arktype 2.0.0-dev.1 → 2.0.0-dev.11
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/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/main.d.ts +6 -7
- package/out/main.js +4 -3
- package/out/match.d.ts +57 -34
- package/out/match.js +51 -17
- package/out/module.d.ts +12 -0
- package/out/module.js +3 -0
- package/out/parser/definition.d.ts +14 -14
- 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 +44 -18
- package/out/parser/objectLiteral.js +57 -51
- 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 +27 -24
- 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 +8 -12
- package/out/parser/string/shift/operand/unenclosed.d.ts +16 -21
- 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 +2 -2
- package/out/parser/string/shift/scanner.js +14 -16
- package/out/parser/string/string.d.ts +8 -6
- package/out/parser/string/string.js +1 -3
- package/out/parser/tuple.d.ts +102 -43
- package/out/parser/tuple.js +119 -87
- package/out/scope.d.ts +44 -119
- package/out/scope.js +39 -209
- package/out/type.d.ts +43 -64
- package/out/type.js +30 -131
- package/package.json +12 -10
- package/__tests__/array.test.ts +0 -272
- 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 -168
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/dateLiteral.test.ts +0 -32
- package/__tests__/declared.test.ts +0 -123
- 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 -73
- package/__tests__/keyof.test.ts +0 -134
- package/__tests__/keywords.test.ts +0 -188
- package/__tests__/literal.test.ts +0 -51
- package/__tests__/match.test.ts +0 -34
- 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 -300
- 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 -116
- 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.map +0 -1
- 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 -54
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -47
- 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 -144
- package/parser/semantic/utils.ts +0 -26
- package/parser/semantic/validate.ts +0 -109
- package/parser/shared.ts +0 -152
- 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 -474
- package/scope.ts +0 -574
- package/type.ts +0 -347
- package/util.ts +0 -36
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { bench } from "@arktype/attest"
|
|
2
|
-
import { type } from "arktype"
|
|
3
|
-
|
|
4
|
-
bench("dictionary", () => {
|
|
5
|
-
const dict = type({
|
|
6
|
-
a: "string[]",
|
|
7
|
-
b: "number[]",
|
|
8
|
-
c: { nested: "boolean[]" }
|
|
9
|
-
})
|
|
10
|
-
})
|
|
11
|
-
.median([20.83, "us"])
|
|
12
|
-
.types([1704, "instantiations"])
|
|
13
|
-
|
|
14
|
-
bench("dictionary with optional keys", () => {
|
|
15
|
-
const dict = type({
|
|
16
|
-
"a?": "string[]",
|
|
17
|
-
"b?": "number[]",
|
|
18
|
-
"c?": { "nested?": "boolean[]" }
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
.median([21.23, "us"])
|
|
22
|
-
.types([1704, "instantiations"])
|
|
23
|
-
|
|
24
|
-
bench("tuple", () => {
|
|
25
|
-
const tuple = type(["string[]", "number[]", ["boolean[]"]])
|
|
26
|
-
})
|
|
27
|
-
.median([28.6, "us"])
|
|
28
|
-
.types([2739, "instantiations"])
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { registry } from "@arktype/schema"
|
|
3
|
-
import { printable } from "@arktype/util"
|
|
4
|
-
import { scope, type } from "arktype"
|
|
5
|
-
import {
|
|
6
|
-
writeInvalidPropertyKeyMessage,
|
|
7
|
-
writeInvalidSpreadTypeMessage
|
|
8
|
-
} from "../parser/objectLiteral.js"
|
|
9
|
-
import { writeUnresolvableMessage } from "../parser/string/shift/operand/unenclosed.js"
|
|
10
|
-
import { writeUnboundableMessage } from "../parser/string/shift/operator/bounds.js"
|
|
11
|
-
|
|
12
|
-
describe("object literal", () => {
|
|
13
|
-
it("empty", () => {
|
|
14
|
-
const o = type({})
|
|
15
|
-
attest(o.json).equals(type("object").json)
|
|
16
|
-
})
|
|
17
|
-
it("required", () => {
|
|
18
|
-
const o = type({ a: "string", b: "number" })
|
|
19
|
-
attest<{ a: string; b: number }>(o.infer)
|
|
20
|
-
attest(o.json).snap({
|
|
21
|
-
basis: "object",
|
|
22
|
-
required: [
|
|
23
|
-
{ key: "a", value: "string" },
|
|
24
|
-
{ key: "b", value: "number" }
|
|
25
|
-
]
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
it("optional keys", () => {
|
|
29
|
-
const o = type({ "a?": "string", b: "number" })
|
|
30
|
-
attest<{ a?: string; b: number }>(o.infer)
|
|
31
|
-
attest(o.json).snap({
|
|
32
|
-
basis: "object",
|
|
33
|
-
optional: [{ key: "a", value: "string" }],
|
|
34
|
-
required: [{ key: "b", value: "number" }]
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
it("symbol key", () => {
|
|
38
|
-
const s = Symbol()
|
|
39
|
-
const name = registry.register(s)
|
|
40
|
-
const t = type({
|
|
41
|
-
[s]: "string"
|
|
42
|
-
})
|
|
43
|
-
attest<{ [s]: string }>(t.infer)
|
|
44
|
-
attest(t.json).equals({
|
|
45
|
-
basis: "object",
|
|
46
|
-
required: [{ key: name, value: "string" }]
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
it("optional symbol", () => {
|
|
50
|
-
const s = Symbol()
|
|
51
|
-
const name = registry.register(s)
|
|
52
|
-
const t = type({
|
|
53
|
-
[s]: "number?"
|
|
54
|
-
})
|
|
55
|
-
attest<{ [s]?: number }>(t.infer)
|
|
56
|
-
attest(t.json).equals({
|
|
57
|
-
basis: "object",
|
|
58
|
-
optional: [{ key: name, value: "number" }]
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
describe("spread syntax", () => {
|
|
62
|
-
it("within scope", () => {
|
|
63
|
-
const s = scope({
|
|
64
|
-
user: { isAdmin: "false", name: "string" },
|
|
65
|
-
admin: { "...": "user", isAdmin: "true" }
|
|
66
|
-
}).export()
|
|
67
|
-
|
|
68
|
-
attest<{ isAdmin: true; name: string }>(s.admin.infer)
|
|
69
|
-
attest(s.admin.json).equals({
|
|
70
|
-
basis: "object",
|
|
71
|
-
required: [
|
|
72
|
-
{ key: "isAdmin", value: { unit: true } },
|
|
73
|
-
{ key: "name", value: "string" }
|
|
74
|
-
]
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it("from another `type` call", () => {
|
|
79
|
-
const user = type({ isAdmin: "false", name: "string" })
|
|
80
|
-
const admin = type({ "...": user, isAdmin: "true" })
|
|
81
|
-
|
|
82
|
-
attest<{ isAdmin: true; name: string }>(admin.infer)
|
|
83
|
-
attest(admin.json).equals({
|
|
84
|
-
basis: "object",
|
|
85
|
-
required: [
|
|
86
|
-
{ key: "isAdmin", value: { unit: true } },
|
|
87
|
-
{ key: "name", value: "string" }
|
|
88
|
-
]
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it("from an object literal", () => {
|
|
93
|
-
// no idea why you'd want to do this
|
|
94
|
-
const t = type({
|
|
95
|
-
"...": {
|
|
96
|
-
inherited: "boolean",
|
|
97
|
-
overridden: "string"
|
|
98
|
-
},
|
|
99
|
-
overridden: "number"
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
attest<{
|
|
103
|
-
inherited: boolean
|
|
104
|
-
overridden: number
|
|
105
|
-
}>(t.infer)
|
|
106
|
-
|
|
107
|
-
attest(t.json).snap({
|
|
108
|
-
basis: "object",
|
|
109
|
-
required: [
|
|
110
|
-
{ key: "inherited", value: [{ unit: false }, { unit: true }] },
|
|
111
|
-
{ key: "overridden", value: "number" }
|
|
112
|
-
]
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it("escaped key", () => {
|
|
117
|
-
const t = type({
|
|
118
|
-
"\\...": "string"
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
attest<{ "...": string }>(t.infer)
|
|
122
|
-
|
|
123
|
-
attest(t.json).equals({
|
|
124
|
-
basis: "object",
|
|
125
|
-
required: [{ key: "...", value: "string" }]
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it("with non-object", () => {
|
|
130
|
-
// @ts-expect-error
|
|
131
|
-
attest(() => type({ "...": "string" })).throwsAndHasTypeError(
|
|
132
|
-
writeInvalidSpreadTypeMessage(printable("string"))
|
|
133
|
-
)
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
// this is a regression test to ensure nodes are handled even if they aren't just an object
|
|
137
|
-
it("with complex type", () => {
|
|
138
|
-
const adminUser = type({
|
|
139
|
-
"...": [{ name: "string" }, "&", { isAdmin: "false" }],
|
|
140
|
-
isAdmin: "true"
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
attest<{ isAdmin: true; name: string }>(adminUser.infer)
|
|
144
|
-
attest(adminUser.json).snap({
|
|
145
|
-
basis: "object",
|
|
146
|
-
required: [
|
|
147
|
-
{ key: "isAdmin", value: { unit: true } },
|
|
148
|
-
{ key: "name", value: "string" }
|
|
149
|
-
]
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
describe("optional keys and definition reduction", () => {
|
|
154
|
-
it("optional value", () => {
|
|
155
|
-
const t = type({ a: "string?" })
|
|
156
|
-
attest(t.json).equals(type({ "a?": "string" }).json)
|
|
157
|
-
})
|
|
158
|
-
it("optional key and value", () => {
|
|
159
|
-
const t = type({ "a?": "string?" })
|
|
160
|
-
attest(t.json).equals(type({ "a?": "string" }).json)
|
|
161
|
-
})
|
|
162
|
-
it("optional value as tuple", () => {
|
|
163
|
-
const t = type({ a: ["string", "?"] })
|
|
164
|
-
attest(t.json).equals(type({ "a?": "string" }).json)
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
it("error in obj that has tuple that writes error at proper path", () => {
|
|
168
|
-
// @ts-expect-error
|
|
169
|
-
attest(() => type({ "a?": ["string", "string?", ["stringx", "?"]] }))
|
|
170
|
-
.throws(writeUnresolvableMessage("stringx"))
|
|
171
|
-
.type.errors.snap(
|
|
172
|
-
"Type '\"stringx\"' is not assignable to type '\"'stringx' is unresolvable \"'."
|
|
173
|
-
)
|
|
174
|
-
})
|
|
175
|
-
it("index", () => {
|
|
176
|
-
const o = type({ "[string]": "string" })
|
|
177
|
-
attest<{ [x: string]: string }>(o.infer)
|
|
178
|
-
})
|
|
179
|
-
it("enumerable indexed union", () => {
|
|
180
|
-
const o = type({ "['foo' | 'bar']": "string" })
|
|
181
|
-
attest<{ foo: string; bar: string }>(o.infer)
|
|
182
|
-
})
|
|
183
|
-
it("non-enumerable indexed union", () => {
|
|
184
|
-
const o = type({ "[string | symbol]": "string" })
|
|
185
|
-
attest<{ [x: string]: string; [x: symbol]: string }>(o.infer)
|
|
186
|
-
})
|
|
187
|
-
it("multiple indexed", () => {
|
|
188
|
-
const o = type({
|
|
189
|
-
"[string]": "string",
|
|
190
|
-
"[symbol]": "number"
|
|
191
|
-
})
|
|
192
|
-
attest<{ [x: string]: string; [x: symbol]: number }>(o.infer)
|
|
193
|
-
})
|
|
194
|
-
it("all key kinds", () => {
|
|
195
|
-
const o = type({
|
|
196
|
-
"[string]": "string",
|
|
197
|
-
required: "'foo'",
|
|
198
|
-
"optional?": "'bar'"
|
|
199
|
-
})
|
|
200
|
-
attest<{ [x: string]: string; required: "foo"; optional?: "bar" }>(o.infer)
|
|
201
|
-
})
|
|
202
|
-
it("index key from scope", () => {
|
|
203
|
-
const types = scope({
|
|
204
|
-
key: "symbol|'foo'|'bar'|'baz'",
|
|
205
|
-
obj: {
|
|
206
|
-
"[key]": "string"
|
|
207
|
-
}
|
|
208
|
-
}).export()
|
|
209
|
-
type Key = symbol | "foo" | "bar" | "baz"
|
|
210
|
-
attest<Key>(types.key.infer)
|
|
211
|
-
attest<Record<Key, string>>(types.obj.infer)
|
|
212
|
-
})
|
|
213
|
-
it("syntax error in index definition", () => {
|
|
214
|
-
attest(() =>
|
|
215
|
-
type({
|
|
216
|
-
// @ts-expect-error
|
|
217
|
-
"[unresolvable]": "string"
|
|
218
|
-
})
|
|
219
|
-
).throwsAndHasTypeError(writeUnresolvableMessage("unresolvable"))
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
it("does not allow syntax error message as value", () => {
|
|
223
|
-
attest(() =>
|
|
224
|
-
type({
|
|
225
|
-
// @ts-expect-error
|
|
226
|
-
"[unresolvable]": "'unresolvable' is unresolvable"
|
|
227
|
-
})
|
|
228
|
-
).throwsAndHasTypeError(writeUnresolvableMessage("unresolvable"))
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it("semantic error in index definition", () => {
|
|
232
|
-
attest(() =>
|
|
233
|
-
type({
|
|
234
|
-
// @ts-expect-error
|
|
235
|
-
"[symbol<5]": "string"
|
|
236
|
-
})
|
|
237
|
-
).throwsAndHasTypeError(writeUnboundableMessage("symbol"))
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
it("invalid key type for index definition", () => {
|
|
241
|
-
attest(() =>
|
|
242
|
-
type({
|
|
243
|
-
// @ts-expect-error
|
|
244
|
-
"[object]": "string"
|
|
245
|
-
})
|
|
246
|
-
).throwsAndHasTypeError(writeInvalidPropertyKeyMessage("object"))
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
it("does not allow invalid key type error as value", () => {
|
|
250
|
-
attest(() =>
|
|
251
|
-
type({
|
|
252
|
-
// @ts-expect-error
|
|
253
|
-
"[object]":
|
|
254
|
-
"Indexed key definition 'object' must be a string, number or symbol"
|
|
255
|
-
})
|
|
256
|
-
).throwsAndHasTypeError(writeInvalidPropertyKeyMessage("object"))
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
it("nested", () => {
|
|
260
|
-
const t = type({ "a?": { b: "boolean" } })
|
|
261
|
-
attest<{ a?: { b: boolean } }>(t.infer)
|
|
262
|
-
})
|
|
263
|
-
it("intersections", () => {
|
|
264
|
-
const a = { "a?": "string" } as const
|
|
265
|
-
const b = { b: "string" } as const
|
|
266
|
-
const c = { "c?": "string" } as const
|
|
267
|
-
const abc = type(a).and(b).and(c)
|
|
268
|
-
attest<{ a?: string; b: string; c?: string }>(abc.infer)
|
|
269
|
-
attest(abc.json).equals(type({ ...a, ...b, ...c }).json)
|
|
270
|
-
attest(abc.json).equals(type([[a, "&", b], "&", c]).json)
|
|
271
|
-
})
|
|
272
|
-
it("traverse optional", () => {
|
|
273
|
-
const o = type({ "a?": "string" }).configure({ keys: "strict" })
|
|
274
|
-
attest(o({ a: "a" }).out).snap({ a: "a" })
|
|
275
|
-
attest(o({}).out).snap({})
|
|
276
|
-
attest(o({ a: 1 }).errors?.summary).snap("a must be a string (was number)")
|
|
277
|
-
})
|
|
278
|
-
it("intersection", () => {
|
|
279
|
-
const t = type({ a: "number" }).and({ b: "boolean" })
|
|
280
|
-
// Should be simplified from {a: number} & {b: boolean} to {a: number, b: boolean}
|
|
281
|
-
attest(t.infer).type.toString.snap("{ a: number; b: boolean; }")
|
|
282
|
-
attest(t.json).equals(type({ a: "number", b: "boolean" }).json)
|
|
283
|
-
})
|
|
284
|
-
it("escaped optional token", () => {
|
|
285
|
-
const t = type({ "a\\?": "string" })
|
|
286
|
-
attest<{ "a?": string }>(t.infer)
|
|
287
|
-
})
|
|
288
|
-
it("escaped index", () => {
|
|
289
|
-
const o = type({ "\\[string]": "string" })
|
|
290
|
-
attest<{ "[string]": string }>(o.infer)
|
|
291
|
-
})
|
|
292
|
-
it("multiple bad strict", () => {
|
|
293
|
-
const t = type({ a: "string", b: "boolean" }).configure({
|
|
294
|
-
keys: "strict"
|
|
295
|
-
})
|
|
296
|
-
attest(t({ a: 1, b: 2 }).errors?.summary).snap(
|
|
297
|
-
"a must be a string (was number)\nb must be boolean (was number)"
|
|
298
|
-
)
|
|
299
|
-
})
|
|
300
|
-
})
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { bench } from "@arktype/attest"
|
|
2
|
-
import { scope, type } from "arktype"
|
|
3
|
-
|
|
4
|
-
bench("single-quoted", () => {
|
|
5
|
-
const _ = type("'nineteen characters'")
|
|
6
|
-
})
|
|
7
|
-
.median([3.05, "us"])
|
|
8
|
-
.types([502, "instantiations"])
|
|
9
|
-
|
|
10
|
-
bench("double-quoted", () => {
|
|
11
|
-
const _ = type('"nineteen characters"')
|
|
12
|
-
})
|
|
13
|
-
.median([3.13, "us"])
|
|
14
|
-
.types([502, "instantiations"])
|
|
15
|
-
|
|
16
|
-
bench("regex literal", () => {
|
|
17
|
-
const _ = type("/nineteen characters/")
|
|
18
|
-
})
|
|
19
|
-
.median([4.18, "us"])
|
|
20
|
-
.types([502, "instantiations"])
|
|
21
|
-
|
|
22
|
-
bench("keyword", () => {
|
|
23
|
-
const _ = type("string")
|
|
24
|
-
})
|
|
25
|
-
.median([1.44, "us"])
|
|
26
|
-
.types([84, "instantiations"])
|
|
27
|
-
|
|
28
|
-
const $ = scope({ strung: "string" })
|
|
29
|
-
bench("alias", () => {
|
|
30
|
-
const _ = $.type("strung")
|
|
31
|
-
})
|
|
32
|
-
.median([1.54, "us"])
|
|
33
|
-
.types([725, "instantiations"])
|
|
34
|
-
|
|
35
|
-
bench("number", () => {
|
|
36
|
-
const _ = type("-98765.4321")
|
|
37
|
-
})
|
|
38
|
-
.median([4.41, "us"])
|
|
39
|
-
.types([415, "instantiations"])
|
|
40
|
-
|
|
41
|
-
bench("bigint", () => {
|
|
42
|
-
const _ = type("-987654321n")
|
|
43
|
-
})
|
|
44
|
-
.median()
|
|
45
|
-
.types()
|
|
@@ -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"])
|