@finos/legend-application-studio 28.9.0 → 28.10.1

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 (122) hide show
  1. package/lib/__lib__/LegendStudioCommand.d.ts +1 -0
  2. package/lib/__lib__/LegendStudioCommand.d.ts.map +1 -1
  3. package/lib/__lib__/LegendStudioCommand.js +5 -0
  4. package/lib/__lib__/LegendStudioCommand.js.map +1 -1
  5. package/lib/components/ShowcaseManager.d.ts.map +1 -1
  6. package/lib/components/ShowcaseManager.js +5 -2
  7. package/lib/components/ShowcaseManager.js.map +1 -1
  8. package/lib/components/editor/ActivityBar.d.ts.map +1 -1
  9. package/lib/components/editor/ActivityBar.js +20 -17
  10. package/lib/components/editor/ActivityBar.js.map +1 -1
  11. package/lib/components/editor/editor-group/EditorGroup.d.ts.map +1 -1
  12. package/lib/components/editor/editor-group/EditorGroup.js +7 -1
  13. package/lib/components/editor/editor-group/EditorGroup.js.map +1 -1
  14. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.d.ts +5 -0
  15. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.d.ts.map +1 -1
  16. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.js +29 -10
  17. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.js.map +1 -1
  18. package/lib/components/editor/editor-group/connection-editor/DatabaseModelBuilder.d.ts +11 -0
  19. package/lib/components/editor/editor-group/connection-editor/DatabaseModelBuilder.d.ts.map +1 -1
  20. package/lib/components/editor/editor-group/connection-editor/DatabaseModelBuilder.js +22 -10
  21. package/lib/components/editor/editor-group/connection-editor/DatabaseModelBuilder.js.map +1 -1
  22. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.d.ts +7 -0
  23. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.d.ts.map +1 -1
  24. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js +3 -3
  25. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js.map +1 -1
  26. package/lib/components/editor/editor-group/end-to-end-flow-editor/ConnectionToQueryWorkflowEditor.d.ts +52 -0
  27. package/lib/components/editor/editor-group/end-to-end-flow-editor/ConnectionToQueryWorkflowEditor.d.ts.map +1 -0
  28. package/lib/components/editor/editor-group/end-to-end-flow-editor/ConnectionToQueryWorkflowEditor.js +150 -0
  29. package/lib/components/editor/editor-group/end-to-end-flow-editor/ConnectionToQueryWorkflowEditor.js.map +1 -0
  30. package/lib/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.js +1 -1
  31. package/lib/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.js.map +1 -1
  32. package/lib/components/editor/side-bar/Explorer.d.ts.map +1 -1
  33. package/lib/components/editor/side-bar/Explorer.js +6 -6
  34. package/lib/components/editor/side-bar/Explorer.js.map +1 -1
  35. package/lib/components/editor/side-bar/SideBar.d.ts.map +1 -1
  36. package/lib/components/editor/side-bar/SideBar.js +4 -1
  37. package/lib/components/editor/side-bar/SideBar.js.map +1 -1
  38. package/lib/components/editor/side-bar/end-to-end-workflow/EndToEndWorkflows.d.ts +23 -0
  39. package/lib/components/editor/side-bar/end-to-end-workflow/EndToEndWorkflows.d.ts.map +1 -0
  40. package/lib/components/editor/side-bar/end-to-end-workflow/EndToEndWorkflows.js +43 -0
  41. package/lib/components/editor/side-bar/end-to-end-workflow/EndToEndWorkflows.js.map +1 -0
  42. package/lib/index.css +2 -2
  43. package/lib/index.css.map +1 -1
  44. package/lib/package.json +1 -1
  45. package/lib/stores/ShowcaseManagerState.d.ts +1 -0
  46. package/lib/stores/ShowcaseManagerState.d.ts.map +1 -1
  47. package/lib/stores/ShowcaseManagerState.js +11 -1
  48. package/lib/stores/ShowcaseManagerState.js.map +1 -1
  49. package/lib/stores/editor/EditorConfig.d.ts +3 -1
  50. package/lib/stores/editor/EditorConfig.d.ts.map +1 -1
  51. package/lib/stores/editor/EditorConfig.js +4 -1
  52. package/lib/stores/editor/EditorConfig.js.map +1 -1
  53. package/lib/stores/editor/EditorStore.d.ts +3 -0
  54. package/lib/stores/editor/EditorStore.d.ts.map +1 -1
  55. package/lib/stores/editor/EditorStore.js +17 -0
  56. package/lib/stores/editor/EditorStore.js.map +1 -1
  57. package/lib/stores/editor/ExplorerTreeState.d.ts.map +1 -1
  58. package/lib/stores/editor/ExplorerTreeState.js +1 -1
  59. package/lib/stores/editor/ExplorerTreeState.js.map +1 -1
  60. package/lib/stores/editor/GraphEditGrammarModeState.d.ts.map +1 -1
  61. package/lib/stores/editor/GraphEditGrammarModeState.js.map +1 -1
  62. package/lib/stores/editor/NewElementState.d.ts +1 -0
  63. package/lib/stores/editor/NewElementState.d.ts.map +1 -1
  64. package/lib/stores/editor/NewElementState.js +1 -1
  65. package/lib/stores/editor/NewElementState.js.map +1 -1
  66. package/lib/stores/editor/editor-state/element-editor-state/ElementEditorState.d.ts.map +1 -1
  67. package/lib/stores/editor/editor-state/element-editor-state/ElementEditorState.js +2 -1
  68. package/lib/stores/editor/editor-state/element-editor-state/ElementEditorState.js.map +1 -1
  69. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts +6 -2
  70. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts.map +1 -1
  71. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js +53 -34
  72. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js.map +1 -1
  73. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.d.ts.map +1 -1
  74. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.js +1 -1
  75. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.js.map +1 -1
  76. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseModelBuilderState.d.ts +3 -2
  77. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseModelBuilderState.d.ts.map +1 -1
  78. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseModelBuilderState.js +8 -5
  79. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseModelBuilderState.js.map +1 -1
  80. package/lib/stores/editor/editor-state/end-to-end-workflow-state/EndToEndWorkflowEditorState.d.ts +22 -0
  81. package/lib/stores/editor/editor-state/end-to-end-workflow-state/EndToEndWorkflowEditorState.d.ts.map +1 -0
  82. package/lib/stores/editor/editor-state/end-to-end-workflow-state/EndToEndWorkflowEditorState.js +23 -0
  83. package/lib/stores/editor/editor-state/end-to-end-workflow-state/EndToEndWorkflowEditorState.js.map +1 -0
  84. package/lib/stores/editor/editor-state/end-to-end-workflow-state/QueryConnectionEndToEndWorkflowEditorState.d.ts +111 -0
  85. package/lib/stores/editor/editor-state/end-to-end-workflow-state/QueryConnectionEndToEndWorkflowEditorState.d.ts.map +1 -0
  86. package/lib/stores/editor/editor-state/end-to-end-workflow-state/QueryConnectionEndToEndWorkflowEditorState.js +453 -0
  87. package/lib/stores/editor/editor-state/end-to-end-workflow-state/QueryConnectionEndToEndWorkflowEditorState.js.map +1 -0
  88. package/lib/stores/editor/sidebar-state/end-to-end-workflow/GlobalEndToEndFlowState.d.ts +24 -0
  89. package/lib/stores/editor/sidebar-state/end-to-end-workflow/GlobalEndToEndFlowState.d.ts.map +1 -0
  90. package/lib/stores/editor/sidebar-state/end-to-end-workflow/GlobalEndToEndFlowState.js +37 -0
  91. package/lib/stores/editor/sidebar-state/end-to-end-workflow/GlobalEndToEndFlowState.js.map +1 -0
  92. package/lib/stores/showcase/ShowcaseViewerStore.d.ts.map +1 -1
  93. package/lib/stores/showcase/ShowcaseViewerStore.js +5 -1
  94. package/lib/stores/showcase/ShowcaseViewerStore.js.map +1 -1
  95. package/package.json +5 -5
  96. package/src/__lib__/LegendStudioCommand.ts +5 -0
  97. package/src/components/ShowcaseManager.tsx +18 -0
  98. package/src/components/editor/ActivityBar.tsx +56 -15
  99. package/src/components/editor/editor-group/EditorGroup.tsx +21 -1
  100. package/src/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.tsx +136 -103
  101. package/src/components/editor/editor-group/connection-editor/DatabaseModelBuilder.tsx +97 -53
  102. package/src/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.tsx +4 -3
  103. package/src/components/editor/editor-group/end-to-end-flow-editor/ConnectionToQueryWorkflowEditor.tsx +518 -0
  104. package/src/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.tsx +1 -1
  105. package/src/components/editor/side-bar/Explorer.tsx +7 -6
  106. package/src/components/editor/side-bar/SideBar.tsx +13 -1
  107. package/src/components/editor/side-bar/end-to-end-workflow/EndToEndWorkflows.tsx +102 -0
  108. package/src/stores/ShowcaseManagerState.ts +19 -1
  109. package/src/stores/editor/EditorConfig.ts +3 -0
  110. package/src/stores/editor/EditorStore.ts +21 -0
  111. package/src/stores/editor/ExplorerTreeState.ts +1 -0
  112. package/src/stores/editor/GraphEditGrammarModeState.ts +3 -3
  113. package/src/stores/editor/NewElementState.ts +1 -1
  114. package/src/stores/editor/editor-state/element-editor-state/ElementEditorState.ts +2 -1
  115. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.ts +77 -49
  116. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.ts +1 -2
  117. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseModelBuilderState.ts +12 -8
  118. package/src/stores/editor/editor-state/end-to-end-workflow-state/EndToEndWorkflowEditorState.ts +23 -0
  119. package/src/stores/editor/editor-state/end-to-end-workflow-state/QueryConnectionEndToEndWorkflowEditorState.ts +775 -0
  120. package/src/stores/editor/sidebar-state/end-to-end-workflow/GlobalEndToEndFlowState.ts +43 -0
  121. package/src/stores/showcase/ShowcaseViewerStore.ts +4 -0
  122. package/tsconfig.json +5 -0
