@finos/legend-graph 13.0.2 → 14.0.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 (56) hide show
  1. package/lib/graph/Core_HashUtils.js +2 -2
  2. package/lib/graph/Core_HashUtils.js.map +1 -1
  3. package/lib/graph/helpers/DomainHelper.d.ts +4 -0
  4. package/lib/graph/helpers/DomainHelper.d.ts.map +1 -1
  5. package/lib/graph/helpers/DomainHelper.js +14 -2
  6. package/lib/graph/helpers/DomainHelper.js.map +1 -1
  7. package/lib/graph/metamodel/pure/Reference.d.ts +1 -0
  8. package/lib/graph/metamodel/pure/Reference.d.ts.map +1 -1
  9. package/lib/graph/metamodel/pure/Reference.js +2 -0
  10. package/lib/graph/metamodel/pure/Reference.js.map +1 -1
  11. package/lib/graph/metamodel/pure/packageableElements/domain/PropertyReference.js +2 -2
  12. package/lib/graph/metamodel/pure/packageableElements/domain/PropertyReference.js.map +1 -1
  13. package/lib/graph/metamodel/pure/packageableElements/domain/StereotypeReference.js +2 -2
  14. package/lib/graph/metamodel/pure/packageableElements/domain/StereotypeReference.js.map +1 -1
  15. package/lib/graph/metamodel/pure/packageableElements/domain/TagReference.js +2 -2
  16. package/lib/graph/metamodel/pure/packageableElements/domain/TagReference.js.map +1 -1
  17. package/lib/graph/metamodel/pure/packageableElements/store/flatData/model/FlatDataSectionReference.js +2 -2
  18. package/lib/graph/metamodel/pure/packageableElements/store/flatData/model/FlatDataSectionReference.js.map +1 -1
  19. package/lib/graph/metamodel/pure/packageableElements/store/relational/model/TableReference.js +3 -3
  20. package/lib/graph/metamodel/pure/packageableElements/store/relational/model/TableReference.js.map +1 -1
  21. package/lib/graph/metamodel/pure/packageableElements/store/relational/model/ViewReference.js +3 -3
  22. package/lib/graph/metamodel/pure/packageableElements/store/relational/model/ViewReference.js.map +1 -1
  23. package/lib/graphManager/AbstractPureGraphManager.d.ts +5 -5
  24. package/lib/graphManager/AbstractPureGraphManager.d.ts.map +1 -1
  25. package/lib/graphManager/AbstractPureGraphManager.js.map +1 -1
  26. package/lib/graphManager/GraphManagerState.d.ts +8 -17
  27. package/lib/graphManager/GraphManagerState.d.ts.map +1 -1
  28. package/lib/graphManager/GraphManagerState.js +8 -73
  29. package/lib/graphManager/GraphManagerState.js.map +1 -1
  30. package/lib/graphManager/protocol/pure/v1/V1_PureGraphManager.d.ts +4 -4
  31. package/lib/graphManager/protocol/pure/v1/V1_PureGraphManager.d.ts.map +1 -1
  32. package/lib/graphManager/protocol/pure/v1/V1_PureGraphManager.js +26 -91
  33. package/lib/graphManager/protocol/pure/v1/V1_PureGraphManager.js.map +1 -1
  34. package/lib/graphManager/protocol/pure/v1/engine/execution/V1_ExecuteInput.d.ts +1 -1
  35. package/lib/graphManager/protocol/pure/v1/engine/execution/V1_ExecuteInput.d.ts.map +1 -1
  36. package/lib/graphManager/protocol/pure/v1/engine/execution/V1_ExecuteInput.js +2 -2
  37. package/lib/graphManager/protocol/pure/v1/engine/execution/V1_ExecuteInput.js.map +1 -1
  38. package/lib/graphManager/protocol/pure/v1/model/packageableElements/store/flatData/model/V1_FlatDataProperty.d.ts +3 -1
  39. package/lib/graphManager/protocol/pure/v1/model/packageableElements/store/flatData/model/V1_FlatDataProperty.d.ts.map +1 -1
  40. package/lib/graphManager/protocol/pure/v1/model/packageableElements/store/flatData/model/V1_FlatDataProperty.js.map +1 -1
  41. package/lib/package.json +2 -2
  42. package/package.json +5 -5
  43. package/src/graph/Core_HashUtils.ts +2 -2
  44. package/src/graph/helpers/DomainHelper.ts +31 -0
  45. package/src/graph/metamodel/pure/Reference.ts +4 -0
  46. package/src/graph/metamodel/pure/packageableElements/domain/PropertyReference.ts +2 -2
  47. package/src/graph/metamodel/pure/packageableElements/domain/StereotypeReference.ts +2 -2
  48. package/src/graph/metamodel/pure/packageableElements/domain/TagReference.ts +2 -2
  49. package/src/graph/metamodel/pure/packageableElements/store/flatData/model/FlatDataSectionReference.ts +2 -2
  50. package/src/graph/metamodel/pure/packageableElements/store/relational/model/TableReference.ts +3 -3
  51. package/src/graph/metamodel/pure/packageableElements/store/relational/model/ViewReference.ts +3 -3
  52. package/src/graphManager/AbstractPureGraphManager.ts +14 -20
  53. package/src/graphManager/GraphManagerState.ts +10 -113
  54. package/src/graphManager/protocol/pure/v1/V1_PureGraphManager.ts +36 -113
  55. package/src/graphManager/protocol/pure/v1/engine/execution/V1_ExecuteInput.ts +2 -2
  56. package/src/graphManager/protocol/pure/v1/model/packageableElements/store/flatData/model/V1_FlatDataProperty.ts +3 -1
