Skip to content

Commit

Permalink
fix(aliasing): added new resolvedName property to typeIdentifier obje…
Browse files Browse the repository at this point in the history
…ct for import aliased declrations (#36)

* fix(aliasing): added new resolvedName property to typeIdentifier object for import aliased declrations

Signed-off-by: sanketshevkar <[email protected]>

* fix(aliasing): added new resolvedName property to typeIdentifier object for import aliased declrations

Signed-off-by: sanketshevkar <[email protected]>

---------

Signed-off-by: sanketshevkar <[email protected]>
  • Loading branch information
sanketshevkar authored Jan 16, 2025
1 parent 826a20c commit 9a02b5b
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 71 deletions.
5 changes: 2 additions & 3 deletions lib/metamodel.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions lib/metamodel.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
"isArray": false,
"isOptional": false
},
{
"$class": "[email protected]",
"name": "resolvedName",
"isArray": false,
"isOptional": true
},
{
"$class": "[email protected]",
"name": "namespace",
Expand Down Expand Up @@ -998,10 +1004,10 @@
]
},
{
"$class":"[email protected]",
"name":"AliasedType",
"isAbstract":false,
"properties":[
"$class": "[email protected]",
"name": "AliasedType",
"isAbstract": false,
"properties": [
{
"$class": "[email protected]",
"name": "name",
Expand Down Expand Up @@ -1089,7 +1095,6 @@
"name": "Import"
}
},

{
"$class": "[email protected]",
"name": "Model",
Expand Down
12 changes: 9 additions & 3 deletions lib/metamodelutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function createNameTable(priorModels, metaModel) {
'Asset': {namespace: concertoNs, name: 'Asset'},
'Participant': {namespace: concertoNs, name: 'Participant'},
'Transaction': {namespace: concertoNs, name: 'Transaction'},
'Event': {namespace: concertoNs, name: 'Event'}
'Event': {namespace: concertoNs, name: 'Event'},
};

// First list the imported names in order (overriding as we go along)
Expand All @@ -89,7 +89,7 @@ function createNameTable(priorModels, metaModel) {
if (!findDeclaration(modelFile, type)) {
throw new Error(`Declaration ${type} in namespace ${namespace} not found`);
}
table[localName] = {namespace, name: type};
table[localName] = localName !== type ? {namespace, name: localName, resolvedName: type} : {namespace, name: type};
});
} else {
(modelFile.declarations || []).forEach((decl) => {
Expand Down Expand Up @@ -147,6 +147,9 @@ function resolveTypeNames(metaModel, table) {
const name = metaModel.superType.name;
metaModel.superType.namespace = resolveName(name, table);
metaModel.superType.name = table[name].name;
if (table[name]?.resolvedName) {
metaModel.superType.resolvedName = table[name].resolvedName;
}
}
(metaModel.properties || []).forEach((property) => {
resolveTypeNames(property, table);
Expand All @@ -172,6 +175,9 @@ function resolveTypeNames(metaModel, table) {
case `${MetaModelNamespace}.ObjectMapValueType`: {
metaModel.type.namespace = resolveName(metaModel.type.name, table);
metaModel.type.name = table[metaModel.type.name].name;
if (table[metaModel.type.name]?.resolvedName) {
metaModel.type.resolvedName = table[metaModel.type.name].resolvedName;
}
}
break;
case `${MetaModelNamespace}.StringScalar`:
Expand Down Expand Up @@ -273,4 +279,4 @@ module.exports = {
resolveLocalNamesForAll,
importFullyQualifiedNames,
getExternalImports,
};
};
Loading

0 comments on commit 9a02b5b

Please sign in to comment.