@dereekb/firebase 11.1.7 → 12.0.0

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.
Files changed (87) hide show
  1. package/index.cjs.js +3748 -2018
  2. package/index.esm.d.ts +1 -0
  3. package/index.esm.js +3672 -3107
  4. package/package.json +7 -6
  5. package/src/lib/common/firestore/accessor/accessor.batch.d.ts +12 -0
  6. package/src/lib/common/firestore/accessor/accessor.d.ts +90 -30
  7. package/src/lib/common/firestore/accessor/accessor.default.d.ts +14 -0
  8. package/src/lib/common/firestore/accessor/accessor.transaction.d.ts +15 -0
  9. package/src/lib/common/firestore/accessor/accessor.wrap.d.ts +107 -2
  10. package/src/lib/common/firestore/accessor/context.batch.d.ts +31 -0
  11. package/src/lib/common/firestore/accessor/context.d.ts +28 -5
  12. package/src/lib/common/firestore/accessor/context.default.d.ts +21 -0
  13. package/src/lib/common/firestore/accessor/context.transaction.d.ts +31 -0
  14. package/src/lib/common/firestore/accessor/converter.d.ts +28 -3
  15. package/src/lib/common/firestore/accessor/document.rxjs.d.ts +37 -0
  16. package/src/lib/common/firestore/accessor/document.utility.d.ts +129 -8
  17. package/src/lib/common/firestore/collection/collection.d.ts +116 -8
  18. package/src/lib/common/firestore/collection/collection.group.d.ts +38 -3
  19. package/src/lib/common/firestore/collection/collection.key.d.ts +62 -2
  20. package/src/lib/common/firestore/collection/collection.query.d.ts +168 -8
  21. package/src/lib/common/firestore/collection/collection.single.d.ts +33 -0
  22. package/src/lib/common/firestore/collection/subcollection.d.ts +70 -5
  23. package/src/lib/common/firestore/collection/subcollection.single.d.ts +40 -0
  24. package/src/lib/common/firestore/context.d.ts +154 -5
  25. package/src/lib/common/firestore/query/accumulator.d.ts +78 -5
  26. package/src/lib/common/firestore/query/constraint.d.ts +401 -15
  27. package/src/lib/common/firestore/query/constraint.template.d.ts +133 -40
  28. package/src/lib/common/firestore/query/iterator.d.ts +200 -14
  29. package/src/lib/common/firestore/query/query.d.ts +120 -11
  30. package/src/lib/common/firestore/query/query.iterate.array.d.ts +113 -9
  31. package/src/lib/common/firestore/query/query.iterate.d.ts +136 -13
  32. package/src/lib/common/firestore/query/query.util.d.ts +74 -7
  33. package/src/lib/common/firestore/query/watcher.d.ts +133 -2
  34. package/src/lib/common/firestore/snapshot/snapshot.d.ts +26 -0
  35. package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +513 -3
  36. package/src/lib/common/firestore/snapshot/snapshot.type.d.ts +86 -5
  37. package/src/lib/common/model/function.d.ts +1 -1
  38. package/src/lib/common/storage/driver/accessor.d.ts +0 -1
  39. package/src/lib/common/storage/types.d.ts +0 -1
  40. package/test/CHANGELOG.md +13 -0
  41. package/test/package.json +3 -2
  42. package/test/src/lib/client/firebase.authorized.d.ts +2 -2
  43. package/test/src/lib/client/firebase.authorized.js.map +1 -1
  44. package/test/src/lib/client/firebase.d.ts +13 -13
  45. package/test/src/lib/client/firebase.js +4 -4
  46. package/test/src/lib/client/firebase.js.map +1 -1
  47. package/test/src/lib/client/firestore.mock.item.fixture.authorized.d.ts +2 -2
  48. package/test/src/lib/common/firebase.instance.d.ts +6 -6
  49. package/test/src/lib/common/firebase.instance.js.map +1 -1
  50. package/test/src/lib/common/firestore/firestore.d.ts +1 -1
  51. package/test/src/lib/common/firestore/firestore.instance.d.ts +3 -3
  52. package/test/src/lib/common/firestore/firestore.instance.js.map +1 -1
  53. package/test/src/lib/common/firestore/firestore.js +3 -4
  54. package/test/src/lib/common/firestore/firestore.js.map +1 -1
  55. package/test/src/lib/common/firestore/test.driver.accessor.d.ts +3 -3
  56. package/test/src/lib/common/firestore/test.driver.accessor.js +5 -6
  57. package/test/src/lib/common/firestore/test.driver.accessor.js.map +1 -1
  58. package/test/src/lib/common/firestore/test.driver.query.d.ts +1 -1
  59. package/test/src/lib/common/firestore/test.driver.query.js +14 -10
  60. package/test/src/lib/common/firestore/test.driver.query.js.map +1 -1
  61. package/test/src/lib/common/firestore/test.iterator.d.ts +1 -1
  62. package/test/src/lib/common/firestore/test.iterator.js +1 -2
  63. package/test/src/lib/common/firestore/test.iterator.js.map +1 -1
  64. package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +5 -5
  65. package/test/src/lib/common/mock/mock.item.collection.fixture.js +2 -2
  66. package/test/src/lib/common/mock/mock.item.collection.fixture.js.map +1 -1
  67. package/test/src/lib/common/mock/mock.item.d.ts +5 -5
  68. package/test/src/lib/common/mock/mock.item.id.d.ts +1 -1
  69. package/test/src/lib/common/mock/mock.item.js +19 -19
  70. package/test/src/lib/common/mock/mock.item.js.map +1 -1
  71. package/test/src/lib/common/mock/mock.item.query.d.ts +2 -2
  72. package/test/src/lib/common/mock/mock.item.query.js +3 -4
  73. package/test/src/lib/common/mock/mock.item.query.js.map +1 -1
  74. package/test/src/lib/common/mock/mock.item.service.d.ts +3 -3
  75. package/test/src/lib/common/mock/mock.item.service.js +2 -2
  76. package/test/src/lib/common/mock/mock.item.service.js.map +1 -1
  77. package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +4 -4
  78. package/test/src/lib/common/mock/mock.item.storage.fixture.js +2 -2
  79. package/test/src/lib/common/mock/mock.item.storage.fixture.js.map +1 -1
  80. package/test/src/lib/common/storage/storage.d.ts +1 -1
  81. package/test/src/lib/common/storage/storage.instance.d.ts +3 -3
  82. package/test/src/lib/common/storage/storage.instance.js.map +1 -1
  83. package/test/src/lib/common/storage/storage.js +2 -3
  84. package/test/src/lib/common/storage/storage.js.map +1 -1
  85. package/test/src/lib/common/storage/test.driver.accessor.d.ts +1 -1
  86. package/test/src/lib/common/storage/test.driver.accessor.js +1 -2
  87. package/test/src/lib/common/storage/test.driver.accessor.js.map +1 -1
