@dereekb/firebase 13.0.5 → 13.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,247 +3,383 @@ import { type FirestoreModelId, type FirestoreModelIdRef, type FirestoreModelKey
3
3
  import { type QueryDocumentSnapshot, type DocumentDataWithIdAndKey, type DocumentReference, type DocumentSnapshot, type QuerySnapshot, type Transaction } from '../types';
4
4
  import { type FirestoreDocumentData, type FirestoreDocument, type FirestoreDocumentAccessor, type LimitedFirestoreDocumentAccessor, type LimitedFirestoreDocumentAccessorContextExtension } from './document';
5
5
  /**
6
- * Creates an array of new FirestoreDocument instances without creating them in Firestore.
6
+ * Creates an array of new {@link FirestoreDocument} instances without persisting them to Firestore.
7
7
  *
8
- * @template T - The document data type
9
- * @template D - The FirestoreDocument implementation type
10
- * @param documentAccessor - The document accessor to use for creating document instances
11
- * @param count - The number of document instances to create
12
- * @returns An array of new document instances
8
+ * Each document is allocated a unique auto-generated ID via {@link FirestoreDocumentAccessor.newDocument},
9
+ * but no data is written to the database. Useful for preparing document references in bulk before
10
+ * deciding what data to write.
11
+ *
12
+ * @param documentAccessor - Accessor that provides the `newDocument()` factory method
13
+ * @param count - Number of document instances to create
14
+ * @returns Array of `count` new document instances, each with a unique auto-generated ID
13
15
  */
14
16
  export declare function newDocuments<T, D extends FirestoreDocument<T>>(documentAccessor: FirestoreDocumentAccessor<T, D>, count: number): D[];
15
17
  /**
16
- * Parameters for creating and initializing multiple Firestore documents.
17
- *
18
- * @template T - The document data type
19
- * @template D - The FirestoreDocument implementation type
18
+ * Configuration for {@link makeDocuments} that controls how documents are created and initialized.
20
19
  */
21
20
  export interface MakeDocumentsParams<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> {
22
21
  /**
23
- * The number of documents to create.
22
+ * Number of documents to create.
24
23
  */
25
24
  readonly count: number;
26
25
  /**
27
- * Optional override to create a new document using the input accessor.
28
- * If not provided, the accessor's default newDocument method will be used.
26
+ * Optional factory override for creating new document instances.
29
27
  *
30
- * @param documentAccessor - The document accessor to use for creating document instances
28
+ * When omitted, the accessor's default {@link FirestoreDocumentAccessor.newDocument} is used,
29
+ * which generates a random document ID. Provide this to customize document creation,
30
+ * e.g. to use specific IDs via `loadDocumentForId`.
31
+ *
32
+ * @param documentAccessor - The accessor to create the document from
31
33
  * @returns A new document instance
32
34
  */
33
35
  readonly newDocument?: (documentAccessor: FirestoreDocumentAccessor<T, D>) => D;
34
36
  /**
35
- * Initializes the document with data and/or performs tasks with the document.
37
+ * Called for each document to produce its initial data.
36
38
  *
37
- * If this function returns a value (not null/undefined), that data will be used
38
- * to create the document in Firestore. If it returns null/undefined, no document
39
- * will be created in Firestore but the document instance will still be returned.
39
+ * If the returned value is non-nullish, the document is created in Firestore with that data
40
+ * via `document.accessor.create(data)`. If nullish, the document instance is still returned
41
+ * but nothing is written to the database.
40
42
  *
41
- * @param i - The index of the document being created (0 to count-1)
42
- * @param document - The document instance to initialize
43
- * @returns Document data to create in Firestore, or null/undefined to skip creation
43
+ * @param i - Zero-based index of the current document
44
+ * @param document - The document instance (already has an allocated reference)
45
+ * @returns Data to persist, or nullish to skip Firestore creation
44
46
  */
45
47
  readonly init: (i: number, document: D) => Maybe<T> | Promise<Maybe<T>>;
46
48
  }
47
49
  /**
48
- * Creates multiple documents in Firestore and returns the document instances.
50
+ * Creates and optionally persists multiple Firestore documents in sequence.
51
+ *
52
+ * Uses {@link performMakeLoop} to iterate `count` times. For each iteration:
53
+ * 1. A new document instance is created (via `make.newDocument` or the default factory)
54
+ * 2. `make.init(i, document)` is awaited to produce initial data
55
+ * 3. If init returns non-nullish data, `document.accessor.create(data)` persists it
56
+ * 4. The document instance is collected regardless of whether it was persisted
49
57
  *
50
- * For each document, this function:
51
- * 1. Creates a new document instance using the specified or default factory
52
- * 2. Calls the init function with the document instance
53
- * 3. If init returns data, creates the document in Firestore
54
- * 4. Returns all document instances, whether they were created in Firestore or not
58
+ * Documents are created sequentially (not in parallel) to allow index-dependent logic.
55
59
  *
56
- * @template T - The document data type
57
- * @template D - The FirestoreDocument implementation type
58
- * @param documentAccessor - The document accessor to use for creating document instances
59
- * @param make - Parameters for document creation and initialization
60
- * @returns A promise that resolves to an array of document instances
60
+ * @param documentAccessor - Accessor providing the document factory and collection context
61
+ * @param make - Configuration controlling count, factory, and initialization
62
+ * @returns Promise resolving to all created document instances (length === `make.count`)
61
63
  */
62
64
  export declare function makeDocuments<T, D extends FirestoreDocument<T>>(documentAccessor: FirestoreDocumentAccessor<T, D>, make: MakeDocumentsParams<T, D>): Promise<D[]>;
63
65
  /**
64
- * Retrieves DocumentSnapshots for an array of documents in parallel.
66
+ * Fetches {@link DocumentSnapshot}s for multiple documents in parallel using {@link runAsyncTasksForValues}.
65
67
  *
66
- * This is useful for fetching the current state of multiple documents at once.
68
+ * Each document's `accessor.get()` is called concurrently. The returned array preserves
69
+ * the same ordering as the input `documents` array.
67
70
  *
68
- * @template D - The FirestoreDocument implementation type
69
- * @param documents - Array of document instances to get snapshots for
70
- * @returns Promise that resolves to an array of DocumentSnapshots in the same order as the input documents
71
+ * @param documents - Documents to fetch snapshots for
72
+ * @returns Snapshots in the same order as the input array
71
73
  */
72
74
  export declare function getDocumentSnapshots<D extends FirestoreDocument<any>>(documents: D[]): Promise<DocumentSnapshot<FirestoreDocumentData<D>>[]>;
73
75
  /**
74
- * A pair containing both a FirestoreDocument instance and its current DocumentSnapshot.
76
+ * Pairs a {@link FirestoreDocument} instance with its fetched {@link DocumentSnapshot}.
75
77
  *
76
- * This allows keeping track of both the document reference and its data.
77
- *
78
- * @template D - The FirestoreDocument implementation type
78
+ * Retains a reference to the original document alongside its snapshot, which is useful
79
+ * when you need both the document's methods (e.g. `update`, `create`) and its current data state.
79
80
  */
80
81
  export type FirestoreDocumentSnapshotPair<D extends FirestoreDocument<any>> = {
81
- /** The original document instance */
82
+ /** The document instance used to fetch the snapshot. */
82
83
  readonly document: D;
83
- /** The current snapshot of the document from Firestore */
84
+ /** The fetched snapshot reflecting the document's current state in Firestore. */
84
85
  readonly snapshot: DocumentSnapshot<FirestoreDocumentData<D>>;
85
86
  };
86
87
  /**
87
- * Creates a document-snapshot pair from a document instance.
88
- *
89
- * Fetches the current snapshot of the document and returns both the original
90
- * document instance and the snapshot together.
88
+ * Fetches the current snapshot of a single document and pairs it with the document instance.
91
89
  *
92
- * @template D - The FirestoreDocument implementation type
93
- * @param document - The document instance to get a snapshot for
94
- * @returns Promise that resolves to a document-snapshot pair
90
+ * @param document - The document to fetch
91
+ * @returns A pair containing the document and its snapshot
95
92
  */
96
93
  export declare function getDocumentSnapshotPair<D extends FirestoreDocument<any>>(document: D): Promise<FirestoreDocumentSnapshotPair<D>>;
97
94
  /**
98
- * Creates document-snapshot pairs for an array of documents in parallel.
99
- *
100
- * Fetches the current snapshot of each document and returns pairs containing both
101
- * the original document instances and their snapshots.
95
+ * Fetches snapshots for multiple documents in parallel and pairs each with its document instance.
102
96
  *
103
- * @template D - The FirestoreDocument implementation type
104
- * @param documents - Array of document instances to get snapshots for
105
- * @returns Promise that resolves to an array of document-snapshot pairs in the same order as the input documents
97
+ * @param documents - Documents to fetch
98
+ * @returns Pairs in the same order as the input array
106
99
  */
107
100
  export declare function getDocumentSnapshotPairs<D extends FirestoreDocument<any>>(documents: D[]): Promise<FirestoreDocumentSnapshotPair<D>[]>;
108
101
  /**
109
- * A tuple containing a document instance, its snapshot, and the extracted data.
102
+ * Combines a {@link FirestoreDocument}, its {@link DocumentSnapshot}, and extracted data with `id`/`key` fields.
110
103
  *
111
- * Provides a comprehensive view of a document with its reference, snapshot state,
112
- * and formatted data (including ID and key fields).
113
- *
114
- * @template D - The FirestoreDocument implementation type
104
+ * The `data` field is produced by {@link documentDataWithIdAndKey}, which mutates the snapshot's data object
105
+ * to include `id` (the document ID) and `key` (the full document path). If the document does not exist
106
+ * in Firestore, `data` will be `undefined`.
115
107
  */
116
108
  export interface FirestoreDocumentSnapshotDataPair<D extends FirestoreDocument<any>> {
117
- /** The original document instance */
109
+ /** The document instance used to fetch the snapshot. */
118
110
  readonly document: D;
119
- /** The current snapshot of the document from Firestore */
111
+ /** The fetched snapshot reflecting the document's current state in Firestore. */
120
112
  readonly snapshot: DocumentSnapshot<FirestoreDocumentData<D>>;
121
- /** The document data with ID and key fields added, or undefined if the document doesn't exist */
113
+ /** The snapshot's data with `id` and `key` fields injected, or `undefined` if the document does not exist. */
122
114
  readonly data: Maybe<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>>;
123
115
  }
124
116
  /**
125
- * A variant of FirestoreDocumentSnapshotDataPair that guarantees data exists.
126
- *
127
- * This interface is used when you need to ensure that only documents with existing
128
- * data are included in the results.
117
+ * Narrowed variant of {@link FirestoreDocumentSnapshotDataPair} where `data` is guaranteed non-nullish.
129
118
  *
130
- * @template D - The FirestoreDocument implementation type
119
+ * Used by functions like {@link getDocumentSnapshotDataPairsWithData} that filter out non-existent documents.
131
120
  */
132
121
  export interface FirestoreDocumentSnapshotDataPairWithData<D extends FirestoreDocument<any>> extends Omit<FirestoreDocumentSnapshotDataPair<D>, 'data'> {
133
- /** The document data with ID and key fields added (guaranteed to exist) */
122
+ /** The snapshot's data with `id` and `key` fields injected (guaranteed to exist). */
134
123
  readonly data: DocumentDataWithIdAndKey<FirestoreDocumentData<D>>;
135
124
  }
136
125
  /**
137
- * Creates a document-snapshot-data triplet from a document instance.
138
- *
139
- * Fetches the current snapshot of the document, extracts its data with ID and key fields,
140
- * and returns all three together in a single object.
126
+ * Fetches a document's snapshot, extracts its data with `id`/`key` fields, and returns all three as a triplet.
141
127
  *
142
- * @template D - The FirestoreDocument implementation type
143
- * @param document - The document instance to get data for
144
- * @returns Promise that resolves to a document-snapshot-data triplet
128
+ * @param document - The document to fetch
129
+ * @returns A triplet of document, snapshot, and data (data may be `undefined` if the document doesn't exist)
145
130
  */
146
131
  export declare function getDocumentSnapshotDataPair<D extends FirestoreDocument<any>>(document: D): Promise<FirestoreDocumentSnapshotDataPair<D>>;
147
132
  /**
148
- * Creates document-snapshot-data triplets for an array of documents in parallel.
133
+ * Fetches snapshot-data triplets for multiple documents in parallel.
149
134
  *
150
- * Fetches the current snapshot of each document, extracts its data with ID and key fields,
151
- * and returns triplets containing all three components for each document.
135
+ * Processes up to 200 documents concurrently via {@link runAsyncTasksForValues}.
136
+ * The returned array preserves the same ordering as the input.
152
137
  *
153
- * @template D - The FirestoreDocument implementation type
154
- * @param documents - Array of document instances to get data for
155
- * @returns Promise that resolves to an array of document-snapshot-data triplets in the same order as the input documents
138
+ * @param documents - Documents to fetch
139
+ * @returns Triplets in the same order as the input array
156
140
  */
157
141
  export declare function getDocumentSnapshotDataPairs<D extends FirestoreDocument<any>>(documents: D[]): Promise<FirestoreDocumentSnapshotDataPair<D>[]>;
158
142
  /**
159
- * Creates document-snapshot-data triplets for an array of documents and filters out those without data.
143
+ * Fetches snapshot-data triplets for multiple documents and filters out those that don't exist in Firestore.
160
144
  *
161
- * This is a convenience function that fetches data for all documents and then returns
162
- * only the triplets for documents that actually exist in Firestore.
145
+ * Convenience wrapper around {@link getDocumentSnapshotDataPairs} that removes entries where `data` is nullish,
146
+ * returning only {@link FirestoreDocumentSnapshotDataPairWithData} results.
163
147
  *
164
- * @template D - The FirestoreDocument implementation type
165
- * @param documents - Array of document instances to get data for
166
- * @returns Promise that resolves to an array of document-snapshot-data triplets for existing documents only
148
+ * @param documents - Documents to fetch
149
+ * @returns Triplets for documents that exist, in their original relative order
167
150
  */
168
151
  export declare function getDocumentSnapshotDataPairsWithData<D extends FirestoreDocument<any>>(documents: D[]): Promise<FirestoreDocumentSnapshotDataPairWithData<D>[]>;
152
+ /**
153
+ * A tuple of `[document, data]` where `data` is the raw snapshot data (without `id`/`key` injection)
154
+ * or `undefined` if the document doesn't exist.
155
+ */
169
156
  export type FirestoreDocumentSnapshotDataTuple<D extends FirestoreDocument<any>> = [D, Maybe<FirestoreDocumentData<D>>];
157
+ /**
158
+ * Fetches raw snapshot data tuples for multiple documents in parallel.
159
+ *
160
+ * Unlike {@link getDocumentSnapshotDataPairs}, this returns a lightweight `[document, data]` tuple
161
+ * and does not inject `id`/`key` fields onto the data. The `data` value is the raw result of
162
+ * `snapshot.data()` and may be `undefined` for non-existent documents.
163
+ *
164
+ * @param documents - Documents to fetch
165
+ * @returns Tuples in the same order as the input array
166
+ */
170
167
  export declare function getDocumentSnapshotDataTuples<D extends FirestoreDocument<any>>(documents: D[]): Promise<FirestoreDocumentSnapshotDataTuple<D>[]>;
168
+ /**
169
+ * Fetches the data from a single document's snapshot.
170
+ *
171
+ * By default (`withId=true`), the returned data has `id` and `key` fields injected via
172
+ * {@link documentDataWithIdAndKey}. Pass `withId=false` to get the raw snapshot data instead.
173
+ *
174
+ * Returns `undefined` if the document does not exist.
175
+ *
176
+ * @param document - The document to fetch data for
177
+ * @param withId - Whether to inject `id` and `key` fields onto the data (default: `true`)
178
+ * @returns The document's data, or `undefined` if it doesn't exist
179
+ */
171
180
  export declare function getDocumentSnapshotData<D extends FirestoreDocument<any>>(document: D): Promise<Maybe<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>>>;
172
181
  export declare function getDocumentSnapshotData<D extends FirestoreDocument<any>>(document: D, withId: true): Promise<Maybe<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>>>;
173
182
  export declare function getDocumentSnapshotData<D extends FirestoreDocument<any>>(document: D, withId: false): Promise<Maybe<FirestoreDocumentData<D>>>;
174
183
  export declare function getDocumentSnapshotData<D extends FirestoreDocument<any>>(document: D, withId?: boolean): Promise<Maybe<DocumentDataWithIdAndKey<FirestoreDocumentData<D>> | FirestoreDocumentData<D>>>;
184
+ /**
185
+ * Fetches data for multiple documents in parallel, filtering out non-existent documents.
186
+ *
187
+ * By default (`withId=true`), each data object has `id` and `key` fields injected.
188
+ * Documents that don't exist in Firestore are excluded from the results (the returned
189
+ * array may be shorter than the input).
190
+ *
191
+ * @param documents - Documents to fetch data for
192
+ * @param withId - Whether to inject `id` and `key` fields onto each data object (default: `true`)
193
+ * @returns Data objects for existing documents only
194
+ */
175
195
  export declare function getDocumentSnapshotsData<D extends FirestoreDocument<any>>(documents: D[]): Promise<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>[]>;
176
196
  export declare function getDocumentSnapshotsData<D extends FirestoreDocument<any>>(documents: D[], withId: true): Promise<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>[]>;
177
197
  export declare function getDocumentSnapshotsData<D extends FirestoreDocument<any>>(documents: D[], withId: false): Promise<FirestoreDocumentData<D>[]>;
178
198
  export declare function getDocumentSnapshotsData<D extends FirestoreDocument<any>>(documents: D[], withId?: boolean): Promise<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>[] | FirestoreDocumentData<D>[]>;
179
199
  /**
180
- * Returns the data from all input snapshots. Snapshots without data are filtered out.
200
+ * Extracts data from an array of {@link DocumentSnapshot}s, filtering out snapshots for non-existent documents.
201
+ *
202
+ * By default (`withId=true`), each data object has `id` and `key` fields injected via {@link documentDataWithIdAndKey}.
203
+ * Snapshots where `data()` returns `undefined` are removed from the output via {@link filterMaybeArrayValues}.
181
204
  *
182
- * @param snapshots
205
+ * @param snapshots - Snapshots to extract data from
206
+ * @param withId - Whether to inject `id` and `key` fields onto each data object (default: `true`)
207
+ * @returns Data objects for existing documents only (may be shorter than input)
183
208
  */
184
209
  export declare function getDataFromDocumentSnapshots<T>(snapshots: DocumentSnapshot<T>[]): DocumentDataWithIdAndKey<T>[];
185
210
  export declare function getDataFromDocumentSnapshots<T>(snapshots: DocumentSnapshot<T>[], withId: true): DocumentDataWithIdAndKey<T>[];
186
211
  export declare function getDataFromDocumentSnapshots<T>(snapshots: DocumentSnapshot<T>[], withId: false): T[];
187
212
  export declare function getDataFromDocumentSnapshots<T>(snapshots: DocumentSnapshot<T>[], withId?: boolean): DocumentDataWithIdAndKey<T>[] | T[];
213
+ /**
214
+ * Creates {@link FirestoreDocument} instances for all documents in a {@link QuerySnapshot}.
215
+ *
216
+ * Maps each document in `snapshots.docs` to a loaded document via `accessor.loadDocument(ref)`.
217
+ * No additional data fetching occurs; the documents are loaded from their existing references.
218
+ *
219
+ * @param accessor - Accessor to load documents with
220
+ * @param snapshots - Query snapshot containing the document references
221
+ * @returns Document instances in the same order as the query results
222
+ */
188
223
  export declare function loadDocumentsForSnapshots<T, D extends FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>, snapshots: QuerySnapshot<T>): D[];
