@finos/legend-cube-builder 0.0.0-stage → 0.0.2

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 (301) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -2
  3. package/lib/__lib__/LegendCubeCommand.d.ts +26 -0
  4. package/lib/__lib__/LegendCubeCommand.d.ts.map +1 -0
  5. package/lib/__lib__/LegendCubeCommand.js +40 -0
  6. package/lib/__lib__/LegendCubeCommand.js.map +1 -0
  7. package/lib/__lib__/LegendCubeHelpText.d.ts +19 -0
  8. package/lib/__lib__/LegendCubeHelpText.d.ts.map +1 -0
  9. package/lib/__lib__/LegendCubeHelpText.js +27 -0
  10. package/lib/__lib__/LegendCubeHelpText.js.map +1 -0
  11. package/lib/__lib__/LegendCubeLabels.d.ts +68 -0
  12. package/lib/__lib__/LegendCubeLabels.d.ts.map +1 -0
  13. package/lib/__lib__/LegendCubeLabels.js +109 -0
  14. package/lib/__lib__/LegendCubeLabels.js.map +1 -0
  15. package/lib/__lib__/LegendCubeTesting.d.ts +33 -0
  16. package/lib/__lib__/LegendCubeTesting.d.ts.map +1 -0
  17. package/lib/__lib__/LegendCubeTesting.js +34 -0
  18. package/lib/__lib__/LegendCubeTesting.js.map +1 -0
  19. package/lib/__test-utils__/CubeCanvasTestUtils.d.ts +24 -0
  20. package/lib/__test-utils__/CubeCanvasTestUtils.d.ts.map +1 -0
  21. package/lib/__test-utils__/CubeCanvasTestUtils.js +37 -0
  22. package/lib/__test-utils__/CubeCanvasTestUtils.js.map +1 -0
  23. package/lib/__test-utils__/CubeEngineTestSupport.d.ts +41 -0
  24. package/lib/__test-utils__/CubeEngineTestSupport.d.ts.map +1 -0
  25. package/lib/__test-utils__/CubeEngineTestSupport.js +76 -0
  26. package/lib/__test-utils__/CubeEngineTestSupport.js.map +1 -0
  27. package/lib/__test-utils__/CubeNorthwindTestQueries.d.ts +31 -0
  28. package/lib/__test-utils__/CubeNorthwindTestQueries.d.ts.map +1 -0
  29. package/lib/__test-utils__/CubeNorthwindTestQueries.js +102 -0
  30. package/lib/__test-utils__/CubeNorthwindTestQueries.js.map +1 -0
  31. package/lib/__test-utils__/CubePageTestUtils.d.ts +33 -0
  32. package/lib/__test-utils__/CubePageTestUtils.d.ts.map +1 -0
  33. package/lib/__test-utils__/CubePageTestUtils.js +68 -0
  34. package/lib/__test-utils__/CubePageTestUtils.js.map +1 -0
  35. package/lib/__test-utils__/CubeTestApplication.d.ts +30 -0
  36. package/lib/__test-utils__/CubeTestApplication.d.ts.map +1 -0
  37. package/lib/__test-utils__/CubeTestApplication.js +57 -0
  38. package/lib/__test-utils__/CubeTestApplication.js.map +1 -0
  39. package/lib/__test-utils__/FakeCubeEngine.d.ts +41 -0
  40. package/lib/__test-utils__/FakeCubeEngine.d.ts.map +1 -0
  41. package/lib/__test-utils__/FakeCubeEngine.js +85 -0
  42. package/lib/__test-utils__/FakeCubeEngine.js.map +1 -0
  43. package/lib/components/CubeButton.d.ts +20 -0
  44. package/lib/components/CubeButton.d.ts.map +1 -0
  45. package/lib/components/CubeButton.js +24 -0
  46. package/lib/components/CubeButton.js.map +1 -0
  47. package/lib/components/CubeEditor.d.ts +31 -0
  48. package/lib/components/CubeEditor.d.ts.map +1 -0
  49. package/lib/components/CubeEditor.js +90 -0
  50. package/lib/components/CubeEditor.js.map +1 -0
  51. package/lib/components/CubeNodeIcon.d.ts +23 -0
  52. package/lib/components/CubeNodeIcon.d.ts.map +1 -0
  53. package/lib/components/CubeNodeIcon.js +32 -0
  54. package/lib/components/CubeNodeIcon.js.map +1 -0
  55. package/lib/components/canvas/CubeCanvas.d.ts +37 -0
  56. package/lib/components/canvas/CubeCanvas.d.ts.map +1 -0
  57. package/lib/components/canvas/CubeCanvas.js +135 -0
  58. package/lib/components/canvas/CubeCanvas.js.map +1 -0
  59. package/lib/components/canvas/CubeCanvasContext.d.ts +19 -0
  60. package/lib/components/canvas/CubeCanvasContext.d.ts.map +1 -0
  61. package/lib/components/canvas/CubeCanvasContext.js +22 -0
  62. package/lib/components/canvas/CubeCanvasContext.js.map +1 -0
  63. package/lib/components/canvas/CubeCanvasContextMenu.d.ts +28 -0
  64. package/lib/components/canvas/CubeCanvasContextMenu.d.ts.map +1 -0
  65. package/lib/components/canvas/CubeCanvasContextMenu.js +35 -0
  66. package/lib/components/canvas/CubeCanvasContextMenu.js.map +1 -0
  67. package/lib/components/canvas/CubeCanvasDnd.d.ts +43 -0
  68. package/lib/components/canvas/CubeCanvasDnd.d.ts.map +1 -0
  69. package/lib/components/canvas/CubeCanvasDnd.js +51 -0
  70. package/lib/components/canvas/CubeCanvasDnd.js.map +1 -0
  71. package/lib/components/canvas/CubeCanvasEdge.d.ts +24 -0
  72. package/lib/components/canvas/CubeCanvasEdge.d.ts.map +1 -0
  73. package/lib/components/canvas/CubeCanvasEdge.js +33 -0
  74. package/lib/components/canvas/CubeCanvasEdge.js.map +1 -0
  75. package/lib/components/canvas/CubeCanvasElements.d.ts +64 -0
  76. package/lib/components/canvas/CubeCanvasElements.d.ts.map +1 -0
  77. package/lib/components/canvas/CubeCanvasElements.js +96 -0
  78. package/lib/components/canvas/CubeCanvasElements.js.map +1 -0
  79. package/lib/components/canvas/CubeCanvasLayout.d.ts +32 -0
  80. package/lib/components/canvas/CubeCanvasLayout.d.ts.map +1 -0
  81. package/lib/components/canvas/CubeCanvasLayout.js +63 -0
  82. package/lib/components/canvas/CubeCanvasLayout.js.map +1 -0
  83. package/lib/components/canvas/CubeCanvasNode.d.ts +29 -0
  84. package/lib/components/canvas/CubeCanvasNode.d.ts.map +1 -0
  85. package/lib/components/canvas/CubeCanvasNode.js +72 -0
  86. package/lib/components/canvas/CubeCanvasNode.js.map +1 -0
  87. package/lib/components/editors/CubeColumnPicker.d.ts +40 -0
  88. package/lib/components/editors/CubeColumnPicker.d.ts.map +1 -0
  89. package/lib/components/editors/CubeColumnPicker.js +51 -0
  90. package/lib/components/editors/CubeColumnPicker.js.map +1 -0
  91. package/lib/components/editors/CubeFilterEditor.d.ts +26 -0
  92. package/lib/components/editors/CubeFilterEditor.d.ts.map +1 -0
  93. package/lib/components/editors/CubeFilterEditor.js +90 -0
  94. package/lib/components/editors/CubeFilterEditor.js.map +1 -0
  95. package/lib/components/editors/CubeJoinEditor.d.ts +26 -0
  96. package/lib/components/editors/CubeJoinEditor.d.ts.map +1 -0
  97. package/lib/components/editors/CubeJoinEditor.js +76 -0
  98. package/lib/components/editors/CubeJoinEditor.js.map +1 -0
  99. package/lib/components/editors/CubeNodeEditorPanel.d.ts +29 -0
  100. package/lib/components/editors/CubeNodeEditorPanel.d.ts.map +1 -0
  101. package/lib/components/editors/CubeNodeEditorPanel.js +71 -0
  102. package/lib/components/editors/CubeNodeEditorPanel.js.map +1 -0
  103. package/lib/components/editors/CubeNodeEditorRegistry.d.ts +44 -0
  104. package/lib/components/editors/CubeNodeEditorRegistry.d.ts.map +1 -0
  105. package/lib/components/editors/CubeNodeEditorRegistry.js +30 -0
  106. package/lib/components/editors/CubeNodeEditorRegistry.js.map +1 -0
  107. package/lib/components/editors/CubeSourceEditor.d.ts +25 -0
  108. package/lib/components/editors/CubeSourceEditor.d.ts.map +1 -0
  109. package/lib/components/editors/CubeSourceEditor.js +42 -0
  110. package/lib/components/editors/CubeSourceEditor.js.map +1 -0
  111. package/lib/components/editors/CubeValueEditor.d.ts +40 -0
  112. package/lib/components/editors/CubeValueEditor.d.ts.map +1 -0
  113. package/lib/components/editors/CubeValueEditor.js +177 -0
  114. package/lib/components/editors/CubeValueEditor.js.map +1 -0
  115. package/lib/components/grid/CubeGridRegion.d.ts +23 -0
  116. package/lib/components/grid/CubeGridRegion.d.ts.map +1 -0
  117. package/lib/components/grid/CubeGridRegion.js +94 -0
  118. package/lib/components/grid/CubeGridRegion.js.map +1 -0
  119. package/lib/components/grid/CubeGridValues.d.ts +25 -0
  120. package/lib/components/grid/CubeGridValues.d.ts.map +1 -0
  121. package/lib/components/grid/CubeGridValues.js +95 -0
  122. package/lib/components/grid/CubeGridValues.js.map +1 -0
  123. package/lib/components/grid/CubeResultGrid.d.ts +26 -0
  124. package/lib/components/grid/CubeResultGrid.d.ts.map +1 -0
  125. package/lib/components/grid/CubeResultGrid.js +50 -0
  126. package/lib/components/grid/CubeResultGrid.js.map +1 -0
  127. package/lib/components/palette/CubePalette.d.ts +29 -0
  128. package/lib/components/palette/CubePalette.d.ts.map +1 -0
  129. package/lib/components/palette/CubePalette.js +73 -0
  130. package/lib/components/palette/CubePalette.js.map +1 -0
  131. package/lib/components/show-pure/CubeShowPureDialog.d.ts +23 -0
  132. package/lib/components/show-pure/CubeShowPureDialog.d.ts.map +1 -0
  133. package/lib/components/show-pure/CubeShowPureDialog.js +37 -0
  134. package/lib/components/show-pure/CubeShowPureDialog.js.map +1 -0
  135. package/lib/components/source-picker/CubeSourcePicker.d.ts +22 -0
  136. package/lib/components/source-picker/CubeSourcePicker.d.ts.map +1 -0
  137. package/lib/components/source-picker/CubeSourcePicker.js +89 -0
  138. package/lib/components/source-picker/CubeSourcePicker.js.map +1 -0
  139. package/lib/components/spec-transfer/CubeSpecTransferDialog.d.ts +26 -0
  140. package/lib/components/spec-transfer/CubeSpecTransferDialog.d.ts.map +1 -0
  141. package/lib/components/spec-transfer/CubeSpecTransferDialog.js +45 -0
  142. package/lib/components/spec-transfer/CubeSpecTransferDialog.js.map +1 -0
  143. package/lib/graph-manager/CubeEngine.d.ts +115 -0
  144. package/lib/graph-manager/CubeEngine.d.ts.map +1 -0
  145. package/lib/graph-manager/CubeEngine.js +61 -0
  146. package/lib/graph-manager/CubeEngine.js.map +1 -0
  147. package/lib/graph-manager/CubeModelOutlineHelper.d.ts +25 -0
  148. package/lib/graph-manager/CubeModelOutlineHelper.d.ts.map +1 -0
  149. package/lib/graph-manager/CubeModelOutlineHelper.js +24 -0
  150. package/lib/graph-manager/CubeModelOutlineHelper.js.map +1 -0
  151. package/lib/graph-manager/protocol/pure/CubeEngineBuilder.d.ts +26 -0
  152. package/lib/graph-manager/protocol/pure/CubeEngineBuilder.d.ts.map +1 -0
  153. package/lib/graph-manager/protocol/pure/CubeEngineBuilder.js +22 -0
  154. package/lib/graph-manager/protocol/pure/CubeEngineBuilder.js.map +1 -0
  155. package/lib/graph-manager/protocol/pure/v1/V1_CubeEngineErrors.d.ts +27 -0
  156. package/lib/graph-manager/protocol/pure/v1/V1_CubeEngineErrors.d.ts.map +1 -0
  157. package/lib/graph-manager/protocol/pure/v1/V1_CubeEngineErrors.js +76 -0
  158. package/lib/graph-manager/protocol/pure/v1/V1_CubeEngineErrors.js.map +1 -0
  159. package/lib/graph-manager/protocol/pure/v1/V1_CubeExecutionResultReader.d.ts +27 -0
  160. package/lib/graph-manager/protocol/pure/v1/V1_CubeExecutionResultReader.d.ts.map +1 -0
  161. package/lib/graph-manager/protocol/pure/v1/V1_CubeExecutionResultReader.js +82 -0
  162. package/lib/graph-manager/protocol/pure/v1/V1_CubeExecutionResultReader.js.map +1 -0
  163. package/lib/graph-manager/protocol/pure/v1/V1_CubeLambdaSerializer.d.ts +32 -0
  164. package/lib/graph-manager/protocol/pure/v1/V1_CubeLambdaSerializer.d.ts.map +1 -0
  165. package/lib/graph-manager/protocol/pure/v1/V1_CubeLambdaSerializer.js +195 -0
  166. package/lib/graph-manager/protocol/pure/v1/V1_CubeLambdaSerializer.js.map +1 -0
  167. package/lib/graph-manager/protocol/pure/v1/V1_CubeModelOutlineBuilder.d.ts +20 -0
  168. package/lib/graph-manager/protocol/pure/v1/V1_CubeModelOutlineBuilder.d.ts.map +1 -0
  169. package/lib/graph-manager/protocol/pure/v1/V1_CubeModelOutlineBuilder.js +121 -0
  170. package/lib/graph-manager/protocol/pure/v1/V1_CubeModelOutlineBuilder.js.map +1 -0
  171. package/lib/graph-manager/protocol/pure/v1/V1_CubeRelationTypeAdapter.d.ts +24 -0
  172. package/lib/graph-manager/protocol/pure/v1/V1_CubeRelationTypeAdapter.d.ts.map +1 -0
  173. package/lib/graph-manager/protocol/pure/v1/V1_CubeRelationTypeAdapter.js +43 -0
  174. package/lib/graph-manager/protocol/pure/v1/V1_CubeRelationTypeAdapter.js.map +1 -0
  175. package/lib/graph-manager/protocol/pure/v1/V1_LegendCubeEngine.d.ts +45 -0
  176. package/lib/graph-manager/protocol/pure/v1/V1_LegendCubeEngine.d.ts.map +1 -0
  177. package/lib/graph-manager/protocol/pure/v1/V1_LegendCubeEngine.js +171 -0
  178. package/lib/graph-manager/protocol/pure/v1/V1_LegendCubeEngine.js.map +1 -0
  179. package/lib/graph-manager/protocol/pure/v1/__test-utils__/V1_CubeEngineTestUtils.d.ts +22 -0
  180. package/lib/graph-manager/protocol/pure/v1/__test-utils__/V1_CubeEngineTestUtils.d.ts.map +1 -0
  181. package/lib/graph-manager/protocol/pure/v1/__test-utils__/V1_CubeEngineTestUtils.js +79 -0
  182. package/lib/graph-manager/protocol/pure/v1/__test-utils__/V1_CubeEngineTestUtils.js.map +1 -0
  183. package/lib/index.css +17 -0
  184. package/lib/index.css.map +1 -0
  185. package/lib/index.d.ts +25 -0
  186. package/lib/index.d.ts.map +1 -0
  187. package/lib/index.js +24 -0
  188. package/lib/index.js.map +1 -0
  189. package/lib/stores/CubeEditorState.d.ts +206 -0
  190. package/lib/stores/CubeEditorState.d.ts.map +1 -0
  191. package/lib/stores/CubeEditorState.js +551 -0
  192. package/lib/stores/CubeEditorState.js.map +1 -0
  193. package/lib/stores/CubeExecutionState.d.ts +67 -0
  194. package/lib/stores/CubeExecutionState.d.ts.map +1 -0
  195. package/lib/stores/CubeExecutionState.js +196 -0
  196. package/lib/stores/CubeExecutionState.js.map +1 -0
  197. package/lib/stores/CubeHost.d.ts +31 -0
  198. package/lib/stores/CubeHost.d.ts.map +1 -0
  199. package/lib/stores/CubeHost.js +17 -0
  200. package/lib/stores/CubeHost.js.map +1 -0
  201. package/lib/stores/CubeNodeEditorState.d.ts +85 -0
  202. package/lib/stores/CubeNodeEditorState.d.ts.map +1 -0
  203. package/lib/stores/CubeNodeEditorState.js +207 -0
  204. package/lib/stores/CubeNodeEditorState.js.map +1 -0
  205. package/lib/stores/CubeShowPureState.d.ts +38 -0
  206. package/lib/stores/CubeShowPureState.d.ts.map +1 -0
  207. package/lib/stores/CubeShowPureState.js +83 -0
  208. package/lib/stores/CubeShowPureState.js.map +1 -0
  209. package/lib/stores/CubeSourcePickerState.d.ts +98 -0
  210. package/lib/stores/CubeSourcePickerState.d.ts.map +1 -0
  211. package/lib/stores/CubeSourcePickerState.js +334 -0
  212. package/lib/stores/CubeSourcePickerState.js.map +1 -0
  213. package/lib/stores/CubeSpecTransferState.d.ts +60 -0
  214. package/lib/stores/CubeSpecTransferState.d.ts.map +1 -0
  215. package/lib/stores/CubeSpecTransferState.js +167 -0
  216. package/lib/stores/CubeSpecTransferState.js.map +1 -0
  217. package/lib/stores/LocalModelCatalog.d.ts +37 -0
  218. package/lib/stores/LocalModelCatalog.d.ts.map +1 -0
  219. package/lib/stores/LocalModelCatalog.js +49 -0
  220. package/lib/stores/LocalModelCatalog.js.map +1 -0
  221. package/lib/stores/editors/CubeFilterDraft.d.ts +61 -0
  222. package/lib/stores/editors/CubeFilterDraft.d.ts.map +1 -0
  223. package/lib/stores/editors/CubeFilterDraft.js +186 -0
  224. package/lib/stores/editors/CubeFilterDraft.js.map +1 -0
  225. package/lib/stores/editors/CubeJoinDraft.d.ts +63 -0
  226. package/lib/stores/editors/CubeJoinDraft.d.ts.map +1 -0
  227. package/lib/stores/editors/CubeJoinDraft.js +136 -0
  228. package/lib/stores/editors/CubeJoinDraft.js.map +1 -0
  229. package/lib/stores/editors/CubeNodeDraft.d.ts +38 -0
  230. package/lib/stores/editors/CubeNodeDraft.d.ts.map +1 -0
  231. package/lib/stores/editors/CubeNodeDraft.js +35 -0
  232. package/lib/stores/editors/CubeNodeDraft.js.map +1 -0
  233. package/lib/stores/editors/CubeNodeDraftRegistry.d.ts +29 -0
  234. package/lib/stores/editors/CubeNodeDraftRegistry.d.ts.map +1 -0
  235. package/lib/stores/editors/CubeNodeDraftRegistry.js +33 -0
  236. package/lib/stores/editors/CubeNodeDraftRegistry.js.map +1 -0
  237. package/lib/stores/fixtures/CubeNorthwindModel.d.ts +23 -0
  238. package/lib/stores/fixtures/CubeNorthwindModel.d.ts.map +1 -0
  239. package/lib/stores/fixtures/CubeNorthwindModel.js +338 -0
  240. package/lib/stores/fixtures/CubeNorthwindModel.js.map +1 -0
  241. package/package.json +81 -3
  242. package/src/__lib__/LegendCubeCommand.ts +44 -0
  243. package/src/__lib__/LegendCubeHelpText.ts +38 -0
  244. package/src/__lib__/LegendCubeLabels.ts +141 -0
  245. package/src/__lib__/LegendCubeTesting.ts +33 -0
  246. package/src/__test-utils__/CubeCanvasTestUtils.ts +53 -0
  247. package/src/__test-utils__/CubeEngineTestSupport.ts +137 -0
  248. package/src/__test-utils__/CubeNorthwindTestQueries.ts +165 -0
  249. package/src/__test-utils__/CubePageTestUtils.tsx +96 -0
  250. package/src/__test-utils__/CubeTestApplication.ts +82 -0
  251. package/src/__test-utils__/FakeCubeEngine.ts +139 -0
  252. package/src/components/CubeButton.tsx +35 -0
  253. package/src/components/CubeEditor.tsx +239 -0
  254. package/src/components/CubeNodeIcon.tsx +47 -0
  255. package/src/components/canvas/CubeCanvas.tsx +260 -0
  256. package/src/components/canvas/CubeCanvasContext.ts +31 -0
  257. package/src/components/canvas/CubeCanvasContextMenu.tsx +89 -0
  258. package/src/components/canvas/CubeCanvasDnd.ts +82 -0
  259. package/src/components/canvas/CubeCanvasEdge.tsx +57 -0
  260. package/src/components/canvas/CubeCanvasElements.ts +150 -0
  261. package/src/components/canvas/CubeCanvasLayout.ts +88 -0
  262. package/src/components/canvas/CubeCanvasNode.tsx +141 -0
  263. package/src/components/editors/CubeColumnPicker.tsx +114 -0
  264. package/src/components/editors/CubeFilterEditor.tsx +309 -0
  265. package/src/components/editors/CubeJoinEditor.tsx +224 -0
  266. package/src/components/editors/CubeNodeEditorPanel.tsx +204 -0
  267. package/src/components/editors/CubeNodeEditorRegistry.ts +61 -0
  268. package/src/components/editors/CubeSourceEditor.tsx +116 -0
  269. package/src/components/editors/CubeValueEditor.tsx +332 -0
  270. package/src/components/grid/CubeGridRegion.tsx +274 -0
  271. package/src/components/grid/CubeGridValues.ts +125 -0
  272. package/src/components/grid/CubeResultGrid.tsx +84 -0
  273. package/src/components/palette/CubePalette.tsx +177 -0
  274. package/src/components/show-pure/CubeShowPureDialog.tsx +101 -0
  275. package/src/components/source-picker/CubeSourcePicker.tsx +304 -0
  276. package/src/components/spec-transfer/CubeSpecTransferDialog.tsx +157 -0
  277. package/src/graph-manager/CubeEngine.ts +155 -0
  278. package/src/graph-manager/CubeModelOutlineHelper.ts +32 -0
  279. package/src/graph-manager/protocol/pure/CubeEngineBuilder.ts +34 -0
  280. package/src/graph-manager/protocol/pure/v1/V1_CubeEngineErrors.ts +109 -0
  281. package/src/graph-manager/protocol/pure/v1/V1_CubeExecutionResultReader.ts +115 -0
  282. package/src/graph-manager/protocol/pure/v1/V1_CubeLambdaSerializer.ts +257 -0
  283. package/src/graph-manager/protocol/pure/v1/V1_CubeModelOutlineBuilder.ts +157 -0
  284. package/src/graph-manager/protocol/pure/v1/V1_CubeRelationTypeAdapter.ts +58 -0
  285. package/src/graph-manager/protocol/pure/v1/V1_LegendCubeEngine.ts +278 -0
  286. package/src/graph-manager/protocol/pure/v1/__test-utils__/V1_CubeEngineTestUtils.ts +124 -0
  287. package/src/index.ts +41 -0
  288. package/src/stores/CubeEditorState.ts +702 -0
  289. package/src/stores/CubeExecutionState.ts +255 -0
  290. package/src/stores/CubeHost.ts +32 -0
  291. package/src/stores/CubeNodeEditorState.ts +255 -0
  292. package/src/stores/CubeShowPureState.ts +96 -0
  293. package/src/stores/CubeSourcePickerState.ts +426 -0
  294. package/src/stores/CubeSpecTransferState.ts +198 -0
  295. package/src/stores/LocalModelCatalog.ts +70 -0
  296. package/src/stores/editors/CubeFilterDraft.ts +241 -0
  297. package/src/stores/editors/CubeJoinDraft.ts +197 -0
  298. package/src/stores/editors/CubeNodeDraft.ts +46 -0
  299. package/src/stores/editors/CubeNodeDraftRegistry.ts +49 -0
  300. package/src/stores/fixtures/CubeNorthwindModel.ts +355 -0
  301. package/tsconfig.json +118 -0
