@finos/legend-application-data-cube 0.7.34 → 0.7.36

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 (31) hide show
  1. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.d.ts.map +1 -1
  2. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.js +12 -0
  3. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.js.map +1 -1
  4. package/lib/components/builder/LegendDataCubeSourceViewer.js +2 -2
  5. package/lib/components/builder/LegendDataCubeSourceViewer.js.map +1 -1
  6. package/lib/components/builder/source/LakehouseConsumerDataCubeSourceBuilder.d.ts.map +1 -1
  7. package/lib/components/builder/source/LakehouseConsumerDataCubeSourceBuilder.js +72 -38
  8. package/lib/components/builder/source/LakehouseConsumerDataCubeSourceBuilder.js.map +1 -1
  9. package/lib/index.css +1 -1
  10. package/lib/package.json +1 -1
  11. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts.map +1 -1
  12. package/lib/stores/LegendDataCubeDataCubeEngine.js +30 -6
  13. package/lib/stores/LegendDataCubeDataCubeEngine.js.map +1 -1
  14. package/lib/stores/builder/LegendDataCubeCreatorState.js +1 -1
  15. package/lib/stores/builder/LegendDataCubeCreatorState.js.map +1 -1
  16. package/lib/stores/builder/source/LakehouseConsumerDataCubeSourceBuilderState.d.ts +15 -24
  17. package/lib/stores/builder/source/LakehouseConsumerDataCubeSourceBuilderState.d.ts.map +1 -1
  18. package/lib/stores/builder/source/LakehouseConsumerDataCubeSourceBuilderState.js +57 -107
  19. package/lib/stores/builder/source/LakehouseConsumerDataCubeSourceBuilderState.js.map +1 -1
  20. package/lib/stores/model/LakehouseConsumerDataCubeSource.d.ts +1 -1
  21. package/lib/stores/model/LakehouseConsumerDataCubeSource.d.ts.map +1 -1
  22. package/lib/stores/model/LakehouseConsumerDataCubeSource.js +1 -1
  23. package/lib/stores/model/LakehouseConsumerDataCubeSource.js.map +1 -1
  24. package/package.json +8 -8
  25. package/src/components/__test-utils__/LegendDataCubeStoreTestUtils.tsx +15 -0
  26. package/src/components/builder/LegendDataCubeSourceViewer.tsx +3 -3
  27. package/src/components/builder/source/LakehouseConsumerDataCubeSourceBuilder.tsx +152 -96
  28. package/src/stores/LegendDataCubeDataCubeEngine.ts +51 -8
  29. package/src/stores/builder/LegendDataCubeCreatorState.tsx +1 -1
  30. package/src/stores/builder/source/LakehouseConsumerDataCubeSourceBuilderState.ts +96 -173
  31. package/src/stores/model/LakehouseConsumerDataCubeSource.ts +1 -1
@@ -30,31 +30,25 @@ import {
30
30
  ActionState,
31
31
  assertErrorThrown,
32
32
  guaranteeNonNullable,
33
- isNonNullable,
34
- uniq,
35
33
  type GeneratorFn,
36
34
  type PlainObject,
37
35
  } from '@finos/legend-shared';
38
36
  import type { DataCubeAlertService } from '@finos/legend-data-cube';
39
37
  import type { LegendDataCubeApplicationStore } from '../../LegendDataCubeBaseStore.js';
40
38
  import type { LegendDataCubeDataCubeEngine } from '../../LegendDataCubeDataCubeEngine.js';