@@ -6,48 +6,208 @@ import { type FirestoreQueryConstraint } from '../query/constraint';
6
6
  import { type Transaction } from '../types';
7
7
  import { type Observable } from 'rxjs';
8
8
  import { type FirestoreDocumentSnapshotDataPairWithData } from '../accessor';
9
+ /**
10
+ * An executable Firestore query that returns typed document objects.
11
+ *
12
+ * This interface extends the basic FirestoreExecutableQuery with methods that automatically
13
+ * convert Firestore document snapshots to fully-typed application model objects. It provides
14
+ * a fluent API for querying collections and processing the results as either Promises or
15
+ * Observables.
16
+ *
17
+ * @template T - The data type of the documents
18
+ * @template D - The FirestoreDocument type that wraps the data
19
+ *
20
+ * @example
21
+ * // Create a query for active users created in the last 30 days
22
+ * const recentActiveUsers = usersCollection.queryDocument(
23
+ * where('status', '==', 'active'),
24
+ * where('createdAt', '>=', thirtyDaysAgo)
25
+ * );
26
+ *
27
+ * // Get all matching users
28
+ * const users = await recentActiveUsers.getDocs();
29
+ *
30
+ * // Or stream updates in real-time
31
+ * recentActiveUsers.streamDocs().subscribe(users => {
32
+ * console.log('Active users updated:', users);
33
+ * });
34
+ */
9
35
  export interface FirestoreCollectionExecutableDocumentQuery<T, D extends FirestoreDocument<T>> {
36
+ /**
37
+ * The underlying base query that this document query wraps.
38
+ * This gives access to the raw Firestore query functionality if needed.
39
+ */
10
40
  readonly baseQuery: FirestoreExecutableQuery<T>;
11
41
  /**
12
- * Returns the number of result documents.
42
+ * Returns the total number of documents that match this query.
43
+ *
44
+ * This is useful for pagination or checking if results exist without
45
+ * retrieving the full documents.
46
+ *
47
+ * @returns A promise that resolves to the count of matching documents
13
48
  */
14
49
  countDocs(): Promise<number>;
15
50
  /**
16
51
  * Limits the results to a single document, then returns that first/single document if it exists.
52
+ *
53
+ * This is a convenience method for queries where you expect a single result or
54
+ * are only interested in the first match.
55
+ *
56
+ * @param transaction - Optional transaction to perform this operation in
57
+ * @returns A promise that resolves to the first matching document or undefined if none exists
17
58
  */
18
59
  getFirstDoc(transaction?: Transaction): Promise<Maybe<D>>;
19
60
  /**
20
- * Limits the results to a single document, then returns that first/single FirestoreDocumentSnapshotDataPair for the document if it exists.
61
+ * Limits the results to a single document, then returns that first/single
62
+ * FirestoreDocumentSnapshotDataPair for the document if it exists.
63
+ *
64
+ * This provides both the document snapshot and converted data object,
65
+ * giving access to metadata like create/update times while still having
66
+ * the typed document data.
67
+ *
68
+ * @param transaction - Optional transaction to perform this operation in
69
+ * @returns A promise that resolves to the first matching document pair or undefined if none exists
21
70
  */
22
71
  getFirstDocSnapshotDataPair(transaction?: Transaction): Promise<Maybe<FirestoreDocumentSnapshotDataPairWithData<D>>>;
23
72
  /**
24
- * Returns the results in a Promise.
73
+ * Returns all matching documents as a Promise of document array.
74
+ *
75
+ * This retrieves all documents matching the query constraints and converts
76
+ * them to the appropriate document model type.
77
+ *
78
+ * @param transaction - Optional transaction to perform this operation in
79
+ * @returns A promise that resolves to an array of typed documents
25
80
  */
26
81
  getDocs(transaction?: Transaction): Promise<D[]>;
27
82
  /**
28
- * Returns the FirestoreDocumentSnapshotDataPairs results in a Promise.
83
+ * Returns all matching documents as a Promise of document snapshot data pairs.
84
+ *
85
+ * This retrieves all documents matching the query constraints and provides both
86
+ * the raw snapshots and converted document models, useful when you need access
87
+ * to metadata like create/update times.
88
+ *
89
+ * @param transaction - Optional transaction to perform this operation in
90
+ * @returns A promise that resolves to an array of document snapshot data pairs
29
91
  */
30
92
  getDocSnapshotDataPairs(transaction?: Transaction): Promise<FirestoreDocumentSnapshotDataPairWithData<D>[]>;
31
93
  /**
32
- * Streams the results as an Observable.
94
+ * Streams the query results as an Observable that emits whenever the query results change.
95
+ *
96
+ * This sets up a real-time listener for the query and automatically converts
97
+ * snapshots to typed document models. The Observable emits the complete result set
98
+ * each time any document in the set changes.
99
+ *
100
+ * @returns An Observable that emits arrays of typed documents
33
101
  */
34
102
  streamDocs(): Observable<D[]>;
35
103
  /**
36
- * Streams the FirestoreDocumentSnapshotDataPair results as an Observable.
104
+ * Streams the query results as an Observable of document snapshot data pairs.
105
+ *
106
+ * Similar to streamDocs(), but provides both the raw snapshots and converted document
107
+ * models, giving access to metadata while maintaining type safety.
108
+ *
109
+ * @returns An Observable that emits arrays of document snapshot data pairs
37
110
  */
38
111
  streamDocSnapshotDataPairs(): Observable<FirestoreDocumentSnapshotDataPairWithData<D>[]>;
39
112
  /**
40
- * Extend this query by adding additional filters.
113
+ * Extends this query by adding additional filters or constraints.
114
+ *
115
+ * This enables fluent composition of queries by adding constraints incrementally.
116
+ * It returns a new query instance with the combined constraints of the original
117
+ * query plus the new ones.
118
+ *
119
+ * @param queryConstraints - One or more query constraints to apply
120
+ * @returns A new query with the additional constraints applied
121
+ *
122
+ * @example
123
+ * // Start with a basic query
124
+ * let query = usersCollection.queryDocument();
41
125
  *
42
- * @param queryConstraints
126
+ * // Add filters conditionally
127
+ * if (filterByStatus) {
128
+ * query = query.filter(where('status', '==', selectedStatus));
129
+ * }
130
+ *
131
+ * // Add more constraints and execute
132
+ * const result = await query
133
+ * .filter(orderBy('createdAt', 'desc'))
134
+ * .filter(limit(10))
135
+ * .getDocs();
43
136
  */
44
137
  filter(...queryConstraints: ArrayOrValue<FirestoreQueryConstraint>[]): FirestoreCollectionExecutableDocumentQuery<T, D>;
45
138
  }
