Skip to content

Commit

Permalink
feat(ModelFile): model file class declarations (#695)
Browse files Browse the repository at this point in the history
* feat(maps): adds getClassDeclarations

Signed-off-by: jonathan.casey <[email protected]>

* feat(maps): adds type definition

Signed-off-by: jonathan.casey <[email protected]>

* feat(maps): adds test

Signed-off-by: jonathan.casey <[email protected]>

* feat(maps): updates api.txt

Signed-off-by: jonathan.casey <[email protected]>

* feat(maps): updates changelog hash

Signed-off-by: jonathan.casey <[email protected]>

---------

Signed-off-by: jonathan.casey <[email protected]>
  • Loading branch information
jonathan-casey authored Aug 28, 2023
1 parent 8894748 commit d648566
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class ModelFile extends Decorated {
+ TransactionDeclaration[] getTransactionDeclarations()
+ EventDeclaration[] getEventDeclarations()
+ ParticipantDeclaration[] getParticipantDeclarations()
+ ClassDeclaration[] getClassDeclarations()
+ ConceptDeclaration[] getConceptDeclarations()
+ EnumDeclaration[] getEnumDeclarations()
+ MapDeclaration[] getMapDeclarations()
Expand Down
3 changes: 3 additions & 0 deletions packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/concerto-core/test/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {

Expand Down Expand Up @@ -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 = {
Expand Down
5 changes: 5 additions & 0 deletions packages/concerto-core/types/lib/introspect/modelfile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d648566

Please sign in to comment.