@elaraai/east 0.0.1-beta.8 → 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
@@ -1,670 +0,0 @@
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 {} from "../types.js";
6
- import { isVariant, variant } from "../containers/variant.js";
7
- import { BufferWriter, StreamBufferReader } from "./binary-utils.js";
8
- import { encodeBeast2ValueToBufferFor, MAGIC_BYTES } from "./beast2.js";
9
- import { EastTypeValueType, toEastTypeValue } from "../type_of_type.js";
10
- import { equalFor } from "../comparison.js";
11
- import { printFor } from "./east.js";
12
- import { ref } from "../containers/ref.js";
13
- const printTypeValue = printFor(EastTypeValueType);
14
- const isTypeValueEqual = equalFor(EastTypeValueType);
15
- // Chunk size for streaming (64KB - good balance of memory vs throughput)
16
- const CHUNK_SIZE = 64 * 1024;
17
- /**
18
- * Determines if a type can be encoded synchronously without needing to yield.
19
- * Sync types are small and bounded - they can't cause excessive buffer growth.
20
- */
21
- function isSyncType(type) {
22
- switch (type.type) {
23
- case "Never":
24
- case "Null":
25
- case "Boolean":
26
- case "Integer":
27
- case "Float":
28
- case "DateTime":
29
- return true;
30
- case "String":
31
- case "Blob":
32
- case "Ref":
33
- case "Array":
34
- case "Set":
35
- case "Dict":
36
- // These can be large
37
- return false;
38
- case "Struct":
39
- // Sync only if all fields are sync
40
- return type.value.every(({ type }) => isSyncType(type));
41
- case "Variant":
42
- // Sync only if all cases are sync
43
- return type.value.every(({ type }) => isSyncType(type));
44
- case "Recursive":
45
- return false;
46
- case "Function":
47
- return true; // Will throw, but no need to yield
48
- case "AsyncFunction":
49
- return true; // Will throw, but no need to yield
50
- default:
51
- return false;
52
- }
53
- }
54
- function encodeBeast2ValueToStreamFor(type, typeCtx = []) {
55
- // Convert EastType to EastTypeValue if necessary
56
- if (!isVariant(type)) {
57
- type = toEastTypeValue(type);
58
- }
59
- // For fully sync types, use the sync encoder directly
60
- if (isSyncType(type)) {
61
- const syncEncoder = encodeBeast2ValueToBufferFor(type);
62
- return function* (value, writer, ctx) {
63
- syncEncoder(value, writer, ctx);
64
- };
65
- }
66
- // Async types - need generator logic
67
- if (type.type === "String") {
68
- return function* (value, writer, _ctx) {
69
- writer.writeStringUtf8Varint(value);
70
- if (writer.size >= CHUNK_SIZE) {
71
- yield writer.pop();
72
- }
73
- };
74
- }
75
- else if (type.type === "Blob") {
76
- return function* (value, writer, _ctx) {
77
- // Write length prefix
78
- writer.writeVarint(value.length);
79
- // Check if we should chunk the blob
80
- if (value.length > CHUNK_SIZE) {
81
- // Large blob - flush buffer first, then send blob in chunks
82
- if (writer.size > 0) {
83
- yield writer.pop();
84
- }
85
- let offset = 0;
86
- while (offset < value.length) {
87
- const chunkSize = Math.min(CHUNK_SIZE, value.length - offset);
88
- const chunk = value.subarray(offset, offset + chunkSize);
89
- writer.writeBytes(chunk);
90
- yield writer.pop();
91
- offset += chunkSize;
92
- }
93
- }
94
- else {
95
- // Small blob - write it all
96
- writer.writeBytes(value);
97
- if (writer.size >= CHUNK_SIZE) {
98
- yield writer.pop();
99
- }
100
- }
101
- };
102
- }
103
- else if (type.type === "Ref") {
104
- // Branch on whether value type is sync
105
- if (isSyncType(type.value)) {
106
- const syncValueEncoder = encodeBeast2ValueToBufferFor(type.value);
107
- return function* (value, writer, ctx = { refs: new Map() }) {
108
- // Check for backreference
109
- if (ctx.refs.has(value)) {
110
- const offset = ctx.refs.get(value);
111
- writer.writeVarint(writer.currentOffset - offset);
112
- return;
113
- }
114
- // Write inline marker and register
115
- writer.writeVarint(0);
116
- ctx.refs.set(value, writer.currentOffset);
117
- syncValueEncoder(value.value, writer, ctx);
118
- };
119
- }
120
- else {
121
- // Use late binding for async value type
122
- let valueGen;
123
- const ret = function* (value, writer, ctx = { refs: new Map() }) {
124
- // Check for backreference
125
- if (ctx.refs.has(value)) {
126
- const offset = ctx.refs.get(value);
127
- writer.writeVarint(writer.currentOffset - offset);
128
- return;
129
- }
130
- // Write inline marker and register
131
- writer.writeVarint(0);
132
- ctx.refs.set(value, writer.currentOffset);
133
- yield* valueGen(value.value, writer, ctx);
134
- };
135
- typeCtx.push(ret);
136
- valueGen = encodeBeast2ValueToStreamFor(type.value, typeCtx);
137
- typeCtx.pop();
138
- return ret;
139
- }
140
- }
141
- else if (type.type === "Array") {
142
- // Branch on whether value type is sync
143
- if (isSyncType(type.value)) {
144
- const syncValueEncoder = encodeBeast2ValueToBufferFor(type.value);
145
- return function* (value, writer, ctx = { refs: new Map() }) {
146
- // Check for backreference
147
- if (ctx.refs.has(value)) {
148
- const offset = ctx.refs.get(value);
149
- writer.writeVarint(writer.currentOffset - offset);
150
- return;
151
- }
152
- // Write inline marker and register
153
- writer.writeVarint(0);
154
- ctx.refs.set(value, writer.currentOffset);
155
- // Encode length
156
- writer.writeVarint(value.length);
157
- for (const item of value) {
158
- syncValueEncoder(item, writer, ctx);
159
- if (writer.size >= CHUNK_SIZE) {
160
- yield writer.pop();
161
- }
162
- }
163
- };
164
- }
165
- else {
166
- // Use late binding for async value type
167
- let valueGen;
168
- const ret = function* (value, writer, ctx = { refs: new Map() }) {
169
- // Check for backreference
170
- if (ctx.refs.has(value)) {
171
- const offset = ctx.refs.get(value);
172
- writer.writeVarint(writer.currentOffset - offset);
173
- return;
174
- }
175
- // Write inline marker and register
176
- writer.writeVarint(0);
177
- ctx.refs.set(value, writer.currentOffset);
178
- // Encode length
179
- writer.writeVarint(value.length);
180
- for (const item of value) {
181
- yield* valueGen(item, writer, ctx);
182
- if (writer.size >= CHUNK_SIZE) {
183
- yield writer.pop();
184
- }
185
- }
186
- };
187
- typeCtx.push(ret);
188
- valueGen = encodeBeast2ValueToStreamFor(type.value, typeCtx);
189
- typeCtx.pop();
190
- return ret;
191
- }
192
- }
193
- else if (type.type === "Set") {
194
- // Keys are assumed small - always use sync
195
- const syncKeyEncoder = encodeBeast2ValueToBufferFor(type.value);
196
- return function* (value, writer, ctx = { refs: new Map() }) {
197
- // Check for backreference
198
- if (ctx.refs.has(value)) {
199
- const offset = ctx.refs.get(value);
200
- writer.writeVarint(writer.currentOffset - offset);
201
- return;
202
- }
203
- // Write inline marker and register
204
- writer.writeVarint(0);
205
- ctx.refs.set(value, writer.currentOffset);
206
- // Encode length
207
- writer.writeVarint(value.size);
208
- for (const key of value) {
209
- syncKeyEncoder(key, writer, ctx);
210
- if (writer.size >= CHUNK_SIZE) {
211
- yield writer.pop();
212
- }
213
- }
214
- };
215
- }
216
- else if (type.type === "Dict") {
217
- // Keys are assumed small - always use sync. Check value type.
218
- const syncKeyEncoder = encodeBeast2ValueToBufferFor(type.value.key);
219
- if (isSyncType(type.value.value)) {
220
- const syncValueEncoder = encodeBeast2ValueToBufferFor(type.value.value);
221
- return function* (value, writer, ctx = { refs: new Map() }) {
222
- // Check for backreference
223
- if (ctx.refs.has(value)) {
224
- const offset = ctx.refs.get(value);
225
- writer.writeVarint(writer.currentOffset - offset);
226
- return;
227
- }
228
- // Write inline marker and register
229
- writer.writeVarint(0);
230
- ctx.refs.set(value, writer.currentOffset);
231
- // Encode length
232
- writer.writeVarint(value.size);
233
- for (const [k, v] of value) {
234
- syncKeyEncoder(k, writer, ctx);
235
- syncValueEncoder(v, writer, ctx);
236
- if (writer.size >= CHUNK_SIZE) {
237
- yield writer.pop();
238
- }
239
- }
240
- };
241
- }
242
- else {
243
- // Use late binding for async value type
244
- let valueGen;
245
- const ret = function* (value, writer, ctx = { refs: new Map() }) {
246
- // Check for backreference
247
- if (ctx.refs.has(value)) {
248
- const offset = ctx.refs.get(value);
249
- writer.writeVarint(writer.currentOffset - offset);
250
- return;
251
- }
252
- // Write inline marker and register
253
- writer.writeVarint(0);
254
- ctx.refs.set(value, writer.currentOffset);
255
- // Encode length
256
- writer.writeVarint(value.size);
257
- for (const [k, v] of value) {
258
- syncKeyEncoder(k, writer, ctx);
259
- yield* valueGen(v, writer, ctx);
260
- if (writer.size >= CHUNK_SIZE) {
261
- yield writer.pop();
262
- }
263
- }
264
- };
265
- typeCtx.push(ret);
266
- valueGen = encodeBeast2ValueToStreamFor(type.value.value, typeCtx);
267
- typeCtx.pop();
268
- return ret;
269
- }
270
- }
271
- else if (type.type === "Struct") {
272
- // Annotate each field with sync flag and appropriate encoder
273
- const fieldInfo = [];
274
- const ret = function* (value, writer, _ctx) {
275
- // Struct is immutable - no backreference checking needed
276
- // Encode fields directly
277
- for (const { name, isSync, encoder } of fieldInfo) {
278
- if (isSync) {
279
- encoder(value[name], writer);
280
- }
281
- else {
282
- yield* encoder(value[name], writer);
283
- }
284
- }
285
- };
286
- typeCtx.push(ret);
287
- for (const { name, type: fieldType } of type.value)
288
- fieldInfo.push({
289
- name,
290
- isSync: isSyncType(fieldType),
291
- encoder: isSyncType(fieldType)
292
- ? encodeBeast2ValueToBufferFor(fieldType)
293
- : encodeBeast2ValueToStreamFor(fieldType, typeCtx),
294
- });
295
- typeCtx.pop();
296
- return ret;
297
- }
298
- else if (type.type === "Variant") {
299
- // Annotate each case with sync flag and appropriate encoder
300
- const caseInfo = {};
301
- const ret = function* (value, writer, _ctx) {
302
- // Variant is immutable - no backreference checking needed
303
- // Encode tag and value directly
304
- const tag = value.type;
305
- const { tagIndex, isSync, encoder } = caseInfo[tag]; // Assume valid input
306
- writer.writeVarint(tagIndex);
307
- if (isSync) {
308
- encoder(value.value, writer);
309
- }
310
- else {
311
- yield* encoder(value.value, writer);
312
- }
313
- };
314
- typeCtx.push(ret);
315
- let i = 0;
316
- for (const { name, type: caseType } of type.value) {
317
- caseInfo[name] = {
318
- tagIndex: i,
319
- isSync: isSyncType(caseType),
320
- encoder: isSyncType(caseType)
321
- ? encodeBeast2ValueToBufferFor(caseType)
322
- : encodeBeast2ValueToStreamFor(caseType, typeCtx),
323
- };
324
- i += 1;
325
- }
326
- typeCtx.pop();
327
- return ret;
328
- }
329
- else if (type.type === "Recursive") {
330
- // Type stack lookup: index from the end
331
- const targetEncoder = typeCtx[typeCtx.length - Number(type.value)];
332
- if (!targetEncoder) {
333
- throw new Error(`Recursive type depth ${type.value} exceeds type context stack size ${typeCtx.length}`);
334
- }
335
- return targetEncoder;
336
- }
337
- else {
338
- // Should never reach here - all types handled above
339
- throw new Error(`Unhandled type: ${type.type}`);
340
- }
341
- }
342
- const typeEncoder = encodeBeast2ValueToBufferFor(EastTypeValueType);
343
- export function encodeBeast2ToStreamFor(type) {
344
- // Convert EastType to EastTypeValue if necessary
345
- if (!isVariant(type)) {
346
- type = toEastTypeValue(type);
347
- }
348
- const valueGen = encodeBeast2ValueToStreamFor(type);
349
- return (value) => {
350
- let writer;
351
- let generator;
352
- let ctx;
353
- return new ReadableStream({
354
- start(controller) {
355
- // Initialize writer and write header
356
- writer = new BufferWriter();
357
- writer.writeBytes(MAGIC_BYTES);
358
- // Write type schema
359
- typeEncoder(type, writer, { refs: new Map() });
360
- // Check if header exceeded chunk size (rare)
361
- if (writer.size >= CHUNK_SIZE) {
362
- controller.enqueue(writer.pop());
363
- }
364
- // Create context for value encoding
365
- ctx = { refs: new Map() };
366
- // Create value generator
367
- generator = valueGen(value, writer, ctx);
368
- },
369
- pull(controller) {
370
- while (true) {
371
- const { done, value: chunk } = generator.next();
372
- if (done) {
373
- // Flush any remaining data
374
- if (writer.size > 0) {
375
- controller.enqueue(writer.pop());
376
- }
377
- controller.close();
378
- return;
379
- }
380
- if (chunk !== undefined) {
381
- controller.enqueue(chunk);
382
- return; // Backpressure - wait for next pull()
383
- }
384
- // chunk is void from yield* delegation - keep looping
385
- }
386
- },
387
- });
388
- };
389
- }
390
- /**
391
- * Create a streaming decoder function for a given Beast v2 type.
392
- * Factory pattern: analyzes type once, returns async decoder.
393
- */
394
- function decodeBeast2ValueFromStreamFor(type, typeCtx = []) {
395
- if (type.type === "Never") {
396
- return (_reader, _ctx) => { throw new Error(`Cannot decode Never type`); };
397
- }
398
- else if (type.type === "Null") {
399
- return (_reader, _ctx) => null;
400
- }
401
- else if (type.type === "Boolean") {
402
- return async (reader, _ctx) => {
403
- const byte = await reader.readByte();
404
- return byte !== 0;
405
- };
406
- }
407
- else if (type.type === "Integer") {
408
- return (reader, _ctx) => reader.readZigzag();
409
- }
410
- else if (type.type === "Float") {
411
- return (reader, _ctx) => reader.readFloat64LE();
412
- }
413
- else if (type.type === "String") {
414
- return (reader, _ctx) => reader.readStringUtf8Varint();
415
- }
416
- else if (type.type === "DateTime") {
417
- return (reader, _ctx) => {
418
- const millis = reader.readZigzag();
419
- if (millis instanceof Promise) {
420
- return millis.then(m => new Date(Number(m)));
421
- }
422
- return new Date(Number(millis));
423
- };
424
- }
425
- else if (type.type === "Blob") {
426
- return async (reader, _ctx) => {
427
- const length = await reader.readVarint();
428
- const blob = new Uint8Array(length);
429
- await reader.readBytes(blob);
430
- return blob;
431
- };
432
- }
433
- else if (type.type === "Ref") {
434
- // Use late binding for element decoder
435
- let elemDecoder;
436
- const ret = async (reader, ctx = { refs: new Map() }) => {
437
- const startOffset = reader.position;
438
- const refOrZero = await reader.readVarint();
439
- // Check if this is a backreference
440
- if (refOrZero > 0) {
441
- const targetOffset = startOffset - refOrZero;
442
- if (!ctx.refs.has(targetOffset)) {
443
- throw new Error(`Undefined backreference at offset ${startOffset}, target ${targetOffset}`);
444
- }
445
- return ctx.refs.get(targetOffset);
446
- }
447
- // Inline ref
448
- const result = ref(undefined);
449
- ctx.refs.set(startOffset, result);
450
- result.value = await elemDecoder(reader, ctx);
451
- return result;
452
- };
453
- typeCtx.push(ret);
454
- elemDecoder = decodeBeast2ValueFromStreamFor(type.value, typeCtx);
455
- typeCtx.pop();
456
- return ret;
457
- }
458
- else if (type.type === "Array") {
459
- // Use late binding for element decoder
460
- let elemDecoder;
461
- const ret = async (reader, ctx = { refs: new Map() }) => {
462
- const startOffset = reader.position;
463
- const refOrZero = await reader.readVarint();
464
- // Check if this is a backreference
465
- if (refOrZero > 0) {
466
- const targetOffset = startOffset - refOrZero;
467
- if (!ctx.refs.has(targetOffset)) {
468
- throw new Error(`Undefined backreference at offset ${startOffset}, target ${targetOffset}`);
469
- }
470
- return ctx.refs.get(targetOffset);
471
- }
472
- // Inline array
473
- const result = [];
474
- ctx.refs.set(startOffset, result);
475
- const length = await reader.readVarint();
476
- for (let i = 0; i < length; i++) {
477
- result.push(await elemDecoder(reader, ctx));
478
- }
479
- return result;
480
- };
481
- typeCtx.push(ret);
482
- elemDecoder = decodeBeast2ValueFromStreamFor(type.value, typeCtx);
483
- typeCtx.pop();
484
- return ret;
485
- }
486
- else if (type.type === "Set") {
487
- // Keys are standalone - no need for late binding
488
- const keyDecoder = decodeBeast2ValueFromStreamFor(type.value, []);
489
- return async (reader, ctx = { refs: new Map() }) => {
490
- const startOffset = reader.position;
491
- const refOrZero = await reader.readVarint();
492
- // Check if this is a backreference
493
- if (refOrZero > 0) {
494
- const targetOffset = startOffset - refOrZero;
495
- if (!ctx.refs.has(targetOffset)) {
496
- throw new Error(`Undefined backreference at offset ${startOffset}, target ${targetOffset}`);
497
- }
498
- return ctx.refs.get(targetOffset);
499
- }
500
- // Inline set
501
- const result = new Set();
502
- ctx.refs.set(startOffset, result);
503
- const length = await reader.readVarint();
504
- for (let i = 0; i < length; i++) {
505
- result.add(await keyDecoder(reader));
506
- }
507
- return result;
508
- };
509
- }
510
- else if (type.type === "Dict") {
511
- // Keys are standalone, values use late binding
512
- const keyDecoder = decodeBeast2ValueFromStreamFor(type.value.key, []);
513
- let valueDecoder;
514
- const ret = async (reader, ctx = { refs: new Map() }) => {
515
- const startOffset = reader.position;
516
- const refOrZero = await reader.readVarint();
517
- // Check if this is a backreference
518
- if (refOrZero > 0) {
519
- const targetOffset = startOffset - refOrZero;
520
- if (!ctx.refs.has(targetOffset)) {
521
- throw new Error(`Undefined backreference at offset ${startOffset}, target ${targetOffset}`);
522
- }
523
- return ctx.refs.get(targetOffset);
524
- }
525
- // Inline dict
526
- const result = new Map();
527
- ctx.refs.set(startOffset, result);
528
- const length = await reader.readVarint();
529
- for (let i = 0; i < length; i++) {
530
- const key = await keyDecoder(reader);
531
- const value = await valueDecoder(reader, ctx);
532
- result.set(key, value);
533
- }
534
- return result;
535
- };
536
- typeCtx.push(ret);
537
- valueDecoder = decodeBeast2ValueFromStreamFor(type.value.value, typeCtx);
538
- typeCtx.pop();
539
- return ret;
540
- }
541
- else if (type.type === "Struct") {
542
- // Struct is immutable - fields use typeCtx for recursive types
543
- let fieldDecoders = [];
544
- const ret = async (reader, _ctx) => {
545
- // Struct is immutable - no backreference checking needed
546
- const result = {};
547
- for (const [key, decoder] of fieldDecoders) {
548
- result[key] = await decoder(reader);
549
- }
550
- return result;
551
- };
552
- typeCtx.push(ret);
553
- for (const { name, type: fieldType } of type.value) {
554
- fieldDecoders.push([name, decodeBeast2ValueFromStreamFor(fieldType, typeCtx)]);
555
- }
556
- ;
557
- typeCtx.pop();
558
- return ret;
559
- }
560
- else if (type.type === "Variant") {
561
- // Variant is immutable - cases use typeCtx for recursive types
562
- let caseDecoders = [];
563
- const ret = async (reader, _ctx) => {
564
- // Variant is immutable - no backreference checking needed
565
- const tagIndex = await reader.readVarint();
566
- if (tagIndex >= caseDecoders.length) {
567
- throw new Error(`Invalid variant tag ${tagIndex}`);
568
- }
569
- const [caseName, caseDecoder] = caseDecoders[tagIndex];
570
- const value = await caseDecoder(reader);
571
- return variant(caseName, value);
572
- };
573
- typeCtx.push(ret);
574
- for (const { name, type: caseType } of type.value) {
575
- caseDecoders.push([name, decodeBeast2ValueFromStreamFor(caseType, typeCtx)]);
576
- }
577
- typeCtx.pop();
578
- return ret;
579
- }
580
- else if (type.type === "Recursive") {
581
- // Type stack lookup: index from the end
582
- const targetDecoder = typeCtx[typeCtx.length - Number(type.value)];
583
- if (!targetDecoder) {
584
- throw new Error(`Recursive type depth ${type.value} exceeds type context stack size ${typeCtx.length}`);
585
- }
586
- return targetDecoder;
587
- }
588
- else if (type.type === "Function") {
589
- return (_reader, _ctx) => { throw new Error(`Functions cannot be deserialized`); };
590
- }
591
- else if (type.type === "AsyncFunction") {
592
- return (_reader, _ctx) => { throw new Error(`AsyncFunctions cannot be deserialized`); };
593
- }
594
- else {
595
- throw new Error(`Unhandled type ${type.type}`);
596
- }
597
- }
598
- /**
599
- * Internal helper to decode a value from a stream.
600
- * Uses the streaming decoder factory with context threading.
601
- */
602
- async function decodeBeast2ValueFromStream(type, reader) {
603
- const decoder = decodeBeast2ValueFromStreamFor(type);
604
- const ctx = { refs: new Map() };
605
- return await decoder(reader, ctx);
606
- }
607
- const streamingTypeDecode = decodeBeast2ValueFromStreamFor(EastTypeValueType);
608
- /**
609
- * Decode a Beast v2 format stream to an East value.
610
- * Reads the type schema from the stream and returns both type and value.
611
- *
612
- * @param stream The input stream to decode
613
- * @returns Promise resolving to { type, value }
614
- */
615
- export async function decodeBeast2FromStream(stream) {
616
- const reader = new StreamBufferReader(stream);
617
- try {
618
- // Verify magic bytes
619
- for (let i = 0; i < MAGIC_BYTES.length; i++) {
620
- const byte = await reader.readByte();
621
- if (byte !== MAGIC_BYTES[i]) {
622
- throw new Error(`Invalid Beast v2 magic bytes at offset ${i}: expected 0x${MAGIC_BYTES[i].toString(16)}, got 0x${byte.toString(16)}`);
623
- }
624
- }
625
- // Decode type schema directly from stream
626
- const type = await streamingTypeDecode(reader, { refs: new Map() });
627
- // Decode value
628
- const value = await decodeBeast2ValueFromStream(type, reader);
629
- return { type, value };
630
- }
631
- finally {
632
- await reader.release();
633
- }
634
- }
635
- /**
636
- * Create a streaming decoder for a specific Beast v2 type.
637
- * Factory pattern: the type is verified once, returns async decoder.
638
- *
639
- * @param type The expected type to decode
640
- * @returns A function that takes a stream and returns a Promise of the decoded value
641
- */
642
- export function decodeBeast2FromStreamFor(type) {
643
- const valueDecoder = decodeBeast2ValueFromStreamFor(type);
644
- return async (stream) => {
645
- const reader = new StreamBufferReader(stream);
646
- try {
647
- // Verify magic bytes
648
- for (let i = 0; i < MAGIC_BYTES.length; i++) {
649
- const byte = await reader.readByte();
650
- if (byte !== MAGIC_BYTES[i]) {
651
- throw new Error(`Invalid Beast v2 magic bytes at offset ${i}: expected 0x${MAGIC_BYTES[i].toString(16)}, got 0x${byte.toString(16)}`);
652
- }
653
- }
654
- // Decode type schema directly from stream
655
- const decodedType = await streamingTypeDecode(reader, { refs: new Map() });
656
- // Verify type matches expected type
657
- if (!isTypeValueEqual(decodedType, type)) {
658
- throw new Error(`Type mismatch: expected ${printTypeValue(type)}, got ${printTypeValue(decodedType)}`);
659
- }
660
- // Decode value with context
661
- const ctx = { refs: new Map() };
662
- const value = await valueDecoder(reader, ctx);
663
- return value;
664
- }
665
- finally {
666
- await reader.release();
667
- }
668
- };
669
- }
670
- //# sourceMappingURL=beast2-stream.js.map