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,138 +0,0 @@
|
|
|
1
|
-
import { attest } from "@arktype/attest"
|
|
2
|
-
import { schema } from "@arktype/schema"
|
|
3
|
-
import { type, type Out } from "arktype"
|
|
4
|
-
import { scope, type Ark } from "../ark.js"
|
|
5
|
-
import {
|
|
6
|
-
writeMissingRightOperandMessage,
|
|
7
|
-
writeUnresolvableMessage
|
|
8
|
-
} from "../parser/string/shift/operand/unenclosed.js"
|
|
9
|
-
import type { Type } from "../type.js"
|
|
10
|
-
|
|
11
|
-
describe("tuple expressions", () => {
|
|
12
|
-
it("nested", () => {
|
|
13
|
-
const t = type(["string|bigint", "|", ["number", "|", "boolean"]])
|
|
14
|
-
attest<string | number | bigint | boolean>(t.infer)
|
|
15
|
-
})
|
|
16
|
-
it("autocompletion", () => {
|
|
17
|
-
// @ts-expect-error
|
|
18
|
-
attest(() => type([""])).type.errors(
|
|
19
|
-
`IndexZeroOperator | keyof Ark | "this"`
|
|
20
|
-
)
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
attest(() => type(["string", ""])).type.errors(
|
|
23
|
-
`"keyof" | keyof Ark | "this" | IndexOneOperator'`
|
|
24
|
-
)
|
|
25
|
-
})
|
|
26
|
-
describe("errors", () => {
|
|
27
|
-
it("missing right operand", () => {
|
|
28
|
-
// @ts-expect-error
|
|
29
|
-
attest(() => type(["string", "|"])).throwsAndHasTypeError(
|
|
30
|
-
writeMissingRightOperandMessage("|", "")
|
|
31
|
-
)
|
|
32
|
-
// @ts-expect-error
|
|
33
|
-
attest(() => type(["string", "&"])).throwsAndHasTypeError(
|
|
34
|
-
writeMissingRightOperandMessage("&", "")
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
it("nested parse error", () => {
|
|
38
|
-
attest(() => {
|
|
39
|
-
// @ts-expect-error
|
|
40
|
-
type(["string", "|", "numbr"])
|
|
41
|
-
}).throwsAndHasTypeError(writeUnresolvableMessage("numbr"))
|
|
42
|
-
})
|
|
43
|
-
it("nested object parse error", () => {
|
|
44
|
-
attest(() => {
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
type([{ s: "strng" }, "|", "number"])
|
|
47
|
-
}).throwsAndHasTypeError(writeUnresolvableMessage("strng"))
|
|
48
|
-
})
|
|
49
|
-
// TODO: reenable
|
|
50
|
-
it("this", () => {
|
|
51
|
-
const t = type([{ a: "string" }, "|", { b: "this" }])
|
|
52
|
-
attest(t.infer).type.toString.snap(
|
|
53
|
-
"{ a: string; } | { b: { a: string; } | any; }"
|
|
54
|
-
)
|
|
55
|
-
const types = scope({
|
|
56
|
-
a: {
|
|
57
|
-
a: "string"
|
|
58
|
-
},
|
|
59
|
-
b: {
|
|
60
|
-
b: "expected"
|
|
61
|
-
},
|
|
62
|
-
expected: "a|b"
|
|
63
|
-
}).export()
|
|
64
|
-
attest(t.json).equals(types.expected.json)
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
describe("root expression", () => {
|
|
70
|
-
it("=== single", () => {
|
|
71
|
-
const t = type("===", 5)
|
|
72
|
-
attest<5>(t.infer)
|
|
73
|
-
attest(t.json).equals(type("5").json)
|
|
74
|
-
})
|
|
75
|
-
it("=== branches", () => {
|
|
76
|
-
const t = type("===", "foo", "bar", "baz")
|
|
77
|
-
attest<"foo" | "bar" | "baz">(t.infer)
|
|
78
|
-
attest(t.json).equals(schema.units("foo", "bar", "baz").json)
|
|
79
|
-
})
|
|
80
|
-
it("instanceof single", () => {
|
|
81
|
-
const t = type("instanceof", RegExp)
|
|
82
|
-
attest<RegExp>(t.infer)
|
|
83
|
-
attest(t.json).equals(schema(RegExp).json)
|
|
84
|
-
})
|
|
85
|
-
it("instanceof branches", () => {
|
|
86
|
-
const t = type("instanceof", Array, Date)
|
|
87
|
-
attest<unknown[] | Date>(t.infer)
|
|
88
|
-
attest(t.json).equals(schema(Array, Date).json)
|
|
89
|
-
})
|
|
90
|
-
it("postfix", () => {
|
|
91
|
-
const t = type({ a: "string" }, "[]")
|
|
92
|
-
attest<{ a: string }[]>(t.infer)
|
|
93
|
-
attest(t.json).equals(type({ a: "string" }).array().json)
|
|
94
|
-
})
|
|
95
|
-
it("infix", () => {
|
|
96
|
-
const t = type({ a: "string" }, "|", { b: "boolean" })
|
|
97
|
-
attest<
|
|
98
|
-
| {
|
|
99
|
-
a: string
|
|
100
|
-
}
|
|
101
|
-
| {
|
|
102
|
-
b: boolean
|
|
103
|
-
}
|
|
104
|
-
>(t.infer)
|
|
105
|
-
|
|
106
|
-
attest(t.json).equals(type({ a: "string" }).or({ b: "boolean" }).json)
|
|
107
|
-
})
|
|
108
|
-
it("morph", () => {
|
|
109
|
-
const t = type({ a: "string" }, "=>", (In) => ({ b: In.a }))
|
|
110
|
-
attest<Type<(In: { a: string }) => Out<{ b: string }>, Ark>>(t)
|
|
111
|
-
})
|
|
112
|
-
it("narrow", () => {
|
|
113
|
-
const t = type(
|
|
114
|
-
{ a: "string" },
|
|
115
|
-
":",
|
|
116
|
-
(In): In is { a: "foo" } => In.a === "foo"
|
|
117
|
-
)
|
|
118
|
-
attest<{ a: "foo" }>(t.infer)
|
|
119
|
-
})
|
|
120
|
-
it("this", () => {
|
|
121
|
-
const t = type({ a: "string" }, "|", { b: "this" })
|
|
122
|
-
attest(t.infer).type.toString.snap(
|
|
123
|
-
"{ a: string; } | { b: { a: string; } | any; }"
|
|
124
|
-
)
|
|
125
|
-
attest(t.json).equals(type([{ a: "string" }, "|", { b: "this" }]).json)
|
|
126
|
-
})
|
|
127
|
-
it("tuple as second arg", () => {
|
|
128
|
-
// this case is not fundamentally unique but TS has a hard time
|
|
129
|
-
// narrowing tuples in contexts like this
|
|
130
|
-
const t = type("keyof", [
|
|
131
|
-
{ a: "string" },
|
|
132
|
-
"&",
|
|
133
|
-
{ b: "boolean" }
|
|
134
|
-
// as const is required for TS <=5.0
|
|
135
|
-
] as const)
|
|
136
|
-
attest<"a" | "b">(t.infer)
|
|
137
|
-
})
|
|
138
|
-
})
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// import { writeFileSync } from "node:fs"
|
|
2
|
-
// import { fromHere } from "@arktype/fs"
|
|
3
|
-
|
|
4
|
-
// const randomInRange = (min: number, max: number) =>
|
|
5
|
-
// Math.floor(Math.random() * (max - min + 1)) + min
|
|
6
|
-
|
|
7
|
-
// const cyclicScopeSeed = Object.freeze({
|
|
8
|
-
// user: {
|
|
9
|
-
// name: "string",
|
|
10
|
-
// "friends?": "user[]",
|
|
11
|
-
// groups: "group[]"
|
|
12
|
-
// },
|
|
13
|
-
// group: {
|
|
14
|
-
// title: "string",
|
|
15
|
-
// members: "user[]",
|
|
16
|
-
// isActive: "boolean|undefined"
|
|
17
|
-
// }
|
|
18
|
-
// })
|
|
19
|
-
|
|
20
|
-
// const generateScopeJson = (interval: number, seedDefs: object) => {
|
|
21
|
-
// const defs = Object.entries(seedDefs).reduce(
|
|
22
|
-
// (result, [name, seedDef]) => {
|
|
23
|
-
// const variants: Record<string, any> = { [name]: seedDef }
|
|
24
|
-
// const defCopyCount = Math.floor(interval / 2)
|
|
25
|
-
// for (let i = 2; i <= defCopyCount; i++) {
|
|
26
|
-
// variants[`${name}${i}`] = Object.fromEntries(
|
|
27
|
-
// Object.entries(seedDef).map(([k, def]) => {
|
|
28
|
-
// const isOptionalKey = k.endsWith("?")
|
|
29
|
-
// let randomizedDef = def as string
|
|
30
|
-
// if (typeof def === "string") {
|
|
31
|
-
// // Only randomize the cyclic scope values
|
|
32
|
-
// for (let name in cyclicScopeSeed) {
|
|
33
|
-
// if (name.endsWith("?")) {
|
|
34
|
-
// name = name.slice(0, -1)
|
|
35
|
-
// }
|
|
36
|
-
// randomizedDef = randomizedDef.replaceAll(
|
|
37
|
-
// name,
|
|
38
|
-
// `${name}${randomInRange(2, defCopyCount)}`
|
|
39
|
-
// )
|
|
40
|
-
// }
|
|
41
|
-
// }
|
|
42
|
-
// return [
|
|
43
|
-
// `${isOptionalKey ? k.slice(0, -1) : k}${i}${
|
|
44
|
-
// isOptionalKey ? "?" : ""
|
|
45
|
-
// }`,
|
|
46
|
-
// randomizedDef
|
|
47
|
-
// ]
|
|
48
|
-
// })
|
|
49
|
-
// )
|
|
50
|
-
// }
|
|
51
|
-
// return { ...result, ...variants }
|
|
52
|
-
// },
|
|
53
|
-
// {} as Record<string, any>
|
|
54
|
-
// )
|
|
55
|
-
// return JSON.stringify(defs, null, 4)
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
// const seedMap = {
|
|
59
|
-
// cyclic: cyclicScopeSeed
|
|
60
|
-
// }
|
|
61
|
-
|
|
62
|
-
// type GenerateScopeBenchesOptions = {
|
|
63
|
-
// intervals: number[]
|
|
64
|
-
// seed: keyof typeof seedMap
|
|
65
|
-
// }
|
|
66
|
-
|
|
67
|
-
// const generateScopeBenches = ({
|
|
68
|
-
// intervals,
|
|
69
|
-
// seed
|
|
70
|
-
// }: GenerateScopeBenchesOptions) => {
|
|
71
|
-
// const toFile = fromHere("generated", `${seed}.ts`)
|
|
72
|
-
// let benchDeclarations = ""
|
|
73
|
-
// for (const interval of intervals) {
|
|
74
|
-
// const scopeName = `${seed}${interval}`
|
|
75
|
-
// console.log(`Generating dictionary '${scopeName}'...`)
|
|
76
|
-
// benchDeclarations += `export const ${scopeName} = ${generateScopeJson(
|
|
77
|
-
// interval,
|
|
78
|
-
// seedMap[seed]
|
|
79
|
-
// )} as const
|
|
80
|
-
|
|
81
|
-
// `
|
|
82
|
-
// }
|
|
83
|
-
// writeFileSync(toFile, benchDeclarations)
|
|
84
|
-
// }
|
|
85
|
-
|
|
86
|
-
// generateScopeBenches({
|
|
87
|
-
// intervals: [10, 100, 500],
|
|
88
|
-
// seed: "cyclic"
|
|
89
|
-
// })
|