arktype 2.0.0-dev.7 → 2.0.0-dev.9

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 (414) hide show
  1. package/__tests__/array.test.ts +23 -25
  2. package/__tests__/config.test.ts +19 -8
  3. package/__tests__/examples.test.ts +3 -3
  4. package/__tests__/imports.test.ts +18 -12
  5. package/__tests__/instanceof.test.ts +7 -7
  6. package/__tests__/intersection.test.ts +2 -2
  7. package/__tests__/keyTraversal.test.ts +15 -15
  8. package/__tests__/keywords.test.ts +50 -37
  9. package/__tests__/literal.test.ts +30 -14
  10. package/__tests__/match.bench.ts +6 -6
  11. package/__tests__/narrow.test.ts +18 -24
  12. package/__tests__/objectLiteral.test.ts +134 -11
  13. package/__tests__/operator.bench.ts +4 -4
  14. package/__tests__/{morph.test.ts → pipe.test.ts} +136 -75
  15. package/__tests__/scope.test.ts +202 -15
  16. package/__tests__/traverse.test.ts +45 -36
  17. package/__tests__/type.test.ts +8 -10
  18. package/ark.ts +14 -11
  19. package/generic.ts +8 -6
  20. package/match.ts +59 -70
  21. package/out/ark.d.ts +5 -5
  22. package/out/ark.js +4 -5
  23. package/out/ark.js.map +1 -1
  24. package/out/generic.d.ts +0 -1
  25. package/out/generic.js +8 -7
  26. package/out/generic.js.map +1 -1
  27. package/out/main.d.ts +0 -1
  28. package/out/main.js +0 -1
  29. package/out/match.d.ts +0 -1
  30. package/out/match.js +50 -57
  31. package/out/match.js.map +1 -1
  32. package/out/module.d.ts +0 -1
  33. package/out/module.js +0 -1
  34. package/out/parser/definition.d.ts +1 -2
  35. package/out/parser/definition.js +0 -1
  36. package/out/parser/generic.d.ts +5 -6
  37. package/out/parser/generic.js +4 -6
  38. package/out/parser/generic.js.map +1 -1
  39. package/out/parser/objectLiteral.d.ts +1 -2
  40. package/out/parser/objectLiteral.js +17 -11
  41. package/out/parser/objectLiteral.js.map +1 -1
  42. package/out/parser/semantic/bounds.d.ts +1 -2
  43. package/out/parser/semantic/bounds.js +0 -1
  44. package/out/parser/semantic/divisor.d.ts +0 -1
  45. package/out/parser/semantic/divisor.js +0 -2
  46. package/out/parser/semantic/infer.d.ts +0 -1
  47. package/out/parser/semantic/infer.js +0 -2
  48. package/out/parser/semantic/utils.d.ts +0 -1
  49. package/out/parser/semantic/utils.js +0 -2
  50. package/out/parser/semantic/validate.d.ts +4 -5
  51. package/out/parser/semantic/validate.js +0 -1
  52. package/out/parser/semantic/validate.js.map +1 -1
  53. package/out/parser/string/reduce/dynamic.d.ts +0 -1
  54. package/out/parser/string/reduce/dynamic.js +4 -9
  55. package/out/parser/string/reduce/dynamic.js.map +1 -1
  56. package/out/parser/string/reduce/shared.d.ts +5 -18
  57. package/out/parser/string/reduce/shared.js +0 -1
  58. package/out/parser/string/reduce/static.d.ts +0 -1
  59. package/out/parser/string/reduce/static.js +0 -2
  60. package/out/parser/string/shift/operand/date.d.ts +2 -3
  61. package/out/parser/string/shift/operand/date.js +2 -5
  62. package/out/parser/string/shift/operand/date.js.map +1 -1
  63. package/out/parser/string/shift/operand/enclosed.d.ts +2 -17
  64. package/out/parser/string/shift/operand/enclosed.js +6 -9
  65. package/out/parser/string/shift/operand/enclosed.js.map +1 -1
  66. package/out/parser/string/shift/operand/genericArgs.d.ts +5 -6
  67. package/out/parser/string/shift/operand/genericArgs.js +4 -6
  68. package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
  69. package/out/parser/string/shift/operand/operand.d.ts +0 -1
  70. package/out/parser/string/shift/operand/operand.js +0 -1
  71. package/out/parser/string/shift/operand/unenclosed.d.ts +6 -7
  72. package/out/parser/string/shift/operand/unenclosed.js +6 -13
  73. package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
  74. package/out/parser/string/shift/operator/bounds.d.ts +1 -8
  75. package/out/parser/string/shift/operator/bounds.js +4 -9
  76. package/out/parser/string/shift/operator/bounds.js.map +1 -1
  77. package/out/parser/string/shift/operator/divisor.d.ts +1 -2
  78. package/out/parser/string/shift/operator/divisor.js +1 -3
  79. package/out/parser/string/shift/operator/divisor.js.map +1 -1
  80. package/out/parser/string/shift/operator/operator.d.ts +1 -2
  81. package/out/parser/string/shift/operator/operator.js +0 -1
  82. package/out/parser/string/shift/scanner.d.ts +0 -1
  83. package/out/parser/string/shift/scanner.js +2 -5
  84. package/out/parser/string/shift/scanner.js.map +1 -1
  85. package/out/parser/string/string.d.ts +0 -1
  86. package/out/parser/string/string.js +1 -3
  87. package/out/parser/string/string.js.map +1 -1
  88. package/out/parser/tuple.d.ts +1 -2
  89. package/out/parser/tuple.js +12 -16
  90. package/out/parser/tuple.js.map +1 -1
  91. package/out/scope.d.ts +12 -12
  92. package/out/scope.js +16 -38
  93. package/out/scope.js.map +1 -1
  94. package/out/type.d.ts +38 -19
  95. package/out/type.js +32 -2
  96. package/out/type.js.map +1 -1
  97. package/package.json +6 -4
  98. package/parser/generic.ts +13 -14
  99. package/parser/objectLiteral.ts +25 -11
  100. package/parser/semantic/validate.ts +2 -3
  101. package/parser/string/reduce/dynamic.ts +7 -10
  102. package/parser/string/shift/operand/date.ts +3 -6
  103. package/parser/string/shift/operand/enclosed.ts +8 -8
  104. package/parser/string/shift/operand/genericArgs.ts +8 -8
  105. package/parser/string/shift/operand/unenclosed.ts +15 -25
  106. package/parser/string/shift/operator/bounds.ts +7 -9
  107. package/parser/string/shift/operator/divisor.ts +2 -3
  108. package/parser/string/shift/scanner.ts +2 -4
  109. package/parser/string/string.ts +2 -3
  110. package/parser/tuple.ts +15 -16
  111. package/scope.ts +39 -57
  112. package/type.ts +151 -35
  113. package/__tests__/cyclic.test.ts +0 -148
  114. package/out/ark.d.ts.map +0 -1
  115. package/out/base.d.ts +0 -205
  116. package/out/base.d.ts.map +0 -1
  117. package/out/base.js +0 -320
  118. package/out/base.js.map +0 -1
  119. package/out/builtins/builtins.d.ts +0 -23
  120. package/out/builtins/builtins.d.ts.map +0 -1
  121. package/out/builtins/builtins.js +0 -15
  122. package/out/builtins/builtins.js.map +0 -1
  123. package/out/builtins/jsObjects.d.ts +0 -19
  124. package/out/builtins/jsObjects.d.ts.map +0 -1
  125. package/out/builtins/jsObjects.js +0 -18
  126. package/out/builtins/jsObjects.js.map +0 -1
  127. package/out/builtins/parsing.d.ts +0 -16
  128. package/out/builtins/parsing.d.ts.map +0 -1
  129. package/out/builtins/parsing.js +0 -62
  130. package/out/builtins/parsing.js.map +0 -1
  131. package/out/builtins/tsGenerics.d.ts +0 -2
  132. package/out/builtins/tsGenerics.d.ts.map +0 -1
  133. package/out/builtins/tsGenerics.js +0 -26
  134. package/out/builtins/tsGenerics.js.map +0 -1
  135. package/out/builtins/tsKeywords.d.ts +0 -23
  136. package/out/builtins/tsKeywords.d.ts.map +0 -1
  137. package/out/builtins/tsKeywords.js +0 -23
  138. package/out/builtins/tsKeywords.js.map +0 -1
  139. package/out/builtins/utils/creditCard.d.ts +0 -3
  140. package/out/builtins/utils/creditCard.d.ts.map +0 -1
  141. package/out/builtins/utils/creditCard.js +0 -35
  142. package/out/builtins/utils/creditCard.js.map +0 -1
  143. package/out/builtins/utils/date.d.ts +0 -41
  144. package/out/builtins/utils/date.d.ts.map +0 -1
  145. package/out/builtins/utils/date.js +0 -56
  146. package/out/builtins/utils/date.js.map +0 -1
  147. package/out/builtins/validation.d.ts +0 -19
  148. package/out/builtins/validation.d.ts.map +0 -1
  149. package/out/builtins/validation.js +0 -74
  150. package/out/builtins/validation.js.map +0 -1
  151. package/out/config.d.ts +0 -9
  152. package/out/config.d.ts.map +0 -1
  153. package/out/config.js +0 -18
  154. package/out/config.js.map +0 -1
  155. package/out/constraints/ast.d.ts +0 -287
  156. package/out/constraints/ast.d.ts.map +0 -1
  157. package/out/constraints/ast.js +0 -2
  158. package/out/constraints/ast.js.map +0 -1
  159. package/out/constraints/constraint.d.ts +0 -200
  160. package/out/constraints/constraint.d.ts.map +0 -1
  161. package/out/constraints/constraint.js +0 -25
  162. package/out/constraints/constraint.js.map +0 -1
  163. package/out/constraints/predicate.d.ts +0 -64
  164. package/out/constraints/predicate.d.ts.map +0 -1
  165. package/out/constraints/predicate.js +0 -52
  166. package/out/constraints/predicate.js.map +0 -1
  167. package/out/constraints/props/index.d.ts +0 -42
  168. package/out/constraints/props/index.d.ts.map +0 -1
  169. package/out/constraints/props/index.js +0 -56
  170. package/out/constraints/props/index.js.map +0 -1
  171. package/out/constraints/props/optional.d.ts +0 -37
  172. package/out/constraints/props/optional.d.ts.map +0 -1
  173. package/out/constraints/props/optional.js +0 -56
  174. package/out/constraints/props/optional.js.map +0 -1
  175. package/out/constraints/props/prop.d.ts +0 -49
  176. package/out/constraints/props/prop.d.ts.map +0 -1
  177. package/out/constraints/props/prop.js +0 -106
  178. package/out/constraints/props/prop.js.map +0 -1
  179. package/out/constraints/props/props.d.ts +0 -37
  180. package/out/constraints/props/props.d.ts.map +0 -1
  181. package/out/constraints/props/props.js +0 -121
  182. package/out/constraints/props/props.js.map +0 -1
  183. package/out/constraints/props/required.d.ts +0 -46
  184. package/out/constraints/props/required.d.ts.map +0 -1
  185. package/out/constraints/props/required.js +0 -81
  186. package/out/constraints/props/required.js.map +0 -1
  187. package/out/constraints/props/sequence.d.ts +0 -82
  188. package/out/constraints/props/sequence.d.ts.map +0 -1
  189. package/out/constraints/props/sequence.js +0 -376
  190. package/out/constraints/props/sequence.js.map +0 -1
  191. package/out/constraints/props/shared.d.ts +0 -3
  192. package/out/constraints/props/shared.d.ts.map +0 -1
  193. package/out/constraints/props/shared.js +0 -4
  194. package/out/constraints/props/shared.js.map +0 -1
  195. package/out/constraints/refinements/after.d.ts +0 -33
  196. package/out/constraints/refinements/after.d.ts.map +0 -1
  197. package/out/constraints/refinements/after.js +0 -36
  198. package/out/constraints/refinements/after.js.map +0 -1
  199. package/out/constraints/refinements/before.d.ts +0 -33
  200. package/out/constraints/refinements/before.d.ts.map +0 -1
  201. package/out/constraints/refinements/before.js +0 -43
  202. package/out/constraints/refinements/before.js.map +0 -1
  203. package/out/constraints/refinements/divisor.d.ts +0 -52
  204. package/out/constraints/refinements/divisor.d.ts.map +0 -1
  205. package/out/constraints/refinements/divisor.js +0 -52
  206. package/out/constraints/refinements/divisor.js.map +0 -1
  207. package/out/constraints/refinements/exactLength.d.ts +0 -45
  208. package/out/constraints/refinements/exactLength.d.ts.map +0 -1
  209. package/out/constraints/refinements/exactLength.js +0 -52
  210. package/out/constraints/refinements/exactLength.js.map +0 -1
  211. package/out/constraints/refinements/kinds.d.ts +0 -29
  212. package/out/constraints/refinements/kinds.d.ts.map +0 -1
  213. package/out/constraints/refinements/kinds.js +0 -17
  214. package/out/constraints/refinements/kinds.js.map +0 -1
  215. package/out/constraints/refinements/length.d.ts +0 -48
  216. package/out/constraints/refinements/length.d.ts.map +0 -1
  217. package/out/constraints/refinements/length.js +0 -53
  218. package/out/constraints/refinements/length.js.map +0 -1
  219. package/out/constraints/refinements/max.d.ts +0 -31
  220. package/out/constraints/refinements/max.d.ts.map +0 -1
  221. package/out/constraints/refinements/max.js +0 -35
  222. package/out/constraints/refinements/max.js.map +0 -1
  223. package/out/constraints/refinements/maxLength.d.ts +0 -32
  224. package/out/constraints/refinements/maxLength.d.ts.map +0 -1
  225. package/out/constraints/refinements/maxLength.js +0 -36
  226. package/out/constraints/refinements/maxLength.js.map +0 -1
  227. package/out/constraints/refinements/min.d.ts +0 -31
  228. package/out/constraints/refinements/min.d.ts.map +0 -1
  229. package/out/constraints/refinements/min.js +0 -28
  230. package/out/constraints/refinements/min.js.map +0 -1
  231. package/out/constraints/refinements/minLength.d.ts +0 -32
  232. package/out/constraints/refinements/minLength.d.ts.map +0 -1
  233. package/out/constraints/refinements/minLength.js +0 -33
  234. package/out/constraints/refinements/minLength.js.map +0 -1
  235. package/out/constraints/refinements/range.d.ts +0 -119
  236. package/out/constraints/refinements/range.d.ts.map +0 -1
  237. package/out/constraints/refinements/range.js +0 -89
  238. package/out/constraints/refinements/range.js.map +0 -1
  239. package/out/constraints/refinements/regex.d.ts +0 -47
  240. package/out/constraints/refinements/regex.d.ts.map +0 -1
  241. package/out/constraints/refinements/regex.js +0 -37
  242. package/out/constraints/refinements/regex.js.map +0 -1
  243. package/out/constraints/refinements/shared.d.ts +0 -20
  244. package/out/constraints/refinements/shared.d.ts.map +0 -1
  245. package/out/constraints/refinements/shared.js +0 -10
  246. package/out/constraints/refinements/shared.js.map +0 -1
  247. package/out/generic.d.ts.map +0 -1
  248. package/out/inference.d.ts +0 -137
  249. package/out/inference.d.ts.map +0 -1
  250. package/out/inference.js +0 -73
  251. package/out/inference.js.map +0 -1
  252. package/out/keywords/ark.d.ts +0 -70
  253. package/out/keywords/ark.d.ts.map +0 -1
  254. package/out/keywords/ark.js +0 -29
  255. package/out/keywords/ark.js.map +0 -1
  256. package/out/keywords/internal.d.ts +0 -13
  257. package/out/keywords/internal.d.ts.map +0 -1
  258. package/out/keywords/internal.js +0 -13
  259. package/out/keywords/internal.js.map +0 -1
  260. package/out/keywords/jsObject.d.ts +0 -20
  261. package/out/keywords/jsObject.d.ts.map +0 -1
  262. package/out/keywords/jsObject.js +0 -18
  263. package/out/keywords/jsObject.js.map +0 -1
  264. package/out/keywords/parsing.d.ts +0 -17
  265. package/out/keywords/parsing.d.ts.map +0 -1
  266. package/out/keywords/parsing.js +0 -64
  267. package/out/keywords/parsing.js.map +0 -1
  268. package/out/keywords/root.d.ts +0 -7
  269. package/out/keywords/root.d.ts.map +0 -1
  270. package/out/keywords/root.js +0 -4
  271. package/out/keywords/root.js.map +0 -1
  272. package/out/keywords/tsGenerics.d.ts +0 -2
  273. package/out/keywords/tsGenerics.d.ts.map +0 -1
  274. package/out/keywords/tsGenerics.js +0 -26
  275. package/out/keywords/tsGenerics.js.map +0 -1
  276. package/out/keywords/tsPrimitive.d.ts +0 -24
  277. package/out/keywords/tsPrimitive.d.ts.map +0 -1
  278. package/out/keywords/tsPrimitive.js +0 -25
  279. package/out/keywords/tsPrimitive.js.map +0 -1
  280. package/out/keywords/utils/creditCard.d.ts +0 -11
  281. package/out/keywords/utils/creditCard.d.ts.map +0 -1
  282. package/out/keywords/utils/creditCard.js +0 -35
  283. package/out/keywords/utils/creditCard.js.map +0 -1
  284. package/out/keywords/utils/date.d.ts +0 -45
  285. package/out/keywords/utils/date.d.ts.map +0 -1
  286. package/out/keywords/utils/date.js +0 -56
  287. package/out/keywords/utils/date.js.map +0 -1
  288. package/out/keywords/validation.d.ts +0 -20
  289. package/out/keywords/validation.d.ts.map +0 -1
  290. package/out/keywords/validation.js +0 -80
  291. package/out/keywords/validation.js.map +0 -1
  292. package/out/kinds.d.ts +0 -102
  293. package/out/kinds.d.ts.map +0 -1
  294. package/out/kinds.js +0 -29
  295. package/out/kinds.js.map +0 -1
  296. package/out/main.d.ts.map +0 -1
  297. package/out/match.d.ts.map +0 -1
  298. package/out/module.d.ts.map +0 -1
  299. package/out/parse.d.ts +0 -29
  300. package/out/parse.d.ts.map +0 -1
  301. package/out/parse.js +0 -161
  302. package/out/parse.js.map +0 -1
  303. package/out/parser/definition.d.ts.map +0 -1
  304. package/out/parser/generic.d.ts.map +0 -1
  305. package/out/parser/objectLiteral.d.ts.map +0 -1
  306. package/out/parser/semantic/bounds.d.ts.map +0 -1
  307. package/out/parser/semantic/divisor.d.ts.map +0 -1
  308. package/out/parser/semantic/infer.d.ts.map +0 -1
  309. package/out/parser/semantic/utils.d.ts.map +0 -1
  310. package/out/parser/semantic/validate.d.ts.map +0 -1
  311. package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
  312. package/out/parser/string/reduce/shared.d.ts.map +0 -1
  313. package/out/parser/string/reduce/static.d.ts.map +0 -1
  314. package/out/parser/string/shift/operand/date.d.ts.map +0 -1
  315. package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  316. package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
  317. package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
  318. package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  319. package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
  320. package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
  321. package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
  322. package/out/parser/string/shift/scanner.d.ts.map +0 -1
  323. package/out/parser/string/string.d.ts.map +0 -1
  324. package/out/parser/tuple.d.ts.map +0 -1
  325. package/out/schema.d.ts +0 -175
  326. package/out/schema.d.ts.map +0 -1
  327. package/out/schema.js +0 -73
  328. package/out/schema.js.map +0 -1
  329. package/out/schemaScope.d.ts +0 -180
  330. package/out/schemaScope.d.ts.map +0 -1
  331. package/out/schemaScope.js +0 -235
  332. package/out/schemaScope.js.map +0 -1
  333. package/out/scope.d.ts.map +0 -1
  334. package/out/shared/compile.d.ts +0 -22
  335. package/out/shared/compile.d.ts.map +0 -1
  336. package/out/shared/compile.js +0 -79
  337. package/out/shared/compile.js.map +0 -1
  338. package/out/shared/context.d.ts +0 -54
  339. package/out/shared/context.d.ts.map +0 -1
  340. package/out/shared/context.js +0 -53
  341. package/out/shared/context.js.map +0 -1
  342. package/out/shared/declare.d.ts +0 -69
  343. package/out/shared/declare.d.ts.map +0 -1
  344. package/out/shared/declare.js +0 -2
  345. package/out/shared/declare.js.map +0 -1
  346. package/out/shared/disjoint.d.ts +0 -91
  347. package/out/shared/disjoint.d.ts.map +0 -1
  348. package/out/shared/disjoint.js +0 -110
  349. package/out/shared/disjoint.js.map +0 -1
  350. package/out/shared/errors.d.ts +0 -99
  351. package/out/shared/errors.d.ts.map +0 -1
  352. package/out/shared/errors.js +0 -108
  353. package/out/shared/errors.js.map +0 -1
  354. package/out/shared/implement.d.ts +0 -363
  355. package/out/shared/implement.d.ts.map +0 -1
  356. package/out/shared/implement.js +0 -68
  357. package/out/shared/implement.js.map +0 -1
  358. package/out/shared/inference.d.ts +0 -6
  359. package/out/shared/inference.d.ts.map +0 -1
  360. package/out/shared/inference.js +0 -5
  361. package/out/shared/inference.js.map +0 -1
  362. package/out/shared/intersections.d.ts +0 -60
  363. package/out/shared/intersections.d.ts.map +0 -1
  364. package/out/shared/intersections.js +0 -2
  365. package/out/shared/intersections.js.map +0 -1
  366. package/out/shared/traversal.d.ts +0 -62
  367. package/out/shared/traversal.d.ts.map +0 -1
  368. package/out/shared/traversal.js +0 -97
  369. package/out/shared/traversal.js.map +0 -1
  370. package/out/shared/utils.d.ts +0 -24
  371. package/out/shared/utils.d.ts.map +0 -1
  372. package/out/shared/utils.js +0 -15
  373. package/out/shared/utils.js.map +0 -1
  374. package/out/type.d.ts.map +0 -1
  375. package/out/types/basis.d.ts +0 -47
  376. package/out/types/basis.d.ts.map +0 -1
  377. package/out/types/basis.js +0 -15
  378. package/out/types/basis.js.map +0 -1
  379. package/out/types/discriminate.d.ts +0 -34
  380. package/out/types/discriminate.d.ts.map +0 -1
  381. package/out/types/discriminate.js +0 -120
  382. package/out/types/discriminate.js.map +0 -1
  383. package/out/types/domain.d.ts +0 -57
  384. package/out/types/domain.d.ts.map +0 -1
  385. package/out/types/domain.js +0 -41
  386. package/out/types/domain.js.map +0 -1
  387. package/out/types/intersection.d.ts +0 -127
  388. package/out/types/intersection.d.ts.map +0 -1
  389. package/out/types/intersection.js +0 -379
  390. package/out/types/intersection.js.map +0 -1
  391. package/out/types/morph.d.ts +0 -157
  392. package/out/types/morph.d.ts.map +0 -1
  393. package/out/types/morph.js +0 -99
  394. package/out/types/morph.js.map +0 -1
  395. package/out/types/proto.d.ts +0 -51
  396. package/out/types/proto.d.ts.map +0 -1
  397. package/out/types/proto.js +0 -60
  398. package/out/types/proto.js.map +0 -1
  399. package/out/types/type.d.ts +0 -143
  400. package/out/types/type.d.ts.map +0 -1
  401. package/out/types/type.js +0 -123
  402. package/out/types/type.js.map +0 -1
  403. package/out/types/union.d.ts +0 -71
  404. package/out/types/union.d.ts.map +0 -1
  405. package/out/types/union.js +0 -379
  406. package/out/types/union.js.map +0 -1
  407. package/out/types/unit.d.ts +0 -45
  408. package/out/types/unit.d.ts.map +0 -1
  409. package/out/types/unit.js +0 -56
  410. package/out/types/unit.js.map +0 -1
  411. package/out/util.d.ts +0 -31
  412. package/out/util.d.ts.map +0 -1
  413. package/out/util.js +0 -8
  414. package/out/util.js.map +0 -1
