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/out/scope.js
CHANGED
|
@@ -6,6 +6,7 @@ import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.
|
|
|
6
6
|
import { parseGenericParams } from "./parser/generic.js";
|
|
7
7
|
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
8
8
|
import { fullStringParse } from "./parser/string/string.js";
|
|
9
|
+
import { RawTypeParser } from "./type.js";
|
|
9
10
|
export const scope = ((def, config = {}) => new RawScope(def, config));
|
|
10
11
|
export class RawScope extends RawSchemaScope {
|
|
11
12
|
parseCache = {};
|
|
@@ -21,57 +22,35 @@ export class RawScope extends RawSchemaScope {
|
|
|
21
22
|
}
|
|
22
23
|
super(aliases, config);
|
|
23
24
|
}
|
|
24
|
-
type(
|
|
25
|
-
if (args.length === 1) {
|
|
26
|
-
// treat as a simple definition
|
|
27
|
-
return this.parseRoot(args[0]);
|
|
28
|
-
}
|
|
29
|
-
if (args.length === 2 &&
|
|
30
|
-
typeof args[0] === "string" &&
|
|
31
|
-
args[0][0] === "<" &&
|
|
32
|
-
args[0].at(-1) === ">") {
|
|
33
|
-
// if there are exactly two args, the first of which looks like <${string}>,
|
|
34
|
-
// treat as a generic
|
|
35
|
-
const params = parseGenericParams(args[0].slice(1, -1));
|
|
36
|
-
const def = args[1];
|
|
37
|
-
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
38
|
-
return new Generic(params, def, this);
|
|
39
|
-
}
|
|
40
|
-
// otherwise, treat as a tuple expression. technically, this also allows
|
|
41
|
-
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
42
|
-
// part of the API as specified by the associated types
|
|
43
|
-
return this.parseRoot(args);
|
|
44
|
-
}
|
|
25
|
+
type = new RawTypeParser(this);
|
|
45
26
|
match = createMatchParser(this);
|
|
46
|
-
declare() {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
define(def)
|
|
50
|
-
return def;
|
|
51
|
-
}
|
|
27
|
+
declare = (() => ({
|
|
28
|
+
type: this.type
|
|
29
|
+
})).bind(this);
|
|
30
|
+
define = ((def) => def).bind(this);
|
|
52
31
|
preparseRoot(def) {
|
|
53
|
-
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
32
|
+
if (isThunk(def) && !hasArkKind(def, "generic"))
|
|
54
33
|
return def();
|
|
55
|
-
}
|
|
56
34
|
return def;
|
|
57
35
|
}
|
|
58
|
-
parseRoot(def
|
|
36
|
+
parseRoot(def) {
|
|
37
|
+
// args: { this: {} as RawSchema },
|
|
59
38
|
return this.parse(def, {
|
|
60
|
-
args: { this: {} },
|
|
61
39
|
$: this,
|
|
62
|
-
|
|
40
|
+
args: {}
|
|
41
|
+
// type parsing can bypass nodes if it hits the cache,
|
|
42
|
+
// so bind it directly (could be optimized)
|
|
63
43
|
}).bindScope(this);
|
|
64
44
|
}
|
|
65
45
|
parse(def, ctx) {
|
|
66
46
|
if (typeof def === "string") {
|
|
67
|
-
if (ctx.args && Object.keys(ctx.args).every(
|
|
47
|
+
if (ctx.args && Object.keys(ctx.args).every(k => !def.includes(k))) {
|
|
68
48
|
// we can only rely on the cache if there are no contextual
|
|
69
49
|
// resolutions like "this" or generic args
|
|
70
50
|
return this.parseString(def, ctx);
|
|
71
51
|
}
|
|
72
|
-
if (!this.parseCache[def])
|
|
52
|
+
if (!this.parseCache[def])
|
|
73
53
|
this.parseCache[def] = this.parseString(def, ctx);
|
|
74
|
-
}
|
|
75
54
|
return this.parseCache[def];
|
|
76
55
|
}
|
|
77
56
|
return hasDomain(def, "object") ?
|
|
@@ -79,9 +58,9 @@ export class RawScope extends RawSchemaScope {
|
|
|
79
58
|
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
80
59
|
}
|
|
81
60
|
parseString(def, ctx) {
|
|
82
|
-
return (this.
|
|
61
|
+
return (this.maybeResolveSchema(def) ??
|
|
83
62
|
((def.endsWith("[]") &&
|
|
84
|
-
this.
|
|
63
|
+
this.maybeResolveSchema(def.slice(0, -2))?.array()) ||
|
|
85
64
|
fullStringParse(new DynamicState(def, ctx))));
|
|
86
65
|
}
|
|
87
66
|
}
|
|
@@ -102,4 +81,3 @@ export const parseScopeKey = (k) => {
|
|
|
102
81
|
params: parseGenericParams(k.slice(firstParamIndex + 1, -1))
|
|
103
82
|
};
|
|
104
83
|
};
|
|
105
|
-
//# sourceMappingURL=scope.js.map
|
package/out/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,EAQd,UAAU,EAEV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEN,QAAQ,EACR,SAAS,EAET,OAAO,EAIP,eAAe,EACf,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,EAEN,WAAW,EAEX,6BAA6B,EAC7B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAGN,kBAAkB,EAClB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAGN,aAAa,EAGb,MAAM,WAAW,CAAA;AA2GlB,MAAM,CAAC,MAAM,KAAK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,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;gBACnD,eAAe,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAC7C,CAAA;IACF,CAAC;CACD;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC5C,IAAY,EACZ,IAAc,EACL,EAAE,CACX,UAAU,IAAI,qCAAqC,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;AAO/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAkB,EAAE;IAC1D,MAAM,eAAe,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACtC,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5B,OAAO;YACN,IAAI,EAAE,CAAC;YACP,MAAM,EAAE,EAAE;SACV,CAAA;IACF,CAAC;IACD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACtB,eAAe,CACd,oEAAoE,CACpE,CAAA;IACF,CAAC;IACD,OAAO;QACN,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC;QACjC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC5D,CAAA;AACF,CAAC,CAAA"}
|
package/out/type.d.ts
CHANGED
|
@@ -1,37 +1,56 @@
|
|
|
1
|
-
import { type BaseMeta, type Morph, type NodeDef, type Out, type Predicate, type PrimitiveConstraintKind, type Schema, type ambient, type constrain, type constraintKindOf, type
|
|
2
|
-
import type
|
|
3
|
-
import
|
|
1
|
+
import { ArkErrors, type BaseMeta, type BaseRoot, type Disjoint, type Morph, type NodeDef, type Out, type Predicate, type PrimitiveConstraintKind, RawSchema, type Schema, type ambient, type constrain, type constraintKindOf, type distillConstrainableOut, type distillIn, type distillOut, type includesMorphs, type inferIntersection, type inferMorphOut, type inferNarrow, type inferPipes, type internalImplementationOf } from "@arktype/schema";
|
|
2
|
+
import { Callable, type Constructor, type array, type conform } from "@arktype/util";
|
|
3
|
+
import { Generic, type validateParameterString } from "./generic.js";
|
|
4
4
|
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
|
|
5
|
-
import
|
|
5
|
+
import { parseGenericParams } from "./parser/generic.js";
|
|
6
6
|
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.js";
|
|
7
|
-
import type { Scope, bindThis } from "./scope.js";
|
|
8
|
-
export
|
|
7
|
+
import type { RawScope, Scope, bindThis } from "./scope.js";
|
|
8
|
+
export interface TypeParserAttachments {
|
|
9
|
+
errors: typeof ArkErrors;
|
|
10
|
+
}
|
|
11
|
+
export interface TypeParser<$> extends TypeParserAttachments {
|
|
9
12
|
<const def>(def: validateTypeRoot<def, $>): Type<inferTypeRoot<def, $>, $>;
|
|
10
13
|
<const zero, const one, const rest extends array>(_0: zero extends IndexZeroOperator ? zero : validateTypeRoot<zero, $>, _1: zero extends "keyof" ? validateTypeRoot<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distillIn<inferTypeRoot<zero, $>>>] : one extends "=>" ? [Morph<distillOut<inferTypeRoot<zero, $>>, unknown>] : one extends "@" ? [string | BaseMeta] : [validateTypeRoot<rest[0], $>] : []): Type<inferTypeRoot<[zero, one, ...rest], $>, $>;
|
|
11
14
|
<params extends string, const def>(params: `<${validateParameterString<params>}>`, def: validateDefinition<def, $, {
|
|
12
15
|
[param in parseGenericParams<params>[number]]: unknown;
|
|
13
16
|
}>): Generic<parseGenericParams<params>, def, $>;
|
|
14
|
-
}
|
|
17
|
+
}
|
|
18
|
+
export declare class RawTypeParser extends Callable<(...args: unknown[]) => RawSchema | Generic, TypeParserAttachments> {
|
|
19
|
+
constructor($: RawScope);
|
|
20
|
+
}
|
|
15
21
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
16
22
|
type: <def>(def: validateDeclared<preinferred, def, $ & ambient, bindThis<def>>) => Type<preinferred, $>;
|
|
17
23
|
};
|
|
24
|
+
declare class _Type<t = unknown, $ = any> extends BaseRoot<t, $> implements internalImplementationOf<Schema> {
|
|
25
|
+
$: Scope<$>;
|
|
26
|
+
get in(): Type<this["tIn"], $>;
|
|
27
|
+
get out(): Type<this["tOut"], $>;
|
|
28
|
+
intersect<def>(def: validateTypeRoot<def, $>): Type<inferIntersection<t, inferTypeRoot<def, $>>> | Disjoint;
|
|
29
|
+
and<def>(def: validateTypeRoot<def, $>): Type<inferIntersection<t, inferTypeRoot<def, $>>, $>;
|
|
30
|
+
or<def>(def: validateTypeRoot<def, $>): Type<t | inferTypeRoot<def, $>, $>;
|
|
31
|
+
array(): Type<t[], $>;
|
|
32
|
+
keyof(): Type<keyof this["inferIn"], $>;
|
|
33
|
+
pipe<a extends Morph<this["infer"]>>(a: a): Type<inferPipes<t, [a]>, $>;
|
|
34
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>>(a: a, b: b): Type<inferPipes<t, [a, b]>, $>;
|
|
35
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>>(a: a, b: b, c: c): Type<inferPipes<t, [a, b, c]>, $>;
|
|
36
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>>(a: a, b: b, c: c, d: d): Type<inferPipes<t, [a, b, c, d]>, $>;
|
|
37
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>>(a: a, b: b, c: c, d: d, e: e): Type<inferPipes<t, [a, b, c, d, e]>, $>;
|
|
38
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>>(a: a, b: b, c: c, d: d, e: e, f: f): Type<inferPipes<t, [a, b, c, d, e, f]>, $>;
|
|
39
|
+
pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): Type<inferPipes<t, [a, b, c, d, e, f, g]>, $>;
|
|
40
|
+
narrow<def extends Predicate<distillConstrainableOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: this["tIn"]) => Out<inferNarrow<this["infer"], def>> : inferNarrow<this["infer"], def>, $>;
|
|
41
|
+
equals<def>(def: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
|
|
42
|
+
extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
43
|
+
exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
|
|
44
|
+
extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
|
|
45
|
+
constrain<kind extends PrimitiveConstraintKind, const def extends NodeDef<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
|
|
46
|
+
}
|
|
18
47
|
export interface Type<
|
|
19
48
|
/** @ts-expect-error allow instantiation assignment to the base type */
|
|
20
|
-
out t = unknown, $ = any> extends
|
|
21
|
-
and: (<def>(def: validateTypeRoot<def, $>) => Type<inferIntersection<t, inferTypeRoot<def, $>>, $>) & Schema<t, $>["and"];
|
|
22
|
-
or: (<def>(def: validateTypeRoot<def, $>) => Type<t | inferTypeRoot<def, $>, $>) & Schema<t, $>["or"];
|
|
23
|
-
get in(): Type<distillConstrainableIn<t>, $>;
|
|
24
|
-
get out(): Type<distillConstrainableOut<t>, $>;
|
|
25
|
-
array(): Type<t[], $>;
|
|
26
|
-
morph: (<morph extends Morph<this["infer"]>, outValidatorDef = never>(morph: morph, outValidator?: validateTypeRoot<outValidatorDef, $>) => Type<(In: distillConstrainableIn<t>) => Out<[
|
|
27
|
-
outValidatorDef
|
|
28
|
-
] extends [never] ? inferMorphOut<morph> : distillConstrainableOut<inferTypeRoot<outValidatorDef, $>>>, $>) & Schema<t, $>["morph"];
|
|
29
|
-
narrow<def extends Predicate<distillConstrainableOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: distillIn<t>) => Out<inferNarrow<this["infer"], def>> : inferNarrow<this["infer"], def>, $>;
|
|
30
|
-
constrain<kind extends PrimitiveConstraintKind, const def extends NodeDef<kind>>(kind: conform<kind, constraintKindOf<this["in"]["infer"]>>, def: def): Type<constrain<t, kind, def>, $>;
|
|
49
|
+
out t = unknown, $ = any> extends _Type<t, $> {
|
|
31
50
|
}
|
|
32
51
|
export type TypeConstructor<t = unknown, $ = any> = new (def: unknown, $: Scope<$>) => Type<t, $>;
|
|
33
52
|
export declare const Type: TypeConstructor;
|
|
34
53
|
export type DefinitionParser<$> = <def>(def: validateTypeRoot<def, $>) => def;
|
|
35
54
|
export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $ & ambient, bindThis<def>>;
|
|
36
55
|
export type inferTypeRoot<def, $ = {}> = inferDefinition<def, $ & ambient, bindThis<def>>;
|
|
37
|
-
|
|
56
|
+
export {};
|
package/out/type.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
import { RawSchema } from "@arktype/schema";
|
|
1
|
+
import { ArkErrors, RawSchema } from "@arktype/schema";
|
|
2
|
+
import { Callable } from "@arktype/util";
|
|
3
|
+
import { Generic } from "./generic.js";
|
|
4
|
+
import { parseGenericParams } from "./parser/generic.js";
|
|
5
|
+
const typeParserAttachments = Object.freeze({
|
|
6
|
+
errors: ArkErrors
|
|
7
|
+
});
|
|
8
|
+
export class RawTypeParser extends Callable {
|
|
9
|
+
constructor($) {
|
|
10
|
+
super((...args) => {
|
|
11
|
+
if (args.length === 1) {
|
|
12
|
+
// treat as a simple definition
|
|
13
|
+
return $.parseRoot(args[0]);
|
|
14
|
+
}
|
|
15
|
+
if (args.length === 2 &&
|
|
16
|
+
typeof args[0] === "string" &&
|
|
17
|
+
args[0][0] === "<" &&
|
|
18
|
+
args[0].at(-1) === ">") {
|
|
19
|
+
// if there are exactly two args, the first of which looks like <${string}>,
|
|
20
|
+
// treat as a generic
|
|
21
|
+
const params = parseGenericParams(args[0].slice(1, -1));
|
|
22
|
+
const def = args[1];
|
|
23
|
+
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
24
|
+
return new Generic(params, def, $);
|
|
25
|
+
}
|
|
26
|
+
// otherwise, treat as a tuple expression. technically, this also allows
|
|
27
|
+
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
28
|
+
// part of the API as specified by the associated types
|
|
29
|
+
return $.parseRoot(args);
|
|
30
|
+
}, { bind: $, attach: typeParserAttachments });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
2
33
|
export const Type = RawSchema;
|
|
3
|
-
//# sourceMappingURL=type.js.map
|
package/out/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../type.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../type.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EAST,SAAS,EAcT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,QAAQ,EAIR,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,OAAO,EAAgC,MAAM,cAAc,CAAA;AAMpE,OAAO,EAAE,kBAAkB,E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|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
3
|
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
|
|
4
|
-
"version": "2.0.0-dev.
|
|
4
|
+
"version": "2.0.0-dev.9",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "David Blass",
|
|
@@ -35,10 +35,12 @@
|
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsx ../repo/build.ts",
|
|
38
|
-
"test": "tsx ../repo/testPackage.ts"
|
|
38
|
+
"test": "tsx ../repo/testPackage.ts",
|
|
39
|
+
"latest": "npm dist-tag add arktype@1.0.29-alpha latest",
|
|
40
|
+
"devtag": "npm dist-tag add arktype@2.0.0-dev.8 dev"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@arktype/util": "0.0.
|
|
42
|
-
"@arktype/schema": "0.0
|
|
43
|
+
"@arktype/util": "0.0.35",
|
|
44
|
+
"@arktype/schema": "0.1.0"
|
|
43
45
|
}
|
|
44
46
|
}
|
package/parser/generic.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type keyError, throwParseError } from "@arktype/util"
|
|
2
2
|
import { writeUnexpectedCharacterMessage } from "./string/shift/operator/operator.js"
|
|
3
3
|
import { Scanner } from "./string/shift/scanner.js"
|
|
4
4
|
|
|
@@ -9,14 +9,14 @@ export type GenericDeclaration<
|
|
|
9
9
|
|
|
10
10
|
// we put the error in a tuple so that parseGenericParams always returns a string[]
|
|
11
11
|
export type GenericParamsParseError<message extends string = string> = [
|
|
12
|
-
|
|
12
|
+
keyError<message>
|
|
13
13
|
]
|
|
14
14
|
|
|
15
15
|
export const parseGenericParams = (def: string): string[] =>
|
|
16
|
-
|
|
16
|
+
_parseGenericParams(new Scanner(def))
|
|
17
17
|
|
|
18
18
|
export type parseGenericParams<def extends string> =
|
|
19
|
-
|
|
19
|
+
_parseParams<def, "", []> extends infer result extends string[] ?
|
|
20
20
|
"" extends result[number] ?
|
|
21
21
|
GenericParamsParseError<emptyGenericParameterMessage>
|
|
22
22
|
: result
|
|
@@ -27,41 +27,40 @@ export const emptyGenericParameterMessage =
|
|
|
27
27
|
|
|
28
28
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const _parseGenericParams = (scanner: Scanner): string[] => {
|
|
31
31
|
const param = scanner.shiftUntilNextTerminator()
|
|
32
|
-
if (param === "")
|
|
33
|
-
|
|
34
|
-
}
|
|
32
|
+
if (param === "") throwParseError(emptyGenericParameterMessage)
|
|
33
|
+
|
|
35
34
|
scanner.shiftUntilNonWhitespace()
|
|
36
35
|
const nextNonWhitespace = scanner.shift()
|
|
37
36
|
return (
|
|
38
37
|
nextNonWhitespace === "" ? [param]
|
|
39
|
-
: nextNonWhitespace === "," ? [param,
|
|
38
|
+
: nextNonWhitespace === "," ? [param, ..._parseGenericParams(scanner)]
|
|
40
39
|
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ","))
|
|
41
40
|
)
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
type
|
|
43
|
+
type _parseParams<
|
|
45
44
|
unscanned extends string,
|
|
46
45
|
param extends string,
|
|
47
46
|
result extends string[]
|
|
48
47
|
> =
|
|
49
48
|
unscanned extends `${infer lookahead}${infer nextUnscanned}` ?
|
|
50
|
-
lookahead extends "," ?
|
|
49
|
+
lookahead extends "," ? _parseParams<nextUnscanned, "", [...result, param]>
|
|
51
50
|
: lookahead extends Scanner.WhiteSpaceToken ?
|
|
52
51
|
param extends "" ?
|
|
53
52
|
// if the next char is whitespace and we aren't in the middle of a param, skip to the next one
|
|
54
|
-
|
|
53
|
+
_parseParams<Scanner.skipWhitespace<nextUnscanned>, "", result>
|
|
55
54
|
: Scanner.skipWhitespace<nextUnscanned> extends (
|
|
56
55
|
`${infer nextNonWhitespace}${infer rest}`
|
|
57
56
|
) ?
|
|
58
57
|
nextNonWhitespace extends "," ?
|
|
59
|
-
|
|
58
|
+
_parseParams<rest, "", [...result, param]>
|
|
60
59
|
: GenericParamsParseError<
|
|
61
60
|
writeUnexpectedCharacterMessage<nextNonWhitespace, ",">
|
|
62
61
|
>
|
|
63
62
|
: // params end with a single whitespace character, add the current token
|
|
64
63
|
[...result, param]
|
|
65
|
-
:
|
|
64
|
+
: _parseParams<nextUnscanned, `${param}${lookahead}`, result>
|
|
66
65
|
: param extends "" ? result
|
|
67
66
|
: [...result, param]
|
package/parser/objectLiteral.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type NodeDef,
|
|
3
3
|
type RawSchema,
|
|
4
4
|
tsKeywords,
|
|
5
5
|
type writeInvalidPropertyKeyMessage
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type merge,
|
|
12
12
|
printable,
|
|
13
13
|
type show,
|
|
14
|
+
spliterate,
|
|
14
15
|
stringAndSymbolicEntriesOf,
|
|
15
16
|
throwParseError
|
|
16
17
|
} from "@arktype/util"
|
|
@@ -21,8 +22,8 @@ import type { validateString } from "./semantic/validate.js"
|
|
|
21
22
|
import { Scanner } from "./string/shift/scanner.js"
|
|
22
23
|
|
|
23
24
|
export const parseObjectLiteral = (def: Dict, ctx: ParseContext): RawSchema => {
|
|
24
|
-
const propNodes:
|
|
25
|
-
const indexNodes:
|
|
25
|
+
const propNodes: NodeDef<"prop">[] = []
|
|
26
|
+
const indexNodes: NodeDef<"index">[] = []
|
|
26
27
|
// We only allow a spread operator to be used as the first key in an object
|
|
27
28
|
// because to match JS behavior any keys before the spread are overwritten
|
|
28
29
|
// by the values in the target object, so there'd be no useful purpose in having it
|
|
@@ -46,33 +47,44 @@ export const parseObjectLiteral = (def: Dict, ctx: ParseContext): RawSchema => {
|
|
|
46
47
|
// We filter out keys from the spreadNode that will be defined later on this same object
|
|
47
48
|
// because the currently parsed definition will overwrite them.
|
|
48
49
|
spreadNode.prop?.forEach(
|
|
49
|
-
|
|
50
|
+
spreadRequired =>
|
|
50
51
|
!parsedEntries.some(
|
|
51
52
|
({ inner: innerKey }) => innerKey === spreadRequired.key
|
|
52
53
|
) && propNodes.push(spreadRequired)
|
|
53
54
|
)
|
|
54
55
|
}
|
|
55
56
|
for (const entry of parsedEntries) {
|
|
56
|
-
if (entry.kind === "spread")
|
|
57
|
-
return throwParseError(nonLeadingSpreadError)
|
|
58
|
-
}
|
|
57
|
+
if (entry.kind === "spread") return throwParseError(nonLeadingSpreadError)
|
|
59
58
|
|
|
60
59
|
if (entry.kind === "index") {
|
|
61
60
|
// handle key parsing first to match type behavior
|
|
62
61
|
const key = ctx.$.parse(entry.inner, ctx)
|
|
63
62
|
const value = ctx.$.parse(entry.value, ctx)
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
|
|
64
|
+
// extract enumerable named props from the index signature
|
|
65
|
+
const [enumerable, nonEnumerable] = spliterate(key.branches, k =>
|
|
66
|
+
k.hasKind("unit")
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
if (enumerable.length) {
|
|
70
|
+
propNodes.push(
|
|
71
|
+
...enumerable.map(k =>
|
|
72
|
+
ctx.$.node("prop", { key: k.unit as Key, value })
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
if (nonEnumerable.length)
|
|
76
|
+
indexNodes.push(ctx.$.node("index", { key: nonEnumerable, value }))
|
|
77
|
+
} else indexNodes.push(ctx.$.node("index", { key, value }))
|
|
66
78
|
} else {
|
|
67
79
|
const value = ctx.$.parse(entry.value, ctx)
|
|
68
|
-
|
|
80
|
+
propNodes.push({
|
|
69
81
|
key: entry.inner,
|
|
70
82
|
value,
|
|
71
83
|
optional: entry.kind === "optional"
|
|
72
84
|
})
|
|
73
|
-
propNodes.push(propNode)
|
|
74
85
|
}
|
|
75
86
|
}
|
|
87
|
+
|
|
76
88
|
return ctx.$.schema({
|
|
77
89
|
domain: "object",
|
|
78
90
|
prop: propNodes,
|
|
@@ -172,6 +184,8 @@ const parseKey = (key: Key): PreparsedKey =>
|
|
|
172
184
|
}
|
|
173
185
|
: key[0] === "[" && key.at(-1) === "]" ?
|
|
174
186
|
{ inner: key.slice(1, -1), kind: "index" }
|
|
187
|
+
: key[0] === Scanner.escapeToken && key[1] === "[" && key.at(-1) === "]" ?
|
|
188
|
+
{ inner: key.slice(1), kind: "required" }
|
|
175
189
|
: key === "..." ? { inner: "...", kind: "spread" }
|
|
176
190
|
: { inner: key === "\\..." ? "..." : key, kind: "required" }
|
|
177
191
|
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
charsAfterFirst,
|
|
10
10
|
Completion,
|
|
11
11
|
ErrorMessage,
|
|
12
|
+
isAnyOrNever,
|
|
12
13
|
writeMalformedNumericLiteralMessage
|
|
13
14
|
} from "@arktype/util"
|
|
14
15
|
import type { Comparator } from "../string/reduce/shared.js"
|
|
@@ -81,9 +82,7 @@ type validateStringAst<def extends string, $> =
|
|
|
81
82
|
ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">>
|
|
82
83
|
: undefined
|
|
83
84
|
: maybeExtractAlias<def, $> extends infer alias extends keyof $ ?
|
|
84
|
-
|
|
85
|
-
// handle any/never
|
|
86
|
-
def
|
|
85
|
+
isAnyOrNever<$[alias]> extends true ? def
|
|
87
86
|
: def extends PrivateDeclaration ?
|
|
88
87
|
ErrorMessage<writePrefixedPrivateReferenceMessage<def>>
|
|
89
88
|
: // these problems would've been caught during a fullStringParse, but it's most
|
|
@@ -77,18 +77,17 @@ export class DynamicState {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
finalize(finalizer: Scanner.FinalizingLookahead): void {
|
|
80
|
-
if (this.groups.length)
|
|
81
|
-
|
|
82
|
-
}
|
|
80
|
+
if (this.groups.length) return this.error(writeUnclosedGroupMessage(")"))
|
|
81
|
+
|
|
83
82
|
this.finalizeBranches()
|
|
84
83
|
this.finalizer = finalizer
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void {
|
|
88
87
|
const invertedComparator = invertedComparators[comparator]
|
|
89
|
-
if (!isKeyOf(invertedComparator, minComparators))
|
|
88
|
+
if (!isKeyOf(invertedComparator, minComparators))
|
|
90
89
|
return this.error(writeUnpairableComparatorMessage(comparator))
|
|
91
|
-
|
|
90
|
+
|
|
92
91
|
if (this.branches.leftBound) {
|
|
93
92
|
return this.error(
|
|
94
93
|
writeMultipleLeftBoundsMessage(
|
|
@@ -113,17 +112,15 @@ export class DynamicState {
|
|
|
113
112
|
} else if (this.branches.intersection) {
|
|
114
113
|
this.pushRootToBranch("&")
|
|
115
114
|
this.root = this.branches.intersection
|
|
116
|
-
} else
|
|
117
|
-
this.applyPrefixes()
|
|
118
|
-
}
|
|
115
|
+
} else this.applyPrefixes()
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
finalizeGroup(): void {
|
|
122
119
|
this.finalizeBranches()
|
|
123
120
|
const topBranchState = this.groups.pop()
|
|
124
|
-
if (!topBranchState)
|
|
121
|
+
if (!topBranchState)
|
|
125
122
|
return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned))
|
|
126
|
-
|
|
123
|
+
|
|
127
124
|
this.branches = topBranchState
|
|
128
125
|
}
|
|
129
126
|
|
|
@@ -40,15 +40,12 @@ const maybeParseDate = <errorOnFail extends boolean | string>(
|
|
|
40
40
|
errorOnFail?: errorOnFail
|
|
41
41
|
): DateParseResult<errorOnFail> => {
|
|
42
42
|
const stringParsedDate = new Date(source)
|
|
43
|
-
if (isValidDate(stringParsedDate))
|
|
44
|
-
|
|
45
|
-
}
|
|
43
|
+
if (isValidDate(stringParsedDate)) return stringParsedDate
|
|
44
|
+
|
|
46
45
|
const epochMillis = tryParseNumber(source)
|
|
47
46
|
if (epochMillis !== undefined) {
|
|
48
47
|
const numberParsedDate = new Date(epochMillis)
|
|
49
|
-
if (isValidDate(numberParsedDate))
|
|
50
|
-
return numberParsedDate
|
|
51
|
-
}
|
|
48
|
+
if (isValidDate(numberParsedDate)) return numberParsedDate
|
|
52
49
|
}
|
|
53
50
|
return errorOnFail ?
|
|
54
51
|
throwParseError(
|
|
@@ -21,11 +21,11 @@ export const parseEnclosed = (
|
|
|
21
21
|
const enclosed = s.scanner.shiftUntil(
|
|
22
22
|
untilLookaheadIsClosing[enclosingTokens[enclosing]]
|
|
23
23
|
)
|
|
24
|
-
if (s.scanner.lookahead === "")
|
|
24
|
+
if (s.scanner.lookahead === "")
|
|
25
25
|
return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing))
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
// Shift the scanner one additional time for the second enclosing token
|
|
28
|
-
|
|
28
|
+
s.scanner.shift()
|
|
29
29
|
if (enclosing === "/") {
|
|
30
30
|
// fail parsing if the regex is invalid
|
|
31
31
|
new RegExp(enclosed)
|
|
@@ -37,9 +37,9 @@ export const parseEnclosed = (
|
|
|
37
37
|
},
|
|
38
38
|
{ prereduced: true }
|
|
39
39
|
)
|
|
40
|
-
} else if (isKeyOf(enclosing, enclosingQuote))
|
|
40
|
+
} else if (isKeyOf(enclosing, enclosingQuote))
|
|
41
41
|
s.root = s.ctx.$.node("unit", { unit: enclosed })
|
|
42
|
-
|
|
42
|
+
else {
|
|
43
43
|
const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed))
|
|
44
44
|
s.root = s.ctx.$.node("unit", { unit: date, description: enclosed })
|
|
45
45
|
}
|
|
@@ -93,9 +93,9 @@ export const untilLookaheadIsClosing: Record<
|
|
|
93
93
|
EnclosingEndToken,
|
|
94
94
|
Scanner.UntilCondition
|
|
95
95
|
> = {
|
|
96
|
-
"'":
|
|
97
|
-
'"':
|
|
98
|
-
"/":
|
|
96
|
+
"'": scanner => scanner.lookahead === `'`,
|
|
97
|
+
'"': scanner => scanner.lookahead === `"`,
|
|
98
|
+
"/": scanner => scanner.lookahead === `/`
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const enclosingCharDescriptions = {
|
|
@@ -17,7 +17,7 @@ export const parseGenericArgs = (
|
|
|
17
17
|
name: string,
|
|
18
18
|
params: string[],
|
|
19
19
|
s: DynamicState
|
|
20
|
-
): ParsedArgs<RawSchema[]> =>
|
|
20
|
+
): ParsedArgs<RawSchema[]> => _parseGenericArgs(name, params, s, [], [])
|
|
21
21
|
|
|
22
22
|
export type parseGenericArgs<
|
|
23
23
|
name extends string,
|
|
@@ -25,9 +25,9 @@ export type parseGenericArgs<
|
|
|
25
25
|
unscanned extends string,
|
|
26
26
|
$,
|
|
27
27
|
args
|
|
28
|
-
> =
|
|
28
|
+
> = _parseGenericArgs<name, params, unscanned, $, args, [], []>
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const _parseGenericArgs = (
|
|
31
31
|
name: string,
|
|
32
32
|
params: string[],
|
|
33
33
|
s: DynamicState,
|
|
@@ -47,13 +47,13 @@ const $parseGenericArgs = (
|
|
|
47
47
|
}
|
|
48
48
|
return argState.error(writeInvalidGenericArgsMessage(name, params, argDefs))
|
|
49
49
|
}
|
|
50
|
-
if (argState.finalizer === ",")
|
|
51
|
-
return
|
|
52
|
-
|
|
50
|
+
if (argState.finalizer === ",")
|
|
51
|
+
return _parseGenericArgs(name, params, s, argDefs, argNodes)
|
|
52
|
+
|
|
53
53
|
return argState.error(writeUnclosedGroupMessage(">"))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
type
|
|
56
|
+
type _parseGenericArgs<
|
|
57
57
|
name extends string,
|
|
58
58
|
params extends string[],
|
|
59
59
|
unscanned extends string,
|
|
@@ -85,7 +85,7 @@ type $parseGenericArgs<
|
|
|
85
85
|
ParsedArgs<nextAsts, nextUnscanned>
|
|
86
86
|
: state.error<writeInvalidGenericArgsMessage<name, params, nextDefs>>
|
|
87
87
|
: finalArgState["finalizer"] extends "," ?
|
|
88
|
-
|
|
88
|
+
_parseGenericArgs<
|
|
89
89
|
name,
|
|
90
90
|
params,
|
|
91
91
|
nextUnscanned,
|