Skip to content

Commit

Permalink
feat(alias import): modelfile.js alias imports handled
Browse files Browse the repository at this point in the history
- alias types mapped to fqn in the importShortNames

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>
  • Loading branch information
salujajaskeerat committed Jun 20, 2024
1 parent 09f6b04 commit 4d26b39
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/concerto-core/lib/basemodelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ class BaseModelManager {
return this.strict;
}

/**
* Returns the value of the enableAliasedType option
* @returns {boolean} true if the enableAliasedType has been set
*/
isAliasedTypeEnabled() {
return this.enableAliasedType;
}

/**
* Adds root types
* @private
Expand Down
23 changes: 19 additions & 4 deletions packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ModelFile extends Decorated {
*/
validate() {
super.validate();

// TODO
// A dictionary of imports to versions to track unique namespaces
const importsMap = new Map();

Expand Down Expand Up @@ -752,9 +752,24 @@ class ModelFile extends Decorated {
this.importWildcardNamespaces.push(imp.namespace);
break;
case `${MetaModelNamespace}.ImportTypes`:
imp.types.forEach( type => {
this.importShortNames.set(type, `${imp.namespace}.${type}`);
});
if (this.getModelManager().isAliasedTypeEnabled()) {
// map: alias name to the fqn's
// imp.types and imp.aliasedTypes both are available
let aliasedTypes = new Map();
if (imp.aliasedTypes) {
imp.aliasedTypes.forEach(({ name, aliasName }) => {
aliasedTypes.set(name, aliasName);
});
}
imp.types.forEach((type)=> aliasedTypes.has(type)? this.importShortNames.set(aliasedTypes[type],`${imp.namespace}.${type}`):this.importShortNames.set(type,`${imp.namespace}.${type}`));
} else {
if (imp.aliasedTypes) {
throw new Error('Aliasing disabled, set enableAliasType to true');
}
imp.types.forEach((type) => {
this.importShortNames.set(type,`${imp.namespace}.${type}`);
});
}
break;
default:
this.importShortNames.set(imp.name, ModelUtil.importFullyQualifiedNames(imp)[0]);
Expand Down

0 comments on commit 4d26b39

Please sign in to comment.