arktype 2.0.0-dev.8 → 2.0.0-dev.9
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__/config.test.ts +11 -0
- package/__tests__/imports.test.ts +18 -12
- package/__tests__/literal.test.ts +30 -14
- package/__tests__/narrow.test.ts +2 -2
- package/__tests__/objectLiteral.test.ts +130 -7
- package/__tests__/pipe.test.ts +1 -1
- package/__tests__/scope.test.ts +197 -0
- package/__tests__/traverse.test.ts +13 -5
- package/out/ark.d.ts +1 -2
- package/out/ark.js +0 -1
- package/out/generic.d.ts +0 -1
- package/out/generic.js +0 -1
- package/out/main.d.ts +0 -1
- package/out/main.js +0 -1
- package/out/match.d.ts +0 -1
- package/out/match.js +0 -1
- package/out/module.d.ts +0 -1
- package/out/module.js +0 -1
- package/out/parser/definition.d.ts +1 -2
- package/out/parser/definition.js +0 -1
- package/out/parser/generic.d.ts +2 -3
- package/out/parser/generic.js +0 -1
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +1 -2
- package/out/parser/objectLiteral.js +15 -8
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +1 -2
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/divisor.d.ts +0 -1
- package/out/parser/semantic/divisor.js +0 -2
- package/out/parser/semantic/infer.d.ts +0 -1
- package/out/parser/semantic/infer.js +0 -2
- package/out/parser/semantic/utils.d.ts +0 -1
- package/out/parser/semantic/utils.js +0 -2
- package/out/parser/semantic/validate.d.ts +2 -3
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/reduce/dynamic.d.ts +0 -1
- package/out/parser/string/reduce/dynamic.js +0 -1
- package/out/parser/string/reduce/shared.d.ts +5 -18
- package/out/parser/string/reduce/shared.js +0 -1
- package/out/parser/string/reduce/static.d.ts +0 -1
- package/out/parser/string/reduce/static.js +0 -2
- package/out/parser/string/shift/operand/date.d.ts +2 -3
- package/out/parser/string/shift/operand/date.js +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -17
- package/out/parser/string/shift/operand/enclosed.js +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +1 -2
- package/out/parser/string/shift/operand/genericArgs.js +0 -1
- package/out/parser/string/shift/operand/operand.d.ts +0 -1
- package/out/parser/string/shift/operand/operand.js +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +2 -3
- package/out/parser/string/shift/operand/unenclosed.js +1 -3
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +1 -8
- package/out/parser/string/shift/operator/bounds.js +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -2
- package/out/parser/string/shift/operator/divisor.js +0 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -2
- package/out/parser/string/shift/operator/operator.js +0 -1
- package/out/parser/string/shift/scanner.d.ts +0 -1
- package/out/parser/string/shift/scanner.js +0 -1
- package/out/parser/string/string.d.ts +0 -1
- package/out/parser/string/string.js +0 -1
- package/out/parser/tuple.d.ts +1 -2
- package/out/parser/tuple.js +0 -1
- package/out/scope.d.ts +6 -6
- package/out/scope.js +6 -6
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +0 -1
- package/out/type.js +0 -1
- package/out/type.js.map +1 -1
- package/package.json +6 -4
- package/parser/generic.ts +2 -2
- package/parser/objectLiteral.ts +23 -7
- package/parser/string/shift/operand/unenclosed.ts +1 -2
- package/scope.ts +18 -12
- package/type.ts +1 -0
- package/__tests__/cyclic.test.ts +0 -148
- package/out/ark.d.ts.map +0 -1
- package/out/base.d.ts +0 -205
- package/out/base.d.ts.map +0 -1
- package/out/base.js +0 -320
- package/out/base.js.map +0 -1
- package/out/builtins/builtins.d.ts +0 -23
- package/out/builtins/builtins.d.ts.map +0 -1
- package/out/builtins/builtins.js +0 -15
- package/out/builtins/builtins.js.map +0 -1
- package/out/builtins/jsObjects.d.ts +0 -19
- package/out/builtins/jsObjects.d.ts.map +0 -1
- package/out/builtins/jsObjects.js +0 -18
- package/out/builtins/jsObjects.js.map +0 -1
- package/out/builtins/parsing.d.ts +0 -16
- package/out/builtins/parsing.d.ts.map +0 -1
- package/out/builtins/parsing.js +0 -62
- package/out/builtins/parsing.js.map +0 -1
- package/out/builtins/tsGenerics.d.ts +0 -2
- package/out/builtins/tsGenerics.d.ts.map +0 -1
- package/out/builtins/tsGenerics.js +0 -26
- package/out/builtins/tsGenerics.js.map +0 -1
- package/out/builtins/tsKeywords.d.ts +0 -23
- package/out/builtins/tsKeywords.d.ts.map +0 -1
- package/out/builtins/tsKeywords.js +0 -23
- package/out/builtins/tsKeywords.js.map +0 -1
- package/out/builtins/utils/creditCard.d.ts +0 -3
- package/out/builtins/utils/creditCard.d.ts.map +0 -1
- package/out/builtins/utils/creditCard.js +0 -35
- package/out/builtins/utils/creditCard.js.map +0 -1
- package/out/builtins/utils/date.d.ts +0 -41
- package/out/builtins/utils/date.d.ts.map +0 -1
- package/out/builtins/utils/date.js +0 -56
- package/out/builtins/utils/date.js.map +0 -1
- package/out/builtins/validation.d.ts +0 -19
- package/out/builtins/validation.d.ts.map +0 -1
- package/out/builtins/validation.js +0 -74
- package/out/builtins/validation.js.map +0 -1
- package/out/config.d.ts +0 -9
- package/out/config.d.ts.map +0 -1
- package/out/config.js +0 -18
- package/out/config.js.map +0 -1
- package/out/constraints/ast.d.ts +0 -287
- package/out/constraints/ast.d.ts.map +0 -1
- package/out/constraints/ast.js +0 -2
- package/out/constraints/ast.js.map +0 -1
- package/out/constraints/constraint.d.ts +0 -200
- package/out/constraints/constraint.d.ts.map +0 -1
- package/out/constraints/constraint.js +0 -25
- package/out/constraints/constraint.js.map +0 -1
- package/out/constraints/predicate.d.ts +0 -64
- package/out/constraints/predicate.d.ts.map +0 -1
- package/out/constraints/predicate.js +0 -52
- package/out/constraints/predicate.js.map +0 -1
- package/out/constraints/props/index.d.ts +0 -42
- package/out/constraints/props/index.d.ts.map +0 -1
- package/out/constraints/props/index.js +0 -56
- package/out/constraints/props/index.js.map +0 -1
- package/out/constraints/props/optional.d.ts +0 -37
- package/out/constraints/props/optional.d.ts.map +0 -1
- package/out/constraints/props/optional.js +0 -56
- package/out/constraints/props/optional.js.map +0 -1
- package/out/constraints/props/prop.d.ts +0 -49
- package/out/constraints/props/prop.d.ts.map +0 -1
- package/out/constraints/props/prop.js +0 -106
- package/out/constraints/props/prop.js.map +0 -1
- package/out/constraints/props/props.d.ts +0 -37
- package/out/constraints/props/props.d.ts.map +0 -1
- package/out/constraints/props/props.js +0 -121
- package/out/constraints/props/props.js.map +0 -1
- package/out/constraints/props/required.d.ts +0 -46
- package/out/constraints/props/required.d.ts.map +0 -1
- package/out/constraints/props/required.js +0 -81
- package/out/constraints/props/required.js.map +0 -1
- package/out/constraints/props/sequence.d.ts +0 -82
- package/out/constraints/props/sequence.d.ts.map +0 -1
- package/out/constraints/props/sequence.js +0 -376
- package/out/constraints/props/sequence.js.map +0 -1
- package/out/constraints/props/shared.d.ts +0 -3
- package/out/constraints/props/shared.d.ts.map +0 -1
- package/out/constraints/props/shared.js +0 -4
- package/out/constraints/props/shared.js.map +0 -1
- package/out/constraints/refinements/after.d.ts +0 -33
- package/out/constraints/refinements/after.d.ts.map +0 -1
- package/out/constraints/refinements/after.js +0 -36
- package/out/constraints/refinements/after.js.map +0 -1
- package/out/constraints/refinements/before.d.ts +0 -33
- package/out/constraints/refinements/before.d.ts.map +0 -1
- package/out/constraints/refinements/before.js +0 -43
- package/out/constraints/refinements/before.js.map +0 -1
- package/out/constraints/refinements/divisor.d.ts +0 -52
- package/out/constraints/refinements/divisor.d.ts.map +0 -1
- package/out/constraints/refinements/divisor.js +0 -52
- package/out/constraints/refinements/divisor.js.map +0 -1
- package/out/constraints/refinements/exactLength.d.ts +0 -45
- package/out/constraints/refinements/exactLength.d.ts.map +0 -1
- package/out/constraints/refinements/exactLength.js +0 -52
- package/out/constraints/refinements/exactLength.js.map +0 -1
- package/out/constraints/refinements/kinds.d.ts +0 -29
- package/out/constraints/refinements/kinds.d.ts.map +0 -1
- package/out/constraints/refinements/kinds.js +0 -17
- package/out/constraints/refinements/kinds.js.map +0 -1
- package/out/constraints/refinements/length.d.ts +0 -48
- package/out/constraints/refinements/length.d.ts.map +0 -1
- package/out/constraints/refinements/length.js +0 -53
- package/out/constraints/refinements/length.js.map +0 -1
- package/out/constraints/refinements/max.d.ts +0 -31
- package/out/constraints/refinements/max.d.ts.map +0 -1
- package/out/constraints/refinements/max.js +0 -35
- package/out/constraints/refinements/max.js.map +0 -1
- package/out/constraints/refinements/maxLength.d.ts +0 -32
- package/out/constraints/refinements/maxLength.d.ts.map +0 -1
- package/out/constraints/refinements/maxLength.js +0 -36
- package/out/constraints/refinements/maxLength.js.map +0 -1
- package/out/constraints/refinements/min.d.ts +0 -31
- package/out/constraints/refinements/min.d.ts.map +0 -1
- package/out/constraints/refinements/min.js +0 -28
- package/out/constraints/refinements/min.js.map +0 -1
- package/out/constraints/refinements/minLength.d.ts +0 -32
- package/out/constraints/refinements/minLength.d.ts.map +0 -1
- package/out/constraints/refinements/minLength.js +0 -33
- package/out/constraints/refinements/minLength.js.map +0 -1
- package/out/constraints/refinements/range.d.ts +0 -119
- package/out/constraints/refinements/range.d.ts.map +0 -1
- package/out/constraints/refinements/range.js +0 -89
- package/out/constraints/refinements/range.js.map +0 -1
- package/out/constraints/refinements/regex.d.ts +0 -47
- package/out/constraints/refinements/regex.d.ts.map +0 -1
- package/out/constraints/refinements/regex.js +0 -37
- package/out/constraints/refinements/regex.js.map +0 -1
- package/out/constraints/refinements/shared.d.ts +0 -20
- package/out/constraints/refinements/shared.d.ts.map +0 -1
- package/out/constraints/refinements/shared.js +0 -10
- package/out/constraints/refinements/shared.js.map +0 -1
- package/out/generic.d.ts.map +0 -1
- package/out/inference.d.ts +0 -137
- package/out/inference.d.ts.map +0 -1
- package/out/inference.js +0 -73
- package/out/inference.js.map +0 -1
- package/out/keywords/ark.d.ts +0 -70
- package/out/keywords/ark.d.ts.map +0 -1
- package/out/keywords/ark.js +0 -29
- package/out/keywords/ark.js.map +0 -1
- package/out/keywords/internal.d.ts +0 -13
- package/out/keywords/internal.d.ts.map +0 -1
- package/out/keywords/internal.js +0 -13
- package/out/keywords/internal.js.map +0 -1
- package/out/keywords/jsObject.d.ts +0 -20
- package/out/keywords/jsObject.d.ts.map +0 -1
- package/out/keywords/jsObject.js +0 -18
- package/out/keywords/jsObject.js.map +0 -1
- package/out/keywords/parsing.d.ts +0 -17
- package/out/keywords/parsing.d.ts.map +0 -1
- package/out/keywords/parsing.js +0 -64
- package/out/keywords/parsing.js.map +0 -1
- package/out/keywords/root.d.ts +0 -7
- package/out/keywords/root.d.ts.map +0 -1
- package/out/keywords/root.js +0 -4
- package/out/keywords/root.js.map +0 -1
- package/out/keywords/tsGenerics.d.ts +0 -2
- package/out/keywords/tsGenerics.d.ts.map +0 -1
- package/out/keywords/tsGenerics.js +0 -26
- package/out/keywords/tsGenerics.js.map +0 -1
- package/out/keywords/tsPrimitive.d.ts +0 -24
- package/out/keywords/tsPrimitive.d.ts.map +0 -1
- package/out/keywords/tsPrimitive.js +0 -25
- package/out/keywords/tsPrimitive.js.map +0 -1
- package/out/keywords/utils/creditCard.d.ts +0 -11
- package/out/keywords/utils/creditCard.d.ts.map +0 -1
- package/out/keywords/utils/creditCard.js +0 -35
- package/out/keywords/utils/creditCard.js.map +0 -1
- package/out/keywords/utils/date.d.ts +0 -45
- package/out/keywords/utils/date.d.ts.map +0 -1
- package/out/keywords/utils/date.js +0 -56
- package/out/keywords/utils/date.js.map +0 -1
- package/out/keywords/validation.d.ts +0 -20
- package/out/keywords/validation.d.ts.map +0 -1
- package/out/keywords/validation.js +0 -80
- package/out/keywords/validation.js.map +0 -1
- package/out/kinds.d.ts +0 -102
- package/out/kinds.d.ts.map +0 -1
- package/out/kinds.js +0 -29
- package/out/kinds.js.map +0 -1
- package/out/main.d.ts.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/module.d.ts.map +0 -1
- package/out/parse.d.ts +0 -29
- package/out/parse.d.ts.map +0 -1
- package/out/parse.js +0 -161
- package/out/parse.js.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/infer.d.ts.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/schema.d.ts +0 -175
- package/out/schema.d.ts.map +0 -1
- package/out/schema.js +0 -73
- package/out/schema.js.map +0 -1
- package/out/schemaScope.d.ts +0 -180
- package/out/schemaScope.d.ts.map +0 -1
- package/out/schemaScope.js +0 -235
- package/out/schemaScope.js.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/shared/compile.d.ts +0 -22
- package/out/shared/compile.d.ts.map +0 -1
- package/out/shared/compile.js +0 -79
- package/out/shared/compile.js.map +0 -1
- package/out/shared/context.d.ts +0 -54
- package/out/shared/context.d.ts.map +0 -1
- package/out/shared/context.js +0 -53
- package/out/shared/context.js.map +0 -1
- package/out/shared/declare.d.ts +0 -69
- package/out/shared/declare.d.ts.map +0 -1
- package/out/shared/declare.js +0 -2
- package/out/shared/declare.js.map +0 -1
- package/out/shared/disjoint.d.ts +0 -91
- package/out/shared/disjoint.d.ts.map +0 -1
- package/out/shared/disjoint.js +0 -110
- package/out/shared/disjoint.js.map +0 -1
- package/out/shared/errors.d.ts +0 -99
- package/out/shared/errors.d.ts.map +0 -1
- package/out/shared/errors.js +0 -108
- package/out/shared/errors.js.map +0 -1
- package/out/shared/implement.d.ts +0 -363
- package/out/shared/implement.d.ts.map +0 -1
- package/out/shared/implement.js +0 -68
- package/out/shared/implement.js.map +0 -1
- package/out/shared/inference.d.ts +0 -6
- package/out/shared/inference.d.ts.map +0 -1
- package/out/shared/inference.js +0 -5
- package/out/shared/inference.js.map +0 -1
- package/out/shared/intersections.d.ts +0 -60
- package/out/shared/intersections.d.ts.map +0 -1
- package/out/shared/intersections.js +0 -2
- package/out/shared/intersections.js.map +0 -1
- package/out/shared/traversal.d.ts +0 -62
- package/out/shared/traversal.d.ts.map +0 -1
- package/out/shared/traversal.js +0 -97
- package/out/shared/traversal.js.map +0 -1
- package/out/shared/utils.d.ts +0 -24
- package/out/shared/utils.d.ts.map +0 -1
- package/out/shared/utils.js +0 -15
- package/out/shared/utils.js.map +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/types/basis.d.ts +0 -47
- package/out/types/basis.d.ts.map +0 -1
- package/out/types/basis.js +0 -15
- package/out/types/basis.js.map +0 -1
- package/out/types/discriminate.d.ts +0 -34
- package/out/types/discriminate.d.ts.map +0 -1
- package/out/types/discriminate.js +0 -120
- package/out/types/discriminate.js.map +0 -1
- package/out/types/domain.d.ts +0 -57
- package/out/types/domain.d.ts.map +0 -1
- package/out/types/domain.js +0 -41
- package/out/types/domain.js.map +0 -1
- package/out/types/intersection.d.ts +0 -127
- package/out/types/intersection.d.ts.map +0 -1
- package/out/types/intersection.js +0 -379
- package/out/types/intersection.js.map +0 -1
- package/out/types/morph.d.ts +0 -157
- package/out/types/morph.d.ts.map +0 -1
- package/out/types/morph.js +0 -99
- package/out/types/morph.js.map +0 -1
- package/out/types/proto.d.ts +0 -51
- package/out/types/proto.d.ts.map +0 -1
- package/out/types/proto.js +0 -60
- package/out/types/proto.js.map +0 -1
- package/out/types/type.d.ts +0 -143
- package/out/types/type.d.ts.map +0 -1
- package/out/types/type.js +0 -123
- package/out/types/type.js.map +0 -1
- package/out/types/union.d.ts +0 -71
- package/out/types/union.d.ts.map +0 -1
- package/out/types/union.js +0 -379
- package/out/types/union.js.map +0 -1
- package/out/types/unit.d.ts +0 -45
- package/out/types/unit.d.ts.map +0 -1
- package/out/types/unit.js +0 -56
- package/out/types/unit.js.map +0 -1
- package/out/util.d.ts +0 -31
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -8
- package/out/util.js.map +0 -1
package/__tests__/config.test.ts
CHANGED
|
@@ -82,4 +82,15 @@ contextualize(() => {
|
|
|
82
82
|
// should give the shallow custom error
|
|
83
83
|
attest(user(null).toString()).snap("must be a valid user (was null)")
|
|
84
84
|
})
|
|
85
|
+
|
|
86
|
+
it("jitless", () => {
|
|
87
|
+
const types = scope(
|
|
88
|
+
{
|
|
89
|
+
fast: "false"
|
|
90
|
+
},
|
|
91
|
+
{ jitless: true }
|
|
92
|
+
).export()
|
|
93
|
+
|
|
94
|
+
attest(types.fast.raw.jit).equals(false)
|
|
95
|
+
})
|
|
85
96
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { attest, contextualize } from "@arktype/attest"
|
|
2
|
+
import { writeDuplicateAliasError } from "@arktype/schema"
|
|
2
3
|
import { lazily } from "@arktype/util"
|
|
3
4
|
import { type Module, scope, type } from "arktype"
|
|
4
5
|
import { writePrefixedPrivateReferenceMessage } from "../parser/semantic/validate.js"
|
|
@@ -39,18 +40,6 @@ contextualize(() => {
|
|
|
39
40
|
attest<{ a: 3 | 60 | "no" | "yes" | true }>(imported.infer)
|
|
40
41
|
})
|
|
41
42
|
|
|
42
|
-
// TODO: fix, tests for more duplicate scenarios
|
|
43
|
-
// it("duplicate alias", () => {
|
|
44
|
-
// attest(() =>
|
|
45
|
-
// scope({ a: "boolean" })
|
|
46
|
-
// .scope(
|
|
47
|
-
// // @ts-expect-error
|
|
48
|
-
// { a: "string" }
|
|
49
|
-
// )
|
|
50
|
-
// .export()
|
|
51
|
-
// ).throwsAndHasTypeError(writeDuplicateAliasesMessage("a"))
|
|
52
|
-
// })
|
|
53
|
-
|
|
54
43
|
it("import & export", () => {
|
|
55
44
|
const threeSixtyNoScope = scope({
|
|
56
45
|
three: "3",
|
|
@@ -109,6 +98,23 @@ contextualize(() => {
|
|
|
109
98
|
).throwsAndHasTypeError(writePrefixedPrivateReferenceMessage("#kekw"))
|
|
110
99
|
})
|
|
111
100
|
|
|
101
|
+
it("errors on public and private refrence with same name", () => {
|
|
102
|
+
attest(() =>
|
|
103
|
+
scope({
|
|
104
|
+
kekw: "1",
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
"#kekw": "1"
|
|
107
|
+
}).export()
|
|
108
|
+
).throwsAndHasTypeError(writeDuplicateAliasError("kekw"))
|
|
109
|
+
attest(() =>
|
|
110
|
+
scope({
|
|
111
|
+
// @ts-expect-error
|
|
112
|
+
"#kekw": "1",
|
|
113
|
+
kekw: "1"
|
|
114
|
+
}).export()
|
|
115
|
+
).throwsAndHasTypeError(writeDuplicateAliasError("kekw"))
|
|
116
|
+
})
|
|
117
|
+
|
|
112
118
|
// TODO: reenable
|
|
113
119
|
// it("generic", () => {
|
|
114
120
|
// const types = scope({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { attest, contextualize } from "@arktype/attest"
|
|
2
|
-
import {
|
|
2
|
+
import { printable, registeredReference } from "@arktype/util"
|
|
3
3
|
import { type } from "arktype"
|
|
4
4
|
|
|
5
5
|
contextualize(
|
|
@@ -11,28 +11,44 @@ contextualize(
|
|
|
11
11
|
attest(t.json).equals(type("5").json)
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
it("
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
it("symbol with description", () => {
|
|
15
|
+
// if another symbol with the description "ism" is used in a test,
|
|
16
|
+
// the snapshotted errors below could break, but I want to test the
|
|
17
|
+
// actual display format.
|
|
18
|
+
// if you're here for that reason, choose another symbol name :P
|
|
19
|
+
const ism = Symbol("ism")
|
|
20
|
+
const t = type(["===", ism])
|
|
21
|
+
attest(t(ism)).equals(ism)
|
|
22
|
+
|
|
23
|
+
// same with ick- don't use it
|
|
24
|
+
const ick = Symbol("ick")
|
|
25
|
+
|
|
26
|
+
attest(t(ick).toString()).snap("must be Symbol(ism) (was Symbol(ick))")
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it("anonymous symbol", () => {
|
|
30
|
+
const anon = Symbol()
|
|
31
|
+
// An anonymous symbol will definitely have a suffix so we need to
|
|
32
|
+
// get the name ahead of time
|
|
33
|
+
const anonName = printable(anon)
|
|
34
|
+
const t = type(["===", anon])
|
|
17
35
|
attest<symbol>(t.infer)
|
|
18
|
-
attest(t(
|
|
19
|
-
attest(t("test").toString()).
|
|
20
|
-
'must be (symbol anonymous) (was "test")'
|
|
21
|
-
)
|
|
36
|
+
attest(t(anon)).equals(anon)
|
|
37
|
+
attest(t("test").toString()).equals(`must be ${anonName} (was "test")`)
|
|
22
38
|
})
|
|
23
39
|
|
|
24
40
|
it("branches", () => {
|
|
25
41
|
const o = { ark: true }
|
|
26
|
-
const oReference =
|
|
42
|
+
const oReference = registeredReference(o)
|
|
27
43
|
const s = Symbol()
|
|
28
|
-
const sReference =
|
|
44
|
+
const sReference = registeredReference(s)
|
|
29
45
|
const t = type(["===", true, "foo", 5, 1n, null, undefined, o, s])
|
|
30
46
|
attest<
|
|
31
47
|
true | "foo" | 5 | 1n | null | undefined | { ark: boolean } | typeof s
|
|
32
48
|
>(t.infer)
|
|
33
49
|
attest(t.json).equals([
|
|
34
|
-
{ unit: sReference },
|
|
35
50
|
{ unit: oReference },
|
|
51
|
+
{ unit: sReference },
|
|
36
52
|
{ unit: "1n" },
|
|
37
53
|
{ unit: "foo" },
|
|
38
54
|
{ unit: "undefined" },
|
|
@@ -52,16 +68,16 @@ contextualize(
|
|
|
52
68
|
|
|
53
69
|
it("branches", () => {
|
|
54
70
|
const o = { ark: true }
|
|
55
|
-
const oReference =
|
|
71
|
+
const oReference = registeredReference(o)
|
|
56
72
|
const s = Symbol()
|
|
57
|
-
const sReference =
|
|
73
|
+
const sReference = registeredReference(s)
|
|
58
74
|
const t = type("===", "foo", 5, true, null, 1n, undefined, o, s)
|
|
59
75
|
attest<
|
|
60
76
|
true | "foo" | 5 | 1n | null | undefined | { ark: boolean } | typeof s
|
|
61
77
|
>(t.infer)
|
|
62
78
|
attest(t.json).equals([
|
|
63
|
-
{ unit: sReference },
|
|
64
79
|
{ unit: oReference },
|
|
80
|
+
{ unit: sReference },
|
|
65
81
|
{ unit: "1n" },
|
|
66
82
|
{ unit: "foo" },
|
|
67
83
|
{ unit: "undefined" },
|
package/__tests__/narrow.test.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { attest, contextualize } from "@arktype/attest"
|
|
2
2
|
import type { Narrowed, Out, of, string } from "@arktype/schema"
|
|
3
|
-
import {
|
|
3
|
+
import { registeredReference, type equals } from "@arktype/util"
|
|
4
4
|
import { type, type Type } from "arktype"
|
|
5
5
|
|
|
6
6
|
contextualize(() => {
|
|
7
7
|
it("implicit problem", () => {
|
|
8
8
|
const isOdd = (n: number) => n % 2 === 1
|
|
9
|
-
const isOddRef =
|
|
9
|
+
const isOddRef = registeredReference(isOdd)
|
|
10
10
|
const odd = type(["number", ":", isOdd])
|
|
11
11
|
attest<number>(odd.infer)
|
|
12
12
|
attest(odd.json).equals({ domain: "number", predicate: [isOddRef] })
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
writeUnboundableMessage,
|
|
5
5
|
writeUnresolvableMessage
|
|
6
6
|
} from "@arktype/schema"
|
|
7
|
-
import { printable,
|
|
7
|
+
import { printable, registeredReference } from "@arktype/util"
|
|
8
8
|
import { scope, type } from "arktype"
|
|
9
9
|
import { writeInvalidSpreadTypeMessage } from "../parser/objectLiteral.js"
|
|
10
10
|
|
|
@@ -42,7 +42,7 @@ contextualize(
|
|
|
42
42
|
|
|
43
43
|
it("symbol key", () => {
|
|
44
44
|
const s = Symbol()
|
|
45
|
-
const name =
|
|
45
|
+
const name = registeredReference(s)
|
|
46
46
|
const t = type({
|
|
47
47
|
[s]: "string"
|
|
48
48
|
})
|
|
@@ -89,9 +89,16 @@ contextualize(
|
|
|
89
89
|
attest<{ "a?": string }>(t.infer)
|
|
90
90
|
})
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
it("traverse optional", () => {
|
|
93
|
+
const o = type({ "a?": "string" })
|
|
94
|
+
attest(o({ a: "a" })).snap({ a: "a" })
|
|
95
|
+
attest(o({})).snap({})
|
|
96
|
+
attest(o({ a: 1 }).toString()).snap("a must be a string (was number)")
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// it("traverse strict optional", () => {
|
|
100
|
+
// // TODO: strict
|
|
101
|
+
// const o = type({ "a?": "string" })
|
|
95
102
|
// attest(o({ a: "a" })).snap({ a: "a" })
|
|
96
103
|
// attest(o({})).snap({})
|
|
97
104
|
// attest(o({ a: 1 }).toString()).snap("a must be a string (was number)")
|
|
@@ -217,19 +224,75 @@ contextualize(
|
|
|
217
224
|
},
|
|
218
225
|
"index",
|
|
219
226
|
() => {
|
|
220
|
-
it("index", () => {
|
|
227
|
+
it("string index", () => {
|
|
221
228
|
const o = type({ "[string]": "string" })
|
|
222
229
|
attest<{ [x: string]: string }>(o.infer)
|
|
230
|
+
attest(o.json).snap({
|
|
231
|
+
domain: "object",
|
|
232
|
+
index: [{ key: "string", value: "string" }]
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
attest(o({})).equals({})
|
|
236
|
+
attest(o({ a: "a", b: "b" })).equals({ a: "a", b: "b" })
|
|
237
|
+
|
|
238
|
+
const validWithSymbol = { a: "a", [Symbol()]: null }
|
|
239
|
+
attest(validWithSymbol).equals(validWithSymbol)
|
|
240
|
+
|
|
241
|
+
attest(o({ a: 1 }).toString()).snap("a must be a string (was number)")
|
|
242
|
+
attest(o({ a: true, b: false }).toString())
|
|
243
|
+
.snap(`a must be a string (was true)
|
|
244
|
+
b must be a string (was false)`)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it("symbol index", () => {
|
|
248
|
+
const o = type({ "[symbol]": "1" })
|
|
249
|
+
attest<{ [x: symbol]: 1 }>(o.infer)
|
|
250
|
+
attest(o.json).snap({
|
|
251
|
+
domain: "object",
|
|
252
|
+
index: [{ key: "symbol", value: { unit: 1 } }]
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
attest(o({})).equals({})
|
|
256
|
+
|
|
257
|
+
attest(o({ a: 999 })).unknown.snap({ a: 999 })
|
|
258
|
+
|
|
259
|
+
const zildjian = Symbol()
|
|
260
|
+
const zildjianName = printable(zildjian)
|
|
261
|
+
|
|
262
|
+
// I've been dope, suspenseful with a pencil
|
|
263
|
+
// Ever since...
|
|
264
|
+
const prince = Symbol()
|
|
265
|
+
const princeName = printable(prince)
|
|
266
|
+
|
|
267
|
+
attest(o({ [zildjian]: 1, [prince]: 1 })).equals({
|
|
268
|
+
[zildjian]: 1,
|
|
269
|
+
[prince]: 1
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
attest({ a: 0, [zildjian]: 1 }).equals({ a: 0, [zildjian]: 1 })
|
|
273
|
+
|
|
274
|
+
attest(o({ [zildjian]: 0 }).toString()).equals(
|
|
275
|
+
`value at [${zildjianName}] must be 1 (was 0)`
|
|
276
|
+
)
|
|
277
|
+
attest(o({ [prince]: null, [zildjian]: undefined }).toString())
|
|
278
|
+
.snap(`value at [${princeName}] must be 1 (was null)
|
|
279
|
+
value at [${zildjianName}] must be 1 (was undefined)`)
|
|
223
280
|
})
|
|
224
281
|
|
|
225
282
|
it("enumerable indexed union", () => {
|
|
226
283
|
const o = type({ "['foo' | 'bar']": "string" })
|
|
227
|
-
|
|
284
|
+
const expected = type({ foo: "string", bar: "string" })
|
|
285
|
+
attest<typeof expected>(o)
|
|
286
|
+
attest(o.json).equals(expected.json)
|
|
228
287
|
})
|
|
229
288
|
|
|
230
289
|
it("non-enumerable indexed union", () => {
|
|
231
290
|
const o = type({ "[string | symbol]": "string" })
|
|
232
291
|
attest<{ [x: string]: string; [x: symbol]: string }>(o.infer)
|
|
292
|
+
attest(o.json).snap({
|
|
293
|
+
domain: "object",
|
|
294
|
+
index: [{ key: ["string", "symbol"], value: "string" }]
|
|
295
|
+
})
|
|
233
296
|
})
|
|
234
297
|
|
|
235
298
|
it("multiple indexed", () => {
|
|
@@ -238,6 +301,35 @@ contextualize(
|
|
|
238
301
|
"[symbol]": "number"
|
|
239
302
|
})
|
|
240
303
|
attest<{ [x: string]: string; [x: symbol]: number }>(o.infer)
|
|
304
|
+
attest(o.json).snap({
|
|
305
|
+
domain: "object",
|
|
306
|
+
index: [
|
|
307
|
+
{ key: "string", value: "string" },
|
|
308
|
+
{ key: "symbol", value: "number" }
|
|
309
|
+
]
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
attest(o({})).equals({})
|
|
313
|
+
attest(o({ foo: "f" })).equals({ foo: "f" })
|
|
314
|
+
|
|
315
|
+
const sym = Symbol()
|
|
316
|
+
|
|
317
|
+
const symName = printable(sym)
|
|
318
|
+
|
|
319
|
+
const validWithStringsAndSymbols = {
|
|
320
|
+
str: "string",
|
|
321
|
+
[sym]: 8675309
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
attest(o(validWithStringsAndSymbols)).equals(validWithStringsAndSymbols)
|
|
325
|
+
|
|
326
|
+
attest(
|
|
327
|
+
o({
|
|
328
|
+
str: 100,
|
|
329
|
+
[sym]: "💯"
|
|
330
|
+
}).toString()
|
|
331
|
+
).snap(`str must be a string (was number)
|
|
332
|
+
value at [${symName}] must be a number (was string)`)
|
|
241
333
|
})
|
|
242
334
|
|
|
243
335
|
it("all key kinds", () => {
|
|
@@ -249,6 +341,25 @@ contextualize(
|
|
|
249
341
|
attest<{ [x: string]: string; required: "foo"; optional?: "bar" }>(
|
|
250
342
|
o.infer
|
|
251
343
|
)
|
|
344
|
+
attest(o.json).snap({
|
|
345
|
+
domain: "object",
|
|
346
|
+
prop: [
|
|
347
|
+
{ key: "optional", optional: true, value: { unit: "bar" } },
|
|
348
|
+
{ key: "required", value: { unit: "foo" } }
|
|
349
|
+
],
|
|
350
|
+
index: [{ key: "string", value: "string" }]
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
const valid: typeof o.infer = { required: "foo", other: "bar" }
|
|
354
|
+
attest(o(valid)).equals(valid)
|
|
355
|
+
attest(
|
|
356
|
+
o({
|
|
357
|
+
optional: "wrongString",
|
|
358
|
+
other: 0n
|
|
359
|
+
}).toString()
|
|
360
|
+
).snap(`optional must be "bar" (was "wrongString")
|
|
361
|
+
required must be "foo" (was missing)
|
|
362
|
+
other must be a string (was bigint)`)
|
|
252
363
|
})
|
|
253
364
|
|
|
254
365
|
it("index key from scope", () => {
|
|
@@ -261,6 +372,14 @@ contextualize(
|
|
|
261
372
|
type Key = symbol | "foo" | "bar" | "baz"
|
|
262
373
|
attest<Key>(types.key.infer)
|
|
263
374
|
attest<Record<Key, string>>(types.obj.infer)
|
|
375
|
+
|
|
376
|
+
const expected = type({ "[symbol]": "string" }).and({
|
|
377
|
+
foo: "string",
|
|
378
|
+
bar: "string",
|
|
379
|
+
baz: "string"
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
attest(types.obj.json).snap(expected.json)
|
|
264
383
|
})
|
|
265
384
|
|
|
266
385
|
it("syntax error in index definition", () => {
|
|
@@ -314,6 +433,10 @@ contextualize(
|
|
|
314
433
|
it("escaped index", () => {
|
|
315
434
|
const o = type({ "\\[string]": "string" })
|
|
316
435
|
attest<{ "[string]": string }>(o.infer)
|
|
436
|
+
attest(o.json).snap({
|
|
437
|
+
domain: "object",
|
|
438
|
+
prop: [{ key: "[string]", value: "string" }]
|
|
439
|
+
})
|
|
317
440
|
})
|
|
318
441
|
}
|
|
319
442
|
)
|
package/__tests__/pipe.test.ts
CHANGED
|
@@ -41,7 +41,7 @@ contextualize(() => {
|
|
|
41
41
|
attest(parsedUser(JSON.stringify(validUser))).equals(validUser)
|
|
42
42
|
const missingKey = { name: "David" }
|
|
43
43
|
attest(parsedUser(JSON.stringify(missingKey)).toString()).snap(
|
|
44
|
-
"age must be
|
|
44
|
+
"age must be a number (was missing)"
|
|
45
45
|
)
|
|
46
46
|
})
|
|
47
47
|
|
package/__tests__/scope.test.ts
CHANGED
|
@@ -174,4 +174,201 @@ contextualize(() => {
|
|
|
174
174
|
)
|
|
175
175
|
})
|
|
176
176
|
})
|
|
177
|
+
describe("cyclic", () => {
|
|
178
|
+
it("base", () => {
|
|
179
|
+
const types = scope({ a: { b: "b" }, b: { a: "a" } }).export()
|
|
180
|
+
|
|
181
|
+
const a = {} as { b: typeof b }
|
|
182
|
+
const b = { a }
|
|
183
|
+
a.b = b
|
|
184
|
+
|
|
185
|
+
attest(types.a(a)).equals(a)
|
|
186
|
+
attest(types.a({ b: { a: { b: { a: 5 } } } }).toString()).snap(
|
|
187
|
+
"b.a.b.a must be an object (was number)"
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
// Type hint displays as "..." on hitting cycle (or any if "noErrorTruncation" is true)
|
|
191
|
+
attest({} as typeof types.a.infer).type.toString.snap()
|
|
192
|
+
attest({} as typeof types.b.infer.a.b.a.b.a.b.a).type.toString.snap()
|
|
193
|
+
|
|
194
|
+
// @ts-expect-error
|
|
195
|
+
attest({} as typeof types.a.infer.b.a.b.c).type.errors.snap(
|
|
196
|
+
`Property 'c' does not exist on type '{ a: { b: ...; }; }'.`
|
|
197
|
+
)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
const getCyclicScope = () =>
|
|
201
|
+
scope({
|
|
202
|
+
package: {
|
|
203
|
+
name: "string",
|
|
204
|
+
"dependencies?": "package[]",
|
|
205
|
+
"contributors?": "contributor[]"
|
|
206
|
+
},
|
|
207
|
+
contributor: {
|
|
208
|
+
email: "email",
|
|
209
|
+
"packages?": "package[]"
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
type Package = ReturnType<typeof getCyclicScope>["infer"]["package"]
|
|
214
|
+
|
|
215
|
+
const getCyclicData = () => {
|
|
216
|
+
const packageData = {
|
|
217
|
+
name: "arktype",
|
|
218
|
+
dependencies: [{ name: "typescript" }],
|
|
219
|
+
contributors: [{ email: "david@arktype.io" }]
|
|
220
|
+
} satisfies Package
|
|
221
|
+
packageData.dependencies.push(packageData)
|
|
222
|
+
return packageData
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
it("cyclic union", () => {
|
|
226
|
+
const $ = scope({
|
|
227
|
+
a: { b: "b|false" },
|
|
228
|
+
b: { a: "a|true" }
|
|
229
|
+
})
|
|
230
|
+
attest($.infer).type.toString.snap(
|
|
231
|
+
"{ a: { b: false | { a: true | any; }; }; b: { a: true | { b: false | any; }; }; }"
|
|
232
|
+
)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
it("cyclic intersection", () => {
|
|
236
|
+
const $ = scope({
|
|
237
|
+
a: { b: "b&a" },
|
|
238
|
+
b: { a: "a&b" }
|
|
239
|
+
})
|
|
240
|
+
attest($.infer).type.toString.snap(
|
|
241
|
+
"{ a: { b: { a: { b: any; a: any; }; b: any; }; }; b: { a: { b: { a: any; b: any; }; a: any; }; }; }"
|
|
242
|
+
)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it("allows valid", () => {
|
|
246
|
+
const types = getCyclicScope().export()
|
|
247
|
+
const data = getCyclicData()
|
|
248
|
+
attest(types.package(data)).snap({
|
|
249
|
+
name: "arktype",
|
|
250
|
+
dependencies: [{ name: "typescript" }, "(cycle)" as never],
|
|
251
|
+
contributors: [{ email: "david@arktype.io" }]
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it("adds errors on invalid", () => {
|
|
256
|
+
const types = getCyclicScope().export()
|
|
257
|
+
const data = getCyclicData()
|
|
258
|
+
data.contributors[0].email = "ssalbdivad"
|
|
259
|
+
attest(types.package(data).toString()).snap(
|
|
260
|
+
'contributors[0].email must be a valid email (was "ssalbdivad")'
|
|
261
|
+
)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it("can include cyclic data in message", () => {
|
|
265
|
+
const data = getCyclicData()
|
|
266
|
+
const nonSelfDependent = getCyclicScope().type([
|
|
267
|
+
"package",
|
|
268
|
+
":",
|
|
269
|
+
p => !p.dependencies?.some(d => d.name === p.name)
|
|
270
|
+
])
|
|
271
|
+
attest(nonSelfDependent(data).toString()).snap(
|
|
272
|
+
'must be valid according to an anonymous predicate (was {"name":"arktype","dependencies":[{"name":"typescript"},"(cycle)"],"contributors":[{"email":"david@arktype.io"}]})'
|
|
273
|
+
)
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it("union cyclic reference", () => {
|
|
277
|
+
const types = scope({
|
|
278
|
+
a: {
|
|
279
|
+
b: "b"
|
|
280
|
+
},
|
|
281
|
+
b: {
|
|
282
|
+
a: "a|3"
|
|
283
|
+
}
|
|
284
|
+
}).export()
|
|
285
|
+
attest(types.a.infer).type.toString.snap("{ b: { a: 3 | any; }")
|
|
286
|
+
|
|
287
|
+
attest(types.a.json).snap({
|
|
288
|
+
domain: "object",
|
|
289
|
+
prop: [
|
|
290
|
+
{
|
|
291
|
+
key: "b",
|
|
292
|
+
value: {
|
|
293
|
+
domain: "object",
|
|
294
|
+
prop: [{ key: "a", value: ["$a", { unit: 3 }] }]
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
const valid: typeof types.a.infer = { b: { a: 3 } }
|
|
301
|
+
|
|
302
|
+
attest(types.a(valid)).equals(valid)
|
|
303
|
+
|
|
304
|
+
valid.b.a = valid
|
|
305
|
+
|
|
306
|
+
// check cyclic
|
|
307
|
+
attest(types.a(valid)).equals(valid)
|
|
308
|
+
|
|
309
|
+
attest(types.a({ b: { a: { b: { a: 4 } } } }).toString()).snap(
|
|
310
|
+
'b.a.b.a must be an object or 3 (was number, 4) or b.a must be 3 (was {"b":{"a":4}})'
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
attest(types.b.infer).type.toString.snap("{ a: 3 | { b: any; }; }")
|
|
314
|
+
attest(types.b.json).snap({
|
|
315
|
+
domain: "object",
|
|
316
|
+
prop: [{ key: "a", value: ["$a", { unit: 3 }] }]
|
|
317
|
+
})
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
it("intersect cyclic reference", () => {
|
|
321
|
+
const types = scope({
|
|
322
|
+
a: {
|
|
323
|
+
b: "b"
|
|
324
|
+
},
|
|
325
|
+
b: {
|
|
326
|
+
c: "a&b"
|
|
327
|
+
}
|
|
328
|
+
}).export()
|
|
329
|
+
attest(types.a.infer).type.toString.snap()
|
|
330
|
+
attest(types.b.infer).type.toString.snap()
|
|
331
|
+
|
|
332
|
+
const expectedCyclicJson =
|
|
333
|
+
types.a.raw.firstReferenceOfKindOrThrow("alias").json
|
|
334
|
+
|
|
335
|
+
attest(types.a.json).snap({
|
|
336
|
+
domain: "object",
|
|
337
|
+
prop: [
|
|
338
|
+
{
|
|
339
|
+
key: "b",
|
|
340
|
+
value: {
|
|
341
|
+
domain: "object",
|
|
342
|
+
prop: [
|
|
343
|
+
{
|
|
344
|
+
key: "c",
|
|
345
|
+
value: expectedCyclicJson
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
})
|
|
352
|
+
const a = {} as typeof types.a.infer
|
|
353
|
+
const b = { c: {} } as typeof types.b.infer
|
|
354
|
+
a.b = b
|
|
355
|
+
b.c.b = b
|
|
356
|
+
b.c.c = b.c
|
|
357
|
+
|
|
358
|
+
attest(types.a(a)).equals(a)
|
|
359
|
+
attest(types.a({ b: { c: {} } }).toString())
|
|
360
|
+
.snap(`b.c.b must be { c: a&b } (was missing)
|
|
361
|
+
b.c.c must be a&b (was missing)`)
|
|
362
|
+
|
|
363
|
+
attest(types.b.json).snap({
|
|
364
|
+
domain: "object",
|
|
365
|
+
prop: [
|
|
366
|
+
{
|
|
367
|
+
key: "c",
|
|
368
|
+
value: expectedCyclicJson
|
|
369
|
+
}
|
|
370
|
+
]
|
|
371
|
+
})
|
|
372
|
+
})
|
|
373
|
+
})
|
|
177
374
|
})
|
|
@@ -38,7 +38,9 @@ contextualize(() => {
|
|
|
38
38
|
name: "Shawn",
|
|
39
39
|
age: 99
|
|
40
40
|
})
|
|
41
|
-
attest(t({ name: "Shawn" }).toString()).snap(
|
|
41
|
+
attest(t({ name: "Shawn" }).toString()).snap(
|
|
42
|
+
"age must be a number (was missing)"
|
|
43
|
+
)
|
|
42
44
|
})
|
|
43
45
|
|
|
44
46
|
it("customized builtin problem", () => {
|
|
@@ -74,7 +76,9 @@ contextualize(() => {
|
|
|
74
76
|
const t = type({ bar: "boolean" }, "|", { foo: "string" })
|
|
75
77
|
attest(t({ foo: "ok" })).snap({ foo: "ok" })
|
|
76
78
|
attest(t({ bar: true })).snap({ bar: true })
|
|
77
|
-
attest(t({}).toString()).snap(
|
|
79
|
+
attest(t({}).toString()).snap(
|
|
80
|
+
"bar must be boolean (was missing) or foo must be a string (was missing)"
|
|
81
|
+
)
|
|
78
82
|
attest(t({ bar: "swapped", foo: true }).toString()).snap(
|
|
79
83
|
'bar must be boolean (was "swapped") or foo must be a string (was true)'
|
|
80
84
|
)
|
|
@@ -85,7 +89,7 @@ contextualize(() => {
|
|
|
85
89
|
attest(t({ key: { a: "ok" } })).snap({ key: { a: "ok" } })
|
|
86
90
|
attest(t({ key: { b: true } })).snap({ key: { b: true } })
|
|
87
91
|
attest(t({ key: {} }).toString()).snap(
|
|
88
|
-
"key.a must be
|
|
92
|
+
"key.a must be a string (was missing) or key.b must be boolean (was missing)"
|
|
89
93
|
)
|
|
90
94
|
})
|
|
91
95
|
|
|
@@ -94,7 +98,9 @@ contextualize(() => {
|
|
|
94
98
|
attest(t({ a: "ok" })).snap({ a: "ok" })
|
|
95
99
|
attest(t({ a: 5 })).snap({ a: 5 })
|
|
96
100
|
// value isn't present
|
|
97
|
-
attest(t({}).toString()).snap(
|
|
101
|
+
attest(t({}).toString()).snap(
|
|
102
|
+
"a must be a number, a string or null (was missing)"
|
|
103
|
+
)
|
|
98
104
|
// unsatisfying value
|
|
99
105
|
attest(t({ a: false }).toString()).snap(
|
|
100
106
|
"a must be a number, a string or null (was false)"
|
|
@@ -108,7 +114,9 @@ contextualize(() => {
|
|
|
108
114
|
c: { foo: "Function" },
|
|
109
115
|
d: "a|b|c"
|
|
110
116
|
}).export()
|
|
111
|
-
attest(types.d({}).toString()).snap(
|
|
117
|
+
attest(types.d({}).toString()).snap(
|
|
118
|
+
"foo must be a function, a number or a string (was missing)"
|
|
119
|
+
)
|
|
112
120
|
attest(types.d({ foo: null }).toString()).snap(
|
|
113
121
|
"foo must be a function, a number or a string (was null)"
|
|
114
122
|
)
|
package/out/ark.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type TsGenericsExports<$ = Ark> = {
|
|
|
12
12
|
"[K]": "V";
|
|
13
13
|
}, $>;
|
|
14
14
|
};
|
|
15
|
-
export declare const tsGenerics: Module<TsGenericsExports
|
|
15
|
+
export declare const tsGenerics: Module<TsGenericsExports>;
|
|
16
16
|
export declare const ambient: Scope<Ark>;
|
|
17
17
|
export declare const ark: Module<Ark>;
|
|
18
18
|
export declare const type: TypeParser<{}>;
|
|
@@ -26,4 +26,3 @@ export declare const match: MatchParser<{}>;
|
|
|
26
26
|
export declare const define: DefinitionParser<{}>;
|
|
27
27
|
export declare const declare: DeclarationParser<{}>;
|
|
28
28
|
export {};
|
|
29
|
-
//# sourceMappingURL=ark.d.ts.map
|
package/out/ark.js
CHANGED
package/out/generic.d.ts
CHANGED
package/out/generic.js
CHANGED
package/out/main.d.ts
CHANGED
|
@@ -4,4 +4,3 @@ export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
|
4
4
|
export { Module } from "./module.js";
|
|
5
5
|
export { scope, type Scope } from "./scope.js";
|
|
6
6
|
export { Type, type inferTypeRoot, type validateTypeRoot } from "./type.js";
|
|
7
|
-
//# sourceMappingURL=main.d.ts.map
|
package/out/main.js
CHANGED
package/out/match.d.ts
CHANGED
package/out/match.js
CHANGED