224
+ /**
225
+ * Extracts {@link DocumentReference}s from arbitrary values and loads them as {@link FirestoreDocument} instances.
226
+ *
227
+ * Convenience function that maps values through `getRef` then delegates to {@link loadDocumentsForDocumentReferences}.
228
+ *
229
+ * @param accessor - Accessor to load documents with
230
+ * @param values - Source values to extract references from
231
+ * @param getRef - Extracts a document reference from each value
232
+ * @returns Document instances in the same order as the input values
233
+ */
189
234
  export declare function loadDocumentsForDocumentReferencesFromValues<I, T, D extends FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>, values: I[], getRef: (value: I) => DocumentReference<T>): D[];
235
+ /**
236
+ * Alias for {@link loadDocumentsForDocumentReferencesFromValues}.
237
+ */
190
238
  export declare const loadDocumentsForValues: typeof loadDocumentsForDocumentReferencesFromValues;
239
+ /**
240
+ * Loads {@link FirestoreDocument} instances from an array of {@link DocumentReference}s.
241
+ *
242
+ * Each reference is passed to `accessor.loadDocument()` to create a document wrapper.
243
+ * No network calls are made; this only creates in-memory document instances bound to the given references.
244
+ *
245
+ * @param accessor - Accessor to load documents with
246
+ * @param refs - Document references to load
247
+ * @returns Document instances in the same order as the input references
248
+ */
191
249
  export declare function loadDocumentsForDocumentReferences<T, D extends FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>, refs: DocumentReference<T>[]): D[];
