arktype 1.1.0-dev-2 → 2.0.0-beta.1

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 (225) hide show
  1. package/LICENSE +7 -0
  2. package/out/ark.d.ts +19 -0
  3. package/out/ark.js +9 -0
  4. package/out/config.d.ts +1 -0
  5. package/out/config.js +2 -0
  6. package/out/generic.d.ts +65 -0
  7. package/out/generic.js +39 -0
  8. package/out/index.d.ts +6 -0
  9. package/out/index.js +5 -0
  10. package/out/match.d.ts +71 -0
  11. package/out/match.js +50 -0
  12. package/out/module.d.ts +14 -0
  13. package/out/module.js +2 -0
  14. package/{dist → out}/parser/definition.d.ts +16 -16
  15. package/{dist → out}/parser/definition.js +12 -12
  16. package/out/parser/objectLiteral.d.ts +79 -0
  17. package/out/parser/objectLiteral.js +100 -0
  18. package/out/parser/semantic/bounds.d.ts +15 -0
  19. package/{dist → out}/parser/semantic/bounds.js +0 -1
  20. package/out/parser/semantic/default.d.ts +8 -0
  21. package/out/parser/semantic/default.js +1 -0
  22. package/out/parser/semantic/divisor.d.ts +7 -0
  23. package/out/parser/semantic/divisor.js +1 -0
  24. package/out/parser/semantic/infer.d.ts +27 -0
  25. package/out/parser/semantic/infer.js +1 -0
  26. package/out/parser/semantic/utils.d.ts +4 -0
  27. package/out/parser/semantic/utils.js +1 -0
  28. package/out/parser/semantic/validate.d.ts +30 -0
  29. package/out/parser/semantic/validate.js +2 -0
  30. package/out/parser/string/reduce/dynamic.d.ts +43 -0
  31. package/{dist → out}/parser/string/reduce/dynamic.js +50 -33
  32. package/out/parser/string/reduce/shared.d.ts +42 -0
  33. package/{dist → out}/parser/string/reduce/shared.js +22 -2
  34. package/{dist → out}/parser/string/reduce/static.d.ts +29 -27
  35. package/out/parser/string/reduce/static.js +1 -0
  36. package/out/parser/string/shift/operand/date.d.ts +9 -0
  37. package/{dist → out}/parser/string/shift/operand/date.js +5 -8
  38. package/{dist → out}/parser/string/shift/operand/enclosed.d.ts +5 -16
  39. package/{dist → out}/parser/string/shift/operand/enclosed.js +15 -15
  40. package/out/parser/string/shift/operand/genericArgs.d.ts +28 -0
  41. package/out/parser/string/shift/operand/genericArgs.js +16 -0
  42. package/out/parser/string/shift/operand/operand.d.ts +9 -0
  43. package/out/parser/string/shift/operand/operand.js +12 -0
  44. package/out/parser/string/shift/operand/unenclosed.d.ts +30 -0
  45. package/out/parser/string/shift/operand/unenclosed.js +53 -0
  46. package/out/parser/string/shift/operator/bounds.d.ts +27 -0
  47. package/out/parser/string/shift/operator/bounds.js +94 -0
  48. package/out/parser/string/shift/operator/default.d.ts +24 -0
  49. package/out/parser/string/shift/operator/default.js +23 -0
  50. package/{dist → out}/parser/string/shift/operator/divisor.d.ts +2 -4
  51. package/{dist → out}/parser/string/shift/operator/divisor.js +2 -4
  52. package/{dist → out}/parser/string/shift/operator/operator.d.ts +4 -4
  53. package/out/parser/string/shift/operator/operator.js +22 -0
  54. package/{dist → out}/parser/string/shift/scanner.d.ts +13 -17
  55. package/{dist → out}/parser/string/shift/scanner.js +27 -24
  56. package/out/parser/string/string.d.ts +28 -0
  57. package/out/parser/string/string.js +24 -0
  58. package/out/parser/tuple.d.ts +130 -0
  59. package/out/parser/tuple.js +157 -0
  60. package/out/scope.d.ts +86 -0
  61. package/out/scope.js +132 -0
  62. package/out/type.d.ts +83 -0
  63. package/out/type.js +36 -0
  64. package/package.json +37 -41
  65. package/dist/main.d.ts +0 -11
  66. package/dist/main.d.ts.map +0 -1
  67. package/dist/main.js +0 -8
  68. package/dist/main.js.map +0 -1
  69. package/dist/match.d.ts +0 -46
  70. package/dist/match.d.ts.map +0 -1
  71. package/dist/match.js +0 -23
  72. package/dist/match.js.map +0 -1
  73. package/dist/parser/definition.d.ts.map +0 -1
  74. package/dist/parser/definition.js.map +0 -1
  75. package/dist/parser/generic.d.ts +0 -44
  76. package/dist/parser/generic.d.ts.map +0 -1
  77. package/dist/parser/generic.js +0 -46
  78. package/dist/parser/generic.js.map +0 -1
  79. package/dist/parser/objectLiteral.d.ts +0 -24
  80. package/dist/parser/objectLiteral.d.ts.map +0 -1
  81. package/dist/parser/objectLiteral.js +0 -38
  82. package/dist/parser/objectLiteral.js.map +0 -1
  83. package/dist/parser/semantic/bounds.d.ts +0 -13
  84. package/dist/parser/semantic/bounds.d.ts.map +0 -1
  85. package/dist/parser/semantic/bounds.js.map +0 -1
  86. package/dist/parser/semantic/divisor.d.ts +0 -9
  87. package/dist/parser/semantic/divisor.d.ts.map +0 -1
  88. package/dist/parser/semantic/divisor.js +0 -2
  89. package/dist/parser/semantic/divisor.js.map +0 -1
  90. package/dist/parser/semantic/intersections.d.ts +0 -15
  91. package/dist/parser/semantic/intersections.d.ts.map +0 -1
  92. package/dist/parser/semantic/intersections.js +0 -2
  93. package/dist/parser/semantic/intersections.js.map +0 -1
  94. package/dist/parser/semantic/semantic.d.ts +0 -22
  95. package/dist/parser/semantic/semantic.d.ts.map +0 -1
  96. package/dist/parser/semantic/semantic.js +0 -2
  97. package/dist/parser/semantic/semantic.js.map +0 -1
  98. package/dist/parser/semantic/utils.d.ts +0 -8
  99. package/dist/parser/semantic/utils.d.ts.map +0 -1
  100. package/dist/parser/semantic/utils.js +0 -2
  101. package/dist/parser/semantic/utils.js.map +0 -1
  102. package/dist/parser/semantic/validate.d.ts +0 -24
  103. package/dist/parser/semantic/validate.d.ts.map +0 -1
  104. package/dist/parser/semantic/validate.js +0 -2
  105. package/dist/parser/semantic/validate.js.map +0 -1
  106. package/dist/parser/shared.d.ts +0 -48
  107. package/dist/parser/shared.d.ts.map +0 -1
  108. package/dist/parser/shared.js +0 -41
  109. package/dist/parser/shared.js.map +0 -1
  110. package/dist/parser/string/reduce/dynamic.d.ts +0 -40
  111. package/dist/parser/string/reduce/dynamic.d.ts.map +0 -1
  112. package/dist/parser/string/reduce/dynamic.js.map +0 -1
  113. package/dist/parser/string/reduce/shared.d.ts +0 -29
  114. package/dist/parser/string/reduce/shared.d.ts.map +0 -1
  115. package/dist/parser/string/reduce/shared.js.map +0 -1
  116. package/dist/parser/string/reduce/static.d.ts.map +0 -1
  117. package/dist/parser/string/reduce/static.js +0 -2
  118. package/dist/parser/string/reduce/static.js.map +0 -1
  119. package/dist/parser/string/shift/operand/date.d.ts +0 -11
  120. package/dist/parser/string/shift/operand/date.d.ts.map +0 -1
  121. package/dist/parser/string/shift/operand/date.js.map +0 -1
  122. package/dist/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  123. package/dist/parser/string/shift/operand/enclosed.js.map +0 -1
  124. package/dist/parser/string/shift/operand/operand.d.ts +0 -9
  125. package/dist/parser/string/shift/operand/operand.d.ts.map +0 -1
  126. package/dist/parser/string/shift/operand/operand.js +0 -17
  127. package/dist/parser/string/shift/operand/operand.js.map +0 -1
  128. package/dist/parser/string/shift/operand/unenclosed.d.ts +0 -36
  129. package/dist/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  130. package/dist/parser/string/shift/operand/unenclosed.js +0 -68
  131. package/dist/parser/string/shift/operand/unenclosed.js.map +0 -1
  132. package/dist/parser/string/shift/operator/bounds.d.ts +0 -55
  133. package/dist/parser/string/shift/operator/bounds.d.ts.map +0 -1
  134. package/dist/parser/string/shift/operator/bounds.js +0 -95
  135. package/dist/parser/string/shift/operator/bounds.js.map +0 -1
  136. package/dist/parser/string/shift/operator/divisor.d.ts.map +0 -1
  137. package/dist/parser/string/shift/operator/divisor.js.map +0 -1
  138. package/dist/parser/string/shift/operator/operator.d.ts.map +0 -1
  139. package/dist/parser/string/shift/operator/operator.js +0 -29
  140. package/dist/parser/string/shift/operator/operator.js.map +0 -1
  141. package/dist/parser/string/shift/scanner.d.ts.map +0 -1
  142. package/dist/parser/string/shift/scanner.js.map +0 -1
  143. package/dist/parser/string/string.d.ts +0 -26
  144. package/dist/parser/string/string.d.ts.map +0 -1
  145. package/dist/parser/string/string.js +0 -31
  146. package/dist/parser/string/string.js.map +0 -1
  147. package/dist/parser/tuple.d.ts +0 -73
  148. package/dist/parser/tuple.d.ts.map +0 -1
  149. package/dist/parser/tuple.js +0 -134
  150. package/dist/parser/tuple.js.map +0 -1
  151. package/dist/scope.d.ts +0 -159
  152. package/dist/scope.d.ts.map +0 -1
  153. package/dist/scope.js +0 -248
  154. package/dist/scope.js.map +0 -1
  155. package/dist/scopes/ark.d.ts +0 -38
  156. package/dist/scopes/ark.d.ts.map +0 -1
  157. package/dist/scopes/ark.js +0 -24
  158. package/dist/scopes/ark.js.map +0 -1
  159. package/dist/scopes/jsObjects.d.ts +0 -19
  160. package/dist/scopes/jsObjects.d.ts.map +0 -1
  161. package/dist/scopes/jsObjects.js +0 -15
  162. package/dist/scopes/jsObjects.js.map +0 -1
  163. package/dist/scopes/parsing.d.ts +0 -18
  164. package/dist/scopes/parsing.d.ts.map +0 -1
  165. package/dist/scopes/parsing.js +0 -61
  166. package/dist/scopes/parsing.js.map +0 -1
  167. package/dist/scopes/tsGenerics.d.ts +0 -17
  168. package/dist/scopes/tsGenerics.d.ts.map +0 -1
  169. package/dist/scopes/tsGenerics.js +0 -13
  170. package/dist/scopes/tsGenerics.js.map +0 -1
  171. package/dist/scopes/tsKeywords.d.ts +0 -24
  172. package/dist/scopes/tsKeywords.d.ts.map +0 -1
  173. package/dist/scopes/tsKeywords.js +0 -20
  174. package/dist/scopes/tsKeywords.js.map +0 -1
  175. package/dist/scopes/utils/creditCard.d.ts +0 -3
  176. package/dist/scopes/utils/creditCard.d.ts.map +0 -1
  177. package/dist/scopes/utils/creditCard.js +0 -36
  178. package/dist/scopes/utils/creditCard.js.map +0 -1
  179. package/dist/scopes/utils/date.d.ts +0 -24
  180. package/dist/scopes/utils/date.d.ts.map +0 -1
  181. package/dist/scopes/utils/date.js +0 -53
  182. package/dist/scopes/utils/date.js.map +0 -1
  183. package/dist/scopes/validation.d.ts +0 -20
  184. package/dist/scopes/validation.d.ts.map +0 -1
  185. package/dist/scopes/validation.js +0 -57
  186. package/dist/scopes/validation.js.map +0 -1
  187. package/dist/type.d.ts +0 -101
  188. package/dist/type.d.ts.map +0 -1
  189. package/dist/type.js +0 -138
  190. package/dist/type.js.map +0 -1
  191. package/main.ts +0 -20
  192. package/match.ts +0 -137
  193. package/parser/definition.ts +0 -156
  194. package/parser/generic.ts +0 -208
  195. package/parser/objectLiteral.ts +0 -120
  196. package/parser/semantic/bounds.ts +0 -63
  197. package/parser/semantic/divisor.ts +0 -13
  198. package/parser/semantic/intersections.ts +0 -47
  199. package/parser/semantic/semantic.ts +0 -107
  200. package/parser/semantic/utils.ts +0 -26
  201. package/parser/semantic/validate.ts +0 -105
  202. package/parser/shared.ts +0 -141
  203. package/parser/string/reduce/dynamic.ts +0 -181
  204. package/parser/string/reduce/shared.ts +0 -73
  205. package/parser/string/reduce/static.ts +0 -300
  206. package/parser/string/shift/operand/date.ts +0 -57
  207. package/parser/string/shift/operand/enclosed.ts +0 -119
  208. package/parser/string/shift/operand/operand.ts +0 -48
  209. package/parser/string/shift/operand/unenclosed.ts +0 -282
  210. package/parser/string/shift/operator/bounds.ts +0 -229
  211. package/parser/string/shift/operator/divisor.ts +0 -36
  212. package/parser/string/shift/operator/operator.ts +0 -82
  213. package/parser/string/shift/scanner.ts +0 -209
  214. package/parser/string/string.ts +0 -93
  215. package/parser/tuple.ts +0 -475
  216. package/scope.ts +0 -573
  217. package/scopes/ark.ts +0 -64
  218. package/scopes/jsObjects.ts +0 -29
  219. package/scopes/parsing.ts +0 -81
  220. package/scopes/tsGenerics.ts +0 -28
  221. package/scopes/tsKeywords.ts +0 -39
  222. package/scopes/utils/creditCard.ts +0 -37
  223. package/scopes/utils/date.ts +0 -108
  224. package/scopes/validation.ts +0 -81
  225. package/type.ts +0 -403
