import type { RxJsonSchema, RxDocument, MigrationStrategies, RxConflictHandler } from './index.d.ts'; import type { RxCollectionBase } from '../rx-collection.d.ts'; import type { QueryCache } from '../query-cache.d.ts'; import type { RxLocalDocumentMutation } from './rx-database.d.ts'; export interface KeyFunctionMap { [key: string]: Function; } export interface NumberFunctionMap { [key: number]: Function; } /** * Params to create a new collection. * Notice the name of the collection is set one level higher * when calling addCollections() */ export type RxCollectionCreator = { schema: RxJsonSchema; instanceCreationOptions?: any; migrationStrategies?: MigrationStrategies; autoMigrate?: boolean; statics?: KeyFunctionMap; methods?: KeyFunctionMap; attachments?: KeyFunctionMap; options?: any; /** * Set this to true if you want to store local documents * in the RxCollection instance. */ localDocuments?: boolean; cacheReplacementPolicy?: RxCacheReplacementPolicy; /** * Depending on which plugins or storage is used, * the RxCollection might need a way to resolve conflicts * which is done by this conflict handler. * If no conflict handler is provided, a master-always-wins handler * will be used as default */ conflictHandler?: RxConflictHandler; }; export type RxCacheReplacementPolicy = (collection: RxCollection, queryCache: QueryCache) => void; export type RxCollectionHookCallback< RxDocumentType, OrmMethods, Reactivity > = ( data: RxDocumentType, instance: RxDocument ) => void | Promise | any; export type RxCollectionHookNoInstance = (data: RxDocumentType) => void | Promise | any; export type RxCollectionHookCallbackNonAsync = ( data: RxDocumentType, instance: RxDocument ) => void | any; export type RxCollectionHookNoInstanceCallback< RxDocumentType, OrmMethods, Reactivity > = ( data: RxDocumentType, instance: RxCollection ) => Promise | void | any; export type RxCollection< RxDocumentType = any, OrmMethods = {}, StaticMethods = {}, InstanceCreationOptions = {}, Reactivity = unknown > = StaticMethods & RxCollectionBase & RxCollectionGenerated; export interface RxCollectionGenerated extends RxLocalDocumentMutation> { // HOOKS preInsert(fun: RxCollectionHookNoInstanceCallback, parallel: boolean): void; preSave(fun: RxCollectionHookCallback, parallel: boolean): void; preRemove(fun: RxCollectionHookCallback, parallel: boolean): void; postInsert(fun: RxCollectionHookCallback, parallel: boolean): void; postSave(fun: RxCollectionHookCallback, parallel: boolean): void; postRemove(fun: RxCollectionHookCallback, parallel: boolean): void; postCreate(fun: RxCollectionHookCallbackNonAsync): void; // only inMemory-collections awaitPersistence(): Promise; } /** * Previously all properties were typed as any because they could be encrypted. * This is no longer needed so the type now preserves the original property types. */ export type RxDumpCollectionAsAny = T; interface RxDumpCollectionBase { name: string; passwordHash?: string; schemaHash: string; } export interface RxDumpCollection extends RxDumpCollectionBase { docs: RxDocumentType[]; } export interface RxDumpCollectionAny extends RxDumpCollectionBase { docs: RxDumpCollectionAsAny[]; }