arktype 2.0.0-dev.10 → 2.0.0-dev.12

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.
Files changed (146) hide show
  1. package/out/api.d.ts +6 -0
  2. package/out/api.js +5 -0
  3. package/out/ark.d.ts +1 -1
  4. package/out/config.d.ts +1 -0
  5. package/out/config.js +2 -0
  6. package/out/generic.d.ts +3 -3
  7. package/out/match.js +1 -1
  8. package/out/module.d.ts +7 -6
  9. package/out/module.js +2 -3
  10. package/out/parser/definition.d.ts +11 -9
  11. package/out/parser/definition.js +2 -2
  12. package/out/parser/objectLiteral.d.ts +8 -13
  13. package/out/parser/objectLiteral.js +20 -23
  14. package/out/parser/semantic/bounds.d.ts +3 -3
  15. package/out/parser/semantic/divisor.d.ts +2 -2
  16. package/out/parser/semantic/infer.d.ts +1 -1
  17. package/out/parser/semantic/validate.d.ts +6 -4
  18. package/out/parser/string/reduce/dynamic.d.ts +6 -6
  19. package/out/parser/string/reduce/shared.d.ts +16 -16
  20. package/out/parser/string/reduce/shared.js +4 -2
  21. package/out/parser/string/shift/operand/date.d.ts +2 -2
  22. package/out/parser/string/shift/operand/enclosed.d.ts +17 -3
  23. package/out/parser/string/shift/operand/enclosed.js +2 -1
  24. package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
  25. package/out/parser/string/shift/operand/unenclosed.d.ts +9 -7
  26. package/out/parser/string/shift/operand/unenclosed.js +2 -2
  27. package/out/parser/string/shift/operator/bounds.d.ts +5 -5
  28. package/out/parser/string/shift/operator/bounds.js +3 -3
  29. package/out/parser/string/shift/operator/divisor.d.ts +1 -1
  30. package/out/parser/string/shift/operator/operator.d.ts +1 -1
  31. package/out/parser/string/string.d.ts +2 -2
  32. package/out/parser/tuple.d.ts +11 -11
  33. package/out/parser/tuple.js +3 -3
  34. package/out/scope.d.ts +15 -13
  35. package/out/scope.js +7 -7
  36. package/out/type.d.ts +4 -4
  37. package/out/type.js +3 -3
  38. package/package.json +8 -10
  39. package/__tests__/array.test.ts +0 -391
  40. package/__tests__/badDefinitionType.test.ts +0 -58
  41. package/__tests__/basis.test.ts +0 -50
  42. package/__tests__/bounds.test.ts +0 -318
  43. package/__tests__/cast.test.ts +0 -37
  44. package/__tests__/completions.test.ts +0 -51
  45. package/__tests__/config.test.ts +0 -96
  46. package/__tests__/dateLiteral.test.ts +0 -36
  47. package/__tests__/declared.test.ts +0 -124
  48. package/__tests__/discrimination.test.ts +0 -74
  49. package/__tests__/divisor.test.ts +0 -114
  50. package/__tests__/enclosed.test.ts +0 -107
  51. package/__tests__/examples.test.ts +0 -56
  52. package/__tests__/expressions.test.ts +0 -210
  53. package/__tests__/generateBenchData.ts +0 -89
  54. package/__tests__/generated/cyclic.ts +0 -3058
  55. package/__tests__/generic.test.ts +0 -313
  56. package/__tests__/group.test.ts +0 -85
  57. package/__tests__/hkt.test.ts +0 -22
  58. package/__tests__/imports.test.ts +0 -126
  59. package/__tests__/instanceof.test.ts +0 -104
  60. package/__tests__/intersection.test.ts +0 -108
  61. package/__tests__/keyTraversal.test.ts +0 -77
  62. package/__tests__/keyof.test.ts +0 -150
  63. package/__tests__/keywords.test.ts +0 -214
  64. package/__tests__/literal.test.ts +0 -90
  65. package/__tests__/match.bench.ts +0 -31
  66. package/__tests__/match.test.ts +0 -234
  67. package/__tests__/methods.bench.ts +0 -22
  68. package/__tests__/narrow.test.ts +0 -100
  69. package/__tests__/object.bench.ts +0 -28
  70. package/__tests__/objectLiteral.test.ts +0 -442
  71. package/__tests__/operand.bench.ts +0 -45
  72. package/__tests__/operator.bench.ts +0 -130
  73. package/__tests__/pipe.test.ts +0 -501
  74. package/__tests__/realWorld.test.ts +0 -63
  75. package/__tests__/regex.test.ts +0 -68
  76. package/__tests__/scope.bench.ts +0 -39
  77. package/__tests__/scope.test.ts +0 -374
  78. package/__tests__/serialization.test.ts +0 -19
  79. package/__tests__/string.test.ts +0 -52
  80. package/__tests__/submodule.test.ts +0 -86
  81. package/__tests__/this.test.ts +0 -83
  82. package/__tests__/thunk.test.ts +0 -86
  83. package/__tests__/traverse.test.ts +0 -141
  84. package/__tests__/tsGenerics.test.ts +0 -12
  85. package/__tests__/type.test.ts +0 -36
  86. package/__tests__/typeReference.test.ts +0 -39
  87. package/__tests__/unenclosed.test.ts +0 -136
  88. package/__tests__/union.test.ts +0 -214
  89. package/ark.ts +0 -47
  90. package/generic.ts +0 -69
  91. package/main.ts +0 -6
  92. package/match.ts +0 -218
  93. package/module.ts +0 -15
  94. package/out/ark.js.map +0 -1
  95. package/out/generic.js.map +0 -1
  96. package/out/main.js.map +0 -1
  97. package/out/match.js.map +0 -1
  98. package/out/module.js.map +0 -1
  99. package/out/parser/definition.js.map +0 -1
  100. package/out/parser/generic.js.map +0 -1
  101. package/out/parser/objectLiteral.js.map +0 -1
  102. package/out/parser/semantic/bounds.js.map +0 -1
  103. package/out/parser/semantic/divisor.js.map +0 -1
  104. package/out/parser/semantic/infer.js.map +0 -1
  105. package/out/parser/semantic/utils.js.map +0 -1
  106. package/out/parser/semantic/validate.js.map +0 -1
  107. package/out/parser/string/reduce/dynamic.js.map +0 -1
  108. package/out/parser/string/reduce/shared.js.map +0 -1
  109. package/out/parser/string/reduce/static.js.map +0 -1
  110. package/out/parser/string/shift/operand/date.js.map +0 -1
  111. package/out/parser/string/shift/operand/enclosed.js.map +0 -1
  112. package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
  113. package/out/parser/string/shift/operand/operand.js.map +0 -1
  114. package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
  115. package/out/parser/string/shift/operator/bounds.js.map +0 -1
  116. package/out/parser/string/shift/operator/divisor.js.map +0 -1
  117. package/out/parser/string/shift/operator/operator.js.map +0 -1
  118. package/out/parser/string/shift/scanner.js.map +0 -1
  119. package/out/parser/string/string.js.map +0 -1
  120. package/out/parser/tuple.js.map +0 -1
  121. package/out/scope.js.map +0 -1
  122. package/out/type.js.map +0 -1
  123. package/parser/definition.ts +0 -143
  124. package/parser/generic.ts +0 -66
  125. package/parser/objectLiteral.ts +0 -233
  126. package/parser/semantic/bounds.ts +0 -62
  127. package/parser/semantic/divisor.ts +0 -11
  128. package/parser/semantic/infer.ts +0 -141
  129. package/parser/semantic/utils.ts +0 -15
  130. package/parser/semantic/validate.ts +0 -117
  131. package/parser/string/reduce/dynamic.ts +0 -208
  132. package/parser/string/reduce/shared.ts +0 -99
  133. package/parser/string/reduce/static.ts +0 -296
  134. package/parser/string/shift/operand/date.ts +0 -55
  135. package/parser/string/shift/operand/enclosed.ts +0 -123
  136. package/parser/string/shift/operand/genericArgs.ts +0 -128
  137. package/parser/string/shift/operand/operand.ts +0 -42
  138. package/parser/string/shift/operand/unenclosed.ts +0 -217
  139. package/parser/string/shift/operator/bounds.ts +0 -270
  140. package/parser/string/shift/operator/divisor.ts +0 -33
  141. package/parser/string/shift/operator/operator.ts +0 -71
  142. package/parser/string/shift/scanner.ts +0 -210
  143. package/parser/string/string.ts +0 -85
  144. package/parser/tuple.ts +0 -542
  145. package/scope.ts +0 -291
  146. package/type.ts +0 -266
