@elaraai/east 0.0.1-beta.9 → 1.0.0

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 (410) hide show
  1. package/LICENSE.md +15 -666
  2. package/README.md +113 -88
  3. package/dist/src/analyze.d.ts +3 -0
  4. package/dist/src/analyze.d.ts.map +1 -1
  5. package/dist/src/analyze.js +223 -111
  6. package/dist/src/analyze.js.map +1 -1
  7. package/dist/src/analyze.spec.d.ts +2 -0
  8. package/dist/src/analyze.spec.d.ts.map +1 -0
  9. package/dist/src/analyze.spec.js +445 -0
  10. package/dist/src/analyze.spec.js.map +1 -0
  11. package/dist/src/ast.d.ts +54 -35
  12. package/dist/src/ast.d.ts.map +1 -1
  13. package/dist/src/ast_to_ir.coerce_to.spec.d.ts +15 -0
  14. package/dist/src/ast_to_ir.coerce_to.spec.d.ts.map +1 -0
  15. package/dist/src/ast_to_ir.coerce_to.spec.js +420 -0
  16. package/dist/src/ast_to_ir.coerce_to.spec.js.map +1 -0
  17. package/dist/src/ast_to_ir.d.ts +18 -4
  18. package/dist/src/ast_to_ir.d.ts.map +1 -1
  19. package/dist/src/ast_to_ir.js +233 -178
  20. package/dist/src/ast_to_ir.js.map +1 -1
  21. package/dist/src/builtins.d.ts +1 -1
  22. package/dist/src/builtins.d.ts.map +1 -1
  23. package/dist/src/builtins.js +194 -2
  24. package/dist/src/builtins.js.map +1 -1
  25. package/dist/src/comparison.d.ts +2 -2
  26. package/dist/src/comparison.d.ts.map +1 -1
  27. package/dist/src/comparison.js +115 -40
  28. package/dist/src/comparison.js.map +1 -1
  29. package/dist/src/comparison.spec.d.ts +2 -0
  30. package/dist/src/comparison.spec.d.ts.map +1 -0
  31. package/dist/src/comparison.spec.js +1200 -0
  32. package/dist/src/comparison.spec.js.map +1 -0
  33. package/dist/src/compile.d.ts +31 -9
  34. package/dist/src/compile.d.ts.map +1 -1
  35. package/dist/src/compile.js +1048 -548
  36. package/dist/src/compile.js.map +1 -1
  37. package/dist/src/containers/matrix.d.ts +15 -0
  38. package/dist/src/containers/matrix.d.ts.map +1 -0
  39. package/dist/src/containers/matrix.js +15 -0
  40. package/dist/src/containers/matrix.js.map +1 -0
  41. package/dist/src/containers/ref.d.ts.map +1 -1
  42. package/dist/src/containers/ref.js +1 -1
  43. package/dist/src/containers/ref.js.map +1 -1
  44. package/dist/src/containers/sortedmap.spec.d.ts +2 -0
  45. package/dist/src/containers/sortedmap.spec.d.ts.map +1 -0
  46. package/dist/src/containers/sortedmap.spec.js +180 -0
  47. package/dist/src/containers/sortedmap.spec.js.map +1 -0
  48. package/dist/src/containers/sortedset.spec.d.ts +2 -0
  49. package/dist/src/containers/sortedset.spec.d.ts.map +1 -0
  50. package/dist/src/containers/sortedset.spec.js +228 -0
  51. package/dist/src/containers/sortedset.spec.js.map +1 -0
  52. package/dist/src/containers/variant.d.ts.map +1 -1
  53. package/dist/src/containers/variant.js +1 -1
  54. package/dist/src/containers/variant.js.map +1 -1
  55. package/dist/src/containers/variant.spec.d.ts +2 -0
  56. package/dist/src/containers/variant.spec.d.ts.map +1 -0
  57. package/dist/src/containers/variant.spec.js +217 -0
  58. package/dist/src/containers/variant.spec.js.map +1 -0
  59. package/dist/src/datetime_format/parse.spec.d.ts +6 -0
  60. package/dist/src/datetime_format/parse.spec.d.ts.map +1 -0
  61. package/dist/src/datetime_format/parse.spec.js +379 -0
  62. package/dist/src/datetime_format/parse.spec.js.map +1 -0
  63. package/dist/src/datetime_format/print.spec.d.ts +6 -0
  64. package/dist/src/datetime_format/print.spec.d.ts.map +1 -0
  65. package/dist/src/datetime_format/print.spec.js +257 -0
  66. package/dist/src/datetime_format/print.spec.js.map +1 -0
  67. package/dist/src/datetime_format/tokenize.spec.d.ts +2 -0
  68. package/dist/src/datetime_format/tokenize.spec.d.ts.map +1 -0
  69. package/dist/src/datetime_format/tokenize.spec.js +508 -0
  70. package/dist/src/datetime_format/tokenize.spec.js.map +1 -0
  71. package/dist/src/datetime_format/types.d.ts +23 -23
  72. package/dist/src/default.d.ts.map +1 -1
  73. package/dist/src/default.js +33 -0
  74. package/dist/src/default.js.map +1 -1
  75. package/dist/src/default.spec.d.ts +2 -0
  76. package/dist/src/default.spec.d.ts.map +1 -0
  77. package/dist/src/default.spec.js +178 -0
  78. package/dist/src/default.spec.js.map +1 -0
  79. package/dist/src/eastir.d.ts +7 -0
  80. package/dist/src/eastir.d.ts.map +1 -1
  81. package/dist/src/eastir.js +55 -7
  82. package/dist/src/eastir.js.map +1 -1
  83. package/dist/src/error.d.ts +14 -4
  84. package/dist/src/error.d.ts.map +1 -1
  85. package/dist/src/error.js +28 -3
  86. package/dist/src/error.js.map +1 -1
  87. package/dist/src/example.d.ts +87 -0
  88. package/dist/src/example.d.ts.map +1 -0
  89. package/dist/src/example.js +18 -0
  90. package/dist/src/example.js.map +1 -0
  91. package/dist/src/expr/array.d.ts +43 -1
  92. package/dist/src/expr/array.d.ts.map +1 -1
  93. package/dist/src/expr/array.js +103 -53
  94. package/dist/src/expr/array.js.map +1 -1
  95. package/dist/src/expr/ast.d.ts +1 -1
  96. package/dist/src/expr/ast.d.ts.map +1 -1
  97. package/dist/src/expr/ast.js +112 -54
  98. package/dist/src/expr/ast.js.map +1 -1
  99. package/dist/src/expr/asyncfunction.d.ts.map +1 -1
  100. package/dist/src/expr/asyncfunction.js +6 -4
  101. package/dist/src/expr/asyncfunction.js.map +1 -1
  102. package/dist/src/expr/blob.d.ts +48 -0
  103. package/dist/src/expr/blob.d.ts.map +1 -1
  104. package/dist/src/expr/blob.js +63 -8
  105. package/dist/src/expr/blob.js.map +1 -1
  106. package/dist/src/expr/block.d.ts +213 -12
  107. package/dist/src/expr/block.d.ts.map +1 -1
  108. package/dist/src/expr/block.js +796 -293
  109. package/dist/src/expr/block.js.map +1 -1
  110. package/dist/src/expr/boolean.d.ts +44 -0
  111. package/dist/src/expr/boolean.d.ts.map +1 -1
  112. package/dist/src/expr/boolean.js +58 -6
  113. package/dist/src/expr/boolean.js.map +1 -1
  114. package/dist/src/expr/datetime.d.ts +135 -0
  115. package/dist/src/expr/datetime.d.ts.map +1 -1
  116. package/dist/src/expr/datetime.js +184 -34
  117. package/dist/src/expr/datetime.js.map +1 -1
  118. package/dist/src/expr/dict.d.ts +47 -2
  119. package/dist/src/expr/dict.d.ts.map +1 -1
  120. package/dist/src/expr/dict.js +122 -61
  121. package/dist/src/expr/dict.js.map +1 -1
  122. package/dist/src/expr/expr.d.ts +3 -1
  123. package/dist/src/expr/expr.d.ts.map +1 -1
  124. package/dist/src/expr/expr.js +4 -3
  125. package/dist/src/expr/expr.js.map +1 -1
  126. package/dist/src/expr/float.d.ts +153 -0
  127. package/dist/src/expr/float.d.ts.map +1 -1
  128. package/dist/src/expr/float.js +191 -17
  129. package/dist/src/expr/float.js.map +1 -1
  130. package/dist/src/expr/function.d.ts +7 -2
  131. package/dist/src/expr/function.d.ts.map +1 -1
  132. package/dist/src/expr/function.js +6 -4
  133. package/dist/src/expr/function.js.map +1 -1
  134. package/dist/src/expr/index.d.ts +186 -2
  135. package/dist/src/expr/index.d.ts.map +1 -1
  136. package/dist/src/expr/index.js +183 -2
  137. package/dist/src/expr/index.js.map +1 -1
  138. package/dist/src/expr/integer.d.ts +180 -0
  139. package/dist/src/expr/integer.d.ts.map +1 -1
  140. package/dist/src/expr/integer.js +189 -18
  141. package/dist/src/expr/integer.js.map +1 -1
  142. package/dist/src/expr/libs/array.js +3 -3
  143. package/dist/src/expr/libs/array.js.map +1 -1
  144. package/dist/src/expr/libs/blob.js +3 -3
  145. package/dist/src/expr/libs/blob.js.map +1 -1
  146. package/dist/src/expr/libs/dict.js +1 -1
  147. package/dist/src/expr/libs/dict.js.map +1 -1
  148. package/dist/src/expr/libs/matrix.d.ts +17 -0
  149. package/dist/src/expr/libs/matrix.d.ts.map +1 -0
  150. package/dist/src/expr/libs/matrix.js +60 -0
  151. package/dist/src/expr/libs/matrix.js.map +1 -0
  152. package/dist/src/expr/libs/set.js +1 -1
  153. package/dist/src/expr/libs/set.js.map +1 -1
  154. package/dist/src/expr/libs/string.d.ts.map +1 -1
  155. package/dist/src/expr/libs/string.js +2 -1
  156. package/dist/src/expr/libs/string.js.map +1 -1
  157. package/dist/src/expr/libs/vector.d.ts +16 -0
  158. package/dist/src/expr/libs/vector.d.ts.map +1 -0
  159. package/dist/src/expr/libs/vector.js +44 -0
  160. package/dist/src/expr/libs/vector.js.map +1 -0
  161. package/dist/src/expr/matrix.d.ts +109 -0
  162. package/dist/src/expr/matrix.d.ts.map +1 -0
  163. package/dist/src/expr/matrix.js +224 -0
  164. package/dist/src/expr/matrix.js.map +1 -0
  165. package/dist/src/expr/recursive.d.ts +83 -0
  166. package/dist/src/expr/recursive.d.ts.map +1 -0
  167. package/dist/src/expr/recursive.js +99 -0
  168. package/dist/src/expr/recursive.js.map +1 -0
  169. package/dist/src/expr/ref.js +5 -5
  170. package/dist/src/expr/ref.js.map +1 -1
  171. package/dist/src/expr/set.d.ts +44 -2
  172. package/dist/src/expr/set.d.ts.map +1 -1
  173. package/dist/src/expr/set.js +102 -52
  174. package/dist/src/expr/set.js.map +1 -1
  175. package/dist/src/expr/string.d.ts +134 -0
  176. package/dist/src/expr/string.d.ts.map +1 -1
  177. package/dist/src/expr/string.js +173 -23
  178. package/dist/src/expr/string.js.map +1 -1
  179. package/dist/src/expr/struct.d.ts +1 -1
  180. package/dist/src/expr/struct.d.ts.map +1 -1
  181. package/dist/src/expr/struct.js +2 -2
  182. package/dist/src/expr/struct.js.map +1 -1
  183. package/dist/src/expr/types.d.ts +12 -9
  184. package/dist/src/expr/types.d.ts.map +1 -1
  185. package/dist/src/expr/variant.d.ts +108 -11
  186. package/dist/src/expr/variant.d.ts.map +1 -1
  187. package/dist/src/expr/variant.js +76 -38
  188. package/dist/src/expr/variant.js.map +1 -1
  189. package/dist/src/expr/vector.d.ts +102 -0
  190. package/dist/src/expr/vector.d.ts.map +1 -0
  191. package/dist/src/expr/vector.js +202 -0
  192. package/dist/src/expr/vector.js.map +1 -0
  193. package/dist/src/fuzz.d.ts +36 -2
  194. package/dist/src/fuzz.d.ts.map +1 -1
  195. package/dist/src/fuzz.js +409 -77
  196. package/dist/src/fuzz.js.map +1 -1
  197. package/dist/src/index.d.ts +4 -0
  198. package/dist/src/index.d.ts.map +1 -1
  199. package/dist/src/index.js +4 -0
  200. package/dist/src/index.js.map +1 -1
  201. package/dist/src/internal.d.ts +12 -2
  202. package/dist/src/internal.d.ts.map +1 -1
  203. package/dist/src/internal.js +13 -2
  204. package/dist/src/internal.js.map +1 -1
  205. package/dist/src/ir.d.ts +1754 -1484
  206. package/dist/src/ir.d.ts.map +1 -1
  207. package/dist/src/ir.js +51 -34
  208. package/dist/src/ir.js.map +1 -1
  209. package/dist/src/ir.spec.d.ts +2 -0
  210. package/dist/src/ir.spec.d.ts.map +1 -0
  211. package/dist/src/ir.spec.js +35 -0
  212. package/dist/src/ir.spec.js.map +1 -0
  213. package/dist/src/location.d.ts +56 -17
  214. package/dist/src/location.d.ts.map +1 -1
  215. package/dist/src/location.js +226 -29
  216. package/dist/src/location.js.map +1 -1
  217. package/dist/src/location.spec.d.ts +2 -0
  218. package/dist/src/location.spec.d.ts.map +1 -0
  219. package/dist/src/location.spec.js +102 -0
  220. package/dist/src/location.spec.js.map +1 -0
  221. package/dist/src/patch/apply.d.ts +15 -0
  222. package/dist/src/patch/apply.d.ts.map +1 -0
  223. package/dist/src/patch/apply.js +352 -0
  224. package/dist/src/patch/apply.js.map +1 -0
  225. package/dist/src/patch/compose.d.ts +15 -0
  226. package/dist/src/patch/compose.d.ts.map +1 -0
  227. package/dist/src/patch/compose.js +448 -0
  228. package/dist/src/patch/compose.js.map +1 -0
  229. package/dist/src/patch/diff.d.ts +15 -0
  230. package/dist/src/patch/diff.d.ts.map +1 -0
  231. package/dist/src/patch/diff.js +347 -0
  232. package/dist/src/patch/diff.js.map +1 -0
  233. package/dist/src/patch/fuzz.d.ts +73 -0
  234. package/dist/src/patch/fuzz.d.ts.map +1 -0
  235. package/dist/src/patch/fuzz.js +159 -0
  236. package/dist/src/patch/fuzz.js.map +1 -0
  237. package/dist/src/patch/index.d.ts +32 -0
  238. package/dist/src/patch/index.d.ts.map +1 -0
  239. package/dist/src/patch/index.js +48 -0
  240. package/dist/src/patch/index.js.map +1 -0
  241. package/dist/src/patch/invert.d.ts +15 -0
  242. package/dist/src/patch/invert.d.ts.map +1 -0
  243. package/dist/src/patch/invert.js +284 -0
  244. package/dist/src/patch/invert.js.map +1 -0
  245. package/dist/src/patch/merge.d.ts +56 -0
  246. package/dist/src/patch/merge.d.ts.map +1 -0
  247. package/dist/src/patch/merge.js +586 -0
  248. package/dist/src/patch/merge.js.map +1 -0
  249. package/dist/src/patch/merge.spec.d.ts +2 -0
  250. package/dist/src/patch/merge.spec.d.ts.map +1 -0
  251. package/dist/src/patch/merge.spec.js +1139 -0
  252. package/dist/src/patch/merge.spec.js.map +1 -0
  253. package/dist/src/patch/patch.spec.d.ts +2 -0
  254. package/dist/src/patch/patch.spec.d.ts.map +1 -0
  255. package/dist/src/patch/patch.spec.js +452 -0
  256. package/dist/src/patch/patch.spec.js.map +1 -0
  257. package/dist/src/patch/path.d.ts +115 -0
  258. package/dist/src/patch/path.d.ts.map +1 -0
  259. package/dist/src/patch/path.js +192 -0
  260. package/dist/src/patch/path.js.map +1 -0
  261. package/dist/src/patch/path.spec.d.ts +6 -0
  262. package/dist/src/patch/path.spec.d.ts.map +1 -0
  263. package/dist/src/patch/path.spec.js +322 -0
  264. package/dist/src/patch/path.spec.js.map +1 -0
  265. package/dist/src/patch/prune.d.ts +77 -0
  266. package/dist/src/patch/prune.d.ts.map +1 -0
  267. package/dist/src/patch/prune.js +115 -0
  268. package/dist/src/patch/prune.js.map +1 -0
  269. package/dist/src/patch/prune.spec.d.ts +6 -0
  270. package/dist/src/patch/prune.spec.d.ts.map +1 -0
  271. package/dist/src/patch/prune.spec.js +473 -0
  272. package/dist/src/patch/prune.spec.js.map +1 -0
  273. package/dist/src/patch/type_of_patch.d.ts +25 -0
  274. package/dist/src/patch/type_of_patch.d.ts.map +1 -0
  275. package/dist/src/patch/type_of_patch.js +144 -0
  276. package/dist/src/patch/type_of_patch.js.map +1 -0
  277. package/dist/src/patch/types.d.ts +220 -0
  278. package/dist/src/patch/types.d.ts.map +1 -0
  279. package/dist/src/patch/types.js +62 -0
  280. package/dist/src/patch/types.js.map +1 -0
  281. package/dist/src/patch/validate.d.ts +44 -0
  282. package/dist/src/patch/validate.d.ts.map +1 -0
  283. package/dist/src/patch/validate.js +190 -0
  284. package/dist/src/patch/validate.js.map +1 -0
  285. package/dist/src/patch/validate.spec.d.ts +6 -0
  286. package/dist/src/patch/validate.spec.d.ts.map +1 -0
  287. package/dist/src/patch/validate.spec.js +225 -0
  288. package/dist/src/patch/validate.spec.js.map +1 -0
  289. package/dist/src/patch/walk.d.ts +121 -0
  290. package/dist/src/patch/walk.d.ts.map +1 -0
  291. package/dist/src/patch/walk.js +385 -0
  292. package/dist/src/patch/walk.js.map +1 -0
  293. package/dist/src/patch/walk.spec.d.ts +6 -0
  294. package/dist/src/patch/walk.spec.d.ts.map +1 -0
  295. package/dist/src/patch/walk.spec.js +621 -0
  296. package/dist/src/patch/walk.spec.js.map +1 -0
  297. package/dist/src/platform.d.ts +6 -0
  298. package/dist/src/platform.d.ts.map +1 -1
  299. package/dist/src/platform.spec.d.ts +2 -0
  300. package/dist/src/platform.spec.d.ts.map +1 -0
  301. package/dist/src/platform.spec.js +330 -0
  302. package/dist/src/platform.spec.js.map +1 -0
  303. package/dist/src/serialization/beast.d.ts.map +1 -1
  304. package/dist/src/serialization/beast.js +12 -0
  305. package/dist/src/serialization/beast.js.map +1 -1
  306. package/dist/src/serialization/beast.spec.d.ts +6 -0
  307. package/dist/src/serialization/beast.spec.d.ts.map +1 -0
  308. package/dist/src/serialization/beast.spec.js +406 -0
  309. package/dist/src/serialization/beast.spec.js.map +1 -0
  310. package/dist/src/serialization/beast2/index.d.ts +50 -0
  311. package/dist/src/serialization/beast2/index.d.ts.map +1 -0
  312. package/dist/src/serialization/beast2/index.js +756 -0
  313. package/dist/src/serialization/beast2/index.js.map +1 -0
  314. package/dist/src/serialization/beast2/index.spec.d.ts +6 -0
  315. package/dist/src/serialization/beast2/index.spec.d.ts.map +1 -0
  316. package/dist/src/serialization/beast2/index.spec.js +528 -0
  317. package/dist/src/serialization/beast2/index.spec.js.map +1 -0
  318. package/dist/src/serialization/beast2/sourcemap-table.d.ts +29 -0
  319. package/dist/src/serialization/beast2/sourcemap-table.d.ts.map +1 -0
  320. package/dist/src/serialization/beast2/sourcemap-table.js +82 -0
  321. package/dist/src/serialization/beast2/sourcemap-table.js.map +1 -0
  322. package/dist/src/serialization/beast2/string-table.d.ts +16 -0
  323. package/dist/src/serialization/beast2/string-table.d.ts.map +1 -0
  324. package/dist/src/serialization/beast2/string-table.js +38 -0
  325. package/dist/src/serialization/beast2/string-table.js.map +1 -0
  326. package/dist/src/serialization/beast2/type-table.d.ts +86 -0
  327. package/dist/src/serialization/beast2/type-table.d.ts.map +1 -0
  328. package/dist/src/serialization/beast2/type-table.js +618 -0
  329. package/dist/src/serialization/beast2/type-table.js.map +1 -0
  330. package/dist/src/serialization/beast2/value-table.d.ts +40 -0
  331. package/dist/src/serialization/beast2/value-table.d.ts.map +1 -0
  332. package/dist/src/serialization/beast2/value-table.js +157 -0
  333. package/dist/src/serialization/beast2/value-table.js.map +1 -0
  334. package/dist/src/serialization/binary-utils.d.ts +33 -0
  335. package/dist/src/serialization/binary-utils.d.ts.map +1 -1
  336. package/dist/src/serialization/binary-utils.js +157 -0
  337. package/dist/src/serialization/binary-utils.js.map +1 -1
  338. package/dist/src/serialization/csv.d.ts +17 -17
  339. package/dist/src/serialization/csv.d.ts.map +1 -1
  340. package/dist/src/serialization/csv.js +10 -8
  341. package/dist/src/serialization/csv.js.map +1 -1
  342. package/dist/src/serialization/csv.spec.d.ts +2 -0
  343. package/dist/src/serialization/csv.spec.d.ts.map +1 -0
  344. package/dist/src/serialization/csv.spec.js +556 -0
  345. package/dist/src/serialization/csv.spec.js.map +1 -0
  346. package/dist/src/serialization/east-inferred.spec.d.ts +2 -0
  347. package/dist/src/serialization/east-inferred.spec.d.ts.map +1 -0
  348. package/dist/src/serialization/east-inferred.spec.js +322 -0
  349. package/dist/src/serialization/east-inferred.spec.js.map +1 -0
  350. package/dist/src/serialization/east.d.ts +1 -1
  351. package/dist/src/serialization/east.d.ts.map +1 -1
  352. package/dist/src/serialization/east.js +178 -26
  353. package/dist/src/serialization/east.js.map +1 -1
  354. package/dist/src/serialization/east.spec.d.ts +2 -0
  355. package/dist/src/serialization/east.spec.d.ts.map +1 -0
  356. package/dist/src/serialization/east.spec.js +1548 -0
  357. package/dist/src/serialization/east.spec.js.map +1 -0
  358. package/dist/src/serialization/index.d.ts +1 -2
  359. package/dist/src/serialization/index.d.ts.map +1 -1
  360. package/dist/src/serialization/index.js +1 -2
  361. package/dist/src/serialization/index.js.map +1 -1
  362. package/dist/src/serialization/json.d.ts +1 -1
  363. package/dist/src/serialization/json.d.ts.map +1 -1
  364. package/dist/src/serialization/json.js +123 -24
  365. package/dist/src/serialization/json.js.map +1 -1
  366. package/dist/src/serialization/json.spec.d.ts +2 -0
  367. package/dist/src/serialization/json.spec.d.ts.map +1 -0
  368. package/dist/src/serialization/json.spec.js +1297 -0
  369. package/dist/src/serialization/json.spec.js.map +1 -0
  370. package/dist/src/type_of_type.d.ts +72 -35
  371. package/dist/src/type_of_type.d.ts.map +1 -1
  372. package/dist/src/type_of_type.is_data.spec.d.ts +6 -0
  373. package/dist/src/type_of_type.is_data.spec.d.ts.map +1 -0
  374. package/dist/src/type_of_type.is_data.spec.js +221 -0
  375. package/dist/src/type_of_type.is_data.spec.js.map +1 -0
  376. package/dist/src/type_of_type.js +355 -80
  377. package/dist/src/type_of_type.js.map +1 -1
  378. package/dist/src/type_of_type.to_etv.spec.d.ts +6 -0
  379. package/dist/src/type_of_type.to_etv.spec.d.ts.map +1 -0
  380. package/dist/src/type_of_type.to_etv.spec.js +263 -0
  381. package/dist/src/type_of_type.to_etv.spec.js.map +1 -0
  382. package/dist/src/types.d.ts +82 -12
  383. package/dist/src/types.d.ts.map +1 -1
  384. package/dist/src/types.error.spec.d.ts +2 -0
  385. package/dist/src/types.error.spec.d.ts.map +1 -0
  386. package/dist/src/types.error.spec.js +665 -0
  387. package/dist/src/types.error.spec.js.map +1 -0
  388. package/dist/src/types.js +663 -156
  389. package/dist/src/types.js.map +1 -1
  390. package/dist/src/types.spec.d.ts +2 -0
  391. package/dist/src/types.spec.d.ts.map +1 -0
  392. package/dist/src/types.spec.js +946 -0
  393. package/dist/src/types.spec.js.map +1 -0
  394. package/dist/src/walker.d.ts +65 -0
  395. package/dist/src/walker.d.ts.map +1 -0
  396. package/dist/src/walker.js +165 -0
  397. package/dist/src/walker.js.map +1 -0
  398. package/dist/src/walker.spec.d.ts +6 -0
  399. package/dist/src/walker.spec.d.ts.map +1 -0
  400. package/dist/src/walker.spec.js +109 -0
  401. package/dist/src/walker.spec.js.map +1 -0
  402. package/package.json +16 -38
  403. package/dist/src/serialization/beast2-stream.d.ts +0 -38
  404. package/dist/src/serialization/beast2-stream.d.ts.map +0 -1
  405. package/dist/src/serialization/beast2-stream.js +0 -670
  406. package/dist/src/serialization/beast2-stream.js.map +0 -1
  407. package/dist/src/serialization/beast2.d.ts +0 -41
  408. package/dist/src/serialization/beast2.d.ts.map +0 -1
  409. package/dist/src/serialization/beast2.js +0 -495
  410. package/dist/src/serialization/beast2.js.map +0 -1
