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
package/out/scope.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EAEnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAK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,OAAO,EAAE,GAAG,SAAS,GAAG,OAAO;IAwB7C,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAA4C;IAEjE,OAAO,IAAI;QAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;KAAE;IAIrC,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO;IAIpB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO;IAOnC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,SAAS;IAQpE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,GAAG,SAAS;IAiBjD,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,SAAS;CAQtD;AAED,eAAO,MAAM,6BAA6B,SACnC,MAAM,QACN,MAAM,EAAE,KACZ,MAC4E,CAAA;AAE/E,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,EAAE,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,aAAa,MAAO,MAAM,KAAG,cAiBzC,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,IAC1B,CAAC,SAAS,kBAAkB,CAAC,MAAM,IAAI,EAAE,MAAM,WAAW,CAAC,GAC1D;IACC,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAA;CACvC,GACA;IACA,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,EAAE,CAAA;CACV,CAAA"}
|
package/out/scope.js
CHANGED
|
@@ -1,82 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { domainOf, hasDomain, isThunk,
|
|
1
|
+
import { RawSchemaScope, hasArkKind } from "@arktype/schema";
|
|
2
|
+
import { domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
|
|
3
|
+
import { Generic } from "./generic.js";
|
|
3
4
|
import { createMatchParser } from "./match.js";
|
|
4
5
|
import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
|
|
5
6
|
import { parseGenericParams } from "./parser/generic.js";
|
|
6
7
|
import { DynamicState } from "./parser/string/reduce/dynamic.js";
|
|
7
|
-
import { writeMissingSubmoduleAccessMessage, writeNonSubmoduleDotMessage, writeUnresolvableMessage } from "./parser/string/shift/operand/unenclosed.js";
|
|
8
8
|
import { fullStringParse } from "./parser/string/string.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export class Scope {
|
|
12
|
-
config;
|
|
9
|
+
export const scope = ((def, config = {}) => new RawScope(def, config));
|
|
10
|
+
export class RawScope extends RawSchemaScope {
|
|
13
11
|
parseCache = {};
|
|
14
|
-
resolutions;
|
|
15
|
-
/** The set of names defined at the root-level of the scope mapped to their
|
|
16
|
-
* corresponding definitions.**/
|
|
17
|
-
aliases = {};
|
|
18
|
-
exportedNames = [];
|
|
19
|
-
ambient;
|
|
20
12
|
constructor(def, config) {
|
|
13
|
+
const aliases = {};
|
|
21
14
|
for (const k in def) {
|
|
22
15
|
const parsedKey = parseScopeKey(k);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
16
|
+
aliases[parsedKey.name] =
|
|
17
|
+
parsedKey.params.length ?
|
|
18
|
+
// TODO: this
|
|
19
|
+
new Generic(parsedKey.params, def[k], {})
|
|
20
|
+
: def[k];
|
|
29
21
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
super(aliases, config);
|
|
23
|
+
}
|
|
24
|
+
type(...args) {
|
|
25
|
+
if (args.length === 1) {
|
|
26
|
+
// treat as a simple definition
|
|
27
|
+
return this.parseRoot(args[0]);
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
if (args.length === 2 &&
|
|
30
|
+
typeof args[0] === "string" &&
|
|
31
|
+
args[0][0] === "<" &&
|
|
32
|
+
args[0].at(-1) === ">") {
|
|
33
|
+
// if there are exactly two args, the first of which looks like <${string}>,
|
|
34
|
+
// treat as a generic
|
|
35
|
+
const params = parseGenericParams(args[0].slice(1, -1));
|
|
36
|
+
const def = args[1];
|
|
37
|
+
// TODO: validateUninstantiatedGeneric, remove this cast
|
|
38
|
+
return new Generic(params, def, this);
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
// otherwise, treat as a tuple expression. technically, this also allows
|
|
41
|
+
// non-expression tuple definitions to be parsed, but it's not a supported
|
|
42
|
+
// part of the API as specified by the associated types
|
|
43
|
+
return this.parseRoot(args);
|
|
40
44
|
}
|
|
41
|
-
static root = (aliases) => {
|
|
42
|
-
return new Scope(aliases, {});
|
|
43
|
-
};
|
|
44
|
-
type = createTypeParser(this);
|
|
45
45
|
match = createMatchParser(this);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
scope = ((def, config = {}) => {
|
|
49
|
-
return new Scope(def, {
|
|
50
|
-
ambient: this.ambient,
|
|
51
|
-
...this.config,
|
|
52
|
-
...config
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
define = (def) => def;
|
|
56
|
-
toAmbient() {
|
|
57
|
-
// TODO: private?
|
|
58
|
-
return new Scope(this.aliases, {
|
|
59
|
-
ambient: this,
|
|
60
|
-
...this.config
|
|
61
|
-
});
|
|
46
|
+
declare() {
|
|
47
|
+
return { type: this.type.bind(this) };
|
|
62
48
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return this.export()[name];
|
|
49
|
+
define(def) {
|
|
50
|
+
return def;
|
|
66
51
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
52
|
+
preparseRoot(def) {
|
|
53
|
+
if (isThunk(def) && !hasArkKind(def, "generic")) {
|
|
54
|
+
return def();
|
|
55
|
+
}
|
|
56
|
+
return def;
|
|
73
57
|
}
|
|
74
|
-
|
|
75
|
-
return this.parse(def,
|
|
58
|
+
parseRoot(def, opts) {
|
|
59
|
+
return this.parse(def, {
|
|
60
|
+
args: { this: {} },
|
|
61
|
+
$: this,
|
|
62
|
+
...opts
|
|
63
|
+
}).bindScope(this);
|
|
76
64
|
}
|
|
77
65
|
parse(def, ctx) {
|
|
78
66
|
if (typeof def === "string") {
|
|
79
|
-
if (ctx.args
|
|
67
|
+
if (ctx.args && Object.keys(ctx.args).every((k) => !def.includes(k))) {
|
|
80
68
|
// we can only rely on the cache if there are no contextual
|
|
81
69
|
// resolutions like "this" or generic args
|
|
82
70
|
return this.parseString(def, ctx);
|
|
@@ -86,8 +74,8 @@ export class Scope {
|
|
|
86
74
|
}
|
|
87
75
|
return this.parseCache[def];
|
|
88
76
|
}
|
|
89
|
-
return hasDomain(def, "object")
|
|
90
|
-
|
|
77
|
+
return hasDomain(def, "object") ?
|
|
78
|
+
parseObject(def, ctx)
|
|
91
79
|
: throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
|
|
92
80
|
}
|
|
93
81
|
parseString(def, ctx) {
|
|
@@ -96,130 +84,13 @@ export class Scope {
|
|
|
96
84
|
this.maybeResolveNode(def.slice(0, -2))?.array()) ||
|
|
97
85
|
fullStringParse(new DynamicState(def, ctx))));
|
|
98
86
|
}
|
|
99
|
-
maybeResolve(name) {
|
|
100
|
-
const cached = this.resolutions[name];
|
|
101
|
-
if (cached) {
|
|
102
|
-
return cached;
|
|
103
|
-
}
|
|
104
|
-
let def = this.aliases[name];
|
|
105
|
-
if (!def) {
|
|
106
|
-
return this.maybeResolveSubalias(name);
|
|
107
|
-
}
|
|
108
|
-
if (isThunk(def) && !hasArkKind(def, "generic")) {
|
|
109
|
-
def = def();
|
|
110
|
-
}
|
|
111
|
-
// TODO: initialize here?
|
|
112
|
-
const resolution = hasArkKind(def, "generic")
|
|
113
|
-
? validateUninstantiatedGeneric(def)
|
|
114
|
-
: hasArkKind(def, "module")
|
|
115
|
-
? throwParseError(writeMissingSubmoduleAccessMessage(name))
|
|
116
|
-
: this.parseDefinition(def, this.createRootContext({ baseName: name, args: {} }));
|
|
117
|
-
this.resolutions[name] = resolution;
|
|
118
|
-
return resolution;
|
|
119
|
-
}
|
|
120
|
-
/** If name is a valid reference to a submodule alias, return its resolution */
|
|
121
|
-
maybeResolveSubalias(name) {
|
|
122
|
-
const dotIndex = name.indexOf(".");
|
|
123
|
-
if (dotIndex === -1) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const dotPrefix = name.slice(0, dotIndex);
|
|
127
|
-
const prefixDef = this.aliases[dotPrefix];
|
|
128
|
-
if (hasArkKind(prefixDef, "module")) {
|
|
129
|
-
const resolution = prefixDef[name.slice(dotIndex + 1)]?.root;
|
|
130
|
-
// if the first part of name is a submodule but the suffix is
|
|
131
|
-
// unresolvable, we can throw immediately
|
|
132
|
-
if (!resolution) {
|
|
133
|
-
return throwParseError(writeUnresolvableMessage(name));
|
|
134
|
-
}
|
|
135
|
-
this.resolutions[name] = resolution;
|
|
136
|
-
return resolution;
|
|
137
|
-
}
|
|
138
|
-
if (prefixDef !== undefined) {
|
|
139
|
-
return throwParseError(writeNonSubmoduleDotMessage(dotPrefix));
|
|
140
|
-
}
|
|
141
|
-
// if the name includes ".", but the prefix is not an alias, it
|
|
142
|
-
// might be something like a decimal literal, so just fall through to return
|
|
143
|
-
}
|
|
144
|
-
maybeResolveNode(name) {
|
|
145
|
-
const result = this.maybeResolve(name);
|
|
146
|
-
return result instanceof BaseType ? result : undefined;
|
|
147
|
-
}
|
|
148
|
-
import(...names) {
|
|
149
|
-
return addArkKind(morph(this.export(...names), (alias, value) => [
|
|
150
|
-
`#${alias}`,
|
|
151
|
-
value
|
|
152
|
-
]), "module");
|
|
153
|
-
}
|
|
154
|
-
bindThis() {
|
|
155
|
-
// TODO: fix
|
|
156
|
-
return { this: keywords.unknown };
|
|
157
|
-
}
|
|
158
|
-
exportedResolutions;
|
|
159
|
-
exportCache;
|
|
160
|
-
export(...names) {
|
|
161
|
-
if (!this.exportCache) {
|
|
162
|
-
this.exportCache = {};
|
|
163
|
-
for (const name of this.exportedNames) {
|
|
164
|
-
let def = this.aliases[name];
|
|
165
|
-
if (hasArkKind(def, "generic")) {
|
|
166
|
-
this.exportCache[name] = def;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
// TODO: thunk generics?
|
|
170
|
-
// handle generics before invoking thunks, since they use
|
|
171
|
-
// varargs they will incorrectly be considered thunks
|
|
172
|
-
if (isThunk(def)) {
|
|
173
|
-
def = def();
|
|
174
|
-
}
|
|
175
|
-
if (hasArkKind(def, "module")) {
|
|
176
|
-
this.exportCache[name] = def;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.exportCache[name] = new Type(this.maybeResolve(name), this);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
this.exportedResolutions = resolutionsOfModule(this.exportCache);
|
|
183
|
-
Object.assign(this.resolutions, this.exportedResolutions);
|
|
184
|
-
}
|
|
185
|
-
const namesToExport = names.length ? names : this.exportedNames;
|
|
186
|
-
return addArkKind(morph(namesToExport, (_, name) => [
|
|
187
|
-
name,
|
|
188
|
-
this.exportCache[name]
|
|
189
|
-
]), "module");
|
|
190
|
-
}
|
|
191
87
|
}
|
|
192
|
-
const resolutionsOfModule = (typeSet) => {
|
|
193
|
-
const result = {};
|
|
194
|
-
for (const k in typeSet) {
|
|
195
|
-
const v = typeSet[k];
|
|
196
|
-
if (hasArkKind(v, "module")) {
|
|
197
|
-
const innerResolutions = resolutionsOfModule(v);
|
|
198
|
-
const prefixedResolutions = morph(innerResolutions, (innerK, innerV) => [
|
|
199
|
-
`${k}.${innerK}`,
|
|
200
|
-
innerV
|
|
201
|
-
]);
|
|
202
|
-
Object.assign(result, prefixedResolutions);
|
|
203
|
-
}
|
|
204
|
-
else if (hasArkKind(v, "generic")) {
|
|
205
|
-
result[k] = v;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
result[k] = v.root;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return result;
|
|
212
|
-
};
|
|
213
88
|
export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
|
|
214
|
-
export const writeDuplicateNameMessage = (name) => `Duplicate name '${name}'`;
|
|
215
89
|
export const parseScopeKey = (k) => {
|
|
216
|
-
const isLocal = k[0] === "#";
|
|
217
|
-
const name = isLocal ? k.slice(1) : k;
|
|
218
90
|
const firstParamIndex = k.indexOf("<");
|
|
219
91
|
if (firstParamIndex === -1) {
|
|
220
92
|
return {
|
|
221
|
-
|
|
222
|
-
name,
|
|
93
|
+
name: k,
|
|
223
94
|
params: []
|
|
224
95
|
};
|
|
225
96
|
}
|
|
@@ -227,8 +98,7 @@ export const parseScopeKey = (k) => {
|
|
|
227
98
|
throwParseError(`'>' must be the last character of a generic declaration in a scope`);
|
|
228
99
|
}
|
|
229
100
|
return {
|
|
230
|
-
|
|
231
|
-
name: name.slice(0, firstParamIndex),
|
|
101
|
+
name: k.slice(0, firstParamIndex),
|
|
232
102
|
params: parseGenericParams(k.slice(firstParamIndex + 1, -1))
|
|
233
103
|
};
|
|
234
104
|
};
|
package/out/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,cAAc,EAOd,UAAU,EACV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEN,QAAQ,EACR,SAAS,EACT,OAAO,EAGP,eAAe,EACf,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAoB,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEhE,OAAO,EAEN,WAAW,EAEX,6B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AI,qCAAqC,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;AAO/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAkB,EAAE;IAC1D,MAAM,eAAe,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACtC,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;QAC5B,OAAO;YACN,IAAI,EAAE,CAAC;YACP,MAAM,EAAE,EAAE;SACV,CAAA;IACF,CAAC;IACD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACtB,eAAe,CACd,oEAAoE,CACpE,CAAA;IACF,CAAC;IACD,OAAO;QACN,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC;QACjC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC5D,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CompiledFunction } from "@arktype/util"
|
|
2
|
+
import type { Node, UnknownNode } from "../base.js"
|
|
3
|
+
import type { Discriminant } from "../types/discriminate.js"
|
|
4
|
+
import type { PrimitiveKind } from "./implement.js"
|
|
5
|
+
import type { TraversalKind } from "./traversal.js"
|
|
6
|
+
export type InvokeOptions = {
|
|
7
|
+
arg?: string
|
|
8
|
+
kind?: TraversalKind
|
|
9
|
+
}
|
|
10
|
+
export declare class NodeCompiler extends CompiledFunction<["data", "ctx"]> {
|
|
11
|
+
traversalKind: TraversalKind
|
|
12
|
+
path: string[]
|
|
13
|
+
discriminants: Discriminant[]
|
|
14
|
+
constructor(traversalKind: TraversalKind)
|
|
15
|
+
invoke(node: UnknownNode, opts?: InvokeOptions): string
|
|
16
|
+
requiresContextFor(node: UnknownNode): boolean
|
|
17
|
+
checkReferenceKey(keyExpression: string, node: UnknownNode): this
|
|
18
|
+
check(node: UnknownNode, opts?: InvokeOptions): this
|
|
19
|
+
compilePrimitive(node: Node<PrimitiveKind>): this
|
|
20
|
+
writeMethod(name: string): string
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../shared/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA0B,MAAM,eAAe,CAAA;AACxE,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,MAAM,MAAM,aAAa,GAAG;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,aAAa,CAAA;CACpB,CAAA;AAED,qBAAa,YAAa,SAAQ,gBAAgB,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAI/C,aAAa,EAAE,aAAa;IAH/C,IAAI,EAAE,MAAM,EAAE,CAAK;IACnB,aAAa,EAAE,YAAY,EAAE,CAAK;gBAEf,aAAa,EAAE,aAAa;IAI/C,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,MAAM;IAUvD,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO;IAM9C,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI;IAcjE,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,IAAI;IAMpD,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI;IAiCjD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGjC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { CompiledFunction, compileSerializedValue } from "@arktype/util"
|
|
2
|
+
export class NodeCompiler extends CompiledFunction {
|
|
3
|
+
traversalKind
|
|
4
|
+
path = []
|
|
5
|
+
discriminants = []
|
|
6
|
+
constructor(traversalKind) {
|
|
7
|
+
super("data", "ctx")
|
|
8
|
+
this.traversalKind = traversalKind
|
|
9
|
+
}
|
|
10
|
+
invoke(node, opts) {
|
|
11
|
+
const invokedKind = opts?.kind ?? this.traversalKind
|
|
12
|
+
const method = `${node.reference}${invokedKind}`
|
|
13
|
+
const arg = opts?.arg ?? this.data
|
|
14
|
+
if (this.requiresContextFor(node)) {
|
|
15
|
+
return `this.${method}(${arg}, ${this.ctx})`
|
|
16
|
+
}
|
|
17
|
+
return `this.${method}(${arg})`
|
|
18
|
+
}
|
|
19
|
+
requiresContextFor(node) {
|
|
20
|
+
return (
|
|
21
|
+
this.traversalKind === "Apply" ||
|
|
22
|
+
node.includesContextDependentPredicate
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
checkReferenceKey(keyExpression, node) {
|
|
26
|
+
const requiresContext = this.requiresContextFor(node)
|
|
27
|
+
if (requiresContext) {
|
|
28
|
+
this.line(`${this.ctx}.path.push(${keyExpression})`)
|
|
29
|
+
}
|
|
30
|
+
this.check(node, {
|
|
31
|
+
arg: `${this.data}${this.index(keyExpression)}`
|
|
32
|
+
})
|
|
33
|
+
if (requiresContext) {
|
|
34
|
+
this.line(`${this.ctx}.path.pop()`)
|
|
35
|
+
}
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
check(node, opts) {
|
|
39
|
+
return this.traversalKind === "Allows"
|
|
40
|
+
? this.if(`!${this.invoke(node, opts)}`, () => this.return(false))
|
|
41
|
+
: this.line(this.invoke(node, opts))
|
|
42
|
+
}
|
|
43
|
+
compilePrimitive(node) {
|
|
44
|
+
const pathString = this.path.join()
|
|
45
|
+
if (
|
|
46
|
+
node.kind === "domain" &&
|
|
47
|
+
node.domain === "object" &&
|
|
48
|
+
this.discriminants.some((d) => d.path.join().startsWith(pathString))
|
|
49
|
+
) {
|
|
50
|
+
// if we've already checked a path at least as long as the current one,
|
|
51
|
+
// we don't need to revalidate that we're in an object
|
|
52
|
+
return this
|
|
53
|
+
}
|
|
54
|
+
if (
|
|
55
|
+
(node.kind === "domain" || node.kind === "unit") &&
|
|
56
|
+
this.discriminants.some(
|
|
57
|
+
(d) =>
|
|
58
|
+
d.path.join() === pathString &&
|
|
59
|
+
(node.kind === "domain"
|
|
60
|
+
? d.kind === "domain" || d.kind === "value"
|
|
61
|
+
: d.kind === "value")
|
|
62
|
+
)
|
|
63
|
+
) {
|
|
64
|
+
// if the discriminant has already checked the domain at the current path
|
|
65
|
+
// (or an exact value, implying a domain), we don't need to recheck it
|
|
66
|
+
return this
|
|
67
|
+
}
|
|
68
|
+
if (this.traversalKind === "Allows") {
|
|
69
|
+
return this.return(node.compiledCondition)
|
|
70
|
+
}
|
|
71
|
+
return this.if(node.compiledNegation, () =>
|
|
72
|
+
this.line(`${this.ctx}.error(${node.compiledErrorContext})`)
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
writeMethod(name) {
|
|
76
|
+
return `${name}(${this.argNames.join(", ")}){\n${this.body} }\n`
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../shared/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAWxE,MAAM,OAAO,YAAa,SAAQ,gBAAiC;IAI/C;IAHnB,IAAI,GAAa,EAAE,CAAA;IACnB,aAAa,GAAmB,EAAE,CAAA;IAElC,Y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,IAAI,IAAI,CAAC,aAAa,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,UAAU,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAC5D,CAAA;IACF,CAAC;IAED,WAAW,CAAC,IAAY;QACvB,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,SAAS,CAAA;IACpE,CAAC;CACD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ArkErrors, type ArkErrorInput } from "./errors.js"
|
|
2
|
+
import type { ParsedArkConfig } from "../schemaScope.js"
|
|
3
|
+
export type TraversalPath = (string | symbol)[]
|
|
4
|
+
export declare const pathToPropString: (path: TraversalPath) => string
|
|
5
|
+
export declare class TraversalContext {
|
|
6
|
+
root: unknown
|
|
7
|
+
config: ParsedArkConfig
|
|
8
|
+
path: TraversalPath
|
|
9
|
+
errorsStack: ArkErrors[]
|
|
10
|
+
entriesToPrune: [data: Record<string, unknown>, key: string][]
|
|
11
|
+
seen: {
|
|
12
|
+
[name in string]?: object[]
|
|
13
|
+
}
|
|
14
|
+
constructor(root: unknown, config: ParsedArkConfig)
|
|
15
|
+
get currentErrors(): ArkErrors
|
|
16
|
+
get error(): (
|
|
17
|
+
input: ArkErrorInput
|
|
18
|
+
) => import("./errors.js").ArkTypeError<
|
|
19
|
+
| "max"
|
|
20
|
+
| "min"
|
|
21
|
+
| "maxLength"
|
|
22
|
+
| "minLength"
|
|
23
|
+
| "before"
|
|
24
|
+
| "after"
|
|
25
|
+
| "length"
|
|
26
|
+
| "union"
|
|
27
|
+
| "unit"
|
|
28
|
+
| "intersection"
|
|
29
|
+
| "proto"
|
|
30
|
+
| "domain"
|
|
31
|
+
| "regex"
|
|
32
|
+
| "divisor"
|
|
33
|
+
| "required"
|
|
34
|
+
| "predicate"
|
|
35
|
+
>
|
|
36
|
+
get data(): unknown
|
|
37
|
+
invalid(input: ArkErrorInput): false
|
|
38
|
+
pushUnion(): void
|
|
39
|
+
popUnion(branchCount: number, data: unknown, path: string[]): void
|
|
40
|
+
}
|
|
41
|
+
export type TraversalMethodsByKind<input = unknown> = {
|
|
42
|
+
Allows: TraverseAllows<input>
|
|
43
|
+
Apply: TraverseApply<input>
|
|
44
|
+
}
|
|
45
|
+
export type TraversalKind = keyof TraversalMethodsByKind
|
|
46
|
+
export type TraverseAllows<data = unknown> = (
|
|
47
|
+
data: data,
|
|
48
|
+
ctx: TraversalContext
|
|
49
|
+
) => boolean
|
|
50
|
+
export type TraverseApply<data = unknown> = (
|
|
51
|
+
data: data,
|
|
52
|
+
ctx: TraversalContext
|
|
53
|
+
) => void
|
|
54
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../shared/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;AAE/C,eAAO,MAAM,gBAAgB,iCAM5B,CAAA;AAED,qBAAa,gBAAgB;IAUpB,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,eAAe;IAV/B,IAAI,EAAE,aAAa,CAAK;IACxB,WAAW,EAAE,SAAS,EAAE,CAAA;IAExB,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,CAAK;IAGnE,IAAI,EAAE;SAAG,IAAI,IAAI,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE;KAAE,CAAK;gBAGlC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,eAAe;IAK/B,IAAI,aAAa,cAEhB;IAED,IAAI,KAAK,sPAER;IAED,IAAI,IAAI,IAAI,OAAO,CAMlB;IAED,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK;IAKpC,SAAS;IAIT,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;CAM3D;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,53 @@
|
|
|
1
|
+
import { literalPropAccess } from "@arktype/util"
|
|
2
|
+
import { ArkErrors } from "./errors.js"
|
|
3
|
+
export const pathToPropString = (path) => {
|
|
4
|
+
const propAccessChain = path.reduce(
|
|
5
|
+
(s, segment) => s + literalPropAccess(segment),
|
|
6
|
+
""
|
|
7
|
+
)
|
|
8
|
+
return propAccessChain[0] === "."
|
|
9
|
+
? propAccessChain.slice(1)
|
|
10
|
+
: propAccessChain
|
|
11
|
+
}
|
|
12
|
+
export class TraversalContext {
|
|
13
|
+
root
|
|
14
|
+
config
|
|
15
|
+
path = []
|
|
16
|
+
errorsStack
|
|
17
|
+
// TODO: add morphs here
|
|
18
|
+
entriesToPrune = []
|
|
19
|
+
// Qualified
|
|
20
|
+
seen = {}
|
|
21
|
+
constructor(root, config) {
|
|
22
|
+
this.root = root
|
|
23
|
+
this.config = config
|
|
24
|
+
this.errorsStack = [new ArkErrors(this)]
|
|
25
|
+
}
|
|
26
|
+
get currentErrors() {
|
|
27
|
+
return this.errorsStack.at(-1)
|
|
28
|
+
}
|
|
29
|
+
get error() {
|
|
30
|
+
return this.currentErrors.add.bind(this.currentErrors)
|
|
31
|
+
}
|
|
32
|
+
get data() {
|
|
33
|
+
let result = this.root
|
|
34
|
+
for (const segment of this.path) {
|
|
35
|
+
result = result?.[segment]
|
|
36
|
+
}
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
invalid(input) {
|
|
40
|
+
this.error(input)
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
pushUnion() {
|
|
44
|
+
this.errorsStack.push(new ArkErrors(this))
|
|
45
|
+
}
|
|
46
|
+
popUnion(branchCount, data, path) {
|
|
47
|
+
const branchProblems = this.errorsStack.pop()
|
|
48
|
+
if (branchProblems.count === branchCount) {
|
|
49
|
+
// this.addError("union", { data: this.data, errors: branchProblems })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../shared/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,SAAS,EAAsB,MAAM,aAAa,CAAA;AAK3D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAmB,EAAE,EAAE;IACvD,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAClC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,iBAAiB,C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