arktype 2.0.0-dev.4 → 2.0.0-dev.6
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 +176 -236
- package/__tests__/badDefinitionType.test.ts +10 -3
- package/__tests__/basis.test.ts +6 -2
- package/__tests__/bounds.test.ts +282 -352
- package/__tests__/cast.test.ts +7 -2
- package/__tests__/completions.test.ts +8 -3
- package/__tests__/config.test.ts +16 -8
- package/__tests__/cyclic.test.ts +141 -137
- package/__tests__/dateLiteral.test.ts +8 -4
- package/__tests__/declared.test.ts +2 -2
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +45 -25
- package/__tests__/enclosed.test.ts +39 -25
- package/__tests__/examples.test.ts +56 -56
- package/__tests__/expressions.test.ts +184 -112
- package/__tests__/generic.test.ts +307 -288
- package/__tests__/group.test.ts +67 -54
- package/__tests__/imports.test.ts +44 -37
- package/__tests__/instanceof.test.ts +17 -15
- package/__tests__/intersection.test.ts +50 -46
- package/__tests__/keyTraversal.test.ts +6 -3
- package/__tests__/keyof.test.ts +68 -52
- package/__tests__/keywords.test.ts +149 -136
- package/__tests__/literal.test.ts +38 -15
- package/__tests__/match.test.ts +234 -224
- package/__tests__/morph.test.ts +300 -269
- package/__tests__/narrow.test.ts +46 -42
- package/__tests__/objectLiteral.test.ts +228 -210
- package/__tests__/realWorld.test.ts +63 -0
- package/__tests__/regex.test.ts +17 -7
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +65 -18
- package/__tests__/serialization.test.ts +19 -0
- package/__tests__/string.test.ts +11 -7
- package/__tests__/submodule.test.ts +26 -39
- package/__tests__/this.test.ts +83 -57
- package/__tests__/thunk.test.ts +13 -7
- package/__tests__/traverse.test.ts +50 -37
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +38 -0
- package/__tests__/typeReference.test.ts +7 -7
- package/__tests__/unenclosed.test.ts +116 -100
- package/__tests__/union.test.ts +171 -104
- package/ark.ts +18 -65
- package/generic.ts +67 -0
- package/main.ts +6 -18
- package/match.ts +53 -67
- package/module.ts +15 -0
- package/out/ark.d.ts +12 -36
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +9 -17
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +205 -0
- package/out/base.d.ts.map +1 -0
- package/out/base.js +320 -0
- package/out/base.js.map +1 -0
- package/out/builtins/builtins.d.ts +23 -0
- package/out/builtins/builtins.d.ts.map +1 -0
- package/out/builtins/builtins.js +15 -0
- package/out/builtins/builtins.js.map +1 -0
- package/out/builtins/jsObjects.d.ts +19 -0
- package/out/builtins/jsObjects.d.ts.map +1 -0
- package/out/builtins/jsObjects.js +18 -0
- package/out/builtins/jsObjects.js.map +1 -0
- package/out/builtins/parsing.d.ts +16 -0
- package/out/builtins/parsing.d.ts.map +1 -0
- package/out/builtins/parsing.js +62 -0
- package/out/builtins/parsing.js.map +1 -0
- package/out/builtins/tsGenerics.d.ts +2 -0
- package/out/builtins/tsGenerics.d.ts.map +1 -0
- package/out/builtins/tsGenerics.js +26 -0
- package/out/builtins/tsGenerics.js.map +1 -0
- package/out/builtins/tsKeywords.d.ts +23 -0
- package/out/builtins/tsKeywords.d.ts.map +1 -0
- package/out/builtins/tsKeywords.js +23 -0
- package/out/builtins/tsKeywords.js.map +1 -0
- package/out/builtins/utils/creditCard.d.ts +3 -0
- package/out/builtins/utils/creditCard.d.ts.map +1 -0
- package/out/builtins/utils/creditCard.js +35 -0
- package/out/builtins/utils/creditCard.js.map +1 -0
- package/out/builtins/utils/date.d.ts +41 -0
- package/out/builtins/utils/date.d.ts.map +1 -0
- package/out/builtins/utils/date.js +56 -0
- package/out/builtins/utils/date.js.map +1 -0
- package/out/builtins/validation.d.ts +19 -0
- package/out/builtins/validation.d.ts.map +1 -0
- package/out/builtins/validation.js +74 -0
- package/out/builtins/validation.js.map +1 -0
- package/out/config.d.ts +9 -0
- package/out/config.d.ts.map +1 -0
- package/out/config.js +18 -0
- package/out/config.js.map +1 -0
- package/out/constraints/ast.d.ts +287 -0
- package/out/constraints/ast.d.ts.map +1 -0
- package/out/constraints/ast.js +2 -0
- package/out/constraints/ast.js.map +1 -0
- package/out/constraints/constraint.d.ts +200 -0
- package/out/constraints/constraint.d.ts.map +1 -0
- package/out/constraints/constraint.js +25 -0
- package/out/constraints/constraint.js.map +1 -0
- package/out/constraints/predicate.d.ts +64 -0
- package/out/constraints/predicate.d.ts.map +1 -0
- package/out/constraints/predicate.js +52 -0
- package/out/constraints/predicate.js.map +1 -0
- package/out/constraints/props/index.d.ts +42 -0
- package/out/constraints/props/index.d.ts.map +1 -0
- package/out/constraints/props/index.js +56 -0
- package/out/constraints/props/index.js.map +1 -0
- package/out/constraints/props/optional.d.ts +37 -0
- package/out/constraints/props/optional.d.ts.map +1 -0
- package/out/constraints/props/optional.js +56 -0
- package/out/constraints/props/optional.js.map +1 -0
- package/out/constraints/props/prop.d.ts +49 -0
- package/out/constraints/props/prop.d.ts.map +1 -0
- package/out/constraints/props/prop.js +106 -0
- package/out/constraints/props/prop.js.map +1 -0
- package/out/constraints/props/props.d.ts +37 -0
- package/out/constraints/props/props.d.ts.map +1 -0
- package/out/constraints/props/props.js +121 -0
- package/out/constraints/props/props.js.map +1 -0
- package/out/constraints/props/required.d.ts +46 -0
- package/out/constraints/props/required.d.ts.map +1 -0
- package/out/constraints/props/required.js +81 -0
- package/out/constraints/props/required.js.map +1 -0
- package/out/constraints/props/sequence.d.ts +82 -0
- package/out/constraints/props/sequence.d.ts.map +1 -0
- package/out/constraints/props/sequence.js +376 -0
- package/out/constraints/props/sequence.js.map +1 -0
- package/out/constraints/props/shared.d.ts +3 -0
- package/out/constraints/props/shared.d.ts.map +1 -0
- package/out/constraints/props/shared.js +4 -0
- package/out/constraints/props/shared.js.map +1 -0
- package/out/constraints/refinements/after.d.ts +33 -0
- package/out/constraints/refinements/after.d.ts.map +1 -0
- package/out/constraints/refinements/after.js +36 -0
- package/out/constraints/refinements/after.js.map +1 -0
- package/out/constraints/refinements/before.d.ts +33 -0
- package/out/constraints/refinements/before.d.ts.map +1 -0
- package/out/constraints/refinements/before.js +43 -0
- package/out/constraints/refinements/before.js.map +1 -0
- package/out/constraints/refinements/divisor.d.ts +52 -0
- package/out/constraints/refinements/divisor.d.ts.map +1 -0
- package/out/constraints/refinements/divisor.js +52 -0
- package/out/constraints/refinements/divisor.js.map +1 -0
- package/out/constraints/refinements/exactLength.d.ts +45 -0
- package/out/constraints/refinements/exactLength.d.ts.map +1 -0
- package/out/constraints/refinements/exactLength.js +52 -0
- package/out/constraints/refinements/exactLength.js.map +1 -0
- package/out/constraints/refinements/kinds.d.ts +29 -0
- package/out/constraints/refinements/kinds.d.ts.map +1 -0
- package/out/constraints/refinements/kinds.js +17 -0
- package/out/constraints/refinements/kinds.js.map +1 -0
- package/out/constraints/refinements/length.d.ts +48 -0
- package/out/constraints/refinements/length.d.ts.map +1 -0
- package/out/constraints/refinements/length.js +53 -0
- package/out/constraints/refinements/length.js.map +1 -0
- package/out/constraints/refinements/max.d.ts +31 -0
- package/out/constraints/refinements/max.d.ts.map +1 -0
- package/out/constraints/refinements/max.js +35 -0
- package/out/constraints/refinements/max.js.map +1 -0
- package/out/constraints/refinements/maxLength.d.ts +32 -0
- package/out/constraints/refinements/maxLength.d.ts.map +1 -0
- package/out/constraints/refinements/maxLength.js +36 -0
- package/out/constraints/refinements/maxLength.js.map +1 -0
- package/out/constraints/refinements/min.d.ts +31 -0
- package/out/constraints/refinements/min.d.ts.map +1 -0
- package/out/constraints/refinements/min.js +28 -0
- package/out/constraints/refinements/min.js.map +1 -0
- package/out/constraints/refinements/minLength.d.ts +32 -0
- package/out/constraints/refinements/minLength.d.ts.map +1 -0
- package/out/constraints/refinements/minLength.js +33 -0
- package/out/constraints/refinements/minLength.js.map +1 -0
- package/out/constraints/refinements/range.d.ts +119 -0
- package/out/constraints/refinements/range.d.ts.map +1 -0
- package/out/constraints/refinements/range.js +89 -0
- package/out/constraints/refinements/range.js.map +1 -0
- package/out/constraints/refinements/regex.d.ts +47 -0
- package/out/constraints/refinements/regex.d.ts.map +1 -0
- package/out/constraints/refinements/regex.js +37 -0
- package/out/constraints/refinements/regex.js.map +1 -0
- package/out/constraints/refinements/shared.d.ts +20 -0
- package/out/constraints/refinements/shared.d.ts.map +1 -0
- package/out/constraints/refinements/shared.js +10 -0
- package/out/constraints/refinements/shared.js.map +1 -0
- package/out/generic.d.ts +22 -0
- package/out/generic.d.ts.map +1 -0
- package/out/generic.js +23 -0
- package/out/generic.js.map +1 -0
- package/out/inference.d.ts +137 -0
- package/out/inference.d.ts.map +1 -0
- package/out/inference.js +73 -0
- package/out/inference.js.map +1 -0
- package/out/keywords/ark.d.ts +70 -0
- package/out/keywords/ark.d.ts.map +1 -0
- package/out/keywords/ark.js +29 -0
- package/out/keywords/ark.js.map +1 -0
- package/out/keywords/internal.d.ts +13 -0
- package/out/keywords/internal.d.ts.map +1 -0
- package/out/keywords/internal.js +13 -0
- package/out/keywords/internal.js.map +1 -0
- package/out/keywords/jsObject.d.ts +20 -0
- package/out/keywords/jsObject.d.ts.map +1 -0
- package/out/keywords/jsObject.js +18 -0
- package/out/keywords/jsObject.js.map +1 -0
- package/out/keywords/parsing.d.ts +17 -0
- package/out/keywords/parsing.d.ts.map +1 -0
- package/out/keywords/parsing.js +64 -0
- package/out/keywords/parsing.js.map +1 -0
- package/out/keywords/root.d.ts +7 -0
- package/out/keywords/root.d.ts.map +1 -0
- package/out/keywords/root.js +4 -0
- package/out/keywords/root.js.map +1 -0
- package/out/keywords/tsGenerics.d.ts +2 -0
- package/out/keywords/tsGenerics.d.ts.map +1 -0
- package/out/keywords/tsGenerics.js +26 -0
- package/out/keywords/tsGenerics.js.map +1 -0
- package/out/keywords/tsPrimitive.d.ts +24 -0
- package/out/keywords/tsPrimitive.d.ts.map +1 -0
- package/out/keywords/tsPrimitive.js +25 -0
- package/out/keywords/tsPrimitive.js.map +1 -0
- package/out/keywords/utils/creditCard.d.ts +11 -0
- package/out/keywords/utils/creditCard.d.ts.map +1 -0
- package/out/keywords/utils/creditCard.js +35 -0
- package/out/keywords/utils/creditCard.js.map +1 -0
- package/out/keywords/utils/date.d.ts +45 -0
- package/out/keywords/utils/date.d.ts.map +1 -0
- package/out/keywords/utils/date.js +56 -0
- package/out/keywords/utils/date.js.map +1 -0
- package/out/keywords/validation.d.ts +20 -0
- package/out/keywords/validation.d.ts.map +1 -0
- package/out/keywords/validation.js +80 -0
- package/out/keywords/validation.js.map +1 -0
- package/out/kinds.d.ts +102 -0
- package/out/kinds.d.ts.map +1 -0
- package/out/kinds.js +29 -0
- package/out/kinds.js.map +1 -0
- package/out/main.d.ts +6 -6
- package/out/main.d.ts.map +1 -1
- package/out/main.js +4 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +18 -23
- package/out/match.d.ts.map +1 -1
- package/out/match.js +3 -4
- package/out/match.js.map +1 -1
- package/out/module.d.ts +11 -0
- package/out/module.d.ts.map +1 -0
- package/out/module.js +4 -0
- package/out/module.js.map +1 -0
- package/out/parse.d.ts +29 -0
- package/out/parse.d.ts.map +1 -0
- package/out/parse.js +161 -0
- package/out/parse.js.map +1 -0
- package/out/parser/definition.d.ts +9 -12
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +10 -12
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +3 -4
- package/out/parser/generic.d.ts.map +1 -1
- package/out/parser/generic.js +6 -8
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +44 -12
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +43 -36
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +9 -6
- package/out/parser/semantic/bounds.d.ts.map +1 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +5 -6
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +25 -0
- package/out/parser/semantic/infer.d.ts.map +1 -0
- package/out/parser/semantic/infer.js +2 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -6
- package/out/parser/semantic/utils.d.ts.map +1 -1
- package/out/parser/semantic/validate.d.ts +14 -12
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js +1 -0
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -12
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +27 -17
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +1 -2
- package/out/parser/string/reduce/shared.d.ts.map +1 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +26 -22
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -1
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js +2 -2
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +6 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -9
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js +6 -8
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -3
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js +8 -11
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +13 -20
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +21 -26
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +15 -12
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +42 -48
- 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.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -1
- package/out/parser/string/shift/operator/operator.js +12 -18
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js +12 -11
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +8 -5
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +96 -37
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +61 -66
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +175 -0
- package/out/schema.d.ts.map +1 -0
- package/out/schema.js +73 -0
- package/out/schema.js.map +1 -0
- package/out/schemaScope.d.ts +180 -0
- package/out/schemaScope.d.ts.map +1 -0
- package/out/schemaScope.js +235 -0
- package/out/schemaScope.js.map +1 -0
- package/out/scope.d.ts +42 -114
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +51 -181
- package/out/scope.js.map +1 -1
- package/out/shared/compile.d.ts +22 -0
- package/out/shared/compile.d.ts.map +1 -0
- package/out/shared/compile.js +79 -0
- package/out/shared/compile.js.map +1 -0
- package/out/shared/context.d.ts +54 -0
- package/out/shared/context.d.ts.map +1 -0
- package/out/shared/context.js +53 -0
- package/out/shared/context.js.map +1 -0
- package/out/shared/declare.d.ts +69 -0
- package/out/shared/declare.d.ts.map +1 -0
- package/out/shared/declare.js +2 -0
- package/out/shared/declare.js.map +1 -0
- package/out/shared/disjoint.d.ts +91 -0
- package/out/shared/disjoint.d.ts.map +1 -0
- package/out/shared/disjoint.js +110 -0
- package/out/shared/disjoint.js.map +1 -0
- package/out/shared/errors.d.ts +99 -0
- package/out/shared/errors.d.ts.map +1 -0
- package/out/shared/errors.js +108 -0
- package/out/shared/errors.js.map +1 -0
- package/out/shared/implement.d.ts +363 -0
- package/out/shared/implement.d.ts.map +1 -0
- package/out/shared/implement.js +68 -0
- package/out/shared/implement.js.map +1 -0
- package/out/shared/inference.d.ts +6 -0
- package/out/shared/inference.d.ts.map +1 -0
- package/out/shared/inference.js +5 -0
- package/out/shared/inference.js.map +1 -0
- package/out/shared/intersections.d.ts +60 -0
- package/out/shared/intersections.d.ts.map +1 -0
- package/out/shared/intersections.js +2 -0
- package/out/shared/intersections.js.map +1 -0
- package/out/shared/traversal.d.ts +62 -0
- package/out/shared/traversal.d.ts.map +1 -0
- package/out/shared/traversal.js +97 -0
- package/out/shared/traversal.js.map +1 -0
- package/out/shared/utils.d.ts +24 -0
- package/out/shared/utils.d.ts.map +1 -0
- package/out/shared/utils.js +15 -0
- package/out/shared/utils.js.map +1 -0
- package/out/type.d.ts +23 -59
- package/out/type.d.ts.map +1 -1
- package/out/type.js +2 -137
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +47 -0
- package/out/types/basis.d.ts.map +1 -0
- package/out/types/basis.js +15 -0
- package/out/types/basis.js.map +1 -0
- package/out/types/discriminate.d.ts +34 -0
- package/out/types/discriminate.d.ts.map +1 -0
- package/out/types/discriminate.js +120 -0
- package/out/types/discriminate.js.map +1 -0
- package/out/types/domain.d.ts +57 -0
- package/out/types/domain.d.ts.map +1 -0
- package/out/types/domain.js +41 -0
- package/out/types/domain.js.map +1 -0
- package/out/types/intersection.d.ts +127 -0
- package/out/types/intersection.d.ts.map +1 -0
- package/out/types/intersection.js +379 -0
- package/out/types/intersection.js.map +1 -0
- package/out/types/morph.d.ts +157 -0
- package/out/types/morph.d.ts.map +1 -0
- package/out/types/morph.js +99 -0
- package/out/types/morph.js.map +1 -0
- package/out/types/proto.d.ts +51 -0
- package/out/types/proto.d.ts.map +1 -0
- package/out/types/proto.js +60 -0
- package/out/types/proto.js.map +1 -0
- package/out/types/type.d.ts +143 -0
- package/out/types/type.d.ts.map +1 -0
- package/out/types/type.js +123 -0
- package/out/types/type.js.map +1 -0
- package/out/types/union.d.ts +71 -0
- package/out/types/union.d.ts.map +1 -0
- package/out/types/union.js +379 -0
- package/out/types/union.js.map +1 -0
- package/out/types/unit.d.ts +45 -0
- package/out/types/unit.d.ts.map +1 -0
- package/out/types/unit.js +56 -0
- package/out/types/unit.js.map +1 -0
- package/out/util.d.ts +30 -18
- package/out/util.d.ts.map +1 -1
- package/out/util.js +8 -7
- package/out/util.js.map +1 -1
- package/package.json +7 -3
- package/parser/definition.ts +73 -89
- package/parser/generic.ts +35 -36
- package/parser/objectLiteral.ts +143 -117
- package/parser/semantic/bounds.ts +33 -32
- package/parser/semantic/divisor.ts +8 -10
- package/parser/semantic/infer.ts +141 -0
- package/parser/semantic/utils.ts +12 -23
- package/parser/semantic/validate.ts +82 -73
- package/parser/string/reduce/dynamic.ts +61 -46
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +65 -67
- package/parser/string/shift/operand/date.ts +12 -8
- package/parser/string/shift/operand/enclosed.ts +22 -17
- package/parser/string/shift/operand/genericArgs.ts +46 -45
- package/parser/string/shift/operand/operand.ts +32 -38
- package/parser/string/shift/operand/unenclosed.ts +106 -147
- package/parser/string/shift/operator/bounds.ts +114 -106
- package/parser/string/shift/operator/divisor.ts +12 -14
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +49 -46
- package/parser/string/string.ts +28 -32
- package/parser/tuple.ts +288 -308
- package/scope.ts +183 -425
- package/type.ts +82 -281
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/typeMethods.test.ts +0 -69
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -32
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/shared.d.ts +0 -62
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -56
- package/out/parser/shared.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/parser/semantic/semantic.ts +0 -143
- package/parser/shared.ts +0 -170
- package/util.ts +0 -36
|
@@ -1,43 +1,48 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LimitLiteral, RawSchema } from "@arktype/schema"
|
|
2
2
|
import {
|
|
3
3
|
isKeyOf,
|
|
4
|
+
type requireKeys,
|
|
4
5
|
throwInternalError,
|
|
5
|
-
throwParseError
|
|
6
|
-
type requireKeys
|
|
6
|
+
throwParseError
|
|
7
7
|
} from "@arktype/util"
|
|
8
8
|
import type { ParseContext } from "../../../scope.js"
|
|
9
|
+
import type { InfixOperator } from "../../semantic/infer.js"
|
|
9
10
|
import { parseOperand } from "../shift/operand/operand.js"
|
|
10
11
|
import { parseOperator } from "../shift/operator/operator.js"
|
|
11
12
|
import { Scanner } from "../shift/scanner.js"
|
|
12
13
|
import { parseUntilFinalizer } from "../string.js"
|
|
13
14
|
import {
|
|
15
|
+
type Comparator,
|
|
16
|
+
type MinComparator,
|
|
17
|
+
type OpenLeftBound,
|
|
18
|
+
type StringifiablePrefixOperator,
|
|
14
19
|
invertedComparators,
|
|
15
20
|
minComparators,
|
|
16
21
|
writeMultipleLeftBoundsMessage,
|
|
17
22
|
writeOpenRangeMessage,
|
|
18
23
|
writeUnclosedGroupMessage,
|
|
19
24
|
writeUnmatchedGroupCloseMessage,
|
|
20
|
-
writeUnpairableComparatorMessage
|
|
21
|
-
type Comparator,
|
|
22
|
-
type LimitLiteral,
|
|
23
|
-
type OpenLeftBound,
|
|
24
|
-
type StringifiablePrefixOperator
|
|
25
|
+
writeUnpairableComparatorMessage
|
|
25
26
|
} from "./shared.js"
|
|
26
27
|
|
|
27
28
|
type BranchState = {
|
|
28
29
|
prefixes: StringifiablePrefixOperator[]
|
|
29
|
-
leftBound
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
leftBound: OpenLeftBound | null
|
|
31
|
+
intersection: RawSchema | null
|
|
32
|
+
union: RawSchema | null
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">
|
|
35
36
|
|
|
36
37
|
export class DynamicState {
|
|
37
38
|
readonly scanner: Scanner
|
|
38
|
-
root
|
|
39
|
+
// set root type to `any` so that all constraints can be applied
|
|
40
|
+
root: RawSchema<any> | undefined
|
|
39
41
|
branches: BranchState = {
|
|
40
|
-
prefixes: []
|
|
42
|
+
prefixes: [],
|
|
43
|
+
leftBound: null,
|
|
44
|
+
intersection: null,
|
|
45
|
+
union: null
|
|
41
46
|
}
|
|
42
47
|
finalizer: Scanner.FinalizingLookahead | undefined
|
|
43
48
|
groups: BranchState[] = []
|
|
@@ -49,7 +54,7 @@ export class DynamicState {
|
|
|
49
54
|
this.scanner = new Scanner(def)
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
error(message: string) {
|
|
57
|
+
error(message: string): never {
|
|
53
58
|
return throwParseError(message)
|
|
54
59
|
}
|
|
55
60
|
|
|
@@ -57,21 +62,21 @@ export class DynamicState {
|
|
|
57
62
|
return this.root !== undefined
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
setRoot(root: RawSchema): void {
|
|
66
|
+
this.root = root
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
unsetRoot(): this["root"] {
|
|
61
70
|
const value = this.root
|
|
62
71
|
this.root = undefined
|
|
63
72
|
return value
|
|
64
73
|
}
|
|
65
74
|
|
|
66
|
-
constrainRoot(...args: Parameters<
|
|
67
|
-
this.root = this.root!.constrain(
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
setRoot(root: TypeNode) {
|
|
71
|
-
this.root = root
|
|
75
|
+
constrainRoot(...args: Parameters<RawSchema<any>["constrain"]>): void {
|
|
76
|
+
this.root = this.root!.constrain(args[0], args[1])
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
finalize(finalizer: Scanner.FinalizingLookahead) {
|
|
79
|
+
finalize(finalizer: Scanner.FinalizingLookahead): void {
|
|
75
80
|
if (this.groups.length) {
|
|
76
81
|
return this.error(writeUnclosedGroupMessage(")"))
|
|
77
82
|
}
|
|
@@ -79,7 +84,7 @@ export class DynamicState {
|
|
|
79
84
|
this.finalizer = finalizer
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
reduceLeftBound(limit: LimitLiteral, comparator: Comparator) {
|
|
87
|
+
reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void {
|
|
83
88
|
const invertedComparator = invertedComparators[comparator]
|
|
84
89
|
if (!isKeyOf(invertedComparator, minComparators)) {
|
|
85
90
|
return this.error(writeUnpairableComparatorMessage(comparator))
|
|
@@ -100,20 +105,20 @@ export class DynamicState {
|
|
|
100
105
|
}
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
finalizeBranches() {
|
|
108
|
+
finalizeBranches(): void {
|
|
104
109
|
this.assertRangeUnset()
|
|
105
|
-
if (this.branches
|
|
110
|
+
if (this.branches.union) {
|
|
106
111
|
this.pushRootToBranch("|")
|
|
107
|
-
this.root = this.branches
|
|
108
|
-
} else if (this.branches
|
|
112
|
+
this.root = this.branches.union
|
|
113
|
+
} else if (this.branches.intersection) {
|
|
109
114
|
this.pushRootToBranch("&")
|
|
110
|
-
this.root = this.branches
|
|
115
|
+
this.root = this.branches.intersection
|
|
111
116
|
} else {
|
|
112
117
|
this.applyPrefixes()
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
120
|
|
|
116
|
-
finalizeGroup() {
|
|
121
|
+
finalizeGroup(): void {
|
|
117
122
|
this.finalizeBranches()
|
|
118
123
|
const topBranchState = this.groups.pop()
|
|
119
124
|
if (!topBranchState) {
|
|
@@ -122,44 +127,45 @@ export class DynamicState {
|
|
|
122
127
|
this.branches = topBranchState
|
|
123
128
|
}
|
|
124
129
|
|
|
125
|
-
addPrefix(prefix: StringifiablePrefixOperator) {
|
|
130
|
+
addPrefix(prefix: StringifiablePrefixOperator): void {
|
|
126
131
|
this.branches.prefixes.push(prefix)
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
applyPrefixes() {
|
|
134
|
+
applyPrefixes(): void {
|
|
130
135
|
while (this.branches.prefixes.length) {
|
|
131
136
|
const lastPrefix = this.branches.prefixes.pop()!
|
|
132
137
|
this.root =
|
|
133
|
-
lastPrefix === "keyof"
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
lastPrefix === "keyof" ?
|
|
139
|
+
this.root!.keyof()
|
|
140
|
+
: throwInternalError(`Unexpected prefix '${lastPrefix}'`)
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
|
|
139
|
-
pushRootToBranch(token: "|" | "&") {
|
|
144
|
+
pushRootToBranch(token: "|" | "&"): void {
|
|
140
145
|
this.assertRangeUnset()
|
|
141
146
|
this.applyPrefixes()
|
|
142
147
|
const root = this.root!
|
|
143
|
-
this.branches
|
|
148
|
+
this.branches.intersection = this.branches.intersection?.and(root) ?? root
|
|
144
149
|
if (token === "|") {
|
|
145
|
-
this.branches
|
|
146
|
-
this.branches
|
|
147
|
-
|
|
150
|
+
this.branches.union =
|
|
151
|
+
this.branches.union?.or(this.branches.intersection) ??
|
|
152
|
+
this.branches.intersection
|
|
153
|
+
this.branches.intersection = null
|
|
148
154
|
}
|
|
149
155
|
this.root = undefined
|
|
150
156
|
}
|
|
151
157
|
|
|
152
|
-
parseUntilFinalizer() {
|
|
158
|
+
parseUntilFinalizer(): DynamicStateWithRoot {
|
|
153
159
|
return parseUntilFinalizer(
|
|
154
160
|
new DynamicState(this.scanner.unscanned, this.ctx)
|
|
155
161
|
)
|
|
156
162
|
}
|
|
157
163
|
|
|
158
|
-
parseOperator(this: DynamicStateWithRoot) {
|
|
164
|
+
parseOperator(this: DynamicStateWithRoot): void {
|
|
159
165
|
return parseOperator(this)
|
|
160
166
|
}
|
|
161
167
|
|
|
162
|
-
parseOperand() {
|
|
168
|
+
parseOperand(): void {
|
|
163
169
|
return parseOperand(this)
|
|
164
170
|
}
|
|
165
171
|
|
|
@@ -174,22 +180,31 @@ export class DynamicState {
|
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
|
|
177
|
-
reduceGroupOpen() {
|
|
183
|
+
reduceGroupOpen(): void {
|
|
178
184
|
this.groups.push(this.branches)
|
|
179
185
|
this.branches = {
|
|
180
|
-
prefixes: []
|
|
186
|
+
prefixes: [],
|
|
187
|
+
leftBound: null,
|
|
188
|
+
union: null,
|
|
189
|
+
intersection: null
|
|
181
190
|
}
|
|
182
191
|
}
|
|
183
192
|
|
|
184
|
-
previousOperator()
|
|
193
|
+
previousOperator():
|
|
194
|
+
| MinComparator
|
|
195
|
+
| StringifiablePrefixOperator
|
|
196
|
+
| InfixOperator
|
|
197
|
+
| undefined {
|
|
185
198
|
return (
|
|
186
199
|
this.branches.leftBound?.comparator ??
|
|
187
200
|
this.branches.prefixes.at(-1) ??
|
|
188
|
-
(this.branches
|
|
201
|
+
(this.branches.intersection ? "&"
|
|
202
|
+
: this.branches.union ? "|"
|
|
203
|
+
: undefined)
|
|
189
204
|
)
|
|
190
205
|
}
|
|
191
206
|
|
|
192
|
-
shiftedByOne() {
|
|
207
|
+
shiftedByOne(): this {
|
|
193
208
|
this.scanner.shift()
|
|
194
209
|
return this
|
|
195
210
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LimitLiteral } from "@arktype/schema"
|
|
2
2
|
|
|
3
3
|
export type StringifiablePrefixOperator = "keyof"
|
|
4
4
|
|
|
@@ -34,8 +34,6 @@ export const invertedComparators = {
|
|
|
34
34
|
|
|
35
35
|
export type InvertedComparators = typeof invertedComparators
|
|
36
36
|
|
|
37
|
-
export type LimitLiteral = number | DateLiteral
|
|
38
|
-
|
|
39
37
|
export type OpenLeftBound = { limit: LimitLiteral; comparator: MinComparator }
|
|
40
38
|
|
|
41
39
|
export const writeUnmatchedGroupCloseMessage = <unscanned extends string>(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LimitLiteral } from "@arktype/schema"
|
|
2
|
+
import type { Completion, ErrorMessage, defined } from "@arktype/util"
|
|
2
3
|
import type { Scanner } from "../shift/scanner.js"
|
|
3
4
|
import type {
|
|
4
5
|
Comparator,
|
|
5
6
|
InvertedComparators,
|
|
6
|
-
LimitLiteral,
|
|
7
7
|
MaxComparator,
|
|
8
8
|
MinComparator,
|
|
9
9
|
OpenLeftBound,
|
|
@@ -27,8 +27,8 @@ export type StaticState = {
|
|
|
27
27
|
type BranchState = {
|
|
28
28
|
prefixes: StringifiablePrefixOperator[]
|
|
29
29
|
leftBound: OpenLeftBound | undefined
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
intersection: unknown
|
|
31
|
+
union: unknown
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export type AutocompletePrefix = `${StringifiablePrefixOperator} `
|
|
@@ -64,17 +64,18 @@ export namespace state {
|
|
|
64
64
|
type initialBranches = branchesFrom<{
|
|
65
65
|
prefixes: []
|
|
66
66
|
leftBound: undefined
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
intersection: undefined
|
|
68
|
+
union: undefined
|
|
69
69
|
}>
|
|
70
70
|
|
|
71
71
|
type updateScanned<
|
|
72
72
|
previousScanned extends string,
|
|
73
73
|
previousUnscanned extends string,
|
|
74
74
|
updatedUnscanned extends string
|
|
75
|
-
> =
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
> =
|
|
76
|
+
previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ?
|
|
77
|
+
`${previousScanned}${justScanned}`
|
|
78
|
+
: previousScanned
|
|
78
79
|
|
|
79
80
|
export type setRoot<
|
|
80
81
|
s extends StaticState,
|
|
@@ -98,8 +99,8 @@ export namespace state {
|
|
|
98
99
|
branches: {
|
|
99
100
|
prefixes: [...s["branches"]["prefixes"], prefix]
|
|
100
101
|
leftBound: s["branches"]["leftBound"]
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
intersection: s["branches"]["intersection"]
|
|
103
|
+
union: s["branches"]["union"]
|
|
103
104
|
}
|
|
104
105
|
groups: s["groups"]
|
|
105
106
|
finalizer: s["finalizer"]
|
|
@@ -111,38 +112,40 @@ export namespace state {
|
|
|
111
112
|
s extends StaticState,
|
|
112
113
|
token extends "|" | "&",
|
|
113
114
|
unscanned extends string
|
|
114
|
-
> =
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
> =
|
|
116
|
+
s["branches"]["leftBound"] extends {} ?
|
|
117
|
+
openRangeError<s["branches"]["leftBound"]>
|
|
118
|
+
: from<{
|
|
117
119
|
root: undefined
|
|
118
120
|
branches: {
|
|
119
121
|
prefixes: []
|
|
120
122
|
leftBound: undefined
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
intersection: token extends "&" ? mergeToIntersection<s> : undefined
|
|
124
|
+
union: token extends "|" ? mergeToUnion<s> : s["branches"]["union"]
|
|
123
125
|
}
|
|
124
126
|
groups: s["groups"]
|
|
125
127
|
finalizer: s["finalizer"]
|
|
126
128
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
|
|
127
129
|
unscanned: unscanned
|
|
128
|
-
|
|
130
|
+
}>
|
|
129
131
|
|
|
130
132
|
export type reduceLeftBound<
|
|
131
133
|
s extends StaticState,
|
|
132
134
|
limit extends LimitLiteral,
|
|
133
135
|
comparator extends Comparator,
|
|
134
136
|
unscanned extends string
|
|
135
|
-
> =
|
|
136
|
-
|
|
137
|
-
?
|
|
137
|
+
> =
|
|
138
|
+
comparator extends "<" | "<=" ?
|
|
139
|
+
s["branches"]["leftBound"] extends {} ?
|
|
140
|
+
state.error<
|
|
138
141
|
writeMultipleLeftBoundsMessage<
|
|
139
142
|
s["branches"]["leftBound"]["limit"],
|
|
140
143
|
s["branches"]["leftBound"]["comparator"],
|
|
141
144
|
limit,
|
|
142
145
|
InvertedComparators[comparator]
|
|
143
146
|
>
|
|
144
|
-
|
|
145
|
-
:
|
|
147
|
+
>
|
|
148
|
+
: from<{
|
|
146
149
|
root: undefined
|
|
147
150
|
branches: {
|
|
148
151
|
prefixes: s["branches"]["prefixes"]
|
|
@@ -150,15 +153,15 @@ export namespace state {
|
|
|
150
153
|
limit: limit
|
|
151
154
|
comparator: InvertedComparators[comparator]
|
|
152
155
|
}
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
intersection: s["branches"]["intersection"]
|
|
157
|
+
union: s["branches"]["union"]
|
|
155
158
|
}
|
|
156
159
|
groups: s["groups"]
|
|
157
160
|
finalizer: s["finalizer"]
|
|
158
161
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
|
|
159
162
|
unscanned: unscanned
|
|
160
|
-
|
|
161
|
-
:
|
|
163
|
+
}>
|
|
164
|
+
: state.error<writeUnpairableComparatorMessage<comparator>>
|
|
162
165
|
|
|
163
166
|
export type reduceRange<
|
|
164
167
|
s extends StaticState,
|
|
@@ -172,8 +175,8 @@ export namespace state {
|
|
|
172
175
|
branches: {
|
|
173
176
|
prefixes: s["branches"]["prefixes"]
|
|
174
177
|
leftBound: undefined
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
intersection: s["branches"]["intersection"]
|
|
179
|
+
union: s["branches"]["union"]
|
|
177
180
|
}
|
|
178
181
|
groups: s["groups"]
|
|
179
182
|
finalizer: s["finalizer"]
|
|
@@ -184,15 +187,15 @@ export namespace state {
|
|
|
184
187
|
export type reduceSingleBound<
|
|
185
188
|
s extends StaticState,
|
|
186
189
|
comparator extends Comparator,
|
|
187
|
-
limit extends
|
|
190
|
+
limit extends number | string,
|
|
188
191
|
unscanned extends string
|
|
189
192
|
> = state.from<{
|
|
190
193
|
root: [s["root"], comparator, limit]
|
|
191
194
|
branches: {
|
|
192
195
|
prefixes: s["branches"]["prefixes"]
|
|
193
196
|
leftBound: undefined
|
|
194
|
-
|
|
195
|
-
|
|
197
|
+
intersection: s["branches"]["intersection"]
|
|
198
|
+
union: s["branches"]["union"]
|
|
196
199
|
}
|
|
197
200
|
groups: s["groups"]
|
|
198
201
|
finalizer: s["finalizer"]
|
|
@@ -201,42 +204,39 @@ export namespace state {
|
|
|
201
204
|
}>
|
|
202
205
|
|
|
203
206
|
type mergeToUnion<s extends StaticState> =
|
|
204
|
-
s["branches"]["
|
|
205
|
-
|
|
206
|
-
: [s["branches"]["|"], "|", mergeToIntersection<s>]
|
|
207
|
+
s["branches"]["union"] extends undefined ? mergeToIntersection<s>
|
|
208
|
+
: [s["branches"]["union"], "|", mergeToIntersection<s>]
|
|
207
209
|
|
|
208
210
|
type mergeToIntersection<s extends StaticState> =
|
|
209
|
-
s["branches"]["
|
|
210
|
-
|
|
211
|
-
: [s["branches"]["&"], "&", mergePrefixes<s>]
|
|
211
|
+
s["branches"]["intersection"] extends undefined ? mergePrefixes<s>
|
|
212
|
+
: [s["branches"]["intersection"], "&", mergePrefixes<s>]
|
|
212
213
|
|
|
213
214
|
type mergePrefixes<
|
|
214
215
|
s extends StaticState,
|
|
215
216
|
remaining extends unknown[] = s["branches"]["prefixes"]
|
|
216
|
-
> =
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
> =
|
|
218
|
+
remaining extends [infer head, ...infer tail] ?
|
|
219
|
+
[head, mergePrefixes<s, tail>]
|
|
220
|
+
: s["root"]
|
|
219
221
|
|
|
220
222
|
type popGroup<stack extends BranchState[], top extends BranchState> = [
|
|
221
223
|
...stack,
|
|
222
224
|
top
|
|
223
225
|
]
|
|
224
226
|
|
|
225
|
-
export type finalizeGroup<
|
|
226
|
-
s extends
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
: s["groups"] extends popGroup<infer stack, infer top>
|
|
231
|
-
? from<{
|
|
227
|
+
export type finalizeGroup<s extends StaticState, unscanned extends string> =
|
|
228
|
+
s["branches"]["leftBound"] extends {} ?
|
|
229
|
+
openRangeError<s["branches"]["leftBound"]>
|
|
230
|
+
: s["groups"] extends popGroup<infer stack, infer top> ?
|
|
231
|
+
from<{
|
|
232
232
|
groups: stack
|
|
233
233
|
branches: top
|
|
234
234
|
root: mergeToUnion<s>
|
|
235
235
|
finalizer: s["finalizer"]
|
|
236
236
|
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
|
|
237
237
|
unscanned: unscanned
|
|
238
|
-
|
|
239
|
-
:
|
|
238
|
+
}>
|
|
239
|
+
: state.error<writeUnmatchedGroupCloseMessage<unscanned>>
|
|
240
240
|
|
|
241
241
|
export type reduceGroupOpen<
|
|
242
242
|
s extends StaticState,
|
|
@@ -253,35 +253,33 @@ export namespace state {
|
|
|
253
253
|
export type finalize<
|
|
254
254
|
s extends StaticState,
|
|
255
255
|
finalizer extends Scanner.FinalizingLookahead
|
|
256
|
-
> =
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
> =
|
|
257
|
+
s["groups"] extends [] ?
|
|
258
|
+
s["branches"]["leftBound"] extends {} ?
|
|
259
|
+
openRangeError<s["branches"]["leftBound"]>
|
|
260
|
+
: from<{
|
|
260
261
|
root: mergeToUnion<s>
|
|
261
262
|
groups: s["groups"]
|
|
262
263
|
branches: initialBranches
|
|
263
264
|
finalizer: finalizer
|
|
264
265
|
scanned: s["scanned"]
|
|
265
266
|
unscanned: s["unscanned"]
|
|
266
|
-
|
|
267
|
-
:
|
|
267
|
+
}>
|
|
268
|
+
: state.error<writeUnclosedGroupMessage<")">>
|
|
268
269
|
|
|
269
270
|
type openRangeError<range extends defined<BranchState["leftBound"]>> =
|
|
270
271
|
state.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>
|
|
271
272
|
|
|
272
273
|
export type previousOperator<s extends StaticState> =
|
|
273
|
-
s["branches"]["leftBound"] extends {}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
: s["branches"]["|"] extends {}
|
|
283
|
-
? "|"
|
|
284
|
-
: undefined
|
|
274
|
+
s["branches"]["leftBound"] extends {} ?
|
|
275
|
+
s["branches"]["leftBound"]["comparator"]
|
|
276
|
+
: s["branches"]["prefixes"] extends (
|
|
277
|
+
[...unknown[], infer tail extends string]
|
|
278
|
+
) ?
|
|
279
|
+
tail
|
|
280
|
+
: s["branches"]["intersection"] extends {} ? "&"
|
|
281
|
+
: s["branches"]["union"] extends {} ? "|"
|
|
282
|
+
: undefined
|
|
285
283
|
|
|
286
284
|
export type scanTo<s extends StaticState, unscanned extends string> = from<{
|
|
287
285
|
root: s["root"]
|
|
@@ -7,11 +7,11 @@ export const isDateLiteral = (value: unknown): value is DateLiteral =>
|
|
|
7
7
|
(value[1] === "'" || value[1] === '"') &&
|
|
8
8
|
value.at(-1) === value[1]
|
|
9
9
|
|
|
10
|
-
export const isValidDate = (d: Date) => d.toString() !== "Invalid Date"
|
|
10
|
+
export const isValidDate = (d: Date): boolean => d.toString() !== "Invalid Date"
|
|
11
11
|
|
|
12
12
|
export const extractDateLiteralSource = <literal extends DateLiteral>(
|
|
13
13
|
literal: literal
|
|
14
|
-
) => literal.slice(2, -1) as
|
|
14
|
+
): extractDateLiteralSource<literal> => literal.slice(2, -1) as never
|
|
15
15
|
|
|
16
16
|
type extractDateLiteralSource<literal extends DateLiteral> =
|
|
17
17
|
literal extends DateLiteral<infer source> ? source : never
|
|
@@ -26,15 +26,19 @@ export type writeInvalidDateMessage<source extends string> =
|
|
|
26
26
|
|
|
27
27
|
export type DateInput = ConstructorParameters<typeof Date>[0]
|
|
28
28
|
|
|
29
|
+
export type DateParseResult<
|
|
30
|
+
errorOnFail extends boolean | string = boolean | string
|
|
31
|
+
> = Date | (errorOnFail extends true | string ? never : undefined)
|
|
32
|
+
|
|
29
33
|
export const tryParseDate = <errorOnFail extends boolean | string>(
|
|
30
34
|
source: string,
|
|
31
35
|
errorOnFail?: errorOnFail
|
|
32
|
-
) => maybeParseDate(source, errorOnFail)
|
|
36
|
+
): DateParseResult<errorOnFail> => maybeParseDate(source, errorOnFail)
|
|
33
37
|
|
|
34
38
|
const maybeParseDate = <errorOnFail extends boolean | string>(
|
|
35
39
|
source: string,
|
|
36
40
|
errorOnFail?: errorOnFail
|
|
37
|
-
):
|
|
41
|
+
): DateParseResult<errorOnFail> => {
|
|
38
42
|
const stringParsedDate = new Date(source)
|
|
39
43
|
if (isValidDate(stringParsedDate)) {
|
|
40
44
|
return stringParsedDate
|
|
@@ -46,9 +50,9 @@ const maybeParseDate = <errorOnFail extends boolean | string>(
|
|
|
46
50
|
return numberParsedDate
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
|
-
return errorOnFail
|
|
50
|
-
|
|
53
|
+
return errorOnFail ?
|
|
54
|
+
throwParseError(
|
|
51
55
|
errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail
|
|
52
|
-
|
|
53
|
-
:
|
|
56
|
+
)
|
|
57
|
+
: (undefined as never)
|
|
54
58
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { schema, type RegexLiteral } from "@arktype/schema"
|
|
2
1
|
import { isKeyOf } from "@arktype/util"
|
|
3
2
|
import type { DynamicState } from "../../reduce/dynamic.js"
|
|
4
3
|
import type { StaticState, state } from "../../reduce/static.js"
|
|
@@ -18,7 +17,7 @@ export type SingleQuotedStringLiteral<Text extends string = string> =
|
|
|
18
17
|
export const parseEnclosed = (
|
|
19
18
|
s: DynamicState,
|
|
20
19
|
enclosing: EnclosingStartToken
|
|
21
|
-
) => {
|
|
20
|
+
): void => {
|
|
22
21
|
const enclosed = s.scanner.shiftUntil(
|
|
23
22
|
untilLookaheadIsClosing[enclosingTokens[enclosing]]
|
|
24
23
|
)
|
|
@@ -30,12 +29,19 @@ export const parseEnclosed = (
|
|
|
30
29
|
if (enclosing === "/") {
|
|
31
30
|
// fail parsing if the regex is invalid
|
|
32
31
|
new RegExp(enclosed)
|
|
33
|
-
s.root =
|
|
32
|
+
s.root = s.ctx.$.node(
|
|
33
|
+
"intersection",
|
|
34
|
+
{
|
|
35
|
+
domain: "string",
|
|
36
|
+
regex: enclosed
|
|
37
|
+
},
|
|
38
|
+
{ prereduced: true }
|
|
39
|
+
)
|
|
34
40
|
} else if (isKeyOf(enclosing, enclosingQuote)) {
|
|
35
|
-
s.root =
|
|
41
|
+
s.root = s.ctx.$.node("unit", { unit: enclosed })
|
|
36
42
|
} else {
|
|
37
43
|
const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed))
|
|
38
|
-
s.root =
|
|
44
|
+
s.root = s.ctx.$.node("unit", { unit: date, description: enclosed })
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
|
|
@@ -43,20 +49,19 @@ export type parseEnclosed<
|
|
|
43
49
|
s extends StaticState,
|
|
44
50
|
enclosingStart extends EnclosingStartToken,
|
|
45
51
|
unscanned extends string
|
|
46
|
-
> =
|
|
47
|
-
unscanned,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
:
|
|
52
|
+
> =
|
|
53
|
+
Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (
|
|
54
|
+
Scanner.shiftResult<infer scanned, infer nextUnscanned>
|
|
55
|
+
) ?
|
|
56
|
+
nextUnscanned extends "" ?
|
|
57
|
+
state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>>
|
|
58
|
+
: state.setRoot<
|
|
53
59
|
s,
|
|
54
60
|
`${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`,
|
|
55
|
-
nextUnscanned extends Scanner.shift<string, infer unscanned>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: never
|
|
61
|
+
nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned
|
|
62
|
+
: ""
|
|
63
|
+
>
|
|
64
|
+
: never
|
|
60
65
|
|
|
61
66
|
export const enclosingQuote = {
|
|
62
67
|
"'": 1,
|