@finos/legend-graph 0.2.0 → 0.2.5

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 (110) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/lib/GraphManagerState.d.ts +1 -0
  3. package/lib/GraphManagerState.d.ts.map +1 -1
  4. package/lib/GraphManagerState.js +27 -2
  5. package/lib/GraphManagerState.js.map +1 -1
  6. package/lib/GraphManagerStateProvider.js +1 -1
  7. package/lib/GraphManagerStateProvider.js.map +1 -1
  8. package/lib/GraphManagerTestUtils.js +1 -1
  9. package/lib/GraphManagerTestUtils.js.map +1 -1
  10. package/lib/graphManager/action/SourceInformationHelper.d.ts.map +1 -1
  11. package/lib/graphManager/action/SourceInformationHelper.js +3 -1
  12. package/lib/graphManager/action/SourceInformationHelper.js.map +1 -1
  13. package/lib/helpers/MappingResolutionHelper.js +1 -1
  14. package/lib/helpers/MappingResolutionHelper.js.map +1 -1
  15. package/lib/models/metamodels/pure/packageableElements/domain/Association.js +1 -1
  16. package/lib/models/metamodels/pure/packageableElements/domain/Association.js.map +1 -1
  17. package/lib/models/metamodels/pure/packageableElements/mapping/EnumValueMapping.d.ts.map +1 -1
  18. package/lib/models/metamodels/pure/packageableElements/mapping/EnumValueMapping.js +2 -2
  19. package/lib/models/metamodels/pure/packageableElements/mapping/EnumValueMapping.js.map +1 -1
  20. package/lib/models/metamodels/pure/packageableElements/mapping/SetImplementation.d.ts.map +1 -1
  21. package/lib/models/metamodels/pure/packageableElements/mapping/SetImplementation.js +0 -1
  22. package/lib/models/metamodels/pure/packageableElements/mapping/SetImplementation.js.map +1 -1
  23. package/lib/models/metamodels/pure/packageableElements/store/relational/model/RelationalOperationElement.d.ts.map +1 -1
  24. package/lib/models/metamodels/pure/packageableElements/store/relational/model/RelationalOperationElement.js +3 -1
  25. package/lib/models/metamodels/pure/packageableElements/store/relational/model/RelationalOperationElement.js.map +1 -1
  26. package/lib/models/protocols/pure/v1/V1_PureGraphManager.js +3 -3
  27. package/lib/models/protocols/pure/v1/V1_PureGraphManager.js.map +1 -1
  28. package/lib/models/protocols/pure/v1/model/context/V1_PureModelContextPointer.d.ts +3 -3
  29. package/lib/models/protocols/pure/v1/model/context/V1_PureModelContextPointer.d.ts.map +1 -1
  30. package/lib/models/protocols/pure/v1/model/context/{V1_AlloySdlc.d.ts → V1_SDLC.d.ts} +4 -4
  31. package/lib/models/protocols/pure/v1/model/context/V1_SDLC.d.ts.map +1 -0
  32. package/lib/models/protocols/pure/v1/model/context/{V1_AlloySdlc.js → V1_SDLC.js} +3 -3
  33. package/lib/models/protocols/pure/v1/model/context/V1_SDLC.js.map +1 -0
  34. package/lib/models/protocols/pure/v1/model/packageableElements/mapping/V1_ClassMapping.d.ts.map +1 -1
  35. package/lib/models/protocols/pure/v1/model/packageableElements/mapping/V1_ClassMapping.js.map +1 -1
  36. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_DatabaseTransformer.d.ts.map +1 -1
  37. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_DatabaseTransformer.js +4 -2
  38. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_DatabaseTransformer.js.map +1 -1
  39. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.d.ts.map +1 -1
  40. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.js +6 -4
  41. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.js.map +1 -1
  42. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_ValueSpecificationTransformer.d.ts.map +1 -1
  43. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_ValueSpecificationTransformer.js +4 -3
  44. package/lib/models/protocols/pure/v1/transformation/pureGraph/from/V1_ValueSpecificationTransformer.js.map +1 -1
  45. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ExecutionPlanBuilder.d.ts.map +1 -1
  46. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ExecutionPlanBuilder.js +6 -6
  47. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ExecutionPlanBuilder.js.map +1 -1
  48. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_GraphBuilderContext.d.ts.map +1 -1
  49. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_GraphBuilderContext.js +2 -2
  50. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_GraphBuilderContext.js.map +1 -1
  51. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.d.ts.map +1 -1
  52. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.js +4 -4
  53. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.js.map +1 -1
  54. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelGraphThirdPassBuilder.d.ts.map +1 -1
  55. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelGraphThirdPassBuilder.js +3 -3
  56. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelGraphThirdPassBuilder.js.map +1 -1
  57. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.d.ts.map +1 -1
  58. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.js +12 -10
  59. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.js.map +1 -1
  60. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_AssociationMappingHelper.d.ts.map +1 -1
  61. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_AssociationMappingHelper.js +3 -2
  62. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_AssociationMappingHelper.js.map +1 -1
  63. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DatabaseBuilderHelper.d.ts.map +1 -1
  64. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DatabaseBuilderHelper.js +1 -1
  65. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DatabaseBuilderHelper.js.map +1 -1
  66. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.d.ts.map +1 -1
  67. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.js +2 -1
  68. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.js.map +1 -1
  69. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_MappingBuilderHelper.d.ts.map +1 -1
  70. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_MappingBuilderHelper.js.map +1 -1
  71. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ProcessingContext.d.ts +1 -1
  72. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ProcessingContext.d.ts.map +1 -1
  73. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ProcessingContext.js +6 -4
  74. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ProcessingContext.js.map +1 -1
  75. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.d.ts.map +1 -1
  76. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.js +12 -11
  77. package/lib/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.js.map +1 -1
  78. package/lib/models/protocols/pure/v1/transformation/pureProtocol/V1_PureProtocolSerialization.js +8 -8
  79. package/lib/models/protocols/pure/v1/transformation/pureProtocol/V1_PureProtocolSerialization.js.map +1 -1
  80. package/package.json +8 -8
  81. package/src/GraphManagerState.ts +35 -4
  82. package/src/graphManager/action/SourceInformationHelper.ts +3 -1
  83. package/src/helpers/MappingResolutionHelper.ts +3 -3
  84. package/src/models/metamodels/pure/packageableElements/domain/Association.ts +1 -1
  85. package/src/models/metamodels/pure/packageableElements/mapping/EnumValueMapping.ts +7 -2
  86. package/src/models/metamodels/pure/packageableElements/mapping/SetImplementation.ts +0 -1
  87. package/src/models/metamodels/pure/packageableElements/store/relational/model/RelationalOperationElement.ts +3 -1
  88. package/src/models/protocols/pure/v1/V1_PureGraphManager.ts +3 -3
  89. package/src/models/protocols/pure/v1/model/context/V1_PureModelContextPointer.ts +3 -3
  90. package/src/models/protocols/pure/v1/model/context/{V1_AlloySdlc.ts → V1_SDLC.ts} +3 -3
  91. package/src/models/protocols/pure/v1/model/packageableElements/mapping/V1_ClassMapping.ts +0 -1
  92. package/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_DatabaseTransformer.ts +4 -2
  93. package/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.ts +7 -4
  94. package/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_ValueSpecificationTransformer.ts +4 -3
  95. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ExecutionPlanBuilder.ts +32 -6
  96. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_GraphBuilderContext.ts +2 -1
  97. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelClassMappingSecondPassBuilder.ts +6 -3
  98. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelGraphThirdPassBuilder.ts +3 -2
  99. package/src/models/protocols/pure/v1/transformation/pureGraph/to/V1_ProtocolToMetaModelPropertyMappingBuilder.ts +18 -11
  100. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_AssociationMappingHelper.ts +3 -2
  101. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DatabaseBuilderHelper.ts +13 -4
  102. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.ts +2 -1
  103. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_MappingBuilderHelper.ts +3 -1
  104. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ProcessingContext.ts +8 -4
  105. package/src/models/protocols/pure/v1/transformation/pureGraph/to/helpers/V1_ValueSpecificationBuilderHelper.ts +19 -13
  106. package/src/models/protocols/pure/v1/transformation/pureProtocol/V1_PureProtocolSerialization.ts +5 -5
  107. package/tsconfig.json +2 -1
  108. package/tsconfig.package.json +1 -0
  109. package/lib/models/protocols/pure/v1/model/context/V1_AlloySdlc.d.ts.map +0 -1
  110. package/lib/models/protocols/pure/v1/model/context/V1_AlloySdlc.js.map +0 -1