@@ -279,6 +279,16 @@ export abstract class AbstractPureGraphManager {
279
279
  rawValueSpecification: RawValueSpecification,
280
280
  ): Record<PropertyKey, unknown>;
281
281
 
282
+ // These methods are utilities that we could use to quickly construct compilable
283
+ // raw lambdas.
284
+ // NOTE: As of now, to simplify the code, these methods are implemented in quite a hacky way, as we create
285
+ // the lambdas from a templated JSON object. Formally, we could remove these method by building them
286
+ // in metamodel form and convert to raw form as these are relatively simple lambda to construct
287
+ abstract createGetAllRawLambda(_class: Class): RawLambda;
288
+ abstract createDefaultBasicRawLambda(options?: {
289
+ addDummyParameter?: boolean;
290
+ }): RawLambda;
291
+
282
292
  // ------------------------------------------- Generation -------------------------------------------
283
293
 
284
294
  abstract getAvailableGenerationConfigurationDescriptions(): Promise<
@@ -420,6 +430,10 @@ export abstract class AbstractPureGraphManager {
420
430
  input: RawMappingModelCoverageAnalysisResult,
421
431
  ): MappingModelCoverageAnalysisResult;
422
432
 
433
+ // ------------------------------------------- Change detection -------------------------------------------
434
+
435
+ abstract buildHashesIndex(entities: Entity[]): Promise<Map<string, string>>;
436
+
423
437
  // ------------------------------------------- Utilities -------------------------------------------
424
438
 
425
439
  abstract elementToEntity(
@@ -448,24 +462,4 @@ export abstract class AbstractPureGraphManager {
448
462
  );
449
463
  return graph;
450
464
  }
451
-
452
- // ------------------------------------------- Change detection -------------------------------------------
453
-
454
- abstract buildHashesIndex(entities: Entity[]): Promise<Map<string, string>>;
455
-
456
- // --------------------------------------------- HACKY ---------------------------------------------
457
- // As the name suggested, these methods are temporary hacks since we don't handle value-specification
458
- // structurally in Studio
459
-
460
- // Eventually, we could remove these method by building them in metamodel form and convert to raw form
461
- // as these are relatively simple lambda to construct
462
- abstract HACKY__createGetAllLambda(_class: Class): RawLambda;
463
- abstract HACKY__createDefaultBlankLambda(): RawLambda;
464
-
465
- // NOTE: after we refactor service, we probably can remove these methods
466
- // See https://github.com/finos/legend-studio/issues/1077
467
- abstract HACKY__createServiceTestAssertLambda(assertData: string): RawLambda;
468
- abstract HACKY__extractServiceTestAssertionData(
469
- query: RawLambda,
470
- ): string | undefined;
471
465
  }
