@dereekb/firebase 11.1.8 → 12.0.1

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 +3749 -2018
  2. package/index.esm.d.ts +1 -0
  3. package/index.esm.js +3673 -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/firebase",
3
- "version": "11.1.8",
3
+ "version": "12.0.1",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -27,13 +27,14 @@
27
27
  "@dereekb/model": "*",
28
28
  "@dereekb/date": "*",
29
29
  "rxjs": "^7.5.0",
30
- "firebase": "^10.5.0",
31
- "ts-essentials": "^9.1.2",
30
+ "firebase": "^11.0.0",
32
31
  "class-transformer": "^0.5.1",
33
32
  "class-validator": "^0.14.0",
34
- "date-fns": "^2.30.0"
33
+ "ts-essentials": "^9.1.2",
34
+ "date-fns": "^3.0.0"
35
35
  },
36
36
  "dependencies": {},
37
37
  "module": "./index.esm.js",
38
- "main": "./index.cjs.js"
39
- }
38
+ "main": "./index.cjs.js",
39
+ "types": "./index.esm.d.ts"
40
+ }
@@ -1,3 +1,15 @@
1
1
  import { type WriteBatch } from '../types';
2
2
  import { type FirestoreDocumentDataAccessorFactory } from './accessor';
3
+ /**
4
+ * Factory function type for creating document accessor factories that operate within a write batch.
5
+ *
6
+ * This is a higher-order factory that takes a Firestore WriteBatch and returns a document
7
+ * accessor factory. All document accessors created by the returned factory will perform
8
+ * their write operations as part of the specified batch, providing atomicity guarantees
9
+ * across multiple documents and operations.
10
+ *
11
+ * @template T - The document data type that accessors will work with
12
+ * @param writeBatch - The Firestore write batch to execute operations within
13
+ * @returns A factory for creating document accessors that operate within the specified write batch
14
+ */
3
15
  export type WriteBatchAccessorFactory = <T>(writeBatch: WriteBatch) => FirestoreDocumentDataAccessorFactory<T>;
