@dereekb/firebase 13.2.2 → 13.3.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 (135) hide show
  1. package/index.cjs.js +12893 -4062
  2. package/index.esm.js +12872 -4065
  3. package/package.json +5 -5
  4. package/src/lib/client/error/error.d.ts +18 -3
  5. package/src/lib/client/firestore/array.d.ts +16 -3
  6. package/src/lib/client/firestore/driver.accessor.batch.d.ts +35 -4
  7. package/src/lib/client/firestore/driver.accessor.create.d.ts +15 -0
  8. package/src/lib/client/firestore/driver.accessor.d.ts +15 -0
  9. package/src/lib/client/firestore/driver.accessor.default.d.ts +32 -0
  10. package/src/lib/client/firestore/driver.accessor.transaction.d.ts +35 -4
  11. package/src/lib/client/firestore/driver.d.ts +16 -0
  12. package/src/lib/client/firestore/driver.query.d.ts +36 -0
  13. package/src/lib/client/firestore/firestore.d.ts +11 -1
  14. package/src/lib/client/firestore/increment.d.ts +12 -3
  15. package/src/lib/client/function/development.function.factory.d.ts +27 -2
  16. package/src/lib/client/function/error.d.ts +27 -0
  17. package/src/lib/client/function/function.callable.d.ts +50 -5
  18. package/src/lib/client/function/function.factory.d.ts +70 -4
  19. package/src/lib/client/function/model.function.factory.d.ts +64 -9
  20. package/src/lib/client/storage/driver.accessor.d.ts +93 -0
  21. package/src/lib/client/storage/driver.d.ts +15 -0
  22. package/src/lib/client/storage/storage.d.ts +10 -1
  23. package/src/lib/common/auth/auth.context.d.ts +17 -2
  24. package/src/lib/common/auth/auth.d.ts +38 -9
  25. package/src/lib/common/auth/auth.error.d.ts +25 -0
  26. package/src/lib/common/auth/auth.server.error.d.ts +6 -2
  27. package/src/lib/common/development/function.d.ts +17 -6
  28. package/src/lib/common/development/function.schedule.d.ts +30 -1
  29. package/src/lib/common/firestore/accessor/accessor.wrap.modify.d.ts +36 -12
  30. package/src/lib/common/firestore/accessor/array.d.ts +14 -4
  31. package/src/lib/common/firestore/accessor/document.d.ts +77 -2
  32. package/src/lib/common/firestore/accessor/increment.d.ts +15 -3
  33. package/src/lib/common/firestore/collection/collection.d.ts +22 -4
  34. package/src/lib/common/firestore/collection/collection.util.d.ts +12 -2
  35. package/src/lib/common/firestore/driver/accessor.d.ts +28 -1
  36. package/src/lib/common/firestore/driver/batch.d.ts +6 -4
  37. package/src/lib/common/firestore/driver/driver.d.ts +18 -1
  38. package/src/lib/common/firestore/driver/query.d.ts +20 -1
  39. package/src/lib/common/firestore/driver/query.handler.d.ts +23 -0
  40. package/src/lib/common/firestore/driver/transaction.d.ts +18 -6
  41. package/src/lib/common/firestore/error.d.ts +16 -4
  42. package/src/lib/common/firestore/query/iterator.d.ts +11 -0
  43. package/src/lib/common/firestore/reference.d.ts +11 -6
  44. package/src/lib/common/firestore/snapshot/snapshot.d.ts +4 -0
  45. package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +263 -63
  46. package/src/lib/common/firestore/types.d.ts +39 -1
  47. package/src/lib/common/firestore/util/id.batch.d.ts +55 -3
  48. package/src/lib/common/function/action.d.ts +35 -0
  49. package/src/lib/common/model/context.d.ts +11 -1
  50. package/src/lib/common/model/function.d.ts +45 -9
  51. package/src/lib/common/model/model/model.loader.d.ts +37 -0
  52. package/src/lib/common/model/model/model.param.d.ts +24 -2
  53. package/src/lib/common/model/model.service.d.ts +126 -4
  54. package/src/lib/common/model/permission/permission.context.d.ts +15 -0
  55. package/src/lib/common/model/permission/permission.d.ts +16 -0
  56. package/src/lib/common/model/permission/permission.service.d.ts +24 -1
  57. package/src/lib/common/model/permission/permission.service.grant.d.ts +72 -28
  58. package/src/lib/common/model/permission/permission.service.role.d.ts +15 -0
  59. package/src/lib/common/storage/accessor/path.model.d.ts +25 -8
  60. package/src/lib/common/storage/context.d.ts +23 -6
  61. package/src/lib/common/storage/driver/accessor.d.ts +15 -4
  62. package/src/lib/common/storage/driver/accessor.iterate.d.ts +31 -8
  63. package/src/lib/common/storage/driver/accessor.util.d.ts +13 -6
  64. package/src/lib/common/storage/driver/driver.d.ts +10 -1
  65. package/src/lib/common/storage/driver/error.d.ts +16 -0
  66. package/src/lib/common/storage/driver/list.d.ts +30 -0
  67. package/src/lib/common/storage/storage.d.ts +76 -19
  68. package/src/lib/common/storage/types.d.ts +23 -5
  69. package/src/lib/model/index.d.ts +1 -0
  70. package/src/lib/model/notification/notification.action.d.ts +8 -0
  71. package/src/lib/model/notification/notification.api.d.ts +26 -0
  72. package/src/lib/model/notification/notification.api.error.d.ts +15 -0
  73. package/src/lib/model/notification/notification.api.util.d.ts +27 -12
  74. package/src/lib/model/notification/notification.config.d.ts +193 -64
  75. package/src/lib/model/notification/notification.create.d.ts +62 -13
  76. package/src/lib/model/notification/notification.create.task.d.ts +25 -4
  77. package/src/lib/model/notification/notification.d.ts +258 -99
  78. package/src/lib/model/notification/notification.details.d.ts +66 -18
  79. package/src/lib/model/notification/notification.id.d.ts +90 -12
  80. package/src/lib/model/notification/notification.item.d.ts +57 -16
  81. package/src/lib/model/notification/notification.message.d.ts +84 -18
  82. package/src/lib/model/notification/notification.query.d.ts +21 -24
  83. package/src/lib/model/notification/notification.send.d.ts +38 -5
  84. package/src/lib/model/notification/notification.task.d.ts +87 -16
  85. package/src/lib/model/notification/notification.task.subtask.d.ts +42 -13
  86. package/src/lib/model/notification/notification.util.d.ts +68 -18
  87. package/src/lib/model/oidcmodel/index.d.ts +8 -0
  88. package/src/lib/model/oidcmodel/oidcmodel.action.d.ts +37 -0
  89. package/src/lib/model/oidcmodel/oidcmodel.api.d.ts +131 -0
  90. package/src/lib/model/oidcmodel/oidcmodel.d.ts +114 -0
  91. package/src/lib/model/oidcmodel/oidcmodel.data.d.ts +17 -0
  92. package/src/lib/model/oidcmodel/oidcmodel.id.d.ts +18 -0
  93. package/src/lib/model/oidcmodel/oidcmodel.interaction.d.ts +40 -0
  94. package/src/lib/model/oidcmodel/oidcmodel.interaction.oauth.d.ts +73 -0
  95. package/src/lib/model/oidcmodel/oidcmodel.query.d.ts +21 -0
  96. package/src/lib/model/storagefile/storagefile.action.d.ts +47 -0
  97. package/src/lib/model/storagefile/storagefile.api.d.ts +54 -4
  98. package/src/lib/model/storagefile/storagefile.create.d.ts +40 -3
  99. package/src/lib/model/storagefile/storagefile.d.ts +153 -16
  100. package/src/lib/model/storagefile/storagefile.file.d.ts +22 -7
  101. package/src/lib/model/storagefile/storagefile.group.d.ts +30 -1
  102. package/src/lib/model/storagefile/storagefile.group.processing.d.ts +20 -2
  103. package/src/lib/model/storagefile/storagefile.id.d.ts +44 -5
  104. package/src/lib/model/storagefile/storagefile.permission.d.ts +23 -4
  105. package/src/lib/model/storagefile/storagefile.query.d.ts +63 -11
  106. package/src/lib/model/storagefile/storagefile.task.d.ts +47 -4
  107. package/src/lib/model/storagefile/storagefile.upload.claims.d.ts +21 -4
  108. package/src/lib/model/storagefile/storagefile.upload.d.ts +41 -9
  109. package/src/lib/model/storagefile/storagefile.upload.determiner.d.ts +112 -20
  110. package/src/lib/model/storagefile/storagefile.util.d.ts +66 -3
  111. package/src/lib/model/system/system.action.d.ts +25 -0
  112. package/src/lib/model/system/system.d.ts +80 -4
  113. package/src/lib/model/user.d.ts +8 -2
  114. package/test/index.cjs.js +11168 -3295
  115. package/test/index.esm.js +11176 -3303
  116. package/test/package.json +6 -6
  117. package/test/src/lib/client/firebase.authorized.d.ts +18 -0
  118. package/test/src/lib/client/firebase.d.ts +60 -0
  119. package/test/src/lib/common/firebase.instance.d.ts +21 -0
  120. package/test/src/lib/common/firestore/firestore.d.ts +40 -0
  121. package/test/src/lib/common/firestore/firestore.instance.d.ts +16 -0
  122. package/test/src/lib/common/firestore/test.driver.accessor.d.ts +39 -2
  123. package/test/src/lib/common/firestore/test.driver.utility.d.ts +8 -2
  124. package/test/src/lib/common/firestore/test.iterator.d.ts +7 -2
  125. package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +29 -1
  126. package/test/src/lib/common/mock/mock.item.d.ts +219 -5
  127. package/test/src/lib/common/mock/mock.item.id.d.ts +6 -0
  128. package/test/src/lib/common/mock/mock.item.query.d.ts +12 -0
  129. package/test/src/lib/common/mock/mock.item.service.d.ts +60 -0
  130. package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +28 -1
  131. package/test/src/lib/common/storage/storage.d.ts +30 -0
  132. package/test/src/lib/common/storage/storage.instance.d.ts +22 -0
  133. package/test/src/lib/common/storage/test.driver.accessor.d.ts +7 -2
  134. package/index.cjs.js.map +0 -1
  135. package/index.esm.js.map +0 -1
