@finos/legend-extension-dsl-data-space 10.4.273 → 10.4.274

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.
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Copyright (c) 2026-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 { GenericLegendApplicationStore } from '@finos/legend-application';
18
+ import { InMemoryGraphData, type GraphManagerState } from '@finos/legend-graph';
19
+ import type { ActionState } from '@finos/legend-shared';
20
+ import type { DepotServerClient } from '@finos/legend-server-depot';
21
+ import type { EntitiesWithOrigin, Entity } from '@finos/legend-storage';
22
+ import { DATA_SPACE_ELEMENT_CLASSIFIER_PATH } from '../graph-manager/protocol/pure/DSL_DataSpace_PureProtocolProcessorPlugin.js';
23
+ import { DSL_DataSpace_getGraphManagerExtension } from '../graph-manager/protocol/pure/DSL_DataSpace_PureGraphManagerExtension.js';
24
+ import { DataSpaceViewerState } from './DataSpaceViewerState.js';
25
+
26
+ export type DataSpaceViewerActions = Omit<
27
+ ConstructorParameters<typeof DataSpaceViewerState>[7],
28
+ 'retrieveGraphData'
29
+ >;
30
+
31
+ export interface DataSpacePreviewOrigin {
32
+ groupId: string;
33
+ artifactId: string;
34
+ versionId: string;
35
+ }
36
+
37
+ /**
38
+ * The DataSpace to preview among *entities*: *preferredPath* when given -- and only
39
+ * that one, never another in its place -- else the only one the model has.
40
+ */
41
+ export const findDataSpaceEntity = (
42
+ entities: Entity[],
43
+ preferredPath?: string,
44
+ ): Entity => {
45
+ const dataSpaces = entities.filter(
46
+ (entity) => entity.classifierPath === DATA_SPACE_ELEMENT_CLASSIFIER_PATH,
47
+ );
48
+ const has = `the model has: ${
49
+ dataSpaces.map((entity) => entity.path).join(', ') || 'none'
50
+ }`;
51
+ if (preferredPath !== undefined) {
52
+ const preferred = dataSpaces.find(
53
+ (entity) => entity.path === preferredPath,
54
+ );
55
+ if (!preferred) {
56
+ throw new Error(`No data product ${preferredPath} to preview; ${has}`);
57
+ }
58
+ return preferred;
59
+ }
60
+ if (dataSpaces.length !== 1) {
61
+ throw new Error(
62
+ dataSpaces.length
63
+ ? `More than one data product to preview; ${has}`
64
+ : 'No data product to preview',
65
+ );
66
+ }
67
+ return dataSpaces[0] as Entity;
68
+ };
69
+
70
+ /**
71
+ * A viewer for the DataSpace *dataSpacePath* of the model *graphManagerState*
72
+ * has built: the DataSpace analysed over *entities* (the model's own and its
73
+ * dependencies'), then viewed over that graph. Studio's editor preview passes
74
+ * the graph it already has; `previewDataSpaceFromEntities` builds one first.
75
+ */
76
+ export const previewDataSpace = async (
77
+ applicationStore: GenericLegendApplicationStore,
78
+ graphManagerState: GraphManagerState,
79
+ dataSpacePath: string,
80
+ entities: () => Promise<Entity[]>,
81
+ origin: DataSpacePreviewOrigin,
82
+ depotServerClient: DepotServerClient | undefined,
83
+ actions: DataSpaceViewerActions,
84
+ actionState?: ActionState,
85
+ ): Promise<DataSpaceViewerState> => {
86
+ const analysisResult = await DSL_DataSpace_getGraphManagerExtension(
87
+ graphManagerState.graphManager,
88
+ ).analyzeDataSpace(dataSpacePath, entities, undefined, actionState);
89
+ return new DataSpaceViewerState(
90
+ applicationStore,
91
+ graphManagerState,
92
+ origin.groupId,
93
+ origin.artifactId,
94
+ origin.versionId,
95
+ analysisResult,
96
+ depotServerClient,
97
+ {
98
+ ...actions,
99
+ retrieveGraphData: () => new InMemoryGraphData(graphManagerState.graph),
100
+ },
101
+ );
102
+ };
103
+
104
+ /**
105
+ * A viewer for the DataSpace *dataSpacePath* of a model that exists only as
106
+ * entities -- unsaved or unreleased, as Studio previews one in its editor --
107
+ * with its dependencies' entities by project (as
108
+ * `collectIndexedDependencyEntities` gives them). The graph is built, not just
109
+ * handed to the analysis: the viewer reads graph data as soon as the DataSpace
110
+ * has a default execution context.
111
+ */
112
+ export const previewDataSpaceFromEntities = async (
113
+ applicationStore: GenericLegendApplicationStore,
114
+ graphManagerState: GraphManagerState,
115
+ ownEntities: Entity[],
116
+ dependencyEntitiesIndex: Map<string, EntitiesWithOrigin>,
117
+ dataSpacePath: string,
118
+ origin: DataSpacePreviewOrigin,
119
+ depotServerClient: DepotServerClient | undefined,
120
+ actions: DataSpaceViewerActions,
121
+ ): Promise<DataSpaceViewerState> => {
122
+ await graphManagerState.initializeSystem();
123
+ const dependencyManager =
124
+ graphManagerState.graphManager.createDependencyManager();
125
+ graphManagerState.graph.dependencyManager = dependencyManager;
126
+ await graphManagerState.graphManager.buildDependencies(
127
+ graphManagerState.coreModel,
128
+ graphManagerState.systemModel,
129
+ dependencyManager,
130
+ dependencyEntitiesIndex,
131
+ graphManagerState.dependenciesBuildState,
132
+ );
133
+ await graphManagerState.graphManager.buildGraph(
134
+ graphManagerState.graph,
135
+ ownEntities,
136
+ graphManagerState.graphBuildState,
137
+ );
138
+ const dependencyEntities = Array.from(
139
+ dependencyEntitiesIndex.values(),
140
+ ).flatMap((project) => project.entities);
141
+ return previewDataSpace(
142
+ applicationStore,
143
+ graphManagerState,
144
+ dataSpacePath,
145
+ () => Promise.resolve(ownEntities.concat(dependencyEntities)),
146
+ origin,
147
+ depotServerClient,
148
+ actions,
149
+ );
150
+ };
@@ -21,16 +21,13 @@ import {
21
21
  LogEvent,
22
22
  type GeneratorFn,
23
23
  } from '@finos/legend-shared';
