Skip to content

Commit

Permalink
handle type args fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Dec 3, 2024
1 parent 7acf19a commit 3aa5cb4
Show file tree
Hide file tree
Showing 20 changed files with 1,384 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .changeset/soft-candles-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
'@finos/legend-extension-dsl-persistence': patch
'@finos/legend-graph': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { V1_Persister } from './V1_DSL_Persistence_Persister.js';
import type { V1_Trigger } from './V1_DSL_Persistence_Trigger.js';
import {
V1_PackageableElement,
type V1_PackageableElementPointer,
type V1_PackageableElementVisitor,
} from '@finos/legend-graph';
import { type Hashable, hashArray } from '@finos/legend-shared';
Expand All @@ -29,7 +30,7 @@ import type { V1_ServiceOutputTarget as V1_ServiceOutputTarget } from './V1_DSL_
export class V1_Persistence extends V1_PackageableElement implements Hashable {
documentation!: string;
trigger!: V1_Trigger;
service!: string;
service!: V1_PackageableElementPointer;
persister?: V1_Persister | undefined;
serviceOutputTargets?: V1_ServiceOutputTarget[] | undefined;
notifier!: V1_Notifier;
Expand All @@ -40,7 +41,7 @@ export class V1_Persistence extends V1_PackageableElement implements Hashable {
PERSISTENCE_HASH_STRUCTURE.PERSISTENCE,
this.documentation,
this.trigger,
this.service,
this.service.path,
hashArray(this.serviceOutputTargets ?? []),
this.persister ?? '',
this.notifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { type Hashable, hashArray } from '@finos/legend-shared';
import { PERSISTENCE_HASH_STRUCTURE } from '../../../../../../../graph/DSL_Persistence_HashUtils.js';
import type { V1_Temporality } from './V1_DSL_Persistence_Temporality.js';
import type { V1_PackageableElementPointer } from '@finos/legend-graph';

export abstract class V1_PersistenceTarget implements Hashable {
abstract get hashCode(): string;
Expand All @@ -27,14 +28,14 @@ export class V1_RelationalPersistenceTarget
implements Hashable
{
table!: string;
database!: string;
database!: V1_PackageableElementPointer;
temporality!: V1_Temporality;

get hashCode(): string {
return hashArray([
PERSISTENCE_HASH_STRUCTURE.RELATIONAL_PERSISTENCE_TARGET,
this.table,
this.database,
this.database.path,
this.temporality,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import type { V1_PackageableElementPointer } from '@finos/legend-graph';
import { PERSISTENCE_HASH_STRUCTURE } from '../../../../../../../graph/DSL_Persistence_HashUtils.js';
import { type Hashable, hashArray } from '@finos/legend-shared';

Expand All @@ -22,23 +23,23 @@ export abstract class V1_Sink implements Hashable {
}

export class V1_RelationalSink extends V1_Sink implements Hashable {
database!: string;
database!: V1_PackageableElementPointer;

override get hashCode(): string {
return hashArray([
PERSISTENCE_HASH_STRUCTURE.RELATIONAL_SINK,
this.database,
this.database.path,
]);
}
}

export class V1_ObjectStorageSink extends V1_Sink implements Hashable {
binding!: string;
binding!: V1_PackageableElementPointer;

override get hashCode(): string {
return hashArray([
PERSISTENCE_HASH_STRUCTURE.OBJECT_STORAGE_SINK,
this.binding,
this.binding.path,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ import {
V1_transformEmbeddedData,
V1_transformTestAssertion,
V1_transformAtomicTest,
PackageableElementPointerType,
V1_PackageableElementPointer,
} from '@finos/legend-graph';
import { guaranteeType, UnsupportedOperationError } from '@finos/legend-shared';
import type { PersistenceTestBatch } from '../../../../../../../graph/metamodel/pure/model/packageableElements/persistence/DSL_Persistence_PersistenceTestBatch.js';
Expand Down Expand Up @@ -357,7 +359,10 @@ export const V1_transformRelationalSink = (
context: V1_GraphTransformerContext,
): V1_RelationalSink => {
const protocol = new V1_RelationalSink();
protocol.database = element.database.value.path;
protocol.database = new V1_PackageableElementPointer(
PackageableElementPointerType.STORE,
element.database.value.path,
);
return protocol;
};

Expand All @@ -366,7 +371,10 @@ export const V1_transformObjectStorageSink = (
context: V1_GraphTransformerContext,
): V1_ObjectStorageSink => {
const protocol = new V1_ObjectStorageSink();
protocol.binding = element.binding.value.path;
protocol.binding = new V1_PackageableElementPointer(
PackageableElementPointerType.BINDING,
element.binding.value.path,
);
return protocol;
};

Expand Down Expand Up @@ -963,7 +971,11 @@ export const V1_transformPersistenceTarget = (
): V1_PersistenceTarget => {
if (element instanceof RelationalPersistenceTarget) {
const protocol = new V1_RelationalPersistenceTarget();
protocol.database = element.database;
protocol.database = new V1_PackageableElementPointer(
PackageableElementPointerType.STORE,
element.database,
);

protocol.table = element.table;
protocol.temporality = V1_transformTemporality(
element.temporality,
Expand Down Expand Up @@ -1252,7 +1264,10 @@ export const V1_transformPersistence = (
protocol.documentation = element.documentation;
protocol.notifier = V1_transformNotifier(element.notifier, context);
protocol.persister = V1_transformPersister(element.persister, context);
protocol.service = element.service.valueForSerialization ?? '';
protocol.service = new V1_PackageableElementPointer(
PackageableElementPointerType.SERVICE,
element.service.valueForSerialization ?? '',
);
protocol.serviceOutputTargets = V1_transformServiceOutputTargets(
element.serviceOutputTargets,
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import {
V1_buildFullPath,
V1_EqualToJson,
type V1_GraphBuilderContext,
V1_PackageableElementPointer,
type V1_TestAssertion,
} from '@finos/legend-graph';
import {
Expand Down Expand Up @@ -368,7 +369,7 @@ export const V1_buildRelationalSink = (
): RelationalSink => {
const sink = new RelationalSink();
sink.database = context.resolveElement(
protocol.database,
protocol.database.path,
false,
) as PackageableElementImplicitReference<Database>;
return sink;
Expand All @@ -380,7 +381,7 @@ export const V1_buildObjectStorageSink = (
): ObjectStorageSink => {
const sink = new ObjectStorageSink();
sink.binding = context.resolveElement(
protocol.binding,
protocol.binding.path,
false,
) as PackageableElementImplicitReference<Binding>;
return sink;
Expand Down Expand Up @@ -1164,7 +1165,7 @@ export const V1_buildPersistenceTarget = (
): PersistenceTarget => {
if (protocol instanceof V1_RelationalPersistenceTarget) {
const persistentTarget = new RelationalPersistenceTarget();
persistentTarget.database = protocol.database;
persistentTarget.database = protocol.database.path;
persistentTarget.table = protocol.table;
persistentTarget.temporality = V1_buildTemporality(
protocol.temporality,
Expand Down Expand Up @@ -1222,7 +1223,7 @@ export const V1_buildPersistence = (
);
persistence.notifier = V1_buildNotifier(protocol.notifier, context);
persistence.persister = V1_buildPersister(protocol.persister, context);
persistence.service = context.resolveService(protocol.service);
persistence.service = context.resolveService(protocol.service.path);
persistence.serviceOutputTargets = V1_buildServiceOutputTargets(
protocol.serviceOutputTargets,
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ import {
V1_externalFormatDataModelSchema,
V1_serializeAtomicTest,
V1_deserializeAtomicTest,
V1_packageableElementPointerModelSchema,
V1_serializePackageableElementPointer,
PackageableElementPointerType,
} from '@finos/legend-graph';
import {
type PlainObject,
Expand Down Expand Up @@ -777,15 +780,29 @@ const V1_relationalSinkModelSchema = (
): ModelSchema<V1_RelationalSink> =>
createModelSchema(V1_RelationalSink, {
_type: usingConstantValueSchema(V1_SinkType.RELATIONAL_SINK),
database: primitive(),
database: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) =>
V1_serializePackageableElementPointer(
val,
PackageableElementPointerType.STORE,
),
),
});

const V1_objectStorageSinkModelSchema = (
plugins: PureProtocolProcessorPlugin[],
): ModelSchema<V1_ObjectStorageSink> =>
createModelSchema(V1_ObjectStorageSink, {
_type: usingConstantValueSchema(V1_SinkType.OBJECT_STORAGE_SINK),
binding: primitive(),
binding: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) =>
V1_serializePackageableElementPointer(
val,
PackageableElementPointerType.BINDING,
),
),
});

export const V1_serializeSink = (
Expand Down Expand Up @@ -1599,7 +1616,14 @@ export const V1_relationalPersistenceTargetModelSchema = (
_type: usingConstantValueSchema(
V1_PersistentTargetType.RELATIONAL_PERSISTENCE_TARGET,
),
database: primitive(),
database: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) =>
V1_serializePackageableElementPointer(
val,
PackageableElementPointerType.STORE,
),
),
table: primitive(),
temporality: custom(
(val) => V1_serializeTemporality(val, plugins),
Expand Down Expand Up @@ -2134,7 +2158,14 @@ export const V1_persistenceModelSchema = (
(val) => V1_serializePersister(val, plugins),
(val) => V1_deserializePersister(val, plugins),
),
service: primitive(),
service: custom(
(val) => serialize(V1_packageableElementPointerModelSchema, val),
(val) =>
V1_serializePackageableElementPointer(
val,
PackageableElementPointerType.SERVICE,
),
),
serviceOutputTargets: optionalCustomList(
(val: V1_ServiceOutputTarget) =>
V1_serializeServiceOutputTarget(val, plugins),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,31 @@ import {
V1_PackageableElement,
} from '../../../model/packageableElements/V1_PackageableElement.js';

export class V1_ProfileStereotype {
value!: string;

constructor(value: string) {
this.value = value;
}
}

export class V1_ProfileTag {
value!: string;
constructor(value: string) {
this.value = value;
}
}

export class V1_Profile extends V1_PackageableElement implements Hashable {
stereotypes: string[] = [];
tags: string[] = [];
stereotypes: V1_ProfileStereotype[] = [];
tags: V1_ProfileTag[] = [];

override get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.PROFILE,
this.path,
hashArray(this.stereotypes),
hashArray(this.tags),
hashArray(this.stereotypes.map((e) => e.value)),
hashArray(this.tags.map((e) => e.value)),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import {
type V1_EnumValueMapping,
V1_getEnumValueMappingSourceValueType,
} from '../../../model/packageableElements/mapping/V1_EnumValueMapping.js';
import type { V1_PackageableElementPointer } from '../V1_PackageableElement.js';

export class V1_EnumerationMapping implements Hashable {
id?: string | undefined;
enumeration!: string;
enumeration!: V1_PackageableElementPointer;
/**
* NOTE: the order is important, during deserialization, we want sourceType to be already available
* @deprecated since v1_11_0
Expand All @@ -41,7 +42,7 @@ export class V1_EnumerationMapping implements Hashable {
return hashArray([
CORE_HASH_STRUCTURE.ENUMERATION_MAPPING,
this.id ?? '',
this.enumeration,
this.enumeration.path,
// NOTE: older protocol formats have information about source type so we have to account for those,
// otherwise, we don't need to account for the source type in hash computation
// If there is no enum value mapping, ignore the source type since it's synthetic and used by the editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import type { Class } from '../../../../../../../graph/metamodel/pure/packageabl
import type { Association } from '../../../../../../../graph/metamodel/pure/packageableElements/domain/Association.js';
import type { ConcreteFunctionDefinition } from '../../../../../../../graph/metamodel/pure/packageableElements/function/ConcreteFunctionDefinition.js';
import type { Property } from '../../../../../../../graph/metamodel/pure/packageableElements/domain/Property.js';
import { V1_Profile } from '../../../model/packageableElements/domain/V1_Profile.js';
import {
V1_Profile,
V1_ProfileStereotype,
V1_ProfileTag,
} from '../../../model/packageableElements/domain/V1_Profile.js';
import { V1_StereotypePtr } from '../../../model/packageableElements/domain/V1_StereotypePtr.js';
import {
V1_initPackageableElement,
Expand Down Expand Up @@ -88,8 +92,10 @@ export const V1_createRawGenericTypeWithElementPath = (
export const V1_transformProfile = (element: Profile): V1_Profile => {
const profile = new V1_Profile();
V1_initPackageableElement(profile, element);
profile.stereotypes = element.p_stereotypes.map((s) => s.value);
profile.tags = element.p_tags.map((t) => t.value);
profile.stereotypes = element.p_stereotypes.map(
(s) => new V1_ProfileStereotype(s.value),
);
profile.tags = element.p_tags.map((t) => new V1_ProfileTag(t.value));
return profile;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ const transformEnumerationMapping = (
enumerationMapping.enumValueMappings = element.enumValueMappings
.filter((e) => !isStubbed_EnumValueMapping(e))
.map(transformEnumValueMapping);
enumerationMapping.enumeration =
element.enumeration.valueForSerialization ?? '';
enumerationMapping.enumeration = new V1_PackageableElementPointer(
PackageableElementPointerType.ENUMERATION,
element.enumeration.valueForSerialization ?? '',
);
enumerationMapping.id = mappingElementIdSerializer(element.id);
return enumerationMapping;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ export class V1_ElementSecondPassBuilder
V1_buildFullPath(element.package, element.name),
);
const uniqueStereotypes = new Set<string>();
profile.p_stereotypes = element.stereotypes.map((stereotype) => {
profile.p_stereotypes = element.stereotypes.map((stereotypeV) => {
const stereotype = stereotypeV.value;
if (uniqueStereotypes.has(stereotype)) {
const message = `Found duplicated stereotype '${stereotype}' in profile '${element.path}'`;
/**
Expand All @@ -258,7 +259,8 @@ export class V1_ElementSecondPassBuilder
return new Stereotype(profile, stereotype);
});
const uniqueTags = new Set<string>();
profile.p_tags = element.tags.map((tag) => {
profile.p_tags = element.tags.map((tagV) => {
const tag = tagV.value;
if (uniqueTags.has(tag)) {
const message = `Found duplicated tag '${tag}' in profile '${element.path}'`;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ export const V1_buildEnumerationMapping = (
parentMapping: Mapping,
): EnumerationMapping => {
assertNonEmptyString(
srcEnumerationMapping.enumeration,
srcEnumerationMapping.enumeration.path,
`Enumeration mapping 'enumeration' field is missing or empty`,
);
const targetEnumeration = context.resolveEnumeration(
srcEnumerationMapping.enumeration,
srcEnumerationMapping.enumeration.path,
);
const possibleSourceTypes = new Set(
srcEnumerationMapping.enumValueMappings.flatMap((enumValueMapping) =>
Expand Down
Loading

0 comments on commit 3aa5cb4

Please sign in to comment.