46
139
  /**
47
140
  * Creates a new FirestoreExecutableQuery from the input constraints for a FirestoreDocument.
141
+ *
142
+ * This factory function type creates document-aware queries by applying constraints and
143
+ * returning an executable query that handles document conversion automatically.
144
+ *
145
+ * @template T - The data type of the documents
146
+ * @template D - The FirestoreDocument type that wraps the data
147
+ *
148
+ * @param queryConstraints - Zero or more constraints to apply to the query
149
+ * @returns An executable document query configured with the specified constraints
150
+ *
151
+ * @example
152
+ * // Type definition of the query factory function
153
+ * const queryUsers: FirestoreCollectionQueryFactoryFunction<UserData, UserDocument> =
154
+ * usersCollection.queryDocument;
155
+ *
156
+ * // Using the factory function to create a query
157
+ * const activeUsersQuery = queryUsers(where('status', '==', 'active'));
48
158
  */
49
159
  export type FirestoreCollectionQueryFactoryFunction<T, D extends FirestoreDocument<T>> = (...queryConstraints: ArrayOrValue<FirestoreQueryConstraint>[]) => FirestoreCollectionExecutableDocumentQuery<T, D>;
160
+ /**
161
+ * Factory for creating document-aware Firestore queries for a collection.
162
+ *
163
+ * This interface provides access to query factory functions that create executable
164
+ * queries that automatically convert Firestore snapshots to typed document models.
165
+ *
166
+ * @template T - The data type of the documents
167
+ * @template D - The FirestoreDocument type that wraps the data
168
+ *
169
+ * @example
170
+ * // A collection with a query factory
171
+ * const usersCollection: FirestoreCollection<UserData, UserDocument> = makeFirestoreCollection({
172
+ * collectionPath: 'users',
173
+ * converter: userConverter
174
+ * });
175
+ *
176
+ * // Use the factory to create a query
177
+ * const activeUsersQuery = usersCollection.queryFactory.queryDocument(
178
+ * where('status', '==', 'active')
179
+ * );
180
+ */
50
181
  export interface FirestoreCollectionQueryFactory<T, D extends FirestoreDocument<T>> {
182
+ /**
183
+ * Factory function for creating document queries with optional constraints.
184
+ * This is the primary method for creating typed queries against a collection.
185
+ */
51
186
  readonly queryDocument: FirestoreCollectionQueryFactoryFunction<T, D>;
52
187
  }
