import { Observable } from 'rxjs'; import { PouchDB } from './pouch'; import { RxSchema, RxJsonSchema } from './rx-schema'; import { RxDatabase } from './rx-database'; import { RxQuery } from './rx-query'; import { PouchSettings } from './pouch'; import { RxChangeEvent, RxChangeEventInsert, RxChangeEventUpdate, RxChangeEventRemove } from './rx-change-event'; import { RxDocument, RxLocalDocument } from './rx-document'; import { SyncOptions, RxReplicationState } from './plugins/replication'; export interface RxCollectionCreator { name: string; schema: RxJsonSchema; pouchSettings?: PouchSettings; migrationStrategies?: { [key: number]: Function }; autoMigrate?: boolean; statics?: { [key: string]: Function }; methods?: { [key: string]: Function }; attachments?: { [key: string]: Function }; options?: any; } export type RxCollectionHookCallback = (data: RxDocumentType, instance: RxDocument) => void | Promise; export type RxCollectionHookNoInstance = (data: RxDocumentType) => void | Promise; export type RxCollectionHookCallbackNonAsync = (data: RxDocumentType, instance: RxDocument) => void; export type RxCollectionHookNoInstanceCallback = (data: RxDocumentType) => Promise; export type RxCollection = RxCollectionBase & StaticMethods; export declare class RxCollectionBase { readonly database: RxDatabase; readonly name: string; readonly schema: RxSchema; options?: any; readonly pouch: PouchDB; readonly $: Observable | RxChangeEventUpdate | RxChangeEventRemove>; readonly insert$: Observable>; readonly update$: Observable>; readonly remove$: Observable>; $emit(changeEvent: RxChangeEvent): void; insert(json: RxDocumentType): Promise>; newDocument(json: Partial): RxDocument; upsert(json: Partial): Promise>; atomicUpsert(json: Partial): Promise>; find(queryObj?: any): RxQuery[]>; findOne(queryObj?: any): RxQuery | null>; dump(decrytped: boolean): Promise; importDump(exportedJSON: any): Promise; // 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; // migration migrationNeeded(): Promise; migrate(batchSize: number): Observable<{ done: boolean, // true if finished total: number, // will be the doc-count handled: number, // amount of handled docs success: number, // handled docs which successed deleted: number, // handled docs which got deleted percent: number // percentage }>; migratePromise(batchSize: number): Promise; sync(syncOptions: SyncOptions): RxReplicationState; // if you do custom-sync, use this createRxReplicationState(): RxReplicationState; /** * creates an in-memory replicated version of this collection */ inMemory(): Promise>; insertLocal(id: string, data: any): Promise>>; upsertLocal(id: string, data: any): Promise>>; getLocal(id: string): Promise>>; // only inMemory-collections awaitPersistence(): Promise; destroy(): Promise; remove(): Promise; }