Skip to content

Commit

Permalink
feat(alias): Pr suggestion added
Browse files Browse the repository at this point in the history
- Added new test case where a concept is extended on a aliased import
  type concept
- removed unecessary comments and formated code

Signed-off-by: Jaskeerat Singh Saluja <[email protected]>
  • Loading branch information
salujajaskeerat committed Jul 9, 2024
1 parent 68b37ac commit 56356ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ 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 @@ -738,7 +737,6 @@ class ModelFile extends Decorated {
);
}

// TODO:handle ImportTypes
this.imports = imports;
this.imports.forEach((imp) => {
this.enforceImportVersioning(imp);
Expand All @@ -752,8 +750,6 @@ class ModelFile extends Decorated {
break;
case `${MetaModelNamespace}.ImportTypes`:
if (this.getModelManager().isAliasedTypeEnabled()) {
// map: alias name to the fqn's
// imp.types and imp.aliasedTypes both are available
const aliasedTypes = new Map();
if (imp.aliasedTypes) {
imp.aliasedTypes.forEach(({ name, aliasName }) => {
Expand All @@ -763,7 +759,18 @@ class ModelFile extends Decorated {
aliasedTypes.set(name, aliasName);
});
}
imp.types.forEach((type)=> aliasedTypes.has(type)? this.importShortNames.set(aliasedTypes.get(type),`${imp.namespace}.${type}`):this.importShortNames.set(type,`${imp.namespace}.${type}`));
// Local-name(aliased or non-aliased) is mapped to the Fully qualified type name
imp.types.forEach((type) =>
aliasedTypes.has(type)
? this.importShortNames.set(
aliasedTypes.get(type),
`${imp.namespace}.${type}`
)
: this.importShortNames.set(
type,
`${imp.namespace}.${type}`
)
);
} else {
if (imp.aliasedTypes) {
throw new Error('Aliasing disabled, set enableAliasType to true');
Expand Down
23 changes: 23 additions & 0 deletions packages/concerto-core/test/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,29 @@ describe('ModelFile', () => {
let modelFile2 = ParserUtil.newModelFile(modelManager, model2);
(() => modelFile2.validate()).should.not.throw();
});

it('should not throw if declaration is extended on a aliased type declaration', () => {
const model1 = `
namespace org.saluja
scalar nickname extends String
asset Vehicle identified by serialno {
o String serialno
}`;
const model2 = `
namespace org.acme
import org.saluja.{Vehicle as V,nickname as nk}
asset Car extends V{
o String company
o nk shortname
}`;
modelManager.enableMapType = true;
let modelFile1 = ParserUtil.newModelFile(modelManager, model1);
modelManager.addModelFile(modelFile1);
let modelFile2 = ParserUtil.newModelFile(modelManager, model2);
(() => modelFile2.validate()).should.not.throw();
});
});


Expand Down

0 comments on commit 56356ca

Please sign in to comment.