entity-api
Advanced tools
Comparing version
@@ -79,3 +79,3 @@ "use strict"; | ||
var type = entityType.getEntityTypeId(); | ||
_system2.default.log("registerEntityType", "Registering entity type: " + type); | ||
_system2.default.log("EntityAPI", "Registering entity type: " + type); | ||
this._registry.set('entityTypes', type, entityType); | ||
@@ -154,2 +154,70 @@ } | ||
/** | ||
* Perform installation manoeuvre for storage backends. | ||
* | ||
* @param options | ||
* Options to be passed for storages. | ||
* @preturn promise | ||
* Promise to be resolved when all entity types are installed | ||
*/ | ||
}, { | ||
key: "install", | ||
value: function install() { | ||
var _this2 = this; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_system2.default.log('EntityAPI', "Executing install manoeuvre"); | ||
return this.getEntityTypeIds().reduce(function (sequence, entityType) { | ||
return sequence.then(function () { | ||
return _this2.getStorage(entityType).install(); | ||
}); | ||
}, Promise.resolve()); | ||
} | ||
/** | ||
* Perform uninstallation manoeuvre for storage backends. | ||
* | ||
* @param options | ||
* Options to be passed for storages. | ||
*/ | ||
}, { | ||
key: "uninstall", | ||
value: function uninstall() { | ||
var _this3 = this; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_system2.default.log('EntityAPI', "Executing uninstall manoeuvre"); | ||
return this.getEntityTypeIds().reduce(function (sequence, entityType) { | ||
return sequence.then(function () { | ||
return _this3.getStorage(entityType).uninstall(); | ||
}); | ||
}, Promise.resolve()); | ||
} | ||
/** | ||
* Perform uninstallation manoeuvre for storage backends. | ||
* | ||
* @param options | ||
* Options to be passed for storages. | ||
*/ | ||
}, { | ||
key: "update", | ||
value: function update() { | ||
var _this4 = this; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_system2.default.log('EntityAPI', "Executing update manoeuvre"); | ||
return this.getEntityTypeIds().reduce(function (sequence, entityType) { | ||
return sequence.then(function () { | ||
return _this4.getStorage(entityType).update(); | ||
}); | ||
}, Promise.resolve()); | ||
} | ||
/** | ||
* Returns singleton object | ||
@@ -156,0 +224,0 @@ * |
@@ -30,3 +30,3 @@ "use strict"; | ||
/** | ||
* Entity storage handler | ||
* Entity Storage handler. | ||
*/ | ||
@@ -59,2 +59,4 @@ var EntityStorageHandler = function (_EntityHandler) { | ||
if (!backend) throw new Error("Storage backend is not defined"); | ||
// Apply reference to backend | ||
@@ -172,2 +174,15 @@ backend.setStorageHandler(_this); | ||
/** | ||
* Returns entity schemas. | ||
* | ||
* @return schemas | ||
* Array of schemas. Required format depends on storage backend. | ||
*/ | ||
}, { | ||
key: "getSchemas", | ||
value: function getSchemas() { | ||
return []; | ||
} | ||
/** | ||
* Traditional callback based api. | ||
@@ -452,9 +467,10 @@ */ | ||
value: function extractEntityId(indexes, data) { | ||
var build = {}; | ||
if (!indexes) return false; | ||
var entityId = {}; | ||
for (var i = 0; i < indexes.length; i++) { | ||
entityId[indexes[i].fieldName] = data[indexes[i].fieldName]; | ||
build[indexes[i].fieldName] = data[indexes[i].fieldName]; | ||
} | ||
return entityId; | ||
return build; | ||
} | ||
@@ -476,2 +492,67 @@ | ||
} | ||
/** | ||
* Perform installation manoeuvre for storage backends. | ||
* | ||
* @param options | ||
* Options to be passed for storages. | ||
* @preturn promise | ||
* Promise to be resolved when all entity types are installed | ||
*/ | ||
}, { | ||
key: "install", | ||
value: function install() { | ||
var _this8 = this; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return new Promise(function (resolve, reject) { | ||
_this8.getStorageBackend().installSchemas(_this8.getSchemas(options), options, function (err) { | ||
if (err) reject(err);else resolve(); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Perform uninstallation manoeuvre for storage backends. | ||
* | ||
* @param options | ||
* Options to be passed for storages. | ||
*/ | ||
}, { | ||
key: "uninstall", | ||
value: function uninstall() { | ||
var _this9 = this; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return new Promise(function (resolve, reject) { | ||
_this9.getStorageBackend().uninstallSchemas(_this9.getSchemas(options), options, function (err) { | ||
if (err) reject(err);else resolve(); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Perform uninstallation manoeuvre for storage backends. | ||
* | ||
* @param options | ||
* Options to be passed for storages. | ||
*/ | ||
}, { | ||
key: "update", | ||
value: function update() { | ||
var _this10 = this; | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return new Promise(function (resolve, reject) { | ||
_this10.getStorageBackend().updateSchemas(_this10.getSchemas(options), options, function (err) { | ||
if (err) reject(err);else resolve(); | ||
}); | ||
}); | ||
} | ||
}]); | ||
@@ -478,0 +559,0 @@ |
@@ -122,3 +122,4 @@ 'use strict'; | ||
* Install one or more schemas | ||
* @param callback | ||
* @param options | ||
* @return promise | ||
*/ | ||
@@ -128,5 +129,35 @@ | ||
key: 'installSchemas', | ||
value: function installSchemas(schemas, callback) { | ||
value: function installSchemas(schemas, options, callback) { | ||
callback(null); | ||
} | ||
/** | ||
* Update schema | ||
* | ||
* @param scema | ||
* Install one or more schemas | ||
* @param options | ||
* @return promise | ||
*/ | ||
}, { | ||
key: 'updateSchemas', | ||
value: function updateSchemas(schemas, options, callback) { | ||
callback(null); | ||
} | ||
/** | ||
* Uninstall schema | ||
* | ||
* @param scema | ||
* Install one or more schemas | ||
* @param options | ||
* @return promise | ||
*/ | ||
}, { | ||
key: 'uninstallSchemas', | ||
value: function uninstallSchemas(schemas, options, callback) { | ||
callback(null); | ||
} | ||
}]); | ||
@@ -133,0 +164,0 @@ |
{ | ||
"name": "entity-api", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Entity API for Node.JS.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -15,3 +15,2 @@ import assert from "assert" | ||
let probe = { | ||
// Random probe values | ||
values: { | ||
@@ -22,3 +21,2 @@ entityTypeProbe: 'entityTypeprob:' + TestUtils.getUUID(), | ||
}, | ||
// Probe classes | ||
classes: {} | ||
@@ -25,0 +23,0 @@ } |
@@ -27,2 +27,8 @@ import assert from "assert" | ||
class ProbeEntityStorageBackend extends EntityStorageHandler { | ||
getProb() { | ||
return probe.values.entityHandlerProbe; | ||
} | ||
} | ||
class ProbeEntityStorageHandler extends EntityStorageHandler { | ||
@@ -137,3 +143,2 @@ getProb() { | ||
}); | ||
}); | ||
}); |
184894
5.72%47
2.17%4880
6.67%