250
+ /**
251
+ * Extracts {@link FirestoreModelKey}s from arbitrary values and loads them as {@link FirestoreDocument} instances.
252
+ *
253
+ * Convenience function that maps values through `getKey` then delegates to {@link loadDocumentsForKeys}.
254
+ *
255
+ * @param accessor - Accessor to load documents with
256
+ * @param values - Source values to extract keys from
257
+ * @param getKey - Extracts a model key (full Firestore path) from each value
258
+ * @returns Document instances in the same order as the input values
259
+ */
192
260
  export declare function loadDocumentsForKeysFromValues<I, T, D extends FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>, values: I[], getKey: (value: I) => FirestoreModelKey): D[];
261
+ /**
262
+ * Loads {@link FirestoreDocument} instances from an array of full Firestore document paths (keys).
263
+ *
264
+ * Each key is passed to `accessor.loadDocumentForKey()`. No network calls are made.
265
+ *
266
+ * @param accessor - Accessor to load documents with
267
+ * @param keys - Full Firestore document paths (e.g. `'users/abc123'`)
268
+ * @returns Document instances in the same order as the input keys
269
+ */
193
270
  export declare function loadDocumentsForKeys<T, D extends FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>, keys: FirestoreModelKey[]): D[];
271
+ /**
272
+ * Extracts {@link FirestoreModelId}s from arbitrary values and loads them as {@link FirestoreDocument} instances.
273
+ *
274
+ * Convenience function that maps values through `getId` then delegates to {@link loadDocumentsForIds}.
275
+ * Requires a full {@link FirestoreDocumentAccessor} (not limited) because loading by ID requires collection context.
276
+ *
277
+ * @param accessor - Accessor to load documents with (must have collection context for ID resolution)
278
+ * @param values - Source values to extract IDs from
279
+ * @param getId - Extracts a model ID from each value
280
+ * @returns Document instances in the same order as the input values
281
+ */
194
282
  export declare function loadDocumentsForIdsFromValues<I, T, D extends FirestoreDocument<T>>(accessor: FirestoreDocumentAccessor<T, D>, values: I[], getId: (value: I) => FirestoreModelId): D[];
