import { CollectionReference } from './collection'; import { MetaType } from '../metaTypeCreator'; import { Firestore } from '../alias'; import { GetOddOrEvenSegments } from '../utils'; import { IsValidDocIDLoop } from '../validID'; import { ErrorAutoIdTypeMustBeWideString, ErrorDocIdIncorrectType } from '../error'; /** * A {@link DocumentReference} refers to a document location in a Firestore database * and can be used to write, read, or listen to the location. The document at * the referenced location may or may not exist. A {@link DocumentReference} can * also be used to create a `CollectionReference` to a subcollection. */ export interface DocumentReference { /** * The document's identifier within its collection. */ readonly id: T['docID']; /** * The `Firestore` instance the document is in. * This is useful for performing transactions, for example. */ readonly firestore: Firestore; /** * The collection this {@link DocumentReference} belongs to. */ readonly parent: CollectionReference; /** * A string representing the path of the referenced document (relative * to the root of the database). */ readonly path: T['docPath']; /** * Fetches the subcollections that are direct children of this document. * * @returns A Promise that resolves with an array of CollectionReferences. */ listCollections(): Promise[]>; } export type DocCreator = (fStore: Firestore, ...collectionIDs: GetOddOrEvenSegments) => Doc; export type Doc = { /** * Gets a {@link DocumentReference} instance that refers to the document at the * specified absolute path. * * related documentations: * - {@link https://firelordjs.com/guides/metatype child meta type} * - {@link https://firelordjs.com/firelord/quick_start#operations operation} * @param documentIds_or_CollectionReference * Option 1: all the docID(s) needed to build this document path, eg * - for top-collection: example.doc(SelfDocId) * - for sub-collection: example.doc(GrandParentDocId, ParentsDocId, SelfDocId). * * Option 2: CollectionReference (to create auto id doc ref), eg * - for top-collection: example.doc(example.collection()) * - for sub-collection: example.doc(example.collection(GrandParentCollectionID, ParenCollectionID)) * * @returns The {@link DocumentReference} instance. */ > | CollectionReference>(...documentIds_or_CollectionReference: D extends never ? D : D extends CollectionReference ? string extends T['docID'] ? [D] : [ErrorAutoIdTypeMustBeWideString] : D extends string[] ? IsValidDocIDLoop : ErrorDocIdIncorrectType): DocumentReference; }; export type GetDocIds = GetOddOrEvenSegments;