arktype 1.0.28-alpha → 1.1.0-dev-2

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 (364) hide show
  1. package/dist/main.d.ts +11 -0
  2. package/dist/main.d.ts.map +1 -0
  3. package/dist/main.js +8 -0
  4. package/dist/main.js.map +1 -0
  5. package/dist/match.d.ts +46 -0
  6. package/dist/match.d.ts.map +1 -0
  7. package/dist/match.js +23 -0
  8. package/dist/match.js.map +1 -0
  9. package/dist/parser/definition.d.ts +32 -0
  10. package/dist/parser/definition.d.ts.map +1 -0
  11. package/dist/parser/definition.js +29 -0
  12. package/dist/parser/definition.js.map +1 -0
  13. package/dist/parser/generic.d.ts +44 -0
  14. package/dist/parser/generic.d.ts.map +1 -0
  15. package/dist/parser/generic.js +46 -0
  16. package/dist/parser/generic.js.map +1 -0
  17. package/dist/parser/objectLiteral.d.ts +24 -0
  18. package/dist/parser/objectLiteral.d.ts.map +1 -0
  19. package/dist/parser/objectLiteral.js +38 -0
  20. package/dist/parser/objectLiteral.js.map +1 -0
  21. package/dist/parser/semantic/bounds.d.ts +13 -0
  22. package/dist/parser/semantic/bounds.d.ts.map +1 -0
  23. package/dist/parser/semantic/bounds.js +2 -0
  24. package/dist/parser/semantic/bounds.js.map +1 -0
  25. package/dist/parser/semantic/divisor.d.ts +9 -0
  26. package/dist/parser/semantic/divisor.d.ts.map +1 -0
  27. package/dist/parser/semantic/divisor.js +2 -0
  28. package/dist/parser/semantic/divisor.js.map +1 -0
  29. package/dist/parser/semantic/intersections.d.ts +15 -0
  30. package/dist/parser/semantic/intersections.d.ts.map +1 -0
  31. package/dist/parser/semantic/intersections.js +2 -0
  32. package/dist/parser/semantic/intersections.js.map +1 -0
  33. package/dist/parser/semantic/semantic.d.ts +22 -0
  34. package/dist/parser/semantic/semantic.d.ts.map +1 -0
  35. package/dist/parser/semantic/semantic.js +2 -0
  36. package/dist/parser/semantic/semantic.js.map +1 -0
  37. package/dist/parser/semantic/utils.d.ts +8 -0
  38. package/dist/parser/semantic/utils.d.ts.map +1 -0
  39. package/dist/parser/semantic/utils.js +2 -0
  40. package/dist/parser/semantic/utils.js.map +1 -0
  41. package/dist/parser/semantic/validate.d.ts +24 -0
  42. package/dist/parser/semantic/validate.d.ts.map +1 -0
  43. package/dist/parser/semantic/validate.js +2 -0
  44. package/dist/parser/semantic/validate.js.map +1 -0
  45. package/dist/parser/shared.d.ts +48 -0
  46. package/dist/parser/shared.d.ts.map +1 -0
  47. package/dist/parser/shared.js +41 -0
  48. package/dist/parser/shared.js.map +1 -0
  49. package/dist/parser/string/reduce/dynamic.d.ts +40 -0
  50. package/dist/parser/string/reduce/dynamic.d.ts.map +1 -0
  51. package/dist/parser/string/reduce/dynamic.js +122 -0
  52. package/dist/parser/string/reduce/dynamic.js.map +1 -0
  53. package/dist/parser/string/reduce/shared.d.ts +29 -0
  54. package/dist/parser/string/reduce/shared.d.ts.map +1 -0
  55. package/dist/parser/string/reduce/shared.js +7 -0
  56. package/dist/parser/string/reduce/shared.js.map +1 -0
  57. package/dist/parser/string/reduce/static.d.ts +177 -0
  58. package/dist/parser/string/reduce/static.d.ts.map +1 -0
  59. package/dist/parser/string/reduce/static.js +2 -0
  60. package/dist/parser/string/reduce/static.js.map +1 -0
  61. package/dist/parser/string/shift/operand/date.d.ts +11 -0
  62. package/dist/parser/string/shift/operand/date.d.ts.map +1 -0
  63. package/dist/parser/string/shift/operand/date.js +26 -0
  64. package/dist/parser/string/shift/operand/date.js.map +1 -0
  65. package/dist/parser/string/shift/operand/enclosed.d.ts +49 -0
  66. package/dist/parser/string/shift/operand/enclosed.d.ts.map +1 -0
  67. package/dist/parser/string/shift/operand/enclosed.js +50 -0
  68. package/dist/parser/string/shift/operand/enclosed.js.map +1 -0
  69. package/dist/parser/string/shift/operand/operand.d.ts +9 -0
  70. package/dist/parser/string/shift/operand/operand.d.ts.map +1 -0
  71. package/dist/parser/string/shift/operand/operand.js +17 -0
  72. package/dist/parser/string/shift/operand/operand.js.map +1 -0
  73. package/dist/parser/string/shift/operand/unenclosed.d.ts +36 -0
  74. package/dist/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
  75. package/dist/parser/string/shift/operand/unenclosed.js +68 -0
  76. package/dist/parser/string/shift/operand/unenclosed.js.map +1 -0
  77. package/dist/parser/string/shift/operator/bounds.d.ts +55 -0
  78. package/dist/parser/string/shift/operator/bounds.d.ts.map +1 -0
  79. package/dist/parser/string/shift/operator/bounds.js +95 -0
  80. package/dist/parser/string/shift/operator/bounds.js.map +1 -0
  81. package/dist/parser/string/shift/operator/divisor.d.ts +9 -0
  82. package/dist/parser/string/shift/operator/divisor.d.ts.map +1 -0
  83. package/dist/parser/string/shift/operator/divisor.js +13 -0
  84. package/dist/parser/string/shift/operator/divisor.js.map +1 -0
  85. package/dist/parser/string/shift/operator/operator.d.ts +13 -0
  86. package/dist/parser/string/shift/operator/operator.d.ts.map +1 -0
  87. package/dist/parser/string/shift/operator/operator.js +29 -0
  88. package/dist/parser/string/shift/operator/operator.js.map +1 -0
  89. package/dist/parser/string/shift/scanner.d.ts +71 -0
  90. package/dist/parser/string/shift/scanner.d.ts.map +1 -0
  91. package/dist/parser/string/shift/scanner.js +99 -0
  92. package/dist/parser/string/shift/scanner.js.map +1 -0
  93. package/dist/parser/string/string.d.ts +26 -0
  94. package/dist/parser/string/string.d.ts.map +1 -0
  95. package/dist/parser/string/string.js +31 -0
  96. package/dist/parser/string/string.js.map +1 -0
  97. package/dist/parser/tuple.d.ts +73 -0
  98. package/dist/parser/tuple.d.ts.map +1 -0
  99. package/dist/parser/tuple.js +134 -0
  100. package/dist/parser/tuple.js.map +1 -0
  101. package/dist/scope.d.ts +159 -0
  102. package/dist/scope.d.ts.map +1 -0
  103. package/dist/scope.js +248 -0
  104. package/dist/scope.js.map +1 -0
  105. package/dist/scopes/ark.d.ts +38 -0
  106. package/dist/scopes/ark.d.ts.map +1 -0
  107. package/dist/scopes/ark.js +24 -0
  108. package/dist/scopes/ark.js.map +1 -0
  109. package/dist/scopes/jsObjects.d.ts +19 -0
  110. package/dist/scopes/jsObjects.d.ts.map +1 -0
  111. package/dist/scopes/jsObjects.js +15 -0
  112. package/dist/scopes/jsObjects.js.map +1 -0
  113. package/dist/scopes/parsing.d.ts +18 -0
  114. package/dist/scopes/parsing.d.ts.map +1 -0
  115. package/dist/scopes/parsing.js +61 -0
  116. package/dist/scopes/parsing.js.map +1 -0
  117. package/dist/scopes/tsGenerics.d.ts +17 -0
  118. package/dist/scopes/tsGenerics.d.ts.map +1 -0
  119. package/dist/scopes/tsGenerics.js +13 -0
  120. package/dist/scopes/tsGenerics.js.map +1 -0
  121. package/dist/scopes/tsKeywords.d.ts +24 -0
  122. package/dist/scopes/tsKeywords.d.ts.map +1 -0
  123. package/dist/scopes/tsKeywords.js +20 -0
  124. package/dist/scopes/tsKeywords.js.map +1 -0
  125. package/dist/scopes/utils/creditCard.d.ts +3 -0
  126. package/dist/scopes/utils/creditCard.d.ts.map +1 -0
  127. package/dist/{mjs/scopes/validation → scopes/utils}/creditCard.js +14 -12
  128. package/dist/scopes/utils/creditCard.js.map +1 -0
  129. package/dist/{types/scopes/validation → scopes/utils}/date.d.ts +3 -2
  130. package/dist/scopes/utils/date.d.ts.map +1 -0
  131. package/dist/{mjs/scopes/validation → scopes/utils}/date.js +24 -19
  132. package/dist/scopes/utils/date.js.map +1 -0
  133. package/dist/scopes/validation.d.ts +20 -0
  134. package/dist/scopes/validation.d.ts.map +1 -0
  135. package/dist/scopes/validation.js +57 -0
  136. package/dist/scopes/validation.js.map +1 -0
  137. package/dist/type.d.ts +101 -0
  138. package/dist/type.d.ts.map +1 -0
  139. package/dist/type.js +138 -0
  140. package/dist/type.js.map +1 -0
  141. package/main.ts +20 -0
  142. package/match.ts +137 -0
  143. package/package.json +41 -108
  144. package/parser/definition.ts +156 -0
  145. package/parser/generic.ts +208 -0
  146. package/parser/objectLiteral.ts +120 -0
  147. package/parser/semantic/bounds.ts +63 -0
  148. package/parser/semantic/divisor.ts +13 -0
  149. package/parser/semantic/intersections.ts +47 -0
  150. package/parser/semantic/semantic.ts +107 -0
  151. package/parser/semantic/utils.ts +26 -0
  152. package/parser/semantic/validate.ts +105 -0
  153. package/parser/shared.ts +141 -0
  154. package/parser/string/reduce/dynamic.ts +181 -0
  155. package/parser/string/reduce/shared.ts +73 -0
  156. package/parser/string/reduce/static.ts +300 -0
  157. package/parser/string/shift/operand/date.ts +57 -0
  158. package/parser/string/shift/operand/enclosed.ts +119 -0
  159. package/parser/string/shift/operand/operand.ts +48 -0
  160. package/parser/string/shift/operand/unenclosed.ts +282 -0
  161. package/parser/string/shift/operator/bounds.ts +229 -0
  162. package/parser/string/shift/operator/divisor.ts +36 -0
  163. package/parser/string/shift/operator/operator.ts +82 -0
  164. package/parser/string/shift/scanner.ts +209 -0
  165. package/parser/string/string.ts +93 -0
  166. package/parser/tuple.ts +475 -0
  167. package/scope.ts +573 -0
  168. package/scopes/ark.ts +64 -0
  169. package/scopes/jsObjects.ts +29 -0
  170. package/scopes/parsing.ts +81 -0
  171. package/scopes/tsGenerics.ts +28 -0
  172. package/scopes/tsKeywords.ts +39 -0
  173. package/scopes/utils/creditCard.ts +37 -0
  174. package/scopes/utils/date.ts +108 -0
  175. package/scopes/validation.ts +81 -0
  176. package/type.ts +403 -0
  177. package/LICENSE +0 -7
  178. package/README.md +0 -351
  179. package/dist/cjs/main.js +0 -38
  180. package/dist/cjs/nodes/branch.js +0 -140
  181. package/dist/cjs/nodes/compose.js +0 -163
  182. package/dist/cjs/nodes/discriminate.js +0 -265
  183. package/dist/cjs/nodes/node.js +0 -139
  184. package/dist/cjs/nodes/predicate.js +0 -86
  185. package/dist/cjs/nodes/rules/class.js +0 -25
  186. package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
  187. package/dist/cjs/nodes/rules/divisor.js +0 -29
  188. package/dist/cjs/nodes/rules/props.js +0 -167
  189. package/dist/cjs/nodes/rules/range.js +0 -105
  190. package/dist/cjs/nodes/rules/regex.js +0 -26
  191. package/dist/cjs/nodes/rules/rules.js +0 -123
  192. package/dist/cjs/package.json +0 -3
  193. package/dist/cjs/parse/ast/ast.js +0 -4
  194. package/dist/cjs/parse/ast/bound.js +0 -16
  195. package/dist/cjs/parse/ast/config.js +0 -13
  196. package/dist/cjs/parse/ast/distributableFunction.js +0 -48
  197. package/dist/cjs/parse/ast/divisor.js +0 -9
  198. package/dist/cjs/parse/ast/intersection.js +0 -30
  199. package/dist/cjs/parse/ast/keyof.js +0 -111
  200. package/dist/cjs/parse/ast/morph.js +0 -58
  201. package/dist/cjs/parse/ast/narrow.js +0 -22
  202. package/dist/cjs/parse/ast/node.js +0 -4
  203. package/dist/cjs/parse/ast/tuple.js +0 -94
  204. package/dist/cjs/parse/ast/union.js +0 -9
  205. package/dist/cjs/parse/ast/utils.js +0 -4
  206. package/dist/cjs/parse/definition.js +0 -61
  207. package/dist/cjs/parse/record.js +0 -37
  208. package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
  209. package/dist/cjs/parse/string/reduce/shared.js +0 -23
  210. package/dist/cjs/parse/string/reduce/static.js +0 -4
  211. package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
  212. package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
  213. package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
  214. package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
  215. package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
  216. package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
  217. package/dist/cjs/parse/string/shift/scanner.js +0 -114
  218. package/dist/cjs/parse/string/string.js +0 -43
  219. package/dist/cjs/scopes/ark.js +0 -45
  220. package/dist/cjs/scopes/cache.js +0 -52
  221. package/dist/cjs/scopes/expressions.js +0 -29
  222. package/dist/cjs/scopes/jsObjects.js +0 -93
  223. package/dist/cjs/scopes/scope.js +0 -323
  224. package/dist/cjs/scopes/tsKeywords.js +0 -113
  225. package/dist/cjs/scopes/type.js +0 -50
  226. package/dist/cjs/scopes/validation/creditCard.js +0 -47
  227. package/dist/cjs/scopes/validation/date.js +0 -62
  228. package/dist/cjs/scopes/validation/validation.js +0 -108
  229. package/dist/cjs/traverse/problems.js +0 -281
  230. package/dist/cjs/traverse/traverse.js +0 -390
  231. package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
  232. package/dist/cjs/utils/data.js +0 -53
  233. package/dist/cjs/utils/domains.js +0 -30
  234. package/dist/cjs/utils/errors.js +0 -26
  235. package/dist/cjs/utils/freeze.js +0 -15
  236. package/dist/cjs/utils/generics.js +0 -63
  237. package/dist/cjs/utils/numericLiterals.js +0 -75
  238. package/dist/cjs/utils/objectKinds.js +0 -69
  239. package/dist/cjs/utils/paths.js +0 -32
  240. package/dist/cjs/utils/serialize.js +0 -74
  241. package/dist/cjs/utils/unionToTuple.js +0 -4
  242. package/dist/mjs/main.js +0 -8
  243. package/dist/mjs/nodes/branch.js +0 -123
  244. package/dist/mjs/nodes/compose.js +0 -141
  245. package/dist/mjs/nodes/discriminate.js +0 -250
  246. package/dist/mjs/nodes/node.js +0 -117
  247. package/dist/mjs/nodes/predicate.js +0 -69
  248. package/dist/mjs/nodes/rules/class.js +0 -11
  249. package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
  250. package/dist/mjs/nodes/rules/divisor.js +0 -15
  251. package/dist/mjs/nodes/rules/props.js +0 -149
  252. package/dist/mjs/nodes/rules/range.js +0 -86
  253. package/dist/mjs/nodes/rules/regex.js +0 -11
  254. package/dist/mjs/nodes/rules/rules.js +0 -106
  255. package/dist/mjs/package.json +0 -3
  256. package/dist/mjs/parse/ast/ast.js +0 -1
  257. package/dist/mjs/parse/ast/bound.js +0 -2
  258. package/dist/mjs/parse/ast/config.js +0 -9
  259. package/dist/mjs/parse/ast/distributableFunction.js +0 -34
  260. package/dist/mjs/parse/ast/divisor.js +0 -1
  261. package/dist/mjs/parse/ast/intersection.js +0 -16
  262. package/dist/mjs/parse/ast/keyof.js +0 -103
  263. package/dist/mjs/parse/ast/morph.js +0 -44
  264. package/dist/mjs/parse/ast/narrow.js +0 -14
  265. package/dist/mjs/parse/ast/node.js +0 -1
  266. package/dist/mjs/parse/ast/tuple.js +0 -80
  267. package/dist/mjs/parse/ast/union.js +0 -1
  268. package/dist/mjs/parse/ast/utils.js +0 -1
  269. package/dist/mjs/parse/definition.js +0 -46
  270. package/dist/mjs/parse/record.js +0 -29
  271. package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
  272. package/dist/mjs/parse/string/reduce/shared.js +0 -6
  273. package/dist/mjs/parse/string/reduce/static.js +0 -1
  274. package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
  275. package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
  276. package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
  277. package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
  278. package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
  279. package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
  280. package/dist/mjs/parse/string/shift/scanner.js +0 -106
  281. package/dist/mjs/parse/string/string.js +0 -28
  282. package/dist/mjs/scopes/ark.js +0 -28
  283. package/dist/mjs/scopes/cache.js +0 -38
  284. package/dist/mjs/scopes/expressions.js +0 -89
  285. package/dist/mjs/scopes/jsObjects.js +0 -82
  286. package/dist/mjs/scopes/scope.js +0 -303
  287. package/dist/mjs/scopes/tsKeywords.js +0 -116
  288. package/dist/mjs/scopes/type.js +0 -35
  289. package/dist/mjs/scopes/validation/validation.js +0 -112
  290. package/dist/mjs/traverse/problems.js +0 -260
  291. package/dist/mjs/traverse/traverse.js +0 -373
  292. package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
  293. package/dist/mjs/utils/data.js +0 -38
  294. package/dist/mjs/utils/domains.js +0 -15
  295. package/dist/mjs/utils/errors.js +0 -10
  296. package/dist/mjs/utils/freeze.js +0 -7
  297. package/dist/mjs/utils/generics.js +0 -38
  298. package/dist/mjs/utils/numericLiterals.js +0 -72
  299. package/dist/mjs/utils/objectKinds.js +0 -55
  300. package/dist/mjs/utils/paths.js +0 -18
  301. package/dist/mjs/utils/serialize.js +0 -58
  302. package/dist/mjs/utils/unionToTuple.js +0 -1
  303. package/dist/tsconfig.temp.tsbuildinfo +0 -1
  304. package/dist/types/main.d.ts +0 -15
  305. package/dist/types/nodes/branch.d.ts +0 -29
  306. package/dist/types/nodes/compose.d.ts +0 -98
  307. package/dist/types/nodes/discriminate.d.ts +0 -26
  308. package/dist/types/nodes/node.d.ts +0 -69
  309. package/dist/types/nodes/predicate.d.ts +0 -18
  310. package/dist/types/nodes/rules/class.d.ts +0 -4
  311. package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
  312. package/dist/types/nodes/rules/divisor.d.ts +0 -3
  313. package/dist/types/nodes/rules/props.d.ts +0 -43
  314. package/dist/types/nodes/rules/range.d.ts +0 -34
  315. package/dist/types/nodes/rules/regex.d.ts +0 -5
  316. package/dist/types/nodes/rules/rules.d.ts +0 -33
  317. package/dist/types/parse/ast/ast.d.ts +0 -24
  318. package/dist/types/parse/ast/bound.d.ts +0 -27
  319. package/dist/types/parse/ast/config.d.ts +0 -15
  320. package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
  321. package/dist/types/parse/ast/divisor.d.ts +0 -13
  322. package/dist/types/parse/ast/intersection.d.ts +0 -31
  323. package/dist/types/parse/ast/keyof.d.ts +0 -10
  324. package/dist/types/parse/ast/morph.d.ts +0 -18
  325. package/dist/types/parse/ast/narrow.d.ts +0 -21
  326. package/dist/types/parse/ast/node.d.ts +0 -35
  327. package/dist/types/parse/ast/tuple.d.ts +0 -41
  328. package/dist/types/parse/ast/union.d.ts +0 -17
  329. package/dist/types/parse/ast/utils.d.ts +0 -7
  330. package/dist/types/parse/definition.d.ts +0 -30
  331. package/dist/types/parse/record.d.ts +0 -26
  332. package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
  333. package/dist/types/parse/string/reduce/shared.d.ts +0 -25
  334. package/dist/types/parse/string/reduce/static.d.ts +0 -130
  335. package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
  336. package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
  337. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
  338. package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
  339. package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
  340. package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
  341. package/dist/types/parse/string/shift/scanner.d.ts +0 -89
  342. package/dist/types/parse/string/string.d.ts +0 -25
  343. package/dist/types/scopes/ark.d.ts +0 -209
  344. package/dist/types/scopes/cache.d.ts +0 -14
  345. package/dist/types/scopes/expressions.d.ts +0 -136
  346. package/dist/types/scopes/jsObjects.d.ts +0 -26
  347. package/dist/types/scopes/scope.d.ts +0 -99
  348. package/dist/types/scopes/tsKeywords.d.ts +0 -50
  349. package/dist/types/scopes/type.d.ts +0 -67
  350. package/dist/types/scopes/validation/creditCard.d.ts +0 -2
  351. package/dist/types/scopes/validation/validation.d.ts +0 -49
  352. package/dist/types/traverse/problems.d.ts +0 -88
  353. package/dist/types/traverse/traverse.d.ts +0 -55
  354. package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
  355. package/dist/types/utils/data.d.ts +0 -13
  356. package/dist/types/utils/domains.d.ts +0 -32
  357. package/dist/types/utils/errors.d.ts +0 -6
  358. package/dist/types/utils/freeze.d.ts +0 -2
  359. package/dist/types/utils/generics.d.ts +0 -125
  360. package/dist/types/utils/numericLiterals.d.ts +0 -46
  361. package/dist/types/utils/objectKinds.d.ts +0 -84
  362. package/dist/types/utils/paths.d.ts +0 -9
  363. package/dist/types/utils/serialize.d.ts +0 -37
  364. package/dist/types/utils/unionToTuple.d.ts +0 -11