@@ -1,14 +1,26 @@
1
1
  import { type UpdateData } from 'firebase/firestore';
2
+ /**
3
+ * Throws an error indicating the current Firestore driver does not support the called function.
4
+ * Used by driver implementations to reject unsupported operations at runtime.
5
+ *
6
+ * @param message - Optional custom error message
7
+ * @throws {Error} Always throws
8
+ */
2
9
  export declare function unsupportedFirestoreDriverFunctionError(message?: string): void;
3
10
  /**
4
- * Asserts that the input data is not an empty object and has keys.
11
+ * Asserts that the input update data contains at least one key.
5
12
  *
6
- * Used to help bring pairity to update(), as google-cloud/firestore will throw an error if the input data has no keys defined.
13
+ * The `google-cloud/firestore` Admin SDK throws on empty update objects, but the Web SDK
14
+ * does not. This assertion normalizes behavior across both platforms so that empty updates
15
+ * are caught early regardless of which driver is in use.
7
16
  *
8
- * @param data
17
+ * @param data - The update data to validate
18
+ * @throws {Error} When the data object has no keys
9
19
  */
10
20
  export declare function assertFirestoreUpdateHasData(data: UpdateData<object>): void;
11
21
  /**
12
- * Throws an error related to an empty object being passed to a FirestoreDocumentDataAccessor's update() function.
22
+ * Creates and throws an error for empty update data passed to a {@link FirestoreDocumentDataAccessor}'s `update()` method.
23
+ *
24
+ * @throws {Error} Always throws
13
25
  */
14
26
  export declare function firestoreUpdateWithNoDataError(): void;