@@ -1,4 +1,4 @@
1
- import { type BoundKind, type LimitLiteral, type RawSchema } from "@arktype/schema";
1
+ import { type BaseRoot, type BoundKind, type LimitLiteral } from "@arktype/schema";
2
2
  import { type keySet } from "@arktype/util";
3
3
  import type { astToString } from "../../../semantic/utils.js";
4
4
  import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.js";
@@ -17,13 +17,13 @@ export type ComparatorStartChar = Comparator extends `${infer char}${string}` ?
17
17
  export declare const comparatorStartChars: keySet<ComparatorStartChar>;
18
18
  declare const shiftComparator: (s: DynamicState, start: ComparatorStartChar) => Comparator;
19
19
  type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : start extends OneCharComparator ? [start, unscanned] : state.error<singleEqualsMessage>;
20
- export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => "Bound kinds exactLength and exactLength are incompatible" | "Bound kinds exactLength and max are incompatible" | "Bound kinds exactLength and min are incompatible" | "Bound kinds exactLength and maxLength are incompatible" | "Bound kinds exactLength and minLength are incompatible" | "Bound kinds exactLength and before are incompatible" | "Bound kinds exactLength and after are incompatible" | "Bound kinds max and exactLength are incompatible" | "Bound kinds max and max are incompatible" | "Bound kinds max and min are incompatible" | "Bound kinds max and maxLength are incompatible" | "Bound kinds max and minLength are incompatible" | "Bound kinds max and before are incompatible" | "Bound kinds max and after are incompatible" | "Bound kinds min and exactLength are incompatible" | "Bound kinds min and max are incompatible" | "Bound kinds min and min are incompatible" | "Bound kinds min and maxLength are incompatible" | "Bound kinds min and minLength are incompatible" | "Bound kinds min and before are incompatible" | "Bound kinds min and after are incompatible" | "Bound kinds maxLength and exactLength are incompatible" | "Bound kinds maxLength and max are incompatible" | "Bound kinds maxLength and min are incompatible" | "Bound kinds maxLength and maxLength are incompatible" | "Bound kinds maxLength and minLength are incompatible" | "Bound kinds maxLength and before are incompatible" | "Bound kinds maxLength and after are incompatible" | "Bound kinds minLength and exactLength are incompatible" | "Bound kinds minLength and max are incompatible" | "Bound kinds minLength and min are incompatible" | "Bound kinds minLength and maxLength are incompatible" | "Bound kinds minLength and minLength are incompatible" | "Bound kinds minLength and before are incompatible" | "Bound kinds minLength and after are incompatible" | "Bound kinds before and exactLength are incompatible" | "Bound kinds before and max are incompatible" | "Bound kinds before and min are incompatible" | "Bound kinds before and maxLength are incompatible" | "Bound kinds before and minLength are incompatible" | "Bound kinds before and before are incompatible" | "Bound kinds before and after are incompatible" | "Bound kinds after and exactLength are incompatible" | "Bound kinds after and max are incompatible" | "Bound kinds after and min are incompatible" | "Bound kinds after and maxLength are incompatible" | "Bound kinds after and minLength are incompatible" | "Bound kinds after and before are incompatible" | "Bound kinds after and after are incompatible";
21
- export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root: RawSchema, boundKind: BoundExpressionKind) => BoundKind[];
20
+ export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
21
+ export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
22
22
  export declare const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
