UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("ajv/dist/compile/codegen");
4function getDef() {
5 return {
6 keyword: "deepRequired",
7 type: "object",
8 schemaType: "array",
9 code(ctx) {
10 const { schema, data } = ctx;
11 const props = schema.map((jp) => codegen_1._ `(${getData(jp)}) === undefined`);
12 ctx.fail(codegen_1.or(...props));
13 function getData(jsonPointer) {
14 if (jsonPointer === "")
15 throw new Error("empty JSON pointer not allowed");
16 const segments = jsonPointer.split("/");
17 let x = data;
18 const xs = segments.map((s, i) => i ? (x = codegen_1._ `${x}${codegen_1.getProperty(unescapeJPSegment(s))}`) : x);
19 return codegen_1.and(...xs);
20 }
21 },
22 metaSchema: {
23 type: "array",
24 items: { type: "string", format: "json-pointer" },
25 },
26 };
27}
28exports.default = getDef;
29function unescapeJPSegment(s) {
30 return s.replace(/~1/g, "/").replace(/~0/g, "~");
31}
32module.exports = getDef;
33//# sourceMappingURL=deepRequired.js.map
\No newline at end of file