Upload folder using huggingface_hub (part 15)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/ajv/lib/compile/validate/keyword.ts +171 -0
- node_modules/ajv/lib/compile/validate/subschema.ts +135 -0
- node_modules/ajv/lib/core.ts +892 -0
- node_modules/ajv/lib/jtd.ts +132 -0
- node_modules/ajv/lib/refs/data.json +13 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/index.ts +28 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/meta/applicator.json +53 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/meta/content.json +17 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/meta/core.json +57 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/meta/format.json +14 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/meta/meta-data.json +37 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/meta/validation.json +90 -0
- node_modules/ajv/lib/refs/json-schema-2019-09/schema.json +39 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/index.ts +30 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/applicator.json +48 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/content.json +17 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/core.json +51 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/format-annotation.json +14 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/meta-data.json +37 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/unevaluated.json +15 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/meta/validation.json +90 -0
- node_modules/ajv/lib/refs/json-schema-2020-12/schema.json +55 -0
- node_modules/ajv/lib/refs/json-schema-draft-06.json +137 -0
- node_modules/ajv/lib/refs/json-schema-draft-07.json +151 -0
- node_modules/ajv/lib/refs/json-schema-secure.json +88 -0
- node_modules/ajv/lib/refs/jtd-schema.ts +130 -0
- node_modules/ajv/lib/runtime/equal.ts +7 -0
- node_modules/ajv/lib/runtime/parseJson.ts +177 -0
- node_modules/ajv/lib/runtime/quote.ts +31 -0
- node_modules/ajv/lib/runtime/re2.ts +6 -0
- node_modules/ajv/lib/runtime/timestamp.ts +46 -0
- node_modules/ajv/lib/runtime/ucs2length.ts +20 -0
- node_modules/ajv/lib/runtime/uri.ts +6 -0
- node_modules/ajv/lib/runtime/validation_error.ts +13 -0
- node_modules/ajv/lib/standalone/index.ts +100 -0
- node_modules/ajv/lib/standalone/instance.ts +36 -0
- node_modules/ajv/lib/types/index.ts +244 -0
- node_modules/ajv/lib/types/json-schema.ts +187 -0
- node_modules/ajv/lib/types/jtd-schema.ts +273 -0
- node_modules/ajv/lib/vocabularies/applicator/additionalItems.ts +56 -0
- node_modules/ajv/lib/vocabularies/applicator/additionalProperties.ts +118 -0
- node_modules/ajv/lib/vocabularies/applicator/allOf.ts +22 -0
- node_modules/ajv/lib/vocabularies/applicator/anyOf.ts +14 -0
- node_modules/ajv/lib/vocabularies/applicator/contains.ts +109 -0
- node_modules/ajv/lib/vocabularies/applicator/dependencies.ts +112 -0
- node_modules/ajv/lib/vocabularies/applicator/dependentSchemas.ts +11 -0
- node_modules/ajv/lib/vocabularies/applicator/if.ts +80 -0
- node_modules/ajv/lib/vocabularies/applicator/index.ts +53 -0
- node_modules/ajv/lib/vocabularies/applicator/items.ts +59 -0
- node_modules/ajv/lib/vocabularies/applicator/items2020.ts +36 -0
node_modules/ajv/lib/compile/validate/keyword.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {KeywordCxt} from "."
|
| 2 |
+
import type {
|
| 3 |
+
AnySchema,
|
| 4 |
+
SchemaValidateFunction,
|
| 5 |
+
AnyValidateFunction,
|
| 6 |
+
AddedKeywordDefinition,
|
| 7 |
+
MacroKeywordDefinition,
|
| 8 |
+
FuncKeywordDefinition,
|
| 9 |
+
} from "../../types"
|
| 10 |
+
import type {SchemaObjCxt} from ".."
|
| 11 |
+
import {_, nil, not, stringify, Code, Name, CodeGen} from "../codegen"
|
| 12 |
+
import N from "../names"
|
| 13 |
+
import type {JSONType} from "../rules"
|
| 14 |
+
import {callValidateCode} from "../../vocabularies/code"
|
| 15 |
+
import {extendErrors} from "../errors"
|
| 16 |
+
|
| 17 |
+
type KeywordCompilationResult = AnySchema | SchemaValidateFunction | AnyValidateFunction
|
| 18 |
+
|
| 19 |
+
export function macroKeywordCode(cxt: KeywordCxt, def: MacroKeywordDefinition): void {
|
| 20 |
+
const {gen, keyword, schema, parentSchema, it} = cxt
|
| 21 |
+
const macroSchema = def.macro.call(it.self, schema, parentSchema, it)
|
| 22 |
+
const schemaRef = useKeyword(gen, keyword, macroSchema)
|
| 23 |
+
if (it.opts.validateSchema !== false) it.self.validateSchema(macroSchema, true)
|
| 24 |
+
|
| 25 |
+
const valid = gen.name("valid")
|
| 26 |
+
cxt.subschema(
|
| 27 |
+
{
|
| 28 |
+
schema: macroSchema,
|
| 29 |
+
schemaPath: nil,
|
| 30 |
+
errSchemaPath: `${it.errSchemaPath}/${keyword}`,
|
| 31 |
+
topSchemaRef: schemaRef,
|
| 32 |
+
compositeRule: true,
|
| 33 |
+
},
|
| 34 |
+
valid
|
| 35 |
+
)
|
| 36 |
+
cxt.pass(valid, () => cxt.error(true))
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
export function funcKeywordCode(cxt: KeywordCxt, def: FuncKeywordDefinition): void {
|
| 40 |
+
const {gen, keyword, schema, parentSchema, $data, it} = cxt
|
| 41 |
+
checkAsyncKeyword(it, def)
|
| 42 |
+
const validate =
|
| 43 |
+
!$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate
|
| 44 |
+
const validateRef = useKeyword(gen, keyword, validate)
|
| 45 |
+
const valid = gen.let("valid")
|
| 46 |
+
cxt.block$data(valid, validateKeyword)
|
| 47 |
+
cxt.ok(def.valid ?? valid)
|
| 48 |
+
|
| 49 |
+
function validateKeyword(): void {
|
| 50 |
+
if (def.errors === false) {
|
| 51 |
+
assignValid()
|
| 52 |
+
if (def.modifying) modifyData(cxt)
|
| 53 |
+
reportErrs(() => cxt.error())
|
| 54 |
+
} else {
|
| 55 |
+
const ruleErrs = def.async ? validateAsync() : validateSync()
|
| 56 |
+
if (def.modifying) modifyData(cxt)
|
| 57 |
+
reportErrs(() => addErrs(cxt, ruleErrs))
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function validateAsync(): Name {
|
| 62 |
+
const ruleErrs = gen.let("ruleErrs", null)
|
| 63 |
+
gen.try(
|
| 64 |
+
() => assignValid(_`await `),
|
| 65 |
+
(e) =>
|
| 66 |
+
gen.assign(valid, false).if(
|
| 67 |
+
_`${e} instanceof ${it.ValidationError as Name}`,
|
| 68 |
+
() => gen.assign(ruleErrs, _`${e}.errors`),
|
| 69 |
+
() => gen.throw(e)
|
| 70 |
+
)
|
| 71 |
+
)
|
| 72 |
+
return ruleErrs
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function validateSync(): Code {
|
| 76 |
+
const validateErrs = _`${validateRef}.errors`
|
| 77 |
+
gen.assign(validateErrs, null)
|
| 78 |
+
assignValid(nil)
|
| 79 |
+
return validateErrs
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
function assignValid(_await: Code = def.async ? _`await ` : nil): void {
|
| 83 |
+
const passCxt = it.opts.passContext ? N.this : N.self
|
| 84 |
+
const passSchema = !(("compile" in def && !$data) || def.schema === false)
|
| 85 |
+
gen.assign(
|
| 86 |
+
valid,
|
| 87 |
+
_`${_await}${callValidateCode(cxt, validateRef, passCxt, passSchema)}`,
|
| 88 |
+
def.modifying
|
| 89 |
+
)
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function reportErrs(errors: () => void): void {
|
| 93 |
+
gen.if(not(def.valid ?? valid), errors)
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
function modifyData(cxt: KeywordCxt): void {
|
| 98 |
+
const {gen, data, it} = cxt
|
| 99 |
+
gen.if(it.parentData, () => gen.assign(data, _`${it.parentData}[${it.parentDataProperty}]`))
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
function addErrs(cxt: KeywordCxt, errs: Code): void {
|
| 103 |
+
const {gen} = cxt
|
| 104 |
+
gen.if(
|
| 105 |
+
_`Array.isArray(${errs})`,
|
| 106 |
+
() => {
|
| 107 |
+
gen
|
| 108 |
+
.assign(N.vErrors, _`${N.vErrors} === null ? ${errs} : ${N.vErrors}.concat(${errs})`)
|
| 109 |
+
.assign(N.errors, _`${N.vErrors}.length`)
|
| 110 |
+
extendErrors(cxt)
|
| 111 |
+
},
|
| 112 |
+
() => cxt.error()
|
| 113 |
+
)
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
function checkAsyncKeyword({schemaEnv}: SchemaObjCxt, def: FuncKeywordDefinition): void {
|
| 117 |
+
if (def.async && !schemaEnv.$async) throw new Error("async keyword in sync schema")
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function useKeyword(gen: CodeGen, keyword: string, result?: KeywordCompilationResult): Name {
|
| 121 |
+
if (result === undefined) throw new Error(`keyword "${keyword}" failed to compile`)
|
| 122 |
+
return gen.scopeValue(
|
| 123 |
+
"keyword",
|
| 124 |
+
typeof result == "function" ? {ref: result} : {ref: result, code: stringify(result)}
|
| 125 |
+
)
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
export function validSchemaType(
|
| 129 |
+
schema: unknown,
|
| 130 |
+
schemaType: JSONType[],
|
| 131 |
+
allowUndefined = false
|
| 132 |
+
): boolean {
|
| 133 |
+
// TODO add tests
|
| 134 |
+
return (
|
| 135 |
+
!schemaType.length ||
|
| 136 |
+
schemaType.some((st) =>
|
| 137 |
+
st === "array"
|
| 138 |
+
? Array.isArray(schema)
|
| 139 |
+
: st === "object"
|
| 140 |
+
? schema && typeof schema == "object" && !Array.isArray(schema)
|
| 141 |
+
: typeof schema == st || (allowUndefined && typeof schema == "undefined")
|
| 142 |
+
)
|
| 143 |
+
)
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
export function validateKeywordUsage(
|
| 147 |
+
{schema, opts, self, errSchemaPath}: SchemaObjCxt,
|
| 148 |
+
def: AddedKeywordDefinition,
|
| 149 |
+
keyword: string
|
| 150 |
+
): void {
|
| 151 |
+
/* istanbul ignore if */
|
| 152 |
+
if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) {
|
| 153 |
+
throw new Error("ajv implementation error")
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
const deps = def.dependencies
|
| 157 |
+
if (deps?.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
| 158 |
+
throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`)
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
if (def.validateSchema) {
|
| 162 |
+
const valid = def.validateSchema(schema[keyword])
|
| 163 |
+
if (!valid) {
|
| 164 |
+
const msg =
|
| 165 |
+
`keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` +
|
| 166 |
+
self.errorsText(def.validateSchema.errors)
|
| 167 |
+
if (opts.validateSchema === "log") self.logger.error(msg)
|
| 168 |
+
else throw new Error(msg)
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
node_modules/ajv/lib/compile/validate/subschema.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {AnySchema} from "../../types"
|
| 2 |
+
import type {SchemaObjCxt} from ".."
|
| 3 |
+
import {_, str, getProperty, Code, Name} from "../codegen"
|
| 4 |
+
import {escapeFragment, getErrorPath, Type} from "../util"
|
| 5 |
+
import type {JSONType} from "../rules"
|
| 6 |
+
|
| 7 |
+
export interface SubschemaContext {
|
| 8 |
+
// TODO use Optional? align with SchemCxt property types
|
| 9 |
+
schema: AnySchema
|
| 10 |
+
schemaPath: Code
|
| 11 |
+
errSchemaPath: string
|
| 12 |
+
topSchemaRef?: Code
|
| 13 |
+
errorPath?: Code
|
| 14 |
+
dataLevel?: number
|
| 15 |
+
dataTypes?: JSONType[]
|
| 16 |
+
data?: Name
|
| 17 |
+
parentData?: Name
|
| 18 |
+
parentDataProperty?: Code | number
|
| 19 |
+
dataNames?: Name[]
|
| 20 |
+
dataPathArr?: (Code | number)[]
|
| 21 |
+
propertyName?: Name
|
| 22 |
+
jtdDiscriminator?: string
|
| 23 |
+
jtdMetadata?: boolean
|
| 24 |
+
compositeRule?: true
|
| 25 |
+
createErrors?: boolean
|
| 26 |
+
allErrors?: boolean
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export type SubschemaArgs = Partial<{
|
| 30 |
+
keyword: string
|
| 31 |
+
schemaProp: string | number
|
| 32 |
+
schema: AnySchema
|
| 33 |
+
schemaPath: Code
|
| 34 |
+
errSchemaPath: string
|
| 35 |
+
topSchemaRef: Code
|
| 36 |
+
data: Name | Code
|
| 37 |
+
dataProp: Code | string | number
|
| 38 |
+
dataTypes: JSONType[]
|
| 39 |
+
definedProperties: Set<string>
|
| 40 |
+
propertyName: Name
|
| 41 |
+
dataPropType: Type
|
| 42 |
+
jtdDiscriminator: string
|
| 43 |
+
jtdMetadata: boolean
|
| 44 |
+
compositeRule: true
|
| 45 |
+
createErrors: boolean
|
| 46 |
+
allErrors: boolean
|
| 47 |
+
}>
|
| 48 |
+
|
| 49 |
+
export function getSubschema(
|
| 50 |
+
it: SchemaObjCxt,
|
| 51 |
+
{keyword, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef}: SubschemaArgs
|
| 52 |
+
): SubschemaContext {
|
| 53 |
+
if (keyword !== undefined && schema !== undefined) {
|
| 54 |
+
throw new Error('both "keyword" and "schema" passed, only one allowed')
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (keyword !== undefined) {
|
| 58 |
+
const sch = it.schema[keyword]
|
| 59 |
+
return schemaProp === undefined
|
| 60 |
+
? {
|
| 61 |
+
schema: sch,
|
| 62 |
+
schemaPath: _`${it.schemaPath}${getProperty(keyword)}`,
|
| 63 |
+
errSchemaPath: `${it.errSchemaPath}/${keyword}`,
|
| 64 |
+
}
|
| 65 |
+
: {
|
| 66 |
+
schema: sch[schemaProp],
|
| 67 |
+
schemaPath: _`${it.schemaPath}${getProperty(keyword)}${getProperty(schemaProp)}`,
|
| 68 |
+
errSchemaPath: `${it.errSchemaPath}/${keyword}/${escapeFragment(schemaProp)}`,
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (schema !== undefined) {
|
| 73 |
+
if (schemaPath === undefined || errSchemaPath === undefined || topSchemaRef === undefined) {
|
| 74 |
+
throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"')
|
| 75 |
+
}
|
| 76 |
+
return {
|
| 77 |
+
schema,
|
| 78 |
+
schemaPath,
|
| 79 |
+
topSchemaRef,
|
| 80 |
+
errSchemaPath,
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
throw new Error('either "keyword" or "schema" must be passed')
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
export function extendSubschemaData(
|
| 88 |
+
subschema: SubschemaContext,
|
| 89 |
+
it: SchemaObjCxt,
|
| 90 |
+
{dataProp, dataPropType: dpType, data, dataTypes, propertyName}: SubschemaArgs
|
| 91 |
+
): void {
|
| 92 |
+
if (data !== undefined && dataProp !== undefined) {
|
| 93 |
+
throw new Error('both "data" and "dataProp" passed, only one allowed')
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
const {gen} = it
|
| 97 |
+
|
| 98 |
+
if (dataProp !== undefined) {
|
| 99 |
+
const {errorPath, dataPathArr, opts} = it
|
| 100 |
+
const nextData = gen.let("data", _`${it.data}${getProperty(dataProp)}`, true)
|
| 101 |
+
dataContextProps(nextData)
|
| 102 |
+
subschema.errorPath = str`${errorPath}${getErrorPath(dataProp, dpType, opts.jsPropertySyntax)}`
|
| 103 |
+
subschema.parentDataProperty = _`${dataProp}`
|
| 104 |
+
subschema.dataPathArr = [...dataPathArr, subschema.parentDataProperty]
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
if (data !== undefined) {
|
| 108 |
+
const nextData = data instanceof Name ? data : gen.let("data", data, true) // replaceable if used once?
|
| 109 |
+
dataContextProps(nextData)
|
| 110 |
+
if (propertyName !== undefined) subschema.propertyName = propertyName
|
| 111 |
+
// TODO something is possibly wrong here with not changing parentDataProperty and not appending dataPathArr
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if (dataTypes) subschema.dataTypes = dataTypes
|
| 115 |
+
|
| 116 |
+
function dataContextProps(_nextData: Name): void {
|
| 117 |
+
subschema.data = _nextData
|
| 118 |
+
subschema.dataLevel = it.dataLevel + 1
|
| 119 |
+
subschema.dataTypes = []
|
| 120 |
+
it.definedProperties = new Set<string>()
|
| 121 |
+
subschema.parentData = it.data
|
| 122 |
+
subschema.dataNames = [...it.dataNames, _nextData]
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
export function extendSubschemaMode(
|
| 127 |
+
subschema: SubschemaContext,
|
| 128 |
+
{jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors}: SubschemaArgs
|
| 129 |
+
): void {
|
| 130 |
+
if (compositeRule !== undefined) subschema.compositeRule = compositeRule
|
| 131 |
+
if (createErrors !== undefined) subschema.createErrors = createErrors
|
| 132 |
+
if (allErrors !== undefined) subschema.allErrors = allErrors
|
| 133 |
+
subschema.jtdDiscriminator = jtdDiscriminator // not inherited
|
| 134 |
+
subschema.jtdMetadata = jtdMetadata // not inherited
|
| 135 |
+
}
|
node_modules/ajv/lib/core.ts
ADDED
|
@@ -0,0 +1,892 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export {
|
| 2 |
+
Format,
|
| 3 |
+
FormatDefinition,
|
| 4 |
+
AsyncFormatDefinition,
|
| 5 |
+
KeywordDefinition,
|
| 6 |
+
KeywordErrorDefinition,
|
| 7 |
+
CodeKeywordDefinition,
|
| 8 |
+
MacroKeywordDefinition,
|
| 9 |
+
FuncKeywordDefinition,
|
| 10 |
+
Vocabulary,
|
| 11 |
+
Schema,
|
| 12 |
+
SchemaObject,
|
| 13 |
+
AnySchemaObject,
|
| 14 |
+
AsyncSchema,
|
| 15 |
+
AnySchema,
|
| 16 |
+
ValidateFunction,
|
| 17 |
+
AsyncValidateFunction,
|
| 18 |
+
AnyValidateFunction,
|
| 19 |
+
ErrorObject,
|
| 20 |
+
ErrorNoParams,
|
| 21 |
+
} from "./types"
|
| 22 |
+
|
| 23 |
+
export {SchemaCxt, SchemaObjCxt} from "./compile"
|
| 24 |
+
export interface Plugin<Opts> {
|
| 25 |
+
(ajv: Ajv, options?: Opts): Ajv
|
| 26 |
+
[prop: string]: any
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export {KeywordCxt} from "./compile/validate"
|
| 30 |
+
export {DefinedError} from "./vocabularies/errors"
|
| 31 |
+
export {JSONType} from "./compile/rules"
|
| 32 |
+
export {JSONSchemaType} from "./types/json-schema"
|
| 33 |
+
export {JTDSchemaType, SomeJTDSchemaType, JTDDataType} from "./types/jtd-schema"
|
| 34 |
+
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
|
| 35 |
+
|
| 36 |
+
import type {
|
| 37 |
+
Schema,
|
| 38 |
+
AnySchema,
|
| 39 |
+
AnySchemaObject,
|
| 40 |
+
SchemaObject,
|
| 41 |
+
AsyncSchema,
|
| 42 |
+
Vocabulary,
|
| 43 |
+
KeywordDefinition,
|
| 44 |
+
AddedKeywordDefinition,
|
| 45 |
+
AnyValidateFunction,
|
| 46 |
+
ValidateFunction,
|
| 47 |
+
AsyncValidateFunction,
|
| 48 |
+
ErrorObject,
|
| 49 |
+
Format,
|
| 50 |
+
AddedFormat,
|
| 51 |
+
RegExpEngine,
|
| 52 |
+
UriResolver,
|
| 53 |
+
} from "./types"
|
| 54 |
+
import type {JSONSchemaType} from "./types/json-schema"
|
| 55 |
+
import type {JTDSchemaType, SomeJTDSchemaType, JTDDataType} from "./types/jtd-schema"
|
| 56 |
+
import ValidationError from "./runtime/validation_error"
|
| 57 |
+
import MissingRefError from "./compile/ref_error"
|
| 58 |
+
import {getRules, ValidationRules, Rule, RuleGroup, JSONType} from "./compile/rules"
|
| 59 |
+
import {SchemaEnv, compileSchema, resolveSchema} from "./compile"
|
| 60 |
+
import {Code, ValueScope} from "./compile/codegen"
|
| 61 |
+
import {normalizeId, getSchemaRefs} from "./compile/resolve"
|
| 62 |
+
import {getJSONTypes} from "./compile/validate/dataType"
|
| 63 |
+
import {eachItem} from "./compile/util"
|
| 64 |
+
import * as $dataRefSchema from "./refs/data.json"
|
| 65 |
+
|
| 66 |
+
import DefaultUriResolver from "./runtime/uri"
|
| 67 |
+
|
| 68 |
+
const defaultRegExp: RegExpEngine = (str, flags) => new RegExp(str, flags)
|
| 69 |
+
defaultRegExp.code = "new RegExp"
|
| 70 |
+
|
| 71 |
+
const META_IGNORE_OPTIONS: (keyof Options)[] = ["removeAdditional", "useDefaults", "coerceTypes"]
|
| 72 |
+
const EXT_SCOPE_NAMES = new Set([
|
| 73 |
+
"validate",
|
| 74 |
+
"serialize",
|
| 75 |
+
"parse",
|
| 76 |
+
"wrapper",
|
| 77 |
+
"root",
|
| 78 |
+
"schema",
|
| 79 |
+
"keyword",
|
| 80 |
+
"pattern",
|
| 81 |
+
"formats",
|
| 82 |
+
"validate$data",
|
| 83 |
+
"func",
|
| 84 |
+
"obj",
|
| 85 |
+
"Error",
|
| 86 |
+
])
|
| 87 |
+
|
| 88 |
+
export type Options = CurrentOptions & DeprecatedOptions
|
| 89 |
+
|
| 90 |
+
export interface CurrentOptions {
|
| 91 |
+
// strict mode options (NEW)
|
| 92 |
+
strict?: boolean | "log"
|
| 93 |
+
strictSchema?: boolean | "log"
|
| 94 |
+
strictNumbers?: boolean | "log"
|
| 95 |
+
strictTypes?: boolean | "log"
|
| 96 |
+
strictTuples?: boolean | "log"
|
| 97 |
+
strictRequired?: boolean | "log"
|
| 98 |
+
allowMatchingProperties?: boolean // disables a strict mode restriction
|
| 99 |
+
allowUnionTypes?: boolean
|
| 100 |
+
validateFormats?: boolean
|
| 101 |
+
// validation and reporting options:
|
| 102 |
+
$data?: boolean
|
| 103 |
+
allErrors?: boolean
|
| 104 |
+
verbose?: boolean
|
| 105 |
+
discriminator?: boolean
|
| 106 |
+
unicodeRegExp?: boolean
|
| 107 |
+
timestamp?: "string" | "date" // JTD only
|
| 108 |
+
parseDate?: boolean // JTD only
|
| 109 |
+
allowDate?: boolean // JTD only
|
| 110 |
+
specialNumbers?: "fast" | "null" // JTD only
|
| 111 |
+
$comment?:
|
| 112 |
+
| true
|
| 113 |
+
| ((comment: string, schemaPath?: string, rootSchema?: AnySchemaObject) => unknown)
|
| 114 |
+
formats?: {[Name in string]?: Format}
|
| 115 |
+
keywords?: Vocabulary
|
| 116 |
+
schemas?: AnySchema[] | {[Key in string]?: AnySchema}
|
| 117 |
+
logger?: Logger | false
|
| 118 |
+
loadSchema?: (uri: string) => Promise<AnySchemaObject>
|
| 119 |
+
// options to modify validated data:
|
| 120 |
+
removeAdditional?: boolean | "all" | "failing"
|
| 121 |
+
useDefaults?: boolean | "empty"
|
| 122 |
+
coerceTypes?: boolean | "array"
|
| 123 |
+
// advanced options:
|
| 124 |
+
next?: boolean // NEW
|
| 125 |
+
unevaluated?: boolean // NEW
|
| 126 |
+
dynamicRef?: boolean // NEW
|
| 127 |
+
schemaId?: "id" | "$id"
|
| 128 |
+
jtd?: boolean // NEW
|
| 129 |
+
meta?: SchemaObject | boolean
|
| 130 |
+
defaultMeta?: string | AnySchemaObject
|
| 131 |
+
validateSchema?: boolean | "log"
|
| 132 |
+
addUsedSchema?: boolean
|
| 133 |
+
inlineRefs?: boolean | number
|
| 134 |
+
passContext?: boolean
|
| 135 |
+
loopRequired?: number
|
| 136 |
+
loopEnum?: number // NEW
|
| 137 |
+
ownProperties?: boolean
|
| 138 |
+
multipleOfPrecision?: number
|
| 139 |
+
int32range?: boolean // JTD only
|
| 140 |
+
messages?: boolean
|
| 141 |
+
code?: CodeOptions // NEW
|
| 142 |
+
uriResolver?: UriResolver
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
export interface CodeOptions {
|
| 146 |
+
es5?: boolean
|
| 147 |
+
esm?: boolean
|
| 148 |
+
lines?: boolean
|
| 149 |
+
optimize?: boolean | number
|
| 150 |
+
formats?: Code // code to require (or construct) map of available formats - for standalone code
|
| 151 |
+
source?: boolean
|
| 152 |
+
process?: (code: string, schema?: SchemaEnv) => string
|
| 153 |
+
regExp?: RegExpEngine
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
interface InstanceCodeOptions extends CodeOptions {
|
| 157 |
+
regExp: RegExpEngine
|
| 158 |
+
optimize: number
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
interface DeprecatedOptions {
|
| 162 |
+
/** @deprecated */
|
| 163 |
+
ignoreKeywordsWithRef?: boolean
|
| 164 |
+
/** @deprecated */
|
| 165 |
+
jsPropertySyntax?: boolean // added instead of jsonPointers
|
| 166 |
+
/** @deprecated */
|
| 167 |
+
unicode?: boolean
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
interface RemovedOptions {
|
| 171 |
+
format?: boolean
|
| 172 |
+
errorDataPath?: "object" | "property"
|
| 173 |
+
nullable?: boolean // "nullable" keyword is supported by default
|
| 174 |
+
jsonPointers?: boolean
|
| 175 |
+
extendRefs?: true | "ignore" | "fail"
|
| 176 |
+
missingRefs?: true | "ignore" | "fail"
|
| 177 |
+
processCode?: (code: string, schema?: SchemaEnv) => string
|
| 178 |
+
sourceCode?: boolean
|
| 179 |
+
strictDefaults?: boolean
|
| 180 |
+
strictKeywords?: boolean
|
| 181 |
+
uniqueItems?: boolean
|
| 182 |
+
unknownFormats?: true | string[] | "ignore"
|
| 183 |
+
cache?: any
|
| 184 |
+
serialize?: (schema: AnySchema) => unknown
|
| 185 |
+
ajvErrors?: boolean
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
type OptionsInfo<T extends RemovedOptions | DeprecatedOptions> = {
|
| 189 |
+
[K in keyof T]-?: string | undefined
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
const removedOptions: OptionsInfo<RemovedOptions> = {
|
| 193 |
+
errorDataPath: "",
|
| 194 |
+
format: "`validateFormats: false` can be used instead.",
|
| 195 |
+
nullable: '"nullable" keyword is supported by default.',
|
| 196 |
+
jsonPointers: "Deprecated jsPropertySyntax can be used instead.",
|
| 197 |
+
extendRefs: "Deprecated ignoreKeywordsWithRef can be used instead.",
|
| 198 |
+
missingRefs: "Pass empty schema with $id that should be ignored to ajv.addSchema.",
|
| 199 |
+
processCode: "Use option `code: {process: (code, schemaEnv: object) => string}`",
|
| 200 |
+
sourceCode: "Use option `code: {source: true}`",
|
| 201 |
+
strictDefaults: "It is default now, see option `strict`.",
|
| 202 |
+
strictKeywords: "It is default now, see option `strict`.",
|
| 203 |
+
uniqueItems: '"uniqueItems" keyword is always validated.',
|
| 204 |
+
unknownFormats: "Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",
|
| 205 |
+
cache: "Map is used as cache, schema object as key.",
|
| 206 |
+
serialize: "Map is used as cache, schema object as key.",
|
| 207 |
+
ajvErrors: "It is default now.",
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
const deprecatedOptions: OptionsInfo<DeprecatedOptions> = {
|
| 211 |
+
ignoreKeywordsWithRef: "",
|
| 212 |
+
jsPropertySyntax: "",
|
| 213 |
+
unicode: '"minLength"/"maxLength" account for unicode characters by default.',
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
type RequiredInstanceOptions = {
|
| 217 |
+
[K in
|
| 218 |
+
| "strictSchema"
|
| 219 |
+
| "strictNumbers"
|
| 220 |
+
| "strictTypes"
|
| 221 |
+
| "strictTuples"
|
| 222 |
+
| "strictRequired"
|
| 223 |
+
| "inlineRefs"
|
| 224 |
+
| "loopRequired"
|
| 225 |
+
| "loopEnum"
|
| 226 |
+
| "meta"
|
| 227 |
+
| "messages"
|
| 228 |
+
| "schemaId"
|
| 229 |
+
| "addUsedSchema"
|
| 230 |
+
| "validateSchema"
|
| 231 |
+
| "validateFormats"
|
| 232 |
+
| "int32range"
|
| 233 |
+
| "unicodeRegExp"
|
| 234 |
+
| "uriResolver"]: NonNullable<Options[K]>
|
| 235 |
+
} & {code: InstanceCodeOptions}
|
| 236 |
+
|
| 237 |
+
export type InstanceOptions = Options & RequiredInstanceOptions
|
| 238 |
+
|
| 239 |
+
const MAX_EXPRESSION = 200
|
| 240 |
+
|
| 241 |
+
// eslint-disable-next-line complexity
|
| 242 |
+
function requiredOptions(o: Options): RequiredInstanceOptions {
|
| 243 |
+
const s = o.strict
|
| 244 |
+
const _optz = o.code?.optimize
|
| 245 |
+
const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0
|
| 246 |
+
const regExp = o.code?.regExp ?? defaultRegExp
|
| 247 |
+
const uriResolver = o.uriResolver ?? DefaultUriResolver
|
| 248 |
+
return {
|
| 249 |
+
strictSchema: o.strictSchema ?? s ?? true,
|
| 250 |
+
strictNumbers: o.strictNumbers ?? s ?? true,
|
| 251 |
+
strictTypes: o.strictTypes ?? s ?? "log",
|
| 252 |
+
strictTuples: o.strictTuples ?? s ?? "log",
|
| 253 |
+
strictRequired: o.strictRequired ?? s ?? false,
|
| 254 |
+
code: o.code ? {...o.code, optimize, regExp} : {optimize, regExp},
|
| 255 |
+
loopRequired: o.loopRequired ?? MAX_EXPRESSION,
|
| 256 |
+
loopEnum: o.loopEnum ?? MAX_EXPRESSION,
|
| 257 |
+
meta: o.meta ?? true,
|
| 258 |
+
messages: o.messages ?? true,
|
| 259 |
+
inlineRefs: o.inlineRefs ?? true,
|
| 260 |
+
schemaId: o.schemaId ?? "$id",
|
| 261 |
+
addUsedSchema: o.addUsedSchema ?? true,
|
| 262 |
+
validateSchema: o.validateSchema ?? true,
|
| 263 |
+
validateFormats: o.validateFormats ?? true,
|
| 264 |
+
unicodeRegExp: o.unicodeRegExp ?? true,
|
| 265 |
+
int32range: o.int32range ?? true,
|
| 266 |
+
uriResolver: uriResolver,
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
export interface Logger {
|
| 271 |
+
log(...args: unknown[]): unknown
|
| 272 |
+
warn(...args: unknown[]): unknown
|
| 273 |
+
error(...args: unknown[]): unknown
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
export default class Ajv {
|
| 277 |
+
opts: InstanceOptions
|
| 278 |
+
errors?: ErrorObject[] | null // errors from the last validation
|
| 279 |
+
logger: Logger
|
| 280 |
+
// shared external scope values for compiled functions
|
| 281 |
+
readonly scope: ValueScope
|
| 282 |
+
readonly schemas: {[Key in string]?: SchemaEnv} = {}
|
| 283 |
+
readonly refs: {[Ref in string]?: SchemaEnv | string} = {}
|
| 284 |
+
readonly formats: {[Name in string]?: AddedFormat} = Object.create(null)
|
| 285 |
+
readonly RULES: ValidationRules
|
| 286 |
+
readonly _compilations: Set<SchemaEnv> = new Set()
|
| 287 |
+
private readonly _loading: {[Ref in string]?: Promise<AnySchemaObject>} = {}
|
| 288 |
+
private readonly _cache: Map<AnySchema, SchemaEnv> = new Map()
|
| 289 |
+
private readonly _metaOpts: InstanceOptions
|
| 290 |
+
|
| 291 |
+
static ValidationError = ValidationError
|
| 292 |
+
static MissingRefError = MissingRefError
|
| 293 |
+
|
| 294 |
+
constructor(opts: Options = {}) {
|
| 295 |
+
opts = this.opts = {...opts, ...requiredOptions(opts)}
|
| 296 |
+
const {es5, lines} = this.opts.code
|
| 297 |
+
|
| 298 |
+
this.scope = new ValueScope({scope: {}, prefixes: EXT_SCOPE_NAMES, es5, lines})
|
| 299 |
+
this.logger = getLogger(opts.logger)
|
| 300 |
+
const formatOpt = opts.validateFormats
|
| 301 |
+
opts.validateFormats = false
|
| 302 |
+
|
| 303 |
+
this.RULES = getRules()
|
| 304 |
+
checkOptions.call(this, removedOptions, opts, "NOT SUPPORTED")
|
| 305 |
+
checkOptions.call(this, deprecatedOptions, opts, "DEPRECATED", "warn")
|
| 306 |
+
this._metaOpts = getMetaSchemaOptions.call(this)
|
| 307 |
+
|
| 308 |
+
if (opts.formats) addInitialFormats.call(this)
|
| 309 |
+
this._addVocabularies()
|
| 310 |
+
this._addDefaultMetaSchema()
|
| 311 |
+
if (opts.keywords) addInitialKeywords.call(this, opts.keywords)
|
| 312 |
+
if (typeof opts.meta == "object") this.addMetaSchema(opts.meta)
|
| 313 |
+
addInitialSchemas.call(this)
|
| 314 |
+
opts.validateFormats = formatOpt
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
_addVocabularies(): void {
|
| 318 |
+
this.addKeyword("$async")
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
_addDefaultMetaSchema(): void {
|
| 322 |
+
const {$data, meta, schemaId} = this.opts
|
| 323 |
+
let _dataRefSchema: SchemaObject = $dataRefSchema
|
| 324 |
+
if (schemaId === "id") {
|
| 325 |
+
_dataRefSchema = {...$dataRefSchema}
|
| 326 |
+
_dataRefSchema.id = _dataRefSchema.$id
|
| 327 |
+
delete _dataRefSchema.$id
|
| 328 |
+
}
|
| 329 |
+
if (meta && $data) this.addMetaSchema(_dataRefSchema, _dataRefSchema[schemaId], false)
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
defaultMeta(): string | AnySchemaObject | undefined {
|
| 333 |
+
const {meta, schemaId} = this.opts
|
| 334 |
+
return (this.opts.defaultMeta = typeof meta == "object" ? meta[schemaId] || meta : undefined)
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// Validate data using schema
|
| 338 |
+
// AnySchema will be compiled and cached using schema itself as a key for Map
|
| 339 |
+
validate(schema: Schema | string, data: unknown): boolean
|
| 340 |
+
validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise<unknown>
|
| 341 |
+
validate<T>(schema: Schema | JSONSchemaType<T> | string, data: unknown): data is T
|
| 342 |
+
// Separated for type inference to work
|
| 343 |
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
| 344 |
+
validate<T>(schema: JTDSchemaType<T>, data: unknown): data is T
|
| 345 |
+
// This overload is only intended for typescript inference, the first
|
| 346 |
+
// argument prevents manual type annotation from matching this overload
|
| 347 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 348 |
+
validate<N extends never, T extends SomeJTDSchemaType>(
|
| 349 |
+
schema: T,
|
| 350 |
+
data: unknown
|
| 351 |
+
): data is JTDDataType<T>
|
| 352 |
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
| 353 |
+
validate<T>(schema: AsyncSchema, data: unknown | T): Promise<T>
|
| 354 |
+
validate<T>(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise<T>
|
| 355 |
+
validate<T>(
|
| 356 |
+
schemaKeyRef: AnySchema | string, // key, ref or schema object
|
| 357 |
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
| 358 |
+
data: unknown | T // to be validated
|
| 359 |
+
): boolean | Promise<T> {
|
| 360 |
+
let v: AnyValidateFunction | undefined
|
| 361 |
+
if (typeof schemaKeyRef == "string") {
|
| 362 |
+
v = this.getSchema<T>(schemaKeyRef)
|
| 363 |
+
if (!v) throw new Error(`no schema with key or ref "${schemaKeyRef}"`)
|
| 364 |
+
} else {
|
| 365 |
+
v = this.compile<T>(schemaKeyRef)
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
const valid = v(data)
|
| 369 |
+
if (!("$async" in v)) this.errors = v.errors
|
| 370 |
+
return valid
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// Create validation function for passed schema
|
| 374 |
+
// _meta: true if schema is a meta-schema. Used internally to compile meta schemas of user-defined keywords.
|
| 375 |
+
compile<T = unknown>(schema: Schema | JSONSchemaType<T>, _meta?: boolean): ValidateFunction<T>
|
| 376 |
+
// Separated for type inference to work
|
| 377 |
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
| 378 |
+
compile<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): ValidateFunction<T>
|
| 379 |
+
// This overload is only intended for typescript inference, the first
|
| 380 |
+
// argument prevents manual type annotation from matching this overload
|
| 381 |
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
| 382 |
+
compile<N extends never, T extends SomeJTDSchemaType>(
|
| 383 |
+
schema: T,
|
| 384 |
+
_meta?: boolean
|
| 385 |
+
): ValidateFunction<JTDDataType<T>>
|
| 386 |
+
compile<T = unknown>(schema: AsyncSchema, _meta?: boolean): AsyncValidateFunction<T>
|
| 387 |
+
compile<T = unknown>(schema: AnySchema, _meta?: boolean): AnyValidateFunction<T>
|
| 388 |
+
compile<T = unknown>(schema: AnySchema, _meta?: boolean): AnyValidateFunction<T> {
|
| 389 |
+
const sch = this._addSchema(schema, _meta)
|
| 390 |
+
return (sch.validate || this._compileSchemaEnv(sch)) as AnyValidateFunction<T>
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
// Creates validating function for passed schema with asynchronous loading of missing schemas.
|
| 394 |
+
// `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
|
| 395 |
+
// TODO allow passing schema URI
|
| 396 |
+
// meta - optional true to compile meta-schema
|
| 397 |
+
compileAsync<T = unknown>(
|
| 398 |
+
schema: SchemaObject | JSONSchemaType<T>,
|
| 399 |
+
_meta?: boolean
|
| 400 |
+
): Promise<ValidateFunction<T>>
|
| 401 |
+
// Separated for type inference to work
|
| 402 |
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
| 403 |
+
compileAsync<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): Promise<ValidateFunction<T>>
|
| 404 |
+
compileAsync<T = unknown>(schema: AsyncSchema, meta?: boolean): Promise<AsyncValidateFunction<T>>
|
| 405 |
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
| 406 |
+
compileAsync<T = unknown>(
|
| 407 |
+
schema: AnySchemaObject,
|
| 408 |
+
meta?: boolean
|
| 409 |
+
): Promise<AnyValidateFunction<T>>
|
| 410 |
+
compileAsync<T = unknown>(
|
| 411 |
+
schema: AnySchemaObject,
|
| 412 |
+
meta?: boolean
|
| 413 |
+
): Promise<AnyValidateFunction<T>> {
|
| 414 |
+
if (typeof this.opts.loadSchema != "function") {
|
| 415 |
+
throw new Error("options.loadSchema should be a function")
|
| 416 |
+
}
|
| 417 |
+
const {loadSchema} = this.opts
|
| 418 |
+
return runCompileAsync.call(this, schema, meta)
|
| 419 |
+
|
| 420 |
+
async function runCompileAsync(
|
| 421 |
+
this: Ajv,
|
| 422 |
+
_schema: AnySchemaObject,
|
| 423 |
+
_meta?: boolean
|
| 424 |
+
): Promise<AnyValidateFunction> {
|
| 425 |
+
await loadMetaSchema.call(this, _schema.$schema)
|
| 426 |
+
const sch = this._addSchema(_schema, _meta)
|
| 427 |
+
return sch.validate || _compileAsync.call(this, sch)
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
async function loadMetaSchema(this: Ajv, $ref?: string): Promise<void> {
|
| 431 |
+
if ($ref && !this.getSchema($ref)) {
|
| 432 |
+
await runCompileAsync.call(this, {$ref}, true)
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
async function _compileAsync(this: Ajv, sch: SchemaEnv): Promise<AnyValidateFunction> {
|
| 437 |
+
try {
|
| 438 |
+
return this._compileSchemaEnv(sch)
|
| 439 |
+
} catch (e) {
|
| 440 |
+
if (!(e instanceof MissingRefError)) throw e
|
| 441 |
+
checkLoaded.call(this, e)
|
| 442 |
+
await loadMissingSchema.call(this, e.missingSchema)
|
| 443 |
+
return _compileAsync.call(this, sch)
|
| 444 |
+
}
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
function checkLoaded(this: Ajv, {missingSchema: ref, missingRef}: MissingRefError): void {
|
| 448 |
+
if (this.refs[ref]) {
|
| 449 |
+
throw new Error(`AnySchema ${ref} is loaded but ${missingRef} cannot be resolved`)
|
| 450 |
+
}
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
async function loadMissingSchema(this: Ajv, ref: string): Promise<void> {
|
| 454 |
+
const _schema = await _loadSchema.call(this, ref)
|
| 455 |
+
if (!this.refs[ref]) await loadMetaSchema.call(this, _schema.$schema)
|
| 456 |
+
if (!this.refs[ref]) this.addSchema(_schema, ref, meta)
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
async function _loadSchema(this: Ajv, ref: string): Promise<AnySchemaObject> {
|
| 460 |
+
const p = this._loading[ref]
|
| 461 |
+
if (p) return p
|
| 462 |
+
try {
|
| 463 |
+
return await (this._loading[ref] = loadSchema(ref))
|
| 464 |
+
} finally {
|
| 465 |
+
delete this._loading[ref]
|
| 466 |
+
}
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
// Adds schema to the instance
|
| 471 |
+
addSchema(
|
| 472 |
+
schema: AnySchema | AnySchema[], // If array is passed, `key` will be ignored
|
| 473 |
+
key?: string, // Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
|
| 474 |
+
_meta?: boolean, // true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
|
| 475 |
+
_validateSchema = this.opts.validateSchema // false to skip schema validation. Used internally, option validateSchema should be used instead.
|
| 476 |
+
): Ajv {
|
| 477 |
+
if (Array.isArray(schema)) {
|
| 478 |
+
for (const sch of schema) this.addSchema(sch, undefined, _meta, _validateSchema)
|
| 479 |
+
return this
|
| 480 |
+
}
|
| 481 |
+
let id: string | undefined
|
| 482 |
+
if (typeof schema === "object") {
|
| 483 |
+
const {schemaId} = this.opts
|
| 484 |
+
id = schema[schemaId]
|
| 485 |
+
if (id !== undefined && typeof id != "string") {
|
| 486 |
+
throw new Error(`schema ${schemaId} must be string`)
|
| 487 |
+
}
|
| 488 |
+
}
|
| 489 |
+
key = normalizeId(key || id)
|
| 490 |
+
this._checkUnique(key)
|
| 491 |
+
this.schemas[key] = this._addSchema(schema, _meta, key, _validateSchema, true)
|
| 492 |
+
return this
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
// Add schema that will be used to validate other schemas
|
| 496 |
+
// options in META_IGNORE_OPTIONS are alway set to false
|
| 497 |
+
addMetaSchema(
|
| 498 |
+
schema: AnySchemaObject,
|
| 499 |
+
key?: string, // schema key
|
| 500 |
+
_validateSchema = this.opts.validateSchema // false to skip schema validation, can be used to override validateSchema option for meta-schema
|
| 501 |
+
): Ajv {
|
| 502 |
+
this.addSchema(schema, key, true, _validateSchema)
|
| 503 |
+
return this
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
// Validate schema against its meta-schema
|
| 507 |
+
validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown> {
|
| 508 |
+
if (typeof schema == "boolean") return true
|
| 509 |
+
let $schema: string | AnySchemaObject | undefined
|
| 510 |
+
$schema = schema.$schema
|
| 511 |
+
if ($schema !== undefined && typeof $schema != "string") {
|
| 512 |
+
throw new Error("$schema must be a string")
|
| 513 |
+
}
|
| 514 |
+
$schema = $schema || this.opts.defaultMeta || this.defaultMeta()
|
| 515 |
+
if (!$schema) {
|
| 516 |
+
this.logger.warn("meta-schema not available")
|
| 517 |
+
this.errors = null
|
| 518 |
+
return true
|
| 519 |
+
}
|
| 520 |
+
const valid = this.validate($schema, schema)
|
| 521 |
+
if (!valid && throwOrLogError) {
|
| 522 |
+
const message = "schema is invalid: " + this.errorsText()
|
| 523 |
+
if (this.opts.validateSchema === "log") this.logger.error(message)
|
| 524 |
+
else throw new Error(message)
|
| 525 |
+
}
|
| 526 |
+
return valid
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
// Get compiled schema by `key` or `ref`.
|
| 530 |
+
// (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id)
|
| 531 |
+
getSchema<T = unknown>(keyRef: string): AnyValidateFunction<T> | undefined {
|
| 532 |
+
let sch
|
| 533 |
+
while (typeof (sch = getSchEnv.call(this, keyRef)) == "string") keyRef = sch
|
| 534 |
+
if (sch === undefined) {
|
| 535 |
+
const {schemaId} = this.opts
|
| 536 |
+
const root = new SchemaEnv({schema: {}, schemaId})
|
| 537 |
+
sch = resolveSchema.call(this, root, keyRef)
|
| 538 |
+
if (!sch) return
|
| 539 |
+
this.refs[keyRef] = sch
|
| 540 |
+
}
|
| 541 |
+
return (sch.validate || this._compileSchemaEnv(sch)) as AnyValidateFunction<T> | undefined
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
// Remove cached schema(s).
|
| 545 |
+
// If no parameter is passed all schemas but meta-schemas are removed.
|
| 546 |
+
// If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
|
| 547 |
+
// Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
|
| 548 |
+
removeSchema(schemaKeyRef?: AnySchema | string | RegExp): Ajv {
|
| 549 |
+
if (schemaKeyRef instanceof RegExp) {
|
| 550 |
+
this._removeAllSchemas(this.schemas, schemaKeyRef)
|
| 551 |
+
this._removeAllSchemas(this.refs, schemaKeyRef)
|
| 552 |
+
return this
|
| 553 |
+
}
|
| 554 |
+
switch (typeof schemaKeyRef) {
|
| 555 |
+
case "undefined":
|
| 556 |
+
this._removeAllSchemas(this.schemas)
|
| 557 |
+
this._removeAllSchemas(this.refs)
|
| 558 |
+
this._cache.clear()
|
| 559 |
+
return this
|
| 560 |
+
case "string": {
|
| 561 |
+
const sch = getSchEnv.call(this, schemaKeyRef)
|
| 562 |
+
if (typeof sch == "object") this._cache.delete(sch.schema)
|
| 563 |
+
delete this.schemas[schemaKeyRef]
|
| 564 |
+
delete this.refs[schemaKeyRef]
|
| 565 |
+
return this
|
| 566 |
+
}
|
| 567 |
+
case "object": {
|
| 568 |
+
const cacheKey = schemaKeyRef
|
| 569 |
+
this._cache.delete(cacheKey)
|
| 570 |
+
let id = schemaKeyRef[this.opts.schemaId]
|
| 571 |
+
if (id) {
|
| 572 |
+
id = normalizeId(id)
|
| 573 |
+
delete this.schemas[id]
|
| 574 |
+
delete this.refs[id]
|
| 575 |
+
}
|
| 576 |
+
return this
|
| 577 |
+
}
|
| 578 |
+
default:
|
| 579 |
+
throw new Error("ajv.removeSchema: invalid parameter")
|
| 580 |
+
}
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
// add "vocabulary" - a collection of keywords
|
| 584 |
+
addVocabulary(definitions: Vocabulary): Ajv {
|
| 585 |
+
for (const def of definitions) this.addKeyword(def)
|
| 586 |
+
return this
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
addKeyword(
|
| 590 |
+
kwdOrDef: string | KeywordDefinition,
|
| 591 |
+
def?: KeywordDefinition // deprecated
|
| 592 |
+
): Ajv {
|
| 593 |
+
let keyword: string | string[]
|
| 594 |
+
if (typeof kwdOrDef == "string") {
|
| 595 |
+
keyword = kwdOrDef
|
| 596 |
+
if (typeof def == "object") {
|
| 597 |
+
this.logger.warn("these parameters are deprecated, see docs for addKeyword")
|
| 598 |
+
def.keyword = keyword
|
| 599 |
+
}
|
| 600 |
+
} else if (typeof kwdOrDef == "object" && def === undefined) {
|
| 601 |
+
def = kwdOrDef
|
| 602 |
+
keyword = def.keyword
|
| 603 |
+
if (Array.isArray(keyword) && !keyword.length) {
|
| 604 |
+
throw new Error("addKeywords: keyword must be string or non-empty array")
|
| 605 |
+
}
|
| 606 |
+
} else {
|
| 607 |
+
throw new Error("invalid addKeywords parameters")
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
checkKeyword.call(this, keyword, def)
|
| 611 |
+
if (!def) {
|
| 612 |
+
eachItem(keyword, (kwd) => addRule.call(this, kwd))
|
| 613 |
+
return this
|
| 614 |
+
}
|
| 615 |
+
keywordMetaschema.call(this, def)
|
| 616 |
+
const definition: AddedKeywordDefinition = {
|
| 617 |
+
...def,
|
| 618 |
+
type: getJSONTypes(def.type),
|
| 619 |
+
schemaType: getJSONTypes(def.schemaType),
|
| 620 |
+
}
|
| 621 |
+
eachItem(
|
| 622 |
+
keyword,
|
| 623 |
+
definition.type.length === 0
|
| 624 |
+
? (k) => addRule.call(this, k, definition)
|
| 625 |
+
: (k) => definition.type.forEach((t) => addRule.call(this, k, definition, t))
|
| 626 |
+
)
|
| 627 |
+
return this
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
getKeyword(keyword: string): AddedKeywordDefinition | boolean {
|
| 631 |
+
const rule = this.RULES.all[keyword]
|
| 632 |
+
return typeof rule == "object" ? rule.definition : !!rule
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
// Remove keyword
|
| 636 |
+
removeKeyword(keyword: string): Ajv {
|
| 637 |
+
// TODO return type should be Ajv
|
| 638 |
+
const {RULES} = this
|
| 639 |
+
delete RULES.keywords[keyword]
|
| 640 |
+
delete RULES.all[keyword]
|
| 641 |
+
for (const group of RULES.rules) {
|
| 642 |
+
const i = group.rules.findIndex((rule) => rule.keyword === keyword)
|
| 643 |
+
if (i >= 0) group.rules.splice(i, 1)
|
| 644 |
+
}
|
| 645 |
+
return this
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
// Add format
|
| 649 |
+
addFormat(name: string, format: Format): Ajv {
|
| 650 |
+
if (typeof format == "string") format = new RegExp(format)
|
| 651 |
+
this.formats[name] = format
|
| 652 |
+
return this
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
errorsText(
|
| 656 |
+
errors: ErrorObject[] | null | undefined = this.errors, // optional array of validation errors
|
| 657 |
+
{separator = ", ", dataVar = "data"}: ErrorsTextOptions = {} // optional options with properties `separator` and `dataVar`
|
| 658 |
+
): string {
|
| 659 |
+
if (!errors || errors.length === 0) return "No errors"
|
| 660 |
+
return errors
|
| 661 |
+
.map((e) => `${dataVar}${e.instancePath} ${e.message}`)
|
| 662 |
+
.reduce((text, msg) => text + separator + msg)
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
$dataMetaSchema(metaSchema: AnySchemaObject, keywordsJsonPointers: string[]): AnySchemaObject {
|
| 666 |
+
const rules = this.RULES.all
|
| 667 |
+
metaSchema = JSON.parse(JSON.stringify(metaSchema))
|
| 668 |
+
for (const jsonPointer of keywordsJsonPointers) {
|
| 669 |
+
const segments = jsonPointer.split("/").slice(1) // first segment is an empty string
|
| 670 |
+
let keywords = metaSchema
|
| 671 |
+
for (const seg of segments) keywords = keywords[seg] as AnySchemaObject
|
| 672 |
+
|
| 673 |
+
for (const key in rules) {
|
| 674 |
+
const rule = rules[key]
|
| 675 |
+
if (typeof rule != "object") continue
|
| 676 |
+
const {$data} = rule.definition
|
| 677 |
+
const schema = keywords[key] as AnySchemaObject | undefined
|
| 678 |
+
if ($data && schema) keywords[key] = schemaOrData(schema)
|
| 679 |
+
}
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
return metaSchema
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
private _removeAllSchemas(schemas: {[Ref in string]?: SchemaEnv | string}, regex?: RegExp): void {
|
| 686 |
+
for (const keyRef in schemas) {
|
| 687 |
+
const sch = schemas[keyRef]
|
| 688 |
+
if (!regex || regex.test(keyRef)) {
|
| 689 |
+
if (typeof sch == "string") {
|
| 690 |
+
delete schemas[keyRef]
|
| 691 |
+
} else if (sch && !sch.meta) {
|
| 692 |
+
this._cache.delete(sch.schema)
|
| 693 |
+
delete schemas[keyRef]
|
| 694 |
+
}
|
| 695 |
+
}
|
| 696 |
+
}
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
_addSchema(
|
| 700 |
+
schema: AnySchema,
|
| 701 |
+
meta?: boolean,
|
| 702 |
+
baseId?: string,
|
| 703 |
+
validateSchema = this.opts.validateSchema,
|
| 704 |
+
addSchema = this.opts.addUsedSchema
|
| 705 |
+
): SchemaEnv {
|
| 706 |
+
let id: string | undefined
|
| 707 |
+
const {schemaId} = this.opts
|
| 708 |
+
if (typeof schema == "object") {
|
| 709 |
+
id = schema[schemaId]
|
| 710 |
+
} else {
|
| 711 |
+
if (this.opts.jtd) throw new Error("schema must be object")
|
| 712 |
+
else if (typeof schema != "boolean") throw new Error("schema must be object or boolean")
|
| 713 |
+
}
|
| 714 |
+
let sch = this._cache.get(schema)
|
| 715 |
+
if (sch !== undefined) return sch
|
| 716 |
+
|
| 717 |
+
baseId = normalizeId(id || baseId)
|
| 718 |
+
const localRefs = getSchemaRefs.call(this, schema, baseId)
|
| 719 |
+
sch = new SchemaEnv({schema, schemaId, meta, baseId, localRefs})
|
| 720 |
+
this._cache.set(sch.schema, sch)
|
| 721 |
+
if (addSchema && !baseId.startsWith("#")) {
|
| 722 |
+
// TODO atm it is allowed to overwrite schemas without id (instead of not adding them)
|
| 723 |
+
if (baseId) this._checkUnique(baseId)
|
| 724 |
+
this.refs[baseId] = sch
|
| 725 |
+
}
|
| 726 |
+
if (validateSchema) this.validateSchema(schema, true)
|
| 727 |
+
return sch
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
private _checkUnique(id: string): void {
|
| 731 |
+
if (this.schemas[id] || this.refs[id]) {
|
| 732 |
+
throw new Error(`schema with key or id "${id}" already exists`)
|
| 733 |
+
}
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
private _compileSchemaEnv(sch: SchemaEnv): AnyValidateFunction {
|
| 737 |
+
if (sch.meta) this._compileMetaSchema(sch)
|
| 738 |
+
else compileSchema.call(this, sch)
|
| 739 |
+
|
| 740 |
+
/* istanbul ignore if */
|
| 741 |
+
if (!sch.validate) throw new Error("ajv implementation error")
|
| 742 |
+
return sch.validate
|
| 743 |
+
}
|
| 744 |
+
|
| 745 |
+
private _compileMetaSchema(sch: SchemaEnv): void {
|
| 746 |
+
const currentOpts = this.opts
|
| 747 |
+
this.opts = this._metaOpts
|
| 748 |
+
try {
|
| 749 |
+
compileSchema.call(this, sch)
|
| 750 |
+
} finally {
|
| 751 |
+
this.opts = currentOpts
|
| 752 |
+
}
|
| 753 |
+
}
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
export interface ErrorsTextOptions {
|
| 757 |
+
separator?: string
|
| 758 |
+
dataVar?: string
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
function checkOptions(
|
| 762 |
+
this: Ajv,
|
| 763 |
+
checkOpts: OptionsInfo<RemovedOptions | DeprecatedOptions>,
|
| 764 |
+
options: Options & RemovedOptions,
|
| 765 |
+
msg: string,
|
| 766 |
+
log: "warn" | "error" = "error"
|
| 767 |
+
): void {
|
| 768 |
+
for (const key in checkOpts) {
|
| 769 |
+
const opt = key as keyof typeof checkOpts
|
| 770 |
+
if (opt in options) this.logger[log](`${msg}: option ${key}. ${checkOpts[opt]}`)
|
| 771 |
+
}
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
function getSchEnv(this: Ajv, keyRef: string): SchemaEnv | string | undefined {
|
| 775 |
+
keyRef = normalizeId(keyRef) // TODO tests fail without this line
|
| 776 |
+
return this.schemas[keyRef] || this.refs[keyRef]
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
function addInitialSchemas(this: Ajv): void {
|
| 780 |
+
const optsSchemas = this.opts.schemas
|
| 781 |
+
if (!optsSchemas) return
|
| 782 |
+
if (Array.isArray(optsSchemas)) this.addSchema(optsSchemas)
|
| 783 |
+
else for (const key in optsSchemas) this.addSchema(optsSchemas[key] as AnySchema, key)
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
function addInitialFormats(this: Ajv): void {
|
| 787 |
+
for (const name in this.opts.formats) {
|
| 788 |
+
const format = this.opts.formats[name]
|
| 789 |
+
if (format) this.addFormat(name, format)
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
function addInitialKeywords(
|
| 794 |
+
this: Ajv,
|
| 795 |
+
defs: Vocabulary | {[K in string]?: KeywordDefinition}
|
| 796 |
+
): void {
|
| 797 |
+
if (Array.isArray(defs)) {
|
| 798 |
+
this.addVocabulary(defs)
|
| 799 |
+
return
|
| 800 |
+
}
|
| 801 |
+
this.logger.warn("keywords option as map is deprecated, pass array")
|
| 802 |
+
for (const keyword in defs) {
|
| 803 |
+
const def = defs[keyword] as KeywordDefinition
|
| 804 |
+
if (!def.keyword) def.keyword = keyword
|
| 805 |
+
this.addKeyword(def)
|
| 806 |
+
}
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
function getMetaSchemaOptions(this: Ajv): InstanceOptions {
|
| 810 |
+
const metaOpts = {...this.opts}
|
| 811 |
+
for (const opt of META_IGNORE_OPTIONS) delete metaOpts[opt]
|
| 812 |
+
return metaOpts
|
| 813 |
+
}
|
| 814 |
+
|
| 815 |
+
const noLogs = {log() {}, warn() {}, error() {}}
|
| 816 |
+
|
| 817 |
+
function getLogger(logger?: Partial<Logger> | false): Logger {
|
| 818 |
+
if (logger === false) return noLogs
|
| 819 |
+
if (logger === undefined) return console
|
| 820 |
+
if (logger.log && logger.warn && logger.error) return logger as Logger
|
| 821 |
+
throw new Error("logger must implement log, warn and error methods")
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
const KEYWORD_NAME = /^[a-z_$][a-z0-9_$:-]*$/i
|
| 825 |
+
|
| 826 |
+
function checkKeyword(this: Ajv, keyword: string | string[], def?: KeywordDefinition): void {
|
| 827 |
+
const {RULES} = this
|
| 828 |
+
eachItem(keyword, (kwd) => {
|
| 829 |
+
if (RULES.keywords[kwd]) throw new Error(`Keyword ${kwd} is already defined`)
|
| 830 |
+
if (!KEYWORD_NAME.test(kwd)) throw new Error(`Keyword ${kwd} has invalid name`)
|
| 831 |
+
})
|
| 832 |
+
if (!def) return
|
| 833 |
+
if (def.$data && !("code" in def || "validate" in def)) {
|
| 834 |
+
throw new Error('$data keyword must have "code" or "validate" function')
|
| 835 |
+
}
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
function addRule(
|
| 839 |
+
this: Ajv,
|
| 840 |
+
keyword: string,
|
| 841 |
+
definition?: AddedKeywordDefinition,
|
| 842 |
+
dataType?: JSONType
|
| 843 |
+
): void {
|
| 844 |
+
const post = definition?.post
|
| 845 |
+
if (dataType && post) throw new Error('keyword with "post" flag cannot have "type"')
|
| 846 |
+
const {RULES} = this
|
| 847 |
+
let ruleGroup = post ? RULES.post : RULES.rules.find(({type: t}) => t === dataType)
|
| 848 |
+
if (!ruleGroup) {
|
| 849 |
+
ruleGroup = {type: dataType, rules: []}
|
| 850 |
+
RULES.rules.push(ruleGroup)
|
| 851 |
+
}
|
| 852 |
+
RULES.keywords[keyword] = true
|
| 853 |
+
if (!definition) return
|
| 854 |
+
|
| 855 |
+
const rule: Rule = {
|
| 856 |
+
keyword,
|
| 857 |
+
definition: {
|
| 858 |
+
...definition,
|
| 859 |
+
type: getJSONTypes(definition.type),
|
| 860 |
+
schemaType: getJSONTypes(definition.schemaType),
|
| 861 |
+
},
|
| 862 |
+
}
|
| 863 |
+
if (definition.before) addBeforeRule.call(this, ruleGroup, rule, definition.before)
|
| 864 |
+
else ruleGroup.rules.push(rule)
|
| 865 |
+
RULES.all[keyword] = rule
|
| 866 |
+
definition.implements?.forEach((kwd) => this.addKeyword(kwd))
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
function addBeforeRule(this: Ajv, ruleGroup: RuleGroup, rule: Rule, before: string): void {
|
| 870 |
+
const i = ruleGroup.rules.findIndex((_rule) => _rule.keyword === before)
|
| 871 |
+
if (i >= 0) {
|
| 872 |
+
ruleGroup.rules.splice(i, 0, rule)
|
| 873 |
+
} else {
|
| 874 |
+
ruleGroup.rules.push(rule)
|
| 875 |
+
this.logger.warn(`rule ${before} is not defined`)
|
| 876 |
+
}
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
function keywordMetaschema(this: Ajv, def: KeywordDefinition): void {
|
| 880 |
+
let {metaSchema} = def
|
| 881 |
+
if (metaSchema === undefined) return
|
| 882 |
+
if (def.$data && this.opts.$data) metaSchema = schemaOrData(metaSchema)
|
| 883 |
+
def.validateSchema = this.compile(metaSchema, true)
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
const $dataRef = {
|
| 887 |
+
$ref: "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
function schemaOrData(schema: AnySchema): AnySchemaObject {
|
| 891 |
+
return {anyOf: [schema, $dataRef]}
|
| 892 |
+
}
|
node_modules/ajv/lib/jtd.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {AnySchemaObject, SchemaObject, JTDParser} from "./types"
|
| 2 |
+
import type {JTDSchemaType, SomeJTDSchemaType, JTDDataType} from "./types/jtd-schema"
|
| 3 |
+
import AjvCore, {CurrentOptions} from "./core"
|
| 4 |
+
import jtdVocabulary from "./vocabularies/jtd"
|
| 5 |
+
import jtdMetaSchema from "./refs/jtd-schema"
|
| 6 |
+
import compileSerializer from "./compile/jtd/serialize"
|
| 7 |
+
import compileParser from "./compile/jtd/parse"
|
| 8 |
+
import {SchemaEnv} from "./compile"
|
| 9 |
+
|
| 10 |
+
const META_SCHEMA_ID = "JTD-meta-schema"
|
| 11 |
+
|
| 12 |
+
type JTDOptions = CurrentOptions & {
|
| 13 |
+
// strict mode options not supported with JTD:
|
| 14 |
+
strict?: never
|
| 15 |
+
allowMatchingProperties?: never
|
| 16 |
+
allowUnionTypes?: never
|
| 17 |
+
validateFormats?: never
|
| 18 |
+
// validation and reporting options not supported with JTD:
|
| 19 |
+
$data?: never
|
| 20 |
+
verbose?: boolean
|
| 21 |
+
$comment?: never
|
| 22 |
+
formats?: never
|
| 23 |
+
loadSchema?: never
|
| 24 |
+
// options to modify validated data:
|
| 25 |
+
useDefaults?: never
|
| 26 |
+
coerceTypes?: never
|
| 27 |
+
// advanced options:
|
| 28 |
+
next?: never
|
| 29 |
+
unevaluated?: never
|
| 30 |
+
dynamicRef?: never
|
| 31 |
+
meta?: boolean
|
| 32 |
+
defaultMeta?: never
|
| 33 |
+
inlineRefs?: boolean
|
| 34 |
+
loopRequired?: never
|
| 35 |
+
multipleOfPrecision?: never
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export class Ajv extends AjvCore {
|
| 39 |
+
constructor(opts: JTDOptions = {}) {
|
| 40 |
+
super({
|
| 41 |
+
...opts,
|
| 42 |
+
jtd: true,
|
| 43 |
+
})
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
_addVocabularies(): void {
|
| 47 |
+
super._addVocabularies()
|
| 48 |
+
this.addVocabulary(jtdVocabulary)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
_addDefaultMetaSchema(): void {
|
| 52 |
+
super._addDefaultMetaSchema()
|
| 53 |
+
if (!this.opts.meta) return
|
| 54 |
+
this.addMetaSchema(jtdMetaSchema, META_SCHEMA_ID, false)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
defaultMeta(): string | AnySchemaObject | undefined {
|
| 58 |
+
return (this.opts.defaultMeta =
|
| 59 |
+
super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined))
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
compileSerializer<T = unknown>(schema: SchemaObject): (data: T) => string
|
| 63 |
+
// Separated for type inference to work
|
| 64 |
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
| 65 |
+
compileSerializer<T = unknown>(schema: JTDSchemaType<T>): (data: T) => string
|
| 66 |
+
compileSerializer<T = unknown>(schema: SchemaObject): (data: T) => string {
|
| 67 |
+
const sch = this._addSchema(schema)
|
| 68 |
+
return sch.serialize || this._compileSerializer(sch)
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
compileParser<T = unknown>(schema: SchemaObject): JTDParser<T>
|
| 72 |
+
// Separated for type inference to work
|
| 73 |
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
| 74 |
+
compileParser<T = unknown>(schema: JTDSchemaType<T>): JTDParser<T>
|
| 75 |
+
compileParser<T = unknown>(schema: SchemaObject): JTDParser<T> {
|
| 76 |
+
const sch = this._addSchema(schema)
|
| 77 |
+
return (sch.parse || this._compileParser(sch)) as JTDParser<T>
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
private _compileSerializer<T>(sch: SchemaEnv): (data: T) => string {
|
| 81 |
+
compileSerializer.call(this, sch, (sch.schema as AnySchemaObject).definitions || {})
|
| 82 |
+
/* istanbul ignore if */
|
| 83 |
+
if (!sch.serialize) throw new Error("ajv implementation error")
|
| 84 |
+
return sch.serialize
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
private _compileParser(sch: SchemaEnv): JTDParser {
|
| 88 |
+
compileParser.call(this, sch, (sch.schema as AnySchemaObject).definitions || {})
|
| 89 |
+
/* istanbul ignore if */
|
| 90 |
+
if (!sch.parse) throw new Error("ajv implementation error")
|
| 91 |
+
return sch.parse
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
module.exports = exports = Ajv
|
| 96 |
+
module.exports.Ajv = Ajv
|
| 97 |
+
Object.defineProperty(exports, "__esModule", {value: true})
|
| 98 |
+
|
| 99 |
+
export default Ajv
|
| 100 |
+
|
| 101 |
+
export {
|
| 102 |
+
Format,
|
| 103 |
+
FormatDefinition,
|
| 104 |
+
AsyncFormatDefinition,
|
| 105 |
+
KeywordDefinition,
|
| 106 |
+
KeywordErrorDefinition,
|
| 107 |
+
CodeKeywordDefinition,
|
| 108 |
+
MacroKeywordDefinition,
|
| 109 |
+
FuncKeywordDefinition,
|
| 110 |
+
Vocabulary,
|
| 111 |
+
Schema,
|
| 112 |
+
SchemaObject,
|
| 113 |
+
AnySchemaObject,
|
| 114 |
+
AsyncSchema,
|
| 115 |
+
AnySchema,
|
| 116 |
+
ValidateFunction,
|
| 117 |
+
AsyncValidateFunction,
|
| 118 |
+
ErrorObject,
|
| 119 |
+
ErrorNoParams,
|
| 120 |
+
JTDParser,
|
| 121 |
+
} from "./types"
|
| 122 |
+
|
| 123 |
+
export {Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions} from "./core"
|
| 124 |
+
export {SchemaCxt, SchemaObjCxt} from "./compile"
|
| 125 |
+
export {KeywordCxt} from "./compile/validate"
|
| 126 |
+
export {JTDErrorObject} from "./vocabularies/jtd"
|
| 127 |
+
export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
|
| 128 |
+
|
| 129 |
+
export {JTDSchemaType, SomeJTDSchemaType, JTDDataType}
|
| 130 |
+
export {JTDOptions}
|
| 131 |
+
export {default as ValidationError} from "./runtime/validation_error"
|
| 132 |
+
export {default as MissingRefError} from "./compile/ref_error"
|
node_modules/ajv/lib/refs/data.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
|
| 3 |
+
"description": "Meta-schema for $data reference (JSON AnySchema extension proposal)",
|
| 4 |
+
"type": "object",
|
| 5 |
+
"required": ["$data"],
|
| 6 |
+
"properties": {
|
| 7 |
+
"$data": {
|
| 8 |
+
"type": "string",
|
| 9 |
+
"anyOf": [{"format": "relative-json-pointer"}, {"format": "json-pointer"}]
|
| 10 |
+
}
|
| 11 |
+
},
|
| 12 |
+
"additionalProperties": false
|
| 13 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type Ajv from "../../core"
|
| 2 |
+
import type {AnySchemaObject} from "../../types"
|
| 3 |
+
import * as metaSchema from "./schema.json"
|
| 4 |
+
import * as applicator from "./meta/applicator.json"
|
| 5 |
+
import * as content from "./meta/content.json"
|
| 6 |
+
import * as core from "./meta/core.json"
|
| 7 |
+
import * as format from "./meta/format.json"
|
| 8 |
+
import * as metadata from "./meta/meta-data.json"
|
| 9 |
+
import * as validation from "./meta/validation.json"
|
| 10 |
+
|
| 11 |
+
const META_SUPPORT_DATA = ["/properties"]
|
| 12 |
+
|
| 13 |
+
export default function addMetaSchema2019(this: Ajv, $data?: boolean): Ajv {
|
| 14 |
+
;[
|
| 15 |
+
metaSchema,
|
| 16 |
+
applicator,
|
| 17 |
+
content,
|
| 18 |
+
core,
|
| 19 |
+
with$data(this, format),
|
| 20 |
+
metadata,
|
| 21 |
+
with$data(this, validation),
|
| 22 |
+
].forEach((sch) => this.addMetaSchema(sch, undefined, false))
|
| 23 |
+
return this
|
| 24 |
+
|
| 25 |
+
function with$data(ajv: Ajv, sch: AnySchemaObject): AnySchemaObject {
|
| 26 |
+
return $data ? ajv.$dataMetaSchema(sch, META_SUPPORT_DATA) : sch
|
| 27 |
+
}
|
| 28 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/meta/applicator.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/meta/applicator",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/applicator": true
|
| 6 |
+
},
|
| 7 |
+
"$recursiveAnchor": true,
|
| 8 |
+
|
| 9 |
+
"title": "Applicator vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"additionalItems": {"$recursiveRef": "#"},
|
| 13 |
+
"unevaluatedItems": {"$recursiveRef": "#"},
|
| 14 |
+
"items": {
|
| 15 |
+
"anyOf": [{"$recursiveRef": "#"}, {"$ref": "#/$defs/schemaArray"}]
|
| 16 |
+
},
|
| 17 |
+
"contains": {"$recursiveRef": "#"},
|
| 18 |
+
"additionalProperties": {"$recursiveRef": "#"},
|
| 19 |
+
"unevaluatedProperties": {"$recursiveRef": "#"},
|
| 20 |
+
"properties": {
|
| 21 |
+
"type": "object",
|
| 22 |
+
"additionalProperties": {"$recursiveRef": "#"},
|
| 23 |
+
"default": {}
|
| 24 |
+
},
|
| 25 |
+
"patternProperties": {
|
| 26 |
+
"type": "object",
|
| 27 |
+
"additionalProperties": {"$recursiveRef": "#"},
|
| 28 |
+
"propertyNames": {"format": "regex"},
|
| 29 |
+
"default": {}
|
| 30 |
+
},
|
| 31 |
+
"dependentSchemas": {
|
| 32 |
+
"type": "object",
|
| 33 |
+
"additionalProperties": {
|
| 34 |
+
"$recursiveRef": "#"
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
+
"propertyNames": {"$recursiveRef": "#"},
|
| 38 |
+
"if": {"$recursiveRef": "#"},
|
| 39 |
+
"then": {"$recursiveRef": "#"},
|
| 40 |
+
"else": {"$recursiveRef": "#"},
|
| 41 |
+
"allOf": {"$ref": "#/$defs/schemaArray"},
|
| 42 |
+
"anyOf": {"$ref": "#/$defs/schemaArray"},
|
| 43 |
+
"oneOf": {"$ref": "#/$defs/schemaArray"},
|
| 44 |
+
"not": {"$recursiveRef": "#"}
|
| 45 |
+
},
|
| 46 |
+
"$defs": {
|
| 47 |
+
"schemaArray": {
|
| 48 |
+
"type": "array",
|
| 49 |
+
"minItems": 1,
|
| 50 |
+
"items": {"$recursiveRef": "#"}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/meta/content.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/meta/content",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/content": true
|
| 6 |
+
},
|
| 7 |
+
"$recursiveAnchor": true,
|
| 8 |
+
|
| 9 |
+
"title": "Content vocabulary meta-schema",
|
| 10 |
+
|
| 11 |
+
"type": ["object", "boolean"],
|
| 12 |
+
"properties": {
|
| 13 |
+
"contentMediaType": {"type": "string"},
|
| 14 |
+
"contentEncoding": {"type": "string"},
|
| 15 |
+
"contentSchema": {"$recursiveRef": "#"}
|
| 16 |
+
}
|
| 17 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/meta/core.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/meta/core",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/core": true
|
| 6 |
+
},
|
| 7 |
+
"$recursiveAnchor": true,
|
| 8 |
+
|
| 9 |
+
"title": "Core vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"$id": {
|
| 13 |
+
"type": "string",
|
| 14 |
+
"format": "uri-reference",
|
| 15 |
+
"$comment": "Non-empty fragments not allowed.",
|
| 16 |
+
"pattern": "^[^#]*#?$"
|
| 17 |
+
},
|
| 18 |
+
"$schema": {
|
| 19 |
+
"type": "string",
|
| 20 |
+
"format": "uri"
|
| 21 |
+
},
|
| 22 |
+
"$anchor": {
|
| 23 |
+
"type": "string",
|
| 24 |
+
"pattern": "^[A-Za-z][-A-Za-z0-9.:_]*$"
|
| 25 |
+
},
|
| 26 |
+
"$ref": {
|
| 27 |
+
"type": "string",
|
| 28 |
+
"format": "uri-reference"
|
| 29 |
+
},
|
| 30 |
+
"$recursiveRef": {
|
| 31 |
+
"type": "string",
|
| 32 |
+
"format": "uri-reference"
|
| 33 |
+
},
|
| 34 |
+
"$recursiveAnchor": {
|
| 35 |
+
"type": "boolean",
|
| 36 |
+
"default": false
|
| 37 |
+
},
|
| 38 |
+
"$vocabulary": {
|
| 39 |
+
"type": "object",
|
| 40 |
+
"propertyNames": {
|
| 41 |
+
"type": "string",
|
| 42 |
+
"format": "uri"
|
| 43 |
+
},
|
| 44 |
+
"additionalProperties": {
|
| 45 |
+
"type": "boolean"
|
| 46 |
+
}
|
| 47 |
+
},
|
| 48 |
+
"$comment": {
|
| 49 |
+
"type": "string"
|
| 50 |
+
},
|
| 51 |
+
"$defs": {
|
| 52 |
+
"type": "object",
|
| 53 |
+
"additionalProperties": {"$recursiveRef": "#"},
|
| 54 |
+
"default": {}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/meta/format.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/meta/format",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/format": true
|
| 6 |
+
},
|
| 7 |
+
"$recursiveAnchor": true,
|
| 8 |
+
|
| 9 |
+
"title": "Format vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"format": {"type": "string"}
|
| 13 |
+
}
|
| 14 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/meta/meta-data.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/meta/meta-data",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/meta-data": true
|
| 6 |
+
},
|
| 7 |
+
"$recursiveAnchor": true,
|
| 8 |
+
|
| 9 |
+
"title": "Meta-data vocabulary meta-schema",
|
| 10 |
+
|
| 11 |
+
"type": ["object", "boolean"],
|
| 12 |
+
"properties": {
|
| 13 |
+
"title": {
|
| 14 |
+
"type": "string"
|
| 15 |
+
},
|
| 16 |
+
"description": {
|
| 17 |
+
"type": "string"
|
| 18 |
+
},
|
| 19 |
+
"default": true,
|
| 20 |
+
"deprecated": {
|
| 21 |
+
"type": "boolean",
|
| 22 |
+
"default": false
|
| 23 |
+
},
|
| 24 |
+
"readOnly": {
|
| 25 |
+
"type": "boolean",
|
| 26 |
+
"default": false
|
| 27 |
+
},
|
| 28 |
+
"writeOnly": {
|
| 29 |
+
"type": "boolean",
|
| 30 |
+
"default": false
|
| 31 |
+
},
|
| 32 |
+
"examples": {
|
| 33 |
+
"type": "array",
|
| 34 |
+
"items": true
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/meta/validation.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/meta/validation",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/validation": true
|
| 6 |
+
},
|
| 7 |
+
"$recursiveAnchor": true,
|
| 8 |
+
|
| 9 |
+
"title": "Validation vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"multipleOf": {
|
| 13 |
+
"type": "number",
|
| 14 |
+
"exclusiveMinimum": 0
|
| 15 |
+
},
|
| 16 |
+
"maximum": {
|
| 17 |
+
"type": "number"
|
| 18 |
+
},
|
| 19 |
+
"exclusiveMaximum": {
|
| 20 |
+
"type": "number"
|
| 21 |
+
},
|
| 22 |
+
"minimum": {
|
| 23 |
+
"type": "number"
|
| 24 |
+
},
|
| 25 |
+
"exclusiveMinimum": {
|
| 26 |
+
"type": "number"
|
| 27 |
+
},
|
| 28 |
+
"maxLength": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 29 |
+
"minLength": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
|
| 30 |
+
"pattern": {
|
| 31 |
+
"type": "string",
|
| 32 |
+
"format": "regex"
|
| 33 |
+
},
|
| 34 |
+
"maxItems": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 35 |
+
"minItems": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
|
| 36 |
+
"uniqueItems": {
|
| 37 |
+
"type": "boolean",
|
| 38 |
+
"default": false
|
| 39 |
+
},
|
| 40 |
+
"maxContains": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 41 |
+
"minContains": {
|
| 42 |
+
"$ref": "#/$defs/nonNegativeInteger",
|
| 43 |
+
"default": 1
|
| 44 |
+
},
|
| 45 |
+
"maxProperties": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 46 |
+
"minProperties": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
|
| 47 |
+
"required": {"$ref": "#/$defs/stringArray"},
|
| 48 |
+
"dependentRequired": {
|
| 49 |
+
"type": "object",
|
| 50 |
+
"additionalProperties": {
|
| 51 |
+
"$ref": "#/$defs/stringArray"
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"const": true,
|
| 55 |
+
"enum": {
|
| 56 |
+
"type": "array",
|
| 57 |
+
"items": true
|
| 58 |
+
},
|
| 59 |
+
"type": {
|
| 60 |
+
"anyOf": [
|
| 61 |
+
{"$ref": "#/$defs/simpleTypes"},
|
| 62 |
+
{
|
| 63 |
+
"type": "array",
|
| 64 |
+
"items": {"$ref": "#/$defs/simpleTypes"},
|
| 65 |
+
"minItems": 1,
|
| 66 |
+
"uniqueItems": true
|
| 67 |
+
}
|
| 68 |
+
]
|
| 69 |
+
}
|
| 70 |
+
},
|
| 71 |
+
"$defs": {
|
| 72 |
+
"nonNegativeInteger": {
|
| 73 |
+
"type": "integer",
|
| 74 |
+
"minimum": 0
|
| 75 |
+
},
|
| 76 |
+
"nonNegativeIntegerDefault0": {
|
| 77 |
+
"$ref": "#/$defs/nonNegativeInteger",
|
| 78 |
+
"default": 0
|
| 79 |
+
},
|
| 80 |
+
"simpleTypes": {
|
| 81 |
+
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
| 82 |
+
},
|
| 83 |
+
"stringArray": {
|
| 84 |
+
"type": "array",
|
| 85 |
+
"items": {"type": "string"},
|
| 86 |
+
"uniqueItems": true,
|
| 87 |
+
"default": []
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2019-09/schema.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2019-09/schema",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2019-09/vocab/core": true,
|
| 6 |
+
"https://json-schema.org/draft/2019-09/vocab/applicator": true,
|
| 7 |
+
"https://json-schema.org/draft/2019-09/vocab/validation": true,
|
| 8 |
+
"https://json-schema.org/draft/2019-09/vocab/meta-data": true,
|
| 9 |
+
"https://json-schema.org/draft/2019-09/vocab/format": false,
|
| 10 |
+
"https://json-schema.org/draft/2019-09/vocab/content": true
|
| 11 |
+
},
|
| 12 |
+
"$recursiveAnchor": true,
|
| 13 |
+
|
| 14 |
+
"title": "Core and Validation specifications meta-schema",
|
| 15 |
+
"allOf": [
|
| 16 |
+
{"$ref": "meta/core"},
|
| 17 |
+
{"$ref": "meta/applicator"},
|
| 18 |
+
{"$ref": "meta/validation"},
|
| 19 |
+
{"$ref": "meta/meta-data"},
|
| 20 |
+
{"$ref": "meta/format"},
|
| 21 |
+
{"$ref": "meta/content"}
|
| 22 |
+
],
|
| 23 |
+
"type": ["object", "boolean"],
|
| 24 |
+
"properties": {
|
| 25 |
+
"definitions": {
|
| 26 |
+
"$comment": "While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.",
|
| 27 |
+
"type": "object",
|
| 28 |
+
"additionalProperties": {"$recursiveRef": "#"},
|
| 29 |
+
"default": {}
|
| 30 |
+
},
|
| 31 |
+
"dependencies": {
|
| 32 |
+
"$comment": "\"dependencies\" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to \"dependentSchemas\" and \"dependentRequired\"",
|
| 33 |
+
"type": "object",
|
| 34 |
+
"additionalProperties": {
|
| 35 |
+
"anyOf": [{"$recursiveRef": "#"}, {"$ref": "meta/validation#/$defs/stringArray"}]
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type Ajv from "../../core"
|
| 2 |
+
import type {AnySchemaObject} from "../../types"
|
| 3 |
+
import * as metaSchema from "./schema.json"
|
| 4 |
+
import * as applicator from "./meta/applicator.json"
|
| 5 |
+
import * as unevaluated from "./meta/unevaluated.json"
|
| 6 |
+
import * as content from "./meta/content.json"
|
| 7 |
+
import * as core from "./meta/core.json"
|
| 8 |
+
import * as format from "./meta/format-annotation.json"
|
| 9 |
+
import * as metadata from "./meta/meta-data.json"
|
| 10 |
+
import * as validation from "./meta/validation.json"
|
| 11 |
+
|
| 12 |
+
const META_SUPPORT_DATA = ["/properties"]
|
| 13 |
+
|
| 14 |
+
export default function addMetaSchema2020(this: Ajv, $data?: boolean): Ajv {
|
| 15 |
+
;[
|
| 16 |
+
metaSchema,
|
| 17 |
+
applicator,
|
| 18 |
+
unevaluated,
|
| 19 |
+
content,
|
| 20 |
+
core,
|
| 21 |
+
with$data(this, format),
|
| 22 |
+
metadata,
|
| 23 |
+
with$data(this, validation),
|
| 24 |
+
].forEach((sch) => this.addMetaSchema(sch, undefined, false))
|
| 25 |
+
return this
|
| 26 |
+
|
| 27 |
+
function with$data(ajv: Ajv, sch: AnySchemaObject): AnySchemaObject {
|
| 28 |
+
return $data ? ajv.$dataMetaSchema(sch, META_SUPPORT_DATA) : sch
|
| 29 |
+
}
|
| 30 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/applicator.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/applicator",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/applicator": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Applicator vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"prefixItems": {"$ref": "#/$defs/schemaArray"},
|
| 13 |
+
"items": {"$dynamicRef": "#meta"},
|
| 14 |
+
"contains": {"$dynamicRef": "#meta"},
|
| 15 |
+
"additionalProperties": {"$dynamicRef": "#meta"},
|
| 16 |
+
"properties": {
|
| 17 |
+
"type": "object",
|
| 18 |
+
"additionalProperties": {"$dynamicRef": "#meta"},
|
| 19 |
+
"default": {}
|
| 20 |
+
},
|
| 21 |
+
"patternProperties": {
|
| 22 |
+
"type": "object",
|
| 23 |
+
"additionalProperties": {"$dynamicRef": "#meta"},
|
| 24 |
+
"propertyNames": {"format": "regex"},
|
| 25 |
+
"default": {}
|
| 26 |
+
},
|
| 27 |
+
"dependentSchemas": {
|
| 28 |
+
"type": "object",
|
| 29 |
+
"additionalProperties": {"$dynamicRef": "#meta"},
|
| 30 |
+
"default": {}
|
| 31 |
+
},
|
| 32 |
+
"propertyNames": {"$dynamicRef": "#meta"},
|
| 33 |
+
"if": {"$dynamicRef": "#meta"},
|
| 34 |
+
"then": {"$dynamicRef": "#meta"},
|
| 35 |
+
"else": {"$dynamicRef": "#meta"},
|
| 36 |
+
"allOf": {"$ref": "#/$defs/schemaArray"},
|
| 37 |
+
"anyOf": {"$ref": "#/$defs/schemaArray"},
|
| 38 |
+
"oneOf": {"$ref": "#/$defs/schemaArray"},
|
| 39 |
+
"not": {"$dynamicRef": "#meta"}
|
| 40 |
+
},
|
| 41 |
+
"$defs": {
|
| 42 |
+
"schemaArray": {
|
| 43 |
+
"type": "array",
|
| 44 |
+
"minItems": 1,
|
| 45 |
+
"items": {"$dynamicRef": "#meta"}
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/content.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/content",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/content": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Content vocabulary meta-schema",
|
| 10 |
+
|
| 11 |
+
"type": ["object", "boolean"],
|
| 12 |
+
"properties": {
|
| 13 |
+
"contentEncoding": {"type": "string"},
|
| 14 |
+
"contentMediaType": {"type": "string"},
|
| 15 |
+
"contentSchema": {"$dynamicRef": "#meta"}
|
| 16 |
+
}
|
| 17 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/core.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/core",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/core": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Core vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"$id": {
|
| 13 |
+
"$ref": "#/$defs/uriReferenceString",
|
| 14 |
+
"$comment": "Non-empty fragments not allowed.",
|
| 15 |
+
"pattern": "^[^#]*#?$"
|
| 16 |
+
},
|
| 17 |
+
"$schema": {"$ref": "#/$defs/uriString"},
|
| 18 |
+
"$ref": {"$ref": "#/$defs/uriReferenceString"},
|
| 19 |
+
"$anchor": {"$ref": "#/$defs/anchorString"},
|
| 20 |
+
"$dynamicRef": {"$ref": "#/$defs/uriReferenceString"},
|
| 21 |
+
"$dynamicAnchor": {"$ref": "#/$defs/anchorString"},
|
| 22 |
+
"$vocabulary": {
|
| 23 |
+
"type": "object",
|
| 24 |
+
"propertyNames": {"$ref": "#/$defs/uriString"},
|
| 25 |
+
"additionalProperties": {
|
| 26 |
+
"type": "boolean"
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"$comment": {
|
| 30 |
+
"type": "string"
|
| 31 |
+
},
|
| 32 |
+
"$defs": {
|
| 33 |
+
"type": "object",
|
| 34 |
+
"additionalProperties": {"$dynamicRef": "#meta"}
|
| 35 |
+
}
|
| 36 |
+
},
|
| 37 |
+
"$defs": {
|
| 38 |
+
"anchorString": {
|
| 39 |
+
"type": "string",
|
| 40 |
+
"pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
|
| 41 |
+
},
|
| 42 |
+
"uriString": {
|
| 43 |
+
"type": "string",
|
| 44 |
+
"format": "uri"
|
| 45 |
+
},
|
| 46 |
+
"uriReferenceString": {
|
| 47 |
+
"type": "string",
|
| 48 |
+
"format": "uri-reference"
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/format-annotation.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/format-annotation",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Format vocabulary meta-schema for annotation results",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"format": {"type": "string"}
|
| 13 |
+
}
|
| 14 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/meta-data.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/meta-data",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Meta-data vocabulary meta-schema",
|
| 10 |
+
|
| 11 |
+
"type": ["object", "boolean"],
|
| 12 |
+
"properties": {
|
| 13 |
+
"title": {
|
| 14 |
+
"type": "string"
|
| 15 |
+
},
|
| 16 |
+
"description": {
|
| 17 |
+
"type": "string"
|
| 18 |
+
},
|
| 19 |
+
"default": true,
|
| 20 |
+
"deprecated": {
|
| 21 |
+
"type": "boolean",
|
| 22 |
+
"default": false
|
| 23 |
+
},
|
| 24 |
+
"readOnly": {
|
| 25 |
+
"type": "boolean",
|
| 26 |
+
"default": false
|
| 27 |
+
},
|
| 28 |
+
"writeOnly": {
|
| 29 |
+
"type": "boolean",
|
| 30 |
+
"default": false
|
| 31 |
+
},
|
| 32 |
+
"examples": {
|
| 33 |
+
"type": "array",
|
| 34 |
+
"items": true
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/unevaluated.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/unevaluated",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Unevaluated applicator vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"unevaluatedItems": {"$dynamicRef": "#meta"},
|
| 13 |
+
"unevaluatedProperties": {"$dynamicRef": "#meta"}
|
| 14 |
+
}
|
| 15 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/meta/validation.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/meta/validation",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/validation": true
|
| 6 |
+
},
|
| 7 |
+
"$dynamicAnchor": "meta",
|
| 8 |
+
|
| 9 |
+
"title": "Validation vocabulary meta-schema",
|
| 10 |
+
"type": ["object", "boolean"],
|
| 11 |
+
"properties": {
|
| 12 |
+
"type": {
|
| 13 |
+
"anyOf": [
|
| 14 |
+
{"$ref": "#/$defs/simpleTypes"},
|
| 15 |
+
{
|
| 16 |
+
"type": "array",
|
| 17 |
+
"items": {"$ref": "#/$defs/simpleTypes"},
|
| 18 |
+
"minItems": 1,
|
| 19 |
+
"uniqueItems": true
|
| 20 |
+
}
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
"const": true,
|
| 24 |
+
"enum": {
|
| 25 |
+
"type": "array",
|
| 26 |
+
"items": true
|
| 27 |
+
},
|
| 28 |
+
"multipleOf": {
|
| 29 |
+
"type": "number",
|
| 30 |
+
"exclusiveMinimum": 0
|
| 31 |
+
},
|
| 32 |
+
"maximum": {
|
| 33 |
+
"type": "number"
|
| 34 |
+
},
|
| 35 |
+
"exclusiveMaximum": {
|
| 36 |
+
"type": "number"
|
| 37 |
+
},
|
| 38 |
+
"minimum": {
|
| 39 |
+
"type": "number"
|
| 40 |
+
},
|
| 41 |
+
"exclusiveMinimum": {
|
| 42 |
+
"type": "number"
|
| 43 |
+
},
|
| 44 |
+
"maxLength": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 45 |
+
"minLength": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
|
| 46 |
+
"pattern": {
|
| 47 |
+
"type": "string",
|
| 48 |
+
"format": "regex"
|
| 49 |
+
},
|
| 50 |
+
"maxItems": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 51 |
+
"minItems": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
|
| 52 |
+
"uniqueItems": {
|
| 53 |
+
"type": "boolean",
|
| 54 |
+
"default": false
|
| 55 |
+
},
|
| 56 |
+
"maxContains": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 57 |
+
"minContains": {
|
| 58 |
+
"$ref": "#/$defs/nonNegativeInteger",
|
| 59 |
+
"default": 1
|
| 60 |
+
},
|
| 61 |
+
"maxProperties": {"$ref": "#/$defs/nonNegativeInteger"},
|
| 62 |
+
"minProperties": {"$ref": "#/$defs/nonNegativeIntegerDefault0"},
|
| 63 |
+
"required": {"$ref": "#/$defs/stringArray"},
|
| 64 |
+
"dependentRequired": {
|
| 65 |
+
"type": "object",
|
| 66 |
+
"additionalProperties": {
|
| 67 |
+
"$ref": "#/$defs/stringArray"
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
},
|
| 71 |
+
"$defs": {
|
| 72 |
+
"nonNegativeInteger": {
|
| 73 |
+
"type": "integer",
|
| 74 |
+
"minimum": 0
|
| 75 |
+
},
|
| 76 |
+
"nonNegativeIntegerDefault0": {
|
| 77 |
+
"$ref": "#/$defs/nonNegativeInteger",
|
| 78 |
+
"default": 0
|
| 79 |
+
},
|
| 80 |
+
"simpleTypes": {
|
| 81 |
+
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
| 82 |
+
},
|
| 83 |
+
"stringArray": {
|
| 84 |
+
"type": "array",
|
| 85 |
+
"items": {"type": "string"},
|
| 86 |
+
"uniqueItems": true,
|
| 87 |
+
"default": []
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
}
|
node_modules/ajv/lib/refs/json-schema-2020-12/schema.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"$id": "https://json-schema.org/draft/2020-12/schema",
|
| 4 |
+
"$vocabulary": {
|
| 5 |
+
"https://json-schema.org/draft/2020-12/vocab/core": true,
|
| 6 |
+
"https://json-schema.org/draft/2020-12/vocab/applicator": true,
|
| 7 |
+
"https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
|
| 8 |
+
"https://json-schema.org/draft/2020-12/vocab/validation": true,
|
| 9 |
+
"https://json-schema.org/draft/2020-12/vocab/meta-data": true,
|
| 10 |
+
"https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
|
| 11 |
+
"https://json-schema.org/draft/2020-12/vocab/content": true
|
| 12 |
+
},
|
| 13 |
+
"$dynamicAnchor": "meta",
|
| 14 |
+
|
| 15 |
+
"title": "Core and Validation specifications meta-schema",
|
| 16 |
+
"allOf": [
|
| 17 |
+
{"$ref": "meta/core"},
|
| 18 |
+
{"$ref": "meta/applicator"},
|
| 19 |
+
{"$ref": "meta/unevaluated"},
|
| 20 |
+
{"$ref": "meta/validation"},
|
| 21 |
+
{"$ref": "meta/meta-data"},
|
| 22 |
+
{"$ref": "meta/format-annotation"},
|
| 23 |
+
{"$ref": "meta/content"}
|
| 24 |
+
],
|
| 25 |
+
"type": ["object", "boolean"],
|
| 26 |
+
"$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",
|
| 27 |
+
"properties": {
|
| 28 |
+
"definitions": {
|
| 29 |
+
"$comment": "\"definitions\" has been replaced by \"$defs\".",
|
| 30 |
+
"type": "object",
|
| 31 |
+
"additionalProperties": {"$dynamicRef": "#meta"},
|
| 32 |
+
"deprecated": true,
|
| 33 |
+
"default": {}
|
| 34 |
+
},
|
| 35 |
+
"dependencies": {
|
| 36 |
+
"$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.",
|
| 37 |
+
"type": "object",
|
| 38 |
+
"additionalProperties": {
|
| 39 |
+
"anyOf": [{"$dynamicRef": "#meta"}, {"$ref": "meta/validation#/$defs/stringArray"}]
|
| 40 |
+
},
|
| 41 |
+
"deprecated": true,
|
| 42 |
+
"default": {}
|
| 43 |
+
},
|
| 44 |
+
"$recursiveAnchor": {
|
| 45 |
+
"$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".",
|
| 46 |
+
"$ref": "meta/core#/$defs/anchorString",
|
| 47 |
+
"deprecated": true
|
| 48 |
+
},
|
| 49 |
+
"$recursiveRef": {
|
| 50 |
+
"$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".",
|
| 51 |
+
"$ref": "meta/core#/$defs/uriReferenceString",
|
| 52 |
+
"deprecated": true
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
}
|
node_modules/ajv/lib/refs/json-schema-draft-06.json
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-06/schema#",
|
| 3 |
+
"$id": "http://json-schema.org/draft-06/schema#",
|
| 4 |
+
"title": "Core schema meta-schema",
|
| 5 |
+
"definitions": {
|
| 6 |
+
"schemaArray": {
|
| 7 |
+
"type": "array",
|
| 8 |
+
"minItems": 1,
|
| 9 |
+
"items": {"$ref": "#"}
|
| 10 |
+
},
|
| 11 |
+
"nonNegativeInteger": {
|
| 12 |
+
"type": "integer",
|
| 13 |
+
"minimum": 0
|
| 14 |
+
},
|
| 15 |
+
"nonNegativeIntegerDefault0": {
|
| 16 |
+
"allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
|
| 17 |
+
},
|
| 18 |
+
"simpleTypes": {
|
| 19 |
+
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
| 20 |
+
},
|
| 21 |
+
"stringArray": {
|
| 22 |
+
"type": "array",
|
| 23 |
+
"items": {"type": "string"},
|
| 24 |
+
"uniqueItems": true,
|
| 25 |
+
"default": []
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"type": ["object", "boolean"],
|
| 29 |
+
"properties": {
|
| 30 |
+
"$id": {
|
| 31 |
+
"type": "string",
|
| 32 |
+
"format": "uri-reference"
|
| 33 |
+
},
|
| 34 |
+
"$schema": {
|
| 35 |
+
"type": "string",
|
| 36 |
+
"format": "uri"
|
| 37 |
+
},
|
| 38 |
+
"$ref": {
|
| 39 |
+
"type": "string",
|
| 40 |
+
"format": "uri-reference"
|
| 41 |
+
},
|
| 42 |
+
"title": {
|
| 43 |
+
"type": "string"
|
| 44 |
+
},
|
| 45 |
+
"description": {
|
| 46 |
+
"type": "string"
|
| 47 |
+
},
|
| 48 |
+
"default": {},
|
| 49 |
+
"examples": {
|
| 50 |
+
"type": "array",
|
| 51 |
+
"items": {}
|
| 52 |
+
},
|
| 53 |
+
"multipleOf": {
|
| 54 |
+
"type": "number",
|
| 55 |
+
"exclusiveMinimum": 0
|
| 56 |
+
},
|
| 57 |
+
"maximum": {
|
| 58 |
+
"type": "number"
|
| 59 |
+
},
|
| 60 |
+
"exclusiveMaximum": {
|
| 61 |
+
"type": "number"
|
| 62 |
+
},
|
| 63 |
+
"minimum": {
|
| 64 |
+
"type": "number"
|
| 65 |
+
},
|
| 66 |
+
"exclusiveMinimum": {
|
| 67 |
+
"type": "number"
|
| 68 |
+
},
|
| 69 |
+
"maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
|
| 70 |
+
"minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
|
| 71 |
+
"pattern": {
|
| 72 |
+
"type": "string",
|
| 73 |
+
"format": "regex"
|
| 74 |
+
},
|
| 75 |
+
"additionalItems": {"$ref": "#"},
|
| 76 |
+
"items": {
|
| 77 |
+
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
|
| 78 |
+
"default": {}
|
| 79 |
+
},
|
| 80 |
+
"maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
|
| 81 |
+
"minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
|
| 82 |
+
"uniqueItems": {
|
| 83 |
+
"type": "boolean",
|
| 84 |
+
"default": false
|
| 85 |
+
},
|
| 86 |
+
"contains": {"$ref": "#"},
|
| 87 |
+
"maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
|
| 88 |
+
"minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
|
| 89 |
+
"required": {"$ref": "#/definitions/stringArray"},
|
| 90 |
+
"additionalProperties": {"$ref": "#"},
|
| 91 |
+
"definitions": {
|
| 92 |
+
"type": "object",
|
| 93 |
+
"additionalProperties": {"$ref": "#"},
|
| 94 |
+
"default": {}
|
| 95 |
+
},
|
| 96 |
+
"properties": {
|
| 97 |
+
"type": "object",
|
| 98 |
+
"additionalProperties": {"$ref": "#"},
|
| 99 |
+
"default": {}
|
| 100 |
+
},
|
| 101 |
+
"patternProperties": {
|
| 102 |
+
"type": "object",
|
| 103 |
+
"additionalProperties": {"$ref": "#"},
|
| 104 |
+
"default": {}
|
| 105 |
+
},
|
| 106 |
+
"dependencies": {
|
| 107 |
+
"type": "object",
|
| 108 |
+
"additionalProperties": {
|
| 109 |
+
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
"propertyNames": {"$ref": "#"},
|
| 113 |
+
"const": {},
|
| 114 |
+
"enum": {
|
| 115 |
+
"type": "array",
|
| 116 |
+
"minItems": 1,
|
| 117 |
+
"uniqueItems": true
|
| 118 |
+
},
|
| 119 |
+
"type": {
|
| 120 |
+
"anyOf": [
|
| 121 |
+
{"$ref": "#/definitions/simpleTypes"},
|
| 122 |
+
{
|
| 123 |
+
"type": "array",
|
| 124 |
+
"items": {"$ref": "#/definitions/simpleTypes"},
|
| 125 |
+
"minItems": 1,
|
| 126 |
+
"uniqueItems": true
|
| 127 |
+
}
|
| 128 |
+
]
|
| 129 |
+
},
|
| 130 |
+
"format": {"type": "string"},
|
| 131 |
+
"allOf": {"$ref": "#/definitions/schemaArray"},
|
| 132 |
+
"anyOf": {"$ref": "#/definitions/schemaArray"},
|
| 133 |
+
"oneOf": {"$ref": "#/definitions/schemaArray"},
|
| 134 |
+
"not": {"$ref": "#"}
|
| 135 |
+
},
|
| 136 |
+
"default": {}
|
| 137 |
+
}
|
node_modules/ajv/lib/refs/json-schema-draft-07.json
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 3 |
+
"$id": "http://json-schema.org/draft-07/schema#",
|
| 4 |
+
"title": "Core schema meta-schema",
|
| 5 |
+
"definitions": {
|
| 6 |
+
"schemaArray": {
|
| 7 |
+
"type": "array",
|
| 8 |
+
"minItems": 1,
|
| 9 |
+
"items": {"$ref": "#"}
|
| 10 |
+
},
|
| 11 |
+
"nonNegativeInteger": {
|
| 12 |
+
"type": "integer",
|
| 13 |
+
"minimum": 0
|
| 14 |
+
},
|
| 15 |
+
"nonNegativeIntegerDefault0": {
|
| 16 |
+
"allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
|
| 17 |
+
},
|
| 18 |
+
"simpleTypes": {
|
| 19 |
+
"enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
|
| 20 |
+
},
|
| 21 |
+
"stringArray": {
|
| 22 |
+
"type": "array",
|
| 23 |
+
"items": {"type": "string"},
|
| 24 |
+
"uniqueItems": true,
|
| 25 |
+
"default": []
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"type": ["object", "boolean"],
|
| 29 |
+
"properties": {
|
| 30 |
+
"$id": {
|
| 31 |
+
"type": "string",
|
| 32 |
+
"format": "uri-reference"
|
| 33 |
+
},
|
| 34 |
+
"$schema": {
|
| 35 |
+
"type": "string",
|
| 36 |
+
"format": "uri"
|
| 37 |
+
},
|
| 38 |
+
"$ref": {
|
| 39 |
+
"type": "string",
|
| 40 |
+
"format": "uri-reference"
|
| 41 |
+
},
|
| 42 |
+
"$comment": {
|
| 43 |
+
"type": "string"
|
| 44 |
+
},
|
| 45 |
+
"title": {
|
| 46 |
+
"type": "string"
|
| 47 |
+
},
|
| 48 |
+
"description": {
|
| 49 |
+
"type": "string"
|
| 50 |
+
},
|
| 51 |
+
"default": true,
|
| 52 |
+
"readOnly": {
|
| 53 |
+
"type": "boolean",
|
| 54 |
+
"default": false
|
| 55 |
+
},
|
| 56 |
+
"examples": {
|
| 57 |
+
"type": "array",
|
| 58 |
+
"items": true
|
| 59 |
+
},
|
| 60 |
+
"multipleOf": {
|
| 61 |
+
"type": "number",
|
| 62 |
+
"exclusiveMinimum": 0
|
| 63 |
+
},
|
| 64 |
+
"maximum": {
|
| 65 |
+
"type": "number"
|
| 66 |
+
},
|
| 67 |
+
"exclusiveMaximum": {
|
| 68 |
+
"type": "number"
|
| 69 |
+
},
|
| 70 |
+
"minimum": {
|
| 71 |
+
"type": "number"
|
| 72 |
+
},
|
| 73 |
+
"exclusiveMinimum": {
|
| 74 |
+
"type": "number"
|
| 75 |
+
},
|
| 76 |
+
"maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
|
| 77 |
+
"minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
|
| 78 |
+
"pattern": {
|
| 79 |
+
"type": "string",
|
| 80 |
+
"format": "regex"
|
| 81 |
+
},
|
| 82 |
+
"additionalItems": {"$ref": "#"},
|
| 83 |
+
"items": {
|
| 84 |
+
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
|
| 85 |
+
"default": true
|
| 86 |
+
},
|
| 87 |
+
"maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
|
| 88 |
+
"minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
|
| 89 |
+
"uniqueItems": {
|
| 90 |
+
"type": "boolean",
|
| 91 |
+
"default": false
|
| 92 |
+
},
|
| 93 |
+
"contains": {"$ref": "#"},
|
| 94 |
+
"maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
|
| 95 |
+
"minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
|
| 96 |
+
"required": {"$ref": "#/definitions/stringArray"},
|
| 97 |
+
"additionalProperties": {"$ref": "#"},
|
| 98 |
+
"definitions": {
|
| 99 |
+
"type": "object",
|
| 100 |
+
"additionalProperties": {"$ref": "#"},
|
| 101 |
+
"default": {}
|
| 102 |
+
},
|
| 103 |
+
"properties": {
|
| 104 |
+
"type": "object",
|
| 105 |
+
"additionalProperties": {"$ref": "#"},
|
| 106 |
+
"default": {}
|
| 107 |
+
},
|
| 108 |
+
"patternProperties": {
|
| 109 |
+
"type": "object",
|
| 110 |
+
"additionalProperties": {"$ref": "#"},
|
| 111 |
+
"propertyNames": {"format": "regex"},
|
| 112 |
+
"default": {}
|
| 113 |
+
},
|
| 114 |
+
"dependencies": {
|
| 115 |
+
"type": "object",
|
| 116 |
+
"additionalProperties": {
|
| 117 |
+
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
|
| 118 |
+
}
|
| 119 |
+
},
|
| 120 |
+
"propertyNames": {"$ref": "#"},
|
| 121 |
+
"const": true,
|
| 122 |
+
"enum": {
|
| 123 |
+
"type": "array",
|
| 124 |
+
"items": true,
|
| 125 |
+
"minItems": 1,
|
| 126 |
+
"uniqueItems": true
|
| 127 |
+
},
|
| 128 |
+
"type": {
|
| 129 |
+
"anyOf": [
|
| 130 |
+
{"$ref": "#/definitions/simpleTypes"},
|
| 131 |
+
{
|
| 132 |
+
"type": "array",
|
| 133 |
+
"items": {"$ref": "#/definitions/simpleTypes"},
|
| 134 |
+
"minItems": 1,
|
| 135 |
+
"uniqueItems": true
|
| 136 |
+
}
|
| 137 |
+
]
|
| 138 |
+
},
|
| 139 |
+
"format": {"type": "string"},
|
| 140 |
+
"contentMediaType": {"type": "string"},
|
| 141 |
+
"contentEncoding": {"type": "string"},
|
| 142 |
+
"if": {"$ref": "#"},
|
| 143 |
+
"then": {"$ref": "#"},
|
| 144 |
+
"else": {"$ref": "#"},
|
| 145 |
+
"allOf": {"$ref": "#/definitions/schemaArray"},
|
| 146 |
+
"anyOf": {"$ref": "#/definitions/schemaArray"},
|
| 147 |
+
"oneOf": {"$ref": "#/definitions/schemaArray"},
|
| 148 |
+
"not": {"$ref": "#"}
|
| 149 |
+
},
|
| 150 |
+
"default": true
|
| 151 |
+
}
|
node_modules/ajv/lib/refs/json-schema-secure.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
| 3 |
+
"$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/json-schema-secure.json#",
|
| 4 |
+
"title": "Meta-schema for the security assessment of JSON Schemas",
|
| 5 |
+
"description": "If a JSON AnySchema fails validation against this meta-schema, it may be unsafe to validate untrusted data",
|
| 6 |
+
"definitions": {
|
| 7 |
+
"schemaArray": {
|
| 8 |
+
"type": "array",
|
| 9 |
+
"minItems": 1,
|
| 10 |
+
"items": {"$ref": "#"}
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"dependencies": {
|
| 14 |
+
"patternProperties": {
|
| 15 |
+
"description": "prevent slow validation of large property names",
|
| 16 |
+
"required": ["propertyNames"],
|
| 17 |
+
"properties": {
|
| 18 |
+
"propertyNames": {
|
| 19 |
+
"required": ["maxLength"]
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
"uniqueItems": {
|
| 24 |
+
"description": "prevent slow validation of large non-scalar arrays",
|
| 25 |
+
"if": {
|
| 26 |
+
"properties": {
|
| 27 |
+
"uniqueItems": {"const": true},
|
| 28 |
+
"items": {
|
| 29 |
+
"properties": {
|
| 30 |
+
"type": {
|
| 31 |
+
"anyOf": [
|
| 32 |
+
{
|
| 33 |
+
"enum": ["object", "array"]
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"type": "array",
|
| 37 |
+
"contains": {"enum": ["object", "array"]}
|
| 38 |
+
}
|
| 39 |
+
]
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"then": {
|
| 46 |
+
"required": ["maxItems"]
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
"pattern": {
|
| 50 |
+
"description": "prevent slow pattern matching of large strings",
|
| 51 |
+
"required": ["maxLength"]
|
| 52 |
+
},
|
| 53 |
+
"format": {
|
| 54 |
+
"description": "prevent slow format validation of large strings",
|
| 55 |
+
"required": ["maxLength"]
|
| 56 |
+
}
|
| 57 |
+
},
|
| 58 |
+
"properties": {
|
| 59 |
+
"additionalItems": {"$ref": "#"},
|
| 60 |
+
"additionalProperties": {"$ref": "#"},
|
| 61 |
+
"dependencies": {
|
| 62 |
+
"additionalProperties": {
|
| 63 |
+
"anyOf": [{"type": "array"}, {"$ref": "#"}]
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"items": {
|
| 67 |
+
"anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}]
|
| 68 |
+
},
|
| 69 |
+
"definitions": {
|
| 70 |
+
"additionalProperties": {"$ref": "#"}
|
| 71 |
+
},
|
| 72 |
+
"patternProperties": {
|
| 73 |
+
"additionalProperties": {"$ref": "#"}
|
| 74 |
+
},
|
| 75 |
+
"properties": {
|
| 76 |
+
"additionalProperties": {"$ref": "#"}
|
| 77 |
+
},
|
| 78 |
+
"if": {"$ref": "#"},
|
| 79 |
+
"then": {"$ref": "#"},
|
| 80 |
+
"else": {"$ref": "#"},
|
| 81 |
+
"allOf": {"$ref": "#/definitions/schemaArray"},
|
| 82 |
+
"anyOf": {"$ref": "#/definitions/schemaArray"},
|
| 83 |
+
"oneOf": {"$ref": "#/definitions/schemaArray"},
|
| 84 |
+
"not": {"$ref": "#"},
|
| 85 |
+
"contains": {"$ref": "#"},
|
| 86 |
+
"propertyNames": {"$ref": "#"}
|
| 87 |
+
}
|
| 88 |
+
}
|
node_modules/ajv/lib/refs/jtd-schema.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {SchemaObject} from "../types"
|
| 2 |
+
|
| 3 |
+
type MetaSchema = (root: boolean) => SchemaObject
|
| 4 |
+
|
| 5 |
+
const shared: MetaSchema = (root) => {
|
| 6 |
+
const sch: SchemaObject = {
|
| 7 |
+
nullable: {type: "boolean"},
|
| 8 |
+
metadata: {
|
| 9 |
+
optionalProperties: {
|
| 10 |
+
union: {elements: {ref: "schema"}},
|
| 11 |
+
},
|
| 12 |
+
additionalProperties: true,
|
| 13 |
+
},
|
| 14 |
+
}
|
| 15 |
+
if (root) sch.definitions = {values: {ref: "schema"}}
|
| 16 |
+
return sch
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
const emptyForm: MetaSchema = (root) => ({
|
| 20 |
+
optionalProperties: shared(root),
|
| 21 |
+
})
|
| 22 |
+
|
| 23 |
+
const refForm: MetaSchema = (root) => ({
|
| 24 |
+
properties: {
|
| 25 |
+
ref: {type: "string"},
|
| 26 |
+
},
|
| 27 |
+
optionalProperties: shared(root),
|
| 28 |
+
})
|
| 29 |
+
|
| 30 |
+
const typeForm: MetaSchema = (root) => ({
|
| 31 |
+
properties: {
|
| 32 |
+
type: {
|
| 33 |
+
enum: [
|
| 34 |
+
"boolean",
|
| 35 |
+
"timestamp",
|
| 36 |
+
"string",
|
| 37 |
+
"float32",
|
| 38 |
+
"float64",
|
| 39 |
+
"int8",
|
| 40 |
+
"uint8",
|
| 41 |
+
"int16",
|
| 42 |
+
"uint16",
|
| 43 |
+
"int32",
|
| 44 |
+
"uint32",
|
| 45 |
+
],
|
| 46 |
+
},
|
| 47 |
+
},
|
| 48 |
+
optionalProperties: shared(root),
|
| 49 |
+
})
|
| 50 |
+
|
| 51 |
+
const enumForm: MetaSchema = (root) => ({
|
| 52 |
+
properties: {
|
| 53 |
+
enum: {elements: {type: "string"}},
|
| 54 |
+
},
|
| 55 |
+
optionalProperties: shared(root),
|
| 56 |
+
})
|
| 57 |
+
|
| 58 |
+
const elementsForm: MetaSchema = (root) => ({
|
| 59 |
+
properties: {
|
| 60 |
+
elements: {ref: "schema"},
|
| 61 |
+
},
|
| 62 |
+
optionalProperties: shared(root),
|
| 63 |
+
})
|
| 64 |
+
|
| 65 |
+
const propertiesForm: MetaSchema = (root) => ({
|
| 66 |
+
properties: {
|
| 67 |
+
properties: {values: {ref: "schema"}},
|
| 68 |
+
},
|
| 69 |
+
optionalProperties: {
|
| 70 |
+
optionalProperties: {values: {ref: "schema"}},
|
| 71 |
+
additionalProperties: {type: "boolean"},
|
| 72 |
+
...shared(root),
|
| 73 |
+
},
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
const optionalPropertiesForm: MetaSchema = (root) => ({
|
| 77 |
+
properties: {
|
| 78 |
+
optionalProperties: {values: {ref: "schema"}},
|
| 79 |
+
},
|
| 80 |
+
optionalProperties: {
|
| 81 |
+
additionalProperties: {type: "boolean"},
|
| 82 |
+
...shared(root),
|
| 83 |
+
},
|
| 84 |
+
})
|
| 85 |
+
|
| 86 |
+
const discriminatorForm: MetaSchema = (root) => ({
|
| 87 |
+
properties: {
|
| 88 |
+
discriminator: {type: "string"},
|
| 89 |
+
mapping: {
|
| 90 |
+
values: {
|
| 91 |
+
metadata: {
|
| 92 |
+
union: [propertiesForm(false), optionalPropertiesForm(false)],
|
| 93 |
+
},
|
| 94 |
+
},
|
| 95 |
+
},
|
| 96 |
+
},
|
| 97 |
+
optionalProperties: shared(root),
|
| 98 |
+
})
|
| 99 |
+
|
| 100 |
+
const valuesForm: MetaSchema = (root) => ({
|
| 101 |
+
properties: {
|
| 102 |
+
values: {ref: "schema"},
|
| 103 |
+
},
|
| 104 |
+
optionalProperties: shared(root),
|
| 105 |
+
})
|
| 106 |
+
|
| 107 |
+
const schema: MetaSchema = (root) => ({
|
| 108 |
+
metadata: {
|
| 109 |
+
union: [
|
| 110 |
+
emptyForm,
|
| 111 |
+
refForm,
|
| 112 |
+
typeForm,
|
| 113 |
+
enumForm,
|
| 114 |
+
elementsForm,
|
| 115 |
+
propertiesForm,
|
| 116 |
+
optionalPropertiesForm,
|
| 117 |
+
discriminatorForm,
|
| 118 |
+
valuesForm,
|
| 119 |
+
].map((s) => s(root)),
|
| 120 |
+
},
|
| 121 |
+
})
|
| 122 |
+
|
| 123 |
+
const jtdMetaSchema: SchemaObject = {
|
| 124 |
+
definitions: {
|
| 125 |
+
schema: schema(false),
|
| 126 |
+
},
|
| 127 |
+
...schema(true),
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
export default jtdMetaSchema
|
node_modules/ajv/lib/runtime/equal.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://github.com/ajv-validator/ajv/issues/889
|
| 2 |
+
import * as equal from "fast-deep-equal"
|
| 3 |
+
|
| 4 |
+
type Equal = typeof equal & {code: string}
|
| 5 |
+
;(equal as Equal).code = 'require("ajv/dist/runtime/equal").default'
|
| 6 |
+
|
| 7 |
+
export default equal as Equal
|
node_modules/ajv/lib/runtime/parseJson.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const rxParseJson = /position\s(\d+)(?: \(line \d+ column \d+\))?$/
|
| 2 |
+
|
| 3 |
+
export function parseJson(s: string, pos: number): unknown {
|
| 4 |
+
let endPos: number | undefined
|
| 5 |
+
parseJson.message = undefined
|
| 6 |
+
let matches: RegExpExecArray | null
|
| 7 |
+
if (pos) s = s.slice(pos)
|
| 8 |
+
try {
|
| 9 |
+
parseJson.position = pos + s.length
|
| 10 |
+
return JSON.parse(s)
|
| 11 |
+
} catch (e) {
|
| 12 |
+
matches = rxParseJson.exec((e as Error).message)
|
| 13 |
+
if (!matches) {
|
| 14 |
+
parseJson.message = "unexpected end"
|
| 15 |
+
return undefined
|
| 16 |
+
}
|
| 17 |
+
endPos = +matches[1]
|
| 18 |
+
const c = s[endPos]
|
| 19 |
+
s = s.slice(0, endPos)
|
| 20 |
+
parseJson.position = pos + endPos
|
| 21 |
+
try {
|
| 22 |
+
return JSON.parse(s)
|
| 23 |
+
} catch (e1) {
|
| 24 |
+
parseJson.message = `unexpected token ${c}`
|
| 25 |
+
return undefined
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
parseJson.message = undefined as string | undefined
|
| 31 |
+
parseJson.position = 0 as number
|
| 32 |
+
parseJson.code = 'require("ajv/dist/runtime/parseJson").parseJson'
|
| 33 |
+
|
| 34 |
+
export function parseJsonNumber(s: string, pos: number, maxDigits?: number): number | undefined {
|
| 35 |
+
let numStr = ""
|
| 36 |
+
let c: string
|
| 37 |
+
parseJsonNumber.message = undefined
|
| 38 |
+
if (s[pos] === "-") {
|
| 39 |
+
numStr += "-"
|
| 40 |
+
pos++
|
| 41 |
+
}
|
| 42 |
+
if (s[pos] === "0") {
|
| 43 |
+
numStr += "0"
|
| 44 |
+
pos++
|
| 45 |
+
} else {
|
| 46 |
+
if (!parseDigits(maxDigits)) {
|
| 47 |
+
errorMessage()
|
| 48 |
+
return undefined
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
if (maxDigits) {
|
| 52 |
+
parseJsonNumber.position = pos
|
| 53 |
+
return +numStr
|
| 54 |
+
}
|
| 55 |
+
if (s[pos] === ".") {
|
| 56 |
+
numStr += "."
|
| 57 |
+
pos++
|
| 58 |
+
if (!parseDigits()) {
|
| 59 |
+
errorMessage()
|
| 60 |
+
return undefined
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
if (((c = s[pos]), c === "e" || c === "E")) {
|
| 64 |
+
numStr += "e"
|
| 65 |
+
pos++
|
| 66 |
+
if (((c = s[pos]), c === "+" || c === "-")) {
|
| 67 |
+
numStr += c
|
| 68 |
+
pos++
|
| 69 |
+
}
|
| 70 |
+
if (!parseDigits()) {
|
| 71 |
+
errorMessage()
|
| 72 |
+
return undefined
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
parseJsonNumber.position = pos
|
| 76 |
+
return +numStr
|
| 77 |
+
|
| 78 |
+
function parseDigits(maxLen?: number): boolean {
|
| 79 |
+
let digit = false
|
| 80 |
+
while (((c = s[pos]), c >= "0" && c <= "9" && (maxLen === undefined || maxLen-- > 0))) {
|
| 81 |
+
digit = true
|
| 82 |
+
numStr += c
|
| 83 |
+
pos++
|
| 84 |
+
}
|
| 85 |
+
return digit
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
function errorMessage(): void {
|
| 89 |
+
parseJsonNumber.position = pos
|
| 90 |
+
parseJsonNumber.message = pos < s.length ? `unexpected token ${s[pos]}` : "unexpected end"
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
parseJsonNumber.message = undefined as string | undefined
|
| 95 |
+
parseJsonNumber.position = 0 as number
|
| 96 |
+
parseJsonNumber.code = 'require("ajv/dist/runtime/parseJson").parseJsonNumber'
|
| 97 |
+
|
| 98 |
+
const escapedChars: {[X in string]?: string} = {
|
| 99 |
+
b: "\b",
|
| 100 |
+
f: "\f",
|
| 101 |
+
n: "\n",
|
| 102 |
+
r: "\r",
|
| 103 |
+
t: "\t",
|
| 104 |
+
'"': '"',
|
| 105 |
+
"/": "/",
|
| 106 |
+
"\\": "\\",
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
const CODE_A: number = "a".charCodeAt(0)
|
| 110 |
+
const CODE_0: number = "0".charCodeAt(0)
|
| 111 |
+
|
| 112 |
+
export function parseJsonString(s: string, pos: number): string | undefined {
|
| 113 |
+
let str = ""
|
| 114 |
+
let c: string | undefined
|
| 115 |
+
parseJsonString.message = undefined
|
| 116 |
+
// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
|
| 117 |
+
while (true) {
|
| 118 |
+
c = s[pos++]
|
| 119 |
+
if (c === '"') break
|
| 120 |
+
if (c === "\\") {
|
| 121 |
+
c = s[pos]
|
| 122 |
+
if (c in escapedChars) {
|
| 123 |
+
str += escapedChars[c]
|
| 124 |
+
pos++
|
| 125 |
+
} else if (c === "u") {
|
| 126 |
+
pos++
|
| 127 |
+
let count = 4
|
| 128 |
+
let code = 0
|
| 129 |
+
while (count--) {
|
| 130 |
+
code <<= 4
|
| 131 |
+
c = s[pos]
|
| 132 |
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
| 133 |
+
if (c === undefined) {
|
| 134 |
+
errorMessage("unexpected end")
|
| 135 |
+
return undefined
|
| 136 |
+
}
|
| 137 |
+
c = c.toLowerCase()
|
| 138 |
+
if (c >= "a" && c <= "f") {
|
| 139 |
+
code += c.charCodeAt(0) - CODE_A + 10
|
| 140 |
+
} else if (c >= "0" && c <= "9") {
|
| 141 |
+
code += c.charCodeAt(0) - CODE_0
|
| 142 |
+
} else {
|
| 143 |
+
errorMessage(`unexpected token ${c}`)
|
| 144 |
+
return undefined
|
| 145 |
+
}
|
| 146 |
+
pos++
|
| 147 |
+
}
|
| 148 |
+
str += String.fromCharCode(code)
|
| 149 |
+
} else {
|
| 150 |
+
errorMessage(`unexpected token ${c}`)
|
| 151 |
+
return undefined
|
| 152 |
+
}
|
| 153 |
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
| 154 |
+
} else if (c === undefined) {
|
| 155 |
+
errorMessage("unexpected end")
|
| 156 |
+
return undefined
|
| 157 |
+
} else {
|
| 158 |
+
if (c.charCodeAt(0) >= 0x20) {
|
| 159 |
+
str += c
|
| 160 |
+
} else {
|
| 161 |
+
errorMessage(`unexpected token ${c}`)
|
| 162 |
+
return undefined
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
parseJsonString.position = pos
|
| 167 |
+
return str
|
| 168 |
+
|
| 169 |
+
function errorMessage(msg: string): void {
|
| 170 |
+
parseJsonString.position = pos
|
| 171 |
+
parseJsonString.message = msg
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
parseJsonString.message = undefined as string | undefined
|
| 176 |
+
parseJsonString.position = 0 as number
|
| 177 |
+
parseJsonString.code = 'require("ajv/dist/runtime/parseJson").parseJsonString'
|
node_modules/ajv/lib/runtime/quote.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const rxEscapable =
|
| 2 |
+
// eslint-disable-next-line no-control-regex, no-misleading-character-class
|
| 3 |
+
/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
|
| 4 |
+
|
| 5 |
+
const escaped: {[K in string]?: string} = {
|
| 6 |
+
"\b": "\\b",
|
| 7 |
+
"\t": "\\t",
|
| 8 |
+
"\n": "\\n",
|
| 9 |
+
"\f": "\\f",
|
| 10 |
+
"\r": "\\r",
|
| 11 |
+
'"': '\\"',
|
| 12 |
+
"\\": "\\\\",
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export default function quote(s: string): string {
|
| 16 |
+
rxEscapable.lastIndex = 0
|
| 17 |
+
return (
|
| 18 |
+
'"' +
|
| 19 |
+
(rxEscapable.test(s)
|
| 20 |
+
? s.replace(rxEscapable, (a) => {
|
| 21 |
+
const c = escaped[a]
|
| 22 |
+
return typeof c === "string"
|
| 23 |
+
? c
|
| 24 |
+
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
|
| 25 |
+
})
|
| 26 |
+
: s) +
|
| 27 |
+
'"'
|
| 28 |
+
)
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
quote.code = 'require("ajv/dist/runtime/quote").default'
|
node_modules/ajv/lib/runtime/re2.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as re2 from "re2"
|
| 2 |
+
|
| 3 |
+
type Re2 = typeof re2 & {code: string}
|
| 4 |
+
;(re2 as Re2).code = 'require("ajv/dist/runtime/re2").default'
|
| 5 |
+
|
| 6 |
+
export default re2 as Re2
|
node_modules/ajv/lib/runtime/timestamp.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const DT_SEPARATOR = /t|\s/i
|
| 2 |
+
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
|
| 3 |
+
const TIME = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i
|
| 4 |
+
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
| 5 |
+
|
| 6 |
+
export default function validTimestamp(str: string, allowDate: boolean): boolean {
|
| 7 |
+
// http://tools.ietf.org/html/rfc3339#section-5.6
|
| 8 |
+
const dt: string[] = str.split(DT_SEPARATOR)
|
| 9 |
+
return (
|
| 10 |
+
(dt.length === 2 && validDate(dt[0]) && validTime(dt[1])) ||
|
| 11 |
+
(allowDate && dt.length === 1 && validDate(dt[0]))
|
| 12 |
+
)
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function validDate(str: string): boolean {
|
| 16 |
+
const matches: string[] | null = DATE.exec(str)
|
| 17 |
+
if (!matches) return false
|
| 18 |
+
const y: number = +matches[1]
|
| 19 |
+
const m: number = +matches[2]
|
| 20 |
+
const d: number = +matches[3]
|
| 21 |
+
return (
|
| 22 |
+
m >= 1 &&
|
| 23 |
+
m <= 12 &&
|
| 24 |
+
d >= 1 &&
|
| 25 |
+
(d <= DAYS[m] ||
|
| 26 |
+
// leap year: https://tools.ietf.org/html/rfc3339#appendix-C
|
| 27 |
+
(m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0)))
|
| 28 |
+
)
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function validTime(str: string): boolean {
|
| 32 |
+
const matches: string[] | null = TIME.exec(str)
|
| 33 |
+
if (!matches) return false
|
| 34 |
+
const hr: number = +matches[1]
|
| 35 |
+
const min: number = +matches[2]
|
| 36 |
+
const sec: number = +matches[3]
|
| 37 |
+
const tzH: number = +(matches[4] || 0)
|
| 38 |
+
const tzM: number = +(matches[5] || 0)
|
| 39 |
+
return (
|
| 40 |
+
(hr <= 23 && min <= 59 && sec <= 59) ||
|
| 41 |
+
// leap second
|
| 42 |
+
(hr - tzH === 23 && min - tzM === 59 && sec === 60)
|
| 43 |
+
)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
validTimestamp.code = 'require("ajv/dist/runtime/timestamp").default'
|
node_modules/ajv/lib/runtime/ucs2length.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://mathiasbynens.be/notes/javascript-encoding
|
| 2 |
+
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
|
| 3 |
+
export default function ucs2length(str: string): number {
|
| 4 |
+
const len = str.length
|
| 5 |
+
let length = 0
|
| 6 |
+
let pos = 0
|
| 7 |
+
let value: number
|
| 8 |
+
while (pos < len) {
|
| 9 |
+
length++
|
| 10 |
+
value = str.charCodeAt(pos++)
|
| 11 |
+
if (value >= 0xd800 && value <= 0xdbff && pos < len) {
|
| 12 |
+
// high surrogate, and there is a next character
|
| 13 |
+
value = str.charCodeAt(pos)
|
| 14 |
+
if ((value & 0xfc00) === 0xdc00) pos++ // low surrogate
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
return length
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default'
|
node_modules/ajv/lib/runtime/uri.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as uri from "fast-uri"
|
| 2 |
+
|
| 3 |
+
type URI = typeof uri & {code: string}
|
| 4 |
+
;(uri as URI).code = 'require("ajv/dist/runtime/uri").default'
|
| 5 |
+
|
| 6 |
+
export default uri as URI
|
node_modules/ajv/lib/runtime/validation_error.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {ErrorObject} from "../types"
|
| 2 |
+
|
| 3 |
+
export default class ValidationError extends Error {
|
| 4 |
+
readonly errors: Partial<ErrorObject>[]
|
| 5 |
+
readonly ajv: true
|
| 6 |
+
readonly validation: true
|
| 7 |
+
|
| 8 |
+
constructor(errors: Partial<ErrorObject>[]) {
|
| 9 |
+
super("validation failed")
|
| 10 |
+
this.errors = errors
|
| 11 |
+
this.ajv = this.validation = true
|
| 12 |
+
}
|
| 13 |
+
}
|
node_modules/ajv/lib/standalone/index.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type AjvCore from "../core"
|
| 2 |
+
import type {AnyValidateFunction, SourceCode} from "../types"
|
| 3 |
+
import type {SchemaEnv} from "../compile"
|
| 4 |
+
import {UsedScopeValues, UsedValueState, ValueScopeName, varKinds} from "../compile/codegen/scope"
|
| 5 |
+
import {_, nil, _Code, Code, getProperty, getEsmExportName} from "../compile/codegen/code"
|
| 6 |
+
|
| 7 |
+
function standaloneCode(
|
| 8 |
+
ajv: AjvCore,
|
| 9 |
+
refsOrFunc?: {[K in string]?: string} | AnyValidateFunction
|
| 10 |
+
): string {
|
| 11 |
+
if (!ajv.opts.code.source) {
|
| 12 |
+
throw new Error("moduleCode: ajv instance must have code.source option")
|
| 13 |
+
}
|
| 14 |
+
const {_n} = ajv.scope.opts
|
| 15 |
+
return typeof refsOrFunc == "function"
|
| 16 |
+
? funcExportCode(refsOrFunc.source)
|
| 17 |
+
: refsOrFunc !== undefined
|
| 18 |
+
? multiExportsCode<string>(refsOrFunc, getValidate)
|
| 19 |
+
: multiExportsCode<SchemaEnv>(ajv.schemas, (sch) =>
|
| 20 |
+
sch.meta ? undefined : ajv.compile(sch.schema)
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
function getValidate(id: string): AnyValidateFunction {
|
| 24 |
+
const v = ajv.getSchema(id)
|
| 25 |
+
if (!v) throw new Error(`moduleCode: no schema with id ${id}`)
|
| 26 |
+
return v
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function funcExportCode(source?: SourceCode): string {
|
| 30 |
+
const usedValues: UsedScopeValues = {}
|
| 31 |
+
const n = source?.validateName
|
| 32 |
+
const vCode = validateCode(usedValues, source)
|
| 33 |
+
if (ajv.opts.code.esm) {
|
| 34 |
+
// Always do named export as `validate` rather than the variable `n` which is `validateXX` for known export value
|
| 35 |
+
return `"use strict";${_n}export const validate = ${n};${_n}export default ${n};${_n}${vCode}`
|
| 36 |
+
}
|
| 37 |
+
return `"use strict";${_n}module.exports = ${n};${_n}module.exports.default = ${n};${_n}${vCode}`
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function multiExportsCode<T extends SchemaEnv | string>(
|
| 41 |
+
schemas: {[K in string]?: T},
|
| 42 |
+
getValidateFunc: (schOrId: T) => AnyValidateFunction | undefined
|
| 43 |
+
): string {
|
| 44 |
+
const usedValues: UsedScopeValues = {}
|
| 45 |
+
let code = _`"use strict";`
|
| 46 |
+
for (const name in schemas) {
|
| 47 |
+
const v = getValidateFunc(schemas[name] as T)
|
| 48 |
+
if (v) {
|
| 49 |
+
const vCode = validateCode(usedValues, v.source)
|
| 50 |
+
const exportSyntax = ajv.opts.code.esm
|
| 51 |
+
? _`export const ${getEsmExportName(name)}`
|
| 52 |
+
: _`exports${getProperty(name)}`
|
| 53 |
+
code = _`${code}${_n}${exportSyntax} = ${v.source?.validateName};${_n}${vCode}`
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
return `${code}`
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function validateCode(usedValues: UsedScopeValues, s?: SourceCode): Code {
|
| 60 |
+
if (!s) throw new Error('moduleCode: function does not have "source" property')
|
| 61 |
+
if (usedState(s.validateName) === UsedValueState.Completed) return nil
|
| 62 |
+
setUsedState(s.validateName, UsedValueState.Started)
|
| 63 |
+
|
| 64 |
+
const scopeCode = ajv.scope.scopeCode(s.scopeValues, usedValues, refValidateCode)
|
| 65 |
+
const code = new _Code(`${scopeCode}${_n}${s.validateCode}`)
|
| 66 |
+
return s.evaluated ? _`${code}${s.validateName}.evaluated = ${s.evaluated};${_n}` : code
|
| 67 |
+
|
| 68 |
+
function refValidateCode(n: ValueScopeName): Code | undefined {
|
| 69 |
+
const vRef = n.value?.ref
|
| 70 |
+
if (n.prefix === "validate" && typeof vRef == "function") {
|
| 71 |
+
const v = vRef as AnyValidateFunction
|
| 72 |
+
return validateCode(usedValues, v.source)
|
| 73 |
+
} else if ((n.prefix === "root" || n.prefix === "wrapper") && typeof vRef == "object") {
|
| 74 |
+
const {validate, validateName} = vRef as SchemaEnv
|
| 75 |
+
if (!validateName) throw new Error("ajv internal error")
|
| 76 |
+
const def = ajv.opts.code.es5 ? varKinds.var : varKinds.const
|
| 77 |
+
const wrapper = _`${def} ${n} = {validate: ${validateName}};`
|
| 78 |
+
if (usedState(validateName) === UsedValueState.Started) return wrapper
|
| 79 |
+
const vCode = validateCode(usedValues, validate?.source)
|
| 80 |
+
return _`${wrapper}${_n}${vCode}`
|
| 81 |
+
}
|
| 82 |
+
return undefined
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function usedState(name: ValueScopeName): UsedValueState | undefined {
|
| 86 |
+
return usedValues[name.prefix]?.get(name)
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
function setUsedState(name: ValueScopeName, state: UsedValueState): void {
|
| 90 |
+
const {prefix} = name
|
| 91 |
+
const names = (usedValues[prefix] = usedValues[prefix] || new Map())
|
| 92 |
+
names.set(name, state)
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
module.exports = exports = standaloneCode
|
| 98 |
+
Object.defineProperty(exports, "__esModule", {value: true})
|
| 99 |
+
|
| 100 |
+
export default standaloneCode
|
node_modules/ajv/lib/standalone/instance.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Ajv, {AnySchema, AnyValidateFunction, ErrorObject} from "../core"
|
| 2 |
+
import standaloneCode from "."
|
| 3 |
+
import * as requireFromString from "require-from-string"
|
| 4 |
+
|
| 5 |
+
export default class AjvPack {
|
| 6 |
+
errors?: ErrorObject[] | null // errors from the last validation
|
| 7 |
+
constructor(readonly ajv: Ajv) {}
|
| 8 |
+
|
| 9 |
+
validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise<unknown> {
|
| 10 |
+
return Ajv.prototype.validate.call(this, schemaKeyRef, data)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
compile<T = unknown>(schema: AnySchema, meta?: boolean): AnyValidateFunction<T> {
|
| 14 |
+
return this.getStandalone(this.ajv.compile<T>(schema, meta))
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
getSchema<T = unknown>(keyRef: string): AnyValidateFunction<T> | undefined {
|
| 18 |
+
const v = this.ajv.getSchema<T>(keyRef)
|
| 19 |
+
if (!v) return undefined
|
| 20 |
+
return this.getStandalone(v)
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
private getStandalone<T = unknown>(v: AnyValidateFunction<T>): AnyValidateFunction<T> {
|
| 24 |
+
return requireFromString(standaloneCode(this.ajv, v)) as AnyValidateFunction<T>
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
addSchema(...args: Parameters<typeof Ajv.prototype.addSchema>): AjvPack {
|
| 28 |
+
this.ajv.addSchema.call(this.ajv, ...args)
|
| 29 |
+
return this
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
addKeyword(...args: Parameters<typeof Ajv.prototype.addKeyword>): AjvPack {
|
| 33 |
+
this.ajv.addKeyword.call(this.ajv, ...args)
|
| 34 |
+
return this
|
| 35 |
+
}
|
| 36 |
+
}
|
node_modules/ajv/lib/types/index.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {URIComponent} from "fast-uri"
|
| 2 |
+
import type {CodeGen, Code, Name, ScopeValueSets, ValueScopeName} from "../compile/codegen"
|
| 3 |
+
import type {SchemaEnv, SchemaCxt, SchemaObjCxt} from "../compile"
|
| 4 |
+
import type {JSONType} from "../compile/rules"
|
| 5 |
+
import type {KeywordCxt} from "../compile/validate"
|
| 6 |
+
import type Ajv from "../core"
|
| 7 |
+
|
| 8 |
+
interface _SchemaObject {
|
| 9 |
+
id?: string
|
| 10 |
+
$id?: string
|
| 11 |
+
$schema?: string
|
| 12 |
+
[x: string]: any // TODO
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export interface SchemaObject extends _SchemaObject {
|
| 16 |
+
id?: string
|
| 17 |
+
$id?: string
|
| 18 |
+
$schema?: string
|
| 19 |
+
$async?: false
|
| 20 |
+
[x: string]: any // TODO
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
export interface AsyncSchema extends _SchemaObject {
|
| 24 |
+
$async: true
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export type AnySchemaObject = SchemaObject | AsyncSchema
|
| 28 |
+
|
| 29 |
+
export type Schema = SchemaObject | boolean
|
| 30 |
+
|
| 31 |
+
export type AnySchema = Schema | AsyncSchema
|
| 32 |
+
|
| 33 |
+
export type SchemaMap = {[Key in string]?: AnySchema}
|
| 34 |
+
|
| 35 |
+
export interface SourceCode {
|
| 36 |
+
validateName: ValueScopeName
|
| 37 |
+
validateCode: string
|
| 38 |
+
scopeValues: ScopeValueSets
|
| 39 |
+
evaluated?: Code
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export interface DataValidationCxt<T extends string | number = string | number> {
|
| 43 |
+
instancePath: string
|
| 44 |
+
parentData: {[K in T]: any} // object or array
|
| 45 |
+
parentDataProperty: T // string or number
|
| 46 |
+
rootData: Record<string, any> | any[]
|
| 47 |
+
dynamicAnchors: {[Ref in string]?: ValidateFunction}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export interface ValidateFunction<T = unknown> {
|
| 51 |
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
| 52 |
+
(this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T
|
| 53 |
+
errors?: null | ErrorObject[]
|
| 54 |
+
evaluated?: Evaluated
|
| 55 |
+
schema: AnySchema
|
| 56 |
+
schemaEnv: SchemaEnv
|
| 57 |
+
source?: SourceCode
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
export interface JTDParser<T = unknown> {
|
| 61 |
+
(json: string): T | undefined
|
| 62 |
+
message?: string
|
| 63 |
+
position?: number
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
export type EvaluatedProperties = {[K in string]?: true} | true
|
| 67 |
+
|
| 68 |
+
export type EvaluatedItems = number | true
|
| 69 |
+
|
| 70 |
+
export interface Evaluated {
|
| 71 |
+
// determined at compile time if staticProps/Items is true
|
| 72 |
+
props?: EvaluatedProperties
|
| 73 |
+
items?: EvaluatedItems
|
| 74 |
+
// whether props/items determined at compile time
|
| 75 |
+
dynamicProps: boolean
|
| 76 |
+
dynamicItems: boolean
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
export interface AsyncValidateFunction<T = unknown> extends ValidateFunction<T> {
|
| 80 |
+
(...args: Parameters<ValidateFunction<T>>): Promise<T>
|
| 81 |
+
$async: true
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
export type AnyValidateFunction<T = any> = ValidateFunction<T> | AsyncValidateFunction<T>
|
| 85 |
+
|
| 86 |
+
export interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
|
| 87 |
+
keyword: K
|
| 88 |
+
instancePath: string
|
| 89 |
+
schemaPath: string
|
| 90 |
+
params: P
|
| 91 |
+
// Added to validation errors of "propertyNames" keyword schema
|
| 92 |
+
propertyName?: string
|
| 93 |
+
// Excluded if option `messages` set to false.
|
| 94 |
+
message?: string
|
| 95 |
+
// These are added with the `verbose` option.
|
| 96 |
+
schema?: S
|
| 97 |
+
parentSchema?: AnySchemaObject
|
| 98 |
+
data?: unknown
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
export type ErrorNoParams<K extends string, S = unknown> = ErrorObject<K, Record<string, never>, S>
|
| 102 |
+
|
| 103 |
+
interface _KeywordDef {
|
| 104 |
+
keyword: string | string[]
|
| 105 |
+
type?: JSONType | JSONType[] // data types that keyword applies to
|
| 106 |
+
schemaType?: JSONType | JSONType[] // allowed type(s) of keyword value in the schema
|
| 107 |
+
allowUndefined?: boolean // used for keywords that can be invoked by other keywords, not being present in the schema
|
| 108 |
+
$data?: boolean // keyword supports [$data reference](../../docs/guide/combining-schemas.md#data-reference)
|
| 109 |
+
implements?: string[] // other schema keywords that this keyword implements
|
| 110 |
+
before?: string // keyword should be executed before this keyword (should be applicable to the same type)
|
| 111 |
+
post?: boolean // keyword should be executed after other keywords without post flag
|
| 112 |
+
metaSchema?: AnySchemaObject // meta-schema for keyword schema value - it is better to use schemaType where applicable
|
| 113 |
+
validateSchema?: AnyValidateFunction // compiled keyword metaSchema - should not be passed
|
| 114 |
+
dependencies?: string[] // keywords that must be present in the same schema
|
| 115 |
+
error?: KeywordErrorDefinition
|
| 116 |
+
$dataError?: KeywordErrorDefinition
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
export interface CodeKeywordDefinition extends _KeywordDef {
|
| 120 |
+
code: (cxt: KeywordCxt, ruleType?: string) => void
|
| 121 |
+
trackErrors?: boolean
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
export type MacroKeywordFunc = (
|
| 125 |
+
schema: any,
|
| 126 |
+
parentSchema: AnySchemaObject,
|
| 127 |
+
it: SchemaCxt
|
| 128 |
+
) => AnySchema
|
| 129 |
+
|
| 130 |
+
export type CompileKeywordFunc = (
|
| 131 |
+
schema: any,
|
| 132 |
+
parentSchema: AnySchemaObject,
|
| 133 |
+
it: SchemaObjCxt
|
| 134 |
+
) => DataValidateFunction
|
| 135 |
+
|
| 136 |
+
export interface DataValidateFunction {
|
| 137 |
+
(...args: Parameters<ValidateFunction>): boolean | Promise<any>
|
| 138 |
+
errors?: Partial<ErrorObject>[]
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
export interface SchemaValidateFunction {
|
| 142 |
+
(
|
| 143 |
+
schema: any,
|
| 144 |
+
data: any,
|
| 145 |
+
parentSchema?: AnySchemaObject,
|
| 146 |
+
dataCxt?: DataValidationCxt
|
| 147 |
+
): boolean | Promise<any>
|
| 148 |
+
errors?: Partial<ErrorObject>[]
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
export interface FuncKeywordDefinition extends _KeywordDef {
|
| 152 |
+
validate?: SchemaValidateFunction | DataValidateFunction
|
| 153 |
+
compile?: CompileKeywordFunc
|
| 154 |
+
// schema: false makes validate not to expect schema (DataValidateFunction)
|
| 155 |
+
schema?: boolean // requires "validate"
|
| 156 |
+
modifying?: boolean
|
| 157 |
+
async?: boolean
|
| 158 |
+
valid?: boolean
|
| 159 |
+
errors?: boolean | "full"
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
export interface MacroKeywordDefinition extends FuncKeywordDefinition {
|
| 163 |
+
macro: MacroKeywordFunc
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
export type KeywordDefinition =
|
| 167 |
+
| CodeKeywordDefinition
|
| 168 |
+
| FuncKeywordDefinition
|
| 169 |
+
| MacroKeywordDefinition
|
| 170 |
+
|
| 171 |
+
export type AddedKeywordDefinition = KeywordDefinition & {
|
| 172 |
+
type: JSONType[]
|
| 173 |
+
schemaType: JSONType[]
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
export interface KeywordErrorDefinition {
|
| 177 |
+
message: string | Code | ((cxt: KeywordErrorCxt) => string | Code)
|
| 178 |
+
params?: Code | ((cxt: KeywordErrorCxt) => Code)
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
export type Vocabulary = (KeywordDefinition | string)[]
|
| 182 |
+
|
| 183 |
+
export interface KeywordErrorCxt {
|
| 184 |
+
gen: CodeGen
|
| 185 |
+
keyword: string
|
| 186 |
+
data: Name
|
| 187 |
+
$data?: string | false
|
| 188 |
+
schema: any // TODO
|
| 189 |
+
parentSchema?: AnySchemaObject
|
| 190 |
+
schemaCode: Code | number | boolean
|
| 191 |
+
schemaValue: Code | number | boolean
|
| 192 |
+
schemaType?: JSONType[]
|
| 193 |
+
errsCount?: Name
|
| 194 |
+
params: KeywordCxtParams
|
| 195 |
+
it: SchemaCxt
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
export type KeywordCxtParams = {[P in string]?: Code | string | number}
|
| 199 |
+
|
| 200 |
+
export type FormatValidator<T extends string | number> = (data: T) => boolean
|
| 201 |
+
|
| 202 |
+
export type FormatCompare<T extends string | number> = (data1: T, data2: T) => number | undefined
|
| 203 |
+
|
| 204 |
+
export type AsyncFormatValidator<T extends string | number> = (data: T) => Promise<boolean>
|
| 205 |
+
|
| 206 |
+
export interface FormatDefinition<T extends string | number> {
|
| 207 |
+
type?: T extends string ? "string" | undefined : "number"
|
| 208 |
+
validate: FormatValidator<T> | (T extends string ? string | RegExp : never)
|
| 209 |
+
async?: false | undefined
|
| 210 |
+
compare?: FormatCompare<T>
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
export interface AsyncFormatDefinition<T extends string | number> {
|
| 214 |
+
type?: T extends string ? "string" | undefined : "number"
|
| 215 |
+
validate: AsyncFormatValidator<T>
|
| 216 |
+
async: true
|
| 217 |
+
compare?: FormatCompare<T>
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
export type AddedFormat =
|
| 221 |
+
| true
|
| 222 |
+
| RegExp
|
| 223 |
+
| FormatValidator<string>
|
| 224 |
+
| FormatDefinition<string>
|
| 225 |
+
| FormatDefinition<number>
|
| 226 |
+
| AsyncFormatDefinition<string>
|
| 227 |
+
| AsyncFormatDefinition<number>
|
| 228 |
+
|
| 229 |
+
export type Format = AddedFormat | string
|
| 230 |
+
|
| 231 |
+
export interface RegExpEngine {
|
| 232 |
+
(pattern: string, u: string): RegExpLike
|
| 233 |
+
code: string
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
export interface RegExpLike {
|
| 237 |
+
test: (s: string) => boolean
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
export interface UriResolver {
|
| 241 |
+
parse(uri: string): URIComponent
|
| 242 |
+
resolve(base: string, path: string): string
|
| 243 |
+
serialize(component: URIComponent): string
|
| 244 |
+
}
|
node_modules/ajv/lib/types/json-schema.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
| 2 |
+
type StrictNullChecksWrapper<Name extends string, Type> = undefined extends null
|
| 3 |
+
? `strictNullChecks must be true in tsconfig to use ${Name}`
|
| 4 |
+
: Type
|
| 5 |
+
|
| 6 |
+
type UnionToIntersection<U> = (U extends any ? (_: U) => void : never) extends (_: infer I) => void
|
| 7 |
+
? I
|
| 8 |
+
: never
|
| 9 |
+
|
| 10 |
+
export type SomeJSONSchema = UncheckedJSONSchemaType<Known, true>
|
| 11 |
+
|
| 12 |
+
type UncheckedPartialSchema<T> = Partial<UncheckedJSONSchemaType<T, true>>
|
| 13 |
+
|
| 14 |
+
export type PartialSchema<T> = StrictNullChecksWrapper<"PartialSchema", UncheckedPartialSchema<T>>
|
| 15 |
+
|
| 16 |
+
type JSONType<T extends string, IsPartial extends boolean> = IsPartial extends true
|
| 17 |
+
? T | undefined
|
| 18 |
+
: T
|
| 19 |
+
|
| 20 |
+
interface NumberKeywords {
|
| 21 |
+
minimum?: number
|
| 22 |
+
maximum?: number
|
| 23 |
+
exclusiveMinimum?: number
|
| 24 |
+
exclusiveMaximum?: number
|
| 25 |
+
multipleOf?: number
|
| 26 |
+
format?: string
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
interface StringKeywords {
|
| 30 |
+
minLength?: number
|
| 31 |
+
maxLength?: number
|
| 32 |
+
pattern?: string
|
| 33 |
+
format?: string
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
type UncheckedJSONSchemaType<T, IsPartial extends boolean> = (
|
| 37 |
+
| // these two unions allow arbitrary unions of types
|
| 38 |
+
{
|
| 39 |
+
anyOf: readonly UncheckedJSONSchemaType<T, IsPartial>[]
|
| 40 |
+
}
|
| 41 |
+
| {
|
| 42 |
+
oneOf: readonly UncheckedJSONSchemaType<T, IsPartial>[]
|
| 43 |
+
}
|
| 44 |
+
// this union allows for { type: (primitive)[] } style schemas
|
| 45 |
+
| ({
|
| 46 |
+
type: readonly (T extends number
|
| 47 |
+
? JSONType<"number" | "integer", IsPartial>
|
| 48 |
+
: T extends string
|
| 49 |
+
? JSONType<"string", IsPartial>
|
| 50 |
+
: T extends boolean
|
| 51 |
+
? JSONType<"boolean", IsPartial>
|
| 52 |
+
: never)[]
|
| 53 |
+
} & UnionToIntersection<
|
| 54 |
+
T extends number
|
| 55 |
+
? NumberKeywords
|
| 56 |
+
: T extends string
|
| 57 |
+
? StringKeywords
|
| 58 |
+
: T extends boolean
|
| 59 |
+
? // eslint-disable-next-line @typescript-eslint/ban-types
|
| 60 |
+
{}
|
| 61 |
+
: never
|
| 62 |
+
>)
|
| 63 |
+
// this covers "normal" types; it's last so typescript looks to it first for errors
|
| 64 |
+
| ((T extends number
|
| 65 |
+
? {
|
| 66 |
+
type: JSONType<"number" | "integer", IsPartial>
|
| 67 |
+
} & NumberKeywords
|
| 68 |
+
: T extends string
|
| 69 |
+
? {
|
| 70 |
+
type: JSONType<"string", IsPartial>
|
| 71 |
+
} & StringKeywords
|
| 72 |
+
: T extends boolean
|
| 73 |
+
? {
|
| 74 |
+
type: JSONType<"boolean", IsPartial>
|
| 75 |
+
}
|
| 76 |
+
: T extends readonly [any, ...any[]]
|
| 77 |
+
? {
|
| 78 |
+
// JSON AnySchema for tuple
|
| 79 |
+
type: JSONType<"array", IsPartial>
|
| 80 |
+
items: {
|
| 81 |
+
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>
|
| 82 |
+
} & {length: T["length"]}
|
| 83 |
+
minItems: T["length"]
|
| 84 |
+
} & ({maxItems: T["length"]} | {additionalItems: false})
|
| 85 |
+
: T extends readonly any[]
|
| 86 |
+
? {
|
| 87 |
+
type: JSONType<"array", IsPartial>
|
| 88 |
+
items: UncheckedJSONSchemaType<T[0], false>
|
| 89 |
+
contains?: UncheckedPartialSchema<T[0]>
|
| 90 |
+
minItems?: number
|
| 91 |
+
maxItems?: number
|
| 92 |
+
minContains?: number
|
| 93 |
+
maxContains?: number
|
| 94 |
+
uniqueItems?: true
|
| 95 |
+
additionalItems?: never
|
| 96 |
+
}
|
| 97 |
+
: T extends Record<string, any>
|
| 98 |
+
? {
|
| 99 |
+
// JSON AnySchema for records and dictionaries
|
| 100 |
+
// "required" is not optional because it is often forgotten
|
| 101 |
+
// "properties" are optional for more concise dictionary schemas
|
| 102 |
+
// "patternProperties" and can be only used with interfaces that have string index
|
| 103 |
+
type: JSONType<"object", IsPartial>
|
| 104 |
+
additionalProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
|
| 105 |
+
unevaluatedProperties?: boolean | UncheckedJSONSchemaType<T[string], false>
|
| 106 |
+
properties?: IsPartial extends true
|
| 107 |
+
? Partial<UncheckedPropertiesSchema<T>>
|
| 108 |
+
: UncheckedPropertiesSchema<T>
|
| 109 |
+
patternProperties?: Record<string, UncheckedJSONSchemaType<T[string], false>>
|
| 110 |
+
propertyNames?: Omit<UncheckedJSONSchemaType<string, false>, "type"> & {type?: "string"}
|
| 111 |
+
dependencies?: {[K in keyof T]?: readonly (keyof T)[] | UncheckedPartialSchema<T>}
|
| 112 |
+
dependentRequired?: {[K in keyof T]?: readonly (keyof T)[]}
|
| 113 |
+
dependentSchemas?: {[K in keyof T]?: UncheckedPartialSchema<T>}
|
| 114 |
+
minProperties?: number
|
| 115 |
+
maxProperties?: number
|
| 116 |
+
} & (IsPartial extends true // "required" is not necessary if it's a non-partial type with no required keys // are listed it only asserts that optional cannot be listed. // "required" type does not guarantee that all required properties
|
| 117 |
+
? {required: readonly (keyof T)[]}
|
| 118 |
+
: [UncheckedRequiredMembers<T>] extends [never]
|
| 119 |
+
? {required?: readonly UncheckedRequiredMembers<T>[]}
|
| 120 |
+
: {required: readonly UncheckedRequiredMembers<T>[]})
|
| 121 |
+
: T extends null
|
| 122 |
+
? {
|
| 123 |
+
type: JSONType<"null", IsPartial>
|
| 124 |
+
nullable: true
|
| 125 |
+
}
|
| 126 |
+
: never) & {
|
| 127 |
+
allOf?: readonly UncheckedPartialSchema<T>[]
|
| 128 |
+
anyOf?: readonly UncheckedPartialSchema<T>[]
|
| 129 |
+
oneOf?: readonly UncheckedPartialSchema<T>[]
|
| 130 |
+
if?: UncheckedPartialSchema<T>
|
| 131 |
+
then?: UncheckedPartialSchema<T>
|
| 132 |
+
else?: UncheckedPartialSchema<T>
|
| 133 |
+
not?: UncheckedPartialSchema<T>
|
| 134 |
+
})
|
| 135 |
+
) & {
|
| 136 |
+
[keyword: string]: any
|
| 137 |
+
$id?: string
|
| 138 |
+
$ref?: string
|
| 139 |
+
$defs?: Record<string, UncheckedJSONSchemaType<Known, true>>
|
| 140 |
+
definitions?: Record<string, UncheckedJSONSchemaType<Known, true>>
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
export type JSONSchemaType<T> = StrictNullChecksWrapper<
|
| 144 |
+
"JSONSchemaType",
|
| 145 |
+
UncheckedJSONSchemaType<T, false>
|
| 146 |
+
>
|
| 147 |
+
|
| 148 |
+
type Known =
|
| 149 |
+
| {[key: string]: Known}
|
| 150 |
+
| [Known, ...Known[]]
|
| 151 |
+
| Known[]
|
| 152 |
+
| number
|
| 153 |
+
| string
|
| 154 |
+
| boolean
|
| 155 |
+
| null
|
| 156 |
+
|
| 157 |
+
type UncheckedPropertiesSchema<T> = {
|
| 158 |
+
[K in keyof T]-?: (UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>) | {$ref: string}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
export type PropertiesSchema<T> = StrictNullChecksWrapper<
|
| 162 |
+
"PropertiesSchema",
|
| 163 |
+
UncheckedPropertiesSchema<T>
|
| 164 |
+
>
|
| 165 |
+
|
| 166 |
+
type UncheckedRequiredMembers<T> = {
|
| 167 |
+
[K in keyof T]-?: undefined extends T[K] ? never : K
|
| 168 |
+
}[keyof T]
|
| 169 |
+
|
| 170 |
+
export type RequiredMembers<T> = StrictNullChecksWrapper<
|
| 171 |
+
"RequiredMembers",
|
| 172 |
+
UncheckedRequiredMembers<T>
|
| 173 |
+
>
|
| 174 |
+
|
| 175 |
+
type Nullable<T> = undefined extends T
|
| 176 |
+
? {
|
| 177 |
+
nullable: true
|
| 178 |
+
const?: null // any non-null value would fail `const: null`, `null` would fail any other value in const
|
| 179 |
+
enum?: readonly (T | null)[] // `null` must be explicitly included in "enum" for `null` to pass
|
| 180 |
+
default?: T | null
|
| 181 |
+
}
|
| 182 |
+
: {
|
| 183 |
+
nullable?: false
|
| 184 |
+
const?: T
|
| 185 |
+
enum?: readonly T[]
|
| 186 |
+
default?: T
|
| 187 |
+
}
|
node_modules/ajv/lib/types/jtd-schema.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** numeric strings */
|
| 2 |
+
type NumberType = "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32"
|
| 3 |
+
|
| 4 |
+
/** string strings */
|
| 5 |
+
type StringType = "string" | "timestamp"
|
| 6 |
+
|
| 7 |
+
/** Generic JTD Schema without inference of the represented type */
|
| 8 |
+
export type SomeJTDSchemaType = (
|
| 9 |
+
| // ref
|
| 10 |
+
{ref: string}
|
| 11 |
+
// primitives
|
| 12 |
+
| {type: NumberType | StringType | "boolean"}
|
| 13 |
+
// enum
|
| 14 |
+
| {enum: string[]}
|
| 15 |
+
// elements
|
| 16 |
+
| {elements: SomeJTDSchemaType}
|
| 17 |
+
// values
|
| 18 |
+
| {values: SomeJTDSchemaType}
|
| 19 |
+
// properties
|
| 20 |
+
| {
|
| 21 |
+
properties: Record<string, SomeJTDSchemaType>
|
| 22 |
+
optionalProperties?: Record<string, SomeJTDSchemaType>
|
| 23 |
+
additionalProperties?: boolean
|
| 24 |
+
}
|
| 25 |
+
| {
|
| 26 |
+
properties?: Record<string, SomeJTDSchemaType>
|
| 27 |
+
optionalProperties: Record<string, SomeJTDSchemaType>
|
| 28 |
+
additionalProperties?: boolean
|
| 29 |
+
}
|
| 30 |
+
// discriminator
|
| 31 |
+
| {discriminator: string; mapping: Record<string, SomeJTDSchemaType>}
|
| 32 |
+
// empty
|
| 33 |
+
// NOTE see the end of
|
| 34 |
+
// https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
|
| 35 |
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
| 36 |
+
| {}
|
| 37 |
+
) & {
|
| 38 |
+
nullable?: boolean
|
| 39 |
+
metadata?: Record<string, unknown>
|
| 40 |
+
definitions?: Record<string, SomeJTDSchemaType>
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/** required keys of an object, not undefined */
|
| 44 |
+
type RequiredKeys<T> = {
|
| 45 |
+
[K in keyof T]-?: undefined extends T[K] ? never : K
|
| 46 |
+
}[keyof T]
|
| 47 |
+
|
| 48 |
+
/** optional or undifined-able keys of an object */
|
| 49 |
+
type OptionalKeys<T> = {
|
| 50 |
+
[K in keyof T]-?: undefined extends T[K] ? K : never
|
| 51 |
+
}[keyof T]
|
| 52 |
+
|
| 53 |
+
/** type is true if T is a union type */
|
| 54 |
+
type IsUnion_<T, U extends T = T> = false extends (
|
| 55 |
+
T extends unknown ? ([U] extends [T] ? false : true) : never
|
| 56 |
+
)
|
| 57 |
+
? false
|
| 58 |
+
: true
|
| 59 |
+
type IsUnion<T> = IsUnion_<T>
|
| 60 |
+
|
| 61 |
+
/** type is true if T is identically E */
|
| 62 |
+
type TypeEquality<T, E> = [T] extends [E] ? ([E] extends [T] ? true : false) : false
|
| 63 |
+
|
| 64 |
+
/** type is true if T or null is identically E or null*/
|
| 65 |
+
type NullTypeEquality<T, E> = TypeEquality<T | null, E | null>
|
| 66 |
+
|
| 67 |
+
/** gets only the string literals of a type or null if a type isn't a string literal */
|
| 68 |
+
type EnumString<T> = [T] extends [never]
|
| 69 |
+
? null
|
| 70 |
+
: T extends string
|
| 71 |
+
? string extends T
|
| 72 |
+
? null
|
| 73 |
+
: T
|
| 74 |
+
: null
|
| 75 |
+
|
| 76 |
+
/** true if type is a union of string literals */
|
| 77 |
+
type IsEnum<T> = null extends EnumString<T> ? false : true
|
| 78 |
+
|
| 79 |
+
/** true only if all types are array types (not tuples) */
|
| 80 |
+
// NOTE relies on the fact that tuples don't have an index at 0.5, but arrays
|
| 81 |
+
// have an index at every number
|
| 82 |
+
type IsElements<T> = false extends IsUnion<T>
|
| 83 |
+
? [T] extends [readonly unknown[]]
|
| 84 |
+
? undefined extends T[0.5]
|
| 85 |
+
? false
|
| 86 |
+
: true
|
| 87 |
+
: false
|
| 88 |
+
: false
|
| 89 |
+
|
| 90 |
+
/** true if the the type is a values type */
|
| 91 |
+
type IsValues<T> = false extends IsUnion<T> ? TypeEquality<keyof T, string> : false
|
| 92 |
+
|
| 93 |
+
/** true if type is a properties type and Union is false, or type is a discriminator type and Union is true */
|
| 94 |
+
type IsRecord<T, Union extends boolean> = Union extends IsUnion<T>
|
| 95 |
+
? null extends EnumString<keyof T>
|
| 96 |
+
? false
|
| 97 |
+
: true
|
| 98 |
+
: false
|
| 99 |
+
|
| 100 |
+
/** true if type represents an empty record */
|
| 101 |
+
type IsEmptyRecord<T> = [T] extends [Record<string, never>]
|
| 102 |
+
? [T] extends [never]
|
| 103 |
+
? false
|
| 104 |
+
: true
|
| 105 |
+
: false
|
| 106 |
+
|
| 107 |
+
/** actual schema */
|
| 108 |
+
export type JTDSchemaType<T, D extends Record<string, unknown> = Record<string, never>> = (
|
| 109 |
+
| // refs - where null wasn't specified, must match exactly
|
| 110 |
+
(null extends EnumString<keyof D>
|
| 111 |
+
? never
|
| 112 |
+
:
|
| 113 |
+
| ({[K in keyof D]: [T] extends [D[K]] ? {ref: K} : never}[keyof D] & {nullable?: false})
|
| 114 |
+
// nulled refs - if ref is nullable and nullable is specified, then it can
|
| 115 |
+
// match either null or non-null definitions
|
| 116 |
+
| (null extends T
|
| 117 |
+
? {
|
| 118 |
+
[K in keyof D]: [Exclude<T, null>] extends [Exclude<D[K], null>]
|
| 119 |
+
? {ref: K}
|
| 120 |
+
: never
|
| 121 |
+
}[keyof D] & {nullable: true}
|
| 122 |
+
: never))
|
| 123 |
+
// empty - empty schemas also treat nullable differently in that it's now fully ignored
|
| 124 |
+
| (unknown extends T ? {nullable?: boolean} : never)
|
| 125 |
+
// all other types // numbers - only accepts the type number
|
| 126 |
+
| ((true extends NullTypeEquality<T, number>
|
| 127 |
+
? {type: NumberType}
|
| 128 |
+
: // booleans - accepts the type boolean
|
| 129 |
+
true extends NullTypeEquality<T, boolean>
|
| 130 |
+
? {type: "boolean"}
|
| 131 |
+
: // strings - only accepts the type string
|
| 132 |
+
true extends NullTypeEquality<T, string>
|
| 133 |
+
? {type: StringType}
|
| 134 |
+
: // strings - only accepts the type Date
|
| 135 |
+
true extends NullTypeEquality<T, Date>
|
| 136 |
+
? {type: "timestamp"}
|
| 137 |
+
: // enums - only accepts union of string literals
|
| 138 |
+
// TODO we can't actually check that everything in the union was specified
|
| 139 |
+
true extends IsEnum<Exclude<T, null>>
|
| 140 |
+
? {enum: EnumString<Exclude<T, null>>[]}
|
| 141 |
+
: // arrays - only accepts arrays, could be array of unions to be resolved later
|
| 142 |
+
true extends IsElements<Exclude<T, null>>
|
| 143 |
+
? T extends readonly (infer E)[]
|
| 144 |
+
? {
|
| 145 |
+
elements: JTDSchemaType<E, D>
|
| 146 |
+
}
|
| 147 |
+
: never
|
| 148 |
+
: // empty properties
|
| 149 |
+
true extends IsEmptyRecord<Exclude<T, null>>
|
| 150 |
+
?
|
| 151 |
+
| {properties: Record<string, never>; optionalProperties?: Record<string, never>}
|
| 152 |
+
| {optionalProperties: Record<string, never>}
|
| 153 |
+
: // values
|
| 154 |
+
true extends IsValues<Exclude<T, null>>
|
| 155 |
+
? T extends Record<string, infer V>
|
| 156 |
+
? {
|
| 157 |
+
values: JTDSchemaType<V, D>
|
| 158 |
+
}
|
| 159 |
+
: never
|
| 160 |
+
: // properties
|
| 161 |
+
true extends IsRecord<Exclude<T, null>, false>
|
| 162 |
+
? ([RequiredKeys<Exclude<T, null>>] extends [never]
|
| 163 |
+
? {
|
| 164 |
+
properties?: Record<string, never>
|
| 165 |
+
}
|
| 166 |
+
: {
|
| 167 |
+
properties: {[K in RequiredKeys<T>]: JTDSchemaType<T[K], D>}
|
| 168 |
+
}) &
|
| 169 |
+
([OptionalKeys<Exclude<T, null>>] extends [never]
|
| 170 |
+
? {
|
| 171 |
+
optionalProperties?: Record<string, never>
|
| 172 |
+
}
|
| 173 |
+
: {
|
| 174 |
+
optionalProperties: {
|
| 175 |
+
[K in OptionalKeys<T>]: JTDSchemaType<Exclude<T[K], undefined>, D>
|
| 176 |
+
}
|
| 177 |
+
}) & {
|
| 178 |
+
additionalProperties?: boolean
|
| 179 |
+
}
|
| 180 |
+
: // discriminator
|
| 181 |
+
true extends IsRecord<Exclude<T, null>, true>
|
| 182 |
+
? {
|
| 183 |
+
[K in keyof Exclude<T, null>]-?: Exclude<T, null>[K] extends string
|
| 184 |
+
? {
|
| 185 |
+
discriminator: K
|
| 186 |
+
mapping: {
|
| 187 |
+
// TODO currently allows descriminator to be present in schema
|
| 188 |
+
[M in Exclude<T, null>[K]]: JTDSchemaType<
|
| 189 |
+
Omit<T extends Record<K, M> ? T : never, K>,
|
| 190 |
+
D
|
| 191 |
+
>
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
: never
|
| 195 |
+
}[keyof Exclude<T, null>]
|
| 196 |
+
: never) &
|
| 197 |
+
(null extends T
|
| 198 |
+
? {
|
| 199 |
+
nullable: true
|
| 200 |
+
}
|
| 201 |
+
: {nullable?: false}))
|
| 202 |
+
) & {
|
| 203 |
+
// extra properties
|
| 204 |
+
metadata?: Record<string, unknown>
|
| 205 |
+
// TODO these should only be allowed at the top level
|
| 206 |
+
definitions?: {[K in keyof D]: JTDSchemaType<D[K], D>}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
type JTDDataDef<S, D extends Record<string, unknown>> =
|
| 210 |
+
| // ref
|
| 211 |
+
(S extends {ref: string}
|
| 212 |
+
? D extends {[K in S["ref"]]: infer V}
|
| 213 |
+
? JTDDataDef<V, D>
|
| 214 |
+
: never
|
| 215 |
+
: // type
|
| 216 |
+
S extends {type: NumberType}
|
| 217 |
+
? number
|
| 218 |
+
: S extends {type: "boolean"}
|
| 219 |
+
? boolean
|
| 220 |
+
: S extends {type: "string"}
|
| 221 |
+
? string
|
| 222 |
+
: S extends {type: "timestamp"}
|
| 223 |
+
? string | Date
|
| 224 |
+
: // enum
|
| 225 |
+
S extends {enum: readonly (infer E)[]}
|
| 226 |
+
? string extends E
|
| 227 |
+
? never
|
| 228 |
+
: [E] extends [string]
|
| 229 |
+
? E
|
| 230 |
+
: never
|
| 231 |
+
: // elements
|
| 232 |
+
S extends {elements: infer E}
|
| 233 |
+
? JTDDataDef<E, D>[]
|
| 234 |
+
: // properties
|
| 235 |
+
S extends {
|
| 236 |
+
properties: Record<string, unknown>
|
| 237 |
+
optionalProperties?: Record<string, unknown>
|
| 238 |
+
additionalProperties?: boolean
|
| 239 |
+
}
|
| 240 |
+
? {-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>} & {
|
| 241 |
+
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<
|
| 242 |
+
S["optionalProperties"][K],
|
| 243 |
+
D
|
| 244 |
+
>
|
| 245 |
+
} & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown)
|
| 246 |
+
: S extends {
|
| 247 |
+
properties?: Record<string, unknown>
|
| 248 |
+
optionalProperties: Record<string, unknown>
|
| 249 |
+
additionalProperties?: boolean
|
| 250 |
+
}
|
| 251 |
+
? {-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>} & {
|
| 252 |
+
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<
|
| 253 |
+
S["optionalProperties"][K],
|
| 254 |
+
D
|
| 255 |
+
>
|
| 256 |
+
} & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown)
|
| 257 |
+
: // values
|
| 258 |
+
S extends {values: infer V}
|
| 259 |
+
? Record<string, JTDDataDef<V, D>>
|
| 260 |
+
: // discriminator
|
| 261 |
+
S extends {discriminator: infer M; mapping: Record<string, unknown>}
|
| 262 |
+
? [M] extends [string]
|
| 263 |
+
? {
|
| 264 |
+
[K in keyof S["mapping"]]: JTDDataDef<S["mapping"][K], D> & {[KM in M]: K}
|
| 265 |
+
}[keyof S["mapping"]]
|
| 266 |
+
: never
|
| 267 |
+
: // empty
|
| 268 |
+
unknown)
|
| 269 |
+
| (S extends {nullable: true} ? null : never)
|
| 270 |
+
|
| 271 |
+
export type JTDDataType<S> = S extends {definitions: Record<string, unknown>}
|
| 272 |
+
? JTDDataDef<S, S["definitions"]>
|
| 273 |
+
: JTDDataDef<S, Record<string, never>>
|
node_modules/ajv/lib/vocabularies/applicator/additionalItems.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {
|
| 2 |
+
CodeKeywordDefinition,
|
| 3 |
+
ErrorObject,
|
| 4 |
+
KeywordErrorDefinition,
|
| 5 |
+
AnySchema,
|
| 6 |
+
} from "../../types"
|
| 7 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 8 |
+
import {_, str, not, Name} from "../../compile/codegen"
|
| 9 |
+
import {alwaysValidSchema, checkStrictMode, Type} from "../../compile/util"
|
| 10 |
+
|
| 11 |
+
export type AdditionalItemsError = ErrorObject<"additionalItems", {limit: number}, AnySchema>
|
| 12 |
+
|
| 13 |
+
const error: KeywordErrorDefinition = {
|
| 14 |
+
message: ({params: {len}}) => str`must NOT have more than ${len} items`,
|
| 15 |
+
params: ({params: {len}}) => _`{limit: ${len}}`,
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const def: CodeKeywordDefinition = {
|
| 19 |
+
keyword: "additionalItems" as const,
|
| 20 |
+
type: "array",
|
| 21 |
+
schemaType: ["boolean", "object"],
|
| 22 |
+
before: "uniqueItems",
|
| 23 |
+
error,
|
| 24 |
+
code(cxt: KeywordCxt) {
|
| 25 |
+
const {parentSchema, it} = cxt
|
| 26 |
+
const {items} = parentSchema
|
| 27 |
+
if (!Array.isArray(items)) {
|
| 28 |
+
checkStrictMode(it, '"additionalItems" is ignored when "items" is not an array of schemas')
|
| 29 |
+
return
|
| 30 |
+
}
|
| 31 |
+
validateAdditionalItems(cxt, items)
|
| 32 |
+
},
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
export function validateAdditionalItems(cxt: KeywordCxt, items: AnySchema[]): void {
|
| 36 |
+
const {gen, schema, data, keyword, it} = cxt
|
| 37 |
+
it.items = true
|
| 38 |
+
const len = gen.const("len", _`${data}.length`)
|
| 39 |
+
if (schema === false) {
|
| 40 |
+
cxt.setParams({len: items.length})
|
| 41 |
+
cxt.pass(_`${len} <= ${items.length}`)
|
| 42 |
+
} else if (typeof schema == "object" && !alwaysValidSchema(it, schema)) {
|
| 43 |
+
const valid = gen.var("valid", _`${len} <= ${items.length}`) // TODO var
|
| 44 |
+
gen.if(not(valid), () => validateItems(valid))
|
| 45 |
+
cxt.ok(valid)
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function validateItems(valid: Name): void {
|
| 49 |
+
gen.forRange("i", items.length, len, (i) => {
|
| 50 |
+
cxt.subschema({keyword, dataProp: i, dataPropType: Type.Num}, valid)
|
| 51 |
+
if (!it.allErrors) gen.if(not(valid), () => gen.break())
|
| 52 |
+
})
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/additionalProperties.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {
|
| 2 |
+
CodeKeywordDefinition,
|
| 3 |
+
AddedKeywordDefinition,
|
| 4 |
+
ErrorObject,
|
| 5 |
+
KeywordErrorDefinition,
|
| 6 |
+
AnySchema,
|
| 7 |
+
} from "../../types"
|
| 8 |
+
import {allSchemaProperties, usePattern, isOwnProperty} from "../code"
|
| 9 |
+
import {_, nil, or, not, Code, Name} from "../../compile/codegen"
|
| 10 |
+
import N from "../../compile/names"
|
| 11 |
+
import type {SubschemaArgs} from "../../compile/validate/subschema"
|
| 12 |
+
import {alwaysValidSchema, schemaRefOrVal, Type} from "../../compile/util"
|
| 13 |
+
|
| 14 |
+
export type AdditionalPropertiesError = ErrorObject<
|
| 15 |
+
"additionalProperties",
|
| 16 |
+
{additionalProperty: string},
|
| 17 |
+
AnySchema
|
| 18 |
+
>
|
| 19 |
+
|
| 20 |
+
const error: KeywordErrorDefinition = {
|
| 21 |
+
message: "must NOT have additional properties",
|
| 22 |
+
params: ({params}) => _`{additionalProperty: ${params.additionalProperty}}`,
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
const def: CodeKeywordDefinition & AddedKeywordDefinition = {
|
| 26 |
+
keyword: "additionalProperties",
|
| 27 |
+
type: ["object"],
|
| 28 |
+
schemaType: ["boolean", "object"],
|
| 29 |
+
allowUndefined: true,
|
| 30 |
+
trackErrors: true,
|
| 31 |
+
error,
|
| 32 |
+
code(cxt) {
|
| 33 |
+
const {gen, schema, parentSchema, data, errsCount, it} = cxt
|
| 34 |
+
/* istanbul ignore if */
|
| 35 |
+
if (!errsCount) throw new Error("ajv implementation error")
|
| 36 |
+
const {allErrors, opts} = it
|
| 37 |
+
it.props = true
|
| 38 |
+
if (opts.removeAdditional !== "all" && alwaysValidSchema(it, schema)) return
|
| 39 |
+
const props = allSchemaProperties(parentSchema.properties)
|
| 40 |
+
const patProps = allSchemaProperties(parentSchema.patternProperties)
|
| 41 |
+
checkAdditionalProperties()
|
| 42 |
+
cxt.ok(_`${errsCount} === ${N.errors}`)
|
| 43 |
+
|
| 44 |
+
function checkAdditionalProperties(): void {
|
| 45 |
+
gen.forIn("key", data, (key: Name) => {
|
| 46 |
+
if (!props.length && !patProps.length) additionalPropertyCode(key)
|
| 47 |
+
else gen.if(isAdditional(key), () => additionalPropertyCode(key))
|
| 48 |
+
})
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function isAdditional(key: Name): Code {
|
| 52 |
+
let definedProp: Code
|
| 53 |
+
if (props.length > 8) {
|
| 54 |
+
// TODO maybe an option instead of hard-coded 8?
|
| 55 |
+
const propsSchema = schemaRefOrVal(it, parentSchema.properties, "properties")
|
| 56 |
+
definedProp = isOwnProperty(gen, propsSchema as Code, key)
|
| 57 |
+
} else if (props.length) {
|
| 58 |
+
definedProp = or(...props.map((p) => _`${key} === ${p}`))
|
| 59 |
+
} else {
|
| 60 |
+
definedProp = nil
|
| 61 |
+
}
|
| 62 |
+
if (patProps.length) {
|
| 63 |
+
definedProp = or(definedProp, ...patProps.map((p) => _`${usePattern(cxt, p)}.test(${key})`))
|
| 64 |
+
}
|
| 65 |
+
return not(definedProp)
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
function deleteAdditional(key: Name): void {
|
| 69 |
+
gen.code(_`delete ${data}[${key}]`)
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function additionalPropertyCode(key: Name): void {
|
| 73 |
+
if (opts.removeAdditional === "all" || (opts.removeAdditional && schema === false)) {
|
| 74 |
+
deleteAdditional(key)
|
| 75 |
+
return
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (schema === false) {
|
| 79 |
+
cxt.setParams({additionalProperty: key})
|
| 80 |
+
cxt.error()
|
| 81 |
+
if (!allErrors) gen.break()
|
| 82 |
+
return
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
if (typeof schema == "object" && !alwaysValidSchema(it, schema)) {
|
| 86 |
+
const valid = gen.name("valid")
|
| 87 |
+
if (opts.removeAdditional === "failing") {
|
| 88 |
+
applyAdditionalSchema(key, valid, false)
|
| 89 |
+
gen.if(not(valid), () => {
|
| 90 |
+
cxt.reset()
|
| 91 |
+
deleteAdditional(key)
|
| 92 |
+
})
|
| 93 |
+
} else {
|
| 94 |
+
applyAdditionalSchema(key, valid)
|
| 95 |
+
if (!allErrors) gen.if(not(valid), () => gen.break())
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
function applyAdditionalSchema(key: Name, valid: Name, errors?: false): void {
|
| 101 |
+
const subschema: SubschemaArgs = {
|
| 102 |
+
keyword: "additionalProperties",
|
| 103 |
+
dataProp: key,
|
| 104 |
+
dataPropType: Type.Str,
|
| 105 |
+
}
|
| 106 |
+
if (errors === false) {
|
| 107 |
+
Object.assign(subschema, {
|
| 108 |
+
compositeRule: true,
|
| 109 |
+
createErrors: false,
|
| 110 |
+
allErrors: false,
|
| 111 |
+
})
|
| 112 |
+
}
|
| 113 |
+
cxt.subschema(subschema, valid)
|
| 114 |
+
}
|
| 115 |
+
},
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/allOf.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {CodeKeywordDefinition, AnySchema} from "../../types"
|
| 2 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 3 |
+
import {alwaysValidSchema} from "../../compile/util"
|
| 4 |
+
|
| 5 |
+
const def: CodeKeywordDefinition = {
|
| 6 |
+
keyword: "allOf",
|
| 7 |
+
schemaType: "array",
|
| 8 |
+
code(cxt: KeywordCxt) {
|
| 9 |
+
const {gen, schema, it} = cxt
|
| 10 |
+
/* istanbul ignore if */
|
| 11 |
+
if (!Array.isArray(schema)) throw new Error("ajv implementation error")
|
| 12 |
+
const valid = gen.name("valid")
|
| 13 |
+
schema.forEach((sch: AnySchema, i: number) => {
|
| 14 |
+
if (alwaysValidSchema(it, sch)) return
|
| 15 |
+
const schCxt = cxt.subschema({keyword: "allOf", schemaProp: i}, valid)
|
| 16 |
+
cxt.ok(valid)
|
| 17 |
+
cxt.mergeEvaluated(schCxt)
|
| 18 |
+
})
|
| 19 |
+
},
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/anyOf.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {CodeKeywordDefinition, ErrorNoParams, AnySchema} from "../../types"
|
| 2 |
+
import {validateUnion} from "../code"
|
| 3 |
+
|
| 4 |
+
export type AnyOfError = ErrorNoParams<"anyOf", AnySchema[]>
|
| 5 |
+
|
| 6 |
+
const def: CodeKeywordDefinition = {
|
| 7 |
+
keyword: "anyOf",
|
| 8 |
+
schemaType: "array",
|
| 9 |
+
trackErrors: true,
|
| 10 |
+
code: validateUnion,
|
| 11 |
+
error: {message: "must match a schema in anyOf"},
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/contains.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {
|
| 2 |
+
CodeKeywordDefinition,
|
| 3 |
+
KeywordErrorDefinition,
|
| 4 |
+
ErrorObject,
|
| 5 |
+
AnySchema,
|
| 6 |
+
} from "../../types"
|
| 7 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 8 |
+
import {_, str, Name} from "../../compile/codegen"
|
| 9 |
+
import {alwaysValidSchema, checkStrictMode, Type} from "../../compile/util"
|
| 10 |
+
|
| 11 |
+
export type ContainsError = ErrorObject<
|
| 12 |
+
"contains",
|
| 13 |
+
{minContains: number; maxContains?: number},
|
| 14 |
+
AnySchema
|
| 15 |
+
>
|
| 16 |
+
|
| 17 |
+
const error: KeywordErrorDefinition = {
|
| 18 |
+
message: ({params: {min, max}}) =>
|
| 19 |
+
max === undefined
|
| 20 |
+
? str`must contain at least ${min} valid item(s)`
|
| 21 |
+
: str`must contain at least ${min} and no more than ${max} valid item(s)`,
|
| 22 |
+
params: ({params: {min, max}}) =>
|
| 23 |
+
max === undefined ? _`{minContains: ${min}}` : _`{minContains: ${min}, maxContains: ${max}}`,
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
const def: CodeKeywordDefinition = {
|
| 27 |
+
keyword: "contains",
|
| 28 |
+
type: "array",
|
| 29 |
+
schemaType: ["object", "boolean"],
|
| 30 |
+
before: "uniqueItems",
|
| 31 |
+
trackErrors: true,
|
| 32 |
+
error,
|
| 33 |
+
code(cxt: KeywordCxt) {
|
| 34 |
+
const {gen, schema, parentSchema, data, it} = cxt
|
| 35 |
+
let min: number
|
| 36 |
+
let max: number | undefined
|
| 37 |
+
const {minContains, maxContains} = parentSchema
|
| 38 |
+
if (it.opts.next) {
|
| 39 |
+
min = minContains === undefined ? 1 : minContains
|
| 40 |
+
max = maxContains
|
| 41 |
+
} else {
|
| 42 |
+
min = 1
|
| 43 |
+
}
|
| 44 |
+
const len = gen.const("len", _`${data}.length`)
|
| 45 |
+
cxt.setParams({min, max})
|
| 46 |
+
if (max === undefined && min === 0) {
|
| 47 |
+
checkStrictMode(it, `"minContains" == 0 without "maxContains": "contains" keyword ignored`)
|
| 48 |
+
return
|
| 49 |
+
}
|
| 50 |
+
if (max !== undefined && min > max) {
|
| 51 |
+
checkStrictMode(it, `"minContains" > "maxContains" is always invalid`)
|
| 52 |
+
cxt.fail()
|
| 53 |
+
return
|
| 54 |
+
}
|
| 55 |
+
if (alwaysValidSchema(it, schema)) {
|
| 56 |
+
let cond = _`${len} >= ${min}`
|
| 57 |
+
if (max !== undefined) cond = _`${cond} && ${len} <= ${max}`
|
| 58 |
+
cxt.pass(cond)
|
| 59 |
+
return
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
it.items = true
|
| 63 |
+
const valid = gen.name("valid")
|
| 64 |
+
if (max === undefined && min === 1) {
|
| 65 |
+
validateItems(valid, () => gen.if(valid, () => gen.break()))
|
| 66 |
+
} else if (min === 0) {
|
| 67 |
+
gen.let(valid, true)
|
| 68 |
+
if (max !== undefined) gen.if(_`${data}.length > 0`, validateItemsWithCount)
|
| 69 |
+
} else {
|
| 70 |
+
gen.let(valid, false)
|
| 71 |
+
validateItemsWithCount()
|
| 72 |
+
}
|
| 73 |
+
cxt.result(valid, () => cxt.reset())
|
| 74 |
+
|
| 75 |
+
function validateItemsWithCount(): void {
|
| 76 |
+
const schValid = gen.name("_valid")
|
| 77 |
+
const count = gen.let("count", 0)
|
| 78 |
+
validateItems(schValid, () => gen.if(schValid, () => checkLimits(count)))
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function validateItems(_valid: Name, block: () => void): void {
|
| 82 |
+
gen.forRange("i", 0, len, (i) => {
|
| 83 |
+
cxt.subschema(
|
| 84 |
+
{
|
| 85 |
+
keyword: "contains",
|
| 86 |
+
dataProp: i,
|
| 87 |
+
dataPropType: Type.Num,
|
| 88 |
+
compositeRule: true,
|
| 89 |
+
},
|
| 90 |
+
_valid
|
| 91 |
+
)
|
| 92 |
+
block()
|
| 93 |
+
})
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
function checkLimits(count: Name): void {
|
| 97 |
+
gen.code(_`${count}++`)
|
| 98 |
+
if (max === undefined) {
|
| 99 |
+
gen.if(_`${count} >= ${min}`, () => gen.assign(valid, true).break())
|
| 100 |
+
} else {
|
| 101 |
+
gen.if(_`${count} > ${max}`, () => gen.assign(valid, false).break())
|
| 102 |
+
if (min === 1) gen.assign(valid, true)
|
| 103 |
+
else gen.if(_`${count} >= ${min}`, () => gen.assign(valid, true))
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
},
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/dependencies.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {
|
| 2 |
+
CodeKeywordDefinition,
|
| 3 |
+
ErrorObject,
|
| 4 |
+
KeywordErrorDefinition,
|
| 5 |
+
SchemaMap,
|
| 6 |
+
AnySchema,
|
| 7 |
+
} from "../../types"
|
| 8 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 9 |
+
import {_, str} from "../../compile/codegen"
|
| 10 |
+
import {alwaysValidSchema} from "../../compile/util"
|
| 11 |
+
import {checkReportMissingProp, checkMissingProp, reportMissingProp, propertyInData} from "../code"
|
| 12 |
+
|
| 13 |
+
export type PropertyDependencies = {[K in string]?: string[]}
|
| 14 |
+
|
| 15 |
+
export interface DependenciesErrorParams {
|
| 16 |
+
property: string
|
| 17 |
+
missingProperty: string
|
| 18 |
+
depsCount: number
|
| 19 |
+
deps: string // TODO change to string[]
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
type SchemaDependencies = SchemaMap
|
| 23 |
+
|
| 24 |
+
export type DependenciesError = ErrorObject<
|
| 25 |
+
"dependencies",
|
| 26 |
+
DependenciesErrorParams,
|
| 27 |
+
{[K in string]?: string[] | AnySchema}
|
| 28 |
+
>
|
| 29 |
+
|
| 30 |
+
export const error: KeywordErrorDefinition = {
|
| 31 |
+
message: ({params: {property, depsCount, deps}}) => {
|
| 32 |
+
const property_ies = depsCount === 1 ? "property" : "properties"
|
| 33 |
+
return str`must have ${property_ies} ${deps} when property ${property} is present`
|
| 34 |
+
},
|
| 35 |
+
params: ({params: {property, depsCount, deps, missingProperty}}) =>
|
| 36 |
+
_`{property: ${property},
|
| 37 |
+
missingProperty: ${missingProperty},
|
| 38 |
+
depsCount: ${depsCount},
|
| 39 |
+
deps: ${deps}}`, // TODO change to reference
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
const def: CodeKeywordDefinition = {
|
| 43 |
+
keyword: "dependencies",
|
| 44 |
+
type: "object",
|
| 45 |
+
schemaType: "object",
|
| 46 |
+
error,
|
| 47 |
+
code(cxt: KeywordCxt) {
|
| 48 |
+
const [propDeps, schDeps] = splitDependencies(cxt)
|
| 49 |
+
validatePropertyDeps(cxt, propDeps)
|
| 50 |
+
validateSchemaDeps(cxt, schDeps)
|
| 51 |
+
},
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function splitDependencies({schema}: KeywordCxt): [PropertyDependencies, SchemaDependencies] {
|
| 55 |
+
const propertyDeps: PropertyDependencies = {}
|
| 56 |
+
const schemaDeps: SchemaDependencies = {}
|
| 57 |
+
for (const key in schema) {
|
| 58 |
+
if (key === "__proto__") continue
|
| 59 |
+
const deps = Array.isArray(schema[key]) ? propertyDeps : schemaDeps
|
| 60 |
+
deps[key] = schema[key]
|
| 61 |
+
}
|
| 62 |
+
return [propertyDeps, schemaDeps]
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
export function validatePropertyDeps(
|
| 66 |
+
cxt: KeywordCxt,
|
| 67 |
+
propertyDeps: {[K in string]?: string[]} = cxt.schema
|
| 68 |
+
): void {
|
| 69 |
+
const {gen, data, it} = cxt
|
| 70 |
+
if (Object.keys(propertyDeps).length === 0) return
|
| 71 |
+
const missing = gen.let("missing")
|
| 72 |
+
for (const prop in propertyDeps) {
|
| 73 |
+
const deps = propertyDeps[prop] as string[]
|
| 74 |
+
if (deps.length === 0) continue
|
| 75 |
+
const hasProperty = propertyInData(gen, data, prop, it.opts.ownProperties)
|
| 76 |
+
cxt.setParams({
|
| 77 |
+
property: prop,
|
| 78 |
+
depsCount: deps.length,
|
| 79 |
+
deps: deps.join(", "),
|
| 80 |
+
})
|
| 81 |
+
if (it.allErrors) {
|
| 82 |
+
gen.if(hasProperty, () => {
|
| 83 |
+
for (const depProp of deps) {
|
| 84 |
+
checkReportMissingProp(cxt, depProp)
|
| 85 |
+
}
|
| 86 |
+
})
|
| 87 |
+
} else {
|
| 88 |
+
gen.if(_`${hasProperty} && (${checkMissingProp(cxt, deps, missing)})`)
|
| 89 |
+
reportMissingProp(cxt, missing)
|
| 90 |
+
gen.else()
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
export function validateSchemaDeps(cxt: KeywordCxt, schemaDeps: SchemaMap = cxt.schema): void {
|
| 96 |
+
const {gen, data, keyword, it} = cxt
|
| 97 |
+
const valid = gen.name("valid")
|
| 98 |
+
for (const prop in schemaDeps) {
|
| 99 |
+
if (alwaysValidSchema(it, schemaDeps[prop] as AnySchema)) continue
|
| 100 |
+
gen.if(
|
| 101 |
+
propertyInData(gen, data, prop, it.opts.ownProperties),
|
| 102 |
+
() => {
|
| 103 |
+
const schCxt = cxt.subschema({keyword, schemaProp: prop}, valid)
|
| 104 |
+
cxt.mergeValidEvaluated(schCxt, valid)
|
| 105 |
+
},
|
| 106 |
+
() => gen.var(valid, true) // TODO var
|
| 107 |
+
)
|
| 108 |
+
cxt.ok(valid)
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/dependentSchemas.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {CodeKeywordDefinition} from "../../types"
|
| 2 |
+
import {validateSchemaDeps} from "./dependencies"
|
| 3 |
+
|
| 4 |
+
const def: CodeKeywordDefinition = {
|
| 5 |
+
keyword: "dependentSchemas",
|
| 6 |
+
type: "object",
|
| 7 |
+
schemaType: "object",
|
| 8 |
+
code: (cxt) => validateSchemaDeps(cxt),
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/if.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {
|
| 2 |
+
CodeKeywordDefinition,
|
| 3 |
+
ErrorObject,
|
| 4 |
+
KeywordErrorDefinition,
|
| 5 |
+
AnySchema,
|
| 6 |
+
} from "../../types"
|
| 7 |
+
import type {SchemaObjCxt} from "../../compile"
|
| 8 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 9 |
+
import {_, str, not, Name} from "../../compile/codegen"
|
| 10 |
+
import {alwaysValidSchema, checkStrictMode} from "../../compile/util"
|
| 11 |
+
|
| 12 |
+
export type IfKeywordError = ErrorObject<"if", {failingKeyword: string}, AnySchema>
|
| 13 |
+
|
| 14 |
+
const error: KeywordErrorDefinition = {
|
| 15 |
+
message: ({params}) => str`must match "${params.ifClause}" schema`,
|
| 16 |
+
params: ({params}) => _`{failingKeyword: ${params.ifClause}}`,
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
const def: CodeKeywordDefinition = {
|
| 20 |
+
keyword: "if",
|
| 21 |
+
schemaType: ["object", "boolean"],
|
| 22 |
+
trackErrors: true,
|
| 23 |
+
error,
|
| 24 |
+
code(cxt: KeywordCxt) {
|
| 25 |
+
const {gen, parentSchema, it} = cxt
|
| 26 |
+
if (parentSchema.then === undefined && parentSchema.else === undefined) {
|
| 27 |
+
checkStrictMode(it, '"if" without "then" and "else" is ignored')
|
| 28 |
+
}
|
| 29 |
+
const hasThen = hasSchema(it, "then")
|
| 30 |
+
const hasElse = hasSchema(it, "else")
|
| 31 |
+
if (!hasThen && !hasElse) return
|
| 32 |
+
|
| 33 |
+
const valid = gen.let("valid", true)
|
| 34 |
+
const schValid = gen.name("_valid")
|
| 35 |
+
validateIf()
|
| 36 |
+
cxt.reset()
|
| 37 |
+
|
| 38 |
+
if (hasThen && hasElse) {
|
| 39 |
+
const ifClause = gen.let("ifClause")
|
| 40 |
+
cxt.setParams({ifClause})
|
| 41 |
+
gen.if(schValid, validateClause("then", ifClause), validateClause("else", ifClause))
|
| 42 |
+
} else if (hasThen) {
|
| 43 |
+
gen.if(schValid, validateClause("then"))
|
| 44 |
+
} else {
|
| 45 |
+
gen.if(not(schValid), validateClause("else"))
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
cxt.pass(valid, () => cxt.error(true))
|
| 49 |
+
|
| 50 |
+
function validateIf(): void {
|
| 51 |
+
const schCxt = cxt.subschema(
|
| 52 |
+
{
|
| 53 |
+
keyword: "if",
|
| 54 |
+
compositeRule: true,
|
| 55 |
+
createErrors: false,
|
| 56 |
+
allErrors: false,
|
| 57 |
+
},
|
| 58 |
+
schValid
|
| 59 |
+
)
|
| 60 |
+
cxt.mergeEvaluated(schCxt)
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function validateClause(keyword: string, ifClause?: Name): () => void {
|
| 64 |
+
return () => {
|
| 65 |
+
const schCxt = cxt.subschema({keyword}, schValid)
|
| 66 |
+
gen.assign(valid, schValid)
|
| 67 |
+
cxt.mergeValidEvaluated(schCxt, valid)
|
| 68 |
+
if (ifClause) gen.assign(ifClause, _`${keyword}`)
|
| 69 |
+
else cxt.setParams({ifClause: keyword})
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function hasSchema(it: SchemaObjCxt, keyword: string): boolean {
|
| 76 |
+
const schema = it.schema[keyword]
|
| 77 |
+
return schema !== undefined && !alwaysValidSchema(it, schema)
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {ErrorNoParams, Vocabulary} from "../../types"
|
| 2 |
+
import additionalItems, {AdditionalItemsError} from "./additionalItems"
|
| 3 |
+
import prefixItems from "./prefixItems"
|
| 4 |
+
import items from "./items"
|
| 5 |
+
import items2020, {ItemsError} from "./items2020"
|
| 6 |
+
import contains, {ContainsError} from "./contains"
|
| 7 |
+
import dependencies, {DependenciesError} from "./dependencies"
|
| 8 |
+
import propertyNames, {PropertyNamesError} from "./propertyNames"
|
| 9 |
+
import additionalProperties, {AdditionalPropertiesError} from "./additionalProperties"
|
| 10 |
+
import properties from "./properties"
|
| 11 |
+
import patternProperties from "./patternProperties"
|
| 12 |
+
import notKeyword, {NotKeywordError} from "./not"
|
| 13 |
+
import anyOf, {AnyOfError} from "./anyOf"
|
| 14 |
+
import oneOf, {OneOfError} from "./oneOf"
|
| 15 |
+
import allOf from "./allOf"
|
| 16 |
+
import ifKeyword, {IfKeywordError} from "./if"
|
| 17 |
+
import thenElse from "./thenElse"
|
| 18 |
+
|
| 19 |
+
export default function getApplicator(draft2020 = false): Vocabulary {
|
| 20 |
+
const applicator = [
|
| 21 |
+
// any
|
| 22 |
+
notKeyword,
|
| 23 |
+
anyOf,
|
| 24 |
+
oneOf,
|
| 25 |
+
allOf,
|
| 26 |
+
ifKeyword,
|
| 27 |
+
thenElse,
|
| 28 |
+
// object
|
| 29 |
+
propertyNames,
|
| 30 |
+
additionalProperties,
|
| 31 |
+
dependencies,
|
| 32 |
+
properties,
|
| 33 |
+
patternProperties,
|
| 34 |
+
]
|
| 35 |
+
// array
|
| 36 |
+
if (draft2020) applicator.push(prefixItems, items2020)
|
| 37 |
+
else applicator.push(additionalItems, items)
|
| 38 |
+
applicator.push(contains)
|
| 39 |
+
return applicator
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export type ApplicatorKeywordError =
|
| 43 |
+
| ErrorNoParams<"false schema">
|
| 44 |
+
| AdditionalItemsError
|
| 45 |
+
| ItemsError
|
| 46 |
+
| ContainsError
|
| 47 |
+
| AdditionalPropertiesError
|
| 48 |
+
| DependenciesError
|
| 49 |
+
| IfKeywordError
|
| 50 |
+
| AnyOfError
|
| 51 |
+
| OneOfError
|
| 52 |
+
| NotKeywordError
|
| 53 |
+
| PropertyNamesError
|
node_modules/ajv/lib/vocabularies/applicator/items.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {CodeKeywordDefinition, AnySchema, AnySchemaObject} from "../../types"
|
| 2 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 3 |
+
import {_} from "../../compile/codegen"
|
| 4 |
+
import {alwaysValidSchema, mergeEvaluated, checkStrictMode} from "../../compile/util"
|
| 5 |
+
import {validateArray} from "../code"
|
| 6 |
+
|
| 7 |
+
const def: CodeKeywordDefinition = {
|
| 8 |
+
keyword: "items",
|
| 9 |
+
type: "array",
|
| 10 |
+
schemaType: ["object", "array", "boolean"],
|
| 11 |
+
before: "uniqueItems",
|
| 12 |
+
code(cxt: KeywordCxt) {
|
| 13 |
+
const {schema, it} = cxt
|
| 14 |
+
if (Array.isArray(schema)) return validateTuple(cxt, "additionalItems", schema)
|
| 15 |
+
it.items = true
|
| 16 |
+
if (alwaysValidSchema(it, schema)) return
|
| 17 |
+
cxt.ok(validateArray(cxt))
|
| 18 |
+
},
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
export function validateTuple(
|
| 22 |
+
cxt: KeywordCxt,
|
| 23 |
+
extraItems: string,
|
| 24 |
+
schArr: AnySchema[] = cxt.schema
|
| 25 |
+
): void {
|
| 26 |
+
const {gen, parentSchema, data, keyword, it} = cxt
|
| 27 |
+
checkStrictTuple(parentSchema)
|
| 28 |
+
if (it.opts.unevaluated && schArr.length && it.items !== true) {
|
| 29 |
+
it.items = mergeEvaluated.items(gen, schArr.length, it.items)
|
| 30 |
+
}
|
| 31 |
+
const valid = gen.name("valid")
|
| 32 |
+
const len = gen.const("len", _`${data}.length`)
|
| 33 |
+
schArr.forEach((sch: AnySchema, i: number) => {
|
| 34 |
+
if (alwaysValidSchema(it, sch)) return
|
| 35 |
+
gen.if(_`${len} > ${i}`, () =>
|
| 36 |
+
cxt.subschema(
|
| 37 |
+
{
|
| 38 |
+
keyword,
|
| 39 |
+
schemaProp: i,
|
| 40 |
+
dataProp: i,
|
| 41 |
+
},
|
| 42 |
+
valid
|
| 43 |
+
)
|
| 44 |
+
)
|
| 45 |
+
cxt.ok(valid)
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
function checkStrictTuple(sch: AnySchemaObject): void {
|
| 49 |
+
const {opts, errSchemaPath} = it
|
| 50 |
+
const l = schArr.length
|
| 51 |
+
const fullTuple = l === sch.minItems && (l === sch.maxItems || sch[extraItems] === false)
|
| 52 |
+
if (opts.strictTuples && !fullTuple) {
|
| 53 |
+
const msg = `"${keyword}" is ${l}-tuple, but minItems or maxItems/${extraItems} are not specified or different at path "${errSchemaPath}"`
|
| 54 |
+
checkStrictMode(it, msg, opts.strictTuples)
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
export default def
|
node_modules/ajv/lib/vocabularies/applicator/items2020.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type {
|
| 2 |
+
CodeKeywordDefinition,
|
| 3 |
+
KeywordErrorDefinition,
|
| 4 |
+
ErrorObject,
|
| 5 |
+
AnySchema,
|
| 6 |
+
} from "../../types"
|
| 7 |
+
import type {KeywordCxt} from "../../compile/validate"
|
| 8 |
+
import {_, str} from "../../compile/codegen"
|
| 9 |
+
import {alwaysValidSchema} from "../../compile/util"
|
| 10 |
+
import {validateArray} from "../code"
|
| 11 |
+
import {validateAdditionalItems} from "./additionalItems"
|
| 12 |
+
|
| 13 |
+
export type ItemsError = ErrorObject<"items", {limit: number}, AnySchema>
|
| 14 |
+
|
| 15 |
+
const error: KeywordErrorDefinition = {
|
| 16 |
+
message: ({params: {len}}) => str`must NOT have more than ${len} items`,
|
| 17 |
+
params: ({params: {len}}) => _`{limit: ${len}}`,
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
const def: CodeKeywordDefinition = {
|
| 21 |
+
keyword: "items",
|
| 22 |
+
type: "array",
|
| 23 |
+
schemaType: ["object", "boolean"],
|
| 24 |
+
before: "uniqueItems",
|
| 25 |
+
error,
|
| 26 |
+
code(cxt: KeywordCxt) {
|
| 27 |
+
const {schema, parentSchema, it} = cxt
|
| 28 |
+
const {prefixItems} = parentSchema
|
| 29 |
+
it.items = true
|
| 30 |
+
if (alwaysValidSchema(it, schema)) return
|
| 31 |
+
if (prefixItems) validateAdditionalItems(cxt, prefixItems)
|
| 32 |
+
else cxt.ok(validateArray(cxt))
|
| 33 |
+
},
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export default def
|