Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(doc) Fix for instance off and missing JSDoc for utcOffset option #272

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Concerto {
+ void fromURI(string) throws Error
+ string getType()
+ string getNamespace()
+ boolean instanceOf(String)
}
+ object setCurrentTime()
class Factory {
Expand Down Expand Up @@ -191,8 +190,8 @@ class ValidatedResource extends Resource {
+ void validate() throws Error
}
class ModelLoader {
+ object loadModelManager(string[],object,boolean)
+ object loadModelManagerFromModelFiles(object[],undefined,object,boolean)
+ object loadModelManager(string[],object,boolean,number)
+ object loadModelManagerFromModelFiles(object[],undefined,object,boolean,number)
}
class ModelManager {
+ void constructor(object)
Expand All @@ -217,6 +216,7 @@ class ModelManager {
+ Serializer getSerializer()
+ DecoratorFactory[] getDecoratorFactories()
+ void addDecoratorFactory(DecoratorFactory)
+ boolean derivesFrom(String,String)
+ boolean hasInstance(object)
}
class SecurityException extends BaseException {
Expand Down
7 changes: 4 additions & 3 deletions packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 1.0.0-alpha.8 {63957095b410cd581a8b1896659ad170} 2021-04-22
- Add datetimeutil
Version 1.0.0-alpha.8 {08b0c809336354e7d1b17a2e44fca8b0} 2021-04-22
- Add datetimeutil & Consolidate UTC offset support
- Delete Concerto.instanceOf replace by ModelManager.derivesFrom

Version 1.0.0-alpha.7 {e791f955bbe9bdac6bcd8944d6111e1a} 2021-04-17
Version 1.0.0-alpha.7 {aec0f0d4e25be4dab03d6b94be60767b} 2021-04-17
- Remove unused systemtime options in modelfile API
- Fixes to the validation option targeting the ergo ES6 runtime

Expand Down
25 changes: 0 additions & 25 deletions packages/concerto-core/lib/concerto.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,31 +205,6 @@ class Concerto {
getNamespace(obj) {
return this.getTypeDeclaration(obj).getNamespace();
}

/**
* Check to see if this instance is an instance of the specified fully qualified
* type name.
* @param {*} obj the input object
* @param {String} fqt The fully qualified type name.
* @returns {boolean} True if this instance is an instance of the specified fully
* qualified type name, false otherwise.
*/
instanceOf(obj, fqt) {
// Check to see if this is an exact instance of the specified type.
const classDeclaration = this.getTypeDeclaration(obj);
if (classDeclaration.getFullyQualifiedName() === fqt) {
return true;
}
// Now walk the class hierachy looking to see if it's an instance of the specified type.
let superTypeDeclaration = classDeclaration.getSuperTypeDeclaration();
while (superTypeDeclaration) {
if (superTypeDeclaration.getFullyQualifiedName() === fqt) {
return true;
}
superTypeDeclaration = superTypeDeclaration.getSuperTypeDeclaration();
}
return false;
}
}

module.exports = Concerto;
2 changes: 2 additions & 0 deletions packages/concerto-core/lib/modelloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ModelLoader {
* @param {string[]} ctoFiles - the CTO files (can be local file paths or URLs)
* @param {object} options - optional parameters
* @param {boolean} [options.offline] - do not resolve external models
* @param {number} [options.utcOffset] - UTC Offset for this execution
* @return {object} the model manager
*/
static async loadModelManager(ctoFiles, options = { offline: false }) {
Expand Down Expand Up @@ -86,6 +87,7 @@ class ModelLoader {
* @param {string[]} [fileNames] - An optional array of file names to associate with the model files
* @param {object} options - optional parameters
* @param {boolean} [options.offline] - do not resolve external models
* @param {number} [options.utcOffset] - UTC Offset for this execution
* @return {object} the model manager
*/
static async loadModelManagerFromModelFiles(modelFiles, fileNames, options = { offline: false }) {
Expand Down
19 changes: 19 additions & 0 deletions packages/concerto-core/lib/modelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,25 @@ abstract concept Event {}
this.decoratorFactories.push(factory);
}

/**
* Checks if this fully qualified type name is derived from another.
* @param {String} fqt1 The fully qualified type name to check.
* @param {String} fqt2 The fully qualified type name it is may be derived from.
* @returns {boolean} True if this instance is an instance of the specified fully
* qualified type name, false otherwise.
*/
derivesFrom(fqt1, fqt2) {
// Check to see if this is an exact instance of the specified type.
let typeDeclaration = this.getType(fqt1);
while (typeDeclaration) {
if (typeDeclaration.getFullyQualifiedName() === fqt2) {
return true;
}
typeDeclaration = typeDeclaration.getSuperTypeDeclaration();
}
return false;
}

/**
* Alternative instanceof that is reliable across different module instances
* @see https://github.com/hyperledger/composer-concerto/issues/47
Expand Down
60 changes: 0 additions & 60 deletions packages/concerto-core/test/concerto.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
const fs = require('fs');
const chai = require('chai');

const expect = chai.expect;
// eslint-disable-next-line no-unused-vars
const should = chai.should();
chai.use(require('chai-things'));
Expand Down Expand Up @@ -229,65 +228,6 @@ describe('concerto', () => {
});
});

describe('#instanceOf', () => {

it('should get instanceOf for sub type', () => {
const obj = {
$class : 'org.accordproject.test.Customer',
ssn: '123456789',
customerId: '001',
name: 'Dan Selman'
};

const result = concerto.instanceOf(obj, 'org.accordproject.test.Person');
result.should.be.true;
});

it('should get instanceOf for sub-sub type', () => {
const obj = {
$class : 'org.accordproject.test.Manager',
ssn: '123456789',
customerId: '001',
name: 'Dan Selman'
};

const result = concerto.instanceOf(obj, 'org.accordproject.test.Person');
result.should.be.true;
});

it('should get instanceOf for type', () => {
const obj = {
$class : 'org.accordproject.test.Customer',
ssn: '123456789',
customerId: '001',
name: 'Dan Selman'
};

const result = concerto.instanceOf(obj, 'org.accordproject.test.Customer');
result.should.be.true;
});

it('should not get instanceOf for derived type', () => {
const obj = {
$class : 'org.accordproject.test.Person',
ssn: '123456789'
};

const result = concerto.instanceOf(obj, 'org.accordproject.test.Customer');
expect(result).to.be.false;
});

it('all types should be an instance of concerto.Concept', () => {
const obj = {
$class : 'org.accordproject.test.Person',
ssn: '123456789'
};

const result = concerto.instanceOf(obj, 'concerto.Concept');
expect(result).to.be.true;
});
});

describe('#validate', () => {

it('should validate data that conforms to model', () => {
Expand Down
40 changes: 40 additions & 0 deletions packages/concerto-core/test/modelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('ModelManager', () => {
let composerModel = fs.readFileSync('./test/data/model/composer.cto', 'utf8');
let invalidModel = fs.readFileSync('./test/data/model/invalid.cto', 'utf8');
let invalidModel2 = fs.readFileSync('./test/data/model/invalid2.cto', 'utf8');
let concertoModel = fs.readFileSync('./test/data/model/concerto.cto', 'utf8');
let modelManager;
let sandbox;

Expand Down Expand Up @@ -958,4 +959,43 @@ concept Bar {
});
});

describe('#derivesFrom', () => {

it('should get derivesFrom for sub type', () => {
modelManager.addModelFile(concertoModel);
const result = modelManager.derivesFrom('org.accordproject.test.Customer', 'org.accordproject.test.Person');
result.should.be.true;
});

it('should get derivesFrom for sub-sub type', () => {
modelManager.addModelFile(concertoModel);
const result = modelManager.derivesFrom('org.accordproject.test.Manager', 'org.accordproject.test.Person');
result.should.be.true;
});

it('should get derivesFrom for type', () => {
modelManager.addModelFile(concertoModel);
const result = modelManager.derivesFrom('org.accordproject.test.Customer', 'org.accordproject.test.Customer');
result.should.be.true;
});

it('should not get derivesFrom for derived type', () => {
modelManager.addModelFile(concertoModel);
const result = modelManager.derivesFrom('org.accordproject.test.Person', 'org.accordproject.test.Customer');
result.should.be.false;
});

it('should be an instance of concerto.Participant', () => {
modelManager.addModelFile(concertoModel);
const result = modelManager.derivesFrom('org.accordproject.test.Person', 'concerto.Participant');
result.should.be.true;
});

it('all types should be an instance of concerto.Concept', () => {
modelManager.addModelFile(concertoModel);
const result = modelManager.derivesFrom('org.accordproject.test.Person', 'concerto.Concept');
result.should.be.true;
});
});

});
51 changes: 51 additions & 0 deletions packages/concerto-core/umd/concerto.js

Large diffs are not rendered by default.