@finos/legend-application-studio 26.1.1 → 26.1.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 (188) hide show
  1. package/lib/__lib__/LegendStudioApplicationNavigationContext.d.ts +2 -1
  2. package/lib/__lib__/LegendStudioApplicationNavigationContext.d.ts.map +1 -1
  3. package/lib/__lib__/LegendStudioApplicationNavigationContext.js +1 -0
  4. package/lib/__lib__/LegendStudioApplicationNavigationContext.js.map +1 -1
  5. package/lib/__lib__/STO_Relational_LegendStudioCommand.d.ts +21 -0
  6. package/lib/__lib__/STO_Relational_LegendStudioCommand.d.ts.map +1 -0
  7. package/lib/__lib__/STO_Relational_LegendStudioCommand.js +28 -0
  8. package/lib/__lib__/STO_Relational_LegendStudioCommand.js.map +1 -0
  9. package/lib/application/LegendStudioApplicationConfig.d.ts +5 -0
  10. package/lib/application/LegendStudioApplicationConfig.d.ts.map +1 -1
  11. package/lib/application/LegendStudioApplicationConfig.js +6 -0
  12. package/lib/application/LegendStudioApplicationConfig.js.map +1 -1
  13. package/lib/components/ElementIconUtils.d.ts +13 -2
  14. package/lib/components/ElementIconUtils.d.ts.map +1 -1
  15. package/lib/components/ElementIconUtils.js +15 -6
  16. package/lib/components/ElementIconUtils.js.map +1 -1
  17. package/lib/components/editor/Editor.d.ts.map +1 -1
  18. package/lib/components/editor/Editor.js +2 -1
  19. package/lib/components/editor/Editor.js.map +1 -1
  20. package/lib/components/editor/QuickInput.d.ts +19 -0
  21. package/lib/components/editor/QuickInput.d.ts.map +1 -0
  22. package/lib/components/editor/QuickInput.js +51 -0
  23. package/lib/components/editor/QuickInput.js.map +1 -0
  24. package/lib/components/editor/__test-utils__/EditorComponentTestUtils.d.ts.map +1 -1
  25. package/lib/components/editor/__test-utils__/EditorComponentTestUtils.js +5 -1
  26. package/lib/components/editor/__test-utils__/EditorComponentTestUtils.js.map +1 -1
  27. package/lib/components/editor/command-center/ProjectSearchCommand.js +3 -3
  28. package/lib/components/editor/command-center/ProjectSearchCommand.js.map +1 -1
  29. package/lib/components/editor/editor-group/EditorGroup.d.ts.map +1 -1
  30. package/lib/components/editor/editor-group/EditorGroup.js +11 -4
  31. package/lib/components/editor/editor-group/EditorGroup.js.map +1 -1
  32. package/lib/components/editor/editor-group/FunctionEditor.d.ts.map +1 -1
  33. package/lib/components/editor/editor-group/FunctionEditor.js +30 -8
  34. package/lib/components/editor/editor-group/FunctionEditor.js.map +1 -1
  35. package/lib/components/editor/editor-group/GenerationSpecificationEditor.js +1 -1
  36. package/lib/components/editor/editor-group/GenerationSpecificationEditor.js.map +1 -1
  37. package/lib/components/editor/editor-group/GrammarTextEditor.d.ts.map +1 -1
  38. package/lib/components/editor/editor-group/GrammarTextEditor.js +99 -100
  39. package/lib/components/editor/editor-group/GrammarTextEditor.js.map +1 -1
  40. package/lib/components/editor/editor-group/INTERNAL__UnknownFunctionActivatorEdtior.d.ts.map +1 -1
  41. package/lib/components/editor/editor-group/INTERNAL__UnknownFunctionActivatorEdtior.js +5 -5
  42. package/lib/components/editor/editor-group/INTERNAL__UnknownFunctionActivatorEdtior.js.map +1 -1
  43. package/lib/components/editor/editor-group/RuntimeEditor.js +1 -1
  44. package/lib/components/editor/editor-group/RuntimeEditor.js.map +1 -1
  45. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.d.ts.map +1 -1
  46. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.js +27 -19
  47. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.js.map +1 -1
  48. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js +2 -2
  49. package/lib/components/editor/editor-group/diff-editor/EntityChangeConflictEditor.d.ts.map +1 -1
  50. package/lib/components/editor/editor-group/diff-editor/EntityChangeConflictEditor.js +5 -5
  51. package/lib/components/editor/editor-group/diff-editor/EntityChangeConflictEditor.js.map +1 -1
  52. package/lib/components/editor/editor-group/element-generation-editor/FileGenerationEditor.js +2 -2
  53. package/lib/components/editor/editor-group/element-generation-editor/FileGenerationEditor.js.map +1 -1
  54. package/lib/components/editor/editor-group/external-format-editor/DSL_ExternalFormat_BindingElementEditor.js +1 -1
  55. package/lib/components/editor/editor-group/external-format-editor/DSL_ExternalFormat_BindingElementEditor.js.map +1 -1
  56. package/lib/components/editor/editor-group/mapping-editor/ClassMappingEditor.js +1 -1
  57. package/lib/components/editor/editor-group/mapping-editor/ClassMappingEditor.js.map +1 -1
  58. package/lib/components/editor/editor-group/mapping-editor/MappingExplorer.js +2 -2
  59. package/lib/components/editor/editor-group/mapping-editor/MappingExplorer.js.map +1 -1
  60. package/lib/components/editor/editor-group/mapping-editor/PropertyMappingsEditor.js +1 -1
  61. package/lib/components/editor/editor-group/mapping-editor/PropertyMappingsEditor.js.map +1 -1
  62. package/lib/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.d.ts.map +1 -1
  63. package/lib/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.js +4 -6
  64. package/lib/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.js.map +1 -1
  65. package/lib/components/editor/editor-group/service-editor/testable/ServiceTestDataEditor.js +2 -2
  66. package/lib/components/editor/editor-group/service-editor/testable/ServiceTestDataEditor.js.map +1 -1
  67. package/lib/components/editor/editor-group/service-editor/testable/ServiceTestableEditor.d.ts.map +1 -1
  68. package/lib/components/editor/editor-group/service-editor/testable/ServiceTestableEditor.js +2 -2
  69. package/lib/components/editor/editor-group/service-editor/testable/ServiceTestableEditor.js.map +1 -1
  70. package/lib/components/editor/editor-group/uml-editor/AssociationEditor.js +2 -2
  71. package/lib/components/editor/editor-group/uml-editor/AssociationEditor.js.map +1 -1
  72. package/lib/components/editor/editor-group/uml-editor/ClassEditor.js +4 -4
  73. package/lib/components/editor/editor-group/uml-editor/ClassEditor.js.map +1 -1
  74. package/lib/components/editor/panel-group/PanelGroup.d.ts +2 -0
  75. package/lib/components/editor/panel-group/PanelGroup.d.ts.map +1 -1
  76. package/lib/components/editor/panel-group/PanelGroup.js +18 -3
  77. package/lib/components/editor/panel-group/PanelGroup.js.map +1 -1
  78. package/lib/components/editor/panel-group/SQLPlaygroundPanel.d.ts +26 -0
  79. package/lib/components/editor/panel-group/SQLPlaygroundPanel.d.ts.map +1 -0
  80. package/lib/components/editor/panel-group/SQLPlaygroundPanel.js +339 -0
  81. package/lib/components/editor/panel-group/SQLPlaygroundPanel.js.map +1 -0
  82. package/lib/components/editor/side-bar/Explorer.js +5 -6
  83. package/lib/components/editor/side-bar/Explorer.js.map +1 -1
  84. package/lib/components/editor/side-bar/testable/GlobalTestRunner.js +1 -1
  85. package/lib/components/editor/side-bar/testable/GlobalTestRunner.js.map +1 -1
  86. package/lib/components/extensions/Core_LegendStudioApplicationPlugin.d.ts.map +1 -1
  87. package/lib/components/extensions/Core_LegendStudioApplicationPlugin.js +5 -1
  88. package/lib/components/extensions/Core_LegendStudioApplicationPlugin.js.map +1 -1
  89. package/lib/index.css +2 -2
  90. package/lib/index.css.map +1 -1
  91. package/lib/package.json +2 -2
  92. package/lib/stores/editor/EditorConfig.d.ts +2 -1
  93. package/lib/stores/editor/EditorConfig.d.ts.map +1 -1
  94. package/lib/stores/editor/EditorConfig.js +1 -0
  95. package/lib/stores/editor/EditorConfig.js.map +1 -1
  96. package/lib/stores/editor/EditorStore.d.ts +8 -2
  97. package/lib/stores/editor/EditorStore.d.ts.map +1 -1
  98. package/lib/stores/editor/EditorStore.js +19 -4
  99. package/lib/stores/editor/EditorStore.js.map +1 -1
  100. package/lib/stores/editor/GraphEditFormModeState.d.ts.map +1 -1
  101. package/lib/stores/editor/GraphEditFormModeState.js +1 -0
  102. package/lib/stores/editor/GraphEditFormModeState.js.map +1 -1
  103. package/lib/stores/editor/QuickInputState.d.ts +28 -0
  104. package/lib/stores/editor/QuickInputState.d.ts.map +1 -0
  105. package/lib/stores/editor/QuickInputState.js +17 -0
  106. package/lib/stores/editor/QuickInputState.js.map +1 -0
  107. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.d.ts +22 -2
  108. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.d.ts.map +1 -1
  109. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.js +181 -4
  110. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.js.map +1 -1
  111. package/lib/stores/editor/editor-state/element-editor-state/ProtocolValueBuilderState.d.ts.map +1 -1
  112. package/lib/stores/editor/editor-state/element-editor-state/ProtocolValueBuilderState.js +6 -2
  113. package/lib/stores/editor/editor-state/element-editor-state/ProtocolValueBuilderState.js.map +1 -1
  114. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts +19 -18
  115. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts.map +1 -1
  116. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js +167 -157
  117. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js.map +1 -1
  118. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingElementDecorator.d.ts +3 -3
  119. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingElementDecorator.d.ts.map +1 -1
  120. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingElementDecorator.js +2 -2
  121. package/lib/stores/editor/editor-state/element-editor-state/mapping/MappingElementDecorator.js.map +1 -1
  122. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.d.ts +8 -9
  123. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.d.ts.map +1 -1
  124. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.js +9 -14
  125. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.js.map +1 -1
  126. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.d.ts +4 -4
  127. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.d.ts.map +1 -1
  128. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.js +7 -8
  129. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.js.map +1 -1
  130. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.d.ts +1 -1
  131. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.d.ts.map +1 -1
  132. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.js +3 -1
  133. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.js.map +1 -1
  134. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.d.ts +82 -0
  135. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.d.ts.map +1 -0
  136. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.js +328 -0
  137. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.js.map +1 -0
  138. package/lib/stores/graph-modifier/DSL_Service_GraphModifierHelper.d.ts +1 -1
  139. package/lib/stores/graph-modifier/DSL_Service_GraphModifierHelper.d.ts.map +1 -1
  140. package/lib/stores/graph-modifier/DSL_Service_GraphModifierHelper.js +8 -2
  141. package/lib/stores/graph-modifier/DSL_Service_GraphModifierHelper.js.map +1 -1
  142. package/package.json +12 -12
  143. package/src/__lib__/LegendStudioApplicationNavigationContext.ts +2 -0
  144. package/src/__lib__/STO_Relational_LegendStudioCommand.ts +30 -0
  145. package/src/application/LegendStudioApplicationConfig.ts +7 -0
  146. package/src/components/ElementIconUtils.tsx +23 -8
  147. package/src/components/editor/Editor.tsx +2 -0
  148. package/src/components/editor/QuickInput.tsx +91 -0
  149. package/src/components/editor/__test-utils__/EditorComponentTestUtils.tsx +5 -1
  150. package/src/components/editor/command-center/ProjectSearchCommand.tsx +4 -4
  151. package/src/components/editor/editor-group/EditorGroup.tsx +41 -1
  152. package/src/components/editor/editor-group/FunctionEditor.tsx +145 -5
  153. package/src/components/editor/editor-group/GenerationSpecificationEditor.tsx +1 -1
  154. package/src/components/editor/editor-group/GrammarTextEditor.tsx +134 -131
  155. package/src/components/editor/editor-group/INTERNAL__UnknownFunctionActivatorEdtior.tsx +26 -13
  156. package/src/components/editor/editor-group/RuntimeEditor.tsx +1 -1
  157. package/src/components/editor/editor-group/connection-editor/DatabaseBuilder.tsx +193 -150
  158. package/src/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.tsx +2 -2
  159. package/src/components/editor/editor-group/diff-editor/EntityChangeConflictEditor.tsx +6 -5
  160. package/src/components/editor/editor-group/element-generation-editor/FileGenerationEditor.tsx +1 -1
  161. package/src/components/editor/editor-group/external-format-editor/DSL_ExternalFormat_BindingElementEditor.tsx +1 -1
  162. package/src/components/editor/editor-group/mapping-editor/ClassMappingEditor.tsx +1 -1
  163. package/src/components/editor/editor-group/mapping-editor/MappingExplorer.tsx +2 -2
  164. package/src/components/editor/editor-group/mapping-editor/PropertyMappingsEditor.tsx +1 -1
  165. package/src/components/editor/editor-group/service-editor/ServiceExecutionQueryEditor.tsx +8 -10
  166. package/src/components/editor/editor-group/service-editor/testable/ServiceTestDataEditor.tsx +2 -2
  167. package/src/components/editor/editor-group/service-editor/testable/ServiceTestableEditor.tsx +9 -3
  168. package/src/components/editor/editor-group/uml-editor/AssociationEditor.tsx +2 -2
  169. package/src/components/editor/editor-group/uml-editor/ClassEditor.tsx +4 -4
  170. package/src/components/editor/panel-group/PanelGroup.tsx +35 -3
  171. package/src/components/editor/panel-group/SQLPlaygroundPanel.tsx +730 -0
  172. package/src/components/editor/side-bar/Explorer.tsx +5 -5
  173. package/src/components/editor/side-bar/testable/GlobalTestRunner.tsx +1 -1
  174. package/src/components/extensions/Core_LegendStudioApplicationPlugin.tsx +9 -3
  175. package/src/stores/editor/EditorConfig.ts +1 -0
  176. package/src/stores/editor/EditorStore.ts +23 -4
  177. package/src/stores/editor/GraphEditFormModeState.ts +1 -0
  178. package/src/stores/editor/QuickInputState.ts +24 -0
  179. package/src/stores/editor/editor-state/element-editor-state/FunctionEditorState.ts +317 -3
  180. package/src/stores/editor/editor-state/element-editor-state/ProtocolValueBuilderState.ts +11 -2
  181. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.ts +262 -249
  182. package/src/stores/editor/editor-state/element-editor-state/mapping/MappingElementDecorator.ts +5 -5
  183. package/src/stores/editor/editor-state/element-editor-state/service/ServiceExecutionState.ts +19 -23
  184. package/src/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.ts +9 -9
  185. package/src/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.ts +4 -2
  186. package/src/stores/editor/panel-group/SQLPlaygroundPanelState.ts +485 -0
  187. package/src/stores/graph-modifier/DSL_Service_GraphModifierHelper.ts +13 -1
  188. package/tsconfig.json +5 -0
