@finos/legend-application-data-cube 0.1.0

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 (108) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/lib/application/Core_LegendDataCubeApplicationPlugin.d.ts +23 -0
  4. package/lib/application/Core_LegendDataCubeApplicationPlugin.d.ts.map +1 -0
  5. package/lib/application/Core_LegendDataCubeApplicationPlugin.js +35 -0
  6. package/lib/application/Core_LegendDataCubeApplicationPlugin.js.map +1 -0
  7. package/lib/application/Core_LegendDataCube_LegendApplicationPlugin.d.ts +19 -0
  8. package/lib/application/Core_LegendDataCube_LegendApplicationPlugin.d.ts.map +1 -0
  9. package/lib/application/Core_LegendDataCube_LegendApplicationPlugin.js +19 -0
  10. package/lib/application/Core_LegendDataCube_LegendApplicationPlugin.js.map +1 -0
  11. package/lib/application/LegendDataCube.d.ts +26 -0
  12. package/lib/application/LegendDataCube.d.ts.map +1 -0
  13. package/lib/application/LegendDataCube.js +41 -0
  14. package/lib/application/LegendDataCube.js.map +1 -0
  15. package/lib/application/LegendDataCubeApplicationConfig.d.ts +33 -0
  16. package/lib/application/LegendDataCubeApplicationConfig.d.ts.map +1 -0
  17. package/lib/application/LegendDataCubeApplicationConfig.js +36 -0
  18. package/lib/application/LegendDataCubeApplicationConfig.js.map +1 -0
  19. package/lib/application/LegendDataCubeApplicationPlugin.d.ts +26 -0
  20. package/lib/application/LegendDataCubeApplicationPlugin.d.ts.map +1 -0
  21. package/lib/application/LegendDataCubeApplicationPlugin.js +28 -0
  22. package/lib/application/LegendDataCubeApplicationPlugin.js.map +1 -0
  23. package/lib/application/LegendDataCubePluginManager.d.ts +32 -0
  24. package/lib/application/LegendDataCubePluginManager.d.ts.map +1 -0
  25. package/lib/application/LegendDataCubePluginManager.js +47 -0
  26. package/lib/application/LegendDataCubePluginManager.js.map +1 -0
  27. package/lib/components/DataCubeEditor.d.ts +19 -0
  28. package/lib/components/DataCubeEditor.d.ts.map +1 -0
  29. package/lib/components/DataCubeEditor.js +31 -0
  30. package/lib/components/DataCubeEditor.js.map +1 -0
  31. package/lib/components/LegendDataCubeFrameworkProvider.d.ts +25 -0
  32. package/lib/components/LegendDataCubeFrameworkProvider.d.ts.map +1 -0
  33. package/lib/components/LegendDataCubeFrameworkProvider.js +31 -0
  34. package/lib/components/LegendDataCubeFrameworkProvider.js.map +1 -0
  35. package/lib/components/LegendDataCubeWebApplication.d.ts +21 -0
  36. package/lib/components/LegendDataCubeWebApplication.d.ts.map +1 -0
  37. package/lib/components/LegendDataCubeWebApplication.js +29 -0
  38. package/lib/components/LegendDataCubeWebApplication.js.map +1 -0
  39. package/lib/components/source/DataCubeSourceEditor.d.ts +22 -0
  40. package/lib/components/source/DataCubeSourceEditor.d.ts.map +1 -0
  41. package/lib/components/source/DataCubeSourceEditor.js +43 -0
  42. package/lib/components/source/DataCubeSourceEditor.js.map +1 -0
  43. package/lib/components/source/SavedQuerySourceEditor.d.ts +22 -0
  44. package/lib/components/source/SavedQuerySourceEditor.d.ts.map +1 -0
  45. package/lib/components/source/SavedQuerySourceEditor.js +25 -0
  46. package/lib/components/source/SavedQuerySourceEditor.js.map +1 -0
  47. package/lib/index.css +17 -0
  48. package/lib/index.css.map +1 -0
  49. package/lib/index.d.ts +19 -0
  50. package/lib/index.d.ts.map +1 -0
  51. package/lib/index.js +19 -0
  52. package/lib/index.js.map +1 -0
  53. package/lib/package.json +81 -0
  54. package/lib/stores/LegendDataCubeEditorStore.d.ts +44 -0
  55. package/lib/stores/LegendDataCubeEditorStore.d.ts.map +1 -0
  56. package/lib/stores/LegendDataCubeEditorStore.js +91 -0
  57. package/lib/stores/LegendDataCubeEditorStore.js.map +1 -0
  58. package/lib/stores/engine/LegendExecutionDataCubeEngine.d.ts +46 -0
  59. package/lib/stores/engine/LegendExecutionDataCubeEngine.d.ts.map +1 -0
  60. package/lib/stores/engine/LegendExecutionDataCubeEngine.js +145 -0
  61. package/lib/stores/engine/LegendExecutionDataCubeEngine.js.map +1 -0
  62. package/lib/stores/source/CubeInputSource.d.ts +38 -0
  63. package/lib/stores/source/CubeInputSource.d.ts.map +1 -0
  64. package/lib/stores/source/CubeInputSource.js +40 -0
  65. package/lib/stores/source/CubeInputSource.js.map +1 -0
  66. package/lib/stores/source/CubeInputSourceLoader.d.ts +37 -0
  67. package/lib/stores/source/CubeInputSourceLoader.d.ts.map +1 -0
  68. package/lib/stores/source/CubeInputSourceLoader.js +40 -0
  69. package/lib/stores/source/CubeInputSourceLoader.js.map +1 -0
  70. package/lib/stores/source/LegendCubeViewer.d.ts +23 -0
  71. package/lib/stores/source/LegendCubeViewer.d.ts.map +1 -0
  72. package/lib/stores/source/LegendCubeViewer.js +24 -0
  73. package/lib/stores/source/LegendCubeViewer.js.map +1 -0
  74. package/lib/stores/source/LegendDataCubeSourceBuilder.d.ts +34 -0
  75. package/lib/stores/source/LegendDataCubeSourceBuilder.d.ts.map +1 -0
  76. package/lib/stores/source/LegendDataCubeSourceBuilder.js +70 -0
  77. package/lib/stores/source/LegendDataCubeSourceBuilder.js.map +1 -0
  78. package/lib/stores/source/SavedDepotInputSourceState.d.ts +47 -0
  79. package/lib/stores/source/SavedDepotInputSourceState.d.ts.map +1 -0
  80. package/lib/stores/source/SavedDepotInputSourceState.js +77 -0
  81. package/lib/stores/source/SavedDepotInputSourceState.js.map +1 -0
  82. package/lib/stores/source/SavedQueryInputSourceState.d.ts +35 -0
  83. package/lib/stores/source/SavedQueryInputSourceState.d.ts.map +1 -0
  84. package/lib/stores/source/SavedQueryInputSourceState.js +81 -0
  85. package/lib/stores/source/SavedQueryInputSourceState.js.map +1 -0
  86. package/package.json +81 -0
  87. package/src/application/Core_LegendDataCubeApplicationPlugin.ts +38 -0
  88. package/src/application/Core_LegendDataCube_LegendApplicationPlugin.ts +19 -0
  89. package/src/application/LegendDataCube.tsx +70 -0
  90. package/src/application/LegendDataCubeApplicationConfig.ts +74 -0
  91. package/src/application/LegendDataCubeApplicationPlugin.ts +30 -0
  92. package/src/application/LegendDataCubePluginManager.ts +66 -0
  93. package/src/components/DataCubeEditor.tsx +93 -0
  94. package/src/components/LegendDataCubeFrameworkProvider.tsx +70 -0
  95. package/src/components/LegendDataCubeWebApplication.tsx +45 -0
  96. package/src/components/source/DataCubeSourceEditor.tsx +133 -0
  97. package/src/components/source/SavedQuerySourceEditor.tsx +62 -0
  98. package/src/index.ts +19 -0
  99. package/src/stores/LegendDataCubeEditorStore.ts +120 -0
  100. package/src/stores/engine/LegendExecutionDataCubeEngine.ts +257 -0
  101. package/src/stores/source/CubeInputSource.ts +47 -0
  102. package/src/stores/source/CubeInputSourceLoader.ts +56 -0
  103. package/src/stores/source/LegendCubeViewer.ts +28 -0
  104. package/src/stores/source/LegendDataCubeSourceBuilder.ts +98 -0
  105. package/src/stores/source/SavedDepotInputSourceState.ts +103 -0
  106. package/src/stores/source/SavedQueryInputSourceState.ts +144 -0
  107. package/tsconfig.json +82 -0
  108. package/tsconfig.package.json +54 -0
