import type { RxQuery, RxQueryOP, MangoQuery } from './rx-query.d.ts'; import type { RxCollection, RxCollectionCreator } from './rx-collection.d.ts'; import type { RxStorageInstanceCreationParams } from './rx-storage.d.ts'; import type { DeepReadonly, FilledMangoQuery, RxDatabase, RxDatabaseCreator, RxDocument, RxStorage, RxReplicationWriteToMasterRow, WithDeleted, RxState, BulkWriteRow, RxStorageInstance } from './index.d.ts'; import type { RxSchema } from '../rx-schema.d.ts'; export type RxPluginPrePrepareRxQueryArgs = { op: RxQueryOP; queryObj: MangoQuery | string | number | Array; collection: RxCollection; }; export type RxPluginPreCreateRxQueryArgs = { op: RxQueryOP; queryObj: MangoQuery; collection: RxCollection; }; export type RxPluginPreAddRxPluginArgs = { // the plugin that is getting added plugin: RxPlugin | any; // previous added plugins plugins: Set; }; export type RxPluginPrePrepareQueryArgs = { rxQuery: RxQuery; mangoQuery: FilledMangoQuery; }; /** * Depending on which plugins are used together, * it is important that the plugin is able to define if * the hooks must be added as first or as last array item. * For example the encryption plugin must run encryption * before the key-compression changes the fieldnames. */ export type RxPluginHooks = { /** * Hook function that is added as first. */ before?: (i: Input) => void; /** * Hook function that is added as last. */ after?: (i: Input) => void; }; export interface RxPlugin { /** * A string to uniquely identifies the plugin. * Can be used to throw when different versions of the same plugin are used. * And also other checks. * Use kebab-case. */ readonly name: string; /** * set this to true so RxDB * knows that this object in a rxdb plugin */ readonly rxdb: true; /** * Init function where dependent plugins could be added. * (optional) */ init?(): any; prototypes?: { RxSchema?: (proto: RxSchema) => void; RxDocument?: (proto: RxDocument) => void; RxQuery?: (proto: RxQuery) => void; RxCollection?: (proto: RxCollection) => void; RxDatabase?: (proto: RxDatabase) => void; }; overwritable?: { isDevMode?: () => boolean; deepFreezeWhenDevMode?: (obj: T) => DeepReadonly; validatePassword?: Function; checkAdapter?: Function; tunnelErrorMessage?: Function; }; hooks?: { preAddRxPlugin?: RxPluginHooks; preCreateRxDatabase?: RxPluginHooks; createRxDatabase?: RxPluginHooks<{ database: RxDatabase; creator: RxDatabaseCreator; }>; preCloseRxDatabase?: RxPluginHooks; postRemoveRxDatabase?: RxPluginHooks<{ databaseName: string; storage: RxStorage; }>; createRxCollection?: RxPluginHooks<{ collection: RxCollection; creator: RxCollectionCreator; }>; createRxState?: RxPluginHooks<{ collection: RxCollection; state: RxState; }>; preCreateRxCollection?: RxPluginHooks & { name: string; database: RxDatabase; }>; postCloseRxCollection?: RxPluginHooks; postRemoveRxCollection?: RxPluginHooks<{ storage: RxStorage; databaseName: string; collectionName: string; }>; preCreateRxSchema?: RxPluginHooks; createRxSchema?: RxPluginHooks; prePrepareRxQuery?: RxPluginHooks; preCreateRxQuery?: RxPluginHooks; prePrepareQuery?: RxPluginHooks; createRxQuery?: RxPluginHooks; createRxDocument?: RxPluginHooks; postCreateRxDocument?: RxPluginHooks; preCreateRxStorageInstance?: RxPluginHooks>; /** * Runs before a write to the storage instance of a RxCollection or RxDatabase. */ preStorageWrite?: RxPluginHooks<{ storageInstance: RxStorageInstance; rows: BulkWriteRow[]; }>; preMigrateDocument?: RxPluginHooks; postMigrateDocument?: RxPluginHooks; postCleanup?: RxPluginHooks<{ databaseName: string; collectionName: string; }>; preReplicationMasterWrite?: RxPluginHooks<{ rows: RxReplicationWriteToMasterRow[]; collection: RxCollection; }>; preReplicationMasterWriteDocumentsHandle?: RxPluginHooks<{ result: WithDeleted[]; collection: RxCollection; }>; }; }