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,100 @@
|
|
|
1
|
+
import type { merge, show } from "../../util/index.js";
|
|
2
|
+
import type { UnknownErrorConfigs } from "../config.ts";
|
|
3
|
+
import type { nodeOfKind, reducibleKindOf } from "../kinds.ts";
|
|
4
|
+
import type { Disjoint } from "./disjoint.ts";
|
|
5
|
+
import type { ArkErrorCode, ArkErrors } from "./errors.ts";
|
|
6
|
+
import type { NarrowedAttachments, NodeKind } from "./implement.ts";
|
|
7
|
+
import type { JsonSchema } from "./jsonSchema.ts";
|
|
8
|
+
export interface DefaultArkEnv {
|
|
9
|
+
/** the scope strings resolve against, where unknown is arktype's keywords */
|
|
10
|
+
$(): unknown;
|
|
11
|
+
}
|
|
12
|
+
interface NodeMeta extends JsonSchema.UniversalMeta, UnknownErrorConfigs {
|
|
13
|
+
alias?: string;
|
|
14
|
+
/** the flat alias of the builtin keyword whose phrase describes this node */
|
|
15
|
+
keyword?: string;
|
|
16
|
+
/** the JSON Schema to write for this node in place of the one its constraints imply */
|
|
17
|
+
jsonSchema?: JsonSchema;
|
|
18
|
+
onFail?: ArkErrors.Handler;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What a program declares for arktype, by augmenting the module it imports:
|
|
22
|
+
*
|
|
23
|
+
* declare module "arktype" {
|
|
24
|
+
* interface ArkEnv {
|
|
25
|
+
* meta(): { secretIngredient?: string }
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* A module's interface, not a global one, so each copy of arktype in a
|
|
30
|
+
* program (a dependency's 2.x, or another 3.x) reads only what was declared
|
|
31
|
+
* for it. A global would merge every copy's declarations into one, typing one
|
|
32
|
+
* copy's strings with another's keywords and its calls with another's onFail.
|
|
33
|
+
*/
|
|
34
|
+
export interface ArkEnv extends DefaultArkEnv {
|
|
35
|
+
prototypes(): never;
|
|
36
|
+
}
|
|
37
|
+
export declare namespace ArkEnv {
|
|
38
|
+
type meta = show<NodeMeta & (ArkEnv extends {
|
|
39
|
+
meta(...args: never): infer meta;
|
|
40
|
+
} ? meta : {})>;
|
|
41
|
+
type onFail = ArkEnv extends {
|
|
42
|
+
onFail(...args: never): infer result;
|
|
43
|
+
} ? result : ArkErrors;
|
|
44
|
+
/** what a call passes for its narrows and morphs to read as `ctx.context` */
|
|
45
|
+
type context = ArkEnv extends {
|
|
46
|
+
context(...args: never): infer context;
|
|
47
|
+
} ? context : {};
|
|
48
|
+
/** classes `.infer` leaves opaque */
|
|
49
|
+
type prototypes = ReturnType<ArkEnv["prototypes"]>;
|
|
50
|
+
}
|
|
51
|
+
export type TypeMeta = Omit<ArkEnv.meta, "onFail">;
|
|
52
|
+
export declare namespace TypeMeta {
|
|
53
|
+
type Collapsible<meta extends TypeMeta = TypeMeta> = meta | string;
|
|
54
|
+
type Mapper<meta extends TypeMeta = TypeMeta> = (existing: Readonly<meta>) => meta;
|
|
55
|
+
type MappableInput<meta extends TypeMeta = TypeMeta> = Collapsible<meta> | Mapper<meta>;
|
|
56
|
+
namespace MappableInput {
|
|
57
|
+
type Internal = MappableInput<ArkEnv.meta>;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export interface BaseNodeInput {
|
|
61
|
+
readonly meta?: ArkEnv.meta | string;
|
|
62
|
+
}
|
|
63
|
+
interface DeclarationInput {
|
|
64
|
+
kind: NodeKind;
|
|
65
|
+
inner: object;
|
|
66
|
+
errorCtx?: BaseErrorContext;
|
|
67
|
+
reducibleTo?: NodeKind;
|
|
68
|
+
stacks?: true;
|
|
69
|
+
prerequisite?: unknown;
|
|
70
|
+
childKind?: NodeKind;
|
|
71
|
+
}
|
|
72
|
+
export interface BaseErrorContext<code extends NodeKind | ArkErrorCode = NodeKind> {
|
|
73
|
+
readonly description?: string;
|
|
74
|
+
readonly code: code;
|
|
75
|
+
readonly meta: ArkEnv.meta;
|
|
76
|
+
}
|
|
77
|
+
export type defaultErrorContext<d extends DeclarationInput> = show<BaseErrorContext<d["kind"]> & d["inner"]>;
|
|
78
|
+
export type declareNode<d extends {
|
|
79
|
+
[k in keyof d]: k extends keyof DeclarationInput ? DeclarationInput[k] : never;
|
|
80
|
+
} & DeclarationInput> = merge<{
|
|
81
|
+
stacks: false;
|
|
82
|
+
prerequisite: prerequisiteOf<d>;
|
|
83
|
+
childKind: never;
|
|
84
|
+
reducibleTo: d["kind"];
|
|
85
|
+
errorCtx: null;
|
|
86
|
+
}, d>;
|
|
87
|
+
type prerequisiteOf<d extends DeclarationInput> = "prerequisite" extends keyof d ? d["prerequisite"] : unknown;
|
|
88
|
+
export type attachmentsOf<d extends BaseNodeDeclaration> = NarrowedAttachments<d> & attachedInner<d>;
|
|
89
|
+
type attachedInner<d extends BaseNodeDeclaration> = "intersection" & d["kind"] extends never ? d["inner"] : {};
|
|
90
|
+
export interface BaseNodeDeclaration {
|
|
91
|
+
kind: NodeKind;
|
|
92
|
+
inner: {};
|
|
93
|
+
reducibleTo: NodeKind;
|
|
94
|
+
prerequisite: any;
|
|
95
|
+
stacks: boolean;
|
|
96
|
+
childKind: NodeKind;
|
|
97
|
+
errorCtx: BaseErrorContext | null;
|
|
98
|
+
}
|
|
99
|
+
export type ownIntersectionResult<d extends BaseNodeDeclaration> = nodeOfKind<reducibleKindOf<d["kind"]>> | Disjoint;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Key } from "../../util/index.js";
|
|
2
|
+
import type { nodeOfKind } from "../kinds.ts";
|
|
3
|
+
import type { BaseNode } from "../node.ts";
|
|
4
|
+
import type { BoundKind } from "../refinements/kinds.ts";
|
|
5
|
+
import type { Domain } from "../roots/domain.ts";
|
|
6
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
7
|
+
import type { Prop } from "../structure/prop.ts";
|
|
8
|
+
import type { UndeclaredKeyHandling } from "../structure/structure.ts";
|
|
9
|
+
export interface DisjointEntry<kind extends DisjointKind = DisjointKind> {
|
|
10
|
+
kind: kind;
|
|
11
|
+
l: OperandsByDisjointKind[kind];
|
|
12
|
+
r: OperandsByDisjointKind[kind];
|
|
13
|
+
path: Key[];
|
|
14
|
+
optional: boolean;
|
|
15
|
+
undeclared?: UndeclaredKeyHandling;
|
|
16
|
+
}
|
|
17
|
+
type OperandsByDisjointKind = {
|
|
18
|
+
domain: nodeOfKind<"domain"> | Domain.Enumerable;
|
|
19
|
+
unit: nodeOfKind<"unit">;
|
|
20
|
+
proto: nodeOfKind<"proto">;
|
|
21
|
+
presence: BaseRoot;
|
|
22
|
+
range: nodeOfKind<BoundKind>;
|
|
23
|
+
assignability: BaseNode | string;
|
|
24
|
+
union: readonly BaseRoot[];
|
|
25
|
+
};
|
|
26
|
+
export type DisjointEntryContext = {
|
|
27
|
+
path?: Key[];
|
|
28
|
+
optional?: true;
|
|
29
|
+
undeclared?: UndeclaredKeyHandling | undefined;
|
|
30
|
+
};
|
|
31
|
+
export declare class Disjoint extends Array<DisjointEntry> {
|
|
32
|
+
static init<kind extends DisjointKind>(kind: kind, l: OperandsByDisjointKind[kind], r: OperandsByDisjointKind[kind], ctx?: DisjointEntryContext): Disjoint;
|
|
33
|
+
add<kind extends DisjointKind>(kind: kind, l: OperandsByDisjointKind[kind], r: OperandsByDisjointKind[kind], ctx?: DisjointEntryContext): Disjoint;
|
|
34
|
+
get summary(): string;
|
|
35
|
+
describeReasons(): string;
|
|
36
|
+
private undeclaredHint;
|
|
37
|
+
throw(): never;
|
|
38
|
+
invert(): Disjoint;
|
|
39
|
+
withPrefixKey(key: PropertyKey, kind: Prop.Kind): Disjoint;
|
|
40
|
+
toNeverIfDisjoint(): BaseRoot;
|
|
41
|
+
}
|
|
42
|
+
export type DisjointKind = keyof OperandsByDisjointKind;
|
|
43
|
+
export declare const writeUnsatisfiableExpressionError: <expression extends string>(expression: expression) => writeUnsatisfiableExpressionError<expression>;
|
|
44
|
+
export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describeCollapsibleDate, printKind } from "../../util/index.js";
|
|
2
|
+
import type { ActualWriter, LineWriter, MessageWriter } from "./errors.ts";
|
|
3
|
+
import type { Locale } from "./locale.ts";
|
|
4
|
+
/**
|
|
5
|
+
* notes that an error's actual describes its data: a writer configured to
|
|
6
|
+
* read actual gets it, but en's messages leave it out, as a standalone
|
|
7
|
+
* validator's do without shipping a printer
|
|
8
|
+
*/
|
|
9
|
+
export declare const describeActual: (ctx: object) => void;
|
|
10
|
+
/**
|
|
11
|
+
* describeActual for a ctx whose actual is yet to be written, which is
|
|
12
|
+
* described already only where its actual was cleared since. It isn't asked
|
|
13
|
+
* first: V8 caches no answer for a private field an object lacks, so asking
|
|
14
|
+
* cost an error more than stamping it does
|
|
15
|
+
*/
|
|
16
|
+
export declare const describeUnwrittenActual: (ctx: object) => void;
|
|
17
|
+
/** the actual en's messages say a value was: one configured or supplied */
|
|
18
|
+
export declare const printedActualOf: (ctx: {
|
|
19
|
+
readonly actual: string;
|
|
20
|
+
}) => string;
|
|
21
|
+
export declare const writeMessage: MessageWriter;
|
|
22
|
+
export declare const writeLine: LineWriter;
|
|
23
|
+
export declare const writeUnitMessage: MessageWriter<"unit">;
|
|
24
|
+
export declare const writeUnitActual: ActualWriter<"unit">;
|
|
25
|
+
export declare const writeNotEqualActual: ActualWriter<"notEqual">;
|
|
26
|
+
export declare const writeDomainActual: ActualWriter<"domain">;
|
|
27
|
+
export declare const writeLengthActual: ActualWriter<"minLength" | "maxLength" | "exactLength" | "notEqualLength">;
|
|
28
|
+
export declare const writeProtoActual: ActualWriter<"proto">;
|
|
29
|
+
export declare const enInfo: Locale.Info;
|
|
30
|
+
export { describeCollapsibleDate, printKind };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "../config.ts";
|
|
2
|
+
import { ArkErrors, ArkTraversal, SiteTraversal, type ArkError } from "./errors.ts";
|
|
3
|
+
import { type RootApplyRuntime } from "./rootApply.ts";
|
|
4
|
+
import type { FailHandler } from "./traversal.ts";
|
|
5
|
+
export declare class ArkFirstIssueTraversal extends ArkTraversal {
|
|
6
|
+
get failFast(): boolean;
|
|
7
|
+
fin(onFail?: FailHandler | null): unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The errors a Type configured with `errors: "none"` returns: one issue at
|
|
11
|
+
* the root, whose message is `is invalid`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class UndetailedErrors extends ArkErrors {
|
|
14
|
+
get issues(): readonly ArkError[];
|
|
15
|
+
get _first(): ArkError | undefined;
|
|
16
|
+
get summary(): string;
|
|
17
|
+
summaryIn(): string;
|
|
18
|
+
get _i(): ArkError[];
|
|
19
|
+
}
|
|
20
|
+
export declare class UndetailedTraversal extends SiteTraversal {
|
|
21
|
+
createErrors(): UndetailedErrors;
|
|
22
|
+
fin(onFail?: FailHandler | null): unknown;
|
|
23
|
+
}
|
|
24
|
+
export declare const rejectUndetailed: (node: unknown, data: unknown, config: ResolvedConfig, onFail: FailHandler | null | undefined) => unknown;
|
|
25
|
+
export declare const errorModes: Record<"first" | "none", RootApplyRuntime>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type requireKeys } from "../../util/index.js";
|
|
2
|
+
import type { ErrorConfig } from "../config.ts";
|
|
3
|
+
import type { Declaration, Inner } from "../kinds.ts";
|
|
4
|
+
import type { BaseErrorContext } from "./declare.ts";
|
|
5
|
+
import type { ActualWriter, ArkErrorCode, MessageWriter } from "./errors.ts";
|
|
6
|
+
import type { NodeKind } from "./implement.ts";
|
|
7
|
+
export declare const errorWriters: {
|
|
8
|
+
actual: ActualWriter;
|
|
9
|
+
message: MessageWriter;
|
|
10
|
+
};
|
|
11
|
+
export declare const errorWritersByCode: {
|
|
12
|
+
[code in ArkErrorCode]: errorWritersOf<code>;
|
|
13
|
+
};
|
|
14
|
+
/** notes an actual writer describing data, like en's own */
|
|
15
|
+
export declare const registerDescriber: (writer: object) => void;
|
|
16
|
+
/**
|
|
17
|
+
* whether an error's actual is written by a writer describing its data,
|
|
18
|
+
* which en's messages leave out, rather than one configured
|
|
19
|
+
*/
|
|
20
|
+
export declare const describesData: (writer: unknown) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @internal whether a union's text is its errors', each naming its own path,
|
|
23
|
+
* rather than what's written of the union itself: it has none to list, like
|
|
24
|
+
* never, or says what it is or expects, by a description or a configured
|
|
25
|
+
* expected, which is written after `must be` and its path as any is
|
|
26
|
+
*/
|
|
27
|
+
export declare const listsErrors: (ctx: {
|
|
28
|
+
errors: readonly unknown[];
|
|
29
|
+
description?: string;
|
|
30
|
+
meta?: {
|
|
31
|
+
expected?: unknown;
|
|
32
|
+
};
|
|
33
|
+
}) => boolean;
|
|
34
|
+
export type errorWritersOf<code extends ArkErrorCode> = requireKeys<ErrorConfig<code>, code extends NodeKind ? Inner<code> extends (Omit<Declaration<code>["errorCtx"], keyof BaseErrorContext | "description">) ? never : "expected" : "expected">;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { type JsonArray, type array, type merge, type mutable, type omit, type propwiseXor, type show } from "../../util/index.js";
|
|
2
|
+
import type { ArkSchemaConfig, ResolvedConfig } from "../config.ts";
|
|
3
|
+
import type { NodeErrorContextsByKind, Prerequisite, errorCtx } from "../kinds.ts";
|
|
4
|
+
import type { BaseNode } from "../node.ts";
|
|
5
|
+
import type { DiscriminantErrorContext } from "../roots/union.ts";
|
|
6
|
+
import type { UndeclaredErrorContext } from "../structure/structure.ts";
|
|
7
|
+
import type { NodeKind } from "./implement.ts";
|
|
8
|
+
import type { Locale } from "./locale.ts";
|
|
9
|
+
import { ArkErrors as BaseArkErrors, isCustomIssue, TraversalError as BaseTraversalError, type ArkIssue, type CompactApply, type FailureSite, type SiteContext, type SiteFailureContext, type UnionSite } from "./issues.ts";
|
|
10
|
+
import { Traversal, type FailHandler, type InternalTraversal } from "./traversal.ts";
|
|
11
|
+
import type { ArkEnv } from "./declare.ts";
|
|
12
|
+
export { throwOnDefault } from "./issues.ts";
|
|
13
|
+
/**
|
|
14
|
+
* Thrown by a Type's `assert`, holding the errors it returned.
|
|
15
|
+
*/
|
|
16
|
+
interface ThrownErrors extends BaseTraversalError {
|
|
17
|
+
arkErrors: ArkErrors;
|
|
18
|
+
}
|
|
19
|
+
declare const ThrownErrors: new (errors: ArkErrors) => ThrownErrors;
|
|
20
|
+
export { ThrownErrors as TraversalError };
|
|
21
|
+
/**
|
|
22
|
+
* A failed check: its context, the data and path it failed at, and the text
|
|
23
|
+
* written for it when its errors are first read.
|
|
24
|
+
*/
|
|
25
|
+
export type ArkError<code extends ArkErrorCode = ArkErrorCode> = ArkErrorsByCode[code];
|
|
26
|
+
type ArkErrorsByCode = {
|
|
27
|
+
[code in ArkErrorCode]: mutable<omit<errorCtx<code>, "meta">> & WrittenErrorContext<code>;
|
|
28
|
+
};
|
|
29
|
+
export interface WrittenErrorContext<code extends ArkErrorCode> extends DerivableErrorContext<code> {
|
|
30
|
+
data: getAssociatedDataForError<code>;
|
|
31
|
+
path: PropertyKey[];
|
|
32
|
+
meta?: ArkEnv.meta;
|
|
33
|
+
}
|
|
34
|
+
export declare namespace ArkErrors {
|
|
35
|
+
type Handler<returns = unknown> = (errors: ArkErrors) => returns;
|
|
36
|
+
}
|
|
37
|
+
declare const writtenKey: unique symbol;
|
|
38
|
+
declare const localeKey: unique symbol;
|
|
39
|
+
declare const configKey: unique symbol;
|
|
40
|
+
/**
|
|
41
|
+
* The errors returned by a Type on invalid input, one issue for each failed
|
|
42
|
+
* check in the order each failed, as a standalone validator returns them.
|
|
43
|
+
*/
|
|
44
|
+
export declare class ArkErrors extends BaseArkErrors {
|
|
45
|
+
_: ArkError[];
|
|
46
|
+
[writtenKey]: number;
|
|
47
|
+
[localeKey]: Locale.Resolved | undefined;
|
|
48
|
+
[configKey]: ResolvedConfig;
|
|
49
|
+
constructor(config: ResolvedConfig);
|
|
50
|
+
/** @internal resets the fields its constructor sets */
|
|
51
|
+
_init(config: ResolvedConfig): void;
|
|
52
|
+
get " arkKind"(): "errors";
|
|
53
|
+
/**
|
|
54
|
+
* Each error, in the order it was added, with its text written in the
|
|
55
|
+
* locale selected when they were first read.
|
|
56
|
+
*/
|
|
57
|
+
get issues(): readonly ArkError[];
|
|
58
|
+
/** @internal the first of issues, its text written alone */
|
|
59
|
+
get _first(): ArkError | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* @internal the first of issues, found with the rest. Counted as written,
|
|
62
|
+
* so reading the rest doesn't write it again, which would note the line of
|
|
63
|
+
* a union listing its errors from the message already written from its own
|
|
64
|
+
* path, dropping the path before each error's
|
|
65
|
+
*/
|
|
66
|
+
_firstGrouped(): ArkError | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* A human-readable summary of all errors.
|
|
69
|
+
*/
|
|
70
|
+
get summary(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Each error's JSON: what it says and where, without its data or any other
|
|
73
|
+
* value only JavaScript holds, like its Type's `meta`.
|
|
74
|
+
*/
|
|
75
|
+
toJSON(): JsonArray;
|
|
76
|
+
/**
|
|
77
|
+
* The summary in `locale`, or as configured without one.
|
|
78
|
+
*/
|
|
79
|
+
summaryIn(locale?: Locale): string;
|
|
80
|
+
/** @internal */
|
|
81
|
+
_merge(merged: BaseArkErrors, prefix: array<PropertyKey>): void;
|
|
82
|
+
/** @internal the config its errors are written with */
|
|
83
|
+
get _config(): ResolvedConfig;
|
|
84
|
+
/** @internal the errors, without their text */
|
|
85
|
+
get _i(): ArkError[];
|
|
86
|
+
}
|
|
87
|
+
export declare const errorOfIssue: (issue: ArkIssue & {
|
|
88
|
+
message: string;
|
|
89
|
+
}, prefix: array<PropertyKey>, config: ResolvedConfig) => ArkError;
|
|
90
|
+
export declare const applyUnread: (node: BaseNode, data: unknown, config: ResolvedConfig, onFail: FailHandler | null, ctor: typeof Traversal) => unknown;
|
|
91
|
+
/**
|
|
92
|
+
* the traversal arktype's own compiled code reports to, which fails a site,
|
|
93
|
+
* at a key where it's passed one, and enters a key passed the site it fails
|
|
94
|
+
* where missing and its value. A validator's code passes neither a site nor a
|
|
95
|
+
* value, so its traversal holds none of this; one of these takes a
|
|
96
|
+
* validator's failures too, as each is named apart
|
|
97
|
+
*/
|
|
98
|
+
export declare class SiteTraversal extends Traversal implements SiteFailureContext {
|
|
99
|
+
/** @internal */
|
|
100
|
+
_at(site: FailureSite, data: unknown, key?: PropertyKey): boolean;
|
|
101
|
+
/** @internal */
|
|
102
|
+
_in(apply: CompactApply, data: unknown, key: PropertyKey, missing?: FailureSite, value?: unknown): boolean | undefined;
|
|
103
|
+
}
|
|
104
|
+
export declare const siteTraversalOf: (ctx: Traversal) => SiteTraversal;
|
|
105
|
+
export declare class ArkTraversal extends SiteTraversal {
|
|
106
|
+
createErrors(): ArkErrors;
|
|
107
|
+
nodeError<input extends NodeErrorContextInput>(input: input, data: unknown): ArkError<input["code"]>;
|
|
108
|
+
_at(site: FailureSite, data: unknown, key?: PropertyKey): boolean;
|
|
109
|
+
failsUnion(branches: readonly CompactApply[], site: UnionSite, data: unknown): boolean;
|
|
110
|
+
protected raise(input: ArkErrorInput): ArkError;
|
|
111
|
+
}
|
|
112
|
+
/** adds an error from a context at ctx's path */
|
|
113
|
+
export declare const errorFromContext: (ctx: InternalTraversal, input: ArkErrorContextInput) => ArkError;
|
|
114
|
+
/** adds a node's error at a path from ctx's, as a site's is added */
|
|
115
|
+
export declare const errorFromNodeAt: (ctx: InternalTraversal, context: SiteContext, relativePath: array<PropertyKey>, data: unknown) => ArkError;
|
|
116
|
+
/** adds a union's error from each branch's first */
|
|
117
|
+
export declare const errorFromUnion: (ctx: InternalTraversal, errors: readonly ArkError[], meta: ArkEnv.meta, data: unknown) => ArkError;
|
|
118
|
+
/**
|
|
119
|
+
* Writes an error's `message` in `locale`: what `error.message` would be had
|
|
120
|
+
* that locale been configured, never naming its path, e.g. `must be a string`
|
|
121
|
+
* where its line of `summaryIn(locale)` is `name must be a string`.
|
|
122
|
+
*/
|
|
123
|
+
export declare const messageIn: (error: ArkError, locale: Locale) => string;
|
|
124
|
+
/** an issue errors "none" added, written in en as saying its data is invalid */
|
|
125
|
+
export declare const invalidError: ({ data, path }: ArkIssue, config: ResolvedConfig) => ArkError;
|
|
126
|
+
export type ErrorBuilder = (context: ArkErrorContextInput, path: PropertyKey[], data: unknown, error: ArkError) => ArkError;
|
|
127
|
+
export declare const registerBuilderCompiler: (compile: (context: ArkErrorContextInput) => ErrorBuilder | undefined) => void;
|
|
128
|
+
/** an ArkError, not an issue errors "none" writes once read */
|
|
129
|
+
export declare const isArkError: (issue: ArkIssue) => issue is ArkError;
|
|
130
|
+
export declare const suppliedText: (error: ArkError, slot: "expected" | "actual" | "message") => string | undefined;
|
|
131
|
+
export { isCustomIssue };
|
|
132
|
+
/**
|
|
133
|
+
* @internal marks an error raised with a message arktype wrote from what it
|
|
134
|
+
* expected, like one read from another copy of arktype, so a summary writes it
|
|
135
|
+
* after its path as it does its own, or as `line`, where it listed its
|
|
136
|
+
* errors' whole paths
|
|
137
|
+
*/
|
|
138
|
+
export declare const asTemplated: <error extends ArkIssue>(error: error, line?: string) => error;
|
|
139
|
+
/**
|
|
140
|
+
* @internal whether an error's message was configured for its Type or code or
|
|
141
|
+
* supplied where it was raised, rather than written from what it expected
|
|
142
|
+
*/
|
|
143
|
+
export declare const isCustom: (error: ArkError) => boolean;
|
|
144
|
+
/**
|
|
145
|
+
* @internal whether an issue is an error of this copy of arktype whose message
|
|
146
|
+
* is custom: what a Type's Standard Schema props answer another copy reading
|
|
147
|
+
* one, which can't tell from what this copy's errors keep to themselves
|
|
148
|
+
*/
|
|
149
|
+
export declare const isCustomError: (issue: object) => boolean;
|
|
150
|
+
/**
|
|
151
|
+
* @internal the message configured for an error's Type. A message written out
|
|
152
|
+
* for a value says what's wrong with it however it fails, so it's a missing
|
|
153
|
+
* key's too
|
|
154
|
+
*/
|
|
155
|
+
export declare const configuredMessageOf: (error: ArkError) => MessageConfig<never> | undefined;
|
|
156
|
+
export declare const writeText: (error: ArkError, config: ResolvedConfig, locale: Locale.Resolved, code?: ArkErrorCode) => void;
|
|
157
|
+
/**
|
|
158
|
+
* an error's actual, noting one that describes its data, which en's messages
|
|
159
|
+
* leave out, so a configured writer still reads what the data was
|
|
160
|
+
*/
|
|
161
|
+
export declare const writeActual: (error: ArkError, actual: string | ActualWriter<never>, locale: Locale.Info) => string;
|
|
162
|
+
interface LocaleRenderer {
|
|
163
|
+
/** the locale errors.ts writes itself */
|
|
164
|
+
readonly en: Locale.Resolved;
|
|
165
|
+
/** the locale a configured locale resolves to, en if it's a function */
|
|
166
|
+
configure: (locale: ArkSchemaConfig["locale"], base: ResolvedConfig) => Locale.Resolved;
|
|
167
|
+
/** the locale errors are written in when they are first read */
|
|
168
|
+
select: (config: ResolvedConfig) => Locale.Resolved;
|
|
169
|
+
write: (error: ArkError, config: ResolvedConfig, locale: Locale.Resolved) => void;
|
|
170
|
+
/** a locale completed from en where it lacks a part */
|
|
171
|
+
normalize: (locale: Locale) => Locale.Resolved;
|
|
172
|
+
}
|
|
173
|
+
export declare const registerLocaleRenderer: (registered: LocaleRenderer) => void;
|
|
174
|
+
/** the default config, once one has resolved */
|
|
175
|
+
export declare let defaultConfig: ResolvedConfig;
|
|
176
|
+
export declare const configureLocale: (locale: ArkSchemaConfig["locale"], base: ResolvedConfig) => Locale.Resolved;
|
|
177
|
+
export declare const writeInvalidLocaleObjectMessage: (locale: unknown) => string;
|
|
178
|
+
export declare const unwrittenError: (error: ArkError, prefix?: array<PropertyKey>, config?: ResolvedConfig) => ArkError;
|
|
179
|
+
/** @internal attaches non-enumerable toJSON to an errors' issues array */
|
|
180
|
+
export declare const serializableErrors: (issues: ArkError[]) => readonly ArkError[];
|
|
181
|
+
/**
|
|
182
|
+
* The first of `errors.issues`, its text written without the rest's.
|
|
183
|
+
*/
|
|
184
|
+
export declare const firstIssue: (errors: ArkErrors) => ArkError;
|
|
185
|
+
/**
|
|
186
|
+
* The first error at each path, by the string of the path.
|
|
187
|
+
*/
|
|
188
|
+
export declare const byPath: (errors: ArkErrors) => Record<string, ArkError>;
|
|
189
|
+
/**
|
|
190
|
+
* Each path's errors, by the string of the path.
|
|
191
|
+
*/
|
|
192
|
+
export declare const flatByPath: (errors: ArkErrors) => Record<string, ArkError[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Each path's messages, by the string of the path.
|
|
195
|
+
*/
|
|
196
|
+
export declare const flatMessagesByPath: (errors: ArkErrors) => Record<string, string[]>;
|
|
197
|
+
/**
|
|
198
|
+
* All path strings at which errors are present mapped to the errors occuring
|
|
199
|
+
* at that path or any nested path within it.
|
|
200
|
+
*/
|
|
201
|
+
export declare const byAncestorPath: (errors: ArkErrors) => Record<string, ArkError[]>;
|
|
202
|
+
export interface DerivableErrorContext<code extends ArkErrorCode = ArkErrorCode> {
|
|
203
|
+
expected: string;
|
|
204
|
+
actual: string;
|
|
205
|
+
/** what failed, without the path it failed at, which a summary writes */
|
|
206
|
+
message: string;
|
|
207
|
+
data: getAssociatedDataForError<code>;
|
|
208
|
+
path: array<PropertyKey>;
|
|
209
|
+
propString: string;
|
|
210
|
+
}
|
|
211
|
+
export type DerivableErrorContextInput<code extends ArkErrorCode = ArkErrorCode> = Partial<DerivableErrorContext<code>> & propwiseXor<{
|
|
212
|
+
path?: array<PropertyKey>;
|
|
213
|
+
}, {
|
|
214
|
+
relativePath?: array<PropertyKey>;
|
|
215
|
+
prefixPath?: array<PropertyKey>;
|
|
216
|
+
}>;
|
|
217
|
+
export interface ErrorContextsByCode extends NodeErrorContextsByKind {
|
|
218
|
+
undeclared: UndeclaredErrorContext;
|
|
219
|
+
discriminant: DiscriminantErrorContext;
|
|
220
|
+
}
|
|
221
|
+
export type ArkErrorCode = keyof ErrorContextsByCode & string;
|
|
222
|
+
type ArkErrorContextInputsByCode = {
|
|
223
|
+
[code in ArkErrorCode]: errorCtx<code> & DerivableErrorContextInput<code>;
|
|
224
|
+
};
|
|
225
|
+
export type ArkErrorContextInput<code extends ArkErrorCode = ArkErrorCode> = merge<ArkErrorContextInputsByCode[code], {
|
|
226
|
+
meta?: ArkEnv.meta;
|
|
227
|
+
}>;
|
|
228
|
+
export type NodeErrorContextInput<code extends ArkErrorCode = ArkErrorCode> = ArkErrorContextInputsByCode[code] & {
|
|
229
|
+
meta: ArkEnv.meta;
|
|
230
|
+
};
|
|
231
|
+
export type MessageContext<code extends ArkErrorCode = ArkErrorCode> = code extends unknown ? omit<ArkError<code>, "message"> & unstringifiable : never;
|
|
232
|
+
type unstringifiable = {
|
|
233
|
+
toString(never: never): string;
|
|
234
|
+
toLocaleString(never: never): string;
|
|
235
|
+
};
|
|
236
|
+
/** an error as its line of a summary is written, once its message is */
|
|
237
|
+
export type LineContext<code extends ArkErrorCode = ArkErrorCode> = code extends unknown ? ArkError<code> & {
|
|
238
|
+
/** `true` where its message was configured or supplied, not written from what it expected */
|
|
239
|
+
readonly custom?: true;
|
|
240
|
+
} & unstringifiable : never;
|
|
241
|
+
export type LineWriter = (error: LineContext, locale: Locale.Info) => string;
|
|
242
|
+
export type CustomErrorInput = show<{
|
|
243
|
+
code?: undefined;
|
|
244
|
+
meta?: ArkEnv.meta;
|
|
245
|
+
} & DerivableErrorContextInput>;
|
|
246
|
+
/**
|
|
247
|
+
* the parts of an error `ctx.reject` takes. A string isn't one: it would be
|
|
248
|
+
* what the value must be, which `ctx.mustBe` takes, though it reads as the
|
|
249
|
+
* sentence a `message` is
|
|
250
|
+
*/
|
|
251
|
+
export type RejectInput = ArkErrorContextInput | CustomErrorInput;
|
|
252
|
+
export type ArkErrorInput = string | RejectInput;
|
|
253
|
+
export type MessageConfig<code extends ArkErrorCode = ArkErrorCode> = string | MessageWriter<code>;
|
|
254
|
+
export type MessageWriter<code extends ArkErrorCode = ArkErrorCode> = (error: MessageContext<code>, locale: Locale.Info) => string;
|
|
255
|
+
export type getAssociatedDataForError<code extends ArkErrorCode> = code extends NodeKind ? Prerequisite<code> : unknown;
|
|
256
|
+
export type ExpectedConfig<code extends ArkErrorCode = ArkErrorCode> = string | ExpectedWriter<code>;
|
|
257
|
+
export type ExpectedContext<code extends ArkErrorCode = ArkErrorCode> = code extends unknown ? omit<ArkError<code>, "expected" | "actual" | "message"> & unstringifiable : never;
|
|
258
|
+
export type ExpectedWriter<code extends ArkErrorCode = ArkErrorCode> = (error: ExpectedContext<code>, locale: Locale.Info) => string;
|
|
259
|
+
export type ActualConfig<code extends ArkErrorCode = ArkErrorCode> = string | ActualWriter<code>;
|
|
260
|
+
export type ActualContext<code extends ArkErrorCode = ArkErrorCode> = code extends unknown ? omit<ArkError<code>, "expected" | "description" | "actual" | "message"> & unstringifiable : never;
|
|
261
|
+
export type ActualWriter<code extends ArkErrorCode = ArkErrorCode> = (data: getAssociatedDataForError<code>, error: ActualContext<code>, locale: Locale.Info) => string;
|
|
262
|
+
export declare const configureAfterTypeMessage = "configure() must be called before any Type is created, so import the module calling it before any module that creates one";
|
|
263
|
+
export declare const unrenderedLocaleMessage = "import \"arktype/i18n\" to write errors in locales other than en";
|
|
264
|
+
export declare const copiedErrorMessage = "Only errors validation returned can be written again, not copies";
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { type Entry, type Json, type JsonObject, type JsonStructure, type KeySet, type arrayIndexOf, type keySetOf, type listable, type requireKeys, type show } from "../../util/index.js";
|
|
2
|
+
import type { NodeConfig, ResolvedUnknownNodeConfig } from "../config.ts";
|
|
3
|
+
import type { Declaration, nodeOfKind } from "../kinds.ts";
|
|
4
|
+
import type { BaseNode } from "../node.ts";
|
|
5
|
+
import type { NodeId } from "../parse.ts";
|
|
6
|
+
import type { BaseRoot, schemaKindOrRightOf, schemaKindRightOf } from "../roots/root.ts";
|
|
7
|
+
import type { BaseScope, ResolvedScopeConfig } from "../scope.ts";
|
|
8
|
+
import type { Structure } from "../structure/structure.ts";
|
|
9
|
+
import type { ArkEnv, BaseNodeDeclaration } from "./declare.ts";
|
|
10
|
+
import type { Disjoint } from "./disjoint.ts";
|
|
11
|
+
import { type makeRootAndArrayPropertiesMutable } from "./utils.ts";
|
|
12
|
+
export declare const basisKinds: readonly ["unit", "proto", "domain"];
|
|
13
|
+
export type BasisKind = (typeof basisKinds)[number];
|
|
14
|
+
export declare const structuralKinds: readonly ["required", "optional", "index", "sequence"];
|
|
15
|
+
export type StructuralKind = (typeof structuralKinds)[number];
|
|
16
|
+
export declare const prestructuralKinds: readonly ["pattern", "divisor", "exactLength", "max", "min", "maxLength", "minLength", "before", "after", "notEqual", "notEqualLength"];
|
|
17
|
+
export type PrestructuralKind = (typeof prestructuralKinds)[number];
|
|
18
|
+
export declare const refinementKinds: readonly ["pattern", "divisor", "exactLength", "max", "min", "maxLength", "minLength", "before", "after", "notEqual", "notEqualLength", "structure", "predicate"];
|
|
19
|
+
export type RefinementKind = (typeof refinementKinds)[number];
|
|
20
|
+
export declare const constraintKinds: readonly ["pattern", "divisor", "exactLength", "max", "min", "maxLength", "minLength", "before", "after", "notEqual", "notEqualLength", "structure", "predicate", "required", "optional", "index", "sequence"];
|
|
21
|
+
export type ConstraintKind = (typeof constraintKinds)[number];
|
|
22
|
+
export declare const rootKinds: readonly ["alias", "union", "morph", "unit", "intersection", "proto", "domain"];
|
|
23
|
+
export type RootKind = (typeof rootKinds)[number];
|
|
24
|
+
export type NodeKind = RootKind | ConstraintKind;
|
|
25
|
+
type orderedNodeKinds = [...typeof rootKinds, ...typeof constraintKinds];
|
|
26
|
+
export declare const nodeKinds: orderedNodeKinds;
|
|
27
|
+
export type OpenNodeKind = {
|
|
28
|
+
[k in NodeKind]: Declaration<k>["stacks"] extends true ? k : never;
|
|
29
|
+
}[NodeKind];
|
|
30
|
+
export type ClosedNodeKind = Exclude<NodeKind, OpenNodeKind>;
|
|
31
|
+
export type PrimitiveKind = Exclude<RefinementKind | BasisKind, "structure">;
|
|
32
|
+
export type CompositeKind = Exclude<NodeKind, PrimitiveKind>;
|
|
33
|
+
export type OrderedNodeKinds = typeof nodeKinds;
|
|
34
|
+
export declare const constraintKeys: KeySet<ConstraintKind>;
|
|
35
|
+
export declare const structureKeys: keySetOf<Structure.Inner>;
|
|
36
|
+
type RightsByKind = accumulateRightKinds<OrderedNodeKinds, {}>;
|
|
37
|
+
export type kindOrRightOf<kind extends NodeKind> = kind | kindRightOf<kind>;
|
|
38
|
+
export type kindLeftOf<kind extends NodeKind> = Exclude<NodeKind, kindOrRightOf<kind>>;
|
|
39
|
+
export type kindOrLeftOf<kind extends NodeKind> = kind | kindLeftOf<kind>;
|
|
40
|
+
type accumulateRightKinds<remaining extends readonly NodeKind[], result> = remaining extends (readonly [infer head extends NodeKind, ...infer tail extends NodeKind[]]) ? accumulateRightKinds<tail, result & {
|
|
41
|
+
[k in head]: tail[number];
|
|
42
|
+
}> : result;
|
|
43
|
+
export interface InternalIntersectionOptions {
|
|
44
|
+
pipe: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface IntersectionContext extends InternalIntersectionOptions {
|
|
47
|
+
$: BaseScope;
|
|
48
|
+
invert: boolean;
|
|
49
|
+
}
|
|
50
|
+
export type ConstraintIntersection<lKind extends ConstraintKind, rKind extends kindOrRightOf<lKind>> = (l: nodeOfKind<lKind>, r: nodeOfKind<rKind>, ctx: IntersectionContext) => BaseNode | Disjoint | null;
|
|
51
|
+
export type ConstraintIntersectionMap<kind extends ConstraintKind> = show<{
|
|
52
|
+
[_ in kind]: ConstraintIntersection<kind, kind>;
|
|
53
|
+
} & {
|
|
54
|
+
[rKind in kindRightOf<kind>]?: ConstraintIntersection<kind, rKind>;
|
|
55
|
+
}>;
|
|
56
|
+
export type RootIntersection<lKind extends RootKind, rKind extends schemaKindOrRightOf<lKind>> = (l: nodeOfKind<lKind>, r: nodeOfKind<rKind>, ctx: IntersectionContext) => BaseRoot | Disjoint;
|
|
57
|
+
export type TypeIntersectionMap<kind extends RootKind> = {
|
|
58
|
+
[rKind in schemaKindOrRightOf<kind>]: RootIntersection<kind, rKind>;
|
|
59
|
+
};
|
|
60
|
+
export type IntersectionMap<kind extends NodeKind> = kind extends RootKind ? TypeIntersectionMap<kind> : ConstraintIntersectionMap<kind & ConstraintKind>;
|
|
61
|
+
export type UnknownIntersectionMap = {
|
|
62
|
+
[k in NodeKind]?: (l: BaseNode, r: BaseNode, ctx: IntersectionContext) => UnknownIntersectionResult;
|
|
63
|
+
};
|
|
64
|
+
export type UnknownIntersectionResult = BaseNode | Disjoint | null;
|
|
65
|
+
type PrecedenceByKind = {
|
|
66
|
+
[i in arrayIndexOf<OrderedNodeKinds> as OrderedNodeKinds[i]]: i;
|
|
67
|
+
};
|
|
68
|
+
export declare const precedenceByKind: PrecedenceByKind;
|
|
69
|
+
export declare const isNodeKind: (value: unknown) => value is NodeKind;
|
|
70
|
+
export declare function assertNodeKind<kind extends NodeKind>(value: BaseNode, kind: kind): asserts value is nodeOfKind<kind>;
|
|
71
|
+
export type precedenceOfKind<kind extends NodeKind> = PrecedenceByKind[kind];
|
|
72
|
+
export declare const precedenceOfKind: <kind extends NodeKind>(kind: kind) => precedenceOfKind<kind>;
|
|
73
|
+
export type kindRightOf<kind extends NodeKind> = RightsByKind[kind];
|
|
74
|
+
export declare const schemaKindsRightOf: <kind extends RootKind>(kind: kind) => schemaKindRightOf<kind>[];
|
|
75
|
+
export declare const unionChildKinds: readonly [...("domain" | "intersection" | "morph" | "proto" | "unit")[], "alias"];
|
|
76
|
+
export type UnionChildKind = (typeof unionChildKinds)[number];
|
|
77
|
+
export declare const morphChildKinds: readonly [...("domain" | "intersection" | "proto" | "unit")[], "alias"];
|
|
78
|
+
export type MorphChildKind = (typeof morphChildKinds)[number];
|
|
79
|
+
export type keyImplementationsOf<d extends BaseNodeDeclaration> = {
|
|
80
|
+
[k in keyof d["inner"]]-?: NodeKeyImplementation<d, k>;
|
|
81
|
+
};
|
|
82
|
+
export declare const defaultValueSerializer: (v: unknown) => Json;
|
|
83
|
+
export declare const metaJsonOf: (meta: ArkEnv.meta) => JsonObject;
|
|
84
|
+
export type NodeKeyImplementation<d extends BaseNodeDeclaration, k extends keyof d["inner"], instantiated = Exclude<d["inner"][k], undefined>> = requireKeys<{
|
|
85
|
+
/** whether an undefined value is kept as the key's value rather than dropped */
|
|
86
|
+
keepUndef?: true;
|
|
87
|
+
child?: boolean | ((value: instantiated) => BaseNode[]);
|
|
88
|
+
serialize?: (schema: instantiated) => Json;
|
|
89
|
+
structural?: true;
|
|
90
|
+
unserialized?: true;
|
|
91
|
+
reduceIo?: (ioKind: "in" | "out", inner: makeRootAndArrayPropertiesMutable<d["inner"]>, value: d["inner"][k], node: BaseNode) => void;
|
|
92
|
+
}, [
|
|
93
|
+
instantiated
|
|
94
|
+
] extends [listable<BaseNode>] ? "child" : never>;
|
|
95
|
+
interface CommonNodeImplementationInput<d extends BaseNodeDeclaration> {
|
|
96
|
+
kind: d["kind"];
|
|
97
|
+
keys: keyImplementationsOf<d>;
|
|
98
|
+
applyConfig?: (inner: d["inner"], config: ResolvedScopeConfig) => d["inner"];
|
|
99
|
+
/** whether it reports its own error when data fails it, rather than its children's */
|
|
100
|
+
ownErr: d["errorCtx"] extends null ? false : true;
|
|
101
|
+
/** rewrites its inner JSON once it's written, e.g. to collapse a key */
|
|
102
|
+
fixJson?: (json: {
|
|
103
|
+
[k in keyof d["inner"]]: Json;
|
|
104
|
+
}) => JsonStructure;
|
|
105
|
+
/** the key whose value stands for its whole json when it's all the json holds */
|
|
106
|
+
bareKey?: keyof d["inner"];
|
|
107
|
+
/** whether its description says what its basis would, so the basis isn't described */
|
|
108
|
+
coversNoun?: d["kind"] extends RefinementKind ? true : never;
|
|
109
|
+
/** whether its expression says what its basis would, so the basis isn't written */
|
|
110
|
+
coversExpr?: d["kind"] extends RefinementKind ? true : never;
|
|
111
|
+
}
|
|
112
|
+
export interface UnknownNodeImplementation extends CommonNodeImplementationInput<BaseNodeDeclaration> {
|
|
113
|
+
defaults: ResolvedUnknownNodeConfig;
|
|
114
|
+
/** whether one intersection can hold several of its kind, as narrows and `!=` can */
|
|
115
|
+
stacks: boolean;
|
|
116
|
+
keys: Record<string, NodeKeyImplementation<any, any>>;
|
|
117
|
+
}
|
|
118
|
+
export declare const compileObjectLiteral: (ctx: object) => string;
|
|
119
|
+
export type nodeImplementationOf<d extends BaseNodeDeclaration> = nodeImplementationInputOf<d> & {
|
|
120
|
+
stacks: d["stacks"];
|
|
121
|
+
defaults: Required<NodeConfig<d["kind"]>>;
|
|
122
|
+
};
|
|
123
|
+
export type nodeImplementationInputOf<d extends BaseNodeDeclaration> = CommonNodeImplementationInput<d> & {
|
|
124
|
+
defaults: {
|
|
125
|
+
description: DescriptionWriter<d["kind"]>;
|
|
126
|
+
};
|
|
127
|
+
} & (d["stacks"] extends true ? {
|
|
128
|
+
stacks: true;
|
|
129
|
+
} : {});
|
|
130
|
+
export type DescriptionWriter<kind extends NodeKind = NodeKind> = (node: nodeOfKind<kind>) => string;
|
|
131
|
+
export interface UnknownAttachments {
|
|
132
|
+
readonly kind: NodeKind;
|
|
133
|
+
readonly impl: UnknownNodeImplementation;
|
|
134
|
+
readonly id: NodeId;
|
|
135
|
+
readonly inner: Record<string, any>;
|
|
136
|
+
readonly kv: readonly Entry<string>[];
|
|
137
|
+
readonly meta: ArkEnv.meta;
|
|
138
|
+
readonly metaJson: object;
|
|
139
|
+
readonly children: BaseNode[];
|
|
140
|
+
}
|
|
141
|
+
export interface UnknownAttachmentsInput extends Omit<UnknownAttachments, "kv" | "metaJson"> {
|
|
142
|
+
readonly metaJson: object | undefined;
|
|
143
|
+
readonly shell?: {
|
|
144
|
+
fn: Function;
|
|
145
|
+
c: object;
|
|
146
|
+
} | undefined;
|
|
147
|
+
}
|
|
148
|
+
export interface NarrowedAttachments<d extends BaseNodeDeclaration> extends UnknownAttachments {
|
|
149
|
+
kind: d["kind"];
|
|
150
|
+
inner: d["inner"];
|
|
151
|
+
children: nodeOfKind<d["childKind"]>[];
|
|
152
|
+
}
|
|
153
|
+
export declare const implementNode: <d extends BaseNodeDeclaration = never>(_: nodeImplementationInputOf<d>) => nodeImplementationOf<d>;
|
|
154
|
+
export {};
|