arktype 1.1.0-dev-2 → 2.0.0-dev.0
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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { attest } from "@arktype/attest"
|
|
2
|
+
import { writeMalformedNumericLiteralMessage } from "@arktype/util"
|
|
3
|
+
import { scope, type } from "arktype"
|
|
4
|
+
import { writeUnresolvableMessage } from "../parser/string/shift/operand/unenclosed.js"
|
|
5
|
+
|
|
6
|
+
describe("parse unenclosed", () => {
|
|
7
|
+
describe("identifier", () => {
|
|
8
|
+
it("keyword", () => {
|
|
9
|
+
attest<string>(type("string").infer)
|
|
10
|
+
})
|
|
11
|
+
it("alias", () => {
|
|
12
|
+
const a = scope({ a: "string" }).type("a")
|
|
13
|
+
attest<string>(a.infer)
|
|
14
|
+
})
|
|
15
|
+
describe("errors", () => {
|
|
16
|
+
it("unresolvable", () => {
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
attest(() => type("HUH")).throwsAndHasTypeError(
|
|
19
|
+
writeUnresolvableMessage("HUH")
|
|
20
|
+
)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
describe("number", () => {
|
|
25
|
+
describe("positive", () => {
|
|
26
|
+
it("whole", () => {
|
|
27
|
+
const four = type("4")
|
|
28
|
+
attest<4>(four.infer)
|
|
29
|
+
// attest(four.node).snap({ number: { value: 4 } })
|
|
30
|
+
})
|
|
31
|
+
it("decimal", () => {
|
|
32
|
+
attest<3.14159>(type("3.14159").infer)
|
|
33
|
+
})
|
|
34
|
+
it("decimal with zero whole portion", () => {
|
|
35
|
+
attest<0.5>(type("0.5").infer)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
describe("negative", () => {
|
|
39
|
+
it("whole", () => {
|
|
40
|
+
attest<-12>(type("-12").infer)
|
|
41
|
+
})
|
|
42
|
+
it("decimal", () => {
|
|
43
|
+
attest<-1.618>(type("-1.618").infer)
|
|
44
|
+
})
|
|
45
|
+
it("decimal with zero whole portion", () => {
|
|
46
|
+
attest<-0.001>(type("-0.001").infer)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
it("zero", () => {
|
|
50
|
+
attest<0>(type("0").infer)
|
|
51
|
+
})
|
|
52
|
+
describe("errors", () => {
|
|
53
|
+
it("multiple decimals", () => {
|
|
54
|
+
// @ts-expect-error
|
|
55
|
+
attest(() => type("127.0.0.1")).throwsAndHasTypeError(
|
|
56
|
+
writeUnresolvableMessage("127.0.0.1")
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
it("with alpha", () => {
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
attest(() => type("13three7")).throwsAndHasTypeError(
|
|
62
|
+
writeUnresolvableMessage("13three7")
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
it("leading zeroes", () => {
|
|
66
|
+
// @ts-expect-error
|
|
67
|
+
attest(() => type("010")).throwsAndHasTypeError(
|
|
68
|
+
writeMalformedNumericLiteralMessage("010", "number")
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
it("trailing zeroes", () => {
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
attest(() => type("4.0")).throws(
|
|
74
|
+
writeMalformedNumericLiteralMessage("4.0", "number")
|
|
75
|
+
)
|
|
76
|
+
})
|
|
77
|
+
it("negative zero", () => {
|
|
78
|
+
// @ts-expect-error
|
|
79
|
+
attest(() => type("-0")).throws(
|
|
80
|
+
writeMalformedNumericLiteralMessage("-0", "number")
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
describe("bigint", () => {
|
|
86
|
+
it("positive", () => {
|
|
87
|
+
// Is prime :D
|
|
88
|
+
attest<12345678910987654321n>(type("12345678910987654321n").infer)
|
|
89
|
+
})
|
|
90
|
+
it("negative", () => {
|
|
91
|
+
attest<-9801n>(type("-9801n").infer)
|
|
92
|
+
})
|
|
93
|
+
it("zero", () => {
|
|
94
|
+
attest<0n>(type("0n").infer)
|
|
95
|
+
})
|
|
96
|
+
describe("errors", () => {
|
|
97
|
+
it("decimal", () => {
|
|
98
|
+
// @ts-expect-error
|
|
99
|
+
attest(() => type("999.1n")).throwsAndHasTypeError(
|
|
100
|
+
writeUnresolvableMessage("999.1n")
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it("leading zeroes", () => {
|
|
105
|
+
// TS currently doesn't try to infer this as bigint even
|
|
106
|
+
// though it matches our rules for a "malformed" integer.
|
|
107
|
+
// @ts-expect-error
|
|
108
|
+
attest(() => type("007n"))
|
|
109
|
+
.throws(writeMalformedNumericLiteralMessage("007n", "bigint"))
|
|
110
|
+
.type.errors(writeUnresolvableMessage("007n"))
|
|
111
|
+
})
|
|
112
|
+
it("negative zero", () => {
|
|
113
|
+
// @ts-expect-error
|
|
114
|
+
attest(() => type("-0n")).throwsAndHasTypeError(
|
|
115
|
+
writeMalformedNumericLiteralMessage("-0n", "bigint")
|
|
116
|
+
)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
})
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { attest } from "@arktype/attest"
|
|
2
|
+
import { schema, writeIndivisibleMessage } from "@arktype/schema"
|
|
3
|
+
import { type } from "arktype"
|
|
4
|
+
import {
|
|
5
|
+
writeMissingRightOperandMessage,
|
|
6
|
+
writeUnresolvableMessage
|
|
7
|
+
} from "../parser/string/shift/operand/unenclosed.js"
|
|
8
|
+
|
|
9
|
+
describe("union", () => {
|
|
10
|
+
it("binary", () => {
|
|
11
|
+
const binary = type("number|string")
|
|
12
|
+
attest<number | string>(binary.infer)
|
|
13
|
+
// attest(binary.node).snap({ number: true, string: true })
|
|
14
|
+
})
|
|
15
|
+
it("nary", () => {
|
|
16
|
+
const nary = type("false|null|undefined|0|''")
|
|
17
|
+
attest<false | "" | 0 | null | undefined>(nary.infer)
|
|
18
|
+
const expected = schema.units(false, null, undefined, 0, "")
|
|
19
|
+
attest(nary.json).equals(expected.json)
|
|
20
|
+
})
|
|
21
|
+
it("subtype pruning", () => {
|
|
22
|
+
type([{ a: "string" }, "|", { a: "'foo'" }])
|
|
23
|
+
})
|
|
24
|
+
it("multiple subtypes pruned", () => {
|
|
25
|
+
const t = type("'foo'|'bar'|string|'baz'|/.*/")
|
|
26
|
+
attest<string>(t.infer)
|
|
27
|
+
attest(t.json).is(type("string").json)
|
|
28
|
+
})
|
|
29
|
+
it("union of true and false reduces to boolean", () => {
|
|
30
|
+
const t = type("true|false")
|
|
31
|
+
attest(t.infer).type.toString("boolean")
|
|
32
|
+
attest(t.json).equals(type("boolean").json)
|
|
33
|
+
})
|
|
34
|
+
it("nested tuple union", () => {
|
|
35
|
+
const t = type(["string|bigint", "|", ["number", "|", "boolean"]])
|
|
36
|
+
attest<string | number | bigint | boolean>(t.infer)
|
|
37
|
+
attest(t.json).equals(type("string|bigint|number|boolean").json)
|
|
38
|
+
})
|
|
39
|
+
it("length stress", () => {
|
|
40
|
+
// as of TS 5.1, can handle a max of 46 branches before an inifinitely
|
|
41
|
+
// deep error not the end of the world if this changes slightly, but
|
|
42
|
+
// wanted to make those changes explicit if something reduces it it's
|
|
43
|
+
// also still very responsive up until it hits the limit, so it is
|
|
44
|
+
// likely a safeguard rather than a limitation of the parser
|
|
45
|
+
const t = type(
|
|
46
|
+
"0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45"
|
|
47
|
+
)
|
|
48
|
+
// prettier-ignore
|
|
49
|
+
attest<0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45>(t.infer)
|
|
50
|
+
})
|
|
51
|
+
describe("expressions", () => {
|
|
52
|
+
const expected = () =>
|
|
53
|
+
schema(
|
|
54
|
+
{
|
|
55
|
+
basis: "object",
|
|
56
|
+
required: {
|
|
57
|
+
key: "a",
|
|
58
|
+
value: { basis: "string" }
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
basis: "object",
|
|
63
|
+
required: {
|
|
64
|
+
key: "b",
|
|
65
|
+
value: { basis: "number" }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
).json
|
|
69
|
+
|
|
70
|
+
it("tuple", () => {
|
|
71
|
+
const t = type([{ a: "string" }, "|", { b: "number" }])
|
|
72
|
+
attest<{ a: string } | { b: number }>(t.infer)
|
|
73
|
+
attest(t.json).equals(expected())
|
|
74
|
+
})
|
|
75
|
+
it("root", () => {
|
|
76
|
+
const t = type({ a: "string" }, "|", { b: "number" })
|
|
77
|
+
attest<{ a: string } | { b: number }>(t.infer)
|
|
78
|
+
attest(t.json).equals(expected())
|
|
79
|
+
})
|
|
80
|
+
it("chained", () => {
|
|
81
|
+
const t = type({ a: "string" }).or({ b: "number" })
|
|
82
|
+
attest<
|
|
83
|
+
| {
|
|
84
|
+
a: string
|
|
85
|
+
}
|
|
86
|
+
| {
|
|
87
|
+
b: number
|
|
88
|
+
}
|
|
89
|
+
>(t.infer)
|
|
90
|
+
attest(t.json).equals(expected())
|
|
91
|
+
})
|
|
92
|
+
it("root autocompletions", () => {
|
|
93
|
+
// @ts-expect-error
|
|
94
|
+
attest(() => type({ a: "s" }, "|", { b: "boolean" })).type.errors(
|
|
95
|
+
`Type '"s"' is not assignable to type '"string" | "symbol" | "semver"'`
|
|
96
|
+
)
|
|
97
|
+
// @ts-expect-error
|
|
98
|
+
attest(() => type({ a: "string" }, "|", { b: "b" })).type.errors(
|
|
99
|
+
`Type '"b"' is not assignable to type '"bigint" | "boolean"'`
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
describe("errors", () => {
|
|
104
|
+
it("bad reference", () => {
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
attest(() => type("number|strng")).throwsAndHasTypeError(
|
|
107
|
+
writeUnresolvableMessage("strng")
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
it("consecutive tokens", () => {
|
|
111
|
+
// @ts-expect-error
|
|
112
|
+
attest(() => type("boolean||null")).throws(
|
|
113
|
+
writeMissingRightOperandMessage("|", "|null")
|
|
114
|
+
)
|
|
115
|
+
})
|
|
116
|
+
it("ends with |", () => {
|
|
117
|
+
// @ts-expect-error
|
|
118
|
+
attest(() => type("boolean|")).throws(
|
|
119
|
+
writeMissingRightOperandMessage("|", "")
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
it("long missing union member", () => {
|
|
123
|
+
attest(() =>
|
|
124
|
+
// @ts-expect-error
|
|
125
|
+
type("boolean[]|(string|number|)|object")
|
|
126
|
+
).throws(writeMissingRightOperandMessage("|", ")|object"))
|
|
127
|
+
})
|
|
128
|
+
it("left semantic error", () => {
|
|
129
|
+
// @ts-expect-error
|
|
130
|
+
attest(() => type("symbol%2|string")).throwsAndHasTypeError(
|
|
131
|
+
writeIndivisibleMessage("symbol")
|
|
132
|
+
)
|
|
133
|
+
})
|
|
134
|
+
it("right semantic error", () => {
|
|
135
|
+
// @ts-expect-error
|
|
136
|
+
attest(() => type("string|symbol%2")).throwsAndHasTypeError(
|
|
137
|
+
writeIndivisibleMessage("symbol")
|
|
138
|
+
)
|
|
139
|
+
})
|
|
140
|
+
it("chained bad reference", () => {
|
|
141
|
+
// @ts-expect-error
|
|
142
|
+
attest(() => type("string").or("nummer")).throwsAndHasTypeError(
|
|
143
|
+
writeUnresolvableMessage("nummer")
|
|
144
|
+
)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
})
|
package/ark.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JsObjects,
|
|
3
|
+
Parsing,
|
|
4
|
+
TsKeywords,
|
|
5
|
+
Validation,
|
|
6
|
+
type inferred
|
|
7
|
+
} from "@arktype/schema"
|
|
8
|
+
import type { MatchParser } from "./match.js"
|
|
9
|
+
import { Scope, type Module, type ScopeParser } from "./scope.js"
|
|
10
|
+
import type {
|
|
11
|
+
DeclarationParser,
|
|
12
|
+
DefinitionParser,
|
|
13
|
+
Generic,
|
|
14
|
+
TypeParser
|
|
15
|
+
} from "./type.js"
|
|
16
|
+
|
|
17
|
+
/** Root scopes can be inferred automatically from node definitions, but
|
|
18
|
+
* explicitly typing them can improve responsiveness */
|
|
19
|
+
export type RootScope<exports> = Scope<{
|
|
20
|
+
exports: exports
|
|
21
|
+
locals: {}
|
|
22
|
+
ambient: {}
|
|
23
|
+
}>
|
|
24
|
+
|
|
25
|
+
export type ArkResolutions = { exports: Ark; locals: {}; ambient: Ark }
|
|
26
|
+
|
|
27
|
+
// For some reason if we try to inline this, it gets evaluated and the module
|
|
28
|
+
// can't be inferred
|
|
29
|
+
export type ParsingResolutions = {
|
|
30
|
+
exports: Parsing.infer
|
|
31
|
+
locals: {}
|
|
32
|
+
ambient: {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type TsGenericsResolutions<$ = Ark> = {
|
|
36
|
+
exports: TsGenericsExports<$>
|
|
37
|
+
locals: {}
|
|
38
|
+
ambient: {}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type TsGenericsExports<$ = Ark> = {
|
|
42
|
+
Record: Generic<
|
|
43
|
+
["K", "V"],
|
|
44
|
+
{
|
|
45
|
+
"[K]": "V"
|
|
46
|
+
},
|
|
47
|
+
// as long as the generics in the root scope don't reference one
|
|
48
|
+
// another, they shouldn't need a bound local scope
|
|
49
|
+
$
|
|
50
|
+
>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const tsGenerics = {} as Module<TsGenericsResolutions>
|
|
54
|
+
|
|
55
|
+
export const ark: Scope<ArkResolutions> = Scope.root({
|
|
56
|
+
...TsKeywords.resolutions,
|
|
57
|
+
...JsObjects.resolutions,
|
|
58
|
+
...Validation.resolutions,
|
|
59
|
+
// TODO: fix
|
|
60
|
+
...tsGenerics,
|
|
61
|
+
parse: Parsing.resolutions as {} as Module<ParsingResolutions>
|
|
62
|
+
}).toAmbient() as never
|
|
63
|
+
|
|
64
|
+
export const arktypes: Module<ArkResolutions> = ark.export()
|
|
65
|
+
|
|
66
|
+
// this type is redundant with the inferred definition of ark but allow types
|
|
67
|
+
// derived from the default scope to be calulated more efficiently
|
|
68
|
+
export interface Ark
|
|
69
|
+
extends TsKeywords.infer,
|
|
70
|
+
JsObjects.infer,
|
|
71
|
+
Validation.infer,
|
|
72
|
+
TsGenericsExports {
|
|
73
|
+
parse: Module<ParsingResolutions>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const scope: ScopeParser<{}, Ark> = ark.scope as never
|
|
77
|
+
|
|
78
|
+
export const type: TypeParser<Ark> = ark.type
|
|
79
|
+
|
|
80
|
+
// TODO: cast needed?
|
|
81
|
+
export const match: MatchParser<Ark> = ark.match as never
|
|
82
|
+
|
|
83
|
+
export namespace type {
|
|
84
|
+
export type cast<to> = {
|
|
85
|
+
[inferred]?: to
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const define: DefinitionParser<Ark> = ark.define
|
|
90
|
+
|
|
91
|
+
export const declare: DeclarationParser<Ark> = ark.declare
|
package/main.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export {
|
|
2
|
+
ArkErrors as ArkErrors,
|
|
3
|
+
type ArkTypeError as ArkTypeError
|
|
4
|
+
} from "@arktype/schema"
|
|
5
|
+
export type { Out, is } from "@arktype/schema"
|
|
4
6
|
export {
|
|
5
7
|
ark,
|
|
6
8
|
arktypes,
|
|
@@ -9,12 +11,8 @@ export {
|
|
|
9
11
|
match,
|
|
10
12
|
scope,
|
|
11
13
|
type,
|
|
12
|
-
when,
|
|
13
14
|
type Ark
|
|
14
|
-
} from "./
|
|
15
|
-
export {
|
|
16
|
-
export { tsGenerics } from "./scopes/tsGenerics.js"
|
|
17
|
-
export { tsKeywords } from "./scopes/tsKeywords.js"
|
|
18
|
-
export { validation } from "./scopes/validation.js"
|
|
15
|
+
} from "./ark.js"
|
|
16
|
+
export type { Module, Scope } from "./scope.js"
|
|
19
17
|
export { Type } from "./type.js"
|
|
20
18
|
export type { inferTypeRoot, validateTypeRoot } from "./type.js"
|
package/match.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { Morph } from "@arktype/schema"
|
|
2
2
|
import type {
|
|
3
|
-
conform,
|
|
4
|
-
entryOf,
|
|
5
|
-
ErrorMessage,
|
|
6
|
-
evaluate,
|
|
7
3
|
Fn,
|
|
8
4
|
isDisjoint,
|
|
9
|
-
join,
|
|
10
|
-
paramsOf,
|
|
11
5
|
replaceKey,
|
|
12
6
|
returnOf,
|
|
13
7
|
unionToTuple,
|
|
@@ -16,41 +10,6 @@ import type {
|
|
|
16
10
|
import type { Scope } from "./scope.js"
|
|
17
11
|
import { Type, type inferTypeRoot, type validateTypeRoot } from "./type.js"
|
|
18
12
|
|
|
19
|
-
type cedille = "¸"
|
|
20
|
-
|
|
21
|
-
type serializedWhentry<
|
|
22
|
-
k extends string,
|
|
23
|
-
v extends string
|
|
24
|
-
> = `[${k}${cedille}${v}]`
|
|
25
|
-
|
|
26
|
-
type parseWhentryKey<
|
|
27
|
-
s extends string,
|
|
28
|
-
$,
|
|
29
|
-
result = {}
|
|
30
|
-
> = s extends `${serializedWhentry<infer k, infer v>}${cedille}${infer tail}`
|
|
31
|
-
? validateTypeRoot<v, $> extends ErrorMessage<infer message>
|
|
32
|
-
? ErrorMessage<message>
|
|
33
|
-
: parseWhentryKey<tail, $, result & { [_ in k]: inferTypeRoot<v, $> }>
|
|
34
|
-
: s extends serializedWhentry<infer k, infer v>
|
|
35
|
-
? validateTypeRoot<v, $> extends ErrorMessage<infer message>
|
|
36
|
-
? ErrorMessage<message>
|
|
37
|
-
: evaluate<result & { [_ in k]: inferTypeRoot<v, $> }>
|
|
38
|
-
: validateTypeRoot<s, $> extends ErrorMessage<infer message>
|
|
39
|
-
? ErrorMessage<message>
|
|
40
|
-
: never
|
|
41
|
-
|
|
42
|
-
export type WhenParser<$> = <const def>(
|
|
43
|
-
def: validateTypeRoot<def, $>
|
|
44
|
-
) => join<
|
|
45
|
-
unionToTuple<`[${join<conform<entryOf<def>, [string, string]>, cedille>}]`>,
|
|
46
|
-
cedille
|
|
47
|
-
>
|
|
48
|
-
|
|
49
|
-
export const createWhenParser = <$>(scope: Scope): WhenParser<$> => {
|
|
50
|
-
const parser = (def: unknown) => new Type(def, scope).alias
|
|
51
|
-
return parser as never
|
|
52
|
-
}
|
|
53
|
-
|
|
54
13
|
type MatchContext = {
|
|
55
14
|
inConstraint: unknown
|
|
56
15
|
outConstraint: unknown
|
|
@@ -59,35 +18,54 @@ type MatchContext = {
|
|
|
59
18
|
}
|
|
60
19
|
|
|
61
20
|
type validateCases<cases, ctx extends MatchContext> = {
|
|
62
|
-
|
|
63
|
-
|
|
21
|
+
[k in keyof cases | keyof ctx["$"] | "default"]?: k extends "default"
|
|
22
|
+
? (In: ctx["inConstraint"]) => ctx["outConstraint"]
|
|
23
|
+
: k extends validateTypeRoot<k, ctx["$"]>
|
|
64
24
|
? (
|
|
65
25
|
In: ctx["inConstraint"] & inferTypeRoot<k, ctx["$"]>
|
|
66
26
|
) => ctx["outConstraint"]
|
|
67
|
-
:
|
|
68
|
-
|
|
69
|
-
|
|
27
|
+
: validateTypeRoot<k, ctx["$"]>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type errorCases<cases, ctx extends MatchContext> = {
|
|
31
|
+
[k in keyof cases]?: k extends "default"
|
|
32
|
+
? (In: ctx["inConstraint"]) => ctx["outConstraint"]
|
|
33
|
+
: k extends validateTypeRoot<k, ctx["$"]>
|
|
34
|
+
? (
|
|
35
|
+
In: ctx["inConstraint"] & inferTypeRoot<k, ctx["$"]>
|
|
36
|
+
) => ctx["outConstraint"]
|
|
37
|
+
: validateTypeRoot<k, ctx["$"]>
|
|
38
|
+
} & {
|
|
39
|
+
[k in Exclude<keyof ctx["$"], keyof cases>]?: (
|
|
40
|
+
In: ctx["inConstraint"] & ctx["$"][k]
|
|
41
|
+
) => ctx["outConstraint"]
|
|
42
|
+
} & {
|
|
43
|
+
default?: (In: ctx["inConstraint"]) => ctx["outConstraint"]
|
|
70
44
|
}
|
|
71
45
|
|
|
72
|
-
export type
|
|
46
|
+
export type CaseMatchParser<ctx extends MatchContext> = {
|
|
47
|
+
<cases>(
|
|
48
|
+
def: cases extends validateCases<cases, ctx>
|
|
49
|
+
? cases
|
|
50
|
+
: errorCases<cases, ctx>
|
|
51
|
+
): ChainableMatchParser<
|
|
52
|
+
replaceKey<ctx, "thens", [...ctx["thens"], ...unionToTuple<valueOf<cases>>]>
|
|
53
|
+
>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type MatchParser<$> = CaseMatchParser<{
|
|
57
|
+
inConstraint: unknown
|
|
58
|
+
outConstraint: unknown
|
|
59
|
+
thens: []
|
|
60
|
+
$: $
|
|
61
|
+
}> & {
|
|
73
62
|
<In = unknown, Out = unknown>(): ChainableMatchParser<{
|
|
74
63
|
inConstraint: In
|
|
75
64
|
outConstraint: Out
|
|
76
65
|
thens: []
|
|
77
66
|
$: $
|
|
78
67
|
}>
|
|
79
|
-
}
|
|
80
|
-
inConstraint: unknown
|
|
81
|
-
outConstraint: unknown
|
|
82
|
-
thens: []
|
|
83
|
-
$: $
|
|
84
|
-
}>
|
|
85
|
-
|
|
86
|
-
export type CaseMatchParser<ctx extends MatchContext> = <cases>(
|
|
87
|
-
def: conform<cases, validateCases<cases, ctx>>
|
|
88
|
-
) => ChainableMatchParser<
|
|
89
|
-
replaceKey<ctx, "thens", [...ctx["thens"], ...unionToTuple<valueOf<cases>>]>
|
|
90
|
-
>
|
|
68
|
+
}
|
|
91
69
|
|
|
92
70
|
export type WhenMatchParser<ctx extends MatchContext> = <
|
|
93
71
|
def,
|
|
@@ -99,27 +77,28 @@ export type WhenMatchParser<ctx extends MatchContext> = <
|
|
|
99
77
|
then: then
|
|
100
78
|
) => ChainableMatchParser<replaceKey<ctx, "thens", [...ctx["thens"], then]>>
|
|
101
79
|
|
|
102
|
-
export type
|
|
80
|
+
export type MatchInvocation<ctx extends MatchContext> = <
|
|
103
81
|
data extends ctx["inConstraint"]
|
|
104
82
|
>(
|
|
105
|
-
|
|
83
|
+
data: data
|
|
106
84
|
) => {
|
|
107
|
-
[i in Extract<keyof ctx["thens"], `${number}`>]:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
>
|
|
111
|
-
?
|
|
85
|
+
[i in Extract<keyof ctx["thens"], `${number}`>]: ctx["thens"][i] extends Fn<
|
|
86
|
+
[infer In],
|
|
87
|
+
infer Out
|
|
88
|
+
>
|
|
89
|
+
? isDisjoint<data, In> extends true
|
|
90
|
+
? never
|
|
91
|
+
: Out
|
|
112
92
|
: returnOf<ctx["thens"][i]>
|
|
113
93
|
}[Extract<keyof ctx["thens"], `${number}`>]
|
|
114
94
|
|
|
115
95
|
export type ChainableMatchParser<ctx extends MatchContext> =
|
|
116
|
-
|
|
96
|
+
MatchInvocation<ctx> & {
|
|
117
97
|
cases: CaseMatchParser<ctx>
|
|
118
98
|
when: WhenMatchParser<ctx>
|
|
119
99
|
}
|
|
120
100
|
|
|
121
101
|
export const createMatchParser = <$>(scope: Scope): MatchParser<$> => {
|
|
122
|
-
// TODO: move to match node, discrimination
|
|
123
102
|
const parser = (cases: Record<string, Morph>) => {
|
|
124
103
|
const caseArray = Object.entries(cases).map(([def, morph]) => ({
|
|
125
104
|
when: new Type(def, scope).allows,
|
package/out/ark.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { JsObjects, Parsing, TsKeywords, Validation, type inferred } from "@arktype/schema";
|
|
2
|
+
import type { MatchParser } from "./match.js";
|
|
3
|
+
import { Scope, type Module, type ScopeParser } from "./scope.js";
|
|
4
|
+
import type { DeclarationParser, DefinitionParser, Generic, TypeParser } from "./type.js";
|
|
5
|
+
/** Root scopes can be inferred automatically from node definitions, but
|
|
6
|
+
* explicitly typing them can improve responsiveness */
|
|
7
|
+
export type RootScope<exports> = Scope<{
|
|
8
|
+
exports: exports;
|
|
9
|
+
locals: {};
|
|
10
|
+
ambient: {};
|
|
11
|
+
}>;
|
|
12
|
+
export type ArkResolutions = {
|
|
13
|
+
exports: Ark;
|
|
14
|
+
locals: {};
|
|
15
|
+
ambient: Ark;
|
|
16
|
+
};
|
|
17
|
+
export type ParsingResolutions = {
|
|
18
|
+
exports: Parsing.infer;
|
|
19
|
+
locals: {};
|
|
20
|
+
ambient: {};
|
|
21
|
+
};
|
|
22
|
+
export type TsGenericsResolutions<$ = Ark> = {
|
|
23
|
+
exports: TsGenericsExports<$>;
|
|
24
|
+
locals: {};
|
|
25
|
+
ambient: {};
|
|
26
|
+
};
|
|
27
|
+
type TsGenericsExports<$ = Ark> = {
|
|
28
|
+
Record: Generic<[
|
|
29
|
+
"K",
|
|
30
|
+
"V"
|
|
31
|
+
], {
|
|
32
|
+
"[K]": "V";
|
|
33
|
+
}, $>;
|
|
34
|
+
};
|
|
35
|
+
export declare const tsGenerics: Module<TsGenericsResolutions<Ark>>;
|
|
36
|
+
export declare const ark: Scope<ArkResolutions>;
|
|
37
|
+
export declare const arktypes: Module<ArkResolutions>;
|
|
38
|
+
export interface Ark extends TsKeywords.infer, JsObjects.infer, Validation.infer, TsGenericsExports {
|
|
39
|
+
parse: Module<ParsingResolutions>;
|
|
40
|
+
}
|
|
41
|
+
export declare const scope: ScopeParser<{}, Ark>;
|
|
42
|
+
export declare const type: TypeParser<Ark>;
|
|
43
|
+
export declare const match: MatchParser<Ark>;
|
|
44
|
+
export declare namespace type {
|
|
45
|
+
type cast<to> = {
|
|
46
|
+
[inferred]?: to;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export declare const define: DefinitionParser<Ark>;
|
|
50
|
+
export declare const declare: DeclarationParser<Ark>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=ark.d.ts.map
|
package/out/ark.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ark.d.ts","sourceRoot":"","sources":["../ark.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,UAAU,EACV,KAAK,QAAQ,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,KAAK,EACX,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EACP,UAAU,EACV,MAAM,WAAW,CAAA;AAElB;uDACuD;AACvD,MAAM,MAAM,SAAS,CAAC,OAAO,IAAI,KAAK,CAAC;IACtC,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,EAAE,CAAA;IACV,OAAO,EAAE,EAAE,CAAA;CACX,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,EAAE,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAA;AAIvE,MAAM,MAAM,kBAAkB,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAA;IACtB,MAAM,EAAE,EAAE,CAAA;IACV,OAAO,EAAE,EAAE,CAAA;CACX,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI;IAC5C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;IAC7B,MAAM,EAAE,EAAE,CAAA;IACV,OAAO,EAAE,EAAE,CAAA;CACX,CAAA;AAED,KAAK,iBAAiB,CAAC,CAAC,GAAG,GAAG,IAAI;IACjC,MAAM,EAAE,OAAO,CACd;QAAC,GAAG;QAAE,GAAG;KAAC,EACV;QACC,KAAK,EAAE,GAAG,CAAA;KACV,EAGD,CAAC,CACD,CAAA;CACD,CAAA;AAED,eAAO,MAAM,UAAU,oCAAsC,CAAA;AAE7D,eAAO,MAAM,GAAG,EAAE,KAAK,CAAC,cAAc,CAOf,CAAA;AAEvB,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAgB,CAAA;AAI5D,MAAM,WAAW,GAChB,SAAQ,UAAU,CAAC,KAAK,EACvB,SAAS,CAAC,KAAK,EACf,UAAU,CAAC,KAAK,EAChB,iBAAiB;IAClB,KAAK,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAA;CACjC;AAED,eAAO,MAAM,KAAK,EAAE,WAAW,CAAC,EAAE,EAAE,GAAG,CAAsB,CAAA;AAE7D,eAAO,MAAM,IAAI,EAAE,UAAU,CAAC,GAAG,CAAY,CAAA;AAG7C,eAAO,MAAM,KAAK,EAAE,WAAW,CAAC,GAAG,CAAsB,CAAA;AAEzD,yBAAiB,IAAI,CAAC;IACrB,KAAY,IAAI,CAAC,EAAE,IAAI;QACtB,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAA;KACf,CAAA;CACD;AAED,eAAO,MAAM,MAAM,EAAE,gBAAgB,CAAC,GAAG,CAAc,CAAA;AAEvD,eAAO,MAAM,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAe,CAAA"}
|
package/out/ark.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JsObjects, Parsing, TsKeywords, Validation } from "@arktype/schema";
|
|
2
|
+
import { Scope } from "./scope.js";
|
|
3
|
+
export const tsGenerics = {};
|
|
4
|
+
export const ark = Scope.root({
|
|
5
|
+
...TsKeywords.resolutions,
|
|
6
|
+
...JsObjects.resolutions,
|
|
7
|
+
...Validation.resolutions,
|
|
8
|
+
// TODO: fix
|
|
9
|
+
...tsGenerics,
|
|
10
|
+
parse: Parsing.resolutions
|
|
11
|
+
}).toAmbient();
|
|
12
|
+
export const arktypes = ark.export();
|
|
13
|
+
export const scope = ark.scope;
|
|
14
|
+
export const type = ark.type;
|
|
15
|
+
// TODO: cast needed?
|
|
16
|
+
export const match = ark.match;
|
|
17
|
+
export const define = ark.define;
|
|
18
|
+
export const declare = ark.declare;
|
|
19
|
+
//# sourceMappingURL=ark.js.map
|
package/out/ark.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ark.js","sourceRoot":"","sources":["../ark.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,UAAU,EAEV,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,KAAK,EAAiC,MAAM,YAAY,CAAA;AA4CjE,MAAM,CAAC,MAAM,UAAU,GAAG,EAAmC,CAAA;AAE7D,MAAM,CAAC,MAAM,GAAG,GAA0B,KAAK,CAAC,IAAI,CAAC;IACpD,GAAG,UAAU,CAAC,WAAW;IACzB,GAAG,SAAS,CAAC,WAAW;IACxB,GAAG,UAAU,CAAC,WAAW;IACzB,YAAY;IACZ,GAAG,UAAU;IACb,KAAK,EAAE,OAAO,CAAC,WAA+C;CAC9D,CAAC,CAAC,SAAS,EAAW,CAAA;AAEvB,MAAM,CAAC,MAAM,QAAQ,GAA2B,GAAG,CAAC,MAAM,EAAE,CAAA;AAY5D,MAAM,CAAC,MAAM,KAAK,GAAyB,GAAG,CAAC,KAAc,CAAA;AAE7D,MAAM,CAAC,MAAM,IAAI,GAAoB,GAAG,CAAC,IAAI,CAAA;AAE7C,qBAAqB;AACrB,MAAM,CAAC,MAAM,KAAK,GAAqB,GAAG,CAAC,KAAc,CAAA;AAQzD,MAAM,CAAC,MAAM,MAAM,GAA0B,GAAG,CAAC,MAAM,CAAA;AAEvD,MAAM,CAAC,MAAM,OAAO,GAA2B,GAAG,CAAC,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arkConfig.d.ts","sourceRoot":"","sources":["../arkConfig.ts"],"names":[],"mappings":""}
|
package/out/arkConfig.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-restricted-imports */
|
|
2
|
+
import { configure } from "@arktype/schema/config";
|
|
3
|
+
// import { type } from "arktype"
|
|
4
|
+
// const user = type("string")
|
|
5
|
+
configure({
|
|
6
|
+
domain: {
|
|
7
|
+
description: (inner) => `my special ${inner.domain}`
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=arkConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arkConfig.js","sourceRoot":"","sources":["../arkConfig.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,iCAAiC;AAEjC,8BAA8B;AAE9B,SAAS,CAAC;IACT,MAAM,EAAE;QACP,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,KAAK,CAAC,MAAM,EAAE;KACpD;CACD,CAAC,CAAA"}
|
package/out/main.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ArkErrors as ArkErrors, type ArkTypeError as ArkTypeError } from "@arktype/schema";
|
|
2
|
+
export type { Out, is } from "@arktype/schema";
|
|
3
|
+
export { ark, arktypes, declare, define, match, scope, type, type Ark } from "./ark.js";
|
|
4
|
+
export type { Module, Scope } from "./scope.js";
|
|
5
|
+
export { Type } from "./type.js";
|
|
6
|
+
export type { inferTypeRoot, validateTypeRoot } from "./type.js";
|
|
7
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,IAAI,SAAS,EACtB,KAAK,YAAY,IAAI,YAAY,EACjC,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EACN,GAAG,EACH,QAAQ,EACR,OAAO,EACP,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,KAAK,GAAG,EACR,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA"}
|
package/out/main.js
ADDED
package/out/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../main.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,IAAI,SAAS,EAEtB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EACN,GAAG,EACH,QAAQ,EACR,OAAO,EACP,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EAEJ,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA"}
|