@akohn/dashql-react 0.0.0-stage → 0.0.20-dev.1001.g5e5121808

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 (356) hide show
  1. package/LICENSE +373 -0
  2. package/NOTICE +118 -0
  3. package/README.md +133 -2
  4. package/dist/_virtual/_vite/preload-helper.js +100 -0
  5. package/dist/brand/brand.d.ts +13 -0
  6. package/dist/brand/brand.js +14 -0
  7. package/dist/brand/landing_backdrop.d.ts +56 -0
  8. package/dist/brand/landing_backdrop.js +1019 -0
  9. package/dist/brand/wobble_morph.d.ts +54 -0
  10. package/dist/brand/wobble_morph.js +439 -0
  11. package/dist/components/action_list.d.ts +31 -0
  12. package/dist/components/action_list.js +63 -0
  13. package/dist/components/action_list.module.js +11 -0
  14. package/dist/components/anchored_overlay.d.ts +28 -0
  15. package/dist/components/anchored_overlay.js +93 -0
  16. package/dist/components/button.d.ts +42 -0
  17. package/dist/components/button.js +97 -0
  18. package/dist/components/button.module.js +20 -0
  19. package/dist/components/button_group.d.ts +7 -0
  20. package/dist/components/button_group.js +18 -0
  21. package/dist/components/button_group.module.js +3 -0
  22. package/dist/components/card_placeholder.d.ts +9 -0
  23. package/dist/components/card_placeholder.js +39 -0
  24. package/dist/components/card_placeholder.module.js +6 -0
  25. package/dist/components/clipboard.d.ts +19 -0
  26. package/dist/components/clipboard.js +54 -0
  27. package/dist/components/data_table/computation_tables.d.ts +12 -0
  28. package/dist/components/data_table/computation_tables.js +42 -0
  29. package/dist/components/data_table/data_table.d.ts +39 -0
  30. package/dist/components/data_table/data_table.js +415 -0
  31. package/dist/components/data_table/data_table.module.js +41 -0
  32. package/dist/components/data_table/data_table_cell.d.ts +7 -0
  33. package/dist/components/data_table/data_table_cell.js +9 -0
  34. package/dist/components/data_table/data_table_cell_data.d.ts +22 -0
  35. package/dist/components/data_table/data_table_cell_data.js +103 -0
  36. package/dist/components/data_table/data_table_cell_header_name.d.ts +17 -0
  37. package/dist/components/data_table/data_table_cell_header_name.js +73 -0
  38. package/dist/components/data_table/data_table_cell_header_plots.d.ts +29 -0
  39. package/dist/components/data_table/data_table_cell_header_plots.js +120 -0
  40. package/dist/components/data_table/data_table_colors.d.ts +19 -0
  41. package/dist/components/data_table/data_table_colors.js +27 -0
  42. package/dist/components/data_table/data_table_column_resize.d.ts +21 -0
  43. package/dist/components/data_table/data_table_column_resize.js +121 -0
  44. package/dist/components/data_table/data_table_focus.d.ts +15 -0
  45. package/dist/components/data_table/data_table_focus.js +53 -0
  46. package/dist/components/data_table/data_table_layout.d.ts +18 -0
  47. package/dist/components/data_table/data_table_layout.js +103 -0
  48. package/dist/components/data_table/data_table_ordering.d.ts +9 -0
  49. package/dist/components/data_table/data_table_ordering.js +39 -0
  50. package/dist/components/data_table/data_table_portals.d.ts +9 -0
  51. package/dist/components/data_table/data_table_portals.js +29 -0
  52. package/dist/components/data_table/data_table_row_detail.d.ts +22 -0
  53. package/dist/components/data_table/data_table_row_detail.js +68 -0
  54. package/dist/components/data_table/data_table_row_detail.module.js +7 -0
  55. package/dist/components/data_table/data_table_sticky_views.d.ts +35 -0
  56. package/dist/components/data_table/data_table_sticky_views.js +161 -0
  57. package/dist/components/data_table/data_table_window.d.ts +18 -0
  58. package/dist/components/data_table/data_table_window.js +118 -0
  59. package/dist/components/data_table/format_peek.d.ts +2 -0
  60. package/dist/components/data_table/format_peek.js +17 -0
  61. package/dist/components/data_table/histogram_bars.d.ts +36 -0
  62. package/dist/components/data_table/histogram_bars.js +100 -0
  63. package/dist/components/data_table/histogram_brush.d.ts +22 -0
  64. package/dist/components/data_table/histogram_brush.js +105 -0
  65. package/dist/components/data_table/histogram_cell.d.ts +17 -0
  66. package/dist/components/data_table/histogram_cell.js +324 -0
  67. package/dist/components/data_table/histogram_cell.module.js +9 -0
  68. package/dist/components/data_table/histogram_label.d.ts +1 -0
  69. package/dist/components/data_table/histogram_label.js +7 -0
  70. package/dist/components/data_table/memo_props.d.ts +1 -0
  71. package/dist/components/data_table/memo_props.js +17 -0
  72. package/dist/components/data_table/mostfrequent_cell.d.ts +17 -0
  73. package/dist/components/data_table/mostfrequent_cell.js +316 -0
  74. package/dist/components/data_table/mostfrequent_cell.module.js +10 -0
  75. package/dist/components/data_table/use_cross_filters.d.ts +14 -0
  76. package/dist/components/data_table/use_cross_filters.js +47 -0
  77. package/dist/components/deferred.d.ts +11 -0
  78. package/dist/components/deferred.js +41 -0
  79. package/dist/components/deferred.module.js +5 -0
  80. package/dist/components/error_boundary.d.ts +18 -0
  81. package/dist/components/error_boundary.js +15 -0
  82. package/dist/components/graph.module.js +15 -0
  83. package/dist/components/graph_port.d.ts +10 -0
  84. package/dist/components/graph_port.js +34 -0
  85. package/dist/components/inspector_overlay.d.ts +32 -0
  86. package/dist/components/inspector_overlay.js +72 -0
  87. package/dist/components/inspector_overlay.module.js +18 -0
  88. package/dist/components/json/json_arrow_symbol.d.ts +4 -0
  89. package/dist/components/json/json_arrow_symbol.js +25 -0
  90. package/dist/components/json/json_copy_button.d.ts +11 -0
  91. package/dist/components/json/json_copy_button.js +61 -0
  92. package/dist/components/json/json_ellipsis_symbol.d.ts +7 -0
  93. package/dist/components/json/json_ellipsis_symbol.js +11 -0
  94. package/dist/components/json/json_item_count.d.ts +5 -0
  95. package/dist/components/json/json_item_count.js +12 -0
  96. package/dist/components/json/json_key_name.d.ts +6 -0
  97. package/dist/components/json/json_key_name.js +40 -0
  98. package/dist/components/json/json_key_values.d.ts +12 -0
  99. package/dist/components/json/json_key_values.js +99 -0
  100. package/dist/components/json/json_literal.d.ts +8 -0
  101. package/dist/components/json/json_literal.js +140 -0
  102. package/dist/components/json/json_nested_close.d.ts +11 -0
  103. package/dist/components/json/json_nested_close.js +31 -0
  104. package/dist/components/json/json_nested_open.d.ts +18 -0
  105. package/dist/components/json/json_nested_open.js +150 -0
  106. package/dist/components/json/json_nested_state.d.ts +14 -0
  107. package/dist/components/json/json_nested_state.js +28 -0
  108. package/dist/components/json/json_tool_state.d.ts +18 -0
  109. package/dist/components/json/json_tool_state.js +46 -0
  110. package/dist/components/json/json_value.d.ts +10 -0
  111. package/dist/components/json/json_value.js +46 -0
  112. package/dist/components/json/json_view.d.ts +14 -0
  113. package/dist/components/json/json_view.js +37 -0
  114. package/dist/components/json/json_view.module.js +41 -0
  115. package/dist/components/json/json_view_state.d.ts +14 -0
  116. package/dist/components/json/json_view_state.js +32 -0
  117. package/dist/components/json/unique_key.d.ts +1 -0
  118. package/dist/components/json/unique_key.js +8 -0
  119. package/dist/components/keyvalue_list.d.ts +25 -0
  120. package/dist/components/keyvalue_list.js +106 -0
  121. package/dist/components/keyvalue_list.module.js +15 -0
  122. package/dist/components/name_input.d.ts +12 -0
  123. package/dist/components/name_input.js +63 -0
  124. package/dist/components/overlay.d.ts +53 -0
  125. package/dist/components/overlay.js +183 -0
  126. package/dist/components/overlay.module.js +32 -0
  127. package/dist/components/panel_resize_handle.d.ts +12 -0
  128. package/dist/components/panel_resize_handle.js +39 -0
  129. package/dist/components/portal.d.ts +8 -0
  130. package/dist/components/portal.js +53 -0
  131. package/dist/components/progress_bar.d.ts +7 -0
  132. package/dist/components/progress_bar.js +21 -0
  133. package/dist/components/progress_bar.module.js +3 -0
  134. package/dist/components/query_history_viewer.d.ts +31 -0
  135. package/dist/components/query_history_viewer.js +271 -0
  136. package/dist/components/query_history_viewer.module.js +7 -0
  137. package/dist/components/query_profile/engine_profile_view.d.ts +19 -0
  138. package/dist/components/query_profile/engine_profile_view.js +94 -0
  139. package/dist/components/query_profile/numeric_limits.d.ts +1 -0
  140. package/dist/components/query_profile/numeric_limits.js +2 -0
  141. package/dist/components/query_profile/profile_execution_controller.d.ts +12 -0
  142. package/dist/components/query_profile/profile_execution_controller.js +44 -0
  143. package/dist/components/query_profile/profile_fit.d.ts +24 -0
  144. package/dist/components/query_profile/profile_fit.js +22 -0
  145. package/dist/components/query_profile/profile_navigation.d.ts +3 -0
  146. package/dist/components/query_profile/profile_navigation.js +34 -0
  147. package/dist/components/query_profile/profile_scene.d.ts +64 -0
  148. package/dist/components/query_profile/profile_scene.js +422 -0
  149. package/dist/components/query_profile/query_profile_view.d.ts +36 -0
  150. package/dist/components/query_profile/query_profile_view.js +953 -0
  151. package/dist/components/query_profile/query_profile_view.module.js +23 -0
  152. package/dist/components/query_progress/query_profile_overlay.d.ts +7 -0
  153. package/dist/components/query_progress/query_profile_overlay.js +67 -0
  154. package/dist/components/query_progress/query_profile_overlay.module.js +6 -0
  155. package/dist/components/query_progress/query_progress_panel.d.ts +14 -0
  156. package/dist/components/query_progress/query_progress_panel.js +255 -0
  157. package/dist/components/query_progress/query_progress_panel.module.js +10 -0
  158. package/dist/components/query_result/cell_detail_overlay.d.ts +34 -0
  159. package/dist/components/query_result/cell_detail_overlay.js +277 -0
  160. package/dist/components/query_result/cell_detail_overlay.module.js +21 -0
  161. package/dist/components/query_result/query_result_action_menu.d.ts +12 -0
  162. package/dist/components/query_result/query_result_action_menu.js +62 -0
  163. package/dist/components/query_result/query_result_action_menu.module.js +2 -0
  164. package/dist/components/query_result/query_result_details.d.ts +17 -0
  165. package/dist/components/query_result/query_result_details.js +46 -0
  166. package/dist/components/query_result/query_result_details.module.js +5 -0
  167. package/dist/components/query_result/query_result_download_button.d.ts +8 -0
  168. package/dist/components/query_result/query_result_download_button.js +38 -0
  169. package/dist/components/query_result/query_result_header.d.ts +21 -0
  170. package/dist/components/query_result/query_result_header.js +72 -0
  171. package/dist/components/query_result/query_result_header.module.js +3 -0
  172. package/dist/components/query_result/query_result_search_controls.d.ts +12 -0
  173. package/dist/components/query_result/query_result_search_controls.js +141 -0
  174. package/dist/components/query_result/query_result_search_controls.module.js +7 -0
  175. package/dist/components/query_result/query_result_toolbar.d.ts +21 -0
  176. package/dist/components/query_result/query_result_toolbar.js +74 -0
  177. package/dist/components/query_result/result_table_overlay.d.ts +9 -0
  178. package/dist/components/query_result/result_table_overlay.js +73 -0
  179. package/dist/components/query_result/result_table_overlay.module.js +6 -0
  180. package/dist/components/query_result/use_query_result_search.d.ts +8 -0
  181. package/dist/components/query_result/use_query_result_search.js +28 -0
  182. package/dist/components/segmented_control.d.ts +58 -0
  183. package/dist/components/segmented_control.js +116 -0
  184. package/dist/components/segmented_control.module.js +17 -0
  185. package/dist/components/separator.d.ts +21 -0
  186. package/dist/components/separator.js +79 -0
  187. package/dist/components/separator.module.js +7 -0
  188. package/dist/components/sheet.d.ts +11 -0
  189. package/dist/components/sheet.js +65 -0
  190. package/dist/components/sheet.module.js +7 -0
  191. package/dist/components/size_observer.d.ts +7 -0
  192. package/dist/components/size_observer.js +57 -0
  193. package/dist/components/skeleton.d.ts +2 -0
  194. package/dist/components/skeleton.js +14 -0
  195. package/dist/components/skeleton.module.js +2 -0
  196. package/dist/components/spinners.d.ts +8 -0
  197. package/dist/components/spinners.js +33 -0
  198. package/dist/components/spinners.module.js +8 -0
  199. package/dist/components/status_indicator.d.ts +36 -0
  200. package/dist/components/status_indicator.js +182 -0
  201. package/dist/components/status_indicator.module.js +3 -0
  202. package/dist/components/symbol_icon.d.ts +65 -0
  203. package/dist/components/symbol_icon.js +213 -0
  204. package/dist/components/tab_header.d.ts +11 -0
  205. package/dist/components/tab_header.js +55 -0
  206. package/dist/components/tab_header.module.js +7 -0
  207. package/dist/components/tag.d.ts +10 -0
  208. package/dist/components/tag.js +17 -0
  209. package/dist/components/tag.module.js +4 -0
  210. package/dist/components/text_field.d.ts +44 -0
  211. package/dist/components/text_field.js +159 -0
  212. package/dist/components/text_field.module.js +15 -0
  213. package/dist/components/text_input.d.ts +25 -0
  214. package/dist/components/text_input.js +90 -0
  215. package/dist/components/text_input.module.js +13 -0
  216. package/dist/components/text_input_action.d.ts +19 -0
  217. package/dist/components/text_input_action.js +33 -0
  218. package/dist/components/text_input_action.module.js +2 -0
  219. package/dist/components/toggle_switch.d.ts +7 -0
  220. package/dist/components/toggle_switch.js +22 -0
  221. package/dist/components/toggle_switch.module.js +6 -0
  222. package/dist/components/tooltip.d.ts +22 -0
  223. package/dist/components/tooltip.js +139 -0
  224. package/dist/components/tooltip.module.js +2 -0
  225. package/dist/components/tree_entry.d.ts +17 -0
  226. package/dist/components/tree_entry.js +48 -0
  227. package/dist/components/tree_entry.module.js +9 -0
  228. package/dist/components/value_list.d.ts +17 -0
  229. package/dist/components/value_list.js +70 -0
  230. package/dist/components/value_list.module.js +8 -0
  231. package/dist/components/vegalite_chart.d.ts +16 -0
  232. package/dist/components/vegalite_chart.js +149 -0
  233. package/dist/components/vegalite_chart.module.js +3 -0
  234. package/dist/components/vegalite_view.d.ts +26 -0
  235. package/dist/components/vegalite_view.js +239 -0
  236. package/dist/components/vegalite_view.module.js +5 -0
  237. package/dist/components/vertical_scroll_shadows.d.ts +14 -0
  238. package/dist/components/vertical_scroll_shadows.js +55 -0
  239. package/dist/components/vertical_scroll_shadows.module.js +5 -0
  240. package/dist/components/vertical_split.d.ts +15 -0
  241. package/dist/components/vertical_split.js +112 -0
  242. package/dist/components/vertical_split.module.js +5 -0
  243. package/dist/components/vertical_tabs.d.ts +36 -0
  244. package/dist/components/vertical_tabs.js +169 -0
  245. package/dist/components/vertical_tabs.module.js +23 -0
  246. package/dist/components/visualization/capped_rows.d.ts +9 -0
  247. package/dist/components/visualization/capped_rows.js +23 -0
  248. package/dist/components/visualization/capped_rows.module.js +3 -0
  249. package/dist/components/visualization/chart_download_button.d.ts +12 -0
  250. package/dist/components/visualization/chart_download_button.js +41 -0
  251. package/dist/components/visualization/kpi_view.d.ts +10 -0
  252. package/dist/components/visualization/kpi_view.js +215 -0
  253. package/dist/components/visualization/kpi_view.module.js +17 -0
  254. package/dist/components/visualization/markdown_view.d.ts +17 -0
  255. package/dist/components/visualization/markdown_view.js +154 -0
  256. package/dist/components/visualization/markdown_view.module.js +4 -0
  257. package/dist/components/visualization/result_rows.d.ts +17 -0
  258. package/dist/components/visualization/result_rows.js +82 -0
  259. package/dist/components/visualization/vegalite_preview.d.ts +8 -0
  260. package/dist/components/visualization/vegalite_preview.js +17 -0
  261. package/dist/components/visualization/vegalite_preview.module.js +2 -0
  262. package/dist/components/visualization/visualization_dispatch.d.ts +13 -0
  263. package/dist/components/visualization/visualization_dispatch.js +40 -0
  264. package/dist/components/visualization/visualization_panel.d.ts +10 -0
  265. package/dist/components/visualization/visualization_panel.js +36 -0
  266. package/dist/components/visualization/visualization_panel.module.js +3 -0
  267. package/dist/dom/anchored_position.d.ts +42 -0
  268. package/dist/dom/anchored_position.js +255 -0
  269. package/dist/dom/app_host.d.ts +2 -0
  270. package/dist/dom/app_host.js +7 -0
  271. package/dist/dom/calm_frames.d.ts +29 -0
  272. package/dist/dom/calm_frames.js +120 -0
  273. package/dist/dom/classnames.d.ts +8 -0
  274. package/dist/dom/classnames.js +20 -0
  275. package/dist/dom/download_file.d.ts +1 -0
  276. package/dist/dom/download_file.js +12 -0
  277. package/dist/dom/focus.d.ts +29 -0
  278. package/dist/dom/focus.js +84 -0
  279. package/dist/dom/graph_edges.d.ts +53 -0
  280. package/dist/dom/graph_edges.js +450 -0
  281. package/dist/dom/key_events.d.ts +9 -0
  282. package/dist/dom/key_events.js +33 -0
  283. package/dist/dom/media_query.d.ts +5 -0
  284. package/dist/dom/media_query.js +18 -0
  285. package/dist/dom/outside_click.d.ts +8 -0
  286. package/dist/dom/outside_click.js +32 -0
  287. package/dist/dom/rerender_ref.d.ts +2 -0
  288. package/dist/dom/rerender_ref.js +11 -0
  289. package/dist/dom/row_context_menu.d.ts +7 -0
  290. package/dist/dom/row_context_menu.js +32 -0
  291. package/dist/dom/scrollbar.d.ts +3 -0
  292. package/dist/dom/scrollbar.js +23 -0
  293. package/dist/format/format.d.ts +11 -0
  294. package/dist/format/format.js +72 -0
  295. package/dist/format/query_progress_format.d.ts +17 -0
  296. package/dist/format/query_progress_format.js +69 -0
  297. package/dist/format/time_format.d.ts +5 -0
  298. package/dist/format/time_format.js +45 -0
  299. package/dist/hooks.d.ts +72 -0
  300. package/dist/hooks.js +305 -0
  301. package/dist/host.d.ts +10 -0
  302. package/dist/host.js +12 -0
  303. package/dist/logger.d.ts +4 -0
  304. package/dist/logger.js +13 -0
  305. package/dist/models/computation_model.d.ts +14 -0
  306. package/dist/models/computation_model.js +27 -0
  307. package/dist/models/query_model.d.ts +12 -0
  308. package/dist/models/query_model.js +27 -0
  309. package/dist/models/script_model.d.ts +17 -0
  310. package/dist/models/script_model.js +59 -0
  311. package/dist/platform/content_length.d.ts +1 -0
  312. package/dist/platform/content_length.js +7 -0
  313. package/dist/platform/core_provider.d.ts +18 -0
  314. package/dist/platform/core_provider.js +106 -0
  315. package/dist/platform/embedded_database_provider.d.ts +19 -0
  316. package/dist/platform/embedded_database_provider.js +53 -0
  317. package/dist/platform/page_runtime.d.ts +3 -0
  318. package/dist/platform/page_runtime.js +29 -0
  319. package/dist/style.css +4386 -0
  320. package/dist/svg_symbols.d.ts +2 -0
  321. package/dist/svg_symbols.js +2 -0
  322. package/dist/symbols.svg +1197 -0
  323. package/dist/theme/color_scheme.d.ts +4 -0
  324. package/dist/theme/color_scheme.js +28 -0
  325. package/dist/theme/xcode_palette.d.ts +22 -0
  326. package/dist/theme/xcode_palette.js +4 -0
  327. package/dist/theme/xcode_palettes.js +41 -0
  328. package/dist/utils/plan_engine.d.ts +2 -0
  329. package/dist/utils/plan_engine.js +13 -0
  330. package/dist/vegalite/vegalite_check.d.ts +1 -0
  331. package/dist/vegalite/vegalite_check.js +7 -0
  332. package/dist/vegalite/vegalite_crossfilter.d.ts +54 -0
  333. package/dist/vegalite/vegalite_crossfilter.js +187 -0
  334. package/dist/vegalite/vegalite_image.d.ts +14 -0
  335. package/dist/vegalite/vegalite_image.js +28 -0
  336. package/dist/vegalite/vegalite_loader.d.ts +7 -0
  337. package/dist/vegalite/vegalite_loader.js +15 -0
  338. package/dist/vegalite/vegalite_rows.d.ts +3 -0
  339. package/dist/vegalite/vegalite_rows.js +23 -0
  340. package/dist/vegalite/vegalite_theme.d.ts +13 -0
  341. package/dist/vegalite/vegalite_theme.js +141 -0
  342. package/fonts/InstrumentSans-Bold.ttf +0 -0
  343. package/fonts/InstrumentSans-Medium.ttf +0 -0
  344. package/fonts/InstrumentSans-OFL.txt +93 -0
  345. package/fonts/InstrumentSans-Regular.ttf +0 -0
  346. package/fonts/InstrumentSans-SemiBold.ttf +0 -0
  347. package/fonts/JetBrainsMono-Bold.ttf +0 -0
  348. package/fonts/JetBrainsMono-Medium.ttf +0 -0
  349. package/fonts/JetBrainsMono-OFL.txt +93 -0
  350. package/fonts/JetBrainsMono-Regular.ttf +0 -0
  351. package/fonts/JetBrainsMono-SemiBold.ttf +0 -0
  352. package/fonts/fonts.css +61 -0
  353. package/package.json +403 -4
  354. package/styles/colors.css +110 -0
  355. package/styles/flavors/dbcom.css +48 -0
  356. package/styles/tokens.css +192 -0