@@ -28,16 +28,22 @@ import {
28
28
  isNonNullable,
29
29
  filterByType,
30
30
  ActionState,
31
- guaranteeType,
31
+ getNonNullableEntry,
32
32
  } from '@finos/legend-shared';
33
- import { observable, action, makeObservable, flow, flowResult } from 'mobx';
33
+ import {
34
+ observable,
35
+ action,
36
+ makeObservable,
37
+ flow,
38
+ flowResult,
39
+ computed,
40
+ } from 'mobx';
34
41
  import { LEGEND_STUDIO_APP_EVENT } from '../../../../../__lib__/LegendStudioEvent.js';
35
42
  import type { EditorStore } from '../../../EditorStore.js';
36
43
  import {
37
44
  type Schema,
38
- type PackageableElement,
39
45
  type Table,
40
- RelationalDatabaseConnection,
46
+ type RelationalDatabaseConnection,
41
47
  DatabaseBuilderInput,
42
48
  DatabasePattern,
43
49
  TargetDatabase,
@@ -50,19 +56,10 @@ import {
50
56
  getSchema,
51
57
  getNullableSchema,
52
58
  getNullableTable,
53
- PackageableConnection,
54
59
  } from '@finos/legend-graph';
55
60
  import { connection_setStore } from '../../../../graph-modifier/DSL_Mapping_GraphModifierHelper.js';
56
61
  import { GraphEditFormModeState } from '../../../GraphEditFormModeState.js';
57
62
 
58
- export const guaranteeRelationalDatabaseConnection = (
59
- val: PackageableElement | undefined,
60
- ): RelationalDatabaseConnection =>
61
- guaranteeType(
62
- guaranteeType(val, PackageableConnection).connectionValue,
63
- RelationalDatabaseConnection,
64
- );
65
-
66
63
  export abstract class DatabaseBuilderTreeNodeData implements TreeNodeData {
67
64
  isOpen?: boolean | undefined;
68
65
  id: string;
@@ -72,35 +69,52 @@ export abstract class DatabaseBuilderTreeNodeData implements TreeNodeData {
72
69
  isChecked = false;
73
70
 
74
71
  constructor(id: string, label: string, parentId: string | undefined) {
72
+ makeObservable(this, {
73
+ isChecked: observable,
74
+ setChecked: action,
75
+ });
76
+
75
77
  this.id = id;
76
78
  this.label = label;
77
79
  this.parentId = parentId;
78
80
  }
81
+
82
+ setChecked(val: boolean): void {
83
+ this.isChecked = val;
84
+ }
79
85
  }
80
86
 
81
87
  export class SchemaDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeData {
82
88
  schema: Schema;
83
89
 
84
- constructor(id: string, parentId: string | undefined, schema: Schema) {
85
- super(id, schema.name, parentId);
90
+ constructor(id: string, schema: Schema) {
91
+ super(id, schema.name, undefined);
86
92
  this.schema = schema;
87
93
  }
88
94
  }
89
95
 
90
96
  export class TableDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeData {
97
+ override parentId: string;
98
+ owner: Schema;
91
99
  table: Table;
92
100
 
93
- constructor(id: string, parentId: string | undefined, table: Table) {
101
+ constructor(id: string, parentId: string, owner: Schema, table: Table) {
94
102
  super(id, table.name, parentId);
103
+ this.parentId = parentId;
104
+ this.owner = owner;
95
105
  this.table = table;
96
106
  }
97
107
  }
98
108
 
99
109
  export class ColumnDatabaseBuilderTreeNodeData extends DatabaseBuilderTreeNodeData {
110
+ override parentId: string;
111
+ owner: Table;
100
112
  column: Column;
101
113
 
102
- constructor(id: string, parentId: string | undefined, column: Column) {
114
+ constructor(id: string, parentId: string, owner: Table, column: Column) {
103
115
  super(id, column.name, parentId);
116
+ this.parentId = parentId;
117
+ this.owner = owner;
104
118
  this.column = column;
105
119
  }
106
120
  }
@@ -110,54 +124,61 @@ export interface DatabaseBuilderTreeData
110
124
  database: Database;
111
125
  }
112
126
 
113
- const WILDCARD = '%';
127
+ const DEFAULT_DATABASE_PATH = 'store::MyDatabase';
114
128
 
115
129
  export class DatabaseBuilderState {
116
- editorStore: EditorStore;
117
- connection: RelationalDatabaseConnection;
130
+ readonly editorStore: EditorStore;
131
+ readonly connection: RelationalDatabaseConnection;
132
+ readonly isReadOnly: boolean;
133
+
118
134
  showModal = false;
119
135
  databaseGrammarCode = '';
120
136
  isBuildingDatabase = false;
121
137
  isSavingDatabase = false;
122
138
  targetDatabasePath: string;
123
139
  treeData?: DatabaseBuilderTreeData | undefined;
124
- isReadOnly: boolean;
125
140
 
126
141
  constructor(
127
142
  editorStore: EditorStore,
128
143
  connection: RelationalDatabaseConnection,
129
144
  isReadOnly: boolean,
130
145
  ) {
131
- makeObservable<
132
- DatabaseBuilderState,
133
- 'buildDatabaseFromInput' | 'buildDatabaseGrammar'
134
- >(this, {
146
+ makeObservable<DatabaseBuilderState>(this, {
135
147
  showModal: observable,
136
148
  targetDatabasePath: observable,
137
149
  isBuildingDatabase: observable,
138
150
  databaseGrammarCode: observable,
139
151
  isSavingDatabase: observable,
152
+ currentDatabase: computed,
140
153
  setTargetDatabasePath: action,
141
154
  setShowModal: action,
142
155
  setDatabaseGrammarCode: action,
143
156
  setTreeData: action,
144
157
  treeData: observable,
145
158
  onNodeSelect: flow,
146
- buildDatabaseGrammar: flow,
147
- buildDatabaseFromInput: flow,
148
- buildDatabaseWithTreeData: flow,
159
+ generateDatabase: flow,
160
+ previewDatabaseModel: flow,
149
161
  createOrUpdateDatabase: flow,
150
- fetchSchemaDefinitions: flow,
162
+ fetchDatabaseMetadata: flow,
151
163
  fetchSchemaMetadata: flow,
152
164
  fetchTableMetadata: flow,
153
165
  });
154
166
 
155
167
  this.connection = connection;
156
168
  this.editorStore = editorStore;
157
- this.targetDatabasePath = this.currentDatabase?.path ?? 'store::MyDatabase';
169
+ this.targetDatabasePath =
170
+ this.currentDatabase?.path ?? DEFAULT_DATABASE_PATH;
158
171
  this.isReadOnly = isReadOnly;
159
172
  }
160
173
 
174
+ get currentDatabase(): Database | undefined {
175
+ const store = this.connection.store.value;
176
+ if (store instanceof Database && !isStubbed_PackageableElement(store)) {
177
+ return store;
178
+ }
179
+ return undefined;
180
+ }
181
+
161
182
  setShowModal(val: boolean): void {
162
183
  this.showModal = val;
163
184
  }
@@ -206,10 +227,10 @@ export class DatabaseBuilderState {
206
227
  node: DatabaseBuilderTreeNodeData,
207
228
  treeData: DatabaseBuilderTreeData,
208
229
  ): void {
209
- node.isChecked = !node.isChecked;
230
+ node.setChecked(!node.isChecked);
210
231
  if (node instanceof SchemaDatabaseBuilderTreeNodeData) {
211
- this.getChildNodes(node, treeData)?.forEach((n) => {
212
- n.isChecked = node.isChecked;
232
+ this.getChildNodes(node, treeData)?.forEach((childNode) => {
233
+ childNode.setChecked(node.isChecked);
213
234
  });
214
235
  } else if (node instanceof TableDatabaseBuilderTreeNodeData) {
215
236
  if (node.parentId) {
@@ -220,7 +241,7 @@ export class DatabaseBuilderState {
220
241
  (e) => e.isChecked === node.isChecked,
221
242
  )
222
243
  ) {
223
- parent.isChecked = node.isChecked;
244
+ parent.setChecked(node.isChecked);
224
245
  }
225
246
  }
226
247
  }
@@ -228,46 +249,42 @@ export class DatabaseBuilderState {
228
249
  this.setTreeData({ ...treeData });
229
250
  }
230
251
 
231
- private buildNonEnrichedDbBuilderInput(
232
- schema?: string,
233
- ): DatabaseBuilderInput {
234
- const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
235
- const [packagePath, databaseName] = this.getDatabasePackageAndName();
236
- databaseBuilderInput.targetDatabase = new TargetDatabase(
237
- packagePath,
238
- databaseName,
239
- );
240
- databaseBuilderInput.config.maxTables = undefined;
241
- databaseBuilderInput.config.enrichTables = Boolean(schema);
242
- databaseBuilderInput.config.patterns = [
243
- new DatabasePattern(schema ?? WILDCARD, WILDCARD),
244
- ];
245
- return databaseBuilderInput;
246
- }
247
-
248
- *fetchSchemaDefinitions(): GeneratorFn<void> {
252
+ *fetchDatabaseMetadata(): GeneratorFn<void> {
249
253
  try {
250
254
  this.isBuildingDatabase = true;
251
- const databaseBuilderInput = this.buildNonEnrichedDbBuilderInput();
252
- const database = (yield flowResult(
253
- this.buildDatabaseFromInput(databaseBuilderInput),
255
+ const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
256
+ const [packagePath, databaseName] = this.getDatabasePackageAndName();
257
+ databaseBuilderInput.targetDatabase = new TargetDatabase(
258
+ packagePath,
259
+ databaseName,
260
+ );
261
+ databaseBuilderInput.config.maxTables = undefined;
262
+ databaseBuilderInput.config.enrichTables = false;
263
+ databaseBuilderInput.config.patterns = [
264
+ new DatabasePattern(undefined, undefined),
265
+ ];
266
+ const database = (yield this.buildIntermediateDatabase(
267
+ databaseBuilderInput,
254
268
  )) as Database;
269
+
255
270
  const rootIds: string[] = [];
256
271
  const nodes = new Map<string, DatabaseBuilderTreeNodeData>();
257
272
  database.schemas
258
273
  .slice()
259
274
  .sort((schemaA, schemaB) => schemaA.name.localeCompare(schemaB.name))
260
- .forEach((dbSchema) => {
261
- const schemaId = dbSchema.name;
275
+ .forEach((schema) => {
276
+ const schemaId = schema.name;
262
277
  rootIds.push(schemaId);
263
278
  const schemaNode = new SchemaDatabaseBuilderTreeNodeData(
264
279
  schemaId,
265
- undefined,
266
- dbSchema,
280
+ schema,
267
281
  );
268
- schemaNode.isChecked = Boolean(
269
- this.currentDatabase?.schemas.find(
270
- (cSchema) => cSchema.name === dbSchema.name,
282
+
283
+ schemaNode.setChecked(
284
+ Boolean(
285
+ this.currentDatabase?.schemas.find(
286
+ (cSchema) => cSchema.name === schema.name,
287
+ ),
271
288
  ),
272
289
  );
273
290
  nodes.set(schemaId, schemaNode);
@@ -292,13 +309,23 @@ export class DatabaseBuilderState {
292
309
  ): GeneratorFn<void> {
293
310
  try {
294
311
  this.isBuildingDatabase = true;
312
+
295
313
  const schema = schemaNode.schema;
296
- const databaseBuilderInput = this.buildNonEnrichedDbBuilderInput(
297
- schema.name,
314
+ const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
315
+ const [packagePath, databaseName] = this.getDatabasePackageAndName();
316
+ databaseBuilderInput.targetDatabase = new TargetDatabase(
317
+ packagePath,
318
+ databaseName,
298
319
  );
299
- const database = (yield flowResult(
300
- this.buildDatabaseFromInput(databaseBuilderInput),
320
+ databaseBuilderInput.config.maxTables = undefined;
321
+ databaseBuilderInput.config.enrichTables = true;
322
+ databaseBuilderInput.config.patterns = [
323
+ new DatabasePattern(schema.name, undefined),
324
+ ];
325
+ const database = (yield this.buildIntermediateDatabase(
326
+ databaseBuilderInput,
301
327
  )) as Database;
328
+
302
329
  const tables = getSchema(database, schema.name).tables;
303
330
  const childrenIds = schemaNode.childrenIds ?? [];
304
331
  schema.tables = tables;
@@ -311,6 +338,7 @@ export class DatabaseBuilderState {
311
338
  const tableNode = new TableDatabaseBuilderTreeNodeData(
312
339
  tableId,
313
340
  schemaNode.id,
341
+ schema,
314
342
  table,
315
343
  );
316
344
 
@@ -319,13 +347,15 @@ export class DatabaseBuilderState {
319
347
  this.currentDatabase,
320
348
  schema.name,
321
349
  );
322
- tableNode.isChecked = Boolean(
323
- matchingSchema
324
- ? getNullableTable(matchingSchema, table.name)
325
- : undefined,
350
+ tableNode.setChecked(
351
+ Boolean(
352
+ matchingSchema
353
+ ? getNullableTable(matchingSchema, table.name)
354
+ : undefined,
355
+ ),
326
356
  );
327
357
  } else {
328
- tableNode.isChecked = false;
358
+ tableNode.setChecked(false);
329
359
  }
330
360
 
331
361
  treeData.nodes.set(tableId, tableNode);
@@ -350,6 +380,8 @@ export class DatabaseBuilderState {
350
380
  treeData: DatabaseBuilderTreeData,
351
381
  ): GeneratorFn<void> {
352
382
  try {
383
+ this.isBuildingDatabase = true;
384
+
353
385
  const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
354
386
  const [packagePath, databaseName] = resolvePackagePathAndElementName(
355
387
  this.targetDatabasePath,
@@ -358,21 +390,46 @@ export class DatabaseBuilderState {
358
390
  packagePath,
359
391
  databaseName,
360
392
  );
393
+ const table = tableNode.table;
361
394
  const config = databaseBuilderInput.config;
362
395
  config.maxTables = undefined;
363
396
  config.enrichTables = true;
364
397
  config.enrichColumns = true;
365
398
  config.enrichPrimaryKeys = true;
366
- const table = tableNode.table;
367
399
  config.patterns = [new DatabasePattern(table.schema.name, table.name)];
368
- const database = (yield flowResult(
369
- this.buildDatabaseFromInput(databaseBuilderInput),
400
+ const database = (yield this.buildIntermediateDatabase(
401
+ databaseBuilderInput,
370
402
  )) as Database;
403
+
371
404
  const enrichedTable = database.schemas
372
405
  .find((s) => table.schema.name === s.name)
373
406
  ?.tables.find((t) => t.name === table.name);
374
407
  if (enrichedTable) {
375
- this.addColumnsNodeToTableNode(tableNode, enrichedTable, treeData);
408
+ table.primaryKey = enrichedTable.primaryKey;
409
+ const columns = enrichedTable.columns.filter(filterByType(Column));
410
+ tableNode.table.columns = columns;
411
+ tableNode.childrenIds?.forEach((childId) =>
412
+ treeData.nodes.delete(childId),
413
+ );
414
+ tableNode.childrenIds = undefined;
415
+ const childrenIds: string[] = [];
416
+ const tableId = tableNode.id;
417
+ columns
418
+ .slice()
419
+ .sort((colA, colB) => colA.name.localeCompare(colB.name))
420
+ .forEach((column) => {
421
+ const columnId = `${tableId}.${column.name}`;
422
+ const columnNode = new ColumnDatabaseBuilderTreeNodeData(
423
+ columnId,
424
+ tableId,
425
+ table,
426
+ column,
427
+ );
428
+ column.owner = tableNode.table;
429
+ treeData.nodes.set(columnId, columnNode);
430
+ addUniqueEntry(childrenIds, columnId);
431
+ });
432
+ tableNode.childrenIds = childrenIds;
376
433
  }
377
434
  } catch (error) {
378
435
  assertErrorThrown(error);
@@ -386,44 +443,6 @@ export class DatabaseBuilderState {
386
443
  }
387
444
  }
388
445
 
389
- private addColumnsNodeToTableNode(
390
- tableNode: TableDatabaseBuilderTreeNodeData,
391
- enrichedTable: Table,
392
- treeData: DatabaseBuilderTreeData,
393
- ): void {
394
- const columns = enrichedTable.columns.filter(filterByType(Column));
395
- tableNode.table.columns = columns;
396
- this.removeChildren(tableNode, treeData);
397
- const childrenIds: string[] = [];
398
- const tableId = tableNode.id;
399
- columns
400
- .slice()
401
- .sort((colA, colB) => colA.name.localeCompare(colB.name))
402
- .forEach((c) => {
403
- const columnId = `${tableId}.${c.name}`;
404
- const columnNode = new ColumnDatabaseBuilderTreeNodeData(
405
- columnId,
406
- tableId,
407
- c,
408
- );
409
- c.owner = tableNode.table;
410
- treeData.nodes.set(columnId, columnNode);
411
- addUniqueEntry(childrenIds, columnId);
412
- });
413
- tableNode.childrenIds = childrenIds;
414
- }
415
-
416
- private removeChildren(
417
- node: DatabaseBuilderTreeNodeData,
418
- treeData: DatabaseBuilderTreeData,
419
- ): void {
420
- const currentChildren = node.childrenIds;
421
- if (currentChildren) {
422
- currentChildren.forEach((c) => treeData.nodes.delete(c));
423
- node.childrenIds = undefined;
424
- }
425
- }
426
-
427
446
  private getDatabasePackageAndName(): [string, string] {
428
447
  if (this.currentDatabase) {
429
448
  return [
@@ -442,60 +461,95 @@ export class DatabaseBuilderState {
442
461
  );
443
462
  }
444
463
 
445
- *buildDatabaseWithTreeData(): GeneratorFn<void> {
464
+ async buildIntermediateDatabase(
465
+ databaseBuilderInput: DatabaseBuilderInput,
466
+ ): Promise<Database> {
467
+ const entities =
468
+ await this.editorStore.graphManagerState.graphManager.buildDatabase(
469
+ databaseBuilderInput,
470
+ );
471
+ const graph = this.editorStore.graphManagerState.createNewGraph();
472
+ await this.editorStore.graphManagerState.graphManager.buildGraph(
473
+ graph,
474
+ entities,
475
+ ActionState.create(),
476
+ );
477
+ return getNonNullableEntry(
478
+ graph.ownDatabases,
479
+ 0,
480
+ 'Expected one database to be generated from input',
481
+ );
482
+ }
483
+
484
+ *generateDatabase(): GeneratorFn<Entity> {
446
485
  try {
447
- if (this.treeData) {
448
- const dbTreeData = this.treeData;
449
- this.isBuildingDatabase = true;
450
- const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
451
- const [packagePath, databaseName] = this.getDatabasePackageAndName();
452
- databaseBuilderInput.targetDatabase = new TargetDatabase(
453
- packagePath,
454
- databaseName,
455
- );
456
- const config = databaseBuilderInput.config;
457
- config.maxTables = undefined;
458
- config.enrichTables = true;
459
- config.enrichColumns = true;
460
- config.enrichPrimaryKeys = true;
461
- dbTreeData.rootIds
462
- .map((e) => dbTreeData.nodes.get(e))
463
- .filter(isNonNullable)
464
- .forEach((schemaNode) => {
465
- if (schemaNode instanceof SchemaDatabaseBuilderTreeNodeData) {
466
- const tableNodes = this.getChildNodes(schemaNode, dbTreeData);
467
- const allChecked = tableNodes?.every((t) => t.isChecked === true);
468
- if (
469
- allChecked ||
470
- (schemaNode.isChecked && !schemaNode.childrenIds)
471
- ) {
472
- config.patterns.push(
473
- new DatabasePattern(schemaNode.schema.name, WILDCARD),
474
- );
475
- } else {
476
- tableNodes?.forEach((t) => {
477
- if (
478
- t instanceof TableDatabaseBuilderTreeNodeData &&
479
- t.isChecked
480
- ) {
481
- config.patterns.push(
482
- new DatabasePattern(schemaNode.schema.name, t.table.name),
483
- );
484
- }
485
- });
486
- }
486
+ this.isBuildingDatabase = true;
487
+
488
+ const treeData = guaranteeNonNullable(this.treeData);
489
+ const databaseBuilderInput = new DatabaseBuilderInput(this.connection);
490
+ const [packagePath, databaseName] = this.getDatabasePackageAndName();
491
+ databaseBuilderInput.targetDatabase = new TargetDatabase(
492
+ packagePath,
493
+ databaseName,
494
+ );
495
+ const config = databaseBuilderInput.config;
496
+ config.maxTables = undefined;
497
+ config.enrichTables = true;
498
+ config.enrichColumns = true;
499
+ config.enrichPrimaryKeys = true;
500
+ treeData.rootIds
501
+ .map((e) => treeData.nodes.get(e))
502
+ .filter(isNonNullable)
503
+ .forEach((schemaNode) => {
504
+ if (schemaNode instanceof SchemaDatabaseBuilderTreeNodeData) {
505
+ const tableNodes = this.getChildNodes(schemaNode, treeData);
506
+ const allChecked = tableNodes?.every((t) => t.isChecked === true);
507
+ if (
508
+ allChecked ||
509
+ (schemaNode.isChecked && !schemaNode.childrenIds)
510
+ ) {
511
+ config.patterns.push(
512
+ new DatabasePattern(schemaNode.schema.name, undefined),
513
+ );
514
+ } else {
515
+ tableNodes?.forEach((t) => {
516
+ if (
517
+ t instanceof TableDatabaseBuilderTreeNodeData &&
518
+ t.isChecked
519
+ ) {
520
+ config.patterns.push(
521
+ new DatabasePattern(schemaNode.schema.name, t.table.name),
522
+ );
523
+ }
524
+ });
487
525
  }
488
- });
489
- const entities =
490
- (yield this.editorStore.graphManagerState.graphManager.buildDatabase(
491
- databaseBuilderInput,
492
- )) as Entity[];
493
- const dbGrammar =
494
- (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
495
- entities,
496
- )) as string;
497
- this.setDatabaseGrammarCode(dbGrammar);
498
- }
526
+ }
527
+ });
528
+ const entities =
529
+ (yield this.editorStore.graphManagerState.graphManager.buildDatabase(
530
+ databaseBuilderInput,
531
+ )) as Entity[];
532
+ return getNonNullableEntry(
533
+ entities,
534
+ 0,
535
+ 'Expected a database to be generated',
536
+ );
537
+ } finally {
538
+ this.isBuildingDatabase = false;
539
+ }
540
+ }
541
+
542
+ *previewDatabaseModel(): GeneratorFn<void> {
543
+ if (!this.treeData) {
544
+ return;
545
+ }
546
+
547
+ try {
548
+ this.setDatabaseGrammarCode(
549
+ (yield this.editorStore.graphManagerState.graphManager.entitiesToPureCode(
550
+ [(yield flowResult(this.generateDatabase())) as Entity],
551
+ )) as string,
552
+ );
499
553
  } catch (error) {
500
554
  assertErrorThrown(error);
501
555
  this.editorStore.applicationStore.logService.error(
@@ -508,65 +562,26 @@ export class DatabaseBuilderState {
508
562
  }
509
563
  }
510
564
 
511
- private getSchemasFromTreeNode(tree: DatabaseBuilderTreeData): Schema[] {
512
- return Array.from(tree.nodes.values())
513
- .map((e) => {
514
- if (e instanceof SchemaDatabaseBuilderTreeNodeData) {
515
- return e.schema;
516
- }
517
- return undefined;
518
- })
519
- .filter(isNonNullable);
520
- }
521
-
522
- private *buildDatabaseGrammar(grammar: string): GeneratorFn<Database> {
523
- const entities =
524
- (yield this.editorStore.graphManagerState.graphManager.pureCodeToEntities(
525
- grammar,
526
- )) as Entity[];
527
- const dbGraph = this.editorStore.graphManagerState.createNewGraph();
528
- (yield this.editorStore.graphManagerState.graphManager.buildGraph(
529
- dbGraph,
530
- entities,
531
- ActionState.create(),
532
- )) as Entity[];
533
- assertTrue(
534
- dbGraph.ownDatabases.length === 1,
535
- 'Expected one database to be generated from grammar',
536
- );
537
- return dbGraph.ownDatabases[0] as Database;
538
- }
539
-
540
- private *buildDatabaseFromInput(
541
- databaseBuilderInput: DatabaseBuilderInput,
542
- ): GeneratorFn<Database> {
543
- const entities =
544
- (yield this.editorStore.graphManagerState.graphManager.buildDatabase(
545
- databaseBuilderInput,
546
- )) as Entity[];
547
- const dbGraph = this.editorStore.graphManagerState.createNewGraph();
548
- (yield this.editorStore.graphManagerState.graphManager.buildGraph(
549
- dbGraph,
550
- entities,
551
- ActionState.create(),
552
- )) as Entity[];
553
- assertTrue(
554
- dbGraph.ownDatabases.length === 1,
555
- 'Expected one database to be generated from input',
556
- );
557
- return dbGraph.ownDatabases[0] as Database;
558
- }
559
-
560
565
  *createOrUpdateDatabase(): GeneratorFn<void> {
566
+ if (!this.treeData) {
567
+ return;
568
+ }
569
+
561
570
  try {
562
571
  this.isSavingDatabase = true;
563
- assertNonEmptyString(
564
- this.databaseGrammarCode,
565
- 'Database grammar is empty',
572
+
573
+ const graph = this.editorStore.graphManagerState.createNewGraph();
574
+ (yield this.editorStore.graphManagerState.graphManager.buildGraph(
575
+ graph,
576
+ [(yield flowResult(this.generateDatabase())) as Entity],
577
+ ActionState.create(),
578
+ )) as Entity[];
579
+ const database = getNonNullableEntry(
580
+ graph.ownDatabases,
581
+ 0,
582
+ 'Expected one database to be generated from input',
566
583
  );
567
- const database = (yield flowResult(
568
- this.buildDatabaseGrammar(this.databaseGrammarCode),
569
- )) as Database;
584
+
570
585
  let currentDatabase: Database;
571
586
  const isUpdating = Boolean(this.currentDatabase);
572
587
  if (!this.currentDatabase) {
@@ -590,22 +605,27 @@ export class DatabaseBuilderState {
590
605
  } else {
591
606
  currentDatabase = this.currentDatabase;
592
607
  }
593
- if (this.treeData) {
594
- const schemas = this.getSchemasFromTreeNode(this.treeData);
595
- this.updateDatabase(currentDatabase, database, schemas);
596
- this.editorStore.applicationStore.notificationService.notifySuccess(
597
- `Database successfully '${isUpdating ? 'updated' : 'created'}.`,
608
+ const schemas = Array.from(this.treeData.nodes.values())
609
+ .map((schemaNode) => {
610
+ if (schemaNode instanceof SchemaDatabaseBuilderTreeNodeData) {
611
+ return schemaNode.schema;
612
+ }
613
+ return undefined;
614
+ })
615
+ .filter(isNonNullable);
616
+ this.updateDatabase(currentDatabase, database, schemas);
617
+ this.editorStore.applicationStore.notificationService.notifySuccess(
618
+ `Database successfully '${isUpdating ? 'updated' : 'created'}.`,
619
+ );
620
+ this.fetchDatabaseMetadata();
621
+ if (isUpdating) {
622
+ yield flowResult(
623
+ this.editorStore
624
+ .getGraphEditorMode(GraphEditFormModeState)
625
+ .globalCompile({
626
+ message: `Can't compile graph after editing database. Redirecting you to text mode`,
627
+ }),
598
628
  );
599
- this.fetchSchemaDefinitions();
600
- if (isUpdating) {
601
- yield flowResult(
602
- this.editorStore
603
- .getGraphEditorMode(GraphEditFormModeState)
604
- .globalCompile({
605
- message: `Can't compile graph after editing database. Redirecting you to text mode`,
606
- }),
607
- );
608
- }
609
629
  }
610
630
  this.setShowModal(false);
611
631
  } catch (error) {
@@ -622,24 +642,25 @@ export class DatabaseBuilderState {
622
642
 
623
643
  updateDatabase(
624
644
  current: Database,
625
- generatedDb: Database,
645
+ generatedDatabase: Database,
626
646
  allSchemas: Schema[],
627
647
  ): void {
628
- // remove shemas not defined
648
+ // remove undefined schemas
629
649
  current.schemas = current.schemas.filter((schema) => {
630
650
  if (
631
- allSchemas.find((c) => c.name === schema.name) &&
632
- !generatedDb.schemas.find((c) => c.name === schema.name)
651
+ allSchemas.find((item) => item.name === schema.name) &&
652
+ !generatedDatabase.schemas.find((c) => c.name === schema.name)
633
653
  ) {
634
654
  return false;
635
655
  }
636
656
  return true;
637
657
  });
658
+
638
659
  // update existing schemas
639
- generatedDb.schemas.forEach((schema) => {
660
+ generatedDatabase.schemas.forEach((schema) => {
640
661
  (schema as Writable<Schema>)._OWNER = current;
641
662
  const currentSchemaIndex = current.schemas.findIndex(
642
- (c) => c.name === schema.name,
663
+ (item) => item.name === schema.name,
643
664
  );
644
665
  if (currentSchemaIndex !== -1) {
645
666
  current.schemas[currentSchemaIndex] = schema;
@@ -648,12 +669,4 @@ export class DatabaseBuilderState {
648
669
  }
649
670
  });
650
671
  }
651
-
652
- get currentDatabase(): Database | undefined {
653
- const store = this.connection.store.value;
654
- if (store instanceof Database && !isStubbed_PackageableElement(store)) {
655
- return store;
656
- }
657
- return undefined;
658
- }
659
672
  }