diff --git a/packages/concerto-core/api.txt b/packages/concerto-core/api.txt index 23059ef095..666fa3668b 100644 --- a/packages/concerto-core/api.txt +++ b/packages/concerto-core/api.txt @@ -14,6 +14,7 @@ class Factory { + Relationship newRelationship(String,String,String) throws TypeNotFoundException + Resource newTransaction(String,String,String,Object,String,boolean,boolean) + Resource newEvent(String,String,String,Object,String,boolean,boolean) + + boolean hasInstance(object) } class AssetDeclaration extends ClassDeclaration { + void constructor(ModelFile,Object) throws IllegalModelException @@ -216,4 +217,5 @@ class Serializer { + void setDefaultOptions(Object) + Object toJSON(Resource,Object,boolean,boolean,boolean,boolean,boolean) throws Error + Resource fromJSON(Object,Object,boolean,boolean) + + boolean hasInstance(object) } diff --git a/packages/concerto-core/changelog.txt b/packages/concerto-core/changelog.txt index f389215cf2..93bb594879 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 0.82.5 {d4d49fabba1c6ce465c446e2dccad488} 2019-11-10 +- Add instance of alternatives to Factory and Serializer + Version 0.82.1 {dee013e99a3c2d6acc4eddfb00aad2a2} 2019-10-22 - Make several constructors public - Add model loader utility class diff --git a/packages/concerto-core/lib/factory.js b/packages/concerto-core/lib/factory.js index a153f645a4..680f14a73b 100644 --- a/packages/concerto-core/lib/factory.js +++ b/packages/concerto-core/lib/factory.js @@ -53,6 +53,7 @@ class Factory { */ constructor(modelManager) { this.modelManager = modelManager; + this._isFactory = true; } /** @@ -317,6 +318,17 @@ class Factory { return generateParams; } + + /** + * Alternative instanceof that is reliable across different module instances + * @see https://github.com/hyperledger/composer-concerto/issues/47 + * + * @param {object} object - The object to test against + * @returns {boolean} - True, if the object is an instance of a Factory + */ + static [Symbol.hasInstance](object){ + return typeof object !== 'undefined' && object !== null && Boolean(object._isFactory); + } } module.exports = Factory; diff --git a/packages/concerto-core/lib/serializer.js b/packages/concerto-core/lib/serializer.js index fb9eef78f7..27950ad975 100644 --- a/packages/concerto-core/lib/serializer.js +++ b/packages/concerto-core/lib/serializer.js @@ -55,6 +55,7 @@ class Serializer { this.factory = factory; this.modelManager = modelManager; this.defaultOptions = Object.assign({}, baseDefaultOptions); + this._isSerializer = true; } /** @@ -188,6 +189,17 @@ class Serializer { return resource; } + + /** + * Alternative instanceof that is reliable across different module instances + * @see https://github.com/hyperledger/composer-concerto/issues/47 + * + * @param {object} object - The object to test against + * @returns {boolean} - True, if the object is an instance of a Serializer + */ + static [Symbol.hasInstance](object){ + return typeof object !== 'undefined' && object !== null && Boolean(object._isSerializer); + } } module.exports = Serializer;