/// /// import type { Collections, CollectionName } from "../collections"; import type * as Id from "../id"; type Identified = PouchDB.Core.IdMeta; type Retrieved = PouchDB.Core.GetMeta; /** * An object is a Record if it has identification info * (i.e., `{ _id: string }`) */ export type Record = T & Identified; /** * SavedRecord objects additionally contain PouchDB revision info, etc. */ export type SavedRecord = Record & Retrieved; /** * A reference has only identification information */ export type RecordReference = Pick, "_id">; /** * Low-level interface for PouchDB adapters - allows basic CRUD operations * for arbitrary (weakly-typed) data types. */ export interface Adapter { /** * Retrieve and return every saved record for a given collection name */ every, T>(collectionName: N): Promise[]>; /** * Retrieve specific saved records of a given collection name by list of * references. * * @param references - Can be sparse * @return - Items in list correspond to `references` by index (also sparse) */ retrieve, T>(collectionName: N, references: (RecordReference | undefined)[]): Promise<(SavedRecord | undefined)[]>; /** * Search for saved records of a given collection name by PouchDB find * syntax */ search, T>(collectionName: N, options: PouchDB.Find.FindRequest<{}>): Promise[]>; /** * Create or update saved records of a given collection name. * * @param records - Can be sparse * @return - Items in list correspond to `records` by index (also sparse) */ save, T>(collectionName: N, records: (Record | undefined)[], options: { overwrite?: boolean; }): Promise<(SavedRecord | undefined)[]>; /** * Delete saved records * * @param references - Can be sparse */ delete, T>(collectionName: N, references: (RecordReference | undefined)[]): Promise; } /** * @category Definitions */ export type Definitions = { [N in CollectionName]: Definition; }; /** * @category Definitions */ export type Definition> = { createIndexes: PouchDB.Find.CreateIndexOptions["index"][]; } & Id.Definition; export {};