arktype 2.0.0-dev.3 → 2.0.0-dev.5

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 (492) hide show
  1. package/__tests__/array.test.ts +123 -215
  2. package/__tests__/badDefinitionType.test.ts +2 -2
  3. package/__tests__/bounds.test.ts +448 -349
  4. package/__tests__/config.test.ts +8 -6
  5. package/__tests__/cyclic.test.ts +1 -1
  6. package/__tests__/dateLiteral.test.ts +2 -2
  7. package/__tests__/discrimination.test.ts +1 -1
  8. package/__tests__/divisor.test.ts +23 -19
  9. package/__tests__/enclosed.test.ts +7 -2
  10. package/__tests__/errors.test.ts +115 -0
  11. package/__tests__/expressions.test.ts +14 -20
  12. package/__tests__/generic.test.ts +4 -5
  13. package/__tests__/group.test.ts +8 -3
  14. package/__tests__/instanceof.test.ts +7 -7
  15. package/__tests__/intersection.test.ts +62 -38
  16. package/__tests__/keyTraversal.test.ts +0 -2
  17. package/__tests__/keyof.test.ts +15 -13
  18. package/__tests__/keywords.test.ts +29 -25
  19. package/__tests__/literal.test.ts +26 -8
  20. package/__tests__/match.test.ts +28 -16
  21. package/__tests__/morph.test.ts +187 -172
  22. package/__tests__/narrow.test.ts +38 -39
  23. package/__tests__/objectLiteral.test.ts +106 -76
  24. package/__tests__/realWorld.test.ts +62 -0
  25. package/__tests__/schema.bench.ts +14 -0
  26. package/__tests__/schema.test.ts +60 -0
  27. package/__tests__/scope.bench.ts +1 -1
  28. package/__tests__/scope.test.ts +8 -6
  29. package/__tests__/submodule.test.ts +2 -2
  30. package/__tests__/traverse.test.ts +34 -31
  31. package/__tests__/typeMethods.test.ts +2 -3
  32. package/__tests__/typeReference.test.ts +3 -3
  33. package/__tests__/unenclosed.test.ts +9 -3
  34. package/__tests__/union.test.ts +127 -55
  35. package/__tests__/unit.test.ts +61 -0
  36. package/base.ts +520 -0
  37. package/config.ts +25 -0
  38. package/constraints/ast.ts +288 -0
  39. package/constraints/constraint.ts +91 -0
  40. package/constraints/predicate.ts +102 -0
  41. package/constraints/props/index.ts +93 -0
  42. package/constraints/props/prop.ts +146 -0
  43. package/constraints/props/props.ts +148 -0
  44. package/constraints/props/sequence.ts +473 -0
  45. package/constraints/props/shared.ts +5 -0
  46. package/constraints/refinements/after.ts +68 -0
  47. package/constraints/refinements/before.ts +75 -0
  48. package/constraints/refinements/divisor.ts +76 -0
  49. package/constraints/refinements/exactLength.ts +75 -0
  50. package/constraints/refinements/kinds.ts +31 -0
  51. package/constraints/refinements/max.ts +61 -0
  52. package/constraints/refinements/maxLength.ts +66 -0
  53. package/constraints/refinements/min.ts +54 -0
  54. package/constraints/refinements/minLength.ts +63 -0
  55. package/constraints/refinements/range.ts +181 -0
  56. package/constraints/refinements/regex.ts +59 -0
  57. package/{ark.ts → keywords/ark.ts} +40 -30
  58. package/keywords/internal.ts +29 -0
  59. package/keywords/jsObject.ts +39 -0
  60. package/keywords/parsing.ts +87 -0
  61. package/keywords/root.ts +9 -0
  62. package/keywords/tsGenerics.ts +28 -0
  63. package/keywords/tsPrimitive.ts +52 -0
  64. package/keywords/utils/creditCard.ts +37 -0
  65. package/keywords/utils/date.ts +112 -0
  66. package/keywords/validation.ts +115 -0
  67. package/kinds.ts +115 -0
  68. package/main.ts +7 -8
  69. package/match.ts +30 -34
  70. package/out/ark.d.ts +5 -1
  71. package/out/ark.d.ts.map +1 -1
  72. package/out/ark.js +4 -1
  73. package/out/ark.js.map +1 -1
  74. package/out/base.d.ts +129 -0
  75. package/out/base.d.ts.map +1 -0
  76. package/out/base.js +274 -0
  77. package/out/base.js.map +1 -0
  78. package/out/builtins/builtins.d.ts +19 -0
  79. package/out/builtins/builtins.d.ts.map +1 -0
  80. package/out/builtins/builtins.js +12 -0
  81. package/out/builtins/builtins.js.map +1 -0
  82. package/out/builtins/jsObjects.d.ts +19 -0
  83. package/out/builtins/jsObjects.d.ts.map +1 -0
  84. package/out/builtins/jsObjects.js +15 -0
  85. package/out/builtins/jsObjects.js.map +1 -0
  86. package/out/builtins/parsing.d.ts +16 -0
  87. package/out/builtins/parsing.d.ts.map +1 -0
  88. package/out/builtins/parsing.js +59 -0
  89. package/out/builtins/parsing.js.map +1 -0
  90. package/out/builtins/tsGenerics.d.ts +2 -0
  91. package/out/builtins/tsGenerics.d.ts.map +1 -0
  92. package/out/builtins/tsGenerics.js +26 -0
  93. package/out/builtins/tsGenerics.js.map +1 -0
  94. package/out/builtins/tsKeywords.d.ts +23 -0
  95. package/out/builtins/tsKeywords.d.ts.map +1 -0
  96. package/out/builtins/tsKeywords.js +20 -0
  97. package/out/builtins/tsKeywords.js.map +1 -0
  98. package/out/builtins/utils/creditCard.d.ts +3 -0
  99. package/out/builtins/utils/creditCard.d.ts.map +1 -0
  100. package/out/builtins/utils/creditCard.js +36 -0
  101. package/out/builtins/utils/creditCard.js.map +1 -0
  102. package/out/builtins/utils/date.d.ts +22 -0
  103. package/out/builtins/utils/date.d.ts.map +1 -0
  104. package/out/builtins/utils/date.js +53 -0
  105. package/out/builtins/utils/date.js.map +1 -0
  106. package/out/builtins/validation.d.ts +19 -0
  107. package/out/builtins/validation.d.ts.map +1 -0
  108. package/out/builtins/validation.js +70 -0
  109. package/out/builtins/validation.js.map +1 -0
  110. package/out/config.d.ts +6 -0
  111. package/out/config.d.ts.map +1 -0
  112. package/out/config.js +17 -0
  113. package/out/config.js.map +1 -0
  114. package/out/constraints/ast.d.ts +176 -0
  115. package/out/constraints/ast.d.ts.map +1 -0
  116. package/out/constraints/ast.js +2 -0
  117. package/out/constraints/ast.js.map +1 -0
  118. package/out/constraints/constraint.d.ts +70 -0
  119. package/out/constraints/constraint.d.ts.map +1 -0
  120. package/out/constraints/constraint.js +21 -0
  121. package/out/constraints/constraint.js.map +1 -0
  122. package/out/constraints/predicate.d.ts +46 -0
  123. package/out/constraints/predicate.d.ts.map +1 -0
  124. package/out/constraints/predicate.js +47 -0
  125. package/out/constraints/predicate.js.map +1 -0
  126. package/out/constraints/props/index.d.ts +36 -0
  127. package/out/constraints/props/index.d.ts.map +1 -0
  128. package/out/constraints/props/index.js +48 -0
  129. package/out/constraints/props/index.js.map +1 -0
  130. package/out/constraints/props/optional.d.ts +34 -0
  131. package/out/constraints/props/optional.d.ts.map +1 -0
  132. package/out/constraints/props/optional.js +55 -0
  133. package/out/constraints/props/optional.js.map +1 -0
  134. package/out/constraints/props/prop.d.ts +46 -0
  135. package/out/constraints/props/prop.d.ts.map +1 -0
  136. package/out/constraints/props/prop.js +104 -0
  137. package/out/constraints/props/prop.js.map +1 -0
  138. package/out/constraints/props/props.d.ts +34 -0
  139. package/out/constraints/props/props.d.ts.map +1 -0
  140. package/out/constraints/props/props.js +106 -0
  141. package/out/constraints/props/props.js.map +1 -0
  142. package/out/constraints/props/required.d.ts +43 -0
  143. package/out/constraints/props/required.d.ts.map +1 -0
  144. package/out/constraints/props/required.js +76 -0
  145. package/out/constraints/props/required.js.map +1 -0
  146. package/out/constraints/props/sequence.d.ts +64 -0
  147. package/out/constraints/props/sequence.d.ts.map +1 -0
  148. package/out/constraints/props/sequence.js +327 -0
  149. package/out/constraints/props/sequence.js.map +1 -0
  150. package/out/constraints/props/shared.d.ts +3 -0
  151. package/out/constraints/props/shared.d.ts.map +1 -0
  152. package/out/constraints/props/shared.js +4 -0
  153. package/out/constraints/props/shared.js.map +1 -0
  154. package/out/constraints/refinements/after.d.ts +25 -0
  155. package/out/constraints/refinements/after.d.ts.map +1 -0
  156. package/out/constraints/refinements/after.js +35 -0
  157. package/out/constraints/refinements/after.js.map +1 -0
  158. package/out/constraints/refinements/before.d.ts +25 -0
  159. package/out/constraints/refinements/before.d.ts.map +1 -0
  160. package/out/constraints/refinements/before.js +41 -0
  161. package/out/constraints/refinements/before.js.map +1 -0
  162. package/out/constraints/refinements/divisor.d.ts +42 -0
  163. package/out/constraints/refinements/divisor.d.ts.map +1 -0
  164. package/out/constraints/refinements/divisor.js +41 -0
  165. package/out/constraints/refinements/divisor.js.map +1 -0
  166. package/out/constraints/refinements/exactLength.d.ts +41 -0
  167. package/out/constraints/refinements/exactLength.d.ts.map +1 -0
  168. package/out/constraints/refinements/exactLength.js +44 -0
  169. package/out/constraints/refinements/exactLength.js.map +1 -0
  170. package/out/constraints/refinements/kinds.d.ts +29 -0
  171. package/out/constraints/refinements/kinds.d.ts.map +1 -0
  172. package/out/constraints/refinements/kinds.js +17 -0
  173. package/out/constraints/refinements/kinds.js.map +1 -0
  174. package/out/constraints/refinements/length.d.ts +42 -0
  175. package/out/constraints/refinements/length.d.ts.map +1 -0
  176. package/out/constraints/refinements/length.js +45 -0
  177. package/out/constraints/refinements/length.js.map +1 -0
  178. package/out/constraints/refinements/max.d.ts +24 -0
  179. package/out/constraints/refinements/max.d.ts.map +1 -0
  180. package/out/constraints/refinements/max.js +31 -0
  181. package/out/constraints/refinements/max.js.map +1 -0
  182. package/out/constraints/refinements/maxLength.d.ts +24 -0
  183. package/out/constraints/refinements/maxLength.d.ts.map +1 -0
  184. package/out/constraints/refinements/maxLength.js +34 -0
  185. package/out/constraints/refinements/maxLength.js.map +1 -0
  186. package/out/constraints/refinements/min.d.ts +24 -0
  187. package/out/constraints/refinements/min.d.ts.map +1 -0
  188. package/out/constraints/refinements/min.js +25 -0
  189. package/out/constraints/refinements/min.js.map +1 -0
  190. package/out/constraints/refinements/minLength.d.ts +24 -0
  191. package/out/constraints/refinements/minLength.d.ts.map +1 -0
  192. package/out/constraints/refinements/minLength.js +32 -0
  193. package/out/constraints/refinements/minLength.js.map +1 -0
  194. package/out/constraints/refinements/range.d.ts +90 -0
  195. package/out/constraints/refinements/range.d.ts.map +1 -0
  196. package/out/constraints/refinements/range.js +72 -0
  197. package/out/constraints/refinements/range.js.map +1 -0
  198. package/out/constraints/refinements/regex.d.ts +43 -0
  199. package/out/constraints/refinements/regex.d.ts.map +1 -0
  200. package/out/constraints/refinements/regex.js +36 -0
  201. package/out/constraints/refinements/regex.js.map +1 -0
  202. package/out/constraints/refinements/shared.d.ts +5 -0
  203. package/out/constraints/refinements/shared.d.ts.map +1 -0
  204. package/out/constraints/refinements/shared.js +10 -0
  205. package/out/constraints/refinements/shared.js.map +1 -0
  206. package/out/inference.d.ts +40 -0
  207. package/out/inference.d.ts.map +1 -0
  208. package/out/inference.js +73 -0
  209. package/out/inference.js.map +1 -0
  210. package/out/keywords/ark.d.ts +60 -0
  211. package/out/keywords/ark.d.ts.map +1 -0
  212. package/out/keywords/ark.js +29 -0
  213. package/out/keywords/ark.js.map +1 -0
  214. package/out/keywords/internal.d.ts +13 -0
  215. package/out/keywords/internal.d.ts.map +1 -0
  216. package/out/keywords/internal.js +10 -0
  217. package/out/keywords/internal.js.map +1 -0
  218. package/out/keywords/jsObject.d.ts +20 -0
  219. package/out/keywords/jsObject.d.ts.map +1 -0
  220. package/out/keywords/jsObject.js +15 -0
  221. package/out/keywords/jsObject.js.map +1 -0
  222. package/out/keywords/parsing.d.ts +17 -0
  223. package/out/keywords/parsing.d.ts.map +1 -0
  224. package/out/keywords/parsing.js +61 -0
  225. package/out/keywords/parsing.js.map +1 -0
  226. package/out/keywords/root.d.ts +7 -0
  227. package/out/keywords/root.d.ts.map +1 -0
  228. package/out/keywords/root.js +4 -0
  229. package/out/keywords/root.js.map +1 -0
  230. package/out/keywords/tsGenerics.d.ts +2 -0
  231. package/out/keywords/tsGenerics.d.ts.map +1 -0
  232. package/out/keywords/tsGenerics.js +26 -0
  233. package/out/keywords/tsGenerics.js.map +1 -0
  234. package/out/keywords/tsPrimitive.d.ts +24 -0
  235. package/out/keywords/tsPrimitive.d.ts.map +1 -0
  236. package/out/keywords/tsPrimitive.js +22 -0
  237. package/out/keywords/tsPrimitive.js.map +1 -0
  238. package/out/keywords/utils/creditCard.d.ts +8 -0
  239. package/out/keywords/utils/creditCard.d.ts.map +1 -0
  240. package/out/keywords/utils/creditCard.js +36 -0
  241. package/out/keywords/utils/creditCard.js.map +1 -0
  242. package/out/keywords/utils/date.d.ts +25 -0
  243. package/out/keywords/utils/date.d.ts.map +1 -0
  244. package/out/keywords/utils/date.js +53 -0
  245. package/out/keywords/utils/date.js.map +1 -0
  246. package/out/keywords/validation.d.ts +20 -0
  247. package/out/keywords/validation.d.ts.map +1 -0
  248. package/out/keywords/validation.js +76 -0
  249. package/out/keywords/validation.js.map +1 -0
  250. package/out/kinds.d.ts +72 -0
  251. package/out/kinds.d.ts.map +1 -0
  252. package/out/kinds.js +29 -0
  253. package/out/kinds.js.map +1 -0
  254. package/out/main.d.ts +5 -4
  255. package/out/main.d.ts.map +1 -1
  256. package/out/main.js +2 -3
  257. package/out/main.js.map +1 -1
  258. package/out/match.d.ts +17 -18
  259. package/out/match.d.ts.map +1 -1
  260. package/out/match.js +3 -4
  261. package/out/match.js.map +1 -1
  262. package/out/parse.d.ts +23 -0
  263. package/out/parse.d.ts.map +1 -0
  264. package/out/parse.js +148 -0
  265. package/out/parse.js.map +1 -0
  266. package/out/parser/definition.d.ts +8 -9
  267. package/out/parser/definition.d.ts.map +1 -1
  268. package/out/parser/definition.js +8 -9
  269. package/out/parser/definition.js.map +1 -1
  270. package/out/parser/objectLiteral.d.ts +44 -11
  271. package/out/parser/objectLiteral.d.ts.map +1 -1
  272. package/out/parser/objectLiteral.js +47 -35
  273. package/out/parser/objectLiteral.js.map +1 -1
  274. package/out/parser/semantic/bounds.d.ts +8 -6
  275. package/out/parser/semantic/bounds.d.ts.map +1 -1
  276. package/out/parser/semantic/bounds.js.map +1 -1
  277. package/out/parser/semantic/divisor.d.ts +4 -6
  278. package/out/parser/semantic/divisor.d.ts.map +1 -1
  279. package/out/parser/semantic/infer.d.ts +28 -0
  280. package/out/parser/semantic/infer.d.ts.map +1 -0
  281. package/out/parser/semantic/infer.js +2 -0
  282. package/out/parser/semantic/infer.js.map +1 -0
  283. package/out/parser/semantic/utils.d.ts +3 -6
  284. package/out/parser/semantic/utils.d.ts.map +1 -1
  285. package/out/parser/semantic/validate.d.ts +1 -1
  286. package/out/parser/semantic/validate.d.ts.map +1 -1
  287. package/out/parser/semantic/validate.js.map +1 -1
  288. package/out/parser/string/reduce/dynamic.d.ts +13 -11
  289. package/out/parser/string/reduce/dynamic.d.ts.map +1 -1
  290. package/out/parser/string/reduce/dynamic.js +15 -9
  291. package/out/parser/string/reduce/dynamic.js.map +1 -1
  292. package/out/parser/string/reduce/shared.d.ts +2 -3
  293. package/out/parser/string/reduce/shared.d.ts.map +1 -1
  294. package/out/parser/string/reduce/shared.js.map +1 -1
  295. package/out/parser/string/reduce/static.d.ts +20 -19
  296. package/out/parser/string/reduce/static.d.ts.map +1 -1
  297. package/out/parser/string/shift/operand/date.d.ts +3 -2
  298. package/out/parser/string/shift/operand/date.d.ts.map +1 -1
  299. package/out/parser/string/shift/operand/date.js.map +1 -1
  300. package/out/parser/string/shift/operand/enclosed.d.ts +1 -1
  301. package/out/parser/string/shift/operand/enclosed.d.ts.map +1 -1
  302. package/out/parser/string/shift/operand/enclosed.js +6 -4
  303. package/out/parser/string/shift/operand/enclosed.js.map +1 -1
  304. package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
  305. package/out/parser/string/shift/operand/genericArgs.d.ts.map +1 -1
  306. package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
  307. package/out/parser/string/shift/operand/operand.d.ts +2 -2
  308. package/out/parser/string/shift/operand/operand.d.ts.map +1 -1
  309. package/out/parser/string/shift/operand/operand.js.map +1 -1
  310. package/out/parser/string/shift/operand/unenclosed.d.ts +5 -6
  311. package/out/parser/string/shift/operand/unenclosed.d.ts.map +1 -1
  312. package/out/parser/string/shift/operand/unenclosed.js +5 -5
  313. package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
  314. package/out/parser/string/shift/operator/bounds.d.ts +17 -12
  315. package/out/parser/string/shift/operator/bounds.d.ts.map +1 -1
  316. package/out/parser/string/shift/operator/bounds.js +28 -25
  317. package/out/parser/string/shift/operator/bounds.js.map +1 -1
  318. package/out/parser/string/shift/operator/divisor.d.ts +1 -1
  319. package/out/parser/string/shift/operator/divisor.d.ts.map +1 -1
  320. package/out/parser/string/shift/operator/divisor.js.map +1 -1
  321. package/out/parser/string/shift/scanner.d.ts.map +1 -1
  322. package/out/parser/string/string.d.ts +3 -3
  323. package/out/parser/string/string.d.ts.map +1 -1
  324. package/out/parser/string/string.js.map +1 -1
  325. package/out/parser/tuple.d.ts +95 -33
  326. package/out/parser/tuple.d.ts.map +1 -1
  327. package/out/parser/tuple.js +45 -48
  328. package/out/parser/tuple.js.map +1 -1
  329. package/out/schema.d.ts +44 -0
  330. package/out/schema.d.ts.map +1 -0
  331. package/out/schema.js +73 -0
  332. package/out/schema.js.map +1 -0
  333. package/out/schemaScope.d.ts +110 -0
  334. package/out/schemaScope.d.ts.map +1 -0
  335. package/out/schemaScope.js +212 -0
  336. package/out/schemaScope.js.map +1 -0
  337. package/out/scope.d.ts +98 -26
  338. package/out/scope.d.ts.map +1 -1
  339. package/out/scope.js +185 -45
  340. package/out/scope.js.map +1 -1
  341. package/out/shared/compile.d.ts +22 -0
  342. package/out/shared/compile.d.ts.map +1 -0
  343. package/out/shared/compile.js +67 -0
  344. package/out/shared/compile.js.map +1 -0
  345. package/out/shared/context.d.ts +29 -0
  346. package/out/shared/context.d.ts.map +1 -0
  347. package/out/shared/context.js +48 -0
  348. package/out/shared/context.js.map +1 -0
  349. package/out/shared/declare.d.ts +53 -0
  350. package/out/shared/declare.d.ts.map +1 -0
  351. package/out/shared/declare.js +2 -0
  352. package/out/shared/declare.js.map +1 -0
  353. package/out/shared/disjoint.d.ts +79 -0
  354. package/out/shared/disjoint.d.ts.map +1 -0
  355. package/out/shared/disjoint.js +82 -0
  356. package/out/shared/disjoint.js.map +1 -0
  357. package/out/shared/errors.d.ts +59 -0
  358. package/out/shared/errors.d.ts.map +1 -0
  359. package/out/shared/errors.js +108 -0
  360. package/out/shared/errors.js.map +1 -0
  361. package/out/shared/implement.d.ts +170 -0
  362. package/out/shared/implement.d.ts.map +1 -0
  363. package/out/shared/implement.js +69 -0
  364. package/out/shared/implement.js.map +1 -0
  365. package/out/shared/inference.d.ts +6 -0
  366. package/out/shared/inference.d.ts.map +1 -0
  367. package/out/shared/inference.js +5 -0
  368. package/out/shared/inference.js.map +1 -0
  369. package/out/shared/intersections.d.ts +15 -0
  370. package/out/shared/intersections.d.ts.map +1 -0
  371. package/out/shared/intersections.js.map +1 -0
  372. package/out/shared/traversal.d.ts +44 -0
  373. package/out/shared/traversal.d.ts.map +1 -0
  374. package/out/shared/traversal.js +97 -0
  375. package/out/shared/traversal.js.map +1 -0
  376. package/out/shared/utils.d.ts +8 -0
  377. package/out/shared/utils.d.ts.map +1 -0
  378. package/out/shared/utils.js +10 -0
  379. package/out/shared/utils.js.map +1 -0
  380. package/out/type.d.ts +10 -38
  381. package/out/type.d.ts.map +1 -1
  382. package/out/type.js +20 -106
  383. package/out/type.js.map +1 -1
  384. package/out/types/basis.d.ts +24 -0
  385. package/out/types/basis.d.ts.map +1 -0
  386. package/out/types/basis.js +15 -0
  387. package/out/types/basis.js.map +1 -0
  388. package/out/types/discriminate.d.ts +20 -0
  389. package/out/types/discriminate.d.ts.map +1 -0
  390. package/out/types/discriminate.js +114 -0
  391. package/out/types/discriminate.js.map +1 -0
  392. package/out/types/domain.d.ts +40 -0
  393. package/out/types/domain.d.ts.map +1 -0
  394. package/out/types/domain.js +38 -0
  395. package/out/types/domain.js.map +1 -0
  396. package/out/types/intersection.d.ts +67 -0
  397. package/out/types/intersection.d.ts.map +1 -0
  398. package/out/types/intersection.js +350 -0
  399. package/out/types/intersection.js.map +1 -0
  400. package/out/types/morph.d.ts +79 -0
  401. package/out/types/morph.d.ts.map +1 -0
  402. package/out/types/morph.js +95 -0
  403. package/out/types/morph.js.map +1 -0
  404. package/out/types/proto.d.ts +42 -0
  405. package/out/types/proto.d.ts.map +1 -0
  406. package/out/types/proto.js +48 -0
  407. package/out/types/proto.js.map +1 -0
  408. package/out/types/type.d.ts +61 -0
  409. package/out/types/type.d.ts.map +1 -0
  410. package/out/types/type.js +111 -0
  411. package/out/types/type.js.map +1 -0
  412. package/out/types/union.d.ts +48 -0
  413. package/out/types/union.d.ts.map +1 -0
  414. package/out/types/union.js +337 -0
  415. package/out/types/union.js.map +1 -0
  416. package/out/types/unit.d.ts +40 -0
  417. package/out/types/unit.d.ts.map +1 -0
  418. package/out/types/unit.js +48 -0
  419. package/out/types/unit.js.map +1 -0
  420. package/out/util.d.ts +5 -2
  421. package/out/util.d.ts.map +1 -1
  422. package/out/util.js.map +1 -1
  423. package/package.json +6 -3
  424. package/parse.ts +221 -0
  425. package/parser/definition.ts +24 -23
  426. package/parser/objectLiteral.ts +128 -88
  427. package/parser/semantic/bounds.ts +18 -9
  428. package/parser/semantic/divisor.ts +12 -10
  429. package/parser/semantic/infer.ts +152 -0
  430. package/parser/semantic/utils.ts +5 -13
  431. package/parser/semantic/validate.ts +1 -2
  432. package/parser/string/reduce/dynamic.ts +42 -30
  433. package/parser/string/reduce/shared.ts +1 -3
  434. package/parser/string/reduce/static.ts +22 -22
  435. package/parser/string/shift/operand/date.ts +9 -5
  436. package/parser/string/shift/operand/enclosed.ts +11 -5
  437. package/parser/string/shift/operand/genericArgs.ts +6 -6
  438. package/parser/string/shift/operand/operand.ts +1 -2
  439. package/parser/string/shift/operand/unenclosed.ts +14 -20
  440. package/parser/string/shift/operator/bounds.ts +59 -54
  441. package/parser/string/shift/operator/divisor.ts +2 -2
  442. package/parser/string/shift/scanner.ts +10 -10
  443. package/parser/string/string.ts +4 -4
  444. package/parser/tuple.ts +224 -202
  445. package/schema.ts +263 -0
  446. package/scope.ts +358 -81
  447. package/shared/compile.ts +92 -0
  448. package/shared/declare.ts +75 -0
  449. package/shared/disjoint.ts +203 -0
  450. package/shared/errors.ts +204 -0
  451. package/shared/implement.ts +327 -0
  452. package/shared/inference.ts +9 -0
  453. package/shared/intersections.ts +53 -0
  454. package/shared/traversal.ts +146 -0
  455. package/shared/utils.ts +30 -0
  456. package/type.ts +23 -183
  457. package/types/basis.ts +62 -0
  458. package/types/discriminate.ts +168 -0
  459. package/types/domain.ts +79 -0
  460. package/types/intersection.ts +539 -0
  461. package/types/morph.ts +263 -0
  462. package/types/proto.ts +89 -0
  463. package/types/type.ts +319 -0
  464. package/types/union.ts +451 -0
  465. package/types/unit.ts +78 -0
  466. package/util.ts +5 -2
  467. package/__tests__/astUtils.test.ts +0 -17
  468. package/__tests__/jsdoc.test.ts +0 -64
  469. package/__tests__/nodeDefinitions.test.ts +0 -190
  470. package/out/arkConfig.d.ts +0 -2
  471. package/out/arkConfig.d.ts.map +0 -1
  472. package/out/arkConfig.js +0 -10
  473. package/out/arkConfig.js.map +0 -1
  474. package/out/parser/semantic/intersections.d.ts +0 -14
  475. package/out/parser/semantic/intersections.d.ts.map +0 -1
  476. package/out/parser/semantic/intersections.js.map +0 -1
  477. package/out/parser/semantic/semantic.d.ts +0 -32
  478. package/out/parser/semantic/semantic.d.ts.map +0 -1
  479. package/out/parser/semantic/semantic.js +0 -2
  480. package/out/parser/semantic/semantic.js.map +0 -1
  481. package/out/parser/shared.d.ts +0 -62
  482. package/out/parser/shared.d.ts.map +0 -1
  483. package/out/parser/shared.js +0 -56
  484. package/out/parser/shared.js.map +0 -1
  485. package/out/test.d.ts +0 -2
  486. package/out/test.d.ts.map +0 -1
  487. package/out/test.js +0 -7
  488. package/out/test.js.map +0 -1
  489. package/out/tsconfig.build.tsbuildinfo +0 -1
  490. package/parser/semantic/semantic.ts +0 -143
  491. package/parser/shared.ts +0 -170
  492. /package/out/{parser/semantic → shared}/intersections.js +0 -0
