arktype 1.0.28-alpha → 1.1.0-dev-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/dist/main.d.ts +11 -0
  2. package/dist/main.d.ts.map +1 -0
  3. package/dist/main.js +8 -0
  4. package/dist/main.js.map +1 -0
  5. package/dist/match.d.ts +46 -0
  6. package/dist/match.d.ts.map +1 -0
  7. package/dist/match.js +23 -0
  8. package/dist/match.js.map +1 -0
  9. package/dist/parser/definition.d.ts +32 -0
  10. package/dist/parser/definition.d.ts.map +1 -0
  11. package/dist/parser/definition.js +29 -0
  12. package/dist/parser/definition.js.map +1 -0
  13. package/dist/parser/generic.d.ts +44 -0
  14. package/dist/parser/generic.d.ts.map +1 -0
  15. package/dist/parser/generic.js +46 -0
  16. package/dist/parser/generic.js.map +1 -0
  17. package/dist/parser/objectLiteral.d.ts +24 -0
  18. package/dist/parser/objectLiteral.d.ts.map +1 -0
  19. package/dist/parser/objectLiteral.js +38 -0
  20. package/dist/parser/objectLiteral.js.map +1 -0
  21. package/dist/parser/semantic/bounds.d.ts +13 -0
  22. package/dist/parser/semantic/bounds.d.ts.map +1 -0
  23. package/dist/parser/semantic/bounds.js +2 -0
  24. package/dist/parser/semantic/bounds.js.map +1 -0
  25. package/dist/parser/semantic/divisor.d.ts +9 -0
  26. package/dist/parser/semantic/divisor.d.ts.map +1 -0
  27. package/dist/parser/semantic/divisor.js +2 -0
  28. package/dist/parser/semantic/divisor.js.map +1 -0
  29. package/dist/parser/semantic/intersections.d.ts +15 -0
  30. package/dist/parser/semantic/intersections.d.ts.map +1 -0
  31. package/dist/parser/semantic/intersections.js +2 -0
  32. package/dist/parser/semantic/intersections.js.map +1 -0
  33. package/dist/parser/semantic/semantic.d.ts +22 -0
  34. package/dist/parser/semantic/semantic.d.ts.map +1 -0
  35. package/dist/parser/semantic/semantic.js +2 -0
  36. package/dist/parser/semantic/semantic.js.map +1 -0
  37. package/dist/parser/semantic/utils.d.ts +8 -0
  38. package/dist/parser/semantic/utils.d.ts.map +1 -0
  39. package/dist/parser/semantic/utils.js +2 -0
  40. package/dist/parser/semantic/utils.js.map +1 -0
  41. package/dist/parser/semantic/validate.d.ts +24 -0
  42. package/dist/parser/semantic/validate.d.ts.map +1 -0
  43. package/dist/parser/semantic/validate.js +2 -0
  44. package/dist/parser/semantic/validate.js.map +1 -0
  45. package/dist/parser/shared.d.ts +48 -0
  46. package/dist/parser/shared.d.ts.map +1 -0
  47. package/dist/parser/shared.js +41 -0
  48. package/dist/parser/shared.js.map +1 -0
  49. package/dist/parser/string/reduce/dynamic.d.ts +40 -0
  50. package/dist/parser/string/reduce/dynamic.d.ts.map +1 -0
  51. package/dist/parser/string/reduce/dynamic.js +122 -0
  52. package/dist/parser/string/reduce/dynamic.js.map +1 -0
  53. package/dist/parser/string/reduce/shared.d.ts +29 -0
  54. package/dist/parser/string/reduce/shared.d.ts.map +1 -0
  55. package/dist/parser/string/reduce/shared.js +7 -0
  56. package/dist/parser/string/reduce/shared.js.map +1 -0
  57. package/dist/parser/string/reduce/static.d.ts +177 -0
  58. package/dist/parser/string/reduce/static.d.ts.map +1 -0
  59. package/dist/parser/string/reduce/static.js +2 -0
  60. package/dist/parser/string/reduce/static.js.map +1 -0
  61. package/dist/parser/string/shift/operand/date.d.ts +11 -0
  62. package/dist/parser/string/shift/operand/date.d.ts.map +1 -0
  63. package/dist/parser/string/shift/operand/date.js +26 -0
  64. package/dist/parser/string/shift/operand/date.js.map +1 -0
  65. package/dist/parser/string/shift/operand/enclosed.d.ts +49 -0
  66. package/dist/parser/string/shift/operand/enclosed.d.ts.map +1 -0
  67. package/dist/parser/string/shift/operand/enclosed.js +50 -0
  68. package/dist/parser/string/shift/operand/enclosed.js.map +1 -0
  69. package/dist/parser/string/shift/operand/operand.d.ts +9 -0
  70. package/dist/parser/string/shift/operand/operand.d.ts.map +1 -0
  71. package/dist/parser/string/shift/operand/operand.js +17 -0
  72. package/dist/parser/string/shift/operand/operand.js.map +1 -0
  73. package/dist/parser/string/shift/operand/unenclosed.d.ts +36 -0
  74. package/dist/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
  75. package/dist/parser/string/shift/operand/unenclosed.js +68 -0
  76. package/dist/parser/string/shift/operand/unenclosed.js.map +1 -0
  77. package/dist/parser/string/shift/operator/bounds.d.ts +55 -0
  78. package/dist/parser/string/shift/operator/bounds.d.ts.map +1 -0
  79. package/dist/parser/string/shift/operator/bounds.js +95 -0
  80. package/dist/parser/string/shift/operator/bounds.js.map +1 -0
  81. package/dist/parser/string/shift/operator/divisor.d.ts +9 -0
  82. package/dist/parser/string/shift/operator/divisor.d.ts.map +1 -0
  83. package/dist/parser/string/shift/operator/divisor.js +13 -0
  84. package/dist/parser/string/shift/operator/divisor.js.map +1 -0
  85. package/dist/parser/string/shift/operator/operator.d.ts +13 -0
  86. package/dist/parser/string/shift/operator/operator.d.ts.map +1 -0
  87. package/dist/parser/string/shift/operator/operator.js +29 -0
  88. package/dist/parser/string/shift/operator/operator.js.map +1 -0
  89. package/dist/parser/string/shift/scanner.d.ts +71 -0
  90. package/dist/parser/string/shift/scanner.d.ts.map +1 -0
  91. package/dist/parser/string/shift/scanner.js +99 -0
  92. package/dist/parser/string/shift/scanner.js.map +1 -0
  93. package/dist/parser/string/string.d.ts +26 -0
  94. package/dist/parser/string/string.d.ts.map +1 -0
  95. package/dist/parser/string/string.js +31 -0
  96. package/dist/parser/string/string.js.map +1 -0
  97. package/dist/parser/tuple.d.ts +73 -0
  98. package/dist/parser/tuple.d.ts.map +1 -0
  99. package/dist/parser/tuple.js +134 -0
  100. package/dist/parser/tuple.js.map +1 -0
  101. package/dist/scope.d.ts +159 -0
  102. package/dist/scope.d.ts.map +1 -0
  103. package/dist/scope.js +248 -0
  104. package/dist/scope.js.map +1 -0
  105. package/dist/scopes/ark.d.ts +38 -0
  106. package/dist/scopes/ark.d.ts.map +1 -0
  107. package/dist/scopes/ark.js +24 -0
  108. package/dist/scopes/ark.js.map +1 -0
  109. package/dist/scopes/jsObjects.d.ts +19 -0
  110. package/dist/scopes/jsObjects.d.ts.map +1 -0
  111. package/dist/scopes/jsObjects.js +15 -0
  112. package/dist/scopes/jsObjects.js.map +1 -0
  113. package/dist/scopes/parsing.d.ts +18 -0
  114. package/dist/scopes/parsing.d.ts.map +1 -0
  115. package/dist/scopes/parsing.js +61 -0
  116. package/dist/scopes/parsing.js.map +1 -0
  117. package/dist/scopes/tsGenerics.d.ts +17 -0
  118. package/dist/scopes/tsGenerics.d.ts.map +1 -0
  119. package/dist/scopes/tsGenerics.js +13 -0
  120. package/dist/scopes/tsGenerics.js.map +1 -0
  121. package/dist/scopes/tsKeywords.d.ts +24 -0
  122. package/dist/scopes/tsKeywords.d.ts.map +1 -0
  123. package/dist/scopes/tsKeywords.js +20 -0
  124. package/dist/scopes/tsKeywords.js.map +1 -0
  125. package/dist/scopes/utils/creditCard.d.ts +3 -0
  126. package/dist/scopes/utils/creditCard.d.ts.map +1 -0
  127. package/dist/{mjs/scopes/validation → scopes/utils}/creditCard.js +14 -12
  128. package/dist/scopes/utils/creditCard.js.map +1 -0
  129. package/dist/{types/scopes/validation → scopes/utils}/date.d.ts +3 -2
  130. package/dist/scopes/utils/date.d.ts.map +1 -0
  131. package/dist/{mjs/scopes/validation → scopes/utils}/date.js +24 -19
  132. package/dist/scopes/utils/date.js.map +1 -0
  133. package/dist/scopes/validation.d.ts +20 -0
  134. package/dist/scopes/validation.d.ts.map +1 -0
  135. package/dist/scopes/validation.js +57 -0
  136. package/dist/scopes/validation.js.map +1 -0
  137. package/dist/type.d.ts +101 -0
  138. package/dist/type.d.ts.map +1 -0
  139. package/dist/type.js +138 -0
  140. package/dist/type.js.map +1 -0
  141. package/main.ts +20 -0
  142. package/match.ts +137 -0
  143. package/package.json +41 -108
  144. package/parser/definition.ts +156 -0
  145. package/parser/generic.ts +208 -0
  146. package/parser/objectLiteral.ts +120 -0
  147. package/parser/semantic/bounds.ts +63 -0
  148. package/parser/semantic/divisor.ts +13 -0
  149. package/parser/semantic/intersections.ts +47 -0
  150. package/parser/semantic/semantic.ts +107 -0
  151. package/parser/semantic/utils.ts +26 -0
  152. package/parser/semantic/validate.ts +105 -0
  153. package/parser/shared.ts +141 -0
  154. package/parser/string/reduce/dynamic.ts +181 -0
  155. package/parser/string/reduce/shared.ts +73 -0
  156. package/parser/string/reduce/static.ts +300 -0
  157. package/parser/string/shift/operand/date.ts +57 -0
  158. package/parser/string/shift/operand/enclosed.ts +119 -0
  159. package/parser/string/shift/operand/operand.ts +48 -0
  160. package/parser/string/shift/operand/unenclosed.ts +282 -0
  161. package/parser/string/shift/operator/bounds.ts +229 -0
  162. package/parser/string/shift/operator/divisor.ts +36 -0
  163. package/parser/string/shift/operator/operator.ts +82 -0
  164. package/parser/string/shift/scanner.ts +209 -0
  165. package/parser/string/string.ts +93 -0
  166. package/parser/tuple.ts +475 -0
  167. package/scope.ts +573 -0
  168. package/scopes/ark.ts +64 -0
  169. package/scopes/jsObjects.ts +29 -0
  170. package/scopes/parsing.ts +81 -0
  171. package/scopes/tsGenerics.ts +28 -0
  172. package/scopes/tsKeywords.ts +39 -0
  173. package/scopes/utils/creditCard.ts +37 -0
  174. package/scopes/utils/date.ts +108 -0
  175. package/scopes/validation.ts +81 -0
  176. package/type.ts +403 -0
  177. package/LICENSE +0 -7
  178. package/README.md +0 -351
  179. package/dist/cjs/main.js +0 -38
  180. package/dist/cjs/nodes/branch.js +0 -140
  181. package/dist/cjs/nodes/compose.js +0 -163
  182. package/dist/cjs/nodes/discriminate.js +0 -265
  183. package/dist/cjs/nodes/node.js +0 -139
  184. package/dist/cjs/nodes/predicate.js +0 -86
  185. package/dist/cjs/nodes/rules/class.js +0 -25
  186. package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
  187. package/dist/cjs/nodes/rules/divisor.js +0 -29
  188. package/dist/cjs/nodes/rules/props.js +0 -167
  189. package/dist/cjs/nodes/rules/range.js +0 -105
  190. package/dist/cjs/nodes/rules/regex.js +0 -26
  191. package/dist/cjs/nodes/rules/rules.js +0 -123
  192. package/dist/cjs/package.json +0 -3
  193. package/dist/cjs/parse/ast/ast.js +0 -4
  194. package/dist/cjs/parse/ast/bound.js +0 -16
  195. package/dist/cjs/parse/ast/config.js +0 -13
  196. package/dist/cjs/parse/ast/distributableFunction.js +0 -48
  197. package/dist/cjs/parse/ast/divisor.js +0 -9
  198. package/dist/cjs/parse/ast/intersection.js +0 -30
  199. package/dist/cjs/parse/ast/keyof.js +0 -111
  200. package/dist/cjs/parse/ast/morph.js +0 -58
  201. package/dist/cjs/parse/ast/narrow.js +0 -22
  202. package/dist/cjs/parse/ast/node.js +0 -4
  203. package/dist/cjs/parse/ast/tuple.js +0 -94
  204. package/dist/cjs/parse/ast/union.js +0 -9
  205. package/dist/cjs/parse/ast/utils.js +0 -4
  206. package/dist/cjs/parse/definition.js +0 -61
  207. package/dist/cjs/parse/record.js +0 -37
  208. package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
  209. package/dist/cjs/parse/string/reduce/shared.js +0 -23
  210. package/dist/cjs/parse/string/reduce/static.js +0 -4
  211. package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
  212. package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
  213. package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
  214. package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
  215. package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
  216. package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
  217. package/dist/cjs/parse/string/shift/scanner.js +0 -114
  218. package/dist/cjs/parse/string/string.js +0 -43
  219. package/dist/cjs/scopes/ark.js +0 -45
  220. package/dist/cjs/scopes/cache.js +0 -52
  221. package/dist/cjs/scopes/expressions.js +0 -29
  222. package/dist/cjs/scopes/jsObjects.js +0 -93
  223. package/dist/cjs/scopes/scope.js +0 -323
  224. package/dist/cjs/scopes/tsKeywords.js +0 -113
  225. package/dist/cjs/scopes/type.js +0 -50
  226. package/dist/cjs/scopes/validation/creditCard.js +0 -47
  227. package/dist/cjs/scopes/validation/date.js +0 -62
  228. package/dist/cjs/scopes/validation/validation.js +0 -108
  229. package/dist/cjs/traverse/problems.js +0 -281
  230. package/dist/cjs/traverse/traverse.js +0 -390
  231. package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
  232. package/dist/cjs/utils/data.js +0 -53
  233. package/dist/cjs/utils/domains.js +0 -30
  234. package/dist/cjs/utils/errors.js +0 -26
  235. package/dist/cjs/utils/freeze.js +0 -15
  236. package/dist/cjs/utils/generics.js +0 -63
  237. package/dist/cjs/utils/numericLiterals.js +0 -75
  238. package/dist/cjs/utils/objectKinds.js +0 -69
  239. package/dist/cjs/utils/paths.js +0 -32
  240. package/dist/cjs/utils/serialize.js +0 -74
  241. package/dist/cjs/utils/unionToTuple.js +0 -4
  242. package/dist/mjs/main.js +0 -8
  243. package/dist/mjs/nodes/branch.js +0 -123
  244. package/dist/mjs/nodes/compose.js +0 -141
  245. package/dist/mjs/nodes/discriminate.js +0 -250
  246. package/dist/mjs/nodes/node.js +0 -117
  247. package/dist/mjs/nodes/predicate.js +0 -69
  248. package/dist/mjs/nodes/rules/class.js +0 -11
  249. package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
  250. package/dist/mjs/nodes/rules/divisor.js +0 -15
  251. package/dist/mjs/nodes/rules/props.js +0 -149
  252. package/dist/mjs/nodes/rules/range.js +0 -86
  253. package/dist/mjs/nodes/rules/regex.js +0 -11
  254. package/dist/mjs/nodes/rules/rules.js +0 -106
  255. package/dist/mjs/package.json +0 -3
  256. package/dist/mjs/parse/ast/ast.js +0 -1
  257. package/dist/mjs/parse/ast/bound.js +0 -2
  258. package/dist/mjs/parse/ast/config.js +0 -9
  259. package/dist/mjs/parse/ast/distributableFunction.js +0 -34
  260. package/dist/mjs/parse/ast/divisor.js +0 -1
  261. package/dist/mjs/parse/ast/intersection.js +0 -16
  262. package/dist/mjs/parse/ast/keyof.js +0 -103
  263. package/dist/mjs/parse/ast/morph.js +0 -44
  264. package/dist/mjs/parse/ast/narrow.js +0 -14
  265. package/dist/mjs/parse/ast/node.js +0 -1
  266. package/dist/mjs/parse/ast/tuple.js +0 -80
  267. package/dist/mjs/parse/ast/union.js +0 -1
  268. package/dist/mjs/parse/ast/utils.js +0 -1
  269. package/dist/mjs/parse/definition.js +0 -46
  270. package/dist/mjs/parse/record.js +0 -29
  271. package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
  272. package/dist/mjs/parse/string/reduce/shared.js +0 -6
  273. package/dist/mjs/parse/string/reduce/static.js +0 -1
  274. package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
  275. package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
  276. package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
  277. package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
  278. package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
  279. package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
  280. package/dist/mjs/parse/string/shift/scanner.js +0 -106
  281. package/dist/mjs/parse/string/string.js +0 -28
  282. package/dist/mjs/scopes/ark.js +0 -28
  283. package/dist/mjs/scopes/cache.js +0 -38
  284. package/dist/mjs/scopes/expressions.js +0 -89
  285. package/dist/mjs/scopes/jsObjects.js +0 -82
  286. package/dist/mjs/scopes/scope.js +0 -303
  287. package/dist/mjs/scopes/tsKeywords.js +0 -116
  288. package/dist/mjs/scopes/type.js +0 -35
  289. package/dist/mjs/scopes/validation/validation.js +0 -112
  290. package/dist/mjs/traverse/problems.js +0 -260
  291. package/dist/mjs/traverse/traverse.js +0 -373
  292. package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
  293. package/dist/mjs/utils/data.js +0 -38
  294. package/dist/mjs/utils/domains.js +0 -15
  295. package/dist/mjs/utils/errors.js +0 -10
  296. package/dist/mjs/utils/freeze.js +0 -7
  297. package/dist/mjs/utils/generics.js +0 -38
  298. package/dist/mjs/utils/numericLiterals.js +0 -72
  299. package/dist/mjs/utils/objectKinds.js +0 -55
  300. package/dist/mjs/utils/paths.js +0 -18
  301. package/dist/mjs/utils/serialize.js +0 -58
  302. package/dist/mjs/utils/unionToTuple.js +0 -1
  303. package/dist/tsconfig.temp.tsbuildinfo +0 -1
  304. package/dist/types/main.d.ts +0 -15
  305. package/dist/types/nodes/branch.d.ts +0 -29
  306. package/dist/types/nodes/compose.d.ts +0 -98
  307. package/dist/types/nodes/discriminate.d.ts +0 -26
  308. package/dist/types/nodes/node.d.ts +0 -69
  309. package/dist/types/nodes/predicate.d.ts +0 -18
  310. package/dist/types/nodes/rules/class.d.ts +0 -4
  311. package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
  312. package/dist/types/nodes/rules/divisor.d.ts +0 -3
  313. package/dist/types/nodes/rules/props.d.ts +0 -43
  314. package/dist/types/nodes/rules/range.d.ts +0 -34
  315. package/dist/types/nodes/rules/regex.d.ts +0 -5
  316. package/dist/types/nodes/rules/rules.d.ts +0 -33
  317. package/dist/types/parse/ast/ast.d.ts +0 -24
  318. package/dist/types/parse/ast/bound.d.ts +0 -27
  319. package/dist/types/parse/ast/config.d.ts +0 -15
  320. package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
  321. package/dist/types/parse/ast/divisor.d.ts +0 -13
  322. package/dist/types/parse/ast/intersection.d.ts +0 -31
  323. package/dist/types/parse/ast/keyof.d.ts +0 -10
  324. package/dist/types/parse/ast/morph.d.ts +0 -18
  325. package/dist/types/parse/ast/narrow.d.ts +0 -21
  326. package/dist/types/parse/ast/node.d.ts +0 -35
  327. package/dist/types/parse/ast/tuple.d.ts +0 -41
  328. package/dist/types/parse/ast/union.d.ts +0 -17
  329. package/dist/types/parse/ast/utils.d.ts +0 -7
  330. package/dist/types/parse/definition.d.ts +0 -30
  331. package/dist/types/parse/record.d.ts +0 -26
  332. package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
  333. package/dist/types/parse/string/reduce/shared.d.ts +0 -25
  334. package/dist/types/parse/string/reduce/static.d.ts +0 -130
  335. package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
  336. package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
  337. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
  338. package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
  339. package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
  340. package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
  341. package/dist/types/parse/string/shift/scanner.d.ts +0 -89
  342. package/dist/types/parse/string/string.d.ts +0 -25
  343. package/dist/types/scopes/ark.d.ts +0 -209
  344. package/dist/types/scopes/cache.d.ts +0 -14
  345. package/dist/types/scopes/expressions.d.ts +0 -136
  346. package/dist/types/scopes/jsObjects.d.ts +0 -26
  347. package/dist/types/scopes/scope.d.ts +0 -99
  348. package/dist/types/scopes/tsKeywords.d.ts +0 -50
  349. package/dist/types/scopes/type.d.ts +0 -67
  350. package/dist/types/scopes/validation/creditCard.d.ts +0 -2
  351. package/dist/types/scopes/validation/validation.d.ts +0 -49
  352. package/dist/types/traverse/problems.d.ts +0 -88
  353. package/dist/types/traverse/traverse.d.ts +0 -55
  354. package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
  355. package/dist/types/utils/data.d.ts +0 -13
  356. package/dist/types/utils/domains.d.ts +0 -32
  357. package/dist/types/utils/errors.d.ts +0 -6
  358. package/dist/types/utils/freeze.d.ts +0 -2
  359. package/dist/types/utils/generics.d.ts +0 -125
  360. package/dist/types/utils/numericLiterals.d.ts +0 -46
  361. package/dist/types/utils/objectKinds.d.ts +0 -84
  362. package/dist/types/utils/paths.d.ts +0 -9
  363. package/dist/types/utils/serialize.d.ts +0 -37
  364. package/dist/types/utils/unionToTuple.d.ts +0 -11
