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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/__tests__/array.test.ts +23 -25
  2. package/__tests__/config.test.ts +19 -8
  3. package/__tests__/examples.test.ts +3 -3
  4. package/__tests__/imports.test.ts +18 -12
  5. package/__tests__/instanceof.test.ts +7 -7
  6. package/__tests__/intersection.test.ts +2 -2
  7. package/__tests__/keyTraversal.test.ts +15 -15
  8. package/__tests__/keywords.test.ts +50 -37
  9. package/__tests__/literal.test.ts +30 -14
  10. package/__tests__/match.bench.ts +6 -6
  11. package/__tests__/narrow.test.ts +18 -24
  12. package/__tests__/objectLiteral.test.ts +134 -11
  13. package/__tests__/operator.bench.ts +4 -4
  14. package/__tests__/{morph.test.ts → pipe.test.ts} +136 -75
  15. package/__tests__/scope.test.ts +202 -15
  16. package/__tests__/traverse.test.ts +45 -36
  17. package/__tests__/type.test.ts +8 -10
  18. package/ark.ts +14 -11
  19. package/generic.ts +8 -6
  20. package/match.ts +59 -70
  21. package/out/ark.d.ts +5 -5
  22. package/out/ark.js +4 -5
  23. package/out/ark.js.map +1 -1
  24. package/out/generic.d.ts +0 -1
  25. package/out/generic.js +8 -7
  26. package/out/generic.js.map +1 -1
  27. package/out/main.d.ts +0 -1
  28. package/out/main.js +0 -1
  29. package/out/match.d.ts +0 -1
  30. package/out/match.js +50 -57
  31. package/out/match.js.map +1 -1
  32. package/out/module.d.ts +0 -1
  33. package/out/module.js +0 -1
  34. package/out/parser/definition.d.ts +1 -2
  35. package/out/parser/definition.js +0 -1
  36. package/out/parser/generic.d.ts +5 -6
  37. package/out/parser/generic.js +4 -6
  38. package/out/parser/generic.js.map +1 -1
  39. package/out/parser/objectLiteral.d.ts +1 -2
  40. package/out/parser/objectLiteral.js +17 -11
  41. package/out/parser/objectLiteral.js.map +1 -1
  42. package/out/parser/semantic/bounds.d.ts +1 -2
  43. package/out/parser/semantic/bounds.js +0 -1
  44. package/out/parser/semantic/divisor.d.ts +0 -1
  45. package/out/parser/semantic/divisor.js +0 -2
  46. package/out/parser/semantic/infer.d.ts +0 -1
  47. package/out/parser/semantic/infer.js +0 -2
  48. package/out/parser/semantic/utils.d.ts +0 -1
  49. package/out/parser/semantic/utils.js +0 -2
  50. package/out/parser/semantic/validate.d.ts +4 -5
  51. package/out/parser/semantic/validate.js +0 -1
  52. package/out/parser/semantic/validate.js.map +1 -1
  53. package/out/parser/string/reduce/dynamic.d.ts +0 -1
  54. package/out/parser/string/reduce/dynamic.js +4 -9
  55. package/out/parser/string/reduce/dynamic.js.map +1 -1
  56. package/out/parser/string/reduce/shared.d.ts +5 -18
  57. package/out/parser/string/reduce/shared.js +0 -1
  58. package/out/parser/string/reduce/static.d.ts +0 -1
  59. package/out/parser/string/reduce/static.js +0 -2
  60. package/out/parser/string/shift/operand/date.d.ts +2 -3
  61. package/out/parser/string/shift/operand/date.js +2 -5
  62. package/out/parser/string/shift/operand/date.js.map +1 -1
  63. package/out/parser/string/shift/operand/enclosed.d.ts +2 -17
  64. package/out/parser/string/shift/operand/enclosed.js +6 -9
  65. package/out/parser/string/shift/operand/enclosed.js.map +1 -1
  66. package/out/parser/string/shift/operand/genericArgs.d.ts +5 -6
  67. package/out/parser/string/shift/operand/genericArgs.js +4 -6
  68. package/out/parser/string/shift/operand/genericArgs.js.map +1 -1
  69. package/out/parser/string/shift/operand/operand.d.ts +0 -1
  70. package/out/parser/string/shift/operand/operand.js +0 -1
  71. package/out/parser/string/shift/operand/unenclosed.d.ts +6 -7
  72. package/out/parser/string/shift/operand/unenclosed.js +6 -13
  73. package/out/parser/string/shift/operand/unenclosed.js.map +1 -1
  74. package/out/parser/string/shift/operator/bounds.d.ts +1 -8
  75. package/out/parser/string/shift/operator/bounds.js +4 -9
  76. package/out/parser/string/shift/operator/bounds.js.map +1 -1
  77. package/out/parser/string/shift/operator/divisor.d.ts +1 -2
  78. package/out/parser/string/shift/operator/divisor.js +1 -3
  79. package/out/parser/string/shift/operator/divisor.js.map +1 -1
  80. package/out/parser/string/shift/operator/operator.d.ts +1 -2
  81. package/out/parser/string/shift/operator/operator.js +0 -1
  82. package/out/parser/string/shift/scanner.d.ts +0 -1
  83. package/out/parser/string/shift/scanner.js +2 -5
  84. package/out/parser/string/shift/scanner.js.map +1 -1
  85. package/out/parser/string/string.d.ts +0 -1
  86. package/out/parser/string/string.js +1 -3
  87. package/out/parser/string/string.js.map +1 -1
  88. package/out/parser/tuple.d.ts +1 -2
  89. package/out/parser/tuple.js +12 -16
  90. package/out/parser/tuple.js.map +1 -1
  91. package/out/scope.d.ts +12 -12
  92. package/out/scope.js +16 -38
  93. package/out/scope.js.map +1 -1
  94. package/out/type.d.ts +38 -19
  95. package/out/type.js +32 -2
  96. package/out/type.js.map +1 -1
  97. package/package.json +6 -4
  98. package/parser/generic.ts +13 -14
  99. package/parser/objectLiteral.ts +25 -11
  100. package/parser/semantic/validate.ts +2 -3
  101. package/parser/string/reduce/dynamic.ts +7 -10
  102. package/parser/string/shift/operand/date.ts +3 -6
  103. package/parser/string/shift/operand/enclosed.ts +8 -8
  104. package/parser/string/shift/operand/genericArgs.ts +8 -8
  105. package/parser/string/shift/operand/unenclosed.ts +15 -25
  106. package/parser/string/shift/operator/bounds.ts +7 -9
  107. package/parser/string/shift/operator/divisor.ts +2 -3
  108. package/parser/string/shift/scanner.ts +2 -4
  109. package/parser/string/string.ts +2 -3
  110. package/parser/tuple.ts +15 -16
  111. package/scope.ts +39 -57
  112. package/type.ts +151 -35
  113. package/__tests__/cyclic.test.ts +0 -148
  114. package/out/ark.d.ts.map +0 -1
  115. package/out/base.d.ts +0 -205
  116. package/out/base.d.ts.map +0 -1
  117. package/out/base.js +0 -320
  118. package/out/base.js.map +0 -1
  119. package/out/builtins/builtins.d.ts +0 -23
  120. package/out/builtins/builtins.d.ts.map +0 -1
  121. package/out/builtins/builtins.js +0 -15
  122. package/out/builtins/builtins.js.map +0 -1
  123. package/out/builtins/jsObjects.d.ts +0 -19
  124. package/out/builtins/jsObjects.d.ts.map +0 -1
  125. package/out/builtins/jsObjects.js +0 -18
  126. package/out/builtins/jsObjects.js.map +0 -1
  127. package/out/builtins/parsing.d.ts +0 -16
  128. package/out/builtins/parsing.d.ts.map +0 -1
  129. package/out/builtins/parsing.js +0 -62
  130. package/out/builtins/parsing.js.map +0 -1
  131. package/out/builtins/tsGenerics.d.ts +0 -2
  132. package/out/builtins/tsGenerics.d.ts.map +0 -1
  133. package/out/builtins/tsGenerics.js +0 -26
  134. package/out/builtins/tsGenerics.js.map +0 -1
  135. package/out/builtins/tsKeywords.d.ts +0 -23
  136. package/out/builtins/tsKeywords.d.ts.map +0 -1
  137. package/out/builtins/tsKeywords.js +0 -23
  138. package/out/builtins/tsKeywords.js.map +0 -1
  139. package/out/builtins/utils/creditCard.d.ts +0 -3
  140. package/out/builtins/utils/creditCard.d.ts.map +0 -1
  141. package/out/builtins/utils/creditCard.js +0 -35
  142. package/out/builtins/utils/creditCard.js.map +0 -1
  143. package/out/builtins/utils/date.d.ts +0 -41
  144. package/out/builtins/utils/date.d.ts.map +0 -1
  145. package/out/builtins/utils/date.js +0 -56
  146. package/out/builtins/utils/date.js.map +0 -1
  147. package/out/builtins/validation.d.ts +0 -19
  148. package/out/builtins/validation.d.ts.map +0 -1
  149. package/out/builtins/validation.js +0 -74
  150. package/out/builtins/validation.js.map +0 -1
  151. package/out/config.d.ts +0 -9
  152. package/out/config.d.ts.map +0 -1
  153. package/out/config.js +0 -18
  154. package/out/config.js.map +0 -1
  155. package/out/constraints/ast.d.ts +0 -287
  156. package/out/constraints/ast.d.ts.map +0 -1
  157. package/out/constraints/ast.js +0 -2
  158. package/out/constraints/ast.js.map +0 -1
  159. package/out/constraints/constraint.d.ts +0 -200
  160. package/out/constraints/constraint.d.ts.map +0 -1
  161. package/out/constraints/constraint.js +0 -25
  162. package/out/constraints/constraint.js.map +0 -1
  163. package/out/constraints/predicate.d.ts +0 -64
  164. package/out/constraints/predicate.d.ts.map +0 -1
  165. package/out/constraints/predicate.js +0 -52
  166. package/out/constraints/predicate.js.map +0 -1
  167. package/out/constraints/props/index.d.ts +0 -42
  168. package/out/constraints/props/index.d.ts.map +0 -1
  169. package/out/constraints/props/index.js +0 -56
  170. package/out/constraints/props/index.js.map +0 -1
  171. package/out/constraints/props/optional.d.ts +0 -37
  172. package/out/constraints/props/optional.d.ts.map +0 -1
  173. package/out/constraints/props/optional.js +0 -56
  174. package/out/constraints/props/optional.js.map +0 -1
  175. package/out/constraints/props/prop.d.ts +0 -49
  176. package/out/constraints/props/prop.d.ts.map +0 -1
  177. package/out/constraints/props/prop.js +0 -106
  178. package/out/constraints/props/prop.js.map +0 -1
  179. package/out/constraints/props/props.d.ts +0 -37
  180. package/out/constraints/props/props.d.ts.map +0 -1
  181. package/out/constraints/props/props.js +0 -121
  182. package/out/constraints/props/props.js.map +0 -1
  183. package/out/constraints/props/required.d.ts +0 -46
  184. package/out/constraints/props/required.d.ts.map +0 -1
  185. package/out/constraints/props/required.js +0 -81
  186. package/out/constraints/props/required.js.map +0 -1
  187. package/out/constraints/props/sequence.d.ts +0 -82
  188. package/out/constraints/props/sequence.d.ts.map +0 -1
  189. package/out/constraints/props/sequence.js +0 -376
  190. package/out/constraints/props/sequence.js.map +0 -1
  191. package/out/constraints/props/shared.d.ts +0 -3
  192. package/out/constraints/props/shared.d.ts.map +0 -1
  193. package/out/constraints/props/shared.js +0 -4
  194. package/out/constraints/props/shared.js.map +0 -1
  195. package/out/constraints/refinements/after.d.ts +0 -33
  196. package/out/constraints/refinements/after.d.ts.map +0 -1
  197. package/out/constraints/refinements/after.js +0 -36
  198. package/out/constraints/refinements/after.js.map +0 -1
  199. package/out/constraints/refinements/before.d.ts +0 -33
  200. package/out/constraints/refinements/before.d.ts.map +0 -1
  201. package/out/constraints/refinements/before.js +0 -43
  202. package/out/constraints/refinements/before.js.map +0 -1
  203. package/out/constraints/refinements/divisor.d.ts +0 -52
  204. package/out/constraints/refinements/divisor.d.ts.map +0 -1
  205. package/out/constraints/refinements/divisor.js +0 -52
  206. package/out/constraints/refinements/divisor.js.map +0 -1
  207. package/out/constraints/refinements/exactLength.d.ts +0 -45
  208. package/out/constraints/refinements/exactLength.d.ts.map +0 -1
  209. package/out/constraints/refinements/exactLength.js +0 -52
  210. package/out/constraints/refinements/exactLength.js.map +0 -1
  211. package/out/constraints/refinements/kinds.d.ts +0 -29
  212. package/out/constraints/refinements/kinds.d.ts.map +0 -1
  213. package/out/constraints/refinements/kinds.js +0 -17
  214. package/out/constraints/refinements/kinds.js.map +0 -1
  215. package/out/constraints/refinements/length.d.ts +0 -48
  216. package/out/constraints/refinements/length.d.ts.map +0 -1
  217. package/out/constraints/refinements/length.js +0 -53
  218. package/out/constraints/refinements/length.js.map +0 -1
  219. package/out/constraints/refinements/max.d.ts +0 -31
  220. package/out/constraints/refinements/max.d.ts.map +0 -1
  221. package/out/constraints/refinements/max.js +0 -35
  222. package/out/constraints/refinements/max.js.map +0 -1
  223. package/out/constraints/refinements/maxLength.d.ts +0 -32
  224. package/out/constraints/refinements/maxLength.d.ts.map +0 -1
  225. package/out/constraints/refinements/maxLength.js +0 -36
  226. package/out/constraints/refinements/maxLength.js.map +0 -1
  227. package/out/constraints/refinements/min.d.ts +0 -31
  228. package/out/constraints/refinements/min.d.ts.map +0 -1
  229. package/out/constraints/refinements/min.js +0 -28
  230. package/out/constraints/refinements/min.js.map +0 -1
  231. package/out/constraints/refinements/minLength.d.ts +0 -32
  232. package/out/constraints/refinements/minLength.d.ts.map +0 -1
  233. package/out/constraints/refinements/minLength.js +0 -33
  234. package/out/constraints/refinements/minLength.js.map +0 -1
  235. package/out/constraints/refinements/range.d.ts +0 -119
  236. package/out/constraints/refinements/range.d.ts.map +0 -1
  237. package/out/constraints/refinements/range.js +0 -89
  238. package/out/constraints/refinements/range.js.map +0 -1
  239. package/out/constraints/refinements/regex.d.ts +0 -47
  240. package/out/constraints/refinements/regex.d.ts.map +0 -1
  241. package/out/constraints/refinements/regex.js +0 -37
  242. package/out/constraints/refinements/regex.js.map +0 -1
  243. package/out/constraints/refinements/shared.d.ts +0 -20
  244. package/out/constraints/refinements/shared.d.ts.map +0 -1
  245. package/out/constraints/refinements/shared.js +0 -10
  246. package/out/constraints/refinements/shared.js.map +0 -1
  247. package/out/generic.d.ts.map +0 -1
  248. package/out/inference.d.ts +0 -137
  249. package/out/inference.d.ts.map +0 -1
  250. package/out/inference.js +0 -73
  251. package/out/inference.js.map +0 -1
  252. package/out/keywords/ark.d.ts +0 -70
  253. package/out/keywords/ark.d.ts.map +0 -1
  254. package/out/keywords/ark.js +0 -29
  255. package/out/keywords/ark.js.map +0 -1
  256. package/out/keywords/internal.d.ts +0 -13
  257. package/out/keywords/internal.d.ts.map +0 -1
  258. package/out/keywords/internal.js +0 -13
  259. package/out/keywords/internal.js.map +0 -1
  260. package/out/keywords/jsObject.d.ts +0 -20
  261. package/out/keywords/jsObject.d.ts.map +0 -1
  262. package/out/keywords/jsObject.js +0 -18
  263. package/out/keywords/jsObject.js.map +0 -1
  264. package/out/keywords/parsing.d.ts +0 -17
  265. package/out/keywords/parsing.d.ts.map +0 -1
  266. package/out/keywords/parsing.js +0 -64
  267. package/out/keywords/parsing.js.map +0 -1
  268. package/out/keywords/root.d.ts +0 -7
  269. package/out/keywords/root.d.ts.map +0 -1
  270. package/out/keywords/root.js +0 -4
  271. package/out/keywords/root.js.map +0 -1
  272. package/out/keywords/tsGenerics.d.ts +0 -2
  273. package/out/keywords/tsGenerics.d.ts.map +0 -1
  274. package/out/keywords/tsGenerics.js +0 -26
  275. package/out/keywords/tsGenerics.js.map +0 -1
  276. package/out/keywords/tsPrimitive.d.ts +0 -24
  277. package/out/keywords/tsPrimitive.d.ts.map +0 -1
  278. package/out/keywords/tsPrimitive.js +0 -25
  279. package/out/keywords/tsPrimitive.js.map +0 -1
  280. package/out/keywords/utils/creditCard.d.ts +0 -11
  281. package/out/keywords/utils/creditCard.d.ts.map +0 -1
  282. package/out/keywords/utils/creditCard.js +0 -35
  283. package/out/keywords/utils/creditCard.js.map +0 -1
  284. package/out/keywords/utils/date.d.ts +0 -45
  285. package/out/keywords/utils/date.d.ts.map +0 -1
  286. package/out/keywords/utils/date.js +0 -56
  287. package/out/keywords/utils/date.js.map +0 -1
  288. package/out/keywords/validation.d.ts +0 -20
  289. package/out/keywords/validation.d.ts.map +0 -1
  290. package/out/keywords/validation.js +0 -80
  291. package/out/keywords/validation.js.map +0 -1
  292. package/out/kinds.d.ts +0 -102
  293. package/out/kinds.d.ts.map +0 -1
  294. package/out/kinds.js +0 -29
  295. package/out/kinds.js.map +0 -1
  296. package/out/main.d.ts.map +0 -1
  297. package/out/match.d.ts.map +0 -1
  298. package/out/module.d.ts.map +0 -1
  299. package/out/parse.d.ts +0 -29
  300. package/out/parse.d.ts.map +0 -1
  301. package/out/parse.js +0 -161
  302. package/out/parse.js.map +0 -1
  303. package/out/parser/definition.d.ts.map +0 -1
  304. package/out/parser/generic.d.ts.map +0 -1
  305. package/out/parser/objectLiteral.d.ts.map +0 -1
  306. package/out/parser/semantic/bounds.d.ts.map +0 -1
  307. package/out/parser/semantic/divisor.d.ts.map +0 -1
  308. package/out/parser/semantic/infer.d.ts.map +0 -1
  309. package/out/parser/semantic/utils.d.ts.map +0 -1
  310. package/out/parser/semantic/validate.d.ts.map +0 -1
  311. package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
  312. package/out/parser/string/reduce/shared.d.ts.map +0 -1
  313. package/out/parser/string/reduce/static.d.ts.map +0 -1
  314. package/out/parser/string/shift/operand/date.d.ts.map +0 -1
  315. package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
  316. package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
  317. package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
  318. package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
  319. package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
  320. package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
  321. package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
  322. package/out/parser/string/shift/scanner.d.ts.map +0 -1
  323. package/out/parser/string/string.d.ts.map +0 -1
  324. package/out/parser/tuple.d.ts.map +0 -1
  325. package/out/schema.d.ts +0 -175
  326. package/out/schema.d.ts.map +0 -1
  327. package/out/schema.js +0 -73
  328. package/out/schema.js.map +0 -1
  329. package/out/schemaScope.d.ts +0 -180
  330. package/out/schemaScope.d.ts.map +0 -1
  331. package/out/schemaScope.js +0 -235
  332. package/out/schemaScope.js.map +0 -1
  333. package/out/scope.d.ts.map +0 -1
  334. package/out/shared/compile.d.ts +0 -22
  335. package/out/shared/compile.d.ts.map +0 -1
  336. package/out/shared/compile.js +0 -79
  337. package/out/shared/compile.js.map +0 -1
  338. package/out/shared/context.d.ts +0 -54
  339. package/out/shared/context.d.ts.map +0 -1
  340. package/out/shared/context.js +0 -53
  341. package/out/shared/context.js.map +0 -1
  342. package/out/shared/declare.d.ts +0 -69
  343. package/out/shared/declare.d.ts.map +0 -1
  344. package/out/shared/declare.js +0 -2
  345. package/out/shared/declare.js.map +0 -1
  346. package/out/shared/disjoint.d.ts +0 -91
  347. package/out/shared/disjoint.d.ts.map +0 -1
  348. package/out/shared/disjoint.js +0 -110
  349. package/out/shared/disjoint.js.map +0 -1
  350. package/out/shared/errors.d.ts +0 -99
  351. package/out/shared/errors.d.ts.map +0 -1
  352. package/out/shared/errors.js +0 -108
  353. package/out/shared/errors.js.map +0 -1
  354. package/out/shared/implement.d.ts +0 -363
  355. package/out/shared/implement.d.ts.map +0 -1
  356. package/out/shared/implement.js +0 -68
  357. package/out/shared/implement.js.map +0 -1
  358. package/out/shared/inference.d.ts +0 -6
  359. package/out/shared/inference.d.ts.map +0 -1
  360. package/out/shared/inference.js +0 -5
  361. package/out/shared/inference.js.map +0 -1
  362. package/out/shared/intersections.d.ts +0 -60
  363. package/out/shared/intersections.d.ts.map +0 -1
  364. package/out/shared/intersections.js +0 -2
  365. package/out/shared/intersections.js.map +0 -1
  366. package/out/shared/traversal.d.ts +0 -62
  367. package/out/shared/traversal.d.ts.map +0 -1
  368. package/out/shared/traversal.js +0 -97
  369. package/out/shared/traversal.js.map +0 -1
  370. package/out/shared/utils.d.ts +0 -24
  371. package/out/shared/utils.d.ts.map +0 -1
  372. package/out/shared/utils.js +0 -15
  373. package/out/shared/utils.js.map +0 -1
  374. package/out/type.d.ts.map +0 -1
  375. package/out/types/basis.d.ts +0 -47
  376. package/out/types/basis.d.ts.map +0 -1
  377. package/out/types/basis.js +0 -15
  378. package/out/types/basis.js.map +0 -1
  379. package/out/types/discriminate.d.ts +0 -34
  380. package/out/types/discriminate.d.ts.map +0 -1
  381. package/out/types/discriminate.js +0 -120
  382. package/out/types/discriminate.js.map +0 -1
  383. package/out/types/domain.d.ts +0 -57
  384. package/out/types/domain.d.ts.map +0 -1
  385. package/out/types/domain.js +0 -41
  386. package/out/types/domain.js.map +0 -1
  387. package/out/types/intersection.d.ts +0 -127
  388. package/out/types/intersection.d.ts.map +0 -1
  389. package/out/types/intersection.js +0 -379
  390. package/out/types/intersection.js.map +0 -1
  391. package/out/types/morph.d.ts +0 -157
  392. package/out/types/morph.d.ts.map +0 -1
  393. package/out/types/morph.js +0 -99
  394. package/out/types/morph.js.map +0 -1
  395. package/out/types/proto.d.ts +0 -51
  396. package/out/types/proto.d.ts.map +0 -1
  397. package/out/types/proto.js +0 -60
  398. package/out/types/proto.js.map +0 -1
  399. package/out/types/type.d.ts +0 -143
  400. package/out/types/type.d.ts.map +0 -1
  401. package/out/types/type.js +0 -123
  402. package/out/types/type.js.map +0 -1
  403. package/out/types/union.d.ts +0 -71
  404. package/out/types/union.d.ts.map +0 -1
  405. package/out/types/union.js +0 -379
  406. package/out/types/union.js.map +0 -1
  407. package/out/types/unit.d.ts +0 -45
  408. package/out/types/unit.d.ts.map +0 -1
  409. package/out/types/unit.js +0 -56
  410. package/out/types/unit.js.map +0 -1
  411. package/out/util.d.ts +0 -31
  412. package/out/util.d.ts.map +0 -1
  413. package/out/util.js +0 -8
  414. package/out/util.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { attest, contextualize } from "@arktype/attest"
