arktype 2.0.0-dev.4 → 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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Hkt, type array, type conform, type evaluate, type intersectArrays, type isAny } from "@arktype/util";
|
|
2
|
+
import type { of } from "../constraints/ast.js";
|
|
3
|
+
import type { MorphAst, Out } from "../types/morph.js";
|
|
4
|
+
export type inferIntersection<l, r> = [l] extends [never] ? never : [r] extends [never] ? never : [l & r] extends [never] ? never : isAny<l | r> extends true ? any : l extends MorphAst<infer lIn, infer lOut> ? r extends MorphAst ? never : (In: evaluate<lIn & r>) => Out<lOut> : r extends MorphAst<infer rIn, infer rOut> ? (In: evaluate<rIn & l>) => Out<rOut> : l extends of<infer lBase, infer lConstraints> ? r extends of<infer rBase, infer rConstraints> ? of<inferIntersection<lBase, rBase>, lConstraints & rConstraints> : of<inferIntersection<lBase, r>, lConstraints> : r extends of<infer rBase, infer rConstraints> ? of<inferIntersection<l, rBase>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r> extends infer result ? result : never : l & r;
|
|
5
|
+
declare class MorphableIntersection extends Hkt.Kind {
|
|
6
|
+
f: (In: conform<this[Hkt.key], [l: unknown, r: unknown]>) => inferIntersection<(typeof In)[0], (typeof In)[1]>;
|
|
7
|
+
}
|
|
8
|
+
type intersectObjects<l, r> = [l, r] extends [
|
|
9
|
+
infer lList extends array,
|
|
10
|
+
infer rList extends array
|
|
11
|
+
] ? intersectArrays<lList, rList, MorphableIntersection> : evaluate<{
|
|
12
|
+
[k in keyof l]: k extends keyof r ? inferIntersection<l[k], r[k]> : l[k];
|
|
13
|
+
} & Omit<r, keyof l>>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=intersections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersections.d.ts","sourceRoot":"","sources":["../../shared/intersections.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EACH,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,KAAK,EACV,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAEtD,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACtD,KAAK,GACL,CAAC,CAAC,CAAC,SAAS,CAAC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O,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,KAChD,iBAAiB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;CACtD;AAED,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS;IAC5C,MAAM,KAAK,SAAS,KAAK;IACzB,MAAM,KAAK,SAAS,KAAK;CACzB,GACE,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,qBAAqB,CAAC,GACpD,QAAQ,CACR;KACE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACxE,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CACnB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intersections.js","sourceRoot":"","sources":["../../shared/intersections.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EAMH,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ResolvedArkConfig } from "../scope.js";
|
|
2
|
+
import type { Morph } from "../types/morph.js";
|
|
3
|
+
import { ArkErrors, type ArkErrorCode, type ArkErrorInput, type ArkResult, type ArkTypeError } from "./errors.js";
|
|
4
|
+
import type { TraversalPath } from "./utils.js";
|
|
5
|
+
export type QueuedMorph = {
|
|
6
|
+
path: TraversalPath;
|
|
7
|
+
morph: Morph;
|
|
8
|
+
};
|
|
9
|
+
export type BranchTraversalContext = {
|
|
10
|
+
error: ArkTypeError | undefined;
|
|
11
|
+
morphs: QueuedMorph[];
|
|
12
|
+
};
|
|
13
|
+
export declare class TraversalContext {
|
|
14
|
+
root: unknown;
|
|
15
|
+
config: ResolvedArkConfig;
|
|
16
|
+
path: TraversalPath;
|
|
17
|
+
morphs: QueuedMorph[];
|
|
18
|
+
errors: ArkErrors;
|
|
19
|
+
branches: BranchTraversalContext[];
|
|
20
|
+
seen: {
|
|
21
|
+
[name in string]?: object[];
|
|
22
|
+
};
|
|
23
|
+
constructor(root: unknown, config: ResolvedArkConfig);
|
|
24
|
+
get currentBranch(): BranchTraversalContext | undefined;
|
|
25
|
+
queueMorph(morph: Morph): void;
|
|
26
|
+
finalize(): ArkResult<any>;
|
|
27
|
+
hasError(): boolean;
|
|
28
|
+
get failFast(): boolean;
|
|
29
|
+
error<input extends ArkErrorInput>(input: input): ArkTypeError<input extends {
|
|
30
|
+
code: ArkErrorCode;
|
|
31
|
+
} ? input["code"] : "predicate">;
|
|
32
|
+
get data(): unknown;
|
|
33
|
+
invalid(input: ArkErrorInput): false;
|
|
34
|
+
pushBranch(): void;
|
|
35
|
+
popBranch(): BranchTraversalContext;
|
|
36
|
+
}
|
|
37
|
+
export type TraversalMethodsByKind<input = unknown> = {
|
|
38
|
+
Allows: TraverseAllows<input>;
|
|
39
|
+
Apply: TraverseApply<input>;
|
|
40
|
+
};
|
|
41
|
+
export type TraversalKind = keyof TraversalMethodsByKind;
|
|
42
|
+
export type TraverseAllows<data = unknown> = (data: data, ctx: TraversalContext) => boolean;
|
|
43
|
+
export type TraverseApply<data = unknown> = (data: data, ctx: TraversalContext) => void;
|
|
44
|
+
//# sourceMappingURL=traversal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traversal.d.ts","sourceRoot":"","sources":["../../shared/traversal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAC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AS,IAAI,sBAAsB;CAGnC;AAED,MAAM,MAAM,sBAAsB,CAAC,KAAK,GAAG,OAAO,IAAI;IACrD,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAA;IAC7B,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,sBAAsB,CAAA;AAExD,MAAM,MAAM,cAAc,CAAC,IAAI,GAAG,OAAO,IAAI,CAC5C,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,gBAAgB,KACjB,OAAO,CAAA;AACZ,MAAM,MAAM,aAAa,CAAC,IAAI,GAAG,OAAO,IAAI,CAC3C,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,gBAAgB,KACjB,IAAI,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { deepClone } from "@arktype/util";
|
|
2
|
+
import { ArkErrors, createError } from "./errors.js";
|
|
3
|
+
export class TraversalContext {
|
|
4
|
+
root;
|
|
5
|
+
config;
|
|
6
|
+
path = [];
|
|
7
|
+
morphs = [];
|
|
8
|
+
errors = new ArkErrors(this);
|
|
9
|
+
branches = [];
|
|
10
|
+
// Qualified
|
|
11
|
+
seen = {};
|
|
12
|
+
constructor(root, config) {
|
|
13
|
+
this.root = root;
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
get currentBranch() {
|
|
17
|
+
return this.branches.at(-1);
|
|
18
|
+
}
|
|
19
|
+
queueMorph(morph) {
|
|
20
|
+
const input = { path: [...this.path], morph };
|
|
21
|
+
this.currentBranch?.morphs.push(input) ?? this.morphs.push(input);
|
|
22
|
+
}
|
|
23
|
+
finalize() {
|
|
24
|
+
if (this.hasError()) {
|
|
25
|
+
return { errors: this.errors };
|
|
26
|
+
}
|
|
27
|
+
const data = this.root;
|
|
28
|
+
let out = data;
|
|
29
|
+
if (this.morphs.length) {
|
|
30
|
+
out = deepClone(this.root);
|
|
31
|
+
for (let i = 0; i < this.morphs.length; i++) {
|
|
32
|
+
const { path, morph } = this.morphs[i];
|
|
33
|
+
if (path.length === 0) {
|
|
34
|
+
this.path = [];
|
|
35
|
+
// if the morph applies to the root, just assign to it directly
|
|
36
|
+
const result = morph(out, this);
|
|
37
|
+
if (this.hasError())
|
|
38
|
+
return { errors: this.errors };
|
|
39
|
+
out = result;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// find the object on which the key to be morphed exists
|
|
43
|
+
let parent = out;
|
|
44
|
+
for (let pathIndex = 0; pathIndex < path.length - 1; pathIndex++)
|
|
45
|
+
parent = parent[path[pathIndex]];
|
|
46
|
+
// apply the morph function and assign the result to the corresponding property
|
|
47
|
+
const key = path.at(-1);
|
|
48
|
+
this.path = path;
|
|
49
|
+
const result = morph(parent[key], this);
|
|
50
|
+
if (this.hasError())
|
|
51
|
+
return { errors: this.errors };
|
|
52
|
+
else
|
|
53
|
+
parent[key] = result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { data, out };
|
|
57
|
+
}
|
|
58
|
+
hasError() {
|
|
59
|
+
return this.currentBranch
|
|
60
|
+
? this.currentBranch.error !== undefined
|
|
61
|
+
: this.errors.count !== 0;
|
|
62
|
+
}
|
|
63
|
+
get failFast() {
|
|
64
|
+
return this.branches.length !== 0;
|
|
65
|
+
}
|
|
66
|
+
error(input) {
|
|
67
|
+
const error = createError(this, input);
|
|
68
|
+
if (this.currentBranch) {
|
|
69
|
+
this.currentBranch.error = error;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.errors.add(error);
|
|
73
|
+
}
|
|
74
|
+
return error;
|
|
75
|
+
}
|
|
76
|
+
get data() {
|
|
77
|
+
let result = this.root;
|
|
78
|
+
for (const segment of this.path) {
|
|
79
|
+
result = result?.[segment];
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
invalid(input) {
|
|
84
|
+
this.error(input);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
pushBranch() {
|
|
88
|
+
this.branches.push({
|
|
89
|
+
error: undefined,
|
|
90
|
+
morphs: []
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
popBranch() {
|
|
94
|
+
return this.branches.pop();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=traversal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traversal.js","sourceRoot":"","sources":["../../shared/traversal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAGzC,OAAO,EACN,SAAS,EACT,WAAW,EAKX,MAAM,aAAa,CAAA;AAapB,MAAM,OAAO,gBAAgB;IAUpB;IACA;IAVR,IAAI,GAAkB,EAAE,CAAA;IACxB,MAAM,GAAkB,EAAE,CAAA;IAC1B,MAAM,GAAc,IAAI,SAAS,CAAC,IAAI,CAAC,CAAA;IACvC,QAAQ,GAA6B,EAAE,CAAA;IAEvC,YAAY;IACZ,IAAI,GAAoC,EAAE,CAAA;IAE1C,YACQ,IAAa,EACb,MAAyB;QADzB,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAmB;IAC9B,CAAC;IAEJ,IAAI,aAAa;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAED,UAAU,CAAC,KAAY;QACtB,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAA;QAC1D,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClE,CAAC;IAED,QAAQ;QACP,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACrB,OAAO,EAAE,MAAM,EAAE,IAAI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AChB,MAAM,EAAE,EAAE;SACV,CAAC,CAAA;IACH,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAG,CAAA;IAC5B,CAAC;CACD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type array, type mutable } from "@arktype/util";
|
|
2
|
+
export declare const makeRootAndArrayPropertiesMutable: <o extends object>(o: o) => { -readonly [k in keyof o]: o[k] extends array | undefined ? o[k] extends infer T ? T extends o[k] ? T extends object ? T extends (...args: never[]) => unknown ? T : { -readonly [k_1 in keyof T]: T[k_1]; } : T : never : never : o[k]; };
|
|
3
|
+
export type makeRootAndArrayPropertiesMutable<inner> = {
|
|
4
|
+
-readonly [k in keyof inner]: inner[k] extends array | undefined ? mutable<inner[k]> : inner[k];
|
|
5
|
+
} & unknown;
|
|
6
|
+
export type TraversalPath = PropertyKey[];
|
|
7
|
+
export declare const pathToPropString: (path: TraversalPath) => string;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../shared/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,MAAM,eAAe,CAAA;AAEtB,eAAO,MAAM,iCAAiC,yQAKqB,CAAA;AAEnE,MAAM,MAAM,iCAAiC,CAAC,KAAK,IAAI;IACtD,CAAC,UAAU,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,SAAS,GAC7D,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GACjB,KAAK,CAAC,CAAC,CAAC;CACX,GAAG,OAAO,CAAA;AAEX,MAAM,MAAM,aAAa,GAAG,WAAW,EAAE,CAAA;AAEzC,eAAO,MAAM,gBAAgB,2BAA0B,MAMtD,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isArray, literalPropAccess, morph } from "@arktype/util";
|
|
2
|
+
export const makeRootAndArrayPropertiesMutable = (o) =>
|
|
3
|
+
// TODO: this cast should not be required, but it seems TS is referencing
|
|
4
|
+
// the wrong parameters here?
|
|
5
|
+
morph(o, (k, v) => [k, isArray(v) ? [...v] : v]);
|
|
6
|
+
export const pathToPropString = (path) => {
|
|
7
|
+
const propAccessChain = path.reduce((s, segment) => s + literalPropAccess(segment), "");
|
|
8
|
+
return propAccessChain[0] === "." ? propAccessChain.slice(1) : propAccessChain;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../shared/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EACP,iBAAiB,EACjB,KAAK,EAGL,MAAM,eAAe,CAAA;AAEtB,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAChD,CAAI,EACmC,EAAE;AACzC,yEAAyE;AACzE,6BAA6B;AAC7B,KAAK,CAAC,CAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAU,CAAA;AAUnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAmB,EAAU,EAAE;IAC/D,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAClC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,EAC9C,EAAE,CACF,CAAA;IACD,OAAO,eAAe,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAA;AAC/E,CAAC,CAAA"}
|
package/out/type.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { type Constructor, type array, type conform } from "@arktype/util";
|
|
2
|
+
import type { Predicate } from "./constraints/predicate.js";
|
|
3
3
|
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
|
|
4
4
|
import { parseGenericParams, type GenericParamsParseError } from "./parser/generic.js";
|
|
5
5
|
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.js";
|
|
6
6
|
import type { Scope, bindThis } from "./scope.js";
|
|
7
|
+
import type { BaseMeta } from "./shared/declare.js";
|
|
8
|
+
import type { Morph, distillIn, distillOut } from "./types/morph.js";
|
|
9
|
+
import type { Type } from "./types/type.js";
|
|
7
10
|
import { arkKind } from "./util.js";
|
|
8
11
|
export type TypeParser<$> = {
|
|
9
12
|
<const def>(def: validateTypeRoot<def, $>): Type<inferTypeRoot<def, $>, $>;
|
|
10
|
-
<const zero, const one, const rest extends
|
|
11
|
-
Morph<extractOut<inferTypeRoot<zero, $>>, unknown>
|
|
12
|
-
] : one extends "@" ? [string | BaseMeta] : [validateTypeRoot<rest[0], $>] : []): Type<inferTypeRoot<[zero, one, ...rest], $>, $>;
|
|
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], $>, $>;
|
|
13
14
|
<params extends string, const def>(params: `<${validateParameterString<params>}>`, def: validateDefinition<def, $, {
|
|
14
15
|
[param in parseGenericParams<params>[number]]: unknown;
|
|
15
16
|
}>): Generic<parseGenericParams<params>, def, $>;
|
|
@@ -17,42 +18,13 @@ export type TypeParser<$> = {
|
|
|
17
18
|
export type DeclarationParser<$> = <preinferred>() => {
|
|
18
19
|
type: <def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
|
|
19
20
|
};
|
|
20
|
-
export declare const createTypeParser: <$>(
|
|
21
|
+
export declare const createTypeParser: <$>($: Scope) => TypeParser<$>;
|
|
21
22
|
export type DefinitionParser<$> = <def>(def: validateDefinition<def, $, bindThis<def>>) => def;
|
|
22
|
-
export declare class Type<t = unknown, $ = any> extends Callable<(data: unknown) => ArkResult<distill<extractOut<t>>>> {
|
|
23
|
-
definition: unknown;
|
|
24
|
-
scope: Scope;
|
|
25
|
-
[inferred]: t;
|
|
26
|
-
infer: distill<extractOut<t>>;
|
|
27
|
-
root: TypeNode<t>;
|
|
28
|
-
allows: this["root"]["allows"];
|
|
29
|
-
description: string;
|
|
30
|
-
json: Json;
|
|
31
|
-
constructor(definition: unknown, scope: Scope);
|
|
32
|
-
configure(configOrDescription: BaseMeta | string): this;
|
|
33
|
-
describe(description: string): this;
|
|
34
|
-
from(literal: this["in"]["infer"]): this["in"]["infer"];
|
|
35
|
-
and<def>(def: validateTypeRoot<def, $>): Type<inferIntersection<t, inferTypeRoot<def, $>>, $>;
|
|
36
|
-
or<def>(def: validateTypeRoot<def, $>): Type<t | inferTypeRoot<def, $>, $>;
|
|
37
|
-
morph<morph extends Morph<this["infer"]>>(morph: morph): Type<(In: this["in"]["infer"]) => Out<inferMorphOut<ReturnType<morph>>>, $>;
|
|
38
|
-
morph<morph extends Morph<this["infer"]>, def>(morph: morph, outValidator: validateTypeRoot<def, $>): Type<(In: this["in"]["infer"]) => Out<extractOut<inferTypeRoot<def, $>>>, $>;
|
|
39
|
-
narrow<def extends Predicate<extractOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: this["in"]["infer"]) => Out<inferNarrow<this["infer"], def>> : inferNarrow<this["infer"], def>, $>;
|
|
40
|
-
array(): Type<t[], $>;
|
|
41
|
-
keyof(): Type<keyof this["in"]["infer"], $>;
|
|
42
|
-
assert(data: unknown): this["infer"];
|
|
43
|
-
equals<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def, $>, $>;
|
|
44
|
-
extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def, $>, $>;
|
|
45
|
-
private inCache?;
|
|
46
|
-
get in(): Type<extractIn<t>, $>;
|
|
47
|
-
outCache?: Type<extractOut<t>, $>;
|
|
48
|
-
get out(): Type<extractOut<t>, $>;
|
|
49
|
-
toString(): string;
|
|
50
|
-
}
|
|
51
23
|
export type validateTypeRoot<def, $> = validateDefinition<def, $, bindThis<def>>;
|
|
52
24
|
export type inferTypeRoot<def, $> = inferDefinition<def, $, bindThis<def>>;
|
|
53
25
|
type validateParameterString<params extends string> = parseGenericParams<params> extends GenericParamsParseError<infer message> ? message : params;
|
|
54
|
-
export declare const validateUninstantiatedGeneric: (g: Generic) => Generic
|
|
55
|
-
export declare const generic: (parameters: string[], definition: unknown,
|
|
26
|
+
export declare const validateUninstantiatedGeneric: (g: Generic) => Generic;
|
|
27
|
+
export declare const generic: (parameters: string[], definition: unknown, $: Scope) => Generic;
|
|
56
28
|
export type GenericProps<params extends string[] = string[], def = unknown, $ = any> = {
|
|
57
29
|
[arkKind]: "generic";
|
|
58
30
|
$: $;
|
|
@@ -60,7 +32,7 @@ export type GenericProps<params extends string[] = string[], def = unknown, $ =
|
|
|
60
32
|
definition: def;
|
|
61
33
|
scope: Scope;
|
|
62
34
|
};
|
|
63
|
-
export type BoundArgs = Record<string,
|
|
35
|
+
export type BoundArgs = Record<string, Type>;
|
|
64
36
|
export type Generic<params extends string[] = string[], def = unknown, $ = any> = {
|
|
65
37
|
<args>(...args: conform<args, {
|
|
66
38
|
[i in keyof params]: validateTypeRoot<args[i & keyof args], $>;
|
package/out/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../type.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../type.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EACX,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACN,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EACX,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAG3B,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAG1E,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,SAAS,KAAK,EAC/C,EAAE,EAAE,IAAI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GAAG,IACJ;IACH,CAAC,OAAO,CAAC,EAAE,SAAS,CAAA;IACpB,CAAC,EAAE,CAAC,CAAA;IACJ,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,GAAG,CAAA;IACf,KAAK,EAAE,KAAK,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAG5C,MAAM,MAAM,OAAO,CAClB,MAAM,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,EAClC,GAAG,GAAG,OAAO,EACb,CAAC,GAAG,GAAG,IACJ;IACH,CAAC,IAAI,EACJ,GAAG,IAAI,EAAE,OAAO,CACf,IAAI,EACJ;SACE,CAAC,IAAI,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;KAC9D,CACD,GACC,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,EAAE,wBAAwB,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CAC9E,GAAG,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;AAEhC,KAAK,wBAAwB,CAAC,MAAM,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,IAAI,IAAI;KAChE,CAAC,IAAI,MAAM,MAAM,GAAG,GAAG,MAAM,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,aAAa,CAC5D,IAAI,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC,EACpB,CAAC,CACD;CACD,CAAA"}
|
package/out/type.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Callable, morph } from "@arktype/util";
|
|
1
|
+
import { morph } from "@arktype/util";
|
|
3
2
|
import { parseGenericParams } from "./parser/generic.js";
|
|
4
|
-
import { configureShallowDescendants } from "./parser/shared.js";
|
|
5
3
|
import { arkKind } from "./util.js";
|
|
6
|
-
export const createTypeParser = (
|
|
4
|
+
export const createTypeParser = ($) => {
|
|
7
5
|
const parser = (...args) => {
|
|
8
6
|
if (args.length === 1) {
|
|
9
7
|
// treat as a simple definition
|
|
10
|
-
return
|
|
8
|
+
return $.parseTypeRoot(args[0]);
|
|
11
9
|
}
|
|
12
10
|
if (args.length === 2 &&
|
|
13
11
|
typeof args[0] === "string" &&
|
|
@@ -17,122 +15,38 @@ export const createTypeParser = (scope) => {
|
|
|
17
15
|
// treat as a generic
|
|
18
16
|
const params = parseGenericParams(args[0].slice(1, -1));
|
|
19
17
|
const def = args[1];
|
|
20
|
-
return validateUninstantiatedGeneric(generic(params, def,
|
|
18
|
+
return validateUninstantiatedGeneric(generic(params, def, $));
|
|
21
19
|
}
|
|
22
20
|
// otherwise, treat as a tuple expression. technically, this also allows
|
|
23
21
|
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
24
22
|
// part of the API as specified by the associated types
|
|
25
|
-
return
|
|
23
|
+
return $.parseTypeRoot(args);
|
|
26
24
|
};
|
|
27
25
|
return parser;
|
|
28
26
|
};
|
|
29
|
-
export class Type extends Callable {
|
|
30
|
-
definition;
|
|
31
|
-
scope;
|
|
32
|
-
root;
|
|
33
|
-
allows;
|
|
34
|
-
description;
|
|
35
|
-
json;
|
|
36
|
-
constructor(definition, scope) {
|
|
37
|
-
const root = parseTypeRoot(definition, scope);
|
|
38
|
-
super(root.apply, root);
|
|
39
|
-
this.definition = definition;
|
|
40
|
-
this.scope = scope;
|
|
41
|
-
this.root = root;
|
|
42
|
-
this.allows = root.allows;
|
|
43
|
-
this.json = root.json;
|
|
44
|
-
this.description = this.root.description;
|
|
45
|
-
}
|
|
46
|
-
configure(configOrDescription) {
|
|
47
|
-
return new Type(configureShallowDescendants(this.root, configOrDescription), this.scope);
|
|
48
|
-
}
|
|
49
|
-
describe(description) {
|
|
50
|
-
return this.configure(description);
|
|
51
|
-
}
|
|
52
|
-
// TODO: should return out
|
|
53
|
-
from(literal) {
|
|
54
|
-
return literal;
|
|
55
|
-
}
|
|
56
|
-
// TODO: Morph intersections, ordering
|
|
57
|
-
and(def) {
|
|
58
|
-
return new Type(this.root.and(parseTypeRoot(def, this.scope)), this.scope);
|
|
59
|
-
}
|
|
60
|
-
or(def) {
|
|
61
|
-
return new Type(this.root.or(parseTypeRoot(def, this.scope)), this.scope);
|
|
62
|
-
}
|
|
63
|
-
morph(morph, outValidator) {
|
|
64
|
-
// TODO: tuple expression for out validator
|
|
65
|
-
outValidator;
|
|
66
|
-
return this;
|
|
67
|
-
// return new Type(
|
|
68
|
-
// this.root.constrain("morph", morph),
|
|
69
|
-
// this.scope
|
|
70
|
-
// ) as never
|
|
71
|
-
}
|
|
72
|
-
// TODO: based on below, should maybe narrow morph output if used after
|
|
73
|
-
narrow(def) {
|
|
74
|
-
return new Type(this.root.constrain("predicate", def), this.scope);
|
|
75
|
-
}
|
|
76
|
-
array() {
|
|
77
|
-
return new Type(this.root.array(), this.scope);
|
|
78
|
-
}
|
|
79
|
-
keyof() {
|
|
80
|
-
return new Type(this.root.keyof(), this.scope);
|
|
81
|
-
}
|
|
82
|
-
assert(data) {
|
|
83
|
-
const result = this.call(null, data);
|
|
84
|
-
return result.errors ? result.errors.throw() : result.out;
|
|
85
|
-
}
|
|
86
|
-
equals(other) {
|
|
87
|
-
return this.root.equals(parseTypeRoot(other, this.scope));
|
|
88
|
-
}
|
|
89
|
-
extends(other) {
|
|
90
|
-
return this.root.extends(parseTypeRoot(other, this.scope));
|
|
91
|
-
}
|
|
92
|
-
inCache;
|
|
93
|
-
get in() {
|
|
94
|
-
this.inCache ??= new Type(this.root.in, this.scope);
|
|
95
|
-
return this.inCache;
|
|
96
|
-
}
|
|
97
|
-
outCache;
|
|
98
|
-
get out() {
|
|
99
|
-
this.outCache ??= new Type(this.root.out, this.scope);
|
|
100
|
-
return this.outCache;
|
|
101
|
-
}
|
|
102
|
-
toString() {
|
|
103
|
-
return this.description;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const parseTypeRoot = (def, scope, args) => scope.parseDefinition(def, {
|
|
107
|
-
args: args ?? scope.bindThis(),
|
|
108
|
-
baseName: "type"
|
|
109
|
-
});
|
|
110
27
|
export const validateUninstantiatedGeneric = (g) => {
|
|
111
28
|
// the unconstrained instantiation of the generic is not used for now
|
|
112
29
|
// other than to eagerly validate that the def does not contain any errors
|
|
113
|
-
g.scope.
|
|
30
|
+
g.scope.parseTypeRoot(g.definition,
|
|
114
31
|
// once we support constraints on generic parameters, we'd use
|
|
115
32
|
// the base type here: https://github.com/arktypeio/arktype/issues/796
|
|
116
33
|
{
|
|
117
34
|
baseName: "generic",
|
|
118
|
-
args: morph(g.parameters, (_, name) => [name, keywords.unknown])
|
|
35
|
+
args: morph(g.parameters, (_, name) => [name, g.scope.keywords.unknown])
|
|
119
36
|
});
|
|
120
37
|
return g;
|
|
121
38
|
};
|
|
122
|
-
export const generic = (parameters, definition,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// $ is only needed at compile-time
|
|
136
|
-
});
|
|
137
|
-
};
|
|
39
|
+
export const generic = (parameters, definition, $) => Object.assign((...args) => {
|
|
40
|
+
const argNodes = morph(parameters, (i, param) => [
|
|
41
|
+
param,
|
|
42
|
+
$.parseTypeRoot(args[i])
|
|
43
|
+
]);
|
|
44
|
+
return $.parseTypeRoot(definition, { args: argNodes });
|
|
45
|
+
}, {
|
|
46
|
+
[arkKind]: "generic",
|
|
47
|
+
parameters,
|
|
48
|
+
definition,
|
|
49
|
+
scope: $
|
|
50
|
+
// $ is only needed at compile-time
|
|
51
|
+
});
|
|
138
52
|
//# 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,EACN,
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../type.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,EAIL,MAAM,eAAe,CAAA;AAOtB,OAAO,EACN,kBAAkB,EAElB,MAAM,qBAAqB,CAAA;AAU5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAmDnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAI,CAAQ,EAAiB,EAAE;IAC9D,MAAM,MAAM,GAAG,CAAC,GAAG,IAAe,EAAkB,EAAE;QACrD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,+BAA+B;YAC/B,OAAO,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QAChC,CAAC;QACD,IACC,IAAI,CAAC,MAAM,KAAK,CAAC;YACjB,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;YAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;YAClB,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EACrB,CAAC;YACF,4EAA4E;YAC5E,qBAAqB;YACrB,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YACvD,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YACnB,OAAO,6BAA6B,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAU,CAAC,CAAA;QACvE,CAAC;QACD,wEAAwE;QACxE,0EAA0E;QAC1E,uDAAuD;QACvD,OAAO,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC,CAAA;IACD,OAAO,MAAe,CAAA;AACvB,CAAC,CAAA;AAeD,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAU,EAAW,EAAE;IACpE,qEAAqE;IACrE,0EAA0E;IAC1E,CAAC,CAAC,KAAK,CAAC,aAAa,CACpB,CAAC,CAAC,UAAU;IACZ,8DAA8D;IAC9D,sEAAsE;IACtE;QACC,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KACxE,CACD,CAAA;IACD,OAAO,CAAC,CAAA;AACT,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CACtB,UAAoB,EACpB,UAAmB,EACnB,CAAQ,EACE,EAAE,CACZ,MAAM,CAAC,MAAM,CACZ,CAAC,GAAG,IAAe,EAAE,EAAE;IACtB,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAChD,KAAK;QACL,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACxB,CAAC,CAAA;IACF,OAAO,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AACvD,CAAC,EACD;IACC,CAAC,OAAO,CAAC,EAAE,SAAS;IACpB,UAAU;IACV,UAAU;IACV,KAAK,EAAE,CAAC;IACR,mCAAmC;CACD,CAC1B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Constructor, Key, NonEnumerableDomain, inferDomain, instanceOf, isAny } from "@arktype/util";
|
|
2
|
+
import type { Schema } from "../kinds.js";
|
|
3
|
+
import type { NodeCompiler } from "../shared/compile.js";
|
|
4
|
+
import type { BasisKind } from "../shared/implement.js";
|
|
5
|
+
import type { TraverseApply } from "../shared/traversal.js";
|
|
6
|
+
import type { DomainSchema } from "./domain.js";
|
|
7
|
+
import type { ProtoSchema } from "./proto.js";
|
|
8
|
+
import { BaseType, type BaseTypeDeclaration, type Type } from "./type.js";
|
|
9
|
+
import type { UnitSchema } from "./unit.js";
|
|
10
|
+
export interface BaseBasisDeclaration extends BaseTypeDeclaration {
|
|
11
|
+
kind: BasisKind;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class BaseBasis<t, d extends BaseBasisDeclaration, $> extends BaseType<t, d, $> {
|
|
14
|
+
abstract readonly expression: string;
|
|
15
|
+
abstract readonly compiledCondition: string;
|
|
16
|
+
abstract readonly compiledNegation: string;
|
|
17
|
+
abstract readonly errorContext: d["errorContext"];
|
|
18
|
+
abstract literalKeys: Key[];
|
|
19
|
+
rawKeyOf(): Type;
|
|
20
|
+
traverseApply: TraverseApply<d["prerequisite"]>;
|
|
21
|
+
compile(js: NodeCompiler): void;
|
|
22
|
+
}
|
|
23
|
+
export type inferBasis<def extends Schema<BasisKind>> = isAny<def> extends true ? any : def extends NonEnumerableDomain ? inferDomain<def> : def extends Constructor<infer instance> ? instance : def extends DomainSchema<infer domain> ? inferDomain<domain> : def extends ProtoSchema<infer proto> ? instanceOf<proto> : def extends UnitSchema<infer is> ? is : never;
|
|
24
|
+
//# sourceMappingURL=basis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basis.d.ts","sourceRoot":"","sources":["../../types/basis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,GAAG,EACH,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,KAAK,EACL,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,KAAK,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M,CAAC,GACtC,WAAW,CAAC,MAAM,CAAC,GACnB,GAAG,SAAS,WAAW,CAAC,MAAM,KAAK,CAAC,GACpC,UAAU,CAAC,KAAK,CAAC,GACjB,GAAG,SAAS,UAAU,CAAC,MAAM,EAAE,CAAC,GAChC,EAAE,GACF,KAAK,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseType } from "./type.js";
|
|
2
|
+
export class BaseBasis extends BaseType {
|
|
3
|
+
rawKeyOf() {
|
|
4
|
+
return this.$.parseUnits(...this.literalKeys);
|
|
5
|
+
}
|
|
6
|
+
traverseApply = (data, ctx) => {
|
|
7
|
+
if (!this.traverseAllows(data, ctx)) {
|
|
8
|
+
ctx.error(this.errorContext);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
compile(js) {
|
|
12
|
+
js.compilePrimitive(this);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=basis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basis.js","sourceRoot":"","sources":["../../types/basis.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,QAAQ,EAAuC,MAAM,WAAW,CAAA;AAOzE,MAAM,OAAgB,SAIpB,SAAQ,QAAiB;IAO1B,QAAQ;QACP,OAAO,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAC9C,CAAC;IAED,aAAa,GAAqC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAC/D,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;YACrC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,YAAqB,CAAC,CAAA;QACtC,CAAC;IACF,CAAC,CAAA;IAED,OAAO,CAAC,EAAgB;QACvB,EAAE,CAAC,gBAAgB,CAAC,IAAa,CAAC,CAAA;IACnC,CAAC;CACD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Domain, type SerializedPrimitive, type evaluate } from "@arktype/util";
|
|
2
|
+
import type { UnionChildNode } from "./union.js";
|
|
3
|
+
export type CaseKey<kind extends DiscriminantKind = DiscriminantKind> = DiscriminantKind extends kind ? string : DiscriminantKinds[kind] | "default";
|
|
4
|
+
export type Discriminant<kind extends DiscriminantKind = DiscriminantKind> = Readonly<{
|
|
5
|
+
readonly path: string[];
|
|
6
|
+
readonly kind: kind;
|
|
7
|
+
readonly cases: DiscriminatedCases<kind>;
|
|
8
|
+
readonly isPureRootLiteral: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export type DiscriminatedCases<kind extends DiscriminantKind = DiscriminantKind> = Readonly<{
|
|
11
|
+
[caseKey in CaseKey<kind>]: Discriminant | UnionChildNode[];
|
|
12
|
+
}>;
|
|
13
|
+
export type DiscriminantKinds = {
|
|
14
|
+
domain: Domain;
|
|
15
|
+
value: SerializedPrimitive;
|
|
16
|
+
};
|
|
17
|
+
export type DiscriminantKind = evaluate<keyof DiscriminantKinds>;
|
|
18
|
+
export declare const discriminate: (branches: readonly UnionChildNode[]) => Discriminant | null;
|
|
19
|
+
export declare const writeUndiscriminableMorphUnionMessage: <path extends string>(path: path) => `${string} union including one or more morphs must be discriminable`;
|
|
20
|
+
//# sourceMappingURL=discriminate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discriminate.d.ts","sourceRoot":"","sources":["../../types/discriminate.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,MAAM,EACX,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EAGb,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,MAAM,MAAM,OAAO,CAAC,IAAI,SAAS,gBAAgB,GAAG,gBAAgB,IACnE,gBAAgB,SAAS,IAAI,GAAG,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,SAAS,CAA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