diff --git a/.changeset/fluffy-gorillas-drum.md b/.changeset/fluffy-gorillas-drum.md new file mode 100644 index 00000000000..06bbd4edfbc --- /dev/null +++ b/.changeset/fluffy-gorillas-drum.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-graph': patch +--- + +Adopt new `grammar - JSON` transformation API endpoints. diff --git a/.changeset/fresh-seas-jump.md b/.changeset/fresh-seas-jump.md new file mode 100644 index 00000000000..60af0616d3d --- /dev/null +++ b/.changeset/fresh-seas-jump.md @@ -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 +--- diff --git a/.changeset/good-lizards-wait.md b/.changeset/good-lizards-wait.md new file mode 100644 index 00000000000..b3ae087eb7f --- /dev/null +++ b/.changeset/good-lizards-wait.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-graph': major +--- + +**BREAKING CHANGE:** Renamed `hashLambda` to `hashRawLambda` diff --git a/.changeset/great-lies-melt.md b/.changeset/great-lies-melt.md new file mode 100644 index 00000000000..23d36ac1ecb --- /dev/null +++ b/.changeset/great-lies-melt.md @@ -0,0 +1,6 @@ +--- +'@finos/legend-graph': patch +'@finos/legend-manual-tests': patch +'@finos/legend-query': patch +'@finos/legend-studio': patch +--- diff --git a/.changeset/smooth-hornets-join.md b/.changeset/smooth-hornets-join.md new file mode 100644 index 00000000000..2b453cda60a --- /dev/null +++ b/.changeset/smooth-hornets-join.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-graph': patch +'@finos/legend-query': patch +'@finos/legend-studio': patch +--- diff --git a/.changeset/sour-houses-promise.md b/.changeset/sour-houses-promise.md new file mode 100644 index 00000000000..2b453cda60a --- /dev/null +++ b/.changeset/sour-houses-promise.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-graph': patch +'@finos/legend-query': patch +'@finos/legend-studio': patch +--- diff --git a/packages/legend-graph/src/MetaModelUtils.ts b/packages/legend-graph/src/MetaModelUtils.ts index 1d52c305fe9..a378ef9387c 100644 --- a/packages/legend-graph/src/MetaModelUtils.ts +++ b/packages/legend-graph/src/MetaModelUtils.ts @@ -34,6 +34,7 @@ import { hashArray, hashObject, hashString, + recursiveOmit, } from '@finos/legend-shared'; export const extractElementNameFromPath = (fullPath: string): string => @@ -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, +): Record => + recursiveOmit(object, [SOURCE_INFORMATION_KEY]); + // -------------------------------- HASHING ------------------------------------- // TODO: this should be moved after we refactor `hashing` out of metamodels @@ -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 => diff --git a/packages/legend-graph/src/__tests__/MetaModelUtils.test.ts b/packages/legend-graph/src/__tests__/MetaModelUtils.test.ts index fcbc7835a5e..bf4334d02b0 100644 --- a/packages/legend-graph/src/__tests__/MetaModelUtils.test.ts +++ b/packages/legend-graph/src/__tests__/MetaModelUtils.test.ts @@ -18,7 +18,7 @@ import { extractElementNameFromPath, fromElementPathToMappingElementId, matchFunctionName, - hashLambda, + hashRawLambda, isValidFullPath, isValidPath, isValidPathIdentifier, @@ -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), ); }, ); diff --git a/packages/legend-graph/src/graphManager/AbstractPureGraphManager.ts b/packages/legend-graph/src/graphManager/AbstractPureGraphManager.ts index e3bdc966878..6bb78ebea99 100644 --- a/packages/legend-graph/src/graphManager/AbstractPureGraphManager.ts +++ b/packages/legend-graph/src/graphManager/AbstractPureGraphManager.ts @@ -179,10 +179,9 @@ export abstract class AbstractPureGraphManager { abstract pureCodeToLambda( lambda: string, lambdaId?: string, - ): Promise; + ): Promise; abstract lambdaToPureCode( lambda: RawLambda, - lambdaId?: string, pretty?: boolean, ): Promise; abstract lambdasToPureCode( @@ -194,7 +193,7 @@ export abstract class AbstractPureGraphManager { abstract pureCodeToRelationalOperationElement( operation: string, operationId: string, - ): Promise; + ): Promise; abstract relationalOperationElementToPureCode( operations: Map, ): Promise>; @@ -223,7 +222,7 @@ export abstract class AbstractPureGraphManager { graph: PureModel, ): Promise; - // ------------------------------------------- ValueSpecification ------------------------------------------- + // ------------------------------------------- Value Specification ------------------------------------------- abstract buildValueSpecification( valueSpecificationJson: Record, @@ -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; abstract elementToEntity( element: PackageableElement, diff --git a/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/ConcreteFunctionDefinition.ts b/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/ConcreteFunctionDefinition.ts index 6e522857b03..68bb6d7bcc3 100644 --- a/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/ConcreteFunctionDefinition.ts +++ b/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/ConcreteFunctionDefinition.ts @@ -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'; @@ -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), ]); } diff --git a/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/DerivedProperty.ts b/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/DerivedProperty.ts index 58c1c3e696b..3d06726825d 100644 --- a/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/DerivedProperty.ts +++ b/packages/legend-graph/src/models/metamodels/pure/packageableElements/domain/DerivedProperty.ts @@ -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'; @@ -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), ]); } } diff --git a/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/MergeOperationSetImplementation.ts b/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/MergeOperationSetImplementation.ts index 1bd3d9e0bfb..bde99830eba 100644 --- a/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/MergeOperationSetImplementation.ts +++ b/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/MergeOperationSetImplementation.ts @@ -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 @@ -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, ), diff --git a/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/AggregationFunctionSpecification.ts b/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/AggregationFunctionSpecification.ts index 87851d80d44..7bc44291e97 100644 --- a/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/AggregationFunctionSpecification.ts +++ b/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/AggregationFunctionSpecification.ts @@ -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 { /** @@ -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), ]); } } diff --git a/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/GroupByFunctionSpecification.ts b/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/GroupByFunctionSpecification.ts index fc360188165..f32d2dcd03a 100644 --- a/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/GroupByFunctionSpecification.ts +++ b/packages/legend-graph/src/models/metamodels/pure/packageableElements/mapping/aggregationAware/GroupByFunctionSpecification.ts @@ -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 { /** @@ -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), ]); } } diff --git a/packages/legend-graph/src/models/metamodels/pure/rawValueSpecification/RawLambda.ts b/packages/legend-graph/src/models/metamodels/pure/rawValueSpecification/RawLambda.ts index c417ab23f66..717e41780bf 100644 --- a/packages/legend-graph/src/models/metamodels/pure/rawValueSpecification/RawLambda.ts +++ b/packages/legend-graph/src/models/metamodels/pure/rawValueSpecification/RawLambda.ts @@ -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 { @@ -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), ]); } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/V1_PureGraphManager.ts b/packages/legend-graph/src/models/protocols/pure/v1/V1_PureGraphManager.ts index e5792dc5da9..f8dc994ece6 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/V1_PureGraphManager.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/V1_PureGraphManager.ts @@ -1431,21 +1431,17 @@ export class V1_PureGraphManager extends AbstractPureGraphManager { async pureCodeToLambda( lambda: string, - lambdaId = 'stub_lambdaId', - ): Promise { + lambdaId?: string, + ): Promise { 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 { - const lambdas = new Map(); - lambdas.set(lambdaId, lambda); - return guaranteeNonNullable( - (await this.lambdasToPureCode(lambdas, pretty)).get(lambdaId), + async lambdaToPureCode(lambda: RawLambda, pretty?: boolean): Promise { + return this.engine.transformLambdaToCode( + lambda, + Boolean(pretty), + this.pluginManager.getPureProtocolProcessorPlugins(), ); } @@ -1455,15 +1451,15 @@ export class V1_PureGraphManager extends AbstractPureGraphManager { ): Promise> { return this.engine.transformLambdasToCode( lambdas, + Boolean(pretty), this.pluginManager.getPureProtocolProcessorPlugins(), - pretty, ); } pureCodeToRelationalOperationElement( operation: string, operationId: string, - ): Promise { + ): Promise { return this.engine.transformPureCodeToRelationalOperationElement( operation, operationId, diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_Engine.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_Engine.ts index 2252ba019ad..c259ea7b1d9 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_Engine.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_Engine.ts @@ -21,11 +21,11 @@ import { LogEvent, losslessParse, assertErrorThrown, - guaranteeNonNullable, mergeObjects, HttpStatus, NetworkClientError, returnUndefOnError, + deserializeMap, } from '@finos/legend-shared'; import { type ImportConfigurationDescription, @@ -40,11 +40,6 @@ import { TEMPORARY__AbstractEngineConfig } from '../../../../../graphManager/act import { V1_EngineServerClient } from './V1_EngineServerClient'; import type { V1_PureModelContextData } from '../model/context/V1_PureModelContextData'; import type { V1_LambdaReturnTypeResult } from '../engine/compilation/V1_LambdaReturnTypeResult'; -import { - V1_JsonToGrammarInput, - V1_RenderStyle, -} from '../engine/grammar/V1_JsonToGrammarInput'; -import { V1_GrammarToJsonInput } from '../engine/grammar/V1_GrammarToJson'; import type { V1_RawLambda } from '../model/rawValueSpecification/V1_RawLambda'; import { V1_deserializePureModelContextData, @@ -62,8 +57,6 @@ import { V1_ParserError } from '../engine/grammar/V1_ParserError'; import { V1_CompilationError } from '../engine/compilation/V1_CompilationError'; import type { V1_RawRelationalOperationElement } from '../model/packageableElements/store/relational/model/V1_RawRelationalOperationElement'; import type { RawRelationalOperationElement } from '../../../../metamodels/pure/packageableElements/store/relational/model/RawRelationalOperationElement'; -import { V1_RelationalOperationElementJsonToGrammarInput } from './grammar/V1_RelationalOperationElementJsonToGrammarInput'; -import { V1_RelationalOperationElementGrammarToJsonInput } from './grammar/V1_RelationalOperationElementGrammarToJson'; import { V1_GraphTransformerContextBuilder } from '../transformation/pureGraph/from/V1_GraphTransformerContext'; import type { PureProtocolProcessorPlugin } from '../../PureProtocolProcessorPlugin'; import { @@ -101,6 +94,7 @@ import { V1_ExternalFormatModelGenerationInput } from './externalFormat/V1_Exter import { GRAPH_MANAGER_EVENT } from '../../../../../graphManager/GraphManagerEvent'; import { V1_RunTestsInput } from './test/V1_RunTestsInput'; import { V1_RunTestsResult } from './test/V1_RunTestsResult'; +import { V1_RenderStyle } from './grammar/V1_RenderStyle'; class V1_EngineConfig extends TEMPORARY__AbstractEngineConfig { private engine: V1_Engine; @@ -196,15 +190,12 @@ export class V1_Engine { // ------------------------------------------- Grammar ------------------------------------------- - async pureModelContextDataToPureCode( + pureModelContextDataToPureCode( graph: V1_PureModelContextData, ): Promise { - return ( - (( - await this.engineServerClient.transformJSONToGrammar({ - modelDataContext: this.serializePureModelContextData(graph), - }) - ).code as string | undefined) ?? '' + return this.engineServerClient.JSONToGrammar_model( + this.serializePureModelContextData(graph), + V1_RenderStyle.STANDARD, ); } @@ -213,111 +204,155 @@ export class V1_Engine { options?: { onError?: () => void }, ): Promise { return V1_deserializePureModelContextData( - await this.pureCodeToPureModelContextDataJson(code, options), + await this.pureCodeToPureModelContextDataJSON(code, false, options), ); } - private async pureCodeToPureModelContextDataJson( + private async pureCodeToPureModelContextDataJSON( code: string, + returnSourceInformation: boolean, options?: { onError?: () => void }, ): Promise> { - const parsingResult = await this.engineServerClient.transformGrammarToJSON({ - code, - }); - if (parsingResult.codeError) { - options?.onError?.(); - throw V1_buildParserError( - V1_ParserError.serialization.fromJson( - parsingResult.codeError as PlainObject, - ), + try { + return await this.engineServerClient.grammarToJSON_model( + code, + undefined, + undefined, + // TODO: we should use the passed `returnSourceInformation` + // but right now, we must test if this works for engine + // See https://github.com/finos/legend-engine/pull/692 + undefined, ); + } catch (error) { + assertErrorThrown(error); + options?.onError?.(); + if ( + error instanceof NetworkClientError && + error.response.status === HttpStatus.BAD_REQUEST + ) { + throw V1_buildParserError( + V1_ParserError.serialization.fromJson( + error.payload as PlainObject, + ), + ); + } + throw error; } - return guaranteeNonNullable( - parsingResult.modelDataContext, - ) as PlainObject; } async transformLambdasToCode( - inputLambdas: Map, - pureProtocolProcessorPlugins: PureProtocolProcessorPlugin[], - pretty?: boolean, + input: Map, + pretty: boolean, + plugins: PureProtocolProcessorPlugin[], ): Promise> { const lambdas: Record> = {}; - inputLambdas.forEach((inputLambda, key) => { + input.forEach((inputLambda, key) => { lambdas[key] = V1_serializeRawValueSpecification( V1_transformRawLambda( inputLambda, - new V1_GraphTransformerContextBuilder( - pureProtocolProcessorPlugins, - ).build(), + new V1_GraphTransformerContextBuilder(plugins).build(), ), ); }); - const result = V1_GrammarToJsonInput.serialization.fromJson( - await this.engineServerClient.transformJSONToGrammar({ - isolatedLambdas: { lambdas }, - renderStyle: pretty ? V1_RenderStyle.PRETTY : V1_RenderStyle.STANDARD, - }), + return deserializeMap( + await this.engineServerClient.JSONToGrammar_lambda_batch( + lambdas, + pretty ? V1_RenderStyle.PRETTY : V1_RenderStyle.STANDARD, + ), + (v) => v, ); - return result.isolatedLambdas ?? new Map(); } - async transformCodeToLambda( - lambda: string, - lambdaId: string, - ): Promise { - const result = V1_JsonToGrammarInput.serialization.fromJson( - await this.engineServerClient.transformGrammarToJSON({ - isolatedLambdas: { [lambdaId]: lambda }, - }), + async transformLambdaToCode( + lambda: RawLambda, + pretty: boolean, + plugins: PureProtocolProcessorPlugin[], + ): Promise { + return await this.engineServerClient.JSONToGrammar_lambda( + V1_serializeRawValueSpecification( + V1_transformRawLambda( + lambda, + new V1_GraphTransformerContextBuilder(plugins).build(), + ), + ), + pretty ? V1_RenderStyle.PRETTY : V1_RenderStyle.STANDARD, ); - const lambdaResult = guaranteeNonNullable(result.isolatedLambdas); - const parserError = lambdaResult.lambdaErrors?.get(lambdaId); - if (parserError) { - throw V1_buildParserError(parserError); + } + + async transformCodeToLambda( + code: string, + lambdaId?: string, + ): Promise { + try { + return (await this.engineServerClient.grammarToJSON_lambda( + code, + lambdaId ?? '', + undefined, + undefined, + true, + )) as unknown as V1_RawLambda; + } catch (error) { + assertErrorThrown(error); + if ( + error instanceof NetworkClientError && + error.response.status === HttpStatus.BAD_REQUEST + ) { + throw V1_buildParserError( + V1_ParserError.serialization.fromJson( + error.payload as PlainObject, + ), + ); + } + throw error; } - return lambdaResult.lambdas?.get(lambdaId); } async transformRelationalOperationElementsToPureCode( - inputOperations: Map, + input: Map, ): Promise> { const operations: Record< string, PlainObject > = {}; - inputOperations.forEach((inputOperation, key) => { + input.forEach((inputOperation, key) => { operations[key] = inputOperation as PlainObject; }); - const result = - V1_RelationalOperationElementGrammarToJsonInput.serialization.fromJson( - await this.engineServerClient.transformRelationalOperationElementJSONToGrammar( - { - operations, - }, - ), - ); - return result.operations; + return deserializeMap( + await this.engineServerClient.JSONToGrammar_relationalOperationElement_batch( + operations, + V1_RenderStyle.STANDARD, + ), + (v) => v, + ); } async transformPureCodeToRelationalOperationElement( - operation: string, + code: string, operationId: string, - ): Promise { - const result = - V1_RelationalOperationElementJsonToGrammarInput.serialization.fromJson( - await this.engineServerClient.transformRelationalOperationElementGrammarToJSON( - { - operations: { [operationId]: operation }, - }, - ), - ); - const parserError = result.operationErrors?.get(operationId); - if (parserError) { - throw V1_buildParserError(parserError); + ): Promise { + try { + return (await this.engineServerClient.grammarToJSON_relationalOperationElement( + code, + operationId, + undefined, + undefined, + true, + )) as unknown as V1_RawRelationalOperationElement; + } catch (error) { + assertErrorThrown(error); + if ( + error instanceof NetworkClientError && + error.response.status === HttpStatus.BAD_REQUEST + ) { + throw V1_buildParserError( + V1_ParserError.serialization.fromJson( + error.payload as PlainObject, + ), + ); + } + throw error; } - return result.operations.get(operationId); } // ------------------------------------------- Compile ------------------------------------------- @@ -352,8 +387,11 @@ export class V1_Engine { compileContext?: V1_PureModelContextData, options?: { onError?: () => void }, ): Promise { - const mainGraph = await this.pureCodeToPureModelContextDataJson( + const mainGraph = await this.pureCodeToPureModelContextDataJSON( graphText, + // NOTE: we need to return source information here so we can locate the compilation + // errors/warnings + true, options, ); const pureModelContextDataJson = compileContext @@ -545,15 +583,13 @@ export class V1_Engine { async generateModel( input: V1_ExternalFormatModelGenerationInput, ): Promise { - const pmcd = (await this.engineServerClient.generateModel( + const model = (await this.engineServerClient.generateModel( V1_ExternalFormatModelGenerationInput.serialization.toJson(input), )) as unknown as PlainObject; - const pureCode = - (( - await this.engineServerClient.transformJSONToGrammar({ - modelDataContext: pmcd, - }) - ).code as string | undefined) ?? ''; + const pureCode = await this.engineServerClient.JSONToGrammar_model( + model, + V1_RenderStyle.STANDARD, + ); return pureCode; } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_EngineServerClient.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_EngineServerClient.ts index 6623af34f2b..c344e90f056 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_EngineServerClient.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/engine/V1_EngineServerClient.ts @@ -28,8 +28,6 @@ import type { V1_DEPRECATED__ServiceTestResult } from './service/V1_DEPRECATED__ import type { V1_ServiceRegistrationResult } from './service/V1_ServiceRegistrationResult'; import type { V1_ServiceConfigurationInfo } from './service/V1_ServiceConfiguration'; import type { V1_CompileResult } from './compilation/V1_CompileResult'; -import type { V1_GrammarToJsonInput } from './grammar/V1_GrammarToJson'; -import type { V1_JsonToGrammarInput } from './grammar/V1_JsonToGrammarInput'; import type { V1_RawLambda } from '../model/rawValueSpecification/V1_RawLambda'; import type { V1_PureModelContextGenerationInput } from './import/V1_PureModelContextGenerationInput'; import type { V1_GenerateFileInput } from './generation/V1_FileGenerationInput'; @@ -39,8 +37,6 @@ import type { V1_GenerationConfigurationDescription } from './generation/V1_Gene import type { V1_GenerationOutput } from './generation/V1_GenerationOutput'; import type { V1_ExecuteInput } from './execution/V1_ExecuteInput'; import type { V1_PureModelContext } from '../model/context/V1_PureModelContext'; -import type { V1_RelationalOperationElementGrammarToJsonInput } from './grammar/V1_RelationalOperationElementGrammarToJson'; -import type { V1_RelationalOperationElementJsonToGrammarInput } from './grammar/V1_RelationalOperationElementJsonToGrammarInput'; import type { V1_ExecutionPlan } from '../model/executionPlan/V1_ExecutionPlan'; import type { V1_LightQuery, V1_Query } from './query/V1_Query'; import type { V1_ServiceStorage } from './service/V1_ServiceStorage'; @@ -51,6 +47,9 @@ import type { V1_ExternalFormatDescription } from './externalFormat/V1_ExternalF import type { V1_ExternalFormatModelGenerationInput } from './externalFormat/V1_ExternalFormatModelGeneration'; import type { V1_RunTestsInput } from './test/V1_RunTestsInput'; import type { V1_TestResult } from '../model/test/result/V1_TestResult'; +import type { V1_RawRelationalOperationElement } from '../model/packageableElements/store/relational/model/V1_RawRelationalOperationElement'; +import type { V1_RenderStyle } from './grammar/V1_RenderStyle'; +import type { V1_ParserError } from './grammar/V1_ParserError'; enum CORE_ENGINE_TRACER_SPAN { GRAMMAR_TO_JSON = 'transform Pure code to protocol', @@ -79,6 +78,18 @@ enum CORE_ENGINE_TRACER_SPAN { DELETE_QUERY = 'delete query', } +type GrammarParserBatchInputEntry = { + value: string; + returnSourceInformation?: boolean | undefined; + sourceInformationOffset?: + | { + sourceId?: string | undefined; + lineOffset?: number | undefined; + columnOffset?: number | undefined; + } + | undefined; +}; + export class V1_EngineServerClient extends AbstractServerClient { currentUserId?: string | undefined; private env?: string | undefined; @@ -131,24 +142,59 @@ export class V1_EngineServerClient extends AbstractServerClient { // ------------------------------------------- Grammar ------------------------------------------- - transformGrammarToJSON = ( - input: PlainObject, - ): Promise> => + _grammarToJSON = (): string => `${this._pure()}/grammar/grammarToJson`; + + grammarToJSON_model = ( + input: string, + sourceId?: string | undefined, + lineOffset?: number | undefined, + returnSourceInformation?: boolean | undefined, + ): Promise> => this.postWithTracing( this.getTraceData(CORE_ENGINE_TRACER_SPAN.GRAMMAR_TO_JSON), - `${this._pure()}/grammar/transformGrammarToJson`, + `${this._grammarToJSON()}/model`, input, {}, undefined, + { + sourceId, + lineOffset, + returnSourceInformation, + }, + { enableCompression: true }, + ); + + grammarToJSON_lambda = ( + input: string, + sourceId?: string | undefined, + lineOffset?: number | undefined, + columnOffset?: number | undefined, + returnSourceInformation?: boolean | undefined, + ): Promise> => + this.postWithTracing( + this.getTraceData(CORE_ENGINE_TRACER_SPAN.GRAMMAR_TO_JSON), + `${this._grammarToJSON()}/lambda`, + input, + {}, undefined, + { + sourceId, + lineOffset, + columnOffset, + returnSourceInformation, + }, { enableCompression: true }, ); - transformJSONToGrammar = ( - input: PlainObject, - ): Promise> => + + grammarToJSON_lambda_batch = ( + input: Record, + ): Promise<{ + errors?: Record> | undefined; + result?: Record> | undefined; + }> => this.postWithTracing( - this.getTraceData(CORE_ENGINE_TRACER_SPAN.JSON_TO_GRAMMAR), - `${this._pure()}/grammar/transformJsonToGrammar`, + this.getTraceData(CORE_ENGINE_TRACER_SPAN.GRAMMAR_TO_JSON), + `${this._grammarToJSON()}/lambda/batch`, input, {}, undefined, @@ -156,29 +202,115 @@ export class V1_EngineServerClient extends AbstractServerClient { { enableCompression: true }, ); - transformRelationalOperationElementGrammarToJSON = ( - input: PlainObject, - ): Promise> => + grammarToJSON_relationalOperationElement = ( + input: string, + sourceId?: string | undefined, + lineOffset?: number | undefined, + columnOffset?: number | undefined, + returnSourceInformation?: boolean | undefined, + ): Promise> => this.postWithTracing( this.getTraceData(CORE_ENGINE_TRACER_SPAN.GRAMMAR_TO_JSON), - `${this._pure()}/grammar/transformRelationalOperationElementGrammarToJson`, + `${this._grammarToJSON()}/relationalOperationElement`, + input, + {}, + undefined, + { + sourceId, + lineOffset, + columnOffset, + returnSourceInformation, + }, + { enableCompression: true }, + ); + + grammarToJSON_relationalOperationElement_batch = ( + input: Record, + ): Promise<{ + errors?: Record> | undefined; + result?: + | Record> + | undefined; + }> => + this.postWithTracing( + this.getTraceData(CORE_ENGINE_TRACER_SPAN.GRAMMAR_TO_JSON), + `${this._grammarToJSON()}/relationalOperationElement/batch`, + input, + {}, + undefined, + undefined, + { enableCompression: true }, + ); + + _JSONToGrammar = (): string => `${this._pure()}/grammar/jsonToGrammar`; + + JSONToGrammar_model = ( + input: PlainObject, + renderStyle?: V1_RenderStyle | undefined, + ): Promise => + this.postWithTracing( + this.getTraceData(CORE_ENGINE_TRACER_SPAN.JSON_TO_GRAMMAR), + `${this._JSONToGrammar()}/model`, + input, + {}, + { Accept: ContentType.TEXT_PLAIN }, + { renderStyle }, + { enableCompression: true }, + ); + + JSONToGrammar_lambda = ( + input: PlainObject, + renderStyle?: V1_RenderStyle | undefined, + ): Promise => + this.postWithTracing( + this.getTraceData(CORE_ENGINE_TRACER_SPAN.JSON_TO_GRAMMAR), + `${this._JSONToGrammar()}/lambda`, input, {}, undefined, + { renderStyle }, + { enableCompression: true }, + ); + + JSONToGrammar_lambda_batch = ( + input: Record>, + renderStyle?: V1_RenderStyle | undefined, + ): Promise> => + this.postWithTracing( + this.getTraceData(CORE_ENGINE_TRACER_SPAN.JSON_TO_GRAMMAR), + `${this._JSONToGrammar()}/lambda/batch`, + input, + {}, undefined, + { renderStyle }, { enableCompression: true }, ); - transformRelationalOperationElementJSONToGrammar = ( - input: PlainObject, - ): Promise> => + JSONToGrammar_relationalOperationElement = ( + input: PlainObject, + renderStyle?: V1_RenderStyle | undefined, + ): Promise => this.postWithTracing( this.getTraceData(CORE_ENGINE_TRACER_SPAN.JSON_TO_GRAMMAR), - `${this._pure()}/grammar/transformRelationalOperationElementJsonToGrammar`, + `${this._JSONToGrammar()}/relationalOperationElement`, input, {}, undefined, + { renderStyle }, + { enableCompression: true }, + ); + + JSONToGrammar_relationalOperationElement_batch = ( + input: Record>, + renderStyle?: V1_RenderStyle | undefined, + ): Promise> => + this.postWithTracing( + this.getTraceData(CORE_ENGINE_TRACER_SPAN.JSON_TO_GRAMMAR), + `${this._JSONToGrammar()}/relationalOperationElement/batch`, + input, + {}, undefined, + { renderStyle }, { enableCompression: true }, ); diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_GrammarToJson.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_GrammarToJson.ts deleted file mode 100644 index 04d1f72d132..00000000000 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_GrammarToJson.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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 { custom, createModelSchema, primitive } from 'serializr'; -import { - deserializeMap, - SerializationFactory, - serializeMap, -} from '@finos/legend-shared'; - -export class V1_GrammarToJsonInput { - isolatedLambdas?: Map | undefined; - code?: string | undefined; - - static readonly serialization = new SerializationFactory( - createModelSchema(V1_GrammarToJsonInput, { - isolatedLambdas: custom( - (val) => serializeMap(val, (v) => v), - (val) => deserializeMap(val, (v) => v), - ), - code: primitive(), - }), - ); -} diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_JsonToGrammarInput.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_JsonToGrammarInput.ts deleted file mode 100644 index 265d6e987f4..00000000000 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_JsonToGrammarInput.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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 { createModelSchema, object, optional, primitive } from 'serializr'; -import { SerializationFactory, usingModelSchema } from '@finos/legend-shared'; -import { V1_ParserError } from '../../engine/grammar/V1_ParserError'; -import { V1_LambdaInput } from './V1_LambdaInput'; -import { V1_PureModelContextData } from '../../model/context/V1_PureModelContextData'; - -export enum V1_RenderStyle { - STANDARD = 'STANDARD', - PRETTY = 'PRETTY', - PRETTY_HTML = 'PRETTY_HTML', -} - -export class V1_JsonToGrammarInput { - modelDataContext?: V1_PureModelContextData | undefined; - isolatedLambdas?: V1_LambdaInput | undefined; - renderStyle?: V1_RenderStyle | undefined; - codeError?: V1_ParserError | undefined; - - static readonly serialization = new SerializationFactory( - createModelSchema(V1_JsonToGrammarInput, { - modelDataContext: optional(object(V1_PureModelContextData)), - isolatedLambdas: usingModelSchema(V1_LambdaInput.serialization.schema), - renderStyle: optional(primitive()), - codeError: usingModelSchema(V1_ParserError.serialization.schema), - }), - ); -} diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_LambdaInput.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_LambdaInput.ts deleted file mode 100644 index 0582c2b3414..00000000000 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_LambdaInput.ts +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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 { custom, createModelSchema, serialize, deserialize } from 'serializr'; -import { - deserializeMap, - SerializationFactory, - serializeMap, - usingModelSchema, -} from '@finos/legend-shared'; -import { V1_ParserError } from '../../engine/grammar/V1_ParserError'; -import { V1_Protocol } from '../../model/V1_Protocol'; -import type { V1_RawLambda } from '../../model/rawValueSpecification/V1_RawLambda'; -import { V1_rawLambdaModelSchema } from '../../transformation/pureProtocol/serializationHelpers/V1_RawValueSpecificationSerializationHelper'; - -export class V1_LambdaInput { - serializer?: V1_Protocol | undefined; - lambdas?: Map | undefined; - lambdaErrors?: Map | undefined; - - static readonly serialization = new SerializationFactory( - createModelSchema(V1_LambdaInput, { - serializer: usingModelSchema(V1_Protocol.serialization.schema), - lambdas: custom( - (val) => - serializeMap(val, (v) => serialize(V1_rawLambdaModelSchema, v)), - (val) => - deserializeMap(val, (v) => deserialize(V1_rawLambdaModelSchema, v)), - ), - lambdaErrors: custom( - (val) => serializeMap(val, (v) => serialize(V1_ParserError, v)), - (val) => deserializeMap(val, (v) => deserialize(V1_ParserError, v)), - ), - }), - ); -} diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RelationalOperationElementJsonToGrammarInput.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RelationalOperationElementJsonToGrammarInput.ts deleted file mode 100644 index 21d08c2a094..00000000000 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RelationalOperationElementJsonToGrammarInput.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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 { createModelSchema, custom, deserialize, serialize } from 'serializr'; -import { - deserializeMap, - SerializationFactory, - serializeMap, -} from '@finos/legend-shared'; -import { V1_ParserError } from './V1_ParserError'; -import type { V1_RawRelationalOperationElement } from '../../model/packageableElements/store/relational/model/V1_RawRelationalOperationElement'; - -export class V1_RelationalOperationElementJsonToGrammarInput { - operations!: Map; - operationErrors?: Map | undefined; - // renderStyle?: V1_RenderStyle | undefined; - - static readonly serialization = new SerializationFactory( - createModelSchema(V1_RelationalOperationElementJsonToGrammarInput, { - operations: custom( - (val) => serializeMap(val, (v) => v), - (val) => deserializeMap(val, (v) => v), - ), - operationErrors: custom( - (val) => serializeMap(val, (v) => serialize(V1_ParserError, v)), - (val) => deserializeMap(val, (v) => deserialize(V1_ParserError, v)), - ), - }), - ); -} diff --git a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RelationalOperationElementGrammarToJson.ts b/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RenderStyle.ts similarity index 53% rename from packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RelationalOperationElementGrammarToJson.ts rename to packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RenderStyle.ts index a6ebf69b4f2..4700a286a0f 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RelationalOperationElementGrammarToJson.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/engine/grammar/V1_RenderStyle.ts @@ -14,22 +14,8 @@ * limitations under the License. */ -import { custom, createModelSchema } from 'serializr'; -import { - deserializeMap, - SerializationFactory, - serializeMap, -} from '@finos/legend-shared'; - -export class V1_RelationalOperationElementGrammarToJsonInput { - operations!: Map; - - static readonly serialization = new SerializationFactory( - createModelSchema(V1_RelationalOperationElementGrammarToJsonInput, { - operations: custom( - (val) => serializeMap(val, (v) => v), - (val) => deserializeMap(val, (v) => v), - ), - }), - ); +export enum V1_RenderStyle { + STANDARD = 'STANDARD', + PRETTY = 'PRETTY', + PRETTY_HTML = 'PRETTY_HTML', } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/domain/V1_DerivedProperty.ts b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/domain/V1_DerivedProperty.ts index df92e2f7e56..3523dd8b8a2 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/domain/V1_DerivedProperty.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/domain/V1_DerivedProperty.ts @@ -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 type { V1_Multiplicity } from './V1_Multiplicity'; @@ -48,7 +48,7 @@ export class V1_DerivedProperty implements Hashable { this.returnType, hashArray(this.stereotypes), hashArray(this.taggedValues), - hashLambda(this.parameters, this.body), + hashRawLambda(this.parameters, this.body), ]); } } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/function/V1_ConcreteFunctionDefinition.ts b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/function/V1_ConcreteFunctionDefinition.ts index e3f6d85aaeb..807c396e284 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/function/V1_ConcreteFunctionDefinition.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/function/V1_ConcreteFunctionDefinition.ts @@ -15,7 +15,7 @@ */ import { hashArray } from '@finos/legend-shared'; -import { hashLambda } from '../../../../../../../MetaModelUtils'; +import { hashRawLambda } from '../../../../../../../MetaModelUtils'; import { CORE_HASH_STRUCTURE } from '../../../../../../../MetaModelConst'; import type { V1_RawVariable } from '../../../model/rawValueSpecification/V1_RawVariable'; import type { V1_Multiplicity } from '../../../model/packageableElements/domain/V1_Multiplicity'; @@ -52,7 +52,7 @@ export class V1_ConcreteFunctionDefinition extends V1_PackageableElement { this.returnType, hashArray(this.taggedValues), hashArray(this.stereotypes), - hashLambda(undefined, this.body), + hashRawLambda(undefined, this.body), ]); } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/mapping/V1_MergeOperationClassMapping.ts b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/mapping/V1_MergeOperationClassMapping.ts index 327bcf06190..63a869f9ef5 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/mapping/V1_MergeOperationClassMapping.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/mapping/V1_MergeOperationClassMapping.ts @@ -16,7 +16,7 @@ import { hashArray, type Hashable } from '@finos/legend-shared'; import { CORE_HASH_STRUCTURE } from '../../../../../../../MetaModelConst'; -import { hashLambda } from '../../../../../../../MetaModelUtils'; +import { hashRawLambda } from '../../../../../../../MetaModelUtils'; import type { V1_RawLambda } from '../../rawValueSpecification/V1_RawLambda'; import type { V1_ClassMappingVisitor } from './V1_ClassMapping'; import { V1_OperationClassMapping } from './V1_OperationClassMapping'; @@ -37,7 +37,7 @@ export class V1_MergeOperationClassMapping CORE_HASH_STRUCTURE.OPERATION_SET_IMPLEMENTATION, this.operation, hashArray(this.parameters), - hashLambda( + hashRawLambda( this.validationFunction.parameters, this.validationFunction.body, ), diff --git a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_AggregateFunction.ts b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_AggregateFunction.ts index 9f95fcdfbd9..db3d5fc0e36 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_AggregateFunction.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_AggregateFunction.ts @@ -17,7 +17,7 @@ import type { V1_RawLambda } from '../../../../../../model/rawValueSpecification/V1_RawLambda'; import { type Hashable, hashArray } from '@finos/legend-shared'; import { CORE_HASH_STRUCTURE } from '../../../../../../../../../../MetaModelConst'; -import { hashLambda } from '../../../../../../../../../../MetaModelUtils'; +import { hashRawLambda } from '../../../../../../../../../../MetaModelUtils'; export class V1_AggregateFunction implements Hashable { /** @@ -36,8 +36,8 @@ export class V1_AggregateFunction 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), ]); } } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_GroupByFunction.ts b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_GroupByFunction.ts index 03d3b5c2eb0..0f72238909d 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_GroupByFunction.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/model/packageableElements/store/relational/mapping/aggregationAware/V1_GroupByFunction.ts @@ -17,7 +17,7 @@ import type { V1_RawLambda } from '../../../../../../model/rawValueSpecification/V1_RawLambda'; import { type Hashable, hashArray } from '@finos/legend-shared'; import { CORE_HASH_STRUCTURE } from '../../../../../../../../../../MetaModelConst'; -import { hashLambda } from '../../../../../../../../../../MetaModelUtils'; +import { hashRawLambda } from '../../../../../../../../../../MetaModelUtils'; export class V1_GroupByFunction implements Hashable { /** @@ -30,7 +30,7 @@ export class V1_GroupByFunction 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), ]); } } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/model/rawValueSpecification/V1_RawLambda.ts b/packages/legend-graph/src/models/protocols/pure/v1/model/rawValueSpecification/V1_RawLambda.ts index 88c43dda30b..b3ca2f4c750 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/model/rawValueSpecification/V1_RawLambda.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/model/rawValueSpecification/V1_RawLambda.ts @@ -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 { @@ -29,7 +29,7 @@ export class V1_RawLambda extends V1_RawValueSpecification implements Hashable { get hashCode(): string { return hashArray([ CORE_HASH_STRUCTURE.RAW_LAMBDA, - hashLambda(this.parameters, this.body), + hashRawLambda(this.parameters, this.body), ]); } diff --git a/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.ts b/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.ts index cf1b47e556a..e5555b701d0 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_MappingTransformer.ts @@ -18,7 +18,6 @@ import { guaranteeNonEmptyString, IllegalStateError, isNonNullable, - recursiveOmit, UnsupportedOperationError, } from '@finos/legend-shared'; import type { Mapping } from '../../../../../../metamodels/pure/packageableElements/mapping/Mapping'; @@ -139,10 +138,7 @@ import { V1_JoinPointer } from '../../../model/packageableElements/store/relatio import type { V1_RawRelationalOperationElement } from '../../../model/packageableElements/store/relational/model/V1_RawRelationalOperationElement'; import { RelationalInputData } from '../../../../../../metamodels/pure/packageableElements/store/relational/mapping/RelationalInputData'; import { V1_RelationalInputData } from '../../../model/packageableElements/store/relational/mapping/V1_RelationalInputData'; -import { - SOURCE_INFORMATION_KEY, - PackageableElementPointerType, -} from '../../../../../../../MetaModelConst'; +import { PackageableElementPointerType } from '../../../../../../../MetaModelConst'; import type { V1_GraphTransformerContext } from './V1_GraphTransformerContext'; import type { DSLMapping_PureProtocolProcessorPlugin_Extension } from '../../../../DSLMapping_PureProtocolProcessorPlugin_Extension'; import type { InstanceSetImplementation } from '../../../../../../metamodels/pure/packageableElements/mapping/InstanceSetImplementation'; @@ -154,6 +150,7 @@ import type { TEMPORARY__UnresolvedSetImplementation } from '../../../../../../m import { isStubbed_EnumValueMapping } from '../../../../../../../graphManager/action/creation/DSLMapping_ModelCreatorHelper'; import { isStubbed_RawLambda } from '../../../../../../../graphManager/action/creation/RawValueSpecificationCreatorHelper'; import { isStubbed_RawRelationalOperationElement } from '../../../../../../../graphManager/action/creation/StoreRelational_ModelCreatorHelper'; +import { pruneSourceInformation } from '../../../../../../../MetaModelUtils'; export const V1_transformPropertyReference = ( element: PropertyReference, @@ -507,9 +504,8 @@ const transformRelationalPropertyMapping = ( propertyMapping.relationalOperation = ( context.keepSourceInformation ? element.relationalOperation - : recursiveOmit( + : pruneSourceInformation( element.relationalOperation as Record, - [SOURCE_INFORMATION_KEY], ) ) as V1_RawRelationalOperationElement; // NOTE: isTransformingSourceId is needed for the roundtrip of association relational property mapping diff --git a/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_RawValueSpecificationTransformer.ts b/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_RawValueSpecificationTransformer.ts index e42f4036fb6..5ce4300dfc1 100644 --- a/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_RawValueSpecificationTransformer.ts +++ b/packages/legend-graph/src/models/protocols/pure/v1/transformation/pureGraph/from/V1_RawValueSpecificationTransformer.ts @@ -23,12 +23,11 @@ import { V1_transformMultiplicity, V1_transformElementReference, } from './V1_CoreTransformerHelper'; -import { SOURCE_INFORMATION_KEY } from '../../../../../../../MetaModelConst'; -import { recursiveOmit } from '@finos/legend-shared'; import type { V1_GraphTransformerContext } from './V1_GraphTransformerContext'; import type { V1_RawValueSpecification } from '../../../model/rawValueSpecification/V1_RawValueSpecification'; import { V1_RawPrimitiveInstanceValue } from '../../../model/rawValueSpecification/V1_RawPrimitiveInstanceValue'; import type { RawPrimitiveInstanceValue } from '../../../../../../metamodels/pure/rawValueSpecification/RawPrimitiveInstanceValue'; +import { pruneSourceInformation } from '../../../../../../../MetaModelUtils'; export class V1_RawValueSpecificationTransformer implements RawValueSpecificationVisitor @@ -48,17 +47,15 @@ export class V1_RawValueSpecificationTransformer rawLambda.body = rawValueSpecification.body ? this.context.keepSourceInformation ? rawValueSpecification.body - : recursiveOmit( + : pruneSourceInformation( rawValueSpecification.body as Record, - [SOURCE_INFORMATION_KEY], ) : undefined; rawLambda.parameters = rawValueSpecification.parameters ? this.context.keepSourceInformation ? rawValueSpecification.parameters - : recursiveOmit( + : pruneSourceInformation( rawValueSpecification.parameters as Record, - [SOURCE_INFORMATION_KEY], ) : undefined; return rawLambda; diff --git a/packages/legend-manual-tests/src/__tests__/roundtrip-grammar-mismatch/RoundtripGrammarMismatch.test.ts b/packages/legend-manual-tests/src/__tests__/roundtrip-grammar-mismatch/RoundtripGrammarMismatch.test.ts index 65e8f14191b..2b57c6e9713 100644 --- a/packages/legend-manual-tests/src/__tests__/roundtrip-grammar-mismatch/RoundtripGrammarMismatch.test.ts +++ b/packages/legend-manual-tests/src/__tests__/roundtrip-grammar-mismatch/RoundtripGrammarMismatch.test.ts @@ -22,8 +22,10 @@ import { TEST__buildGraphWithEntities, TEST__getTestGraphManagerState, TEST__GraphPluginManager, + type V1_PureModelContextData, } from '@finos/legend-graph'; import { getLegendGraphExtensionCollection } from '@finos/legend-graph-extension-collection'; +import { ContentType, type PlainObject } from '@finos/legend-shared'; const engineConfig = JSON.parse( fs.readFileSync(resolve(__dirname, '../../../engine-config.json'), { @@ -121,16 +123,19 @@ const checkGrammarRoundtripMismatch = async ( const transformGrammarToJsonResult = await axios.post< unknown, - AxiosResponse<{ modelDataContext: unknown }> - >( - `${ENGINE_SERVER_URL}/pure/v1/grammar/transformGrammarToJson`, - { - code: grammarBefore, + AxiosResponse> + >(`${ENGINE_SERVER_URL}/pure/v1/grammar/grammarToJson/model`, grammarBefore, { + headers: { + 'Content-Type': ContentType.TEXT_PLAIN, }, - {}, - ); + // TODO: we should enable this, but we need to make sure engine works first + // See https://github.com/finos/legend-engine/pull/692 + // params: { + // returnSourceInformation: false, + // }, + }); const entities = graphManagerState.graphManager.pureProtocolTextToEntities( - JSON.stringify(transformGrammarToJsonResult.data.modelDataContext), + JSON.stringify(transformGrammarToJsonResult.data), ); await TEST__buildGraphWithEntities(graphManagerState, entities, { TEMPORARY__preserveSectionIndex: false, @@ -155,17 +160,21 @@ const checkGrammarRoundtripMismatch = async ( }; const transformJsonToGrammarResult = await axios.post< unknown, - AxiosResponse<{ code: string }> + AxiosResponse >( - `${ENGINE_SERVER_URL}/pure/v1/grammar/transformJsonToGrammar`, + `${ENGINE_SERVER_URL}/pure/v1/grammar/jsonToGrammar/model`, + modelDataContext, { - modelDataContext, - renderStyle: 'STANDARD', + headers: { + Accept: ContentType.TEXT_PLAIN, + }, + params: { + renderStyle: 'STANDARD', + }, }, - {}, ); if (!excludes.includes(phase)) { - expect(transformJsonToGrammarResult.data.code).toEqual(grammarAfter); + expect(transformJsonToGrammarResult.data).toEqual(grammarAfter); logSuccess(phase, options?.debug); } diff --git a/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/ProfilingGraphBuilding.test.ts b/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/ProfilingGraphBuilding.test.ts index 4b5cd3a902e..43cd68acaf1 100644 --- a/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/ProfilingGraphBuilding.test.ts +++ b/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/ProfilingGraphBuilding.test.ts @@ -19,13 +19,20 @@ import { resolve } from 'path'; import fs from 'fs'; import axios, { type AxiosResponse } from 'axios'; -import { WebConsole, Log, LogEvent } from '@finos/legend-shared'; +import { + WebConsole, + Log, + LogEvent, + ContentType, + type PlainObject, +} from '@finos/legend-shared'; import { TEST__GraphPluginManager, TEST__buildGraphWithEntities, TEST__getTestGraphManagerState, GRAPH_MANAGER_EVENT, V1_ENGINE_EVENT, + type V1_PureModelContextData, } from '@finos/legend-graph'; import { getLegendGraphExtensionCollection } from '@finos/legend-graph-extension-collection'; @@ -167,14 +174,17 @@ const profileRoundtrip = async ( let startTime = Date.now(); const transformGrammarToJsonResult = await axios.post< unknown, - AxiosResponse<{ modelDataContext: { elements: object[] } }> - >( - `${ENGINE_SERVER_URL}/pure/v1/grammar/transformGrammarToJson`, - { - code: grammarText, + AxiosResponse> + >(`${ENGINE_SERVER_URL}/pure/v1/grammar/grammarToJson/model`, grammarText, { + headers: { + 'Content-Type': ContentType.TEXT_PLAIN, }, - {}, - ); + // TODO: we should enable this, but we need to make sure engine works first + // See https://github.com/finos/legend-engine/pull/692 + // params: { + // returnSourceInformation: false, + // }, + }); if (options.debug) { log.info( LogEvent.create(V1_ENGINE_EVENT.GRAMMAR_TO_JSON), @@ -183,7 +193,7 @@ const profileRoundtrip = async ( ); } const entities = graphManagerState.graphManager.pureProtocolTextToEntities( - JSON.stringify(transformGrammarToJsonResult.data.modelDataContext), + JSON.stringify(transformGrammarToJsonResult.data), ); if (options.debug) { log.info( @@ -239,13 +249,17 @@ const profileRoundtrip = async ( .map((entity) => entity.content), }; startTime = Date.now(); - await axios.post>( - `${ENGINE_SERVER_URL}/pure/v1/grammar/transformJsonToGrammar`, + await axios.post>( + `${ENGINE_SERVER_URL}/pure/v1/grammar/jsonToGrammar/model`, + modelDataContext, { - modelDataContext, - renderStyle: 'STANDARD', + headers: { + Accept: ContentType.TEXT_PLAIN, + }, + params: { + renderStyle: 'STANDARD', + }, }, - {}, ); if (options.debug) { log.info( diff --git a/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/RoundtripGrammar.test.ts b/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/RoundtripGrammar.test.ts index a85f2629c24..c55812ebcc6 100644 --- a/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/RoundtripGrammar.test.ts +++ b/packages/legend-manual-tests/src/__tests__/roundtrip-grammar/RoundtripGrammar.test.ts @@ -23,6 +23,7 @@ import { WebConsole, Log, LogEvent, + ContentType, } from '@finos/legend-shared'; import { type V1_PackageableElement, @@ -157,14 +158,17 @@ const checkGrammarRoundtrip = async ( let startTime = Date.now(); const transformGrammarToJsonResult = await axios.post< unknown, - AxiosResponse<{ modelDataContext: { elements: object[] } }> - >( - `${ENGINE_SERVER_URL}/pure/v1/grammar/transformGrammarToJson`, - { - code: grammarText, + AxiosResponse<{ elements: object[] }> + >(`${ENGINE_SERVER_URL}/pure/v1/grammar/grammarToJson/model`, grammarText, { + headers: { + 'Content-Type': ContentType.TEXT_PLAIN, }, - {}, - ); + // TODO: we should enable this, but we need to make sure engine works first + // See https://github.com/finos/legend-engine/pull/692 + // params: { + // returnSourceInformation: false, + // }, + }); if (options?.debug) { log.info( LogEvent.create(V1_ENGINE_EVENT.GRAMMAR_TO_JSON), @@ -173,7 +177,7 @@ const checkGrammarRoundtrip = async ( ); } const entities = graphManagerState.graphManager.pureProtocolTextToEntities( - JSON.stringify(transformGrammarToJsonResult.data.modelDataContext), + JSON.stringify(transformGrammarToJsonResult.data), ); if (options?.debug) { log.info( @@ -216,7 +220,10 @@ const checkGrammarRoundtrip = async ( .map(graphManagerState.graphManager.pruneSourceInformation), ).toIncludeSameMembers( // expected: protocol JSON parsed from grammar text - transformGrammarToJsonResult.data.modelDataContext.elements + ( + (transformGrammarToJsonResult.data as { elements: object[] }) + .elements as PlainObject[] + ) .map(graphManagerState.graphManager.pruneSourceInformation) .filter( (elementProtocol: PlainObject) => @@ -256,14 +263,18 @@ const checkGrammarRoundtrip = async ( startTime = Date.now(); const transformJsonToGrammarResult = await axios.post< unknown, - AxiosResponse<{ code: string }> + AxiosResponse >( - `${ENGINE_SERVER_URL}/pure/v1/grammar/transformJsonToGrammar`, + `${ENGINE_SERVER_URL}/pure/v1/grammar/jsonToGrammar/model`, + modelDataContext, { - modelDataContext, - renderStyle: 'STANDARD', + headers: { + Accept: ContentType.TEXT_PLAIN, + }, + params: { + renderStyle: 'STANDARD', + }, }, - {}, ); if (options?.debug) { log.info( @@ -273,7 +284,7 @@ const checkGrammarRoundtrip = async ( ); } if (!excludes.includes(phase)) { - expect(transformJsonToGrammarResult.data.code).toEqual(grammarText); + expect(transformJsonToGrammarResult.data).toEqual(grammarText); logSuccess(phase, log, options?.debug); } diff --git a/packages/legend-query/src/stores/QueryBuilderProjectionState.ts b/packages/legend-query/src/stores/QueryBuilderProjectionState.ts index f12284d13f5..fd963af7888 100644 --- a/packages/legend-query/src/stores/QueryBuilderProjectionState.ts +++ b/packages/legend-query/src/stores/QueryBuilderProjectionState.ts @@ -229,9 +229,9 @@ class QueryBuilderDerivationProjectionLambdaState extends LambdaEditorState { (yield this.queryBuilderState.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); - this.derivationProjectionColumnState.setLambda(lambda ?? emptyLambda); + this.derivationProjectionColumnState.setLambda(lambda); } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { diff --git a/packages/legend-query/src/stores/QueryTextEditorState.ts b/packages/legend-query/src/stores/QueryTextEditorState.ts index c3910a10f58..9e7509b235c 100644 --- a/packages/legend-query/src/stores/QueryTextEditorState.ts +++ b/packages/legend-query/src/stores/QueryTextEditorState.ts @@ -20,6 +20,7 @@ import { ParserError, RawLambda, stub_RawLambda, + pruneSourceInformation, } from '@finos/legend-graph'; import { type GeneratorFn, @@ -104,9 +105,9 @@ export class QueryTextEditorState extends LambdaEditorState { (yield this.queryBuilderState.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); - this.rawLambdaState.setLambda(lambda ?? emptyLambda); + this.rawLambdaState.setLambda(lambda); } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { @@ -170,7 +171,7 @@ export class QueryTextEditorState extends LambdaEditorState { if (mode === QueryTextEditorMode.JSON) { this.setLambdaJson( JSON.stringify( - this.queryBuilderState.graphManagerState.graphManager.pruneSourceInformation( + pruneSourceInformation( this.queryBuilderState.graphManagerState.graphManager.serializeRawValueSpecification( rawLambda, ), diff --git a/packages/legend-shared/src/application/SerializationUtils.ts b/packages/legend-shared/src/application/SerializationUtils.ts index 963a169467f..6f97dd906de 100644 --- a/packages/legend-shared/src/application/SerializationUtils.ts +++ b/packages/legend-shared/src/application/SerializationUtils.ts @@ -134,12 +134,15 @@ export const serializeArray = ( // determines if it should produce object or ES6 Map but we always want ES6 Map, // so we would use this function export const deserializeMap = ( - val: Record>, - itemDeserializer: (val: PlainObject) => T, + val: Record : T>, + itemDeserializer: (val: T extends object ? PlainObject : T) => T, ): Map => { const result = new Map(); Object.keys(val).forEach((key: string) => - result.set(key, itemDeserializer(val[key] as PlainObject)), + result.set( + key, + itemDeserializer(val[key] as T extends object ? PlainObject : T), + ), ); return result; }; diff --git a/packages/legend-studio/src/stores/editor-state/element-editor-state/ClassState.ts b/packages/legend-studio/src/stores/editor-state/element-editor-state/ClassState.ts index 127cf1f96fa..61c320c2ff8 100644 --- a/packages/legend-studio/src/stores/editor-state/element-editor-state/ClassState.ts +++ b/packages/legend-studio/src/stores/editor-state/element-editor-state/ClassState.ts @@ -85,9 +85,9 @@ export class DerivedPropertyState extends LambdaEditorState { (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); - this.setBodyAndParameters(lambda ?? emptyLambda); + this.setBodyAndParameters(lambda); } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { @@ -174,12 +174,9 @@ export class ConstraintState extends LambdaEditorState { (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); - constraint_setFunctionDefinition( - this.constraint, - lambda ?? emptyFunctionDefinition, - ); + constraint_setFunctionDefinition(this.constraint, lambda); } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { diff --git a/packages/legend-studio/src/stores/editor-state/element-editor-state/FunctionEditorState.ts b/packages/legend-studio/src/stores/editor-state/element-editor-state/FunctionEditorState.ts index b7dcac731db..0fc1c004cf9 100644 --- a/packages/legend-studio/src/stores/editor-state/element-editor-state/FunctionEditorState.ts +++ b/packages/legend-studio/src/stores/editor-state/element-editor-state/FunctionEditorState.ts @@ -74,9 +74,9 @@ export class FunctionBodyEditorState extends LambdaEditorState { (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); - this.functionElement.body = lambda ? (lambda.body as object[]) : []; + this.functionElement.body = lambda.body as object[]; } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { diff --git a/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/FlatDataInstanceSetImplementationState.ts b/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/FlatDataInstanceSetImplementationState.ts index 228a05c915b..b9e30c79dec 100644 --- a/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/FlatDataInstanceSetImplementationState.ts +++ b/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/FlatDataInstanceSetImplementationState.ts @@ -85,10 +85,10 @@ export class FlatDataPropertyMappingState extends PropertyMappingState { (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); if (this.propertyMapping instanceof FlatDataPropertyMapping) { - this.propertyMapping.transform = lambda ?? emptyLambda; + this.propertyMapping.transform = lambda; } } catch (error) { assertErrorThrown(error); diff --git a/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/PureInstanceSetImplementationState.ts b/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/PureInstanceSetImplementationState.ts index 6554f6e18b5..1a04c9d2a0d 100644 --- a/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/PureInstanceSetImplementationState.ts +++ b/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/PureInstanceSetImplementationState.ts @@ -80,9 +80,9 @@ export class PurePropertyMappingState extends PropertyMappingState { (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); - this.propertyMapping.transform = lambda ?? emptyLambda; + this.propertyMapping.transform = lambda; } catch (error) { assertErrorThrown(error); if (error instanceof ParserError) { @@ -164,11 +164,11 @@ export class PureInstanceSetImplementationFilterState extends LambdaEditorState (yield this.editorStore.graphManagerState.graphManager.pureCodeToLambda( this.fullLambdaString, this.lambdaId, - )) as RawLambda | undefined; + )) as RawLambda; this.setParserError(undefined); pureInstanceSetImpl_setMappingFilter( this.instanceSetImplementation, - lambda ?? emptyFunctionDefinition, + lambda, ); } catch (error) { assertErrorThrown(error); @@ -198,7 +198,6 @@ export class PureInstanceSetImplementationFilterState extends LambdaEditorState const grammarText = (yield this.editorStore.graphManagerState.graphManager.lambdaToPureCode( this.instanceSetImplementation.filter, - this.lambdaId, pretty, )) as string; this.setLambdaString(this.extractLambdaString(grammarText)); diff --git a/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/relational/RelationalInstanceSetImplementationState.ts b/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/relational/RelationalInstanceSetImplementationState.ts index ce88d90ff1a..9aa73d14c21 100644 --- a/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/relational/RelationalInstanceSetImplementationState.ts +++ b/packages/legend-studio/src/stores/editor-state/element-editor-state/mapping/relational/RelationalInstanceSetImplementationState.ts @@ -86,10 +86,10 @@ export class RelationalPropertyMappingState extends PropertyMappingState { (yield this.editorStore.graphManagerState.graphManager.pureCodeToRelationalOperationElement( this.fullLambdaString, this.lambdaId, - )) as RawRelationalOperationElement | undefined; + )) as RawRelationalOperationElement; this.setParserError(undefined); if (this.propertyMapping instanceof RelationalPropertyMapping) { - this.propertyMapping.relationalOperation = operation ?? stubOperation; + this.propertyMapping.relationalOperation = operation; } } catch (error) { assertErrorThrown(error); diff --git a/packages/legend-studio/src/stores/editor-state/element-editor-state/service/ServiceExecutionState.ts b/packages/legend-studio/src/stores/editor-state/element-editor-state/service/ServiceExecutionState.ts index acdd775b1c8..ee3ef22df88 100644 --- a/packages/legend-studio/src/stores/editor-state/element-editor-state/service/ServiceExecutionState.ts +++ b/packages/legend-studio/src/stores/editor-state/element-editor-state/service/ServiceExecutionState.ts @@ -220,7 +220,6 @@ export class ServicePureExecutionQueryState extends LambdaEditorState { query.id, )) as string, )) as RawLambda, - '', true, )) as string; this.selectedQueryInfo = {