Skip to content

Commit

Permalink
feat(map): add property based flag (#728)
Browse files Browse the repository at this point in the history
* feat(map): add property based flag

Signed-off-by: Jonathan Casey <[email protected]>

* fix typo

Signed-off-by: Jonathan Casey <[email protected]>

---------

Signed-off-by: Jonathan Casey <[email protected]>
  • Loading branch information
jonathan-casey authored Oct 9, 2023
1 parent 3337541 commit e067cc3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/concerto-core/lib/basemodelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class BaseModelManager {
this.options = options;
this.addRootModel();

// TODO Remove on release of MapType
// Supports both env var and property based flag
this.enableMapType = !!options?.enableMapType;

// Cache a copy of the Metamodel ModelFile for use when validating the structure of ModelFiles later.
this.metamodelModelFile = new ModelFile(this, MetaModelUtil.metaModelAst, undefined, MetaModelNamespace);

Expand Down
5 changes: 3 additions & 2 deletions packages/concerto-core/lib/introspect/mapdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class MapDeclaration extends Declaration {
*/
constructor(modelFile, ast) {
// TODO remove on full release.
if(process.env.ENABLE_MAP_TYPE !== 'true') {
throw new Error('MapType feature is not enabled. Please set the environment variable "ENABLE_MAP_TYPE=true" to access this functionality.');
const mm = modelFile.getModelManager();
if(process.env.ENABLE_MAP_TYPE !== 'true' && !mm.enableMapType) {
throw new Error('MapType feature is not enabled. Please set the environment variable "ENABLE_MAP_TYPE=true", or add {enableMapType: true} to the ModelManger options, to access this functionality.');
}

super(modelFile, ast);
Expand Down
22 changes: 20 additions & 2 deletions packages/concerto-core/test/introspect/mapdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,29 @@ describe('MapDeclaration', () => {
$class: '[email protected]'
}
});
}).should.throw(/MapType feature is not enabled. Please set the environment variable "ENABLE_MAP_TYPE=true" to access this functionality./);
}).should.throw(/MapType feature is not enabled. Please set the environment variable "ENABLE_MAP_TYPE=true", or add {enableMapType: true} to the ModelManger options, to access this functionality/);
process.env.ENABLE_MAP_TYPE = 'true'; // enable after the test run. This is necessary to ensure functioning of other tests.
});


it('should throw if Map Type not enabled in ModelManager options', () => {
process.env.ENABLE_MAP_TYPE = 'false';
const mm = new ModelManager({enableMapType: false});
Util.addComposerModel(mm);
const introspectUtils = new IntrospectUtils(mm);
try {
introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodkey.primitive.datetime.cto', MapDeclaration);
} catch (error) {
expect(error.message).to.equal('MapType feature is not enabled. Please set the environment variable "ENABLE_MAP_TYPE=true", or add {enableMapType: true} to the ModelManger options, to access this functionality.');
}
});

it('should not throw if Map Type is enabled in ModelManager options', () => {
const mm = new ModelManager({enableMapType: true});
Util.addComposerModel(mm);
const introspectUtils = new IntrospectUtils(mm);
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodkey.primitive.datetime.cto', MapDeclaration);
decl.validate();
});

it('should throw if invalid $class provided for Map Key', () => {
(() =>
Expand Down

0 comments on commit e067cc3

Please sign in to comment.