@@ -28,6 +28,17 @@ export interface FirestoreItemPageIteratorFilter extends ItemPageLimit {
28
28
  * and should not be included here.
29
29
  */
30
30
  readonly constraints?: Maybe<ArrayOrValue<FirestoreQueryConstraint>>;
31
+ /**
32
+ * Whether to infer the end of results when a page returns fewer items than
33
+ * the requested page size (limit).
34
+ *
35
+ * When enabled, if a query returns fewer documents than the limit, the iterator
36
+ * marks the result as the final page — avoiding an unnecessary extra fetch that
37
+ * would return zero results.
38
+ *
39
+ * Defaults to true.
40
+ */
41
+ readonly inferEndOfResultsFromPageSize?: Maybe<boolean>;
31
42
  }
32
43
  /**
33
44
  * Base configuration for Firestore query pagination.
@@ -1,37 +1,42 @@
1
1
  import { type FirestoreContext } from './context';
2
2
  import { type CollectionReference, type DocumentReference, type Firestore, type FirestoreDataConverter, type Query, type Transaction } from './types';
3
3
  /**
4
- * Contains a reference to a Query.
4
+ * Holds a reference to a Firestore {@link Query}, which may be either a collection query
5
+ * or a collection group query. Used as a base reference by collection groups and other
6
+ * query-oriented interfaces.
5
7
  */
6
8
  export interface QueryLikeReferenceRef<T> {
7
9
  readonly queryLike: Query<T>;
8
10
  }
9
11
  /**
10
- * Contains a reference to a CollectionReference.
12
+ * Holds a reference to a {@link CollectionReference}.
11
13
  */
12
14
  export interface CollectionReferenceRef<T> {
13
15
  readonly collection: CollectionReference<T>;
14
16
  }
15
17
  /**
16
- * Contains a reference to a DocumentReference.
18
+ * Holds a reference to a {@link DocumentReference}.
17
19
  */
18
20
  export interface DocumentReferenceRef<T> {
19
21
  readonly documentRef: DocumentReference<T>;
20
22
  }
21
23
  /**
22
- * Contains a reference to a FirestoreContext.
24
+ * Holds a reference to a {@link FirestoreContext} instance, providing access to
25
+ * collection factories, transactions, and batch operations.
23
26
  */
24
27
  export interface FirestoreContextReference<F extends Firestore = Firestore> {
25
28
  readonly firestoreContext: FirestoreContext<F>;
26
29
  }
27
30
  /**
28
- * Contains contextual information about the current Transaction, if available.
31
+ * Provides optional access to the current Firestore {@link Transaction}, if the
32
+ * operation is running within a transaction context.
29
33
  */
30
34
  export interface FirebaseTransactionContext {
31
35
  readonly transaction?: Transaction;
32
36
  }
33
37
  /**
34
- * Contains contextual information about the current Transaction, if available.
38
+ * Holds a reference to a {@link FirestoreDataConverter} for transforming data
39
+ * between application models and Firestore document representations.
35
40
  */