188
+ /**
189
+ * Creates a query factory for Firestore collections that automatically handles document conversion.
190
+ *
191
+ * This factory function bridges the gap between raw Firestore queries and typed document models
192
+ * by wrapping standard query operations with document loading capabilities. It transforms
193
+ * query results from raw Firestore snapshots into fully-typed document model instances.
194
+ *
195
+ * @template T - The data type of the documents
196
+ * @template D - The FirestoreDocument type that wraps the data
197
+ * @param queryFactory - The base query factory for creating raw Firestore queries
198
+ * @param accessorContext - The document accessor context for loading and converting documents
199
+ * @returns A collection query factory for creating document-aware queries
200
+ *
201
+ * @example
202
+ * // Creating a collection query factory
203
+ * const userQueryFactory = firestoreCollectionQueryFactory(
204
+ * userQueryFactory, // Base query factory
205
+ * userAccessorContext // Document accessor context
206
+ * );
207
+ *
208
+ * // Using the factory to create and execute a query
209
+ * const activeUsers = await userQueryFactory
210
+ * .queryDocument(where('status', '==', 'active'))
211
+ * .getDocs();
212
+ */
53
213
  export declare function firestoreCollectionQueryFactory<T, D extends FirestoreDocument<T>>(queryFactory: FirestoreQueryFactory<T>, accessorContext: LimitedFirestoreDocumentAccessorContextExtension<T, D>): FirestoreCollectionQueryFactory<T, D>;
@@ -1,7 +1,40 @@
1
1
  import { type FirestoreDocument, type FirestoreSingleDocumentAccessor, type SingleItemFirestoreCollectionDocumentIdentifierRef } from '../accessor/document';
2
2
  import { type FirestoreCollection, type FirestoreCollectionConfig } from './collection';
3
+ /**
4
+ * Configuration for creating a root-level collection that focuses on a single document.
5
+ *
6
+ * This configuration extends the standard FirestoreCollectionConfig with optional
7
+ * settings for specifying a single document identifier. This is used when you need
8
+ * to work with a specific document in a collection, such as configuration or settings.
9
+ *
10
+ * @template T - The data type of the document
11
+ * @template D - The FirestoreDocument type, defaults to FirestoreDocument<T>
12
+ */
3
13
  export interface RootSingleItemFirestoreCollectionConfig<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends FirestoreCollectionConfig<T, D>, Partial<SingleItemFirestoreCollectionDocumentIdentifierRef> {
4
14
  }
15
+ /**
16
+ * A Firestore collection that provides specialized accessors for working with a single document.
17
+ *
18
+ * This interface combines the capabilities of a standard FirestoreCollection with
19
+ * FirestoreSingleDocumentAccessor, providing convenient methods for working directly
20
+ * with a single document without needing to specify its ID in each call.
21
+ *
22
+ * @template T - The data type of the document
23
+ * @template D - The FirestoreDocument type, defaults to FirestoreDocument<T>
24
+ */
5
25
  export interface RootSingleItemFirestoreCollection<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends FirestoreCollection<T, D>, FirestoreSingleDocumentAccessor<T, D> {
6
26
  }
27
+ /**
28
+ * Creates a root-level Firestore collection focused on a single document.
29
+ *
30
+ * This factory function creates a specialized collection that combines standard collection
31
+ * functionality with convenient accessors for working with a single document. It's particularly
32
+ * useful for application settings, configuration, or any singleton-like data structures
33
+ * that are stored in Firestore.
34
+ *
35
+ * @template T - The data type of the document
36
+ * @template D - The FirestoreDocument type, defaults to FirestoreDocument<T>
37
+ * @param config - Configuration for the single document collection
38
+ * @returns A RootSingleItemFirestoreCollection instance configured for the specified document
39
+ */
7
40
  export declare function makeRootSingleItemFirestoreCollection<T, D extends FirestoreDocument<T> = FirestoreDocument<T>>(config: RootSingleItemFirestoreCollectionConfig<T, D>): RootSingleItemFirestoreCollection<T, D>;
