@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
@@ -3,13 +3,33 @@ import { type FirestoreQueryConstraint } from '../../common/firestore/query/cons
3
3
  import { type StorageFilePurposeSubgroup, type StorageFilePurpose } from './storagefile.id';
4
4
  import { type FirebaseAuthUserId } from '../../common/auth/auth';
5
5
  /**
6
- * Returns a query constraint for StorageFiles that are queued for processing.
6
+ * Returns query constraints for StorageFiles with `ps == QUEUED_FOR_PROCESSING`.
7
+ *
8
+ * Used by the server action service to find files awaiting processing task creation.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const constraints = storageFilesQueuedForProcessingQuery();
13
+ * const results = await collection.query(constraints);
14
+ * ```
7
15
  */
8
16
  export declare function storageFilesQueuedForProcessingQuery(): FirestoreQueryConstraint[];
9
17
  /**
10
- * Returns a query constraint for StorageFiles that are queued for deletion and are past their scheduled delete date.
18
+ * Returns query constraints for StorageFiles whose scheduled delete date (`sdat`) has passed.
19
+ *
20
+ * Used by the cleanup service to find files ready for permanent deletion.
21
+ *
22
+ * @param now - reference time for comparison; defaults to current time
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const constraints = storageFilesQueuedForDeleteQuery();
27
+ * ```
11
28
  */
12
29
  export declare function storageFilesQueuedForDeleteQuery(now?: Maybe<Date>): FirestoreQueryConstraint[];
