Skip to content

Commit

Permalink
feature(core): Add distinct AstModelManager
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
Jerome Simeon authored and Jerome Simeon committed Mar 15, 2022
1 parent 2c3bf4e commit a7665fd
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class AstModelManager extends BaseModelManager {
+ void constructor(object?)
}
class BaseModelManager {
+ void constructor(object?,processFile?)
+ boolean isModelManager()
Expand Down Expand Up @@ -223,7 +226,7 @@ class ModelLoader {
+ object loadModelManagerFromModelFiles(object[],string[],object,boolean?,number?)
}
class ModelManager extends BaseModelManager {
+ void constructor(object?,processFile?)
+ void constructor(object?)
+ Object addCTOModel(string,string,boolean?) throws IllegalModelException
}
class SecurityException extends BaseException {
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 1.2.2 {a92fdef435d8588901b0c5f4b7b7cff1} 2021-11-24
Version 1.2.2 {0bd210dc69b3813e8724353b1c355efc} 2021-11-24
- Remove custom instanceof and add methods to check runtime type
- Remove support for Node 12
- Generate Typescript definitions from JSDoc
Expand Down
52 changes: 52 additions & 0 deletions packages/concerto-core/lib/astmodelmanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const BaseModelManager = require('./basemodelmanager');

// How to create a modelfile from a cto file
const astProcessFile = (name, data) => {
return {
ast: data,
definitions: null,
fileName: name,
};
};

/**
* Manages the Concerto model files in AST format.
*
* The structure of {@link Resource}s (Assets, Transactions, Participants) is modelled
* in a set of Concerto files. The contents of these files are managed
* by the {@link ModelManager}. Each Concerto file has a single namespace and contains
* a set of asset, transaction and participant type definitions.
*
* Concerto applications load their Concerto files and then call the {@link ModelManager#addModelFile addModelFile}
* method to register the Concerto file(s) with the ModelManager.
*
* @memberof module:concerto-core
*/
class AstModelManager extends BaseModelManager {
/**
* Create the ModelManager.
* @constructor
* @param {object} [options] - Serializer options
*/
constructor(options) {
super(options, astProcessFile);
}
}

module.exports = AstModelManager;
1 change: 0 additions & 1 deletion packages/concerto-core/lib/modelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class ModelManager extends BaseModelManager {
* Create the ModelManager.
* @constructor
* @param {object} [options] - Serializer options
* @param {*} [processFile] - how to obtain a concerto AST from an input to the model manager
*/
constructor(options) {
super(options, ctoProcessFile);
Expand Down
44 changes: 44 additions & 0 deletions packages/concerto-core/test/astmodelmanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const AstModelManager = require('../lib/astmodelmanager');

const chai = require('chai');
chai.should();
chai.use(require('chai-things'));
chai.use(require('chai-as-promised'));
const sinon = require('sinon');

describe('AstModelManager', () => {
let sandbox;
let modelManager;

beforeEach(() => {
sandbox = sinon.createSandbox();
modelManager = new AstModelManager();
});

afterEach(() => {
sandbox.restore();
});

describe('#isModelManager', () => {
it('should return true', () => {
modelManager.isModelManager().should.be.true;
});
});

});

0 comments on commit a7665fd

Please sign in to comment.