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,146 @@
|
|
|
1
|
+
import { type SerializedPrimitive, type array, type show } from "../../util/index.js";
|
|
2
|
+
import type { nodeOfKind } from "../kinds.ts";
|
|
3
|
+
import { type BaseNode } from "../node.ts";
|
|
4
|
+
import { type NodeCompiler } from "../shared/compile.ts";
|
|
5
|
+
import type { ArkEnv, BaseErrorContext, BaseNodeInput, declareNode } from "../shared/declare.ts";
|
|
6
|
+
import { type ArkError } from "../shared/errors.ts";
|
|
7
|
+
import type { UnionSite } from "../shared/issues.ts";
|
|
8
|
+
import { type RootKind, type UnionChildKind, type nodeImplementationOf } from "../shared/implement.ts";
|
|
9
|
+
import { type RegisteredReference } from "../shared/registry.ts";
|
|
10
|
+
import { type AliasDepth, type InternalTraversal } from "../shared/traversal.ts";
|
|
11
|
+
import type { Domain } from "./domain.ts";
|
|
12
|
+
import type { Morph } from "./morph.ts";
|
|
13
|
+
import { BaseRoot } from "./root.ts";
|
|
14
|
+
import type { Unit } from "./unit.ts";
|
|
15
|
+
export declare namespace Union {
|
|
16
|
+
type ChildKind = UnionChildKind;
|
|
17
|
+
type ChildNode = nodeOfKind<ChildKind>;
|
|
18
|
+
interface Inner {
|
|
19
|
+
readonly branches: readonly ChildNode[];
|
|
20
|
+
readonly ordered?: true;
|
|
21
|
+
}
|
|
22
|
+
interface Input extends BaseNodeInput {
|
|
23
|
+
readonly branches: readonly BaseRoot[];
|
|
24
|
+
readonly ordered?: true;
|
|
25
|
+
}
|
|
26
|
+
interface ErrorContext extends BaseErrorContext<"union"> {
|
|
27
|
+
errors: readonly ArkError[];
|
|
28
|
+
}
|
|
29
|
+
interface Declaration extends declareNode<{
|
|
30
|
+
kind: "union";
|
|
31
|
+
inner: Inner;
|
|
32
|
+
errorCtx: ErrorContext;
|
|
33
|
+
reducibleTo: RootKind;
|
|
34
|
+
childKind: UnionChildKind;
|
|
35
|
+
}> {
|
|
36
|
+
}
|
|
37
|
+
type Node = UnionNode;
|
|
38
|
+
}
|
|
39
|
+
export type DiscriminantErrorContext = {
|
|
40
|
+
[kind in DiscriminantKind]: DiscriminantErrorContextOf<kind>;
|
|
41
|
+
}[DiscriminantKind];
|
|
42
|
+
interface DiscriminantErrorContextOf<kind extends DiscriminantKind> extends BaseErrorContext<"discriminant"> {
|
|
43
|
+
readonly discriminantKind: kind;
|
|
44
|
+
/**
|
|
45
|
+
* the domains or unit values the discriminant expected, with Array for
|
|
46
|
+
* an object case only arrays reach
|
|
47
|
+
*/
|
|
48
|
+
readonly cases: readonly (kind extends "domain" ? DomainCase : unknown)[];
|
|
49
|
+
/** the discriminant is at a key, so meta describes the value around it */
|
|
50
|
+
readonly onKey: boolean;
|
|
51
|
+
/** the discriminant key is not in its parent; false unless onKey */
|
|
52
|
+
readonly absent: boolean;
|
|
53
|
+
readonly data: unknown;
|
|
54
|
+
}
|
|
55
|
+
export declare class UnionNode extends BaseRoot<Union.Declaration> {
|
|
56
|
+
get isBoolean(): boolean;
|
|
57
|
+
private _unitBranches;
|
|
58
|
+
get unitBranches(): (Unit.Node | Morph.Node)[];
|
|
59
|
+
readonly caseNodes: BaseRoot[];
|
|
60
|
+
private _disc;
|
|
61
|
+
get discriminant(): Discriminant | null;
|
|
62
|
+
/** `discCases`, once read */
|
|
63
|
+
private _discCases;
|
|
64
|
+
/** the cases of its discriminant, by the serialized value each branch is discriminated by */
|
|
65
|
+
get discCases(): DiscriminantCases;
|
|
66
|
+
/** `missLists`, once read */
|
|
67
|
+
private _missLists;
|
|
68
|
+
/** whether a miss of its own value lists its branches: if one is described, as an indiscriminable union's does */
|
|
69
|
+
get missLists(): boolean;
|
|
70
|
+
/** `discDesc`, once read */
|
|
71
|
+
private _discDesc;
|
|
72
|
+
/** the description of what its discriminant expects */
|
|
73
|
+
get discDesc(): string;
|
|
74
|
+
get failSite(): UnionSite;
|
|
75
|
+
get missPath(): array<PropertyKey>;
|
|
76
|
+
/** `discMeta`, once read */
|
|
77
|
+
private _discMeta;
|
|
78
|
+
/** the meta its discriminant's errors are written with: at a key, expected and actual describe the object around it */
|
|
79
|
+
get discMeta(): ArkEnv.meta;
|
|
80
|
+
get expression(): string;
|
|
81
|
+
discriminate(): Discriminant | null;
|
|
82
|
+
get otherRefs(): readonly BaseNode[];
|
|
83
|
+
protected get ctxSel(): boolean;
|
|
84
|
+
get topMorphs(): array<Morph>;
|
|
85
|
+
get brief(): string;
|
|
86
|
+
/**
|
|
87
|
+
* the discriminant an uncompiled check reads. A Type compiled later checks
|
|
88
|
+
* its first data through its branches, sparing that call discriminating
|
|
89
|
+
* every union on the data's path. A predicate reading ctx is only called for
|
|
90
|
+
* the branch compiled code picks, and a node never compiled checks as
|
|
91
|
+
* compiled code would. This reads no cache: whether something else had
|
|
92
|
+
* already discriminated the union (a binding sizing its references by id,
|
|
93
|
+
* a describe of a miss) would decide which branches' predicates are called
|
|
94
|
+
*/
|
|
95
|
+
private get uncompiledDisc();
|
|
96
|
+
tAllows(data: unknown, ctx: InternalTraversal | AliasDepth): boolean;
|
|
97
|
+
tApply(data: unknown, ctx: InternalTraversal): void;
|
|
98
|
+
applyMiss(data: unknown, ctx: InternalTraversal, value: unknown): boolean;
|
|
99
|
+
applyDefault(data: unknown, ctx: InternalTraversal, value: unknown): boolean;
|
|
100
|
+
private errorFromMiss;
|
|
101
|
+
private _missContexts;
|
|
102
|
+
private get missContexts();
|
|
103
|
+
applyBranches(data: unknown, ctx: InternalTraversal): void;
|
|
104
|
+
tTransform(data: unknown, ctx: InternalTraversal): unknown;
|
|
105
|
+
jsCond(js: NodeCompiler, data: string): string | undefined;
|
|
106
|
+
compile(js: NodeCompiler): void;
|
|
107
|
+
/** writes the check of branches no discriminant tells apart */
|
|
108
|
+
private jsIndisc;
|
|
109
|
+
get nestedExpr(): string;
|
|
110
|
+
}
|
|
111
|
+
export declare const Union: {
|
|
112
|
+
impl: nodeImplementationOf<Union.Declaration>;
|
|
113
|
+
Node: typeof UnionNode;
|
|
114
|
+
};
|
|
115
|
+
export declare const compileDomainOf: (value: string, labels: readonly string[]) => string;
|
|
116
|
+
export type DiscriminantCases = {
|
|
117
|
+
[kind in DiscriminantKind]: Pick<DiscriminantErrorContextOf<kind>, "discriminantKind" | "cases">;
|
|
118
|
+
}[DiscriminantKind];
|
|
119
|
+
export type DomainCase = Domain | "Array";
|
|
120
|
+
export type CaseKey<kind extends DiscriminantKind = DiscriminantKind> = DiscriminantKind extends kind ? string : DiscriminantKinds[kind] | "default";
|
|
121
|
+
export type DiscriminantLocation<kind extends DiscriminantKind = DiscriminantKind> = {
|
|
122
|
+
path: PropertyKey[];
|
|
123
|
+
/** the discriminant's path as optional-chained property accesses */
|
|
124
|
+
pathStr: string;
|
|
125
|
+
kind: kind;
|
|
126
|
+
};
|
|
127
|
+
export interface Discriminant<kind extends DiscriminantKind = DiscriminantKind> extends DiscriminantLocation<kind> {
|
|
128
|
+
cases: DiscriminatedCases<kind>;
|
|
129
|
+
members?: {
|
|
130
|
+
[caseKey in CaseKey<kind>]?: BaseRoot;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export type CaseContext = {
|
|
134
|
+
branchIndices: number[];
|
|
135
|
+
condition: nodeOfKind<DiscriminantKind> | Domain.Enumerable;
|
|
136
|
+
};
|
|
137
|
+
export type CaseDiscriminant = nodeOfKind<DiscriminantKind> | Domain.Enumerable;
|
|
138
|
+
export type DiscriminatedCases<kind extends DiscriminantKind = DiscriminantKind> = {
|
|
139
|
+
[caseKey in CaseKey<kind>]: BaseRoot | true;
|
|
140
|
+
};
|
|
141
|
+
export type DiscriminantKinds = {
|
|
142
|
+
domain: Domain;
|
|
143
|
+
unit: SerializedPrimitive | RegisteredReference;
|
|
144
|
+
};
|
|
145
|
+
export type DiscriminantKind = show<keyof DiscriminantKinds>;
|
|
146
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Domain, type JsonPrimitive } from "../../util/index.js";
|
|
2
|
+
import { type NodeCompiler } from "../shared/compile.ts";
|
|
3
|
+
import type { BaseErrorContext, declareNode } from "../shared/declare.ts";
|
|
4
|
+
import { type nodeImplementationOf } from "../shared/implement.ts";
|
|
5
|
+
import type { TraverseAllows } from "../shared/traversal.ts";
|
|
6
|
+
import { InternalBasis } from "./basis.ts";
|
|
7
|
+
export declare namespace Unit {
|
|
8
|
+
interface Inner<value = unknown> {
|
|
9
|
+
readonly unit: value;
|
|
10
|
+
}
|
|
11
|
+
interface ErrorContext<value = unknown> extends BaseErrorContext<"unit">, Inner<value> {
|
|
12
|
+
}
|
|
13
|
+
interface Declaration extends declareNode<{
|
|
14
|
+
kind: "unit";
|
|
15
|
+
inner: Inner;
|
|
16
|
+
errorCtx: ErrorContext;
|
|
17
|
+
}> {
|
|
18
|
+
}
|
|
19
|
+
type Node = UnitNode;
|
|
20
|
+
}
|
|
21
|
+
export declare class UnitNode extends InternalBasis<Unit.Declaration> {
|
|
22
|
+
/** its unit as JSON: a Date by its ISO string, an object or symbol by its registered reference */
|
|
23
|
+
unitJson: JsonPrimitive;
|
|
24
|
+
/** its unit written as a JavaScript literal, as compiled code compares data to it */
|
|
25
|
+
jsUnit: string;
|
|
26
|
+
sameInner(r: UnitNode): boolean;
|
|
27
|
+
jsCond(js: NodeCompiler, data: string): string;
|
|
28
|
+
expression: string;
|
|
29
|
+
domain: Domain;
|
|
30
|
+
get brief(): string;
|
|
31
|
+
tAllows: TraverseAllows;
|
|
32
|
+
}
|
|
33
|
+
export declare const Unit: {
|
|
34
|
+
impl: nodeImplementationOf<Unit.Declaration>;
|
|
35
|
+
Node: typeof UnitNode;
|
|
36
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ArkSchemaConfig, ResolvedConfig } from "./config.ts";
|
|
2
|
+
export type { ArkError, ArkErrorCode, ArkErrorInput, RejectInput, ErrorContextsByCode } from "./shared/errors.ts";
|
|
3
|
+
export * from "./shared/enWriters.ts";
|
|
4
|
+
export { appliesValues, discriminatesBooleans, failsInBranches, findsOnRead, holdsExpression, listsUnions, transformsBranches, traversesUnions } from "./shared/issueFeatures.ts";
|
|
5
|
+
export * from "./shared/issues.ts";
|
|
6
|
+
export * from "./shared/listed.ts";
|
|
7
|
+
export { supportedJsonSchemaTargets, ToJsonSchemaError, validateStandardJsonSchemaTarget, writeNullableJsonSchema, writeUnionJsonSchema } from "./shared/jsonSchema.ts";
|
|
8
|
+
export * from "./shared/transform.ts";
|
|
9
|
+
export * from "./shared/traversal.ts";
|
|
10
|
+
export { arrayIndexMatcher } from "./structure/shared.ts";
|
|
11
|
+
export declare const runtimeConfig: ResolvedConfig;
|
|
12
|
+
export declare const runtimeScope: {
|
|
13
|
+
cfg: ResolvedConfig;
|
|
14
|
+
};
|
|
15
|
+
export declare const configure: (config: ArkSchemaConfig, fingerprint?: string) => ArkSchemaConfig;
|
|
16
|
+
export declare const configuredWriterOf: (code: string, k: string) => (...args: unknown[]) => unknown;
|
|
17
|
+
export declare const configuredFallbackOf: (code: string) => (ctx: object) => unknown;
|
|
18
|
+
export declare const fingerprintOf: (config: object) => string;
|
|
19
|
+
export declare const fixConfig: () => void;
|
|
20
|
+
export declare const fixConfigured: (fingerprint: string, path: string, config: string) => void;
|
|
21
|
+
export declare const shareConfig: (configureArktype: (config: ArkSchemaConfig) => unknown) => void;
|
|
22
|
+
export declare const configuredUnlikeBuildMessage = "configure() received values other than its build's";
|
|
23
|
+
export declare const reconfiguredMessage = "configure() must be called once, before any Type is created";
|
|
24
|
+
export declare const writtenConfigMessage = "configure()'s argument was modified after it was called";
|
|
25
|
+
export declare const configMismatchMessage = "An artifact must run under the configuration it was built with";
|
|
26
|
+
export declare const writeCreatedBeforeConfigureMessage: <path extends string, config extends string>(path: path, config: config) => writeCreatedBeforeConfigureMessage<path, config>;
|
|
27
|
+
export type writeCreatedBeforeConfigureMessage<path extends string, config extends string> = `${path} creates a Type before configure() runs
|
|
28
|
+
Import the config module before any module that creates a Type: first in the entry or test setup file that loads ${path}, or at the top of ${path}:
|
|
29
|
+
import "${config}"`;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { arkKind, ParseError, WeakCache, type Fn, type JsonStructure, type anyOrNever, type array, type conform, type intersectUnion, type noSuggest, type satisfy, type show } from "../util/index.js";
|
|
2
|
+
import { type ArkSchemaConfig, type ResolvedConfig } from "./config.ts";
|
|
3
|
+
import { GenericRoot, type GenericRootParser } from "./generic.ts";
|
|
4
|
+
import type { NodeInput, nodeOfKind, reducibleKindOf } from "./kinds.ts";
|
|
5
|
+
import { RootModule, type InternalModule, type PreparsedNodeResolution, type SchemaModule, type instantiateRoot } from "./module.ts";
|
|
6
|
+
import { type BaseNode } from "./node.ts";
|
|
7
|
+
import { type AttachedParseContext, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions } from "./parse.ts";
|
|
8
|
+
import { type RootSchema } from "./parseSchema.ts";
|
|
9
|
+
import { type Alias } from "./roots/alias.ts";
|
|
10
|
+
import { BaseRoot } from "./roots/root.ts";
|
|
11
|
+
import { type NodeKind } from "./shared/implement.ts";
|
|
12
|
+
import { $ark } from "./shared/registry.ts";
|
|
13
|
+
import type { Traversal } from "./shared/traversal.ts";
|
|
14
|
+
export type InternalResolutions = Record<string, InternalResolution | undefined>;
|
|
15
|
+
export type exportedNameOf<$> = Exclude<keyof $ & string, PrivateDeclaration>;
|
|
16
|
+
export type resolvableReferenceIn<$> = [
|
|
17
|
+
keyof $
|
|
18
|
+
] extends [never] ? never : [
|
|
19
|
+
keyof $ & (PrivateDeclaration | noSuggest | "root")
|
|
20
|
+
] extends [never] ? keyof $ & string : Exclude<keyof $ & string, PrivateDeclaration | noSuggest | "root"> | privateAliasOf<Extract<keyof $, PrivateDeclaration>>;
|
|
21
|
+
type privateAliasOf<k> = k extends PrivateDeclaration<infer alias> ? alias : never;
|
|
22
|
+
export type resolveReference<reference extends resolvableReferenceIn<$>, $> = reference extends keyof $ ? $[reference] : $[`#${reference}` & keyof $];
|
|
23
|
+
export type flatResolutionsOf<$> = show<intersectUnion<resolvableReferenceIn<$> extends infer k ? k extends keyof $ & string ? resolutionsOfReference<k, $[k]> : unknown : unknown>>;
|
|
24
|
+
type resolutionsOfReference<k extends string, v> = [
|
|
25
|
+
v
|
|
26
|
+
] extends [{
|
|
27
|
+
[arkKind]: "module";
|
|
28
|
+
}] ? [
|
|
29
|
+
v
|
|
30
|
+
] extends [anyOrNever] ? {
|
|
31
|
+
[_ in k]: v;
|
|
32
|
+
} : prefixKeys<flatResolutionsOf<v>, k> & {
|
|
33
|
+
[innerKey in keyof v as innerKey extends "root" ? k : never]: v[innerKey];
|
|
34
|
+
} : {
|
|
35
|
+
[_ in k]: v;
|
|
36
|
+
};
|
|
37
|
+
type prefixKeys<o, prefix extends string> = {
|
|
38
|
+
[k in keyof o & string as `${prefix}.${k}`]: o[k];
|
|
39
|
+
} & unknown;
|
|
40
|
+
export type PrivateDeclaration<key extends string = string> = `#${key}`;
|
|
41
|
+
export type InternalResolution = BaseRoot | GenericRoot | InternalModule;
|
|
42
|
+
export type toInternalScope<$> = BaseScope<{
|
|
43
|
+
[k in keyof $]: $[k] extends {
|
|
44
|
+
[arkKind]: infer kind;
|
|
45
|
+
} ? [
|
|
46
|
+
$[k]
|
|
47
|
+
] extends [anyOrNever] ? BaseRoot : kind extends "generic" ? GenericRoot : kind extends "module" ? InternalModule : never : BaseRoot;
|
|
48
|
+
}>;
|
|
49
|
+
type CachedResolution = BaseParseContext | BaseRoot | GenericRoot;
|
|
50
|
+
export declare const writeDuplicateAliasError: <alias extends string>(alias: alias) => writeDuplicateAliasError<alias>;
|
|
51
|
+
export type writeDuplicateAliasError<alias extends string> = `#${alias} duplicates public alias ${alias}`;
|
|
52
|
+
export declare const writeForeignArkMessage: (subject: string) => string;
|
|
53
|
+
export type AliasDefEntry = [name: string, defValue: unknown];
|
|
54
|
+
export type InstalledOption = "errors" | "mutatesInput";
|
|
55
|
+
export declare const writeMissingImportMessage: <option extends InstalledOption, value extends string>(option: option, value: value) => writeMissingImportMessage<option, value>;
|
|
56
|
+
export type writeMissingImportMessage<option extends InstalledOption, value extends string> = `${option}: ${value} requires import "arktype/${option}"`;
|
|
57
|
+
export type GlobalOnlyConfigOptionName = satisfy<keyof ArkSchemaConfig, "dateAllowsInvalid" | "numberAllowsInfinity" | "numberAllowsNaN" | "onUndeclaredKey" | "keywords" | "locale">;
|
|
58
|
+
export declare const writeGlobalOnlyConfigMessage: <name extends GlobalOnlyConfigOptionName>(name: name) => writeGlobalOnlyConfigMessage<name>;
|
|
59
|
+
export type writeGlobalOnlyConfigMessage<name extends GlobalOnlyConfigOptionName> = `${name} can only be configured globally, with configure()`;
|
|
60
|
+
export interface ScopeOnlyConfigOptions {
|
|
61
|
+
name?: string;
|
|
62
|
+
prereducedAliases?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ArkSchemaScopeConfig extends Omit<ArkSchemaConfig, GlobalOnlyConfigOptionName>, ScopeOnlyConfigOptions {
|
|
65
|
+
}
|
|
66
|
+
export interface ResolvedScopeConfig extends ResolvedConfig, ScopeOnlyConfigOptions {
|
|
67
|
+
}
|
|
68
|
+
export declare abstract class BaseScope<$ extends {} = {}> {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
/** where it was created among scopes, which tells it apart where its name may not */
|
|
71
|
+
readonly index: number;
|
|
72
|
+
readonly isBuiltin: boolean;
|
|
73
|
+
readonly scopeConfig: ArkSchemaScopeConfig | undefined;
|
|
74
|
+
get [arkKind](): "scope";
|
|
75
|
+
/** `refsById`, once read */
|
|
76
|
+
private _refsById;
|
|
77
|
+
get byId(): {
|
|
78
|
+
[id: string]: BaseNode;
|
|
79
|
+
};
|
|
80
|
+
private _references;
|
|
81
|
+
get references(): readonly BaseNode[];
|
|
82
|
+
/** each alias's resolution, or the parse context of one still unresolved */
|
|
83
|
+
readonly res: {
|
|
84
|
+
[alias: string]: CachedResolution | undefined;
|
|
85
|
+
};
|
|
86
|
+
/** each reference bound to this scope, so it's bound once */
|
|
87
|
+
private readonly boundRefs;
|
|
88
|
+
exportedNames: string[];
|
|
89
|
+
readonly aliases: Record<string, unknown>;
|
|
90
|
+
resolved: boolean;
|
|
91
|
+
readonly nodesByKey: WeakCache<BaseNode>;
|
|
92
|
+
constructor(
|
|
93
|
+
/** The set of names defined at the root-level of the scope mapped to their
|
|
94
|
+
* corresponding definitions.**/
|
|
95
|
+
def: Record<string, unknown>, config?: ArkSchemaScopeConfig, isBuiltin?: boolean);
|
|
96
|
+
get config(): ArkSchemaScopeConfig;
|
|
97
|
+
/** its config, with defaults and global config applied */
|
|
98
|
+
get cfg(): ResolvedScopeConfig;
|
|
99
|
+
get intrinsic(): Omit<typeof $ark.kw, `json${string}`>;
|
|
100
|
+
/** defines `name` as an own property holding `value`, so the getter it shadows runs once */
|
|
101
|
+
protected memo<name extends keyof this>(name: name, value: this[name]): this[name];
|
|
102
|
+
get internal(): this;
|
|
103
|
+
private _json;
|
|
104
|
+
get json(): JsonStructure;
|
|
105
|
+
defineSchema<def extends RootSchema>(def: def): def;
|
|
106
|
+
generic: GenericRootParser;
|
|
107
|
+
units: (values: array, opts?: BaseParseOptions) => BaseRoot;
|
|
108
|
+
lazilyResolve(resolve: () => BaseRoot, reference?: string, operator?: string, operands?: readonly BaseRoot[]): Alias.Node;
|
|
109
|
+
schema: (schema: RootSchema, opts?: BaseParseOptions) => BaseRoot;
|
|
110
|
+
/** `reference` copied into this scope, unless it's already this scope's or an alias */
|
|
111
|
+
bindRef<reference extends BaseNode | GenericRoot>(reference: reference): reference;
|
|
112
|
+
bindKw<reference extends BaseNode | GenericRoot>(reference: reference): reference;
|
|
113
|
+
private describesLike;
|
|
114
|
+
resolveRoot(name: string): BaseRoot;
|
|
115
|
+
maybeResolveRoot(name: string): BaseRoot | undefined;
|
|
116
|
+
/** If name is a valid reference to a submodule alias, return its resolution */
|
|
117
|
+
protected maybeResolveSubalias(name: string): BaseRoot | GenericRoot | undefined;
|
|
118
|
+
get ambient(): InternalModule;
|
|
119
|
+
private aliasOf;
|
|
120
|
+
private resolveContext;
|
|
121
|
+
private resolvePending;
|
|
122
|
+
maybeResolve(name: string): Exclude<CachedResolution, BaseParseContext> | undefined;
|
|
123
|
+
private resolveDefinition;
|
|
124
|
+
private resolveUncached;
|
|
125
|
+
protected createParseCtx<input extends BaseParseContextInput>(input: input): input & AttachedParseContext;
|
|
126
|
+
traversal(root: unknown): Traversal;
|
|
127
|
+
import(): SchemaModule<{
|
|
128
|
+
[k in exportedNameOf<$> as PrivateDeclaration<k>]: $[k];
|
|
129
|
+
}>;
|
|
130
|
+
import<names extends exportedNameOf<$>[]>(...names: names): SchemaModule<{
|
|
131
|
+
[k in names[number] as PrivateDeclaration<k>]: $[k];
|
|
132
|
+
} & unknown>;
|
|
133
|
+
unitFn: Fn | undefined;
|
|
134
|
+
get precompilation(): string | undefined;
|
|
135
|
+
private _exported;
|
|
136
|
+
private _exports;
|
|
137
|
+
export(): SchemaModule<{
|
|
138
|
+
[k in exportedNameOf<$>]: $[k];
|
|
139
|
+
}>;
|
|
140
|
+
export<names extends exportedNameOf<$>[]>(...names: names): SchemaModule<{
|
|
141
|
+
[k in names[number]]: $[k];
|
|
142
|
+
} & unknown>;
|
|
143
|
+
resolve<name extends exportedNameOf<$>>(name: name): instantiateRoot<$[name]>;
|
|
144
|
+
/** the module `exportLazily` returns, once read */
|
|
145
|
+
private _lazy;
|
|
146
|
+
exportLazily(): SchemaModule<{
|
|
147
|
+
[k in exportedNameOf<$>]: $[k];
|
|
148
|
+
}>;
|
|
149
|
+
node: <kind extends NodeKind, reduced extends boolean = false>(kind: kind, input: NodeInput<kind>, opts?: BaseParseOptions<reduced>) => nodeOfKind<reduced extends true ? kind : reducibleKindOf<kind>>;
|
|
150
|
+
parse: (def: unknown, opts?: BaseParseOptions) => BaseRoot;
|
|
151
|
+
/** parses a definition in this scope to a node */
|
|
152
|
+
parseDef(def: unknown, opts?: BaseParseOptions): BaseRoot;
|
|
153
|
+
openSynthetic(name: string | undefined): BaseParseContext;
|
|
154
|
+
/** parses a definition in this scope while its aliases may still be open */
|
|
155
|
+
private parseOpenDef;
|
|
156
|
+
fin<node extends BaseRoot>(node: node, jit?: boolean): node;
|
|
157
|
+
jit(node: BaseNode): void;
|
|
158
|
+
protected abstract preparseOwn(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
|
|
159
|
+
abstract parseOwn(def: unknown, ctx: BaseParseContext): BaseRoot;
|
|
160
|
+
/** an alias's entry as the scope writes it, its generic params and keyword config applied, before it's parsed */
|
|
161
|
+
protected abstract preparseEntry(k: string, v: unknown): AliasDefEntry;
|
|
162
|
+
/** a scope value as the definition it's parsed from, e.g. a Type's internal node */
|
|
163
|
+
protected abstract normValue(resolution: unknown): unknown;
|
|
164
|
+
}
|
|
165
|
+
export declare class SchemaScope<$ extends {} = {}> extends BaseScope<$> {
|
|
166
|
+
parseOwn(def: unknown, ctx: BaseParseContext): BaseRoot;
|
|
167
|
+
protected preparseOwn(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
|
|
168
|
+
protected preparseEntry(k: string, v: unknown): AliasDefEntry;
|
|
169
|
+
protected normValue(v: unknown): unknown;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* whether a module's member can hold `resolution`: an alias referencing a
|
|
173
|
+
* definition still resolving is a placeholder, read while that definition's
|
|
174
|
+
* expression is written, which the member would otherwise hold for good
|
|
175
|
+
*/
|
|
176
|
+
export declare const isFinalResolution: (resolution: unknown) => boolean;
|
|
177
|
+
export declare const finalizeExport: ($: BaseScope, resolution: BaseRoot | GenericRoot) => BaseRoot | GenericRoot;
|
|
178
|
+
/** calls `fn` with `resolveAmbient(name)` resolving nothing */
|
|
179
|
+
export declare const whileResolvingAmbient: <t>(name: string, fn: () => t) => t;
|
|
180
|
+
/** the root the builtin keyword named resolves to, if any */
|
|
181
|
+
export declare const resolveAmbient: (name: string) => BaseRoot | undefined;
|
|
182
|
+
type instantiateAliases<aliases> = {
|
|
183
|
+
[k in keyof aliases]: aliases[k] extends InternalResolution ? aliases[k] : BaseRoot;
|
|
184
|
+
} & unknown;
|
|
185
|
+
export type SchemaScopeParser = <const aliases>(aliases: {
|
|
186
|
+
[k in keyof aliases]: conform<aliases[k], RootSchema | PreparsedNodeResolution>;
|
|
187
|
+
}, config?: ArkSchemaScopeConfig) => BaseScope<instantiateAliases<aliases>>;
|
|
188
|
+
export declare const schemaScope: SchemaScopeParser;
|
|
189
|
+
export declare const rootSchemaScope: SchemaScope;
|
|
190
|
+
export declare const bootstrapRootScope: () => void;
|
|
191
|
+
export declare const parseAsSchema: (def: unknown, opts?: BaseParseOptions) => BaseRoot | ParseError;
|
|
192
|
+
export type RootExportCache = Record<string, BaseRoot | GenericRoot | RootModule | undefined>;
|
|
193
|
+
export declare const writeUnresolvableMessage: <token extends string>(token: token) => writeUnresolvableMessage<token>;
|
|
194
|
+
export type writeUnresolvableMessage<token extends string> = `'${token}' is unresolvable`;
|
|
195
|
+
export declare const writeNonSubmoduleDotMessage: <name extends string>(name: name) => writeNonSubmoduleDotMessage<name>;
|
|
196
|
+
export type writeNonSubmoduleDotMessage<name extends string> = `'${name}' must reference a module to be accessed using dot syntax`;
|
|
197
|
+
export declare const writeMissingSubmoduleAccessMessage: <name extends string>(name: name) => writeMissingSubmoduleAccessMessage<name>;
|
|
198
|
+
export type writeMissingSubmoduleAccessMessage<name extends string> = `Reference to submodule '${name}' must specify an alias`;
|
|
199
|
+
export declare const rootSchema: BaseScope["schema"];
|
|
200
|
+
export declare const node: BaseScope["node"];
|
|
201
|
+
export declare const defineSchema: BaseScope["defineSchema"];
|
|
202
|
+
export declare const genericNode: BaseScope["generic"];
|
|
203
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Morph } from "../roots/morph.ts";
|
|
2
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
3
|
+
export declare const inverses: WeakMap<Morph, Morph>;
|
|
4
|
+
export declare const writeMissingInverseMessage: (expression: string) => string;
|
|
5
|
+
export declare const encode: (node: BaseRoot) => BaseRoot;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { CastableBase, type Fn } from "../../util/index.js";
|
|
2
|
+
import type { ResolvedConfig } from "../config.ts";
|
|
3
|
+
import type { BaseNode } from "../node.ts";
|
|
4
|
+
import type { NodeId } from "../parse.ts";
|
|
5
|
+
import type { Predicate } from "../predicate.ts";
|
|
6
|
+
import type { IntersectionNode } from "../roots/intersection.ts";
|
|
7
|
+
import type { BaseRoot } from "../roots/root.ts";
|
|
8
|
+
import type { UnionNode } from "../roots/union.ts";
|
|
9
|
+
import type { StructureNode } from "../structure/structure.ts";
|
|
10
|
+
import { type TraversalKind } from "./traversal.ts";
|
|
11
|
+
import type { ArkEnv } from "./declare.ts";
|
|
12
|
+
export declare const canJit: (config: ResolvedConfig) => boolean;
|
|
13
|
+
export declare const tryJit: <result>(jit: () => result) => result | undefined;
|
|
14
|
+
export type CoercibleValue = string | number | boolean | null | undefined;
|
|
15
|
+
export declare class CompiledFunction<compiledSignature = (...args: unknown[]) => unknown, args extends readonly string[] = readonly string[]> extends CastableBase<{
|
|
16
|
+
[k in args[number]]: k;
|
|
17
|
+
}> {
|
|
18
|
+
readonly argNames: args;
|
|
19
|
+
private readonly lines;
|
|
20
|
+
get body(): string;
|
|
21
|
+
constructor(...args: args);
|
|
22
|
+
indentation: number;
|
|
23
|
+
indent(): this;
|
|
24
|
+
dedent(): this;
|
|
25
|
+
prop(key: PropertyKey, optional?: boolean): string;
|
|
26
|
+
index(key: string | number, optional?: boolean): string;
|
|
27
|
+
line(statement: string): this;
|
|
28
|
+
const(identifier: string, expression: CoercibleValue): this;
|
|
29
|
+
let(identifier: string, expression: CoercibleValue): this;
|
|
30
|
+
set(identifier: string, expression: CoercibleValue): this;
|
|
31
|
+
if(condition: string, then: (self: this) => this): this;
|
|
32
|
+
elseIf(condition: string, then: (self: this) => this): this;
|
|
33
|
+
else(then: (self: this) => this): this;
|
|
34
|
+
/** Current index is "i" */
|
|
35
|
+
for(until: string, body: (self: this) => this, initialValue?: CoercibleValue): this;
|
|
36
|
+
/** Current key is "k" */
|
|
37
|
+
forIn(object: string, body: (self: this) => this): this;
|
|
38
|
+
loopDepth: number;
|
|
39
|
+
loop(prefix: string, body: (self: this) => this): this;
|
|
40
|
+
block(prefix: string, contents: (self: this) => this, suffix?: string): this;
|
|
41
|
+
return(expression?: CoercibleValue): this;
|
|
42
|
+
write(name?: string, indent?: number): string;
|
|
43
|
+
compile(): compiledSignature;
|
|
44
|
+
}
|
|
45
|
+
export declare const compileSerializedValue: (value: unknown) => string;
|
|
46
|
+
export declare const compileLiteralPropAccess: (key: PropertyKey, optional?: boolean) => string;
|
|
47
|
+
export declare const serializeLiteralKey: (key: PropertyKey) => string;
|
|
48
|
+
export declare const indexPropAccess: (key: string, optional?: boolean) => string;
|
|
49
|
+
export interface InvokeOptions extends ReferenceOptions {
|
|
50
|
+
arg?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface CheckOptions extends InvokeOptions {
|
|
53
|
+
breaks?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface ReferenceOptions {
|
|
56
|
+
kind?: TraversalKind;
|
|
57
|
+
bind?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface TransformKeyOptions {
|
|
60
|
+
/** the expression of the key a transformed value is written to */
|
|
61
|
+
keyExpr?: string;
|
|
62
|
+
condition?: string;
|
|
63
|
+
onChange?: () => unknown;
|
|
64
|
+
}
|
|
65
|
+
export type SwitchCase = readonly [label: string, returned: string];
|
|
66
|
+
export interface TransformStep {
|
|
67
|
+
node: BaseNode;
|
|
68
|
+
signature?: BaseNode;
|
|
69
|
+
}
|
|
70
|
+
export declare const expectedOf: <description extends string | undefined>(meta: ArkEnv.meta, description: description) => string | description;
|
|
71
|
+
export declare namespace NodeCompiler {
|
|
72
|
+
interface Context {
|
|
73
|
+
kind: TraversalKind;
|
|
74
|
+
needsCtx?: boolean;
|
|
75
|
+
refs?: Refs;
|
|
76
|
+
}
|
|
77
|
+
type Refs = Map<object | symbol, string>;
|
|
78
|
+
}
|
|
79
|
+
export declare abstract class NodeCompiler extends CompiledFunction<Fn, [
|
|
80
|
+
"data",
|
|
81
|
+
"ctx"
|
|
82
|
+
]> {
|
|
83
|
+
trav: TraversalKind;
|
|
84
|
+
/** whether the traversal it compiles takes `ctx` */
|
|
85
|
+
needsCtx: boolean;
|
|
86
|
+
readonly refs: NodeCompiler.Refs | undefined;
|
|
87
|
+
readonly inPlace?: boolean;
|
|
88
|
+
readonly reportsFirst?: boolean;
|
|
89
|
+
readonly shortest?: boolean;
|
|
90
|
+
readonly copiesValues?: boolean;
|
|
91
|
+
readonly jsonInput?: boolean;
|
|
92
|
+
readonly readsApplied?: boolean;
|
|
93
|
+
/** whether the transform it compiles checks for errors a transformed child added */
|
|
94
|
+
checksErrs: boolean;
|
|
95
|
+
constructor(ctx: NodeCompiler.Context);
|
|
96
|
+
unionFails?(node: UnionNode): string;
|
|
97
|
+
listedFails?(node: UnionNode): string;
|
|
98
|
+
missFails?(node: UnionNode): string;
|
|
99
|
+
defaultFails?(node: UnionNode, caseNode: BaseRoot): string;
|
|
100
|
+
undeclaredFails?(node: StructureNode): string;
|
|
101
|
+
failingSiteOf?(prop: BaseNode): string | undefined;
|
|
102
|
+
failingApplyOf?(value: BaseNode): string | undefined;
|
|
103
|
+
addsNoIssues?(predicate: Predicate): boolean;
|
|
104
|
+
abstract outline(name: string, args: readonly string[], body: (js: NodeCompiler) => unknown): this;
|
|
105
|
+
/** an expression calling node's traversal, or a referenced one's by id */
|
|
106
|
+
inv(node: BaseNode | NodeId, opts?: InvokeOptions): string;
|
|
107
|
+
allows(node: BaseNode, arg?: string): string;
|
|
108
|
+
applyMember(node: BaseNode, member?: BaseNode): string;
|
|
109
|
+
resolution(node: BaseNode, id: NodeId, arg?: string): string;
|
|
110
|
+
refToId(id: NodeId, opts?: ReferenceOptions): string;
|
|
111
|
+
nameOf(id: NodeId): string;
|
|
112
|
+
prop(key: PropertyKey, optional?: boolean): string;
|
|
113
|
+
serialize(value: unknown): string;
|
|
114
|
+
/** validates that a numeric literal interpolated into generated JS is a number */
|
|
115
|
+
num(n: number): string;
|
|
116
|
+
ref(value: object | symbol): string;
|
|
117
|
+
site(node: BaseNode): string;
|
|
118
|
+
error(node: BaseNode, key?: string, data?: string): string;
|
|
119
|
+
failsSite(site: string, data: string, key?: string): string;
|
|
120
|
+
failsEither(condition: string, site: string, otherwise: string, data: string, key: string): string;
|
|
121
|
+
failsIn(args: string): string;
|
|
122
|
+
applied(key: string, value: string, missing?: string): string;
|
|
123
|
+
switch(on: string, cases: readonly SwitchCase[], otherwise: string): this;
|
|
124
|
+
needsCtxFor(node: BaseNode, kind?: TraversalKind): boolean;
|
|
125
|
+
rejectNullish(node: BaseNode): this;
|
|
126
|
+
rejection(node: BaseNode): string;
|
|
127
|
+
initErrCount(): this;
|
|
128
|
+
travKey(keyExpr: string, accessExpression: string, node: BaseNode): this;
|
|
129
|
+
keyFails(key: string, value: string, node: BaseNode): string | undefined;
|
|
130
|
+
private applyKey;
|
|
131
|
+
initTf(transformedChildren: readonly BaseNode[]): this;
|
|
132
|
+
tfKey(name: string, input: string, steps: readonly TransformStep[], opts?: TransformKeyOptions): this;
|
|
133
|
+
addMorphErrs(errors: string, keyExpr?: string): this;
|
|
134
|
+
cmpTfd(steps: readonly TransformStep[], transformed: string, operator: "===" | "!==", input: string): string;
|
|
135
|
+
retIfFailed(): this;
|
|
136
|
+
condition(node: BaseNode): string;
|
|
137
|
+
check(node: BaseNode, opts?: CheckOptions): this;
|
|
138
|
+
checkLeaf(node: BaseNode): this;
|
|
139
|
+
traversal(node: BaseNode, kind: TraversalKind): string;
|
|
140
|
+
}
|
|
141
|
+
export declare const returnsTransformErrors: (node: BaseNode) => boolean;
|
|
142
|
+
export declare const isDecidedByAllows: (node: BaseNode) => boolean;
|
|
143
|
+
export declare const isRefinedBasis: (node: BaseNode) => node is IntersectionNode;
|
|
144
|
+
export declare const isRefinedPattern: (node: BaseNode) => node is IntersectionNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* configure()'s argument, copied through its objects and arrays so writing
|
|
3
|
+
* to what was passed after the call, like a keyword's description, changes
|
|
4
|
+
* nothing, as it can't once a Type exists. A locale is kept as passed, as
|
|
5
|
+
* arktype reads one by identity, and so is any other instance, like a Date
|
|
6
|
+
*/
|
|
7
|
+
export declare const copyConfig: <config extends object>(config: config) => config;
|
|
8
|
+
/**
|
|
9
|
+
* whether a config changes nothing of what's applied, as when a test runner
|
|
10
|
+
* resets its modules and the config module runs again. That creates each
|
|
11
|
+
* function it declares anew, so a function is the same where its source is,
|
|
12
|
+
* unless it's native, like a bound one, whose source is the same for any
|
|
13
|
+
*/
|
|
14
|
+
export declare const isSameConfig: (l: unknown, r: unknown) => boolean;
|