283
+ /**
284
+ * Loads {@link FirestoreDocument} instances from an array of document IDs relative to the accessor's collection.
285
+ *
286
+ * Each ID is passed to `accessor.loadDocumentForId()`. Requires a full {@link FirestoreDocumentAccessor}
287
+ * because ID-based loading needs the collection reference to resolve the full path. No network calls are made.
288
+ *
289
+ * @param accessor - Accessor to load documents with (must have collection context)
290
+ * @param ids - Document IDs within the accessor's collection
291
+ * @returns Document instances in the same order as the input IDs
292
+ */
195
293
  export declare function loadDocumentsForIds<T, D extends FirestoreDocument<T>>(accessor: FirestoreDocumentAccessor<T, D>, ids: FirestoreModelId[]): D[];
196
294
  /**
197
- * Used for loading documents for the input references.
295
+ * Function type that loads {@link FirestoreDocument} instances from {@link DocumentReference}s.
296
+ *
297
+ * When a {@link Transaction} is provided, the returned documents are bound to that transaction's accessor,
298
+ * ensuring reads/writes participate in the transaction. Otherwise, the default accessor is used.
198
299
  */
199
300
  export type FirestoreDocumentLoader<T, D extends FirestoreDocument<T>> = (references: DocumentReference<T>[], transaction?: Transaction) => D[];
