arktype 2.0.0-dev.5 → 2.0.0-dev.7
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/__tests__/array.test.ts +70 -38
- package/__tests__/badDefinitionType.test.ts +9 -2
- package/__tests__/basis.test.ts +6 -2
- package/__tests__/bounds.test.ts +49 -218
- package/__tests__/cast.test.ts +7 -2
- package/__tests__/completions.test.ts +8 -3
- package/__tests__/config.test.ts +8 -2
- package/__tests__/cyclic.test.ts +141 -137
- package/__tests__/dateLiteral.test.ts +6 -2
- package/__tests__/declared.test.ts +2 -2
- package/__tests__/divisor.test.ts +28 -12
- package/__tests__/enclosed.test.ts +32 -23
- package/__tests__/examples.test.ts +56 -56
- package/__tests__/expressions.test.ts +184 -106
- package/__tests__/generic.test.ts +307 -287
- package/__tests__/group.test.ts +59 -51
- package/__tests__/imports.test.ts +44 -37
- package/__tests__/instanceof.test.ts +14 -12
- package/__tests__/intersection.test.ts +16 -36
- package/__tests__/keyTraversal.test.ts +6 -1
- package/__tests__/keyof.test.ts +57 -43
- package/__tests__/keywords.test.ts +144 -135
- package/__tests__/literal.test.ts +12 -7
- package/__tests__/match.test.ts +234 -236
- package/__tests__/morph.test.ts +169 -153
- package/__tests__/narrow.test.ts +14 -9
- package/__tests__/objectLiteral.test.ts +172 -184
- package/__tests__/realWorld.test.ts +60 -59
- package/__tests__/regex.test.ts +17 -7
- package/__tests__/scope.test.ts +59 -14
- package/__tests__/serialization.test.ts +19 -0
- package/__tests__/string.test.ts +11 -7
- package/__tests__/submodule.test.ts +24 -37
- package/__tests__/this.test.ts +83 -57
- package/__tests__/thunk.test.ts +13 -7
- package/__tests__/traverse.test.ts +22 -12
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +38 -0
- package/__tests__/typeReference.test.ts +5 -5
- package/__tests__/unenclosed.test.ts +106 -96
- package/__tests__/union.test.ts +207 -212
- package/ark.ts +44 -0
- package/generic.ts +67 -0
- package/main.ts +6 -17
- package/match.ts +41 -51
- package/module.ts +15 -0
- package/out/ark.d.ts +12 -40
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +9 -20
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +198 -122
- package/out/base.d.ts.map +1 -1
- package/out/base.js +317 -271
- package/out/base.js.map +1 -1
- package/out/builtins/builtins.d.ts +21 -17
- package/out/builtins/builtins.js +15 -12
- package/out/builtins/jsObjects.d.ts +17 -17
- package/out/builtins/jsObjects.js +18 -15
- package/out/builtins/parsing.d.ts +13 -13
- package/out/builtins/parsing.js +57 -54
- package/out/builtins/tsGenerics.d.ts +2 -2
- package/out/builtins/tsGenerics.js +2 -2
- package/out/builtins/tsKeywords.d.ts +21 -21
- package/out/builtins/tsKeywords.js +23 -20
- package/out/builtins/utils/creditCard.d.ts +3 -3
- package/out/builtins/utils/creditCard.js +31 -32
- package/out/builtins/utils/date.d.ts +39 -20
- package/out/builtins/utils/date.js +51 -48
- package/out/builtins/validation.d.ts +17 -17
- package/out/builtins/validation.js +66 -62
- package/out/config.d.ts +9 -6
- package/out/config.js +17 -16
- package/out/constraints/ast.d.ts +263 -152
- package/out/constraints/ast.js +2 -2
- package/out/constraints/constraint.d.ts +196 -66
- package/out/constraints/constraint.js +21 -17
- package/out/constraints/predicate.d.ts +60 -42
- package/out/constraints/predicate.js +48 -43
- package/out/constraints/props/index.d.ts +35 -29
- package/out/constraints/props/index.js +54 -46
- package/out/constraints/props/optional.d.ts +31 -28
- package/out/constraints/props/optional.js +54 -53
- package/out/constraints/props/prop.d.ts +42 -39
- package/out/constraints/props/prop.js +104 -102
- package/out/constraints/props/props.d.ts +35 -32
- package/out/constraints/props/props.js +117 -102
- package/out/constraints/props/props.js.map +1 -1
- package/out/constraints/props/required.d.ts +40 -37
- package/out/constraints/props/required.js +78 -73
- package/out/constraints/props/sequence.d.ts +74 -56
- package/out/constraints/props/sequence.js +371 -322
- package/out/constraints/props/shared.d.ts +3 -3
- package/out/constraints/props/shared.js +4 -4
- package/out/constraints/refinements/after.d.ts +26 -18
- package/out/constraints/refinements/after.js +34 -33
- package/out/constraints/refinements/before.d.ts +26 -18
- package/out/constraints/refinements/before.js +41 -39
- package/out/constraints/refinements/divisor.d.ts +47 -37
- package/out/constraints/refinements/divisor.js +48 -37
- package/out/constraints/refinements/exactLength.d.ts +40 -36
- package/out/constraints/refinements/exactLength.js +50 -42
- package/out/constraints/refinements/kinds.d.ts +25 -25
- package/out/constraints/refinements/kinds.js +16 -16
- package/out/constraints/refinements/length.d.ts +45 -39
- package/out/constraints/refinements/length.js +51 -43
- package/out/constraints/refinements/max.d.ts +24 -17
- package/out/constraints/refinements/max.js +33 -29
- package/out/constraints/refinements/maxLength.d.ts +25 -17
- package/out/constraints/refinements/maxLength.js +34 -32
- package/out/constraints/refinements/min.d.ts +24 -17
- package/out/constraints/refinements/min.js +26 -23
- package/out/constraints/refinements/minLength.d.ts +25 -17
- package/out/constraints/refinements/minLength.js +31 -30
- package/out/constraints/refinements/range.d.ts +107 -78
- package/out/constraints/refinements/range.js +83 -66
- package/out/constraints/refinements/regex.d.ts +42 -38
- package/out/constraints/refinements/regex.js +35 -34
- package/out/constraints/refinements/shared.d.ts +20 -5
- package/out/constraints/refinements/shared.js +9 -9
- package/out/generic.d.ts +22 -0
- package/out/generic.d.ts.map +1 -0
- package/out/generic.js +23 -0
- package/out/generic.js.map +1 -0
- package/out/inference.d.ts +132 -35
- package/out/inference.js +2 -2
- package/out/keywords/ark.d.ts +60 -50
- package/out/keywords/ark.js +25 -25
- package/out/keywords/internal.d.ts +11 -11
- package/out/keywords/internal.js +13 -10
- package/out/keywords/jsObject.d.ts +18 -18
- package/out/keywords/jsObject.js +18 -15
- package/out/keywords/parsing.d.ts +14 -14
- package/out/keywords/parsing.js +53 -50
- package/out/keywords/root.d.ts +6 -6
- package/out/keywords/root.js +4 -4
- package/out/keywords/tsGenerics.d.ts +2 -2
- package/out/keywords/tsGenerics.js +2 -2
- package/out/keywords/tsPrimitive.d.ts +22 -22
- package/out/keywords/tsPrimitive.js +25 -22
- package/out/keywords/utils/creditCard.d.ts +11 -8
- package/out/keywords/utils/creditCard.js +31 -32
- package/out/keywords/utils/date.d.ts +43 -23
- package/out/keywords/utils/date.js +51 -48
- package/out/keywords/validation.d.ts +18 -18
- package/out/keywords/validation.js +67 -63
- package/out/kinds.d.ts +97 -67
- package/out/kinds.js +28 -28
- package/out/main.d.ts +6 -7
- package/out/main.d.ts.map +1 -1
- package/out/main.js +5 -2
- package/out/main.js.map +1 -1
- package/out/match.d.ts +6 -10
- package/out/match.d.ts.map +1 -1
- package/out/match.js +1 -1
- package/out/match.js.map +1 -1
- package/out/module.d.ts +11 -0
- package/out/module.d.ts.map +1 -0
- package/out/module.js +4 -0
- package/out/module.js.map +1 -0
- package/out/parse.d.ts +28 -22
- package/out/parse.js +157 -144
- package/out/parser/definition.d.ts +8 -10
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +5 -6
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +3 -4
- package/out/parser/generic.d.ts.map +1 -1
- package/out/parser/generic.js +6 -8
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +5 -6
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +10 -15
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +4 -3
- package/out/parser/semantic/bounds.d.ts.map +1 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +4 -3
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +7 -10
- package/out/parser/semantic/infer.d.ts.map +1 -1
- package/out/parser/semantic/utils.d.ts.map +1 -1
- package/out/parser/semantic/validate.d.ts +13 -11
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js +1 -0
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +7 -8
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +26 -22
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +2 -2
- package/out/parser/string/reduce/shared.d.ts.map +1 -1
- package/out/parser/string/reduce/static.d.ts +8 -5
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +1 -1
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js +2 -2
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +1 -1
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +8 -8
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js +6 -8
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -3
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js +8 -11
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +10 -16
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +19 -24
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +6 -8
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +20 -29
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -2
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -1
- package/out/parser/string/shift/operator/operator.js +12 -18
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js +12 -11
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +7 -4
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +27 -30
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +33 -35
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +171 -40
- package/out/schema.js +2 -2
- package/out/schemaScope.d.ts +170 -100
- package/out/schemaScope.js +231 -208
- package/out/scope.d.ts +43 -187
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +56 -326
- package/out/scope.js.map +1 -1
- package/out/shared/compile.d.ts +19 -19
- package/out/shared/compile.js +77 -65
- package/out/shared/context.d.ts +51 -26
- package/out/shared/context.js +50 -45
- package/out/shared/declare.d.ts +61 -45
- package/out/shared/declare.js +2 -2
- package/out/shared/disjoint.d.ts +85 -73
- package/out/shared/disjoint.js +108 -80
- package/out/shared/disjoint.js.map +1 -1
- package/out/shared/errors.d.ts +85 -45
- package/out/shared/errors.js +101 -101
- package/out/shared/implement.d.ts +351 -158
- package/out/shared/implement.js +61 -62
- package/out/shared/implement.js.map +1 -1
- package/out/shared/inference.d.ts +5 -5
- package/out/shared/inference.js +2 -2
- package/out/shared/intersections.d.ts +57 -12
- package/out/shared/intersections.js +2 -2
- package/out/shared/traversal.d.ts +57 -39
- package/out/shared/traversal.js +95 -95
- package/out/shared/utils.d.ts +23 -7
- package/out/shared/utils.d.ts.map +1 -1
- package/out/shared/utils.js +14 -9
- package/out/shared/utils.js.map +1 -1
- package/out/type.d.ts +24 -32
- package/out/type.d.ts.map +1 -1
- package/out/type.js +2 -51
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +44 -21
- package/out/types/basis.js +13 -13
- package/out/types/discriminate.d.ts +33 -19
- package/out/types/discriminate.js +116 -110
- package/out/types/domain.d.ts +54 -37
- package/out/types/domain.js +39 -36
- package/out/types/intersection.d.ts +121 -61
- package/out/types/intersection.js +355 -326
- package/out/types/morph.d.ts +148 -70
- package/out/types/morph.js +97 -93
- package/out/types/proto.d.ts +48 -39
- package/out/types/proto.js +58 -46
- package/out/types/type.d.ts +137 -55
- package/out/types/type.d.ts.map +1 -1
- package/out/types/type.js +121 -109
- package/out/types/type.js.map +1 -1
- package/out/types/union.d.ts +66 -43
- package/out/types/union.js +299 -257
- package/out/types/unit.d.ts +41 -36
- package/out/types/unit.js +53 -45
- package/out/util.d.ts +30 -21
- package/out/util.js +8 -7
- package/package.json +3 -2
- package/parser/definition.ts +64 -81
- package/parser/generic.ts +35 -36
- package/parser/objectLiteral.ts +78 -92
- package/parser/semantic/bounds.ts +25 -33
- package/parser/semantic/divisor.ts +7 -11
- package/parser/semantic/infer.ts +69 -80
- package/parser/semantic/utils.ts +10 -13
- package/parser/semantic/validate.ts +81 -71
- package/parser/string/reduce/dynamic.ts +42 -39
- package/parser/string/reduce/shared.ts +1 -1
- package/parser/string/reduce/static.ts +50 -52
- package/parser/string/shift/operand/date.ts +5 -5
- package/parser/string/shift/operand/enclosed.ts +12 -13
- package/parser/string/shift/operand/genericArgs.ts +45 -44
- package/parser/string/shift/operand/operand.ts +32 -37
- package/parser/string/shift/operand/unenclosed.ts +99 -134
- package/parser/string/shift/operator/bounds.ts +78 -75
- package/parser/string/shift/operator/divisor.ts +11 -13
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +39 -36
- package/parser/string/string.ts +26 -30
- package/parser/tuple.ts +206 -248
- package/scope.ts +185 -704
- package/type.ts +101 -140
- package/__tests__/errors.test.ts +0 -115
- package/__tests__/schema.bench.ts +0 -14
- package/__tests__/schema.test.ts +0 -60
- package/__tests__/typeMethods.test.ts +0 -68
- package/__tests__/unit.test.ts +0 -61
- package/base.ts +0 -520
- package/config.ts +0 -25
- package/constraints/ast.ts +0 -288
- package/constraints/constraint.ts +0 -91
- package/constraints/predicate.ts +0 -102
- package/constraints/props/index.ts +0 -93
- package/constraints/props/prop.ts +0 -146
- package/constraints/props/props.ts +0 -148
- package/constraints/props/sequence.ts +0 -473
- package/constraints/props/shared.ts +0 -5
- package/constraints/refinements/after.ts +0 -68
- package/constraints/refinements/before.ts +0 -75
- package/constraints/refinements/divisor.ts +0 -76
- package/constraints/refinements/exactLength.ts +0 -75
- package/constraints/refinements/kinds.ts +0 -31
- package/constraints/refinements/max.ts +0 -61
- package/constraints/refinements/maxLength.ts +0 -66
- package/constraints/refinements/min.ts +0 -54
- package/constraints/refinements/minLength.ts +0 -63
- package/constraints/refinements/range.ts +0 -181
- package/constraints/refinements/regex.ts +0 -59
- package/keywords/ark.ts +0 -101
- package/keywords/internal.ts +0 -29
- package/keywords/jsObject.ts +0 -39
- package/keywords/parsing.ts +0 -87
- package/keywords/root.ts +0 -9
- package/keywords/tsGenerics.ts +0 -28
- package/keywords/tsPrimitive.ts +0 -52
- package/keywords/utils/creditCard.ts +0 -37
- package/keywords/utils/date.ts +0 -112
- package/keywords/validation.ts +0 -115
- package/kinds.ts +0 -115
- package/parse.ts +0 -221
- package/schema.ts +0 -263
- package/shared/compile.ts +0 -92
- package/shared/declare.ts +0 -75
- package/shared/disjoint.ts +0 -203
- package/shared/errors.ts +0 -204
- package/shared/implement.ts +0 -327
- package/shared/inference.ts +0 -9
- package/shared/intersections.ts +0 -53
- package/shared/traversal.ts +0 -146
- package/shared/utils.ts +0 -30
- package/types/basis.ts +0 -62
- package/types/discriminate.ts +0 -168
- package/types/domain.ts +0 -79
- package/types/intersection.ts +0 -539
- package/types/morph.ts +0 -263
- package/types/proto.ts +0 -89
- package/types/type.ts +0 -319
- package/types/union.ts +0 -451
- package/types/unit.ts +0 -78
- package/util.ts +0 -39
package/out/parse.js
CHANGED
|
@@ -1,148 +1,161 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
entriesOf,
|
|
3
|
+
hasDomain,
|
|
4
|
+
isArray,
|
|
5
|
+
isKeyOf,
|
|
6
|
+
registry,
|
|
7
|
+
throwParseError
|
|
8
|
+
} from "@arktype/util"
|
|
9
|
+
import { BaseNode } from "./base.js"
|
|
10
|
+
import { nodesByKind } from "./kinds.js"
|
|
11
|
+
import { Disjoint } from "./shared/disjoint.js"
|
|
12
|
+
import { defaultValueSerializer, precedenceOfKind } from "./shared/implement.js"
|
|
13
|
+
const typeCountsByPrefix = {}
|
|
7
14
|
const baseKeys = {
|
|
8
|
-
|
|
9
|
-
}
|
|
15
|
+
description: { meta: true }
|
|
16
|
+
}
|
|
10
17
|
// eslint-disable-next-line prefer-arrow-functions/prefer-arrow-functions
|
|
11
18
|
export function parseAttachments(kind, schema, ctx) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
19
|
+
const cls = nodesByKind[kind]
|
|
20
|
+
const impl = cls.implementation
|
|
21
|
+
if (schema instanceof BaseNode && schema.kind === kind) {
|
|
22
|
+
return schema
|
|
23
|
+
}
|
|
24
|
+
const normalizedDefinition = impl.normalize?.(schema) ?? schema
|
|
25
|
+
// check again after normalization in case a node is a valid collapsed
|
|
26
|
+
// schema for the kind (e.g. sequence can collapse to element accepting a Node)
|
|
27
|
+
if (normalizedDefinition instanceof BaseNode) {
|
|
28
|
+
return normalizedDefinition.kind === kind
|
|
29
|
+
? normalizedDefinition
|
|
30
|
+
: throwMismatchedNodeSchemaError(kind, normalizedDefinition.kind)
|
|
31
|
+
}
|
|
32
|
+
const inner = {}
|
|
33
|
+
// ensure node entries are parsed in order of precedence, with non-children
|
|
34
|
+
// parsed first
|
|
35
|
+
const schemaEntries = entriesOf(normalizedDefinition).sort(
|
|
36
|
+
([lKey], [rKey]) =>
|
|
37
|
+
isKeyOf(lKey, nodesByKind)
|
|
38
|
+
? isKeyOf(rKey, nodesByKind)
|
|
39
|
+
? precedenceOfKind(lKey) - precedenceOfKind(rKey)
|
|
40
|
+
: 1
|
|
41
|
+
: isKeyOf(rKey, nodesByKind)
|
|
42
|
+
? -1
|
|
43
|
+
: lKey < rKey
|
|
44
|
+
? -1
|
|
45
|
+
: 1
|
|
46
|
+
)
|
|
47
|
+
const children = []
|
|
48
|
+
for (const entry of schemaEntries) {
|
|
49
|
+
const k = entry[0]
|
|
50
|
+
const keyImpl = impl.keys[k] ?? baseKeys[k]
|
|
51
|
+
if (!keyImpl) {
|
|
52
|
+
return throwParseError(`Key ${k} is not valid on ${kind} schema`)
|
|
53
|
+
}
|
|
54
|
+
const v = keyImpl.parse ? keyImpl.parse(entry[1], ctx) : entry[1]
|
|
55
|
+
if (v !== undefined || keyImpl.preserveUndefined) {
|
|
56
|
+
inner[k] = v
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const entries = entriesOf(inner)
|
|
60
|
+
let json = {}
|
|
61
|
+
let typeJson = {}
|
|
62
|
+
let collapsibleJson = {}
|
|
63
|
+
entries.forEach(([k, v]) => {
|
|
64
|
+
const keyImpl = impl.keys[k] ?? baseKeys[k]
|
|
65
|
+
if (keyImpl.child) {
|
|
66
|
+
const listableNode = v
|
|
67
|
+
if (isArray(listableNode)) {
|
|
68
|
+
json[k] = listableNode.map((node) => node.collapsibleJson)
|
|
69
|
+
children.push(...listableNode)
|
|
70
|
+
} else {
|
|
71
|
+
json[k] = listableNode.collapsibleJson
|
|
72
|
+
children.push(listableNode)
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
json[k] = keyImpl.serialize
|
|
76
|
+
? keyImpl.serialize(v)
|
|
77
|
+
: defaultValueSerializer(v)
|
|
78
|
+
}
|
|
79
|
+
if (!keyImpl.meta) {
|
|
80
|
+
typeJson[k] = json[k]
|
|
81
|
+
}
|
|
82
|
+
if (!keyImpl.implied) {
|
|
83
|
+
collapsibleJson[k] = json[k]
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
// check keys on collapsibleJson instead of schema in case one or more keys is
|
|
87
|
+
// implied, e.g. minVariadicLength on a SequenceNode
|
|
88
|
+
const collapsibleKeys = Object.keys(collapsibleJson)
|
|
89
|
+
if (
|
|
90
|
+
collapsibleKeys.length === 1 &&
|
|
91
|
+
collapsibleKeys[0] === impl.collapsibleKey
|
|
92
|
+
) {
|
|
93
|
+
collapsibleJson = collapsibleJson[impl.collapsibleKey]
|
|
94
|
+
if (
|
|
95
|
+
// if the collapsibleJson is still an object
|
|
96
|
+
hasDomain(collapsibleJson, "object") &&
|
|
97
|
+
// and the JSON did not include any implied keys
|
|
98
|
+
Object.keys(json).length === 1
|
|
99
|
+
) {
|
|
100
|
+
// we can replace it with its collapsed value
|
|
101
|
+
json = collapsibleJson
|
|
102
|
+
typeJson = collapsibleJson
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const innerId = JSON.stringify({ kind, ...json })
|
|
106
|
+
if (ctx.reduceTo) {
|
|
107
|
+
return (ctx.$.nodeCache[innerId] = ctx.reduceTo)
|
|
108
|
+
}
|
|
109
|
+
const typeId = JSON.stringify({ kind, ...typeJson })
|
|
110
|
+
if (impl.reduce && !ctx.prereduced) {
|
|
111
|
+
const reduced = impl.reduce(inner, ctx.$)
|
|
112
|
+
if (reduced) {
|
|
113
|
+
if (reduced instanceof Disjoint) return reduced.throw()
|
|
114
|
+
// if we're defining the resolution of an alias and the result is
|
|
115
|
+
// reduced to another node, add the alias to that node if it doesn't
|
|
116
|
+
// already have one.
|
|
117
|
+
if (ctx.alias) {
|
|
118
|
+
reduced.alias ??= ctx.alias
|
|
119
|
+
}
|
|
120
|
+
// we can't cache this reduction for now in case the reduction involved
|
|
121
|
+
// impliedSiblings
|
|
122
|
+
return reduced
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// we have to wait until after reduction to return a cached entry,
|
|
126
|
+
// since reduction can add impliedSiblings
|
|
127
|
+
if (innerId in ctx.$.nodeCache) {
|
|
128
|
+
return ctx.$.nodeCache[innerId]
|
|
129
|
+
}
|
|
130
|
+
const prefix = ctx.alias ?? kind
|
|
131
|
+
typeCountsByPrefix[prefix] ??= 0
|
|
132
|
+
const reference = `${prefix}${++typeCountsByPrefix[prefix]}`
|
|
133
|
+
const attachments = {
|
|
134
|
+
reference,
|
|
135
|
+
kind,
|
|
136
|
+
inner,
|
|
137
|
+
entries,
|
|
138
|
+
json: json,
|
|
139
|
+
typeJson: typeJson,
|
|
140
|
+
collapsibleJson: collapsibleJson,
|
|
141
|
+
children,
|
|
142
|
+
innerId,
|
|
143
|
+
typeId,
|
|
144
|
+
$: ctx.$
|
|
145
|
+
}
|
|
146
|
+
if (ctx.alias) {
|
|
147
|
+
attachments.alias = ctx.alias
|
|
148
|
+
}
|
|
149
|
+
for (const k in inner) {
|
|
150
|
+
// avoid conflict with builtin cached getters
|
|
151
|
+
if (k !== "description" && k !== "in" && k !== "out") {
|
|
152
|
+
attachments[k] = inner[k]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return (ctx.$.nodeCache[innerId] = new cls(attachments))
|
|
146
156
|
}
|
|
147
|
-
const throwMismatchedNodeSchemaError = (expected, actual) =>
|
|
148
|
-
|
|
157
|
+
const throwMismatchedNodeSchemaError = (expected, actual) =>
|
|
158
|
+
throwParseError(
|
|
159
|
+
`Node of kind ${actual} is not valid as a ${expected} definition`
|
|
160
|
+
)
|
|
161
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
3
|
-
import type { type } from "../
|
|
1
|
+
import { type RawSchema, type string } from "@arktype/schema";
|
|
2
|
+
import { type ErrorMessage, type Primitive, type array, type defined, type equals, type isAny, type isUnknown, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@arktype/util";
|
|
3
|
+
import type { type } from "../ark.js";
|
|
4
4
|
import type { ParseContext } from "../scope.js";
|
|
5
|
-
import type { Type } from "../types/type.js";
|
|
6
5
|
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.js";
|
|
7
6
|
import type { validateString } from "./semantic/validate.js";
|
|
8
7
|
import type { BaseCompletions, inferString } from "./string/string.js";
|
|
9
8
|
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.js";
|
|
10
|
-
export declare const parseObject: (def: object, ctx: ParseContext) =>
|
|
9
|
+
export declare const parseObject: (def: object, ctx: ParseContext) => RawSchema;
|
|
11
10
|
export type inferDefinition<def, $, args> = isAny<def> extends true ? never : def extends type.cast<infer t> | ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
12
|
-
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>> : isUnknown<def> extends true ?
|
|
13
|
-
BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
11
|
+
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>> : isUnknown<def> extends true ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
14
12
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
15
13
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
16
14
|
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : unknown;
|
|
17
|
-
} :
|
|
15
|
+
} : show<declarationMismatch<def, declared, $, args>> : def extends object ? show<{
|
|
18
16
|
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> : unknown;
|
|
19
17
|
} & {
|
|
20
|
-
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends keyof def ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> : unknown;
|
|
18
|
+
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> : unknown;
|
|
21
19
|
}> : validateShallowInference<def, declared, $, args>;
|
|
22
|
-
type validateShallowInference<def, declared, $, args> = equals<inferDefinition<def, $, args>, declared> extends true ? def :
|
|
20
|
+
type validateShallowInference<def, declared, $, args> = equals<inferDefinition<def, $, args>, declared> extends true ? def : show<declarationMismatch<def, declared, $, args>>;
|
|
23
21
|
type declarationMismatch<def, declared, $, args> = {
|
|
24
22
|
declared: declared;
|
|
25
23
|
inferred: inferDefinition<def, $, args>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../../parser/definition.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,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;AAEpD,KAAK,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,IAAI;IAClD,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,EAAE,eAAe,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;CACvC,CAAA;AAID,KAAK,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,CAAA;AAE7E,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAEvD,KAAK,iBAAiB,GAAG,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AAEnD,eAAO,MAAM,6BAA6B,0GAGoB,CAAA;AAE9D,KAAK,6BAA6B,CAAC,MAAM,SAAS,MAAM,IACvD,oDAAoD,MAAM,GAAG,CAAA"}
|
package/out/parser/definition.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import { hasArkKind } from "@arktype/schema";
|
|
1
2
|
import { isThunk, objectKindOf, printable, throwParseError } from "@arktype/util";
|
|
2
|
-
import { hasArkKind } from "../util.js";
|
|
3
3
|
import { parseObjectLiteral } from "./objectLiteral.js";
|
|
4
4
|
import { parseTuple } from "./tuple.js";
|
|
5
5
|
export const parseObject = (def, ctx) => {
|
|
6
6
|
const objectKind = objectKindOf(def);
|
|
7
7
|
switch (objectKind) {
|
|
8
8
|
case undefined:
|
|
9
|
-
if (hasArkKind(def, "
|
|
9
|
+
if (hasArkKind(def, "schema"))
|
|
10
10
|
return def;
|
|
11
|
-
}
|
|
12
11
|
return parseObjectLiteral(def, ctx);
|
|
13
12
|
case "Array":
|
|
14
13
|
return parseTuple(def, ctx);
|
|
@@ -17,12 +16,12 @@ export const parseObject = (def, ctx) => {
|
|
|
17
16
|
domain: "string",
|
|
18
17
|
regex: def
|
|
19
18
|
}, { prereduced: true });
|
|
20
|
-
case "Function":
|
|
19
|
+
case "Function": {
|
|
21
20
|
const resolvedDef = isThunk(def) ? def() : def;
|
|
22
|
-
if (hasArkKind(resolvedDef, "
|
|
21
|
+
if (hasArkKind(resolvedDef, "schema"))
|
|
23
22
|
return resolvedDef;
|
|
24
|
-
}
|
|
25
23
|
return throwParseError(writeBadDefinitionTypeMessage("Function"));
|
|
24
|
+
}
|
|
26
25
|
default:
|
|
27
26
|
return throwParseError(writeBadDefinitionTypeMessage(objectKind ?? printable(def)));
|
|
28
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../parser/definition.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../../parser/definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,UAAU,EAAe,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAQN,OAAO,EAEP,YAAY,EAGZ,SAAS,EAGT,eAAe,EACf,MAAM,eAAe,CAAA;AAGtB,OAAO,EAEN,kBAAkB,EAElB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAGN,UAAU,EAEV,MAAM,YAAY,CAAA;AAEnB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,GAAiB,EAAa,EAAE;IACxE,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;IACpC,QAAQ,UAAU,EAAE,CAAC;QACpB,KAAK,SAAS;YACb,IAAI,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC;gBAAE,OAAO,GAAG,CAAA;YACzC,OAAO,kBAAkB,CAAC,GAAW,EAAE,GAAG,CAAC,CAAA;QAC5C,KAAK,OAAO;YACX,OAAO,UAAU,CAAC,GAAY,EAAE,GAAG,CAAC,CAAA;QACrC,KAAK,QAAQ;YACZ,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAChB,cAAc,EACd;gBACC,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,GAAa;aACpB,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACpB,CAAA;QACF,KAAK,UAAU,CAAC,CAAC,CAAC;YACjB,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;YAC9C,IAAI,UAAU,CAAC,WAAW,EAAE,QAAQ,CAAC;gBAAE,OAAO,WAAW,CAAA;YACzD,OAAO,eAAe,CAAC,6BAA6B,CAAC,UAAU,CAAC,CAAC,CAAA;QAClE,CAAC;QACD;YACC,OAAO,eAAe,CACrB,6BAA6B,CAAC,UAAU,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAC3D,CAAA;IACH,CAAC;AACF,CAAC,CAAA;AA0ED,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC5C,MAAc,EAC0B,EAAE,CAC1C,oDAAoD,MAAM,GAAG,CAAA"}
|
package/out/parser/generic.d.ts
CHANGED
|
@@ -6,13 +6,12 @@ export type GenericParamsParseError<message extends string = string> = [
|
|
|
6
6
|
nominal<message, "InvalidGenericParameters">
|
|
7
7
|
];
|
|
8
8
|
export declare const parseGenericParams: (def: string) => string[];
|
|
9
|
-
export type parseGenericParams<def extends string> =
|
|
10
|
-
]> extends infer result extends string[] ? "" extends result[number] ? GenericParamsParseError<emptyGenericParameterMessage> : result : never;
|
|
9
|
+
export type parseGenericParams<def extends string> = $parseParams<def, "", []> extends infer result extends string[] ? "" extends result[number] ? GenericParamsParseError<emptyGenericParameterMessage> : result : never;
|
|
11
10
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
12
11
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
13
|
-
type
|
|
12
|
+
type $parseParams<unscanned extends string, param extends string, result extends string[]> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends "," ? $parseParams<nextUnscanned, "", [...result, param]> : lookahead extends Scanner.WhiteSpaceToken ? param extends "" ? $parseParams<Scanner.skipWhitespace<nextUnscanned>, "", result> : Scanner.skipWhitespace<nextUnscanned> extends (`${infer nextNonWhitespace}${infer rest}`) ? nextNonWhitespace extends "," ? $parseParams<rest, "", [...result, param]> : GenericParamsParseError<writeUnexpectedCharacterMessage<nextNonWhitespace, ",">> : [
|
|
14
13
|
...result,
|
|
15
14
|
param
|
|
16
|
-
] :
|
|
15
|
+
] : $parseParams<nextUnscanned, `${param}${lookahead}`, result> : param extends "" ? result : [...result, param];
|
|
17
16
|
export {};
|
|
18
17
|
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../parser/generic.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../parser/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAmB,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAEnD,MAAM,MAAM,kBAAkB,CAC7B,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,MAAM,SAAS,MAAM,GAAG,MAAM,IAC3B,GAAG,IAAI,IAAI,MAAM,GAAG,CAAA;AAGxB,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,IAAI;IACtE,OAAO,CAAC,OAAO,EAAE,0BAA0B,CAAC;CAC5C,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,MAAM,KAAG,MAAM,EACjB,CAAA;AAEtC,MAAM,MAAM,kBAAkB,CAAC,GAAG,SAAS,MAAM,IAChD,YAAY,CAAC,GA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
|
import { throwParseError } from "@arktype/util";
|
|
2
2
|
import { writeUnexpectedCharacterMessage } from "./string/shift/operator/operator.js";
|
|
3
3
|
import { Scanner } from "./string/shift/scanner.js";
|
|
4
|
-
export const parseGenericParams = (def) =>
|
|
5
|
-
export const emptyGenericParameterMessage =
|
|
6
|
-
const
|
|
4
|
+
export const parseGenericParams = (def) => $parseGenericParams(new Scanner(def));
|
|
5
|
+
export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
6
|
+
const $parseGenericParams = (scanner) => {
|
|
7
7
|
const param = scanner.shiftUntilNextTerminator();
|
|
8
8
|
if (param === "") {
|
|
9
9
|
throwParseError(emptyGenericParameterMessage);
|
|
10
10
|
}
|
|
11
11
|
scanner.shiftUntilNonWhitespace();
|
|
12
12
|
const nextNonWhitespace = scanner.shift();
|
|
13
|
-
return nextNonWhitespace === ""
|
|
14
|
-
? [param]
|
|
15
|
-
|
|
16
|
-
? [param, ...parseGenericParamsRecurse(scanner)]
|
|
17
|
-
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ","));
|
|
13
|
+
return (nextNonWhitespace === "" ? [param]
|
|
14
|
+
: nextNonWhitespace === "," ? [param, ...$parseGenericParams(scanner)]
|
|
15
|
+
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ",")));
|
|
18
16
|
};
|
|
19
17
|
//# sourceMappingURL=generic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../parser/generic.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../parser/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,eAAe,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAYnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAY,EAAE,CAC3D,mBAAmB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;AAStC,MAAM,CAAC,MAAM,4BAA4B,GACxC,uDAAuD,CAAA;AAIxD,MAAM,mBAAmB,GAAG,CAAC,OAAgB,EAAY,EAAE;IAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAA;IAChD,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAClB,eAAe,CAAC,4BAA4B,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,CAAC,uBAAuB,EAAE,CAAA;IACjC,MAAM,iBAAiB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAA;IACzC,OAAO,CACN,iBAAiB,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAClC,CAAC,CAAC,iBAAiB,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;YACtE,CAAC,CAAC,eAAe,CAAC,+BAA+B,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,CAC1E,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
1
|
+
import { type RawSchema, type writeInvalidPropertyKeyMessage } from "@arktype/schema";
|
|
2
|
+
import { type Dict, type ErrorMessage, type Key, type merge, type show } from "@arktype/util";
|
|
3
3
|
import type { ParseContext } from "../scope.js";
|
|
4
|
-
import type { Type } from "../types/type.js";
|
|
5
4
|
import type { inferDefinition, validateDefinition } from "./definition.js";
|
|
6
5
|
import type { astToString } from "./semantic/utils.js";
|
|
7
6
|
import type { validateString } from "./semantic/validate.js";
|
|
8
7
|
import { Scanner } from "./string/shift/scanner.js";
|
|
9
|
-
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) =>
|
|
8
|
+
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => RawSchema;
|
|
10
9
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
11
10
|
/**
|
|
12
11
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
@@ -17,7 +16,7 @@ type inferObjectLiteralInner<def extends object, $, args> = {
|
|
|
17
16
|
} & {
|
|
18
17
|
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
19
18
|
};
|
|
20
|
-
export type inferObjectLiteral<def extends object, $, args> =
|
|
19
|
+
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, inferObjectLiteralInner<def, $, args>> : inferObjectLiteralInner<def, $, args>>;
|
|
21
20
|
export type validateObjectLiteral<def, $, args> = {
|
|
22
21
|
[k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? indexParseError<message> : inferDefinition<indexDef, $, args> extends PropertyKey ? validateDefinition<def[k], $, args> : indexParseError<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : indexParseError<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : validateDefinition<def[k], $, args>;
|
|
23
22
|
};
|
|
@@ -54,7 +53,7 @@ type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName
|
|
|
54
53
|
inner: def;
|
|
55
54
|
}> : PreparsedKey.from<{
|
|
56
55
|
kind: "required";
|
|
57
|
-
inner: k extends `${Scanner.EscapeToken}${infer escapedIndexKey extends IndexKey}` ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
56
|
+
inner: k extends (`${Scanner.EscapeToken}${infer escapedIndexKey extends IndexKey}`) ? escapedIndexKey : k extends Key ? k : `${k & number}`;
|
|
58
57
|
}>;
|
|
59
58
|
declare const indexParseSymbol: unique symbol;
|
|
60
59
|
export type indexParseError<message extends string = string> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectLiteral.d.ts","sourceRoot":"","sources":["../../parser/objectLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"objectLiteral.d.ts","sourceRoot":"","sources":["../../parser/objectLiteral.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,SAAS,EAEd,KAAK,8BAA8B,EACnC,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,GAAG,EACR,KAAK,KAAK,EAEV,KAAK,IAAI,EAGT,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAEnD,eAAO,MAAM,kBAAkB,QAAS,IAAI,OAAO,YAAY,KAAG,SA0DjE,CAAA;AAED,eAAO,MAAM,qBAAqB,mEAC+B,CAAA;AAEjE;;;GAGG;AACH,KAAK,uBAAuB,CAAC,GAAG,SAAS,MAAM,EAAE,CAAC,EAAE,IAAI,IAAI;IAI3D,CAAC,UAAU,CAAC,IAAI,MAAM,GAAG,IAAI,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,eAAe,CAC5E,GAAG,CAAC,CAAC,CAAC,EACN,CAAC,EACD,IAAI,CACJ;CACD,GAAG;IACH,CAAC,UAAU,CAAC,IAAI,MAAM,GAAG,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe,CACjE,GAAG,CAAC,CAAC,CAAC,EACN,CAAC,EACD,IAAI,CACJ;CACD,CAAA;AAED,MAAM,MA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
|
|
2
3
|
import { Scanner } from "./string/shift/scanner.js";
|
|
3
4
|
export const parseObjectLiteral = (def, ctx) => {
|
|
@@ -14,7 +15,7 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
14
15
|
const spreadEntry = parsedEntries.shift();
|
|
15
16
|
const spreadNode = ctx.$.parse(spreadEntry.value, ctx);
|
|
16
17
|
if (!spreadNode.hasKind("intersection") ||
|
|
17
|
-
!spreadNode.extends(
|
|
18
|
+
!spreadNode.extends(tsKeywords.object)) {
|
|
18
19
|
return throwParseError(writeInvalidSpreadTypeMessage(printable(spreadEntry.value)));
|
|
19
20
|
}
|
|
20
21
|
// TODO: move to props group merge in schema
|
|
@@ -27,9 +28,6 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
27
28
|
if (entry.kind === "spread") {
|
|
28
29
|
return throwParseError(nonLeadingSpreadError);
|
|
29
30
|
}
|
|
30
|
-
ctx.path.push(`${typeof entry.inner === "symbol"
|
|
31
|
-
? `[${printable(entry.inner)}]`
|
|
32
|
-
: entry.inner}`);
|
|
33
31
|
if (entry.kind === "index") {
|
|
34
32
|
// handle key parsing first to match type behavior
|
|
35
33
|
const key = ctx.$.parse(entry.inner, ctx);
|
|
@@ -46,9 +44,8 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
46
44
|
});
|
|
47
45
|
propNodes.push(propNode);
|
|
48
46
|
}
|
|
49
|
-
ctx.path.pop();
|
|
50
47
|
}
|
|
51
|
-
return ctx.$.
|
|
48
|
+
return ctx.$.schema({
|
|
52
49
|
domain: "object",
|
|
53
50
|
prop: propNodes,
|
|
54
51
|
index: indexNodes
|
|
@@ -56,19 +53,17 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
56
53
|
};
|
|
57
54
|
export const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
58
55
|
export const parseEntry = (entry) => Object.assign(parseKey(entry[0]), { value: entry[1] });
|
|
59
|
-
const parseKey = (key) => typeof key === "symbol"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
? { inner: `${key.slice(0, -2)}?`, kind: "required" }
|
|
56
|
+
const parseKey = (key) => typeof key === "symbol" ? { inner: key, kind: "required" }
|
|
57
|
+
: key.at(-1) === "?" ?
|
|
58
|
+
key.at(-2) === Scanner.escapeToken ?
|
|
59
|
+
{ inner: `${key.slice(0, -2)}?`, kind: "required" }
|
|
64
60
|
: {
|
|
65
61
|
inner: key.slice(0, -1),
|
|
66
62
|
kind: "optional"
|
|
67
63
|
}
|
|
68
|
-
: key[0] === "[" && key.at(-1) === "]"
|
|
69
|
-
|
|
70
|
-
: key === "..."
|
|
71
|
-
? { inner: "...", kind: "spread" }
|
|
64
|
+
: key[0] === "[" && key.at(-1) === "]" ?
|
|
65
|
+
{ inner: key.slice(1, -1), kind: "index" }
|
|
66
|
+
: key === "..." ? { inner: "...", kind: "spread" }
|
|
72
67
|
: { inner: key === "\\..." ? "..." : key, kind: "required" };
|
|
73
68
|
export const writeInvalidSpreadTypeMessage = (def) => `Spread operand must resolve to an object literal type (was ${def})`;
|
|
74
69
|
//# sourceMappingURL=objectLiteral.js.map
|