23
23
  type singleEqualsMessage = typeof singleEqualsMessage;
24
24
  export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) => void;
25
25
  export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends `${infer limit extends LimitLiteral}` ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ? state.reduceRange<s, s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], comparator, limit, nextState["unscanned"]> : state.error<writeUnpairableComparatorMessage<comparator>> : state.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : state.error<writeInvalidLimitMessage<comparator, astToString<nextState["root"]>, "right">> : never;
26
- export declare const writeInvalidLimitMessage: <comparator extends "==" | "<" | "<=" | ">" | ">=", limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => writeInvalidLimitMessage<comparator, limit, boundKind>;
27
- export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was '${limit}')`;
26
+ export declare const writeInvalidLimitMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==", limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
27
+ export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
28
28
  export type BoundExpressionKind = "left" | "right";
29
29
  export {};
@@ -58,7 +58,7 @@ export const getBoundKinds = (comparator, limit, root, boundKind) => {
58
58
  return throwParseError(writeUnboundableMessage(root.expression));
59
59
  };
60
60
  export const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
61
- const openLeftBoundToSchema = (leftBound) => ({
61
+ const openLeftBoundToRoot = (leftBound) => ({
62
62
  rule: isDateLiteral(leftBound.limit) ?
63
63
  extractDateLiteralSource(leftBound.limit)
64
64
  : leftBound.limit,
@@ -89,7 +89,7 @@ export const parseRightBound = (s, comparator) => {
89
89
  if (!isKeyOf(comparator, maxComparators))
90
90
  return s.error(writeUnpairableComparatorMessage(comparator));
91
91
  const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
92
- s.constrainRoot(lowerBoundKind[0], openLeftBoundToSchema(s.branches.leftBound));
92
+ s.constrainRoot(lowerBoundKind[0], openLeftBoundToRoot(s.branches.leftBound));
93
93
  s.branches.leftBound = null;
94
94
  };
95
- export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was '${limit}')`;
95
+ export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
@@ -3,5 +3,5 @@ import type { StaticState, state } from "../../reduce/static.js";
3
3
  import type { Scanner } from "../scanner.js";
