-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aliasing): resolve aliased import type name to imported type name
Signed-off-by: muhammed-abdulkadir <[email protected]>
- Loading branch information
muhammed-abdulkadir
committed
Dec 2, 2024
1 parent
46354a3
commit 6d02b65
Showing
1 changed file
with
14 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,11 +59,11 @@ function findDeclaration(thisModel, name) { | |
function createNameTable(priorModels, metaModel) { | ||
const concertoNs = '[email protected]'; | ||
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; | ||
} | ||
|