source: trip-planner-front/node_modules/ajv/dist/vocabularies/applicator/items.js

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

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.validateTuple = void 0;
4const codegen_1 = require("../../compile/codegen");
5const util_1 = require("../../compile/util");
6const code_1 = require("../code");
7const def = {
8 keyword: "items",
9 type: "array",
10 schemaType: ["object", "array", "boolean"],
11 before: "uniqueItems",
12 code(cxt) {
13 const { schema, it } = cxt;
14 if (Array.isArray(schema))
15 return validateTuple(cxt, "additionalItems", schema);
16 it.items = true;
17 if (util_1.alwaysValidSchema(it, schema))
18 return;
19 cxt.ok(code_1.validateArray(cxt));
20 },
21};
22function validateTuple(cxt, extraItems, schArr = cxt.schema) {
23 const { gen, parentSchema, data, keyword, it } = cxt;
24 checkStrictTuple(parentSchema);
25 if (it.opts.unevaluated && schArr.length && it.items !== true) {
26 it.items = util_1.mergeEvaluated.items(gen, schArr.length, it.items);
27 }
28 const valid = gen.name("valid");
29 const len = gen.const("len", codegen_1._ `${data}.length`);
30 schArr.forEach((sch, i) => {
31 if (util_1.alwaysValidSchema(it, sch))
32 return;
33 gen.if(codegen_1._ `${len} > ${i}`, () => cxt.subschema({
34 keyword,
35 schemaProp: i,
36 dataProp: i,
37 }, valid));
38 cxt.ok(valid);
39 });
40 function checkStrictTuple(sch) {
41 const { opts, errSchemaPath } = it;
42 const l = schArr.length;
43 const fullTuple = l === sch.minItems && (l === sch.maxItems || sch[extraItems] === false);
44 if (opts.strictTuples && !fullTuple) {
45 const msg = `"${keyword}" is ${l}-tuple, but minItems or maxItems/${extraItems} are not specified or different at path "${errSchemaPath}"`;
46 util_1.checkStrictMode(it, msg, opts.strictTuples);
47 }
48 }
49}
50exports.validateTuple = validateTuple;
51exports.default = def;
52//# sourceMappingURL=items.js.map
Note: See TracBrowser for help on using the repository browser.