import { DocFn } from './Magnetar.js'; import { FetchMetaDataCollection, MagnetarDeleteAction, MagnetarFetchAction, MagnetarFetchAverageAction, MagnetarFetchCountAction, MagnetarFetchSumAction, MagnetarInsertAction, MagnetarStreamAction } from './types/actions.js'; import { Query, WhereFilterOp, WhereFilterValue } from './types/clauses.js'; import { DeepPropType } from './types/utils/DeepPropType.js'; import { DefaultTo } from './types/utils/DefaultTo.js'; import { PartialDeep } from './types/utils/PartialDeep.js'; import { OPathsWithOptional } from './types/utils/Paths.js'; import { PickNumbers } from './types/utils/PickNumbers.js'; export type CollectionInstance = { /** * The cached data that was written or read so far */ data: Map; /** * Represents `data.size` of your collection, however, calling `fetchCount()` will update just this `count`, from where on it will no longer be linked to `data.size`. */ count: number; /** * Holds the fetched "sum" of the fields on which you called `fetchSum()` so far. This only gets updated when `fetchSum` is called, it is not automatically updated when local cached `data` changes. */ sum: PartialDeep>; /** * Holds the fetched "average" of the fields on which you called `fetchAverage()` so far. This only gets updated when `fetchAverage` is called, it is not automatically updated when local cached `data` changes. */ average: PartialDeep>; /** * `doc` is available on every collection for chaining * @see {@link DocFn} * @example collection('pokedex').doc('001') */ doc: DocFn; /** * The id of the collection. When this is a nested collection, it will not include the full path, only the final part * @example 'items' */ id: string; /** * The full path of the collection * @example 'pokedex/001/items' * @example 'pokedex' */ path: string; /** * Returns the open stream promise of this collection, dependant on which `where`/`query`/`limit`/`orderBy` filters was used. * * Returns `null` when there is no open stream. * * This promise will resolve when `collection().closeStream()` is called, or when the stream closed because of an error. */ streaming: () => Promise | null; /** * Close the stream of this collection, dependant on which `where`/`query`/`limit`/`orderBy` filters was used. * * Does nothing if there is no open stream. */ closeStream: () => void; /** * Close all streams of this collection, no matter which `where`/`query`/`limit`/`orderBy` filters were used. * * Does nothing if there are no open streams. */ closeAllStreams: () => void; /** * @see {@link MagnetarFetchCountAction} */ fetchCount: MagnetarFetchCountAction; /** * @see {@link MagnetarFetchSumAction} */ fetchSum: MagnetarFetchSumAction; /** * @see {@link MagnetarFetchAverageAction} */ fetchAverage: MagnetarFetchAverageAction; /** * @see {@link MagnetarFetchAction} */ fetch: MagnetarFetchAction; /** * @see {@link MagnetarStreamAction} */ stream: MagnetarStreamAction; /** * @see {@link MagnetarInsertAction} */ insert: MagnetarInsertAction; /** * @see {@link MagnetarDeleteAction} */ delete: MagnetarDeleteAction; /** * Chainable filter. Returns {@link CollectionInstance} with filter applied. */ orderBy: (fieldPath: OPathsWithOptional, direction?: 'asc' | 'desc') => CollectionInstance; /** * Chainable filter. Returns {@link CollectionInstance} with filter applied. */ limit: (limitCount: number) => CollectionInstance; /** * Chainable filter. Returns {@link CollectionInstance} with filter applied. */ where: , WhereOp extends WhereFilterOp>(fieldPath: Path, operator: WhereOp, value: WhereFilterValue, any>>) => CollectionInstance; /** * Chainable filter. Returns {@link CollectionInstance} with filter applied. */ query: (query: Query) => CollectionInstance; /** * Chainable filter. Returns {@link CollectionInstance} with filter applied. */ startAfter(docSnapshot: { [key: string]: any; }): CollectionInstance; startAfter(...fieldValues: unknown[]): CollectionInstance; /** * Meta data from the last fetch call */ fetched: FetchMetaDataCollection; };