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
|
@@ -4,26 +4,26 @@ import { scope, type } from "arktype"
|
|
|
4
4
|
contextualize(() => {
|
|
5
5
|
it("divisible", () => {
|
|
6
6
|
const t = type("number%2")
|
|
7
|
-
attest(t(4)
|
|
8
|
-
attest(t(5).
|
|
7
|
+
attest(t(4)).snap(4)
|
|
8
|
+
attest(t(5).toString()).snap("must be a multiple of 2 (was 5)")
|
|
9
9
|
})
|
|
10
10
|
|
|
11
11
|
it("range", () => {
|
|
12
12
|
const t = type("number>2")
|
|
13
|
-
attest(t(3)
|
|
14
|
-
attest(t(2).
|
|
13
|
+
attest(t(3)).snap(3)
|
|
14
|
+
attest(t(2).toString()).snap("must be more than 2 (was 2)")
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
it("domain", () => {
|
|
18
18
|
const t = type("number")
|
|
19
|
-
attest(t(5)
|
|
20
|
-
attest(t("foo").
|
|
19
|
+
attest(t(5)).snap(5)
|
|
20
|
+
attest(t("foo").toString()).snap("must be a number (was string)")
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
it("regex", () => {
|
|
24
24
|
const t = type("/.*@arktype.io/")
|
|
25
|
-
attest(t("shawn@arktype.io")
|
|
26
|
-
attest(t("shawn@hotmail.com").
|
|
25
|
+
attest(t("shawn@arktype.io")).snap("shawn@arktype.io")
|
|
26
|
+
attest(t("shawn@hotmail.com").toString()).snap(
|
|
27
27
|
'must be matched by .*@arktype.io (was "shawn@hotmail.com")'
|
|
28
28
|
)
|
|
29
29
|
})
|
|
@@ -34,11 +34,13 @@ contextualize(() => {
|
|
|
34
34
|
age: "number",
|
|
35
35
|
"title?": "string"
|
|
36
36
|
})
|
|
37
|
-
attest(t({ name: "Shawn", age: 99 })
|
|
37
|
+
attest(t({ name: "Shawn", age: 99 })).snap({
|
|
38
38
|
name: "Shawn",
|
|
39
39
|
age: 99
|
|
40
40
|
})
|
|
41
|
-
attest(t({ name: "Shawn" }).
|
|
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", () => {
|
|
@@ -46,56 +48,61 @@ contextualize(() => {
|
|
|
46
48
|
{ isEven: "number%2" },
|
|
47
49
|
{
|
|
48
50
|
divisor: {
|
|
49
|
-
expected:
|
|
50
|
-
problem:
|
|
51
|
+
expected: ctx => `% ${ctx.rule} !== 0`,
|
|
52
|
+
problem: ctx => `${ctx.actual} ${ctx.expected}`
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
).export()
|
|
54
|
-
attest(types.isEven(3).
|
|
56
|
+
attest(types.isEven(3).toString()).snap("3 % 2 !== 0")
|
|
55
57
|
})
|
|
56
58
|
|
|
57
59
|
it("domains", () => {
|
|
58
60
|
const t = type("string|number[]")
|
|
59
|
-
attest(t([1])
|
|
60
|
-
attest(t("hello")
|
|
61
|
-
attest(t(2).
|
|
62
|
-
"must be a string or an array (was number)"
|
|
63
|
-
)
|
|
61
|
+
attest(t([1])).snap([1])
|
|
62
|
+
attest(t("hello")).snap("hello")
|
|
63
|
+
attest(t(2).toString()).snap("must be a string or an array (was number)")
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
it("tuple length", () => {
|
|
67
67
|
const t = type(["string", "number", "string", "string[]"])
|
|
68
68
|
const data: typeof t.infer = ["foo", 5, "boo", []]
|
|
69
|
-
attest(t(data)
|
|
70
|
-
attest(t(["hello"]).
|
|
69
|
+
attest(t(data)).equals(data)
|
|
70
|
+
attest(t(["hello"]).toString()).snap(
|
|
71
71
|
'must be exactly length 4 (was ["hello"])'
|
|
72
72
|
)
|
|
73
73
|
})
|
|
74
74
|
|
|
75
75
|
it("branches", () => {
|
|
76
|
-
const t = type(
|
|
77
|
-
attest(t({
|
|
78
|
-
attest(t({
|
|
79
|
-
attest(t({}).
|
|
76
|
+
const t = type({ bar: "boolean" }, "|", { foo: "string" })
|
|
77
|
+
attest(t({ foo: "ok" })).snap({ foo: "ok" })
|
|
78
|
+
attest(t({ bar: true })).snap({ bar: true })
|
|
79
|
+
attest(t({}).toString()).snap(
|
|
80
|
+
"bar must be boolean (was missing) or foo must be a string (was missing)"
|
|
81
|
+
)
|
|
82
|
+
attest(t({ bar: "swapped", foo: true }).toString()).snap(
|
|
83
|
+
'bar must be boolean (was "swapped") or foo must be a string (was true)'
|
|
84
|
+
)
|
|
80
85
|
})
|
|
81
86
|
|
|
82
87
|
it("branches at path", () => {
|
|
83
88
|
const t = type({ key: [{ a: "string" }, "|", { b: "boolean" }] })
|
|
84
|
-
attest(t({ key: { a: "ok" } })
|
|
85
|
-
attest(t({ key: { b: true } })
|
|
86
|
-
attest(t({ key: {} }).
|
|
87
|
-
"key.a must be
|
|
89
|
+
attest(t({ key: { a: "ok" } })).snap({ key: { a: "ok" } })
|
|
90
|
+
attest(t({ key: { b: true } })).snap({ key: { b: true } })
|
|
91
|
+
attest(t({ key: {} }).toString()).snap(
|
|
92
|
+
"key.a must be a string (was missing) or key.b must be boolean (was missing)"
|
|
88
93
|
)
|
|
89
94
|
})
|
|
90
95
|
|
|
91
96
|
it("switch", () => {
|
|
92
97
|
const t = type({ a: "string" }).or({ a: "null" }).or({ a: "number" })
|
|
93
|
-
attest(t({ a: "ok" })
|
|
94
|
-
attest(t({ a: 5 })
|
|
98
|
+
attest(t({ a: "ok" })).snap({ a: "ok" })
|
|
99
|
+
attest(t({ a: 5 })).snap({ a: 5 })
|
|
95
100
|
// value isn't present
|
|
96
|
-
attest(t({}).
|
|
101
|
+
attest(t({}).toString()).snap(
|
|
102
|
+
"a must be a number, a string or null (was missing)"
|
|
103
|
+
)
|
|
97
104
|
// unsatisfying value
|
|
98
|
-
attest(t({ a: false }).
|
|
105
|
+
attest(t({ a: false }).toString()).snap(
|
|
99
106
|
"a must be a number, a string or null (was false)"
|
|
100
107
|
)
|
|
101
108
|
})
|
|
@@ -107,15 +114,17 @@ contextualize(() => {
|
|
|
107
114
|
c: { foo: "Function" },
|
|
108
115
|
d: "a|b|c"
|
|
109
116
|
}).export()
|
|
110
|
-
attest(types.d({}).
|
|
111
|
-
|
|
117
|
+
attest(types.d({}).toString()).snap(
|
|
118
|
+
"foo must be a function, a number or a string (was missing)"
|
|
119
|
+
)
|
|
120
|
+
attest(types.d({ foo: null }).toString()).snap(
|
|
112
121
|
"foo must be a function, a number or a string (was null)"
|
|
113
122
|
)
|
|
114
123
|
})
|
|
115
124
|
|
|
116
125
|
it("multi", () => {
|
|
117
126
|
const naturalNumber = type("integer>0")
|
|
118
|
-
attest(naturalNumber(-1.2).
|
|
127
|
+
attest(naturalNumber(-1.2).toString()).snap(
|
|
119
128
|
`must be...
|
|
120
129
|
• an integer
|
|
121
130
|
• more than 0`
|
|
@@ -123,7 +132,7 @@ contextualize(() => {
|
|
|
123
132
|
const naturalAtPath = type({
|
|
124
133
|
natural: naturalNumber
|
|
125
134
|
})
|
|
126
|
-
attest(naturalAtPath({ natural: -0.1 }).
|
|
135
|
+
attest(naturalAtPath({ natural: -0.1 }).toString()).snap(
|
|
127
136
|
`natural must be...
|
|
128
137
|
• an integer
|
|
129
138
|
• more than 0`
|
package/__tests__/type.test.ts
CHANGED
|
@@ -5,12 +5,9 @@ import { AssertionError } from "node:assert"
|
|
|
5
5
|
contextualize(() => {
|
|
6
6
|
it("root discriminates", () => {
|
|
7
7
|
const t = type("string")
|
|
8
|
-
const
|
|
9
|
-
if (errors)
|
|
10
|
-
|
|
11
|
-
} else {
|
|
12
|
-
attest<string>(out)
|
|
13
|
-
}
|
|
8
|
+
const out = t("")
|
|
9
|
+
if (out instanceof type.errors) out.throw()
|
|
10
|
+
else attest<string>(out)
|
|
14
11
|
})
|
|
15
12
|
|
|
16
13
|
it("allows", () => {
|
|
@@ -19,16 +16,17 @@ contextualize(() => {
|
|
|
19
16
|
if (t.allows(data)) {
|
|
20
17
|
// narrows correctly
|
|
21
18
|
attest<number>(data)
|
|
22
|
-
} else
|
|
23
|
-
|
|
24
|
-
}
|
|
19
|
+
} else throw new Error()
|
|
20
|
+
|
|
25
21
|
attest(t.allows(5)).equals(false)
|
|
26
22
|
})
|
|
27
23
|
|
|
24
|
+
// TODO: ?
|
|
28
25
|
it("errors can be thrown", () => {
|
|
29
26
|
const t = type("number")
|
|
30
27
|
try {
|
|
31
|
-
|
|
28
|
+
const result = t("invalid")
|
|
29
|
+
attest(result instanceof type.errors && result.throw())
|
|
32
30
|
} catch (e) {
|
|
33
31
|
attest(e instanceof ArkError).equals(true)
|
|
34
32
|
return
|
package/ark.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Ark,
|
|
3
|
+
type ArkErrors,
|
|
4
|
+
type inferred,
|
|
5
|
+
keywordNodes
|
|
6
|
+
} from "@arktype/schema"
|
|
2
7
|
import type { Generic } from "./generic.js"
|
|
3
8
|
import type { MatchParser } from "./match.js"
|
|
4
9
|
import type { Module } from "./module.js"
|
|
@@ -25,20 +30,18 @@ RawScope.ambient = ambient.raw
|
|
|
25
30
|
|
|
26
31
|
export const ark: Module<Ark> = ambient.export()
|
|
27
32
|
|
|
28
|
-
export const type: TypeParser<{}> = ambient.type
|
|
33
|
+
export const type: TypeParser<{}> = ambient.type as never
|
|
29
34
|
|
|
30
35
|
export namespace type {
|
|
31
|
-
export type cast<
|
|
32
|
-
[inferred]?:
|
|
36
|
+
export type cast<t> = {
|
|
37
|
+
[inferred]?: t
|
|
33
38
|
}
|
|
39
|
+
|
|
40
|
+
export type errors = ArkErrors
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
export const match: MatchParser<{}> = ambient.match
|
|
43
|
+
export const match: MatchParser<{}> = ambient.match as never
|
|
37
44
|
|
|
38
|
-
export const define: DefinitionParser<{}> = ambient.define
|
|
39
|
-
ambient
|
|
40
|
-
) as never
|
|
45
|
+
export const define: DefinitionParser<{}> = ambient.define as never
|
|
41
46
|
|
|
42
|
-
export const declare: DeclarationParser<{}> = ambient.declare
|
|
43
|
-
ambient
|
|
44
|
-
) as never
|
|
47
|
+
export const declare: DeclarationParser<{}> = ambient.declare as never
|
package/generic.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type SchemaScope,
|
|
5
5
|
arkKind
|
|
6
6
|
} from "@arktype/schema"
|
|
7
|
-
import { Callable, type conform
|
|
7
|
+
import { Callable, type conform } from "@arktype/util"
|
|
8
8
|
import type { inferDefinition } from "./parser/definition.js"
|
|
9
9
|
import type {
|
|
10
10
|
GenericParamsParseError,
|
|
@@ -57,11 +57,13 @@ export class Generic<params extends string[] = string[], def = unknown, $ = any>
|
|
|
57
57
|
public $: SchemaScope<$>
|
|
58
58
|
) {
|
|
59
59
|
super((...args: unknown[]) => {
|
|
60
|
-
const argNodes = flatMorph(params, (i, param: string) => [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
])
|
|
64
|
-
|
|
60
|
+
// const argNodes = flatMorph(params, (i, param: string) => [
|
|
61
|
+
// param,
|
|
62
|
+
// $.parseRoot(args[i])
|
|
63
|
+
// ])
|
|
64
|
+
// { args: argNodes }
|
|
65
|
+
args
|
|
66
|
+
return $.parseRoot(def) as never
|
|
65
67
|
})
|
|
66
68
|
}
|
|
67
69
|
}
|
package/match.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Morph,
|
|
3
|
-
Narrowed,
|
|
4
|
-
RawSchema,
|
|
5
|
-
distillOut,
|
|
6
|
-
inferIntersection
|
|
7
|
-
} from "@arktype/schema"
|
|
1
|
+
import type { Narrowed, distillOut, inferIntersection } from "@arktype/schema"
|
|
8
2
|
import type {
|
|
9
3
|
ErrorMessage,
|
|
10
4
|
isDisjoint,
|
|
@@ -163,67 +157,62 @@ export type MatchInvocation<ctx extends MatchInvocationContext> = <
|
|
|
163
157
|
}[numericStringKeyOf<ctx["thens"]>]
|
|
164
158
|
|
|
165
159
|
export const createMatchParser = <$>($: Scope): MatchParser<$> => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return Object.assign(() => matchParser(false), {
|
|
227
|
-
only: () => matchParser(true)
|
|
228
|
-
}) as never
|
|
160
|
+
return (() => {}).bind($) as never
|
|
161
|
+
// const matchParser = (isRestricted: boolean) => {
|
|
162
|
+
// const handledCases: { when: RawSchema; then: Morph }[] = []
|
|
163
|
+
// let defaultCase: ((x: unknown) => unknown) | null = null
|
|
164
|
+
|
|
165
|
+
// const parser = {
|
|
166
|
+
// when: (when: unknown, then: Morph) => {
|
|
167
|
+
// handledCases.push({ when: $.parseRoot(when, {}), then })
|
|
168
|
+
|
|
169
|
+
// return parser
|
|
170
|
+
// },
|
|
171
|
+
|
|
172
|
+
// finalize: () => {
|
|
173
|
+
// // TODO: exhaustiveness checking
|
|
174
|
+
// const branches = handledCases.flatMap(({ when, then }) => {
|
|
175
|
+
// if (when.kind === "union") {
|
|
176
|
+
// return when.branches.map((branch) => ({
|
|
177
|
+
// from: branch,
|
|
178
|
+
// morph: then
|
|
179
|
+
// }))
|
|
180
|
+
// }
|
|
181
|
+
// if (when.kind === "morph") {
|
|
182
|
+
// return [{ from: when, morph: [when.morph, then] }]
|
|
183
|
+
// }
|
|
184
|
+
// return [{ from: when, morph: then }]
|
|
185
|
+
// })
|
|
186
|
+
// if (defaultCase) {
|
|
187
|
+
// branches.push({ from: keywordNodes.unknown, morph: defaultCase })
|
|
188
|
+
// }
|
|
189
|
+
// const matchers = $.node("union", {
|
|
190
|
+
// branches,
|
|
191
|
+
// ordered: true
|
|
192
|
+
// })
|
|
193
|
+
// return matchers.assert
|
|
194
|
+
// },
|
|
195
|
+
|
|
196
|
+
// orThrow: () => {
|
|
197
|
+
// // implicitly finalize, we don't need to do anything else because we throw either way
|
|
198
|
+
// return parser.finalize()
|
|
199
|
+
// },
|
|
200
|
+
|
|
201
|
+
// default: (x: unknown) => {
|
|
202
|
+
// if (x instanceof Function) {
|
|
203
|
+
// defaultCase = x as never
|
|
204
|
+
// } else {
|
|
205
|
+
// defaultCase = () => x
|
|
206
|
+
// }
|
|
207
|
+
|
|
208
|
+
// return parser.finalize()
|
|
209
|
+
// }
|
|
210
|
+
// }
|
|
211
|
+
|
|
212
|
+
// return parser
|
|
213
|
+
// }
|
|
214
|
+
|
|
215
|
+
// return Object.assign(() => matchParser(false), {
|
|
216
|
+
// only: () => matchParser(true)
|
|
217
|
+
// }) as never
|
|
229
218
|
}
|
package/out/ark.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Ark, type inferred } from "@arktype/schema";
|
|
1
|
+
import { type Ark, type ArkErrors, type inferred } from "@arktype/schema";
|
|
2
2
|
import type { Generic } from "./generic.js";
|
|
3
3
|
import type { MatchParser } from "./match.js";
|
|
4
4
|
import type { Module } from "./module.js";
|
|
@@ -12,17 +12,17 @@ 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<{}>;
|
|
19
19
|
export declare namespace type {
|
|
20
|
-
type cast<
|
|
21
|
-
[inferred]?:
|
|
20
|
+
type cast<t> = {
|
|
21
|
+
[inferred]?: t;
|
|
22
22
|
};
|
|
23
|
+
type errors = ArkErrors;
|
|
23
24
|
}
|
|
24
25
|
export declare const match: MatchParser<{}>;
|
|
25
26
|
export declare const define: DefinitionParser<{}>;
|
|
26
27
|
export declare const declare: DeclarationParser<{}>;
|
|
27
28
|
export {};
|
|
28
|
-
//# sourceMappingURL=ark.d.ts.map
|
package/out/ark.js
CHANGED
|
@@ -4,8 +4,7 @@ export const tsGenerics = {};
|
|
|
4
4
|
export const ambient = scope(keywordNodes);
|
|
5
5
|
RawScope.ambient = ambient.raw;
|
|
6
6
|
export const ark = ambient.export();
|
|
7
|
-
export const type = ambient.type
|
|
8
|
-
export const match = ambient.match
|
|
9
|
-
export const define = ambient.define
|
|
10
|
-
export const declare = ambient.declare
|
|
11
|
-
//# sourceMappingURL=ark.js.map
|
|
7
|
+
export const type = ambient.type;
|
|
8
|
+
export const match = ambient.match;
|
|
9
|
+
export const define = ambient.define;
|
|
10
|
+
export const declare = ambient.declare;
|
package/out/ark.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ark.js","sourceRoot":"","sources":["../ark.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ark.js","sourceRoot":"","sources":["../ark.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,YAAY,EACZ,MAAM,iBAAiB,CAAA;AAIxB,OAAO,EAAE,QAAQ,EAAc,KAAK,EAAE,MAAM,YAAY,CAAA;AAexD,MAAM,CAAC,MAAM,UAAU,GAAG,EAA+B,CAAA;AAEzD,MAAM,CAAC,MAAM,OAAO,GAAe,KAAK,CAAC,YAAY,CAAU,CAAA;AAE/D,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAA;AAE9B,MAAM,CAAC,MAAM,GAAG,GAAgB,OAAO,CAAC,MAAM,EAAE,CAAA;AAEhD,MAAM,CAAC,MAAM,IAAI,GAAmB,OAAO,CAAC,IAAa,CAAA;AAUzD,MAAM,CAAC,MAAM,KAAK,GAAoB,OAAO,CAAC,KAAc,CAAA;AAE5D,MAAM,CAAC,MAAM,MAAM,GAAyB,OAAO,CAAC,MAAe,CAAA;AAEnE,MAAM,CAAC,MAAM,OAAO,GAA0B,OAAO,CAAC,OAAgB,CAAA"}
|
package/out/generic.d.ts
CHANGED
package/out/generic.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { arkKind } from "@arktype/schema";
|
|
2
|
-
import { Callable
|
|
2
|
+
import { Callable } from "@arktype/util";
|
|
3
3
|
export class Generic extends Callable {
|
|
4
4
|
params;
|
|
5
5
|
def;
|
|
@@ -9,15 +9,16 @@ export class Generic extends Callable {
|
|
|
9
9
|
// TODO: should be Scope<$>, but breaks inference
|
|
10
10
|
$) {
|
|
11
11
|
super((...args) => {
|
|
12
|
-
const argNodes = flatMorph(params, (i, param) => [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
])
|
|
16
|
-
|
|
12
|
+
// const argNodes = flatMorph(params, (i, param: string) => [
|
|
13
|
+
// param,
|
|
14
|
+
// $.parseRoot(args[i])
|
|
15
|
+
// ])
|
|
16
|
+
// { args: argNodes }
|
|
17
|
+
args;
|
|
18
|
+
return $.parseRoot(def);
|
|
17
19
|
});
|
|
18
20
|
this.params = params;
|
|
19
21
|
this.def = def;
|
|
20
22
|
this.$ = $;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
//# sourceMappingURL=generic.js.map
|
package/out/generic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,OAAO,EACP,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,QAAQ,EAAgB,
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,OAAO,EACP,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,QAAQ,EAAgB,MAAM,eAAe,CAAA;AAwCtD,MAAM,OAAO,OACZ,SAAQ,QAA8C;IAM9C;IACA;IAEA;IANC,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;IAE9B,YACQ,MAAc,EACd,GAAQ;IACf,iDAAiD;IAC1C,CAAiB;QAExB,KAAK,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE;YAC5B,6DAA6D;YAC7D,UAAU;YACV,wBAAwB;YACxB,KAAK;YACL,qBAAqB;YACrB,IAAI,CAAA;YACJ,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,CAAU,CAAA;QACjC,CAAC,CAAC,CAAA;QAbK,WAAM,GAAN,MAAM,CAAQ;QACd,QAAG,GAAH,GAAG,CAAK;QAER,MAAC,GAAD,CAAC,CAAgB;IAWzB,CAAC;CACD"}
|
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
|
@@ -1,59 +1,52 @@
|
|
|
1
1
|
export const createMatchParser = ($) => {
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
return parser;
|
|
54
|
-
};
|
|
55
|
-
return Object.assign(() => matchParser(false), {
|
|
56
|
-
only: () => matchParser(true)
|
|
57
|
-
});
|
|
2
|
+
return (() => { }).bind($);
|
|
3
|
+
// const matchParser = (isRestricted: boolean) => {
|
|
4
|
+
// const handledCases: { when: RawSchema; then: Morph }[] = []
|
|
5
|
+
// let defaultCase: ((x: unknown) => unknown) | null = null
|
|
6
|
+
// const parser = {
|
|
7
|
+
// when: (when: unknown, then: Morph) => {
|
|
8
|
+
// handledCases.push({ when: $.parseRoot(when, {}), then })
|
|
9
|
+
// return parser
|
|
10
|
+
// },
|
|
11
|
+
// finalize: () => {
|
|
12
|
+
// // TODO: exhaustiveness checking
|
|
13
|
+
// const branches = handledCases.flatMap(({ when, then }) => {
|
|
14
|
+
// if (when.kind === "union") {
|
|
15
|
+
// return when.branches.map((branch) => ({
|
|
16
|
+
// from: branch,
|
|
17
|
+
// morph: then
|
|
18
|
+
// }))
|
|
19
|
+
// }
|
|
20
|
+
// if (when.kind === "morph") {
|
|
21
|
+
// return [{ from: when, morph: [when.morph, then] }]
|
|
22
|
+
// }
|
|
23
|
+
// return [{ from: when, morph: then }]
|
|
24
|
+
// })
|
|
25
|
+
// if (defaultCase) {
|
|
26
|
+
// branches.push({ from: keywordNodes.unknown, morph: defaultCase })
|
|
27
|
+
// }
|
|
28
|
+
// const matchers = $.node("union", {
|
|
29
|
+
// branches,
|
|
30
|
+
// ordered: true
|
|
31
|
+
// })
|
|
32
|
+
// return matchers.assert
|
|
33
|
+
// },
|
|
34
|
+
// orThrow: () => {
|
|
35
|
+
// // implicitly finalize, we don't need to do anything else because we throw either way
|
|
36
|
+
// return parser.finalize()
|
|
37
|
+
// },
|
|
38
|
+
// default: (x: unknown) => {
|
|
39
|
+
// if (x instanceof Function) {
|
|
40
|
+
// defaultCase = x as never
|
|
41
|
+
// } else {
|
|
42
|
+
// defaultCase = () => x
|
|
43
|
+
// }
|
|
44
|
+
// return parser.finalize()
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
// return parser
|
|
48
|
+
// }
|
|
49
|
+
// return Object.assign(() => matchParser(false), {
|
|
50
|
+
// only: () => matchParser(true)
|
|
51
|
+
// }) as never
|
|
58
52
|
};
|
|
59
|
-
//# sourceMappingURL=match.js.map
|
package/out/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../match.ts"],"names":[],"mappings":"AA8JA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAI,CAAQ,EAAkB,EAAE;IAChE,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAU,CAAA;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,4DAA4D;IAE5D,oBAAoB;IACpB,4CAA4C;IAC5C,8DAA8D;IAE9D,mBAAmB;IACnB,OAAO;IAEP,sBAAsB;IACtB,sCAAsC;IACtC,iEAAiE;IACjE,mCAAmC;IACnC,+CAA+C;IAC/C,sBAAsB;IACtB,oBAAoB;IACpB,WAAW;IACX,QAAQ;IACR,mCAAmC;IACnC,0DAA0D;IAC1D,QAAQ;IACR,2CAA2C;IAC3C,QAAQ;IACR,wBAAwB;IACxB,wEAAwE;IACxE,OAAO;IACP,wCAAwC;IACxC,gBAAgB;IAChB,oBAAoB;IACpB,QAAQ;IACR,4BAA4B;IAC5B,OAAO;IAEP,qBAAqB;IACrB,2FAA2F;IAC3F,8BAA8B;IAC9B,OAAO;IAEP,+BAA+B;IAC/B,kCAAkC;IAClC,+BAA+B;IAC/B,cAAc;IACd,4BAA4B;IAC5B,OAAO;IAEP,8BAA8B;IAC9B,MAAM;IACN,KAAK;IAEL,iBAAiB;IACjB,IAAI;IAEJ,mDAAmD;IACnD,iCAAiC;IACjC,cAAc;AACf,CAAC,CAAA"}
|