@@ -0,0 +1,7 @@
1
+ import type { SchemaRoot, writeIndivisibleMessage } from "@ark/schema";
2
+ import type { ErrorMessage } from "@ark/util";
3
+ import type { inferAstIn } from "./infer.js";
4
+ import type { validateAst } from "./validate.js";
5
+ export type validateDivisor<l, $, args> = inferAstIn<l, $, args> extends infer data ? [
6
+ data
7
+ ] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<SchemaRoot<data>>> : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { Date, DateLiteral, Default, GenericProps, LimitLiteral, RegexLiteral, constrain, distillIn, distillOut, inferIntersection, normalizeLimit, string } from "@ark/schema";
2
+ import type { BigintLiteral, Hkt, array } from "@ark/util";
3
+ import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.js";
4
+ import type { inferDefinition } from "../definition.js";
5
+ import type { Comparator, MinComparator } from "../string/reduce/shared.js";
6
+ import type { StringLiteral } from "../string/shift/operand/enclosed.js";
7
+ export type inferAstRoot<ast, $, args> = inferConstrainableAst<ast, $, args>;
8
+ export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
9
+ export type inferAstOut<ast, $, args> = distillOut<inferAstRoot<ast, $, args>>;
10
+ export type inferConstrainableAst<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : ast extends string ? inferTerminal<ast, $, args> : never;
11
+ export type GenericInstantiationAst<generic extends GenericProps = GenericProps, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
12
+ export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer generic, infer argAsts> ? generic extends Hkt.Kind ? Hkt.apply<generic, {
13
+ [i in keyof argAsts]: inferConstrainableAst<argAsts[i], $, args>;
14
+ }> : inferDefinition<generic["bodyDef"], generic["$"]["t"] extends UnparsedScope ? $ : generic["$"]["t"], {
15
+ [i in keyof generic["params"] & `${number}` as generic["names"][i & keyof generic["names"]]]: inferConstrainableAst<argAsts[i & keyof argAsts], $, args>;
16
+ }> : ast[1] extends "[]" ? inferConstrainableAst<ast[0], $, args>[] : ast[1] extends "|" ? inferConstrainableAst<ast[0], $, args> | inferConstrainableAst<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferConstrainableAst<ast[0], $, args>, inferConstrainableAst<ast[2], $, args>> : ast[1] extends "=" ? inferTerminal<ast[2] & string, $, args> extends infer defaultValue ? (In?: inferConstrainableAst<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferConstrainableAst<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferConstrainableAst<ast[0], $, args>, ast[1], ast[2]> : ast[1] extends "%" ? constrain<inferConstrainableAst<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferConstrainableAst<ast[1], $, args> : never;
17
+ export type constrainBound<constrainableIn, comparator extends Comparator, limit> = distillIn<constrainableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : constrain<constrainableIn, "exactLength", limit & number> : constrain<constrainableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
18
+ rule: normalizeLimit<limit>;
19
+ exclusive: comparator extends ">" | "<" ? true : false;
20
+ }> : never;
21
+ export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
22
+ export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
23
+ export type PostfixOperator = "[]";
24
+ export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
25
+ export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
26
+ export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
27
+ export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof ArkEnv.$ ? ArkEnv.$[token] : `#${token}` extends keyof $ ? resolve<`#${token}`, $, args> : token extends StringLiteral<infer text> ? text : token extends `${infer n extends number}` ? n : token extends BigintLiteral<infer b> ? b : token extends RegexLiteral<infer source> ? string.matching<source> : token extends DateLiteral<infer source> ? Date.literal<source> : tryInferSubmoduleReference<$, token>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { Stringifiable } from "@ark/util";
2
+ import type { Comparator } from "../string/reduce/shared.js";
3
+ import type { InfixExpression, PostfixExpression } from "./infer.js";
4
+ export type astToString<ast> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { arkKind, GenericParamAst, GenericProps, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
2
+ import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
3
+ import type { Generic } from "../../generic.js";
4
+ import type { Comparator } from "../string/reduce/shared.js";
5
+ import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.js";
6
+ import type { UnitLiteral } from "../string/shift/operator/default.js";
7
+ import type { parseString } from "../string/string.js";
8
+ import type { validateRange } from "./bounds.js";
9
+ import type { validateDefault } from "./default.js";
10
+ import type { validateDivisor } from "./divisor.js";
11
+ import type { GenericInstantiationAst, inferAstRoot, InfixExpression, PostfixExpression } from "./infer.js";
12
+ import type { astToString } from "./utils.js";
13
+ export type validateAst<ast, $, args> = ast extends string ? validateStringAst<ast, $> : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends (readonly [infer baseAst, "=", infer unitLiteral extends UnitLiteral]) ? validateDefault<baseAst, unitLiteral, $, args> : ast extends readonly ["keyof", infer operand] ? validateAst<operand, $, args> : ast extends (GenericInstantiationAst<Generic<infer params, any, any> | GenericProps<infer params>, infer argAsts>) ? validateGenericArgs<params, argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
14
+ ast: ast;
15
+ };
16
+ type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
17
+ type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
18
+ export declare const writeUnsatisfiableExpressionError: <expression extends string>(expression: expression) => writeUnsatisfiableExpressionError<expression>;
19
+ export type writeUnsatisfiableExpressionError<expression extends string> = `${expression} results in an unsatisfiable type`;
20
+ export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
21
+ export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
22
+ type validateStringAst<def extends string, $> = def extends `${infer n extends number}` ? number extends n ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral<infer b> ? bigint extends b ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : maybeExtractAlias<def, $> extends infer alias extends keyof $ ? [
23
+ $[alias]
24
+ ] extends [anyOrNever] ? def : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : $[alias] extends GenericProps ? ErrorMessage<writeInvalidGenericArgCountMessage<def, $[alias]["names"], []>> : $[alias] extends {
25
+ [arkKind]: "module";
26
+ } ? ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
27
+ export type maybeExtractAlias<def extends string, $> = def extends keyof $ ? def : `#${def}` extends keyof $ ? `#${def}` : null;
28
+ export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
29
+ type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : validateAst<ast[2], $, args> extends ErrorMessage<infer message> ? ErrorMessage<message> : undefined;
30
+ export {};
@@ -0,0 +1,2 @@
1
+ export const writeUnsatisfiableExpressionError = (expression) => `${expression} results in an unsatisfiable type`;
2
+ export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
@@ -0,0 +1,43 @@
1
+ import type { BaseRoot, LimitLiteral } from "@ark/schema";
2
+ import { type requireKeys } from "@ark/util";
3
+ import type { ParseContext } from "../../../scope.js";
4
+ import type { InfixOperator } from "../../semantic/infer.js";
5
+ import type { Scanner } from "../shift/scanner.js";
6
+ import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.js";
7
+ type BranchState = {
8
+ prefixes: StringifiablePrefixOperator[];
9
+ leftBound: OpenLeftBound | null;
10
+ intersection: BaseRoot | null;
11
+ union: BaseRoot | null;
12
+ };
13
+ export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
14
+ export declare class DynamicState {
15
+ readonly scanner: Scanner;
16
+ readonly ctx: ParseContext;
17
+ readonly defaultable: boolean;
18
+ root: BaseRoot<any> | undefined;
19
+ branches: BranchState;
20
+ finalizer: Scanner.FinalizingLookahead | undefined;
21
+ groups: BranchState[];
22
+ constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
23
+ error(message: string): never;
24
+ hasRoot(): this is DynamicStateWithRoot;
25
+ setRoot(root: BaseRoot): void;
26
+ unsetRoot(): this["root"];
27
+ constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
28
+ finalize(finalizer: Scanner.FinalizingLookahead): void;
29
+ reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
30
+ finalizeBranches(): void;
31
+ finalizeGroup(): void;
32
+ addPrefix(prefix: StringifiablePrefixOperator): void;
33
+ applyPrefixes(): void;
34
+ pushRootToBranch(token: "|" | "&"): void;
35
+ parseUntilFinalizer(): DynamicStateWithRoot;
36
+ parseOperator(this: DynamicStateWithRoot): void;
37
+ parseOperand(): void;
38
+ private assertRangeUnset;
39
+ reduceGroupOpen(): void;
40
+ previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
41
+ shiftedByOne(): this;
42
+ }
43
+ export {};
@@ -1,19 +1,26 @@
1
- import { isKeyOf, throwInternalError, throwParseError } from "@arktype/util";
2
- import { invertedComparators, minComparators } from "../shift/operator/bounds.js";
3
- import { Scanner } from "../shift/scanner.js";
4
- import { writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
1
+ import { isKeyOf, throwInternalError, throwParseError } from "@ark/util";
2
+ import { parseOperand } from "../shift/operand/operand.js";
3
+ import { parseOperator } from "../shift/operator/operator.js";
4
+ import { parseUntilFinalizer } from "../string.js";
5
+ import { invertedComparators, minComparators, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
5
6
  export class DynamicState {
6
- ctx;
7
7
  scanner;
8
+ ctx;
9
+ defaultable;
10
+ // set root type to `any` so that all constraints can be applied
8
11
  root;
9
12
  branches = {
10
- prefixes: []
13
+ prefixes: [],
14
+ leftBound: null,
15
+ intersection: null,
16
+ union: null
11
17
  };
12
18
  finalizer;
13
19
  groups = [];
14
- constructor(def, ctx) {
20
+ constructor(scanner, ctx, defaultable) {
21
+ this.scanner = scanner;
15
22
  this.ctx = ctx;
16
- this.scanner = new Scanner(def);
23
+ this.defaultable = defaultable;
17
24
  }
18
25
  error(message) {
19
26
  return throwParseError(message);
@@ -21,29 +28,27 @@ export class DynamicState {
21
28
  hasRoot() {
22
29
  return this.root !== undefined;
23
30
  }
31
+ setRoot(root) {
32
+ this.root = root;
33
+ }
24
34
  unsetRoot() {
25
35
  const value = this.root;
26
36
  this.root = undefined;
27
37
  return value;
28
38
  }
29
39
  constrainRoot(...args) {
30
- this.root = this.root.constrain(...args);
31
- }
32
- setRoot(root) {
33
- this.root = root;
40
+ this.root = this.root.constrain(args[0], args[1]);
34
41
  }
35
42
  finalize(finalizer) {
36
- if (this.groups.length) {
43
+ if (this.groups.length)
37
44
  return this.error(writeUnclosedGroupMessage(")"));
38
- }
39
45
  this.finalizeBranches();
40
46
  this.finalizer = finalizer;
41
47
  }
42
48
  reduceLeftBound(limit, comparator) {
43
49
  const invertedComparator = invertedComparators[comparator];
44
- if (!isKeyOf(invertedComparator, minComparators)) {
50
+ if (!isKeyOf(invertedComparator, minComparators))
45
51
  return this.error(writeUnpairableComparatorMessage(comparator));
46
- }
47
52
  if (this.branches.leftBound) {
48
53
  return this.error(writeMultipleLeftBoundsMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
49
54
  }
@@ -54,24 +59,22 @@ export class DynamicState {
54
59
  }
55
60
  finalizeBranches() {
56
61
  this.assertRangeUnset();
57
- if (this.branches["|"]) {
62
+ if (this.branches.union) {
58
63
  this.pushRootToBranch("|");
59
- this.root = this.branches["|"];
64
+ this.root = this.branches.union;
60
65
  }
61
- else if (this.branches["&"]) {
66
+ else if (this.branches.intersection) {
62
67
  this.pushRootToBranch("&");
63
- this.root = this.branches["&"];
68
+ this.root = this.branches.intersection;
64
69
  }
65
- else {
70
+ else
66
71
  this.applyPrefixes();
67
- }
68
72
  }
69
73
  finalizeGroup() {
70
74
  this.finalizeBranches();
71
75
  const topBranchState = this.groups.pop();
72
- if (!topBranchState) {
76
+ if (!topBranchState)
73
77
  return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned));
74
- }
75
78
  this.branches = topBranchState;
76
79
  }
77
80
  addPrefix(prefix) {
@@ -81,8 +84,8 @@ export class DynamicState {
81
84
  while (this.branches.prefixes.length) {
82
85
  const lastPrefix = this.branches.prefixes.pop();
83
86
  this.root =
84
- lastPrefix === "keyof"
85
- ? this.root.keyof()
87
+ lastPrefix === "keyof" ?
88
+ this.root.keyof()
86
89
  : throwInternalError(`Unexpected prefix '${lastPrefix}'`);
87
90
  }
88
91
  }
@@ -90,14 +93,24 @@ export class DynamicState {
90
93
  this.assertRangeUnset();
91
94
  this.applyPrefixes();
92
95
  const root = this.root;
93
- this.branches["&"] = this.branches["&"]?.and(root) ?? root;
96
+ this.branches.intersection = this.branches.intersection?.and(root) ?? root;
94
97
  if (token === "|") {
95
- this.branches["|"] =
96
- this.branches["|"]?.or(this.branches["&"]) ?? this.branches["&"];
97
- delete this.branches["&"];
98
+ this.branches.union =
99
+ this.branches.union?.or(this.branches.intersection) ??
100
+ this.branches.intersection;
101
+ this.branches.intersection = null;
98
102
  }
99
103
  this.root = undefined;
100
104
  }
105
+ parseUntilFinalizer() {
106
+ return parseUntilFinalizer(new DynamicState(this.scanner, this.ctx, false));
107
+ }
108
+ parseOperator() {
109
+ return parseOperator(this);
110
+ }
111
+ parseOperand() {
112
+ return parseOperand(this);
113
+ }
101
114
  assertRangeUnset() {
102
115
  if (this.branches.leftBound) {
103
116
  return this.error(writeOpenRangeMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator));
@@ -106,17 +119,21 @@ export class DynamicState {
106
119
  reduceGroupOpen() {
107
120
  this.groups.push(this.branches);
108
121
  this.branches = {
109
- prefixes: []
122
+ prefixes: [],
123
+ leftBound: null,
124
+ union: null,
125
+ intersection: null
110
126
  };
111
127
  }
112
128
  previousOperator() {
113
129
  return (this.branches.leftBound?.comparator ??
114
130
  this.branches.prefixes.at(-1) ??
115
- (this.branches["&"] ? "&" : this.branches["|"] ? "|" : undefined));
131
+ (this.branches.intersection ? "&"
132
+ : this.branches.union ? "|"
133
+ : undefined));
116
134
  }
117
135
  shiftedByOne() {
118
136
  this.scanner.shift();
119
137
  return this;
120
138
  }
121
139
  }
122
- //# sourceMappingURL=dynamic.js.map
@@ -0,0 +1,42 @@
1
+ import type { LimitLiteral } from "@ark/schema";
2
+ export type StringifiablePrefixOperator = "keyof";
3
+ export declare const minComparators: {
4
+ readonly ">": true;
5
+ readonly ">=": true;
6
+ };
7
+ export type MinComparator = keyof typeof minComparators;
8
+ export declare const maxComparators: {
9
+ readonly "<": true;
10
+ readonly "<=": true;
11
+ };
12
+ export type MaxComparator = keyof typeof maxComparators;
13
+ export declare const comparators: {
14
+ ">": boolean;
15
+ ">=": boolean;
16
+ "<": boolean;
17
+ "<=": boolean;
18
+ "==": boolean;
19
+ };
20
+ export type Comparator = keyof typeof comparators;
21
+ export declare const invertedComparators: InvertedComparators;
22
+ export type InvertedComparators = {
23
+ "<": ">";
24
+ ">": "<";
25
+ "<=": ">=";
26
+ ">=": "<=";
27
+ "==": "==";
28
+ };
29
+ export type OpenLeftBound = {
30
+ limit: LimitLiteral;
31
+ comparator: MinComparator;
32
+ };
33
+ export declare const writeUnmatchedGroupCloseMessage: <unscanned extends string>(unscanned: unscanned) => writeUnmatchedGroupCloseMessage<unscanned>;
34
+ export type writeUnmatchedGroupCloseMessage<unscanned extends string> = `Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`;
35
+ export declare const writeUnclosedGroupMessage: <missingChar extends string>(missingChar: missingChar) => writeUnclosedGroupMessage<missingChar>;
36
+ export type writeUnclosedGroupMessage<missingChar extends string> = `Missing ${missingChar}`;
37
+ export declare const writeOpenRangeMessage: <min extends LimitLiteral, comparator extends MinComparator>(min: min, comparator: comparator) => writeOpenRangeMessage<min, comparator>;
38
+ export type writeOpenRangeMessage<min extends LimitLiteral, comparator extends MinComparator> = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
39
+ export type writeUnpairableComparatorMessage<comparator extends Comparator> = `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
40
+ export declare const writeUnpairableComparatorMessage: <comparator extends Comparator>(comparator: comparator) => writeUnpairableComparatorMessage<comparator>;
41
+ export declare const writeMultipleLeftBoundsMessage: <openLimit extends LimitLiteral, openComparator extends MinComparator, limit extends LimitLiteral, comparator extends MinComparator>(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) => writeMultipleLeftBoundsMessage<openLimit, openComparator, limit, comparator>;
42
+ export type writeMultipleLeftBoundsMessage<openLimit extends LimitLiteral, openComparator extends MinComparator, limit extends LimitLiteral, comparator extends MinComparator> = `An expression may have at most one left bound (parsed ${openLimit}${InvertedComparators[openComparator]}, ${limit}${InvertedComparators[comparator]})`;
@@ -1,7 +1,27 @@
1
- import { invertedComparators } from "../shift/operator/bounds.js";
1
+ export const minComparators = {
2
+ ">": true,
3
+ ">=": true
4
+ };
5
+ export const maxComparators = {
6
+ "<": true,
7
+ "<=": true
8
+ };
9
+ export const comparators = {
10
+ ">": true,
11
+ ">=": true,
12
+ "<": true,
13
+ "<=": true,
14
+ "==": true
15
+ };
16
+ export const invertedComparators = {
17
+ "<": ">",
18
+ ">": "<",
19
+ "<=": ">=",
20
+ ">=": "<=",
21
+ "==": "=="
22
+ };
2
23
  export const writeUnmatchedGroupCloseMessage = (unscanned) => `Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`)}`;
3
24
  export const writeUnclosedGroupMessage = (missingChar) => `Missing ${missingChar}`;
4
25
  export const writeOpenRangeMessage = (min, comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
5
26
  export const writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
6
27
  export const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`;
7
- //# sourceMappingURL=shared.js.map
@@ -1,7 +1,7 @@
1
- import type { Completion, defined, ErrorMessage } from "@arktype/util";
2
- import type { Comparator, InvertedComparators, LimitLiteral, MaxComparator, MinComparator } from "../shift/operator/bounds.js";
1
+ import type { LimitLiteral } from "@ark/schema";
2
+ import type { Completion, ErrorMessage, defined } from "@ark/util";
3
3
  import type { Scanner } from "../shift/scanner.js";
4
- import type { OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
4
+ import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
5
5
  export type StaticState = {
6
6
  root: unknown;
7
7
  branches: BranchState;
@@ -10,13 +10,13 @@ export type StaticState = {
10
10
  scanned: string;
11
11
  unscanned: string;
12
12
  };
13
- export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
14
13
  type BranchState = {
15
14
  prefixes: StringifiablePrefixOperator[];
16
15
  leftBound: OpenLeftBound | undefined;
17
- "&": unknown;
18
- "|": unknown;
16
+ intersection: unknown;
17
+ union: unknown;
19
18
  };
19
+ export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
20
20
  export declare namespace state {
21
21
  export type initialize<def extends string> = from<{
22
22
  root: undefined;
@@ -27,7 +27,7 @@ export declare namespace state {
27
27
  unscanned: def;
28
28
  }>;
29
29
  export type error<message extends string> = from<{
30
- root: undefined;
30
+ root: ErrorMessage<message>;
31
31
  branches: initialBranches;
32
32
  groups: [];
33
33
  finalizer: ErrorMessage<message>;
@@ -35,7 +35,7 @@ export declare namespace state {
35
35
  unscanned: "";
36
36
  }>;
37
37
  export type completion<text extends string> = from<{
38
- root: undefined;
38
+ root: Completion<text>;
39
39
  branches: initialBranches;
40
40
  groups: [];
41
41
  finalizer: Completion<text>;
@@ -45,8 +45,8 @@ export declare namespace state {
45
45
  type initialBranches = branchesFrom<{
46
46
  prefixes: [];
47
47
  leftBound: undefined;
48
- "&": undefined;
49
- "|": undefined;
48
+ intersection: undefined;
49
+ union: undefined;
50
50
  }>;
51
51
  type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
52
52
  export type setRoot<s extends StaticState, root, unscanned extends string> = from<{
@@ -62,8 +62,8 @@ export declare namespace state {
62
62
  branches: {
63
63
  prefixes: [...s["branches"]["prefixes"], prefix];
64
64
  leftBound: s["branches"]["leftBound"];
65
- "&": s["branches"]["&"];
66
- "|": s["branches"]["|"];
65
+ intersection: s["branches"]["intersection"];
66
+ union: s["branches"]["union"];
67
67
  };
68
68
  groups: s["groups"];
69
69
  finalizer: s["finalizer"];
@@ -75,8 +75,8 @@ export declare namespace state {
75
75
  branches: {
76
76
  prefixes: [];
77
77
  leftBound: undefined;
78
- "&": token extends "&" ? mergeToIntersection<s> : undefined;
79
- "|": token extends "|" ? mergeToUnion<s> : s["branches"]["|"];
78
+ intersection: token extends "&" ? mergeToIntersection<s> : undefined;
79
+ union: token extends "|" ? mergeToUnion<s> : s["branches"]["union"];
80
80
  };
81
81
  groups: s["groups"];
82
82
  finalizer: s["finalizer"];
@@ -91,8 +91,8 @@ export declare namespace state {
91
91
  limit: limit;
92
92
  comparator: InvertedComparators[comparator];
93
93
  };
94
- "&": s["branches"]["&"];
95
- "|": s["branches"]["|"];
94
+ intersection: s["branches"]["intersection"];
95
+ union: s["branches"]["union"];
96
96
  };
97
97
  groups: s["groups"];
98
98
  finalizer: s["finalizer"];
@@ -104,30 +104,33 @@ export declare namespace state {
104
104
  branches: {
105
105
  prefixes: s["branches"]["prefixes"];
106
106
  leftBound: undefined;
107
- "&": s["branches"]["&"];
108
- "|": s["branches"]["|"];
107
+ intersection: s["branches"]["intersection"];
108
+ union: s["branches"]["union"];
109
109
  };
110
110
  groups: s["groups"];
111
111
  finalizer: s["finalizer"];
112
112
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
113
113
  unscanned: unscanned;
114
114
  }>;
115
- export type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends LimitLiteral, unscanned extends string> = state.from<{
115
+ export type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends number | string, unscanned extends string> = state.from<{
116
116
  root: [s["root"], comparator, limit];
117
117
  branches: {
118
118
  prefixes: s["branches"]["prefixes"];
119
119
  leftBound: undefined;
120
- "&": s["branches"]["&"];
121
- "|": s["branches"]["|"];
120
+ intersection: s["branches"]["intersection"];
121
+ union: s["branches"]["union"];
122
122
  };
123
123
  groups: s["groups"];
124
124
  finalizer: s["finalizer"];
125
125
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
126
126
  unscanned: unscanned;
127
127
  }>;
128
- type mergeToUnion<s extends StaticState> = s["branches"]["|"] extends undefined ? mergeToIntersection<s> : [s["branches"]["|"], "|", mergeToIntersection<s>];
129
- type mergeToIntersection<s extends StaticState> = s["branches"]["&"] extends undefined ? mergePrefixes<s> : [s["branches"]["&"], "&", mergePrefixes<s>];
130
- type mergePrefixes<s extends StaticState, remaining extends unknown[] = s["branches"]["prefixes"]> = remaining extends [infer head, ...infer tail] ? [head, mergePrefixes<s, tail>] : s["root"];
128
+ type mergeToUnion<s extends StaticState> = s["branches"]["union"] extends undefined ? mergeToIntersection<s> : [s["branches"]["union"], "|", mergeToIntersection<s>];
129
+ type mergeToIntersection<s extends StaticState> = s["branches"]["intersection"] extends undefined ? mergePrefixes<s> : [s["branches"]["intersection"], "&", mergePrefixes<s>];
130
+ type mergePrefixes<s extends StaticState, remaining extends unknown[] = s["branches"]["prefixes"]> = remaining extends [infer head, ...infer tail] ? [
131
+ head,
132
+ mergePrefixes<s, tail>
133
+ ] : s["root"];
131
134
  type popGroup<stack extends BranchState[], top extends BranchState> = [
132
135
  ...stack,
133
136
  top
@@ -157,10 +160,10 @@ export declare namespace state {
157
160
  unscanned: s["unscanned"];
158
161
  }> : state.error<writeUnclosedGroupMessage<")">>;
159
162
  type openRangeError<range extends defined<BranchState["leftBound"]>> = state.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
160
- export type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends [
163
+ export type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends ([
161
164
  ...unknown[],
162
165
  infer tail extends string
163
- ] ? tail : s["branches"]["&"] extends {} ? "&" : s["branches"]["|"] extends {} ? "|" : undefined;
166
+ ]) ? tail : s["branches"]["intersection"] extends {} ? "&" : s["branches"]["union"] extends {} ? "|" : undefined;
164
167
  export type scanTo<s extends StaticState, unscanned extends string> = from<{
165
168
  root: s["root"];
166
169
  branches: s["branches"];
@@ -174,4 +177,3 @@ export declare namespace state {
174
177
  export {};
175
178
  }
176
179
  export {};
177
- //# sourceMappingURL=static.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { DateLiteral } from "@ark/schema";
2
+ export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
3
+ export declare const isValidDate: (d: Date) => boolean;
4
+ export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
5
+ export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
6
+ export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
7
+ export type DateInput = ConstructorParameters<typeof Date>[0];
8
+ export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
9
+ export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
@@ -1,4 +1,4 @@
1
- import { throwParseError, tryParseNumber } from "@arktype/util";
1
+ import { throwParseError, tryParseNumber } from "@ark/util";
2
2
  export const isDateLiteral = (value) => typeof value === "string" &&
3
3
  value[0] === "d" &&
4
4
  (value[1] === "'" || value[1] === '"') &&
@@ -9,18 +9,15 @@ export const writeInvalidDateMessage = (source) => `'${source}' could not be par
9
9
  export const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
10
10
  const maybeParseDate = (source, errorOnFail) => {
11
11
  const stringParsedDate = new Date(source);
12
- if (isValidDate(stringParsedDate)) {
12
+ if (isValidDate(stringParsedDate))
13
13
  return stringParsedDate;
14
- }
15
14
  const epochMillis = tryParseNumber(source);
16
15
  if (epochMillis !== undefined) {
17
16
  const numberParsedDate = new Date(epochMillis);
18
- if (isValidDate(numberParsedDate)) {
17
+ if (isValidDate(numberParsedDate))
19
18
  return numberParsedDate;
20
- }
21
19
  }
22
- return errorOnFail
23
- ? throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
20
+ return errorOnFail ?
21
+ throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
24
22
  : undefined;
25
23
  };
26
- //# sourceMappingURL=date.js.map
@@ -1,20 +1,20 @@
1
1
  import type { DynamicState } 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 type { Scanner } from "../scanner.js";
4
4
  export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
5
5
  export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
6
6
  export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
7
- export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => undefined;
8
- export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
7
+ export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingStartToken) => void;
8
+ export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntil<unscanned, EnclosingTokens[enclosingStart]> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? nextUnscanned extends "" ? state.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : state.setRoot<s, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
9
9
  export declare const enclosingQuote: {
10
10
  readonly "'": 1;
11
11
  readonly '"': 1;
12
12
  };
13
13
  export type EnclosingQuote = keyof typeof enclosingQuote;
14
14
  export declare const enclosingChar: {
15
+ readonly "/": 1;
15
16
  readonly "'": 1;
16
17
  readonly '"': 1;
17
- readonly "/": 1;
18
18
  };
19
19
  export declare const enclosingTokens: {
20
20
  readonly "d'": "'";
@@ -33,17 +33,6 @@ declare const enclosingCharDescriptions: {
33
33
  readonly "/": "forward slash";
34
34
  };
35
35
  type enclosingCharDescriptions = typeof enclosingCharDescriptions;
36
- export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends "/" | "'" | "\"" | "d'" | "d\"">(fragment: fragment, enclosingStart: enclosingStart) => `${enclosingStart}${fragment} requires a closing ${{
37
- readonly '"': "double-quote";
38
- readonly "'": "single-quote";
39
- readonly "/": "forward slash";
40
- }[{
41
- readonly "d'": "'";
42
- readonly 'd"': "\"";
43
- readonly "'": "'";
44
- readonly '"': "\"";
45
- readonly "/": "/";
46
- }[enclosingStart]]}`;
36
+ export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosingStart extends EnclosingStartToken>(fragment: fragment, enclosingStart: enclosingStart) => writeUnterminatedEnclosedMessage<fragment, enclosingStart>;
47
37
  export type writeUnterminatedEnclosedMessage<fragment extends string, enclosingStart extends EnclosingStartToken> = `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[EnclosingTokens[enclosingStart]]}`;
48
38
  export {};
49
- //# sourceMappingURL=enclosed.d.ts.map