@@ -3,20 +3,43 @@ import { type WriteResult, type SnapshotOptions, type DocumentReference, type Do
3
3
  import { type Observable, type OperatorFunction } from 'rxjs';
4
4
  import { type DocumentReferenceRef } from '../reference';
5
5
  import { type PickProperties } from 'ts-essentials';
6
+ /**
7
+ * Parameters for document deletion operations.
8
+ */
6
9
  export interface FirestoreDocumentDeleteParams {
10
+ /**
11
+ * Precondition that must be met for the operation to succeed.
12
+ * Can be used to check document exists or has a specific update time.
13
+ */
7
14
  readonly precondition?: Precondition;
8
15
  }
16
+ /**
17
+ * Parameters for document update operations.
18
+ */
9
19
  export interface FirestoreDocumentUpdateParams {
20
+ /**
21
+ * Precondition that must be met for the operation to succeed.
22
+ * Can be used to check document exists or has a specific update time.
23
+ */
10
24
  readonly precondition?: Precondition;
11
25
  }
12
26
  /**
13
- * Used for performing increment updates.
27
+ * Used for performing increment operations on numeric fields.
28
+ *
29
+ * Represents a partial object where keys correspond to numeric fields in the document
30
+ * and values represent the amount to increment each field by.
14
31
  *
15
- * Is an object that contains the amount to increment.
32
+ * @template T - The document type containing numeric fields to increment
16
33
  */
17
34
  export type FirestoreAccessorIncrementUpdate<T> = Partial<KeyValueTransformMap<PickProperties<T, Maybe<number> | number>, number>>;
18
35
  /**
19
- * Firestore database accessor instance used to retrieve and make changes to items in the database.
36
+ * Interface for accessing and modifying a Firestore document.
37
+ *
38
+ * Provides methods for reading, creating, updating, and deleting document data,
39
+ * as well as streaming document snapshots for real-time updates.
40
+ *
41
+ * @template T - The document data type that this accessor will work with
42
+ * @template D - The raw document data type in Firestore (defaults to DocumentData)
20
43
  */
21
44
  export interface FirestoreDocumentDataAccessor<T, D = DocumentData> extends DocumentReferenceRef<T> {
22
45
  /**
@@ -72,10 +95,26 @@ export interface FirestoreDocumentDataAccessor<T, D = DocumentData> extends Docu
72
95
  */
73
96
  increment(data: FirestoreAccessorIncrementUpdate<T>, params?: FirestoreDocumentUpdateParams): Promise<WriteResult | void>;
74
97
  }
98
+ /**
99
+ * Function signature for creating a document.
100
+ *
101
+ * @template T - The document data type
102
+ */
75
103
  export type FirestoreDocumentDataAccessorCreateFunction<T> = (data: WithFieldValue<T>) => Promise<void | WriteResult>;
104
+ /**
105
+ * Function signature for setting document data with optional merge settings.
106
+ *
107
+ * @template T - The document data type
108
+ */
76
109
  export type FirestoreDocumentDataAccessorSetFunction<T> = (data: PartialWithFieldValue<T> | WithFieldValue<T>, options?: SetOptions) => Promise<void | WriteResult>;
77
110
  /**
78
- * Contextual interface used for making a FirestoreDocumentModifier for a specific document.
111
+ * Factory interface for creating document accessors for specific document references.
112
+ *
113
+ * Provides a mechanism to create data accessors tailored to specific document references,
114
+ * enabling consistent access patterns across multiple documents.
115
+ *
116
+ * @template T - The document data type that accessors will work with
117
+ * @template D - The raw document data type in Firestore (defaults to DocumentData)
79
118
  */
80
119
  export interface FirestoreDocumentDataAccessorFactory<T, D = DocumentData> {
81
120
  /**
@@ -85,64 +124,85 @@ export interface FirestoreDocumentDataAccessorFactory<T, D = DocumentData> {
85
124
  */
86
125
  accessorFor(ref: DocumentReference<T>): FirestoreDocumentDataAccessor<T, D>;
87
126
  }
127
+ /**
128
+ * Enumeration of methods for retrieving document data.
129
+ */
88
130
  export declare enum FirestoreAccessorStreamMode {
89
131
  /**
90
- *
132
+ * Continuous stream of document snapshots that updates in real-time.
91
133
  */
92
134
  STREAM = 0,
93
135
  /**
94
- *
136
+ * One-time retrieval of the current document snapshot.
95
137
  */
96
138
  GET = 1
97
139
  }
98
140
  /**
99
- * Retrieves a DocumentSnapshot's data observable using the input stream mode.
141
+ * Creates an Observable that emits the document data from snapshots based on the specified stream mode.
100
142
  *
101
- * @param accessor
102
- * @param mode
103
- * @returns
143
+ * @template T - The document data type
144
+ * @param accessor - The document accessor to retrieve snapshots from
145
+ * @param mode - Whether to use a one-time GET or continuous STREAM mode
146
+ * @param options - Options for how to format the document data
147
+ * @returns An Observable that emits the document data or undefined if the document doesn't exist
104
148
  */
105
149
  export declare function snapshotStreamDataForAccessor<T>(accessor: FirestoreDocumentDataAccessor<T>, mode: FirestoreAccessorStreamMode, options?: SnapshotOptions): Observable<T | undefined>;
106
150
  /**
107
- * Retrieves a DocumentSnapshot observable using the input stream mode.
151
+ * Creates an Observable that emits DocumentSnapshots based on the specified stream mode.
108
152
  *
109
- * @param accessor
110
- * @param mode
111
- * @returns
153
+ * @template T - The document data type
154
+ * @param accessor - The document accessor to retrieve snapshots from
155
+ * @param mode - Whether to use a one-time GET or continuous STREAM mode
156
+ * @returns An Observable that emits DocumentSnapshots
112
157
  */
113
158
  export declare function snapshotStreamForAccessor<T>(accessor: FirestoreDocumentDataAccessor<T>, mode: FirestoreAccessorStreamMode): Observable<DocumentSnapshot<T>>;
114
159
  /**
115
- * Maps data from the given snapshot stream.
160
+ * Creates an Observable that emits document data from a stream of DocumentSnapshots.
116
161
  *
117
- * Maybe values are filtered from the stream until data is provided.
162
+ * Filters out null/undefined values from the stream (documents that don't exist).
118
163
  *
119
- * @param stream
120
- * @param options
121
- * @returns
164
+ * @template T - The document data type
165
+ * @param stream - Observable that emits DocumentSnapshots
166
+ * @param options - Options for how to format the document data
167
+ * @returns An Observable that emits document data, filtering out non-existent documents
122
168
  */
123
169
  export declare function dataFromSnapshotStream<T>(stream: Observable<DocumentSnapshot<T>>, options?: SnapshotOptions): Observable<T>;
124
170
  /**
125
- * OperatorFunction to map data from the snapshot.
171
+ * Creates an RxJS operator that transforms DocumentSnapshots into their data.
126
172
  *
127
- * @param options
128
- * @returns
173
+ * @template T - The document data type
174
+ * @param options - Options for how to format the document data
175
+ * @returns An operator that transforms DocumentSnapshots into document data (or undefined if the document doesn't exist)
129
176
  */
130
177
  export declare function mapDataFromSnapshot<T>(options?: SnapshotOptions): OperatorFunction<DocumentSnapshot<T>, Maybe<T>>;
131
178
  /**
132
- * Updates the target object using the input data that uses the input converter to build data suitable for the update function.
179
+ * Function that updates a document using a data converter to transform the input data.
133
180
  *
134
- * If the input data after conversion is empty then returns void.
181
+ * The function handles:
182
+ * - Converting the input data to Firestore format
183
+ * - Skipping updates if the converted data is empty
184
+ * - Applying preconditions to the update operation
135
185
  *
136
- * If the target object does not exist, this will fail.
186
+ * Note: If the target document doesn't exist, the update will fail.
137
187
  *
138
- * @param data
188
+ * @template T - The document data type
189
+ * @param data - The partial data to update in the document
190
+ * @param params - Optional parameters for the update operation
191
+ * @returns A promise that resolves with the WriteResult or void
139
192
  */
140
193
  export type UpdateWithAccessorUpdateAndConverterFunction<T> = (data: Partial<T>, params?: FirestoreDocumentUpdateParams) => Promise<WriteResult | void>;
141
194
  /**
142
- * Creates an UpdateWithAccessorUpdateAndConverterFunction.
195
+ * Creates a function that updates a document using a data converter.
196
+ *
197
+ * The created function:
198
+ * - Filters out undefined values from the input data
199
+ * - Uses the converter to transform data to Firestore format
200
+ * - Skips the update if the resulting data is empty
201
+ * - Applies any provided preconditions to the update
143
202
  *
144
- * @param accessor
145
- * @param converter
146
- * @returns
203
+ * @template T - The document data type
204
+ * @param accessor - The document accessor to use for updates
205
+ * @param converter - The data converter to transform input data to Firestore format
206
+ * @returns A function that updates the document with converted data
147
207
  */
148
208
  export declare function updateWithAccessorUpdateAndConverterFunction<T>(accessor: FirestoreDocumentDataAccessor<T>, converter: FirestoreDataConverter<T>): UpdateWithAccessorUpdateAndConverterFunction<T>;
@@ -1,2 +1,16 @@
1
1
  import { type FirestoreDocumentDataAccessorFactory } from './accessor';
2
+ /**
3
+ * Factory function type for creating standard document accessor factories.
4
+ *
5
+ * This is a parameterless factory that creates a document accessor factory for standard
6
+ * (non-transactional) operations. The returned factory can then be used to create document
7
+ * accessors for specific document references.
8
+ *
9
+ * Document accessors created through this factory chain will perform operations with
10
+ * standard Firestore semantics - individual operations with no transactional guarantees
11
+ * across multiple operations.
12
+ *
13
+ * @template T - The document data type that accessors will work with
14
+ * @returns A factory for creating standard document accessors
15
+ */
2
16
  export type DefaultFirestoreAccessorFactory<T> = () => FirestoreDocumentDataAccessorFactory<T>;
@@ -1,3 +1,18 @@
1
1
  import { type Transaction } from '../types';
2
2
  import { type FirestoreDocumentDataAccessorFactory } from './accessor';
3
+ /**
4
+ * Factory function type for creating document accessor factories that operate within a transaction.
5
+ *
6
+ * This is a higher-order factory that takes a Firestore Transaction and returns a document
7
+ * accessor factory. All document accessors created by the returned factory will perform
8
+ * their read and write operations as part of the specified transaction, providing atomicity
9
+ * and consistency guarantees across multiple documents and operations.
10
+ *
11
+ * Unlike write batches, transactions support both read and write operations and ensure
12
+ * that reads reflect a consistent snapshot of the database.
13
+ *
14
+ * @template T - The document data type that accessors will work with
15
+ * @param transaction - The Firestore transaction to execute operations within
16
+ * @returns A factory for creating document accessors that operate within the specified transaction
17
+ */
3
18
  export type TransactionAccessorFactory<T = unknown> = (transaction: Transaction) => FirestoreDocumentDataAccessorFactory<T>;
@@ -2,26 +2,131 @@ import { type Observable } from 'rxjs';
2
2
  import { type DocumentData, type DocumentReference, type DocumentSnapshot, type FirestoreDataConverter, type PartialWithFieldValue, type SetOptions, type UpdateData, type WithFieldValue, type WriteResult } from '../types';
3
3
  import { type FirestoreAccessorIncrementUpdate, type FirestoreDocumentDataAccessor, type FirestoreDocumentDataAccessorFactory, type FirestoreDocumentDeleteParams, type FirestoreDocumentUpdateParams } from './accessor';
4
4
  /**
5
- * Abstract wrapper for a FirestoreDocumentDataAccessor.
5
+ * Abstract wrapper for a FirestoreDocumentDataAccessor that delegates operations.
6
6
  *
7
- * Forwards all non-overridden accessor functions to the wrapped accessor by default.
7
+ * Provides a base implementation that forwards all accessor operations to the wrapped
8
+ * accessor instance. Subclasses can override specific methods to modify or intercept
9
+ * the behavior while inheriting the rest of the implementation.
10
+ *
11
+ * @template T - The document data type
12
+ * @template D - The raw document data type in Firestore (defaults to DocumentData)
8
13
  */
9
14
  export declare abstract class AbstractFirestoreDocumentDataAccessorWrapper<T, D = DocumentData> implements FirestoreDocumentDataAccessor<T, D> {
10
15
  private readonly _accessor;
16
+ /**
17
+ * Creates a new accessor wrapper.
18
+ *
19
+ * @param accessor - The accessor instance to wrap
20
+ */
11
21
  constructor(accessor: FirestoreDocumentDataAccessor<T, D>);
22
+ /**
23
+ * Gets the wrapped accessor instance.
24
+ *
25
+ * @returns The wrapped FirestoreDocumentDataAccessor instance
26
+ */
12
27
  get accessor(): FirestoreDocumentDataAccessor<T, D>;
28
+ /**
29
+ * Gets the document reference from the wrapped accessor.
30
+ *
31
+ * @returns The DocumentReference for the current document
32
+ */
13
33
  get documentRef(): DocumentReference<T>;
34
+ /**
35
+ * Streams document snapshots from the wrapped accessor.
36
+ *
37
+ * @returns An Observable that emits DocumentSnapshots when the document changes
38
+ */
14
39
  stream(): Observable<DocumentSnapshot<T>>;
40
+ /**
41
+ * Creates a new document with the provided data.
42
+ *
43
+ * @param data - The data to create the document with
44
+ * @returns A Promise that resolves when the create operation completes
45
+ */
15
46
  create(data: WithFieldValue<T>): Promise<WriteResult | void>;
47
+ /**
48
+ * Gets the current document snapshot.
49
+ *
50
+ * @returns A Promise that resolves with the current DocumentSnapshot
51
+ */
16
52
  get(): Promise<DocumentSnapshot<T>>;
53
+ /**
54
+ * Gets the document snapshot with a specific data converter.
55
+ *
56
+ * @template U - The converted data type
57
+ * @param converter - The data converter to use, or null for raw data
58
+ * @returns A Promise that resolves with the DocumentSnapshot with converted data
59
+ */
17
60
  getWithConverter<U = DocumentData>(converter: null | FirestoreDataConverter<U>): Promise<DocumentSnapshot<U>>;
61
+ /**
62
+ * Checks if the document exists.
63
+ *
64
+ * @returns A Promise that resolves with true if the document exists, false otherwise
65
+ */
18
66
  exists(): Promise<boolean>;
67
+ /**
68
+ * Deletes the document.
69
+ *
70
+ * @param params - Optional parameters for the delete operation
71
+ * @returns A Promise that resolves when the delete operation completes
72
+ */
19
73
  delete(params?: FirestoreDocumentDeleteParams): Promise<void | WriteResult>;
74
+ /**
75
+ * Sets document data with merge options.
76
+ *
77
+ * @param data - The partial data to set with merge
78
+ * @param options - The set options (e.g., merge settings)
79
+ * @returns A Promise that resolves when the set operation completes
80
+ */
20
81
  set(data: PartialWithFieldValue<T>, options: SetOptions): Promise<WriteResult | void>;
82
+ /**
83
+ * Sets document data, replacing any existing data.
84
+ *
85
+ * @param data - The complete data to set
86
+ * @returns A Promise that resolves when the set operation completes
87
+ */
21
88
  set(data: WithFieldValue<T>): Promise<WriteResult | void>;
89
+ /**
90
+ * Updates specific fields of the document.
91
+ *
92
+ * @param data - The fields to update and their new values
93
+ * @param params - Optional parameters for the update operation
94
+ * @returns A Promise that resolves when the update operation completes
95
+ */
22
96
  update(data: UpdateData<D>, params?: FirestoreDocumentUpdateParams): Promise<void | WriteResult>;
97
+ /**
98
+ * Increments numeric fields in the document.
99
+ *
100
+ * @param data - Mapping of fields to increment and the amount to increment by
101
+ * @param params - Optional parameters for the increment operation
102
+ * @returns A Promise that resolves when the increment operation completes
103
+ */
23
104
  increment(data: FirestoreAccessorIncrementUpdate<T>, params?: FirestoreDocumentUpdateParams): Promise<WriteResult | void>;
24
105
  }
106
+ /**
107
+ * Function type for wrapping a document accessor with additional functionality.
108
+ *
109
+ * @template T - The document data type
110
+ * @template D - The raw document data type in Firestore
111
+ */
25
112
  export type WrapFirestoreDocumentDataAccessorFunction<T, D = DocumentData> = (input: FirestoreDocumentDataAccessor<T, D>) => FirestoreDocumentDataAccessor<T, D>;
113
+ /**
114
+ * Function type for intercepting an accessor factory to modify all created accessors.
115
+ *
116
+ * @template T - The document data type
117
+ * @template D - The raw document data type in Firestore
118
+ */
26
119
  export type InterceptAccessorFactoryFunction<T, D = DocumentData> = (input: FirestoreDocumentDataAccessorFactory<T, D>) => FirestoreDocumentDataAccessorFactory<T, D>;
120
+ /**
121
+ * Creates a function that intercepts an accessor factory to wrap all created accessors.
122
+ *
123
+ * This function creates a higher-order factory that wraps each accessor created by the
124
+ * original factory with the provided wrapper function, allowing for consistent modification
125
+ * of all accessors created through the factory.
126
+ *
127
+ * @template T - The document data type
128
+ * @template D - The raw document data type in Firestore
129
+ * @param wrap - Function to wrap each created accessor
130
+ * @returns A function that transforms accessor factories to use the wrapper
131
+ */
27
132
  export declare function interceptAccessorFactoryFunction<T, D = DocumentData>(wrap: WrapFirestoreDocumentDataAccessorFunction<T, D>): InterceptAccessorFactoryFunction<T, D>;
@@ -1,7 +1,38 @@
1
1
  import { type WriteBatch } from '../types';
2
2
  import { type FirestoreDocumentContext, type FirestoreDocumentContextType } from './context';
3
+ /**
4
+ * Factory function type for creating write batch document contexts.
5
+ *
6
+ * This factory creates contexts that execute write operations within a Firestore batch,
7
+ * providing atomicity guarantees across multiple write operations.
8
+ *
9
+ * @template T - The document data type that accessors from this context will work with
10
+ * @param writeBatch - The Firestore write batch to execute operations within
11
+ * @returns A FirestoreDocumentContext with batch execution semantics
12
+ */
3
13
  export type WriteBatchFirestoreDocumentContextFactory = <T>(writeBatch: WriteBatch) => WriteBatchFirestoreDocumentContext<T>;
14
+ /**
15
+ * Document context for operations executed within a Firestore write batch.
16
+ *
17
+ * This context ensures that document write operations are performed as part of a batch,
18
+ * providing atomicity guarantees. Multiple write operations performed through accessors
19
+ * from this context will either all succeed or all fail together.
20
+ *
21
+ * Unlike transactions, batches in Firestore only support write operations (create, update,
22
+ * delete) and cannot read documents. This makes them more performant for write-only
23
+ * operations that don't depend on reading the current state.
24
+ *
25
+ * @template T - The document data type that accessors from this context will work with
26
+ */
4
27
  export interface WriteBatchFirestoreDocumentContext<T> extends FirestoreDocumentContext<T> {
28
+ /**
29
+ * The context type is always BATCH, indicating batch execution.
30
+ */
5
31
  readonly contextType: FirestoreDocumentContextType.BATCH;
32
+ /**
33
+ * The Firestore write batch that operations will be executed within.
34
+ *
35
+ * All write operations performed through accessors from this context will be part of this batch.
36
+ */
6
37
  readonly batch: WriteBatch;
7
38
  }
@@ -1,24 +1,47 @@
1
1
  import { type FirestoreDocumentDataAccessorFactory } from './accessor';
2
2
  /**
3
- * A specific document context type.
3
+ * Enumeration of possible contexts for document operations.
4
4
  *
5
- * Used by a FirestoreDocumentContext to communicate which kind of context it was created in.
5
+ * Used by FirestoreDocumentContext to indicate the execution environment of document operations,
6
+ * which affects how reads and writes are processed (e.g., atomicity, consistency).
7
+ *
8
+ * @remarks
9
+ * - NONE: Standard individual operations without transaction or batch guarantees
10
+ * - TRANSACTION: Operations within a Firestore transaction (atomic, with reads and writes)
11
+ * - BATCH: Operations within a Firestore write batch (atomic writes only, no reads)
6
12
  */
7
13
  export declare enum FirestoreDocumentContextType {
14
+ /** Standard context with no special transactional semantics */
8
15
  NONE = "none",
16
+ /** Operations within a Firestore transaction (atomic reads and writes) */
9
17
  TRANSACTION = "transaction",
18
+ /** Operations within a Firestore write batch (atomic writes only) */
10
19
  BATCH = "batch"
11
20
  }
12
21
  /**
13
- * Firebase database context used for accessing and modifying documents in a specific context, such as a transaction.
22
+ * Container for document operations within a specific execution context.
23
+ *
24
+ * Provides an accessor factory that creates document accessors appropriate for the current
25
+ * context (standard, transaction, or batch). When operations are performed using accessors
26
+ * from this context, they inherit the guarantees of the context type (e.g., transaction atomicity).
27
+ *
28
+ * This interface is used throughout the accessor system to propagate context information
29
+ * through the document access chain, ensuring consistent behavior.
30
+ *
31
+ * @template T - The document data type that accessors will work with
14
32
  */
15
33
  export interface FirestoreDocumentContext<T> {
16
34
  /**
17
- * Context type
35
+ * The type of execution context (none, transaction, or batch).
36
+ *
37
+ * Determines how operations will be executed and what guarantees they provide.
18
38
  */
19
39
  readonly contextType: FirestoreDocumentContextType;
20
40
  /**
21
- * Database accessor
41
+ * Factory for creating document accessors appropriate for this context.
42
+ *
43
+ * The returned accessors will execute operations in a manner consistent with
44
+ * the current context type (e.g., using transaction references for transactions).
22
45
  */
23
46
  readonly accessorFactory: FirestoreDocumentDataAccessorFactory<T>;
24
47
  }
@@ -1,5 +1,26 @@
1
1
  import { type FirestoreDocumentContext, type FirestoreDocumentContextType } from './context';
2
+ /**
3
+ * Factory function type for creating default (non-transactional) document contexts.
4
+ *
5
+ * This factory creates contexts with the standard execution semantics where
6
+ * operations are executed individually without transaction or batch guarantees.
7
+ *
8
+ * @template T - The document data type that accessors from this context will work with
9
+ * @returns A FirestoreDocumentContext with standard execution semantics
10
+ */
2
11
  export type DefaultFirestoreDocumentContextFactory = <T>() => FirestoreDocumentContext<T>;
12
+ /**
13
+ * The standard document context with no special transactional semantics.
14
+ *
15
+ * This context is used for regular document operations outside of transactions or batches.
16
+ * Operations performed through accessors from this context will be executed individually
17
+ * with standard Firestore guarantees but no atomicity across multiple operations.
18
+ *
19
+ * @template T - The document data type that accessors from this context will work with
20
+ */
3
21
  export interface DefaultFirestoreDocumentContext<T> extends FirestoreDocumentContext<T> {
22
+ /**
23
+ * The context type is always NONE, indicating standard non-transactional execution.
24
+ */
4
25
  readonly contextType: FirestoreDocumentContextType.NONE;
5
26
  }
@@ -1,7 +1,38 @@
1
1
  import { type Transaction } from '../types';
2
2
  import { type FirestoreDocumentContext, type FirestoreDocumentContextType } from './context';
3
+ /**
4
+ * Factory function type for creating transaction document contexts.
5
+ *
6
+ * This factory creates contexts that execute operations within a Firestore transaction,
7
+ * providing atomicity guarantees across multiple read and write operations.
8
+ *
9
+ * @template T - The document data type that accessors from this context will work with
10
+ * @param transaction - The Firestore transaction to execute operations within
11
+ * @returns A FirestoreDocumentContext with transaction execution semantics
12
+ */
3
13
  export type TransactionFirestoreDocumentContextFactory = <T>(transaction: Transaction) => TransactionFirestoreDocumentContext<T>;
14
+ /**
15
+ * Document context for operations executed within a Firestore transaction.
16
+ *
17
+ * This context ensures that document operations are performed as part of a transaction,
18
+ * providing atomicity guarantees. Multiple operations performed through accessors from
19
+ * this context will either all succeed or all fail together.
20
+ *
21
+ * Transactions in Firestore allow both reading and writing documents, and ensure that
22
+ * reads reflect a consistent snapshot of the database that isn't affected by other
23
+ * transactions until the current transaction completes.
24
+ *
25
+ * @template T - The document data type that accessors from this context will work with
26
+ */
4
27
  export interface TransactionFirestoreDocumentContext<T> extends FirestoreDocumentContext<T> {
28
+ /**
29
+ * The context type is always TRANSACTION, indicating transactional execution.
30
+ */
5
31
  readonly contextType: FirestoreDocumentContextType.TRANSACTION;
32
+ /**
33
+ * The Firestore transaction that operations will be executed within.
34
+ *
35
+ * All operations performed through accessors from this context will be part of this transaction.
36
+ */
6
37
  readonly transaction: Transaction;
7
38
  }
@@ -1,16 +1,41 @@
1
1
  import { type FactoryWithInput, type FactoryWithRequiredInput, type Maybe } from '@dereekb/util';
2
2
  import { type DocumentReference, type FirestoreDataConverter } from '../types';
3
3
  /**
4
- * Factory used to provide an FirestoreDataConverter based on the input reference.
4
+ * Factory that creates a FirestoreDataConverter for a specific document reference.
5
+ *
6
+ * This factory allows dynamic creation of data converters based on the specific document
7
+ * reference being accessed. This enables different document references to have different
8
+ * conversion logic even within the same collection.
9
+ *
10
+ * @template T - The document data type that the converter will transform to/from Firestore
5
11
  */
6
12
  export type FirestoreDataConverterFactory<T> = FactoryWithInput<FirestoreDataConverter<T>, DocumentReference<T>>;
7
13
  /**
8
- * Ref to a FirestoreDataConverterFactory.
14
+ * Interface that provides access to a FirestoreDataConverterFactory.
15
+ *
16
+ * This interface is typically implemented by classes or objects that need to
17
+ * reference a converter factory without directly containing the creation logic.
18
+ * It enables separation between components that use converters and those that
19
+ * define how conversion should happen.
20
+ *
21
+ * @template T - The document data type that the converter will transform to/from Firestore
9
22
  */
10
23
  export interface FirestoreDataConverterFactoryRef<T> {
24
+ /**
25
+ * Factory function that creates a FirestoreDataConverter for a specific document reference.
26
+ */
11
27
  readonly converterFactory: FirestoreDataConverterFactory<T>;
12
28
  }
13
29
  /**
14
- * Factory used to provide an optional custom FirestoreDataConverter based on the input reference.
30
+ * Factory that optionally intercepts and provides a custom FirestoreDataConverter.
31
+ *
32
+ * Unlike FirestoreDataConverterFactory which always returns a converter, this factory
33
+ * may return null/undefined to indicate that no custom converter should be used.
34
+ * This allows for selective interception of converter creation based on specific criteria.
35
+ *
36
+ * This pattern is useful for middleware-like components that need to optionally modify
37
+ * or replace converters without affecting the entire conversion pipeline.
38
+ *
39
+ * @template T - The document data type that the converter will transform to/from Firestore
15
40
  */
16
41
  export type InterceptFirestoreDataConverterFactory<T> = FactoryWithRequiredInput<Maybe<FirestoreDataConverter<T>>, DocumentReference<T>>;
@@ -1,6 +1,43 @@
1
1
  import { type Observable, type OperatorFunction } from 'rxjs';
2
2
  import { type DocumentDataWithIdAndKey, type DocumentSnapshot } from '../types';
3
3
  import { type FirestoreDocument, type FirestoreDocumentData } from './document';
4
+ /**
5
+ * Creates an Observable that emits arrays of document snapshots for multiple documents.
6
+ *
7
+ * This function streams the latest snapshots for each document in the provided array.
8
+ * Each time any document in the array changes, a new array containing the latest snapshots
9
+ * of all documents is emitted. Results are shared with multiple subscribers through shareReplay.
10
+ *
11
+ * If the input array is empty, an Observable that emits an empty array is returned.
12
+ *
13
+ * @template D - The FirestoreDocument implementation type
14
+ * @param documents - Array of document instances to stream snapshots for
15
+ * @returns Observable that emits arrays of DocumentSnapshots whenever any document changes
16
+ */
4
17
  export declare function latestSnapshotsFromDocuments<D extends FirestoreDocument<any>>(documents: D[]): Observable<DocumentSnapshot<FirestoreDocumentData<D>>[]>;
18
+ /**
19
+ * Creates an Observable that emits arrays of document data for multiple documents.
20
+ *
21
+ * This function streams the latest data for each document in the provided array.
22
+ * Each time any document in the array changes, a new array containing the latest data
23
+ * of all documents is emitted. Document data includes both the document content and
24
+ * metadata like document ID and key. Results are shared with multiple subscribers.
25
+ *
26
+ * Non-existent documents are filtered out of the results automatically.
27
+ *
28
+ * @template D - The FirestoreDocument implementation type
29
+ * @param documents - Array of document instances to stream data for
30
+ * @returns Observable that emits arrays of document data whenever any document changes
31
+ */
5
32
  export declare function latestDataFromDocuments<D extends FirestoreDocument<any>>(documents: D[]): Observable<DocumentDataWithIdAndKey<FirestoreDocumentData<D>>[]>;
33
+ /**
34
+ * Creates an RxJS operator that transforms arrays of DocumentSnapshots into arrays of document data.
35
+ *
36
+ * This operator extracts the data from each document snapshot, adds ID and key information,
37
+ * and filters out non-existent documents. It's designed to be used in a pipe after
38
+ * operations that produce arrays of snapshots.
39
+ *
40
+ * @template T - The document data type
41
+ * @returns An operator that transforms arrays of DocumentSnapshots into arrays of document data
42
+ */
6
43
  export declare function dataFromDocumentSnapshots<T>(): OperatorFunction<DocumentSnapshot<T>[], DocumentDataWithIdAndKey<T>[]>;