@earendil-works/pi-schema 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSES/typebox-LICENSE +23 -0
- package/README.md +295 -2
- package/dist/annotations.d.ts +44 -0
- package/dist/annotations.d.ts.map +1 -0
- package/dist/annotations.js +193 -0
- package/dist/annotations.js.map +1 -0
- package/dist/builders.d.ts +114 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/builders.js +98 -0
- package/dist/builders.js.map +1 -0
- package/dist/checks.d.ts +87 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +447 -0
- package/dist/checks.js.map +1 -0
- package/dist/coerce.d.ts +53 -0
- package/dist/coerce.d.ts.map +1 -0
- package/dist/coerce.js +585 -0
- package/dist/coerce.js.map +1 -0
- package/dist/compiler.d.ts +53 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +532 -0
- package/dist/compiler.js.map +1 -0
- package/dist/explain.d.ts +29 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +381 -0
- package/dist/explain.js.map +1 -0
- package/dist/formats/index.d.ts +7 -0
- package/dist/formats/index.d.ts.map +1 -0
- package/dist/formats/index.js +51 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/typebox/date.d.ts +7 -0
- package/dist/formats/typebox/date.d.ts.map +1 -0
- package/dist/formats/typebox/date.js +47 -0
- package/dist/formats/typebox/date.js.map +1 -0
- package/dist/formats/typebox/date_time.d.ts +7 -0
- package/dist/formats/typebox/date_time.d.ts.map +1 -0
- package/dist/formats/typebox/date_time.js +39 -0
- package/dist/formats/typebox/date_time.js.map +1 -0
- package/dist/formats/typebox/duration.d.ts +6 -0
- package/dist/formats/typebox/duration.d.ts.map +1 -0
- package/dist/formats/typebox/duration.js +36 -0
- package/dist/formats/typebox/duration.js.map +1 -0
- package/dist/formats/typebox/email.d.ts +6 -0
- package/dist/formats/typebox/email.d.ts.map +1 -0
- package/dist/formats/typebox/email.js +36 -0
- package/dist/formats/typebox/email.js.map +1 -0
- package/dist/formats/typebox/hostname.d.ts +8 -0
- package/dist/formats/typebox/hostname.d.ts.map +1 -0
- package/dist/formats/typebox/hostname.js +38 -0
- package/dist/formats/typebox/hostname.js.map +1 -0
- package/dist/formats/typebox/idn_email.d.ts +6 -0
- package/dist/formats/typebox/idn_email.d.ts.map +1 -0
- package/dist/formats/typebox/idn_email.js +36 -0
- package/dist/formats/typebox/idn_email.js.map +1 -0
- package/dist/formats/typebox/idn_hostname.d.ts +9 -0
- package/dist/formats/typebox/idn_hostname.d.ts.map +1 -0
- package/dist/formats/typebox/idn_hostname.js +39 -0
- package/dist/formats/typebox/idn_hostname.js.map +1 -0
- package/dist/formats/typebox/idna/format/bidi.d.ts +4 -0
- package/dist/formats/typebox/idna/format/bidi.d.ts.map +1 -0
- package/dist/formats/typebox/idna/format/bidi.js +132 -0
- package/dist/formats/typebox/idna/format/bidi.js.map +1 -0
- package/dist/formats/typebox/idna/format/puny.d.ts +4 -0
- package/dist/formats/typebox/idna/format/puny.d.ts.map +1 -0
- package/dist/formats/typebox/idna/format/puny.js +172 -0
- package/dist/formats/typebox/idna/format/puny.js.map +1 -0
- package/dist/formats/typebox/idna/hostname.d.ts +2 -0
- package/dist/formats/typebox/idna/hostname.d.ts.map +1 -0
- package/dist/formats/typebox/idna/hostname.js +43 -0
- package/dist/formats/typebox/idna/hostname.js.map +1 -0
- package/dist/formats/typebox/idna/idn-hostname.d.ts +2 -0
- package/dist/formats/typebox/idna/idn-hostname.d.ts.map +1 -0
- package/dist/formats/typebox/idna/idn-hostname.js +71 -0
- package/dist/formats/typebox/idna/idn-hostname.js.map +1 -0
- package/dist/formats/typebox/idna/index.d.ts +3 -0
- package/dist/formats/typebox/idna/index.d.ts.map +1 -0
- package/dist/formats/typebox/idna/index.js +30 -0
- package/dist/formats/typebox/idna/index.js.map +1 -0
- package/dist/formats/typebox/idna/label/ascii.d.ts +2 -0
- package/dist/formats/typebox/idna/label/ascii.d.ts.map +1 -0
- package/dist/formats/typebox/idna/label/ascii.js +37 -0
- package/dist/formats/typebox/idna/label/ascii.js.map +1 -0
- package/dist/formats/typebox/idna/label/puny.d.ts +2 -0
- package/dist/formats/typebox/idna/label/puny.d.ts.map +1 -0
- package/dist/formats/typebox/idna/label/puny.js +56 -0
- package/dist/formats/typebox/idna/label/puny.js.map +1 -0
- package/dist/formats/typebox/idna/label/unicode.d.ts +2 -0
- package/dist/formats/typebox/idna/label/unicode.d.ts.map +1 -0
- package/dist/formats/typebox/idna/label/unicode.js +134 -0
- package/dist/formats/typebox/idna/label/unicode.js.map +1 -0
- package/dist/formats/typebox/idna/pattern/pattern.d.ts +31 -0
- package/dist/formats/typebox/idna/pattern/pattern.d.ts.map +1 -0
- package/dist/formats/typebox/idna/pattern/pattern.js +98 -0
- package/dist/formats/typebox/idna/pattern/pattern.js.map +1 -0
- package/dist/formats/typebox/ipv4.d.ts +6 -0
- package/dist/formats/typebox/ipv4.d.ts.map +1 -0
- package/dist/formats/typebox/ipv4.js +36 -0
- package/dist/formats/typebox/ipv4.js.map +1 -0
- package/dist/formats/typebox/ipv6.d.ts +6 -0
- package/dist/formats/typebox/ipv6.d.ts.map +1 -0
- package/dist/formats/typebox/ipv6.js +36 -0
- package/dist/formats/typebox/ipv6.js.map +1 -0
- package/dist/formats/typebox/iri.d.ts +6 -0
- package/dist/formats/typebox/iri.d.ts.map +1 -0
- package/dist/formats/typebox/iri.js +63 -0
- package/dist/formats/typebox/iri.js.map +1 -0
- package/dist/formats/typebox/iri_reference.d.ts +6 -0
- package/dist/formats/typebox/iri_reference.d.ts.map +1 -0
- package/dist/formats/typebox/iri_reference.js +40 -0
- package/dist/formats/typebox/iri_reference.js.map +1 -0
- package/dist/formats/typebox/json_pointer.d.ts +7 -0
- package/dist/formats/typebox/json_pointer.d.ts.map +1 -0
- package/dist/formats/typebox/json_pointer.js +37 -0
- package/dist/formats/typebox/json_pointer.js.map +1 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.d.ts +7 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.d.ts.map +1 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.js +37 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.js.map +1 -0
- package/dist/formats/typebox/regex.d.ts +6 -0
- package/dist/formats/typebox/regex.d.ts.map +1 -0
- package/dist/formats/typebox/regex.js +41 -0
- package/dist/formats/typebox/regex.js.map +1 -0
- package/dist/formats/typebox/relative_json_pointer.d.ts +7 -0
- package/dist/formats/typebox/relative_json_pointer.d.ts.map +1 -0
- package/dist/formats/typebox/relative_json_pointer.js +37 -0
- package/dist/formats/typebox/relative_json_pointer.js.map +1 -0
- package/dist/formats/typebox/time.d.ts +6 -0
- package/dist/formats/typebox/time.d.ts.map +1 -0
- package/dist/formats/typebox/time.js +60 -0
- package/dist/formats/typebox/time.js.map +1 -0
- package/dist/formats/typebox/uri.d.ts +6 -0
- package/dist/formats/typebox/uri.d.ts.map +1 -0
- package/dist/formats/typebox/uri.js +36 -0
- package/dist/formats/typebox/uri.js.map +1 -0
- package/dist/formats/typebox/uri_reference.d.ts +6 -0
- package/dist/formats/typebox/uri_reference.d.ts.map +1 -0
- package/dist/formats/typebox/uri_reference.js +36 -0
- package/dist/formats/typebox/uri_reference.js.map +1 -0
- package/dist/formats/typebox/uri_template.d.ts +6 -0
- package/dist/formats/typebox/uri_template.d.ts.map +1 -0
- package/dist/formats/typebox/uri_template.js +37 -0
- package/dist/formats/typebox/uri_template.js.map +1 -0
- package/dist/formats/typebox/url.d.ts +7 -0
- package/dist/formats/typebox/url.d.ts.map +1 -0
- package/dist/formats/typebox/url.js +36 -0
- package/dist/formats/typebox/url.js.map +1 -0
- package/dist/formats/typebox/uuid.d.ts +7 -0
- package/dist/formats/typebox/uuid.d.ts.map +1 -0
- package/dist/formats/typebox/uuid.js +37 -0
- package/dist/formats/typebox/uuid.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/resolver.d.ts +57 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +202 -0
- package/dist/resolver.js.map +1 -0
- package/dist/shared.d.ts +9 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +33 -0
- package/dist/shared.js.map +1 -0
- package/dist/typebox-static.d.ts +48 -0
- package/dist/typebox-static.d.ts.map +1 -0
- package/dist/typebox-static.js +5 -0
- package/dist/typebox-static.js.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validator.d.ts +39 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +71 -0
- package/dist/validator.js.map +1 -0
- package/package.json +59 -5
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Compiler } from "./compiler.ts";
|
|
2
|
+
import type { ValidationError } from "./types.ts";
|
|
3
|
+
/** Explains failures of one compiled schema. */
|
|
4
|
+
export declare class Explainer {
|
|
5
|
+
private readonly c;
|
|
6
|
+
private readonly schema;
|
|
7
|
+
/**
|
|
8
|
+
* The errors of `$ref` targets for object values, within one errors() call: a recursive union explains each branch
|
|
9
|
+
* to pick the one to blame, and every branch would explain the same children again, exponentially in the depth.
|
|
10
|
+
*/
|
|
11
|
+
private memo;
|
|
12
|
+
constructor(compiler: Compiler, schema: unknown);
|
|
13
|
+
/** The errors of `value`, at least one (`value` failed the check). */
|
|
14
|
+
errors(value: unknown): ValidationError[];
|
|
15
|
+
private ok;
|
|
16
|
+
private walk;
|
|
17
|
+
private walkRef;
|
|
18
|
+
private walkString;
|
|
19
|
+
private walkBytes;
|
|
20
|
+
private walkNumber;
|
|
21
|
+
private walkObject;
|
|
22
|
+
private walkArray;
|
|
23
|
+
private walkUnion;
|
|
24
|
+
/** How many of the keys of `v` the branch `s` (through a `$ref`) declares in `properties`. */
|
|
25
|
+
private declaredKeys;
|
|
26
|
+
private tagOf;
|
|
27
|
+
private walkUnevaluated;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=explain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../src/explain.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,YAAY,CAAC;AAEhE,gDAAgD;AAChD,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAW;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC;;;OAGG;IACH,OAAO,CAAC,IAAI,CAAgG;IAE5G,YAAY,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAI9C;IAED,sEAAsE;IACtE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,EAAE,CASxC;IAED,OAAO,CAAC,EAAE;IAKV,OAAO,CAAC,IAAI;IAmDZ,OAAO,CAAC,OAAO;IA2Bf,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,UAAU;IA0DlB,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,SAAS;IA6CjB,8FAA8F;IAC9F,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,KAAK;IAiBb,OAAO,CAAC,eAAe;CAqBvB"}
|
package/dist/explain.js
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// Errors of a failed value: a walk over the schema that reports each failing keyword at the value it failed on.
|
|
2
|
+
// It runs only for values that failed the check, using the compiler's checks for subschemas.
|
|
3
|
+
import { newAnnotations } from "./annotations.js";
|
|
4
|
+
import { codePoints, constCheck, containsCheck, enumCheck, isMultiple, isObject, NEVER, TYPE_CHECKS, uniqueCheck, } from "./checks.js";
|
|
5
|
+
import { isSchemaObject } from "./resolver.js";
|
|
6
|
+
import { sharedRegex } from "./shared.js";
|
|
7
|
+
/** Explains failures of one compiled schema. */
|
|
8
|
+
export class Explainer {
|
|
9
|
+
c;
|
|
10
|
+
schema;
|
|
11
|
+
/**
|
|
12
|
+
* The errors of `$ref` targets for object values, within one errors() call: a recursive union explains each branch
|
|
13
|
+
* to pick the one to blame, and every branch would explain the same children again, exponentially in the depth.
|
|
14
|
+
*/
|
|
15
|
+
memo = undefined;
|
|
16
|
+
constructor(compiler, schema) {
|
|
17
|
+
this.c = compiler;
|
|
18
|
+
this.schema = schema;
|
|
19
|
+
compiler.root();
|
|
20
|
+
}
|
|
21
|
+
/** The errors of `value`, at least one (`value` failed the check). */
|
|
22
|
+
errors(value) {
|
|
23
|
+
const out = [];
|
|
24
|
+
try {
|
|
25
|
+
this.walk(this.schema, this.c.r.rootBase, value, "", out);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
this.memo = undefined;
|
|
29
|
+
}
|
|
30
|
+
if (out.length === 0)
|
|
31
|
+
out.push({ path: "", keyword: "schema", message: "invalid" });
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
ok(node, base, v) {
|
|
35
|
+
return this.c.check(node, base)(v);
|
|
36
|
+
}
|
|
37
|
+
// For $dynamicRef schemas this check runs outside the original dynamic scope, so their errors are approximate.
|
|
38
|
+
walk(node, base, v, path, out) {
|
|
39
|
+
if (node === true)
|
|
40
|
+
return;
|
|
41
|
+
if (node === false) {
|
|
42
|
+
out.push({ path, keyword: "false", message: "no value is allowed here" });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!isSchemaObject(node))
|
|
46
|
+
return;
|
|
47
|
+
const b = this.c.r.baseFor(node, base);
|
|
48
|
+
if (this.ok(node, b, v))
|
|
49
|
+
return;
|
|
50
|
+
const start = out.length;
|
|
51
|
+
const push = (keyword, message, at = path) => {
|
|
52
|
+
out.push({ path: at, keyword, message });
|
|
53
|
+
};
|
|
54
|
+
if (this.c.draft === "7" && typeof node.$ref === "string") {
|
|
55
|
+
this.walkRef(node.$ref, b, v, path, out);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (node.type !== undefined) {
|
|
59
|
+
const types = Array.isArray(node.type) ? node.type : [node.type];
|
|
60
|
+
const checks = types.map((t) => (typeof t === "string" ? TYPE_CHECKS.get(t) : undefined) ?? NEVER);
|
|
61
|
+
if (!checks.some((check) => check(v))) {
|
|
62
|
+
push("type", `expected ${types.join(" or ")}, got ${typeName(v)}`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(node.enum) && !enumCheck(node.enum)(v))
|
|
67
|
+
push("enum", `expected one of ${listValues(node.enum)}`);
|
|
68
|
+
if (Object.hasOwn(node, "const") && !constCheck(node.const)(v))
|
|
69
|
+
push("const", `expected ${JSON.stringify(node.const)}`);
|
|
70
|
+
if (typeof v === "string" && node.type !== "bytes")
|
|
71
|
+
this.walkString(node, v, push);
|
|
72
|
+
if (v instanceof Uint8Array && node.type === "bytes")
|
|
73
|
+
this.walkBytes(node, v, push);
|
|
74
|
+
if (typeof v === "number")
|
|
75
|
+
this.walkNumber(node, v, push);
|
|
76
|
+
if (isObject(v))
|
|
77
|
+
this.walkObject(node, b, v, path, out, push);
|
|
78
|
+
if (Array.isArray(v))
|
|
79
|
+
this.walkArray(node, b, v, path, out, push);
|
|
80
|
+
if (Array.isArray(node.allOf))
|
|
81
|
+
for (const s of node.allOf)
|
|
82
|
+
this.walk(s, b, v, path, out);
|
|
83
|
+
if (Array.isArray(node.anyOf))
|
|
84
|
+
this.walkUnion(node.anyOf, b, v, path, out, false);
|
|
85
|
+
if (Array.isArray(node.oneOf))
|
|
86
|
+
this.walkUnion(node.oneOf, b, v, path, out, true);
|
|
87
|
+
if (node.not !== undefined && this.ok(node.not, b, v))
|
|
88
|
+
push("not", "must not match the schema in not");
|
|
89
|
+
if (node.if !== undefined) {
|
|
90
|
+
const branch = this.ok(node.if, b, v) ? node.then : node.else;
|
|
91
|
+
if (branch !== undefined)
|
|
92
|
+
this.walk(branch, b, v, path, out);
|
|
93
|
+
}
|
|
94
|
+
if (typeof node.$ref === "string")
|
|
95
|
+
this.walkRef(node.$ref, b, v, path, out);
|
|
96
|
+
if (out.length === start && (node.unevaluatedProperties !== undefined || node.unevaluatedItems !== undefined)) {
|
|
97
|
+
this.walkUnevaluated(node, b, v, path, out);
|
|
98
|
+
}
|
|
99
|
+
if (out.length === start && typeof node.$dynamicRef === "string") {
|
|
100
|
+
push("$dynamicRef", "does not match the dynamically referenced schema");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
walkRef(ref, base, v, path, out) {
|
|
104
|
+
const target = this.c.r.resolve(ref, base);
|
|
105
|
+
if (target.node === false && this.c.r.isUnresolved(ref, base)) {
|
|
106
|
+
out.push({ path, keyword: "$ref", message: `unresolved reference ${ref}` });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!isSchemaObject(target.node) || typeof v !== "object" || v === null) {
|
|
110
|
+
this.walk(target.node, target.base, v, path, out);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.memo ??= new Map();
|
|
114
|
+
let values = this.memo.get(target.node);
|
|
115
|
+
const known = values?.get(v);
|
|
116
|
+
if (known !== undefined && known.path === path) {
|
|
117
|
+
out.push(...known.errors);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const errors = [];
|
|
121
|
+
this.walk(target.node, target.base, v, path, errors);
|
|
122
|
+
if (values === undefined) {
|
|
123
|
+
values = new Map();
|
|
124
|
+
this.memo.set(target.node, values);
|
|
125
|
+
}
|
|
126
|
+
values.set(v, { path, errors });
|
|
127
|
+
out.push(...errors);
|
|
128
|
+
}
|
|
129
|
+
walkString(node, v, push) {
|
|
130
|
+
const n = codePoints(v);
|
|
131
|
+
if (typeof node.minLength === "number" && n < node.minLength) {
|
|
132
|
+
push("minLength", `expected at least ${node.minLength} characters`);
|
|
133
|
+
}
|
|
134
|
+
if (typeof node.maxLength === "number" && n > node.maxLength) {
|
|
135
|
+
push("maxLength", `expected at most ${node.maxLength} characters`);
|
|
136
|
+
}
|
|
137
|
+
if (typeof node.pattern === "string" && !sharedRegex(node.pattern).test(v)) {
|
|
138
|
+
push("pattern", `expected to match ${node.pattern}`);
|
|
139
|
+
}
|
|
140
|
+
const formats = this.c.formats;
|
|
141
|
+
const format = formats !== undefined && typeof node.format === "string" && Object.hasOwn(formats, node.format)
|
|
142
|
+
? formats[node.format]
|
|
143
|
+
: undefined;
|
|
144
|
+
if (format !== undefined && !format(v))
|
|
145
|
+
push("format", `expected format ${node.format}`);
|
|
146
|
+
}
|
|
147
|
+
walkBytes(node, v, push) {
|
|
148
|
+
if (typeof node.minLength === "number" && v.length < node.minLength) {
|
|
149
|
+
push("minLength", `expected at least ${node.minLength} bytes`);
|
|
150
|
+
}
|
|
151
|
+
if (typeof node.maxLength === "number" && v.length > node.maxLength) {
|
|
152
|
+
push("maxLength", `expected at most ${node.maxLength} bytes`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
walkNumber(node, v, push) {
|
|
156
|
+
if (typeof node.minimum === "number" && v < node.minimum)
|
|
157
|
+
push("minimum", `expected >= ${node.minimum}`);
|
|
158
|
+
if (typeof node.maximum === "number" && v > node.maximum)
|
|
159
|
+
push("maximum", `expected <= ${node.maximum}`);
|
|
160
|
+
if (typeof node.exclusiveMinimum === "number" && v <= node.exclusiveMinimum) {
|
|
161
|
+
push("exclusiveMinimum", `expected > ${node.exclusiveMinimum}`);
|
|
162
|
+
}
|
|
163
|
+
if (typeof node.exclusiveMaximum === "number" && v >= node.exclusiveMaximum) {
|
|
164
|
+
push("exclusiveMaximum", `expected < ${node.exclusiveMaximum}`);
|
|
165
|
+
}
|
|
166
|
+
if (typeof node.multipleOf === "number" && !isMultiple(v, node.multipleOf)) {
|
|
167
|
+
push("multipleOf", `expected a multiple of ${node.multipleOf}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
walkObject(node, b, v, path, out, push) {
|
|
171
|
+
const properties = isSchemaObject(node.properties) ? node.properties : {};
|
|
172
|
+
const required = Array.isArray(node.required) ? node.required : [];
|
|
173
|
+
for (const k of required) {
|
|
174
|
+
if (typeof k === "string" && (!Object.hasOwn(v, k) || v[k] === undefined))
|
|
175
|
+
push("required", "missing", pointer(path, k));
|
|
176
|
+
}
|
|
177
|
+
for (const k of Object.keys(properties)) {
|
|
178
|
+
if (Object.hasOwn(v, k) && v[k] !== undefined)
|
|
179
|
+
this.walk(properties[k], b, v[k], pointer(path, k), out);
|
|
180
|
+
}
|
|
181
|
+
const patterns = isSchemaObject(node.patternProperties) ? Object.entries(node.patternProperties) : [];
|
|
182
|
+
for (const k of Object.keys(v)) {
|
|
183
|
+
let matched = Object.hasOwn(properties, k);
|
|
184
|
+
for (const [p, s] of patterns) {
|
|
185
|
+
if (sharedRegex(p).test(k)) {
|
|
186
|
+
matched = true;
|
|
187
|
+
this.walk(s, b, v[k], pointer(path, k), out);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!matched && node.additionalProperties !== undefined) {
|
|
191
|
+
if (node.additionalProperties === false)
|
|
192
|
+
push("additionalProperties", "unknown field", pointer(path, k));
|
|
193
|
+
else
|
|
194
|
+
this.walk(node.additionalProperties, b, v[k], pointer(path, k), out);
|
|
195
|
+
}
|
|
196
|
+
if (node.propertyNames !== undefined && !this.ok(node.propertyNames, b, k)) {
|
|
197
|
+
push("propertyNames", "invalid property name", pointer(path, k));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const count = Object.keys(v).length;
|
|
201
|
+
if (typeof node.minProperties === "number" && count < node.minProperties) {
|
|
202
|
+
push("minProperties", `expected at least ${node.minProperties} properties`);
|
|
203
|
+
}
|
|
204
|
+
if (typeof node.maxProperties === "number" && count > node.maxProperties) {
|
|
205
|
+
push("maxProperties", `expected at most ${node.maxProperties} properties`);
|
|
206
|
+
}
|
|
207
|
+
const dependencies = {
|
|
208
|
+
...(this.c.draft === "7" || !isSchemaObject(node.dependentRequired) ? {} : node.dependentRequired),
|
|
209
|
+
...(isSchemaObject(node.dependencies) ? node.dependencies : {}),
|
|
210
|
+
};
|
|
211
|
+
for (const [k, d] of Object.entries(dependencies)) {
|
|
212
|
+
if (!Object.hasOwn(v, k))
|
|
213
|
+
continue;
|
|
214
|
+
if (!Array.isArray(d))
|
|
215
|
+
this.walk(d, b, v, path, out);
|
|
216
|
+
else
|
|
217
|
+
for (const r of d)
|
|
218
|
+
if (!Object.hasOwn(v, r))
|
|
219
|
+
push("dependentRequired", `required when ${k} is present`, pointer(path, r));
|
|
220
|
+
}
|
|
221
|
+
if (this.c.draft !== "7" && isSchemaObject(node.dependentSchemas)) {
|
|
222
|
+
for (const [k, s] of Object.entries(node.dependentSchemas))
|
|
223
|
+
if (Object.hasOwn(v, k))
|
|
224
|
+
this.walk(s, b, v, path, out);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
walkArray(node, b, v, path, out, push) {
|
|
228
|
+
let prefix = [];
|
|
229
|
+
let rest;
|
|
230
|
+
if (Array.isArray(node.items)) {
|
|
231
|
+
prefix = node.items;
|
|
232
|
+
rest = node.additionalItems;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
if (this.c.draft !== "7" && Array.isArray(node.prefixItems))
|
|
236
|
+
prefix = node.prefixItems;
|
|
237
|
+
rest = node.items;
|
|
238
|
+
}
|
|
239
|
+
for (let i = 0; i < v.length; i++) {
|
|
240
|
+
const s = i < prefix.length ? prefix[i] : rest;
|
|
241
|
+
if (s !== undefined)
|
|
242
|
+
this.walk(s, b, v[i], `${path}/${i}`, out);
|
|
243
|
+
}
|
|
244
|
+
if (typeof node.minItems === "number" && v.length < node.minItems) {
|
|
245
|
+
push("minItems", `expected at least ${node.minItems} items`);
|
|
246
|
+
}
|
|
247
|
+
if (typeof node.maxItems === "number" && v.length > node.maxItems) {
|
|
248
|
+
push("maxItems", `expected at most ${node.maxItems} items`);
|
|
249
|
+
}
|
|
250
|
+
if (node.uniqueItems === true && !uniqueCheck(v))
|
|
251
|
+
push("uniqueItems", "expected unique items");
|
|
252
|
+
if (node.contains !== undefined) {
|
|
253
|
+
const draft7 = this.c.draft === "7";
|
|
254
|
+
const min = draft7 || typeof node.minContains !== "number" ? 1 : node.minContains;
|
|
255
|
+
const max = draft7 || typeof node.maxContains !== "number" ? Number.POSITIVE_INFINITY : node.maxContains;
|
|
256
|
+
if (!containsCheck(this.c.check(node.contains, b), min, max)(v)) {
|
|
257
|
+
push("contains", containsMessage(min, max));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
walkUnion(branches, b, v, path, out, exactlyOne) {
|
|
262
|
+
const matches = branches.filter((s) => this.ok(s, b, v)).length;
|
|
263
|
+
if (matches === 1 || (!exactlyOne && matches > 0))
|
|
264
|
+
return;
|
|
265
|
+
const keyword = exactlyOne ? "oneOf" : "anyOf";
|
|
266
|
+
if (matches > 1) {
|
|
267
|
+
out.push({ path, keyword, message: "matches more than one alternative" });
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
// A tagged union reports the branch its tag selects; otherwise the branch whose first error is deepest.
|
|
271
|
+
const tag = this.tagOf(branches, b);
|
|
272
|
+
if (tag !== undefined && isObject(v)) {
|
|
273
|
+
const i = tag.values.indexOf(v[tag.key]);
|
|
274
|
+
if (i < 0)
|
|
275
|
+
out.push({
|
|
276
|
+
path: pointer(path, tag.key),
|
|
277
|
+
keyword,
|
|
278
|
+
message: `expected one of ${listValues(tag.values)}`,
|
|
279
|
+
});
|
|
280
|
+
else
|
|
281
|
+
this.walk(branches[i], b, v, path, out);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
// An object is blamed on the branch that declares most of its properties (the one it was most likely meant for),
|
|
285
|
+
// then on the branch whose first error is deepest.
|
|
286
|
+
let best;
|
|
287
|
+
for (const s of branches) {
|
|
288
|
+
const errors = [];
|
|
289
|
+
this.walk(s, b, v, path, errors);
|
|
290
|
+
if (errors.length === 0)
|
|
291
|
+
continue;
|
|
292
|
+
const declared = isObject(v) ? this.declaredKeys(s, b, v) : 0;
|
|
293
|
+
const better = best === undefined ||
|
|
294
|
+
declared > best.declared ||
|
|
295
|
+
(declared === best.declared && errors[0].path.length > best.errors[0].path.length);
|
|
296
|
+
if (better)
|
|
297
|
+
best = { errors, declared };
|
|
298
|
+
}
|
|
299
|
+
out.push(...(best?.errors ?? [{ path, keyword, message: "matches no alternative" }]));
|
|
300
|
+
}
|
|
301
|
+
/** How many of the keys of `v` the branch `s` (through a `$ref`) declares in `properties`. */
|
|
302
|
+
declaredKeys(s, b, v) {
|
|
303
|
+
const node = isSchemaObject(s) && typeof s.$ref === "string" ? this.c.r.resolve(s.$ref, b).node : s;
|
|
304
|
+
const properties = isSchemaObject(node) && isSchemaObject(node.properties) ? node.properties : {};
|
|
305
|
+
return Object.keys(v).filter((k) => Object.hasOwn(properties, k)).length;
|
|
306
|
+
}
|
|
307
|
+
tagOf(branches, b) {
|
|
308
|
+
const resolved = branches.map((s) => isSchemaObject(s) && typeof s.$ref === "string" ? this.c.r.resolve(s.$ref, b).node : s);
|
|
309
|
+
const first = resolved[0];
|
|
310
|
+
if (!isSchemaObject(first) || !isSchemaObject(first.properties))
|
|
311
|
+
return undefined;
|
|
312
|
+
for (const key of Object.keys(first.properties)) {
|
|
313
|
+
const values = resolved.map((s) => {
|
|
314
|
+
const tag = isSchemaObject(s) && isSchemaObject(s.properties) ? s.properties[key] : undefined;
|
|
315
|
+
return isSchemaObject(tag) ? tag.const : undefined;
|
|
316
|
+
});
|
|
317
|
+
const primitive = values.every((x) => x !== undefined && (typeof x !== "object" || x === null));
|
|
318
|
+
if (primitive && new Set(values).size === values.length)
|
|
319
|
+
return { key, values };
|
|
320
|
+
}
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
walkUnevaluated(node, b, v, path, out) {
|
|
324
|
+
const { unevaluatedProperties, unevaluatedItems, ...rest } = node;
|
|
325
|
+
const a = newAnnotations();
|
|
326
|
+
this.c.annotating(rest, b)(v, a);
|
|
327
|
+
if (isObject(v) && unevaluatedProperties !== undefined && !a.allProps) {
|
|
328
|
+
for (const k of Object.keys(v)) {
|
|
329
|
+
if (a.props?.has(k))
|
|
330
|
+
continue;
|
|
331
|
+
if (unevaluatedProperties === false) {
|
|
332
|
+
out.push({ path: pointer(path, k), keyword: "unevaluatedProperties", message: "unknown field" });
|
|
333
|
+
}
|
|
334
|
+
else
|
|
335
|
+
this.walk(unevaluatedProperties, b, v[k], pointer(path, k), out);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (Array.isArray(v) && unevaluatedItems !== undefined && !a.allItems) {
|
|
339
|
+
for (let i = a.items; i < v.length; i++) {
|
|
340
|
+
if (a.indexes?.has(i))
|
|
341
|
+
continue;
|
|
342
|
+
if (unevaluatedItems === false) {
|
|
343
|
+
out.push({ path: `${path}/${i}`, keyword: "unevaluatedItems", message: "unexpected item" });
|
|
344
|
+
}
|
|
345
|
+
else
|
|
346
|
+
this.walk(unevaluatedItems, b, v[i], `${path}/${i}`, out);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// Enum errors name the allowed values; a long list (an enum of thousands) is cut, so the message stays readable.
|
|
352
|
+
const LISTED_VALUES = 20;
|
|
353
|
+
/** `values` as JSON, at most LISTED_VALUES of them, then how many more there are. */
|
|
354
|
+
function listValues(values) {
|
|
355
|
+
if (values.length <= LISTED_VALUES)
|
|
356
|
+
return JSON.stringify(values);
|
|
357
|
+
const listed = JSON.stringify(values.slice(0, LISTED_VALUES));
|
|
358
|
+
return `${listed.slice(0, -1)}, ... and ${values.length - LISTED_VALUES} more]`;
|
|
359
|
+
}
|
|
360
|
+
function containsMessage(min, max) {
|
|
361
|
+
if (max === Number.POSITIVE_INFINITY)
|
|
362
|
+
return `expected at least ${min} matching ${min === 1 ? "item" : "items"}`;
|
|
363
|
+
if (min === 0)
|
|
364
|
+
return `expected at most ${max} matching ${max === 1 ? "item" : "items"}`;
|
|
365
|
+
return `expected between ${min} and ${max} matching items`;
|
|
366
|
+
}
|
|
367
|
+
function pointer(path, key) {
|
|
368
|
+
return `${path}/${String(key).replace(/~/g, "~0").replace(/\//g, "~1")}`;
|
|
369
|
+
}
|
|
370
|
+
function typeName(v) {
|
|
371
|
+
if (v === null)
|
|
372
|
+
return "null";
|
|
373
|
+
if (Array.isArray(v))
|
|
374
|
+
return "array";
|
|
375
|
+
if (v instanceof Uint8Array)
|
|
376
|
+
return "bytes";
|
|
377
|
+
if (typeof v === "number" && Number.isInteger(v))
|
|
378
|
+
return "integer";
|
|
379
|
+
return typeof v;
|
|
380
|
+
}
|
|
381
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../src/explain.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,6FAA6F;AAE7F,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACN,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,QAAQ,EACR,KAAK,EACL,WAAW,EACX,WAAW,GACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,gDAAgD;AAChD,MAAM,OAAO,SAAS;IACJ,CAAC,CAAW;IACZ,MAAM,CAAU;IACjC;;;OAGG;IACK,IAAI,GAAsF,SAAS,CAAC;IAE5G,YAAY,QAAkB,EAAE,MAAe;QAC9C,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,QAAQ,CAAC,IAAI,EAAE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AAO,oBAAoB,GAAG,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACzF,OAAO,oBAAoB,GAAG,QAAQ,GAAG,iBAAiB,CAAC;AAC5D,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,GAAoB;IAClD,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU;IAC3B,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,OAAO,CAAC;IACrC,IAAI,CAAC,YAAY,UAAU;QAAE,OAAO,OAAO,CAAC;IAC5C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACnE,OAAO,OAAO,CAAC,CAAC;AACjB,CAAC","sourcesContent":["// Errors of a failed value: a walk over the schema that reports each failing keyword at the value it failed on.\n// It runs only for values that failed the check, using the compiler's checks for subschemas.\n\nimport { newAnnotations } from \"./annotations.ts\";\nimport {\n\tcodePoints,\n\tconstCheck,\n\tcontainsCheck,\n\tenumCheck,\n\tisMultiple,\n\tisObject,\n\tNEVER,\n\tTYPE_CHECKS,\n\tuniqueCheck,\n} from \"./checks.ts\";\nimport type { Compiler } from \"./compiler.ts\";\nimport { isSchemaObject } from \"./resolver.ts\";\nimport { sharedRegex } from \"./shared.ts\";\nimport type { SchemaObject, ValidationError } from \"./types.ts\";\n\n/** Explains failures of one compiled schema. */\nexport class Explainer {\n\tprivate readonly c: Compiler;\n\tprivate readonly schema: unknown;\n\t/**\n\t * The errors of `$ref` targets for object values, within one errors() call: a recursive union explains each branch\n\t * to pick the one to blame, and every branch would explain the same children again, exponentially in the depth.\n\t */\n\tprivate memo: Map<object, Map<object, { path: string; errors: ValidationError[] }>> | undefined = undefined;\n\n\tconstructor(compiler: Compiler, schema: unknown) {\n\t\tthis.c = compiler;\n\t\tthis.schema = schema;\n\t\tcompiler.root();\n\t}\n\n\t/** The errors of `value`, at least one (`value` failed the check). */\n\terrors(value: unknown): ValidationError[] {\n\t\tconst out: ValidationError[] = [];\n\t\ttry {\n\t\t\tthis.walk(this.schema, this.c.r.rootBase, value, \"\", out);\n\t\t} finally {\n\t\t\tthis.memo = undefined;\n\t\t}\n\t\tif (out.length === 0) out.push({ path: \"\", keyword: \"schema\", message: \"invalid\" });\n\t\treturn out;\n\t}\n\n\tprivate ok(node: unknown, base: string, v: unknown): boolean {\n\t\treturn this.c.check(node, base)(v);\n\t}\n\n\t// For $dynamicRef schemas this check runs outside the original dynamic scope, so their errors are approximate.\n\tprivate walk(node: unknown, base: string, v: unknown, path: string, out: ValidationError[]): void {\n\t\tif (node === true) return;\n\t\tif (node === false) {\n\t\t\tout.push({ path, keyword: \"false\", message: \"no value is allowed here\" });\n\t\t\treturn;\n\t\t}\n\t\tif (!isSchemaObject(node)) return;\n\t\tconst b = this.c.r.baseFor(node, base);\n\t\tif (this.ok(node, b, v)) return;\n\t\tconst start = out.length;\n\t\tconst push = (keyword: string, message: string, at = path) => {\n\t\t\tout.push({ path: at, keyword, message });\n\t\t};\n\t\tif (this.c.draft === \"7\" && typeof node.$ref === \"string\") {\n\t\t\tthis.walkRef(node.$ref, b, v, path, out);\n\t\t\treturn;\n\t\t}\n\t\tif (node.type !== undefined) {\n\t\t\tconst types = Array.isArray(node.type) ? node.type : [node.type];\n\t\t\tconst checks = types.map((t) => (typeof t === \"string\" ? TYPE_CHECKS.get(t) : undefined) ?? NEVER);\n\t\t\tif (!checks.some((check) => check(v))) {\n\t\t\t\tpush(\"type\", `expected ${types.join(\" or \")}, got ${typeName(v)}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(node.enum) && !enumCheck(node.enum)(v))\n\t\t\tpush(\"enum\", `expected one of ${listValues(node.enum)}`);\n\t\tif (Object.hasOwn(node, \"const\") && !constCheck(node.const)(v))\n\t\t\tpush(\"const\", `expected ${JSON.stringify(node.const)}`);\n\t\tif (typeof v === \"string\" && node.type !== \"bytes\") this.walkString(node, v, push);\n\t\tif (v instanceof Uint8Array && node.type === \"bytes\") this.walkBytes(node, v, push);\n\t\tif (typeof v === \"number\") this.walkNumber(node, v, push);\n\t\tif (isObject(v)) this.walkObject(node, b, v, path, out, push);\n\t\tif (Array.isArray(v)) this.walkArray(node, b, v, path, out, push);\n\t\tif (Array.isArray(node.allOf)) for (const s of node.allOf) this.walk(s, b, v, path, out);\n\t\tif (Array.isArray(node.anyOf)) this.walkUnion(node.anyOf, b, v, path, out, false);\n\t\tif (Array.isArray(node.oneOf)) this.walkUnion(node.oneOf, b, v, path, out, true);\n\t\tif (node.not !== undefined && this.ok(node.not, b, v)) push(\"not\", \"must not match the schema in not\");\n\t\tif (node.if !== undefined) {\n\t\t\tconst branch = this.ok(node.if, b, v) ? node.then : node.else;\n\t\t\tif (branch !== undefined) this.walk(branch, b, v, path, out);\n\t\t}\n\t\tif (typeof node.$ref === \"string\") this.walkRef(node.$ref, b, v, path, out);\n\t\tif (out.length === start && (node.unevaluatedProperties !== undefined || node.unevaluatedItems !== undefined)) {\n\t\t\tthis.walkUnevaluated(node, b, v, path, out);\n\t\t}\n\t\tif (out.length === start && typeof node.$dynamicRef === \"string\") {\n\t\t\tpush(\"$dynamicRef\", \"does not match the dynamically referenced schema\");\n\t\t}\n\t}\n\n\tprivate walkRef(ref: string, base: string, v: unknown, path: string, out: ValidationError[]): void {\n\t\tconst target = this.c.r.resolve(ref, base);\n\t\tif (target.node === false && this.c.r.isUnresolved(ref, base)) {\n\t\t\tout.push({ path, keyword: \"$ref\", message: `unresolved reference ${ref}` });\n\t\t\treturn;\n\t\t}\n\t\tif (!isSchemaObject(target.node) || typeof v !== \"object\" || v === null) {\n\t\t\tthis.walk(target.node, target.base, v, path, out);\n\t\t\treturn;\n\t\t}\n\t\tthis.memo ??= new Map();\n\t\tlet values = this.memo.get(target.node);\n\t\tconst known = values?.get(v);\n\t\tif (known !== undefined && known.path === path) {\n\t\t\tout.push(...known.errors);\n\t\t\treturn;\n\t\t}\n\t\tconst errors: ValidationError[] = [];\n\t\tthis.walk(target.node, target.base, v, path, errors);\n\t\tif (values === undefined) {\n\t\t\tvalues = new Map();\n\t\t\tthis.memo.set(target.node, values);\n\t\t}\n\t\tvalues.set(v, { path, errors });\n\t\tout.push(...errors);\n\t}\n\n\tprivate walkString(node: SchemaObject, v: string, push: Push): void {\n\t\tconst n = codePoints(v);\n\t\tif (typeof node.minLength === \"number\" && n < node.minLength) {\n\t\t\tpush(\"minLength\", `expected at least ${node.minLength} characters`);\n\t\t}\n\t\tif (typeof node.maxLength === \"number\" && n > node.maxLength) {\n\t\t\tpush(\"maxLength\", `expected at most ${node.maxLength} characters`);\n\t\t}\n\t\tif (typeof node.pattern === \"string\" && !sharedRegex(node.pattern).test(v)) {\n\t\t\tpush(\"pattern\", `expected to match ${node.pattern}`);\n\t\t}\n\t\tconst formats = this.c.formats;\n\t\tconst format =\n\t\t\tformats !== undefined && typeof node.format === \"string\" && Object.hasOwn(formats, node.format)\n\t\t\t\t? formats[node.format]\n\t\t\t\t: undefined;\n\t\tif (format !== undefined && !format(v)) push(\"format\", `expected format ${node.format}`);\n\t}\n\n\tprivate walkBytes(node: SchemaObject, v: Uint8Array, push: Push): void {\n\t\tif (typeof node.minLength === \"number\" && v.length < node.minLength) {\n\t\t\tpush(\"minLength\", `expected at least ${node.minLength} bytes`);\n\t\t}\n\t\tif (typeof node.maxLength === \"number\" && v.length > node.maxLength) {\n\t\t\tpush(\"maxLength\", `expected at most ${node.maxLength} bytes`);\n\t\t}\n\t}\n\n\tprivate walkNumber(node: SchemaObject, v: number, push: Push): void {\n\t\tif (typeof node.minimum === \"number\" && v < node.minimum) push(\"minimum\", `expected >= ${node.minimum}`);\n\t\tif (typeof node.maximum === \"number\" && v > node.maximum) push(\"maximum\", `expected <= ${node.maximum}`);\n\t\tif (typeof node.exclusiveMinimum === \"number\" && v <= node.exclusiveMinimum) {\n\t\t\tpush(\"exclusiveMinimum\", `expected > ${node.exclusiveMinimum}`);\n\t\t}\n\t\tif (typeof node.exclusiveMaximum === \"number\" && v >= node.exclusiveMaximum) {\n\t\t\tpush(\"exclusiveMaximum\", `expected < ${node.exclusiveMaximum}`);\n\t\t}\n\t\tif (typeof node.multipleOf === \"number\" && !isMultiple(v, node.multipleOf)) {\n\t\t\tpush(\"multipleOf\", `expected a multiple of ${node.multipleOf}`);\n\t\t}\n\t}\n\n\tprivate walkObject(\n\t\tnode: SchemaObject,\n\t\tb: string,\n\t\tv: Record<string, unknown>,\n\t\tpath: string,\n\t\tout: ValidationError[],\n\t\tpush: Push,\n\t): void {\n\t\tconst properties = isSchemaObject(node.properties) ? node.properties : {};\n\t\tconst required = Array.isArray(node.required) ? node.required : [];\n\t\tfor (const k of required) {\n\t\t\tif (typeof k === \"string\" && (!Object.hasOwn(v, k) || v[k] === undefined))\n\t\t\t\tpush(\"required\", \"missing\", pointer(path, k));\n\t\t}\n\t\tfor (const k of Object.keys(properties)) {\n\t\t\tif (Object.hasOwn(v, k) && v[k] !== undefined) this.walk(properties[k], b, v[k], pointer(path, k), out);\n\t\t}\n\t\tconst patterns = isSchemaObject(node.patternProperties) ? Object.entries(node.patternProperties) : [];\n\t\tfor (const k of Object.keys(v)) {\n\t\t\tlet matched = Object.hasOwn(properties, k);\n\t\t\tfor (const [p, s] of patterns) {\n\t\t\t\tif (sharedRegex(p).test(k)) {\n\t\t\t\t\tmatched = true;\n\t\t\t\t\tthis.walk(s, b, v[k], pointer(path, k), out);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!matched && node.additionalProperties !== undefined) {\n\t\t\t\tif (node.additionalProperties === false) push(\"additionalProperties\", \"unknown field\", pointer(path, k));\n\t\t\t\telse this.walk(node.additionalProperties, b, v[k], pointer(path, k), out);\n\t\t\t}\n\t\t\tif (node.propertyNames !== undefined && !this.ok(node.propertyNames, b, k)) {\n\t\t\t\tpush(\"propertyNames\", \"invalid property name\", pointer(path, k));\n\t\t\t}\n\t\t}\n\t\tconst count = Object.keys(v).length;\n\t\tif (typeof node.minProperties === \"number\" && count < node.minProperties) {\n\t\t\tpush(\"minProperties\", `expected at least ${node.minProperties} properties`);\n\t\t}\n\t\tif (typeof node.maxProperties === \"number\" && count > node.maxProperties) {\n\t\t\tpush(\"maxProperties\", `expected at most ${node.maxProperties} properties`);\n\t\t}\n\t\tconst dependencies = {\n\t\t\t...(this.c.draft === \"7\" || !isSchemaObject(node.dependentRequired) ? {} : node.dependentRequired),\n\t\t\t...(isSchemaObject(node.dependencies) ? node.dependencies : {}),\n\t\t};\n\t\tfor (const [k, d] of Object.entries(dependencies)) {\n\t\t\tif (!Object.hasOwn(v, k)) continue;\n\t\t\tif (!Array.isArray(d)) this.walk(d, b, v, path, out);\n\t\t\telse\n\t\t\t\tfor (const r of d)\n\t\t\t\t\tif (!Object.hasOwn(v, r)) push(\"dependentRequired\", `required when ${k} is present`, pointer(path, r));\n\t\t}\n\t\tif (this.c.draft !== \"7\" && isSchemaObject(node.dependentSchemas)) {\n\t\t\tfor (const [k, s] of Object.entries(node.dependentSchemas))\n\t\t\t\tif (Object.hasOwn(v, k)) this.walk(s, b, v, path, out);\n\t\t}\n\t}\n\n\tprivate walkArray(\n\t\tnode: SchemaObject,\n\t\tb: string,\n\t\tv: unknown[],\n\t\tpath: string,\n\t\tout: ValidationError[],\n\t\tpush: Push,\n\t): void {\n\t\tlet prefix: readonly unknown[] = [];\n\t\tlet rest: unknown;\n\t\tif (Array.isArray(node.items)) {\n\t\t\tprefix = node.items;\n\t\t\trest = node.additionalItems;\n\t\t} else {\n\t\t\tif (this.c.draft !== \"7\" && Array.isArray(node.prefixItems)) prefix = node.prefixItems;\n\t\t\trest = node.items;\n\t\t}\n\t\tfor (let i = 0; i < v.length; i++) {\n\t\t\tconst s = i < prefix.length ? prefix[i] : rest;\n\t\t\tif (s !== undefined) this.walk(s, b, v[i], `${path}/${i}`, out);\n\t\t}\n\t\tif (typeof node.minItems === \"number\" && v.length < node.minItems) {\n\t\t\tpush(\"minItems\", `expected at least ${node.minItems} items`);\n\t\t}\n\t\tif (typeof node.maxItems === \"number\" && v.length > node.maxItems) {\n\t\t\tpush(\"maxItems\", `expected at most ${node.maxItems} items`);\n\t\t}\n\t\tif (node.uniqueItems === true && !uniqueCheck(v)) push(\"uniqueItems\", \"expected unique items\");\n\t\tif (node.contains !== undefined) {\n\t\t\tconst draft7 = this.c.draft === \"7\";\n\t\t\tconst min = draft7 || typeof node.minContains !== \"number\" ? 1 : node.minContains;\n\t\t\tconst max = draft7 || typeof node.maxContains !== \"number\" ? Number.POSITIVE_INFINITY : node.maxContains;\n\t\t\tif (!containsCheck(this.c.check(node.contains, b), min, max)(v)) {\n\t\t\t\tpush(\"contains\", containsMessage(min, max));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate walkUnion(\n\t\tbranches: readonly unknown[],\n\t\tb: string,\n\t\tv: unknown,\n\t\tpath: string,\n\t\tout: ValidationError[],\n\t\texactlyOne: boolean,\n\t): void {\n\t\tconst matches = branches.filter((s) => this.ok(s, b, v)).length;\n\t\tif (matches === 1 || (!exactlyOne && matches > 0)) return;\n\t\tconst keyword = exactlyOne ? \"oneOf\" : \"anyOf\";\n\t\tif (matches > 1) {\n\t\t\tout.push({ path, keyword, message: \"matches more than one alternative\" });\n\t\t\treturn;\n\t\t}\n\t\t// A tagged union reports the branch its tag selects; otherwise the branch whose first error is deepest.\n\t\tconst tag = this.tagOf(branches, b);\n\t\tif (tag !== undefined && isObject(v)) {\n\t\t\tconst i = tag.values.indexOf(v[tag.key]);\n\t\t\tif (i < 0)\n\t\t\t\tout.push({\n\t\t\t\t\tpath: pointer(path, tag.key),\n\t\t\t\t\tkeyword,\n\t\t\t\t\tmessage: `expected one of ${listValues(tag.values)}`,\n\t\t\t\t});\n\t\t\telse this.walk(branches[i], b, v, path, out);\n\t\t\treturn;\n\t\t}\n\t\t// An object is blamed on the branch that declares most of its properties (the one it was most likely meant for),\n\t\t// then on the branch whose first error is deepest.\n\t\tlet best: { errors: ValidationError[]; declared: number } | undefined;\n\t\tfor (const s of branches) {\n\t\t\tconst errors: ValidationError[] = [];\n\t\t\tthis.walk(s, b, v, path, errors);\n\t\t\tif (errors.length === 0) continue;\n\t\t\tconst declared = isObject(v) ? this.declaredKeys(s, b, v) : 0;\n\t\t\tconst better =\n\t\t\t\tbest === undefined ||\n\t\t\t\tdeclared > best.declared ||\n\t\t\t\t(declared === best.declared && errors[0].path.length > best.errors[0].path.length);\n\t\t\tif (better) best = { errors, declared };\n\t\t}\n\t\tout.push(...(best?.errors ?? [{ path, keyword, message: \"matches no alternative\" }]));\n\t}\n\n\t/** How many of the keys of `v` the branch `s` (through a `$ref`) declares in `properties`. */\n\tprivate declaredKeys(s: unknown, b: string, v: Record<string, unknown>): number {\n\t\tconst node = isSchemaObject(s) && typeof s.$ref === \"string\" ? this.c.r.resolve(s.$ref, b).node : s;\n\t\tconst properties = isSchemaObject(node) && isSchemaObject(node.properties) ? node.properties : {};\n\t\treturn Object.keys(v).filter((k) => Object.hasOwn(properties, k)).length;\n\t}\n\n\tprivate tagOf(branches: readonly unknown[], b: string): { key: string; values: unknown[] } | undefined {\n\t\tconst resolved = branches.map((s) =>\n\t\t\tisSchemaObject(s) && typeof s.$ref === \"string\" ? this.c.r.resolve(s.$ref, b).node : s,\n\t\t);\n\t\tconst first = resolved[0];\n\t\tif (!isSchemaObject(first) || !isSchemaObject(first.properties)) return undefined;\n\t\tfor (const key of Object.keys(first.properties)) {\n\t\t\tconst values = resolved.map((s) => {\n\t\t\t\tconst tag = isSchemaObject(s) && isSchemaObject(s.properties) ? s.properties[key] : undefined;\n\t\t\t\treturn isSchemaObject(tag) ? tag.const : undefined;\n\t\t\t});\n\t\t\tconst primitive = values.every((x) => x !== undefined && (typeof x !== \"object\" || x === null));\n\t\t\tif (primitive && new Set(values).size === values.length) return { key, values };\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate walkUnevaluated(node: SchemaObject, b: string, v: unknown, path: string, out: ValidationError[]): void {\n\t\tconst { unevaluatedProperties, unevaluatedItems, ...rest } = node;\n\t\tconst a = newAnnotations();\n\t\tthis.c.annotating(rest, b)(v, a);\n\t\tif (isObject(v) && unevaluatedProperties !== undefined && !a.allProps) {\n\t\t\tfor (const k of Object.keys(v)) {\n\t\t\t\tif (a.props?.has(k)) continue;\n\t\t\t\tif (unevaluatedProperties === false) {\n\t\t\t\t\tout.push({ path: pointer(path, k), keyword: \"unevaluatedProperties\", message: \"unknown field\" });\n\t\t\t\t} else this.walk(unevaluatedProperties, b, v[k], pointer(path, k), out);\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(v) && unevaluatedItems !== undefined && !a.allItems) {\n\t\t\tfor (let i = a.items; i < v.length; i++) {\n\t\t\t\tif (a.indexes?.has(i)) continue;\n\t\t\t\tif (unevaluatedItems === false) {\n\t\t\t\t\tout.push({ path: `${path}/${i}`, keyword: \"unevaluatedItems\", message: \"unexpected item\" });\n\t\t\t\t} else this.walk(unevaluatedItems, b, v[i], `${path}/${i}`, out);\n\t\t\t}\n\t\t}\n\t}\n}\n\ntype Push = (keyword: string, message: string, at?: string) => void;\n\n// Enum errors name the allowed values; a long list (an enum of thousands) is cut, so the message stays readable.\nconst LISTED_VALUES = 20;\n\n/** `values` as JSON, at most LISTED_VALUES of them, then how many more there are. */\nfunction listValues(values: readonly unknown[]): string {\n\tif (values.length <= LISTED_VALUES) return JSON.stringify(values);\n\tconst listed = JSON.stringify(values.slice(0, LISTED_VALUES));\n\treturn `${listed.slice(0, -1)}, ... and ${values.length - LISTED_VALUES} more]`;\n}\n\nfunction containsMessage(min: number, max: number): string {\n\tif (max === Number.POSITIVE_INFINITY) return `expected at least ${min} matching ${min === 1 ? \"item\" : \"items\"}`;\n\tif (min === 0) return `expected at most ${max} matching ${max === 1 ? \"item\" : \"items\"}`;\n\treturn `expected between ${min} and ${max} matching items`;\n}\n\nfunction pointer(path: string, key: string | number): string {\n\treturn `${path}/${String(key).replace(/~/g, \"~0\").replace(/\\//g, \"~1\")}`;\n}\n\nfunction typeName(v: unknown): string {\n\tif (v === null) return \"null\";\n\tif (Array.isArray(v)) return \"array\";\n\tif (v instanceof Uint8Array) return \"bytes\";\n\tif (typeof v === \"number\" && Number.isInteger(v)) return \"integer\";\n\treturn typeof v;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FormatCheck } from "../types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Every format JSON Schema 2020-12 defines, by name, plus `url` and `json-pointer-uri-fragment`, which TypeBox and
|
|
4
|
+
* ajv-formats also check. The checks are adapted from TypeBox 1.3.27 (MIT).
|
|
5
|
+
*/
|
|
6
|
+
export declare const formats: Readonly<Record<string, FormatCheck>>;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formats/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuB/C;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAsBxD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The format checks of JSON Schema 2020-12, for compile()'s `formats` option. An optional entry point: schemas
|
|
2
|
+
// compiled without it treat `format` as an annotation and do not bundle these checks.
|
|
3
|
+
import { IsDate } from "./typebox/date.js";
|
|
4
|
+
import { IsDateTime } from "./typebox/date_time.js";
|
|
5
|
+
import { IsDuration } from "./typebox/duration.js";
|
|
6
|
+
import { IsEmail } from "./typebox/email.js";
|
|
7
|
+
import { IsHostname } from "./typebox/hostname.js";
|
|
8
|
+
import { IsIdnEmail } from "./typebox/idn_email.js";
|
|
9
|
+
import { IsIdnHostname } from "./typebox/idn_hostname.js";
|
|
10
|
+
import { IsIPv4 } from "./typebox/ipv4.js";
|
|
11
|
+
import { IsIPv6 } from "./typebox/ipv6.js";
|
|
12
|
+
import { IsIri } from "./typebox/iri.js";
|
|
13
|
+
import { IsIriReference } from "./typebox/iri_reference.js";
|
|
14
|
+
import { IsJsonPointer } from "./typebox/json_pointer.js";
|
|
15
|
+
import { IsJsonPointerUriFragment } from "./typebox/json_pointer_uri_fragment.js";
|
|
16
|
+
import { IsRegex } from "./typebox/regex.js";
|
|
17
|
+
import { IsRelativeJsonPointer } from "./typebox/relative_json_pointer.js";
|
|
18
|
+
import { IsTime } from "./typebox/time.js";
|
|
19
|
+
import { IsUri } from "./typebox/uri.js";
|
|
20
|
+
import { IsUriReference } from "./typebox/uri_reference.js";
|
|
21
|
+
import { IsUriTemplate } from "./typebox/uri_template.js";
|
|
22
|
+
import { IsUrl } from "./typebox/url.js";
|
|
23
|
+
import { IsUuid } from "./typebox/uuid.js";
|
|
24
|
+
/**
|
|
25
|
+
* Every format JSON Schema 2020-12 defines, by name, plus `url` and `json-pointer-uri-fragment`, which TypeBox and
|
|
26
|
+
* ajv-formats also check. The checks are adapted from TypeBox 1.3.27 (MIT).
|
|
27
|
+
*/
|
|
28
|
+
export const formats = Object.freeze({
|
|
29
|
+
date: IsDate,
|
|
30
|
+
"date-time": IsDateTime,
|
|
31
|
+
duration: IsDuration,
|
|
32
|
+
email: IsEmail,
|
|
33
|
+
hostname: IsHostname,
|
|
34
|
+
"idn-email": IsIdnEmail,
|
|
35
|
+
"idn-hostname": IsIdnHostname,
|
|
36
|
+
ipv4: IsIPv4,
|
|
37
|
+
ipv6: IsIPv6,
|
|
38
|
+
iri: IsIri,
|
|
39
|
+
"iri-reference": IsIriReference,
|
|
40
|
+
"json-pointer": IsJsonPointer,
|
|
41
|
+
"json-pointer-uri-fragment": IsJsonPointerUriFragment,
|
|
42
|
+
regex: IsRegex,
|
|
43
|
+
"relative-json-pointer": IsRelativeJsonPointer,
|
|
44
|
+
time: IsTime,
|
|
45
|
+
uri: IsUri,
|
|
46
|
+
"uri-reference": IsUriReference,
|
|
47
|
+
"uri-template": IsUriTemplate,
|
|
48
|
+
url: IsUrl,
|
|
49
|
+
uuid: IsUuid,
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formats/index.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,sFAAsF;AAGtF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAA0C,MAAM,CAAC,MAAM,CAAC;IAC3E,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,UAAU;IACvB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,aAAa;IAC7B,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,eAAe,EAAE,cAAc;IAC/B,cAAc,EAAE,aAAa;IAC7B,2BAA2B,EAAE,wBAAwB;IACrD,KAAK,EAAE,OAAO;IACd,uBAAuB,EAAE,qBAAqB;IAC9C,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,eAAe,EAAE,cAAc;IAC/B,cAAc,EAAE,aAAa;IAC7B,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACZ,CAAC,CAAC","sourcesContent":["// The format checks of JSON Schema 2020-12, for compile()'s `formats` option. An optional entry point: schemas\n// compiled without it treat `format` as an annotation and do not bundle these checks.\n\nimport type { FormatCheck } from \"../types.ts\";\nimport { IsDate } from \"./typebox/date.ts\";\nimport { IsDateTime } from \"./typebox/date_time.ts\";\nimport { IsDuration } from \"./typebox/duration.ts\";\nimport { IsEmail } from \"./typebox/email.ts\";\nimport { IsHostname } from \"./typebox/hostname.ts\";\nimport { IsIdnEmail } from \"./typebox/idn_email.ts\";\nimport { IsIdnHostname } from \"./typebox/idn_hostname.ts\";\nimport { IsIPv4 } from \"./typebox/ipv4.ts\";\nimport { IsIPv6 } from \"./typebox/ipv6.ts\";\nimport { IsIri } from \"./typebox/iri.ts\";\nimport { IsIriReference } from \"./typebox/iri_reference.ts\";\nimport { IsJsonPointer } from \"./typebox/json_pointer.ts\";\nimport { IsJsonPointerUriFragment } from \"./typebox/json_pointer_uri_fragment.ts\";\nimport { IsRegex } from \"./typebox/regex.ts\";\nimport { IsRelativeJsonPointer } from \"./typebox/relative_json_pointer.ts\";\nimport { IsTime } from \"./typebox/time.ts\";\nimport { IsUri } from \"./typebox/uri.ts\";\nimport { IsUriReference } from \"./typebox/uri_reference.ts\";\nimport { IsUriTemplate } from \"./typebox/uri_template.ts\";\nimport { IsUrl } from \"./typebox/url.ts\";\nimport { IsUuid } from \"./typebox/uuid.ts\";\n\n/**\n * Every format JSON Schema 2020-12 defines, by name, plus `url` and `json-pointer-uri-fragment`, which TypeBox and\n * ajv-formats also check. The checks are adapted from TypeBox 1.3.27 (MIT).\n */\nexport const formats: Readonly<Record<string, FormatCheck>> = Object.freeze({\n\tdate: IsDate,\n\t\"date-time\": IsDateTime,\n\tduration: IsDuration,\n\temail: IsEmail,\n\thostname: IsHostname,\n\t\"idn-email\": IsIdnEmail,\n\t\"idn-hostname\": IsIdnHostname,\n\tipv4: IsIPv4,\n\tipv6: IsIPv6,\n\tiri: IsIri,\n\t\"iri-reference\": IsIriReference,\n\t\"json-pointer\": IsJsonPointer,\n\t\"json-pointer-uri-fragment\": IsJsonPointerUriFragment,\n\tregex: IsRegex,\n\t\"relative-json-pointer\": IsRelativeJsonPointer,\n\ttime: IsTime,\n\turi: IsUri,\n\t\"uri-reference\": IsUriReference,\n\t\"uri-template\": IsUriTemplate,\n\turl: IsUrl,\n\tuuid: IsUuid,\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/formats/typebox/date.ts"],"names":[],"mappings":"AAkCA;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO7C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
TypeBox
|
|
4
|
+
|
|
5
|
+
The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2017-2026 Haydn Paterson
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
|
26
|
+
|
|
27
|
+
---------------------------------------------------------------------------*/
|
|
28
|
+
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
29
|
+
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
30
|
+
function IsLeapYear(year) {
|
|
31
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns true if the value is a ISO8601 Date component string
|
|
35
|
+
* @description https://datatracker.ietf.org/doc/html/rfc3339
|
|
36
|
+
* @example `2020-12-12`
|
|
37
|
+
*/
|
|
38
|
+
export function IsDate(value) {
|
|
39
|
+
const matches = DATE.exec(value);
|
|
40
|
+
if (!matches)
|
|
41
|
+
return false;
|
|
42
|
+
const year = +matches[1];
|
|
43
|
+
const month = +matches[2];
|
|
44
|
+
const day = +matches[3];
|
|
45
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && IsLeapYear(year) ? 29 : DAYS[month]);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/formats/typebox/date.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;6EA0B6E;AAE7E,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACjE,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C,SAAS,UAAU,CAAC,IAAY;IAC/B,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC;AACD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa;IACnC,MAAM,OAAO,GAAoB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,MAAM,IAAI,GAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,KAAK,GAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,GAAG,GAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["/*--------------------------------------------------------------------------\n\nTypeBox\n\nThe MIT License (MIT)\n\nCopyright (c) 2017-2026 Haydn Paterson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n---------------------------------------------------------------------------*/\n\nconst DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst DATE = /^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$/;\n\nfunction IsLeapYear(year: number): boolean {\n\treturn year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\n/**\n * Returns true if the value is a ISO8601 Date component string\n * @description https://datatracker.ietf.org/doc/html/rfc3339\n * @example `2020-12-12`\n */\nexport function IsDate(value: string): boolean {\n\tconst matches: string[] | null = DATE.exec(value);\n\tif (!matches) return false;\n\tconst year: number = +matches[1];\n\tconst month: number = +matches[2];\n\tconst day: number = +matches[3];\n\treturn month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && IsLeapYear(year) ? 29 : DAYS[month]);\n}\n"]}
|