Skip to content

Commit

Permalink
change dataReference to handle any type of packagable element (#2951)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Feb 27, 2024
1 parent 506a09c commit aaf4fab
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changeset/lazy-swans-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-graph': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,10 @@ export const TEST_DATA__SERVICE_WITH_ONLY_QUERY_Roundtrip = [
{
data: {
_type: 'reference',
dataElement: 'data::RelationalData',
dataElement: {
type: 'DATA',
path: 'data::RelationalData',
},
},
id: 'connection_1',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../../../../../../graph/Core_HashUtils.js';
import type { V1_RelationalCSVData } from './V1_RelationalCSVData.js';
import type { V1_INTERNAL__UnknownEmbeddedData } from './V1_INTERNAL__UnknownEmbeddedData.js';
import type { V1_PackageableElementPointer } from '../packageableElements/V1_PackageableElement.js';

export interface V1_EmbeddedDataVisitor<T> {
visit_EmbeddedData(data: V1_EmbeddedData): T;
Expand All @@ -44,12 +45,12 @@ export class V1_DataElementReference
extends V1_EmbeddedData
implements Hashable
{
dataElement!: string;
dataElement!: V1_PackageableElementPointer;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.DATA_ELEMENT_REFERENCE,
this.dataElement,
this.dataElement.path,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ import {
V1_RelationalCSVDataTable,
} from '../../../model/data/V1_RelationalCSVData.js';
import { V1_DataElement } from '../../../model/packageableElements/data/V1_DataElement.js';
import { V1_initPackageableElement } from './V1_CoreTransformerHelper.js';
import {
V1_initPackageableElement,
V1_transformElementReferencePointer,
} from './V1_CoreTransformerHelper.js';
import {
V1_transformStereotype,
V1_transformTaggedValue,
} from './V1_DomainTransformer.js';
import type { V1_GraphTransformerContext } from './V1_GraphTransformerContext.js';
import { INTERNAL__UnknownEmbeddedData } from '../../../../../../../graph/metamodel/pure/data/INTERNAL__UnknownEmbeddedData.js';
import { V1_INTERNAL__UnknownEmbeddedData } from '../../../model/data/V1_INTERNAL__UnknownEmbeddedData.js';
import { PackageableElementPointerType } from '../../../../../../../graph/MetaModelConst.js';

// ----------------------------------------------- DATA ----------------------------------------

Expand Down Expand Up @@ -112,8 +116,10 @@ const V1_transformDataElementReference = (
element: DataElementReference,
): V1_DataElementReference => {
const dataElementReference = new V1_DataElementReference();
dataElementReference.dataElement =
element.dataElement.valueForSerialization ?? '';
dataElementReference.dataElement = V1_transformElementReferencePointer(
PackageableElementPointerType.DATA,
element.dataElement,
);
return dataElementReference;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class V1_EmbeddedDataBuilder implements V1_EmbeddedDataVisitor<EmbeddedData> {
): EmbeddedData {
const metamodel = new DataElementReference();
metamodel.dataElement = this.context.resolveDataElement(
dataElementReference.dataElement,
dataElementReference.dataElement.path,
);
return metamodel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
usingModelSchema,
customListWithSchema,
optionalCustomList,
isString,
} from '@finos/legend-shared';
import {
createModelSchema,
Expand Down Expand Up @@ -54,6 +55,9 @@ import {
V1_taggedValueModelSchema,
} from './V1_DomainSerializationHelper.js';
import { V1_INTERNAL__UnknownEmbeddedData } from '../../../model/data/V1_INTERNAL__UnknownEmbeddedData.js';
import { V1_packageableElementPointerModelSchema } from './V1_CoreSerializationHelper.js';
import { V1_PackageableElementPointer } from '../../../model/packageableElements/V1_PackageableElement.js';
import { PackageableElementPointerType } from '../../../../../../../graph/MetaModelConst.js';

export const V1_DATA_ELEMENT_PROTOCOL_TYPE = 'dataElement';

Expand Down Expand Up @@ -136,11 +140,27 @@ export const V1_externalFormatDataModelSchema = createModelSchema(
},
);

const V1_serializeDataElementReferenceValue = (
json: PlainObject<V1_PackageableElementPointer> | string,
): V1_PackageableElementPointer => {
// For backward compatible: see https://github.com/finos/legend-engine/pull/2621
if (isString(json)) {
return new V1_PackageableElementPointer(
PackageableElementPointerType.DATA,
json,
);
}
return deserialize(V1_packageableElementPointerModelSchema, json);
};

export const V1_dataElementReferenceModelSchema = createModelSchema(
V1_DataElementReference,
{
_type: usingConstantValueSchema(V1_EmbeddedDataType.DATA_ELEMENT_REFERENCE),
dataElement: primitive(),
dataElement: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) => V1_serializeDataElementReferenceValue(val),
),
},
);

Expand Down
1 change: 1 addition & 0 deletions packages/legend-graph/src/graph/MetaModelConst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export enum PackageableElementPointerType {
FUNCTION = 'FUNCTION',
FILE_GENERATION = 'FILE_GENERATION',
SERVICE = 'SERVICE',
DATA = 'DATA',
}

export enum SUPPORTED_FUNCTIONS {
Expand Down

0 comments on commit aaf4fab

Please sign in to comment.