Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-gorillas-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': patch
---

Adopt new `grammar - JSON` transformation API endpoints.
7 changes: 7 additions & 0 deletions .changeset/fresh-seas-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@finos/legend-graph': patch
'@finos/legend-manual-tests': patch
'@finos/legend-query': patch
'@finos/legend-shared': patch
'@finos/legend-studio': patch
---
5 changes: 5 additions & 0 deletions .changeset/good-lizards-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': major
---

**BREAKING CHANGE:** Renamed `hashLambda` to `hashRawLambda`
6 changes: 6 additions & 0 deletions .changeset/great-lies-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@finos/legend-graph': patch
'@finos/legend-manual-tests': patch
'@finos/legend-query': patch
'@finos/legend-studio': patch
---
5 changes: 5 additions & 0 deletions .changeset/smooth-hornets-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': patch
'@finos/legend-query': patch
'@finos/legend-studio': patch
---
5 changes: 5 additions & 0 deletions .changeset/sour-houses-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': patch
'@finos/legend-query': patch
'@finos/legend-studio': patch
---
18 changes: 17 additions & 1 deletion packages/legend-graph/src/MetaModelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
hashArray,
hashObject,
hashString,
recursiveOmit,
} from '@finos/legend-shared';

export const extractElementNameFromPath = (fullPath: string): string =>
Expand Down Expand Up @@ -85,6 +86,20 @@ export const isValidPath = (path: string): boolean =>
export const fromElementPathToMappingElementId = (className: string): string =>
className.split(ELEMENT_PATH_DELIMITER).join('_');

/**
* Prune source information from object such as raw lambda, raw value specification, etc.
*
* NOTE: currently, there is no exhaustive way to do this. Majority of the cases, the source information field
* is named `sourceInformation`, however, we have sometimes deviated from this pattern in our protocol model,
* so we have fields like `classSourceInformation`, etc. So this is really an optimistic, non-exhaustive prune.
* To do this exhaustively, we might need to make use of engine grammar API endpoints or do a full roundtrip
* raw object-protocol transformation to prune unrecognized fields, which include source information fields.
*/
export const pruneSourceInformation = (
object: Record<PropertyKey, unknown>,
): Record<PropertyKey, unknown> =>
recursiveOmit(object, [SOURCE_INFORMATION_KEY]);

// -------------------------------- HASHING -------------------------------------
// TODO: this should be moved after we refactor `hashing` out of metamodels

