@finos/legend-cube-builder 0.0.5 → 0.0.6

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 (245) hide show
  1. package/docs/adding-an-operation.md +4 -2
  2. package/docs/demo/README.md +1 -1
  3. package/docs/hosting.md +40 -9
  4. package/lib/__lib__/LegendCubeHelpText.d.ts.map +1 -1
  5. package/lib/__lib__/LegendCubeHelpText.js +3 -1
  6. package/lib/__lib__/LegendCubeHelpText.js.map +1 -1
  7. package/lib/__lib__/LegendCubeLabels.d.ts +34 -5
  8. package/lib/__lib__/LegendCubeLabels.d.ts.map +1 -1
  9. package/lib/__lib__/LegendCubeLabels.js +45 -8
  10. package/lib/__lib__/LegendCubeLabels.js.map +1 -1
  11. package/lib/__lib__/LegendCubeNavigation.d.ts +23 -0
  12. package/lib/__lib__/LegendCubeNavigation.d.ts.map +1 -0
  13. package/lib/__lib__/LegendCubeNavigation.js +33 -0
  14. package/lib/__lib__/LegendCubeNavigation.js.map +1 -0
  15. package/lib/__lib__/LegendCubeTesting.d.ts +3 -1
  16. package/lib/__lib__/LegendCubeTesting.d.ts.map +1 -1
  17. package/lib/__lib__/LegendCubeTesting.js +2 -0
  18. package/lib/__lib__/LegendCubeTesting.js.map +1 -1
  19. package/lib/__lib__/LegendCubeTour.d.ts +62 -0
  20. package/lib/__lib__/LegendCubeTour.d.ts.map +1 -0
  21. package/lib/__lib__/LegendCubeTour.js +149 -0
  22. package/lib/__lib__/LegendCubeTour.js.map +1 -0
  23. package/lib/__test-utils__/CubeExampleTestUtils.d.ts +34 -0
  24. package/lib/__test-utils__/CubeExampleTestUtils.d.ts.map +1 -0
  25. package/lib/__test-utils__/CubeExampleTestUtils.js +72 -0
  26. package/lib/__test-utils__/CubeExampleTestUtils.js.map +1 -0
  27. package/lib/__test-utils__/CubeVariantTestUtils.d.ts +16 -0
  28. package/lib/__test-utils__/CubeVariantTestUtils.d.ts.map +1 -0
  29. package/lib/__test-utils__/CubeVariantTestUtils.js +66 -0
  30. package/lib/__test-utils__/CubeVariantTestUtils.js.map +1 -0
  31. package/lib/components/CubeAddItems.d.ts.map +1 -1
  32. package/lib/components/CubeAddItems.js +2 -1
  33. package/lib/components/CubeAddItems.js.map +1 -1
  34. package/lib/components/CubeEditor.d.ts.map +1 -1
  35. package/lib/components/CubeEditor.js +11 -5
  36. package/lib/components/CubeEditor.js.map +1 -1
  37. package/lib/components/CubeFileMenu.d.ts.map +1 -1
  38. package/lib/components/CubeFileMenu.js +2 -1
  39. package/lib/components/CubeFileMenu.js.map +1 -1
  40. package/lib/components/CubeNodeIcon.d.ts.map +1 -1
  41. package/lib/components/CubeNodeIcon.js +2 -1
  42. package/lib/components/CubeNodeIcon.js.map +1 -1
  43. package/lib/components/canvas/CubeCanvas.d.ts.map +1 -1
  44. package/lib/components/canvas/CubeCanvas.js +3 -2
  45. package/lib/components/canvas/CubeCanvas.js.map +1 -1
  46. package/lib/components/canvas/CubeCanvasNode.d.ts.map +1 -1
  47. package/lib/components/canvas/CubeCanvasNode.js +4 -1
  48. package/lib/components/canvas/CubeCanvasNode.js.map +1 -1
  49. package/lib/components/dev-settings/CubeDevSettings.d.ts +2 -2
  50. package/lib/components/dev-settings/CubeDevSettings.d.ts.map +1 -1
  51. package/lib/components/dev-settings/CubeDevSettings.js +12 -8
  52. package/lib/components/dev-settings/CubeDevSettings.js.map +1 -1
  53. package/lib/components/editors/CubeColumnPicker.d.ts.map +1 -1
  54. package/lib/components/editors/CubeColumnPicker.js +3 -1
  55. package/lib/components/editors/CubeColumnPicker.js.map +1 -1
  56. package/lib/components/editors/CubeExplodeEditor.d.ts +26 -0
  57. package/lib/components/editors/CubeExplodeEditor.d.ts.map +1 -0
  58. package/lib/components/editors/CubeExplodeEditor.js +61 -0
  59. package/lib/components/editors/CubeExplodeEditor.js.map +1 -0
  60. package/lib/components/editors/CubeExpressionFilterEditor.d.ts.map +1 -1
  61. package/lib/components/editors/CubeExpressionFilterEditor.js +8 -5
  62. package/lib/components/editors/CubeExpressionFilterEditor.js.map +1 -1
  63. package/lib/components/editors/CubeExtendEditor.d.ts +0 -2
  64. package/lib/components/editors/CubeExtendEditor.d.ts.map +1 -1
  65. package/lib/components/editors/CubeExtendEditor.js +12 -11
  66. package/lib/components/editors/CubeExtendEditor.js.map +1 -1
  67. package/lib/components/editors/CubeJsonFieldsTree.d.ts +46 -0
  68. package/lib/components/editors/CubeJsonFieldsTree.d.ts.map +1 -0
  69. package/lib/components/editors/CubeJsonFieldsTree.js +93 -0
  70. package/lib/components/editors/CubeJsonFieldsTree.js.map +1 -0
  71. package/lib/components/editors/CubeNodeEditorRegistry.d.ts.map +1 -1
  72. package/lib/components/editors/CubeNodeEditorRegistry.js +3 -1
  73. package/lib/components/editors/CubeNodeEditorRegistry.js.map +1 -1
  74. package/lib/components/grid/CubeGridRegion.d.ts.map +1 -1
  75. package/lib/components/grid/CubeGridRegion.js +5 -4
  76. package/lib/components/grid/CubeGridRegion.js.map +1 -1
  77. package/lib/components/grid/CubeGridValues.d.ts +5 -3
  78. package/lib/components/grid/CubeGridValues.d.ts.map +1 -1
  79. package/lib/components/grid/CubeGridValues.js +8 -3
  80. package/lib/components/grid/CubeGridValues.js.map +1 -1
  81. package/lib/components/grid/CubeJsonExplorerDialog.d.ts +27 -0
  82. package/lib/components/grid/CubeJsonExplorerDialog.d.ts.map +1 -0
  83. package/lib/components/grid/CubeJsonExplorerDialog.js +102 -0
  84. package/lib/components/grid/CubeJsonExplorerDialog.js.map +1 -0
  85. package/lib/components/grid/CubeJsonViewerDialog.d.ts +27 -0
  86. package/lib/components/grid/CubeJsonViewerDialog.d.ts.map +1 -0
  87. package/lib/components/grid/CubeJsonViewerDialog.js +68 -0
  88. package/lib/components/grid/CubeJsonViewerDialog.js.map +1 -0
  89. package/lib/components/grid/CubeResultGrid.d.ts +15 -3
  90. package/lib/components/grid/CubeResultGrid.d.ts.map +1 -1
  91. package/lib/components/grid/CubeResultGrid.js +95 -3
  92. package/lib/components/grid/CubeResultGrid.js.map +1 -1
  93. package/lib/components/grid/CubeServerSideGrid.d.ts.map +1 -1
  94. package/lib/components/grid/CubeServerSideGrid.js +4 -2
  95. package/lib/components/grid/CubeServerSideGrid.js.map +1 -1
  96. package/lib/components/palette/CubePalette.d.ts.map +1 -1
  97. package/lib/components/palette/CubePalette.js +4 -1
  98. package/lib/components/palette/CubePalette.js.map +1 -1
  99. package/lib/components/source-picker/CubeIngestTab.d.ts +2 -2
  100. package/lib/components/source-picker/CubeIngestTab.d.ts.map +1 -1
  101. package/lib/components/source-picker/CubeIngestTab.js +19 -13
  102. package/lib/components/source-picker/CubeIngestTab.js.map +1 -1
  103. package/lib/components/tour/CubeTour.d.ts +36 -0
  104. package/lib/components/tour/CubeTour.d.ts.map +1 -0
  105. package/lib/components/tour/CubeTour.js +183 -0
  106. package/lib/components/tour/CubeTour.js.map +1 -0
  107. package/lib/index.css +1 -1
  108. package/lib/index.d.ts +1 -0
  109. package/lib/index.d.ts.map +1 -1
  110. package/lib/index.js +1 -0
  111. package/lib/index.js.map +1 -1
  112. package/lib/stores/CubeEditorState.d.ts +17 -1
  113. package/lib/stores/CubeEditorState.d.ts.map +1 -1
  114. package/lib/stores/CubeEditorState.js +35 -5
  115. package/lib/stores/CubeEditorState.js.map +1 -1
  116. package/lib/stores/CubeExamples.d.ts.map +1 -1
  117. package/lib/stores/CubeExamples.js +101 -4
  118. package/lib/stores/CubeExamples.js.map +1 -1
  119. package/lib/stores/CubeExamplesState.d.ts.map +1 -1
  120. package/lib/stores/CubeExamplesState.js +4 -1
  121. package/lib/stores/CubeExamplesState.js.map +1 -1
  122. package/lib/stores/CubeGridQuickActions.d.ts +7 -0
  123. package/lib/stores/CubeGridQuickActions.d.ts.map +1 -1
  124. package/lib/stores/CubeGridQuickActions.js +20 -11
  125. package/lib/stores/CubeGridQuickActions.js.map +1 -1
  126. package/lib/stores/CubePureText.d.ts +20 -0
  127. package/lib/stores/CubePureText.d.ts.map +1 -0
  128. package/lib/stores/CubePureText.js +24 -0
  129. package/lib/stores/CubePureText.js.map +1 -0
  130. package/lib/stores/CubeTourState.d.ts +49 -0
  131. package/lib/stores/CubeTourState.d.ts.map +1 -0
  132. package/lib/stores/CubeTourState.js +92 -0
  133. package/lib/stores/CubeTourState.js.map +1 -0
  134. package/lib/stores/LegendCubeHost.d.ts +88 -0
  135. package/lib/stores/LegendCubeHost.d.ts.map +1 -0
  136. package/lib/stores/LegendCubeHost.js +149 -0
  137. package/lib/stores/LegendCubeHost.js.map +1 -0
  138. package/lib/stores/editors/CubeExplodeDraft.d.ts +87 -0
  139. package/lib/stores/editors/CubeExplodeDraft.d.ts.map +1 -0
  140. package/lib/stores/editors/CubeExplodeDraft.js +221 -0
  141. package/lib/stores/editors/CubeExplodeDraft.js.map +1 -0
  142. package/lib/stores/editors/CubeExpressionFilterDraft.d.ts +3 -0
  143. package/lib/stores/editors/CubeExpressionFilterDraft.d.ts.map +1 -1
  144. package/lib/stores/editors/CubeExpressionFilterDraft.js +4 -0
  145. package/lib/stores/editors/CubeExpressionFilterDraft.js.map +1 -1
  146. package/lib/stores/editors/CubeExtendDraft.d.ts +9 -0
  147. package/lib/stores/editors/CubeExtendDraft.d.ts.map +1 -1
  148. package/lib/stores/editors/CubeExtendDraft.js +26 -0
  149. package/lib/stores/editors/CubeExtendDraft.js.map +1 -1
  150. package/lib/stores/editors/CubeNodeDraftRegistry.d.ts.map +1 -1
  151. package/lib/stores/editors/CubeNodeDraftRegistry.js +6 -1
  152. package/lib/stores/editors/CubeNodeDraftRegistry.js.map +1 -1
  153. package/lib/stores/fixtures/CubeSalesDuckDbModel.d.ts +1 -0
  154. package/lib/stores/fixtures/CubeSalesDuckDbModel.d.ts.map +1 -1
  155. package/lib/stores/fixtures/CubeSalesDuckDbModel.js +8 -2
  156. package/lib/stores/fixtures/CubeSalesDuckDbModel.js.map +1 -1
  157. package/lib/stores/source-picker/CubeIngestTabState.d.ts +48 -14
  158. package/lib/stores/source-picker/CubeIngestTabState.d.ts.map +1 -1
  159. package/lib/stores/source-picker/CubeIngestTabState.js +159 -62
  160. package/lib/stores/source-picker/CubeIngestTabState.js.map +1 -1
  161. package/lib/stores/variant/CubeJson.d.ts +48 -0
  162. package/lib/stores/variant/CubeJson.d.ts.map +1 -0
  163. package/lib/stores/variant/CubeJson.js +207 -0
  164. package/lib/stores/variant/CubeJson.js.map +1 -0
  165. package/lib/stores/variant/CubeJsonExplorerState.d.ts +88 -0
  166. package/lib/stores/variant/CubeJsonExplorerState.d.ts.map +1 -0
  167. package/lib/stores/variant/CubeJsonExplorerState.js +297 -0
  168. package/lib/stores/variant/CubeJsonExplorerState.js.map +1 -0
  169. package/lib/stores/variant/CubeJsonFieldsState.d.ts +83 -0
  170. package/lib/stores/variant/CubeJsonFieldsState.d.ts.map +1 -0
  171. package/lib/stores/variant/CubeJsonFieldsState.js +207 -0
  172. package/lib/stores/variant/CubeJsonFieldsState.js.map +1 -0
  173. package/lib/stores/variant/CubeJsonOffers.d.ts +76 -0
  174. package/lib/stores/variant/CubeJsonOffers.d.ts.map +1 -0
  175. package/lib/stores/variant/CubeJsonOffers.js +250 -0
  176. package/lib/stores/variant/CubeJsonOffers.js.map +1 -0
  177. package/lib/stores/variant/CubeJsonParse.d.ts +28 -0
  178. package/lib/stores/variant/CubeJsonParse.d.ts.map +1 -0
  179. package/lib/stores/variant/CubeJsonParse.js +53 -0
  180. package/lib/stores/variant/CubeJsonParse.js.map +1 -0
  181. package/lib/stores/variant/CubeJsonSampling.d.ts +41 -0
  182. package/lib/stores/variant/CubeJsonSampling.d.ts.map +1 -0
  183. package/lib/stores/variant/CubeJsonSampling.js +59 -0
  184. package/lib/stores/variant/CubeJsonSampling.js.map +1 -0
  185. package/lib/stores/variant/CubeJsonShape.d.ts +87 -0
  186. package/lib/stores/variant/CubeJsonShape.d.ts.map +1 -0
  187. package/lib/stores/variant/CubeJsonShape.js +209 -0
  188. package/lib/stores/variant/CubeJsonShape.js.map +1 -0
  189. package/lib/stores/variant/CubeJsonViewerState.d.ts +33 -0
  190. package/lib/stores/variant/CubeJsonViewerState.d.ts.map +1 -0
  191. package/lib/stores/variant/CubeJsonViewerState.js +53 -0
  192. package/lib/stores/variant/CubeJsonViewerState.js.map +1 -0
  193. package/package.json +2 -2
  194. package/src/__lib__/LegendCubeHelpText.ts +4 -0
  195. package/src/__lib__/LegendCubeLabels.ts +60 -8
  196. package/src/__lib__/LegendCubeNavigation.ts +48 -0
  197. package/src/__lib__/LegendCubeTesting.ts +2 -0
  198. package/src/__lib__/LegendCubeTour.ts +173 -0
  199. package/src/__test-utils__/CubeExampleTestUtils.ts +119 -0
  200. package/src/__test-utils__/CubeVariantTestUtils.ts +103 -0
  201. package/src/components/CubeAddItems.tsx +2 -0
  202. package/src/components/CubeEditor.tsx +15 -0
  203. package/src/components/CubeFileMenu.tsx +2 -0
  204. package/src/components/CubeNodeIcon.tsx +2 -0
  205. package/src/components/canvas/CubeCanvas.tsx +17 -1
  206. package/src/components/canvas/CubeCanvasNode.tsx +7 -0
  207. package/src/components/dev-settings/CubeDevSettings.tsx +17 -2
  208. package/src/components/editors/CubeColumnPicker.tsx +3 -0
  209. package/src/components/editors/CubeExplodeEditor.tsx +207 -0
  210. package/src/components/editors/CubeExpressionFilterEditor.tsx +25 -8
  211. package/src/components/editors/CubeExtendEditor.tsx +32 -19
  212. package/src/components/editors/CubeJsonFieldsTree.tsx +316 -0
  213. package/src/components/editors/CubeNodeEditorRegistry.ts +3 -0
  214. package/src/components/grid/CubeGridRegion.tsx +21 -3
  215. package/src/components/grid/CubeGridValues.ts +8 -3
  216. package/src/components/grid/CubeJsonExplorerDialog.tsx +304 -0
  217. package/src/components/grid/CubeJsonViewerDialog.tsx +190 -0
  218. package/src/components/grid/CubeResultGrid.tsx +144 -2
  219. package/src/components/grid/CubeServerSideGrid.tsx +13 -0
  220. package/src/components/palette/CubePalette.tsx +9 -0
  221. package/src/components/source-picker/CubeIngestTab.tsx +62 -30
  222. package/src/components/tour/CubeTour.tsx +317 -0
  223. package/src/index.ts +7 -0
  224. package/src/stores/CubeEditorState.ts +36 -5
  225. package/src/stores/CubeExamples.ts +120 -2
  226. package/src/stores/CubeExamplesState.ts +9 -1
  227. package/src/stores/CubeGridQuickActions.ts +23 -12
  228. package/src/stores/CubePureText.ts +28 -0
  229. package/src/stores/CubeTourState.ts +116 -0
  230. package/src/stores/LegendCubeHost.ts +243 -0
  231. package/src/stores/editors/CubeExplodeDraft.ts +272 -0
  232. package/src/stores/editors/CubeExpressionFilterDraft.ts +4 -0
  233. package/src/stores/editors/CubeExtendDraft.ts +29 -0
  234. package/src/stores/editors/CubeNodeDraftRegistry.ts +7 -0
  235. package/src/stores/fixtures/CubeSalesDuckDbModel.ts +8 -2
  236. package/src/stores/source-picker/CubeIngestTabState.ts +253 -102
  237. package/src/stores/variant/CubeJson.ts +229 -0
  238. package/src/stores/variant/CubeJsonExplorerState.ts +378 -0
  239. package/src/stores/variant/CubeJsonFieldsState.ts +252 -0
  240. package/src/stores/variant/CubeJsonOffers.ts +359 -0
  241. package/src/stores/variant/CubeJsonParse.ts +75 -0
  242. package/src/stores/variant/CubeJsonSampling.ts +90 -0
  243. package/src/stores/variant/CubeJsonShape.ts +279 -0
  244. package/src/stores/variant/CubeJsonViewerState.ts +59 -0
  245. package/tsconfig.json +22 -1
