@bldrs-ai/conway 1.389.1221 → 1.394.1504

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 (382) hide show
  1. package/README.md +36 -22
  2. package/compiled/Dist/ConwayGeomWasmNode.js +0 -0
  3. package/compiled/Dist/ConwayGeomWasmNodeMT.js +0 -0
  4. package/compiled/Dist/ConwayGeomWasmWeb.js +0 -0
  5. package/compiled/Dist/ConwayGeomWasmWebMT.js +1 -1
  6. package/compiled/Dist/ConwayGeomWasmWebMT.wasm +0 -0
  7. package/compiled/dependencies/conway-geom/Dist/ConwayGeomWasmNode.js +0 -0
  8. package/compiled/dependencies/conway-geom/Dist/ConwayGeomWasmNodeMT.js +0 -0
  9. package/compiled/dependencies/conway-geom/Dist/ConwayGeomWasmWeb.js +0 -0
  10. package/compiled/dependencies/conway-geom/Dist/ConwayGeomWasmWebMT.js +1 -1
  11. package/compiled/dependencies/conway-geom/Dist/ConwayGeomWasmWebMT.wasm +0 -0
  12. package/compiled/dependencies/conway-geom/interface/conway_geometry.d.ts +19 -0
  13. package/compiled/dependencies/conway-geom/interface/conway_geometry.d.ts.map +1 -1
  14. package/compiled/dependencies/conway-geom/interface/conway_geometry.js +17 -0
  15. package/compiled/dependencies/conway-geom/interface/parameters/surface_object.d.ts +6 -0
  16. package/compiled/dependencies/conway-geom/interface/parameters/surface_object.d.ts.map +1 -1
  17. package/compiled/examples/browser-bundled.cjs +1569 -51
  18. package/compiled/examples/cli-bundled.cjs +2790 -436
  19. package/compiled/examples/cli-step-bundled.cjs +1904 -229
  20. package/compiled/examples/validator-bundled.cjs +1569 -51
  21. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/b_spline_curve.gen.d.ts +2 -2
  22. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/b_spline_curve.gen.d.ts.map +1 -1
  23. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/b_spline_curve.gen.js +2 -2
  24. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/b_spline_surface.gen.d.ts +3 -3
  25. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/b_spline_surface.gen.d.ts.map +1 -1
  26. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/b_spline_surface.gen.js +3 -3
  27. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/composite_curve.gen.d.ts +1 -1
  28. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/composite_curve.gen.d.ts.map +1 -1
  29. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/composite_curve.gen.js +1 -1
  30. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_curve_2d.gen.d.ts +1 -1
  31. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_curve_2d.gen.d.ts.map +1 -1
  32. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_curve_2d.gen.js +1 -1
  33. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_curve_3d.gen.d.ts +1 -1
  34. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_curve_3d.gen.d.ts.map +1 -1
  35. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_curve_3d.gen.js +1 -1
  36. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_surface.gen.d.ts +1 -1
  37. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_surface.gen.d.ts.map +1 -1
  38. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/offset_surface.gen.js +1 -1
  39. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/presentation_style_assignment.gen.d.ts.map +1 -1
  40. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/presentation_style_assignment.gen.js +2 -2
  41. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/schema_ap214.gen.js +11 -11
  42. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/shape_aspect.gen.d.ts +1 -1
  43. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/shape_aspect.gen.d.ts.map +1 -1
  44. package/compiled/src/AP214E3_2010/AP214E3_2010_gen/shape_aspect.gen.js +1 -1
  45. package/compiled/src/AP214E3_2010/ap214_command_line_main.js +7 -3
  46. package/compiled/src/AP214E3_2010/ap214_geometry_extraction.d.ts +181 -7
  47. package/compiled/src/AP214E3_2010/ap214_geometry_extraction.d.ts.map +1 -1
  48. package/compiled/src/AP214E3_2010/ap214_geometry_extraction.js +906 -137
  49. package/compiled/src/AP214E3_2010/ap214_geometry_extraction.test.js +10 -2
  50. package/compiled/src/AP214E3_2010/ap214_logical_attribute.test.d.ts +2 -0
  51. package/compiled/src/AP214E3_2010/ap214_logical_attribute.test.d.ts.map +1 -0
  52. package/compiled/src/AP214E3_2010/ap214_logical_attribute.test.js +114 -0
  53. package/compiled/src/AP214E3_2010/ap214_model_geometry.d.ts +6 -0
  54. package/compiled/src/AP214E3_2010/ap214_model_geometry.d.ts.map +1 -1
  55. package/compiled/src/AP214E3_2010/ap214_model_geometry.js +9 -0
  56. package/compiled/src/AP214E3_2010/ap214_pcurve_basis_surfaces.test.d.ts +2 -0
  57. package/compiled/src/AP214E3_2010/ap214_pcurve_basis_surfaces.test.d.ts.map +1 -0
  58. package/compiled/src/AP214E3_2010/ap214_pcurve_basis_surfaces.test.js +233 -0
  59. package/compiled/src/AP214E3_2010/ap214_sphere_vertex_loop.test.d.ts +2 -0
  60. package/compiled/src/AP214E3_2010/ap214_sphere_vertex_loop.test.d.ts.map +1 -0
  61. package/compiled/src/AP214E3_2010/ap214_sphere_vertex_loop.test.js +147 -0
  62. package/compiled/src/AP214E3_2010/ap214_step_model.d.ts +2 -1
  63. package/compiled/src/AP214E3_2010/ap214_step_model.d.ts.map +1 -1
  64. package/compiled/src/AP214E3_2010/ap214_step_model.js +1 -1
  65. package/compiled/src/AP214E3_2010/ap214_typed_select_enum.test.d.ts +2 -0
  66. package/compiled/src/AP214E3_2010/ap214_typed_select_enum.test.d.ts.map +1 -0
  67. package/compiled/src/AP214E3_2010/ap214_typed_select_enum.test.js +65 -0
  68. package/compiled/src/AP214E3_2010/ap214_unit_scale.test.d.ts +2 -0
  69. package/compiled/src/AP214E3_2010/ap214_unit_scale.test.d.ts.map +1 -0
  70. package/compiled/src/AP214E3_2010/ap214_unit_scale.test.js +111 -0
  71. package/compiled/src/compat/web-ifc/ap214_streamed_open.test.d.ts +2 -0
  72. package/compiled/src/compat/web-ifc/ap214_streamed_open.test.d.ts.map +1 -0
  73. package/compiled/src/compat/web-ifc/ap214_streamed_open.test.js +190 -0
  74. package/compiled/src/compat/web-ifc/coordination_export_order.test.d.ts +2 -0
  75. package/compiled/src/compat/web-ifc/coordination_export_order.test.d.ts.map +1 -0
  76. package/compiled/src/compat/web-ifc/coordination_export_order.test.js +110 -0
  77. package/compiled/src/compat/web-ifc/coordination_f64.d.ts +165 -0
  78. package/compiled/src/compat/web-ifc/coordination_f64.d.ts.map +1 -0
  79. package/compiled/src/compat/web-ifc/coordination_f64.js +286 -0
  80. package/compiled/src/compat/web-ifc/coordination_f64.test.d.ts +2 -0
  81. package/compiled/src/compat/web-ifc/coordination_f64.test.d.ts.map +1 -0
  82. package/compiled/src/compat/web-ifc/coordination_f64.test.js +225 -0
  83. package/compiled/src/compat/web-ifc/ifc_api.d.ts +154 -0
  84. package/compiled/src/compat/web-ifc/ifc_api.d.ts.map +1 -1
  85. package/compiled/src/compat/web-ifc/ifc_api.js +211 -3
  86. package/compiled/src/compat/web-ifc/ifc_api_deferred_open.test.d.ts +2 -0
  87. package/compiled/src/compat/web-ifc/ifc_api_deferred_open.test.d.ts.map +1 -0
  88. package/compiled/src/compat/web-ifc/ifc_api_deferred_open.test.js +288 -0
  89. package/compiled/src/compat/web-ifc/ifc_api_model_passthrough.d.ts +39 -0
  90. package/compiled/src/compat/web-ifc/ifc_api_model_passthrough.d.ts.map +1 -1
  91. package/compiled/src/compat/web-ifc/ifc_api_model_passthrough_factory.d.ts +30 -0
  92. package/compiled/src/compat/web-ifc/ifc_api_model_passthrough_factory.d.ts.map +1 -1
  93. package/compiled/src/compat/web-ifc/ifc_api_model_passthrough_factory.js +83 -0
  94. package/compiled/src/compat/web-ifc/ifc_api_preview_channel.test.d.ts +2 -0
  95. package/compiled/src/compat/web-ifc/ifc_api_preview_channel.test.d.ts.map +1 -0
  96. package/compiled/src/compat/web-ifc/ifc_api_preview_channel.test.js +383 -0
  97. package/compiled/src/compat/web-ifc/ifc_api_preview_coordination.test.d.ts +2 -0
  98. package/compiled/src/compat/web-ifc/ifc_api_preview_coordination.test.d.ts.map +1 -0
  99. package/compiled/src/compat/web-ifc/ifc_api_preview_coordination.test.js +124 -0
  100. package/compiled/src/compat/web-ifc/ifc_api_proxy_ap214.d.ts +132 -0
  101. package/compiled/src/compat/web-ifc/ifc_api_proxy_ap214.d.ts.map +1 -1
  102. package/compiled/src/compat/web-ifc/ifc_api_proxy_ap214.js +488 -92
  103. package/compiled/src/compat/web-ifc/ifc_api_proxy_ifc.d.ts +268 -0
  104. package/compiled/src/compat/web-ifc/ifc_api_proxy_ifc.d.ts.map +1 -1
  105. package/compiled/src/compat/web-ifc/ifc_api_proxy_ifc.js +996 -149
  106. package/compiled/src/compat/web-ifc/ifc_api_streamed_open.test.d.ts +2 -0
  107. package/compiled/src/compat/web-ifc/ifc_api_streamed_open.test.d.ts.map +1 -0
  108. package/compiled/src/compat/web-ifc/ifc_api_streamed_open.test.js +129 -0
  109. package/compiled/src/compat/web-ifc/spatial_imposter.d.ts +134 -0
  110. package/compiled/src/compat/web-ifc/spatial_imposter.d.ts.map +1 -0
  111. package/compiled/src/compat/web-ifc/spatial_imposter.js +933 -0
  112. package/compiled/src/compat/web-ifc/spatial_imposter.test.d.ts +2 -0
  113. package/compiled/src/compat/web-ifc/spatial_imposter.test.d.ts.map +1 -0
  114. package/compiled/src/compat/web-ifc/spatial_imposter.test.js +467 -0
  115. package/compiled/src/compat/web-ifc/store_preview_channel.d.ts +187 -0
  116. package/compiled/src/compat/web-ifc/store_preview_channel.d.ts.map +1 -0
  117. package/compiled/src/compat/web-ifc/store_preview_channel.js +524 -0
  118. package/compiled/src/compat/web-ifc/store_preview_channel.test.d.ts +2 -0
  119. package/compiled/src/compat/web-ifc/store_preview_channel.test.d.ts.map +1 -0
  120. package/compiled/src/compat/web-ifc/store_preview_channel.test.js +234 -0
  121. package/compiled/src/compat/web-ifc/streamed_preview_channel.d.ts +306 -0
  122. package/compiled/src/compat/web-ifc/streamed_preview_channel.d.ts.map +1 -0
  123. package/compiled/src/compat/web-ifc/streamed_preview_channel.js +580 -0
  124. package/compiled/src/compat/web-ifc/web_wasm_directory.test.d.ts +2 -0
  125. package/compiled/src/compat/web-ifc/web_wasm_directory.test.d.ts.map +1 -0
  126. package/compiled/src/compat/web-ifc/web_wasm_directory.test.js +22 -0
  127. package/compiled/src/core/composed_model_skeleton.d.ts +63 -0
  128. package/compiled/src/core/composed_model_skeleton.d.ts.map +1 -0
  129. package/compiled/src/core/composed_model_skeleton.js +66 -0
  130. package/compiled/src/core/composed_model_skeleton.test.d.ts +2 -0
  131. package/compiled/src/core/composed_model_skeleton.test.d.ts.map +1 -0
  132. package/compiled/src/core/composed_model_skeleton.test.js +69 -0
  133. package/compiled/src/core/demand_geometry_queue.d.ts +147 -0
  134. package/compiled/src/core/demand_geometry_queue.d.ts.map +1 -0
  135. package/compiled/src/core/demand_geometry_queue.js +223 -0
  136. package/compiled/src/core/demand_geometry_queue.test.d.ts +2 -0
  137. package/compiled/src/core/demand_geometry_queue.test.d.ts.map +1 -0
  138. package/compiled/src/core/demand_geometry_queue.test.js +133 -0
  139. package/compiled/src/core/demand_residency_pump.d.ts +93 -0
  140. package/compiled/src/core/demand_residency_pump.d.ts.map +1 -0
  141. package/compiled/src/core/demand_residency_pump.js +120 -0
  142. package/compiled/src/core/demand_residency_pump.test.d.ts +2 -0
  143. package/compiled/src/core/demand_residency_pump.test.d.ts.map +1 -0
  144. package/compiled/src/core/demand_residency_pump.test.js +148 -0
  145. package/compiled/src/core/geometry_tile_bindings.d.ts +110 -0
  146. package/compiled/src/core/geometry_tile_bindings.d.ts.map +1 -0
  147. package/compiled/src/core/geometry_tile_bindings.js +76 -0
  148. package/compiled/src/core/geometry_tile_bindings.test.d.ts +2 -0
  149. package/compiled/src/core/geometry_tile_bindings.test.d.ts.map +1 -0
  150. package/compiled/src/core/geometry_tile_bindings.test.js +211 -0
  151. package/compiled/src/core/geometry_tile_pool.d.ts +99 -0
  152. package/compiled/src/core/geometry_tile_pool.d.ts.map +1 -0
  153. package/compiled/src/core/geometry_tile_pool.js +104 -0
  154. package/compiled/src/core/geometry_tile_pool.test.d.ts +2 -0
  155. package/compiled/src/core/geometry_tile_pool.test.d.ts.map +1 -0
  156. package/compiled/src/core/geometry_tile_pool.test.js +180 -0
  157. package/compiled/src/core/mem/chunked_pool.d.ts +116 -0
  158. package/compiled/src/core/mem/chunked_pool.d.ts.map +1 -0
  159. package/compiled/src/core/mem/chunked_pool.js +149 -0
  160. package/compiled/src/core/mem/chunked_pool.test.d.ts +2 -0
  161. package/compiled/src/core/mem/chunked_pool.test.d.ts.map +1 -0
  162. package/compiled/src/core/mem/chunked_pool.test.js +63 -0
  163. package/compiled/src/core/mem/shared_asset_pool.d.ts +82 -0
  164. package/compiled/src/core/mem/shared_asset_pool.d.ts.map +1 -0
  165. package/compiled/src/core/mem/shared_asset_pool.js +113 -0
  166. package/compiled/src/core/mem/shared_asset_pool.test.d.ts +2 -0
  167. package/compiled/src/core/mem/shared_asset_pool.test.d.ts.map +1 -0
  168. package/compiled/src/core/mem/shared_asset_pool.test.js +49 -0
  169. package/compiled/src/core/model_registry.d.ts +87 -0
  170. package/compiled/src/core/model_registry.d.ts.map +1 -0
  171. package/compiled/src/core/model_registry.js +101 -0
  172. package/compiled/src/core/model_registry.test.d.ts +2 -0
  173. package/compiled/src/core/model_registry.test.d.ts.map +1 -0
  174. package/compiled/src/core/model_registry.test.js +60 -0
  175. package/compiled/src/core/model_uri.d.ts +57 -0
  176. package/compiled/src/core/model_uri.d.ts.map +1 -0
  177. package/compiled/src/core/model_uri.js +101 -0
  178. package/compiled/src/core/model_uri.test.d.ts +2 -0
  179. package/compiled/src/core/model_uri.test.d.ts.map +1 -0
  180. package/compiled/src/core/model_uri.test.js +49 -0
  181. package/compiled/src/core/progress.d.ts +16 -2
  182. package/compiled/src/core/progress.d.ts.map +1 -1
  183. package/compiled/src/core/progress.js +31 -5
  184. package/compiled/src/core/progress.test.js +11 -2
  185. package/compiled/src/core/progress_log.d.ts +1 -0
  186. package/compiled/src/core/progress_log.d.ts.map +1 -1
  187. package/compiled/src/core/progress_log.js +7 -2
  188. package/compiled/src/core/progress_log.test.js +21 -0
  189. package/compiled/src/core/shared_byte_budget.d.ts +60 -0
  190. package/compiled/src/core/shared_byte_budget.d.ts.map +1 -0
  191. package/compiled/src/core/shared_byte_budget.js +85 -0
  192. package/compiled/src/core/shared_byte_budget.test.d.ts +2 -0
  193. package/compiled/src/core/shared_byte_budget.test.d.ts.map +1 -0
  194. package/compiled/src/core/shared_byte_budget.test.js +55 -0
  195. package/compiled/src/core/wasm_heap.d.ts +208 -0
  196. package/compiled/src/core/wasm_heap.d.ts.map +1 -0
  197. package/compiled/src/core/wasm_heap.js +417 -0
  198. package/compiled/src/core/wasm_heap.test.d.ts +2 -0
  199. package/compiled/src/core/wasm_heap.test.d.ts.map +1 -0
  200. package/compiled/src/core/wasm_heap.test.js +546 -0
  201. package/compiled/src/demand/index.d.ts +23 -0
  202. package/compiled/src/demand/index.d.ts.map +1 -0
  203. package/compiled/src/demand/index.js +22 -0
  204. package/compiled/src/ifc/ifc4_gen/IfcLogical.gen.d.ts +1 -1
  205. package/compiled/src/ifc/ifc4_gen/IfcLogical.gen.d.ts.map +1 -1
  206. package/compiled/src/ifc/ifc4_gen/IfcLogical.gen.js +1 -1
  207. package/compiled/src/ifc/ifc4_gen/IfcPresentationStyleAssignment.gen.d.ts.map +1 -1
  208. package/compiled/src/ifc/ifc4_gen/IfcPresentationStyleAssignment.gen.js +2 -2
  209. package/compiled/src/ifc/ifc4_gen/IfcRelInterferesElements.gen.d.ts +1 -1
  210. package/compiled/src/ifc/ifc4_gen/IfcRelInterferesElements.gen.d.ts.map +1 -1
  211. package/compiled/src/ifc/ifc4_gen/IfcRelInterferesElements.gen.js +1 -1
  212. package/compiled/src/ifc/ifc4_gen/schema_ifc.gen.js +2 -2
  213. package/compiled/src/ifc/ifc_demand_extraction.test.d.ts +2 -0
  214. package/compiled/src/ifc/ifc_demand_extraction.test.d.ts.map +1 -0
  215. package/compiled/src/ifc/ifc_demand_extraction.test.js +251 -0
  216. package/compiled/src/ifc/ifc_geometry_extraction.d.ts +367 -6
  217. package/compiled/src/ifc/ifc_geometry_extraction.d.ts.map +1 -1
  218. package/compiled/src/ifc/ifc_geometry_extraction.js +1322 -389
  219. package/compiled/src/ifc/ifc_grid_placement.test.d.ts +2 -0
  220. package/compiled/src/ifc/ifc_grid_placement.test.d.ts.map +1 -0
  221. package/compiled/src/ifc/ifc_grid_placement.test.js +261 -0
  222. package/compiled/src/ifc/ifc_model_geometry.d.ts +12 -0
  223. package/compiled/src/ifc/ifc_model_geometry.d.ts.map +1 -1
  224. package/compiled/src/ifc/ifc_model_geometry.js +15 -0
  225. package/compiled/src/ifc/ifc_regression_batch_main.js +210 -12
  226. package/compiled/src/ifc/ifc_spatial_skeleton.d.ts +145 -0
  227. package/compiled/src/ifc/ifc_spatial_skeleton.d.ts.map +1 -0
  228. package/compiled/src/ifc/ifc_spatial_skeleton.js +266 -0
  229. package/compiled/src/ifc/ifc_spatial_skeleton.test.d.ts +2 -0
  230. package/compiled/src/ifc/ifc_spatial_skeleton.test.d.ts.map +1 -0
  231. package/compiled/src/ifc/ifc_spatial_skeleton.test.js +199 -0
  232. package/compiled/src/ifc/ifc_step_model.d.ts +6 -2
  233. package/compiled/src/ifc/ifc_step_model.d.ts.map +1 -1
  234. package/compiled/src/ifc/ifc_step_model.js +6 -4
  235. package/compiled/src/ifc/ifc_step_parser.d.ts +58 -0
  236. package/compiled/src/ifc/ifc_step_parser.d.ts.map +1 -1
  237. package/compiled/src/ifc/ifc_step_parser.js +64 -0
  238. package/compiled/src/ifc/ifc_stream_model.test.d.ts +2 -0
  239. package/compiled/src/ifc/ifc_stream_model.test.d.ts.map +1 -0
  240. package/compiled/src/ifc/ifc_stream_model.test.js +70 -0
  241. package/compiled/src/ifc/ifc_stream_open.d.ts +131 -0
  242. package/compiled/src/ifc/ifc_stream_open.d.ts.map +1 -0
  243. package/compiled/src/ifc/ifc_stream_open.js +116 -0
  244. package/compiled/src/ifc/ifc_stream_open.test.d.ts +2 -0
  245. package/compiled/src/ifc/ifc_stream_open.test.d.ts.map +1 -0
  246. package/compiled/src/ifc/ifc_stream_open.test.js +230 -0
  247. package/compiled/src/ifc/ifc_tile_extractor.d.ts +84 -0
  248. package/compiled/src/ifc/ifc_tile_extractor.d.ts.map +1 -0
  249. package/compiled/src/ifc/ifc_tile_extractor.js +134 -0
  250. package/compiled/src/ifc/ifc_tile_extractor.test.d.ts +2 -0
  251. package/compiled/src/ifc/ifc_tile_extractor.test.d.ts.map +1 -0
  252. package/compiled/src/ifc/ifc_tile_extractor.test.js +118 -0
  253. package/compiled/src/ifc/ifc_typed_select_enum.test.d.ts +2 -0
  254. package/compiled/src/ifc/ifc_typed_select_enum.test.d.ts.map +1 -0
  255. package/compiled/src/ifc/ifc_typed_select_enum.test.js +60 -0
  256. package/compiled/src/index.d.ts +21 -1
  257. package/compiled/src/index.d.ts.map +1 -1
  258. package/compiled/src/index.js +28 -1
  259. package/compiled/src/logging/logger.d.ts +16 -2
  260. package/compiled/src/logging/logger.d.ts.map +1 -1
  261. package/compiled/src/logging/logger.js +34 -7
  262. package/compiled/src/logging/logger.test.js +30 -0
  263. package/compiled/src/mem/index.d.ts +17 -0
  264. package/compiled/src/mem/index.d.ts.map +1 -0
  265. package/compiled/src/mem/index.js +16 -0
  266. package/compiled/src/namespace_surface.test.d.ts +2 -0
  267. package/compiled/src/namespace_surface.test.d.ts.map +1 -0
  268. package/compiled/src/namespace_surface.test.js +43 -0
  269. package/compiled/src/parsing/parsing_buffer.d.ts +23 -0
  270. package/compiled/src/parsing/parsing_buffer.d.ts.map +1 -1
  271. package/compiled/src/parsing/parsing_buffer.js +31 -0
  272. package/compiled/src/scripts/model_report_displacement.test.d.ts +2 -0
  273. package/compiled/src/scripts/model_report_displacement.test.d.ts.map +1 -0
  274. package/compiled/src/scripts/model_report_displacement.test.js +104 -0
  275. package/compiled/src/scripts/render_glb_paths.test.d.ts +2 -0
  276. package/compiled/src/scripts/render_glb_paths.test.d.ts.map +1 -0
  277. package/compiled/src/scripts/render_glb_paths.test.js +115 -0
  278. package/compiled/src/step/indexing/step_type_indexer.d.ts +20 -0
  279. package/compiled/src/step/indexing/step_type_indexer.d.ts.map +1 -1
  280. package/compiled/src/step/indexing/step_type_indexer.js +67 -0
  281. package/compiled/src/step/parsing/byte_source.d.ts +153 -0
  282. package/compiled/src/step/parsing/byte_source.d.ts.map +1 -0
  283. package/compiled/src/step/parsing/byte_source.js +106 -0
  284. package/compiled/src/step/parsing/byte_source.test.d.ts +2 -0
  285. package/compiled/src/step/parsing/byte_source.test.d.ts.map +1 -0
  286. package/compiled/src/step/parsing/byte_source.test.js +47 -0
  287. package/compiled/src/step/parsing/byte_source_node.d.ts +41 -0
  288. package/compiled/src/step/parsing/byte_source_node.d.ts.map +1 -0
  289. package/compiled/src/step/parsing/byte_source_node.js +54 -0
  290. package/compiled/src/step/parsing/columnar_index.d.ts +103 -0
  291. package/compiled/src/step/parsing/columnar_index.d.ts.map +1 -0
  292. package/compiled/src/step/parsing/columnar_index.js +224 -0
  293. package/compiled/src/step/parsing/columnar_index.test.d.ts +2 -0
  294. package/compiled/src/step/parsing/columnar_index.test.d.ts.map +1 -0
  295. package/compiled/src/step/parsing/columnar_index.test.js +155 -0
  296. package/compiled/src/step/parsing/cross_reference_registry.d.ts +95 -0
  297. package/compiled/src/step/parsing/cross_reference_registry.d.ts.map +1 -0
  298. package/compiled/src/step/parsing/cross_reference_registry.js +91 -0
  299. package/compiled/src/step/parsing/cross_reference_registry.test.d.ts +2 -0
  300. package/compiled/src/step/parsing/cross_reference_registry.test.d.ts.map +1 -0
  301. package/compiled/src/step/parsing/cross_reference_registry.test.js +66 -0
  302. package/compiled/src/step/parsing/decode_utf8.d.ts +15 -0
  303. package/compiled/src/step/parsing/decode_utf8.d.ts.map +1 -1
  304. package/compiled/src/step/parsing/decode_utf8.js +28 -0
  305. package/compiled/src/step/parsing/express_ref_scan.d.ts +20 -0
  306. package/compiled/src/step/parsing/express_ref_scan.d.ts.map +1 -0
  307. package/compiled/src/step/parsing/express_ref_scan.js +91 -0
  308. package/compiled/src/step/parsing/express_ref_scan.test.d.ts +2 -0
  309. package/compiled/src/step/parsing/express_ref_scan.test.d.ts.map +1 -0
  310. package/compiled/src/step/parsing/express_ref_scan.test.js +28 -0
  311. package/compiled/src/step/parsing/index_sidecar.d.ts +81 -0
  312. package/compiled/src/step/parsing/index_sidecar.d.ts.map +1 -0
  313. package/compiled/src/step/parsing/index_sidecar.js +283 -0
  314. package/compiled/src/step/parsing/index_sidecar.test.d.ts +2 -0
  315. package/compiled/src/step/parsing/index_sidecar.test.d.ts.map +1 -0
  316. package/compiled/src/step/parsing/index_sidecar.test.js +122 -0
  317. package/compiled/src/step/parsing/inf_recovery_index.test.d.ts +2 -0
  318. package/compiled/src/step/parsing/inf_recovery_index.test.d.ts.map +1 -0
  319. package/compiled/src/step/parsing/inf_recovery_index.test.js +108 -0
  320. package/compiled/src/step/parsing/prefix_type_index.d.ts +124 -0
  321. package/compiled/src/step/parsing/prefix_type_index.d.ts.map +1 -0
  322. package/compiled/src/step/parsing/prefix_type_index.js +207 -0
  323. package/compiled/src/step/parsing/prefix_type_index.test.d.ts +2 -0
  324. package/compiled/src/step/parsing/prefix_type_index.test.d.ts.map +1 -0
  325. package/compiled/src/step/parsing/prefix_type_index.test.js +298 -0
  326. package/compiled/src/step/parsing/range_byte_source.d.ts +69 -0
  327. package/compiled/src/step/parsing/range_byte_source.d.ts.map +1 -0
  328. package/compiled/src/step/parsing/range_byte_source.js +78 -0
  329. package/compiled/src/step/parsing/range_byte_source.test.d.ts +2 -0
  330. package/compiled/src/step/parsing/range_byte_source.test.d.ts.map +1 -0
  331. package/compiled/src/step/parsing/range_byte_source.test.js +70 -0
  332. package/compiled/src/step/parsing/record_event.d.ts +23 -0
  333. package/compiled/src/step/parsing/record_event.d.ts.map +1 -0
  334. package/compiled/src/step/parsing/record_event.js +1 -0
  335. package/compiled/src/step/parsing/record_field_cursor.d.ts +94 -0
  336. package/compiled/src/step/parsing/record_field_cursor.d.ts.map +1 -0
  337. package/compiled/src/step/parsing/record_field_cursor.js +189 -0
  338. package/compiled/src/step/parsing/step_deserialization_functions.d.ts +29 -0
  339. package/compiled/src/step/parsing/step_deserialization_functions.d.ts.map +1 -1
  340. package/compiled/src/step/parsing/step_deserialization_functions.js +45 -0
  341. package/compiled/src/step/parsing/step_deserialization_functions.test.js +59 -1
  342. package/compiled/src/step/parsing/step_parser.d.ts +66 -1
  343. package/compiled/src/step/parsing/step_parser.d.ts.map +1 -1
  344. package/compiled/src/step/parsing/step_parser.js +164 -10
  345. package/compiled/src/step/parsing/step_string_parser.js +8 -8
  346. package/compiled/src/step/parsing/streaming_index_builder.d.ts +141 -0
  347. package/compiled/src/step/parsing/streaming_index_builder.d.ts.map +1 -0
  348. package/compiled/src/step/parsing/streaming_index_builder.js +280 -0
  349. package/compiled/src/step/parsing/streaming_index_builder.test.d.ts +2 -0
  350. package/compiled/src/step/parsing/streaming_index_builder.test.d.ts.map +1 -0
  351. package/compiled/src/step/parsing/streaming_index_builder.test.js +107 -0
  352. package/compiled/src/step/parsing/streaming_index_builder_async.test.d.ts +2 -0
  353. package/compiled/src/step/parsing/streaming_index_builder_async.test.d.ts.map +1 -0
  354. package/compiled/src/step/parsing/streaming_index_builder_async.test.js +109 -0
  355. package/compiled/src/step/parsing/streaming_record_dispatcher.d.ts +71 -0
  356. package/compiled/src/step/parsing/streaming_record_dispatcher.d.ts.map +1 -0
  357. package/compiled/src/step/parsing/streaming_record_dispatcher.js +88 -0
  358. package/compiled/src/step/parsing/streaming_record_dispatcher.test.d.ts +2 -0
  359. package/compiled/src/step/parsing/streaming_record_dispatcher.test.d.ts.map +1 -0
  360. package/compiled/src/step/parsing/streaming_record_dispatcher.test.js +66 -0
  361. package/compiled/src/step/parsing/uint32_sink.d.ts +72 -0
  362. package/compiled/src/step/parsing/uint32_sink.d.ts.map +1 -0
  363. package/compiled/src/step/parsing/uint32_sink.js +180 -0
  364. package/compiled/src/step/parsing/uint32_sink.test.d.ts +2 -0
  365. package/compiled/src/step/parsing/uint32_sink.test.d.ts.map +1 -0
  366. package/compiled/src/step/parsing/uint32_sink.test.js +199 -0
  367. package/compiled/src/step/step_buffer_provider.d.ts +48 -3
  368. package/compiled/src/step/step_buffer_provider.d.ts.map +1 -1
  369. package/compiled/src/step/step_buffer_provider.js +60 -11
  370. package/compiled/src/step/step_buffer_provider.test.js +14 -0
  371. package/compiled/src/step/step_entity_base.d.ts +65 -3
  372. package/compiled/src/step/step_entity_base.d.ts.map +1 -1
  373. package/compiled/src/step/step_entity_base.js +135 -3
  374. package/compiled/src/step/step_model_base.d.ts +221 -8
  375. package/compiled/src/step/step_model_base.d.ts.map +1 -1
  376. package/compiled/src/step/step_model_base.js +542 -7
  377. package/compiled/src/stream/index.d.ts +34 -0
  378. package/compiled/src/stream/index.d.ts.map +1 -0
  379. package/compiled/src/stream/index.js +32 -0
  380. package/compiled/src/version/version.js +1 -1
  381. package/compiled/tsconfig.tsbuildinfo +1 -1
  382. package/package.json +16 -1
