UNPKG

rxdb

Version:

A local-first realtime NoSQL Database for JavaScript applications - https://rxdb.info/

131 lines (128 loc) 3.3 kB
"use strict"; 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 close-process of a collection * @async */ postCloseRxCollection: [], /** * 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: [], prePrepareRxQuery: [], 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 close-process of a database */ preCloseRxDatabase: [], /** * 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)); } } /** * We do intentionally not run the hooks in parallel * because that makes stuff unpredictable and we use runAsyncPluginHooks() * only in places that are not that relevant for performance. */ async function runAsyncPluginHooks(hookKey, obj) { for (var fn of HOOKS[hookKey]) { await fn(obj); } } /** * used in tests to remove hooks */ function _clearHook(type, fun) { HOOKS[type] = HOOKS[type].filter(h => h !== fun); } //# sourceMappingURL=hooks.js.map