arktype 2.0.0-dev.3 → 2.0.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/array.test.ts +123 -215
- package/__tests__/badDefinitionType.test.ts +2 -2
- package/__tests__/bounds.test.ts +448 -349
- package/__tests__/config.test.ts +8 -6
- package/__tests__/cyclic.test.ts +1 -1
- package/__tests__/dateLiteral.test.ts +2 -2
- package/__tests__/discrimination.test.ts +1 -1
- package/__tests__/divisor.test.ts +23 -19
- package/__tests__/enclosed.test.ts +7 -2
- package/__tests__/errors.test.ts +115 -0
- package/__tests__/expressions.test.ts +14 -20
- package/__tests__/generic.test.ts +4 -5
- package/__tests__/group.test.ts +8 -3
- package/__tests__/instanceof.test.ts +7 -7
- package/__tests__/intersection.test.ts +62 -38
- package/__tests__/keyTraversal.test.ts +0 -2
- package/__tests__/keyof.test.ts +15 -13
- package/__tests__/keywords.test.ts +29 -25
- package/__tests__/literal.test.ts +26 -8
- package/__tests__/match.test.ts +28 -16
- package/__tests__/morph.test.ts +187 -172
- package/__tests__/narrow.test.ts +38 -39
- package/__tests__/objectLiteral.test.ts +106 -76
- package/__tests__/realWorld.test.ts +62 -0
- package/__tests__/schema.bench.ts +14 -0
- package/__tests__/schema.test.ts +60 -0
- package/__tests__/scope.bench.ts +1 -1
- package/__tests__/scope.test.ts +8 -6
- package/__tests__/submodule.test.ts +2 -2
- package/__tests__/traverse.test.ts +34 -31
- package/__tests__/typeMethods.test.ts +2 -3
- package/__tests__/typeReference.test.ts +3 -3
- package/__tests__/unenclosed.test.ts +9 -3
- package/__tests__/union.test.ts +127 -55
- package/__tests__/unit.test.ts +61 -0
- package/base.ts +520 -0
- package/config.ts +25 -0
- package/constraints/ast.ts +288 -0
- package/constraints/constraint.ts +91 -0
- package/constraints/predicate.ts +102 -0
- package/constraints/props/index.ts +93 -0
- package/constraints/props/prop.ts +146 -0
- package/constraints/props/props.ts +148 -0
- package/constraints/props/sequence.ts +473 -0
- package/constraints/props/shared.ts +5 -0
- package/constraints/refinements/after.ts +68 -0
- package/constraints/refinements/before.ts +75 -0
- package/constraints/refinements/divisor.ts +76 -0
- package/constraints/refinements/exactLength.ts +75 -0
- package/constraints/refinements/kinds.ts +31 -0
- package/constraints/refinements/max.ts +61 -0
- package/constraints/refinements/maxLength.ts +66 -0
- package/constraints/refinements/min.ts +54 -0
- package/constraints/refinements/minLength.ts +63 -0
- package/constraints/refinements/range.ts +181 -0
- package/constraints/refinements/regex.ts +59 -0
- package/{ark.ts → keywords/ark.ts} +40 -30
- package/keywords/internal.ts +29 -0
- package/keywords/jsObject.ts +39 -0
- package/keywords/parsing.ts +87 -0
- package/keywords/root.ts +9 -0
- package/keywords/tsGenerics.ts +28 -0
- package/keywords/tsPrimitive.ts +52 -0
- package/keywords/utils/creditCard.ts +37 -0
- package/keywords/utils/date.ts +112 -0
- package/keywords/validation.ts +115 -0
- package/kinds.ts +115 -0
- package/main.ts +7 -8
- package/match.ts +30 -34
- package/out/ark.d.ts +5 -1
- package/out/ark.d.ts.map +1 -1
- package/out/ark.js +4 -1
- package/out/ark.js.map +1 -1
- package/out/base.d.ts +129 -0
- package/out/base.d.ts.map +1 -0
- package/out/base.js +274 -0
- package/out/base.js.map +1 -0
- package/out/builtins/builtins.d.ts +19 -0
- package/out/builtins/builtins.d.ts.map +1 -0
- package/out/builtins/builtins.js +12 -0
- package/out/builtins/builtins.js.map +1 -0
- package/out/builtins/jsObjects.d.ts +19 -0
- package/out/builtins/jsObjects.d.ts.map +1 -0
- package/out/builtins/jsObjects.js +15 -0
- package/out/builtins/jsObjects.js.map +1 -0
- package/out/builtins/parsing.d.ts +16 -0
- package/out/builtins/parsing.d.ts.map +1 -0
- package/out/builtins/parsing.js +59 -0
- package/out/builtins/parsing.js.map +1 -0
- package/out/builtins/tsGenerics.d.ts +2 -0
- package/out/builtins/tsGenerics.d.ts.map +1 -0
- package/out/builtins/tsGenerics.js +26 -0
- package/out/builtins/tsGenerics.js.map +1 -0
- package/out/builtins/tsKeywords.d.ts +23 -0
- package/out/builtins/tsKeywords.d.ts.map +1 -0
- package/out/builtins/tsKeywords.js +20 -0
- package/out/builtins/tsKeywords.js.map +1 -0
- package/out/builtins/utils/creditCard.d.ts +3 -0
- package/out/builtins/utils/creditCard.d.ts.map +1 -0
- package/out/builtins/utils/creditCard.js +36 -0
- package/out/builtins/utils/creditCard.js.map +1 -0
- package/out/builtins/utils/date.d.ts +22 -0
- package/out/builtins/utils/date.d.ts.map +1 -0
- package/out/builtins/utils/date.js +53 -0
- package/out/builtins/utils/date.js.map +1 -0
- package/out/builtins/validation.d.ts +19 -0
- package/out/builtins/validation.d.ts.map +1 -0
- package/out/builtins/validation.js +70 -0
- package/out/builtins/validation.js.map +1 -0
- package/out/config.d.ts +6 -0
- package/out/config.d.ts.map +1 -0
- package/out/config.js +17 -0
- package/out/config.js.map +1 -0
- package/out/constraints/ast.d.ts +176 -0
- package/out/constraints/ast.d.ts.map +1 -0
- package/out/constraints/ast.js +2 -0
- package/out/constraints/ast.js.map +1 -0
- package/out/constraints/constraint.d.ts +70 -0
- package/out/constraints/constraint.d.ts.map +1 -0
- package/out/constraints/constraint.js +21 -0
- package/out/constraints/constraint.js.map +1 -0
- package/out/constraints/predicate.d.ts +46 -0
- package/out/constraints/predicate.d.ts.map +1 -0
- package/out/constraints/predicate.js +47 -0
- package/out/constraints/predicate.js.map +1 -0
- package/out/constraints/props/index.d.ts +36 -0
- package/out/constraints/props/index.d.ts.map +1 -0
- package/out/constraints/props/index.js +48 -0
- package/out/constraints/props/index.js.map +1 -0
- package/out/constraints/props/optional.d.ts +34 -0
- package/out/constraints/props/optional.d.ts.map +1 -0
- package/out/constraints/props/optional.js +55 -0
- package/out/constraints/props/optional.js.map +1 -0
- package/out/constraints/props/prop.d.ts +46 -0
- package/out/constraints/props/prop.d.ts.map +1 -0
- package/out/constraints/props/prop.js +104 -0
- package/out/constraints/props/prop.js.map +1 -0
- package/out/constraints/props/props.d.ts +34 -0
- package/out/constraints/props/props.d.ts.map +1 -0
- package/out/constraints/props/props.js +106 -0
- package/out/constraints/props/props.js.map +1 -0
- package/out/constraints/props/required.d.ts +43 -0
- package/out/constraints/props/required.d.ts.map +1 -0
- package/out/constraints/props/required.js +76 -0
- package/out/constraints/props/required.js.map +1 -0
- package/out/constraints/props/sequence.d.ts +64 -0
- package/out/constraints/props/sequence.d.ts.map +1 -0
- package/out/constraints/props/sequence.js +327 -0
- package/out/constraints/props/sequence.js.map +1 -0
- package/out/constraints/props/shared.d.ts +3 -0
- package/out/constraints/props/shared.d.ts.map +1 -0
- package/out/constraints/props/shared.js +4 -0
- package/out/constraints/props/shared.js.map +1 -0
- package/out/constraints/refinements/after.d.ts +25 -0
- package/out/constraints/refinements/after.d.ts.map +1 -0
- package/out/constraints/refinements/after.js +35 -0
- package/out/constraints/refinements/after.js.map +1 -0
- package/out/constraints/refinements/before.d.ts +25 -0
- package/out/constraints/refinements/before.d.ts.map +1 -0
- package/out/constraints/refinements/before.js +41 -0
- package/out/constraints/refinements/before.js.map +1 -0
- package/out/constraints/refinements/divisor.d.ts +42 -0
- package/out/constraints/refinements/divisor.d.ts.map +1 -0
- package/out/constraints/refinements/divisor.js +41 -0
- package/out/constraints/refinements/divisor.js.map +1 -0
- package/out/constraints/refinements/exactLength.d.ts +41 -0
- package/out/constraints/refinements/exactLength.d.ts.map +1 -0
- package/out/constraints/refinements/exactLength.js +44 -0
- package/out/constraints/refinements/exactLength.js.map +1 -0
- package/out/constraints/refinements/kinds.d.ts +29 -0
- package/out/constraints/refinements/kinds.d.ts.map +1 -0
- package/out/constraints/refinements/kinds.js +17 -0
- package/out/constraints/refinements/kinds.js.map +1 -0
- package/out/constraints/refinements/length.d.ts +42 -0
- package/out/constraints/refinements/length.d.ts.map +1 -0
- package/out/constraints/refinements/length.js +45 -0
- package/out/constraints/refinements/length.js.map +1 -0
- package/out/constraints/refinements/max.d.ts +24 -0
- package/out/constraints/refinements/max.d.ts.map +1 -0
- package/out/constraints/refinements/max.js +31 -0
- package/out/constraints/refinements/max.js.map +1 -0
- package/out/constraints/refinements/maxLength.d.ts +24 -0
- package/out/constraints/refinements/maxLength.d.ts.map +1 -0
- package/out/constraints/refinements/maxLength.js +34 -0
- package/out/constraints/refinements/maxLength.js.map +1 -0
- package/out/constraints/refinements/min.d.ts +24 -0
- package/out/constraints/refinements/min.d.ts.map +1 -0
- package/out/constraints/refinements/min.js +25 -0
- package/out/constraints/refinements/min.js.map +1 -0
- package/out/constraints/refinements/minLength.d.ts +24 -0
- package/out/constraints/refinements/minLength.d.ts.map +1 -0
- package/out/constraints/refinements/minLength.js +32 -0
- package/out/constraints/refinements/minLength.js.map +1 -0
- package/out/constraints/refinements/range.d.ts +90 -0
- package/out/constraints/refinements/range.d.ts.map +1 -0
- package/out/constraints/refinements/range.js +72 -0
- package/out/constraints/refinements/range.js.map +1 -0
- package/out/constraints/refinements/regex.d.ts +43 -0
- package/out/constraints/refinements/regex.d.ts.map +1 -0
- package/out/constraints/refinements/regex.js +36 -0
- package/out/constraints/refinements/regex.js.map +1 -0
- package/out/constraints/refinements/shared.d.ts +5 -0
- package/out/constraints/refinements/shared.d.ts.map +1 -0
- package/out/constraints/refinements/shared.js +10 -0
- package/out/constraints/refinements/shared.js.map +1 -0
- package/out/inference.d.ts +40 -0
- package/out/inference.d.ts.map +1 -0
- package/out/inference.js +73 -0
- package/out/inference.js.map +1 -0
- package/out/keywords/ark.d.ts +60 -0
- package/out/keywords/ark.d.ts.map +1 -0
- package/out/keywords/ark.js +29 -0
- package/out/keywords/ark.js.map +1 -0
- package/out/keywords/internal.d.ts +13 -0
- package/out/keywords/internal.d.ts.map +1 -0
- package/out/keywords/internal.js +10 -0
- package/out/keywords/internal.js.map +1 -0
- package/out/keywords/jsObject.d.ts +20 -0
- package/out/keywords/jsObject.d.ts.map +1 -0
- package/out/keywords/jsObject.js +15 -0
- package/out/keywords/jsObject.js.map +1 -0
- package/out/keywords/parsing.d.ts +17 -0
- package/out/keywords/parsing.d.ts.map +1 -0
- package/out/keywords/parsing.js +61 -0
- package/out/keywords/parsing.js.map +1 -0
- package/out/keywords/root.d.ts +7 -0
- package/out/keywords/root.d.ts.map +1 -0
- package/out/keywords/root.js +4 -0
- package/out/keywords/root.js.map +1 -0
- package/out/keywords/tsGenerics.d.ts +2 -0
- package/out/keywords/tsGenerics.d.ts.map +1 -0
- package/out/keywords/tsGenerics.js +26 -0
- package/out/keywords/tsGenerics.js.map +1 -0
- package/out/keywords/tsPrimitive.d.ts +24 -0
- package/out/keywords/tsPrimitive.d.ts.map +1 -0
- package/out/keywords/tsPrimitive.js +22 -0
- package/out/keywords/tsPrimitive.js.map +1 -0
- package/out/keywords/utils/creditCard.d.ts +8 -0
- package/out/keywords/utils/creditCard.d.ts.map +1 -0
- package/out/keywords/utils/creditCard.js +36 -0
- package/out/keywords/utils/creditCard.js.map +1 -0
- package/out/keywords/utils/date.d.ts +25 -0
- package/out/keywords/utils/date.d.ts.map +1 -0
- package/out/keywords/utils/date.js +53 -0
- package/out/keywords/utils/date.js.map +1 -0
- package/out/keywords/validation.d.ts +20 -0
- package/out/keywords/validation.d.ts.map +1 -0
- package/out/keywords/validation.js +76 -0
- package/out/keywords/validation.js.map +1 -0
- package/out/kinds.d.ts +72 -0
- package/out/kinds.d.ts.map +1 -0
- package/out/kinds.js +29 -0
- package/out/kinds.js.map +1 -0
- package/out/main.d.ts +5 -4
- package/out/main.d.ts.map +1 -1
- package/out/main.js +2 -3
- package/out/main.js.map +1 -1
- package/out/match.d.ts +17 -18
- package/out/match.d.ts.map +1 -1
- package/out/match.js +3 -4
- package/out/match.js.map +1 -1
- package/out/parse.d.ts +23 -0
- package/out/parse.d.ts.map +1 -0
- package/out/parse.js +148 -0
- package/out/parse.js.map +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/definition.d.ts.map +1 -1
- package/out/parser/definition.js +8 -9
- package/out/parser/definition.js.map +1 -1
- package/out/parser/objectLiteral.d.ts +44 -11
- package/out/parser/objectLiteral.d.ts.map +1 -1
- package/out/parser/objectLiteral.js +47 -35
- package/out/parser/objectLiteral.js.map +1 -1
- package/out/parser/semantic/bounds.d.ts +8 -6
- package/out/parser/semantic/bounds.d.ts.map +1 -1
- package/out/parser/semantic/bounds.js.map +1 -1
- package/out/parser/semantic/divisor.d.ts +4 -6
- package/out/parser/semantic/divisor.d.ts.map +1 -1
- package/out/parser/semantic/infer.d.ts +28 -0
- package/out/parser/semantic/infer.d.ts.map +1 -0
- package/out/parser/semantic/infer.js +2 -0
- package/out/parser/semantic/infer.js.map +1 -0
- package/out/parser/semantic/utils.d.ts +3 -6
- package/out/parser/semantic/utils.d.ts.map +1 -1
- package/out/parser/semantic/validate.d.ts +1 -1
- package/out/parser/semantic/validate.d.ts.map +1 -1
- package/out/parser/semantic/validate.js.map +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -11
- package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
- package/out/parser/string/reduce/dynamic.js +15 -9
- package/out/parser/string/reduce/dynamic.js.map +1 -1
- package/out/parser/string/reduce/shared.d.ts +2 -3
- package/out/parser/string/reduce/shared.d.ts.map +1 -1
- package/out/parser/string/reduce/shared.js.map +1 -1
- package/out/parser/string/reduce/static.d.ts +20 -19
- package/out/parser/string/reduce/static.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.d.ts +3 -2
- package/out/parser/string/shift/operand/date.d.ts.map +1 -1
- package/out/parser/string/shift/operand/date.js.map +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts +1 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/enclosed.js +6 -4
- package/out/parser/string/shift/operand/enclosed.js.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
- package/out/parser/string/shift/operand/operand.d.ts +2 -2
- package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
- package/out/parser/string/shift/operand/operand.js.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts +5 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
- package/out/parser/string/shift/operand/unenclosed.js +5 -5
- package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
- package/out/parser/string/shift/operator/bounds.d.ts +17 -12
- package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
- package/out/parser/string/shift/operator/bounds.js +28 -25
- package/out/parser/string/shift/operator/bounds.js.map +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts +1 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
- package/out/parser/string/shift/operator/divisor.js.map +1 -1
- package/out/parser/string/shift/scanner.d.ts.map +1 -1
- package/out/parser/string/string.d.ts +3 -3
- package/out/parser/string/string.d.ts.map +1 -1
- package/out/parser/string/string.js.map +1 -1
- package/out/parser/tuple.d.ts +95 -33
- package/out/parser/tuple.d.ts.map +1 -1
- package/out/parser/tuple.js +45 -48
- package/out/parser/tuple.js.map +1 -1
- package/out/schema.d.ts +44 -0
- package/out/schema.d.ts.map +1 -0
- package/out/schema.js +73 -0
- package/out/schema.js.map +1 -0
- package/out/schemaScope.d.ts +110 -0
- package/out/schemaScope.d.ts.map +1 -0
- package/out/schemaScope.js +212 -0
- package/out/schemaScope.js.map +1 -0
- package/out/scope.d.ts +98 -26
- package/out/scope.d.ts.map +1 -1
- package/out/scope.js +185 -45
- package/out/scope.js.map +1 -1
- package/out/shared/compile.d.ts +22 -0
- package/out/shared/compile.d.ts.map +1 -0
- package/out/shared/compile.js +67 -0
- package/out/shared/compile.js.map +1 -0
- package/out/shared/context.d.ts +29 -0
- package/out/shared/context.d.ts.map +1 -0
- package/out/shared/context.js +48 -0
- package/out/shared/context.js.map +1 -0
- package/out/shared/declare.d.ts +53 -0
- package/out/shared/declare.d.ts.map +1 -0
- package/out/shared/declare.js +2 -0
- package/out/shared/declare.js.map +1 -0
- package/out/shared/disjoint.d.ts +79 -0
- package/out/shared/disjoint.d.ts.map +1 -0
- package/out/shared/disjoint.js +82 -0
- package/out/shared/disjoint.js.map +1 -0
- package/out/shared/errors.d.ts +59 -0
- package/out/shared/errors.d.ts.map +1 -0
- package/out/shared/errors.js +108 -0
- package/out/shared/errors.js.map +1 -0
- package/out/shared/implement.d.ts +170 -0
- package/out/shared/implement.d.ts.map +1 -0
- package/out/shared/implement.js +69 -0
- package/out/shared/implement.js.map +1 -0
- package/out/shared/inference.d.ts +6 -0
- package/out/shared/inference.d.ts.map +1 -0
- package/out/shared/inference.js +5 -0
- package/out/shared/inference.js.map +1 -0
- package/out/shared/intersections.d.ts +15 -0
- package/out/shared/intersections.d.ts.map +1 -0
- package/out/shared/intersections.js.map +1 -0
- package/out/shared/traversal.d.ts +44 -0
- package/out/shared/traversal.d.ts.map +1 -0
- package/out/shared/traversal.js +97 -0
- package/out/shared/traversal.js.map +1 -0
- package/out/shared/utils.d.ts +8 -0
- package/out/shared/utils.d.ts.map +1 -0
- package/out/shared/utils.js +10 -0
- package/out/shared/utils.js.map +1 -0
- package/out/type.d.ts +10 -38
- package/out/type.d.ts.map +1 -1
- package/out/type.js +20 -106
- package/out/type.js.map +1 -1
- package/out/types/basis.d.ts +24 -0
- package/out/types/basis.d.ts.map +1 -0
- package/out/types/basis.js +15 -0
- package/out/types/basis.js.map +1 -0
- package/out/types/discriminate.d.ts +20 -0
- package/out/types/discriminate.d.ts.map +1 -0
- package/out/types/discriminate.js +114 -0
- package/out/types/discriminate.js.map +1 -0
- package/out/types/domain.d.ts +40 -0
- package/out/types/domain.d.ts.map +1 -0
- package/out/types/domain.js +38 -0
- package/out/types/domain.js.map +1 -0
- package/out/types/intersection.d.ts +67 -0
- package/out/types/intersection.d.ts.map +1 -0
- package/out/types/intersection.js +350 -0
- package/out/types/intersection.js.map +1 -0
- package/out/types/morph.d.ts +79 -0
- package/out/types/morph.d.ts.map +1 -0
- package/out/types/morph.js +95 -0
- package/out/types/morph.js.map +1 -0
- package/out/types/proto.d.ts +42 -0
- package/out/types/proto.d.ts.map +1 -0
- package/out/types/proto.js +48 -0
- package/out/types/proto.js.map +1 -0
- package/out/types/type.d.ts +61 -0
- package/out/types/type.d.ts.map +1 -0
- package/out/types/type.js +111 -0
- package/out/types/type.js.map +1 -0
- package/out/types/union.d.ts +48 -0
- package/out/types/union.d.ts.map +1 -0
- package/out/types/union.js +337 -0
- package/out/types/union.js.map +1 -0
- package/out/types/unit.d.ts +40 -0
- package/out/types/unit.d.ts.map +1 -0
- package/out/types/unit.js +48 -0
- package/out/types/unit.js.map +1 -0
- package/out/util.d.ts +5 -2
- package/out/util.d.ts.map +1 -1
- package/out/util.js.map +1 -1
- package/package.json +6 -3
- package/parse.ts +221 -0
- package/parser/definition.ts +24 -23
- package/parser/objectLiteral.ts +128 -88
- package/parser/semantic/bounds.ts +18 -9
- package/parser/semantic/divisor.ts +12 -10
- package/parser/semantic/infer.ts +152 -0
- package/parser/semantic/utils.ts +5 -13
- package/parser/semantic/validate.ts +1 -2
- package/parser/string/reduce/dynamic.ts +42 -30
- package/parser/string/reduce/shared.ts +1 -3
- package/parser/string/reduce/static.ts +22 -22
- package/parser/string/shift/operand/date.ts +9 -5
- package/parser/string/shift/operand/enclosed.ts +11 -5
- package/parser/string/shift/operand/genericArgs.ts +6 -6
- package/parser/string/shift/operand/operand.ts +1 -2
- package/parser/string/shift/operand/unenclosed.ts +14 -20
- package/parser/string/shift/operator/bounds.ts +59 -54
- package/parser/string/shift/operator/divisor.ts +2 -2
- package/parser/string/shift/scanner.ts +10 -10
- package/parser/string/string.ts +4 -4
- package/parser/tuple.ts +224 -202
- package/schema.ts +263 -0
- package/scope.ts +358 -81
- package/shared/compile.ts +92 -0
- package/shared/declare.ts +75 -0
- package/shared/disjoint.ts +203 -0
- package/shared/errors.ts +204 -0
- package/shared/implement.ts +327 -0
- package/shared/inference.ts +9 -0
- package/shared/intersections.ts +53 -0
- package/shared/traversal.ts +146 -0
- package/shared/utils.ts +30 -0
- package/type.ts +23 -183
- package/types/basis.ts +62 -0
- package/types/discriminate.ts +168 -0
- package/types/domain.ts +79 -0
- package/types/intersection.ts +539 -0
- package/types/morph.ts +263 -0
- package/types/proto.ts +89 -0
- package/types/type.ts +319 -0
- package/types/union.ts +451 -0
- package/types/unit.ts +78 -0
- package/util.ts +5 -2
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -32
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/shared.d.ts +0 -62
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -56
- package/out/parser/shared.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/parser/semantic/semantic.ts +0 -143
- package/parser/shared.ts +0 -170
- /package/out/{parser/semantic → shared}/intersections.js +0 -0
package/__tests__/config.test.ts
CHANGED
|
@@ -13,11 +13,11 @@ describe("config traversal", () => {
|
|
|
13
13
|
attest<string>(types.a.infer)
|
|
14
14
|
attest(types.a.description).equals(description)
|
|
15
15
|
attest(types.a(1).errors?.summary).snap(
|
|
16
|
-
"
|
|
16
|
+
"must be a series of characters (was number)"
|
|
17
17
|
)
|
|
18
18
|
attest<{ a: string }>(types.b.infer)
|
|
19
19
|
attest(types.b({ a: true }).errors?.summary).snap(
|
|
20
|
-
"a must be a series of characters (was
|
|
20
|
+
"a must be a series of characters (was true)"
|
|
21
21
|
)
|
|
22
22
|
})
|
|
23
23
|
it("tuple expression at path", () => {
|
|
@@ -26,7 +26,9 @@ describe("config traversal", () => {
|
|
|
26
26
|
monster: ["196883", "@", description]
|
|
27
27
|
})
|
|
28
28
|
attest<{ monster: 196883 }>(t.infer)
|
|
29
|
-
attest(t.description).
|
|
29
|
+
attest(t.description).snap(
|
|
30
|
+
"{ monster: the number of dimensions in the monster group }"
|
|
31
|
+
)
|
|
30
32
|
attest(t({ monster: 196882 }).errors?.summary).snap(
|
|
31
33
|
"monster must be the number of dimensions in the monster group (was 196882)"
|
|
32
34
|
)
|
|
@@ -34,7 +36,7 @@ describe("config traversal", () => {
|
|
|
34
36
|
it("anonymous type config", () => {
|
|
35
37
|
const t = type(type("true", "@", { description: "unfalse" }))
|
|
36
38
|
attest<true>(t.infer)
|
|
37
|
-
attest(t(false).errors?.summary).snap("
|
|
39
|
+
attest(t(false).errors?.summary).snap("must be unfalse (was false)")
|
|
38
40
|
})
|
|
39
41
|
it("anonymous type config at path", () => {
|
|
40
42
|
const unfalse = type("true", "@", { description: "unfalse" })
|
|
@@ -69,9 +71,9 @@ describe("config traversal", () => {
|
|
|
69
71
|
name: "david",
|
|
70
72
|
age: true
|
|
71
73
|
}).errors?.summary
|
|
72
|
-
).snap("age must be a number (was
|
|
74
|
+
).snap("age must be a number (was true)")
|
|
73
75
|
|
|
74
76
|
// should give the shallow custom error
|
|
75
|
-
attest(user(null).errors?.summary).snap("
|
|
77
|
+
attest(user(null).errors?.summary).snap("must be a valid user (was null)")
|
|
76
78
|
})
|
|
77
79
|
})
|
package/__tests__/cyclic.test.ts
CHANGED
|
@@ -97,7 +97,7 @@ describe("cyclic", () => {
|
|
|
97
97
|
(p) => !p.dependencies?.some((d) => d.name === p.name)
|
|
98
98
|
])
|
|
99
99
|
attest(nonSelfDependent(data).errors?.summary).snap(
|
|
100
|
-
'
|
|
100
|
+
'must be valid (was {"name":"arktype","dependencies":[{"name":"typescript"},"(cycle)"],"contributors":[{"email":"david@arktype.io"}]})'
|
|
101
101
|
)
|
|
102
102
|
})
|
|
103
103
|
|
|
@@ -8,7 +8,7 @@ describe("date literal", () => {
|
|
|
8
8
|
attest<Date>(t.infer)
|
|
9
9
|
attest(t.allows(new Date("2000/05/05"))).equals(true)
|
|
10
10
|
attest(t.allows(new Date("2000/06/05"))).equals(false)
|
|
11
|
-
attest(t.allows(new Date("2000
|
|
11
|
+
attest(t.allows(new Date("2000-05-05T09:00:00.000Z"))).equals(false)
|
|
12
12
|
})
|
|
13
13
|
it("with punctuation", () => {
|
|
14
14
|
const ISO = type("d'2000-05-05T04:00:00.000Z'")
|
|
@@ -24,7 +24,7 @@ describe("date literal", () => {
|
|
|
24
24
|
const now = new Date()
|
|
25
25
|
const t = type(`d'${now.valueOf()}'`)
|
|
26
26
|
attest(t.allows(now)).equals(true)
|
|
27
|
-
attest(t.allows(new Date(now.valueOf() + 1)))
|
|
27
|
+
attest(t.allows(new Date(now.valueOf() + 1))).equals(false)
|
|
28
28
|
})
|
|
29
29
|
it("invalid date", () => {
|
|
30
30
|
attest(() => type("d'tuesday'")).throws(writeInvalidDateMessage("tuesday"))
|
|
@@ -52,7 +52,7 @@ describe("discrimination", () => {
|
|
|
52
52
|
// duration: "'s' | 'min' | 'h'",
|
|
53
53
|
// operator: "'to'"
|
|
54
54
|
// })
|
|
55
|
-
// attest(t.
|
|
55
|
+
// attest(t.hasKind("union") && t.discriminant).equals(null)
|
|
56
56
|
// })
|
|
57
57
|
// it("default case", () => {
|
|
58
58
|
// const t = getPlaces().type([
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { attest } from "@arktype/attest"
|
|
2
|
-
import { writeIndivisibleMessage } from "@arktype/schema"
|
|
3
2
|
import { type } from "arktype"
|
|
3
|
+
import { writeIndivisibleMessage } from "../constraints/refinements/divisor.js"
|
|
4
|
+
import { keywords } from "../keywords/ark.js"
|
|
4
5
|
import { writeInvalidDivisorMessage } from "../parser/string/shift/operator/divisor.js"
|
|
5
6
|
|
|
6
7
|
describe("divisibility", () => {
|
|
@@ -8,22 +9,25 @@ describe("divisibility", () => {
|
|
|
8
9
|
it("integer literal", () => {
|
|
9
10
|
const divisibleByTwo = type("number%2")
|
|
10
11
|
attest<number>(divisibleByTwo.infer)
|
|
11
|
-
attest(divisibleByTwo.json).snap({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
12
|
+
attest(divisibleByTwo.json).snap({ domain: "number", divisor: 2 })
|
|
13
|
+
})
|
|
14
|
+
it("chained", () => {
|
|
15
|
+
const t = type("number").constrain("divisor", 2)
|
|
16
|
+
const expected = type("number%2")
|
|
17
|
+
attest<typeof expected>(t)
|
|
18
|
+
attest(t.json).equals(expected.json)
|
|
16
19
|
})
|
|
17
20
|
it("whitespace after %", () => {
|
|
18
21
|
const t = type("number % 5")
|
|
19
22
|
attest<number>(t.infer)
|
|
20
|
-
attest(t.json).snap({
|
|
21
|
-
})
|
|
22
|
-
it("with
|
|
23
|
-
const t = type("number%8<
|
|
24
|
-
|
|
25
|
-
attest(t.
|
|
26
|
-
|
|
23
|
+
attest(t.json).snap({ domain: "number", divisor: 5 })
|
|
24
|
+
})
|
|
25
|
+
it("with bounds", () => {
|
|
26
|
+
const t = type("7<number%8<222")
|
|
27
|
+
const expected = type("number%8").and("7<number<222")
|
|
28
|
+
attest(t.json).equals(expected.json)
|
|
29
|
+
attest(t.description).snap(
|
|
30
|
+
"a number and a multiple of 8 and less than 222 and more than 7"
|
|
27
31
|
)
|
|
28
32
|
})
|
|
29
33
|
it("allows non-narrowed divisor", () => {
|
|
@@ -48,20 +52,20 @@ describe("divisibility", () => {
|
|
|
48
52
|
it("unknown", () => {
|
|
49
53
|
// @ts-expect-error
|
|
50
54
|
attest(() => type("unknown%2")).throwsAndHasTypeError(
|
|
51
|
-
writeIndivisibleMessage(
|
|
55
|
+
writeIndivisibleMessage(keywords.unknown)
|
|
52
56
|
)
|
|
53
57
|
})
|
|
54
58
|
it("indivisible", () => {
|
|
55
59
|
// @ts-expect-error
|
|
56
60
|
attest(() => type("string%1")).throwsAndHasTypeError(
|
|
57
|
-
writeIndivisibleMessage(
|
|
61
|
+
writeIndivisibleMessage(keywords.string)
|
|
58
62
|
)
|
|
59
63
|
})
|
|
60
64
|
it("overlapping", () => {
|
|
61
65
|
// @ts-expect-error
|
|
62
|
-
attest(() => type("(number|string)%10"))
|
|
63
|
-
.
|
|
64
|
-
|
|
66
|
+
attest(() => type("(number|string)%10")).throwsAndHasTypeError(
|
|
67
|
+
writeIndivisibleMessage(keywords.number.or(keywords.string))
|
|
68
|
+
)
|
|
65
69
|
})
|
|
66
70
|
})
|
|
67
71
|
describe("intersection", () => {
|
|
@@ -87,7 +91,7 @@ describe("divisibility", () => {
|
|
|
87
91
|
})
|
|
88
92
|
it("invalid literal", () => {
|
|
89
93
|
attest(() => type("number%3&8")).throws.snap(
|
|
90
|
-
"
|
|
94
|
+
"ParseError: Intersection of 8 and number & % 3 results in an unsatisfiable type"
|
|
91
95
|
)
|
|
92
96
|
})
|
|
93
97
|
})
|
|
@@ -11,7 +11,10 @@ describe("parse enclosed", () => {
|
|
|
11
11
|
it("with neighbors", () => {
|
|
12
12
|
const t = type("'foo'|/.*/[]")
|
|
13
13
|
attest<"foo" | string[]>(t.infer)
|
|
14
|
-
attest(t.json).snap([
|
|
14
|
+
attest(t.json).snap([
|
|
15
|
+
{ proto: "Array", sequence: { domain: "string", regex: [".*"] } },
|
|
16
|
+
{ unit: "foo" }
|
|
17
|
+
])
|
|
15
18
|
})
|
|
16
19
|
describe("errors", () => {
|
|
17
20
|
describe("unterminated", () => {
|
|
@@ -36,7 +39,9 @@ describe("parse enclosed", () => {
|
|
|
36
39
|
})
|
|
37
40
|
})
|
|
38
41
|
it("single-quoted", () => {
|
|
39
|
-
|
|
42
|
+
const t = type("'hello'")
|
|
43
|
+
attest<"hello">(t.infer)
|
|
44
|
+
attest(t.json).snap({ unit: "hello" })
|
|
40
45
|
})
|
|
41
46
|
it("double-quoted", () => {
|
|
42
47
|
attest<"goodbye">(type('"goodbye"').infer)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { attest } from "@arktype/attest"
|
|
2
|
+
import { scope } from "arktype"
|
|
3
|
+
import { configure } from "../config.js"
|
|
4
|
+
import { node } from "../keywords/ark.js"
|
|
5
|
+
import { defaultConfig } from "../scope.js"
|
|
6
|
+
|
|
7
|
+
describe("errors", () => {
|
|
8
|
+
it("shallow", () => {
|
|
9
|
+
const n = node({
|
|
10
|
+
domain: "number",
|
|
11
|
+
divisor: 3
|
|
12
|
+
})
|
|
13
|
+
attest(n(6)).snap({ data: 6, out: 6 })
|
|
14
|
+
attest(n(7).errors?.summary).snap("must be a multiple of 3 (was 7)")
|
|
15
|
+
})
|
|
16
|
+
it("at path", () => {
|
|
17
|
+
const o = node({
|
|
18
|
+
domain: "object",
|
|
19
|
+
prop: {
|
|
20
|
+
key: "foo",
|
|
21
|
+
value: {
|
|
22
|
+
domain: "number",
|
|
23
|
+
divisor: 3
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
attest(o({ foo: 6 }).out).snap({ foo: 6 })
|
|
28
|
+
attest(o({ foo: 7 }).errors?.summary).snap(
|
|
29
|
+
"foo must be a multiple of 3 (was 7)"
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
it("array", () => {
|
|
33
|
+
const t = node({
|
|
34
|
+
proto: Array,
|
|
35
|
+
sequence: "number"
|
|
36
|
+
})
|
|
37
|
+
attest(t([5]).out).snap([5])
|
|
38
|
+
attest(t([5, "five"]).errors?.summary).snap(
|
|
39
|
+
"value at [1] must be a number (was string)"
|
|
40
|
+
)
|
|
41
|
+
})
|
|
42
|
+
it("custom description integrated with error", () => {
|
|
43
|
+
const superSpecialBigint = node({
|
|
44
|
+
domain: "bigint",
|
|
45
|
+
description: "my special bigint"
|
|
46
|
+
})
|
|
47
|
+
attest(superSpecialBigint.description).snap("my special bigint")
|
|
48
|
+
attest(superSpecialBigint(5).errors?.summary).snap(
|
|
49
|
+
"must be my special bigint (was number)"
|
|
50
|
+
)
|
|
51
|
+
})
|
|
52
|
+
it("custom description on parent doesn't affect children", () => {
|
|
53
|
+
const evenNumber = node({
|
|
54
|
+
domain: "number",
|
|
55
|
+
divisor: 2,
|
|
56
|
+
description: "an even number"
|
|
57
|
+
})
|
|
58
|
+
attest(evenNumber.description).snap("an even number")
|
|
59
|
+
// since the error is from the divisor constraint which didn't have a
|
|
60
|
+
// description, it is unchanged
|
|
61
|
+
attest(evenNumber(5).errors?.summary).snap(
|
|
62
|
+
"must be a multiple of 2 (was 5)"
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
it("can configure errors by kind at a scope level", () => {
|
|
66
|
+
const types = scope(
|
|
67
|
+
{ superSpecialString: "string" },
|
|
68
|
+
{
|
|
69
|
+
domain: {
|
|
70
|
+
expected: (inner) => `custom expected ${inner.domain}`,
|
|
71
|
+
actual: (data) => `custom actual ${data}`,
|
|
72
|
+
problem: (ctx) => `custom problem ${ctx.expected} ${ctx.actual}`,
|
|
73
|
+
message: (ctx) => `custom message ${ctx.problem}`
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
).export()
|
|
77
|
+
const superSpecialString = types.superSpecialString
|
|
78
|
+
attest(superSpecialString(5).errors?.summary).snap(
|
|
79
|
+
"custom message custom problem custom expected string custom actual 5"
|
|
80
|
+
)
|
|
81
|
+
})
|
|
82
|
+
it("can configure description by kind at scope level", () => {
|
|
83
|
+
const types = scope(
|
|
84
|
+
{ superSpecialNumber: "number" },
|
|
85
|
+
{
|
|
86
|
+
domain: {
|
|
87
|
+
description: (inner) => `my special ${inner.domain}`
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
).export()
|
|
91
|
+
const superSpecialNumber = types.superSpecialNumber
|
|
92
|
+
attest(superSpecialNumber.description).snap("my special number")
|
|
93
|
+
attest(superSpecialNumber("five").errors?.summary).snap(
|
|
94
|
+
"must be my special number (was string)"
|
|
95
|
+
)
|
|
96
|
+
})
|
|
97
|
+
it("can apply a global config", () => {
|
|
98
|
+
configure({
|
|
99
|
+
domain: {
|
|
100
|
+
description: (inner) => `my special ${inner.domain}`
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
const mySpecialSymbol = scope({}).node("symbol")
|
|
104
|
+
attest(mySpecialSymbol("foo").errors?.summary).snap(
|
|
105
|
+
"must be my special symbol (was string)"
|
|
106
|
+
)
|
|
107
|
+
configure({
|
|
108
|
+
domain: defaultConfig.domain
|
|
109
|
+
})
|
|
110
|
+
const myBoringSymbol = scope({}).node("symbol")
|
|
111
|
+
attest(myBoringSymbol("foo").errors?.summary).snap(
|
|
112
|
+
"must be a symbol (was string)"
|
|
113
|
+
)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { attest } from "@arktype/attest"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { scope, type Ark } from "../ark.js"
|
|
2
|
+
import { scope, type, type Ark, type Out } from "arktype"
|
|
3
|
+
import { node } from "../keywords/ark.js"
|
|
5
4
|
import {
|
|
6
5
|
writeMissingRightOperandMessage,
|
|
7
6
|
writeUnresolvableMessage
|
|
8
7
|
} from "../parser/string/shift/operand/unenclosed.js"
|
|
9
|
-
import type { Type } from "../type.js"
|
|
8
|
+
import type { Type } from "../types/type.js"
|
|
10
9
|
|
|
11
10
|
describe("tuple expressions", () => {
|
|
12
11
|
it("nested", () => {
|
|
@@ -15,13 +14,9 @@ describe("tuple expressions", () => {
|
|
|
15
14
|
})
|
|
16
15
|
it("autocompletion", () => {
|
|
17
16
|
// @ts-expect-error
|
|
18
|
-
attest(() => type([""])).
|
|
19
|
-
`IndexZeroOperator | keyof Ark | "this"`
|
|
20
|
-
)
|
|
17
|
+
attest(() => type([""])).completions()
|
|
21
18
|
// @ts-expect-error
|
|
22
|
-
attest(() => type(["string", ""])).
|
|
23
|
-
`"keyof" | keyof Ark | "this" | IndexOneOperator'`
|
|
24
|
-
)
|
|
19
|
+
attest(() => type(["string", ""])).completions()
|
|
25
20
|
})
|
|
26
21
|
describe("errors", () => {
|
|
27
22
|
it("missing right operand", () => {
|
|
@@ -75,17 +70,19 @@ describe("root expression", () => {
|
|
|
75
70
|
it("=== branches", () => {
|
|
76
71
|
const t = type("===", "foo", "bar", "baz")
|
|
77
72
|
attest<"foo" | "bar" | "baz">(t.infer)
|
|
78
|
-
attest(t.json).
|
|
73
|
+
attest(t.json).snap([{ unit: "bar" }, { unit: "baz" }, { unit: "foo" }])
|
|
79
74
|
})
|
|
80
75
|
it("instanceof single", () => {
|
|
81
76
|
const t = type("instanceof", RegExp)
|
|
82
77
|
attest<RegExp>(t.infer)
|
|
83
|
-
|
|
78
|
+
const expected = node(RegExp)
|
|
79
|
+
attest(t.json).equals(expected.json)
|
|
84
80
|
})
|
|
85
81
|
it("instanceof branches", () => {
|
|
86
82
|
const t = type("instanceof", Array, Date)
|
|
87
83
|
attest<unknown[] | Date>(t.infer)
|
|
88
|
-
|
|
84
|
+
const expected = node([Array, Date])
|
|
85
|
+
attest(t.json).equals(expected.json)
|
|
89
86
|
})
|
|
90
87
|
it("postfix", () => {
|
|
91
88
|
const t = type({ a: "string" }, "[]")
|
|
@@ -127,12 +124,9 @@ describe("root expression", () => {
|
|
|
127
124
|
it("tuple as second arg", () => {
|
|
128
125
|
// this case is not fundamentally unique but TS has a hard time
|
|
129
126
|
// narrowing tuples in contexts like this
|
|
130
|
-
const t = type("keyof", [
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// as const is required for TS <=5.0
|
|
135
|
-
] as const)
|
|
136
|
-
attest<"a" | "b">(t.infer)
|
|
127
|
+
const t = type("keyof", [{ a: "string" }, "&", { b: "boolean" }])
|
|
128
|
+
const expected = type("'a' | 'b'")
|
|
129
|
+
attest<typeof expected.infer>(t.infer)
|
|
130
|
+
attest(t.json).equals(expected.json)
|
|
137
131
|
})
|
|
138
132
|
})
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { attest } from "@arktype/attest"
|
|
2
|
-
import { writeIndivisibleMessage } from "@arktype/schema"
|
|
3
2
|
import { lazily } from "@arktype/util"
|
|
4
|
-
import { scope, type } from "arktype"
|
|
5
|
-
import {
|
|
3
|
+
import { keywords, scope, type } from "arktype"
|
|
4
|
+
import { writeIndivisibleMessage } from "../constraints/refinements/divisor.js"
|
|
6
5
|
import { emptyGenericParameterMessage } from "../parser/generic.js"
|
|
7
6
|
import { writeUnclosedGroupMessage } from "../parser/string/reduce/shared.js"
|
|
8
7
|
import { writeInvalidGenericArgsMessage } from "../parser/string/shift/operand/genericArgs.js"
|
|
@@ -281,13 +280,13 @@ describe("generics", () => {
|
|
|
281
280
|
attest(() =>
|
|
282
281
|
// @ts-expect-error
|
|
283
282
|
$.type("box<1,string%2>")
|
|
284
|
-
).throwsAndHasTypeError(writeIndivisibleMessage(
|
|
283
|
+
).throwsAndHasTypeError(writeIndivisibleMessage(keywords.string))
|
|
285
284
|
})
|
|
286
285
|
})
|
|
287
286
|
})
|
|
288
287
|
describe("builtins", () => {
|
|
289
288
|
it("record", () => {
|
|
290
|
-
const t =
|
|
289
|
+
const t = keywords.Record("string", "number")
|
|
291
290
|
attest(t.json).equals(type("Record<string, number>").json)
|
|
292
291
|
})
|
|
293
292
|
})
|
package/__tests__/group.test.ts
CHANGED
|
@@ -8,11 +8,16 @@ import { writeExpressionExpectedMessage } from "../parser/string/shift/operand/u
|
|
|
8
8
|
|
|
9
9
|
describe("group", () => {
|
|
10
10
|
it("entire expression", () => {
|
|
11
|
-
|
|
11
|
+
const t = type("(string)")
|
|
12
|
+
const expected = type("string")
|
|
13
|
+
attest<typeof expected>(t)
|
|
14
|
+
attest(t.json).equals(expected.json)
|
|
12
15
|
})
|
|
13
16
|
it("overrides default precedence", () => {
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const t = type("(boolean|number)[]")
|
|
18
|
+
const expected = type("boolean|number").array()
|
|
19
|
+
attest<typeof expected>(t)
|
|
20
|
+
attest(t.json).equals(expected.json)
|
|
16
21
|
})
|
|
17
22
|
it("nested", () => {
|
|
18
23
|
attest<((number | boolean)[] | (string | undefined)[])[]>(
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { attest } from "@arktype/attest"
|
|
2
|
-
import { schema } from "@arktype/schema"
|
|
3
2
|
import { type } from "arktype"
|
|
4
|
-
import type
|
|
3
|
+
import { node, type Ark } from "../keywords/ark.js"
|
|
5
4
|
import { writeInvalidConstructorMessage } from "../parser/tuple.js"
|
|
6
|
-
import type { Type } from "../type.js"
|
|
5
|
+
import type { Type } from "../types/type.js"
|
|
7
6
|
|
|
8
7
|
describe("instanceof", () => {
|
|
9
8
|
describe("tuple expression", () => {
|
|
10
9
|
it("base", () => {
|
|
11
10
|
const t = type(["instanceof", Error])
|
|
12
11
|
attest<Error>(t.infer)
|
|
13
|
-
|
|
12
|
+
const expected = node(Error)
|
|
13
|
+
attest(t.json).equals(expected.json)
|
|
14
14
|
const e = new Error()
|
|
15
15
|
attest(t(e).out).equals(e)
|
|
16
|
-
attest(t({}).errors?.summary).snap("
|
|
16
|
+
attest(t({}).errors?.summary).snap("must be an Error (was object)")
|
|
17
17
|
})
|
|
18
18
|
it("inherited", () => {
|
|
19
19
|
const t = type(["instanceof", TypeError])
|
|
@@ -23,7 +23,7 @@ describe("instanceof", () => {
|
|
|
23
23
|
// attest<TypeError>(t.infer)
|
|
24
24
|
attest(t(e).out).equals(e)
|
|
25
25
|
attest(t(new Error()).errors?.summary).snap(
|
|
26
|
-
"
|
|
26
|
+
"must be an instance of TypeError (was Error)"
|
|
27
27
|
)
|
|
28
28
|
})
|
|
29
29
|
it("abstract", () => {
|
|
@@ -60,7 +60,7 @@ describe("instanceof", () => {
|
|
|
60
60
|
const a = new ArkClass()
|
|
61
61
|
attest(ark(a).out).equals(a)
|
|
62
62
|
attest(ark({}).errors?.summary).snap(
|
|
63
|
-
"
|
|
63
|
+
"must be an instance of ArkClass (was object)"
|
|
64
64
|
)
|
|
65
65
|
})
|
|
66
66
|
// TODO: Fix- Investigate bidirectional check impact on perf to narrow private props without breaking this case:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { attest } from "@arktype/attest"
|
|
2
|
-
import { writeIndivisibleMessage } from "@arktype/schema"
|
|
3
2
|
import { type } from "arktype"
|
|
3
|
+
import { writeIndivisibleMessage } from "../constraints/refinements/divisor.js"
|
|
4
|
+
import { keywords, node } from "../keywords/ark.js"
|
|
4
5
|
import {
|
|
5
6
|
writeMissingRightOperandMessage,
|
|
6
7
|
writeUnresolvableMessage
|
|
@@ -59,46 +60,69 @@ describe("intersection", () => {
|
|
|
59
60
|
|
|
60
61
|
attest<{ a: number; b: boolean[]; c: "hello" }>(t.infer)
|
|
61
62
|
})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
|
|
64
|
+
it("bad reference", () => {
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
attest(() => type("boolean&tru"))
|
|
67
|
+
.throws(writeUnresolvableMessage("tru"))
|
|
68
|
+
.type.errors("boolean&true")
|
|
69
|
+
})
|
|
70
|
+
it("double and", () => {
|
|
71
|
+
// @ts-expect-error
|
|
72
|
+
attest(() => type("boolean&&true")).throws(
|
|
73
|
+
writeMissingRightOperandMessage("&", "&true")
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
it("implicit never", () => {
|
|
77
|
+
attest(() => type("string&number")).throws.snap(
|
|
78
|
+
"ParseError: Intersection of string and number results in an unsatisfiable type"
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
it("left semantic error", () => {
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
attest(() => type("string%2&'foo'")).throwsAndHasTypeError(
|
|
84
|
+
writeIndivisibleMessage(keywords.string)
|
|
85
|
+
)
|
|
86
|
+
})
|
|
87
|
+
it("right semantic error", () => {
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
attest(() => type("'foo'&string%2")).throwsAndHasTypeError(
|
|
90
|
+
writeIndivisibleMessage(keywords.string)
|
|
91
|
+
)
|
|
92
|
+
})
|
|
93
|
+
it("chained validation", () => {
|
|
94
|
+
attest(() =>
|
|
87
95
|
// @ts-expect-error
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
type({ a: "string" }).and({ b: "what" })
|
|
97
|
+
).throwsAndHasTypeError(writeUnresolvableMessage("what"))
|
|
98
|
+
})
|
|
99
|
+
it("at path", () => {
|
|
100
|
+
attest(() => type({ a: "string" }).and({ a: "number" })).throws.snap(
|
|
101
|
+
"ParseError: Intersection at a of string and number results in an unsatisfiable type"
|
|
102
|
+
)
|
|
103
|
+
})
|
|
104
|
+
it("normalizes refinement order", () => {
|
|
105
|
+
const l = node({
|
|
106
|
+
domain: "number",
|
|
107
|
+
divisor: 3,
|
|
108
|
+
min: 5
|
|
91
109
|
})
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
).throwsAndHasTypeError(writeUnresolvableMessage("what"))
|
|
110
|
+
const r = node({
|
|
111
|
+
domain: "number",
|
|
112
|
+
min: 5,
|
|
113
|
+
divisor: 3
|
|
97
114
|
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
attest(l.innerId).equals(r.innerId)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it("multiple constraints", () => {
|
|
119
|
+
const n = node({
|
|
120
|
+
domain: "number",
|
|
121
|
+
divisor: 3,
|
|
122
|
+
min: 5
|
|
102
123
|
})
|
|
124
|
+
attest(n.allows(6)).snap(true)
|
|
125
|
+
attest(n.allows(4)).snap(false)
|
|
126
|
+
attest(n.allows(7)).snap(false)
|
|
103
127
|
})
|
|
104
128
|
})
|