200
301
  /**
201
- * Used to make a FirestoreDocumentLoader.
302
+ * Creates a {@link FirestoreDocumentLoader} from a {@link LimitedFirestoreDocumentAccessorContextExtension}.
303
+ *
304
+ * The returned loader resolves the appropriate accessor based on whether a transaction is provided,
305
+ * then delegates to {@link loadDocumentsForDocumentReferences}.
202
306
  *
203
- * @param accessorContext
204
- * @returns
307
+ * @param accessorContext - Context that provides accessors for both default and transactional use
308
+ * @returns A loader function that converts document references to document instances
205
309
  */
206
310
  export declare function firestoreDocumentLoader<T, D extends FirestoreDocument<T>>(accessorContext: LimitedFirestoreDocumentAccessorContextExtension<T, D>): FirestoreDocumentLoader<T, D>;
207
311
  /**
208
- * Used for loading documents for the input snapshots.
312
+ * Function type that converts {@link DocumentSnapshot}s into {@link FirestoreDocumentSnapshotDataPair}s.
313
+ *
314
+ * Loads a document for each snapshot's reference and extracts data with `id`/`key` fields.
315
+ * When a {@link Transaction} is provided, documents are bound to that transaction's accessor.
209
316
  */
210
317
  export type FirestoreDocumentSnapshotPairsLoader<T, D extends FirestoreDocument<T>> = (snapshots: DocumentSnapshot<T>[], transaction?: Transaction) => FirestoreDocumentSnapshotDataPair<D>[];
211
318
  /**
212
- * Used for loading documents for the input query snapshots. Query snapshots always contain data.
319
+ * Variant of {@link FirestoreDocumentSnapshotPairsLoader} for {@link QueryDocumentSnapshot}s.
320
+ *
321
+ * Since query snapshots always contain data, the returned pairs use
322
+ * {@link FirestoreDocumentSnapshotDataPairWithData} where `data` is guaranteed non-nullish.
213
323
  */
