baobox 0.1.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/README.md +193 -0
- package/dist/compile/bun-fast-path.d.ts +14 -0
- package/dist/compile/bun-fast-path.d.ts.map +1 -0
- package/dist/compile/emit.d.ts +5 -0
- package/dist/compile/emit.d.ts.map +1 -0
- package/dist/compile/index.d.ts +57 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +4711 -0
- package/dist/compile/index.js.map +65 -0
- package/dist/error/catalog-types.d.ts +30 -0
- package/dist/error/catalog-types.d.ts.map +1 -0
- package/dist/error/collector/advanced.d.ts +5 -0
- package/dist/error/collector/advanced.d.ts.map +1 -0
- package/dist/error/collector/collections-basic.d.ts +5 -0
- package/dist/error/collector/collections-basic.d.ts.map +1 -0
- package/dist/error/collector/collections-derived.d.ts +5 -0
- package/dist/error/collector/collections-derived.d.ts.map +1 -0
- package/dist/error/collector/collections-parameters.d.ts +5 -0
- package/dist/error/collector/collections-parameters.d.ts.map +1 -0
- package/dist/error/collector/collections.d.ts +5 -0
- package/dist/error/collector/collections.d.ts.map +1 -0
- package/dist/error/collector/primitives.d.ts +5 -0
- package/dist/error/collector/primitives.d.ts.map +1 -0
- package/dist/error/collector/shared.d.ts +6 -0
- package/dist/error/collector/shared.d.ts.map +1 -0
- package/dist/error/collector.d.ts +5 -0
- package/dist/error/collector.d.ts.map +1 -0
- package/dist/error/errors.d.ts +23 -0
- package/dist/error/errors.d.ts.map +1 -0
- package/dist/error/index.d.ts +11 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/index.js +3163 -0
- package/dist/error/index.js.map +53 -0
- package/dist/error/locales/de.d.ts +3 -0
- package/dist/error/locales/de.d.ts.map +1 -0
- package/dist/error/locales/en.d.ts +3 -0
- package/dist/error/locales/en.d.ts.map +1 -0
- package/dist/error/locales/es.d.ts +3 -0
- package/dist/error/locales/es.d.ts.map +1 -0
- package/dist/error/locales/fr.d.ts +3 -0
- package/dist/error/locales/fr.d.ts.map +1 -0
- package/dist/error/locales/ja.d.ts +3 -0
- package/dist/error/locales/ja.d.ts.map +1 -0
- package/dist/error/locales/ko.d.ts +3 -0
- package/dist/error/locales/ko.d.ts.map +1 -0
- package/dist/error/locales/pt.d.ts +3 -0
- package/dist/error/locales/pt.d.ts.map +1 -0
- package/dist/error/locales/shared.d.ts +4 -0
- package/dist/error/locales/shared.d.ts.map +1 -0
- package/dist/error/locales/zh.d.ts +4 -0
- package/dist/error/locales/zh.d.ts.map +1 -0
- package/dist/error/messages.d.ts +7 -0
- package/dist/error/messages.d.ts.map +1 -0
- package/dist/format/format.d.ts +61 -0
- package/dist/format/format.d.ts.map +1 -0
- package/dist/format/index.d.ts +5 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +1475 -0
- package/dist/format/index.js.map +29 -0
- package/dist/guard/guard.d.ts +73 -0
- package/dist/guard/guard.d.ts.map +1 -0
- package/dist/guard/index.d.ts +7 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +342 -0
- package/dist/guard/index.js.map +11 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8938 -0
- package/dist/index.js.map +104 -0
- package/dist/locale/index.d.ts +124 -0
- package/dist/locale/index.d.ts.map +1 -0
- package/dist/locale/index.js +564 -0
- package/dist/locale/index.js.map +20 -0
- package/dist/schema/build.d.ts +32 -0
- package/dist/schema/build.d.ts.map +1 -0
- package/dist/schema/check.d.ts +6 -0
- package/dist/schema/check.d.ts.map +1 -0
- package/dist/schema/compile.d.ts +16 -0
- package/dist/schema/compile.d.ts.map +1 -0
- package/dist/schema/core-keywords.d.ts +8 -0
- package/dist/schema/core-keywords.d.ts.map +1 -0
- package/dist/schema/core.d.ts +3 -0
- package/dist/schema/core.d.ts.map +1 -0
- package/dist/schema/emitter-advanced.d.ts +6 -0
- package/dist/schema/emitter-advanced.d.ts.map +1 -0
- package/dist/schema/emitter-base.d.ts +8 -0
- package/dist/schema/emitter-base.d.ts.map +1 -0
- package/dist/schema/emitter-derived.d.ts +5 -0
- package/dist/schema/emitter-derived.d.ts.map +1 -0
- package/dist/schema/emitter-reference.d.ts +5 -0
- package/dist/schema/emitter-reference.d.ts.map +1 -0
- package/dist/schema/emitter-types.d.ts +5 -0
- package/dist/schema/emitter-types.d.ts.map +1 -0
- package/dist/schema/emitter-wrapper.d.ts +5 -0
- package/dist/schema/emitter-wrapper.d.ts.map +1 -0
- package/dist/schema/emitter.d.ts +52 -0
- package/dist/schema/emitter.d.ts.map +1 -0
- package/dist/schema/engine.d.ts +61 -0
- package/dist/schema/engine.d.ts.map +1 -0
- package/dist/schema/error-collector.d.ts +4 -0
- package/dist/schema/error-collector.d.ts.map +1 -0
- package/dist/schema/errors.d.ts +7 -0
- package/dist/schema/errors.d.ts.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +3661 -0
- package/dist/schema/index.js.map +50 -0
- package/dist/schema/parse.d.ts +14 -0
- package/dist/schema/parse.d.ts.map +1 -0
- package/dist/schema/pointer.d.ts +13 -0
- package/dist/schema/pointer.d.ts.map +1 -0
- package/dist/schema/predicates.d.ts +62 -0
- package/dist/schema/predicates.d.ts.map +1 -0
- package/dist/schema/resolve.d.ts +6 -0
- package/dist/schema/resolve.d.ts.map +1 -0
- package/dist/schema/runtime-keywords.d.ts +136 -0
- package/dist/schema/runtime-keywords.d.ts.map +1 -0
- package/dist/schema/schema.d.ts +14 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/shared.d.ts +61 -0
- package/dist/schema/shared.d.ts.map +1 -0
- package/dist/script/generic.d.ts +3 -0
- package/dist/script/generic.d.ts.map +1 -0
- package/dist/script/index.d.ts +7 -0
- package/dist/script/index.d.ts.map +1 -0
- package/dist/script/index.js +3948 -0
- package/dist/script/index.js.map +55 -0
- package/dist/script/literals.d.ts +5 -0
- package/dist/script/literals.d.ts.map +1 -0
- package/dist/script/shared.d.ts +15 -0
- package/dist/script/shared.d.ts.map +1 -0
- package/dist/shared/bytes.d.ts +9 -0
- package/dist/shared/bytes.d.ts.map +1 -0
- package/dist/shared/format-constants.d.ts +16 -0
- package/dist/shared/format-constants.d.ts.map +1 -0
- package/dist/shared/format-validators.d.ts +13 -0
- package/dist/shared/format-validators.d.ts.map +1 -0
- package/dist/shared/locale.d.ts +43 -0
- package/dist/shared/locale.d.ts.map +1 -0
- package/dist/shared/object-utils.d.ts +21 -0
- package/dist/shared/object-utils.d.ts.map +1 -0
- package/dist/shared/regex-json.d.ts +5 -0
- package/dist/shared/regex-json.d.ts.map +1 -0
- package/dist/shared/registries.d.ts +41 -0
- package/dist/shared/registries.d.ts.map +1 -0
- package/dist/shared/runtime-context.d.ts +109 -0
- package/dist/shared/runtime-context.d.ts.map +1 -0
- package/dist/shared/runtime-guards.d.ts +7 -0
- package/dist/shared/runtime-guards.d.ts.map +1 -0
- package/dist/shared/schema-access.d.ts +34 -0
- package/dist/shared/schema-access.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +9 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/dist/shared/utils.js +1321 -0
- package/dist/shared/utils.js.map +27 -0
- package/dist/standard/index.d.ts +51 -0
- package/dist/standard/index.d.ts.map +1 -0
- package/dist/standard/index.js +4551 -0
- package/dist/standard/index.js.map +66 -0
- package/dist/system/index.d.ts +5 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/system/index.js +1632 -0
- package/dist/system/index.js.map +33 -0
- package/dist/system/system.d.ts +154 -0
- package/dist/system/system.d.ts.map +1 -0
- package/dist/type/actions.d.ts +48 -0
- package/dist/type/actions.d.ts.map +1 -0
- package/dist/type/base-types.d.ts +5 -0
- package/dist/type/base-types.d.ts.map +1 -0
- package/dist/type/codec-builtins.d.ts +9 -0
- package/dist/type/codec-builtins.d.ts.map +1 -0
- package/dist/type/combinator-core.d.ts +26 -0
- package/dist/type/combinator-core.d.ts.map +1 -0
- package/dist/type/combinator-functions.d.ts +16 -0
- package/dist/type/combinator-functions.d.ts.map +1 -0
- package/dist/type/combinator-objects.d.ts +30 -0
- package/dist/type/combinator-objects.d.ts.map +1 -0
- package/dist/type/combinators.d.ts +4 -0
- package/dist/type/combinators.d.ts.map +1 -0
- package/dist/type/composite-types.d.ts +39 -0
- package/dist/type/composite-types.d.ts.map +1 -0
- package/dist/type/containers-types.d.ts +47 -0
- package/dist/type/containers-types.d.ts.map +1 -0
- package/dist/type/containers.d.ts +7 -0
- package/dist/type/containers.d.ts.map +1 -0
- package/dist/type/extends.d.ts +32 -0
- package/dist/type/extends.d.ts.map +1 -0
- package/dist/type/extensions.d.ts +86 -0
- package/dist/type/extensions.d.ts.map +1 -0
- package/dist/type/guards.d.ts +78 -0
- package/dist/type/guards.d.ts.map +1 -0
- package/dist/type/index.d.ts +29 -0
- package/dist/type/index.d.ts.map +1 -0
- package/dist/type/index.js +4049 -0
- package/dist/type/index.js.map +51 -0
- package/dist/type/instantiation.d.ts +10 -0
- package/dist/type/instantiation.d.ts.map +1 -0
- package/dist/type/kind.d.ts +76 -0
- package/dist/type/kind.d.ts.map +1 -0
- package/dist/type/narrow-types.d.ts +23 -0
- package/dist/type/narrow-types.d.ts.map +1 -0
- package/dist/type/primitives-types.d.ts +103 -0
- package/dist/type/primitives-types.d.ts.map +1 -0
- package/dist/type/primitives.d.ts +81 -0
- package/dist/type/primitives.d.ts.map +1 -0
- package/dist/type/root-constants.d.ts +65 -0
- package/dist/type/root-constants.d.ts.map +1 -0
- package/dist/type/root-cyclic.d.ts +12 -0
- package/dist/type/root-cyclic.d.ts.map +1 -0
- package/dist/type/root-deferred.d.ts +39 -0
- package/dist/type/root-deferred.d.ts.map +1 -0
- package/dist/type/root-guards.d.ts +15 -0
- package/dist/type/root-guards.d.ts.map +1 -0
- package/dist/type/root-helpers.d.ts +28 -0
- package/dist/type/root-helpers.d.ts.map +1 -0
- package/dist/type/root-instantiate.d.ts +33 -0
- package/dist/type/root-instantiate.d.ts.map +1 -0
- package/dist/type/root-shared.d.ts +14 -0
- package/dist/type/root-shared.d.ts.map +1 -0
- package/dist/type/root-template.d.ts +15 -0
- package/dist/type/root-template.d.ts.map +1 -0
- package/dist/type/schema.d.ts +10 -0
- package/dist/type/schema.d.ts.map +1 -0
- package/dist/type/static-const-types.d.ts +25 -0
- package/dist/type/static-const-types.d.ts.map +1 -0
- package/dist/type/static-shared-types.d.ts +17 -0
- package/dist/type/static-shared-types.d.ts.map +1 -0
- package/dist/type/static-types.d.ts +39 -0
- package/dist/type/static-types.d.ts.map +1 -0
- package/dist/type/string-action-types.d.ts +24 -0
- package/dist/type/string-action-types.d.ts.map +1 -0
- package/dist/type/transform-types.d.ts +54 -0
- package/dist/type/transform-types.d.ts.map +1 -0
- package/dist/type/uint8array-codec.d.ts +8 -0
- package/dist/type/uint8array-codec.d.ts.map +1 -0
- package/dist/type/wrapper-types.d.ts +71 -0
- package/dist/type/wrapper-types.d.ts.map +1 -0
- package/dist/typebox.d.ts +3 -0
- package/dist/typebox.d.ts.map +1 -0
- package/dist/typebox.js +4767 -0
- package/dist/typebox.js.map +55 -0
- package/dist/value/assert.d.ts +8 -0
- package/dist/value/assert.d.ts.map +1 -0
- package/dist/value/check-collections-derived.d.ts +6 -0
- package/dist/value/check-collections-derived.d.ts.map +1 -0
- package/dist/value/check-collections.d.ts +5 -0
- package/dist/value/check-collections.d.ts.map +1 -0
- package/dist/value/check-extensions.d.ts +3 -0
- package/dist/value/check-extensions.d.ts.map +1 -0
- package/dist/value/check-primitives.d.ts +4 -0
- package/dist/value/check-primitives.d.ts.map +1 -0
- package/dist/value/check.d.ts +13 -0
- package/dist/value/check.d.ts.map +1 -0
- package/dist/value/clean.d.ts +4 -0
- package/dist/value/clean.d.ts.map +1 -0
- package/dist/value/clone.d.ts +3 -0
- package/dist/value/clone.d.ts.map +1 -0
- package/dist/value/convert.d.ts +4 -0
- package/dist/value/convert.d.ts.map +1 -0
- package/dist/value/create.d.ts +4 -0
- package/dist/value/create.d.ts.map +1 -0
- package/dist/value/decode.d.ts +4 -0
- package/dist/value/decode.d.ts.map +1 -0
- package/dist/value/default.d.ts +4 -0
- package/dist/value/default.d.ts.map +1 -0
- package/dist/value/diff.d.ts +9 -0
- package/dist/value/diff.d.ts.map +1 -0
- package/dist/value/encode.d.ts +4 -0
- package/dist/value/encode.d.ts.map +1 -0
- package/dist/value/equal.d.ts +3 -0
- package/dist/value/equal.d.ts.map +1 -0
- package/dist/value/has-codec.d.ts +3 -0
- package/dist/value/has-codec.d.ts.map +1 -0
- package/dist/value/hash.d.ts +3 -0
- package/dist/value/hash.d.ts.map +1 -0
- package/dist/value/index.d.ts +145 -0
- package/dist/value/index.d.ts.map +1 -0
- package/dist/value/index.js +4702 -0
- package/dist/value/index.js.map +71 -0
- package/dist/value/mutate.d.ts +3 -0
- package/dist/value/mutate.d.ts.map +1 -0
- package/dist/value/parse.d.ts +13 -0
- package/dist/value/parse.d.ts.map +1 -0
- package/dist/value/patch.d.ts +4 -0
- package/dist/value/patch.d.ts.map +1 -0
- package/dist/value/pipeline.d.ts +6 -0
- package/dist/value/pipeline.d.ts.map +1 -0
- package/dist/value/pointer.d.ts +8 -0
- package/dist/value/pointer.d.ts.map +1 -0
- package/dist/value/repair.d.ts +5 -0
- package/dist/value/repair.d.ts.map +1 -0
- package/dist/value/result.d.ts +10 -0
- package/dist/value/result.d.ts.map +1 -0
- package/docs/locale-packs.md +78 -0
- package/docs/package-contract.md +89 -0
- package/docs/parity-and-extensions.md +56 -0
- package/docs/script-module-registries.md +107 -0
- package/docs/workflows.md +154 -0
- package/package.json +117 -0
|
@@ -0,0 +1,4711 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/error/locales/shared.ts
|
|
18
|
+
function formatList(values) {
|
|
19
|
+
return values === undefined ? "" : values.join(", ");
|
|
20
|
+
}
|
|
21
|
+
function labelFor(params, fallback) {
|
|
22
|
+
return params.label ?? fallback;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/error/locales/de.ts
|
|
26
|
+
var deDECatalog = {
|
|
27
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `Erwartet: ${params.expected ?? "Wert"}` : `Erwartet: ${params.expected ?? "Wert"}, erhalten: ${params.actual}`,
|
|
28
|
+
MIN_LENGTH: (params) => `${labelFor(params, "Der Wert")} muss mindestens ${params.minimum} sein`,
|
|
29
|
+
MAX_LENGTH: (params) => `${labelFor(params, "Der Wert")} darf h\xF6chstens ${params.maximum} sein`,
|
|
30
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "Der Wert")} muss einem von folgenden Mustern entsprechen: ${formatList(params.patterns)}` : `${labelFor(params, "Der Wert")} muss dem Muster ${params.pattern} entsprechen`,
|
|
31
|
+
FORMAT: (params) => `${labelFor(params, "Der Wert")} muss dem Format ${params.format} entsprechen`,
|
|
32
|
+
MINIMUM: (params) => `${labelFor(params, "Der Wert")} muss >= ${params.minimum} sein`,
|
|
33
|
+
MAXIMUM: (params) => `${labelFor(params, "Der Wert")} muss <= ${params.maximum} sein`,
|
|
34
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "Der Wert")} muss > ${params.minimum} sein`,
|
|
35
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "Der Wert")} muss < ${params.maximum} sein`,
|
|
36
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "Der Wert")} muss ein Vielfaches von ${params.divisor} sein`,
|
|
37
|
+
INVALID_CONST: (params) => `Erwartet: ${params.expectedValue}`,
|
|
38
|
+
MIN_ITEMS: (params) => `${labelFor(params, "Das Array")} muss mindestens ${params.minimum} Elemente enthalten`,
|
|
39
|
+
MAX_ITEMS: (params) => `${labelFor(params, "Das Array")} darf h\xF6chstens ${params.maximum} Elemente enthalten`,
|
|
40
|
+
UNIQUE_ITEMS: (params) => `Die Elemente von ${labelFor(params, "diesem Array")} m\xFCssen eindeutig sein`,
|
|
41
|
+
CONTAINS: (params) => `${labelFor(params, "Das Array")} muss mindestens ein passendes Element enthalten`,
|
|
42
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "Das Array")} muss mindestens ${params.minimum} passende Elemente enthalten`,
|
|
43
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "Das Array")} darf h\xF6chstens ${params.maximum} passende Elemente enthalten`,
|
|
44
|
+
MISSING_REQUIRED: (params) => `Erforderliche Eigenschaft "${params.property}" fehlt`,
|
|
45
|
+
ADDITIONAL_PROPERTY: (params) => `Unerwartete Eigenschaft "${params.property}"`,
|
|
46
|
+
ADDITIONAL_ITEMS: (params) => `Unerwartetes Element an Index ${params.count}`,
|
|
47
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "Das Objekt")} muss mindestens ${params.minimum} Eigenschaften haben`,
|
|
48
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "Das Objekt")} darf h\xF6chstens ${params.maximum} Eigenschaften haben`,
|
|
49
|
+
INVALID_KEY: (params) => `Ung\xFCltiger Schl\xFCssel "${params.key}"`,
|
|
50
|
+
UNION: () => "Der Wert passt zu keiner Union-Variante",
|
|
51
|
+
ENUM: (params) => `Der Wert muss einer von folgenden sein: ${formatList(params.values)}`,
|
|
52
|
+
UNRESOLVED_REF: () => "Nicht aufgel\xF6ste Schema-Referenz",
|
|
53
|
+
EXCLUDE: () => "Der Wert entspricht einem ausgeschlossenen Schema",
|
|
54
|
+
EXTRACT: () => "Der Wert entspricht nicht dem extrahierten Schema",
|
|
55
|
+
NEVER: () => "Der Wert ist nicht erlaubt",
|
|
56
|
+
NOT: () => "Der Wert entspricht einem negierten Schema",
|
|
57
|
+
KEYOF: (params) => `Der Wert muss einer von folgenden sein: ${formatList(params.values)}`,
|
|
58
|
+
CONDITIONAL: () => "Der Wert passt zu keinem bedingten Zweig",
|
|
59
|
+
INDEX: () => "Der Wert passt zu keinem indexierten Schema",
|
|
60
|
+
IDENTIFIER: () => "G\xFCltiger Bezeichner erwartet",
|
|
61
|
+
BASE: () => "Basisvalidierung fehlgeschlagen",
|
|
62
|
+
REFINE: (params) => params.customMessage ?? "Verfeinerung fehlgeschlagen",
|
|
63
|
+
CALL: () => "Aufrufschema konnte nicht instanziiert werden",
|
|
64
|
+
PARAMETERS_LENGTH: (params) => `${params.count} Parameter erwartet`,
|
|
65
|
+
CUSTOM_TYPE: (params) => `Validierung des benutzerdefinierten Typs "${params.kind}" fehlgeschlagen`
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/error/locales/en.ts
|
|
69
|
+
var enUSCatalog = {
|
|
70
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `Expected ${params.expected ?? "value"}` : `Expected ${params.expected ?? "value"}, got ${params.actual}`,
|
|
71
|
+
MIN_LENGTH: (params) => `${labelFor(params, "Value")} must be at least ${params.minimum}`,
|
|
72
|
+
MAX_LENGTH: (params) => `${labelFor(params, "Value")} must be at most ${params.maximum}`,
|
|
73
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "Value")} must match one of: ${formatList(params.patterns)}` : `${labelFor(params, "Value")} must match pattern ${params.pattern}`,
|
|
74
|
+
FORMAT: (params) => `${labelFor(params, "Value")} must match format ${params.format}`,
|
|
75
|
+
MINIMUM: (params) => `${labelFor(params, "Value")} must be >= ${params.minimum}`,
|
|
76
|
+
MAXIMUM: (params) => `${labelFor(params, "Value")} must be <= ${params.maximum}`,
|
|
77
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "Value")} must be > ${params.minimum}`,
|
|
78
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "Value")} must be < ${params.maximum}`,
|
|
79
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "Value")} must be a multiple of ${params.divisor}`,
|
|
80
|
+
INVALID_CONST: (params) => `Expected ${params.expectedValue}`,
|
|
81
|
+
MIN_ITEMS: (params) => `${labelFor(params, "Array")} must have at least ${params.minimum} items`,
|
|
82
|
+
MAX_ITEMS: (params) => `${labelFor(params, "Array")} must have at most ${params.maximum} items`,
|
|
83
|
+
UNIQUE_ITEMS: (params) => `${labelFor(params, "Array")} items must be unique`,
|
|
84
|
+
CONTAINS: (params) => `${labelFor(params, "Array")} must contain at least one matching item`,
|
|
85
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "Array")} must contain at least ${params.minimum} matching items`,
|
|
86
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "Array")} must contain at most ${params.maximum} matching items`,
|
|
87
|
+
MISSING_REQUIRED: (params) => `Missing required property "${params.property}"`,
|
|
88
|
+
ADDITIONAL_PROPERTY: (params) => `Unexpected property "${params.property}"`,
|
|
89
|
+
ADDITIONAL_ITEMS: (params) => `Unexpected item at index ${params.count}`,
|
|
90
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "Object")} must have at least ${params.minimum} properties`,
|
|
91
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "Object")} must have at most ${params.maximum} properties`,
|
|
92
|
+
INVALID_KEY: (params) => `Invalid record key "${params.key}"`,
|
|
93
|
+
UNION: () => "Value does not match any union variant",
|
|
94
|
+
ENUM: (params) => `Value must be one of: ${formatList(params.values)}`,
|
|
95
|
+
UNRESOLVED_REF: () => "Unresolved schema reference",
|
|
96
|
+
EXCLUDE: () => "Value matched an excluded schema",
|
|
97
|
+
EXTRACT: () => "Value did not match the extracted schema",
|
|
98
|
+
NEVER: () => "Value is not allowed",
|
|
99
|
+
NOT: () => "Value matches a negated schema",
|
|
100
|
+
KEYOF: (params) => `Value must be one of: ${formatList(params.values)}`,
|
|
101
|
+
CONDITIONAL: () => "Value does not match any conditional branch",
|
|
102
|
+
INDEX: () => "Value does not match any indexed schema",
|
|
103
|
+
IDENTIFIER: () => "Expected valid identifier string",
|
|
104
|
+
BASE: () => "Base validation failed",
|
|
105
|
+
REFINE: (params) => params.customMessage ?? "Refinement failed",
|
|
106
|
+
CALL: () => "Unable to instantiate call schema",
|
|
107
|
+
PARAMETERS_LENGTH: (params) => `Expected ${params.count} parameters`,
|
|
108
|
+
CUSTOM_TYPE: (params) => `Custom type validation failed for kind "${params.kind}"`
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/error/locales/es.ts
|
|
112
|
+
var esESCatalog = {
|
|
113
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `Se esperaba ${params.expected ?? "un valor"}` : `Se esperaba ${params.expected ?? "un valor"}, se recibi\xF3 ${params.actual}`,
|
|
114
|
+
MIN_LENGTH: (params) => `${labelFor(params, "El valor")} debe ser al menos ${params.minimum}`,
|
|
115
|
+
MAX_LENGTH: (params) => `${labelFor(params, "El valor")} debe ser como m\xE1ximo ${params.maximum}`,
|
|
116
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "El valor")} debe coincidir con uno de: ${formatList(params.patterns)}` : `${labelFor(params, "El valor")} debe coincidir con el patr\xF3n ${params.pattern}`,
|
|
117
|
+
FORMAT: (params) => `${labelFor(params, "El valor")} debe coincidir con el formato ${params.format}`,
|
|
118
|
+
MINIMUM: (params) => `${labelFor(params, "El valor")} debe ser >= ${params.minimum}`,
|
|
119
|
+
MAXIMUM: (params) => `${labelFor(params, "El valor")} debe ser <= ${params.maximum}`,
|
|
120
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "El valor")} debe ser > ${params.minimum}`,
|
|
121
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "El valor")} debe ser < ${params.maximum}`,
|
|
122
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "El valor")} debe ser m\xFAltiplo de ${params.divisor}`,
|
|
123
|
+
INVALID_CONST: (params) => `Se esperaba ${params.expectedValue}`,
|
|
124
|
+
MIN_ITEMS: (params) => `${labelFor(params, "El arreglo")} debe tener al menos ${params.minimum} elementos`,
|
|
125
|
+
MAX_ITEMS: (params) => `${labelFor(params, "El arreglo")} debe tener como m\xE1ximo ${params.maximum} elementos`,
|
|
126
|
+
UNIQUE_ITEMS: (params) => `Los elementos de ${labelFor(params, "este arreglo")} deben ser \xFAnicos`,
|
|
127
|
+
CONTAINS: (params) => `${labelFor(params, "El arreglo")} debe contener al menos un elemento coincidente`,
|
|
128
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "El arreglo")} debe contener al menos ${params.minimum} elementos coincidentes`,
|
|
129
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "El arreglo")} debe contener como m\xE1ximo ${params.maximum} elementos coincidentes`,
|
|
130
|
+
MISSING_REQUIRED: (params) => `Falta la propiedad requerida "${params.property}"`,
|
|
131
|
+
ADDITIONAL_PROPERTY: (params) => `Propiedad inesperada "${params.property}"`,
|
|
132
|
+
ADDITIONAL_ITEMS: (params) => `Elemento inesperado en el \xEDndice ${params.count}`,
|
|
133
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "El objeto")} debe tener al menos ${params.minimum} propiedades`,
|
|
134
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "El objeto")} debe tener como m\xE1ximo ${params.maximum} propiedades`,
|
|
135
|
+
INVALID_KEY: (params) => `Clave de registro no v\xE1lida "${params.key}"`,
|
|
136
|
+
UNION: () => "El valor no coincide con ninguna variante de la uni\xF3n",
|
|
137
|
+
ENUM: (params) => `El valor debe ser uno de: ${formatList(params.values)}`,
|
|
138
|
+
UNRESOLVED_REF: () => "Referencia de esquema no resuelta",
|
|
139
|
+
EXCLUDE: () => "El valor coincidi\xF3 con un esquema excluido",
|
|
140
|
+
EXTRACT: () => "El valor no coincidi\xF3 con el esquema extra\xEDdo",
|
|
141
|
+
NEVER: () => "El valor no est\xE1 permitido",
|
|
142
|
+
NOT: () => "El valor coincide con un esquema negado",
|
|
143
|
+
KEYOF: (params) => `El valor debe ser uno de: ${formatList(params.values)}`,
|
|
144
|
+
CONDITIONAL: () => "El valor no coincide con ninguna rama condicional",
|
|
145
|
+
INDEX: () => "El valor no coincide con ning\xFAn esquema indexado",
|
|
146
|
+
IDENTIFIER: () => "Se esperaba una cadena identificadora v\xE1lida",
|
|
147
|
+
BASE: () => "La validaci\xF3n base fall\xF3",
|
|
148
|
+
REFINE: (params) => params.customMessage ?? "La validaci\xF3n refinada fall\xF3",
|
|
149
|
+
CALL: () => "No se pudo instanciar el esquema de llamada",
|
|
150
|
+
PARAMETERS_LENGTH: (params) => `Se esperaban ${params.count} par\xE1metros`,
|
|
151
|
+
CUSTOM_TYPE: (params) => `La validaci\xF3n del tipo personalizado "${params.kind}" fall\xF3`
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/error/locales/fr.ts
|
|
155
|
+
var frFRCatalog = {
|
|
156
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `Valeur attendue: ${params.expected ?? "valeur"}` : `Valeur attendue: ${params.expected ?? "valeur"}, re\xE7u: ${params.actual}`,
|
|
157
|
+
MIN_LENGTH: (params) => `${labelFor(params, "La valeur")} doit \xEAtre au moins ${params.minimum}`,
|
|
158
|
+
MAX_LENGTH: (params) => `${labelFor(params, "La valeur")} doit \xEAtre au plus ${params.maximum}`,
|
|
159
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "La valeur")} doit correspondre \xE0 l'un de: ${formatList(params.patterns)}` : `${labelFor(params, "La valeur")} doit correspondre au motif ${params.pattern}`,
|
|
160
|
+
FORMAT: (params) => `${labelFor(params, "La valeur")} doit respecter le format ${params.format}`,
|
|
161
|
+
MINIMUM: (params) => `${labelFor(params, "La valeur")} doit \xEAtre >= ${params.minimum}`,
|
|
162
|
+
MAXIMUM: (params) => `${labelFor(params, "La valeur")} doit \xEAtre <= ${params.maximum}`,
|
|
163
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "La valeur")} doit \xEAtre > ${params.minimum}`,
|
|
164
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "La valeur")} doit \xEAtre < ${params.maximum}`,
|
|
165
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "La valeur")} doit \xEAtre un multiple de ${params.divisor}`,
|
|
166
|
+
INVALID_CONST: (params) => `Valeur attendue: ${params.expectedValue}`,
|
|
167
|
+
MIN_ITEMS: (params) => `${labelFor(params, "Le tableau")} doit contenir au moins ${params.minimum} \xE9l\xE9ments`,
|
|
168
|
+
MAX_ITEMS: (params) => `${labelFor(params, "Le tableau")} doit contenir au plus ${params.maximum} \xE9l\xE9ments`,
|
|
169
|
+
UNIQUE_ITEMS: (params) => `Les \xE9l\xE9ments de ${labelFor(params, "ce tableau")} doivent \xEAtre uniques`,
|
|
170
|
+
CONTAINS: (params) => `${labelFor(params, "Le tableau")} doit contenir au moins un \xE9l\xE9ment correspondant`,
|
|
171
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "Le tableau")} doit contenir au moins ${params.minimum} \xE9l\xE9ments correspondants`,
|
|
172
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "Le tableau")} doit contenir au plus ${params.maximum} \xE9l\xE9ments correspondants`,
|
|
173
|
+
MISSING_REQUIRED: (params) => `Propri\xE9t\xE9 requise manquante "${params.property}"`,
|
|
174
|
+
ADDITIONAL_PROPERTY: (params) => `Propri\xE9t\xE9 inattendue "${params.property}"`,
|
|
175
|
+
ADDITIONAL_ITEMS: (params) => `\xC9l\xE9ment inattendu \xE0 l'index ${params.count}`,
|
|
176
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "L\u2019objet")} doit avoir au moins ${params.minimum} propri\xE9t\xE9s`,
|
|
177
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "L\u2019objet")} doit avoir au plus ${params.maximum} propri\xE9t\xE9s`,
|
|
178
|
+
INVALID_KEY: (params) => `Cl\xE9 d\u2019enregistrement invalide "${params.key}"`,
|
|
179
|
+
UNION: () => "La valeur ne correspond \xE0 aucune variante de l\u2019union",
|
|
180
|
+
ENUM: (params) => `La valeur doit \xEAtre l\u2019une de: ${formatList(params.values)}`,
|
|
181
|
+
UNRESOLVED_REF: () => "R\xE9f\xE9rence de sch\xE9ma non r\xE9solue",
|
|
182
|
+
EXCLUDE: () => "La valeur correspond \xE0 un sch\xE9ma exclu",
|
|
183
|
+
EXTRACT: () => "La valeur ne correspond pas au sch\xE9ma extrait",
|
|
184
|
+
NEVER: () => "La valeur n\u2019est pas autoris\xE9e",
|
|
185
|
+
NOT: () => "La valeur correspond \xE0 un sch\xE9ma n\xE9gatif",
|
|
186
|
+
KEYOF: (params) => `La valeur doit \xEAtre l\u2019une de: ${formatList(params.values)}`,
|
|
187
|
+
CONDITIONAL: () => "La valeur ne correspond \xE0 aucune branche conditionnelle",
|
|
188
|
+
INDEX: () => "La valeur ne correspond \xE0 aucun sch\xE9ma index\xE9",
|
|
189
|
+
IDENTIFIER: () => "Identifiant attendu valide",
|
|
190
|
+
BASE: () => "La validation de base a \xE9chou\xE9",
|
|
191
|
+
REFINE: (params) => params.customMessage ?? "Le raffinement a \xE9chou\xE9",
|
|
192
|
+
CALL: () => "Impossible d\u2019instancier le sch\xE9ma d\u2019appel",
|
|
193
|
+
PARAMETERS_LENGTH: (params) => `${params.count} param\xE8tres attendus`,
|
|
194
|
+
CUSTOM_TYPE: (params) => `La validation du type personnalis\xE9 "${params.kind}" a \xE9chou\xE9`
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/error/locales/ja.ts
|
|
198
|
+
var jaJPCatalog = {
|
|
199
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `${params.expected ?? "\u5024"}\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059` : `${params.expected ?? "\u5024"}\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\u3002\u5B9F\u969B\u306E\u578B: ${params.actual}`,
|
|
200
|
+
MIN_LENGTH: (params) => `${labelFor(params, "\u5024")}\u306F\u5C11\u306A\u304F\u3068\u3082${params.minimum}\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
201
|
+
MAX_LENGTH: (params) => `${labelFor(params, "\u5024")}\u306F\u6700\u5927\u3067${params.maximum}\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
202
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "\u5024")}\u306F\u6B21\u306E\u3044\u305A\u308C\u304B\u306B\u4E00\u81F4\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059: ${formatList(params.patterns)}` : `${labelFor(params, "\u5024")}\u306F\u30D1\u30BF\u30FC\u30F3${params.pattern}\u306B\u4E00\u81F4\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
203
|
+
FORMAT: (params) => `${labelFor(params, "\u5024")}\u306F\u5F62\u5F0F${params.format}\u306B\u4E00\u81F4\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
204
|
+
MINIMUM: (params) => `${labelFor(params, "\u5024")}\u306F${params.minimum}\u4EE5\u4E0A\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
205
|
+
MAXIMUM: (params) => `${labelFor(params, "\u5024")}\u306F${params.maximum}\u4EE5\u4E0B\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
206
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "\u5024")}\u306F${params.minimum}\u3088\u308A\u5927\u304D\u3044\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
207
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "\u5024")}\u306F${params.maximum}\u3088\u308A\u5C0F\u3055\u3044\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
208
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "\u5024")}\u306F${params.divisor}\u306E\u500D\u6570\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
209
|
+
INVALID_CONST: (params) => `${params.expectedValue}\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
210
|
+
MIN_ITEMS: (params) => `${labelFor(params, "\u914D\u5217")}\u306B\u306F\u5C11\u306A\u304F\u3068\u3082${params.minimum}\u500B\u306E\u9805\u76EE\u304C\u5FC5\u8981\u3067\u3059`,
|
|
211
|
+
MAX_ITEMS: (params) => `${labelFor(params, "\u914D\u5217")}\u306B\u306F\u6700\u5927${params.maximum}\u500B\u306E\u9805\u76EE\u307E\u3067\u8A31\u53EF\u3055\u308C\u307E\u3059`,
|
|
212
|
+
UNIQUE_ITEMS: (params) => `${labelFor(params, "\u914D\u5217")}\u306E\u9805\u76EE\u306F\u4E00\u610F\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
213
|
+
CONTAINS: (params) => `${labelFor(params, "\u914D\u5217")}\u306B\u306F\u4E00\u81F4\u3059\u308B\u9805\u76EE\u304C\u5C11\u306A\u304F\u3068\u30821\u3064\u5FC5\u8981\u3067\u3059`,
|
|
214
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "\u914D\u5217")}\u306B\u306F\u4E00\u81F4\u3059\u308B\u9805\u76EE\u304C\u5C11\u306A\u304F\u3068\u3082${params.minimum}\u500B\u5FC5\u8981\u3067\u3059`,
|
|
215
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "\u914D\u5217")}\u306B\u306F\u4E00\u81F4\u3059\u308B\u9805\u76EE\u3092\u6700\u5927${params.maximum}\u500B\u307E\u3067\u542B\u3081\u3089\u308C\u307E\u3059`,
|
|
216
|
+
MISSING_REQUIRED: (params) => `\u5FC5\u9808\u30D7\u30ED\u30D1\u30C6\u30A3"${params.property}"\u304C\u3042\u308A\u307E\u305B\u3093`,
|
|
217
|
+
ADDITIONAL_PROPERTY: (params) => `\u4E88\u671F\u3057\u306A\u3044\u30D7\u30ED\u30D1\u30C6\u30A3"${params.property}"\u3067\u3059`,
|
|
218
|
+
ADDITIONAL_ITEMS: (params) => `\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9${params.count}\u306B\u4E88\u671F\u3057\u306A\u3044\u9805\u76EE\u304C\u3042\u308A\u307E\u3059`,
|
|
219
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8")}\u306B\u306F\u5C11\u306A\u304F\u3068\u3082${params.minimum}\u500B\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u304C\u5FC5\u8981\u3067\u3059`,
|
|
220
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8")}\u306B\u306F\u6700\u5927${params.maximum}\u500B\u306E\u30D7\u30ED\u30D1\u30C6\u30A3\u307E\u3067\u8A31\u53EF\u3055\u308C\u307E\u3059`,
|
|
221
|
+
INVALID_KEY: (params) => `\u7121\u52B9\u306A\u30EC\u30B3\u30FC\u30C9\u30AD\u30FC"${params.key}"\u3067\u3059`,
|
|
222
|
+
UNION: () => "\u5024\u304C\u3069\u306E\u30E6\u30CB\u30AA\u30F3\u5206\u5C90\u306B\u3082\u4E00\u81F4\u3057\u307E\u305B\u3093",
|
|
223
|
+
ENUM: (params) => `\u5024\u306F\u6B21\u306E\u3044\u305A\u308C\u304B\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059: ${formatList(params.values)}`,
|
|
224
|
+
UNRESOLVED_REF: () => "\u89E3\u6C7A\u3067\u304D\u306A\u3044\u30B9\u30AD\u30FC\u30DE\u53C2\u7167\u3067\u3059",
|
|
225
|
+
EXCLUDE: () => "\u5024\u304C\u9664\u5916\u3055\u308C\u305F\u30B9\u30AD\u30FC\u30DE\u306B\u4E00\u81F4\u3057\u307E\u3057\u305F",
|
|
226
|
+
EXTRACT: () => "\u5024\u304C\u62BD\u51FA\u3055\u308C\u305F\u30B9\u30AD\u30FC\u30DE\u306B\u4E00\u81F4\u3057\u307E\u305B\u3093",
|
|
227
|
+
NEVER: () => "\u5024\u306F\u8A31\u53EF\u3055\u308C\u3066\u3044\u307E\u305B\u3093",
|
|
228
|
+
NOT: () => "\u5024\u304C\u5426\u5B9A\u30B9\u30AD\u30FC\u30DE\u306B\u4E00\u81F4\u3057\u3066\u3044\u307E\u3059",
|
|
229
|
+
KEYOF: (params) => `\u5024\u306F\u6B21\u306E\u3044\u305A\u308C\u304B\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059: ${formatList(params.values)}`,
|
|
230
|
+
CONDITIONAL: () => "\u5024\u304C\u3069\u306E\u6761\u4EF6\u5206\u5C90\u306B\u3082\u4E00\u81F4\u3057\u307E\u305B\u3093",
|
|
231
|
+
INDEX: () => "\u5024\u304C\u3069\u306E\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9\u5019\u88DC\u30B9\u30AD\u30FC\u30DE\u306B\u3082\u4E00\u81F4\u3057\u307E\u305B\u3093",
|
|
232
|
+
IDENTIFIER: () => "\u6709\u52B9\u306A\u8B58\u5225\u5B50\u6587\u5B57\u5217\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059",
|
|
233
|
+
BASE: () => "\u57FA\u672C\u691C\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
234
|
+
REFINE: (params) => params.customMessage ?? "\u8FFD\u52A0\u6761\u4EF6\u306E\u691C\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
|
|
235
|
+
CALL: () => "\u547C\u3073\u51FA\u3057\u30B9\u30AD\u30FC\u30DE\u3092\u30A4\u30F3\u30B9\u30BF\u30F3\u30B9\u5316\u3067\u304D\u307E\u305B\u3093",
|
|
236
|
+
PARAMETERS_LENGTH: (params) => `\u30D1\u30E9\u30E1\u30FC\u30BF\u306F${params.count}\u500B\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`,
|
|
237
|
+
CUSTOM_TYPE: (params) => `\u30AB\u30B9\u30BF\u30E0\u578B"${params.kind}"\u306E\u691C\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F`
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/error/locales/ko.ts
|
|
241
|
+
var koKRCatalog = {
|
|
242
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `${params.expected ?? "\uAC12"}\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4` : `${params.expected ?? "\uAC12"}\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4. \uD604\uC7AC \uAC12 \uC720\uD615: ${params.actual}`,
|
|
243
|
+
MIN_LENGTH: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) \uCD5C\uC18C ${params.minimum}\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
244
|
+
MAX_LENGTH: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) \uCD5C\uB300 ${params.maximum}\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
245
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "\uAC12")}\uC740(\uB294) \uB2E4\uC74C \uC911 \uD558\uB098\uC640 \uC77C\uCE58\uD574\uC57C \uD569\uB2C8\uB2E4: ${formatList(params.patterns)}` : `${labelFor(params, "\uAC12")}\uC740(\uB294) \uD328\uD134 ${params.pattern}\uACFC \uC77C\uCE58\uD574\uC57C \uD569\uB2C8\uB2E4`,
|
|
246
|
+
FORMAT: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) ${params.format} \uD615\uC2DD\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
247
|
+
MINIMUM: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) ${params.minimum} \uC774\uC0C1\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
248
|
+
MAXIMUM: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) ${params.maximum} \uC774\uD558\uC5EC\uC57C \uD569\uB2C8\uB2E4`,
|
|
249
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) ${params.minimum}\uBCF4\uB2E4 \uCEE4\uC57C \uD569\uB2C8\uB2E4`,
|
|
250
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) ${params.maximum}\uBCF4\uB2E4 \uC791\uC544\uC57C \uD569\uB2C8\uB2E4`,
|
|
251
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "\uAC12")}\uC740(\uB294) ${params.divisor}\uC758 \uBC30\uC218\uC5EC\uC57C \uD569\uB2C8\uB2E4`,
|
|
252
|
+
INVALID_CONST: (params) => `${params.expectedValue}\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
253
|
+
MIN_ITEMS: (params) => `${labelFor(params, "\uBC30\uC5F4")}\uC740(\uB294) \uCD5C\uC18C ${params.minimum}\uAC1C \uD56D\uBAA9\uC774 \uD544\uC694\uD569\uB2C8\uB2E4`,
|
|
254
|
+
MAX_ITEMS: (params) => `${labelFor(params, "\uBC30\uC5F4")}\uC740(\uB294) \uCD5C\uB300 ${params.maximum}\uAC1C \uD56D\uBAA9\uB9CC \uD5C8\uC6A9\uB429\uB2C8\uB2E4`,
|
|
255
|
+
UNIQUE_ITEMS: (params) => `${labelFor(params, "\uBC30\uC5F4")} \uD56D\uBAA9\uC740 \uACE0\uC720\uD574\uC57C \uD569\uB2C8\uB2E4`,
|
|
256
|
+
CONTAINS: (params) => `${labelFor(params, "\uBC30\uC5F4")}\uC5D0 \uC77C\uCE58\uD558\uB294 \uD56D\uBAA9\uC774 \uD558\uB098 \uC774\uC0C1 \uC788\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
257
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "\uBC30\uC5F4")}\uC5D0 \uC77C\uCE58\uD558\uB294 \uD56D\uBAA9\uC774 \uCD5C\uC18C ${params.minimum}\uAC1C \uC788\uC5B4\uC57C \uD569\uB2C8\uB2E4`,
|
|
258
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "\uBC30\uC5F4")}\uC5D0 \uC77C\uCE58\uD558\uB294 \uD56D\uBAA9\uC774 \uCD5C\uB300 ${params.maximum}\uAC1C\uAE4C\uC9C0\uB9CC \uD5C8\uC6A9\uB429\uB2C8\uB2E4`,
|
|
259
|
+
MISSING_REQUIRED: (params) => `\uD544\uC218 \uC18D\uC131 "${params.property}"\uC774(\uAC00) \uC5C6\uC2B5\uB2C8\uB2E4`,
|
|
260
|
+
ADDITIONAL_PROPERTY: (params) => `\uC608\uC0C1\uD558\uC9C0 \uBABB\uD55C \uC18D\uC131 "${params.property}"\uC785\uB2C8\uB2E4`,
|
|
261
|
+
ADDITIONAL_ITEMS: (params) => `\uC778\uB371\uC2A4 ${params.count}\uC758 \uD56D\uBAA9\uC740 \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4`,
|
|
262
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "\uAC1D\uCCB4")}\uC5D0\uB294 \uCD5C\uC18C ${params.minimum}\uAC1C\uC758 \uC18D\uC131\uC774 \uD544\uC694\uD569\uB2C8\uB2E4`,
|
|
263
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "\uAC1D\uCCB4")}\uC5D0\uB294 \uCD5C\uB300 ${params.maximum}\uAC1C\uC758 \uC18D\uC131\uB9CC \uD5C8\uC6A9\uB429\uB2C8\uB2E4`,
|
|
264
|
+
INVALID_KEY: (params) => `\uB808\uCF54\uB4DC \uD0A4 "${params.key}"\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4`,
|
|
265
|
+
UNION: () => "\uAC12\uC774 \uC5B4\uB5A4 \uC720\uB2C8\uC5B8 \uBD84\uAE30\uC640\uB3C4 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
|
|
266
|
+
ENUM: (params) => `\uAC12\uC740 \uB2E4\uC74C \uC911 \uD558\uB098\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${formatList(params.values)}`,
|
|
267
|
+
UNRESOLVED_REF: () => "\uC2A4\uD0A4\uB9C8 \uCC38\uC870\uB97C \uD655\uC778\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",
|
|
268
|
+
EXCLUDE: () => "\uAC12\uC774 \uC81C\uC678\uB41C \uC2A4\uD0A4\uB9C8\uC640 \uC77C\uCE58\uD588\uC2B5\uB2C8\uB2E4",
|
|
269
|
+
EXTRACT: () => "\uAC12\uC774 \uCD94\uCD9C\uB41C \uC2A4\uD0A4\uB9C8\uC640 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
|
|
270
|
+
NEVER: () => "\uAC12\uC774 \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
|
|
271
|
+
NOT: () => "\uAC12\uC774 \uBD80\uC815 \uC2A4\uD0A4\uB9C8\uC640 \uC77C\uCE58\uD569\uB2C8\uB2E4",
|
|
272
|
+
KEYOF: (params) => `\uAC12\uC740 \uB2E4\uC74C \uC911 \uD558\uB098\uC5EC\uC57C \uD569\uB2C8\uB2E4: ${formatList(params.values)}`,
|
|
273
|
+
CONDITIONAL: () => "\uAC12\uC774 \uC5B4\uB5A4 \uC870\uAC74 \uBD84\uAE30\uC640\uB3C4 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
|
|
274
|
+
INDEX: () => "\uAC12\uC774 \uC5B4\uB5A4 \uC778\uB371\uC2A4 \uD6C4\uBCF4 \uC2A4\uD0A4\uB9C8\uC640\uB3C4 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4",
|
|
275
|
+
IDENTIFIER: () => "\uC62C\uBC14\uB978 \uC2DD\uBCC4\uC790 \uBB38\uC790\uC5F4\uC774\uC5B4\uC57C \uD569\uB2C8\uB2E4",
|
|
276
|
+
BASE: () => "\uAE30\uBCF8 \uAC80\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4",
|
|
277
|
+
REFINE: (params) => params.customMessage ?? "\uC138\uBD80 \uC870\uAC74 \uAC80\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4",
|
|
278
|
+
CALL: () => "\uD638\uCD9C \uC2A4\uD0A4\uB9C8\uB97C \uC778\uC2A4\uD134\uC2A4\uD654\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",
|
|
279
|
+
PARAMETERS_LENGTH: (params) => `\uB9E4\uAC1C\uBCC0\uC218\uB294 ${params.count}\uAC1C\uC5EC\uC57C \uD569\uB2C8\uB2E4`,
|
|
280
|
+
CUSTOM_TYPE: (params) => `\uC0AC\uC6A9\uC790 \uC815\uC758 \uD0C0\uC785 "${params.kind}" \uAC80\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4`
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/error/locales/pt.ts
|
|
284
|
+
var ptBRCatalog = {
|
|
285
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `Esperado ${params.expected ?? "valor"}` : `Esperado ${params.expected ?? "valor"}, recebido ${params.actual}`,
|
|
286
|
+
MIN_LENGTH: (params) => `${labelFor(params, "O valor")} deve ser no m\xEDnimo ${params.minimum}`,
|
|
287
|
+
MAX_LENGTH: (params) => `${labelFor(params, "O valor")} deve ser no m\xE1ximo ${params.maximum}`,
|
|
288
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "O valor")} deve corresponder a um destes padr\xF5es: ${formatList(params.patterns)}` : `${labelFor(params, "O valor")} deve corresponder ao padr\xE3o ${params.pattern}`,
|
|
289
|
+
FORMAT: (params) => `${labelFor(params, "O valor")} deve corresponder ao formato ${params.format}`,
|
|
290
|
+
MINIMUM: (params) => `${labelFor(params, "O valor")} deve ser >= ${params.minimum}`,
|
|
291
|
+
MAXIMUM: (params) => `${labelFor(params, "O valor")} deve ser <= ${params.maximum}`,
|
|
292
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "O valor")} deve ser > ${params.minimum}`,
|
|
293
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "O valor")} deve ser < ${params.maximum}`,
|
|
294
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "O valor")} deve ser m\xFAltiplo de ${params.divisor}`,
|
|
295
|
+
INVALID_CONST: (params) => `Esperado ${params.expectedValue}`,
|
|
296
|
+
MIN_ITEMS: (params) => `${labelFor(params, "O array")} deve ter pelo menos ${params.minimum} itens`,
|
|
297
|
+
MAX_ITEMS: (params) => `${labelFor(params, "O array")} deve ter no m\xE1ximo ${params.maximum} itens`,
|
|
298
|
+
UNIQUE_ITEMS: (params) => `Os itens de ${labelFor(params, "este array")} devem ser \xFAnicos`,
|
|
299
|
+
CONTAINS: (params) => `${labelFor(params, "O array")} deve conter ao menos um item correspondente`,
|
|
300
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "O array")} deve conter pelo menos ${params.minimum} itens correspondentes`,
|
|
301
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "O array")} deve conter no m\xE1ximo ${params.maximum} itens correspondentes`,
|
|
302
|
+
MISSING_REQUIRED: (params) => `Propriedade obrigat\xF3ria ausente "${params.property}"`,
|
|
303
|
+
ADDITIONAL_PROPERTY: (params) => `Propriedade inesperada "${params.property}"`,
|
|
304
|
+
ADDITIONAL_ITEMS: (params) => `Item inesperado no \xEDndice ${params.count}`,
|
|
305
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "O objeto")} deve ter pelo menos ${params.minimum} propriedades`,
|
|
306
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "O objeto")} deve ter no m\xE1ximo ${params.maximum} propriedades`,
|
|
307
|
+
INVALID_KEY: (params) => `Chave inv\xE1lida "${params.key}"`,
|
|
308
|
+
UNION: () => "O valor n\xE3o corresponde a nenhuma variante da uni\xE3o",
|
|
309
|
+
ENUM: (params) => `O valor deve ser um destes: ${formatList(params.values)}`,
|
|
310
|
+
UNRESOLVED_REF: () => "Refer\xEAncia de esquema n\xE3o resolvida",
|
|
311
|
+
EXCLUDE: () => "O valor correspondeu a um esquema exclu\xEDdo",
|
|
312
|
+
EXTRACT: () => "O valor n\xE3o correspondeu ao esquema extra\xEDdo",
|
|
313
|
+
NEVER: () => "O valor n\xE3o \xE9 permitido",
|
|
314
|
+
NOT: () => "O valor corresponde a um esquema negado",
|
|
315
|
+
KEYOF: (params) => `O valor deve ser um destes: ${formatList(params.values)}`,
|
|
316
|
+
CONDITIONAL: () => "O valor n\xE3o corresponde a nenhum ramo condicional",
|
|
317
|
+
INDEX: () => "O valor n\xE3o corresponde a nenhum esquema indexado",
|
|
318
|
+
IDENTIFIER: () => "Era esperado um identificador v\xE1lido",
|
|
319
|
+
BASE: () => "A valida\xE7\xE3o base falhou",
|
|
320
|
+
REFINE: (params) => params.customMessage ?? "A valida\xE7\xE3o refinada falhou",
|
|
321
|
+
CALL: () => "N\xE3o foi poss\xEDvel instanciar o esquema de chamada",
|
|
322
|
+
PARAMETERS_LENGTH: (params) => `Esperados ${params.count} par\xE2metros`,
|
|
323
|
+
CUSTOM_TYPE: (params) => `A valida\xE7\xE3o do tipo personalizado "${params.kind}" falhou`
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// src/error/locales/zh.ts
|
|
327
|
+
var zhHansCatalog = {
|
|
328
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `\u5E94\u4E3A${params.expected ?? "\u503C"}` : `\u5E94\u4E3A${params.expected ?? "\u503C"}\uFF0C\u5B9E\u9645\u7C7B\u578B\u4E3A${params.actual}`,
|
|
329
|
+
MIN_LENGTH: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B\u81F3\u5C11\u4E3A${params.minimum}`,
|
|
330
|
+
MAX_LENGTH: (params) => `${labelFor(params, "\u503C")}\u6700\u591A\u53EA\u80FD\u4E3A${params.maximum}`,
|
|
331
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "\u503C")}\u5FC5\u987B\u5339\u914D\u4EE5\u4E0B\u4E4B\u4E00\uFF1A${formatList(params.patterns)}` : `${labelFor(params, "\u503C")}\u5FC5\u987B\u5339\u914D\u6A21\u5F0F${params.pattern}`,
|
|
332
|
+
FORMAT: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B\u5339\u914D\u683C\u5F0F${params.format}`,
|
|
333
|
+
MINIMUM: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B >= ${params.minimum}`,
|
|
334
|
+
MAXIMUM: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B <= ${params.maximum}`,
|
|
335
|
+
EXCLUSIVE_MINIMUM: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B > ${params.minimum}`,
|
|
336
|
+
EXCLUSIVE_MAXIMUM: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B < ${params.maximum}`,
|
|
337
|
+
MULTIPLE_OF: (params) => `${labelFor(params, "\u503C")}\u5FC5\u987B\u662F${params.divisor}\u7684\u500D\u6570`,
|
|
338
|
+
INVALID_CONST: (params) => `\u5E94\u4E3A${params.expectedValue}`,
|
|
339
|
+
MIN_ITEMS: (params) => `${labelFor(params, "\u6570\u7EC4")}\u81F3\u5C11\u9700\u8981${params.minimum}\u4E2A\u9879\u76EE`,
|
|
340
|
+
MAX_ITEMS: (params) => `${labelFor(params, "\u6570\u7EC4")}\u6700\u591A\u53EA\u80FD\u6709${params.maximum}\u4E2A\u9879\u76EE`,
|
|
341
|
+
UNIQUE_ITEMS: (params) => `${labelFor(params, "\u6570\u7EC4")}\u4E2D\u7684\u9879\u76EE\u5FC5\u987B\u552F\u4E00`,
|
|
342
|
+
CONTAINS: (params) => `${labelFor(params, "\u6570\u7EC4")}\u81F3\u5C11\u8981\u5305\u542B\u4E00\u4E2A\u5339\u914D\u9879\u76EE`,
|
|
343
|
+
MIN_CONTAINS: (params) => `${labelFor(params, "\u6570\u7EC4")}\u81F3\u5C11\u8981\u5305\u542B${params.minimum}\u4E2A\u5339\u914D\u9879\u76EE`,
|
|
344
|
+
MAX_CONTAINS: (params) => `${labelFor(params, "\u6570\u7EC4")}\u6700\u591A\u53EA\u80FD\u5305\u542B${params.maximum}\u4E2A\u5339\u914D\u9879\u76EE`,
|
|
345
|
+
MISSING_REQUIRED: (params) => `\u7F3A\u5C11\u5FC5\u586B\u5C5E\u6027"${params.property}"`,
|
|
346
|
+
ADDITIONAL_PROPERTY: (params) => `\u5B58\u5728\u672A\u9884\u671F\u7684\u5C5E\u6027"${params.property}"`,
|
|
347
|
+
ADDITIONAL_ITEMS: (params) => `\u7D22\u5F15${params.count}\u5904\u5B58\u5728\u672A\u9884\u671F\u7684\u9879\u76EE`,
|
|
348
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "\u5BF9\u8C61")}\u81F3\u5C11\u9700\u8981${params.minimum}\u4E2A\u5C5E\u6027`,
|
|
349
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "\u5BF9\u8C61")}\u6700\u591A\u53EA\u80FD\u6709${params.maximum}\u4E2A\u5C5E\u6027`,
|
|
350
|
+
INVALID_KEY: (params) => `\u65E0\u6548\u7684\u8BB0\u5F55\u952E"${params.key}"`,
|
|
351
|
+
UNION: () => "\u503C\u4E0D\u7B26\u5408\u4EFB\u4F55\u8054\u5408\u5206\u652F",
|
|
352
|
+
ENUM: (params) => `\u503C\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00\uFF1A${formatList(params.values)}`,
|
|
353
|
+
UNRESOLVED_REF: () => "\u65E0\u6CD5\u89E3\u6790\u7684\u6A21\u5F0F\u5F15\u7528",
|
|
354
|
+
EXCLUDE: () => "\u503C\u5339\u914D\u4E86\u88AB\u6392\u9664\u7684\u6A21\u5F0F",
|
|
355
|
+
EXTRACT: () => "\u503C\u4E0D\u5339\u914D\u63D0\u53D6\u540E\u7684\u6A21\u5F0F",
|
|
356
|
+
NEVER: () => "\u4E0D\u5141\u8BB8\u8BE5\u503C",
|
|
357
|
+
NOT: () => "\u503C\u5339\u914D\u4E86\u5426\u5B9A\u6A21\u5F0F",
|
|
358
|
+
KEYOF: (params) => `\u503C\u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00\uFF1A${formatList(params.values)}`,
|
|
359
|
+
CONDITIONAL: () => "\u503C\u4E0D\u5339\u914D\u4EFB\u4F55\u6761\u4EF6\u5206\u652F",
|
|
360
|
+
INDEX: () => "\u503C\u4E0D\u5339\u914D\u4EFB\u4F55\u7D22\u5F15\u6A21\u5F0F",
|
|
361
|
+
IDENTIFIER: () => "\u5FC5\u987B\u662F\u6709\u6548\u7684\u6807\u8BC6\u7B26\u5B57\u7B26\u4E32",
|
|
362
|
+
BASE: () => "\u57FA\u7840\u9A8C\u8BC1\u5931\u8D25",
|
|
363
|
+
REFINE: (params) => params.customMessage ?? "\u7EC6\u5316\u9A8C\u8BC1\u5931\u8D25",
|
|
364
|
+
CALL: () => "\u65E0\u6CD5\u5B9E\u4F8B\u5316\u8C03\u7528\u6A21\u5F0F",
|
|
365
|
+
PARAMETERS_LENGTH: (params) => `\u53C2\u6570\u6570\u91CF\u5FC5\u987B\u4E3A${params.count}`,
|
|
366
|
+
CUSTOM_TYPE: (params) => `\u81EA\u5B9A\u4E49\u7C7B\u578B"${params.kind}"\u9A8C\u8BC1\u5931\u8D25`
|
|
367
|
+
};
|
|
368
|
+
var zhHantCatalog = {
|
|
369
|
+
...zhHansCatalog,
|
|
370
|
+
INVALID_TYPE: (params) => params.actual === undefined ? `\u61C9\u70BA${params.expected ?? "\u503C"}` : `\u61C9\u70BA${params.expected ?? "\u503C"}\uFF0C\u5BE6\u969B\u985E\u578B\u70BA${params.actual}`,
|
|
371
|
+
PATTERN: (params) => params.patterns !== undefined ? `${labelFor(params, "\u503C")}\u5FC5\u9808\u7B26\u5408\u4EE5\u4E0B\u5176\u4E2D\u4E4B\u4E00\uFF1A${formatList(params.patterns)}` : `${labelFor(params, "\u503C")}\u5FC5\u9808\u7B26\u5408\u6A21\u5F0F${params.pattern}`,
|
|
372
|
+
MISSING_REQUIRED: (params) => `\u7F3A\u5C11\u5FC5\u8981\u5C6C\u6027"${params.property}"`,
|
|
373
|
+
ADDITIONAL_PROPERTY: (params) => `\u5B58\u5728\u672A\u9810\u671F\u7684\u5C6C\u6027"${params.property}"`,
|
|
374
|
+
ADDITIONAL_ITEMS: (params) => `\u7D22\u5F15${params.count}\u8655\u5B58\u5728\u672A\u9810\u671F\u7684\u9805\u76EE`,
|
|
375
|
+
MIN_PROPERTIES: (params) => `${labelFor(params, "\u7269\u4EF6")}\u81F3\u5C11\u9700\u8981${params.minimum}\u500B\u5C6C\u6027`,
|
|
376
|
+
MAX_PROPERTIES: (params) => `${labelFor(params, "\u7269\u4EF6")}\u6700\u591A\u53EA\u80FD\u6709${params.maximum}\u500B\u5C6C\u6027`,
|
|
377
|
+
INVALID_KEY: (params) => `\u7121\u6548\u7684\u8A18\u9304\u9375"${params.key}"`,
|
|
378
|
+
UNRESOLVED_REF: () => "\u7121\u6CD5\u89E3\u6790\u7684\u7D50\u69CB\u53C3\u7167",
|
|
379
|
+
EXCLUDE: () => "\u503C\u7B26\u5408\u88AB\u6392\u9664\u7684\u7D50\u69CB",
|
|
380
|
+
EXTRACT: () => "\u503C\u4E0D\u7B26\u5408\u63D0\u53D6\u5F8C\u7684\u7D50\u69CB",
|
|
381
|
+
NEVER: () => "\u4E0D\u5141\u8A31\u6B64\u503C",
|
|
382
|
+
CONDITIONAL: () => "\u503C\u4E0D\u7B26\u5408\u4EFB\u4F55\u689D\u4EF6\u5206\u652F",
|
|
383
|
+
INDEX: () => "\u503C\u4E0D\u7B26\u5408\u4EFB\u4F55\u7D22\u5F15\u7D50\u69CB",
|
|
384
|
+
IDENTIFIER: () => "\u5FC5\u9808\u662F\u6709\u6548\u7684\u8B58\u5225\u5B57\u4E32",
|
|
385
|
+
BASE: () => "\u57FA\u790E\u9A57\u8B49\u5931\u6557",
|
|
386
|
+
REFINE: (params) => params.customMessage ?? "\u7D30\u5316\u9A57\u8B49\u5931\u6557",
|
|
387
|
+
CALL: () => "\u7121\u6CD5\u5BE6\u4F8B\u5316\u547C\u53EB\u7D50\u69CB",
|
|
388
|
+
PARAMETERS_LENGTH: (params) => `\u53C3\u6578\u6578\u91CF\u5FC5\u9808\u70BA${params.count}`,
|
|
389
|
+
CUSTOM_TYPE: (params) => `\u81EA\u8A02\u985E\u578B"${params.kind}"\u9A57\u8B49\u5931\u6557`
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// src/shared/locale.ts
|
|
393
|
+
var LocaleCodes = {
|
|
394
|
+
ar_001: "ar_001",
|
|
395
|
+
bn_BD: "bn_BD",
|
|
396
|
+
cs_CZ: "cs_CZ",
|
|
397
|
+
de_DE: "de_DE",
|
|
398
|
+
el_GR: "el_GR",
|
|
399
|
+
en_US: "en_US",
|
|
400
|
+
es_419: "es_419",
|
|
401
|
+
es_AR: "es_AR",
|
|
402
|
+
es_ES: "es_ES",
|
|
403
|
+
es_MX: "es_MX",
|
|
404
|
+
fa_IR: "fa_IR",
|
|
405
|
+
fil_PH: "fil_PH",
|
|
406
|
+
fr_CA: "fr_CA",
|
|
407
|
+
fr_FR: "fr_FR",
|
|
408
|
+
ha_NG: "ha_NG",
|
|
409
|
+
hi_IN: "hi_IN",
|
|
410
|
+
hu_HU: "hu_HU",
|
|
411
|
+
id_ID: "id_ID",
|
|
412
|
+
it_IT: "it_IT",
|
|
413
|
+
ja_JP: "ja_JP",
|
|
414
|
+
ko_KR: "ko_KR",
|
|
415
|
+
ms_MY: "ms_MY",
|
|
416
|
+
nl_NL: "nl_NL",
|
|
417
|
+
pl_PL: "pl_PL",
|
|
418
|
+
pt_BR: "pt_BR",
|
|
419
|
+
pt_PT: "pt_PT",
|
|
420
|
+
ro_RO: "ro_RO",
|
|
421
|
+
ru_RU: "ru_RU",
|
|
422
|
+
sv_SE: "sv_SE",
|
|
423
|
+
sw_TZ: "sw_TZ",
|
|
424
|
+
th_TH: "th_TH",
|
|
425
|
+
tr_TR: "tr_TR",
|
|
426
|
+
uk_UA: "uk_UA",
|
|
427
|
+
ur_PK: "ur_PK",
|
|
428
|
+
vi_VN: "vi_VN",
|
|
429
|
+
yo_NG: "yo_NG",
|
|
430
|
+
zh_Hans: "zh_Hans",
|
|
431
|
+
zh_Hant: "zh_Hant"
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// src/locale/index.ts
|
|
435
|
+
var ar_001 = enUSCatalog;
|
|
436
|
+
var bn_BD = enUSCatalog;
|
|
437
|
+
var cs_CZ = enUSCatalog;
|
|
438
|
+
var de_DE = deDECatalog;
|
|
439
|
+
var el_GR = enUSCatalog;
|
|
440
|
+
var en_US = enUSCatalog;
|
|
441
|
+
var es_419 = esESCatalog;
|
|
442
|
+
var es_AR = esESCatalog;
|
|
443
|
+
var es_ES = esESCatalog;
|
|
444
|
+
var es_MX = esESCatalog;
|
|
445
|
+
var fa_IR = enUSCatalog;
|
|
446
|
+
var fil_PH = enUSCatalog;
|
|
447
|
+
var fr_CA = frFRCatalog;
|
|
448
|
+
var fr_FR = frFRCatalog;
|
|
449
|
+
var ha_NG = enUSCatalog;
|
|
450
|
+
var hi_IN = enUSCatalog;
|
|
451
|
+
var hu_HU = enUSCatalog;
|
|
452
|
+
var id_ID = enUSCatalog;
|
|
453
|
+
var it_IT = enUSCatalog;
|
|
454
|
+
var ja_JP = jaJPCatalog;
|
|
455
|
+
var ko_KR = koKRCatalog;
|
|
456
|
+
var ms_MY = enUSCatalog;
|
|
457
|
+
var nl_NL = enUSCatalog;
|
|
458
|
+
var pl_PL = enUSCatalog;
|
|
459
|
+
var pt_BR = ptBRCatalog;
|
|
460
|
+
var pt_PT = ptBRCatalog;
|
|
461
|
+
var ro_RO = enUSCatalog;
|
|
462
|
+
var ru_RU = enUSCatalog;
|
|
463
|
+
var sv_SE = enUSCatalog;
|
|
464
|
+
var sw_TZ = enUSCatalog;
|
|
465
|
+
var th_TH = enUSCatalog;
|
|
466
|
+
var tr_TR = enUSCatalog;
|
|
467
|
+
var uk_UA = enUSCatalog;
|
|
468
|
+
var ur_PK = enUSCatalog;
|
|
469
|
+
var vi_VN = enUSCatalog;
|
|
470
|
+
var yo_NG = enUSCatalog;
|
|
471
|
+
var zh_Hans = zhHansCatalog;
|
|
472
|
+
var zh_Hant = zhHantCatalog;
|
|
473
|
+
var OfficialLocaleCatalogs = {
|
|
474
|
+
[LocaleCodes.ar_001]: ar_001,
|
|
475
|
+
[LocaleCodes.bn_BD]: bn_BD,
|
|
476
|
+
[LocaleCodes.cs_CZ]: cs_CZ,
|
|
477
|
+
[LocaleCodes.de_DE]: de_DE,
|
|
478
|
+
[LocaleCodes.el_GR]: el_GR,
|
|
479
|
+
[LocaleCodes.en_US]: en_US,
|
|
480
|
+
[LocaleCodes.es_419]: es_419,
|
|
481
|
+
[LocaleCodes.es_AR]: es_AR,
|
|
482
|
+
[LocaleCodes.es_ES]: es_ES,
|
|
483
|
+
[LocaleCodes.es_MX]: es_MX,
|
|
484
|
+
[LocaleCodes.fa_IR]: fa_IR,
|
|
485
|
+
[LocaleCodes.fil_PH]: fil_PH,
|
|
486
|
+
[LocaleCodes.fr_CA]: fr_CA,
|
|
487
|
+
[LocaleCodes.fr_FR]: fr_FR,
|
|
488
|
+
[LocaleCodes.ha_NG]: ha_NG,
|
|
489
|
+
[LocaleCodes.hi_IN]: hi_IN,
|
|
490
|
+
[LocaleCodes.hu_HU]: hu_HU,
|
|
491
|
+
[LocaleCodes.id_ID]: id_ID,
|
|
492
|
+
[LocaleCodes.it_IT]: it_IT,
|
|
493
|
+
[LocaleCodes.ja_JP]: ja_JP,
|
|
494
|
+
[LocaleCodes.ko_KR]: ko_KR,
|
|
495
|
+
[LocaleCodes.ms_MY]: ms_MY,
|
|
496
|
+
[LocaleCodes.nl_NL]: nl_NL,
|
|
497
|
+
[LocaleCodes.pl_PL]: pl_PL,
|
|
498
|
+
[LocaleCodes.pt_BR]: pt_BR,
|
|
499
|
+
[LocaleCodes.pt_PT]: pt_PT,
|
|
500
|
+
[LocaleCodes.ro_RO]: ro_RO,
|
|
501
|
+
[LocaleCodes.ru_RU]: ru_RU,
|
|
502
|
+
[LocaleCodes.sv_SE]: sv_SE,
|
|
503
|
+
[LocaleCodes.sw_TZ]: sw_TZ,
|
|
504
|
+
[LocaleCodes.th_TH]: th_TH,
|
|
505
|
+
[LocaleCodes.tr_TR]: tr_TR,
|
|
506
|
+
[LocaleCodes.uk_UA]: uk_UA,
|
|
507
|
+
[LocaleCodes.ur_PK]: ur_PK,
|
|
508
|
+
[LocaleCodes.vi_VN]: vi_VN,
|
|
509
|
+
[LocaleCodes.yo_NG]: yo_NG,
|
|
510
|
+
[LocaleCodes.zh_Hans]: zh_Hans,
|
|
511
|
+
[LocaleCodes.zh_Hant]: zh_Hant
|
|
512
|
+
};
|
|
513
|
+
function LocaleCatalogEntries() {
|
|
514
|
+
return Object.values(LocaleCodes).map((locale) => [locale, OfficialLocaleCatalogs[locale]]);
|
|
515
|
+
}
|
|
516
|
+
var LocalePacks = OfficialLocaleCatalogs;
|
|
517
|
+
var locale_default = LocalePacks;
|
|
518
|
+
|
|
519
|
+
// src/shared/object-utils.ts
|
|
520
|
+
function deriveObjectSchema(object, options = {}) {
|
|
521
|
+
const pickSet = options.pickKeys ? new Set(options.pickKeys) : undefined;
|
|
522
|
+
const omitSet = options.omitKeys ? new Set(options.omitKeys) : undefined;
|
|
523
|
+
const originalOptional = new Set((object.optional ?? []).map(String));
|
|
524
|
+
const originalRequired = new Set((object.required ?? []).map(String));
|
|
525
|
+
const originalProperties = object.properties;
|
|
526
|
+
const properties = {};
|
|
527
|
+
for (const [key, schema] of Object.entries(originalProperties)) {
|
|
528
|
+
if (pickSet && !pickSet.has(key))
|
|
529
|
+
continue;
|
|
530
|
+
if (omitSet && omitSet.has(key))
|
|
531
|
+
continue;
|
|
532
|
+
properties[key] = schema;
|
|
533
|
+
}
|
|
534
|
+
const keys = Object.keys(properties);
|
|
535
|
+
const required = options.requiredMode === "all" ? keys : options.requiredMode === "none" ? [] : keys.filter((key) => originalRequired.has(key));
|
|
536
|
+
const optional = keys.filter((key) => originalOptional.has(key) && !required.includes(key));
|
|
537
|
+
return {
|
|
538
|
+
"~kind": "Object",
|
|
539
|
+
properties,
|
|
540
|
+
...required.length > 0 ? { required } : {},
|
|
541
|
+
...optional.length > 0 ? { optional } : {},
|
|
542
|
+
...object.patternProperties !== undefined ? { patternProperties: object.patternProperties } : {},
|
|
543
|
+
...options.additionalProperties !== undefined ? { additionalProperties: options.additionalProperties } : object.additionalProperties !== undefined ? { additionalProperties: object.additionalProperties } : {}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function getPatternPropertySchemas(patternProperties, key) {
|
|
547
|
+
if (!patternProperties)
|
|
548
|
+
return [];
|
|
549
|
+
const matches = [];
|
|
550
|
+
for (const [pattern, schema] of Object.entries(patternProperties)) {
|
|
551
|
+
if (new RegExp(pattern).test(key)) {
|
|
552
|
+
matches.push(schema);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return matches;
|
|
556
|
+
}
|
|
557
|
+
function deriveIndexSchemas(object, keySchema, checkFn) {
|
|
558
|
+
const candidates = [];
|
|
559
|
+
const properties = object.properties;
|
|
560
|
+
for (const [key, schema] of Object.entries(properties)) {
|
|
561
|
+
if (checkFn(keySchema, key)) {
|
|
562
|
+
candidates.push(schema);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return candidates;
|
|
566
|
+
}
|
|
567
|
+
function deriveIndexSchemasForEmission(object, keySchema) {
|
|
568
|
+
const candidates = [];
|
|
569
|
+
const properties = object.properties;
|
|
570
|
+
const keySchemaRecord = keySchema;
|
|
571
|
+
for (const [key, schema] of Object.entries(properties)) {
|
|
572
|
+
const keyValidationSchema = {
|
|
573
|
+
"~kind": "String",
|
|
574
|
+
...typeof keySchemaRecord.format === "string" ? { format: keySchemaRecord.format } : {},
|
|
575
|
+
...typeof keySchemaRecord.pattern === "string" ? { pattern: keySchemaRecord.pattern } : {}
|
|
576
|
+
};
|
|
577
|
+
if (keySchemaRecord["~kind"] === "String" ? stringMatchesKeySchema(keyValidationSchema, key) : true) {
|
|
578
|
+
candidates.push(schema);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return candidates;
|
|
582
|
+
}
|
|
583
|
+
function stringMatchesKeySchema(schema, value) {
|
|
584
|
+
return schema.pattern === undefined || new RegExp(schema.pattern).test(value);
|
|
585
|
+
}
|
|
586
|
+
function transformStringLiteralValue(kind, value) {
|
|
587
|
+
switch (kind) {
|
|
588
|
+
case "Capitalize":
|
|
589
|
+
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
590
|
+
case "Lowercase":
|
|
591
|
+
return value.toLowerCase();
|
|
592
|
+
case "Uppercase":
|
|
593
|
+
return value.toUpperCase();
|
|
594
|
+
case "Uncapitalize":
|
|
595
|
+
return value.length === 0 ? value : value.charAt(0).toLowerCase() + value.slice(1);
|
|
596
|
+
default:
|
|
597
|
+
return value;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function resolveStringActionSchema(schema) {
|
|
601
|
+
const value = schema;
|
|
602
|
+
const kind = value["~kind"];
|
|
603
|
+
if (kind !== "Capitalize" && kind !== "Lowercase" && kind !== "Uppercase" && kind !== "Uncapitalize") {
|
|
604
|
+
return schema;
|
|
605
|
+
}
|
|
606
|
+
const item = value["item"];
|
|
607
|
+
if (typeof item !== "object" || item === null) {
|
|
608
|
+
return schema;
|
|
609
|
+
}
|
|
610
|
+
const target = item;
|
|
611
|
+
const targetKind = target["~kind"];
|
|
612
|
+
if (targetKind === "Literal" && typeof target["const"] === "string") {
|
|
613
|
+
return { "~kind": "Literal", const: transformStringLiteralValue(String(kind), target["const"]) };
|
|
614
|
+
}
|
|
615
|
+
if (targetKind === "Enum" && Array.isArray(target["values"]) && target["values"].every((entry) => typeof entry === "string")) {
|
|
616
|
+
return {
|
|
617
|
+
"~kind": "Enum",
|
|
618
|
+
values: target["values"].map((entry) => transformStringLiteralValue(String(kind), entry))
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return item;
|
|
622
|
+
}
|
|
623
|
+
// src/shared/runtime-guards.ts
|
|
624
|
+
function isPromiseLike(value) {
|
|
625
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value && typeof value.then === "function";
|
|
626
|
+
}
|
|
627
|
+
function isIteratorLike(value) {
|
|
628
|
+
return typeof value === "object" && value !== null && "next" in value && typeof value.next === "function" && Symbol.iterator in value && typeof value[Symbol.iterator] === "function";
|
|
629
|
+
}
|
|
630
|
+
function isAsyncIteratorLike(value) {
|
|
631
|
+
return typeof value === "object" && value !== null && "next" in value && typeof value.next === "function" && Symbol.asyncIterator in value && typeof value[Symbol.asyncIterator] === "function";
|
|
632
|
+
}
|
|
633
|
+
// src/shared/format-constants.ts
|
|
634
|
+
var EMAIL_RE = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[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])?)*$/;
|
|
635
|
+
var URI_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
|
|
636
|
+
var HOSTNAME_RE = /^(?!-)[a-zA-Z0-9-]{0,63}(?<!-)(.(?!-)[a-zA-Z0-9-]{0,63}(?<!-))*$/;
|
|
637
|
+
var IPV4_RE = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
638
|
+
var IPV6_RE = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){1,6}::$/;
|
|
639
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
640
|
+
var ISO_DATE_RE = /^\d{4}-(0[1-9]|1[0-2])-([0-2]\d|3[01])$/;
|
|
641
|
+
var ISO_DT_RE = /^\d{4}-(0[1-9]|1[0-2])-([0-2]\d|3[01])T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-][01]\d:[0-5]\d)$/;
|
|
642
|
+
var ISO_TIME_RE = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?$/;
|
|
643
|
+
var ISO_DUR_RE = /^P(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$/;
|
|
644
|
+
var BASE64_RE = /^[a-zA-Z0-9+/]*={0,2}$/;
|
|
645
|
+
var HEX_RE = /^[0-9a-fA-F]+$/;
|
|
646
|
+
var HEXCLR_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
647
|
+
var LUHN_DIGITS_RE = /^\d{13,19}$/;
|
|
648
|
+
var KNOWN_FORMATS = new Set([
|
|
649
|
+
"email",
|
|
650
|
+
"uri",
|
|
651
|
+
"hostname",
|
|
652
|
+
"ip",
|
|
653
|
+
"ipv4",
|
|
654
|
+
"ipv6",
|
|
655
|
+
"uuid",
|
|
656
|
+
"date",
|
|
657
|
+
"datetime",
|
|
658
|
+
"time",
|
|
659
|
+
"duration",
|
|
660
|
+
"base64",
|
|
661
|
+
"hex",
|
|
662
|
+
"hexcolor",
|
|
663
|
+
"creditcard",
|
|
664
|
+
"regex",
|
|
665
|
+
"uint8array",
|
|
666
|
+
"json"
|
|
667
|
+
]);
|
|
668
|
+
// src/shared/regex-json.ts
|
|
669
|
+
function isAsciiDigit(value) {
|
|
670
|
+
return value >= "0" && value <= "9";
|
|
671
|
+
}
|
|
672
|
+
function consumeRegexQuantifier(pattern, start) {
|
|
673
|
+
let index = start;
|
|
674
|
+
const first = pattern[index];
|
|
675
|
+
if (first === undefined || !isAsciiDigit(first)) {
|
|
676
|
+
return -1;
|
|
677
|
+
}
|
|
678
|
+
while (index < pattern.length) {
|
|
679
|
+
const character = pattern[index];
|
|
680
|
+
if (character === undefined || !isAsciiDigit(character)) {
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
index += 1;
|
|
684
|
+
}
|
|
685
|
+
if (pattern[index] === ",") {
|
|
686
|
+
index += 1;
|
|
687
|
+
while (index < pattern.length) {
|
|
688
|
+
const character = pattern[index];
|
|
689
|
+
if (character === undefined || !isAsciiDigit(character)) {
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
index += 1;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return pattern[index] === "}" ? index : -1;
|
|
696
|
+
}
|
|
697
|
+
function isValidRegex(value) {
|
|
698
|
+
let escaped = false;
|
|
699
|
+
let inCharacterClass = false;
|
|
700
|
+
let groupDepth = 0;
|
|
701
|
+
let hasToken = false;
|
|
702
|
+
let groupPrefixAllowed = false;
|
|
703
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
704
|
+
const character = value[index];
|
|
705
|
+
if (character === undefined)
|
|
706
|
+
return false;
|
|
707
|
+
if (escaped) {
|
|
708
|
+
escaped = false;
|
|
709
|
+
hasToken = true;
|
|
710
|
+
groupPrefixAllowed = false;
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
if (character === "\\") {
|
|
714
|
+
escaped = true;
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (inCharacterClass) {
|
|
718
|
+
if (character === "]") {
|
|
719
|
+
inCharacterClass = false;
|
|
720
|
+
hasToken = true;
|
|
721
|
+
}
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
if (groupPrefixAllowed && character === "?") {
|
|
725
|
+
groupPrefixAllowed = false;
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
groupPrefixAllowed = false;
|
|
729
|
+
switch (character) {
|
|
730
|
+
case "[":
|
|
731
|
+
inCharacterClass = true;
|
|
732
|
+
hasToken = true;
|
|
733
|
+
break;
|
|
734
|
+
case "(":
|
|
735
|
+
groupDepth += 1;
|
|
736
|
+
hasToken = false;
|
|
737
|
+
groupPrefixAllowed = true;
|
|
738
|
+
break;
|
|
739
|
+
case ")":
|
|
740
|
+
if (groupDepth === 0)
|
|
741
|
+
return false;
|
|
742
|
+
groupDepth -= 1;
|
|
743
|
+
hasToken = true;
|
|
744
|
+
break;
|
|
745
|
+
case "{": {
|
|
746
|
+
if (!hasToken)
|
|
747
|
+
return false;
|
|
748
|
+
const quantifierEnd = consumeRegexQuantifier(value, index + 1);
|
|
749
|
+
if (quantifierEnd < 0)
|
|
750
|
+
return false;
|
|
751
|
+
index = quantifierEnd;
|
|
752
|
+
hasToken = true;
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
case "*":
|
|
756
|
+
case "+":
|
|
757
|
+
case "?":
|
|
758
|
+
if (!hasToken)
|
|
759
|
+
return false;
|
|
760
|
+
hasToken = true;
|
|
761
|
+
break;
|
|
762
|
+
case "]":
|
|
763
|
+
case "}":
|
|
764
|
+
return false;
|
|
765
|
+
case "|":
|
|
766
|
+
hasToken = false;
|
|
767
|
+
break;
|
|
768
|
+
default:
|
|
769
|
+
hasToken = true;
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return !escaped && !inCharacterClass && groupDepth === 0;
|
|
774
|
+
}
|
|
775
|
+
function skipWhitespace(state) {
|
|
776
|
+
while (state.index < state.text.length) {
|
|
777
|
+
const character = state.text[state.index];
|
|
778
|
+
if (character !== " " && character !== `
|
|
779
|
+
` && character !== "\r" && character !== "\t") {
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
state.index += 1;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function consumeLiteral(state, literal) {
|
|
786
|
+
if (state.text.slice(state.index, state.index + literal.length) !== literal) {
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
state.index += literal.length;
|
|
790
|
+
return true;
|
|
791
|
+
}
|
|
792
|
+
function parseString(state) {
|
|
793
|
+
if (state.text[state.index] !== '"')
|
|
794
|
+
return false;
|
|
795
|
+
state.index += 1;
|
|
796
|
+
while (state.index < state.text.length) {
|
|
797
|
+
const character = state.text[state.index];
|
|
798
|
+
if (character === undefined)
|
|
799
|
+
return false;
|
|
800
|
+
if (character === '"') {
|
|
801
|
+
state.index += 1;
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
if (character === "\\") {
|
|
805
|
+
const escape = state.text[state.index + 1];
|
|
806
|
+
if (escape === undefined)
|
|
807
|
+
return false;
|
|
808
|
+
if (escape === "u") {
|
|
809
|
+
for (let offset = 2;offset < 6; offset += 1) {
|
|
810
|
+
const hex = state.text[state.index + offset];
|
|
811
|
+
if (hex === undefined || !/[0-9a-fA-F]/.test(hex))
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
state.index += 6;
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (!'"\\/bfnrt'.includes(escape))
|
|
818
|
+
return false;
|
|
819
|
+
state.index += 2;
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
if (character < " ")
|
|
823
|
+
return false;
|
|
824
|
+
state.index += 1;
|
|
825
|
+
}
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
function parseNumber(state) {
|
|
829
|
+
const start = state.index;
|
|
830
|
+
if (state.text[state.index] === "-") {
|
|
831
|
+
state.index += 1;
|
|
832
|
+
}
|
|
833
|
+
const firstDigit = state.text[state.index];
|
|
834
|
+
if (firstDigit === undefined || !isAsciiDigit(firstDigit))
|
|
835
|
+
return false;
|
|
836
|
+
if (firstDigit === "0") {
|
|
837
|
+
state.index += 1;
|
|
838
|
+
} else {
|
|
839
|
+
while (state.index < state.text.length) {
|
|
840
|
+
const digit = state.text[state.index];
|
|
841
|
+
if (digit === undefined || !isAsciiDigit(digit))
|
|
842
|
+
break;
|
|
843
|
+
state.index += 1;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (state.text[state.index] === ".") {
|
|
847
|
+
state.index += 1;
|
|
848
|
+
const fractionDigit = state.text[state.index];
|
|
849
|
+
if (fractionDigit === undefined || !isAsciiDigit(fractionDigit))
|
|
850
|
+
return false;
|
|
851
|
+
while (state.index < state.text.length) {
|
|
852
|
+
const digit = state.text[state.index];
|
|
853
|
+
if (digit === undefined || !isAsciiDigit(digit))
|
|
854
|
+
break;
|
|
855
|
+
state.index += 1;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
const exponent = state.text[state.index];
|
|
859
|
+
if (exponent === "e" || exponent === "E") {
|
|
860
|
+
state.index += 1;
|
|
861
|
+
const sign = state.text[state.index];
|
|
862
|
+
if (sign === "+" || sign === "-")
|
|
863
|
+
state.index += 1;
|
|
864
|
+
const exponentDigit = state.text[state.index];
|
|
865
|
+
if (exponentDigit === undefined || !isAsciiDigit(exponentDigit))
|
|
866
|
+
return false;
|
|
867
|
+
while (state.index < state.text.length) {
|
|
868
|
+
const digit = state.text[state.index];
|
|
869
|
+
if (digit === undefined || !isAsciiDigit(digit))
|
|
870
|
+
break;
|
|
871
|
+
state.index += 1;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return state.index > start;
|
|
875
|
+
}
|
|
876
|
+
function parseArray(state) {
|
|
877
|
+
if (state.text[state.index] !== "[")
|
|
878
|
+
return false;
|
|
879
|
+
state.index += 1;
|
|
880
|
+
skipWhitespace(state);
|
|
881
|
+
if (state.text[state.index] === "]") {
|
|
882
|
+
state.index += 1;
|
|
883
|
+
return true;
|
|
884
|
+
}
|
|
885
|
+
while (state.index < state.text.length) {
|
|
886
|
+
if (!parseValue(state))
|
|
887
|
+
return false;
|
|
888
|
+
skipWhitespace(state);
|
|
889
|
+
const separator = state.text[state.index];
|
|
890
|
+
if (separator === ",") {
|
|
891
|
+
state.index += 1;
|
|
892
|
+
skipWhitespace(state);
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
if (separator === "]") {
|
|
896
|
+
state.index += 1;
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
function parseObject(state) {
|
|
904
|
+
if (state.text[state.index] !== "{")
|
|
905
|
+
return false;
|
|
906
|
+
state.index += 1;
|
|
907
|
+
skipWhitespace(state);
|
|
908
|
+
if (state.text[state.index] === "}") {
|
|
909
|
+
state.index += 1;
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
while (state.index < state.text.length) {
|
|
913
|
+
if (!parseString(state))
|
|
914
|
+
return false;
|
|
915
|
+
skipWhitespace(state);
|
|
916
|
+
if (state.text[state.index] !== ":")
|
|
917
|
+
return false;
|
|
918
|
+
state.index += 1;
|
|
919
|
+
if (!parseValue(state))
|
|
920
|
+
return false;
|
|
921
|
+
skipWhitespace(state);
|
|
922
|
+
const separator = state.text[state.index];
|
|
923
|
+
if (separator === ",") {
|
|
924
|
+
state.index += 1;
|
|
925
|
+
skipWhitespace(state);
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (separator === "}") {
|
|
929
|
+
state.index += 1;
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
function parseValue(state) {
|
|
937
|
+
skipWhitespace(state);
|
|
938
|
+
const character = state.text[state.index];
|
|
939
|
+
switch (character) {
|
|
940
|
+
case '"':
|
|
941
|
+
return parseString(state);
|
|
942
|
+
case "{":
|
|
943
|
+
return parseObject(state);
|
|
944
|
+
case "[":
|
|
945
|
+
return parseArray(state);
|
|
946
|
+
case "t":
|
|
947
|
+
return consumeLiteral(state, "true");
|
|
948
|
+
case "f":
|
|
949
|
+
return consumeLiteral(state, "false");
|
|
950
|
+
case "n":
|
|
951
|
+
return consumeLiteral(state, "null");
|
|
952
|
+
default:
|
|
953
|
+
return character === "-" || character !== undefined && isAsciiDigit(character) ? parseNumber(state) : false;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
function isValidJson(value) {
|
|
957
|
+
const state = { index: 0, text: value };
|
|
958
|
+
if (!parseValue(state))
|
|
959
|
+
return false;
|
|
960
|
+
skipWhitespace(state);
|
|
961
|
+
return state.index === state.text.length;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// src/shared/runtime-context.ts
|
|
965
|
+
var builtinLocaleCatalogEntries = LocaleCatalogEntries();
|
|
966
|
+
var defaultTypePolicy = {
|
|
967
|
+
AllowNaN: false,
|
|
968
|
+
AllowArrayObject: false,
|
|
969
|
+
AllowNullVoid: true
|
|
970
|
+
};
|
|
971
|
+
var defaultSettings = {
|
|
972
|
+
correctiveParse: false
|
|
973
|
+
};
|
|
974
|
+
var runtimeContextCounter = 0;
|
|
975
|
+
function cloneEntries(entries) {
|
|
976
|
+
return Array.from(entries, ([key, value]) => [key, value]);
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
class RuntimeContext {
|
|
980
|
+
id = ++runtimeContextCounter;
|
|
981
|
+
revision = 0;
|
|
982
|
+
activeLocale;
|
|
983
|
+
formatValidators = new Map;
|
|
984
|
+
localeCatalogs = new Map;
|
|
985
|
+
settings;
|
|
986
|
+
typeValidators = new Map;
|
|
987
|
+
typePolicy;
|
|
988
|
+
FormatRegistry = {
|
|
989
|
+
Clear: () => {
|
|
990
|
+
this.formatValidators.clear();
|
|
991
|
+
this.touch();
|
|
992
|
+
},
|
|
993
|
+
Delete: (name) => {
|
|
994
|
+
const deleted = this.formatValidators.delete(name);
|
|
995
|
+
if (deleted) {
|
|
996
|
+
this.touch();
|
|
997
|
+
}
|
|
998
|
+
return deleted;
|
|
999
|
+
},
|
|
1000
|
+
Entries: () => Array.from(this.formatValidators.entries()),
|
|
1001
|
+
Get: (name) => this.formatValidators.get(name),
|
|
1002
|
+
Has: (name) => this.formatValidators.has(name),
|
|
1003
|
+
Set: (name, validator) => {
|
|
1004
|
+
this.formatValidators.set(name, validator);
|
|
1005
|
+
this.touch();
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
Locale = {
|
|
1009
|
+
...LocaleCodes,
|
|
1010
|
+
Entries: () => Array.from(this.localeCatalogs.entries()),
|
|
1011
|
+
Get: () => this.activeLocale,
|
|
1012
|
+
GetCatalog: (locale = this.activeLocale) => this.localeCatalogs.get(locale) ?? this.localeCatalogs.get(LocaleCodes.en_US) ?? enUSCatalog,
|
|
1013
|
+
Has: (locale) => this.localeCatalogs.has(locale),
|
|
1014
|
+
Register: (locale, catalog) => {
|
|
1015
|
+
this.localeCatalogs.set(locale, catalog);
|
|
1016
|
+
this.touch();
|
|
1017
|
+
},
|
|
1018
|
+
Reset: () => {
|
|
1019
|
+
this.activeLocale = LocaleCodes.en_US;
|
|
1020
|
+
this.touch();
|
|
1021
|
+
},
|
|
1022
|
+
Set: (locale) => {
|
|
1023
|
+
this.activeLocale = locale;
|
|
1024
|
+
this.touch();
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
Settings = {
|
|
1028
|
+
Get: () => this.settings,
|
|
1029
|
+
Reset: () => {
|
|
1030
|
+
this.settings = { ...defaultSettings };
|
|
1031
|
+
this.touch();
|
|
1032
|
+
},
|
|
1033
|
+
Set: (options) => {
|
|
1034
|
+
this.settings = { ...this.settings, ...options };
|
|
1035
|
+
this.touch();
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
TypeRegistry = {
|
|
1039
|
+
Clear: () => {
|
|
1040
|
+
this.typeValidators.clear();
|
|
1041
|
+
this.touch();
|
|
1042
|
+
},
|
|
1043
|
+
Delete: (kind) => {
|
|
1044
|
+
const deleted = this.typeValidators.delete(kind);
|
|
1045
|
+
if (deleted) {
|
|
1046
|
+
this.touch();
|
|
1047
|
+
}
|
|
1048
|
+
return deleted;
|
|
1049
|
+
},
|
|
1050
|
+
Entries: () => Array.from(this.typeValidators.entries()),
|
|
1051
|
+
Get: (kind) => this.typeValidators.get(kind),
|
|
1052
|
+
Has: (kind) => this.typeValidators.has(kind),
|
|
1053
|
+
Set: (kind, validator) => {
|
|
1054
|
+
this.typeValidators.set(kind, validator);
|
|
1055
|
+
this.touch();
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
TypeSystemPolicy = {
|
|
1059
|
+
Get: () => this.typePolicy,
|
|
1060
|
+
Reset: () => {
|
|
1061
|
+
this.typePolicy = { ...defaultTypePolicy };
|
|
1062
|
+
this.touch();
|
|
1063
|
+
},
|
|
1064
|
+
Set: (options) => {
|
|
1065
|
+
this.typePolicy = { ...this.typePolicy, ...options };
|
|
1066
|
+
this.touch();
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
constructor(options = {}) {
|
|
1070
|
+
this.activeLocale = options.locale ?? LocaleCodes.en_US;
|
|
1071
|
+
this.settings = { ...defaultSettings, ...options.settings };
|
|
1072
|
+
this.typePolicy = { ...defaultTypePolicy, ...options.typePolicy };
|
|
1073
|
+
for (const [locale, catalog] of builtinLocaleCatalogEntries) {
|
|
1074
|
+
this.localeCatalogs.set(locale, catalog);
|
|
1075
|
+
}
|
|
1076
|
+
for (const [locale, catalog] of options.localeCatalogs ?? []) {
|
|
1077
|
+
this.localeCatalogs.set(locale, catalog);
|
|
1078
|
+
}
|
|
1079
|
+
for (const [name, validator] of options.formats ?? []) {
|
|
1080
|
+
this.formatValidators.set(name, validator);
|
|
1081
|
+
}
|
|
1082
|
+
for (const [kind, validator] of options.types ?? []) {
|
|
1083
|
+
this.typeValidators.set(kind, validator);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
Clone(options = {}) {
|
|
1087
|
+
return new RuntimeContext({
|
|
1088
|
+
formats: [...cloneEntries(this.formatValidators.entries()), ...options.formats ?? []],
|
|
1089
|
+
locale: options.locale ?? this.activeLocale,
|
|
1090
|
+
localeCatalogs: [...cloneEntries(this.localeCatalogs.entries()), ...options.localeCatalogs ?? []],
|
|
1091
|
+
settings: { ...this.settings, ...options.settings },
|
|
1092
|
+
typePolicy: { ...this.typePolicy, ...options.typePolicy },
|
|
1093
|
+
types: [...cloneEntries(this.typeValidators.entries()), ...options.types ?? []]
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
CacheKey(namespace = "runtime") {
|
|
1097
|
+
return `${namespace}:${this.id}:${this.revision}`;
|
|
1098
|
+
}
|
|
1099
|
+
touch() {
|
|
1100
|
+
this.revision += 1;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
var defaultRuntimeContext = new RuntimeContext;
|
|
1104
|
+
function CreateRuntimeContext(options = {}) {
|
|
1105
|
+
return new RuntimeContext(options);
|
|
1106
|
+
}
|
|
1107
|
+
function getDefaultRuntimeContext() {
|
|
1108
|
+
return defaultRuntimeContext;
|
|
1109
|
+
}
|
|
1110
|
+
function resolveRuntimeContext(context) {
|
|
1111
|
+
if (context instanceof RuntimeContext) {
|
|
1112
|
+
return context;
|
|
1113
|
+
}
|
|
1114
|
+
return context?.context ?? defaultRuntimeContext;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// src/shared/format-validators.ts
|
|
1118
|
+
function luhnCheck(digits) {
|
|
1119
|
+
if (!LUHN_DIGITS_RE.test(digits))
|
|
1120
|
+
return false;
|
|
1121
|
+
let sum = 0;
|
|
1122
|
+
let alternate = false;
|
|
1123
|
+
for (let index = digits.length - 1;index >= 0; index -= 1) {
|
|
1124
|
+
let digit = Number.parseInt(digits.charAt(index), 10);
|
|
1125
|
+
if (alternate) {
|
|
1126
|
+
digit *= 2;
|
|
1127
|
+
if (digit > 9)
|
|
1128
|
+
digit -= 9;
|
|
1129
|
+
}
|
|
1130
|
+
sum += digit;
|
|
1131
|
+
alternate = !alternate;
|
|
1132
|
+
}
|
|
1133
|
+
return sum % 10 === 0;
|
|
1134
|
+
}
|
|
1135
|
+
function isValidISODate(value) {
|
|
1136
|
+
const parts = value.split("-").map(Number);
|
|
1137
|
+
const year = parts[0];
|
|
1138
|
+
const month = parts[1];
|
|
1139
|
+
const day = parts[2];
|
|
1140
|
+
if (year === undefined || month === undefined || day === undefined)
|
|
1141
|
+
return false;
|
|
1142
|
+
const date = new globalThis.Date(year, month - 1, day);
|
|
1143
|
+
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
|
1144
|
+
}
|
|
1145
|
+
function validateFormat(value, format, context) {
|
|
1146
|
+
const runtimeContext = resolveRuntimeContext(context);
|
|
1147
|
+
const custom = runtimeContext.FormatRegistry.Get(format);
|
|
1148
|
+
if (custom !== undefined)
|
|
1149
|
+
return custom(value);
|
|
1150
|
+
switch (format) {
|
|
1151
|
+
case "email":
|
|
1152
|
+
return EMAIL_RE.test(value);
|
|
1153
|
+
case "uri":
|
|
1154
|
+
return URI_RE.test(value);
|
|
1155
|
+
case "ip":
|
|
1156
|
+
return IPV4_RE.test(value) || IPV6_RE.test(value);
|
|
1157
|
+
case "hostname":
|
|
1158
|
+
return HOSTNAME_RE.test(value);
|
|
1159
|
+
case "ipv4":
|
|
1160
|
+
return IPV4_RE.test(value);
|
|
1161
|
+
case "ipv6":
|
|
1162
|
+
return IPV6_RE.test(value);
|
|
1163
|
+
case "uuid":
|
|
1164
|
+
return UUID_RE.test(value);
|
|
1165
|
+
case "date":
|
|
1166
|
+
return ISO_DATE_RE.test(value) && isValidISODate(value);
|
|
1167
|
+
case "datetime":
|
|
1168
|
+
return ISO_DT_RE.test(value);
|
|
1169
|
+
case "time":
|
|
1170
|
+
return ISO_TIME_RE.test(value);
|
|
1171
|
+
case "duration":
|
|
1172
|
+
return ISO_DUR_RE.test(value);
|
|
1173
|
+
case "base64":
|
|
1174
|
+
return BASE64_RE.test(value);
|
|
1175
|
+
case "hex":
|
|
1176
|
+
return HEX_RE.test(value);
|
|
1177
|
+
case "hexcolor":
|
|
1178
|
+
return HEXCLR_RE.test(value);
|
|
1179
|
+
case "creditcard":
|
|
1180
|
+
return luhnCheck(value.replace(/\D/g, ""));
|
|
1181
|
+
case "regex":
|
|
1182
|
+
return isValidRegex(value);
|
|
1183
|
+
case "json":
|
|
1184
|
+
return isValidJson(value);
|
|
1185
|
+
case "uint8array":
|
|
1186
|
+
return BASE64_RE.test(value);
|
|
1187
|
+
default:
|
|
1188
|
+
return true;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function checkStringConstraints(schema, value, context) {
|
|
1192
|
+
if (schema.minLength !== undefined && value.length < schema.minLength)
|
|
1193
|
+
return false;
|
|
1194
|
+
if (schema.maxLength !== undefined && value.length > schema.maxLength)
|
|
1195
|
+
return false;
|
|
1196
|
+
if (schema.pattern !== undefined) {
|
|
1197
|
+
const regex = new RegExp(schema.pattern);
|
|
1198
|
+
if (!regex.test(value))
|
|
1199
|
+
return false;
|
|
1200
|
+
}
|
|
1201
|
+
return schema.format === undefined || validateFormat(value, schema.format, context);
|
|
1202
|
+
}
|
|
1203
|
+
function checkNumberConstraints(schema, value) {
|
|
1204
|
+
if (schema.minimum !== undefined && value < schema.minimum)
|
|
1205
|
+
return false;
|
|
1206
|
+
if (schema.maximum !== undefined && value > schema.maximum)
|
|
1207
|
+
return false;
|
|
1208
|
+
if (schema.exclusiveMinimum !== undefined && value <= schema.exclusiveMinimum)
|
|
1209
|
+
return false;
|
|
1210
|
+
if (schema.exclusiveMaximum !== undefined && value >= schema.exclusiveMaximum)
|
|
1211
|
+
return false;
|
|
1212
|
+
return schema.multipleOf === undefined || value % schema.multipleOf === 0;
|
|
1213
|
+
}
|
|
1214
|
+
// src/shared/registries.ts
|
|
1215
|
+
var FormatRegistry = {
|
|
1216
|
+
Clear() {
|
|
1217
|
+
getDefaultRuntimeContext().FormatRegistry.Clear();
|
|
1218
|
+
},
|
|
1219
|
+
Delete(name) {
|
|
1220
|
+
return getDefaultRuntimeContext().FormatRegistry.Delete(name);
|
|
1221
|
+
},
|
|
1222
|
+
Entries() {
|
|
1223
|
+
return getDefaultRuntimeContext().FormatRegistry.Entries();
|
|
1224
|
+
},
|
|
1225
|
+
Get(name) {
|
|
1226
|
+
return getDefaultRuntimeContext().FormatRegistry.Get(name);
|
|
1227
|
+
},
|
|
1228
|
+
Has(name) {
|
|
1229
|
+
return getDefaultRuntimeContext().FormatRegistry.Has(name);
|
|
1230
|
+
},
|
|
1231
|
+
Set(name, validator) {
|
|
1232
|
+
getDefaultRuntimeContext().FormatRegistry.Set(name, validator);
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
var TypeRegistry = {
|
|
1236
|
+
Clear() {
|
|
1237
|
+
getDefaultRuntimeContext().TypeRegistry.Clear();
|
|
1238
|
+
},
|
|
1239
|
+
Delete(kind) {
|
|
1240
|
+
return getDefaultRuntimeContext().TypeRegistry.Delete(kind);
|
|
1241
|
+
},
|
|
1242
|
+
Entries() {
|
|
1243
|
+
return getDefaultRuntimeContext().TypeRegistry.Entries();
|
|
1244
|
+
},
|
|
1245
|
+
Get(kind) {
|
|
1246
|
+
return getDefaultRuntimeContext().TypeRegistry.Get(kind);
|
|
1247
|
+
},
|
|
1248
|
+
Has(kind) {
|
|
1249
|
+
return getDefaultRuntimeContext().TypeRegistry.Has(kind);
|
|
1250
|
+
},
|
|
1251
|
+
Set(kind, validator) {
|
|
1252
|
+
getDefaultRuntimeContext().TypeRegistry.Set(kind, validator);
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
var TypeSystemPolicy = {
|
|
1256
|
+
Get() {
|
|
1257
|
+
return getDefaultRuntimeContext().TypeSystemPolicy.Get();
|
|
1258
|
+
},
|
|
1259
|
+
Reset() {
|
|
1260
|
+
getDefaultRuntimeContext().TypeSystemPolicy.Reset();
|
|
1261
|
+
},
|
|
1262
|
+
Set(options) {
|
|
1263
|
+
getDefaultRuntimeContext().TypeSystemPolicy.Set(options);
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
var Settings = {
|
|
1267
|
+
Get() {
|
|
1268
|
+
return getDefaultRuntimeContext().Settings.Get();
|
|
1269
|
+
},
|
|
1270
|
+
Reset() {
|
|
1271
|
+
getDefaultRuntimeContext().Settings.Reset();
|
|
1272
|
+
},
|
|
1273
|
+
Set(options) {
|
|
1274
|
+
getDefaultRuntimeContext().Settings.Set(options);
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
// src/shared/schema-access.ts
|
|
1278
|
+
function isRecord(value) {
|
|
1279
|
+
return typeof value === "object" && value !== null;
|
|
1280
|
+
}
|
|
1281
|
+
function isSchemaValue(value) {
|
|
1282
|
+
return isRecord(value) && typeof value["~kind"] === "string";
|
|
1283
|
+
}
|
|
1284
|
+
function schemaNode(schema) {
|
|
1285
|
+
return schema;
|
|
1286
|
+
}
|
|
1287
|
+
function schemaKind(schema) {
|
|
1288
|
+
const kind = schemaNode(schema)["~kind"];
|
|
1289
|
+
return typeof kind === "string" ? kind : undefined;
|
|
1290
|
+
}
|
|
1291
|
+
function schemaUnknownField(schema, field) {
|
|
1292
|
+
return schemaNode(schema)[field];
|
|
1293
|
+
}
|
|
1294
|
+
function schemaStringField(schema, field) {
|
|
1295
|
+
const value = schemaUnknownField(schema, field);
|
|
1296
|
+
return typeof value === "string" ? value : undefined;
|
|
1297
|
+
}
|
|
1298
|
+
function schemaNumberField(schema, field) {
|
|
1299
|
+
const value = schemaUnknownField(schema, field);
|
|
1300
|
+
return typeof value === "number" ? value : undefined;
|
|
1301
|
+
}
|
|
1302
|
+
function schemaBigIntField(schema, field) {
|
|
1303
|
+
const value = schemaUnknownField(schema, field);
|
|
1304
|
+
return typeof value === "bigint" ? value : undefined;
|
|
1305
|
+
}
|
|
1306
|
+
function schemaBooleanField(schema, field) {
|
|
1307
|
+
const value = schemaUnknownField(schema, field);
|
|
1308
|
+
return typeof value === "boolean" ? value : undefined;
|
|
1309
|
+
}
|
|
1310
|
+
function schemaStringListField(schema, field) {
|
|
1311
|
+
const value = schemaUnknownField(schema, field);
|
|
1312
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string") ? value : [];
|
|
1313
|
+
}
|
|
1314
|
+
function schemaSchemaField(schema, field) {
|
|
1315
|
+
const value = schemaUnknownField(schema, field);
|
|
1316
|
+
return isSchemaValue(value) ? value : undefined;
|
|
1317
|
+
}
|
|
1318
|
+
function schemaSchemaListField(schema, field) {
|
|
1319
|
+
const value = schemaUnknownField(schema, field);
|
|
1320
|
+
return Array.isArray(value) && value.every(isSchemaValue) ? value : [];
|
|
1321
|
+
}
|
|
1322
|
+
function schemaSchemaMapField(schema, field) {
|
|
1323
|
+
const value = schemaUnknownField(schema, field);
|
|
1324
|
+
if (!isRecord(value)) {
|
|
1325
|
+
return {};
|
|
1326
|
+
}
|
|
1327
|
+
return Object.values(value).every(isSchemaValue) ? value : {};
|
|
1328
|
+
}
|
|
1329
|
+
function schemaBooleanOrSchemaField(schema, field) {
|
|
1330
|
+
const value = schemaUnknownField(schema, field);
|
|
1331
|
+
if (typeof value === "boolean" || value === undefined) {
|
|
1332
|
+
return value;
|
|
1333
|
+
}
|
|
1334
|
+
return isSchemaValue(value) ? value : undefined;
|
|
1335
|
+
}
|
|
1336
|
+
function schemaCallbackField(schema, field) {
|
|
1337
|
+
const value = schemaUnknownField(schema, field);
|
|
1338
|
+
return typeof value === "function" ? value : undefined;
|
|
1339
|
+
}
|
|
1340
|
+
function schemaItem(schema) {
|
|
1341
|
+
return schemaSchemaField(schema, "item");
|
|
1342
|
+
}
|
|
1343
|
+
function schemaInner(schema) {
|
|
1344
|
+
return schemaSchemaField(schema, "inner");
|
|
1345
|
+
}
|
|
1346
|
+
function schemaItemOrInner(schema) {
|
|
1347
|
+
return schemaItem(schema) ?? schemaInner(schema);
|
|
1348
|
+
}
|
|
1349
|
+
function schemaVariants(schema) {
|
|
1350
|
+
return schemaSchemaListField(schema, "variants");
|
|
1351
|
+
}
|
|
1352
|
+
function schemaProperties(schema) {
|
|
1353
|
+
return schemaSchemaMapField(schema, "properties");
|
|
1354
|
+
}
|
|
1355
|
+
function schemaDefinitions(schema) {
|
|
1356
|
+
return schemaSchemaMapField(schema, "$defs");
|
|
1357
|
+
}
|
|
1358
|
+
function schemaPatternProperties(schema) {
|
|
1359
|
+
return schemaSchemaMapField(schema, "patternProperties");
|
|
1360
|
+
}
|
|
1361
|
+
function schemaRequiredKeys(schema) {
|
|
1362
|
+
return schemaStringListField(schema, "required");
|
|
1363
|
+
}
|
|
1364
|
+
function schemaOptionalKeys(schema) {
|
|
1365
|
+
return schemaStringListField(schema, "optional");
|
|
1366
|
+
}
|
|
1367
|
+
function schemaConst(schema) {
|
|
1368
|
+
return schemaUnknownField(schema, "const");
|
|
1369
|
+
}
|
|
1370
|
+
function schemaPatterns(schema) {
|
|
1371
|
+
return schemaStringListField(schema, "patterns");
|
|
1372
|
+
}
|
|
1373
|
+
function schemaRefinements(schema) {
|
|
1374
|
+
const value = schemaUnknownField(schema, "~refine");
|
|
1375
|
+
return Array.isArray(value) ? value.filter((entry) => isRecord(entry) && typeof entry.refine === "function" && (entry.message === undefined || typeof entry.message === "string")) : [];
|
|
1376
|
+
}
|
|
1377
|
+
function schemaPath(path) {
|
|
1378
|
+
return path.join(".") || "/";
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// src/type/instantiation.ts
|
|
1382
|
+
function getString(value) {
|
|
1383
|
+
return typeof value === "string" ? value : undefined;
|
|
1384
|
+
}
|
|
1385
|
+
function getSchema(value) {
|
|
1386
|
+
if (typeof value !== "object" || value === null) {
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
return typeof value["~kind"] === "string" ? value : undefined;
|
|
1390
|
+
}
|
|
1391
|
+
function getSchemaArray(value) {
|
|
1392
|
+
return Array.isArray(value) ? value.flatMap((entry) => getSchema(entry) ? [entry] : []) : [];
|
|
1393
|
+
}
|
|
1394
|
+
function getParameterSchema(schema) {
|
|
1395
|
+
const value = schema;
|
|
1396
|
+
return {
|
|
1397
|
+
name: getString(value["name"]) ?? "",
|
|
1398
|
+
equals: getSchema(value["equals"]) ?? schema
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
function getInferSchema(schema) {
|
|
1402
|
+
const value = schema;
|
|
1403
|
+
return {
|
|
1404
|
+
name: getString(value["name"]) ?? "",
|
|
1405
|
+
extends: getSchema(value["extends"]) ?? schema
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
function getGenericSchema(schema) {
|
|
1409
|
+
const value = schema;
|
|
1410
|
+
const parameters = Array.isArray(value["parameters"]) ? value["parameters"].flatMap((entry) => {
|
|
1411
|
+
if (typeof entry !== "object" || entry === null)
|
|
1412
|
+
return [];
|
|
1413
|
+
const candidate = entry;
|
|
1414
|
+
return candidate["~kind"] === "Parameter" ? [entry] : [];
|
|
1415
|
+
}) : [];
|
|
1416
|
+
return {
|
|
1417
|
+
parameters,
|
|
1418
|
+
expression: getSchema(value["expression"]) ?? schema
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
function getCallSchema(schema) {
|
|
1422
|
+
const value = schema;
|
|
1423
|
+
return {
|
|
1424
|
+
target: getSchema(value["target"]) ?? schema,
|
|
1425
|
+
arguments: getSchemaArray(value["arguments"])
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
function getCyclicSchema(schema) {
|
|
1429
|
+
const value = schema;
|
|
1430
|
+
const defsSource = value["$defs"];
|
|
1431
|
+
const defs = typeof defsSource === "object" && defsSource !== null ? Object.fromEntries(Object.entries(defsSource).flatMap(([key, entry]) => {
|
|
1432
|
+
const nextSchema = getSchema(entry);
|
|
1433
|
+
return nextSchema ? [[key, nextSchema]] : [];
|
|
1434
|
+
})) : {};
|
|
1435
|
+
return {
|
|
1436
|
+
$defs: defs,
|
|
1437
|
+
$ref: getString(value["$ref"]) ?? ""
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
function bindParameterContext(parameters, arguments_) {
|
|
1441
|
+
const context = {};
|
|
1442
|
+
for (let index = 0;index < parameters.length; index += 1) {
|
|
1443
|
+
const parameter = parameters[index];
|
|
1444
|
+
const name = parameter.name;
|
|
1445
|
+
const argument = arguments_[index] ?? parameter.equals;
|
|
1446
|
+
context[name] = argument;
|
|
1447
|
+
}
|
|
1448
|
+
return context;
|
|
1449
|
+
}
|
|
1450
|
+
function getObjectSchema(schema) {
|
|
1451
|
+
const value = schema;
|
|
1452
|
+
const propertiesSource = value["properties"];
|
|
1453
|
+
const patternPropertiesSource = value["patternProperties"];
|
|
1454
|
+
const requiredSource = value["required"];
|
|
1455
|
+
const optionalSource = value["optional"];
|
|
1456
|
+
return {
|
|
1457
|
+
...schema,
|
|
1458
|
+
"~kind": "Object",
|
|
1459
|
+
properties: typeof propertiesSource === "object" && propertiesSource !== null ? propertiesSource : {},
|
|
1460
|
+
...typeof patternPropertiesSource === "object" && patternPropertiesSource !== null ? { patternProperties: patternPropertiesSource } : {},
|
|
1461
|
+
...Array.isArray(requiredSource) ? { required: requiredSource.filter((entry) => typeof entry === "string") } : {},
|
|
1462
|
+
...Array.isArray(optionalSource) ? { optional: optionalSource.filter((entry) => typeof entry === "string") } : {}
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
function instantiateObject(context, schema) {
|
|
1466
|
+
const objectSchema = getObjectSchema(schema);
|
|
1467
|
+
const properties = {};
|
|
1468
|
+
for (const [key, value] of Object.entries(objectSchema.properties)) {
|
|
1469
|
+
properties[key] = Instantiate(context, value);
|
|
1470
|
+
}
|
|
1471
|
+
const patternProperties = objectSchema.patternProperties === undefined ? undefined : Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => [key, Instantiate(context, value)]));
|
|
1472
|
+
return {
|
|
1473
|
+
...objectSchema,
|
|
1474
|
+
properties,
|
|
1475
|
+
...patternProperties !== undefined ? { patternProperties } : {},
|
|
1476
|
+
...typeof objectSchema.additionalProperties === "object" && objectSchema.additionalProperties !== null ? { additionalProperties: Instantiate(context, objectSchema.additionalProperties) } : {}
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
function Instantiate(context, schema) {
|
|
1480
|
+
const value = schema;
|
|
1481
|
+
const kind = value["~kind"];
|
|
1482
|
+
switch (kind) {
|
|
1483
|
+
case "Parameter": {
|
|
1484
|
+
const parameter = getParameterSchema(schema);
|
|
1485
|
+
return context[parameter.name] ?? parameter.equals;
|
|
1486
|
+
}
|
|
1487
|
+
case "Infer": {
|
|
1488
|
+
const infer = getInferSchema(schema);
|
|
1489
|
+
return context[infer.name] ?? infer.extends;
|
|
1490
|
+
}
|
|
1491
|
+
case "This":
|
|
1492
|
+
return schema;
|
|
1493
|
+
case "Ref": {
|
|
1494
|
+
const name = value["name"];
|
|
1495
|
+
return typeof name === "string" && context[name] !== undefined ? context[name] : schema;
|
|
1496
|
+
}
|
|
1497
|
+
case "Array":
|
|
1498
|
+
return { ...schema, items: Instantiate(context, value["items"]) };
|
|
1499
|
+
case "Object":
|
|
1500
|
+
return instantiateObject(context, schema);
|
|
1501
|
+
case "Tuple":
|
|
1502
|
+
return { ...schema, items: value["items"].map((item) => Instantiate(context, item)) };
|
|
1503
|
+
case "Record":
|
|
1504
|
+
return {
|
|
1505
|
+
...schema,
|
|
1506
|
+
key: Instantiate(context, value["key"]),
|
|
1507
|
+
value: Instantiate(context, value["value"])
|
|
1508
|
+
};
|
|
1509
|
+
case "Union":
|
|
1510
|
+
case "Intersect":
|
|
1511
|
+
return { ...schema, variants: value["variants"].map((item) => Instantiate(context, item)) };
|
|
1512
|
+
case "Optional":
|
|
1513
|
+
case "Readonly":
|
|
1514
|
+
case "Capitalize":
|
|
1515
|
+
case "Lowercase":
|
|
1516
|
+
case "Uppercase":
|
|
1517
|
+
case "Uncapitalize":
|
|
1518
|
+
case "Awaited":
|
|
1519
|
+
return { ...schema, item: Instantiate(context, value["item"]) };
|
|
1520
|
+
case "Immutable":
|
|
1521
|
+
case "Refine":
|
|
1522
|
+
return { ...schema, item: Instantiate(context, value["item"]) };
|
|
1523
|
+
case "Codec":
|
|
1524
|
+
return { ...schema, inner: Instantiate(context, value["inner"]) };
|
|
1525
|
+
case "Exclude":
|
|
1526
|
+
case "Extract":
|
|
1527
|
+
return {
|
|
1528
|
+
...schema,
|
|
1529
|
+
left: Instantiate(context, value["left"]),
|
|
1530
|
+
right: Instantiate(context, value["right"])
|
|
1531
|
+
};
|
|
1532
|
+
case "Not":
|
|
1533
|
+
return { ...schema, schema: Instantiate(context, value["schema"]) };
|
|
1534
|
+
case "IfThenElse":
|
|
1535
|
+
return {
|
|
1536
|
+
...schema,
|
|
1537
|
+
if: Instantiate(context, value["if"]),
|
|
1538
|
+
then: Instantiate(context, value["then"]),
|
|
1539
|
+
else: Instantiate(context, value["else"])
|
|
1540
|
+
};
|
|
1541
|
+
case "Index":
|
|
1542
|
+
return {
|
|
1543
|
+
...schema,
|
|
1544
|
+
object: Instantiate(context, value["object"]),
|
|
1545
|
+
key: Instantiate(context, value["key"])
|
|
1546
|
+
};
|
|
1547
|
+
case "Mapped":
|
|
1548
|
+
return { ...schema, object: Instantiate(context, value["object"]) };
|
|
1549
|
+
case "Conditional":
|
|
1550
|
+
return {
|
|
1551
|
+
...schema,
|
|
1552
|
+
check: Instantiate(context, value["check"]),
|
|
1553
|
+
union: value["union"].map((item) => Instantiate(context, item)),
|
|
1554
|
+
...value["default"] !== undefined ? { default: Instantiate(context, value["default"]) } : {}
|
|
1555
|
+
};
|
|
1556
|
+
case "Function":
|
|
1557
|
+
case "Constructor":
|
|
1558
|
+
return {
|
|
1559
|
+
...schema,
|
|
1560
|
+
parameters: value["parameters"].map((item) => Instantiate(context, item)),
|
|
1561
|
+
returns: Instantiate(context, value["returns"])
|
|
1562
|
+
};
|
|
1563
|
+
case "Promise":
|
|
1564
|
+
case "Iterator":
|
|
1565
|
+
case "AsyncIterator":
|
|
1566
|
+
case "Rest":
|
|
1567
|
+
return { ...schema, item: Instantiate(context, value["item"]), items: Instantiate(context, value["items"] ?? value["item"]) };
|
|
1568
|
+
case "Decode":
|
|
1569
|
+
return { ...schema, inner: Instantiate(context, value["inner"]) };
|
|
1570
|
+
case "Encode":
|
|
1571
|
+
return { ...schema, inner: Instantiate(context, value["inner"]) };
|
|
1572
|
+
case "ReturnType":
|
|
1573
|
+
case "Parameters":
|
|
1574
|
+
return { ...schema, function: Instantiate(context, value["function"]) };
|
|
1575
|
+
case "InstanceType":
|
|
1576
|
+
case "ConstructorParameters":
|
|
1577
|
+
return { ...schema, constructor: Instantiate(context, value["constructor"]) };
|
|
1578
|
+
case "Generic": {
|
|
1579
|
+
const generic = getGenericSchema(schema);
|
|
1580
|
+
return {
|
|
1581
|
+
...generic,
|
|
1582
|
+
parameters: generic.parameters,
|
|
1583
|
+
expression: Instantiate(context, generic.expression)
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
case "Call": {
|
|
1587
|
+
const call = getCallSchema(schema);
|
|
1588
|
+
const target = Instantiate(context, call.target);
|
|
1589
|
+
const arguments_ = call.arguments.map((item) => Instantiate(context, item));
|
|
1590
|
+
const targetValue = target;
|
|
1591
|
+
if (targetValue["~kind"] === "Generic") {
|
|
1592
|
+
const generic = getGenericSchema(target);
|
|
1593
|
+
const nextContext = bindParameterContext(generic.parameters, arguments_);
|
|
1594
|
+
return Instantiate({ ...context, ...nextContext }, generic.expression);
|
|
1595
|
+
}
|
|
1596
|
+
return {
|
|
1597
|
+
"~kind": "Call",
|
|
1598
|
+
target,
|
|
1599
|
+
arguments: arguments_
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
case "Cyclic": {
|
|
1603
|
+
const cyclic = getCyclicSchema(schema);
|
|
1604
|
+
const defs = Object.fromEntries(Object.entries(cyclic.$defs).map(([key, value2]) => [key, Instantiate(context, value2)]));
|
|
1605
|
+
return {
|
|
1606
|
+
...cyclic,
|
|
1607
|
+
$defs: defs
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
default:
|
|
1611
|
+
return schema;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// src/shared/bytes.ts
|
|
1616
|
+
import { dlopen, ptr } from "bun:ffi";
|
|
1617
|
+
var libcPath = process.platform === "darwin" ? "/usr/lib/libSystem.B.dylib" : process.platform === "linux" ? "libc.so.6" : process.platform === "win32" ? "msvcrt.dll" : "";
|
|
1618
|
+
var memcmp = libcPath === "" ? undefined : dlopen(libcPath, {
|
|
1619
|
+
memcmp: {
|
|
1620
|
+
args: ["ptr", "ptr", "usize"],
|
|
1621
|
+
returns: "i32"
|
|
1622
|
+
}
|
|
1623
|
+
}).symbols.memcmp;
|
|
1624
|
+
function encodeUint8ArrayBase64(value) {
|
|
1625
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64");
|
|
1626
|
+
}
|
|
1627
|
+
function decodeUint8ArrayBase64(value) {
|
|
1628
|
+
const bunWithBase64 = Bun;
|
|
1629
|
+
if (typeof bunWithBase64.base64ToBytes === "function") {
|
|
1630
|
+
return bunWithBase64.base64ToBytes(value);
|
|
1631
|
+
}
|
|
1632
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
1633
|
+
}
|
|
1634
|
+
function getBase64DecodedByteLength(value) {
|
|
1635
|
+
const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
|
|
1636
|
+
return value.length / 4 * 3 - padding;
|
|
1637
|
+
}
|
|
1638
|
+
function areUint8ArraysEqual(left, right) {
|
|
1639
|
+
if (left.byteLength !== right.byteLength) {
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
if (left.byteLength === 0) {
|
|
1643
|
+
return true;
|
|
1644
|
+
}
|
|
1645
|
+
if (memcmp !== undefined) {
|
|
1646
|
+
return memcmp(ptr(left), ptr(right), left.byteLength) === 0;
|
|
1647
|
+
}
|
|
1648
|
+
for (let index = 0;index < left.length; index += 1) {
|
|
1649
|
+
if (left[index] !== right[index]) {
|
|
1650
|
+
return false;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
return true;
|
|
1654
|
+
}
|
|
1655
|
+
function isUint8ArrayWithinBounds(value, minByteLength, maxByteLength) {
|
|
1656
|
+
if (minByteLength !== undefined && value.byteLength < minByteLength)
|
|
1657
|
+
return false;
|
|
1658
|
+
return maxByteLength === undefined || value.byteLength <= maxByteLength;
|
|
1659
|
+
}
|
|
1660
|
+
function isUint8ArrayBase64String(value, minByteLength, maxByteLength, constBytes, constBase64) {
|
|
1661
|
+
if (typeof value !== "string" || !validateFormat(value, "base64")) {
|
|
1662
|
+
return false;
|
|
1663
|
+
}
|
|
1664
|
+
if (!isUint8ArrayWithinBounds({ byteLength: getBase64DecodedByteLength(value) }, minByteLength, maxByteLength)) {
|
|
1665
|
+
return false;
|
|
1666
|
+
}
|
|
1667
|
+
return constBytes === undefined ? true : value === (constBase64 ?? encodeUint8ArrayBase64(constBytes));
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// src/value/check-collections-derived.ts
|
|
1671
|
+
function checkReferenceCollection(kind, schema, value, refs, check) {
|
|
1672
|
+
switch (kind) {
|
|
1673
|
+
case "Union":
|
|
1674
|
+
return schemaVariants(schema).some((variant) => check(variant, value, refs));
|
|
1675
|
+
case "Intersect":
|
|
1676
|
+
return schemaVariants(schema).every((variant) => check(variant, value, refs));
|
|
1677
|
+
case "Optional": {
|
|
1678
|
+
const itemSchema = schemaItem(schema);
|
|
1679
|
+
return value === undefined || (itemSchema ? check(itemSchema, value, refs) : false);
|
|
1680
|
+
}
|
|
1681
|
+
case "Readonly":
|
|
1682
|
+
case "Immutable":
|
|
1683
|
+
case "Codec": {
|
|
1684
|
+
const inner = schemaItemOrInner(schema);
|
|
1685
|
+
return inner ? check(inner, value, refs) : false;
|
|
1686
|
+
}
|
|
1687
|
+
case "Ref": {
|
|
1688
|
+
const target = refs.get(schemaStringField(schema, "name") ?? "");
|
|
1689
|
+
return target ? check(target, value, refs) : false;
|
|
1690
|
+
}
|
|
1691
|
+
case "Recursive": {
|
|
1692
|
+
const name = schemaStringField(schema, "name");
|
|
1693
|
+
const target = schemaSchemaField(schema, "schema");
|
|
1694
|
+
if (!name || target === undefined)
|
|
1695
|
+
return false;
|
|
1696
|
+
const nextRefs = new Map(refs);
|
|
1697
|
+
nextRefs.set(name, target);
|
|
1698
|
+
nextRefs.set("#", target);
|
|
1699
|
+
return check(target, value, nextRefs);
|
|
1700
|
+
}
|
|
1701
|
+
case "Cyclic": {
|
|
1702
|
+
const defs = schemaDefinitions(schema);
|
|
1703
|
+
const refName = schemaStringField(schema, "$ref");
|
|
1704
|
+
const nextRefs = new Map(refs);
|
|
1705
|
+
for (const [name, definition] of Object.entries(defs)) {
|
|
1706
|
+
nextRefs.set(name, definition);
|
|
1707
|
+
}
|
|
1708
|
+
const target = refName ? defs[refName] : undefined;
|
|
1709
|
+
return target ? check(target, value, nextRefs) : false;
|
|
1710
|
+
}
|
|
1711
|
+
case "Exclude": {
|
|
1712
|
+
const left = schemaSchemaField(schema, "left");
|
|
1713
|
+
const right = schemaSchemaField(schema, "right");
|
|
1714
|
+
return left !== undefined && right !== undefined ? check(left, value, refs) && !check(right, value, refs) : false;
|
|
1715
|
+
}
|
|
1716
|
+
case "Extract": {
|
|
1717
|
+
const left = schemaSchemaField(schema, "left");
|
|
1718
|
+
const right = schemaSchemaField(schema, "right");
|
|
1719
|
+
return left !== undefined && right !== undefined ? check(left, value, refs) && check(right, value, refs) : false;
|
|
1720
|
+
}
|
|
1721
|
+
default:
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
function checkDerivedCollection(kind, schema, value, refs, check) {
|
|
1726
|
+
switch (kind) {
|
|
1727
|
+
case "Partial": {
|
|
1728
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1729
|
+
return objectSchema ? check(deriveObjectSchema(objectSchema, { requiredMode: "none" }), value, refs) : false;
|
|
1730
|
+
}
|
|
1731
|
+
case "Required": {
|
|
1732
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1733
|
+
return objectSchema ? check(deriveObjectSchema(objectSchema, { requiredMode: "all" }), value, refs) : false;
|
|
1734
|
+
}
|
|
1735
|
+
case "KeyOf": {
|
|
1736
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1737
|
+
return objectSchema ? typeof value === "string" && Object.keys(schemaProperties(objectSchema)).includes(value) : false;
|
|
1738
|
+
}
|
|
1739
|
+
case "Pick": {
|
|
1740
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1741
|
+
const keys = schemaUnknownField(schema, "keys");
|
|
1742
|
+
return objectSchema && Array.isArray(keys) ? check(deriveObjectSchema(objectSchema, { pickKeys: keys.map(String), additionalProperties: false }), value, refs) : false;
|
|
1743
|
+
}
|
|
1744
|
+
case "Omit": {
|
|
1745
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1746
|
+
const keys = schemaUnknownField(schema, "keys");
|
|
1747
|
+
return objectSchema && Array.isArray(keys) ? check(deriveObjectSchema(objectSchema, { omitKeys: keys.map(String), additionalProperties: false }), value, refs) : false;
|
|
1748
|
+
}
|
|
1749
|
+
case "Not": {
|
|
1750
|
+
const target = schemaSchemaField(schema, "schema");
|
|
1751
|
+
return target ? !check(target, value, refs) : false;
|
|
1752
|
+
}
|
|
1753
|
+
case "IfThenElse": {
|
|
1754
|
+
const checkSchema = schemaSchemaField(schema, "if");
|
|
1755
|
+
const thenSchema = schemaSchemaField(schema, "then");
|
|
1756
|
+
const elseSchema = schemaSchemaField(schema, "else");
|
|
1757
|
+
if (checkSchema === undefined || thenSchema === undefined || elseSchema === undefined)
|
|
1758
|
+
return false;
|
|
1759
|
+
return check(checkSchema, value, refs) ? check(thenSchema, value, refs) : check(elseSchema, value, refs);
|
|
1760
|
+
}
|
|
1761
|
+
case "Index": {
|
|
1762
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1763
|
+
const keySchema = schemaSchemaField(schema, "key");
|
|
1764
|
+
if (objectSchema === undefined || keySchema === undefined)
|
|
1765
|
+
return false;
|
|
1766
|
+
const candidates = deriveIndexSchemas(objectSchema, keySchema, (candidate, candidateValue) => check(candidate, candidateValue, new Map));
|
|
1767
|
+
return candidates.length > 0 && candidates.some((candidate) => check(candidate, value, refs));
|
|
1768
|
+
}
|
|
1769
|
+
case "Mapped": {
|
|
1770
|
+
const objectSchema = schemaSchemaField(schema, "object");
|
|
1771
|
+
if (objectSchema === undefined)
|
|
1772
|
+
return false;
|
|
1773
|
+
const transform = schemaCallbackField(schema, "transform");
|
|
1774
|
+
if (!transform) {
|
|
1775
|
+
return check(objectSchema, value, refs);
|
|
1776
|
+
}
|
|
1777
|
+
const transformed = {};
|
|
1778
|
+
for (const [key, propertySchema] of Object.entries(schemaProperties(objectSchema))) {
|
|
1779
|
+
transformed[key] = transform(propertySchema, key);
|
|
1780
|
+
}
|
|
1781
|
+
return check({ ...objectSchema, properties: transformed }, value, refs);
|
|
1782
|
+
}
|
|
1783
|
+
case "Conditional": {
|
|
1784
|
+
const checkSchema = schemaSchemaField(schema, "check");
|
|
1785
|
+
const union = schemaSchemaListField(schema, "union");
|
|
1786
|
+
const defaultSchema = schemaSchemaField(schema, "default");
|
|
1787
|
+
if (checkSchema === undefined)
|
|
1788
|
+
return false;
|
|
1789
|
+
if (check(checkSchema, value, refs)) {
|
|
1790
|
+
return union.some((candidate) => check(candidate, value, refs));
|
|
1791
|
+
}
|
|
1792
|
+
return defaultSchema !== undefined ? check(defaultSchema, value, refs) : true;
|
|
1793
|
+
}
|
|
1794
|
+
case "Rest": {
|
|
1795
|
+
const items = schemaSchemaField(schema, "items");
|
|
1796
|
+
return Array.isArray(value) && items !== undefined && value.every((item) => check(items, item, refs));
|
|
1797
|
+
}
|
|
1798
|
+
case "Refine": {
|
|
1799
|
+
if (schemaUnknownField(schema, "~uint8arrayCodec") === true) {
|
|
1800
|
+
const constBytes = schemaUnknownField(schema, "constBytes");
|
|
1801
|
+
return isUint8ArrayBase64String(value, schemaNumberField(schema, "minByteLength"), schemaNumberField(schema, "maxByteLength"), constBytes instanceof Uint8Array ? constBytes : undefined, schemaStringField(schema, "constBase64"));
|
|
1802
|
+
}
|
|
1803
|
+
const itemSchema = schemaItem(schema);
|
|
1804
|
+
return itemSchema !== undefined && check(itemSchema, value, refs) && schemaRefinements(schema).every((entry) => entry.refine(value));
|
|
1805
|
+
}
|
|
1806
|
+
default:
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
// src/value/check-collections.ts
|
|
1812
|
+
function isRecord2(value) {
|
|
1813
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1814
|
+
}
|
|
1815
|
+
function checkArrayCollection(schema, value, refs, check) {
|
|
1816
|
+
if (!Array.isArray(value))
|
|
1817
|
+
return false;
|
|
1818
|
+
const itemSchema = schemaSchemaField(schema, "items");
|
|
1819
|
+
const minItems = schemaNumberField(schema, "minItems");
|
|
1820
|
+
const maxItems = schemaNumberField(schema, "maxItems");
|
|
1821
|
+
const uniqueItems = schemaBooleanField(schema, "uniqueItems");
|
|
1822
|
+
const containsSchema = schemaSchemaField(schema, "contains");
|
|
1823
|
+
const minContains = schemaNumberField(schema, "minContains");
|
|
1824
|
+
const maxContains = schemaNumberField(schema, "maxContains");
|
|
1825
|
+
if (minItems !== undefined && value.length < minItems)
|
|
1826
|
+
return false;
|
|
1827
|
+
if (maxItems !== undefined && value.length > maxItems)
|
|
1828
|
+
return false;
|
|
1829
|
+
if (uniqueItems && new Set(value).size !== value.length)
|
|
1830
|
+
return false;
|
|
1831
|
+
if (containsSchema !== undefined) {
|
|
1832
|
+
let containsCount = 0;
|
|
1833
|
+
for (const item of value) {
|
|
1834
|
+
if (check(containsSchema, item, refs))
|
|
1835
|
+
containsCount += 1;
|
|
1836
|
+
}
|
|
1837
|
+
if (containsCount === 0)
|
|
1838
|
+
return false;
|
|
1839
|
+
if (minContains !== undefined && containsCount < minContains)
|
|
1840
|
+
return false;
|
|
1841
|
+
if (maxContains !== undefined && containsCount > maxContains)
|
|
1842
|
+
return false;
|
|
1843
|
+
}
|
|
1844
|
+
return itemSchema ? value.every((item) => check(itemSchema, item, refs)) : false;
|
|
1845
|
+
}
|
|
1846
|
+
function checkObjectCollection(schema, value, refs, check) {
|
|
1847
|
+
if (!isRecord2(value))
|
|
1848
|
+
return false;
|
|
1849
|
+
const properties = schemaProperties(schema);
|
|
1850
|
+
const required = schemaRequiredKeys(schema);
|
|
1851
|
+
const optional = new Set(schemaOptionalKeys(schema));
|
|
1852
|
+
const patternProperties = schemaPatternProperties(schema);
|
|
1853
|
+
const additionalProperties = schemaBooleanOrSchemaField(schema, "additionalProperties");
|
|
1854
|
+
for (const key of required) {
|
|
1855
|
+
if (!(key in value))
|
|
1856
|
+
return false;
|
|
1857
|
+
const propertySchema = properties[key];
|
|
1858
|
+
if (propertySchema === undefined || !check(propertySchema, value[key], refs))
|
|
1859
|
+
return false;
|
|
1860
|
+
}
|
|
1861
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
1862
|
+
const propertySchema = properties[key];
|
|
1863
|
+
const matchedPatterns = getPatternPropertySchemas(patternProperties, key);
|
|
1864
|
+
if (propertySchema !== undefined) {
|
|
1865
|
+
if (entryValue === undefined && optional.has(key))
|
|
1866
|
+
continue;
|
|
1867
|
+
if (!check(propertySchema, entryValue, refs))
|
|
1868
|
+
return false;
|
|
1869
|
+
}
|
|
1870
|
+
if (matchedPatterns.length > 0) {
|
|
1871
|
+
if (!matchedPatterns.every((patternSchema) => check(patternSchema, entryValue, refs)))
|
|
1872
|
+
return false;
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
if (propertySchema === undefined && additionalProperties === false)
|
|
1876
|
+
return false;
|
|
1877
|
+
if (propertySchema === undefined && typeof additionalProperties === "object") {
|
|
1878
|
+
if (!check(additionalProperties, entryValue, refs))
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return true;
|
|
1883
|
+
}
|
|
1884
|
+
function checkTupleCollection(schema, value, refs, check) {
|
|
1885
|
+
if (!Array.isArray(value))
|
|
1886
|
+
return false;
|
|
1887
|
+
const items = schemaSchemaListField(schema, "items");
|
|
1888
|
+
const minItems = schemaNumberField(schema, "minItems");
|
|
1889
|
+
const maxItems = schemaNumberField(schema, "maxItems");
|
|
1890
|
+
const additionalItems = schemaBooleanField(schema, "additionalItems");
|
|
1891
|
+
if (minItems !== undefined && value.length < minItems)
|
|
1892
|
+
return false;
|
|
1893
|
+
if (maxItems !== undefined && value.length > maxItems)
|
|
1894
|
+
return false;
|
|
1895
|
+
if (value.length > items.length && additionalItems !== true)
|
|
1896
|
+
return false;
|
|
1897
|
+
return value.every((item, index) => {
|
|
1898
|
+
const itemSchema = items[index];
|
|
1899
|
+
return itemSchema ? check(itemSchema, item, refs) : true;
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
function checkRecordCollection(schema, value, refs, check) {
|
|
1903
|
+
if (!isRecord2(value))
|
|
1904
|
+
return false;
|
|
1905
|
+
const keySchema = schemaSchemaField(schema, "key");
|
|
1906
|
+
const valueSchema = schemaSchemaField(schema, "value");
|
|
1907
|
+
const entries = Object.entries(value);
|
|
1908
|
+
const minProperties = schemaNumberField(schema, "minProperties");
|
|
1909
|
+
const maxProperties = schemaNumberField(schema, "maxProperties");
|
|
1910
|
+
if (keySchema === undefined || valueSchema === undefined)
|
|
1911
|
+
return false;
|
|
1912
|
+
if (minProperties !== undefined && entries.length < minProperties)
|
|
1913
|
+
return false;
|
|
1914
|
+
if (maxProperties !== undefined && entries.length > maxProperties)
|
|
1915
|
+
return false;
|
|
1916
|
+
return entries.every(([entryKey, entryValue]) => check(keySchema, entryKey, refs) && check(valueSchema, entryValue, refs));
|
|
1917
|
+
}
|
|
1918
|
+
function checkCollectionKind(kind, schema, value, refs, check) {
|
|
1919
|
+
switch (kind) {
|
|
1920
|
+
case "Array":
|
|
1921
|
+
return checkArrayCollection(schema, value, refs, check);
|
|
1922
|
+
case "Object":
|
|
1923
|
+
return checkObjectCollection(schema, value, refs, check);
|
|
1924
|
+
case "Tuple":
|
|
1925
|
+
return checkTupleCollection(schema, value, refs, check);
|
|
1926
|
+
case "Record":
|
|
1927
|
+
return checkRecordCollection(schema, value, refs, check);
|
|
1928
|
+
default:
|
|
1929
|
+
return checkReferenceCollection(kind, schema, value, refs, check) ?? checkDerivedCollection(kind, schema, value, refs, check);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// src/value/check-extensions.ts
|
|
1934
|
+
function checkExtensionKind(kind, schema, value, refs, check) {
|
|
1935
|
+
switch (kind) {
|
|
1936
|
+
case "Capitalize":
|
|
1937
|
+
case "Lowercase":
|
|
1938
|
+
case "Uppercase":
|
|
1939
|
+
case "Uncapitalize":
|
|
1940
|
+
return check(resolveStringActionSchema(schema), value, refs);
|
|
1941
|
+
case "Parameter":
|
|
1942
|
+
return check(schema.equals, value, refs);
|
|
1943
|
+
case "This": {
|
|
1944
|
+
const target = refs.get("#");
|
|
1945
|
+
return target ? check(target, value, refs) : false;
|
|
1946
|
+
}
|
|
1947
|
+
case "Generic":
|
|
1948
|
+
return check(schema.expression, value, refs);
|
|
1949
|
+
case "Call": {
|
|
1950
|
+
const instantiated = Instantiate({}, schema);
|
|
1951
|
+
return instantiated === schema ? false : check(instantiated, value, refs);
|
|
1952
|
+
}
|
|
1953
|
+
case "Infer":
|
|
1954
|
+
return check(schema.extends, value, refs);
|
|
1955
|
+
case "Decode":
|
|
1956
|
+
case "Encode":
|
|
1957
|
+
return check(schema.inner, value, refs);
|
|
1958
|
+
case "Awaited": {
|
|
1959
|
+
const current = schema;
|
|
1960
|
+
return check(current.promise.item, value, refs);
|
|
1961
|
+
}
|
|
1962
|
+
case "ReturnType": {
|
|
1963
|
+
const current = schema;
|
|
1964
|
+
return check(current.function.returns, value, refs);
|
|
1965
|
+
}
|
|
1966
|
+
case "Parameters": {
|
|
1967
|
+
const current = schema;
|
|
1968
|
+
if (!Array.isArray(value) || value.length !== current.function.parameters.length)
|
|
1969
|
+
return false;
|
|
1970
|
+
return value.every((item, index) => {
|
|
1971
|
+
const parameterSchema = current.function.parameters[index];
|
|
1972
|
+
return parameterSchema ? check(parameterSchema, item, refs) : false;
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
case "InstanceType": {
|
|
1976
|
+
const current = schema;
|
|
1977
|
+
return check(current.constructor.returns, value, refs);
|
|
1978
|
+
}
|
|
1979
|
+
case "ConstructorParameters": {
|
|
1980
|
+
const current = schema;
|
|
1981
|
+
if (!Array.isArray(value) || value.length !== current.constructor.parameters.length)
|
|
1982
|
+
return false;
|
|
1983
|
+
return value.every((item, index) => {
|
|
1984
|
+
const parameterSchema = current.constructor.parameters[index];
|
|
1985
|
+
return parameterSchema ? check(parameterSchema, item, refs) : false;
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
default:
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
// src/value/check-primitives.ts
|
|
1994
|
+
function checkBigIntConstraints(schema, value) {
|
|
1995
|
+
const minimum = schemaBigIntField(schema, "minimum");
|
|
1996
|
+
const maximum = schemaBigIntField(schema, "maximum");
|
|
1997
|
+
const exclusiveMinimum = schemaBigIntField(schema, "exclusiveMinimum");
|
|
1998
|
+
const exclusiveMaximum = schemaBigIntField(schema, "exclusiveMaximum");
|
|
1999
|
+
const multipleOf = schemaBigIntField(schema, "multipleOf");
|
|
2000
|
+
if (minimum !== undefined && value < minimum)
|
|
2001
|
+
return false;
|
|
2002
|
+
if (maximum !== undefined && value > maximum)
|
|
2003
|
+
return false;
|
|
2004
|
+
if (exclusiveMinimum !== undefined && value <= exclusiveMinimum)
|
|
2005
|
+
return false;
|
|
2006
|
+
if (exclusiveMaximum !== undefined && value >= exclusiveMaximum)
|
|
2007
|
+
return false;
|
|
2008
|
+
if (multipleOf !== undefined && value % multipleOf !== 0n)
|
|
2009
|
+
return false;
|
|
2010
|
+
return true;
|
|
2011
|
+
}
|
|
2012
|
+
function checkDateConstraints(schema, value) {
|
|
2013
|
+
if (Number.isNaN(value.getTime()))
|
|
2014
|
+
return false;
|
|
2015
|
+
const minimum = schemaNumberField(schema, "minimumTimestamp");
|
|
2016
|
+
const maximum = schemaNumberField(schema, "maximumTimestamp");
|
|
2017
|
+
const exclusiveMinimum = schemaNumberField(schema, "exclusiveMinimumTimestamp");
|
|
2018
|
+
const exclusiveMaximum = schemaNumberField(schema, "exclusiveMaximumTimestamp");
|
|
2019
|
+
const timestamp = value.getTime();
|
|
2020
|
+
if (minimum !== undefined && timestamp < minimum)
|
|
2021
|
+
return false;
|
|
2022
|
+
if (maximum !== undefined && timestamp > maximum)
|
|
2023
|
+
return false;
|
|
2024
|
+
if (exclusiveMinimum !== undefined && timestamp <= exclusiveMinimum)
|
|
2025
|
+
return false;
|
|
2026
|
+
if (exclusiveMaximum !== undefined && timestamp >= exclusiveMaximum)
|
|
2027
|
+
return false;
|
|
2028
|
+
return true;
|
|
2029
|
+
}
|
|
2030
|
+
function checkUint8ArrayConstraints(schema, value) {
|
|
2031
|
+
const minByteLength = schemaNumberField(schema, "minByteLength");
|
|
2032
|
+
const maxByteLength = schemaNumberField(schema, "maxByteLength");
|
|
2033
|
+
const constBytes = schemaConst(schema);
|
|
2034
|
+
const expectedBytes = constBytes instanceof Uint8Array ? constBytes : undefined;
|
|
2035
|
+
if (!isUint8ArrayWithinBounds(value, minByteLength, maxByteLength))
|
|
2036
|
+
return false;
|
|
2037
|
+
return expectedBytes === undefined || areUint8ArraysEqual(value, expectedBytes);
|
|
2038
|
+
}
|
|
2039
|
+
function checkPrimitiveKind(kind, schema, value, context) {
|
|
2040
|
+
const runtimeContext = resolveRuntimeContext(context);
|
|
2041
|
+
switch (kind) {
|
|
2042
|
+
case "String":
|
|
2043
|
+
return typeof value === "string" && checkStringConstraints(schema, value, runtimeContext);
|
|
2044
|
+
case "Number": {
|
|
2045
|
+
const policy = runtimeContext.TypeSystemPolicy.Get();
|
|
2046
|
+
return typeof value === "number" && (policy.AllowNaN || Number.isFinite(value)) && checkNumberConstraints(schema, value);
|
|
2047
|
+
}
|
|
2048
|
+
case "Integer":
|
|
2049
|
+
return typeof value === "number" && Number.isInteger(value) && checkNumberConstraints(schema, value);
|
|
2050
|
+
case "Boolean":
|
|
2051
|
+
return typeof value === "boolean";
|
|
2052
|
+
case "Null":
|
|
2053
|
+
return value === null;
|
|
2054
|
+
case "Literal":
|
|
2055
|
+
return value === schemaConst(schema);
|
|
2056
|
+
case "BigInt": {
|
|
2057
|
+
if (typeof value !== "bigint")
|
|
2058
|
+
return false;
|
|
2059
|
+
return checkBigIntConstraints(schema, value);
|
|
2060
|
+
}
|
|
2061
|
+
case "Date": {
|
|
2062
|
+
if (!(value instanceof globalThis.Date))
|
|
2063
|
+
return false;
|
|
2064
|
+
return checkDateConstraints(schema, value);
|
|
2065
|
+
}
|
|
2066
|
+
case "Void":
|
|
2067
|
+
return value === undefined || value === null;
|
|
2068
|
+
case "Undefined":
|
|
2069
|
+
return value === undefined;
|
|
2070
|
+
case "Unknown":
|
|
2071
|
+
case "Any":
|
|
2072
|
+
case "Unsafe":
|
|
2073
|
+
return true;
|
|
2074
|
+
case "Never":
|
|
2075
|
+
return false;
|
|
2076
|
+
case "Enum":
|
|
2077
|
+
return schemaStringListField(schema, "values").includes(String(value));
|
|
2078
|
+
case "Identifier":
|
|
2079
|
+
return typeof value === "string" && /^[$A-Z_a-z][$\w]*$/.test(value);
|
|
2080
|
+
case "TemplateLiteral": {
|
|
2081
|
+
if (typeof value !== "string")
|
|
2082
|
+
return false;
|
|
2083
|
+
return new RegExp(schemaPatterns(schema).join("|")).test(value);
|
|
2084
|
+
}
|
|
2085
|
+
case "Uint8Array": {
|
|
2086
|
+
if (!(value instanceof globalThis.Uint8Array))
|
|
2087
|
+
return false;
|
|
2088
|
+
return checkUint8ArrayConstraints(schema, value);
|
|
2089
|
+
}
|
|
2090
|
+
case "RegExpInstance":
|
|
2091
|
+
return value instanceof globalThis.RegExp;
|
|
2092
|
+
case "Promise":
|
|
2093
|
+
return isPromiseLike(value);
|
|
2094
|
+
case "Iterator":
|
|
2095
|
+
return isIteratorLike(value);
|
|
2096
|
+
case "AsyncIterator":
|
|
2097
|
+
return isAsyncIteratorLike(value);
|
|
2098
|
+
case "Function":
|
|
2099
|
+
return typeof value === "function";
|
|
2100
|
+
case "Constructor":
|
|
2101
|
+
return typeof value === "function" && "prototype" in value;
|
|
2102
|
+
case "Symbol":
|
|
2103
|
+
return typeof value === "symbol";
|
|
2104
|
+
case "Base": {
|
|
2105
|
+
const check = schemaCallbackField(schema, "Check");
|
|
2106
|
+
return check ? check(value) : true;
|
|
2107
|
+
}
|
|
2108
|
+
default:
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
// src/value/check.ts
|
|
2114
|
+
function resolveCheckContext(context) {
|
|
2115
|
+
return resolveRuntimeContext(context);
|
|
2116
|
+
}
|
|
2117
|
+
function Check(schema, value, options) {
|
|
2118
|
+
return CheckInternal(schema, value, new Map, resolveCheckContext(options));
|
|
2119
|
+
}
|
|
2120
|
+
function CheckInternal(schema, value, refs, context) {
|
|
2121
|
+
const runtimeContext = resolveCheckContext(context);
|
|
2122
|
+
const kind = schema["~kind"];
|
|
2123
|
+
const primitiveResult = checkPrimitiveKind(kind, schema, value, runtimeContext);
|
|
2124
|
+
if (primitiveResult !== undefined) {
|
|
2125
|
+
return primitiveResult;
|
|
2126
|
+
}
|
|
2127
|
+
const collectionResult = checkCollectionKind(kind, schema, value, refs, (nextSchema, nextValue, nextRefs) => CheckInternal(nextSchema, nextValue, nextRefs, runtimeContext));
|
|
2128
|
+
if (collectionResult !== undefined) {
|
|
2129
|
+
return collectionResult;
|
|
2130
|
+
}
|
|
2131
|
+
const extensionResult = checkExtensionKind(kind, schema, value, refs, (nextSchema, nextValue, nextRefs) => CheckInternal(nextSchema, nextValue, nextRefs, runtimeContext));
|
|
2132
|
+
if (extensionResult !== undefined) {
|
|
2133
|
+
return extensionResult;
|
|
2134
|
+
}
|
|
2135
|
+
const customValidator = runtimeContext.TypeRegistry.Get(kind ?? "");
|
|
2136
|
+
return customValidator ? customValidator(schema, value) : false;
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// src/error/messages.ts
|
|
2140
|
+
function createSchemaIssue(path, code, params = {}) {
|
|
2141
|
+
return { path, code, params };
|
|
2142
|
+
}
|
|
2143
|
+
function localizeSchemaIssueWithCatalog(issue, catalog, locale) {
|
|
2144
|
+
return {
|
|
2145
|
+
...issue,
|
|
2146
|
+
locale,
|
|
2147
|
+
message: catalog[issue.code](issue.params ?? {})
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
// src/error/collector/advanced.ts
|
|
2152
|
+
function unresolvedRefIssue(path) {
|
|
2153
|
+
return [createSchemaIssue(schemaPath(path), "UNRESOLVED_REF")];
|
|
2154
|
+
}
|
|
2155
|
+
function collectDelegatedIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2156
|
+
switch (kind) {
|
|
2157
|
+
case "Optional":
|
|
2158
|
+
return value === undefined ? [] : collectSchemaIssues(schema.item, value, path, refs);
|
|
2159
|
+
case "Readonly":
|
|
2160
|
+
case "Immutable":
|
|
2161
|
+
return collectSchemaIssues(schema.item, value, path, refs);
|
|
2162
|
+
case "Codec":
|
|
2163
|
+
return collectSchemaIssues(schema.inner, value, path, refs);
|
|
2164
|
+
case "Decode":
|
|
2165
|
+
return collectSchemaIssues(schema.inner, value, path, refs);
|
|
2166
|
+
case "Encode":
|
|
2167
|
+
return collectSchemaIssues(schema.inner, value, path, refs);
|
|
2168
|
+
case "Awaited":
|
|
2169
|
+
return collectSchemaIssues(schema.promise.item, value, path, refs);
|
|
2170
|
+
case "ReturnType":
|
|
2171
|
+
return collectSchemaIssues(schema.function.returns, value, path, refs);
|
|
2172
|
+
case "InstanceType":
|
|
2173
|
+
return collectSchemaIssues(schema.constructor.returns, value, path, refs);
|
|
2174
|
+
case "Capitalize":
|
|
2175
|
+
case "Lowercase":
|
|
2176
|
+
case "Uppercase":
|
|
2177
|
+
case "Uncapitalize":
|
|
2178
|
+
return collectSchemaIssues(resolveStringActionSchema(schema), value, path, refs);
|
|
2179
|
+
case "Parameter":
|
|
2180
|
+
return collectSchemaIssues(schema.equals, value, path, refs);
|
|
2181
|
+
case "Generic":
|
|
2182
|
+
return collectSchemaIssues(schema.expression, value, path, refs);
|
|
2183
|
+
case "Infer":
|
|
2184
|
+
return collectSchemaIssues(schema.extends, value, path, refs);
|
|
2185
|
+
default:
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
function collectReferenceIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2190
|
+
switch (kind) {
|
|
2191
|
+
case "Recursive": {
|
|
2192
|
+
const recursiveSchema = schema;
|
|
2193
|
+
const nextRefs = new Map(refs);
|
|
2194
|
+
nextRefs.set(recursiveSchema.name, recursiveSchema.schema);
|
|
2195
|
+
nextRefs.set("#", recursiveSchema.schema);
|
|
2196
|
+
return collectSchemaIssues(recursiveSchema.schema, value, path, nextRefs);
|
|
2197
|
+
}
|
|
2198
|
+
case "Ref": {
|
|
2199
|
+
const target = refs.get(schema.name);
|
|
2200
|
+
return target === undefined ? unresolvedRefIssue(path) : collectSchemaIssues(target, value, path, refs);
|
|
2201
|
+
}
|
|
2202
|
+
case "This": {
|
|
2203
|
+
const target = refs.get("#");
|
|
2204
|
+
return target === undefined ? unresolvedRefIssue(path) : collectSchemaIssues(target, value, path, refs);
|
|
2205
|
+
}
|
|
2206
|
+
case "Call": {
|
|
2207
|
+
const instantiated = Instantiate({}, schema);
|
|
2208
|
+
return instantiated === schema ? [createSchemaIssue(schemaPath(path), "CALL")] : collectSchemaIssues(instantiated, value, path, refs);
|
|
2209
|
+
}
|
|
2210
|
+
case "Cyclic": {
|
|
2211
|
+
const cyclicSchema = schema;
|
|
2212
|
+
const nextRefs = new Map(refs);
|
|
2213
|
+
Object.entries(cyclicSchema.$defs).forEach(([name, definition]) => {
|
|
2214
|
+
nextRefs.set(name, definition);
|
|
2215
|
+
});
|
|
2216
|
+
const target = cyclicSchema.$defs[cyclicSchema.$ref];
|
|
2217
|
+
return target === undefined ? [] : collectSchemaIssues(target, value, path, nextRefs);
|
|
2218
|
+
}
|
|
2219
|
+
default:
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
function collectBranchIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2224
|
+
const currentPath = schemaPath(path);
|
|
2225
|
+
switch (kind) {
|
|
2226
|
+
case "Exclude": {
|
|
2227
|
+
const excludeSchema = schema;
|
|
2228
|
+
if (!CheckInternal(excludeSchema.left, value, refs)) {
|
|
2229
|
+
return collectSchemaIssues(excludeSchema.left, value, path, refs);
|
|
2230
|
+
}
|
|
2231
|
+
return CheckInternal(excludeSchema.right, value, refs) ? [createSchemaIssue(currentPath, "EXCLUDE")] : [];
|
|
2232
|
+
}
|
|
2233
|
+
case "Extract": {
|
|
2234
|
+
const extractSchema = schema;
|
|
2235
|
+
if (!CheckInternal(extractSchema.left, value, refs)) {
|
|
2236
|
+
return collectSchemaIssues(extractSchema.left, value, path, refs);
|
|
2237
|
+
}
|
|
2238
|
+
return CheckInternal(extractSchema.right, value, refs) ? [] : [createSchemaIssue(currentPath, "EXTRACT")];
|
|
2239
|
+
}
|
|
2240
|
+
case "Not":
|
|
2241
|
+
return CheckInternal(schema.schema, value, refs) ? [createSchemaIssue(currentPath, "NOT")] : [];
|
|
2242
|
+
case "IfThenElse": {
|
|
2243
|
+
const conditionalSchema = schema;
|
|
2244
|
+
return collectSchemaIssues(CheckInternal(conditionalSchema.if, value, refs) ? conditionalSchema.then : conditionalSchema.else, value, path, refs);
|
|
2245
|
+
}
|
|
2246
|
+
case "Conditional": {
|
|
2247
|
+
const conditionalSchema = schema;
|
|
2248
|
+
if (CheckInternal(conditionalSchema.check, value, refs)) {
|
|
2249
|
+
const variantIssues = conditionalSchema.union.map((entry) => collectSchemaIssues(entry, value, path, refs));
|
|
2250
|
+
return variantIssues.some((entry) => entry.length === 0) ? [] : [createSchemaIssue(currentPath, "CONDITIONAL")];
|
|
2251
|
+
}
|
|
2252
|
+
return conditionalSchema.default === undefined ? [] : collectSchemaIssues(conditionalSchema.default, value, path, refs);
|
|
2253
|
+
}
|
|
2254
|
+
case "Refine": {
|
|
2255
|
+
const refineSchema = schema;
|
|
2256
|
+
const nestedIssues = collectSchemaIssues(refineSchema.item, value, path, refs);
|
|
2257
|
+
if (nestedIssues.length > 0) {
|
|
2258
|
+
return nestedIssues;
|
|
2259
|
+
}
|
|
2260
|
+
const issues = [];
|
|
2261
|
+
refineSchema["~refine"].forEach((refinement) => {
|
|
2262
|
+
if (!refinement.refine(value)) {
|
|
2263
|
+
issues.push(createSchemaIssue(currentPath, "REFINE", { customMessage: refinement.message }));
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
return issues;
|
|
2267
|
+
}
|
|
2268
|
+
default:
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
function collectAdvancedIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2273
|
+
return collectDelegatedIssues(kind, schema, value, path, refs, collectSchemaIssues) ?? collectReferenceIssues(kind, schema, value, path, refs, collectSchemaIssues) ?? collectBranchIssues(kind, schema, value, path, refs, collectSchemaIssues) ?? (() => {
|
|
2274
|
+
const customValidator = TypeRegistry.Get(kind ?? "");
|
|
2275
|
+
return customValidator !== undefined && !customValidator(schema, value) ? [createSchemaIssue(schemaPath(path), "CUSTOM_TYPE", { kind: kind ?? "" })] : [];
|
|
2276
|
+
})();
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// src/error/collector/shared.ts
|
|
2280
|
+
function appendPath(path, segment) {
|
|
2281
|
+
return [...path, segment];
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
// src/error/collector/collections-basic.ts
|
|
2285
|
+
function collectArrayIssues(schema, value, path, refs, collectSchemaIssues) {
|
|
2286
|
+
const issues = [];
|
|
2287
|
+
const currentPath = schemaPath(path);
|
|
2288
|
+
if (!Array.isArray(value)) {
|
|
2289
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "array" }));
|
|
2290
|
+
return issues;
|
|
2291
|
+
}
|
|
2292
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
2293
|
+
issues.push(createSchemaIssue(currentPath, "MIN_ITEMS", { minimum: schema.minItems }));
|
|
2294
|
+
}
|
|
2295
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
2296
|
+
issues.push(createSchemaIssue(currentPath, "MAX_ITEMS", { maximum: schema.maxItems }));
|
|
2297
|
+
}
|
|
2298
|
+
if (schema.uniqueItems && new Set(value).size !== value.length) {
|
|
2299
|
+
issues.push(createSchemaIssue(currentPath, "UNIQUE_ITEMS"));
|
|
2300
|
+
}
|
|
2301
|
+
if (schema.contains !== undefined) {
|
|
2302
|
+
let containsCount = 0;
|
|
2303
|
+
value.forEach((item) => {
|
|
2304
|
+
if (CheckInternal(schema.contains, item, refs)) {
|
|
2305
|
+
containsCount += 1;
|
|
2306
|
+
}
|
|
2307
|
+
});
|
|
2308
|
+
if (containsCount === 0) {
|
|
2309
|
+
issues.push(createSchemaIssue(currentPath, "CONTAINS"));
|
|
2310
|
+
}
|
|
2311
|
+
if (schema.minContains !== undefined && containsCount < schema.minContains) {
|
|
2312
|
+
issues.push(createSchemaIssue(currentPath, "MIN_CONTAINS", { minimum: schema.minContains }));
|
|
2313
|
+
}
|
|
2314
|
+
if (schema.maxContains !== undefined && containsCount > schema.maxContains) {
|
|
2315
|
+
issues.push(createSchemaIssue(currentPath, "MAX_CONTAINS", { maximum: schema.maxContains }));
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
value.forEach((item, index) => {
|
|
2319
|
+
issues.push(...collectSchemaIssues(schema.items, item, appendPath(path, String(index)), refs));
|
|
2320
|
+
});
|
|
2321
|
+
return issues;
|
|
2322
|
+
}
|
|
2323
|
+
function collectObjectIssues(schema, value, path, refs, collectSchemaIssues) {
|
|
2324
|
+
const issues = [];
|
|
2325
|
+
const currentPath = schemaPath(path);
|
|
2326
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
2327
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "object" }));
|
|
2328
|
+
return issues;
|
|
2329
|
+
}
|
|
2330
|
+
const objectValue = value;
|
|
2331
|
+
const required = schema.required ?? [];
|
|
2332
|
+
const optional = new Set((schema.optional ?? []).map(String));
|
|
2333
|
+
for (const key of required) {
|
|
2334
|
+
if (!(key in objectValue)) {
|
|
2335
|
+
issues.push(createSchemaIssue(schemaPath(appendPath(path, String(key))), "MISSING_REQUIRED", { property: String(key) }));
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
for (const [key, entryValue] of Object.entries(objectValue)) {
|
|
2339
|
+
const entryPath = appendPath(path, key);
|
|
2340
|
+
const patternSchemas = getPatternPropertySchemas(schema.patternProperties, key);
|
|
2341
|
+
if (schema.properties[key] !== undefined) {
|
|
2342
|
+
if (!(entryValue === undefined && optional.has(key))) {
|
|
2343
|
+
issues.push(...collectSchemaIssues(schema.properties[key], entryValue, entryPath, refs));
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
if (patternSchemas.length > 0) {
|
|
2347
|
+
for (const patternSchema of patternSchemas) {
|
|
2348
|
+
issues.push(...collectSchemaIssues(patternSchema, entryValue, entryPath, refs));
|
|
2349
|
+
}
|
|
2350
|
+
} else if (schema.properties[key] === undefined && schema.additionalProperties === false) {
|
|
2351
|
+
issues.push(createSchemaIssue(schemaPath(entryPath), "ADDITIONAL_PROPERTY", { property: key }));
|
|
2352
|
+
} else if (schema.properties[key] === undefined && typeof schema.additionalProperties === "object") {
|
|
2353
|
+
issues.push(...collectSchemaIssues(schema.additionalProperties, entryValue, entryPath, refs));
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
return issues;
|
|
2357
|
+
}
|
|
2358
|
+
function collectTupleIssues(schema, value, path, refs, collectSchemaIssues) {
|
|
2359
|
+
const issues = [];
|
|
2360
|
+
const currentPath = schemaPath(path);
|
|
2361
|
+
if (!Array.isArray(value)) {
|
|
2362
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "array" }));
|
|
2363
|
+
return issues;
|
|
2364
|
+
}
|
|
2365
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
2366
|
+
issues.push(createSchemaIssue(currentPath, "MIN_ITEMS", { label: "Tuple", minimum: schema.minItems }));
|
|
2367
|
+
}
|
|
2368
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems) {
|
|
2369
|
+
issues.push(createSchemaIssue(currentPath, "MAX_ITEMS", { label: "Tuple", maximum: schema.maxItems }));
|
|
2370
|
+
}
|
|
2371
|
+
value.forEach((item, index) => {
|
|
2372
|
+
const itemSchema = schema.items[index];
|
|
2373
|
+
if (itemSchema !== undefined) {
|
|
2374
|
+
issues.push(...collectSchemaIssues(itemSchema, item, appendPath(path, String(index)), refs));
|
|
2375
|
+
} else if (!schema.additionalItems) {
|
|
2376
|
+
issues.push(createSchemaIssue(schemaPath(appendPath(path, String(index))), "ADDITIONAL_ITEMS", { count: index }));
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
return issues;
|
|
2380
|
+
}
|
|
2381
|
+
function collectRecordIssues(schema, value, path, refs, collectSchemaIssues) {
|
|
2382
|
+
const issues = [];
|
|
2383
|
+
const currentPath = schemaPath(path);
|
|
2384
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
2385
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "object" }));
|
|
2386
|
+
return issues;
|
|
2387
|
+
}
|
|
2388
|
+
const entries = Object.entries(value);
|
|
2389
|
+
if (schema.minProperties !== undefined && entries.length < schema.minProperties) {
|
|
2390
|
+
issues.push(createSchemaIssue(currentPath, "MIN_PROPERTIES", { minimum: schema.minProperties }));
|
|
2391
|
+
}
|
|
2392
|
+
if (schema.maxProperties !== undefined && entries.length > schema.maxProperties) {
|
|
2393
|
+
issues.push(createSchemaIssue(currentPath, "MAX_PROPERTIES", { maximum: schema.maxProperties }));
|
|
2394
|
+
}
|
|
2395
|
+
entries.forEach(([key, entryValue]) => {
|
|
2396
|
+
if (!CheckInternal(schema.key, key, refs)) {
|
|
2397
|
+
issues.push(createSchemaIssue(schemaPath(appendPath(path, key)), "INVALID_KEY", { key }));
|
|
2398
|
+
}
|
|
2399
|
+
issues.push(...collectSchemaIssues(schema.value, entryValue, appendPath(path, key), refs));
|
|
2400
|
+
});
|
|
2401
|
+
return issues;
|
|
2402
|
+
}
|
|
2403
|
+
function collectBasicCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2404
|
+
switch (kind) {
|
|
2405
|
+
case "Array":
|
|
2406
|
+
return collectArrayIssues(schema, value, path, refs, collectSchemaIssues);
|
|
2407
|
+
case "Object":
|
|
2408
|
+
return collectObjectIssues(schema, value, path, refs, collectSchemaIssues);
|
|
2409
|
+
case "Tuple":
|
|
2410
|
+
return collectTupleIssues(schema, value, path, refs, collectSchemaIssues);
|
|
2411
|
+
case "Record":
|
|
2412
|
+
return collectRecordIssues(schema, value, path, refs, collectSchemaIssues);
|
|
2413
|
+
default:
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// src/error/collector/collections-derived.ts
|
|
2419
|
+
function collectDerivedCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2420
|
+
const currentPath = schemaPath(path);
|
|
2421
|
+
switch (kind) {
|
|
2422
|
+
case "Union": {
|
|
2423
|
+
const unionSchema = schema;
|
|
2424
|
+
const variantIssues = unionSchema.variants.map((variant) => collectSchemaIssues(variant, value, path, refs));
|
|
2425
|
+
return variantIssues.some((entry) => entry.length === 0) ? [] : [createSchemaIssue(currentPath, "UNION")];
|
|
2426
|
+
}
|
|
2427
|
+
case "Intersect": {
|
|
2428
|
+
const intersectSchema = schema;
|
|
2429
|
+
const issues = [];
|
|
2430
|
+
intersectSchema.variants.forEach((variant) => {
|
|
2431
|
+
issues.push(...collectSchemaIssues(variant, value, path, refs));
|
|
2432
|
+
});
|
|
2433
|
+
return issues;
|
|
2434
|
+
}
|
|
2435
|
+
case "Partial":
|
|
2436
|
+
return collectSchemaIssues(deriveObjectSchema(schema.object, { requiredMode: "none" }), value, path, refs);
|
|
2437
|
+
case "Required":
|
|
2438
|
+
return collectSchemaIssues(deriveObjectSchema(schema.object, { requiredMode: "all" }), value, path, refs);
|
|
2439
|
+
case "KeyOf": {
|
|
2440
|
+
const keyOfSchema = schema;
|
|
2441
|
+
const keys = Object.keys(keyOfSchema.object.properties);
|
|
2442
|
+
if (typeof value !== "string") {
|
|
2443
|
+
return [createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "string", actual: typeof value })];
|
|
2444
|
+
}
|
|
2445
|
+
return keys.includes(value) ? [] : [createSchemaIssue(currentPath, "KEYOF", { values: keys })];
|
|
2446
|
+
}
|
|
2447
|
+
case "Pick": {
|
|
2448
|
+
const pickSchema = schema;
|
|
2449
|
+
return collectSchemaIssues(deriveObjectSchema(pickSchema.object, { pickKeys: pickSchema.keys, additionalProperties: false }), value, path, refs);
|
|
2450
|
+
}
|
|
2451
|
+
case "Omit": {
|
|
2452
|
+
const omitSchema = schema;
|
|
2453
|
+
return collectSchemaIssues(deriveObjectSchema(omitSchema.object, { omitKeys: omitSchema.keys, additionalProperties: false }), value, path, refs);
|
|
2454
|
+
}
|
|
2455
|
+
case "Index": {
|
|
2456
|
+
const indexSchema = schema;
|
|
2457
|
+
const candidates = deriveIndexSchemas(indexSchema.object, indexSchema.key, (candidateSchema, candidateValue) => CheckInternal(candidateSchema, candidateValue, new Map));
|
|
2458
|
+
if (candidates.length === 0) {
|
|
2459
|
+
return [createSchemaIssue(currentPath, "INDEX")];
|
|
2460
|
+
}
|
|
2461
|
+
const candidateIssues = candidates.map((candidate) => collectSchemaIssues(candidate, value, path, refs));
|
|
2462
|
+
return candidateIssues.some((entry) => entry.length === 0) ? [] : [createSchemaIssue(currentPath, "INDEX")];
|
|
2463
|
+
}
|
|
2464
|
+
case "Mapped":
|
|
2465
|
+
return collectSchemaIssues(schema.object, value, path, refs);
|
|
2466
|
+
default:
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// src/error/collector/collections-parameters.ts
|
|
2472
|
+
function collectTupleParameterIssues(parameters, value, path, refs, collectSchemaIssues) {
|
|
2473
|
+
const currentPath = schemaPath(path);
|
|
2474
|
+
if (!Array.isArray(value)) {
|
|
2475
|
+
return [createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "array" })];
|
|
2476
|
+
}
|
|
2477
|
+
const issues = [];
|
|
2478
|
+
if (value.length !== parameters.length) {
|
|
2479
|
+
issues.push(createSchemaIssue(currentPath, "PARAMETERS_LENGTH", { count: parameters.length }));
|
|
2480
|
+
}
|
|
2481
|
+
value.forEach((item, index) => {
|
|
2482
|
+
const parameter = parameters[index];
|
|
2483
|
+
if (parameter !== undefined) {
|
|
2484
|
+
issues.push(...collectSchemaIssues(parameter, item, appendPath(path, String(index)), refs));
|
|
2485
|
+
}
|
|
2486
|
+
});
|
|
2487
|
+
return issues;
|
|
2488
|
+
}
|
|
2489
|
+
function collectParameterCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2490
|
+
switch (kind) {
|
|
2491
|
+
case "Rest": {
|
|
2492
|
+
const currentPath = schemaPath(path);
|
|
2493
|
+
if (!Array.isArray(value)) {
|
|
2494
|
+
return [createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "array" })];
|
|
2495
|
+
}
|
|
2496
|
+
const restSchema = schema;
|
|
2497
|
+
const issues = [];
|
|
2498
|
+
value.forEach((item, index) => {
|
|
2499
|
+
issues.push(...collectSchemaIssues(restSchema.items, item, appendPath(path, String(index)), refs));
|
|
2500
|
+
});
|
|
2501
|
+
return issues;
|
|
2502
|
+
}
|
|
2503
|
+
case "Parameters":
|
|
2504
|
+
return collectTupleParameterIssues(schema.function.parameters, value, path, refs, collectSchemaIssues);
|
|
2505
|
+
case "ConstructorParameters":
|
|
2506
|
+
return collectTupleParameterIssues(schema.constructor.parameters, value, path, refs, collectSchemaIssues);
|
|
2507
|
+
default:
|
|
2508
|
+
return;
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
// src/error/collector/collections.ts
|
|
2513
|
+
function collectCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues) {
|
|
2514
|
+
const basicIssues = collectBasicCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues);
|
|
2515
|
+
if (basicIssues !== undefined) {
|
|
2516
|
+
return basicIssues;
|
|
2517
|
+
}
|
|
2518
|
+
const derivedIssues = collectDerivedCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues);
|
|
2519
|
+
if (derivedIssues !== undefined) {
|
|
2520
|
+
return derivedIssues;
|
|
2521
|
+
}
|
|
2522
|
+
return collectParameterCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues);
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
// src/type/combinator-core.ts
|
|
2526
|
+
function Union(variants, options) {
|
|
2527
|
+
return { "~kind": "Union", variants, ...options };
|
|
2528
|
+
}
|
|
2529
|
+
function Intersect(variants, options) {
|
|
2530
|
+
return { "~kind": "Intersect", variants, ...options };
|
|
2531
|
+
}
|
|
2532
|
+
function Evaluate(schema) {
|
|
2533
|
+
if (schema["~kind"] === "Object") {
|
|
2534
|
+
return schema;
|
|
2535
|
+
}
|
|
2536
|
+
const properties = {};
|
|
2537
|
+
const required = new Set;
|
|
2538
|
+
const optional = new Set;
|
|
2539
|
+
const patternProperties = {};
|
|
2540
|
+
let additionalProperties;
|
|
2541
|
+
for (const variant of schema.variants) {
|
|
2542
|
+
Object.assign(properties, variant.properties);
|
|
2543
|
+
for (const key of variant.required ?? [])
|
|
2544
|
+
required.add(String(key));
|
|
2545
|
+
for (const key of variant.optional ?? [])
|
|
2546
|
+
optional.add(String(key));
|
|
2547
|
+
Object.assign(patternProperties, variant.patternProperties);
|
|
2548
|
+
if (variant.additionalProperties === false) {
|
|
2549
|
+
additionalProperties = false;
|
|
2550
|
+
} else if (additionalProperties !== false && variant.additionalProperties !== undefined) {
|
|
2551
|
+
additionalProperties = variant.additionalProperties;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
for (const key of optional) {
|
|
2555
|
+
required.delete(key);
|
|
2556
|
+
}
|
|
2557
|
+
return {
|
|
2558
|
+
"~kind": "Object",
|
|
2559
|
+
properties,
|
|
2560
|
+
...required.size > 0 ? { required: [...required] } : {},
|
|
2561
|
+
...optional.size > 0 ? { optional: [...optional] } : {},
|
|
2562
|
+
...Object.keys(patternProperties).length > 0 ? { patternProperties } : {},
|
|
2563
|
+
...additionalProperties !== undefined ? { additionalProperties } : {}
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
function Optional(item, options) {
|
|
2567
|
+
return { "~kind": "Optional", item, ...options };
|
|
2568
|
+
}
|
|
2569
|
+
function Readonly(item, options) {
|
|
2570
|
+
return { "~kind": "Readonly", item, ...options };
|
|
2571
|
+
}
|
|
2572
|
+
function Enum(values, options) {
|
|
2573
|
+
return { "~kind": "Enum", values, ...options };
|
|
2574
|
+
}
|
|
2575
|
+
function Ref(name, options) {
|
|
2576
|
+
return { "~kind": "Ref", name, ...options };
|
|
2577
|
+
}
|
|
2578
|
+
function Recursive(name, build, options) {
|
|
2579
|
+
const self = Ref(name);
|
|
2580
|
+
const schema = build(self);
|
|
2581
|
+
return { "~kind": "Recursive", name, schema, ...options };
|
|
2582
|
+
}
|
|
2583
|
+
function Variant(discriminator, variants, options) {
|
|
2584
|
+
return Union(variants, { discriminator, ...options });
|
|
2585
|
+
}
|
|
2586
|
+
// src/type/combinator-objects.ts
|
|
2587
|
+
function Exclude(left, right, options) {
|
|
2588
|
+
return { "~kind": "Exclude", left, right, ...options };
|
|
2589
|
+
}
|
|
2590
|
+
function Extract(left, right, options) {
|
|
2591
|
+
return { "~kind": "Extract", left, right, ...options };
|
|
2592
|
+
}
|
|
2593
|
+
function KeyOf(object, options) {
|
|
2594
|
+
return { "~kind": "KeyOf", object, ...options };
|
|
2595
|
+
}
|
|
2596
|
+
function Partial(object, options) {
|
|
2597
|
+
return { "~kind": "Partial", object, ...options };
|
|
2598
|
+
}
|
|
2599
|
+
function Required(object, options) {
|
|
2600
|
+
return { "~kind": "Required", object, ...options };
|
|
2601
|
+
}
|
|
2602
|
+
function Pick(object, keys, options) {
|
|
2603
|
+
return { "~kind": "Pick", object, keys, ...options };
|
|
2604
|
+
}
|
|
2605
|
+
function Omit(object, keys, options) {
|
|
2606
|
+
return { "~kind": "Omit", object, keys, ...options };
|
|
2607
|
+
}
|
|
2608
|
+
function Not(schema, options) {
|
|
2609
|
+
return { "~kind": "Not", schema, ...options };
|
|
2610
|
+
}
|
|
2611
|
+
function IfThenElse(condition, then, elseSchema, options) {
|
|
2612
|
+
return {
|
|
2613
|
+
"~kind": "IfThenElse",
|
|
2614
|
+
if: condition,
|
|
2615
|
+
then,
|
|
2616
|
+
else: elseSchema,
|
|
2617
|
+
...options
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
function Unsafe(schema, options) {
|
|
2621
|
+
return {
|
|
2622
|
+
"~kind": "Unsafe",
|
|
2623
|
+
schema,
|
|
2624
|
+
type: undefined,
|
|
2625
|
+
...options
|
|
2626
|
+
};
|
|
2627
|
+
}
|
|
2628
|
+
function Index(object, key, options) {
|
|
2629
|
+
return {
|
|
2630
|
+
"~kind": "Index",
|
|
2631
|
+
object,
|
|
2632
|
+
key: key ?? { "~kind": "String" },
|
|
2633
|
+
...options
|
|
2634
|
+
};
|
|
2635
|
+
}
|
|
2636
|
+
function Mapped(object, transform, options) {
|
|
2637
|
+
return { "~kind": "Mapped", object, ...transform ? { transform } : {}, ...options };
|
|
2638
|
+
}
|
|
2639
|
+
function Conditional(check, union, defaultSchema, options) {
|
|
2640
|
+
return {
|
|
2641
|
+
"~kind": "Conditional",
|
|
2642
|
+
check,
|
|
2643
|
+
union,
|
|
2644
|
+
default: defaultSchema,
|
|
2645
|
+
...options
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
// src/type/combinator-functions.ts
|
|
2649
|
+
function Awaited(promise) {
|
|
2650
|
+
return { "~kind": "Awaited", promise };
|
|
2651
|
+
}
|
|
2652
|
+
function ReturnType(fn) {
|
|
2653
|
+
return { "~kind": "ReturnType", function: fn };
|
|
2654
|
+
}
|
|
2655
|
+
function Parameters(fn) {
|
|
2656
|
+
return { "~kind": "Parameters", function: fn };
|
|
2657
|
+
}
|
|
2658
|
+
function InstanceType(ctor) {
|
|
2659
|
+
return { "~kind": "InstanceType", constructor: ctor };
|
|
2660
|
+
}
|
|
2661
|
+
function ConstructorParameters(ctor) {
|
|
2662
|
+
return { "~kind": "ConstructorParameters", constructor: ctor };
|
|
2663
|
+
}
|
|
2664
|
+
function Module(definitions) {
|
|
2665
|
+
const mod = { "~kind": "Module", definitions };
|
|
2666
|
+
return {
|
|
2667
|
+
...mod,
|
|
2668
|
+
Import(name) {
|
|
2669
|
+
return { "~kind": "Ref", name };
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2672
|
+
}
|
|
2673
|
+
// src/type/containers.ts
|
|
2674
|
+
function Array2(item, options) {
|
|
2675
|
+
return {
|
|
2676
|
+
"~kind": "Array",
|
|
2677
|
+
items: item,
|
|
2678
|
+
...options
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
function Object2(properties, options) {
|
|
2682
|
+
return {
|
|
2683
|
+
"~kind": "Object",
|
|
2684
|
+
properties,
|
|
2685
|
+
...options
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
function Tuple(items, options) {
|
|
2689
|
+
const expandedItems = ExpandTupleRest(items);
|
|
2690
|
+
return {
|
|
2691
|
+
"~kind": "Tuple",
|
|
2692
|
+
items: expandedItems,
|
|
2693
|
+
minItems: options?.minItems ?? expandedItems.length,
|
|
2694
|
+
maxItems: options?.maxItems ?? (options?.additionalItems === true ? undefined : expandedItems.length),
|
|
2695
|
+
additionalItems: options?.additionalItems ?? false,
|
|
2696
|
+
...options
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
function Record(key, value, options) {
|
|
2700
|
+
return {
|
|
2701
|
+
"~kind": "Record",
|
|
2702
|
+
key,
|
|
2703
|
+
value,
|
|
2704
|
+
...options
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
// src/value/clone.ts
|
|
2709
|
+
function cloneValue(value) {
|
|
2710
|
+
return globalThis.structuredClone(value);
|
|
2711
|
+
}
|
|
2712
|
+
function Clone(value) {
|
|
2713
|
+
return cloneValue(value);
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
// src/type/actions.ts
|
|
2717
|
+
function hasKind(value, kind) {
|
|
2718
|
+
return value["~kind"] === kind;
|
|
2719
|
+
}
|
|
2720
|
+
function ExpandTupleRest(items) {
|
|
2721
|
+
const expanded = [];
|
|
2722
|
+
for (const item of items) {
|
|
2723
|
+
if (hasKind(item, "Rest")) {
|
|
2724
|
+
const rest = item;
|
|
2725
|
+
if (hasKind(rest.items, "Tuple")) {
|
|
2726
|
+
expanded.push(...rest.items.items);
|
|
2727
|
+
continue;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
expanded.push(item);
|
|
2731
|
+
}
|
|
2732
|
+
return expanded;
|
|
2733
|
+
}
|
|
2734
|
+
function Rest(item) {
|
|
2735
|
+
return { "~kind": "Rest", type: "rest", items: item };
|
|
2736
|
+
}
|
|
2737
|
+
function Composite(objects) {
|
|
2738
|
+
return Evaluate(Intersect(objects));
|
|
2739
|
+
}
|
|
2740
|
+
function Clone2(schema) {
|
|
2741
|
+
return Clone(schema);
|
|
2742
|
+
}
|
|
2743
|
+
function Capitalize(item) {
|
|
2744
|
+
return { "~kind": "Capitalize", item };
|
|
2745
|
+
}
|
|
2746
|
+
function Lowercase(item) {
|
|
2747
|
+
return { "~kind": "Lowercase", item };
|
|
2748
|
+
}
|
|
2749
|
+
function Uppercase(item) {
|
|
2750
|
+
return { "~kind": "Uppercase", item };
|
|
2751
|
+
}
|
|
2752
|
+
function Uncapitalize(item) {
|
|
2753
|
+
return { "~kind": "Uncapitalize", item };
|
|
2754
|
+
}
|
|
2755
|
+
function Interface(heritage, properties, options) {
|
|
2756
|
+
return {
|
|
2757
|
+
...Evaluate(Intersect([...heritage, Object2(properties)])),
|
|
2758
|
+
...options
|
|
2759
|
+
};
|
|
2760
|
+
}
|
|
2761
|
+
function NonNullable(type, options) {
|
|
2762
|
+
return Exclude(type, Union([Null(), Undefined()]), options);
|
|
2763
|
+
}
|
|
2764
|
+
function Options(type, options) {
|
|
2765
|
+
return {
|
|
2766
|
+
...type,
|
|
2767
|
+
...options
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
function ReadonlyType(type, options) {
|
|
2771
|
+
return Readonly(type, options);
|
|
2772
|
+
}
|
|
2773
|
+
function Identifier(name) {
|
|
2774
|
+
return {
|
|
2775
|
+
"~kind": "Identifier",
|
|
2776
|
+
type: "identifier",
|
|
2777
|
+
name
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
function Parameter(name, extends_, equals) {
|
|
2781
|
+
const constraint = extends_ ?? Unknown();
|
|
2782
|
+
const fallback = equals ?? constraint;
|
|
2783
|
+
return {
|
|
2784
|
+
"~kind": "Parameter",
|
|
2785
|
+
name,
|
|
2786
|
+
extends: constraint,
|
|
2787
|
+
equals: fallback
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
function This(options) {
|
|
2791
|
+
return {
|
|
2792
|
+
"~kind": "This",
|
|
2793
|
+
$ref: "#",
|
|
2794
|
+
...options
|
|
2795
|
+
};
|
|
2796
|
+
}
|
|
2797
|
+
function Import(module, name) {
|
|
2798
|
+
const definition = module.definitions[name];
|
|
2799
|
+
if (definition === undefined) {
|
|
2800
|
+
throw new Error(`Unknown module definition: ${name}`);
|
|
2801
|
+
}
|
|
2802
|
+
return definition;
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
// src/type/primitives.ts
|
|
2806
|
+
function String2(options) {
|
|
2807
|
+
return { "~kind": "String", ...options };
|
|
2808
|
+
}
|
|
2809
|
+
function Number2(options) {
|
|
2810
|
+
return { "~kind": "Number", ...options };
|
|
2811
|
+
}
|
|
2812
|
+
function Integer(options) {
|
|
2813
|
+
return { "~kind": "Integer", ...options };
|
|
2814
|
+
}
|
|
2815
|
+
function Boolean(options) {
|
|
2816
|
+
return { "~kind": "Boolean", ...options };
|
|
2817
|
+
}
|
|
2818
|
+
function Null(options) {
|
|
2819
|
+
return { "~kind": "Null", ...options };
|
|
2820
|
+
}
|
|
2821
|
+
function Literal(value, options) {
|
|
2822
|
+
return { "~kind": "Literal", const: value, ...options };
|
|
2823
|
+
}
|
|
2824
|
+
function Void(options) {
|
|
2825
|
+
return { "~kind": "Void", ...options };
|
|
2826
|
+
}
|
|
2827
|
+
function Undefined(options) {
|
|
2828
|
+
return { "~kind": "Undefined", ...options };
|
|
2829
|
+
}
|
|
2830
|
+
function Unknown(options) {
|
|
2831
|
+
return { "~kind": "Unknown", ...options };
|
|
2832
|
+
}
|
|
2833
|
+
function Any(options) {
|
|
2834
|
+
return { "~kind": "Any", ...options };
|
|
2835
|
+
}
|
|
2836
|
+
function Never(options) {
|
|
2837
|
+
return { "~kind": "Never", ...options };
|
|
2838
|
+
}
|
|
2839
|
+
function BigInt2(options) {
|
|
2840
|
+
return { "~kind": "BigInt", ...options };
|
|
2841
|
+
}
|
|
2842
|
+
function Date(options) {
|
|
2843
|
+
return { "~kind": "Date", ...options };
|
|
2844
|
+
}
|
|
2845
|
+
function DateFormat(options) {
|
|
2846
|
+
return String2({ format: "date", ...options });
|
|
2847
|
+
}
|
|
2848
|
+
function Uuid(options) {
|
|
2849
|
+
return String2({ format: "uuid", ...options });
|
|
2850
|
+
}
|
|
2851
|
+
function Email(options) {
|
|
2852
|
+
return String2({ format: "email", ...options });
|
|
2853
|
+
}
|
|
2854
|
+
function Uri(options) {
|
|
2855
|
+
return String2({ format: "uri", ...options });
|
|
2856
|
+
}
|
|
2857
|
+
function Hostname(options) {
|
|
2858
|
+
return String2({ format: "hostname", ...options });
|
|
2859
|
+
}
|
|
2860
|
+
function Ip(options) {
|
|
2861
|
+
return String2({ format: "ip", ...options });
|
|
2862
|
+
}
|
|
2863
|
+
function Base64(options) {
|
|
2864
|
+
return String2({ format: "base64", ...options });
|
|
2865
|
+
}
|
|
2866
|
+
function Hex(options) {
|
|
2867
|
+
return String2({ format: "hex", ...options });
|
|
2868
|
+
}
|
|
2869
|
+
function HexColor(options) {
|
|
2870
|
+
return String2({ format: "hexcolor", ...options });
|
|
2871
|
+
}
|
|
2872
|
+
function DateTime(options) {
|
|
2873
|
+
return String2({ format: "datetime", ...options });
|
|
2874
|
+
}
|
|
2875
|
+
function Time(options) {
|
|
2876
|
+
return String2({ format: "time", ...options });
|
|
2877
|
+
}
|
|
2878
|
+
function Duration(options) {
|
|
2879
|
+
return String2({ format: "duration", ...options });
|
|
2880
|
+
}
|
|
2881
|
+
function Json(options) {
|
|
2882
|
+
return String2({ format: "json", ...options });
|
|
2883
|
+
}
|
|
2884
|
+
function CreditCard(options) {
|
|
2885
|
+
return String2({ format: "creditcard", ...options });
|
|
2886
|
+
}
|
|
2887
|
+
function Uint8Array2(options) {
|
|
2888
|
+
return { "~kind": "Uint8Array", ...options };
|
|
2889
|
+
}
|
|
2890
|
+
function RegExpInstance(options) {
|
|
2891
|
+
return { "~kind": "RegExpInstance", ...options };
|
|
2892
|
+
}
|
|
2893
|
+
function RegExp2(options) {
|
|
2894
|
+
return String2({ format: "regex", ...options });
|
|
2895
|
+
}
|
|
2896
|
+
function Symbol2(options) {
|
|
2897
|
+
return { "~kind": "Symbol", ...options };
|
|
2898
|
+
}
|
|
2899
|
+
function TemplateLiteral(patterns, options) {
|
|
2900
|
+
return { "~kind": "TemplateLiteral", patterns, ...options };
|
|
2901
|
+
}
|
|
2902
|
+
function Function2(parameters, returns, options) {
|
|
2903
|
+
const resolvedParameters = ExpandTupleRest(parameters ?? []);
|
|
2904
|
+
const resolvedReturns = returns ?? Any();
|
|
2905
|
+
return {
|
|
2906
|
+
"~kind": "Function",
|
|
2907
|
+
parameters: resolvedParameters,
|
|
2908
|
+
returns: resolvedReturns,
|
|
2909
|
+
...options
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
function Constructor(parameters, returns, options) {
|
|
2913
|
+
const resolvedParameters = ExpandTupleRest(parameters ?? []);
|
|
2914
|
+
const resolvedReturns = returns ?? Any();
|
|
2915
|
+
return {
|
|
2916
|
+
"~kind": "Constructor",
|
|
2917
|
+
parameters: resolvedParameters,
|
|
2918
|
+
returns: resolvedReturns,
|
|
2919
|
+
...options
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2922
|
+
function Promise2(item, options) {
|
|
2923
|
+
return { "~kind": "Promise", item, ...options };
|
|
2924
|
+
}
|
|
2925
|
+
function Iterator(item, options) {
|
|
2926
|
+
return { "~kind": "Iterator", item, ...options };
|
|
2927
|
+
}
|
|
2928
|
+
function AsyncIterator(item, options) {
|
|
2929
|
+
return { "~kind": "AsyncIterator", item, ...options };
|
|
2930
|
+
}
|
|
2931
|
+
function Decode(inner, decode) {
|
|
2932
|
+
return { "~kind": "Decode", inner, decode };
|
|
2933
|
+
}
|
|
2934
|
+
function Encode(inner, encode) {
|
|
2935
|
+
return { "~kind": "Encode", inner, encode };
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2938
|
+
// src/error/collector/primitives.ts
|
|
2939
|
+
function invalidTypeIssue(path, expected, actual) {
|
|
2940
|
+
return [createSchemaIssue(schemaPath(path), "INVALID_TYPE", actual === undefined ? { expected } : { expected, actual })];
|
|
2941
|
+
}
|
|
2942
|
+
function collectStringIssues(schema, value, path, refs) {
|
|
2943
|
+
const issues = [];
|
|
2944
|
+
const currentPath = schemaPath(path);
|
|
2945
|
+
if (typeof value !== "string") {
|
|
2946
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "string", actual: typeof value }));
|
|
2947
|
+
return issues;
|
|
2948
|
+
}
|
|
2949
|
+
if (schema.minLength !== undefined && value.length < schema.minLength) {
|
|
2950
|
+
issues.push(createSchemaIssue(currentPath, "MIN_LENGTH", { label: "String length", minimum: schema.minLength }));
|
|
2951
|
+
}
|
|
2952
|
+
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
2953
|
+
issues.push(createSchemaIssue(currentPath, "MAX_LENGTH", { label: "String length", maximum: schema.maxLength }));
|
|
2954
|
+
}
|
|
2955
|
+
if (schema.pattern !== undefined && !new RegExp(schema.pattern).test(value)) {
|
|
2956
|
+
issues.push(createSchemaIssue(currentPath, "PATTERN", { label: "String", pattern: schema.pattern }));
|
|
2957
|
+
}
|
|
2958
|
+
if (typeof schema.format === "string" && !CheckInternal(String2({ format: schema.format }), value, refs)) {
|
|
2959
|
+
issues.push(createSchemaIssue(currentPath, "FORMAT", { label: "String", format: schema.format }));
|
|
2960
|
+
}
|
|
2961
|
+
return issues;
|
|
2962
|
+
}
|
|
2963
|
+
function collectNumberIssues(schema, value, path, integerOnly) {
|
|
2964
|
+
const issues = [];
|
|
2965
|
+
const currentPath = schemaPath(path);
|
|
2966
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
2967
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "number", actual: typeof value }));
|
|
2968
|
+
return issues;
|
|
2969
|
+
}
|
|
2970
|
+
if (integerOnly && !Number.isInteger(value)) {
|
|
2971
|
+
issues.push(createSchemaIssue(currentPath, "INVALID_TYPE", { expected: "integer" }));
|
|
2972
|
+
}
|
|
2973
|
+
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
2974
|
+
issues.push(createSchemaIssue(currentPath, "MINIMUM", { minimum: schema.minimum }));
|
|
2975
|
+
}
|
|
2976
|
+
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
2977
|
+
issues.push(createSchemaIssue(currentPath, "MAXIMUM", { maximum: schema.maximum }));
|
|
2978
|
+
}
|
|
2979
|
+
if (schema.exclusiveMinimum !== undefined && value <= schema.exclusiveMinimum) {
|
|
2980
|
+
issues.push(createSchemaIssue(currentPath, "EXCLUSIVE_MINIMUM", { minimum: schema.exclusiveMinimum }));
|
|
2981
|
+
}
|
|
2982
|
+
if (schema.exclusiveMaximum !== undefined && value >= schema.exclusiveMaximum) {
|
|
2983
|
+
issues.push(createSchemaIssue(currentPath, "EXCLUSIVE_MAXIMUM", { maximum: schema.exclusiveMaximum }));
|
|
2984
|
+
}
|
|
2985
|
+
if (schema.multipleOf !== undefined && value % schema.multipleOf !== 0) {
|
|
2986
|
+
issues.push(createSchemaIssue(currentPath, "MULTIPLE_OF", { divisor: schema.multipleOf }));
|
|
2987
|
+
}
|
|
2988
|
+
return issues;
|
|
2989
|
+
}
|
|
2990
|
+
function collectBigIntIssues(schema, value, path) {
|
|
2991
|
+
const issues = [];
|
|
2992
|
+
const currentPath = schemaPath(path);
|
|
2993
|
+
if (typeof value !== "bigint") {
|
|
2994
|
+
return invalidTypeIssue(path, "bigint", typeof value);
|
|
2995
|
+
}
|
|
2996
|
+
if (schema.minimum !== undefined && value < schema.minimum) {
|
|
2997
|
+
issues.push(createSchemaIssue(currentPath, "MINIMUM", { minimum: schema.minimum }));
|
|
2998
|
+
}
|
|
2999
|
+
if (schema.maximum !== undefined && value > schema.maximum) {
|
|
3000
|
+
issues.push(createSchemaIssue(currentPath, "MAXIMUM", { maximum: schema.maximum }));
|
|
3001
|
+
}
|
|
3002
|
+
if (schema.exclusiveMinimum !== undefined && value <= schema.exclusiveMinimum) {
|
|
3003
|
+
issues.push(createSchemaIssue(currentPath, "EXCLUSIVE_MINIMUM", { minimum: schema.exclusiveMinimum }));
|
|
3004
|
+
}
|
|
3005
|
+
if (schema.exclusiveMaximum !== undefined && value >= schema.exclusiveMaximum) {
|
|
3006
|
+
issues.push(createSchemaIssue(currentPath, "EXCLUSIVE_MAXIMUM", { maximum: schema.exclusiveMaximum }));
|
|
3007
|
+
}
|
|
3008
|
+
if (schema.multipleOf !== undefined && value % schema.multipleOf !== 0n) {
|
|
3009
|
+
issues.push(createSchemaIssue(currentPath, "MULTIPLE_OF", { divisor: schema.multipleOf }));
|
|
3010
|
+
}
|
|
3011
|
+
return issues;
|
|
3012
|
+
}
|
|
3013
|
+
function collectDateIssues(schema, value, path) {
|
|
3014
|
+
const issues = [];
|
|
3015
|
+
const currentPath = schemaPath(path);
|
|
3016
|
+
if (!(value instanceof globalThis.Date) || Number.isNaN(value.getTime())) {
|
|
3017
|
+
return invalidTypeIssue(path, "Date instance");
|
|
3018
|
+
}
|
|
3019
|
+
const timestamp = value.getTime();
|
|
3020
|
+
if (schema.minimumTimestamp !== undefined && timestamp < schema.minimumTimestamp) {
|
|
3021
|
+
issues.push(createSchemaIssue(currentPath, "MINIMUM", { label: "Date timestamp", minimum: schema.minimumTimestamp }));
|
|
3022
|
+
}
|
|
3023
|
+
if (schema.maximumTimestamp !== undefined && timestamp > schema.maximumTimestamp) {
|
|
3024
|
+
issues.push(createSchemaIssue(currentPath, "MAXIMUM", { label: "Date timestamp", maximum: schema.maximumTimestamp }));
|
|
3025
|
+
}
|
|
3026
|
+
return issues;
|
|
3027
|
+
}
|
|
3028
|
+
function collectLiteralIssues(schema, value, path) {
|
|
3029
|
+
return value === schema.const ? [] : [createSchemaIssue(schemaPath(path), "INVALID_CONST", { expectedValue: JSON.stringify(schema.const) })];
|
|
3030
|
+
}
|
|
3031
|
+
function collectEnumIssues(schema, value, path) {
|
|
3032
|
+
if (typeof value !== "string") {
|
|
3033
|
+
return invalidTypeIssue(path, "string", typeof value);
|
|
3034
|
+
}
|
|
3035
|
+
return schema.values.includes(value) ? [] : [createSchemaIssue(schemaPath(path), "ENUM", { values: schema.values })];
|
|
3036
|
+
}
|
|
3037
|
+
function collectTemplateLiteralIssues(schema, value, path) {
|
|
3038
|
+
if (typeof value !== "string") {
|
|
3039
|
+
return invalidTypeIssue(path, "string", typeof value);
|
|
3040
|
+
}
|
|
3041
|
+
return new RegExp(schema.patterns.join("|")).test(value) ? [] : [createSchemaIssue(schemaPath(path), "PATTERN", { label: "String", patterns: schema.patterns })];
|
|
3042
|
+
}
|
|
3043
|
+
function collectUint8ArrayIssues(schema, value, path) {
|
|
3044
|
+
const issues = [];
|
|
3045
|
+
const currentPath = schemaPath(path);
|
|
3046
|
+
if (!(value instanceof globalThis.Uint8Array)) {
|
|
3047
|
+
return invalidTypeIssue(path, "Uint8Array", typeof value);
|
|
3048
|
+
}
|
|
3049
|
+
if (schema.minByteLength !== undefined && value.byteLength < schema.minByteLength) {
|
|
3050
|
+
issues.push(createSchemaIssue(currentPath, "MIN_LENGTH", { label: "Uint8Array byteLength", minimum: schema.minByteLength }));
|
|
3051
|
+
}
|
|
3052
|
+
if (schema.maxByteLength !== undefined && value.byteLength > schema.maxByteLength) {
|
|
3053
|
+
issues.push(createSchemaIssue(currentPath, "MAX_LENGTH", { label: "Uint8Array byteLength", maximum: schema.maxByteLength }));
|
|
3054
|
+
}
|
|
3055
|
+
return issues;
|
|
3056
|
+
}
|
|
3057
|
+
function collectPrimitiveIssues(kind, schema, value, path, refs) {
|
|
3058
|
+
const currentPath = schemaPath(path);
|
|
3059
|
+
switch (kind) {
|
|
3060
|
+
case "String":
|
|
3061
|
+
return collectStringIssues(schema, value, path, refs);
|
|
3062
|
+
case "Number":
|
|
3063
|
+
return collectNumberIssues(schema, value, path, false);
|
|
3064
|
+
case "Integer":
|
|
3065
|
+
return collectNumberIssues(schema, value, path, true);
|
|
3066
|
+
case "BigInt":
|
|
3067
|
+
return collectBigIntIssues(schema, value, path);
|
|
3068
|
+
case "Date":
|
|
3069
|
+
return collectDateIssues(schema, value, path);
|
|
3070
|
+
case "Boolean":
|
|
3071
|
+
return typeof value === "boolean" ? [] : invalidTypeIssue(path, "boolean", typeof value);
|
|
3072
|
+
case "Null":
|
|
3073
|
+
return value === null ? [] : invalidTypeIssue(path, "null");
|
|
3074
|
+
case "Literal":
|
|
3075
|
+
return collectLiteralIssues(schema, value, path);
|
|
3076
|
+
case "Enum":
|
|
3077
|
+
return collectEnumIssues(schema, value, path);
|
|
3078
|
+
case "Void":
|
|
3079
|
+
return value === undefined || value === null ? [] : invalidTypeIssue(path, "void (undefined or null)");
|
|
3080
|
+
case "Undefined":
|
|
3081
|
+
return value === undefined ? [] : invalidTypeIssue(path, "undefined");
|
|
3082
|
+
case "Never":
|
|
3083
|
+
return [createSchemaIssue(currentPath, "NEVER")];
|
|
3084
|
+
case "TemplateLiteral":
|
|
3085
|
+
return collectTemplateLiteralIssues(schema, value, path);
|
|
3086
|
+
case "Uint8Array":
|
|
3087
|
+
return collectUint8ArrayIssues(schema, value, path);
|
|
3088
|
+
case "Identifier":
|
|
3089
|
+
return typeof value === "string" && /^[$A-Z_a-z][$\w]*$/.test(value) ? [] : [createSchemaIssue(currentPath, typeof value === "string" ? "IDENTIFIER" : "INVALID_TYPE", { expected: "string", actual: typeof value })];
|
|
3090
|
+
case "Promise":
|
|
3091
|
+
return isPromiseLike(value) ? [] : invalidTypeIssue(path, "Promise-like value");
|
|
3092
|
+
case "Iterator":
|
|
3093
|
+
return isIteratorLike(value) ? [] : invalidTypeIssue(path, "iterator value");
|
|
3094
|
+
case "AsyncIterator":
|
|
3095
|
+
return isAsyncIteratorLike(value) ? [] : invalidTypeIssue(path, "async iterator value");
|
|
3096
|
+
case "Function":
|
|
3097
|
+
return typeof value === "function" ? [] : invalidTypeIssue(path, "function", typeof value);
|
|
3098
|
+
case "Constructor":
|
|
3099
|
+
return typeof value === "function" && "prototype" in value ? [] : invalidTypeIssue(path, "constructor function");
|
|
3100
|
+
case "Symbol":
|
|
3101
|
+
return typeof value === "symbol" ? [] : invalidTypeIssue(path, "symbol", typeof value);
|
|
3102
|
+
case "Base": {
|
|
3103
|
+
const baseSchema = schema;
|
|
3104
|
+
if (typeof baseSchema.Check === "function" && !baseSchema.Check(value)) {
|
|
3105
|
+
return [createSchemaIssue(currentPath, "BASE")];
|
|
3106
|
+
}
|
|
3107
|
+
return [];
|
|
3108
|
+
}
|
|
3109
|
+
default:
|
|
3110
|
+
return;
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
// src/error/collector.ts
|
|
3115
|
+
function collectSchemaIssues(schema, value, path = [], refs = new Map) {
|
|
3116
|
+
const kind = schemaKind(schema);
|
|
3117
|
+
const primitiveIssues = collectPrimitiveIssues(kind, schema, value, path, refs);
|
|
3118
|
+
if (primitiveIssues !== undefined) {
|
|
3119
|
+
return primitiveIssues;
|
|
3120
|
+
}
|
|
3121
|
+
const collectionIssues = collectCollectionIssues(kind, schema, value, path, refs, collectSchemaIssues);
|
|
3122
|
+
if (collectionIssues !== undefined) {
|
|
3123
|
+
return collectionIssues;
|
|
3124
|
+
}
|
|
3125
|
+
return collectAdvancedIssues(kind, schema, value, path, refs, collectSchemaIssues);
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
// src/error/errors.ts
|
|
3129
|
+
function Explain(schema, value, context) {
|
|
3130
|
+
const runtimeContext = resolveRuntimeContext(context);
|
|
3131
|
+
const locale = String(runtimeContext.Locale.Get());
|
|
3132
|
+
const catalog = runtimeContext.Locale.GetCatalog(locale);
|
|
3133
|
+
return collectSchemaIssues(schema, value).map((issue) => localizeSchemaIssueWithCatalog(issue, catalog, locale));
|
|
3134
|
+
}
|
|
3135
|
+
function Errors(schema, value, context) {
|
|
3136
|
+
return Explain(schema, value, context).map((issue) => ({
|
|
3137
|
+
path: issue.path,
|
|
3138
|
+
code: issue.code,
|
|
3139
|
+
message: issue.message
|
|
3140
|
+
}));
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
// src/value/clean.ts
|
|
3144
|
+
var NOT_HANDLED = Symbol("clean.not-handled");
|
|
3145
|
+
function Clean(schema, value) {
|
|
3146
|
+
return CleanInternal(schema, value, new Map);
|
|
3147
|
+
}
|
|
3148
|
+
function cleanStructuredValue(s, value, refs) {
|
|
3149
|
+
const kind = s["~kind"];
|
|
3150
|
+
switch (kind) {
|
|
3151
|
+
case "Object": {
|
|
3152
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3153
|
+
return value;
|
|
3154
|
+
const result = {};
|
|
3155
|
+
const props = s["properties"];
|
|
3156
|
+
const additionalProperties = s["additionalProperties"];
|
|
3157
|
+
for (const [key, val] of Object.entries(value)) {
|
|
3158
|
+
const propSchema = props[key];
|
|
3159
|
+
if (propSchema) {
|
|
3160
|
+
result[key] = CleanInternal(propSchema, val, refs);
|
|
3161
|
+
} else if (additionalProperties !== false) {
|
|
3162
|
+
if (typeof additionalProperties === "object") {
|
|
3163
|
+
result[key] = CleanInternal(additionalProperties, val, refs);
|
|
3164
|
+
} else {
|
|
3165
|
+
result[key] = val;
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
return result;
|
|
3170
|
+
}
|
|
3171
|
+
case "Array": {
|
|
3172
|
+
if (!Array.isArray(value))
|
|
3173
|
+
return value;
|
|
3174
|
+
const itemSchema = s["items"];
|
|
3175
|
+
return value.map((item) => CleanInternal(itemSchema, item, refs));
|
|
3176
|
+
}
|
|
3177
|
+
case "Tuple": {
|
|
3178
|
+
if (!Array.isArray(value))
|
|
3179
|
+
return value;
|
|
3180
|
+
const items = s["items"];
|
|
3181
|
+
const cleanedItems = value.slice(0, items.length).map((item, i) => items[i] ? CleanInternal(items[i], item, refs) : item);
|
|
3182
|
+
return s["additionalItems"] === true ? [...cleanedItems, ...value.slice(items.length)] : cleanedItems;
|
|
3183
|
+
}
|
|
3184
|
+
case "Record": {
|
|
3185
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3186
|
+
return value;
|
|
3187
|
+
const result = {};
|
|
3188
|
+
const valueSchema = s["value"];
|
|
3189
|
+
for (const [key, val] of Object.entries(value)) {
|
|
3190
|
+
result[key] = CleanInternal(valueSchema, val, refs);
|
|
3191
|
+
}
|
|
3192
|
+
return result;
|
|
3193
|
+
}
|
|
3194
|
+
default:
|
|
3195
|
+
return NOT_HANDLED;
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
function cleanCompositeValue(s, value, refs) {
|
|
3199
|
+
const kind = s["~kind"];
|
|
3200
|
+
switch (kind) {
|
|
3201
|
+
case "Union": {
|
|
3202
|
+
const variants = s["variants"];
|
|
3203
|
+
for (const variant of variants) {
|
|
3204
|
+
const cleaned = CleanInternal(variant, value, refs);
|
|
3205
|
+
if (cleaned !== value)
|
|
3206
|
+
return cleaned;
|
|
3207
|
+
}
|
|
3208
|
+
return value;
|
|
3209
|
+
}
|
|
3210
|
+
case "Intersect": {
|
|
3211
|
+
const variants = s["variants"];
|
|
3212
|
+
let result = value;
|
|
3213
|
+
for (const variant of variants) {
|
|
3214
|
+
result = CleanInternal(variant, result, refs);
|
|
3215
|
+
}
|
|
3216
|
+
return result;
|
|
3217
|
+
}
|
|
3218
|
+
case "Optional":
|
|
3219
|
+
case "Readonly":
|
|
3220
|
+
return value === undefined ? value : CleanInternal(s["item"], value, refs);
|
|
3221
|
+
case "Recursive": {
|
|
3222
|
+
const nextRefs = new Map(refs);
|
|
3223
|
+
nextRefs.set(s["name"], s["schema"]);
|
|
3224
|
+
return CleanInternal(s["schema"], value, nextRefs);
|
|
3225
|
+
}
|
|
3226
|
+
case "Ref": {
|
|
3227
|
+
const target = refs.get(s["name"]);
|
|
3228
|
+
return target ? CleanInternal(target, value, refs) : value;
|
|
3229
|
+
}
|
|
3230
|
+
case "Decode":
|
|
3231
|
+
case "Encode":
|
|
3232
|
+
return CleanInternal(s["inner"], value, refs);
|
|
3233
|
+
default:
|
|
3234
|
+
return NOT_HANDLED;
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
function CleanInternal(schema, value, refs) {
|
|
3238
|
+
const s = schema;
|
|
3239
|
+
const structured = cleanStructuredValue(s, value, refs);
|
|
3240
|
+
if (structured !== NOT_HANDLED) {
|
|
3241
|
+
return structured;
|
|
3242
|
+
}
|
|
3243
|
+
const composite = cleanCompositeValue(s, value, refs);
|
|
3244
|
+
return composite !== NOT_HANDLED ? composite : value;
|
|
3245
|
+
}
|
|
3246
|
+
|
|
3247
|
+
// src/value/convert.ts
|
|
3248
|
+
var NOT_HANDLED2 = Symbol("convert.not-handled");
|
|
3249
|
+
function isBigIntText(value) {
|
|
3250
|
+
const normalized = value.trim();
|
|
3251
|
+
if (normalized.length === 0) {
|
|
3252
|
+
return false;
|
|
3253
|
+
}
|
|
3254
|
+
const first = normalized[0];
|
|
3255
|
+
const start = first === "+" || first === "-" ? 1 : 0;
|
|
3256
|
+
if (start === normalized.length) {
|
|
3257
|
+
return false;
|
|
3258
|
+
}
|
|
3259
|
+
for (let index = start;index < normalized.length; index += 1) {
|
|
3260
|
+
const char = normalized[index];
|
|
3261
|
+
if (char === undefined || char < "0" || char > "9") {
|
|
3262
|
+
return false;
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
return true;
|
|
3266
|
+
}
|
|
3267
|
+
function Convert(schema, value) {
|
|
3268
|
+
return ConvertInternal(schema, value, new Map);
|
|
3269
|
+
}
|
|
3270
|
+
function convertPrimitiveValue(s, value) {
|
|
3271
|
+
const kind = s["~kind"];
|
|
3272
|
+
switch (kind) {
|
|
3273
|
+
case "String": {
|
|
3274
|
+
if (typeof value === "string")
|
|
3275
|
+
return value;
|
|
3276
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
3277
|
+
return globalThis.String(value);
|
|
3278
|
+
}
|
|
3279
|
+
return value;
|
|
3280
|
+
}
|
|
3281
|
+
case "Number": {
|
|
3282
|
+
if (typeof value === "number")
|
|
3283
|
+
return value;
|
|
3284
|
+
if (typeof value === "string") {
|
|
3285
|
+
const n = globalThis.Number(value);
|
|
3286
|
+
if (!isNaN(n))
|
|
3287
|
+
return n;
|
|
3288
|
+
}
|
|
3289
|
+
if (typeof value === "boolean")
|
|
3290
|
+
return value ? 1 : 0;
|
|
3291
|
+
return value;
|
|
3292
|
+
}
|
|
3293
|
+
case "Integer": {
|
|
3294
|
+
if (typeof value === "number" && Number.isInteger(value))
|
|
3295
|
+
return value;
|
|
3296
|
+
if (typeof value === "string") {
|
|
3297
|
+
const n = parseInt(value, 10);
|
|
3298
|
+
if (!isNaN(n))
|
|
3299
|
+
return n;
|
|
3300
|
+
}
|
|
3301
|
+
if (typeof value === "boolean")
|
|
3302
|
+
return value ? 1 : 0;
|
|
3303
|
+
if (typeof value === "number")
|
|
3304
|
+
return Math.trunc(value);
|
|
3305
|
+
return value;
|
|
3306
|
+
}
|
|
3307
|
+
case "Boolean": {
|
|
3308
|
+
if (typeof value === "boolean")
|
|
3309
|
+
return value;
|
|
3310
|
+
if (typeof value === "string") {
|
|
3311
|
+
if (value === "true" || value === "1")
|
|
3312
|
+
return true;
|
|
3313
|
+
if (value === "false" || value === "0")
|
|
3314
|
+
return false;
|
|
3315
|
+
}
|
|
3316
|
+
if (typeof value === "number")
|
|
3317
|
+
return value !== 0;
|
|
3318
|
+
return value;
|
|
3319
|
+
}
|
|
3320
|
+
case "BigInt": {
|
|
3321
|
+
if (typeof value === "bigint")
|
|
3322
|
+
return value;
|
|
3323
|
+
if (typeof value === "number" && Number.isInteger(value))
|
|
3324
|
+
return globalThis.BigInt(value);
|
|
3325
|
+
if (typeof value === "string") {
|
|
3326
|
+
const normalized = value.trim();
|
|
3327
|
+
if (isBigIntText(normalized)) {
|
|
3328
|
+
return globalThis.BigInt(normalized);
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3331
|
+
return value;
|
|
3332
|
+
}
|
|
3333
|
+
case "Date": {
|
|
3334
|
+
if (value instanceof globalThis.Date)
|
|
3335
|
+
return value;
|
|
3336
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
3337
|
+
const d = new globalThis.Date(value);
|
|
3338
|
+
if (!isNaN(d.getTime()))
|
|
3339
|
+
return d;
|
|
3340
|
+
}
|
|
3341
|
+
return value;
|
|
3342
|
+
}
|
|
3343
|
+
case "Null":
|
|
3344
|
+
return value === null ? value : value === "null" || value === undefined ? null : value;
|
|
3345
|
+
default:
|
|
3346
|
+
return NOT_HANDLED2;
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
function convertStructuredValue(s, value, refs) {
|
|
3350
|
+
const kind = s["~kind"];
|
|
3351
|
+
switch (kind) {
|
|
3352
|
+
case "Object": {
|
|
3353
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3354
|
+
return value;
|
|
3355
|
+
const result = {};
|
|
3356
|
+
const props = s["properties"];
|
|
3357
|
+
const obj = value;
|
|
3358
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
3359
|
+
const propSchema = props[key];
|
|
3360
|
+
result[key] = propSchema ? ConvertInternal(propSchema, val, refs) : val;
|
|
3361
|
+
}
|
|
3362
|
+
return result;
|
|
3363
|
+
}
|
|
3364
|
+
case "Array": {
|
|
3365
|
+
if (!Array.isArray(value))
|
|
3366
|
+
return value;
|
|
3367
|
+
const itemSchema = s["items"];
|
|
3368
|
+
return value.map((item) => ConvertInternal(itemSchema, item, refs));
|
|
3369
|
+
}
|
|
3370
|
+
case "Tuple": {
|
|
3371
|
+
if (!Array.isArray(value))
|
|
3372
|
+
return value;
|
|
3373
|
+
const items = s["items"];
|
|
3374
|
+
return value.map((item, i) => items[i] ? ConvertInternal(items[i], item, refs) : item);
|
|
3375
|
+
}
|
|
3376
|
+
default:
|
|
3377
|
+
return NOT_HANDLED2;
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
function convertCompositeValue(s, value, refs) {
|
|
3381
|
+
const kind = s["~kind"];
|
|
3382
|
+
switch (kind) {
|
|
3383
|
+
case "Optional":
|
|
3384
|
+
return value === undefined ? value : ConvertInternal(s["item"], value, refs);
|
|
3385
|
+
case "Readonly":
|
|
3386
|
+
return ConvertInternal(s["item"], value, refs);
|
|
3387
|
+
case "Union": {
|
|
3388
|
+
const variants = s["variants"];
|
|
3389
|
+
for (const variant of variants) {
|
|
3390
|
+
const converted = ConvertInternal(variant, value, refs);
|
|
3391
|
+
if (converted !== value)
|
|
3392
|
+
return converted;
|
|
3393
|
+
}
|
|
3394
|
+
return value;
|
|
3395
|
+
}
|
|
3396
|
+
case "Intersect": {
|
|
3397
|
+
const variants = s["variants"];
|
|
3398
|
+
let result = value;
|
|
3399
|
+
for (const variant of variants) {
|
|
3400
|
+
result = ConvertInternal(variant, result, refs);
|
|
3401
|
+
}
|
|
3402
|
+
return result;
|
|
3403
|
+
}
|
|
3404
|
+
case "Recursive": {
|
|
3405
|
+
const nextRefs = new Map(refs);
|
|
3406
|
+
nextRefs.set(s["name"], s["schema"]);
|
|
3407
|
+
return ConvertInternal(s["schema"], value, nextRefs);
|
|
3408
|
+
}
|
|
3409
|
+
case "Ref": {
|
|
3410
|
+
const target = refs.get(s["name"]);
|
|
3411
|
+
return target ? ConvertInternal(target, value, refs) : value;
|
|
3412
|
+
}
|
|
3413
|
+
case "Decode":
|
|
3414
|
+
case "Encode":
|
|
3415
|
+
return ConvertInternal(s["inner"], value, refs);
|
|
3416
|
+
default:
|
|
3417
|
+
return NOT_HANDLED2;
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
function ConvertInternal(schema, value, refs) {
|
|
3421
|
+
const s = schema;
|
|
3422
|
+
const primitive = convertPrimitiveValue(s, value);
|
|
3423
|
+
if (primitive !== NOT_HANDLED2) {
|
|
3424
|
+
return primitive;
|
|
3425
|
+
}
|
|
3426
|
+
const structured = convertStructuredValue(s, value, refs);
|
|
3427
|
+
if (structured !== NOT_HANDLED2) {
|
|
3428
|
+
return structured;
|
|
3429
|
+
}
|
|
3430
|
+
const composite = convertCompositeValue(s, value, refs);
|
|
3431
|
+
return composite !== NOT_HANDLED2 ? composite : value;
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
// src/value/create.ts
|
|
3435
|
+
var NOT_HANDLED3 = Symbol("create.not-handled");
|
|
3436
|
+
function cloneValue2(value) {
|
|
3437
|
+
return globalThis.structuredClone(value);
|
|
3438
|
+
}
|
|
3439
|
+
function Create(schema) {
|
|
3440
|
+
return CreateInternal(schema, new Map);
|
|
3441
|
+
}
|
|
3442
|
+
function createPrimitiveValue(s) {
|
|
3443
|
+
const kind = s["~kind"];
|
|
3444
|
+
switch (kind) {
|
|
3445
|
+
case "String":
|
|
3446
|
+
return "";
|
|
3447
|
+
case "Number":
|
|
3448
|
+
return 0;
|
|
3449
|
+
case "Integer":
|
|
3450
|
+
return 0;
|
|
3451
|
+
case "Boolean":
|
|
3452
|
+
return false;
|
|
3453
|
+
case "Null":
|
|
3454
|
+
return null;
|
|
3455
|
+
case "BigInt":
|
|
3456
|
+
return 0n;
|
|
3457
|
+
case "Date":
|
|
3458
|
+
return new globalThis.Date(0);
|
|
3459
|
+
case "Literal":
|
|
3460
|
+
return s["const"];
|
|
3461
|
+
case "Void":
|
|
3462
|
+
case "Undefined":
|
|
3463
|
+
case "Unknown":
|
|
3464
|
+
case "Any":
|
|
3465
|
+
case "Never":
|
|
3466
|
+
return;
|
|
3467
|
+
case "Symbol":
|
|
3468
|
+
return globalThis.Symbol();
|
|
3469
|
+
case "Uint8Array":
|
|
3470
|
+
return new globalThis.Uint8Array(0);
|
|
3471
|
+
case "Function":
|
|
3472
|
+
return () => {};
|
|
3473
|
+
case "Constructor":
|
|
3474
|
+
return class {
|
|
3475
|
+
};
|
|
3476
|
+
case "Promise":
|
|
3477
|
+
return globalThis.Promise.resolve(undefined);
|
|
3478
|
+
default:
|
|
3479
|
+
return NOT_HANDLED3;
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
function createStructuredValue(s, refs) {
|
|
3483
|
+
const kind = s["~kind"];
|
|
3484
|
+
switch (kind) {
|
|
3485
|
+
case "Array":
|
|
3486
|
+
return [];
|
|
3487
|
+
case "Tuple": {
|
|
3488
|
+
const items = s["items"];
|
|
3489
|
+
return items.map((item) => CreateInternal(item, refs));
|
|
3490
|
+
}
|
|
3491
|
+
case "Object": {
|
|
3492
|
+
const obj = {};
|
|
3493
|
+
const props = s["properties"];
|
|
3494
|
+
const required = s["required"] ?? [];
|
|
3495
|
+
const optionalKeys = new Set(s["optional"] ?? []);
|
|
3496
|
+
for (const key of required) {
|
|
3497
|
+
if (props[key])
|
|
3498
|
+
obj[key] = CreateInternal(props[key], refs);
|
|
3499
|
+
}
|
|
3500
|
+
for (const [key, propSchema] of Object.entries(props)) {
|
|
3501
|
+
if (!(key in obj) && !optionalKeys.has(key)) {
|
|
3502
|
+
obj[key] = CreateInternal(propSchema, refs);
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
return obj;
|
|
3506
|
+
}
|
|
3507
|
+
case "Record":
|
|
3508
|
+
case "Partial":
|
|
3509
|
+
return {};
|
|
3510
|
+
case "Union": {
|
|
3511
|
+
const variants = s["variants"];
|
|
3512
|
+
return variants.length > 0 ? CreateInternal(variants[0], refs) : undefined;
|
|
3513
|
+
}
|
|
3514
|
+
case "Intersect": {
|
|
3515
|
+
const variants = s["variants"];
|
|
3516
|
+
let result = {};
|
|
3517
|
+
for (const variant of variants) {
|
|
3518
|
+
const v = CreateInternal(variant, refs);
|
|
3519
|
+
if (typeof v === "object" && v !== null)
|
|
3520
|
+
result = { ...result, ...v };
|
|
3521
|
+
}
|
|
3522
|
+
return result;
|
|
3523
|
+
}
|
|
3524
|
+
case "Optional":
|
|
3525
|
+
return;
|
|
3526
|
+
case "Readonly":
|
|
3527
|
+
return CreateInternal(s["item"], refs);
|
|
3528
|
+
case "Enum": {
|
|
3529
|
+
const values = s["values"];
|
|
3530
|
+
return values.length > 0 ? values[0] : "";
|
|
3531
|
+
}
|
|
3532
|
+
case "Required": {
|
|
3533
|
+
const obj = s["object"];
|
|
3534
|
+
const result = {};
|
|
3535
|
+
for (const [key, propSchema] of Object.entries(obj.properties)) {
|
|
3536
|
+
result[key] = CreateInternal(propSchema, refs);
|
|
3537
|
+
}
|
|
3538
|
+
return result;
|
|
3539
|
+
}
|
|
3540
|
+
default:
|
|
3541
|
+
return NOT_HANDLED3;
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
function createReferenceValue(s, refs) {
|
|
3545
|
+
const kind = s["~kind"];
|
|
3546
|
+
switch (kind) {
|
|
3547
|
+
case "Ref": {
|
|
3548
|
+
const target = refs.get(s["name"]);
|
|
3549
|
+
return target ? CreateInternal(target, refs) : undefined;
|
|
3550
|
+
}
|
|
3551
|
+
case "Recursive": {
|
|
3552
|
+
const nextRefs = new Map(refs);
|
|
3553
|
+
nextRefs.set(s["name"], s["schema"]);
|
|
3554
|
+
return CreateInternal(s["schema"], nextRefs);
|
|
3555
|
+
}
|
|
3556
|
+
case "Decode":
|
|
3557
|
+
case "Encode":
|
|
3558
|
+
return CreateInternal(s["inner"], refs);
|
|
3559
|
+
default:
|
|
3560
|
+
return NOT_HANDLED3;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
function CreateInternal(schema, refs) {
|
|
3564
|
+
const s = schema;
|
|
3565
|
+
if (s["default"] !== undefined)
|
|
3566
|
+
return cloneValue2(s["default"]);
|
|
3567
|
+
const primitive = createPrimitiveValue(s);
|
|
3568
|
+
if (primitive !== NOT_HANDLED3) {
|
|
3569
|
+
return primitive;
|
|
3570
|
+
}
|
|
3571
|
+
const structured = createStructuredValue(s, refs);
|
|
3572
|
+
if (structured !== NOT_HANDLED3) {
|
|
3573
|
+
return structured;
|
|
3574
|
+
}
|
|
3575
|
+
const reference = createReferenceValue(s, refs);
|
|
3576
|
+
return reference !== NOT_HANDLED3 ? reference : undefined;
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
// src/value/decode.ts
|
|
3580
|
+
function Decode2(schema, value) {
|
|
3581
|
+
return DecodeInternal(schema, value, new Map);
|
|
3582
|
+
}
|
|
3583
|
+
function isRecord3(value) {
|
|
3584
|
+
return typeof value === "object" && value !== null;
|
|
3585
|
+
}
|
|
3586
|
+
function resolveCodec(schema) {
|
|
3587
|
+
const codec = schemaUnknownField(schema, "codec");
|
|
3588
|
+
return isRecord3(codec) && typeof codec.decode === "function" ? codec : undefined;
|
|
3589
|
+
}
|
|
3590
|
+
function decodeObject(schema, value, refs) {
|
|
3591
|
+
if (!isRecord3(value) || Array.isArray(value))
|
|
3592
|
+
return value;
|
|
3593
|
+
const result = {};
|
|
3594
|
+
const properties = schemaProperties(schema);
|
|
3595
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
3596
|
+
const propertySchema = properties[key];
|
|
3597
|
+
result[key] = propertySchema ? DecodeInternal(propertySchema, entryValue, refs) : entryValue;
|
|
3598
|
+
}
|
|
3599
|
+
return result;
|
|
3600
|
+
}
|
|
3601
|
+
function decodeArrayItems(itemSchema, value, refs) {
|
|
3602
|
+
return Array.isArray(value) && itemSchema ? value.map((item) => DecodeInternal(itemSchema, item, refs)) : value;
|
|
3603
|
+
}
|
|
3604
|
+
function decodeTupleItems(schema, value, refs) {
|
|
3605
|
+
if (!Array.isArray(value))
|
|
3606
|
+
return value;
|
|
3607
|
+
const items = schemaSchemaListField(schema, "items");
|
|
3608
|
+
return value.map((item, index) => {
|
|
3609
|
+
const itemSchema = items[index];
|
|
3610
|
+
return itemSchema ? DecodeInternal(itemSchema, item, refs) : item;
|
|
3611
|
+
});
|
|
3612
|
+
}
|
|
3613
|
+
function decodeWrappedInner(schema, value, refs) {
|
|
3614
|
+
const inner = schemaInner(schema) ?? schemaItem(schema);
|
|
3615
|
+
return value === undefined || inner === undefined ? value : DecodeInternal(inner, value, refs);
|
|
3616
|
+
}
|
|
3617
|
+
function decodeReferenceSchema(schema, value, refs) {
|
|
3618
|
+
switch (schemaKind(schema)) {
|
|
3619
|
+
case "Call": {
|
|
3620
|
+
const instantiated = Instantiate({}, schema);
|
|
3621
|
+
return instantiated === schema ? value : DecodeInternal(instantiated, value, refs);
|
|
3622
|
+
}
|
|
3623
|
+
case "Cyclic": {
|
|
3624
|
+
const defs = schemaDefinitions(schema);
|
|
3625
|
+
const refName = schemaStringField(schema, "$ref");
|
|
3626
|
+
const nextRefs = new Map(refs);
|
|
3627
|
+
for (const [key, definition] of Object.entries(defs)) {
|
|
3628
|
+
nextRefs.set(key, definition);
|
|
3629
|
+
}
|
|
3630
|
+
const target = refName ? defs[refName] : undefined;
|
|
3631
|
+
return target === undefined ? value : DecodeInternal(target, value, nextRefs);
|
|
3632
|
+
}
|
|
3633
|
+
case "Recursive": {
|
|
3634
|
+
const name = schemaStringField(schema, "name");
|
|
3635
|
+
const target = schemaSchemaField(schema, "schema");
|
|
3636
|
+
if (!name || target === undefined)
|
|
3637
|
+
return value;
|
|
3638
|
+
const nextRefs = new Map(refs);
|
|
3639
|
+
nextRefs.set(name, target);
|
|
3640
|
+
nextRefs.set("#", target);
|
|
3641
|
+
return DecodeInternal(target, value, nextRefs);
|
|
3642
|
+
}
|
|
3643
|
+
case "Ref": {
|
|
3644
|
+
const target = refs.get(schemaStringField(schema, "name") ?? "");
|
|
3645
|
+
return target ? DecodeInternal(target, value, refs) : value;
|
|
3646
|
+
}
|
|
3647
|
+
default:
|
|
3648
|
+
return value;
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3651
|
+
function DecodeInternal(schema, value, refs) {
|
|
3652
|
+
switch (schemaKind(schema)) {
|
|
3653
|
+
case "Decode": {
|
|
3654
|
+
const inner = schemaInner(schema);
|
|
3655
|
+
const decode = schemaCallbackField(schema, "decode");
|
|
3656
|
+
return inner && decode ? decode(DecodeInternal(inner, value, refs)) : value;
|
|
3657
|
+
}
|
|
3658
|
+
case "Codec": {
|
|
3659
|
+
const inner = schemaInner(schema);
|
|
3660
|
+
const codec = resolveCodec(schema);
|
|
3661
|
+
return inner && codec ? codec.decode(DecodeInternal(inner, value, refs)) : value;
|
|
3662
|
+
}
|
|
3663
|
+
case "Object":
|
|
3664
|
+
return decodeObject(schema, value, refs);
|
|
3665
|
+
case "Array":
|
|
3666
|
+
return decodeArrayItems(schemaSchemaField(schema, "items"), value, refs);
|
|
3667
|
+
case "Tuple":
|
|
3668
|
+
return decodeTupleItems(schema, value, refs);
|
|
3669
|
+
case "Union":
|
|
3670
|
+
return value;
|
|
3671
|
+
case "Intersect": {
|
|
3672
|
+
let result = value;
|
|
3673
|
+
for (const variant of schemaSchemaListField(schema, "variants")) {
|
|
3674
|
+
result = DecodeInternal(variant, result, refs);
|
|
3675
|
+
}
|
|
3676
|
+
return result;
|
|
3677
|
+
}
|
|
3678
|
+
case "Optional":
|
|
3679
|
+
case "Readonly":
|
|
3680
|
+
case "Immutable":
|
|
3681
|
+
case "Refine":
|
|
3682
|
+
return decodeWrappedInner(schema, value, refs);
|
|
3683
|
+
case "Generic":
|
|
3684
|
+
return DecodeInternal(schemaSchemaField(schema, "expression") ?? schema, value, refs);
|
|
3685
|
+
case "Infer":
|
|
3686
|
+
return DecodeInternal(schemaSchemaField(schema, "extends") ?? schema, value, refs);
|
|
3687
|
+
case "Call":
|
|
3688
|
+
case "Cyclic":
|
|
3689
|
+
case "Recursive":
|
|
3690
|
+
case "Ref":
|
|
3691
|
+
return decodeReferenceSchema(schema, value, refs);
|
|
3692
|
+
case "Encode":
|
|
3693
|
+
return decodeWrappedInner(schema, value, refs);
|
|
3694
|
+
case "Base": {
|
|
3695
|
+
const convert = schemaCallbackField(schema, "Convert");
|
|
3696
|
+
return convert ? convert(value) : value;
|
|
3697
|
+
}
|
|
3698
|
+
default:
|
|
3699
|
+
return value;
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
// src/value/default.ts
|
|
3704
|
+
var NOT_HANDLED4 = Symbol("default.not-handled");
|
|
3705
|
+
function cloneValue3(value) {
|
|
3706
|
+
return globalThis.structuredClone(value);
|
|
3707
|
+
}
|
|
3708
|
+
function Default(schema, value) {
|
|
3709
|
+
return DefaultInternal(schema, value, new Map);
|
|
3710
|
+
}
|
|
3711
|
+
function defaultStructuredValue(s, value, refs) {
|
|
3712
|
+
const kind = s["~kind"];
|
|
3713
|
+
switch (kind) {
|
|
3714
|
+
case "Object": {
|
|
3715
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
3716
|
+
return value;
|
|
3717
|
+
const result = { ...value };
|
|
3718
|
+
const props = s["properties"];
|
|
3719
|
+
for (const [key, propSchema] of Object.entries(props)) {
|
|
3720
|
+
if (result[key] === undefined) {
|
|
3721
|
+
const propS = propSchema;
|
|
3722
|
+
if (propS["default"] !== undefined) {
|
|
3723
|
+
result[key] = cloneValue3(propS["default"]);
|
|
3724
|
+
}
|
|
3725
|
+
} else {
|
|
3726
|
+
result[key] = DefaultInternal(propSchema, result[key], refs);
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
return result;
|
|
3730
|
+
}
|
|
3731
|
+
case "Array": {
|
|
3732
|
+
if (!Array.isArray(value))
|
|
3733
|
+
return value;
|
|
3734
|
+
const itemSchema = s["items"];
|
|
3735
|
+
return value.map((item) => DefaultInternal(itemSchema, item, refs));
|
|
3736
|
+
}
|
|
3737
|
+
case "Tuple": {
|
|
3738
|
+
if (!Array.isArray(value))
|
|
3739
|
+
return value;
|
|
3740
|
+
const items = s["items"];
|
|
3741
|
+
return value.map((item, i) => items[i] ? DefaultInternal(items[i], item, refs) : item);
|
|
3742
|
+
}
|
|
3743
|
+
default:
|
|
3744
|
+
return NOT_HANDLED4;
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
function defaultCompositeValue(s, value, refs) {
|
|
3748
|
+
const kind = s["~kind"];
|
|
3749
|
+
switch (kind) {
|
|
3750
|
+
case "Optional":
|
|
3751
|
+
return value === undefined ? value : DefaultInternal(s["item"], value, refs);
|
|
3752
|
+
case "Readonly":
|
|
3753
|
+
return DefaultInternal(s["item"], value, refs);
|
|
3754
|
+
case "Intersect": {
|
|
3755
|
+
const variants = s["variants"];
|
|
3756
|
+
let result = value;
|
|
3757
|
+
for (const variant of variants) {
|
|
3758
|
+
result = DefaultInternal(variant, result, refs);
|
|
3759
|
+
}
|
|
3760
|
+
return result;
|
|
3761
|
+
}
|
|
3762
|
+
case "Union":
|
|
3763
|
+
return value;
|
|
3764
|
+
case "Recursive": {
|
|
3765
|
+
const nextRefs = new Map(refs);
|
|
3766
|
+
nextRefs.set(s["name"], s["schema"]);
|
|
3767
|
+
return DefaultInternal(s["schema"], value, nextRefs);
|
|
3768
|
+
}
|
|
3769
|
+
case "Ref": {
|
|
3770
|
+
const target = refs.get(s["name"]);
|
|
3771
|
+
return target ? DefaultInternal(target, value, refs) : value;
|
|
3772
|
+
}
|
|
3773
|
+
case "Decode":
|
|
3774
|
+
case "Encode":
|
|
3775
|
+
return DefaultInternal(s["inner"], value, refs);
|
|
3776
|
+
default:
|
|
3777
|
+
return NOT_HANDLED4;
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
function DefaultInternal(schema, value, refs) {
|
|
3781
|
+
const s = schema;
|
|
3782
|
+
if (value === undefined && s["default"] !== undefined) {
|
|
3783
|
+
return cloneValue3(s["default"]);
|
|
3784
|
+
}
|
|
3785
|
+
const structured = defaultStructuredValue(s, value, refs);
|
|
3786
|
+
if (structured !== NOT_HANDLED4) {
|
|
3787
|
+
return structured;
|
|
3788
|
+
}
|
|
3789
|
+
const composite = defaultCompositeValue(s, value, refs);
|
|
3790
|
+
return composite !== NOT_HANDLED4 ? composite : value;
|
|
3791
|
+
}
|
|
3792
|
+
|
|
3793
|
+
// src/value/encode.ts
|
|
3794
|
+
function Encode2(schema, value) {
|
|
3795
|
+
return EncodeInternal(schema, value, new Map);
|
|
3796
|
+
}
|
|
3797
|
+
function isRecord4(value) {
|
|
3798
|
+
return typeof value === "object" && value !== null;
|
|
3799
|
+
}
|
|
3800
|
+
function resolveCodec2(schema) {
|
|
3801
|
+
const codec = schemaUnknownField(schema, "codec");
|
|
3802
|
+
return isRecord4(codec) && typeof codec.encode === "function" ? codec : undefined;
|
|
3803
|
+
}
|
|
3804
|
+
function encodeObject(schema, value, refs) {
|
|
3805
|
+
if (!isRecord4(value) || Array.isArray(value))
|
|
3806
|
+
return value;
|
|
3807
|
+
const result = {};
|
|
3808
|
+
const properties = schemaProperties(schema);
|
|
3809
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
3810
|
+
const propertySchema = properties[key];
|
|
3811
|
+
result[key] = propertySchema ? EncodeInternal(propertySchema, entryValue, refs) : entryValue;
|
|
3812
|
+
}
|
|
3813
|
+
return result;
|
|
3814
|
+
}
|
|
3815
|
+
function encodeArrayItems(itemSchema, value, refs) {
|
|
3816
|
+
return Array.isArray(value) && itemSchema ? value.map((item) => EncodeInternal(itemSchema, item, refs)) : value;
|
|
3817
|
+
}
|
|
3818
|
+
function encodeTupleItems(schema, value, refs) {
|
|
3819
|
+
if (!Array.isArray(value))
|
|
3820
|
+
return value;
|
|
3821
|
+
const items = schemaSchemaListField(schema, "items");
|
|
3822
|
+
return value.map((item, index) => {
|
|
3823
|
+
const itemSchema = items[index];
|
|
3824
|
+
return itemSchema ? EncodeInternal(itemSchema, item, refs) : item;
|
|
3825
|
+
});
|
|
3826
|
+
}
|
|
3827
|
+
function encodeWrappedInner(schema, value, refs) {
|
|
3828
|
+
const inner = schemaInner(schema) ?? schemaItem(schema);
|
|
3829
|
+
return value === undefined || inner === undefined ? value : EncodeInternal(inner, value, refs);
|
|
3830
|
+
}
|
|
3831
|
+
function encodeReferenceSchema(schema, value, refs) {
|
|
3832
|
+
switch (schemaKind(schema)) {
|
|
3833
|
+
case "Call": {
|
|
3834
|
+
const instantiated = Instantiate({}, schema);
|
|
3835
|
+
return instantiated === schema ? value : EncodeInternal(instantiated, value, refs);
|
|
3836
|
+
}
|
|
3837
|
+
case "Cyclic": {
|
|
3838
|
+
const defs = schemaDefinitions(schema);
|
|
3839
|
+
const refName = schemaStringField(schema, "$ref");
|
|
3840
|
+
const nextRefs = new Map(refs);
|
|
3841
|
+
for (const [key, definition] of Object.entries(defs)) {
|
|
3842
|
+
nextRefs.set(key, definition);
|
|
3843
|
+
}
|
|
3844
|
+
const target = refName ? defs[refName] : undefined;
|
|
3845
|
+
return target === undefined ? value : EncodeInternal(target, value, nextRefs);
|
|
3846
|
+
}
|
|
3847
|
+
case "Recursive": {
|
|
3848
|
+
const name = schemaStringField(schema, "name");
|
|
3849
|
+
const target = schemaSchemaField(schema, "schema");
|
|
3850
|
+
if (!name || target === undefined)
|
|
3851
|
+
return value;
|
|
3852
|
+
const nextRefs = new Map(refs);
|
|
3853
|
+
nextRefs.set(name, target);
|
|
3854
|
+
nextRefs.set("#", target);
|
|
3855
|
+
return EncodeInternal(target, value, nextRefs);
|
|
3856
|
+
}
|
|
3857
|
+
case "Ref": {
|
|
3858
|
+
const target = refs.get(schemaStringField(schema, "name") ?? "");
|
|
3859
|
+
return target ? EncodeInternal(target, value, refs) : value;
|
|
3860
|
+
}
|
|
3861
|
+
default:
|
|
3862
|
+
return value;
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
function EncodeInternal(schema, value, refs) {
|
|
3866
|
+
switch (schemaKind(schema)) {
|
|
3867
|
+
case "Encode": {
|
|
3868
|
+
const inner = schemaInner(schema);
|
|
3869
|
+
const encode = schemaCallbackField(schema, "encode");
|
|
3870
|
+
return inner && encode ? EncodeInternal(inner, encode(value), refs) : value;
|
|
3871
|
+
}
|
|
3872
|
+
case "Codec": {
|
|
3873
|
+
const inner = schemaInner(schema);
|
|
3874
|
+
const codec = resolveCodec2(schema);
|
|
3875
|
+
return inner && codec ? EncodeInternal(inner, codec.encode(value), refs) : value;
|
|
3876
|
+
}
|
|
3877
|
+
case "Object":
|
|
3878
|
+
return encodeObject(schema, value, refs);
|
|
3879
|
+
case "Array":
|
|
3880
|
+
return encodeArrayItems(schemaSchemaField(schema, "items"), value, refs);
|
|
3881
|
+
case "Tuple":
|
|
3882
|
+
return encodeTupleItems(schema, value, refs);
|
|
3883
|
+
case "Optional":
|
|
3884
|
+
case "Readonly":
|
|
3885
|
+
case "Immutable":
|
|
3886
|
+
case "Refine":
|
|
3887
|
+
return encodeWrappedInner(schema, value, refs);
|
|
3888
|
+
case "Generic":
|
|
3889
|
+
return EncodeInternal(schemaSchemaField(schema, "expression") ?? schema, value, refs);
|
|
3890
|
+
case "Infer":
|
|
3891
|
+
return EncodeInternal(schemaSchemaField(schema, "extends") ?? schema, value, refs);
|
|
3892
|
+
case "Call":
|
|
3893
|
+
case "Cyclic":
|
|
3894
|
+
case "Recursive":
|
|
3895
|
+
case "Ref":
|
|
3896
|
+
return encodeReferenceSchema(schema, value, refs);
|
|
3897
|
+
case "Decode":
|
|
3898
|
+
return encodeWrappedInner(schema, value, refs);
|
|
3899
|
+
case "Base": {
|
|
3900
|
+
const convert = schemaCallbackField(schema, "Convert");
|
|
3901
|
+
return convert ? convert(value) : value;
|
|
3902
|
+
}
|
|
3903
|
+
default:
|
|
3904
|
+
return value;
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
// src/value/hash.ts
|
|
3909
|
+
function Hash(value) {
|
|
3910
|
+
let h = 0xcbf29ce484222325n;
|
|
3911
|
+
hashValue(value);
|
|
3912
|
+
return h;
|
|
3913
|
+
function mix(b) {
|
|
3914
|
+
h ^= b & 0xffn;
|
|
3915
|
+
h = BigInt.asUintN(64, h * 0x100000001b3n);
|
|
3916
|
+
}
|
|
3917
|
+
function hashString(s) {
|
|
3918
|
+
for (let i = 0;i < s.length; i++) {
|
|
3919
|
+
mix(BigInt(s.charCodeAt(i)));
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
function hashValue(v) {
|
|
3923
|
+
if (v === null) {
|
|
3924
|
+
mix(0n);
|
|
3925
|
+
return;
|
|
3926
|
+
}
|
|
3927
|
+
if (v === undefined) {
|
|
3928
|
+
mix(1n);
|
|
3929
|
+
return;
|
|
3930
|
+
}
|
|
3931
|
+
switch (typeof v) {
|
|
3932
|
+
case "boolean":
|
|
3933
|
+
mix(v ? 2n : 3n);
|
|
3934
|
+
return;
|
|
3935
|
+
case "number":
|
|
3936
|
+
mix(4n);
|
|
3937
|
+
hashString(v.toString());
|
|
3938
|
+
return;
|
|
3939
|
+
case "bigint":
|
|
3940
|
+
mix(5n);
|
|
3941
|
+
hashString(v.toString());
|
|
3942
|
+
return;
|
|
3943
|
+
case "string":
|
|
3944
|
+
mix(6n);
|
|
3945
|
+
hashString(v);
|
|
3946
|
+
return;
|
|
3947
|
+
case "symbol":
|
|
3948
|
+
mix(7n);
|
|
3949
|
+
hashString(v.toString());
|
|
3950
|
+
return;
|
|
3951
|
+
case "object": {
|
|
3952
|
+
if (Array.isArray(v)) {
|
|
3953
|
+
mix(8n);
|
|
3954
|
+
for (const item of v)
|
|
3955
|
+
hashValue(item);
|
|
3956
|
+
return;
|
|
3957
|
+
}
|
|
3958
|
+
if (v instanceof globalThis.Date) {
|
|
3959
|
+
mix(9n);
|
|
3960
|
+
hashString(v.toISOString());
|
|
3961
|
+
return;
|
|
3962
|
+
}
|
|
3963
|
+
if (v instanceof globalThis.Uint8Array) {
|
|
3964
|
+
mix(10n);
|
|
3965
|
+
for (const byte of v)
|
|
3966
|
+
mix(BigInt(byte));
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
mix(11n);
|
|
3970
|
+
const keys = Object.keys(v).sort();
|
|
3971
|
+
for (const key of keys) {
|
|
3972
|
+
hashString(key);
|
|
3973
|
+
hashValue(v[key]);
|
|
3974
|
+
}
|
|
3975
|
+
return;
|
|
3976
|
+
}
|
|
3977
|
+
default:
|
|
3978
|
+
mix(12n);
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
|
|
3983
|
+
// src/value/parse.ts
|
|
3984
|
+
class ParseError extends Error {
|
|
3985
|
+
errors;
|
|
3986
|
+
constructor(errors) {
|
|
3987
|
+
super(`Parse failed with ${errors.length} error(s)`);
|
|
3988
|
+
this.name = "ParseError";
|
|
3989
|
+
this.errors = errors;
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
function TryParse(schema, value, context) {
|
|
3993
|
+
let result = Clone(value);
|
|
3994
|
+
result = Default(schema, result);
|
|
3995
|
+
result = Convert(schema, result);
|
|
3996
|
+
result = Clean(schema, result);
|
|
3997
|
+
if (!Check(schema, result, context)) {
|
|
3998
|
+
return {
|
|
3999
|
+
success: false,
|
|
4000
|
+
errors: Errors(schema, result, context)
|
|
4001
|
+
};
|
|
4002
|
+
}
|
|
4003
|
+
return {
|
|
4004
|
+
success: true,
|
|
4005
|
+
value: result
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
function Parse(schema, value, context) {
|
|
4009
|
+
const result = TryParse(schema, value, context);
|
|
4010
|
+
if (!result.success) {
|
|
4011
|
+
throw new ParseError(result.errors);
|
|
4012
|
+
}
|
|
4013
|
+
return result.value;
|
|
4014
|
+
}
|
|
4015
|
+
|
|
4016
|
+
// src/value/repair.ts
|
|
4017
|
+
function Repair(schema, value, context) {
|
|
4018
|
+
const converted = Convert(schema, Clone(value));
|
|
4019
|
+
const kind = schemaKind(schema);
|
|
4020
|
+
if (Check(schema, converted, context) && kind !== "Object" && kind !== "Tuple" && kind !== "Array" && kind !== "Record") {
|
|
4021
|
+
return converted;
|
|
4022
|
+
}
|
|
4023
|
+
return repairInternal(schema, converted, new Map, context);
|
|
4024
|
+
}
|
|
4025
|
+
function repairObject(schema, value, refs) {
|
|
4026
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
4027
|
+
return Create(schema);
|
|
4028
|
+
}
|
|
4029
|
+
const optional = new Set((schema.optional ?? []).map(String));
|
|
4030
|
+
const objectValue = value;
|
|
4031
|
+
const result = {};
|
|
4032
|
+
for (const [key, propertySchema] of Object.entries(schema.properties)) {
|
|
4033
|
+
if (key in objectValue) {
|
|
4034
|
+
const propertyValue = objectValue[key];
|
|
4035
|
+
if (propertyValue === undefined && optional.has(key)) {
|
|
4036
|
+
result[key] = undefined;
|
|
4037
|
+
} else {
|
|
4038
|
+
result[key] = repairInternal(propertySchema, propertyValue, refs);
|
|
4039
|
+
}
|
|
4040
|
+
} else if (!optional.has(key)) {
|
|
4041
|
+
result[key] = Create(propertySchema);
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
if (schema.additionalProperties !== false) {
|
|
4045
|
+
for (const [key, entryValue] of Object.entries(objectValue)) {
|
|
4046
|
+
if (!(key in schema.properties))
|
|
4047
|
+
result[key] = entryValue;
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
4050
|
+
return result;
|
|
4051
|
+
}
|
|
4052
|
+
function repairArray(schema, value, refs) {
|
|
4053
|
+
if (!Array.isArray(value)) {
|
|
4054
|
+
const result2 = [];
|
|
4055
|
+
if (schema.minItems !== undefined) {
|
|
4056
|
+
for (let index = 0;index < schema.minItems; index += 1) {
|
|
4057
|
+
result2.push(Create(schema.items));
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
return result2;
|
|
4061
|
+
}
|
|
4062
|
+
const result = value.map((entry) => repairInternal(schema.items, entry, refs));
|
|
4063
|
+
if (schema.minItems !== undefined && result.length < schema.minItems) {
|
|
4064
|
+
while (result.length < schema.minItems)
|
|
4065
|
+
result.push(Create(schema.items));
|
|
4066
|
+
}
|
|
4067
|
+
if (schema.maxItems !== undefined && result.length > schema.maxItems) {
|
|
4068
|
+
result.length = schema.maxItems;
|
|
4069
|
+
}
|
|
4070
|
+
return result;
|
|
4071
|
+
}
|
|
4072
|
+
function repairTuple(schema, value, refs) {
|
|
4073
|
+
if (!Array.isArray(value))
|
|
4074
|
+
return schema.items.map((item) => Create(item));
|
|
4075
|
+
const repairedItems = schema.items.map((itemSchema, index) => index < value.length ? repairInternal(itemSchema, value[index], refs) : Create(itemSchema));
|
|
4076
|
+
if (!schema.additionalItems) {
|
|
4077
|
+
return repairedItems;
|
|
4078
|
+
}
|
|
4079
|
+
const extraItems = value.slice(schema.items.length);
|
|
4080
|
+
if (schema.maxItems === undefined) {
|
|
4081
|
+
return [...repairedItems, ...extraItems];
|
|
4082
|
+
}
|
|
4083
|
+
return [...repairedItems, ...extraItems.slice(0, Math.max(schema.maxItems - repairedItems.length, 0))];
|
|
4084
|
+
}
|
|
4085
|
+
function repairRecord(schema, value, refs) {
|
|
4086
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
4087
|
+
return {};
|
|
4088
|
+
const result = {};
|
|
4089
|
+
Object.entries(value).forEach(([key, entryValue]) => {
|
|
4090
|
+
result[key] = repairInternal(schema.value, entryValue, refs);
|
|
4091
|
+
});
|
|
4092
|
+
return result;
|
|
4093
|
+
}
|
|
4094
|
+
function repairUnion(schema, value, refs, context) {
|
|
4095
|
+
for (const variant of schema.variants) {
|
|
4096
|
+
const repaired = repairInternal(variant, value, refs, context);
|
|
4097
|
+
if (Check(variant, repaired, context))
|
|
4098
|
+
return repaired;
|
|
4099
|
+
}
|
|
4100
|
+
return schema.variants.length > 0 ? repairInternal(schema.variants[0], value, refs, context) : value;
|
|
4101
|
+
}
|
|
4102
|
+
function repairInternal(schema, value, refs, context) {
|
|
4103
|
+
switch (schemaKind(schema)) {
|
|
4104
|
+
case "Object":
|
|
4105
|
+
return repairObject(schema, value, refs);
|
|
4106
|
+
case "Array":
|
|
4107
|
+
return repairArray(schema, value, refs);
|
|
4108
|
+
case "Tuple":
|
|
4109
|
+
return repairTuple(schema, value, refs);
|
|
4110
|
+
case "Record":
|
|
4111
|
+
return repairRecord(schema, value, refs);
|
|
4112
|
+
case "Union":
|
|
4113
|
+
return repairUnion(schema, value, refs, context);
|
|
4114
|
+
case "Intersect": {
|
|
4115
|
+
let result = value;
|
|
4116
|
+
schema.variants.forEach((variant) => {
|
|
4117
|
+
result = repairInternal(variant, result, refs, context);
|
|
4118
|
+
});
|
|
4119
|
+
return result;
|
|
4120
|
+
}
|
|
4121
|
+
case "Optional":
|
|
4122
|
+
return value === undefined ? undefined : repairInternal(schema.item, value, refs, context);
|
|
4123
|
+
case "Readonly":
|
|
4124
|
+
return repairInternal(schema.item, value, refs, context);
|
|
4125
|
+
case "Recursive": {
|
|
4126
|
+
const recursiveSchema = schema;
|
|
4127
|
+
const nextRefs = new Map(refs);
|
|
4128
|
+
nextRefs.set(recursiveSchema.name, recursiveSchema.schema);
|
|
4129
|
+
return repairInternal(recursiveSchema.schema, value, nextRefs, context);
|
|
4130
|
+
}
|
|
4131
|
+
case "Ref": {
|
|
4132
|
+
const target = refs.get(schema.name);
|
|
4133
|
+
return target === undefined ? value : repairInternal(target, value, refs, context);
|
|
4134
|
+
}
|
|
4135
|
+
case "Decode":
|
|
4136
|
+
case "Encode":
|
|
4137
|
+
return repairInternal(schema.inner, value, refs, context);
|
|
4138
|
+
default:
|
|
4139
|
+
return Check(schema, value, context) ? value : Create(schema);
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4143
|
+
// src/value/result.ts
|
|
4144
|
+
function TryCreate(schema, context) {
|
|
4145
|
+
const created = Create(schema);
|
|
4146
|
+
return Check(schema, created, context) ? { success: true, value: created } : { success: false, errors: Errors(schema, created, context) };
|
|
4147
|
+
}
|
|
4148
|
+
function TryDecode(schema, value, context) {
|
|
4149
|
+
const decoded = Decode2(schema, value);
|
|
4150
|
+
const encoded = Encode2(schema, decoded);
|
|
4151
|
+
return Check(schema, encoded, context) ? { success: true, value: decoded } : { success: false, errors: Errors(schema, encoded, context) };
|
|
4152
|
+
}
|
|
4153
|
+
function TryEncode(schema, value, context) {
|
|
4154
|
+
const encoded = Encode2(schema, value);
|
|
4155
|
+
return Check(schema, encoded, context) ? { success: true, value: encoded } : { success: false, errors: Errors(schema, encoded, context) };
|
|
4156
|
+
}
|
|
4157
|
+
function TryRepair(schema, value, context) {
|
|
4158
|
+
const repaired = Repair(schema, value, context);
|
|
4159
|
+
return Check(schema, repaired, context) ? { success: true, value: repaired } : { success: false, errors: Errors(schema, repaired, context) };
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
// src/compile/bun-fast-path.ts
|
|
4163
|
+
function mergeStrategy(...strategies) {
|
|
4164
|
+
return strategies.includes("bun-ffi") ? "bun-ffi" : "bun-native";
|
|
4165
|
+
}
|
|
4166
|
+
function containsBinaryPath(schema) {
|
|
4167
|
+
switch (schemaKind(schema)) {
|
|
4168
|
+
case "Uint8Array":
|
|
4169
|
+
return true;
|
|
4170
|
+
case "String":
|
|
4171
|
+
return schemaStringField(schema, "format") === "base64" || schemaStringField(schema, "format") === "uint8array";
|
|
4172
|
+
case "Array":
|
|
4173
|
+
return containsBinaryPath(schemaSchemaField(schema, "items") ?? schemaItem(schema) ?? schema);
|
|
4174
|
+
case "Tuple":
|
|
4175
|
+
return schemaSchemaListField(schema, "items").some(containsBinaryPath);
|
|
4176
|
+
case "Object":
|
|
4177
|
+
return Object.values(schemaProperties(schema)).some(containsBinaryPath);
|
|
4178
|
+
case "Optional":
|
|
4179
|
+
case "Readonly":
|
|
4180
|
+
case "Immutable":
|
|
4181
|
+
case "Codec":
|
|
4182
|
+
case "Decode":
|
|
4183
|
+
case "Encode":
|
|
4184
|
+
case "Refine":
|
|
4185
|
+
return containsBinaryPath(schemaItemOrInner(schema) ?? schema);
|
|
4186
|
+
case "Union":
|
|
4187
|
+
case "Intersect":
|
|
4188
|
+
return schemaVariants(schema).some(containsBinaryPath);
|
|
4189
|
+
default:
|
|
4190
|
+
return false;
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
function compilePrimitivePlan(schema, context) {
|
|
4194
|
+
const current = schemaUnknownField(schema, "~kind");
|
|
4195
|
+
switch (typeof current === "string" ? current : undefined) {
|
|
4196
|
+
case "String":
|
|
4197
|
+
return {
|
|
4198
|
+
fn: (value) => typeof value === "string" && checkStringConstraints(schema, value, context),
|
|
4199
|
+
strategy: "bun-native"
|
|
4200
|
+
};
|
|
4201
|
+
case "Number":
|
|
4202
|
+
return {
|
|
4203
|
+
fn: (value) => typeof value === "number" && (context.TypeSystemPolicy.Get().AllowNaN || Number.isFinite(value)) && checkNumberConstraints(schema, value),
|
|
4204
|
+
strategy: "bun-native"
|
|
4205
|
+
};
|
|
4206
|
+
case "Integer":
|
|
4207
|
+
return {
|
|
4208
|
+
fn: (value) => typeof value === "number" && Number.isInteger(value) && checkNumberConstraints(schema, value),
|
|
4209
|
+
strategy: "bun-native"
|
|
4210
|
+
};
|
|
4211
|
+
case "Boolean":
|
|
4212
|
+
return { fn: (value) => typeof value === "boolean", strategy: "bun-native" };
|
|
4213
|
+
case "Null":
|
|
4214
|
+
return { fn: (value) => value === null, strategy: "bun-native" };
|
|
4215
|
+
case "Literal":
|
|
4216
|
+
return { fn: (value) => value === schemaUnknownField(schema, "const"), strategy: "bun-native" };
|
|
4217
|
+
case "Unknown":
|
|
4218
|
+
case "Any":
|
|
4219
|
+
case "Unsafe":
|
|
4220
|
+
return { fn: () => true, strategy: "bun-native" };
|
|
4221
|
+
case "Never":
|
|
4222
|
+
return { fn: () => false, strategy: "bun-native" };
|
|
4223
|
+
case "Uint8Array": {
|
|
4224
|
+
const expected = schemaUnknownField(schema, "constBytes");
|
|
4225
|
+
const constBytes = expected instanceof Uint8Array ? expected : undefined;
|
|
4226
|
+
const minByteLength = typeof schemaUnknownField(schema, "minByteLength") === "number" ? schemaUnknownField(schema, "minByteLength") : undefined;
|
|
4227
|
+
const maxByteLength = typeof schemaUnknownField(schema, "maxByteLength") === "number" ? schemaUnknownField(schema, "maxByteLength") : undefined;
|
|
4228
|
+
return {
|
|
4229
|
+
fn: (value) => value instanceof Uint8Array && isUint8ArrayWithinBounds(value, minByteLength, maxByteLength) && (constBytes === undefined || areUint8ArraysEqual(value, constBytes)),
|
|
4230
|
+
strategy: constBytes === undefined ? "bun-native" : "bun-ffi"
|
|
4231
|
+
};
|
|
4232
|
+
}
|
|
4233
|
+
default:
|
|
4234
|
+
return null;
|
|
4235
|
+
}
|
|
4236
|
+
}
|
|
4237
|
+
function compileCollectionPlan(schema, context) {
|
|
4238
|
+
switch (schemaKind(schema)) {
|
|
4239
|
+
case "Array": {
|
|
4240
|
+
const itemPlan = compilePlan(schemaItem(schema) ?? schema, context);
|
|
4241
|
+
if (itemPlan === null)
|
|
4242
|
+
return null;
|
|
4243
|
+
return {
|
|
4244
|
+
fn: (value) => Array.isArray(value) && value.every(itemPlan.fn),
|
|
4245
|
+
strategy: itemPlan.strategy
|
|
4246
|
+
};
|
|
4247
|
+
}
|
|
4248
|
+
case "Tuple": {
|
|
4249
|
+
const itemPlans = schemaSchemaListField(schema, "items").map((entry) => compilePlan(entry, context));
|
|
4250
|
+
if (itemPlans.some((plan) => plan === null))
|
|
4251
|
+
return null;
|
|
4252
|
+
const tuplePlans = itemPlans;
|
|
4253
|
+
const minItems = schemaNumberField(schema, "minItems");
|
|
4254
|
+
const maxItems = schemaNumberField(schema, "maxItems");
|
|
4255
|
+
const additionalItems = schemaBooleanField(schema, "additionalItems");
|
|
4256
|
+
return {
|
|
4257
|
+
fn: (value) => Array.isArray(value) && (minItems === undefined || value.length >= minItems) && (maxItems === undefined || value.length <= maxItems) && value.length >= tuplePlans.length && (additionalItems === true || value.length === tuplePlans.length) && tuplePlans.every((plan, index) => plan.fn(value[index])),
|
|
4258
|
+
strategy: mergeStrategy(...tuplePlans.map((plan) => plan.strategy))
|
|
4259
|
+
};
|
|
4260
|
+
}
|
|
4261
|
+
case "Object": {
|
|
4262
|
+
const additionalProperties = schemaBooleanOrSchemaField(schema, "additionalProperties");
|
|
4263
|
+
if (Object.keys(schemaPatternProperties(schema)).length > 0 || typeof additionalProperties === "object") {
|
|
4264
|
+
return null;
|
|
4265
|
+
}
|
|
4266
|
+
const properties = schemaProperties(schema);
|
|
4267
|
+
if (Object.keys(schemaProperties(schema)).length === 0 && schemaUnknownField(schema, "properties") === undefined) {
|
|
4268
|
+
return null;
|
|
4269
|
+
}
|
|
4270
|
+
const propertyEntries = Object.entries(properties).map(([key, propertySchema]) => [key, compilePlan(propertySchema, context)]);
|
|
4271
|
+
if (propertyEntries.some(([, plan]) => plan === null))
|
|
4272
|
+
return null;
|
|
4273
|
+
const propertyPlans = new Map(propertyEntries);
|
|
4274
|
+
const required = new Set(schemaRequiredKeys(schema).length > 0 ? schemaRequiredKeys(schema) : Object.keys(properties));
|
|
4275
|
+
const optional = new Set(schemaOptionalKeys(schema));
|
|
4276
|
+
return {
|
|
4277
|
+
fn: (value) => {
|
|
4278
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
4279
|
+
return false;
|
|
4280
|
+
const objectValue = value;
|
|
4281
|
+
for (const key of required) {
|
|
4282
|
+
if (!optional.has(key) && !(key in objectValue))
|
|
4283
|
+
return false;
|
|
4284
|
+
}
|
|
4285
|
+
for (const [key, propertyValue] of Object.entries(objectValue)) {
|
|
4286
|
+
const propertyPlan = propertyPlans.get(key);
|
|
4287
|
+
if (propertyPlan === undefined) {
|
|
4288
|
+
if (additionalProperties === false)
|
|
4289
|
+
return false;
|
|
4290
|
+
continue;
|
|
4291
|
+
}
|
|
4292
|
+
if (!propertyPlan.fn(propertyValue))
|
|
4293
|
+
return false;
|
|
4294
|
+
}
|
|
4295
|
+
return true;
|
|
4296
|
+
},
|
|
4297
|
+
strategy: mergeStrategy(...Array.from(propertyPlans.values(), (plan) => plan.strategy))
|
|
4298
|
+
};
|
|
4299
|
+
}
|
|
4300
|
+
case "Union": {
|
|
4301
|
+
const variantPlans = schemaVariants(schema).map((entry) => compilePlan(entry, context));
|
|
4302
|
+
if (variantPlans.some((plan) => plan === null))
|
|
4303
|
+
return null;
|
|
4304
|
+
const plans = variantPlans;
|
|
4305
|
+
return {
|
|
4306
|
+
fn: (value) => plans.some((plan) => plan.fn(value)),
|
|
4307
|
+
strategy: mergeStrategy(...plans.map((plan) => plan.strategy))
|
|
4308
|
+
};
|
|
4309
|
+
}
|
|
4310
|
+
case "Intersect": {
|
|
4311
|
+
const variantPlans = schemaVariants(schema).map((entry) => compilePlan(entry, context));
|
|
4312
|
+
if (variantPlans.some((plan) => plan === null))
|
|
4313
|
+
return null;
|
|
4314
|
+
const plans = variantPlans;
|
|
4315
|
+
return {
|
|
4316
|
+
fn: (value) => plans.every((plan) => plan.fn(value)),
|
|
4317
|
+
strategy: mergeStrategy(...plans.map((plan) => plan.strategy))
|
|
4318
|
+
};
|
|
4319
|
+
}
|
|
4320
|
+
default:
|
|
4321
|
+
return null;
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
function compileWrapperPlan(schema, context) {
|
|
4325
|
+
switch (schemaKind(schema)) {
|
|
4326
|
+
case "Optional":
|
|
4327
|
+
case "Readonly":
|
|
4328
|
+
case "Immutable":
|
|
4329
|
+
case "Codec":
|
|
4330
|
+
case "Decode":
|
|
4331
|
+
case "Encode": {
|
|
4332
|
+
const innerPlan = compilePlan(schemaItemOrInner(schema) ?? schema, context);
|
|
4333
|
+
if (innerPlan === null)
|
|
4334
|
+
return null;
|
|
4335
|
+
return {
|
|
4336
|
+
fn: (value) => schemaKind(schema) === "Optional" && value === undefined ? true : innerPlan.fn(value),
|
|
4337
|
+
strategy: innerPlan.strategy
|
|
4338
|
+
};
|
|
4339
|
+
}
|
|
4340
|
+
case "Refine": {
|
|
4341
|
+
if (schemaUnknownField(schema, "~uint8arrayCodec") === true) {
|
|
4342
|
+
const minByteLength = typeof schemaUnknownField(schema, "minByteLength") === "number" ? schemaUnknownField(schema, "minByteLength") : undefined;
|
|
4343
|
+
const maxByteLength = typeof schemaUnknownField(schema, "maxByteLength") === "number" ? schemaUnknownField(schema, "maxByteLength") : undefined;
|
|
4344
|
+
const constBytes = schemaUnknownField(schema, "constBytes");
|
|
4345
|
+
const normalizedBytes = constBytes instanceof Uint8Array ? constBytes : undefined;
|
|
4346
|
+
const constBase64 = schemaStringField(schema, "constBase64");
|
|
4347
|
+
if (constBase64 !== undefined) {
|
|
4348
|
+
return {
|
|
4349
|
+
fn: (value) => typeof value === "string" && value === constBase64,
|
|
4350
|
+
strategy: "bun-native-const"
|
|
4351
|
+
};
|
|
4352
|
+
}
|
|
4353
|
+
return {
|
|
4354
|
+
fn: (value) => isUint8ArrayBase64String(value, minByteLength, maxByteLength, normalizedBytes, constBase64),
|
|
4355
|
+
strategy: "bun-native"
|
|
4356
|
+
};
|
|
4357
|
+
}
|
|
4358
|
+
const itemPlan = compilePlan(schemaItem(schema) ?? schema, context);
|
|
4359
|
+
const refinementsValue = schemaUnknownField(schema, "~refine");
|
|
4360
|
+
const refinements = Array.isArray(refinementsValue) ? refinementsValue.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.refine === "function") : undefined;
|
|
4361
|
+
if (itemPlan === null || refinements === undefined)
|
|
4362
|
+
return null;
|
|
4363
|
+
return {
|
|
4364
|
+
fn: (value) => itemPlan.fn(value) && refinements.every((entry) => entry.refine(value)),
|
|
4365
|
+
strategy: schemaUnknownField(schema, "constBytes") instanceof Uint8Array ? "bun-ffi" : itemPlan.strategy
|
|
4366
|
+
};
|
|
4367
|
+
}
|
|
4368
|
+
default:
|
|
4369
|
+
return null;
|
|
4370
|
+
}
|
|
4371
|
+
}
|
|
4372
|
+
function compilePlan(schema, context) {
|
|
4373
|
+
return compilePrimitivePlan(schema, context) ?? compileCollectionPlan(schema, context) ?? compileWrapperPlan(schema, context);
|
|
4374
|
+
}
|
|
4375
|
+
function compileBunFastPath(schema, context) {
|
|
4376
|
+
if (!containsBinaryPath(schema)) {
|
|
4377
|
+
return null;
|
|
4378
|
+
}
|
|
4379
|
+
const plan = compilePlan(schema, context);
|
|
4380
|
+
if (plan === null) {
|
|
4381
|
+
return null;
|
|
4382
|
+
}
|
|
4383
|
+
return {
|
|
4384
|
+
fn: plan.fn,
|
|
4385
|
+
code: `/* ${plan.strategy} binary validation path */`,
|
|
4386
|
+
accelerated: true,
|
|
4387
|
+
strategy: plan.strategy
|
|
4388
|
+
};
|
|
4389
|
+
}
|
|
4390
|
+
|
|
4391
|
+
// src/compile/emit.ts
|
|
4392
|
+
function emitStringCheck(schema, valueExpr) {
|
|
4393
|
+
const checks = [`typeof ${valueExpr} === 'string'`];
|
|
4394
|
+
if (schema.minLength !== undefined)
|
|
4395
|
+
checks.push(`${valueExpr}.length >= ${schema.minLength}`);
|
|
4396
|
+
if (schema.maxLength !== undefined)
|
|
4397
|
+
checks.push(`${valueExpr}.length <= ${schema.maxLength}`);
|
|
4398
|
+
if (schema.pattern !== undefined)
|
|
4399
|
+
checks.push(`/${schema.pattern}/.test(${valueExpr})`);
|
|
4400
|
+
if (schema.format !== undefined)
|
|
4401
|
+
checks.push(`__validateFormat(${valueExpr}, ${JSON.stringify(schema.format)})`);
|
|
4402
|
+
return checks.join(" && ");
|
|
4403
|
+
}
|
|
4404
|
+
function emitNumberCheck(schema, valueExpr) {
|
|
4405
|
+
const checks = [`typeof ${valueExpr} === 'number'`, `(__policy.AllowNaN || Number.isFinite(${valueExpr}))`];
|
|
4406
|
+
if (schema.minimum !== undefined)
|
|
4407
|
+
checks.push(`${valueExpr} >= ${schema.minimum}`);
|
|
4408
|
+
if (schema.maximum !== undefined)
|
|
4409
|
+
checks.push(`${valueExpr} <= ${schema.maximum}`);
|
|
4410
|
+
if (schema.exclusiveMinimum !== undefined)
|
|
4411
|
+
checks.push(`${valueExpr} > ${schema.exclusiveMinimum}`);
|
|
4412
|
+
if (schema.exclusiveMaximum !== undefined)
|
|
4413
|
+
checks.push(`${valueExpr} < ${schema.exclusiveMaximum}`);
|
|
4414
|
+
if (schema.multipleOf !== undefined)
|
|
4415
|
+
checks.push(`${valueExpr} % ${schema.multipleOf} === 0`);
|
|
4416
|
+
return checks.join(" && ");
|
|
4417
|
+
}
|
|
4418
|
+
function emitIntegerCheck(schema, valueExpr) {
|
|
4419
|
+
const checks = [`typeof ${valueExpr} === 'number'`, `Number.isInteger(${valueExpr})`];
|
|
4420
|
+
if (schema.minimum !== undefined)
|
|
4421
|
+
checks.push(`${valueExpr} >= ${schema.minimum}`);
|
|
4422
|
+
if (schema.maximum !== undefined)
|
|
4423
|
+
checks.push(`${valueExpr} <= ${schema.maximum}`);
|
|
4424
|
+
return checks.join(" && ");
|
|
4425
|
+
}
|
|
4426
|
+
function emitLiteralCheck(schema, valueExpr) {
|
|
4427
|
+
return `${valueExpr} === ${JSON.stringify(schema.const)}`;
|
|
4428
|
+
}
|
|
4429
|
+
function emitArrayCheck(schema, valueExpr, emitSchema, nextVar) {
|
|
4430
|
+
const itemVar = nextVar();
|
|
4431
|
+
const checks = [`Array.isArray(${valueExpr})`];
|
|
4432
|
+
if (schema.minItems !== undefined)
|
|
4433
|
+
checks.push(`${valueExpr}.length >= ${schema.minItems}`);
|
|
4434
|
+
if (schema.maxItems !== undefined)
|
|
4435
|
+
checks.push(`${valueExpr}.length <= ${schema.maxItems}`);
|
|
4436
|
+
checks.push(`${valueExpr}.every(${itemVar} => ${emitSchema(schema.items, itemVar)})`);
|
|
4437
|
+
return checks.join(" && ");
|
|
4438
|
+
}
|
|
4439
|
+
function emitObjectCheck(schema, valueExpr, emitSchema) {
|
|
4440
|
+
const checks = [
|
|
4441
|
+
`typeof ${valueExpr} === 'object'`,
|
|
4442
|
+
`${valueExpr} !== null`,
|
|
4443
|
+
`!Array.isArray(${valueExpr})`
|
|
4444
|
+
];
|
|
4445
|
+
const required = schema.required ?? Object.keys(schema.properties);
|
|
4446
|
+
const optional = new Set((schema.optional ?? []).map(String));
|
|
4447
|
+
for (const key of required) {
|
|
4448
|
+
if (schema.properties[key] !== undefined && !optional.has(String(key))) {
|
|
4449
|
+
checks.push(`'${String(key)}' in ${valueExpr}`);
|
|
4450
|
+
checks.push(emitSchema(schema.properties[key], `${valueExpr}['${String(key)}']`));
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
return checks.join(" && ");
|
|
4454
|
+
}
|
|
4455
|
+
function emitVariantCheck(schema, valueExpr, emitSchema, operator) {
|
|
4456
|
+
return schema.variants.map((variant) => `(${emitSchema(variant, valueExpr)})`).join(` ${operator} `);
|
|
4457
|
+
}
|
|
4458
|
+
function emitEnumCheck(schema, valueExpr) {
|
|
4459
|
+
return `[${schema.values.map((value) => JSON.stringify(value)).join(",")}].includes(${valueExpr})`;
|
|
4460
|
+
}
|
|
4461
|
+
function emitUint8ArrayCheck(schema, valueExpr) {
|
|
4462
|
+
return [
|
|
4463
|
+
`${valueExpr} instanceof Uint8Array`,
|
|
4464
|
+
schema.minByteLength !== undefined ? `${valueExpr}.byteLength >= ${schema.minByteLength}` : "true",
|
|
4465
|
+
schema.maxByteLength !== undefined ? `${valueExpr}.byteLength <= ${schema.maxByteLength}` : "true"
|
|
4466
|
+
].join(" && ");
|
|
4467
|
+
}
|
|
4468
|
+
function emitPrimitiveSchemaCheck(currentSchema, valueExpr) {
|
|
4469
|
+
switch (schemaKind(currentSchema)) {
|
|
4470
|
+
case "String":
|
|
4471
|
+
return emitStringCheck(currentSchema, valueExpr);
|
|
4472
|
+
case "Number":
|
|
4473
|
+
return emitNumberCheck(currentSchema, valueExpr);
|
|
4474
|
+
case "Integer":
|
|
4475
|
+
return emitIntegerCheck(currentSchema, valueExpr);
|
|
4476
|
+
case "Boolean":
|
|
4477
|
+
return `typeof ${valueExpr} === 'boolean'`;
|
|
4478
|
+
case "Null":
|
|
4479
|
+
return `${valueExpr} === null`;
|
|
4480
|
+
case "BigInt":
|
|
4481
|
+
return `typeof ${valueExpr} === 'bigint'`;
|
|
4482
|
+
case "Date":
|
|
4483
|
+
return `${valueExpr} instanceof Date && !isNaN(${valueExpr}.getTime())`;
|
|
4484
|
+
case "Literal":
|
|
4485
|
+
return emitLiteralCheck(currentSchema, valueExpr);
|
|
4486
|
+
case "Void":
|
|
4487
|
+
return `${valueExpr} === undefined || ${valueExpr} === null`;
|
|
4488
|
+
case "Undefined":
|
|
4489
|
+
return `${valueExpr} === undefined`;
|
|
4490
|
+
case "Unknown":
|
|
4491
|
+
case "Any":
|
|
4492
|
+
return "true";
|
|
4493
|
+
case "Never":
|
|
4494
|
+
return "false";
|
|
4495
|
+
case "Symbol":
|
|
4496
|
+
return `typeof ${valueExpr} === 'symbol'`;
|
|
4497
|
+
case "Function":
|
|
4498
|
+
return `typeof ${valueExpr} === 'function'`;
|
|
4499
|
+
case "Uint8Array":
|
|
4500
|
+
return emitUint8ArrayCheck(currentSchema, valueExpr);
|
|
4501
|
+
default:
|
|
4502
|
+
return;
|
|
4503
|
+
}
|
|
4504
|
+
}
|
|
4505
|
+
function emitStructuredSchemaCheck(currentSchema, valueExpr, emitSchema, nextVar) {
|
|
4506
|
+
switch (schemaKind(currentSchema)) {
|
|
4507
|
+
case "Array":
|
|
4508
|
+
return emitArrayCheck(currentSchema, valueExpr, emitSchema, nextVar);
|
|
4509
|
+
case "Object":
|
|
4510
|
+
return emitObjectCheck(currentSchema, valueExpr, emitSchema);
|
|
4511
|
+
case "Union":
|
|
4512
|
+
return emitVariantCheck(currentSchema, valueExpr, emitSchema, "||");
|
|
4513
|
+
case "Intersect":
|
|
4514
|
+
return emitVariantCheck(currentSchema, valueExpr, emitSchema, "&&");
|
|
4515
|
+
case "Optional": {
|
|
4516
|
+
const item = schemaItem(currentSchema);
|
|
4517
|
+
return `${valueExpr} === undefined || (${emitSchema(item ?? currentSchema, valueExpr)})`;
|
|
4518
|
+
}
|
|
4519
|
+
case "Readonly":
|
|
4520
|
+
return emitSchema(schemaItem(currentSchema) ?? currentSchema, valueExpr);
|
|
4521
|
+
case "Enum":
|
|
4522
|
+
return emitEnumCheck(currentSchema, valueExpr);
|
|
4523
|
+
default:
|
|
4524
|
+
return;
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
|
|
4528
|
+
// src/compile/index.ts
|
|
4529
|
+
var validatorCaches = new WeakMap;
|
|
4530
|
+
function getValidatorCache(context) {
|
|
4531
|
+
const existing = validatorCaches.get(context);
|
|
4532
|
+
if (existing !== undefined) {
|
|
4533
|
+
return existing;
|
|
4534
|
+
}
|
|
4535
|
+
const created = new Map;
|
|
4536
|
+
validatorCaches.set(context, created);
|
|
4537
|
+
return created;
|
|
4538
|
+
}
|
|
4539
|
+
function createCompiledFunction(body) {
|
|
4540
|
+
return new Function("value", "__check", "__validateFormat", "__policy", body);
|
|
4541
|
+
}
|
|
4542
|
+
function createPortableArtifact(schema) {
|
|
4543
|
+
let varCounter = 0;
|
|
4544
|
+
function nextVar() {
|
|
4545
|
+
return `v${varCounter++}`;
|
|
4546
|
+
}
|
|
4547
|
+
function emit(currentSchema, valueExpr) {
|
|
4548
|
+
return emitPrimitiveSchemaCheck(currentSchema, valueExpr) ?? emitStructuredSchemaCheck(currentSchema, valueExpr, emit, nextVar) ?? `__check(${valueExpr})`;
|
|
4549
|
+
}
|
|
4550
|
+
const body = `return ${emit(schema, "value")};`;
|
|
4551
|
+
return {
|
|
4552
|
+
body,
|
|
4553
|
+
code: `(function(value, __check, __validateFormat, __policy) { ${body} })`
|
|
4554
|
+
};
|
|
4555
|
+
}
|
|
4556
|
+
function compileFromBody(schema, context, body, code, strategy) {
|
|
4557
|
+
const compiled = createCompiledFunction(body);
|
|
4558
|
+
const fallbackCheck = (value) => Check(schema, value, context);
|
|
4559
|
+
const runtimeValidateFormat = (value, format) => validateFormat(value, format, context);
|
|
4560
|
+
return {
|
|
4561
|
+
accelerated: true,
|
|
4562
|
+
body,
|
|
4563
|
+
code,
|
|
4564
|
+
fn: (value) => compiled(value, fallbackCheck, runtimeValidateFormat, context.TypeSystemPolicy.Get()),
|
|
4565
|
+
strategy
|
|
4566
|
+
};
|
|
4567
|
+
}
|
|
4568
|
+
function compileSchema(schema, context) {
|
|
4569
|
+
const artifact = createPortableArtifact(schema);
|
|
4570
|
+
return compileFromBody(schema, context, artifact.body, artifact.code, "jit");
|
|
4571
|
+
}
|
|
4572
|
+
function schemaHash(schema) {
|
|
4573
|
+
return Hash(schema).toString(16);
|
|
4574
|
+
}
|
|
4575
|
+
function resolveCompileOptions(options) {
|
|
4576
|
+
if (options instanceof RuntimeContext) {
|
|
4577
|
+
return {
|
|
4578
|
+
artifact: undefined,
|
|
4579
|
+
cache: true,
|
|
4580
|
+
context: resolveRuntimeContext(options)
|
|
4581
|
+
};
|
|
4582
|
+
}
|
|
4583
|
+
return {
|
|
4584
|
+
artifact: options?.artifact,
|
|
4585
|
+
cache: options?.cache ?? true,
|
|
4586
|
+
context: resolveRuntimeContext(options?.context)
|
|
4587
|
+
};
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
class Validator {
|
|
4591
|
+
schema;
|
|
4592
|
+
context;
|
|
4593
|
+
hash;
|
|
4594
|
+
artifact;
|
|
4595
|
+
result;
|
|
4596
|
+
constructor(schema, context, hash, artifact, result) {
|
|
4597
|
+
this.schema = schema;
|
|
4598
|
+
this.context = context;
|
|
4599
|
+
this.hash = hash;
|
|
4600
|
+
this.artifact = artifact;
|
|
4601
|
+
this.result = result;
|
|
4602
|
+
}
|
|
4603
|
+
Artifact() {
|
|
4604
|
+
return this.artifact;
|
|
4605
|
+
}
|
|
4606
|
+
Check(value) {
|
|
4607
|
+
return this.result.fn(value);
|
|
4608
|
+
}
|
|
4609
|
+
Clean(value) {
|
|
4610
|
+
return Clean(this.schema, value);
|
|
4611
|
+
}
|
|
4612
|
+
Code() {
|
|
4613
|
+
return this.result.code;
|
|
4614
|
+
}
|
|
4615
|
+
Context() {
|
|
4616
|
+
return this.context;
|
|
4617
|
+
}
|
|
4618
|
+
Convert(value) {
|
|
4619
|
+
return Convert(this.schema, value);
|
|
4620
|
+
}
|
|
4621
|
+
Create() {
|
|
4622
|
+
return Create(this.schema);
|
|
4623
|
+
}
|
|
4624
|
+
Decode(value) {
|
|
4625
|
+
return Decode2(this.schema, value);
|
|
4626
|
+
}
|
|
4627
|
+
Default(value) {
|
|
4628
|
+
return Default(this.schema, value);
|
|
4629
|
+
}
|
|
4630
|
+
Encode(value) {
|
|
4631
|
+
return Encode2(this.schema, value);
|
|
4632
|
+
}
|
|
4633
|
+
Errors(value) {
|
|
4634
|
+
return Errors(this.schema, value, this.context);
|
|
4635
|
+
}
|
|
4636
|
+
Explain(value) {
|
|
4637
|
+
return Explain(this.schema, value, this.context);
|
|
4638
|
+
}
|
|
4639
|
+
Hash() {
|
|
4640
|
+
return this.hash;
|
|
4641
|
+
}
|
|
4642
|
+
IsAccelerated() {
|
|
4643
|
+
return this.result.accelerated;
|
|
4644
|
+
}
|
|
4645
|
+
Parse(value) {
|
|
4646
|
+
return Parse(this.schema, value, this.context);
|
|
4647
|
+
}
|
|
4648
|
+
Repair(value) {
|
|
4649
|
+
return Repair(this.schema, value, this.context);
|
|
4650
|
+
}
|
|
4651
|
+
Strategy() {
|
|
4652
|
+
return this.result.strategy;
|
|
4653
|
+
}
|
|
4654
|
+
TryCreate() {
|
|
4655
|
+
return TryCreate(this.schema, this.context);
|
|
4656
|
+
}
|
|
4657
|
+
TryDecode(value) {
|
|
4658
|
+
return TryDecode(this.schema, value, this.context);
|
|
4659
|
+
}
|
|
4660
|
+
TryEncode(value) {
|
|
4661
|
+
return TryEncode(this.schema, value, this.context);
|
|
4662
|
+
}
|
|
4663
|
+
TryParse(value) {
|
|
4664
|
+
return TryParse(this.schema, value, this.context);
|
|
4665
|
+
}
|
|
4666
|
+
TryRepair(value) {
|
|
4667
|
+
return TryRepair(this.schema, value, this.context);
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
function Compile(schema, options) {
|
|
4671
|
+
const resolved = resolveCompileOptions(options);
|
|
4672
|
+
const hash = schemaHash(schema);
|
|
4673
|
+
const artifact = resolved.artifact;
|
|
4674
|
+
const cacheKey = [
|
|
4675
|
+
resolved.context.CacheKey("compile"),
|
|
4676
|
+
hash,
|
|
4677
|
+
artifact?.hash ?? "live"
|
|
4678
|
+
].join(":");
|
|
4679
|
+
if (resolved.cache) {
|
|
4680
|
+
const cache = getValidatorCache(resolved.context);
|
|
4681
|
+
const cached = cache.get(cacheKey);
|
|
4682
|
+
if (cached !== undefined) {
|
|
4683
|
+
return cached;
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
const portable = createPortableArtifact(schema);
|
|
4687
|
+
const artifactValue = {
|
|
4688
|
+
...portable,
|
|
4689
|
+
hash
|
|
4690
|
+
};
|
|
4691
|
+
const fastPath = compileBunFastPath(schema, resolved.context);
|
|
4692
|
+
const compileResult = artifact !== undefined && artifact.hash === hash ? compileFromBody(schema, resolved.context, artifact.body, artifact.code, "artifact") : fastPath !== null ? { ...fastPath, body: portable.body } : compileSchema(schema, resolved.context);
|
|
4693
|
+
const validator = new Validator(schema, resolved.context, hash, artifactValue, compileResult);
|
|
4694
|
+
if (resolved.cache) {
|
|
4695
|
+
getValidatorCache(resolved.context).set(cacheKey, validator);
|
|
4696
|
+
}
|
|
4697
|
+
return validator;
|
|
4698
|
+
}
|
|
4699
|
+
function Code(schema, options) {
|
|
4700
|
+
return options === undefined ? Compile(schema).Code() : Compile(schema, options).Code();
|
|
4701
|
+
}
|
|
4702
|
+
var compile_default = Compile;
|
|
4703
|
+
export {
|
|
4704
|
+
compile_default as default,
|
|
4705
|
+
Validator,
|
|
4706
|
+
Compile,
|
|
4707
|
+
Code
|
|
4708
|
+
};
|
|
4709
|
+
|
|
4710
|
+
//# debugId=4D751EE28C800EEA64756E2164756E21
|
|
4711
|
+
//# sourceMappingURL=index.js.map
|