diff --git a/packages/concerto-core/api.txt b/packages/concerto-core/api.txt index 896399f87..725515c33 100644 --- a/packages/concerto-core/api.txt +++ b/packages/concerto-core/api.txt @@ -211,6 +211,7 @@ class ModelFile extends Decorated { + TransactionDeclaration[] getTransactionDeclarations() + EventDeclaration[] getEventDeclarations() + ParticipantDeclaration[] getParticipantDeclarations() + + ClassDeclaration[] getClassDeclarations() + ConceptDeclaration[] getConceptDeclarations() + EnumDeclaration[] getEnumDeclarations() + MapDeclaration[] getMapDeclarations() diff --git a/packages/concerto-core/changelog.txt b/packages/concerto-core/changelog.txt index a99aa193e..df015d64e 100644 --- a/packages/concerto-core/changelog.txt +++ b/packages/concerto-core/changelog.txt @@ -24,6 +24,9 @@ # Note that the latest public API is documented using JSDocs and is available in api.txt. # +Version 3.12.2 {bb8951ea059e312cd347b715bc9fc8d7} 2023-08-28 +- Adds ModelFile :: getClassDeclarations + Version 3.10.1 {399b057614d1178c02b744184b09f845} 2023-08-22 - Change return type for MapDeclaration :: MapKeyType MapValueType diff --git a/packages/concerto-core/lib/introspect/modelfile.js b/packages/concerto-core/lib/introspect/modelfile.js index 497e68cf6..27d72be30 100644 --- a/packages/concerto-core/lib/introspect/modelfile.js +++ b/packages/concerto-core/lib/introspect/modelfile.js @@ -20,6 +20,7 @@ const packageJson = require('../../package.json'); const semver = require('semver'); const AssetDeclaration = require('./assetdeclaration'); const EnumDeclaration = require('./enumdeclaration'); +const ClassDeclaration = require('./classdeclaration'); const ConceptDeclaration = require('./conceptdeclaration'); const ScalarDeclaration = require('./scalardeclaration'); const ParticipantDeclaration = require('./participantdeclaration'); @@ -575,6 +576,14 @@ class ModelFile extends Decorated { return this.getDeclarations(ParticipantDeclaration); } + /** + * Get the ClassDeclarations defined in this ModelFile + * @return {ClassDeclaration[]} the ClassDeclarations defined in the model file + */ + getClassDeclarations() { + return this.getDeclarations(ClassDeclaration); + } + /** * Get the ConceptDeclarations defined in this ModelFile * @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file diff --git a/packages/concerto-core/test/introspect/modelfile.js b/packages/concerto-core/test/introspect/modelfile.js index 9eb7d3066..baafc77d0 100644 --- a/packages/concerto-core/test/introspect/modelfile.js +++ b/packages/concerto-core/test/introspect/modelfile.js @@ -37,6 +37,7 @@ const should = chai.should(); chai.use(require('chai-things')); const sinon = require('sinon'); const ScalarDeclaration = require('../../lib/introspect/scalardeclaration'); +const ClassDeclaration = require('../../lib/introspect/classdeclaration'); describe('ModelFile', () => { @@ -720,6 +721,15 @@ describe('ModelFile', () => { }); }); + describe('#getClassDeclarations', () => { + it('should return the expected number of Class declarations', () => { + let modelFile = ParserUtil.newModelFile(modelManager, carLeaseModel); + let decls = modelFile.getClassDeclarations(); + decls.should.all.be.an.instanceOf(ClassDeclaration); + decls.length.should.equal(16); + }); + }); + describe('#getFullyQualifiedTypeName', () => { it('should return null if not prmative, imported or local type', () => { const ast = { diff --git a/packages/concerto-core/types/lib/introspect/modelfile.d.ts b/packages/concerto-core/types/lib/introspect/modelfile.d.ts index 10db59d39..f7ab63c2f 100644 --- a/packages/concerto-core/types/lib/introspect/modelfile.d.ts +++ b/packages/concerto-core/types/lib/introspect/modelfile.d.ts @@ -202,6 +202,11 @@ declare class ModelFile extends Decorated { * @return {ParticipantDeclaration[]} the ParticipantDeclaration defined in the model file */ getParticipantDeclarations(): ParticipantDeclaration[]; + /** + * Get the ClassDeclarations defined in this ModelFile + * @return {ClassDeclaration[]} the ClassDeclarations defined in the model file + */ + getClassDeclarations(): ClassDeclaration[]; /** * Get the ConceptDeclarations defined in this ModelFile * @return {ConceptDeclaration[]} the ParticipantDeclaration defined in the model file