diff --git a/lib/Entity.js b/lib/Entity.js index bfaa345..069e708 100644 --- a/lib/Entity.js +++ b/lib/Entity.js @@ -2,6 +2,7 @@ const uuid = require('uuid'); const PersistenceUtils = require("./PersistenceUtils"); +const typly = require("typly"); module.exports = class Entity { constructor(config) @@ -59,7 +60,7 @@ module.exports = class Entity { { obj[newKey] = this[key]; } - else if (PersistenceUtils.isInstanceOf(property, Entity)) + else if (typly.isInstanceOf(property, Entity)) { obj[newKey] = property; } diff --git a/lib/MetaModel.js b/lib/MetaModel.js index 5f1bcce..6a0cec2 100644 --- a/lib/MetaModel.js +++ b/lib/MetaModel.js @@ -69,7 +69,7 @@ module.exports = class MetaModel { } if(this.entityClass) { - if (PersistenceUtils.isInstanceOf(entity, this.entityClass) === false) + if (typly.isInstanceOf(entity, this.entityClass) === false) { throw new RangeError("row cannot be prepared, unexpected entity class: " + entity.constructor.name); } diff --git a/lib/PersistenceUtils.js b/lib/PersistenceUtils.js index d07b679..0b6e414 100644 --- a/lib/PersistenceUtils.js +++ b/lib/PersistenceUtils.js @@ -16,7 +16,7 @@ module.exports = class PersistenceUtils { typly.assertNotNull(value); if (typly.isObject(value)) { - if (PersistenceUtils.isInstanceOf(value, TimeUuid) ) + if (typly.isInstanceOf(value, TimeUuid) ) { return value; } @@ -124,33 +124,4 @@ module.exports = class PersistenceUtils { }); return obj; } - - static isInstanceOf(_object, _class) - { - if (typeof _object !== "object" || _object == undefined || _object === null) - { - throw TypeError("Not valid input for isInstanceOf"); - } - //let hasInstance = _object[Symbol.hasInstance]; - - let isImplementation = true; - let targetPrototype = _class.prototype; - if (_class.constructor) - { - targetPrototype = new _class(); - } - let propNames = Object.getOwnPropertyNames(targetPrototype); - if(propNames.length !== Object.getOwnPropertyNames(_object).length) - { - return false; - } - propNames.forEach(function (propName, idx, array) - { - if (!_object.hasOwnProperty(propName)) - { - return false; - } - }); - return true; - } }; \ No newline at end of file