arktype 2.0.0-dev.2 → 2.0.0-dev.21
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/LICENSE +7 -0
- package/out/api.d.ts +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/match.d.ts +18 -24
- package/out/match.js +50 -60
- package/out/module.d.ts +11 -0
- package/out/module.js +2 -0
- package/out/parser/definition.d.ts +13 -15
- package/out/parser/definition.js +10 -13
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/objectLiteral.d.ts +57 -18
- package/out/parser/objectLiteral.js +93 -52
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +16 -13
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/shared.d.ts +14 -28
- package/out/parser/string/reduce/shared.js +4 -3
- package/out/parser/string/reduce/static.d.ts +26 -23
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/string/shift/operand/enclosed.js +14 -14
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +9 -13
- package/out/parser/string/shift/operand/unenclosed.d.ts +15 -20
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +45 -56
- package/out/parser/string/shift/operator/divisor.d.ts +1 -3
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/operator.d.ts +1 -2
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/scanner.d.ts +8 -7
- package/out/parser/string/shift/scanner.js +17 -16
- package/out/parser/string/string.d.ts +9 -7
- package/out/parser/string/string.js +1 -3
- package/out/parser/tuple.d.ts +101 -42
- package/out/parser/tuple.js +107 -86
- package/out/scope.d.ts +44 -115
- package/out/scope.js +39 -188
- package/out/type.d.ts +63 -61
- package/out/type.js +30 -135
- package/package.json +33 -39
- package/__tests__/array.test.ts +0 -310
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/badDefinitionType.test.ts +0 -51
- package/__tests__/basis.test.ts +0 -46
- package/__tests__/bounds.test.ts +0 -388
- package/__tests__/cast.test.ts +0 -32
- package/__tests__/completions.test.ts +0 -46
- package/__tests__/config.test.ts +0 -77
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/dateLiteral.test.ts +0 -32
- package/__tests__/declared.test.ts +0 -124
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -90
- package/__tests__/enclosed.test.ts +0 -93
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -138
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -294
- package/__tests__/group.test.ts +0 -72
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -113
- package/__tests__/instanceof.test.ts +0 -102
- package/__tests__/intersection.test.ts +0 -104
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/keyTraversal.test.ts +0 -74
- package/__tests__/keyof.test.ts +0 -134
- package/__tests__/keywords.test.ts +0 -188
- package/__tests__/literal.test.ts +0 -51
- package/__tests__/match.bench.ts +0 -31
- package/__tests__/match.test.ts +0 -224
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/narrow.test.ts +0 -102
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -301
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/regex.test.ts +0 -58
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -140
- package/__tests__/string.test.ts +0 -48
- package/__tests__/submodule.test.ts +0 -99
- package/__tests__/this.test.ts +0 -57
- package/__tests__/thunk.test.ts +0 -80
- package/__tests__/traverse.test.ts +0 -119
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/typeMethods.test.ts +0 -69
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -120
- package/__tests__/union.test.ts +0 -147
- package/ark.ts +0 -91
- package/main.ts +0 -18
- package/match.ts +0 -243
- package/out/ark.d.ts.map +0 -1
- package/out/ark.js.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts +0 -7
- package/out/main.d.ts.map +0 -1
- package/out/main.js +0 -4
- package/out/main.js.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/match.js.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/shared.d.ts +0 -56
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -55
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/type.js.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/definition.ts +0 -159
- package/parser/generic.ts +0 -68
- package/parser/objectLiteral.ts +0 -197
- package/parser/semantic/bounds.ts +0 -61
- package/parser/semantic/divisor.ts +0 -13
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -143
- package/parser/semantic/utils.ts +0 -26
- package/parser/semantic/validate.ts +0 -109
- package/parser/shared.ts +0 -167
- package/parser/string/reduce/dynamic.ts +0 -196
- package/parser/string/reduce/shared.ts +0 -101
- package/parser/string/reduce/static.ts +0 -298
- package/parser/string/shift/operand/date.ts +0 -54
- package/parser/string/shift/operand/enclosed.ts +0 -118
- package/parser/string/shift/operand/genericArgs.ts +0 -127
- package/parser/string/shift/operand/operand.ts +0 -48
- package/parser/string/shift/operand/unenclosed.ts +0 -268
- package/parser/string/shift/operator/bounds.ts +0 -264
- package/parser/string/shift/operator/divisor.ts +0 -36
- package/parser/string/shift/operator/operator.ts +0 -82
- package/parser/string/shift/scanner.ts +0 -209
- package/parser/string/string.ts +0 -90
- package/parser/tuple.ts +0 -475
- package/scope.ts +0 -548
- package/type.ts +0 -349
- package/util.ts +0 -36
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { bench } from "@arktype/attest"
|
|
2
|
-
import { type } from "arktype"
|
|
3
|
-
|
|
4
|
-
bench("array-string", () => {
|
|
5
|
-
const _ = type("number[]")
|
|
6
|
-
})
|
|
7
|
-
.median([3.18, "us"])
|
|
8
|
-
.types([99, "instantiations"])
|
|
9
|
-
|
|
10
|
-
bench("array-tuple", () => {
|
|
11
|
-
const _ = type(["number", "[]"])
|
|
12
|
-
})
|
|
13
|
-
.median([3.47, "us"])
|
|
14
|
-
.types([212, "instantiations"])
|
|
15
|
-
|
|
16
|
-
bench("array-chain", () => {
|
|
17
|
-
const _ = type("number").array()
|
|
18
|
-
})
|
|
19
|
-
.median([5.15, "us"])
|
|
20
|
-
.types([5, "instantiations"])
|
|
21
|
-
|
|
22
|
-
bench("union-string", () => {
|
|
23
|
-
const _ = type("number|string")
|
|
24
|
-
})
|
|
25
|
-
.median([7.07, "us"])
|
|
26
|
-
.types([777, "instantiations"])
|
|
27
|
-
|
|
28
|
-
bench("union-tuple", () => {
|
|
29
|
-
const _ = type(["number", "|", "string"])
|
|
30
|
-
})
|
|
31
|
-
.median([5.59, "us"])
|
|
32
|
-
.types([273, "instantiations"])
|
|
33
|
-
|
|
34
|
-
bench("union-chain", () => {
|
|
35
|
-
const _ = type("number").or("string")
|
|
36
|
-
})
|
|
37
|
-
.median([7.09, "us"])
|
|
38
|
-
.types([488, "instantiations"])
|
|
39
|
-
|
|
40
|
-
bench("union-10-ary", () => {
|
|
41
|
-
const _ = type("0|1|2|3|4|5|6|7|8|9")
|
|
42
|
-
})
|
|
43
|
-
.median([119.87, "us"])
|
|
44
|
-
.types([4841, "instantiations"])
|
|
45
|
-
|
|
46
|
-
bench("intersection-string", () => {
|
|
47
|
-
const _ = type("number&0")
|
|
48
|
-
})
|
|
49
|
-
.median([3.61, "us"])
|
|
50
|
-
.types([686, "instantiations"])
|
|
51
|
-
|
|
52
|
-
bench("intersection-tuple", () => {
|
|
53
|
-
const _ = type(["number", "&", "0"])
|
|
54
|
-
})
|
|
55
|
-
.median([3.16, "us"])
|
|
56
|
-
.types([474, "instantiations"])
|
|
57
|
-
|
|
58
|
-
bench("intersection-chain", () => {
|
|
59
|
-
const _ = type("number").and("0")
|
|
60
|
-
})
|
|
61
|
-
.median([4.78, "us"])
|
|
62
|
-
.types([687, "instantiations"])
|
|
63
|
-
|
|
64
|
-
bench("intersection-10-ary", () => {
|
|
65
|
-
const _ = type(
|
|
66
|
-
"unknown&unknown&unknown&unknown&unknown&unknown&unknown&unknown&unknown&unknown"
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
.median([12.61, "us"])
|
|
70
|
-
.types([4351, "instantiations"])
|
|
71
|
-
|
|
72
|
-
bench("group-shallow", () => {
|
|
73
|
-
const _ = type("string|(number[])")
|
|
74
|
-
})
|
|
75
|
-
.median([9.58, "us"])
|
|
76
|
-
.types([1080, "instantiations"])
|
|
77
|
-
|
|
78
|
-
bench("group-nested", () => {
|
|
79
|
-
const _ = type("string|(number|(boolean))[][]")
|
|
80
|
-
})
|
|
81
|
-
.median([17.22, "us"])
|
|
82
|
-
.types([3008, "instantiations"])
|
|
83
|
-
|
|
84
|
-
bench("group-deep", () => {
|
|
85
|
-
const _ = type("(0|(1|(2|(3|(4|5)[])[])[])[])[]")
|
|
86
|
-
})
|
|
87
|
-
.median([32.5, "us"])
|
|
88
|
-
.types([37638, "instantiations"])
|
|
89
|
-
|
|
90
|
-
bench("bound-single", () => {
|
|
91
|
-
const _ = type("string>5")
|
|
92
|
-
})
|
|
93
|
-
.median([3.81, "us"])
|
|
94
|
-
.types([615, "instantiations"])
|
|
95
|
-
|
|
96
|
-
bench("bound-double", () => {
|
|
97
|
-
const _ = type("-7<=integer<99")
|
|
98
|
-
})
|
|
99
|
-
.median([7.2, "us"])
|
|
100
|
-
.types([1041, "instantiations"])
|
|
101
|
-
|
|
102
|
-
bench("divisor", () => {
|
|
103
|
-
const _ = type("number%5")
|
|
104
|
-
})
|
|
105
|
-
.median([4.53, "us"])
|
|
106
|
-
.types([1023, "instantiations"])
|
|
107
|
-
|
|
108
|
-
bench("filter-tuple", () => {
|
|
109
|
-
const _ = type(["boolean", ":", (b) => b])
|
|
110
|
-
})
|
|
111
|
-
.median([8.04, "us"])
|
|
112
|
-
.types([583, "instantiations"])
|
|
113
|
-
|
|
114
|
-
bench("filter-chain", () => {
|
|
115
|
-
const _ = type("boolean").narrow((b) => b)
|
|
116
|
-
})
|
|
117
|
-
.median([12.19, "us"])
|
|
118
|
-
.types([42, "instantiations"])
|
|
119
|
-
|
|
120
|
-
bench("morph-tuple", () => {
|
|
121
|
-
const _ = type(["boolean", "=>", (b) => b])
|
|
122
|
-
})
|
|
123
|
-
.median([8.96, "us"])
|
|
124
|
-
.types([562, "instantiations"])
|
|
125
|
-
|
|
126
|
-
bench("morph-chain", () => {
|
|
127
|
-
const _ = type("boolean").morph((b) => b)
|
|
128
|
-
})
|
|
129
|
-
.median([2.98, "us"])
|
|
130
|
-
.types([26, "instantiations"])
|
package/__tests__/regex.test.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { type } from "arktype"
|
|
3
|
-
|
|
4
|
-
describe("regex", () => {
|
|
5
|
-
describe("intersection", () => {
|
|
6
|
-
it("distinct strings", () => {
|
|
7
|
-
const t = type("/a/&/b/")
|
|
8
|
-
attest<string>(t.infer)
|
|
9
|
-
attest(t.allows("a")).equals(false)
|
|
10
|
-
attest(t.allows("b")).equals(false)
|
|
11
|
-
attest(t.allows("ab")).equals(true)
|
|
12
|
-
})
|
|
13
|
-
it("identical strings", () => {
|
|
14
|
-
const t = type("/a/&/a/")
|
|
15
|
-
attest(t.json).equals(type("/a/").json)
|
|
16
|
-
})
|
|
17
|
-
it("string and list", () => {
|
|
18
|
-
const expected = type("/a/&/b/&/c/").json
|
|
19
|
-
attest(type(["/a/", "&", "/b/&/c/"]).json).equals(expected)
|
|
20
|
-
attest(type(["/a/", "&", "/b/&/c/"]).json).equals(expected)
|
|
21
|
-
})
|
|
22
|
-
it("redundant string and list", () => {
|
|
23
|
-
const expected = type("/a/&/b/&/c/").json
|
|
24
|
-
attest(type(["/a/", "&", "/a/&/b/&/c/"]).json).equals(expected)
|
|
25
|
-
attest(type(["/a/&/b/&/c/", "&", "/c/"]).json).equals(expected)
|
|
26
|
-
})
|
|
27
|
-
it("distinct lists", () => {
|
|
28
|
-
const t = type(["/a/&/b/", "&", "/c/&/d/"])
|
|
29
|
-
attest(t.json).equals(type("/a/&/b/&/c/&/d/").json)
|
|
30
|
-
})
|
|
31
|
-
it("overlapping lists", () => {
|
|
32
|
-
const t = type(["/a/&/b/", "&", "/c/&/b/"])
|
|
33
|
-
attest(t.json).equals(type("/a/&/b/&/c/").json)
|
|
34
|
-
})
|
|
35
|
-
it("identical lists", () => {
|
|
36
|
-
const t = type(["/a/&/b/", "&", "/b/&/a/"])
|
|
37
|
-
attest(t.json).equals(type("/a/&/b/").json)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
describe("object literal", () => {
|
|
41
|
-
it("flagless", () => {
|
|
42
|
-
const t = type(/.*/)
|
|
43
|
-
attest<string>(t.infer)
|
|
44
|
-
attest(t.json).equals(type("/.*/").json)
|
|
45
|
-
})
|
|
46
|
-
it("single flag preserved", () => {
|
|
47
|
-
const t = type(/a/i)
|
|
48
|
-
// the flag should prevent it from reducing to the same regex
|
|
49
|
-
attest(t.json === type("/a/").json).equals(false)
|
|
50
|
-
attest(t.allows("A")).equals(true)
|
|
51
|
-
})
|
|
52
|
-
it("flag order doesn't matter", () => {
|
|
53
|
-
const a = type(/a/gi)
|
|
54
|
-
const b = type(new RegExp("a", "ig"))
|
|
55
|
-
attest(a.json).equals(b.json)
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
})
|
package/__tests__/scope.bench.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { bench } from "@arktype/attest"
|
|
2
|
-
import { scope, type Ark } from "arktype"
|
|
3
|
-
import { cyclic10, cyclic100, cyclic500 } from "./generated/cyclic.js"
|
|
4
|
-
|
|
5
|
-
// const recursive = scope({ dejaVu: { "dejaVu?": "dejaVu" } }).compile()
|
|
6
|
-
// const dejaVu: typeof recursive.dejaVu.infer = {}
|
|
7
|
-
// let i = 0
|
|
8
|
-
// let current = dejaVu
|
|
9
|
-
// while (i < 50) {
|
|
10
|
-
// current.dejaVu = { dejaVu: {} }
|
|
11
|
-
// current = current.dejaVu
|
|
12
|
-
// i++
|
|
13
|
-
// }
|
|
14
|
-
|
|
15
|
-
// bench("validate recursive", () => {
|
|
16
|
-
// recursive.dejaVu(dejaVu)
|
|
17
|
-
// }).median([11.21, "us"])
|
|
18
|
-
|
|
19
|
-
bench("cyclic 10 intersection", () => {
|
|
20
|
-
const s = scope(cyclic10).type("user&user2").infer
|
|
21
|
-
}).types([15964, "instantiations"])
|
|
22
|
-
|
|
23
|
-
bench("cyclic(10)", () => {
|
|
24
|
-
const types = scope(cyclic10).export()
|
|
25
|
-
})
|
|
26
|
-
// .median([47.02, "us"])
|
|
27
|
-
.types([3827, "instantiations"])
|
|
28
|
-
|
|
29
|
-
bench("cyclic(100)", () => {
|
|
30
|
-
const types = scope(cyclic100).export()
|
|
31
|
-
})
|
|
32
|
-
// .median([417.71, "us"])
|
|
33
|
-
.types([31106, "instantiations"])
|
|
34
|
-
|
|
35
|
-
bench("cyclic(500)", () => {
|
|
36
|
-
const types = scope(cyclic500).export()
|
|
37
|
-
})
|
|
38
|
-
// .median([2.62, "ms"])
|
|
39
|
-
.types([158351, "instantiations"])
|
package/__tests__/scope.test.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { scope, type } from "arktype"
|
|
3
|
-
import { writeUnresolvableMessage } from "../parser/string/shift/operand/unenclosed.js"
|
|
4
|
-
import { writeUnboundableMessage } from "../parser/string/shift/operator/bounds.js"
|
|
5
|
-
import { writeUnexpectedCharacterMessage } from "../parser/string/shift/operator/operator.js"
|
|
6
|
-
|
|
7
|
-
describe("scope", () => {
|
|
8
|
-
it("base definition", () => {
|
|
9
|
-
const types = scope({ a: "string" }).export()
|
|
10
|
-
attest<string>(types.a.infer)
|
|
11
|
-
attest(() =>
|
|
12
|
-
// @ts-expect-error
|
|
13
|
-
scope({ a: "strong" }).export()
|
|
14
|
-
).throwsAndHasTypeError(writeUnresolvableMessage("strong"))
|
|
15
|
-
})
|
|
16
|
-
it("type definition", () => {
|
|
17
|
-
const types = scope({ a: type("string") }).export()
|
|
18
|
-
attest<string>(types.a.infer)
|
|
19
|
-
attest(() =>
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
scope({ a: type("strong") })
|
|
22
|
-
).throwsAndHasTypeError(writeUnresolvableMessage("strong"))
|
|
23
|
-
})
|
|
24
|
-
it("interdependent", () => {
|
|
25
|
-
const types = scope({
|
|
26
|
-
a: "string>5",
|
|
27
|
-
b: "email<=10",
|
|
28
|
-
c: "a&b"
|
|
29
|
-
}).export()
|
|
30
|
-
attest<string>(types.c.infer)
|
|
31
|
-
})
|
|
32
|
-
it("object array", () => {
|
|
33
|
-
const types = scope({ a: "string", b: [{ c: "a" }] }).export()
|
|
34
|
-
attest<
|
|
35
|
-
[
|
|
36
|
-
{
|
|
37
|
-
c: string
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
>(types.b.infer)
|
|
41
|
-
})
|
|
42
|
-
it("doesn't try to validate any in scope", () => {
|
|
43
|
-
// const $ = scope({ a: {} as any })
|
|
44
|
-
// attest<{ a: never }>($.infer)
|
|
45
|
-
// attest<[number, never]>($.type(["number", "a"]).infer)
|
|
46
|
-
})
|
|
47
|
-
it("infers input and output", () => {
|
|
48
|
-
const $ = scope({
|
|
49
|
-
a: ["string", "=>", (s) => s.length]
|
|
50
|
-
})
|
|
51
|
-
attest<{ a: number }>($.infer)
|
|
52
|
-
// TODO: API?
|
|
53
|
-
// attest<{ a: string }>($.in.infer)
|
|
54
|
-
})
|
|
55
|
-
it("scope.scope", () => {
|
|
56
|
-
const $ = scope({
|
|
57
|
-
a: "string"
|
|
58
|
-
})
|
|
59
|
-
const importer = $.scope({ b: "a[]" })
|
|
60
|
-
attest<{ b: string[] }>(importer.infer)
|
|
61
|
-
const t = importer.type("b")
|
|
62
|
-
attest(t.json).is(type("string[]").json)
|
|
63
|
-
})
|
|
64
|
-
it("infers its own helpers", () => {
|
|
65
|
-
const $ = scope({
|
|
66
|
-
a: () => $.type("string"),
|
|
67
|
-
b: () => $.type("number")
|
|
68
|
-
})
|
|
69
|
-
const types = $.export()
|
|
70
|
-
attest<string>(types.a.infer)
|
|
71
|
-
attest<number>(types.b.infer)
|
|
72
|
-
})
|
|
73
|
-
it("allows semantically valid helpers", () => {
|
|
74
|
-
const $ = scope({
|
|
75
|
-
n: () => $.type("number"),
|
|
76
|
-
lessThan10: () => $.type("n<10")
|
|
77
|
-
})
|
|
78
|
-
const types = $.export()
|
|
79
|
-
attest<number>(types.n.infer)
|
|
80
|
-
attest<number>(types.lessThan10.infer)
|
|
81
|
-
})
|
|
82
|
-
it("errors on helper parse error", () => {
|
|
83
|
-
attest(() => {
|
|
84
|
-
const $ = scope({
|
|
85
|
-
// @ts-expect-error
|
|
86
|
-
a: () => $.type("kung|foo")
|
|
87
|
-
})
|
|
88
|
-
$.export()
|
|
89
|
-
}).throwsAndHasTypeError(writeUnresolvableMessage("kung"))
|
|
90
|
-
})
|
|
91
|
-
it("errors on semantically invalid helper", () => {
|
|
92
|
-
attest(() => {
|
|
93
|
-
const $ = scope({
|
|
94
|
-
b: () => $.type("boolean"),
|
|
95
|
-
// @ts-expect-error
|
|
96
|
-
lessThan10: () => $.type("b<10")
|
|
97
|
-
})
|
|
98
|
-
$.export()
|
|
99
|
-
}).throwsAndHasTypeError(writeUnboundableMessage("'b'"))
|
|
100
|
-
})
|
|
101
|
-
it("errors on ridiculous unexpected alias scenario", () => {
|
|
102
|
-
attest(() =>
|
|
103
|
-
scope({
|
|
104
|
-
Unexpected: {},
|
|
105
|
-
User: {
|
|
106
|
-
// Previously, using the alias `Unexpected` allowed creating
|
|
107
|
-
// this type string which matched its own error message.
|
|
108
|
-
// @ts-expect-error
|
|
109
|
-
name: "Unexpected character 'c'"
|
|
110
|
-
}
|
|
111
|
-
}).export()
|
|
112
|
-
).throwsAndHasTypeError(writeUnexpectedCharacterMessage("c"))
|
|
113
|
-
})
|
|
114
|
-
it("autocompletion", () => {
|
|
115
|
-
attest(() => {
|
|
116
|
-
scope({
|
|
117
|
-
foobar: "string",
|
|
118
|
-
// @ts-expect-error
|
|
119
|
-
baz: "fo"
|
|
120
|
-
}).export()
|
|
121
|
-
}).type.errors(`Type '"fo"' is not assignable to type '"foobar"'`)
|
|
122
|
-
})
|
|
123
|
-
it("cross-scope reference", () => {
|
|
124
|
-
const { Apple } = scope({
|
|
125
|
-
Apple: {
|
|
126
|
-
pear: "Pear"
|
|
127
|
-
},
|
|
128
|
-
Pear: {
|
|
129
|
-
tasty: "true"
|
|
130
|
-
}
|
|
131
|
-
}).export()
|
|
132
|
-
|
|
133
|
-
const { X } = scope({
|
|
134
|
-
X: Apple
|
|
135
|
-
}).export()
|
|
136
|
-
|
|
137
|
-
const { out: data } = X({ pear: { tasty: true } })
|
|
138
|
-
attest(data).snap({ pear: { tasty: true } })
|
|
139
|
-
})
|
|
140
|
-
})
|
package/__tests__/string.test.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { type } from "arktype"
|
|
3
|
-
import { writeUnterminatedEnclosedMessage } from "../parser/string/shift/operand/enclosed.js"
|
|
4
|
-
import {
|
|
5
|
-
writeExpressionExpectedMessage,
|
|
6
|
-
writeUnresolvableMessage
|
|
7
|
-
} from "../parser/string/shift/operand/unenclosed.js"
|
|
8
|
-
|
|
9
|
-
describe("string", () => {
|
|
10
|
-
it("errors on empty string", () => {
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
attest(() => type("")).throws(writeExpressionExpectedMessage(""))
|
|
13
|
-
})
|
|
14
|
-
it("ignores whitespace between identifiers/operators", () => {
|
|
15
|
-
const t = type(` \n string |
|
|
16
|
-
boolean [] `)
|
|
17
|
-
attest<string | boolean[]>(t.infer)
|
|
18
|
-
attest(t.json).equals(type("string|boolean[]").json)
|
|
19
|
-
})
|
|
20
|
-
it("errors on bad whitespace", () => {
|
|
21
|
-
attest(() =>
|
|
22
|
-
// @ts-expect-error
|
|
23
|
-
type("string | boo lean[]")
|
|
24
|
-
)
|
|
25
|
-
.throws(writeUnresolvableMessage("boo"))
|
|
26
|
-
.type.errors("string | boolean")
|
|
27
|
-
})
|
|
28
|
-
it("unterminated string", () => {
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
attest(() => type("'bob")).throwsAndHasTypeError(
|
|
31
|
-
writeUnterminatedEnclosedMessage("bob", "'")
|
|
32
|
-
)
|
|
33
|
-
})
|
|
34
|
-
it("shallow single autocomplete", () => {
|
|
35
|
-
// @ts-expect-error
|
|
36
|
-
attest(() => type("str")).type.errors(
|
|
37
|
-
`Argument of type '"str"' is not assignable to parameter of type '"string"'`
|
|
38
|
-
)
|
|
39
|
-
})
|
|
40
|
-
it("shallow multi autocomplete", () => {
|
|
41
|
-
// @ts-expect-error
|
|
42
|
-
attest(() => type("s")).type.errors(`"string" | "symbol" | "semver"`)
|
|
43
|
-
})
|
|
44
|
-
it("post-operator autocomplete", () => {
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
attest(() => type("string|num")).type.errors(`"string|number"`)
|
|
47
|
-
})
|
|
48
|
-
})
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { lazily } from "@arktype/util"
|
|
3
|
-
import { scope, type, type Ark, type Module, type Scope } from "arktype"
|
|
4
|
-
import {
|
|
5
|
-
writeMissingSubmoduleAccessMessage,
|
|
6
|
-
writeNonSubmoduleDotMessage,
|
|
7
|
-
writeUnresolvableMessage
|
|
8
|
-
} from "../parser/string/shift/operand/unenclosed.js"
|
|
9
|
-
|
|
10
|
-
const $ = lazily(() =>
|
|
11
|
-
scope({
|
|
12
|
-
a: "string",
|
|
13
|
-
b: "sub.alias",
|
|
14
|
-
sub: scope({ alias: "number" }).export()
|
|
15
|
-
})
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
describe("submodules", () => {
|
|
19
|
-
it("base", () => {
|
|
20
|
-
const types = $.export()
|
|
21
|
-
attest<
|
|
22
|
-
Module<{
|
|
23
|
-
exports: {
|
|
24
|
-
a: string
|
|
25
|
-
b: number
|
|
26
|
-
sub: Module<{
|
|
27
|
-
exports: {
|
|
28
|
-
alias: number
|
|
29
|
-
}
|
|
30
|
-
locals: {}
|
|
31
|
-
ambient: Ark
|
|
32
|
-
}>
|
|
33
|
-
}
|
|
34
|
-
locals: {}
|
|
35
|
-
ambient: Ark
|
|
36
|
-
}>
|
|
37
|
-
>(types)
|
|
38
|
-
|
|
39
|
-
attest<number>(types.sub.alias.infer)
|
|
40
|
-
const expected = type("number").json
|
|
41
|
-
attest(types.sub.alias.json).is(expected)
|
|
42
|
-
attest(types.b.json).is(expected)
|
|
43
|
-
})
|
|
44
|
-
it("non-submodule dot access", () => {
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
attest(() => $.type("b.foo")).throwsAndHasTypeError(
|
|
47
|
-
writeNonSubmoduleDotMessage("b")
|
|
48
|
-
)
|
|
49
|
-
})
|
|
50
|
-
it("thunk submodule", () => {
|
|
51
|
-
const $ = scope({
|
|
52
|
-
a: "string",
|
|
53
|
-
c: "a",
|
|
54
|
-
sub: () =>
|
|
55
|
-
$.scope({
|
|
56
|
-
foo: "a",
|
|
57
|
-
bar: "foo"
|
|
58
|
-
}).export()
|
|
59
|
-
})
|
|
60
|
-
attest<
|
|
61
|
-
Scope<{
|
|
62
|
-
exports: {
|
|
63
|
-
a: string
|
|
64
|
-
c: string
|
|
65
|
-
sub: Module<{
|
|
66
|
-
exports: {
|
|
67
|
-
foo: string
|
|
68
|
-
bar: string
|
|
69
|
-
}
|
|
70
|
-
locals: {}
|
|
71
|
-
ambient: Ark
|
|
72
|
-
}>
|
|
73
|
-
}
|
|
74
|
-
locals: {}
|
|
75
|
-
ambient: Ark
|
|
76
|
-
}>
|
|
77
|
-
>($)
|
|
78
|
-
})
|
|
79
|
-
it("no alias reference", () => {
|
|
80
|
-
// @ts-expect-error
|
|
81
|
-
attest(() => $.type("sub")).throwsAndHasTypeError(
|
|
82
|
-
writeMissingSubmoduleAccessMessage("sub")
|
|
83
|
-
)
|
|
84
|
-
})
|
|
85
|
-
it("bad alias reference", () => {
|
|
86
|
-
// @ts-expect-error
|
|
87
|
-
attest(() => $.type("sub.marine")).throwsAndHasTypeError(
|
|
88
|
-
writeUnresolvableMessage("sub.marine")
|
|
89
|
-
)
|
|
90
|
-
})
|
|
91
|
-
it("autocompletion", () => {
|
|
92
|
-
const base = scope({ foo: "true" })
|
|
93
|
-
// @ts-expect-error
|
|
94
|
-
attest(() => scope({ base, reference: "base." }).export())
|
|
95
|
-
.throws(writeUnresolvableMessage("base."))
|
|
96
|
-
.type.errors("base.foo")
|
|
97
|
-
})
|
|
98
|
-
// TODO: private aliases
|
|
99
|
-
})
|
package/__tests__/this.test.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { scope, type } from "arktype"
|
|
3
|
-
import { writeUnresolvableMessage } from "../parser/string/shift/operand/unenclosed.js"
|
|
4
|
-
|
|
5
|
-
describe("this reference", () => {
|
|
6
|
-
it("resolves from type", () => {
|
|
7
|
-
const disappointingGift = type({
|
|
8
|
-
label: "string",
|
|
9
|
-
"box?": "this"
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
type ExpectedDisappointingGift = {
|
|
13
|
-
label: string
|
|
14
|
-
box?: ExpectedDisappointingGift
|
|
15
|
-
}
|
|
16
|
-
attest<ExpectedDisappointingGift>(disappointingGift.infer)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it("doesn't change when rereferenced", () => {
|
|
20
|
-
const initial = type({
|
|
21
|
-
initial: "this"
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const reference = type({
|
|
25
|
-
reference: initial
|
|
26
|
-
})
|
|
27
|
-
type Initial = {
|
|
28
|
-
initial: Initial
|
|
29
|
-
}
|
|
30
|
-
type Expected = {
|
|
31
|
-
reference: Initial
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
attest<Expected>(reference.infer)
|
|
35
|
-
const types = scope({
|
|
36
|
-
initial: {
|
|
37
|
-
initial: "initial"
|
|
38
|
-
},
|
|
39
|
-
reference: {
|
|
40
|
-
reference: "initial"
|
|
41
|
-
}
|
|
42
|
-
}).export()
|
|
43
|
-
attest(reference.json).equals(types.reference.json)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it("unresolvable in scope", () => {
|
|
47
|
-
attest(() =>
|
|
48
|
-
scope({
|
|
49
|
-
disappointingGift: {
|
|
50
|
-
label: "string",
|
|
51
|
-
// @ts-expect-error
|
|
52
|
-
"box?": "this"
|
|
53
|
-
}
|
|
54
|
-
}).export()
|
|
55
|
-
).throwsAndHasTypeError(writeUnresolvableMessage("this"))
|
|
56
|
-
})
|
|
57
|
-
})
|
package/__tests__/thunk.test.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { scope, type } from "arktype"
|
|
3
|
-
import { writeBadDefinitionTypeMessage } from "../parser/definition.js"
|
|
4
|
-
import { writeUnresolvableMessage } from "../parser/string/shift/operand/unenclosed.js"
|
|
5
|
-
|
|
6
|
-
describe("thunk", () => {
|
|
7
|
-
it("thunk", () => {
|
|
8
|
-
const t = type(() => type("boolean"))
|
|
9
|
-
attest<boolean>(t.infer)
|
|
10
|
-
attest(() => {
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
type(() => type("moolean"))
|
|
13
|
-
}).throwsAndHasTypeError(writeUnresolvableMessage("moolean"))
|
|
14
|
-
})
|
|
15
|
-
it("thunks in scope", () => {
|
|
16
|
-
const $ = scope({
|
|
17
|
-
a: () => $.type({ b: "b" }),
|
|
18
|
-
b: () => $.type({ a: "string" })
|
|
19
|
-
})
|
|
20
|
-
attest<{
|
|
21
|
-
a: {
|
|
22
|
-
b: {
|
|
23
|
-
a: string
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
b: {
|
|
27
|
-
a: string
|
|
28
|
-
}
|
|
29
|
-
}>($.infer)
|
|
30
|
-
|
|
31
|
-
const types = $.export()
|
|
32
|
-
attest<{
|
|
33
|
-
b: {
|
|
34
|
-
a: string
|
|
35
|
-
}
|
|
36
|
-
}>(types.a.infer)
|
|
37
|
-
|
|
38
|
-
// attest(types.a.node).snap({ object: { props: { b: "b" } } })
|
|
39
|
-
attest<{ a: string }>(types.b.infer)
|
|
40
|
-
|
|
41
|
-
// attest(types.b.node).snap({
|
|
42
|
-
// object: { props: { a: { object: { props: { a: "string" } } } } }
|
|
43
|
-
// })
|
|
44
|
-
})
|
|
45
|
-
it("expression from thunk", () => {
|
|
46
|
-
const $ = scope({
|
|
47
|
-
a: () => $.type({ a: "string" }),
|
|
48
|
-
b: { b: "boolean" },
|
|
49
|
-
aAndB: () => $.type("a&b")
|
|
50
|
-
})
|
|
51
|
-
const types = $.export()
|
|
52
|
-
attest<{ a: string; b: boolean }>(types.aAndB.infer)
|
|
53
|
-
// attest(types.aAndB.node).snap({
|
|
54
|
-
// object: { props: { a: "string", b: "boolean" } }
|
|
55
|
-
// })
|
|
56
|
-
})
|
|
57
|
-
it("shallow thunk in type", () => {
|
|
58
|
-
const t = type(() => type("string"))
|
|
59
|
-
attest(t.json).equals(type("string").json)
|
|
60
|
-
attest<string>(t.infer)
|
|
61
|
-
})
|
|
62
|
-
it("deep thunk in type", () => {
|
|
63
|
-
const t = type({ a: () => type("string") })
|
|
64
|
-
attest(t.json).equals(type({ a: "string" }).json)
|
|
65
|
-
attest<{ a: string }>(t.infer)
|
|
66
|
-
})
|
|
67
|
-
it("non-type thunk in scope", () => {
|
|
68
|
-
const $ = scope({
|
|
69
|
-
a: () => 42
|
|
70
|
-
})
|
|
71
|
-
attest(() => $.export()).throws(writeBadDefinitionTypeMessage("number"))
|
|
72
|
-
})
|
|
73
|
-
it("parse error in thunk in scope", () => {
|
|
74
|
-
const $ = scope({
|
|
75
|
-
// @ts-expect-error
|
|
76
|
-
a: () => $.type("bad")
|
|
77
|
-
})
|
|
78
|
-
attest(() => $.export()).throws(writeUnresolvableMessage("bad"))
|
|
79
|
-
})
|
|
80
|
-
})
|