Skip to content

Commit

Permalink
replace type string with generic type in protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Nov 20, 2024
1 parent f5ad6d7 commit d8d748e
Show file tree
Hide file tree
Showing 36 changed files with 714 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .changeset/kind-cougars-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@finos/legend-server-showcase-deployment': patch
'@finos/legend-extension-dsl-data-space': patch
'@finos/legend-query-builder': patch
'@finos/legend-graph': patch
---
6 changes: 6 additions & 0 deletions .changeset/short-cheetahs-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@finos/legend-server-showcase-deployment': patch
'@finos/legend-extension-dsl-data-space': patch
'@finos/legend-query-builder': patch
'@finos/legend-graph': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
V1_MappingAnalysisCoveragePartition,
V1_deserializeDataspaceCoveragePartition,
V1_MappingModelCoveragePartition,
V1_getFullReturnTypePath,
} from '@finos/legend-graph';
import type {
Entity,
Expand Down Expand Up @@ -703,8 +704,14 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
analysisResult.model.elements.flatMap((element) => {
if (element instanceof V1_Class) {
return element.derivedProperties
.map((prop) => prop.returnType)
.concat(element.properties.map((prop) => prop.type));
.map((prop) =>
V1_getFullReturnTypePath(prop.returnGenericType),
)
.concat(
element.properties.map((prop) =>
V1_getFullReturnTypePath(prop.genericType),
),
);
}
return [];
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { UnsupportedOperationError } from '@finos/legend-shared';
import {
FunctionAnalysisInfo,
FunctionAnalysisParameterInfo,
Expand All @@ -26,7 +27,18 @@ import {
import type { PureModel } from '../../../../../graph/PureModel.js';
import type { V1_Multiplicity } from '../model/packageableElements/domain/V1_Multiplicity.js';
import type { V1_ConcreteFunctionDefinition } from '../model/packageableElements/function/V1_ConcreteFunctionDefinition.js';
import type { V1_GenericType } from '../model/packageableElements/type/V1_GenericType.js';
import type { V1_RawVariable } from '../model/rawValueSpecification/V1_RawVariable.js';
import { V1_PackageableType } from '../model/valueSpecification/raw/V1_PackageableElementPtr.js';

export const V1_getGenericTypeFullPath = (val: V1_GenericType): string => {
if (val.rawType instanceof V1_PackageableType) {
return val.rawType.fullPath;
}
throw new UnsupportedOperationError(
'Failed to get full path from generic type',
);
};

const V1_buildFunctionMultiplicitySignature = (
multiplicity: V1_Multiplicity,
Expand All @@ -45,7 +57,7 @@ const V1_buildFunctionMultiplicitySignature = (
};

const V1_buildFunctionParameterSignature = (variable: V1_RawVariable): string =>
`${variable.class
`${variable.genericType.rawType.fullPath
.split(ELEMENT_PATH_DELIMITER)
.pop()}_${V1_buildFunctionMultiplicitySignature(variable.multiplicity)}_`;

Expand All @@ -54,7 +66,7 @@ const V1_buildFunctionSignatureSuffix = (
): string =>
`_${func.parameters
.map((p) => V1_buildFunctionParameterSignature(p))
.join('_')}_${func.returnType
.join('_')}_${V1_getGenericTypeFullPath(func.returnGenericType)
.split(ELEMENT_PATH_DELIMITER)
.pop()}_${V1_buildFunctionMultiplicitySignature(func.returnMultiplicity)}_`;

Expand Down Expand Up @@ -89,16 +101,18 @@ const V1_buildFunctionPrettyName = (
}${element.name.substring(0, element.name.indexOf(V1_buildFunctionSignatureSuffix(element)))}(${element.parameters
.map((p) =>
!options?.notIncludeParamName
? `${p.name}: ${p.class}[${generateMultiplicityString(
? `${p.name}: ${p.genericType.rawType.fullPath}[${generateMultiplicityString(
p.multiplicity.lowerBound,
p.multiplicity.upperBound,
)}]`
: `${p.class}[${generateMultiplicityString(
: `${p.genericType.rawType.fullPath}[${generateMultiplicityString(
p.multiplicity.lowerBound,
p.multiplicity.upperBound,
)}]`,
)
.join(', ')}): ${element.returnType}[${generateMultiplicityString(
.join(
', ',
)}): ${V1_getGenericTypeFullPath(element.returnGenericType)}[${generateMultiplicityString(
element.returnMultiplicity.lowerBound,
element.returnMultiplicity.upperBound,
)}]`.replaceAll(/\s*/gu, (val) => {
Expand All @@ -122,15 +136,15 @@ export const V1_buildFunctionInfoAnalysis = (
fullPath: true,
});
functionInfo.packagePath = func.package;
functionInfo.returnType = func.returnType;
functionInfo.returnType = V1_getGenericTypeFullPath(func.returnGenericType);
functionInfo.parameterInfoList = func.parameters.map((param) => {
const paramInfo = new FunctionAnalysisParameterInfo();
paramInfo.multiplicity = graph.getMultiplicity(
param.multiplicity.lowerBound,
param.multiplicity.upperBound,
);
paramInfo.name = param.name;
paramInfo.type = param.class;
paramInfo.type = param.genericType.rawType.fullPath;
return paramInfo;
});
return functionInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import {
import type { V1_Multiplicity } from './V1_Multiplicity.js';
import type { V1_StereotypePtr } from '../../../model/packageableElements/domain/V1_StereotypePtr.js';
import type { V1_TaggedValue } from '../../../model/packageableElements/domain/V1_TaggedValue.js';
import type { V1_GenericType } from '../type/V1_GenericType.js';
import { V1_PackageableType } from '../../valueSpecification/raw/V1_PackageableElementPtr.js';

export class V1_DerivedProperty implements Hashable {
name!: string;
returnType!: string;
returnGenericType!: V1_GenericType;
returnMultiplicity!: V1_Multiplicity;
stereotypes: V1_StereotypePtr[] = [];
taggedValues: V1_TaggedValue[] = [];
Expand All @@ -47,7 +49,9 @@ export class V1_DerivedProperty implements Hashable {
CORE_HASH_STRUCTURE.DERIVED_PROPERTY,
this.name,
this.returnMultiplicity,
this.returnType,
this.returnGenericType.rawType instanceof V1_PackageableType
? this.returnGenericType.rawType.fullPath
: '',
hashArray(this.stereotypes),
hashArray(this.taggedValues),
hashRawLambda(this.parameters, this.body),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import type { V1_Multiplicity } from './V1_Multiplicity.js';
import type { V1_StereotypePtr } from '../../../model/packageableElements/domain/V1_StereotypePtr.js';
import type { V1_TaggedValue } from '../../../model/packageableElements/domain/V1_TaggedValue.js';
import type { V1_DefaultValue } from './V1_DefaultValue.js';
import type { V1_GenericType } from '../type/V1_GenericType.js';
import { V1_PackageableType } from '../../valueSpecification/raw/V1_PackageableElementPtr.js';

export class V1_Property implements Hashable {
name!: string;
type!: string;
genericType!: V1_GenericType;
multiplicity!: V1_Multiplicity;
aggregation?: string | undefined;
defaultValue: V1_DefaultValue | undefined;
Expand All @@ -35,7 +37,9 @@ export class V1_Property implements Hashable {
CORE_HASH_STRUCTURE.PROPERTY,
this.name,
this.multiplicity,
this.type,
this.genericType.rawType instanceof V1_PackageableType
? this.genericType.rawType.fullPath
: '',
this.aggregation ?? '',
this.defaultValue ?? '',
hashArray(this.stereotypes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
V1_PackageableElement,
} from '../../../model/packageableElements/V1_PackageableElement.js';
import type { V1_FunctionTestSuite } from './test/V1_FunctionTestSuite.js';
import type { V1_GenericType } from '../type/V1_GenericType.js';
import { V1_PackageableType } from '../../valueSpecification/raw/V1_PackageableElementPtr.js';

export class V1_ConcreteFunctionDefinition extends V1_PackageableElement {
/**
Expand All @@ -54,7 +56,7 @@ export class V1_ConcreteFunctionDefinition extends V1_PackageableElement {
* @discrepancy model
*/
postConstraints = [];
returnType!: string;
returnGenericType!: V1_GenericType;
returnMultiplicity!: V1_Multiplicity;
taggedValues: V1_TaggedValue[] = [];
stereotypes: V1_StereotypePtr[] = [];
Expand All @@ -65,7 +67,9 @@ export class V1_ConcreteFunctionDefinition extends V1_PackageableElement {
CORE_HASH_STRUCTURE.FUNCTION,
this.path,
hashArray(this.parameters),
this.returnType,
this.returnGenericType.rawType instanceof V1_PackageableType
? this.returnGenericType.rawType.fullPath
: '',
hashArray(this.taggedValues),
hashArray(this.stereotypes),
hashRawLambda(undefined, this.body),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { V1_ValueSpecification } from '../../valueSpecification/V1_ValueSpecification.js';
import type { V1_Multiplicity } from '../domain/V1_Multiplicity.js';
import type { V1_Type } from './V1_Type.js';

export class V1_GenericType {
rawType!: V1_Type;
typeArguments: V1_GenericType[] = [];
multiplicityArguments: V1_Multiplicity[] = [];
typeVariableValues: V1_ValueSpecification[] = [];

get hashCode(): string {
return this.rawType.hashCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { Hashable } from '@finos/legend-shared';

export type V1_Type = Hashable;
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@ import {
} from '../../model/rawValueSpecification/V1_RawValueSpecification.js';
import type { V1_Multiplicity } from '../../model/packageableElements/domain/V1_Multiplicity.js';

export class V1_RawRawType {
fullPath!: string;
}
export class V1_RawGenricType {
rawType!: V1_RawRawType;
multiplicityArguments: V1_Multiplicity[] = [];
typeArguments: V1_RawGenricType[] = [];
typeVariableValues: unknown[] = [];
}

export class V1_RawVariable
extends V1_RawValueSpecification
implements Hashable
{
class!: string;
genericType!: V1_RawGenricType;
name!: string;
multiplicity!: V1_Multiplicity;

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.RAW_VARIABLE,
this.class,
this.genericType.rawType.fullPath,
this.name,
this.multiplicity,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
* limitations under the License.
*/

import { SerializationFactory, usingModelSchema } from '@finos/legend-shared';
import {
hashArray,
SerializationFactory,
usingModelSchema,
type Hashable,
} from '@finos/legend-shared';
import { createModelSchema, list, primitive } from 'serializr';
import type { V1_Type } from '../packageableElements/type/V1_Type.js';
import { CORE_HASH_STRUCTURE } from '../../../../../../graph/Core_HashUtils.js';

export class V1_RelationTypeColumn {
export class V1_RelationTypeColumn implements Hashable {
name!: string;
type!: string;
static readonly serialization = new SerializationFactory(
Expand All @@ -26,9 +33,13 @@ export class V1_RelationTypeColumn {
type: primitive(),
}),
);

get hashCode(): string {
return hashArray([CORE_HASH_STRUCTURE.REALTION_TYPE, this.name, this.type]);
}
}

export class V1_RelationType {
export class V1_RelationType implements V1_Type {
columns: V1_RelationTypeColumn[] = [];

static readonly serialization = new SerializationFactory(
Expand All @@ -38,4 +49,11 @@ export class V1_RelationType {
),
}),
);

get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.REALTION_TYPE,
hashArray(this.columns),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {
type V1_ValueSpecificationVisitor,
} from '../../model/valueSpecification/V1_ValueSpecification.js';
import type { V1_Multiplicity } from '../../model/packageableElements/domain/V1_Multiplicity.js';
import type { V1_GenericType } from '../packageableElements/type/V1_GenericType.js';

export class V1_Variable extends V1_ValueSpecification {
name!: string;
multiplicity!: V1_Multiplicity;
class?: string | undefined;
genericType: V1_GenericType | undefined;

accept_ValueSpecificationVisitor<T>(
visitor: V1_ValueSpecificationVisitor<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
V1_ValueSpecification,
} from '../../../model/valueSpecification/V1_ValueSpecification.js';
import { V1_Multiplicity } from '../../packageableElements/domain/V1_Multiplicity.js';
import type { V1_Type } from '../../packageableElements/type/V1_Type.js';

export class V1_PackageableElementPtr extends V1_ValueSpecification {
readonly multiplicity = V1_Multiplicity.ONE;
Expand All @@ -30,3 +31,12 @@ export class V1_PackageableElementPtr extends V1_ValueSpecification {
return visitor.visit_PackageableElementPtr(this);
}
}

export class V1_PackageableType
extends V1_PackageableElementPtr
implements V1_Type
{
get hashCode(): string {
return this.fullPath;
}
}
Loading

0 comments on commit d8d748e

Please sign in to comment.