36
41
  export interface FirestoreDataConverterRef<U = unknown> {
37
42
  readonly converter: FirestoreDataConverter<U>;
@@ -2,6 +2,10 @@ import { type FirestoreModelData, type SnapshotConverterConfig, type SnapshotCon
2
2
  /**
3
3
  * Creates converter functions for transforming between Firestore document snapshots and application model objects.
4
4
  *
5
+ * This is the primary entry point for defining how your application models map to/from Firestore documents.
6
+ * The returned object implements Firebase's {@link FirestoreDataConverter} interface and can be passed directly
7
+ * to `withConverter()` on collection/document references.
8
+ *
5
9
  * This function generates a set of utility functions that handle the conversion between your application's
6
10
  * typed model objects and the data format stored in Firestore. It supports field-level conversions,
7
11
  * custom modifiers, and handles Firestore's merge options appropriately.
@@ -1,3 +1,33 @@
1
+ /**
2
+ * @module snapshot.field
3
+ *
4
+ * Provides pre-built Firestore field mapping configurations for converting between application model types and
5
+ * their Firestore-stored representations. Each field converter is a factory function that returns a
6
+ * {@link FirestoreModelFieldMapFunctionsConfig}, which plugs into the snapshot converter system
7
+ * (see {@link snapshotConverterFunctions} in `snapshot.ts`).
8
+ *
9
+ * ## Pattern
10
+ *
11
+ * Every field type has a required variant (e.g., `firestoreString()`) and an optional variant
12
+ * (e.g., `optionalFirestoreString()`). Required variants provide a default value when the field
13
+ * is missing from Firestore; optional variants return `null`/`undefined`.
14
+ *
15
+ * ## Storage Optimization
16
+ *
17
+ * Optional fields support `dontStoreIf` / `dontStoreValueIf` to skip storing values that match a
18
+ * condition (e.g., don't store `false` booleans or empty arrays). This reduces Firestore document
19
+ * size and read costs. The value is still returned correctly on read via `defaultReadValue`.
20
+ *
21
+ * ## Available Field Types
22
+ *
23
+ * - **Primitives**: `firestoreString`, `firestoreNumber`, `firestoreBoolean`, `firestoreEnum`
24
+ * - **Dates**: `firestoreDate` (ISO8601), `firestoreDateNumber` (unix seconds)
25
+ * - **Arrays**: `firestoreArray`, `firestoreUniqueArray`, `firestoreEnumArray`, `firestoreEncodedArray`
26
+ * - **Maps**: `firestoreMap`, `firestoreEncodedObjectMap`, `firestoreArrayMap`
27
+ * - **Objects**: `firestoreSubObject`, `firestoreObjectArray`
28
+ * - **Specialized**: `firestoreUID`, `firestoreLatLngString`, `firestoreWebsiteLink`,
29
+ * `firestoreDateCellRange`, `firestoreBitwiseSet`, `firestoreUnitedStatesAddress`
30
+ */
1
31
  import { type WebsiteLink, type GrantedRole, type WebsiteFileLink } from '@dereekb/model';
2
32
  import { type DateCellRange, type DateCellSchedule } from '@dereekb/date';
3
33
  import { type ModelFieldMapFunctionsConfig, type GetterOrValue, type Maybe, type ModelFieldMapConvertFunction, type PrimativeKey, type ReadKeyFunction, type ModelFieldMapFunctionsWithDefaultsConfig, type FilterUniqueStringsTransformConfig, type MapFunction, type FilterKeyValueTuplesInput, type ModelKey, type ToModelMapFunctionsInput, type ModelMapFunctionsRef, type LatLngPrecision, type LatLngString, type TimezoneString, type PrimativeKeyStringDencoderFunction, type PrimativeKeyDencoderFunction, type UnitedStatesAddress, type ZoomLevel, type FilterUniqueFunction, type BitwiseEncodedSet, type BitwiseObjectDencoder, type SortCompareFunctionRef, type TransformNumberFunctionConfigInput, type TransformStringFunctionConfigInput, type DecisionFunction, type ISO8601DateString, type FilterFunction } from '@dereekb/util';
@@ -69,22 +99,47 @@ export interface FirestoreFieldConfigWithDefaultData<V, D = unknown> extends Bas
69
99
  */
70
100
  export type FirestoreFieldConfig<V, D = unknown> = FirestoreFieldConfigWithDefault<V, D> | FirestoreFieldConfigWithDefaultData<V, D>;
71
101
  /**
72
- * All firebase ModelFieldMapFunctionsConfig are configured to handle the read field value as null/undefined. This implies that
73
- * by design, the firebase database documents do not need to be fully intact for the system to handle them properly.
102
+ * The standard field mapping config type used by all Firestore field converters.
103
+ *
104
+ * The read side accepts `Maybe<D>` (nullable) because Firestore documents are schemaless — any field
105
+ * can be missing or null. This design ensures the system gracefully handles incomplete documents.
106
+ *
107
+ * @template V - Value type in the application model
108
+ * @template D - Data type in Firestore
74
109
  */
75
110
  export type FirestoreModelFieldMapFunctionsConfig<V, D> = ModelFieldMapFunctionsWithDefaultsConfig<V, Maybe<D>>;
76
111
  /**
77
112
  * Creates a Firestore field mapping configuration.
78
113
  *
79
- * This function generates the necessary mapping functions for converting between
80
- * model values and Firestore data. It handles defaults and conversions in both directions.
114
+ * This is the low-level building block that all other field converters (e.g., {@link firestoreString},
115
+ * {@link firestoreDate}) delegate to. It generates `from`/`to` mapping functions that handle defaults
116
+ * and conversions in both directions.
117
+ *
118
+ * Use the higher-level field converters for common types; use this directly only when you need a
119
+ * custom conversion not covered by the built-in converters.
81
120
  *
82
121
  * @template V - Value type for the field in the model
83
122
  * @template D - Data type for the field in Firestore (defaults to unknown)
84
123
  * @param config - Configuration for the Firestore field
85
124
  * @returns A configured mapping between model and Firestore data
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * // Custom field that stores a Set<string> as a comma-separated string
129
+ * const tagsField = firestoreField<Set<string>, string>({
130
+ * default: () => new Set(),
131
+ * fromData: (csv) => new Set(csv.split(',')),
132
+ * toData: (set) => [...set].join(',')
133
+ * });
134
+ * ```
86
135
  */
87
136
  export declare function firestoreField<V, D = unknown>(config: FirestoreFieldConfig<V, D>): FirestoreModelFieldMapFunctionsConfig<V, D>;
137
+ /**
138
+ * A pre-built passthrough field mapping that stores and reads values unchanged.
139
+ *
140
+ * Defaults to `null` when the field is missing. Used internally by {@link firestorePassThroughField}
141
+ * and as a fallback for {@link optionalFirestoreField} when no config is provided.
142
+ */
88
143
  export declare const FIRESTORE_PASSTHROUGH_FIELD: FirestoreModelFieldMapFunctionsConfig<unknown, unknown>;
89
144
  /**
90
145
  * Creates a pass-through field mapping configuration that doesn't transform the data.
@@ -99,8 +154,13 @@ export declare function firestorePassThroughField<T>(): ModelFieldMapFunctionsCo
99
154
  /**
100
155
  * Configuration for optional Firestore fields with conditional storage.
101
156
  *
102
- * This interface provides options for determining when fields should not be stored
103
- * in Firestore and default values for reading.
157
+ * Enables storage optimization by skipping fields that match a "don't store" condition.
158
+ * This reduces Firestore document size and cost. The field is still read correctly because
159
+ * `defaultReadValue` provides the expected value when the field is absent from the document.
160
+ *
161
+ * The optimization flow:
162
+ * 1. On write: if the value matches `dontStoreValueIf` (pre-transform) or `dontStoreIf` (post-transform), store `null` instead
163
+ * 2. On read: if the stored value is `null`/`undefined`, return `defaultReadValue` (if configured) before transforming
104
164
  *
105
165
  * @template V - Value type for the field in the model
106
166
  * @template D - Data type for the field in Firestore
@@ -109,17 +169,24 @@ export interface OptionalFirestoreFieldConfig<V, D> {
109
169
  /**
110
170
  * Removes the value from the object if the decision returns true.
111
171
  *
112
- * This occurs before the value is transformed.
172
+ * This check occurs **before** the value is transformed to Firestore data format.
173
+ * Can be a specific value (compared with `===`) or a decision function.
113
174
  */
114
175
  readonly dontStoreValueIf?: V | DecisionFunction<V>;
115
176
  /**
116
177
  * Removes the value from the object if the decision returns true.
178
+ *
179
+ * This check occurs **after** the value is transformed to Firestore data format.
180
+ * Can be a specific value (compared with `===`) or a decision function.
117
181
  */
118
182
  readonly dontStoreIf?: D | DecisionFunction<D>;
119
183
  /**
120
- * Database data value to optionally return if there is no value in the database when reading from the database.
184
+ * Default data value to return when the field is missing from the Firestore document.
185
+ *
186
+ * Pairs with `dontStoreIf`/`dontStoreValueIf` to enable storage optimization: don't store the value,
187
+ * but return this default on read so the application sees the expected value.
121
188
  *
122
- * If using a getter the getter is invoked each time.
189
+ * If using a getter, the getter is invoked each time to ensure fresh copies.
123
190
  */
124
191
  readonly defaultReadValue?: GetterOrValue<D>;
125
192
  }
@@ -176,12 +243,30 @@ export interface OptionalFirestoreFieldConfigWithOneTypeTransform<T> extends Opt
176
243
  /**
177
244
  * Creates a field mapping configuration for optional Firestore fields.
178
245
  *
179
- * Handles transformation and conditional storage of values with different types.
246
+ * Optional fields store `null` in Firestore when absent and return `null`/`undefined` to the application.
247
+ * Supports conditional storage via `dontStoreIf`/`dontStoreValueIf` to reduce document size.
248
+ *
249
+ * When no config is provided, returns a passthrough field that stores/reads values unchanged.
180
250
  *
181
251
  * @template V - Value type for the field in the model
182
252
  * @template D - Data type for the field in Firestore
183
253
  * @param config - Configuration for the optional Firestore field
184
254
  * @returns A field mapping configuration for optional values
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * // Optional boolean that isn't stored when false (saves document space)
259
+ * const isAdminField = optionalFirestoreField<boolean>({
260
+ * dontStoreIf: false,
261
+ * defaultReadValue: false
262
+ * });
263
+ *
264
+ * // Optional date with transformation
265
+ * const deletedAtField = optionalFirestoreField<Date, string>({
266
+ * transformFromData: toJsDate,
267
+ * transformToData: toISODateString
268
+ * });
269
+ * ```
185
270
  */
186
271
  export declare function optionalFirestoreField<V, D>(config?: OptionalFirestoreFieldConfigWithTwoTypeTransform<V, D>): FirestoreModelFieldMapFunctionsConfig<Maybe<V>, Maybe<D>>;
187
272
  /**
@@ -240,13 +325,28 @@ export interface FirestoreStringConfig<S extends string = string> extends Defaul
240
325
  */
241
326
  readonly transform?: TransformStringFunctionConfigInput<S>;
242
327
  }
