arktype 2.0.0-dev.4 → 2.0.0-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/array.test.ts +176 -236
- package/__tests__/badDefinitionType.test.ts +10 -3
- package/__tests__/basis.test.ts +6 -2
- package/__tests__/bounds.test.ts +282 -352
- package/__tests__/cast.test.ts +7 -2
- package/__tests__/completions.test.ts +8 -3
- package/__tests__/config.test.ts +16 -8
- package/__tests__/cyclic.test.ts +141 -137
- package/__tests__/dateLiteral.test.ts +8 -4
- package/__tests__/declared.test.ts +2 -2
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +45 -25
- package/__tests__/enclosed.test.ts +39 -25
- package/__tests__/examples.test.ts +56 -56
- package/__tests__/expressions.test.ts +184 -112
- package/__tests__/generic.test.ts +307 -288
- package/__tests__/group.test.ts +67 -54
- package/__tests__/imports.test.ts +44 -37
- package/__tests__/instanceof.test.ts +17 -15
- package/__tests__/intersection.test.ts +50 -46
- package/__tests__/keyTraversal.test.ts +6 -3
- package/__tests__/keyof.test.ts +68 -52
- package/__tests__/keywords.test.ts +149 -136
- package/__tests__/literal.test.ts +38 -15
- package/__tests__/match.test.ts +234 -224
- package/__tests__/morph.test.ts +300 -269
- package/__tests__/narrow.test.ts +46 -42
- package/__tests__/objectLiteral.test.ts +228 -210
- package/__tests__/realWorld.test.ts +63 -0
- package/__tests__/regex.test.ts +17 -7
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +65 -18
- package/__tests__/serialization.test.ts +19 -0
- package/__tests__/string.test.ts +11 -7
- package/__tests__/submodule.test.ts +26 -39
- package/__tests__/this.test.ts +83 -57
- package/__tests__/thunk.test.ts +13 -7
- package/__tests__/traverse.test.ts +50 -37
- package/__tests__/tsGenerics.test.ts +12 -12
- package/__tests__/type.test.ts +38 -0
- package/__tests__/typeReference.test.ts +7 -7
- package/__tests__/unenclosed.test.ts +116 -100
- package/__tests__/union.test.ts +171 -104
- package/ark.ts +18 -65
- package/generic.ts +67 -0
- package/main.ts +6 -18
- package/match.ts +53 -67
- package/module.ts +15 -0
- package/out/ark.d.ts +12 -36
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +9 -17
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +205 -0
- package/out/base.d.ts.map +1 -0
- package/out/base.js +320 -0
- package/out/base.js.map +1 -0
- package/out/builtins/builtins.d.ts +23 -0
- package/out/builtins/builtins.d.ts.map +1 -0
- package/out/builtins/builtins.js +15 -0
- package/out/builtins/builtins.js.map +1 -0
- package/out/builtins/jsObjects.d.ts +19 -0
- package/out/builtins/jsObjects.d.ts.map +1 -0
- package/out/builtins/jsObjects.js +18 -0
- package/out/builtins/jsObjects.js.map +1 -0
- package/out/builtins/parsing.d.ts +16 -0
- package/out/builtins/parsing.d.ts.map +1 -0
- package/out/builtins/parsing.js +62 -0
- package/out/builtins/parsing.js.map +1 -0
- package/out/builtins/tsGenerics.d.ts +2 -0
- package/out/builtins/tsGenerics.d.ts.map +1 -0
- package/out/builtins/tsGenerics.js +26 -0
- package/out/builtins/tsGenerics.js.map +1 -0
- package/out/builtins/tsKeywords.d.ts +23 -0
- package/out/builtins/tsKeywords.d.ts.map +1 -0
- package/out/builtins/tsKeywords.js +23 -0
- package/out/builtins/tsKeywords.js.map +1 -0
- package/out/builtins/utils/creditCard.d.ts +3 -0
- package/out/builtins/utils/creditCard.d.ts.map +1 -0
- package/out/builtins/utils/creditCard.js +35 -0
- package/out/builtins/utils/creditCard.js.map +1 -0
- package/out/builtins/utils/date.d.ts +41 -0
- package/out/builtins/utils/date.d.ts.map +1 -0
- package/out/builtins/utils/date.js +56 -0
- package/out/builtins/utils/date.js.map +1 -0
- package/out/builtins/validation.d.ts +19 -0
- package/out/builtins/validation.d.ts.map +1 -0
- package/out/builtins/validation.js +74 -0
- package/out/builtins/validation.js.map +1 -0
- package/out/config.d.ts +9 -0
- package/out/config.d.ts.map +1 -0
- package/out/config.js +18 -0
- package/out/config.js.map +1 -0
- package/out/constraints/ast.d.ts +287 -0
- package/out/constraints/ast.d.ts.map +1 -0
- package/out/constraints/ast.js +2 -0
- package/out/constraints/ast.js.map +1 -0
- package/out/constraints/constraint.d.ts +200 -0
- package/out/constraints/constraint.d.ts.map +1 -0
- package/out/constraints/constraint.js +25 -0
- package/out/constraints/constraint.js.map +1 -0
- package/out/constraints/predicate.d.ts +64 -0
- package/out/constraints/predicate.d.ts.map +1 -0
- package/out/constraints/predicate.js +52 -0
- package/out/constraints/predicate.js.map +1 -0
- package/out/constraints/props/index.d.ts +42 -0
- package/out/constraints/props/index.d.ts.map +1 -0
- package/out/constraints/props/index.js +56 -0
- package/out/constraints/props/index.js.map +1 -0
- package/out/constraints/props/optional.d.ts +37 -0
- package/out/constraints/props/optional.d.ts.map +1 -0
- package/out/constraints/props/optional.js +56 -0
- package/out/constraints/props/optional.js.map +1 -0
- package/out/constraints/props/prop.d.ts +49 -0
- package/out/constraints/props/prop.d.ts.map +1 -0
- package/out/constraints/props/prop.js +106 -0
- package/out/constraints/props/prop.js.map +1 -0
- package/out/constraints/props/props.d.ts +37 -0
- package/out/constraints/props/props.d.ts.map +1 -0
- package/out/constraints/props/props.js +121 -0
- package/out/constraints/props/props.js.map +1 -0
- package/out/constraints/props/required.d.ts +46 -0
- package/out/constraints/props/required.d.ts.map +1 -0
- package/out/constraints/props/required.js +81 -0
- package/out/constraints/props/required.js.map +1 -0
- package/out/constraints/props/sequence.d.ts +82 -0
- package/out/constraints/props/sequence.d.ts.map +1 -0
- package/out/constraints/props/sequence.js +376 -0
- package/out/constraints/props/sequence.js.map +1 -0
- package/out/constraints/props/shared.d.ts +3 -0
- package/out/constraints/props/shared.d.ts.map +1 -0
- package/out/constraints/props/shared.js +4 -0
- package/out/constraints/props/shared.js.map +1 -0
- package/out/constraints/refinements/after.d.ts +33 -0
- package/out/constraints/refinements/after.d.ts.map +1 -0
- package/out/constraints/refinements/after.js +36 -0
- package/out/constraints/refinements/after.js.map +1 -0
- package/out/constraints/refinements/before.d.ts +33 -0
- package/out/constraints/refinements/before.d.ts.map +1 -0
- package/out/constraints/refinements/before.js +43 -0
- package/out/constraints/refinements/before.js.map +1 -0
- package/out/constraints/refinements/divisor.d.ts +52 -0
- package/out/constraints/refinements/divisor.d.ts.map +1 -0
- package/out/constraints/refinements/divisor.js +52 -0
- package/out/constraints/refinements/divisor.js.map +1 -0
- package/out/constraints/refinements/exactLength.d.ts +45 -0
- package/out/constraints/refinements/exactLength.d.ts.map +1 -0
- package/out/constraints/refinements/exactLength.js +52 -0
- package/out/constraints/refinements/exactLength.js.map +1 -0
- package/out/constraints/refinements/kinds.d.ts +29 -0
- package/out/constraints/refinements/kinds.d.ts.map +1 -0
- package/out/constraints/refinements/kinds.js +17 -0
- package/out/constraints/refinements/kinds.js.map +1 -0
- package/out/constraints/refinements/length.d.ts +48 -0
- package/out/constraints/refinements/length.d.ts.map +1 -0
- package/out/constraints/refinements/length.js +53 -0
- package/out/constraints/refinements/length.js.map +1 -0
- package/out/constraints/refinements/max.d.ts +31 -0
- package/out/constraints/refinements/max.d.ts.map +1 -0
- package/out/constraints/refinements/max.js +35 -0
- package/out/constraints/refinements/max.js.map +1 -0
- package/out/constraints/refinements/maxLength.d.ts +32 -0
- package/out/constraints/refinements/maxLength.d.ts.map +1 -0
- package/out/constraints/refinements/maxLength.js +36 -0
- package/out/constraints/refinements/maxLength.js.map +1 -0
- package/out/constraints/refinements/min.d.ts +31 -0
- package/out/constraints/refinements/min.d.ts.map +1 -0
- package/out/constraints/refinements/min.js +28 -0
- package/out/constraints/refinements/min.js.map +1 -0
- package/out/constraints/refinements/minLength.d.ts +32 -0
- package/out/constraints/refinements/minLength.d.ts.map +1 -0
- package/out/constraints/refinements/minLength.js +33 -0
- package/out/constraints/refinements/minLength.js.map +1 -0
- package/out/constraints/refinements/range.d.ts +119 -0
- package/out/constraints/refinements/range.d.ts.map +1 -0
- package/out/constraints/refinements/range.js +89 -0
- package/out/constraints/refinements/range.js.map +1 -0
- package/out/constraints/refinements/regex.d.ts +47 -0
- package/out/constraints/refinements/regex.d.ts.map +1 -0
- package/out/constraints/refinements/regex.js +37 -0
- package/out/constraints/refinements/regex.js.map +1 -0
- package/out/constraints/refinements/shared.d.ts +20 -0
- package/out/constraints/refinements/shared.d.ts.map +1 -0
- package/out/constraints/refinements/shared.js +10 -0
- package/out/constraints/refinements/shared.js.map +1 -0
- package/out/generic.d.ts +22 -0
- package/out/generic.d.ts.map +1 -0
- package/out/generic.js +23 -0
- package/out/generic.js.map +1 -0
- package/out/inference.d.ts +137 -0
- package/out/inference.d.ts.map +1 -0
- package/out/inference.js +73 -0
- package/out/inference.js.map +1 -0
- package/out/keywords/ark.d.ts +70 -0
- package/out/keywords/ark.d.ts.map +1 -0
- package/out/keywords/ark.js +29 -0
- package/out/keywords/ark.js.map +1 -0
- package/out/keywords/internal.d.ts +13 -0
- package/out/keywords/internal.d.ts.map +1 -0
- package/out/keywords/internal.js +13 -0
- package/out/keywords/internal.js.map +1 -0
- package/out/keywords/jsObject.d.ts +20 -0
- package/out/keywords/jsObject.d.ts.map +1 -0
- package/out/keywords/jsObject.js +18 -0
- package/out/keywords/jsObject.js.map +1 -0
- package/out/keywords/parsing.d.ts +17 -0
- package/out/keywords/parsing.d.ts.map +1 -0
- package/out/keywords/parsing.js +64 -0
- package/out/keywords/parsing.js.map +1 -0
- package/out/keywords/root.d.ts +7 -0
- package/out/keywords/root.d.ts.map +1 -0
- package/out/keywords/root.js +4 -0
- package/out/keywords/root.js.map +1 -0
- package/out/keywords/tsGenerics.d.ts +2 -0
- package/out/keywords/tsGenerics.d.ts.map +1 -0
- package/out/keywords/tsGenerics.js +26 -0
- package/out/keywords/tsGenerics.js.map +1 -0
- package/out/keywords/tsPrimitive.d.ts +24 -0
- package/out/keywords/tsPrimitive.d.ts.map +1 -0
- package/out/keywords/tsPrimitive.js +25 -0
- package/out/keywords/tsPrimitive.js.map +1 -0
- package/out/keywords/utils/creditCard.d.ts +11 -0
- package/out/keywords/utils/creditCard.d.ts.map +1 -0
- package/out/keywords/utils/creditCard.js +35 -0
- package/out/keywords/utils/creditCard.js.map +1 -0
- package/out/keywords/utils/date.d.ts +45 -0
- package/out/keywords/utils/date.d.ts.map +1 -0
- package/out/keywords/utils/date.js +56 -0
- package/out/keywords/utils/date.js.map +1 -0
- package/out/keywords/validation.d.ts +20 -0
- package/out/keywords/validation.d.ts.map +1 -0
- package/out/keywords/validation.js +80 -0
- package/out/keywords/validation.js.map +1 -0
- package/out/kinds.d.ts +102 -0
- package/out/kinds.d.ts.map +1 -0
- package/out/kinds.js +29 -0
- package/out/kinds.js.map +1 -0
- package/out/main.d.ts +6 -6
- package/out/main.d.ts.map +1 -1
- package/out/main.js +4 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +18 -23
- package/out/match.d.ts.map +1 -1
- package/out/match.js +3 -4
- package/out/match.js.map +1 -1
- package/out/module.d.ts +11 -0
- package/out/module.d.ts.map +1 -0
- package/out/module.js +4 -0
- package/out/module.js.map +1 -0
- package/out/parse.d.ts +29 -0
- package/out/parse.d.ts.map +1 -0
- package/out/parse.js +161 -0
- package/out/parse.js.map +1 -0
- package/out/parser/definition.d.ts +9 -12
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +10 -12
- package/out/parser/definition.js.map +1 -1
- package/out/parser/generic.d.ts +3 -4
- package/out/parser/generic.d.ts.map +1 -1
- package/out/parser/generic.js +6 -8
- package/out/parser/generic.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +44 -12
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +43 -36
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +9 -6
- package/out/parser/semantic/bounds.d.ts.map +1 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +5 -6
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +25 -0
- package/out/parser/semantic/infer.d.ts.map +1 -0
- package/out/parser/semantic/infer.js +2 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -6
- package/out/parser/semantic/utils.d.ts.map +1 -1
- package/out/parser/semantic/validate.d.ts +14 -12
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js +1 -0
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -12
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +27 -17
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +1 -2
- package/out/parser/string/reduce/shared.d.ts.map +1 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +26 -22
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -1
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js +2 -2
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -2
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +6 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -9
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js +6 -8
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +3 -3
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js +8 -11
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +13 -20
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +21 -26
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +15 -12
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +42 -48
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -2
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/operator/operator.d.ts +1 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +1 -1
- package/out/parser/string/shift/operator/operator.js +12 -18
- package/out/parser/string/shift/operator/operator.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts +2 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/shift/scanner.js +12 -11
- package/out/parser/string/shift/scanner.js.map +1 -1
- package/out/parser/string/string.d.ts +8 -5
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +96 -37
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +61 -66
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +175 -0
- package/out/schema.d.ts.map +1 -0
- package/out/schema.js +73 -0
- package/out/schema.js.map +1 -0
- package/out/schemaScope.d.ts +180 -0
- package/out/schemaScope.d.ts.map +1 -0
- package/out/schemaScope.js +235 -0
- package/out/schemaScope.js.map +1 -0
- package/out/scope.d.ts +42 -114
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +51 -181
- package/out/scope.js.map +1 -1
- package/out/shared/compile.d.ts +22 -0
- package/out/shared/compile.d.ts.map +1 -0
- package/out/shared/compile.js +79 -0
- package/out/shared/compile.js.map +1 -0
- package/out/shared/context.d.ts +54 -0
- package/out/shared/context.d.ts.map +1 -0
- package/out/shared/context.js +53 -0
- package/out/shared/context.js.map +1 -0
- package/out/shared/declare.d.ts +69 -0
- package/out/shared/declare.d.ts.map +1 -0
- package/out/shared/declare.js +2 -0
- package/out/shared/declare.js.map +1 -0
- package/out/shared/disjoint.d.ts +91 -0
- package/out/shared/disjoint.d.ts.map +1 -0
- package/out/shared/disjoint.js +110 -0
- package/out/shared/disjoint.js.map +1 -0
- package/out/shared/errors.d.ts +99 -0
- package/out/shared/errors.d.ts.map +1 -0
- package/out/shared/errors.js +108 -0
- package/out/shared/errors.js.map +1 -0
- package/out/shared/implement.d.ts +363 -0
- package/out/shared/implement.d.ts.map +1 -0
- package/out/shared/implement.js +68 -0
- package/out/shared/implement.js.map +1 -0
- package/out/shared/inference.d.ts +6 -0
- package/out/shared/inference.d.ts.map +1 -0
- package/out/shared/inference.js +5 -0
- package/out/shared/inference.js.map +1 -0
- package/out/shared/intersections.d.ts +60 -0
- package/out/shared/intersections.d.ts.map +1 -0
- package/out/shared/intersections.js +2 -0
- package/out/shared/intersections.js.map +1 -0
- package/out/shared/traversal.d.ts +62 -0
- package/out/shared/traversal.d.ts.map +1 -0
- package/out/shared/traversal.js +97 -0
- package/out/shared/traversal.js.map +1 -0
- package/out/shared/utils.d.ts +24 -0
- package/out/shared/utils.d.ts.map +1 -0
- package/out/shared/utils.js +15 -0
- package/out/shared/utils.js.map +1 -0
- package/out/type.d.ts +23 -59
- package/out/type.d.ts.map +1 -1
- package/out/type.js +2 -137
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +47 -0
- package/out/types/basis.d.ts.map +1 -0
- package/out/types/basis.js +15 -0
- package/out/types/basis.js.map +1 -0
- package/out/types/discriminate.d.ts +34 -0
- package/out/types/discriminate.d.ts.map +1 -0
- package/out/types/discriminate.js +120 -0
- package/out/types/discriminate.js.map +1 -0
- package/out/types/domain.d.ts +57 -0
- package/out/types/domain.d.ts.map +1 -0
- package/out/types/domain.js +41 -0
- package/out/types/domain.js.map +1 -0
- package/out/types/intersection.d.ts +127 -0
- package/out/types/intersection.d.ts.map +1 -0
- package/out/types/intersection.js +379 -0
- package/out/types/intersection.js.map +1 -0
- package/out/types/morph.d.ts +157 -0
- package/out/types/morph.d.ts.map +1 -0
- package/out/types/morph.js +99 -0
- package/out/types/morph.js.map +1 -0
- package/out/types/proto.d.ts +51 -0
- package/out/types/proto.d.ts.map +1 -0
- package/out/types/proto.js +60 -0
- package/out/types/proto.js.map +1 -0
- package/out/types/type.d.ts +143 -0
- package/out/types/type.d.ts.map +1 -0
- package/out/types/type.js +123 -0
- package/out/types/type.js.map +1 -0
- package/out/types/union.d.ts +71 -0
- package/out/types/union.d.ts.map +1 -0
- package/out/types/union.js +379 -0
- package/out/types/union.js.map +1 -0
- package/out/types/unit.d.ts +45 -0
- package/out/types/unit.d.ts.map +1 -0
- package/out/types/unit.js +56 -0
- package/out/types/unit.js.map +1 -0
- package/out/util.d.ts +30 -18
- package/out/util.d.ts.map +1 -1
- package/out/util.js +8 -7
- package/out/util.js.map +1 -1
- package/package.json +7 -3
- package/parser/definition.ts +73 -89
- package/parser/generic.ts +35 -36
- package/parser/objectLiteral.ts +143 -117
- package/parser/semantic/bounds.ts +33 -32
- package/parser/semantic/divisor.ts +8 -10
- package/parser/semantic/infer.ts +141 -0
- package/parser/semantic/utils.ts +12 -23
- package/parser/semantic/validate.ts +82 -73
- package/parser/string/reduce/dynamic.ts +61 -46
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +65 -67
- package/parser/string/shift/operand/date.ts +12 -8
- package/parser/string/shift/operand/enclosed.ts +22 -17
- package/parser/string/shift/operand/genericArgs.ts +46 -45
- package/parser/string/shift/operand/operand.ts +32 -38
- package/parser/string/shift/operand/unenclosed.ts +106 -147
- package/parser/string/shift/operator/bounds.ts +114 -106
- package/parser/string/shift/operator/divisor.ts +12 -14
- package/parser/string/shift/operator/operator.ts +35 -46
- package/parser/string/shift/scanner.ts +49 -46
- package/parser/string/string.ts +28 -32
- package/parser/tuple.ts +288 -308
- package/scope.ts +183 -425
- package/type.ts +82 -281
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/typeMethods.test.ts +0 -69
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -32
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/shared.d.ts +0 -62
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -56
- package/out/parser/shared.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/parser/semantic/semantic.ts +0 -143
- package/parser/shared.ts +0 -170
- package/util.ts +0 -36
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Dict,
|
|
3
|
+
type List,
|
|
4
|
+
type evaluate,
|
|
5
|
+
type require,
|
|
6
|
+
type requireKeys
|
|
7
|
+
} from "@arktype/util"
|
|
8
|
+
import type { Node, TypeNode } from "./base.js"
|
|
9
|
+
import type { schema } from "./builtins/builtins.js"
|
|
10
|
+
import type { JsObjects } from "./builtins/jsObjects.js"
|
|
11
|
+
import type { TsKeywords } from "./builtins/tsKeywords.js"
|
|
12
|
+
import type { LengthBoundableData } from "./constraints/refinements/range.js"
|
|
13
|
+
import type {
|
|
14
|
+
instantiateAliases,
|
|
15
|
+
instantiateSchemaBranches,
|
|
16
|
+
validateAliases,
|
|
17
|
+
validateSchemaBranch
|
|
18
|
+
} from "./inference.js"
|
|
19
|
+
import { type Schema, type reducibleKindOf } from "./kinds.js"
|
|
20
|
+
import { type SchemaParseOptions } from "./parse.js"
|
|
21
|
+
import type { TraverseAllows, TraverseApply } from "./shared/context.js"
|
|
22
|
+
import type {
|
|
23
|
+
ActualWriter,
|
|
24
|
+
ArkErrorCode,
|
|
25
|
+
ExpectedWriter,
|
|
26
|
+
MessageWriter,
|
|
27
|
+
ProblemWriter
|
|
28
|
+
} from "./shared/errors.js"
|
|
29
|
+
import type {
|
|
30
|
+
DescriptionWriter,
|
|
31
|
+
NodeKind,
|
|
32
|
+
TypeKind
|
|
33
|
+
} from "./shared/implement.js"
|
|
34
|
+
import type {
|
|
35
|
+
NormalizedUnionSchema,
|
|
36
|
+
UnionChildKind,
|
|
37
|
+
UnionNode
|
|
38
|
+
} from "./types/union.js"
|
|
39
|
+
import type { UnitNode } from "./types/unit.js"
|
|
40
|
+
export type nodeResolutions<keywords> = {
|
|
41
|
+
[k in keyof keywords]: TypeNode
|
|
42
|
+
}
|
|
43
|
+
export type BaseResolutions = Record<string, TypeNode>
|
|
44
|
+
declare global {
|
|
45
|
+
export interface StaticArkConfig {
|
|
46
|
+
preserve(): never
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
type nodeConfigForKind<kind extends NodeKind> = evaluate<
|
|
50
|
+
{
|
|
51
|
+
description?: DescriptionWriter<kind>
|
|
52
|
+
} & (kind extends ArkErrorCode
|
|
53
|
+
? {
|
|
54
|
+
expected?: ExpectedWriter<kind>
|
|
55
|
+
actual?: ActualWriter<kind>
|
|
56
|
+
problem?: ProblemWriter<kind>
|
|
57
|
+
message?: MessageWriter<kind>
|
|
58
|
+
}
|
|
59
|
+
: {})
|
|
60
|
+
>
|
|
61
|
+
type NodeConfigsByKind = {
|
|
62
|
+
[kind in NodeKind]: nodeConfigForKind<kind>
|
|
63
|
+
}
|
|
64
|
+
export type NodeConfig<kind extends NodeKind = NodeKind> =
|
|
65
|
+
NodeConfigsByKind[kind]
|
|
66
|
+
type UnknownNodeConfig = {
|
|
67
|
+
description?: DescriptionWriter
|
|
68
|
+
expected?: ExpectedWriter
|
|
69
|
+
actual?: ActualWriter
|
|
70
|
+
problem?: ProblemWriter
|
|
71
|
+
message?: MessageWriter
|
|
72
|
+
}
|
|
73
|
+
export type ParsedUnknownNodeConfig = requireKeys<
|
|
74
|
+
UnknownNodeConfig,
|
|
75
|
+
"description"
|
|
76
|
+
>
|
|
77
|
+
export type StaticArkOption<k extends keyof StaticArkConfig> = ReturnType<
|
|
78
|
+
StaticArkConfig[k]
|
|
79
|
+
>
|
|
80
|
+
export interface ArkConfig extends Partial<NodeConfigsByKind> {}
|
|
81
|
+
export type ParsedArkConfig = require<ArkConfig, 2>
|
|
82
|
+
export declare class ScopeNode<r extends object = any> {
|
|
83
|
+
def: Dict
|
|
84
|
+
infer: {
|
|
85
|
+
[k in keyof r]: r[k] extends schema.cast<infer t> ? t : never
|
|
86
|
+
}
|
|
87
|
+
static jsObjects: JsObjects.resolutions
|
|
88
|
+
static tsKeywords: TsKeywords.resolutions
|
|
89
|
+
readonly nodeCache: {
|
|
90
|
+
[innerId: string]: Node
|
|
91
|
+
}
|
|
92
|
+
readonly config: ParsedArkConfig
|
|
93
|
+
readonly resolutions: r
|
|
94
|
+
readonly referencesByName: {
|
|
95
|
+
[name: string]: Node
|
|
96
|
+
}
|
|
97
|
+
readonly references: readonly Node[]
|
|
98
|
+
protected resolved: boolean
|
|
99
|
+
protected prereducedAliases: boolean
|
|
100
|
+
readonly lengthBoundable: UnionNode<LengthBoundableData>
|
|
101
|
+
constructor(def: Dict, config?: ArkConfig)
|
|
102
|
+
get tsKeywords(): TsKeywords.resolutions
|
|
103
|
+
get jsObjects(): JsObjects.resolutions
|
|
104
|
+
static from<const aliases>(
|
|
105
|
+
aliases: validateAliases<aliases>,
|
|
106
|
+
config?: ArkConfig
|
|
107
|
+
): ScopeNode<instantiateAliases<aliases>>
|
|
108
|
+
static root: ScopeNode<{}>
|
|
109
|
+
parseUnion<const branches extends readonly Schema<UnionChildKind>[]>(
|
|
110
|
+
input: {
|
|
111
|
+
branches: {
|
|
112
|
+
[i in keyof branches]: validateSchemaBranch<branches[i], r>
|
|
113
|
+
}
|
|
114
|
+
} & NormalizedUnionSchema
|
|
115
|
+
): instantiateSchemaBranches<branches>
|
|
116
|
+
parseBranches<const branches extends readonly Schema<UnionChildKind>[]>(
|
|
117
|
+
...branches: {
|
|
118
|
+
[i in keyof branches]: validateSchemaBranch<branches[i], r>
|
|
119
|
+
}
|
|
120
|
+
): instantiateSchemaBranches<branches>
|
|
121
|
+
parseUnits<const branches extends List>(
|
|
122
|
+
...values: branches
|
|
123
|
+
): branches["length"] extends 1
|
|
124
|
+
? UnionNode<branches[0]>
|
|
125
|
+
: UnionNode<branches[number]> | UnitNode<branches[number]>
|
|
126
|
+
parseTypeNode<defKind extends TypeKind>(
|
|
127
|
+
schema: Schema<defKind>,
|
|
128
|
+
opts?: TypeSchemaParseOptions<defKind>
|
|
129
|
+
): Node<reducibleKindOf<defKind>>
|
|
130
|
+
parseRoot<kind extends NodeKind>(
|
|
131
|
+
kind: kind,
|
|
132
|
+
def: Schema<kind>,
|
|
133
|
+
opts?: SchemaParseOptions
|
|
134
|
+
): Node<reducibleKindOf<kind>>
|
|
135
|
+
parsePrereduced<kind extends NodeKind>(
|
|
136
|
+
kind: kind,
|
|
137
|
+
def: Schema<kind>
|
|
138
|
+
): Node<kind>
|
|
139
|
+
parse<kind extends NodeKind>(
|
|
140
|
+
kind: kind,
|
|
141
|
+
def: Schema<kind>,
|
|
142
|
+
opts?: SchemaParseOptions
|
|
143
|
+
): Node<reducibleKindOf<kind>>
|
|
144
|
+
protected bindCompiledScope(references: readonly Node[]): void
|
|
145
|
+
protected compileScope(references: readonly Node[]): {
|
|
146
|
+
[k: `${string}Allows`]: TraverseAllows
|
|
147
|
+
[k: `${string}Apply`]: TraverseApply
|
|
148
|
+
}
|
|
149
|
+
readonly schema: SchemaParser<r>
|
|
150
|
+
}
|
|
151
|
+
export type SchemaBranchesParser<$> = <
|
|
152
|
+
const branches extends readonly Schema<UnionChildKind>[]
|
|
153
|
+
>(
|
|
154
|
+
...branches: {
|
|
155
|
+
[i in keyof branches]: validateSchemaBranch<branches[i], $>
|
|
156
|
+
}
|
|
157
|
+
) => instantiateSchemaBranches<branches>
|
|
158
|
+
export type SchemaParser<$> = SchemaBranchesParser<$> & {
|
|
159
|
+
union<const branches extends readonly Schema<UnionChildKind>[]>(
|
|
160
|
+
input: {
|
|
161
|
+
branches: {
|
|
162
|
+
[i in keyof branches]: validateSchemaBranch<branches[i], $>
|
|
163
|
+
}
|
|
164
|
+
} & NormalizedUnionSchema
|
|
165
|
+
): instantiateSchemaBranches<branches>
|
|
166
|
+
units<const branches extends List>(
|
|
167
|
+
...values: branches
|
|
168
|
+
): branches["length"] extends 1
|
|
169
|
+
? UnionNode<branches[0]>
|
|
170
|
+
: UnionNode<branches[number]> | UnitNode<branches[number]>
|
|
171
|
+
}
|
|
172
|
+
export interface TypeSchemaParseOptions<allowedKind extends TypeKind = TypeKind>
|
|
173
|
+
extends SchemaParseOptions {
|
|
174
|
+
root?: boolean
|
|
175
|
+
allowedKinds?: readonly allowedKind[]
|
|
176
|
+
}
|
|
177
|
+
export declare const scopeNode: typeof ScopeNode.from
|
|
178
|
+
export declare const rootSchema: SchemaBranchesParser<{}>
|
|
179
|
+
export {}
|
|
180
|
+
//# sourceMappingURL=schemaScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaScope.d.ts","sourceRoot":"","sources":["../schemaScope.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,M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AW,sBAAsB,CAAC,WAAW,SAAS,QAAQ,GAAG,QAAQ,CAC9E,SAAQ,kBAAkB;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,YAAY,CAAC,EAAE,SAAS,WAAW,EAAE,CAAA;CACrC;AAED,eAAO,MAAM,SAAS,uBAAiB,CAAA;AAEvC,eAAO,MAAM,UAAU,EAAE,oBAAoB,CAAC,EAAE,CAOrC,CAAA"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CompiledFunction,
|
|
3
|
+
isArray,
|
|
4
|
+
printable,
|
|
5
|
+
throwInternalError,
|
|
6
|
+
throwParseError
|
|
7
|
+
} from "@arktype/util"
|
|
8
|
+
import { globalConfig } from "./config.js"
|
|
9
|
+
import { nodesByKind } from "./kinds.js"
|
|
10
|
+
import { parseAttachments } from "./parse.js"
|
|
11
|
+
import { NodeCompiler } from "./shared/compile.js"
|
|
12
|
+
import { discriminatingIntersectionKeys } from "./types/intersection.js"
|
|
13
|
+
import { BaseType } from "./types/type.js"
|
|
14
|
+
const parseConfig = (scopeConfig) => {
|
|
15
|
+
if (!scopeConfig) {
|
|
16
|
+
return globalConfig
|
|
17
|
+
}
|
|
18
|
+
const parsedConfig = { ...globalConfig }
|
|
19
|
+
let k
|
|
20
|
+
for (k in scopeConfig) {
|
|
21
|
+
if (k === "prereducedAliases") {
|
|
22
|
+
parsedConfig[k] = scopeConfig[k]
|
|
23
|
+
} else {
|
|
24
|
+
parsedConfig[k] = {
|
|
25
|
+
...nodesByKind[k].implementation.defaults,
|
|
26
|
+
...scopeConfig[k]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return parsedConfig
|
|
31
|
+
}
|
|
32
|
+
const assertTypeKind = (schema) => {
|
|
33
|
+
switch (typeof schema) {
|
|
34
|
+
case "string":
|
|
35
|
+
return "domain"
|
|
36
|
+
case "function":
|
|
37
|
+
return "proto"
|
|
38
|
+
case "object":
|
|
39
|
+
// throw at end of function
|
|
40
|
+
if (schema === null) break
|
|
41
|
+
if (schema instanceof BaseType) return schema.kind
|
|
42
|
+
if ("morph" in schema) return "morph"
|
|
43
|
+
if ("branches" in schema || isArray(schema)) return "union"
|
|
44
|
+
if ("unit" in schema) return "unit"
|
|
45
|
+
const schemaKeys = Object.keys(schema)
|
|
46
|
+
if (
|
|
47
|
+
schemaKeys.length === 0 ||
|
|
48
|
+
schemaKeys.some((k) => k in discriminatingIntersectionKeys)
|
|
49
|
+
)
|
|
50
|
+
return "intersection"
|
|
51
|
+
if ("proto" in schema) return "proto"
|
|
52
|
+
if ("domain" in schema) return "domain"
|
|
53
|
+
}
|
|
54
|
+
return throwParseError(`${printable(schema)} is not a valid type schema`)
|
|
55
|
+
}
|
|
56
|
+
export class ScopeNode {
|
|
57
|
+
def
|
|
58
|
+
nodeCache = {}
|
|
59
|
+
config
|
|
60
|
+
resolutions = {}
|
|
61
|
+
referencesByName = {}
|
|
62
|
+
references
|
|
63
|
+
resolved = false
|
|
64
|
+
prereducedAliases
|
|
65
|
+
lengthBoundable
|
|
66
|
+
constructor(def, config = {}) {
|
|
67
|
+
this.def = def
|
|
68
|
+
this.config = parseConfig(config)
|
|
69
|
+
this.prereducedAliases = config.prereducedAliases ?? false
|
|
70
|
+
for (const k in this.def) {
|
|
71
|
+
this.resolutions[k] = this.parseRoot(
|
|
72
|
+
assertTypeKind(this.def[k]),
|
|
73
|
+
this.def[k],
|
|
74
|
+
{
|
|
75
|
+
alias: k,
|
|
76
|
+
prereduced: this.prereducedAliases
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
this.references = Object.values(this.referencesByName)
|
|
81
|
+
this.bindCompiledScope(this.references)
|
|
82
|
+
this.resolved = true
|
|
83
|
+
this.parse(
|
|
84
|
+
"union",
|
|
85
|
+
{
|
|
86
|
+
branches: [
|
|
87
|
+
"string",
|
|
88
|
+
"number",
|
|
89
|
+
"object",
|
|
90
|
+
"bigint",
|
|
91
|
+
"symbol",
|
|
92
|
+
{ unit: true },
|
|
93
|
+
{ unit: false },
|
|
94
|
+
{ unit: null },
|
|
95
|
+
{ unit: undefined }
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{ reduceTo: this.parsePrereduced("intersection", {}) }
|
|
99
|
+
)
|
|
100
|
+
this.lengthBoundable = this.parsePrereduced("union", ["string", Array])
|
|
101
|
+
}
|
|
102
|
+
get tsKeywords() {
|
|
103
|
+
return ScopeNode.tsKeywords
|
|
104
|
+
}
|
|
105
|
+
get jsObjects() {
|
|
106
|
+
return ScopeNode.jsObjects
|
|
107
|
+
}
|
|
108
|
+
static from(aliases, config = {}) {
|
|
109
|
+
return new ScopeNode(aliases, config)
|
|
110
|
+
}
|
|
111
|
+
static root = this.from({})
|
|
112
|
+
parseUnion(input) {
|
|
113
|
+
return this.parseRoot("union", input)
|
|
114
|
+
}
|
|
115
|
+
parseBranches(...branches) {
|
|
116
|
+
return branches.length === 1
|
|
117
|
+
? this.parseTypeNode(branches[0], { root: true })
|
|
118
|
+
: this.parseRoot("union", branches)
|
|
119
|
+
}
|
|
120
|
+
parseUnits(...values) {
|
|
121
|
+
const uniqueValues = []
|
|
122
|
+
for (const value of values) {
|
|
123
|
+
if (!uniqueValues.includes(value)) {
|
|
124
|
+
uniqueValues.push(value)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const branches = uniqueValues.map((unit) =>
|
|
128
|
+
this.parsePrereduced("unit", { unit })
|
|
129
|
+
)
|
|
130
|
+
if (branches.length === 1) {
|
|
131
|
+
return branches[0]
|
|
132
|
+
}
|
|
133
|
+
return this.parseRoot("union", {
|
|
134
|
+
branches
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
parseTypeNode(schema, opts = {}) {
|
|
138
|
+
const kind = assertTypeKind(schema)
|
|
139
|
+
if (opts.allowedKinds && !opts.allowedKinds.includes(kind)) {
|
|
140
|
+
return throwParseError(
|
|
141
|
+
`Schema of kind ${kind} should be one of ${opts.allowedKinds}`
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
return opts.root
|
|
145
|
+
? this.parseRoot(kind, schema, opts)
|
|
146
|
+
: this.parse(kind, schema, opts)
|
|
147
|
+
}
|
|
148
|
+
parseRoot(kind, def, opts = {}) {
|
|
149
|
+
const node = this.parse(kind, def, opts)
|
|
150
|
+
if (this.resolved) {
|
|
151
|
+
// this node was not part of the original scope, so compile an anonymous scope
|
|
152
|
+
// including only its references
|
|
153
|
+
this.bindCompiledScope(node.contributesReferences)
|
|
154
|
+
} else {
|
|
155
|
+
// we're still parsing the scope itself, so defer compilation but
|
|
156
|
+
// add the node as a reference
|
|
157
|
+
Object.assign(
|
|
158
|
+
this.referencesByName,
|
|
159
|
+
node.contributesReferencesByName
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
return node
|
|
163
|
+
}
|
|
164
|
+
parsePrereduced(kind, def) {
|
|
165
|
+
return this.parse(kind, def, { prereduced: true })
|
|
166
|
+
}
|
|
167
|
+
parse(kind, def, opts = {}) {
|
|
168
|
+
if (opts.alias && opts.alias in this.resolutions) {
|
|
169
|
+
return throwInternalError(
|
|
170
|
+
`Unexpected attempt to recreate existing alias ${opts.alias}`
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
const node = parseAttachments(kind, def, {
|
|
174
|
+
...opts,
|
|
175
|
+
$: this,
|
|
176
|
+
definition: def,
|
|
177
|
+
prereduced: opts.prereduced ?? false
|
|
178
|
+
})
|
|
179
|
+
return node
|
|
180
|
+
}
|
|
181
|
+
bindCompiledScope(references) {
|
|
182
|
+
const compiledTraversals = this.compileScope(references)
|
|
183
|
+
for (const node of references) {
|
|
184
|
+
if (node.jit) {
|
|
185
|
+
// if node has already been bound to another scope or anonymous type, don't rebind it
|
|
186
|
+
continue
|
|
187
|
+
}
|
|
188
|
+
node.jit = true
|
|
189
|
+
node.traverseAllows =
|
|
190
|
+
compiledTraversals[`${node.name}Allows`].bind(
|
|
191
|
+
compiledTraversals
|
|
192
|
+
)
|
|
193
|
+
if (node.isType() && !node.includesContextDependentPredicate) {
|
|
194
|
+
// if the reference doesn't require context, we can assign over
|
|
195
|
+
// it directly to avoid having to initialize it
|
|
196
|
+
node.allows = node.traverseAllows
|
|
197
|
+
}
|
|
198
|
+
node.traverseApply =
|
|
199
|
+
compiledTraversals[`${node.name}Apply`].bind(compiledTraversals)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
compileScope(references) {
|
|
203
|
+
return new CompiledFunction()
|
|
204
|
+
.block(`return`, (js) => {
|
|
205
|
+
references.forEach((node) => {
|
|
206
|
+
const allowsCompiler = new NodeCompiler("Allows").indent()
|
|
207
|
+
node.compile(allowsCompiler)
|
|
208
|
+
const applyCompiler = new NodeCompiler("Apply").indent()
|
|
209
|
+
node.compile(applyCompiler)
|
|
210
|
+
js.line(
|
|
211
|
+
allowsCompiler.writeMethod(`${node.name}Allows`) +
|
|
212
|
+
",\n" +
|
|
213
|
+
applyCompiler.writeMethod(`${node.name}Apply`) +
|
|
214
|
+
","
|
|
215
|
+
)
|
|
216
|
+
})
|
|
217
|
+
return js
|
|
218
|
+
})
|
|
219
|
+
.compile()()
|
|
220
|
+
}
|
|
221
|
+
schema = Object.assign(this.parseBranches.bind(this), {
|
|
222
|
+
units: this.parseUnits.bind(this),
|
|
223
|
+
union: this.parseUnion.bind(this)
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
export const scopeNode = ScopeNode.from
|
|
227
|
+
export const rootSchema = (...branches) =>
|
|
228
|
+
ScopeNode.root.parseTypeNode(
|
|
229
|
+
branches.length === 1 ? branches[0] : branches,
|
|
230
|
+
{
|
|
231
|
+
root: true,
|
|
232
|
+
prereduced: true
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
//# sourceMappingURL=schemaScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaScope.js","sourceRoot":"","sources":["../schemaScope.ts"],"names":[],"mappings":"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AA;gBACxD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;gBAC3B,EAAE,CAAC,IAAI,CACN,cAAc,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,IAAI,QAAQ,CAAC;oBAC/C,KAAK;oBACL,aAAa,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,IAAI,OAAO,CAAC;oBAC9C,GAAG,CACJ,CAAA;YACF,CAAC,CAAC,CAAA;YACF,OAAO,EAAE,CAAA;QACV,CAAC,CAAC;aACD,OAAO,EAAE,EAAW,CAAA;IACvB,CAAC;IAEQ,MAAM,GAAoB,MAAM,CAAC,MAAM,CAC/C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAC7B;QACC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QACjC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;KACjC,CACQ,CAAA;;AAiCX,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAA;AAEvC,MAAM,CAAC,MAAM,UAAU,GAA6B,CAAC,GAAG,QAAQ,EAAE,EAAE,CACnE,SAAS,CAAC,IAAI,CAAC,aAAa,CAC3B,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,QAAgB,EACvD;IACC,IAAI,EAAE,IAAI;IACV,UAAU,EAAE,IAAI;CAChB,CACQ,CAAA"}
|
package/out/scope.d.ts
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
import { type ArkConfig, type
|
|
2
|
-
import { type
|
|
1
|
+
import { type ArkConfig, type GenericProps, type NodeParseOptions, type PreparsedNodeResolution, type RawSchema, type RawSchemaResolutions, RawSchemaScope, type SchemaScope, type ambient, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf } from "@arktype/schema";
|
|
2
|
+
import { type nominal, type show } from "@arktype/util";
|
|
3
3
|
import type { type } from "./ark.js";
|
|
4
|
+
import { Generic } from "./generic.js";
|
|
4
5
|
import { type MatchParser } from "./match.js";
|
|
6
|
+
import type { Module } from "./module.js";
|
|
5
7
|
import { type inferDefinition, type validateDefinition } from "./parser/definition.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports: inferBootstrapped<{
|
|
12
|
-
exports: bootstrapExports<def>;
|
|
13
|
-
locals: bootstrapLocals<def> & parent;
|
|
14
|
-
ambient: ambient;
|
|
15
|
-
}>;
|
|
16
|
-
locals: inferBootstrapped<{
|
|
17
|
-
exports: bootstrapLocals<def>;
|
|
18
|
-
locals: bootstrapExports<def> & parent;
|
|
19
|
-
ambient: ambient;
|
|
20
|
-
}>;
|
|
21
|
-
ambient: ambient;
|
|
22
|
-
}>;
|
|
23
|
-
};
|
|
24
|
-
export interface ArkScopeConfig extends ArkConfig {
|
|
25
|
-
ambient?: Scope | null;
|
|
26
|
-
}
|
|
27
|
-
type validateScope<def, $> = {
|
|
28
|
-
[k in keyof def]: parseScopeKey<k>["params"] extends [] ? def[k] extends Type | PreparsedResolution ? def[k] : validateDefinition<def[k], $ & bootstrap<def>, {}> : parseScopeKey<k>["params"] extends GenericParamsParseError ? parseScopeKey<k>["params"][0] : validateDefinition<def[k], $ & bootstrap<def>, {
|
|
8
|
+
import { type GenericDeclaration, type GenericParamsParseError, parseGenericParams } from "./parser/generic.js";
|
|
9
|
+
import type { DeclarationParser, DefinitionParser, Type, TypeParser } from "./type.js";
|
|
10
|
+
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkConfig) => Scope<inferBootstrapped<bootstrapAliases<def>>>;
|
|
11
|
+
type validateScope<def> = {
|
|
12
|
+
[k in keyof def]: k extends symbol ? unknown : parseScopeKey<k>["params"] extends [] ? def[k] extends Type | PreparsedResolution ? def[k] : validateDefinition<def[k], ambient & bootstrapAliases<def>, {}> : parseScopeKey<k>["params"] extends GenericParamsParseError ? parseScopeKey<k>["params"][0] : validateDefinition<def[k], ambient & bootstrapAliases<def>, {
|
|
29
13
|
[param in parseScopeKey<k>["params"][number]]: unknown;
|
|
30
14
|
}>;
|
|
31
15
|
};
|
|
@@ -36,117 +20,61 @@ export type bindThis<def> = {
|
|
|
36
20
|
type Def<def = {}> = nominal<def, "unparsed">;
|
|
37
21
|
/** sentinel indicating a scope that will be associated with a generic has not yet been parsed */
|
|
38
22
|
export type UnparsedScope = "$";
|
|
39
|
-
type bootstrap<def> = bootstrapLocals<def> & bootstrapExports<def>;
|
|
40
|
-
type bootstrapLocals<def> = bootstrapAliases<{
|
|
41
|
-
[k in keyof def & PrivateDeclaration as extractPrivateKey<k>]: def[k];
|
|
42
|
-
}>;
|
|
43
|
-
type bootstrapExports<def> = bootstrapAliases<{
|
|
44
|
-
[k in Exclude<keyof def, PrivateDeclaration>]: def[k];
|
|
45
|
-
}>;
|
|
46
23
|
/** These are legal as values of a scope but not as definitions in other contexts */
|
|
47
|
-
type PreparsedResolution =
|
|
24
|
+
type PreparsedResolution = PreparsedNodeResolution;
|
|
48
25
|
type bootstrapAliases<def> = {
|
|
49
26
|
[k in Exclude<keyof def, GenericDeclaration | symbol>]: def[k] extends PreparsedResolution ? def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn : Def<def[k]>;
|
|
50
27
|
} & {
|
|
51
|
-
[k in keyof def & GenericDeclaration as extractGenericName<k>]:
|
|
28
|
+
[k in keyof def & GenericDeclaration as extractGenericName<k>]: GenericProps<parseGenericParams<extractGenericParameters<k>>, def[k], UnparsedScope>;
|
|
52
29
|
};
|
|
53
|
-
type inferBootstrapped
|
|
54
|
-
[name in keyof
|
|
30
|
+
type inferBootstrapped<$> = show<{
|
|
31
|
+
[name in keyof $]: $[name] extends Def<infer def> ? inferDefinition<def, $ & ambient, {}> : $[name] extends GenericProps<infer params, infer def> ? Generic<params, def, $> : $[name];
|
|
55
32
|
}>;
|
|
56
33
|
type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
|
|
57
34
|
type extractGenericParameters<k> = k extends GenericDeclaration<string, infer params> ? params : never;
|
|
58
|
-
type
|
|
59
|
-
type PrivateDeclaration<key extends string = string> = `#${key}`;
|
|
60
|
-
export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ? [resolution] extends [never] ? never : isAny<resolution> extends true ? any : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution : never;
|
|
35
|
+
export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ? resolution extends Def<infer def> ? def extends null ? resolution : inferDefinition<def, $, args> : resolution : never;
|
|
61
36
|
export type moduleKeyOf<$> = {
|
|
62
|
-
[k in keyof $]: $[k] extends
|
|
37
|
+
[k in keyof $]: $[k] extends {
|
|
38
|
+
[arkKind]: "module";
|
|
39
|
+
} ? k & string : never;
|
|
63
40
|
}[keyof $];
|
|
64
|
-
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] extends
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
scope: Scope;
|
|
79
|
-
args: Record<string, TypeNode> | undefined;
|
|
80
|
-
};
|
|
81
|
-
type ParseContextInput = Pick<ParseContext, "baseName" | "args">;
|
|
82
|
-
export declare class Scope<r extends Resolutions = any> {
|
|
83
|
-
infer: extractOut<r["exports"]>;
|
|
84
|
-
inferIn: extractIn<r["exports"]>;
|
|
85
|
-
config: ArkScopeConfig;
|
|
41
|
+
export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] extends type.cast<infer t> ? t : never : never : never;
|
|
42
|
+
export interface ParseContext extends NodeParseOptions {
|
|
43
|
+
$: RawScope;
|
|
44
|
+
}
|
|
45
|
+
export declare const scope: ScopeParser;
|
|
46
|
+
export interface Scope<$ = any> extends SchemaScope<$> {
|
|
47
|
+
type: TypeParser<$>;
|
|
48
|
+
match: MatchParser<$>;
|
|
49
|
+
declare: DeclarationParser<$>;
|
|
50
|
+
define: DefinitionParser<$>;
|
|
51
|
+
import<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredImportContext<$, names>>>;
|
|
52
|
+
export<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredExportContext<$, names>>>;
|
|
53
|
+
}
|
|
54
|
+
export declare class RawScope<$ extends RawSchemaResolutions = RawSchemaResolutions> extends RawSchemaScope<$> {
|
|
86
55
|
private parseCache;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
private ambient;
|
|
93
|
-
constructor(def: Dict, config: ArkScopeConfig);
|
|
94
|
-
static root: ScopeParser<{}, {}>;
|
|
95
|
-
type: TypeParser<$<r>>;
|
|
96
|
-
match: MatchParser<$<r>>;
|
|
97
|
-
declare: DeclarationParser<$<r>>;
|
|
98
|
-
scope: ScopeParser<r["exports"], r["ambient"]>;
|
|
99
|
-
define: DefinitionParser<$<r>>;
|
|
100
|
-
toAmbient(): Scope<{
|
|
101
|
-
exports: r["exports"];
|
|
102
|
-
locals: r["locals"];
|
|
103
|
-
ambient: r["exports"];
|
|
104
|
-
}>;
|
|
105
|
-
get<name extends keyof r["exports"] & string>(name: name): Type<r["exports"][name], $<r>>;
|
|
106
|
-
private createRootContext;
|
|
107
|
-
parseDefinition(def: unknown, input: ParseContextInput): TypeNode;
|
|
108
|
-
parse(def: unknown, ctx: ParseContext): TypeNode;
|
|
109
|
-
parseString(def: string, ctx: ParseContext): TypeNode;
|
|
110
|
-
maybeResolve(name: string): TypeNode | Generic | undefined;
|
|
111
|
-
/** If name is a valid reference to a submodule alias, return its resolution */
|
|
112
|
-
private maybeResolveSubalias;
|
|
113
|
-
maybeResolveNode(name: string): TypeNode | undefined;
|
|
114
|
-
import<names extends exportedName<r>[]>(...names: names): destructuredImportContext<r, names extends [] ? keyof r["exports"] & string : names[number]>;
|
|
115
|
-
bindThis(): {
|
|
116
|
-
this: import("@arktype/schema").IntersectionNode<unknown>;
|
|
56
|
+
constructor(def: Record<string, unknown>, config?: ArkConfig);
|
|
57
|
+
type(...args: unknown[]): RawSchema | Generic;
|
|
58
|
+
match: MatchParser<$>;
|
|
59
|
+
declare(): {
|
|
60
|
+
type: RawScope["type"];
|
|
117
61
|
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
62
|
+
define(def: unknown): unknown;
|
|
63
|
+
preparseRoot(def: unknown): unknown;
|
|
64
|
+
parseRoot(def: unknown, opts?: NodeParseOptions): RawSchema;
|
|
65
|
+
parse(def: unknown, ctx: ParseContext): RawSchema;
|
|
66
|
+
parseString(def: string, ctx: ParseContext): RawSchema;
|
|
121
67
|
}
|
|
122
|
-
type destructuredExportContext<r extends Resolutions, name extends exportedName<r>> = {
|
|
123
|
-
exports: {
|
|
124
|
-
[k in name]: r["exports"][k];
|
|
125
|
-
};
|
|
126
|
-
locals: r["locals"] & {
|
|
127
|
-
[k in Exclude<keyof r["exports"], name>]: r["exports"][k];
|
|
128
|
-
};
|
|
129
|
-
ambient: r["ambient"];
|
|
130
|
-
};
|
|
131
|
-
type destructuredImportContext<r extends Resolutions, name extends exportedName<r>> = {
|
|
132
|
-
[k in name as `#${k & string}`]: type.cast<r["exports"][k]>;
|
|
133
|
-
};
|
|
134
68
|
export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
|
|
135
|
-
export declare const writeDuplicateNameMessage: <name extends string>(name: name) => `Duplicate name '${name}'`;
|
|
136
|
-
type writeDuplicateNameMessage<name extends string> = `Duplicate name '${name}'`;
|
|
137
69
|
export type ParsedScopeKey = {
|
|
138
|
-
isLocal: boolean;
|
|
139
70
|
name: string;
|
|
140
71
|
params: string[];
|
|
141
72
|
};
|
|
142
73
|
export declare const parseScopeKey: (k: string) => ParsedScopeKey;
|
|
143
|
-
type parseScopeKey<k> = k extends
|
|
144
|
-
type parsePossibleGenericDeclaration<k, isLocal extends boolean> = k extends GenericDeclaration<infer name, infer paramString> ? {
|
|
145
|
-
isLocal: isLocal;
|
|
74
|
+
export type parseScopeKey<k> = k extends GenericDeclaration<infer name, infer paramString> ? {
|
|
146
75
|
name: name;
|
|
147
76
|
params: parseGenericParams<paramString>;
|
|
148
77
|
} : {
|
|
149
|
-
isLocal: isLocal;
|
|
150
78
|
name: k;
|
|
151
79
|
params: [];
|
|
152
80
|
};
|