@finos/legend-application-data-cube 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/lib/components/builder/LegendDataCubeCreator.d.ts.map +1 -1
  2. package/lib/components/builder/LegendDataCubeCreator.js +2 -5
  3. package/lib/components/builder/LegendDataCubeCreator.js.map +1 -1
  4. package/lib/components/builder/source/AdhocQueryDataCubeSourceBuilder.d.ts +8 -0
  5. package/lib/components/builder/source/AdhocQueryDataCubeSourceBuilder.d.ts.map +1 -1
  6. package/lib/components/builder/source/AdhocQueryDataCubeSourceBuilder.js +175 -2
  7. package/lib/components/builder/source/AdhocQueryDataCubeSourceBuilder.js.map +1 -1
  8. package/lib/index.css +1 -1
  9. package/lib/package.json +1 -1
  10. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts +9 -4
  11. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts.map +1 -1
  12. package/lib/stores/LegendDataCubeDataCubeEngine.js +34 -10
  13. package/lib/stores/LegendDataCubeDataCubeEngine.js.map +1 -1
  14. package/lib/stores/builder/LegendDataCubeCreatorState.d.ts.map +1 -1
  15. package/lib/stores/builder/LegendDataCubeCreatorState.js +1 -1
  16. package/lib/stores/builder/LegendDataCubeCreatorState.js.map +1 -1
  17. package/lib/stores/builder/source/AdHocCodeEditorState.d.ts +40 -0
  18. package/lib/stores/builder/source/AdHocCodeEditorState.d.ts.map +1 -0
  19. package/lib/stores/builder/source/AdHocCodeEditorState.js +147 -0
  20. package/lib/stores/builder/source/AdHocCodeEditorState.js.map +1 -0
  21. package/lib/stores/builder/source/AdhocQueryDataCubeSourceBuilderState.d.ts +38 -1
  22. package/lib/stores/builder/source/AdhocQueryDataCubeSourceBuilderState.d.ts.map +1 -1
  23. package/lib/stores/builder/source/AdhocQueryDataCubeSourceBuilderState.js +144 -4
  24. package/lib/stores/builder/source/AdhocQueryDataCubeSourceBuilderState.js.map +1 -1
  25. package/package.json +5 -5
  26. package/src/components/builder/LegendDataCubeCreator.tsx +2 -4
  27. package/src/components/builder/source/AdhocQueryDataCubeSourceBuilder.tsx +348 -4
  28. package/src/stores/LegendDataCubeDataCubeEngine.ts +38 -12
  29. package/src/stores/builder/LegendDataCubeCreatorState.tsx +1 -0
  30. package/src/stores/builder/source/AdHocCodeEditorState.tsx +189 -0
  31. package/src/stores/builder/source/AdhocQueryDataCubeSourceBuilderState.ts +221 -4
  32. package/tsconfig.json +1 -0
@@ -14,22 +14,239 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { type PlainObject } from '@finos/legend-shared';
17
+ import {
18
+ ActionState,
19
+ IllegalStateError,
20
+ assertErrorThrown,
21
+ guaranteeNonNullable,
22
+ type PlainObject,
23
+ } from '@finos/legend-shared';
18
24
  import {
19
25
  LegendDataCubeSourceBuilderState,
20
26
  LegendDataCubeSourceBuilderType,
21
27
  } from './LegendDataCubeSourceBuilderState.js';
28
+ import { StoreProjectData } from '@finos/legend-server-depot';
29
+ import type { LegendDataCubeBuilderStore } from '../LegendDataCubeBuilderStore.js';
30
+ import { type LegendDataCubeDataCubeEngine } from '../../LegendDataCubeDataCubeEngine.js';
31
+ import type { LegendDataCubeApplicationStore } from '../../LegendDataCubeBaseStore.js';
32
+ import { action, flow, makeObservable, observable, runInAction } from 'mobx';
33
+ import {
34
+ V1_LegendSDLC,
35
+ type V1_PackageableRuntime,
36
+ V1_PureModelContextPointer,
37
+ V1_serializePureModelContext,
38
+ type V1_Mapping,
39
+ V1_Lambda,
40
+ } from '@finos/legend-graph';
41
+ import {
42
+ _lambda,
43
+ type DataCubeAlertService,
44
+ RawAdhocQueryDataCubeSource,
45
+ } from '@finos/legend-data-cube';
46
+ import { AdHocCodeEditorState } from './AdHocCodeEditorState.js';
22
47
 