@@ -14,12 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import {
18
- type Log,
19
- uniq,
20
- ActionState,
21
- assertErrorThrown,
22
- } from '@finos/legend-shared';
17
+ import { type Log, ActionState, assertErrorThrown } from '@finos/legend-shared';
23
18
  import { action, makeObservable, observable } from 'mobx';
24
19
  import { DependencyManager } from '../graph/DependencyManager.js';
25
20
  import {
@@ -33,22 +28,14 @@ import type {
33
28
  GraphBuilderOptions,
34
29
  } from '../graphManager/AbstractPureGraphManager.js';
35
30
  import type { GraphManagerPluginManager } from './GraphManagerPluginManager.js';
36
- import { getElementRootPackage } from '../graph/helpers/DomainHelper.js';
37
- import { getLeafSetImplementations } from '../graph/helpers/DSLMapping_Helper.js';
38
- import { ROOT_PACKAGE_NAME } from '../graph/MetaModelConst.js';
39
- import { AssociationImplementation } from '../graph/metamodel/pure/packageableElements/mapping/AssociationImplementation.js';
40
31
  import type { EnumerationMapping } from '../graph/metamodel/pure/packageableElements/mapping/EnumerationMapping.js';
41
32
  import { InstanceSetImplementation } from '../graph/metamodel/pure/packageableElements/mapping/InstanceSetImplementation.js';
42
- import { OperationSetImplementation } from '../graph/metamodel/pure/packageableElements/mapping/OperationSetImplementation.js';
43
- import type { PropertyMapping } from '../graph/metamodel/pure/packageableElements/mapping/PropertyMapping.js';
44
33
  import type { SetImplementation } from '../graph/metamodel/pure/packageableElements/mapping/SetImplementation.js';
45
34
  import type { PackageableElement } from '../graph/metamodel/pure/packageableElements/PackageableElement.js';
46
35
  import { EmbeddedFlatDataPropertyMapping } from '../graph/metamodel/pure/packageableElements/store/flatData/mapping/EmbeddedFlatDataPropertyMapping.js';
47
36
  import { EmbeddedRelationalInstanceSetImplementation } from '../graph/metamodel/pure/packageableElements/store/relational/mapping/EmbeddedRelationalInstanceSetImplementation.js';
48
- import { InlineEmbeddedRelationalInstanceSetImplementation } from '../graph/metamodel/pure/packageableElements/store/relational/mapping/InlineEmbeddedRelationalInstanceSetImplementation.js';
49
- import { OtherwiseEmbeddedRelationalInstanceSetImplementation } from '../graph/metamodel/pure/packageableElements/store/relational/mapping/OtherwiseEmbeddedRelationalInstanceSetImplementation.js';
50
37
  import { buildPureGraphManager } from '../graphManager/protocol/pure/PureGraphManagerBuilder.js';
51
- import { PrimitiveType } from '../graph/metamodel/pure/packageableElements/domain/PrimitiveType.js';
38
+ import type { AssociationImplementation } from '../graph/metamodel/pure/packageableElements/mapping/AssociationImplementation.js';
52
39
 
53
40
  export class BasicGraphManagerState {
54
41
  pluginManager: GraphManagerPluginManager;
@@ -63,49 +50,17 @@ export class BasicGraphManagerState {
63
50
  }
64
51
 
65
52
  // -------------------------------------------------- UTILITIES -----------------------------------------------------
53
+
66
54
  /**
67
- * NOTE: Notice how this utility draws resources from all of metamodels and uses `instanceof` to classify behavior/response.
68
- * As such, methods in this utility cannot be placed in place they should belong to.
55
+ * Check if a mapping element is an instance set implementation
69
56
  *
70
- * For example: `getSetImplemetnationType` cannot be placed in `SetImplementation` because of circular module dependency
71
- * So this utility is born for such purpose, to avoid circular module dependency, and it should just be used for only that
72
- * Other utilities that really should reside in the domain-specific meta model should be placed in the meta model module.
57
+ * NOTE: This would account for embedded property mappings as well
58
+ * these are technically instance of `InstanceSetImplementation`
59
+ * but since unlike Pure, Typescript cannot do multiple inheritance
60
+ * we only can make embedded property mapping extends `PropertyMapping`
73
61
  *
74
- * NOTE: We expect the need for these methods will eventually go away as we complete modularization. But we need these
75
- * methods here so that we can load plugins.
62
+ * Potentially, we might need to apply an extension mechanism on this
76
63
  */
77
-
78
- isDependencyElement(
79
- element: PackageableElement,
80
- ): element is PackageableElement {
81
- return (
82
- getElementRootPackage(element).name ===
83
- ROOT_PACKAGE_NAME.PROJECT_DEPENDENCY_ROOT
84
- );
85
- }
86
-
87
- isGeneratedElement(
88
- element: PackageableElement,
89
- ): element is PackageableElement {
90
- return (
91
- getElementRootPackage(element).name === ROOT_PACKAGE_NAME.MODEL_GENERATION
92
- );
93
- }
94
-
95
- isSystemElement(element: PackageableElement): element is PackageableElement {
96
- return (
97
- element instanceof PrimitiveType ||
98
- getElementRootPackage(element).name === ROOT_PACKAGE_NAME.SYSTEM ||
99
- getElementRootPackage(element).name === ROOT_PACKAGE_NAME.CORE
100
- );
101
- }
102
-
103
- isMainGraphElement(
104
- element: PackageableElement,
105
- ): element is PackageableElement {
106
- return getElementRootPackage(element).name === ROOT_PACKAGE_NAME.MAIN;
107
- }
108
-
109
64
  isInstanceSetImplementation(
110
65
  setImplementation:
111
66
  | EnumerationMapping
@@ -119,67 +74,13 @@ export class BasicGraphManagerState {
119
74
  );
120
75
  }
121
76
 
122
- getInstanceSetImplementationPropertyMappings(
123
- instanceSetImpl: InstanceSetImplementation,
124
- ): PropertyMapping[] {
125
- if (
126
- instanceSetImpl instanceof
127
- InlineEmbeddedRelationalInstanceSetImplementation
128
- ) {
129
- return this.getMappingElementPropertyMappings(
130
- instanceSetImpl.inlineSetImplementation,
131
- );
132
- } else if (
133
- instanceSetImpl instanceof
134
- OtherwiseEmbeddedRelationalInstanceSetImplementation
135
- ) {
136
- // NOTE: for now we will grab all property mappings from the main otherwise embedded mapping and the otherwise property mapping.
137
- // In the future we may want to incorporate some smartness as to when the otherwise set implementation isinvoked.
138
- const otherwisePropertyMappings = instanceSetImpl.otherwisePropertyMapping
139
- .targetSetImplementation?.value
140
- ? this.getMappingElementPropertyMappings(
141
- instanceSetImpl.otherwisePropertyMapping.targetSetImplementation
142
- .value,
143
- )
144
- : [];
145
- return [
146
- ...instanceSetImpl.propertyMappings,
147
- ...otherwisePropertyMappings,
148
- ];
149
- }
150
- return instanceSetImpl.propertyMappings;
151
- }
152
-
153
- getMappingElementPropertyMappings(
154
- mappingElement:
155
- | EnumerationMapping
156
- | SetImplementation
157
- | AssociationImplementation,
158
- ): PropertyMapping[] {
159
- let mappedProperties: PropertyMapping[] = [];
160
- if (this.isInstanceSetImplementation(mappingElement)) {
161
- mappedProperties =
162
- this.getInstanceSetImplementationPropertyMappings(mappingElement);
163
- } else if (mappingElement instanceof AssociationImplementation) {
164
- mappedProperties = mappingElement.propertyMappings;
165
- } else if (mappingElement instanceof OperationSetImplementation) {
166
- mappedProperties = getLeafSetImplementations(mappingElement)
167
- .filter((me): me is InstanceSetImplementation =>
168
- this.isInstanceSetImplementation(me),
169
- )
170
- .map((si) => si.propertyMappings)
171
- .flat();
172
- }
173
- return uniq(mappedProperties);
174
- }
175
-
176
77
  /**
177
78
  * Filter the list of system elements that will be shown in selection options
178
79
  * to users. This is helpful to avoid overwhelming and confusing users in form
179
80
  * mode since many system elements are needed to build the graph, but should
180
81
  * not present at all as selection options in form mode.
181
82
  */
182
- filterSystemElementOptions<T extends PackageableElement>(
83
+ collectExposedSystemElements<T extends PackageableElement>(
183
84
  systemElements: T[],
184
85
  ): T[] {
185
86
  const allowedSystemElements = this.pluginManager
@@ -189,10 +90,6 @@ export class BasicGraphManagerState {
189
90
  allowedSystemElements.includes(element.path),
190
91
  );
191
92
  }
192
-
193
- isElementReadOnly(element: PackageableElement): boolean {
194
- return getElementRootPackage(element).name !== ROOT_PACKAGE_NAME.MAIN;
195
- }
196
93
  }
197
94
 
198
95
  export class GraphManagerState extends BasicGraphManagerState {
@@ -30,7 +30,6 @@ import {
30
30
  getClass,
31
31
  guaranteeNonNullable,
32
32
  UnsupportedOperationError,
33
- assertTrue,
34
33
  assertErrorThrown,
35
34
  promisify,
36
35
  StopWatch,
@@ -1721,7 +1720,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1721
1720
  }
1722
1721
  }
1723
1722
 
1724
- // ------------------------------------------- ValueSpecification -------------------------------------------
1723
+ // ------------------------------------------- Value Specification -------------------------------------------
1725
1724
 
1726
1725
  buildValueSpecification(
1727
1726
  json: Record<PropertyKey, unknown>,
@@ -1780,7 +1779,41 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1780
1779
  );
1781
1780
  }
1782
1781
 
1782
+ createGetAllRawLambda(_class: Class): RawLambda {
1783
+ return new RawLambda(
1784
+ [],
1785
+ [
1786
+ {
1787
+ _type: 'func',
1788
+ function: 'getAll',
1789
+ parameters: [
1790
+ {
1791
+ _type: 'packageableElementPtr',
1792
+ fullPath: _class.path,
1793
+ },
1794
+ ],
1795
+ },
1796
+ ],
1797
+ );
1798
+ }
1799
+
1800
+ createDefaultBasicRawLambda(options?: {
1801
+ addDummyParameter?: boolean;
1802
+ }): RawLambda {
1803
+ return new RawLambda(
1804
+ options?.addDummyParameter ? [{ _type: 'var', name: 'x' }] : undefined,
1805
+ [
1806
+ {
1807
+ _type: 'string',
1808
+ multiplicity: { lowerBound: 1, upperBound: 1 },
1809
+ values: [''],
1810
+ },
1811
+ ],
1812
+ );
1813
+ }
1814
+
1783
1815
  // ------------------------------------------- External Format --------------------------------
1816
+
1784
1817
  getAvailableExternalFormatsDescriptions(): Promise<
1785
1818
  ExternalFormatDescription[]
1786
1819
  > {
@@ -1987,7 +2020,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1987
2020
  testDataGenerationExecuteInput,
1988
2021
  );
1989
2022
  testDataGenerationExecuteInput.parameters = parameters;
1990
- testDataGenerationExecuteInput.hashStrings = Boolean(
2023
+ testDataGenerationExecuteInput.hashValues = Boolean(
1991
2024
  options?.anonymizeGeneratedData,
1992
2025
  );
1993
2026
  return this.engine.generateExecuteTestData(testDataGenerationExecuteInput);
@@ -2346,116 +2379,6 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
2346
2379
  );
2347
2380
  }
