arktype 1.1.0-dev-2 → 2.0.0-dev.1
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 +272 -0
- package/__tests__/astUtils.test.ts +17 -0
- package/__tests__/badDefinitionType.test.ts +51 -0
- package/__tests__/basis.test.ts +46 -0
- package/__tests__/bounds.test.ts +388 -0
- package/__tests__/cast.test.ts +32 -0
- package/__tests__/completions.test.ts +46 -0
- package/__tests__/config.test.ts +168 -0
- package/__tests__/cyclic.test.ts +144 -0
- package/__tests__/dateLiteral.test.ts +32 -0
- package/__tests__/declared.test.ts +123 -0
- package/__tests__/discrimination.test.ts +74 -0
- package/__tests__/divisor.test.ts +90 -0
- package/__tests__/enclosed.test.ts +93 -0
- package/__tests__/examples.test.ts +56 -0
- package/__tests__/expressions.test.ts +138 -0
- package/__tests__/generateBenchData.ts +89 -0
- package/__tests__/generated/cyclic.ts +3058 -0
- package/__tests__/generic.test.ts +294 -0
- package/__tests__/group.test.ts +72 -0
- package/__tests__/hkt.test.ts +22 -0
- package/__tests__/imports.test.ts +113 -0
- package/__tests__/instanceof.test.ts +102 -0
- package/__tests__/intersection.test.ts +104 -0
- package/__tests__/jsdoc.test.ts +64 -0
- package/__tests__/keyTraversal.test.ts +73 -0
- package/__tests__/keyof.test.ts +134 -0
- package/__tests__/keywords.test.ts +188 -0
- package/__tests__/literal.test.ts +51 -0
- package/__tests__/match.test.ts +34 -0
- package/__tests__/methods.bench.ts +22 -0
- package/__tests__/morph.test.ts +409 -0
- package/__tests__/narrow.test.ts +102 -0
- package/__tests__/nodeDefinitions.test.ts +190 -0
- package/__tests__/object.bench.ts +28 -0
- package/__tests__/objectLiteral.test.ts +300 -0
- package/__tests__/operand.bench.ts +45 -0
- package/__tests__/operator.bench.ts +130 -0
- package/__tests__/regex.test.ts +58 -0
- package/__tests__/scope.bench.ts +39 -0
- package/__tests__/scope.test.ts +140 -0
- package/__tests__/string.test.ts +48 -0
- package/__tests__/submodule.test.ts +99 -0
- package/__tests__/this.test.ts +57 -0
- package/__tests__/thunk.test.ts +80 -0
- package/__tests__/traverse.test.ts +119 -0
- package/__tests__/tsGenerics.test.ts +12 -0
- package/__tests__/typeMethods.test.ts +69 -0
- package/__tests__/typeReference.test.ts +39 -0
- package/__tests__/unenclosed.test.ts +120 -0
- package/__tests__/union.test.ts +147 -0
- package/ark.ts +91 -0
- package/main.ts +7 -9
- package/match.ts +47 -68
- package/out/ark.d.ts +52 -0
- package/out/ark.d.ts.map +1 -0
- package/out/ark.js +19 -0
- package/out/ark.js.map +1 -0
- package/out/arkConfig.d.ts +2 -0
- package/out/arkConfig.d.ts.map +1 -0
- package/out/arkConfig.js +10 -0
- package/out/arkConfig.js.map +1 -0
- package/out/main.d.ts +7 -0
- package/out/main.d.ts.map +1 -0
- package/out/main.js +4 -0
- package/out/main.js.map +1 -0
- package/out/match.d.ts +48 -0
- package/out/match.d.ts.map +1 -0
- package/{dist → out}/match.js +0 -5
- package/out/match.js.map +1 -0
- package/{dist → out}/parser/definition.d.ts +3 -3
- package/out/parser/definition.d.ts.map +1 -0
- package/{dist → out}/parser/definition.js +8 -5
- package/out/parser/definition.js.map +1 -0
- package/out/parser/generic.d.ts +18 -0
- package/out/parser/generic.d.ts.map +1 -0
- package/out/parser/generic.js +19 -0
- package/out/parser/generic.js.map +1 -0
- package/{dist → out}/parser/objectLiteral.d.ts +14 -5
- package/out/parser/objectLiteral.d.ts.map +1 -0
- package/out/parser/objectLiteral.js +66 -0
- package/out/parser/objectLiteral.js.map +1 -0
- package/out/parser/semantic/bounds.d.ts +13 -0
- package/out/parser/semantic/bounds.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/bounds.js.map +1 -1
- package/{dist → out}/parser/semantic/divisor.d.ts +2 -2
- package/{dist → out}/parser/semantic/divisor.d.ts.map +1 -1
- package/{dist → out}/parser/semantic/intersections.d.ts +1 -2
- package/out/parser/semantic/intersections.d.ts.map +1 -0
- package/out/parser/semantic/semantic.d.ts +33 -0
- package/out/parser/semantic/semantic.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/utils.d.ts +1 -1
- package/{dist → out}/parser/semantic/utils.d.ts.map +1 -1
- package/{dist → out}/parser/semantic/validate.d.ts +3 -3
- package/out/parser/semantic/validate.d.ts.map +1 -0
- package/{dist → out}/parser/semantic/validate.js.map +1 -1
- package/{dist → out}/parser/shared.d.ts +7 -1
- package/out/parser/shared.d.ts.map +1 -0
- package/{dist → out}/parser/shared.js +7 -1
- package/out/parser/shared.js.map +1 -0
- package/{dist → out}/parser/string/reduce/dynamic.d.ts +11 -9
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -0
- package/{dist → out}/parser/string/reduce/dynamic.js +13 -2
- package/out/parser/string/reduce/dynamic.js.map +1 -0
- package/{dist → out}/parser/string/reduce/shared.d.ts +29 -2
- package/{dist → out}/parser/string/reduce/shared.d.ts.map +1 -1
- package/{dist → out}/parser/string/reduce/shared.js +20 -1
- package/out/parser/string/reduce/shared.js.map +1 -0
- package/{dist → out}/parser/string/reduce/static.d.ts +1 -2
- package/out/parser/string/reduce/static.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/date.d.ts +3 -3
- package/out/parser/string/shift/operand/date.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/date.js.map +1 -1
- package/{dist → out}/parser/string/shift/operand/enclosed.d.ts +2 -2
- package/{dist → out}/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/{dist → out}/parser/string/shift/operand/enclosed.js +4 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts +29 -0
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -0
- package/out/parser/string/shift/operand/genericArgs.js +25 -0
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -0
- package/{dist → out}/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/{dist → out}/parser/string/shift/operand/operand.js.map +1 -1
- package/{dist → out}/parser/string/shift/operand/unenclosed.d.ts +7 -9
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operand/unenclosed.js +10 -10
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -0
- package/{dist → out}/parser/string/shift/operator/bounds.d.ts +11 -33
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -0
- package/out/parser/string/shift/operator/bounds.js +106 -0
- package/out/parser/string/shift/operator/bounds.js.map +1 -0
- package/{dist → out}/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -0
- package/{dist → out}/parser/string/shift/operator/operator.js.map +1 -1
- package/{dist → out}/parser/string/shift/scanner.d.ts +1 -1
- package/{dist → out}/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js.map +1 -0
- package/{dist → out}/parser/string/string.d.ts +9 -11
- package/out/parser/string/string.d.ts.map +1 -0
- package/out/parser/string/string.js +23 -0
- package/out/parser/string/string.js.map +1 -0
- package/{dist → out}/parser/tuple.d.ts +9 -11
- package/out/parser/tuple.d.ts.map +1 -0
- package/{dist → out}/parser/tuple.js +17 -14
- package/out/parser/tuple.js.map +1 -0
- package/{dist → out}/scope.d.ts +16 -16
- package/out/scope.d.ts.map +1 -0
- package/{dist → out}/scope.js +27 -22
- package/out/scope.js.map +1 -0
- package/out/test.d.ts +2 -0
- package/out/test.d.ts.map +1 -0
- package/out/test.js +7 -0
- package/out/test.js.map +1 -0
- package/out/tsconfig.build.tsbuildinfo +1 -0
- package/{dist → out}/type.d.ts +23 -47
- package/out/type.d.ts.map +1 -0
- package/{dist → out}/type.js +27 -31
- package/out/type.js.map +1 -0
- package/out/util.d.ts +19 -0
- package/out/util.d.ts.map +1 -0
- package/out/util.js +7 -0
- package/out/util.js.map +1 -0
- package/package.json +13 -15
- package/parser/definition.ts +58 -55
- package/parser/generic.ts +17 -157
- package/parser/objectLiteral.ts +107 -30
- package/parser/semantic/bounds.ts +22 -24
- package/parser/semantic/divisor.ts +2 -2
- package/parser/semantic/intersections.ts +17 -18
- package/parser/semantic/semantic.ts +80 -43
- package/parser/semantic/utils.ts +7 -7
- package/parser/semantic/validate.ts +40 -36
- package/parser/shared.ts +28 -17
- package/parser/string/reduce/dynamic.ts +26 -11
- package/parser/string/reduce/shared.ts +35 -7
- package/parser/string/reduce/static.ts +20 -22
- package/parser/string/shift/operand/date.ts +1 -4
- package/parser/string/shift/operand/enclosed.ts +5 -6
- package/parser/string/shift/operand/genericArgs.ts +127 -0
- package/parser/string/shift/operand/operand.ts +21 -21
- package/parser/string/shift/operand/unenclosed.ts +54 -68
- package/parser/string/shift/operator/bounds.ts +99 -64
- package/parser/string/shift/operator/operator.ts +31 -31
- package/parser/string/shift/scanner.ts +7 -7
- package/parser/string/string.ts +29 -32
- package/parser/tuple.ts +87 -88
- package/scope.ts +81 -80
- package/type.ts +76 -132
- package/util.ts +36 -0
- package/dist/main.d.ts +0 -11
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js +0 -8
- package/dist/main.js.map +0 -1
- package/dist/match.d.ts +0 -46
- package/dist/match.d.ts.map +0 -1
- package/dist/match.js.map +0 -1
- package/dist/parser/definition.d.ts.map +0 -1
- package/dist/parser/definition.js.map +0 -1
- package/dist/parser/generic.d.ts +0 -44
- package/dist/parser/generic.d.ts.map +0 -1
- package/dist/parser/generic.js +0 -46
- package/dist/parser/generic.js.map +0 -1
- package/dist/parser/objectLiteral.d.ts.map +0 -1
- package/dist/parser/objectLiteral.js +0 -38
- package/dist/parser/objectLiteral.js.map +0 -1
- package/dist/parser/semantic/bounds.d.ts +0 -13
- package/dist/parser/semantic/bounds.d.ts.map +0 -1
- package/dist/parser/semantic/intersections.d.ts.map +0 -1
- package/dist/parser/semantic/semantic.d.ts +0 -22
- package/dist/parser/semantic/semantic.d.ts.map +0 -1
- package/dist/parser/semantic/validate.d.ts.map +0 -1
- package/dist/parser/shared.d.ts.map +0 -1
- package/dist/parser/shared.js.map +0 -1
- package/dist/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/dist/parser/string/reduce/dynamic.js.map +0 -1
- package/dist/parser/string/reduce/shared.js.map +0 -1
- package/dist/parser/string/reduce/static.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/date.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/enclosed.js.map +0 -1
- package/dist/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/dist/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/dist/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/dist/parser/string/shift/operator/bounds.js +0 -95
- package/dist/parser/string/shift/operator/bounds.js.map +0 -1
- package/dist/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/dist/parser/string/shift/scanner.js.map +0 -1
- package/dist/parser/string/string.d.ts.map +0 -1
- package/dist/parser/string/string.js +0 -31
- package/dist/parser/string/string.js.map +0 -1
- package/dist/parser/tuple.d.ts.map +0 -1
- package/dist/parser/tuple.js.map +0 -1
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js.map +0 -1
- package/dist/scopes/ark.d.ts +0 -38
- package/dist/scopes/ark.d.ts.map +0 -1
- package/dist/scopes/ark.js +0 -24
- package/dist/scopes/ark.js.map +0 -1
- package/dist/scopes/jsObjects.d.ts +0 -19
- package/dist/scopes/jsObjects.d.ts.map +0 -1
- package/dist/scopes/jsObjects.js +0 -15
- package/dist/scopes/jsObjects.js.map +0 -1
- package/dist/scopes/parsing.d.ts +0 -18
- package/dist/scopes/parsing.d.ts.map +0 -1
- package/dist/scopes/parsing.js +0 -61
- package/dist/scopes/parsing.js.map +0 -1
- package/dist/scopes/tsGenerics.d.ts +0 -17
- package/dist/scopes/tsGenerics.d.ts.map +0 -1
- package/dist/scopes/tsGenerics.js +0 -13
- package/dist/scopes/tsGenerics.js.map +0 -1
- package/dist/scopes/tsKeywords.d.ts +0 -24
- package/dist/scopes/tsKeywords.d.ts.map +0 -1
- package/dist/scopes/tsKeywords.js +0 -20
- package/dist/scopes/tsKeywords.js.map +0 -1
- package/dist/scopes/utils/creditCard.d.ts +0 -3
- package/dist/scopes/utils/creditCard.d.ts.map +0 -1
- package/dist/scopes/utils/creditCard.js +0 -36
- package/dist/scopes/utils/creditCard.js.map +0 -1
- package/dist/scopes/utils/date.d.ts +0 -24
- package/dist/scopes/utils/date.d.ts.map +0 -1
- package/dist/scopes/utils/date.js +0 -53
- package/dist/scopes/utils/date.js.map +0 -1
- package/dist/scopes/validation.d.ts +0 -20
- package/dist/scopes/validation.d.ts.map +0 -1
- package/dist/scopes/validation.js +0 -57
- package/dist/scopes/validation.js.map +0 -1
- package/dist/type.d.ts.map +0 -1
- package/dist/type.js.map +0 -1
- package/scopes/ark.ts +0 -64
- package/scopes/jsObjects.ts +0 -29
- package/scopes/parsing.ts +0 -81
- package/scopes/tsGenerics.ts +0 -28
- package/scopes/tsKeywords.ts +0 -39
- package/scopes/utils/creditCard.ts +0 -37
- package/scopes/utils/date.ts +0 -108
- package/scopes/validation.ts +0 -81
- /package/{dist → out}/parser/semantic/bounds.js +0 -0
- /package/{dist → out}/parser/semantic/divisor.js +0 -0
- /package/{dist → out}/parser/semantic/divisor.js.map +0 -0
- /package/{dist → out}/parser/semantic/intersections.js +0 -0
- /package/{dist → out}/parser/semantic/intersections.js.map +0 -0
- /package/{dist → out}/parser/semantic/semantic.js +0 -0
- /package/{dist → out}/parser/semantic/semantic.js.map +0 -0
- /package/{dist → out}/parser/semantic/utils.js +0 -0
- /package/{dist → out}/parser/semantic/utils.js.map +0 -0
- /package/{dist → out}/parser/semantic/validate.js +0 -0
- /package/{dist → out}/parser/string/reduce/static.js +0 -0
- /package/{dist → out}/parser/string/reduce/static.js.map +0 -0
- /package/{dist → out}/parser/string/shift/operand/date.js +0 -0
- /package/{dist → out}/parser/string/shift/operand/operand.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operand/operand.js +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.d.ts.map +0 -0
- /package/{dist → out}/parser/string/shift/operator/divisor.js +0 -0
- /package/{dist → out}/parser/string/shift/operator/operator.d.ts +0 -0
- /package/{dist → out}/parser/string/shift/operator/operator.js +0 -0
- /package/{dist → out}/parser/string/shift/scanner.js +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
NumericallyBoundable,
|
|
3
|
-
writeUnboundableMessage
|
|
4
|
-
} from "@arktype/schema"
|
|
1
|
+
import type { NumericallyBoundable } from "@arktype/schema"
|
|
5
2
|
import type { ErrorMessage } from "@arktype/util"
|
|
6
|
-
import type { DateLiteral } from "../string/shift/operand/date.js"
|
|
7
3
|
import type {
|
|
8
|
-
BoundKind,
|
|
9
4
|
Comparator,
|
|
10
5
|
InvertedComparators,
|
|
11
|
-
LimitLiteral
|
|
12
|
-
|
|
6
|
+
LimitLiteral
|
|
7
|
+
} from "../string/reduce/shared.js"
|
|
8
|
+
import type {
|
|
9
|
+
BoundExpressionKind,
|
|
10
|
+
writeInvalidLimitMessage,
|
|
11
|
+
writeUnboundableMessage
|
|
13
12
|
} from "../string/shift/operator/bounds.js"
|
|
14
|
-
import type {
|
|
13
|
+
import type { inferAstBase } from "./semantic.js"
|
|
15
14
|
import type { astToString } from "./utils.js"
|
|
16
15
|
import type { validateAst } from "./validate.js"
|
|
17
16
|
|
|
@@ -24,34 +23,33 @@ export type validateRange<
|
|
|
24
23
|
> = l extends LimitLiteral
|
|
25
24
|
? validateBound<r, InvertedComparators[comparator], l, "left", $, args>
|
|
26
25
|
: l extends [infer leftAst, Comparator, unknown]
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>>
|
|
27
|
+
: validateBound<l, comparator, r & LimitLiteral, "right", $, args>
|
|
29
28
|
|
|
30
29
|
export type validateBound<
|
|
31
30
|
boundedAst,
|
|
32
31
|
comparator extends Comparator,
|
|
33
32
|
limit extends LimitLiteral,
|
|
34
|
-
boundKind extends
|
|
33
|
+
boundKind extends BoundExpressionKind,
|
|
35
34
|
$,
|
|
36
35
|
args
|
|
37
|
-
> =
|
|
36
|
+
> = inferAstBase<boundedAst, $, args> extends infer bounded
|
|
38
37
|
? [bounded] extends [NumericallyBoundable]
|
|
39
38
|
? limit extends number
|
|
40
39
|
? validateAst<boundedAst, $, args>
|
|
41
40
|
: ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>>
|
|
42
41
|
: bounded extends Date
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: boundedAst
|
|
52
|
-
>
|
|
42
|
+
? // allow numeric or date literal as a Date limit
|
|
43
|
+
validateAst<boundedAst, $, args>
|
|
44
|
+
: ErrorMessage<
|
|
45
|
+
writeUnboundableMessage<
|
|
46
|
+
astToString<
|
|
47
|
+
boundKind extends "left"
|
|
48
|
+
? boundedAst[0 & keyof boundedAst]
|
|
49
|
+
: boundedAst
|
|
53
50
|
>
|
|
54
|
-
|
|
51
|
+
>
|
|
52
|
+
>
|
|
55
53
|
: never
|
|
56
54
|
|
|
57
55
|
export const writeDoubleRightBoundMessage = <root extends string>(
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { writeIndivisibleMessage } from "@arktype/schema"
|
|
2
2
|
import type { ErrorMessage } from "@arktype/util"
|
|
3
|
-
import type {
|
|
3
|
+
import type { inferAstBase } from "./semantic.js"
|
|
4
4
|
import type { astToString } from "./utils.js"
|
|
5
5
|
import type { validateAst } from "./validate.js"
|
|
6
6
|
|
|
7
7
|
export type validateDivisor<l, $, args> = isDivisible<
|
|
8
|
-
|
|
8
|
+
inferAstBase<l, $, args>
|
|
9
9
|
> extends true
|
|
10
10
|
? validateAst<l, $, args>
|
|
11
11
|
: ErrorMessage<writeIndivisibleMessage<astToString<l>>>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Out } from "@arktype/schema"
|
|
1
|
+
import type { MorphAst, Out } from "@arktype/schema"
|
|
2
2
|
import {
|
|
3
3
|
Hkt,
|
|
4
4
|
type List,
|
|
@@ -7,27 +7,26 @@ import {
|
|
|
7
7
|
type intersectArrays,
|
|
8
8
|
type isAny
|
|
9
9
|
} from "@arktype/util"
|
|
10
|
-
import type { MorphAst } from "../tuple.js"
|
|
11
10
|
|
|
12
11
|
export type inferIntersection<l, r> = [l] extends [never]
|
|
13
12
|
? never
|
|
14
13
|
: [r] extends [never]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
? never
|
|
15
|
+
: [l & r] extends [never]
|
|
16
|
+
? never
|
|
17
|
+
: isAny<l | r> extends true
|
|
18
|
+
? any
|
|
19
|
+
: l extends MorphAst<infer lIn, infer lOut>
|
|
20
|
+
? r extends MorphAst
|
|
21
|
+
? never
|
|
22
|
+
: (In: evaluate<lIn & r>) => Out<lOut>
|
|
23
|
+
: r extends MorphAst<infer rIn, infer rOut>
|
|
24
|
+
? (In: evaluate<rIn & l>) => Out<rOut>
|
|
25
|
+
: [l, r] extends [object, object]
|
|
26
|
+
? intersectObjects<l, r> extends infer result
|
|
27
|
+
? result
|
|
28
|
+
: never
|
|
29
|
+
: l & r
|
|
31
30
|
|
|
32
31
|
declare class MorphableIntersection extends Hkt.Kind {
|
|
33
32
|
f: (
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DateLiteral,
|
|
3
|
+
Refinements,
|
|
4
|
+
RegexLiteral,
|
|
5
|
+
distill,
|
|
6
|
+
is
|
|
7
|
+
} from "@arktype/schema"
|
|
8
|
+
import type {
|
|
9
|
+
BigintLiteral,
|
|
10
|
+
List,
|
|
11
|
+
NumberLiteral,
|
|
12
|
+
evaluate,
|
|
13
|
+
extend
|
|
14
|
+
} from "@arktype/util"
|
|
2
15
|
import type {
|
|
3
16
|
UnparsedScope,
|
|
4
17
|
resolve,
|
|
@@ -6,17 +19,26 @@ import type {
|
|
|
6
19
|
} from "../../scope.js"
|
|
7
20
|
import type { GenericProps } from "../../type.js"
|
|
8
21
|
import type { inferDefinition } from "../definition.js"
|
|
9
|
-
import type { DateLiteral } from "../string/shift/operand/date.js"
|
|
10
|
-
import type { StringLiteral } from "../string/shift/operand/enclosed.js"
|
|
11
22
|
import type {
|
|
12
23
|
Comparator,
|
|
24
|
+
InvertedComparators,
|
|
13
25
|
LimitLiteral
|
|
14
|
-
} from "../string/
|
|
26
|
+
} from "../string/reduce/shared.js"
|
|
27
|
+
import type { StringLiteral } from "../string/shift/operand/enclosed.js"
|
|
15
28
|
import type { inferIntersection } from "./intersections.js"
|
|
16
29
|
|
|
17
|
-
export type
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
export type inferAstRoot<ast, $, args> = inferAst<ast, $, args, {}>
|
|
31
|
+
|
|
32
|
+
export type inferAstBase<ast, $, args> = distill<inferAstRoot<ast, $, args>>
|
|
33
|
+
|
|
34
|
+
export type inferAst<
|
|
35
|
+
ast,
|
|
36
|
+
$,
|
|
37
|
+
args,
|
|
38
|
+
refinements extends Refinements
|
|
39
|
+
> = ast extends List
|
|
40
|
+
? inferExpression<ast, $, args, refinements>
|
|
41
|
+
: inferTerminal<ast, $, args, refinements>
|
|
20
42
|
|
|
21
43
|
export type GenericInstantiationAst<
|
|
22
44
|
g extends GenericProps = GenericProps,
|
|
@@ -26,7 +48,8 @@ export type GenericInstantiationAst<
|
|
|
26
48
|
export type inferExpression<
|
|
27
49
|
ast extends List,
|
|
28
50
|
$,
|
|
29
|
-
args
|
|
51
|
+
args,
|
|
52
|
+
refinements extends Refinements
|
|
30
53
|
> = ast extends GenericInstantiationAst
|
|
31
54
|
? inferDefinition<
|
|
32
55
|
ast[0]["definition"],
|
|
@@ -43,28 +66,36 @@ export type inferExpression<
|
|
|
43
66
|
`${number}` as ast[0]["parameters"][i]]: inferAst<
|
|
44
67
|
ast[2][i & keyof ast[2]],
|
|
45
68
|
$,
|
|
46
|
-
args
|
|
69
|
+
args,
|
|
70
|
+
refinements
|
|
47
71
|
>
|
|
48
72
|
}
|
|
49
73
|
>
|
|
50
74
|
: ast[1] extends "[]"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
? inferAst<ast[0], $, args, refinements>[]
|
|
76
|
+
: ast[1] extends "|"
|
|
77
|
+
?
|
|
78
|
+
| inferAst<ast[0], $, args, refinements>
|
|
79
|
+
| inferAst<ast[2], $, args, refinements>
|
|
80
|
+
: ast[1] extends "&"
|
|
81
|
+
? inferIntersection<
|
|
82
|
+
inferAst<ast[0], $, args, refinements>,
|
|
83
|
+
inferAst<ast[2], $, args, refinements>
|
|
84
|
+
>
|
|
85
|
+
: ast[1] extends Comparator
|
|
86
|
+
? ast[0] extends LimitLiteral
|
|
87
|
+
? inferAst<
|
|
88
|
+
ast[2],
|
|
89
|
+
$,
|
|
90
|
+
args,
|
|
91
|
+
refinements & { [_ in InvertedComparators[ast[1]]]: ast[0] }
|
|
92
|
+
>
|
|
93
|
+
: inferAst<ast[0], $, args, refinements & { [_ in ast[1]]: ast[2] }>
|
|
94
|
+
: ast[1] extends "%"
|
|
95
|
+
? inferAst<ast[0], $, args, refinements & { [k in `%${ast[2] & string}`]: 0 }>
|
|
96
|
+
: ast[0] extends "keyof"
|
|
97
|
+
? keyof inferAst<ast[1], $, args, refinements>
|
|
98
|
+
: never
|
|
68
99
|
|
|
69
100
|
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node"
|
|
70
101
|
|
|
@@ -88,20 +119,26 @@ export type InfixExpression<
|
|
|
88
119
|
r = unknown
|
|
89
120
|
> = [l, operator, r]
|
|
90
121
|
|
|
91
|
-
export type
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
export type inferTerminal<
|
|
123
|
+
token,
|
|
124
|
+
$,
|
|
125
|
+
args,
|
|
126
|
+
refinements extends Refinements
|
|
127
|
+
> = token extends keyof args | keyof $
|
|
128
|
+
? {} extends refinements
|
|
129
|
+
? resolve<token, $, args>
|
|
130
|
+
: is<resolve<token, $, args>, evaluate<refinements>>
|
|
131
|
+
: token extends StringLiteral<infer text>
|
|
132
|
+
? text
|
|
133
|
+
: token extends RegexLiteral
|
|
134
|
+
? is<string, extend<refinements, { [_ in token]: true }>>
|
|
135
|
+
: token extends DateLiteral
|
|
136
|
+
? is<Date, extend<refinements, { [_ in token]: true }>>
|
|
137
|
+
: token extends NumberLiteral<infer value>
|
|
138
|
+
? value
|
|
139
|
+
: token extends BigintLiteral<infer value>
|
|
140
|
+
? value
|
|
141
|
+
: // TODO: refinements
|
|
142
|
+
// doing this last allows us to infer never if it isn't valid rather than check
|
|
143
|
+
// if it's a valid submodule reference ahead of time
|
|
144
|
+
tryInferSubmoduleReference<$, token>
|
package/parser/semantic/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { List, Stringifiable } from "@arktype/util"
|
|
2
|
-
import type { Comparator } from "../string/
|
|
2
|
+
import type { Comparator } from "../string/reduce/shared.js"
|
|
3
3
|
import type { InfixExpression, PostfixExpression } from "./semantic.js"
|
|
4
4
|
|
|
5
5
|
export type astToString<ast> = `'${astToStringRecurse<ast>}'`
|
|
@@ -12,12 +12,12 @@ type astToStringRecurse<ast> = ast extends PostfixExpression<
|
|
|
12
12
|
? `${groupAst<operand>}[]`
|
|
13
13
|
: never
|
|
14
14
|
: ast extends InfixExpression<infer operator, infer l, infer r>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
? operator extends "&" | "|" | "%" | Comparator
|
|
16
|
+
? `${groupAst<l>}${operator}${groupAst<r>}`
|
|
17
|
+
: never
|
|
18
|
+
: ast extends Stringifiable
|
|
19
|
+
? `${ast extends bigint ? `${ast}n` : ast}`
|
|
20
|
+
: "..."
|
|
21
21
|
|
|
22
22
|
type groupAst<ast> = ast extends List
|
|
23
23
|
? ast[1] extends "[]"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Refinements } from "@arktype/schema"
|
|
1
2
|
import type {
|
|
2
3
|
BigintLiteral,
|
|
3
4
|
Completion,
|
|
@@ -7,9 +8,9 @@ import type {
|
|
|
7
8
|
} from "@arktype/util"
|
|
8
9
|
import type { Module } from "../../scope.js"
|
|
9
10
|
import type { GenericProps } from "../../type.js"
|
|
10
|
-
import type {
|
|
11
|
+
import type { Comparator } from "../string/reduce/shared.js"
|
|
12
|
+
import type { writeInvalidGenericArgsMessage } from "../string/shift/operand/genericArgs.js"
|
|
11
13
|
import type { writeMissingSubmoduleAccessMessage } from "../string/shift/operand/unenclosed.js"
|
|
12
|
-
import type { Comparator } from "../string/shift/operator/bounds.js"
|
|
13
14
|
import type { parseString } from "../string/string.js"
|
|
14
15
|
import type { validateRange } from "./bounds.js"
|
|
15
16
|
import type { validateDivisor } from "./divisor.js"
|
|
@@ -23,22 +24,22 @@ import type { astToString } from "./utils.js"
|
|
|
23
24
|
export type validateAst<ast, $, args> = ast extends string
|
|
24
25
|
? validateStringAst<ast, $>
|
|
25
26
|
: ast extends PostfixExpression<infer operator, infer operand>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
? operator extends "[]"
|
|
28
|
+
? validateAst<operand, $, args>
|
|
29
|
+
: never
|
|
30
|
+
: ast extends InfixExpression<infer operator, infer l, infer r>
|
|
31
|
+
? operator extends "&" | "|"
|
|
32
|
+
? validateInfix<ast, $, args>
|
|
33
|
+
: operator extends Comparator
|
|
34
|
+
? validateRange<l, operator, r, $, args>
|
|
35
|
+
: operator extends "%"
|
|
36
|
+
? validateDivisor<l, $, args>
|
|
37
|
+
: undefined
|
|
38
|
+
: ast extends readonly ["keyof", infer operand]
|
|
39
|
+
? validateAst<operand, $, args>
|
|
40
|
+
: ast extends GenericInstantiationAst
|
|
41
|
+
? validateGenericArgs<ast["2"], $, args>
|
|
42
|
+
: ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>>
|
|
42
43
|
|
|
43
44
|
type writeUnexpectedExpressionMessage<expression extends string> =
|
|
44
45
|
`Unexpectedly failed to parse the expression resulting from ${expression}`
|
|
@@ -67,22 +68,25 @@ type validateStringAst<def extends string, $> = def extends NumberLiteral<
|
|
|
67
68
|
? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">>
|
|
68
69
|
: undefined
|
|
69
70
|
: def extends BigintLiteral<infer value>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
? bigint extends value
|
|
72
|
+
? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">>
|
|
73
|
+
: undefined
|
|
74
|
+
: def extends keyof $
|
|
75
|
+
? $[def] extends null
|
|
76
|
+
? // handle any/never
|
|
77
|
+
def
|
|
78
|
+
: // these problems would've been caught during a fullStringParse, but it's most
|
|
79
|
+
// efficient to check for them here in case the string was naively parsed
|
|
80
|
+
$[def] extends GenericProps
|
|
81
|
+
? ErrorMessage<
|
|
82
|
+
writeInvalidGenericArgsMessage<def, $[def]["parameters"], []>
|
|
83
|
+
>
|
|
84
|
+
: $[def] extends Module
|
|
85
|
+
? ErrorMessage<writeMissingSubmoduleAccessMessage<def>>
|
|
86
|
+
: undefined
|
|
87
|
+
: def extends ErrorMessage
|
|
88
|
+
? def
|
|
89
|
+
: undefined
|
|
86
90
|
|
|
87
91
|
export type validateString<def extends string, $, args> = validateAst<
|
|
88
92
|
parseString<def, $, args>,
|
|
@@ -101,5 +105,5 @@ type validateInfix<ast extends InfixExpression, $, args> = validateAst<
|
|
|
101
105
|
> extends ErrorMessage<infer message>
|
|
102
106
|
? ErrorMessage<message>
|
|
103
107
|
: validateAst<ast[2], $, args> extends ErrorMessage<infer message>
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
? ErrorMessage<message>
|
|
109
|
+
: undefined
|
package/parser/shared.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type EntryParseResult<kind extends ParsedKeyKind = ParsedKeyKind> =
|
|
|
26
26
|
|
|
27
27
|
type ParsedValueKind = "required" | "optional"
|
|
28
28
|
|
|
29
|
-
type ParsedKeyKind = "required" | "optional" | "indexed"
|
|
29
|
+
type ParsedKeyKind = "required" | "optional" | "indexed" | "spread"
|
|
30
30
|
|
|
31
31
|
type parsedEntry<result extends EntryParseResult> = result
|
|
32
32
|
|
|
@@ -73,12 +73,19 @@ const getInnerValue = (value: unknown): ValueParseResult => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
// these methods are also used in tuple parsing, however the keys of a tuple will always be 0, 1,
|
|
77
|
+
// 2, etc and never be `...`, meaning `"spread"` as a kind will never occur in tuples
|
|
78
|
+
|
|
76
79
|
export const parseEntry = ([key, value]: DefinitionEntry): EntryParseResult => {
|
|
77
80
|
const keyParseResult: KeyParseResult =
|
|
78
81
|
typeof key === "string" && key.at(-1) === "?"
|
|
79
82
|
? key.at(-2) === Scanner.escapeToken
|
|
80
83
|
? { innerKey: `${key.slice(0, -2)}?`, kind: "required" }
|
|
81
84
|
: { innerKey: key.slice(0, -1), kind: "optional" }
|
|
85
|
+
: key === "..."
|
|
86
|
+
? { innerKey: "...", kind: "spread" }
|
|
87
|
+
: key === "\\..."
|
|
88
|
+
? { innerKey: "...", kind: "required" }
|
|
82
89
|
: { innerKey: key, kind: "required" }
|
|
83
90
|
const valueParseResult = getInnerValue(value)
|
|
84
91
|
return {
|
|
@@ -88,8 +95,8 @@ export const parseEntry = ([key, value]: DefinitionEntry): EntryParseResult => {
|
|
|
88
95
|
keyParseResult.kind === "indexed"
|
|
89
96
|
? "indexed"
|
|
90
97
|
: valueParseResult.kind === "optional"
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
? "optional"
|
|
99
|
+
: keyParseResult.kind
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
|
|
@@ -124,18 +131,22 @@ type parseKey<k> = k extends OptionalStringDefinition<infer inner>
|
|
|
124
131
|
kind: "optional"
|
|
125
132
|
innerKey: inner
|
|
126
133
|
}>
|
|
134
|
+
: k extends "..."
|
|
135
|
+
? parsedKey<{ kind: "spread"; innerKey: "..." }>
|
|
136
|
+
: k extends "\\..."
|
|
137
|
+
? parsedKey<{ kind: "required"; innerKey: "..." }>
|
|
127
138
|
: k extends IndexedKey<infer def>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
? parsedKey<{
|
|
140
|
+
kind: "indexed"
|
|
141
|
+
innerKey: def
|
|
142
|
+
}>
|
|
143
|
+
: k extends `${Scanner.EscapeToken}${infer escapedIndexKey extends
|
|
144
|
+
IndexedKey}`
|
|
145
|
+
? parsedKey<{
|
|
146
|
+
kind: "required"
|
|
147
|
+
innerKey: escapedIndexKey
|
|
148
|
+
}>
|
|
149
|
+
: parsedKey<{
|
|
150
|
+
kind: "required"
|
|
151
|
+
innerKey: k & (string | symbol)
|
|
152
|
+
}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TypeNode } from "@arktype/schema"
|
|
2
2
|
import {
|
|
3
3
|
isKeyOf,
|
|
4
4
|
throwInternalError,
|
|
@@ -6,19 +6,20 @@ import {
|
|
|
6
6
|
type requireKeys
|
|
7
7
|
} from "@arktype/util"
|
|
8
8
|
import type { ParseContext } from "../../../scope.js"
|
|
9
|
+
import { parseOperand } from "../shift/operand/operand.js"
|
|
10
|
+
import { parseOperator } from "../shift/operator/operator.js"
|
|
11
|
+
import { Scanner } from "../shift/scanner.js"
|
|
12
|
+
import { parseUntilFinalizer } from "../string.js"
|
|
9
13
|
import {
|
|
10
14
|
invertedComparators,
|
|
11
15
|
minComparators,
|
|
12
|
-
type Comparator,
|
|
13
|
-
type LimitLiteral
|
|
14
|
-
} from "../shift/operator/bounds.js"
|
|
15
|
-
import { Scanner } from "../shift/scanner.js"
|
|
16
|
-
import {
|
|
17
16
|
writeMultipleLeftBoundsMessage,
|
|
18
17
|
writeOpenRangeMessage,
|
|
19
18
|
writeUnclosedGroupMessage,
|
|
20
19
|
writeUnmatchedGroupCloseMessage,
|
|
21
20
|
writeUnpairableComparatorMessage,
|
|
21
|
+
type Comparator,
|
|
22
|
+
type LimitLiteral,
|
|
22
23
|
type OpenLeftBound,
|
|
23
24
|
type StringifiablePrefixOperator
|
|
24
25
|
} from "./shared.js"
|
|
@@ -26,15 +27,15 @@ import {
|
|
|
26
27
|
type BranchState = {
|
|
27
28
|
prefixes: StringifiablePrefixOperator[]
|
|
28
29
|
leftBound?: OpenLeftBound
|
|
29
|
-
"&"?:
|
|
30
|
-
"|"?:
|
|
30
|
+
"&"?: TypeNode
|
|
31
|
+
"|"?: TypeNode
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">
|
|
34
35
|
|
|
35
36
|
export class DynamicState {
|
|
36
37
|
readonly scanner: Scanner
|
|
37
|
-
root:
|
|
38
|
+
root: TypeNode | undefined
|
|
38
39
|
branches: BranchState = {
|
|
39
40
|
prefixes: []
|
|
40
41
|
}
|
|
@@ -62,11 +63,11 @@ export class DynamicState {
|
|
|
62
63
|
return value
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
constrainRoot(...args: Parameters<
|
|
66
|
+
constrainRoot(...args: Parameters<TypeNode["constrain"]>) {
|
|
66
67
|
this.root = this.root!.constrain(...args)
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
setRoot(root:
|
|
70
|
+
setRoot(root: TypeNode) {
|
|
70
71
|
this.root = root
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -148,6 +149,20 @@ export class DynamicState {
|
|
|
148
149
|
this.root = undefined
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
parseUntilFinalizer() {
|
|
153
|
+
return parseUntilFinalizer(
|
|
154
|
+
new DynamicState(this.scanner.unscanned, this.ctx)
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
parseOperator(this: DynamicStateWithRoot) {
|
|
159
|
+
return parseOperator(this)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
parseOperand() {
|
|
163
|
+
return parseOperand(this)
|
|
164
|
+
}
|
|
165
|
+
|
|
151
166
|
private assertRangeUnset() {
|
|
152
167
|
if (this.branches.leftBound) {
|
|
153
168
|
return this.error(
|
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
invertedComparators,
|
|
3
|
-
type Comparator,
|
|
4
|
-
type InvertedComparators,
|
|
5
|
-
type LimitLiteral,
|
|
6
|
-
type MinComparator
|
|
7
|
-
} from "../shift/operator/bounds.js"
|
|
1
|
+
import type { DateLiteral } from "@arktype/schema"
|
|
8
2
|
|
|
9
3
|
export type StringifiablePrefixOperator = "keyof"
|
|
10
4
|
|
|
5
|
+
export const minComparators = {
|
|
6
|
+
">": true,
|
|
7
|
+
">=": true
|
|
8
|
+
} as const
|
|
9
|
+
|
|
10
|
+
export type MinComparator = keyof typeof minComparators
|
|
11
|
+
|
|
12
|
+
export const maxComparators = {
|
|
13
|
+
"<": true,
|
|
14
|
+
"<=": true
|
|
15
|
+
} as const
|
|
16
|
+
|
|
17
|
+
export type MaxComparator = keyof typeof maxComparators
|
|
18
|
+
|
|
19
|
+
export const comparators = {
|
|
20
|
+
...minComparators,
|
|
21
|
+
...maxComparators,
|
|
22
|
+
"==": true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type Comparator = keyof typeof comparators
|
|
26
|
+
|
|
27
|
+
export const invertedComparators = {
|
|
28
|
+
"<": ">",
|
|
29
|
+
">": "<",
|
|
30
|
+
"<=": ">=",
|
|
31
|
+
">=": "<=",
|
|
32
|
+
"==": "=="
|
|
33
|
+
} as const satisfies Record<Comparator, Comparator>
|
|
34
|
+
|
|
35
|
+
export type InvertedComparators = typeof invertedComparators
|
|
36
|
+
|
|
37
|
+
export type LimitLiteral = number | DateLiteral
|
|
38
|
+
|
|
11
39
|
export type OpenLeftBound = { limit: LimitLiteral; comparator: MinComparator }
|
|
12
40
|
|
|
13
41
|
export const writeUnmatchedGroupCloseMessage = <unscanned extends string>(
|