1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.validateAdditionalItems = void 0;
|
---|
4 | const codegen_1 = require("../../compile/codegen");
|
---|
5 | const util_1 = require("../../compile/util");
|
---|
6 | const error = {
|
---|
7 | message: ({ params: { len } }) => codegen_1.str `must NOT have more than ${len} items`,
|
---|
8 | params: ({ params: { len } }) => codegen_1._ `{limit: ${len}}`,
|
---|
9 | };
|
---|
10 | const 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 | };
|
---|
26 | function 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 | }
|
---|
47 | exports.validateAdditionalItems = validateAdditionalItems;
|
---|
48 | exports.default = def;
|
---|
49 | //# sourceMappingURL=additionalItems.js.map |
---|