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 error = {
|
---|
6 | message: ({ params: { len } }) => codegen_1.str `must NOT have more than ${len} items`,
|
---|
7 | params: ({ params: { len } }) => codegen_1._ `{limit: ${len}}`,
|
---|
8 | };
|
---|
9 | const def = {
|
---|
10 | keyword: "unevaluatedItems",
|
---|
11 | type: "array",
|
---|
12 | schemaType: ["boolean", "object"],
|
---|
13 | error,
|
---|
14 | code(cxt) {
|
---|
15 | const { gen, schema, data, it } = cxt;
|
---|
16 | const items = it.items || 0;
|
---|
17 | if (items === true)
|
---|
18 | return;
|
---|
19 | const len = gen.const("len", codegen_1._ `${data}.length`);
|
---|
20 | if (schema === false) {
|
---|
21 | cxt.setParams({ len: items });
|
---|
22 | cxt.fail(codegen_1._ `${len} > ${items}`);
|
---|
23 | }
|
---|
24 | else if (typeof schema == "object" && !util_1.alwaysValidSchema(it, schema)) {
|
---|
25 | const valid = gen.var("valid", codegen_1._ `${len} <= ${items}`);
|
---|
26 | gen.if(codegen_1.not(valid), () => validateItems(valid, items));
|
---|
27 | cxt.ok(valid);
|
---|
28 | }
|
---|
29 | it.items = true;
|
---|
30 | function validateItems(valid, from) {
|
---|
31 | gen.forRange("i", from, len, (i) => {
|
---|
32 | cxt.subschema({ keyword: "unevaluatedItems", dataProp: i, dataPropType: util_1.Type.Num }, valid);
|
---|
33 | if (!it.allErrors)
|
---|
34 | gen.if(codegen_1.not(valid), () => gen.break());
|
---|
35 | });
|
---|
36 | }
|
---|
37 | },
|
---|
38 | };
|
---|
39 | exports.default = def;
|
---|
40 | //# sourceMappingURL=unevaluatedItems.js.map |
---|