@@ -1,25 +1,90 @@
1
+ /**
2
+ * @module Firestore Subcollections
3
+ *
4
+ * This module provides utilities for working with Firestore subcollections - collections that exist
5
+ * within a specific document rather than at the root level. Subcollections enable hierarchical
6
+ * data modeling in Firestore by allowing documents to contain their own collections.
7
+ *
8
+ * Key features of subcollections:
9
+ * - They provide a natural way to model hierarchical relationships
10
+ * - They establish clear ownership boundaries (parent document owns child documents)
11
+ * - They enable more granular security rules (access to child documents can depend on parent)
12
+ * - They support efficient querying within the context of a specific parent
13
+ *
14
+ * Example hierarchy in Firestore paths:
15
+ * - users/{userId} (parent document)
16
+ * - users/{userId}/posts/{postId} (document in subcollection)
17
+ * - users/{userId}/posts/{postId}/comments/{commentId} (nested subcollection)
18
+ */
1
19
  import { type FirestoreDocument } from '../accessor/document';
2
20
  import { type FirestoreCollection, type FirestoreCollectionConfig } from './collection';
3
21
  /**
4
- * Used for collections that are a subcollection of a document.
22
+ * Configuration for a Firestore subcollection that maintains a reference to its parent document.
23
+ *
24
+ * This configuration extends the standard FirestoreCollectionConfig with a reference to the
25
+ * parent document, establishing a parent-child relationship between documents in different
26
+ * collections. This relationship is used for building proper collection paths and maintaining
27
+ * the document hierarchy.
28
+ *
29
+ * @template T - The data type of documents in the subcollection
30
+ * @template PT - The data type of the parent document
31
+ * @template D - The document type for documents in the subcollection, defaults to FirestoreDocument<T>
32
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
5
33
  */
6
34
  export interface FirestoreCollectionWithParentConfig<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> extends FirestoreCollectionConfig<T, D> {
7
35
  /**
8
- * The parent document.
36
+ * The parent document that contains this subcollection.
37
+ * This reference establishes the hierarchical relationship and is used for path construction
38
+ * and maintaining the document hierarchy context.
9
39
  */
10
40
  readonly parent: PD;
11
41
  }
12
42
  /**
13
- * A FirestoreCollection as a reference to a Subcollection.
43
+ * A FirestoreCollection that represents a subcollection with a reference to its parent document.
44
+ *
45
+ * This interface extends FirestoreCollection to maintain the parent-child relationship
46
+ * between documents. It allows access to documents within the context of their parent,
47
+ * enabling proper path construction and maintaining the document hierarchy.
48
+ *
49
+ * @template T - The data type of documents in the subcollection
50
+ * @template PT - The data type of the parent document
51
+ * @template D - The document type for documents in the subcollection, defaults to FirestoreDocument<T>
52
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
14
53
  */
15
54
  export interface FirestoreCollectionWithParent<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> extends FirestoreCollection<T, D> {
55
+ /**
56
+ * Reference to the parent document that contains this subcollection.
57
+ * This allows navigation up the document hierarchy and provides context
58
+ * for the subcollection's position in the data model.
59
+ */
16
60
  readonly parent: PD;
17
61
  }
18
62
  /**
19
- * A FirestoreCollectionWithParent factory type.
63
+ * A factory function type for creating subcollection instances for a given parent document.
64
+ *
65
+ * This type defines a function that creates a subcollection instance when given a parent document.
66
+ * It's useful for establishing reusable patterns for accessing subcollections across different
67
+ * parent documents of the same type.
68
+ *
69
+ * @template T - The data type of documents in the subcollection
70
+ * @template PT - The data type of the parent document
71
+ * @template D - The document type for documents in the subcollection, defaults to FirestoreDocument<T>
72
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
73
+ * @template C - The specific subcollection type to return, defaults to FirestoreCollectionWithParent<T, PT, D, PD>
20
74
  */
21
75
  export type FirestoreCollectionWithParentFactory<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>, C extends FirestoreCollectionWithParent<T, PT, D, PD> = FirestoreCollectionWithParent<T, PT, D, PD>> = (parent: PD) => C;
