arktype 2.0.0-dev.2 → 2.0.0-dev.20

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 (223) hide show
  1. package/LICENSE +7 -0
  2. package/out/api.d.ts +6 -0
  3. package/out/api.js +5 -0
  4. package/out/ark.d.ts +15 -39
  5. package/out/ark.js +9 -18
  6. package/out/config.d.ts +1 -0
  7. package/out/config.js +2 -0
  8. package/out/generic.d.ts +21 -0
  9. package/out/generic.js +24 -0
  10. package/out/match.d.ts +18 -24
  11. package/out/match.js +50 -60
  12. package/out/module.d.ts +11 -0
  13. package/out/module.js +2 -0
  14. package/out/parser/definition.d.ts +13 -15
  15. package/out/parser/definition.js +10 -13
  16. package/out/parser/generic.d.ts +5 -7
  17. package/out/parser/generic.js +7 -11
  18. package/out/parser/objectLiteral.d.ts +57 -18
  19. package/out/parser/objectLiteral.js +93 -52
  20. package/out/parser/semantic/bounds.d.ts +10 -8
  21. package/out/parser/semantic/bounds.js +0 -1
  22. package/out/parser/semantic/divisor.d.ts +5 -7
  23. package/out/parser/semantic/divisor.js +0 -1
  24. package/out/parser/semantic/infer.d.ts +24 -0
  25. package/out/parser/semantic/infer.js +1 -0
  26. package/out/parser/semantic/utils.d.ts +3 -7
  27. package/out/parser/semantic/utils.js +0 -1
  28. package/out/parser/semantic/validate.d.ts +16 -13
  29. package/out/parser/semantic/validate.js +1 -1
  30. package/out/parser/string/reduce/dynamic.d.ts +13 -13
  31. package/out/parser/string/reduce/dynamic.js +31 -26
  32. package/out/parser/string/reduce/shared.d.ts +14 -28
  33. package/out/parser/string/reduce/shared.js +4 -3
  34. package/out/parser/string/reduce/static.d.ts +26 -23
  35. package/out/parser/string/reduce/static.js +0 -1
  36. package/out/parser/string/shift/operand/date.d.ts +2 -2
  37. package/out/parser/string/shift/operand/date.js +4 -7
  38. package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
  39. package/out/parser/string/shift/operand/enclosed.js +14 -14
  40. package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
  41. package/out/parser/string/shift/operand/genericArgs.js +6 -10
  42. package/out/parser/string/shift/operand/operand.d.ts +3 -4
  43. package/out/parser/string/shift/operand/operand.js +9 -13
  44. package/out/parser/string/shift/operand/unenclosed.d.ts +15 -20
  45. package/out/parser/string/shift/operand/unenclosed.js +24 -36
  46. package/out/parser/string/shift/operator/bounds.d.ts +8 -12
  47. package/out/parser/string/shift/operator/bounds.js +45 -56
  48. package/out/parser/string/shift/operator/divisor.d.ts +1 -3
  49. package/out/parser/string/shift/operator/divisor.js +1 -3
  50. package/out/parser/string/shift/operator/operator.d.ts +1 -2
  51. package/out/parser/string/shift/operator/operator.js +12 -19
  52. package/out/parser/string/shift/scanner.d.ts +8 -7
  53. package/out/parser/string/shift/scanner.js +17 -16
  54. package/out/parser/string/string.d.ts +9 -7
  55. package/out/parser/string/string.js +1 -3
  56. package/out/parser/tuple.d.ts +101 -42
  57. package/out/parser/tuple.js +107 -86
  58. package/out/scope.d.ts +44 -115
  59. package/out/scope.js +39 -188
  60. package/out/type.d.ts +63 -61
  61. package/out/type.js +30 -135
  62. package/package.json +33 -39
  63. package/__tests__/array.test.ts +0 -310
  64. package/__tests__/astUtils.test.ts +0 -17
  65. package/__tests__/badDefinitionType.test.ts +0 -51
  66. package/__tests__/basis.test.ts +0 -46
  67. package/__tests__/bounds.test.ts +0 -388
  68. package/__tests__/cast.test.ts +0 -32
  69. package/__tests__/completions.test.ts +0 -46
  70. package/__tests__/config.test.ts +0 -77
  71. package/__tests__/cyclic.test.ts +0 -144
  72. package/__tests__/dateLiteral.test.ts +0 -32
  73. package/__tests__/declared.test.ts +0 -124
  74. package/__tests__/discrimination.test.ts +0 -74
  75. package/__tests__/divisor.test.ts +0 -90
  76. package/__tests__/enclosed.test.ts +0 -93
  77. package/__tests__/examples.test.ts +0 -56
  78. package/__tests__/expressions.test.ts +0 -138
  79. package/__tests__/generateBenchData.ts +0 -89
  80. package/__tests__/generated/cyclic.ts +0 -3058
  81. package/__tests__/generic.test.ts +0 -294
  82. package/__tests__/group.test.ts +0 -72
  83. package/__tests__/hkt.test.ts +0 -22
  84. package/__tests__/imports.test.ts +0 -113
  85. package/__tests__/instanceof.test.ts +0 -102
  86. package/__tests__/intersection.test.ts +0 -104
  87. package/__tests__/jsdoc.test.ts +0 -64
  88. package/__tests__/keyTraversal.test.ts +0 -74
  89. package/__tests__/keyof.test.ts +0 -134
  90. package/__tests__/keywords.test.ts +0 -188
  91. package/__tests__/literal.test.ts +0 -51
  92. package/__tests__/match.bench.ts +0 -31
  93. package/__tests__/match.test.ts +0 -224
  94. package/__tests__/methods.bench.ts +0 -22
  95. package/__tests__/morph.test.ts +0 -409
  96. package/__tests__/narrow.test.ts +0 -102
  97. package/__tests__/nodeDefinitions.test.ts +0 -190
  98. package/__tests__/object.bench.ts +0 -28
  99. package/__tests__/objectLiteral.test.ts +0 -301
  100. package/__tests__/operand.bench.ts +0 -45
  101. package/__tests__/operator.bench.ts +0 -130
  102. package/__tests__/regex.test.ts +0 -58
  103. package/__tests__/scope.bench.ts +0 -39
  104. package/__tests__/scope.test.ts +0 -140
  105. package/__tests__/string.test.ts +0 -48
  106. package/__tests__/submodule.test.ts +0 -99
  107. package/__tests__/this.test.ts +0 -57
  108. package/__tests__/thunk.test.ts +0 -80
  109. package/__tests__/traverse.test.ts +0 -119
  110. package/__tests__/tsGenerics.test.ts +0 -12
  111. package/__tests__/typeMethods.test.ts +0 -69
  112. package/__tests__/typeReference.test.ts +0 -39
  113. package/__tests__/unenclosed.test.ts +0 -120
  114. package/__tests__/union.test.ts +0 -147
  115. package/ark.ts +0 -91
  116. package/main.ts +0 -18
  117. package/match.ts +0 -243
  118. package/out/ark.d.ts.map +0 -1
  119. package/out/ark.js.map +0 -1
  120. package/out/arkConfig.d.ts +0 -2
  121. package/out/arkConfig.d.ts.map +0 -1
  122. package/out/arkConfig.js +0 -10
  123. package/out/arkConfig.js.map +0 -1
  124. package/out/main.d.ts +0 -7
  125. package/out/main.d.ts.map +0 -1
  126. package/out/main.js +0 -4
  127. package/out/main.js.map +0 -1
  128. package/out/match.d.ts.map +0 -1
  129. package/out/match.js.map +0 -1
  130. package/out/parser/definition.d.ts.map +0 -1
  131. package/out/parser/definition.js.map +0 -1
  132. package/out/parser/generic.d.ts.map +0 -1
  133. package/out/parser/generic.js.map +0 -1
  134. package/out/parser/objectLiteral.d.ts.map +0 -1
  135. package/out/parser/objectLiteral.js.map +0 -1
  136. package/out/parser/semantic/bounds.d.ts.map +0 -1
  137. package/out/parser/semantic/bounds.js.map +0 -1
  138. package/out/parser/semantic/divisor.d.ts.map +0 -1
  139. package/out/parser/semantic/divisor.js.map +0 -1
  140. package/out/parser/semantic/intersections.d.ts +0 -14
  141. package/out/parser/semantic/intersections.d.ts.map +0 -1
  142. package/out/parser/semantic/intersections.js +0 -2
  143. package/out/parser/semantic/intersections.js.map +0 -1
  144. package/out/parser/semantic/semantic.d.ts +0 -33
  145. package/out/parser/semantic/semantic.d.ts.map +0 -1
  146. package/out/parser/semantic/semantic.js +0 -2
  147. package/out/parser/semantic/semantic.js.map +0 -1
  148. package/out/parser/semantic/utils.d.ts.map +0 -1
  149. package/out/parser/semantic/utils.js.map +0 -1
  150. package/out/parser/semantic/validate.d.ts.map +0 -1
  151. package/out/parser/semantic/validate.js.map +0 -1
  152. package/out/parser/shared.d.ts +0 -56
  153. package/out/parser/shared.d.ts.map +0 -1
  154. package/out/parser/shared.js +0 -55
  155. package/out/parser/shared.js.map +0 -1
  156. package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
  157. package/out/parser/string/reduce/dynamic.js.map +0 -1
  158. package/out/parser/string/reduce/shared.d.ts.map +0 -1
  159. package/out/parser/string/reduce/shared.js.map +0 -1
  160. package/out/parser/string/reduce/static.d.ts.map +0 -1
  161. package/out/parser/string/reduce/static.js.map +0 -1
  162. package/out/parser/string/shift/operand/date.d.ts.map +0 -1
  163. package/out/parser/string/shift/operand/date.js.map +0 -1
  164. package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  165. package/out/parser/string/shift/operand/enclosed.js.map +0 -1
  166. package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
  167. package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
  168. package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
  169. package/out/parser/string/shift/operand/operand.js.map +0 -1
  170. package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  171. package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
  172. package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
  173. package/out/parser/string/shift/operator/bounds.js.map +0 -1
  174. package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
  175. package/out/parser/string/shift/operator/divisor.js.map +0 -1
  176. package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
  177. package/out/parser/string/shift/operator/operator.js.map +0 -1
  178. package/out/parser/string/shift/scanner.d.ts.map +0 -1
  179. package/out/parser/string/shift/scanner.js.map +0 -1
  180. package/out/parser/string/string.d.ts.map +0 -1
  181. package/out/parser/string/string.js.map +0 -1
  182. package/out/parser/tuple.d.ts.map +0 -1
  183. package/out/parser/tuple.js.map +0 -1
  184. package/out/scope.d.ts.map +0 -1
  185. package/out/scope.js.map +0 -1
  186. package/out/test.d.ts +0 -2
  187. package/out/test.d.ts.map +0 -1
  188. package/out/test.js +0 -7
  189. package/out/test.js.map +0 -1
  190. package/out/tsconfig.build.tsbuildinfo +0 -1
  191. package/out/type.d.ts.map +0 -1
  192. package/out/type.js.map +0 -1
  193. package/out/util.d.ts +0 -19
  194. package/out/util.d.ts.map +0 -1
  195. package/out/util.js +0 -7
  196. package/out/util.js.map +0 -1
  197. package/parser/definition.ts +0 -159
  198. package/parser/generic.ts +0 -68
  199. package/parser/objectLiteral.ts +0 -197
  200. package/parser/semantic/bounds.ts +0 -61
  201. package/parser/semantic/divisor.ts +0 -13
  202. package/parser/semantic/intersections.ts +0 -46
  203. package/parser/semantic/semantic.ts +0 -143
  204. package/parser/semantic/utils.ts +0 -26
  205. package/parser/semantic/validate.ts +0 -109
  206. package/parser/shared.ts +0 -167
  207. package/parser/string/reduce/dynamic.ts +0 -196
  208. package/parser/string/reduce/shared.ts +0 -101
  209. package/parser/string/reduce/static.ts +0 -298
  210. package/parser/string/shift/operand/date.ts +0 -54
  211. package/parser/string/shift/operand/enclosed.ts +0 -118
  212. package/parser/string/shift/operand/genericArgs.ts +0 -127
  213. package/parser/string/shift/operand/operand.ts +0 -48
  214. package/parser/string/shift/operand/unenclosed.ts +0 -268
  215. package/parser/string/shift/operator/bounds.ts +0 -264
  216. package/parser/string/shift/operator/divisor.ts +0 -36
  217. package/parser/string/shift/operator/operator.ts +0 -82
  218. package/parser/string/shift/scanner.ts +0 -209
  219. package/parser/string/string.ts +0 -90
  220. package/parser/tuple.ts +0 -475
  221. package/scope.ts +0 -548
  222. package/type.ts +0 -349
  223. package/util.ts +0 -36