39
+ import { type LakehouseContractServerClient } from '@finos/legend-server-lakehouse';
41
40
  import {
42
- type LakehousePlatformServerClient,
43
- type LakehouseContractServerClient,
44
- type IngestDeploymentServerConfig,
45
- filterEnvironmentsByEntitlementsEnv,
46
- getIngestDeploymentServerConfigName,
47
- } from '@finos/legend-server-lakehouse';
48
- import { VersionedProjectData } from '@finos/legend-server-depot';
41
+ resolveVersion,
42
+ VersionedProjectData,
43
+ type DepotServerClient,
44
+ } from '@finos/legend-server-depot';
49
45
  import {
50
46
  V1_SdlcDeploymentDataProductOrigin,
51
47
  type V1_EntitlementsDataProductLite,
52
48
  type V1_EntitlementsDataProductLiteResponse,
53
- V1_entitlementsDataProductDetailsResponseToDataProductDetails,
49
+ V1_EntitlementsLakehouseEnvironmentType,
54
50
  V1_DataProductOriginType,
55
51
  V1_AdHocDeploymentDataProductOrigin,
56
- type V1_EntitlementsDataProductDetails,
57
- V1_isIngestEnvsCompatibleWithEntitlements,
58
52
  V1_LegendSDLC,
59
53
  V1_serializePureModelContext,
60
54
  V1_PureModelContextPointer,
@@ -64,7 +58,10 @@ import {
64
58
  V1_Protocol,
65
59
  V1_PureGraphManager,
66
60
  PureClientVersion,
67
- type V1_EntitlementsUserEnvResponse,
61
+ V1_DataProduct,
62
+ V1_dataProductModelSchema,
63
+ V1_deserializePureModelContextData,
64
+ V1_EntitlementsDataProductLiteModelSchema,
68
65
  } from '@finos/legend-graph';
69
66
  import {
70
67
  RawLakehouseAdhocOrigin,
@@ -72,68 +69,61 @@ import {
72
69
  RawLakehouseSdlcOrigin,
73
70
  } from '../../model/LakehouseConsumerDataCubeSource.js';
74
71
  import { LegendDataCubeCodeEditorState } from '../LegendDataCubeCodeEditorState.js';
72
+ import type { Entity } from '@finos/legend-storage';
73
+ import { deserialize } from 'serializr';
75
74
 
76
75
  export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeSourceBuilderState {
77
76
  warehouse: string | undefined;
78
- selectedDataProduct: string | undefined;
79
- selectedAccessPoint: string | undefined;
77
+ selectedDataProduct: V1_EntitlementsDataProductLite | undefined;
78
+ // accesspoint is an array of id and title
79
+ selectedAccessPoint: [string, string] | undefined;
80
80
  paths: string[] = [];
81
81
  dataProducts: V1_EntitlementsDataProductLite[] = [];
82
- accessPoints: string[] = [];
82
+ accessPoints: Map<string, string | undefined> = new Map();
83
83
  dpCoordinates: VersionedProjectData | undefined;
84
84
  origin: string | undefined;
85
85
  fullGraphGrammar: string | undefined;
86
86
  deploymentId: number | undefined;
87
- userEntitlementEnvs: string[] = [];
88
- dataProductDetails: V1_EntitlementsDataProductDetails[] | undefined;
87
+ envMode: V1_EntitlementsLakehouseEnvironmentType;
89
88
  showQueryEditor = false;
90
89
  DEFAULT_CONSUMER_WAREHOUSE = 'LAKEHOUSE_CONSUMER_DEFAULT_WH';
91
90
  codeEditorState: LegendDataCubeCodeEditorState;
92
91
 
93
- // envs
94
- allEnvironments: IngestDeploymentServerConfig[] | undefined;
95
- selectedEnvironment: IngestDeploymentServerConfig | undefined;
96
-
97
- private readonly _platformServerClient: LakehousePlatformServerClient;
98
92
  private readonly _contractServerClient: LakehouseContractServerClient;
93
+ private readonly _depotServerClient: DepotServerClient;
99
94
  readonly dataProductLoadingState = ActionState.create();
100
95
  readonly ingestEnvLoadingState = ActionState.create();
101
96
 
102
97
  constructor(
103
98
  application: LegendDataCubeApplicationStore,
104
99
  engine: LegendDataCubeDataCubeEngine,
105
- platformServerClient: LakehousePlatformServerClient,
100
+ depotServerClient: DepotServerClient,
106
101
  contractServerClient: LakehouseContractServerClient,
107
102
  alertService: DataCubeAlertService,
108
103
  ) {
109
104
  super(application, engine, alertService);
110
- this._platformServerClient = platformServerClient;
111
105
  this._contractServerClient = contractServerClient;
106
+ this._depotServerClient = depotServerClient;
112
107
 
113
108
  makeObservable(this, {
114
109
  warehouse: observable,
115
110
  dataProducts: observable,
116
111
  selectedDataProduct: observable,
112
+ envMode: observable,
117
113
  accessPoints: observable,
118
- allEnvironments: observable,
119
- dataProductDetails: observable,
120
- environments: computed,
121
- selectedDataProductDetail: computed,
114
+ filteredDataProducts: computed,
122
115
  selectedAccessPoint: observable,
123
- selectedEnvironment: observable,
124
116
  showQueryEditor: observable,
125
117
  setShowQueryEditor: action,
118
+ setEnvMode: action,
126
119
  loadDataProducts: flow,
127
- fetchEnvironment: flow,
128
- fetchUserEntitlementEnvs: flow,
129
120
 
130
121
  setWarehouse: action,
131
122
  setDataProducts: action,
132
123
  setSelectedDataProduct: action,
133
124
  setAccessPoints: action,
134
125
  setSelectedAccessPoint: action,
135
- setSelectedEnvironment: action,
136
- setUserEntitlementEnv: action,
126
+ resetDataProduct: action,
137
127
  });
138
128
 
139
129
  this.codeEditorState = new LegendDataCubeCodeEditorState(
@@ -142,6 +132,8 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
142
132
  undefined,
143
133
  );
144
134
 
135
+ this.envMode = V1_EntitlementsLakehouseEnvironmentType.PRODUCTION;
136
+
145
137
  reaction(
146
138
  () => this.selectedAccessPoint,
147
139
  (accessPoint) => {
@@ -158,84 +150,40 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
158
150
  this.dataProducts = dataProducts;
159
151
  }
160
152
 
161
- setSelectedDataProduct(dataProduct: string | undefined) {
162
- this.selectedDataProduct = dataProduct;
153
+ setSelectedDataProduct(
154
+ dataProduct: V1_EntitlementsDataProductLite | undefined,
155
+ ) {
156
+ this.selectedDataProduct = deserialize(
157
+ V1_EntitlementsDataProductLiteModelSchema,
158
+ dataProduct,
159
+ );
163
160
  }
164
161
 
165
- setAccessPoints(accessPoints: string[]) {
162
+ setAccessPoints(accessPoints: Map<string, string | undefined>) {
166
163
  this.accessPoints = accessPoints;
167
164
  }
168
165
 
169
- setAllEnvironments(environments: IngestDeploymentServerConfig[]) {
170
- this.allEnvironments = environments;
171
- }
172
-
173
- setSelectedAccessPoint(accessPoint: string | undefined) {
166
+ setSelectedAccessPoint(accessPoint: [string, string] | undefined) {
174
167
  this.selectedAccessPoint = accessPoint;
175
168
  }
176
169
 
177
- setSelectedEnvironment(
178
- environment: IngestDeploymentServerConfig | undefined,
179
- ) {
180
- this.selectedEnvironment = environment;
170
+ setEnvMode(env: V1_EntitlementsLakehouseEnvironmentType): void {
171
+ this.envMode = env;
181
172
  }
182
173
 
183
- setUserEntitlementEnv(envs: string[]) {
184
- this.userEntitlementEnvs = envs;
174
+ get filteredDataProducts(): V1_EntitlementsDataProductLite[] {
175
+ if (!this.dataProducts.length) {
176
+ return [];
177
+ }
178
+ return this.dataProducts.filter(
179
+ (dp) => dp.lakehouseEnvironment?.type === this.envMode,
180
+ );
185
181
  }
186
182
 
187
183
  setShowQueryEditor(val: boolean): void {
188
184
  this.showQueryEditor = val;
189
185
  }
190
186
 
191
- get environments(): IngestDeploymentServerConfig[] {
192
- const allEnvironments = this.allEnvironments;
193
- if (allEnvironments) {
194
- const details = this.dataProductDetails?.map(
195
- (detail) => detail.lakehouseEnvironment?.type,
196
- );
197
- if (details?.length && !details.includes(undefined)) {
198
- const entitlementsTypes = uniq(details.filter(isNonNullable));
199
- return uniq(
200
- entitlementsTypes
201
- .map((type) =>
202
- filterEnvironmentsByEntitlementsEnv(type, allEnvironments),
203
- )
204
- .flat()
205
- .filter((env) =>
206
- this.userEntitlementEnvs.some((userEnv) =>
207
- userEnv.includes(env.environmentName),
208
- ),
209
- ),
210
- );
211
- }
212
- return allEnvironments;
213
- }
214
- return [];
215
- }
216
-
217
- get selectedDataProductDetail():
218
- | V1_EntitlementsDataProductDetails
219
- | undefined {
220
- const selectedEnv = this.selectedEnvironment;
221
- if (selectedEnv && this.dataProductDetails?.length) {
222
- const details = this.dataProductDetails.filter((dpDetail) => {
223
- const dpDetailType = dpDetail.lakehouseEnvironment?.type;
224
- if (!dpDetailType) {
225
- return false;
226
- }
227
- return V1_isIngestEnvsCompatibleWithEntitlements(
228
- selectedEnv.environmentClassification,
229
- dpDetailType,
230
- );
231
- });
232
- if (details.length === 1) {
233
- return guaranteeNonNullable(details[0]);
234
- }
235
- }
236
- return undefined;
237
- }
238
-
239
187
  *loadDataProducts(access_token?: string): GeneratorFn<void> {
240
188
  try {
241
189
  this.dataProductLoadingState.inProgress();
@@ -252,31 +200,16 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
252
200
  }
253
201
  }
254
202
 
255
- async fetchDataProduct(access_token?: string) {
256
- this.resetEnvironment();
257
-
258
- const selectedDp = guaranteeNonNullable(this.selectedDataProduct);
259
- this.dataProductDetails =
260
- V1_entitlementsDataProductDetailsResponseToDataProductDetails(
261
- await this._contractServerClient.getDataProduct(
262
- selectedDp.split('::').pop() ?? '',
263
- access_token,
264
- ),
265
- );
266
- }
267
-
268
203
  async fetchAccessPoints() {
269
204
  try {
270
- this.resetAccessPoint();
271
- const dataProduct = guaranteeNonNullable(
272
- this.selectedDataProductDetail,
273
- 'unable to resolve data product',
274
- );
275
- if (dataProduct.origin instanceof V1_SdlcDeploymentDataProductOrigin) {
205
+ this.resetEnvironment();
206
+ const selectedDp = guaranteeNonNullable(this.selectedDataProduct);
207
+ let v1DataProduct: V1_DataProduct | undefined;
208
+ if (selectedDp.origin instanceof V1_SdlcDeploymentDataProductOrigin) {
276
209
  const versionedData = new VersionedProjectData();
277
- versionedData.groupId = dataProduct.origin.group;
278
- versionedData.artifactId = dataProduct.origin.artifact;
279
- versionedData.versionId = dataProduct.origin.version;
210
+ versionedData.groupId = selectedDp.origin.group;
211
+ versionedData.artifactId = selectedDp.origin.artifact;
212
+ versionedData.versionId = selectedDp.origin.version;
280
213
  this.dpCoordinates = versionedData;
281
214
  this.origin = V1_DataProductOriginType.SDLC_DEPLOYMENT;
282
215
 
@@ -297,25 +230,50 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
297
230
  );
298
231
 
299
232
  this.codeEditorState.setModel(model);
233
+
234
+ v1DataProduct = deserialize(
235
+ V1_dataProductModelSchema(
236
+ this._application.pluginManager.getPureProtocolProcessorPlugins(),
237
+ ),
238
+ (
239
+ (await this._depotServerClient.getVersionEntity(
240
+ selectedDp.origin.group,
241
+ selectedDp.origin.artifact,
242
+ resolveVersion(selectedDp.origin.version),
243
+ guaranteeNonNullable(selectedDp.fullPath),
244
+ )) as unknown as Entity
245
+ ).content,
246
+ );
300
247
  } else if (
301
- dataProduct.origin instanceof V1_AdHocDeploymentDataProductOrigin
248
+ selectedDp.origin instanceof V1_AdHocDeploymentDataProductOrigin
302
249
  ) {
303
250
  this.dpCoordinates = undefined;
304
251
  this.origin = V1_DataProductOriginType.AD_HOC_DEPLOYMENT;
305
- this.fullGraphGrammar = dataProduct.origin.definition;
252
+ this.fullGraphGrammar = selectedDp.origin.definition;
306
253
 
307
254
  const model = await this._engine.parseCompatibleModel(
308
255
  this.fullGraphGrammar,
309
256
  );
310
257
 
311
258
  this.codeEditorState.setModel(model);
259
+
260
+ v1DataProduct = guaranteeNonNullable(
261
+ V1_deserializePureModelContextData(model)
262
+ .elements.filter((ele) => ele instanceof V1_DataProduct)
263
+ .map((ele) => ele)
264
+ .at(0),
265
+ );
312
266
  }
313
- this.deploymentId = dataProduct.deploymentId;
314
- this.setAccessPoints(
315
- dataProduct.dataProduct.accessPoints.map(
316
- (accessPoint) => accessPoint.name,
317
- ),
318
- );
267
+ this.deploymentId = selectedDp.deploymentId;
268
+
269
+ const accessPointMap = new Map<string, string | undefined>();
270
+ guaranteeNonNullable(v1DataProduct).accessPointGroups.forEach((apg) => {
271
+ apg.accessPoints.forEach((accessPoint) => {
272
+ accessPointMap.set(accessPoint.id, accessPoint.title);
273
+ });
274
+ });
275
+
276
+ this.setAccessPoints(accessPointMap);
319
277
  } catch (error) {
320
278
  assertErrorThrown(error);
321
279
  this._application.notificationService.notifyError(
@@ -324,36 +282,13 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
324
282
  }
325
283
  }
326
284
 
327
- *fetchEnvironment(access_token: string | undefined): GeneratorFn<void> {
328
- this.ingestEnvLoadingState.inProgress();
329
- const ingestServerConfigs =
330
- (yield this._platformServerClient.getIngestEnvironmentSummaries(
331
- access_token,
332
- )) as IngestDeploymentServerConfig[];
333
- this.setAllEnvironments(ingestServerConfigs);
334
- this.ingestEnvLoadingState.complete();
335
- }
336
-
337
- *fetchUserEntitlementEnvs(
338
- access_token: string | undefined,
339
- ): GeneratorFn<void> {
340
- const entitledEnvs =
341
- (yield this._contractServerClient.getUserEntitlementEnvs(
342
- this._application.identityService.currentUser,
343
- access_token,
344
- )) as V1_EntitlementsUserEnvResponse;
345
- this.setUserEntitlementEnv(
346
- entitledEnvs.users.map((env) => env.lakehouseEnvironment),
347
- );
348
- }
349
-
350
285
  async initializeQuery() {
351
286
  const query = new V1_ClassInstance();
352
287
  query.type = V1_ClassInstanceType.DATA_PRODUCT_ACCESSOR;
353
288
  const dataProductAccessor = new V1_DataProductAccessor();
354
289
  dataProductAccessor.path = [
355
- guaranteeNonNullable(this.selectedDataProduct),
356
- guaranteeNonNullable(this.selectedAccessPoint),
290
+ guaranteeNonNullable(this.selectedDataProduct?.fullPath),
291
+ guaranteeNonNullable(this.selectedAccessPoint)[0],
357
292
  ];
358
293
  dataProductAccessor.parameters = [];
359
294
  query.value = dataProductAccessor;
@@ -363,26 +298,18 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
363
298
  }
364
299
 
365
300
  reset() {
366
- this.setWarehouse(undefined);
367
301
  this.setDataProducts([]);
368
- this.setSelectedDataProduct(undefined);
369
- this.setAccessPoints([]);
370
- this.setSelectedAccessPoint(undefined);
371
- this.setSelectedEnvironment(undefined);
372
- this.dpCoordinates = undefined;
302
+ this.resetDataProduct();
373
303
  }
374
304
 
375
- resetEnvironment() {
376
- this.setWarehouse(undefined);
377
- this.setAccessPoints([]);
378
- this.setSelectedAccessPoint(undefined);
379
- this.setSelectedEnvironment(undefined);
380
- this.dpCoordinates = undefined;
305
+ resetDataProduct() {
306
+ this.setSelectedDataProduct(undefined);
307
+ this.resetEnvironment();
381
308
  }
382
309
 
383
- resetAccessPoint() {
310
+ resetEnvironment() {
384
311
  this.setWarehouse(undefined);
385
- this.setAccessPoints([]);
312
+ this.setAccessPoints(new Map());
386
313
  this.setSelectedAccessPoint(undefined);
387
314
  this.dpCoordinates = undefined;
388
315
  }
@@ -396,7 +323,7 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
396
323
  Boolean(this.warehouse) &&
397
324
  Boolean(this.selectedAccessPoint) &&
398
325
  Boolean(this.selectedDataProduct) &&
399
- Boolean(this.selectedEnvironment) &&
326
+ Boolean(this.envMode) &&
400
327
  !this.codeEditorState.hasErrors
401
328
  );
402
329
  }
@@ -406,17 +333,12 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
406
333
  this.paths = [];
407
334
  this.paths.push(
408
335
  ...[
409
- guaranteeNonNullable(this.selectedDataProduct),
410
- guaranteeNonNullable(this.selectedAccessPoint),
336
+ guaranteeNonNullable(this.selectedDataProduct?.fullPath),
337
+ guaranteeNonNullable(this.selectedAccessPoint)[0],
411
338
  ],
412
339
  );
413
340
 
414
341
  const rawSource = new RawLakehouseConsumerDataCubeSource();
415
- const selectedEnv = guaranteeNonNullable(this.selectedEnvironment);
416
- rawSource.environment = guaranteeNonNullable(
417
- getIngestDeploymentServerConfigName(selectedEnv),
418
- 'Unable to resolve env env string',
419
- );
420
342
  if (this.origin === V1_DataProductOriginType.SDLC_DEPLOYMENT) {
421
343
  const lakehouseOrigin = new RawLakehouseSdlcOrigin();
422
344
  lakehouseOrigin.dpCoordinates = guaranteeNonNullable(this.dpCoordinates);
@@ -425,6 +347,7 @@ export class LakehouseConsumerDataCubeSourceBuilderState extends LegendDataCubeS
425
347
  rawSource.origin = new RawLakehouseAdhocOrigin();
426
348
  }
427
349
  rawSource.paths = this.paths;
350
+ rawSource.environment = guaranteeNonNullable(this.envMode);
428
351
  rawSource.warehouse = guaranteeNonNullable(this.warehouse);
429
352
  rawSource.deploymentId = this.deploymentId;
430
353
  rawSource.query = this.codeEditorState.code;
@@ -44,7 +44,7 @@ export class LakehouseConsumerDataCubeSource extends DataCubeSource {
44
44
  dpCoordinates?: VersionedProjectData;
45
45
  runtime!: string;
46
46
  warehouse!: string;
47
- environment!: string;
47
+ userEnvironment!: string;
48
48
  paths!: string[];
49
49
  deploymentId?: number | undefined;
50
50
  }