@@ -0,0 +1,181 @@
1
+ import type { Root } from "@arktype/schema"
2
+ import {
3
+ isKeyOf,
4
+ throwInternalError,
5
+ throwParseError,
6
+ type requireKeys
7
+ } from "@arktype/util"
8
+ import type { ParseContext } from "../../../scope.js"
9
+ import {
10
+ invertedComparators,
11
+ minComparators,
12
+ type Comparator,
13
+ type LimitLiteral
14
+ } from "../shift/operator/bounds.js"
15
+ import { Scanner } from "../shift/scanner.js"
16
+ import {
17
+ writeMultipleLeftBoundsMessage,
18
+ writeOpenRangeMessage,
19
+ writeUnclosedGroupMessage,
20
+ writeUnmatchedGroupCloseMessage,
21
+ writeUnpairableComparatorMessage,
22
+ type OpenLeftBound,
23
+ type StringifiablePrefixOperator
24
+ } from "./shared.js"
25
+
26
+ type BranchState = {
27
+ prefixes: StringifiablePrefixOperator[]
28
+ leftBound?: OpenLeftBound
29
+ "&"?: Root
30
+ "|"?: Root
31
+ }
32
+
33
+ export type DynamicStateWithRoot = requireKeys<DynamicState, "root">
34
+
35
+ export class DynamicState {
36
+ readonly scanner: Scanner
37
+ root: Root | undefined
38
+ branches: BranchState = {
39
+ prefixes: []
40
+ }
41
+ finalizer: Scanner.FinalizingLookahead | undefined
42
+ groups: BranchState[] = []
43
+
44
+ constructor(
45
+ def: string,
46
+ public readonly ctx: ParseContext
47
+ ) {
48
+ this.scanner = new Scanner(def)
49
+ }
50
+
51
+ error(message: string) {
52
+ return throwParseError(message)
53
+ }
54
+
55
+ hasRoot(): this is DynamicStateWithRoot {
56
+ return this.root !== undefined
57
+ }
58
+
59
+ unsetRoot(): this["root"] {
60
+ const value = this.root
61
+ this.root = undefined
62
+ return value
63
+ }
64
+
65
+ constrainRoot(...args: Parameters<Root["constrain"]>) {
66
+ this.root = this.root!.constrain(...args)
67
+ }
68
+
69
+ setRoot(root: Root) {
70
+ this.root = root
71
+ }
72
+
73
+ finalize(finalizer: Scanner.FinalizingLookahead) {
74
+ if (this.groups.length) {
75
+ return this.error(writeUnclosedGroupMessage(")"))
76
+ }
77
+ this.finalizeBranches()
78
+ this.finalizer = finalizer
79
+ }
80
+
81
+ reduceLeftBound(limit: LimitLiteral, comparator: Comparator) {
82
+ const invertedComparator = invertedComparators[comparator]
83
+ if (!isKeyOf(invertedComparator, minComparators)) {
84
+ return this.error(writeUnpairableComparatorMessage(comparator))
85
+ }
86
+ if (this.branches.leftBound) {
87
+ return this.error(
88
+ writeMultipleLeftBoundsMessage(
89
+ this.branches.leftBound.limit,
90
+ this.branches.leftBound.comparator,
91
+ limit,
92
+ invertedComparator
93
+ )
94
+ )
95
+ }
96
+ this.branches.leftBound = {
97
+ comparator: invertedComparator,
98
+ limit
99
+ }
100
+ }
101
+
102
+ finalizeBranches() {
103
+ this.assertRangeUnset()
104
+ if (this.branches["|"]) {
105
+ this.pushRootToBranch("|")
106
+ this.root = this.branches["|"]
107
+ } else if (this.branches["&"]) {
108
+ this.pushRootToBranch("&")
109
+ this.root = this.branches["&"]
110
+ } else {
111
+ this.applyPrefixes()
112
+ }
113
+ }
114
+
115
+ finalizeGroup() {
116
+ this.finalizeBranches()
117
+ const topBranchState = this.groups.pop()
118
+ if (!topBranchState) {
119
+ return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned))
120
+ }
121
+ this.branches = topBranchState
122
+ }
123
+
124
+ addPrefix(prefix: StringifiablePrefixOperator) {
125
+ this.branches.prefixes.push(prefix)
126
+ }
127
+
128
+ applyPrefixes() {
129
+ while (this.branches.prefixes.length) {
130
+ const lastPrefix = this.branches.prefixes.pop()!
131
+ this.root =
132
+ lastPrefix === "keyof"
133
+ ? this.root!.keyof()
134
+ : throwInternalError(`Unexpected prefix '${lastPrefix}'`)
135
+ }
136
+ }
137
+
138
+ pushRootToBranch(token: "|" | "&") {
139
+ this.assertRangeUnset()
140
+ this.applyPrefixes()
141
+ const root = this.root!
142
+ this.branches["&"] = this.branches["&"]?.and(root) ?? root
143
+ if (token === "|") {
144
+ this.branches["|"] =
145
+ this.branches["|"]?.or(this.branches["&"]) ?? this.branches["&"]
146
+ delete this.branches["&"]
147
+ }
148
+ this.root = undefined
149
+ }
150
+
151
+ private assertRangeUnset() {
152
+ if (this.branches.leftBound) {
153
+ return this.error(
154
+ writeOpenRangeMessage(
155
+ this.branches.leftBound.limit,
156
+ this.branches.leftBound.comparator
157
+ )
158
+ )
159
+ }
160
+ }
161
+
162
+ reduceGroupOpen() {
163
+ this.groups.push(this.branches)
164
+ this.branches = {
165
+ prefixes: []
166
+ }
167
+ }
168
+
169
+ previousOperator() {
170
+ return (
171
+ this.branches.leftBound?.comparator ??
172
+ this.branches.prefixes.at(-1) ??
173
+ (this.branches["&"] ? "&" : this.branches["|"] ? "|" : undefined)
174
+ )
175
+ }
176
+
177
+ shiftedByOne() {
178
+ this.scanner.shift()
179
+ return this
180
+ }
181
+ }
@@ -0,0 +1,73 @@
1
+ import {
2
+ invertedComparators,
3
+ type Comparator,
4
+ type InvertedComparators,
5
+ type LimitLiteral,
6
+ type MinComparator
7
+ } from "../shift/operator/bounds.js"
8
+
9
+ export type StringifiablePrefixOperator = "keyof"
10
+
11
+ export type OpenLeftBound = { limit: LimitLiteral; comparator: MinComparator }
12
+
13
+ export const writeUnmatchedGroupCloseMessage = <unscanned extends string>(
14
+ unscanned: unscanned
15
+ ): writeUnmatchedGroupCloseMessage<unscanned> =>
16
+ `Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`) as any}`
17
+
18
+ export type writeUnmatchedGroupCloseMessage<unscanned extends string> =
19
+ `Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`
20
+
21
+ export const writeUnclosedGroupMessage = <missingChar extends string>(
22
+ missingChar: missingChar
23
+ ): writeUnclosedGroupMessage<missingChar> => `Missing ${missingChar}`
24
+
25
+ export type writeUnclosedGroupMessage<missingChar extends string> =
26
+ `Missing ${missingChar}`
27
+
28
+ export const writeOpenRangeMessage = <
29
+ min extends LimitLiteral,
30
+ comparator extends MinComparator
31
+ >(
32
+ min: min,
33
+ comparator: comparator
34
+ ): writeOpenRangeMessage<min, comparator> =>
35
+ `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`
36
+
37
+ export type writeOpenRangeMessage<
38
+ min extends LimitLiteral,
39
+ comparator extends MinComparator
40
+ > = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`
41
+
42
+ export type writeUnpairableComparatorMessage<comparator extends Comparator> =
43
+ `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`
44
+
45
+ export const writeUnpairableComparatorMessage = <comparator extends Comparator>(
46
+ comparator: comparator
47
+ ): writeUnpairableComparatorMessage<comparator> =>
48
+ `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`
49
+
50
+ export const writeMultipleLeftBoundsMessage = <
51
+ openLimit extends LimitLiteral,
52
+ openComparator extends MinComparator,
53
+ limit extends LimitLiteral,
54
+ comparator extends MinComparator
55
+ >(
56
+ openLimit: openLimit,
57
+ openComparator: openComparator,
58
+ limit: limit,
59
+ comparator: comparator
60
+ ): writeMultipleLeftBoundsMessage<
61
+ openLimit,
62
+ openComparator,
63
+ limit,
64
+ comparator
65
+ > =>
66
+ `An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`
67
+
68
+ export type writeMultipleLeftBoundsMessage<
69
+ openLimit extends LimitLiteral,
70
+ openComparator extends MinComparator,
71
+ limit extends LimitLiteral,
72
+ comparator extends MinComparator
73
+ > = `An expression may have at most one left bound (parsed ${openLimit}${InvertedComparators[openComparator]}, ${limit}${InvertedComparators[comparator]})`
@@ -0,0 +1,300 @@
1
+ import type { Completion, defined, ErrorMessage } from "@arktype/util"
2
+ import type {
3
+ Comparator,
4
+ InvertedComparators,
5
+ LimitLiteral,
6
+ MaxComparator,
7
+ MinComparator
8
+ } from "../shift/operator/bounds.js"
9
+ import type { Scanner } from "../shift/scanner.js"
10
+ import type {
11
+ OpenLeftBound,
12
+ StringifiablePrefixOperator,
13
+ writeMultipleLeftBoundsMessage,
14
+ writeOpenRangeMessage,
15
+ writeUnclosedGroupMessage,
16
+ writeUnmatchedGroupCloseMessage,
17
+ writeUnpairableComparatorMessage
18
+ } from "./shared.js"
19
+
20
+ export type StaticState = {
21
+ root: unknown
22
+ branches: BranchState
23
+ groups: BranchState[]
24
+ finalizer: Scanner.FinalizingLookahead | ErrorMessage | undefined
25
+ scanned: string
26
+ unscanned: string
27
+ }
28
+
29
+ export type AutocompletePrefix = `${StringifiablePrefixOperator} `
30
+
31
+ type BranchState = {
32
+ prefixes: StringifiablePrefixOperator[]
33
+ leftBound: OpenLeftBound | undefined
34
+ "&": unknown
35
+ "|": unknown
36
+ }
37
+
38
+ export namespace state {
39
+ export type initialize<def extends string> = from<{
40
+ root: undefined
41
+ branches: initialBranches
42
+ groups: []
43
+ finalizer: undefined
44
+ scanned: ""
45
+ unscanned: def
46
+ }>
47
+
48
+ export type error<message extends string> = from<{
49
+ root: undefined
50
+ branches: initialBranches
51
+ groups: []
52
+ finalizer: ErrorMessage<message>
53
+ scanned: ""
54
+ unscanned: ""
55
+ }>
56
+
57
+ export type completion<text extends string> = from<{
58
+ root: undefined
59
+ branches: initialBranches
60
+ groups: []
61
+ finalizer: Completion<text>
62
+ scanned: ""
63
+ unscanned: ""
64
+ }>
65
+
66
+ type initialBranches = branchesFrom<{
67
+ prefixes: []
68
+ leftBound: undefined
69
+ "&": undefined
70
+ "|": undefined
71
+ }>
72
+
73
+ type updateScanned<
74
+ previousScanned extends string,
75
+ previousUnscanned extends string,
76
+ updatedUnscanned extends string
77
+ > = previousUnscanned extends `${infer justScanned}${updatedUnscanned}`
78
+ ? `${previousScanned}${justScanned}`
79
+ : previousScanned
80
+
81
+ export type setRoot<
82
+ s extends StaticState,
83
+ root,
84
+ unscanned extends string
85
+ > = from<{
86
+ root: root
87
+ branches: s["branches"]
88
+ groups: s["groups"]
89
+ finalizer: s["finalizer"]
90
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
91
+ unscanned: unscanned
92
+ }>
93
+
94
+ export type addPrefix<
95
+ s extends StaticState,
96
+ prefix extends StringifiablePrefixOperator,
97
+ unscanned extends string
98
+ > = from<{
99
+ root: s["root"]
100
+ branches: {
101
+ prefixes: [...s["branches"]["prefixes"], prefix]
102
+ leftBound: s["branches"]["leftBound"]
103
+ "&": s["branches"]["&"]
104
+ "|": s["branches"]["|"]
105
+ }
106
+ groups: s["groups"]
107
+ finalizer: s["finalizer"]
108
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
109
+ unscanned: unscanned
110
+ }>
111
+
112
+ export type reduceBranch<
113
+ s extends StaticState,
114
+ token extends "|" | "&",
115
+ unscanned extends string
116
+ > = s["branches"]["leftBound"] extends {}
117
+ ? openRangeError<s["branches"]["leftBound"]>
118
+ : from<{
119
+ root: undefined
120
+ branches: {
121
+ prefixes: []
122
+ leftBound: undefined
123
+ "&": token extends "&" ? mergeToIntersection<s> : undefined
124
+ "|": token extends "|" ? mergeToUnion<s> : s["branches"]["|"]
125
+ }
126
+ groups: s["groups"]
127
+ finalizer: s["finalizer"]
128
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
129
+ unscanned: unscanned
130
+ }>
131
+
132
+ export type reduceLeftBound<
133
+ s extends StaticState,
134
+ limit extends LimitLiteral,
135
+ comparator extends Comparator,
136
+ unscanned extends string
137
+ > = comparator extends "<" | "<="
138
+ ? s["branches"]["leftBound"] extends {}
139
+ ? state.error<
140
+ writeMultipleLeftBoundsMessage<
141
+ s["branches"]["leftBound"]["limit"],
142
+ s["branches"]["leftBound"]["comparator"],
143
+ limit,
144
+ InvertedComparators[comparator]
145
+ >
146
+ >
147
+ : from<{
148
+ root: undefined
149
+ branches: {
150
+ prefixes: s["branches"]["prefixes"]
151
+ leftBound: {
152
+ limit: limit
153
+ comparator: InvertedComparators[comparator]
154
+ }
155
+ "&": s["branches"]["&"]
156
+ "|": s["branches"]["|"]
157
+ }
158
+ groups: s["groups"]
159
+ finalizer: s["finalizer"]
160
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
161
+ unscanned: unscanned
162
+ }>
163
+ : state.error<writeUnpairableComparatorMessage<comparator>>
164
+
165
+ export type reduceRange<
166
+ s extends StaticState,
167
+ minLimit extends LimitLiteral,
168
+ minComparator extends MinComparator,
169
+ maxComparator extends MaxComparator,
170
+ maxLimit extends LimitLiteral,
171
+ unscanned extends string
172
+ > = state.from<{
173
+ root: [minLimit, minComparator, [s["root"], maxComparator, maxLimit]]
174
+ branches: {
175
+ prefixes: s["branches"]["prefixes"]
176
+ leftBound: undefined
177
+ "&": s["branches"]["&"]
178
+ "|": s["branches"]["|"]
179
+ }
180
+ groups: s["groups"]
181
+ finalizer: s["finalizer"]
182
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
183
+ unscanned: unscanned
184
+ }>
185
+
186
+ export type reduceSingleBound<
187
+ s extends StaticState,
188
+ comparator extends Comparator,
189
+ limit extends LimitLiteral,
190
+ unscanned extends string
191
+ > = state.from<{
192
+ root: [s["root"], comparator, limit]
193
+ branches: {
194
+ prefixes: s["branches"]["prefixes"]
195
+ leftBound: undefined
196
+ "&": s["branches"]["&"]
197
+ "|": s["branches"]["|"]
198
+ }
199
+ groups: s["groups"]
200
+ finalizer: s["finalizer"]
201
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
202
+ unscanned: unscanned
203
+ }>
204
+
205
+ type mergeToUnion<s extends StaticState> =
206
+ s["branches"]["|"] extends undefined
207
+ ? mergeToIntersection<s>
208
+ : [s["branches"]["|"], "|", mergeToIntersection<s>]
209
+
210
+ type mergeToIntersection<s extends StaticState> =
211
+ s["branches"]["&"] extends undefined
212
+ ? mergePrefixes<s>
213
+ : [s["branches"]["&"], "&", mergePrefixes<s>]
214
+
215
+ type mergePrefixes<
216
+ s extends StaticState,
217
+ remaining extends unknown[] = s["branches"]["prefixes"]
218
+ > = remaining extends [infer head, ...infer tail]
219
+ ? [head, mergePrefixes<s, tail>]
220
+ : s["root"]
221
+
222
+ type popGroup<stack extends BranchState[], top extends BranchState> = [
223
+ ...stack,
224
+ top
225
+ ]
226
+
227
+ export type finalizeGroup<
228
+ s extends StaticState,
229
+ unscanned extends string
230
+ > = s["branches"]["leftBound"] extends {}
231
+ ? openRangeError<s["branches"]["leftBound"]>
232
+ : s["groups"] extends popGroup<infer stack, infer top>
233
+ ? from<{
234
+ groups: stack
235
+ branches: top
236
+ root: mergeToUnion<s>
237
+ finalizer: s["finalizer"]
238
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
239
+ unscanned: unscanned
240
+ }>
241
+ : state.error<writeUnmatchedGroupCloseMessage<unscanned>>
242
+
243
+ export type reduceGroupOpen<
244
+ s extends StaticState,
245
+ unscanned extends string
246
+ > = from<{
247
+ groups: [...s["groups"], s["branches"]]
248
+ branches: initialBranches
249
+ root: undefined
250
+ finalizer: s["finalizer"]
251
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
252
+ unscanned: unscanned
253
+ }>
254
+
255
+ export type finalize<
256
+ s extends StaticState,
257
+ finalizer extends Scanner.FinalizingLookahead
258
+ > = s["groups"] extends []
259
+ ? s["branches"]["leftBound"] extends {}
260
+ ? openRangeError<s["branches"]["leftBound"]>
261
+ : from<{
262
+ root: mergeToUnion<s>
263
+ groups: s["groups"]
264
+ branches: initialBranches
265
+ finalizer: finalizer
266
+ scanned: s["scanned"]
267
+ unscanned: s["unscanned"]
268
+ }>
269
+ : state.error<writeUnclosedGroupMessage<")">>
270
+
271
+ type openRangeError<range extends defined<BranchState["leftBound"]>> =
272
+ state.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>
273
+
274
+ export type previousOperator<s extends StaticState> =
275
+ s["branches"]["leftBound"] extends {}
276
+ ? s["branches"]["leftBound"]["comparator"]
277
+ : s["branches"]["prefixes"] extends [
278
+ ...unknown[],
279
+ infer tail extends string
280
+ ]
281
+ ? tail
282
+ : s["branches"]["&"] extends {}
283
+ ? "&"
284
+ : s["branches"]["|"] extends {}
285
+ ? "|"
286
+ : undefined
287
+
288
+ export type scanTo<s extends StaticState, unscanned extends string> = from<{
289
+ root: s["root"]
290
+ branches: s["branches"]
291
+ groups: s["groups"]
292
+ finalizer: s["finalizer"]
293
+ scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>
294
+ unscanned: unscanned
295
+ }>
296
+
297
+ export type from<s extends StaticState> = s
298
+
299
+ export type branchesFrom<b extends BranchState> = b
300
+ }
@@ -0,0 +1,57 @@
1
+ import { throwParseError, tryParseNumber } from "@arktype/util"
2
+
3
+ export type DateLiteral<source extends string = string> =
4
+ | `d"${source}"`
5
+ | `d'${source}'`
6
+
7
+ export const isDateLiteral = (value: unknown): value is DateLiteral =>
8
+ typeof value === "string" &&
9
+ value[0] === "d" &&
10
+ (value[1] === "'" || value[1] === '"') &&
11
+ value.at(-1) === value[1]
12
+
13
+ export const isValidDate = (d: Date) => d.toString() !== "Invalid Date"
14
+
15
+ export const extractDateLiteralSource = <literal extends DateLiteral>(
16
+ literal: literal
17
+ ) => literal.slice(2, -1) as extractDateLiteralSource<literal>
18
+
19
+ type extractDateLiteralSource<literal extends DateLiteral> =
20
+ literal extends DateLiteral<infer source> ? source : never
21
+
22
+ export const writeInvalidDateMessage = <source extends string>(
23
+ source: source
24
+ ): writeInvalidDateMessage<source> =>
25
+ `'${source}' could not be parsed by the Date constructor`
26
+
27
+ export type writeInvalidDateMessage<source extends string> =
28
+ `'${source}' could not be parsed by the Date constructor`
29
+
30
+ export type DateInput = ConstructorParameters<typeof Date>[0]
31
+
32
+ export const tryParseDate = <errorOnFail extends boolean | string>(
33
+ source: string,
34
+ errorOnFail?: errorOnFail
35
+ ) => maybeParseDate(source, errorOnFail)
36
+
37
+ const maybeParseDate = <errorOnFail extends boolean | string>(
38
+ source: string,
39
+ errorOnFail?: errorOnFail
40
+ ): Date | (errorOnFail extends true | string ? never : undefined) => {
41
+ const stringParsedDate = new Date(source)
42
+ if (isValidDate(stringParsedDate)) {
43
+ return stringParsedDate
44
+ }
45
+ const epochMillis = tryParseNumber(source)
46
+ if (epochMillis !== undefined) {
47
+ const numberParsedDate = new Date(epochMillis)
48
+ if (isValidDate(numberParsedDate)) {
49
+ return numberParsedDate
50
+ }
51
+ }
52
+ return errorOnFail
53
+ ? throwParseError(
54
+ errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail
55
+ )
56
+ : (undefined as never)
57
+ }