@@ -1,13 +1,13 @@
1
- import { type BoundKind, type LimitSchemaValue, type TypeNode } 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";
5
- import { writeUnpairableComparatorMessage, type Comparator, type LimitLiteral, type MaxComparator } from "../../reduce/shared.js";
5
+ import { type Comparator, type InvertedComparators, type MaxComparator, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
6
6
  import type { StaticState, state } from "../../reduce/static.js";
7
7
  import type { parseOperand } from "../operand/operand.js";
8
8
  import type { Scanner } from "../scanner.js";
9
- export declare const parseBound: (s: DynamicStateWithRoot, start: ComparatorStartChar) => undefined;
10
- export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends Scanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned> ? s["root"] extends `${infer limit extends LimitLiteral}` ? state.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<state.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
9
+ export declare const parseBound: (s: DynamicStateWithRoot, start: ComparatorStartChar) => void;
10
+ export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends (Scanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned>) ? s["root"] extends `${infer limit extends LimitLiteral}` ? state.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<state.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
11
11
  declare const oneCharComparators: {
12
12
  readonly "<": true;
13
13
  readonly ">": true;
@@ -17,17 +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 writeUnboundableMessage: <root extends string>(root: root) => `Bounded expression ${root} must be a number, string, Array, or Date`;
21
- export type writeUnboundableMessage<root extends string> = `Bounded expression ${root} must be a number, string, Array, or Date`;
22
20
  export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
23
- export declare const writeLimitMismatchMessage: (root: string, limitValue: LimitSchemaValue) => string;
24
- export declare const getBoundKinds: (comparator: Comparator, limit: LimitSchemaValue, root: TypeNode) => BoundKind[];
21
+ export declare const getBoundKinds: (comparator: Comparator, limit: LimitLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
25
22
  export declare const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
26
23
  type singleEqualsMessage = typeof singleEqualsMessage;
27
- export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) => undefined;
24
+ export declare const parseRightBound: (s: DynamicStateWithRoot, comparator: Comparator) => void;
28
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;
29
- export declare const writeInvalidLimitMessage: <comparator extends "==" | "<" | "<=" | ">" | ">=", limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => `Comparator ${comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was '${limit}')`;
30
- export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `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})`;
31
28
  export type BoundExpressionKind = "left" | "right";
32
29
  export {};
33
- //# sourceMappingURL=bounds.d.ts.map
@@ -1,18 +1,20 @@
1
- import { keywords } from "@arktype/schema";
2
- import { isKeyOf, throwParseError, tryParseNumber } from "@arktype/util";
3
- import { maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
1
+ import { internalKeywords, jsObjects, tsKeywords, writeUnboundableMessage } from "@arktype/schema";
2
+ import { isKeyOf, throwParseError } from "@arktype/util";
3
+ import { invertedComparators, maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
4
4
  import { extractDateLiteralSource, isDateLiteral } from "../operand/date.js";
5
5
  export const parseBound = (s, start) => {
6
6
  const comparator = shiftComparator(s, start);
7
- if (s.root.kind === "unit") {
7
+ if (s.root.hasKind("unit")) {
8
8
  if (typeof s.root.unit === "number") {
9
+ s.reduceLeftBound(s.root.unit, comparator);
9
10
  s.unsetRoot();
10
- return s.reduceLeftBound(s.root.unit, comparator);
11
+ return;
11
12
  }
12
13
  if (s.root.unit instanceof Date) {
13
- s.unsetRoot();
14
14
  const literal = `d'${s.root.description ?? s.root.unit.toISOString()}'`;
15
- return s.reduceLeftBound(literal, comparator);
15
+ s.unsetRoot();
16
+ s.reduceLeftBound(literal, comparator);
17
+ return;
16
18
  }
17
19
  }
18
20
  return parseRightBound(s, comparator);
@@ -26,49 +28,39 @@ export const comparatorStartChars = {
26
28
  ">": 1,
27
29
  "=": 1
28
30
  };
29
- const shiftComparator = (s, start) => s.scanner.lookaheadIs("=")
30
- ? `${start}${s.scanner.shift()}`
31
- : isKeyOf(start, oneCharComparators)
32
- ? start
31
+ const shiftComparator = (s, start) => s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}`
32
+ : isKeyOf(start, oneCharComparators) ? start
33
33
  : s.error(singleEqualsMessage);
34
- export const writeUnboundableMessage = (root) => `Bounded expression ${root} must be a number, string, Array, or Date`;
35
34
  export const writeIncompatibleRangeMessage = (l, r) => `Bound kinds ${l} and ${r} are incompatible`;
36
- export const writeLimitMismatchMessage = (root, limitValue) => `Limit '${limitValue}' cannot bound ${root}`;
37
- export const getBoundKinds = (comparator, limit, root) => {
38
- if (root.extends(keywords.number)) {
35
+ export const getBoundKinds = (comparator, limit, root, boundKind) => {
36
+ if (root.extends(tsKeywords.number)) {
39
37
  if (typeof limit !== "number") {
40
- return throwParseError(writeLimitMismatchMessage(root.toString(), limit));
38
+ return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
41
39
  }
42
- return comparator === "=="
43
- ? ["min", "max"]
44
- : comparator[0] === ">"
45
- ? ["min"]
46
- : ["max"];
40
+ return (comparator === "==" ? ["min", "max"]
41
+ : comparator[0] === ">" ? ["min"]
42
+ : ["max"]);
47
43
  }
48
- if (root.extends(keywords.string) || root.extends(keywords.Array)) {
44
+ if (root.extends(internalKeywords.lengthBoundable)) {
49
45
  if (typeof limit !== "number") {
50
- return throwParseError(writeLimitMismatchMessage(root.toString(), limit));
46
+ return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
51
47
  }
52
- return comparator === "=="
53
- ? ["minLength", "maxLength"]
54
- : comparator[0] === ">"
55
- ? ["minLength"]
56
- : ["maxLength"];
48
+ return (comparator === "==" ? ["minLength", "maxLength"]
49
+ : comparator[0] === ">" ? ["minLength"]
50
+ : ["maxLength"]);
57
51
  }
58
- if (root.extends(keywords.Date)) {
52
+ if (root.extends(jsObjects.Date)) {
59
53
  // allow either numeric or date limits
60
- return comparator === "=="
61
- ? ["after", "before"]
62
- : comparator[0] === ">"
63
- ? ["after"]
64
- : ["before"];
54
+ return (comparator === "==" ? ["after", "before"]
55
+ : comparator[0] === ">" ? ["after"]
56
+ : ["before"]);
65
57
  }
66
- return throwParseError(writeUnboundableMessage(root.toString()));
58
+ return throwParseError(writeUnboundableMessage(root.expression));
67
59
  };
68
- export const singleEqualsMessage = `= is not a valid comparator. Use == to check for equality`;
69
- const openLeftBoundToSchema = (leftBound) => ({
70
- limit: isDateLiteral(leftBound.limit)
71
- ? extractDateLiteralSource(leftBound.limit)
60
+ export const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
61
+ const openLeftBoundToRoot = (leftBound) => ({
62
+ rule: isDateLiteral(leftBound.limit) ?
63
+ extractDateLiteralSource(leftBound.limit)
72
64
  : leftBound.limit,
73
65
  exclusive: leftBound.comparator.length === 1
74
66
  });
@@ -77,30 +69,27 @@ export const parseRightBound = (s, comparator) => {
77
69
  const previousRoot = s.unsetRoot();
78
70
  const previousScannerIndex = s.scanner.location;
79
71
  s.parseOperand();
72
+ const limitNode = s.unsetRoot();
80
73
  // after parsing the next operand, use the locations to get the
81
74
  // token from which it was parsed
82
75
  const limitToken = s.scanner.sliceChars(previousScannerIndex, s.scanner.location);
83
- s.setRoot(previousRoot);
84
- const limit = tryParseNumber(limitToken) ??
85
- (isDateLiteral(limitToken)
86
- ? extractDateLiteralSource(limitToken)
87
- : s.error(writeInvalidLimitMessage(comparator, limitToken, "right")));
76
+ s.root = previousRoot;
77
+ if (!limitNode.hasKind("unit") ||
78
+ (typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date)))
79
+ return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"));
80
+ const limit = limitNode.unit;
88
81
  // apply the newly-parsed right bound
89
82
  const exclusive = comparator.length === 1;
90
83
  // if the comparator is ==, both the min and max of that pair will be applied
91
- for (const kind of getBoundKinds(comparator, limit, previousRoot)) {
92
- s.constrainRoot(kind, { limit, exclusive });
93
- }
94
- if (!s.branches.leftBound) {
84
+ for (const kind of getBoundKinds(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right"))
85
+ s.constrainRoot(kind, { rule: limit, exclusive });
86
+ if (!s.branches.leftBound)
95
87
  return;
96
- }
97
88
  // if there's an open left bound, perform additional validation and apply it
98
- if (!isKeyOf(comparator, maxComparators)) {
89
+ if (!isKeyOf(comparator, maxComparators))
99
90
  return s.error(writeUnpairableComparatorMessage(comparator));
100
- }
101
- const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot);
102
- s.constrainRoot(lowerBoundKind[0], openLeftBoundToSchema(s.branches.leftBound));
103
- delete s.branches.leftBound;
91
+ const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
92
+ s.constrainRoot(lowerBoundKind[0], openLeftBoundToRoot(s.branches.leftBound));
93
+ s.branches.leftBound = null;
104
94
  };
105
- export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was '${limit}')`;
106
- //# sourceMappingURL=bounds.js.map
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})`;
@@ -1,9 +1,7 @@
1
- import { type NumberLiteral } from "@arktype/util";
2
1
  import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
3
2
  import type { StaticState, state } from "../../reduce/static.js";
4
3
  import type { Scanner } from "../scanner.js";
5
4
  export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
6
- export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? scanned extends NumberLiteral<infer divisor> ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", scanned], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
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;
7
6
  export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
8
7
  export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
9
- //# sourceMappingURL=divisor.d.ts.map
@@ -4,10 +4,8 @@ export const parseDivisor = (s) => {
4
4
  const divisor = tryParseInteger(divisorToken, {
5
5
  errorOnFail: writeInvalidDivisorMessage(divisorToken)
6
6
  });
7
- if (divisor === 0) {
7
+ if (divisor === 0)
8
8
  s.error(writeInvalidDivisorMessage(0));
9
- }
10
9
  s.root = s.root.constrain("divisor", divisor);
11
10
  };
12
11
  export const writeInvalidDivisorMessage = (divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
13
- //# sourceMappingURL=divisor.js.map
@@ -1,5 +1,5 @@
1
1
  import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
2
- import type { state, StaticState } from "../../reduce/static.js";
2
+ import type { StaticState, state } from "../../reduce/static.js";
3
3
  import { Scanner } from "../scanner.js";
4
4
  import { parseBound, type ComparatorStartChar } from "./bounds.js";
5
5
  import { parseDivisor } from "./divisor.js";
@@ -10,4 +10,3 @@ export type writeUnexpectedCharacterMessage<char extends string, shouldBe extend
10
10
  export declare const incompleteArrayTokenMessage = "Missing expected ']'";
11
11
  type incompleteArrayTokenMessage = typeof incompleteArrayTokenMessage;
12
12
  export {};
13
- //# sourceMappingURL=operator.d.ts.map
@@ -4,26 +4,19 @@ import { comparatorStartChars, parseBound } from "./bounds.js";
4
4
  import { parseDivisor } from "./divisor.js";
5
5
  export const parseOperator = (s) => {
6
6
  const lookahead = s.scanner.shift();
7
- return lookahead === ""
8
- ? s.finalize("")
9
- : lookahead === "["
10
- ? s.scanner.shift() === "]"
11
- ? s.setRoot(s.root.array())
7
+ return (lookahead === "" ? s.finalize("")
8
+ : lookahead === "[" ?
9
+ s.scanner.shift() === "]" ?
10
+ s.setRoot(s.root.array())
12
11
  : s.error(incompleteArrayTokenMessage)
13
- : lookahead === "|" || lookahead === "&"
14
- ? s.pushRootToBranch(lookahead)
15
- : lookahead === ")"
16
- ? s.finalizeGroup()
17
- : Scanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned)
18
- ? s.finalize(lookahead)
19
- : isKeyOf(lookahead, comparatorStartChars)
20
- ? parseBound(s, lookahead)
21
- : lookahead === "%"
22
- ? parseDivisor(s)
23
- : lookahead === " "
24
- ? parseOperator(s)
25
- : s.error(writeUnexpectedCharacterMessage(lookahead));
12
+ : lookahead === "|" || lookahead === "&" ? s.pushRootToBranch(lookahead)
13
+ : lookahead === ")" ? s.finalizeGroup()
14
+ : Scanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
15
+ s.finalize(lookahead)
16
+ : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
17
+ : lookahead === "%" ? parseDivisor(s)
18
+ : lookahead === " " ? parseOperator(s)
19
+ : s.error(writeUnexpectedCharacterMessage(lookahead)));
26
20
  };
27
21
  export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
28
22
  export const incompleteArrayTokenMessage = `Missing expected ']'`;
29
- //# sourceMappingURL=operator.js.map
@@ -1,12 +1,13 @@
1
1
  import { type Dict } from "@arktype/util";
2
2
  import type { Comparator } from "../reduce/shared.js";
3
- export declare class Scanner<Lookahead extends string = string> {
3
+ export declare class Scanner<lookahead extends string = string> {
4
4
  private chars;
5
5
  private i;
6
6
  constructor(def: string);
7
7
  /** Get lookahead and advance scanner by one */
8
- shift(): Lookahead;
9
- get lookahead(): Lookahead;
8
+ shift(): lookahead;
9
+ get lookahead(): lookahead;
10
+ get nextLookahead(): string;
10
11
  get length(): number;
11
12
  shiftUntil(condition: Scanner.UntilCondition): string;
12
13
  shiftUntilNextTerminator(): string;
@@ -16,8 +17,8 @@ export declare class Scanner<Lookahead extends string = string> {
16
17
  get unscanned(): string;
17
18
  get scanned(): string;
18
19
  sliceChars(start: number, end?: number): string;
19
- lookaheadIs<Char extends Lookahead>(char: Char): this is Scanner<Char>;
20
- lookaheadIsIn<Tokens extends Dict>(tokens: Tokens): this is Scanner<Extract<keyof Tokens, string>>;
20
+ lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
21
+ lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
21
22
  }
22
23
  export declare namespace Scanner {
23
24
  type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
@@ -54,10 +55,11 @@ export declare namespace Scanner {
54
55
  const whiteSpaceTokens: {
55
56
  readonly " ": true;
56
57
  readonly "\n": true;
58
+ readonly "\t": true;
57
59
  };
58
60
  type WhiteSpaceToken = keyof typeof whiteSpaceTokens;
59
61
  const lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | ",";
60
- type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends "" | `${TerminatingChar}${string}` ? true : false : lookahead extends "," ? true : false;
62
+ type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "," ? true : false;
61
63
  type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
62
64
  type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeToken}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
63
65
  type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
@@ -68,4 +70,3 @@ export declare namespace Scanner {
68
70
  unscanned
69
71
  ];
70
72
  }
71
- //# sourceMappingURL=scanner.d.ts.map
@@ -13,6 +13,9 @@ export class Scanner {
13
13
  get lookahead() {
14
14
  return (this.chars[this.i] ?? "");
15
15
  }
16
+ get nextLookahead() {
17
+ return this.chars[this.i + 1] ?? "";
18
+ }
16
19
  get length() {
17
20
  return this.chars.length;
18
21
  }
@@ -20,12 +23,10 @@ export class Scanner {
20
23
  let shifted = "";
21
24
  while (this.lookahead) {
22
25
  if (condition(this, shifted)) {
23
- if (shifted[shifted.length - 1] === Scanner.escapeToken) {
26
+ if (shifted[shifted.length - 1] === Scanner.escapeToken)
24
27
  shifted = shifted.slice(0, -1);
25
- }
26
- else {
28
+ else
27
29
  break;
28
- }
29
30
  }
30
31
  shifted += this.shift();
31
32
  }
@@ -83,17 +84,17 @@ export class Scanner {
83
84
  Scanner.escapeToken = "\\";
84
85
  Scanner.whiteSpaceTokens = {
85
86
  " ": true,
86
- "\n": true
87
+ "\n": true,
88
+ "\t": true
87
89
  };
88
- Scanner.lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">"
89
- ? unscanned[0] === "="
90
- ? // >== would only occur in an expression like Array<number>==5
91
- // otherwise, >= would only occur as part of a bound like number>=5
92
- unscanned[1] === "="
93
- : // if > is the end of a generic instantiation, the next token will be an operator or the end of the string
94
- unscanned.trimStart() === "" ||
95
- isKeyOf(unscanned.trimStart()[0], Scanner.terminatingChars)
96
- : // if the lookahead is a finalizing token but not >, it's unambiguously a finalizer (currently just ",")
97
- lookahead === ",";
90
+ Scanner.lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
91
+ unscanned[0] === "=" ?
92
+ // >== would only occur in an expression like Array<number>==5
93
+ // otherwise, >= would only occur as part of a bound like number>=5
94
+ unscanned[1] === "="
95
+ // if > is the end of a generic instantiation, the next token will be an operator or the end of the string
96
+ : unscanned.trimStart() === "" ||
97
+ isKeyOf(unscanned.trimStart()[0], Scanner.terminatingChars)
98
+ // if the lookahead is a finalizing token but not >, it's unambiguously a finalizer (currently just ",")
99
+ : lookahead === ",";
98
100
  })(Scanner || (Scanner = {}));
99
- //# sourceMappingURL=scanner.js.map
@@ -1,19 +1,22 @@
1
- import type { TypeNode } from "@arktype/schema";
1
+ import type { BaseRoot, resolvableReferenceIn } from "@arktype/schema";
2
2
  import { type ErrorMessage } from "@arktype/util";
3
- import type { inferAstRoot } from "../semantic/semantic.js";
3
+ import type { inferAstRoot } from "../semantic/infer.js";
4
4
  import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js";
5
5
  import type { StringifiablePrefixOperator } from "./reduce/shared.js";
6
6
  import type { StaticState, state } from "./reduce/static.js";
7
7
  import type { parseOperand } from "./shift/operand/operand.js";
8
- import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.js";
8
+ import { type parseOperator, writeUnexpectedCharacterMessage } from "./shift/operator/operator.js";
9
9
  /**
10
10
  * Try to parse the definition from right to left using the most common syntax.
11
11
  * This can be much more efficient for simple definitions.
12
12
  */
13
- export type parseString<def extends string, $, args> = def extends keyof $ ? def : def extends `${infer child}[]` ? child extends keyof $ ? [child, "[]"] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
13
+ export type parseString<def extends string, $, args> = def extends keyof $ ? def : def extends `${infer child}[]` ? child extends keyof $ ? [
14
+ child,
15
+ "[]"
16
+ ] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
14
17
  export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
15
- export type BaseCompletions<$, args, otherSuggestions extends string = never> = (keyof $ & string) | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
16
- export declare const fullStringParse: (s: DynamicState) => TypeNode;
18
+ export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
19
+ export declare const fullStringParse: (s: DynamicState) => BaseRoot;
17
20
  type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
18
21
  export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
19
22
  export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
@@ -21,4 +24,3 @@ declare const next: (s: DynamicState) => void;
21
24
  type next<s extends StaticState, $, args> = s["root"] extends undefined ? parseOperand<s, $, args> : parseOperator<s, $, args>;
22
25
  export type extractFinalizedResult<s extends StaticState> = s["finalizer"] extends ErrorMessage ? s["finalizer"] : s["finalizer"] extends "" ? s["root"] : state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>;
23
26
  export {};
24
- //# sourceMappingURL=string.d.ts.map
@@ -14,10 +14,8 @@ export const fullStringParse = (s) => {
14
14
  return result;
15
15
  };
16
16
  export const parseUntilFinalizer = (s) => {
17
- while (s.finalizer === undefined) {
17
+ while (s.finalizer === undefined)
18
18
  next(s);
19
- }
20
19
  return s;
21
20
  };
22
21
  const next = (s) => s.hasRoot() ? s.parseOperator() : s.parseOperand();
23
- //# sourceMappingURL=string.js.map
@@ -1,58 +1,119 @@
1
- import { type BaseMeta, type Morph, type Out, type Predicate, type TypeNode, type extractIn, type extractOut, type inferMorphOut, type inferNarrow } from "@arktype/schema";
2
- import { type Constructor, type Domain, type List, type conform, type evaluate, type isAny } from "@arktype/util";
1
+ import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type distillConstrainableOut, type inferIntersection, type inferMorphOut, type inferPredicate } from "@arktype/schema";
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
- import type { inferIntersection } from "./semantic/intersections.js";
6
- import type { InfixOperator, PostfixExpression } from "./semantic/semantic.js";
7
- import { parseEntry, type EntryParseResult, type validateObjectValue } from "./shared.js";
5
+ import type { InfixOperator, PostfixExpression } from "./semantic/infer.js";
8
6
  import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
9
7
  import type { BaseCompletions } from "./string/string.js";
10
- export declare const parseTuple: (def: List, ctx: ParseContext) => TypeNode;
11
- export declare const parseTupleLiteral: (def: List, ctx: ParseContext) => TypeNode;
12
- export declare const maybeParseTupleExpression: (def: List, ctx: ParseContext) => TypeNode | undefined;
8
+ export declare const parseTuple: (def: array, ctx: ParseContext) => BaseRoot;
9
+ export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => BaseRoot;
13
10
  type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
14
- export type validateTuple<def extends List, $, 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 [
15
- def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator> : def[0],
16
- def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator> : def[1]
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
+ def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
13
+ def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..." | "?"> : def[1]
17
14
  ] : validateTupleLiteral<def, $, args>;
18
- export type validateTupleLiteral<def extends List, $, args, result extends unknown[] = []> = def extends readonly [infer head, ...infer tail] ? validateTupleLiteral<tail, $, args, [
19
- ...result,
20
- validateTupleElement<head, tail, $, args>
21
- ]> : result;
22
- type validateTupleElement<head, tail, $, args> = head extends variadicExpression<infer operand> ? validateDefinition<operand, $, args> extends infer syntacticResult ? syntacticResult extends operand ? semanticallyValidateRestElement<operand, $, args> extends infer semanticResult ? semanticResult extends operand ? tail extends [] ? head : prematureRestMessage : semanticResult : never : syntacticResult : never : validateObjectValue<head, $, args>;
23
- type semanticallyValidateRestElement<operand, $, args> = inferDefinition<operand, $, args> extends infer result ? result extends never ? writeNonArrayRestMessage<operand> : isAny<result> extends true ? writeNonArrayRestMessage<operand> : result extends readonly unknown[] ? operand : writeNonArrayRestMessage<operand> : never;
24
- export declare const writeNonArrayRestMessage: <operand>(operand: operand) => `Rest element ${operand extends string ? `'${operand}'` : ""} must be an array`;
25
- type writeNonArrayRestMessage<operand> = `Rest element ${operand extends string ? `'${operand}'` : ""} must be an array`;
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
+ type SequenceParseState = {
18
+ unscanned: array;
19
+ inferred: array;
20
+ validated: array;
21
+ };
22
+ type parseSequence<def extends array, $, args> = parseNextElement<{
23
+ unscanned: def;
24
+ inferred: [];
25
+ validated: [];
26
+ }, $, args>;
27
+ type PreparsedElement = {
28
+ head: unknown;
29
+ tail: array;
30
+ optional: boolean;
31
+ spread: boolean;
32
+ };
33
+ declare namespace PreparsedElement {
34
+ type from<result extends PreparsedElement> = result;
35
+ }
36
+ type preparseNextElement<s extends SequenceParseState> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? tail extends readonly ["?", ...infer postOptionalTail] ? PreparsedElement.from<{
37
+ head: head;
38
+ tail: postOptionalTail;
39
+ optional: true;
40
+ spread: true;
41
+ }> : PreparsedElement.from<{
42
+ head: head;
43
+ tail: tail;
44
+ optional: false;
45
+ spread: true;
46
+ }> : s["unscanned"] extends readonly [infer head, "?", ...infer tail] ? PreparsedElement.from<{
47
+ head: head;
48
+ tail: tail;
49
+ optional: true;
50
+ spread: false;
51
+ }> : s["unscanned"] extends readonly [infer head, ...infer tail] ? PreparsedElement.from<{
52
+ head: head;
53
+ tail: tail;
54
+ optional: false;
55
+ spread: false;
56
+ }> : null;
57
+ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s> extends infer next extends PreparsedElement ? parseNextElement<{
58
+ unscanned: next["tail"];
59
+ inferred: next["spread"] extends true ? [
60
+ ...s["inferred"],
61
+ ...conform<inferDefinition<next["head"], $, args>, array>
62
+ ] : next["optional"] extends true ? [
63
+ ...s["inferred"],
64
+ inferDefinition<next["head"], $, args>?
65
+ ] : [...s["inferred"], inferDefinition<next["head"], $, args>];
66
+ validated: [
67
+ ...s["validated"],
68
+ ...(next["spread"] extends true ? [
69
+ inferDefinition<next["head"], $, args> extends (infer spreadOperand extends array) ? [
70
+ number,
71
+ number
72
+ ] extends ([
73
+ s["inferred"]["length"],
74
+ spreadOperand["length"]
75
+ ]) ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
76
+ ] : []),
77
+ [
78
+ next["optional"] | next["spread"],
79
+ "?"
80
+ ] extends ([
81
+ false,
82
+ s["validated"][number]
83
+ ]) ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>,
84
+ ...(next["optional"] extends true ? [
85
+ next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : "?"
86
+ ] : [])
87
+ ];
88
+ }, $, args> : s;
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})` : ""}`;
26
91
  export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
27
- type prematureRestMessage = typeof multipleVariadicMesage;
28
- type inferTupleLiteral<def extends List, $, args, result extends unknown[] = []> = def extends readonly [infer head, ...infer tail] ? parseEntry<result["length"], head extends variadicExpression<infer operand> ? operand : head> extends infer entryParseResult extends EntryParseResult ? inferDefinition<entryParseResult["innerValue"], $, args> extends infer element ? head extends variadicExpression ? element extends readonly unknown[] ? inferTupleLiteral<tail, $, args, [...result, ...element]> : never : inferTupleLiteral<tail, $, args, entryParseResult["kind"] extends "optional" ? [...result, element?] : [...result, element]> : never : never : result;
29
- type variadicExpression<operandDef = unknown> = variadicStringExpression<operandDef & string> | variadicTupleExpression<operandDef>;
30
- type variadicStringExpression<operandDef extends string = string> = `...${operandDef}`;
31
- type variadicTupleExpression<operandDef = unknown> = readonly [
32
- "...",
33
- operandDef
34
- ];
35
- export type inferTuple<def extends List, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
36
- export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferNarrow<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def extends readonly ["===", ...infer values] ? values[number] : def extends readonly [
37
- "instanceof",
38
- ...infer constructors extends Constructor[]
39
- ] ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
92
+ type multipleVariadicMessage = typeof multipleVariadicMesage;
93
+ export declare const requiredPostOptionalMessage = "A required element may not follow an optional element";
94
+ type requiredPostOptionalMessage = typeof requiredPostOptionalMessage;
95
+ export declare const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
96
+ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
97
+ export declare const spreadOptionalMessage = "A spread element cannot be optional";
98
+ type spreadOptionalMessage = typeof optionalPostVariadicMessage;
99
+ export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
100
+ export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
40
101
  export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
41
102
  export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]"]>;
42
103
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
43
104
  validateDefinition<def[0], $, args>,
44
105
  def[1],
45
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<extractIn<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<extractOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? BaseMeta | string : validateDefinition<def[2], $, args>
106
+ def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<distillConstrainableIn<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<distillConstrainableOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? BaseMeta | string : validateDefinition<def[2], $, args>
46
107
  ];
47
108
  export type UnparsedTupleExpressionInput = {
48
109
  instanceof: Constructor;
49
110
  "===": unknown;
50
111
  };
51
- export type UnparsedTupleOperator = evaluate<keyof UnparsedTupleExpressionInput>;
112
+ export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
52
113
  export declare const parseKeyOfTuple: PrefixParser<"keyof">;
53
- export type inferKeyOfExpression<operandDef, $, args> = evaluate<keyof inferDefinition<operandDef, $, args>>;
54
- export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => TypeNode;
55
- export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => TypeNode;
114
+ export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
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;
56
117
  export type TupleExpression = IndexZeroExpression | IndexOneExpression;
57
118
  export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
58
119
  export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
@@ -60,12 +121,10 @@ export type TuplePostfixOperator = "[]";
60
121
  export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
61
122
  export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
62
123
  export declare const parseMorphTuple: PostfixParser<"=>">;
63
- export declare const writeMalformedFunctionalExpressionMessage: (operator: FunctionalTupleOperator, value: unknown) => string;
64
- export type parseMorph<inDef, morph, $, args> = morph extends Morph ? (In: extractIn<inferDefinition<inDef, $, args>>) => Out<inferMorphOut<ReturnType<morph>>> : never;
124
+ export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
125
+ export type parseMorph<inDef, morph, $, args> = morph extends Morph ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<inferMorphOut<morph>> : never;
65
126
  export declare const parseNarrowTuple: PostfixParser<":">;
66
- export type FunctionalTupleOperator = ":" | "=>";
67
127
  export type IndexZeroOperator = "keyof" | "instanceof" | "===";
68
128
  export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
69
- export declare const writeInvalidConstructorMessage: <actual extends "Array" | "Date" | "Error" | "Function" | "Map" | "RegExp" | "Set" | "String" | "Number" | "Boolean" | "WeakMap" | "WeakSet" | "Promise" | Domain>(actual: actual) => string;
129
+ export declare const writeInvalidConstructorMessage: <actual extends Domain | keyof import("@arktype/util").builtinConstructors>(actual: actual) => string;
70
130
  export {};
71
- //# sourceMappingURL=tuple.d.ts.map