4
4
  export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
5
5
  export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
6
- export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
6
+ export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
7
7
  export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
@@ -5,7 +5,7 @@ import { parseBound, type ComparatorStartChar } from "./bounds.js";
5
5
  import { parseDivisor } from "./divisor.js";
6
6
  export declare const parseOperator: (s: DynamicStateWithRoot) => void;
7
7
  export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
8
- export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
8
+ export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
9
9
  export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
10
10
  export declare const incompleteArrayTokenMessage = "Missing expected ']'";
11
11
  type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
@@ -1,4 +1,4 @@
1
- import type { RawSchema } from "@arktype/schema";
1
+ import type { BaseRoot } from "@arktype/schema";
2
2
  import { type ErrorMessage } from "@arktype/util";
3
3
  import type { inferAstRoot } from "../semantic/infer.js";
4
4
  import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js";
@@ -16,7 +16,7 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? def
16
16
  ] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
17
17
  export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
18
18
  export type BaseCompletions<$, args, otherSuggestions extends string = never> = (keyof $ & string) | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
19
- export declare const fullStringParse: (s: DynamicState) => RawSchema;
19
+ export declare const fullStringParse: (s: DynamicState) => BaseRoot;
20
20
  type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
21
21
  export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
22
22
  export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
@@ -1,19 +1,19 @@
1
- import { type BaseMeta, type Morph, type Out, type Predicate, type RawSchema, type distillConstrainableIn, type distillConstrainableOut, type inferIntersection, type inferMorphOut, type inferNarrow } from "@arktype/schema";
1
+ import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type distillConstrainableOut, type inferIntersection, type inferMorphOut, type inferNarrow } from "@arktype/schema";
2
2
  import { type Constructor, type Domain, type ErrorMessage, type array, type conform, type show } from "@arktype/util";
3
3
  import type { ParseContext } from "../scope.js";
4
4
  import type { inferDefinition, validateDefinition } from "./definition.js";
5
5
  import type { InfixOperator, PostfixExpression } from "./semantic/infer.js";
6
6
  import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
7
7
  import type { BaseCompletions } from "./string/string.js";
8
- export declare const parseTuple: (def: array, ctx: ParseContext) => RawSchema;
9
- export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => RawSchema;
8
+ export declare const parseTuple: (def: array, ctx: ParseContext) => BaseRoot;
9
+ export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => BaseRoot;
10
10
  type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
11
11
  export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
12
12
  def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
13
13
  def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..." | "?"> : def[1]
14
14
  ] : validateTupleLiteral<def, $, args>;
15
- export type validateTupleLiteral<def extends array, $, args> = Readonly<parseSequence<def, $, args>["validated"]>;
16
- type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args>["inferred"];
15
+ export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
16
+ type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
17
17
  type SequenceParseState = {
18
18
  unscanned: array;
19
19
  inferred: array;
@@ -86,8 +86,8 @@ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextEleme
86
86
  ] : [])