23
48
  export class AdhocQueryDataCubeSourceBuilderState extends LegendDataCubeSourceBuilderState {
49
+ builderStore: LegendDataCubeBuilderStore;
50
+ projects: StoreProjectData[] = [];
51
+ currentProject?: StoreProjectData | undefined;
52
+ currentProjectVersions?: string[] | undefined;
53
+ currentVersionId?: string | undefined;
54
+ runtimes?: V1_PackageableRuntime[] | undefined;
55
+ currentRuntime?: V1_PackageableRuntime | undefined;
56
+ mappings?: V1_Mapping[] | undefined;
57
+ currentMapping?: V1_Mapping | undefined;
58
+ modelPointer: PlainObject<V1_PureModelContextPointer> | undefined;
59
+
60
+ codeEditorState: AdHocCodeEditorState;
61
+ queryCompileState = ActionState.create();
62
+ code = '';
63
+
64
+ readonly loadProjectsState = ActionState.create();
65
+
66
+ constructor(
67
+ application: LegendDataCubeApplicationStore,
68
+ engine: LegendDataCubeDataCubeEngine,
69
+ alertService: DataCubeAlertService,
70
+ builderStore: LegendDataCubeBuilderStore,
71
+ ) {
72
+ super(application, engine, alertService);
73
+ this.builderStore = builderStore;
74
+
75
+ makeObservable(this, {
76
+ loadProjects: flow,
77
+ projects: observable,
78
+ currentProject: observable,
79
+ currentProjectVersions: observable,
80
+ currentVersionId: observable,
81
+ currentRuntime: observable,
82
+ currentMapping: observable,
83
+ setCurrentProject: action,
84
+ setCurrentProjectVersions: action,
85
+ setCurrentVersionId: action,
86
+ setCurrentRuntime: action,
87
+ setCurrentMapping: action,
88
+ setMappings: action,
89
+ setRuntimes: action,
90
+ codeEditorState: observable,
91
+ // compileQueryCheck: flow,
92
+ });
93
+
94
+ this.modelPointer = this.buildPureModelContextPointer();
95
+ this.codeEditorState = new AdHocCodeEditorState(
96
+ application.alertUnhandledError,
97
+ this.modelPointer,
98
+ this.compileQueryCallback,
99
+ this.queryLambda,
100
+ engine,
101
+ );
102
+ }
103
+
104
+ setCurrentProject(val: StoreProjectData | undefined): void {
105
+ this.currentProject = val;
106
+ }
107
+
108
+ setCurrentProjectVersions(val: string[] | undefined): void {
109
+ this.currentProjectVersions = val;
110
+ }
111
+
112
+ setCurrentVersionId(val: string | undefined): void {
113
+ this.currentVersionId = val;
114
+ }
115
+
116
+ getProjects(): StoreProjectData[] {
117
+ return this.projects;
118
+ }
119
+
120
+ setCurrentRuntime(val: V1_PackageableRuntime | undefined): void {
121
+ this.currentRuntime = val;
122
+ }
123
+
124
+ setRuntimes(val: V1_PackageableRuntime[] | undefined): void {
125
+ this.runtimes = val;
126
+ }
127
+
128
+ setCurrentMapping(val: V1_Mapping | undefined): void {
129
+ runInAction(() => {
130
+ this.currentMapping = val;
131
+ });
132
+ }
133
+
134
+ setMappings(val: V1_Mapping[] | undefined): void {
135
+ this.mappings = val;
136
+ }
137
+
138
+ setModelPointer(
139
+ val: PlainObject<V1_PureModelContextPointer> | undefined,
140
+ ): void {
141
+ this.modelPointer = val;
142
+ this.codeEditorState.setModel(val);
143
+ }
144
+
145
+ *loadProjects() {
146
+ this.loadProjectsState.inProgress();
147
+ try {
148
+ this.projects = (
149
+ (yield this.builderStore.depotServerClient.getProjects()) as PlainObject<StoreProjectData>[]
150
+ ).map((v) => StoreProjectData.serialization.fromJson(v));
151
+ this.loadProjectsState.pass();
152
+ } catch (error) {
153
+ assertErrorThrown(error);
154
+ this.builderStore.application.notificationService.notifyError(error);
155
+ this.loadProjectsState.fail();
156
+ }
157
+ }
158
+
24
159
  override get label(): LegendDataCubeSourceBuilderType {
25
160
  return LegendDataCubeSourceBuilderType.ADHOC_QUERY;
26
161
  }
27
162
 
28
163
  override get isValid(): boolean {
29
- return false;
164
+ return Boolean(
165
+ this.currentProject &&
166
+ this.currentVersionId &&
167
+ this.currentRuntime &&
168
+ !this.codeEditorState.hasErrors &&
169
+ this.codeEditorState.code,
170
+ );
30
171
  }
31
172
 
32
- override generateSourceData(): Promise<PlainObject> {
33
- throw new Error('Method not implemented.');
173
+ async queryLambdaHelper(): Promise<V1_Lambda> {
174
+ const query = await this._engine.parseValueSpecification(
175
+ this.codeEditorState.code,
176
+ false,
177
+ );
178
+ const lambda = query instanceof V1_Lambda ? query : _lambda([], [query]);
179
+ return lambda;
180
+ }
181
+
182
+ queryLambda = (): V1_Lambda => {
183
+ this.queryLambdaHelper()
184
+ .then((lambda) => {
185
+ return lambda;
186
+ })
187
+ .catch((error) => {
188
+ assertErrorThrown(error);
189
+ });
190
+ return _lambda([], []);
191
+ };
192
+
193
+ compileQueryCallback = () => {
194
+ return this.compileQueryHelper();
195
+ };
196
+
197
+ async compileQueryHelper() {
198
+ const query = await this.queryLambdaHelper();
199
+ const lambda = this.builderStore.engine.serializeValueSpecification(query);
200
+ return Boolean(
201
+ (
202
+ await this.builderStore.engine._getLambdaRelationType(
203
+ lambda,
204
+ guaranteeNonNullable(this.modelPointer),
205
+ )
206
+ ).columns,
207
+ );
208
+ }
209
+
210
+ buildPureModelContextPointer():
211
+ | PlainObject<V1_PureModelContextPointer>
212
+ | undefined {
213
+ if (this.currentProject && this.currentVersionId) {
214
+ const sdlc = new V1_LegendSDLC(
215
+ this.currentProject.groupId,
216
+ this.currentProject.artifactId,
217
+ this.currentVersionId,
218
+ );
219
+ return V1_serializePureModelContext(
220
+ new V1_PureModelContextPointer(undefined, sdlc),
221
+ );
222
+ } else {
223
+ return undefined;
224
+ }
225
+ }
226
+
227
+ override async generateSourceData(): Promise<PlainObject> {
228
+ if (!this.isValid) {
229
+ throw new IllegalStateError(
230
+ `Can't generate source data: project, version, runtime, or query are not set`,
231
+ );
232
+ }
233
+
234
+ const source = new RawAdhocQueryDataCubeSource();
235
+ if (this.currentMapping) {
236
+ source.mapping = this.currentMapping.path;
237
+ }
238
+ if (this.currentRuntime && this.codeEditorState.code) {
239
+ source.runtime = this.currentRuntime.path;
240
+ source.query = this.codeEditorState.code;
241
+ const modelContextPointer = this.buildPureModelContextPointer();
242
+ if (modelContextPointer) {
243
+ source.model = modelContextPointer;
244
+ } else {
245
+ throw new IllegalStateError(
246
+ `Can't generate source data: Pure Model Context Pointer could not be made. Ensure project and version are set properly`,
247
+ );
248
+ }
249
+ }
250
+ return RawAdhocQueryDataCubeSource.serialization.toJson(source);
34
251
  }
35
252
  }
package/tsconfig.json CHANGED
@@ -94,6 +94,7 @@
94
94
  "./src/stores/builder/LegendDataCubeBuilderStore.tsx",
95
95
  "./src/stores/builder/LegendDataCubeCreatorState.tsx",
96
96
  "./src/stores/builder/LegendDataCubeLoaderState.tsx",
97
+ "./src/stores/builder/source/AdHocCodeEditorState.tsx",
97
98
  "./src/stores/builder/source/LegendDataCubeSourceLoaderState.tsx"
98
99
  ],
99
100
  "include": [