30
+ /**
31
+ * Input for querying StorageFiles by purpose and owning user, with optional subgroup filtering.
32
+ */
13
33
  export interface StorageFilePurposeAndUserQueryInput {
14
34
  readonly user: FirebaseAuthUserId;
15
35
  readonly purpose: StorageFilePurpose;
@@ -18,26 +38,58 @@ export interface StorageFilePurposeAndUserQueryInput {
18
38
  */
19
39
  readonly purposeSubgroup?: Maybe<StorageFilePurposeSubgroup>;
20
40
  }
41
+ /**
42
+ * Returns query constraints for StorageFiles matching a specific purpose and user,
43
+ * with optional subgroup filtering.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const constraints = storageFilePurposeAndUserQuery({
48
+ * user: 'user123',
49
+ * purpose: 'avatar'
50
+ * });
51
+ * ```
52
+ */
21
53
  export declare function storageFilePurposeAndUserQuery(input: StorageFilePurposeAndUserQueryInput): FirestoreQueryConstraint[];
54
+ /**
55
+ * Returns query constraints for StorageFiles flagged for group synchronization (`gs == true`).
56
+ *
57
+ * Used by the sync service to find files whose group memberships need to be propagated.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const constraints = storageFileFlaggedForSyncWithGroupsQuery();
62
+ * ```
63
+ */
22
64
  export declare function storageFileFlaggedForSyncWithGroupsQuery(): FirestoreQueryConstraint[];
23
65
  /**
24
- * Query for storageFileGroups that are flagged for initialization.
66
+ * Returns query constraints for StorageFileGroups that need initialization (`s == true`).
25
67
  *
26
- * @param now
27
- * @returns
68
+ * Used by the initialization service to find newly-created groups that haven't been synced yet.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const constraints = storageFileGroupsFlaggedForNeedsInitializationQuery();
73
+ * ```
28
74
  */
29
75
  export declare function storageFileGroupsFlaggedForNeedsInitializationQuery(): FirestoreQueryConstraint[];
30
76
  /**
31
- * Query for storageFileGroups that are flagged for content regeneration.
77
+ * Returns query constraints for StorageFileGroups flagged for content regeneration (`re == true`).
32
78
  *
33
- * @param now
34
- * @returns
79
+ * @example
80
+ * ```ts
81
+ * const constraints = storageFileGroupsFlaggedForContentRegenerationQuery();
82
+ * ```
35
83
  */
36
84
  export declare function storageFileGroupsFlaggedForContentRegenerationQuery(): FirestoreQueryConstraint[];
37
85
  /**
38
- * Query for storageFileGroups that are flagged as invalid.
86
+ * Returns query constraints for StorageFileGroups flagged as invalid (`fi == true`).
87
+ *
88
+ * Invalid groups are typically cleaned up (deleted along with their associated files).
39
89
  *
40
- * @param now
41
- * @returns
90
+ * @example
91
+ * ```ts
92
+ * const constraints = storageFileGroupsFlaggedInvalidQuery();
93
+ * ```
42
94
  */
43
95
  export declare function storageFileGroupsFlaggedInvalidQuery(): FirestoreQueryConstraint[];
@@ -5,19 +5,36 @@ import { type NotificationTaskType } from '../notification/notification.id';
5
5
  import { type StorageFileDocument } from './storagefile';
6
6
  import { type StorageFileId, type StorageFilePurpose } from './storagefile.id';
7
7
  import { type StoragePath } from '../../common';
8
+ /**
9
+ * NotificationTask type identifier for StorageFile processing tasks.
10
+ *
11
+ * Tasks with this type drive the StorageFile processing lifecycle, executing
12
+ * purpose-specific processing logic through the subtask checkpoint system.
13
+ */
8
14
  export declare const STORAGE_FILE_PROCESSING_NOTIFICATION_TASK_TYPE: NotificationTaskType;
9
15
  /**
10
- * A subtask checkpoint.
16
+ * Checkpoint string for a StorageFile processing subtask.
11
17
  *
12
- * It is similar to NotificationTaskCheckpointString, but is used for StorageFile processing.
18
+ * Subtasks within a StorageFile processing task use these checkpoints to track
19
+ * multi-step progress (e.g., zip creation, file conversion).
13
20
  */
14
21
  export type StorageFileProcessingSubtask = NotificationTaskSubtaskCheckpointString;
15
22
  /**
16
- * Metadata for a subtask.
23
+ * Arbitrary metadata passed to StorageFile processing subtasks.
17
24
  *
18
- * It is similar to NotificationItemMetadata, but is stored within the StorageFileProcessingNotificationTaskData and passed to the subtasks.
25
+ * Stored within {@link StorageFileProcessingNotificationTaskData} and made available
26
+ * to each subtask handler during execution.
19
27
  */
20
28
  export type StorageFileProcessingSubtaskMetadata = NotificationTaskSubtaskMetadata;
29
+ /**
30
+ * Data payload for a StorageFile processing NotificationTask.
31
+ *
32
+ * Extends the subtask data model with StorageFile-specific fields (file ID, storage path, purpose).
33
+ * The storage path and purpose are populated from the StorageFile on first task execution.
34
+ *
35
+ * @template M - subtask metadata type
36
+ * @template S - subtask checkpoint string type
37
+ */
21
38
  export interface StorageFileProcessingNotificationTaskData<M extends StorageFileProcessingSubtaskMetadata = StorageFileProcessingSubtaskMetadata, S extends StorageFileProcessingSubtask = StorageFileProcessingSubtask> extends NotificationTaskSubtaskData<M, S> {
22
39
  /**
23
40
  * The StorageFileDocument id.
@@ -36,9 +53,35 @@ export interface StorageFileProcessingNotificationTaskData<M extends StorageFile
36
53
  */
37
54
  readonly p?: Maybe<StorageFilePurpose>;
38
55
  }
56
+ /**
57
+ * Input for creating a StorageFile processing NotificationTask.
58
+ *
59
+ * Accepts the target StorageFileDocument (from which the ID and purpose are derived)
60
+ * and optional override behavior for existing tasks.
61
+ */
39
62
  export interface StorageFileProcessingNotificationTaskInput<M extends StorageFileProcessingSubtaskMetadata = StorageFileProcessingSubtaskMetadata> extends Omit<StorageFileProcessingNotificationTaskData<M>, 'storageFile' | 'p' | 'sfps'> {
40
63
  readonly storageFileDocument: StorageFileDocument;
41
64
  readonly overrideExistingTask?: Maybe<boolean>;
42
65
  }
66
+ /**
67
+ * Creates a {@link CreateNotificationTaskTemplate} for a StorageFile processing task.
68
+ *
69
+ * The created task is unique per StorageFile (only one processing task at a time).
70
+ *
71
+ * @param input - the target StorageFileDocument and optional subtask data
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const template = storageFileProcessingNotificationTaskTemplate({
76
+ * storageFileDocument: doc,
77
+ * sd: { customKey: 'value' }
78
+ * });
79
+ * ```
80
+ */
43
81
  export declare function storageFileProcessingNotificationTaskTemplate(input: StorageFileProcessingNotificationTaskInput): CreateNotificationTaskTemplate;
82
+ /**
83
+ * All NotificationTask types used by the StorageFile system.
84
+ *
85
+ * Register these with the notification task handler to enable StorageFile processing.
86
+ */
44
87
  export declare const ALL_STORAGE_FILE_NOTIFICATION_TASK_TYPES: NotificationTaskType[];
@@ -1,12 +1,19 @@
1
1
  import { type AUTH_ROLE_CLAIMS_DEFAULT_CLAIM_VALUE, type AuthRoleClaimsFactoryConfigEntrySimpleOptions } from '@dereekb/util';
2
2
  /**
3
- * Used as a flag to disable uploads for a user.
3
+ * Claim value type used to restrict file uploads for a user.
4
+ *
5
+ * When set to true in the user's custom claims, the `uploads` role is revoked
6
+ * (inverse claim pattern).
4
7
  */
5
8
  export type StorageFileUploadUserRestriction = typeof AUTH_ROLE_CLAIMS_DEFAULT_CLAIM_VALUE;
6
9
  /**
7
- * Claims value for disabling uploads for a user.
10
+ * Custom claims shape for controlling a user's file upload permission.
11
+ *
12
+ * Uses an inverse claim pattern: when `fr` is set to true, the `uploads` role
13
+ * is removed from the user, preventing file uploads. When absent or false,
14
+ * the user retains the `uploads` role by default.
8
15
  *
9
- * Can be used in conjuction with the Storage security roles to prevent users from uploading files.
16
+ * Used with Firebase Storage security rules to enforce upload restrictions.
10
17
  */
11
18
  export type StorageFileUploadUserClaims = {
12
19
  /**
@@ -21,6 +28,16 @@ export type StorageFileUploadUserClaims = {
21
28
  */
22
29
  export declare const STORAGE_FILE_UPLOAD_USER_ROLE = "uploads";
23
30
  /**
24
- * AuthRoleClaimsFactoryConfigEntrySimpleOptions configuration for adding the "uploads" role to the user when the disable uploads claim is not present.
31
+ * Pre-configured claims entry that grants the `uploads` role by default and revokes it
32
+ * when the `fr` claim is set (inverse pattern).
33
+ *
34
+ * Pass this to an `AuthRoleClaimsFactory` to integrate upload restrictions into your auth system.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * const claimsConfig = {
39
+ * fr: storageFileUploadUserSimpleClaimsConfiguration
40
+ * };
41
+ * ```
25
42
  */
26
43
  export declare const storageFileUploadUserSimpleClaimsConfiguration: AuthRoleClaimsFactoryConfigEntrySimpleOptions<StorageFileUploadUserRestriction>;
@@ -2,9 +2,12 @@ import { type FactoryWithRequiredInput, type Maybe, type SlashPath } from '@dere
2
2
  import { type StoragePath } from '../../common/storage/storage';
3
3
  import { type FirebaseAuthUserId } from '../../common';
4
4
  /**
5
- * The base path for all uploaded files.
5
+ * Root path for all uploaded files in Firebase Storage.
6
6
  *
7
- * The uploads folder is a transient folder that is cleared/processed often of files that are uploaded to it.
7
+ * Files uploaded here are transient and are processed/cleared by the upload initialization
8
+ * service. The folder structure is: `uploads/u/{userId}/{fileName}`.
9
+ *
10
+ * See {@link userUploadsFolderSlashPathFactory} for building user-specific upload paths.
8
11
  */
9
12
  export declare const UPLOADS_FOLDER_PATH = "uploads";
10
13
  /**
@@ -18,15 +21,43 @@ export declare const ALL_USER_UPLOADS_FOLDER_NAME = "u";
18
21
  */
19
22
  export declare const ALL_USER_UPLOADS_FOLDER_PATH = "uploads/u";
20
23
  /**
21
- * Creates a SlashPath for the input user's uploads folder.
24
+ * Factory that generates the uploads folder SlashPath for a given user ID.
22
25
  */
23
26
  export type UserUploadsFolderSlashPathFactory = FactoryWithRequiredInput<SlashPath, FirebaseAuthUserId>;
27
+ /**
28
+ * Creates a {@link UserUploadsFolderSlashPathFactory} that generates per-user upload folder paths.
29
+ *
30
+ * @param inputBasePath - optional custom base path; defaults to {@link ALL_USER_UPLOADS_FOLDER_PATH}
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const factory = userUploadsFolderSlashPathFactory();
35
+ * const path = factory('user123');
36
+ * // path === '/uploads/u/user123'
37
+ * ```
38
+ */
24
39
  export declare function userUploadsFolderSlashPathFactory(inputBasePath?: Maybe<string>): UserUploadsFolderSlashPathFactory;
40
+ /**
41
+ * Factory that generates a full {@link StoragePath} (with bucket) for a given user's uploads folder.
42
+ */
25
43
  export type UserUploadsFolderStoragePathFactory = FactoryWithRequiredInput<StoragePath, FirebaseAuthUserId>;
44
+ /**
45
+ * Configuration for {@link userUploadsFolderStoragePathFactory}.
46
+ */
26
47
  export interface UserUploadsFolderStoragePathFactoryConfig {
27
48
  readonly bucketId: string;
28
49
  readonly basePath?: Maybe<string>;
29
50
  }
51
+ /**
52
+ * Creates a {@link UserUploadsFolderStoragePathFactory} that includes the storage bucket ID.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const factory = userUploadsFolderStoragePathFactory({ bucketId: 'my-bucket' });
57
+ * const storagePath = factory('user123');
58
+ * // storagePath === { pathString: '/uploads/u/user123', bucketId: 'my-bucket' }
59
+ * ```
60
+ */
30
61
  export declare function userUploadsFolderStoragePathFactory({ bucketId, basePath: inputBasePath }: UserUploadsFolderStoragePathFactoryConfig): UserUploadsFolderStoragePathFactory;
31
62
  /**
32
63
  * StorageFile uploaded-file type identifier.
@@ -41,12 +72,13 @@ export declare function userUploadsFolderStoragePathFactory({ bucketId, basePath
41
72
  */
42
73
  export type UploadedFileTypeIdentifier = string;
43
74
  /**
44
- * Result type of a StorageFileInitializeFromUploadService.handleNotificationTask() call.
75
+ * Result of a `StorageFileInitializeFromUploadService.handleNotificationTask()` call,
76
+ * indicating how the upload initialization concluded.
45
77
  *
46
- * success: The file was used/processed successfully.
47
- * no_determiner_match: Could not determine the proper processor for this file.
48
- * no_initializer_configured: There was no processor configured for this file.
49
- * initializer_error: There was an error thrown during processing.
50
- * permanent_initializer_failure: The initializer failed permanently and the file should be deleted.
78
+ * - `success` file was used/processed successfully and a StorageFile was created
79
+ * - `no_determiner_match` no {@link UploadedFileTypeDeterminer} could identify this file
80
+ * - `no_initializer_configured` the file type was identified but no initializer is registered for it
81
+ * - `initializer_error` the initializer threw an error during processing
82
+ * - `permanent_initializer_failure` the initializer failed permanently; the file should be deleted
51
83
  */
52
84
  export type StorageFileInitializeFromUploadResultType = 'success' | 'no_determiner_match' | 'no_initializer_configured' | 'initializer_error' | 'permanent_initializer_failure';
@@ -3,7 +3,24 @@ import { type UploadedFileTypeIdentifier } from './storagefile.upload';
3
3
  import { type FirebaseAuthUserId, type StorageBucketId } from '../../common';
4
4
  import { type StoredFileReader } from './storagefile.file';
5
5
  /**
6
- * The level of confidence in the determined upload type.
6
+ * @module storagefile.upload.determiner
7
+ *
8
+ * Provides the upload type determination system for classifying uploaded files.
9
+ *
10
+ * Determiners inspect a file's path, name, metadata, or content to assign an
11
+ * {@link UploadedFileTypeIdentifier} with a confidence level. Multiple determiners
12
+ * can be combined via {@link combineUploadFileTypeDeterminers}, and user detection
13
+ * can be added via {@link determineUserByFolderWrapperFunction}.
14
+ *
15
+ * Built-in determiners:
16
+ * - {@link determineByFileName} — match by file name or prefix
17
+ * - {@link determineByFolderName} — match by parent folder name
18
+ * - {@link determineByFilePath} — match by full path pattern with optional bucket filtering
19
+ */
20
+ /**
21
+ * Confidence level of a file type determination. Higher values indicate higher confidence.
22
+ *
23
+ * When multiple determiners match, the one with the highest level wins.
7
24
  *
8
25
  * Higher values indicate higher confidence.
9
26
  *
@@ -66,7 +83,11 @@ export interface UploadedFileTypeDeterminerResult {
66
83
  */
67
84
  export type UploadedFileTypeDeterminationFunction = (input: StoredFileReader) => PromiseOrValue<Maybe<UploadedFileTypeDeterminerResult>>;
68
85
  /**
69
- * Determines the upload type of a StorageFile.
86
+ * Strategy interface for determining the upload type of a file in Firebase Storage.
87
+ *
88
+ * Implement custom determiners for application-specific file type classification,
89
+ * or use the built-in factory functions ({@link determineByFileName}, {@link determineByFolderName},
90
+ * {@link determineByFilePath}).
70
91
  */
71
92
  export interface UploadedFileTypeDeterminer {
72
93
  /**
@@ -105,10 +126,21 @@ export interface DetermineByFileNameConfig {
105
126
  readonly nameMatchDeterminationLevel?: Maybe<UploadedFileTypeDeterminationLevel>;
106
127
  }
107
128
  /**
108
- * Creates an UploadedFileTypeDeterminer that determines the upload type based on the file name.
129
+ * Creates a determiner that classifies files by their file name.
130
+ *
131
+ * If the match string includes a file extension (e.g., `avatar.png`), only exact matches succeed
132
+ * at {@link EXACT_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL}. Otherwise, prefix matching is used
133
+ * (e.g., `image` matches `image.png`, `image-test.jpg`) at {@link HIGH_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL}.
134
+ *
135
+ * @param config - file type, match string, and optional determination levels
109
136
  *
110
- * @param config The configuration for the determiner.
111
- * @returns The determiner.
137
+ * @example
138
+ * ```ts
139
+ * const avatarDeterminer = determineByFileName({
140
+ * fileType: 'avatar',
141
+ * match: 'avatar.png'
142
+ * });
143
+ * ```
112
144
  */
113
145
  export declare function determineByFileName(config: DetermineByFileNameConfig): UploadedFileTypeDeterminer;
114
146
  export interface DetermineByFolderNameConfig {
@@ -122,10 +154,20 @@ export interface DetermineByFolderNameConfig {
122
154
  readonly match: SlashPathPart;
123
155
  }
124
156
  /**
125
- * Creates an UploadedFileTypeDeterminer that determines the upload type based on the folder name.
157
+ * Creates a determiner that classifies files by their parent folder name.
158
+ *
159
+ * Matches at {@link EXACT_UPLOADED_FILE_TYPE_DETERMINATION_LEVEL} when the folder path
160
+ * exactly equals the configured match string.
161
+ *
162
+ * @param config - file type and folder name to match
126
163
  *
127
- * @param config The configuration for the determiner.
128
- * @returns The determiner.
164
+ * @example
165
+ * ```ts
166
+ * const photoDeterminer = determineByFolderName({
167
+ * fileType: 'photo',
168
+ * match: 'photos'
169
+ * });
170
+ * ```
129
171
  */
130
172
  export declare function determineByFolderName(config: DetermineByFolderNameConfig): UploadedFileTypeDeterminer;
131
173
  export interface DetermineByFilePathConfig {
@@ -153,10 +195,22 @@ export interface DetermineByFilePathConfig {
153
195
  readonly matchDeterminationLevel?: Maybe<UploadedFileTypeDeterminationLevel>;
154
196
  }
155
197
  /**
156
- * Creates an UploadedFileTypeDeterminer that determines the upload type based on the file name.
198
+ * Creates a determiner that classifies files by their full storage path, with optional
199
+ * bucket filtering and additional file details matching.
157
200
  *
158
- * @param config The configuration for the determiner.
159
- * @returns The determiner.
201
+ * Uses {@link slashPathPathMatcher} for path pattern matching. Most flexible of the
202
+ * built-in determiners.
203
+ *
204
+ * @param config - file type, path match config, optional bucket/file filters
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * const reportDeterminer = determineByFilePath({
209
+ * fileType: 'report',
210
+ * match: { targetPath: 'reports', matchType: 'startsWith' },
211
+ * matchBucket: (bucket) => bucket === 'my-bucket'
212
+ * });
213
+ * ```
160
214
  */
161
215
  export declare function determineByFilePath(config: DetermineByFilePathConfig): UploadedFileTypeDeterminer;
162
216
  export interface DetermineUserByFolderWrapperFunctionConfig {
@@ -198,11 +252,33 @@ export interface DetermineUserByFolderWrapperFunctionConfig {
198
252
  */
199
253
  export type DetermineUserByFolderDeterminerWrapperFunction = (determiner: UploadedFileTypeDeterminer) => UploadedFileTypeDeterminer;
200
254
  /**
201
- * Wraps a separate UploadedFileTypeDeterminer and adds user determination based on folder path structure.
255
+ * Creates a wrapper function that adds user detection to any {@link UploadedFileTypeDeterminer}
256
+ * by inspecting the folder path structure.
202
257
  *
203
- * @param config Configuration.
258
+ * Extracts the user ID from a path like `{rootFolder}/{userFolderPrefix}/{userId}/{file}`.
259
+ * If `requireUser` is true, the determination fails when no user can be detected.
260
+ *
261
+ * @param config - root folder, user prefix, and matching options
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * const addUser = determineUserByFolderWrapperFunction({
266
+ * rootFolder: 'uploads',
267
+ * userFolderPrefix: 'u'
268
+ * });
269
+ * const withUser = addUser(myDeterminer);
270
+ * ```
204
271
  */
205
272
  export declare function determineUserByFolderWrapperFunction(config: DetermineUserByFolderWrapperFunctionConfig): DetermineUserByFolderDeterminerWrapperFunction;
273
+ /**
274
+ * Convenience wrapper pre-configured for the standard uploads folder structure (`uploads/u/{userId}/...`).
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * const addUser = determineUserByUserUploadsFolderWrapperFunction();
279
+ * const withUser = addUser(myDeterminer);
280
+ * ```
281
+ */
206
282
  export declare function determineUserByUserUploadsFolderWrapperFunction(config?: Omit<DetermineUserByFolderWrapperFunctionConfig, 'rootFolder' | 'userFolderPrefix'>): DetermineUserByFolderDeterminerWrapperFunction;
207
283
  /**
208
284
  * Configuration for determineUserByFolder().
@@ -234,10 +310,17 @@ export interface LimitUploadFileTypeDeterminerConfig {
234
310
  readonly determiner: UploadedFileTypeDeterminer;
235
311
  }
236
312
  /**
237
- * Wraps an UploadedFileTypeDeterminer to only allow respond to certain file types.
313
+ * Wraps an {@link UploadedFileTypeDeterminer} to only return results for the specified file types.
314
+ *
315
+ * Useful for scoping a broad determiner to a subset of types in a specific context.
238
316
  *
239
- * @param determiner The determiner to wrap.
240
- * @param types The file types to allow.
317
+ * @param determiner - the determiner to filter
318
+ * @param types - allowed file type identifier(s)
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * const limited = limitUploadFileTypeDeterminer(broadDeterminer, ['avatar', 'photo']);
323
+ * ```
241
324
  */
242
325
  export declare function limitUploadFileTypeDeterminer(determiner: UploadedFileTypeDeterminer, types: ArrayOrValue<UploadedFileTypeIdentifier>): UploadedFileTypeDeterminer;
243
326
  export interface CombineUploadFileTypeDeterminerConfig {
@@ -261,11 +344,20 @@ export interface CombineUploadFileTypeDeterminerConfig {
261
344
  readonly completeSearchAtLevel?: Maybe<UploadedFileTypeDeterminationLevel>;
262
345
  }
263
346
  /**
264
- * Combines multiple UploadedFileTypeDeterminer instances into a single determiner.
347
+ * Combines multiple {@link UploadedFileTypeDeterminer} instances into a single determiner
348
+ * that tries each in order and returns the highest-confidence match.
349
+ *
350
+ * If only one determiner is provided, it is returned unwrapped. The search can be
351
+ * short-circuited via `completeSearchOnFirstMatch` or `completeSearchAtLevel`.
265
352
  *
266
- * If a single determiner is provided, it will be returned and not wrapped.
353
+ * @param config - determiners to combine and optional early-exit settings
267
354
  *
268
- * @param determiners The determiners to combine.
269
- * @returns The combined determiner.
355
+ * @example
356
+ * ```ts
357
+ * const combined = combineUploadFileTypeDeterminers({
358
+ * determiners: [avatarDeterminer, photoDeterminer, documentDeterminer],
359
+ * completeSearchOnFirstMatch: true
360
+ * });
361
+ * ```
270
362
  */
271
363
  export declare function combineUploadFileTypeDeterminers(config: CombineUploadFileTypeDeterminerConfig): UploadedFileTypeDeterminer;
@@ -2,6 +2,12 @@ import { type Maybe } from '@dereekb/util';
2
2
  import { type FirestoreModelKey, type FirestoreDocumentAccessor } from '../../common';
3
3
  import { type StorageFileGroupDocument, type StorageFileGroup, type StorageFileGroupEmbeddedFile } from './storagefile';
4
4
  import { type StorageFileId } from './storagefile.id';
5
+ /**
6
+ * Reference to a StorageFileGroup document, either directly or by the related model key.
7
+ *
8
+ * Used by utility functions that need to load or update a StorageFileGroup but accept
9
+ * either a pre-loaded document or a model key for lazy loading.
10
+ */
5
11
  export interface StorageFileGroupDocumentReferencePair {
6
12
  /**
7
13
  * StorageFileGroupDocument to update.
@@ -14,7 +20,27 @@ export interface StorageFileGroupDocumentReferencePair {
14
20
  */
15
21
  readonly storageFileGroupRelatedModelKey?: Maybe<FirestoreModelKey>;
16
22
  }
23
+ /**
24
+ * Resolves a {@link StorageFileGroupDocumentReferencePair} to a concrete {@link StorageFileGroupDocument}.
25
+ *
26
+ * If a document is provided directly, it is returned as-is. Otherwise, the related model key
27
+ * is converted to a group ID via {@link storageFileGroupIdForModel} and loaded from the accessor.
28
+ *
29
+ * @throws {Error} When neither storageFileGroupDocument nor storageFileGroupRelatedModelKey is provided
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const doc = loadStorageFileGroupDocumentForReferencePair(
34
+ * { storageFileGroupRelatedModelKey: 'notification/abc123' },
35
+ * accessor
36
+ * );
37
+ * ```
38
+ */
17
39
  export declare function loadStorageFileGroupDocumentForReferencePair(input: StorageFileGroupDocumentReferencePair, accessor: FirestoreDocumentAccessor<StorageFileGroup, StorageFileGroupDocument>): StorageFileGroupDocument;
40
+ /**
41
+ * Input for {@link calculateStorageFileGroupEmbeddedFileUpdate}, specifying the current group state
42
+ * and files to insert/remove.
43
+ */
18
44
  export interface CalculateStorageFileGroupEmbeddedFileUpdateInput {
19
45
  readonly storageFileGroup: Pick<StorageFileGroup, 'f' | 're' | 'z' | 'zat'>;
20
46
  readonly insert?: Maybe<(Pick<StorageFileGroupEmbeddedFile, 's'> & Partial<Omit<StorageFileGroupEmbeddedFile, 's'>>)[]>;
@@ -28,7 +54,32 @@ export interface CalculateStorageFileGroupEmbeddedFileUpdateInput {
28
54
  */
29
55
  readonly allowRecalculateRegenerateFlag?: Maybe<boolean>;
30
56
  }
57
+ /**
58
+ * Calculates the updated embedded file list and regeneration flag for a StorageFileGroup
59
+ * after inserting and/or removing files.
60
+ *
61
+ * Handles deduplication via {@link ModelRelationUtility.insertCollection}, merging new entries
62
+ * with existing ones by StorageFile ID. Automatically flags regeneration when files are removed
63
+ * or when new files haven't been added to the zip yet.
64
+ *
65
+ * @param input - current group state, files to insert/remove, and regeneration options
66
+ * @returns updated `f` (embedded files) and `re` (regeneration flag)
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const update = calculateStorageFileGroupEmbeddedFileUpdate({
71
+ * storageFileGroup: group,
72
+ * insert: [{ s: 'newFileId' }],
73
+ * remove: ['oldFileId']
74
+ * });
75
+ * // update.f = [...updated file list]
76
+ * // update.re = true (because a file was removed)
77
+ * ```
78
+ */
31
79
  export declare function calculateStorageFileGroupEmbeddedFileUpdate(input: CalculateStorageFileGroupEmbeddedFileUpdateInput): Pick<StorageFileGroup, 'f' | 're'>;
80
+ /**
81
+ * Input for {@link calculateStorageFileGroupRegeneration}.
82
+ */
32
83
  export interface CalculateStorageFileGroupRegenerationInput {
33
84
  readonly storageFileGroup: Pick<StorageFileGroup, 'f' | 'z' | 'zat'>;
34
85
  /**
@@ -47,9 +98,21 @@ export interface CalculateStorageFileGroupRegenerationResult {
47
98
  readonly flagRegenerate: boolean;
48
99
  }
49
100
  /**
50
- * Calculates the regeneration flags for a StorageFileGroup.
101
+ * Determines whether a StorageFileGroup's derived content (e.g., zip files) needs regeneration.
102
+ *
103
+ * The zip needs regeneration when:
104
+ * - `force` is true
105
+ * - The zip has never been generated (`zat` is unset) and files exist
106
+ * - Any embedded file has never been included in the zip (`zat` is unset on the entry)
107
+ *
108
+ * @param input - group state and optional force flag
51
109
  *
52
- * @param input CalculateStorageFileGroupRegenerationInput
53
- * @returns CalculateStorageFileGroupRegenerationResult
110
+ * @example
111
+ * ```ts
112
+ * const { flagRegenerate, regenerateZip } = calculateStorageFileGroupRegeneration({
113
+ * storageFileGroup: group,
114
+ * force: false
115
+ * });
116
+ * ```
54
117
  */
55
118
  export declare function calculateStorageFileGroupRegeneration(input: CalculateStorageFileGroupRegenerationInput): CalculateStorageFileGroupRegenerationResult;
@@ -1,8 +1,33 @@
1
1
  import { type AsyncFirebaseFunctionCreateAction, type AsyncFirebaseFunctionDeleteAction, type AsyncFirebaseFunctionUpdateAction, type FirebaseFunctionCreateAction, type FirebaseFunctionDeleteAction, type FirebaseFunctionUpdateAction } from '@dereekb/firebase';
2
2
  import { type SystemStateDocument } from './system';
3
+ /**
4
+ * @module system.action
5
+ *
6
+ * Type aliases for SystemState server action functions.
7
+ *
8
+ * @template P - the API parameter type for the action
9
+ */
10
+ /**
11
+ * Synchronous create action targeting a {@link SystemStateDocument}.
12
+ */
3
13
  export type SystemStateCreateAction<P extends object> = FirebaseFunctionCreateAction<P, SystemStateDocument>;
14
+ /**
15
+ * Async create action targeting a {@link SystemStateDocument}.
16
+ */
4
17
  export type AsyncSystemStateCreateAction<P extends object> = AsyncFirebaseFunctionCreateAction<P, SystemStateDocument>;
18
+ /**
19
+ * Synchronous update action targeting a {@link SystemStateDocument}.
20
+ */
5
21
  export type SystemStateUpdateAction<P extends object> = FirebaseFunctionUpdateAction<P, SystemStateDocument>;
22
+ /**
23
+ * Async update action targeting a {@link SystemStateDocument}.
24
+ */
6
25
  export type AsyncSystemStateUpdateAction<P extends object> = AsyncFirebaseFunctionUpdateAction<P, SystemStateDocument>;
26
+ /**
27
+ * Synchronous delete action targeting a {@link SystemStateDocument}.
28
+ */
7
29
  export type SystemStateDeleteAction<P extends object> = FirebaseFunctionDeleteAction<P, SystemStateDocument>;
30
+ /**
31
+ * Async delete action targeting a {@link SystemStateDocument}.
32
+ */
8
33
  export type AsyncSystemStateDeleteAction<P extends object> = AsyncFirebaseFunctionDeleteAction<P, SystemStateDocument>;