test-rxdb
Version:
A local realtime NoSQL Database for JavaScript applications -
128 lines (125 loc) • 3.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.HOOKS = void 0;
exports._clearHook = _clearHook;
exports.runAsyncPluginHooks = runAsyncPluginHooks;
exports.runPluginHooks = runPluginHooks;
/**
* hook-functions that can be extended by the plugin
*/
var HOOKS = exports.HOOKS = {
/**
* Runs before a plugin is added.
* Use this to block the usage of non-compatible plugins.
*/
preAddRxPlugin: [],
/**
* functions that run before the database is created
*/
preCreateRxDatabase: [],
/**
* runs after the database is created and prepared
* but before the instance is returned to the user
* @async
*/
createRxDatabase: [],
preCreateRxCollection: [],
createRxCollection: [],
createRxState: [],
/**
* runs at the end of the destroy-process of a collection
* @async
*/
postDestroyRxCollection: [],
/**
* Runs after a collection is removed.
* @async
*/
postRemoveRxCollection: [],
/**
* functions that get the json-schema as input
* to do additionally checks/manipulation
*/
preCreateRxSchema: [],
/**
* functions that run after the RxSchema is created
* gets RxSchema as attribute
*/
createRxSchema: [],
preCreateRxQuery: [],
/**
* Runs before a query is send to the
* prepareQuery function of the storage engine.
*/
prePrepareQuery: [],
createRxDocument: [],
/**
* runs after a RxDocument is created,
* cannot be async
*/
postCreateRxDocument: [],
/**
* Runs before a RxStorageInstance is created
* gets the params of createStorageInstance()
* as attribute so you can manipulate them.
* Notice that you have to clone stuff before mutating the inputs.
*/
preCreateRxStorageInstance: [],
preStorageWrite: [],
/**
* runs on the document-data before the document is migrated
* {
* doc: Object, // original doc-data
* migrated: // migrated doc-data after run through migration-strategies
* }
*/
preMigrateDocument: [],
/**
* runs after the migration of a document has been done
*/
postMigrateDocument: [],
/**
* runs at the beginning of the destroy-process of a database
*/
preDestroyRxDatabase: [],
/**
* runs after a database has been removed
* @async
*/
postRemoveRxDatabase: [],
postCleanup: [],
/**
* runs before the replication writes the rows to master
* but before the rows have been modified
* @async
*/
preReplicationMasterWrite: [],
/**
* runs after the replication has been sent to the server
* but before the new documents have been handled
* @async
*/
preReplicationMasterWriteDocumentsHandle: []
};
function runPluginHooks(hookKey, obj) {
if (HOOKS[hookKey].length > 0) {
HOOKS[hookKey].forEach(fun => fun(obj));
}
}
/**
* TODO
* we should not run the hooks in parallel
* this makes stuff unpredictable.
*/
function runAsyncPluginHooks(hookKey, obj) {
return Promise.all(HOOKS[hookKey].map(fun => fun(obj)));
}
/**
* used in tests to remove hooks
*/
function _clearHook(type, fun) {
HOOKS[type] = HOOKS[type].filter(h => h !== fun);
}
//# sourceMappingURL=hooks.js.map
;