arktype 2.0.0-dev.7 → 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__/array.test.ts +23 -25
- package/__tests__/config.test.ts +19 -8
- package/__tests__/examples.test.ts +3 -3
- package/__tests__/imports.test.ts +18 -12
- package/__tests__/instanceof.test.ts +7 -7
- package/__tests__/intersection.test.ts +2 -2
- package/__tests__/keyTraversal.test.ts +15 -15
- package/__tests__/keywords.test.ts +50 -37
- package/__tests__/literal.test.ts +30 -14
- package/__tests__/match.bench.ts +6 -6
- package/__tests__/narrow.test.ts +18 -24
- package/__tests__/objectLiteral.test.ts +134 -11
- package/__tests__/operator.bench.ts +4 -4
- package/__tests__/{morph.test.ts → pipe.test.ts} +136 -75
- package/__tests__/scope.test.ts +202 -15
- package/__tests__/traverse.test.ts +45 -36
- package/__tests__/type.test.ts +8 -10
- package/ark.ts +14 -11
- package/generic.ts +8 -6
- package/match.ts +59 -70
- package/out/ark.d.ts +5 -5
- package/out/ark.js +4 -5
- package/out/ark.js.map +1 -1
- package/out/generic.d.ts +0 -1
- package/out/generic.js +8 -7
- package/out/generic.js.map +1 -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 +50 -57
- package/out/match.js.map +1 -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 +5 -6
- package/out/parser/generic.js +4 -6
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +1 -2
- package/out/parser/objectLiteral.js +17 -11
- 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 +4 -5
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +0 -1
- package/out/parser/string/reduce/dynamic.js +4 -9
- package/out/parser/string/reduce/dynamic.js.map +1 -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 +2 -5
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -17
- package/out/parser/string/shift/operand/enclosed.js +6 -9
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +5 -6
- package/out/parser/string/shift/operand/genericArgs.js +4 -6
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -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 +6 -7
- package/out/parser/string/shift/operand/unenclosed.js +6 -13
- 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 +4 -9
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -2
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/divisor.js.map +1 -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 +2 -5
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +0 -1
- package/out/parser/string/string.js +1 -3
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +1 -2
- package/out/parser/tuple.js +12 -16
- package/out/parser/tuple.js.map +1 -1
- package/out/scope.d.ts +12 -12
- package/out/scope.js +16 -38
- package/out/scope.js.map +1 -1
- package/out/type.d.ts +38 -19
- package/out/type.js +32 -2
- package/out/type.js.map +1 -1
- package/package.json +6 -4
- package/parser/generic.ts +13 -14
- package/parser/objectLiteral.ts +25 -11
- package/parser/semantic/validate.ts +2 -3
- package/parser/string/reduce/dynamic.ts +7 -10
- package/parser/string/shift/operand/date.ts +3 -6
- package/parser/string/shift/operand/enclosed.ts +8 -8
- package/parser/string/shift/operand/genericArgs.ts +8 -8
- package/parser/string/shift/operand/unenclosed.ts +15 -25
- package/parser/string/shift/operator/bounds.ts +7 -9
- package/parser/string/shift/operator/divisor.ts +2 -3
- package/parser/string/shift/scanner.ts +2 -4
- package/parser/string/string.ts +2 -3
- package/parser/tuple.ts +15 -16
- package/scope.ts +39 -57
- package/type.ts +151 -35
- 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__/array.test.ts
CHANGED
|
@@ -14,15 +14,15 @@ contextualize(
|
|
|
14
14
|
const t = type("string[]")
|
|
15
15
|
attest<string[]>(t.infer)
|
|
16
16
|
attest(t.allows([])).equals(true)
|
|
17
|
-
attest(t([])
|
|
17
|
+
attest(t([])).snap([])
|
|
18
18
|
attest(t.allows(["foo", "bar"])).equals(true)
|
|
19
|
-
attest(t(["foo", "bar"])
|
|
19
|
+
attest(t(["foo", "bar"])).snap(["foo", "bar"])
|
|
20
20
|
attest(t.allows(["foo", "bar", 5])).equals(false)
|
|
21
|
-
attest(t(["foo", "bar", 5]).
|
|
21
|
+
attest(t(["foo", "bar", 5]).toString()).snap(
|
|
22
22
|
"value at [2] must be a string (was number)"
|
|
23
23
|
)
|
|
24
24
|
attest(t.allows([5, "foo", "bar"])).equals(false)
|
|
25
|
-
attest(t([5, "foo", "bar"]).
|
|
25
|
+
attest(t([5, "foo", "bar"]).toString()).snap(
|
|
26
26
|
"value at [0] must be a string (was number)"
|
|
27
27
|
)
|
|
28
28
|
})
|
|
@@ -31,15 +31,15 @@ contextualize(
|
|
|
31
31
|
const t = type("string[][]")
|
|
32
32
|
attest<string[][]>(t.infer)
|
|
33
33
|
attest(t.allows([])).equals(true)
|
|
34
|
-
attest(t([])
|
|
34
|
+
attest(t([])).snap([])
|
|
35
35
|
attest(t.allows([["foo"]])).equals(true)
|
|
36
|
-
attest(t([["foo"]])
|
|
36
|
+
attest(t([["foo"]])).snap([["foo"]])
|
|
37
37
|
attest(t.allows(["foo"])).equals(false)
|
|
38
|
-
attest(t(["foo"]).
|
|
38
|
+
attest(t(["foo"]).toString()).snap(
|
|
39
39
|
"value at [0] must be an array (was string)"
|
|
40
40
|
)
|
|
41
41
|
attest(t.allows([["foo", 5]])).equals(false)
|
|
42
|
-
attest(t([["foo", 5]]).
|
|
42
|
+
attest(t([["foo", 5]]).toString()).snap(
|
|
43
43
|
"value at [0][1] must be a string (was number)"
|
|
44
44
|
)
|
|
45
45
|
})
|
|
@@ -79,23 +79,21 @@ contextualize(
|
|
|
79
79
|
const t = type(["string", "number"])
|
|
80
80
|
attest<[string, number]>(t.infer)
|
|
81
81
|
attest(t.allows(["", 0])).equals(true)
|
|
82
|
-
attest(t(["", 0])
|
|
82
|
+
attest(t(["", 0])).snap(["", 0])
|
|
83
83
|
attest(t.allows([true, 0])).equals(false)
|
|
84
|
-
attest(t([true, 0]).
|
|
84
|
+
attest(t([true, 0]).toString()).snap(
|
|
85
85
|
"value at [0] must be a string (was true)"
|
|
86
86
|
)
|
|
87
87
|
attest(t.allows([0, false])).equals(false)
|
|
88
|
-
attest(t([0, false]).
|
|
88
|
+
attest(t([0, false]).toString())
|
|
89
89
|
.snap(`value at [0] must be a string (was number)
|
|
90
90
|
value at [1] must be a number (was false)`)
|
|
91
91
|
// too short
|
|
92
92
|
attest(t.allows([""])).equals(false)
|
|
93
|
-
attest(t([""]).
|
|
94
|
-
'must be exactly length 2 (was [""])'
|
|
95
|
-
)
|
|
93
|
+
attest(t([""]).toString()).snap('must be exactly length 2 (was [""])')
|
|
96
94
|
// too long
|
|
97
95
|
attest(t.allows(["", 0, 1])).equals(false)
|
|
98
|
-
attest(t(["", 0, 1]).
|
|
96
|
+
attest(t(["", 0, 1]).toString()).snap(
|
|
99
97
|
'must be exactly length 2 (was ["",0,1])'
|
|
100
98
|
)
|
|
101
99
|
// non-array
|
|
@@ -111,7 +109,7 @@ value at [1] must be a number (was false)`)
|
|
|
111
109
|
length: 2,
|
|
112
110
|
0: "",
|
|
113
111
|
1: 0
|
|
114
|
-
}).
|
|
112
|
+
}).toString()
|
|
115
113
|
).snap("must be an array (was object)")
|
|
116
114
|
})
|
|
117
115
|
|
|
@@ -130,10 +128,10 @@ value at [1] must be a number (was false)`)
|
|
|
130
128
|
>(t.infer)
|
|
131
129
|
const valid: typeof t.infer = [["", 0], [{ a: 0n, b: [null] }]]
|
|
132
130
|
attest(t.allows(valid)).equals(true)
|
|
133
|
-
attest(t(valid)
|
|
131
|
+
attest(t(valid)).equals(valid)
|
|
134
132
|
const invalid = [["", 0], [{ a: 0n, b: [undefined] }]]
|
|
135
133
|
attest(t.allows(invalid)).equals(false)
|
|
136
|
-
attest(t(invalid).
|
|
134
|
+
attest(t(invalid).toString()).snap(
|
|
137
135
|
"value at [1][0].b[0] must be null (was undefined)"
|
|
138
136
|
)
|
|
139
137
|
})
|
|
@@ -141,12 +139,12 @@ value at [1] must be a number (was false)`)
|
|
|
141
139
|
it("optional tuple", () => {
|
|
142
140
|
const t = type(["string", "?"])
|
|
143
141
|
attest<[string?]>(t.infer)
|
|
144
|
-
attest(t([])
|
|
145
|
-
attest(t(["foo"])
|
|
146
|
-
attest(t([5]).
|
|
142
|
+
attest(t([])).equals([])
|
|
143
|
+
attest(t(["foo"])).equals(["foo"])
|
|
144
|
+
attest(t([5]).toString()).snap(
|
|
147
145
|
"value at [0] must be a string (was number)"
|
|
148
146
|
)
|
|
149
|
-
attest(t(["foo", "bar"]).
|
|
147
|
+
attest(t(["foo", "bar"]).toString()).snap(
|
|
150
148
|
"must be at most length 1 (was 2)"
|
|
151
149
|
)
|
|
152
150
|
})
|
|
@@ -161,8 +159,8 @@ value at [1] must be a number (was false)`)
|
|
|
161
159
|
it("spreads simple arrays", () => {
|
|
162
160
|
const wellRested = type(["string", "...", "number[]"])
|
|
163
161
|
attest<[string, ...number[]]>(wellRested.infer)
|
|
164
|
-
attest(wellRested(["foo"])
|
|
165
|
-
attest(wellRested(["foo", 1, 2])
|
|
162
|
+
attest(wellRested(["foo"])).equals(["foo"])
|
|
163
|
+
attest(wellRested(["foo", 1, 2])).equals(["foo", 1, 2])
|
|
166
164
|
})
|
|
167
165
|
|
|
168
166
|
it("spreads array expressions", () => {
|
|
@@ -386,7 +384,7 @@ value at [1] must be a number (was false)`)
|
|
|
386
384
|
// describe("traversal", () => {
|
|
387
385
|
// it("multiple errors", () => {
|
|
388
386
|
// const stringArray = type("string[]")
|
|
389
|
-
// attest(stringArray([1, 2]).
|
|
387
|
+
// attest(stringArray([1, 2]).toString()).snap(
|
|
390
388
|
// "Item at index 0 must be a string (was number)\nItem at index 1 must be a string (was number)"
|
|
391
389
|
// )
|
|
392
390
|
// })
|
package/__tests__/config.test.ts
CHANGED
|
@@ -12,11 +12,11 @@ contextualize(() => {
|
|
|
12
12
|
}).export()
|
|
13
13
|
attest<string>(types.a.infer)
|
|
14
14
|
attest(types.a.description).equals(description)
|
|
15
|
-
attest(types.a(1).
|
|
15
|
+
attest(types.a(1).toString()).snap(
|
|
16
16
|
"must be a series of characters (was number)"
|
|
17
17
|
)
|
|
18
18
|
attest<{ a: string }>(types.b.infer)
|
|
19
|
-
attest(types.b({ a: true }).
|
|
19
|
+
attest(types.b({ a: true }).toString()).snap(
|
|
20
20
|
"a must be a series of characters (was true)"
|
|
21
21
|
)
|
|
22
22
|
})
|
|
@@ -30,7 +30,7 @@ contextualize(() => {
|
|
|
30
30
|
attest(t.description).snap(
|
|
31
31
|
"{ monster: the number of dimensions in the monster group }"
|
|
32
32
|
)
|
|
33
|
-
attest(t({ monster: 196882 }).
|
|
33
|
+
attest(t({ monster: 196882 }).toString()).snap(
|
|
34
34
|
"monster must be the number of dimensions in the monster group (was 196882)"
|
|
35
35
|
)
|
|
36
36
|
})
|
|
@@ -38,13 +38,13 @@ contextualize(() => {
|
|
|
38
38
|
it("anonymous type config", () => {
|
|
39
39
|
const t = type(type("true", "@", { description: "unfalse" }))
|
|
40
40
|
attest<true>(t.infer)
|
|
41
|
-
attest(t(false).
|
|
41
|
+
attest(t(false).toString()).snap("must be unfalse (was false)")
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
it("anonymous type config at path", () => {
|
|
45
45
|
const unfalse = type("true", "@", { description: "unfalse" })
|
|
46
46
|
const t = type({ myKey: unfalse })
|
|
47
|
-
attest(t({ myKey: "500" }).
|
|
47
|
+
attest(t({ myKey: "500" }).toString()).snap(
|
|
48
48
|
`myKey must be unfalse (was "500")`
|
|
49
49
|
)
|
|
50
50
|
})
|
|
@@ -60,7 +60,7 @@ contextualize(() => {
|
|
|
60
60
|
myKey: () => type("false", "@", { description: "untrue" })
|
|
61
61
|
})
|
|
62
62
|
attest<{ myKey: false }>(t.infer)
|
|
63
|
-
attest(t({ myKey: true }).
|
|
63
|
+
attest(t({ myKey: true }).toString()).snap(
|
|
64
64
|
"myKey must be untrue (was true)"
|
|
65
65
|
)
|
|
66
66
|
})
|
|
@@ -76,10 +76,21 @@ contextualize(() => {
|
|
|
76
76
|
user({
|
|
77
77
|
name: "david",
|
|
78
78
|
age: true
|
|
79
|
-
}).
|
|
79
|
+
}).toString()
|
|
80
80
|
).snap("age must be a number (was true)")
|
|
81
81
|
|
|
82
82
|
// should give the shallow custom error
|
|
83
|
-
attest(user(null).
|
|
83
|
+
attest(user(null).toString()).snap("must be a valid user (was null)")
|
|
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)
|
|
84
95
|
})
|
|
85
96
|
})
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// version: string
|
|
7
7
|
// contributors?: string[]
|
|
8
8
|
// }
|
|
9
|
-
// attest(typeSnippet.
|
|
9
|
+
// attest(typeSnippet.toString()).snap(
|
|
10
10
|
// "contributors must be more than 1 items long (was 1)"
|
|
11
11
|
// )
|
|
12
12
|
// })
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// version?: number
|
|
20
20
|
// }
|
|
21
21
|
// }
|
|
22
|
-
// attest(typeSnippet.
|
|
22
|
+
// attest(typeSnippet.toString()).snap(
|
|
23
23
|
// "device/platform must be 'android' or 'ios' (was 'enigma')"
|
|
24
24
|
// )
|
|
25
25
|
// })
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
// // packages?: any[]
|
|
35
35
|
// // }[]
|
|
36
36
|
// // }
|
|
37
|
-
// // attest(scopeSnippet.
|
|
37
|
+
// // attest(scopeSnippet.toString()).snap(
|
|
38
38
|
// // "dependencies/0/dependencies/0/contributors/0/email must be a valid email (was 'david@sharktypeio')\ncontributors/0/email must be a valid email (was 'david@sharktypeio')"
|
|
39
39
|
// // )
|
|
40
40
|
// // })
|
|
@@ -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({
|
|
@@ -13,8 +13,8 @@ contextualize(
|
|
|
13
13
|
const expected = rawSchema(Error)
|
|
14
14
|
attest(t.json).equals(expected.json)
|
|
15
15
|
const e = new Error()
|
|
16
|
-
attest(t(e)
|
|
17
|
-
attest(t({}).
|
|
16
|
+
attest(t(e)).equals(e)
|
|
17
|
+
attest(t({}).toString()).snap("must be an Error (was object)")
|
|
18
18
|
})
|
|
19
19
|
it("inherited", () => {
|
|
20
20
|
const t = type(["instanceof", TypeError])
|
|
@@ -22,8 +22,8 @@ contextualize(
|
|
|
22
22
|
// for some reason the return of TypeError's constructor is actually
|
|
23
23
|
// inferred as Error? Disabling this check for now, seems like an anomaly.
|
|
24
24
|
// attest<TypeError>(t.infer)
|
|
25
|
-
attest(t(e)
|
|
26
|
-
attest(t(new Error()).
|
|
25
|
+
attest(t(e)).equals(e)
|
|
26
|
+
attest(t(new Error()).toString()).snap(
|
|
27
27
|
"must be an instance of TypeError (was Error)"
|
|
28
28
|
)
|
|
29
29
|
})
|
|
@@ -37,7 +37,7 @@ contextualize(
|
|
|
37
37
|
const t = type(["instanceof", Base])
|
|
38
38
|
attest<Base>(t.infer)
|
|
39
39
|
const sub = new Sub()
|
|
40
|
-
attest(t(sub)
|
|
40
|
+
attest(t(sub)).equals(sub)
|
|
41
41
|
})
|
|
42
42
|
it("multiple branches", () => {
|
|
43
43
|
const t = type(["instanceof", Date, Array])
|
|
@@ -59,8 +59,8 @@ contextualize(
|
|
|
59
59
|
attest(ark.infer).type.toString("ArkClass")
|
|
60
60
|
attest(ark.in.infer).type.toString("ArkClass")
|
|
61
61
|
const a = new ArkClass()
|
|
62
|
-
attest(ark(a)
|
|
63
|
-
attest(ark({}).
|
|
62
|
+
attest(ark(a)).equals(a)
|
|
63
|
+
attest(ark({}).toString()).snap(
|
|
64
64
|
"must be an instance of ArkClass (was object)"
|
|
65
65
|
)
|
|
66
66
|
})
|
|
@@ -42,9 +42,9 @@ contextualize(() => {
|
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
it("chained deep intersections", () => {
|
|
45
|
-
const b = type({ b: "boolean" }, "=>",
|
|
45
|
+
const b = type({ b: "boolean" }, "=>", o => [o.b])
|
|
46
46
|
const t = type({
|
|
47
|
-
a: ["string", "=>",
|
|
47
|
+
a: ["string", "=>", s => s.length]
|
|
48
48
|
})
|
|
49
49
|
.and({
|
|
50
50
|
// unable to inline this due to:
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
// a: "string"
|
|
7
7
|
// })
|
|
8
8
|
// const dataWithExtraneousB = getExtraneousB()
|
|
9
|
-
// attest(t(dataWithExtraneousB)
|
|
9
|
+
// attest(t(dataWithExtraneousB)).equals(dataWithExtraneousB)
|
|
10
10
|
// })
|
|
11
11
|
//
|
|
12
12
|
// it("invalid union", () => {
|
|
13
13
|
// const o = type([{ a: "string" }, "|", { b: "boolean" }]).configure({
|
|
14
14
|
// keys: "strict"
|
|
15
15
|
// })
|
|
16
|
-
// attest(o({ a: 2 }).
|
|
16
|
+
// attest(o({ a: 2 }).toString()).snap(
|
|
17
17
|
// 'a must be a string or removed (was {"a":2})'
|
|
18
18
|
// )
|
|
19
19
|
// })
|
|
@@ -22,22 +22,22 @@
|
|
|
22
22
|
// const t = type({
|
|
23
23
|
// a: "string"
|
|
24
24
|
// }).configure({ keys: "distilled" })
|
|
25
|
-
// attest(t({ a: "ok" })
|
|
26
|
-
// attest(t(getExtraneousB())
|
|
25
|
+
// attest(t({ a: "ok" })).equals({ a: "ok" })
|
|
26
|
+
// attest(t(getExtraneousB())).snap({ a: "ok" })
|
|
27
27
|
// })
|
|
28
28
|
//
|
|
29
29
|
// it("distilled array", () => {
|
|
30
30
|
// const o = type({ a: "email[]" }).configure({
|
|
31
31
|
// keys: "distilled"
|
|
32
32
|
// })
|
|
33
|
-
// attest(o({ a: ["shawn@arktype.io"] })
|
|
33
|
+
// attest(o({ a: ["shawn@arktype.io"] })).snap({
|
|
34
34
|
// a: ["shawn@arktype.io"]
|
|
35
35
|
// })
|
|
36
|
-
// attest(o({ a: ["notAnEmail"] }).
|
|
36
|
+
// attest(o({ a: ["notAnEmail"] }).toString()).snap(
|
|
37
37
|
// "a/0 must be a valid email (was 'notAnEmail')"
|
|
38
38
|
// )
|
|
39
39
|
// // can handle missing keys
|
|
40
|
-
// attest(o({ b: ["shawn"] }).
|
|
40
|
+
// attest(o({ b: ["shawn"] }).toString()).snap("a must be defined")
|
|
41
41
|
// })
|
|
42
42
|
//
|
|
43
43
|
// it("distilled union", () => {
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
// keys: "distilled"
|
|
46
46
|
// })
|
|
47
47
|
// // can distill to first branch
|
|
48
|
-
// attest(o({ a: "to", z: "bra" })
|
|
48
|
+
// attest(o({ a: "to", z: "bra" })).snap({ a: "to" })
|
|
49
49
|
// // can distill to second branch
|
|
50
|
-
// attest(o({ b: true, c: false })
|
|
50
|
+
// attest(o({ b: true, c: false })).snap({ b: true })
|
|
51
51
|
// // can handle missing keys
|
|
52
|
-
// attest(o({ a: 2 }).
|
|
52
|
+
// attest(o({ a: 2 }).toString()).snap(
|
|
53
53
|
// 'a must be a string or b must be defined (was {"a":2})'
|
|
54
54
|
// )
|
|
55
55
|
// })
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
// const t = type({
|
|
59
59
|
// a: "string"
|
|
60
60
|
// }).configure({ keys: "strict" })
|
|
61
|
-
// attest(t({ a: "ok" })
|
|
62
|
-
// attest(t(getExtraneousB()).
|
|
61
|
+
// attest(t({ a: "ok" })).equals({ a: "ok" })
|
|
62
|
+
// attest(t(getExtraneousB()).toString()).snap("b must be removed")
|
|
63
63
|
// })
|
|
64
64
|
//
|
|
65
65
|
// it("strict array", () => {
|
|
66
66
|
// const o = type({ a: "string[]" }).configure({
|
|
67
67
|
// keys: "strict"
|
|
68
68
|
// })
|
|
69
|
-
// attest(o({ a: ["shawn"] })
|
|
70
|
-
// attest(o({ a: [2] }).
|
|
69
|
+
// attest(o({ a: ["shawn"] })).snap({ a: ["shawn"] })
|
|
70
|
+
// attest(o({ a: [2] }).toString()).snap(
|
|
71
71
|
// "a/0 must be a string (was number)"
|
|
72
72
|
// )
|
|
73
|
-
// attest(o({ b: ["shawn"] }).
|
|
73
|
+
// attest(o({ b: ["shawn"] }).toString()).snap(
|
|
74
74
|
// "b must be removed\na must be defined"
|
|
75
75
|
// )
|
|
76
76
|
// })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { attest, contextualize } from "@arktype/attest"
|
|
2
2
|
import { rawSchema } from "@arktype/schema"
|
|
3
|
-
import { type } from "arktype"
|
|
3
|
+
import { ark, type } from "arktype"
|
|
4
4
|
|
|
5
5
|
contextualize(
|
|
6
6
|
"jsObjects",
|
|
@@ -28,7 +28,7 @@ contextualize(
|
|
|
28
28
|
*/
|
|
29
29
|
const string = type("string")
|
|
30
30
|
attest<string>(string.infer)
|
|
31
|
-
attest(string("string")
|
|
31
|
+
attest(string("string")).snap("string")
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
it("any", () => {
|
|
@@ -39,6 +39,12 @@ contextualize(
|
|
|
39
39
|
attest<any>(any.infer)
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
+
it("any in expression", () => {
|
|
43
|
+
const t = type("string&any")
|
|
44
|
+
attest<any>(t.infer)
|
|
45
|
+
attest(t.json).equals(ark.string.json)
|
|
46
|
+
})
|
|
47
|
+
|
|
42
48
|
it("boolean", () => {
|
|
43
49
|
const boolean = type("boolean")
|
|
44
50
|
attest<boolean>(boolean.infer)
|
|
@@ -59,6 +65,13 @@ contextualize(
|
|
|
59
65
|
attest(never.json).equals(expected.json)
|
|
60
66
|
})
|
|
61
67
|
|
|
68
|
+
// TODO: ??
|
|
69
|
+
it("never in union", () => {
|
|
70
|
+
const t = type("string|never")
|
|
71
|
+
attest<string>(t.infer)
|
|
72
|
+
attest(t.json).equals(ark.string.json)
|
|
73
|
+
})
|
|
74
|
+
|
|
62
75
|
it("unknown", () => {
|
|
63
76
|
const expected = rawSchema({})
|
|
64
77
|
// should be equivalent to an unconstrained predicate
|
|
@@ -78,84 +91,84 @@ contextualize(
|
|
|
78
91
|
// describe("validation", () => {
|
|
79
92
|
// it("integer", () => {
|
|
80
93
|
// const integer = type("integer")
|
|
81
|
-
// attest(integer(123)
|
|
82
|
-
// attest(integer("123").
|
|
94
|
+
// attest(integer(123)).equals(123)
|
|
95
|
+
// attest(integer("123").toString()).equals(
|
|
83
96
|
// "must be a number (was string)"
|
|
84
97
|
// )
|
|
85
|
-
// attest(integer(12.12).
|
|
98
|
+
// attest(integer(12.12).toString()).equals(
|
|
86
99
|
// "must be an integer (was 12.12)"
|
|
87
100
|
// )
|
|
88
101
|
// })
|
|
89
102
|
// it("alpha", () => {
|
|
90
103
|
// const alpha = type("alpha")
|
|
91
|
-
// attest(alpha("user")
|
|
92
|
-
// attest(alpha("user123").
|
|
104
|
+
// attest(alpha("user")).equals("user")
|
|
105
|
+
// attest(alpha("user123").toString()).equals(
|
|
93
106
|
// "must be only letters (was 'user123')"
|
|
94
107
|
// )
|
|
95
108
|
// })
|
|
96
109
|
// it("alphanumeric", () => {
|
|
97
110
|
// const alphanumeric = type("alphanumeric")
|
|
98
|
-
// attest(alphanumeric("user123")
|
|
99
|
-
// attest(alphanumeric("user")
|
|
100
|
-
// attest(alphanumeric("123")
|
|
101
|
-
// attest(alphanumeric("abc@123").
|
|
111
|
+
// attest(alphanumeric("user123")).equals("user123")
|
|
112
|
+
// attest(alphanumeric("user")).equals("user")
|
|
113
|
+
// attest(alphanumeric("123")).equals("123")
|
|
114
|
+
// attest(alphanumeric("abc@123").toString()).equals(
|
|
102
115
|
// "must be only letters and digits (was 'abc@123')"
|
|
103
116
|
// )
|
|
104
117
|
// })
|
|
105
118
|
// it("lowercase", () => {
|
|
106
119
|
// const lowercase = type("lowercase")
|
|
107
|
-
// attest(lowercase("var")
|
|
108
|
-
// attest(lowercase("newVar").
|
|
120
|
+
// attest(lowercase("var")).equals("var")
|
|
121
|
+
// attest(lowercase("newVar").toString()).equals(
|
|
109
122
|
// "must be only lowercase letters (was 'newVar')"
|
|
110
123
|
// )
|
|
111
124
|
// })
|
|
112
125
|
// it("uppercase", () => {
|
|
113
126
|
// const uppercase = type("uppercase")
|
|
114
|
-
// attest(uppercase("VAR")
|
|
115
|
-
// attest(uppercase("CONST_VAR").
|
|
127
|
+
// attest(uppercase("VAR")).equals("VAR")
|
|
128
|
+
// attest(uppercase("CONST_VAR").toString()).equals(
|
|
116
129
|
// "must be only uppercase letters (was 'CONST_VAR')"
|
|
117
130
|
// )
|
|
118
|
-
// attest(uppercase("myVar").
|
|
131
|
+
// attest(uppercase("myVar").toString()).equals(
|
|
119
132
|
// "must be only uppercase letters (was 'myVar')"
|
|
120
133
|
// )
|
|
121
134
|
// })
|
|
122
135
|
// it("email", () => {
|
|
123
136
|
// const email = type("email")
|
|
124
|
-
// attest(email("shawn@mail.com")
|
|
125
|
-
// attest(email("shawn@email").
|
|
137
|
+
// attest(email("shawn@mail.com")).equals("shawn@mail.com")
|
|
138
|
+
// attest(email("shawn@email").toString()).equals(
|
|
126
139
|
// "must be a valid email (was 'shawn@email')"
|
|
127
140
|
// )
|
|
128
141
|
// })
|
|
129
142
|
// it("uuid", () => {
|
|
130
143
|
// const uuid = type("uuid")
|
|
131
|
-
// attest(uuid("f70b8242-dd57-4e6b-b0b7-649d997140a0")
|
|
144
|
+
// attest(uuid("f70b8242-dd57-4e6b-b0b7-649d997140a0")).equals(
|
|
132
145
|
// "f70b8242-dd57-4e6b-b0b7-649d997140a0"
|
|
133
146
|
// )
|
|
134
|
-
// attest(uuid("1234").
|
|
147
|
+
// attest(uuid("1234").toString()).equals(
|
|
135
148
|
// "must be a valid UUID (was '1234')"
|
|
136
149
|
// )
|
|
137
150
|
// })
|
|
138
151
|
// it("parsedNumber", () => {
|
|
139
152
|
// const parsedNumber = type("parsedNumber")
|
|
140
|
-
// attest(parsedNumber("5")
|
|
141
|
-
// attest(parsedNumber("5.5")
|
|
142
|
-
// attest(parsedNumber("five").
|
|
153
|
+
// attest(parsedNumber("5")).equals(5)
|
|
154
|
+
// attest(parsedNumber("5.5")).equals(5.5)
|
|
155
|
+
// attest(parsedNumber("five").toString()).equals(
|
|
143
156
|
// "must be a well-formed numeric string (was 'five')"
|
|
144
157
|
// )
|
|
145
158
|
// })
|
|
146
159
|
// it("parsedInteger", () => {
|
|
147
160
|
// const parsedInteger = type("parsedInteger")
|
|
148
|
-
// attest(parsedInteger("5")
|
|
149
|
-
// attest(parsedInteger("5.5").
|
|
161
|
+
// attest(parsedInteger("5")).equals(5)
|
|
162
|
+
// attest(parsedInteger("5.5").toString()).equals(
|
|
150
163
|
// "must be a well-formed integer string (was '5.5')"
|
|
151
164
|
// )
|
|
152
|
-
// attest(parsedInteger("five").
|
|
165
|
+
// attest(parsedInteger("five").toString()).equals(
|
|
153
166
|
// "must be a well-formed integer string (was 'five')"
|
|
154
167
|
// )
|
|
155
|
-
// attest(parsedInteger(5).
|
|
168
|
+
// attest(parsedInteger(5).toString()).equals(
|
|
156
169
|
// "must be a string (was number)"
|
|
157
170
|
// )
|
|
158
|
-
// attest(parsedInteger("9007199254740992").
|
|
171
|
+
// attest(parsedInteger("9007199254740992").toString()).equals(
|
|
159
172
|
// "must be an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER (was '9007199254740992')"
|
|
160
173
|
// )
|
|
161
174
|
// })
|
|
@@ -164,37 +177,37 @@ contextualize(
|
|
|
164
177
|
// attest(parsedDate("5/21/1993").out?.toDateString()).equals(
|
|
165
178
|
// "Fri May 21 1993"
|
|
166
179
|
// )
|
|
167
|
-
// attest(parsedDate("foo").
|
|
180
|
+
// attest(parsedDate("foo").toString()).equals(
|
|
168
181
|
// "must be a valid date (was 'foo')"
|
|
169
182
|
// )
|
|
170
|
-
// attest(parsedDate(5).
|
|
183
|
+
// attest(parsedDate(5).toString()).equals(
|
|
171
184
|
// "must be a string (was number)"
|
|
172
185
|
// )
|
|
173
186
|
// })
|
|
174
187
|
// it("json", () => {
|
|
175
188
|
// const json = type("json")
|
|
176
|
-
// attest(json('{"a": "hello"}')
|
|
177
|
-
// attest(json(123).
|
|
189
|
+
// attest(json('{"a": "hello"}')).equals({ a: "hello" })
|
|
190
|
+
// attest(json(123).toString()).equals(
|
|
178
191
|
// "must be a JSON-parsable string (was number)"
|
|
179
192
|
// )
|
|
180
193
|
// })
|
|
181
194
|
// it("credit card", () => {
|
|
182
195
|
// const validCC = "5489582921773376"
|
|
183
|
-
// attest(ark.creditCard(validCC)
|
|
196
|
+
// attest(ark.creditCard(validCC)).equals(validCC)
|
|
184
197
|
// // Regex validation
|
|
185
|
-
// attest(ark.creditCard("0".repeat(16)).
|
|
198
|
+
// attest(ark.creditCard("0".repeat(16)).toString()).equals(
|
|
186
199
|
// "must be a valid credit card number (was '0000000000000000')"
|
|
187
200
|
// )
|
|
188
201
|
// // Luhn validation
|
|
189
202
|
// attest(
|
|
190
|
-
// ark.creditCard(validCC.slice(0, -1) + "0").
|
|
203
|
+
// ark.creditCard(validCC.slice(0, -1) + "0").toString()
|
|
191
204
|
// ).equals(
|
|
192
205
|
// "must be a valid credit card number (was '5489582921773370')"
|
|
193
206
|
// )
|
|
194
207
|
// })
|
|
195
208
|
// it("semver", () => {
|
|
196
|
-
// attest(ark.semver("1.0.0")
|
|
197
|
-
// attest(ark.semver("-1.0.0").
|
|
209
|
+
// attest(ark.semver("1.0.0")).equals("1.0.0")
|
|
210
|
+
// attest(ark.semver("-1.0.0").toString()).equals(
|
|
198
211
|
// "must be a valid semantic version (see https://semver.org/) (was '-1.0.0')"
|
|
199
212
|
// )
|
|
200
213
|
// })
|