@@ -0,0 +1,120 @@
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
+ DEFAULT_TAB_SIZE,
19
+ type ApplicationStore,
20
+ } from '@finos/legend-application';
21
+ import type { LegendDataCubePluginManager } from '../application/LegendDataCubePluginManager.js';
22
+ import { DepotServerClient } from '@finos/legend-server-depot';
23
+ import type { LegendDataCubeApplicationConfig } from '../application/LegendDataCubeApplicationConfig.js';
24
+ import { GraphManagerState } from '@finos/legend-graph';
25
+ import { LegendDataCubeSourceBuilder } from './source/LegendDataCubeSourceBuilder.js';
26
+ import {
27
+ ActionState,
28
+ assertErrorThrown,
29
+ type GeneratorFn,
30
+ } from '@finos/legend-shared';
31
+ import { action, flow, makeObservable, observable } from 'mobx';
32
+ import { LegendCubeViewer } from './source/LegendCubeViewer.js';
33
+ import type { CubeInputSource } from './source/CubeInputSource.js';
34
+ import type { DataCubeEngine } from '@finos/legend-data-cube';
35
+
36
+ export type LegendDataCubeApplicationStore = ApplicationStore<
37
+ LegendDataCubeApplicationConfig,
38
+ LegendDataCubePluginManager
39
+ >;
40
+
41
+ export class LegendDataCubeStoreContext {
42
+ readonly applicationStore: LegendDataCubeApplicationStore;
43
+ readonly depotServerClient: DepotServerClient;
44
+ readonly graphManagerState: GraphManagerState;
45
+ initState = ActionState.create();
46
+
47
+ constructor(applicationStore: LegendDataCubeApplicationStore) {
48
+ makeObservable(this, {
49
+ initialize: flow,
50
+ initState: observable,
51
+ });
52
+ // server
53
+ this.depotServerClient = new DepotServerClient({
54
+ serverUrl: applicationStore.config.depotServerUrl,
55
+ });
56
+ this.depotServerClient.setTracerService(applicationStore.tracerService);
57
+ this.graphManagerState = new GraphManagerState(
58
+ applicationStore.pluginManager,
59
+ applicationStore.logService,
60
+ );
61
+ this.applicationStore = applicationStore;
62
+ }
63
+
64
+ *initialize(): GeneratorFn<void> {
65
+ if (!this.initState.isInInitialState) {
66
+ return;
67
+ }
68
+
69
+ try {
70
+ this.initState.inProgress();
71
+ // TODO: when we genericize the way to initialize an application page
72
+ this.applicationStore.assistantService.setIsHidden(true);
73
+
74
+ // initialize the graph manager
75
+ yield this.graphManagerState.graphManager.initialize(
76
+ {
77
+ env: this.applicationStore.config.env,
78
+ tabSize: DEFAULT_TAB_SIZE,
79
+ clientConfig: {
80
+ baseUrl: this.applicationStore.config.engineServerUrl,
81
+ queryBaseUrl: this.applicationStore.config.engineQueryServerUrl,
82
+ enableCompression: true,
83
+ },
84
+ },
85
+ {
86
+ tracerService: this.applicationStore.tracerService,
87
+ },
88
+ );
89
+ this.initState.pass();
90
+ } catch (error) {
91
+ assertErrorThrown(error);
92
+ this.applicationStore.notificationService.notifyError(error);
93
+ this.initState.fail();
94
+ }
95
+ }
96
+ }
97
+
98
+ export class LegendDataCubeStore {
99
+ readonly applicationStore: LegendDataCubeApplicationStore;
100
+ readonly context: LegendDataCubeStoreContext;
101
+ readonly pluginManager: LegendDataCubePluginManager;
102
+ sourceSelector: LegendDataCubeSourceBuilder;
103
+ cubeViewer: LegendCubeViewer | undefined;
104
+
105
+ constructor(applicationStore: LegendDataCubeApplicationStore) {
106
+ makeObservable(this, {
107
+ cubeViewer: observable,
108
+ sourceSelector: observable,
109
+ initializeView: action,
110
+ });
111
+ this.applicationStore = applicationStore;
112
+ this.pluginManager = applicationStore.pluginManager;
113
+ this.context = new LegendDataCubeStoreContext(applicationStore);
114
+ this.sourceSelector = new LegendDataCubeSourceBuilder(this.context);
115
+ }
116
+
117
+ initializeView(source: CubeInputSource, engine: DataCubeEngine): void {
118
+ this.cubeViewer = new LegendCubeViewer(source, engine);
119
+ }
120
+ }
@@ -0,0 +1,257 @@
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
+ SUPPORTED_FUNCTIONS,
19
+ V1_AppliedFunction,
20
+ V1_Lambda,
21
+ RawLambda,
22
+ RelationalExecutionActivities,
23
+ TDSExecutionResult,
24
+ V1_deserializeRawValueSpecification,
25
+ V1_deserializeValueSpecification,
26
+ V1_RawLambda,
27
+ V1_serializeValueSpecification,
28
+ type GraphManagerState,
29
+ type PureModel,
30
+ type V1_ValueSpecification,
31
+ type ParameterValue,
32
+ } from '@finos/legend-graph';
33
+ import {
34
+ _elementPtr,
35
+ _functionName,
36
+ DataCubeEngine,
37
+ DataCubeSource,
38
+ type RelationType,
39
+ DataCubeQuery,
40
+ type DataCubeInitialInput,
41
+ type CompletionItem,
42
+ _function,
43
+ DataCubeFunction,
44
+ } from '@finos/legend-data-cube';
45
+ import { guaranteeType, isNonNullable, LogService } from '@finos/legend-shared';
46
+
47
+ class QueryBuilderDataCubeSource extends DataCubeSource {
48
+ mapping?: string | undefined;
49
+ runtime!: string;
50
+ }
51
+
52
+ export class LegendExecutionDataCubeEngine extends DataCubeEngine {
53
+ readonly logService = new LogService();
54
+ readonly graphState: GraphManagerState;
55
+ readonly selectInitialQuery: RawLambda;
56
+ readonly mappingPath: string | undefined;
57
+ readonly parameterValues: ParameterValue[] | undefined;
58
+ readonly runtimePath: string;
59
+ _parameters: object | undefined;
60
+
61
+ constructor(
62
+ selectQuery: RawLambda,
63
+ parameterValues: ParameterValue[] | undefined,
64
+ mappingPath: string | undefined,
65
+ runtimePath: string,
66
+ graphManagerState: GraphManagerState,
67
+ ) {
68
+ super();
69
+ this.graphState = graphManagerState;
70
+ this.selectInitialQuery = selectQuery;
71
+ this.mappingPath = mappingPath;
72
+ this.runtimePath = runtimePath;
73
+ this.parameterValues = parameterValues;
74
+ }
75
+
76
+ get sourceLabel(): string {
77
+ return `Query Builder Report`;
78
+ }
79
+
80
+ override getInitialInput(): Promise<DataCubeInitialInput> {
81
+ return this.buildBaseQuery();
82
+ }
83
+
84
+ async buildBaseQuery(): Promise<DataCubeInitialInput> {
85
+ let srcFuncExp = V1_deserializeValueSpecification(
86
+ this.graphState.graphManager.serializeRawValueSpecification(
87
+ this.selectInitialQuery,
88
+ ),
89
+ [],
90
+ );
91
+ // We could do a further check here to ensure the experssion is an applied funciton
92
+ // this is because data cube expects an expression to be able to built further upon the queery
93
+ if (
94
+ srcFuncExp instanceof V1_Lambda &&
95
+ srcFuncExp.body.length === 1 &&
96
+ srcFuncExp.body[0]
97
+ ) {
98
+ srcFuncExp = srcFuncExp.body[0];
99
+ }
100
+ this._parameters = this.selectInitialQuery.parameters;
101
+ const fromFuncExp = new V1_AppliedFunction();
102
+ fromFuncExp.function = _functionName(SUPPORTED_FUNCTIONS.FROM);
103
+ fromFuncExp.parameters = [srcFuncExp];
104
+ if (this.mappingPath) {
105
+ fromFuncExp.parameters.push(_elementPtr(this.mappingPath));
106
+ }
107
+ if (this.runtimePath) {
108
+ fromFuncExp.parameters.push(_elementPtr(this.runtimePath));
109
+ }
110
+ const columns = (await this.getRelationalType(this.selectInitialQuery))
111
+ .columns;
112
+ const query = new DataCubeQuery();
113
+ query.query = `~[${columns.map((e) => `'${e.name}'`)}]->select()`;
114
+ const source = new QueryBuilderDataCubeSource();
115
+ source.sourceColumns = columns;
116
+ source.mapping = this.mappingPath;
117
+ source.runtime = this.runtimePath;
118
+ source.query = srcFuncExp;
119
+ return {
120
+ query,
121
+ source,
122
+ };
123
+ }
124
+
125
+ get graph(): PureModel {
126
+ return this.graphState.graph;
127
+ }
128
+
129
+ private buildRawLambdaFromValueSpec(query: V1_Lambda): RawLambda {
130
+ const json = guaranteeType(
131
+ V1_deserializeRawValueSpecification(
132
+ V1_serializeValueSpecification(query, []),
133
+ ),
134
+ V1_RawLambda,
135
+ );
136
+ return new RawLambda(json.parameters, json.body);
137
+ }
138
+
139
+ async getQueryTypeahead(
140
+ code: string,
141
+ baseQuery: V1_Lambda,
142
+ source: DataCubeSource,
143
+ ) {
144
+ const lambda = this.buildRawLambdaFromValueSpec(baseQuery);
145
+ const queryString =
146
+ await this.graphState.graphManager.lambdaToPureCode(lambda);
147
+ let codeBlock = queryString + code;
148
+ if (codeBlock[0] === '|') {
149
+ codeBlock = codeBlock.substring(1);
150
+ }
151
+ const result = await this.graphState.graphManager.getCodeComplete(
152
+ codeBlock,
153
+ this.graph,
154
+ undefined,
155
+ );
156
+ return result.completions as CompletionItem[];
157
+ }
158
+
159
+ override async parseValueSpecification(
160
+ code: string,
161
+ returnSourceInformation?: boolean,
162
+ ) {
163
+ return V1_deserializeValueSpecification(
164
+ await this.graphState.graphManager.pureCodeToValueSpecification(
165
+ code,
166
+ returnSourceInformation,
167
+ ),
168
+ [],
169
+ );
170
+ }
171
+
172
+ override getValueSpecificationCode(
173
+ value: V1_ValueSpecification,
174
+ pretty?: boolean | undefined,
175
+ ) {
176
+ return this.graphState.graphManager.valueSpecificationToPureCode(
177
+ V1_serializeValueSpecification(value, []),
178
+ pretty,
179
+ );
180
+ }
181
+
182
+ private async getRelationalType(query: RawLambda): Promise<RelationType> {
183
+ const relationType =
184
+ await this.graphState.graphManager.getLambdaRelationType(
185
+ query,
186
+ this.graph,
187
+ );
188
+ return relationType;
189
+ }
190
+
191
+ override getQueryRelationType(query: V1_Lambda, source: DataCubeSource) {
192
+ const lambda = this.buildRawLambdaFromValueSpec(query);
193
+ return this.getRelationalType(lambda);
194
+ }
195
+
196
+ override async getQueryCodeRelationReturnType(
197
+ code: string,
198
+ baseQuery: V1_ValueSpecification,
199
+ source: DataCubeSource,
200
+ ) {
201
+ const queryString =
202
+ await this.graphState.graphManager.valueSpecificationToPureCode(
203
+ V1_serializeValueSpecification(baseQuery, []),
204
+ );
205
+ const fullQuery = queryString + code;
206
+ return this.getRelationalType(
207
+ await this.graphState.graphManager.pureCodeToLambda(fullQuery),
208
+ );
209
+ }
210
+
211
+ override async executeQuery(query: V1_Lambda, source: DataCubeSource) {
212
+ const lambda = this.buildRawLambdaFromValueSpec(query);
213
+ lambda.parameters = this._parameters;
214
+ const [executionWithMetadata, queryString] = await Promise.all([
215
+ this.graphState.graphManager.runQuery(
216
+ lambda,
217
+ undefined,
218
+ undefined,
219
+ this.graph,
220
+ {
221
+ parameterValues: this.parameterValues ?? [],
222
+ },
223
+ ),
224
+ this.graphState.graphManager.lambdaToPureCode(lambda),
225
+ ]);
226
+ const expectedTDS = guaranteeType(
227
+ executionWithMetadata.executionResult,
228
+ TDSExecutionResult,
229
+ 'Query returned expected to be of tabular data set',
230
+ );
231
+ const sql = expectedTDS.activities?.[0];
232
+ let sqlString = '### NO SQL FOUND';
233
+ if (sql instanceof RelationalExecutionActivities) {
234
+ sqlString = sql.sql;
235
+ }
236
+ return {
237
+ result: expectedTDS,
238
+ executedQuery: queryString,
239
+ executedSQL: sqlString,
240
+ };
241
+ }
242
+
243
+ override buildExecutionContext(
244
+ source: DataCubeSource,
245
+ ): V1_AppliedFunction | undefined {
246
+ if (source instanceof QueryBuilderDataCubeSource) {
247
+ return _function(
248
+ DataCubeFunction.FROM,
249
+ [
250
+ source.mapping ? _elementPtr(source.mapping) : undefined,
251
+ _elementPtr(source.runtime),
252
+ ].filter(isNonNullable),
253
+ );
254
+ }
255
+ return undefined;
256
+ }
257
+ }
@@ -0,0 +1,47 @@
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 type { VersionedProjectData } from '@finos/legend-server-depot';
18
+
19
+ export abstract class CubeInputSource {}
20
+
21
+ export abstract class LegendDepotSavedSource {
22
+ project!: VersionedProjectData;
23
+ }
24
+
25
+ export class LegendSavedQuerySource extends CubeInputSource {
26
+ id: string;
27
+
28
+ constructor(id: string) {
29
+ super();
30
+ this.id = id;
31
+ }
32
+ }
33
+
34
+ export class LegendDepotService extends LegendDepotSavedSource {
35
+ service!: string;
36
+ }
37
+
38
+ export class LegendDepotFunction extends LegendDepotSavedSource {
39
+ _function!: string;
40
+ }
41
+
42
+ export class LegendDepotTable extends LegendDepotSavedSource {
43
+ database!: string;
44
+ schema!: string;
45
+ table!: string;
46
+ runtime!: string;
47
+ }
@@ -0,0 +1,56 @@
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 { ActionState, UnsupportedOperationError } from '@finos/legend-shared';
18
+ import { type CubeInputSource } from './CubeInputSource.js';
19
+ import type { DataCubeEngine } from '@finos/legend-data-cube';
20
+ import type { LegendDataCubeStoreContext } from '../LegendDataCubeEditorStore.js';
21
+
22
+ export enum DataCubeSourceType {
23
+ LEGEND_QUERY = 'Legend Query',
24
+ DEPOT_QUERY = 'Depot Query',
25
+ }
26
+
27
+ export abstract class CubeInputSourceState {
28
+ buildCubeEngineState = ActionState.create();
29
+
30
+ setupActionState = ActionState.create();
31
+
32
+ readonly context: LegendDataCubeStoreContext;
33
+
34
+ constructor(context: LegendDataCubeStoreContext) {
35
+ this.context = context;
36
+ }
37
+ abstract get label(): DataCubeSourceType;
38
+
39
+ async setup(): Promise<void> {
40
+ this.setupActionState.complete();
41
+ }
42
+
43
+ abstract buildCubeEngine(): Promise<DataCubeEngine | undefined>;
44
+
45
+ abstract process(): CubeInputSource;
46
+
47
+ abstract get isValid(): boolean;
48
+
49
+ get openActionable(): boolean {
50
+ return true;
51
+ }
52
+
53
+ static builder(context: LegendDataCubeStoreContext): CubeInputSourceState {
54
+ throw new UnsupportedOperationError('No builder');
55
+ }
56
+ }
@@ -0,0 +1,28 @@
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 type { DataCubeEngine } from '@finos/legend-data-cube';
18
+ import type { CubeInputSource } from './CubeInputSource.js';
19
+
20
+ export class LegendCubeViewer {
21
+ source: CubeInputSource;
22
+ engine: DataCubeEngine;
23
+
24
+ constructor(source: CubeInputSource, engine: DataCubeEngine) {
25
+ this.source = source;
26
+ this.engine = engine;
27
+ }
28
+ }
@@ -0,0 +1,98 @@
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 { flow, makeObservable, observable } from 'mobx';
18
+ import {
19
+ DataCubeSourceType,
20
+ type CubeInputSourceState,
21
+ } from './CubeInputSourceLoader.js';
22
+ import { SavedQueryInputSourceState } from './SavedQueryInputSourceState.js';
23
+ import type { LegendDataCubeStoreContext } from '../LegendDataCubeEditorStore.js';
24
+ import {
25
+ UnsupportedOperationError,
26
+ assertErrorThrown,
27
+ assertTrue,
28
+ guaranteeNonNullable,
29
+ type GeneratorFn,
30
+ } from '@finos/legend-shared';
31
+ import type { CubeInputSource } from './CubeInputSource.js';
32
+ import type { DataCubeEngine } from '@finos/legend-data-cube';
33
+
34
+ export class LegendDataCubeSourceBuilder {
35
+ readonly context: LegendDataCubeStoreContext;
36
+ open = false;
37
+ sourceState: CubeInputSourceState;
38
+
39
+ constructor(context: LegendDataCubeStoreContext) {
40
+ makeObservable(this, {
41
+ open: observable,
42
+ sourceState: observable,
43
+ inputSource: flow,
44
+ });
45
+ this.context = context;
46
+ this.sourceState = this.buildSource(guaranteeNonNullable(this.options[0]));
47
+ }
48
+
49
+ get options(): DataCubeSourceType[] {
50
+ return Object.values(DataCubeSourceType);
51
+ }
52
+
53
+ get currentOption(): DataCubeSourceType {
54
+ throw new UnsupportedOperationError('');
55
+ }
56
+
57
+ openModal(): void {
58
+ this.open = true;
59
+ }
60
+
61
+ close(): void {
62
+ this.open = false;
63
+ }
64
+
65
+ changeSource(source: DataCubeSourceType): void {
66
+ if (this.sourceState.label !== source) {
67
+ this.sourceState = this.buildSource(source);
68
+ }
69
+ }
70
+
71
+ buildSource(source: DataCubeSourceType): CubeInputSourceState {
72
+ if (source === DataCubeSourceType.LEGEND_QUERY) {
73
+ return SavedQueryInputSourceState.builder(this.context);
74
+ }
75
+ throw new UnsupportedOperationError('Not supported');
76
+ }
77
+
78
+ *inputSource(
79
+ callback: (source: CubeInputSource, engine: DataCubeEngine) => void,
80
+ ): GeneratorFn<void> {
81
+ try {
82
+ assertTrue(
83
+ this.sourceState.isValid,
84
+ 'Source State is in a valid state to input',
85
+ );
86
+ const engine =
87
+ (yield this.sourceState.buildCubeEngine()) as DataCubeEngine;
88
+ const source = this.sourceState.process();
89
+ callback(source, engine);
90
+ this.close();
91
+ } catch (error) {
92
+ assertErrorThrown(error);
93
+ this.context.applicationStore.notificationService.notifyError(
94
+ `Unable to import: ${this.sourceState.label}: ${error.message}`,
95
+ );
96
+ }
97
+ }
98
+ }