@dereekb/firebase 13.2.2 → 13.3.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 (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
@@ -7,6 +7,17 @@ import { type StoragePathRef, type StoragePath } from '../../common/storage/stor
7
7
  import { type FirebaseAuthOwnershipKey, type FirebaseAuthUserId } from '../../common/auth/auth';
8
8
  import { type StorageFilePurposeSubgroup, type StorageFileGroupId, type StorageFileGroupRelatedStorageFilePurpose, type StorageFileMetadata, type StorageFilePurpose } from './storagefile.id';
9
9
  import { type ReadFirestoreModelKeyInput } from '../../common';
10
+ /**
11
+ * Input for creating a StorageFile document paired with its storage path.
12
+ *
13
+ * Provides all the fields needed to create a fully-configured {@link StorageFile} Firestore document,
14
+ * including ownership, purpose, group membership, and processing state.
15
+ *
16
+ * Either a `file`, `storagePathRef`, or `storagePath` must be provided to identify the storage location.
17
+ * Either an `accessor` or `context` must be provided for Firestore document creation.
18
+ *
19
+ * @template M - type of arbitrary metadata stored in the `d` field
20
+ */
10
21
  export interface CreateStorageFileDocumentPairInput<M extends StorageFileMetadata = StorageFileMetadata> {
11
22
  /**
12
23
  * Optional "now" value that is assigned to the "cat" value, created at time.
@@ -111,6 +122,9 @@ export interface CreateStorageFileDocumentPairInput<M extends StorageFileMetadat
111
122
  */
112
123
  readonly accessor?: FirestoreDocumentAccessor<StorageFile, StorageFileDocument>;
113
124
  }
125
+ /**
126
+ * Result of creating a StorageFile document pair, containing the document and its template data.
127
+ */
114
128
  export interface CreateStorageFileDocumentPairResult<M extends StorageFileMetadata = StorageFileMetadata> {
115
129
  /**
116
130
  * The StorageFileDocument that was created.
@@ -121,6 +135,10 @@ export interface CreateStorageFileDocumentPairResult<M extends StorageFileMetada
121
135
  */
122
136
  readonly storageFile: StorageFile<M>;
123
137
  }
138
+ /**
139
+ * Configuration for {@link createStorageFileDocumentPairFactory}, controlling default values
140
+ * for creation type, purpose subgroup, and processing state.
141
+ */
124
142
  export interface CreateStorageFileDocumentPairFactoryConfig {
125
143
  /**
126
144
  * The default creation type to use.
@@ -146,10 +164,29 @@ export interface CreateStorageFileDocumentPairFactoryConfig {
146
164
  */
147
165
  export type CreateStorageFileDocumentPairFactory = <M extends StorageFileMetadata = StorageFileMetadata>(input: CreateStorageFileDocumentPairInput<M>) => Promise<CreateStorageFileDocumentPairResult<M>>;
148
166
  /**
149
- * Creates a CreateStorageFileDocumentPairFactory.
167
+ * Creates a factory for producing StorageFile document pairs with pre-configured defaults.
168
+ *
169
+ * The factory handles document ID generation (random for direct creation, deterministic for
170
+ * {@link StorageFileCreationType.FOR_STORAGE_FILE_GROUP}), storage path resolution, and
171
+ * initial state setup.
172
+ *
173
+ * @param config - optional defaults for creation type, subgroup, and processing state
174
+ * @throws {Error} When neither accessor nor context is provided
175
+ * @throws {Error} When no storage path can be resolved from the input
176
+ * @throws {Error} When FOR_STORAGE_FILE_GROUP is used without parentStorageFileGroup or purpose
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const factory = createStorageFileDocumentPairFactory({
181
+ * defaultShouldBeProcessed: true
182
+ * });
150
183
  *
151
- * @param config
152
- * @returns
184
+ * const { storageFileDocument, storageFile } = await factory({
185
+ * storagePath: { bucketId: 'my-bucket', pathString: '/files/report.pdf' },
186
+ * purpose: 'report',
187
+ * context: collections
188
+ * });
189
+ * ```
153
190
  */
154
191
  export declare function createStorageFileDocumentPairFactory(config?: CreateStorageFileDocumentPairFactoryConfig): CreateStorageFileDocumentPairFactory;
155
192
  /**
@@ -3,10 +3,33 @@ import { type GrantedReadRole, type GrantedUpdateRole } from '@dereekb/model';
3
3
  import { AbstractFirestoreDocument, type CollectionReference, type FirestoreCollection, type FirestoreContext, type FirebaseAuthUserId, type FirebaseAuthOwnershipKey, type StoragePath, type StorageSignedDownloadUrl, type StorageDownloadUrl, type SavedToFirestoreIfTrue, type OneWayFlatFirestoreModelKey, type FirestoreCollectionModelKey } from '../../common';
4
4
  import { type StorageFilePurposeSubgroup, type StorageFileGroupId, type StorageFileGroupRelatedStorageFilePurpose, type StorageFileId, type StorageFileMetadata, type StorageFilePurpose, type StorageFileDisplayName } from './storagefile.id';
5
5
  import { type NotificationKey } from '../notification';
6
+ /**
7
+ * @module storagefile
8
+ *
9
+ * Defines the StorageFile and StorageFileGroup Firestore models for managing files in Google Cloud Storage.
10
+ *
11
+ * **StorageFile** tracks individual files with ownership, state machine (INIT → OK → QUEUED_FOR_DELETE),
12
+ * processing lifecycle (INIT_OR_NONE → QUEUED → PROCESSING → SUCCESS/FAILED), and group membership.
13
+ * Files are created either directly, from uploads, or for a {@link StorageFileGroup}.
14
+ *
15
+ * **StorageFileGroup** aggregates multiple StorageFiles around a related model (e.g., a user or entity).
16
+ * Groups support automatic zip generation and content regeneration via the `re` flag.
17
+ *
18
+ * Server-side processing is handled via NotificationTask integration — see `@dereekb/firebase-server/model`
19
+ * for the StorageFile action service.
20
+ */
21
+ /**
22
+ * Abstract base providing access to StorageFile and StorageFileGroup Firestore collections.
23
+ *
24
+ * Implement this in your app module to wire up the collections for dependency injection.
25
+ */
6
26
  export declare abstract class StorageFileFirestoreCollections {
7
27
  abstract readonly storageFileCollection: StorageFileFirestoreCollection;
8
28
  abstract readonly storageFileGroupCollection: StorageFileGroupFirestoreCollection;
9
29
  }
30
+ /**
31
+ * Union of all StorageFile-related model identity types.
32
+ */
10
33
  export type StorageFileTypes = typeof storageFileIdentity | typeof storageFileGroupIdentity;
11
34
  /**
12
35
  * StorageFile-related model that is initialized asynchronously at a later time.
@@ -65,7 +88,10 @@ export interface StorageFileRelatedFileMetadata {
65
88
  readonly [STORAGEFILE_RELATED_FILE_METADATA_KEY]?: Maybe<StorageFileId>;
66
89
  }
67
90
  /**
68
- * The current file state.
91
+ * How a StorageFile was created, which affects document ID generation and initialization behavior.
92
+ *
93
+ * When {@link FOR_STORAGE_FILE_GROUP} is used, the StorageFile ID is derived deterministically
94
+ * from the parent StorageFileGroup, enabling predictable document references.
69
95
  */
70
96
  export declare enum StorageFileCreationType {
71
97
  /**
@@ -89,7 +115,13 @@ export declare enum StorageFileCreationType {
89
115
  FOR_STORAGE_FILE_GROUP = 3
90
116
  }
91
117
  /**
92
- * The current file state.
118
+ * Lifecycle state of a StorageFile document.
119
+ *
120
+ * State transitions:
121
+ * - `INIT` → `OK` (successful initialization) or `INVALID` (failed initialization)
122
+ * - `OK` → `QUEUED_FOR_DELETE` (flagged for deletion)
123
+ * - `INVALID` → (deleted after a period)
124
+ * - `QUEUED_FOR_DELETE` → (deleted once `sdat` is reached)
93
125
  */
94
126
  export declare enum StorageFileState {
95
127
  /**
@@ -114,7 +146,17 @@ export declare enum StorageFileState {
114
146
  QUEUED_FOR_DELETE = 3
115
147
  }
116
148
  /**
117
- * The current processing state of the file.
149
+ * Processing lifecycle state for a StorageFile.
150
+ *
151
+ * Processing is driven by NotificationTask integration. State transitions:
152
+ * - `INIT_OR_NONE` → `QUEUED_FOR_PROCESSING` (flagged for processing)
153
+ * - `QUEUED_FOR_PROCESSING` → `PROCESSING` (NotificationTask created)
154
+ * - `PROCESSING` → `SUCCESS` or `FAILED`
155
+ * - `FAILED` → `QUEUED_FOR_PROCESSING` (retry) or `DO_NOT_PROCESS`
156
+ * - `SUCCESS` → `QUEUED_FOR_PROCESSING` (reprocess) or `ARCHIVED`
157
+ * - `ARCHIVED` and `DO_NOT_PROCESS` are terminal states.
158
+ *
159
+ * Use {@link canQueueStorageFileForProcessing} to check if a file can be re-queued.
118
160
  */
119
161
  export declare enum StorageFileProcessingState {
120
162
  /**
@@ -155,19 +197,26 @@ export declare enum StorageFileProcessingState {
155
197
  DO_NOT_PROCESS = 6
156
198
  }
157
199
  /**
158
- * If true, the StorageFile can safely be re-queued for processing.
200
+ * Checks whether a StorageFile can safely be re-queued for processing.
201
+ *
202
+ * A file is eligible when it has a purpose set and its processing state allows re-queuing
203
+ * (INIT_OR_NONE, FAILED, or SUCCESS). Files that are already QUEUED/PROCESSING, ARCHIVED,
204
+ * or DO_NOT_PROCESS are not eligible.
159
205
  *
160
- * Requirements:
161
- * - Has a purpose
162
- * - The processing state is not already queued for processing, or processing.
163
- * - The processing state is not archived or marked as do not process, as these should never be re-processed.
206
+ * @param storageFile - the file's processing state (`ps`) and purpose (`p`) fields
207
+ * @returns true if the file can be queued for processing
164
208
  *
165
- * @param state
166
- * @returns
209
+ * @example
210
+ * ```ts
211
+ * if (canQueueStorageFileForProcessing(storageFile)) {
212
+ * // safe to set ps = QUEUED_FOR_PROCESSING
213
+ * }
214
+ * ```
167
215
  */
168
216
  export declare function canQueueStorageFileForProcessing(storageFile: Pick<StorageFile, 'ps' | 'p'>): boolean;
169
217
  /**
170
- * After 3 hours of being in the PROCESSING state, we can check for retring processing.
218
+ * Throttle duration (3 hours) after which a PROCESSING-state file is considered "stuck"
219
+ * and eligible for retry checks.
171
220
  */
172
221
  export declare const STORAGE_FILE_PROCESSING_STUCK_THROTTLE_CHECK_MS: number;
173
222
  /**
@@ -191,9 +240,16 @@ export type StorageFileSignedDownloadUrl = StorageSignedDownloadUrl;
191
240
  */
192
241
  export type StorageFileDownloadUrl = StorageFilePublicDownloadUrl | StorageFileSignedDownloadUrl;
193
242
  /**
194
- * A StorageFile in the system, which references a file in Google Cloud Storage.
243
+ * A StorageFile Firestore document that references a file in Google Cloud Storage.
244
+ *
245
+ * Tracks file ownership, lifecycle state ({@link StorageFileState}), processing state
246
+ * ({@link StorageFileProcessingState}), group membership, and arbitrary metadata. Extends
247
+ * {@link StoragePath} to carry the bucket and path of the underlying storage object.
248
+ *
249
+ * Server-side processing is driven by the NotificationTask system — see
250
+ * `StorageFileActionServerActions` in `@dereekb/firebase-server/model`.
195
251
  *
196
- * Contains file metadata and ownership information, along with other arbitrary metadata.
252
+ * @template M - type of the arbitrary metadata stored in the `d` field
197
253
  */
198
254
  export interface StorageFile<M extends StorageFileMetadata = StorageFileMetadata> extends StoragePath {
199
255
  /**
@@ -299,17 +355,54 @@ export interface StorageFile<M extends StorageFileMetadata = StorageFileMetadata
299
355
  * The admin_download role allows specifying additional parameters and longer expiration times.
300
356
  */
301
357
  export type StorageFileDownloadRole = 'download' | 'admin_download';
358
+ /**
359
+ * All available permission roles for StorageFile operations.
360
+ *
361
+ * Includes download roles, sync/processing roles, and standard CRUD roles.
362
+ */
302
363
  export type StorageFileRoles = StorageFileDownloadRole | 'forceSyncWithGroups' | 'syncWithGroups' | 'process' | GrantedUpdateRole | GrantedReadRole;
364
+ /**
365
+ * Firestore document wrapper for a {@link StorageFile}.
366
+ */
303
367
  export declare class StorageFileDocument extends AbstractFirestoreDocument<StorageFile, StorageFileDocument, typeof storageFileIdentity> {
304
368
  get modelIdentity(): import("../..").RootFirestoreModelIdentity<"storageFile", "sf">;
305
369
  }
370
+ /**
371
+ * Snapshot converter for {@link StorageFile} documents, handling field-level serialization
372
+ * between the application model and Firestore storage format.
373
+ */
306
374
  export declare const storageFileConverter: import("../..").SnapshotConverterFunctions<StorageFile<Readonly<Record<string, any>>>, Partial<import("@dereekb/util").ReplaceType<StorageFile<Readonly<Record<string, any>>>, import("@dereekb/util").MaybeMap<object>, any>>>;
375
+ /**
376
+ * Returns the raw Firestore CollectionReference for the StorageFile collection.
377
+ *
378
+ * @example
379
+ * ```ts
380
+ * const colRef = storageFileCollectionReference(firestoreContext);
381
+ * ```
382
+ */
307
383
  export declare function storageFileCollectionReference(context: FirestoreContext): CollectionReference<StorageFile>;
384
+ /**
385
+ * Typed FirestoreCollection for {@link StorageFile} documents.
386
+ */
308
387
  export type StorageFileFirestoreCollection = FirestoreCollection<StorageFile, StorageFileDocument>;
388
+ /**
389
+ * Creates a fully configured {@link StorageFileFirestoreCollection} with snapshot conversion and document factory.
390
+ *
391
+ * @example
392
+ * ```ts
393
+ * const collection = storageFileFirestoreCollection(firestoreContext);
394
+ * const doc = collection.documentAccessor().newDocument();
395
+ * ```
396
+ */
309
397
  export declare function storageFileFirestoreCollection(firestoreContext: FirestoreContext): StorageFileFirestoreCollection;
398
+ /**
399
+ * Model identity for the StorageFileGroup collection (collection name: `storageFileGroup`, prefix: `sfg`).
400
+ */
310
401
  export declare const storageFileGroupIdentity: import("../..").RootFirestoreModelIdentity<"storageFileGroup", "sfg">;
311
402
  /**
312
- * Current embedded state
403
+ * Represents a single StorageFile's embedding within a {@link StorageFileGroup}.
404
+ *
405
+ * Tracks when the file was added to the group and when it was last included in a zip archive.
313
406
  */
314
407
  export interface StorageFileGroupEmbeddedFile {
315
408
  /**
@@ -330,11 +423,20 @@ export interface StorageFileGroupEmbeddedFile {
330
423
  */
331
424
  zat?: Maybe<Date>;
332
425
  }
426
+ /**
427
+ * Firestore sub-object converter for {@link StorageFileGroupEmbeddedFile}, handling date serialization
428
+ * of `sat` and `zat` fields as Unix timestamp seconds.
429
+ */
333
430
  export declare const storageFileGroupEmbeddedFile: import("../..").FirestoreSubObjectFieldMapFunctionsConfig<StorageFileGroupEmbeddedFile, Partial<import("@dereekb/util").ReplaceType<StorageFileGroupEmbeddedFile, import("@dereekb/util").MaybeMap<object>, any>>>;
334
431
  /**
335
- * A group of StorageFiles.
432
+ * A group of {@link StorageFile}s aggregated around a related model or common identifier.
433
+ *
434
+ * Groups are identified by a two-way flat key derived from the related model's key
435
+ * (see {@link storageFileGroupIdForModel}). They support automatic zip file generation
436
+ * via the `z` flag and content regeneration via the `re` flag.
336
437
  *
337
- * Contains file metadata and ownership information, along with other arbitrary metadata.
438
+ * Implements {@link InitializedStorageFileModel} for async initialization tracking
439
+ * the `s` (needs sync) flag is set on creation and cleared once initialized.
338
440
  */
339
441
  export interface StorageFileGroup extends InitializedStorageFileModel {
340
442
  /**
@@ -374,13 +476,48 @@ export interface StorageFileGroup extends InitializedStorageFileModel {
374
476
  */
375
477
  c?: Maybe<SavedToFirestoreIfTrue>;
376
478
  }
479
+ /**
480
+ * Subset of {@link StorageFileGroup} fields controlling content generation flags.
481
+ */
377
482
  export type StorageFileGroupContentFlagsData = Pick<StorageFileGroup, 'z'>;
483
+ /**
484
+ * Permission roles for StorageFileGroup operations.
485
+ */
378
486
  export type StorageFileGroupRoles = 'regenerate' | GrantedReadRole;
487
+ /**
488
+ * Firestore document wrapper for a {@link StorageFileGroup}.
489
+ *
490
+ * Provides a convenience getter to infer the related model key from the group's own ID.
491
+ */
379
492
  export declare class StorageFileGroupDocument extends AbstractFirestoreDocument<StorageFileGroup, StorageFileGroupDocument, typeof storageFileGroupIdentity> {
380
493
  get modelIdentity(): import("../..").RootFirestoreModelIdentity<"storageFileGroup", "sfg">;
381
494
  get storageFileGroupRelatedModelKey(): string;
382
495
  }
496
+ /**
497
+ * Snapshot converter for {@link StorageFileGroup} documents, including nested
498
+ * {@link StorageFileGroupEmbeddedFile} array conversion.
499
+ */
383
500
  export declare const storageFileGroupConverter: import("../..").SnapshotConverterFunctions<StorageFileGroup, Partial<import("@dereekb/util").ReplaceType<StorageFileGroup, import("@dereekb/util").MaybeMap<object>, any>>>;
501
+ /**
502
+ * Returns the raw Firestore CollectionReference for the StorageFileGroup collection.
503
+ *
504
+ * @example
505
+ * ```ts
506
+ * const colRef = storageFileGroupCollectionReference(firestoreContext);
507
+ * ```
508
+ */
384
509
  export declare function storageFileGroupCollectionReference(context: FirestoreContext): CollectionReference<StorageFileGroup>;
510
+ /**
511
+ * Typed FirestoreCollection for {@link StorageFileGroup} documents.
512
+ */
385
513
  export type StorageFileGroupFirestoreCollection = FirestoreCollection<StorageFileGroup, StorageFileGroupDocument>;
514
+ /**
515
+ * Creates a fully configured {@link StorageFileGroupFirestoreCollection} with snapshot conversion and document factory.
516
+ *
517
+ * @example
518
+ * ```ts
519
+ * const collection = storageFileGroupFirestoreCollection(firestoreContext);
520
+ * const doc = collection.documentAccessor().loadDocumentForId(groupId);
521
+ * ```
522
+ */
386
523
  export declare function storageFileGroupFirestoreCollection(firestoreContext: FirestoreContext): StorageFileGroupFirestoreCollection;
@@ -3,19 +3,23 @@ import { type StoragePath } from '../../common/storage/storage';
3
3
  import { type StorageCustomMetadata } from '../../common/storage/types';
4
4
  import { type FirebaseStorageAccessorFile } from '../../common/storage/driver/accessor';
5
5
  /**
6
- * Details from the input.
6
+ * Input for a {@link StoredFileReader}, carrying the storage bucket and path of the file.
7
7
  */
8
8
  export type StoredFileReaderInput = StoragePath;
9
9
  /**
10
- * Factory function that creates a StoredFileReader from the input details.
10
+ * Factory that creates a {@link StoredFileReader} from a {@link FirebaseStorageAccessorFile}.
11
+ *
12
+ * Use {@link storedFileReaderFactory} to create an instance.
11
13
  */
12
14
  export type StoredFileReaderFactory = FactoryWithRequiredInput<StoredFileReader, FirebaseStorageAccessorFile>;
13
15
  /**
14
- * A read-only accessor for file in FirebaseStorage.
16
+ * Read-only accessor for a file in Firebase Storage.
15
17
  *
16
- * It exposes only read-only methods for accessing details about the file.
18
+ * Provides lazy-loading access to file bytes, streams, metadata, and copy operations
19
+ * without exposing write/delete methods. Metadata is cached after first load.
17
20
  *
18
- * This accessor is generally a server-side only interface.
21
+ * Primarily used server-side for upload processing and file type determination
22
+ * (see {@link UploadedFileTypeDeterminer} in `storagefile.upload.determiner.ts`).
19
23
  */
20
24
  export interface StoredFileReader {
21
25
  /**
@@ -48,8 +52,19 @@ export interface StoredFileReader {
48
52
  readonly copy: Required<FirebaseStorageAccessorFile>['copy'];
49
53
  }
50
54
  /**
51
- * Creates a StoredFileReaderFactory.
55
+ * Creates a {@link StoredFileReaderFactory} that wraps {@link FirebaseStorageAccessorFile} instances
56
+ * into read-only {@link StoredFileReader} accessors.
57
+ *
58
+ * File metadata is cached after first load; byte/stream accessors are not cached to avoid
59
+ * holding large data in memory.
60
+ *
61
+ * Should only be used server-side, as `copy` may not be available on the client.
52
62
  *
53
- * Should generally only be used on the server-side, as copy may not be available on the client-side.
63
+ * @example
64
+ * ```ts
65
+ * const factory = storedFileReaderFactory();
66
+ * const reader = factory(storageAccessorFile);
67
+ * const bytes = await reader.loadFileBytes();
68
+ * ```
54
69
  */
55
70
  export declare function storedFileReaderFactory(): StoredFileReaderFactory;
@@ -1,9 +1,38 @@
1
1
  import { type SlashPathFile, type SlashPathFolder, type SlashPath, type Maybe } from '@dereekb/util';
2
2
  import { type StorageFileGroupId } from './storagefile.id';
3
3
  /**
4
- * All StorageFileGroup generated files are stored under this root folder.
4
+ * Root folder in Firebase Storage where all StorageFileGroup-generated files are stored.
5
+ *
6
+ * Each group gets a subfolder: `/sfg/{storageFileGroupId}/`.
5
7
  */
6
8
  export declare const STORAGE_FILE_GROUP_ROOT_FOLDER_PATH: SlashPathFolder;
9
+ /**
10
+ * Builds the storage folder path for a specific StorageFileGroup, optionally with sub-paths.
11
+ *
12
+ * @param storageFileGroupId - the group's document ID
13
+ * @param subPath - optional sub-paths to append
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const folder = storageFileGroupFolderPath('abc123');
18
+ * // folder === '/sfg/abc123/'
19
+ *
20
+ * const nested = storageFileGroupFolderPath('abc123', 'output');
21
+ * // nested === '/sfg/abc123/output/'
22
+ * ```
23
+ */
7
24
  export declare function storageFileGroupFolderPath(storageFileGroupId: StorageFileGroupId, ...subPath: Maybe<SlashPath>[]): SlashPathFolder;
25
+ /**
26
+ * File name for a StorageFileGroup's generated zip archive within its folder.
27
+ */
8
28
  export declare const STORAGE_FILE_GROUP_ZIP_FILE_PATH: SlashPathFile;
29
+ /**
30
+ * Returns the full storage path for a StorageFileGroup's zip file.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const zipPath = storageFileGroupZipFileStoragePath('abc123');
35
+ * // zipPath === '/sfg/abc123/z.zip'
36
+ * ```
37
+ */
9
38
  export declare function storageFileGroupZipFileStoragePath(storageFileGroupId: StorageFileGroupId): SlashPath;
@@ -3,7 +3,10 @@ import { type StorageFileGroupId, type StorageFilePurpose } from './storagefile.
3
3
  import { type StorageFileProcessingSubtask, type StorageFileProcessingSubtaskMetadata } from './storagefile.task';
4
4
  import { type StorageFileGroupCreatedStorageFileKey } from './storagefile';
5
5
  /**
6
- * StorageFilePurpose for a StorageFileGroup's generated zip file.
6
+ * {@link StorageFilePurpose} identifier for a StorageFileGroup's generated zip file.
7
+ *
8
+ * This purpose is used to create a predictable {@link StorageFileGroupCreatedStorageFileKey}
9
+ * for the group's zip StorageFile, enabling deterministic document ID generation.
7
10
  */
8
11
  export declare const STORAGE_FILE_GROUP_ZIP_STORAGE_FILE_PURPOSE: StorageFilePurpose;
9
12
  /**
@@ -15,12 +18,27 @@ export type StorageFileGroupZipStorageFileKey = StorageFileGroupCreatedStorageFi
15
18
  */
16
19
  export declare const storageFileGroupZipStorageFileKey: import("./storagefile").StorageFileGroupCreateStorageFileKeyFactory<string>;
17
20
  /**
18
- * Metadata for the StorageFileGroupZipStorageFile.
21
+ * Metadata stored on the zip StorageFile, linking it back to its parent StorageFileGroup.
19
22
  */
20
23
  export interface StorageFileGroupZipStorageFileMetadata {
24
+ /**
25
+ * StorageFileGroup ID. ID of the StorageFileGroup that this zip file was generated for.
26
+ */
21
27
  readonly sfg: StorageFileGroupId;
22
28
  }
29
+ /**
30
+ * Subtask checkpoint identifier for the zip creation step of StorageFileGroup processing.
31
+ */
23
32
  export declare const STORAGE_FILE_GROUP_ZIP_STORAGE_FILE_PURPOSE_CREATE_ZIP_SUBTASK: StorageFileProcessingSubtask;
33
+ /**
34
+ * Type alias for the zip creation subtask checkpoint string.
35
+ */
24
36
  export type StorageFileGroupZipStorageFileProcessingSubtask = typeof STORAGE_FILE_GROUP_ZIP_STORAGE_FILE_PURPOSE_CREATE_ZIP_SUBTASK;
37
+ /**
38
+ * Metadata type for the zip creation subtask.
39
+ */
25
40
  export type StorageFileGroupZipStorageFileProcessingSubtaskMetadata = StorageFileProcessingSubtaskMetadata;
41
+ /**
42
+ * File name of the JSON metadata file stored alongside the zip in the group's storage folder.
43
+ */
26
44
  export declare const STORAGE_FILE_GROUP_ZIP_INFO_JSON_FILE_NAME: SlashPathTypedFile;
@@ -1,6 +1,21 @@
1
1
  import { type SlashPathUntypedFile } from '@dereekb/util';
2
2
  import { type FlatFirestoreModelKey, inferKeyFromTwoWayFlatFirestoreModelKey, twoWayFlatFirestoreModelKey, type FirestoreModelId, type FirestoreModelKey } from '../../common';
3
+ /**
4
+ * @module storagefile.id
5
+ *
6
+ * Defines identity types and ID generation patterns for the StorageFile and StorageFileGroup models.
7
+ *
8
+ * StorageFileGroup IDs use a two-way flat key encoding of the related model's key, enabling
9
+ * bidirectional lookup between a group and its source model via {@link storageFileGroupIdForModel}
10
+ * and {@link inferStorageFileGroupRelatedModelKey}.
11
+ */
12
+ /**
13
+ * Firestore document ID for a StorageFile.
14
+ */
3
15
  export type StorageFileId = FirestoreModelId;
16
+ /**
17
+ * Full Firestore document key (collection path + ID) for a StorageFile.
18
+ */
4
19
  export type StorageFileKey = FirestoreModelKey;
5
20
  /**
6
21
  * Arbitrary string that can be used to describe the file's purpose.
@@ -46,17 +61,41 @@ export type StorageFileGroupRelatedStorageFilePurpose = StorageFilePurpose;
46
61
  */
47
62
  export type StorageFileMetadata = Readonly<Record<string, any>>;
48
63
  /**
49
- * The StorgaeFileGroupId is a two way flat firestore model key of the object that it represents.
64
+ * A StorageFileGroup's document ID, encoded as a two-way flat Firestore model key
65
+ * of the model it represents.
50
66
  *
51
- * This identifier is used by StorageFile's to group files together based around some other model or common identifier.
67
+ * This encoding enables bidirectional lookup: given a model key you can derive the
68
+ * group ID, and given a group ID you can recover the original model key.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const groupId = storageFileGroupIdForModel('notification/abc123');
73
+ * // groupId is a flat key like "notification_abc123"
74
+ *
75
+ * const modelKey = inferStorageFileGroupRelatedModelKey(groupId);
76
+ * // modelKey === 'notification/abc123'
77
+ * ```
52
78
  */
53
79
  export type StorageFileGroupId = FlatFirestoreModelKey;
80
+ /**
81
+ * Full Firestore document key (collection path + ID) for a StorageFileGroup.
82
+ */
54
83
  export type StorageFileGroupKey = FirestoreModelKey;
55
84
  /**
56
- * Creates a StorgaeFileGroupId from the input FirestoreModelKey.
85
+ * Encodes a FirestoreModelKey into a {@link StorageFileGroupId} using two-way flat key encoding.
57
86
  *
58
- * @param modelKey
59
- * @returns
87
+ * @example
88
+ * ```ts
89
+ * const groupId = storageFileGroupIdForModel('notification/abc123');
90
+ * ```
60
91
  */
61
92
  export declare const storageFileGroupIdForModel: typeof twoWayFlatFirestoreModelKey;
93
+ /**
94
+ * Decodes a {@link StorageFileGroupId} back into the original FirestoreModelKey.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const modelKey = inferStorageFileGroupRelatedModelKey(groupId);
99
+ * ```
100
+ */
62
101
  export declare const inferStorageFileGroupRelatedModelKey: typeof inferKeyFromTwoWayFlatFirestoreModelKey;
@@ -1,13 +1,18 @@
1
1
  import { type FirebasePermissionServiceModel, type FirestoreModelKey, type GrantedRolesOtherwiseFunctionResult, type GrantRolesOtherwiseFunction, type StorageFile, type StorageFileDocument, type StorageFileRoles, type FirebaseModelContext } from '@dereekb/firebase';
2
2
  import { type Getter, type Maybe } from '@dereekb/util';
3
3
  /**
4
- * grantStorageFileRolesForUserAuthFunction() configuration
4
+ * Configuration for {@link grantStorageFileRolesForUserAuthFunction}, providing the permission
5
+ * service output, auth context, and target StorageFile document.
5
6
  */
6
7
  export interface GrantStorageFileRolesForUserAuthFunctionConfig<T extends FirebaseModelContext> {
7
8
  readonly output: FirebasePermissionServiceModel<StorageFile, StorageFileDocument>;
8
9
  readonly context: T;
9
10
  readonly model: StorageFileDocument;
10
11
  }
12
+ /**
13
+ * Input for the role granting function, specifying which roles to grant based on
14
+ * user ownership and/or ownership key matching.
15
+ */
11
16
  export interface GrantStorageFileRolesForUserAuthInput {
12
17
  /**
13
18
  * Roles to grant if the user matches the storage file user.
@@ -20,9 +25,23 @@ export interface GrantStorageFileRolesForUserAuthInput {
20
25
  }
21
26
  export type GrantStorageFileRolesForUserAuthFunction = (input: GrantStorageFileRolesForUserAuthInput) => GrantRolesOtherwiseFunction<StorageFileRoles>;
22
27
  /**
23
- * Creates a new GrantStorageFileRolesForUserAuthFunction given the input config/context.
28
+ * Creates a function that grants {@link StorageFileRoles} based on user authentication context.
29
+ *
30
+ * The returned function checks two conditions in parallel:
31
+ * 1. Whether the authenticated user matches the StorageFile's `u` (user) field
32
+ * 2. Whether the StorageFile has an ownership key (`o`) that grants additional roles
33
+ *
34
+ * Use this within a permission service to define role-based access for StorageFile operations.
35
+ *
36
+ * @param config - the permission output, auth context, and target document
24
37
  *
25
- * @param config
26
- * @returns
38
+ * @example
39
+ * ```ts
40
+ * const grantRoles = grantStorageFileRolesForUserAuthFunction({ output, context, model });
41
+ * const otherwise = grantRoles({
42
+ * rolesForStorageFileUser: () => ({ download: true, update: true }),
43
+ * rolesForStorageFileOwnershipKey: (key) => ({ read: true })
44
+ * });
45
+ * ```
27
46
  */
28
47
  export declare function grantStorageFileRolesForUserAuthFunction<T extends FirebaseModelContext>(config: GrantStorageFileRolesForUserAuthFunctionConfig<T>): GrantStorageFileRolesForUserAuthFunction;