328
+ /**
329
+ * Default value for required Firestore string fields when the field is missing from the document.
330
+ */
243
331
  export declare const DEFAULT_FIRESTORE_STRING_FIELD_VALUE = "";
244
332
  /**
245
333
  * Creates a field mapping configuration for Firestore string fields.
246
334
  *
335
+ * Defaults to empty string `''` when the field is missing. Supports optional string
336
+ * transformation (e.g., lowercase, trim) applied on both read and write.
337
+ *
247
338
  * @template S - String type for the field (defaults to string)
248
339
  * @param config - Configuration for the string field
249
340
  * @returns A field mapping configuration for string values
341
+ *
342
+ * @example
343
+ * ```ts
344
+ * // Simple string field with default
345
+ * const nameField = firestoreString({ default: 'unnamed' });
346
+ *
347
+ * // String field with lowercase transformation
348
+ * const emailField = firestoreString({ transform: 'lowercase' });
349
+ * ```
250
350
  */
251
351
  export declare function firestoreString<S extends string = string>(config?: FirestoreStringConfig<S>): FirestoreModelFieldMapFunctionsConfig<S, S>;
252
352
  /**
@@ -303,7 +403,13 @@ export declare function firestoreUID(): FirestoreModelFieldMapFunctionsConfig<st
303
403
  * @returns A field mapping configuration for optional Firebase Auth user IDs
304
404
  */
305
405
  export declare function optionalFirestoreUID(): FirestoreModelFieldMapFunctionsConfig<Maybe<string>, Maybe<string>>;
406
+ /**
407
+ * Pre-built field mapping for Firestore model key strings. Defaults to empty string.
408
+ */
306
409
  export declare const firestoreModelKeyString: FirestoreModelFieldMapFunctionsConfig<string, string>;
410
+ /**
411
+ * Pre-built field mapping for Firestore model ID strings. Defaults to empty string.
412
+ */
307
413
  export declare const firestoreModelIdString: FirestoreModelFieldMapFunctionsConfig<string, string>;
308
414
  /**
309
415
  * Configuration for a Firestore date field.
@@ -321,9 +427,20 @@ export type FirestoreDateFieldConfig = DefaultMapConfiguredFirestoreFieldConfig<
321
427
  * Creates a field mapping configuration for Firestore date fields.
322
428
  *
323
429
  * Handles conversion between JavaScript Date objects and ISO8601 strings stored in Firestore.
430
+ * Defaults to `new Date()` when the field is missing. Use `saveDefaultAsNow` to automatically
431
+ * store the current timestamp when a new document is created.
324
432
  *
325
433
  * @param config - Configuration for the date field
326
434
  * @returns A field mapping configuration for Date values
435
+ *
436
+ * @example
437
+ * ```ts
438
+ * // Date field that auto-saves current time on creation
439
+ * const createdAtField = firestoreDate({ saveDefaultAsNow: true });
440
+ *
441
+ * // Date field with a fixed default
442
+ * const startDateField = firestoreDate({ default: new Date('2020-01-01') });
443
+ * ```
327
444
  */
328
445
  export declare function firestoreDate(config?: FirestoreDateFieldConfig): FirestoreModelFieldMapFunctionsConfig<Date, string>;
329
446
  /**
@@ -360,12 +477,13 @@ export type FirestoreDateNumberFieldConfig = DefaultMapConfiguredFirestoreFieldC
360
477
  readonly toDate: (input: number) => Date;
361
478
  };
362
479
  /**
363
- * Creates a field mapping configuration for Firestore date fields.
480
+ * Creates a field mapping configuration for Firestore date fields stored as numbers.
364
481
  *
365
- * Handles conversion between JavaScript Date objects and ISO8601 strings stored in Firestore.
482
+ * Handles conversion between JavaScript Date objects and numeric representations
483
+ * using the provided `fromDate`/`toDate` conversion functions.
366
484
  *
367
- * @param config - Configuration for the date field
368
- * @returns A field mapping configuration for Date values
485
+ * @param config - Configuration including custom Date-to-number conversion functions
486
+ * @returns A field mapping configuration for Date values stored as numbers
369
487
  */
370
488
  export declare function firestoreDateNumber(config: FirestoreDateNumberFieldConfig): FirestoreModelFieldMapFunctionsConfig<Date, number>;