2348
2381
 
2349
- // --------------------------------------------- HACKY ---------------------------------------------
2350
-
2351
- HACKY__createGetAllLambda(_class: Class): RawLambda {
2352
- return new RawLambda(
2353
- [],
2354
- [
2355
- {
2356
- _type: 'func',
2357
- function: 'getAll',
2358
- parameters: [
2359
- {
2360
- _type: 'packageableElementPtr',
2361
- fullPath: _class.path,
2362
- },
2363
- ],
2364
- },
2365
- ],
2366
- );
2367
- }
2368
-
2369
- HACKY__createServiceTestAssertLambda(assertData: string): RawLambda {
2370
- return new RawLambda(
2371
- [
2372
- {
2373
- _type: 'var',
2374
- class: 'meta::pure::mapping::Result',
2375
- multiplicity: { lowerBound: 1, upperBound: 1 },
2376
- name: 'res',
2377
- },
2378
- ],
2379
- [
2380
- {
2381
- _type: 'func',
2382
- function: 'equalJsonStrings',
2383
- parameters: [
2384
- {
2385
- _type: 'func',
2386
- function: 'toString',
2387
- parameters: [
2388
- {
2389
- _type: 'func',
2390
- function: 'toOne',
2391
- parameters: [
2392
- {
2393
- _type: 'property',
2394
- parameters: [
2395
- {
2396
- _type: 'var',
2397
- name: 'res',
2398
- },
2399
- ],
2400
- property: 'values',
2401
- },
2402
- ],
2403
- },
2404
- ],
2405
- },
2406
- {
2407
- _type: 'string',
2408
- multiplicity: {
2409
- lowerBound: 1,
2410
- upperBound: 1,
2411
- },
2412
- values: [assertData],
2413
- },
2414
- ],
2415
- },
2416
- ],
2417
- );
2418
- }
2419
-
2420
- HACKY__extractServiceTestAssertionData(query: RawLambda): string | undefined {
2421
- let json: string | undefined;
2422
- try {
2423
- json = (
2424
- (
2425
- ((query.body as unknown[])[0] as Record<PropertyKey, unknown>) // FunctionValue
2426
- .parameters as unknown[]
2427
- )[1] as {
2428
- values: (string | undefined)[];
2429
- }
2430
- ).values[0];
2431
- assertTrue(typeof json === 'string', `Expected value of type 'string'`);
2432
- } catch (error) {
2433
- assertErrorThrown(error);
2434
- this.log.warn(
2435
- LogEvent.create(GRAPH_MANAGER_EVENT.GRAPH_MANAGER_FAILURE),
2436
- `Can't extract assertion result`,
2437
- );
2438
- json = undefined;
2439
- }
2440
- if (!json) {
2441
- /* Add other assertion cases if we read others */
2442
- }
2443
- return json;
2444
- }
2445
-
2446
- HACKY__createDefaultBlankLambda(): RawLambda {
2447
- return new RawLambda(
2448
- [{ _type: 'var', name: 'x' }],
2449
- [
2450
- {
2451
- _type: 'string',
2452
- multiplicity: { lowerBound: 1, upperBound: 1 },
2453
- values: [''],
2454
- },
2455
- ],
2456
- );
2457
- }
2458
-
2459
2382
  // --------------------------------------------- Utilities ---------------------------------------------