24
+ import { QUALITY_LEVEL } from '@finos/legend-extension-dsl-data-product';
24
25
  import type { DataSpaceViewerState } from './DataSpaceViewerState.js';
25
26
  import { DSL_DATASPACE_EVENT } from '../__lib__/DSL_DataSpace_Event.js';
26
27
 
27
- export enum DATA_SPACE_QUALITY_LEVEL {
28
- DIAMOND = 'DIAMOND',
29
- PLATINUM = 'PLATINUM',
30
- GOLD = 'GOLD',
31
- SILVER = 'SILVER',
32
- BRONZE = 'BRONZE',
33
- }
28
+ // The tiers are the same for a data product and a data space: one enum, defined with the quality
29
+ // response models. This keeps the name existing consumers know it by.
30
+ export { QUALITY_LEVEL as DATA_SPACE_QUALITY_LEVEL };
34
31
 
35
32
  // A step-by-step breakdown of every criterion behind the quality rating, so the UI can show
36
33
  // users a roadmap of what's already done and what's needed for the next tier.
@@ -45,7 +42,7 @@ export type DataSpaceQualityBreakdown = {
45
42
  };
46
43
 
47
44
  export type DataSpaceQualityResult = {
48
- qualityLevel: DATA_SPACE_QUALITY_LEVEL;
45
+ qualityLevel: QUALITY_LEVEL;
49
46
  qualityBreakdown: DataSpaceQualityBreakdown;
50
47
  };
51
48
 
@@ -59,7 +56,7 @@ export type DataSpaceQualityResult = {
59
56
  // and the badge simply doesn't render.
60
57
  export class DataSpaceQualityState {
61
58
  readonly dataSpaceViewerState: DataSpaceViewerState;
62
- qualityLevel: DATA_SPACE_QUALITY_LEVEL | undefined;
59
+ qualityLevel: QUALITY_LEVEL | undefined;
63
60
  qualityBreakdown: DataSpaceQualityBreakdown | undefined;
64
61
  readonly computingQualityState = ActionState.create();
65
62
 
@@ -75,7 +72,7 @@ export class DataSpaceQualityState {
75
72
  this.dataSpaceViewerState = dataSpaceViewerState;
76
73
  }
77
74
 
78
- setQualityLevel(val: DATA_SPACE_QUALITY_LEVEL | undefined): void {
75
+ setQualityLevel(val: QUALITY_LEVEL | undefined): void {
79
76
  this.qualityLevel = val;
80
77
  }
81
78
 
package/tsconfig.json CHANGED
@@ -88,6 +88,7 @@
88
88
  "./src/stores/DataSpaceDataProductAccessState.ts",
89
89
  "./src/stores/DataSpaceLayoutState.ts",
90
90
  "./src/stores/DataSpaceModelsDocumentationState.ts",
91
+ "./src/stores/DataSpacePreviewFromEntities.ts",
91
92
  "./src/stores/DataSpaceQualityState.ts",
92
93
  "./src/stores/DataSpaceQuickStartState.ts",
93
94
  "./src/stores/DataSpaceViewerDiagramViewerState.ts",