214
324
  export type FirestoreQueryDocumentSnapshotPairsLoader<T, D extends FirestoreDocument<T>> = (snapshots: QueryDocumentSnapshot<T>[], transaction?: Transaction) => FirestoreDocumentSnapshotDataPairWithData<D>[];
215
325
  /**
216
- * Used to make a FirestoreDocumentSnapshotPairsLoader.
326
+ * Creates a {@link FirestoreDocumentSnapshotPairsLoader} from a {@link LimitedFirestoreDocumentAccessorContextExtension}.
327
+ *
328
+ * The returned loader resolves the appropriate accessor based on whether a transaction is provided,
329
+ * then maps each snapshot to a {@link FirestoreDocumentSnapshotDataPair} using {@link firestoreDocumentSnapshotPairsLoaderInstance}.
330
+ *
331
+ * Also satisfies the {@link FirestoreQueryDocumentSnapshotPairsLoader} type since the implementation
332
+ * handles both {@link DocumentSnapshot} and {@link QueryDocumentSnapshot} inputs.
217
333
  *
218
- * @param accessorContext
219
- * @returns
334
+ * @param accessorContext - Context that provides accessors for both default and transactional use
335
+ * @returns A loader function that converts snapshots to document-snapshot-data pairs
220
336
  */
221
337
  export declare function firestoreDocumentSnapshotPairsLoader<T, D extends FirestoreDocument<T>>(accessorContext: LimitedFirestoreDocumentAccessorContextExtension<T, D>): FirestoreDocumentSnapshotPairsLoader<T, D> & FirestoreQueryDocumentSnapshotPairsLoader<T, D>;
222
338
  /**
223
- * Used for loading a FirestoreDocumentSnapshotDataPair for the input snapshot. The accessor is already available given the context.
339
+ * A callable that converts a single snapshot into a {@link FirestoreDocumentSnapshotDataPair},
340
+ * with the accessor already bound.
341
+ *
342
+ * Overloaded: when given a {@link QueryDocumentSnapshot} (which always has data), returns
343
+ * {@link FirestoreDocumentSnapshotDataPairWithData}. When given a {@link DocumentSnapshot},
344
+ * returns the base {@link FirestoreDocumentSnapshotDataPair} where `data` may be `undefined`.
345
+ *
346
+ * Exposes `_accessor` for inspection of the bound accessor.
224
347
  */
225
348
  export type FirestoreDocumentSnapshotPairsLoaderInstance<T, D extends FirestoreDocument<T>> = (((snapshot: QueryDocumentSnapshot<T>) => FirestoreDocumentSnapshotDataPairWithData<D>) & ((snapshots: DocumentSnapshot<T>) => FirestoreDocumentSnapshotDataPair<D>)) & {
226
349
  readonly _accessor: LimitedFirestoreDocumentAccessor<T, D>;
227
350
  };
228
351
  /**
229
- * Used to make a FirestoreDocumentSnapshotPairsLoader.
352
+ * Creates a {@link FirestoreDocumentSnapshotPairsLoaderInstance} bound to a specific accessor.
353
+ *
354
+ * The returned function converts a snapshot into a {@link FirestoreDocumentSnapshotDataPair} by:
355
+ * 1. Extracting data with `id`/`key` fields via {@link documentDataWithIdAndKey}
356
+ * 2. Loading the document from the snapshot's reference via `accessor.loadDocument()`
357
+ * 3. Combining all three into a single pair object
230
358
  *
231
- * @param accessorContext
232
- * @returns
359
+ * @param accessor - The accessor to bind for document loading
360
+ * @returns A reusable function that converts snapshots to pairs using the bound accessor
233
361
  */
234
362
  export declare function firestoreDocumentSnapshotPairsLoaderInstance<T, D extends FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>): FirestoreDocumentSnapshotPairsLoaderInstance<T, D>;
235
363
  /**
236
- * Used to make a FirestoreQueryDocumentSnapshotPairsLoader.
364
+ * Alias for {@link firestoreDocumentSnapshotPairsLoader}, typed specifically as a {@link FirestoreQueryDocumentSnapshotPairsLoader}.
237
365
  *
238
- * @param accessorContext
239
- * @returns
366
+ * Use this when you know all input snapshots are from a query and want the stronger return type
367
+ * that guarantees `data` is non-nullish.
240
368
  */
241
369
  export declare const firestoreQueryDocumentSnapshotPairsLoader: <T, D extends FirestoreDocument<T>>(accessorContext: LimitedFirestoreDocumentAccessorContextExtension<T, D>) => FirestoreQueryDocumentSnapshotPairsLoader<T, D>;
242
370
  /**
243
- * Creates the document data from the snapshot.
371
+ * Extracts data from a {@link DocumentSnapshot}, optionally injecting `id` and `key` fields.
244
372
  *
245
- * @param snapshot
246
- * @returns
373
+ * When `withId` is `true` (default is `false`), delegates to {@link documentDataWithIdAndKey} to mutate
374
+ * the data object with `id` (document ID) and `key` (full document path). When `false`, returns the
375
+ * raw result of `snapshot.data()`.
376
+ *
377
+ * For {@link QueryDocumentSnapshot} inputs, the return value is guaranteed non-nullish.
378
+ * For {@link DocumentSnapshot} inputs, may return `undefined` if the document doesn't exist.
379
+ *
380
+ * @param snapshot - The snapshot to extract data from
381
+ * @param withId - Whether to inject `id` and `key` fields (default: `false`)
382
+ * @returns The snapshot data, or `undefined` for non-existent documents
247
383
  */
