@finos/legend-application-studio 27.1.0 → 27.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 (156) hide show
  1. package/lib/__lib__/LegendStudioEvent.d.ts +1 -0
  2. package/lib/__lib__/LegendStudioEvent.d.ts.map +1 -1
  3. package/lib/__lib__/LegendStudioEvent.js +1 -0
  4. package/lib/__lib__/LegendStudioEvent.js.map +1 -1
  5. package/lib/components/editor/editor-group/FunctionEditor.d.ts.map +1 -1
  6. package/lib/components/editor/editor-group/FunctionEditor.js +28 -24
  7. package/lib/components/editor/editor-group/FunctionEditor.js.map +1 -1
  8. package/lib/components/editor/editor-group/connection-editor/{DatabaseBuilder.d.ts → DatabaseBuilderWizard.d.ts} +4 -11
  9. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.d.ts.map +1 -0
  10. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.js +48 -0
  11. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.js.map +1 -0
  12. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.d.ts +32 -0
  13. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.d.ts.map +1 -0
  14. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.js +99 -0
  15. package/lib/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.js.map +1 -0
  16. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js +1 -1
  17. package/lib/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.js.map +1 -1
  18. package/lib/components/editor/editor-group/data-editor/EmbeddedDataEditor.d.ts.map +1 -1
  19. package/lib/components/editor/editor-group/data-editor/EmbeddedDataEditor.js +5 -4
  20. package/lib/components/editor/editor-group/data-editor/EmbeddedDataEditor.js.map +1 -1
  21. package/lib/components/editor/editor-group/data-editor/RelationalCSVDataEditor.d.ts.map +1 -1
  22. package/lib/components/editor/editor-group/data-editor/RelationalCSVDataEditor.js +62 -12
  23. package/lib/components/editor/editor-group/data-editor/RelationalCSVDataEditor.js.map +1 -1
  24. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.d.ts +1 -1
  25. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.d.ts.map +1 -1
  26. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.js +101 -137
  27. package/lib/components/editor/editor-group/mapping-editor/MappingTestableEditor.js.map +1 -1
  28. package/lib/components/editor/editor-group/testable/TestableSharedComponents.d.ts +11 -0
  29. package/lib/components/editor/editor-group/testable/TestableSharedComponents.d.ts.map +1 -1
  30. package/lib/components/editor/editor-group/testable/TestableSharedComponents.js +27 -2
  31. package/lib/components/editor/editor-group/testable/TestableSharedComponents.js.map +1 -1
  32. package/lib/components/editor/panel-group/SQLPlaygroundPanel.d.ts +0 -7
  33. package/lib/components/editor/panel-group/SQLPlaygroundPanel.d.ts.map +1 -1
  34. package/lib/components/editor/panel-group/SQLPlaygroundPanel.js +20 -77
  35. package/lib/components/editor/panel-group/SQLPlaygroundPanel.js.map +1 -1
  36. package/lib/components/editor/side-bar/Explorer.js +3 -3
  37. package/lib/components/editor/side-bar/Explorer.js.map +1 -1
  38. package/lib/components/editor/side-bar/WorkflowManager.d.ts.map +1 -1
  39. package/lib/components/editor/side-bar/WorkflowManager.js +6 -1
  40. package/lib/components/editor/side-bar/WorkflowManager.js.map +1 -1
  41. package/lib/index.css +2 -2
  42. package/lib/index.css.map +1 -1
  43. package/lib/package.json +3 -3
  44. package/lib/stores/editor/ExplorerTreeState.d.ts +4 -4
  45. package/lib/stores/editor/ExplorerTreeState.d.ts.map +1 -1
  46. package/lib/stores/editor/ExplorerTreeState.js +4 -4
  47. package/lib/stores/editor/ExplorerTreeState.js.map +1 -1
  48. package/lib/stores/editor/NewElementState.d.ts.map +1 -1
  49. package/lib/stores/editor/NewElementState.js.map +1 -1
  50. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.d.ts +12 -12
  51. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.d.ts.map +1 -1
  52. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.js +45 -46
  53. package/lib/stores/editor/editor-state/element-editor-state/FunctionEditorState.js.map +1 -1
  54. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts +20 -29
  55. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.d.ts.map +1 -1
  56. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js +60 -141
  57. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.js.map +1 -1
  58. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.d.ts +33 -0
  59. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.d.ts.map +1 -0
  60. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.js +71 -0
  61. package/lib/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.js.map +1 -0
  62. package/lib/stores/editor/editor-state/element-editor-state/data/DataEditorState.d.ts +2 -2
  63. package/lib/stores/editor/editor-state/element-editor-state/data/DataEditorState.d.ts.map +1 -1
  64. package/lib/stores/editor/editor-state/element-editor-state/data/DataEditorState.js +2 -2
  65. package/lib/stores/editor/editor-state/element-editor-state/data/DataEditorState.js.map +1 -1
  66. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.d.ts +14 -19
  67. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.d.ts.map +1 -1
  68. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.js +30 -65
  69. package/lib/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.js.map +1 -1
  70. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestableState.d.ts +56 -78
  71. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestableState.d.ts.map +1 -1
  72. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestableState.js +285 -384
  73. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestableState.js.map +1 -1
  74. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestingHelper.d.ts +23 -0
  75. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestingHelper.d.ts.map +1 -0
  76. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestingHelper.js +129 -0
  77. package/lib/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestingHelper.js.map +1 -0
  78. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceEditorState.d.ts.map +1 -1
  79. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceEditorState.js +2 -2
  80. package/lib/stores/editor/editor-state/element-editor-state/service/ServiceEditorState.js.map +1 -1
  81. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.d.ts +1 -0
  82. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.d.ts.map +1 -1
  83. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.js +12 -2
  84. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.js.map +1 -1
  85. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.d.ts.map +1 -1
  86. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.js +15 -8
  87. package/lib/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.js.map +1 -1
  88. package/lib/stores/editor/editor-state/element-editor-state/testable/TestAssertionState.d.ts +7 -4
  89. package/lib/stores/editor/editor-state/element-editor-state/testable/TestAssertionState.d.ts.map +1 -1
  90. package/lib/stores/editor/editor-state/element-editor-state/testable/TestAssertionState.js +53 -10
  91. package/lib/stores/editor/editor-state/element-editor-state/testable/TestAssertionState.js.map +1 -1
  92. package/lib/stores/editor/editor-state/element-editor-state/testable/TestableEditorState.d.ts +2 -1
  93. package/lib/stores/editor/editor-state/element-editor-state/testable/TestableEditorState.d.ts.map +1 -1
  94. package/lib/stores/editor/editor-state/element-editor-state/testable/TestableEditorState.js +20 -16
  95. package/lib/stores/editor/editor-state/element-editor-state/testable/TestableEditorState.js.map +1 -1
  96. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.d.ts +3 -48
  97. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.d.ts.map +1 -1
  98. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.js +12 -350
  99. package/lib/stores/editor/panel-group/SQLPlaygroundPanelState.js.map +1 -1
  100. package/lib/stores/editor/sidebar-state/WorkflowManagerState.d.ts +5 -0
  101. package/lib/stores/editor/sidebar-state/WorkflowManagerState.d.ts.map +1 -1
  102. package/lib/stores/editor/sidebar-state/WorkflowManagerState.js +26 -0
  103. package/lib/stores/editor/sidebar-state/WorkflowManagerState.js.map +1 -1
  104. package/lib/stores/editor/sidebar-state/testable/GlobalTestRunnerState.d.ts +1 -1
  105. package/lib/stores/editor/sidebar-state/testable/GlobalTestRunnerState.d.ts.map +1 -1
  106. package/lib/stores/editor/sidebar-state/testable/GlobalTestRunnerState.js +3 -0
  107. package/lib/stores/editor/sidebar-state/testable/GlobalTestRunnerState.js.map +1 -1
  108. package/lib/stores/editor/utils/MockDataUtils.d.ts.map +1 -1
  109. package/lib/stores/editor/utils/MockDataUtils.js +3 -0
  110. package/lib/stores/editor/utils/MockDataUtils.js.map +1 -1
  111. package/lib/stores/editor/utils/TestableUtils.d.ts +11 -1
  112. package/lib/stores/editor/utils/TestableUtils.d.ts.map +1 -1
  113. package/lib/stores/editor/utils/TestableUtils.js +50 -1
  114. package/lib/stores/editor/utils/TestableUtils.js.map +1 -1
  115. package/lib/stores/graph-modifier/DSL_Mapping_GraphModifierHelper.d.ts +5 -4
  116. package/lib/stores/graph-modifier/DSL_Mapping_GraphModifierHelper.d.ts.map +1 -1
  117. package/lib/stores/graph-modifier/DSL_Mapping_GraphModifierHelper.js +4 -1
  118. package/lib/stores/graph-modifier/DSL_Mapping_GraphModifierHelper.js.map +1 -1
  119. package/package.json +9 -9
  120. package/src/__lib__/LegendStudioEvent.ts +1 -1
  121. package/src/components/editor/editor-group/FunctionEditor.tsx +133 -118
  122. package/src/components/editor/editor-group/connection-editor/DatabaseBuilderWizard.tsx +191 -0
  123. package/src/components/editor/editor-group/connection-editor/DatabaseSchemaExplorer.tsx +227 -0
  124. package/src/components/editor/editor-group/connection-editor/RelationalDatabaseConnectionEditor.tsx +1 -1
  125. package/src/components/editor/editor-group/data-editor/EmbeddedDataEditor.tsx +34 -37
  126. package/src/components/editor/editor-group/data-editor/RelationalCSVDataEditor.tsx +134 -31
  127. package/src/components/editor/editor-group/mapping-editor/MappingTestableEditor.tsx +296 -414
  128. package/src/components/editor/editor-group/testable/TestableSharedComponents.tsx +88 -3
  129. package/src/components/editor/panel-group/SQLPlaygroundPanel.tsx +47 -211
  130. package/src/components/editor/side-bar/Explorer.tsx +3 -3
  131. package/src/components/editor/side-bar/WorkflowManager.tsx +10 -0
  132. package/src/stores/editor/ExplorerTreeState.ts +6 -9
  133. package/src/stores/editor/NewElementState.ts +0 -1
  134. package/src/stores/editor/editor-state/element-editor-state/FunctionEditorState.ts +44 -50
  135. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderState.ts +88 -212
  136. package/src/stores/editor/editor-state/element-editor-state/connection/DatabaseBuilderWizardState.ts +102 -0
  137. package/src/stores/editor/editor-state/element-editor-state/data/DataEditorState.ts +7 -1
  138. package/src/stores/editor/editor-state/element-editor-state/data/EmbeddedDataState.ts +48 -77
  139. package/src/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestableState.ts +407 -617
  140. package/src/stores/editor/editor-state/element-editor-state/mapping/testable/MappingTestingHelper.ts +243 -0
  141. package/src/stores/editor/editor-state/element-editor-state/service/ServiceEditorState.ts +6 -2
  142. package/src/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestDataState.ts +18 -1
  143. package/src/stores/editor/editor-state/element-editor-state/service/testable/ServiceTestableState.ts +20 -12
  144. package/src/stores/editor/editor-state/element-editor-state/testable/TestAssertionState.ts +76 -18
  145. package/src/stores/editor/editor-state/element-editor-state/testable/TestableEditorState.ts +29 -24
  146. package/src/stores/editor/panel-group/SQLPlaygroundPanelState.ts +13 -533
  147. package/src/stores/editor/sidebar-state/WorkflowManagerState.ts +47 -0
  148. package/src/stores/editor/sidebar-state/testable/GlobalTestRunnerState.ts +4 -1
  149. package/src/stores/editor/utils/MockDataUtils.ts +2 -0
  150. package/src/stores/editor/utils/TestableUtils.ts +73 -0
  151. package/src/stores/graph-modifier/DSL_Mapping_GraphModifierHelper.ts +15 -12
  152. package/tsconfig.json +4 -1
  153. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.d.ts.map +0 -1
  154. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.js +0 -133
  155. package/lib/components/editor/editor-group/connection-editor/DatabaseBuilder.js.map +0 -1
  156. package/src/components/editor/editor-group/connection-editor/DatabaseBuilder.tsx +0 -397
