Upload via GUI (7543 Dateien)
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
|||||||
|
import type { CodeKeywordDefinition, ErrorObject, AnySchema } from "../../types";
|
||||||
|
export type PropertyNamesError = ErrorObject<"propertyNames", {
|
||||||
|
propertyName: string;
|
||||||
|
}, AnySchema>;
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const codegen_1 = require("../../compile/codegen");
|
||||||
|
const util_1 = require("../../compile/util");
|
||||||
|
const error = {
|
||||||
|
message: "property name must be valid",
|
||||||
|
params: ({ params }) => (0, codegen_1._) `{propertyName: ${params.propertyName}}`,
|
||||||
|
};
|
||||||
|
const def = {
|
||||||
|
keyword: "propertyNames",
|
||||||
|
type: "object",
|
||||||
|
schemaType: ["object", "boolean"],
|
||||||
|
error,
|
||||||
|
code(cxt) {
|
||||||
|
const { gen, schema, data, it } = cxt;
|
||||||
|
if ((0, util_1.alwaysValidSchema)(it, schema))
|
||||||
|
return;
|
||||||
|
const valid = gen.name("valid");
|
||||||
|
gen.forIn("key", data, (key) => {
|
||||||
|
cxt.setParams({ propertyName: key });
|
||||||
|
cxt.subschema({
|
||||||
|
keyword: "propertyNames",
|
||||||
|
data: key,
|
||||||
|
dataTypes: ["string"],
|
||||||
|
propertyName: key,
|
||||||
|
compositeRule: true,
|
||||||
|
}, valid);
|
||||||
|
gen.if((0, codegen_1.not)(valid), () => {
|
||||||
|
cxt.error(true);
|
||||||
|
if (!it.allErrors)
|
||||||
|
gen.break();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
cxt.ok(valid);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=propertyNames.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"propertyNames.js","sourceRoot":"","sources":["../../../lib/vocab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E,CAAC,KAAK,CAAC,CAAA;IACf,CAAC;CACF,CAAA;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const util_1 = require("../../compile/util");
|
||||||
|
const def = {
|
||||||
|
keyword: ["then", "else"],
|
||||||
|
schemaType: ["object", "boolean"],
|
||||||
|
code({ keyword, parentSchema, it }) {
|
||||||
|
if (parentSchema.if === undefined)
|
||||||
|
(0, util_1.checkStrictMode)(it, `"${keyword}" without "if" is ignored`);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=thenElse.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"thenElse.js","sourceRoot":"","sources":["../../../lib/vocabularies/applicator/thenElse.ts"],"names":[],"mappings":";;AAEA,6CAAkD;AAElD,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;IACjC,IAAI,CAAC,EAAC,OAAO,EAAE,YAAY,EAAE,EAAE,EAAa;QAC1C,IAAI,YAAY,CAAC,EAAE,KAAK,SAAS;YAAE,IAAA,sBAAe,EAAC,EAAE,EAAE,IAAI,OAAO,2BAA2B,CAAC,CAAA;IAChG,CAAC;CACF,CAAA;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
import type { SchemaMap } from "../types";
|
||||||
|
import type { SchemaCxt } from "../compile";
|
||||||
|
import type { KeywordCxt } from "../compile/validate";
|
||||||
|
import { CodeGen, Code, Name } from "../compile/codegen";
|
||||||
|
export declare function checkReportMissingProp(cxt: KeywordCxt, prop: string): void;
|
||||||
|
export declare function checkMissingProp({ gen, data, it: { opts } }: KeywordCxt, properties: string[], missing: Name): Code;
|
||||||
|
export declare function reportMissingProp(cxt: KeywordCxt, missing: Name): void;
|
||||||
|
export declare function hasPropFunc(gen: CodeGen): Name;
|
||||||
|
export declare function isOwnProperty(gen: CodeGen, data: Name, property: Name | string): Code;
|
||||||
|
export declare function propertyInData(gen: CodeGen, data: Name, property: Name | string, ownProperties?: boolean): Code;
|
||||||
|
export declare function noPropertyInData(gen: CodeGen, data: Name, property: Name | string, ownProperties?: boolean): Code;
|
||||||
|
export declare function allSchemaProperties(schemaMap?: SchemaMap): string[];
|
||||||
|
export declare function schemaProperties(it: SchemaCxt, schemaMap: SchemaMap): string[];
|
||||||
|
export declare function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }: KeywordCxt, func: Code, context: Code, passSchema?: boolean): Code;
|
||||||
|
export declare function usePattern({ gen, it: { opts } }: KeywordCxt, pattern: string): Name;
|
||||||
|
export declare function validateArray(cxt: KeywordCxt): Name;
|
||||||
|
export declare function validateUnion(cxt: KeywordCxt): void;
|
||||||
+131
@@ -0,0 +1,131 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.validateUnion = exports.validateArray = exports.usePattern = exports.callValidateCode = exports.schemaProperties = exports.allSchemaProperties = exports.noPropertyInData = exports.propertyInData = exports.isOwnProperty = exports.hasPropFunc = exports.reportMissingProp = exports.checkMissingProp = exports.checkReportMissingProp = void 0;
|
||||||
|
const codegen_1 = require("../compile/codegen");
|
||||||
|
const util_1 = require("../compile/util");
|
||||||
|
const names_1 = require("../compile/names");
|
||||||
|
const util_2 = require("../compile/util");
|
||||||
|
function checkReportMissingProp(cxt, prop) {
|
||||||
|
const { gen, data, it } = cxt;
|
||||||
|
gen.if(noPropertyInData(gen, data, prop, it.opts.ownProperties), () => {
|
||||||
|
cxt.setParams({ missingProperty: (0, codegen_1._) `${prop}` }, true);
|
||||||
|
cxt.error();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.checkReportMissingProp = checkReportMissingProp;
|
||||||
|
function checkMissingProp({ gen, data, it: { opts } }, properties, missing) {
|
||||||
|
return (0, codegen_1.or)(...properties.map((prop) => (0, codegen_1.and)(noPropertyInData(gen, data, prop, opts.ownProperties), (0, codegen_1._) `${missing} = ${prop}`)));
|
||||||
|
}
|
||||||
|
exports.checkMissingProp = checkMissingProp;
|
||||||
|
function reportMissingProp(cxt, missing) {
|
||||||
|
cxt.setParams({ missingProperty: missing }, true);
|
||||||
|
cxt.error();
|
||||||
|
}
|
||||||
|
exports.reportMissingProp = reportMissingProp;
|
||||||
|
function hasPropFunc(gen) {
|
||||||
|
return gen.scopeValue("func", {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||||
|
ref: Object.prototype.hasOwnProperty,
|
||||||
|
code: (0, codegen_1._) `Object.prototype.hasOwnProperty`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.hasPropFunc = hasPropFunc;
|
||||||
|
function isOwnProperty(gen, data, property) {
|
||||||
|
return (0, codegen_1._) `${hasPropFunc(gen)}.call(${data}, ${property})`;
|
||||||
|
}
|
||||||
|
exports.isOwnProperty = isOwnProperty;
|
||||||
|
function propertyInData(gen, data, property, ownProperties) {
|
||||||
|
const cond = (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(property)} !== undefined`;
|
||||||
|
return ownProperties ? (0, codegen_1._) `${cond} && ${isOwnProperty(gen, data, property)}` : cond;
|
||||||
|
}
|
||||||
|
exports.propertyInData = propertyInData;
|
||||||
|
function noPropertyInData(gen, data, property, ownProperties) {
|
||||||
|
const cond = (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(property)} === undefined`;
|
||||||
|
return ownProperties ? (0, codegen_1.or)(cond, (0, codegen_1.not)(isOwnProperty(gen, data, property))) : cond;
|
||||||
|
}
|
||||||
|
exports.noPropertyInData = noPropertyInData;
|
||||||
|
function allSchemaProperties(schemaMap) {
|
||||||
|
return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
|
||||||
|
}
|
||||||
|
exports.allSchemaProperties = allSchemaProperties;
|
||||||
|
function schemaProperties(it, schemaMap) {
|
||||||
|
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1.alwaysValidSchema)(it, schemaMap[p]));
|
||||||
|
}
|
||||||
|
exports.schemaProperties = schemaProperties;
|
||||||
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
||||||
|
const dataAndSchema = passSchema ? (0, codegen_1._) `${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
|
||||||
|
const valCxt = [
|
||||||
|
[names_1.default.instancePath, (0, codegen_1.strConcat)(names_1.default.instancePath, errorPath)],
|
||||||
|
[names_1.default.parentData, it.parentData],
|
||||||
|
[names_1.default.parentDataProperty, it.parentDataProperty],
|
||||||
|
[names_1.default.rootData, names_1.default.rootData],
|
||||||
|
];
|
||||||
|
if (it.opts.dynamicRef)
|
||||||
|
valCxt.push([names_1.default.dynamicAnchors, names_1.default.dynamicAnchors]);
|
||||||
|
const args = (0, codegen_1._) `${dataAndSchema}, ${gen.object(...valCxt)}`;
|
||||||
|
return context !== codegen_1.nil ? (0, codegen_1._) `${func}.call(${context}, ${args})` : (0, codegen_1._) `${func}(${args})`;
|
||||||
|
}
|
||||||
|
exports.callValidateCode = callValidateCode;
|
||||||
|
const newRegExp = (0, codegen_1._) `new RegExp`;
|
||||||
|
function usePattern({ gen, it: { opts } }, pattern) {
|
||||||
|
const u = opts.unicodeRegExp ? "u" : "";
|
||||||
|
const { regExp } = opts.code;
|
||||||
|
const rx = regExp(pattern, u);
|
||||||
|
return gen.scopeValue("pattern", {
|
||||||
|
key: rx.toString(),
|
||||||
|
ref: rx,
|
||||||
|
code: (0, codegen_1._) `${regExp.code === "new RegExp" ? newRegExp : (0, util_2.useFunc)(gen, regExp)}(${pattern}, ${u})`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.usePattern = usePattern;
|
||||||
|
function validateArray(cxt) {
|
||||||
|
const { gen, data, keyword, it } = cxt;
|
||||||
|
const valid = gen.name("valid");
|
||||||
|
if (it.allErrors) {
|
||||||
|
const validArr = gen.let("valid", true);
|
||||||
|
validateItems(() => gen.assign(validArr, false));
|
||||||
|
return validArr;
|
||||||
|
}
|
||||||
|
gen.var(valid, true);
|
||||||
|
validateItems(() => gen.break());
|
||||||
|
return valid;
|
||||||
|
function validateItems(notValid) {
|
||||||
|
const len = gen.const("len", (0, codegen_1._) `${data}.length`);
|
||||||
|
gen.forRange("i", 0, len, (i) => {
|
||||||
|
cxt.subschema({
|
||||||
|
keyword,
|
||||||
|
dataProp: i,
|
||||||
|
dataPropType: util_1.Type.Num,
|
||||||
|
}, valid);
|
||||||
|
gen.if((0, codegen_1.not)(valid), notValid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.validateArray = validateArray;
|
||||||
|
function validateUnion(cxt) {
|
||||||
|
const { gen, schema, keyword, it } = cxt;
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (!Array.isArray(schema))
|
||||||
|
throw new Error("ajv implementation error");
|
||||||
|
const alwaysValid = schema.some((sch) => (0, util_1.alwaysValidSchema)(it, sch));
|
||||||
|
if (alwaysValid && !it.opts.unevaluated)
|
||||||
|
return;
|
||||||
|
const valid = gen.let("valid", false);
|
||||||
|
const schValid = gen.name("_valid");
|
||||||
|
gen.block(() => schema.forEach((_sch, i) => {
|
||||||
|
const schCxt = cxt.subschema({
|
||||||
|
keyword,
|
||||||
|
schemaProp: i,
|
||||||
|
compositeRule: true,
|
||||||
|
}, schValid);
|
||||||
|
gen.assign(valid, (0, codegen_1._) `${valid} || ${schValid}`);
|
||||||
|
const merged = cxt.mergeValidEvaluated(schCxt, schValid);
|
||||||
|
// can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true)
|
||||||
|
// or if all properties and items were evaluated (it.props === true && it.items === true)
|
||||||
|
if (!merged)
|
||||||
|
gen.if((0, codegen_1.not)(valid));
|
||||||
|
}));
|
||||||
|
cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
|
||||||
|
}
|
||||||
|
exports.validateUnion = validateUnion;
|
||||||
|
//# sourceMappingURL=code.js.map
|
||||||
+1
File diff suppressed because one or more lines are too long
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const def = {
|
||||||
|
keyword: "id",
|
||||||
|
code() {
|
||||||
|
throw new Error('NOT SUPPORTED: keyword "id", use "$id" for schema ID');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=id.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../../lib/vocabularies/core/id.ts"],"names":[],"mappings":";;AAEA,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,IAAI;IACb,IAAI;QACF,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;CACF,CAAA;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { Vocabulary } from "../../types";
|
||||||
|
declare const core: Vocabulary;
|
||||||
|
export default core;
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const id_1 = require("./id");
|
||||||
|
const ref_1 = require("./ref");
|
||||||
|
const core = [
|
||||||
|
"$schema",
|
||||||
|
"$id",
|
||||||
|
"$defs",
|
||||||
|
"$vocabulary",
|
||||||
|
{ keyword: "$comment" },
|
||||||
|
"definitions",
|
||||||
|
id_1.default,
|
||||||
|
ref_1.default,
|
||||||
|
];
|
||||||
|
exports.default = core;
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/vocabularies/core/index.ts"],"names":[],"mappings":";;AACA,6BAA4B;AAC5B,+BAA8B;AAE9B,MAAM,IAAI,GAAe;IACvB,SAAS;IACT,KAAK;IACL,OAAO;IACP,aAAa;IACb,EAAC,OAAO,EAAE,UAAU,EAAC;IACrB,aAAa;IACb,YAAS;IACT,aAAU;CACX,CAAA;AAED,kBAAe,IAAI,CAAA"}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
import type { KeywordCxt } from "../../compile/validate";
|
||||||
|
import { Code } from "../../compile/codegen";
|
||||||
|
import { SchemaEnv } from "../../compile";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export declare function getValidate(cxt: KeywordCxt, sch: SchemaEnv): Code;
|
||||||
|
export declare function callRef(cxt: KeywordCxt, v: Code, sch?: SchemaEnv, $async?: boolean): void;
|
||||||
|
export default def;
|
||||||
+122
@@ -0,0 +1,122 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.callRef = exports.getValidate = void 0;
|
||||||
|
const ref_error_1 = require("../../compile/ref_error");
|
||||||
|
const code_1 = require("../code");
|
||||||
|
const codegen_1 = require("../../compile/codegen");
|
||||||
|
const names_1 = require("../../compile/names");
|
||||||
|
const compile_1 = require("../../compile");
|
||||||
|
const util_1 = require("../../compile/util");
|
||||||
|
const def = {
|
||||||
|
keyword: "$ref",
|
||||||
|
schemaType: "string",
|
||||||
|
code(cxt) {
|
||||||
|
const { gen, schema: $ref, it } = cxt;
|
||||||
|
const { baseId, schemaEnv: env, validateName, opts, self } = it;
|
||||||
|
const { root } = env;
|
||||||
|
if (($ref === "#" || $ref === "#/") && baseId === root.baseId)
|
||||||
|
return callRootRef();
|
||||||
|
const schOrEnv = compile_1.resolveRef.call(self, root, baseId, $ref);
|
||||||
|
if (schOrEnv === undefined)
|
||||||
|
throw new ref_error_1.default(it.opts.uriResolver, baseId, $ref);
|
||||||
|
if (schOrEnv instanceof compile_1.SchemaEnv)
|
||||||
|
return callValidate(schOrEnv);
|
||||||
|
return inlineRefSchema(schOrEnv);
|
||||||
|
function callRootRef() {
|
||||||
|
if (env === root)
|
||||||
|
return callRef(cxt, validateName, env, env.$async);
|
||||||
|
const rootName = gen.scopeValue("root", { ref: root });
|
||||||
|
return callRef(cxt, (0, codegen_1._) `${rootName}.validate`, root, root.$async);
|
||||||
|
}
|
||||||
|
function callValidate(sch) {
|
||||||
|
const v = getValidate(cxt, sch);
|
||||||
|
callRef(cxt, v, sch, sch.$async);
|
||||||
|
}
|
||||||
|
function inlineRefSchema(sch) {
|
||||||
|
const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
|
||||||
|
const valid = gen.name("valid");
|
||||||
|
const schCxt = cxt.subschema({
|
||||||
|
schema: sch,
|
||||||
|
dataTypes: [],
|
||||||
|
schemaPath: codegen_1.nil,
|
||||||
|
topSchemaRef: schName,
|
||||||
|
errSchemaPath: $ref,
|
||||||
|
}, valid);
|
||||||
|
cxt.mergeEvaluated(schCxt);
|
||||||
|
cxt.ok(valid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
function getValidate(cxt, sch) {
|
||||||
|
const { gen } = cxt;
|
||||||
|
return sch.validate
|
||||||
|
? gen.scopeValue("validate", { ref: sch.validate })
|
||||||
|
: (0, codegen_1._) `${gen.scopeValue("wrapper", { ref: sch })}.validate`;
|
||||||
|
}
|
||||||
|
exports.getValidate = getValidate;
|
||||||
|
function callRef(cxt, v, sch, $async) {
|
||||||
|
const { gen, it } = cxt;
|
||||||
|
const { allErrors, schemaEnv: env, opts } = it;
|
||||||
|
const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
|
||||||
|
if ($async)
|
||||||
|
callAsyncRef();
|
||||||
|
else
|
||||||
|
callSyncRef();
|
||||||
|
function callAsyncRef() {
|
||||||
|
if (!env.$async)
|
||||||
|
throw new Error("async schema referenced by sync schema");
|
||||||
|
const valid = gen.let("valid");
|
||||||
|
gen.try(() => {
|
||||||
|
gen.code((0, codegen_1._) `await ${(0, code_1.callValidateCode)(cxt, v, passCxt)}`);
|
||||||
|
addEvaluatedFrom(v); // TODO will not work with async, it has to be returned with the result
|
||||||
|
if (!allErrors)
|
||||||
|
gen.assign(valid, true);
|
||||||
|
}, (e) => {
|
||||||
|
gen.if((0, codegen_1._) `!(${e} instanceof ${it.ValidationError})`, () => gen.throw(e));
|
||||||
|
addErrorsFrom(e);
|
||||||
|
if (!allErrors)
|
||||||
|
gen.assign(valid, false);
|
||||||
|
});
|
||||||
|
cxt.ok(valid);
|
||||||
|
}
|
||||||
|
function callSyncRef() {
|
||||||
|
cxt.result((0, code_1.callValidateCode)(cxt, v, passCxt), () => addEvaluatedFrom(v), () => addErrorsFrom(v));
|
||||||
|
}
|
||||||
|
function addErrorsFrom(source) {
|
||||||
|
const errs = (0, codegen_1._) `${source}.errors`;
|
||||||
|
gen.assign(names_1.default.vErrors, (0, codegen_1._) `${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`); // TODO tagged
|
||||||
|
gen.assign(names_1.default.errors, (0, codegen_1._) `${names_1.default.vErrors}.length`);
|
||||||
|
}
|
||||||
|
function addEvaluatedFrom(source) {
|
||||||
|
var _a;
|
||||||
|
if (!it.opts.unevaluated)
|
||||||
|
return;
|
||||||
|
const schEvaluated = (_a = sch === null || sch === void 0 ? void 0 : sch.validate) === null || _a === void 0 ? void 0 : _a.evaluated;
|
||||||
|
// TODO refactor
|
||||||
|
if (it.props !== true) {
|
||||||
|
if (schEvaluated && !schEvaluated.dynamicProps) {
|
||||||
|
if (schEvaluated.props !== undefined) {
|
||||||
|
it.props = util_1.mergeEvaluated.props(gen, schEvaluated.props, it.props);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const props = gen.var("props", (0, codegen_1._) `${source}.evaluated.props`);
|
||||||
|
it.props = util_1.mergeEvaluated.props(gen, props, it.props, codegen_1.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (it.items !== true) {
|
||||||
|
if (schEvaluated && !schEvaluated.dynamicItems) {
|
||||||
|
if (schEvaluated.items !== undefined) {
|
||||||
|
it.items = util_1.mergeEvaluated.items(gen, schEvaluated.items, it.items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const items = gen.var("items", (0, codegen_1._) `${source}.evaluated.items`);
|
||||||
|
it.items = util_1.mergeEvaluated.items(gen, items, it.items, codegen_1.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.callRef = callRef;
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=ref.js.map
|
||||||
+1
File diff suppressed because one or more lines are too long
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
import { DiscrError, DiscrErrorObj } from "../discriminator/types";
|
||||||
|
export type DiscriminatorError = DiscrErrorObj<DiscrError.Tag> | DiscrErrorObj<DiscrError.Mapping>;
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const codegen_1 = require("../../compile/codegen");
|
||||||
|
const types_1 = require("../discriminator/types");
|
||||||
|
const compile_1 = require("../../compile");
|
||||||
|
const ref_error_1 = require("../../compile/ref_error");
|
||||||
|
const util_1 = require("../../compile/util");
|
||||||
|
const error = {
|
||||||
|
message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag
|
||||||
|
? `tag "${tagName}" must be string`
|
||||||
|
: `value of tag "${tagName}" must be in oneOf`,
|
||||||
|
params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._) `{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`,
|
||||||
|
};
|
||||||
|
const def = {
|
||||||
|
keyword: "discriminator",
|
||||||
|
type: "object",
|
||||||
|
schemaType: "object",
|
||||||
|
error,
|
||||||
|
code(cxt) {
|
||||||
|
const { gen, data, schema, parentSchema, it } = cxt;
|
||||||
|
const { oneOf } = parentSchema;
|
||||||
|
if (!it.opts.discriminator) {
|
||||||
|
throw new Error("discriminator: requires discriminator option");
|
||||||
|
}
|
||||||
|
const tagName = schema.propertyName;
|
||||||
|
if (typeof tagName != "string")
|
||||||
|
throw new Error("discriminator: requires propertyName");
|
||||||
|
if (schema.mapping)
|
||||||
|
throw new Error("discriminator: mapping is not supported");
|
||||||
|
if (!oneOf)
|
||||||
|
throw new Error("discriminator: requires oneOf keyword");
|
||||||
|
const valid = gen.let("valid", false);
|
||||||
|
const tag = gen.const("tag", (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(tagName)}`);
|
||||||
|
gen.if((0, codegen_1._) `typeof ${tag} == "string"`, () => validateMapping(), () => cxt.error(false, { discrError: types_1.DiscrError.Tag, tag, tagName }));
|
||||||
|
cxt.ok(valid);
|
||||||
|
function validateMapping() {
|
||||||
|
const mapping = getMapping();
|
||||||
|
gen.if(false);
|
||||||
|
for (const tagValue in mapping) {
|
||||||
|
gen.elseIf((0, codegen_1._) `${tag} === ${tagValue}`);
|
||||||
|
gen.assign(valid, applyTagSchema(mapping[tagValue]));
|
||||||
|
}
|
||||||
|
gen.else();
|
||||||
|
cxt.error(false, { discrError: types_1.DiscrError.Mapping, tag, tagName });
|
||||||
|
gen.endIf();
|
||||||
|
}
|
||||||
|
function applyTagSchema(schemaProp) {
|
||||||
|
const _valid = gen.name("valid");
|
||||||
|
const schCxt = cxt.subschema({ keyword: "oneOf", schemaProp }, _valid);
|
||||||
|
cxt.mergeEvaluated(schCxt, codegen_1.Name);
|
||||||
|
return _valid;
|
||||||
|
}
|
||||||
|
function getMapping() {
|
||||||
|
var _a;
|
||||||
|
const oneOfMapping = {};
|
||||||
|
const topRequired = hasRequired(parentSchema);
|
||||||
|
let tagRequired = true;
|
||||||
|
for (let i = 0; i < oneOf.length; i++) {
|
||||||
|
let sch = oneOf[i];
|
||||||
|
if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it.self.RULES)) {
|
||||||
|
const ref = sch.$ref;
|
||||||
|
sch = compile_1.resolveRef.call(it.self, it.schemaEnv.root, it.baseId, ref);
|
||||||
|
if (sch instanceof compile_1.SchemaEnv)
|
||||||
|
sch = sch.schema;
|
||||||
|
if (sch === undefined)
|
||||||
|
throw new ref_error_1.default(it.opts.uriResolver, it.baseId, ref);
|
||||||
|
}
|
||||||
|
const propSch = (_a = sch === null || sch === void 0 ? void 0 : sch.properties) === null || _a === void 0 ? void 0 : _a[tagName];
|
||||||
|
if (typeof propSch != "object") {
|
||||||
|
throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${tagName}"`);
|
||||||
|
}
|
||||||
|
tagRequired = tagRequired && (topRequired || hasRequired(sch));
|
||||||
|
addMappings(propSch, i);
|
||||||
|
}
|
||||||
|
if (!tagRequired)
|
||||||
|
throw new Error(`discriminator: "${tagName}" must be required`);
|
||||||
|
return oneOfMapping;
|
||||||
|
function hasRequired({ required }) {
|
||||||
|
return Array.isArray(required) && required.includes(tagName);
|
||||||
|
}
|
||||||
|
function addMappings(sch, i) {
|
||||||
|
if (sch.const) {
|
||||||
|
addMapping(sch.const, i);
|
||||||
|
}
|
||||||
|
else if (sch.enum) {
|
||||||
|
for (const tagValue of sch.enum) {
|
||||||
|
addMapping(tagValue, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error(`discriminator: "properties/${tagName}" must have "const" or "enum"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function addMapping(tagValue, i) {
|
||||||
|
if (typeof tagValue != "string" || tagValue in oneOfMapping) {
|
||||||
|
throw new Error(`discriminator: "${tagName}" values must be unique strings`);
|
||||||
|
}
|
||||||
|
oneOfMapping[tagValue] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/vocabularies/discriminator/index.ts"],"names":[],"mappings":";;AAEA,mDAA0D;AAC1D,kDAAgE;AAChE,2CAAmD;AACnD,uDAAqD;AACrD,6CAAuD;AAIvD,MAAM,KAAK,GAA2B;IACpC,OAAO,EAAE,CAAC,EAAC,MAAM,EAAE,EAAC,UAAU,EAAE,OAAO,EAAC,EAAC,EAAE,EAAE,CAC3C,UAAU,KAAK,kBAAU,CAAC,GAAG;QAC3B,CAAC,CAAC,QAAQ,OAAO,kBAAkB;QACnC,CAAC,CAAC,iBAAiB,OAAO,oBAAoB;IAClD,MAAM,EAAE,CAAC,EAAC,MAAM,EAAE,EAAC,UAAU,EAAE,GAAG,EAAE,OAAO,EAAC,EAAC,EAAE,EAAE,CAC/C,IAAA,WAAC,EAAA,WAAW,UAAU,UAAU,OAAO,eAAe,GAAG,GAAG;CAC/D,CAAA;AAED,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,QAAQ;IACpB,KAAK;IACL,IAAI,CAAC,GAAe;QAClB,MAAM,EAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAC,GAAG,GAAG,CAAA;QACjD,MAAM,EAAC,KAAK,EAAC,GAAG,YAAY,CAAA;QAC5B,IAAI,CAAC,EAAE,CAAC,IAAI,CA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8B,OAAO,+BAA+B,CAAC,CAAA;gBACvF,CAAC;YACH,CAAC;YAED,SAAS,UAAU,CAAC,QAAiB,EAAE,CAAS;gBAC9C,IAAI,OAAO,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,YAAY,EAAE,CAAC;oBAC5D,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,iCAAiC,CAAC,CAAA;gBAC9E,CAAC;gBACD,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import type { ErrorObject } from "../../types";
|
||||||
|
export declare enum DiscrError {
|
||||||
|
Tag = "tag",
|
||||||
|
Mapping = "mapping"
|
||||||
|
}
|
||||||
|
export type DiscrErrorObj<E extends DiscrError> = ErrorObject<"discriminator", {
|
||||||
|
error: E;
|
||||||
|
tag: string;
|
||||||
|
tagValue: unknown;
|
||||||
|
}, string>;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.DiscrError = void 0;
|
||||||
|
var DiscrError;
|
||||||
|
(function (DiscrError) {
|
||||||
|
DiscrError["Tag"] = "tag";
|
||||||
|
DiscrError["Mapping"] = "mapping";
|
||||||
|
})(DiscrError || (exports.DiscrError = DiscrError = {}));
|
||||||
|
//# sourceMappingURL=types.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/vocabularies/discriminator/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,iCAAmB,CAAA;AACrB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { Vocabulary } from "../types";
|
||||||
|
declare const draft2020Vocabularies: Vocabulary[];
|
||||||
|
export default draft2020Vocabularies;
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const core_1 = require("./core");
|
||||||
|
const validation_1 = require("./validation");
|
||||||
|
const applicator_1 = require("./applicator");
|
||||||
|
const dynamic_1 = require("./dynamic");
|
||||||
|
const next_1 = require("./next");
|
||||||
|
const unevaluated_1 = require("./unevaluated");
|
||||||
|
const format_1 = require("./format");
|
||||||
|
const metadata_1 = require("./metadata");
|
||||||
|
const draft2020Vocabularies = [
|
||||||
|
dynamic_1.default,
|
||||||
|
core_1.default,
|
||||||
|
validation_1.default,
|
||||||
|
(0, applicator_1.default)(true),
|
||||||
|
format_1.default,
|
||||||
|
metadata_1.metadataVocabulary,
|
||||||
|
metadata_1.contentVocabulary,
|
||||||
|
next_1.default,
|
||||||
|
unevaluated_1.default,
|
||||||
|
];
|
||||||
|
exports.default = draft2020Vocabularies;
|
||||||
|
//# sourceMappingURL=draft2020.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"draft2020.js","sourceRoot":"","sources":["../../lib/vocabularies/draft2020.ts"],"names":[],"mappings":";;AACA,iCAAmC;AACnC,6CAA+C;AAC/C,6CAAkD;AAClD,uCAAyC;AACzC,iCAAmC;AACnC,+CAAiD;AACjD,qCAAuC;AACvC,yCAAgE;AAEhE,MAAM,qBAAqB,GAAiB;IAC1C,iBAAiB;IACjB,cAAc;IACd,oBAAoB;IACpB,IAAA,oBAAuB,EAAC,IAAI,CAAC;IAC7B,gBAAgB;IAChB,6BAAkB;IAClB,4BAAiB;IACjB,cAAc;IACd,qBAAqB;CACtB,CAAA;AAED,kBAAe,qBAAqB,CAAA"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { Vocabulary } from "../types";
|
||||||
|
declare const draft7Vocabularies: Vocabulary[];
|
||||||
|
export default draft7Vocabularies;
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const core_1 = require("./core");
|
||||||
|
const validation_1 = require("./validation");
|
||||||
|
const applicator_1 = require("./applicator");
|
||||||
|
const format_1 = require("./format");
|
||||||
|
const metadata_1 = require("./metadata");
|
||||||
|
const draft7Vocabularies = [
|
||||||
|
core_1.default,
|
||||||
|
validation_1.default,
|
||||||
|
(0, applicator_1.default)(),
|
||||||
|
format_1.default,
|
||||||
|
metadata_1.metadataVocabulary,
|
||||||
|
metadata_1.contentVocabulary,
|
||||||
|
];
|
||||||
|
exports.default = draft7Vocabularies;
|
||||||
|
//# sourceMappingURL=draft7.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"draft7.js","sourceRoot":"","sources":["../../lib/vocabularies/draft7.ts"],"names":[],"mappings":";;AACA,iCAAmC;AACnC,6CAA+C;AAC/C,6CAAkD;AAClD,qCAAuC;AACvC,yCAAgE;AAEhE,MAAM,kBAAkB,GAAiB;IACvC,cAAc;IACd,oBAAoB;IACpB,IAAA,oBAAuB,GAAE;IACzB,gBAAgB;IAChB,6BAAkB;IAClB,4BAAiB;CAClB,CAAA;AAED,kBAAe,kBAAkB,CAAA"}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
import type { KeywordCxt } from "../../compile/validate";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export declare function dynamicAnchor(cxt: KeywordCxt, anchor: string): void;
|
||||||
|
export default def;
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.dynamicAnchor = void 0;
|
||||||
|
const codegen_1 = require("../../compile/codegen");
|
||||||
|
const names_1 = require("../../compile/names");
|
||||||
|
const compile_1 = require("../../compile");
|
||||||
|
const ref_1 = require("../core/ref");
|
||||||
|
const def = {
|
||||||
|
keyword: "$dynamicAnchor",
|
||||||
|
schemaType: "string",
|
||||||
|
code: (cxt) => dynamicAnchor(cxt, cxt.schema),
|
||||||
|
};
|
||||||
|
function dynamicAnchor(cxt, anchor) {
|
||||||
|
const { gen, it } = cxt;
|
||||||
|
it.schemaEnv.root.dynamicAnchors[anchor] = true;
|
||||||
|
const v = (0, codegen_1._) `${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`;
|
||||||
|
const validate = it.errSchemaPath === "#" ? it.validateName : _getValidate(cxt);
|
||||||
|
gen.if((0, codegen_1._) `!${v}`, () => gen.assign(v, validate));
|
||||||
|
}
|
||||||
|
exports.dynamicAnchor = dynamicAnchor;
|
||||||
|
function _getValidate(cxt) {
|
||||||
|
const { schemaEnv, schema, self } = cxt.it;
|
||||||
|
const { root, baseId, localRefs, meta } = schemaEnv.root;
|
||||||
|
const { schemaId } = self.opts;
|
||||||
|
const sch = new compile_1.SchemaEnv({ schema, schemaId, root, baseId, localRefs, meta });
|
||||||
|
compile_1.compileSchema.call(self, sch);
|
||||||
|
return (0, ref_1.getValidate)(cxt, sch);
|
||||||
|
}
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=dynamicAnchor.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"dynamicAnchor.js","sourceRoot":"","sources":["../../../lib/vocabularies/dynamic/dynamicAnchor.ts"],"names":[],"mappings":";;;AAEA,mDAA0D;AAC1D,+CAAmC;AACnC,2CAAsD;AACtD,qCAAuC;AAEvC,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,gBAAgB;IACzB,UAAU,EAAE,QAAQ;IACpB,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;CAC9C,CAAA;AAED,SAAgB,aAAa,CAAC,GAAe,EAAE,MAAc;IAC3D,MAA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../../compile/validate";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export declare function dynamicRef(cxt: KeywordCxt, ref: string): void;
|
||||||
|
export default def;
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.dynamicRef = void 0;
|
||||||
|
const codegen_1 = require("../../compile/codegen");
|
||||||
|
const names_1 = require("../../compile/names");
|
||||||
|
const ref_1 = require("../core/ref");
|
||||||
|
const def = {
|
||||||
|
keyword: "$dynamicRef",
|
||||||
|
schemaType: "string",
|
||||||
|
code: (cxt) => dynamicRef(cxt, cxt.schema),
|
||||||
|
};
|
||||||
|
function dynamicRef(cxt, ref) {
|
||||||
|
const { gen, keyword, it } = cxt;
|
||||||
|
if (ref[0] !== "#")
|
||||||
|
throw new Error(`"${keyword}" only supports hash fragment reference`);
|
||||||
|
const anchor = ref.slice(1);
|
||||||
|
if (it.allErrors) {
|
||||||
|
_dynamicRef();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const valid = gen.let("valid", false);
|
||||||
|
_dynamicRef(valid);
|
||||||
|
cxt.ok(valid);
|
||||||
|
}
|
||||||
|
function _dynamicRef(valid) {
|
||||||
|
// TODO the assumption here is that `recursiveRef: #` always points to the root
|
||||||
|
// of the schema object, which is not correct, because there may be $id that
|
||||||
|
// makes # point to it, and the target schema may not contain dynamic/recursiveAnchor.
|
||||||
|
// Because of that 2 tests in recursiveRef.json fail.
|
||||||
|
// This is a similar problem to #815 (`$id` doesn't alter resolution scope for `{ "$ref": "#" }`).
|
||||||
|
// (This problem is not tested in JSON-Schema-Test-Suite)
|
||||||
|
if (it.schemaEnv.root.dynamicAnchors[anchor]) {
|
||||||
|
const v = gen.let("_v", (0, codegen_1._) `${names_1.default.dynamicAnchors}${(0, codegen_1.getProperty)(anchor)}`);
|
||||||
|
gen.if(v, _callRef(v, valid), _callRef(it.validateName, valid));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_callRef(it.validateName, valid)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _callRef(validate, valid) {
|
||||||
|
return valid
|
||||||
|
? () => gen.block(() => {
|
||||||
|
(0, ref_1.callRef)(cxt, validate);
|
||||||
|
gen.let(valid, true);
|
||||||
|
})
|
||||||
|
: () => (0, ref_1.callRef)(cxt, validate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.dynamicRef = dynamicRef;
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=dynamicRef.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"dynamicRef.js","sourceRoot":"","sources":["../../../lib/vocabularies/dynamic/dynamicRef.ts"],"names":[],"mappings":";;;AAEA,mDAAgE;AAChE,+CAAmC;AACnC,qCAAmC;AAEnC,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,aAAa;IACtB,UAAU,EAAE,QAAQ;IACpB,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;CAC3C,CAAA;AAED,SAAgB,UAAU,CAAC,GAAe,EAAE,GAAW;IACrD,MAAM,EAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAC,GAAG,GAAG,CAAA;IAC9B,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,OAAO,yCAAyC,CAAC,CAAA;IACzF,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3B,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC;QACjB,WAAW,EAAE,CAAA;IACf,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QACrC,WAAW,CAAC,KAAK,CAAC,CAAA;QAClB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;IACf,CAAC;IAED,SAAS,WAAW,CAAC,KAAY;QAC/B,+EAA+E;QAC/E,4EAA4E;QAC5E,sFAAsF;QACtF,qDAAqD;QACrD,kGAAkG;QAClG,yDAAyD;QACzD,IAAI,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAA,WAAC,EAAA,GAAG,eAAC,CAAC,cAAc,GAAG,IAAA,qBAAW,EAAC,MAAM,CAAC,EAAE,CAAC,CAAA;YACrE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAA;QACjE,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,CAAA;QACpC,CAAC;IACH,CAAC;IAED,SAAS,QAAQ,CAAC,QAAc,EAAE,KAAY;QAC5C,OAAO,KAAK;YACV,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE;gBACb,IAAA,aAAO,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;gBACtB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACtB,CAAC,CAAC;YACN,CAAC,CAAC,GAAG,EAAE,CAAC,IAAA,aAAO,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IAClC,CAAC;AACH,CAAC;AApCD,gCAoCC;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { Vocabulary } from "../../types";
|
||||||
|
declare const dynamic: Vocabulary;
|
||||||
|
export default dynamic;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const dynamicAnchor_1 = require("./dynamicAnchor");
|
||||||
|
const dynamicRef_1 = require("./dynamicRef");
|
||||||
|
const recursiveAnchor_1 = require("./recursiveAnchor");
|
||||||
|
const recursiveRef_1 = require("./recursiveRef");
|
||||||
|
const dynamic = [dynamicAnchor_1.default, dynamicRef_1.default, recursiveAnchor_1.default, recursiveRef_1.default];
|
||||||
|
exports.default = dynamic;
|
||||||
|
//# sourceMappingURL=index.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/vocabularies/dynamic/index.ts"],"names":[],"mappings":";;AACA,mDAA2C;AAC3C,6CAAqC;AACrC,uDAA+C;AAC/C,iDAAyC;AAEzC,MAAM,OAAO,GAAe,CAAC,uBAAa,EAAE,oBAAU,EAAE,yBAAe,EAAE,sBAAY,CAAC,CAAA;AAEtF,kBAAe,OAAO,CAAA"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const dynamicAnchor_1 = require("./dynamicAnchor");
|
||||||
|
const util_1 = require("../../compile/util");
|
||||||
|
const def = {
|
||||||
|
keyword: "$recursiveAnchor",
|
||||||
|
schemaType: "boolean",
|
||||||
|
code(cxt) {
|
||||||
|
if (cxt.schema)
|
||||||
|
(0, dynamicAnchor_1.dynamicAnchor)(cxt, "");
|
||||||
|
else
|
||||||
|
(0, util_1.checkStrictMode)(cxt.it, "$recursiveAnchor: false is ignored");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=recursiveAnchor.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"recursiveAnchor.js","sourceRoot":"","sources":["../../../lib/vocabularies/dynamic/recursiveAnchor.ts"],"names":[],"mappings":";;AACA,mDAA6C;AAC7C,6CAAkD;AAElD,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,kBAAkB;IAC3B,UAAU,EAAE,SAAS;IACrB,IAAI,CAAC,GAAG;QACN,IAAI,GAAG,CAAC,MAAM;YAAE,IAAA,6BAAa,EAAC,GAAG,EAAE,EAAE,CAAC,CAAA;;YACjC,IAAA,sBAAe,EAAC,GAAG,CAAC,EAAE,EAAE,oCAAoC,CAAC,CAAA;IACpE,CAAC;CACF,CAAA;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
import type { CodeKeywordDefinition } from "../../types";
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const dynamicRef_1 = require("./dynamicRef");
|
||||||
|
const def = {
|
||||||
|
keyword: "$recursiveRef",
|
||||||
|
schemaType: "string",
|
||||||
|
code: (cxt) => (0, dynamicRef_1.dynamicRef)(cxt, cxt.schema),
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=recursiveRef.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"recursiveRef.js","sourceRoot":"","sources":["../../../lib/vocabularies/dynamic/recursiveRef.ts"],"names":[],"mappings":";;AACA,6CAAuC;AAEvC,MAAM,GAAG,GAA0B;IACjC,OAAO,EAAE,eAAe;IACxB,UAAU,EAAE,QAAQ;IACpB,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,uBAAU,EAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;CAC3C,CAAA;AAED,kBAAe,GAAG,CAAA"}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import type { TypeError } from "../compile/validate/dataType";
|
||||||
|
import type { ApplicatorKeywordError } from "./applicator";
|
||||||
|
import type { ValidationKeywordError } from "./validation";
|
||||||
|
import type { FormatError } from "./format/format";
|
||||||
|
import type { UnevaluatedPropertiesError } from "./unevaluated/unevaluatedProperties";
|
||||||
|
import type { UnevaluatedItemsError } from "./unevaluated/unevaluatedItems";
|
||||||
|
import type { DependentRequiredError } from "./validation/dependentRequired";
|
||||||
|
import type { DiscriminatorError } from "./discriminator";
|
||||||
|
export type DefinedError = TypeError | ApplicatorKeywordError | ValidationKeywordError | FormatError | UnevaluatedPropertiesError | UnevaluatedItemsError | DependentRequiredError | DiscriminatorError;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
//# sourceMappingURL=errors.js.map
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/vocabularies/errors.ts"],"names":[],"mappings":""}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
import type { CodeKeywordDefinition, ErrorObject } from "../../types";
|
||||||
|
export type FormatError = ErrorObject<"format", {
|
||||||
|
format: string;
|
||||||
|
}, string | {
|
||||||
|
$data: string;
|
||||||
|
}>;
|
||||||
|
declare const def: CodeKeywordDefinition;
|
||||||
|
export default def;
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const codegen_1 = require("../../compile/codegen");
|
||||||
|
const error = {
|
||||||
|
message: ({ schemaCode }) => (0, codegen_1.str) `must match format "${schemaCode}"`,
|
||||||
|
params: ({ schemaCode }) => (0, codegen_1._) `{format: ${schemaCode}}`,
|
||||||
|
};
|
||||||
|
const def = {
|
||||||
|
keyword: "format",
|
||||||
|
type: ["number", "string"],
|
||||||
|
schemaType: "string",
|
||||||
|
$data: true,
|
||||||
|
error,
|
||||||
|
code(cxt, ruleType) {
|
||||||
|
const { gen, data, $data, schema, schemaCode, it } = cxt;
|
||||||
|
const { opts, errSchemaPath, schemaEnv, self } = it;
|
||||||
|
if (!opts.validateFormats)
|
||||||
|
return;
|
||||||
|
if ($data)
|
||||||
|
validate$DataFormat();
|
||||||
|
else
|
||||||
|
validateFormat();
|
||||||
|
function validate$DataFormat() {
|
||||||
|
const fmts = gen.scopeValue("formats", {
|
||||||
|
ref: self.formats,
|
||||||
|
code: opts.code.formats,
|
||||||
|
});
|
||||||
|
const fDef = gen.const("fDef", (0, codegen_1._) `${fmts}[${schemaCode}]`);
|
||||||
|
const fType = gen.let("fType");
|
||||||
|
const format = gen.let("format");
|
||||||
|
// TODO simplify
|
||||||
|
gen.if((0, codegen_1._) `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, (0, codegen_1._) `${fDef}.type || "string"`).assign(format, (0, codegen_1._) `${fDef}.validate`), () => gen.assign(fType, (0, codegen_1._) `"string"`).assign(format, fDef));
|
||||||
|
cxt.fail$data((0, codegen_1.or)(unknownFmt(), invalidFmt()));
|
||||||
|
function unknownFmt() {
|
||||||
|
if (opts.strictSchema === false)
|
||||||
|
return codegen_1.nil;
|
||||||
|
return (0, codegen_1._) `${schemaCode} && !${format}`;
|
||||||
|
}
|
||||||
|
function invalidFmt() {
|
||||||
|
const callFormat = schemaEnv.$async
|
||||||
|
? (0, codegen_1._) `(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))`
|
||||||
|
: (0, codegen_1._) `${format}(${data})`;
|
||||||
|
const validData = (0, codegen_1._) `(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
|
||||||
|
return (0, codegen_1._) `${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function validateFormat() {
|
||||||
|
const formatDef = self.formats[schema];
|
||||||
|
if (!formatDef) {
|
||||||
|
unknownFormat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (formatDef === true)
|
||||||
|
return;
|
||||||
|
const [fmtType, format, fmtRef] = getFormat(formatDef);
|
||||||
|
if (fmtType === ruleType)
|
||||||
|
cxt.pass(validCondition());
|
||||||
|
function unknownFormat() {
|
||||||
|
if (opts.strictSchema === false) {
|
||||||
|
self.logger.warn(unknownMsg());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new Error(unknownMsg());
|
||||||
|
function unknownMsg() {
|
||||||
|
return `unknown format "${schema}" ignored in schema at path "${errSchemaPath}"`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getFormat(fmtDef) {
|
||||||
|
const code = fmtDef instanceof RegExp
|
||||||
|
? (0, codegen_1.regexpCode)(fmtDef)
|
||||||
|
: opts.code.formats
|
||||||
|
? (0, codegen_1._) `${opts.code.formats}${(0, codegen_1.getProperty)(schema)}`
|
||||||
|
: undefined;
|
||||||
|
const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
|
||||||
|
if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
|
||||||
|
return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._) `${fmt}.validate`];
|
||||||
|
}
|
||||||
|
return ["string", fmtDef, fmt];
|
||||||
|
}
|
||||||
|
function validCondition() {
|
||||||
|
if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
|
||||||
|
if (!schemaEnv.$async)
|
||||||
|
throw new Error("async format in sync schema");
|
||||||
|
return (0, codegen_1._) `await ${fmtRef}(${data})`;
|
||||||
|
}
|
||||||
|
return typeof format == "function" ? (0, codegen_1._) `${fmtRef}(${data})` : (0, codegen_1._) `${fmtRef}.test(${data})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
exports.default = def;
|
||||||
|
//# sourceMappingURL=format.js.map
|
||||||
Reference in New Issue
Block a user