2
- import { reference } from "@arktype/util"
2
+ import { printable, registeredReference } from "@arktype/util"
3
3
  import { type } from "arktype"
4
4
 
5
5
  contextualize(
@@ -11,28 +11,44 @@ contextualize(
11
11
  attest(t.json).equals(type("5").json)
12
12
  })
13
13
 
14
- it("non-serializable", () => {
15
- const s = Symbol()
16
- const t = type(["===", s])
14
+ it("symbol with description", () => {
15
+ // if another symbol with the description "ism" is used in a test,
16
+ // the snapshotted errors below could break, but I want to test the
17
+ // actual display format.
18
+ // if you're here for that reason, choose another symbol name :P
19
+ const ism = Symbol("ism")
20
+ const t = type(["===", ism])
21
+ attest(t(ism)).equals(ism)
22
+
23
+ // same with ick- don't use it
24
+ const ick = Symbol("ick")
25
+
26
+ attest(t(ick).toString()).snap("must be Symbol(ism) (was Symbol(ick))")
27
+ })
28
+
29
+ it("anonymous symbol", () => {
30
+ const anon = Symbol()
31
+ // An anonymous symbol will definitely have a suffix so we need to
32
+ // get the name ahead of time
33
+ const anonName = printable(anon)
34
+ const t = type(["===", anon])
17
35
  attest<symbol>(t.infer)
18
- attest(t(s).out).equals(s)
19
- attest(t("test").errors?.summary).snap(
20
- 'must be (symbol anonymous) (was "test")'
21
- )
36
+ attest(t(anon)).equals(anon)
37
+ attest(t("test").toString()).equals(`must be ${anonName} (was "test")`)
22
38
  })
23
39
 
24
40
  it("branches", () => {
25
41
  const o = { ark: true }
26
- const oReference = reference(o)
42
+ const oReference = registeredReference(o)
27
43
  const s = Symbol()
28
- const sReference = reference(s)
44
+ const sReference = registeredReference(s)
29
45
  const t = type(["===", true, "foo", 5, 1n, null, undefined, o, s])
30
46
  attest<
31
47
  true | "foo" | 5 | 1n | null | undefined | { ark: boolean } | typeof s
32
48
  >(t.infer)
33
49
  attest(t.json).equals([
34
- { unit: sReference },
35
50
  { unit: oReference },
51
+ { unit: sReference },
36
52
  { unit: "1n" },
37
53
  { unit: "foo" },
38
54
  { unit: "undefined" },
@@ -52,16 +68,16 @@ contextualize(
52
68
 
53
69
  it("branches", () => {
54
70
  const o = { ark: true }
55
- const oReference = reference(o)
71
+ const oReference = registeredReference(o)
56
72
  const s = Symbol()
57
- const sReference = reference(s)
73
+ const sReference = registeredReference(s)
58
74
  const t = type("===", "foo", 5, true, null, 1n, undefined, o, s)
59
75
  attest<
60
76
  true | "foo" | 5 | 1n | null | undefined | { ark: boolean } | typeof s
61
77
  >(t.infer)
62
78
  attest(t.json).equals([
63
- { unit: sReference },
64
79
  { unit: oReference },
80
+ { unit: sReference },
65
81
  { unit: "1n" },
66
82
  { unit: "foo" },
67
83
  { unit: "undefined" },
@@ -3,9 +3,9 @@ import { match } from "arktype"
3
3
 
4
4
  bench("general matchers", () => {
5
5
  const matcher = match()
6
- .when("string", (s) => s)
7
- .when("number", (n) => n)
8
- .when("boolean", (b) => b)
6
+ .when("string", s => s)
7
+ .when("number", n => n)
8
+ .when("boolean", b => b)
9
9
  .orThrow()
10
10
 
11
11
  const a = matcher("abc")
@@ -18,9 +18,9 @@ bench("general matchers", () => {
18
18
  bench("match.only<T>", () => {
19
19
  const matcher = match
20
20
  .only<string | number | boolean>()
21
- .when("string", (s) => s)
22
- .when("number", (n) => n)
23
- .when("boolean", (b) => b)
21
+ .when("string", s => s)
22
+ .when("number", n => n)
23
+ .when("boolean", b => b)
24
24
  .finalize()
25
25
 
26
26
  const a = matcher("abc")
@@ -1,24 +1,22 @@
1
1
  import { attest, contextualize } from "@arktype/attest"
2
2
  import type { Narrowed, Out, of, string } from "@arktype/schema"
3
- import { type equals, reference } from "@arktype/util"
4
- import { type Type, type } from "arktype"
3
+ import { registeredReference, type equals } from "@arktype/util"
4
+ import { type, type Type } from "arktype"
5
5
 
6
6
  contextualize(() => {
7
7
  it("implicit problem", () => {
8
8
  const isOdd = (n: number) => n % 2 === 1
9
- const isOddRef = reference(isOdd)
9
+ const isOddRef = registeredReference(isOdd)
10
10
  const odd = type(["number", ":", isOdd])
11
11
  attest<number>(odd.infer)
12
12
  attest(odd.json).equals({ domain: "number", predicate: [isOddRef] })
13
- attest(odd(1).out).equals(1)
14
- attest(odd(2).errors?.summary).snap(
15
- "must be valid according to isOdd (was 2)"
16
- )
13
+ attest(odd(1)).equals(1)
14
+ attest(odd(2).toString()).snap("must be valid according to isOdd (was 2)")
17
15
  })
18
16
 
19
17
  it("implicit problem anonymous", () => {
20
- const even = type("number", ":", (n) => n % 2 === 0)
21
- attest(even(1).errors?.summary).snap(
18
+ const even = type("number", ":", n => n % 2 === 0)
19
+ attest(even(1).toString()).snap(
22
20
  "must be valid according to an anonymous predicate (was 1)"
23
21
  )
24
22
  })
@@ -27,9 +25,9 @@ contextualize(() => {
27
25
  const even = type([
28
26
  "number",
29
27
  ":",
30
- (n, ctx) => n % 3 === 0 || ctx.invalid({ expected: "divisible by 3" })
28
+ (n, ctx) => n % 3 === 0 || ctx.invalid("divisible by 3")
31
29
  ])
32
- attest(even(1).errors?.summary).snap("must be divisible by 3 (was 1)")
30
+ attest(even(1).toString()).snap("must be divisible by 3 (was 1)")
33
31
  })
34
32
 
35
33
  it("problem at path", () => {
@@ -40,16 +38,15 @@ contextualize(() => {
40
38
  },
41
39
  ":",
42
40
  ({ a, b }, ctx) => {
43
- if (a === b) {
44
- return true
45
- }
41
+ if (a === b) return true
42
+
46
43
  ctx.error({ expected: "equal to b", path: ["a"] })
47
44
  ctx.error({ expected: "equal to a", path: ["b"] })
48
45
  return false
49
46
  }
50
47
  ])
51
- attest(abEqual({ a: 1, b: 1 }).out).equals({ a: 1, b: 1 })
52
- attest(abEqual({ a: 1, b: 2 }).errors?.summary).snap(
48
+ attest(abEqual({ a: 1, b: 1 })).equals({ a: 1, b: 1 })
49
+ attest(abEqual({ a: 1, b: 2 }).toString()).snap(
53
50
  'a must be equal to b (was {"a":1,"b":2})\nb must be equal to a (was {"a":1,"b":2})'
54
51
  )
55
52
  })
@@ -65,11 +62,8 @@ contextualize(() => {
65
62
  t: equals<t, Expected> extends true ? t : Expected
66
63
  ) => true
67
64
  attest<number | boolean[]>(
68
- type([
69
- "number|boolean[]",
70
- ":",
71
- (data) => validateNumberOrBooleanList(data)
72
- ]).infer
65
+ type(["number|boolean[]", ":", data => validateNumberOrBooleanList(data)])
66
+ .infer
73
67
  )
74
68
  attest(() => {
75
69
  // @ts-expect-error
@@ -85,15 +79,15 @@ contextualize(() => {
85
79
  s === [...s].reverse().join("") ? true : ctx.invalid("a palindrome")
86
80
  ])
87
81
  attest<Type<string.narrowed>>(palindrome)
88
- attest(palindrome("dad").out).snap("dad")
89
- attest(palindrome("david").errors?.summary).snap(
82
+ attest(palindrome("dad")).snap("dad")
83
+ attest(palindrome("david").toString()).snap(
90
84
  'must be a palindrome (was "david")'
91
85
  )
92
86
  })
93
87
 
94
88
  it("narrows the output type of a morph", () => {
95
89
  const t = type("string")
96
- .morph((s) => s.length)
90
+ .pipe(s => s.length)
97
91
  .narrow((n): n is 5 => n === 5)
98
92
 
99
93
  attest<Type<(In: string) => Out<of<5, Narrowed>>, {}>>(t)
@@ -4,7 +4,7 @@ import {
4
4
  writeUnboundableMessage,
5
5
  writeUnresolvableMessage
6
6
  } from "@arktype/schema"
7
- import { printable, reference } from "@arktype/util"
7
+ import { printable, registeredReference } from "@arktype/util"
8
8
  import { scope, type } from "arktype"
9
9
  import { writeInvalidSpreadTypeMessage } from "../parser/objectLiteral.js"
10
10
 
@@ -42,7 +42,7 @@ contextualize(
42
42
 
43
43
  it("symbol key", () => {
44
44
  const s = Symbol()
45
- const name = reference(s)
45
+ const name = registeredReference(s)
46
46
  const t = type({
47
47
  [s]: "string"
48
48
  })
@@ -89,19 +89,26 @@ contextualize(
89
89
  attest<{ "a?": string }>(t.infer)
90
90
  })
91
91
 
92
- // TODO: reenable
93
- // it("traverse optional", () => {
94
- // const o = type({ "a?": "string" }).configure({ keys: "strict" })
95
- // attest(o({ a: "a" }).out).snap({ a: "a" })
96
- // attest(o({}).out).snap({})
97
- // attest(o({ a: 1 }).errors?.summary).snap("a must be a string (was number)")
92
+ it("traverse optional", () => {
93
+ const o = type({ "a?": "string" })
94
+ attest(o({ a: "a" })).snap({ a: "a" })
95
+ attest(o({})).snap({})
96
+ attest(o({ a: 1 }).toString()).snap("a must be a string (was number)")
97
+ })
98
+
99
+ // it("traverse strict optional", () => {
100
+ // // TODO: strict
101
+ // const o = type({ "a?": "string" })
102
+ // attest(o({ a: "a" })).snap({ a: "a" })
103
+ // attest(o({})).snap({})
104
+ // attest(o({ a: 1 }).toString()).snap("a must be a string (was number)")
98
105
  // })
99
106
 
100
107
  // it("multiple bad strict", () => {
101
108
  // const t = type({ a: "string", b: "boolean" }).configure({
102
109
  // keys: "strict"
103
110
  // })
104
- // attest(t({ a: 1, b: 2 }).errors?.summary).snap(
111
+ // attest(t({ a: 1, b: 2 }).toString()).snap(
105
112
  // "a must be a string (was number)\nb must be boolean (was number)"
106
113
  // )
107
114
  // })
@@ -217,19 +224,75 @@ contextualize(
217
224
  },
218
225
  "index",
219
226
  () => {
220
- it("index", () => {
227
+ it("string index", () => {
221
228
  const o = type({ "[string]": "string" })
222
229
  attest<{ [x: string]: string }>(o.infer)
230
+ attest(o.json).snap({
231
+ domain: "object",
232
+ index: [{ key: "string", value: "string" }]
233
+ })
234
+
235
+ attest(o({})).equals({})
236
+ attest(o({ a: "a", b: "b" })).equals({ a: "a", b: "b" })
237
+
238
+ const validWithSymbol = { a: "a", [Symbol()]: null }
239
+ attest(validWithSymbol).equals(validWithSymbol)
240
+
241
+ attest(o({ a: 1 }).toString()).snap("a must be a string (was number)")
242
+ attest(o({ a: true, b: false }).toString())
243
+ .snap(`a must be a string (was true)
244
+ b must be a string (was false)`)
245
+ })
246
+
247
+ it("symbol index", () => {
248
+ const o = type({ "[symbol]": "1" })
249
+ attest<{ [x: symbol]: 1 }>(o.infer)
250
+ attest(o.json).snap({
251
+ domain: "object",
252
+ index: [{ key: "symbol", value: { unit: 1 } }]
253
+ })
254
+
255
+ attest(o({})).equals({})
256
+
257
+ attest(o({ a: 999 })).unknown.snap({ a: 999 })
258
+
259
+ const zildjian = Symbol()
260
+ const zildjianName = printable(zildjian)
261
+
262
+ // I've been dope, suspenseful with a pencil
263
+ // Ever since...
264
+ const prince = Symbol()
265
+ const princeName = printable(prince)
266
+
267
+ attest(o({ [zildjian]: 1, [prince]: 1 })).equals({
268
+ [zildjian]: 1,
269
+ [prince]: 1
270
+ })
271
+
272
+ attest({ a: 0, [zildjian]: 1 }).equals({ a: 0, [zildjian]: 1 })
273
+
274
+ attest(o({ [zildjian]: 0 }).toString()).equals(
275
+ `value at [${zildjianName}] must be 1 (was 0)`
276
+ )
277
+ attest(o({ [prince]: null, [zildjian]: undefined }).toString())
278
+ .snap(`value at [${princeName}] must be 1 (was null)
279
+ value at [${zildjianName}] must be 1 (was undefined)`)
223
280
  })
224
281
 
225
282
  it("enumerable indexed union", () => {
226
283
  const o = type({ "['foo' | 'bar']": "string" })
227
- attest<{ foo: string; bar: string }>(o.infer)
284
+ const expected = type({ foo: "string", bar: "string" })
285
+ attest<typeof expected>(o)
286
+ attest(o.json).equals(expected.json)
228
287
  })
229
288
 
230
289
  it("non-enumerable indexed union", () => {
231
290
  const o = type({ "[string | symbol]": "string" })
232
291
  attest<{ [x: string]: string; [x: symbol]: string }>(o.infer)
292
+ attest(o.json).snap({
293
+ domain: "object",
294
+ index: [{ key: ["string", "symbol"], value: "string" }]
295
+ })
233
296
  })
234
297
 
235
298
  it("multiple indexed", () => {
@@ -238,6 +301,35 @@ contextualize(
238
301
  "[symbol]": "number"
239
302
  })
240
303
  attest<{ [x: string]: string; [x: symbol]: number }>(o.infer)
304
+ attest(o.json).snap({
305
+ domain: "object",
306
+ index: [
307
+ { key: "string", value: "string" },
308
+ { key: "symbol", value: "number" }
309
+ ]
310
+ })
311
+
312
+ attest(o({})).equals({})
313
+ attest(o({ foo: "f" })).equals({ foo: "f" })
314
+
315
+ const sym = Symbol()
316
+
317
+ const symName = printable(sym)
318
+
319
+ const validWithStringsAndSymbols = {
320
+ str: "string",
321
+ [sym]: 8675309
322
+ }
323
+
324
+ attest(o(validWithStringsAndSymbols)).equals(validWithStringsAndSymbols)
325
+
326
+ attest(
327
+ o({
328
+ str: 100,
329
+ [sym]: "💯"
330
+ }).toString()
331
+ ).snap(`str must be a string (was number)
332
+ value at [${symName}] must be a number (was string)`)
241
333
  })
242
334
 
243
335
  it("all key kinds", () => {
@@ -249,6 +341,25 @@ contextualize(
249
341
  attest<{ [x: string]: string; required: "foo"; optional?: "bar" }>(
250
342
  o.infer
251
343
  )
344
+ attest(o.json).snap({
345
+ domain: "object",
346
+ prop: [
347
+ { key: "optional", optional: true, value: { unit: "bar" } },
348
+ { key: "required", value: { unit: "foo" } }
349
+ ],
350
+ index: [{ key: "string", value: "string" }]
351
+ })
352
+
353
+ const valid: typeof o.infer = { required: "foo", other: "bar" }
354
+ attest(o(valid)).equals(valid)
355
+ attest(
356
+ o({
357
+ optional: "wrongString",
358
+ other: 0n
359
+ }).toString()
360
+ ).snap(`optional must be "bar" (was "wrongString")
361
+ required must be "foo" (was missing)
362
+ other must be a string (was bigint)`)
252
363
  })
253
364
 
254
365
  it("index key from scope", () => {
@@ -261,6 +372,14 @@ contextualize(
261
372
  type Key = symbol | "foo" | "bar" | "baz"
262
373
  attest<Key>(types.key.infer)
263
374
  attest<Record<Key, string>>(types.obj.infer)
375
+
376
+ const expected = type({ "[symbol]": "string" }).and({
377
+ foo: "string",
378
+ bar: "string",
379
+ baz: "string"
380
+ })
381
+
382
+ attest(types.obj.json).snap(expected.json)
264
383
  })
265
384
 
266
385
  it("syntax error in index definition", () => {
@@ -314,6 +433,10 @@ contextualize(
314
433
  it("escaped index", () => {
315
434
  const o = type({ "\\[string]": "string" })
316
435
  attest<{ "[string]": string }>(o.infer)
436
+ attest(o.json).snap({
437
+ domain: "object",
438
+ prop: [{ key: "[string]", value: "string" }]
439
+ })
317
440
  })
318
441
  }
319
442
  )
@@ -106,25 +106,25 @@ bench("divisor", () => {
106
106
  .types([1023, "instantiations"])
107
107
 
108
108
  bench("filter-tuple", () => {
109
- const _ = type(["boolean", ":", (b) => b])
109
+ const _ = type(["boolean", ":", b => b])
110
110
  })
111
111
  .median([8.04, "us"])
112
112
  .types([583, "instantiations"])
113
113
 
114
114
  bench("filter-chain", () => {
115
- const _ = type("boolean").narrow((b) => b)
115
+ const _ = type("boolean").narrow(b => b)
116
116
  })
117
117
  .median([12.19, "us"])
118
118
  .types([42, "instantiations"])
119
119
 
120
120
  bench("morph-tuple", () => {
121
- const _ = type(["boolean", "=>", (b) => b])
121
+ const _ = type(["boolean", "=>", b => b])
122
122
  })
123
123
  .median([8.96, "us"])
124
124
  .types([562, "instantiations"])
125
125
 
126
126
  bench("morph-chain", () => {
127
- const _ = type("boolean").morph((b) => b)
127
+ const _ = type("boolean").pipe(b => b)
128
128
  })
129
129
  .median([2.98, "us"])
130
130
  .types([26, "instantiations"])