22
76
  /**
23
- * Creates a new FirestoreCollectionWithParent from the input config.
77
+ * Creates a new subcollection instance with a reference to its parent document.
78
+ *
79
+ * This factory function creates a subcollection that maintains its relationship to a
80
+ * parent document. The subcollection inherits all the capabilities of a standard
81
+ * collection while also providing access to its parent document context.
82
+ *
83
+ * @template T - The data type of documents in the subcollection
84
+ * @template PT - The data type of the parent document
85
+ * @template D - The document type for documents in the subcollection, defaults to FirestoreDocument<T>
86
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
87
+ * @param config - Configuration for the subcollection, including the parent document reference
88
+ * @returns A subcollection instance linked to the specified parent document
24
89
  */
25
90
  export declare function makeFirestoreCollectionWithParent<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>>(config: FirestoreCollectionWithParentConfig<T, PT, D, PD>): FirestoreCollectionWithParent<T, PT, D, PD>;
@@ -1,7 +1,47 @@
1
1
  import { type FirestoreDocument, type FirestoreSingleDocumentAccessor, type SingleItemFirestoreCollectionDocumentIdentifierRef } from '../accessor/document';
2
2
  import { type FirestoreCollectionWithParent, type FirestoreCollectionWithParentConfig } from './subcollection';
3
+ /**
4
+ * Configuration for a subcollection that focuses on a single document within a parent document.
5
+ *
6
+ * This configuration extends FirestoreCollectionWithParentConfig with an optional
7
+ * specification for a single document identifier. It combines the hierarchical relationship
8
+ * of subcollections with the focused access of single document collections.
9
+ *
10
+ * @template T - The data type of the subcollection document
11
+ * @template PT - The data type of the parent document
12
+ * @template D - The document type for the subcollection document, defaults to FirestoreDocument<T>
13
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
14
+ */
3
15
  export interface SingleItemFirestoreCollectionConfig<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> extends FirestoreCollectionWithParentConfig<T, PT, D, PD>, Partial<SingleItemFirestoreCollectionDocumentIdentifierRef> {
4
16
  }
17
+ /**
18
+ * A subcollection that provides specialized accessors for working with a single document
19
+ * within a parent document context.
20
+ *
21
+ * This interface combines the capabilities of FirestoreCollectionWithParent (which maintains
22
+ * the parent-child relationship) with FirestoreSingleDocumentAccessor (which provides
23
+ * convenient methods for working with a specific document). This allows for direct access
24
+ * to a known document within the subcollection without needing to specify its ID in each call.
25
+ *
26
+ * @template T - The data type of the subcollection document
27
+ * @template PT - The data type of the parent document
28
+ * @template D - The document type for the subcollection document, defaults to FirestoreDocument<T>
29
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
30
+ */
5
31
  export interface SingleItemFirestoreCollection<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> extends FirestoreCollectionWithParent<T, PT, D, PD>, FirestoreSingleDocumentAccessor<T, D> {
6
32
  }
33
+ /**
34
+ * Creates a subcollection that focuses on a single document within a parent document context.
35
+ *
36
+ * This factory function creates a subcollection with specialized accessors for working with
37
+ * a specific document. It combines the hierarchical relationship of parent-child documents
38
+ * with the convenience of direct access to a single, known document in the subcollection.
39
+ *
40
+ * @template T - The data type of the subcollection document
41
+ * @template PT - The data type of the parent document
42
+ * @template D - The document type for the subcollection document, defaults to FirestoreDocument<T>
43
+ * @template PD - The document type for the parent document, defaults to FirestoreDocument<PT>
44
+ * @param config - Configuration for the single document subcollection
45
+ * @returns A subcollection instance with specialized accessors for the single document
46
+ */
7
47
  export declare function makeSingleItemFirestoreCollection<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>>(config: SingleItemFirestoreCollectionConfig<T, PT, D, PD>): SingleItemFirestoreCollection<T, PT, D, PD>;
@@ -5,37 +5,186 @@ import { type WriteBatchFactoryReference, type RunTransactionFactoryReference }
5
5
  import { type DocumentReference, type CollectionReference, type DocumentData, type Firestore, type CollectionGroup } from './types';
6
6
  import { type QueryLikeReferenceRef } from './reference';
7
7
  /**
8
- * A @dereekb/firebase FirestoreContext. Wraps the main Firestore context and the drivers, as well as utility/convenience functions.
8
+ * A high-level context for Firestore operations that wraps the Firestore instance and its drivers.
9
+ *
10
+ * This context provides a unified interface for working with Firestore, offering convenience methods
11
+ * for accessing collections, creating documents, and managing transactions and batches. It serves as
12
+ * the main entry point for Firestore operations throughout the application.
13
+ *
14
+ * The context abstracts away the low-level Firestore implementation details, offering type-safe
15
+ * methods for creating various collection types (standard, group, with parent, single-item) and
16
+ * managing document operations within different execution contexts (standard, transaction, batch).
17
+ *
18
+ * @template F - The Firestore implementation type (defaults to standard Firestore)
9
19
  */