Expand All @@ -93,7 +108,8 @@ export const hashObjectWithoutSourceInformation = (val: object): string =>
hashObject(val, {
excludeKeys: (key: string) => key === SOURCE_INFORMATION_KEY,
});
export const hashLambda = (

export const hashRawLambda = (
parameters: object | undefined,
body: object | undefined,
): string =>
Expand Down
10 changes: 5 additions & 5 deletions packages/legend-graph/src/__tests__/MetaModelUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
extractElementNameFromPath,
fromElementPathToMappingElementId,
matchFunctionName,
hashLambda,
hashRawLambda,
isValidFullPath,
isValidPath,
isValidPathIdentifier,
Expand Down Expand Up @@ -66,11 +66,11 @@ test(
parameters: [{ b: 2 }, { a: 1 }],
body: { a: 3 },
};
expect(hashLambda(lambda1.parameters, lambda1.body)).toEqual(
hashLambda(lambda2.parameters, lambda2.body),
expect(hashRawLambda(lambda1.parameters, lambda1.body)).toEqual(
hashRawLambda(lambda2.parameters, lambda2.body),
);
expect(hashLambda(lambda1.parameters, lambda1.body)).not.toEqual(
hashLambda(lambda3.parameters, lambda3.body),
expect(hashRawLambda(lambda1.parameters, lambda1.body)).not.toEqual(
hashRawLambda(lambda3.parameters, lambda3.body),
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ export abstract class AbstractPureGraphManager {
abstract pureCodeToLambda(
lambda: string,
lambdaId?: string,
): Promise<RawLambda | undefined>;
): Promise<RawLambda>;
abstract lambdaToPureCode(
lambda: RawLambda,
lambdaId?: string,
pretty?: boolean,
): Promise<string>;
abstract lambdasToPureCode(
Expand All @@ -194,7 +193,7 @@ export abstract class AbstractPureGraphManager {
abstract pureCodeToRelationalOperationElement(
operation: string,
operationId: string,
): Promise<RawRelationalOperationElement | undefined>;
): Promise<RawRelationalOperationElement>;
abstract relationalOperationElementToPureCode(
operations: Map<string, RawRelationalOperationElement>,
): Promise<Map<string, string>>;
Expand Down Expand Up @@ -223,7 +222,7 @@ export abstract class AbstractPureGraphManager {
graph: PureModel,
): Promise<TestResult[]>;

// ------------------------------------------- ValueSpecification -------------------------------------------
// ------------------------------------------- Value Specification -------------------------------------------

abstract buildValueSpecification(
valueSpecificationJson: Record<PropertyKey, unknown>,
Expand Down Expand Up @@ -401,13 +400,6 @@ export abstract class AbstractPureGraphManager {
// displaying, or for interacting with SDLC server.
// As such, most of these methods will only deal with `string` or `plain object`

/**
* Prune source information from protocol object
*
* NOTE: if we did this right initially, it is as easy as walking through the object and prune
* any field with key `sourceInformation`, but we have introduced many specific source information
* fields, such as `elementSourceInformation in connection, so we need to handle them all.
*/
abstract pruneSourceInformation(object: object): Record<PropertyKey, unknown>;
abstract elementToEntity(
element: PackageableElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { type Hashable, hashArray } from '@finos/legend-shared';
import { hashLambda } from '../../../../../MetaModelUtils';
import { hashRawLambda } from '../../../../../MetaModelUtils';
import { CORE_HASH_STRUCTURE } from '../../../../../MetaModelConst';
import type { PackageableElementVisitor } from '../PackageableElement';
import type { RawVariableExpression } from '../../rawValueSpecification/RawVariableExpression';
Expand Down Expand Up @@ -65,7 +65,7 @@ export class ConcreteFunctionDefinition
this.returnType.hashValue,
hashArray(this.taggedValues),
hashArray(this.stereotypes.map((val) => val.pointerHashCode)),
hashLambda(undefined, this.body),
hashRawLambda(undefined, this.body),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { type Hashable, hashArray, uuid } from '@finos/legend-shared';
import { hashLambda } from '../../../../../MetaModelUtils';
import { hashRawLambda } from '../../../../../MetaModelUtils';
import { CORE_HASH_STRUCTURE } from '../../../../../MetaModelConst';
import type { Multiplicity } from './Multiplicity';
import type { TaggedValue } from './TaggedValue';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class DerivedProperty
this.genericType.ownerReference.hashValue,
hashArray(this.stereotypes.map((val) => val.pointerHashCode)),
hashArray(this.taggedValues),
hashLambda(this.parameters, this.body),
hashRawLambda(this.parameters, this.body),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from './OperationSetImplementation';
import type { RawLambda } from '../../rawValueSpecification/RawLambda';
import type { SetImplementationVisitor } from './SetImplementation';
import { hashLambda } from '../../../../../MetaModelUtils';
import { hashRawLambda } from '../../../../../MetaModelUtils';

export class MergeOperationSetImplementation
extends OperationSetImplementation
Expand Down Expand Up @@ -55,7 +55,7 @@ export class MergeOperationSetImplementation
// TODO: use `isStubbed_SetImplementationContainer` when we refactor hashing
this.parameters.map((param) => param.setImplementation.value.id.value),
),
hashLambda(
hashRawLambda(
this.validationFunction.parameters,
this.validationFunction.body,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { RawLambda } from '../../../rawValueSpecification/RawLambda';
import { hashArray, type Hashable } from '@finos/legend-shared';
import { CORE_HASH_STRUCTURE } from '../../../../../../MetaModelConst';
import { hashLambda } from '../../../../../../MetaModelUtils';
import { hashRawLambda } from '../../../../../../MetaModelUtils';

export class AggregationFunctionSpecification implements Hashable {
/**
Expand All @@ -41,8 +41,8 @@ export class AggregationFunctionSpecification implements Hashable {
get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.AGGREGATE_FUNCTION,
hashLambda(this.mapFn.parameters, this.mapFn.body),
hashLambda(this.aggregateFn.parameters, this.aggregateFn.body),
hashRawLambda(this.mapFn.parameters, this.mapFn.body),
hashRawLambda(this.aggregateFn.parameters, this.aggregateFn.body),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { RawLambda } from '../../../rawValueSpecification/RawLambda';
import { hashArray, type Hashable } from '@finos/legend-shared';
import { CORE_HASH_STRUCTURE } from '../../../../../../MetaModelConst';
import { hashLambda } from '../../../../../../MetaModelUtils';
import { hashRawLambda } from '../../../../../../MetaModelUtils';

export class GroupByFunctionSpecification implements Hashable {
/**
Expand All @@ -34,7 +34,7 @@ export class GroupByFunctionSpecification implements Hashable {
get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.GROUP_BY_FUNCTION,
hashLambda(this.groupByFn.parameters, this.groupByFn.body),
hashRawLambda(this.groupByFn.parameters, this.groupByFn.body),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { hashLambda } from '../../../../MetaModelUtils';
import { hashRawLambda } from '../../../../MetaModelUtils';
import { hashArray, type Hashable } from '@finos/legend-shared';
import { CORE_HASH_STRUCTURE } from '../../../../MetaModelConst';
import {
Expand All @@ -35,7 +35,7 @@ export class RawLambda extends RawValueSpecification implements Hashable {
get hashCode(): string {
return hashArray([
CORE_HASH_STRUCTURE.RAW_LAMBDA,
hashLambda(this.parameters, this.body),
hashRawLambda(this.parameters, this.body),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,21 +1431,17 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {

async pureCodeToLambda(
lambda: string,
lambdaId = 'stub_lambdaId',
): Promise<RawLambda | undefined> {
lambdaId?: string,
): Promise<RawLambda> {
const result = await this.engine.transformCodeToLambda(lambda, lambdaId);
return result ? new RawLambda(result.parameters, result.body) : undefined;
return new RawLambda(result.parameters, result.body);
}

async lambdaToPureCode(
lambda: RawLambda,
lambdaId = 'stub_lambdaId',
pretty?: boolean,
): Promise<string> {
const lambdas = new Map<string, RawLambda>();
lambdas.set(lambdaId, lambda);
return guaranteeNonNullable(
(await this.lambdasToPureCode(lambdas, pretty)).get(lambdaId),
async lambdaToPureCode(lambda: RawLambda, pretty?: boolean): Promise<string> {
return this.engine.transformLambdaToCode(
lambda,
Boolean(pretty),
this.pluginManager.getPureProtocolProcessorPlugins(),
);
}

Expand All @@ -1455,15 +1451,15 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
): Promise<Map<string, string>> {
return this.engine.transformLambdasToCode(
lambdas,
Boolean(pretty),
this.pluginManager.getPureProtocolProcessorPlugins(),
pretty,
);
}

pureCodeToRelationalOperationElement(
operation: string,
operationId: string,
): Promise<RawRelationalOperationElement | undefined> {
): Promise<RawRelationalOperationElement> {
return this.engine.transformPureCodeToRelationalOperationElement(
operation,
operationId,
Expand Down
Loading