@@ -0,0 +1,114 @@
1
+ import { compileSerializedValue, entriesOf, isKeyOf, throwInternalError } from "@arktype/util";
2
+ import { Disjoint } from "../shared/disjoint.js";
3
+ const discriminantKinds = {
4
+ domain: 1,
5
+ value: 1
6
+ };
7
+ const parseDiscriminantKey = (key) => {
8
+ const lastPathIndex = key.lastIndexOf("]");
9
+ return [
10
+ JSON.parse(key.slice(0, lastPathIndex + 1)),
11
+ key.slice(lastPathIndex + 1)
12
+ ];
13
+ };
14
+ const discriminantCache = new Map();
15
+ export const discriminate = (branches) => {
16
+ if (branches.length < 2) {
17
+ return null;
18
+ }
19
+ const cached = discriminantCache.get(branches);
20
+ if (cached !== undefined) {
21
+ return cached;
22
+ }
23
+ // const pureValueBranches = branches.flatMap((branch) =>
24
+ // branch.unit ? branch.unit : []
25
+ // )
26
+ // if (pureValueBranches.length === branches.length) {
27
+ // const cases: DiscriminatedCases = transform(
28
+ // pureValueBranches,
29
+ // ([i, valueNode]) => [valueNode.serialized, [branches[i]]]
30
+ // )
31
+ // return {
32
+ // path: [],
33
+ // kind: "value",
34
+ // cases,
35
+ // isPureRootLiteral: true
36
+ // }
37
+ // }
38
+ const casesBySpecifier = {};
39
+ for (let lIndex = 0; lIndex < branches.length - 1; lIndex++) {
40
+ const l = branches[lIndex];
41
+ for (let rIndex = lIndex + 1; rIndex < branches.length; rIndex++) {
42
+ const r = branches[rIndex];
43
+ const result = l.intersect(r);
44
+ if (!(result instanceof Disjoint)) {
45
+ continue;
46
+ }
47
+ for (const { path, kind, disjoint } of result.flat) {
48
+ if (!isKeyOf(kind, discriminantKinds)) {
49
+ continue;
50
+ }
51
+ const qualifiedDiscriminant = `${path}${kind}`;
52
+ let lSerialized;
53
+ let rSerialized;
54
+ if (kind === "domain") {
55
+ lSerialized = disjoint.l;
56
+ rSerialized = disjoint.r;
57
+ }
58
+ else if (kind === "value") {
59
+ lSerialized = compileSerializedValue(disjoint.l);
60
+ rSerialized = compileSerializedValue(disjoint.r);
61
+ }
62
+ else {
63
+ return throwInternalError(`Unexpected attempt to discriminate disjoint kind '${kind}'`);
64
+ }
65
+ if (!casesBySpecifier[qualifiedDiscriminant]) {
66
+ casesBySpecifier[qualifiedDiscriminant] = {
67
+ [lSerialized]: [l],
68
+ [rSerialized]: [r]
69
+ };
70
+ continue;
71
+ }
72
+ const cases = casesBySpecifier[qualifiedDiscriminant];
73
+ if (!isKeyOf(lSerialized, cases)) {
74
+ cases[lSerialized] = [l];
75
+ }
76
+ else if (!cases[lSerialized].includes(l)) {
77
+ cases[lSerialized].push(l);
78
+ }
79
+ if (!isKeyOf(rSerialized, cases)) {
80
+ cases[rSerialized] = [r];
81
+ }
82
+ else if (!cases[rSerialized].includes(r)) {
83
+ cases[rSerialized].push(r);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ // TODO: determinstic? Update cache key?
89
+ const bestDiscriminantEntry = entriesOf(casesBySpecifier)
90
+ .sort((a, b) => Object.keys(a[1]).length - Object.keys(b[1]).length)
91
+ .at(-1);
92
+ if (!bestDiscriminantEntry) {
93
+ discriminantCache.set(branches, null);
94
+ return null;
95
+ }
96
+ const [specifier, predicateCases] = bestDiscriminantEntry;
97
+ const [path, kind] = parseDiscriminantKey(specifier);
98
+ const cases = {};
99
+ for (const k in predicateCases) {
100
+ const subdiscriminant = discriminate(predicateCases[k]);
101
+ cases[k] = subdiscriminant ?? predicateCases[k];
102
+ }
103
+ const discriminant = {
104
+ kind,
105
+ path,
106
+ cases,
107
+ isPureRootLiteral: false
108
+ };
109
+ discriminantCache.set(branches, discriminant);
110
+ return discriminant;
111
+ };
112
+ // TODO: if deeply includes morphs?
113
+ export const writeUndiscriminableMorphUnionMessage = (path) => `${path === "/" ? "A" : `At ${path}, a`} union including one or more morphs must be discriminable`;
114
+ //# sourceMappingURL=discriminate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminate.js","sourceRoot":"","sources":["../../types/discriminate.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,sBAAsB,EACtB,SAAS,EACT,OAAO,EACP,kBAAkB,EAMlB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,QAAQ,EAAuB,MAAM,uBAAuB,CAAA;AAgCrE,MAAM,iBAAiB,GAA6B;IACnD,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACR,CAAA;AAID,MAAM,oBAAoB,GAAG,CAAC,GAAoB,EAAE,EAAE;IACrD,MAAM,aAAa,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC1C,OAAO;QACN,IAAI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ACvD,KAAK,CAAC,CAAC,CAAC,GAAG,eAAe,IAAI,cAAc,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC;IACD,MAAM,YAAY,GAAiB;QAClC,IAAI;QACJ,IAAI;QACJ,KAAK;QACL,iBAAiB,EAAE,KAAK;KACxB,CAAA;IACD,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IAC7C,OAAO,YAAY,CAAA;AACpB,CAAC,CAAA;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,qCAAqC,GAAG,CACpD,IAAU,EACT,EAAE,CACH,GACC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,KAChC,2DAAoE,CAAA"}
@@ -0,0 +1,40 @@
1
+ import { type NonEnumerableDomain } from "@arktype/util";
2
+ import type { BaseMeta, declareNode } from "../shared/declare.js";
3
+ import type { TraverseAllows } from "../shared/traversal.js";
4
+ import { BaseBasis } from "./basis.js";
5
+ export interface DomainInner<domain extends NonEnumerableDomain = NonEnumerableDomain> extends BaseMeta {
6
+ readonly domain: domain;
7
+ }
8
+ export type DomainSchema<domain extends NonEnumerableDomain = NonEnumerableDomain> = domain | NormalizedDomainSchema<domain>;
9
+ export type NormalizedDomainSchema<domain extends NonEnumerableDomain = NonEnumerableDomain> = DomainInner<domain>;
10
+ export type DomainDeclaration = declareNode<{
11
+ kind: "domain";
12
+ schema: DomainSchema;
13
+ normalizedSchema: NormalizedDomainSchema;
14
+ inner: DomainInner;
15
+ errorContext: DomainInner;
16
+ }>;
17
+ export declare class DomainNode<t = any, $ = any> extends BaseBasis<t, DomainDeclaration, $> {
18
+ static implementation: import("../shared/implement.js").nodeImplementationOf<{
19
+ reducibleTo: "domain";
20
+ intersectionIsOpen: false;
21
+ prerequisite: unknown;
22
+ childKind: never;
23
+ kind: "domain";
24
+ schema: DomainSchema<"string" | "number" | "bigint" | "symbol" | "object">;
25
+ normalizedSchema: NormalizedDomainSchema<"string" | "number" | "bigint" | "symbol" | "object">;
26
+ inner: DomainInner<"string" | "number" | "bigint" | "symbol" | "object">;
27
+ errorContext: DomainInner<"string" | "number" | "bigint" | "symbol" | "object"> & import("../shared/declare.js").BaseErrorContext<"domain">;
28
+ }>;
29
+ traverseAllows: TraverseAllows;
30
+ readonly compiledCondition: string;
31
+ readonly compiledNegation: string;
32
+ readonly errorContext: {
33
+ code: "domain";
34
+ readonly domain: "string" | "number" | "bigint" | "symbol" | "object";
35
+ readonly description?: string;
36
+ };
37
+ readonly expression: "string" | "number" | "bigint" | "symbol" | "object";
38
+ readonly literalKeys: import("@arktype/util").Key[];
39
+ }
40
+ //# sourceMappingURL=domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../types/domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,mBAAmB,EACxB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,WAAW,WAAW,CAC3B,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CACvD,SAAQ,QAAQ;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,MAAM,YAAY,CAEvB,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,IACrD,MAAM,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAA;AAE3C,MAAM,MAAM,sBAAsB,CACjC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,IACrD,WAAW,CAAC,MAAM,CAAC,CAAA;AAEvB,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC;IAC3C,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,YAAY,CAAA;IACpB,gBAAgB,EAAE,sBAAsB,CAAA;IACxC,KAAK,EAAE,WAAW,CAAA;IAClB,YAAY,EAAE,WAAW,CAAA;CACzB,CAAC,CAAA;AAEF,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,CAAE,SAAQ,SAAS,CAC1D,CAAC,EACD,iBAAiB,EACjB,CAAC,CACD;IACA,MAAM,CAAC,cAAc;;;;;;;;;;OAsBnB;IAEF,cAAc,EAAE,cAAc,CAA2C;IAEzE,QAAQ,CAAC,iBAAiB,SAGY;IAEtC,QAAQ,CAAC,gBAAgB,SAGa;IAEtC,QAAQ,CAAC,YAAY;;;;MAAsC;IAC3D,QAAQ,CAAC,UAAU,uDAAc;IACjC,QAAQ,CAAC,WAAW,gCAAiC;CACrD"}
@@ -0,0 +1,38 @@
1
+ import { domainDescriptions, domainOf, getBaseDomainKeys } from "@arktype/util";
2
+ import { Disjoint } from "../shared/disjoint.js";
3
+ import { BaseBasis } from "./basis.js";
4
+ export class DomainNode extends BaseBasis {
5
+ static implementation = this.implement({
6
+ hasAssociatedError: true,
7
+ collapsibleKey: "domain",
8
+ keys: {
9
+ domain: {}
10
+ },
11
+ normalize: (input) => typeof input === "string" ? { domain: input } : input,
12
+ defaults: {
13
+ description(node) {
14
+ return domainDescriptions[node.domain];
15
+ },
16
+ actual(data) {
17
+ // don't treat boolean as a domain since it is union of units
18
+ // and are error messages are more consistent if they're described
19
+ // that way universally
20
+ return typeof data === "boolean" ? `${data}` : domainOf(data);
21
+ }
22
+ },
23
+ intersections: {
24
+ domain: (l, r) => Disjoint.from("domain", l, r)
25
+ }
26
+ });
27
+ traverseAllows = (data) => domainOf(data) === this.domain;
28
+ compiledCondition = this.domain === "object"
29
+ ? `((typeof data === "object" && data !== null) || typeof data === "function")`
30
+ : `typeof data === "${this.domain}"`;
31
+ compiledNegation = this.domain === "object"
32
+ ? `((typeof data !== "object" || data === null) && typeof data !== "function")`
33
+ : `typeof data !== "${this.domain}"`;
34
+ errorContext = this.createErrorContext(this.inner);
35
+ expression = this.domain;
36
+ literalKeys = getBaseDomainKeys(this.domain);
37
+ }
38
+ //# sourceMappingURL=domain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.js","sourceRoot":"","sources":["../../types/domain.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,QAAQ,EACR,iBAAiB,EAEjB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAyBtC,MAAM,OAAO,UAA6B,SAAQ,SAIjD;IACA,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;QACtC,kBAAkB,EAAE,IAAI;QACxB,cAAc,EAAE,QAAQ;QACxB,IAAI,EAAE;YACL,MAAM,EAAE,EAAE;SACV;QACD,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACpB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK;QACtD,QAAQ,EAAE;YACT,WAAW,CAAC,IAAI;gBACf,OAAO,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACvC,CAAC;YACD,MAAM,CAAC,IAAI;gBACV,6DAA6D;gBAC7D,kEAAkE;gBAClE,uBAAuB;gBACvB,OAAO,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;YAC9D,CAAC;SACD;QACD,aAAa,EAAE;YACd,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;SAC/C;KACD,CAAC,CAAA;IAEF,cAAc,GAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAA;IAEhE,iBAAiB,GACzB,IAAI,CAAC,MAAM,KAAK,QAAQ;QACvB,CAAC,CAAC,6EAA6E;QAC/E,CAAC,CAAC,oBAAoB,IAAI,CAAC,MAAM,GAAG,CAAA;IAE7B,gBAAgB,GACxB,IAAI,CAAC,MAAM,KAAK,QAAQ;QACvB,CAAC,CAAC,6EAA6E;QAC/E,CAAC,CAAC,oBAAoB,IAAI,CAAC,MAAM,GAAG,CAAA;IAE7B,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClD,UAAU,GAAG,IAAI,CAAC,MAAM,CAAA;IACxB,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA"}
@@ -0,0 +1,67 @@
1
+ import { type evaluate, type listable } from "@arktype/util";
2
+ import { type Node } from "../base.js";
3
+ import { PropsGroup, type ExtraneousKeyBehavior, type ExtraneousKeyRestriction } from "../constraints/props/props.js";
4
+ import type { Inner, Prerequisite, Schema } from "../kinds.js";
5
+ import type { NodeCompiler } from "../shared/compile.js";
6
+ import { type BaseMeta, type declareNode } from "../shared/declare.js";
7
+ import type { ArkTypeError } from "../shared/errors.js";
8
+ import { type ConstraintKind, type IntersectionChildKind, type OpenNodeKind, type nodeImplementationOf } from "../shared/implement.js";
9
+ import type { TraverseAllows, TraverseApply } from "../shared/traversal.js";
10
+ import type { DomainNode, DomainSchema } from "./domain.js";
11
+ import type { ProtoNode, ProtoSchema } from "./proto.js";
12
+ import { BaseType, type Type } from "./type.js";
13
+ export type IntersectionBasisKind = "domain" | "proto";
14
+ export type IntersectionInner = evaluate<BaseMeta & {
15
+ domain?: DomainNode;
16
+ proto?: ProtoNode;
17
+ } & {
18
+ [k in ConditionalIntersectionKey]?: conditionalInnerValueOfKey<k>;
19
+ }>;
20
+ export type IntersectionSchema<inferredBasis = any> = evaluate<BaseMeta & {
21
+ domain?: DomainSchema;
22
+ proto?: ProtoSchema;
23
+ } & conditionalSchemaOf<inferredBasis>>;
24
+ export type IntersectionDeclaration = declareNode<{
25
+ kind: "intersection";
26
+ schema: IntersectionSchema;
27
+ normalizedSchema: IntersectionSchema;
28
+ inner: IntersectionInner;
29
+ reducibleTo: "intersection" | IntersectionBasisKind;
30
+ errorContext: {
31
+ errors: readonly ArkTypeError[];
32
+ };
33
+ childKind: IntersectionChildKind;
34
+ }>;
35
+ export declare class IntersectionNode<t = unknown, $ = any> extends BaseType<t, IntersectionDeclaration, $> {
36
+ static implementation: nodeImplementationOf<IntersectionDeclaration>;
37
+ readonly basis: ProtoNode<any, any> | DomainNode<any, any> | undefined;
38
+ readonly refinements: Node<"regex" | "divisor" | "exactLength" | "max" | "min" | "maxLength" | "minLength" | "before" | "after">[];
39
+ readonly props: PropsGroup | undefined;
40
+ readonly traversables: readonly (PropsGroup | Node<"proto" | "domain" | "regex" | "divisor" | "exactLength" | "max" | "min" | "maxLength" | "minLength" | "before" | "after" | "predicate">)[];
41
+ readonly expression: string;
42
+ traverseAllows: TraverseAllows;
43
+ traverseApply: TraverseApply;
44
+ compile(js: NodeCompiler): void;
45
+ rawKeyOf(): Type;
46
+ }
47
+ export type ConditionalTerminalIntersectionSchema = {
48
+ onExtraneousKey?: ExtraneousKeyBehavior;
49
+ };
50
+ export type ConditionalTerminalIntersectionInner = {
51
+ onExtraneousKey?: ExtraneousKeyRestriction;
52
+ };
53
+ type ConditionalTerminalIntersectionKey = keyof ConditionalTerminalIntersectionInner;
54
+ type ConditionalIntersectionKey = ConstraintKind | keyof ConditionalTerminalIntersectionInner;
55
+ export type constraintKindOf<t> = {
56
+ [k in ConstraintKind]: t extends Prerequisite<k> ? k : never;
57
+ }[ConstraintKind];
58
+ type conditionalIntersectionKeyOf<t> = constraintKindOf<t> | (t extends object ? "onExtraneousKey" : never);
59
+ type intersectionChildSchemaValueOf<k extends IntersectionChildKind> = k extends OpenNodeKind ? listable<Schema<k> | Inner<k>> : Schema<k> | Inner<k>;
60
+ type conditionalSchemaValueOfKey<k extends ConditionalIntersectionKey> = k extends IntersectionChildKind ? intersectionChildSchemaValueOf<k> : ConditionalTerminalIntersectionSchema[k & ConditionalTerminalIntersectionKey];
61
+ type intersectionChildInnerValueOf<k extends IntersectionChildKind> = k extends OpenNodeKind ? readonly Node<k>[] : Node<k>;
62
+ type conditionalInnerValueOfKey<k extends ConditionalIntersectionKey> = k extends IntersectionChildKind ? intersectionChildInnerValueOf<k> : ConditionalTerminalIntersectionInner[k & ConditionalTerminalIntersectionKey];
63
+ export type conditionalSchemaOf<t> = {
64
+ [k in conditionalIntersectionKeyOf<t>]?: conditionalSchemaValueOfKey<k>;
65
+ };
66
+ export {};
67
+ //# sourceMappingURL=intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intersection.d.ts","sourceRoot":"","sources":["../../types/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAYN,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EAAiC,KAAK,IAAI,EAAE,MAAM,YAAY,CAAA;AACrE,OAAO,EACN,UAAU,EACV,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAgB,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAG5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAY,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEhF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAGjB,KAAK,oBAAoB,EACzB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EA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AAC,CAAC,GACjC,qCAAqC,CAAC,CAAC,GACvC,kCAAkC,CAAC,CAAA;AAEvC,KAAK,6BAA6B,CAAC,CAAC,SAAS,qBAAqB,IACjE,CAAC,SAAS,YAAY,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AAEtD,KAAK,0BAA0B,CAAC,CAAC,SAAS,0BAA0B,IACnE,CAAC,SAAS,qBAAqB,GAC5B,6BAA6B,CAAC,CAAC,CAAC,GAChC,oCAAoC,CAAC,CAAC,GACtC,kCAAkC,CAAC,CAAA;AAEvC,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;KACnC,CAAC,IAAI,4BAA4B,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,2BAA2B,CAAC,CAAC,CAAC;CACvE,CAAA"}
@@ -0,0 +1,350 @@
1
+ import { append, appendUnique, conflatenateAll, entriesOf, isArray, isEmptyObject, omit, pick, splitByKeys, throwInternalError } from "@arktype/util";
2
+ import { BaseNode } from "../base.js";
3
+ import { PropsGroup } from "../constraints/props/props.js";
4
+ import { metaKeys } from "../shared/declare.js";
5
+ import { Disjoint } from "../shared/disjoint.js";
6
+ import { constraintKeys, propKeys } from "../shared/implement.js";
7
+ import { BaseType, defineRightwardIntersections } from "./type.js";
8
+ const intersectionChildKeyParser = (kind) => (input, ctx) => {
9
+ if (isArray(input)) {
10
+ if (input.length === 0) {
11
+ // Omit empty lists as input
12
+ return;
13
+ }
14
+ return input
15
+ .map((schema) => ctx.$.node(kind, schema))
16
+ .sort((l, r) => (l.innerId < r.innerId ? -1 : 1));
17
+ }
18
+ const node = ctx.$.node(kind, input);
19
+ return node.intersectionIsOpen ? [node] : node;
20
+ };
21
+ // readonly literalKeys = this.named.map((prop) => prop.key.name)
22
+ // readonly namedKeyOf = cached(() => node.unit(...this.literalKeys))
23
+ // readonly indexedKeyOf = cached(
24
+ // () =>
25
+ // new Type(
26
+ // this.indexed.flatMap((entry) => entry.key.branches),
27
+ // this.meta
28
+ // )
29
+ // )
30
+ // readonly keyof = cached(() => this.namedKeyOf().or(this.indexedKeyOf()))
31
+ // get(key: string | Type) {
32
+ // return typeof key === "string"
33
+ // ? this.named.find((entry) => entry.value.branches)?.value
34
+ // : this.indexed.find((entry) => entry.key.equals(key))?.value
35
+ // }
36
+ const intersectIntersections = (reduced, raw, $) => {
37
+ // avoid treating adding instance keys as keys of lRoot, rRoot
38
+ if (reduced instanceof IntersectionNode)
39
+ reduced = reduced.inner;
40
+ if (raw instanceof IntersectionNode)
41
+ raw = raw.inner;
42
+ const [reducedConstraintsInner, reducedRoot] = splitByKeys(reduced, constraintKeys);
43
+ const [rawConstraintsInner, rawRoot] = splitByKeys(raw, constraintKeys);
44
+ // since intersection with a left operand of unknown is leveraged for
45
+ // reduction, check for the case where r is empty so we can preserve
46
+ // metadata and save some time
47
+ const root = isEmptyObject(reduced)
48
+ ? rawRoot
49
+ : intersectRootKeys(reducedRoot, rawRoot);
50
+ if (root instanceof Disjoint)
51
+ return root;
52
+ const lConstraints = flattenConstraints(reducedConstraintsInner);
53
+ const rConstraints = flattenConstraints(rawConstraintsInner);
54
+ return intersectConstraints({
55
+ root,
56
+ l: lConstraints,
57
+ r: rConstraints,
58
+ types: [],
59
+ $
60
+ });
61
+ };
62
+ export class IntersectionNode extends BaseType {
63
+ static implementation = this.implement({
64
+ hasAssociatedError: true,
65
+ normalize: (schema) => schema,
66
+ keys: {
67
+ domain: {
68
+ child: true,
69
+ parse: intersectionChildKeyParser("domain")
70
+ },
71
+ proto: {
72
+ child: true,
73
+ parse: intersectionChildKeyParser("proto")
74
+ },
75
+ divisor: {
76
+ child: true,
77
+ parse: intersectionChildKeyParser("divisor")
78
+ },
79
+ max: {
80
+ child: true,
81
+ parse: intersectionChildKeyParser("max")
82
+ },
83
+ min: {
84
+ child: true,
85
+ parse: intersectionChildKeyParser("min")
86
+ },
87
+ maxLength: {
88
+ child: true,
89
+ parse: intersectionChildKeyParser("maxLength")
90
+ },
91
+ minLength: {
92
+ child: true,
93
+ parse: intersectionChildKeyParser("minLength")
94
+ },
95
+ exactLength: {
96
+ child: true,
97
+ parse: intersectionChildKeyParser("exactLength")
98
+ },
99
+ before: {
100
+ child: true,
101
+ parse: intersectionChildKeyParser("before")
102
+ },
103
+ after: {
104
+ child: true,
105
+ parse: intersectionChildKeyParser("after")
106
+ },
107
+ regex: {
108
+ child: true,
109
+ parse: intersectionChildKeyParser("regex")
110
+ },
111
+ predicate: {
112
+ child: true,
113
+ parse: intersectionChildKeyParser("predicate")
114
+ },
115
+ prop: {
116
+ child: true,
117
+ parse: intersectionChildKeyParser("prop")
118
+ },
119
+ index: {
120
+ child: true,
121
+ parse: intersectionChildKeyParser("index")
122
+ },
123
+ sequence: {
124
+ child: true,
125
+ parse: intersectionChildKeyParser("sequence")
126
+ },
127
+ onExtraneousKey: {
128
+ parse: (def) => (def === "ignore" ? undefined : def)
129
+ }
130
+ },
131
+ // leverage reduction logic from intersection and identity to ensure initial
132
+ // parse result is reduced
133
+ reduce: (inner, $) =>
134
+ // we cast union out of the result here since that only occurs when intersecting two sequences
135
+ // that cannot occur when reducing a single intersection schema using unknown
136
+ intersectIntersections({}, inner, $),
137
+ defaults: {
138
+ description(node) {
139
+ return node.children.length === 0
140
+ ? "unknown"
141
+ : node.props?.description ??
142
+ node.children.map((child) => child.description).join(" and ");
143
+ },
144
+ expected(source) {
145
+ return " • " + source.errors.map((e) => e.expected).join("\n • ");
146
+ },
147
+ problem(ctx) {
148
+ return `must be...\n${ctx.expected}`;
149
+ }
150
+ },
151
+ intersections: {
152
+ intersection: intersectIntersections,
153
+ ...defineRightwardIntersections("intersection", (l, r, $) => {
154
+ // if l is unknown, return r
155
+ if (l.children.length === 0)
156
+ return r;
157
+ const basis = l.basis?.intersect(r) ?? r;
158
+ return basis instanceof Disjoint
159
+ ? basis
160
+ : l?.basis?.equals(basis)
161
+ ? // if the basis doesn't change, return the original intesection
162
+ l
163
+ : // given we've already precluded l being unknown, the result must
164
+ // be an intersection with the new basis result integrated
165
+ $.node("intersection", Object.assign(omit(l.inner, metaKeys), { [basis.kind]: basis }), { prereduced: true });
166
+ })
167
+ }
168
+ });
169
+ basis = this.domain ?? this.proto;
170
+ refinements = this.children.filter((node) => node.isRefinement());
171
+ props = maybeCreatePropsGroup(this.inner, this.$);
172
+ traversables = conflatenateAll(this.basis, this.refinements, this.props, this.predicate);
173
+ expression = this.props?.expression ||
174
+ this.children.map((node) => node.nestableExpression).join(" & ") ||
175
+ "unknown";
176
+ traverseAllows = (data, ctx) => this.traversables.every((traversable) => traversable.traverseAllows(data, ctx));
177
+ traverseApply = (data, ctx) => {
178
+ if (this.basis) {
179
+ this.basis.traverseApply(data, ctx);
180
+ if (ctx.hasError())
181
+ return;
182
+ }
183
+ if (this.refinements.length) {
184
+ for (let i = 0; i < this.refinements.length - 1; i++) {
185
+ this.refinements[i].traverseApply(data, ctx);
186
+ if (ctx.failFast && ctx.hasError())
187
+ return;
188
+ }
189
+ this.refinements.at(-1).traverseApply(data, ctx);
190
+ if (ctx.hasError())
191
+ return;
192
+ }
193
+ if (this.props) {
194
+ this.props.traverseApply(data, ctx);
195
+ if (ctx.hasError())
196
+ return;
197
+ }
198
+ if (this.predicate) {
199
+ for (let i = 0; i < this.predicate.length - 1; i++) {
200
+ this.predicate[i].traverseApply(data, ctx);
201
+ if (ctx.failFast && ctx.hasError())
202
+ return;
203
+ }
204
+ this.predicate.at(-1).traverseApply(data, ctx);
205
+ }
206
+ };
207
+ compile(js) {
208
+ if (js.traversalKind === "Allows") {
209
+ this.traversables.forEach((traversable) => traversable instanceof BaseNode
210
+ ? js.check(traversable)
211
+ : traversable.compile(js));
212
+ js.return(true);
213
+ return;
214
+ }
215
+ const returnIfFail = () => js.if("ctx.hasError()", () => js.return());
216
+ const returnIfFailFast = () => js.if("ctx.failFast && ctx.hasError()", () => js.return());
217
+ if (this.basis) {
218
+ js.check(this.basis);
219
+ // we only have to return conditionally if this is not the last check
220
+ if (this.traversables.length > 1)
221
+ returnIfFail();
222
+ }
223
+ if (this.refinements.length) {
224
+ for (let i = 0; i < this.refinements.length - 1; i++) {
225
+ js.check(this.refinements[i]);
226
+ returnIfFailFast();
227
+ }
228
+ js.check(this.refinements.at(-1));
229
+ if (this.props || this.predicate)
230
+ returnIfFail();
231
+ }
232
+ if (this.props) {
233
+ this.props.compile(js);
234
+ if (this.predicate)
235
+ returnIfFail();
236
+ }
237
+ if (this.predicate) {
238
+ for (let i = 0; i < this.predicate.length - 1; i++) {
239
+ js.check(this.predicate[i]);
240
+ // since predicates can be chained, we have to fail immediately
241
+ // if one fails
242
+ returnIfFail();
243
+ }
244
+ js.check(this.predicate.at(-1));
245
+ }
246
+ }
247
+ rawKeyOf() {
248
+ return this.basis
249
+ ? this.props
250
+ ? this.basis.rawKeyOf().or(this.props.rawKeyOf())
251
+ : this.basis.rawKeyOf()
252
+ : this.props?.rawKeyOf() ?? this.$.keywords.never;
253
+ }
254
+ }
255
+ const maybeCreatePropsGroup = (inner, $) => {
256
+ const propsInput = pick(inner, propKeys);
257
+ return isEmptyObject(propsInput) ? undefined : new PropsGroup(propsInput, $);
258
+ };
259
+ const intersectRootKeys = (l, r) => {
260
+ const result = {};
261
+ const lBasis = l.proto ?? l.domain;
262
+ const rBasis = r.proto ?? r.domain;
263
+ const resultBasis = lBasis
264
+ ? rBasis
265
+ ? lBasis.intersect(rBasis)
266
+ : lBasis
267
+ : rBasis;
268
+ if (resultBasis) {
269
+ if (resultBasis instanceof Disjoint) {
270
+ return resultBasis;
271
+ }
272
+ if (resultBasis.kind === "domain" || resultBasis.kind === "proto") {
273
+ result[resultBasis.kind] = resultBasis;
274
+ }
275
+ else {
276
+ return throwInternalError(`Unexpected intersection basis intersection ${resultBasis}`);
277
+ }
278
+ }
279
+ if (l.onExtraneousKey || r.onExtraneousKey) {
280
+ result.onExtraneousKey =
281
+ l.onExtraneousKey === "throw" || r.onExtraneousKey === "throw"
282
+ ? "throw"
283
+ : "prune";
284
+ }
285
+ return result;
286
+ };
287
+ const intersectConstraints = (s) => {
288
+ if (!s.r.length) {
289
+ let result = s.$.node("intersection", Object.assign(s.root, unflattenConstraints(s.l)), { prereduced: true });
290
+ for (const type of s.types) {
291
+ if (result instanceof Disjoint) {
292
+ return result;
293
+ }
294
+ result = type.intersect(result);
295
+ }
296
+ return result;
297
+ }
298
+ const head = s.r.shift();
299
+ let matched = false;
300
+ for (let i = 0; i < s.l.length; i++) {
301
+ const result = s.l[i].intersect(head);
302
+ if (result === null)
303
+ continue;
304
+ if (result instanceof Disjoint)
305
+ return result;
306
+ if (!matched) {
307
+ if (result.isType())
308
+ s.types.push(result);
309
+ else
310
+ s.l[i] = result;
311
+ matched = true;
312
+ }
313
+ else if (!s.l.includes(result)) {
314
+ return throwInternalError(`Unexpectedly encountered multiple distinct intersection results for refinement ${result}`);
315
+ }
316
+ }
317
+ if (!matched) {
318
+ s.l.push(head);
319
+ }
320
+ head.impliedSiblings?.forEach((node) => appendUnique(s.r, node));
321
+ return intersectConstraints(s);
322
+ };
323
+ const flattenConstraints = (inner) => {
324
+ const result = entriesOf(inner)
325
+ .flatMap(([k, v]) => k in constraintKeys ? v : [])
326
+ .sort((l, r) => l.precedence < r.precedence
327
+ ? -1
328
+ : l.precedence > r.precedence
329
+ ? 1
330
+ : l.innerId < r.innerId
331
+ ? -1
332
+ : 1);
333
+ return result;
334
+ };
335
+ const unflattenConstraints = (constraints) => {
336
+ const inner = {};
337
+ for (const constraint of constraints) {
338
+ if (constraint.intersectionIsOpen) {
339
+ inner[constraint.kind] = append(inner[constraint.kind], constraint);
340
+ }
341
+ else {
342
+ if (inner[constraint.kind]) {
343
+ return throwInternalError(`Unexpected intersection of closed refinements of kind ${constraint.kind}`);
344
+ }
345
+ inner[constraint.kind] = constraint;
346
+ }
347
+ }
348
+ return inner;
349
+ };
350
+ //# sourceMappingURL=intersection.js.map