import type { App } from '../app/lifecycle.js'; import { type OrderDirection, type WhereOp } from './rest/query-encoding.js'; import { FirestoreRestClient } from './rest/client.js'; import { FieldPath } from './field-path.js'; import { Filter, type FilterNode } from './filter.js'; import { Timestamp } from './timestamp.js'; export type DocumentData = Record; export type SetOptions = { merge?: boolean; mergeFields?: Array; }; export type TransactionOptions = { maxAttempts?: number; }; export declare class WriteResult { readonly writeTime: Timestamp; constructor(writeTime: Timestamp); } export declare class SnapshotMetadata { readonly fromCache: boolean; readonly hasPendingWrites: boolean; constructor(fromCache: boolean, hasPendingWrites: boolean); isEqual(other: SnapshotMetadata): boolean; } export type DocumentSnapshotData = T; export declare class DocumentSnapshot { readonly ref: DocumentReference; readonly exists: boolean; readonly metadata: SnapshotMetadata; private readonly _data; private readonly _createTime; private readonly _updateTime; private readonly _readTime; constructor(options: { ref: DocumentReference; exists: boolean; data: T | null; metadata?: SnapshotMetadata; createTime?: Timestamp | null; updateTime?: Timestamp | null; readTime?: Timestamp | null; }); get id(): string; data(): DocumentSnapshotData | undefined; get createTime(): Timestamp | undefined; get updateTime(): Timestamp | undefined; get readTime(): Timestamp | undefined; get(fieldPath: string | FieldPath): unknown; } export declare class QueryDocumentSnapshot extends DocumentSnapshot { constructor(options: { ref: DocumentReference; data: T; createTime?: Timestamp | null; updateTime?: Timestamp | null; readTime?: Timestamp | null; }); data(): DocumentSnapshotData; } export type DocumentChangeType = 'added' | 'modified' | 'removed'; export type DocumentChange = { type: DocumentChangeType; doc: QueryDocumentSnapshot; oldIndex: number; newIndex: number; }; export declare class QuerySnapshot { readonly docs: QueryDocumentSnapshot[]; readonly metadata: SnapshotMetadata; private readonly changes; constructor(docs: QueryDocumentSnapshot[], options?: { metadata?: SnapshotMetadata; changes?: Array>; }); get empty(): boolean; get size(): number; forEach(callback: (snapshot: QueryDocumentSnapshot) => void): void; docChanges(options?: { includeMetadataChanges?: boolean; }): Array>; } export declare class Firestore { private readonly rest; private readonly projectId; private readonly baseUrl; private readonly accessTokenProvider; private ignoreUndefinedProperties; constructor(options: { app: App; baseUrl?: string; }); settings(options: { ignoreUndefinedProperties?: boolean; }): void; collection(collectionPath: string): CollectionReference; collectionGroup(collectionId: string): Query; doc(documentPath: string): DocumentReference; batch(): WriteBatch; bulkWriter(options?: BulkWriterOptions): BulkWriter; bundle(bundleId?: string): BundleBuilder; getAll(...refs: Array>): Promise>>; listCollections(): Promise>; runTransaction(updateFn: (tx: Transaction) => Promise, options?: TransactionOptions): Promise; _getRestClient(): FirestoreRestClient; _getProjectId(): string; _getBaseUrl(): string; _getAccessToken(): Promise; _ignoreUndefinedProperties(): boolean; } export declare class DocumentReference { readonly firestore: Firestore; readonly path: string; constructor(options: { firestore: Firestore; path: string; }); get id(): string; get parent(): CollectionReference; collection(collectionPath: string): CollectionReference; get(): Promise>; create(data: T): Promise; set(data: T, options?: SetOptions): Promise; update(data: Record): Promise; update(field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; delete(): Promise; listCollections(): Promise>; onSnapshot(onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: unknown) => void): () => void; onSnapshot(_options: { includeMetadataChanges?: boolean; }, onNext: (snapshot: DocumentSnapshot) => void, onError?: (error: unknown) => void): () => void; private writeUpdate; } type CursorConstraint = { kind: 'values'; inclusive: boolean; values: unknown[]; } | { kind: 'snapshot'; inclusive: boolean; snapshot: DocumentSnapshot; }; export declare class Query { readonly firestore: Firestore; protected readonly collectionPath: string; private readonly whereFilter; private readonly orderByClauses; private readonly limitValue; private readonly limitToLastValue; private readonly offsetValue; private readonly selectFieldPaths; private readonly allDescendants; private readonly startAtBound; private readonly endAtBound; constructor(options: { firestore: Firestore; collectionPath: string; where?: FilterNode | null; orderBy?: Array<{ fieldPath: string; direction: OrderDirection; }>; limit?: number | null; limitToLast?: boolean; offset?: number | null; select?: string[] | null; allDescendants?: boolean; startAt?: CursorConstraint | null; endAt?: CursorConstraint | null; }); where(fieldPath: string | FieldPath, op: WhereOp, value: unknown): Query; where(filter: Filter): Query; orderBy(fieldPath: string | FieldPath, direction?: OrderDirection): Query; limit(limit: number): Query; limitToLast(limit: number): Query; offset(offset: number): Query; select(...fieldPaths: Array): Query; startAt(snapshot: DocumentSnapshot): Query; startAt(...fieldValues: unknown[]): Query; startAfter(snapshot: DocumentSnapshot): Query; startAfter(...fieldValues: unknown[]): Query; endAt(snapshot: DocumentSnapshot): Query; endAt(...fieldValues: unknown[]): Query; endBefore(snapshot: DocumentSnapshot): Query; endBefore(...fieldValues: unknown[]): Query; getPartitions(desiredPartitionCount: number): AsyncIterable>; private _buildStructuredQueryRequest; get(): Promise>; onSnapshot(onNext: (snapshot: QuerySnapshot) => void, onError?: (error: unknown) => void): () => void; onSnapshot(_options: { includeMetadataChanges?: boolean; }, onNext: (snapshot: QuerySnapshot) => void, onError?: (error: unknown) => void): () => void; count(): AggregateQuery; aggregate(aggregations: Record): AggregateQuery; } export declare class AggregateField { private readonly kind; private readonly fieldPath; private constructor(); static count(): AggregateField; static sum(fieldPath: string | FieldPath): AggregateField; static average(fieldPath: string | FieldPath): AggregateField; _encode(alias: string): unknown; } export declare class AggregateQuerySnapshot { private readonly snapshotData; private readonly snapshotReadTime; constructor(options: { data: Record; readTime?: Timestamp | null; }); data(): Record; get readTime(): Timestamp | undefined; } export declare class AggregateQuery { readonly query: Query; private readonly parentResourceName; private readonly structuredQuery; private readonly aggregations; constructor(options: { query: Query; parentResourceName: string; structuredQuery: unknown; aggregations: unknown[]; }); get(): Promise; } export declare class QueryPartition { private readonly baseQuery; private readonly startAtValues; private readonly endBeforeValues; constructor(options: { query: Query; startAt?: unknown[] | undefined; endBefore?: unknown[] | undefined; }); get startAt(): unknown[] | undefined; get endBefore(): unknown[] | undefined; toQuery(): Query; } export declare class CollectionReference extends Query { readonly path: string; constructor(options: { firestore: Firestore; path: string; }); get id(): string; get parent(): DocumentReference | null; doc(documentId: string): DocumentReference; add(data: T): Promise>; listDocuments(options?: { pageSize?: number; }): Promise>>; } export declare class WriteBatch { private readonly firestore; private readonly writes; constructor(firestore: Firestore); create(ref: DocumentReference, data: T): this; set(ref: DocumentReference, data: T, options?: SetOptions): this; update(ref: DocumentReference, data: Record): this; update(ref: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; delete(ref: DocumentReference): this; commit(): Promise; } export type BulkWriterOptions = { throttling?: boolean | { initialOpsPerSecond?: number; maxOpsPerSecond?: number; }; }; export declare class BulkWriterError extends Error { readonly code: number; readonly documentRef: DocumentReference; readonly operationType: 'create' | 'set' | 'update' | 'delete'; readonly failedAttempts: number; constructor(options: { code: number; message: string; documentRef: DocumentReference; operationType: 'create' | 'set' | 'update' | 'delete'; failedAttempts: number; }); } export declare class BulkWriter { private readonly firestore; private readonly queue; private readonly pendingOpIds; private readonly flushWaiters; private readonly writeResultListeners; private writeErrorListener; private nextOpId; private scheduled; private processing; private closed; private batchWriteDisabled; private readonly maxBatchSize; private readonly maxAttempts; constructor(firestore: Firestore, options?: BulkWriterOptions); private ensureOpen; onWriteResult(callback: (documentRef: DocumentReference, result: WriteResult) => void): void; onWriteError(shouldRetryCallback: (error: BulkWriterError) => boolean): void; create(documentRef: DocumentReference, data: T): Promise; set(documentRef: DocumentReference, data: T): Promise; set(documentRef: DocumentReference, data: Partial, options: SetOptions): Promise; update(documentRef: DocumentReference, data: Record): Promise; update(documentRef: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise; delete(documentRef: DocumentReference): Promise; flush(): Promise; close(): Promise; private enqueue; private schedule; private notifyFlushWaiters; private takeBatch; private processQueue; private processBatchViaCommit; private processBatch; } export declare class BundleBuilder { readonly bundleId: string; constructor(bundleId: string); add(snapshotOrName: unknown, maybeSnapshot?: unknown): this; build(): Uint8Array; } export declare class Transaction { private readonly firestore; private readonly transactionId; private readonly writes; private didWrite; constructor(firestore: Firestore, transactionId: string); get(ref: DocumentReference): Promise>; set(ref: DocumentReference, data: T, options?: SetOptions): this; create(ref: DocumentReference, data: T): this; update(ref: DocumentReference, data: Record): this; update(ref: DocumentReference, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this; delete(ref: DocumentReference): this; commit(): Promise; } export declare function getFirestore(app?: App): Firestore; export {}; //# sourceMappingURL=firestore.d.ts.map