[79a0317] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | const codegen_1 = require("../../compile/codegen");
|
---|
| 4 | const util_1 = require("../../compile/util");
|
---|
| 5 | const names_1 = require("../../compile/names");
|
---|
| 6 | const error = {
|
---|
| 7 | message: "must NOT have unevaluated properties",
|
---|
| 8 | params: ({ params }) => (0, codegen_1._) `{unevaluatedProperty: ${params.unevaluatedProperty}}`,
|
---|
| 9 | };
|
---|
| 10 | const def = {
|
---|
| 11 | keyword: "unevaluatedProperties",
|
---|
| 12 | type: "object",
|
---|
| 13 | schemaType: ["boolean", "object"],
|
---|
| 14 | trackErrors: true,
|
---|
| 15 | error,
|
---|
| 16 | code(cxt) {
|
---|
| 17 | const { gen, schema, data, errsCount, it } = cxt;
|
---|
| 18 | /* istanbul ignore if */
|
---|
| 19 | if (!errsCount)
|
---|
| 20 | throw new Error("ajv implementation error");
|
---|
| 21 | const { allErrors, props } = it;
|
---|
| 22 | if (props instanceof codegen_1.Name) {
|
---|
| 23 | gen.if((0, codegen_1._) `${props} !== true`, () => gen.forIn("key", data, (key) => gen.if(unevaluatedDynamic(props, key), () => unevaluatedPropCode(key))));
|
---|
| 24 | }
|
---|
| 25 | else if (props !== true) {
|
---|
| 26 | gen.forIn("key", data, (key) => props === undefined
|
---|
| 27 | ? unevaluatedPropCode(key)
|
---|
| 28 | : gen.if(unevaluatedStatic(props, key), () => unevaluatedPropCode(key)));
|
---|
| 29 | }
|
---|
| 30 | it.props = true;
|
---|
| 31 | cxt.ok((0, codegen_1._) `${errsCount} === ${names_1.default.errors}`);
|
---|
| 32 | function unevaluatedPropCode(key) {
|
---|
| 33 | if (schema === false) {
|
---|
| 34 | cxt.setParams({ unevaluatedProperty: key });
|
---|
| 35 | cxt.error();
|
---|
| 36 | if (!allErrors)
|
---|
| 37 | gen.break();
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 | if (!(0, util_1.alwaysValidSchema)(it, schema)) {
|
---|
| 41 | const valid = gen.name("valid");
|
---|
| 42 | cxt.subschema({
|
---|
| 43 | keyword: "unevaluatedProperties",
|
---|
| 44 | dataProp: key,
|
---|
| 45 | dataPropType: util_1.Type.Str,
|
---|
| 46 | }, valid);
|
---|
| 47 | if (!allErrors)
|
---|
| 48 | gen.if((0, codegen_1.not)(valid), () => gen.break());
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | function unevaluatedDynamic(evaluatedProps, key) {
|
---|
| 52 | return (0, codegen_1._) `!${evaluatedProps} || !${evaluatedProps}[${key}]`;
|
---|
| 53 | }
|
---|
| 54 | function unevaluatedStatic(evaluatedProps, key) {
|
---|
| 55 | const ps = [];
|
---|
| 56 | for (const p in evaluatedProps) {
|
---|
| 57 | if (evaluatedProps[p] === true)
|
---|
| 58 | ps.push((0, codegen_1._) `${key} !== ${p}`);
|
---|
| 59 | }
|
---|
| 60 | return (0, codegen_1.and)(...ps);
|
---|
| 61 | }
|
---|
| 62 | },
|
---|
| 63 | };
|
---|
| 64 | exports.default = def;
|
---|
| 65 | //# sourceMappingURL=unevaluatedProperties.js.map |
---|