From 4d26b390fa40e07bc3367ba32df4b3d54c38cb62 Mon Sep 17 00:00:00 2001 From: Jaskeerat Singh Saluja <58400083+salujajaskeerat@users.noreply.github.com> Date: Fri, 21 Jun 2024 01:34:45 +0530 Subject: [PATCH] feat(alias import): modelfile.js alias imports handled - alias types mapped to fqn in the importShortNames Signed-off-by: Jaskeerat Singh Saluja <58400083+salujajaskeerat@users.noreply.github.com> --- .../concerto-core/lib/basemodelmanager.js | 8 +++++++ .../concerto-core/lib/introspect/modelfile.js | 23 +++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/concerto-core/lib/basemodelmanager.js b/packages/concerto-core/lib/basemodelmanager.js index 1b38ca430..ec1507c5d 100644 --- a/packages/concerto-core/lib/basemodelmanager.js +++ b/packages/concerto-core/lib/basemodelmanager.js @@ -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 diff --git a/packages/concerto-core/lib/introspect/modelfile.js b/packages/concerto-core/lib/introspect/modelfile.js index e9694518d..e4bec4077 100644 --- a/packages/concerto-core/lib/introspect/modelfile.js +++ b/packages/concerto-core/lib/introspect/modelfile.js @@ -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(); @@ -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]);