@@ -0,0 +1,702 @@
1
+ /**
2
+ * Copyright (c) 2026-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ buildSchemasAndValidity,
19
+ createNodeRegistry,
20
+ CubeDocument,
21
+ diffSchemas,
22
+ type ModelContext,
23
+ type NodeRegistry,
24
+ type Query,
25
+ QueryEmitter,
26
+ type QueryNode,
27
+ RelationalTableSource,
28
+ rereadQueryFilterValues,
29
+ type Schema,
30
+ type SchemaInferenceResult,
31
+ } from '@finos/legend-cube';
32
+ import type { CommandRegistrar } from '@finos/legend-application';
33
+ import type { GeneratorFn } from '@finos/legend-shared';
34
+ import {
35
+ action,
36
+ computed,
37
+ flow,
38
+ flowResult,
39
+ makeObservable,
40
+ observable,
41
+ } from 'mobx';
42
+ import { LEGEND_CUBE_COMMAND_KEY } from '../__lib__/LegendCubeCommand.js';
43
+ import {
44
+ CUBE_EDITOR_CLOSED_REASON,
45
+ DEFAULT_ROW_LIMIT,
46
+ getSchemaDriftWarning,
47
+ getSourceRecheckWarning,
48
+ LEGEND_CUBE_USER_DATA_KEY,
49
+ MAX_UNDO_STEPS,
50
+ } from '../__lib__/LegendCubeLabels.js';
51
+ import {
52
+ CubeEngineError,
53
+ CubeEngineErrorKind,
54
+ type CubeModelOutline,
55
+ } from '../graph-manager/CubeEngine.js';
56
+ import { CubeExecutionState } from './CubeExecutionState.js';
57
+ import type { CubeHost } from './CubeHost.js';
58
+ import { CubeNodeEditorState } from './CubeNodeEditorState.js';
59
+ import { CubeShowPureState } from './CubeShowPureState.js';
60
+ import { CubeSourcePickerState } from './CubeSourcePickerState.js';
61
+ import { CubeSpecTransferState } from './CubeSpecTransferState.js';
62
+
63
+ /** An engine error placed on a node: its first line shows on the node, its detail in the grid */
64
+ export interface CubeHostIssue {
65
+ readonly firstLine: string;
66
+ readonly detail: string;
67
+ }
68
+
69
+ const isValidRowLimit = (value: number | undefined): value is number =>
70
+ value !== undefined && Number.isSafeInteger(value) && value >= 1;
71
+
72
+ /** Focus is where text is typed, so Ctrl+Z is the field's own undo */
73
+ const isTypingText = (): boolean => {
74
+ const element = document.activeElement;
75
+ return (
76
+ element instanceof HTMLInputElement ||
77
+ element instanceof HTMLTextAreaElement ||
78
+ (element instanceof HTMLElement && element.isContentEditable)
79
+ );
80
+ };
81
+
82
+ /**
83
+ * The state of one Cube page (PLAN §7.8). The document is immutable: every
84
+ * edit makes a new one through `applyDocument`, which keeps the previous one
85
+ * for undo. Domain and port values are held by reference, never observed
86
+ * deeply.
87
+ */
88
+ export class CubeEditorState implements CommandRegistrar {
89
+ readonly host: CubeHost;
90
+ /** One registry for inference, emission and the saved spec */
91
+ readonly registry: NodeRegistry;
92
+ readonly execution: CubeExecutionState;
93
+ readonly sourcePicker: CubeSourcePickerState;
94
+ readonly specTransfer: CubeSpecTransferState;
95
+ readonly showPure: CubeShowPureState;
96
+ readonly nodeEditor: CubeNodeEditorState;
97
+
98
+ document: CubeDocument;
99
+ /** Earlier documents, oldest first */
100
+ history: readonly CubeDocument[] = [];
101
+ /** Engine errors by node id: shown with the node's own errors, never part of inference */
102
+ hostIssues: ReadonlyMap<string, CubeHostIssue> = new Map();
103
+ /**
104
+ * Warnings by node key, e.g. a table that changed since the cube was saved:
105
+ * shown on the node, never errors, and gone once the node is replaced
106
+ */
107
+ warnings: ReadonlyMap<number, readonly string[]> = new Map();
108
+ /**
109
+ * The outline of each model the cube used, loaded when an editor needs it,
110
+ * e.g. for the Join's 'type unknown' warning; by reference, never observed
111
+ * deeply
112
+ */
113
+ private modelOutlines: ReadonlyMap<ModelContext, CubeModelOutline> =
114
+ new Map();
115
+ /** Sources sent to the engine to be typed again, until it answers */
116
+ private pendingSources: ReadonlySet<QueryNode> = new Set();
117
+ /** The rows a run returns; kept per user, never in the cube */
118
+ rowLimit: number;
119
+ /** The palette shows icons only; kept per user, never in the cube */
120
+ isPaletteCollapsed: boolean;
121
+ /**
122
+ * The cube was saved by a newer version of Cube: it can be viewed and run,
123
+ * but not changed, undone or exported (Settled before M1.8)
124
+ */
125
+ readOnly = false;
126
+ /** Documents in the undo history that were read-only, so undo restores the flag */
127
+ private readonly readOnlyDocuments = new WeakSet<CubeDocument>();
128
+ /** Documents an import replaced: undoing back to one opens another cube again */
129
+ private readonly importedOver = new WeakSet<CubeDocument>();
130
+
131
+ constructor(host: CubeHost, document = new CubeDocument()) {
132
+ makeObservable<CubeEditorState, 'pendingSources' | 'modelOutlines'>(this, {
133
+ pendingSources: observable.ref,
134
+ modelOutlines: observable.ref,
135
+ modelOutline: computed,
136
+ loadModelOutline: flow,
137
+ document: observable.ref,
138
+ history: observable.ref,
139
+ hostIssues: observable.ref,
140
+ warnings: observable.ref,
141
+ isResolvingSources: computed,
142
+ rowLimit: observable,
143
+ isPaletteCollapsed: observable,
144
+ readOnly: observable,
145
+ analysis: computed,
146
+ emitter: computed,
147
+ canUndo: computed,
148
+ isDialogOpen: computed,
149
+ applyDocument: action,
150
+ undo: action,
151
+ importDocument: action,
152
+ reresolveSources: flow,
153
+ refreshSource: flow,
154
+ applyQuery: action,
155
+ select: action,
156
+ connect: action,
157
+ addNode: action,
158
+ dropNode: action,
159
+ removeNode: action,
160
+ swapInputs: action,
161
+ setShowGraph: action,
162
+ setPaletteCollapsed: action,
163
+ setHostIssue: action,
164
+ clearHostIssues: action,
165
+ setRowLimit: action,
166
+ });
167
+ this.host = host;
168
+ this.registry = createNodeRegistry();
169
+ this.document = document;
170
+ const storedLimit = host.applicationStore.userDataService.getNumericValue(
171
+ LEGEND_CUBE_USER_DATA_KEY.ROW_LIMIT,
172
+ );
173
+ this.rowLimit = isValidRowLimit(storedLimit)
174
+ ? storedLimit
175
+ : DEFAULT_ROW_LIMIT;
176
+ this.isPaletteCollapsed =
177
+ host.applicationStore.userDataService.getBooleanValue(
178
+ LEGEND_CUBE_USER_DATA_KEY.PALETTE_COLLAPSED,
179
+ ) ?? false;
180
+ this.execution = new CubeExecutionState(this);
181
+ this.sourcePicker = new CubeSourcePickerState(this);
182
+ this.specTransfer = new CubeSpecTransferState(this);
183
+ this.showPure = new CubeShowPureState(this);
184
+ this.nodeEditor = new CubeNodeEditorState(this);
185
+ }
186
+
187
+ /** Each node's schema and errors, query-level rules included, as the emitter sees them */
188
+ get analysis(): SchemaInferenceResult {
189
+ return buildSchemasAndValidity(
190
+ this.document.query,
191
+ this.registry.queryRules,
192
+ );
193
+ }
194
+
195
+ get emitter(): QueryEmitter {
196
+ return new QueryEmitter(this.document.query, this.registry);
197
+ }
198
+
199
+ /** The cube shown has tables being typed again, after an import */
200
+ get isResolvingSources(): boolean {
201
+ return this.document.query.nodes.some((node) =>
202
+ this.pendingSources.has(node),
203
+ );
204
+ }
205
+
206
+ /** The source is being typed again by the engine, e.g. after an import */
207
+ isPendingSource(node: QueryNode): boolean {
208
+ return this.pendingSources.has(node);
209
+ }
210
+
211
+ /**
212
+ * The node's errors, each once: its own and those of the query rules, then
213
+ * the first line of the engine's error on it
214
+ */
215
+ getNodeErrors(nodeId: string): readonly string[] {
216
+ const hostIssue = this.hostIssues.get(nodeId);
217
+ return [
218
+ ...new Set([
219
+ ...(this.analysis.validity.get(nodeId) ?? []),
220
+ ...(hostIssue ? [hostIssue.firstLine] : []),
221
+ ]),
222
+ ];
223
+ }
224
+
225
+ /** The outline of the cube's model, once an editor has loaded it */
226
+ get modelOutline(): CubeModelOutline | undefined {
227
+ const model = this.document.context?.model;
228
+ return model === undefined ? undefined : this.modelOutlines.get(model);
229
+ }
230
+
231
+ /**
232
+ * Loads the outline of the cube's model, once per model. It only adds
233
+ * warnings, so a model that fails to load shows none.
234
+ */
235
+ *loadModelOutline(): GeneratorFn<void> {
236
+ const model = this.document.context?.model;
237
+ if (model === undefined || this.modelOutlines.has(model)) {
238
+ return;
239
+ }
240
+ try {
241
+ const outline = (yield this.host.modelCatalog.loadOutline(
242
+ model,
243
+ )) as CubeModelOutline;
244
+ this.modelOutlines = new Map([...this.modelOutlines, [model, outline]]);
245
+ } catch {
246
+ // no outline, no warning: nothing is blocked on it
247
+ }
248
+ }
249
+
250
+ /** One of Cube's dialogs is open: the source picker, Import or Export, Show Pure */
251
+ get isDialogOpen(): boolean {
252
+ return (
253
+ this.sourcePicker.isOpen ||
254
+ this.specTransfer.mode !== undefined ||
255
+ this.showPure.isOpen
256
+ );
257
+ }
258
+
259
+ /**
260
+ * The page's keyboard shortcuts, while it is open (spec §17.12). Each does
261
+ * nothing when its button can't be used, and nothing while a Cube dialog
262
+ * is open, since a dialog doesn't stop the app's shortcuts (user's choice,
263
+ * 2026-10-07). Undo leaves Ctrl+Z to a text field that has the focus.
264
+ */
265
+ registerCommands(): void {
266
+ const { commandService, alertUnhandledError } = this.host.applicationStore;
267
+ commandService.registerCommand({
268
+ key: LEGEND_CUBE_COMMAND_KEY.EXECUTE,
269
+ trigger: () =>
270
+ !this.isDialogOpen &&
271
+ this.execution.canExecute &&
272
+ !this.execution.isRunning,
273
+ action: () => {
274
+ flowResult(this.execution.execute()).catch(alertUnhandledError);
275
+ },
276
+ });
277
+ commandService.registerCommand({
278
+ key: LEGEND_CUBE_COMMAND_KEY.UNDO,
279
+ trigger: () => !this.isDialogOpen && this.canUndo && !isTypingText(),
280
+ action: () => this.undo(),
281
+ });
282
+ }
283
+
284
+ deregisterCommands(): void {
285
+ Object.values(LEGEND_CUBE_COMMAND_KEY).forEach((key) =>
286
+ this.host.applicationStore.commandService.deregisterCommand(key),
287
+ );
288
+ }
289
+
290
+ get canUndo(): boolean {
291
+ return this.history.length > 0 && !this.readOnly;
292
+ }
293
+
294
+ /** The one way to change the cube; the document before goes to the undo history */
295
+ applyDocument(next: CubeDocument): void {
296
+ if (next === this.document) {
297
+ return;
298
+ }
299
+ this.pushHistory();
300
+ this.replaceDocument(next);
301
+ }
302
+
303
+ /**
304
+ * Opens another cube in place of this one, e.g. an imported spec: one undo
305
+ * step. Stops any run and any table being added, closes the node editor
306
+ * without applying its edits, and drops the last run's rows and errors,
307
+ * which belong to the cube before. Never runs the cube.
308
+ */
309
+ importDocument(next: CubeDocument, readOnly: boolean): void {
310
+ this.pushHistory();
311
+ this.importedOver.add(this.document);
312
+ this.execution.reset();
313
+ this.sourcePicker.close();
314
+ this.nodeEditor.discard(CUBE_EDITOR_CLOSED_REASON.CUBE_REPLACED);
315
+ this.hostIssues = new Map();
316
+ // warnings are kept: they are by node key, which the imported nodes don't
317
+ // share, and Undo brings back the nodes they belong to
318
+ this.document = next;
319
+ this.readOnly = readOnly;
320
+ flowResult(this.reresolveSources()).catch(
321
+ this.host.applicationStore.alertUnhandledError,
322
+ );
323
+ }
324
+
325
+ /**
326
+ * Types the cube's tables again, in one engine call, outside the undo
327
+ * history (PLAN §10.3, Settled before M1.8):
328
+ * - a table whose columns are the saved ones is left as it is;
329
+ * - a table that changed takes its new columns, with a warning listing the
330
+ * changes;
331
+ * - a table with saved columns that can't be typed keeps them, with a
332
+ * warning; one without them shows the engine's error.
333
+ *
334
+ * Then filter values saved as invalid text are read again against the
335
+ * columns. The answer goes to every document holding the very source
336
+ * objects that were typed: the cube shown and the undo snapshots taken
337
+ * meanwhile, so undoing an edit made while the tables were typed keeps
338
+ * them typed. A source the user changed meanwhile is a new object, and is
339
+ * left alone.
340
+ *
341
+ * `only` types just these sources of the cube shown, e.g. one Refresh. A
342
+ * table found unchanged loses any earlier warning.
343
+ */
344
+ *reresolveSources(
345
+ only?: readonly RelationalTableSource[],
346
+ ): GeneratorFn<void> {
347
+ const { context, query } = this.document;
348
+ const sources = (only ?? query.nodes).filter(
349
+ (node): node is RelationalTableSource =>
350
+ node instanceof RelationalTableSource &&
351
+ query.getNode(node.id) === node,
352
+ );
353
+ if (!context || !sources.length) {
354
+ return;
355
+ }
356
+ this.pendingSources = new Set([...this.pendingSources, ...sources]);
357
+ let answers: ReadonlyMap<string, Schema | CubeEngineError>;
358
+ try {
359
+ answers = (yield this.host.engine.resolveSchemas(
360
+ context.model,
361
+ new Map(
362
+ sources.map((source) => [
363
+ source.id,
364
+ [source.database, source.schema, source.table],
365
+ ]),
366
+ ),
367
+ )) as Map<string, Schema | CubeEngineError>;
368
+ } catch (error) {
369
+ const failure =
370
+ error instanceof CubeEngineError
371
+ ? error
372
+ : new CubeEngineError(
373
+ CubeEngineErrorKind.NETWORK,
374
+ error instanceof Error ? error.message : String(error),
375
+ );
376
+ answers = new Map(sources.map((source) => [source.id, failure]));
377
+ } finally {
378
+ this.pendingSources = new Set(
379
+ [...this.pendingSources].filter(
380
+ (node) => !sources.includes(node as RelationalTableSource),
381
+ ),
382
+ );
383
+ }
384
+ const warnings = new Map(this.warnings);
385
+ /** Each typed source, by the object that was sent, and what replaces it */
386
+ const replacements = new Map<
387
+ RelationalTableSource,
388
+ RelationalTableSource
389
+ >();
390
+ sources.forEach((source) => {
391
+ const answer =
392
+ answers.get(source.id) ??
393
+ new CubeEngineError(
394
+ CubeEngineErrorKind.COMPILE,
395
+ 'The engine gave no schema for this table',
396
+ source.id,
397
+ );
398
+ const saved =
399
+ source.resolution.kind === 'resolved'
400
+ ? source.resolution.schema
401
+ : undefined;
402
+ if (answer instanceof CubeEngineError) {
403
+ if (saved) {
404
+ warnings.set(source.key, [getSourceRecheckWarning(answer.firstLine)]);
405
+ } else if (
406
+ source.resolution.kind !== 'failed' ||
407
+ source.resolution.message !== answer.detail
408
+ ) {
409
+ // a table that fails as it did before is left as it is
410
+ replacements.set(
411
+ source,
412
+ source.withResolution({ kind: 'failed', message: answer.detail }),
413
+ );
414
+ }
415
+ return;
416
+ }
417
+ if (saved?.isIdenticalTo(answer)) {
418
+ warnings.delete(source.key);
419
+ return;
420
+ }
421
+ const resolved = source.withResolution({
422
+ kind: 'resolved',
423
+ schema: answer,
424
+ });
425
+ if (saved) {
426
+ warnings.set(resolved.key, [
427
+ getSchemaDriftWarning(diffSchemas(saved, answer)),
428
+ ]);
429
+ }
430
+ replacements.set(source, resolved);
431
+ });
432
+ this.warnings = warnings;
433
+ if (!replacements.size) {
434
+ return;
435
+ }
436
+ // documents that shared a query share its checked one, so an undo
437
+ // between them still finds the query unchanged
438
+ const checkedQueries = new Map<Query, Query>();
439
+ const check = (document: CubeDocument): CubeDocument => {
440
+ let checked = checkedQueries.get(document.query);
441
+ if (checked === undefined) {
442
+ let replaced = document.query;
443
+ replacements.forEach((resolved, source) => {
444
+ if (replaced.getNode(source.id) === source) {
445
+ replaced = replaced.replace(resolved);
446
+ }
447
+ });
448
+ checked =
449
+ replaced === document.query
450
+ ? replaced
451
+ : rereadQueryFilterValues(replaced, this.registry.queryRules);
452
+ checkedQueries.set(document.query, checked);
453
+ }
454
+ if (checked === document.query) {
455
+ return document;
456
+ }
457
+ const next = document.withQuery(checked);
458
+ if (this.readOnlyDocuments.has(document)) {
459
+ this.readOnlyDocuments.add(next);
460
+ }
461
+ if (this.importedOver.has(document)) {
462
+ this.importedOver.add(next);
463
+ }
464
+ return next;
465
+ };
466
+ this.history = this.history.map(check);
467
+ const next = check(this.document);
468
+ if (next !== this.document) {
469
+ this.replaceDocument(next);
470
+ }
471
+ }
472
+
473
+ /**
474
+ * Types a table again with the engine, from its Source panel (spec §17.6),
475
+ * as a re-check after an import does: no undo step, nothing changes when
476
+ * its columns are the same, and a warning lists any change.
477
+ */
478
+ *refreshSource(nodeId: string): GeneratorFn<void> {
479
+ const source = this.document.query.getNode(nodeId);
480
+ if (source instanceof RelationalTableSource) {
481
+ yield flowResult(this.reresolveSources([source]));
482
+ }
483
+ }
484
+
485
+ /**
486
+ * Restores the document before the last edit; does nothing when there is
487
+ * no history. A restored query is a new object (PLAN §4.3), so rows that
488
+ * ran before the edit show as stale. An edit that left the query alone,
489
+ * such as a rename, keeps it, with its rows and engine errors. Undoing an
490
+ * import closes the node editor and the picker, as the import did.
491
+ */
492
+ undo(): void {
493
+ const previous = this.history.at(-1);
494
+ if (!previous || !this.canUndo) {
495
+ return;
496
+ }
497
+ this.history = this.history.slice(0, -1);
498
+ this.readOnly = this.readOnlyDocuments.has(previous);
499
+ if (this.importedOver.has(previous)) {
500
+ // the cube before an import is another cube, as the import was
501
+ this.sourcePicker.close();
502
+ this.nodeEditor.discard(CUBE_EDITOR_CLOSED_REASON.CUBE_REPLACED);
503
+ }
504
+ const { query } = this.document;
505
+ this.replaceDocument(
506
+ previous.withQuery(
507
+ previous.query === query ? query : previous.query.clone(),
508
+ ),
509
+ );
510
+ }
511
+
512
+ private pushHistory(): void {
513
+ if (this.readOnly) {
514
+ this.readOnlyDocuments.add(this.document);
515
+ }
516
+ this.history = [...this.history, this.document].slice(-MAX_UNDO_STEPS);
517
+ }
518
+
519
+ /** Engine errors belong to the query they came from, so they are dropped when the query changes */
520
+ private replaceDocument(next: CubeDocument): void {
521
+ if (next.query !== this.document.query) {
522
+ this.hostIssues = new Map();
523
+ this.execution.clearError();
524
+ }
525
+ this.document = next;
526
+ }
527
+
528
+ applyQuery(next: Query): void {
529
+ this.applyDocument(this.document.withQuery(next));
530
+ }
531
+
532
+ /** Makes a node the capture node, the one Execute runs */
533
+ select(nodeId: string): void {
534
+ if (this.document.query.canSelect(nodeId)) {
535
+ this.applyQuery(this.document.query.select(nodeId));
536
+ }
537
+ }
538
+
539
+ /**
540
+ * Feeds a node into another, on the port if given, else the first free one.
541
+ * Does nothing when the query doesn't allow it or the cube is read-only.
542
+ */
543
+ connect(sourceId: string, targetId: string, port?: string): void {
544
+ const { query } = this.document;
545
+ if (!this.readOnly && query.canConnect(sourceId, targetId, port)) {
546
+ this.applyQuery(query.connect(sourceId, targetId, port));
547
+ }
548
+ }
549
+
550
+ /**
551
+ * Whether a node of the type can be added: a transform, unconnected or
552
+ * spliced in after `afterId`, when the query allows it; a source only
553
+ * unconnected, through the source picker. Never while the cube is read-only.
554
+ */
555
+ canAddNode(type: string, afterId?: string): boolean {
556
+ const definition = this.registry.get(type);
557
+ if (this.readOnly || !definition) {
558
+ return false;
559
+ }
560
+ if (definition.kind === 'source') {
561
+ return afterId === undefined;
562
+ }
563
+ const { query } = this.document;
564
+ return query.canAdd(definition.create(query.generateId(type)), afterId);
565
+ }
566
+
567
+ /**
568
+ * Adds a node of the type, as the palette and the context menu do (spec
569
+ * §17.4): a transform with its default settings, unconnected or spliced in
570
+ * after `afterId`; a source opens the source picker, which adds it once
571
+ * the engine has typed it. Does nothing `canAddNode` refuses.
572
+ */
573
+ addNode(type: string, afterId?: string): void {
574
+ const definition = this.registry.get(type);
575
+ if (!definition || !this.canAddNode(type, afterId)) {
576
+ return;
577
+ }
578
+ if (definition.kind === 'source') {
579
+ this.sourcePicker.open();
580
+ return;
581
+ }
582
+ const { query } = this.document;
583
+ this.applyQuery(
584
+ query.add(definition.create(query.generateId(type)), afterId),
585
+ );
586
+ }
587
+
588
+ /** Whether dropping a node on another does anything: connect it, or else move it after it */
589
+ canDropNode(nodeId: string, targetId: string): boolean {
590
+ const { query } = this.document;
591
+ return (
592
+ !this.readOnly &&
593
+ (query.canConnect(nodeId, targetId) || query.canMove(nodeId, targetId))
594
+ );
595
+ }
596
+
597
+ /**
598
+ * Drops a node on another (spec §17.4): it feeds the target's first free
599
+ * port if it can, else it moves to after the target
600
+ */
601
+ dropNode(nodeId: string, targetId: string): void {
602
+ if (!this.canDropNode(nodeId, targetId)) {
603
+ return;
604
+ }
605
+ const { query } = this.document;
606
+ this.applyQuery(
607
+ query.canConnect(nodeId, targetId)
608
+ ? query.connect(nodeId, targetId)
609
+ : query.move(nodeId, targetId),
610
+ );
611
+ }
612
+
613
+ canRemoveNode(nodeId: string): boolean {
614
+ return !this.readOnly && this.document.query.canRemove(nodeId);
615
+ }
616
+
617
+ /**
618
+ * Removes a node, healing the chain around it. Removing the last node also
619
+ * clears the cube's model and runtime, in the same undo step, so the next
620
+ * table can come from any model (user's choice, 2026-10-07).
621
+ */
622
+ removeNode(nodeId: string): void {
623
+ if (!this.canRemoveNode(nodeId)) {
624
+ return;
625
+ }
626
+ // the node editor, if it shows the node, closes by itself
627
+ const query = this.document.query.remove(nodeId);
628
+ this.applyDocument(
629
+ query.isEmpty
630
+ ? this.document.withContext(undefined).withQuery(query)
631
+ : this.document.withQuery(query),
632
+ );
633
+ }
634
+
635
+ canSwapInputs(nodeId: string): boolean {
636
+ return !this.readOnly && this.document.query.canSwapInputs(nodeId);
637
+ }
638
+
639
+ /** Swaps a binary node's two inputs; its settings follow them, e.g. a Join's key columns */
640
+ swapInputs(nodeId: string): void {
641
+ if (this.canSwapInputs(nodeId)) {
642
+ this.applyQuery(this.document.query.swapInputs(nodeId));
643
+ }
644
+ }
645
+
646
+ /**
647
+ * Shows or hides the graph, which the cube saves (spec §17.1). An undoable
648
+ * edit that leaves the query, and so the rows, as they are (M1.8b).
649
+ */
650
+ setShowGraph(showGraph: boolean): void {
651
+ const { meta } = this.document;
652
+ if (meta.presentation.showGraph !== showGraph) {
653
+ this.applyDocument(
654
+ this.document.withMeta({
655
+ ...meta,
656
+ presentation: { ...meta.presentation, showGraph },
657
+ }),
658
+ );
659
+ }
660
+ }
661
+
662
+ setHostIssue(nodeId: string, error: CubeEngineError): void {
663
+ this.hostIssues = new Map([
664
+ ...this.hostIssues,
665
+ [nodeId, { firstLine: error.firstLine, detail: error.detail }],
666
+ ]);
667
+ }
668
+
669
+ clearHostIssues(): void {
670
+ if (this.hostIssues.size) {
671
+ this.hostIssues = new Map();
672
+ }
673
+ }
674
+
675
+ /** Sets and remembers the row limit; a value that isn't a whole number of at least 1 is refused */
676
+ setRowLimit(value: number): boolean {
677
+ if (!isValidRowLimit(value)) {
678
+ return false;
679
+ }
680
+ this.rowLimit = value;
681
+ this.host.applicationStore.userDataService.persistValue(
682
+ LEGEND_CUBE_USER_DATA_KEY.ROW_LIMIT,
683
+ value,
684
+ );
685
+ return true;
686
+ }
687
+
688
+ /** Collapses or expands the palette, and remembers it for the user */
689
+ setPaletteCollapsed(collapsed: boolean): void {
690
+ this.isPaletteCollapsed = collapsed;
691
+ this.host.applicationStore.userDataService.persistValue(
692
+ LEGEND_CUBE_USER_DATA_KEY.PALETTE_COLLAPSED,
693
+ collapsed,
694
+ );
695
+ }
696
+
697
+ /** Stops any run; call when the page closes */
698
+ dispose(): void {
699
+ this.execution.stop();
700
+ this.nodeEditor.dispose();
701
+ }
702
+ }