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
package/out/schema.d.ts DELETED
@@ -1,175 +0,0 @@
1
- import type {
2
- Constructor,
3
- ErrorMessage,
4
- NonEnumerableDomain,
5
- array,
6
- conform,
7
- describe,
8
- inferDomain,
9
- instanceOf,
10
- isAny
11
- } from "@arktype/util"
12
- import type { Node, TypeSchema, UnknownNode } from "./base.js"
13
- import type { Prerequisite, Schema, reducibleKindOf } from "./kinds.js"
14
- import type { SchemaParseOptions } from "./parse.js"
15
- import type { BasisKind, ConstraintKind, NodeKind } from "./shared/implement.js"
16
- import type { DomainNode, DomainSchema } from "./types/domain.js"
17
- import type {
18
- IntersectionNode,
19
- IntersectionSchema
20
- } from "./types/intersection.js"
21
- import type {
22
- Morph,
23
- MorphChildDefinition,
24
- MorphChildKind,
25
- MorphNode,
26
- MorphSchema,
27
- Out,
28
- inferMorphOut
29
- } from "./types/morph.js"
30
- import type { ProtoNode, ProtoSchema } from "./types/proto.js"
31
- import type {
32
- NormalizedUnionSchema,
33
- UnionChildNode,
34
- UnionNode,
35
- UnionSchema
36
- } from "./types/union.js"
37
- import type { UnitNode, UnitSchema } from "./types/unit.js"
38
- export type SchemaParser<$> = <const schema>(
39
- schema: validateSchema<schema, $>
40
- ) => ["schema", schema]
41
- export type NodeParser<$> = {
42
- <kind extends NodeKind, const schema extends Schema<kind>>(
43
- kind: kind,
44
- schema: schema,
45
- opts?: SchemaParseOptions
46
- ): Node<reducibleKindOf<kind>, instantiateSchema<schema, $>["infer"], $>
47
- <const schema extends TypeSchema>(
48
- schema: schema,
49
- opts?: SchemaParseOptions
50
- ): instantiateSchema<schema, $>
51
- }
52
- export type validateSchema<schema, $> = schema extends UnknownNode
53
- ? schema
54
- : schema extends array
55
- ? {
56
- [i in keyof schema]: validateSchemaBranch<schema[i], $>
57
- }
58
- : schema extends NormalizedUnionSchema<infer branches>
59
- ? conform<
60
- schema,
61
- NormalizedUnionSchema & {
62
- branches: {
63
- [i in keyof branches]: validateSchemaBranch<
64
- branches[i],
65
- $
66
- >
67
- }
68
- }
69
- >
70
- : validateSchemaBranch<schema, $>
71
- export type instantiateSchema<schema, $> = schema extends UnionSchema<
72
- infer branches
73
- >
74
- ? branches["length"] extends 0
75
- ? UnionNode<never, "union">
76
- : branches["length"] extends 1
77
- ? instantiateSchemaBranch<branches[0], $>
78
- : Node<
79
- reducibleKindOf<"union">,
80
- instantiateSchemaBranch<branches[number], $>["infer"]
81
- >
82
- : instantiateSchemaBranch<schema, $>
83
- type validateSchemaBranch<schema, $> = schema extends UnknownNode
84
- ? schema
85
- : keyof schema & ("morph" | "in" | "out") extends never
86
- ? validateMorphChild<schema, $>
87
- : validateMorphSchema<schema, $>
88
- type instantiateSchemaBranch<schema, $> = schema extends UnknownNode
89
- ? schema
90
- : schema extends MorphSchema
91
- ? instantiateMorphSchema<schema, $>
92
- : schema extends MorphChildDefinition
93
- ? instantiateMorphChild<schema, $>
94
- : UnionChildNode
95
- type NonIntersectableBasisSchema =
96
- | NonEnumerableDomain
97
- | Constructor
98
- | UnitSchema
99
- type validateMorphChild<schema, $> = [schema] extends [
100
- NonIntersectableBasisSchema
101
- ]
102
- ? schema
103
- : validateIntersectionSchema<schema, $>
104
- type instantiateMorphChild<schema, $> =
105
- schema extends NonIntersectableBasisSchema
106
- ? instantiateBasis<schema, $>
107
- : schema extends IntersectionSchema
108
- ? instantiateIntersectionSchema<schema, $>
109
- : Node<MorphChildKind>
110
- type validateMorphSchema<def, $> = {
111
- [k in keyof def]: k extends "in" | "out"
112
- ? validateMorphChild<def[k], $>
113
- : k extends keyof MorphSchema
114
- ? MorphSchema[k]
115
- : `'${k & string}' is not a valid morph schema key`
116
- }
117
- type instantiateMorphSchema<schema, $> = schema extends MorphSchema
118
- ? MorphNode<
119
- (
120
- In: schema["in"] extends {}
121
- ? instantiateMorphChild<schema["in"], $>["infer"]
122
- : unknown
123
- ) => schema["out"] extends {}
124
- ? Out<instantiateMorphChild<schema["out"], $>["infer"]>
125
- : schema["morphs"] extends
126
- | Morph<any, infer o>
127
- | readonly [...unknown[], Morph<any, infer o>]
128
- ? Out<inferMorphOut<o>>
129
- : never
130
- >
131
- : never
132
- type exactBasisMessageOnError<schema, expected> = {
133
- [k in keyof schema]: k extends keyof expected
134
- ? conform<schema[k], expected[k]>
135
- : ErrorMessage<
136
- k extends ConstraintKind
137
- ? `${k} has a prerequisite of ${describe<Prerequisite<k>>}`
138
- : `'${k & string}' is not on an intersection schema`
139
- >
140
- }
141
- export type validateIntersectionSchema<schema, $> = exactBasisMessageOnError<
142
- schema,
143
- IntersectionSchema<inferBasisOf<schema, $>>
144
- >
145
- type inferBasisOf<schema, $> = "proto" extends keyof schema
146
- ? instantiateBasis<conform<schema["proto"], ProtoSchema>, $>["infer"]
147
- : "domain" extends keyof schema
148
- ? instantiateBasis<conform<schema["domain"], DomainSchema>, $>["infer"]
149
- : unknown
150
- export type instantiateIntersectionSchema<schema, $> = keyof schema &
151
- ConstraintKind extends never
152
- ? "proto" extends keyof schema
153
- ? ProtoNode<inferBasisOf<schema, $>, $>
154
- : "domain" extends keyof schema
155
- ? DomainNode<inferBasisOf<schema, $>, $>
156
- : IntersectionNode
157
- : IntersectionNode<inferBasisOf<schema, $>, $>
158
- export type instantiateBasis<
159
- schema extends Schema<BasisKind>,
160
- $
161
- > = isAny<schema> extends true
162
- ? any
163
- : schema extends NonEnumerableDomain
164
- ? DomainNode<inferDomain<schema>, $>
165
- : schema extends Constructor<infer instance>
166
- ? ProtoNode<instance, $>
167
- : schema extends DomainSchema<infer domain>
168
- ? DomainNode<inferDomain<domain>, $>
169
- : schema extends ProtoSchema<infer proto>
170
- ? ProtoNode<instanceOf<proto>, $>
171
- : schema extends UnitSchema<infer is>
172
- ? UnitNode<is, $>
173
- : never
174
- export {}
175
- //# sourceMappingURL=schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../schema.ts"],"names":[],"mappings":"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,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAC/B,MAAM,SAAS,UAAU,CAAC,MAAM,EAAE,CAAC,GACnC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,GACf,KAAK,CAAA"}
package/out/schema.js DELETED
@@ -1,73 +0,0 @@
1
- export {}
2
- // export type inferPropsInput<input extends PropsInput> =
3
- // input extends PropsInputTuple<infer named, infer indexed>
4
- // ? inferIndexed<indexed, inferNamedProps<named, indexed>>
5
- // : input extends NamedPropsInput
6
- // ? inferNamedProps<input, []>
7
- // : never
8
- // type inferIndexed<
9
- // indexed extends readonly IndexedPropInput[],
10
- // result = unknown
11
- // > = indexed extends readonly [
12
- // infer entry extends IndexedPropInput,
13
- // ...infer tail extends IndexedPropInput[]
14
- // ]
15
- // ? inferIndexed<
16
- // tail,
17
- // entry["key"] extends { readonly regex: VariadicIndexMatcherLiteral }
18
- // ? result extends List
19
- // ? [...result, ...inferTypeInput<entry["value"]>[]]
20
- // : never
21
- // : entry["key"] extends {
22
- // readonly regex: NonVariadicIndexMatcherLiteral
23
- // }
24
- // ? inferTypeInput<entry["value"]>[]
25
- // : Record<
26
- // Extract<inferTypeInput<entry["key"]>, PropertyKey>,
27
- // inferTypeInput<entry["value"]>
28
- // >
29
- // >
30
- // : result
31
- // type inferNamedProps<
32
- // named extends NamedPropsInput,
33
- // indexed extends readonly IndexedPropInput[]
34
- // > = [named, indexed[0]["key"]] extends
35
- // | [TupleLengthProps, unknown]
36
- // | [unknown, { readonly regex: VariadicIndexMatcherLiteral }]
37
- // ? inferNonVariadicTupleProps<named> &
38
- // inferObjectLiteralProps<Omit<named, "length" | NumberLiteral | number>>
39
- // : inferObjectLiteralProps<named>
40
- // type inferObjectLiteralProps<named extends NamedPropsInput> = {} extends named
41
- // ? unknown
42
- // : evaluate<
43
- // {
44
- // [k in requiredKeyOf<named>]: inferPropValue<named[k]["value"]>
45
- // } & {
46
- // [k in optionalKeyOf<named>]?: inferPropValue<named[k]["value"]>
47
- // }
48
- // >
49
- // type inferPropValue<value extends PropValueInput> = value extends Thunk<
50
- // infer ret
51
- // >
52
- // ? inferResolvedPropValue<ret>
53
- // : inferResolvedPropValue<value>
54
- // type inferResolvedPropValue<value> = value extends TypeNode<infer t>
55
- // ? t
56
- // : inferTypeInput<Extract<value, TypeInput>>
57
- // type stringifiedNumericKeyOf<t> = `${Extract<keyof t, number | NumberLiteral>}`
58
- // type inferNonVariadicTupleProps<
59
- // named extends NamedPropsInput,
60
- // result extends unknown[] = []
61
- // > = `${result["length"]}` extends stringifiedNumericKeyOf<named>
62
- // ? inferNonVariadicTupleProps<
63
- // named,
64
- // [...result, inferPropValue<named[`${result["length"]}`]["value"]>]
65
- // >
66
- // : result
67
- // type TupleLengthProps<length extends number = number> = {
68
- // readonly length: {
69
- // readonly prerequisite: true
70
- // readonly value: { readonly basis: readonly ["===", length] }
71
- // }
72
- // }
73
- //# sourceMappingURL=schema.js.map
package/out/schema.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../schema.ts"],"names":[],"mappings":";AAwLA,0DAA0D;AAC1D,6DAA6D;AAC7D,6DAA6D;AAC7D,oCAAoC;AACpC,iCAAiC;AACjC,YAAY;AAEZ,qBAAqB;AACrB,gDAAgD;AAChD,oBAAoB;AACpB,iCAAiC;AACjC,yCAAyC;AACzC,4CAA4C;AAC5C,IAAI;AACJ,mBAAmB;AACnB,WAAW;AACX,0EAA0E;AAC1E,4BAA4B;AAC5B,0DAA0D;AAC1D,eAAe;AACf,+BAA+B;AAC/B,uDAAuD;AACvD,UAAU;AACV,yCAAyC;AACzC,gBAAgB;AAChB,4DAA4D;AAC5D,uCAAuC;AACvC,UAAU;AACV,OAAO;AACP,YAAY;AAEZ,wBAAwB;AACxB,kCAAkC;AAClC,+CAA+C;AAC/C,yCAAyC;AACzC,iCAAiC;AACjC,gEAAgE;AAChE,yCAAyC;AACzC,6EAA6E;AAC7E,oCAAoC;AAEpC,iFAAiF;AACjF,aAAa;AACb,eAAe;AACf,OAAO;AACP,qEAAqE;AACrE,WAAW;AACX,sEAAsE;AACtE,OAAO;AACP,OAAO;AAEP,2EAA2E;AAC3E,aAAa;AACb,IAAI;AACJ,iCAAiC;AACjC,mCAAmC;AAEnC,uEAAuE;AACvE,OAAO;AACP,+CAA+C;AAE/C,kFAAkF;AAElF,mCAAmC;AACnC,kCAAkC;AAClC,iCAAiC;AACjC,mEAAmE;AACnE,iCAAiC;AACjC,YAAY;AACZ,wEAAwE;AACxE,OAAO;AACP,YAAY;AAEZ,4DAA4D;AAC5D,sBAAsB;AACtB,gCAAgC;AAChC,iEAAiE;AACjE,KAAK;AACL,IAAI"}
@@ -1,180 +0,0 @@
1
- import {
2
- type Dict,
3
- type List,
4
- type evaluate,
5
- type require,
6
- type requireKeys
7
- } from "@arktype/util"
8
- import type { Node, TypeNode } from "./base.js"
9
- import type { schema } from "./builtins/builtins.js"
10
- import type { JsObjects } from "./builtins/jsObjects.js"
11
- import type { TsKeywords } from "./builtins/tsKeywords.js"
12
- import type { LengthBoundableData } from "./constraints/refinements/range.js"
13
- import type {
14
- instantiateAliases,
15
- instantiateSchemaBranches,
16
- validateAliases,
17
- validateSchemaBranch
18
- } from "./inference.js"
19
- import { type Schema, type reducibleKindOf } from "./kinds.js"
20
- import { type SchemaParseOptions } from "./parse.js"
21
- import type { TraverseAllows, TraverseApply } from "./shared/context.js"
22
- import type {
23
- ActualWriter,
24
- ArkErrorCode,
25
- ExpectedWriter,
26
- MessageWriter,
27
- ProblemWriter
28
- } from "./shared/errors.js"
29
- import type {
30
- DescriptionWriter,
31
- NodeKind,
32
- TypeKind
33
- } from "./shared/implement.js"
34
- import type {
35
- NormalizedUnionSchema,
36
- UnionChildKind,
37
- UnionNode
38
- } from "./types/union.js"
39
- import type { UnitNode } from "./types/unit.js"
40
- export type nodeResolutions<keywords> = {
41
- [k in keyof keywords]: TypeNode
42
- }
43
- export type BaseResolutions = Record<string, TypeNode>
44
- declare global {
45
- export interface StaticArkConfig {
46
- preserve(): never
47
- }
48
- }
49
- type nodeConfigForKind<kind extends NodeKind> = evaluate<
50
- {
51
- description?: DescriptionWriter<kind>
52
- } & (kind extends ArkErrorCode
53
- ? {
54
- expected?: ExpectedWriter<kind>
55
- actual?: ActualWriter<kind>
56
- problem?: ProblemWriter<kind>
57
- message?: MessageWriter<kind>
58
- }
59
- : {})
60
- >
61
- type NodeConfigsByKind = {
62
- [kind in NodeKind]: nodeConfigForKind<kind>
63
- }
64
- export type NodeConfig<kind extends NodeKind = NodeKind> =
65
- NodeConfigsByKind[kind]
66
- type UnknownNodeConfig = {
67
- description?: DescriptionWriter
68
- expected?: ExpectedWriter
69
- actual?: ActualWriter
70
- problem?: ProblemWriter
71
- message?: MessageWriter
72
- }
73
- export type ParsedUnknownNodeConfig = requireKeys<
74
- UnknownNodeConfig,
75
- "description"
76
- >
77
- export type StaticArkOption<k extends keyof StaticArkConfig> = ReturnType<
78
- StaticArkConfig[k]
79
- >
80
- export interface ArkConfig extends Partial<NodeConfigsByKind> {}
81
- export type ParsedArkConfig = require<ArkConfig, 2>
82
- export declare class ScopeNode<r extends object = any> {
83
- def: Dict
84
- infer: {
85
- [k in keyof r]: r[k] extends schema.cast<infer t> ? t : never
86
- }
87
- static jsObjects: JsObjects.resolutions
88
- static tsKeywords: TsKeywords.resolutions
89
- readonly nodeCache: {
90
- [innerId: string]: Node
91
- }
92
- readonly config: ParsedArkConfig
93
- readonly resolutions: r
94
- readonly referencesByName: {
95
- [name: string]: Node
96
- }
97
- readonly references: readonly Node[]
98
- protected resolved: boolean
99
- protected prereducedAliases: boolean
100
- readonly lengthBoundable: UnionNode<LengthBoundableData>
101
- constructor(def: Dict, config?: ArkConfig)
102
- get tsKeywords(): TsKeywords.resolutions
103
- get jsObjects(): JsObjects.resolutions
104
- static from<const aliases>(
105
- aliases: validateAliases<aliases>,
106
- config?: ArkConfig
107
- ): ScopeNode<instantiateAliases<aliases>>
108
- static root: ScopeNode<{}>
109
- parseUnion<const branches extends readonly Schema<UnionChildKind>[]>(
110
- input: {
111
- branches: {
112
- [i in keyof branches]: validateSchemaBranch<branches[i], r>
113
- }
114
- } & NormalizedUnionSchema
115
- ): instantiateSchemaBranches<branches>
116
- parseBranches<const branches extends readonly Schema<UnionChildKind>[]>(
117
- ...branches: {
118
- [i in keyof branches]: validateSchemaBranch<branches[i], r>
119
- }
120
- ): instantiateSchemaBranches<branches>
121
- parseUnits<const branches extends List>(
122
- ...values: branches
123
- ): branches["length"] extends 1
124
- ? UnionNode<branches[0]>
125
- : UnionNode<branches[number]> | UnitNode<branches[number]>
126
- parseTypeNode<defKind extends TypeKind>(
127
- schema: Schema<defKind>,
128
- opts?: TypeSchemaParseOptions<defKind>
129
- ): Node<reducibleKindOf<defKind>>
130
- parseRoot<kind extends NodeKind>(
131
- kind: kind,
132
- def: Schema<kind>,
133
- opts?: SchemaParseOptions
134
- ): Node<reducibleKindOf<kind>>
135
- parsePrereduced<kind extends NodeKind>(
136
- kind: kind,
137
- def: Schema<kind>
138
- ): Node<kind>
139
- parse<kind extends NodeKind>(
140
- kind: kind,
141
- def: Schema<kind>,
142
- opts?: SchemaParseOptions
143
- ): Node<reducibleKindOf<kind>>
144
- protected bindCompiledScope(references: readonly Node[]): void
145
- protected compileScope(references: readonly Node[]): {
146
- [k: `${string}Allows`]: TraverseAllows
147
- [k: `${string}Apply`]: TraverseApply
148
- }
149
- readonly schema: SchemaParser<r>
150
- }
151
- export type SchemaBranchesParser<$> = <
152
- const branches extends readonly Schema<UnionChildKind>[]
153
- >(
154
- ...branches: {
155
- [i in keyof branches]: validateSchemaBranch<branches[i], $>
156
- }
157
- ) => instantiateSchemaBranches<branches>
158
- export type SchemaParser<$> = SchemaBranchesParser<$> & {
159
- union<const branches extends readonly Schema<UnionChildKind>[]>(
160
- input: {
161
- branches: {
162
- [i in keyof branches]: validateSchemaBranch<branches[i], $>
163
- }
164
- } & NormalizedUnionSchema
165
- ): instantiateSchemaBranches<branches>
166
- units<const branches extends List>(
167
- ...values: branches
168
- ): branches["length"] extends 1
169
- ? UnionNode<branches[0]>
170
- : UnionNode<branches[number]> | UnitNode<branches[number]>
171
- }
172
- export interface TypeSchemaParseOptions<allowedKind extends TypeKind = TypeKind>
173
- extends SchemaParseOptions {
174
- root?: boolean
175
- allowedKinds?: readonly allowedKind[]
176
- }
177
- export declare const scopeNode: typeof ScopeNode.from
178
- export declare const rootSchema: SchemaBranchesParser<{}>
179
- export {}
180
- //# sourceMappingURL=schemaScope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemaScope.d.ts","sourceRoot":"","sources":["../schemaScope.ts"],"names":[],"mappings":"AAAA,OAAO,EAMN,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAC7E,OAAO,KAAK,EACX,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,EACf,oBAAoB,EACpB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAe,KAAK,MAAM,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAA;AAC3E,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,KAAK,EACX,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,MAAM,oBAAo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YAAY,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAAC,CAAC,GAAG;IACvD,KAAK,CAAC,KAAK,CAAC,QAAQ,SAAS,SAAS,MAAM,CAAC,cAAc,CAAC,EAAE,EAC7D,KAAK,EAAE;QACN,QAAQ,EAAE;aACR,CAAC,IAAI,MAAM,QAAQ,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC3D,CAAA;KACD,GAAG,qBAAqB,GACvB,yBAAyB,CAAC,QAAQ,CAAC,CAAA;IAEtC,KAAK,CAAC,KAAK,CAAC,QAAQ,SAAS,IAAI,EAChC,GAAG,MAAM,EAAE,QAAQ,GACjB,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC5B,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GACtB,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;CAC3D,CAAA;AAED,MAAM,WAAW,sBAAsB,CAAC,WAAW,SAAS,QAAQ,GAAG,QAAQ,CAC9E,SAAQ,kBAAkB;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,YAAY,CAAC,EAAE,SAAS,WAAW,EAAE,CAAA;CACrC;AAED,eAAO,MAAM,SAAS,uBAAiB,CAAA;AAEvC,eAAO,MAAM,UAAU,EAAE,oBAAoB,CAAC,EAAE,CAOrC,CAAA"}
@@ -1,235 +0,0 @@
1
- import {
2
- CompiledFunction,
3
- isArray,
4
- printable,
5
- throwInternalError,
6
- throwParseError
7
- } from "@arktype/util"
8
- import { globalConfig } from "./config.js"
9
- import { nodesByKind } from "./kinds.js"
10
- import { parseAttachments } from "./parse.js"
11
- import { NodeCompiler } from "./shared/compile.js"
12
- import { discriminatingIntersectionKeys } from "./types/intersection.js"
13
- import { BaseType } from "./types/type.js"
14
- const parseConfig = (scopeConfig) => {
15
- if (!scopeConfig) {
16
- return globalConfig
17
- }
18
- const parsedConfig = { ...globalConfig }
19
- let k
20
- for (k in scopeConfig) {
21
- if (k === "prereducedAliases") {
22
- parsedConfig[k] = scopeConfig[k]
23
- } else {
24
- parsedConfig[k] = {
25
- ...nodesByKind[k].implementation.defaults,
26
- ...scopeConfig[k]
27
- }
28
- }
29
- }
30
- return parsedConfig
31
- }
32
- const assertTypeKind = (schema) => {
33
- switch (typeof schema) {
34
- case "string":
35
- return "domain"
36
- case "function":
37
- return "proto"
38
- case "object":
39
- // throw at end of function
40
- if (schema === null) break
41
- if (schema instanceof BaseType) return schema.kind
42
- if ("morph" in schema) return "morph"
43
- if ("branches" in schema || isArray(schema)) return "union"
44
- if ("unit" in schema) return "unit"
45
- const schemaKeys = Object.keys(schema)
46
- if (
47
- schemaKeys.length === 0 ||
48
- schemaKeys.some((k) => k in discriminatingIntersectionKeys)
49
- )
50
- return "intersection"
51
- if ("proto" in schema) return "proto"
52
- if ("domain" in schema) return "domain"
53
- }
54
- return throwParseError(`${printable(schema)} is not a valid type schema`)
55
- }
56
- export class ScopeNode {
57
- def
58
- nodeCache = {}
59
- config
60
- resolutions = {}
61
- referencesByName = {}
62
- references
63
- resolved = false
64
- prereducedAliases
65
- lengthBoundable
66
- constructor(def, config = {}) {
67
- this.def = def
68
- this.config = parseConfig(config)
69
- this.prereducedAliases = config.prereducedAliases ?? false
70
- for (const k in this.def) {
71
- this.resolutions[k] = this.parseRoot(
72
- assertTypeKind(this.def[k]),
73
- this.def[k],
74
- {
75
- alias: k,
76
- prereduced: this.prereducedAliases
77
- }
78
- )
79
- }
80
- this.references = Object.values(this.referencesByName)
81
- this.bindCompiledScope(this.references)
82
- this.resolved = true
83
- this.parse(
84
- "union",
85
- {
86
- branches: [
87
- "string",
88
- "number",
89
- "object",
90
- "bigint",
91
- "symbol",
92
- { unit: true },
93
- { unit: false },
94
- { unit: null },
95
- { unit: undefined }
96
- ]
97
- },
98
- { reduceTo: this.parsePrereduced("intersection", {}) }
99
- )
100
- this.lengthBoundable = this.parsePrereduced("union", ["string", Array])
101
- }
102
- get tsKeywords() {
103
- return ScopeNode.tsKeywords
104
- }
105
- get jsObjects() {
106
- return ScopeNode.jsObjects
107
- }
108
- static from(aliases, config = {}) {
109
- return new ScopeNode(aliases, config)
110
- }
111
- static root = this.from({})
112
- parseUnion(input) {
113
- return this.parseRoot("union", input)
114
- }
115
- parseBranches(...branches) {
116
- return branches.length === 1
117
- ? this.parseTypeNode(branches[0], { root: true })
118
- : this.parseRoot("union", branches)
119
- }
120
- parseUnits(...values) {
121
- const uniqueValues = []
122
- for (const value of values) {
123
- if (!uniqueValues.includes(value)) {
124
- uniqueValues.push(value)
125
- }
126
- }
127
- const branches = uniqueValues.map((unit) =>
128
- this.parsePrereduced("unit", { unit })
129
- )
130
- if (branches.length === 1) {
131
- return branches[0]
132
- }
133
- return this.parseRoot("union", {
134
- branches
135
- })
136
- }
137
- parseTypeNode(schema, opts = {}) {
138
- const kind = assertTypeKind(schema)
139
- if (opts.allowedKinds && !opts.allowedKinds.includes(kind)) {
140
- return throwParseError(
141
- `Schema of kind ${kind} should be one of ${opts.allowedKinds}`
142
- )
143
- }
144
- return opts.root
145
- ? this.parseRoot(kind, schema, opts)
146
- : this.parse(kind, schema, opts)
147
- }
148
- parseRoot(kind, def, opts = {}) {
149
- const node = this.parse(kind, def, opts)
150
- if (this.resolved) {
151
- // this node was not part of the original scope, so compile an anonymous scope
152
- // including only its references
153
- this.bindCompiledScope(node.contributesReferences)
154
- } else {
155
- // we're still parsing the scope itself, so defer compilation but
156
- // add the node as a reference
157
- Object.assign(
158
- this.referencesByName,
159
- node.contributesReferencesByName
160
- )
161
- }
162
- return node
163
- }
164
- parsePrereduced(kind, def) {
165
- return this.parse(kind, def, { prereduced: true })
166
- }
167
- parse(kind, def, opts = {}) {
168
- if (opts.alias && opts.alias in this.resolutions) {
169
- return throwInternalError(
170
- `Unexpected attempt to recreate existing alias ${opts.alias}`
171
- )
172
- }
173
- const node = parseAttachments(kind, def, {
174
- ...opts,
175
- $: this,
176
- definition: def,
177
- prereduced: opts.prereduced ?? false
178
- })
179
- return node
180
- }
181
- bindCompiledScope(references) {
182
- const compiledTraversals = this.compileScope(references)
183
- for (const node of references) {
184
- if (node.jit) {
185
- // if node has already been bound to another scope or anonymous type, don't rebind it
186
- continue
187
- }
188
- node.jit = true
189
- node.traverseAllows =
190
- compiledTraversals[`${node.name}Allows`].bind(
191
- compiledTraversals
192
- )
193
- if (node.isType() && !node.includesContextDependentPredicate) {
194
- // if the reference doesn't require context, we can assign over
195
- // it directly to avoid having to initialize it
196
- node.allows = node.traverseAllows
197
- }
198
- node.traverseApply =
199
- compiledTraversals[`${node.name}Apply`].bind(compiledTraversals)
200
- }
201
- }
202
- compileScope(references) {
203
- return new CompiledFunction()
204
- .block(`return`, (js) => {
205
- references.forEach((node) => {
206
- const allowsCompiler = new NodeCompiler("Allows").indent()
207
- node.compile(allowsCompiler)
208
- const applyCompiler = new NodeCompiler("Apply").indent()
209
- node.compile(applyCompiler)
210
- js.line(
211
- allowsCompiler.writeMethod(`${node.name}Allows`) +
212
- ",\n" +
213
- applyCompiler.writeMethod(`${node.name}Apply`) +
214
- ","
215
- )
216
- })
217
- return js
218
- })
219
- .compile()()
220
- }
221
- schema = Object.assign(this.parseBranches.bind(this), {
222
- units: this.parseUnits.bind(this),
223
- union: this.parseUnion.bind(this)
224
- })
225
- }
226
- export const scopeNode = ScopeNode.from
227
- export const rootSchema = (...branches) =>
228
- ScopeNode.root.parseTypeNode(
229
- branches.length === 1 ? branches[0] : branches,
230
- {
231
- root: true,
232
- prereduced: true
233
- }
234
- )
235
- //# sourceMappingURL=schemaScope.js.map