371
489
  /**
@@ -466,9 +584,20 @@ export type FirestoreArrayFieldConfig<T> = DefaultMapConfiguredFirestoreFieldCon
466
584
  /**
467
585
  * Creates a field mapping configuration for Firestore array fields.
468
586
  *
587
+ * Defaults to an empty array when the field is missing. Supports optional sorting
588
+ * via `sortWith` which is applied on both read and write.
589
+ *
469
590
  * @template T - Type of elements in the array
470
591
  * @param config - Configuration for the array field
471
592
  * @returns A field mapping configuration for array values
593
+ *
594
+ * @example
595
+ * ```ts
596
+ * // Array of strings sorted alphabetically
597
+ * const tagsField = firestoreArray<string>({
598
+ * sortWith: (a, b) => a.localeCompare(b)
599
+ * });
600
+ * ```
472
601
  */
473
602
  export declare function firestoreArray<T>(config: FirestoreArrayFieldConfig<T>): FirestoreModelFieldMapFunctionsConfig<T[], T[]>;
474
603
  /**
@@ -551,13 +680,7 @@ export declare function firestoreUniqueKeyedArray<T, K extends PrimativeKey = Pr
551
680
  */
552
681
  export type FirestoreEnumArrayFieldConfig<S extends string | number> = Omit<FirestoreUniqueArrayFieldConfig<S>, 'filterUnique'>;
553
682
  /**
554
- * FirestoreField configuration for an array of unique enum values.
555
- *
556
- * @param config
557
- * @returns
558
- */
559
- /**
560
- * Creates a field mapping configuration for Firestore array fields of enum values.
683
+ * Creates a field mapping configuration for Firestore array fields of unique enum values.
561
684
  *
562
685
  * @template S - Enum type (string or number)
563
686
  * @param config - Configuration for the enum array field
@@ -578,7 +701,14 @@ export type FirestoreUniqueStringArrayFieldConfig<S extends string = string> = O
578
701
  * @returns A field mapping configuration for unique string array values
579
702
  */
580
703
  export declare function firestoreUniqueStringArray<S extends string = string>(config?: FirestoreUniqueStringArrayFieldConfig<S>): FirestoreModelFieldMapFunctionsConfig<S[], S[]>;
704
+ /**
705
+ * Pre-built field mapping for arrays of unique Firestore model key strings.
706
+ */
581
707
  export declare const firestoreModelKeyArrayField: FirestoreModelFieldMapFunctionsConfig<string[], string[]>;
708
+ /**
709
+ * Pre-built field mapping for arrays of unique Firestore model ID strings.
710
+ * Alias for {@link firestoreModelKeyArrayField}.
711
+ */
582
712
  export declare const firestoreModelIdArrayField: FirestoreModelFieldMapFunctionsConfig<string[], string[]>;
583
713
  /**
584
714
  * Configuration for a Firestore array field of unique number values.
@@ -615,16 +745,11 @@ export type FirestoreEncodedArrayFieldConfig<T, E extends string | number> = Def
615
745
  toData: MapFunction<T, E>;
616
746
  };
617
747
  };
618
- /**
619
- * A Firestore array that encodes values to either string or number values using another FirestoreModelField config for encoding/decoding.
620
- *
621
- * @param config
622
- * @returns
623
- */
624
748
  /**
625
749
  * Creates a field mapping configuration for Firestore array fields with custom encoding.
626
750
  *
627
- * A Firestore array that encodes values to either string or number values using another FirestoreModelField config for encoding/decoding.
751
+ * Encodes model values to string or number representations for storage, and decodes them on read.
752
+ * Useful when the model type is richer than what should be stored directly in Firestore.
628
753
  *
629
754
  * @template T - Type of elements in the model array
630
755
  * @template E - Type of encoded elements in Firestore (string or number)
@@ -645,15 +770,10 @@ export type FirestoreDencoderArrayFieldConfig<D extends PrimativeKey, E extends
645
770
  readonly dencoder: PrimativeKeyDencoderFunction<D, E>;
646
771
  };
647
772
  /**
648
- * An array that is stored as an array of encoded values using a PrimativeKeyDencoderFunction.
649
- *
650
- * @param config
651
- * @returns
652
- */
653
- /**
654
- * Creates a field mapping configuration for Firestore array fields with primative key encoding/decoding.
773
+ * Creates a field mapping configuration for Firestore array fields using a dencoder (encode/decode) function.
655
774
  *
656
- * An array that is stored as an array of encoded values using a PrimativeKeyDencoderFunction.
775
+ * The dencoder is a single function that handles both encoding (model Firestore) and decoding
776
+ * (Firestore → model) directions, leveraging {@link PrimativeKeyDencoderFunction}.
657
777
  *
658
778
  * @template D - Type of decoded elements in the model array
659
779
  * @template E - Type of encoded elements in Firestore
@@ -687,9 +807,15 @@ export type FirestoreDencoderStringArrayFieldConfig<D extends PrimativeKey, E ex
687
807
  */
688
808
  export declare function firestoreDencoderStringArray<D extends PrimativeKey, E extends PrimativeKey, S extends string = string>(config: FirestoreDencoderStringArrayFieldConfig<D, E, S>): FirestoreModelFieldMapFunctionsConfig<D[], S>;
689
809
  /**
690
- * Firestore/JSON maps only have string keys.
810
+ * A Firestore map type. Firestore/JSON maps only support string keys.
811
+ *
812
+ * @template T - Value type in the map
813
+ * @template K - Key type (must extend string)
691
814
  */
692
815
  export type FirestoreMapFieldType<T, K extends string = string> = Record<K, T>;
