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,288 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "../config.ts";
|
|
2
|
+
import type { BaseNode } from "../node.ts";
|
|
3
|
+
import type { Predicate } from "../predicate.ts";
|
|
4
|
+
import type { Morph } from "../roots/morph.ts";
|
|
5
|
+
import type { ArkError, ArkErrorCode, ArkErrorInput, ArkErrors, NodeErrorContextInput, RejectInput } from "./errors.ts";
|
|
6
|
+
import { ArkErrors as BaseArkErrors, type ArkIssue, type CompactApply, type FailureContext, type MissingText, type SiteContext, type UnionSite } from "./issues.ts";
|
|
7
|
+
import type { StandardSchemaV1 } from "./standardSchema.ts";
|
|
8
|
+
import { TransformErrors } from "./transform.ts";
|
|
9
|
+
import type { ArkEnv } from "./declare.ts";
|
|
10
|
+
export type FailHandler = (errors: never) => unknown;
|
|
11
|
+
export type BranchTraversal = {
|
|
12
|
+
error: ArkIssue | undefined;
|
|
13
|
+
/** the errors the branch has added */
|
|
14
|
+
errN: number;
|
|
15
|
+
};
|
|
16
|
+
export declare class InternalTraversal implements FailureContext {
|
|
17
|
+
/**
|
|
18
|
+
* #### the path being validated or morphed
|
|
19
|
+
*
|
|
20
|
+
* ✅ array indices represented as numbers
|
|
21
|
+
* ⚠️ mutated during traversal - use `path.slice(0)` to snapshot
|
|
22
|
+
* 🔗 use {@link propString} for a stringified version
|
|
23
|
+
*/
|
|
24
|
+
path: PropertyKey[];
|
|
25
|
+
_errors: BaseArkErrors | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* #### the original value being traversed
|
|
28
|
+
*/
|
|
29
|
+
root: unknown;
|
|
30
|
+
/**
|
|
31
|
+
* #### configuration for this traversal
|
|
32
|
+
*
|
|
33
|
+
* ✅ options can affect traversal results and error messages
|
|
34
|
+
* ✅ defaults < global config < scope config
|
|
35
|
+
* ✅ does not include options configured on individual types
|
|
36
|
+
*/
|
|
37
|
+
config: ResolvedConfig;
|
|
38
|
+
branches: BranchTraversal[];
|
|
39
|
+
/** what it tracks of the cyclic nodes it enters, once it enters one */
|
|
40
|
+
res: Resolutions | undefined;
|
|
41
|
+
/** whether data a root allowed within the bounds is a tree, so each path is transformed */
|
|
42
|
+
isTree: boolean;
|
|
43
|
+
/** each cyclic node's transformed data, keyed by the input it transformed */
|
|
44
|
+
tfdById: {
|
|
45
|
+
[id in string]?: Map<unknown, unknown>;
|
|
46
|
+
} | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* the data the innermost running morph received, which `data` reads
|
|
49
|
+
* from, since root is the input
|
|
50
|
+
*/
|
|
51
|
+
recv: unknown;
|
|
52
|
+
/** how deep in the root's path the data a morph received is */
|
|
53
|
+
recvAt: number;
|
|
54
|
+
/** whether a piped node is only checked, to be transformed once Apply finds it valid */
|
|
55
|
+
chkOnly: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* the error count a running morph started from, since it fails by
|
|
58
|
+
* returning any error ctx.error adds after
|
|
59
|
+
*/
|
|
60
|
+
retFrom: number | undefined;
|
|
61
|
+
inPlace?: true;
|
|
62
|
+
/**
|
|
63
|
+
* #### the context this validation was called with
|
|
64
|
+
*
|
|
65
|
+
* ✅ the same object at every path, for predicates and morphs to read
|
|
66
|
+
* ✅ `undefined` when a call passes none
|
|
67
|
+
* ✅ typed as declared on `ArkEnv`: `interface ArkEnv { context(): {...} }`
|
|
68
|
+
*/
|
|
69
|
+
context: ArkEnv.context | undefined;
|
|
70
|
+
constructor(root: unknown, config: ResolvedConfig);
|
|
71
|
+
/**
|
|
72
|
+
* #### whether {@link currentBranch} (or the traversal root, outside a union) has one or more errors
|
|
73
|
+
*/
|
|
74
|
+
hasError(): boolean;
|
|
75
|
+
get currentBranch(): BranchTraversal | undefined;
|
|
76
|
+
/** its result: the data, or its errors passed to `onFail` if it has any */
|
|
77
|
+
fin(onFail?: FailHandler | null): unknown;
|
|
78
|
+
/** how many errors the current union branch has, or the traversal has outside a union */
|
|
79
|
+
get errN(): number;
|
|
80
|
+
get failFast(): boolean;
|
|
81
|
+
/** starts counting a union branch's errors */
|
|
82
|
+
pushBr(): void;
|
|
83
|
+
/** stops counting the innermost union branch's errors, returning it */
|
|
84
|
+
popBr(): BranchTraversal | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
* Convenience for casting from InternalTraversal to Traversal
|
|
88
|
+
* for cases where the extra methods on the external type are expected, e.g.
|
|
89
|
+
* a morph or predicate.
|
|
90
|
+
*/
|
|
91
|
+
get external(): Traversal;
|
|
92
|
+
/**
|
|
93
|
+
* an error from a node's context and the data it rejected
|
|
94
|
+
*
|
|
95
|
+
* @internal a node's error, which arktype's traversal writes from its
|
|
96
|
+
* context, and this one, checking Allows for arktype, adds as an issue
|
|
97
|
+
*/
|
|
98
|
+
nodeError<input extends NodeErrorContextInput>(input: input, data: unknown): ArkError<input["code"]>;
|
|
99
|
+
/** @internal a validator's failure, as its errors take one */
|
|
100
|
+
_e(data: unknown, code: ArkErrorCode, expected?: string, message?: string, text?: SiteContext["text"]): boolean;
|
|
101
|
+
/** @internal a validator's key, as its errors enter one */
|
|
102
|
+
_k(apply: CompactApply, data: unknown, key: PropertyKey, ...missing: MissingText): boolean | undefined;
|
|
103
|
+
/** @internal */
|
|
104
|
+
failsUnion(branches: readonly CompactApply[], site: UnionSite, data: unknown): boolean;
|
|
105
|
+
/** @internal */
|
|
106
|
+
addError<error extends ArkIssue>(error: error): error;
|
|
107
|
+
/**
|
|
108
|
+
* @internal adds the errors of a validator called with this traversal,
|
|
109
|
+
* returning its own
|
|
110
|
+
*/
|
|
111
|
+
piped(errors: BaseArkErrors): BaseArkErrors;
|
|
112
|
+
/** @internal */
|
|
113
|
+
createErrors(): BaseArkErrors;
|
|
114
|
+
failBranch(error: ArkIssue): void;
|
|
115
|
+
}
|
|
116
|
+
export declare class Traversal extends InternalTraversal {
|
|
117
|
+
/**
|
|
118
|
+
* #### {@link ArkErrors} that will be part of this traversal's finalized result
|
|
119
|
+
*
|
|
120
|
+
* ✅ will always be empty for a valid traversal
|
|
121
|
+
*/
|
|
122
|
+
get errors(): ArkErrors;
|
|
123
|
+
/**
|
|
124
|
+
* #### the data being validated or morphed
|
|
125
|
+
*
|
|
126
|
+
* ✅ the value at {@link path}, as transformed by any morphs that have already run
|
|
127
|
+
*/
|
|
128
|
+
get data(): unknown;
|
|
129
|
+
/**
|
|
130
|
+
* #### a string representing {@link path}
|
|
131
|
+
*
|
|
132
|
+
* ✅ uses `.access` {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#dot_notation | where allowed by JS}, falling back to `[indexAccess]`
|
|
133
|
+
* @example
|
|
134
|
+
* const path = ["key1", Symbol("key2"), "key3", 4, "~key5"]
|
|
135
|
+
* const propString = 'key1[Symbol(key2)].key3[4]["~key5"]'
|
|
136
|
+
*/
|
|
137
|
+
get propString(): string;
|
|
138
|
+
/**
|
|
139
|
+
* #### add an {@link ArkError} and return `false`
|
|
140
|
+
*
|
|
141
|
+
* ✅ useful for predicates like `.narrow`
|
|
142
|
+
* ✅ `{ message: "Enter a valid email" }` is the whole sentence an issue says
|
|
143
|
+
* 🔗 to say what the value must be, as `must be even`, pass `"even"` to {@link mustBe}
|
|
144
|
+
*/
|
|
145
|
+
reject(input: RejectInput): false;
|
|
146
|
+
/**
|
|
147
|
+
* #### add an {@link ArkError} from a description and return `false`
|
|
148
|
+
*
|
|
149
|
+
* ✅ useful for predicates like `.narrow`
|
|
150
|
+
* 🔗 equivalent to {@link reject}({ expected })
|
|
151
|
+
*/
|
|
152
|
+
mustBe(expected: string): false;
|
|
153
|
+
/**
|
|
154
|
+
* #### add and return an {@link ArkError}
|
|
155
|
+
*
|
|
156
|
+
* ✅ useful for morphs like `.pipe`
|
|
157
|
+
* ⚠️ a string is what the value must be: `error("valid JSON")` reads `must be valid JSON`, so pass a sentence as `{ message }`
|
|
158
|
+
*/
|
|
159
|
+
error<input extends ArkErrorInput>(input: input): ArkError<input extends {
|
|
160
|
+
code: ArkErrorCode;
|
|
161
|
+
} ? input["code"] : "predicate">;
|
|
162
|
+
protected raise(input: ArkErrorInput): ArkError;
|
|
163
|
+
}
|
|
164
|
+
export declare class FirstIssueTraversal extends Traversal {
|
|
165
|
+
get failFast(): boolean;
|
|
166
|
+
fin(onFail?: FailHandler | null): unknown;
|
|
167
|
+
}
|
|
168
|
+
export declare const throwOnProblem: (input: ArkErrorInput) => void;
|
|
169
|
+
export declare const errorsOf: (ctx: InternalTraversal) => BaseArkErrors;
|
|
170
|
+
export declare const applyRejected: (node: BaseNode, data: unknown, config: ResolvedConfig, onFail: FailHandler | null, ctor: typeof InternalTraversal) => unknown;
|
|
171
|
+
export declare const describePredicate: (ctx: {
|
|
172
|
+
predicate?: Predicate;
|
|
173
|
+
morph?: Morph;
|
|
174
|
+
}) => string;
|
|
175
|
+
export declare const tryMorph: (morph: Morph) => Morph;
|
|
176
|
+
export declare const execMorph: (regex: RegExp) => Morph;
|
|
177
|
+
export declare const callMorph: (ctx: InternalTraversal, morph: Morph, data: unknown) => unknown;
|
|
178
|
+
export declare const transform: (ctx: InternalTraversal, node: BaseNode, data: unknown) => unknown;
|
|
179
|
+
export declare const transformed: (ctx: InternalTraversal, result: unknown, data: unknown) => unknown;
|
|
180
|
+
export declare const pipeOf: (node: BaseNode) => TraversePipe;
|
|
181
|
+
export type TraversePipe = (ctx: InternalTraversal, node: BaseNode, data: unknown) => unknown;
|
|
182
|
+
export declare const pipeChecked: TraversePipe;
|
|
183
|
+
export declare const pipeApplied: TraversePipe;
|
|
184
|
+
export declare const pipeTransformed: TraversePipe;
|
|
185
|
+
export declare const pipe: TraversePipe;
|
|
186
|
+
export declare const transformsValid: (ctx: InternalTraversal) => boolean;
|
|
187
|
+
export declare const transformedInApply: (ctx: InternalTraversal, result: unknown) => void;
|
|
188
|
+
export declare const transformIfAllowed: (ctx: InternalTraversal, node: BaseNode, data: unknown) => boolean;
|
|
189
|
+
export declare const allowsInBranch: (ctx: InternalTraversal, node: BaseNode, data: unknown) => boolean;
|
|
190
|
+
export declare const silentCtx: {
|
|
191
|
+
mustBe: () => false;
|
|
192
|
+
reject: () => false;
|
|
193
|
+
readonly context: ArkEnv.context | undefined;
|
|
194
|
+
};
|
|
195
|
+
/** runs a validation, whose traversals each read `context` */
|
|
196
|
+
export declare const inContext: <result>(context: ArkEnv.context | undefined, run: () => result) => result;
|
|
197
|
+
/** runs `run`, where each read of a traversal's context calls `onRead` */
|
|
198
|
+
export declare const readingContextWith: <result>(onRead: () => never, run: () => result) => result;
|
|
199
|
+
/** what `withContext` binds: a Type, or the validator a build precompiled from one */
|
|
200
|
+
export interface ContextualTarget {
|
|
201
|
+
(data: unknown): unknown;
|
|
202
|
+
assert(data: unknown): unknown;
|
|
203
|
+
allows(data: unknown): boolean;
|
|
204
|
+
"~standard": StandardSchemaV1.Props;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* a Type's validation, each run in `context`. As small as it is to create,
|
|
208
|
+
* so a form can bind what it has saved on each render to a Type that's
|
|
209
|
+
* defined, and precompiled, once
|
|
210
|
+
*/
|
|
211
|
+
export declare const withContextOf: (t: ContextualTarget, context: ArkEnv.context) => ContextualTarget;
|
|
212
|
+
export declare const allowsInBranchBy: (ctx: InternalTraversal, allows: TraverseAllows, data: unknown, node?: BaseNode) => boolean;
|
|
213
|
+
export declare const disallowed: () => false;
|
|
214
|
+
export declare const rejected: (allows: (data: unknown) => boolean, value: unknown) => false;
|
|
215
|
+
export declare const rejects: (allows: (data: unknown) => boolean, value: unknown) => boolean;
|
|
216
|
+
export declare const matchesRepeated: (pattern: RegExp, data: string) => boolean;
|
|
217
|
+
export declare const addErrors: (ctx: InternalTraversal, errors: BaseArkErrors) => void;
|
|
218
|
+
export declare const addMorphErrs: (ctx: InternalTraversal, errors: TransformErrors, key?: PropertyKey) => void;
|
|
219
|
+
export declare const transformResolution: (ctx: InternalTraversal, id: string, data: unknown, transform: TraverseTransform, node?: BaseNode) => unknown;
|
|
220
|
+
declare class Resolutions {
|
|
221
|
+
seen: {
|
|
222
|
+
[id in string]?: Map<unknown, ResolutionState>;
|
|
223
|
+
};
|
|
224
|
+
tracked: boolean;
|
|
225
|
+
frames: ResolvingFrame[] | undefined;
|
|
226
|
+
depth: number;
|
|
227
|
+
/** how many nodes were entered while untracked, bounded so a cycle can't run forever */
|
|
228
|
+
visits: number;
|
|
229
|
+
/** whether a failure was recorded, so untracked lookups still find it */
|
|
230
|
+
hasFailed: boolean;
|
|
231
|
+
/** how many resolutions were entered, numbering each */
|
|
232
|
+
nEntered: number;
|
|
233
|
+
assumedFrom: number;
|
|
234
|
+
assumed: unknown[] | undefined;
|
|
235
|
+
/** the first reported invalid resolution reached */
|
|
236
|
+
invalid: InvalidResolution | undefined;
|
|
237
|
+
}
|
|
238
|
+
export declare const enterResolution: (ctx: InternalTraversal, id: string, data: unknown) => boolean | undefined;
|
|
239
|
+
export declare const exitResolution: (ctx: InternalTraversal, allowed?: boolean) => boolean;
|
|
240
|
+
export declare const maxAliasDepth = 64;
|
|
241
|
+
export declare const maxAliasVisits = 1000;
|
|
242
|
+
export declare const aliasVisits: {
|
|
243
|
+
count: number;
|
|
244
|
+
tracked: boolean;
|
|
245
|
+
exceed: (data: unknown) => InternalTraversal | false;
|
|
246
|
+
};
|
|
247
|
+
export declare const applyCyclic: <ctx extends InternalTraversal>(node: BaseNode, data: unknown, ctx: ctx) => ctx;
|
|
248
|
+
export declare const applyResolution: (id: string, node: BaseNode, data: unknown, ctx: InternalTraversal) => void;
|
|
249
|
+
export declare const enterApplied: (ctx: InternalTraversal, id: string, data: unknown) => boolean | undefined;
|
|
250
|
+
export declare const exitApplied: (ctx: InternalTraversal, continues: boolean) => boolean;
|
|
251
|
+
export declare const applyMember: (node: BaseNode, data: unknown, ctx: InternalTraversal, member?: BaseNode) => void;
|
|
252
|
+
export declare const applyValue: (node: BaseNode, data: unknown, ctx: InternalTraversal, tfs?: boolean) => void;
|
|
253
|
+
export declare const allowsUntracked: (node: BaseNode, data: unknown) => boolean | undefined;
|
|
254
|
+
export declare const allowsAcyclic: (node: BaseNode, data: unknown) => boolean | undefined;
|
|
255
|
+
export declare const allowsInContext: (node: BaseNode, data: unknown, config: ResolvedConfig, ctor?: typeof Traversal) => boolean;
|
|
256
|
+
type ResolutionState = number | boolean | InvalidResolution;
|
|
257
|
+
interface InvalidResolution {
|
|
258
|
+
error: ArkIssue;
|
|
259
|
+
reported: boolean;
|
|
260
|
+
}
|
|
261
|
+
interface ResolvingFrame {
|
|
262
|
+
id: string;
|
|
263
|
+
data: unknown;
|
|
264
|
+
entered: number;
|
|
265
|
+
errN: number;
|
|
266
|
+
/** the invalid resolution reached before entering this frame */
|
|
267
|
+
outerInvalid: InvalidResolution | undefined;
|
|
268
|
+
assumedOuter: number;
|
|
269
|
+
assumedLength: number;
|
|
270
|
+
}
|
|
271
|
+
export declare const travKey: <result>(key: PropertyKey, fn: () => result, ctx: InternalTraversal | AliasDepth | undefined) => result;
|
|
272
|
+
interface DefaultedValue {
|
|
273
|
+
(data: unknown, pipedFromCtx: Traversal): unknown;
|
|
274
|
+
traverse: (data: unknown) => unknown;
|
|
275
|
+
}
|
|
276
|
+
export type DefaultedNode = Pick<BaseNode, "alters" | "hasAlias" | "allowsCtx" | "ctxMorph" | "tfs">;
|
|
277
|
+
export declare const computeDefaultValueMorph: (key: PropertyKey, value: DefaultedValue, defaultInput: unknown, node?: DefaultedNode, isThunkInput?: boolean) => Morph<any>;
|
|
278
|
+
export type TraversalMethodsByKind<input = unknown> = {
|
|
279
|
+
Allows: TraverseAllows<input>;
|
|
280
|
+
Apply: TraverseApply<input>;
|
|
281
|
+
Transform: TraverseTransform<input>;
|
|
282
|
+
};
|
|
283
|
+
export type TraversalKind = keyof TraversalMethodsByKind & {};
|
|
284
|
+
export type AliasDepth = number;
|
|
285
|
+
export type TraverseAllows<data = unknown> = (data: data, ctx: InternalTraversal | AliasDepth) => boolean;
|
|
286
|
+
export type TraverseApply<data = unknown> = (data: data, ctx: InternalTraversal) => void;
|
|
287
|
+
export type TraverseTransform<data = unknown> = (data: data, ctx: InternalTraversal) => unknown;
|
|
288
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type array, type mutable, type show, type Thunk } from "../../util/index.js";
|
|
2
|
+
import type { BaseConstraint } from "../constraint.ts";
|
|
3
|
+
import type { GenericRoot } from "../generic.ts";
|
|
4
|
+
import type { InternalModule } from "../module.ts";
|
|
5
|
+
import type { BaseNode } from "../node.ts";
|
|
6
|
+
import type { BaseParseContext } from "../parse.ts";
|
|
7
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
8
|
+
import type { DiscriminantCases } from "../roots/union.ts";
|
|
9
|
+
import type { BaseScope } from "../scope.ts";
|
|
10
|
+
import type { ArkErrors } from "./errors.ts";
|
|
11
|
+
export declare const makeRootAndArrayPropertiesMutable: <o extends object>(o: o) => makeRootAndArrayPropertiesMutable<o>;
|
|
12
|
+
export type makeRootAndArrayPropertiesMutable<inner> = {
|
|
13
|
+
-readonly [k in keyof inner]: inner[k] extends array | undefined ? mutable<inner[k]> : inner[k];
|
|
14
|
+
} & unknown;
|
|
15
|
+
export type internalImplementationOf<external, typeOnlyKey extends keyof external = never> = {
|
|
16
|
+
[k in Exclude<keyof external, typeOnlyKey>]: external[k] extends ((...args: infer args) => unknown) ? (...args: {
|
|
17
|
+
[i in keyof args]: never;
|
|
18
|
+
}) => unknown : unknown;
|
|
19
|
+
};
|
|
20
|
+
export interface ArkKinds {
|
|
21
|
+
constraint: BaseConstraint;
|
|
22
|
+
root: BaseRoot;
|
|
23
|
+
scope: BaseScope;
|
|
24
|
+
generic: GenericRoot;
|
|
25
|
+
module: InternalModule;
|
|
26
|
+
errors: ArkErrors;
|
|
27
|
+
context: BaseParseContext;
|
|
28
|
+
}
|
|
29
|
+
export type ArkKind = show<keyof ArkKinds>;
|
|
30
|
+
export declare const hasArkKind: <kind extends ArkKind>(value: unknown, kind: kind) => value is ArkKinds[kind];
|
|
31
|
+
export declare const isNode: (value: unknown) => value is BaseNode;
|
|
32
|
+
export declare const inProgress: {
|
|
33
|
+
definitions: number;
|
|
34
|
+
resolutions: number;
|
|
35
|
+
ioReads: number;
|
|
36
|
+
compositions: number;
|
|
37
|
+
};
|
|
38
|
+
export declare const isResolutionFinal: () => boolean;
|
|
39
|
+
export declare const isIoFinal: () => boolean;
|
|
40
|
+
export declare const queueUnchecked: (assert: () => void, key?: string) => void;
|
|
41
|
+
export declare const assertUnchecked: () => void;
|
|
42
|
+
export declare const resolving: <t>(resolve: () => t) => t;
|
|
43
|
+
export declare const defining: <t>(define: () => t) => t;
|
|
44
|
+
export declare const composing: <t>(compose: () => t) => t;
|
|
45
|
+
export declare const holeNameMarker = "$hole_";
|
|
46
|
+
export declare const withoutHoleNames: (s: string) => string;
|
|
47
|
+
export declare const elided: (nested: string) => string;
|
|
48
|
+
export declare const printSelfAsThis: <node extends BaseRoot>(node: node, printedWithThis: BaseRoot) => node;
|
|
49
|
+
export type unwrapDefault<thunkableValue> = thunkableValue extends Thunk<infer returnValue> ? returnValue : thunkableValue;
|
|
50
|
+
export declare const valueAtPath: (path: array<PropertyKey>, data: unknown, end?: number) => unknown;
|
|
51
|
+
export declare const isAbsent: (path: array<PropertyKey>, data: unknown) => boolean;
|
|
52
|
+
export type DescribeBranchesOptions = {
|
|
53
|
+
delimiter?: string;
|
|
54
|
+
finalDelimiter?: string;
|
|
55
|
+
};
|
|
56
|
+
export declare const removedProblemMessage = "problem was removed in 3.0; write message";
|
|
57
|
+
export declare const describeBranches: (descriptions: readonly string[], opts?: DescribeBranchesOptions) => string;
|
|
58
|
+
export declare const expressBranches: (expressions: readonly string[]) => string;
|
|
59
|
+
export declare const describeCases: ({ discriminantKind, cases }: DiscriminantCases) => string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BaseConstraint } from "../constraint.ts";
|
|
2
|
+
import type { nodeOfKind } from "../kinds.ts";
|
|
3
|
+
import { type BaseNode, type DeepNodeTransformContext, type DeepNodeTransformation } from "../node.ts";
|
|
4
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
5
|
+
import type { declareNode } from "../shared/declare.ts";
|
|
6
|
+
import { type RootKind, type nodeImplementationOf } from "../shared/implement.ts";
|
|
7
|
+
import { type AliasDepth, type InternalTraversal, type TraverseAllows } from "../shared/traversal.ts";
|
|
8
|
+
export declare namespace Index {
|
|
9
|
+
type KeyKind = Exclude<RootKind, "unit">;
|
|
10
|
+
type KeyNode = nodeOfKind<KeyKind>;
|
|
11
|
+
interface Inner {
|
|
12
|
+
readonly signature: KeyNode;
|
|
13
|
+
readonly value: BaseRoot;
|
|
14
|
+
}
|
|
15
|
+
interface Declaration extends declareNode<{
|
|
16
|
+
kind: "index";
|
|
17
|
+
inner: Inner;
|
|
18
|
+
prerequisite: object;
|
|
19
|
+
stacks: true;
|
|
20
|
+
childKind: RootKind;
|
|
21
|
+
}> {
|
|
22
|
+
}
|
|
23
|
+
type Node = IndexNode;
|
|
24
|
+
}
|
|
25
|
+
export declare class IndexNode extends BaseConstraint<Index.Declaration> {
|
|
26
|
+
implied: BaseRoot;
|
|
27
|
+
get expression(): string;
|
|
28
|
+
constructor(...args: ConstructorParameters<typeof BaseConstraint>);
|
|
29
|
+
protected get ctxSel(): boolean;
|
|
30
|
+
protected initFlat(): void;
|
|
31
|
+
allowsKey: TraverseAllows<PropertyKey>;
|
|
32
|
+
tAllows(data: object, ctx: InternalTraversal | AliasDepth): boolean;
|
|
33
|
+
tApply(data: object, ctx: InternalTraversal): void;
|
|
34
|
+
protected _tf(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): BaseNode | null;
|
|
35
|
+
compile(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare const Index: {
|
|
38
|
+
impl: nodeImplementationOf<Index.Declaration>;
|
|
39
|
+
Node: typeof IndexNode;
|
|
40
|
+
};
|
|
41
|
+
export declare const writeEnumerableIndexBranches: (keys: string[]) => string;
|
|
42
|
+
export declare const writeInvalidPropertyKeyMessage: <indexSchema extends string>(indexSchema: indexSchema) => writeInvalidPropertyKeyMessage<indexSchema>;
|
|
43
|
+
export type writeInvalidPropertyKeyMessage<indexSchema extends string> = `Indexed key definition '${indexSchema}' must be a string or symbol`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type requireKeys } from "../../util/index.js";
|
|
2
|
+
import type { BaseNode } from "../node.ts";
|
|
3
|
+
import type { Morph } from "../roots/morph.ts";
|
|
4
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
5
|
+
import type { NodeCompiler } from "../shared/compile.ts";
|
|
6
|
+
import type { declareNode } from "../shared/declare.ts";
|
|
7
|
+
import { type nodeImplementationOf } from "../shared/implement.ts";
|
|
8
|
+
import { BaseProp, type Prop } from "./prop.ts";
|
|
9
|
+
export declare namespace Optional {
|
|
10
|
+
interface Inner extends Prop.Inner {
|
|
11
|
+
default?: unknown;
|
|
12
|
+
}
|
|
13
|
+
type Declaration = declareNode<Prop.Declaration<"optional"> & {
|
|
14
|
+
inner: Inner;
|
|
15
|
+
}>;
|
|
16
|
+
type Node = OptionalNode;
|
|
17
|
+
namespace Node {
|
|
18
|
+
type withDefault = requireKeys<Node, "default" | "defMorph">;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export declare class OptionalNode extends BaseProp<"optional"> {
|
|
22
|
+
constructor(...args: ConstructorParameters<typeof BaseProp>);
|
|
23
|
+
getIo(ioKind: "in" | "out"): BaseNode;
|
|
24
|
+
private _requiredValue;
|
|
25
|
+
/**
|
|
26
|
+
* its value where its key is required, which without
|
|
27
|
+
* exactOptionalPropertyTypes drops the undefined its key allowed, as
|
|
28
|
+
* TS's `-?` does
|
|
29
|
+
*/
|
|
30
|
+
get requiredValue(): BaseRoot;
|
|
31
|
+
private _outProp;
|
|
32
|
+
get outProp(): Prop.Node;
|
|
33
|
+
get expression(): string;
|
|
34
|
+
/** the morph writing its default when its key is missing */
|
|
35
|
+
defMorph: Morph | undefined;
|
|
36
|
+
readonly defaultsUndefined: boolean;
|
|
37
|
+
holdsValue(data: object): boolean;
|
|
38
|
+
jsHoldsValue(js: NodeCompiler, data: string): string;
|
|
39
|
+
}
|
|
40
|
+
export declare const Optional: {
|
|
41
|
+
impl: nodeImplementationOf<{
|
|
42
|
+
inner: Optional.Inner;
|
|
43
|
+
kind: "optional";
|
|
44
|
+
prerequisite: object;
|
|
45
|
+
stacks: true;
|
|
46
|
+
childKind: import("../shared/implement.ts").RootKind;
|
|
47
|
+
reducibleTo: "optional";
|
|
48
|
+
errorCtx: null;
|
|
49
|
+
}>;
|
|
50
|
+
Node: typeof OptionalNode;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* `value` without its undefined branch, the one exactOptionalPropertyTypes:
|
|
54
|
+
* false adds to an optional key or element's value, where a `-?` drops it. A
|
|
55
|
+
* value like `unknown` allowing undefined otherwise keeps it, as in TS
|
|
56
|
+
*/
|
|
57
|
+
export declare const withoutUndefined: (value: BaseRoot) => BaseRoot;
|
|
58
|
+
export declare const assertDefaultValueAssignability: (node: BaseRoot, value: unknown, key: PropertyKey | null, owner?: BaseNode) => unknown;
|
|
59
|
+
export declare const checkDefault: (node: BaseRoot, value: unknown, key: PropertyKey | null, owner?: BaseNode) => unknown;
|
|
60
|
+
export type writeUnassignableDefaultValueMessage<baseDef extends string, defaultValue extends string> = `Default value ${defaultValue} must be assignable to ${baseDef}`;
|
|
61
|
+
export declare const writeNonPrimitiveNonFunctionDefaultValueMessage: (key: PropertyKey | null) => string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Key } from "../../util/index.js";
|
|
2
|
+
import { BaseConstraint } from "../constraint.ts";
|
|
3
|
+
import type { nodeOfKind } from "../kinds.ts";
|
|
4
|
+
import { type BaseNode, type DeepNodeTransformation, type DeepNodeTransformContext } from "../node.ts";
|
|
5
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
6
|
+
import { type NodeCompiler } from "../shared/compile.ts";
|
|
7
|
+
import type { RootKind } from "../shared/implement.ts";
|
|
8
|
+
import { type AliasDepth, type InternalTraversal } from "../shared/traversal.ts";
|
|
9
|
+
import type { Optional } from "./optional.ts";
|
|
10
|
+
import type { Required } from "./required.ts";
|
|
11
|
+
export declare namespace Prop {
|
|
12
|
+
type Kind = "required" | "optional";
|
|
13
|
+
type Node = nodeOfKind<Kind>;
|
|
14
|
+
interface Inner {
|
|
15
|
+
readonly key: Key;
|
|
16
|
+
readonly value: BaseRoot;
|
|
17
|
+
}
|
|
18
|
+
interface Declaration<kind extends Kind = Kind> {
|
|
19
|
+
kind: kind;
|
|
20
|
+
prerequisite: object;
|
|
21
|
+
stacks: true;
|
|
22
|
+
childKind: RootKind;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare abstract class BaseProp<kind extends Prop.Kind = Prop.Kind> extends BaseConstraint<kind extends "required" ? Required.Declaration : Optional.Declaration> {
|
|
26
|
+
get required(): boolean;
|
|
27
|
+
get optional(): boolean;
|
|
28
|
+
get implied(): BaseRoot;
|
|
29
|
+
get serializedKey(): string;
|
|
30
|
+
/** its key as a path prints it, a symbol by its name */
|
|
31
|
+
get keyStr(): string;
|
|
32
|
+
protected initFlat(): void;
|
|
33
|
+
protected _tf(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): BaseNode | null;
|
|
34
|
+
sameInner(r: BaseProp): boolean | undefined;
|
|
35
|
+
/** whether it's an optional prop with a default */
|
|
36
|
+
hasDef(): this is Optional.Node.withDefault;
|
|
37
|
+
/** whether data has a value at its key, which its value transforms and a default leaves alone */
|
|
38
|
+
holdsValue(data: object): boolean;
|
|
39
|
+
/** writes whether `data` holds its key with a value */
|
|
40
|
+
jsHoldsValue(js: NodeCompiler, data: string): string;
|
|
41
|
+
tAllows(data: object, ctx: InternalTraversal | AliasDepth): boolean;
|
|
42
|
+
tApply(data: object, ctx: InternalTraversal): void;
|
|
43
|
+
compile(js: NodeCompiler): void;
|
|
44
|
+
jsExpression(js: NodeCompiler): string | undefined;
|
|
45
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { errorCtx } from "../kinds.ts";
|
|
2
|
+
import type { ArkEnv, BaseErrorContext, declareNode } from "../shared/declare.ts";
|
|
3
|
+
import type { NodeErrorContextInput } from "../shared/errors.ts";
|
|
4
|
+
import type { FailureSite } from "../shared/issues.ts";
|
|
5
|
+
import { type nodeImplementationOf } from "../shared/implement.ts";
|
|
6
|
+
import { BaseProp, type Prop } from "./prop.ts";
|
|
7
|
+
export declare namespace Required {
|
|
8
|
+
interface ErrorContext extends BaseErrorContext<"required"> {
|
|
9
|
+
readonly missingValueDescription: string;
|
|
10
|
+
readonly missing: MissingValue;
|
|
11
|
+
readonly valueMeta: ArkEnv.meta;
|
|
12
|
+
}
|
|
13
|
+
interface Inner extends Prop.Inner {
|
|
14
|
+
}
|
|
15
|
+
type Declaration = declareNode<Prop.Declaration<"required"> & {
|
|
16
|
+
inner: Inner;
|
|
17
|
+
errorCtx: ErrorContext;
|
|
18
|
+
}>;
|
|
19
|
+
type Node = RequiredNode;
|
|
20
|
+
}
|
|
21
|
+
/** what a missing value should have been; each entry has its node's kind */
|
|
22
|
+
export type MissingValue = MissingBasis | {
|
|
23
|
+
readonly code: "intersection";
|
|
24
|
+
} | {
|
|
25
|
+
readonly code: "union";
|
|
26
|
+
readonly branches: readonly MissingValue[];
|
|
27
|
+
};
|
|
28
|
+
export type MissingBasis = errorCtx<"domain"> | errorCtx<"unit"> | errorCtx<"proto"> | {
|
|
29
|
+
readonly code: "morph";
|
|
30
|
+
readonly meta: ArkEnv.meta;
|
|
31
|
+
};
|
|
32
|
+
export declare class RequiredNode extends BaseProp<"required"> {
|
|
33
|
+
get expression(): string;
|
|
34
|
+
private _errorCtx;
|
|
35
|
+
get errorCtx(): NodeErrorContextInput<"required">;
|
|
36
|
+
get failSite(): FailureSite;
|
|
37
|
+
}
|
|
38
|
+
export declare const Required: {
|
|
39
|
+
impl: nodeImplementationOf<{
|
|
40
|
+
kind: "required";
|
|
41
|
+
prerequisite: object;
|
|
42
|
+
stacks: true;
|
|
43
|
+
childKind: import("../shared/implement.ts").RootKind;
|
|
44
|
+
inner: Required.Inner;
|
|
45
|
+
errorCtx: Required.ErrorContext;
|
|
46
|
+
reducibleTo: "required";
|
|
47
|
+
}>;
|
|
48
|
+
Node: typeof RequiredNode;
|
|
49
|
+
};
|