@@ -0,0 +1,417 @@
1
+ /**
2
+ * Reading and writing the wasm heap from JS, through views that are known to
3
+ * belong to the heap as it is RIGHT NOW.
4
+ *
5
+ * This lives in one place because the two geometry extractors had a copy each,
6
+ * and the copies had drifted: one honoured the source view's window and the
7
+ * other did not, and neither checked what _malloc returned. The failure modes
8
+ * are quiet enough to be worth naming here.
9
+ *
10
+ * See bldrs-ai/conway#485 for what an uninstrumented failure on this path
11
+ * costs: `Invalid typed array length: 80`, no context, and two sightings
12
+ * across two models before it could even be located.
13
+ *
14
+ * The confirmed mechanism behind #485
15
+ * -----------------------------------
16
+ * conway's MT builds create their memory as
17
+ * `new WebAssembly.Memory({ initial, maximum: 65536, shared: true })` with no
18
+ * `maxByteLength`, so `wasmMemory.buffer` is a **non-extensible**
19
+ * SharedArrayBuffer - `growable === false`, `maxByteLength === byteLength`
20
+ * (verified against Dist/ConwayGeomWasmNodeMT.js and by inspecting a live
21
+ * module). A non-extensible buffer cannot grow in place, so
22
+ * `WebAssembly.Memory.grow()` materialises a NEW SharedArrayBuffer, which the
23
+ * `.buffer` getter hands out from then on.
24
+ *
25
+ * emscripten rebuilds `Module.HEAPU8` and friends over that new buffer in
26
+ * `updateMemoryViews()` - but only on the thread that did the growing, and
27
+ * only when its own glue passes through `growMemViews()`. Growth driven by a
28
+ * pthread runs `updateMemoryViews()` in the WORKER's JS scope; the main
29
+ * thread's `Module.HEAPU8` stays bound to the pre-growth buffer until some
30
+ * main-thread glue call happens to run `growMemViews()`. `_malloc` is a raw
31
+ * wasm export, so it is not one of those calls: it can hand back an address in
32
+ * the newly added region while the JS-side view still ends before it. That is
33
+ * exactly the state #498's diagnostic captured in CI - view length equal to
34
+ * its own buffer's byteLength (so not stale relative to that buffer),
35
+ * `extensible false` (so that buffer never grew), and the pointer past the end
36
+ * of both.
37
+ *
38
+ * Which is why every view here is built through wasmHeapView(): it re-reads
39
+ * the module's view, reconciles it against the pointer, and only then
40
+ * constructs.
41
+ */
42
+ import Logger from "../logging/logger.js";
43
+ /**
44
+ * Describe the heap and the request, for an error message that is actually
45
+ * actionable.
46
+ *
47
+ * Three of these fields exist to tell #485's two candidate mechanisms apart,
48
+ * and the CI capture that settled it read them in this order:
49
+ *
50
+ * - `heap view length` BELOW `byteLength` means the view is stale relative to
51
+ * its own buffer - a buffer that grew in place while the view kept its
52
+ * original length.
53
+ * - `heap view length` EQUAL to `byteLength`, with the pointer past both,
54
+ * means the view is fine for the buffer it has and the buffer itself is the
55
+ * old one - the heap grew into a different buffer object entirely.
56
+ * - `extensible` settles whether the first was even possible: a non-extensible
57
+ * buffer can never have grown in place.
58
+ *
59
+ * The flag has different names on the two buffer kinds (`growable` on
60
+ * SharedArrayBuffer, `resizable` on ArrayBuffer), so it is reported as one
61
+ * field alongside the kind rather than making a reader know which goes with
62
+ * which. Printing only one name would make every single-threaded failure look
63
+ * like the shared-memory case, pointing away from whatever the real cause was.
64
+ *
65
+ * @param wasmModule The module whose heap is being written to.
66
+ * @param arrayPtr The pointer _malloc returned.
67
+ * @param numBytes The size of the intended copy.
68
+ * @return {string} A description of the heap state.
69
+ */
70
+ function describeHeap(wasmModule, arrayPtr, numBytes) {
71
+ const heap = wasmModule.HEAPU8;
72
+ const buffer = currentHeapBuffer(wasmModule);
73
+ const shared = typeof SharedArrayBuffer !== "undefined" &&
74
+ buffer instanceof SharedArrayBuffer;
75
+ const kind = buffer === void 0 ? "none" :
76
+ (shared ? "SharedArrayBuffer" : "ArrayBuffer");
77
+ // Whichever flag this buffer type actually carries. Reported as one field so
78
+ // a reader does not have to know which name goes with which kind.
79
+ const extensible = shared ? buffer?.growable : buffer?.resizable;
80
+ return `ptr ${arrayPtr} + ${numBytes} bytes, ` +
81
+ `heap view length ${heap?.length}, ` +
82
+ `buffer ${kind} byteLength ${buffer?.byteLength}, ` +
83
+ `extensible ${extensible}`;
84
+ }
85
+ /**
86
+ * The buffer the heap lives in as of this instant.
87
+ *
88
+ * `wasmMemory` is authoritative when a build exposes it - its `.buffer` getter
89
+ * cannot be stale - and reading it is a property access, so it is worth
90
+ * preferring even though nothing exposes it yet. Otherwise this is the
91
+ * module's cached view's buffer, which is what everything downstream then has
92
+ * to reconcile.
93
+ *
94
+ * @param wasmModule The module whose heap is wanted.
95
+ * @return {ArrayBufferLike} The heap's backing buffer.
96
+ */
97
+ function currentHeapBuffer(wasmModule) {
98
+ const memory = wasmModule.wasmMemory;
99
+ // Re-read HEAPU8 off the module every time rather than caching it: an
100
+ // emscripten refresh REPLACES the property, so a cached reference is exactly
101
+ // the stale view this module exists to avoid.
102
+ return memory !== void 0 ? memory.buffer : wasmModule.HEAPU8?.buffer;
103
+ }
104
+ /**
105
+ * Bring the module's cached heap views back in line with the real memory.
106
+ *
107
+ * Only ever called once a pointer has been seen to fall outside the cached
108
+ * view, so cost here is paid about once per growth event, not per copy.
109
+ *
110
+ * The routes are tried best-first, and the last one is the only one conway's
111
+ * current builds actually have. That is a finding, not an oversight: the
112
+ * emscripten output exposes `HEAP8/HEAPU8/HEAP32/HEAPU32/HEAPF32/HEAPF64`,
113
+ * `_malloc` and `_free` and nothing else memory-related - no `wasmMemory`, no
114
+ * `updateMemoryViews`, no `growMemViews`, no `GROWABLE_HEAP_*` helpers. What
115
+ * it does have is `growMemViews()` guarding every heap access inside its own
116
+ * JS library, and embind's `std::string` marshalling is one of those accesses
117
+ * (`stringToUTF8` reads `(growMemViews(), HEAPU8)`). So pushing an empty
118
+ * string into an embind vector makes emscripten notice the growth and rebuild
119
+ * `Module.HEAPU8` for us, which is what the reconcile below then re-reads.
120
+ * Measured at ~9us per round trip, on a path that runs after a heap growth.
121
+ *
122
+ * @param wasmModule The module whose views may be stale.
123
+ */
124
+ function refreshHeapViews(wasmModule) {
125
+ if (typeof wasmModule.updateMemoryViews === "function") {
126
+ wasmModule.updateMemoryViews();
127
+ return;
128
+ }
129
+ // Nothing to refresh - currentHeapBuffer already reads this live.
130
+ if (wasmModule.wasmMemory !== void 0) {
131
+ return;
132
+ }
133
+ const StringVector = wasmModule.stringVector;
134
+ // Absent on a module that is not conway-geom (the fakes in the tests, say),
135
+ // in which case there is no route and the caller reports the state instead.
136
+ if (StringVector === void 0) {
137
+ return;
138
+ }
139
+ // Every step of the embind round trip is best-effort, INDIVIDUALLY, because
140
+ // this whole function is best-effort: it only ever runs once something has
141
+ // already gone wrong with the heap, and both of its callers have a
142
+ // well-defined answer for "the refresh achieved nothing" - reconcile reports
143
+ // the heap state (#485's actual diagnostic), and the byte-length reporter
144
+ // returns a possibly-lagging number. Letting an embind failure out of here
145
+ // would replace either of those with a bare marshalling error from a
146
+ // function that exists only to try.
147
+ //
148
+ // Both halves can throw, for different reasons:
149
+ //
150
+ // - construct-and-push allocates, and this path runs precisely under the
151
+ // heap pressure that makes allocation fail. A throw here means the views
152
+ // were NOT refreshed, so the caller carries on with its stale-view state
153
+ // and reports it - which is the outcome that matters, since losing the
154
+ // diagnostic to the failure of the repair attempt is what #485 cost two
155
+ // sightings to locate.
156
+ // - delete() re-enters the same runtime that may just have failed. By then
157
+ // the push has already made emscripten rebuild the views, so the refresh
158
+ // SUCCEEDED; failing the caller's copy over the teardown of a scratch
159
+ // object would break an operation that had just been repaired.
160
+ //
161
+ // Split rather than nested so a push that throws still gets its vector
162
+ // deleted: the constructor is what registers the embind handle, so anything
163
+ // constructed is owed a delete regardless of what the push did.
164
+ let scratch;
165
+ releaseQuietly(() => {
166
+ const created = new StringVector();
167
+ scratch = created;
168
+ created.push_back("");
169
+ });
170
+ const created = scratch;
171
+ if (created !== void 0) {
172
+ releaseQuietly(() => created.delete());
173
+ }
174
+ }
175
+ /**
176
+ * Reconcile a pointer against the heap, refreshing stale views if that is what
177
+ * is wrong, and hand back the buffer the view should be built over.
178
+ *
179
+ * The hot path is one property read, one add and one compare - the same test
180
+ * that was already here - so the refresh machinery costs nothing until a
181
+ * pointer actually lands outside.
182
+ *
183
+ * @param wasmModule The module the pointer belongs to.
184
+ * @param address The pointer, already normalised to unsigned.
185
+ * @param numBytes How many bytes past it will be touched.
186
+ * @return {ArrayBufferLike} A buffer that contains [address, address+numBytes).
187
+ */
188
+ function reconcileHeapBuffer(wasmModule, address, numBytes) {
189
+ const buffer = currentHeapBuffer(wasmModule);
190
+ if (buffer !== void 0 && address + numBytes <= buffer.byteLength) {
191
+ return buffer;
192
+ }
193
+ refreshHeapViews(wasmModule);
194
+ const refreshed = currentHeapBuffer(wasmModule);
195
+ if (refreshed !== void 0 && address + numBytes <= refreshed.byteLength) {
196
+ return refreshed;
197
+ }
198
+ // Past here the heap really does not contain the address, so this is the
199
+ // genuinely-impossible case #498 added the diagnostic for rather than the
200
+ // growth race it was chasing.
201
+ throw new Error("wasm heap allocation lies outside the heap, and refreshing the module " +
202
+ "views did not reconcile it. " +
203
+ describeHeap(wasmModule, address, numBytes));
204
+ }
205
+ /**
206
+ * Build a typed-array view over a region of the wasm heap.
207
+ *
208
+ * Every view onto the heap in this repo goes through here, because the
209
+ * property that makes a view safe - that its buffer is the heap's CURRENT
210
+ * buffer - is not something a caller can check by looking at its own code. It
211
+ * depends on whether some other thread grew the heap between the call that
212
+ * produced `pointer` and this line.
213
+ *
214
+ * Two things beyond the reconcile are worth knowing:
215
+ *
216
+ * - The pointer is normalised to unsigned. Pointers reaching JS from raw i32
217
+ * wasm exports arrive NEGATIVE once the heap passes 2GB, and every target
218
+ * builds with `maximum: 65536` pages (4GB), so that is a reachable state and
219
+ * not a theoretical one. (This build's `applySignatureConversions` already
220
+ * wraps `_malloc` as `a0 => f(a0) >>> 0`; pointers from other exports and
221
+ * from other builds are not covered by that, so it is done here too.)
222
+ * - A view is CONSTRUCTED rather than `subarray`d off the module's view.
223
+ * `subarray` silently clamps an out-of-range window, which turns "the heap
224
+ * moved" into a short view and then into a copy that lands somewhere else
225
+ * entirely; the constructor throws instead, and by then the reconcile has
226
+ * already made throwing the right answer.
227
+ *
228
+ * @param wasmModule The module owning the heap.
229
+ * @param arrayType The typed-array constructor for the element type wanted.
230
+ * @param pointer Byte address in the heap, signed or unsigned.
231
+ * @param elementCount How many elements the view spans.
232
+ * @return {TArray} A view over the live heap. Do not retain it across any
233
+ * further call into wasm.
234
+ */
235
+ export function wasmHeapView(wasmModule, arrayType, pointer, elementCount) {
236
+ const address = pointer >>> 0;
237
+ const numBytes = elementCount * arrayType.BYTES_PER_ELEMENT;
238
+ return new arrayType(reconcileHeapBuffer(wasmModule, address, numBytes), address, elementCount);
239
+ }
240
+ /**
241
+ * How many bytes of wasm heap there currently are.
242
+ *
243
+ * Refreshes first, unconditionally - which is the opposite of what
244
+ * wasmHeapView does, and deliberate. There is nothing to compare a size
245
+ * against, so lag here cannot be detected the way an out-of-range pointer can;
246
+ * and `HEAPU8.length` on its own under-reports by a whole growth step whenever
247
+ * the module's views are behind (see this file's header), which is the one
248
+ * thing a high-water figure must not do. This is a reporting call - a line at
249
+ * the end of a run - so paying microseconds for a true answer is the right
250
+ * trade. Do not put it in a loop.
251
+ *
252
+ * That the refresh cannot throw (see refreshHeapViews) matters more here than
253
+ * at the other call site: this figure's only consumer is the AP214 CLI's
254
+ * high-water log line, so an embind failure escaping would abort an otherwise
255
+ * complete extraction from a log statement. A lagging number is the right
256
+ * answer there.
257
+ *
258
+ * @param wasmModule The module to measure.
259
+ * @return {number} The heap's size in bytes, or 0 if it has no heap yet.
260
+ */
261
+ export function wasmHeapByteLength(wasmModule) {
262
+ refreshHeapViews(wasmModule);
263
+ return currentHeapBuffer(wasmModule)?.byteLength ?? 0;
264
+ }
265
+ /**
266
+ * Copy an array into a fresh wasm heap allocation.
267
+ *
268
+ * @param wasmModule The module to allocate in.
269
+ * @param array The data to copy. May be a view into a larger buffer.
270
+ * @return {number} Pointer to the copy, owned by the caller.
271
+ */
272
+ export function arrayToWasmHeap(wasmModule, array) {
273
+ const numBytes = array.length * array.BYTES_PER_ELEMENT;
274
+ // Normalised, not rejected. Pointers arriving from raw i32 wasm exports are
275
+ // NEGATIVE at or above 2^31, and every target builds with 4GB of maximum
276
+ // memory, so that is reachable - and it is reachable precisely under the
277
+ // memory pressure #485 is about. wasmHeapView normalises too; doing it here
278
+ // as well keeps the zero test, the free and the message all talking about
279
+ // the same address.
280
+ const arrayPtr = wasmModule._malloc(numBytes) >>> 0;
281
+ // 0 is _malloc's failure return and also a valid byteOffset, so the view
282
+ // below would be constructed happily and this would go on to write over
283
+ // whatever lives at address 0 - corrupting the heap instead of reporting
284
+ // that it is exhausted.
285
+ if (arrayPtr === 0 && numBytes > 0) {
286
+ throw new Error(`wasm _malloc returned an unusable address for ${numBytes} bytes - ` +
287
+ describeHeap(wasmModule, arrayPtr, numBytes));
288
+ }
289
+ let destination;
290
+ try {
291
+ destination = wasmHeapView(wasmModule, Uint8Array, arrayPtr, numBytes);
292
+ }
293
+ catch (error) {
294
+ // The allocation SUCCEEDED and only the view is refused, so this owns a
295
+ // pointer nobody else can reach - arraysToWasmHeap's cleanup cannot see it
296
+ // because it was never returned. Leaking here would mean leaking once per
297
+ // record, under a per-record catch, while reporting that the heap is in
298
+ // trouble.
299
+ releaseQuietly(() => wasmModule._free(arrayPtr));
300
+ throw error;
301
+ }
302
+ // Honour the source view's own window: subarray() results share their
303
+ // parent's backing buffer, so copying `array.buffer` wholesale reads the
304
+ // wrong bytes, and the wrong number of them, for anything that is a view.
305
+ destination.set(new Uint8Array(array.buffer, array.byteOffset, numBytes));
306
+ return arrayPtr;
307
+ }
308
+ /**
309
+ * Copy several arrays into the wasm heap, all or nothing.
310
+ *
311
+ * arrayToWasmHeap throws on a failed allocation, which is the right thing on
312
+ * its own but turns a caller that allocates N buffers before freeing any into
313
+ * a leak: the throw on buffer 2 strands buffer 1, the per-record catch
314
+ * upstream moves to the next record, and the leak repeats - accelerating the
315
+ * exhaustion being reported. Callers that hold several at once use this
316
+ * instead, which frees what it took before letting the error out.
317
+ *
318
+ * @param wasmModule The module to allocate in.
319
+ * @param arrays The data to copy, in order.
320
+ * @return {number[]} Pointers in the same order, owned by the caller.
321
+ */
322
+ export function arraysToWasmHeap(wasmModule, arrays) {
323
+ const pointers = [];
324
+ try {
325
+ for (const array of arrays) {
326
+ pointers.push(arrayToWasmHeap(wasmModule, array));
327
+ }
328
+ }
329
+ catch (error) {
330
+ // Individually, and quietly. One free throwing must not strand the rest,
331
+ // and must not replace the allocation error being propagated.
332
+ for (const pointer of pointers) {
333
+ releaseQuietly(() => wasmModule._free(pointer));
334
+ }
335
+ throw error;
336
+ }
337
+ return pointers;
338
+ }
339
+ /**
340
+ * Run a resource release so it cannot replace an exception already in flight.
341
+ *
342
+ * Releases here re-enter the wasm runtime - _free, embind delete(), returning
343
+ * a pooled buffer - and they run from finally blocks that may be unwinding
344
+ * because that runtime just failed. A throw from one of them would REPLACE the
345
+ * original error, so the caller upstream would see a generic teardown failure
346
+ * instead of the diagnostic that says what actually went wrong. Losing the
347
+ * cause is strictly worse than failing to reclaim memory on a path where the
348
+ * heap is already lost.
349
+ *
350
+ * Reported at debug rather than swallowed outright, so it is still findable
351
+ * with -vv, and NOT at warning/error: this runs during teardown of an already
352
+ * failing record, where a second message would be noise on top of the one that
353
+ * matters.
354
+ *
355
+ * @param release The release step to run.
356
+ */
357
+ export function releaseQuietly(release) {
358
+ try {
359
+ release();
360
+ }
361
+ catch (error) {
362
+ Logger.debug(`wasm resource release failed during teardown: ${error instanceof Error ? error.message : error}`);
363
+ }
364
+ }
365
+ /**
366
+ * Run `body`, then release - propagating a release failure on success, and
367
+ * suppressing it only when something is already being unwound.
368
+ *
369
+ * That asymmetry is the point. releaseQuietly on its own is right during
370
+ * unwinding and wrong otherwise: on the success path a teardown failure is a
371
+ * real fault with nothing competing to report it, and swallowing it would let
372
+ * a record be reported COMPLETE while its resources were never reclaimed. So
373
+ * the quiet treatment applies to exactly the case it was argued for.
374
+ *
375
+ * @param body The work that needs the resource.
376
+ * @param release How to give the resource back.
377
+ * @return {T} Whatever body returned.
378
+ */
379
+ export function withRelease(body, release) {
380
+ let result;
381
+ try {
382
+ result = body();
383
+ }
384
+ catch (error) {
385
+ releaseQuietly(release);
386
+ throw error;
387
+ }
388
+ release();
389
+ return result;
390
+ }
391
+ /**
392
+ * Free several pointers, independently.
393
+ *
394
+ * One failing free must not abandon the rest - batching them into a single
395
+ * statement means the first failure strands every pointer after it - and it
396
+ * must not be lost either, so the first error is re-thrown once they have all
397
+ * been attempted. Combined with withRelease that gives the wanted behaviour on
398
+ * both paths: everything is freed either way, and the failure surfaces on the
399
+ * success path while staying quiet during unwinding.
400
+ *
401
+ * @param wasmModule The module the pointers belong to.
402
+ * @param pointers The allocations to release.
403
+ */
404
+ export function freeAll(wasmModule, pointers) {
405
+ let firstFailure;
406
+ for (const pointer of pointers) {
407
+ try {
408
+ wasmModule._free(pointer);
409
+ }
410
+ catch (error) {
411
+ firstFailure ??= error;
412
+ }
413
+ }
414
+ if (firstFailure !== void 0) {
415
+ throw firstFailure;
416
+ }
417
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=wasm_heap.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm_heap.test.d.ts","sourceRoot":"","sources":["../../../src/core/wasm_heap.test.ts"],"names":[],"mappings":""}