816
+ /**
817
+ * Configuration for a {@link firestoreMap} field.
818
+ */
693
819
  export type FirestoreMapFieldConfig<T, K extends string = string> = DefaultMapConfiguredFirestoreFieldConfig<FirestoreMapFieldType<T, K>, FirestoreMapFieldType<T, K>> & Partial<FirestoreFieldDefault<FirestoreMapFieldType<T, K>>> & {
694
820
  /**
695
821
  * Optional filter to apply when saving to data.
@@ -703,12 +829,23 @@ export type FirestoreMapFieldConfig<T, K extends string = string> = DefaultMapCo
703
829
  readonly mapFieldValues?: MapFunction<Maybe<T>, Maybe<T>>;
704
830
  };
705
831
  /**
706
- * FirestoreField configuration for a map-type object.
832
+ * Creates a field mapping configuration for Firestore map-type (key-value object) fields.
833
+ *
834
+ * By default, removes all null/undefined keys from the object before saving to Firestore.
835
+ * Defaults to an empty object `{}` when the field is missing.
707
836
  *
708
- * By default it will remove all null/undefined keys from objects before saving.
837
+ * @template T - Value type in the map
838
+ * @template K - Key type (must be string, as Firestore maps only have string keys)
839
+ * @param config - Configuration for the map field
840
+ * @returns A field mapping configuration for map values
709
841
  *
710
- * @param config
711
- * @returns
842
+ * @example
843
+ * ```ts
844
+ * // Map of user preferences
845
+ * const prefsField = firestoreMap<string>({
846
+ * mapFilter: KeyValueTypleValueFilter.EMPTY
847
+ * });
848
+ * ```
712
849
  */
713
850
  export declare function firestoreMap<T, K extends string = string>(config?: FirestoreMapFieldConfig<T, K>): FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<T, K>, FirestoreMapFieldType<T, K>>;
714
851
  /**
@@ -724,7 +861,7 @@ export declare function firestoreModelKeyGrantedRoleMap<R extends GrantedRole>()
724
861
  */
725
862
  export declare const firestoreModelIdGrantedRoleMap: () => FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<ModelKey, string>, FirestoreMapFieldType<ModelKey, string>>;
726
863
  /**
727
- * Firestore/JSON maps only have string keys.
864
+ * A Firestore map type where values are encoded from type `T` to type `E` for storage.
728
865
  */
729
866
  export type FirestoreEncodedObjectMapFieldValueType<T, S extends string = string> = Record<S, T>;
730
867
  export type FirestoreEncodedObjectMapFieldConfig<T, E, S extends string = string> = DefaultMapConfiguredFirestoreFieldConfig<FirestoreEncodedObjectMapFieldValueType<T, S>, FirestoreMapFieldType<E, S>> & Partial<FirestoreFieldDefault<FirestoreEncodedObjectMapFieldValueType<T, S>>> & {
@@ -744,12 +881,16 @@ export type FirestoreEncodedObjectMapFieldConfig<T, E, S extends string = string
744
881
  readonly decoder: MapFunction<E, T>;
745
882
  };
746
883
  /**
747
- * FirestoreField configuration for a map-type object that uses an encoder/decoder to encode/decode values.
884
+ * Creates a field mapping configuration for Firestore map fields with encoded values.
748
885
  *
749
- * By default it will remove all null/undefined keys from objects before saving.
886
+ * Each value in the map is encoded/decoded using the provided `encoder`/`decoder` functions.
887
+ * By default, removes all empty/null keys from the map before saving.
750
888
  *
751
- * @param config
752
- * @returns
889
+ * @template T - Decoded value type in the model
890
+ * @template E - Encoded value type in Firestore
891
+ * @template S - Key type (string, defaults to string)
892
+ * @param config - Configuration including encoder/decoder functions
893
+ * @returns A field mapping configuration for encoded map values
753
894
  */
754
895
  export declare function firestoreEncodedObjectMap<T, E, S extends string = string>(config: FirestoreEncodedObjectMapFieldConfig<T, E, S>): FirestoreModelFieldMapFunctionsConfig<FirestoreEncodedObjectMapFieldValueType<T, S>, FirestoreMapFieldType<E, S>>;
755
896
  export type FirestoreDencoderMapFieldValueType<D extends PrimativeKey, S extends string = string> = FirestoreEncodedObjectMapFieldValueType<D[], S>;
@@ -760,12 +901,16 @@ export type FirestoreDencoderMapFieldConfig<D extends PrimativeKey, E extends Pr
760
901
  readonly dencoder: PrimativeKeyStringDencoderFunction<D, E>;
761
902
  };
762
903
  /**
763
- * FirestoreField configuration for a map-type object that uses a Dencoder to encode/decode values.
904
+ * Creates a field mapping configuration for Firestore map fields using a dencoder function.
764
905
  *
765
- * By default it will remove all null/undefined keys from objects before saving.
906
+ * Similar to {@link firestoreEncodedObjectMap} but uses a single dencoder function for both
907
+ * encoding and decoding directions. By default, removes all empty/null keys from the map before saving.
766
908
  *
767
- * @param config
768
- * @returns
909
+ * @template D - Decoded primative key type
910
+ * @template E - Encoded primative key type
911
+ * @template S - Key type for the map (string, defaults to string)
912
+ * @param config - Configuration including the dencoder function
913
+ * @returns A field mapping configuration for dencoder-mapped values
769
914
  */
770
915
  export declare function firestoreDencoderMap<D extends PrimativeKey, E extends PrimativeKey, S extends string = string>(config: FirestoreDencoderMapFieldConfig<D, E, S>): FirestoreModelFieldMapFunctionsConfig<FirestoreEncodedObjectMapFieldValueType<D[], S>, FirestoreMapFieldType<E, S>>;
771
916
  /**
@@ -775,13 +920,20 @@ export declare function firestoreDencoderMap<D extends PrimativeKey, E extends P
775
920
  */
776
921
  export declare function firestoreModelKeyEncodedGrantedRoleMap<D extends GrantedRole, E extends string>(dencoder: PrimativeKeyStringDencoderFunction<D, E>): FirestoreModelFieldMapFunctionsConfig<FirestoreEncodedObjectMapFieldValueType<D[], string>, FirestoreMapFieldType<E, string>>;
777
922
  /**
778
- * FirestoreField configuration for a map-type object with array values.
779
- *
780
- * @param config
781
- * @returns
923
+ * A Firestore map where each value is an array of `T`.
782
924
  */
783
925
  export type FirestoreArrayMapFieldType<T, K extends string = string> = FirestoreMapFieldType<T[], K>;
784
926
  export type FirestoreArrayMapFieldConfig<T, K extends string = string> = FirestoreMapFieldConfig<T[], K>;