@@ -0,0 +1,775 @@
1
+ /**
2
+ * Copyright (c) 2020-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 { action, flow, flowResult, observable, makeObservable } from 'mobx';
18
+ import {
19
+ guaranteeNonNullable,
20
+ type GeneratorFn,
21
+ LogEvent,
22
+ assertErrorThrown,
23
+ ActionState,
24
+ getNonNullableEntry,
25
+ } from '@finos/legend-shared';
26
+ import {
27
+ END_TO_END_WORKFLOWS,
28
+ EndToEndWorkflowEditorState,
29
+ } from './EndToEndWorkflowEditorState.js';
30
+ import {
31
+ RelationalDatabaseConnection,
32
+ LocalH2DatasourceSpecification,
33
+ PackageableElementExplicitReference,
34
+ stub_Database,
35
+ DatabaseType,
36
+ DefaultH2AuthenticationStrategy,
37
+ type TextCompilationResult,
38
+ type PureModel,
39
+ PackageableConnection,
40
+ EngineRuntime,
41
+ IdentifiedConnection,
42
+ generateIdentifiedConnectionId,
43
+ PackageableRuntime,
44
+ extractElementNameFromPath,
45
+ getOrCreatePackage,
46
+ extractPackagePathFromPath,
47
+ getMappingCompatibleClasses,
48
+ RuntimePointer,
49
+ ParserError,
50
+ CompilationError,
51
+ observe_RelationalDatabaseConnection,
52
+ } from '@finos/legend-graph';
53
+ import type { EditorStore } from '../../EditorStore.js';
54
+ import { BaseStepperState } from '@finos/legend-art';
55
+ import { LEGEND_STUDIO_APP_EVENT } from '../../../../__lib__/LegendStudioEvent.js';
56
+ import { EntityChangeType, type EntityChange } from '@finos/legend-server-sdlc';
57
+ import type { Entity } from '@finos/legend-storage';
58
+ import {
59
+ ClassQueryBuilderState,
60
+ QueryBuilderConfig,
61
+ } from '@finos/legend-query-builder';
62
+ import {
63
+ packageableConnection_setConnectionValue,
64
+ runtime_addIdentifiedConnection,
65
+ runtime_addMapping,
66
+ runtime_setMappings,
67
+ } from '../../../graph-modifier/DSL_Mapping_GraphModifierHelper.js';
68
+ import { DatabaseModelBuilderState } from '../element-editor-state/connection/DatabaseModelBuilderState.js';
69
+ import { DatabaseBuilderWizardState } from '../element-editor-state/connection/DatabaseBuilderWizardState.js';
70
+ import { RelationalDatabaseConnectionValueState } from '../element-editor-state/connection/ConnectionEditorState.js';
71
+ import { DEFAULT_H2_SQL } from '../../NewElementState.js';
72
+
73
+ export enum QUERY_CONNECTION_WORKFLOW_STEPS {
74
+ CREATE_CONNECTION = 'Create Connection',
75
+ CREATE_DATABASE = 'Create Database',
76
+ EDIT_DATABASE = 'Edit Database',
77
+ CREATE_CLASS_MAPPING_RUNTIME = 'Create Class/Mapping/Runtime',
78
+ CONFIRMATION = 'Confirmation',
79
+ }
80
+
81
+ const DEFAULT_CONNECTION_PATH = 'store::MyConnection';
82
+ const DEFAULT_RUNTIME_PATH = 'store::MyRuntime';
83
+ const JOIN_CODE_SYNTAX =
84
+ '// Please refer to pure code syntax below for how to create join' +
85
+ '\n' +
86
+ '// Join join_name(Table1.column1 = Table2.column2);' +
87
+ '\n';
88
+
89
+ export abstract class ConnectionToQueryStepperState extends BaseStepperState {
90
+ abstract override label: QUERY_CONNECTION_WORKFLOW_STEPS;
91
+ }
92
+ // step5 - confirm/update final grammar and query
93
+ export class QueryConnectionConfirmationAndGrammarEditorStepperState extends ConnectionToQueryStepperState {
94
+ workflowEditorState: QueryConnectionEndToEndWorkflowEditorState;
95
+ isCompilingCode = ActionState.create();
96
+ editorStore: EditorStore;
97
+
98
+ constructor(
99
+ queryConnectionEndToEndWorkflowState: QueryConnectionEndToEndWorkflowEditorState,
100
+ ) {
101
+ super();
102
+ makeObservable(this, {
103
+ workflowEditorState: false,
104
+ isCompilingCode: observable,
105
+ handleNext: flow,
106
+ query: flow,
107
+ compile: flow,
108
+ });
109
+ this.workflowEditorState = queryConnectionEndToEndWorkflowState;
110
+ this.editorStore = this.workflowEditorState.editorStore;
111
+ }
112
+
113
+ get label(): QUERY_CONNECTION_WORKFLOW_STEPS {
114
+ return QUERY_CONNECTION_WORKFLOW_STEPS.CONFIRMATION;
115
+ }
116
+
117
+ *compile(): GeneratorFn<void> {
118
+ try {
119
+ this.isCompilingCode.inProgress();
120
+ const compilationResult = (yield flowResult(
121
+ yield this.editorStore.graphManagerState.graphManager.compileText(
122
+ this.workflowEditorState.finalGrammarCode,
123
+ this.workflowEditorState.workflowGraph,
124
+ ),
125
+ )) as TextCompilationResult;
126
+ this.editorStore.applicationStore.notificationService.notifySuccess(
127
+ 'Compiled successfully',
128
+ );
129
+ const entities = compilationResult.entities;
130
+ const newGraph = this.editorStore.graphManagerState.createNewGraph();
131
+ yield flowResult(
132
+ this.editorStore.graphManagerState.graphManager.buildGraph(
133
+ newGraph,
134
+ entities,
135
+ ActionState.create(),
136
+ ),
137
+ );
138
+ this.workflowEditorState.workflowGraph = newGraph;
139
+ this.workflowEditorState.setCompileError(undefined);
140
+ } catch (error) {
141
+ if (error instanceof ParserError || error instanceof CompilationError) {
142
+ this.workflowEditorState.setCompileError(error);
143
+ }
144
+ assertErrorThrown(error);
145
+ this.editorStore.applicationStore.logService.error(
146
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_MODEL_BUILDER_FAILURE),
147
+ error,
148
+ );
149
+ this.editorStore.applicationStore.notificationService.notifyError(error);
150
+ this.isCompilingCode.fail();
151
+ } finally {
152
+ this.isCompilingCode.complete();
153
+ }
154
+ }
155
+
156
+ *query(): GeneratorFn<void> {
157
+ const entities =
158
+ (yield this.editorStore.graphManagerState.graphManager.pureCodeToEntities(
159
+ this.workflowEditorState.finalGrammarCode,
160
+ )) as Entity[];
161
+ const newEntities: EntityChange[] = [];
162
+ for (const entity of entities) {
163
+ newEntities.push({
164
+ type: EntityChangeType.CREATE,
165
+ entityPath: entity.path,
166
+ content: entity.content,
167
+ });
168
+ }
169
+ yield flowResult(
170
+ this.editorStore.graphState.loadEntityChangesToGraph(
171
+ newEntities,
172
+ undefined,
173
+ ),
174
+ );
175
+ this.editorStore.tabManagerState.openTab(
176
+ this.editorStore.globalEndToEndWorkflowState
177
+ .queryToConnectionWorkflowEditorState,
178
+ );
179
+ this.editorStore.tabManagerState.closeTab(
180
+ this.editorStore.globalEndToEndWorkflowState
181
+ .queryToConnectionWorkflowEditorState,
182
+ );
183
+ const theClass = getMappingCompatibleClasses(
184
+ getNonNullableEntry(this.workflowEditorState.workflowGraph.mappings, 0),
185
+ this.workflowEditorState.workflowGraph.classes,
186
+ )[0];
187
+ if (theClass) {
188
+ const config = new QueryBuilderConfig();
189
+ const queryBuilderState = new ClassQueryBuilderState(
190
+ this.editorStore.applicationStore,
191
+ this.editorStore.graphManagerState,
192
+ config,
193
+ );
194
+ queryBuilderState.class = theClass;
195
+ queryBuilderState.executionContextState.mapping = getNonNullableEntry(
196
+ this.workflowEditorState.workflowGraph.mappings,
197
+ 0,
198
+ );
199
+ queryBuilderState.executionContextState.runtimeValue = new RuntimePointer(
200
+ PackageableElementExplicitReference.create(
201
+ getNonNullableEntry(
202
+ this.workflowEditorState.workflowGraph.runtimes,
203
+ 0,
204
+ ),
205
+ ),
206
+ );
207
+ yield flowResult(
208
+ this.editorStore.embeddedQueryBuilderState.setEmbeddedQueryBuilderConfiguration(
209
+ {
210
+ setupQueryBuilderState: () => queryBuilderState,
211
+ actionConfigs: [],
212
+ },
213
+ ),
214
+ );
215
+ }
216
+ }
217
+
218
+ override *handleNext(): GeneratorFn<void> {
219
+ yield flowResult(this.query()).then(() => {
220
+ this.workflowEditorState.reset();
221
+ });
222
+ }
223
+ }
224
+
225
+ // step 4 - build class/mapping/runtime from database
226
+ export class DatabaseModelBuilderStepperState extends ConnectionToQueryStepperState {
227
+ workflowEditorState: QueryConnectionEndToEndWorkflowEditorState;
228
+ databaseModelBuilderState: DatabaseModelBuilderState;
229
+ editorStore: EditorStore;
230
+
231
+ constructor(
232
+ queryConnectionEndToEndWorkflowState: QueryConnectionEndToEndWorkflowEditorState,
233
+ databaseModelBuilderState: DatabaseModelBuilderState,
234
+ ) {
235
+ super();
236
+ makeObservable(this, {
237
+ workflowEditorState: false,
238
+ updateGraphWithModels: flow,
239
+ handleNext: flow,
240
+ });
241
+ this.workflowEditorState = queryConnectionEndToEndWorkflowState;
242
+ this.databaseModelBuilderState = databaseModelBuilderState;
243
+ this.editorStore = this.workflowEditorState.editorStore;
244
+ }
245
+
246
+ get label(): QUERY_CONNECTION_WORKFLOW_STEPS {
247
+ return QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_CLASS_MAPPING_RUNTIME;
248
+ }
249
+
250
+ *updateGraphWithModels(entities: Entity[]): GeneratorFn<void> {
251
+ try {
252
+ const newGraph = this.editorStore.graphManagerState.createNewGraph();
253
+ newGraph.addElement(
254
+ guaranteeNonNullable(this.workflowEditorState.packageableConnection),
255
+ this.workflowEditorState.packageableConnection?.package?.path,
256
+ );
257
+ const databaseBuilderStepperState =
258
+ this.workflowEditorState.activeStepToBaseStepperState.get(
259
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_DATABASE,
260
+ ) as DatabaseBuilderStepperState;
261
+
262
+ newGraph.addElement(
263
+ databaseBuilderStepperState.databaseBuilderWizardState
264
+ .schemaExplorerState.database,
265
+ databaseBuilderStepperState.databaseBuilderWizardState
266
+ .schemaExplorerState.database.package?.path,
267
+ );
268
+ yield flowResult(
269
+ this.editorStore.graphManagerState.graphManager.buildGraph(
270
+ newGraph,
271
+ entities,
272
+ ActionState.create(),
273
+ ),
274
+ );
275
+ // create a runtime
276
+ if (this.workflowEditorState.packageableRuntime) {
277
+ runtime_setMappings(
278
+ this.workflowEditorState.packageableRuntime.runtimeValue,
279
+ [
280
+ PackageableElementExplicitReference.create(
281
+ getNonNullableEntry(newGraph.mappings, 0),
282
+ ),
283
+ ],
284
+ );
285
+ } else {
286
+ const runtime = new PackageableRuntime(
287
+ extractElementNameFromPath(
288
+ this.workflowEditorState.targetRuntimePath,
289
+ ),
290
+ );
291
+ runtime.runtimeValue = new EngineRuntime();
292
+ runtime_addMapping(
293
+ runtime.runtimeValue,
294
+ PackageableElementExplicitReference.create(
295
+ getNonNullableEntry(newGraph.mappings, 0),
296
+ ),
297
+ );
298
+ runtime_addIdentifiedConnection(
299
+ runtime.runtimeValue,
300
+ new IdentifiedConnection(
301
+ generateIdentifiedConnectionId(runtime.runtimeValue),
302
+ guaranteeNonNullable(
303
+ this.workflowEditorState.packageableConnection,
304
+ ).connectionValue,
305
+ ),
306
+ this.workflowEditorState.editorStore.changeDetectionState
307
+ .observerContext,
308
+ );
309
+ this.workflowEditorState.packageableRuntime = runtime;
310
+ }
311
+ newGraph.addElement(
312
+ this.workflowEditorState.packageableRuntime,
313
+ extractPackagePathFromPath(this.workflowEditorState.targetRuntimePath),
314
+ );
315
+ this.workflowEditorState.workflowGraph = newGraph;
316
+ this.workflowEditorState.setRuntimeGrammarCode(
317
+ (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
318
+ [
319
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
320
+ this.workflowEditorState.packageableRuntime,
321
+ ),
322
+ ],
323
+ { pretty: true },
324
+ )) as string,
325
+ );
326
+ const connectionGrammarCode =
327
+ (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
328
+ [
329
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
330
+ guaranteeNonNullable(
331
+ this.workflowEditorState.packageableConnection,
332
+ ),
333
+ ),
334
+ ],
335
+ { pretty: true },
336
+ )) as string;
337
+ this.workflowEditorState.connectionGrammarCode = connectionGrammarCode;
338
+ } catch (error) {
339
+ assertErrorThrown(error);
340
+ this.editorStore.applicationStore.logService.error(
341
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_MODEL_BUILDER_FAILURE),
342
+ error,
343
+ );
344
+ this.editorStore.applicationStore.notificationService.notifyError(error);
345
+ }
346
+ }
347
+
348
+ override *handleNext(): GeneratorFn<void> {
349
+ this.workflowEditorState.setFinalGrammarCode(
350
+ this.databaseModelBuilderState.generatedGrammarCode
351
+ .concat(this.workflowEditorState.runtimeGrammarCode)
352
+ .concat(this.workflowEditorState.databaseGrammarCode)
353
+ .concat(this.workflowEditorState.connectionGrammarCode),
354
+ );
355
+ this.workflowEditorState.activeStepToBaseStepperState.set(
356
+ QUERY_CONNECTION_WORKFLOW_STEPS.CONFIRMATION,
357
+ new QueryConnectionConfirmationAndGrammarEditorStepperState(
358
+ this.workflowEditorState,
359
+ ),
360
+ );
361
+ }
362
+ }
363
+
364
+ // step 3 - database grammar editor
365
+ export class DatabaseGrammarEditorStepperState extends ConnectionToQueryStepperState {
366
+ workflowEditorState: QueryConnectionEndToEndWorkflowEditorState;
367
+ isCompilingGrammarCode = ActionState.create();
368
+ editorStore: EditorStore;
369
+
370
+ constructor(
371
+ queryConnectionEndToEndWorkflowState: QueryConnectionEndToEndWorkflowEditorState,
372
+ ) {
373
+ super();
374
+ makeObservable(this, {
375
+ workflowEditorState: false,
376
+ isCompilingGrammarCode: observable,
377
+ buildDatabaseModelBuilderState: action,
378
+ compileDatabaseGrammarCode: flow,
379
+ handleNext: flow,
380
+ });
381
+ this.workflowEditorState = queryConnectionEndToEndWorkflowState;
382
+ this.editorStore = this.workflowEditorState.editorStore;
383
+ }
384
+
385
+ get label(): QUERY_CONNECTION_WORKFLOW_STEPS {
386
+ return QUERY_CONNECTION_WORKFLOW_STEPS.EDIT_DATABASE;
387
+ }
388
+
389
+ *compileDatabaseGrammarCode(): GeneratorFn<void> {
390
+ try {
391
+ this.isCompilingGrammarCode.inProgress();
392
+ const databaseBuilderStepperState =
393
+ this.workflowEditorState.activeStepToBaseStepperState.get(
394
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_DATABASE,
395
+ ) as DatabaseBuilderStepperState;
396
+ const connectionValueStepperState =
397
+ this.workflowEditorState.activeStepToBaseStepperState.get(
398
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_CONNECTION,
399
+ ) as ConnectionValueStepperState;
400
+ const compilationResult = (yield flowResult(
401
+ yield this.editorStore.graphManagerState.graphManager.compileText(
402
+ this.workflowEditorState.databaseGrammarCode,
403
+ this.workflowEditorState.workflowGraph,
404
+ ),
405
+ )) as TextCompilationResult;
406
+ this.editorStore.applicationStore.notificationService.notifySuccess(
407
+ 'Compiled successfully',
408
+ );
409
+ const entities = compilationResult.entities;
410
+ const newGraph = this.editorStore.graphManagerState.createNewGraph();
411
+ yield flowResult(
412
+ this.editorStore.graphManagerState.graphManager.buildGraph(
413
+ newGraph,
414
+ entities,
415
+ ActionState.create(),
416
+ ),
417
+ );
418
+ if (newGraph.databases.length > 1) {
419
+ this.workflowEditorState.isValid = false;
420
+ this.editorStore.applicationStore.notificationService.notifyError(
421
+ 'Please make sure there is only one databse',
422
+ );
423
+ } else {
424
+ this.workflowEditorState.isValid = true;
425
+ }
426
+ // databaseBuilderWizardState.schemaExplorerState.database needs to be updated
427
+ databaseBuilderStepperState.databaseBuilderWizardState.schemaExplorerState.database =
428
+ getNonNullableEntry(newGraph.databases, 0);
429
+ this.workflowEditorState.workflowGraph = newGraph;
430
+ // start building packageableConnection based on database and adding it to current graph
431
+ const packageableConnection = new PackageableConnection(
432
+ extractElementNameFromPath(
433
+ connectionValueStepperState.targetConnectionPath,
434
+ ),
435
+ );
436
+ connectionValueStepperState.connectionValueState.connection.store =
437
+ PackageableElementExplicitReference.create(
438
+ databaseBuilderStepperState.databaseBuilderWizardState
439
+ .schemaExplorerState.database,
440
+ );
441
+ packageableConnection.package = getOrCreatePackage(
442
+ this.workflowEditorState.workflowGraph.root,
443
+ connectionValueStepperState.targetConnectionPath,
444
+ true,
445
+ new Map(),
446
+ );
447
+ packageableConnection_setConnectionValue(
448
+ packageableConnection,
449
+ connectionValueStepperState.connectionValueState.connection,
450
+ this.workflowEditorState.editorStore.changeDetectionState
451
+ .observerContext,
452
+ );
453
+ this.workflowEditorState.packageableConnection = packageableConnection;
454
+ this.workflowEditorState.workflowGraph.addElement(
455
+ packageableConnection,
456
+ extractPackagePathFromPath(
457
+ connectionValueStepperState.targetConnectionPath,
458
+ ),
459
+ );
460
+ this.workflowEditorState.setCompileError(undefined);
461
+ this.isCompilingGrammarCode.pass();
462
+ } catch (error) {
463
+ if (error instanceof ParserError || error instanceof CompilationError) {
464
+ this.workflowEditorState.setCompileError(error);
465
+ }
466
+ this.workflowEditorState.isValid = false;
467
+ assertErrorThrown(error);
468
+ this.editorStore.applicationStore.logService.error(
469
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_MODEL_BUILDER_FAILURE),
470
+ error,
471
+ );
472
+ this.editorStore.applicationStore.notificationService.notifyError(error);
473
+ this.isCompilingGrammarCode.fail();
474
+ } finally {
475
+ this.isCompilingGrammarCode.complete();
476
+ }
477
+ }
478
+
479
+ buildDatabaseModelBuilderState(): void {
480
+ const databaseBuilderStepperState =
481
+ this.workflowEditorState.activeStepToBaseStepperState.get(
482
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_DATABASE,
483
+ ) as DatabaseBuilderStepperState;
484
+ const databaseModelBuilderState = new DatabaseModelBuilderState(
485
+ this.editorStore,
486
+ databaseBuilderStepperState.databaseBuilderWizardState.schemaExplorerState.database,
487
+ false,
488
+ this.workflowEditorState.workflowGraph,
489
+ );
490
+ this.workflowEditorState.activeStepToBaseStepperState.set(
491
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_CLASS_MAPPING_RUNTIME,
492
+ new DatabaseModelBuilderStepperState(
493
+ this.workflowEditorState,
494
+ databaseModelBuilderState,
495
+ ),
496
+ );
497
+ }
498
+
499
+ override *handleNext(): GeneratorFn<void> {
500
+ yield flowResult(this.compileDatabaseGrammarCode()).then(() => {
501
+ this.buildDatabaseModelBuilderState();
502
+ });
503
+ }
504
+ }
505
+
506
+ // step 2 - build database
507
+ export class DatabaseBuilderStepperState extends ConnectionToQueryStepperState {
508
+ workflowEditorState: QueryConnectionEndToEndWorkflowEditorState;
509
+ databaseBuilderWizardState: DatabaseBuilderWizardState;
510
+ isGeneratingDatabaseGrammarCode = ActionState.create();
511
+ editorStore: EditorStore;
512
+
513
+ constructor(
514
+ queryConnectionEndToEndWorkflowState: QueryConnectionEndToEndWorkflowEditorState,
515
+ databaseBuilderWizardState: DatabaseBuilderWizardState,
516
+ ) {
517
+ super();
518
+ makeObservable(this, {
519
+ workflowEditorState: false,
520
+ databaseBuilderWizardState: observable,
521
+ isGeneratingDatabaseGrammarCode: observable,
522
+ handleNext: flow,
523
+ generateDatabaseGrammarCode: flow,
524
+ buildDatabase: flow,
525
+ });
526
+ this.workflowEditorState = queryConnectionEndToEndWorkflowState;
527
+ this.databaseBuilderWizardState = databaseBuilderWizardState;
528
+ this.editorStore = this.workflowEditorState.editorStore;
529
+ }
530
+
531
+ get label(): QUERY_CONNECTION_WORKFLOW_STEPS {
532
+ return QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_DATABASE;
533
+ }
534
+
535
+ *buildDatabase(): GeneratorFn<void> {
536
+ try {
537
+ if (!this.databaseBuilderWizardState.schemaExplorerState.treeData) {
538
+ return;
539
+ }
540
+ yield flowResult(
541
+ this.databaseBuilderWizardState.schemaExplorerState.updateDatabase(),
542
+ );
543
+ } catch (error) {
544
+ assertErrorThrown(error);
545
+ this.editorStore.applicationStore.logService.error(
546
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_BUILDER_FAILURE),
547
+ error,
548
+ );
549
+ this.editorStore.applicationStore.notificationService.notifyError(error);
550
+ this.isGeneratingDatabaseGrammarCode.fail();
551
+ }
552
+ }
553
+
554
+ *generateDatabaseGrammarCode(): GeneratorFn<void> {
555
+ try {
556
+ this.isGeneratingDatabaseGrammarCode.inProgress();
557
+ // can't use this.databaseBuilderState.databaseGrammarCode as databaseGrammarCode might not be up to date
558
+ this.workflowEditorState.setDatabaseGrammarCode(
559
+ JOIN_CODE_SYNTAX +
560
+ ((yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
561
+ [
562
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
563
+ this.databaseBuilderWizardState.schemaExplorerState.database,
564
+ ),
565
+ ],
566
+ { pretty: true },
567
+ )) as string),
568
+ );
569
+ this.isGeneratingDatabaseGrammarCode.pass();
570
+ } catch (error) {
571
+ assertErrorThrown(error);
572
+ this.editorStore.applicationStore.logService.error(
573
+ LogEvent.create(LEGEND_STUDIO_APP_EVENT.DATABASE_MODEL_BUILDER_FAILURE),
574
+ error,
575
+ );
576
+ this.editorStore.applicationStore.notificationService.notifyError(error);
577
+ this.isGeneratingDatabaseGrammarCode.fail();
578
+ }
579
+ }
580
+
581
+ override *handleNext(): GeneratorFn<void> {
582
+ yield flowResult(this.buildDatabase());
583
+ yield flowResult(this.generateDatabaseGrammarCode());
584
+ this.workflowEditorState.activeStepToBaseStepperState.set(
585
+ QUERY_CONNECTION_WORKFLOW_STEPS.EDIT_DATABASE,
586
+ new DatabaseGrammarEditorStepperState(this.workflowEditorState),
587
+ );
588
+ }
589
+ }
590
+
591
+ // step 1 - build connection
592
+ export class ConnectionValueStepperState extends ConnectionToQueryStepperState {
593
+ workflowEditorState: QueryConnectionEndToEndWorkflowEditorState;
594
+ targetConnectionPath = DEFAULT_CONNECTION_PATH;
595
+ connectionValueState: RelationalDatabaseConnectionValueState;
596
+
597
+ constructor(workflowEditorState: QueryConnectionEndToEndWorkflowEditorState) {
598
+ super();
599
+ makeObservable(this, {
600
+ workflowEditorState: false,
601
+ targetConnectionPath: observable,
602
+ connectionValueState: observable,
603
+ setTargetConnectionPath: action,
604
+ handleNext: flow,
605
+ });
606
+ this.workflowEditorState = workflowEditorState;
607
+ this.connectionValueState = new RelationalDatabaseConnectionValueState(
608
+ this.workflowEditorState.editorStore,
609
+ observe_RelationalDatabaseConnection(
610
+ this.createConnection,
611
+ this.workflowEditorState.editorStore.changeDetectionState
612
+ .observerContext,
613
+ ),
614
+ );
615
+ }
616
+
617
+ get createConnection(): RelationalDatabaseConnection {
618
+ const spec = new LocalH2DatasourceSpecification();
619
+ spec.testDataSetupSqls = [DEFAULT_H2_SQL];
620
+ const connection = new RelationalDatabaseConnection(
621
+ PackageableElementExplicitReference.create(stub_Database()),
622
+ DatabaseType.H2,
623
+ spec,
624
+ new DefaultH2AuthenticationStrategy(),
625
+ );
626
+
627
+ return connection;
628
+ }
629
+
630
+ get label(): QUERY_CONNECTION_WORKFLOW_STEPS {
631
+ return QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_CONNECTION;
632
+ }
633
+
634
+ setTargetConnectionPath(val: string): void {
635
+ this.targetConnectionPath = val;
636
+ }
637
+
638
+ override *handleNext(): GeneratorFn<void> {
639
+ const databaseBuilderWizardState = new DatabaseBuilderWizardState(
640
+ this.workflowEditorState.editorStore,
641
+ this.connectionValueState.connection,
642
+ false,
643
+ );
644
+ databaseBuilderWizardState.schemaExplorerState.setMakeTargetDatabasePathEditable(
645
+ true,
646
+ );
647
+ this.workflowEditorState.activeStepToBaseStepperState.set(
648
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_DATABASE,
649
+ new DatabaseBuilderStepperState(
650
+ this.workflowEditorState,
651
+ databaseBuilderWizardState,
652
+ ),
653
+ );
654
+ }
655
+ }
656
+
657
+ export class QueryConnectionEndToEndWorkflowEditorState extends EndToEndWorkflowEditorState {
658
+ activeStep: number;
659
+ activeStepToBaseStepperState = new Map<string, BaseStepperState>();
660
+ activeStepToStepLabel = new Map<number, string>();
661
+ targetRuntimePath = DEFAULT_RUNTIME_PATH;
662
+ packageableConnection: PackageableConnection | undefined;
663
+ packageableRuntime: PackageableRuntime | undefined;
664
+ databaseGrammarCode = '';
665
+ runtimeGrammarCode = '';
666
+ connectionGrammarCode = '';
667
+ finalGrammarCode = '';
668
+ workflowGraph: PureModel;
669
+ isValid: boolean;
670
+ compileError: ParserError | CompilationError | undefined;
671
+
672
+ constructor(editorStore: EditorStore) {
673
+ super(editorStore);
674
+ makeObservable(this, {
675
+ activeStep: observable,
676
+ activeStepToBaseStepperState: observable,
677
+ compileError: observable,
678
+ packageableRuntime: observable,
679
+ runtimeGrammarCode: observable,
680
+ connectionGrammarCode: observable,
681
+ finalGrammarCode: observable,
682
+ targetRuntimePath: observable,
683
+ isValid: observable,
684
+ packageableConnection: observable,
685
+ setActiveStep: action,
686
+ setDatabaseGrammarCode: action,
687
+ setRuntimeGrammarCode: action,
688
+ setTargetRuntimePath: action,
689
+ setFinalGrammarCode: action,
690
+ setCompileError: action,
691
+ reset: action,
692
+ updateRuntime: flow,
693
+ });
694
+ this.activeStep = 0;
695
+ this.isValid = true;
696
+ this.activeStepToBaseStepperState.set(
697
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_CONNECTION,
698
+ new ConnectionValueStepperState(this),
699
+ );
700
+ this.workflowGraph = this.editorStore.graphManagerState.createNewGraph();
701
+ this.initactiveStepToStepLabel();
702
+ }
703
+
704
+ override get label(): string {
705
+ return END_TO_END_WORKFLOWS.CREATE_QUERY_FROM_CONNECTION;
706
+ }
707
+
708
+ initactiveStepToStepLabel(): void {
709
+ Object.values(QUERY_CONNECTION_WORKFLOW_STEPS).forEach((val, index) =>
710
+ this.activeStepToStepLabel.set(index, val),
711
+ );
712
+ }
713
+
714
+ setActiveStep(step: number): void {
715
+ this.activeStep = step;
716
+ }
717
+
718
+ setTargetRuntimePath(val: string): void {
719
+ this.targetRuntimePath = val;
720
+ }
721
+
722
+ setRuntimeGrammarCode(val: string): void {
723
+ this.runtimeGrammarCode = val;
724
+ }
725
+
726
+ setDatabaseGrammarCode(code: string): void {
727
+ this.databaseGrammarCode = code;
728
+ }
729
+
730
+ setFinalGrammarCode(val: string): void {
731
+ this.finalGrammarCode = val;
732
+ }
733
+
734
+ setCompileError(err: ParserError | CompilationError | undefined): void {
735
+ this.compileError = err;
736
+ }
737
+
738
+ *updateRuntime(newPath: string): GeneratorFn<void> {
739
+ if (this.packageableRuntime) {
740
+ this.packageableRuntime.package = getOrCreatePackage(
741
+ this.workflowGraph.root,
742
+ extractPackagePathFromPath(newPath) ?? newPath,
743
+ true,
744
+ new Map(),
745
+ );
746
+ if (newPath.includes('::')) {
747
+ this.packageableRuntime.name = extractElementNameFromPath(newPath);
748
+ } else {
749
+ this.packageableRuntime.name = newPath;
750
+ }
751
+ this.packageableRuntime.name = extractElementNameFromPath(newPath);
752
+ this.setRuntimeGrammarCode(
753
+ (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
754
+ [
755
+ this.editorStore.graphManagerState.graphManager.elementToEntity(
756
+ this.packageableRuntime,
757
+ ),
758
+ ],
759
+ { pretty: true },
760
+ )) as string,
761
+ );
762
+ }
763
+ }
764
+
765
+ reset(): void {
766
+ this.activeStep = -1;
767
+ this.workflowGraph = this.editorStore.graphManagerState.createNewGraph();
768
+ this.packageableConnection = undefined;
769
+ this.packageableRuntime = undefined;
770
+ this.activeStepToBaseStepperState.set(
771
+ QUERY_CONNECTION_WORKFLOW_STEPS.CREATE_CONNECTION,
772
+ new ConnectionValueStepperState(this),
773
+ );
774
+ }
775
+ }