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
@@ -13,11 +13,11 @@ describe("config traversal", () => {
13
13
  attest<string>(types.a.infer)
14
14
  attest(types.a.description).equals(description)
15
15
  attest(types.a(1).errors?.summary).snap(
16
- "Must be a series of characters (was number)"
16
+ "must be a series of characters (was number)"
17
17
  )
18
18
  attest<{ a: string }>(types.b.infer)
19
19
  attest(types.b({ a: true }).errors?.summary).snap(
20
- "a must be a series of characters (was boolean)"
20
+ "a must be a series of characters (was true)"
21
21
  )
22
22
  })
23
23
  it("tuple expression at path", () => {
@@ -26,7 +26,9 @@ describe("config traversal", () => {
26
26
  monster: ["196883", "@", description]
27
27
  })
28
28
  attest<{ monster: 196883 }>(t.infer)
29
- attest(t.description).equals(description)
29
+ attest(t.description).snap(
30
+ "{ monster: the number of dimensions in the monster group }"
31
+ )
30
32
  attest(t({ monster: 196882 }).errors?.summary).snap(
31
33
  "monster must be the number of dimensions in the monster group (was 196882)"
32
34
  )
@@ -34,7 +36,7 @@ describe("config traversal", () => {
34
36
  it("anonymous type config", () => {
35
37
  const t = type(type("true", "@", { description: "unfalse" }))
36
38
  attest<true>(t.infer)
37
- attest(t(false).errors?.summary).snap("Must be unfalse (was false)")
39
+ attest(t(false).errors?.summary).snap("must be unfalse (was false)")
38
40
  })
39
41
  it("anonymous type config at path", () => {
40
42
  const unfalse = type("true", "@", { description: "unfalse" })
@@ -69,9 +71,9 @@ describe("config traversal", () => {
69
71
  name: "david",
70
72
  age: true
71
73
  }).errors?.summary
72
- ).snap("age must be a number (was boolean)")
74
+ ).snap("age must be a number (was true)")
73
75
 
74
76
  // should give the shallow custom error
75
- attest(user(null).errors?.summary).snap("Must be a valid user (was null)")
77
+ attest(user(null).errors?.summary).snap("must be a valid user (was null)")
76
78
  })
77
79
  })
@@ -97,7 +97,7 @@ describe("cyclic", () => {
97
97
  (p) => !p.dependencies?.some((d) => d.name === p.name)
98
98
  ])
99
99
  attest(nonSelfDependent(data).errors?.summary).snap(
100
- 'Must be valid (was {"name":"arktype","dependencies":[{"name":"typescript"},"(cycle)"],"contributors":[{"email":"david@arktype.io"}]})'
100
+ 'must be valid (was {"name":"arktype","dependencies":[{"name":"typescript"},"(cycle)"],"contributors":[{"email":"david@arktype.io"}]})'
101
101
  )
102
102
  })
103
103
 
@@ -8,7 +8,7 @@ describe("date literal", () => {
8
8
  attest<Date>(t.infer)
9
9
  attest(t.allows(new Date("2000/05/05"))).equals(true)
10
10
  attest(t.allows(new Date("2000/06/05"))).equals(false)
11
- attest(t.allows(new Date("2000/05/05T09:00:00.00Z"))).equals(false)
11
+ attest(t.allows(new Date("2000-05-05T09:00:00.000Z"))).equals(false)
12
12
  })
