From 6d02b65991ff052bc22cfef4e0bcc5b1448a8f53 Mon Sep 17 00:00:00 2001 From: muhammed-abdulkadir Date: Mon, 2 Dec 2024 10:48:03 +0400 Subject: [PATCH 1/2] fix(aliasing): resolve aliased import type name to imported type name Signed-off-by: muhammed-abdulkadir --- lib/metamodelutil.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/metamodelutil.js b/lib/metamodelutil.js index e735146..83d3184 100644 --- a/lib/metamodelutil.js +++ b/lib/metamodelutil.js @@ -59,11 +59,11 @@ function findDeclaration(thisModel, name) { function createNameTable(priorModels, metaModel) { const concertoNs = 'concerto@1.0.0'; const table = { - 'Concept': concertoNs, - 'Asset': concertoNs, - 'Participant': concertoNs, - 'Transaction ': concertoNs, - 'Event': concertoNs + 'Concept': {namespace: concertoNs, name: 'Concept'}, + 'Asset': {namespace: concertoNs, name: 'Asset'}, + 'Participant': {namespace: concertoNs, name: 'Participant'}, + 'Transaction ': {namespace: concertoNs, name: 'Transaction'}, + 'Event': {namespace: concertoNs, name: 'Event'} }; // First list the imported names in order (overriding as we go along) @@ -74,7 +74,7 @@ function createNameTable(priorModels, metaModel) { if (!findDeclaration(modelFile, imp.name)) { throw new Error(`Declaration ${imp.name} in namespace ${namespace} not found`); } - table[imp.name] = namespace; + table[imp.name] = {namespace, name: imp.name}; } else if (imp.$class === `${MetaModelNamespace}.ImportTypes`) { // Create a map of aliased types if they exist, otherwise initialize an empty map. const aliasedMap = imp.aliasedTypes @@ -89,18 +89,18 @@ function createNameTable(priorModels, metaModel) { if (!findDeclaration(modelFile, type)) { throw new Error(`Declaration ${type} in namespace ${namespace} not found`); } - table[localName] = namespace; + table[localName] = {namespace, name: type}; }); } else { (modelFile.declarations || []).forEach((decl) => { - table[decl.name] = namespace; + table[decl.name] = {namespace, name: decl.name}; }); } }); // Then add the names local to this metaModel (overriding as we go along) (metaModel.declarations || []).forEach((decl) => { - table[decl.name] = metaModel.namespace; + table[decl.name] = {namespace: metaModel.namespace, name: decl.name}; }); return table; @@ -116,7 +116,7 @@ function resolveName(name, table) { if (!table[name]) { throw new Error(`Name ${name} not found`); } - return table[name]; + return table[name].namespace; } /** @@ -146,9 +146,11 @@ function resolveTypeNames(metaModel, table) { if (metaModel.superType) { const name = metaModel.superType.name; metaModel.superType.namespace = resolveName(name, table); + metaModel.superType.name = table[name].name; } (metaModel.properties || []).forEach((property) => { resolveTypeNames(property, table); + metaModel.property.name = table[property.name].name; }); } break; @@ -170,6 +172,7 @@ function resolveTypeNames(metaModel, table) { case `${MetaModelNamespace}.ObjectMapKeyType`: case `${MetaModelNamespace}.ObjectMapValueType`: { metaModel.type.namespace = resolveName(metaModel.type.name, table); + metaModel.type.name = table[metaModel.type.name].name; } break; case `${MetaModelNamespace}.StringScalar`: @@ -179,6 +182,7 @@ function resolveTypeNames(metaModel, table) { case `${MetaModelNamespace}.LongScalar`: case `${MetaModelNamespace}.IntegerScalar`: { metaModel.namespace = resolveName(metaModel.name, table); + metaModel.name = table[metaModel.name].name; } break; } From 1a1b3530d3220750aad36ab00a8e2f7da55558ce Mon Sep 17 00:00:00 2001 From: muhammed-abdulkadir Date: Tue, 3 Dec 2024 11:17:12 +0400 Subject: [PATCH 2/2] chore(*): update test Signed-off-by: muhammed-abdulkadir --- lib/metamodelutil.js | 3 +- test/cto/aliasedImport.json | 49 ++------------------------- test/cto/aliasedImportResolved.json | 51 ++--------------------------- 3 files changed, 6 insertions(+), 97 deletions(-) diff --git a/lib/metamodelutil.js b/lib/metamodelutil.js index 83d3184..7885867 100644 --- a/lib/metamodelutil.js +++ b/lib/metamodelutil.js @@ -62,7 +62,7 @@ function createNameTable(priorModels, metaModel) { 'Concept': {namespace: concertoNs, name: 'Concept'}, 'Asset': {namespace: concertoNs, name: 'Asset'}, 'Participant': {namespace: concertoNs, name: 'Participant'}, - 'Transaction ': {namespace: concertoNs, name: 'Transaction'}, + 'Transaction': {namespace: concertoNs, name: 'Transaction'}, 'Event': {namespace: concertoNs, name: 'Event'} }; @@ -150,7 +150,6 @@ function resolveTypeNames(metaModel, table) { } (metaModel.properties || []).forEach((property) => { resolveTypeNames(property, table); - metaModel.property.name = table[property.name].name; }); } break; diff --git a/test/cto/aliasedImport.json b/test/cto/aliasedImport.json index aa28b3f..35f2217 100644 --- a/test/cto/aliasedImport.json +++ b/test/cto/aliasedImport.json @@ -16,39 +16,9 @@ "$class": "concerto.metamodel@1.0.0.StringProperty", "name": "name", "isArray": false, - "isOptional": false, - "location": { - "$class": "concerto.metamodel@1.0.0.Range", - "start": { - "offset": 35, - "line": 4, - "column": 2, - "$class": "concerto.metamodel@1.0.0.Position" - }, - "end": { - "offset": 49, - "line": 5, - "column": 1, - "$class": "concerto.metamodel@1.0.0.Position" - } - } + "isOptional": false } - ], - "location": { - "$class": "concerto.metamodel@1.0.0.Range", - "start": { - "offset": 22, - "line": 3, - "column": 1, - "$class": "concerto.metamodel@1.0.0.Position" - }, - "end": { - "offset": 50, - "line": 5, - "column": 2, - "$class": "concerto.metamodel@1.0.0.Position" - } - } + ] } ] }, @@ -78,21 +48,6 @@ "name": "file", "isAbstract": false, "properties": [], - "location": { - "$class": "concerto.metamodel@1.0.0.Range", - "start": { - "offset": 50, - "line": 5, - "column": 1, - "$class": "concerto.metamodel@1.0.0.Position" - }, - "end": { - "offset": 75, - "line": 6, - "column": 2, - "$class": "concerto.metamodel@1.0.0.Position" - } - }, "superType": { "$class": "concerto.metamodel@1.0.0.TypeIdentifier", "name": "d" diff --git a/test/cto/aliasedImportResolved.json b/test/cto/aliasedImportResolved.json index f2e11cb..4feb000 100644 --- a/test/cto/aliasedImportResolved.json +++ b/test/cto/aliasedImportResolved.json @@ -16,39 +16,9 @@ "$class": "concerto.metamodel@1.0.0.StringProperty", "name": "name", "isArray": false, - "isOptional": false, - "location": { - "$class": "concerto.metamodel@1.0.0.Range", - "start": { - "offset": 35, - "line": 4, - "column": 2, - "$class": "concerto.metamodel@1.0.0.Position" - }, - "end": { - "offset": 49, - "line": 5, - "column": 1, - "$class": "concerto.metamodel@1.0.0.Position" - } - } + "isOptional": false } - ], - "location": { - "$class": "concerto.metamodel@1.0.0.Range", - "start": { - "offset": 22, - "line": 3, - "column": 1, - "$class": "concerto.metamodel@1.0.0.Position" - }, - "end": { - "offset": 50, - "line": 5, - "column": 2, - "$class": "concerto.metamodel@1.0.0.Position" - } - } + ] } ] }, @@ -78,24 +48,9 @@ "name": "file", "isAbstract": false, "properties": [], - "location": { - "$class": "concerto.metamodel@1.0.0.Range", - "start": { - "offset": 50, - "line": 5, - "column": 1, - "$class": "concerto.metamodel@1.0.0.Position" - }, - "end": { - "offset": 75, - "line": 6, - "column": 2, - "$class": "concerto.metamodel@1.0.0.Position" - } - }, "superType": { "$class": "concerto.metamodel@1.0.0.TypeIdentifier", - "name": "d", + "name": "doc", "namespace": "org.saluja" } }