source: trip-planner-front/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.5 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("../../compile/codegen");
4const util_1 = require("../../compile/util");
5const names_1 = require("../../compile/names");
6const error = {
7 message: "must NOT have unevaluated properties",
8 params: ({ params }) => codegen_1._ `{unevaluatedProperty: ${params.unevaluatedProperty}}`,
9};
10const 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(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(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 (!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(codegen_1.not(valid), () => gen.break());
49 }
50 }
51 function unevaluatedDynamic(evaluatedProps, key) {
52 return 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(codegen_1._ `${key} !== ${p}`);
59 }
60 return codegen_1.and(...ps);
61 }
62 },
63};
64exports.default = def;
65//# sourceMappingURL=unevaluatedProperties.js.map
Note: See TracBrowser for help on using the repository browser.