@@ -0,0 +1,665 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ import { describe, test } from "node:test";
6
+ import assert from "node:assert";
7
+ import { NeverType, NullType, BooleanType, IntegerType, FloatType, StringType, DateTimeType, BlobType, ArrayType, SetType, DictType, StructType, VariantType, FunctionType, AsyncFunctionType, RecursiveType, RefType, VectorType, MatrixType, OptionType, TypeUnion, TypeIntersect, TypeEqual, TypeMismatchError, printTypeSummary, TypeWiden, getTypeId, } from "./types.js";
8
+ /** Extract error from assert.throws with proper typing */
9
+ function catchError(fn) {
10
+ try {
11
+ fn();
12
+ }
13
+ catch (e) {
14
+ return e;
15
+ }
16
+ throw new Error("Expected function to throw");
17
+ }
18
+ // ============================================================================
19
+ // printTypeSummary
20
+ // ============================================================================
21
+ describe("printTypeSummary", () => {
22
+ // --- Primitives ---
23
+ test("primitives", () => {
24
+ assert.strictEqual(printTypeSummary(NeverType), ".Never");
25
+ assert.strictEqual(printTypeSummary(NullType), ".Null");
26
+ assert.strictEqual(printTypeSummary(BooleanType), ".Boolean");
27
+ assert.strictEqual(printTypeSummary(IntegerType), ".Integer");
28
+ assert.strictEqual(printTypeSummary(FloatType), ".Float");
29
+ assert.strictEqual(printTypeSummary(StringType), ".String");
30
+ assert.strictEqual(printTypeSummary(DateTimeType), ".DateTime");
31
+ assert.strictEqual(printTypeSummary(BlobType), ".Blob");
32
+ });
33
+ // --- Small compound types (full output at default depth=1) ---
34
+ test("small struct fully printed at depth 1", () => {
35
+ assert.strictEqual(printTypeSummary(StructType({ x: IntegerType, y: FloatType })), '.Struct [(name="x", type=.Integer), (name="y", type=.Float)]');
36
+ });
37
+ test("small variant fully printed at depth 1", () => {
38
+ assert.strictEqual(printTypeSummary(VariantType({ none: NullType, some: IntegerType })), '.Variant [(name="none", type=.Null), (name="some", type=.Integer)]');
39
+ });
40
+ // --- Depth 0 summaries ---
41
+ test("struct at depth 0 shows field count", () => {
42
+ assert.strictEqual(printTypeSummary(StructType({ x: IntegerType, y: FloatType }), 0), ".Struct [2 fields]");
43
+ });
44
+ test("variant at depth 0 shows case names", () => {
45
+ assert.strictEqual(printTypeSummary(VariantType({ none: NullType, some: IntegerType }), 0), ".Variant (none | some)");
46
+ });
47
+ test("array at depth 0", () => {
48
+ assert.strictEqual(printTypeSummary(ArrayType(IntegerType), 0), ".Array ...");
49
+ });
50
+ test("dict at depth 0", () => {
51
+ assert.strictEqual(printTypeSummary(DictType(StringType, IntegerType), 0), ".Dict ...");
52
+ });
53
+ test("set at depth 0", () => {
54
+ assert.strictEqual(printTypeSummary(SetType(StringType), 0), ".Set ...");
55
+ });
56
+ test("ref at depth 0", () => {
57
+ assert.strictEqual(printTypeSummary(RefType(IntegerType), 0), ".Ref ...");
58
+ });
59
+ test("function at depth 0", () => {
60
+ assert.strictEqual(printTypeSummary(FunctionType([IntegerType], StringType), 0), ".Function ...");
61
+ });
62
+ test("async function at depth 0", () => {
63
+ assert.strictEqual(printTypeSummary(AsyncFunctionType([IntegerType], StringType), 0), ".AsyncFunction ...");
64
+ });
65
+ // --- Truncation of large structs ---
66
+ test("7-field struct with maxFields=2", () => {
67
+ const t = StructType({ a: IntegerType, b: FloatType, c: StringType, d: BooleanType, e: NullType, f: IntegerType, g: FloatType });
68
+ assert.strictEqual(printTypeSummary(t, 1, 2), '.Struct [(name="a", type=.Integer), (name="b", type=.Float), ... and 5 more]');
69
+ });
70
+ test("7-field struct with maxFields=3", () => {
71
+ const t = StructType({ a: IntegerType, b: FloatType, c: StringType, d: BooleanType, e: NullType, f: IntegerType, g: FloatType });
72
+ assert.strictEqual(printTypeSummary(t, 1, 3), '.Struct [(name="a", type=.Integer), (name="b", type=.Float), (name="c", type=.String), ... and 4 more]');
73
+ });
74
+ test("5-case variant with maxFields=2", () => {
75
+ const t = VariantType({ a: NullType, b: NullType, c: NullType, d: NullType, e: NullType });
76
+ assert.strictEqual(printTypeSummary(t, 1, 2), '.Variant [(name="a", type=.Null), (name="b", type=.Null), ... and 3 more]');
77
+ });
78
+ // --- Depth 1 nesting (inner compounds collapse) ---
79
+ test("nested struct: inner collapses at depth 1", () => {
80
+ const inner = StructType({ a: IntegerType, b: FloatType });
81
+ const outer = StructType({ x: inner, y: StringType });
82
+ assert.strictEqual(printTypeSummary(outer, 1), '.Struct [(name="x", type=.Struct [2 fields]), (name="y", type=.String)]');
83
+ });
84
+ test("array of struct at depth 1", () => {
85
+ assert.strictEqual(printTypeSummary(ArrayType(StructType({ x: IntegerType, y: FloatType })), 1), '.Array .Struct [2 fields]');
86
+ });
87
+ test("array of struct at depth 2 expands inner", () => {
88
+ assert.strictEqual(printTypeSummary(ArrayType(StructType({ x: IntegerType, y: FloatType })), 2), '.Array .Struct [(name="x", type=.Integer), (name="y", type=.Float)]');
89
+ });
90
+ // --- Vector / Matrix (don't consume depth) ---
91
+ test("vector", () => {
92
+ assert.strictEqual(printTypeSummary(VectorType(FloatType)), ".Vector .Float");
93
+ });
94
+ test("matrix", () => {
95
+ assert.strictEqual(printTypeSummary(MatrixType(IntegerType)), ".Matrix .Integer");
96
+ });
97
+ // --- Function types ---
98
+ test("function at depth 1", () => {
99
+ assert.strictEqual(printTypeSummary(FunctionType([IntegerType, StringType], FloatType), 1), '.Function (inputs=[.Integer, .String], output=.Float)');
100
+ });
101
+ test("async function at depth 1", () => {
102
+ assert.strictEqual(printTypeSummary(AsyncFunctionType([BooleanType], NullType), 1), '.AsyncFunction (inputs=[.Boolean], output=.Null)');
103
+ });
104
+ test("function with complex args at depth 1 collapses inner", () => {
105
+ const fn = FunctionType([ArrayType(IntegerType), StructType({ x: FloatType })], StructType({ result: FloatType }));
106
+ assert.strictEqual(printTypeSummary(fn, 1), '.Function (inputs=[.Array ..., .Struct [1 fields]], output=.Struct [1 fields])');
107
+ });
108
+ test("function with complex args at depth 2 expands one level", () => {
109
+ const fn = FunctionType([ArrayType(IntegerType), StructType({ x: FloatType })], StructType({ result: FloatType }));
110
+ assert.strictEqual(printTypeSummary(fn, 2), '.Function (inputs=[.Array .Integer, .Struct [(name="x", type=.Float)]], output=.Struct [(name="result", type=.Float)])');
111
+ });
112
+ test("async function with struct input at depth 1", () => {
113
+ const fn = AsyncFunctionType([StructType({ x: IntegerType, y: FloatType })], ArrayType(StringType));
114
+ assert.strictEqual(printTypeSummary(fn, 1), '.AsyncFunction (inputs=[.Struct [2 fields]], output=.Array ...)');
115
+ });
116
+ test("async function with struct input at depth 2", () => {
117
+ const fn = AsyncFunctionType([StructType({ x: IntegerType, y: FloatType })], ArrayType(StringType));
118
+ assert.strictEqual(printTypeSummary(fn, 2), '.AsyncFunction (inputs=[.Struct [(name="x", type=.Integer), (name="y", type=.Float)]], output=.Array .String)');
119
+ });
120
+ // --- Recursive types ---
121
+ test("recursive linked list at depth 0 (shows wrapper)", () => {
122
+ const t = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
123
+ const id = getTypeId(t);
124
+ assert.strictEqual(printTypeSummary(t, 0), `.Recursive .wrapper (id=${id}, inner=.Variant (cons | nil))`);
125
+ });
126
+ test("recursive linked list at depth 1", () => {
127
+ const t = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
128
+ const id = getTypeId(t);
129
+ assert.strictEqual(printTypeSummary(t, 1), `.Recursive .wrapper (id=${id}, inner=.Variant [(name="cons", type=.Struct [2 fields]), (name="nil", type=.Null)])`);
130
+ });
131
+ test("recursive linked list at depth 2 (shows self-reference)", () => {
132
+ const t = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
133
+ const id = getTypeId(t);
134
+ assert.strictEqual(printTypeSummary(t, 2), `.Recursive .wrapper (id=${id}, inner=.Variant [(name="cons", type=.Struct [(name="head", type=.Integer), (name="tail", type=.Recursive .ref ${id})]), (name="nil", type=.Null)])`);
135
+ });
136
+ test("recursive linked list stabilizes at depth 3 (same as depth 2)", () => {
137
+ const t = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
138
+ assert.strictEqual(printTypeSummary(t, 3), printTypeSummary(t, 2));
139
+ });
140
+ test("recursive binary tree at depth 0", () => {
141
+ const t = RecursiveType(self => StructType({ value: IntegerType, left: OptionType(self), right: OptionType(self) }));
142
+ const id = getTypeId(t);
143
+ assert.strictEqual(printTypeSummary(t, 0), `.Recursive .wrapper (id=${id}, inner=.Struct [3 fields])`);
144
+ });
145
+ test("recursive binary tree at depth 1 (option collapses)", () => {
146
+ const t = RecursiveType(self => StructType({ value: IntegerType, left: OptionType(self), right: OptionType(self) }));
147
+ const id = getTypeId(t);
148
+ assert.strictEqual(printTypeSummary(t, 1), `.Recursive .wrapper (id=${id}, inner=.Struct [(name="value", type=.Integer), (name="left", type=.Variant (none | some)), (name="right", type=.Variant (none | some))])`);
149
+ });
150
+ test("recursive binary tree at depth 2 (shows self-reference in option)", () => {
151
+ const t = RecursiveType(self => StructType({ value: IntegerType, left: OptionType(self), right: OptionType(self) }));
152
+ const id = getTypeId(t);
153
+ assert.strictEqual(printTypeSummary(t, 2), `.Recursive .wrapper (id=${id}, inner=.Struct [(name="value", type=.Integer), (name="left", type=.Variant [(name="none", type=.Null), (name="some", type=.Recursive .ref ${id})]), (name="right", type=.Variant [(name="none", type=.Null), (name="some", type=.Recursive .ref ${id})])])`);
154
+ });
155
+ // --- Complex nested type at various depths ---
156
+ test("complex type: Array of 5-field struct with recursive child at depth 1", () => {
157
+ const ListType = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
158
+ const t = ArrayType(StructType({
159
+ name: StringType, data: DictType(StringType, FloatType),
160
+ children: ListType, score: FloatType, tags: SetType(StringType),
161
+ }));
162
+ assert.strictEqual(printTypeSummary(t, 1), ".Array .Struct [5 fields]");
163
+ });
164
+ test("complex type at depth 2 (expands struct, truncates at maxFields=3)", () => {
165
+ const ListType = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
166
+ const lid = getTypeId(ListType);
167
+ const t = ArrayType(StructType({
168
+ name: StringType, data: DictType(StringType, FloatType),
169
+ children: ListType, score: FloatType, tags: SetType(StringType),
170
+ }));
171
+ assert.strictEqual(printTypeSummary(t, 2), `.Array .Struct [(name="name", type=.String), (name="data", type=.Dict ...), (name="children", type=.Recursive .wrapper (id=${lid}, inner=.Variant (cons | nil))), ... and 2 more]`);
172
+ });
173
+ test("complex type at depth 3", () => {
174
+ const ListType = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
175
+ const lid = getTypeId(ListType);
176
+ const t = ArrayType(StructType({
177
+ name: StringType, data: DictType(StringType, FloatType),
178
+ children: ListType, score: FloatType, tags: SetType(StringType),
179
+ }));
180
+ assert.strictEqual(printTypeSummary(t, 3), `.Array .Struct [(name="name", type=.String), (name="data", type=.Dict (key=.String, value=.Float)), (name="children", type=.Recursive .wrapper (id=${lid}, inner=.Variant [(name="cons", type=.Struct [2 fields]), (name="nil", type=.Null)])), ... and 2 more]`);
181
+ });
182
+ // --- Complex function at various depths ---
183
+ test("complex function at depth 1", () => {
184
+ const ListType = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
185
+ const t = FunctionType([ArrayType(StructType({ name: StringType, data: DictType(StringType, FloatType), children: ListType, score: FloatType, tags: SetType(StringType) })), IntegerType], StructType({ result: FloatType, error: OptionType(StringType) }));
186
+ assert.strictEqual(printTypeSummary(t, 1), '.Function (inputs=[.Array ..., .Integer], output=.Struct [2 fields])');
187
+ });
188
+ test("complex function at depth 2", () => {
189
+ const ListType = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
190
+ const t = FunctionType([ArrayType(StructType({ name: StringType, data: DictType(StringType, FloatType), children: ListType, score: FloatType, tags: SetType(StringType) })), IntegerType], StructType({ result: FloatType, error: OptionType(StringType) }));
191
+ assert.strictEqual(printTypeSummary(t, 2), '.Function (inputs=[.Array .Struct [5 fields], .Integer], output=.Struct [(name="result", type=.Float), (name="error", type=.Variant (none | some))])');
192
+ });
193
+ });
194
+ // ============================================================================
195
+ // TypeMismatchError path building
196
+ // ============================================================================
197
+ describe("TypeMismatchError", () => {
198
+ test("reason preserved when no path segments", () => {
199
+ const err = new TypeMismatchError("test reason");
200
+ assert.strictEqual(err.message, "test reason");
201
+ assert.strictEqual(err.reason, "test reason");
202
+ assert.deepStrictEqual(err.path, []);
203
+ });
204
+ test("single path segment", () => {
205
+ const err = new TypeMismatchError("expected .Integer but got .Float: incompatible types");
206
+ err.addPathSegment(".b");
207
+ assert.strictEqual(err.message, "at .b: expected .Integer but got .Float: incompatible types");
208
+ assert.deepStrictEqual(err.path, [".b"]);
209
+ });
210
+ test("multiple path segments build up left-to-right", () => {
211
+ const err = new TypeMismatchError("expected .Integer but got .Float: incompatible types");
212
+ err.addPathSegment(".b");
213
+ err.addPathSegment(".a");
214
+ assert.strictEqual(err.message, "at .a.b: expected .Integer but got .Float: incompatible types");
215
+ assert.deepStrictEqual(err.path, [".a", ".b"]);
216
+ });
217
+ test("mixed segment types", () => {
218
+ const err = new TypeMismatchError("expected .Integer but got .Float: incompatible types");
219
+ err.addPathSegment(".c");
220
+ err.addPathSegment("[element]");
221
+ err.addPathSegment(".a");
222
+ assert.strictEqual(err.message, "at .a[element].c: expected .Integer but got .Float: incompatible types");
223
+ });
224
+ });
225
+ // ============================================================================
226
+ // TypeEqual - error messages
227
+ // ============================================================================
228
+ describe("TypeEqual error messages", () => {
229
+ // --- Primitive kind mismatches ---
230
+ test("Integer vs Float", () => {
231
+ const err = catchError(() => TypeEqual(IntegerType, FloatType));
232
+ assert.strictEqual(err.message, "expected .Integer but got .Float: incompatible types");
233
+ assert.deepStrictEqual(err.path, []);
234
+ });
235
+ test("Null vs Boolean", () => {
236
+ const err = catchError(() => TypeEqual(NullType, BooleanType));
237
+ assert.strictEqual(err.message, "expected .Null but got .Boolean: incompatible types");
238
+ });
239
+ test("String vs DateTime", () => {
240
+ const err = catchError(() => TypeEqual(StringType, DateTimeType));
241
+ assert.strictEqual(err.message, "expected .String but got .DateTime: incompatible types");
242
+ });
243
+ test("Blob vs Integer", () => {
244
+ const err = catchError(() => TypeEqual(BlobType, IntegerType));
245
+ assert.strictEqual(err.message, "expected .Blob but got .Integer: incompatible types");
246
+ });
247
+ // --- Container kind mismatches ---
248
+ test("Ref vs Integer", () => {
249
+ const err = catchError(() => TypeEqual(RefType(IntegerType), IntegerType));
250
+ assert.strictEqual(err.message, "expected .Ref .Integer but got .Integer: incompatible types");
251
+ });
252
+ test("Array vs Integer", () => {
253
+ const err = catchError(() => TypeEqual(ArrayType(IntegerType), IntegerType));
254
+ assert.strictEqual(err.message, "expected .Array .Integer but got .Integer: incompatible types");
255
+ });
256
+ test("Vector vs Float", () => {
257
+ const err = catchError(() => TypeEqual(VectorType(FloatType), FloatType));
258
+ assert.strictEqual(err.message, "expected .Vector .Float but got .Float: incompatible types");
259
+ });
260
+ test("Matrix vs Float", () => {
261
+ const err = catchError(() => TypeEqual(MatrixType(FloatType), FloatType));
262
+ assert.strictEqual(err.message, "expected .Matrix .Float but got .Float: incompatible types");
263
+ });
264
+ test("Set vs String", () => {
265
+ const err = catchError(() => TypeEqual(SetType(StringType), StringType));
266
+ assert.strictEqual(err.message, "expected .Set .String but got .String: incompatible types");
267
+ });
268
+ test("Dict vs Integer", () => {
269
+ const err = catchError(() => TypeEqual(DictType(StringType, IntegerType), IntegerType));
270
+ assert.strictEqual(err.message, 'expected .Dict (key=.String, value=.Integer) but got .Integer: incompatible types');
271
+ });
272
+ test("Struct vs Integer", () => {
273
+ const err = catchError(() => TypeEqual(StructType({ x: IntegerType }), IntegerType));
274
+ assert.strictEqual(err.message, 'expected .Struct [(name="x", type=.Integer)] but got .Integer: incompatible types');
275
+ });
276
+ test("Variant vs Null", () => {
277
+ const err = catchError(() => TypeEqual(VariantType({ a: NullType }), NullType));
278
+ assert.strictEqual(err.message, 'expected .Variant [(name="a", type=.Null)] but got .Null: incompatible types');
279
+ });
280
+ test("Function vs Integer", () => {
281
+ const err = catchError(() => TypeEqual(FunctionType([IntegerType], NullType), IntegerType));
282
+ assert.strictEqual(err.message, 'expected .Function (inputs=[.Integer], output=.Null) but got .Integer: incompatible types');
283
+ });
284
+ test("AsyncFunction vs Integer", () => {
285
+ const err = catchError(() => TypeEqual(AsyncFunctionType([IntegerType], NullType), IntegerType));
286
+ assert.strictEqual(err.message, 'expected .AsyncFunction (inputs=[.Integer], output=.Null) but got .Integer: incompatible types');
287
+ });
288
+ test("Function vs AsyncFunction", () => {
289
+ const err = catchError(() => TypeEqual(FunctionType([IntegerType], NullType), AsyncFunctionType([IntegerType], NullType)));
290
+ assert.strictEqual(err.message, 'expected .Function (inputs=[.Integer], output=.Null) but got .AsyncFunction (inputs=[.Integer], output=.Null): incompatible types');
291
+ });
292
+ test("RecursiveType vs Integer (shows wrapper in summary)", () => {
293
+ const t = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
294
+ const id = getTypeId(t);
295
+ const err = catchError(() => TypeEqual(t, IntegerType));
296
+ assert.strictEqual(err.message, `expected .Recursive .wrapper (id=${id}, inner=.Variant [(name="cons", type=.Struct [2 fields]), (name="nil", type=.Null)]) but got .Integer: incompatible types`);
297
+ });
298
+ // --- Inner mismatches with path ---
299
+ test("Ref inner mismatch: [ref]", () => {
300
+ const err = catchError(() => TypeEqual(RefType(IntegerType), RefType(FloatType)));
301
+ assert.strictEqual(err.message, "at [ref]: expected .Integer but got .Float: incompatible types");
302
+ });
303
+ test("Array element mismatch: [element]", () => {
304
+ const err = catchError(() => TypeEqual(ArrayType(IntegerType), ArrayType(FloatType)));
305
+ assert.strictEqual(err.message, "at [element]: expected .Integer but got .Float: incompatible types");
306
+ });
307
+ test("Vector element mismatch: [element]", () => {
308
+ const err = catchError(() => TypeEqual(VectorType(FloatType), VectorType(IntegerType)));
309
+ assert.strictEqual(err.message, "at [element]: expected .Float but got .Integer: incompatible types");
310
+ });
311
+ test("Matrix element mismatch: [element]", () => {
312
+ const err = catchError(() => TypeEqual(MatrixType(FloatType), MatrixType(IntegerType)));
313
+ assert.strictEqual(err.message, "at [element]: expected .Float but got .Integer: incompatible types");
314
+ });
315
+ test("Set key mismatch: [key]", () => {
316
+ const err = catchError(() => TypeEqual(SetType(StringType), SetType(IntegerType)));
317
+ assert.strictEqual(err.message, "at [key]: expected .String but got .Integer: incompatible types");
318
+ });
319
+ test("Dict key mismatch: [key]", () => {
320
+ const err = catchError(() => TypeEqual(DictType(StringType, IntegerType), DictType(IntegerType, IntegerType)));
321
+ assert.strictEqual(err.message, "at [key]: expected .String but got .Integer: incompatible types");
322
+ });
323
+ test("Dict value mismatch: [value]", () => {
324
+ const err = catchError(() => TypeEqual(DictType(StringType, IntegerType), DictType(StringType, FloatType)));
325
+ assert.strictEqual(err.message, "at [value]: expected .Integer but got .Float: incompatible types");
326
+ });
327
+ // --- Struct errors ---
328
+ test("struct field count mismatch", () => {
329
+ const err = catchError(() => TypeEqual(StructType({ x: IntegerType }), StructType({ x: IntegerType, y: FloatType })));
330
+ assert.strictEqual(err.message, "structs contain different number of fields (1 vs 2)");
331
+ });
332
+ test("struct field name mismatch (no path prefix)", () => {
333
+ const err = catchError(() => TypeEqual(StructType({ x: IntegerType }), StructType({ y: IntegerType })));
334
+ assert.strictEqual(err.message, "struct field 0 has mismatched names x and y");
335
+ });
336
+ test("struct field type mismatch: .fieldname path", () => {
337
+ const err = catchError(() => TypeEqual(StructType({ x: IntegerType, y: FloatType }), StructType({ x: IntegerType, y: StringType })));
338
+ assert.strictEqual(err.message, "at .y: expected .Float but got .String: incompatible types");
339
+ });
340
+ test("deep struct: .a.b.c", () => {
341
+ const t1 = StructType({ a: StructType({ b: StructType({ c: IntegerType }) }) });
342
+ const t2 = StructType({ a: StructType({ b: StructType({ c: FloatType }) }) });
343
+ const err = catchError(() => TypeEqual(t1, t2));
344
+ assert.strictEqual(err.message, "at .a.b.c: expected .Integer but got .Float: incompatible types");
345
+ });
346
+ test("5 levels deep: .a[element].b.c.d", () => {
347
+ const t1 = StructType({ a: ArrayType(StructType({ b: StructType({ c: StructType({ d: IntegerType }) }) })) });
348
+ const t2 = StructType({ a: ArrayType(StructType({ b: StructType({ c: StructType({ d: FloatType }) }) })) });
349
+ const err = catchError(() => TypeEqual(t1, t2));
350
+ assert.strictEqual(err.message, "at .a[element].b.c.d: expected .Integer but got .Float: incompatible types");
351
+ });
352
+ test("array element struct field: [element].y", () => {
353
+ const t1 = ArrayType(StructType({ x: IntegerType, y: FloatType }));
354
+ const t2 = ArrayType(StructType({ x: IntegerType, y: StringType }));
355
+ const err = catchError(() => TypeEqual(t1, t2));
356
+ assert.strictEqual(err.message, "at [element].y: expected .Float but got .String: incompatible types");
357
+ });
358
+ test("dict value struct field: [value].x", () => {
359
+ const t1 = DictType(StringType, StructType({ x: IntegerType }));
360
+ const t2 = DictType(StringType, StructType({ x: FloatType }));
361
+ const err = catchError(() => TypeEqual(t1, t2));
362
+ assert.strictEqual(err.message, "at [value].x: expected .Integer but got .Float: incompatible types");
363
+ });
364
+ // --- Variant errors ---
365
+ test("variant case count mismatch with only-in-expected", () => {
366
+ const err = catchError(() => TypeEqual(VariantType({ a: NullType, b: NullType, c: NullType }), VariantType({ a: NullType, c: NullType })));
367
+ assert.strictEqual(err.message, "variants contain different number of cases (3 vs 2); only in expected: b");
368
+ });
369
+ test("variant case count mismatch with only-in-actual", () => {
370
+ const err = catchError(() => TypeEqual(VariantType({ a: NullType }), VariantType({ a: NullType, b: NullType })));
371
+ assert.strictEqual(err.message, "variants contain different number of cases (1 vs 2); only in actual: b");
372
+ });
373
+ test("variant case name mismatch", () => {
374
+ const err = catchError(() => TypeEqual(VariantType({ a: NullType, c: NullType }), VariantType({ a: NullType, b: NullType })));
375
+ assert.strictEqual(err.message, "variant case b is not present in both variants");
376
+ });
377
+ test("variant case type mismatch: .casename path", () => {
378
+ const err = catchError(() => TypeEqual(VariantType({ none: NullType, some: IntegerType }), VariantType({ none: NullType, some: FloatType })));
379
+ assert.strictEqual(err.message, "at .some: expected .Integer but got .Float: incompatible types");
380
+ });
381
+ // --- Function errors ---
382
+ test("function argument count mismatch", () => {
383
+ const err = catchError(() => TypeEqual(FunctionType([IntegerType], NullType), FunctionType([IntegerType, StringType], NullType)));
384
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
385
+ });
386
+ test("function input mismatch: [input N]", () => {
387
+ const err = catchError(() => TypeEqual(FunctionType([IntegerType, StringType], NullType), FunctionType([IntegerType, FloatType], NullType)));
388
+ assert.strictEqual(err.message, "at [input 1]: expected .String but got .Float: incompatible types");
389
+ });
390
+ test("function output mismatch: [output]", () => {
391
+ const err = catchError(() => TypeEqual(FunctionType([IntegerType], StringType), FunctionType([IntegerType], FloatType)));
392
+ assert.strictEqual(err.message, "at [output]: expected .String but got .Float: incompatible types");
393
+ });
394
+ test("async function argument count mismatch", () => {
395
+ const err = catchError(() => TypeEqual(AsyncFunctionType([IntegerType], NullType), AsyncFunctionType([IntegerType, StringType], NullType)));
396
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
397
+ });
398
+ test("async function input mismatch: [input N]", () => {
399
+ const err = catchError(() => TypeEqual(AsyncFunctionType([IntegerType, StringType], NullType), AsyncFunctionType([IntegerType, FloatType], NullType)));
400
+ assert.strictEqual(err.message, "at [input 1]: expected .String but got .Float: incompatible types");
401
+ });
402
+ test("async function output mismatch: [output]", () => {
403
+ const err = catchError(() => TypeEqual(AsyncFunctionType([IntegerType], StringType), AsyncFunctionType([IntegerType], FloatType)));
404
+ assert.strictEqual(err.message, "at [output]: expected .String but got .Float: incompatible types");
405
+ });
406
+ // --- Recursive type mismatches ---
407
+ test("two recursive lists differing in head type: .cons.head", () => {
408
+ const listA = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
409
+ const listB = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: FloatType, tail: self }) }));
410
+ const err = catchError(() => TypeEqual(listA, listB));
411
+ assert.strictEqual(err.message, "at .cons.head: expected .Integer but got .Float: incompatible types");
412
+ });
413
+ test("two recursive trees differing in value type: .value", () => {
414
+ const treeA = RecursiveType(self => StructType({ value: IntegerType, left: OptionType(self), right: OptionType(self) }));
415
+ const treeB = RecursiveType(self => StructType({ value: FloatType, left: OptionType(self), right: OptionType(self) }));
416
+ const err = catchError(() => TypeEqual(treeA, treeB));
417
+ assert.strictEqual(err.message, "at .value: expected .Integer but got .Float: incompatible types");
418
+ });
419
+ test("struct containing recursive tree mismatch: .tree.value", () => {
420
+ const treeA = RecursiveType(self => StructType({ value: IntegerType, left: OptionType(self), right: OptionType(self) }));
421
+ const treeB = RecursiveType(self => StructType({ value: FloatType, left: OptionType(self), right: OptionType(self) }));
422
+ const err = catchError(() => TypeEqual(StructType({ name: StringType, tree: treeA }), StructType({ name: StringType, tree: treeB })));
423
+ assert.strictEqual(err.message, "at .tree.value: expected .Integer but got .Float: incompatible types");
424
+ });
425
+ });
426
+ // ============================================================================
427
+ // TypeUnion - error messages
428
+ // ============================================================================
429
+ describe("TypeUnion error messages", () => {
430
+ // --- Primitive kind mismatch ---
431
+ test("Integer vs Float", () => {
432
+ const err = catchError(() => TypeUnion(IntegerType, FloatType));
433
+ assert.strictEqual(err.message, "expected .Integer but got .Float: incompatible types");
434
+ });
435
+ // --- Container kind mismatches ---
436
+ test("Array vs Integer", () => {
437
+ const err = catchError(() => TypeUnion(ArrayType(IntegerType), IntegerType));
438
+ assert.strictEqual(err.message, "expected .Array .Integer but got .Integer: incompatible types");
439
+ });
440
+ test("Ref vs Integer", () => {
441
+ const err = catchError(() => TypeUnion(RefType(IntegerType), IntegerType));
442
+ assert.strictEqual(err.message, "expected .Ref .Integer but got .Integer: incompatible types");
443
+ });
444
+ test("Struct vs Integer", () => {
445
+ const err = catchError(() => TypeUnion(StructType({ x: IntegerType }), IntegerType));
446
+ assert.strictEqual(err.message, 'expected .Struct [(name="x", type=.Integer)] but got .Integer: incompatible types');
447
+ });
448
+ test("Variant vs Null", () => {
449
+ const err = catchError(() => TypeUnion(VariantType({ a: NullType }), NullType));
450
+ assert.strictEqual(err.message, 'expected .Variant [(name="a", type=.Null)] but got .Null: incompatible types');
451
+ });
452
+ // --- Inner mismatches with path (delegates to TypeEqual) ---
453
+ test("Array element mismatch: [element]", () => {
454
+ const err = catchError(() => TypeUnion(ArrayType(IntegerType), ArrayType(FloatType)));
455
+ assert.strictEqual(err.message, "at [element]: expected .Integer but got .Float: incompatible types");
456
+ });
457
+ test("Ref inner mismatch: [ref]", () => {
458
+ const err = catchError(() => TypeUnion(RefType(IntegerType), RefType(FloatType)));
459
+ assert.strictEqual(err.message, "at [ref]: expected .Integer but got .Float: incompatible types");
460
+ });
461
+ test("Set key mismatch: [key]", () => {
462
+ const err = catchError(() => TypeUnion(SetType(StringType), SetType(IntegerType)));
463
+ assert.strictEqual(err.message, "at [key]: expected .String but got .Integer: incompatible types");
464
+ });
465
+ test("Dict key mismatch: [key]", () => {
466
+ const err = catchError(() => TypeUnion(DictType(StringType, IntegerType), DictType(IntegerType, IntegerType)));
467
+ assert.strictEqual(err.message, "at [key]: expected .String but got .Integer: incompatible types");
468
+ });
469
+ test("Dict value mismatch: [value]", () => {
470
+ const err = catchError(() => TypeUnion(DictType(StringType, IntegerType), DictType(StringType, FloatType)));
471
+ assert.strictEqual(err.message, "at [value]: expected .Integer but got .Float: incompatible types");
472
+ });
473
+ test("Vector element mismatch: [element]", () => {
474
+ const err = catchError(() => TypeUnion(VectorType(FloatType), VectorType(IntegerType)));
475
+ assert.strictEqual(err.message, "at [element]: expected .Float but got .Integer: incompatible types");
476
+ });
477
+ test("Matrix element mismatch: [element]", () => {
478
+ const err = catchError(() => TypeUnion(MatrixType(FloatType), MatrixType(IntegerType)));
479
+ assert.strictEqual(err.message, "at [element]: expected .Float but got .Integer: incompatible types");
480
+ });
481
+ // --- Struct errors ---
482
+ test("struct field count mismatch", () => {
483
+ const err = catchError(() => TypeUnion(StructType({ x: IntegerType }), StructType({ x: IntegerType, y: FloatType })));
484
+ assert.strictEqual(err.message, "structs contain different number of fields (1 vs 2)");
485
+ });
486
+ test("struct field name mismatch", () => {
487
+ const err = catchError(() => TypeUnion(StructType({ x: IntegerType }), StructType({ y: IntegerType })));
488
+ assert.strictEqual(err.message, "struct field 0 has mismatched names x and y");
489
+ });
490
+ test("struct field type mismatch propagates path: .b", () => {
491
+ const err = catchError(() => TypeUnion(StructType({ a: IntegerType, b: FloatType }), StructType({ a: IntegerType, b: StringType })));
492
+ assert.strictEqual(err.message, "at .b: expected .Float but got .String: incompatible types");
493
+ });
494
+ // --- Variant case mismatch ---
495
+ test("variant case type mismatch: .b", () => {
496
+ const err = catchError(() => TypeUnion(VariantType({ a: IntegerType, b: FloatType }), VariantType({ a: IntegerType, b: StringType })));
497
+ assert.strictEqual(err.message, "at .b: expected .Float but got .String: incompatible types");
498
+ });
499
+ // --- Function errors ---
500
+ test("function argument count mismatch (Fn/Fn)", () => {
501
+ const err = catchError(() => TypeUnion(FunctionType([IntegerType], NullType), FunctionType([IntegerType, StringType], NullType)));
502
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
503
+ });
504
+ test("function argument count mismatch (Fn/AsyncFn)", () => {
505
+ const err = catchError(() => TypeUnion(FunctionType([IntegerType], NullType), AsyncFunctionType([IntegerType, StringType], NullType)));
506
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
507
+ });
508
+ test("function argument count mismatch (AsyncFn/Fn)", () => {
509
+ const err = catchError(() => TypeUnion(AsyncFunctionType([IntegerType], NullType), FunctionType([IntegerType, StringType], NullType)));
510
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
511
+ });
512
+ test("function argument count mismatch (AsyncFn/AsyncFn)", () => {
513
+ const err = catchError(() => TypeUnion(AsyncFunctionType([IntegerType], NullType), AsyncFunctionType([IntegerType, StringType], NullType)));
514
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
515
+ });
516
+ test("function output mismatch: [output]", () => {
517
+ const err = catchError(() => TypeUnion(FunctionType([IntegerType], StringType), FunctionType([IntegerType], FloatType)));
518
+ assert.strictEqual(err.message, "at [output]: expected .String but got .Float: incompatible types");
519
+ });
520
+ // --- Multi-level ---
521
+ test("deep path through struct and array: .a[element]", () => {
522
+ const err = catchError(() => TypeUnion(StructType({ a: ArrayType(IntegerType) }), StructType({ a: ArrayType(FloatType) })));
523
+ assert.strictEqual(err.message, "at .a[element]: expected .Integer but got .Float: incompatible types");
524
+ });
525
+ });
526
+ // ============================================================================
527
+ // TypeIntersect - error messages
528
+ // ============================================================================
529
+ describe("TypeIntersect error messages", () => {
530
+ // --- Primitive kind mismatch ---
531
+ test("Integer vs Float", () => {
532
+ const err = catchError(() => TypeIntersect(IntegerType, FloatType));
533
+ assert.strictEqual(err.message, "expected .Integer but got .Float: incompatible types");
534
+ });
535
+ // --- Container kind mismatches ---
536
+ test("Array vs Integer", () => {
537
+ const err = catchError(() => TypeIntersect(ArrayType(IntegerType), IntegerType));
538
+ assert.strictEqual(err.message, "expected .Array .Integer but got .Integer: incompatible types");
539
+ });
540
+ test("Struct vs Integer", () => {
541
+ const err = catchError(() => TypeIntersect(StructType({ x: IntegerType }), IntegerType));
542
+ assert.strictEqual(err.message, 'expected .Struct [(name="x", type=.Integer)] but got .Integer: incompatible types');
543
+ });
544
+ // --- Inner mismatches with path ---
545
+ test("Array element mismatch: [element]", () => {
546
+ const err = catchError(() => TypeIntersect(ArrayType(IntegerType), ArrayType(FloatType)));
547
+ assert.strictEqual(err.message, "at [element]: expected .Integer but got .Float: incompatible types");
548
+ });
549
+ test("Ref inner mismatch: [ref]", () => {
550
+ const err = catchError(() => TypeIntersect(RefType(IntegerType), RefType(FloatType)));
551
+ assert.strictEqual(err.message, "at [ref]: expected .Integer but got .Float: incompatible types");
552
+ });
553
+ test("Dict value mismatch: [value]", () => {
554
+ const err = catchError(() => TypeIntersect(DictType(StringType, IntegerType), DictType(StringType, FloatType)));
555
+ assert.strictEqual(err.message, "at [value]: expected .Integer but got .Float: incompatible types");
556
+ });
557
+ // --- Struct errors ---
558
+ test("struct field count mismatch", () => {
559
+ const err = catchError(() => TypeIntersect(StructType({ x: IntegerType }), StructType({ x: IntegerType, y: FloatType })));
560
+ assert.strictEqual(err.message, "structs contain different number of fields (1 vs 2)");
561
+ });
562
+ test("struct field name mismatch", () => {
563
+ const err = catchError(() => TypeIntersect(StructType({ x: IntegerType }), StructType({ y: IntegerType })));
564
+ assert.strictEqual(err.message, "struct field 0 has mismatched names x and y");
565
+ });
566
+ test("struct field type mismatch: .b", () => {
567
+ const err = catchError(() => TypeIntersect(StructType({ a: IntegerType, b: FloatType }), StructType({ a: IntegerType, b: StringType })));
568
+ assert.strictEqual(err.message, "at .b: expected .Float but got .String: incompatible types");
569
+ });
570
+ // --- Variant errors ---
571
+ test("variants no overlapping cases", () => {
572
+ const err = catchError(() => TypeIntersect(VariantType({ a: NullType }), VariantType({ b: NullType })));
573
+ assert.strictEqual(err.message, "variants have no overlapping cases");
574
+ });
575
+ test("variant case type mismatch: .b", () => {
576
+ const err = catchError(() => TypeIntersect(VariantType({ a: IntegerType, b: FloatType }), VariantType({ a: IntegerType, b: StringType })));
577
+ assert.strictEqual(err.message, "at .b: expected .Float but got .String: incompatible types");
578
+ });
579
+ // --- Function errors ---
580
+ test("function argument count mismatch", () => {
581
+ const err = catchError(() => TypeIntersect(FunctionType([IntegerType], NullType), FunctionType([IntegerType, StringType], NullType)));
582
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
583
+ });
584
+ test("function argument count mismatch (Fn/AsyncFn)", () => {
585
+ const err = catchError(() => TypeIntersect(FunctionType([IntegerType], NullType), AsyncFunctionType([IntegerType, StringType], NullType)));
586
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
587
+ });
588
+ test("function argument count mismatch (AsyncFn/Fn)", () => {
589
+ const err = catchError(() => TypeIntersect(AsyncFunctionType([IntegerType], NullType), FunctionType([IntegerType, StringType], NullType)));
590
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
591
+ });
592
+ test("function argument count mismatch (AsyncFn/AsyncFn)", () => {
593
+ const err = catchError(() => TypeIntersect(AsyncFunctionType([IntegerType], NullType), AsyncFunctionType([IntegerType, StringType], NullType)));
594
+ assert.strictEqual(err.message, "functions take different number of arguments (1 vs 2)");
595
+ });
596
+ test("function output mismatch: [output]", () => {
597
+ const err = catchError(() => TypeIntersect(FunctionType([IntegerType], StringType), FunctionType([IntegerType], FloatType)));
598
+ assert.strictEqual(err.message, "at [output]: expected .String but got .Float: incompatible types");
599
+ });
600
+ // --- Multi-level ---
601
+ test("deep path: .a[element]", () => {
602
+ const err = catchError(() => TypeIntersect(StructType({ a: ArrayType(IntegerType) }), StructType({ a: ArrayType(FloatType) })));
603
+ assert.strictEqual(err.message, "at .a[element]: expected .Integer but got .Float: incompatible types");
604
+ });
605
+ });
606
+ // ============================================================================
607
+ // TypeWiden - error messages
608
+ // ============================================================================
609
+ describe("TypeWiden error messages", () => {
610
+ // --- Primitive kind mismatch ---
611
+ test("Integer vs Float", () => {
612
+ const err = catchError(() => TypeWiden(IntegerType, FloatType));
613
+ assert.strictEqual(err.message, "expected .Integer but got .Float: incompatible types");
614
+ });
615
+ // --- Container kind mismatches ---
616
+ test("Array vs Integer", () => {
617
+ const err = catchError(() => TypeWiden(ArrayType(IntegerType), IntegerType));
618
+ assert.strictEqual(err.message, "expected .Array .Integer but got .Integer: incompatible types");
619
+ });
620
+ test("Struct vs Integer", () => {
621
+ const err = catchError(() => TypeWiden(StructType({ x: IntegerType }), IntegerType));
622
+ assert.strictEqual(err.message, 'expected .Struct [(name="x", type=.Integer)] but got .Integer: incompatible types');
623
+ });
624
+ // --- Inner mismatches with path ---
625
+ test("Array element mismatch: [element]", () => {
626
+ const err = catchError(() => TypeWiden(ArrayType(IntegerType), ArrayType(FloatType)));
627
+ assert.strictEqual(err.message, "at [element]: expected .Integer but got .Float: incompatible types");
628
+ });
629
+ test("Ref inner mismatch: [ref]", () => {
630
+ const err = catchError(() => TypeWiden(RefType(IntegerType), RefType(FloatType)));
631
+ assert.strictEqual(err.message, "at [ref]: expected .Integer but got .Float: incompatible types");
632
+ });
633
+ test("Dict value mismatch: [value]", () => {
634
+ const err = catchError(() => TypeWiden(DictType(StringType, IntegerType), DictType(StringType, FloatType)));
635
+ assert.strictEqual(err.message, "at [value]: expected .Integer but got .Float: incompatible types");
636
+ });
637
+ test("Vector element mismatch: [element]", () => {
638
+ const err = catchError(() => TypeWiden(VectorType(FloatType), VectorType(IntegerType)));
639
+ assert.strictEqual(err.message, "at [element]: expected .Float but got .Integer: incompatible types");
640
+ });
641
+ // --- Struct errors ---
642
+ test("struct field count mismatch", () => {
643
+ const err = catchError(() => TypeWiden(StructType({ x: IntegerType }), StructType({ x: IntegerType, y: FloatType })));
644
+ assert.strictEqual(err.message, "structs contain different number of fields (1 vs 2)");
645
+ });
646
+ test("struct field name mismatch", () => {
647
+ const err = catchError(() => TypeWiden(StructType({ x: IntegerType }), StructType({ y: IntegerType })));
648
+ assert.strictEqual(err.message, "struct field 0 has mismatched names x and y");
649
+ });
650
+ test("struct field type mismatch: .b", () => {
651
+ const err = catchError(() => TypeWiden(StructType({ a: IntegerType, b: FloatType }), StructType({ a: IntegerType, b: StringType })));
652
+ assert.strictEqual(err.message, "at .b: expected .Float but got .String: incompatible types");
653
+ });
654
+ // --- Variant case mismatch ---
655
+ test("variant case type mismatch: .b", () => {
656
+ const err = catchError(() => TypeWiden(VariantType({ a: IntegerType, b: FloatType }), VariantType({ a: IntegerType, b: StringType })));
657
+ assert.strictEqual(err.message, "at .b: expected .Float but got .String: incompatible types");
658
+ });
659
+ // --- Multi-level ---
660
+ test("deep path: .a[element]", () => {
661
+ const err = catchError(() => TypeWiden(StructType({ a: ArrayType(IntegerType) }), StructType({ a: ArrayType(FloatType) })));
662
+ assert.strictEqual(err.message, "at .a[element]: expected .Integer but got .Float: incompatible types");
663
+ });
664
+ });
665
+ //# sourceMappingURL=types.error.spec.js.map