| 4999 | }, |
| 5000 | }; |
| 5001 | function validateTuple(cxt, extraItems, schArr = cxt.schema) { |
| 5002 | const { gen, parentSchema, data, keyword, it } = cxt; |
| 5003 | checkStrictTuple(parentSchema); |
| 5004 | if (it.opts.unevaluated && schArr.length && it.items !== true) { |
| 5005 | it.items = util_1.mergeEvaluated.items(gen, schArr.length, it.items); |
| 5006 | } |
| 5007 | const valid = gen.name("valid"); |
| 5008 | const len = gen.const("len", (0, codegen_1._) `${data}.length`); |
| 5009 | schArr.forEach((sch, i) => { |
| 5010 | if ((0, util_1.alwaysValidSchema)(it, sch)) |
| 5011 | return; |
| 5012 | gen.if((0, codegen_1._) `${len} > ${i}`, () => cxt.subschema({ |
| 5013 | keyword, |
| 5014 | schemaProp: i, |
| 5015 | dataProp: i, |
| 5016 | }, valid)); |
| 5017 | cxt.ok(valid); |
| 5018 | }); |
| 5019 | function checkStrictTuple(sch) { |
| 5020 | const { opts, errSchemaPath } = it; |
| 5021 | const l = schArr.length; |
| 5022 | const fullTuple = l === sch.minItems && (l === sch.maxItems || sch[extraItems] === false); |
| 5023 | if (opts.strictTuples && !fullTuple) { |
| 5024 | const msg = `"${keyword}" is ${l}-tuple, but minItems or maxItems/${extraItems} are not specified or different at path "${errSchemaPath}"`; |
| 5025 | (0, util_1.checkStrictMode)(it, msg, opts.strictTuples); |
| 5026 | } |
| 5027 | } |
| 5028 | } |
| 5029 | exports.validateTuple = validateTuple; |
| 5030 | exports.default = def; |
| 5031 | //# sourceMappingURL=items.js.map |