Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
const jsConfig = require("@ajv-validator/config/.eslintrc_js")
const tsConfig = require("@ajv-validator/config/.eslintrc")
import jsConfig from "@ajv-validator/config/.eslintrc_js.js"
import tsConfig from "./tsconfig.json" with {type: "json"}

module.exports = {
env: {
es6: true,
node: true,
},
overrides: [
jsConfig,
{
...tsConfig,
files: ["*.ts"],
rules: {
...tsConfig.rules,
complexity: ["error", 17],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/no-invalid-this": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-template-expressions": "off",
},
},
],
export const env = {
es6: true,
node: true,
}
export const overrides = [
jsConfig,
{
...tsConfig,
files: ["*.ts"],
rules: {
...tsConfig.rules,
complexity: ["error", 17],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-implied-eval": "off",
"@typescript-eslint/no-invalid-this": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-template-expressions": "off",
},
},
]
59 changes: 36 additions & 23 deletions lib/2019.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {AnySchemaObject} from "./types"
import AjvCore, {Options} from "./core"
import type {AnySchemaObject} from "./types/index.ts"
import AjvCore, {type Options} from "./core.ts"

import draft7Vocabularies from "./vocabularies/draft7"
import dynamicVocabulary from "./vocabularies/dynamic"
import nextVocabulary from "./vocabularies/next"
import unevaluatedVocabulary from "./vocabularies/unevaluated"
import discriminator from "./vocabularies/discriminator"
import addMetaSchema2019 from "./refs/json-schema-2019-09"
import draft7Vocabularies from "./vocabularies/draft7.ts"
import dynamicVocabulary from "./vocabularies/draft7.ts"
import nextVocabulary from "./vocabularies/next.ts"
import unevaluatedVocabulary from "./vocabularies/unevaluated/index.ts"
import discriminator from "./vocabularies/discriminator/index.ts"
import addMetaSchema2019 from "./refs/json-schema-2019-09/index.ts"

const META_SCHEMA_ID = "https://json-schema.org/draft/2019-09/schema"

Expand All @@ -22,6 +22,7 @@ export class Ajv2019 extends AjvCore {

_addVocabularies(): void {
super._addVocabularies()
//@ts-expect-error
this.addVocabulary(dynamicVocabulary)
draft7Vocabularies.forEach((v) => this.addVocabulary(v))
this.addVocabulary(nextVocabulary)
Expand All @@ -43,13 +44,9 @@ export class Ajv2019 extends AjvCore {
}
}

module.exports = exports = Ajv2019
module.exports.Ajv2019 = Ajv2019
Object.defineProperty(exports, "__esModule", {value: true})

export default Ajv2019

export {
export type {
Format,
FormatDefinition,
AsyncFormatDefinition,
Expand All @@ -68,14 +65,30 @@ export {
AsyncValidateFunction,
ErrorObject,
ErrorNoParams,
} from "./types"
} from "./types/index.ts"

export {Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions} from "./core"
export {SchemaCxt, SchemaObjCxt} from "./compile"
export {KeywordCxt} from "./compile/validate"
export {DefinedError} from "./vocabularies/errors"
export {JSONType} from "./compile/rules"
export {JSONSchemaType} from "./types/json-schema"
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
export type {
Plugin,
Options,
CodeOptions,
InstanceOptions,
Logger,
ErrorsTextOptions,
} from "./core.ts"
export type {SchemaCxt, SchemaObjCxt} from "./compile/index.ts"
export {KeywordCxt} from "./compile/validate/index.ts"
export type {DefinedError} from "./vocabularies/errors.ts"
export type {JSONType} from "./compile/rules.ts"
export type {JSONSchemaType} from "./types/json-schema.ts"
export {
_,
str,
stringify,
nil,
Name,
type Code,
CodeGen,
type CodeGenOptions,
} from "./compile/codegen/index.ts"
export {default as ValidationError} from "./runtime/validation_error.ts"
export {default as MissingRefError} from "./compile/ref_error.ts"
52 changes: 32 additions & 20 deletions lib/2020.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {AnySchemaObject} from "./types"
import AjvCore, {Options} from "./core"
import type {AnySchemaObject} from "./types/index.ts"
import AjvCore, {type Options} from "./core.ts"

import draft2020Vocabularies from "./vocabularies/draft2020"
import discriminator from "./vocabularies/discriminator"
import addMetaSchema2020 from "./refs/json-schema-2020-12"
import draft2020Vocabularies from "./vocabularies/draft2020.ts"
import discriminator from "./vocabularies/discriminator/index.ts"
import addMetaSchema2020 from "./refs/json-schema-2020-12/index.ts"

const META_SCHEMA_ID = "https://json-schema.org/draft/2020-12/schema"

Expand Down Expand Up @@ -37,13 +37,9 @@ export class Ajv2020 extends AjvCore {
}
}

module.exports = exports = Ajv2020
module.exports.Ajv2020 = Ajv2020
Object.defineProperty(exports, "__esModule", {value: true})

export default Ajv2020

export {
export type {
Format,
FormatDefinition,
AsyncFormatDefinition,
Expand All @@ -62,14 +58,30 @@ export {
AsyncValidateFunction,
ErrorObject,
ErrorNoParams,
} from "./types"
} from "./types/index.ts"

export {Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions} from "./core"
export {SchemaCxt, SchemaObjCxt} from "./compile"
export {KeywordCxt} from "./compile/validate"
export {DefinedError} from "./vocabularies/errors"
export {JSONType} from "./compile/rules"
export {JSONSchemaType} from "./types/json-schema"
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
export type {
Plugin,
Options,
CodeOptions,
InstanceOptions,
Logger,
ErrorsTextOptions,
} from "./core.ts"
export type {SchemaCxt, SchemaObjCxt} from "./compile/index.ts"
export {KeywordCxt} from "./compile/validate/index.ts"
export type {DefinedError} from "./vocabularies/errors.ts"
export type {JSONType} from "./compile/rules.ts"
export type {JSONSchemaType} from "./types/json-schema.ts"
export {
_,
str,
stringify,
nil,
Name,
type Code,
CodeGen,
type CodeGenOptions,
} from "./compile/codegen/index.ts"
export {default as ValidationError} from "./runtime/validation_error.ts"
export {default as MissingRefError} from "./compile/ref_error.ts"
52 changes: 32 additions & 20 deletions lib/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {AnySchemaObject} from "./types"
import AjvCore from "./core"
import draft7Vocabularies from "./vocabularies/draft7"
import discriminator from "./vocabularies/discriminator"
import * as draft7MetaSchema from "./refs/json-schema-draft-07.json"
import type {AnySchemaObject} from "./types/index.ts"
import AjvCore from "./core.ts"
import draft7Vocabularies from "./vocabularies/draft7.ts"
import discriminator from "./vocabularies/discriminator/index.ts"
import * as draft7MetaSchema from "./refs/json-schema-draft-07.json" with {type: "json"}

const META_SUPPORT_DATA = ["/properties"]

Expand Down Expand Up @@ -31,13 +31,9 @@ export class Ajv extends AjvCore {
}
}

module.exports = exports = Ajv
module.exports.Ajv = Ajv
Object.defineProperty(exports, "__esModule", {value: true})

export default Ajv

export {
export type {
Format,
FormatDefinition,
AsyncFormatDefinition,
Expand All @@ -57,14 +53,30 @@ export {
SchemaValidateFunction,
ErrorObject,
ErrorNoParams,
} from "./types"
} from "./types/index.ts"

export {Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions} from "./core"
export {SchemaCxt, SchemaObjCxt} from "./compile"
export {KeywordCxt} from "./compile/validate"
export {DefinedError} from "./vocabularies/errors"
export {JSONType} from "./compile/rules"
export {JSONSchemaType} from "./types/json-schema"
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
export {default as ValidationError} from "./runtime/validation_error"
export {default as MissingRefError} from "./compile/ref_error"
export type {
Plugin,
Options,
CodeOptions,
InstanceOptions,
Logger,
ErrorsTextOptions,
} from "./core.ts"
export type {SchemaCxt, SchemaObjCxt} from "./compile/index.ts"
export {KeywordCxt} from "./compile/validate/index.ts"
export type {DefinedError} from "./vocabularies/errors.ts"
export type {JSONType} from "./compile/rules.ts"
export type {JSONSchemaType} from "./types/json-schema.ts"
export {
_,
str,
stringify,
nil,
Name,
type Code,
CodeGen,
type CodeGenOptions,
} from "./compile/codegen/index.ts"
export {default as ValidationError} from "./runtime/validation_error.ts"
export {default as MissingRefError} from "./compile/ref_error.ts"
2 changes: 1 addition & 1 deletion lib/compile/codegen/scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {_, nil, Code, Name} from "./code"
import {_, nil, type Code, Name} from "./code.ts"

interface NameGroup {
prefix: string
Expand Down
12 changes: 6 additions & 6 deletions lib/compile/errors.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type {KeywordErrorCxt, KeywordErrorDefinition} from "../types"
import type {SchemaCxt} from "./index"
import {CodeGen, _, str, strConcat, Code, Name} from "./codegen"
import {SafeExpr} from "./codegen/code"
import {getErrorPath, Type} from "./util"
import N from "./names"
import type {KeywordErrorCxt, KeywordErrorDefinition} from "../types/index.ts"
import type {SchemaCxt} from "./index.ts"
import {CodeGen, _, str, strConcat, type Code, Name} from "./codegen/index.ts"
import type {SafeExpr} from "./codegen/code.ts"
import {getErrorPath, Type} from "./util.ts"
import N from "./names.ts"

export const keywordError: KeywordErrorDefinition = {
message: ({keyword}) => str`must pass "${keyword}" keyword validation`,

Check failure on line 9 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Binding element 'keyword' implicitly has an 'any' type.

Check failure on line 9 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Binding element 'keyword' implicitly has an 'any' type.

Check failure on line 9 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (24.x)

Binding element 'keyword' implicitly has an 'any' type.

Check failure on line 9 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / Run Benchmark with variety of JSON Schemas

Binding element 'keyword' implicitly has an 'any' type.
}

export const keyword$DataError: KeywordErrorDefinition = {
message: ({keyword, schemaType}) =>

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Binding element 'schemaType' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Binding element 'keyword' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Binding element 'schemaType' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Binding element 'keyword' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (24.x)

Binding element 'schemaType' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / build (24.x)

Binding element 'keyword' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / Run Benchmark with variety of JSON Schemas

Binding element 'schemaType' implicitly has an 'any' type.

Check failure on line 13 in lib/compile/errors.ts

View workflow job for this annotation

GitHub Actions / Run Benchmark with variety of JSON Schemas

Binding element 'keyword' implicitly has an 'any' type.
schemaType
? str`"${keyword}" keyword must be ${schemaType} ($data)`
: str`"${keyword}" keyword is invalid ($data)`,
Expand Down
37 changes: 22 additions & 15 deletions lib/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ import type {
AsyncValidateFunction,
EvaluatedProperties,
EvaluatedItems,
} from "../types"
import type Ajv from "../core"
import type {InstanceOptions} from "../core"
import {CodeGen, _, nil, stringify, Name, Code, ValueScopeName} from "./codegen"
import ValidationError from "../runtime/validation_error"
import N from "./names"
import {LocalRefs, getFullPath, _getFullPath, inlineRef, normalizeId, resolveUrl} from "./resolve"
import {schemaHasRulesButRef, unescapeFragment} from "./util"
import {validateFunctionCode} from "./validate"
import {URIComponent} from "fast-uri"
import {JSONType} from "./rules"
} from "../types/index.ts"
import type Ajv from "../core.ts"
import type {InstanceOptions} from "../core.ts"
import {CodeGen, _, nil, stringify, Name, type Code, ValueScopeName} from "./codegen/index.ts"
import ValidationError from "../runtime/validation_error.ts"
import N from "./names.ts"
import {
type LocalRefs,
getFullPath,
_getFullPath,
inlineRef,
normalizeId,
resolveUrl,
} from "./resolve.ts"
import {schemaHasRulesButRef, unescapeFragment} from "./util.ts"
import {validateFunctionCode} from "./validate/index.ts"
import {type URIComponent} from "fast-uri"
import {type JSONType} from "./rules.ts"

export type SchemaRefs = {
[Ref in string]?: SchemaEnv | AnySchema
Expand Down Expand Up @@ -94,10 +101,10 @@ export class SchemaEnv implements SchemaEnvArgs {
this.schemaId = env.schemaId
this.root = env.root || this
this.baseId = env.baseId ?? normalizeId(schema?.[env.schemaId || "$id"])
this.schemaPath = env.schemaPath
this.localRefs = env.localRefs
this.meta = env.meta
this.$async = schema?.$async
this.schemaPath = env.schemaPath as string
this.localRefs = env.localRefs as LocalRefs
this.meta = env.meta as boolean
this.$async = schema?.$async as boolean
this.refs = {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/compile/names.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Name} from "./codegen"
import {Name} from "./codegen/index.ts"

const names = {
// validation function arguments
Expand Down
4 changes: 2 additions & 2 deletions lib/compile/ref_error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {resolveUrl, normalizeId, getFullPath} from "./resolve"
import type {UriResolver} from "../types"
import {resolveUrl, normalizeId, getFullPath} from "./resolve.ts"
import type {UriResolver} from "../types/index.ts"

export default class MissingRefError extends Error {
readonly missingRef: string
Expand Down
10 changes: 5 additions & 5 deletions lib/compile/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {AnySchema, AnySchemaObject, UriResolver} from "../types"
import type Ajv from "../ajv"
import type {AnySchema, AnySchemaObject, UriResolver} from "../types/index.ts"
import type Ajv from "../ajv.ts"
import type {URIComponent} from "fast-uri"
import {eachItem} from "./util"
import * as equal from "fast-deep-equal"
import * as traverse from "json-schema-traverse"
import {eachItem} from "./util.ts"
import equal from "fast-deep-equal"
import traverse from "json-schema-traverse"

// the hash of local references inside the schema (created by getSchemaRefs), used for inline resolution
export type LocalRefs = {[Ref in string]?: AnySchemaObject}
Expand Down
2 changes: 1 addition & 1 deletion lib/compile/rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {AddedKeywordDefinition} from "../types"
import type {AddedKeywordDefinition} from "../types/index.ts"

const _jsonTypes = ["string", "number", "integer", "boolean", "null", "object", "array"] as const

Expand Down
Loading
Loading