2460
2383
 
2461
2384
  elementToEntity = (
@@ -64,7 +64,7 @@ export class V1_ExecuteInput {
64
64
 
65
65
  export class V1_TestDataGenerationExecutionInput extends V1_ExecuteInput {
66
66
  parameters: (string | number | boolean)[] = [];
67
- hashStrings = false;
67
+ hashValues = false;
68
68
 
69
69
  static override readonly serialization = new SerializationFactory(
70
70
  createModelSchema(V1_TestDataGenerationExecutionInput, {
@@ -77,7 +77,7 @@ export class V1_TestDataGenerationExecutionInput extends V1_ExecuteInput {
77
77
  () => SKIP,
78
78
  ),
79
79
  context: usingModelSchema(V1_rawBaseExecutionContextModelSchema),
80
- hashStrings: primitive(),
80
+ hashValues: primitive(),
81
81
  parameters: list(primitive()),
82
82
  }),
83
83
  );
@@ -17,9 +17,11 @@
17
17
  import { CORE_HASH_STRUCTURE } from '../../../../../../../../../graph/Core_HashUtils.js';
18
18
  import { type Hashable, hashArray } from '@finos/legend-shared';
19
19
 
20
+ type V1_FlatDataPropertyValue = boolean | string | number;
21
+
20
22
  export class V1_FlatDataProperty implements Hashable {
21
23
  name!: string;
22
- value!: boolean | string | number;
24
+ value!: V1_FlatDataPropertyValue;
23
25
 
24
26
  get hashCode(): string {
25
27
  return hashArray([