import type { RxJsonSchema, RxDocument, MigrationStrategies, RxConflictHandler } from 'nxdb-old/src/types'; import type { RxCollectionBase } from 'nxdb-old/src/rx-collection'; import type { QueryCache } from 'nxdb-old/src/query-cache'; import { RxLocalDocumentMutation } from 'nxdb-old/src/types/rx-database'; 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 interface MigrationState { done: boolean; // true if finished total: number; // will be the doc-count handled: number; // amount of handled docs success: number; // handled docs which succeeded deleted: number; // handled docs which got deleted percent: number; // percentage } export type RxCacheReplacementPolicy = (collection: RxCollection, queryCache: QueryCache) => void; export type RxCollectionHookCallback< RxDocumentType, OrmMethods > = ( 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 > = ( data: RxDocumentType, instance: RxCollection ) => Promise | void | any; export type RxCollection< RxDocumentType = any, OrmMethods = {}, StaticMethods = {}, InstanceCreationOptions = {} > = 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; } /** * Properties are possibly encrypted so type them as any. TODO this is no longer needed. */ export type RxDumpCollectionAsAny = { [P in keyof T]: any }; interface RxDumpCollectionBase { name: string; passwordHash?: string; schemaHash: string; } export interface RxDumpCollection extends RxDumpCollectionBase { docs: RxDocumentType[]; } /** * All base properties are typed as any because they can be encrypted. */ export interface RxDumpCollectionAny extends RxDumpCollectionBase { docs: RxDumpCollectionAsAny[]; }