248
384
  export declare function documentData<T>(snapshot: QueryDocumentSnapshot<T>): DocumentDataWithIdAndKey<T>;
249
385
  export declare function documentData<T>(snapshot: QueryDocumentSnapshot<T>, withId: true): DocumentDataWithIdAndKey<T>;
@@ -251,51 +387,137 @@ export declare function documentData<T>(snapshot: QueryDocumentSnapshot<T>, with
251
387
  export declare function documentData<T>(snapshot: DocumentSnapshot<T>): Maybe<DocumentDataWithIdAndKey<T>>;
252
388
  export declare function documentData<T>(snapshot: DocumentSnapshot<T>, withId: true): Maybe<DocumentDataWithIdAndKey<T>>;
253
389
  export declare function documentData<T>(snapshot: DocumentSnapshot<T>, withId: false): Maybe<T>;
390
+ /**
391
+ * Function type that extracts raw data from a snapshot. Returns `undefined` for non-existent documents.
392
+ */
254
393
  export type DocumentDataFunction<T> = ((snapshot: QueryDocumentSnapshot<T>) => T) & ((snapshot: DocumentSnapshot<T>) => Maybe<T>);
394
+ /**
395
+ * Function type that extracts data from a snapshot with `id` and `key` fields injected.
396
+ * Returns `undefined` for non-existent documents.
397
+ */
255
398
  export type DocumentDataWithIdAndKeyFunction<T> = ((snapshot: QueryDocumentSnapshot<T>) => DocumentDataWithIdAndKey<T>) & ((snapshot: DocumentSnapshot<T>) => Maybe<DocumentDataWithIdAndKey<T>>);
399
+ /**
400
+ * Returns a data extraction function based on whether `id`/`key` injection is desired.
401
+ *
402
+ * When `withId` is `true`, returns {@link documentDataWithIdAndKey} (a {@link DocumentDataWithIdAndKeyFunction}).
403
+ * When `false`, returns a simple `snapshot.data()` wrapper (a {@link DocumentDataFunction}).
404
+ *
405
+ * Useful for creating reusable mappers when processing arrays of snapshots.
406
+ *
407
+ * @param withId - Whether the returned function should inject `id` and `key` fields
408
+ * @returns A snapshot-to-data extraction function
409
+ */
256
410
  export declare function documentDataFunction<T>(withId: true): DocumentDataWithIdAndKeyFunction<T>;
257
411
  export declare function documentDataFunction<T>(withId: false): DocumentDataFunction<T>;
258
412
  export declare function documentDataFunction<T>(withId: boolean): DocumentDataWithIdAndKeyFunction<T> | DocumentDataFunction<T>;
259
413
  /**
260
- * Creates a DocumentDataWithId from the input DocumentSnapshot. If the data does not exist, returns undefined.
414
+ * Extracts data from a {@link DocumentSnapshot} and mutates it to include `id` and `key` fields.
415
+ *
416
+ * The `id` is set to `snapshot.id` (the document's ID within its collection) and `key` is set
417
+ * to `snapshot.ref.path` (the full Firestore document path). The mutation is performed in-place
418
+ * on the data object returned by `snapshot.data()`.
419
+ *
420
+ * For {@link QueryDocumentSnapshot} inputs, the return value is guaranteed non-nullish.
421
+ * Returns `undefined` if the document does not exist (i.e. `snapshot.data()` returns falsy).
261
422
  *
262
- * @param snapshot
263
- * @returns
423
+ * @param snapshot - The snapshot to extract and augment data from
424
+ * @returns The data object with `id` and `key` fields, or `undefined` if the document doesn't exist
264
425
  */
265
426
  export declare function documentDataWithIdAndKey<T>(snapshot: QueryDocumentSnapshot<T>): DocumentDataWithIdAndKey<T>;
266
427
  export declare function documentDataWithIdAndKey<T>(snapshot: DocumentSnapshot<T>): Maybe<DocumentDataWithIdAndKey<T>>;
267
428
  /**
268
- * Sets the id and key values from the snapshot onto the input data.
429
+ * Mutates the input data object to include `id` and `key` fields from a {@link DocumentSnapshot}.
269
430
  *
270
- * @param data
271
- * @param snapshot
272
- * @returns
431
+ * Sets `data.id` to `snapshot.id` and `data.key` to `snapshot.ref.path`. The data object
432
+ * is modified in-place and also returned for chaining convenience.
433
+ *
434
+ * @param data - The data object to augment (mutated in-place)
435
+ * @param snapshot - Source of the `id` and `key` values
436
+ * @returns The same data object, now typed as {@link DocumentDataWithIdAndKey}
273
437
  */
274
438
  export declare function setIdAndKeyFromSnapshotOnDocumentData<T>(data: T, snapshot: DocumentSnapshot<T>): DocumentDataWithIdAndKey<T>;
275
439
  /**
276
- * Sets the id and key values from the snapshot onto the input data.
440
+ * Mutates the input data object to include `id` and `key` fields from a model reference.
441
+ *
442
+ * Similar to {@link setIdAndKeyFromSnapshotOnDocumentData}, but sources the values from a
443
+ * {@link FirestoreModelKeyRef} & {@link FirestoreModelIdRef} instead of a snapshot.
444
+ * The data object is modified in-place and also returned for chaining convenience.
277
445
  *
278
- * @param data
279
- * @param snapshot
280
- * @returns
446
+ * @param data - The data object to augment (mutated in-place)
447
+ * @param modelRef - Source of the `id` and `key` values
448
+ * @returns The same data object, now typed as {@link DocumentDataWithIdAndKey}
281
449
  */
282
450
  export declare function setIdAndKeyFromKeyIdRefOnDocumentData<T>(data: T, modelRef: FirestoreModelKeyRef & FirestoreModelIdRef): DocumentDataWithIdAndKey<T>;
283
451
  /**
284
- * MappedUseAsyncFunction to load a snapshot from the input document and use it.
452
+ * Fetches a document's snapshot and passes it to a `use` callback, following the {@link UseAsync} pattern.
285
453
  *
286
- * @param document
287
- * @param use
288
- * @param defaultValue
289
- * @returns
454
+ * If `document` is nullish, the `use` callback is not invoked and `defaultValue` is returned instead.
455
+ * If `document` exists but the snapshot is nullish (shouldn't happen in practice), `defaultValue` is also used.
456
+ *
457
+ * @param document - The document to fetch, or nullish to skip
458
+ * @param use - Callback that receives the fetched snapshot and returns a result
459
+ * @param defaultValue - Fallback value when `document` is nullish or the snapshot is unavailable
460
+ * @returns The result of `use`, or the default value
290
461
  */
291
462
  export declare function useDocumentSnapshot<D extends FirestoreDocument<any>, O = void>(document: Maybe<D>, use: UseAsync<DocumentSnapshot<FirestoreDocumentData<D>>, O>, defaultValue?: Maybe<AsyncGetterOrValue<O>>): Promise<Maybe<O>>;
292
463
  /**
293
- * MappedUseAsyncFunction to load snapshot data from the input document and use it.
464
+ * Fetches a document's snapshot data (via `snapshot.data()`) and passes it to a `use` callback.
465
+ *
466
+ * Wraps {@link useDocumentSnapshot} with a mapping step that extracts raw data from the snapshot.
467
+ * If the document doesn't exist (data is `undefined`), the `use` callback is not invoked
468
+ * and `defaultValue` is returned instead.
469
+ *
470
+ * @param document - The document to fetch, or nullish to skip
471
+ * @param use - Callback that receives the snapshot data and returns a result
472
+ * @param defaultValue - Fallback value when the document is nullish or doesn't exist
473
+ * @returns The result of `use`, or the default value
294
474
  */
295
475
  export declare const useDocumentSnapshotData: <D extends FirestoreDocument<any>, O = void>(document: Maybe<D>, use: UseAsync<FirestoreDocumentData<D>, O>, defaultValue?: Maybe<AsyncGetterOrValue<O>>) => Promise<Maybe<O>>;
476
+ /**
477
+ * Extracts the document ID ({@link FirestoreModelId}) from a {@link FirestoreDocument}.
478
+ *
479
+ * Useful as a mapper function, e.g. `documents.map(firestoreModelIdFromDocument)`.
480
+ *
481
+ * @param document - The document to extract the ID from
482
+ * @returns The document's ID (the last segment of its Firestore path)
483
+ */
296
484
  export declare function firestoreModelIdFromDocument<T, D extends FirestoreDocument<T>>(document: D): FirestoreModelId;
485
+ /**
486
+ * Extracts document IDs from an array of {@link FirestoreDocument}s.
487
+ *
488
+ * @param documents - Documents to extract IDs from
489
+ * @returns Array of document IDs in the same order as the input
490
+ */
297
491
  export declare function firestoreModelIdsFromDocuments<T, D extends FirestoreDocument<T>>(documents: D[]): FirestoreModelId[];
492
+ /**
493
+ * Extracts the full Firestore path ({@link FirestoreModelKey}) from a {@link FirestoreDocument}.
494
+ *
495
+ * Useful as a mapper function, e.g. `documents.map(firestoreModelKeyFromDocument)`.
496
+ *
497
+ * @param document - The document to extract the key from
498
+ * @returns The document's full Firestore path (e.g. `'users/abc123'`)
499
+ */
298
500
  export declare function firestoreModelKeyFromDocument<T, D extends FirestoreDocument<T>>(document: D): FirestoreModelKey;
501
+ /**
502
+ * Extracts full Firestore paths from an array of {@link FirestoreDocument}s.
503
+ *
504
+ * @param documents - Documents to extract keys from
505
+ * @returns Array of full Firestore paths in the same order as the input
506
+ */
299
507
  export declare function firestoreModelKeysFromDocuments<T, D extends FirestoreDocument<T>>(documents: D[]): FirestoreModelKey[];
508
+ /**
509
+ * Extracts the {@link DocumentReference} from a {@link FirestoreDocument}.
510
+ *
511
+ * Useful as a mapper function, e.g. `documents.map(documentReferenceFromDocument)`.
512
+ *
513
+ * @param document - The document to extract the reference from
514
+ * @returns The underlying Firestore document reference
515
+ */
300
516
  export declare function documentReferenceFromDocument<T, D extends FirestoreDocument<T>>(document: D): DocumentReference<T>;
517
+ /**
518
+ * Extracts {@link DocumentReference}s from an array of {@link FirestoreDocument}s.
519
+ *
520
+ * @param documents - Documents to extract references from
521
+ * @returns Array of document references in the same order as the input
522
+ */
301
523
  export declare function documentReferencesFromDocuments<T, D extends FirestoreDocument<T>>(documents: D[]): DocumentReference<T>[];