927
+ /**
928
+ * Creates a field mapping configuration for Firestore map fields where each value is an array.
929
+ *
930
+ * Defaults to filtering empty arrays and null/undefined elements from each array before saving.
931
+ *
932
+ * @template T - Element type in the array values
933
+ * @template K - Key type for the map (string)
934
+ * @param config - Configuration for the array map field
935
+ * @returns A field mapping configuration for map values with array entries
936
+ */
785
937
  export declare function firestoreArrayMap<T, K extends string = string>(config?: FirestoreArrayMapFieldConfig<T, K>): FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<T[], K>, FirestoreMapFieldType<T[], K>>;
786
938
  /**
787
939
  * FirestoreField configuration for a map of granted roles, keyed by models keys.
@@ -820,12 +972,35 @@ export type FirestoreObjectArrayFieldConfigFirestoreFieldInput<T extends object,
820
972
  */
821
973
  readonly firestoreField: FirestoreModelFieldMapFunctionsConfig<T, O>;
822
974
  };
975
+ /**
976
+ * Converts a {@link FirestoreModelFieldMapFunctionsConfig} into a {@link ModelMapFunctionsRef}.
977
+ *
978
+ * Used internally by {@link firestoreObjectArray} to adapt field configs into the map functions
979
+ * format needed for array element conversion.
980
+ */
823
981
  export declare function firestoreFieldConfigToModelMapFunctionsRef<T extends object, O extends object = FirestoreModelData<T>>(config: FirestoreModelFieldMapFunctionsConfig<T, O>): ModelMapFunctionsRef<T, O>;
824
982
  /**
825
- * A Firestore array that maps each array value using another FirestoreFieldConfig config.
983
+ * Creates a field mapping configuration for Firestore arrays of complex objects.
826
984
  *
827
- * @param config
828
- * @returns
985
+ * Each element in the array is converted using its own set of field converters (via `objectField`
986
+ * or `firestoreField`), enabling type-safe conversion of embedded document arrays.
987
+ * Supports optional unique filtering and sorting.
988
+ *
989
+ * On write, null/undefined values are filtered from each object to match Firestore semantics.
990
+ *
991
+ * @template T - The element model type
992
+ * @template O - The element Firestore data type (defaults to FirestoreModelData<T>)
993
+ * @param config - Configuration including element conversions and optional filtering/sorting
994
+ * @returns A field mapping configuration for object array values
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * // Array of embedded item objects
999
+ * const itemsField = firestoreObjectArray<NotificationItem>({
1000
+ * objectField: notificationItemFields,
1001
+ * sortWith: sortAscendingIndexNumberRefFunction()
1002
+ * });
1003
+ * ```
829
1004
  */
830
1005
  export declare function firestoreObjectArray<T extends object, O extends object = FirestoreModelData<T>>(config: FirestoreObjectArrayFieldConfig<T, O>): FirestoreModelFieldMapFunctionsConfig<T[], O[]>;
831
1006
  /**
@@ -845,20 +1020,45 @@ export type FirestoreSubObjectFieldConfig<T extends object, O extends object = F
845
1020
  };
846
1021
  export type FirestoreSubObjectFieldMapFunctionsConfig<T extends object, O extends object = FirestoreModelData<T>> = FirestoreModelFieldMapFunctionsConfig<T, O> & ModelMapFunctionsRef<T, O>;
847
1022
  /**
848
- * A nested object field that uses other FirestoreFieldConfig configurations to map a field.
1023
+ * Creates a field mapping configuration for nested Firestore object fields.
1024
+ *
1025
+ * Maps a nested object using its own set of field converters, enabling recursive type-safe
1026
+ * conversion of embedded documents. The `objectField` defines the conversion rules for
1027
+ * the nested object's fields using the same converter patterns.
1028
+ *
1029
+ * @template T - The nested model type
1030
+ * @template O - The nested Firestore data type (defaults to FirestoreModelData<T>)
1031
+ * @param config - Configuration including nested field conversions
1032
+ * @returns A field mapping configuration with both field config and map functions
1033
+ *
1034
+ * @example
1035
+ * ```ts
1036
+ * // Nested address object with its own converters
1037
+ * const addressField = firestoreSubObject<Address>({
1038
+ * objectField: {
1039
+ * street: firestoreString(),
1040
+ * city: firestoreString(),
1041
+ * zip: firestoreString()
1042
+ * }
1043
+ * });
1044
+ * ```
849
1045
  */
850
1046
  export declare function firestoreSubObject<T extends object, O extends object = FirestoreModelData<T>>(config: FirestoreSubObjectFieldConfig<T, O>): FirestoreSubObjectFieldMapFunctionsConfig<T, O>;
851
1047
  export interface FirestoreLatLngStringConfig extends DefaultMapConfiguredFirestoreFieldConfig<LatLngString, LatLngString> {
852
1048
  precision?: LatLngPrecision;
853
1049
  }
854
1050
  /**
855
- * Configuration for a LatLngString field.
1051
+ * Creates a field mapping configuration for Firestore latitude/longitude string fields.
1052
+ *
1053
+ * Stores lat/lng as a single string rather than a lat/lng object or value pair. This is preferred
1054
+ * because Firestore cannot efficiently sort/search lat and lng together, making indexing on separate
1055
+ * fields useless. As a single string field, it integrates with the {@link LatLngStringRef} interface
1056
+ * and can be mapped using `latLngDataPointFunction()`.
856
1057
  *
857
- * NOTE: The preference is to store LatLng values as strings as opposed to a lat/lng object or value pair as we could not sort/search lat and lng together, so indexing on them is useless.
858
- * By storing them as a string we can add lat/lng to an object (implements the LatLngStringRef interface) using a single field, and can easily utilize the data object(s) using latLngDataPointFunction() to map the input.
1058
+ * Applies validation and optional precision rounding on both read and write.
859
1059
  *
860
- * @param config
861
- * @returns
1060
+ * @param config - Optional precision and default value configuration
1061
+ * @returns A field mapping configuration for LatLngString values
862
1062
  */
863
1063
  export declare function firestoreLatLngString(config?: FirestoreLatLngStringConfig): FirestoreModelFieldMapFunctionsConfig<`${number},${number}`, `${number},${number}`>;
864
1064
  export type FirestoreTimezoneStringConfig = DefaultMapConfiguredFirestoreFieldConfig<TimezoneString, TimezoneString>;