10
20
  export interface FirestoreContext<F extends Firestore = Firestore> extends RunTransactionFactoryReference, WriteBatchFactoryReference {
21
+ /**
22
+ * The underlying Firestore instance.
23
+ */
11
24
  readonly firestore: F;
25
+ /**
26
+ * The Firestore drivers used by this context.
27
+ * Contains implementations for queries, accessories, and other Firestore operations.
28
+ */
12
29
  readonly drivers: FirestoreDrivers;
30
+ /**
31
+ * Gets a reference to a collection at the specified path.
32
+ *
33
+ * @template T - The document data type in the collection
34
+ * @param path - The initial path segment
35
+ * @param pathSegments - Additional path segments
36
+ * @returns A reference to the specified collection
37
+ */
13
38
  collection<T = DocumentData>(path: string, ...pathSegments: string[]): CollectionReference<T>;
39
+ /**
40
+ * Gets a query for all documents in collections with the specified ID.
41
+ *
42
+ * @template T - The document data type in the collection group
43
+ * @param collectionId - The collection ID to query across all document paths
44
+ * @returns A query across all collections with the given ID
45
+ */
14
46
  collectionGroup<T = DocumentData>(collectionId: string): CollectionGroup<T>;
47
+ /**
48
+ * Gets a reference to a subcollection within a document.
49
+ *
50
+ * @template T - The document data type in the subcollection
51
+ * @param parent - The parent document reference
52
+ * @param path - The initial path segment
53
+ * @param pathSegments - Additional path segments
54
+ * @returns A reference to the specified subcollection
55
+ */
15
56
  subcollection<T = DocumentData>(parent: DocumentReference, path: string, ...pathSegments: string[]): CollectionReference<T>;
57
+ /**
58
+ * Creates a FirestoreCollection for working with documents in a collection.
59
+ *
60
+ * @template T - The document data type
61
+ * @template D - The FirestoreDocument implementation type
62
+ * @param config - Configuration for the collection
63
+ * @returns A FirestoreCollection instance for the specified collection
64
+ */
16
65
  firestoreCollection<T, D extends FirestoreDocument<T>>(config: FirestoreContextFirestoreCollectionConfig<T, D>): FirestoreCollection<T, D>;
66
+ /**
67
+ * Creates a RootSingleItemFirestoreCollection for working with a single document in a collection.
68
+ *
69
+ * @template T - The document data type
70
+ * @template D - The FirestoreDocument implementation type
71
+ * @param config - Configuration for the collection
72
+ * @returns A RootSingleItemFirestoreCollection instance
73
+ */
17
74
  rootSingleItemFirestoreCollection<T, D extends FirestoreDocument<T>>(config: FirestoreContextFirestoreCollectionConfig<T, D>): RootSingleItemFirestoreCollection<T, D>;
75
+ /**
76
+ * Creates a FirestoreCollectionGroup for working with documents across collections with the same ID.
77
+ *
78
+ * @template T - The document data type
79
+ * @template D - The FirestoreDocument implementation type
80
+ * @param config - Configuration for the collection group
81
+ * @returns A FirestoreCollectionGroup instance for the specified collection ID
82
+ */
18
83
  firestoreCollectionGroup<T, D extends FirestoreDocument<T>>(config: FirestoreContextFirestoreCollectionGroupConfig<T, D>): FirestoreCollectionGroup<T, D>;
84
+ /**
85
+ * Creates a FirestoreCollectionWithParent for working with documents in a subcollection.
86
+ *
87
+ * @template T - The document data type
88
+ * @template PT - The parent document data type
89
+ * @template D - The FirestoreDocument implementation type
90
+ * @template PD - The parent FirestoreDocument implementation type
91
+ * @param config - Configuration for the collection with parent
92
+ * @returns A FirestoreCollectionWithParent instance for the specified subcollection
93
+ */
19
94
  firestoreCollectionWithParent<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>>(config: FirestoreContextFirestoreCollectionWithParentConfig<T, PT, D, PD>): FirestoreCollectionWithParent<T, PT, D, PD>;
95
+ /**
96
+ * Creates a SingleItemFirestoreCollection for working with a single document in a subcollection.
97
+ *
98
+ * @template T - The document data type
99
+ * @template PT - The parent document data type
100
+ * @template D - The FirestoreDocument implementation type
101
+ * @template PD - The parent FirestoreDocument implementation type
102
+ * @param config - Configuration for the single-item collection
103
+ * @returns A SingleItemFirestoreCollection instance for the specified document
104
+ */
20
105
  singleItemFirestoreCollection<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>>(config: FirestoreContextSingleItemFirestoreCollectionConfig<T, PT, D, PD>): SingleItemFirestoreCollection<T, PT, D, PD>;
21
106
  }
107
+ /**
108
+ * Configuration for creating a FirestoreCollection through a FirestoreContext.
109
+ *
110
+ * This type omits driver-related properties from FirestoreCollectionConfig since they will be
111
+ * automatically provided by the FirestoreContext when creating the collection.
112
+ *
113
+ * @template T - The document data type in the collection
114
+ * @template D - The FirestoreDocument implementation type
115
+ */
22
116
  export type FirestoreContextFirestoreCollectionConfig<T, D extends FirestoreDocument<T>> = Omit<FirestoreCollectionConfig<T, D>, 'firestoreDriverIdentifier' | 'firestoreDriverType' | 'firestoreQueryDriver' | 'firestoreAccessorDriver'>;