13
13
  it("with punctuation", () => {
14
14
  const ISO = type("d'2000-05-05T04:00:00.000Z'")
@@ -24,7 +24,7 @@ describe("date literal", () => {
24
24
  const now = new Date()
25
25
  const t = type(`d'${now.valueOf()}'`)
26
26
  attest(t.allows(now)).equals(true)
27
- attest(t.allows(new Date(now.valueOf() + 1)))
27
+ attest(t.allows(new Date(now.valueOf() + 1))).equals(false)
28
28
  })
29
29
  it("invalid date", () => {
30
30
  attest(() => type("d'tuesday'")).throws(writeInvalidDateMessage("tuesday"))
@@ -52,7 +52,7 @@ describe("discrimination", () => {
52
52
  // duration: "'s' | 'min' | 'h'",
53
53
  // operator: "'to'"
54
54
  // })
55
- // attest(t.root.hasKind("union") && t.root.discriminant).equals(null)
55
+ // attest(t.hasKind("union") && t.discriminant).equals(null)
56
56
  // })
57
57
  // it("default case", () => {
58
58
  // const t = getPlaces().type([
@@ -1,6 +1,7 @@
1
1
  import { attest } from "@arktype/attest"
2
- import { writeIndivisibleMessage } from "@arktype/schema"
3
2
  import { type } from "arktype"
3
+ import { writeIndivisibleMessage } from "../constraints/refinements/divisor.js"
4
+ import { keywords } from "../keywords/ark.js"
4
5
  import { writeInvalidDivisorMessage } from "../parser/string/shift/operator/divisor.js"
5
6
 
6
7
  describe("divisibility", () => {
@@ -8,22 +9,25 @@ describe("divisibility", () => {
8
9
  it("integer literal", () => {
9
10
  const divisibleByTwo = type("number%2")
10
11
  attest<number>(divisibleByTwo.infer)
11
- attest(divisibleByTwo.json).snap({ basis: "number", divisor: 2 })
12
- attest(divisibleByTwo(4).out).snap(4)
13
- attest(divisibleByTwo(5).errors?.summary).snap(
14
- "Must be a multiple of 2 (was 5)"
15
- )
12
+ attest(divisibleByTwo.json).snap({ domain: "number", divisor: 2 })
13
+ })
14
+ it("chained", () => {
15
+ const t = type("number").constrain("divisor", 2)
16
+ const expected = type("number%2")
17
+ attest<typeof expected>(t)
18
+ attest(t.json).equals(expected.json)
16
19
  })
17
20
  it("whitespace after %", () => {
18
21
  const t = type("number % 5")
19
22
  attest<number>(t.infer)
20
- attest(t.json).snap({ basis: "number", divisor: 5 })
21
- })
22
- it("with bound", () => {
23
- const t = type("number%8<3")
24
- attest(t.json).equals(type("number%8").and("number<3").json)
25
- attest(t.root.description).snap(
26
- "a number and a multiple of 8 and less than 3"
23
+ attest(t.json).snap({ domain: "number", divisor: 5 })
24
+ })
25
+ it("with bounds", () => {
26
+ const t = type("7<number%8<222")
27
+ const expected = type("number%8").and("7<number<222")
28
+ attest(t.json).equals(expected.json)
29
+ attest(t.description).snap(
30
+ "a number and a multiple of 8 and less than 222 and more than 7"
27
31
  )
28
32
  })
29
33
  it("allows non-narrowed divisor", () => {
@@ -48,20 +52,20 @@ describe("divisibility", () => {
48
52
  it("unknown", () => {
49
53
  // @ts-expect-error
50
54
  attest(() => type("unknown%2")).throwsAndHasTypeError(
51
- writeIndivisibleMessage("unknown")
55
+ writeIndivisibleMessage(keywords.unknown)
52
56
  )
53
57
  })
54
58
  it("indivisible", () => {
55
59
  // @ts-expect-error
56
60
  attest(() => type("string%1")).throwsAndHasTypeError(
57
- writeIndivisibleMessage("string")
61
+ writeIndivisibleMessage(keywords.string)
58
62
  )
59
63
  })
60
64
  it("overlapping", () => {
61
65
  // @ts-expect-error
62
- attest(() => type("(number|string)%10"))
63
- .throws("Divisibility operand string must be a number")
64
- .type.errors("Divisibility operand number | string must be a number")
66
+ attest(() => type("(number|string)%10")).throwsAndHasTypeError(
67
+ writeIndivisibleMessage(keywords.number.or(keywords.string))
68
+ )
65
69
  })
66
70
  })
67
71
  describe("intersection", () => {
@@ -87,7 +91,7 @@ describe("divisibility", () => {
87
91
  })
88
92
  it("invalid literal", () => {
89
93
  attest(() => type("number%3&8")).throws.snap(
90
- "Error: Intersection of 8 and a number and a multiple of 3 results in an unsatisfiable type"
94
+ "ParseError: Intersection of 8 and number & % 3 results in an unsatisfiable type"
91
95
  )
92
96
  })
93
97
  })
@@ -11,7 +11,10 @@ describe("parse enclosed", () => {
11
11
  it("with neighbors", () => {
12
12
  const t = type("'foo'|/.*/[]")
13
13
  attest<"foo" | string[]>(t.infer)
14
- attest(t.json).snap([{ unit: "foo" }, { basis: "Array" }])
14
+ attest(t.json).snap([
15
+ { proto: "Array", sequence: { domain: "string", regex: [".*"] } },
16
+ { unit: "foo" }
17
+ ])
15
18
  })
16
19
  describe("errors", () => {
17
20
  describe("unterminated", () => {
@@ -36,7 +39,9 @@ describe("parse enclosed", () => {
36
39
  })
37
40
  })
38
41
  it("single-quoted", () => {
39
- attest<"hello">(type("'hello'").infer)
42
+ const t = type("'hello'")
43
+ attest<"hello">(t.infer)
44
+ attest(t.json).snap({ unit: "hello" })
40
45
  })
41
46
  it("double-quoted", () => {
42
47
  attest<"goodbye">(type('"goodbye"').infer)
@@ -0,0 +1,115 @@
1
+ import { attest } from "@arktype/attest"
2
+ import { scope } from "arktype"
3
+ import { configure } from "../config.js"
4
+ import { node } from "../keywords/ark.js"
5
+ import { defaultConfig } from "../scope.js"
6
+
7
+ describe("errors", () => {
8
+ it("shallow", () => {
9
+ const n = node({
10
+ domain: "number",
11
+ divisor: 3
12
+ })
13
+ attest(n(6)).snap({ data: 6, out: 6 })
14
+ attest(n(7).errors?.summary).snap("must be a multiple of 3 (was 7)")
15
+ })
16
+ it("at path", () => {
17
+ const o = node({
18
+ domain: "object",
19
+ prop: {
20
+ key: "foo",
21
+ value: {
22
+ domain: "number",
23
+ divisor: 3
24
+ }
25
+ }
26
+ })
27
+ attest(o({ foo: 6 }).out).snap({ foo: 6 })
28
+ attest(o({ foo: 7 }).errors?.summary).snap(
29
+ "foo must be a multiple of 3 (was 7)"
30
+ )
31
+ })
32
+ it("array", () => {
33
+ const t = node({
34
+ proto: Array,
35
+ sequence: "number"
36
+ })
37
+ attest(t([5]).out).snap([5])
38
+ attest(t([5, "five"]).errors?.summary).snap(
39
+ "value at [1] must be a number (was string)"
40
+ )
41
+ })
42
+ it("custom description integrated with error", () => {
43
+ const superSpecialBigint = node({
44
+ domain: "bigint",
45
+ description: "my special bigint"
46
+ })
47
+ attest(superSpecialBigint.description).snap("my special bigint")
48
+ attest(superSpecialBigint(5).errors?.summary).snap(
49
+ "must be my special bigint (was number)"
50
+ )
51
+ })
52
+ it("custom description on parent doesn't affect children", () => {
53
+ const evenNumber = node({
54
+ domain: "number",
55
+ divisor: 2,
56
+ description: "an even number"
57
+ })
58
+ attest(evenNumber.description).snap("an even number")
59
+ // since the error is from the divisor constraint which didn't have a
60
+ // description, it is unchanged
61
+ attest(evenNumber(5).errors?.summary).snap(
62
+ "must be a multiple of 2 (was 5)"
63
+ )
64
+ })
65
+ it("can configure errors by kind at a scope level", () => {
66
+ const types = scope(
67
+ { superSpecialString: "string" },
68
+ {
69
+ domain: {
70
+ expected: (inner) => `custom expected ${inner.domain}`,
71
+ actual: (data) => `custom actual ${data}`,
72
+ problem: (ctx) => `custom problem ${ctx.expected} ${ctx.actual}`,
73
+ message: (ctx) => `custom message ${ctx.problem}`
74
+ }
75
+ }
76
+ ).export()
77
+ const superSpecialString = types.superSpecialString
78
+ attest(superSpecialString(5).errors?.summary).snap(
79
+ "custom message custom problem custom expected string custom actual 5"
80
+ )
81
+ })
82
+ it("can configure description by kind at scope level", () => {
83
+ const types = scope(
84
+ { superSpecialNumber: "number" },
85
+ {
86
+ domain: {
87
+ description: (inner) => `my special ${inner.domain}`
88
+ }
89
+ }
90
+ ).export()
91
+ const superSpecialNumber = types.superSpecialNumber
92
+ attest(superSpecialNumber.description).snap("my special number")
93
+ attest(superSpecialNumber("five").errors?.summary).snap(
94
+ "must be my special number (was string)"
95
+ )
96
+ })
97
+ it("can apply a global config", () => {
98
+ configure({
99
+ domain: {
100
+ description: (inner) => `my special ${inner.domain}`
101
+ }
102
+ })
103
+ const mySpecialSymbol = scope({}).node("symbol")
104
+ attest(mySpecialSymbol("foo").errors?.summary).snap(
105
+ "must be my special symbol (was string)"
106
+ )
107
+ configure({
108
+ domain: defaultConfig.domain
109
+ })
110
+ const myBoringSymbol = scope({}).node("symbol")
111
+ attest(myBoringSymbol("foo").errors?.summary).snap(
112
+ "must be a symbol (was string)"
113
+ )
114
+ })
115
+ })
@@ -1,12 +1,11 @@
1
1
  import { attest } from "@arktype/attest"
2
- import { schema } from "@arktype/schema"
3
- import { type, type Out } from "arktype"
4
- import { scope, type Ark } from "../ark.js"
2
+ import { scope, type, type Ark, type Out } from "arktype"
3
+ import { node } from "../keywords/ark.js"
5
4
  import {
6
5
  writeMissingRightOperandMessage,
7
6
  writeUnresolvableMessage
8
7
  } from "../parser/string/shift/operand/unenclosed.js"
9
- import type { Type } from "../type.js"
8
+ import type { Type } from "../types/type.js"
10
9
 
11
10
  describe("tuple expressions", () => {
12
11
  it("nested", () => {
@@ -15,13 +14,9 @@ describe("tuple expressions", () => {
15
14
  })
16
15
  it("autocompletion", () => {
17
16
  // @ts-expect-error
18
- attest(() => type([""])).type.errors(
19
- `IndexZeroOperator | keyof Ark | "this"`
20
- )
17
+ attest(() => type([""])).completions()
21
18
  // @ts-expect-error
22
- attest(() => type(["string", ""])).type.errors(
23
- `"keyof" | keyof Ark | "this" | IndexOneOperator'`
24
- )
19
+ attest(() => type(["string", ""])).completions()
25
20
  })
26
21
  describe("errors", () => {
27
22
  it("missing right operand", () => {
@@ -75,17 +70,19 @@ describe("root expression", () => {
75
70
  it("=== branches", () => {
76
71
  const t = type("===", "foo", "bar", "baz")
77
72
  attest<"foo" | "bar" | "baz">(t.infer)
78
- attest(t.json).equals(schema.units("foo", "bar", "baz").json)
73
+ attest(t.json).snap([{ unit: "bar" }, { unit: "baz" }, { unit: "foo" }])
79
74
  })
80
75
  it("instanceof single", () => {
81
76
  const t = type("instanceof", RegExp)
82
77
  attest<RegExp>(t.infer)
83
- attest(t.json).equals(schema(RegExp).json)
78
+ const expected = node(RegExp)
79
+ attest(t.json).equals(expected.json)
84
80
  })
85
81
  it("instanceof branches", () => {
86
82
  const t = type("instanceof", Array, Date)
87
83
  attest<unknown[] | Date>(t.infer)
88
- attest(t.json).equals(schema(Array, Date).json)
84
+ const expected = node([Array, Date])
85
+ attest(t.json).equals(expected.json)
89
86
  })
90
87
  it("postfix", () => {
91
88
  const t = type({ a: "string" }, "[]")
@@ -127,12 +124,9 @@ describe("root expression", () => {
127
124
  it("tuple as second arg", () => {
128
125
  // this case is not fundamentally unique but TS has a hard time
129
126
  // narrowing tuples in contexts like this
130
- const t = type("keyof", [
131
- { a: "string" },
132
- "&",
133
- { b: "boolean" }
134
- // as const is required for TS <=5.0
135
- ] as const)
136
- attest<"a" | "b">(t.infer)
127
+ const t = type("keyof", [{ a: "string" }, "&", { b: "boolean" }])
128
+ const expected = type("'a' | 'b'")
129
+ attest<typeof expected.infer>(t.infer)
130
+ attest(t.json).equals(expected.json)
137
131
  })
138
132
  })
@@ -1,8 +1,7 @@
1
1
  import { attest } from "@arktype/attest"
2
- import { writeIndivisibleMessage } from "@arktype/schema"
3
2
  import { lazily } from "@arktype/util"
4
- import { scope, type } from "arktype"
5
- import { arktypes } from "../ark.js"
3
+ import { keywords, scope, type } from "arktype"
4
+ import { writeIndivisibleMessage } from "../constraints/refinements/divisor.js"
6
5
  import { emptyGenericParameterMessage } from "../parser/generic.js"
7
6
  import { writeUnclosedGroupMessage } from "../parser/string/reduce/shared.js"
8
7
  import { writeInvalidGenericArgsMessage } from "../parser/string/shift/operand/genericArgs.js"
@@ -281,13 +280,13 @@ describe("generics", () => {
281
280
  attest(() =>
282
281
  // @ts-expect-error
283
282
  $.type("box<1,string%2>")
284
- ).throwsAndHasTypeError(writeIndivisibleMessage("string"))
283
+ ).throwsAndHasTypeError(writeIndivisibleMessage(keywords.string))
285
284
  })
286
285
  })
287
286
  })
288
287
  describe("builtins", () => {
289
288
  it("record", () => {
290
- const t = arktypes.Record("string", "number")
289
+ const t = keywords.Record("string", "number")
291
290
  attest(t.json).equals(type("Record<string, number>").json)
292
291
  })
293
292
  })
@@ -8,11 +8,16 @@ import { writeExpressionExpectedMessage } from "../parser/string/shift/operand/u
8
8
 
9
9
  describe("group", () => {
10
10
  it("entire expression", () => {
11
- attest<string>(type("(string)").infer)
11
+ const t = type("(string)")
12
+ const expected = type("string")
13
+ attest<typeof expected>(t)
14
+ attest(t.json).equals(expected.json)
12
15
  })
13
16
  it("overrides default precedence", () => {
14
- attest<boolean | number[]>(type("boolean|number[]").infer)
15
- attest<(boolean | number)[]>(type("(boolean|number)[]").infer)
17
+ const t = type("(boolean|number)[]")
18
+ const expected = type("boolean|number").array()
19
+ attest<typeof expected>(t)
20
+ attest(t.json).equals(expected.json)
16
21
  })
17
22
  it("nested", () => {
18
23
  attest<((number | boolean)[] | (string | undefined)[])[]>(
@@ -1,19 +1,19 @@
1
1
  import { attest } from "@arktype/attest"
2
- import { schema } from "@arktype/schema"
3
2
  import { type } from "arktype"
4
- import type { Ark } from "../ark.js"
3
+ import { node, type Ark } from "../keywords/ark.js"
5
4
  import { writeInvalidConstructorMessage } from "../parser/tuple.js"
6
- import type { Type } from "../type.js"
5
+ import type { Type } from "../types/type.js"
7
6
 
8
7
  describe("instanceof", () => {
9
8
  describe("tuple expression", () => {
10
9
  it("base", () => {
11
10
  const t = type(["instanceof", Error])
12
11
  attest<Error>(t.infer)
13
- attest(t.json).equals(schema(Error).json)
12
+ const expected = node(Error)
13
+ attest(t.json).equals(expected.json)
14
14
  const e = new Error()
15
15
  attest(t(e).out).equals(e)
16
- attest(t({}).errors?.summary).snap("Must be an Error (was object)")
16
+ attest(t({}).errors?.summary).snap("must be an Error (was object)")
17
17
  })
18
18
  it("inherited", () => {
19
19
  const t = type(["instanceof", TypeError])
@@ -23,7 +23,7 @@ describe("instanceof", () => {
23
23
  // attest<TypeError>(t.infer)
24
24
  attest(t(e).out).equals(e)
25
25
  attest(t(new Error()).errors?.summary).snap(
26
- "Must be an instance of TypeError (was Error)"
26
+ "must be an instance of TypeError (was Error)"
27
27
  )
28
28
  })
29
29
  it("abstract", () => {
@@ -60,7 +60,7 @@ describe("instanceof", () => {
60
60
  const a = new ArkClass()
61
61
  attest(ark(a).out).equals(a)
62
62
  attest(ark({}).errors?.summary).snap(
63
- "Must be an instance of ArkClass (was Object)"
63
+ "must be an instance of ArkClass (was object)"
64
64
  )
65
65
  })
66
66
  // TODO: Fix- Investigate bidirectional check impact on perf to narrow private props without breaking this case:
@@ -1,6 +1,7 @@
1
1
  import { attest } from "@arktype/attest"
2
- import { writeIndivisibleMessage } from "@arktype/schema"
3
2
  import { type } from "arktype"
3
+ import { writeIndivisibleMessage } from "../constraints/refinements/divisor.js"
4
+ import { keywords, node } from "../keywords/ark.js"
4
5
  import {
5
6
  writeMissingRightOperandMessage,
6
7
  writeUnresolvableMessage
@@ -59,46 +60,69 @@ describe("intersection", () => {
59
60
 
60
61
  attest<{ a: number; b: boolean[]; c: "hello" }>(t.infer)
61
62
  })
62
- describe("errors", () => {
63
- it("bad reference", () => {
64
- // @ts-expect-error
65
- attest(() => type("boolean&tru"))
66
- .throws(writeUnresolvableMessage("tru"))
67
- .type.errors("boolean&true")
68
- })
69
- it("double and", () => {
70
- // @ts-expect-error
71
- attest(() => type("boolean&&true")).throws(
72
- writeMissingRightOperandMessage("&", "&true")
73
- )
74
- })
75
- it("implicit never", () => {
76
- attest(() => type("string&number")).throws(
77
- "Intersection of a string and a number results in an unsatisfiable type"
78
- )
79
- })
80
- it("left semantic error", () => {
81
- // @ts-expect-error
82
- attest(() => type("string%2&'foo'")).throwsAndHasTypeError(
83
- writeIndivisibleMessage("string")
84
- )
85
- })
86
- it("right semantic error", () => {
63
+
64
+ it("bad reference", () => {
65
+ // @ts-expect-error
66
+ attest(() => type("boolean&tru"))
67
+ .throws(writeUnresolvableMessage("tru"))
68
+ .type.errors("boolean&true")
69
+ })
70
+ it("double and", () => {
71
+ // @ts-expect-error
72
+ attest(() => type("boolean&&true")).throws(
73
+ writeMissingRightOperandMessage("&", "&true")
74
+ )
75
+ })
76
+ it("implicit never", () => {
77
+ attest(() => type("string&number")).throws.snap(
78
+ "ParseError: Intersection of string and number results in an unsatisfiable type"
79
+ )
80
+ })
81
+ it("left semantic error", () => {
82
+ // @ts-expect-error
83
+ attest(() => type("string%2&'foo'")).throwsAndHasTypeError(
84
+ writeIndivisibleMessage(keywords.string)
85
+ )
86
+ })
87
+ it("right semantic error", () => {
88
+ // @ts-expect-error
89
+ attest(() => type("'foo'&string%2")).throwsAndHasTypeError(
90
+ writeIndivisibleMessage(keywords.string)
91
+ )
92
+ })
93
+ it("chained validation", () => {
94
+ attest(() =>
87
95
  // @ts-expect-error
88
- attest(() => type("'foo'&string%2")).throwsAndHasTypeError(
89
- writeIndivisibleMessage("string")
90
- )
96
+ type({ a: "string" }).and({ b: "what" })
97
+ ).throwsAndHasTypeError(writeUnresolvableMessage("what"))
98
+ })
99
+ it("at path", () => {
100
+ attest(() => type({ a: "string" }).and({ a: "number" })).throws.snap(
101
+ "ParseError: Intersection at a of string and number results in an unsatisfiable type"
102
+ )
103
+ })
104
+ it("normalizes refinement order", () => {
105
+ const l = node({
106
+ domain: "number",
107
+ divisor: 3,
108
+ min: 5
91
109
  })
92
- it("chained validation", () => {
93
- attest(() =>
94
- // @ts-expect-error
95
- type({ a: "string" }).and({ b: "what" })
96
- ).throwsAndHasTypeError(writeUnresolvableMessage("what"))
110
+ const r = node({
111
+ domain: "number",
112
+ min: 5,
113
+ divisor: 3
97
114
  })
98
- it("at path", () => {
99
- attest(() => type({ a: "string" }).and({ a: "number" })).throws(
100
- "Intersection at a of a string and a number results in an unsatisfiable type"
101
- )
115
+ attest(l.innerId).equals(r.innerId)
116
+ })
117
+
118
+ it("multiple constraints", () => {
119
+ const n = node({
120
+ domain: "number",
121
+ divisor: 3,
122
+ min: 5
102
123
  })
124
+ attest(n.allows(6)).snap(true)
125
+ attest(n.allows(4)).snap(false)
126
+ attest(n.allows(7)).snap(false)
103
127
  })
104
128
  })
@@ -1,5 +1,3 @@
1
- import { attest } from "@arktype/attest"
2
- import { type } from "arktype"
3
1
 
4
2
  // TODO: reenable
5
3
  // describe("key traversal", () => {