87
87
  ];
88
88
  }, $, args> : s;
89
- export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
90
- type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? `(was ${operand})` : ""}`;
89
+ export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
90
+ type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
91
91
  export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
92
92
  type multipleVariadicMessage = typeof multipleVariadicMesage;
93
93
  export declare const requiredPostOptionalMessage = "A required element may not follow an optional element";
@@ -112,8 +112,8 @@ export type UnparsedTupleExpressionInput = {
112
112
  export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
113
113
  export declare const parseKeyOfTuple: PrefixParser<"keyof">;
114
114
  export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
115
- export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => RawSchema;
116
- export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => RawSchema;
115
+ export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => BaseRoot;
116
+ export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => BaseRoot;
117
117
  export type TupleExpression = IndexZeroExpression | IndexOneExpression;
118
118
  export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
119
119
  export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
@@ -121,10 +121,10 @@ export type TuplePostfixOperator = "[]";
121
121
  export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
122
122
  export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
123
123
  export declare const parseMorphTuple: PostfixParser<"=>">;
124
- export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => "Narrow expression requires a function following ':' (was string)" | "Narrow expression requires a function following ':' (was number)" | "Narrow expression requires a function following ':' (was bigint)" | "Narrow expression requires a function following ':' (was boolean)" | "Narrow expression requires a function following ':' (was symbol)" | "Narrow expression requires a function following ':' (was undefined)" | "Narrow expression requires a function following ':' (was object)" | "Narrow expression requires a function following ':' (was function)" | "Narrow expression requires a function following '=>' (was string)" | "Narrow expression requires a function following '=>' (was number)" | "Narrow expression requires a function following '=>' (was bigint)" | "Narrow expression requires a function following '=>' (was boolean)" | "Narrow expression requires a function following '=>' (was symbol)" | "Narrow expression requires a function following '=>' (was undefined)" | "Narrow expression requires a function following '=>' (was object)" | "Narrow expression requires a function following '=>' (was function)" | "Morph expression requires a function following ':' (was string)" | "Morph expression requires a function following ':' (was number)" | "Morph expression requires a function following ':' (was bigint)" | "Morph expression requires a function following ':' (was boolean)" | "Morph expression requires a function following ':' (was symbol)" | "Morph expression requires a function following ':' (was undefined)" | "Morph expression requires a function following ':' (was object)" | "Morph expression requires a function following ':' (was function)" | "Morph expression requires a function following '=>' (was string)" | "Morph expression requires a function following '=>' (was number)" | "Morph expression requires a function following '=>' (was bigint)" | "Morph expression requires a function following '=>' (was boolean)" | "Morph expression requires a function following '=>' (was symbol)" | "Morph expression requires a function following '=>' (was undefined)" | "Morph expression requires a function following '=>' (was object)" | "Morph expression requires a function following '=>' (was function)";
124
+ export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
125
125
  export type parseMorph<inDef, morph, $, args> = morph extends Morph ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<inferMorphOut<morph>> : never;
126
126
  export declare const parseNarrowTuple: PostfixParser<":">;
127
127
  export type IndexZeroOperator = "keyof" | "instanceof" | "===";
128
128
  export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
129
- export declare const writeInvalidConstructorMessage: <actual extends Domain | "Array" | "Date" | "Error" | "Function" | "Map" | "RegExp" | "Set" | "String" | "Number" | "Boolean" | "WeakMap" | "WeakSet" | "Promise">(actual: actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
129
+ export declare const writeInvalidConstructorMessage: <actual extends Domain | keyof import("@arktype/util").builtinConstructors>(actual: actual) => string;
130
130
  export {};
@@ -42,7 +42,7 @@ export const parseTupleLiteral = (def, ctx) => {
42
42
  const appendElement = (base, kind, element) => {
43
43
  switch (kind) {
44
44
  case "required":
45
- if (base.optional)
45
+ if (base.optionals)
46
46
  // e.g. [string?, number]
47
47
  return throwParseError(requiredPostOptionalMessage);
48
48
  if (base.variadic) {
@@ -59,7 +59,7 @@ const appendElement = (base, kind, element) => {
59
59
  // e.g. [...string[], number?]
60
60
  return throwParseError(optionalPostVariadicMessage);
61
61
  // e.g. [string, number?]
62
- base.optional = append(base.optional, element);
62
+ base.optionals = append(base.optionals, element);
63
63
  return base;
64
64
  case "variadic":
65
65
  // e.g. [...string[], number, ...string[]]
@@ -87,7 +87,7 @@ const appendSpreadBranch = (base, branch) => {
87
87
  return appendElement(base, "variadic", tsKeywords.unknown);
88
88
  }
89
89
  spread.prefix.forEach(node => appendElement(base, "required", node));
90
- spread.optional.forEach(node => appendElement(base, "optional", node));
90
+ spread.optionals.forEach(node => appendElement(base, "optional", node));
91
91
  spread.variadic && appendElement(base, "variadic", spread.variadic);
92
92
  spread.postfix.forEach(node => appendElement(base, "required", node));
93
93
  return base;
package/out/scope.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { type ArkConfig, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawSchema, type RawSchemaResolutions, RawSchemaScope, type SchemaScope, type UnknownSchema, type ambient, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@arktype/schema";
2
- import { type isAnyOrNever, type keyError, type nominal, type show } from "@arktype/util";
1
+ import { RawRootScope, type ArkConfig, type BaseRoot, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type UnknownRoot, type ambient, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@arktype/schema";
2
+ import { type anyOrNever, type keyError, type nominal, type show } from "@arktype/util";
3
3
  import type { type } from "./ark.js";
4
4
  import { Generic } from "./generic.js";
5
5
  import { type MatchParser } from "./match.js";
6
6
  import type { Module } from "./module.js";
7
7
  import { type inferDefinition, type validateDefinition } from "./parser/definition.js";
8
- import { type GenericDeclaration, type GenericParamsParseError, parseGenericParams } from "./parser/generic.js";
9
- import { type DeclarationParser, type DefinitionParser, RawTypeParser, type Type, type TypeParser } from "./type.js";
8
+ import { parseGenericParams, type GenericDeclaration, type GenericParamsParseError } from "./parser/generic.js";
9
+ import { _TypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.js";
10
10
  export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkConfig) => Scope<inferBootstrapped<bootstrapAliases<def>>>;
11
11
  type validateScope<def> = {
12
12
  [k in keyof def]: k extends symbol ? unknown : parseScopeKey<k>["params"] extends [] ? def[k] extends Type | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? keyError<writeDuplicateAliasError<name>> : validateDefinition<def[k], ambient & bootstrapAliases<def>, {}> : parseScopeKey<k>["params"] extends GenericParamsParseError ? parseScopeKey<k>["params"][0] : validateDefinition<def[k], ambient & bootstrapAliases<def>, {
@@ -32,7 +32,9 @@ type inferBootstrapped<$> = show<{
32
32
  }>;
33
33
  type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
34
34
  type extractGenericParameters<k> = k extends GenericDeclaration<string, infer params> ? params : never;
35
- export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ? isAnyOrNever<resolution> extends true ? resolution : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution : never;
35
+ export type resolve<reference extends keyof $ | keyof args, $, args> = (reference extends keyof args ? args[reference] : $[reference & keyof $]) extends infer resolution ? [
36
+ resolution
37
+ ] extends [anyOrNever] ? resolution : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution : never;
36
38
  export type moduleKeyOf<$> = {
37
39
  [k in keyof $]: $[k] extends {
38
40
  [arkKind]: "module";
@@ -41,10 +43,10 @@ export type moduleKeyOf<$> = {
41
43
  export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? $[submodule][subalias] extends type.cast<infer t> ? t : never : never : never;
42
44
  export interface ParseContext {
43
45
  $: RawScope;
44
- args?: Record<string, UnknownSchema>;
46
+ args?: Record<string, UnknownRoot>;
45
47
  }
46
48
  export declare const scope: ScopeParser;
47
- export interface Scope<$ = any> extends SchemaScope<$> {
49
+ export interface Scope<$ = any> extends RootScope<$> {
48
50
  type: TypeParser<$>;
49
51
  match: MatchParser<$>;
50
52
  declare: DeclarationParser<$>;
@@ -52,19 +54,19 @@ export interface Scope<$ = any> extends SchemaScope<$> {
52
54
  import<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredImportContext<$, names>>>;
53
55
  export<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredExportContext<$, names>>>;
54
56
  }
55
- export declare class RawScope<$ extends RawSchemaResolutions = RawSchemaResolutions> extends RawSchemaScope<$> {
57
+ export declare class RawScope<$ extends RawRootResolutions = RawRootResolutions> extends RawRootScope<$> {
56
58
  private parseCache;
57
59
  constructor(def: Record<string, unknown>, config?: ArkConfig);
58
- type: RawTypeParser;
60
+ type: _TypeParser;
59
61
  match: MatchParser<$>;
60
62
  declare: () => {
61
- type: RawTypeParser;
63
+ type: _TypeParser;
62
64
  };
63
65
  define: (def: unknown) => unknown;
64
66
  preparseRoot(def: unknown): unknown;
65
- parseRoot(def: unknown): RawSchema;
66
- parse(def: unknown, ctx: ParseContext): RawSchema;
67
- parseString(def: string, ctx: ParseContext): RawSchema;
67
+ parseRoot(def: unknown): BaseRoot;
68
+ parse(def: unknown, ctx: ParseContext): BaseRoot;
69
+ parseString(def: string, ctx: ParseContext): BaseRoot;
68
70
  }
69
71
  export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
70
72
  export type ParsedScopeKey = {
package/out/scope.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RawSchemaScope, hasArkKind } from "@arktype/schema";
1
+ import { RawRootScope, hasArkKind } from "@arktype/schema";
2
2
  import { domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
3
3
  import { Generic } from "./generic.js";
4
4
  import { createMatchParser } from "./match.js";
@@ -6,9 +6,9 @@ import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.
6
6
  import { parseGenericParams } from "./parser/generic.js";
7
7
  import { DynamicState } from "./parser/string/reduce/dynamic.js";
8
8
  import { fullStringParse } from "./parser/string/string.js";
9
- import { RawTypeParser } from "./type.js";
9
+ import { _TypeParser } from "./type.js";
10
10
  export const scope = ((def, config = {}) => new RawScope(def, config));
11
- export class RawScope extends RawSchemaScope {
11
+ export class RawScope extends RawRootScope {
12
12
  parseCache = {};
13
13
  constructor(def, config) {
14
14
  const aliases = {};
@@ -22,7 +22,7 @@ export class RawScope extends RawSchemaScope {
22
22
  }
23
23
  super(aliases, config);
24
24
  }
25
- type = new RawTypeParser(this);
25
+ type = new _TypeParser(this);
26
26
  match = createMatchParser(this);
27
27
  declare = (() => ({
28
28
  type: this.type
@@ -34,7 +34,7 @@ export class RawScope extends RawSchemaScope {
34
34
  return def;
35
35
  }
36
36
  parseRoot(def) {
37
- // args: { this: {} as RawSchema },
37
+ // args: { this: {} as RawRoot },
38
38
  return this.parse(def, {
39
39
  $: this,
40
40
  args: {}
@@ -58,9 +58,9 @@ export class RawScope extends RawSchemaScope {
58
58
  : throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
59
59
  }
60
60
  parseString(def, ctx) {
61
- return (this.maybeResolveSchema(def) ??
61
+ return (this.maybeResolveRoot(def) ??
62
62
  ((def.endsWith("[]") &&
63
- this.maybeResolveSchema(def.slice(0, -2))?.array()) ||
63
+ this.maybeResolveRoot(def.slice(0, -2))?.array()) ||
64
64
  fullStringParse(new DynamicState(def, ctx))));
65
65
  }
66
66
  }
package/out/type.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ArkErrors, type BaseMeta, type BaseRoot, type Disjoint, type Morph, type NodeDef, type Out, type Predicate, type PrimitiveConstraintKind, RawSchema, type Schema, type ambient, type constrain, type constraintKindOf, type distillConstrainableOut, type distillIn, type distillOut, type includesMorphs, type inferIntersection, type inferMorphOut, type inferNarrow, type inferPipes, type internalImplementationOf } from "@arktype/schema";
1
+ import { ArkErrors, BaseRoot, type BaseMeta, type Disjoint, type InnerRoot, type Morph, type NodeSchema, type Out, type Predicate, type PrimitiveConstraintKind, type Root, type ambient, type constrain, type constraintKindOf, type distillConstrainableOut, type distillIn, type distillOut, type includesMorphs, type inferIntersection, type inferMorphOut, type inferNarrow, type inferPipes, type internalImplementationOf } from "@arktype/schema";
2
2
  import { Callable, type Constructor, type array, type conform } from "@arktype/util";
3
3
  import { Generic, type validateParameterString } from "./generic.js";
4
4
  import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
@@ -15,13 +15,13 @@ export interface TypeParser<$> extends TypeParserAttachments {
15
15
  [param in parseGenericParams<params>[number]]: unknown;
16
16
  }>): Generic<parseGenericParams<params>, def, $>;
17
17
  }
18
- export declare class RawTypeParser extends Callable<(...args: unknown[]) => RawSchema | Generic, TypeParserAttachments> {
18
+ export declare class _TypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
19
19
  constructor($: RawScope);
20
20
  }
21
21
  export type DeclarationParser<$> = <preinferred>() => {
22
22
  type: <def>(def: validateDeclared<preinferred, def, $ & ambient, bindThis<def>>) => Type<preinferred, $>;
23
23
  };
24
- declare class _Type<t = unknown, $ = any> extends BaseRoot<t, $> implements internalImplementationOf<Schema> {
24
+ declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> implements internalImplementationOf<Root> {
25
25
  $: Scope<$>;
26
26
  get in(): Type<this["tIn"], $>;
27
27
  get out(): Type<this["tOut"], $>;
@@ -42,7 +42,7 @@ declare class _Type<t = unknown, $ = any> extends BaseRoot<t, $> implements inte
42
42
  extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
43
43
  exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
44
44
  extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
45
- constrain<kind extends PrimitiveConstraintKind, const def extends NodeDef<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
45
+ constrain<kind extends PrimitiveConstraintKind, const def extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
46
46
  }
47
47
  export interface Type<
48
48
  /** @ts-expect-error allow instantiation assignment to the base type */
package/out/type.js CHANGED
@@ -1,11 +1,11 @@
1
- import { ArkErrors, RawSchema } from "@arktype/schema";
1
+ import { ArkErrors, BaseRoot } from "@arktype/schema";
2
2
  import { Callable } from "@arktype/util";
3
3
  import { Generic } from "./generic.js";
4
4
  import { parseGenericParams } from "./parser/generic.js";
5
5
  const typeParserAttachments = Object.freeze({
6
6
  errors: ArkErrors
7
7
  });
8
- export class RawTypeParser extends Callable {
8
+ export class _TypeParser extends Callable {
9
9
  constructor($) {
10
10
  super((...args) => {
11
11
  if (args.length === 1) {
@@ -30,4 +30,4 @@ export class RawTypeParser extends Callable {
30
30
  }, { bind: $, attach: typeParserAttachments });
31
31
  }
32
32
  }
33
- export const Type = RawSchema;
33
+ export const Type = BaseRoot;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-dev.10",
4
+ "version": "2.0.0-dev.12",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -13,12 +13,12 @@
13
13
  "url": "https://github.com/arktypeio/arktype.git"
14
14
  },
15
15
  "type": "module",
16
- "main": "./out/main.js",
17
- "types": "./out/main.d.ts",
16
+ "main": "./out/api.js",
17
+ "types": "./out/api.d.ts",
18
18
  "exports": {
19
19
  ".": {
20
- "types": "./out/main.d.ts",
21
- "default": "./out/main.js"
20
+ "types": "./out/api.d.ts",
21
+ "default": "./out/api.js"
22
22
  },
23
23
  "./config": {
24
24
  "types": "./out/config.d.ts",
@@ -29,16 +29,14 @@
29
29
  }
30
30
  },
31
31
  "files": [
32
- "out",
33
- "!__tests__",
34
- "**/*.ts"
32
+ "out"
35
33
  ],
36
34
  "scripts": {
37
35
  "build": "tsx ../repo/build.ts",
38
36
  "test": "tsx ../repo/testPackage.ts"
39
37
  },
40
38
  "dependencies": {
41
- "@arktype/util": "0.0.36",
42
- "@arktype/schema": "0.1.1"
39
+ "@arktype/util": "0.0.41",
40
+ "@arktype/schema": "0.1.4"
43
41
  }
44
42
  }