117
+ /**
118
+ * Configuration for creating a RootSingleItemFirestoreCollection through a FirestoreContext.
119
+ *
120
+ * This configuration extends the standard collection config and optionally allows specifying
121
+ * a custom document identifier for the single item in the collection.
122
+ *
123
+ * @template T - The document data type
124
+ * @template D - The FirestoreDocument implementation type
125
+ */
23
126
  export interface FirestoreContextRootSingleItemFirestoreCollectionConfig<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends FirestoreContextFirestoreCollectionConfig<T, D>, Partial<SingleItemFirestoreCollectionDocumentIdentifierRef> {
24
127
  }
128
+ /**
129
+ * Configuration for creating a FirestoreCollectionGroup through a FirestoreContext.
130
+ *
131
+ * Unlike standard collection configurations, collection group configs use a queryLike reference
132
+ * instead of a collection reference since they span multiple collections with the same ID.
133
+ *
134
+ * @template T - The document data type in the collection group
135
+ * @template D - The FirestoreDocument implementation type
136
+ */
25
137
  export type FirestoreContextFirestoreCollectionGroupConfig<T, D extends FirestoreDocument<T>> = Omit<FirestoreContextFirestoreCollectionConfig<T, D>, 'collection'> & QueryLikeReferenceRef<T>;
138
+ /**
139
+ * Configuration for creating a FirestoreCollectionWithParent through a FirestoreContext.
140
+ *
141
+ * This configuration extends the standard collection config but uses a parent document reference
142
+ * instead of a direct collection reference, enabling access to subcollections within documents.
143
+ *
144
+ * @template T - The document data type in the subcollection
145
+ * @template PT - The parent document data type
146
+ * @template D - The FirestoreDocument implementation type for subcollection documents
147
+ * @template PD - The FirestoreDocument implementation type for the parent document
148
+ */
26
149
  export interface FirestoreContextFirestoreCollectionWithParentConfig<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> extends Omit<FirestoreContextFirestoreCollectionConfig<T, D>, 'queryLike'> {
150
+ /**
151
+ * The parent document that contains the subcollection.
152
+ */
27
153
  readonly parent: PD;
28
154
  }
155
+ /**
156
+ * Configuration for creating a SingleItemFirestoreCollection through a FirestoreContext.
157
+ *
158
+ * This configuration extends the collection with parent config and optionally allows specifying
159
+ * a custom document identifier for the single item in the subcollection.
160
+ *
161
+ * @template T - The document data type in the subcollection
162
+ * @template PT - The parent document data type
163
+ * @template D - The FirestoreDocument implementation type for subcollection documents
164
+ * @template PD - The FirestoreDocument implementation type for the parent document
165
+ */
29
166
  export interface FirestoreContextSingleItemFirestoreCollectionConfig<T, PT, D extends FirestoreDocument<T> = FirestoreDocument<T>, PD extends FirestoreDocument<PT> = FirestoreDocument<PT>> extends FirestoreContextFirestoreCollectionWithParentConfig<T, PT, D, PD>, Partial<SingleItemFirestoreCollectionDocumentIdentifierRef> {
30
167
  }
31
168
  /**
32
- * Factory function for generating a FirestoreContext given the input Firestore.
169
+ * Factory function type for creating FirestoreContext instances.
170
+ *
171
+ * Takes a Firestore instance and returns a fully configured FirestoreContext that wraps
172
+ * the instance and provides additional functionality through the context interface.
173
+ *
174
+ * @template F - The Firestore implementation type
175
+ * @param firestore - The Firestore instance to wrap
176
+ * @returns A FirestoreContext instance for the specified Firestore
33
177
  */
34
178
  export type FirestoreContextFactory<F extends Firestore = Firestore> = (firestore: F) => FirestoreContext;
35
179
  /**
36
- * Creates a new FirestoreContextFactory given the input FirestoreDrivers.
180
+ * Creates a factory function for generating FirestoreContext instances.
181
+ *
182
+ * This function takes a set of FirestoreDrivers and returns a factory function that can
183
+ * create FirestoreContext instances for specific Firestore instances. The resulting contexts
184
+ * will use the provided drivers for all Firestore operations.
37
185
  *
38
- * @param drivers
39
- * @returns
186
+ * @template F - The Firestore implementation type
187
+ * @param drivers - The Firestore drivers to use in created contexts
188
+ * @returns A factory function that creates FirestoreContext instances
40
189
  */
41
190
  export declare function firestoreContextFactory<F extends Firestore = Firestore>(drivers: FirestoreDrivers): FirestoreContextFactory<F>;