@@ -0,0 +1,48 @@
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
+ /** A JSON value, numbers kept as written and keys in their order */
17
+ export type CubeJsonNode = {
18
+ readonly kind: 'object';
19
+ readonly entries: readonly (readonly [string, CubeJsonNode])[];
20
+ } | {
21
+ readonly kind: 'array';
22
+ readonly items: readonly CubeJsonNode[];
23
+ } | {
24
+ readonly kind: 'number';
25
+ readonly text: string;
26
+ } | {
27
+ readonly kind: 'string';
28
+ readonly value: string;
29
+ } | {
30
+ readonly kind: 'boolean';
31
+ readonly value: boolean;
32
+ } | {
33
+ readonly kind: 'null';
34
+ };
35
+ /** A JSON document; throws a `SyntaxError` on text that isn't one */
36
+ export declare const parseCubeJson: (text: string) => CubeJsonNode;
37
+ /** The document, or `undefined` for text that isn't JSON */
38
+ export declare const readCubeJson: (text: string) => CubeJsonNode | undefined;
39
+ /**
40
+ * A Variant cell on one line, for the eye (PLAN §11.20, as legend-lite's
41
+ * Data Cube shows one): `{name: ann, tier: gold}`, `[a, b]`, numbers as
42
+ * written. Text that isn't JSON is shown as it is; the value itself stays the
43
+ * JSON text, for copying and export.
44
+ */
45
+ export declare const formatCubeJsonLine: (text: string) => string;
46
+ /** The document as JSON, indented two spaces, numbers as written */
47
+ export declare const formatCubeJsonPretty: (node: CubeJsonNode, depth?: number) => string;
48
+ //# sourceMappingURL=CubeJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CubeJson.d.ts","sourceRoot":"","sources":["../../../src/stores/variant/CubeJson.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,oEAAoE;AACpE,MAAM,MAAM,YAAY,GACpB;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC;CAChE,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;CAAE,GACnE;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAK9B,qEAAqE;AACrE,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,YAyG5C,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,YAAY,GAAG,SAM1D,CAAC;AAmCF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,MAGjD,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,oBAAoB,GAAI,MAAM,YAAY,EAAE,cAAS,KAAG,MA8BpE,CAAC"}
@@ -0,0 +1,207 @@
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
+ const WHITESPACE = new Set([' ', '\t', '\n', '\r']);
17
+ const NUMBER = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/uy;
18
+ /** A JSON document; throws a `SyntaxError` on text that isn't one */
19
+ export const parseCubeJson = (text) => {
20
+ let at = 0;
21
+ const fail = (what) => {
22
+ throw new SyntaxError(`${what} at ${at} in JSON`);
23
+ };
24
+ const skipWhitespace = () => {
25
+ while (at < text.length && WHITESPACE.has(text.charAt(at))) {
26
+ at += 1;
27
+ }
28
+ };
29
+ const readString = () => {
30
+ const start = at;
31
+ at += 1;
32
+ while (at < text.length && text.charAt(at) !== '"') {
33
+ at += text.charAt(at) === '\\' ? 2 : 1;
34
+ }
35
+ if (at >= text.length) {
36
+ fail('An unterminated string');
37
+ }
38
+ at += 1;
39
+ // a string loses nothing through JSON.parse: only numbers do
40
+ return JSON.parse(text.slice(start, at));
41
+ };
42
+ const readValue = () => {
43
+ skipWhitespace();
44
+ const char = text.charAt(at);
45
+ if (char === '{') {
46
+ at += 1;
47
+ const entries = [];
48
+ skipWhitespace();
49
+ if (text.charAt(at) === '}') {
50
+ at += 1;
51
+ return { kind: 'object', entries };
52
+ }
53
+ for (;;) {
54
+ skipWhitespace();
55
+ if (text.charAt(at) !== '"') {
56
+ fail('A key expected');
57
+ }
58
+ const key = readString();
59
+ skipWhitespace();
60
+ if (text.charAt(at) !== ':') {
61
+ fail('":" expected');
62
+ }
63
+ at += 1;
64
+ entries.push([key, readValue()]);
65
+ skipWhitespace();
66
+ if (text.charAt(at) === ',') {
67
+ at += 1;
68
+ }
69
+ else if (text.charAt(at) === '}') {
70
+ at += 1;
71
+ return { kind: 'object', entries };
72
+ }
73
+ else {
74
+ fail('"," or "}" expected');
75
+ }
76
+ }
77
+ }
78
+ if (char === '[') {
79
+ at += 1;
80
+ const items = [];
81
+ skipWhitespace();
82
+ if (text.charAt(at) === ']') {
83
+ at += 1;
84
+ return { kind: 'array', items };
85
+ }
86
+ for (;;) {
87
+ items.push(readValue());
88
+ skipWhitespace();
89
+ if (text.charAt(at) === ',') {
90
+ at += 1;
91
+ }
92
+ else if (text.charAt(at) === ']') {
93
+ at += 1;
94
+ return { kind: 'array', items };
95
+ }
96
+ else {
97
+ fail('"," or "]" expected');
98
+ }
99
+ }
100
+ }
101
+ if (char === '"') {
102
+ return { kind: 'string', value: readString() };
103
+ }
104
+ for (const [word, node] of [
105
+ ['true', { kind: 'boolean', value: true }],
106
+ ['false', { kind: 'boolean', value: false }],
107
+ ['null', { kind: 'null' }],
108
+ ]) {
109
+ if (text.startsWith(word, at)) {
110
+ at += word.length;
111
+ return node;
112
+ }
113
+ }
114
+ NUMBER.lastIndex = at;
115
+ const number = NUMBER.exec(text);
116
+ if (!number) {
117
+ return fail('A value expected');
118
+ }
119
+ at += number[0].length;
120
+ return { kind: 'number', text: number[0] };
121
+ };
122
+ const value = readValue();
123
+ skipWhitespace();
124
+ if (at < text.length) {
125
+ fail('Text after the value');
126
+ }
127
+ return value;
128
+ };
129
+ /** The document, or `undefined` for text that isn't JSON */
130
+ export const readCubeJson = (text) => {
131
+ try {
132
+ return parseCubeJson(text);
133
+ }
134
+ catch {
135
+ return undefined;
136
+ }
137
+ };
138
+ /**
139
+ * A key or a string shown bare when it can't be mistaken for anything else:
140
+ * not empty, none of the notation's punctuation or a line break, no space at
141
+ * either end, and not a number, `true`, `false` or `null`; JSON-quoted
142
+ * otherwise
143
+ */
144
+ const showText = (text) => text !== '' &&
145
+ !/[,:{}[\]"\n\r\t]/u.test(text) &&
146
+ text === text.trim() &&
147
+ !/^(?:true|false|null|-?\d.*)$/u.test(text)
148
+ ? text
149
+ : JSON.stringify(text);
150
+ const showNode = (node) => {
151
+ switch (node.kind) {
152
+ case 'object':
153
+ return `{${node.entries.map(([key, value]) => `${showText(key)}: ${showNode(value)}`).join(', ')}}`;
154
+ case 'array':
155
+ return `[${node.items.map(showNode).join(', ')}]`;
156
+ case 'string':
157
+ return showText(node.value);
158
+ case 'number':
159
+ return node.text;
160
+ case 'boolean':
161
+ return String(node.value);
162
+ case 'null':
163
+ return 'null';
164
+ default:
165
+ return '';
166
+ }
167
+ };
168
+ /**
169
+ * A Variant cell on one line, for the eye (PLAN §11.20, as legend-lite's
170
+ * Data Cube shows one): `{name: ann, tier: gold}`, `[a, b]`, numbers as
171
+ * written. Text that isn't JSON is shown as it is; the value itself stays the
172
+ * JSON text, for copying and export.
173
+ */
174
+ export const formatCubeJsonLine = (text) => {
175
+ const node = readCubeJson(text);
176
+ return node ? showNode(node) : text;
177
+ };
178
+ /** The document as JSON, indented two spaces, numbers as written */
179
+ export const formatCubeJsonPretty = (node, depth = 0) => {
180
+ const indent = ' '.repeat(depth + 1);
181
+ const closing = ' '.repeat(depth);
182
+ switch (node.kind) {
183
+ case 'object':
184
+ return node.entries.length === 0
185
+ ? '{}'
186
+ : `{\n${node.entries
187
+ .map(([key, value]) => `${indent}${JSON.stringify(key)}: ${formatCubeJsonPretty(value, depth + 1)}`)
188
+ .join(',\n')}\n${closing}}`;
189
+ case 'array':
190
+ return node.items.length === 0
191
+ ? '[]'
192
+ : `[\n${node.items
193
+ .map((item) => `${indent}${formatCubeJsonPretty(item, depth + 1)}`)
194
+ .join(',\n')}\n${closing}]`;
195
+ case 'string':
196
+ return JSON.stringify(node.value);
197
+ case 'number':
198
+ return node.text;
199
+ case 'boolean':
200
+ return String(node.value);
201
+ case 'null':
202
+ return 'null';
203
+ default:
204
+ return '';
205
+ }
206
+ };
207
+ //# sourceMappingURL=CubeJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CubeJson.js","sourceRoot":"","sources":["../../../src/stores/variant/CubeJson.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACpD,MAAM,MAAM,GAAG,+CAA+C,CAAC;AAE/D,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAgB,EAAE;IAC1D,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,MAAM,IAAI,GAAG,CAAC,IAAY,EAAS,EAAE;QACnC,MAAM,IAAI,WAAW,CAAC,GAAG,IAAI,OAAO,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC,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,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAC/E;qBACA,IAAI,CAAC,KAAK,CAAC,KAAK,OAAO,GAAG,CAAC;QACpC,KAAK,OAAO;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;gBAC5B,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK;qBACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;qBAClE,IAAI,CAAC,KAAK,CAAC,KAAK,OAAO,GAAG,CAAC;QACpC,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,88 @@
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
+ import { type SchemaColumn } from '@finos/legend-cube';
17
+ import { type GeneratorFn } from '@finos/legend-shared';
18
+ import type { CubeEditorState } from '../CubeEditorState.js';
19
+ import { type CubeJsonField, type CubeJsonOffer } from './CubeJsonOffers.js';
20
+ import type { CubeJsonSample } from './CubeJsonShape.js';
21
+ /**
22
+ * Explore JSON (PLAN §11.20): a Variant column's documents, sampled through
23
+ * the cube's own query path (the query up to the node that ran, the column
24
+ * alone, its non-empty values), so the sample is listed in Runs and can be
25
+ * stopped; their fields as a tree; and the offers ticked, added after the
26
+ * node that ran as one undo step: an Extend of the columns, then an Explode
27
+ * Array for one row per element of an array. The engine parses each column's
28
+ * text first; the background check types the Extend, as any typed in the
29
+ * editor.
30
+ */
31
+ export declare class CubeJsonExplorerState {
32
+ readonly editorState: CubeEditorState;
33
+ /** The column explored; `undefined` while closed */
34
+ column: SchemaColumn | undefined;
35
+ /** What was read: the first values, or every row */
36
+ sample: CubeJsonSample | undefined;
37
+ isReading: boolean;
38
+ isAdding: boolean;
39
+ /** Why the column couldn't be read, or the columns added */
40
+ error: string | undefined;
41
+ search: string;
42
+ /** The field whose offers show */
43
+ selectedPath: readonly string[];
44
+ /** The ticked offers, by field and key */
45
+ ticked: Map<string, CubeJsonOffer>;
46
+ /** The cube as it was when the dialog opened, and the node that ran */
47
+ private document;
48
+ private afterId;
49
+ private controller;
50
+ constructor(editorState: CubeEditorState);
51
+ get isOpen(): boolean;
52
+ /** The column's fields, from what was read */
53
+ get fields(): CubeJsonField | undefined;
54
+ get selectedField(): CubeJsonField | undefined;
55
+ /** The offers ticked, in the order ticked */
56
+ get tickedOffers(): CubeJsonOffer[];
57
+ isTicked(path: readonly string[], offer: CubeJsonOffer): boolean;
58
+ /**
59
+ * Why Explore JSON can't be used on the column now: the grid's blockers
60
+ * (stale rows, edits, a run, a read-only cube), or a database without
61
+ * JSON; `undefined` when it can
62
+ */
63
+ getDisabledReason(): string | undefined;
64
+ /** Opens the dialog on a column of the rows shown, and reads its first values */
65
+ open(column: SchemaColumn): GeneratorFn<void>;
66
+ /** Reads the column's first values, or every row: either replaces what was read */
67
+ read(everyRow: boolean): GeneratorFn<void>;
68
+ /** Stops a read in flight, keeping what was read before it */
69
+ stop(): void;
70
+ setSearch(search: string): void;
71
+ select(path: readonly string[]): void;
72
+ /**
73
+ * Ticks or unticks an offer. One row per element can be ticked for one
74
+ * array at a time: two would give a row for each pair of their elements.
75
+ */
76
+ toggle(path: readonly string[], offer: CubeJsonOffer): void;
77
+ /**
78
+ * Adds the ticked offers after the node that ran, one undo step: an Extend
79
+ * of the columns, each under its default name or the next free one, then
80
+ * an Explode Array for the array ticked for one row per element, its
81
+ * element named the same way. The engine parses each column's text first,
82
+ * and the dialog stays open with the error if it can't. Nothing is added if
83
+ * the cube changed meanwhile.
84
+ */
85
+ add(): GeneratorFn<void>;
86
+ close(): void;
87
+ }
88
+ //# sourceMappingURL=CubeJsonExplorerState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CubeJsonExplorerState.d.ts","sourceRoot":"","sources":["../../../src/stores/variant/CubeJsonExplorerState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAa3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,aAAa,EAGnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AASzD;;;;;;;;;GASG;AACH,qBAAa,qBAAqB;IAChC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;IAEtC,oDAAoD;IACpD,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;IACjC,oDAAoD;IACpD,MAAM,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,SAAS,UAAS;IAClB,QAAQ,UAAS;IACjB,4DAA4D;IAC5D,KAAK,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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
+ import { Explode, Extend, getVariantDatabaseProblem, } from '@finos/legend-cube';
17
+ import { assertErrorThrown } from '@finos/legend-shared';
18
+ import { action, computed, flow, flowResult, makeObservable, observable, } from 'mobx';
19
+ import { CubeEngineError, } from '../../graph-manager/CubeEngine.js';
20
+ import { getCubeGridActionBlocker } from '../CubeGridQuickActions.js';
21
+ import { CubeQueryRunAborted } from '../CubeQueryRun.js';
22
+ import { getCubeJsonFields, getFreeCubeColumnName, } from './CubeJsonOffers.js';
23
+ import { readCubeJsonSample } from './CubeJsonSampling.js';
24
+ /** A field's path as one key, for ticking */
25
+ const pathKey = (path) => JSON.stringify(path);
26
+ /** A ticked offer, by its field and its key */
27
+ const offerKey = (path, offer) => `${pathKey(path)} ${offer.key}`;
28
+ /**
29
+ * Explore JSON (PLAN §11.20): a Variant column's documents, sampled through
30
+ * the cube's own query path (the query up to the node that ran, the column
31
+ * alone, its non-empty values), so the sample is listed in Runs and can be
32
+ * stopped; their fields as a tree; and the offers ticked, added after the
33
+ * node that ran as one undo step: an Extend of the columns, then an Explode
34
+ * Array for one row per element of an array. The engine parses each column's
35
+ * text first; the background check types the Extend, as any typed in the
36
+ * editor.
37
+ */
38
+ export class CubeJsonExplorerState {
39
+ editorState;
40
+ /** The column explored; `undefined` while closed */
41
+ column;
42
+ /** What was read: the first values, or every row */
43
+ sample;
44
+ isReading = false;
45
+ isAdding = false;
46
+ /** Why the column couldn't be read, or the columns added */
47
+ error;
48
+ search = '';
49
+ /** The field whose offers show */
50
+ selectedPath = [];
51
+ /** The ticked offers, by field and key */
52
+ ticked = new Map();
53
+ /** The cube as it was when the dialog opened, and the node that ran */
54
+ document;
55
+ afterId;
56
+ controller;
57
+ constructor(editorState) {
58
+ makeObservable(this, {
59
+ column: observable.ref,
60
+ sample: observable.ref,
61
+ isReading: observable,
62
+ isAdding: observable,
63
+ error: observable,
64
+ search: observable,
65
+ selectedPath: observable.ref,
66
+ ticked: observable.shallow,
67
+ document: observable.ref,
68
+ afterId: observable,
69
+ isOpen: computed,
70
+ fields: computed,
71
+ selectedField: computed,
72
+ tickedOffers: computed,
73
+ open: flow,
74
+ read: flow,
75
+ add: flow,
76
+ stop: action,
77
+ close: action,
78
+ setSearch: action,
79
+ select: action,
80
+ toggle: action,
81
+ });
82
+ this.editorState = editorState;
83
+ }
84
+ get isOpen() {
85
+ return this.column !== undefined;
86
+ }
87
+ /** The column's fields, from what was read */
88
+ get fields() {
89
+ return this.column && this.sample
90
+ ? getCubeJsonFields(this.column.name, this.sample)
91
+ : undefined;
92
+ }
93
+ get selectedField() {
94
+ const key = pathKey(this.selectedPath);
95
+ const find = (field) => pathKey(field.path) === key
96
+ ? field
97
+ : field.children.reduce((found, child) => found ?? find(child), undefined);
98
+ return this.fields ? find(this.fields) : undefined;
99
+ }
100
+ /** The offers ticked, in the order ticked */
101
+ get tickedOffers() {
102
+ return [...this.ticked.values()];
103
+ }
104
+ isTicked(path, offer) {
105
+ return this.ticked.has(offerKey(path, offer));
106
+ }
107
+ /**
108
+ * Why Explore JSON can't be used on the column now: the grid's blockers
109
+ * (stale rows, edits, a run, a read-only cube), or a database without
110
+ * JSON; `undefined` when it can
111
+ */
112
+ getDisabledReason() {
113
+ const { editorState } = this;
114
+ const blocker = getCubeGridActionBlocker(editorState);
115
+ if (blocker) {
116
+ return blocker;
117
+ }
118
+ const { context, query } = editorState.document;
119
+ const nodeId = query.selected;
120
+ return context?.runtime === undefined || nodeId === undefined
121
+ ? undefined
122
+ : getVariantDatabaseProblem(editorState.getRunDatabaseType(query, nodeId, context.model, context.runtime));
123
+ }
124
+ /** Opens the dialog on a column of the rows shown, and reads its first values */
125
+ *open(column) {
126
+ const { editorState } = this;
127
+ const { document } = editorState;
128
+ this.stop();
129
+ this.column = column;
130
+ this.document = document;
131
+ this.afterId = document.query.selected;
132
+ this.sample = undefined;
133
+ this.error = undefined;
134
+ this.search = '';
135
+ this.selectedPath = [];
136
+ this.ticked.clear();
137
+ // the database the column's rows run on, which must read JSON: its
138
+ // model's outline may not have been needed by the run that showed them
139
+ const context = document.context;
140
+ const nodeId = this.afterId;
141
+ if (context?.runtime !== undefined && nodeId !== undefined) {
142
+ yield flowResult(editorState.loadModelOutline(context.model));
143
+ const problem = getVariantDatabaseProblem(editorState.getRunDatabaseType(document.query, nodeId, context.model, context.runtime));
144
+ if (problem) {
145
+ this.error = problem;
146
+ return;
147
+ }
148
+ }
149
+ yield flowResult(this.read(false));
150
+ }
151
+ /** Reads the column's first values, or every row: either replaces what was read */
152
+ *read(everyRow) {
153
+ const { editorState, column, document, afterId } = this;
154
+ if (!column ||
155
+ !document ||
156
+ afterId === undefined ||
157
+ document.context?.runtime === undefined ||
158
+ this.isReading) {
159
+ return;
160
+ }
161
+ const controller = new AbortController();
162
+ this.controller = controller;
163
+ this.isReading = true;
164
+ this.error = undefined;
165
+ try {
166
+ const sample = (yield readCubeJsonSample(editorState, {
167
+ document,
168
+ afterId,
169
+ column,
170
+ everyRow,
171
+ abortController: controller,
172
+ }));
173
+ if (this.controller !== controller) {
174
+ return;
175
+ }
176
+ this.sample = sample;
177
+ }
178
+ catch (error) {
179
+ if (this.controller !== controller ||
180
+ error instanceof CubeQueryRunAborted) {
181
+ return;
182
+ }
183
+ assertErrorThrown(error);
184
+ this.error =
185
+ error instanceof CubeEngineError ? error.firstLine : error.message;
186
+ }
187
+ finally {
188
+ if (this.controller === controller) {
189
+ this.controller = undefined;
190
+ this.isReading = false;
191
+ }
192
+ }
193
+ }
194
+ /** Stops a read in flight, keeping what was read before it */
195
+ stop() {
196
+ this.controller?.abort();
197
+ this.controller = undefined;
198
+ this.isReading = false;
199
+ }
200
+ setSearch(search) {
201
+ this.search = search;
202
+ }
203
+ select(path) {
204
+ this.selectedPath = path;
205
+ }
206
+ /**
207
+ * Ticks or unticks an offer. One row per element can be ticked for one
208
+ * array at a time: two would give a row for each pair of their elements.
209
+ */
210
+ toggle(path, offer) {
211
+ const key = offerKey(path, offer);
212
+ if (this.ticked.has(key)) {
213
+ this.ticked.delete(key);
214
+ return;
215
+ }
216
+ if (offer.explode) {
217
+ [...this.ticked].forEach(([other, ticked]) => {
218
+ if (ticked.explode) {
219
+ this.ticked.delete(other);
220
+ }
221
+ });
222
+ }
223
+ this.ticked.set(key, offer);
224
+ }
225
+ /**
226
+ * Adds the ticked offers after the node that ran, one undo step: an Extend
227
+ * of the columns, each under its default name or the next free one, then
228
+ * an Explode Array for the array ticked for one row per element, its
229
+ * element named the same way. The engine parses each column's text first,
230
+ * and the dialog stays open with the error if it can't. Nothing is added if
231
+ * the cube changed meanwhile.
232
+ */
233
+ *add() {
234
+ const { editorState, document, afterId } = this;
235
+ const ticked = this.tickedOffers;
236
+ const offers = ticked.filter((offer) => offer.code !== undefined);
237
+ const exploded = ticked.find((offer) => offer.explode !== undefined);
238
+ if (!document ||
239
+ afterId === undefined ||
240
+ (!offers.length && !exploded) ||
241
+ this.isAdding ||
242
+ editorState.document !== document) {
243
+ return;
244
+ }
245
+ this.isAdding = true;
246
+ this.error = undefined;
247
+ try {
248
+ const { query } = document;
249
+ const extendId = query.generateId(Extend.TYPE);
250
+ const taken = (editorState.analysis.schemas.get(afterId)?.columns ?? []).map((column) => column.name);
251
+ const columns = [];
252
+ for (const [index, offer] of offers.entries()) {
253
+ const name = getFreeCubeColumnName(offer.name, [
254
+ ...taken,
255
+ ...columns.map((column) => column.name),
256
+ ]);
257
+ const parsed = (yield editorState.host.engine.parseExpression(offer.code, `${extendId}:${index}`));
258
+ columns.push({ name, code: offer.code, lambda: parsed.lambda });
259
+ }
260
+ // as the dialog found it: nothing changed while the engine parsed
261
+ if (editorState.document !== document) {
262
+ return;
263
+ }
264
+ const nodes = columns.length
265
+ ? [new Extend(extendId, columns)]
266
+ : [];
267
+ if (exploded?.explode) {
268
+ nodes.push(new Explode(query.generateId(Explode.TYPE), exploded.explode.column, exploded.explode.path, getFreeCubeColumnName(exploded.name, [
269
+ ...taken,
270
+ ...columns.map((column) => column.name),
271
+ ])));
272
+ }
273
+ editorState.addConfiguredNodes(nodes, afterId);
274
+ this.close();
275
+ }
276
+ catch (error) {
277
+ assertErrorThrown(error);
278
+ this.error =
279
+ error instanceof CubeEngineError ? error.firstLine : error.message;
280
+ }
281
+ finally {
282
+ this.isAdding = false;
283
+ }
284
+ }
285
+ close() {
286
+ this.stop();
287
+ this.column = undefined;
288
+ this.sample = undefined;
289
+ this.document = undefined;
290
+ this.afterId = undefined;
291
+ this.error = undefined;
292
+ this.search = '';
293
+ this.selectedPath = [];
294
+ this.ticked.clear();
295
+ }
296
+ }
297
+ //# sourceMappingURL=CubeJsonExplorerState.js.map