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
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
type GenericProps,
|
|
3
3
|
type PrivateDeclaration,
|
|
4
4
|
RawSchema,
|
|
5
|
-
type SchemaModule,
|
|
6
5
|
hasArkKind,
|
|
7
6
|
type writeNonSubmoduleDotMessage,
|
|
8
7
|
writeUnresolvableMessage
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
type BigintLiteral,
|
|
12
11
|
type Completion,
|
|
13
12
|
type ErrorMessage,
|
|
13
|
+
type isAnyOrNever,
|
|
14
14
|
type join,
|
|
15
15
|
printable,
|
|
16
16
|
throwParseError,
|
|
@@ -33,11 +33,8 @@ import {
|
|
|
33
33
|
|
|
34
34
|
export const parseUnenclosed = (s: DynamicState): void => {
|
|
35
35
|
const token = s.scanner.shiftUntilNextTerminator()
|
|
36
|
-
if (token === "keyof")
|
|
37
|
-
|
|
38
|
-
} else {
|
|
39
|
-
s.root = unenclosedToNode(s, token)
|
|
40
|
-
}
|
|
36
|
+
if (token === "keyof") s.addPrefix("keyof")
|
|
37
|
+
else s.root = unenclosedToNode(s, token)
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
export type parseUnenclosed<s extends StaticState, $, args> =
|
|
@@ -48,7 +45,9 @@ export type parseUnenclosed<s extends StaticState, $, args> =
|
|
|
48
45
|
: tryResolve<s, token, $, args> extends infer result ?
|
|
49
46
|
result extends ErrorMessage<infer message> ? state.error<message>
|
|
50
47
|
: result extends keyof $ ?
|
|
51
|
-
|
|
48
|
+
isAnyOrNever<$[result]> extends true ?
|
|
49
|
+
state.setRoot<s, result, unscanned>
|
|
50
|
+
: $[result] extends GenericProps ?
|
|
52
51
|
parseGenericInstantiation<
|
|
53
52
|
token,
|
|
54
53
|
$[result],
|
|
@@ -68,9 +67,9 @@ export const parseGenericInstantiation = (
|
|
|
68
67
|
): RawSchema => {
|
|
69
68
|
s.scanner.shiftUntilNonWhitespace()
|
|
70
69
|
const lookahead = s.scanner.shift()
|
|
71
|
-
if (lookahead !== "<")
|
|
70
|
+
if (lookahead !== "<")
|
|
72
71
|
return s.error(writeInvalidGenericArgsMessage(name, g.params, []))
|
|
73
|
-
|
|
72
|
+
|
|
74
73
|
const parsedArgs = parseGenericArgs(name, g.params, s)
|
|
75
74
|
const remainingChars = parsedArgs.unscanned.length
|
|
76
75
|
// set the scanner position to where the args scanner left off
|
|
@@ -115,8 +114,7 @@ const maybeParseReference = (
|
|
|
115
114
|
): RawSchema | undefined => {
|
|
116
115
|
if (s.ctx.args?.[token]) return s.ctx.args[token].raw
|
|
117
116
|
const resolution = s.ctx.$.maybeResolve(token)
|
|
118
|
-
|
|
119
|
-
if (resolution instanceof RawSchema) return resolution.bindScope(s.ctx.$)
|
|
117
|
+
if (resolution instanceof RawSchema) return resolution
|
|
120
118
|
if (resolution === undefined) return
|
|
121
119
|
if (hasArkKind(resolution, "generic"))
|
|
122
120
|
return parseGenericInstantiation(token, resolution as Generic, s)
|
|
@@ -128,13 +126,12 @@ const maybeParseUnenclosedLiteral = (
|
|
|
128
126
|
token: string
|
|
129
127
|
): RawSchema | undefined => {
|
|
130
128
|
const maybeNumber = tryParseNumber(token, { strict: true })
|
|
131
|
-
if (maybeNumber !== undefined)
|
|
129
|
+
if (maybeNumber !== undefined)
|
|
132
130
|
return s.ctx.$.node("unit", { unit: maybeNumber })
|
|
133
|
-
|
|
131
|
+
|
|
134
132
|
const maybeBigint = tryParseWellFormedBigint(token)
|
|
135
|
-
if (maybeBigint !== undefined)
|
|
133
|
+
if (maybeBigint !== undefined)
|
|
136
134
|
return s.ctx.$.node("unit", { unit: maybeBigint })
|
|
137
|
-
}
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
type tryResolve<s extends StaticState, token extends string, $, args> =
|
|
@@ -146,16 +143,9 @@ type tryResolve<s extends StaticState, token extends string, $, args> =
|
|
|
146
143
|
: token extends (
|
|
147
144
|
`${infer submodule extends keyof $ & string}.${infer reference}`
|
|
148
145
|
) ?
|
|
149
|
-
$[submodule] extends
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
reference extends keyof sub$ ? token
|
|
153
|
-
: unknown extends sub$ ?
|
|
154
|
-
// not sure why we need the additional check here, but for now TS seems to
|
|
155
|
-
// hit this branch for a non-scope dot access rather than failing
|
|
156
|
-
// initially when we try to infer r. if this can be removed without breaking
|
|
157
|
-
// any submodule test cases, do it!
|
|
158
|
-
ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
146
|
+
$[submodule] extends Module<infer sub$> ?
|
|
147
|
+
reference extends keyof sub$ ?
|
|
148
|
+
token
|
|
159
149
|
: unresolvableError<s, reference, $[submodule], args, [submodule]>
|
|
160
150
|
: ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
|
|
161
151
|
: unresolvableError<s, token, $, args, []>
|
|
@@ -181,9 +181,8 @@ export const parseRightBound = (
|
|
|
181
181
|
if (
|
|
182
182
|
!limitNode.hasKind("unit") ||
|
|
183
183
|
(typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date))
|
|
184
|
-
)
|
|
184
|
+
)
|
|
185
185
|
return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"))
|
|
186
|
-
}
|
|
187
186
|
|
|
188
187
|
const limit = limitNode.unit
|
|
189
188
|
// apply the newly-parsed right bound
|
|
@@ -194,16 +193,15 @@ export const parseRightBound = (
|
|
|
194
193
|
typeof limit === "number" ? limit : (limitToken as DateLiteral),
|
|
195
194
|
previousRoot,
|
|
196
195
|
"right"
|
|
197
|
-
))
|
|
196
|
+
))
|
|
198
197
|
s.constrainRoot(kind, { rule: limit, exclusive })
|
|
199
|
-
|
|
200
|
-
if (!s.branches.leftBound)
|
|
201
|
-
|
|
202
|
-
}
|
|
198
|
+
|
|
199
|
+
if (!s.branches.leftBound) return
|
|
200
|
+
|
|
203
201
|
// if there's an open left bound, perform additional validation and apply it
|
|
204
|
-
if (!isKeyOf(comparator, maxComparators))
|
|
202
|
+
if (!isKeyOf(comparator, maxComparators))
|
|
205
203
|
return s.error(writeUnpairableComparatorMessage(comparator))
|
|
206
|
-
|
|
204
|
+
|
|
207
205
|
const lowerBoundKind = getBoundKinds(
|
|
208
206
|
s.branches.leftBound.comparator,
|
|
209
207
|
s.branches.leftBound.limit,
|
|
@@ -8,9 +8,8 @@ export const parseDivisor = (s: DynamicStateWithRoot): void => {
|
|
|
8
8
|
const divisor = tryParseInteger(divisorToken, {
|
|
9
9
|
errorOnFail: writeInvalidDivisorMessage(divisorToken)
|
|
10
10
|
})
|
|
11
|
-
if (divisor === 0)
|
|
12
|
-
|
|
13
|
-
}
|
|
11
|
+
if (divisor === 0) s.error(writeInvalidDivisorMessage(0))
|
|
12
|
+
|
|
14
13
|
s.root = s.root.constrain("divisor", divisor)
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -27,11 +27,9 @@ export class Scanner<Lookahead extends string = string> {
|
|
|
27
27
|
let shifted = ""
|
|
28
28
|
while (this.lookahead) {
|
|
29
29
|
if (condition(this, shifted)) {
|
|
30
|
-
if (shifted[shifted.length - 1] === Scanner.escapeToken)
|
|
30
|
+
if (shifted[shifted.length - 1] === Scanner.escapeToken)
|
|
31
31
|
shifted = shifted.slice(0, -1)
|
|
32
|
-
|
|
33
|
-
break
|
|
34
|
-
}
|
|
32
|
+
else break
|
|
35
33
|
}
|
|
36
34
|
shifted += this.shift()
|
|
37
35
|
}
|
package/parser/string/string.ts
CHANGED
|
@@ -62,9 +62,8 @@ type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<
|
|
|
62
62
|
>
|
|
63
63
|
|
|
64
64
|
export const parseUntilFinalizer = (s: DynamicState): DynamicStateWithRoot => {
|
|
65
|
-
while (s.finalizer === undefined)
|
|
66
|
-
|
|
67
|
-
}
|
|
65
|
+
while (s.finalizer === undefined) next(s)
|
|
66
|
+
|
|
68
67
|
return s as DynamicStateWithRoot
|
|
69
68
|
}
|
|
70
69
|
|
package/parser/tuple.ts
CHANGED
|
@@ -53,34 +53,33 @@ export const parseTupleLiteral = (def: array, ctx: ParseContext): RawSchema => {
|
|
|
53
53
|
|
|
54
54
|
i++
|
|
55
55
|
if (def[i] === "?") {
|
|
56
|
-
if (spread)
|
|
57
|
-
|
|
58
|
-
}
|
|
56
|
+
if (spread) return throwParseError(spreadOptionalMessage)
|
|
57
|
+
|
|
59
58
|
optional = true
|
|
60
59
|
i++
|
|
61
60
|
}
|
|
62
61
|
if (spread) {
|
|
63
|
-
if (!element.extends(jsObjects.Array))
|
|
62
|
+
if (!element.extends(jsObjects.Array))
|
|
64
63
|
return throwParseError(writeNonArraySpreadMessage(element.expression))
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
// a spread must be distributed over branches e.g.:
|
|
67
66
|
// def: [string, ...(number[] | [true, false])]
|
|
68
67
|
// nodes: [string, ...number[]] | [string, true, false]
|
|
69
|
-
sequences = sequences.flatMap(
|
|
68
|
+
sequences = sequences.flatMap(base =>
|
|
70
69
|
// since appendElement mutates base, we have to shallow-ish clone it for each branch
|
|
71
|
-
element.branches.map(
|
|
70
|
+
element.branches.map(branch =>
|
|
72
71
|
appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)
|
|
73
72
|
)
|
|
74
73
|
)
|
|
75
74
|
} else {
|
|
76
|
-
sequences = sequences.map(
|
|
75
|
+
sequences = sequences.map(base =>
|
|
77
76
|
appendElement(base, optional ? "optional" : "required", element)
|
|
78
77
|
)
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
return ctx.$.raw.schema(
|
|
82
81
|
sequences.map(
|
|
83
|
-
|
|
82
|
+
sequence =>
|
|
84
83
|
({
|
|
85
84
|
proto: Array,
|
|
86
85
|
sequence
|
|
@@ -143,10 +142,10 @@ const appendSpreadBranch = (
|
|
|
143
142
|
// the only array with no sequence reference is unknown[]
|
|
144
143
|
return appendElement(base, "variadic", tsKeywords.unknown)
|
|
145
144
|
}
|
|
146
|
-
spread.prefix.forEach(
|
|
147
|
-
spread.optional.forEach(
|
|
145
|
+
spread.prefix.forEach(node => appendElement(base, "required", node))
|
|
146
|
+
spread.optional.forEach(node => appendElement(base, "optional", node))
|
|
148
147
|
spread.variadic && appendElement(base, "variadic", spread.variadic)
|
|
149
|
-
spread.postfix.forEach(
|
|
148
|
+
spread.postfix.forEach(node => appendElement(base, "required", node))
|
|
150
149
|
return base
|
|
151
150
|
}
|
|
152
151
|
|
|
@@ -414,9 +413,9 @@ export type inferKeyOfExpression<operandDef, $, args> = show<
|
|
|
414
413
|
>
|
|
415
414
|
|
|
416
415
|
const parseBranchTuple: PostfixParser<"|" | "&"> = (def, ctx) => {
|
|
417
|
-
if (def[2] === undefined)
|
|
416
|
+
if (def[2] === undefined)
|
|
418
417
|
return throwParseError(writeMissingRightOperandMessage(def[1], ""))
|
|
419
|
-
|
|
418
|
+
|
|
420
419
|
const l = ctx.$.parse(def[0], ctx)
|
|
421
420
|
const r = ctx.$.parse(def[2], ctx)
|
|
422
421
|
return def[1] === "&" ? l.and(r) : l.or(r)
|
|
@@ -459,7 +458,7 @@ export const parseMorphTuple: PostfixParser<"=>"> = (def, ctx) => {
|
|
|
459
458
|
)
|
|
460
459
|
}
|
|
461
460
|
// TODO: nested morphs?
|
|
462
|
-
return ctx.$.parse(def[0], ctx).
|
|
461
|
+
return ctx.$.parse(def[0], ctx).pipe(def[2] as Morph)
|
|
463
462
|
}
|
|
464
463
|
|
|
465
464
|
export const writeMalformedFunctionalExpressionMessage = (
|
|
@@ -518,7 +517,7 @@ const prefixParsers: {
|
|
|
518
517
|
}
|
|
519
518
|
const branches = def
|
|
520
519
|
.slice(1)
|
|
521
|
-
.map(
|
|
520
|
+
.map(ctor =>
|
|
522
521
|
typeof ctor === "function" ?
|
|
523
522
|
ctx.$.node("proto", { proto: ctor as Constructor })
|
|
524
523
|
: throwParseError(
|
package/scope.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ArkConfig,
|
|
3
3
|
type GenericProps,
|
|
4
|
-
type NodeParseOptions,
|
|
5
4
|
type PreparsedNodeResolution,
|
|
5
|
+
type PrivateDeclaration,
|
|
6
6
|
type RawSchema,
|
|
7
7
|
type RawSchemaResolutions,
|
|
8
8
|
RawSchemaScope,
|
|
9
9
|
type SchemaScope,
|
|
10
|
+
type UnknownSchema,
|
|
10
11
|
type ambient,
|
|
11
12
|
type arkKind,
|
|
12
13
|
type destructuredExportContext,
|
|
13
14
|
type destructuredImportContext,
|
|
14
15
|
type exportedNameOf,
|
|
15
|
-
hasArkKind
|
|
16
|
+
hasArkKind,
|
|
17
|
+
type writeDuplicateAliasError
|
|
16
18
|
} from "@arktype/schema"
|
|
17
19
|
import {
|
|
18
20
|
type Dict,
|
|
19
21
|
domainOf,
|
|
20
22
|
hasDomain,
|
|
23
|
+
type isAnyOrNever,
|
|
21
24
|
isThunk,
|
|
25
|
+
type keyError,
|
|
22
26
|
type nominal,
|
|
23
27
|
type show,
|
|
24
28
|
throwParseError
|
|
@@ -40,11 +44,12 @@ import {
|
|
|
40
44
|
} from "./parser/generic.js"
|
|
41
45
|
import { DynamicState } from "./parser/string/reduce/dynamic.js"
|
|
42
46
|
import { fullStringParse } from "./parser/string/string.js"
|
|
43
|
-
import
|
|
44
|
-
DeclarationParser,
|
|
45
|
-
DefinitionParser,
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
import {
|
|
48
|
+
type DeclarationParser,
|
|
49
|
+
type DefinitionParser,
|
|
50
|
+
RawTypeParser,
|
|
51
|
+
type Type,
|
|
52
|
+
type TypeParser
|
|
48
53
|
} from "./type.js"
|
|
49
54
|
|
|
50
55
|
export type ScopeParser = <const def>(
|
|
@@ -54,12 +59,14 @@ export type ScopeParser = <const def>(
|
|
|
54
59
|
|
|
55
60
|
type validateScope<def> = {
|
|
56
61
|
[k in keyof def]: k extends symbol ?
|
|
57
|
-
// this should only occur when importing/exporting modules, and those
|
|
62
|
+
// this should only occur when importing/exporting modules, and those
|
|
63
|
+
// keys should be ignored
|
|
58
64
|
unknown
|
|
59
65
|
: parseScopeKey<k>["params"] extends [] ?
|
|
60
66
|
// Not including Type here directly breaks inference
|
|
61
|
-
def[k] extends Type | PreparsedResolution ?
|
|
62
|
-
|
|
67
|
+
def[k] extends Type | PreparsedResolution ? def[k]
|
|
68
|
+
: k extends PrivateDeclaration<infer name extends keyof def & string> ?
|
|
69
|
+
keyError<writeDuplicateAliasError<name>>
|
|
63
70
|
: validateDefinition<def[k], ambient & bootstrapAliases<def>, {}>
|
|
64
71
|
: parseScopeKey<k>["params"] extends GenericParamsParseError ?
|
|
65
72
|
// use the full nominal type here to avoid an overlap between the
|
|
@@ -126,12 +133,9 @@ export type resolve<reference extends keyof $ | keyof args, $, args> =
|
|
|
126
133
|
args[reference]
|
|
127
134
|
: $[reference & keyof $]
|
|
128
135
|
) extends infer resolution ?
|
|
129
|
-
resolution extends
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
resolution
|
|
133
|
-
: inferDefinition<def, $, args>
|
|
134
|
-
: resolution
|
|
136
|
+
isAnyOrNever<resolution> extends true ? resolution
|
|
137
|
+
: resolution extends Def<infer def> ? inferDefinition<def, $, args>
|
|
138
|
+
: resolution
|
|
135
139
|
: never
|
|
136
140
|
|
|
137
141
|
export type moduleKeyOf<$> = {
|
|
@@ -148,8 +152,9 @@ export type tryInferSubmoduleReference<$, token> =
|
|
|
148
152
|
: never
|
|
149
153
|
: never
|
|
150
154
|
|
|
151
|
-
export interface ParseContext
|
|
155
|
+
export interface ParseContext {
|
|
152
156
|
$: RawScope
|
|
157
|
+
args?: Record<string, UnknownSchema>
|
|
153
158
|
}
|
|
154
159
|
|
|
155
160
|
export const scope: ScopeParser = ((def: Dict, config: ArkConfig = {}) =>
|
|
@@ -191,65 +196,42 @@ export class RawScope<
|
|
|
191
196
|
super(aliases, config)
|
|
192
197
|
}
|
|
193
198
|
|
|
194
|
-
type
|
|
195
|
-
if (args.length === 1) {
|
|
196
|
-
// treat as a simple definition
|
|
197
|
-
return this.parseRoot(args[0])
|
|
198
|
-
}
|
|
199
|
-
if (
|
|
200
|
-
args.length === 2 &&
|
|
201
|
-
typeof args[0] === "string" &&
|
|
202
|
-
args[0][0] === "<" &&
|
|
203
|
-
args[0].at(-1) === ">"
|
|
204
|
-
) {
|
|
205
|
-
// if there are exactly two args, the first of which looks like <${string}>,
|
|
206
|
-
// treat as a generic
|
|
207
|
-
const params = parseGenericParams(args[0].slice(1, -1))
|
|
208
|
-
const def = args[1]
|
|
209
|
-
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
210
|
-
return new Generic(params, def, this as never) as never
|
|
211
|
-
}
|
|
212
|
-
// otherwise, treat as a tuple expression. technically, this also allows
|
|
213
|
-
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
214
|
-
// part of the API as specified by the associated types
|
|
215
|
-
return this.parseRoot(args)
|
|
216
|
-
}
|
|
199
|
+
type = new RawTypeParser(this as never)
|
|
217
200
|
|
|
218
201
|
match: MatchParser<$> = createMatchParser(this as never) as never
|
|
219
202
|
|
|
220
|
-
declare()
|
|
221
|
-
|
|
222
|
-
}
|
|
203
|
+
declare = (() => ({
|
|
204
|
+
type: this.type
|
|
205
|
+
})).bind(this)
|
|
223
206
|
|
|
224
|
-
define(def: unknown)
|
|
225
|
-
return def
|
|
226
|
-
}
|
|
207
|
+
define = ((def: unknown) => def).bind(this)
|
|
227
208
|
|
|
228
209
|
override preparseRoot(def: unknown): unknown {
|
|
229
|
-
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
230
|
-
|
|
231
|
-
}
|
|
210
|
+
if (isThunk(def) && !hasArkKind(def, "generic")) return def()
|
|
211
|
+
|
|
232
212
|
return def
|
|
233
213
|
}
|
|
234
214
|
|
|
235
|
-
override parseRoot(def: unknown
|
|
215
|
+
override parseRoot(def: unknown): RawSchema {
|
|
216
|
+
// args: { this: {} as RawSchema },
|
|
236
217
|
return this.parse(def, {
|
|
237
|
-
args: { this: {} as RawSchema },
|
|
238
218
|
$: this as never,
|
|
239
|
-
|
|
219
|
+
args: {}
|
|
220
|
+
// type parsing can bypass nodes if it hits the cache,
|
|
221
|
+
// so bind it directly (could be optimized)
|
|
240
222
|
}).bindScope(this)
|
|
241
223
|
}
|
|
242
224
|
|
|
243
225
|
parse(def: unknown, ctx: ParseContext): RawSchema {
|
|
244
226
|
if (typeof def === "string") {
|
|
245
|
-
if (ctx.args && Object.keys(ctx.args).every(
|
|
227
|
+
if (ctx.args && Object.keys(ctx.args).every(k => !def.includes(k))) {
|
|
246
228
|
// we can only rely on the cache if there are no contextual
|
|
247
229
|
// resolutions like "this" or generic args
|
|
248
230
|
return this.parseString(def, ctx)
|
|
249
231
|
}
|
|
250
|
-
if (!this.parseCache[def])
|
|
232
|
+
if (!this.parseCache[def])
|
|
251
233
|
this.parseCache[def] = this.parseString(def, ctx)
|
|
252
|
-
|
|
234
|
+
|
|
253
235
|
return this.parseCache[def]
|
|
254
236
|
}
|
|
255
237
|
return hasDomain(def, "object") ?
|
|
@@ -259,9 +241,9 @@ export class RawScope<
|
|
|
259
241
|
|
|
260
242
|
parseString(def: string, ctx: ParseContext): RawSchema {
|
|
261
243
|
return (
|
|
262
|
-
this.
|
|
244
|
+
this.maybeResolveSchema(def) ??
|
|
263
245
|
((def.endsWith("[]") &&
|
|
264
|
-
this.
|
|
246
|
+
this.maybeResolveSchema(def.slice(0, -2))?.array()) ||
|
|
265
247
|
fullStringParse(new DynamicState(def, ctx)))
|
|
266
248
|
)
|
|
267
249
|
}
|