@@ -2,7 +2,6 @@ import {
2
2
  type GenericProps,
3
3
  type PrivateDeclaration,
4
4
  RawSchema,
5
- type SchemaModule,
6
5
  hasArkKind,
7
6
  type writeNonSubmoduleDotMessage,
8
7
  writeUnresolvableMessage
@@ -11,6 +10,7 @@ import {
11
10
  type BigintLiteral,
12
11
  type Completion,
13
12
  type ErrorMessage,
13
+ type isAnyOrNever,
14
14
  type join,
15
15
  printable,
16
16
  throwParseError,
@@ -33,11 +33,8 @@ import {
33
33
 
34
34
  export const parseUnenclosed = (s: DynamicState): void => {
35
35
  const token = s.scanner.shiftUntilNextTerminator()
36
- if (token === "keyof") {
37
- s.addPrefix("keyof")
38
- } else {
39
- s.root = unenclosedToNode(s, token)
40
- }
36
+ if (token === "keyof") s.addPrefix("keyof")
37
+ else s.root = unenclosedToNode(s, token)
41
38
  }
42
39
 
43
40
  export type parseUnenclosed<s extends StaticState, $, args> =
@@ -48,7 +45,9 @@ export type parseUnenclosed<s extends StaticState, $, args> =
48
45
  : tryResolve<s, token, $, args> extends infer result ?
49
46
  result extends ErrorMessage<infer message> ? state.error<message>
50
47
  : result extends keyof $ ?
51
- $[result] extends GenericProps ?
48
+ isAnyOrNever<$[result]> extends true ?
49
+ state.setRoot<s, result, unscanned>
50
+ : $[result] extends GenericProps ?
52
51
  parseGenericInstantiation<
53
52
  token,
54
53
  $[result],
@@ -68,9 +67,9 @@ export const parseGenericInstantiation = (
68
67
  ): RawSchema => {
69
68
  s.scanner.shiftUntilNonWhitespace()
70
69
  const lookahead = s.scanner.shift()
71
- if (lookahead !== "<") {
70
+ if (lookahead !== "<")
72
71
  return s.error(writeInvalidGenericArgsMessage(name, g.params, []))
73
- }
72
+
74
73
  const parsedArgs = parseGenericArgs(name, g.params, s)
75
74
  const remainingChars = parsedArgs.unscanned.length
76
75
  // set the scanner position to where the args scanner left off
@@ -115,8 +114,7 @@ const maybeParseReference = (
115
114
  ): RawSchema | undefined => {
116
115
  if (s.ctx.args?.[token]) return s.ctx.args[token].raw
117
116
  const resolution = s.ctx.$.maybeResolve(token)
118
- // TODO: centralize member creation
119
- if (resolution instanceof RawSchema) return resolution.bindScope(s.ctx.$)
117
+ if (resolution instanceof RawSchema) return resolution
120
118
  if (resolution === undefined) return
121
119
  if (hasArkKind(resolution, "generic"))
122
120
  return parseGenericInstantiation(token, resolution as Generic, s)
@@ -128,13 +126,12 @@ const maybeParseUnenclosedLiteral = (
128
126
  token: string
129
127
  ): RawSchema | undefined => {
130
128
  const maybeNumber = tryParseNumber(token, { strict: true })
131
- if (maybeNumber !== undefined) {
129
+ if (maybeNumber !== undefined)
132
130
  return s.ctx.$.node("unit", { unit: maybeNumber })
133
- }
131
+
134
132
  const maybeBigint = tryParseWellFormedBigint(token)
135
- if (maybeBigint !== undefined) {
133
+ if (maybeBigint !== undefined)
136
134
  return s.ctx.$.node("unit", { unit: maybeBigint })
137
- }
138
135
  }
139
136
 
140
137
  type tryResolve<s extends StaticState, token extends string, $, args> =
@@ -146,16 +143,9 @@ type tryResolve<s extends StaticState, token extends string, $, args> =
146
143
  : token extends (
147
144
  `${infer submodule extends keyof $ & string}.${infer reference}`
148
145
  ) ?
149
- $[submodule] extends (
150
- SchemaModule<infer sub$> | Module<infer sub$> // TODO: shouldn't need both checks?
151
- ) ?
152
- reference extends keyof sub$ ? token
153
- : unknown extends sub$ ?
154
- // not sure why we need the additional check here, but for now TS seems to
155
- // hit this branch for a non-scope dot access rather than failing
156
- // initially when we try to infer r. if this can be removed without breaking
157
- // any submodule test cases, do it!
158
- ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
146
+ $[submodule] extends Module<infer sub$> ?
147
+ reference extends keyof sub$ ?
148
+ token
159
149
  : unresolvableError<s, reference, $[submodule], args, [submodule]>
160
150
  : ErrorMessage<writeNonSubmoduleDotMessage<submodule>>
161
151
  : unresolvableError<s, token, $, args, []>
@@ -181,9 +181,8 @@ export const parseRightBound = (
181
181
  if (
182
182
  !limitNode.hasKind("unit") ||
183
183
  (typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date))
184
- ) {
184
+ )
185
185
  return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"))
186
- }
187
186
 
188
187
  const limit = limitNode.unit
189
188
  // apply the newly-parsed right bound
@@ -194,16 +193,15 @@ export const parseRightBound = (
194
193
  typeof limit === "number" ? limit : (limitToken as DateLiteral),
195
194
  previousRoot,
196
195
  "right"
197
- )) {
196
+ ))
198
197
  s.constrainRoot(kind, { rule: limit, exclusive })
199
- }
200
- if (!s.branches.leftBound) {
201
- return
202
- }
198
+
199
+ if (!s.branches.leftBound) return
200
+
203
201
  // if there's an open left bound, perform additional validation and apply it
204
- if (!isKeyOf(comparator, maxComparators)) {
202
+ if (!isKeyOf(comparator, maxComparators))
205
203
  return s.error(writeUnpairableComparatorMessage(comparator))
206
- }
204
+
207
205
  const lowerBoundKind = getBoundKinds(
208
206
  s.branches.leftBound.comparator,
209
207
  s.branches.leftBound.limit,
@@ -8,9 +8,8 @@ export const parseDivisor = (s: DynamicStateWithRoot): void => {
8
8
  const divisor = tryParseInteger(divisorToken, {
9
9
  errorOnFail: writeInvalidDivisorMessage(divisorToken)
10
10
  })
11
- if (divisor === 0) {
12
- s.error(writeInvalidDivisorMessage(0))
13
- }
11
+ if (divisor === 0) s.error(writeInvalidDivisorMessage(0))
12
+
14
13
  s.root = s.root.constrain("divisor", divisor)
15
14
  }
16
15
 
@@ -27,11 +27,9 @@ export class Scanner<Lookahead extends string = string> {
27
27
  let shifted = ""
28
28
  while (this.lookahead) {
29
29
  if (condition(this, shifted)) {
30
- if (shifted[shifted.length - 1] === Scanner.escapeToken) {
30
+ if (shifted[shifted.length - 1] === Scanner.escapeToken)
31
31
  shifted = shifted.slice(0, -1)
32
- } else {
33
- break
34
- }
32
+ else break
35
33
  }
36
34
  shifted += this.shift()
37
35
  }
@@ -62,9 +62,8 @@ type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<
62
62
  >
63
63
 
64
64
  export const parseUntilFinalizer = (s: DynamicState): DynamicStateWithRoot => {
65
- while (s.finalizer === undefined) {
66
- next(s)
67
- }
65
+ while (s.finalizer === undefined) next(s)
66
+
68
67
  return s as DynamicStateWithRoot
69
68
  }
70
69
 
package/parser/tuple.ts CHANGED
@@ -53,34 +53,33 @@ export const parseTupleLiteral = (def: array, ctx: ParseContext): RawSchema => {
53
53
 
54
54
  i++
55
55
  if (def[i] === "?") {
56
- if (spread) {
57
- return throwParseError(spreadOptionalMessage)
58
- }
56
+ if (spread) return throwParseError(spreadOptionalMessage)
57
+
59
58
  optional = true
60
59
  i++
61
60
  }
62
61
  if (spread) {
63
- if (!element.extends(jsObjects.Array)) {
62
+ if (!element.extends(jsObjects.Array))
64
63
  return throwParseError(writeNonArraySpreadMessage(element.expression))
65
- }
64
+
66
65
  // a spread must be distributed over branches e.g.:
67
66
  // def: [string, ...(number[] | [true, false])]
68
67
  // nodes: [string, ...number[]] | [string, true, false]
69
- sequences = sequences.flatMap((base) =>
68
+ sequences = sequences.flatMap(base =>
70
69
  // since appendElement mutates base, we have to shallow-ish clone it for each branch
71
- element.branches.map((branch) =>
70
+ element.branches.map(branch =>
72
71
  appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)
73
72
  )
74
73
  )
75
74
  } else {
76
- sequences = sequences.map((base) =>
75
+ sequences = sequences.map(base =>
77
76
  appendElement(base, optional ? "optional" : "required", element)
78
77
  )
79
78
  }
80
79
  }
81
80
  return ctx.$.raw.schema(
82
81
  sequences.map(
83
- (sequence) =>
82
+ sequence =>
84
83
  ({
85
84
  proto: Array,
86
85
  sequence
@@ -143,10 +142,10 @@ const appendSpreadBranch = (
143
142
  // the only array with no sequence reference is unknown[]
144
143
  return appendElement(base, "variadic", tsKeywords.unknown)
145
144
  }
146
- spread.prefix.forEach((node) => appendElement(base, "required", node))
147
- spread.optional.forEach((node) => appendElement(base, "optional", node))
145
+ spread.prefix.forEach(node => appendElement(base, "required", node))
146
+ spread.optional.forEach(node => appendElement(base, "optional", node))
148
147
  spread.variadic && appendElement(base, "variadic", spread.variadic)
149
- spread.postfix.forEach((node) => appendElement(base, "required", node))
148
+ spread.postfix.forEach(node => appendElement(base, "required", node))
150
149
  return base
151
150
  }
152
151
 
@@ -414,9 +413,9 @@ export type inferKeyOfExpression<operandDef, $, args> = show<
414
413
  >
415
414
 
416
415
  const parseBranchTuple: PostfixParser<"|" | "&"> = (def, ctx) => {
417
- if (def[2] === undefined) {
416
+ if (def[2] === undefined)
418
417
  return throwParseError(writeMissingRightOperandMessage(def[1], ""))
419
- }
418
+
420
419
  const l = ctx.$.parse(def[0], ctx)
421
420
  const r = ctx.$.parse(def[2], ctx)
422
421
  return def[1] === "&" ? l.and(r) : l.or(r)
@@ -459,7 +458,7 @@ export const parseMorphTuple: PostfixParser<"=>"> = (def, ctx) => {
459
458
  )
460
459
  }
461
460
  // TODO: nested morphs?
462
- return ctx.$.parse(def[0], ctx).morph(def[2] as Morph)
461
+ return ctx.$.parse(def[0], ctx).pipe(def[2] as Morph)
463
462
  }
464
463
 
465
464
  export const writeMalformedFunctionalExpressionMessage = (
@@ -518,7 +517,7 @@ const prefixParsers: {
518
517
  }
519
518
  const branches = def
520
519
  .slice(1)
521
- .map((ctor) =>
520
+ .map(ctor =>
522
521
  typeof ctor === "function" ?
523
522
  ctx.$.node("proto", { proto: ctor as Constructor })
524
523
  : throwParseError(
package/scope.ts CHANGED
@@ -1,24 +1,28 @@
1
1
  import {
2
2
  type ArkConfig,
3
3
  type GenericProps,
4
- type NodeParseOptions,
5
4
  type PreparsedNodeResolution,
5
+ type PrivateDeclaration,
6
6
  type RawSchema,
7
7
  type RawSchemaResolutions,
8
8
  RawSchemaScope,
9
9
  type SchemaScope,
10
+ type UnknownSchema,
10
11
  type ambient,
11
12
  type arkKind,
12
13
  type destructuredExportContext,
13
14
  type destructuredImportContext,
14
15
  type exportedNameOf,
15
- hasArkKind
16
+ hasArkKind,
17
+ type writeDuplicateAliasError
16
18
  } from "@arktype/schema"
17
19
  import {
18
20
  type Dict,
19
21
  domainOf,
20
22
  hasDomain,
23
+ type isAnyOrNever,
21
24
  isThunk,
25
+ type keyError,
22
26
  type nominal,
23
27
  type show,
24
28
  throwParseError
@@ -40,11 +44,12 @@ import {
40
44
  } from "./parser/generic.js"
41
45
  import { DynamicState } from "./parser/string/reduce/dynamic.js"
42
46
  import { fullStringParse } from "./parser/string/string.js"
43
- import type {
44
- DeclarationParser,
45
- DefinitionParser,
46
- Type,
47
- TypeParser
47
+ import {
48
+ type DeclarationParser,
49
+ type DefinitionParser,
50
+ RawTypeParser,
51
+ type Type,
52
+ type TypeParser
48
53
  } from "./type.js"
49
54
 
50
55
  export type ScopeParser = <const def>(
@@ -54,12 +59,14 @@ export type ScopeParser = <const def>(
54
59
 
55
60
  type validateScope<def> = {
56
61
  [k in keyof def]: k extends symbol ?
57
- // this should only occur when importing/exporting modules, and those keys should be ignored
62
+ // this should only occur when importing/exporting modules, and those
63
+ // keys should be ignored
58
64
  unknown
59
65
  : parseScopeKey<k>["params"] extends [] ?
60
66
  // Not including Type here directly breaks inference
61
- def[k] extends Type | PreparsedResolution ?
62
- def[k]
67
+ def[k] extends Type | PreparsedResolution ? def[k]
68
+ : k extends PrivateDeclaration<infer name extends keyof def & string> ?
69
+ keyError<writeDuplicateAliasError<name>>
63
70
  : validateDefinition<def[k], ambient & bootstrapAliases<def>, {}>
64
71
  : parseScopeKey<k>["params"] extends GenericParamsParseError ?
65
72
  // use the full nominal type here to avoid an overlap between the
@@ -126,12 +133,9 @@ export type resolve<reference extends keyof $ | keyof args, $, args> =
126
133
  args[reference]
127
134
  : $[reference & keyof $]
128
135
  ) extends infer resolution ?
129
- resolution extends Def<infer def> ?
130
- def extends null ?
131
- // handle resolution of any and never
132
- resolution
133
- : inferDefinition<def, $, args>
134
- : resolution
136
+ isAnyOrNever<resolution> extends true ? resolution
137
+ : resolution extends Def<infer def> ? inferDefinition<def, $, args>
138
+ : resolution
135
139
  : never
136
140
 
137
141
  export type moduleKeyOf<$> = {
@@ -148,8 +152,9 @@ export type tryInferSubmoduleReference<$, token> =
148
152
  : never
149
153
  : never
150
154
 
151
- export interface ParseContext extends NodeParseOptions {
155
+ export interface ParseContext {
152
156
  $: RawScope
157
+ args?: Record<string, UnknownSchema>
153
158
  }
154
159
 
155
160
  export const scope: ScopeParser = ((def: Dict, config: ArkConfig = {}) =>
@@ -191,65 +196,42 @@ export class RawScope<
191
196
  super(aliases, config)
192
197
  }
193
198
 
194
- type(...args: unknown[]): RawSchema | Generic {
195
- if (args.length === 1) {
196
- // treat as a simple definition
197
- return this.parseRoot(args[0])
198
- }
199
- if (
200
- args.length === 2 &&
201
- typeof args[0] === "string" &&
202
- args[0][0] === "<" &&
203
- args[0].at(-1) === ">"
204
- ) {
205
- // if there are exactly two args, the first of which looks like <${string}>,
206
- // treat as a generic
207
- const params = parseGenericParams(args[0].slice(1, -1))
208
- const def = args[1]
209
- // TODO: validateUninstantiatedGeneric, remove this cast
210
- return new Generic(params, def, this as never) as never
211
- }
212
- // otherwise, treat as a tuple expression. technically, this also allows
213
- // non-expression tuple definitions to be parsed, but it's not a supported
214
- // part of the API as specified by the associated types
215
- return this.parseRoot(args)
216
- }
199
+ type = new RawTypeParser(this as never)
217
200
 
218
201
  match: MatchParser<$> = createMatchParser(this as never) as never
219
202
 
220
- declare(): { type: RawScope["type"] } {
221
- return { type: this.type.bind(this) }
222
- }
203
+ declare = (() => ({
204
+ type: this.type
205
+ })).bind(this)
223
206
 
224
- define(def: unknown): unknown {
225
- return def
226
- }
207
+ define = ((def: unknown) => def).bind(this)
227
208
 
228
209
  override preparseRoot(def: unknown): unknown {
229
- if (isThunk(def) && !hasArkKind(def, "generic")) {
230
- return def()
231
- }
210
+ if (isThunk(def) && !hasArkKind(def, "generic")) return def()
211
+
232
212
  return def
233
213
  }
234
214
 
235
- override parseRoot(def: unknown, opts?: NodeParseOptions): RawSchema {
215
+ override parseRoot(def: unknown): RawSchema {
216
+ // args: { this: {} as RawSchema },
236
217
  return this.parse(def, {
237
- args: { this: {} as RawSchema },
238
218
  $: this as never,
239
- ...opts
219
+ args: {}
220
+ // type parsing can bypass nodes if it hits the cache,
221
+ // so bind it directly (could be optimized)
240
222
  }).bindScope(this)
241
223
  }
242
224
 
243
225
  parse(def: unknown, ctx: ParseContext): RawSchema {
244
226
  if (typeof def === "string") {
245
- if (ctx.args && Object.keys(ctx.args).every((k) => !def.includes(k))) {
227
+ if (ctx.args && Object.keys(ctx.args).every(k => !def.includes(k))) {
246
228
  // we can only rely on the cache if there are no contextual
247
229
  // resolutions like "this" or generic args
248
230
  return this.parseString(def, ctx)
249
231
  }
250
- if (!this.parseCache[def]) {
232
+ if (!this.parseCache[def])
251
233
  this.parseCache[def] = this.parseString(def, ctx)
252
- }
234
+
253
235
  return this.parseCache[def]
254
236
  }
255
237
  return hasDomain(def, "object") ?
@@ -259,9 +241,9 @@ export class RawScope<
259
241
 
260
242
  parseString(def: string, ctx: ParseContext): RawSchema {
261
243
  return (
262
- this.maybeResolveNode(def) ??
244
+ this.maybeResolveSchema(def) ??
263
245
  ((def.endsWith("[]") &&
264
- this.maybeResolveNode(def.slice(0, -2))?.array()) ||
246
+ this.maybeResolveSchema(def.slice(0, -2))?.array()) ||
265
247
  fullStringParse(new DynamicState(def, ctx)))
266
248
  )
267
249
  }