arktype 2.0.0-dev.4 → 2.0.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/array.test.ts +123 -215
- package/__tests__/badDefinitionType.test.ts +2 -2
- package/__tests__/bounds.test.ts +448 -349
- package/__tests__/config.test.ts +8 -6
- package/__tests__/cyclic.test.ts +1 -1
- package/__tests__/dateLiteral.test.ts +2 -2
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +23 -19
- package/__tests__/enclosed.test.ts +7 -2
- package/__tests__/errors.test.ts +115 -0
- package/__tests__/expressions.test.ts +14 -20
- package/__tests__/generic.test.ts +4 -5
- package/__tests__/group.test.ts +8 -3
- package/__tests__/instanceof.test.ts +7 -7
- package/__tests__/intersection.test.ts +62 -38
- package/__tests__/keyTraversal.test.ts +0 -2
- package/__tests__/keyof.test.ts +15 -13
- package/__tests__/keywords.test.ts +29 -25
- package/__tests__/literal.test.ts +26 -8
- package/__tests__/match.test.ts +28 -16
- package/__tests__/morph.test.ts +187 -172
- package/__tests__/narrow.test.ts +38 -39
- package/__tests__/objectLiteral.test.ts +106 -76
- package/__tests__/realWorld.test.ts +62 -0
- package/__tests__/schema.bench.ts +14 -0
- package/__tests__/schema.test.ts +60 -0
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +8 -6
- package/__tests__/submodule.test.ts +2 -2
- package/__tests__/traverse.test.ts +34 -31
- package/__tests__/typeMethods.test.ts +2 -3
- package/__tests__/typeReference.test.ts +3 -3
- package/__tests__/unenclosed.test.ts +9 -3
- package/__tests__/union.test.ts +127 -55
- package/__tests__/unit.test.ts +61 -0
- package/base.ts +520 -0
- package/config.ts +25 -0
- package/constraints/ast.ts +288 -0
- package/constraints/constraint.ts +91 -0
- package/constraints/predicate.ts +102 -0
- package/constraints/props/index.ts +93 -0
- package/constraints/props/prop.ts +146 -0
- package/constraints/props/props.ts +148 -0
- package/constraints/props/sequence.ts +473 -0
- package/constraints/props/shared.ts +5 -0
- package/constraints/refinements/after.ts +68 -0
- package/constraints/refinements/before.ts +75 -0
- package/constraints/refinements/divisor.ts +76 -0
- package/constraints/refinements/exactLength.ts +75 -0
- package/constraints/refinements/kinds.ts +31 -0
- package/constraints/refinements/max.ts +61 -0
- package/constraints/refinements/maxLength.ts +66 -0
- package/constraints/refinements/min.ts +54 -0
- package/constraints/refinements/minLength.ts +63 -0
- package/constraints/refinements/range.ts +181 -0
- package/constraints/refinements/regex.ts +59 -0
- package/{ark.ts → keywords/ark.ts} +40 -30
- package/keywords/internal.ts +29 -0
- package/keywords/jsObject.ts +39 -0
- package/keywords/parsing.ts +87 -0
- package/keywords/root.ts +9 -0
- package/keywords/tsGenerics.ts +28 -0
- package/keywords/tsPrimitive.ts +52 -0
- package/keywords/utils/creditCard.ts +37 -0
- package/keywords/utils/date.ts +112 -0
- package/keywords/validation.ts +115 -0
- package/kinds.ts +115 -0
- package/main.ts +7 -8
- package/match.ts +30 -34
- package/out/ark.d.ts +5 -1
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +4 -1
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +129 -0
- package/out/base.d.ts.map +1 -0
- package/out/base.js +274 -0
- package/out/base.js.map +1 -0
- package/out/builtins/builtins.d.ts +19 -0
- package/out/builtins/builtins.d.ts.map +1 -0
- package/out/builtins/builtins.js +12 -0
- package/out/builtins/builtins.js.map +1 -0
- package/out/builtins/jsObjects.d.ts +19 -0
- package/out/builtins/jsObjects.d.ts.map +1 -0
- package/out/builtins/jsObjects.js +15 -0
- package/out/builtins/jsObjects.js.map +1 -0
- package/out/builtins/parsing.d.ts +16 -0
- package/out/builtins/parsing.d.ts.map +1 -0
- package/out/builtins/parsing.js +59 -0
- package/out/builtins/parsing.js.map +1 -0
- package/out/builtins/tsGenerics.d.ts +2 -0
- package/out/builtins/tsGenerics.d.ts.map +1 -0
- package/out/builtins/tsGenerics.js +26 -0
- package/out/builtins/tsGenerics.js.map +1 -0
- package/out/builtins/tsKeywords.d.ts +23 -0
- package/out/builtins/tsKeywords.d.ts.map +1 -0
- package/out/builtins/tsKeywords.js +20 -0
- package/out/builtins/tsKeywords.js.map +1 -0
- package/out/builtins/utils/creditCard.d.ts +3 -0
- package/out/builtins/utils/creditCard.d.ts.map +1 -0
- package/out/builtins/utils/creditCard.js +36 -0
- package/out/builtins/utils/creditCard.js.map +1 -0
- package/out/builtins/utils/date.d.ts +22 -0
- package/out/builtins/utils/date.d.ts.map +1 -0
- package/out/builtins/utils/date.js +53 -0
- package/out/builtins/utils/date.js.map +1 -0
- package/out/builtins/validation.d.ts +19 -0
- package/out/builtins/validation.d.ts.map +1 -0
- package/out/builtins/validation.js +70 -0
- package/out/builtins/validation.js.map +1 -0
- package/out/config.d.ts +6 -0
- package/out/config.d.ts.map +1 -0
- package/out/config.js +17 -0
- package/out/config.js.map +1 -0
- package/out/constraints/ast.d.ts +176 -0
- package/out/constraints/ast.d.ts.map +1 -0
- package/out/constraints/ast.js +2 -0
- package/out/constraints/ast.js.map +1 -0
- package/out/constraints/constraint.d.ts +70 -0
- package/out/constraints/constraint.d.ts.map +1 -0
- package/out/constraints/constraint.js +21 -0
- package/out/constraints/constraint.js.map +1 -0
- package/out/constraints/predicate.d.ts +46 -0
- package/out/constraints/predicate.d.ts.map +1 -0
- package/out/constraints/predicate.js +47 -0
- package/out/constraints/predicate.js.map +1 -0
- package/out/constraints/props/index.d.ts +36 -0
- package/out/constraints/props/index.d.ts.map +1 -0
- package/out/constraints/props/index.js +48 -0
- package/out/constraints/props/index.js.map +1 -0
- package/out/constraints/props/optional.d.ts +34 -0
- package/out/constraints/props/optional.d.ts.map +1 -0
- package/out/constraints/props/optional.js +55 -0
- package/out/constraints/props/optional.js.map +1 -0
- package/out/constraints/props/prop.d.ts +46 -0
- package/out/constraints/props/prop.d.ts.map +1 -0
- package/out/constraints/props/prop.js +104 -0
- package/out/constraints/props/prop.js.map +1 -0
- package/out/constraints/props/props.d.ts +34 -0
- package/out/constraints/props/props.d.ts.map +1 -0
- package/out/constraints/props/props.js +106 -0
- package/out/constraints/props/props.js.map +1 -0
- package/out/constraints/props/required.d.ts +43 -0
- package/out/constraints/props/required.d.ts.map +1 -0
- package/out/constraints/props/required.js +76 -0
- package/out/constraints/props/required.js.map +1 -0
- package/out/constraints/props/sequence.d.ts +64 -0
- package/out/constraints/props/sequence.d.ts.map +1 -0
- package/out/constraints/props/sequence.js +327 -0
- package/out/constraints/props/sequence.js.map +1 -0
- package/out/constraints/props/shared.d.ts +3 -0
- package/out/constraints/props/shared.d.ts.map +1 -0
- package/out/constraints/props/shared.js +4 -0
- package/out/constraints/props/shared.js.map +1 -0
- package/out/constraints/refinements/after.d.ts +25 -0
- package/out/constraints/refinements/after.d.ts.map +1 -0
- package/out/constraints/refinements/after.js +35 -0
- package/out/constraints/refinements/after.js.map +1 -0
- package/out/constraints/refinements/before.d.ts +25 -0
- package/out/constraints/refinements/before.d.ts.map +1 -0
- package/out/constraints/refinements/before.js +41 -0
- package/out/constraints/refinements/before.js.map +1 -0
- package/out/constraints/refinements/divisor.d.ts +42 -0
- package/out/constraints/refinements/divisor.d.ts.map +1 -0
- package/out/constraints/refinements/divisor.js +41 -0
- package/out/constraints/refinements/divisor.js.map +1 -0
- package/out/constraints/refinements/exactLength.d.ts +41 -0
- package/out/constraints/refinements/exactLength.d.ts.map +1 -0
- package/out/constraints/refinements/exactLength.js +44 -0
- package/out/constraints/refinements/exactLength.js.map +1 -0
- package/out/constraints/refinements/kinds.d.ts +29 -0
- package/out/constraints/refinements/kinds.d.ts.map +1 -0
- package/out/constraints/refinements/kinds.js +17 -0
- package/out/constraints/refinements/kinds.js.map +1 -0
- package/out/constraints/refinements/length.d.ts +42 -0
- package/out/constraints/refinements/length.d.ts.map +1 -0
- package/out/constraints/refinements/length.js +45 -0
- package/out/constraints/refinements/length.js.map +1 -0
- package/out/constraints/refinements/max.d.ts +24 -0
- package/out/constraints/refinements/max.d.ts.map +1 -0
- package/out/constraints/refinements/max.js +31 -0
- package/out/constraints/refinements/max.js.map +1 -0
- package/out/constraints/refinements/maxLength.d.ts +24 -0
- package/out/constraints/refinements/maxLength.d.ts.map +1 -0
- package/out/constraints/refinements/maxLength.js +34 -0
- package/out/constraints/refinements/maxLength.js.map +1 -0
- package/out/constraints/refinements/min.d.ts +24 -0
- package/out/constraints/refinements/min.d.ts.map +1 -0
- package/out/constraints/refinements/min.js +25 -0
- package/out/constraints/refinements/min.js.map +1 -0
- package/out/constraints/refinements/minLength.d.ts +24 -0
- package/out/constraints/refinements/minLength.d.ts.map +1 -0
- package/out/constraints/refinements/minLength.js +32 -0
- package/out/constraints/refinements/minLength.js.map +1 -0
- package/out/constraints/refinements/range.d.ts +90 -0
- package/out/constraints/refinements/range.d.ts.map +1 -0
- package/out/constraints/refinements/range.js +72 -0
- package/out/constraints/refinements/range.js.map +1 -0
- package/out/constraints/refinements/regex.d.ts +43 -0
- package/out/constraints/refinements/regex.d.ts.map +1 -0
- package/out/constraints/refinements/regex.js +36 -0
- package/out/constraints/refinements/regex.js.map +1 -0
- package/out/constraints/refinements/shared.d.ts +5 -0
- package/out/constraints/refinements/shared.d.ts.map +1 -0
- package/out/constraints/refinements/shared.js +10 -0
- package/out/constraints/refinements/shared.js.map +1 -0
- package/out/inference.d.ts +40 -0
- package/out/inference.d.ts.map +1 -0
- package/out/inference.js +73 -0
- package/out/inference.js.map +1 -0
- package/out/keywords/ark.d.ts +60 -0
- package/out/keywords/ark.d.ts.map +1 -0
- package/out/keywords/ark.js +29 -0
- package/out/keywords/ark.js.map +1 -0
- package/out/keywords/internal.d.ts +13 -0
- package/out/keywords/internal.d.ts.map +1 -0
- package/out/keywords/internal.js +10 -0
- package/out/keywords/internal.js.map +1 -0
- package/out/keywords/jsObject.d.ts +20 -0
- package/out/keywords/jsObject.d.ts.map +1 -0
- package/out/keywords/jsObject.js +15 -0
- package/out/keywords/jsObject.js.map +1 -0
- package/out/keywords/parsing.d.ts +17 -0
- package/out/keywords/parsing.d.ts.map +1 -0
- package/out/keywords/parsing.js +61 -0
- package/out/keywords/parsing.js.map +1 -0
- package/out/keywords/root.d.ts +7 -0
- package/out/keywords/root.d.ts.map +1 -0
- package/out/keywords/root.js +4 -0
- package/out/keywords/root.js.map +1 -0
- package/out/keywords/tsGenerics.d.ts +2 -0
- package/out/keywords/tsGenerics.d.ts.map +1 -0
- package/out/keywords/tsGenerics.js +26 -0
- package/out/keywords/tsGenerics.js.map +1 -0
- package/out/keywords/tsPrimitive.d.ts +24 -0
- package/out/keywords/tsPrimitive.d.ts.map +1 -0
- package/out/keywords/tsPrimitive.js +22 -0
- package/out/keywords/tsPrimitive.js.map +1 -0
- package/out/keywords/utils/creditCard.d.ts +8 -0
- package/out/keywords/utils/creditCard.d.ts.map +1 -0
- package/out/keywords/utils/creditCard.js +36 -0
- package/out/keywords/utils/creditCard.js.map +1 -0
- package/out/keywords/utils/date.d.ts +25 -0
- package/out/keywords/utils/date.d.ts.map +1 -0
- package/out/keywords/utils/date.js +53 -0
- package/out/keywords/utils/date.js.map +1 -0
- package/out/keywords/validation.d.ts +20 -0
- package/out/keywords/validation.d.ts.map +1 -0
- package/out/keywords/validation.js +76 -0
- package/out/keywords/validation.js.map +1 -0
- package/out/kinds.d.ts +72 -0
- package/out/kinds.d.ts.map +1 -0
- package/out/kinds.js +29 -0
- package/out/kinds.js.map +1 -0
- package/out/main.d.ts +5 -4
- package/out/main.d.ts.map +1 -1
- package/out/main.js +2 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +17 -18
- package/out/match.d.ts.map +1 -1
- package/out/match.js +3 -4
- package/out/match.js.map +1 -1
- package/out/parse.d.ts +23 -0
- package/out/parse.d.ts.map +1 -0
- package/out/parse.js +148 -0
- package/out/parse.js.map +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +8 -9
- package/out/parser/definition.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +44 -11
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +47 -35
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +8 -6
- package/out/parser/semantic/bounds.d.ts.map +1 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +4 -6
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +28 -0
- package/out/parser/semantic/infer.d.ts.map +1 -0
- package/out/parser/semantic/infer.js +2 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -6
- package/out/parser/semantic/utils.d.ts.map +1 -1
- package/out/parser/semantic/validate.d.ts +1 -1
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -11
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +15 -9
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +2 -3
- package/out/parser/string/reduce/shared.d.ts.map +1 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +20 -19
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +3 -2
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +6 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +2 -2
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +5 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +5 -5
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +17 -12
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +28 -25
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/string.d.ts +3 -3
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +95 -33
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +45 -48
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +44 -0
- package/out/schema.d.ts.map +1 -0
- package/out/schema.js +73 -0
- package/out/schema.js.map +1 -0
- package/out/schemaScope.d.ts +110 -0
- package/out/schemaScope.d.ts.map +1 -0
- package/out/schemaScope.js +212 -0
- package/out/schemaScope.js.map +1 -0
- package/out/scope.d.ts +98 -26
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +185 -45
- package/out/scope.js.map +1 -1
- package/out/shared/compile.d.ts +22 -0
- package/out/shared/compile.d.ts.map +1 -0
- package/out/shared/compile.js +67 -0
- package/out/shared/compile.js.map +1 -0
- package/out/shared/context.d.ts +29 -0
- package/out/shared/context.d.ts.map +1 -0
- package/out/shared/context.js +48 -0
- package/out/shared/context.js.map +1 -0
- package/out/shared/declare.d.ts +53 -0
- package/out/shared/declare.d.ts.map +1 -0
- package/out/shared/declare.js +2 -0
- package/out/shared/declare.js.map +1 -0
- package/out/shared/disjoint.d.ts +79 -0
- package/out/shared/disjoint.d.ts.map +1 -0
- package/out/shared/disjoint.js +82 -0
- package/out/shared/disjoint.js.map +1 -0
- package/out/shared/errors.d.ts +59 -0
- package/out/shared/errors.d.ts.map +1 -0
- package/out/shared/errors.js +108 -0
- package/out/shared/errors.js.map +1 -0
- package/out/shared/implement.d.ts +170 -0
- package/out/shared/implement.d.ts.map +1 -0
- package/out/shared/implement.js +69 -0
- package/out/shared/implement.js.map +1 -0
- package/out/shared/inference.d.ts +6 -0
- package/out/shared/inference.d.ts.map +1 -0
- package/out/shared/inference.js +5 -0
- package/out/shared/inference.js.map +1 -0
- package/out/shared/intersections.d.ts +15 -0
- package/out/shared/intersections.d.ts.map +1 -0
- package/out/shared/intersections.js.map +1 -0
- package/out/shared/traversal.d.ts +44 -0
- package/out/shared/traversal.d.ts.map +1 -0
- package/out/shared/traversal.js +97 -0
- package/out/shared/traversal.js.map +1 -0
- package/out/shared/utils.d.ts +8 -0
- package/out/shared/utils.d.ts.map +1 -0
- package/out/shared/utils.js +10 -0
- package/out/shared/utils.js.map +1 -0
- package/out/type.d.ts +10 -38
- package/out/type.d.ts.map +1 -1
- package/out/type.js +20 -106
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +24 -0
- package/out/types/basis.d.ts.map +1 -0
- package/out/types/basis.js +15 -0
- package/out/types/basis.js.map +1 -0
- package/out/types/discriminate.d.ts +20 -0
- package/out/types/discriminate.d.ts.map +1 -0
- package/out/types/discriminate.js +114 -0
- package/out/types/discriminate.js.map +1 -0
- package/out/types/domain.d.ts +40 -0
- package/out/types/domain.d.ts.map +1 -0
- package/out/types/domain.js +38 -0
- package/out/types/domain.js.map +1 -0
- package/out/types/intersection.d.ts +67 -0
- package/out/types/intersection.d.ts.map +1 -0
- package/out/types/intersection.js +350 -0
- package/out/types/intersection.js.map +1 -0
- package/out/types/morph.d.ts +79 -0
- package/out/types/morph.d.ts.map +1 -0
- package/out/types/morph.js +95 -0
- package/out/types/morph.js.map +1 -0
- package/out/types/proto.d.ts +42 -0
- package/out/types/proto.d.ts.map +1 -0
- package/out/types/proto.js +48 -0
- package/out/types/proto.js.map +1 -0
- package/out/types/type.d.ts +61 -0
- package/out/types/type.d.ts.map +1 -0
- package/out/types/type.js +111 -0
- package/out/types/type.js.map +1 -0
- package/out/types/union.d.ts +48 -0
- package/out/types/union.d.ts.map +1 -0
- package/out/types/union.js +337 -0
- package/out/types/union.js.map +1 -0
- package/out/types/unit.d.ts +40 -0
- package/out/types/unit.d.ts.map +1 -0
- package/out/types/unit.js +48 -0
- package/out/types/unit.js.map +1 -0
- package/out/util.d.ts +5 -2
- package/out/util.d.ts.map +1 -1
- package/out/util.js.map +1 -1
- package/package.json +6 -3
- package/parse.ts +221 -0
- package/parser/definition.ts +24 -23
- package/parser/objectLiteral.ts +128 -88
- package/parser/semantic/bounds.ts +18 -9
- package/parser/semantic/divisor.ts +12 -10
- package/parser/semantic/infer.ts +152 -0
- package/parser/semantic/utils.ts +5 -13
- package/parser/semantic/validate.ts +1 -2
- package/parser/string/reduce/dynamic.ts +42 -30
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +22 -22
- package/parser/string/shift/operand/date.ts +9 -5
- package/parser/string/shift/operand/enclosed.ts +11 -5
- package/parser/string/shift/operand/genericArgs.ts +6 -6
- package/parser/string/shift/operand/operand.ts +1 -2
- package/parser/string/shift/operand/unenclosed.ts +14 -20
- package/parser/string/shift/operator/bounds.ts +59 -54
- package/parser/string/shift/operator/divisor.ts +2 -2
- package/parser/string/shift/scanner.ts +10 -10
- package/parser/string/string.ts +4 -4
- package/parser/tuple.ts +224 -202
- package/schema.ts +263 -0
- package/scope.ts +358 -81
- package/shared/compile.ts +92 -0
- package/shared/declare.ts +75 -0
- package/shared/disjoint.ts +203 -0
- package/shared/errors.ts +204 -0
- package/shared/implement.ts +327 -0
- package/shared/inference.ts +9 -0
- package/shared/intersections.ts +53 -0
- package/shared/traversal.ts +146 -0
- package/shared/utils.ts +30 -0
- package/type.ts +23 -183
- package/types/basis.ts +62 -0
- package/types/discriminate.ts +168 -0
- package/types/domain.ts +79 -0
- package/types/intersection.ts +539 -0
- package/types/morph.ts +263 -0
- package/types/proto.ts +89 -0
- package/types/type.ts +319 -0
- package/types/union.ts +451 -0
- package/types/unit.ts +78 -0
- package/util.ts +5 -2
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -32
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/shared.d.ts +0 -62
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -56
- package/out/parser/shared.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/parser/semantic/semantic.ts +0 -143
- package/parser/shared.ts +0 -170
- /package/out/{parser/semantic → shared}/intersections.js +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Key } from "@arktype/util";
|
|
2
|
+
import type { Node, TypeSchema } from "../../base.js";
|
|
3
|
+
import type { NodeCompiler } from "../../shared/compile.js";
|
|
4
|
+
import type { BaseMeta, declareNode } from "../../shared/declare.js";
|
|
5
|
+
import type { TypeKind, nodeImplementationOf } from "../../shared/implement.js";
|
|
6
|
+
import type { TraverseAllows, TraverseApply } from "../../shared/traversal.js";
|
|
7
|
+
import { BaseConstraint } from "../constraint.js";
|
|
8
|
+
export interface PropSchema extends BaseMeta {
|
|
9
|
+
readonly key: Key;
|
|
10
|
+
readonly value: TypeSchema;
|
|
11
|
+
readonly optional?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface PropInner extends BaseMeta {
|
|
14
|
+
readonly key: Key;
|
|
15
|
+
readonly value: Node<TypeKind>;
|
|
16
|
+
readonly optional?: true;
|
|
17
|
+
}
|
|
18
|
+
export type PropDeclaration = declareNode<{
|
|
19
|
+
kind: "prop";
|
|
20
|
+
schema: PropSchema;
|
|
21
|
+
normalizedSchema: PropSchema;
|
|
22
|
+
inner: PropInner;
|
|
23
|
+
errorContext: {
|
|
24
|
+
key: Key;
|
|
25
|
+
};
|
|
26
|
+
prerequisite: object;
|
|
27
|
+
intersectionIsOpen: true;
|
|
28
|
+
childKind: TypeKind;
|
|
29
|
+
}>;
|
|
30
|
+
export declare class PropNode extends BaseConstraint<PropDeclaration> {
|
|
31
|
+
static implementation: nodeImplementationOf<PropDeclaration>;
|
|
32
|
+
readonly required: boolean;
|
|
33
|
+
readonly impliedBasis: import("../../main.js").Type<object, import("../../keywords/tsPrimitive.js").tsPrimitive.exports>;
|
|
34
|
+
readonly serializedKey: string;
|
|
35
|
+
readonly compiledKey: string;
|
|
36
|
+
readonly expression: string;
|
|
37
|
+
readonly errorContext: Readonly<{
|
|
38
|
+
code: "prop";
|
|
39
|
+
description: string;
|
|
40
|
+
key: Key;
|
|
41
|
+
}>;
|
|
42
|
+
traverseAllows: TraverseAllows<object>;
|
|
43
|
+
traverseApply: TraverseApply<object>;
|
|
44
|
+
compile(js: NodeCompiler): void;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=prop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prop.d.ts","sourceRoot":"","sources":["../../../constraints/props/prop.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,GAAG,EAAE,MAAM,eAAe,CAAA;AACh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Q,CAAC,QAAQ,UAAiB;IAClC,QAAQ,CAAC,YAAY,oGAAyB;IAC9C,QAAQ,CAAC,aAAa,SAAmC;IACzD,QAAQ,CAAC,WAAW,SACyC;IAC7D,QAAQ,CAAC,UAAU,SAEjB;IAEF,QAAQ,CAAC,YAAY;;;;OAInB;IAEF,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,CASrC;IAED,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAQnC;IAED,OAAO,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI;CA2B/B"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { compileSerializedValue } from "@arktype/util";
|
|
2
|
+
import { Disjoint } from "../../shared/disjoint.js";
|
|
3
|
+
import { BaseConstraint } from "../constraint.js";
|
|
4
|
+
export class PropNode extends BaseConstraint {
|
|
5
|
+
static implementation = this.implement({
|
|
6
|
+
hasAssociatedError: true,
|
|
7
|
+
intersectionIsOpen: true,
|
|
8
|
+
keys: {
|
|
9
|
+
key: {},
|
|
10
|
+
value: {
|
|
11
|
+
child: true,
|
|
12
|
+
parse: (schema, ctx) => ctx.$.node(schema)
|
|
13
|
+
},
|
|
14
|
+
optional: {
|
|
15
|
+
// normalize { optional: false } to {}
|
|
16
|
+
parse: (schema) => schema || undefined
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
normalize: (schema) => schema,
|
|
20
|
+
defaults: {
|
|
21
|
+
description(node) {
|
|
22
|
+
return `${node.compiledKey}${node.optional ? "?" : ""}: ${node.value.description}`;
|
|
23
|
+
},
|
|
24
|
+
expected() {
|
|
25
|
+
return "defined";
|
|
26
|
+
},
|
|
27
|
+
actual: () => null
|
|
28
|
+
},
|
|
29
|
+
intersections: {
|
|
30
|
+
prop: (l, r, $) => {
|
|
31
|
+
if (l.key !== r.key) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const key = l.key;
|
|
35
|
+
const value = l.value.intersect(r.value);
|
|
36
|
+
if (value instanceof Disjoint) {
|
|
37
|
+
return value.withPrefixKey(l.compiledKey);
|
|
38
|
+
}
|
|
39
|
+
return $.node("prop", {
|
|
40
|
+
key,
|
|
41
|
+
value,
|
|
42
|
+
optional: l.optional === true && r.optional === true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
required = !this.optional;
|
|
48
|
+
impliedBasis = this.$.keywords.object;
|
|
49
|
+
serializedKey = compileSerializedValue(this.key);
|
|
50
|
+
compiledKey = typeof this.key === "string" ? this.key : this.serializedKey;
|
|
51
|
+
expression = `${this.compiledKey}${this.optional ? "?" : ""}: ${this.value.expression}`;
|
|
52
|
+
errorContext = Object.freeze({
|
|
53
|
+
code: "prop",
|
|
54
|
+
description: this.description,
|
|
55
|
+
key: this.key
|
|
56
|
+
});
|
|
57
|
+
traverseAllows = (data, ctx) => {
|
|
58
|
+
if (this.key in data) {
|
|
59
|
+
// ctx will be undefined if this node doesn't have a context-dependent predicate
|
|
60
|
+
ctx?.path.push(this.key);
|
|
61
|
+
const allowed = this.value.traverseAllows(data[this.key], ctx);
|
|
62
|
+
ctx?.path.pop();
|
|
63
|
+
return allowed;
|
|
64
|
+
}
|
|
65
|
+
return this.required;
|
|
66
|
+
};
|
|
67
|
+
traverseApply = (data, ctx) => {
|
|
68
|
+
ctx.path.push(this.key);
|
|
69
|
+
if (this.key in data) {
|
|
70
|
+
this.value.traverseApply(data[this.key], ctx);
|
|
71
|
+
}
|
|
72
|
+
else if (this.required) {
|
|
73
|
+
ctx.error(this.errorContext);
|
|
74
|
+
}
|
|
75
|
+
ctx.path.pop();
|
|
76
|
+
};
|
|
77
|
+
compile(js) {
|
|
78
|
+
const requiresContext = js.requiresContextFor(this.value);
|
|
79
|
+
if (requiresContext) {
|
|
80
|
+
js.line(`ctx.path.push(${this.serializedKey})`);
|
|
81
|
+
}
|
|
82
|
+
js.if(`${this.serializedKey} in ${js.data}`, () => js.check(this.value, {
|
|
83
|
+
arg: `${js.data}${js.prop(this.key)}`
|
|
84
|
+
}));
|
|
85
|
+
if (this.required) {
|
|
86
|
+
js.else(() => {
|
|
87
|
+
if (js.traversalKind === "Apply") {
|
|
88
|
+
return js.line(`ctx.error(${this.compiledErrorContext})`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (requiresContext) {
|
|
92
|
+
js.line(`ctx.path.pop()`);
|
|
93
|
+
}
|
|
94
|
+
return js.return(false);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (requiresContext)
|
|
99
|
+
js.line(`ctx.path.pop()`);
|
|
100
|
+
else
|
|
101
|
+
js.return(true);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=prop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prop.js","sourceRoot":"","sources":["../../../constraints/props/prop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAY,MAAM,eAAe,CAAA;AAIhE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AA2BjD,MAAM,OAAO,QAAS,SAAQ,cAA+B;IAC5D,MAAM,CAAC,cAAc,GAA0C,IAAI,CAAC,SAAS,CAC5E;QACC,kBAAkB,EAAE,IAAI;QACxB,kBAAkB,EAAE,IAAI;QACxB,IAAI,EAAE;YACL,GAAG,EAAE,EAAE;YACP,KAAK,EAAE;gBACN,KAAK,EAAE,IAAI;gBACX,KAAK,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;aAC1C;YACD,QAAQ,EAAE;gBACT,sCAAsC;gBACtC,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,SAAS;aACtC;SACD;QACD,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAA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2
|
+
import type { Node } from "../../base.js";
|
|
3
|
+
import type { Scope } from "../../scope.js";
|
|
4
|
+
import type { NodeCompiler } from "../../shared/compile.js";
|
|
5
|
+
import type { PropKind } from "../../shared/implement.js";
|
|
6
|
+
import type { TraverseAllows, TraverseApply } from "../../shared/traversal.js";
|
|
7
|
+
import type { IntersectionNode } from "../../types/intersection.js";
|
|
8
|
+
import type { Type } from "../../types/type.js";
|
|
9
|
+
export type ExtraneousKeyBehavior = "ignore" | ExtraneousKeyRestriction;
|
|
10
|
+
export type ExtraneousKeyRestriction = "throw" | "prune";
|
|
11
|
+
export type PropsGroupInput = Pick<IntersectionNode, PropKind | "onExtraneousKey">;
|
|
12
|
+
export declare class PropsGroup extends DynamicBase<PropsGroupInput> {
|
|
13
|
+
inner: PropsGroupInput;
|
|
14
|
+
$: Scope;
|
|
15
|
+
constructor(inner: PropsGroupInput, $: Scope);
|
|
16
|
+
readonly exhaustive: boolean;
|
|
17
|
+
readonly all: readonly Node<"prop" | "index" | "sequence">[];
|
|
18
|
+
readonly nameSet: {
|
|
19
|
+
[x: string]: 1;
|
|
20
|
+
[x: symbol]: 1;
|
|
21
|
+
};
|
|
22
|
+
readonly nameSetReference: `$ark.${string}`;
|
|
23
|
+
readonly description: string;
|
|
24
|
+
readonly expression: string;
|
|
25
|
+
readonly literalKeys: Key[];
|
|
26
|
+
private keyofCache;
|
|
27
|
+
rawKeyOf(): Type;
|
|
28
|
+
traverseAllows: TraverseAllows<object>;
|
|
29
|
+
traverseApply: TraverseApply<object>;
|
|
30
|
+
compile(js: NodeCompiler): void;
|
|
31
|
+
protected compileEnumerable(js: NodeCompiler): void;
|
|
32
|
+
protected compileExhaustive(js: NodeCompiler): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../../constraints/props/props.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAA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,YAAY,GAAG,IAAI;IAQ/B,SAAS,CAAC,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI;IAUnD,SAAS,CAAC,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI;CAoCnD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DynamicBase, conflatenateAll, morph, reference } from "@arktype/util";
|
|
2
|
+
import { arrayIndexMatcherReference } from "./shared.js";
|
|
3
|
+
export class PropsGroup extends DynamicBase {
|
|
4
|
+
inner;
|
|
5
|
+
$;
|
|
6
|
+
constructor(inner, $) {
|
|
7
|
+
super(inner);
|
|
8
|
+
this.inner = inner;
|
|
9
|
+
this.$ = $;
|
|
10
|
+
}
|
|
11
|
+
exhaustive = this.onExtraneousKey !== undefined || this.index !== undefined;
|
|
12
|
+
all = conflatenateAll(this.prop, this.index, this.sequence);
|
|
13
|
+
nameSet = this.prop
|
|
14
|
+
? morph(this.prop, (i, node) => [node.key, 1])
|
|
15
|
+
: {};
|
|
16
|
+
nameSetReference = reference(this.nameSet);
|
|
17
|
+
description = describeProps(this, "description");
|
|
18
|
+
expression = describeProps(this, "expression");
|
|
19
|
+
literalKeys = literalPropKeysOf(this.all);
|
|
20
|
+
keyofCache;
|
|
21
|
+
rawKeyOf() {
|
|
22
|
+
if (!this.keyofCache) {
|
|
23
|
+
let branches = this.$.parseUnits(...this.literalKeys).branches;
|
|
24
|
+
this.index?.forEach(({ key }) => (branches = branches.concat(key.branches)));
|
|
25
|
+
this.keyofCache = this.$.node(branches);
|
|
26
|
+
}
|
|
27
|
+
return this.keyofCache;
|
|
28
|
+
}
|
|
29
|
+
traverseAllows = (data, ctx) => this.all.every((prop) => prop.traverseAllows(data, ctx));
|
|
30
|
+
traverseApply = (data, ctx) => this.all.forEach((prop) => prop.traverseApply(data, ctx));
|
|
31
|
+
compile(js) {
|
|
32
|
+
if (this.exhaustive) {
|
|
33
|
+
this.compileExhaustive(js);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.compileEnumerable(js);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
compileEnumerable(js) {
|
|
40
|
+
if (js.traversalKind === "Allows") {
|
|
41
|
+
this.all.forEach((node) => js.if(`!${js.invoke(node)}`, () => js.return(false)));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.all.forEach((node) => js.line(js.invoke(node)));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
compileExhaustive(js) {
|
|
48
|
+
this.prop?.forEach((prop) => js.check(prop));
|
|
49
|
+
this.sequence?.compile(js);
|
|
50
|
+
if (this.sequence)
|
|
51
|
+
js.check(this.sequence);
|
|
52
|
+
js.forIn(js.data, () => {
|
|
53
|
+
if (this.onExtraneousKey) {
|
|
54
|
+
js.let("matched", false);
|
|
55
|
+
}
|
|
56
|
+
this.index?.forEach((node) => {
|
|
57
|
+
js.if(`${js.invoke(node.key, { arg: "k", kind: "Allows" })}`, () => {
|
|
58
|
+
if (js.traversalKind === "Allows") {
|
|
59
|
+
js.if(`!${js.invoke(node.value, { arg: `${js.data}[k]` })}`, () => js.return(false));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
js.line(js.invoke(node.value, { arg: `${js.data}[k]` }));
|
|
63
|
+
}
|
|
64
|
+
if (this.onExtraneousKey) {
|
|
65
|
+
js.set("matched", true);
|
|
66
|
+
}
|
|
67
|
+
return js;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
if (this.onExtraneousKey) {
|
|
71
|
+
if (this.prop?.length !== 0) {
|
|
72
|
+
js.line(`matched ||= k in ${this.nameSetReference}`);
|
|
73
|
+
}
|
|
74
|
+
if (this.sequence) {
|
|
75
|
+
js.line(`matched ||= ${arrayIndexMatcherReference}.test(k)`);
|
|
76
|
+
}
|
|
77
|
+
// TODO: replace error
|
|
78
|
+
js.if("!matched", () => js.line(`throw new Error("strict")`));
|
|
79
|
+
}
|
|
80
|
+
return js;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const literalPropKeysOf = (all) => {
|
|
85
|
+
const keys = [];
|
|
86
|
+
all.forEach((node) => {
|
|
87
|
+
if (node.kind === "index")
|
|
88
|
+
return;
|
|
89
|
+
if (node.kind === "prop")
|
|
90
|
+
return keys.push(node.key);
|
|
91
|
+
node.prevariadic.forEach((_, i) => keys.push(`${i}`));
|
|
92
|
+
});
|
|
93
|
+
return keys;
|
|
94
|
+
};
|
|
95
|
+
const describeProps = (inner, childStringProp) => {
|
|
96
|
+
if (inner.prop || inner.index) {
|
|
97
|
+
const parts = inner.index?.map(String) ?? [];
|
|
98
|
+
inner.prop?.forEach((node) => parts.push(node[childStringProp]));
|
|
99
|
+
const objectLiteralDescription = `${inner.onExtraneousKey ? "exact " : ""}{ ${parts.join(", ")} }`;
|
|
100
|
+
return inner.sequence
|
|
101
|
+
? `${objectLiteralDescription} & ${inner.sequence.description}`
|
|
102
|
+
: objectLiteralDescription;
|
|
103
|
+
}
|
|
104
|
+
return inner.sequence?.description ?? "{}";
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../../constraints/props/props.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,eAAe,EACf,KAAK,EACL,SAAS,EAET,MAAM,eAAe,CAAA;AAQtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAWxD,MAAM,OAAO,UAAW,SAAQ,WAA4B;IAEnD;IACA;IAFR,YACQ,KAAsB,EACtB,CAAQ;QAEf,KAAK,CAAC,KAAK,CAAC,CAAA;QAHL,UAAK,GAAL,KAAK,CAAiB;QACtB,MAAC,GAAD,CAAC,CAAO;IAGhB,CAAC;IAEQ,UAAU,GAClB,IAAI,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,CAAA;IACtD,GAAG,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CAAA;QAChE,MAAM,wBAAwB,GAAG,GAChC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EACpC,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;QACzB,OAAO,KAAK,CAAC,QAAQ;YACpB,CAAC,CAAC,GAAG,wBAAwB,MAAM,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE;YAC/D,CAAC,CAAC,wBAAwB,CAAA;IAC5B,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,EAAE,WAAW,IAAI,IAAI,CAAA;AAC3C,CAAC,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Node, TypeSchema } from "../../base.js";
|
|
2
|
+
import type { NodeCompiler } from "../../shared/compile.js";
|
|
3
|
+
import type { TraverseAllows, TraverseApply } from "../../shared/context.js";
|
|
4
|
+
import type { BaseMeta, declareNode } from "../../shared/declare.js";
|
|
5
|
+
import type { TypeKind, nodeImplementationOf } from "../../shared/implement.js";
|
|
6
|
+
import { BaseConstraint } from "../constraint.js";
|
|
7
|
+
export interface RequiredSchema extends BaseMeta {
|
|
8
|
+
readonly key: string | symbol;
|
|
9
|
+
readonly value: TypeSchema;
|
|
10
|
+
}
|
|
11
|
+
export interface RequiredInner extends BaseMeta {
|
|
12
|
+
readonly key: string | symbol;
|
|
13
|
+
readonly value: Node<TypeKind>;
|
|
14
|
+
}
|
|
15
|
+
export type RequiredDeclaration = declareNode<{
|
|
16
|
+
kind: "required";
|
|
17
|
+
schema: RequiredSchema;
|
|
18
|
+
normalizedSchema: RequiredSchema;
|
|
19
|
+
inner: RequiredInner;
|
|
20
|
+
errorContext: {
|
|
21
|
+
code: "required";
|
|
22
|
+
key: string | symbol;
|
|
23
|
+
};
|
|
24
|
+
prerequisite: object;
|
|
25
|
+
intersectionIsOpen: true;
|
|
26
|
+
childKind: TypeKind;
|
|
27
|
+
}>;
|
|
28
|
+
export declare class RequiredNode extends BaseConstraint<RequiredDeclaration, typeof RequiredNode> {
|
|
29
|
+
static implementation: nodeImplementationOf<RequiredDeclaration>;
|
|
30
|
+
readonly impliedBasis: import("../../types/domain.js").DomainNode<object>;
|
|
31
|
+
readonly serializedKey: string;
|
|
32
|
+
readonly compiledKey: string;
|
|
33
|
+
readonly expression: string;
|
|
34
|
+
readonly errorContext: Readonly<{
|
|
35
|
+
code: "required";
|
|
36
|
+
description: string;
|
|
37
|
+
key: string | symbol;
|
|
38
|
+
}>;
|
|
39
|
+
traverseAllows: TraverseAllows<object>;
|
|
40
|
+
traverseApply: TraverseApply<object>;
|
|
41
|
+
compile(js: NodeCompiler): void;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=required.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required.d.ts","sourceRoot":"","sources":["../../../constraints/props/required.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAEpE,OAAO,KAAK,EAEX,QAAQ,EACR,oBAAoB,EACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC/C,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAC1B;AAED,MAAM,WAAW,aAAc,SAAQ,QAAQ;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;CAC9B;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC;IAC7C,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,cAAc,CAAA;IACtB,gBAAgB,EAAE,cAAc,CAAA;IAChC,KAAK,EAAE,aAAa,CAAA;IACpB,YAAY,EAAE;QACb,IAAI,EAAE,UAAU,CAAA;QAChB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KACpB,CAAA;IACD,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,IAAI,CAAA;IACxB,SAAS,EAAE,QAAQ,CAAA;CACnB,CAAC,CAAA;AAoBF,qBAAa,YAAa,SAAQ,cAAc,CAC/C,mBAAmB,EACnB,OAAO,YAAY,CACnB;IACA,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC,mBAAmB,CAAC,CAyB7D;IAEH,QAAQ,CAAC,YAAY,qDAA2B;IAChD,QAAQ,CAAC,aAAa,SAAmC;IACzD,QAAQ,CAAC,WAAW,SACyC;IAC7D,QAAQ,CAAC,UAAU,SAAuC;IAE1D,QAAQ,CAAC,YAAY;;;;OAInB;IAEF,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,CAKrC;IAED,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAMnC;IAED,OAAO,CAAC,EAAE,EAAE,YAAY;CAYxB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { compileSerializedValue } from "@arktype/util";
|
|
2
|
+
import { Disjoint } from "../../shared/disjoint.js";
|
|
3
|
+
import { BaseConstraint } from "../constraint.js";
|
|
4
|
+
const intersectNamed = (l, r, $) => {
|
|
5
|
+
if (l.key !== r.key) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const key = l.key;
|
|
9
|
+
const value = l.value.intersect(r.value);
|
|
10
|
+
if (value instanceof Disjoint) {
|
|
11
|
+
return value.withPrefixKey(l.compiledKey);
|
|
12
|
+
}
|
|
13
|
+
return $.parse("required", {
|
|
14
|
+
key,
|
|
15
|
+
value
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export class RequiredNode extends BaseConstraint {
|
|
19
|
+
static implementation = this.implement({
|
|
20
|
+
hasAssociatedError: true,
|
|
21
|
+
intersectionIsOpen: true,
|
|
22
|
+
keys: {
|
|
23
|
+
key: {},
|
|
24
|
+
value: {
|
|
25
|
+
child: true,
|
|
26
|
+
parse: (schema, ctx) => ctx.$.parseTypeNode(schema)
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
normalize: (schema) => schema,
|
|
30
|
+
defaults: {
|
|
31
|
+
description(node) {
|
|
32
|
+
return `${node.compiledKey}: ${node.value.description}`;
|
|
33
|
+
},
|
|
34
|
+
expected() {
|
|
35
|
+
return "provided";
|
|
36
|
+
},
|
|
37
|
+
actual: () => null
|
|
38
|
+
},
|
|
39
|
+
intersections: {
|
|
40
|
+
required: intersectNamed,
|
|
41
|
+
optional: intersectNamed
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
impliedBasis = this.$.tsKeywords.object;
|
|
45
|
+
serializedKey = compileSerializedValue(this.key);
|
|
46
|
+
compiledKey = typeof this.key === "string" ? this.key : this.serializedKey;
|
|
47
|
+
expression = `${this.compiledKey}: ${this.value}`;
|
|
48
|
+
errorContext = Object.freeze({
|
|
49
|
+
code: "required",
|
|
50
|
+
description: this.description,
|
|
51
|
+
key: this.key
|
|
52
|
+
});
|
|
53
|
+
traverseAllows = (data, ctx) => {
|
|
54
|
+
if (this.key in data) {
|
|
55
|
+
return this.value.traverseAllows(data[this.key], ctx);
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
traverseApply = (data, ctx) => {
|
|
60
|
+
if (this.key in data) {
|
|
61
|
+
this.value.traverseApply(data[this.key], ctx);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
ctx.error(this.errorContext);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
compile(js) {
|
|
68
|
+
js.if(`${this.serializedKey} in ${js.data}`, () => js.checkLiteralKey(this.key, this.value)).else(() => js.traversalKind === "Allows"
|
|
69
|
+
? js.return(false)
|
|
70
|
+
: js.line(`${js.ctx}.error(${JSON.stringify(this.errorContext)})`));
|
|
71
|
+
if (js.traversalKind === "Allows") {
|
|
72
|
+
js.return(true);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=required.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required.js","sourceRoot":"","sources":["../../../constraints/props/required.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAKtD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAMnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AA0BjD,MAAM,cAAc,GAGhB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;IACf,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC;QACrB,OAAO,IAAI,CAAA;IACZ,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,CAAA;IACjB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACxC,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;IAC1C,CAAC;IACD,OAAO,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;QAC1B,GAAG;QACH,KAAK;KACL,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,OAAO,YAAa,SAAQ,cAGjC;IACA,MAAM,CAAC,cAAc,GACpB,IAAI,CAAC,SAAS,CAAC;QACd,kBAAkB,EAAE,IAAI;QACxB,kBAAk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AC,cAAc,CAAE,IAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;QAC/D,CAAC;QACD,OAAO,KAAK,CAAA;IACb,CAAC,CAAA;IAED,aAAa,GAA0B,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QACpD,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAE,IAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;QACvD,CAAC;aAAM,CAAC;YACP,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC7B,CAAC;IACF,CAAC,CAAA;IAED,OAAO,CAAC,EAAgB;QACvB,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CACjD,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CACxC,CAAC,IAAI,CAAC,GAAG,EAAE,CACX,EAAE,CAAC,aAAa,KAAK,QAAQ;YAC5B,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;YAClB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,UAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CACnE,CAAA;QACD,IAAI,EAAE,CAAC,aAAa,KAAK,QAAQ,EAAE,CAAC;YACnC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC;IACF,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type array, type satisfy } from "@arktype/util";
|
|
2
|
+
import type { TypeSchema } from "../../base.js";
|
|
3
|
+
import type { NodeCompiler } from "../../shared/compile.js";
|
|
4
|
+
import type { BaseMeta, declareNode } from "../../shared/declare.js";
|
|
5
|
+
import type { TypeKind, nodeImplementationOf } from "../../shared/implement.js";
|
|
6
|
+
import type { TraverseAllows, TraverseApply } from "../../shared/traversal.js";
|
|
7
|
+
import type { Type } from "../../types/type.js";
|
|
8
|
+
import { BaseConstraint } from "../constraint.js";
|
|
9
|
+
export interface NormalizedSequenceSchema extends BaseMeta {
|
|
10
|
+
readonly prefix?: readonly TypeSchema[];
|
|
11
|
+
readonly optionals?: readonly TypeSchema[];
|
|
12
|
+
readonly variadic?: TypeSchema;
|
|
13
|
+
readonly minVariadicLength?: number;
|
|
14
|
+
readonly postfix?: readonly TypeSchema[];
|
|
15
|
+
}
|
|
16
|
+
export type SequenceSchema = NormalizedSequenceSchema | TypeSchema;
|
|
17
|
+
export interface SequenceInner extends BaseMeta {
|
|
18
|
+
readonly prefix?: readonly Type[];
|
|
19
|
+
readonly optionals?: readonly Type[];
|
|
20
|
+
readonly variadic?: Type;
|
|
21
|
+
readonly minVariadicLength?: number;
|
|
22
|
+
readonly postfix?: readonly Type[];
|
|
23
|
+
}
|
|
24
|
+
export type SequenceDeclaration = declareNode<{
|
|
25
|
+
kind: "sequence";
|
|
26
|
+
schema: SequenceSchema;
|
|
27
|
+
normalizedSchema: NormalizedSequenceSchema;
|
|
28
|
+
inner: SequenceInner;
|
|
29
|
+
prerequisite: array;
|
|
30
|
+
reducibleTo: "sequence";
|
|
31
|
+
childKind: TypeKind;
|
|
32
|
+
}>;
|
|
33
|
+
export declare class SequenceNode extends BaseConstraint<SequenceDeclaration> {
|
|
34
|
+
static implementation: nodeImplementationOf<SequenceDeclaration>;
|
|
35
|
+
readonly impliedBasis: Type<unknown[], import("../../keywords/jsObject.js").jsObject.exports>;
|
|
36
|
+
readonly prefix: readonly Type<any, any>[];
|
|
37
|
+
readonly optionals: readonly Type<any, any>[];
|
|
38
|
+
readonly prevariadic: Type<any, any>[];
|
|
39
|
+
readonly postfix: readonly Type<any, any>[];
|
|
40
|
+
readonly isVariadicOnly: boolean;
|
|
41
|
+
readonly minVariadicLength: number;
|
|
42
|
+
readonly minLength: number;
|
|
43
|
+
readonly minLengthNode: import("../refinements/minLength.js").MinLengthNode | undefined;
|
|
44
|
+
readonly maxLength: number | undefined;
|
|
45
|
+
readonly maxLengthNode: import("../refinements/maxLength.js").MaxLengthNode | undefined;
|
|
46
|
+
readonly impliedSiblings: (import("../refinements/minLength.js").MinLengthNode | import("../refinements/maxLength.js").MaxLengthNode)[] | undefined;
|
|
47
|
+
protected childAtIndex(data: array, index: number): Type;
|
|
48
|
+
traverseAllows: TraverseAllows<array>;
|
|
49
|
+
traverseApply: TraverseApply<array>;
|
|
50
|
+
compile(js: NodeCompiler): void;
|
|
51
|
+
readonly tuple: SequenceTuple;
|
|
52
|
+
readonly expression: string;
|
|
53
|
+
}
|
|
54
|
+
export declare const postfixFollowingOptionalMessage = "A postfix required element cannot follow an optional element";
|
|
55
|
+
export type postfixFollowingOptionalMessage = typeof postfixFollowingOptionalMessage;
|
|
56
|
+
export declare const postfixWithoutVariadicMessage = "A postfix element requires a variadic element";
|
|
57
|
+
export type postfixWithoutVariadicMessage = typeof postfixWithoutVariadicMessage;
|
|
58
|
+
export type SequenceElementKind = satisfy<keyof SequenceInner, "prefix" | "optionals" | "variadic" | "postfix">;
|
|
59
|
+
export type SequenceElement = {
|
|
60
|
+
kind: SequenceElementKind;
|
|
61
|
+
node: Type;
|
|
62
|
+
};
|
|
63
|
+
export type SequenceTuple = array<SequenceElement>;
|
|
64
|
+
//# sourceMappingURL=sequence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../../constraints/props/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,KAAK,EAEV,KAAK,OAAO,EACZ,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,C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