arktype 2.0.0-dev.3 → 2.0.0-dev.5
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 +123 -215
- package/__tests__/badDefinitionType.test.ts +2 -2
- package/__tests__/bounds.test.ts +448 -349
- package/__tests__/config.test.ts +8 -6
- package/__tests__/cyclic.test.ts +1 -1
- package/__tests__/dateLiteral.test.ts +2 -2
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +23 -19
- package/__tests__/enclosed.test.ts +7 -2
- package/__tests__/errors.test.ts +115 -0
- package/__tests__/expressions.test.ts +14 -20
- package/__tests__/generic.test.ts +4 -5
- package/__tests__/group.test.ts +8 -3
- package/__tests__/instanceof.test.ts +7 -7
- package/__tests__/intersection.test.ts +62 -38
- package/__tests__/keyTraversal.test.ts +0 -2
- package/__tests__/keyof.test.ts +15 -13
- package/__tests__/keywords.test.ts +29 -25
- package/__tests__/literal.test.ts +26 -8
- package/__tests__/match.test.ts +28 -16
- package/__tests__/morph.test.ts +187 -172
- package/__tests__/narrow.test.ts +38 -39
- package/__tests__/objectLiteral.test.ts +106 -76
- package/__tests__/realWorld.test.ts +62 -0
- package/__tests__/schema.bench.ts +14 -0
- package/__tests__/schema.test.ts +60 -0
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +8 -6
- package/__tests__/submodule.test.ts +2 -2
- package/__tests__/traverse.test.ts +34 -31
- package/__tests__/typeMethods.test.ts +2 -3
- package/__tests__/typeReference.test.ts +3 -3
- package/__tests__/unenclosed.test.ts +9 -3
- package/__tests__/union.test.ts +127 -55
- package/__tests__/unit.test.ts +61 -0
- package/base.ts +520 -0
- package/config.ts +25 -0
- package/constraints/ast.ts +288 -0
- package/constraints/constraint.ts +91 -0
- package/constraints/predicate.ts +102 -0
- package/constraints/props/index.ts +93 -0
- package/constraints/props/prop.ts +146 -0
- package/constraints/props/props.ts +148 -0
- package/constraints/props/sequence.ts +473 -0
- package/constraints/props/shared.ts +5 -0
- package/constraints/refinements/after.ts +68 -0
- package/constraints/refinements/before.ts +75 -0
- package/constraints/refinements/divisor.ts +76 -0
- package/constraints/refinements/exactLength.ts +75 -0
- package/constraints/refinements/kinds.ts +31 -0
- package/constraints/refinements/max.ts +61 -0
- package/constraints/refinements/maxLength.ts +66 -0
- package/constraints/refinements/min.ts +54 -0
- package/constraints/refinements/minLength.ts +63 -0
- package/constraints/refinements/range.ts +181 -0
- package/constraints/refinements/regex.ts +59 -0
- package/{ark.ts → keywords/ark.ts} +40 -30
- package/keywords/internal.ts +29 -0
- package/keywords/jsObject.ts +39 -0
- package/keywords/parsing.ts +87 -0
- package/keywords/root.ts +9 -0
- package/keywords/tsGenerics.ts +28 -0
- package/keywords/tsPrimitive.ts +52 -0
- package/keywords/utils/creditCard.ts +37 -0
- package/keywords/utils/date.ts +112 -0
- package/keywords/validation.ts +115 -0
- package/kinds.ts +115 -0
- package/main.ts +7 -8
- package/match.ts +30 -34
- package/out/ark.d.ts +5 -1
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +4 -1
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +129 -0
- package/out/base.d.ts.map +1 -0
- package/out/base.js +274 -0
- package/out/base.js.map +1 -0
- package/out/builtins/builtins.d.ts +19 -0
- package/out/builtins/builtins.d.ts.map +1 -0
- package/out/builtins/builtins.js +12 -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 +15 -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 +59 -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 +20 -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 +36 -0
- package/out/builtins/utils/creditCard.js.map +1 -0
- package/out/builtins/utils/date.d.ts +22 -0
- package/out/builtins/utils/date.d.ts.map +1 -0
- package/out/builtins/utils/date.js +53 -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 +70 -0
- package/out/builtins/validation.js.map +1 -0
- package/out/config.d.ts +6 -0
- package/out/config.d.ts.map +1 -0
- package/out/config.js +17 -0
- package/out/config.js.map +1 -0
- package/out/constraints/ast.d.ts +176 -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 +70 -0
- package/out/constraints/constraint.d.ts.map +1 -0
- package/out/constraints/constraint.js +21 -0
- package/out/constraints/constraint.js.map +1 -0
- package/out/constraints/predicate.d.ts +46 -0
- package/out/constraints/predicate.d.ts.map +1 -0
- package/out/constraints/predicate.js +47 -0
- package/out/constraints/predicate.js.map +1 -0
- package/out/constraints/props/index.d.ts +36 -0
- package/out/constraints/props/index.d.ts.map +1 -0
- package/out/constraints/props/index.js +48 -0
- package/out/constraints/props/index.js.map +1 -0
- package/out/constraints/props/optional.d.ts +34 -0
- package/out/constraints/props/optional.d.ts.map +1 -0
- package/out/constraints/props/optional.js +55 -0
- package/out/constraints/props/optional.js.map +1 -0
- package/out/constraints/props/prop.d.ts +46 -0
- package/out/constraints/props/prop.d.ts.map +1 -0
- package/out/constraints/props/prop.js +104 -0
- package/out/constraints/props/prop.js.map +1 -0
- package/out/constraints/props/props.d.ts +34 -0
- package/out/constraints/props/props.d.ts.map +1 -0
- package/out/constraints/props/props.js +106 -0
- package/out/constraints/props/props.js.map +1 -0
- package/out/constraints/props/required.d.ts +43 -0
- package/out/constraints/props/required.d.ts.map +1 -0
- package/out/constraints/props/required.js +76 -0
- package/out/constraints/props/required.js.map +1 -0
- package/out/constraints/props/sequence.d.ts +64 -0
- package/out/constraints/props/sequence.d.ts.map +1 -0
- package/out/constraints/props/sequence.js +327 -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 +25 -0
- package/out/constraints/refinements/after.d.ts.map +1 -0
- package/out/constraints/refinements/after.js +35 -0
- package/out/constraints/refinements/after.js.map +1 -0
- package/out/constraints/refinements/before.d.ts +25 -0
- package/out/constraints/refinements/before.d.ts.map +1 -0
- package/out/constraints/refinements/before.js +41 -0
- package/out/constraints/refinements/before.js.map +1 -0
- package/out/constraints/refinements/divisor.d.ts +42 -0
- package/out/constraints/refinements/divisor.d.ts.map +1 -0
- package/out/constraints/refinements/divisor.js +41 -0
- package/out/constraints/refinements/divisor.js.map +1 -0
- package/out/constraints/refinements/exactLength.d.ts +41 -0
- package/out/constraints/refinements/exactLength.d.ts.map +1 -0
- package/out/constraints/refinements/exactLength.js +44 -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 +42 -0
- package/out/constraints/refinements/length.d.ts.map +1 -0
- package/out/constraints/refinements/length.js +45 -0
- package/out/constraints/refinements/length.js.map +1 -0
- package/out/constraints/refinements/max.d.ts +24 -0
- package/out/constraints/refinements/max.d.ts.map +1 -0
- package/out/constraints/refinements/max.js +31 -0
- package/out/constraints/refinements/max.js.map +1 -0
- package/out/constraints/refinements/maxLength.d.ts +24 -0
- package/out/constraints/refinements/maxLength.d.ts.map +1 -0
- package/out/constraints/refinements/maxLength.js +34 -0
- package/out/constraints/refinements/maxLength.js.map +1 -0
- package/out/constraints/refinements/min.d.ts +24 -0
- package/out/constraints/refinements/min.d.ts.map +1 -0
- package/out/constraints/refinements/min.js +25 -0
- package/out/constraints/refinements/min.js.map +1 -0
- package/out/constraints/refinements/minLength.d.ts +24 -0
- package/out/constraints/refinements/minLength.d.ts.map +1 -0
- package/out/constraints/refinements/minLength.js +32 -0
- package/out/constraints/refinements/minLength.js.map +1 -0
- package/out/constraints/refinements/range.d.ts +90 -0
- package/out/constraints/refinements/range.d.ts.map +1 -0
- package/out/constraints/refinements/range.js +72 -0
- package/out/constraints/refinements/range.js.map +1 -0
- package/out/constraints/refinements/regex.d.ts +43 -0
- package/out/constraints/refinements/regex.d.ts.map +1 -0
- package/out/constraints/refinements/regex.js +36 -0
- package/out/constraints/refinements/regex.js.map +1 -0
- package/out/constraints/refinements/shared.d.ts +5 -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/inference.d.ts +40 -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 +60 -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 +10 -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 +15 -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 +61 -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 +22 -0
- package/out/keywords/tsPrimitive.js.map +1 -0
- package/out/keywords/utils/creditCard.d.ts +8 -0
- package/out/keywords/utils/creditCard.d.ts.map +1 -0
- package/out/keywords/utils/creditCard.js +36 -0
- package/out/keywords/utils/creditCard.js.map +1 -0
- package/out/keywords/utils/date.d.ts +25 -0
- package/out/keywords/utils/date.d.ts.map +1 -0
- package/out/keywords/utils/date.js +53 -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 +76 -0
- package/out/keywords/validation.js.map +1 -0
- package/out/kinds.d.ts +72 -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 +5 -4
- package/out/main.d.ts.map +1 -1
- package/out/main.js +2 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +17 -18
- package/out/match.d.ts.map +1 -1
- package/out/match.js +3 -4
- package/out/match.js.map +1 -1
- package/out/parse.d.ts +23 -0
- package/out/parse.d.ts.map +1 -0
- package/out/parse.js +148 -0
- package/out/parse.js.map +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +8 -9
- package/out/parser/definition.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +44 -11
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +47 -35
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +8 -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 +4 -6
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +28 -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 +1 -1
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -11
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +15 -9
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +2 -3
- 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 +20 -19
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +3 -2
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +1 -1
- 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 +4 -4
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +2 -2
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +5 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +5 -5
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +17 -12
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +28 -25
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -1
- 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/scanner.d.ts.map +1 -1
- package/out/parser/string/string.d.ts +3 -3
- 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 +95 -33
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +45 -48
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +44 -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 +110 -0
- package/out/schemaScope.d.ts.map +1 -0
- package/out/schemaScope.js +212 -0
- package/out/schemaScope.js.map +1 -0
- package/out/scope.d.ts +98 -26
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +185 -45
- 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 +67 -0
- package/out/shared/compile.js.map +1 -0
- package/out/shared/context.d.ts +29 -0
- package/out/shared/context.d.ts.map +1 -0
- package/out/shared/context.js +48 -0
- package/out/shared/context.js.map +1 -0
- package/out/shared/declare.d.ts +53 -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 +79 -0
- package/out/shared/disjoint.d.ts.map +1 -0
- package/out/shared/disjoint.js +82 -0
- package/out/shared/disjoint.js.map +1 -0
- package/out/shared/errors.d.ts +59 -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 +170 -0
- package/out/shared/implement.d.ts.map +1 -0
- package/out/shared/implement.js +69 -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 +15 -0
- package/out/shared/intersections.d.ts.map +1 -0
- package/out/shared/intersections.js.map +1 -0
- package/out/shared/traversal.d.ts +44 -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 +8 -0
- package/out/shared/utils.d.ts.map +1 -0
- package/out/shared/utils.js +10 -0
- package/out/shared/utils.js.map +1 -0
- package/out/type.d.ts +10 -38
- package/out/type.d.ts.map +1 -1
- package/out/type.js +20 -106
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +24 -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 +20 -0
- package/out/types/discriminate.d.ts.map +1 -0
- package/out/types/discriminate.js +114 -0
- package/out/types/discriminate.js.map +1 -0
- package/out/types/domain.d.ts +40 -0
- package/out/types/domain.d.ts.map +1 -0
- package/out/types/domain.js +38 -0
- package/out/types/domain.js.map +1 -0
- package/out/types/intersection.d.ts +67 -0
- package/out/types/intersection.d.ts.map +1 -0
- package/out/types/intersection.js +350 -0
- package/out/types/intersection.js.map +1 -0
- package/out/types/morph.d.ts +79 -0
- package/out/types/morph.d.ts.map +1 -0
- package/out/types/morph.js +95 -0
- package/out/types/morph.js.map +1 -0
- package/out/types/proto.d.ts +42 -0
- package/out/types/proto.d.ts.map +1 -0
- package/out/types/proto.js +48 -0
- package/out/types/proto.js.map +1 -0
- package/out/types/type.d.ts +61 -0
- package/out/types/type.d.ts.map +1 -0
- package/out/types/type.js +111 -0
- package/out/types/type.js.map +1 -0
- package/out/types/union.d.ts +48 -0
- package/out/types/union.d.ts.map +1 -0
- package/out/types/union.js +337 -0
- package/out/types/union.js.map +1 -0
- package/out/types/unit.d.ts +40 -0
- package/out/types/unit.d.ts.map +1 -0
- package/out/types/unit.js +48 -0
- package/out/types/unit.js.map +1 -0
- package/out/util.d.ts +5 -2
- package/out/util.d.ts.map +1 -1
- package/out/util.js.map +1 -1
- package/package.json +6 -3
- package/parse.ts +221 -0
- package/parser/definition.ts +24 -23
- package/parser/objectLiteral.ts +128 -88
- package/parser/semantic/bounds.ts +18 -9
- package/parser/semantic/divisor.ts +12 -10
- package/parser/semantic/infer.ts +152 -0
- package/parser/semantic/utils.ts +5 -13
- package/parser/semantic/validate.ts +1 -2
- package/parser/string/reduce/dynamic.ts +42 -30
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +22 -22
- package/parser/string/shift/operand/date.ts +9 -5
- package/parser/string/shift/operand/enclosed.ts +11 -5
- package/parser/string/shift/operand/genericArgs.ts +6 -6
- package/parser/string/shift/operand/operand.ts +1 -2
- package/parser/string/shift/operand/unenclosed.ts +14 -20
- package/parser/string/shift/operator/bounds.ts +59 -54
- package/parser/string/shift/operator/divisor.ts +2 -2
- package/parser/string/shift/scanner.ts +10 -10
- package/parser/string/string.ts +4 -4
- package/parser/tuple.ts +224 -202
- package/schema.ts +263 -0
- package/scope.ts +358 -81
- package/shared/compile.ts +92 -0
- package/shared/declare.ts +75 -0
- package/shared/disjoint.ts +203 -0
- package/shared/errors.ts +204 -0
- package/shared/implement.ts +327 -0
- package/shared/inference.ts +9 -0
- package/shared/intersections.ts +53 -0
- package/shared/traversal.ts +146 -0
- package/shared/utils.ts +30 -0
- package/type.ts +23 -183
- package/types/basis.ts +62 -0
- package/types/discriminate.ts +168 -0
- package/types/domain.ts +79 -0
- package/types/intersection.ts +539 -0
- package/types/morph.ts +263 -0
- package/types/proto.ts +89 -0
- package/types/type.ts +319 -0
- package/types/union.ts +451 -0
- package/types/unit.ts +78 -0
- package/util.ts +5 -2
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/nodeDefinitions.test.ts +0 -190
- 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.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/out/{parser/semantic → shared}/intersections.js +0 -0
package/parser/tuple.ts
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
keywords,
|
|
3
|
-
makeRootAndArrayPropertiesMutable,
|
|
4
|
-
schema,
|
|
5
|
-
type BaseMeta,
|
|
6
|
-
type Morph,
|
|
7
|
-
type MorphChildKind,
|
|
8
|
-
type MutableInner,
|
|
9
|
-
type Node,
|
|
10
|
-
type Out,
|
|
11
|
-
type Predicate,
|
|
12
|
-
type Schema,
|
|
13
|
-
type TypeNode,
|
|
14
|
-
type UnionChildKind,
|
|
15
|
-
type extractIn,
|
|
16
|
-
type extractOut,
|
|
17
|
-
type inferIntersection,
|
|
18
|
-
type inferMorphOut,
|
|
19
|
-
type inferNarrow
|
|
20
|
-
} from "@arktype/schema"
|
|
21
1
|
import {
|
|
22
2
|
append,
|
|
23
|
-
isArray,
|
|
24
3
|
objectKindOrDomainOf,
|
|
25
4
|
printable,
|
|
26
5
|
throwParseError,
|
|
@@ -28,44 +7,61 @@ import {
|
|
|
28
7
|
type Constructor,
|
|
29
8
|
type Domain,
|
|
30
9
|
type ErrorMessage,
|
|
31
|
-
type
|
|
10
|
+
type array,
|
|
32
11
|
type conform,
|
|
33
|
-
type evaluate
|
|
34
|
-
type isAny
|
|
12
|
+
type evaluate
|
|
35
13
|
} from "@arktype/util"
|
|
14
|
+
import type { Node } from "../base.js"
|
|
15
|
+
import type { Predicate, inferNarrow } from "../constraints/predicate.js"
|
|
16
|
+
import type { MutableInner } from "../kinds.js"
|
|
17
|
+
import type { instantiateSchema, validateSchema } from "../schema.js"
|
|
36
18
|
import type { ParseContext } from "../scope.js"
|
|
19
|
+
import type { BaseMeta } from "../shared/declare.js"
|
|
20
|
+
import type { inferIntersection } from "../shared/intersections.js"
|
|
21
|
+
import { makeRootAndArrayPropertiesMutable } from "../shared/utils.js"
|
|
22
|
+
import type {
|
|
23
|
+
Morph,
|
|
24
|
+
Out,
|
|
25
|
+
distillConstrainableIn,
|
|
26
|
+
distillConstrainableOut,
|
|
27
|
+
inferMorphOut
|
|
28
|
+
} from "../types/morph.js"
|
|
29
|
+
import type { Type } from "../types/type.js"
|
|
30
|
+
import type { UnionChildKind } from "../types/union.js"
|
|
37
31
|
import type { inferDefinition, validateDefinition } from "./definition.js"
|
|
38
|
-
import type { InfixOperator, PostfixExpression } from "./semantic/
|
|
32
|
+
import type { InfixOperator, PostfixExpression } from "./semantic/infer.js"
|
|
39
33
|
import { writeUnsatisfiableExpressionError } from "./semantic/validate.js"
|
|
40
|
-
import {
|
|
41
|
-
configureShallowDescendants,
|
|
42
|
-
parseEntryValue,
|
|
43
|
-
type EntryParseResult,
|
|
44
|
-
type EntryValueParseResult,
|
|
45
|
-
type parseEntry,
|
|
46
|
-
type validateObjectValue
|
|
47
|
-
} from "./shared.js"
|
|
48
34
|
import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js"
|
|
49
35
|
import type { BaseCompletions } from "./string/string.js"
|
|
50
36
|
|
|
51
|
-
export const parseTuple = (def:
|
|
37
|
+
export const parseTuple = (def: array, ctx: ParseContext): Type =>
|
|
52
38
|
maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx)
|
|
53
39
|
|
|
54
|
-
export const parseTupleLiteral = (
|
|
55
|
-
def: readonly unknown[],
|
|
56
|
-
ctx: ParseContext
|
|
57
|
-
): TypeNode => {
|
|
40
|
+
export const parseTupleLiteral = (def: array, ctx: ParseContext): Type => {
|
|
58
41
|
let sequences: MutableInner<"sequence">[] = [{}]
|
|
59
|
-
|
|
42
|
+
let i = 0
|
|
43
|
+
while (i < def.length) {
|
|
44
|
+
let spread = false
|
|
45
|
+
let optional = false
|
|
46
|
+
if (def[i] === "..." && i < def.length - 1) {
|
|
47
|
+
spread = true
|
|
48
|
+
i++
|
|
49
|
+
}
|
|
50
|
+
|
|
60
51
|
ctx.path.push(`${i}`)
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
const element = ctx.$.parse(def[i], ctx)
|
|
53
|
+
ctx.path.pop()
|
|
54
|
+
i++
|
|
55
|
+
if (def[i] === "?") {
|
|
56
|
+
if (spread) {
|
|
65
57
|
return throwParseError(spreadOptionalMessage)
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
optional = true
|
|
60
|
+
i++
|
|
61
|
+
}
|
|
62
|
+
if (spread) {
|
|
63
|
+
if (!element.extends(ctx.$.keywords.Array)) {
|
|
64
|
+
return throwParseError(writeNonArraySpreadMessage(element.expression))
|
|
69
65
|
}
|
|
70
66
|
// a spread must be distributed over branches e.g.:
|
|
71
67
|
// def: [string, ...(number[] | [true, false])]
|
|
@@ -78,27 +74,27 @@ export const parseTupleLiteral = (
|
|
|
78
74
|
)
|
|
79
75
|
} else {
|
|
80
76
|
sequences = sequences.map((base) =>
|
|
81
|
-
appendElement(
|
|
82
|
-
base,
|
|
83
|
-
parsedElementDef.kind === "optional" ? "optional" : "required",
|
|
84
|
-
element
|
|
85
|
-
)
|
|
77
|
+
appendElement(base, optional ? "optional" : "required", element)
|
|
86
78
|
)
|
|
87
79
|
}
|
|
88
|
-
ctx.path.pop()
|
|
89
80
|
}
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
return ctx.$.node(
|
|
82
|
+
sequences.map(
|
|
83
|
+
(sequence) =>
|
|
84
|
+
({
|
|
85
|
+
proto: Array,
|
|
86
|
+
sequence
|
|
87
|
+
}) as const
|
|
88
|
+
)
|
|
95
89
|
)
|
|
96
90
|
}
|
|
97
91
|
|
|
92
|
+
type ElementKind = "optional" | "required" | "variadic"
|
|
93
|
+
|
|
98
94
|
const appendElement = (
|
|
99
95
|
base: MutableInner<"sequence">,
|
|
100
|
-
kind:
|
|
101
|
-
element:
|
|
96
|
+
kind: ElementKind,
|
|
97
|
+
element: Type
|
|
102
98
|
): MutableInner<"sequence"> => {
|
|
103
99
|
switch (kind) {
|
|
104
100
|
case "required":
|
|
@@ -145,7 +141,7 @@ const appendSpreadBranch = (
|
|
|
145
141
|
const spread = branch.firstReferenceOfKind("sequence")
|
|
146
142
|
if (!spread) {
|
|
147
143
|
// the only array with no sequence reference is unknown[]
|
|
148
|
-
return appendElement(base, "variadic", keywords.unknown)
|
|
144
|
+
return appendElement(base, "variadic", branch.$.keywords.unknown)
|
|
149
145
|
}
|
|
150
146
|
spread.prefix.forEach((node) => appendElement(base, "required", node))
|
|
151
147
|
spread.optionals.forEach((node) => appendElement(base, "optional", node))
|
|
@@ -154,34 +150,17 @@ const appendSpreadBranch = (
|
|
|
154
150
|
return base
|
|
155
151
|
}
|
|
156
152
|
|
|
157
|
-
type TupleElementParseResult = EntryValueParseResult & { spread?: true }
|
|
158
|
-
|
|
159
|
-
const parseSpreadable = (elementDef: unknown): TupleElementParseResult => {
|
|
160
|
-
if (typeof elementDef === "string" && elementDef.startsWith("...")) {
|
|
161
|
-
// variadic string definition like "...string[]"
|
|
162
|
-
return { ...parseEntryValue(elementDef.slice(3)), spread: true }
|
|
163
|
-
}
|
|
164
|
-
if (
|
|
165
|
-
isArray(elementDef) &&
|
|
166
|
-
elementDef.length === 2 &&
|
|
167
|
-
elementDef[0] === "..."
|
|
168
|
-
) {
|
|
169
|
-
// variadic tuple expression like ["...", { a: "1" }]
|
|
170
|
-
return { ...parseEntryValue(elementDef[1]), spread: true }
|
|
171
|
-
}
|
|
172
|
-
return parseEntryValue(elementDef)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
153
|
const maybeParseTupleExpression = (
|
|
176
|
-
def:
|
|
154
|
+
def: array,
|
|
177
155
|
ctx: ParseContext
|
|
178
|
-
):
|
|
179
|
-
const tupleExpressionResult =
|
|
180
|
-
? indexOneParsers[def[1]](def as never, ctx)
|
|
181
|
-
: isIndexZeroExpression(def)
|
|
156
|
+
): Type | undefined => {
|
|
157
|
+
const tupleExpressionResult = isIndexZeroExpression(def)
|
|
182
158
|
? prefixParsers[def[0]](def as never, ctx)
|
|
159
|
+
: isIndexOneExpression(def)
|
|
160
|
+
? indexOneParsers[def[1]](def as never, ctx)
|
|
183
161
|
: undefined
|
|
184
162
|
if (tupleExpressionResult) {
|
|
163
|
+
if (def[0] === "schema") return tupleExpressionResult
|
|
185
164
|
return tupleExpressionResult.isNever()
|
|
186
165
|
? throwParseError(
|
|
187
166
|
writeUnsatisfiableExpressionError(
|
|
@@ -200,7 +179,7 @@ const maybeParseTupleExpression = (
|
|
|
200
179
|
type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]]
|
|
201
180
|
|
|
202
181
|
export type validateTuple<
|
|
203
|
-
def extends
|
|
182
|
+
def extends array,
|
|
204
183
|
$,
|
|
205
184
|
args
|
|
206
185
|
> = def extends IndexZeroExpression
|
|
@@ -213,66 +192,146 @@ export type validateTuple<
|
|
|
213
192
|
| readonly ["", ...unknown[]]
|
|
214
193
|
| readonly [unknown, "", ...unknown[]]
|
|
215
194
|
? readonly [
|
|
216
|
-
def[0] extends ""
|
|
217
|
-
|
|
195
|
+
def[0] extends ""
|
|
196
|
+
? BaseCompletions<$, args, IndexZeroOperator | "...">
|
|
197
|
+
: def[0],
|
|
198
|
+
def[1] extends ""
|
|
199
|
+
? BaseCompletions<$, args, IndexOneOperator | "..." | "?">
|
|
200
|
+
: def[1]
|
|
218
201
|
]
|
|
219
202
|
: validateTupleLiteral<def, $, args>
|
|
220
203
|
|
|
221
|
-
export type validateTupleLiteral<
|
|
222
|
-
def
|
|
204
|
+
export type validateTupleLiteral<def extends array, $, args> = parseSequence<
|
|
205
|
+
def,
|
|
223
206
|
$,
|
|
224
|
-
args
|
|
225
|
-
|
|
226
|
-
> = def extends readonly [infer head, ...infer tail]
|
|
227
|
-
? validateTupleLiteral<
|
|
228
|
-
tail,
|
|
229
|
-
$,
|
|
230
|
-
args,
|
|
231
|
-
[...result, validateTupleElement<head, result, $, args>]
|
|
232
|
-
>
|
|
233
|
-
: result
|
|
207
|
+
args
|
|
208
|
+
>["validated"]
|
|
234
209
|
|
|
235
|
-
type
|
|
236
|
-
|
|
237
|
-
result extends unknown[],
|
|
210
|
+
type inferTupleLiteral<def extends array, $, args> = parseSequence<
|
|
211
|
+
def,
|
|
238
212
|
$,
|
|
239
213
|
args
|
|
240
|
-
>
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
: syntacticResult
|
|
255
|
-
: never
|
|
256
|
-
: validateObjectValue<head, $, args>
|
|
257
|
-
|
|
258
|
-
type semanticallyValidateRestElement<operand, $, args> = inferDefinition<
|
|
259
|
-
operand,
|
|
214
|
+
>["inferred"]
|
|
215
|
+
|
|
216
|
+
type SequenceParseState = {
|
|
217
|
+
unscanned: array
|
|
218
|
+
inferred: array
|
|
219
|
+
validated: array
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
type parseSequence<def extends array, $, args> = parseNextElement<
|
|
223
|
+
{
|
|
224
|
+
unscanned: def
|
|
225
|
+
inferred: []
|
|
226
|
+
validated: []
|
|
227
|
+
},
|
|
260
228
|
$,
|
|
261
229
|
args
|
|
262
|
-
>
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
230
|
+
>
|
|
231
|
+
|
|
232
|
+
type PreparsedElement = {
|
|
233
|
+
head: unknown
|
|
234
|
+
tail: array
|
|
235
|
+
optional: boolean
|
|
236
|
+
spread: boolean
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
namespace PreparsedElement {
|
|
240
|
+
export type from<result extends PreparsedElement> = result
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type preparseNextElement<s extends SequenceParseState> =
|
|
244
|
+
s["unscanned"] extends readonly ["...", infer head, ...infer tail]
|
|
245
|
+
? tail extends readonly ["?", ...infer postOptionalTail]
|
|
246
|
+
? PreparsedElement.from<{
|
|
247
|
+
head: head
|
|
248
|
+
tail: postOptionalTail
|
|
249
|
+
// this will be an error we have to handle
|
|
250
|
+
optional: true
|
|
251
|
+
spread: true
|
|
252
|
+
}>
|
|
253
|
+
: PreparsedElement.from<{
|
|
254
|
+
head: head
|
|
255
|
+
tail: tail
|
|
256
|
+
optional: false
|
|
257
|
+
spread: true
|
|
258
|
+
}>
|
|
259
|
+
: s["unscanned"] extends readonly [infer head, "?", ...infer tail]
|
|
260
|
+
? PreparsedElement.from<{
|
|
261
|
+
head: head
|
|
262
|
+
tail: tail
|
|
263
|
+
optional: true
|
|
264
|
+
spread: false
|
|
265
|
+
}>
|
|
266
|
+
: s["unscanned"] extends readonly [infer head, ...infer tail]
|
|
267
|
+
? PreparsedElement.from<{
|
|
268
|
+
head: head
|
|
269
|
+
tail: tail
|
|
270
|
+
optional: false
|
|
271
|
+
spread: false
|
|
272
|
+
}>
|
|
273
|
+
: null
|
|
274
|
+
|
|
275
|
+
type parseNextElement<
|
|
276
|
+
s extends SequenceParseState,
|
|
277
|
+
$,
|
|
278
|
+
args
|
|
279
|
+
> = preparseNextElement<s> extends infer next extends PreparsedElement
|
|
280
|
+
? parseNextElement<
|
|
281
|
+
{
|
|
282
|
+
unscanned: next["tail"]
|
|
283
|
+
inferred: next["spread"] extends true
|
|
284
|
+
? [
|
|
285
|
+
...s["inferred"],
|
|
286
|
+
...conform<inferDefinition<next["head"], $, args>, array>
|
|
287
|
+
]
|
|
288
|
+
: next["optional"] extends true
|
|
289
|
+
? [...s["inferred"], inferDefinition<next["head"], $, args>?]
|
|
290
|
+
: [...s["inferred"], inferDefinition<next["head"], $, args>]
|
|
291
|
+
validated: [
|
|
292
|
+
...s["validated"],
|
|
293
|
+
...(next["spread"] extends true
|
|
294
|
+
? [
|
|
295
|
+
inferDefinition<
|
|
296
|
+
next["head"],
|
|
297
|
+
$,
|
|
298
|
+
args
|
|
299
|
+
> extends infer spreadOperand extends array
|
|
300
|
+
? [number, number] extends [
|
|
301
|
+
s["inferred"]["length"],
|
|
302
|
+
spreadOperand["length"]
|
|
303
|
+
]
|
|
304
|
+
? ErrorMessage<multipleVariadicMessage>
|
|
305
|
+
: "..."
|
|
306
|
+
: ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
|
|
307
|
+
]
|
|
308
|
+
: []),
|
|
309
|
+
[next["optional"] | next["spread"], "?"] extends [
|
|
310
|
+
false,
|
|
311
|
+
s["validated"][number]
|
|
312
|
+
]
|
|
313
|
+
? ErrorMessage<requiredPostOptionalMessage>
|
|
314
|
+
: validateDefinition<next["head"], $, args>,
|
|
315
|
+
...(next["optional"] extends true
|
|
316
|
+
? [
|
|
317
|
+
next["spread"] extends true
|
|
318
|
+
? ErrorMessage<spreadOptionalMessage>
|
|
319
|
+
: number extends s["inferred"]["length"]
|
|
320
|
+
? ErrorMessage<optionalPostVariadicMessage>
|
|
321
|
+
: "?"
|
|
322
|
+
]
|
|
323
|
+
: [])
|
|
324
|
+
]
|
|
325
|
+
},
|
|
326
|
+
$,
|
|
327
|
+
args
|
|
328
|
+
>
|
|
329
|
+
: s
|
|
271
330
|
|
|
272
|
-
export const writeNonArraySpreadMessage = <operand extends string
|
|
331
|
+
export const writeNonArraySpreadMessage = <operand extends string>(
|
|
273
332
|
operand: operand
|
|
274
|
-
) =>
|
|
275
|
-
`Spread element must be an array (was ${operand})` as
|
|
333
|
+
): writeNonArraySpreadMessage<operand> =>
|
|
334
|
+
`Spread element must be an array (was ${operand})` as never
|
|
276
335
|
|
|
277
336
|
type writeNonArraySpreadMessage<operand> =
|
|
278
337
|
`Spread element must be an array${operand extends string
|
|
@@ -295,50 +354,7 @@ export const spreadOptionalMessage = `A spread element cannot be optional`
|
|
|
295
354
|
|
|
296
355
|
type spreadOptionalMessage = typeof optionalPostVariadicMessage
|
|
297
356
|
|
|
298
|
-
type
|
|
299
|
-
def extends List,
|
|
300
|
-
$,
|
|
301
|
-
args,
|
|
302
|
-
result extends unknown[] = []
|
|
303
|
-
> = def extends readonly [infer head, ...infer tail]
|
|
304
|
-
? parseEntry<
|
|
305
|
-
result["length"],
|
|
306
|
-
head extends variadicExpression<infer operand> ? operand : head
|
|
307
|
-
> extends infer entryParseResult extends EntryParseResult
|
|
308
|
-
? inferDefinition<
|
|
309
|
-
entryParseResult["innerValue"],
|
|
310
|
-
$,
|
|
311
|
-
args
|
|
312
|
-
> extends infer element
|
|
313
|
-
? head extends variadicExpression
|
|
314
|
-
? element extends readonly unknown[]
|
|
315
|
-
? inferTupleLiteral<tail, $, args, [...result, ...element]>
|
|
316
|
-
: never
|
|
317
|
-
: inferTupleLiteral<
|
|
318
|
-
tail,
|
|
319
|
-
$,
|
|
320
|
-
args,
|
|
321
|
-
entryParseResult["kind"] extends "optional"
|
|
322
|
-
? [...result, element?]
|
|
323
|
-
: [...result, element]
|
|
324
|
-
>
|
|
325
|
-
: never
|
|
326
|
-
: never
|
|
327
|
-
: result
|
|
328
|
-
|
|
329
|
-
type variadicExpression<operandDef = unknown> =
|
|
330
|
-
| variadicStringExpression<operandDef & string>
|
|
331
|
-
| variadicTupleExpression<operandDef>
|
|
332
|
-
|
|
333
|
-
type variadicStringExpression<operandDef extends string = string> =
|
|
334
|
-
`...${operandDef}`
|
|
335
|
-
|
|
336
|
-
type variadicTupleExpression<operandDef = unknown> = readonly [
|
|
337
|
-
"...",
|
|
338
|
-
operandDef
|
|
339
|
-
]
|
|
340
|
-
|
|
341
|
-
export type inferTuple<def extends List, $, args> = def extends TupleExpression
|
|
357
|
+
export type inferTuple<def extends array, $, args> = def extends TupleExpression
|
|
342
358
|
? inferTupleExpression<def, $, args>
|
|
343
359
|
: inferTupleLiteral<def, $, args>
|
|
344
360
|
|
|
@@ -370,6 +386,8 @@ export type inferTupleExpression<
|
|
|
370
386
|
? InstanceType<constructors[number]>
|
|
371
387
|
: def[0] extends "keyof"
|
|
372
388
|
? inferKeyOfExpression<def[1], $, args>
|
|
389
|
+
: def[0] extends "schema"
|
|
390
|
+
? instantiateSchema<def[1], $>["infer"]
|
|
373
391
|
: never
|
|
374
392
|
|
|
375
393
|
export type validatePrefixExpression<
|
|
@@ -384,6 +402,8 @@ export type validatePrefixExpression<
|
|
|
384
402
|
? readonly [def[0], ...unknown[]]
|
|
385
403
|
: def[0] extends "instanceof"
|
|
386
404
|
? readonly [def[0], ...Constructor[]]
|
|
405
|
+
: def[0] extends "schema"
|
|
406
|
+
? [def[0], validateSchema<def[1], $>]
|
|
387
407
|
: never
|
|
388
408
|
|
|
389
409
|
export type validatePostfixExpression<
|
|
@@ -408,9 +428,12 @@ export type validateInfixExpression<
|
|
|
408
428
|
: def[1] extends "&"
|
|
409
429
|
? validateDefinition<def[2], $, args>
|
|
410
430
|
: def[1] extends ":"
|
|
411
|
-
? Predicate<
|
|
431
|
+
? Predicate<distillConstrainableIn<inferDefinition<def[0], $, args>>>
|
|
412
432
|
: def[1] extends "=>"
|
|
413
|
-
? Morph<
|
|
433
|
+
? Morph<
|
|
434
|
+
distillConstrainableOut<inferDefinition<def[0], $, args>>,
|
|
435
|
+
unknown
|
|
436
|
+
>
|
|
414
437
|
: def[1] extends "@"
|
|
415
438
|
? BaseMeta | string
|
|
416
439
|
: validateDefinition<def[2], $, args>
|
|
@@ -424,7 +447,7 @@ export type UnparsedTupleExpressionInput = {
|
|
|
424
447
|
export type UnparsedTupleOperator = evaluate<keyof UnparsedTupleExpressionInput>
|
|
425
448
|
|
|
426
449
|
export const parseKeyOfTuple: PrefixParser<"keyof"> = (def, ctx) =>
|
|
427
|
-
ctx
|
|
450
|
+
ctx.$.parse(def[1], ctx).keyof()
|
|
428
451
|
|
|
429
452
|
export type inferKeyOfExpression<operandDef, $, args> = evaluate<
|
|
430
453
|
keyof inferDefinition<operandDef, $, args>
|
|
@@ -434,23 +457,23 @@ const parseBranchTuple: PostfixParser<"|" | "&"> = (def, ctx) => {
|
|
|
434
457
|
if (def[2] === undefined) {
|
|
435
458
|
return throwParseError(writeMissingRightOperandMessage(def[1], ""))
|
|
436
459
|
}
|
|
437
|
-
const l = ctx
|
|
438
|
-
const r = ctx
|
|
460
|
+
const l = ctx.$.parse(def[0], ctx)
|
|
461
|
+
const r = ctx.$.parse(def[2], ctx)
|
|
439
462
|
return def[1] === "&" ? l.and(r) : l.or(r)
|
|
440
463
|
}
|
|
441
464
|
|
|
442
465
|
const parseArrayTuple: PostfixParser<"[]"> = (def, ctx) =>
|
|
443
|
-
ctx
|
|
466
|
+
ctx.$.parse(def[0], ctx).array()
|
|
444
467
|
|
|
445
468
|
export type PostfixParser<token extends IndexOneOperator> = (
|
|
446
469
|
def: IndexOneExpression<token>,
|
|
447
470
|
ctx: ParseContext
|
|
448
|
-
) =>
|
|
471
|
+
) => Type
|
|
449
472
|
|
|
450
473
|
export type PrefixParser<token extends IndexZeroOperator> = (
|
|
451
474
|
def: IndexZeroExpression<token>,
|
|
452
475
|
ctx: ParseContext
|
|
453
|
-
) =>
|
|
476
|
+
) => Type
|
|
454
477
|
|
|
455
478
|
export type TupleExpression = IndexZeroExpression | IndexOneExpression
|
|
456
479
|
|
|
@@ -466,7 +489,7 @@ export type IndexOneExpression<
|
|
|
466
489
|
token extends IndexOneOperator = IndexOneOperator
|
|
467
490
|
> = readonly [unknown, token, ...unknown[]]
|
|
468
491
|
|
|
469
|
-
const isIndexOneExpression = (def:
|
|
492
|
+
const isIndexOneExpression = (def: array): def is IndexOneExpression =>
|
|
470
493
|
indexOneParsers[def[1] as IndexOneOperator] !== undefined
|
|
471
494
|
|
|
472
495
|
export const parseMorphTuple: PostfixParser<"=>"> = (def, ctx) => {
|
|
@@ -476,10 +499,7 @@ export const parseMorphTuple: PostfixParser<"=>"> = (def, ctx) => {
|
|
|
476
499
|
)
|
|
477
500
|
}
|
|
478
501
|
// TODO: nested morphs?
|
|
479
|
-
return
|
|
480
|
-
in: ctx.scope.parse(def[0], ctx) as Schema<MorphChildKind>,
|
|
481
|
-
morph: def[2] as Morph
|
|
482
|
-
})
|
|
502
|
+
return ctx.$.parse(def[0], ctx).morph(def[2] as Morph)
|
|
483
503
|
}
|
|
484
504
|
|
|
485
505
|
export const writeMalformedFunctionalExpressionMessage = (
|
|
@@ -488,11 +508,11 @@ export const writeMalformedFunctionalExpressionMessage = (
|
|
|
488
508
|
) =>
|
|
489
509
|
`${
|
|
490
510
|
operator === ":" ? "Narrow" : "Morph"
|
|
491
|
-
} expression requires a function following '${operator}' (was ${typeof value})`
|
|
511
|
+
} expression requires a function following '${operator}' (was ${typeof value})` as const
|
|
492
512
|
|
|
493
513
|
export type parseMorph<inDef, morph, $, args> = morph extends Morph
|
|
494
514
|
? (
|
|
495
|
-
In:
|
|
515
|
+
In: distillConstrainableIn<inferDefinition<inDef, $, args>>
|
|
496
516
|
) => Out<inferMorphOut<ReturnType<morph>>>
|
|
497
517
|
: never
|
|
498
518
|
|
|
@@ -502,13 +522,11 @@ export const parseNarrowTuple: PostfixParser<":"> = (def, ctx) => {
|
|
|
502
522
|
writeMalformedFunctionalExpressionMessage(":", def[2])
|
|
503
523
|
)
|
|
504
524
|
}
|
|
505
|
-
return ctx.
|
|
506
|
-
.parse(def[0], ctx)
|
|
507
|
-
.constrain("predicate", def[2] as Predicate)
|
|
525
|
+
return ctx.$.parse(def[0], ctx).constrain("predicate", def[2] as Predicate)
|
|
508
526
|
}
|
|
509
527
|
|
|
510
528
|
const parseAttributeTuple: PostfixParser<"@"> = (def, ctx) =>
|
|
511
|
-
|
|
529
|
+
ctx.$.parse(def[0], ctx).configureShallowDescendants(def[2] as never)
|
|
512
530
|
|
|
513
531
|
const indexOneParsers: {
|
|
514
532
|
[token in IndexOneOperator]: PostfixParser<token>
|
|
@@ -523,7 +541,7 @@ const indexOneParsers: {
|
|
|
523
541
|
|
|
524
542
|
export type FunctionalTupleOperator = ":" | "=>"
|
|
525
543
|
|
|
526
|
-
export type IndexZeroOperator = "keyof" | "instanceof" | "==="
|
|
544
|
+
export type IndexZeroOperator = "keyof" | "instanceof" | "===" | "schema"
|
|
527
545
|
|
|
528
546
|
export type IndexZeroExpression<
|
|
529
547
|
token extends IndexZeroOperator = IndexZeroOperator
|
|
@@ -533,7 +551,7 @@ const prefixParsers: {
|
|
|
533
551
|
[token in IndexZeroOperator]: PrefixParser<token>
|
|
534
552
|
} = {
|
|
535
553
|
keyof: parseKeyOfTuple,
|
|
536
|
-
instanceof: (def) => {
|
|
554
|
+
instanceof: (def, ctx) => {
|
|
537
555
|
if (typeof def[1] !== "function") {
|
|
538
556
|
return throwParseError(
|
|
539
557
|
writeInvalidConstructorMessage(objectKindOrDomainOf(def[1]))
|
|
@@ -543,21 +561,25 @@ const prefixParsers: {
|
|
|
543
561
|
.slice(1)
|
|
544
562
|
.map((ctor) =>
|
|
545
563
|
typeof ctor === "function"
|
|
546
|
-
? { proto: ctor as Constructor }
|
|
564
|
+
? ctx.$.node("proto", { proto: ctor as Constructor })
|
|
547
565
|
: throwParseError(
|
|
548
566
|
writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))
|
|
549
567
|
)
|
|
550
568
|
)
|
|
551
|
-
return
|
|
569
|
+
return branches.length === 1
|
|
570
|
+
? branches[0]
|
|
571
|
+
: ctx.$.node("union", { branches })
|
|
552
572
|
},
|
|
553
|
-
"===": (def) =>
|
|
573
|
+
"===": (def, ctx) => ctx.$.parseUnits(...def.slice(1)),
|
|
574
|
+
schema: (def, ctx) => ctx.$.node(def[1] as never)
|
|
554
575
|
}
|
|
555
576
|
|
|
556
|
-
const isIndexZeroExpression = (def:
|
|
577
|
+
const isIndexZeroExpression = (def: array): def is IndexZeroExpression =>
|
|
557
578
|
prefixParsers[def[0] as IndexZeroOperator] !== undefined
|
|
558
579
|
|
|
559
580
|
export const writeInvalidConstructorMessage = <
|
|
560
581
|
actual extends Domain | BuiltinObjectKind
|
|
561
582
|
>(
|
|
562
583
|
actual: actual
|
|
563
|
-
) =>
|
|
584
|
+
) =>
|
|
585
|
+
`Expected a constructor following 'instanceof' operator (was ${actual})` as const
|