@@ -41,6 +41,8 @@ import type { SetImplementation } from './models/metamodels/pure/packageableElem
41
41
  import type { PackageableElement } from './models/metamodels/pure/packageableElements/PackageableElement';
42
42
  import { EmbeddedFlatDataPropertyMapping } from './models/metamodels/pure/packageableElements/store/flatData/mapping/EmbeddedFlatDataPropertyMapping';
43
43
  import { EmbeddedRelationalInstanceSetImplementation } from './models/metamodels/pure/packageableElements/store/relational/mapping/EmbeddedRelationalInstanceSetImplementation';
44
+ import { InlineEmbeddedRelationalInstanceSetImplementation } from './models/metamodels/pure/packageableElements/store/relational/mapping/InlineEmbeddedRelationalInstanceSetImplementation';
45
+ import { OtherwiseEmbeddedRelationalInstanceSetImplementation } from './models/metamodels/pure/packageableElements/store/relational/mapping/OtherwiseEmbeddedRelationalInstanceSetImplementation';
44
46
  import { getGraphManager } from './models/protocols/pure/Pure';
45
47
 
46
48
  export class GraphManagerState {
@@ -154,6 +156,35 @@ export class GraphManagerState {
154
156
  );
155
157
  }
156
158
 
159
+ getInstanceSetImplementationPropertyMappings(
160
+ instanceSetImpl: InstanceSetImplementation,
161
+ ): PropertyMapping[] {
162
+ if (
163
+ instanceSetImpl instanceof
164
+ InlineEmbeddedRelationalInstanceSetImplementation
165
+ ) {
166
+ return this.getMappingElementPropertyMappings(
167
+ instanceSetImpl.inlineSetImplementation,
168
+ );
169
+ } else if (
170
+ instanceSetImpl instanceof
171
+ OtherwiseEmbeddedRelationalInstanceSetImplementation
172
+ ) {
173
+ // NOTE: for now we will grab all property mappings from the main otherwise embedded mapping and the otherwise property mapping.
174
+ // In the future we may want to incorporate some smartness as to when the otherwise set implementation isinvoked.
175
+ const otherwiseSetImpl =
176
+ instanceSetImpl.otherwisePropertyMapping.targetSetImplementation;
177
+ const otherwisePropertyMappings = otherwiseSetImpl
178
+ ? this.getMappingElementPropertyMappings(otherwiseSetImpl)
179
+ : [];
180
+ return [
181
+ ...instanceSetImpl.propertyMappings,
182
+ ...otherwisePropertyMappings,
183
+ ];
184
+ }
185
+ return instanceSetImpl.propertyMappings;
186
+ }
187
+
157
188
  getMappingElementPropertyMappings(
158
189
  mappingElement:
159
190
  | EnumerationMapping
@@ -161,10 +192,10 @@ export class GraphManagerState {
161
192
  | AssociationImplementation,
162
193
  ): PropertyMapping[] {
163
194
  let mappedProperties: PropertyMapping[] = [];
164
- if (
165
- this.isInstanceSetImplementation(mappingElement) ||
166
- mappingElement instanceof AssociationImplementation
167
- ) {
195
+ if (this.isInstanceSetImplementation(mappingElement)) {
196
+ mappedProperties =
197
+ this.getInstanceSetImplementationPropertyMappings(mappingElement);
198
+ } else if (mappingElement instanceof AssociationImplementation) {
168
199
  mappedProperties = mappingElement.propertyMappings;
169
200
  } else if (mappingElement instanceof OperationSetImplementation) {
170
201
  mappedProperties = mappingElement.leafSetImplementations
@@ -17,7 +17,9 @@
17
17
  import { assertTrue } from '@finos/legend-shared';
18
18
  import type { SourceInformation } from './SourceInformation';
19
19
 
20
- const COORDINATE_DELIMITER = '__';
20
+ // NOTE: @ is chosen because it is not part of identifier token in Pure grammar
21
+ // TODO: handle the case of quote identifier e.g. model::something::'I have an @ in me'
22
+ const COORDINATE_DELIMITER = '@';
21
23
 
22
24
  export const extractSourceInformationCoordinates = (
23
25
  sourceInformation: SourceInformation | undefined,
@@ -44,7 +44,7 @@ export const updateRootSetImplementationOnCreate = (
44
44
  if (classMappingsWithSimilarTarget.length) {
45
45
  setImp.setRoot(false);
46
46
  if (classMappingsWithSimilarTarget.length === 1) {
47
- classMappingsWithSimilarTarget[0].setRoot(false);
47
+ (classMappingsWithSimilarTarget[0] as SetImplementation).setRoot(false);
48
48
  }
49
49
  } else {
50
50
  setImp.setRoot(true);
@@ -64,7 +64,7 @@ export const updateRootSetImplementationOnDelete = (
64
64
  setImp.class.value,
65
65
  ).filter((si) => si !== setImp);
66
66
  if (classMappingsWithSimilarTarget.length === 1) {
67
- classMappingsWithSimilarTarget[0].setRoot(false);
67
+ (classMappingsWithSimilarTarget[0] as SetImplementation).setRoot(false);
68
68
  }
69
69
  };
70
70
 
@@ -98,7 +98,7 @@ export const findRootSetImplementation = (
98
98
  // if there is not root set, and only one set implementation is found, we assume that is the root
99
99
  if (
100
100
  classMappingsWithSimilarTarget.length === 1 &&
101
- classMappingsWithSimilarTarget[0].root.value === false
101
+ classMappingsWithSimilarTarget[0]?.root.value === false
102
102
  ) {
103
103
  classMappingsWithSimilarTarget[0].setRoot(true);
104
104
  return classMappingsWithSimilarTarget[0];
@@ -105,7 +105,7 @@ export class Association
105
105
  idx !== -1,
106
106
  `Can't find property '${property.name}' in association '${this.path}'`,
107
107
  );
108
- return this.properties[(idx + 1) % 2];
108
+ return guaranteeNonNullable(this.properties[(idx + 1) % 2]);
109
109
  };
110
110
  getPropertyAssociatedClass = (property: AbstractProperty): Class => {
111
111
  if (property instanceof Property) {
@@ -15,7 +15,12 @@
15
15
  */
16
16
 
17
17
  import { observable, action, computed, makeObservable } from 'mobx';
18
- import { uuid, isNumber, hashArray } from '@finos/legend-shared';
18
+ import {
19
+ uuid,
20
+ isNumber,
21
+ hashArray,
22
+ guaranteeNonNullable,
23
+ } from '@finos/legend-shared';
19
24
  import {
20
25
  CORE_HASH_STRUCTURE,
21
26
  PRIMITIVE_TYPE,
@@ -82,7 +87,7 @@ export class EnumValueMapping implements Hashable, Stubable {
82
87
  val: Enum | string | undefined,
83
88
  sourceType: Type | undefined,
84
89
  ): void {
85
- const sourceValue = this.sourceValues[idx];
90
+ const sourceValue = guaranteeNonNullable(this.sourceValues[idx]);
86
91
  // If the source type is an enumeration but the value does NOT match an enum value (most likely user is mid typing an enum value)
87
92
  // we move on to update the source value with the string value
88
93
  if (
@@ -135,7 +135,6 @@ export enum BASIC_SET_IMPLEMENTATION_TYPE {
135
135
  INSTANCE = 'instance',
136
136
  }
137
137
 
138
- /* @MARKER: NEW CLASS MAPPING TYPE SUPPORT --- consider adding class mapping type handler here whenever support for a new one is added to the app */
139
138
  export enum SET_IMPLEMENTATION_TYPE {
140
139
  OPERATION = 'operation',
141
140
  PUREINSTANCE = 'pureInstance',
@@ -167,7 +167,9 @@ export class JoinTreeNode {
167
167
  */
168
168
  export const extractLine = (joinTreeNode: JoinTreeNode): JoinTreeNode[] =>
169
169
  [joinTreeNode].concat(
170
- joinTreeNode.children.length ? extractLine(joinTreeNode.children[0]) : [],
170
+ joinTreeNode.children.length
171
+ ? extractLine(joinTreeNode.children[0] as JoinTreeNode)
172
+ : [],
171
173
  );
172
174
 
173
175
  export class RelationalOperationElementWithJoin extends RelationalOperationElement {
@@ -135,7 +135,7 @@ import { V1_GenerationSpecification } from './model/packageableElements/generati
135
135
  import { V1_Mapping } from './model/packageableElements/mapping/V1_Mapping';
136
136
  import { V1_ConcreteFunctionDefinition } from './model/packageableElements/function/V1_ConcreteFunctionDefinition';
137
137
  import { V1_PureModelContextComposite } from './model/context/V1_PureModelContextComposite';
138
- import { V1_AlloySdlc } from './model/context/V1_AlloySdlc';
138
+ import { V1_AlloySDLC } from './model/context/V1_SDLC';
139
139
  import { V1_Protocol } from './model/V1_Protocol';
140
140
  import type { V1_PureModelContext } from './model/context/V1_PureModelContext';
141
141
  import type { V1_ElementBuilder } from './transformation/pureGraph/to/V1_ElementBuilder';
@@ -1965,7 +1965,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1965
1965
  break;
1966
1966
  }
1967
1967
  case ServiceExecutionMode.SEMI_INTERACTIVE: {
1968
- const sdlcInfo = new V1_AlloySdlc(groupdId, artifactId, version);
1968
+ const sdlcInfo = new V1_AlloySDLC(groupdId, artifactId, version);
1969
1969
  const pointer = new V1_PureModelContextPointer(protocol, sdlcInfo);
1970
1970
  // data
1971
1971
  const data = new V1_PureModelContextData();
@@ -1991,7 +1991,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
1991
1991
  break;
1992
1992
  }
1993
1993
  case ServiceExecutionMode.PROD: {
1994
- const sdlcInfo = new V1_AlloySdlc(groupdId, artifactId, version);
1994
+ const sdlcInfo = new V1_AlloySDLC(groupdId, artifactId, version);
1995
1995
  const pointer = new V1_PureModelContextPointer(protocol, sdlcInfo);
1996
1996
  sdlcInfo.packageableElementPointers = [
1997
1997
  new V1_PackageableElementPointer(
@@ -14,15 +14,15 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import type { V1_Sdlc } from '../../model/context/V1_AlloySdlc';
17
+ import type { V1_SDLC } from './V1_SDLC';
18
18
  import type { V1_Protocol } from '../../model/V1_Protocol';
19
19
  import { V1_PureModelContext } from './V1_PureModelContext';
20
20
 
21
21
  export class V1_PureModelContextPointer extends V1_PureModelContext {
22
22
  serializer: V1_Protocol;
23
- sdlcInfo?: V1_Sdlc | undefined;
23
+ sdlcInfo?: V1_SDLC | undefined;
24
24
 
25
- constructor(protocol: V1_Protocol, sdlc?: V1_Sdlc) {
25
+ constructor(protocol: V1_Protocol, sdlc?: V1_SDLC) {
26
26
  super();
27
27
  this.serializer = protocol;
28
28
  this.sdlcInfo = sdlc;
@@ -14,9 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import type { V1_PackageableElementPointer } from '../../model/packageableElements/V1_PackageableElement';
17
+ import type { V1_PackageableElementPointer } from '../packageableElements/V1_PackageableElement';
18
18
 
19
- export abstract class V1_Sdlc {
19
+ export abstract class V1_SDLC {
20
20
  baseVersion = 'latest';
21
21
  version: string;
22
22
  packageableElementPointers: V1_PackageableElementPointer[] = [];
@@ -26,7 +26,7 @@ export abstract class V1_Sdlc {
26
26
  }
27
27
  }
28
28
 
29
- export class V1_AlloySdlc extends V1_Sdlc {
29
+ export class V1_AlloySDLC extends V1_SDLC {
30
30
  groupId: string;
31
31
  artifactId: string;
32
32
 
@@ -25,7 +25,6 @@ import type { V1_OperationClassMapping } from './V1_OperationClassMapping';
25
25
  import type { V1_PureInstanceClassMapping } from '../../../model/packageableElements/store/modelToModel/mapping/V1_PureInstanceClassMapping';
26
26
  import type { V1_RootFlatDataClassMapping } from '../../../model/packageableElements/store/flatData/mapping/V1_RootFlatDataClassMapping';
27
27
 
28
- /* @MARKER: NEW CLASS MAPPING TYPE SUPPORT --- consider adding class mapping type handler here whenever support for a new one is added to the app */
29
28
  export interface V1_ClassMappingVisitor<T> {
30
29
  visit_ClassMapping(classMapping: V1_ClassMapping): T;
31
30
  visit_OperationClassMapping(classMapping: V1_OperationClassMapping): T;
@@ -174,7 +174,8 @@ export const V1_transformTableAliasToTablePointer = (
174
174
  tablePtr.database = options?.TEMPORARY__resolveToFullPath
175
175
  ? tableAlias.relation.ownerReference.value.path
176
176
  : tableAlias.relation.ownerReference.valueForSerialization ?? '';
177
- /* @MARKER: GRAMMAR ROUNDTRIP --- omit this information during protocol transformation as it can be interpreted while building the graph */
177
+ // FIXME: Sometimes, we interpret this, so to maintain roundtrip stability, we need to handle this differrently
178
+ // See https://github.com/finos/legend-studio/issues/295
178
179
  tablePtr.mainTableDb = tablePtr.database;
179
180
  tablePtr.schema = tableAlias.isSelfJoinTarget
180
181
  ? SELF_JOIN_SCHEMA_NAME
@@ -188,7 +189,8 @@ export const V1_transformTableAliasToTablePointer = (
188
189
  export const V1_transformTableToTablePointer = (table: Table): V1_TablePtr => {
189
190
  const tablePtr = new V1_TablePtr();
190
191
  tablePtr.database = table.schema.owner.path;
191
- /* @MARKER: GRAMMAR ROUNDTRIP --- omit this information during protocol transformation as it can be interpreted while building the graph */
192
+ // FIXME: Sometimes, we interpret this, so to maintain roundtrip stability, we need to handle this differrently
193
+ // See https://github.com/finos/legend-studio/issues/295
192
194
  tablePtr.mainTableDb = tablePtr.database;
193
195
  tablePtr.schema = table.schema.name;
194
196
  tablePtr.table = table.name;
@@ -141,6 +141,7 @@ import type { V1_GraphTransformerContext } from './V1_GraphTransformerContext';
141
141
  import { toJS } from 'mobx';
142
142
  import type { DSLMapping_PureProtocolProcessorPlugin_Extension } from '../../../../DSLMapping_PureProtocolProcessorPlugin_Extension';
143
143
  import type { InstanceSetImplementation } from '../../../../../../metamodels/pure/packageableElements/mapping/InstanceSetImplementation';
144
+ import type { SubstituteStore } from '../../../../../../metamodels/pure/packageableElements/mapping/SubstituteStore';
144
145
 
145
146
  export const V1_transformPropertyReference = (
146
147
  element: PropertyReference,
@@ -308,7 +309,7 @@ const transformMappingTest = (
308
309
  return test;
309
310
  };
310
311
 
311
- // Include V1_Mapping
312
+ // Include Mapping
312
313
 
313
314
  const transformMappingInclude = (
314
315
  element: MappingInclude,
@@ -316,15 +317,17 @@ const transformMappingInclude = (
316
317
  const mappingInclude = new V1_MappingInclude();
317
318
  mappingInclude.includedMapping = element.included.valueForSerialization ?? '';
318
319
  mappingInclude.sourceDatabasePath = element.storeSubstitutions.length
319
- ? element.storeSubstitutions[0].original.valueForSerialization ?? ''
320
+ ? (element.storeSubstitutions[0] as SubstituteStore).original
321
+ .valueForSerialization ?? ''
320
322
  : undefined;
321
323
  mappingInclude.targetDatabasePath = element.storeSubstitutions.length
322
- ? element.storeSubstitutions[0].substitute.valueForSerialization ?? ''
324
+ ? (element.storeSubstitutions[0] as SubstituteStore).substitute
325
+ .valueForSerialization ?? ''
323
326
  : undefined;
324
327
  return mappingInclude;
325
328
  };
326
329
 
327
- // Class V1_Mapping
330
+ // Class Mapping
328
331
 
329
332
  const transformOptionalPropertyMappingTransformer = (
330
333
  value: EnumerationMapping | undefined,
@@ -112,7 +112,7 @@ class V1_ValueSpecificationTransformer
112
112
  valueSpecification: RootGraphFetchTreeInstanceValue,
113
113
  ): V1_ValueSpecification {
114
114
  return V1_transformGraphFetchTree(
115
- valueSpecification.values[0],
115
+ guaranteeNonNullable(valueSpecification.values[0]),
116
116
  this.inScope,
117
117
  this.open,
118
118
  this.isParameter,
@@ -124,7 +124,7 @@ class V1_ValueSpecificationTransformer
124
124
  valueSpecification: PropertyGraphFetchTreeInstanceValue,
125
125
  ): V1_ValueSpecification {
126
126
  return V1_transformGraphFetchTree(
127
- valueSpecification.values[0],
127
+ guaranteeNonNullable(valueSpecification.values[0]),
128
128
  this.inScope,
129
129
  this.open,
130
130
  this.isParameter,
@@ -200,6 +200,7 @@ class V1_ValueSpecificationTransformer
200
200
  }
201
201
  case PRIMITIVE_TYPE.LATESTDATE: {
202
202
  const cPrimitiveType = new V1_CLatestDate();
203
+ cPrimitiveType.multiplicity = multiplicity;
203
204
  return cPrimitiveType;
204
205
  }
205
206
  default:
@@ -252,7 +253,7 @@ class V1_ValueSpecificationTransformer
252
253
  valueSpecification: EnumValueInstanceValue,
253
254
  ): V1_ValueSpecification {
254
255
  const _enumValue = new V1_EnumValue();
255
- const _enum = valueSpecification.values[0].value;
256
+ const _enum = guaranteeNonNullable(valueSpecification.values[0]).value;
256
257
  _enumValue.value = _enum.name;
257
258
  _enumValue.fullPath = _enum.owner.path;
258
259
  return _enumValue;
@@ -96,19 +96,45 @@ const parseDataType = (val: string): RelationalDataType => {
96
96
  return new Other();
97
97
  default: {
98
98
  if (val.match(/^VARCHAR\(\d+\)$/)) {
99
- return new VarChar(getTypeParams(val)[0]);
99
+ return new VarChar(
100
+ guaranteeNonNullable(
101
+ getTypeParams(val)[0],
102
+ `VARCHAR type size is missing`,
103
+ ),
104
+ );
100
105
  } else if (val.match(/^CHAR\(\d+\)$/)) {
101
- return new Char(getTypeParams(val)[0]);
106
+ return new Char(
107
+ guaranteeNonNullable(
108
+ getTypeParams(val)[0],
109
+ `VAR type size is missing`,
110
+ ),
111
+ );
102
112
  } else if (val.match(/^VARBINARY\(\d+\)$/)) {
103
- return new VarBinary(getTypeParams(val)[0]);
113
+ return new VarBinary(
114
+ guaranteeNonNullable(
115
+ getTypeParams(val)[0],
116
+ `VARBINARY type size is missing`,
117
+ ),
118
+ );
104
119
  } else if (val.match(/^BINARY\(\d+\)$/)) {
105
- return new Binary(getTypeParams(val)[0]);
120
+ return new Binary(
121
+ guaranteeNonNullable(
122
+ getTypeParams(val)[0],
123
+ `BINARY type size is missing`,
124
+ ),
125
+ );
106
126
  } else if (val.match(/^DECIMAL\(\d+\)$/)) {
107
127
  const params = getTypeParams(val);
108
- return new Decimal(params[0], params[1]);
128
+ return new Decimal(
129
+ guaranteeNonNullable(params[0], `Decimal type precision is missing`),
130
+ guaranteeNonNullable(params[1], `Decimal type scale is missing`),
131
+ );
109
132
  } else if (val.match(/^NUMERIC\(\d+\)$/)) {
110
133
  const params = getTypeParams(val);
111
- return new Numeric(params[0], params[1]);
134
+ return new Numeric(
135
+ guaranteeNonNullable(params[0], `Decimal type precision is missing`),
136
+ guaranteeNonNullable(params[1], `Decimal type scale is missing`),
137
+ );
112
138
  }
113
139
  throw new UnsupportedOperationError(`Can't parse data type '${val}'`);
114
140
  }
@@ -21,6 +21,7 @@ import {
21
21
  import type { Log } from '@finos/legend-shared';
22
22
  import {
23
23
  uniq,
24
+ guaranteeNonNullable,
24
25
  assertNonEmptyString,
25
26
  guaranteeType,
26
27
  } from '@finos/legend-shared';
@@ -161,7 +162,7 @@ export class V1_GraphBuilderContext {
161
162
  isFullPath: true,
162
163
  };
163
164
  case 1:
164
- return Array.from(results.values())[0];
165
+ return guaranteeNonNullable(Array.from(results.values())[0]);
165
166
  default:
166
167
  throw new GraphBuilderError(
167
168
  undefined,
@@ -22,6 +22,7 @@ import {
22
22
  guaranteeType,
23
23
  assertNonEmptyString,
24
24
  assertTrue,
25
+ guaranteeNonNullable,
25
26
  } from '@finos/legend-shared';
26
27
  import { GRAPH_MANAGER_LOG_EVENT } from '../../../../../../../graphManager/GraphManagerLogEvent';
27
28
  import type { Mapping } from '../../../../../../metamodels/pure/packageableElements/mapping/Mapping';
@@ -154,7 +155,7 @@ export class V1_ProtocolToMetaModelClassMappingSecondPassBuilder
154
155
  this.context,
155
156
  pureInstanceSetImplementation,
156
157
  pureInstanceSetImplementation,
157
- this.parent.enumerationMappings,
158
+ getAllEnumerationMappings(this.parent),
158
159
  ),
159
160
  ),
160
161
  ) as PurePropertyMapping[];
@@ -270,7 +271,9 @@ export class V1_ProtocolToMetaModelClassMappingSecondPassBuilder
270
271
  );
271
272
  mainTableAlias = new TableAlias();
272
273
  mainTableAlias.name = '';
273
- mainTableAlias.relation = Array.from(tables.values())[0];
274
+ mainTableAlias.relation = guaranteeNonNullable(
275
+ Array.from(tables.values())[0],
276
+ );
274
277
  mainTableAlias.database = Array.from(dbs.values())[0];
275
278
  rootRelationalInstanceSetImplementation.mainTableAlias = mainTableAlias;
276
279
  }
@@ -315,7 +318,7 @@ export class V1_ProtocolToMetaModelClassMappingSecondPassBuilder
315
318
  this.context,
316
319
  aggragetionAwareInstanceSetImplementation,
317
320
  aggragetionAwareInstanceSetImplementation,
318
- this.parent.enumerationMappings,
321
+ getAllEnumerationMappings(this.parent),
319
322
  new Map<string, TableAlias>(),
320
323
  [
321
324
  ...getAllClassMappings(mapping),
@@ -19,6 +19,7 @@ import {
19
19
  assertTrue,
20
20
  isNonNullable,
21
21
  assertErrorThrown,
22
+ guaranteeNonNullable,
22
23
  } from '@finos/legend-shared';
23
24
  import { CORE_ELEMENT_PATH } from '../../../../../../../MetaModelConst';
24
25
  import { Class } from '../../../../../../metamodels/pure/packageableElements/domain/Class';
@@ -117,8 +118,8 @@ export class V1_ProtocolToMetaModelGraphThirdPassBuilder
117
118
  const association = this.context.graph.getAssociation(
118
119
  this.context.graph.buildPath(element.package, element.name),
119
120
  );
120
- const first = element.properties[0];
121
- const second = element.properties[1];
121
+ const first = guaranteeNonNullable(element.properties[0]);
122
+ const second = guaranteeNonNullable(element.properties[1]);
122
123
  association.setProperties([
123
124
  V1_buildAssociationProperty(first, second, this.context, association),
124
125
  V1_buildAssociationProperty(second, first, this.context, association),
@@ -40,10 +40,7 @@ import { InferableMappingElementIdExplicitValue } from '../../../../../../metamo
40
40
  import type { PackageableElementReference } from '../../../../../../metamodels/pure/packageableElements/PackageableElementReference';
41
41
  import { PackageableElementImplicitReference } from '../../../../../../metamodels/pure/packageableElements/PackageableElementReference';
42
42
  import type { PropertyReference } from '../../../../../../metamodels/pure/packageableElements/domain/PropertyReference';
43
- import {
44
- PropertyImplicitReference,
45
- PropertyExplicitReference,
46
- } from '../../../../../../metamodels/pure/packageableElements/domain/PropertyReference';
43
+ import { PropertyImplicitReference } from '../../../../../../metamodels/pure/packageableElements/domain/PropertyReference';
47
44
  import { RootRelationalInstanceSetImplementation } from '../../../../../../metamodels/pure/packageableElements/store/relational/mapping/RootRelationalInstanceSetImplementation';
48
45
  import { OtherwiseEmbeddedRelationalInstanceSetImplementation } from '../../../../../../metamodels/pure/packageableElements/store/relational/mapping/OtherwiseEmbeddedRelationalInstanceSetImplementation';
49
46
  import { EmbeddedRelationalInstanceSetImplementation } from '../../../../../../metamodels/pure/packageableElements/store/relational/mapping/EmbeddedRelationalInstanceSetImplementation';
@@ -80,6 +77,7 @@ import {
80
77
  import { V1_transformRelationalOperationElement } from '../from/V1_DatabaseTransformer';
81
78
  import { V1_GraphTransformerContextBuilder } from '../from/V1_GraphTransformerContext';
82
79
  import {
80
+ getAllEnumerationMappings,
83
81
  getClassMappingById,
84
82
  getClassMappingsByClass,
85
83
  } from '../../../../../../../helpers/MappingHelper';
@@ -638,7 +636,9 @@ export class V1_ProtocolToMetaModelPropertyMappingBuilder
638
636
  this.context,
639
637
  embedded,
640
638
  this.topParent,
641
- this.topParent?.parent.enumerationMappings ?? [],
639
+ this.topParent?.parent
640
+ ? getAllEnumerationMappings(this.topParent.parent)
641
+ : [],
642
642
  this.tableAliasMap,
643
643
  ),
644
644
  ),
@@ -696,7 +696,9 @@ export class V1_ProtocolToMetaModelPropertyMappingBuilder
696
696
  this.context,
697
697
  otherwiseEmbedded,
698
698
  this.topParent,
699
- this.topParent?.parent.enumerationMappings ?? [],
699
+ this.topParent?.parent
700
+ ? getAllEnumerationMappings(this.topParent.parent)
701
+ : [],
700
702
  this.tableAliasMap,
701
703
  ),
702
704
  ),
@@ -707,7 +709,9 @@ export class V1_ProtocolToMetaModelPropertyMappingBuilder
707
709
  this.context,
708
710
  otherwiseEmbedded,
709
711
  this.topParent,
710
- this.topParent?.parent.enumerationMappings ?? [],
712
+ this.topParent?.parent
713
+ ? getAllEnumerationMappings(this.topParent.parent)
714
+ : [],
711
715
  this.tableAliasMap,
712
716
  ),
713
717
  ),
@@ -750,10 +754,13 @@ export class V1_ProtocolToMetaModelPropertyMappingBuilder
750
754
  );
751
755
  const xStorePropertyMapping = new XStorePropertyMapping(
752
756
  xStoreParent,
753
- // NOTE: this should be `implicit` because this comes from an association
754
- // that we should have inferred. But we need to test the impact of changing it to `implicit`.
755
- // This might cause bugs in the future.
756
- PropertyExplicitReference.create(property),
757
+ PropertyImplicitReference.create(
758
+ PackageableElementImplicitReference.create(
759
+ _association,
760
+ protocol.property.class,
761
+ ),
762
+ property,
763
+ ),
757
764
  guaranteeNonNullable(sourceSetImplementation),
758
765
  targetSetImplementation,
759
766
  );
@@ -27,6 +27,7 @@ import { V1_ProtocolToMetaModelPropertyMappingBuilder } from '../../../../transf
27
27
  import type { V1_AssociationMapping } from '../../../../model/packageableElements/mapping/V1_AssociationMapping';
28
28
  import { V1_XStoreAssociationMapping } from '../../../../model/packageableElements/mapping/xStore/V1_XStoreAssociationMapping';
29
29
  import { XStoreAssociationImplementation } from '../../../../../../../metamodels/pure/packageableElements/mapping/xStore/XStoreAssociationImplementation';
30
+ import { getAllEnumerationMappings } from '../../../../../../../../helpers/MappingHelper';
30
31
 
31
32
  const getInferredAssociationMappingId = (
32
33
  _association: Association,
@@ -63,7 +64,7 @@ const buildRelationalAssociationMapping = (
63
64
  context,
64
65
  relationalAssociationImplementation,
65
66
  undefined,
66
- parentMapping.enumerationMappings,
67
+ getAllEnumerationMappings(parentMapping),
67
68
  undefined,
68
69
  allClassMappings,
69
70
  ),
@@ -96,7 +97,7 @@ const buildXStoreAssociationMapping = (
96
97
  context,
97
98
  xStoreAssociationImplementation,
98
99
  undefined,
99
- parentMapping.enumerationMappings,
100
+ getAllEnumerationMappings(parentMapping),
100
101
  undefined,
101
102
  allClassMappings,
102
103
  xStoreAssociationImplementation,
@@ -218,7 +218,10 @@ const buildJoinTreeNode = (
218
218
  joins: { joinReference: JoinReference; joinType?: JoinType | undefined }[],
219
219
  context: V1_GraphBuilderContext,
220
220
  ): JoinTreeNode => {
221
- const joinWithJoinType = joins[0];
221
+ const joinWithJoinType = guaranteeNonNullable(
222
+ joins[0],
223
+ `Can't build join tree node: at least one child node is expected`,
224
+ );
222
225
  const res = new JoinTreeNode(
223
226
  joinWithJoinType.joinReference,
224
227
  joinWithJoinType.joinType,
@@ -599,7 +602,7 @@ export const V1_buildDatabaseJoin = (
599
602
  selfJoinTargets.length !== 0,
600
603
  `Can't build join of 1 table, unless it is a self-join. Please use the '{target}' notation in order to define a directed self-join`,
601
604
  );
602
- const existingAlias = aliases[0];
605
+ const existingAlias = aliases[0] as TableAlias;
603
606
  const existingAliasName = existingAlias.name;
604
607
  const existingRelationalElement = existingAlias.relation;
605
608
  const tableAlias = new TableAlias();
@@ -628,8 +631,14 @@ export const V1_buildDatabaseJoin = (
628
631
  });
629
632
  }
630
633
  join.aliases = [
631
- new Pair<TableAlias, TableAlias>(aliases[0], aliases[1]),
632
- new Pair<TableAlias, TableAlias>(aliases[1], aliases[0]),
634
+ new Pair<TableAlias, TableAlias>(
635
+ aliases[0] as TableAlias,
636
+ aliases[1] as TableAlias,
637
+ ),
638
+ new Pair<TableAlias, TableAlias>(
639
+ aliases[1] as TableAlias,
640
+ aliases[0] as TableAlias,
641
+ ),
633
642
  ];
634
643
  join.owner = database;
635
644
  return join;
@@ -248,7 +248,8 @@ const isCompatibleDerivedProperty = (
248
248
  ): boolean =>
249
249
  o.name === name &&
250
250
  Array.isArray(o.parameters) &&
251
- o.parameters.length === params.length;
251
+ // We add 1 to account for the `this` parameter in the derived property
252
+ o.parameters.length + 1 === params.length;
252
253
 
253
254
  export const V1_getAppliedProperty = (
254
255
  parentClass: Class,
@@ -303,7 +303,9 @@ export const V1_resolveClassMappingRoot = (mapping: Mapping): void => {
303
303
  Array.from(classToSetImplMap.entries()).forEach((entries) => {
304
304
  const _classMappings = entries[1];
305
305
  if (_classMappings.size === 1) {
306
- const classMapping = Array.from(_classMappings.values())[0];
306
+ const classMapping = Array.from(
307
+ _classMappings.values(),
308
+ )[0] as SetImplementation;
307
309
  // ensure you are only altering current mapping
308
310
  if (
309
311
  classMapping.root.value === false &&
@@ -43,20 +43,24 @@ export class V1_ProcessingContext {
43
43
  return this.tags;
44
44
  }
45
45
 
46
- getLastInferredVariableList(): Map<string, ValueSpecification> {
47
- return this.inferredVariableList[this.inferredVariableList.length - 1];
46
+ private get lastInferredVariableList():
47
+ | Map<string, ValueSpecification>
48
+ | undefined {
49
+ return this.inferredVariableList.length
50
+ ? this.inferredVariableList[this.inferredVariableList.length - 1]
51
+ : undefined;
48
52
  }
49
53
 
50
54
  addInferredVariables(name: string, variable: ValueSpecification): void {
51
55
  if (!this.inferredVariableList.length) {
52
56
  this.addVariableToNewLevel(name, variable);
53
57
  } else {
54
- this.getLastInferredVariableList().set(name, variable);
58
+ this.lastInferredVariableList?.set(name, variable);
55
59
  }
56
60
  }
57
61
 
58
62
  flushVariable(name: string): void {
59
- this.getLastInferredVariableList().delete(name);
63
+ this.lastInferredVariableList?.delete(name);
60
64
  }
61
65
 
62
66
  removeLastVariableLevel(): void {