source: trip-planner-front/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js@ 6a80231

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

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.validateAdditionalItems = void 0;
4const codegen_1 = require("../../compile/codegen");
5const util_1 = require("../../compile/util");
6const error = {
7 message: ({ params: { len } }) => codegen_1.str `must NOT have more than ${len} items`,
8 params: ({ params: { len } }) => codegen_1._ `{limit: ${len}}`,
9};
10const def = {
11 keyword: "additionalItems",
12 type: "array",
13 schemaType: ["boolean", "object"],
14 before: "uniqueItems",
15 error,
16 code(cxt) {
17 const { parentSchema, it } = cxt;
18 const { items } = parentSchema;
19 if (!Array.isArray(items)) {
20 util_1.checkStrictMode(it, '"additionalItems" is ignored when "items" is not an array of schemas');
21 return;
22 }
23 validateAdditionalItems(cxt, items);
24 },
25};
26function validateAdditionalItems(cxt, items) {
27 const { gen, schema, data, keyword, it } = cxt;
28 it.items = true;
29 const len = gen.const("len", codegen_1._ `${data}.length`);
30 if (schema === false) {
31 cxt.setParams({ len: items.length });
32 cxt.pass(codegen_1._ `${len} <= ${items.length}`);
33 }
34 else if (typeof schema == "object" && !util_1.alwaysValidSchema(it, schema)) {
35 const valid = gen.var("valid", codegen_1._ `${len} <= ${items.length}`); // TODO var
36 gen.if(codegen_1.not(valid), () => validateItems(valid));
37 cxt.ok(valid);
38 }
39 function validateItems(valid) {
40 gen.forRange("i", items.length, len, (i) => {
41 cxt.subschema({ keyword, dataProp: i, dataPropType: util_1.Type.Num }, valid);
42 if (!it.allErrors)
43 gen.if(codegen_1.not(valid), () => gen.break());
44 });
45 }
46}
47exports.validateAdditionalItems = validateAdditionalItems;
48exports.default = def;
49//# sourceMappingURL=additionalItems.js.map
Note: See TracBrowser for help on using the repository browser.