@dereekb/firebase 13.0.5 → 13.0.7
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.
- package/index.cjs.js +575 -146
- package/index.cjs.js.map +1 -1
- package/index.esm.js +573 -149
- package/index.esm.js.map +1 -1
- package/package.json +5 -5
- package/src/lib/common/firestore/accessor/document.rxjs.d.ts +55 -3
- package/src/lib/common/firestore/accessor/document.utility.d.ts +439 -128
- package/src/lib/common/firestore/query/constraint.d.ts +27 -22
- package/src/lib/common/firestore/query/constraint.template.d.ts +48 -32
- package/src/lib/common/firestore/query/iterator.d.ts +58 -2
- package/src/lib/common/firestore/query/query.iterate.d.ts +300 -96
- package/test/index.cjs.js +824 -15
- package/test/index.esm.js +826 -18
- package/test/package.json +6 -6
- package/test/src/lib/common/firestore/index.d.ts +1 -0
- package/test/src/lib/common/firestore/test.driver.utility.d.ts +7 -0
|
@@ -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
|
|
6
|
+
* Creates an array of new {@link FirestoreDocument} instances without persisting them to Firestore.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
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
|
-
*
|
|
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
|
-
*
|
|
22
|
+
* Number of documents to create.
|
|
24
23
|
*/
|
|
25
24
|
readonly count: number;
|
|
26
25
|
/**
|
|
27
|
-
* Optional override
|
|
28
|
-
*
|
|
26
|
+
* Optional factory override for creating new document instances.
|
|
27
|
+
*
|
|
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`.
|
|
29
31
|
*
|
|
30
|
-
* @param documentAccessor - The
|
|
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
|
-
*
|
|
37
|
+
* Called for each document to produce its initial data.
|
|
36
38
|
*
|
|
37
|
-
* If
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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 -
|
|
42
|
-
* @param document - The document instance
|
|
43
|
-
* @returns
|
|
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
|
|
50
|
+
* Creates and optionally persists multiple Firestore documents in sequence.
|
|
49
51
|
*
|
|
50
|
-
* For each
|
|
51
|
-
* 1.
|
|
52
|
-
* 2.
|
|
53
|
-
* 3. If init returns data,
|
|
54
|
-
* 4.
|
|
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
|
|
55
57
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @param documentAccessor -
|
|
59
|
-
* @param make -
|
|
60
|
-
* @returns
|
|
58
|
+
* Documents are created sequentially (not in parallel) to allow index-dependent logic.
|
|
59
|
+
*
|
|
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
|
-
*
|
|
66
|
+
* Fetches {@link DocumentSnapshot}s for multiple documents in parallel using {@link runAsyncTasksForValues}.
|
|
65
67
|
*
|
|
66
|
-
*
|
|
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
|
-
* @
|
|
69
|
-
* @
|
|
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
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* This allows keeping track of both the document reference and its data.
|
|
76
|
+
* Pairs a {@link FirestoreDocument} instance with its fetched {@link DocumentSnapshot}.
|
|
77
77
|
*
|
|
78
|
-
*
|
|
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
|
|
82
|
+
/** The document instance used to fetch the snapshot. */
|
|
82
83
|
readonly document: D;
|
|
83
|
-
/** The
|
|
84
|
+
/** The fetched snapshot reflecting the document's current state in Firestore. */
|
|
84
85
|
readonly snapshot: DocumentSnapshot<FirestoreDocumentData<D>>;
|
|
85
86
|
};
|
|
86
87
|
/**
|
|
87
|
-
*
|
|
88
|
+
* Fetches the current snapshot of a single document and pairs it with the document instance.
|
|
88
89
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
104
|
-
* @
|
|
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
|
-
*
|
|
102
|
+
* Combines a {@link FirestoreDocument}, its {@link DocumentSnapshot}, and extracted data with `id`/`key` fields.
|
|
110
103
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
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
|
|
109
|
+
/** The document instance used to fetch the snapshot. */
|
|
118
110
|
readonly document: D;
|
|
119
|
-
/** The
|
|
111
|
+
/** The fetched snapshot reflecting the document's current state in Firestore. */
|
|
120
112
|
readonly snapshot: DocumentSnapshot<FirestoreDocumentData<D>>;
|
|
121
|
-
/** The
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
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
|
-
*
|
|
126
|
+
* Fetches a document's snapshot, extracts its data with `id`/`key` fields, and returns all three as a triplet.
|
|
138
127
|
*
|
|
139
|
-
*
|
|
140
|
-
* and
|
|
141
|
-
*
|
|
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
|
-
*
|
|
133
|
+
* Fetches snapshot-data triplets for multiple documents in parallel.
|
|
149
134
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
135
|
+
* Processes up to 200 documents concurrently via {@link runAsyncTasksForValues}.
|
|
136
|
+
* The returned array preserves the same ordering as the input.
|
|
152
137
|
*
|
|
153
|
-
* @
|
|
154
|
-
* @
|
|
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
|
-
*
|
|
143
|
+
* Fetches snapshot-data triplets for multiple documents and filters out those that don't exist in Firestore.
|
|
160
144
|
*
|
|
161
|
-
*
|
|
162
|
-
* only
|
|
145
|
+
* Convenience wrapper around {@link getDocumentSnapshotDataPairs} that removes entries where `data` is nullish,
|
|
146
|
+
* returning only {@link FirestoreDocumentSnapshotDataPairWithData} results.
|
|
163
147
|
*
|
|
164
|
-
* @
|
|
165
|
-
* @
|
|
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
|
-
*
|
|
200
|
+
* Extracts data from an array of {@link DocumentSnapshot}s, filtering out snapshots for non-existent documents.
|
|
181
201
|
*
|
|
182
|
-
* @
|
|
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}.
|
|
204
|
+
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
302
|
+
* Creates a {@link FirestoreDocumentLoader} from a {@link LimitedFirestoreDocumentAccessorContextExtension}.
|
|
202
303
|
*
|
|
203
|
-
*
|
|
204
|
-
* @
|
|
304
|
+
* The returned loader resolves the appropriate accessor based on whether a transaction is provided,
|
|
305
|
+
* then delegates to {@link loadDocumentsForDocumentReferences}.
|
|
306
|
+
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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}.
|
|
217
330
|
*
|
|
218
|
-
* @
|
|
219
|
-
* @
|
|
331
|
+
* Also satisfies the {@link FirestoreQueryDocumentSnapshotPairsLoader} type since the implementation
|
|
332
|
+
* handles both {@link DocumentSnapshot} and {@link QueryDocumentSnapshot} inputs.
|
|
333
|
+
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
364
|
+
* Alias for {@link firestoreDocumentSnapshotPairsLoader}, typed specifically as a {@link FirestoreQueryDocumentSnapshotPairsLoader}.
|
|
237
365
|
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
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
|
-
*
|
|
371
|
+
* Extracts data from a {@link DocumentSnapshot}, optionally injecting `id` and `key` fields.
|
|
244
372
|
*
|
|
245
|
-
* @
|
|
246
|
-
*
|
|
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,226 @@ 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
|
-
*
|
|
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()`.
|
|
261
419
|
*
|
|
262
|
-
* @
|
|
263
|
-
*
|
|
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).
|
|
422
|
+
*
|
|
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
|
-
*
|
|
429
|
+
* Mutates the input data object to include `id` and `key` fields from a {@link DocumentSnapshot}.
|
|
430
|
+
*
|
|
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.
|
|
269
433
|
*
|
|
270
|
-
* @param data
|
|
271
|
-
* @param snapshot
|
|
272
|
-
* @returns
|
|
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
|
-
*
|
|
440
|
+
* Mutates the input data object to include `id` and `key` fields from a model reference.
|
|
277
441
|
*
|
|
278
|
-
* @
|
|
279
|
-
* @
|
|
280
|
-
*
|
|
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.
|
|
445
|
+
*
|
|
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
|
-
*
|
|
452
|
+
* Fetches a document's snapshot and passes it to a `use` callback, following the {@link UseAsync} pattern.
|
|
453
|
+
*
|
|
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.
|
|
285
456
|
*
|
|
286
|
-
* @param document
|
|
287
|
-
* @param use
|
|
288
|
-
* @param defaultValue
|
|
289
|
-
* @returns
|
|
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
|
-
*
|
|
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>[];
|
|
524
|
+
/**
|
|
525
|
+
* An in-memory snapshot cache backed by a {@link LimitedFirestoreDocumentAccessor} that deduplicates
|
|
526
|
+
* Firestore reads for the same document key within a single operation scope.
|
|
527
|
+
*
|
|
528
|
+
* The cache is keyed by {@link FirestoreModelKey} (full Firestore path) and stores the in-flight or
|
|
529
|
+
* resolved {@link FirestoreDocumentSnapshotDataPair} promises. This ensures that concurrent or repeated
|
|
530
|
+
* requests for the same document reuse a single Firestore read.
|
|
531
|
+
*
|
|
532
|
+
* Does not implement {@link LimitedFirestoreDocumentAccessor} itself — it is a higher-level abstraction
|
|
533
|
+
* that wraps an accessor to provide cached snapshot reads. The underlying accessor is exposed via
|
|
534
|
+
* the {@link accessor} property for direct use when needed.
|
|
535
|
+
*
|
|
536
|
+
* Useful in batch processing or fan-out scenarios where multiple code paths may reference the same
|
|
537
|
+
* documents and you want to avoid redundant reads without manual deduplication.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
|
|
542
|
+
*
|
|
543
|
+
* // Both calls resolve from a single Firestore read
|
|
544
|
+
* const [pair1, pair2] = await Promise.all([
|
|
545
|
+
* cache.getDocumentSnapshotDataPairForKey('users/abc123'),
|
|
546
|
+
* cache.getDocumentSnapshotDataPairForKey('users/abc123')
|
|
547
|
+
* ]);
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
export interface LimitedFirestoreDocumentAccessorSnapshotCache<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> {
|
|
551
|
+
/**
|
|
552
|
+
* The underlying accessor used to load documents and fetch snapshots.
|
|
553
|
+
*/
|
|
554
|
+
readonly accessor: LimitedFirestoreDocumentAccessor<T, D>;
|
|
555
|
+
/**
|
|
556
|
+
* Fetches or returns the cached {@link FirestoreDocumentSnapshotDataPair} for the given key.
|
|
557
|
+
*
|
|
558
|
+
* @param key - Full Firestore document path (e.g. `'users/abc123'`)
|
|
559
|
+
* @returns The document, its snapshot, and extracted data (data may be `undefined` if the document doesn't exist)
|
|
560
|
+
*/
|
|
561
|
+
getDocumentSnapshotDataPairForKey(key: FirestoreModelKey): Promise<FirestoreDocumentSnapshotDataPair<D>>;
|
|
562
|
+
/**
|
|
563
|
+
* Fetches or returns cached {@link FirestoreDocumentSnapshotDataPair}s for multiple keys.
|
|
564
|
+
*
|
|
565
|
+
* Each key is resolved independently through the cache, so previously fetched documents are not re-read.
|
|
566
|
+
*
|
|
567
|
+
* @param keys - Full Firestore document paths
|
|
568
|
+
* @returns Pairs in the same order as the input keys
|
|
569
|
+
*/
|
|
570
|
+
getDocumentSnapshotDataPairsForKeys(keys: FirestoreModelKey[]): Promise<FirestoreDocumentSnapshotDataPair<D>[]>;
|
|
571
|
+
/**
|
|
572
|
+
* Fetches or returns cached pairs for multiple keys, filtering out non-existent documents.
|
|
573
|
+
*
|
|
574
|
+
* Convenience method that delegates to {@link getDocumentSnapshotDataPairsForKeys} and removes entries
|
|
575
|
+
* where `data` is nullish, returning only {@link FirestoreDocumentSnapshotDataPairWithData} results.
|
|
576
|
+
*
|
|
577
|
+
* @param keys - Full Firestore document paths
|
|
578
|
+
* @returns Pairs for existing documents only, in their original relative order
|
|
579
|
+
*/
|
|
580
|
+
getDocumentSnapshotDataPairsWithDataForKeys(keys: FirestoreModelKey[]): Promise<FirestoreDocumentSnapshotDataPairWithData<D>[]>;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Creates a {@link LimitedFirestoreDocumentAccessorSnapshotCache} that wraps the given accessor
|
|
584
|
+
* with an in-memory {@link Map} cache so that repeated loads for the same key return the cached
|
|
585
|
+
* promise instead of re-reading from Firestore.
|
|
586
|
+
*
|
|
587
|
+
* The cache stores the promise itself (not the resolved value), which means concurrent requests
|
|
588
|
+
* for the same key that arrive before the first read completes will also be deduplicated.
|
|
589
|
+
*
|
|
590
|
+
* The cache lives for the lifetime of the returned object and is never invalidated, so this is
|
|
591
|
+
* best suited for short-lived scopes (e.g. a single request or batch operation) where stale reads
|
|
592
|
+
* are acceptable.
|
|
593
|
+
*
|
|
594
|
+
* @param accessor - The accessor to wrap with caching behavior
|
|
595
|
+
* @returns A {@link LimitedFirestoreDocumentAccessorSnapshotCache} backed by the given accessor
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const cache = limitedFirestoreDocumentAccessorSnapshotCache(accessor);
|
|
600
|
+
*
|
|
601
|
+
* // First call reads from Firestore; second call returns cached result
|
|
602
|
+
* const pair = await cache.getDocumentSnapshotDataPairForKey('users/abc123');
|
|
603
|
+
* const samePair = await cache.getDocumentSnapshotDataPairForKey('users/abc123');
|
|
604
|
+
*
|
|
605
|
+
* // Batch fetch with automatic deduplication
|
|
606
|
+
* const pairs = await cache.getDocumentSnapshotDataPairsWithDataForKeys(['users/abc', 'users/def']);
|
|
607
|
+
*
|
|
608
|
+
* // Access the underlying accessor directly
|
|
609
|
+
* const doc = cache.accessor.loadDocumentForKey('users/xyz');
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
export declare function limitedFirestoreDocumentAccessorSnapshotCache<T, D extends FirestoreDocument<T> = FirestoreDocument<T>>(accessor: LimitedFirestoreDocumentAccessor<T, D>): LimitedFirestoreDocumentAccessorSnapshotCache<T, D>;
|