LogoLogo

Schema Benchmarks

    • home
      Home

    • download_2
      Download

    • timer
      Initialization
    • check_circle
      Validation
    • output_circle
      Parsing
    • swap_horiz
      Codec
    • schema
      Standard Schema
    • data_object
      JSON Schema
    • format_quote
      String

    • error
      Stack

    • deployed_code
      Libraries

    • article
      Blog
Expand sidebarExpand sidebar
ata-validator/Compiled (minified)Compiled (minified)
github
GitHubGitHub
DiscordDiscord
PreferencesPreferences
schemas/libraries/ata-validator/download_compiled/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), (e = null)), t.exports), s = (e, i, o, s) => { if ((i && typeof i == `object`) || typeof i == `function`) for (var c = r(i), l = 0, u = c.length, d; l < u; l++) ((d = c[l]), !a.call(e, d) && d !== o && t(e, d, { get: ((e) => i[e]).bind(null, d), enumerable: !(s = n(i, d)) || s.enumerable, })); return e; }, c = (n, r, a) => ( (a = n == null ? {} : e(i(n))), s(r || !n || !n.__esModule ? t(a, `default`, { value: n, enumerable: !0 }) : a, n) ), l = o((e, t) => { let n = { Object, Array, Function, Number, String, Date, RegExp, Promise, Map, Set, WeakMap, WeakSet, Buffer: typeof Buffer < `u` ? Buffer : void 0, Uint8Array, ArrayBuffer, }; function r(e) { let t = []; if (!e || typeof e != `object`) return t; if (e.instanceof) { let r = Array.isArray(e.instanceof) ? e.instanceof : [e.instanceof], i = r.map((e) => n[e]).filter(Boolean); i.length > 0 && t.push({ type: `instanceof`, ctors: i, types: r }); } if (e.typeof) { let n = Array.isArray(e.typeof) ? e.typeof : [e.typeof]; t.push({ type: `typeof`, types: n }); } if (e.properties) for (let [n, i] of Object.entries(e.properties)) { let e = r(i); e.length > 0 && t.push({ type: `prop`, key: n, ops: e }); } if (e.items && typeof e.items == `object` && !Array.isArray(e.items)) { let n = r(e.items); n.length > 0 && t.push({ type: `items`, ops: n }); } if (Array.isArray(e.prefixItems)) { let n = e.prefixItems.map(r); n.some((e) => e.length > 0) && t.push({ type: `prefixItems`, tuple: n }); } return t; } function i(e, t, n) { let r = n.join(` | `); return { keyword: e, instancePath: t, schemaPath: ``, params: { expected: r }, message: `expected ` + e + ` ` + r, }; } function a(e, t, n, r) { for (let o = 0; o < t.length; o++) { let s = t[o]; if (s.type === `instanceof`) { let t = !1; for (let n = 0; n < s.ctors.length; n++) if (e instanceof s.ctors[n]) { t = !0; break; } t || r.push(i(`instanceof`, n, s.types)); } else if (s.type === `typeof`) { let t = !1; for (let n = 0; n < s.types.length; n++) if (typeof e === s.types[n]) { t = !0; break; } t || r.push(i(`typeof`, n, s.types)); } else if (s.type === `prop`) { if (e && typeof e == `object`) { let t = e[s.key]; t !== void 0 && a(t, s.ops, n + `/` + s.key, r); } } else if (s.type === `items`) { if (Array.isArray(e)) for (let t = 0; t < e.length; t++) a(e[t], s.ops, n + `/` + t, r); } else if (s.type === `prefixItems` && Array.isArray(e)) { let t = s.tuple.length < e.length ? s.tuple.length : e.length; for (let i = 0; i < t; i++) s.tuple[i].length > 0 && a(e[i], s.tuple[i], n + `/` + i, r); } } } function o(e) { let t = e._schemaObj, n = r(t); e.validate({}); let i = e.validate; return ( n.length === 0 || (e.validate = function (e) { if (typeof e == `object` && e) { let t = []; if ((a(e, n, ``, t), t.length > 0)) return { valid: !1, errors: t }; } return i(e); }), e ); } ((o.CONSTRUCTORS = n), (t.exports = { withKeywords: o, CONSTRUCTORS: n })); }), u = o((e, t) => { t.exports = function () { return null; }; }), d = o((e, t) => { let n = Object.freeze({ ATA1001: { keyword: `type`, category: `type`, headline: `value has wrong type` }, ATA1002: { keyword: `type`, category: `type`, headline: `value is not an object` }, ATA2001: { keyword: `minLength`, category: `constraint`, headline: `string shorter than minLength`, }, ATA2002: { keyword: `maxLength`, category: `constraint`, headline: `string longer than maxLength`, }, ATA2003: { keyword: `minimum`, category: `constraint`, headline: `number below minimum` }, ATA2004: { keyword: `maximum`, category: `constraint`, headline: `number above maximum` }, ATA2005: { keyword: `exclusiveMinimum`, category: `constraint`, headline: `number not above exclusiveMinimum`, }, ATA2006: { keyword: `exclusiveMaximum`, category: `constraint`, headline: `number not below exclusiveMaximum`, }, ATA2007: { keyword: `multipleOf`, category: `constraint`, headline: `number not a multiple of expected divisor`, }, ATA2008: { keyword: `minItems`, category: `constraint`, headline: `array shorter than minItems`, }, ATA2009: { keyword: `maxItems`, category: `constraint`, headline: `array longer than maxItems`, }, ATA2010: { keyword: `minProperties`, category: `constraint`, headline: `object has fewer than minProperties`, }, ATA2011: { keyword: `maxProperties`, category: `constraint`, headline: `object has more than maxProperties`, }, ATA2012: { keyword: `uniqueItems`, category: `constraint`, headline: `array has duplicate items`, }, ATA2013: { keyword: `pattern`, category: `constraint`, headline: `string does not match pattern`, }, ATA3001: { keyword: `format`, format: `email`, category: `format`, headline: `value does not match format "email"`, }, ATA3002: { keyword: `format`, format: `date`, category: `format`, headline: `value does not match format "date"`, }, ATA3003: { keyword: `format`, format: `date-time`, category: `format`, headline: `value does not match format "date-time"`, }, ATA3004: { keyword: `format`, format: `time`, category: `format`, headline: `value does not match format "time"`, }, ATA3005: { keyword: `format`, format: `uri`, category: `format`, headline: `value does not match format "uri"`, }, ATA3006: { keyword: `format`, format: `uri-reference`, category: `format`, headline: `value does not match format "uri-reference"`, }, ATA3007: { keyword: `format`, format: `ipv4`, category: `format`, headline: `value does not match format "ipv4"`, }, ATA3008: { keyword: `format`, format: `ipv6`, category: `format`, headline: `value does not match format "ipv6"`, }, ATA3009: { keyword: `format`, format: `uuid`, category: `format`, headline: `value does not match format "uuid"`, }, ATA3010: { keyword: `format`, format: `hostname`, category: `format`, headline: `value does not match format "hostname"`, }, ATA3099: { keyword: `format`, category: `format`, headline: `value does not match user-defined format`, }, ATA4001: { keyword: `oneOf`, category: `composition`, headline: `value matched 0 of N oneOf variants`, }, ATA4002: { keyword: `oneOf`, category: `composition`, headline: `value matched more than one oneOf variant`, }, ATA4003: { keyword: `anyOf`, category: `composition`, headline: `value matched none of the anyOf variants`, }, ATA4004: { keyword: `allOf`, category: `composition`, headline: `value failed one or more allOf branches`, }, ATA4005: { keyword: `not`, category: `composition`, headline: `value matched a forbidden schema`, }, ATA4006: { keyword: `if`, category: `composition`, headline: `value violated then/else branch`, }, ATA5001: { keyword: `$ref`, category: `ref`, headline: `$ref could not be resolved` }, ATA5002: { keyword: `$ref`, category: `ref`, headline: `recursive $ref cycle detected at validate time`, }, ATA6001: { keyword: `enum`, category: `enum`, headline: `value is not one of the allowed enum values`, }, ATA6002: { keyword: `const`, category: `enum`, headline: `value does not equal const` }, ATA7001: { keyword: `required`, category: `shape`, headline: `object missing required property`, }, ATA7002: { keyword: `additionalProperties`, category: `shape`, headline: `object has property not allowed by schema`, }, ATA7003: { keyword: `unevaluatedProperties`, category: `shape`, headline: `object has unevaluated property`, }, ATA7004: { keyword: `unevaluatedItems`, category: `shape`, headline: `array has unevaluated items`, }, ATA7005: { keyword: `dependentRequired`, category: `shape`, headline: `dependentRequired property missing`, }, ATA7006: { keyword: `propertyNames`, category: `shape`, headline: `property name violates schema`, }, ATA7007: { keyword: `contains`, category: `shape`, headline: `array does not contain a matching item`, }, ATA9000: { keyword: `__abort_early__`, category: `system`, headline: `validation failed (abortEarly)`, }, ATA9001: { keyword: `__parse__`, category: `system`, headline: `input is not valid JSON` }, ATA9002: { keyword: `__compile__`, category: `system`, headline: `schema failed to compile` }, }); function r(e) { return n[e]; } function i() { return Object.keys(n).sort(); } function a(e, t) { if (e === `format` && t) { for (let e of i()) { let r = n[e]; if (r.keyword === `format` && r.format === t) return e; } return `ATA3099`; } for (let t of i()) if (n[t].keyword === e) return t; return null; } t.exports = { CODES: n, get: r, all: i, codeFor: a }; }), f = o((e, t) => { let n = [ [9, 13], [32, 32], [160, 160], ], r = [[48, 57]], i = [ [48, 57], [65, 90], [97, 122], [95, 95], ]; function a(e) { let t = 0, a = e.length, o = () => e[t], s = () => t >= a; function c() { let e = [l()]; for (; !s() && o() === `|`;) (t++, e.push(l())); return e.length === 1 ? e[0] : { t: `alt`, opts: e }; } function l() { let e = []; for (; !s() && o() !== `|` && o() !== `)`;) e.push(u()); return e.length === 0 ? { t: `empty` } : e.length === 1 ? e[0] : { t: `concat`, parts: e }; } function u() { let e = f(); for (; !s();) { let n = o(); if (n === `*`) (t++, (e = { t: `star`, child: e })); else if (n === `+`) (t++, (e = { t: `plus`, child: e })); else if (n === `?`) (t++, (e = { t: `quest`, child: e })); else if (n === `{`) { let n = t, r = d(); if (!r) { t = n; break; } e = { t: `repeat`, child: e, min: r.min, max: r.max }; } else break; !s() && o() === `?` && t++; } return e; } function d() { t++; let e = ``; for (; !s() && /[0-9]/.test(o());) ((e += o()), t++); if (e === ``) return null; let n; if (o() === `}`) return (t++, { min: +e, max: +e }); if (o() === `,`) { t++; let r = ``; for (; !s() && /[0-9]/.test(o());) ((r += o()), t++); return o() === `}` ? (t++, (n = r === `` ? 1 / 0 : +r), { min: +e, max: n }) : null; } return null; } function f() { let n = o(); if (n === `(`) { if ((t++, e[t] === `?`)) if (e[t + 1] === `:`) t += 2; else throw Error(`unsupported group (lookaround/named) in pattern`); let n = c(); if (o() !== `)`) throw Error(`unbalanced ( in pattern`); return (t++, { t: `group`, child: n }); } return n === `[` ? p() : n === `.` ? (t++, { t: `any` }) : n === `^` ? (t++, { t: `bol` }) : n === `$` ? (t++, { t: `eol` }) : n === `\\` ? m(!1) : n === `)` || n === `|` ? { t: `empty` } : (t++, { t: `char`, c: n.charCodeAt(0) }); } function p() { t++; let n = !1; o() === `^` && ((n = !0), t++); let r = []; for (; !s() && o() !== `]`;) { let n; if (o() === `\\`) { let e = m(!0); if (e.t === `classpart`) { for (let t of e.ranges) r.push(t); continue; } n = e.c; } else ((n = o().charCodeAt(0)), t++); if (o() === `-` && e[t + 1] !== `]` && t + 1 < a) { t++; let e; (o() === `\\` ? (e = m(!0).c) : ((e = o().charCodeAt(0)), t++), r.push([n, e])); } else r.push([n, n]); } if (o() !== `]`) throw Error(`unbalanced [ in pattern`); return (t++, { t: `class`, neg: n, ranges: r }); } function m(a) { if ((t++, s())) throw Error(`trailing backslash in pattern`); let c = o(); switch ((t++, c)) { case `d`: return a ? { t: `classpart`, ranges: r } : { t: `class`, neg: !1, ranges: r }; case `w`: return a ? { t: `classpart`, ranges: i } : { t: `class`, neg: !1, ranges: i }; case `s`: return a ? { t: `classpart`, ranges: n } : { t: `class`, neg: !1, ranges: n }; case `D`: if (a) throw Error(`\\D inside a class is not supported`); return { t: `class`, neg: !0, ranges: r }; case `W`: if (a) throw Error(`\\W inside a class is not supported`); return { t: `class`, neg: !0, ranges: i }; case `S`: if (a) throw Error(`\\S inside a class is not supported`); return { t: `class`, neg: !0, ranges: n }; case `n`: return { t: `char`, c: 10 }; case `r`: return { t: `char`, c: 13 }; case `t`: return { t: `char`, c: 9 }; case `f`: return { t: `char`, c: 12 }; case `v`: return { t: `char`, c: 11 }; case `0`: return { t: `char`, c: 0 }; case `x`: { let n = e.slice(t, t + 2); return ((t += 2), { t: `char`, c: parseInt(n, 16) }); } case `u`: { let n = e.slice(t, t + 4); return ((t += 4), { t: `char`, c: parseInt(n, 16) }); } case `b`: if (a) return { t: `char`, c: 8 }; throw Error(`\\b word boundary is not supported`); default: if (/[1-9]/.test(c)) throw Error(`backreferences are not supported in pattern`); return { t: `char`, c: c.charCodeAt(0) }; } } let h = c(); if (!s()) throw Error(`unexpected "` + o() + `" in pattern`); return h; } function o(e) { let t = [], n = (e, n) => { let r = t.length; return (t.push(Object.assign({ op: e }, n)), r); }; function r(e) { switch (e.t) { case `empty`: break; case `char`: n(`char`, { c: e.c }); break; case `any`: n(`any`); break; case `class`: n(`class`, { neg: e.neg, ranges: e.ranges }); break; case `bol`: n(`bol`); break; case `eol`: n(`eol`); break; case `group`: r(e.child); break; case `concat`: for (let t of e.parts) r(t); break; case `alt`: { let i = []; for (let a = 0; a < e.opts.length; a++) if (a < e.opts.length - 1) { let o = n(`split`, { x: 0, y: 0 }); ((t[o].x = t.length), r(e.opts[a]), i.push(n(`jmp`, { x: 0 })), (t[o].y = t.length)); } else r(e.opts[a]); for (let e of i) t[e].x = t.length; break; } case `star`: { let i = n(`split`, { x: 0, y: 0 }); ((t[i].x = t.length), r(e.child), n(`jmp`, { x: i }), (t[i].y = t.length)); break; } case `plus`: { let i = t.length; r(e.child); let a = n(`split`, { x: i, y: 0 }); t[a].y = t.length; break; } case `quest`: { let i = n(`split`, { x: 0, y: 0 }); ((t[i].x = t.length), r(e.child), (t[i].y = t.length)); break; } case `repeat`: for (let t = 0; t < e.min; t++) r(e.child); if (e.max === 1 / 0) (e.min, r({ t: `star`, child: e.child })); else for (let t = 0; t < e.max - e.min; t++) r({ t: `quest`, child: e.child }); break; } } return (r(e), n(`match`), t); } function s(e, t) { let n = !1, r = e.ranges; for (let e = 0; e < r.length; e++) if (t >= r[e][0] && t <= r[e][1]) { n = !0; break; } return e.neg ? !n : n; } function c(e) { let t = e.length, n = new Int32Array(t).fill(-1), r = 0, i = []; function a(t, a, o, s) { for (i.length = 0, i.push(a); i.length;) { let a = i.pop(); if (n[a] === r) continue; n[a] = r; let c = e[a]; switch (c.op) { case `jmp`: i.push(c.x); break; case `split`: (i.push(c.y), i.push(c.x)); break; case `bol`: o === 0 && i.push(a + 1); break; case `eol`: o === s && i.push(a + 1); break; default: t.push(a); } } } return function (t) { let n = t.length, i = [], o = []; (r++, a(i, 0, 0, n)); for (let c = 0; c <= n; c++) { let l = c < n ? t.charCodeAt(c) : -1; (r++, (o.length = 0)); for (let t = 0; t < i.length; t++) { let r = i[t], u = e[r]; if (u.op === `match`) return !0; u.op === `char` ? l === u.c && a(o, r + 1, c + 1, n) : u.op === `any` ? l !== -1 && l !== 10 && a(o, r + 1, c + 1, n) : u.op === `class` && l !== -1 && s(u, l) && a(o, r + 1, c + 1, n); } c < n && a(o, 0, c + 1, n); let u = i; ((i = o), (o = u)); } return !1; }; } function l(e) { return { test: c(o(a(e))), source: e, __ataSafe: !0 }; } function u(e) { try { return (l(e), !0); } catch { return !1; } } t.exports = { compileSafe: l, patternIsSafe: u }; }), p = o((e, t) => { let { codeFor: n } = d(), { compileSafe: r, patternIsSafe: i } = f(); function a(e, t) { return i(t) ? ((e.usesSafeRe = !0), r(t)) : new RegExp(t); } function o(e) { let { keyword: t, format: r, schemaPath: i, sourceMap: a } = e, o = t === `format` && r ? n(`format`, r) : n(t); o ||= `ATA9001`; let s = `https://ata-validator.com/e/` + o, c = ``; if (a && a.file && a.map) { let e = i && i.charAt(0) === `#` ? i.slice(1) : i || ``, t = a.map[e + `#key`]; if (((t ||= a.map[e]), t)) { let e = Array.isArray(t) ? t[0] : t.line, n = Array.isArray(t) ? t[1] : t.col, r = Array.isArray(t) ? t[2] : t.text; c = `,schemaSource:Object.freeze({file:` + JSON.stringify(a.file) + `,line:` + e + `,col:` + n + `,text:` + JSON.stringify(r) + `})`; } } return { codeStr: o, docUrl: s, frame: c }; } function s(e) { let t = e.length; for (let n = 0; n < t; n++) if (e.charCodeAt(n) >= 55296 && e.charCodeAt(n) <= 56319) { let t = 0; for (let n of e) t++; return t; } return t; } let c = { type: (e) => `must be ${e.type}`, required: (e) => `must have required property '${e.missingProperty}'`, additionalProperties: () => `must NOT have additional properties`, enum: () => `must be equal to one of the allowed values`, const: () => `must be equal to constant`, minimum: (e) => `must be >= ${e.limit}`, maximum: (e) => `must be <= ${e.limit}`, exclusiveMinimum: (e) => `must be > ${e.limit}`, exclusiveMaximum: (e) => `must be < ${e.limit}`, minLength: (e) => `must NOT have fewer than ${e.limit} characters`, maxLength: (e) => `must NOT have more than ${e.limit} characters`, pattern: (e) => `must match pattern "${e.pattern}"`, format: (e) => `must match format "${e.format}"`, minItems: (e) => `must NOT have fewer than ${e.limit} items`, maxItems: (e) => `must NOT have more than ${e.limit} items`, uniqueItems: (e) => `must NOT have duplicate items (items ## ${e.j} and ${e.i} are identical)`, minProperties: (e) => `must NOT have fewer than ${e.limit} properties`, maxProperties: (e) => `must NOT have more than ${e.limit} properties`, multipleOf: (e) => `must be multiple of ${e.multipleOf}`, oneOf: () => `must match exactly one schema in oneOf`, anyOf: () => `must match a schema in anyOf`, allOf: () => `must match all schemas in allOf`, not: () => `must NOT be valid`, if: (e) => `must match "${e.failingKeyword}" schema`, }; function l(e, t, n) { if (typeof e == `boolean`) return e ? () => !0 : () => !1; if (typeof e != `object` || !e) return null; if (!t && !C(e, n)) { let t = JSON.stringify(e), n = t.includes(`"$dynamicRef"`) || t.includes(`"$dynamicAnchor"`); if ((!n && !t.includes(`"$anchor"`)) || (!n && S(e))) return null; } let a = t || u(e); if (e.patternProperties || e.dependentSchemas || e.propertyNames) return null; let o = []; if (e.$ref) { let t = h(e.$ref, a, n); if (!t) return null; o.push(t); } if (e.$dynamicRef) { let t = e.$dynamicRef, n = t.startsWith(`#`) ? t : `#` + t; if (a && a[n]) { let e = a[n]; o.push((t) => { let n = e.fn; return !n || n(t); }); } else { let e = t.match(/^#\/(?:\$defs|definitions)\/(.+)$/); if (e && a && a[e[1]]) { let t = a[e[1]]; o.push((e) => { let n = t.fn; return !n || n(e); }); } } } if (e.type) { let t = Array.isArray(e.type) ? e.type : [e.type]; o.push(g(t)); } if (e.enum) { let t = e.enum, n = t.filter((e) => typeof e != `object` || !e), r = t.filter((e) => typeof e == `object` && !!e), i = new Set( n.map((e) => (e === null ? `null` : typeof e == `string` ? `s:` + e : `n:` + e)), ), a = r.map((e) => JSON.stringify(e)); o.push((e) => { let t = e === null ? `null` : typeof e == `string` ? `s:` + e : typeof e == `number` || typeof e == `boolean` ? `n:` + e : null; if (t !== null && i.has(t)) return !0; let r = JSON.stringify(e); for (let e = 0; e < a.length; e++) if (r === a[e]) return !0; for (let t = 0; t < n.length; t++) if (e === n[t]) return !0; return !1; }); } if (e.const !== void 0) { let t = e.const; if (typeof t != `object` || !t) o.push((e) => e === t); else { let e = JSON.stringify(t); o.push((t) => JSON.stringify(t) === e); } } if (e.required && Array.isArray(e.required)) for (let t of e.required) o.push((e) => typeof e == `object` && !!e && t in e); if (e.properties) for (let [t, n] of Object.entries(e.properties)) { let e = l(n, a); if (!e) return null; o.push((n) => typeof n != `object` || !n || !(t in n) || e(n[t])); } if (e.additionalProperties !== void 0 && e.properties) { if (e.additionalProperties === !1) { let t = new Set(Object.keys(e.properties)); o.push((e) => { if (typeof e != `object` || !e || Array.isArray(e)) return !0; let n = Object.keys(e); for (let e = 0; e < n.length; e++) if (!t.has(n[e])) return !1; return !0; }); } else if (typeof e.additionalProperties == `object`) { let t = l(e.additionalProperties, a); if (!t) return null; let n = new Set(Object.keys(e.properties || {})); o.push((e) => { if (typeof e != `object` || !e || Array.isArray(e)) return !0; let r = Object.keys(e); for (let i = 0; i < r.length; i++) if (!n.has(r[i]) && !t(e[r[i]])) return !1; return !0; }); } } if (e.dependentRequired) for (let [t, n] of Object.entries(e.dependentRequired)) o.push((e) => { if (typeof e != `object` || !e || !(t in e)) return !0; for (let t = 0; t < n.length; t++) if (!(n[t] in e)) return !1; return !0; }); if (e.items) { let t = l(e.items, a); if (!t) return null; o.push((e) => { if (!Array.isArray(e)) return !0; for (let n = 0; n < e.length; n++) if (!t(e[n])) return !1; return !0; }); } if (e.prefixItems) { let t = []; for (let n of e.prefixItems) { let e = l(n, a); if (!e) return null; t.push(e); } o.push((e) => { if (!Array.isArray(e)) return !0; for (let n = 0; n < t.length && n < e.length; n++) if (!t[n](e[n])) return !1; return !0; }); } if (e.contains) { let t = l(e.contains, a); if (!t) return null; let n = e.minContains === void 0 ? 1 : e.minContains, r = e.maxContains === void 0 ? 1 / 0 : e.maxContains; o.push((e) => { if (!Array.isArray(e)) return !0; let i = 0; for (let n = 0; n < e.length; n++) t(e[n]) && i++; return i >= n && i <= r; }); } if (e.uniqueItems) { let e = (t) => typeof t != `object` || !t ? typeof t + `:` + t : Array.isArray(t) ? `[` + t.map(e).join(`,`) + `]` : `{` + Object.keys(t) .sort() .map((n) => JSON.stringify(n) + `:` + e(t[n])) .join(`,`) + `}`; o.push((t) => { if (!Array.isArray(t)) return !0; let n = new Set(); for (let r = 0; r < t.length; r++) { let i = e(t[r]); if (n.has(i)) return !1; n.add(i); } return !0; }); } if (e.minimum !== void 0) { let t = e.minimum; o.push((e) => typeof e != `number` || e >= t); } if (e.maximum !== void 0) { let t = e.maximum; o.push((e) => typeof e != `number` || e <= t); } if (e.exclusiveMinimum !== void 0) { let t = e.exclusiveMinimum; o.push((e) => typeof e != `number` || e > t); } if (e.exclusiveMaximum !== void 0) { let t = e.exclusiveMaximum; o.push((e) => typeof e != `number` || e < t); } if (e.multipleOf !== void 0) { let t = e.multipleOf; o.push((e) => typeof e != `number` || e % t === 0); } if (e.minLength !== void 0) { let t = e.minLength, n = t * 2; o.push((e) => typeof e != `string` || e.length >= n || (e.length >= t && s(e) >= t)); } if (e.maxLength !== void 0) { let t = e.maxLength; o.push((e) => typeof e != `string` || e.length <= t || s(e) <= t); } if (e.pattern) try { let t = i(e.pattern) ? r(e.pattern) : new RegExp(e.pattern); o.push((e) => typeof e != `string` || t.test(e)); } catch { return null; } if (e.format) { let t = v[e.format]; t && o.push((e) => typeof e != `string` || t(e)); } if (e.minItems !== void 0) { let t = e.minItems; o.push((e) => !Array.isArray(e) || e.length >= t); } if (e.maxItems !== void 0) { let t = e.maxItems; o.push((e) => !Array.isArray(e) || e.length <= t); } if (e.minProperties !== void 0) { let t = e.minProperties; o.push((e) => typeof e != `object` || !e || Object.keys(e).length >= t); } if (e.maxProperties !== void 0) { let t = e.maxProperties; o.push((e) => typeof e != `object` || !e || Object.keys(e).length <= t); } if (e.allOf) { let t = []; for (let n of e.allOf) { let e = l(n, a); if (!e) return null; t.push(e); } o.push((e) => { for (let n = 0; n < t.length; n++) if (!t[n](e)) return !1; return !0; }); } if (e.anyOf) { let t = []; for (let n of e.anyOf) { let e = l(n, a); if (!e) return null; t.push(e); } o.push((e) => { for (let n = 0; n < t.length; n++) if (t[n](e)) return !0; return !1; }); } if (e.oneOf) { let t = []; for (let n of e.oneOf) { let e = l(n, a); if (!e) return null; t.push(e); } o.push((e) => { let n = 0; for (let r = 0; r < t.length; r++) if ((t[r](e) && n++, n > 1)) return !1; return n === 1; }); } if (e.not) { let t = l(e.not, a); if (!t) return null; o.push((e) => !t(e)); } if (e.if) { let t = l(e.if, a); if (!t) return null; let n = e.then ? l(e.then, a) : null, r = e.else ? l(e.else, a) : null; if ((e.then && !n) || (e.else && !r)) return null; o.push((e) => (t(e) ? !n || n(e) : !r || r(e))); } return o.length === 0 ? () => !0 : o.length === 1 ? o[0] : (e) => { for (let t = 0; t < o.length; t++) if (!o[t](e)) return !1; return !0; }; } function u(e) { let t = {}, n = e.$defs || e.definitions; if (n && typeof n == `object`) for (let [e, r] of Object.entries(n)) { let n; if ( ((t[e] = { get fn() { return (n === void 0 && ((n = null), (n = l(r, t))), n || (() => !0)); }, raw: r, }), r && typeof r == `object`) ) { if (r.$anchor) { let e = r, n; t[`#` + r.$anchor] = { get fn() { return (n === void 0 && ((n = null), (n = l(e, t))), n || (() => !0)); }, raw: e, }; } if (r.$dynamicAnchor) { let e = r, n; t[`#` + r.$dynamicAnchor] = { get fn() { return (n === void 0 && ((n = null), (n = l(e, t))), n || (() => !0)); }, raw: e, }; } } } if (e.$anchor && !t[`#` + e.$anchor]) { let n = e, r; t[`#` + e.$anchor] = { get fn() { return (r === void 0 && ((r = null), (r = l(n, t))), r || (() => !0)); }, raw: n, }; } if (e.$dynamicAnchor && !t[`#` + e.$dynamicAnchor]) { let n = e, r; t[`#` + e.$dynamicAnchor] = { get fn() { return (r === void 0 && ((r = null), (r = l(n, t))), r || (() => !0)); }, raw: n, }; } return t; } function p(e, t) { if (!t || t === `/` || t === `#`) return e; let n = t.startsWith(`#`) ? t.slice(1) : t; if (!n.startsWith(`/`)) return null; let r = n .split(`/`) .slice(1) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), i = e; for (let e of r) { if (typeof i != `object` || !i) return null; if (!(e in i)) { let t = e === `definitions` ? `$defs` : e === `$defs` ? `definitions` : null; if (t !== null && t in i) { i = i[t]; continue; } return null; } i = i[e]; } return i ?? null; } function m(e, t) { if (!t) return null; let n = e.indexOf(`#`), r = n >= 0 ? e.slice(0, n) : e, i = n >= 0 ? e.slice(n) : ``; if (!r) return null; let a = null, o = null; if (t.has(r)) ((a = t.get(r)), (o = r)); else if (!e.includes(`://`)) { for (let [e] of t) if (e.endsWith(`/` + r)) { ((a = t.get(e)), (o = e)); break; } } if (!a) return null; let s = i ? p(a, i) : a; return s == null ? null : { schema: s, fullId: o }; } function h(e, t, n) { if (e === `#`) return () => !0; if (t) { let n = e.match(/^#\/(?:\$defs|definitions)\/(.+)$/); if (n) { let e = t[n[1]]; if (e) return (t) => { let n = e.fn; return !n || n(t); }; } if (e.startsWith(`#`) && !e.startsWith(`#/`)) { let n = t[e]; if (n) return (e) => { let t = n.fn; return !t || t(e); }; } } if (n && n.has(e)) return l(n.get(e), null, n) || (() => !0); if (n && e.includes(`#`)) { let t = m(e, n); if (t) return l(t.schema, null, n) || (() => !0); } if (n && !e.includes(`://`) && !e.startsWith(`#`)) { for (let [t] of n) if (t.endsWith(`/` + e)) return l(n.get(t), null, n) || (() => !0); } return null; } function g(e) { if (e.length === 1) return _[e[0]] || (() => !0); let t = e.map((e) => _[e]).filter(Boolean); return (e) => { for (let n = 0; n < t.length; n++) if (t[n](e)) return !0; return !1; }; } let _ = { string: (e) => typeof e == `string`, number: (e) => typeof e == `number` && isFinite(e), integer: (e) => Number.isInteger(e), boolean: (e) => typeof e == `boolean`, null: (e) => e === null, array: (e) => Array.isArray(e), object: (e) => typeof e == `object` && !!e && !Array.isArray(e), }, v = { email: (e) => { let t = e.indexOf(`@`); return t > 0 && t < e.length - 1 && e.indexOf(`.`, t) > t + 1; }, date: (e) => { if (e.length !== 10 || !/^\d{4}-\d{2}-\d{2}$/.test(e)) return !1; let t = +e.slice(5, 7), n = +e.slice(8, 10); return t >= 1 && t <= 12 && n >= 1 && n <= 31; }, uuid: (e) => e.length === 36 && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e), ipv4: (e) => { let t = e.split(`.`); return ( t.length === 4 && t.every((e) => { let t = +e; return t >= 0 && t <= 255 && String(t) === e; }) ); }, hostname: (e) => e.length > 0 && e.length <= 253 && /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i.test(e), }, y = new Set([ `__proto__`, `constructor`, `toString`, `valueOf`, `hasOwnProperty`, `isPrototypeOf`, `propertyIsEnumerable`, `toLocaleString`, ]); function b(e, t, n) { let r = new Set(); t.$dynamicAnchor && r.add(t.$dynamicAnchor); let i = t.$defs || t.definitions; if (i) for (let e of Object.values(i)) e && typeof e == `object` && e.$dynamicAnchor && r.add(e.$dynamicAnchor); if (n) for (let e of n.values()) e && typeof e == `object` && e.$dynamicAnchor && r.add(e.$dynamicAnchor); let a = [], o = (e) => { if (!(typeof e != `object` || !e)) { if (e.$dynamicRef) { let t = e.$dynamicRef.startsWith(`#`) ? e.$dynamicRef.slice(1) : e.$dynamicRef; a.push(t); } for (let t of Object.values(e)) Array.isArray(t) ? t.forEach(o) : typeof t == `object` && t && o(t); } }; return (o(e), a.every((e) => r.has(e))); } function x(e, t) { if (typeof e != `object` || !e) return !1; if (e.$ref) { let n = /^#\/(?:\$defs|definitions)\/([^/]+)$/.exec(e.$ref); if (n && t.has(n[1])) return !0; } for (let n of Object.values(e)) if (typeof n == `object` && n) { if (Array.isArray(n)) { for (let e of n) if (x(e, t)) return !0; } else if (x(n, t)) return !0; } return !1; } function S(e, t = !0) { if (typeof e != `object` || !e) return !1; if (!t && typeof e.$id == `string` && !e.$id.startsWith(`#`)) return !0; for (let t of Object.values(e)) if (!(typeof t != `object` || !t)) { if (Array.isArray(t)) { for (let e of t) if (S(e, !1)) return !0; } else if (S(t, !1)) return !0; } return !1; } function C(e, t) { if (typeof e == `boolean` || typeof e != `object` || !e) return !0; if ( (e.$dynamicRef && !e.$dynamicRef.startsWith(`#`)) || e.items === !1 || (e.items === !0 && !e.unevaluatedItems) ) return !1; if (e.additionalProperties === !0) return !0; if (e.properties) { for (let n of Object.values(e.properties)) if (n === !1 || (n !== !0 && !C(n, t))) return !1; } if (e.required) { for (let t of e.required) if (y.has(t)) return !1; } if (e.properties) { for (let t of Object.keys(e.properties)) if (y.has(t) || t === `$ref`) return !1; } if (e.pattern && /\\[pP]\{/.test(e.pattern)) return !1; if (e.$ref) { if (e.$ref === `#`) return !0; let n = /^#\/(?:\$defs|definitions)\/[^/]+$/.test(e.$ref), r = !n && t && t.has(e.$ref), i = null; if (!n && !r && t && !e.$ref.includes(`://`) && !e.$ref.startsWith(`#`)) { for (let [n] of t) if (n.endsWith(`/` + e.$ref)) { ((r = !0), (i = t.get(n))); break; } } if (!n && !r && t && e.$ref.includes(`#`) && !e.$ref.startsWith(`#`)) { let n = m(e.$ref, t); n && ((r = !0), (i = n.schema)); } let a = !n && !r && e.$ref.length > 1 && e.$ref.startsWith(`#`) && !e.$ref.startsWith(`#/`); if ( (!n && !r && !a) || (!i && r && (i = t.get(e.$ref)), i && JSON.stringify(i).includes(`"$dynamicRef"`) && !( b(i, e, t) && i.additionalProperties === void 0 && !i.patternProperties && !i.dependentSchemas && !i.propertyNames ) && e.unevaluatedProperties === void 0 && e.unevaluatedItems === void 0) ) return !1; let o = new Set([ `$ref`, `$defs`, `definitions`, `$schema`, `$id`, `$dynamicAnchor`, `$anchor`, ]); if ( Object.keys(e).filter((e) => !o.has(e)).length > 0 && e.unevaluatedProperties === void 0 && e.unevaluatedItems === void 0 ) return !1; } if ( (typeof e.additionalProperties == `object` && e.additionalProperties !== null && (e.allOf || e.oneOf || e.anyOf || e.patternProperties || !C(e.additionalProperties, t))) || (e.additionalProperties === !1 && !e.properties) || e.propertyNames === !1 || (e.unevaluatedProperties !== void 0 && typeof e.unevaluatedProperties == `object` && e.unevaluatedProperties !== null && !C(e.unevaluatedProperties, t)) || (e.unevaluatedItems !== void 0 && (JSON.stringify(e).includes(`"contains"`) || (typeof e.unevaluatedItems == `object` && e.unevaluatedItems !== null && !C(e.unevaluatedItems, t)))) ) return !1; let n = e.$defs || e.definitions; if (n) { let e = new Set(Object.keys(n)); if (Object.values(n).some((t) => typeof t == `object` && !!t && x(t, e))) return !1; for (let [e, r] of Object.entries(n)) if ( /[~/"']/.test(e) || typeof r == `boolean` || (typeof r == `object` && r && ((r.$id && !r.$id.startsWith(`#`)) || r.$ref || !C(r, t))) ) return !1; } let r = [ e.items, e.contains, e.not, e.if, e.then, e.else, ...(e.prefixItems || []), ...(e.allOf || []), ...(e.anyOf || []), ...(e.oneOf || []), ]; typeof e.additionalProperties == `object` && r.push(e.additionalProperties); for (let e of r) if (e != null && (e === !1 || (e !== !0 && !C(e, t)))) return !1; return !0; } function w(e) { if (typeof e != `object` || !e) return !1; if (typeof e.additionalProperties == `object` && e.additionalProperties !== null) return !0; for (let t of [`properties`, `patternProperties`, `$defs`, `definitions`, `dependentSchemas`]) if (e[t] && typeof e[t] == `object`) { for (let n of Object.values(e[t])) if (w(n)) return !0; } for (let t of [`allOf`, `anyOf`, `oneOf`, `prefixItems`]) if (Array.isArray(e[t])) { for (let n of e[t]) if (w(n)) return !0; } for (let t of [`items`, `contains`, `not`, `if`, `then`, `else`, `propertyNames`]) if (typeof e[t] == `object` && e[t] !== null && w(e[t])) return !0; return !1; } function T(e, t, n) { if (typeof e == `boolean`) return e ? () => !0 : () => !1; if (typeof e != `object` || !e || !C(e, t)) return null; let i = e.$defs || e.definitions || null; if (e.patternProperties) { for (let [n, r] of Object.entries(e.patternProperties)) if ( typeof r == `boolean` || /\\[pP]\{/.test(n) || (typeof r == `object` && r && !C(r, t)) ) return null; } if (e.dependentSchemas) { for (let n of Object.values(e.dependentSchemas)) if (typeof n == `boolean` || (typeof n == `object` && n && !C(n, t))) return null; } if (e.propertyNames) { if (typeof e.propertyNames == `boolean`) return null; let t = e.propertyNames, n = [`maxLength`, `minLength`, `pattern`, `const`, `enum`]; if ( Object.keys(t) .filter((e) => e !== `$schema`) .some((e) => !n.includes(e)) ) return null; } let a = {}; if ( (e.$dynamicAnchor && (a[`#` + e.$dynamicAnchor] = e), e.$anchor && (a[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && (a[e.$id] = e), i) ) for (let e of Object.values(i)) e && typeof e == `object` && (e.$dynamicAnchor && (a[`#` + e.$dynamicAnchor] = e), e.$anchor && (a[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && (a[e.$id] = e)); if (t) for (let e of t.values()) e && typeof e == `object` && (e.$dynamicAnchor && !a[`#` + e.$dynamicAnchor] && (a[`#` + e.$dynamicAnchor] = e), e.$anchor && !a[`#` + e.$anchor] && (a[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && !a[e.$id] && (a[e.$id] = e)); let o = { varCounter: 0, helpers: [], helperCode: [], preamble: [], closureVars: [`_cpLen`], closureVals: [s], rootDefs: i, refStack: new Set(), schemaMap: t || null, anchors: a, rootSchema: e, userFormats: n || null, }, c = []; if ((A(e, `d`, c, o), o.deferredChecks)) for (let e of o.deferredChecks) c.push(e); if (c.length === 0) return () => !0; let l = c.join(` `), u = o.closureVars, d = o.closureVals; for (let e of o.helperCode) { let t = e.match(/^const (_re\d+)=__ataSafeRe\((.+)\)$/); if (t) { (u.push(t[1]), d.push(r(JSON.parse(t[2])))); continue; } let n = e.match(/^const (_re\d+)=new RegExp\((.+)\)$/); n && (u.push(n[1]), d.push(new RegExp(JSON.parse(n[2])))); } let f, p; o.usesRecursion ? ((f = `function _validate(d){\n ${l}\n return true\n }\n return _validate(d)`), (p = `function _validate(d){\n ${l}\n return true\n }\n return _validate(d)?R:E(d)`)) : ((f = l + ` return true`), (p = E( l + ` return R`, ))); let m = o.preamble && o.preamble.length ? o.preamble.join(` `) + ` ` : ``; try { let e; e = u.length > 0 ? Function(...u, `${m}return function(d){${f}}`)(...d) : m ? Function(`${m}return function(d){${f}}`)() : Function(`d`, f); try { let t = Function(...u, `R`, `E`, `${m}return function(d){${p}}`); e._hybridFactory = (e, n) => t(...d, e, n); } catch {} let t = o.helperCode.length ? o.helperCode.join(` `) + ` ` : ``; if ( ((e._source = t + f), (e._preambleSource = m), (e._hybridSource = t + p), (e._usesSafeRe = !!o.usesSafeRe), o.userFormats) ) { let t = []; for (let e = 0; e < u.length; e++) u[e].startsWith(`_uf_`) && t.push({ name: u[e], fn: d[e] }); t.length && (e._formatClosures = t); } { let t = []; for (let e = 0; e < u.length; e++) { let n = u[e]; n === `_cpLen` || n.startsWith(`_uf_`) || t.push({ name: n, val: d[e] }); } t.length && (e._closures = t); } return e; } catch { return null; } } function E(e) { let t = ``, n = 0; for (; n < e.length;) if (e.startsWith(`function`, n) && (n === 0 || /[^a-zA-Z_$]/.test(e[n - 1]))) { let r = n + 8; for (; r < e.length && e[r] !== `{`;) r++; ((t += e.slice(n, r + 1)), (n = r + 1)); let i = 1; for (; n < e.length && i > 0;) (e[n] === `{` ? i++ : e[n] === `}` && i--, i > 0 ? (t += e[n]) : (t += `}`), n++); } else e.startsWith(`return false`, n) ? ((t += `return E(d)`), (n += 12)) : e.startsWith(`return true`, n) && (n + 11 >= e.length || !/[a-zA-Z_$]/.test(e[n + 11])) ? ((t += `return R`), (n += 11)) : ((t += e[n]), n++); return t; } function D(e) { if ( typeof e != `object` || !e || e.$ref || e.allOf || e.anyOf || e.oneOf || e.if || e.properties || e.items || e.prefixItems ) return !1; let t = e.type ? (Array.isArray(e.type) ? e.type : [e.type]) : null; if (!t || t.length !== 1) return !1; let n = t[0], r = 1; return ( n === `string` ? (e.minLength !== void 0 && r++, e.maxLength !== void 0 && r++, e.pattern && r++, e.format && r++) : (n === `integer` || n === `number`) && (e.minimum !== void 0 && r++, e.maximum !== void 0 && r++, e.exclusiveMinimum !== void 0 && r++, e.exclusiveMaximum !== void 0 && r++, e.multipleOf !== void 0 && r++), r >= 2 ); } function O(e, t, n) { if ( typeof e != `object` || !e || e.$ref || e.allOf || e.anyOf || e.oneOf || e.if || e.properties || e.items || e.prefixItems || e.patternProperties || e.enum || e.const !== void 0 || e.not || e.dependentRequired || e.dependentSchemas ) return null; let r = e.type ? (Array.isArray(e.type) ? e.type : [e.type]) : null; if (!r || r.length !== 1) return null; let i = r[0], a = /^_[a-zA-Z]\w*$/.test(t), o = (e) => a ? `if(${e.join(`||`).replace(/\b_v\b/g, t)})return false` : `{const _v=${t};if(${e.join(`||`)})return false}`; if (i === `string`) { if (e.pattern || e.format) return null; if (e.minLength !== void 0 && e.maxLength !== void 0) { let n = e.minLength, r = e.maxLength, i = a ? t : `_v`; return `{${a ? `` : `const _v=${t};`}if(typeof ${i}!=='string')return false;const _lv=${i}.length;if(_lv<${n}||_lv>${r * 2})return false;if(_lv<${n * 2}||_lv>${r}){const _cp=_cpLen(${i});if(_cp<${n}||_cp>${r})return false}}`; } let n = [`typeof _v!=='string'`]; if (e.minLength !== void 0 && e.minLength > 0) { let t = e.minLength; (n.push(`_v.length<${t}`), t > 1 && n.push(`_v.length<${t * 2}&&_cpLen(_v)<${t}`)); } if (e.maxLength !== void 0) { let t = e.maxLength; t === 0 ? n.push(`_v.length>0`) : (n.push(`_v.length>${t * 2}`), n.push(`_v.length>${t}&&_cpLen(_v)>${t}`)); } return n.length < 2 ? null : o(n); } if (i === `integer`) { let t = [`!Number.isInteger(_v)`]; return ( e.minimum !== void 0 && t.push(`_v<${e.minimum}`), e.maximum !== void 0 && t.push(`_v>${e.maximum}`), e.exclusiveMinimum !== void 0 && t.push(`_v<=${e.exclusiveMinimum}`), e.exclusiveMaximum !== void 0 && t.push(`_v>=${e.exclusiveMaximum}`), e.multipleOf !== void 0 && t.push(`_v%${e.multipleOf}!==0`), t.length < 2 ? null : o(t) ); } if (i === `number`) { let t = [`typeof _v!=='number'||!isFinite(_v)`]; return ( e.minimum !== void 0 && t.push(`_v<${e.minimum}`), e.maximum !== void 0 && t.push(`_v>${e.maximum}`), e.exclusiveMinimum !== void 0 && t.push(`_v<=${e.exclusiveMinimum}`), e.exclusiveMaximum !== void 0 && t.push(`_v>=${e.exclusiveMaximum}`), e.multipleOf !== void 0 && t.push(`_v%${e.multipleOf}!==0`), t.length < 2 ? null : o(t) ); } return null; } function k(e, t, n, r) { n === `d` ? ((e.deferredChecks ||= []), e.deferredChecks.push(r)) : t.push(r); } function A(e, t, n, r, o) { if (typeof e != `object` || !e) return; r.regExpMap ||= new Map(); let s = e.$ref && (e.unevaluatedProperties !== void 0 || e.unevaluatedItems !== void 0); if (e.$ref) { if ( e.$ref === `#` && ((r.usesRecursion = !0), n.push(`if(!_validate(${t}))return false`), !s) ) return; let i = e.$ref !== `#` && e.$ref.match(/^#\/(?:\$defs|definitions)\/(.+)$/); if (i && r.rootDefs && r.rootDefs[i[1]]) { if (r.refStack.has(e.$ref)) { if (!s) return; } else if ( (r.refStack.add(e.$ref), A(r.rootDefs[i[1]], t, n, r, o), r.refStack.delete(e.$ref), !s) ) return; } else if (e.$ref !== `#` && !i && e.$ref.startsWith(`#`) && !e.$ref.startsWith(`#/`)) { let i = r.rootDefs && r.rootDefs[e.$ref], a = i && i.raw ? i.raw : r.anchors && r.anchors[e.$ref]; if (a) { if (r.refStack.has(e.$ref)) { if (!s) return; } else if ((r.refStack.add(e.$ref), A(a, t, n, r, o), r.refStack.delete(e.$ref), !s)) return; } } else if (e.$ref !== `#` && r.schemaMap) { let i = r.schemaMap.get(e.$ref); if (!i && !e.$ref.includes(`://`) && !e.$ref.startsWith(`#`)) { for (let [t, n] of r.schemaMap) if (t.endsWith(`/` + e.$ref)) { i = n; break; } } if (!i && e.$ref.includes(`#`) && !e.$ref.startsWith(`#`)) { let t = m(e.$ref, r.schemaMap); t && (i = t.schema); } if (i) { if (r.refStack.has(e.$ref)) { if (!s) return; } else if ((r.refStack.add(e.$ref), A(i, t, n, r, o), r.refStack.delete(e.$ref), !s)) return; } else if (!s) return; } else if (!s) return; } if (e.$dynamicRef) { let i = e.$dynamicRef.startsWith(`#`) ? e.$dynamicRef : `#` + e.$dynamicRef; if (r.anchors && r.anchors[i]) { let e = r.anchors[i]; if (e === r.rootSchema) ((r.usesRecursion = !0), n.push(`if(!_validate(${t}))return false`)); else { let a = `$dynamicRef:` + i; r.refStack.has(a) || (r.refStack.add(a), A(e, t, n, r, o), r.refStack.delete(a)); } } } let c = e.type ? (Array.isArray(e.type) ? e.type : [e.type]) : null, l = o; if (c) { if (!o) if (c.length === 1) switch (c[0]) { case `object`: n.push(`if(typeof ${t}!=='object'||${t}===null||Array.isArray(${t}))return false`); break; case `array`: n.push(`if(!Array.isArray(${t}))return false`); break; case `string`: n.push(`if(typeof ${t}!=='string')return false`); break; case `number`: n.push(`if(typeof ${t}!=='number'||!isFinite(${t}))return false`); break; case `integer`: n.push(`if(!Number.isInteger(${t}))return false`); break; case `boolean`: n.push(`if(typeof ${t}!=='boolean')return false`); break; case `null`: n.push(`if(${t}!==null)return false`); break; } else { let e = c.map((e) => { switch (e) { case `object`: return `(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`; case `array`: return `Array.isArray(${t})`; case `string`: return `typeof ${t}==='string'`; case `number`: return `(typeof ${t}==='number'&&isFinite(${t}))`; case `integer`: return `Number.isInteger(${t})`; case `boolean`: return `typeof ${t}==='boolean'`; case `null`: return `${t}===null`; default: return `true`; } }); n.push(`if(!(${e.join(`||`)}))return false`); } c.length === 1 && (l = c[0]); } let u = l === `object`, d = l === `array`, f = l === `string`, p = l === `number` || l === `integer`, h = u ? `` : `typeof ${t}==='object'&&${t}!==null&&`; if ((u || `${t}${t}`, e.enum)) { let r = e.enum, i = r.filter((e) => typeof e != `object` || !e), a = r.filter((e) => typeof e == `object` && !!e), o = [ i.map((e) => `${t}===${JSON.stringify(e)}`).join(`||`), a.map((e) => `JSON.stringify(${t})===${JSON.stringify(JSON.stringify(e))}`).join(`||`), ] .filter(Boolean) .join(`||`); n.push(`if(!(${o || `false`}))return false`); } if (e.const !== void 0) { let r = e.const; typeof r != `object` || !r ? n.push(`if(${t}!==${JSON.stringify(r)})return false`) : n.push(`if(JSON.stringify(${t})!==${JSON.stringify(JSON.stringify(r))})return false`); } let g = new Set(e.required || []), _ = {}; if (e.required && e.properties && u) { let r = []; for (let n of e.required) { _[n] = `${t}[${JSON.stringify(n)}]`; let i = e.properties[n]; (i && (i.type || i.enum || i.const !== void 0)) || r.push(`${t}[${JSON.stringify(n)}]===undefined`); } r.length > 0 && n.push(`if(${r.join(`||`)})return false`); } else if (e.required && e.required.length > 0) if (u) { let r = e.required.map((e) => `${t}[${JSON.stringify(e)}]===undefined`); n.push(`if(${r.join(`||`)})return false`); } else for (let r of e.required) n.push( `if(typeof ${t}!=='object'||${t}===null||!(${JSON.stringify(r)} in ${t}))return false`, ); if (e.unevaluatedProperties === !1 && e.properties && e.required && u) { let i = W(e, r.schemaMap, r.rootDefs); if (!i.dynamic && !i.allProps) { let a = i.props, o = a.length; e.required.length >= o && a.every((t) => e.required.includes(t)) && o > 0 && (o <= 15 ? n.push(`var _n=0;for(var _k in ${t})_n++;if(_n!==${o})return false`) : n.push(`if(Object.keys(${t}).length!==${o})return false`), (r._earlyKeyCount = !0)); } } if ( (e.minimum !== void 0 && n.push( p ? `if(${t}<${e.minimum})return false` : `if(typeof ${t}==='number'&&${t}<${e.minimum})return false`, ), e.maximum !== void 0 && n.push( p ? `if(${t}>${e.maximum})return false` : `if(typeof ${t}==='number'&&${t}>${e.maximum})return false`, ), e.exclusiveMinimum !== void 0 && n.push( p ? `if(${t}<=${e.exclusiveMinimum})return false` : `if(typeof ${t}==='number'&&${t}<=${e.exclusiveMinimum})return false`, ), e.exclusiveMaximum !== void 0 && n.push( p ? `if(${t}>=${e.exclusiveMaximum})return false` : `if(typeof ${t}==='number'&&${t}>=${e.exclusiveMaximum})return false`, ), e.multipleOf !== void 0 && n.push( p ? `if(${t}%${e.multipleOf}!==0)return false` : `if(typeof ${t}==='number'&&${t}%${e.multipleOf}!==0)return false`, ), e.minLength !== void 0 && e.maxLength !== void 0) ) { let i = e.minLength, a = e.maxLength, o = `_l${r.varCounter++}`, s = `{const ${o}=${t}.length;if(${o}<${i}||${o}>${a * 2})return false;if(${o}<${i * 2}||${o}>${a}){const _cp=_cpLen(${t});if(_cp<${i}||_cp>${a})return false}}`; n.push(f ? s : `if(typeof ${t}==='string')${s}`); } else { if (e.minLength !== void 0 && e.minLength > 0) { let r = e.minLength, i = r === 1 ? `if(${t}.length<1)return false` : `if(${t}.length<${r})return false;if(${t}.length<${r * 2}&&_cpLen(${t})<${r})return false`; n.push(f ? i : `if(typeof ${t}==='string'){${i}}`); } if (e.maxLength !== void 0) { let r = e.maxLength, i = r === 0 ? `if(${t}.length>0)return false` : `if(${t}.length>${r * 2})return false;if(${t}.length>${r}&&_cpLen(${t})>${r})return false`; n.push(f ? i : `if(typeof ${t}==='string'){${i}}`); } } if ( (e.minItems !== void 0 && n.push( d ? `if(${t}.length<${e.minItems})return false` : `if(Array.isArray(${t})&&${t}.length<${e.minItems})return false`, ), e.maxItems !== void 0 && n.push( d ? `if(${t}.length>${e.maxItems})return false` : `if(Array.isArray(${t})&&${t}.length>${e.maxItems})return false`, ), e.minProperties !== void 0 && n.push(`if(${h}Object.keys(${t}).length<${e.minProperties})return false`), e.maxProperties !== void 0 && n.push(`if(${h}Object.keys(${t}).length>${e.maxProperties})return false`), e.pattern) ) { let a = P(e.pattern, t); if (a) n.push(f ? `if(!(${a}))return false` : `if(typeof ${t}==='string'&&!(${a}))return false`); else { let a = JSON.stringify(e.pattern); if (!r.regExpMap.has(a)) { let t = r.varCounter++; (r.regExpMap.set(a, t), i(e.pattern) ? (r.helperCode.push(`const _re${t}=__ataSafeRe(${a})`), (r.usesSafeRe = !0)) : r.helperCode.push(`const _re${t}=new RegExp(${a})`)); } let o = r.regExpMap.get(a); n.push( f ? `if(!_re${o}.test(${t}))return false` : `if(typeof ${t}==='string'&&!_re${o}.test(${t}))return false`, ); } } if (e.format) { let i = j[e.format]; if (i) n.push(i(t, f)); else if (r.userFormats && typeof r.userFormats[e.format] == `function`) { let i = `_uf_${e.format.replace(/[^a-zA-Z0-9_]/g, `_`)}`; r.closureVars.includes(i) || (r.closureVars.push(i), r.closureVals.push(r.userFormats[e.format])); let a = f ? `` : `typeof ${t}==='string'&&`; n.push(`if(${a}!${i}(${t}))return false`); } } if (e.uniqueItems) { let i = r.varCounter++, a = e.items && typeof e.items == `object` && e.items.type, o = a === `string` || a === `number` || a === `integer`, s = e.maxItems, c = o && s && s <= 16 ? `for(let _i=1;_i<${t}.length;_i++){for(let _k=0;_k<_i;_k++){if(${t}[_i]===${t}[_k])return false}}` : o ? `const _s${i}=new Set();for(let _i=0;_i<${t}.length;_i++){if(_s${i}.has(${t}[_i]))return false;_s${i}.add(${t}[_i])}` : `const _cn${i}=function(x){if(x===null||typeof x!=='object')return typeof x+':'+x;if(Array.isArray(x))return'['+x.map(_cn${i}).join(',')+']';return'{'+Object.keys(x).sort().map(function(k){return JSON.stringify(k)+':'+_cn${i}(x[k])}).join(',')+'}'};const _s${i}=new Set();for(let _i=0;_i<${t}.length;_i++){const _k=_cn${i}(${t}[_i]);if(_s${i}.has(_k))return false;_s${i}.add(_k)}`; n.push(d ? `{${c}}` : `if(Array.isArray(${t})){${c}}`); } if (e.additionalProperties === !1 && e.properties && !e.patternProperties) { let i = Object.keys(e.properties).length, a = e.required && e.required.length === i ? i <= 15 ? `var _n=0;for(var _k in ${t})_n++;if(_n!==${i})return false` : `if(Object.keys(${t}).length!==${i})return false` : `for(var _k in ${t})if(${Object.keys(e.properties) .map((e) => `_k!==${JSON.stringify(e)}`) .join(`&&`)})return false`; k(r, n, t, u ? a : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${a}}`); } if ( typeof e.additionalProperties == `object` && e.additionalProperties !== null && !e.patternProperties ) { let i = e.properties ? Object.keys(e.properties) : [], a = i.length === 0 ? null : i.map((e) => `_k===${JSON.stringify(e)}`).join(`||`), o = []; if ((A(e.additionalProperties, `_av`, o, r), o.length > 0)) { let e = o.join(`;`), i = a ? `for(var _k in ${t}){if(${a})continue;const _av=${t}[_k];${e}}` : `for(var _k in ${t}){const _av=${t}[_k];${e}}`; k(r, n, t, u ? i : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${i}}`); } } if (e.dependentRequired) for (let [r, i] of Object.entries(e.dependentRequired)) { let e = i.map((e) => `!('${M(e)}' in ${t})`).join(`||`); n.push(`if(${h}'${M(r)}' in ${t}&&(${e}))return false`); } if (e.patternProperties) { let i = Object.entries(e.patternProperties), o = e.propertyNames && typeof e.propertyNames == `object` ? e.propertyNames : null, s = r.varCounter++, c = `_ppk${s}`, l = []; for (let [e] of i) { let t = L(e, c); if (t) l.push({ check: t }); else { let t = r.varCounter++; (r.closureVars.push(`_re${t}`), r.closureVals.push(a(r, e)), l.push({ check: `_re${t}.test(${c})` })); } } for (let e = 0; e < i.length; e++) { let [, t] = i[e], n = []; A(t, `_ppv`, n, r); let a = n.length === 0 ? `return true` : `${n.join(`;`)};return true`, o = `_ppf${s}_${e}`; (r.closureVars.push(o), r.closureVals.push(Function(`_ppv`, a))); } let d = u ? `` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`; if (e.additionalProperties === !1 && e.properties) { ((r._ppHandledAdditional = !0), (r._ppHandledPropertyNames = !!o)); let u = Object.keys(e.properties); if ((n.push(`${d}{for(const ${c} in ${t}){`), o)) { if ( (o.minLength !== void 0 && n.push(`if(${c}.length<${o.minLength})return false`), o.maxLength !== void 0 && n.push(`if(${c}.length>${o.maxLength})return false`), o.pattern) ) { let e = L(o.pattern, c); if (e) n.push(`if(!(${e}))return false`); else { let e = r.varCounter++; (r.closureVars.push(`_re${e}`), r.closureVals.push(a(r, o.pattern)), n.push(`if(!_re${e}.test(${c}))return false`)); } } if ( (o.const !== void 0 && n.push(`if(${c}!==${JSON.stringify(o.const)})return false`), o.enum) ) { let e = r.varCounter++; (r.closureVars.push(`_es${e}`), r.closureVals.push(new Set(o.enum)), n.push(`if(!_es${e}.has(${c}))return false`)); } } let f = u.map((e) => `case ${JSON.stringify(e)}:`).join(``); n.push(`switch(${c}){${f}break;default:`); let p = []; for (let e = 0; e < i.length; e++) p.push( `if(${l[e].check}){if(!_ppf${s}_${e}(${t}[${c}]))return false}else{return false}`, ); (p.length > 0 ? n.push(p.join(``)) : n.push(`return false`), n.push(`}`), n.push(`}}`)); } else { if (((r._ppHandledPropertyNames = !!o), n.push(`${d}{for(const ${c} in ${t}){`), o)) { if ( (o.minLength !== void 0 && n.push(`if(${c}.length<${o.minLength})return false`), o.maxLength !== void 0 && n.push(`if(${c}.length>${o.maxLength})return false`), o.pattern) ) { let e = L(o.pattern, c); if (e) n.push(`if(!(${e}))return false`); else { let e = r.varCounter++; (r.closureVars.push(`_re${e}`), r.closureVals.push(a(r, o.pattern)), n.push(`if(!_re${e}.test(${c}))return false`)); } } if ( (o.const !== void 0 && n.push(`if(${c}!==${JSON.stringify(o.const)})return false`), o.enum) ) { let e = r.varCounter++; (r.closureVars.push(`_es${e}`), r.closureVals.push(new Set(o.enum)), n.push(`if(!_es${e}.has(${c}))return false`)); } } for (let e = 0; e < i.length; e++) n.push(`if(${l[e].check}&&!_ppf${s}_${e}(${t}[${c}]))return false`); n.push(`}}`); } } if (e.dependentSchemas) for (let [i, a] of Object.entries(e.dependentSchemas)) { let e = u ? `` : `typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&`; (n.push(`if(${e}${JSON.stringify(i)} in ${t}){`), A(a, t, n, r, l), n.push(`}`)); } if (e.propertyNames && typeof e.propertyNames == `object` && !r._ppHandledPropertyNames) { let i = e.propertyNames, o = r.varCounter++, s = u ? `` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`; if ( (n.push(`${s}{for(const _k${o} in ${t}){`), i.minLength !== void 0 && n.push(`if(_k${o}.length<${i.minLength})return false`), i.maxLength !== void 0 && n.push(`if(_k${o}.length>${i.maxLength})return false`), i.pattern) ) { let e = L(i.pattern, `_k${o}`); if (e) n.push(`if(!(${e}))return false`); else { let e = r.varCounter++; (r.closureVars.push(`_re${e}`), r.closureVals.push(a(r, i.pattern)), n.push(`if(!_re${e}.test(_k${o}))return false`)); } } if ( (i.const !== void 0 && n.push(`if(_k${o}!==${JSON.stringify(i.const)})return false`), i.enum) ) { let e = r.varCounter++; (r.closureVars.push(`_es${e}`), r.closureVals.push(new Set(i.enum)), n.push(`if(!_es${e}.has(_k${o}))return false`)); } n.push(`}}`); } if (e.properties) for (let [i, a] of Object.entries(e.properties)) if (g.has(i) && u) { let e = _[i] || `${t}[${JSON.stringify(i)}]`, o = O(a, e, r); if (o) n.push(o); else if (D(a)) { let t = `_r${r.varCounter++}`; (n.push(`{const ${t}=${e}`), A(a, t, n, r), n.push(`}`)); } else A(a, e, n, r); } else if (u) { let e = `_o${r.varCounter++}`; n.push(`{const ${e}=${t}[${JSON.stringify(i)}];if(${e}!==undefined){`); let o = O(a, e, r); (o ? n.push(o) : A(a, e, n, r), n.push(`}}`)); } else (n.push(`if(typeof ${t}==='object'&&${t}!==null&&${JSON.stringify(i)} in ${t}){`), A(a, `${t}[${JSON.stringify(i)}]`, n, r), n.push(`}`)); if (e.items) { let i = `_j${r.varCounter}`, a = `_e${r.varCounter}`; (r.varCounter++, n.push( d ? `for(let ${i}=0;${i}<${t}.length;${i}++){const ${a}=${t}[${i}]` : `if(Array.isArray(${t})){for(let ${i}=0;${i}<${t}.length;${i}++){const ${a}=${t}[${i}]`, ), A(e.items, a, n, r), n.push(d ? `}` : `}}`)); } if (e.prefixItems) { let i = r.varCounter++; for (let a = 0; a < e.prefixItems.length; a++) { let o = `_p${i}_${a}`; (n.push( d ? `if(${t}.length>${a}){const ${o}=${t}[${a}]` : `if(Array.isArray(${t})&&${t}.length>${a}){const ${o}=${t}[${a}]`, ), A(e.prefixItems[a], o, n, r), n.push(`}`)); } } if (e.contains) { let i = r.varCounter++, a = e.minContains === void 0 ? 1 : e.minContains, o = e.maxContains === void 0 ? 1 / 0 : e.maxContains, s = []; A(e.contains, `_cv`, s, r); let c = s.length === 0 ? `return true` : `${s.join(`;`)};return true`, l = d ? `` : `if(!Array.isArray(${t})){}else `; (n.push(`${l}{const _cf${i}=function(_cv){${c}};let _cc${i}=0`), n.push( `for(let _ci${i}=0;_ci${i}<${t}.length;_ci${i}++){if(_cf${i}(${t}[_ci${i}]))_cc${i}++}`, ), o === 1 / 0 ? n.push(`if(_cc${i}<${a})return false}`) : n.push(`if(_cc${i}<${a}||_cc${i}>${o})return false}`)); } if (e.allOf) for (let i of e.allOf) A(i, t, n, r, l); if (e.anyOf && e.unevaluatedProperties === void 0) { let i = r.varCounter++, a = [], o = !!r.preamble; for (let t = 0; t < e.anyOf.length; t++) { let n = []; A(e.anyOf[t], `_av`, n, r); let i = n.length === 0 ? `return true` : `${n.join(`;`)};return true`; (/\b_validate\b/.test(i) && (o = !1), a.push(i)); } if (o) { let e = a .map((e, t) => { let n = `_af${i}_b${t}`; return (r.preamble.push(`function ${n}(_av){${e}}`), n); }) .map((e) => `${e}(${t})`) .join(`||`); n.push(`if(!(${e}))return false`); } else { let e = a.map((e) => `function(_av){${e}}`); n.push( `{const _af${i}=[${e.join(`,`)}];let _am${i}=false;for(let _ai=0;_ai<_af${i}.length;_ai++){if(_af${i}[_ai](${t})){_am${i}=true;break}}if(!_am${i})return false}`, ); } } if (e.oneOf) { let i = r.varCounter++, a = [], o = !!r.preamble; for (let t = 0; t < e.oneOf.length; t++) { let n = []; A(e.oneOf[t], `_ov`, n, r); let i = n.length === 0 ? `return true` : `${n.join(`;`)};return true`; (/\b_validate\b/.test(i) && (o = !1), a.push(i)); } if (o) { let e = a .map((e, t) => { let n = `_of${i}_b${t}`; return (r.preamble.push(`function ${n}(_ov){${e}}`), n); }) .map((e) => `if(${e}(${t})){_oc${i}++;if(_oc${i}>1)return false}`) .join(`;`); n.push(`{let _oc${i}=0;${e};if(_oc${i}!==1)return false}`); } else { let e = a.map((e) => `function(_ov){${e}}`); n.push( `{const _of${i}=[${e.join(`,`)}];let _oc${i}=0;for(let _oi=0;_oi<_of${i}.length;_oi++){if(_of${i}[_oi](${t}))_oc${i}++;if(_oc${i}>1)return false}if(_oc${i}!==1)return false}`, ); } } if (e.not) { let i = []; if ((A(e.not, `_nv`, i, r), i.length === 0)) n.push(`return false`); else { let e = r.varCounter++; n.push( `{const _nf${e}=(function(_nv){${i.join(`;`)};return true});if(_nf${e}(${t}))return false}`, ); } } if (e.if) { let i = []; A(e.if, `_iv`, i, r); let a = r.varCounter++, o = i.length === 0 ? `function(_iv){return true}` : `function(_iv){${i.join(`;`)};return true}`, s = `null`, c = `null`; if (e.then) { let t = []; (A(e.then, `_tv`, t, r), (s = t.length === 0 ? `function(_tv){return true}` : `function(_tv){${t.join(`;`)};return true}`)); } if (e.else) { let t = []; (A(e.else, `_ev`, t, r), (c = t.length === 0 ? `function(_ev){return true}` : `function(_ev){${t.join(`;`)};return true}`)); } (n.push(`{const _if${a}=${o};const _th${a}=${s};const _el${a}=${c}`), n.push( `if(_if${a}(${t})){if(_th${a}&&!_th${a}(${t}))return false}else{if(_el${a}&&!_el${a}(${t}))return false}}`, )); } if (e.unevaluatedProperties !== void 0) { let i = W(e, r.schemaMap, r.rootDefs); if (!(i.allProps || e.unevaluatedProperties === !0)) if (i.dynamic) { let i = { props: [], items: null, allProps: !1, allItems: !1, dynamic: !1 }; if (e.properties) for (let t of Object.keys(e.properties)) i.props.includes(t) || i.props.push(t); if (e.allOf) for (let t of e.allOf) { let e = W(t, r.schemaMap, r.rootDefs); if (!e.dynamic && e.props) for (let t of e.props) i.props.includes(t) || i.props.push(t); } let o = i.props, s = e.anyOf ? `anyOf` : e.oneOf ? `oneOf` : null; if (e.unevaluatedProperties === !1) if (e.if && (e.then || e.else) && !s && !e.patternProperties && !e.dependentSchemas) { let i = []; A(e.if, `_iv2`, i, r); let a = r.varCounter++, s = i.length === 0 ? `function(_iv2){return true}` : `function(_iv2){${i.join(`;`)};return true}`, c = []; e.if && e.if.properties && c.push(...Object.keys(e.if.properties)); let l = e.then ? W(e.then, r.schemaMap, r.rootDefs) : { props: [] }, d = e.else ? W(e.else, r.schemaMap, r.rootDefs) : { props: [] }, f = [...new Set([...o, ...c, ...(l.props || [])])], p = [...new Set([...o, ...(d.props || [])])], m = R(f, t), h = R(p, t), g = u ? `` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`; n.push(`${g}{const _uif${a}=${s};if(_uif${a}(${t})){${m}}else{${h}}}`); } else if (s) { let i = e[s], a = []; for (let e of i) { let t = W(e, r.schemaMap, r.rootDefs); a.push(t.props || []); } let c = [...new Set(a.flat())].filter((e) => !o.includes(e)); if (c.length > 0 && c.length <= 32) { let e = `_ev${r.varCounter++}`, l = new Map(); c.forEach((e, t) => l.set(e, t)); let d = a.map((e) => { let t = 0; for (let n of e) l.has(n) && (t |= 1 << l.get(n)); return t; }), f = r.varCounter++; n.push(`{let ${e}=0`); let p = []; for (let e = 0; e < i.length; e++) { let t = []; A(i[e], `_bv`, t, r); let a = `_bf${f}_${e}`; p.push(a); let o = t.length === 0 ? `function(_bv){return true}` : `function(_bv){${t.join(`;`)};return true}`; n.push(`const ${a}=${o}`); } if (s === `oneOf`) { n.push(`let _oc${f}=0`); for (let r = 0; r < i.length; r++) n.push(`if(${p[r]}(${t})){_oc${f}++;${e}=${d[r]};if(_oc${f}>1)return false}`); n.push(`if(_oc${f}!==1)return false`); } else { n.push(`let _am${f}=false`); for (let r = 0; r < i.length; r++) n.push(`if(${p[r]}(${t})){_am${f}=true;${e}|=${d[r]}}`); n.push(`if(!_am${f})return false`); } let m = o.length > 0 ? o.map((e) => `_k===${JSON.stringify(e)}`).join(`||`) : ``, h = new Map(); for (let e of c) { let t = e.charCodeAt(0); (h.has(t) || h.set(t, []), h.get(t).push(e)); } let g = ``; for (let [t, n] of h) { let r = n .map((t) => `_k===${JSON.stringify(t)}&&(${e}&${1 << l.get(t)})`) .join(`||`); g += `case ${t}:if(${r})continue;break;`; } let _ = `switch(_k.charCodeAt(0)){${g}default:break}`, v = m ? `for(var _k in ${t}){if(${m})continue;${_}return false}` : `for(var _k in ${t}){${_}return false}`; k( r, n, t, u ? v + `}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${v}}}`, ); } else { let e = `_ev${r.varCounter++}`, c = []; for (let e = 0; e < i.length; e++) { let t = []; (A(i[e], `_bv`, t, r), c.push( t.length === 0 ? `function(_bv){return true}` : `function(_bv){${t.join(`;`)};return true}`, )); } let l = r.varCounter++; (r.closureVars.push(`_bk${l}`), r.closureVals.push(a), n.push(`{const ${e}={}`)); for (let t of o) n.push(`${e}[${JSON.stringify(t)}]=1`); (n.push(`const _bf${l}=[${c.join(`,`)}]`), s === `oneOf` ? n.push( `let _oc${l}=0;for(let _bi=0;_bi<_bf${l}.length;_bi++){if(_bf${l}[_bi](${t})){_oc${l}++;for(const _p of _bk${l}[_bi])${e}[_p]=1;if(_oc${l}>1)return false}}if(_oc${l}!==1)return false`, ) : n.push( `let _am${l}=false;for(let _bi=0;_bi<_bf${l}.length;_bi++){if(_bf${l}[_bi](${t})){_am${l}=true;for(const _p of _bk${l}[_bi])${e}[_p]=1}}if(!_am${l})return false`, )); let d = `for(var _k in ${t}){if(!${e}[_k])return false}`; k( r, n, t, u ? d + `}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${d}}}`, ); } } else if (e.dependentSchemas) { let i = `_ev${r.varCounter++}`; n.push(`{const ${i}={}`); for (let e of o) n.push(`${i}[${JSON.stringify(e)}]=1`); for (let [a, o] of Object.entries(e.dependentSchemas)) { let e = W(o, r.schemaMap, r.rootDefs); e.props && e.props.length > 0 && n.push( `if(${JSON.stringify(a)} in ${t}){${e.props.map((e) => `${i}[${JSON.stringify(e)}]=1`).join(`;`)}}`, ); } let a = `for(var _k in ${t}){if(!${i}[_k])return false}`; k( r, n, t, u ? a + `}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${a}}}`, ); } else { let i = []; if ((e.patternProperties && i.push(...Object.keys(e.patternProperties)), e.allOf)) for (let t of e.allOf) t && t.patternProperties && i.push(...Object.keys(t.patternProperties)); if ( (e.if && !e.then && !e.else && e.if.patternProperties && i.push(...Object.keys(e.if.patternProperties)), i.length > 0) ) { let s = `_ev${r.varCounter++}`; n.push(`{const ${s}={}`); for (let e of o) n.push(`${s}[${JSON.stringify(e)}]=1`); let c = []; for (let e of i) { let t = r.varCounter++; (r.closureVars.push(`_ure${t}`), r.closureVals.push(a(r, e)), c.push(`_ure${t}`)); } if (e.if && !e.then && !e.else) { let i = []; A(e.if, `_iv2`, i, r); let o = r.varCounter++, c = i.length === 0 ? `function(_iv2){return true}` : `function(_iv2){${i.join(`;`)};return true}`, l = e.if.patternProperties ? Object.keys(e.if.patternProperties) : [], d = []; for (let e of l) { let t = r.varCounter++; (r.closureVars.push(`_ure${t}`), r.closureVals.push(a(r, e)), d.push(`_ure${t}`)); } let f = []; if (e.patternProperties) for (let t of Object.keys(e.patternProperties)) { let e = r.varCounter++; (r.closureVars.push(`_ure${e}`), r.closureVals.push(a(r, t)), f.push(`_ure${e}`)); } let p = f.map((e) => `if(${e}.test(_k))continue;`).join(``), m = `const _uif${o}=${c};if(_uif${o}(${t})){for(var _k in ${t}){if(${s}[_k])continue;${p}${d.map((e) => `if(${e}.test(_k))continue;`).join(``)}return false}}else{for(var _k in ${t}){if(${s}[_k])continue;${p}return false}}`; k( r, n, t, u ? m + `}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${m}}}`, ); } else { let e = `for(var _k in ${t}){if(${s}[_k])continue;${c.map((e) => `if(${e}.test(_k)){${s}[_k]=1;continue}`).join(``)}return false}`; k( r, n, t, u ? e + `}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${e}}}`, ); } } } else if (typeof e.unevaluatedProperties == `object`) { let i = r.varCounter++, a = `_ev${i}`, c = `_uk${i}`; n.push(`{const ${a}={}`); for (let e of o) n.push(`${a}[${JSON.stringify(e)}]=1`); if (s) { let i = e[s], o = []; for (let e of i) { let t = W(e, r.schemaMap, r.rootDefs); o.push(t.props || []); } let c = []; for (let e = 0; e < i.length; e++) { let t = []; (A(i[e], `_bv`, t, r), c.push( t.length === 0 ? `function(_bv){return true}` : `function(_bv){${t.join(`;`)};return true}`, )); } let l = r.varCounter++; (r.closureVars.push(`_bk${l}`), r.closureVals.push(o), n.push(`const _bf${l}=[${c.join(`,`)}]`), s === `oneOf` ? n.push( `for(let _bi=0;_bi<_bf${l}.length;_bi++){if(_bf${l}[_bi](${t})){for(const _p of _bk${l}[_bi])${a}[_p]=1;break}}`, ) : n.push( `for(let _bi=0;_bi<_bf${l}.length;_bi++){if(_bf${l}[_bi](${t})){for(const _p of _bk${l}[_bi])${a}[_p]=1}}`, )); } let l = []; if ((A(e.unevaluatedProperties, `${t}[${c}]`, l, r), l.length > 0)) { let e = `for(var ${c} in ${t}){if(${a}[${c}])continue;${l.join(`;`)}}`; k( r, n, t, u ? e + `}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${e}}}`, ); } else n.push(`}`); } } else { let a = i.props, o = a.length; if (e.unevaluatedProperties === !1) { let i = e.required && e.required.length >= o && a.every((t) => e.required.includes(t)), s; i && o > 0 ? r._earlyKeyCount || ((s = o <= 15 ? `var _n=0;for(var _k in ${t})_n++;if(_n!==${o})return false` : `if(Object.keys(${t}).length!==${o})return false`), k( r, n, t, u ? s : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${s}}`, )) : o > 0 ? ((s = R(a, t)), k( r, n, t, u ? s : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${s}}`, )) : ((s = `for(var _k in ${t})return false`), k( r, n, t, u ? s : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${s}}`, )); } else if (typeof e.unevaluatedProperties == `object`) { let i = `_uk${r.varCounter++}`, o = []; if ((A(e.unevaluatedProperties, `${t}[${i}]`, o, r), o.length > 0)) { let e = o.join(`;`), s = a.map((e) => `${i}===${JSON.stringify(e)}`).join(`||`), c = `for(var ${i} in ${t}){${a.length > 0 ? `if(${s})continue;` : ``}${e}}`; k( r, n, t, u ? c : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${c}}`, ); } } } } if (e.unevaluatedItems !== void 0) { let i = W(e, r.schemaMap, r.rootDefs), a = e.anyOf ? `anyOf` : e.oneOf ? `oneOf` : null, o = i.allItems && i.dynamic && a && e[a].some( (e) => e && typeof e == `object` && ((e.items && typeof e.items == `object`) || e.items === !0), ); if (!(e.unevaluatedItems === !0 || (i.allItems && !o))) { if (i.dynamic) { let a = 0; if ( (e.prefixItems && (a = Math.max(a, e.prefixItems.length)), e.items && typeof e.items == `object` && (a = 1 / 0), e.allOf) ) for (let t of e.allOf) { let e = W(t, r.schemaMap, r.rootDefs); (e.items !== null && (a = Math.max(a, e.items)), e.allItems && (a = 1 / 0)); } a === 1 / 0 && (a = 0); let o = e.anyOf ? `anyOf` : e.oneOf ? `oneOf` : null; if (o && (e.unevaluatedItems === !1 || typeof e.unevaluatedItems == `object`)) { let i = e[o], s = [], c = []; for (let e of i) { let t = W(e, r.schemaMap, r.rootDefs); (s.push(t.items || 0), c.push(t.allItems)); } let l = []; for (let e = 0; e < i.length; e++) { let t = []; (A(i[e], `_bv`, t, r), l.push( t.length === 0 ? `function(_bv){return true}` : `function(_bv){${t.join(`;`)};return true}`, )); } let u = r.varCounter++, f = `_eidx${r.varCounter++}`; (n.push(`{let ${f}=${a}`), n.push(`const _bf${u}=[${l.join(`,`)}]`)); let p = s .map((e, n) => (c[n] ? `_bi===${n}?${t}.length` : `_bi===${n}?${Math.max(e, a)}`)) .join(`:`) + `:${a}`; if ( (o === `oneOf` ? n.push( `for(let _bi=0;_bi<_bf${u}.length;_bi++){if(_bf${u}[_bi](${t})){${f}=${p};break}}`, ) : n.push( `for(let _bi=0;_bi<_bf${u}.length;_bi++){if(_bf${u}[_bi](${t})){const _m=${p};if(_m>${f})${f}=_m}}`, ), e.unevaluatedItems === !1) ) { let e = `if(${t}.length>${f})return false`; k(r, n, t, d ? e + `}` : `if(Array.isArray(${t})){${e}}}`); } else { let i = r.varCounter++, a = `_ue${i}`, o = `_ui${i}`, s = []; if ((A(e.unevaluatedItems, a, s, r), s.length > 0)) { let e = `for(let ${o}=${f};${o}<${t}.length;${o}++){const ${a}=${t}[${o}];${s.join(`;`)}}`; k(r, n, t, d ? e + `}` : `if(Array.isArray(${t})){${e}}}`); } else n.push(`}`); } } else if ( e.if && (e.unevaluatedItems === !1 || typeof e.unevaluatedItems == `object`) ) { let i = W(e.if, r.schemaMap, r.rootDefs), o = e.then ? W(e.then, r.schemaMap, r.rootDefs) : { items: null }, s = e.else ? W(e.else, r.schemaMap, r.rootDefs) : { items: null }, c = i.items || 0, l = Math.max(a, c, o.items || 0), u = Math.max(a, s.items || 0), f = []; A(e.if, `_iv3`, f, r); let p = r.varCounter++, m = f.length === 0 ? `function(_iv3){return true}` : `function(_iv3){${f.join(`;`)};return true}`; if (e.unevaluatedItems === !1) { let e = d ? `` : `if(Array.isArray(${t}))`; n.push( `${e}{const _uif${p}=${m};if(_uif${p}(${t})){if(${t}.length>${l})return false}else{if(${t}.length>${u})return false}}`, ); } } else if ( (e.contains || (e.allOf && e.allOf.some((e) => e && e.contains))) && (e.unevaluatedItems === !1 || typeof e.unevaluatedItems == `object`) ) { let i = []; if ((e.contains && i.push(e.contains), e.allOf)) for (let t of e.allOf) t && t.contains && i.push(t.contains); let o = r.varCounter++, s = `_cev${o}`, c = []; for (let e of i) { let t = []; (A(e, `_cv`, t, r), c.push( t.length === 0 ? `function(_cv){return true}` : `function(_cv){${t.join(`;`)};return true}`, )); } let l = `_cfn${o}`; if ( (n.push(`{const ${l}=[${c.join(`,`)}]`), n.push(`const ${s}=[]`), a > 0 && n.push(`for(let _i=0;_i<${Math.min(a, 1e3)};_i++)${s}[_i]=true`), n.push( `if(Array.isArray(${t})){for(let _ci=0;_ci<${t}.length;_ci++){for(let _cj=0;_cj<${l}.length;_cj++){if(${l}[_cj](${t}[_ci])){${s}[_ci]=true;break}}}}`, ), e.unevaluatedItems === !1) ) k( r, n, t, `if(Array.isArray(${t})){for(let _ci=0;_ci<${t}.length;_ci++){if(!${s}[_ci])return false}}}`, ); else { let i = `_ue${r.varCounter++}`, a = []; (A(e.unevaluatedItems, i, a, r), a.length > 0 ? k( r, n, t, `if(Array.isArray(${t})){for(let _ci=0;_ci<${t}.length;_ci++){if(!${s}[_ci]){const ${i}=${t}[_ci];${a.join(`;`)}}}}}`, ) : n.push(`}`)); } } else if (e.unevaluatedItems === !1) { let e = `if(${t}.length>${i.items || 0})return false`; k(r, n, t, d ? e : `if(Array.isArray(${t})){${e}}`); } } else if (e.unevaluatedItems === !1) { let e = `if(${t}.length>${i.items || 0})return false`; k(r, n, t, d ? e : `if(Array.isArray(${t})){${e}}`); } else if (typeof e.unevaluatedItems == `object`) { let a = i.items || 0, o = r.varCounter++, s = `_ue${o}`, c = `_ui${o}`, l = []; if ((A(e.unevaluatedItems, s, l, r), l.length > 0)) { let e = `for(let ${c}=${a};${c}<${t}.length;${c}++){const ${s}=${t}[${c}];${l.join(`;`)}}`; k(r, n, t, d ? e : `if(Array.isArray(${t})){${e}}`); } } } } } let j = { email: (e, t) => ( t || `${e}`, t ? `{const _at=${e}.indexOf('@');if(_at<=0||_at>=${e}.length-1||${e}.indexOf('.',_at)<=_at+1)return false}` : `if(typeof ${e}==='string'){const _at=${e}.indexOf('@');if(_at<=0||_at>=${e}.length-1||${e}.indexOf('.',_at)<=_at+1)return false}` ), date: (e, t) => t ? `{if(${e}.length!==10||!/^\\d{4}-\\d{2}-\\d{2}$/.test(${e}))return false;const _dm=+${e}.slice(5,7),_dd=+${e}.slice(8,10);if(_dm<1||_dm>12||_dd<1||_dd>31)return false}` : `if(typeof ${e}==='string'){if(${e}.length!==10||!/^\\d{4}-\\d{2}-\\d{2}$/.test(${e}))return false;const _dm=+${e}.slice(5,7),_dd=+${e}.slice(8,10);if(_dm<1||_dm>12||_dd<1||_dd>31)return false}`, uuid: (e, t) => t ? `if(${e}.length!==36||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(${e}))return false` : `if(typeof ${e}==='string'&&(${e}.length!==36||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(${e})))return false`, "date-time": (e, t) => t ? `if(!/^\\d{4}-\\d{2}-\\d{2}[Tt]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([Zz]|[+-]\\d{2}:\\d{2})$/.test(${e})||isNaN(Date.parse(${e})))return false` : `if(typeof ${e}==='string'&&(!/^\\d{4}-\\d{2}-\\d{2}[Tt]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([Zz]|[+-]\\d{2}:\\d{2})$/.test(${e})||isNaN(Date.parse(${e}))))return false`, time: (e, t) => t ? `if(!/^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?$/.test(${e}))return false` : `if(typeof ${e}==='string'&&!/^([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?$/.test(${e}))return false`, duration: (e, t) => t ? `if(!/^P(?:\\d+Y)?(?:\\d+M)?(?:\\d+W)?(?:\\d+D)?(?:T(?:\\d+H)?(?:\\d+M)?(?:\\d+(?:\\.\\d+)?S)?)?$/.test(${e})||${e}==='P'||${e}.endsWith('T'))return false` : `if(typeof ${e}==='string'&&(!/^P(?:\\d+Y)?(?:\\d+M)?(?:\\d+W)?(?:\\d+D)?(?:T(?:\\d+H)?(?:\\d+M)?(?:\\d+(?:\\.\\d+)?S)?)?$/.test(${e})||${e}==='P'||${e}.endsWith('T')))return false`, uri: (e, t) => t ? `if(!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(${e})||/[\\s\\u0000-\\u001f\\u007f]/.test(${e}))return false` : `if(typeof ${e}==='string'&&(!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(${e})||/[\\s\\u0000-\\u001f\\u007f]/.test(${e})))return false`, "uri-reference": (e, t) => t ? `if(/[\\s\\u0000-\\u001f\\u007f]/.test(${e}))return false` : `if(typeof ${e}==='string'&&/[\\s\\u0000-\\u001f\\u007f]/.test(${e}))return false`, ipv4: (e, t) => t ? `{const _p=${e}.split('.');if(_p.length!==4||!_p.every(function(n){var x=+n;return x>=0&&x<=255&&String(x)===n}))return false}` : `if(typeof ${e}==='string'){const _p=${e}.split('.');if(_p.length!==4||!_p.every(function(n){var x=+n;return x>=0&&x<=255&&String(x)===n}))return false}`, ipv6: (e, t) => t ? `{const _s=${e};if(_s===''||!/^[0-9a-fA-F:]+$/.test(_s)||_s.split(':').length<3||_s.split(':').length>8)return false}` : `if(typeof ${e}==='string'){const _s=${e};if(_s===''||!/^[0-9a-fA-F:]+$/.test(_s)||_s.split(':').length<3||_s.split(':').length>8)return false}`, hostname: (e, t) => t ? `if(!/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(${e}))return false` : `if(typeof ${e}==='string'&&!/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(${e}))return false`, }; function M(e) { return JSON.stringify(e).slice(1, -1); } function N(e, t) { return e ? e.startsWith(`'`) && !e.includes(`+`) ? `'${e.slice(1, -1)}/${t}'` : `${e}+'/${t}'` : `'/${t}'`; } function P(e, t) { let n = e.match(/^\^(\[[\w\-]+\])\{(\d+)\}\$$/); if (n) { let e = parseInt(n[2]); if (e <= 16) { let r = []; for (let i = 0; i < e; i++) { let e = F(n[1], `${t}.charCodeAt(${i})`); if (!e) return null; r.push(e); } return `${t}.length===${e}&&${r.join(`&&`)}`; } let r = F(n[1], `${t}.charCodeAt(_pi)`); return r ? `${t}.length===${e}&&(()=>{for(let _pi=0;_pi<${e};_pi++){if(!(${r}))return false}return true})()` : null; } if (((n = e.match(/^\^(\[[\w\-]+\])\+\$$/)), n)) { let e = F(n[1], `${t}.charCodeAt(_pi)`); return e ? `${t}.length>0&&(()=>{for(let _pi=0;_pi<${t}.length;_pi++){if(!(${e}))return false}return true})()` : null; } if (((n = e.match(/^\^(\[[\w\-]+\])\{(\d+),(\d+)\}\$$/)), n)) { let e = F(n[1], `${t}.charCodeAt(_pi)`); return e ? `${t}.length>=${parseInt(n[2])}&&${t}.length<=${parseInt(n[3])}&&(()=>{for(let _pi=0;_pi<${t}.length;_pi++){if(!(${e}))return false}return true})()` : null; } return null; } function F(e, t) { let n = e.slice(1, -1), r = [], i = 0; for (; i < n.length;) i + 2 < n.length && n[i + 1] === `-` ? (r.push([n.charCodeAt(i), n.charCodeAt(i + 2)]), (i += 3)) : (r.push([n.charCodeAt(i), n.charCodeAt(i)]), i++); return r.length === 0 ? null : r.map(([e, n]) => (e === n ? `${t}===${e}` : `(${t}>=${e}&&${t}<=${n})`)).join(`||`); } function I(e, t) { return e ? `${e}+'/'+${t}` : `'/'+${t}`; } function L(e, t) { let n = e.match(/^\^([a-zA-Z0-9_\-./]+)$/); if (!n) return null; let r = n[1]; return r.length === 0 || r.length > 8 ? null : r.length === 1 ? `${t}.charCodeAt(0)===${r.charCodeAt(0)}` : r.length === 2 ? `${t}.charCodeAt(0)===${r.charCodeAt(0)}&&${t}.charCodeAt(1)===${r.charCodeAt(1)}` : `${t}.startsWith(${JSON.stringify(r)})`; } function R(e, t) { if (e.length === 0) return `for(var _k in ${t})return false`; if (e.length <= 3) return `for(var _k in ${t})if(${e.map((e) => `_k!==${JSON.stringify(e)}`).join(`&&`)})return false`; let n = new Map(); for (let t of e) { let e = t.charCodeAt(0); (n.has(e) || n.set(e, []), n.get(e).push(t)); } let r = ``; for (let [e, t] of n) { let n = t.map((e) => `_k===${JSON.stringify(e)}`).join(`||`); r += `case ${e}:if(${n})continue;break;`; } return `for(var _k in ${t}){switch(_k.charCodeAt(0)){${r}default:break}return false}`; } function z(e, t, n, i) { if (typeof e == `object` && e) { let t = JSON.stringify(e); if ( t.includes(`unevaluatedProperties`) || t.includes(`unevaluatedItems`) || t.includes(`"$ref":"#"`) ) return null; } if (typeof e == `boolean`) return e ? () => ({ valid: !0, errors: [] }) : () => ({ valid: !1, errors: [ { keyword: `false schema`, instancePath: ``, schemaPath: `#`, params: {}, message: `boolean schema is false`, }, ], }); if (typeof e != `object` || !e || !C(e, t)) return null; if (e.patternProperties) { for (let [n, r] of Object.entries(e.patternProperties)) if ( typeof r == `boolean` || /\\[pP]\{/.test(n) || (typeof r == `object` && r && !C(r, t)) ) return null; } if (e.dependentSchemas) { for (let n of Object.values(e.dependentSchemas)) if (typeof n == `boolean` || (typeof n == `object` && n && !C(n, t))) return null; } if (e.propertyNames) { if (typeof e.propertyNames == `boolean`) return null; let t = e.propertyNames, n = [`maxLength`, `minLength`, `pattern`, `const`, `enum`]; if ( Object.keys(t) .filter((e) => e !== `$schema`) .some((e) => !n.includes(e)) ) return null; } let a = e.$defs || e.definitions || null, o = {}; if ( (e.$dynamicAnchor && (o[`#` + e.$dynamicAnchor] = e), e.$anchor && (o[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && (o[e.$id] = e), a) ) for (let e of Object.values(a)) e && typeof e == `object` && (e.$dynamicAnchor && (o[`#` + e.$dynamicAnchor] = e), e.$anchor && (o[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && (o[e.$id] = e)); if (t) for (let e of t.values()) e && typeof e == `object` && (e.$dynamicAnchor && !o[`#` + e.$dynamicAnchor] && (o[`#` + e.$dynamicAnchor] = e), e.$anchor && !o[`#` + e.$anchor] && (o[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && !o[e.$id] && (o[e.$id] = e)); let s = { varCounter: 0, helperCode: [], rootDefs: a, refStack: new Set(), schemaMap: t || null, anchors: o, rootSchema: e, userFormats: n || null, sourceMap: i && i.sourceMap && i.schemaFile ? { file: i.schemaFile, map: i.sourceMap } : null, }; s.helperCode.push(`const _cpLen=s=>{let n=0;for(const _ of s)n++;return n}`); let c = []; if ( (V(e, `d`, ``, c, s, `#`), s.usesBranchCollapse && s.helperCode.push( `const __ATA_SEVERITY={type:10,const:8,enum:8,required:5,format:3,minLength:3,maxLength:3,minimum:3,maximum:3,pattern:3,additionalProperties:2,unevaluatedProperties:2,unevaluatedItems:2};function __ataScore(errs){if(!errs||!errs.length)return 0;let s=0;for(const e of errs)s+=__ATA_SEVERITY[e.keyword]||4;return errs.length*100+s}function __ataCollapse(kw,br,pp,sp){const pass=br.filter(b=>b.valid);if(kw==='oneOf'){if(pass.length===1)return null;if(pass.length>1)return{code:'ATA4002',keyword:'oneOf',instancePath:pp||'',path:pp||'',schemaPath:sp,message:'value matched '+pass.length+' of '+br.length+' oneOf variants, expected exactly one',params:{matched:pass.length,total:br.length}}}else{if(pass.length>=1)return null}let bi=0,bs=Infinity;for(let i=0;i<br.length;i++){const s=__ataScore(br[i].errors);if(s<bs){bs=s;bi=i}}const code=kw==='oneOf'?'ATA4001':'ATA4003';const best=br[bi];return{code,keyword:kw,instancePath:pp||'',path:pp||'',schemaPath:sp,message:'value matched 0 of '+br.length+' '+kw+' variants',params:{variants:br.length,closest:bi,closestName:best.title||('variant '+(bi+1))},branchErrors:best.errors}}`, ), c.length === 0) ) return (e) => ({ valid: !0, errors: [] }); let l = c.join(` `), u; u = s.usesRecursion ? `const _e=[]; ` + (s.helperCode.length ? s.helperCode.join(` `) + ` ` : ``) + `function _validateE(d,_all,_e){\n ${l}\n }\n _validateE(d,_all,_e);\n return{valid:_e.length===0,errors:_e}` : `const _e=[]; ` + (s.helperCode.length ? s.helperCode.join(` `) + ` ` : ``) + l + ` return{valid:_e.length===0,errors:_e}`; try { let e; if (s.usesSafeRe) { let t = Function(`__ataSafeRe`, `d`, `_all`, u); e = (e, n) => t(r, e, n); } else e = Function(`d`, `_all`, u); return ((e._errSource = u), (e._usesSafeRe = !!s.usesSafeRe), e); } catch { return null; } } function B(e, t, n, r, i, a, o) { a.usesBranchCollapse = !0; let s = a.varCounter++, c = t, l = o + `/` + c, u = [], d = []; for (let t = 0; t < e.length; t++) { let n = e[t], i = [], o = l + `/` + t; typeof n == `object` && n && V(n, `_bv`, r, i, a, o); let s = n && typeof n == `object` && typeof n.title == `string` ? n.title : ``; d.push(s); let c = i.length === 0 ? `function(_bv){return{valid:true,errors:[]}}` : `function(_bv){const _e=[];${i.join(`;`)};return{valid:_e.length===0,errors:_e}}`; u.push(c); } let f = `_brf${s}`, p = `_brr${s}`, m = JSON.stringify(d), h = `_brc${s}`, g = r || `""`; i.push( `{const ${f}=[${u.join(`,`)}];const _bt${s}=${m};const ${p}=[];for(let _bi=0;_bi<${f}.length;_bi++){const _br=${f}[_bi](${n});${p}.push({valid:_br.valid,errors:_br.errors,title:_bt${s}[_bi]})}const ${h}=__ataCollapse('${c}',${p},${g},'${l}');if(${h}){_e.push(${h});if(!_all)return{valid:false,errors:_e}}}`, ); } function V(e, t, n, r, a, s) { if (((s ||= `#`), typeof e != `object` || !e)) return; if (((a.regExpMap ||= new Map()), e.$ref)) { if (e.$ref === `#`) return; let i = e.$ref.match(/^#\/(?:\$defs|definitions)\/(.+)$/); if (i && a.rootDefs && a.rootDefs[i[1]]) { if (a.refStack.has(e.$ref)) return; (a.refStack.add(e.$ref), V(a.rootDefs[i[1]], t, n, r, a, s), a.refStack.delete(e.$ref)); return; } if (!i && e.$ref.startsWith(`#`) && !e.$ref.startsWith(`#/`)) { let i = a.rootDefs && a.rootDefs[e.$ref], o = i && i.raw ? i.raw : a.anchors && a.anchors[e.$ref]; if (o) { if (a.refStack.has(e.$ref)) return; (a.refStack.add(e.$ref), V(o, t, n, r, a, s), a.refStack.delete(e.$ref)); return; } } if (a.schemaMap && a.schemaMap.has(e.$ref)) { if (a.refStack.has(e.$ref)) return; (a.refStack.add(e.$ref), V(a.schemaMap.get(e.$ref), t, n, r, a, s), a.refStack.delete(e.$ref)); return; } if (a.schemaMap && e.$ref.includes(`#`) && !e.$ref.startsWith(`#`)) { let i = m(e.$ref, a.schemaMap); if (i) { if (a.refStack.has(e.$ref)) return; (a.refStack.add(e.$ref), V(i.schema, t, n, r, a, s), a.refStack.delete(e.$ref)); return; } } } if (e.$dynamicRef) { let i = e.$dynamicRef.startsWith(`#`) ? e.$dynamicRef : `#` + e.$dynamicRef; if (a.anchors && a.anchors[i]) { let e = a.anchors[i]; if (e === a.rootSchema) ((a.usesRecursion = !0), r.push(`_validateE(${t},_all,_e)`)); else { let o = `$dynamicRef:` + i; a.refStack.has(o) || (a.refStack.add(o), V(e, t, n, r, a, s), a.refStack.delete(o)); } } } let c = e.type ? (Array.isArray(e.type) ? e.type : [e.type]) : null; if (c) { let e = c.map((e) => { switch (e) { case `object`: return `(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`; case `array`: return `Array.isArray(${t})`; case `string`: return `typeof ${t}==='string'`; case `number`: return `(typeof ${t}==='number'&&isFinite(${t}))`; case `integer`: return `Number.isInteger(${t})`; case `boolean`: return `typeof ${t}==='boolean'`; case `null`: return `${t}===null`; default: return `true`; } }), i = c.join(`, `); { let t = `${s}/type`, c = o({ keyword: `type`, schemaPath: t, sourceMap: a.sourceMap }); r.push( `if(!(${e.join(`||`)})){_e.push({code:'${c.codeStr}',keyword:'type',instancePath:${n || `""`},schemaPath:'${t}',params:{type:'${i}'},message:'must be ${i}',docUrl:'${c.docUrl}'${c.frame}});if(!_all)return{valid:false,errors:_e}}`, ); } } let l = (e, t, r, i, c) => { let l = s + `/` + t, u = o({ keyword: e, format: c, schemaPath: l, sourceMap: a.sourceMap }); return `_e.push({code:'${u.codeStr}',keyword:'${e}',instancePath:${n || `""`},schemaPath:'${l}',params:${r},message:${i},docUrl:'${u.docUrl}'${u.frame}});if(!_all)return{valid:false,errors:_e}`; }; if (e.enum) { let n = e.enum, i = n.filter((e) => typeof e != `object` || !e), a = n.filter((e) => typeof e == `object` && !!e), o = [ i.map((e) => `${t}===${JSON.stringify(e)}`).join(`||`), a.map((e) => `JSON.stringify(${t})===${JSON.stringify(JSON.stringify(e))}`).join(`||`), ] .filter(Boolean) .join(`||`); r.push( `if(!(${o || `false`})){${l(`enum`, `enum`, `{allowedValues:${JSON.stringify(e.enum)}}`, `'must be equal to one of the allowed values'`)}}`, ); } if (e.const !== void 0) { let n = e.const; if (typeof n != `object` || !n) r.push( `if(${t}!==${JSON.stringify(n)}){${l(`const`, `const`, `{allowedValue:${JSON.stringify(e.const)}}`, `'must be equal to constant'`)}}`, ); else { let i = `_cnE${a.varCounter++}`; a.helperCode.push( `const ${i}=function(x){if(x===null||typeof x!=='object')return JSON.stringify(x);if(Array.isArray(x))return'['+x.map(${i}).join(',')+']';return'{'+Object.keys(x).sort().map(function(k){return JSON.stringify(k)+':'+${i}(x[k])}).join(',')+'}'};`, ); let o = i + `(JSON.parse(` + JSON.stringify(JSON.stringify(n)) + `))`; r.push( `if(${i}(${t})!==${o}){${l(`const`, `const`, `{allowedValue:JSON.parse(${JSON.stringify(JSON.stringify(e.const))})}`, `'must be equal to constant'`)}}`, ); } } if ((new Set(e.required || []), e.required)) { let i = `${s}/required`, c = o({ keyword: `required`, schemaPath: i, sourceMap: a.sourceMap }); for (let a of e.required) r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&!(${JSON.stringify(a)} in ${t})){_e.push({code:'${c.codeStr}',keyword:'required',instancePath:${n || `""`},schemaPath:'${i}',params:{missingProperty:'${M(a)}'},message:"must have required property '${M(a)}'",docUrl:'${c.docUrl}'${c.frame}});if(!_all)return{valid:false,errors:_e}}`, ); } if (e.minimum !== void 0) { let n = `typeof ${t}==='number'&&${t}<${e.minimum}`; r.push( `if(${n}){${l(`minimum`, `minimum`, `{comparison:'>=',limit:${e.minimum}}`, `'must be >= ${e.minimum}'`)}}`, ); } if (e.maximum !== void 0) { let n = `typeof ${t}==='number'&&${t}>${e.maximum}`; r.push( `if(${n}){${l(`maximum`, `maximum`, `{comparison:'<=',limit:${e.maximum}}`, `'must be <= ${e.maximum}'`)}}`, ); } if (e.exclusiveMinimum !== void 0) { let n = `typeof ${t}==='number'&&${t}<=${e.exclusiveMinimum}`; r.push( `if(${n}){${l(`exclusiveMinimum`, `exclusiveMinimum`, `{comparison:'>',limit:${e.exclusiveMinimum}}`, `'must be > ${e.exclusiveMinimum}'`)}}`, ); } if (e.exclusiveMaximum !== void 0) { let n = `typeof ${t}==='number'&&${t}>=${e.exclusiveMaximum}`; r.push( `if(${n}){${l(`exclusiveMaximum`, `exclusiveMaximum`, `{comparison:'<',limit:${e.exclusiveMaximum}}`, `'must be < ${e.exclusiveMaximum}'`)}}`, ); } if (e.multipleOf !== void 0) { let n = e.multipleOf, i = a.varCounter++; r.push( `{const _r${i}=typeof ${t}==='number'?${t}%${n}:NaN;if(typeof ${t}==='number'&&Math.abs(_r${i})>1e-8&&Math.abs(_r${i}-${n})>1e-8){${l(`multipleOf`, `multipleOf`, `{multipleOf:${n}}`, `'must be multiple of ${n}'`)}}}`, ); } if (e.minLength !== void 0) { let n = e.minLength, i = `typeof ${t}==='string'&&(${`${t}.length<${n}||(${t}.length<${n * 2}&&_cpLen(${t})<${n})`})`; r.push( `if(${i}){${l(`minLength`, `minLength`, `{limit:${n}}`, `'must NOT have fewer than ${n} characters'`)}}`, ); } if (e.maxLength !== void 0) { let n = e.maxLength, i = `typeof ${t}==='string'&&(${`${t}.length>${n * 2}||(${t}.length>${n}&&_cpLen(${t})>${n})`})`; r.push( `if(${i}){${l(`maxLength`, `maxLength`, `{limit:${n}}`, `'must NOT have more than ${n} characters'`)}}`, ); } if (e.pattern) { let n = P(e.pattern, t); if (n) { let i = `typeof ${t}==='string'&&!(${n})`; r.push( `if(${i}){${l(`pattern`, `pattern`, `{pattern:${JSON.stringify(e.pattern)}}`, `'must match pattern "${e.pattern}"'`)}}`, ); } else { let n = JSON.stringify(e.pattern); if (!a.regExpMap.has(n)) { let t = a.varCounter++; (a.regExpMap.set(n, t), i(e.pattern) ? (a.helperCode.push(`const _re${t}=__ataSafeRe(${n})`), (a.usesSafeRe = !0)) : a.helperCode.push(`const _re${t}=new RegExp(${n})`)); } let o = `typeof ${t}==='string'&&!_re${a.regExpMap.get(n)}.test(${t})`; r.push( `if(${o}){${l(`pattern`, `pattern`, `{pattern:${JSON.stringify(e.pattern)}}`, `'must match pattern "${e.pattern}"'`)}}`, ); } } if (e.format) { let i = j[e.format], c = `${s}/format`, l = o({ keyword: `format`, format: e.format, schemaPath: c, sourceMap: a.sourceMap }), u = `_e.push({code:'${l.codeStr}',keyword:'format',instancePath:${n || `""`},schemaPath:'${c}',params:{format:'${M(e.format)}'},message:'must match format "${M(e.format)}"',docUrl:'${l.docUrl}'${l.frame}});if(!_all)return{valid:false,errors:_e}`; if (i) { a.varCounter++; let e = []; e.push(i(t, !1)); let n = e.join(`;`).replace(/return false/g, `{${u}}`); r.push(n); } else if (a.userFormats && typeof a.userFormats[e.format] == `function`) { let n = `_uf_${e.format.replace(/[^a-zA-Z0-9_]/g, `_`)}`, i = `typeof ${t}==='string'&&`; r.push(`if(${i}!${n}(${t})){${u}}`); } } if (e.minItems !== void 0) { let n = `Array.isArray(${t})&&${t}.length<${e.minItems}`; r.push( `if(${n}){${l(`minItems`, `minItems`, `{limit:${e.minItems}}`, `'must NOT have fewer than ${e.minItems} items'`)}}`, ); } if (e.maxItems !== void 0) { let n = `Array.isArray(${t})&&${t}.length>${e.maxItems}`; r.push( `if(${n}){${l(`maxItems`, `maxItems`, `{limit:${e.maxItems}}`, `'must NOT have more than ${e.maxItems} items'`)}}`, ); } if (e.uniqueItems) { let n = a.varCounter++, i = e.items && typeof e.items == `object` && e.items.type, o = i === `string` || i === `number` || i === `integer`, s = e.maxItems, c = (e, t) => l( `uniqueItems`, `uniqueItems`, `{i:${e},j:${t}}`, `'must NOT have duplicate items (items ## '+${t}+' and '+${e}+' are identical)'`, ), u; ((u = o && s && s <= 16 ? `for(let _i=1;_i<${t}.length;_i++){for(let _k=0;_k<_i;_k++){if(${t}[_i]===${t}[_k]){${c(`_k`, `_i`)};break}}}` : o ? `const _s${n}=new Map();for(let _i=0;_i<${t}.length;_i++){const _prev=_s${n}.get(${t}[_i]);if(_prev!==undefined){${c(`_prev`, `_i`)};break};_s${n}.set(${t}[_i],_i)}` : `const _cn${n}=function(x){if(x===null||typeof x!=='object')return typeof x+':'+x;if(Array.isArray(x))return'['+x.map(_cn${n}).join(',')+']';return'{'+Object.keys(x).sort().map(function(k){return JSON.stringify(k)+':'+_cn${n}(x[k])}).join(',')+'}'};const _s${n}=new Map();for(let _i=0;_i<${t}.length;_i++){const _k=_cn${n}(${t}[_i]);const _prev=_s${n}.get(_k);if(_prev!==undefined){${c(`_prev`, `_i`)};break};_s${n}.set(_k,_i)}`), r.push(`if(Array.isArray(${t})){${u}}`)); } if ( (e.minProperties !== void 0 && r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&Object.keys(${t}).length<${e.minProperties}){${l(`minProperties`, `minProperties`, `{limit:${e.minProperties}}`, `'must NOT have fewer than ${e.minProperties} properties'`)}}`, ), e.maxProperties !== void 0 && r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&Object.keys(${t}).length>${e.maxProperties}){${l(`maxProperties`, `maxProperties`, `{limit:${e.maxProperties}}`, `'must NOT have more than ${e.maxProperties} properties'`)}}`, ), e.additionalProperties === !1 && e.properties) ) { let i = Object.keys(e.properties) .map((e) => `${JSON.stringify(e)}`) .join(`,`), c = a.varCounter++, l = `${s}/additionalProperties`, u = o({ keyword: `additionalProperties`, schemaPath: l, sourceMap: a.sourceMap }), d = `const _k${c}=Object.keys(${t});const _a${c}=new Set([${i}]);for(let _i=0;_i<_k${c}.length;_i++){if(!_a${c}.has(_k${c}[_i])){_e.push({code:'${u.codeStr}',keyword:'additionalProperties',instancePath:${n || `""`},schemaPath:'${l}',params:{additionalProperty:_k${c}[_i]},message:'must NOT have additional properties',docUrl:'${u.docUrl}'${u.frame}});if(!_all)return{valid:false,errors:_e}}}`; r.push(`if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${d}}`); } if (e.dependentRequired) { let i = `${s}/dependentRequired`, c = o({ keyword: `dependentRequired`, schemaPath: i, sourceMap: a.sourceMap }); for (let [a, o] of Object.entries(e.dependentRequired)) for (let e of o) r.push( `if(typeof ${t}==='object'&&${t}!==null&&${JSON.stringify(a)} in ${t}&&!(${JSON.stringify(e)} in ${t})){_e.push({code:'${c.codeStr}',keyword:'required',instancePath:${n || `""`},schemaPath:'${i}',params:{missingProperty:'${M(e)}'},message:"must have required property '${M(e)}'",docUrl:'${c.docUrl}'${c.frame}});if(!_all)return{valid:false,errors:_e}}`, ); } if (e.properties) for (let [i, o] of Object.entries(e.properties)) { let e = N(n, M(i)); (r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&${JSON.stringify(i)} in ${t}){`, ), V(o, `${t}[${JSON.stringify(i)}]`, e, r, a, s + `/properties/` + i), r.push(`}`)); } if (e.patternProperties) for (let [o, c] of Object.entries(e.patternProperties)) { let e = JSON.stringify(o); if (!a.regExpMap.has(e)) { let t = a.varCounter++; (a.regExpMap.set(e, t), i(o) ? (a.helperCode.push(`const _re${t}=__ataSafeRe(${e})`), (a.usesSafeRe = !0)) : a.helperCode.push(`const _re${t}=new RegExp(${e})`)); } let l = a.regExpMap.get(e), u = a.varCounter++; r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){for(const _k${u} in ${t}){if(_re${l}.test(_k${u})){`, ); let d = n ? `${n}+'/'+_k${u}` : `'/'+_k${u}`; (V(c, `${t}[_k${u}]`, d, r, a, s + `/patternProperties`), r.push(`}}}`)); } if (typeof e.additionalProperties == `object` && e.additionalProperties !== null) { let i = a.varCounter++, o = Object.keys(e.properties || {}), c = o.length ? `const _ak${i}=new Set([${o.map((e) => JSON.stringify(e)).join(`,`)}]);` : ``, l = o.length ? `if(!_ak${i}.has(_k${i})){` : `{`; r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){${c}for(const _k${i} in ${t}){${l}`, ); let u = n ? `${n}+'/'+_k${i}` : `'/'+_k${i}`; (V(e.additionalProperties, `${t}[_k${i}]`, u, r, a, s + `/additionalProperties`), r.push(`}}}`)); } if (e.dependentSchemas) for (let [i, o] of Object.entries(e.dependentSchemas)) (r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&${JSON.stringify(i)} in ${t}){`, ), V(o, t, n, r, a, s + `/dependentSchemas/` + i), r.push(`}`)); if (e.propertyNames && typeof e.propertyNames == `object`) { let n = e.propertyNames, o = a.varCounter++; if ( (r.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){for(const _k${o} in ${t}){`, ), n.minLength !== void 0 && r.push( `if(_k${o}.length<${n.minLength}){${l(`minLength`, `propertyNames/minLength`, `{limit:${n.minLength}}`, `'must NOT have fewer than ${n.minLength} characters'`)}}`, ), n.maxLength !== void 0 && r.push( `if(_k${o}.length>${n.maxLength}){${l(`maxLength`, `propertyNames/maxLength`, `{limit:${n.maxLength}}`, `'must NOT have more than ${n.maxLength} characters'`)}}`, ), n.pattern) ) { let e = JSON.stringify(n.pattern); if (!a.regExpMap.has(e)) { let t = a.varCounter++; (a.regExpMap.set(e, t), i(n.pattern) ? (a.helperCode.push(`const _re${t}=__ataSafeRe(${e})`), (a.usesSafeRe = !0)) : a.helperCode.push(`const _re${t}=new RegExp(${e})`)); } let t = a.regExpMap.get(e); r.push( `if(!_re${t}.test(_k${o})){${l(`pattern`, `propertyNames/pattern`, `{pattern:${JSON.stringify(n.pattern)}}`, `'must match pattern "${n.pattern}"'`)}}`, ); } if ( (n.const !== void 0 && r.push( `if(_k${o}!==${JSON.stringify(n.const)}){${l(`const`, `propertyNames/const`, `{allowedValue:${JSON.stringify(n.const)}}`, `'must be equal to constant'`)}}`, ), n.enum) ) { let e = a.varCounter++; (a.helperCode.push(`const _es${e}=new Set(${JSON.stringify(n.enum)})`), r.push( `if(!_es${e}.has(_k${o})){${l(`enum`, `propertyNames/enum`, `{allowedValues:${JSON.stringify(n.enum)}}`, `'must be equal to one of the allowed values'`)}}`, )); } r.push(`}}`); } if (e.items) { let i = e.prefixItems ? e.prefixItems.length : 0, o = `_j${a.varCounter}`, c = `_ei${a.varCounter}`; a.varCounter++; let l = I(n, o); (r.push( `if(Array.isArray(${t})){for(let ${o}=${i};${o}<${t}.length;${o}++){const ${c}=${t}[${o}]`, ), V(e.items, c, l, r, a, s + `/items`), r.push(`}}`)); } if (e.prefixItems) for (let i = 0; i < e.prefixItems.length; i++) { let o = N(n, String(i)); (r.push(`if(Array.isArray(${t})&&${t}.length>${i}){`), V(e.prefixItems[i], `${t}[${i}]`, o, r, a, s + `/prefixItems/` + i), r.push(`}`)); } if (e.contains) { let n = a.varCounter++, i = []; A(e.contains, `_cv`, i, a); let o = i.length === 0 ? `return true` : `${i.join(`;`)};return true`, s = e.minContains === void 0 ? 1 : e.minContains, c = e.maxContains; (r.push( `if(Array.isArray(${t})){const _cf${n}=function(_cv){${o}};let _cc${n}=0;for(let _ci${n}=0;_ci${n}<${t}.length;_ci${n}++){if(_cf${n}(${t}[_ci${n}]))_cc${n}++}`, ), r.push( `if(_cc${n}<${s}){${l(`contains`, `contains`, `{limit:${s}}`, `'contains: need at least ${s} match(es)'`)}}`, ), c !== void 0 && r.push( `if(_cc${n}>${c}){${l(`contains`, `contains`, `{limit:${c}}`, `'contains: at most ${c} match(es)'`)}}`, ), r.push(`}`)); } if (e.allOf) for (let i = 0; i < e.allOf.length; i++) V(e.allOf[i], t, n, r, a, s + `/allOf/` + i); if ( (e.anyOf && B(e.anyOf, `anyOf`, t, n, r, a, s), e.oneOf && B(e.oneOf, `oneOf`, t, n, r, a, s), e.not) ) { let n = []; A(e.not, `_nv`, n, a); let i = n.length === 0 ? `function(_nv){return true}` : `function(_nv){${n.join(`;`)};return true}`, o = a.varCounter++; r.push( `{const _nf${o}=${i};if(_nf${o}(${t})){${l(`not`, `not`, `{}`, `'must NOT be valid'`)}}}`, ); } if (e.if) { let i = []; A(e.if, `_iv`, i, a); let o = a.varCounter++, c = i.length === 0 ? `function(_iv){return true}` : `function(_iv){${i.join(`;`)};return true}`; (r.push(`{const _if${o}=${c}`), e.then && (r.push(`if(_if${o}(${t})){`), V(e.then, t, n, r, a, s + `/then`), r.push(`}`)), e.else && (r.push(`${e.then ? `else` : `if(!_if${o}(${t}))`}{`), V(e.else, t, n, r, a, s + `/else`), r.push(`}`)), r.push(`}`)); } } function H(e, t, n, r) { if (typeof e == `object` && e) { let t = JSON.stringify(e); if ( t.includes(`unevaluatedProperties`) || t.includes(`unevaluatedItems`) || t.includes(`"$ref":"#"`) || w(e) || t.includes(`"oneOf"`) || t.includes(`"anyOf"`) ) return null; } if (typeof e == `boolean`) return e ? () => t : () => ({ valid: !1, errors: [ { keyword: `false schema`, instancePath: ``, schemaPath: `#`, params: {}, message: `boolean schema is false`, }, ], }); if (typeof e != `object` || !e || !C(e, n)) return null; if (e.patternProperties) { for (let [t, r] of Object.entries(e.patternProperties)) if ( typeof r == `boolean` || /\\[pP]\{/.test(t) || (typeof r == `object` && r && !C(r, n)) ) return null; } if (e.dependentSchemas) { for (let t of Object.values(e.dependentSchemas)) if (typeof t == `boolean` || (typeof t == `object` && t && !C(t, n))) return null; } if (e.propertyNames) { if (typeof e.propertyNames == `boolean`) return null; let t = e.propertyNames, n = [`maxLength`, `minLength`, `pattern`, `const`, `enum`]; if ( Object.keys(t) .filter((e) => e !== `$schema`) .some((e) => !n.includes(e)) ) return null; } let i = e.$defs || e.definitions || null, a = {}; if ( (e.$dynamicAnchor && (a[`#` + e.$dynamicAnchor] = e), e.$anchor && (a[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && (a[e.$id] = e), i) ) for (let e of Object.values(i)) e && typeof e == `object` && (e.$dynamicAnchor && (a[`#` + e.$dynamicAnchor] = e), e.$anchor && (a[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && (a[e.$id] = e)); if (n) for (let e of n.values()) e && typeof e == `object` && (e.$dynamicAnchor && !a[`#` + e.$dynamicAnchor] && (a[`#` + e.$dynamicAnchor] = e), e.$anchor && !a[`#` + e.$anchor] && (a[`#` + e.$anchor] = e), typeof e.$id == `string` && e.$id.startsWith(`#`) && !a[e.$id] && (a[e.$id] = e)); let o = { varCounter: 0, helperCode: [], closureVars: [`_cpLen`], closureVals: [s], rootDefs: i, refStack: new Set(), schemaMap: n || null, anchors: a, rootSchema: e, userFormats: r || null, }, c = []; if ((U(e, `d`, ``, c, o, `#`), c.length === 0)) return () => t; let l = o.closureVars.join(`,`), u = `let _e; ` + (o.helperCode.length ? o.helperCode.join(` `) + ` ` : ``) + c.join(` `) + ` return _e?{valid:false,errors:_e}:R`; try { return ( typeof process < `u` && process.env && process.env.ATA_DUMP_CODEGEN && console.log( `=== COMBINED CODEGEN === ` + u + ` === CLOSURE VARS: ` + o.closureVars.length + ` ===`, ), Function(`R` + (l ? `,` + l : ``), `return function(d){${u}}`)(t, ...o.closureVals) ); } catch (e) { return ( typeof process < `u` && process.env && process.env.ATA_DEBUG && console.error( `compileToJSCombined error:`, e.message, ` `, u.slice(0, 500), ), null ); } } function U(e, t, n, o, s, c) { if (((c ||= `#`), typeof e != `object` || !e)) return; if (e.$ref) { if (e.$ref === `#`) return; let r = e.$ref.match(/^#\/(?:\$defs|definitions)\/(.+)$/); if (r && s.rootDefs && s.rootDefs[r[1]]) { if (s.refStack.has(e.$ref)) return; (s.refStack.add(e.$ref), U(s.rootDefs[r[1]], t, n, o, s, c), s.refStack.delete(e.$ref)); return; } if (!r && e.$ref.startsWith(`#`) && !e.$ref.startsWith(`#/`)) { let r = s.rootDefs && s.rootDefs[e.$ref], i = r && r.raw ? r.raw : s.anchors && s.anchors[e.$ref]; if (i) { if (s.refStack.has(e.$ref)) return; (s.refStack.add(e.$ref), U(i, t, n, o, s, c), s.refStack.delete(e.$ref)); return; } } if (s.schemaMap && s.schemaMap.has(e.$ref)) { if (s.refStack.has(e.$ref)) return; (s.refStack.add(e.$ref), U(s.schemaMap.get(e.$ref), t, n, o, s, c), s.refStack.delete(e.$ref)); return; } if (s.schemaMap && e.$ref.includes(`#`) && !e.$ref.startsWith(`#`)) { let r = m(e.$ref, s.schemaMap); if (r) { if (s.refStack.has(e.$ref)) return; (s.refStack.add(e.$ref), U(r.schema, t, n, o, s, c), s.refStack.delete(e.$ref)); return; } } } if (e.$dynamicRef) { let r = e.$dynamicRef.startsWith(`#`) ? e.$dynamicRef : `#` + e.$dynamicRef; if (s.anchors && s.anchors[r]) { let e = s.anchors[r]; if (e !== s.rootSchema) { let i = `$dynamicRef:` + r; s.refStack.has(i) || (s.refStack.add(i), U(e, t, n, o, s, c), s.refStack.delete(i)); } } } let l = e.type ? (Array.isArray(e.type) ? e.type : [e.type]) : null, u = !1, d = !1, f = !1, p = !1, h = !n || (n.startsWith(`'`) && !n.includes(`+`)), g = (e, t, r, i) => { let a = c + `/` + t; if (h && i.startsWith(`'`) && !i.includes(`+`)) { let t; try { t = Function(`return ` + r)(); } catch {} if (t !== void 0) { let r = `_E${s.varCounter++}`, o = n ? n.slice(1, -1) : ``, c = i.slice(1, -1); return ( s.closureVars.push(r), s.closureVals.push( Object.freeze({ keyword: e, instancePath: o, schemaPath: a, params: Object.freeze(t), message: c, }), ), `(_e||(_e=[])).push(${r})` ); } } return `(_e||(_e=[])).push({keyword:'${e}',instancePath:${n || `""`},schemaPath:'${a}',params:${r},message:${i}})`; }; if (l) { let e = l.map((e) => { switch (e) { case `object`: return `(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`; case `array`: return `Array.isArray(${t})`; case `string`: return `typeof ${t}==='string'`; case `number`: return `(typeof ${t}==='number'&&isFinite(${t}))`; case `integer`: return `Number.isInteger(${t})`; case `boolean`: return `typeof ${t}==='boolean'`; case `null`: return `${t}===null`; default: return `true`; } }), n = l.join(`, `), r = `_tok${s.varCounter++}`; (o.push(`const ${r}=${e.join(`||`)}`), o.push(`if(!${r}){${g(`type`, `type`, `{type:'${n}'}`, `'must be ${n}'`)}}`), l.length === 1 && ((u = l[0] === `object`), (d = l[0] === `array`), (f = l[0] === `string`), (p = l[0] === `number` || l[0] === `integer`)), o.push(`if(${r}){`)); } if (e.enum) { let n = e.enum, r = n.filter((e) => typeof e != `object` || !e), i = n.filter((e) => typeof e == `object` && !!e), a = [ r.map((e) => `${t}===${JSON.stringify(e)}`).join(`||`), i.map((e) => `JSON.stringify(${t})===${JSON.stringify(JSON.stringify(e))}`).join(`||`), ] .filter(Boolean) .join(`||`); o.push( `if(!(${a || `false`})){${g(`enum`, `enum`, `{allowedValues:${JSON.stringify(e.enum)}}`, `'must be equal to one of the allowed values'`)}}`, ); } if (e.const !== void 0) { let n = e.const; if (typeof n != `object` || !n) o.push( `if(${t}!==${JSON.stringify(n)}){${g(`const`, `const`, `{allowedValue:${JSON.stringify(e.const)}}`, `'must be equal to constant'`)}}`, ); else { let r = `_cn${s.varCounter++}`; (s.helperCode.push( `const ${r}=function(x){if(x===null||typeof x!=='object')return JSON.stringify(x);if(Array.isArray(x))return'['+x.map(${r}).join(',')+']';return'{'+Object.keys(x).sort().map(function(k){return JSON.stringify(k)+':'+${r}(x[k])}).join(',')+'}'};`, ), o.push( `if(${r}(${t})!==${r}(JSON.parse(${JSON.stringify(JSON.stringify(n))}))){${g(`const`, `const`, `{allowedValue:JSON.parse(${JSON.stringify(JSON.stringify(e.const))})}`, `'must be equal to constant'`)}}`, )); } } let _ = new Set(e.required || []), v = {}; if (e.required && e.properties && u) { let r = []; for (let t of e.required) if (e.properties[t]) { let e = `_h${s.varCounter++}`; ((v[t] = e), r.push(`${JSON.stringify(t)}:${e}`)); } r.length > 0 && o.push(`const{${r.join(`,`)}}=${t}`); for (let r of e.required) { let e = v[r] ? `${v[r]}===undefined` : `${t}[${JSON.stringify(r)}]===undefined`; if (h) { let t = `_E${s.varCounter++}`, i = n ? n.slice(1, -1) : ``; (s.closureVars.push(t), s.closureVals.push( Object.freeze({ keyword: `required`, instancePath: i, schemaPath: `${c}/required`, params: Object.freeze({ missingProperty: r }), message: `must have required property '${r}'`, }), ), o.push(`if(${e}){(_e||(_e=[])).push(${t})}`)); } else o.push( `if(${e}){(_e||(_e=[])).push({keyword:'required',instancePath:${n || `""`},schemaPath:'${c}/required',params:{missingProperty:'${M(r)}'},message:"must have required property '${M(r)}'"})}`, ); } } else if (e.required) for (let r of e.required) if (!n || (n.startsWith(`'`) && !n.includes(`+`))) { let e = `_E${s.varCounter++}`, i = n ? n.slice(1, -1) : ``; (s.closureVars.push(e), s.closureVals.push( Object.freeze({ keyword: `required`, instancePath: i, schemaPath: `${c}/required`, params: Object.freeze({ missingProperty: r }), message: `must have required property '${r}'`, }), ), o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&!(${JSON.stringify(r)} in ${t})){(_e||(_e=[])).push(${e})}`, )); } else o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&!(${JSON.stringify(r)} in ${t})){(_e||(_e=[])).push({keyword:'required',instancePath:${n || `""`},schemaPath:'${c}/required',params:{missingProperty:'${M(r)}'},message:"must have required property '${M(r)}'"})}`, ); if (e.minimum !== void 0) { let n = p ? `${t}<${e.minimum}` : `typeof ${t}==='number'&&${t}<${e.minimum}`; o.push( `if(${n}){${g(`minimum`, `minimum`, `{comparison:'>=',limit:${e.minimum}}`, `'must be >= ${e.minimum}'`)}}`, ); } if (e.maximum !== void 0) { let n = p ? `${t}>${e.maximum}` : `typeof ${t}==='number'&&${t}>${e.maximum}`; o.push( `if(${n}){${g(`maximum`, `maximum`, `{comparison:'<=',limit:${e.maximum}}`, `'must be <= ${e.maximum}'`)}}`, ); } if (e.exclusiveMinimum !== void 0) { let n = p ? `${t}<=${e.exclusiveMinimum}` : `typeof ${t}==='number'&&${t}<=${e.exclusiveMinimum}`; o.push( `if(${n}){${g(`exclusiveMinimum`, `exclusiveMinimum`, `{comparison:'>',limit:${e.exclusiveMinimum}}`, `'must be > ${e.exclusiveMinimum}'`)}}`, ); } if (e.exclusiveMaximum !== void 0) { let n = p ? `${t}>=${e.exclusiveMaximum}` : `typeof ${t}==='number'&&${t}>=${e.exclusiveMaximum}`; o.push( `if(${n}){${g(`exclusiveMaximum`, `exclusiveMaximum`, `{comparison:'<',limit:${e.exclusiveMaximum}}`, `'must be < ${e.exclusiveMaximum}'`)}}`, ); } if (e.multipleOf !== void 0) { let n = e.multipleOf, r = s.varCounter++; o.push( `{const _r${r}=typeof ${t}==='number'?${t}%${n}:NaN;if(typeof ${t}==='number'&&Math.abs(_r${r})>1e-8&&Math.abs(_r${r}-${n})>1e-8){${g(`multipleOf`, `multipleOf`, `{multipleOf:${n}}`, `'must be multiple of ${n}'`)}}}`, ); } if (e.minLength !== void 0) { let n = e.minLength, r = `${t}.length<${n}||(${t}.length<${n * 2}&&_cpLen(${t})<${n})`, i = f ? r : `typeof ${t}==='string'&&(${r})`; o.push( `if(${i}){${g(`minLength`, `minLength`, `{limit:${n}}`, `'must NOT have fewer than ${n} characters'`)}}`, ); } if (e.maxLength !== void 0) { let n = e.maxLength, r = `${t}.length>${n * 2}||(${t}.length>${n}&&_cpLen(${t})>${n})`, i = f ? r : `typeof ${t}==='string'&&(${r})`; o.push( `if(${i}){${g(`maxLength`, `maxLength`, `{limit:${n}}`, `'must NOT have more than ${n} characters'`)}}`, ); } if (e.pattern) { let n = P(e.pattern, t); if (n) { let r = f ? `!(${n})` : `typeof ${t}==='string'&&!(${n})`; o.push( `if(${r}){${g(`pattern`, `pattern`, `{pattern:${JSON.stringify(e.pattern)}}`, `'must match pattern "${e.pattern}"'`)}}`, ); } else { let n = `_re${s.varCounter++}`; (s.closureVars.push(n), s.closureVals.push(i(e.pattern) ? r(e.pattern) : new RegExp(e.pattern))); let a = f ? `!${n}.test(${t})` : `typeof ${t}==='string'&&!${n}.test(${t})`; o.push( `if(${a}){${g(`pattern`, `pattern`, `{pattern:${JSON.stringify(e.pattern)}}`, `'must match pattern "${e.pattern}"'`)}}`, ); } } if (e.format) { let n = j[e.format]; if (n) { let r = n(t, f).replace( /return false/g, `{${g(`format`, `format`, `{format:'${M(e.format)}'}`, `'must match format "${M(e.format)}"'`)}}`, ); o.push(r); } else if (s.userFormats && typeof s.userFormats[e.format] == `function`) { let n = `_uf_${e.format.replace(/[^a-zA-Z0-9_]/g, `_`)}`; s.closureVars.includes(n) || (s.closureVars.push(n), s.closureVals.push(s.userFormats[e.format])); let r = f ? `` : `typeof ${t}==='string'&&`; o.push( `if(${r}!${n}(${t})){${g(`format`, `format`, `{format:'${M(e.format)}'}`, `'must match format "${M(e.format)}"'`)}}`, ); } } if (e.minItems !== void 0) { let n = d ? `${t}.length<${e.minItems}` : `Array.isArray(${t})&&${t}.length<${e.minItems}`; o.push( `if(${n}){${g(`minItems`, `minItems`, `{limit:${e.minItems}}`, `'must NOT have fewer than ${e.minItems} items'`)}}`, ); } if (e.maxItems !== void 0) { let n = d ? `${t}.length>${e.maxItems}` : `Array.isArray(${t})&&${t}.length>${e.maxItems}`; o.push( `if(${n}){${g(`maxItems`, `maxItems`, `{limit:${e.maxItems}}`, `'must NOT have more than ${e.maxItems} items'`)}}`, ); } if (e.uniqueItems) { let n = s.varCounter++, r = e.items && typeof e.items == `object` && e.items.type, i = r === `string` || r === `number` || r === `integer`, a = e.maxItems, c = (e, t) => g( `uniqueItems`, `uniqueItems`, `{i:${e},j:${t}}`, `'must NOT have duplicate items (items ## '+${t}+' and '+${e}+' are identical)'`, ), l; ((l = i && a && a <= 16 ? `for(let _i=1;_i<${t}.length;_i++){for(let _k=0;_k<_i;_k++){if(${t}[_i]===${t}[_k]){${c(`_k`, `_i`)};break}}}` : i ? `const _s${n}=new Map();for(let _i=0;_i<${t}.length;_i++){const _prev=_s${n}.get(${t}[_i]);if(_prev!==undefined){${c(`_prev`, `_i`)};break};_s${n}.set(${t}[_i],_i)}` : `const _cn${n}=function(x){if(x===null||typeof x!=='object')return typeof x+':'+x;if(Array.isArray(x))return'['+x.map(_cn${n}).join(',')+']';return'{'+Object.keys(x).sort().map(function(k){return JSON.stringify(k)+':'+_cn${n}(x[k])}).join(',')+'}'};const _s${n}=new Map();for(let _i=0;_i<${t}.length;_i++){const _k=_cn${n}(${t}[_i]);const _prev=_s${n}.get(_k);if(_prev!==undefined){${c(`_prev`, `_i`)};break};_s${n}.set(_k,_i)}`), o.push(d ? `{${l}}` : `if(Array.isArray(${t})){${l}}`)); } if ( (e.minProperties !== void 0 && o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&Object.keys(${t}).length<${e.minProperties}){${g(`minProperties`, `minProperties`, `{limit:${e.minProperties}}`, `'must NOT have fewer than ${e.minProperties} properties'`)}}`, ), e.maxProperties !== void 0 && o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&Object.keys(${t}).length>${e.maxProperties}){${g(`maxProperties`, `maxProperties`, `{limit:${e.maxProperties}}`, `'must NOT have more than ${e.maxProperties} properties'`)}}`, ), e.additionalProperties === !1 && e.properties && !e.patternProperties) ) { let n = Object.keys(e.properties), r = s.varCounter++; if (n.length <= 8) { let e = n.map((e) => `_k${r}[_i]!==${JSON.stringify(e)}`).join(`&&`); o.push( u ? `{const _k${r}=Object.keys(${t});for(let _i=0;_i<_k${r}.length;_i++)if(${e}){${g(`additionalProperties`, `additionalProperties`, `{additionalProperty:_k${r}[_i]}`, `'must NOT have additional properties'`)}}}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){const _k${r}=Object.keys(${t});for(let _i=0;_i<_k${r}.length;_i++)if(${e}){${g(`additionalProperties`, `additionalProperties`, `{additionalProperty:_k${r}[_i]}`, `'must NOT have additional properties'`)}}}`, ); } else { let e = n.map((e) => JSON.stringify(e)).join(`,`); o.push( u ? `{const _k${r}=Object.keys(${t});const _a${r}=new Set([${e}]);for(let _i=0;_i<_k${r}.length;_i++)if(!_a${r}.has(_k${r}[_i])){${g(`additionalProperties`, `additionalProperties`, `{additionalProperty:_k${r}[_i]}`, `'must NOT have additional properties'`)}}}` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){const _k${r}=Object.keys(${t});const _a${r}=new Set([${e}]);for(let _i=0;_i<_k${r}.length;_i++)if(!_a${r}.has(_k${r}[_i])){${g(`additionalProperties`, `additionalProperties`, `{additionalProperty:_k${r}[_i]}`, `'must NOT have additional properties'`)}}}`, ); } } if (e.dependentRequired) for (let [r, i] of Object.entries(e.dependentRequired)) for (let e of i) if (!n || (n.startsWith(`'`) && !n.includes(`+`))) { let i = `_E${s.varCounter++}`, a = n ? n.slice(1, -1) : ``; (s.closureVars.push(i), s.closureVals.push( Object.freeze({ keyword: `required`, instancePath: a, schemaPath: `${c}/dependentRequired`, params: Object.freeze({ missingProperty: e }), message: `must have required property '${e}'`, }), ), o.push( `if(typeof ${t}==='object'&&${t}!==null&&${JSON.stringify(r)} in ${t}&&!(${JSON.stringify(e)} in ${t})){(_e||(_e=[])).push(${i})}`, )); } else o.push( `if(typeof ${t}==='object'&&${t}!==null&&${JSON.stringify(r)} in ${t}&&!(${JSON.stringify(e)} in ${t})){(_e||(_e=[])).push({keyword:'required',instancePath:${n || `""`},schemaPath:'${c}/dependentRequired',params:{missingProperty:'${M(e)}'},message:"must have required property '${M(e)}'"})}`, ); if (e.properties) for (let [r, i] of Object.entries(e.properties)) { let e = v[r] || `${t}[${JSON.stringify(r)}]`, a = N(n, M(r)); if (_.has(r) && u) (o.push(`if(${e}!==undefined){`), U(i, e, a, o, s, c + `/properties/` + r), o.push(`}`)); else if (u) { let e = s.varCounter++; (o.push(`{const _o${e}=${t}[${JSON.stringify(r)}];if(_o${e}!==undefined){`), U(i, `_o${e}`, a, o, s, c + `/properties/` + r), o.push(`}}`)); } else (o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&${JSON.stringify(r)} in ${t}){`, ), U(i, `${t}[${JSON.stringify(r)}]`, a, o, s, c + `/properties/` + r), o.push(`}`)); } if (e.patternProperties) { let n = Object.entries(e.patternProperties), r = e.propertyNames && typeof e.propertyNames == `object` ? e.propertyNames : null, i = s.varCounter++, c = []; for (let [e] of n) { let t = L(e, `_k${i}`); if (t) c.push({ check: t }); else { let t = s.varCounter++; (s.closureVars.push(`_re${t}`), s.closureVals.push(a(s, e)), c.push({ check: `_re${t}.test(_k${i})` })); } } for (let e = 0; e < n.length; e++) { let [, t] = n[e], r = []; A(t, `_ppv`, r, s); let a = r.length === 0 ? `return true` : `${r.join(`;`)};return true`, o = `_ppf${i}_${e}`; (s.closureVars.push(o), s.closureVals.push(Function(`_ppv`, a))); } let l = u ? `` : `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t}))`, d = `_k${i}`; if (e.additionalProperties === !1 && e.properties) { s._ppHandledPropertyNamesC = !!r; let u = Object.keys(e.properties), f = u.length <= 8 ? u.map((e) => `${d}===${JSON.stringify(e)}`).join(`||`) : null; if (!f) { let e = `_as${i}`; (s.closureVars.push(e), s.closureVals.push(new Set(u))); } if ((o.push(`${l}{for(const ${d} in ${t}){`), r)) { if ( (r.minLength !== void 0 && o.push( `if(${d}.length<${r.minLength}){${g(`minLength`, `propertyNames/minLength`, `{limit:${r.minLength}}`, `'must NOT have fewer than ${r.minLength} characters'`)}}`, ), r.maxLength !== void 0 && o.push( `if(${d}.length>${r.maxLength}){${g(`maxLength`, `propertyNames/maxLength`, `{limit:${r.maxLength}}`, `'must NOT have more than ${r.maxLength} characters'`)}}`, ), r.pattern) ) { let e = L(r.pattern, d); if (e) o.push( `if(!(${e})){${g(`pattern`, `propertyNames/pattern`, `{pattern:${JSON.stringify(r.pattern)}}`, `'must match pattern "${r.pattern}"'`)}}`, ); else { let e = s.varCounter++; (s.closureVars.push(`_re${e}`), s.closureVals.push(a(s, r.pattern)), o.push( `if(!_re${e}.test(${d})){${g(`pattern`, `propertyNames/pattern`, `{pattern:${JSON.stringify(r.pattern)}}`, `'must match pattern "${r.pattern}"'`)}}`, )); } } if ( (r.const !== void 0 && o.push( `if(${d}!==${JSON.stringify(r.const)}){${g(`const`, `propertyNames/const`, `{allowedValue:${JSON.stringify(r.const)}}`, `'must be equal to constant'`)}}`, ), r.enum) ) { let e = s.varCounter++; (s.closureVars.push(`_es${e}`), s.closureVals.push(new Set(r.enum)), o.push( `if(!_es${e}.has(${d})){${g(`enum`, `propertyNames/enum`, `{allowedValues:${JSON.stringify(r.enum)}}`, `'must be equal to one of the allowed values'`)}}`, )); } } let p = f || `_as${i}.has(${d})`; o.push(`let _m${i}=${p}`); for (let e = 0; e < n.length; e++) o.push( `if(${c[e].check}){_m${i}=true;if(!_ppf${i}_${e}(${t}[${d}])){${g(`pattern`, `patternProperties`, `{pattern:'${n[e][0]}'}`, `'patternProperties: value invalid for key '+${d}`)}}}`, ); (o.push( `if(!_m${i}){${g(`additionalProperties`, `additionalProperties`, `{additionalProperty:${d}}`, `'must NOT have additional properties'`)}}`, ), o.push(`}}`)); } else { if (((s._ppHandledPropertyNamesC = !!r), o.push(`${l}{for(const ${d} in ${t}){`), r)) { if ( (r.minLength !== void 0 && o.push( `if(${d}.length<${r.minLength}){${g(`minLength`, `propertyNames/minLength`, `{limit:${r.minLength}}`, `'must NOT have fewer than ${r.minLength} characters'`)}}`, ), r.maxLength !== void 0 && o.push( `if(${d}.length>${r.maxLength}){${g(`maxLength`, `propertyNames/maxLength`, `{limit:${r.maxLength}}`, `'must NOT have more than ${r.maxLength} characters'`)}}`, ), r.pattern) ) { let e = L(r.pattern, d); if (e) o.push( `if(!(${e})){${g(`pattern`, `propertyNames/pattern`, `{pattern:${JSON.stringify(r.pattern)}}`, `'must match pattern "${r.pattern}"'`)}}`, ); else { let e = s.varCounter++; (s.closureVars.push(`_re${e}`), s.closureVals.push(a(s, r.pattern)), o.push( `if(!_re${e}.test(${d})){${g(`pattern`, `propertyNames/pattern`, `{pattern:${JSON.stringify(r.pattern)}}`, `'must match pattern "${r.pattern}"'`)}}`, )); } } if ( (r.const !== void 0 && o.push( `if(${d}!==${JSON.stringify(r.const)}){${g(`const`, `propertyNames/const`, `{allowedValue:${JSON.stringify(r.const)}}`, `'must be equal to constant'`)}}`, ), r.enum) ) { let e = s.varCounter++; (s.closureVars.push(`_es${e}`), s.closureVals.push(new Set(r.enum)), o.push( `if(!_es${e}.has(${d})){${g(`enum`, `propertyNames/enum`, `{allowedValues:${JSON.stringify(r.enum)}}`, `'must be equal to one of the allowed values'`)}}`, )); } } for (let e = 0; e < n.length; e++) o.push( `if(${c[e].check}&&!_ppf${i}_${e}(${t}[${d}])){${g(`pattern`, `patternProperties`, `{pattern:'${n[e][0]}'}`, `'patternProperties: value invalid for key '+${d}`)}}`, ); o.push(`}}`); } } if (e.dependentSchemas) for (let [r, i] of Object.entries(e.dependentSchemas)) (o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})&&${JSON.stringify(r)} in ${t}){`, ), U(i, t, n, o, s, c + `/dependentSchemas/` + r), o.push(`}`)); if (e.propertyNames && typeof e.propertyNames == `object` && !s._ppHandledPropertyNamesC) { let n = e.propertyNames, r = s.varCounter++; if ( (o.push( `if(typeof ${t}==='object'&&${t}!==null&&!Array.isArray(${t})){for(const _k${r} in ${t}){`, ), n.minLength !== void 0 && o.push( `if(_k${r}.length<${n.minLength}){${g(`minLength`, `propertyNames/minLength`, `{limit:${n.minLength}}`, `'must NOT have fewer than ${n.minLength} characters'`)}}`, ), n.maxLength !== void 0 && o.push( `if(_k${r}.length>${n.maxLength}){${g(`maxLength`, `propertyNames/maxLength`, `{limit:${n.maxLength}}`, `'must NOT have more than ${n.maxLength} characters'`)}}`, ), n.pattern) ) { let e = s.varCounter++; (s.closureVars.push(`_re${e}`), s.closureVals.push(a(s, n.pattern)), o.push( `if(!_re${e}.test(_k${r})){${g(`pattern`, `propertyNames/pattern`, `{pattern:${JSON.stringify(n.pattern)}}`, `'must match pattern "${n.pattern}"'`)}}`, )); } if ( (n.const !== void 0 && o.push( `if(_k${r}!==${JSON.stringify(n.const)}){${g(`const`, `propertyNames/const`, `{allowedValue:${JSON.stringify(n.const)}}`, `'must be equal to constant'`)}}`, ), n.enum) ) { let e = s.varCounter++; (s.closureVars.push(`_es${e}`), s.closureVals.push(new Set(n.enum)), o.push( `if(!_es${e}.has(_k${r})){${g(`enum`, `propertyNames/enum`, `{allowedValues:${JSON.stringify(n.enum)}}`, `'must be equal to one of the allowed values'`)}}`, )); } o.push(`}}`); } if (e.items) { let r = e.prefixItems ? e.prefixItems.length : 0, i = `_j${s.varCounter}`, a = `_ei${s.varCounter}`; s.varCounter++; let l = I(n, i); (o.push( `if(Array.isArray(${t})){for(let ${i}=${r};${i}<${t}.length;${i}++){const ${a}=${t}[${i}]`, ), U(e.items, a, l, o, s, c + `/items`), o.push(`}}`)); } if (e.prefixItems) for (let r = 0; r < e.prefixItems.length; r++) { let i = N(n, String(r)); (o.push(`if(Array.isArray(${t})&&${t}.length>${r}){`), U(e.prefixItems[r], `${t}[${r}]`, i, o, s, c + `/prefixItems/` + r), o.push(`}`)); } if (e.contains) { let n = s.varCounter++, r = []; A(e.contains, `_cv`, r, s); let i = r.length === 0 ? `return true` : `${r.join(`;`)};return true`, a = e.minContains === void 0 ? 1 : e.minContains, c = e.maxContains; (o.push( `if(Array.isArray(${t})){const _cf${n}=function(_cv){${i}};let _cc${n}=0;for(let _ci${n}=0;_ci${n}<${t}.length;_ci${n}++){if(_cf${n}(${t}[_ci${n}]))_cc${n}++}`, ), o.push( `if(_cc${n}<${a}){${g(`contains`, `contains`, `{limit:${a}}`, `'contains: need at least ${a} match(es)'`)}}`, ), c !== void 0 && o.push( `if(_cc${n}>${c}){${g(`contains`, `contains`, `{limit:${c}}`, `'contains: at most ${c} match(es)'`)}}`, ), o.push(`}`)); } if (e.allOf) for (let r = 0; r < e.allOf.length; r++) U(e.allOf[r], t, n, o, s, c + `/allOf/` + r); if (e.anyOf) { let n = s.varCounter++, r = e.anyOf.map((e) => { let t = []; return ( A(e, `_av`, t, s), t.length === 0 ? `function(_av){return true}` : `function(_av){${t.join(`;`)};return true}` ); }); o.push( `{const _af${n}=[${r.join(`,`)}];let _am=false;for(let _ai=0;_ai<_af${n}.length;_ai++){if(_af${n}[_ai](${t})){_am=true;break}}if(!_am){${g(`anyOf`, `anyOf`, `{}`, `'must match a schema in anyOf'`)}}}`, ); } if (e.oneOf) { let n = s.varCounter++, r = e.oneOf.map((e) => { let t = []; return ( A(e, `_ov`, t, s), t.length === 0 ? `function(_ov){return true}` : `function(_ov){${t.join(`;`)};return true}` ); }); o.push( `{const _of${n}=[${r.join(`,`)}];let _oc=0;for(let _oi=0;_oi<_of${n}.length;_oi++){if(_of${n}[_oi](${t}))_oc++;if(_oc>1)break}if(_oc!==1){${g(`oneOf`, `oneOf`, `{}`, `'must match exactly one schema in oneOf'`)}}}`, ); } if (e.not) { let n = []; A(e.not, `_nv`, n, s); let r = n.length === 0 ? `function(_nv){return true}` : `function(_nv){${n.join(`;`)};return true}`, i = s.varCounter++; o.push( `{const _nf${i}=${r};if(_nf${i}(${t})){${g(`not`, `not`, `{}`, `'must NOT be valid'`)}}}`, ); } if (e.if) { let r = []; A(e.if, `_iv`, r, s); let i = s.varCounter++, a = r.length === 0 ? `function(_iv){return true}` : `function(_iv){${r.join(`;`)};return true}`; (o.push(`{const _if${i}=${a}`), e.then && (o.push(`if(_if${i}(${t})){`), U(e.then, t, n, o, s, c + `/then`), o.push(`}`)), e.else && (o.push(`${e.then ? `else` : `if(!_if${i}(${t}))`}{`), U(e.else, t, n, o, s, c + `/else`), o.push(`}`)), o.push(`}`)); } l && o.push(`}`); } function W(e, t, n) { if (typeof e != `object` || !e) return { props: [], items: null, allProps: !1, allItems: !1, dynamic: !1 }; let r = n || e.$defs || e.definitions || null, i = { props: [], items: null, allProps: !1, allItems: !1, dynamic: !1 }; return (G(e, i, r, t, new Set(), !0), i); } function G(e, t, n, r, i, a) { if (!(typeof e != `object` || !e) && !(t.allProps && t.allItems)) { if (e.$ref) { let a = e.$ref.match(/^#\/(?:\$defs|definitions)\/(.+)$/); if (a && n && n[a[1]]) { if (i.has(e.$ref)) { t.dynamic = !0; return; } (i.add(e.$ref), G(n[a[1]], t, n, r, i), i.delete(e.$ref)); } else if (r && typeof r.get == `function`) { let a = r.has(e.$ref) ? r.get(e.$ref) : null; if (!a && !e.$ref.includes(`://`) && !e.$ref.startsWith(`#`)) { for (let [t, n] of r) if (t.endsWith(`/` + e.$ref)) { a = n; break; } } if (a) { if (i.has(e.$ref)) { t.dynamic = !0; return; } (i.add(e.$ref), G(a, t, n, r, i), i.delete(e.$ref)); } } if ( !Object.keys(e).some( (e) => e !== `$ref` && e !== `$defs` && e !== `definitions` && e !== `$schema` && e !== `$id`, ) ) return; } if (e.properties) for (let n of Object.keys(e.properties)) t.props.includes(n) || t.props.push(n); if ( (e.additionalProperties !== void 0 && e.additionalProperties !== !1 && (t.allProps = !0), e.patternProperties && (t.dynamic = !0), e.prefixItems) ) { let n = e.prefixItems.length; t.items = t.items === null ? n : Math.max(t.items, n); } if ( (e.items && typeof e.items == `object` && (t.allItems = !0), e.items === !0 && (t.allItems = !0), e.contains && (t.dynamic = !0), !a && (e.unevaluatedProperties === !0 || (typeof e.unevaluatedProperties == `object` && e.unevaluatedProperties !== null)) && (t.allProps = !0), !a && (e.unevaluatedItems === !0 || (typeof e.unevaluatedItems == `object` && e.unevaluatedItems !== null)) && (t.allItems = !0), e.allOf) ) for (let a of e.allOf) G(a, t, n, r, i); if (e.anyOf || e.oneOf) { t.dynamic = !0; let a = e.anyOf || e.oneOf; for (let e of a) G(e, t, n, r, i); } if (e.if && (e.then || e.else)) ((t.dynamic = !0), G(e.if, t, n, r, i), e.then && G(e.then, t, n, r, i), e.else && G(e.else, t, n, r, i)); else if (e.if) { if (((t.dynamic = !0), e.if.properties)) for (let n of Object.keys(e.if.properties)) t.props.includes(n) || t.props.push(n); e.if.patternProperties; } if (e.dependentSchemas) { t.dynamic = !0; for (let a of Object.values(e.dependentSchemas)) G(a, t, n, r, i); } } } t.exports = { compileToJS: l, compileToJSCodegen: T, compileToJSCodegenWithErrors: z, compileToJSCombined: H, collectEvaluated: W, AJV_MESSAGES: c, }; }), m = o((e, t) => { let n = new Set([ `http://json-schema.org/draft-07/schema#`, `http://json-schema.org/draft-07/schema`, ]); function r(e) { return !!(e && e.$schema && n.has(e.$schema)); } function i(e) { return (r(e) && a(e), e); } function a(e) { if (!(typeof e != `object` || !e)) { if ( (e.definitions && !e.$defs && ((e.$defs = e.definitions), delete e.definitions), e.dependencies) ) { for (let [t, n] of Object.entries(e.dependencies)) Array.isArray(n) ? ((e.dependentRequired ||= {}), (e.dependentRequired[t] = n)) : ((e.dependentSchemas ||= {}), (e.dependentSchemas[t] = n)); delete e.dependencies; } Array.isArray(e.items) && ((e.prefixItems = e.items), e.additionalItems === void 0 ? delete e.items : ((e.items = e.additionalItems), delete e.additionalItems)); for (let t of [ `properties`, `patternProperties`, `$defs`, `definitions`, `dependentSchemas`, ]) if (e[t] && typeof e[t] == `object`) for (let n of Object.values(e[t])) typeof n == `object` && n && a(n); for (let t of [`allOf`, `anyOf`, `oneOf`, `prefixItems`]) if (Array.isArray(e[t])) for (let n of e[t]) typeof n == `object` && n && a(n); for (let t of [ `items`, `contains`, `not`, `if`, `then`, `else`, `additionalProperties`, `propertyNames`, ]) typeof e[t] == `object` && e[t] !== null && a(e[t]); } } function o(e) { return (typeof e != `object` || !e || s(e), e); } function s(e) { if (!(typeof e != `object` || !e)) { (e.nullable === !0 && e.type !== void 0 && (Array.isArray(e.type) ? e.type.includes(`null`) || (e.type = e.type.concat(`null`)) : (e.type = [e.type, `null`])), `nullable` in e && delete e.nullable); for (let t of [ `properties`, `patternProperties`, `$defs`, `definitions`, `dependentSchemas`, ]) if (e[t] && typeof e[t] == `object`) for (let n of Object.values(e[t])) typeof n == `object` && n && s(n); for (let t of [`allOf`, `anyOf`, `oneOf`, `prefixItems`]) if (Array.isArray(e[t])) for (let n of e[t]) typeof n == `object` && n && s(n); for (let t of [ `items`, `contains`, `not`, `if`, `then`, `else`, `additionalProperties`, `propertyNames`, `unevaluatedItems`, `unevaluatedProperties`, ]) typeof e[t] == `object` && e[t] !== null && s(e[t]); } } t.exports = { isDraft7: r, normalizeDraft7: i, normalizeNullable: o }; }), h = o((e, t) => { let n = new Set([`string`, `number`, `integer`, `boolean`]), r = new Set([ `$schema`, `$id`, `$comment`, `title`, `description`, `default`, `examples`, `deprecated`, `readOnly`, `writeOnly`, ]), i = new Set([`type`, `properties`, `required`, `additionalProperties`, ...r]), a = new Set([ `type`, `enum`, `const`, `minLength`, `maxLength`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`, ...r, ]); function o(e) { return typeof e == `string` && n.has(e); } function s(e) { let t = typeof e; return e === null || t === `string` || t === `number` || t === `boolean`; } function c(e) { if (typeof e != `object` || !e || Array.isArray(e) || !o(e.type)) return !1; for (let t of Object.keys(e)) if (!a.has(t)) return !1; if (e.enum !== void 0) { if (!Array.isArray(e.enum) || e.enum.length === 0 || e.enum.length > 256) return !1; for (let t of e.enum) if (!s(t)) return !1; } return !(e.const !== void 0 && !s(e.const)); } function l(e) { if (e.type !== `object`) return !1; for (let t of Object.keys(e)) if (!i.has(t)) return !1; let t = e.additionalProperties; if (t !== void 0 && t !== !0 && t !== !1) return !1; if (e.required !== void 0) { if (!Array.isArray(e.required)) return !1; for (let t of e.required) if (typeof t != `string`) return !1; } let n = e.properties; if (n === void 0) return !0; if (typeof n != `object` || !n || Array.isArray(n)) return !1; let r = Object.keys(n); if (r.length > 10) return !1; for (let e of r) if (!c(n[e])) return !1; return !0; } function u(e) { return typeof e != `object` || !e || Array.isArray(e) ? { tier: 2, plan: null } : c(e) || l(e) ? { tier: 0, plan: null } : { tier: 2, plan: null }; } t.exports = { classify: u, MAX_TIER0_PROPS: 10, MAX_TIER0_ENUM: 256, PRIMITIVE_TYPES: n }; }), g = o((e, t) => { let n = { string: 1, number: 2, integer: 4, boolean: 8 }, r = n.string, i = n.number, a = n.integer, o = n.boolean; function s(e) { let t = e.length; for (let n = 0; n < t; n++) if (e.charCodeAt(n) >= 55296 && e.charCodeAt(n) <= 56319) { let t = 0; for (let n of e) t++; return t; } return t; } function c(e, t) { let r = t.type, i = Array.isArray(t.enum), a = t.const !== void 0, o = 0; return ( typeof t.minimum == `number` && (o |= 1), typeof t.maximum == `number` && (o |= 2), typeof t.exclusiveMinimum == `number` && (o |= 4), typeof t.exclusiveMaximum == `number` && (o |= 8), typeof t.multipleOf == `number` && (o |= 16), { key: e, typeMask: n[r] | 0, numFlags: o, hasEnum: i, hasConst: a, enumSet: i ? new Set(t.enum) : null, constVal: a ? t.const : void 0, minLen: typeof t.minLength == `number` ? t.minLength : -1, maxLen: typeof t.maxLength == `number` ? t.maxLength : -1, min: typeof t.minimum == `number` ? t.minimum : 0, max: typeof t.maximum == `number` ? t.maximum : 0, exclMin: typeof t.exclusiveMinimum == `number` ? t.exclusiveMinimum : 0, exclMax: typeof t.exclusiveMaximum == `number` ? t.exclusiveMaximum : 0, multipleOf: typeof t.multipleOf == `number` ? t.multipleOf : 0, } ); } function l(e) { if (e.type !== `object`) return { isPrimitive: !0, constraints: [c(`__root__`, e)], requiredMask: 0, additionalAllowed: !0, knownKeys: null, }; let t = e.properties || {}, n = Object.keys(t), r = e.required ? new Set(e.required) : null, i = Array(n.length), a = new Set(), o = 0; for (let e = 0; e < n.length; e++) { let s = n[e]; ((i[e] = c(s, t[s])), a.add(s), r && r.has(s) && (o |= 1 << e)); } return { isPrimitive: !1, constraints: i, requiredMask: o, additionalAllowed: e.additionalProperties !== !1, knownKeys: a, }; } function u(e, t) { let n = e.typeMask; if (n === r) { if (typeof t != `string`) return !1; let n = e.minLen, r = e.maxLen; if (n >= 0) { let e = t.length; if (e < n || (e < n * 2 && s(t) < n)) return !1; } if (r >= 0 && t.length > r && s(t) > r) return !1; } else if (n === a) { if (typeof t != `number` || !Number.isInteger(t)) return !1; let n = e.numFlags; if ( n !== 0 && ((n & 1 && t < e.min) || (n & 2 && t > e.max) || (n & 4 && t <= e.exclMin) || (n & 8 && t >= e.exclMax) || (n & 16 && t % e.multipleOf !== 0)) ) return !1; } else if (n === i) { if (typeof t != `number`) return !1; let n = e.numFlags; if ( n !== 0 && ((n & 1 && t < e.min) || (n & 2 && t > e.max) || (n & 4 && t <= e.exclMin) || (n & 8 && t >= e.exclMax) || (n & 16 && t % e.multipleOf !== 0)) ) return !1; } else if (n === o) { if (typeof t != `boolean`) return !1; } else return !1; return !((e.hasEnum && !e.enumSet.has(t)) || (e.hasConst && t !== e.constVal)); } function d(e, t) { if (typeof t != `object` || !t || Array.isArray(t)) return !1; let n = e.constraints, c = n.length, l = e.requiredMask, u = 0; for (let e = 0; e < c; e++) { let c = n[e], d = t[c.key]; if (d === void 0) { if (l & (1 << e)) return !1; continue; } u |= 1 << e; let f = c.typeMask; if (f === r) { if (typeof d != `string`) return !1; let e = c.minLen, t = c.maxLen; if (e >= 0) { let t = d.length; if (t < e || (t < e * 2 && s(d) < e)) return !1; } if (t >= 0 && d.length > t && s(d) > t) return !1; } else if (f === a) { if (typeof d != `number` || !Number.isInteger(d)) return !1; let e = c.numFlags; if ( e !== 0 && ((e & 1 && d < c.min) || (e & 2 && d > c.max) || (e & 4 && d <= c.exclMin) || (e & 8 && d >= c.exclMax) || (e & 16 && d % c.multipleOf !== 0)) ) return !1; } else if (f === i) { if (typeof d != `number`) return !1; let e = c.numFlags; if ( e !== 0 && ((e & 1 && d < c.min) || (e & 2 && d > c.max) || (e & 4 && d <= c.exclMin) || (e & 8 && d >= c.exclMax) || (e & 16 && d % c.multipleOf !== 0)) ) return !1; } else if (f === o) { if (typeof d != `boolean`) return !1; } else return !1; if ((c.hasEnum && !c.enumSet.has(d)) || (c.hasConst && d !== c.constVal)) return !1; } if ((u & l) !== l) return !1; if (!e.additionalAllowed) { let n = e.knownKeys; for (let e in t) if (Object.prototype.hasOwnProperty.call(t, e) && !n.has(e)) return !1; } return !0; } function f(e, t) { return e.isPrimitive ? u(e.constraints[0], t) : d(e, t); } t.exports = { buildTier0Plan: l, tier0Validate: f, tier0ValidateObject: d, checkPrimitive: u, TYPE_MASK: n, }; }), _ = o((e, t) => { function n(e) { return e.replace(/~/g, `~0`).replace(/\//g, `~1`); } function r(e) { let t = Object.create(null), r = e.split(` `), i = Array(r.length + 1); i[0] = 0; for (let e = 0; e < r.length; e++) i[e + 1] = i[e] + r[e].length + 1; function a(e) { let t = 0, n = i.length - 1; for (; t < n;) { let r = (t + n + 1) >> 1; i[r] <= e ? (t = r) : (n = r - 1); } return { line: t + 1, col: e - i[t] + 1, text: r[t] || `` }; } let o = 0, s = e.length; function c() { for (; o < s;) { let t = e.charCodeAt(o); if (t === 32 || t === 9 || t === 10 || t === 13) o++; else break; } } function l() { let t = o; for (o++; o < s;) { let n = e.charCodeAt(o); if (n === 92) { o += 2; continue; } if (n === 34) return (o++, JSON.parse(e.slice(t, o))); o++; } throw Error(`unterminated string at offset ` + t); } function u() { if ((c(), o >= s)) return; let t = e.charCodeAt(o); if (t === 34) { l(); return; } if (t === 123 || t === 91) { let n = t, r = n === 123 ? 125 : 93, i = 1; for (o++; o < s && i > 0;) { let t = e.charCodeAt(o); if (t === 34) { l(); continue; } (t === n ? i++ : t === r && i--, o++); } return; } for (; o < s;) { let t = e.charCodeAt(o); if (t === 44 || t === 125 || t === 93 || t === 32 || t === 9 || t === 10 || t === 13) return; o++; } } function d(e) { return e.length === 0 ? `` : `/` + e.map(n).join(`/`); } function f(n) { if ((c(), o >= s)) return; let r = a(o); t[d(n)] = r; let i = e.charCodeAt(o); if (i === 123) for (o++; ;) { if ((c(), e.charCodeAt(o) === 125)) { o++; return; } if (e.charCodeAt(o) === 44) { o++; continue; } c(); let r = o, i = l(), s = a(r); if ((c(), e.charCodeAt(o) !== 58)) throw Error(`expected ":" at offset ` + o); o++; let u = n.concat([i]); ((t[d(u) + `#key`] = s), f(u)); } else if (i === 91) { o++; let t = 0; for (;;) { if ((c(), e.charCodeAt(o) === 93)) { o++; return; } if (e.charCodeAt(o) === 44) { o++; continue; } (f(n.concat([String(t)])), t++); } } else u(); } return (e.charCodeAt(0) === 65279 && (o = 1), f([]), t); } t.exports = { buildPositionMap: r, escapePtr: n }; }), v = o((e, t) => { let { escapePtr: n } = _(); function r(e) { let t = Buffer.isBuffer(e) ? e.toString(`utf8`) : String(e), r = Object.create(null), i = t.split(` `), a = Array(i.length + 1); a[0] = 0; for (let e = 0; e < i.length; e++) a[e + 1] = a[e] + i[e].length + 1; function o(e) { let t = 0, n = a.length - 1; for (; t < n;) { let r = (t + n + 1) >> 1; a[r] <= e ? (t = r) : (n = r - 1); } return { line: t + 1, col: e - a[t] + 1, text: i[t] || `` }; } let s = 0, c = t.length; function l() { for (; s < c;) { let e = t.charCodeAt(s); if (e === 32 || e === 9 || e === 10 || e === 13) s++; else break; } } function u() { let e = s; for (s++; s < c;) { let n = t.charCodeAt(s); if (n === 92) { s += 2; continue; } if (n === 34) return (s++, JSON.parse(t.slice(e, s))); s++; } throw Error(`unterminated string at offset ` + e); } function d(e) { return e.length === 0 ? `` : `/` + e.map(n).join(`/`); } function f(e) { if ((l(), s >= c)) return; let n = s, i = o(n), a = t.charCodeAt(s); if (a === 123) for (s++; ;) { if ((l(), t.charCodeAt(s) === 125)) { s++; break; } if (t.charCodeAt(s) === 44) { s++; continue; } l(); let n = u(); if ((l(), t.charCodeAt(s) !== 58)) throw Error(`expected ":" at offset ` + s); (s++, f(e.concat([n]))); } else if (a === 91) { s++; let n = 0; for (;;) { if ((l(), t.charCodeAt(s) === 93)) { s++; break; } if (t.charCodeAt(s) === 44) { s++; continue; } (f(e.concat([String(n)])), n++); } } else if (a === 34) u(); else for (; s < c;) { let e = t.charCodeAt(s); if (e === 44 || e === 125 || e === 93 || e === 32 || e === 9 || e === 10 || e === 13) break; s++; } let p = s - n; r[d(e)] = { byteOffset: n, length: p, line: i.line, col: i.col, text: i.text }; } return (t.charCodeAt(0) === 65279 && (s = 1), f([]), r); } t.exports = { buildDataPositionMap: r }; }), y = o((e, t) => { let { buildDataPositionMap: n } = v(); function r() { let e = new WeakMap(), t = new Map(); return { get(r) { if (r == null) return null; if (typeof r == `string`) { if (t.has(r)) return t.get(r); try { let e = n(r); return (t.set(r, e), e); } catch { return null; } } if (Buffer.isBuffer(r)) { if (e.has(r)) return e.get(r); try { let t = n(r); return (e.set(r, t), t); } catch { return null; } } return null; }, reset() { t.clear(); }, }; } t.exports = { createCache: r }; }), b = o((e, t) => { let { compileSafe: n } = f(), r = { single: [ `additionalProperties`, `contains`, `propertyNames`, `if`, `then`, `else`, `not`, `items`, `unevaluatedItems`, `unevaluatedProperties`, ], maps: [`$defs`, `definitions`, `properties`, `patternProperties`, `dependentSchemas`], lists: [`allOf`, `anyOf`, `oneOf`, `prefixItems`], }, i = `ata://root`; function a(e, t) { try { return new URL(t, e || i).href; } catch { return t; } } function o(e) { let t = e.indexOf(`#`); return t < 0 ? [e, ``] : [e.slice(0, t), decodeURIComponent(e.slice(t + 1))]; } function s(e, t) { let n = { resources: new Map(), anchors: new Map(), dynamicAnchors: new Map(), nodeBase: new Map(), rootBase: i, }, r = typeof e == `object` && e && typeof e.$id == `string` ? a(i, o(e.$id)[0]) : i; if (((n.rootBase = r), c(e, r, n), t)) for (let [e, r] of t) { let t = a(i, o(e)[0]); (n.resources.has(t) || c(r, t, n), n.resources.has(e) || n.resources.set(e, r)); } return n; } function c(e, t, n) { typeof e != `object` || !e || (n.resources.has(t) || n.resources.set(t, e), n.anchors.has(t) || n.anchors.set(t, new Map()), n.dynamicAnchors.has(t) || n.dynamicAnchors.set(t, new Map()), l(e, t, n, !0)); } function l(e, t, n, i) { if (!(typeof e != `object` || !e) && !n.nodeBase.has(e)) { if ((n.nodeBase.set(e, t), !i && typeof e.$id == `string`)) { let r = o(a(t, e.$id))[0]; (n.nodeBase.delete(e), c(e, r, n)); return; } (typeof e.$anchor == `string` && n.anchors.get(t).set(e.$anchor, e), typeof e.$dynamicAnchor == `string` && (n.dynamicAnchors.get(t).set(e.$dynamicAnchor, e), n.anchors.get(t).set(e.$dynamicAnchor, e))); for (let i of r.single) e[i] !== void 0 && l(e[i], t, n, !1); for (let i of r.maps) { let r = e[i]; if (r && typeof r == `object` && !Array.isArray(r)) for (let e of Object.keys(r)) l(r[e], t, n, !1); } for (let i of r.lists) { let r = e[i]; if (Array.isArray(r)) for (let e of r) l(e, t, n, !1); } } } function u(e, t) { if (t === `` || t === `/`) return e; let n = t .split(`/`) .slice(1) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), r = e; for (let e of n) { if (typeof r != `object` || !r) return; if (Array.isArray(r)) r = r[Number(e)]; else if (e in r) r = r[e]; else if (e === `definitions` && r.$defs) r = r.$defs; else if (e === `$defs` && r.definitions) r = r.definitions; else return; } return r; } function d(e, t, n) { let [r, s] = o(a(t, e)), c = n.resources.get(r), l = r; if ( (c === void 0 && (r === i || r === ``) && ((c = n.resources.get(n.rootBase)), (l = n.rootBase)), c === void 0) ) { let [t, r] = o(e); if (n.resources.has(t)) { if (((c = n.resources.get(t)), (l = t), r === ``)) return { node: c, base: l }; if (r.startsWith(`/`)) return { node: u(c, r), base: l }; let e = n.anchors.get(l); return { node: e ? e.get(r) : void 0, base: l }; } return { node: void 0, base: l }; } if (s === ``) return { node: c, base: l }; if (s.startsWith(`/`)) { let e = u(c, s); return { node: e, base: typeof e == `object` && e && n.nodeBase.has(e) ? n.nodeBase.get(e) : l, }; } let d = n.anchors.get(l); return { node: d ? d.get(s) : void 0, base: l }; } function p(e, t) { if (e === t) return !0; if (typeof e == `number` && typeof t == `number`) return e === t; if (e === null || t === null || typeof e != `object` || typeof t != `object`) return !1; let n = Array.isArray(e); if (n !== Array.isArray(t)) return !1; if (n) { if (e.length !== t.length) return !1; for (let n = 0; n < e.length; n++) if (!p(e[n], t[n])) return !1; return !0; } let r = Object.keys(e), i = Object.keys(t); if (r.length !== i.length) return !1; for (let n of r) if (!(n in t) || !p(e[n], t[n])) return !1; return !0; } function m(e) { let t = 0; for (let n = 0; n < e.length; n++) { let r = e.charCodeAt(n); (r >= 55296 && r <= 56319 && n + 1 < e.length && n++, t++); } return t; } function h(e, t) { switch (e) { case `string`: return typeof t == `string`; case `number`: return typeof t == `number` && isFinite(t); case `integer`: return typeof t == `number` && Number.isInteger(t); case `boolean`: return typeof t == `boolean`; case `null`: return t === null; case `array`: return Array.isArray(t); case `object`: return typeof t == `object` && !!t && !Array.isArray(t); default: return !0; } } function g(e, t) { if (t === 0) return !1; let n = e / t; return Number.isInteger(n) ? !0 : Math.abs(n - Math.round(n)) < 1e-9; } let _ = { email: (e) => { let t = e.indexOf(`@`); return t > 0 && t < e.length - 1 && e.indexOf(`.`, t) > t + 1; }, date: (e) => { if (e.length !== 10 || !/^\d{4}-\d{2}-\d{2}$/.test(e)) return !1; let t = +e.slice(5, 7), n = +e.slice(8, 10); return t >= 1 && t <= 12 && n >= 1 && n <= 31; }, "date-time": (e) => /^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/.test(e) && !isNaN(Date.parse(e)), time: (e) => /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?([Zz]|[+-]\d{2}:\d{2})?$/.test(e), duration: (e) => /^P(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?$/.test( e, ) && e !== `P` && !e.endsWith(`T`), uuid: (e) => e.length === 36 && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e), uri: (e) => /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e) && !/[\s\u0000-\u001f\u007f]/.test(e), "uri-reference": (e) => !/[\s\u0000-\u001f\u007f]/.test(e), ipv4: (e) => { let t = e.split(`.`); return ( t.length === 4 && t.every((e) => { let t = +e; return e !== `` && t >= 0 && t <= 255 && String(t) === e; }) ); }, ipv6: (e) => e !== `` && /^[0-9a-fA-F:.]+$/.test(e) && e.split(`:`).length >= 3 && e.split(`:`).length <= 8, hostname: (e) => e.length > 0 && e.length <= 253 && /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( e, ), regex: (e) => { try { return (new RegExp(e, `u`), !0); } catch { try { return (new RegExp(e), !0); } catch { return !1; } } }, "json-pointer": (e) => e === `` || (/^\//.test(e) && !/~(?![01])/.test(e)), }; function v(e, t) { if (t.props && t.props.size) { e.props ||= new Set(); for (let n of t.props) e.props.add(n); } if (t.items && t.items.size) { e.items ||= new Set(); for (let n of t.items) e.items.add(n); } } var y = class { constructor(e, t) { let n = t || {}; ((this.root = e), (this.state = s(e, n.schemaMap)), (this.userFormats = n.formats || null), (this.patternCache = new Map())); } pattern(e) { let t = this.patternCache.get(e); if (!t) { if (/\\[pP]\{/.test(e)) try { t = new RegExp(e, `u`); } catch { t = new RegExp(e); } else try { t = n(e); } catch { try { t = new RegExp(e, `u`); } catch { t = new RegExp(e); } } this.patternCache.set(e, t); } return t; } validate(e) { let t = [], n = [this.state.rootBase]; return this.eval(this.root, e, this.state.rootBase, n, t, ``, `#`, [], b()) ? { valid: !0, data: e, errors: [] } : { valid: !1, errors: t }; } eval(e, t, n, r, i, s, c, l, u) { if (e === !0) return !0; if (e === !1) return (i.push(S(`false schema`, `not`, s, c, {}, `boolean schema is false`)), !1); if (typeof e != `object` || !e) return !0; for (let n of l) if (n[0] === e && n[1] === t) return !0; l = l.concat([[e, t]]); let f = this.state.nodeBase.get(e); (f !== void 0 && f !== n && (n = f), this.state.resources.get(n) === e && r[r.length - 1] !== n && (r = r.concat(n))); let y = !0, b = { props: null, items: null }; if (typeof e.$ref == `string`) { let { node: a, base: o } = d(e.$ref, n, this.state); if (a === void 0) (i.push( S(`$ref`, `$ref`, s, c + `/$ref`, { ref: e.$ref }, `cannot resolve $ref ${e.$ref}`), ), (y = !1)); else { let e = { props: null, items: null }; this.eval(a, t, o, r, i, s, c + `/$ref`, l, e) ? v(b, e) : (y = !1); } } if (typeof e.$dynamicRef == `string`) { let u = e.$dynamicRef, { node: f, base: p } = d(u, n, this.state), [, m] = o(a(n, u)); if (f !== void 0 && m && !m.startsWith(`/`)) { let e = this.state.dynamicAnchors.get(p); if (e && e.get(m) === f) for (let e of r) { let t = this.state.dynamicAnchors.get(e); if (t && t.has(m)) { ((f = t.get(m)), (p = e)); break; } } } if (f === void 0) (i.push( S( `$dynamicRef`, `$dynamicRef`, s, c + `/$dynamicRef`, { ref: u }, `cannot resolve $dynamicRef ${u}`, ), ), (y = !1)); else { let e = { props: null, items: null }; this.eval(f, t, p, r, i, s, c + `/$dynamicRef`, l, e) ? v(b, e) : (y = !1); } } if (e.type !== void 0) { let n = Array.isArray(e.type) ? e.type : [e.type]; n.some((e) => h(e, t)) || (i.push( S(`type`, `type`, s, c + `/type`, { type: e.type }, `must be ${n.join(` or `)}`), ), (y = !1)); } if ( (e.enum !== void 0 && (e.enum.some((e) => p(e, t)) || (i.push( S( `enum`, `enum`, s, c + `/enum`, { allowedValues: e.enum }, `must be equal to one of the allowed values`, ), ), (y = !1))), e.const !== void 0 && (p(e.const, t) || (i.push( S( `const`, `const`, s, c + `/const`, { allowedValue: e.const }, `must be equal to constant`, ), ), (y = !1))), typeof t == `number` && (typeof e.minimum == `number` && !(t >= e.minimum) && (i.push( S( `minimum`, `minimum`, s, c + `/minimum`, { comparison: `>=`, limit: e.minimum }, `must be >= ${e.minimum}`, ), ), (y = !1)), typeof e.maximum == `number` && !(t <= e.maximum) && (i.push( S( `maximum`, `maximum`, s, c + `/maximum`, { comparison: `<=`, limit: e.maximum }, `must be <= ${e.maximum}`, ), ), (y = !1)), typeof e.exclusiveMinimum == `number` && !(t > e.exclusiveMinimum) && (i.push( S( `exclusiveMinimum`, `exclusiveMinimum`, s, c + `/exclusiveMinimum`, { comparison: `>`, limit: e.exclusiveMinimum }, `must be > ${e.exclusiveMinimum}`, ), ), (y = !1)), typeof e.exclusiveMaximum == `number` && !(t < e.exclusiveMaximum) && (i.push( S( `exclusiveMaximum`, `exclusiveMaximum`, s, c + `/exclusiveMaximum`, { comparison: `<`, limit: e.exclusiveMaximum }, `must be < ${e.exclusiveMaximum}`, ), ), (y = !1)), typeof e.multipleOf == `number` && !g(t, e.multipleOf) && (i.push( S( `multipleOf`, `multipleOf`, s, c + `/multipleOf`, { multipleOf: e.multipleOf }, `must be multiple of ${e.multipleOf}`, ), ), (y = !1))), typeof t == `string` && (e.minLength !== void 0 && m(t) < e.minLength && (i.push( S( `minLength`, `minLength`, s, c + `/minLength`, { limit: e.minLength }, `must NOT have fewer than ${e.minLength} characters`, ), ), (y = !1)), e.maxLength !== void 0 && m(t) > e.maxLength && (i.push( S( `maxLength`, `maxLength`, s, c + `/maxLength`, { limit: e.maxLength }, `must NOT have more than ${e.maxLength} characters`, ), ), (y = !1)), e.pattern !== void 0 && !this.pattern(e.pattern).test(t) && (i.push( S( `pattern`, `pattern`, s, c + `/pattern`, { pattern: e.pattern }, `must match pattern "${e.pattern}"`, ), ), (y = !1)), e.format !== void 0)) ) { let n = this.userFormats && typeof this.userFormats[e.format] == `function` ? this.userFormats[e.format] : _[e.format]; n && !n(t) && (i.push( S( `format`, `format`, s, c + `/format`, { format: e.format }, `must match format "${e.format}"`, ), ), (y = !1)); } if (Array.isArray(t)) { if ( (e.minItems !== void 0 && t.length < e.minItems && (i.push( S( `minItems`, `minItems`, s, c + `/minItems`, { limit: e.minItems }, `must NOT have fewer than ${e.minItems} items`, ), ), (y = !1)), e.maxItems !== void 0 && t.length > e.maxItems && (i.push( S( `maxItems`, `maxItems`, s, c + `/maxItems`, { limit: e.maxItems }, `must NOT have more than ${e.maxItems} items`, ), ), (y = !1)), e.uniqueItems === !0) ) { outer: for (let e = 0; e < t.length; e++) for (let n = e + 1; n < t.length; n++) if (p(t[e], t[n])) { (i.push( S( `uniqueItems`, `uniqueItems`, s, c + `/uniqueItems`, { i: e, j: n }, `must NOT have duplicate items`, ), ), (y = !1)); break outer; } } let a = Array.isArray(e.prefixItems) ? e.prefixItems : null; if (a) for (let e = 0; e < Math.min(a.length, t.length); e++) (this.eval(a[e], t[e], n, r, i, s + `/` + e, c + `/prefixItems/` + e, l, { props: null, items: null, }) || (y = !1), (b.items ||= new Set()), b.items.add(e)); if (e.items !== void 0) { let o = a ? a.length : 0; for (let a = o; a < t.length; a++) (this.eval(e.items, t[a], n, r, i, s + `/` + a, c + `/items`, l, { props: null, items: null, }) || (y = !1), (b.items ||= new Set()), b.items.add(a)); } if (e.contains !== void 0) { let a = []; for (let i = 0; i < t.length; i++) this.eval(e.contains, t[i], n, r, [], s + `/` + i, c + `/contains`, l, { props: null, items: null, }) && a.push(i); let o = e.minContains === void 0 ? 1 : e.minContains; if ( (a.length < o && (i.push( S( `contains`, `contains`, s, c + `/contains`, { minContains: o }, `must contain at least ${o} valid item(s)`, ), ), (y = !1)), e.maxContains !== void 0 && a.length > e.maxContains && (i.push( S( `maxContains`, `maxContains`, s, c + `/maxContains`, { limit: e.maxContains }, `must NOT contain more than ${e.maxContains} valid item(s)`, ), ), (y = !1)), a.length) ) { b.items ||= new Set(); for (let e of a) b.items.add(e); } } } if (typeof t == `object` && t && !Array.isArray(t)) { let a = Object.keys(t); if (Array.isArray(e.required)) for (let n of e.required) Object.prototype.hasOwnProperty.call(t, n) || (i.push( S( `required`, `required`, s, c + `/required`, { missingProperty: n }, `must have required property '${n}'`, ), ), (y = !1)); if ( (e.minProperties !== void 0 && a.length < e.minProperties && (i.push( S( `minProperties`, `minProperties`, s, c + `/minProperties`, { limit: e.minProperties }, `must NOT have fewer than ${e.minProperties} properties`, ), ), (y = !1)), e.maxProperties !== void 0 && a.length > e.maxProperties && (i.push( S( `maxProperties`, `maxProperties`, s, c + `/maxProperties`, { limit: e.maxProperties }, `must NOT have more than ${e.maxProperties} properties`, ), ), (y = !1)), e.dependentRequired && typeof e.dependentRequired == `object`) ) { for (let [n, r] of Object.entries(e.dependentRequired)) if (Object.prototype.hasOwnProperty.call(t, n)) for (let e of r) Object.prototype.hasOwnProperty.call(t, e) || (i.push( S( `required`, `required`, s, c + `/dependentRequired`, { missingProperty: e }, `must have required property '${e}'`, ), ), (y = !1)); } if (e.propertyNames !== void 0) for (let t of a) this.eval(e.propertyNames, t, n, r, i, s + `/` + x(t), c + `/propertyNames`, l, { props: null, items: null, }) || (y = !1); let o = e.properties && typeof e.properties == `object` ? e.properties : null, u = e.patternProperties && typeof e.patternProperties == `object` ? Object.keys(e.patternProperties) : null; for (let d of a) { let a = !1; if ( (o && Object.prototype.hasOwnProperty.call(o, d) && (this.eval(o[d], t[d], n, r, i, s + `/` + x(d), c + `/properties/` + x(d), l, { props: null, items: null, }) || (y = !1), (a = !0)), u) ) for (let o of u) this.pattern(o).test(d) && (this.eval( e.patternProperties[o], t[d], n, r, i, s + `/` + x(d), c + `/patternProperties/` + x(o), l, { props: null, items: null }, ) || (y = !1), (a = !0)); (!a && e.additionalProperties !== void 0 && (this.eval( e.additionalProperties, t[d], n, r, i, s + `/` + x(d), c + `/additionalProperties`, l, { props: null, items: null }, ) || (y = !1), (a = !0)), a && ((b.props ||= new Set()), b.props.add(d))); } if (e.dependentSchemas && typeof e.dependentSchemas == `object`) { for (let [a, o] of Object.entries(e.dependentSchemas)) if (Object.prototype.hasOwnProperty.call(t, a)) { let e = { props: null, items: null }; this.eval(o, t, n, r, i, s, c + `/dependentSchemas/` + x(a), l, e) ? v(b, e) : (y = !1); } } } if (Array.isArray(e.allOf)) for (let a = 0; a < e.allOf.length; a++) { let o = { props: null, items: null }; this.eval(e.allOf[a], t, n, r, i, s, c + `/allOf/` + a, l, o) ? v(b, o) : (y = !1); } if (Array.isArray(e.anyOf)) { let a = !1, o = []; for (let i = 0; i < e.anyOf.length; i++) { let u = { props: null, items: null }; this.eval(e.anyOf[i], t, n, r, o, s, c + `/anyOf/` + i, l, u) && ((a = !0), v(b, u)); } if (!a) { for (let e of o) i.push(e); (i.push(S(`anyOf`, `anyOf`, s, c + `/anyOf`, {}, `must match a schema in anyOf`)), (y = !1)); } } if (Array.isArray(e.oneOf)) { let a = 0, o = null, u = []; for (let i = 0; i < e.oneOf.length; i++) { let d = { props: null, items: null }; this.eval(e.oneOf[i], t, n, r, u, s, c + `/oneOf/` + i, l, d) && (a++, (o = d)); } if (a === 1) v(b, o); else { if (a === 0) for (let e of u) i.push(e); (i.push( S( `oneOf`, `oneOf`, s, c + `/oneOf`, { passingSchemas: a }, `must match exactly one schema in oneOf`, ), ), (y = !1)); } } if ( (e.not !== void 0 && this.eval(e.not, t, n, r, [], s, c + `/not`, l, { props: null, items: null }) && (i.push(S(`not`, `not`, s, c + `/not`, {}, `must NOT be valid`)), (y = !1)), e.if !== void 0) ) { let a = { props: null, items: null }; if (this.eval(e.if, t, n, r, [], s, c + `/if`, l, a)) { if ((v(b, a), e.then !== void 0)) { let a = { props: null, items: null }; this.eval(e.then, t, n, r, i, s, c + `/then`, l, a) ? v(b, a) : (y = !1); } } else if (e.else !== void 0) { let a = { props: null, items: null }; this.eval(e.else, t, n, r, i, s, c + `/else`, l, a) ? v(b, a) : (y = !1); } } if (e.unevaluatedProperties !== void 0 && typeof t == `object` && t && !Array.isArray(t)) for (let a of Object.keys(t)) (b.props && b.props.has(a)) || (this.eval( e.unevaluatedProperties, t[a], n, r, i, s + `/` + x(a), c + `/unevaluatedProperties`, l, { props: null, items: null }, ) || (y = !1), (b.props ||= new Set()), b.props.add(a)); if (e.unevaluatedItems !== void 0 && Array.isArray(t)) for (let a = 0; a < t.length; a++) (b.items && b.items.has(a)) || (this.eval( e.unevaluatedItems, t[a], n, r, i, s + `/` + a, c + `/unevaluatedItems`, l, { props: null, items: null }, ) || (y = !1), (b.items ||= new Set()), b.items.add(a)); return (y && v(u, b), y); } }; function b() { return { props: null, items: null }; } function x(e) { return String(e).replace(/~/g, `~0`).replace(/\//g, `~1`); } function S(e, t, n, r, i, a) { return { keyword: t, instancePath: n, schemaPath: r, params: i, message: a }; } function C(e, t) { return new y(e, t); } t.exports = { createInterpreter: C }; }), x = o((e, t) => { function n(e, t, n) { let r = n ?? 1 / 0; if (e === t) return 0; if (Math.abs(e.length - t.length) > r) return 1 / 0; if (e.length === 0) return t.length; if (t.length === 0) return e.length; let i = Array(t.length + 1), a = Array(t.length + 1); for (let e = 0; e <= t.length; e++) i[e] = e; for (let n = 1; n <= e.length; n++) { a[0] = n; let o = n; for (let r = 1; r <= t.length; r++) { let s = e[n - 1] === t[r - 1] ? 0 : 1; ((a[r] = Math.min(a[r - 1] + 1, i[r] + 1, i[r - 1] + s)), a[r] < o && (o = a[r])); } if (o > r) return 1 / 0; [i, a] = [a, i]; } return i[t.length]; } t.exports = { levenshtein: n }; }), S = o((e, t) => { let { levenshtein: n } = x(), r = { email: (e) => { if (typeof e != `string`) return null; if (!e.includes(`@`)) return `missing '@' and domain part`; if (e.split(`@`).length > 2) return `multiple '@' characters`; let [, t] = e.split(`@`); return !t || !t.includes(`.`) ? `domain part missing dot` : null; }, date: (e) => { if (typeof e != `string`) return null; let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e); if (!t) return `expected YYYY-MM-DD layout`; let n = +t[2]; if (n < 1 || n > 12) return `month must be 01-12`; let r = +t[3]; return r < 1 || r > 31 ? `day must be 01-31` : null; }, uuid: (e) => typeof e == `string` ? /^[0-9a-fA-F-]+$/.test(e) ? `expected 8-4-4-4-12 hex layout` : `expected hex digits and dashes` : null, ipv4: (e) => (typeof e == `string` ? `expected four 0-255 octets separated by dots` : null), }; function i(e, t) { if (typeof e != `string` || !Array.isArray(t) || t.length === 0 || t.length > 30) return null; let r = null, i = 1 / 0, a = !1; for (let o of t) { if (typeof o != `string`) continue; let t = n(e, o, 2); t < i ? ((r = o), (i = t), (a = !1)) : t === i && (a = !0); } return r && i <= 2 && !a ? { text: `did you mean \`${r}\`?`, kind: `typo` } : null; } function a(e, t) { if (!e || !Array.isArray(t)) return null; for (let r of t) { if (typeof r != `string`) continue; let t = n(e, r, 2); if (t <= 2 && t > 0) return { text: `did you mean \`${e}\` instead of \`${r}\`?`, kind: `similar-key` }; } return null; } function o(e, t) { let n = r[e]; if (!n) return null; let i = t; if (typeof i == `string` && i.startsWith(`"`) && i.endsWith(`"`)) try { i = JSON.parse(i); } catch {} let a = n(i); return a ? { text: a, kind: `format` } : null; } function s(e, t) { if (typeof t != `string` || !t.startsWith(`"`) || !t.endsWith(`"`)) return null; let n; try { n = JSON.parse(t); } catch { return null; } return typeof n == `string` ? e === `integer` && /^-?\d+$/.test(n) ? { text: "value would coerce; enable `coerceTypes` or pass an integer", kind: `coercion`, } : e === `number` && /^-?\d+(\.\d+)?$/.test(n) ? { text: "value would coerce; enable `coerceTypes` or pass a number", kind: `coercion`, } : e === `boolean` && (n === `true` || n === `false`) ? { text: "value would coerce; enable `coerceTypes` or pass a boolean", kind: `coercion`, } : null : null; } function c(e, t) { if (e.keyword === `enum`) return i(l(e.received), e.params && e.params.allowedValues); if (e.keyword === `required`) { let n = e.params && e.params.missingProperty, r = e.path || ``; r.endsWith(`/` + n) && (r = r.slice(0, -n.length - 1)); let i = u(t, r); return i && typeof i == `object` ? a(n, Object.keys(i)) : null; } return e.keyword === `format` ? o(e.params && e.params.format, e.received) : e.keyword === `type` ? s(e.params && e.params.type, e.received) : null; } function l(e) { if (typeof e != `string`) return e; if (e.startsWith(`"`) && e.endsWith(`"`)) try { return JSON.parse(e); } catch { return e; } return e; } function u(e, t) { if (!t) return e; let n = t .replace(/^\//, ``) .split(`/`) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), r = e; for (let e of n) { if (r == null) return; r = r[e]; } return r; } t.exports = { suggestFor: c, suggestEnumTypo: i, suggestRequiredTypo: a, suggestFormat: o, suggestCoercion: s, }; }), C = o((e, t) => { let { CODES: n, codeFor: r } = d(), { suggestFor: i } = S(); function a(e) { if (e === void 0) return `undefined`; if (e === null) return `null`; let t = typeof e; if (t === `string`) { let t = JSON.stringify(e); return t.length > 60 ? t.slice(0, 57) + `..."` : t; } if (t === `number` || t === `boolean`) return String(e); if (Array.isArray(e)) return `[array, ${e.length} items]`; if (t === `object`) try { let t = JSON.stringify(e); return t.length <= 60 ? t : `[object, ~${(t.length / 1024).toFixed(1)}KB]`; } catch { return `[object, unserializable]`; } return `[${t}]`; } function o(e) { switch (e.keyword) { case `type`: return e.params && e.params.type ? String(e.params.type) : void 0; case `minLength`: return e.params && e.params.limit != null ? `string with ≥${e.params.limit} chars` : void 0; case `maxLength`: return e.params && e.params.limit != null ? `string with ≤${e.params.limit} chars` : void 0; case `minimum`: return e.params && e.params.limit != null ? `≥${e.params.limit}` : void 0; case `maximum`: return e.params && e.params.limit != null ? `≤${e.params.limit}` : void 0; case `format`: return e.params && e.params.format ? `format '${e.params.format}'` : void 0; case `enum`: return e.params && e.params.allowedValues ? `one of [${e.params.allowedValues.map(a).join(`, `)}]` : void 0; case `const`: return e.params && `allowedValue` in e.params ? a(e.params.allowedValue) : void 0; case `required`: return e.params && e.params.missingProperty ? `property '${e.params.missingProperty}'` : void 0; default: return; } } function s(e, t) { if (!t && t !== 0 && t !== !1) return; let n = e.instancePath || e.path || ``; if (!n) return a(t); let r = n .replace(/^\//, ``) .split(`/`) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), i = t; for (let e of r) { if (i == null) return; i = i[e]; } return a(i); } function c(e, t) { let a = t && t.data, c = t && t.positions, l = e.keyword, u = e.params && e.params.format, d = e.code || r(l, u) || `ATA9001`, f = n[d], p = e.instancePath == null ? e.path || `` : e.instancePath, m = { code: d, message: e.message || (f && f.headline) || `validation failed`, keyword: l, path: p, expected: o(e), received: a === void 0 ? void 0 : s(e, a), schemaPath: e.schemaPath, docUrl: `https://ata-validator.com/e/` + d, instancePath: p, dataPath: p, params: e.params, parentSchema: e.parentSchema, }; if ((e.branchErrors && (m.branchErrors = e.branchErrors), c && c[p])) { let e = c[p]; m.dataFrame = { byteOffset: e.byteOffset, length: e.length, line: e.line, col: e.col, text: e.text, }; } if (t && t.schemaPositions && e.schemaPath) { let n = e.schemaPath, r = n.startsWith(`#`) ? n.slice(1) : n, i = t.schemaPositions[r] || t.schemaPositions[r + `#key`]; i && (m.schemaSource = { file: t.schemaFile, line: i.line, col: i.col, text: i.text }); } let h = i(m, t && t.data); return (h && (m.suggestion = h), m); } t.exports = { enrich: c, reprValue: a, expectedFor: o }; }), w = o((e, t) => { function n(e, t) { if (!t || typeof t != `string` || t[0] !== `#`) return; let n = t.slice(1); if (!n || n === `/`) return e; let r = n .split(`/`) .filter(Boolean) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), i = e; for (let e = 0; e < r.length - 1; e++) { if (typeof i != `object` || !i) return; i = i[r[e]]; } return i; } function r(e, t) { if (e == null) return; if (typeof e == `string`) return e; if (typeof e != `object`) return; let n = t.keyword; if (n === `required`) { let n = e.required; if (typeof n == `string`) return n; if (n && typeof n == `object`) { let e = t.params && t.params.missingProperty; if (e != null && typeof n[e] == `string`) return n[e]; } } if (n != null && typeof e[n] == `string`) return e[n]; if (typeof e._ == `string`) return e._; } function i(e) { return typeof e == `string` && e.indexOf(`"errorMessage"`) !== -1; } function a(e, t) { if (!e || !e.length) return e; let i = !1, a = Array(e.length); for (let o = 0; o < e.length; o++) { let s = e[o]; if (((a[o] = s), !s || typeof s.schemaPath != `string`)) continue; let c = n(t, s.schemaPath); if (!c || typeof c != `object`) continue; let l = r(c.errorMessage, s); l != null && ((a[o] = Object.assign({}, s, { message: l })), (i = !0)); } return i ? a : e; } t.exports = { schemaHasErrorMessages: i, applyErrorMessages: a, resolveOwner: n, pickMessage: r, }; }), T = o((e, t) => { let n = Symbol.for(`ata.t.refine`); function r(e) { if (!e || typeof e != `object`) return null; let t = e[n]; return Array.isArray(t) && t.length ? t : null; } function i(e, t, r) { if (typeof t != `function`) throw TypeError(`t.refine(schema, check, opts?) — check must be a function`); let i = e && Array.isArray(e[n]) ? e[n] : [], a = r || {}, o = { check: t, message: a.message, path: a.path || `` }; return Object.assign({}, e, { [n]: i.concat(o) }); } function a(e, t) { return { keyword: `refine`, instancePath: e.path || ``, path: e.path || ``, schemaPath: ``, params: {}, message: t ?? (e.message || `value failed refinement`), }; } async function o(e, t) { let n = []; return ( await Promise.all( e.map(async (e) => { let r; try { r = await e.check(t); } catch (t) { n.push(a(e, e.message || (t && t.message) || `refinement threw`)); return; } r || n.push(a(e)); }), ), n ); } t.exports = { REFINE: n, getRefinements: r, attach: i, runRefinements: o }; }), E = o((e, t) => { t.exports = `1.2.2`; }), D = o((e, t) => { t.exports = `'use strict' // Linear-time regex engine for JSON Schema \`pattern\`, used in place of JS RegExp // so an adversarial input cannot trigger catastrophic backtracking (ReDoS). // // It is a Pike VM: the pattern compiles to a small instruction program, and the // VM simulates all NFA threads in lockstep over the input, deduping by program // counter. Runtime is O(input * program), with no backtracking. // // Supported (the RE2 subset, which is what ata's native path also accepts): // literals, ., character classes, \\d \\w \\s \\D \\W \\S, anchors ^ $, quantifiers // * + ? {n} {n,} {n,m} (greedy or lazy, same language for a boolean test), // groups ( ) (?: ), alternation |. Backreferences and lookaround are not // supported by linear engines; compileSafe throws on them so the caller can // decide (ata's codegen rejects such schemas rather than risk a hang). const WS = [[9, 13], [32, 32], [160, 160]] const DIGIT = [[48, 57]] const WORD = [[48, 57], [65, 90], [97, 122], [95, 95]] function parse (src) { let i = 0 const len = src.length const peek = () => src[i] const eof = () => i >= len function parseAlt () { const opts = [parseConcat()] while (!eof() && peek() === '|') { i++; opts.push(parseConcat()) } return opts.length === 1 ? opts[0] : { t: 'alt', opts } } function parseConcat () { const parts = [] while (!eof() && peek() !== '|' && peek() !== ')') parts.push(parseRepeat()) if (parts.length === 0) return { t: 'empty' } return parts.length === 1 ? parts[0] : { t: 'concat', parts } } function parseRepeat () { let node = parseAtom() while (!eof()) { const ch = peek() if (ch === '*') { i++; node = { t: 'star', child: node } } else if (ch === '+') { i++; node = { t: 'plus', child: node } } else if (ch === '?') { i++; node = { t: 'quest', child: node } } else if (ch === '{') { const saved = i const q = tryQuantifier() if (!q) { i = saved; break } node = { t: 'repeat', child: node, min: q.min, max: q.max } } else break // a trailing ? makes the quantifier lazy; same language for a boolean test if (!eof() && peek() === '?') i++ } return node } function tryQuantifier () { // assumes current char is '{' i++ let min = '' while (!eof() && /[0-9]/.test(peek())) { min += peek(); i++ } if (min === '') return null let max if (peek() === '}') { i++; return { min: +min, max: +min } } if (peek() === ',') { i++ let m = '' while (!eof() && /[0-9]/.test(peek())) { m += peek(); i++ } if (peek() !== '}') return null i++ max = m === '' ? Infinity : +m return { min: +min, max } } return null } function parseAtom () { const ch = peek() if (ch === '(') { i++ if (src[i] === '?') { if (src[i + 1] === ':') { i += 2 } else throw new Error('unsupported group (lookaround/named) in pattern') } const child = parseAlt() if (peek() !== ')') throw new Error('unbalanced ( in pattern') i++ return { t: 'group', child } } if (ch === '[') return parseClass() if (ch === '.') { i++; return { t: 'any' } } if (ch === '^') { i++; return { t: 'bol' } } if (ch === '$') { i++; return { t: 'eol' } } if (ch === '\\\\') return parseEscape(false) if (ch === ')' || ch === '|') return { t: 'empty' } i++ return { t: 'char', c: ch.charCodeAt(0) } } function parseClass () { i++ // [ let neg = false if (peek() === '^') { neg = true; i++ } const ranges = [] while (!eof() && peek() !== ']') { let lo if (peek() === '\\\\') { const esc = parseEscape(true) if (esc.t === 'classpart') { for (const r of esc.ranges) ranges.push(r); continue } lo = esc.c } else { lo = peek().charCodeAt(0); i++ } if (peek() === '-' && src[i + 1] !== ']' && i + 1 < len) { i++ // - let hi if (peek() === '\\\\') { const e = parseEscape(true); hi = e.c } else { hi = peek().charCodeAt(0); i++ } ranges.push([lo, hi]) } else { ranges.push([lo, lo]) } } if (peek() !== ']') throw new Error('unbalanced [ in pattern') i++ return { t: 'class', neg, ranges } } function parseEscape (inClass) { i++ // backslash if (eof()) throw new Error('trailing backslash in pattern') const ch = peek(); i++ switch (ch) { case 'd': return inClass ? { t: 'classpart', ranges: DIGIT } : { t: 'class', neg: false, ranges: DIGIT } case 'w': return inClass ? { t: 'classpart', ranges: WORD } : { t: 'class', neg: false, ranges: WORD } case 's': return inClass ? { t: 'classpart', ranges: WS } : { t: 'class', neg: false, ranges: WS } case 'D': if (inClass) throw new Error('\\\\D inside a class is not supported'); return { t: 'class', neg: true, ranges: DIGIT } case 'W': if (inClass) throw new Error('\\\\W inside a class is not supported'); return { t: 'class', neg: true, ranges: WORD } case 'S': if (inClass) throw new Error('\\\\S inside a class is not supported'); return { t: 'class', neg: true, ranges: WS } case 'n': return { t: 'char', c: 10 } case 'r': return { t: 'char', c: 13 } case 't': return { t: 'char', c: 9 } case 'f': return { t: 'char', c: 12 } case 'v': return { t: 'char', c: 11 } case '0': return { t: 'char', c: 0 } case 'x': { const h = src.slice(i, i + 2); i += 2; return { t: 'char', c: parseInt(h, 16) } } case 'u': { const h = src.slice(i, i + 4); i += 4; return { t: 'char', c: parseInt(h, 16) } } case 'b': if (inClass) return { t: 'char', c: 8 }; throw new Error('\\\\b word boundary is not supported') default: if (/[1-9]/.test(ch)) throw new Error('backreferences are not supported in pattern') return { t: 'char', c: ch.charCodeAt(0) } } } const ast = parseAlt() if (!eof()) throw new Error('unexpected "' + peek() + '" in pattern') return ast } function compileProg (ast) { const prog = [] const emit = (op, extra) => { const idx = prog.length; prog.push(Object.assign({ op }, extra)); return idx } function rec (n) { switch (n.t) { case 'empty': break case 'char': emit('char', { c: n.c }); break case 'any': emit('any'); break case 'class': emit('class', { neg: n.neg, ranges: n.ranges }); break case 'bol': emit('bol'); break case 'eol': emit('eol'); break case 'group': rec(n.child); break case 'concat': for (const p of n.parts) rec(p); break case 'alt': { const jmps = [] for (let k = 0; k < n.opts.length; k++) { if (k < n.opts.length - 1) { const sp = emit('split', { x: 0, y: 0 }) prog[sp].x = prog.length rec(n.opts[k]) jmps.push(emit('jmp', { x: 0 })) prog[sp].y = prog.length } else { rec(n.opts[k]) } } for (const j of jmps) prog[j].x = prog.length break } case 'star': { const sp = emit('split', { x: 0, y: 0 }) prog[sp].x = prog.length rec(n.child) emit('jmp', { x: sp }) prog[sp].y = prog.length break } case 'plus': { const start = prog.length rec(n.child) const sp = emit('split', { x: start, y: 0 }) prog[sp].y = prog.length break } case 'quest': { const sp = emit('split', { x: 0, y: 0 }) prog[sp].x = prog.length rec(n.child) prog[sp].y = prog.length break } case 'repeat': { for (let k = 0; k < n.min; k++) rec(n.child) if (n.max === Infinity) { if (n.min === 0) rec({ t: 'star', child: n.child }) else rec({ t: 'star', child: n.child }) } else { for (let k = 0; k < n.max - n.min; k++) rec({ t: 'quest', child: n.child }) } break } } } rec(ast) emit('match') return prog } function matchClass (instr, c) { let inside = false const r = instr.ranges for (let k = 0; k < r.length; k++) { if (c >= r[k][0] && c <= r[k][1]) { inside = true; break } } return instr.neg ? !inside : inside } function makeRunner (prog) { const n = prog.length const lastGen = new Int32Array(n).fill(-1) let gen = 0 const stack = [] function addThread (list, pc, pos, len) { stack.length = 0 stack.push(pc) while (stack.length) { const p = stack.pop() if (lastGen[p] === gen) continue lastGen[p] = gen const I = prog[p] switch (I.op) { case 'jmp': stack.push(I.x); break case 'split': stack.push(I.y); stack.push(I.x); break case 'bol': if (pos === 0) stack.push(p + 1); break case 'eol': if (pos === len) stack.push(p + 1); break default: list.push(p) } } } return function test (s) { const len = s.length let clist = [] let nlist = [] gen++ addThread(clist, 0, 0, len) for (let pos = 0; pos <= len; pos++) { const c = pos < len ? s.charCodeAt(pos) : -1 gen++ nlist.length = 0 for (let k = 0; k < clist.length; k++) { const pc = clist[k] const I = prog[pc] if (I.op === 'match') return true else if (I.op === 'char') { if (c === I.c) addThread(nlist, pc + 1, pos + 1, len) } else if (I.op === 'any') { if (c !== -1 && c !== 10) addThread(nlist, pc + 1, pos + 1, len) } else if (I.op === 'class') { if (c !== -1 && matchClass(I, c)) addThread(nlist, pc + 1, pos + 1, len) } } if (pos < len) addThread(nlist, 0, pos + 1, len) const tmp = clist; clist = nlist; nlist = tmp } return false } } function compileSafe (pattern) { const prog = compileProg(parse(pattern)) const runner = makeRunner(prog) // \`__ataSafe\` brands the result so the standalone serializer can tell a safe // matcher apart from a RegExp and emit \`__ataSafeRe(source)\` instead. return { test: runner, source: pattern, __ataSafe: true } } // True when the linear engine can represent \`src\`. Used by the codegen to decide // between the safe matcher and a JS RegExp fallback for patterns outside the // supported (RE2) subset (backreferences, lookaround, etc.). function patternIsSafe (src) { try { compileSafe(src); return true } catch { return false } } module.exports = { compileSafe, patternIsSafe } `; }), O = o((e, t) => { let { compileToJSCodegenWithErrors: n } = p(), r = D(), i = `function _cpLen(s) { const len = s.length; for (let i = 0; i < len; i++) { if (s.charCodeAt(i) >= 0xD800 && s.charCodeAt(i) <= 0xDBFF) { let n = 0; for (const _ of s) n++; return n; } } return len; }`, a = null; function o() { return ( a === null && (a = r .replace(/^'use strict'\s*\n/, ``) .replace( /\nmodule\.exports[^\n]*\n?/, ` `, ) .trimEnd() + ` const __ataSafeRe = compileSafe;`), a ); } function s(...e) { return e.some((e) => e && e._usesSafeRe) ? o() + ` ` : ``; } function c(e) { e._ensureCompiled(); let t = e._jsFn; if (!t || !t._source) return null; let r = t._source, a = t._hybridSource || ``, o = t._preambleSource || ``, c = n(typeof e._schemaObj == `object` ? e._schemaObj : {}), l = c && c._errSource ? c._errSource : ``; return `// Auto-generated by ata-validator — do not edit 'use strict'; ${i} ${s(t, c)}${o} const boolFn = function(d) { ${r} }; const hybridFactory = function(R, E) { return function(d) { ${a} }; }; ${l ? `const errFn = function(d, _all) {\n ${l}\n};` : `const errFn = null;`} module.exports = { boolFn, hybridFactory, errFn }; `; } function l(e, t) { e._ensureCompiled(); let r = e._jsFn; if (!r || !r._source) return null; let a = (t && t.format) || `esm`, o = !!(t && t.abortEarly), c = !!(t && t.source), l = t && t.sourceMap ? t.sourceMap : null, u = t && t.schemaFile ? t.schemaFile : null, d = r._source, f = ``, p = null; if (!o) { p = n( typeof e._schemaObj == `object` ? e._schemaObj : {}, null, e._userFormats, c && l && u ? { sourceMap: l, schemaFile: u } : null, ); let t = p && p._errSource ? p._errSource : ``; t && (f = `const errFn = function(d, _all) {\n ${t}\n};\n`); } let m = c && u ? `const __ATA_SCHEMA_SOURCE__ = ${JSON.stringify({ file: u })};\n` : ``, h = ``; if (r._closures && r._closures.length > 0) { let e = []; for (let { name: t, val: n } of r._closures) { if (Array.isArray(n)) { e.push(`const ${t} = ${JSON.stringify(n)};`); continue; } if (n && n.__ataSafe) e.push(`const ${t} = __ataSafeRe(${JSON.stringify(n.source)});`); else if (n instanceof RegExp) { let r = n.flags; e.push( `const ${t} = new RegExp(${JSON.stringify(n.source)}${r ? `, ` + JSON.stringify(r) : ``});`, ); } else if (n instanceof Set) e.push(`const ${t} = new Set(${JSON.stringify([...n])});`); else if (typeof n == `function`) { let r = n.toString(), i = r.match(/^function[^(]*\([^)]*\)\s*\{([\s\S]*)\}$/), a = i ? i[1].trim() : r; e.push(`const ${t} = function(_ppv) { ${a} };`); } } e.length && (h = e.join(` `) + ` `); } let g = r._preambleSource ? r._preambleSource + ` ` : ``, _ = ``; r._formatClosures && r._formatClosures.length > 0 && (_ = r._formatClosures.map(({ name: e, fn: t }) => `const ${e} = ${t.toString()};`).join(` `) + ` `); let v = f ? `return _fn(data) ? VALID : { valid: false, errors: errFn(data, true).errors }` : `return _fn(data) ? VALID : ABORT`, y = a === `esm` ? `export { validate, isValid }; export default { validate, isValid }; ` : `module.exports = { validate, isValid }; module.exports.default = module.exports; `; return `// Auto-generated by ata-validator — do not edit. // Schema is embedded; runtime has zero dependency on ata-validator. 'use strict'; ${i} ${s(r, p)}${m}const VALID = Object.freeze({ valid: true, errors: Object.freeze([]) }); const ABORT = Object.freeze({ valid: false, errors: Object.freeze([Object.freeze({ code: 'ATA9000', message: 'validation failed', keyword: '__abort_early__', path: '', })]), }); ${h}${g}${_}const _fn = function(d) { ${d} }; ${f}function isValid(data) { return _fn(data); } function validate(data) { ${v}; } ${y}`; } function u(e, t, n) { return ( `'use strict'; module.exports = [ ` + t.map((t) => { let r = c(new e(t, n)); return r ? `(function(){` + r.replace(`'use strict';`, ``).replace(`module.exports = `, `return `) + `})()` : `null`; }).join(`, `) + ` ]; ` ); } function d(e, t, r) { let i = t.some((e) => e && typeof e == `object` && e.$id) ? { ...(r || {}), schemas: t } : r || {}, a = (r && r.format) || `cjs`, s = `Object.freeze({valid:true,errors:Object.freeze([])})`, c = !1, l = t.map((t) => { let a = new e(t, i); a._ensureCompiled(); let o = a._jsFn; if (!o || !o._hybridSource) return `null`; let s = n(typeof t == `string` ? JSON.parse(t) : t, a._schemaMap, a._userFormats); (o._usesSafeRe || (s && s._usesSafeRe)) && (c = !0); let l = s && s._errSource ? s._errSource : `return{valid:false,errors:[{code:'error',path:'',message:'validation failed'}]}`, u = ``; if ( (o._formatClosures && (u = o._formatClosures.map(({ name: e, fn: t }) => `var ${e}=${t.toString()};`).join(` `)), o._preambleSource && (u = u ? `${u}\n${o._preambleSource}` : o._preambleSource), r && r.verbose) ) { let e = JSON.stringify(typeof t == `string` ? JSON.parse(t) : t); return `(function(R){${u}var _S=${e};function _PS(p){if(!p||p[0]!=='#')return undefined;var s=p.slice(1);if(!s)return _S;var ps=s.split('/').filter(Boolean).map(function(x){return x.replace(/~1/g,'/').replace(/~0/g,'~')});var t=_S;for(var i=0;i<ps.length-1;i++){if(t==null||typeof t!=='object')return undefined;t=t[ps[i]]}return t}var E=function(d){var _all=true;${l}};var _v=function(d){${o._hybridSource}};return function(d){var r=_v(d);if(r&&r.valid===false&&r.errors){var es=[];for(var i=0;i<r.errors.length;i++){var e=r.errors[i];es.push(Object.assign({},e,{parentSchema:_PS(e.schemaPath)}))}return{valid:false,errors:es}}return r}})(R)`; } return `(function(R){${u}var E=function(d){var _all=true;${l}};return function(d){${o._hybridSource}}})(R)`; }), u = `[${l.join(`,`)}]`, d = c ? o() + ` ` : ``; return a === `esm` ? `// Auto-generated by ata-validator — do not edit\n${d}const R=${s};\nconst validators=${u};\nexport default validators;\nexport { validators };\n` : `'use strict';\n${d}var R=${s};\nmodule.exports=[${l.join(`,`)}];\n`; } function f(e, t, r) { let i = t.some((e) => e && typeof e == `object` && e.$id) ? { ...(r || {}), schemas: t } : r || {}, a = (r && r.format) || `cjs`, s = !1, c = t.map((t) => { let r = new e(t, i); r._ensureCompiled(); let a = r._jsFn; if (!a || !a._hybridSource) return null; let o = n(typeof t == `string` ? JSON.parse(t) : t, r._schemaMap, r._userFormats); return ( (a._usesSafeRe || (o && o._usesSafeRe)) && (s = !0), { hybrid: a._preambleSource ? `${a._preambleSource}\n${a._hybridSource}` : a._hybridSource, err: o && o._errSource ? o._errSource : null, fmt: a._formatClosures || null, } ); }), l = new Map(), u = [], d = new Map(), f = [], p = c.map((e) => { if (!e) return [-1, -1]; let t = l.get(e.hybrid); t === void 0 && ((t = u.length), u.push(e.hybrid), l.set(e.hybrid, t)); let n = -1; return ( e.err && ((n = d.get(e.err)), n === void 0 && ((n = f.length), f.push(e.err), d.set(e.err, n))), [t, n] ); }), m = a === `esm`, h = m ? `// Auto-generated by ata-validator — do not edit ` : `'use strict'; `; s && (h += o() + ` `); let g = m ? `const` : `var`; h += `${g} R=Object.freeze({valid:true,errors:Object.freeze([])});\n`; let _ = new Set(); for (let e of c) if (!(!e || !e.fmt)) for (let { name: t, fn: n } of e.fmt) _.has(t) || (_.add(t), (h += `${g} ${t}=${n.toString()};\n`)); ((h += `${g} H=[\n`), (h += u.map((e) => `function(R,E){return function(d){${e}}}`).join(`, `)), (h += ` ]; `), (h += `${g} EF=[\n`), (h += f.map((e) => `function(d){var _all=true;${e}}`).join(`, `)), (h += ` ]; `)); let v = p .map(([e, t]) => e < 0 ? `null` : t >= 0 ? `H[${e}](R,EF[${t}])` : `H[${e}](R,function(){return{valid:false,errors:[]}})`, ) .join(`,`); return ( m ? (h += `const validators=[${v}];\nexport default validators;\nexport { validators };\n`) : (h += `module.exports=[${v}];\n`), h ); } function m(e, t, n, r) { return n.map((n, i) => (t[i] ? e.fromStandalone(t[i], n, r) : new e(n, r))); } t.exports = { toStandalone: c, toStandaloneModule: l, bundle: u, bundleStandalone: d, bundleCompact: f, loadBundle: m, }; }), k = o((e, t) => { function n(e, t, o = 0) { if (o > 32 || e === !0) return `unknown`; if (e === !1) return `never`; if (typeof e != `object` || !e) return `unknown`; if (e.$ref) { let n = e.$ref.match(/^#\/(?:\$defs|definitions)\/(.+)$/); return n && t && t[n[1]] ? a(n[1]) : `unknown`; } if (e.const !== void 0) return i(e.const); if (Array.isArray(e.enum)) return e.enum.map(i).join(` | `) || `never`; if (Array.isArray(e.oneOf)) return e.oneOf.map((e) => n(e, t, o + 1)).join(` | `) || `unknown`; if (Array.isArray(e.anyOf)) return e.anyOf.map((e) => n(e, t, o + 1)).join(` | `) || `unknown`; let s = e.type; if (Array.isArray(s)) return s.map((r) => n({ ...e, type: r }, t, o + 1)).join(` | `); if (s === `string`) return `string`; if (s === `number` || s === `integer`) return `number`; if (s === `boolean`) return `boolean`; if (s === `null`) return `null`; if (s === `array`) { let r = e.items, i = Array.isArray(e.prefixItems) ? e.prefixItems : null; if (i) { let a = i.map((e) => n(e, t, o + 1)), s = typeof e.minItems == `number` ? e.minItems : 0, c = a.map((e, t) => (t < s ? e : `${e}?`)); if (r === !1) return `[${c.join(`, `)}]`; if (r === void 0 || r === !0) return `[${c.join(`, `)}, ...unknown[]]`; if (typeof r == `object` && r) { let e = n(r, t, o + 1), i = e.includes(` | `) ? `(${e})` : e; return `[${c.join(`, `)}, ...${i}[]]`; } } if (r === !1) return `never[]`; if (r === void 0 || r === !0) return `unknown[]`; let a = n(r, t, o + 1); return a.includes(` | `) ? `Array<${a}>` : `${a}[]`; } return s === `object` || (!s && e.properties) ? r(e, t, o + 1) : `unknown`; } function r(e, t, r) { let i = e.properties || {}, a = new Set(e.required || []), s = Object.keys(i); if (s.length === 0) { if (e.additionalProperties === !1) return `Record<string, never>`; let i = e.additionalProperties; return i && typeof i == `object` ? `Record<string, ${n(i, t, r + 1)}>` : `Record<string, unknown>`; } let c = s.map((e) => { let s = n(i[e], t, r + 1), c = a.has(e) ? `` : `?`, l = /^[A-Za-z_$][\w$]*$/.test(e) ? e : JSON.stringify(e); return `${o(i[e], ` `)} ${l}${c}: ${s};`; }), l = e.additionalProperties; if (l && typeof l == `object`) { let e = new Set(); e.add(n(l, t, r + 1)); let o = !1; for (let c of s) (e.add(n(i[c], t, r + 1)), a.has(c) || (o = !0)); o && e.add(`undefined`); let u = e.has(`unknown`) ? `unknown` : Array.from(e).join(` | `); c.push(` [key: string]: ${u};`); } else l !== !1 && c.push(` [key: string]: unknown;`); return `{\n${c.join(` `)}\n}`; } function i(e) { return e === null ? `null` : typeof e == `string` ? JSON.stringify(e) : typeof e == `number` || typeof e == `boolean` ? String(e) : `unknown`; } function a(e) { let t = String(e).replace(/[^A-Za-z0-9_]/g, `_`); return t === `` ? `_Anon` : /^[0-9]/.test(t) ? `_${t}` : t.charAt(0).toUpperCase() + t.slice(1); } function o(e, t) { if (!e || typeof e != `object`) return ``; let n = ``; typeof e.description == `string` && e.description.length > 0 && (n = e.description.replace(/\*\//g, `* /`)); let r = []; for (let t of [ `minLength`, `maxLength`, `minItems`, `maxItems`, `minProperties`, `maxProperties`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`, ]) typeof e[t] == `number` && r.push(`@${t} ${e[t]}`); if ( (typeof e.pattern == `string` && r.push(`@pattern ${e.pattern}`), typeof e.format == `string` && r.push(`@format ${e.format}`), e.uniqueItems === !0 && r.push(`@uniqueItems`), e.deprecated === !0 && r.push(`@deprecated`), e.default !== void 0) ) try { r.push(`@default ${JSON.stringify(e.default)}`); } catch {} if (Array.isArray(e.examples) && e.examples.length > 0) try { r.push(`@example ${JSON.stringify(e.examples[0])}`); } catch {} if (n === `` && r.length === 0) return ``; if (n !== `` && r.length === 0) return `${t}/** ${n} */\n`; let i = [`${t}/**`]; (n !== `` && i.push(`${t} * ${n}`), n !== `` && r.length > 0 && i.push(`${t} *`)); for (let e of r) i.push(`${t} * ${e}`); return ( i.push(`${t} */`), i.join(` `) + ` ` ); } function s(e, t) { let r = a((t || {}).name || `Data`), i = e && (e.$defs || e.definitions), s = []; if (i && typeof i == `object`) for (let [e, t] of Object.entries(i)) { let r = n(t, i, 0); s.push(`export type ${a(e)} = ${r};`); } let c = n(e, i, 0), l = o(e, ``), u = c.startsWith(`{`) && c.endsWith(`}`) && !c.includes(` | `) ? `${l}export interface ${r} ${c}` : `${l}export type ${r} = ${c};`; return `// Auto-generated by ata-validator — do not edit. ${ s.length ? s.join(` `) + ` ` : `` }${u} export interface ValidationError { keyword?: string; instancePath?: string; schemaPath?: string; params?: Record<string, unknown>; message?: string; } export interface ValidResult { valid: true; errors: readonly never[]; } export interface InvalidResult { valid: false; errors: readonly ValidationError[]; } export type Result = ValidResult | InvalidResult; export declare function isValid(data: unknown): data is ${r}; export declare function validate(data: unknown): Result; declare const _default: { validate: typeof validate; isValid: typeof isValid }; export default _default; `; } t.exports = { toTypeScript: s }; }), A = o((e, t) => { let n = { reset: `\x1B[0m`, bold: `\x1B[1m`, dim: `\x1B[2m`, red: `\x1B[31m`, yellow: `\x1B[33m`, cyan: `\x1B[36m`, }; function r(e) { if (e === `never`) return !1; if (e === `always`) return !0; if (process.env.NO_COLOR != null && process.env.NO_COLOR !== ``) return !1; let t = process.env.FORCE_COLOR; return ( t === `1` || t === `2` || t === `3` || t === `true` || !!(process.stdout && process.stdout.isTTY) ); } function i(e, t, r) { return e ? t + r + n.reset : r; } function a(e) { if (!e || e === `/`) return `body`; let t = e .replace(/^\//, ``) .split(`/`) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), n = `body`; for (let e of t) /^[0-9]+$/.test(e) ? (n += `[` + e + `]`) : /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e) ? (n += `.` + e) : (n += `[` + JSON.stringify(e) + `]`); return n; } function o(e, t) { if (!e) return e; let n = t || process.cwd(); return e.startsWith(n + `/`) ? e.slice(n.length + 1) : e; } function s(e, t) { return !e || e.length <= t ? e : e.slice(0, t - 1) + `…`; } function c() { let e = process.stdout && process.stdout.columns; return typeof e == `number` && e > 0 ? e : 100; } t.exports = { ANSI: n, resolveColor: r, color: i, pathToDotted: a, trimCwd: o, truncateLine: s, terminalWidth: c, }; }), j = o((e, t) => { let { color: n, ANSI: r, resolveColor: i, trimCwd: a, truncateLine: o, terminalWidth: s } = A(); function c(e, t, n) { let r = ` `.repeat(n), i = ` `.repeat(Math.max(0, e - 1)), a = `^`.repeat(Math.max(1, t || 1)); return r + `| ` + i + a; } function l(e, t, i) { let l = [], d = i.cwd, f = s(), p = `${e.message}`; if ((l.push(n(t, r.red + r.bold, `error[${e.code}]: `) + p), e.schemaSource)) { let i = a(e.schemaSource.file, d); (l.push(` --> ${n(t, r.cyan, `${i}:${e.schemaSource.line}:${e.schemaSource.col}`)}`), l.push(` |`)); let s = String(e.schemaSource.line).padStart(2, ` `), u = o(e.schemaSource.text, f - 8); l.push(` ${s} | ${u}`); let p = e.expected ? ` ` + n(t, r.dim, `expected ${e.expected}`) : ``; (l.push(c(e.schemaSource.col, 1, 3) + p), l.push(` |`)); } if (e.dataFrame) { (l.push(` --> ${n(t, r.dim, `input, byte ${e.dataFrame.byteOffset}`)}`), l.push(` |`)); let i = String(e.dataFrame.line).padStart(2, ` `), a = o(e.dataFrame.text, f - 8); l.push(` ${i} | ${a}`); let s = e.received == null ? `` : ` ` + n(t, r.dim, `got ${e.received}`); (l.push(c(e.dataFrame.col, e.dataFrame.length, 3) + s), l.push(` |`)); } if ( (e.suggestion && l.push(` = ` + n(t, r.yellow, `help: `) + e.suggestion.text), e.branchErrors && e.branchErrors.length) ) { let i = (e.params && e.params.closestName) || `closest variant`, a = e.branchErrors.length; (l.push( ` = ` + n(t, r.dim, `note: `) + `closest match was ${i} with ${a} error${a === 1 ? `` : `s`}:`, ), u(e.branchErrors, 1, l, t)); } return ( e.docUrl && l.push(` = ` + n(t, r.dim, `note: see `) + e.docUrl), l.join(` `) ); } function u(e, t, i, a) { if (t >= 3) { i.push(` ` + n(a, r.dim, `... deeper branch errors omitted, see structured output`)); return; } let o = e.slice(0, 3); for (let e of o) (i.push(` ` + n(a, r.dim, `${e.keyword}: ${e.message || ``}`)), e.branchErrors && e.branchErrors.length && u(e.branchErrors, t + 1, i, a)); e.length > 3 && i.push(` ` + n(a, r.dim, `... and ${e.length - 3} more`)); } function d(e, t) { if (!Array.isArray(e) || e.length === 0) return ``; t ||= {}; let a = i(t.color || `auto`), o = t.maxErrors == null ? 20 : t.maxErrors, s = t.context || `input`, c = [], u = o === 0 ? e.length : Math.min(o, e.length); for (let n = 0; n < u; n++) c.push(l(e[n], a, t)); let d = c.join(` `); u < e.length && (d += `\n\n... and ${e.length - u} more errors (run with --pretty --max-errors=0 to see all)`); let f = e.length; return ( (d += ` ` + n(a, r.red + r.bold, `error: `) + `${f} schema violation${f === 1 ? `` : `s`} in ${s}`), d ); } t.exports = { renderPretty: d }; }), M = o((e, t) => { let { color: n, ANSI: r, resolveColor: i, pathToDotted: a, trimCwd: o } = A(); function s(e, t) { if (!Array.isArray(e) || e.length === 0) return ``; t ||= {}; let s = i(t.color || `auto`), c = t.cwd, l = []; for (let t of e) { let e = ``; if (t.schemaSource) { let i = o(t.schemaSource.file, c); e = n(s, r.cyan, `${i}:${t.schemaSource.line}:${t.schemaSource.col}`) + ` - `; } let i = n(s, r.red + r.bold, `error ${t.code}`), u = n(s, r.cyan, a(t.path)), d = t.received == null ? `` : `got ${t.received}`, f = t.suggestion ? n(s, r.yellow, `, ${t.suggestion.text}`) : ``, p = d || f ? ` (${d}${f})` : ``; l.push(`${e}${i}: ${u} ${t.message}${p}`); } let u = e.length; return ( l.push(``), l.push(`Found ${u} error${u === 1 ? `` : `s`} in ${t.context || `input`}.`), (process.stdout && process.stdout.isTTY) || l.push(`(run with --pretty for source frames)`), l.join(` `) ); } t.exports = { renderCompact: s }; }), N = o((e, t) => { function n(e, t) { t ||= {}; let n = { errors: Array.isArray(e) ? e : [], summary: { count: Array.isArray(e) ? e.length : 0, context: t.context || `input` }, }; return t.pretty ? JSON.stringify(n, null, 2) : JSON.stringify(n); } t.exports = { renderJSON: n }; }), P = o((e, t) => { let n = u()(), { compileToJS: r, compileToJSCodegen: i, compileToJSCodegenWithErrors: a, compileToJSCombined: o, } = p(), { normalizeDraft7: s, normalizeNullable: c } = m(), { classify: l } = h(), { buildTier0Plan: d, tier0Validate: f } = g(); function v(e) { if (typeof e != `object` || !e) return null; let t = []; return ( x(e, t), t.length === 0 ? null : (e) => { for (let n = 0; n < t.length; n++) t[n](e); } ); } function x(e, t, n) { if (typeof e != `object` || !e) return; let r = e.properties; if (r) for (let [e, i] of Object.entries(r)) { if (i && typeof i == `object` && i.default !== void 0) { let r = i.default; if (!n) t.push((t) => { typeof t == `object` && t && !(e in t) && (t[e] = typeof r == `object` && r ? JSON.parse(JSON.stringify(r)) : r); }); else { let i = n; t.push((t) => { let n = t; for (let e = 0; e < i.length; e++) { if (typeof n != `object` || !n) return; n = n[i[e]]; } typeof n == `object` && n && !(e in n) && (n[e] = typeof r == `object` && r ? JSON.parse(JSON.stringify(r)) : r); }); } } i && typeof i == `object` && i.properties && x(i, t, (n || []).concat(e)); } } function D(e) { if (typeof e != `object` || !e) return null; let t = []; return ( A(e, t), t.length === 0 ? null : (e) => { for (let n = 0; n < t.length; n++) t[n](e); } ); } function A(e, t, n) { if (typeof e != `object` || !e) return; let r = e.properties; if (r) for (let [e, i] of Object.entries(r)) { if (!i || typeof i != `object` || !i.type) continue; let r = Array.isArray(i.type) ? null : i.type; if (!r) continue; let a = P(r); if (a) { if (!n) t.push((t) => { if (typeof t == `object` && t && e in t) { let n = a(t[e]); n !== void 0 && (t[e] = n); } }); else { let r = n; t.push((t) => { let n = t; for (let e = 0; e < r.length; e++) { if (typeof n != `object` || !n) return; n = n[r[e]]; } if (typeof n == `object` && n && e in n) { let t = a(n[e]); t !== void 0 && (n[e] = t); } }); } i.properties && A(i, t, (n || []).concat(e)); } } } function P(e) { switch (e) { case `number`: return (e) => { if (typeof e == `string`) { let t = Number(e); if (e !== `` && !isNaN(t)) return t; } if (typeof e == `boolean`) return +!!e; }; case `integer`: return (e) => { if (typeof e == `string`) { let t = Number(e); if (e !== `` && Number.isInteger(t)) return t; } if (typeof e == `boolean`) return +!!e; }; case `string`: return (e) => { if (typeof e == `number` || typeof e == `boolean`) return String(e); }; case `boolean`: return (e) => { if (e === `true` || e === `1`) return !0; if (e === `false` || e === `0`) return !1; }; default: return null; } } function F(e) { if (typeof e != `object` || !e) return null; let t = []; return ( I(e, t), t.length === 0 ? null : (e) => { for (let n = 0; n < t.length; n++) t[n](e); } ); } function I(e, t, n) { if (!(typeof e != `object` || !e || !e.properties)) { if (e.additionalProperties === !1) { let r = new Set(Object.keys(e.properties)); if (!n) t.push((e) => { if (typeof e != `object` || !e || Array.isArray(e)) return; let t = Object.keys(e); for (let n = 0; n < t.length; n++) r.has(t[n]) || delete e[t[n]]; }); else { let e = n; t.push((t) => { let n = t; for (let t = 0; t < e.length; t++) { if (typeof n != `object` || !n) return; n = n[e[t]]; } if (typeof n != `object` || !n || Array.isArray(n)) return; let i = Object.keys(n); for (let e = 0; e < i.length; e++) r.has(i[e]) || delete n[i[e]]; }); } } for (let [r, i] of Object.entries(e.properties)) i && typeof i == `object` && i.properties && I(i, t, (n || []).concat(r)); } } function L(e, t) { if (typeof e != `object` || !e || !e.properties) return null; let n = [], r = e.properties, i = Object.keys(r); if (t.removeAdditional && e.additionalProperties === !1) { let e = i.map((e) => `_k!==${JSON.stringify(e)}`).join(`&&`); n.push(`for(var _k in d)if(${e})delete d[_k]`); } if (t.coerceTypes) for (let [e, i] of Object.entries(r)) { if (!i || typeof i != `object` || !i.type) continue; let r = Array.isArray(i.type) ? null : i.type; if (!r) continue; let a = JSON.stringify(e); r === `integer` ? (n.push( `if(typeof d[${a}]==='string'){var _n=Number(d[${a}]);if(d[${a}]!==''&&Number.isInteger(_n))d[${a}]=_n}`, ), n.push(`if(typeof d[${a}]==='boolean')d[${a}]=d[${a}]?1:0`)) : r === `number` ? (n.push( `if(typeof d[${a}]==='string'){var _n=Number(d[${a}]);if(d[${a}]!==''&&!isNaN(_n))d[${a}]=_n}`, ), n.push(`if(typeof d[${a}]==='boolean')d[${a}]=d[${a}]?1:0`)) : r === `string` ? n.push( `if(typeof d[${a}]==='number'||typeof d[${a}]==='boolean')d[${a}]=String(d[${a}])`, ) : r === `boolean` ? (n.push(`if(d[${a}]==='true'||d[${a}]==='1')d[${a}]=true`), n.push(`if(d[${a}]==='false'||d[${a}]==='0')d[${a}]=false`)) : r === `array` && t.coerceTypes === `array` && n.push( `if(${a} in d&&d[${a}]!==undefined&&!Array.isArray(d[${a}]))d[${a}]=[d[${a}]]`, ); } for (let [e, t] of Object.entries(r)) if (t && typeof t == `object` && t.default !== void 0) { let r = JSON.stringify(e), i = JSON.stringify(t.default); n.push(`if(!(${r} in d))d[${r}]=${i}`); } if (n.length === 0) return null; n.unshift(`if(d===null||typeof d!=='object')return`); try { return Function( `d`, n.join(` `), ); } catch { return null; } } let R = new Map(), z = new WeakMap(), B = Object.freeze({ valid: !0, errors: Object.freeze([]) }), V = Object.freeze({ valid: !1, errors: Object.freeze([ Object.freeze({ code: `ATA9000`, message: `validation failed`, keyword: `__abort_early__`, path: ``, }), ]), }), H = 8192; function U(e, t) { if (!t || typeof t != `string` || !t.startsWith(`#`)) return; let n = t.slice(1); if (!n || n === `/`) return e; let r = n .split(`/`) .filter(Boolean) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), i = e; for (let e = 0; e < r.length - 1; e++) { if (typeof i != `object` || !i) return; i = i[r[e]]; } return i; } function W(e, t) { if (!t || typeof t != `string` || !t.startsWith(`#`)) return null; let n = t .slice(1) .split(`/`) .filter(Boolean) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), r = [], i = e; for (let e of n) { if (typeof i != `object` || !i) break; if (Array.isArray(i)) { let t = Number(e); if (!Number.isInteger(t) || t < 0 || t >= i.length) break; (r.push(t), (i = i[t])); } else { let t = Object.keys(i).indexOf(e); if (t < 0) break; (r.push(t), (i = i[e])); } } return r; } function G(e, t) { let n = t.map((t, n) => ({ e: t, i: n, rank: W(e, t.schemaPath) })); return ( n.sort((e, t) => { if (!e.rank || !t.rank) return e.i - t.i; let n = Math.min(e.rank.length, t.rank.length); for (let r = 0; r < n; r++) if (e.rank[r] !== t.rank[r]) return e.rank[r] - t.rank[r]; return e.i - t.i; }), n.map((e) => e.e) ); } function K(e) { return e ? e .split(`/`) .filter(Boolean) .map((e) => { let t = e.replace(/~1/g, `/`).replace(/~0/g, `~`); return /^(0|[1-9][0-9]*)$/.test(t) ? { key: Number(t) } : { key: t }; }) : []; } function q(e) { if (typeof Buffer > `u`) throw Error(`createPaddedBuffer requires Node.js Buffer`); let t = Buffer.from(e), n = Buffer.allocUnsafe(t.length + 64); return (t.copy(n), n.fill(0, t.length), { buffer: n, length: t.length }); } function J(e) { if (typeof e != `object` || !e) return e; if (Array.isArray(e)) { let t = Array(e.length); for (let n = 0; n < e.length; n++) t[n] = J(e[n]); return t; } if (Object.getPrototypeOf(e) !== Object.prototype && Object.getPrototypeOf(e) !== null) return e; let t = Object.create(null); for (let n of Object.keys(e)) Object.defineProperty(t, n, { value: J(e[n]), writable: !0, enumerable: !0, configurable: !0, }); for (let n of Object.getOwnPropertySymbols(e)) t[n] = e[n]; return Object.setPrototypeOf(t, Object.prototype); } function Y(e) { let t = e && e.$schema && (e.$schema === `http://json-schema.org/draft-07/schema#` || e.$schema === `http://json-schema.org/draft-07/schema`), n = JSON.stringify(e), r = J(e); return (t && s(r), c(r), JSON.stringify(r) === n ? e : r); } function X(e) { if (!e) return null; let t = new Map(); if (Array.isArray(e)) for (let n of e) { let e = Y(n), r = e.$id; if (!r) throw Error(`Schema in schemas option must have $id`); t.set(r, e); } else for (let [n, r] of Object.entries(e)) { let e = Y(r); t.set(e.$id || n, e); } return t; } function Z(e, t) { if (!t || t.size === 0) return e; let n = []; for (let [e, r] of t) n.push(e + `=` + JSON.stringify(r)); return (n.sort(), e + `\0` + n.join(`\0`)); } function Q(e, t) { if (!t || t.size === 0 || typeof e != `string`) return null; let n = e.indexOf(`#`), r = n >= 0 ? e.slice(0, n) : e, i = n >= 0 ? e.slice(n + 1) : ``; if (!r) return null; let a = null; if (t.has(r)) a = t.get(r); else if (!e.includes(`://`)) { for (let [e, n] of t) if (e.endsWith(`/` + r)) { a = n; break; } } if (!a) return null; if (!i) return a; let o = a; for (let e of i.split(`/`)) if (e !== ``) { if (typeof o != `object` || !o) return null; o = o[e.replace(/~1/g, `/`).replace(/~0/g, `~`)]; } return o ?? null; } function ee(e, t) { if (!e || typeof e != `object` || !t || t.size === 0) return e; let n = e; if (n.$ref && !n.properties) { let e = Q(n.$ref, t); e && typeof e == `object` && (n = e); } if (!n.properties) return n; let r = null; for (let e of Object.keys(n.properties)) { let i = n.properties[e]; if (i && typeof i == `object` && i.$ref && !i.type) { let a = Q(i.$ref, t); a && typeof a == `object` && (r || ((r = Object.assign({}, n)), (r.properties = Object.assign({}, n.properties))), (r.properties[e] = a)); } } return r || n; } var $ = class e { constructor(e, t) { let r = t || {}; if (!t && typeof e == `object` && e) { let t = z.get(e); if (t) return t; } let i = typeof e == `string` ? JSON.parse(e) : Y(e); if ( ((this._schemaStr = null), (this._schemaObj = i), (this._options = r), (this._initialized = !1), (this._nativeReady = !1), (this._compiled = null), (this._fastSlot = -1), (this._jsFn = null), (this._preprocess = null), (this._applyDefaults = null), (this._schemaMap = X(r.schemas) || new Map()), (this._userFormats = r.formats || null), (this._verbose = !!r.verbose), (this._richErrors = !(r && r.richErrors === !1)), (this._source = r && r.source && typeof r.source == `object` ? { path: String(r.source.path || ``), content: String(r.source.content || ``) } : null), this._source) ) { let { buildPositionMap: e } = _(); this._schemaPositions = e(this._source.content); } else this._schemaPositions = null; ((this._posCache = y().createCache()), (this._lastRawInput = null), (this.validate = (e) => (this._ensureCompiled(), this.validate(e))), (this.isValidObject = (e) => { if (l(this._schemaObj).tier === 0) { let e = d(this._schemaObj), t = 0; this.isValidObject = (n) => { let r = f(e, n); if (++t === 2) try { this._ensureCodegen(); } catch {} return r; }; } else (this._ensureCodegen(), this._jsFn || this._ensureCompiled()); return this.isValidObject(e); }), (this.validateJSON = (e) => (this._ensureCompiled(), this.validateJSON(e))), (this.isValidJSON = (e) => (this._ensureCompiled(), this.isValidJSON(e))), (this.validateAndParse = (e) => { if (!n) throw Error(`Native addon required for validateAndParse()`); return (this._ensureCompiled(), this.validateAndParse(e)); }), (this.isValid = (e) => { if (!n) throw Error( `Native addon required for isValid() — use validate() or isValidObject() instead`, ); return (this._ensureCompiled(), this.isValid(e)); }), (this.countValid = (e) => { if (!n) throw Error(`Native addon required for countValid()`); return (this._ensureCompiled(), this.countValid(e)); }), (this.batchIsValid = (e) => { if (!n) throw Error(`Native addon required for batchIsValid()`); return (this._ensureCompiled(), this.batchIsValid(e)); })); let a = this; (Object.defineProperty(this, "~standard", { value: Object.freeze({ version: 1, vendor: `ata-validator`, validate(e) { let t = a.validate(e); return t.valid ? { value: e } : { issues: t.errors.map((e) => ({ message: e.message, path: K(e.instancePath) })), }; }, }), writable: !1, enumerable: !1, configurable: !1, }), !t && typeof e == `object` && e && z.set(e, this)); } _ensureCompiled() { if (this._initialized) return; this._initialized = !0; let e = this._schemaObj, t = this._options; this._schemaStr ||= JSON.stringify(e); let s = this._schemaMap.size > 0 ? this._schemaMap : null, c = Z(this._schemaStr, this._schemaMap), l = this._userFormats ? null : R.get(c), u, d, f, p = !1; var m = typeof process < `u` && process.env && process.env.ATA_FORCE_NAPI; if (l && !m) ((u = l.jsFn), (d = l.combined), (f = l.errFn), (p = !!l.isCodegen)); else if (m) ((u = null), (d = null), (f = null)); else { let t = this._userFormats, n = i(e, s, t); ((u = n || r(e, null, s)), (d = o(e, B, s, t)), (f = a(e, s, t)), (p = !!n), t || R.set(c, { jsFn: u, combined: d, errFn: f, isCodegen: p })); } this._jsFn = u; let h = ee(e, this._schemaMap), g = L(h, t); if (!g) { let e = v(h), n = t.coerceTypes ? D(h) : null, r = [t.removeAdditional ? F(h) : null, n, e].filter(Boolean); g = r.length === 0 ? null : r.length === 1 ? r[0] : (e) => { for (let t = 0; t < r.length; t++) r[t](e); }; } ((this._applyDefaults = g), (this._preprocess = g)); let _ = !( e && (e.items || e.prefixItems || e.contains || (e.properties && Object.values(e.properties).some( (e) => e && (e.items || e.prefixItems || e.contains), ))) ); if (u) { let r = null; if (f) try { (f({}, !0), (r = (e) => f(e, !0))); } catch {} let i = e && (e.unevaluatedProperties !== void 0 || e.unevaluatedItems !== void 0 || this._schemaStr.includes(`unevaluatedProperties`) || this._schemaStr.includes(`unevaluatedItems`)), a = this._schemaStr.includes(`"$dynamicRef"`) || this._schemaStr.includes(`"$dynamicAnchor"`), o = null, s = r || (i ? (e) => ({ valid: u(e), errors: u(e) ? [] : [ { code: `unevaluated`, path: ``, message: `unevaluated property or item`, }, ], }) : n ? a ? (e) => (this._ensureNative(), this._compiled.validateJSON(JSON.stringify(e))) : (e) => (this._ensureNative(), this._compiled.validate(e)) : (t) => { if (u(t)) return { valid: !0, data: t, errors: [] }; if (!o) { let { createInterpreter: t } = b(); o = t(e, { schemaMap: this._schemaMap.size > 0 ? this._schemaMap : null, formats: this._userFormats, }); } let n = o.validate(t); return n.valid ? { valid: !1, errors: [ { keyword: `validation`, instancePath: ``, schemaPath: ``, params: {}, message: `schema validation failed`, }, ], } : n; }), c = null; if (d) try { let t = {}; if (e && e.properties) for (let n of Object.keys(e.properties)) t[n] = ``; if (e && e.if && e.if.properties) for (let n of Object.keys(e.if.properties)) t[n] = ``; (d(t), d({}), d(null), d(0), (c = d)); } catch {} if (t.abortEarly && u && !a) { let e = u; this.validate = g ? (t) => (g(t), e(t) ? B : V) : (t) => (e(t) ? B : V); } else if (a && p && u) { let e = u, t = r || s, n = B; this.validate = g ? (r) => (g(r), e(r) ? n : t(r)) : (r) => (e(r) ? n : t(r)); } else if (a) this.validate = g ? (e) => (g(e), s(e)) : s; else if (u && u._hybridFactory) { let e = u._hybridFactory(B, c || s); this.validate = g ? (t) => (g(t), e(t)) : e; } else if (c) this.validate = g ? (e) => (g(e), c(e)) : c; else { let e = u && u._hybridFactory ? u._hybridFactory(B, s) : null; this.validate = e ? g ? (t) => (g(t), e(t)) : e : g ? (e) => (g(e), u(e) ? B : s(e)) : (e) => (u(e) ? B : s(e)); } if (this._verbose) { let e = this.validate, t = this._schemaObj; this.validate = (n) => { let r = e(n); return r && !r.valid && r.errors ? { valid: !1, errors: r.errors.map((e) => e && e.parentSchema === void 0 ? { ...e, parentSchema: U(t, e.schemaPath) } : e, ), } : r; }; } this.isValidObject = u; let l = u._hybridFactory ? u._hybridFactory(B, s) : null, m = c || l || ((e) => (u(e) ? B : s(e))); ((this.validateJSON = _ && n ? (e) => { if (e.length >= H) { this._ensureNative(); let t = Buffer.from(e); return n.rawFastValidate(this._fastSlot, t) ? B : this._compiled.validateJSON(e); } try { return m(JSON.parse(e)); } catch (e) { if (!(e instanceof SyntaxError)) throw e; } return (this._ensureNative(), this._compiled.validateJSON(e)); } : (e) => { try { return m(JSON.parse(e)); } catch (e) { if (!(e instanceof SyntaxError)) throw e; if (!n) return { valid: !1, errors: [ { keyword: `syntax`, instancePath: ``, schemaPath: `#`, params: {}, message: e.message, }, ], }; } return (this._ensureNative(), this._compiled.validateJSON(e)); }), (this.isValidJSON = _ && n ? (e) => { if (e.length >= H) return ( this._ensureNative(), n.rawFastValidate(this._fastSlot, Buffer.from(e)) ); try { return u(JSON.parse(e)); } catch (e) { if (!(e instanceof SyntaxError)) throw e; return !1; } } : (e) => { try { return u(JSON.parse(e)); } catch (e) { if (!(e instanceof SyntaxError)) throw e; return !1; } })); { let e = this; this.validateAndParse = (t) => { let n; try { n = JSON.parse(typeof t == `string` ? t : new TextDecoder().decode(t)); } catch (e) { return { valid: !1, value: void 0, errors: [ { code: `ATA9001`, message: `invalid JSON: ` + e.message, keyword: `__parse__`, instancePath: ``, schemaPath: ``, params: {}, }, ], }; } let r = e.validate(n); return { valid: r.valid, value: n, errors: r.errors }; }; } if (n) { let e = this; ((this.isValid = (t) => { e._ensureNative(); let r = e._fastSlot; return ( (e.isValid = (e) => { if (typeof e == `string`) e = Buffer.from(e); else if (!(e instanceof Uint8Array)) throw TypeError( `isValid() requires a Buffer, Uint8Array, or string. For parsed objects, use isValidObject().`, ); return n.rawFastValidate(r, e); }), e.isValid(t) ); }), (this.countValid = (t) => { e._ensureNative(); let r = e._fastSlot; return ( (e.countValid = (e) => { if (typeof e == `string`) e = Buffer.from(e); else if (!(e instanceof Uint8Array)) throw TypeError(`countValid() requires a Buffer, Uint8Array, or string`); let t = n.rawNDJSONValidate(r, e), i = 0; for (let e = 0; e < t.length; e++) t[e] && i++; return i; }), e.countValid(t) ); }), (this.batchIsValid = (t) => { e._ensureNative(); let r = e._fastSlot; return ( (e.batchIsValid = (e) => { let t = 0; for (let i of e) { if (!(i instanceof Uint8Array)) throw TypeError(`batchIsValid() requires Buffer or Uint8Array elements`); n.rawFastValidate(r, i) && t++; } return t; }), e.batchIsValid(t) ); })); } } else if (n) { this._ensureNative(); let t = this._schemaStr.includes(`"$dynamicRef"`) || this._schemaStr.includes(`"$dynamicAnchor"`), r = this._schemaStr.includes(`"unevaluatedProperties"`) || this._schemaStr.includes(`"unevaluatedItems"`), i; if (t && !r) ((i = (e) => this._compiled.validateJSON(JSON.stringify(e))), (this.validateJSON = (e) => this._compiled.validateJSON(e)), (this.isValidJSON = (e) => this._compiled.isValidJSON(e))); else { let { createInterpreter: t } = b(), n = t(e, { schemaMap: this._schemaMap.size > 0 ? this._schemaMap : null, formats: this._userFormats, }); ((i = (e) => n.validate(e)), (this.validateJSON = (e) => { try { return i(JSON.parse(e)); } catch (e) { return { valid: !1, errors: [ { keyword: `syntax`, instancePath: ``, schemaPath: `#`, params: {}, message: e.message, }, ], }; } }), (this.isValidJSON = (e) => this.validateJSON(e).valid)); } ((this.validate = g ? (e) => (g(e), i(e)) : i), (this.isValidObject = (e) => i(e).valid), (this.validateAndParse = (e) => this._compiled.validateAndParse(e))); { let e = this._fastSlot; this.isValid = (t) => { if (typeof t == `string`) t = Buffer.from(t); else if (!(t instanceof Uint8Array)) throw TypeError( `isValid() requires a Buffer, Uint8Array, or string. For parsed objects, use isValidObject().`, ); return n.rawFastValidate(e, t); }; } { let e = this._fastSlot; this.countValid = (t) => { if (typeof t == `string`) t = Buffer.from(t); else if (!(t instanceof Uint8Array)) throw TypeError(`countValid() requires a Buffer, Uint8Array, or string`); let r = n.rawNDJSONValidate(e, t), i = 0; for (let e = 0; e < r.length; e++) r[e] && i++; return i; }; } { let e = this._fastSlot; this.batchIsValid = (t) => { let r = 0; for (let i of t) { if (!(i instanceof Uint8Array)) throw TypeError(`batchIsValid() requires Buffer or Uint8Array elements`); n.rawFastValidate(e, i) && r++; } return r; }; } } else { let { createInterpreter: t } = b(), n = t(e, { schemaMap: this._schemaMap.size > 0 ? this._schemaMap : null, formats: this._userFormats, }), r = g ? (e) => (g(e), n.validate(e)) : (e) => n.validate(e); ((this.validate = r), (this.isValidObject = (e) => r(e).valid), (this.validateJSON = (e) => { try { return r(JSON.parse(e)); } catch (e) { return { valid: !1, errors: [ { keyword: `syntax`, instancePath: ``, schemaPath: `#`, params: {}, message: e.message, }, ], }; } }), (this.isValidJSON = (e) => this.validateJSON(e).valid)); } if (this.validate) { let e = this.validate, t = this._schemaObj; this.validate = (n) => { let r = e(n); return r && !r.valid && r.errors && r.errors.length > 1 && r !== V ? { valid: !1, errors: G(t, r.errors) } : r; }; } if (this._richErrors && this.validate) { let e = this.validate, t = C().enrich; if ( ((this.validate = (n) => { let r = e(n); if (r && !r.valid && r.errors && r.errors.length) { if (r === V) return r; let e = this._lastRawInput == null ? null : this._posCache.get(this._lastRawInput), i = r.errors.map((r) => t(r, { data: n, positions: e, schemaPositions: this._schemaPositions, schemaFile: this._source ? this._source.path : void 0, }), ); return (e && this._posCache.reset(), { valid: !1, errors: i }); } return r; }), this.validateJSON) ) { let e = this.validateJSON; this.validateJSON = (n) => { this._lastRawInput = n; let r; try { r = e(n); } finally { } if (r && !r.valid && r.errors && r.errors.length) { let e = r.errors[0]; if (!e || !e.code) { let e = this._lastRawInput == null ? null : this._posCache.get(this._lastRawInput), i; try { i = JSON.parse(n); } catch { i = void 0; } let a = r.errors.map((n) => t(n, { data: i, positions: e, schemaPositions: this._schemaPositions, schemaFile: this._source ? this._source.path : void 0, }), ); return ( e && this._posCache.reset(), (this._lastRawInput = null), { valid: !1, errors: a } ); } let i = this._lastRawInput == null ? null : this._posCache.get(this._lastRawInput); if (i) { for (let e of r.errors) if (e && !e.dataFrame) { let t = i[e.path == null ? e.instancePath || `` : e.path]; t && (e.dataFrame = { byteOffset: t.byteOffset, length: t.length, line: t.line, col: t.col, text: t.text, }); } this._posCache.reset(); } } return ((this._lastRawInput = null), r); }; } } if (this.validate) { let e = this.validate; this.validate = (t) => { let n = e(t); return n.valid === !0 && n.data === void 0 ? { valid: !0, data: t, errors: n.errors } : n; }; } { let e = w(), t = this._schemaStr || (this._schemaObj ? JSON.stringify(this._schemaObj) : ``); if (e.schemaHasErrorMessages(t)) { let t = this._schemaObj, n = (n) => (r) => { let i = n(r); if (i && i.valid === !1 && i.errors && i.errors.length && i !== V) { let n = e.applyErrorMessages(i.errors, t); if (n !== i.errors) return { valid: !1, errors: n }; } return i; }; if ( ((this.validate &&= n(this.validate)), (this.validateJSON &&= n(this.validateJSON)), this.validateAndParse) ) { let n = this.validateAndParse; this.validateAndParse = (r) => { let i = n(r); if (i && i.valid === !1 && i.errors && i.errors.length) { let n = e.applyErrorMessages(i.errors, t); if (n !== i.errors) return { valid: !1, value: i.value, errors: n }; } return i; }; } } } this._schemaObj && typeof this._schemaObj == `object` && z.set(this._schemaObj, this); } _ensureNative() { if (this._nativeReady || ((this._nativeReady = !0), !n)) return; let e = this._schemaStr; if (this._schemaMap.size > 0) { let t = JSON.parse(this._schemaStr); t.$defs ||= {}; for (let [e, n] of this._schemaMap) t.$defs[`__ext_` + e.replace(/[^a-zA-Z0-9]/g, `_`)] = n; e = JSON.stringify(t); } ((this._compiled = new n.CompiledSchema(e)), (this._fastSlot = n.fastRegister(e))); } addSchema(e) { if (this._initialized) throw Error(`Cannot add schema after compilation — call addSchema() before validate()`); if (!e || !e.$id) throw Error(`Schema must have $id`); let t = Y(e); this._schemaMap.set(t.$id, t); } _ensureCodegen() { if (this._jsFn || (typeof process < `u` && process.env && process.env.ATA_FORCE_NAPI)) return; this._schemaStr ||= JSON.stringify(this._schemaObj); let e = this._schemaMap.size > 0 ? this._schemaMap : null, t = Z(this._schemaStr, this._schemaMap), n = this._userFormats ? null : R.get(t); if (n && n.jsFn) { ((this._jsFn = n.jsFn), (this.isValidObject = n.jsFn)); return; } let a = this._userFormats, o = i(this._schemaObj, e, a) || r(this._schemaObj, null, e); ((this._jsFn = o), o && ((this.isValidObject = o), a || (n ? (n.jsFn = o) : R.set(t, { jsFn: o, combined: null, errFn: null })))); } static fromStandalone(t, r, i) { let o = i || {}, s = typeof r == `string` ? JSON.parse(r) : r, c = Object.create(e.prototype); ((c._jsFn = t.boolFn), (c._compiled = null), (c._fastSlot = -1)); let l = v(s), u = o.coerceTypes ? D(s) : null, d = [o.removeAdditional ? F(s) : null, u, l].filter(Boolean), f = d.length === 0 ? null : d.length === 1 ? d[0] : (e) => { for (let t = 0; t < d.length; t++) d[t](e); }; c._preprocess = f; let p = (e) => ({ valid: !1, errors: [{ code: `validation_failed`, path: ``, message: `validation failed` }], }); if (t.errFn) p = (e) => t.errFn(e, !0); else { let e = a(s); if (e) try { (e({}, !0), (p = (t) => e(t, !0))); } catch {} } let m = t.hybridFactory ? t.hybridFactory(B, p) : null; c.validate = m ? f ? (e) => (f(e), m(e)) : m : f ? (e) => (f(e), t.boolFn(e) ? B : p(e)) : (e) => (t.boolFn(e) ? B : p(e)); { let e = c.validate; c.validate = (t) => { let n = e(t); return n.valid === !0 && n.data === void 0 ? { valid: !0, data: t, errors: n.errors } : n; }; } return ( (c.isValidObject = t.boolFn), (c.isValidJSON = (e) => { try { return t.boolFn(JSON.parse(e)); } catch { return !1; } }), (c.validateJSON = (e) => { try { let n = JSON.parse(e); return m ? m(n) : t.boolFn(n) ? B : p(n); } catch { return { valid: !1, errors: [{ code: `invalid_json`, path: ``, message: `invalid JSON` }], }; } }), (c.validateAndParse = n ? (e) => ( c._ensureNative(), (c.validateAndParse = (e) => c._compiled.validateAndParse(e)), c.validateAndParse(e) ) : () => { throw Error(`Native addon required for validateAndParse()`); }), Object.defineProperty(c, "~standard", { value: Object.freeze({ version: 1, vendor: `ata-validator`, validate(e) { let t = c.validate(e); return t.valid ? { value: e } : { issues: t.errors.map((e) => ({ message: e.message, path: K(e.instancePath), })), }; }, }), writable: !1, enumerable: !1, configurable: !1, }), c ); } isValid(e) { if (!n) throw Error( `Native addon required for isValid() — install build tools or use validate() instead`, ); if (typeof e == `string`) e = Buffer.from(e); else if (!(e instanceof Uint8Array)) throw TypeError( `isValid() requires a Buffer, Uint8Array, or string. For parsed objects, use isValidObject().`, ); return (this._ensureNative(), n.rawFastValidate(this._fastSlot, e)); } isValidPrepadded(e, t) { if (!n) throw Error(`Native addon required for isValidPrepadded()`); return (this._ensureNative(), n.rawFastValidate(this._fastSlot, e, t)); } isValidParallel(e) { if (!n) throw Error(`Native addon required for isValidParallel()`); return (this._ensureNative(), n.rawParallelValidate(this._fastSlot, e)); } countValid(e) { if (!n) throw Error(`Native addon required for countValid()`); return (this._ensureNative(), n.rawParallelCount(this._fastSlot, e)); } isValidNDJSON(e) { if (!n) throw Error(`Native addon required for isValidNDJSON()`); return (this._ensureNative(), n.rawNDJSONValidate(this._fastSlot, e)); } }; function te(e, t) { if (n) { let r = typeof e == `string` ? e : JSON.stringify(e); return n.validate(r, t); } return new $(typeof e == `string` ? JSON.parse(e) : e).validate(t); } async function ne(e, t) { let n = T(), r, i; e instanceof $ ? ((r = e), (i = r._schemaObj)) : ((i = e), (r = new $(i))); let a = r.validate(t); if (!a.valid) return a; let o = n.getRefinements(i); if (!o) return a; let s = await n.runRefinements(o, a.data === void 0 ? t : a.data); return s.length ? { valid: !1, errors: s } : a; } async function re(e, t) { let n = await ne(e, t); if (n.valid) return n.data === void 0 ? t : n.data; let r = Error(`ata: async validation failed`); throw ((r.errors = n.errors), r); } function ie() { if (n) return n.version(); try { return E(); } catch { return `unknown`; } } (($.bundle = function (e, t) { return O().bundle($, e, t); }), ($.bundleStandalone = function (e, t) { return O().bundleStandalone($, e, t); }), ($.bundleCompact = function (e, t) { return O().bundleCompact($, e, t); }), ($.loadBundle = function (e, t, n) { return O().loadBundle($, e, t, n); })); let ae = n ? n.parseJSON : JSON.parse, oe = new WeakMap(); function se(e, t) { if (!t && typeof e == `object` && e) { let t = oe.get(e); if (t) return t; } let n = new $(e, t); n._ensureCompiled(); let r = n.validate; return (!t && typeof e == `object` && e && oe.set(e, r), r); } let { toTypeScript: ce } = k(), { renderPretty: le } = j(), { renderCompact: ue } = M(), { renderJSON: de } = N(), { suggestFor: fe } = S(), { reprValue: pe } = C(); function me(e, t) { if (!t) return e; let n = t .replace(/^\//, ``) .split(`/`) .map((e) => e.replace(/~1/g, `/`).replace(/~0/g, `~`)), r = e; for (let e of n) { if (r == null) return; r = r[e]; } return r; } function he(e, t) { if (!e) return e; for (let n of e) { if (!n || n.suggestion) continue; let e = n.received; if (e === void 0 && t !== void 0) { let r = n.instancePath == null ? n.path || `` : n.instancePath, i = me(t, r); (i !== void 0 || r === ``) && (e = pe(i)); } let r = e !== void 0 && n.received === void 0 ? Object.assign({}, n, { received: e }) : n, i = fe(r, t); i && (n.suggestion = i); } return e; } function ge(e) { return e; } t.exports = { Validator: $, compile: se, validate: te, validateAsync: ne, parseAsync: re, version: ie, createPaddedBuffer: q, SIMDJSON_PADDING: 64, parseJSON: ae, toTypeScript: ce, defineSchema: ge, renderPretty: le, renderCompact: ue, renderJSON: de, attachSuggestions: he, }; }), F = l(); const { Validator: I, validate: L, validateAsync: R, parseAsync: z, version: B, createPaddedBuffer: V, SIMDJSON_PADDING: H, renderPretty: U, renderCompact: W, renderJSON: G, toTypeScript: K, } = c(P(), 1).default; var q = o((e, t) => { let n = Symbol.for(`ata.t.optional`), { attach: r } = T(); function i(e) { return Object.assign({ type: `string` }, e); } function a(e) { return Object.assign({ type: `number` }, e); } function o(e) { return Object.assign({ type: `integer` }, e); } function s() { return { type: `boolean` }; } function c() { return { type: `null` }; } function l(e) { return { const: e }; } function u(e) { return { const: e }; } function d(e) { return { enum: e }; } function f(e, t) { return Object.assign({ type: `array`, items: e }, t); } function p(e, t) { return Object.assign({ type: `array`, prefixItems: e, items: !1, minItems: e.length }, t); } function m(e, t) { return Object.assign({ type: `object`, additionalProperties: e }, t); } function h(e, t) { let r = {}, i = [], a = Object.keys(e); for (let t of a) { let a = e[t]; if (a && a[n] === !0) { let { [n]: e, ...i } = a; r[t] = i; } else ((r[t] = a), i.push(t)); } let o = { type: `object`, properties: r }; return (i.length && (o.required = i), Object.assign(o, t)); } function g(e) { return Object.assign({}, e, { [n]: !0 }); } function _(e) { return { anyOf: e }; } function v(e) { return { allOf: e }; } function y(e) { return { $ref: e }; } function b() { return {}; } function x() { return {}; } function S() { return { not: {} }; } function C(e, t, n) { return r(e, t, n); } function w(e, t) { if ( !e || typeof e != `object` || e.type !== `object` || !e.properties || typeof e.properties != `object` ) throw Error(`t.${t}: expected an object schema with properties`); } function E(e) { let t = {}; for (let n of Object.keys(e)) n !== `properties` && n !== `required` && (t[n] = e[n]); return t; } function D(e, t) { w(e, `pick`); let n = new Set(t), r = {}; for (let t of Object.keys(e.properties)) n.has(t) && (r[t] = e.properties[t]); let i = (e.required || []).filter((e) => n.has(e)), a = Object.assign(E(e), { properties: r }); return (i.length && (a.required = i), a); } function O(e, t) { w(e, `omit`); let n = new Set(t), r = {}; for (let t of Object.keys(e.properties)) n.has(t) || (r[t] = e.properties[t]); let i = (e.required || []).filter((e) => !n.has(e)), a = Object.assign(E(e), { properties: r }); return (i.length && (a.required = i), a); } function k(e) { return (w(e, `partial`), Object.assign(E(e), { properties: e.properties })); } function A(e, t) { w(e, `required`); let n = Object.keys(e.properties), r; if (t === void 0) r = n.slice(); else { let i = new Set(n); r = Array.from(new Set([...(e.required || []), ...t])).filter((e) => i.has(e)); } let i = Object.assign(E(e), { properties: e.properties }); return (r.length && (i.required = r), i); } function j(e, t) { let n = e({ $ref: `#/$defs/self` }); return Object.assign({ $ref: `#/$defs/self`, $defs: { self: n } }, t); } function M(e, t) { let n = {}, r = new Set(); for (let t of e) { w(t, `composite`); for (let e of Object.keys(t.properties)) n[e] = t.properties[e]; for (let e of t.required || []) r.add(e); } let i = Array.from(r).filter((e) => Object.hasOwn(n, e)), a = { type: `object`, properties: n }; return (i.length && (a.required = i), Object.assign(a, t)); } t.exports = { string: i, number: a, integer: o, boolean: s, null: c, literal: l, const: u, enum: d, array: f, tuple: p, record: m, object: h, optional: g, union: _, intersect: v, ref: y, any: b, unknown: x, never: S, refine: C, OPTIONAL: n, pick: D, omit: O, partial: k, required: A, composite: M, recursive: j, }; }); const { t: J, OPTIONAL: Y } = c( o((e, t) => { let n = q(); t.exports = { t: n, OPTIONAL: n.OPTIONAL }; })(), 1, ).default, X = J.object({}, { instanceof: `Date` }), Z = J.object({ id: J.number(), created: X, title: J.string({ minLength: 1, maxLength: 100 }), type: J.enum([`jpg`, `png`]), size: J.number(), url: J.string({ format: `url` }), }), Q = J.object({ id: J.number(), stars: J.number({ minimum: 0, maximum: 5 }), title: J.string({ minLength: 1, maxLength: 100 }), text: J.string({ minLength: 1, maxLength: 1e3 }), images: J.array(Z), }); (0, F.withKeywords)( new I( J.object({ id: J.number(), created: X, title: J.string({ minLength: 1, maxLength: 100 }), brand: J.string({ minLength: 1, maxLength: 30 }), description: J.string({ minLength: 1, maxLength: 500 }), price: J.number({ minimum: 1, maximum: 1e4 }), discount: J.union([J.number({ minimum: 1, maximum: 100 }), J.null()]), quantity: J.number({ minimum: 0, maximum: 10 }), tags: J.array(J.string({ minLength: 1, maxLength: 30 })), images: J.array(Z), ratings: J.array(Q), }), ), ).validate({});
Created by eskimojo for Open Circle

Preferences

Style
Theme
NPM browser
Code ligatures