arktype 3.0.0-beta.1 → 3.0.0-rc.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 +48 -144
- package/out/_internal/regex/charset.d.ts +24 -0
- package/out/_internal/regex/escape.d.ts +29 -0
- package/out/_internal/regex/execArray.d.ts +24 -0
- package/out/_internal/regex/group.d.ts +34 -0
- package/out/_internal/regex/index.d.ts +2 -0
- package/out/_internal/regex/internal.d.ts +9 -0
- package/out/_internal/regex/parse.d.ts +10 -0
- package/out/_internal/regex/quantify.d.ts +59 -0
- package/out/_internal/regex/regex.d.ts +38 -0
- package/out/_internal/regex/state.d.ts +383 -0
- package/out/_internal/schema/codecs.d.ts +2 -0
- package/out/_internal/schema/config.d.ts +103 -0
- package/out/_internal/schema/constraint.d.ts +78 -0
- package/out/_internal/schema/errors.d.ts +1 -0
- package/out/_internal/schema/generic.d.ts +85 -0
- package/out/_internal/schema/i18n.d.ts +3 -0
- package/out/_internal/schema/index.d.ts +54 -0
- package/out/_internal/schema/internal.d.ts +15 -0
- package/out/_internal/schema/intrinsic.d.ts +28 -0
- package/out/_internal/schema/kinds.d.ts +76 -0
- package/out/_internal/schema/module.d.ts +23 -0
- package/out/_internal/schema/mutatesInput.d.ts +2 -0
- package/out/_internal/schema/node.d.ts +349 -0
- package/out/_internal/schema/parse.d.ts +77 -0
- package/out/_internal/schema/parseSchema.d.ts +116 -0
- package/out/_internal/schema/predicate.d.ts +46 -0
- package/out/_internal/schema/refinements/after.d.ts +32 -0
- package/out/_internal/schema/refinements/before.d.ts +32 -0
- package/out/_internal/schema/refinements/divisor.d.ts +41 -0
- package/out/_internal/schema/refinements/exactLength.d.ts +43 -0
- package/out/_internal/schema/refinements/kinds.d.ts +40 -0
- package/out/_internal/schema/refinements/max.d.ts +33 -0
- package/out/_internal/schema/refinements/maxLength.d.ts +32 -0
- package/out/_internal/schema/refinements/min.d.ts +33 -0
- package/out/_internal/schema/refinements/minLength.d.ts +32 -0
- package/out/_internal/schema/refinements/notEqual.d.ts +38 -0
- package/out/_internal/schema/refinements/notEqualLength.d.ts +38 -0
- package/out/_internal/schema/refinements/pattern.d.ts +43 -0
- package/out/_internal/schema/refinements/range.d.ts +101 -0
- package/out/_internal/schema/roots/alias.d.ts +49 -0
- package/out/_internal/schema/roots/basis.d.ts +12 -0
- package/out/_internal/schema/roots/domain.d.ts +45 -0
- package/out/_internal/schema/roots/intersection.d.ts +72 -0
- package/out/_internal/schema/roots/morph.d.ts +59 -0
- package/out/_internal/schema/roots/proto.d.ts +42 -0
- package/out/_internal/schema/roots/root.d.ts +163 -0
- package/out/_internal/schema/roots/union.d.ts +146 -0
- package/out/_internal/schema/roots/unit.d.ts +36 -0
- package/out/_internal/schema/runtime.d.ts +29 -0
- package/out/_internal/schema/runtimeLean.d.ts +2 -0
- package/out/_internal/schema/runtimeNone.d.ts +2 -0
- package/out/_internal/schema/runtimeNoneLean.d.ts +2 -0
- package/out/_internal/schema/scope.d.ts +203 -0
- package/out/_internal/schema/shared/codecs.d.ts +5 -0
- package/out/_internal/schema/shared/compile.d.ts +144 -0
- package/out/_internal/schema/shared/configured.d.ts +14 -0
- package/out/_internal/schema/shared/declare.d.ts +100 -0
- package/out/_internal/schema/shared/disjoint.d.ts +45 -0
- package/out/_internal/schema/shared/enWriters.d.ts +30 -0
- package/out/_internal/schema/shared/errorModes.d.ts +25 -0
- package/out/_internal/schema/shared/errorWriters.d.ts +34 -0
- package/out/_internal/schema/shared/errors.d.ts +264 -0
- package/out/_internal/schema/shared/implement.d.ts +154 -0
- package/out/_internal/schema/shared/inPlace.d.ts +8 -0
- package/out/_internal/schema/shared/issueFeatures.d.ts +38 -0
- package/out/_internal/schema/shared/issues.d.ts +261 -0
- package/out/_internal/schema/shared/issuesLean.d.ts +80 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +22 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +20 -0
- package/out/_internal/schema/shared/issuesUndetailed.d.ts +25 -0
- package/out/_internal/schema/shared/jsonSchema.d.ts +153 -0
- package/out/_internal/schema/shared/listed.d.ts +15 -0
- package/out/_internal/schema/shared/locale.d.ts +149 -0
- package/out/_internal/schema/shared/registry.d.ts +16 -0
- package/out/_internal/schema/shared/render.d.ts +3 -0
- package/out/_internal/schema/shared/rootApply.d.ts +19 -0
- package/out/_internal/schema/shared/sets.d.ts +26 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +22 -0
- package/out/_internal/schema/shared/standardSchema.d.ts +124 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +229 -0
- package/out/_internal/schema/shared/transform.d.ts +35 -0
- package/out/_internal/schema/shared/traversal.d.ts +288 -0
- package/out/_internal/schema/shared/utils.d.ts +59 -0
- package/out/_internal/schema/structure/index.d.ts +43 -0
- package/out/_internal/schema/structure/optional.d.ts +61 -0
- package/out/_internal/schema/structure/prop.d.ts +45 -0
- package/out/_internal/schema/structure/required.d.ts +49 -0
- package/out/_internal/schema/structure/sequence.d.ts +127 -0
- package/out/_internal/schema/structure/shared.d.ts +3 -0
- package/out/_internal/schema/structure/structure.d.ts +178 -0
- package/out/_internal/schema/units.d.ts +123 -0
- package/out/_internal/sets/algebra.d.ts +26 -0
- package/out/_internal/sets/constraint.d.ts +19 -0
- package/out/_internal/sets/engine.d.ts +2 -0
- package/out/_internal/sets/formats.d.ts +23 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +15 -0
- package/out/_internal/sets/implement.d.ts +16 -0
- package/out/_internal/sets/index.d.ts +2 -0
- package/out/_internal/sets/internal.d.ts +20 -0
- package/out/_internal/sets/intersections.d.ts +5 -0
- package/out/_internal/sets/kinds.d.ts +3 -0
- package/out/_internal/sets/refinements.d.ts +14 -0
- package/out/_internal/sets/roots/alias.d.ts +3 -0
- package/out/_internal/sets/roots/domain.d.ts +3 -0
- package/out/_internal/sets/roots/intersection.d.ts +4 -0
- package/out/_internal/sets/roots/morph.d.ts +4 -0
- package/out/_internal/sets/roots/proto.d.ts +3 -0
- package/out/_internal/sets/roots/union.d.ts +16 -0
- package/out/_internal/sets/roots/unit.d.ts +3 -0
- package/out/_internal/sets/structure/index.d.ts +3 -0
- package/out/_internal/sets/structure/prop.d.ts +8 -0
- package/out/_internal/sets/structure/sequence.d.ts +3 -0
- package/out/_internal/sets/structure/structure.d.ts +3 -0
- package/out/_internal/sets/toJsonSchema.d.ts +25 -0
- package/out/_internal/util/arrays.d.ts +130 -0
- package/out/_internal/util/clone.d.ts +4 -0
- package/out/_internal/util/describe.d.ts +25 -0
- package/out/_internal/util/domain.d.ts +49 -0
- package/out/_internal/util/errors.d.ts +29 -0
- package/out/_internal/util/facts.d.ts +22 -0
- package/out/_internal/util/flatMorph.d.ts +41 -0
- package/out/_internal/util/formats.d.ts +8 -0
- package/out/_internal/util/functions.d.ts +33 -0
- package/out/_internal/util/generics.d.ts +65 -0
- package/out/_internal/util/get.d.ts +9 -0
- package/out/_internal/util/hkt.d.ts +27 -0
- package/out/_internal/util/i18n.d.ts +12 -0
- package/out/_internal/util/index.d.ts +28 -0
- package/out/_internal/util/internal.d.ts +2 -0
- package/out/_internal/util/intersections.d.ts +50 -0
- package/out/_internal/util/isomorphic.d.ts +8 -0
- package/out/_internal/util/keys.d.ts +18 -0
- package/out/_internal/util/lazily.d.ts +7 -0
- package/out/_internal/util/numbers.d.ts +82 -0
- package/out/_internal/util/objectKinds.d.ts +157 -0
- package/out/_internal/util/path.d.ts +16 -0
- package/out/_internal/util/primitive.d.ts +16 -0
- package/out/_internal/util/records.d.ts +173 -0
- package/out/_internal/util/registry.d.ts +13 -0
- package/out/_internal/util/scanner.d.ts +110 -0
- package/out/_internal/util/serialize.d.ts +40 -0
- package/out/_internal/util/strings.d.ts +35 -0
- package/out/_internal/util/traits.d.ts +89 -0
- package/out/_internal/util/unionToTuple.d.ts +14 -0
- package/out/_internal/util/weak.d.ts +8 -0
- package/out/attributes.d.ts +15 -11
- package/out/checkers.d.ts +1 -1
- package/out/chunk-22RQSVV3.js +0 -0
- package/out/chunk-3HZC67MT.js +965 -0
- package/out/chunk-3KBOPH3J.js +1564 -0
- package/out/chunk-3SH2BQ4T.js +15 -0
- package/out/chunk-46PLKNON.js +126 -0
- package/out/{chunk-G45P2CLE.js → chunk-4FTHWK63.js} +6 -1
- package/out/{chunk-UK5UGFOX.js → chunk-4HREHNIV.js} +23 -11
- package/out/chunk-4NZCLVBD.js +14 -0
- package/out/chunk-6FMBO47M.js +7 -0
- package/out/chunk-7TALAWYX.js +10 -0
- package/out/{chunk-DLWCO4RV.js → chunk-BCYKO54Z.js} +11 -2
- package/out/chunk-BDJVONP7.js +168 -0
- package/out/{chunk-E3DZXEZK.js → chunk-C2JOL5M2.js} +4 -2
- package/out/{chunk-2U2AWCI3.js → chunk-C2V6QPE3.js} +126 -97
- package/out/chunk-C3B4IFQL.js +6408 -0
- package/out/chunk-CWSF57VM.js +10 -0
- package/out/chunk-F5BACUJS.js +7 -0
- package/out/{chunk-EVCML554.js → chunk-FWRSDUJ2.js} +14 -5
- package/out/chunk-GID3FSQA.js +161 -0
- package/out/chunk-I2KLQ2HA.js +22 -0
- package/out/chunk-K7SLP5D2.js +84 -0
- package/out/chunk-KQPSKGUI.js +9 -0
- package/out/chunk-KXOC3JEX.js +8234 -0
- package/out/chunk-KXOSUYRA.js +405 -0
- package/out/chunk-LHNEY6QW.js +0 -0
- package/out/chunk-MTWKGAGO.js +323 -0
- package/out/chunk-NU73GNCX.js +170 -0
- package/out/{chunk-RAZ3TXOE.js → chunk-P5W67FQH.js} +34 -19
- package/out/chunk-PDLTEX6Z.js +1118 -0
- package/out/{chunk-VV6YDN2D.js → chunk-QUS4IAXJ.js} +304 -263
- package/out/chunk-R7WXIH5P.js +94 -0
- package/out/chunk-TACLEIDM.js +95 -0
- package/out/chunk-UJJGG4VQ.js +71 -0
- package/out/chunk-US6BWOGJ.js +109 -0
- package/out/chunk-VMMMOO4R.js +945 -0
- package/out/chunk-VYMXHSFR.js +439 -0
- package/out/chunk-W2XOI5DY.js +141 -0
- package/out/chunk-WC5L5YRP.js +25 -0
- package/out/{chunk-NRIGTMPM.js → chunk-WKOSL2G6.js} +4 -1
- package/out/chunk-XLG66ZDF.js +0 -0
- package/out/{chunk-5U2ZMDNI.js → chunk-XNUAQSJ4.js} +52 -30
- package/out/chunk-ZRYEHGSG.js +79 -0
- package/out/cli.d.ts +28 -0
- package/out/cli.js +636 -0
- package/out/codecs.d.ts +6 -5
- package/out/codecs.js +23 -7
- package/out/config.d.ts +5 -17
- package/out/config.js +11 -2
- package/out/declare.d.ts +40 -12
- package/out/deferred.d.ts +2 -2
- package/out/errors.d.ts +1 -1
- package/out/errors.js +10 -2
- package/out/fn.d.ts +20 -13
- package/out/fromJsonSchema.d.ts +18 -0
- package/out/generic.d.ts +9 -6
- package/out/i18n.d.ts +2 -2
- package/out/i18n.js +9 -2
- package/out/index.d.ts +16 -7
- package/out/index.js +25 -8
- package/out/internal.d.ts +4 -0
- package/out/internal.js +41 -17
- package/out/island.js +22 -6
- package/out/islandDependency.js +42 -18
- package/out/jsonSchema/infer.d.ts +805 -0
- package/out/jsonSchema/validate.d.ts +416 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +3 -3
- package/out/keywords/constructors.d.ts +1 -1
- package/out/keywords/functions.d.ts +5 -192
- package/out/keywords/keywords.d.ts +3 -3
- package/out/keywords/number.d.ts +2 -2
- package/out/keywords/phrases.d.ts +4 -191
- package/out/keywords/string.d.ts +3 -3
- package/out/keywords/ts.d.ts +18 -18
- package/out/keywords/ts.js +19 -4
- package/out/locale.d.ts +6 -2
- package/out/locales/de.js +9 -2
- package/out/locales/en.js +21 -5
- package/out/match.d.ts +13 -10
- package/out/module.d.ts +2 -2
- package/out/mutatesInput.js +18 -3
- package/out/nary.d.ts +220 -194
- package/out/parser/ast/bounds.d.ts +2 -2
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/divisor.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +2 -2
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/keyof.d.ts +2 -2
- package/out/parser/ast/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +2 -2
- package/out/parser/definition.d.ts +4 -4
- package/out/parser/objectLiteral.d.ts +2 -2
- package/out/parser/property.d.ts +2 -2
- package/out/parser/reduce/dynamic.d.ts +2 -2
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/shift/operand/genericArgs.d.ts +2 -2
- package/out/parser/shift/operand/operand.d.ts +1 -1
- package/out/parser/shift/operand/unenclosed.d.ts +2 -2
- package/out/parser/shift/operand/unresolvable.d.ts +2 -2
- package/out/parser/shift/operator/bounds.d.ts +2 -2
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +4 -4
- package/out/parser/shift/operator/divisor.d.ts +1 -1
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +1 -1
- package/out/parser/string.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +6 -8
- package/out/parser/tupleLiteral.d.ts +2 -2
- package/out/precompiled.d.ts +1 -1
- package/out/precompiled.js +16 -2
- package/out/regex.d.ts +1 -0
- package/out/regex.js +2 -0
- package/out/runtime.d.ts +10 -8
- package/out/runtime.js +6 -4
- package/out/runtimeDevelopment.js +70 -52
- package/out/schema.d.ts +1 -0
- package/out/schema.js +15 -0
- package/out/schemaInternal.d.ts +1 -0
- package/out/schemaInternal.js +1401 -0
- package/out/schemaIssueFeatures.d.ts +1 -0
- package/out/schemaRuntime.d.ts +1 -0
- package/out/schemaRuntime.js +7 -0
- package/out/schemaRuntimeLean.d.ts +1 -0
- package/out/schemaRuntimeLean.js +1870 -0
- package/out/schemaRuntimeNone.d.ts +1 -0
- package/out/schemaRuntimeNone.js +1774 -0
- package/out/schemaRuntimeNoneLean.d.ts +1 -0
- package/out/schemaRuntimeNoneLean.js +1767 -0
- package/out/scope.d.ts +3 -4
- package/out/shared/issueFeatures.d.ts +38 -0
- package/out/shared/issueFeatures.js +40 -0
- package/out/standalone/artifact.d.ts +6 -6
- package/out/standalone/baking.d.ts +2 -2
- package/out/standalone/combinators.d.ts +1 -1
- package/out/standalone/compilers.d.ts +1 -1
- package/out/standalone/fallbacks.d.ts +1 -1
- package/out/standalone/keys.d.ts +1 -1
- package/out/standalone/sites.d.ts +3 -3
- package/out/standalone/units.d.ts +1 -1
- package/out/standalone/values.d.ts +1 -1
- package/out/type.d.ts +6 -6
- package/out/util.d.ts +1 -0
- package/out/util.js +137 -0
- package/out/variants/array.d.ts +6 -6
- package/out/variants/base.d.ts +61 -10
- package/out/variants/date.d.ts +5 -5
- package/out/variants/instantiate.d.ts +1 -1
- package/out/variants/number.d.ts +6 -6
- package/out/variants/object.d.ts +25 -12
- package/out/variants/string.d.ts +8 -8
- package/package.json +183 -8
- package/skills/arktype/SKILL.md +93 -93
- package/skills/arktype/references/migrating.md +144 -158
- package/skills/arktype/references/precompile.md +7 -7
- package/out/chunk-4CUA5XIP.js +0 -7
- package/out/chunk-GPNK5353.js +0 -2529
- package/out/chunk-MLKGABMK.js +0 -9
- package/out/chunk-PRTMQCHS.js +0 -3
- package/out/chunk-R5G57XC7.js +0 -7
- package/out/chunk-SWOOCAHN.js +0 -4
- package/out/chunk-TAHPKDNM.js +0 -3
- package/out/chunk-UETB6YE2.js +0 -14
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Issues,
|
|
3
|
+
ThrownIssues,
|
|
4
|
+
Traversal,
|
|
5
|
+
applyRejected,
|
|
6
|
+
describeActual,
|
|
7
|
+
describeCases,
|
|
8
|
+
describePredicate,
|
|
9
|
+
describeUnwrittenActual,
|
|
10
|
+
isCustomIssue,
|
|
11
|
+
issueAt,
|
|
12
|
+
messageOf,
|
|
13
|
+
pathOf,
|
|
14
|
+
throwOnProblem,
|
|
15
|
+
writeDomainActual,
|
|
16
|
+
writeLengthActual,
|
|
17
|
+
writeLine,
|
|
18
|
+
writeListed,
|
|
19
|
+
writeMessage,
|
|
20
|
+
writeNotEqualActual,
|
|
21
|
+
writeProtoActual,
|
|
22
|
+
writeUnitActual,
|
|
23
|
+
writeUnitMessage
|
|
24
|
+
} from "./chunk-3KBOPH3J.js";
|
|
25
|
+
import {
|
|
26
|
+
nameOf,
|
|
27
|
+
register,
|
|
28
|
+
registry
|
|
29
|
+
} from "./chunk-ZRYEHGSG.js";
|
|
30
|
+
import {
|
|
31
|
+
appendStringifiedKey,
|
|
32
|
+
appendUnique,
|
|
33
|
+
conflatenateAll,
|
|
34
|
+
describeCollapsibleDate,
|
|
35
|
+
domainDescriptions,
|
|
36
|
+
domainOf,
|
|
37
|
+
hasOwn,
|
|
38
|
+
pathAt,
|
|
39
|
+
printKind,
|
|
40
|
+
printable,
|
|
41
|
+
stringifyPath,
|
|
42
|
+
throwError,
|
|
43
|
+
throwParseError
|
|
44
|
+
} from "./chunk-3HZC67MT.js";
|
|
45
|
+
|
|
46
|
+
// ../schema/out/shared/errorWriters.js
|
|
47
|
+
var errorWriters = {
|
|
48
|
+
actual: printKind,
|
|
49
|
+
message: writeMessage
|
|
50
|
+
};
|
|
51
|
+
var errorWritersByCode = {
|
|
52
|
+
after: { actual: describeCollapsibleDate },
|
|
53
|
+
before: { actual: describeCollapsibleDate },
|
|
54
|
+
divisor: {},
|
|
55
|
+
domain: { actual: writeDomainActual },
|
|
56
|
+
exactLength: { actual: writeLengthActual },
|
|
57
|
+
max: {},
|
|
58
|
+
maxLength: { actual: writeLengthActual },
|
|
59
|
+
min: {},
|
|
60
|
+
minLength: { actual: writeLengthActual },
|
|
61
|
+
notEqual: { actual: writeNotEqualActual },
|
|
62
|
+
notEqualLength: { actual: writeLengthActual },
|
|
63
|
+
pattern: {},
|
|
64
|
+
// a keyword's phrase writes only the errors it raises through ctx
|
|
65
|
+
predicate: {
|
|
66
|
+
// error contexts from ctx.reject have neither a description nor a predicate
|
|
67
|
+
expected: (ctx) => ctx.description ?? describePredicate(ctx),
|
|
68
|
+
actual: (data, ctx) => ctx.morph ? `aborted due to error:
|
|
69
|
+
${describeCause(ctx.cause)}
|
|
70
|
+
` : printKind(data),
|
|
71
|
+
message: function (ctx, info) {
|
|
72
|
+
const locale = info;
|
|
73
|
+
if (ctx.morph && ctx.cause !== void 0) {
|
|
74
|
+
try {
|
|
75
|
+
return `must be ${ctx.expected} (${String(ctx.cause)})`;
|
|
76
|
+
} catch {
|
|
77
|
+
return `must be ${ctx.expected}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const message = ctx.cause === void 0 ? void 0 : keywordWriterOf(ctx, locale, "message");
|
|
81
|
+
return message === void 0 ? locale.message(ctx, locale) : typeof message === "string" ? message : message(ctx, locale);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
proto: { actual: writeProtoActual },
|
|
85
|
+
required: {
|
|
86
|
+
expected: (ctx) => ctx.missingValueDescription,
|
|
87
|
+
actual: () => "missing"
|
|
88
|
+
},
|
|
89
|
+
union: {
|
|
90
|
+
// written as a standalone validator lists its branches' first issues
|
|
91
|
+
expected: (ctx) => ctx.description ?? (ctx.errors.length ? writeListed(ctx.errors) : "never"),
|
|
92
|
+
// data that may be large is described by its kind
|
|
93
|
+
actual: (data, ctx) => actualAtPathOf(ctx) ?? printKind(data),
|
|
94
|
+
// its text is its errors', unless it has none, like never, or says what
|
|
95
|
+
// it is or expects itself
|
|
96
|
+
message: (ctx, info) => listsErrors(ctx) ? ctx.expected : writeMessage(ctx, info)
|
|
97
|
+
},
|
|
98
|
+
unit: { actual: writeUnitActual, message: writeUnitMessage },
|
|
99
|
+
undeclared: { expected: "removed" },
|
|
100
|
+
discriminant: {
|
|
101
|
+
expected: (e) => e.description ?? describeCases(e),
|
|
102
|
+
actual: (data, e) => e.absent ? "missing" : e.discriminantKind === "domain" ? domainDescriptions[domainOf(data)] : printKind(data)
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var dataDescribers = /* @__PURE__ */ (function () {
|
|
106
|
+
const describers = /* @__PURE__ */ new Set([errorWriters.actual]);
|
|
107
|
+
for (const [code, writers] of Object.entries(errorWritersByCode)) {
|
|
108
|
+
const actual = writers.actual;
|
|
109
|
+
if (code !== "required" && typeof actual === "function")
|
|
110
|
+
describers.add(actual);
|
|
111
|
+
}
|
|
112
|
+
return describers;
|
|
113
|
+
})();
|
|
114
|
+
var registerDescriber = (writer) => {
|
|
115
|
+
dataDescribers.add(writer);
|
|
116
|
+
};
|
|
117
|
+
var describesData = (writer) => dataDescribers.has(writer);
|
|
118
|
+
var listsErrors = (ctx) => ctx.errors.length !== 0 && ctx.description === void 0 && ctx.meta?.expected === void 0;
|
|
119
|
+
|
|
120
|
+
// ../schema/out/shared/errors.js
|
|
121
|
+
import { findsOnRead } from "./shared/issueFeatures.js";
|
|
122
|
+
var ThrownErrors = ThrownIssues;
|
|
123
|
+
var writtenKey = Symbol("written");
|
|
124
|
+
var localeKey = Symbol("locale");
|
|
125
|
+
var configKey = Symbol("config");
|
|
126
|
+
var hasInstance = Function.prototype[Symbol.hasInstance];
|
|
127
|
+
var ArkErrors = class ArkErrors extends Issues {
|
|
128
|
+
constructor(config) {
|
|
129
|
+
super();
|
|
130
|
+
this._init(config);
|
|
131
|
+
}
|
|
132
|
+
/** @internal resets the fields its constructor sets */
|
|
133
|
+
_init(config) {
|
|
134
|
+
this[writtenKey] = 0;
|
|
135
|
+
this[localeKey] = void 0;
|
|
136
|
+
this[configKey] = config;
|
|
137
|
+
}
|
|
138
|
+
// a computed key would keep the class in a bundle that never reads it
|
|
139
|
+
get " arkKind"() {
|
|
140
|
+
return "errors";
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Each error, in the order it was added, with its text written in the
|
|
144
|
+
* locale selected when they were first read.
|
|
145
|
+
*/
|
|
146
|
+
get issues() {
|
|
147
|
+
const issues = this._;
|
|
148
|
+
if (this[writtenKey] < issues.length) {
|
|
149
|
+
const locale = selectedLocaleOf(this);
|
|
150
|
+
const config = this[configKey];
|
|
151
|
+
while (this[writtenKey] < issues.length)
|
|
152
|
+
writeError(issues[this[writtenKey]++], config, locale);
|
|
153
|
+
}
|
|
154
|
+
return serializableErrors(issues);
|
|
155
|
+
}
|
|
156
|
+
/** @internal the first of issues, its text written alone */
|
|
157
|
+
get _first() {
|
|
158
|
+
return this._firstGrouped();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @internal the first of issues, found with the rest. Counted as written,
|
|
162
|
+
* so reading the rest doesn't write it again, which would note the line of
|
|
163
|
+
* a union listing its errors from the message already written from its own
|
|
164
|
+
* path, dropping the path before each error's
|
|
165
|
+
*/
|
|
166
|
+
_firstGrouped() {
|
|
167
|
+
const first = this._[0];
|
|
168
|
+
if (first && this[writtenKey] === 0) {
|
|
169
|
+
writeError(first, this[configKey], selectedLocaleOf(this));
|
|
170
|
+
this[writtenKey] = 1;
|
|
171
|
+
}
|
|
172
|
+
return first;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A human-readable summary of all errors.
|
|
176
|
+
*/
|
|
177
|
+
get summary() {
|
|
178
|
+
const issues = this.issues;
|
|
179
|
+
return summarize(issues, selectedLocaleOf(this));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Each error's JSON: what it says and where, without its data or any other
|
|
183
|
+
* value only JavaScript holds, like its Type's `meta`.
|
|
184
|
+
*/
|
|
185
|
+
toJSON() {
|
|
186
|
+
return this.issues.map(jsonOf);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The summary in `locale`, or as configured without one.
|
|
190
|
+
*/
|
|
191
|
+
summaryIn(locale) {
|
|
192
|
+
if (locale === void 0)
|
|
193
|
+
return this.summary;
|
|
194
|
+
const resolved = resolveLocale(locale);
|
|
195
|
+
return summarize(this._.map((error) => writtenIn(error, resolved)), resolved);
|
|
196
|
+
}
|
|
197
|
+
/** @internal */
|
|
198
|
+
_merge(merged, prefix) {
|
|
199
|
+
if (hasInstance.call(ArkErrors, merged))
|
|
200
|
+
return mergeErrors(this, merged, prefix);
|
|
201
|
+
const config = this[configKey];
|
|
202
|
+
for (const issue of merged.issues) {
|
|
203
|
+
this._.push(issue._m ? errorOfIssue(issue._m(prefix), [], config) : errorOfIssue(issue, prefix, config));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** @internal the config its errors are written with */
|
|
207
|
+
get _config() {
|
|
208
|
+
return this[configKey];
|
|
209
|
+
}
|
|
210
|
+
/** @internal the errors, without their text */
|
|
211
|
+
get _i() {
|
|
212
|
+
return this._;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
Object.defineProperty(ArkErrors, Symbol.hasInstance, {
|
|
216
|
+
value(value) {
|
|
217
|
+
return this === ArkErrors ? value instanceof Issues : hasInstance.call(this, value);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
var selectedLocaleOf = (errors) => errors[localeKey] ??= renderer?.select(errors[configKey]) ?? errors[configKey].locale;
|
|
221
|
+
var pathEquals = function (l, r) {
|
|
222
|
+
if (l.length !== r.length)
|
|
223
|
+
return false;
|
|
224
|
+
for (let i = l.length - 1; i >= 0; i--)
|
|
225
|
+
if (l[i] !== r[i])
|
|
226
|
+
return false;
|
|
227
|
+
return true;
|
|
228
|
+
};
|
|
229
|
+
var errorOfIssue = function (issue, prefix, config) {
|
|
230
|
+
const message = issue.message ?? messageOf(issue);
|
|
231
|
+
const meta = { expected: issue.expected ?? message, message };
|
|
232
|
+
const error = stampError({
|
|
233
|
+
code: issue.code,
|
|
234
|
+
path: [...prefix, ...issue.path],
|
|
235
|
+
data: issue.data,
|
|
236
|
+
meta,
|
|
237
|
+
// a union's issue carries no branch errors
|
|
238
|
+
...issue.code === "union" && { errors: [] }
|
|
239
|
+
}, config);
|
|
240
|
+
if (!isCustomIssue(issue))
|
|
241
|
+
templated.add(error);
|
|
242
|
+
return error;
|
|
243
|
+
};
|
|
244
|
+
var mergeErrors = (errors, merged, prefix) => {
|
|
245
|
+
for (const error of merged._i)
|
|
246
|
+
errors._.push(unwrittenError(error, prefix, errors._config));
|
|
247
|
+
};
|
|
248
|
+
var UnreadErrors = /* @__PURE__ */ (() => {
|
|
249
|
+
class Unread {
|
|
250
|
+
#node;
|
|
251
|
+
#data;
|
|
252
|
+
#ctor;
|
|
253
|
+
#found;
|
|
254
|
+
// the first issue, found alone
|
|
255
|
+
#first;
|
|
256
|
+
constructor(node, data, config, ctor) {
|
|
257
|
+
this[configKey] = config;
|
|
258
|
+
this.#node = node;
|
|
259
|
+
this.#data = data;
|
|
260
|
+
this.#ctor = ctor;
|
|
261
|
+
}
|
|
262
|
+
get _() {
|
|
263
|
+
if (!this.#found) {
|
|
264
|
+
const config = this[configKey];
|
|
265
|
+
const ctx = new this.#ctor(this.#data, config);
|
|
266
|
+
this.#node.tApply(this.#data, ctx);
|
|
267
|
+
if (!ctx.hasError())
|
|
268
|
+
ctx.reject(invalidInput());
|
|
269
|
+
const found = ctx.fin(null)._;
|
|
270
|
+
const first = this.#first;
|
|
271
|
+
const locale = this[localeKey];
|
|
272
|
+
this._init(config);
|
|
273
|
+
if (first) {
|
|
274
|
+
found[0] = first;
|
|
275
|
+
this[writtenKey] = 1;
|
|
276
|
+
this[localeKey] = locale;
|
|
277
|
+
}
|
|
278
|
+
this.#found = found;
|
|
279
|
+
this.#node = this.#ctor = this.#data = void 0;
|
|
280
|
+
}
|
|
281
|
+
return this.#found;
|
|
282
|
+
}
|
|
283
|
+
// a traversal adds only the errors at its path, unless the rest were found first
|
|
284
|
+
get _first() {
|
|
285
|
+
if (this.#first || this.#found)
|
|
286
|
+
return this.#first ?? this._firstGrouped();
|
|
287
|
+
const node = this.#node;
|
|
288
|
+
const ctx = new (firstPathTraversalOf(this.#ctor))(this.#data, this[configKey], !revisitsPaths(node));
|
|
289
|
+
node.tApply(this.#data, ctx);
|
|
290
|
+
if (!ctx.hasError())
|
|
291
|
+
ctx.reject(invalidInput());
|
|
292
|
+
const errors = ctx.fin(null);
|
|
293
|
+
if (errors._.includes(skipped)) {
|
|
294
|
+
const found = errors._.filter((error) => error !== skipped);
|
|
295
|
+
if (findsOnRead)
|
|
296
|
+
errors._f = found;
|
|
297
|
+
else
|
|
298
|
+
errors._ = found;
|
|
299
|
+
}
|
|
300
|
+
errors[localeKey] = selectedLocaleOf(this);
|
|
301
|
+
return this.#first = errors._first;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
Object.setPrototypeOf(Unread.prototype, ArkErrors.prototype);
|
|
305
|
+
Unread.prototype.constructor = ArkErrors;
|
|
306
|
+
return Unread;
|
|
307
|
+
})();
|
|
308
|
+
var skipped = {};
|
|
309
|
+
var firstPathTraversals = /* @__PURE__ */ new WeakMap();
|
|
310
|
+
var firstPathTraversalOf = (Base) => {
|
|
311
|
+
let FirstPath = firstPathTraversals.get(Base);
|
|
312
|
+
if (FirstPath)
|
|
313
|
+
return FirstPath;
|
|
314
|
+
FirstPath = class extends Base {
|
|
315
|
+
constructor(root, config, stopsElsewhere) {
|
|
316
|
+
super(root, config);
|
|
317
|
+
this.firstPath = void 0;
|
|
318
|
+
this.stopsElsewhere = stopsElsewhere;
|
|
319
|
+
this.left = false;
|
|
320
|
+
}
|
|
321
|
+
// outside the first's path, not counting a union's branches
|
|
322
|
+
isElsewhere(key) {
|
|
323
|
+
const first = this.firstPath;
|
|
324
|
+
if (first === void 0 || this.branches.length !== 0)
|
|
325
|
+
return false;
|
|
326
|
+
if (this.left)
|
|
327
|
+
return true;
|
|
328
|
+
const path = this.path;
|
|
329
|
+
if (first.length !== path.length + (key === void 0 ? 0 : 1))
|
|
330
|
+
return true;
|
|
331
|
+
if (key !== void 0 && first[path.length] !== key)
|
|
332
|
+
return true;
|
|
333
|
+
for (let i = 0; i < path.length; i++)
|
|
334
|
+
if (first[i] !== path[i])
|
|
335
|
+
return true;
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
skip() {
|
|
339
|
+
if (this.stopsElsewhere)
|
|
340
|
+
this.left = true;
|
|
341
|
+
super.addError(skipped);
|
|
342
|
+
return this.left || this.failFast;
|
|
343
|
+
}
|
|
344
|
+
_at(site, data, key) {
|
|
345
|
+
return this.isElsewhere(key) ? this.skip() : super._at(site, data, key);
|
|
346
|
+
}
|
|
347
|
+
_in(apply, data, key, missing, value) {
|
|
348
|
+
const stops = super._in(apply, data, key, missing, value);
|
|
349
|
+
if (this.stopsElsewhere && this.firstPath !== void 0 && this.path.length < this.firstPath.length && this.branches.length === 0)
|
|
350
|
+
this.left = true;
|
|
351
|
+
return stops || this.left;
|
|
352
|
+
}
|
|
353
|
+
failsUnion(branches, site, data) {
|
|
354
|
+
return this.isElsewhere() ? this.skip() : super.failsUnion(branches, site, data);
|
|
355
|
+
}
|
|
356
|
+
addError(error) {
|
|
357
|
+
if (this.branches.length === 0) {
|
|
358
|
+
if (this.firstPath === void 0)
|
|
359
|
+
this.firstPath = error.path;
|
|
360
|
+
else if (this.left || !pathEquals(error.path, this.firstPath)) {
|
|
361
|
+
this.skip();
|
|
362
|
+
return error;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return super.addError(error);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
firstPathTraversals.set(Base, FirstPath);
|
|
369
|
+
return FirstPath;
|
|
370
|
+
};
|
|
371
|
+
var revisitsPathsByNode = /* @__PURE__ */ new WeakMap();
|
|
372
|
+
var revisitsPaths = function (node) {
|
|
373
|
+
let revisits = revisitsPathsByNode.get(node);
|
|
374
|
+
if (revisits === void 0) {
|
|
375
|
+
revisits = node.hasAlias || node.references.some((reference2) => reference2.is("index"));
|
|
376
|
+
revisitsPathsByNode.set(node, revisits);
|
|
377
|
+
}
|
|
378
|
+
return revisits;
|
|
379
|
+
};
|
|
380
|
+
var applyUnread = function (node, data, config, onFail, ctor) {
|
|
381
|
+
if (node.userCode || node.alters)
|
|
382
|
+
return applyRejected(node, data, config, onFail, ctor);
|
|
383
|
+
const errors = new UnreadErrors(node, data, config, ctor);
|
|
384
|
+
return onFail ? onFail(errors) : errors;
|
|
385
|
+
};
|
|
386
|
+
var SiteTraversal = class extends Traversal {
|
|
387
|
+
/** @internal */
|
|
388
|
+
_at(site, data, key) {
|
|
389
|
+
this.addError(issueAt(this.path, site, data, key));
|
|
390
|
+
return this.failFast;
|
|
391
|
+
}
|
|
392
|
+
/** @internal */
|
|
393
|
+
_in(apply, data, key, missing, value) {
|
|
394
|
+
if (value === void 0)
|
|
395
|
+
value = data[key];
|
|
396
|
+
if (value === void 0 && missing && !(key in data))
|
|
397
|
+
return this._at(missing, data, key);
|
|
398
|
+
this.path.push(key);
|
|
399
|
+
const continues = apply(value, this);
|
|
400
|
+
this.path.pop();
|
|
401
|
+
return !continues;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
var { _at, _in } = SiteTraversal.prototype;
|
|
405
|
+
var siteTraversalOf = (ctx) => {
|
|
406
|
+
if (!("_at" in ctx))
|
|
407
|
+
Object.assign(ctx, { _at, _in });
|
|
408
|
+
return ctx;
|
|
409
|
+
};
|
|
410
|
+
var ArkTraversal = class extends SiteTraversal {
|
|
411
|
+
createErrors() {
|
|
412
|
+
return new ArkErrors(this.config);
|
|
413
|
+
}
|
|
414
|
+
nodeError(input, data) {
|
|
415
|
+
return this.addError(errorOfNodeContext(input, pathAt(this.path), data, this.config));
|
|
416
|
+
}
|
|
417
|
+
// builds a site's error as compiled code does
|
|
418
|
+
_at(site, data, key) {
|
|
419
|
+
const value = key === void 0 ? data : data[key];
|
|
420
|
+
const missing = key !== void 0 && value === void 0 && site.m && !(key in data);
|
|
421
|
+
const context = missing ? site.m : site.v;
|
|
422
|
+
let build = missing ? site.mb : site.vb;
|
|
423
|
+
if (build === void 0) {
|
|
424
|
+
build = builderOf(context, this.config);
|
|
425
|
+
if (build) {
|
|
426
|
+
if (missing)
|
|
427
|
+
site.mb = build;
|
|
428
|
+
else
|
|
429
|
+
site.vb = build;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
this.addError(errorBuiltBy(build, context, pathAt(this.path, key), missing ? data : value, this.config));
|
|
433
|
+
return this.failFast;
|
|
434
|
+
}
|
|
435
|
+
// each branch stops at its first error, which the union's error lists
|
|
436
|
+
failsUnion(branches, site, data) {
|
|
437
|
+
const errors = branches.map((branch) => {
|
|
438
|
+
this.pushBr();
|
|
439
|
+
branch(data, this);
|
|
440
|
+
return this.popBr().error;
|
|
441
|
+
});
|
|
442
|
+
errorFromUnion(this, errors, site.meta, data);
|
|
443
|
+
return this.failFast;
|
|
444
|
+
}
|
|
445
|
+
raise(input) {
|
|
446
|
+
throwOnProblem(input);
|
|
447
|
+
const errCtx = typeof input === "object" ? input.code ? { ...input } : { ...input, code: "predicate" } : { code: "predicate", expected: input };
|
|
448
|
+
if (!("data" in errCtx))
|
|
449
|
+
errCtx.data = this.data;
|
|
450
|
+
if (errCtx.code !== "predicate" && errCtx.expected === void 0 && errCtx.description === void 0 && errCtx.morph === void 0)
|
|
451
|
+
errCtx.expected = "valid";
|
|
452
|
+
const meta = errCtx.meta;
|
|
453
|
+
if (meta && (meta.expected !== void 0 || meta.actual !== void 0 || meta.message !== void 0)) {
|
|
454
|
+
const { expected, actual, message, ...rest } = meta;
|
|
455
|
+
errCtx.meta = rest;
|
|
456
|
+
}
|
|
457
|
+
return errorFromContext(this, errCtx);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
var errorFromContext = (ctx, input) => ctx.addError(errorOfContext(input, ctx.path, ctx.config));
|
|
461
|
+
var errorFromNodeAt = function (ctx, context, relativePath, data) { return ctx.addError(errorOfNodeContext(context, relativePath.length > 1 ? [...ctx.path, ...relativePath] : pathAt(ctx.path, relativePath[0]), data, ctx.config)) };
|
|
462
|
+
var errorFromUnion = function (ctx, errors, meta, data) {
|
|
463
|
+
const path = pathAt(ctx.path);
|
|
464
|
+
const flat = flattenUnion(errors);
|
|
465
|
+
const isDescribed = meta.description !== void 0 && meta.keyword === void 0;
|
|
466
|
+
const atBases = !isDescribed && meta.expected === void 0 && meta.message === void 0 && flat.length !== 0 && flat.every((e) => failsAtBasis(e, path));
|
|
467
|
+
const error = stampError({
|
|
468
|
+
data,
|
|
469
|
+
path,
|
|
470
|
+
code: "union",
|
|
471
|
+
errors: atBases ? [] : flat,
|
|
472
|
+
// what it lists says what it expects, as a validator's, never its actual
|
|
473
|
+
meta: atBases && meta.actual !== void 0 ? { ...meta, actual: "" } : meta,
|
|
474
|
+
...isDescribed && { description: meta.description }
|
|
475
|
+
}, ctx.config);
|
|
476
|
+
if (atBases)
|
|
477
|
+
basesByUnion.set(error, flat);
|
|
478
|
+
return ctx.addError(error);
|
|
479
|
+
};
|
|
480
|
+
var basesByUnion = /* @__PURE__ */ new WeakMap();
|
|
481
|
+
var failsAtBasis = (error, path) => (error.code === "domain" || error.code === "proto" || error.code === "unit") && pathEquals(error.path, path);
|
|
482
|
+
var messageIn = (error, locale) => writtenIn(error, resolveLocale(locale)).message;
|
|
483
|
+
var invalidInput = () => ({
|
|
484
|
+
expected: "valid",
|
|
485
|
+
message: "is invalid"
|
|
486
|
+
});
|
|
487
|
+
var isInvalidInput = (input) => input?.message === "is invalid" && input.expected === "valid";
|
|
488
|
+
var invalidError = function ({ data, path }, config) {
|
|
489
|
+
const error = errorOfContext({ code: "predicate", ...invalidInput(), data }, path, config);
|
|
490
|
+
writeError(error, config, renderer?.en ?? config.locale);
|
|
491
|
+
return error;
|
|
492
|
+
};
|
|
493
|
+
var errorOfContext = function (input, basePath, config) {
|
|
494
|
+
const { relativePath, prefixPath } = input;
|
|
495
|
+
let error;
|
|
496
|
+
if (!("path" in input) && !("relativePath" in input) && !("prefixPath" in input) && !("propString" in input))
|
|
497
|
+
error = { data: input.data, path: [...basePath], ...input };
|
|
498
|
+
else {
|
|
499
|
+
const path = [...input.path ?? basePath];
|
|
500
|
+
if (relativePath)
|
|
501
|
+
path.push(...relativePath);
|
|
502
|
+
if (prefixPath)
|
|
503
|
+
path.unshift(...prefixPath);
|
|
504
|
+
error = { data: input.data, path };
|
|
505
|
+
for (const k in input)
|
|
506
|
+
if (!(k in pathKeys))
|
|
507
|
+
error[k] = input[k];
|
|
508
|
+
assignSymbols(error, input);
|
|
509
|
+
}
|
|
510
|
+
if (input.code === "union") {
|
|
511
|
+
const flat = flattenUnion(input.errors);
|
|
512
|
+
error.errors = !prefixPath && !relativePath ? flat : flat.map((e) => {
|
|
513
|
+
const copy = unwrittenError(e);
|
|
514
|
+
copy.path = conflatenateAll(prefixPath, e.path, relativePath);
|
|
515
|
+
return copy;
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return stampError(error, config, input);
|
|
519
|
+
};
|
|
520
|
+
var assignSymbols = (target, source) => {
|
|
521
|
+
for (const k of Object.getOwnPropertySymbols(source))
|
|
522
|
+
target[k] = source[k];
|
|
523
|
+
};
|
|
524
|
+
var flattenUnion = function (errors) {
|
|
525
|
+
const flat = [];
|
|
526
|
+
for (const inner of errors) {
|
|
527
|
+
if (inner.code !== "union" || !inner.errors.length)
|
|
528
|
+
appendError(flat, inner);
|
|
529
|
+
else
|
|
530
|
+
for (const e of inner.errors)
|
|
531
|
+
appendError(flat, e);
|
|
532
|
+
}
|
|
533
|
+
return flat;
|
|
534
|
+
};
|
|
535
|
+
var appendError = (errors, error) => {
|
|
536
|
+
if (!errors.includes(error))
|
|
537
|
+
errors.push(error);
|
|
538
|
+
};
|
|
539
|
+
var pathKeys = {
|
|
540
|
+
data: 1,
|
|
541
|
+
path: 1,
|
|
542
|
+
relativePath: 1,
|
|
543
|
+
prefixPath: 1,
|
|
544
|
+
propString: 1
|
|
545
|
+
};
|
|
546
|
+
var errorOfNodeContext = (context, path, data, config) => errorBuiltBy(builderOf(context, config), context, path, data, config);
|
|
547
|
+
var errorBuiltBy = function (build, context, path, data, config) { return build ? build(context, path, data, stampError(new StampedFirst(), config)) : stampError({ data, path, ...context }, config) };
|
|
548
|
+
var StampedFirst = function() {
|
|
549
|
+
this.data = void 0;
|
|
550
|
+
this.path = void 0;
|
|
551
|
+
};
|
|
552
|
+
StampedFirst.prototype = Object.prototype;
|
|
553
|
+
var builderOf = function (context, config) {
|
|
554
|
+
let build = buildersByContext.get(context);
|
|
555
|
+
if (!build && compileBuilder && !config.jitless) {
|
|
556
|
+
build = compileBuilder(context);
|
|
557
|
+
if (build)
|
|
558
|
+
buildersByContext.set(context, build);
|
|
559
|
+
}
|
|
560
|
+
return build;
|
|
561
|
+
};
|
|
562
|
+
var buildersByContext = /* @__PURE__ */ new WeakMap();
|
|
563
|
+
var compileBuilder;
|
|
564
|
+
var registerBuilderCompiler = (compile) => {
|
|
565
|
+
compileBuilder = compile;
|
|
566
|
+
};
|
|
567
|
+
var Identity = class {
|
|
568
|
+
constructor(o) {
|
|
569
|
+
return o;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var Supplied = class {
|
|
573
|
+
constructor(config, input) {
|
|
574
|
+
this.config = config;
|
|
575
|
+
this.input = input;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var ErrorSource = class extends Identity {
|
|
579
|
+
#source;
|
|
580
|
+
constructor(error, source) {
|
|
581
|
+
super(error);
|
|
582
|
+
this.#source = source;
|
|
583
|
+
}
|
|
584
|
+
// a copy holds no source, so reading its config or input throws
|
|
585
|
+
static of(error) {
|
|
586
|
+
return #source in error ? error.#source : throwError(copiedErrorMessage);
|
|
587
|
+
}
|
|
588
|
+
static stamps(issue) {
|
|
589
|
+
return #source in issue;
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
var isArkError = (issue) => ErrorSource.stamps(issue);
|
|
593
|
+
var configOf = (error) => {
|
|
594
|
+
const source = ErrorSource.of(error);
|
|
595
|
+
return source instanceof Supplied ? source.config : source;
|
|
596
|
+
};
|
|
597
|
+
var inputOf = (error) => {
|
|
598
|
+
const source = ErrorSource.of(error);
|
|
599
|
+
return source instanceof Supplied ? source.input : void 0;
|
|
600
|
+
};
|
|
601
|
+
var stampError = (error, config, input) => {
|
|
602
|
+
new ErrorSource(error, input ? new Supplied(config, input) : config);
|
|
603
|
+
return error;
|
|
604
|
+
};
|
|
605
|
+
var suppliedText = (error, slot) => inputOf(error)?.[slot];
|
|
606
|
+
var writeError = function (error, config, locale) {
|
|
607
|
+
const code = error.code;
|
|
608
|
+
if (code === "union") {
|
|
609
|
+
writeAtPaths(error, config, locale);
|
|
610
|
+
writeRelative(error, config, locale);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
error.propString ??= stringifyPath(error.path);
|
|
614
|
+
if (renderer && locale !== renderer.en)
|
|
615
|
+
renderer.write(error, config, locale);
|
|
616
|
+
else
|
|
617
|
+
writeText(error, config, locale, code);
|
|
618
|
+
};
|
|
619
|
+
var noteLine = (error, line) => {
|
|
620
|
+
Object.defineProperty(error, "_l", { value: line, configurable: true });
|
|
621
|
+
};
|
|
622
|
+
var writeRelative = function (error, config, locale) {
|
|
623
|
+
if (error.code !== "union")
|
|
624
|
+
return;
|
|
625
|
+
for (const e of error.errors)
|
|
626
|
+
writeRelative(e, config, locale);
|
|
627
|
+
if (error.path.length === 0)
|
|
628
|
+
return;
|
|
629
|
+
if (isCustom(error)) {
|
|
630
|
+
if (unconfigured(error, config))
|
|
631
|
+
error.expected = relativeTo(error, config, locale, error.message).expected;
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (error.code === "union" && listsErrors(error) && error._l === void 0)
|
|
635
|
+
noteLine(error, error.message);
|
|
636
|
+
const relative = relativeTo(error, config, locale);
|
|
637
|
+
error.expected = relative.expected;
|
|
638
|
+
error.message = relative.message;
|
|
639
|
+
};
|
|
640
|
+
var relativeTo = function (error, config, locale, message) {
|
|
641
|
+
const relative = unwrittenError(error);
|
|
642
|
+
unprefix(relative, error.path.length);
|
|
643
|
+
if (message !== void 0)
|
|
644
|
+
relative.message = message;
|
|
645
|
+
writeAtPaths(relative, config, locale);
|
|
646
|
+
return relative;
|
|
647
|
+
};
|
|
648
|
+
var sharing = /* @__PURE__ */ new WeakSet();
|
|
649
|
+
var templated = /* @__PURE__ */ new WeakSet();
|
|
650
|
+
var asTemplated = function (error, line) {
|
|
651
|
+
if (isArkError(error)) {
|
|
652
|
+
templated.add(error);
|
|
653
|
+
if (line !== void 0)
|
|
654
|
+
noteLine(error, line);
|
|
655
|
+
} else if (line !== void 0)
|
|
656
|
+
error._l = line;
|
|
657
|
+
if (error.message?.startsWith("must be "))
|
|
658
|
+
error.expected = error.message.slice(8);
|
|
659
|
+
else if (error.message === "is invalid")
|
|
660
|
+
error.expected = "valid";
|
|
661
|
+
else if (!isArkError(error) && error._l === void 0 && error.message !== void 0) {
|
|
662
|
+
const path = pathOf(error);
|
|
663
|
+
error._l = path ? `${path} ${error.message}` : error.message;
|
|
664
|
+
}
|
|
665
|
+
return error;
|
|
666
|
+
};
|
|
667
|
+
var isCustom = function (error) {
|
|
668
|
+
if (templated.has(error))
|
|
669
|
+
return false;
|
|
670
|
+
if (sharing.has(error))
|
|
671
|
+
return true;
|
|
672
|
+
const source = ErrorSource.of(error);
|
|
673
|
+
let config;
|
|
674
|
+
if (source instanceof Supplied) {
|
|
675
|
+
if (source.input.message !== void 0)
|
|
676
|
+
return !isInvalidInput(source.input);
|
|
677
|
+
config = source.config;
|
|
678
|
+
} else
|
|
679
|
+
config = source;
|
|
680
|
+
return configuredMessageOf(error) !== void 0 || configuresMessage(config, error.code);
|
|
681
|
+
};
|
|
682
|
+
var messagesDefaulted = /* @__PURE__ */ new WeakMap();
|
|
683
|
+
var lastDefaulted;
|
|
684
|
+
var defaultsMessages = function (config) {
|
|
685
|
+
if (config === lastDefaulted)
|
|
686
|
+
return true;
|
|
687
|
+
let defaulted = messagesDefaulted.get(config);
|
|
688
|
+
if (defaulted === void 0) {
|
|
689
|
+
defaulted = true;
|
|
690
|
+
let k;
|
|
691
|
+
for (k in defaultConfig) {
|
|
692
|
+
const writers = defaultConfig[k];
|
|
693
|
+
if (typeof writers === "object" && writers !== null && "message" in writers && config[k]?.message !== writers.message) {
|
|
694
|
+
defaulted = false;
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
messagesDefaulted.set(config, defaulted);
|
|
699
|
+
}
|
|
700
|
+
if (defaulted)
|
|
701
|
+
lastDefaulted = config;
|
|
702
|
+
return defaulted;
|
|
703
|
+
};
|
|
704
|
+
var configuresMessage = (config, code) => !defaultsMessages(config) && config[code].message !== defaultConfig[code].message;
|
|
705
|
+
var isCustomError = (issue) => isArkError(issue) && isCustom(issue);
|
|
706
|
+
var configuredMessageOf = function (error) {
|
|
707
|
+
const message = error.meta?.message;
|
|
708
|
+
if (message !== void 0 || error.code !== "required")
|
|
709
|
+
return message;
|
|
710
|
+
const ofValue = error.valueMeta?.message;
|
|
711
|
+
return typeof ofValue === "string" ? ofValue : void 0;
|
|
712
|
+
};
|
|
713
|
+
var lineOf = function (error, locale) {
|
|
714
|
+
if (error.path.length === 0)
|
|
715
|
+
return error.message;
|
|
716
|
+
const listed = error._l;
|
|
717
|
+
if (listed !== void 0)
|
|
718
|
+
return listed;
|
|
719
|
+
const custom = isCustom(error) && !beginsAsOwn(error, locale);
|
|
720
|
+
const line = locale.line;
|
|
721
|
+
if (line === void 0 || line === writeLine)
|
|
722
|
+
return `${error.propString}${custom ? ":" : ""} ${error.message}`;
|
|
723
|
+
return line(custom ? { ...error, custom } : error, locale);
|
|
724
|
+
};
|
|
725
|
+
var beginsAsOwn = function (error, locale) { return error.message.startsWith(
|
|
726
|
+
// a standalone runtime's locale is en's info alone
|
|
727
|
+
locale.message === void 0 || locale.message === writeMessage ? messageOf(error) : locale.message({ ...error, actual: "" }, locale)
|
|
728
|
+
) };
|
|
729
|
+
var unprefix = function (error, depth) {
|
|
730
|
+
error.path = error.path.slice(depth);
|
|
731
|
+
if (error.code === "union")
|
|
732
|
+
for (const e of error.errors)
|
|
733
|
+
unprefix(e, depth);
|
|
734
|
+
};
|
|
735
|
+
var writeAtPaths = function (error, config, locale) {
|
|
736
|
+
error.propString ??= stringifyPath(error.path);
|
|
737
|
+
const bases = basesByUnion.get(error);
|
|
738
|
+
if (bases && error.expected === void 0) {
|
|
739
|
+
const expected = [];
|
|
740
|
+
for (const e of bases) {
|
|
741
|
+
writeError(e, config, locale);
|
|
742
|
+
if (!expected.includes(e.expected))
|
|
743
|
+
expected.push(e.expected);
|
|
744
|
+
}
|
|
745
|
+
error.expected = locale.list(expected, "or");
|
|
746
|
+
}
|
|
747
|
+
if (error.code === "union") {
|
|
748
|
+
for (const e of error.errors) {
|
|
749
|
+
if (pathEquals(e.path, error.path))
|
|
750
|
+
e.propString ??= error.propString;
|
|
751
|
+
writeAtPaths(e, config, locale);
|
|
752
|
+
}
|
|
753
|
+
const shared = error.message === void 0 && unconfigured(error, config) && sharedMessageOf(error.errors, locale);
|
|
754
|
+
if (shared) {
|
|
755
|
+
error.message = shared;
|
|
756
|
+
sharing.add(error);
|
|
757
|
+
}
|
|
758
|
+
if (error.path.length !== 0 && error.expected === void 0 && error.message === void 0 && !unconfigured(error, config))
|
|
759
|
+
error.expected = relativeTo(error, config, locale, "").expected;
|
|
760
|
+
}
|
|
761
|
+
if (renderer && locale !== renderer.en)
|
|
762
|
+
renderer.write(error, config, locale);
|
|
763
|
+
else
|
|
764
|
+
writeText(error, config, locale);
|
|
765
|
+
};
|
|
766
|
+
var unconfigured = function (error, config) {
|
|
767
|
+
const message = configuredMessageOf(error);
|
|
768
|
+
return message === void 0 ? !configuresMessage(config, error.code) : message === defaultConfig[error.code].message;
|
|
769
|
+
};
|
|
770
|
+
var sharedMessageOf = function (errors, locale) {
|
|
771
|
+
let shared;
|
|
772
|
+
for (const e of errors) {
|
|
773
|
+
const text = configuredMessageOf(e) !== void 0 || suppliedText(e, "message") !== void 0 ? beginsAsOwn(e, locale) ? void 0 : e.message : e.code === "union" ? sharedMessageOf(e.errors, locale) : void 0;
|
|
774
|
+
if (text === void 0 || shared !== void 0 && text !== shared)
|
|
775
|
+
return;
|
|
776
|
+
shared = text;
|
|
777
|
+
}
|
|
778
|
+
return shared;
|
|
779
|
+
};
|
|
780
|
+
var writeText = function (error, config, locale, code = error.code) {
|
|
781
|
+
const writers = config[code];
|
|
782
|
+
const meta = error.meta;
|
|
783
|
+
let expected = error.expected;
|
|
784
|
+
if (expected === void 0 || expected === null) {
|
|
785
|
+
const configured = meta?.expected ?? writers.expected;
|
|
786
|
+
error.expected = expected = typeof configured === "function" ? configured(error, locale) : configured;
|
|
787
|
+
}
|
|
788
|
+
let described = false;
|
|
789
|
+
if (error.actual === void 0 || error.actual === null) {
|
|
790
|
+
const configured = meta?.actual ?? writers.actual;
|
|
791
|
+
if (typeof configured === "string")
|
|
792
|
+
error.actual = configured;
|
|
793
|
+
else {
|
|
794
|
+
if (describesData(configured)) {
|
|
795
|
+
describeUnwrittenActual(error);
|
|
796
|
+
described = true;
|
|
797
|
+
}
|
|
798
|
+
error.actual = configured(error.data, error, locale);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (error.message === void 0 || error.message === null) {
|
|
802
|
+
const message = meta?.message ?? (code === "required" ? configuredMessageOf(error) : void 0) ?? writers.message;
|
|
803
|
+
error.message = // en's own, written as it writes one whose actual describes its data
|
|
804
|
+
message === writeMessage && described ? `must be ${expected}` : typeof message === "function" ? message(error, locale) : message;
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
var writeActual = function (error, actual, locale) {
|
|
808
|
+
if (typeof actual === "string")
|
|
809
|
+
return actual;
|
|
810
|
+
if (describesData(actual))
|
|
811
|
+
describeActual(error);
|
|
812
|
+
return actual(error.data, error, locale);
|
|
813
|
+
};
|
|
814
|
+
var renderer;
|
|
815
|
+
var registerLocaleRenderer = (registered) => {
|
|
816
|
+
renderer = registered;
|
|
817
|
+
};
|
|
818
|
+
var defaultConfig;
|
|
819
|
+
var configureLocale = function (locale, base) {
|
|
820
|
+
if (defaultConfig !== base) {
|
|
821
|
+
defaultConfig = base;
|
|
822
|
+
messagesDefaulted = /* @__PURE__ */ new WeakMap();
|
|
823
|
+
lastDefaulted = void 0;
|
|
824
|
+
}
|
|
825
|
+
return renderer ? renderer.configure(locale, base) : locale === void 0 || locale === base.locale ? base.locale : throwError(unrenderedLocaleMessage);
|
|
826
|
+
};
|
|
827
|
+
var resolveLocale = function (locale) {
|
|
828
|
+
if (typeof locale !== "object" || locale === null || Array.isArray(locale))
|
|
829
|
+
throwParseError(writeInvalidLocaleObjectMessage(locale));
|
|
830
|
+
return renderer ? renderer.normalize(locale) : locale;
|
|
831
|
+
};
|
|
832
|
+
var writeInvalidLocaleObjectMessage = (locale) => `Expected a Locale object like \`de\` from "arktype/locales/de" (was ${printable(locale)})`;
|
|
833
|
+
var writtenIn = function (error, locale) {
|
|
834
|
+
const config = configOf(error);
|
|
835
|
+
if (!renderer && locale !== config.locale)
|
|
836
|
+
return throwError(unrenderedLocaleMessage);
|
|
837
|
+
const copy = unwrittenError(error);
|
|
838
|
+
writeError(copy, config, locale);
|
|
839
|
+
return copy;
|
|
840
|
+
};
|
|
841
|
+
var unwrittenError = function (error, prefix, config = configOf(error)) {
|
|
842
|
+
const input = inputOf(error);
|
|
843
|
+
const copy = {};
|
|
844
|
+
for (const k in error) {
|
|
845
|
+
if (!(k in writtenKeys))
|
|
846
|
+
copy[k] = error[k];
|
|
847
|
+
else if (k !== "propString" && input?.[k] !== void 0)
|
|
848
|
+
copy[k] = input[k];
|
|
849
|
+
}
|
|
850
|
+
if (input)
|
|
851
|
+
assignSymbols(copy, input);
|
|
852
|
+
copy.path = prefix ? [...prefix, ...error.path] : [...error.path];
|
|
853
|
+
if (error.code === "union")
|
|
854
|
+
copy.errors = error.errors.map((e) => unwrittenError(e, prefix, config));
|
|
855
|
+
const stamped = stampError(copy, config, input);
|
|
856
|
+
if (templated.has(error)) {
|
|
857
|
+
templated.add(stamped);
|
|
858
|
+
const line = error._l;
|
|
859
|
+
if (!prefix && line !== void 0)
|
|
860
|
+
noteLine(stamped, line);
|
|
861
|
+
}
|
|
862
|
+
const bases = basesByUnion.get(error);
|
|
863
|
+
if (bases) {
|
|
864
|
+
basesByUnion.set(stamped, bases.map((e) => unwrittenError(e, prefix, config)));
|
|
865
|
+
}
|
|
866
|
+
return stamped;
|
|
867
|
+
};
|
|
868
|
+
var writtenKeys = {
|
|
869
|
+
propString: 1,
|
|
870
|
+
expected: 1,
|
|
871
|
+
actual: 1,
|
|
872
|
+
message: 1
|
|
873
|
+
};
|
|
874
|
+
var summarize = function (issues, locale) {
|
|
875
|
+
let result = "";
|
|
876
|
+
for (let i = 0; i < issues.length; i++)
|
|
877
|
+
result += (i ? "\n" : "") + lineOf(issues[i], locale);
|
|
878
|
+
return result;
|
|
879
|
+
};
|
|
880
|
+
var jsonOf = function (error) { return ({
|
|
881
|
+
code: error.code,
|
|
882
|
+
path: error.path.map(jsonKeyOf),
|
|
883
|
+
...error.expected !== void 0 && { expected: error.expected },
|
|
884
|
+
message: error.message,
|
|
885
|
+
...error.code === "union" && error.errors.length > 0 ? { errors: error.errors.map(jsonOf) } : {}
|
|
886
|
+
}) };
|
|
887
|
+
var jsonKeyOf = (k) => typeof k === "symbol" ? String(k) : k;
|
|
888
|
+
var errorsToJson = {
|
|
889
|
+
value() {
|
|
890
|
+
return this.map(jsonOf);
|
|
891
|
+
},
|
|
892
|
+
writable: true,
|
|
893
|
+
configurable: true
|
|
894
|
+
};
|
|
895
|
+
var serializableErrors = (issues) => issues.toJSON ? issues : Object.defineProperty(issues, "toJSON", errorsToJson);
|
|
896
|
+
var firstIssue = (errors) => errors._first ?? errors.issues[0];
|
|
897
|
+
var byPath = function (errors) {
|
|
898
|
+
const result = {};
|
|
899
|
+
for (const error of errors.issues) {
|
|
900
|
+
const k = propStringOf(error);
|
|
901
|
+
if (!hasOwn(result, k))
|
|
902
|
+
defineEntry(result, k, error);
|
|
903
|
+
}
|
|
904
|
+
return result;
|
|
905
|
+
};
|
|
906
|
+
var flatByPath = function (errors) {
|
|
907
|
+
const result = {};
|
|
908
|
+
for (const error of errors.issues)
|
|
909
|
+
addEntry(result, propStringOf(error), error);
|
|
910
|
+
return result;
|
|
911
|
+
};
|
|
912
|
+
var flatMessagesByPath = function (errors) {
|
|
913
|
+
const result = {};
|
|
914
|
+
for (const error of errors.issues)
|
|
915
|
+
addEntry(result, propStringOf(error), error.message);
|
|
916
|
+
return result;
|
|
917
|
+
};
|
|
918
|
+
var byAncestorPath = function (errors) {
|
|
919
|
+
const result = {};
|
|
920
|
+
for (const error of errors.issues) {
|
|
921
|
+
let propString = "";
|
|
922
|
+
addEntry(result, propString, error);
|
|
923
|
+
for (const k of error.path) {
|
|
924
|
+
propString = appendStringifiedKey(propString, k);
|
|
925
|
+
addEntry(result, propString, error);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return result;
|
|
929
|
+
};
|
|
930
|
+
var propStringOf = (error) => error.propString ?? stringifyPath(error.path);
|
|
931
|
+
var addEntry = (result, k, value) => {
|
|
932
|
+
if (hasOwn(result, k))
|
|
933
|
+
result[k].push(value);
|
|
934
|
+
else
|
|
935
|
+
defineEntry(result, k, [value]);
|
|
936
|
+
};
|
|
937
|
+
var defineEntry = (result, k, value) => Object.defineProperty(result, k, {
|
|
938
|
+
value,
|
|
939
|
+
enumerable: true,
|
|
940
|
+
writable: true,
|
|
941
|
+
configurable: true
|
|
942
|
+
});
|
|
943
|
+
var configureAfterTypeMessage = "configure() must be called before any Type is created, so import the module calling it before any module that creates one";
|
|
944
|
+
var unrenderedLocaleMessage = 'import "arktype/i18n" to write errors in locales other than en';
|
|
945
|
+
var copiedErrorMessage = "Only errors validation returned can be written again, not copies";
|
|
946
|
+
|
|
947
|
+
// ../schema/out/shared/locale.js
|
|
948
|
+
var keywordPhraseOf = function (error, locale) {
|
|
949
|
+
const keyword = error.meta?.keyword;
|
|
950
|
+
return keyword === void 0 || !hasOwn(locale.keywordPhrases, keyword) ? void 0 : locale.keywordPhrases[keyword];
|
|
951
|
+
};
|
|
952
|
+
var keywordWriterOf = (error, locale, slot) => {
|
|
953
|
+
const phrase = keywordPhraseOf(error, locale);
|
|
954
|
+
return typeof phrase === "object" ? phrase[slot] : void 0;
|
|
955
|
+
};
|
|
956
|
+
var writeKeywordExpected = function (error, locale) {
|
|
957
|
+
const phrase = keywordPhraseOf(error, locale);
|
|
958
|
+
return typeof phrase !== "object" ? phrase : phrase.expected === void 0 ? phrase.noun : typeof phrase.expected === "string" ? phrase.expected : phrase.expected(error, locale);
|
|
959
|
+
};
|
|
960
|
+
var describeMissing = function (missing, locale) {
|
|
961
|
+
if (missing.code === "intersection")
|
|
962
|
+
return locale.nouns.unknown;
|
|
963
|
+
if (missing.code !== "union")
|
|
964
|
+
return describeBasis(missing, locale);
|
|
965
|
+
if (missing.branches.length === 0)
|
|
966
|
+
return locale.nouns.never;
|
|
967
|
+
if (isBooleanPair(missing.branches))
|
|
968
|
+
return locale.nouns.boolean;
|
|
969
|
+
return locale.list(describeEachMissing(missing, locale), "or");
|
|
970
|
+
};
|
|
971
|
+
var describeEachMissing = function (missing, locale) {
|
|
972
|
+
if (missing.code !== "union" || missing.branches.length === 0 || isBooleanPair(missing.branches))
|
|
973
|
+
return [describeMissing(missing, locale)];
|
|
974
|
+
const branches = [];
|
|
975
|
+
for (const branch of missing.branches)
|
|
976
|
+
appendUnique(branches, describeMissing(branch, locale));
|
|
977
|
+
return branches;
|
|
978
|
+
};
|
|
979
|
+
var describeBasis = function (basis, locale) { return (basis.code === "unit" || basis.code === "proto") && basis.meta.keyword === void 0 && basis.description !== defaultConfig[basis.code].description(basis) ? locale.cite(basis.description) : locale.basis(basis, locale) };
|
|
980
|
+
var isBooleanPair = function (values) { return values.length === 2 && values.every((value) => value.code === "unit" && typeof value.unit === "boolean" && value.meta?.description === void 0) };
|
|
981
|
+
var groupByPath = function (union, locale) {
|
|
982
|
+
const groups = [];
|
|
983
|
+
for (const error of union.errors) {
|
|
984
|
+
const group = groups.find((g) => g[0].propString === error.propString);
|
|
985
|
+
if (group)
|
|
986
|
+
group.push(error);
|
|
987
|
+
else
|
|
988
|
+
groups.push([error]);
|
|
989
|
+
}
|
|
990
|
+
return groups.map((group) => {
|
|
991
|
+
const expected = [];
|
|
992
|
+
if (isBooleanPair(group))
|
|
993
|
+
expected.push(locale.nouns.boolean);
|
|
994
|
+
else {
|
|
995
|
+
for (const error of group) {
|
|
996
|
+
for (const branch of alternativesOf(error, locale))
|
|
997
|
+
appendUnique(expected, branch);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
const actual = group[0].actual;
|
|
1001
|
+
const propString = group[0].propString;
|
|
1002
|
+
return {
|
|
1003
|
+
propString,
|
|
1004
|
+
// the union's title is its own value's, whatever its branches'
|
|
1005
|
+
label: (propString === union.propString ? labelOf(union) : void 0) ?? sharedLabelOf(group),
|
|
1006
|
+
expected,
|
|
1007
|
+
actual: group.every((error) => error.actual === actual) ? actual : void 0,
|
|
1008
|
+
data: group[0].data
|
|
1009
|
+
};
|
|
1010
|
+
});
|
|
1011
|
+
};
|
|
1012
|
+
var alternativesOf = function (error, locale) {
|
|
1013
|
+
if (error.code === "required") {
|
|
1014
|
+
return error.expected === describeMissing(error.missing, locale) ? describeEachMissing(error.missing, locale) : [error.expected];
|
|
1015
|
+
}
|
|
1016
|
+
const write = locale.discriminant.expected;
|
|
1017
|
+
if (error.code !== "discriminant" || typeof write !== "function")
|
|
1018
|
+
return [error.expected];
|
|
1019
|
+
const cases = error.cases.map((c) => write({ ...error, cases: [c] }, locale));
|
|
1020
|
+
return error.expected === locale.list(cases, "or") ? cases : [error.expected];
|
|
1021
|
+
};
|
|
1022
|
+
var actualAtPathOf = function (union) {
|
|
1023
|
+
let actual;
|
|
1024
|
+
for (const error of union.errors) {
|
|
1025
|
+
if (error.propString !== union.propString || actual !== void 0 && error.actual !== actual)
|
|
1026
|
+
return;
|
|
1027
|
+
actual = error.actual;
|
|
1028
|
+
}
|
|
1029
|
+
return actual;
|
|
1030
|
+
};
|
|
1031
|
+
var describeCause = (cause) => {
|
|
1032
|
+
try {
|
|
1033
|
+
return String(cause);
|
|
1034
|
+
} catch {
|
|
1035
|
+
return printable(cause);
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
var labelOf = function (error) { return error.code === "required" ? error.valueMeta.title : error.code === "undeclared" || error.code === "discriminant" && error.onKey ? (
|
|
1039
|
+
// their meta is the object's around the key
|
|
1040
|
+
void 0
|
|
1041
|
+
) : error.meta?.title };
|
|
1042
|
+
var sharedLabelOf = function (errors) {
|
|
1043
|
+
const labels = errors.map((error) => labelOf(error));
|
|
1044
|
+
return labels.every((label) => label === labels[0]) ? labels[0] : void 0;
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
// ../schema/out/shared/registry.js
|
|
1048
|
+
var _registryName = "$ark";
|
|
1049
|
+
var suffix = 2;
|
|
1050
|
+
while (_registryName in globalThis)
|
|
1051
|
+
_registryName = `$ark${suffix++}`;
|
|
1052
|
+
var registryName = _registryName;
|
|
1053
|
+
globalThis[registryName] = registry;
|
|
1054
|
+
var $ark = registry;
|
|
1055
|
+
var nodesById = {};
|
|
1056
|
+
$ark.nodesById = nodesById;
|
|
1057
|
+
var ambientResolver = {};
|
|
1058
|
+
var reference = (name) => `${registryName}.${name}`;
|
|
1059
|
+
var registeredReference = (value) => reference(register(value));
|
|
1060
|
+
var namedReference = (value) => reference(nameOf(value));
|
|
1061
|
+
|
|
1062
|
+
export {
|
|
1063
|
+
keywordWriterOf,
|
|
1064
|
+
writeKeywordExpected,
|
|
1065
|
+
describeMissing,
|
|
1066
|
+
groupByPath,
|
|
1067
|
+
alternativesOf,
|
|
1068
|
+
actualAtPathOf,
|
|
1069
|
+
describeCause,
|
|
1070
|
+
labelOf,
|
|
1071
|
+
errorWriters,
|
|
1072
|
+
errorWritersByCode,
|
|
1073
|
+
registerDescriber,
|
|
1074
|
+
describesData,
|
|
1075
|
+
listsErrors,
|
|
1076
|
+
ThrownErrors,
|
|
1077
|
+
ArkErrors,
|
|
1078
|
+
errorOfIssue,
|
|
1079
|
+
applyUnread,
|
|
1080
|
+
SiteTraversal,
|
|
1081
|
+
siteTraversalOf,
|
|
1082
|
+
ArkTraversal,
|
|
1083
|
+
errorFromContext,
|
|
1084
|
+
errorFromNodeAt,
|
|
1085
|
+
errorFromUnion,
|
|
1086
|
+
messageIn,
|
|
1087
|
+
invalidError,
|
|
1088
|
+
registerBuilderCompiler,
|
|
1089
|
+
isArkError,
|
|
1090
|
+
suppliedText,
|
|
1091
|
+
asTemplated,
|
|
1092
|
+
isCustom,
|
|
1093
|
+
isCustomError,
|
|
1094
|
+
configuredMessageOf,
|
|
1095
|
+
writeText,
|
|
1096
|
+
writeActual,
|
|
1097
|
+
registerLocaleRenderer,
|
|
1098
|
+
defaultConfig,
|
|
1099
|
+
configureLocale,
|
|
1100
|
+
writeInvalidLocaleObjectMessage,
|
|
1101
|
+
unwrittenError,
|
|
1102
|
+
serializableErrors,
|
|
1103
|
+
firstIssue,
|
|
1104
|
+
byPath,
|
|
1105
|
+
flatByPath,
|
|
1106
|
+
flatMessagesByPath,
|
|
1107
|
+
byAncestorPath,
|
|
1108
|
+
configureAfterTypeMessage,
|
|
1109
|
+
unrenderedLocaleMessage,
|
|
1110
|
+
copiedErrorMessage,
|
|
1111
|
+
registryName,
|
|
1112
|
+
$ark,
|
|
1113
|
+
nodesById,
|
|
1114
|
+
ambientResolver,
|
|
1115
|
+
reference,
|
|
1116
|
+
registeredReference,
|
|
1117
|
+
namedReference
|
|
1118
|
+
};
|