package/dist/hooks.js ADDED
@@ -0,0 +1,305 @@
1
+ import * as React from "react";
2
+ import { stringifyError } from "@akohn/dashql/platform/logger/logger";
3
+ var LOG_CTX = "runtime";
4
+ var RUNTIME_CTX = React.createContext(null);
5
+ var RuntimeContextProvider = RUNTIME_CTX.Provider;
6
+ function useRuntime() {
7
+ const runtime = React.useContext(RUNTIME_CTX);
8
+ if (runtime == null) throw new Error("the runtime needs a provider, e.g. RuntimeContextProvider");
9
+ return runtime;
10
+ }
11
+ function useOptionalRuntime() {
12
+ return React.useContext(RUNTIME_CTX);
13
+ }
14
+ function useOwnedRuntime(create) {
15
+ const owned = React.useRef(null);
16
+ if (owned.current == null) owned.current = {
17
+ runtime: create(),
18
+ release: null
19
+ };
20
+ React.useEffect(() => {
21
+ const held = owned.current;
22
+ if (held == null) return;
23
+ if (held.release != null) {
24
+ clearTimeout(held.release);
25
+ held.release = null;
26
+ }
27
+ return () => {
28
+ held.release = setTimeout(() => {
29
+ if (owned.current === held) owned.current = null;
30
+ held.runtime.destroy().catch((error) => {
31
+ held.runtime.logger.error("Failed to stop the runtime", { error: stringifyError(error) }, LOG_CTX);
32
+ });
33
+ }, 0);
34
+ };
35
+ }, []);
36
+ return owned.current.runtime;
37
+ }
38
+ var NO_SUBSCRIPTION = () => () => {};
39
+ function useViewSelector(kind, id, select) {
40
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
41
+ const subscribe = React.useMemo(() => store == null || id == null ? NO_SUBSCRIPTION : (listener) => store.subscribe(kind, id, listener), [
42
+ store,
43
+ kind,
44
+ id
45
+ ]);
46
+ const getSelection = () => select(store == null || id == null ? null : store.get(kind, id));
47
+ return React.useSyncExternalStore(subscribe, getSelection, getSelection);
48
+ }
49
+ function useView(kind, id) {
50
+ return useViewSelector(kind, id, selectView);
51
+ }
52
+ var selectView = (view) => view;
53
+ function useViewReader() {
54
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
55
+ return React.useCallback((kind, id) => store?.get(kind, id) ?? null, [store]);
56
+ }
57
+ function useAll(kind) {
58
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
59
+ const subscribe = React.useMemo(() => store == null ? NO_SUBSCRIPTION : (listener) => store.subscribeKind(kind, listener), [store, kind]);
60
+ const getSnapshot = React.useCallback(() => store?.all(kind) ?? NO_SLICES, [store, kind]);
61
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
62
+ }
63
+ var NO_SLICES = /* @__PURE__ */ new Map();
64
+ function useDispatch(target) {
65
+ const runtime = React.useContext(RUNTIME_CTX);
66
+ const key = target == null ? null : JSON.stringify(target);
67
+ return React.useCallback((action) => {
68
+ if (runtime == null) throw new Error("the runtime needs a provider, e.g. RuntimeContextProvider");
69
+ if (key == null) return {
70
+ ok: false,
71
+ changed: false,
72
+ error: "no target",
73
+ id: null,
74
+ settled: Promise.resolve()
75
+ };
76
+ return runtime.dispatch(JSON.parse(key), action);
77
+ }, [runtime, key]);
78
+ }
79
+ function useTable(handle) {
80
+ return React.useContext(RUNTIME_CTX)?.table(handle) ?? null;
81
+ }
82
+ var useWorkbook = (workbookId) => useView("workbook", workbookId);
83
+ function useWorkbookShown(workbookId) {
84
+ const runtime = React.useContext(RUNTIME_CTX);
85
+ React.useEffect(() => {
86
+ if (workbookId != null) runtime?.showWorkbook(workbookId);
87
+ }, [runtime, workbookId]);
88
+ }
89
+ var useScript = (scriptKey) => useView("script", scriptKey);
90
+ var useWorkbookDerived = (workbookId) => useView("workbookDerived", workbookId);
91
+ function useScriptReferences(workbookId, scriptKey) {
92
+ return useViewSelector("workbookDerived", workbookId, (derived) => scriptKey == null ? null : derived?.references.get(scriptKey) ?? null);
93
+ }
94
+ var selectInputs = (derived) => derived?.inputs ?? null;
95
+ var useWorkbookInputs = (workbookId) => useViewSelector("workbookDerived", workbookId, selectInputs);
96
+ var useWorkbookList = () => useView("workbookList", "root");
97
+ var useWorkbooks = () => useAll("workbook");
98
+ function useWorkbookScriptMap(workbookId) {
99
+ const store = React.useContext(RUNTIME_CTX)?.store ?? null;
100
+ const cache = React.useRef({
101
+ keys: null,
102
+ scripts: [],
103
+ map: {}
104
+ });
105
+ const subscribe = React.useMemo(() => {
106
+ if (store == null || workbookId == null) return NO_SUBSCRIPTION;
107
+ return (listener) => {
108
+ const unsubscribeWorkbook = store.subscribe("workbook", workbookId, listener);
109
+ const unsubscribeScripts = store.subscribeKind("script", listener);
110
+ return () => {
111
+ unsubscribeWorkbook();
112
+ unsubscribeScripts();
113
+ };
114
+ };
115
+ }, [store, workbookId]);
116
+ const getSnapshot = React.useCallback(() => {
117
+ const keys = workbookId == null ? null : store?.get("workbook", workbookId)?.scriptKeys ?? null;
118
+ const scripts = (keys ?? []).map((key) => store?.get("script", key) ?? null);
119
+ const held = cache.current;
120
+ if (held.keys === keys && held.scripts.length === scripts.length && scripts.every((script, i) => script === held.scripts[i])) return held.map;
121
+ const map = {};
122
+ for (const script of scripts) if (script != null) map[script.scriptKey] = script;
123
+ cache.current = {
124
+ keys,
125
+ scripts,
126
+ map
127
+ };
128
+ return map;
129
+ }, [store, workbookId]);
130
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
131
+ }
132
+ var useConnection = (connectionId) => useView("connection", connectionId);
133
+ function useCatalog(connectionId) {
134
+ const runtime = React.useContext(RUNTIME_CTX);
135
+ const catalogId = useConnection(connectionId)?.catalogId ?? null;
136
+ return React.useMemo(() => runtime == null || connectionId == null || catalogId == null ? null : runtime.catalog(connectionId), [
137
+ runtime,
138
+ connectionId,
139
+ catalogId
140
+ ]);
141
+ }
142
+ var useConnectionList = () => useView("connectionList", "root");
143
+ var useConnections = () => useAll("connection");
144
+ function useConnectionViews(connectionIds) {
145
+ const connections = useConnections();
146
+ let resolved = null;
147
+ if (connectionIds != null && connectionIds.length > 0) {
148
+ const views = connectionIds.map((connectionId) => connections.get(connectionId));
149
+ if (views.every((view) => view != null)) resolved = views;
150
+ }
151
+ const latest = React.useRef(resolved);
152
+ if (!(latest.current === resolved || latest.current != null && resolved != null && latest.current.length === resolved.length && latest.current.every((connection, i) => connection === resolved[i]))) latest.current = resolved;
153
+ return latest.current;
154
+ }
155
+ var useQuery = (queryId) => useView("query", queryId);
156
+ var useAllQueries = () => useAll("query");
157
+ function useQueryResultTable(query) {
158
+ return useTable(query?.resultTable?.id ?? null);
159
+ }
160
+ function useQueryProfileDetail(queryId, enabled = true) {
161
+ const runtime = React.useContext(RUNTIME_CTX);
162
+ React.useEffect(() => {
163
+ if (!enabled || queryId == null || runtime == null) return;
164
+ return runtime.watchProfile(queryId);
165
+ }, [
166
+ runtime,
167
+ queryId,
168
+ enabled
169
+ ]);
170
+ }
171
+ var useComputation = (tableId) => useView("computation", tableId);
172
+ var useComputationDispatch = (tableId) => useDispatch(tableId == null ? null : { computation: tableId });
173
+ function useTableComputation(load, clientContext = null) {
174
+ const runtime = useRuntime();
175
+ const [state, setState] = React.useState({ status: "idle" });
176
+ const shown = React.useRef(null);
177
+ const release = React.useCallback((tableId) => {
178
+ runtime.dispatch({ computation: tableId }, { kind: "deleteComputation" });
179
+ }, [runtime]);
180
+ React.useEffect(() => () => {
181
+ if (shown.current != null) release(shown.current);
182
+ shown.current = null;
183
+ }, [release]);
184
+ React.useEffect(() => {
185
+ if (load == null) return;
186
+ let current = true;
187
+ setState((state) => state.status === "ready" ? state : { status: "loading" });
188
+ (async () => {
189
+ let tableId = null;
190
+ try {
191
+ const table = await load();
192
+ if (!current) return;
193
+ tableId = runtime.allocateId();
194
+ const ordering = shown.current == null ? [] : runtime.store.get("computation", shown.current)?.dataTableOrdering ?? [];
195
+ await runtime.analyzeTable(tableId, table, {
196
+ clientContext,
197
+ columnAggregates: false,
198
+ ordering
199
+ });
200
+ if (!current) {
201
+ release(tableId);
202
+ return;
203
+ }
204
+ const previous = shown.current;
205
+ shown.current = tableId;
206
+ setState({
207
+ status: "ready",
208
+ tableId,
209
+ table
210
+ });
211
+ if (previous != null) release(previous);
212
+ } catch (error) {
213
+ if (tableId != null) release(tableId);
214
+ runtime.logger.warn("Loading a table failed", { error: stringifyError(error) }, LOG_CTX);
215
+ if (current) setState((state) => state.status === "ready" ? state : {
216
+ status: "failed",
217
+ error: stringifyError(error)
218
+ });
219
+ }
220
+ })();
221
+ return () => {
222
+ current = false;
223
+ };
224
+ }, [
225
+ runtime,
226
+ release,
227
+ load,
228
+ clientContext
229
+ ]);
230
+ return state;
231
+ }
232
+ function useComputeReady() {
233
+ const database = React.useContext(RUNTIME_CTX)?.computeDatabase ?? null;
234
+ const subscribe = React.useMemo(() => database == null ? NO_SUBSCRIPTION : (listener) => database.subscribe(listener), [database]);
235
+ const getSnapshot = React.useCallback(() => database?.ready ?? false, [database]);
236
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
237
+ }
238
+ function useComputeDatabase() {
239
+ const runtime = React.useContext(RUNTIME_CTX);
240
+ const ready = useComputeReady();
241
+ const [database, setDatabase] = React.useState(null);
242
+ React.useEffect(() => {
243
+ if (runtime == null || !ready) return;
244
+ let current = true;
245
+ runtime.computeDatabase.get().then((resolved) => {
246
+ if (current) setDatabase(resolved);
247
+ }, () => {});
248
+ return () => {
249
+ current = false;
250
+ };
251
+ }, [runtime, ready]);
252
+ return ready ? database : null;
253
+ }
254
+ function useWorkbookExecution(workbookId) {
255
+ const runtime = React.useContext(RUNTIME_CTX);
256
+ const run = useView("run", workbookId);
257
+ const ready = useComputeReady();
258
+ const state = run?.state ?? null;
259
+ const held = run?.held != null;
260
+ return React.useMemo(() => {
261
+ const busy = state?.busy ?? false;
262
+ return {
263
+ state,
264
+ busy,
265
+ ready,
266
+ runActive: busy || held,
267
+ start: (options) => {
268
+ if (runtime == null) return;
269
+ const failed = (error) => runtime.logger.error("The run of the workbook failed", {
270
+ workbookId,
271
+ error: stringifyError(error)
272
+ }, "workbook_execution");
273
+ runtime.runWorkbook(workbookId, {
274
+ inputs: options?.inputs == null ? void 0 : [...options.inputs],
275
+ targets: options?.targets == null ? void 0 : [...options.targets]
276
+ }).then((result) => {
277
+ const failure = result.outcome.failure;
278
+ if (failure != null && failure.kind === "error" && failure.queryId == null) failed(result.error);
279
+ }, failed);
280
+ },
281
+ stop: () => runtime?.stopRun(workbookId)
282
+ };
283
+ }, [
284
+ state,
285
+ held,
286
+ runtime,
287
+ workbookId,
288
+ ready
289
+ ]);
290
+ }
291
+ function useScriptRun() {
292
+ const runtime = React.useContext(RUNTIME_CTX);
293
+ return React.useMemo(() => runtime == null ? null : async (workbookId, scriptKey, options = {}) => {
294
+ try {
295
+ await runtime.runScript(workbookId, scriptKey, { refresh: options.refresh });
296
+ } catch (error) {
297
+ runtime.logger.warn("Workbook script run failed", {
298
+ workbookId,
299
+ scriptKey: scriptKey.toString(),
300
+ error: stringifyError(error)
301
+ }, "workbook_execution");
302
+ }
303
+ }, [runtime]);
304
+ }
305
+ export { RuntimeContextProvider, useAllQueries, useCatalog, useComputation, useComputationDispatch, useComputeDatabase, useComputeReady, useConnection, useConnectionList, useConnectionViews, useConnections, useDispatch, useOptionalRuntime, useOwnedRuntime, useQuery, useQueryProfileDetail, useQueryResultTable, useRuntime, useScript, useScriptReferences, useScriptRun, useTable, useTableComputation, useView, useViewReader, useViewSelector, useWorkbook, useWorkbookDerived, useWorkbookExecution, useWorkbookInputs, useWorkbookList, useWorkbookScriptMap, useWorkbookShown, useWorkbooks };
package/dist/host.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import type * as dashql from '@akohn/dashql';
3
+ export type CoreSetup = (context: string) => Promise<dashql.DashQL>;
4
+ export type DownloadFile = (data: Uint8Array | Blob, fileName: string) => Promise<void>;
5
+ export interface Host {
6
+ setupCore: CoreSetup | null;
7
+ downloadFile: DownloadFile;
8
+ }
9
+ export declare const HostProvider: React.Provider<Host>;
10
+ export declare function useHost(): Host;
package/dist/host.js ADDED
@@ -0,0 +1,12 @@
1
+ import { downloadFile } from "./dom/download_file.js";
2
+ import * as React from "react";
3
+ var DEFAULT_HOST = {
4
+ setupCore: null,
5
+ downloadFile
6
+ };
7
+ var HOST = React.createContext(DEFAULT_HOST);
8
+ var HostProvider = HOST.Provider;
9
+ function useHost() {
10
+ return React.useContext(HOST);
11
+ }
12
+ export { HostProvider, useHost };
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { Logger } from '@akohn/dashql/platform/logger/logger';
3
+ export declare const LoggerContext: React.Context<Logger>;
4
+ export declare function useLogger(): Logger;
package/dist/logger.js ADDED
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ import { Logger } from "@akohn/dashql/platform/logger/logger";
3
+ var DroppingLogger = class extends Logger {
4
+ destroy() {}
5
+ flushPendingRecords() {
6
+ this.pendingRecords = [];
7
+ }
8
+ };
9
+ var LoggerContext = React.createContext(new DroppingLogger());
10
+ function useLogger() {
11
+ return React.useContext(LoggerContext);
12
+ }
13
+ export { LoggerContext, useLogger };
@@ -0,0 +1,14 @@
1
+ import * as arrow from 'apache-arrow';
2
+ import type * as core from '@akohn/dashql';
3
+ import type { ComputationView } from '@akohn/dashql';
4
+ import type { ResultRowWindow } from '@akohn/dashql/runtime';
5
+ import type { SummaryTables } from '@akohn/dashql/platform/compute/computation_types';
6
+ export interface ComputationModel {
7
+ readonly computation: ComputationView;
8
+ readonly tables: SummaryTables;
9
+ dispatch(action: core.ComputationAction): core.DispatchOutcome;
10
+ readRows(offset: number, limit: number): Promise<ResultRowWindow>;
11
+ previewRows(offset: number, limit: number, rowNumbers: boolean): Promise<arrow.Table>;
12
+ }
13
+ export type { ResultRowWindow };
14
+ export declare function useComputationModel(computation: ComputationView | null | undefined): ComputationModel | null;
@@ -0,0 +1,27 @@
1
+ import { useComputationDispatch, useOptionalRuntime } from "../hooks.js";
2
+ import * as React from "react";
3
+ import * as arrow from "apache-arrow";
4
+ var NO_TABLES = { table: () => void 0 };
5
+ var noRows = async () => {
6
+ throw new Error("there is no runtime to read the rows from");
7
+ };
8
+ function useComputationModel(computation) {
9
+ const runtime = useOptionalRuntime();
10
+ const dispatch = useComputationDispatch(computation?.tableId);
11
+ return React.useMemo(() => {
12
+ if (computation == null) return null;
13
+ const tableId = computation.tableId;
14
+ return {
15
+ computation,
16
+ tables: runtime ?? NO_TABLES,
17
+ dispatch,
18
+ readRows: runtime == null ? noRows : (offset, limit) => runtime.readResultRows(tableId, offset, limit),
19
+ previewRows: runtime == null ? noRows : async (offset, limit, rowNumbers) => arrow.tableFromIPC(await runtime.previewResult(tableId, offset, limit, rowNumbers))
20
+ };
21
+ }, [
22
+ runtime,
23
+ computation,
24
+ dispatch
25
+ ]);
26
+ }
27
+ export { useComputationModel };
@@ -0,0 +1,12 @@
1
+ import type * as arrow from 'apache-arrow';
2
+ import type { QueryExecutionProgress, QueryExecutionState } from '@akohn/dashql/platform/query/query_execution_state';
3
+ import { type ComputationModel } from './computation_model.js';
4
+ export interface QueryModel {
5
+ readonly queryId: number;
6
+ readonly query: QueryExecutionState;
7
+ readonly progress: QueryExecutionProgress | null;
8
+ readonly result: arrow.Table | null;
9
+ readonly computation: ComputationModel | null;
10
+ cancel(): Promise<void>;
11
+ }
12
+ export declare function useQueryModel(queryId: number | null | undefined): QueryModel | null;
@@ -0,0 +1,27 @@
1
+ import { useComputation, useOptionalRuntime, useQuery, useTable } from "../hooks.js";
2
+ import { useComputationModel } from "./computation_model.js";
3
+ import * as React from "react";
4
+ function useQueryModel(queryId) {
5
+ const runtime = useOptionalRuntime();
6
+ const query = useQuery(queryId);
7
+ const result = useTable(query?.resultTable?.id ?? null);
8
+ const computation = useComputationModel(useComputation(queryId));
9
+ return React.useMemo(() => {
10
+ if (query == null || queryId == null) return null;
11
+ return {
12
+ queryId,
13
+ query,
14
+ progress: query.progress ?? null,
15
+ result,
16
+ computation,
17
+ cancel: async () => await runtime?.cancel(queryId)
18
+ };
19
+ }, [
20
+ runtime,
21
+ queryId,
22
+ query,
23
+ result,
24
+ computation
25
+ ]);
26
+ }
27
+ export { useQueryModel };
@@ -0,0 +1,17 @@
1
+ import type { ScriptData } from '@akohn/dashql/platform/workbook/workbook_scripts';
2
+ import { type QueryModel } from './query_model.js';
3
+ export interface ScriptModel {
4
+ readonly workbookId: string;
5
+ readonly script: ScriptData;
6
+ readonly query: QueryModel | null;
7
+ readonly runActive: boolean;
8
+ run(options?: {
9
+ refresh?: boolean;
10
+ }): Promise<void>;
11
+ cancel(): Promise<void>;
12
+ setText(text: string): Promise<void>;
13
+ acceptDiff(): Promise<void>;
14
+ rejectDiff(): Promise<void>;
15
+ setVisSpec(spec: string): Promise<void>;
16
+ }
17
+ export declare function useScriptModel(workbookId: string, scriptKey: number | null | undefined): ScriptModel | null;
@@ -0,0 +1,59 @@
1
+ import { useDispatch, useOptionalRuntime, useScript, useScriptRun, useViewSelector } from "../hooks.js";
2
+ import { useQueryModel } from "./query_model.js";
3
+ import * as React from "react";
4
+ function useScriptModel(workbookId, scriptKey) {
5
+ const runtime = useOptionalRuntime();
6
+ const runScript = useScriptRun();
7
+ const script = useScript(scriptKey);
8
+ const query = useQueryModel(script?.latestQueryId ?? null);
9
+ const runActive = useViewSelector("run", workbookId, (run) => run?.state?.busy === true || run?.held != null);
10
+ const dispatch = useDispatch({ workbook: workbookId });
11
+ const key = script?.scriptKey ?? null;
12
+ const operations = React.useMemo(() => key == null ? null : {
13
+ run: async (options) => await runScript?.(workbookId, key, options),
14
+ cancel: async () => await runtime?.cancelScript(workbookId, key),
15
+ setText: (text) => dispatch({
16
+ kind: "setScriptText",
17
+ value: {
18
+ scriptKey: key,
19
+ text,
20
+ withDiff: true
21
+ }
22
+ }).settled,
23
+ acceptDiff: () => dispatch({
24
+ kind: "acceptPendingDiff",
25
+ value: { scriptKey: key }
26
+ }).settled,
27
+ rejectDiff: () => dispatch({
28
+ kind: "rejectPendingDiff",
29
+ value: { scriptKey: key }
30
+ }).settled,
31
+ setVisSpec: (spec) => dispatch({
32
+ kind: "setScriptVisSpec",
33
+ value: {
34
+ scriptKey: key,
35
+ spec
36
+ }
37
+ }).settled
38
+ }, [
39
+ runtime,
40
+ runScript,
41
+ workbookId,
42
+ key,
43
+ dispatch
44
+ ]);
45
+ return React.useMemo(() => script == null || operations == null ? null : {
46
+ workbookId,
47
+ script,
48
+ query,
49
+ runActive,
50
+ ...operations
51
+ }, [
52
+ workbookId,
53
+ script,
54
+ query,
55
+ runActive,
56
+ operations
57
+ ]);
58
+ }
59
+ export { useScriptModel };
@@ -0,0 +1 @@
1
+ export declare function decodedContentLength(response: Response): number;
@@ -0,0 +1,7 @@
1
+ function decodedContentLength(response) {
2
+ const encoding = response.headers.get("content-encoding");
3
+ if (encoding != null && encoding.trim().toLowerCase() !== "identity") return 0;
4
+ const length = parseInt(response.headers.get("content-length") ?? "", 10);
5
+ return Number.isFinite(length) && length > 0 ? length : 0;
6
+ }
7
+ export { decodedContentLength };
@@ -0,0 +1,18 @@
1
+ import * as dashql from '@akohn/dashql';
2
+ import * as React from 'react';
3
+ import { type CoreSetup } from '../host.js';
4
+ export interface InstantiationProgress {
5
+ startedAt: Date;
6
+ updatedAt: Date;
7
+ bytesTotal: bigint;
8
+ bytesLoaded: bigint;
9
+ }
10
+ interface Props {
11
+ wasmUrl: string | URL;
12
+ children?: React.ReactNode;
13
+ }
14
+ export declare function DashQLCoreProvider(props: Props): React.FunctionComponentElement<React.ProviderProps<import("../host.js").Host>>;
15
+ export declare const useDashQLCoreSetupProgress: () => InstantiationProgress | null;
16
+ export declare function useDashQLCoreSetup(): CoreSetup;
17
+ export declare function useDashQLCore(): dashql.DashQL | null;
18
+ export {};
@@ -0,0 +1,106 @@
1
+ import { HostProvider, useHost } from "../host.js";
2
+ import { useLogger } from "../logger.js";
3
+ import { decodedContentLength } from "./content_length.js";
4
+ import * as React from "react";
5
+ import { stringifyError } from "@akohn/dashql/platform/logger/logger";
6
+ import * as dashql from "@akohn/dashql";
7
+ import { createTrace } from "@akohn/dashql/platform/logger/trace_context";
8
+ var PROGRESS_CONTEXT = React.createContext(null);
9
+ var CORE_CONTEXT = React.createContext(null);
10
+ function DashQLCoreProvider(props) {
11
+ const logger = useLogger();
12
+ const outer = useHost();
13
+ const wasmUrl = props.wasmUrl.toString();
14
+ const instantiation = React.useRef(null);
15
+ const lifecycle = React.useRef({ disposed: false });
16
+ const [progress, setProgress] = React.useState(null);
17
+ const [core, setCore] = React.useState(null);
18
+ const instantiator = React.useCallback(async (context) => {
19
+ const owner = lifecycle.current;
20
+ if (owner.disposed) throw new DOMException("Core provider was disposed", "AbortError");
21
+ if (instantiation.current != null) return await instantiation.current;
22
+ const now = /* @__PURE__ */ new Date();
23
+ const internal = {
24
+ startedAt: now,
25
+ updatedAt: now,
26
+ bytesTotal: BigInt(0),
27
+ bytesLoaded: BigInt(0)
28
+ };
29
+ const fetchWithProgress = async (url, traced) => {
30
+ traced.info("Fetching core wasm", { "context": context }, "core");
31
+ const response = await fetch(new Request(url));
32
+ if (!response.ok) throw new Error(`Failed to fetch core wasm: ${response.status} ${response.statusText}`);
33
+ const contentLength = decodedContentLength(response);
34
+ const now = /* @__PURE__ */ new Date();
35
+ internal.startedAt = now;
36
+ internal.updatedAt = now;
37
+ internal.bytesTotal = BigInt(contentLength) || BigInt(0);
38
+ internal.bytesLoaded = BigInt(0);
39
+ return new Response(response.body?.pipeThrough(new TransformStream({ transform(chunk, ctrl) {
40
+ const prevUpdate = internal.updatedAt;
41
+ internal.updatedAt = /* @__PURE__ */ new Date();
42
+ internal.bytesLoaded += BigInt(chunk.byteLength);
43
+ if (internal.updatedAt.getTime() - prevUpdate.getTime() > 20) setProgress((_) => ({ ...internal }));
44
+ ctrl.enqueue(chunk);
45
+ } })), response);
46
+ };
47
+ const instantiate = async () => {
48
+ const traced = logger.withTrace(createTrace());
49
+ const initStart = performance.now();
50
+ try {
51
+ traced.info("Loading core Wasm", { "context": context }, "core");
52
+ const response = await fetchWithProgress(wasmUrl, traced);
53
+ const wasmBinary = new Uint8Array(await response.arrayBuffer());
54
+ const instance = await dashql.DashQL.create({ wasmBinary });
55
+ if (owner.disposed) throw new DOMException("Core provider was disposed", "AbortError");
56
+ traced.info("Instantiated core", {
57
+ "context": context,
58
+ "duration": Math.floor(performance.now() - initStart).toString()
59
+ }, "core");
60
+ setProgress((_) => ({
61
+ ...internal,
62
+ updatedAt: /* @__PURE__ */ new Date()
63
+ }));
64
+ return instance;
65
+ } catch (e) {
66
+ traced.error("Failed to instantiate core", {
67
+ "error": stringifyError(e),
68
+ "duration": Math.floor(performance.now() - initStart).toString()
69
+ }, "core");
70
+ throw e;
71
+ }
72
+ };
73
+ instantiation.current = instantiate();
74
+ instantiation.current.then((instance) => {
75
+ if (!owner.disposed) setCore(instance);
76
+ }, () => {});
77
+ return await instantiation.current;
78
+ }, [logger, wasmUrl]);
79
+ React.useEffect(() => {
80
+ if (lifecycle.current.disposed) lifecycle.current = { disposed: false };
81
+ const owner = lifecycle.current;
82
+ return () => {
83
+ owner.disposed = true;
84
+ instantiation.current = null;
85
+ };
86
+ }, []);
87
+ const host = React.useMemo(() => ({
88
+ ...outer,
89
+ setupCore: instantiator
90
+ }), [outer, instantiator]);
91
+ return React.createElement(HostProvider, { value: host }, React.createElement(PROGRESS_CONTEXT.Provider, { value: progress }, React.createElement(CORE_CONTEXT.Provider, { value: core }, props.children)));
92
+ }
93
+ var useDashQLCoreSetupProgress = () => React.useContext(PROGRESS_CONTEXT);
94
+ function useDashQLCoreSetup() {
95
+ return useHost().setupCore;
96
+ }
97
+ function useDashQLCore() {
98
+ const setup = useHost().setupCore;
99
+ const core = React.useContext(CORE_CONTEXT);
100
+ const [instantiated] = React.useState(() => setup == null ? dashql.DashQL.instantiated() : null);
101
+ React.useEffect(() => {
102
+ if (setup != null && core == null) setup("runtime").catch(() => {});
103
+ }, [setup, core]);
104
+ return setup == null ? instantiated : core;
105
+ }
106
+ export { DashQLCoreProvider, useDashQLCore, useDashQLCoreSetup, useDashQLCoreSetupProgress };
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import type { EmbeddedComputeDatabase } from '@akohn/dashql/platform/embedded_database';
3
+ import type { EmbeddedDatabaseOptions, SetupProgress } from '@akohn/dashql/platform/hyperdb/hyperdb_web';
4
+ import type { Logger } from '@akohn/dashql/platform/logger/logger';
5
+ export type { EmbeddedDatabaseOptions, SetupProgress };
6
+ export type EmbeddedDatabaseFactory = (context: string, logger: Logger, onSetupProgress?: (progress: SetupProgress) => void, options?: EmbeddedDatabaseOptions) => Promise<EmbeddedComputeDatabase>;
7
+ export type EmbeddedDatabaseSetupFn = (context: string, onSetupProgress?: (progress: SetupProgress) => void) => Promise<EmbeddedComputeDatabase>;
8
+ interface EmbeddedDatabase {
9
+ setup: EmbeddedDatabaseSetupFn;
10
+ terminate: () => Promise<void>;
11
+ }
12
+ interface Props {
13
+ setupDatabase: EmbeddedDatabaseFactory;
14
+ options?: EmbeddedDatabaseOptions | null;
15
+ children?: React.ReactNode;
16
+ }
17
+ export declare function EmbeddedDatabaseProvider(props: Props): React.FunctionComponentElement<React.ProviderProps<EmbeddedDatabase | null>>;
18
+ export declare function useEmbeddedDatabaseSetup(): EmbeddedDatabaseSetupFn | null;
19
+ export declare function useEmbeddedDatabaseTermination(): () => Promise<void>;