package/README.md DELETED
@@ -1,351 +0,0 @@
1
- <h1 align="center">ArkType <sub><sup>TypeScript's 1:1 validator</sup></sub></h1>
2
-
3
- [<img src="./dev/arktype.io/static/img/arktype.gif">](https://arktype.io/try)
4
- <sub>
5
- <i>`typescript@4.9.5` in VS Code— no extensions or plugins required (<a href="#how">how?</a>) (<a href="https://arktype.io/try">try in-browser</a>)</i>
6
- </sub>
7
- <br />
8
-
9
- ## What is it?
10
-
11
- <!-- @snipStart:intro -->
12
-
13
- <p>ArkType is a runtime validation library that can infer <b>TypeScript definitions 1:1</b> and reuse them as <b>highly-optimized validators</b> for your data.</p>
14
-
15
- <p>With each character you type, you'll get <b>immediate feedback from your editor</b> in the form of either a fully-inferred <code>Type</code> or a specific and helpful <code>ParseError</code>.</p>
16
-
17
- <p>This result exactly mirrors what you can expect to happen at runtime down to the punctuation of the error message- <b>no plugins required</b>.</p>
18
-
19
- <!-- @snipEnd -->
20
-
21
- ```ts @blockFrom:dev/test/examples/type.ts
22
- import { type } from "arktype"
23
-
24
- // Definitions are statically parsed and inferred as TS.
25
- export const user = type({
26
- name: "string",
27
- device: {
28
- platform: "'android'|'ios'",
29
- "version?": "number"
30
- }
31
- })
32
-
33
- // Validators return typed data or clear, customizable errors.
34
- export const { data, problems } = user({
35
- name: "Alan Turing",
36
- device: {
37
- // problems.summary: "device/platform must be 'android' or 'ios' (was 'enigma')"
38
- platform: "enigma"
39
- }
40
- })
41
- ```
42
-
43
- Check out [how it works](#how), [try it in-browser](https://arktype.io/docs/#your-first-type), or [scroll slightly](#install) to read about installation.
44
-
45
- <a id="install" />
46
-
47
- <!-- @snipStart:install -->
48
-
49
- ## Install <sub><sub>📦`12KB` gzipped, `0` dependencies</sub></sub>
50
-
51
- <img src="./dev/arktype.io/static/img/npm.svg" alt="Npm Icon" height="16px" /> <code>npm install arktype</code>
52
- <sub>(or whatever package manager you prefer)</sub>
53
- <br />
54
-
55
- Our types are tested in [strict-mode](https://www.typescriptlang.org/tsconfig#strict) with TypeScript versions `4.8`, `4.9`, and `5.0`.
56
-
57
- _Our APIs have mostly stabilized, but details may still change during the alpha/beta stages of our 1.0 release. If you have suggestions that may require a breaking change, now is the time to let us know!_ ⛵
58
-
59
- <!-- @snipEnd -->
60
-
61
- ### Scopes
62
-
63
- [Try this example in-browser.](https://arktype.io/docs/scopes)
64
-
65
- ```ts @blockFrom:dev/test/examples/scope.ts
66
- import { scope } from "arktype"
67
-
68
- // Scopes are collections of types that can reference each other.
69
- export const types = scope({
70
- package: {
71
- name: "string",
72
- "dependencies?": "package[]",
73
- "contributors?": "contributor[]"
74
- },
75
- contributor: {
76
- // Subtypes like 'email' are inferred like 'string' but provide additional validation at runtime.
77
- email: "email",
78
- "packages?": "package[]"
79
- }
80
- }).compile()
81
-
82
- // Cyclic types are inferred to arbitrary depth...
83
- export type Package = typeof types.package.infer
84
-
85
- // And can validate cyclic data.
86
- const packageData: Package = {
87
- name: "arktype",
88
- dependencies: [{ name: "typescript" }],
89
- contributors: [{ email: "david@sharktypeio" }]
90
- }
91
- packageData.dependencies![0].dependencies = [packageData]
92
-
93
- export const { data, problems } = types.package(packageData)
94
- ```
95
-
96
- ## Syntax
97
-
98
- This is an informal, non-exhaustive list of current and upcoming ArkType syntax.
99
-
100
- There are some subjects it doesn't cover, primarily tuple expressions and scopes. As mentioned below, keep an eye out for comprehensive docs coming with the upcoming beta release. In the meantime, join [our Discord](https://discord.gg/xEzdc3fJQC) or head to our [GitHub Discussions](https://github.com/arktypeio/arktype/discussions) to ask a question and there's a good chance you'll see a response within the hour 😊
101
-
102
- ```ts
103
- export const currentTsSyntax = type({
104
- keyword: "null",
105
- stringLiteral: "'TS'",
106
- numberLiteral: "5",
107
- bigintLiteral: "5n",
108
- union: "string|number",
109
- intersection: "boolean&true",
110
- array: "Date[]",
111
- grouping: "(0|1)[]",
112
- objectLiteral: {
113
- nested: "string",
114
- "optional?": "number"
115
- },
116
- tuple: ["number", "number"]
117
- })
118
-
119
- // these features will be available in the upcoming release
120
-
121
- export const upcomingTsSyntax = type({
122
- keyof: "keyof bigint",
123
- thisKeyword: "this", // recurses to the root of the current type
124
- variadicTuples: ["true", "...false[]"]
125
- })
126
-
127
- export const validationSyntax = type({
128
- keywords: "email|uuid|creditCard|integer", // and many more
129
- builtinParsers: "parsedDate", // parses a Date from a string
130
- nativeRegexLiteral: /@arktype\.io/,
131
- embeddedRegexLiteral: "email&/@arktype\\.io/",
132
- divisibility: "number%10", // a multiple of 10
133
- bound: "alpha>10", // an alpha-only string with more than 10 characters
134
- range: "1<=email[]<99", // a list of 1 to 99 emails
135
- narrows: ["number", "=>", (n) => n % 2 === 1], // an odd integer
136
- morphs: ["string", "|>", parseFloat] // validates a string input then parses it to a number
137
- })
138
-
139
- // in the upcoming release, you can use chaining to define expressions directly
140
- // that use objects or functions that can't be embedded in strings
141
-
142
- export const parseBigintLiteral = type({ value: "string" })
143
- .and({
144
- format: "'bigint'"
145
- })
146
- .narrow((data): data is { value: `${string}n`; format: "bigint" } =>
147
- data.value.endsWith("n")
148
- )
149
- .morph((data) => BigInt(data.value.slice(-1)))
150
-
151
- export const { data, problems } = parseBigintLiteral("999n")
152
- // ^ bigint | undefined
153
- ```
154
-
155
- ## API
156
-
157
- <!--@snipStart:api -->
158
-
159
- ArkType supports many of TypeScript's built-in types and operators, as well as some new ones dedicated exclusively to runtime validation. In fact, we got a little ahead of ourselves and built a ton of cool features, but we're still working on getting caught up syntax and API docs. Keep an eye out for more in the next couple weeks ⛵
160
-
161
- In the meantime, check out the examples here and use the type hints you get to learn how you can customize your types and scopes. If you want to explore some of the more advanced features, take a look at [our unit tests](./dev/test) or ask us [on Discord](https://discord.gg/xEzdc3fJQC) if your functionality is supported. If not, [create a GitHub issue](https://github.com/arktypeio/arktype/issues/new) so we can prioritize it!
162
-
163
- <!--@snipEnd -->
164
-
165
- ## Integrations
166
-
167
- ### tRPC
168
-
169
- ArkType can easily be used with tRPC via the `assert` prop:
170
-
171
- ```ts
172
- ...
173
- t.procedure
174
- .input(
175
- type({
176
- name: "string",
177
- "age?": "number"
178
- }).assert
179
- )
180
- ...
181
- ```
182
-
183
- ## How?
184
-
185
- ArkType's isomorphic parser has parallel static and dynamic implementations. This means as soon as you type a definition in your editor, you'll know the eventual result at runtime.
186
-
187
- If you're curious, below is an example of what that looks like under the hood. If not, close that hood back up, `npm install arktype` and enjoy top-notch developer experience 🧑‍💻
188
-
189
- ```ts @blockFrom:src/parse/string/shift/operator/operator.ts:parseOperator
190
- export const parseOperator = (s: DynamicState): void => {
191
- const lookahead = s.scanner.shift()
192
- return lookahead === ""
193
- ? s.finalize()
194
- : lookahead === "["
195
- ? s.scanner.shift() === "]"
196
- ? s.rootToArray()
197
- : s.error(incompleteArrayTokenMessage)
198
- : isKeyOf(lookahead, Scanner.branchTokens)
199
- ? s.pushRootToBranch(lookahead)
200
- : lookahead === ")"
201
- ? s.finalizeGroup()
202
- : isKeyOf(lookahead, Scanner.comparatorStartChars)
203
- ? parseBound(s, lookahead)
204
- : lookahead === "%"
205
- ? parseDivisor(s)
206
- : lookahead === " "
207
- ? parseOperator(s)
208
- : throwInternalError(writeUnexpectedCharacterMessage(lookahead))
209
- }
210
-
211
- export type parseOperator<s extends StaticState> =
212
- s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned>
213
- ? lookahead extends "["
214
- ? unscanned extends Scanner.shift<"]", infer nextUnscanned>
215
- ? state.setRoot<s, [s["root"], "[]"], nextUnscanned>
216
- : error<incompleteArrayTokenMessage>
217
- : lookahead extends Scanner.BranchToken
218
- ? state.reduceBranch<s, lookahead, unscanned>
219
- : lookahead extends ")"
220
- ? state.finalizeGroup<s, unscanned>
221
- : lookahead extends Scanner.ComparatorStartChar
222
- ? parseBound<s, lookahead, unscanned>
223
- : lookahead extends "%"
224
- ? parseDivisor<s, unscanned>
225
- : lookahead extends " "
226
- ? parseOperator<state.scanTo<s, unscanned>>
227
- : error<writeUnexpectedCharacterMessage<lookahead>>
228
- : state.finalize<s>
229
- ```
230
-
231
- ## Contributions
232
-
233
- We accept and encourage pull requests from outside ArkType.
234
-
235
- Depending on your level of familiarity with type systems and TS generics, some parts of the codebase may be hard to jump into. That said, there's plenty of opportunities for more straightforward contributions.
236
-
237
- If you're planning on submitting a non-trivial fix or a new feature, please [create an issue first](https://github.com/arktypeio/arktype/issues/new) so everyone's on the same page. The last thing we want is for you to spend time on a submission we're unable to merge.
238
-
239
- When you're ready, check out our [guide](./.github/CONTRIBUTING.md) to get started!
240
-
241
- ## License
242
-
243
- This project is licensed under the terms of the
244
- [MIT license](./LICENSE).
245
-
246
- ## Collaboration
247
-
248
- I'd love to hear about what you're working on and how ArkType can help. Please reach out to david@arktype.io.
249
-
250
- ## Code of Conduct
251
-
252
- We will not tolerate any form of disrespect toward members of our community. Please refer to our [Code of Conduct](./.github/CODE_OF_CONDUCT.md) and reach out to david@arktype.io immediately if you've seen or experienced an interaction that may violate these standards.
253
-
254
- ## Sponsorship
255
-
256
- We've been working full-time on this project for over a year and it means a lot to have the community behind us.
257
-
258
- If the project has been useful to you and you are in a financial position to do so, please chip in via [GitHub Sponsors](https://github.com/sponsors/arktypeio).
259
-
260
- Otherwise, consider sending me an email (david@arktype.io) or [message me on Discord](https://arktype.io/discord) to let me know you're a fan of ArkType. Either would make my day!
261
-
262
- ### Current Sponsors 🥰
263
-
264
- <table>
265
- <tr>
266
- <th>fubhy</th>
267
- <th>sam-goodwin</th>
268
- <th>tmm</th>
269
- <th>thomasballinger</th>
270
- <th>jacksteamdev</th>
271
- </tr>
272
- <tr>
273
- <td>
274
- <a href="https://github.com/fubhy"
275
- ><img
276
- height="64px"
277
- src="https://avatars.githubusercontent.com/u/1172528"
278
- /></a>
279
- </td>
280
- <td>
281
- <a href="https://github.com/sam-goodwin"
282
- ><img
283
- height="64px"
284
- src="https://avatars.githubusercontent.com/u/38672686"
285
- /></a>
286
- </td>
287
- <td>
288
- <a href="https://github.com/tmm"
289
- ><img
290
- height="64px"
291
- src="https://avatars.githubusercontent.com/u/6759464"
292
- /></a>
293
- </td>
294
- <td>
295
- <a href="https://github.com/thomasballinger"
296
- ><img
297
- height="64px"
298
- src="https://avatars.githubusercontent.com/u/458879"
299
- /></a>
300
- </td>
301
- <td>
302
- <a href="https://github.com/jacksteamdev"
303
- ><img
304
- height="64px"
305
- src="https://avatars.githubusercontent.com/u/23390212"
306
- /></a>
307
- </td>
308
- </tr>
309
- <tr>
310
- <th>neodon</th>
311
- <th>mewhhaha</th>
312
- <th>codeandcats</th>
313
- <th>xrexy</th>
314
- <th>Timeraa</th>
315
- </tr>
316
- <tr>
317
- <td>
318
- <a href="https://github.com/neodon"
319
- ><img height="64px" src="https://avatars.githubusercontent.com/u/82944"
320
- /></a>
321
- </td>
322
- <td>
323
- <a href="https://github.com/mewhhaha"
324
- ><img
325
- height="64px"
326
- src="https://avatars.githubusercontent.com/u/3399205"
327
- /></a>
328
- </td>
329
- <td>
330
- <a href="https://github.com/codeandcats"
331
- ><img
332
- height="64px"
333
- src="https://avatars.githubusercontent.com/u/6035934"
334
- /></a>
335
- </td>
336
- <td>
337
- <a href="https://github.com/xrexy"
338
- ><img
339
- height="64px"
340
- src="https://avatars.githubusercontent.com/u/71969236"
341
- /></a>
342
- </td>
343
- <td>
344
- <a href="https://github.com/Timeraa"
345
- ><img
346
- height="64px"
347
- src="https://avatars.githubusercontent.com/u/29104008"
348
- /></a>
349
- </td>
350
- </tr>
351
- </table>
package/dist/cjs/main.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- scope: ()=>_scopeJs.scope,
13
- type: ()=>_arkJs.type,
14
- ark: ()=>_arkJs.ark,
15
- arkScope: ()=>_arkJs.arkScope,
16
- arrayOf: ()=>_expressionsJs.arrayOf,
17
- instanceOf: ()=>_expressionsJs.instanceOf,
18
- intersection: ()=>_expressionsJs.intersection,
19
- keyOf: ()=>_expressionsJs.keyOf,
20
- morph: ()=>_expressionsJs.morph,
21
- narrow: ()=>_expressionsJs.narrow,
22
- union: ()=>_expressionsJs.union,
23
- valueOf: ()=>_expressionsJs.valueOf,
24
- jsObjectsScope: ()=>_jsObjectsJs.jsObjectsScope,
25
- tsKeywordsScope: ()=>_tsKeywordsJs.tsKeywordsScope,
26
- validationScope: ()=>_validationJs.validationScope,
27
- Problems: ()=>_problemsJs.Problems,
28
- Problem: ()=>_problemsJs.Problem,
29
- parseConfigTuple: ()=>_configJs.parseConfigTuple
30
- });
31
- const _scopeJs = require("./scopes/scope.js");
32
- const _arkJs = require("./scopes/ark.js");
33
- const _expressionsJs = require("./scopes/expressions.js");
34
- const _jsObjectsJs = require("./scopes/jsObjects.js");
35
- const _tsKeywordsJs = require("./scopes/tsKeywords.js");
36
- const _validationJs = require("./scopes/validation/validation.js");
37
- const _problemsJs = require("./traverse/problems.js");
38
- const _configJs = require("./parse/ast/config.js");
@@ -1,140 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- isBranchComparison: ()=>isBranchComparison,
13
- compareBranches: ()=>compareBranches,
14
- isTransformationBranch: ()=>isTransformationBranch,
15
- flattenBranch: ()=>flattenBranch,
16
- branchIntersection: ()=>branchIntersection
17
- });
18
- const _intersectionJs = require("../parse/ast/intersection.js");
19
- const _domainsJs = require("../utils/domains.js");
20
- const _errorsJs = require("../utils/errors.js");
21
- const _composeJs = require("./compose.js");
22
- const _rulesJs = require("./rules/rules.js");
23
- const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
24
- const compareBranches = (lConditions, rConditions, state)=>{
25
- const result = {
26
- lBranches: lConditions,
27
- rBranches: rConditions,
28
- lExtendsR: [],
29
- rExtendsL: [],
30
- equalities: [],
31
- distinctIntersections: []
32
- };
33
- const pairs = rConditions.map((condition)=>({
34
- condition,
35
- distinct: []
36
- }));
37
- lConditions.forEach((l, lIndex)=>{
38
- let lImpliesR = false;
39
- const distinct = pairs.map((rPairs, rIndex)=>{
40
- if (lImpliesR || !rPairs.distinct) {
41
- return null;
42
- }
43
- const r = rPairs.condition;
44
- const subresult = branchIntersection(l, r, state);
45
- if ((0, _composeJs.isDisjoint)(subresult)) {
46
- // doesn't tell us about any redundancies or add a distinct pair
47
- return null;
48
- } else if (subresult === l) {
49
- result.lExtendsR.push(lIndex);
50
- // If l is a subtype of the current r branch, intersections
51
- // with the remaining branches of r won't lead to distinct
52
- // branches, so we set a flag indicating we can skip them.
53
- lImpliesR = true;
54
- return null;
55
- } else if (subresult === r) {
56
- result.rExtendsL.push(rIndex);
57
- // If r is a subtype of the current l branch, it is removed
58
- // from pairsByR because future intersections won't lead to
59
- // distinct branches.
60
- rPairs.distinct = null;
61
- return null;
62
- } else if ((0, _composeJs.isEquality)(subresult)) {
63
- // Combination of l and r subtype cases.
64
- result.equalities.push([
65
- lIndex,
66
- rIndex
67
- ]);
68
- lImpliesR = true;
69
- rPairs.distinct = null;
70
- return null;
71
- } else if ((0, _domainsJs.hasDomain)(subresult, "object")) {
72
- // Neither branch is a subtype of the other, return
73
- // the result of the intersection as a candidate
74
- // branch for the final union
75
- return subresult;
76
- }
77
- return (0, _errorsJs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsJs.domainOf)(subresult)}'`);
78
- });
79
- if (!lImpliesR) {
80
- for(let i = 0; i < pairs.length; i++){
81
- if (distinct[i]) {
82
- pairs[i].distinct?.push(distinct[i]);
83
- }
84
- }
85
- }
86
- });
87
- result.distinctIntersections = pairs.flatMap((pairs)=>pairs.distinct ?? []);
88
- return result;
89
- };
90
- const isTransformationBranch = (branch)=>"rules" in branch;
91
- const flattenBranch = (branch, ctx)=>{
92
- if (isTransformationBranch(branch)) {
93
- const result = (0, _rulesJs.flattenRules)(branch.rules, ctx);
94
- if (branch.morph) {
95
- if (typeof branch.morph === "function") {
96
- result.push([
97
- "morph",
98
- branch.morph
99
- ]);
100
- } else {
101
- for (const morph of branch.morph){
102
- result.push([
103
- "morph",
104
- morph
105
- ]);
106
- }
107
- }
108
- }
109
- return result;
110
- }
111
- return (0, _rulesJs.flattenRules)(branch, ctx);
112
- };
113
- const rulesOf = (branch)=>branch.rules ?? branch;
114
- const branchIntersection = (l, r, state)=>{
115
- const lRules = rulesOf(l);
116
- const rRules = rulesOf(r);
117
- const rulesResult = (0, _rulesJs.rulesIntersection)(lRules, rRules, state);
118
- if ("morph" in l) {
119
- if ("morph" in r) {
120
- if (l.morph === r.morph) {
121
- return (0, _composeJs.isEquality)(rulesResult) || (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
122
- rules: rulesResult,
123
- morph: l.morph
124
- };
125
- }
126
- return state.lastOperator === "&" ? (0, _errorsJs.throwParseError)((0, _intersectionJs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
127
- }
128
- return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
129
- rules: (0, _composeJs.isEquality)(rulesResult) ? l.rules : rulesResult,
130
- morph: l.morph
131
- };
132
- }
133
- if ("morph" in r) {
134
- return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
135
- rules: (0, _composeJs.isEquality)(rulesResult) ? r.rules : rulesResult,
136
- morph: r.morph
137
- };
138
- }
139
- return rulesResult;
140
- };
@@ -1,163 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- composeIntersection: ()=>composeIntersection,
13
- undefinedOperandsMessage: ()=>undefinedOperandsMessage,
14
- disjointDescriptionWriters: ()=>disjointDescriptionWriters,
15
- stringifyRange: ()=>stringifyRange,
16
- IntersectionState: ()=>IntersectionState,
17
- anonymousDisjoint: ()=>anonymousDisjoint,
18
- isDisjoint: ()=>isDisjoint,
19
- equality: ()=>equality,
20
- isEquality: ()=>isEquality,
21
- composeKeyedIntersection: ()=>composeKeyedIntersection
22
- });
23
- const _errorsJs = require("../utils/errors.js");
24
- const _genericsJs = require("../utils/generics.js");
25
- const _pathsJs = require("../utils/paths.js");
26
- const _serializeJs = require("../utils/serialize.js");
27
- function _checkPrivateRedeclaration(obj, privateCollection) {
28
- if (privateCollection.has(obj)) {
29
- throw new TypeError("Cannot initialize the same private elements twice on an object");
30
- }
31
- }
32
- function _classApplyDescriptorGet(receiver, descriptor) {
33
- if (descriptor.get) {
34
- return descriptor.get.call(receiver);
35
- }
36
- return descriptor.value;
37
- }
38
- function _classApplyDescriptorSet(receiver, descriptor, value) {
39
- if (descriptor.set) {
40
- descriptor.set.call(receiver, value);
41
- } else {
42
- if (!descriptor.writable) {
43
- throw new TypeError("attempted to set read only private field");
44
- }
45
- descriptor.value = value;
46
- }
47
- }
48
- function _classExtractFieldDescriptor(receiver, privateMap, action) {
49
- if (!privateMap.has(receiver)) {
50
- throw new TypeError("attempted to " + action + " private field on non-instance");
51
- }
52
- return privateMap.get(receiver);
53
- }
54
- function _classPrivateFieldGet(receiver, privateMap) {
55
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
56
- return _classApplyDescriptorGet(receiver, descriptor);
57
- }
58
- function _classPrivateFieldInit(obj, privateMap, value) {
59
- _checkPrivateRedeclaration(obj, privateMap);
60
- privateMap.set(obj, value);
61
- }
62
- function _classPrivateFieldSet(receiver, privateMap, value) {
63
- var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
64
- _classApplyDescriptorSet(receiver, descriptor, value);
65
- return value;
66
- }
67
- function _defineProperty(obj, key, value) {
68
- if (key in obj) {
69
- Object.defineProperty(obj, key, {
70
- value: value,
71
- enumerable: true,
72
- configurable: true,
73
- writable: true
74
- });
75
- } else {
76
- obj[key] = value;
77
- }
78
- return obj;
79
- }
80
- const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === undefined ? (0, _errorsJs.throwInternalError)(undefinedOperandsMessage) : r : r === undefined ? l : reducer(l, r, state);
81
- const undefinedOperandsMessage = `Unexpected operation two undefined operands`;
82
- const disjointDescriptionWriters = {
83
- domain: ({ l , r })=>`${l.join(", ")} and ${r.join(", ")}`,
84
- range: ({ l , r })=>`${stringifyRange(l)} and ${stringifyRange(r)}`,
85
- class: ({ l , r })=>`classes ${typeof l === "string" ? l : l.name} and ${typeof r === "string" ? r : r.name}`,
86
- tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
87
- value: ({ l , r })=>`literal values ${(0, _serializeJs.stringify)(l)} and ${(0, _serializeJs.stringify)(r)}`,
88
- leftAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(l.value)} and ${(0, _serializeJs.stringify)(r)}`,
89
- rightAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(r.value)} and ${(0, _serializeJs.stringify)(l)}`,
90
- union: ({ l , r })=>`branches ${(0, _serializeJs.stringify)(l)} and branches ${(0, _serializeJs.stringify)(r)}`
91
- };
92
- const stringifyRange = (range)=>"limit" in range ? `the range of exactly ${range.limit}` : range.min ? range.max ? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}` : `${range.min.comparator}${range.min.limit}` : range.max ? `${range.max.comparator}${range.max.limit}` : "the unbounded range";
93
- var _disjoints = /*#__PURE__*/ new WeakMap();
94
- class IntersectionState {
95
- get disjoints() {
96
- return _classPrivateFieldGet(this, _disjoints);
97
- }
98
- addDisjoint(kind, l, r) {
99
- _classPrivateFieldGet(this, _disjoints)[`${this.path}`] = {
100
- kind,
101
- l,
102
- r,
103
- lOptional: this.lOptional,
104
- rOptional: this.rOptional
105
- };
106
- return empty;
107
- }
108
- constructor(type, lastOperator){
109
- _defineProperty(this, "type", void 0);
110
- _defineProperty(this, "lastOperator", void 0);
111
- _defineProperty(this, "path", void 0);
112
- _defineProperty(this, "lOptional", void 0);
113
- _defineProperty(this, "rOptional", void 0);
114
- _defineProperty(this, "domain", void 0);
115
- _classPrivateFieldInit(this, _disjoints, {
116
- writable: true,
117
- value: void 0
118
- });
119
- this.type = type;
120
- this.lastOperator = lastOperator;
121
- this.path = new _pathsJs.Path();
122
- this.lOptional = false;
123
- this.rOptional = false;
124
- _classPrivateFieldSet(this, _disjoints, {});
125
- }
126
- }
127
- const empty = Symbol("empty");
128
- const anonymousDisjoint = ()=>empty;
129
- const isDisjoint = (result)=>result === empty;
130
- const equal = Symbol("equal");
131
- const equality = ()=>equal;
132
- const isEquality = (result)=>result === equal;
133
- const composeKeyedIntersection = (reducer, config)=>(l, r, state)=>{
134
- const result = {};
135
- const keys = (0, _genericsJs.objectKeysOf)({
136
- ...l,
137
- ...r
138
- });
139
- let lImpliesR = true;
140
- let rImpliesL = true;
141
- for (const k of keys){
142
- const keyResult = typeof reducer === "function" ? reducer(k, l[k], r[k], state) : reducer[k](l[k], r[k], state);
143
- if (isEquality(keyResult)) {
144
- if (l[k] !== undefined) {
145
- result[k] = l[k];
146
- }
147
- } else if (isDisjoint(keyResult)) {
148
- if (config.onEmpty === "omit") {
149
- lImpliesR = false;
150
- rImpliesL = false;
151
- } else {
152
- return empty;
153
- }
154
- } else {
155
- if (keyResult !== undefined) {
156
- result[k] = keyResult;
157
- }
158
- lImpliesR && (lImpliesR = keyResult === l[k]);
159
- rImpliesL && (rImpliesL = keyResult === r[k]);
160
- }
161
- }
162
- return lImpliesR ? rImpliesL ? equality() : l : rImpliesL ? r : result;
163
- };