@@ -0,0 +1,243 @@
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 {
18
+ LambdaFunction,
19
+ type Class,
20
+ type GraphManagerState,
21
+ type RawLambda,
22
+ type SetImplementation,
23
+ type MappingTestSuite,
24
+ type GraphFetchTree,
25
+ type MappingModelCoverageAnalysisResult,
26
+ RootGraphFetchTree,
27
+ PackageableElementExplicitReference,
28
+ FunctionType,
29
+ CORE_PURE_PATH,
30
+ Multiplicity,
31
+ buildRawLambdaFromLambdaFunction,
32
+ StoreTestData,
33
+ RelationalInstanceSetImplementation,
34
+ EmbeddedRelationalInstanceSetImplementation,
35
+ TableAlias,
36
+ RelationalCSVData,
37
+ Table,
38
+ RelationalCSVDataTable,
39
+ PureInstanceSetImplementation,
40
+ MappingTest,
41
+ ModelStore,
42
+ EntityMappedProperty,
43
+ getAllClassProperties,
44
+ getAllClassDerivedProperties,
45
+ PropertyGraphFetchTree,
46
+ PropertyExplicitReference,
47
+ } from '@finos/legend-graph';
48
+ import {
49
+ buildGetAllFunction,
50
+ buildSerialzieFunctionWithGraphFetch,
51
+ } from '@finos/legend-query-builder';
52
+ import type { EditorStore } from '../../../../EditorStore.js';
53
+ import { getMappingElementSource } from '../MappingEditorState.js';
54
+ import { createMockDataForTable } from '../../../../utils/MockDataUtils.js';
55
+ import {
56
+ DEFAULT_TEST_ASSERTION_ID,
57
+ createBareModelStoreData,
58
+ createDefaultEqualToJSONTestAssertion,
59
+ } from '../../../../utils/TestableUtils.js';
60
+ import {
61
+ assertErrorThrown,
62
+ assertTrue,
63
+ guaranteeNonNullable,
64
+ } from '@finos/legend-shared';
65
+
66
+ export const createGraphFetchRawLambda = (
67
+ mainClass: Class,
68
+ graphManagerState: GraphManagerState,
69
+ root: RootGraphFetchTree,
70
+ ): RawLambda => {
71
+ const lambdaFunction = new LambdaFunction(
72
+ new FunctionType(
73
+ PackageableElementExplicitReference.create(
74
+ graphManagerState.graph.getType(CORE_PURE_PATH.ANY),
75
+ ),
76
+ Multiplicity.ONE,
77
+ ),
78
+ );
79
+ const getAllFunction = buildGetAllFunction(mainClass, Multiplicity.ONE);
80
+ const serialize = buildSerialzieFunctionWithGraphFetch(
81
+ root,
82
+ false,
83
+ getAllFunction,
84
+ undefined,
85
+ );
86
+ lambdaFunction.expressionSequence = [serialize];
87
+ return buildRawLambdaFromLambdaFunction(lambdaFunction, graphManagerState);
88
+ };
89
+
90
+ export const createStoreBareModelStoreData = (
91
+ _class: Class,
92
+ editorStore: EditorStore,
93
+ ): StoreTestData => {
94
+ const modelStoreData = createBareModelStoreData(_class, editorStore);
95
+ const testData = new StoreTestData();
96
+ testData.data = modelStoreData;
97
+ testData.store = PackageableElementExplicitReference.create(
98
+ ModelStore.INSTANCE,
99
+ );
100
+ return testData;
101
+ };
102
+
103
+ export const generateStoreTestDataFromSetImpl = (
104
+ setImpl: SetImplementation,
105
+ editorStore: EditorStore,
106
+ tryAndMockTable?: boolean,
107
+ ): StoreTestData | undefined => {
108
+ if (
109
+ setImpl instanceof RelationalInstanceSetImplementation ||
110
+ setImpl instanceof EmbeddedRelationalInstanceSetImplementation ||
111
+ setImpl instanceof EmbeddedRelationalInstanceSetImplementation
112
+ ) {
113
+ const _table = getMappingElementSource(
114
+ setImpl,
115
+ editorStore.pluginManager.getApplicationPlugins(),
116
+ );
117
+ if (_table instanceof TableAlias) {
118
+ const relation = _table.relation.value;
119
+ const owner = relation.schema._OWNER;
120
+ const val = new RelationalCSVData();
121
+ if (tryAndMockTable && relation instanceof Table) {
122
+ const mockTable = new RelationalCSVDataTable();
123
+ const values = createMockDataForTable(relation);
124
+ mockTable.table = relation.name;
125
+ mockTable.schema = relation.schema.name;
126
+ mockTable.values = values;
127
+ val.tables.push(mockTable);
128
+ }
129
+ const testData = new StoreTestData();
130
+ testData.data = val;
131
+ testData.store = PackageableElementExplicitReference.create(owner);
132
+ return testData;
133
+ }
134
+ } else if (setImpl instanceof PureInstanceSetImplementation) {
135
+ const srcClass = setImpl.srcClass;
136
+ if (srcClass) {
137
+ return createStoreBareModelStoreData(srcClass.value, editorStore);
138
+ }
139
+ }
140
+ return undefined;
141
+ };
142
+
143
+ export const createBareMappingTest = (
144
+ id: string,
145
+ storeTestData: StoreTestData | undefined,
146
+ suite?: MappingTestSuite | undefined,
147
+ ): MappingTest => {
148
+ const mappingTest = new MappingTest();
149
+ mappingTest.id = id;
150
+ mappingTest.storeTestData = storeTestData ? [storeTestData] : [];
151
+ mappingTest.assertions = [
152
+ createDefaultEqualToJSONTestAssertion(DEFAULT_TEST_ASSERTION_ID),
153
+ ];
154
+ if (suite) {
155
+ mappingTest.__parent = suite;
156
+ suite.tests.push(mappingTest);
157
+ }
158
+ const assertion = createDefaultEqualToJSONTestAssertion(`expectedAssertion`);
159
+ mappingTest.assertions = [assertion];
160
+ assertion.parentTest = mappingTest;
161
+ return mappingTest;
162
+ };
163
+
164
+ const addPropertySubTreeIfPossible = (
165
+ rootTree: GraphFetchTree,
166
+ _class: Class,
167
+ propertyName: string,
168
+ ): PropertyGraphFetchTree | undefined => {
169
+ const property = getAllClassProperties(_class)
170
+ .concat(
171
+ // we fetch mapped derived properties without parameters
172
+ getAllClassDerivedProperties(_class).filter(
173
+ (p) => !p.parameters || !(p.parameters as object[]).length,
174
+ ),
175
+ )
176
+ .find((prop) => prop.name === propertyName);
177
+ if (property) {
178
+ const subTree = new PropertyGraphFetchTree(
179
+ PropertyExplicitReference.create(property),
180
+ undefined,
181
+ );
182
+ rootTree.subTrees.push(subTree);
183
+ return subTree;
184
+ }
185
+ return undefined;
186
+ };
187
+
188
+ export const createGraphFetchQueryFromMappingAnalysis = (
189
+ _class: Class,
190
+ graphManagerState: GraphManagerState,
191
+ mappingModelCoverageAnalysisResult:
192
+ | MappingModelCoverageAnalysisResult
193
+ | undefined,
194
+ ): RawLambda => {
195
+ try {
196
+ const anaylsis = guaranteeNonNullable(mappingModelCoverageAnalysisResult);
197
+ const mappedEntity = guaranteeNonNullable(
198
+ anaylsis.mappedEntities.find((e) => e.path === _class.path),
199
+ );
200
+ const rootTree = new RootGraphFetchTree(
201
+ PackageableElementExplicitReference.create(_class),
202
+ );
203
+ // TODO: allow complex properties
204
+ mappedEntity.properties.forEach((mapped) => {
205
+ const subTree = addPropertySubTreeIfPossible(
206
+ rootTree,
207
+ _class,
208
+ mapped.name,
209
+ );
210
+ if (mapped instanceof EntityMappedProperty && subTree) {
211
+ const entityPath = mapped.entityPath;
212
+ const entityClass =
213
+ graphManagerState.graph.getNullableClass(entityPath);
214
+ const firstLevelEntity = anaylsis.mappedEntities.find(
215
+ (e) => e.path === entityPath,
216
+ );
217
+ if (entityClass && firstLevelEntity) {
218
+ firstLevelEntity.properties.forEach((e) => {
219
+ if (!(e instanceof EntityMappedProperty)) {
220
+ addPropertySubTreeIfPossible(subTree, entityClass, e.name);
221
+ }
222
+ });
223
+ }
224
+ }
225
+ });
226
+ assertTrue(!rootTree.isEmpty);
227
+ return createGraphFetchRawLambda(_class, graphManagerState, rootTree);
228
+ } catch (error) {
229
+ assertErrorThrown(error);
230
+ const lambdaFunction = new LambdaFunction(
231
+ new FunctionType(
232
+ PackageableElementExplicitReference.create(
233
+ graphManagerState.graph.getType(CORE_PURE_PATH.ANY),
234
+ ),
235
+ Multiplicity.ONE,
236
+ ),
237
+ );
238
+ lambdaFunction.expressionSequence = [
239
+ buildGetAllFunction(_class, Multiplicity.ONE),
240
+ ];
241
+ return buildRawLambdaFromLambdaFunction(lambdaFunction, graphManagerState);
242
+ }
243
+ };
@@ -76,7 +76,9 @@ export const resolveServiceQueryReturnType = (
76
76
  service: Service,
77
77
  editorStore: EditorStore,
78
78
  ): Type | undefined => {
79
- const valueSpec = resolveServiceQueryValueSpec(service, editorStore);
79
+ const valueSpec = returnUndefOnError(() =>
80
+ resolveServiceQueryValueSpec(service, editorStore),
81
+ );
80
82
  if (valueSpec) {
81
83
  return returnUndefOnError(() => getValueSpecificationReturnType(valueSpec));
82
84
  }
@@ -87,7 +89,9 @@ export const isServiceQueryTDS = (
87
89
  service: Service,
88
90
  editorStore: EditorStore,
89
91
  ): boolean => {
90
- const valueSpec = resolveServiceQueryValueSpec(service, editorStore);
92
+ const valueSpec = returnUndefOnError(() =>
93
+ resolveServiceQueryValueSpec(service, editorStore),
94
+ );
91
95
  return Boolean(
92
96
  valueSpec
93
97
  ? valueSpecReturnTDS(valueSpec, editorStore.graphManagerState.graph)
@@ -36,6 +36,7 @@ import {
36
36
  observe_ValueSpecification,
37
37
  getAllIdentifiedConnectionsFromRuntime,
38
38
  getAllIdentifiedServiceConnections,
39
+ Database,
39
40
  } from '@finos/legend-graph';
40
41
  import {
41
42
  type GeneratorFn,
@@ -63,7 +64,10 @@ import {
63
64
  type EmbeddedDataTypeOption,
64
65
  EmbeddedDataEditorState,
65
66
  } from '../../data/DataEditorState.js';
66
- import { createEmbeddedData } from '../../data/EmbeddedDataState.js';
67
+ import {
68
+ RelationalCSVDataState,
69
+ createEmbeddedData,
70
+ } from '../../data/EmbeddedDataState.js';
67
71
  import type { ServiceTestSuiteState } from './ServiceTestableState.js';
68
72
  import { LegendStudioTelemetryHelper } from '../../../../../../__lib__/LegendStudioTelemetryHelper.js';
69
73
  import {
@@ -168,6 +172,7 @@ export class ConnectionTestDataState {
168
172
  anonymizeGeneratedData: observable,
169
173
  setAnonymizeGeneratedData: action,
170
174
  changeEmbeddedData: action,
175
+ buildEmbeddedEditorState: action,
171
176
  generateTestData: flow,
172
177
  generateTestDataForDatabaseConnection: flow,
173
178
  });
@@ -179,6 +184,7 @@ export class ConnectionTestDataState {
179
184
  connectionData.testData,
180
185
  );
181
186
  this.parametersState = new ServiceTestDataParametersState(this);
187
+ this.buildEmbeddedEditorState();
182
188
  }
183
189
  get identifiedConnection(): IdentifiedConnection | undefined {
184
190
  return this.getAllIdentifiedConnections().find(
@@ -186,6 +192,17 @@ export class ConnectionTestDataState {
186
192
  );
187
193
  }
188
194
 
195
+ buildEmbeddedEditorState(): void {
196
+ const val = this.identifiedConnection?.connection.store.value;
197
+ if (
198
+ this.embeddedEditorState.embeddedDataState instanceof
199
+ RelationalCSVDataState &&
200
+ val instanceof Database
201
+ ) {
202
+ this.embeddedEditorState.embeddedDataState.setDatabase(val);
203
+ }
204
+ }
205
+
189
206
  setUseSharedModal(val: boolean): void {
190
207
  this.useSharedModal = val;
191
208
  }
@@ -81,10 +81,10 @@ const createEmptyServiceTestSuite = (
81
81
  );
82
82
  // data
83
83
  suite.testData = new TestData();
84
- const connections = getAllIdentifiedServiceConnections(service);
85
- if (connections.length === 1) {
86
- const iVal = guaranteeNonNullable(connections[0]);
87
- const connectionValue = iVal.connection;
84
+ const identifiedConnections = getAllIdentifiedServiceConnections(service);
85
+ if (identifiedConnections.length === 1) {
86
+ const connectionVal = guaranteeNonNullable(identifiedConnections[0]);
87
+ const connectionValue = connectionVal.connection;
88
88
  const type = returnUndefOnError(() =>
89
89
  connectionValue.accept_ConnectionVisitor(
90
90
  new EmbeddedDataConnectionTypeVisitor(serviceEditorState.editorStore),
@@ -92,7 +92,7 @@ const createEmptyServiceTestSuite = (
92
92
  );
93
93
  if (type) {
94
94
  const testData = createConnectionTestData(
95
- iVal,
95
+ connectionVal,
96
96
  type,
97
97
  serviceEditorState.editorStore,
98
98
  );
@@ -341,12 +341,20 @@ export class ServiceTestableState {
341
341
  }
342
342
 
343
343
  addTestSuite(): void {
344
- const suite = createEmptyServiceTestSuite(this);
345
- service_addTestSuite(
346
- this.serviceEditorState.service,
347
- suite,
348
- this.serviceEditorState.editorStore.changeDetectionState.observerContext,
349
- );
350
- this.selectedSuiteState = new ServiceTestSuiteState(suite, this);
344
+ try {
345
+ const suite = createEmptyServiceTestSuite(this);
346
+ service_addTestSuite(
347
+ this.serviceEditorState.service,
348
+ suite,
349
+ this.serviceEditorState.editorStore.changeDetectionState
350
+ .observerContext,
351
+ );
352
+ this.selectedSuiteState = new ServiceTestSuiteState(suite, this);
353
+ } catch (error) {
354
+ assertErrorThrown(error);
355
+ this.editorStore.applicationStore.notificationService.notifyError(
356
+ `Unable to create service test suite: ${error.message}`,
357
+ );
358
+ }
351
359
  }
352
360
  }
@@ -34,8 +34,13 @@ import {
34
34
  assertErrorThrown,
35
35
  ContentType,
36
36
  UnsupportedOperationError,
37
+ assertTrue,
38
+ isNonNullable,
39
+ IllegalStateError,
40
+ guaranteeNonNullable,
41
+ guaranteeType,
37
42
  } from '@finos/legend-shared';
38
- import { action, flow, makeObservable, observable } from 'mobx';
43
+ import { action, flow, flowResult, makeObservable, observable } from 'mobx';
39
44
  import type { EditorStore } from '../../../EditorStore.js';
40
45
  import { externalFormatData_setData } from '../../../../graph-modifier/DSL_Data_GraphModifierHelper.js';
41
46
  import {
@@ -43,9 +48,10 @@ import {
43
48
  TESTABLE_RESULT,
44
49
  } from '../../../sidebar-state/testable/GlobalTestRunnerState.js';
45
50
  import type { TestableTestEditorState } from './TestableEditorState.js';
51
+ import { isTestPassing } from '../../../utils/TestableUtils.js';
46
52
 
47
53
  export enum TEST_ASSERTION_TAB {
48
- SETUP = 'SETUP',
54
+ EXPECTED = 'EXPECTED',
49
55
  RESULT = 'RESULT',
50
56
  }
51
57
 
@@ -221,11 +227,13 @@ export abstract class TestAssertionState {
221
227
  this.result = new TestAssertionResultState(editorStore, assertionState);
222
228
  }
223
229
 
224
- abstract generateExpected(status: AssertFail): void;
230
+ abstract generateExpected(status: AssertFail): boolean;
225
231
 
226
232
  abstract generateBare(): TestAssertion;
227
233
 
228
234
  abstract label(): string;
235
+
236
+ abstract get supportsGeneratingAssertion(): boolean;
229
237
  }
230
238
 
231
239
  export class EqualToJsonAssertionState extends TestAssertionState {
@@ -235,11 +243,17 @@ export class EqualToJsonAssertionState extends TestAssertionState {
235
243
  externalFormatData_setData(this.assertion.expected, val);
236
244
  }
237
245
 
238
- generateExpected(status: AssertFail): void {
246
+ override get supportsGeneratingAssertion(): boolean {
247
+ return true;
248
+ }
249
+
250
+ generateExpected(status: AssertFail): boolean {
239
251
  if (status instanceof EqualToJsonAssertFail) {
240
252
  const expected = status.actual;
241
253
  this.setExpectedValue(expected);
254
+ return true;
242
255
  }
256
+ return false;
243
257
  }
244
258
  generateBare(): TestAssertion {
245
259
  const bareAssertion = new EqualToJson();
@@ -255,11 +269,14 @@ export class EqualToJsonAssertionState extends TestAssertionState {
255
269
  }
256
270
 
257
271
  export class UnsupportedAssertionState extends TestAssertionState {
272
+ override get supportsGeneratingAssertion(): boolean {
273
+ return false;
274
+ }
258
275
  generateBare(): TestAssertion {
259
276
  throw new UnsupportedOperationError();
260
277
  }
261
- generateExpected(status: AssertFail): void {
262
- return;
278
+ generateExpected(status: AssertFail): boolean {
279
+ return false;
263
280
  }
264
281
 
265
282
  label(): string {
@@ -273,7 +290,7 @@ export class TestAssertionEditorState {
273
290
  assertionState: TestAssertionState;
274
291
  assertionResultState: TestAssertionResultState;
275
292
  assertion: TestAssertion;
276
- selectedTab = TEST_ASSERTION_TAB.SETUP;
293
+ selectedTab = TEST_ASSERTION_TAB.EXPECTED;
277
294
  generatingExpectedAction = ActionState.create();
278
295
  constructor(
279
296
  editorStore: EditorStore,
@@ -299,18 +316,59 @@ export class TestAssertionEditorState {
299
316
 
300
317
  *generateExpected(): GeneratorFn<void> {
301
318
  try {
319
+ assertTrue(
320
+ this.assertionState.supportsGeneratingAssertion,
321
+ 'Assertion does not support generation',
322
+ );
302
323
  this.generatingExpectedAction.inProgress();
303
- const bare = this.assertionState.generateBare();
304
- bare.parentTest = this.assertion.parentTest;
305
- const assertFail =
306
- (yield this.editorStore.graphManagerState.graphManager.generateExpectedResult(
307
- this.testState.testable,
308
- this.testState.test,
324
+ const result = (yield flowResult(
325
+ this.testState.fetchTestResult(),
326
+ )) as TestResult;
327
+ let testExecuted: TestExecuted;
328
+ if (result instanceof TestExecuted) {
329
+ testExecuted = result;
330
+ } else if (result instanceof MultiExecutionServiceTestResult) {
331
+ testExecuted = guaranteeNonNullable(
332
+ Array.from(result.keyIndexedTestResults.values())
333
+ .map((testResult) => {
334
+ if (testResult instanceof TestExecuted) {
335
+ return testResult;
336
+ } else if (testResult instanceof TestError) {
337
+ throw new IllegalStateError(testResult.error);
338
+ }
339
+ return undefined;
340
+ })
341
+ .filter(isNonNullable)[0],
342
+ 'Unable to derive expected result from test result',
343
+ );
344
+ } else {
345
+ throw new UnsupportedOperationError(
346
+ 'Unable to derive expected result from test result',
347
+ );
348
+ }
349
+ // if test is passing, update UI and return
350
+ // if test errors report error
351
+ if (isTestPassing(testExecuted)) {
352
+ this.testState.handleTestResult(testExecuted);
353
+ return;
354
+ } else if (testExecuted instanceof TestError) {
355
+ throw new IllegalStateError(testExecuted.error);
356
+ }
357
+ const assertionStatus = testExecuted.assertStatuses.find(
358
+ (aStatus) =>
359
+ aStatus.assertion.id === this.assertion.id &&
360
+ aStatus instanceof AssertFail,
361
+ );
362
+ const assertFail = guaranteeType(
363
+ assertionStatus,
364
+ AssertFail,
365
+ 'Unable to derive expected result from test result',
366
+ );
367
+ const generated = this.assertionState.generateExpected(assertFail);
309
368
 
310
- bare,
311
- this.editorStore.graphManagerState.graph,
312
- )) as AssertFail;
313
- this.assertionState.generateExpected(assertFail);
369
+ if (generated) {
370
+ this.setSelectedTab(TEST_ASSERTION_TAB.EXPECTED);
371
+ }
314
372
  this.generatingExpectedAction.complete();
315
373
  this.editorStore.applicationStore.notificationService.notifySuccess(
316
374
  `Expected results generated!`,
@@ -320,7 +378,7 @@ export class TestAssertionEditorState {
320
378
  this.editorStore.applicationStore.notificationService.notifyError(
321
379
  `Error generating expected result, please check data input: ${error.message}.`,
322
380
  );
323
- this.setSelectedTab(TEST_ASSERTION_TAB.SETUP);
381
+ this.setSelectedTab(TEST_ASSERTION_TAB.EXPECTED);
324
382
  this.generatingExpectedAction.fail();
325
383
  }
326
384
  }
@@ -36,7 +36,7 @@ import {
36
36
  deleteEntry,
37
37
  isNonNullable,
38
38
  } from '@finos/legend-shared';
39
- import { action, makeObservable, observable } from 'mobx';
39
+ import { action, flowResult, makeObservable, observable } from 'mobx';
40
40
  import type { EditorStore } from '../../../EditorStore.js';
41
41
  import { atomicTest_addAssertion } from '../../../../graph-modifier/Testable_GraphModifierHelper.js';
42
42
  import { createEmptyEqualToJsonAssertion } from '../../../utils/TestableUtils.js';
@@ -141,22 +141,7 @@ export class TestableTestEditorState {
141
141
  try {
142
142
  this.resetResult();
143
143
  this.runningTestAction.inProgress();
144
- const input = new RunTestsTestableInput(this.testable);
145
- const suite =
146
- this.test.__parent instanceof TestSuite
147
- ? this.test.__parent
148
- : undefined;
149
- input.unitTestIds.push(new UniqueTestId(suite, this.test));
150
- const testResults =
151
- (yield this.editorStore.graphManagerState.graphManager.runTests(
152
- [input],
153
- this.editorStore.graphManagerState.graph,
154
- )) as TestResult[];
155
- const result = guaranteeNonNullable(testResults[0]);
156
- assertTrue(
157
- result.testable === this.testable && result.atomicTest === this.test,
158
- 'Unexpected test result',
159
- );
144
+ const result = (yield flowResult(this.fetchTestResult())) as TestResult;
160
145
  this.handleTestResult(result);
161
146
  this.runningTestAction.complete();
162
147
  } catch (error) {
@@ -168,6 +153,26 @@ export class TestableTestEditorState {
168
153
  }
169
154
  }
170
155
 
156
+ // Fetches test results. Caller of test should catch the error
157
+ async fetchTestResult(): Promise<TestResult> {
158
+ const input = new RunTestsTestableInput(this.testable);
159
+ const suite =
160
+ this.test.__parent instanceof TestSuite ? this.test.__parent : undefined;
161
+ input.unitTestIds.push(new UniqueTestId(suite, this.test));
162
+ const testResults =
163
+ await this.editorStore.graphManagerState.graphManager.runTests(
164
+ [input],
165
+ this.editorStore.graphManagerState.graph,
166
+ );
167
+ const result = guaranteeNonNullable(testResults[0]);
168
+ assertTrue(
169
+ result.testable === this.testable &&
170
+ result.atomicTest.id === this.test.id,
171
+ 'Unexpected test result',
172
+ );
173
+ return result;
174
+ }
175
+
171
176
  resetResult(): void {
172
177
  this.testResultState.setResult(undefined);
173
178
  this.assertionEditorStates.forEach((assertionState) =>
@@ -220,7 +225,7 @@ export class TestableTestSuiteEditorState {
220
225
  suite: TestSuite;
221
226
  isReadOnly: boolean;
222
227
  testStates: TestableTestEditorState[] = [];
223
- isRunningTest = ActionState.create();
228
+ runningSuiteState = ActionState.create();
224
229
  selectTestState: TestableTestEditorState | undefined;
225
230
 
226
231
  constructor(
@@ -237,7 +242,7 @@ export class TestableTestSuiteEditorState {
237
242
 
238
243
  *runSuite(): GeneratorFn<void> {
239
244
  try {
240
- this.isRunningTest.inProgress();
245
+ this.runningSuiteState.inProgress();
241
246
  this.testStates.forEach((t) => t.resetResult());
242
247
  this.testStates.forEach((t) => t.runningTestAction.inProgress());
243
248
  const input = new RunTestsTestableInput(this.testable);
@@ -253,11 +258,11 @@ export class TestableTestSuiteEditorState {
253
258
  const state = this.testStates.find((t) => t.test === result.atomicTest);
254
259
  state?.handleTestResult(result);
255
260
  });
256
- this.isRunningTest.complete();
261
+ this.runningSuiteState.complete();
257
262
  } catch (error) {
258
263
  assertErrorThrown(error);
259
264
  this.editorStore.applicationStore.notificationService.notifyError(error);
260
- this.isRunningTest.fail();
265
+ this.runningSuiteState.fail();
261
266
  } finally {
262
267
  this.testStates.forEach((t) => t.runningTestAction.complete());
263
268
  }
@@ -265,7 +270,7 @@ export class TestableTestSuiteEditorState {
265
270
 
266
271
  *runFailingTests(): GeneratorFn<void> {
267
272
  try {
268
- this.isRunningTest.inProgress();
273
+ this.runningSuiteState.inProgress();
269
274
  const input = new RunTestsTestableInput(this.testable);
270
275
  input.unitTestIds = this.testStates
271
276
  .map((testState) => {
@@ -290,11 +295,11 @@ export class TestableTestSuiteEditorState {
290
295
  const state = this.testStates.find((t) => t.test === result.atomicTest);
291
296
  state?.handleTestResult(result);
292
297
  });
293
- this.isRunningTest.complete();
298
+ this.runningSuiteState.complete();
294
299
  } catch (error) {
295
300
  assertErrorThrown(error);
296
301
  this.editorStore.applicationStore.notificationService.notifyError(error);
297
- this.isRunningTest.fail();
302
+ this.runningSuiteState.fail();
298
303
  } finally {
299
304
  this.testStates.forEach((t) => t.runningTestAction.complete());
300
305
  }