@dereekb/firebase 12.4.5 → 12.5.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 (37) hide show
  1. package/index.cjs.js +1523 -231
  2. package/index.esm.js +1458 -234
  3. package/package.json +1 -1
  4. package/src/lib/common/firestore/query/iterator.d.ts +39 -9
  5. package/src/lib/common/firestore/query/watcher.d.ts +2 -2
  6. package/src/lib/common/storage/driver/accessor.d.ts +62 -6
  7. package/src/lib/common/storage/driver/accessor.iterate.d.ts +38 -0
  8. package/src/lib/common/storage/driver/accessor.util.d.ts +14 -0
  9. package/src/lib/common/storage/driver/error.d.ts +4 -0
  10. package/src/lib/common/storage/driver/index.d.ts +2 -0
  11. package/src/lib/common/storage/driver/list.d.ts +4 -2
  12. package/src/lib/common/storage/storage.d.ts +7 -0
  13. package/src/lib/common/storage/types.d.ts +141 -32
  14. package/src/lib/model/index.d.ts +1 -0
  15. package/src/lib/model/notification/notification.api.d.ts +10 -0
  16. package/src/lib/model/notification/notification.create.d.ts +2 -2
  17. package/src/lib/model/notification/notification.item.d.ts +2 -0
  18. package/src/lib/model/notification/notification.task.d.ts +22 -8
  19. package/src/lib/model/storagefile/index.d.ts +12 -0
  20. package/src/lib/model/storagefile/storagefile.action.d.ts +8 -0
  21. package/src/lib/model/storagefile/storagefile.api.d.ts +148 -0
  22. package/src/lib/model/storagefile/storagefile.api.error.d.ts +51 -0
  23. package/src/lib/model/storagefile/storagefile.create.d.ts +121 -0
  24. package/src/lib/model/storagefile/storagefile.d.ts +164 -0
  25. package/src/lib/model/storagefile/storagefile.file.d.ts +55 -0
  26. package/src/lib/model/storagefile/storagefile.id.d.ts +20 -0
  27. package/src/lib/model/storagefile/storagefile.query.d.ts +17 -0
  28. package/src/lib/model/storagefile/storagefile.task.d.ts +67 -0
  29. package/src/lib/model/storagefile/storagefile.upload.claims.d.ts +26 -0
  30. package/src/lib/model/storagefile/storagefile.upload.d.ts +52 -0
  31. package/src/lib/model/storagefile/storagefile.upload.determiner.d.ts +271 -0
  32. package/test/CHANGELOG.md +9 -0
  33. package/test/package.json +1 -1
  34. package/test/src/lib/common/storage/storage.js +3 -3
  35. package/test/src/lib/common/storage/storage.js.map +1 -1
  36. package/test/src/lib/common/storage/test.driver.accessor.js +331 -29
  37. package/test/src/lib/common/storage/test.driver.accessor.js.map +1 -1
@@ -58,7 +58,7 @@ export interface NotificationTask<D extends NotificationItemMetadata = {}> {
58
58
  /**
59
59
  * Returns an empty array, which is used to signal that the task did not fail but has not complete the current checkpoint.
60
60
  */
61
- export declare function delayCompletion(): NotificationTaskServiceTaskHandlerCompletionType;
61
+ export declare function delayCompletion<S extends NotificationTaskCheckpointString = NotificationTaskCheckpointString>(): NotificationTaskServiceTaskHandlerCompletionType<S>;
62
62
  /**
63
63
  * Convenience function for returning a NotificationTaskServiceHandleNotificationTaskResult that says the task should be retried after the specified delay.
64
64
  *
@@ -68,7 +68,7 @@ export declare function notificationTaskDelayRetry<D extends NotificationItemMet
68
68
  /**
69
69
  * Convenience function for returning a NotificationTaskServiceHandleNotificationTaskResult that says the task was partially completed, and to process the next part in the future.
70
70
  */
71
- export declare function notificationTaskPartiallyComplete<D extends NotificationItemMetadata = {}>(completedParts: ArrayOrValue<NotificationTaskCheckpointString>, updateMetadata?: Maybe<Partial<D>>): NotificationTaskServiceHandleNotificationTaskResult<D>;
71
+ export declare function notificationTaskPartiallyComplete<D extends NotificationItemMetadata = {}, S extends NotificationTaskCheckpointString = NotificationTaskCheckpointString>(completedParts: ArrayOrValue<S>, updateMetadata?: Maybe<Partial<D>>): NotificationTaskServiceHandleNotificationTaskResult<D, S>;
72
72
  /**
73
73
  * Convenience function for returning a NotificationTaskServiceHandleNotificationTaskResult that says the task was completed successfully.
74
74
  */
@@ -77,26 +77,34 @@ export declare function notificationTaskComplete<D extends NotificationItemMetad
77
77
  * Convenience function for returning a NotificationTaskServiceHandleNotificationTaskResult that says the task failed.
78
78
  */
79
79
  export declare function notificationTaskFailed<D extends NotificationItemMetadata = {}>(updateMetadata?: Maybe<Partial<D>>, removeFromCompletedCheckpoints?: Maybe<ArrayOrValue<NotificationTaskCheckpointString>>): NotificationTaskServiceHandleNotificationTaskResult<D>;
80
+ /**
81
+ * Wraps an existing NotificationTaskServiceHandleNotificationTaskResult<D> and sets canRunNextCheckpoint to true if it is undefined.
82
+ *
83
+ * @param result The result to use as a template.
84
+ * @param force If true, then canRunNextCheckpoint will be set to true even if it is already defined.
85
+ * @returns A new result.
86
+ */
87
+ export declare function notificationTaskCanRunNextCheckpoint<D extends NotificationItemMetadata = {}>(result: NotificationTaskServiceHandleNotificationTaskResult<D>, force?: Maybe<boolean>): NotificationTaskServiceHandleNotificationTaskResult<D>;
80
88
  /**
81
89
  * One or more NotificationTaskCheckpointString values that are considered complete.
82
90
  */
83
- export type NotificationTaskServiceTaskHandlerCompletionTypeCheckpoint = ArrayOrValue<NotificationTaskCheckpointString>;
91
+ export type NotificationTaskServiceTaskHandlerCompletionTypeCheckpoint<S extends NotificationTaskCheckpointString = NotificationTaskCheckpointString> = ArrayOrValue<S>;
84
92
  /**
85
- * Result of a NotificationTaskServiceTaskHandler.handleNotificationTask() call.
93
+ * Result type of a NotificationTaskServiceTaskHandler.handleNotificationTask() call.
86
94
  *
87
95
  * true: The task was completed successfully and can now be discarded.
88
96
  * false: The task was not completed successfully and should be retried again in the future. Note there are a maximum number of retry attempts before the task is deleted. Use delayCompletion() to avoid increasing the attempt count.
89
97
  * NotificationTaskCheckpointString(s): The task has successfully completed this/these particular checkpoint(s) but is not complete and should be continued again in the future. Return an empty array to signal that the task did not fail but has not reached the next checkpoint.
90
98
  */
91
- export type NotificationTaskServiceTaskHandlerCompletionType = true | false | NotificationTaskServiceTaskHandlerCompletionTypeCheckpoint;
99
+ export type NotificationTaskServiceTaskHandlerCompletionType<S extends NotificationTaskCheckpointString = NotificationTaskCheckpointString> = true | false | NotificationTaskServiceTaskHandlerCompletionTypeCheckpoint<S>;
92
100
  /**
93
101
  * Result of a NotificationTaskServiceTaskHandler.handleNotificationTask() call.
94
102
  */
95
- export interface NotificationTaskServiceHandleNotificationTaskResult<D extends NotificationItemMetadata = {}> {
103
+ export interface NotificationTaskServiceHandleNotificationTaskResult<D extends NotificationItemMetadata = {}, S extends NotificationTaskCheckpointString = NotificationTaskCheckpointString> {
96
104
  /**
97
105
  * Completion type for the task result.
98
106
  */
99
- readonly completion: NotificationTaskServiceTaskHandlerCompletionType;
107
+ readonly completion: NotificationTaskServiceTaskHandlerCompletionType<S>;
100
108
  /**
101
109
  * If true, clears all completed checkpoints.
102
110
  */
@@ -110,7 +118,7 @@ export interface NotificationTaskServiceHandleNotificationTaskResult<D extends N
110
118
  *
111
119
  * Ignored if removeAllCompletedCheckpoints is true.
112
120
  */
113
- readonly removeFromCompletedCheckpoints?: Maybe<ArrayOrValue<NotificationTaskCheckpointString>>;
121
+ readonly removeFromCompletedCheckpoints?: Maybe<ArrayOrValue<S>>;
114
122
  /**
115
123
  * Updates the metadata for the notification item if the task is successful but not yet marked done.
116
124
  *
@@ -121,4 +129,10 @@ export interface NotificationTaskServiceHandleNotificationTaskResult<D extends N
121
129
  * Delays the next run of the task by the specified amount of time or until the given date.
122
130
  */
123
131
  readonly delayUntil?: Maybe<Date | Milliseconds>;
132
+ /**
133
+ * If true, can run the next part of the task immediately.
134
+ *
135
+ * Ignored if delayUntil is set or if the completion is true/false/empty array.
136
+ */
137
+ readonly canRunNextCheckpoint?: Maybe<boolean>;
124
138
  }
@@ -0,0 +1,12 @@
1
+ export * from './storagefile.action';
2
+ export * from './storagefile.api.error';
3
+ export * from './storagefile.api';
4
+ export * from './storagefile.create';
5
+ export * from './storagefile.id';
6
+ export * from './storagefile.query';
7
+ export * from './storagefile.task';
8
+ export * from './storagefile';
9
+ export * from './storagefile.file';
10
+ export * from './storagefile.upload';
11
+ export * from './storagefile.upload.claims';
12
+ export * from './storagefile.upload.determiner';
@@ -0,0 +1,8 @@
1
+ import { AsyncFirebaseFunctionDeleteAction, FirebaseFunctionDeleteAction, type AsyncFirebaseFunctionCreateAction, type AsyncFirebaseFunctionUpdateAction, type FirebaseFunctionCreateAction, type FirebaseFunctionUpdateAction } from '../../common';
2
+ import { type StorageFileDocument } from './storagefile';
3
+ export type StorageFileCreateAction<P extends object> = FirebaseFunctionCreateAction<P, StorageFileDocument>;
4
+ export type AsyncStorageFileCreateAction<P extends object> = AsyncFirebaseFunctionCreateAction<P, StorageFileDocument>;
5
+ export type StorageFileUpdateAction<P extends object> = FirebaseFunctionUpdateAction<P, StorageFileDocument>;
6
+ export type AsyncStorageFileUpdateAction<P extends object> = AsyncFirebaseFunctionUpdateAction<P, StorageFileDocument>;
7
+ export type StorageFileDeleteAction<P extends object> = FirebaseFunctionDeleteAction<P, StorageFileDocument>;
8
+ export type AsyncStorageFileDeleteAction<P extends object> = AsyncFirebaseFunctionDeleteAction<P, StorageFileDocument>;
@@ -0,0 +1,148 @@
1
+ import { TargetModelParams, OnCallCreateModelResult } from '../../common';
2
+ import { type ModelFirebaseCrudFunction, type FirebaseFunctionTypeConfigMap, type ModelFirebaseCrudFunctionConfigMap, type ModelFirebaseFunctionMap, ModelFirebaseCreateFunction } from '../../client';
3
+ import { StorageFileTypes } from './storagefile';
4
+ import { StorageBucketId, StoragePath, StorageSlashPath } from '../../common/storage';
5
+ import { Maybe } from '@dereekb/util';
6
+ /**
7
+ * Used for directly create a new StorageFile.
8
+ */
9
+ export declare class CreateStorageFileParams {
10
+ }
11
+ /**
12
+ * Initializes all StorageFiles in the uploads folder.
13
+ */
14
+ export declare class InitializeAllStorageFilesFromUploadsParams {
15
+ /**
16
+ * The maximum number of files to initialize at once.
17
+ */
18
+ maxFilesToInitialize?: Maybe<number>;
19
+ /**
20
+ * The specific folder under the uploads folder to search for files and initialize
21
+ */
22
+ folderPath?: Maybe<StorageSlashPath>;
23
+ /**
24
+ * Overrides the default uploads folder path.
25
+ */
26
+ overrideUploadsFolderPath?: Maybe<StorageSlashPath>;
27
+ }
28
+ export interface InitializeAllStorageFilesFromUploadsResult extends OnCallCreateModelResult {
29
+ readonly filesVisited: number;
30
+ readonly initializationsSuccessCount: number;
31
+ readonly initializationsFailureCount: number;
32
+ }
33
+ /**
34
+ * Initializes a StorageFile from the document at the given path.
35
+ */
36
+ export declare class InitializeStorageFileFromUploadParams implements Pick<StoragePath, 'pathString'> {
37
+ /**
38
+ * Specific bucketId to use.
39
+ *
40
+ * If not defined, the default bucket will be used.
41
+ */
42
+ bucketId?: Maybe<StorageBucketId>;
43
+ pathString: StorageSlashPath;
44
+ }
45
+ export declare class ProcessStorageFileParams extends TargetModelParams {
46
+ /**
47
+ * If set, will start/run the processing immediately instead of waiting for the next scheduled run.
48
+ */
49
+ runImmediately?: Maybe<boolean>;
50
+ /**
51
+ * If set, will check and retry processing if the StorageFile is in a failed processing state.
52
+ */
53
+ checkRetryProcessing?: Maybe<boolean>;
54
+ /**
55
+ * Used with retryProcessing.
56
+ *
57
+ * If set, will forcibly create a new processing task even if the existing processing task appears to be ok.
58
+ */
59
+ forceRestartProcessing?: Maybe<boolean>;
60
+ }
61
+ export interface ProcessStorageFileResult {
62
+ }
63
+ /**
64
+ * Processes all StorageFiles that are queued for processing.
65
+ */
66
+ export declare class ProcessAllQueuedStorageFilesParams {
67
+ }
68
+ export interface ProcessAllQueuedStorageFilesResult {
69
+ /**
70
+ * The total number of StorageFiles visited.
71
+ */
72
+ readonly storageFilesVisited: number;
73
+ /**
74
+ * The total number of StorageFiles that started processing.
75
+ */
76
+ readonly storageFilesProcessStarted: number;
77
+ /**
78
+ * The total number of StorageFiles that failed to start processing.
79
+ */
80
+ readonly storageFilesFailedStarting: number;
81
+ }
82
+ export declare class UpdateStorageFileParams extends TargetModelParams {
83
+ /**
84
+ * Sets the delete at time for the given StorageFileDocument, and queues the file for deletion.
85
+ */
86
+ sdat?: Maybe<Date>;
87
+ }
88
+ export declare class DeleteStorageFileParams extends TargetModelParams {
89
+ /**
90
+ * If true, will force the deletion of the StorageFile even if it is not queued for deletion.
91
+ */
92
+ force?: Maybe<boolean>;
93
+ }
94
+ /**
95
+ * Processes all StorageFiles that are queued for processing.
96
+ */
97
+ export declare class DeleteAllQueuedStorageFilesParams {
98
+ }
99
+ export interface DeleteAllQueuedStorageFilesResult {
100
+ /**
101
+ * The total number of StorageFiles visited.
102
+ */
103
+ readonly storageFilesVisited: number;
104
+ /**
105
+ * The total number of StorageFiles that were deleted.
106
+ */
107
+ readonly storageFilesDeleted: number;
108
+ /**
109
+ * The total number of StorageFiles that failed to delete.
110
+ */
111
+ readonly storageFilesFailedDeleting: number;
112
+ }
113
+ export type StorageFileFunctionTypeMap = {};
114
+ export declare const storageFileFunctionTypeConfigMap: FirebaseFunctionTypeConfigMap<StorageFileFunctionTypeMap>;
115
+ export type StorageFileModelCrudFunctionsConfig = {
116
+ readonly storageFile: {
117
+ create: {
118
+ _: CreateStorageFileParams;
119
+ fromUpload: InitializeStorageFileFromUploadParams;
120
+ allFromUpload: [InitializeAllStorageFilesFromUploadsParams, InitializeAllStorageFilesFromUploadsResult];
121
+ };
122
+ update: {
123
+ _: UpdateStorageFileParams;
124
+ process: [ProcessStorageFileParams, ProcessStorageFileResult];
125
+ };
126
+ delete: {
127
+ _: DeleteStorageFileParams;
128
+ };
129
+ };
130
+ };
131
+ export declare const storageFileModelCrudFunctionsConfig: ModelFirebaseCrudFunctionConfigMap<StorageFileModelCrudFunctionsConfig, StorageFileTypes>;
132
+ export declare abstract class StorageFileFunctions implements ModelFirebaseFunctionMap<StorageFileFunctionTypeMap, StorageFileModelCrudFunctionsConfig> {
133
+ abstract storageFile: {
134
+ createStorageFile: {
135
+ create: ModelFirebaseCreateFunction<CreateStorageFileParams, OnCallCreateModelResult>;
136
+ fromUpload: ModelFirebaseCreateFunction<InitializeStorageFileFromUploadParams, OnCallCreateModelResult>;
137
+ allFromUpload: ModelFirebaseCrudFunction<InitializeAllStorageFilesFromUploadsParams, InitializeAllStorageFilesFromUploadsResult>;
138
+ };
139
+ updateStorageFile: {
140
+ update: ModelFirebaseCrudFunction<UpdateStorageFileParams>;
141
+ process: ModelFirebaseCrudFunction<ProcessStorageFileParams, ProcessStorageFileResult>;
142
+ };
143
+ deleteStorageFile: {
144
+ delete: ModelFirebaseCrudFunction<DeleteStorageFileParams>;
145
+ };
146
+ };
147
+ }
148
+ export declare const storageFileFunctionMap: import("../../client").ModelFirebaseFunctionMapFactory<StorageFileFunctionTypeMap, StorageFileModelCrudFunctionsConfig>;
@@ -0,0 +1,51 @@
1
+ import { Maybe } from '@dereekb/util';
2
+ import { StorageFileInitializeFromUploadResultType } from './storagefile.upload';
3
+ /**
4
+ * Thrown if the target uploaded file does not exist.
5
+ */
6
+ export declare const UPLOADED_FILE_DOES_NOT_EXIST_ERROR_CODE = "UPLOADED_FILE_DOES_NOT_EXIST";
7
+ /**
8
+ * Thrown if the target uploaded file is not allowed to be initialized.
9
+ */
10
+ export declare const UPLOADED_FILE_NOT_ALLOWED_TO_BE_INITIALIZED_ERROR_CODE = "UPLOADED_FILE_NOT_ALLOWED_TO_BE_INITIALIZED";
11
+ /**
12
+ * Thrown if the target uploaded file initialization failed.
13
+ */
14
+ export declare const UPLOADED_FILE_INITIALIZATION_FAILED_ERROR_CODE = "UPLOADED_FILE_INITIALIZATION_FAILED";
15
+ export interface UploadedFileInitializationFailedErrorData {
16
+ readonly resultType: StorageFileInitializeFromUploadResultType;
17
+ /**
18
+ * True if the file was deleted.
19
+ */
20
+ readonly fileDeleted?: Maybe<boolean>;
21
+ }
22
+ /**
23
+ * Thrown if the target uploaded file initialization was successful, but produced no new StorageFileDocument.
24
+ */
25
+ export declare const UPLOADED_FILE_INITIALIZATION_DISCARDED_ERROR_CODE = "UPLOADED_FILE_INITIALIZATION_DISCARDED";
26
+ /**
27
+ * Thrown if the target StorageFileDocument is not queued for processing and is called to be processed.
28
+ */
29
+ export declare const STORAGE_FILE_PROCESSING_NOT_QUEUED_FOR_PROCESSING_ERROR_CODE = "STORAGE_FILE_PROCESSING_NOT_QUEUED_FOR_PROCESSING";
30
+ /**
31
+ * Thrown if:
32
+ * - the target StorageFileDocument was marked as queued for processing but isn't actually a processable-type.
33
+ * - the target StorageFileDocument is marked as init but has no purpose set, meaning it can't be processed.
34
+ */
35
+ export declare const STORAGE_FILE_PROCESSING_NOT_AVAILABLE_FOR_TYPE_ERROR_CODE = "STORAGE_FILE_PROCESSING_NOT_AVAILABLE_FOR_TYPE";
36
+ /**
37
+ * Thrown if the StorageFile is not in an OK state.
38
+ */
39
+ export declare const STORAGE_FILE_PROCESSING_NOT_ALLOWED_FOR_INVALID_STATE_ERROR_CODE = "STORAGE_FILE_PROCESSING_NOT_ALLOWED_FOR_INVALID_STATE";
40
+ /**
41
+ * Thrown if the target StorageFileDocument already finished processing.
42
+ */
43
+ export declare const STORAGE_FILE_ALREADY_PROCESSED_ERROR_CODE = "STORAGE_FILE_ALREADY_PROCESSED";
44
+ /**
45
+ * Thrown if the target StorageFileDocument is not flagged for deletion but attempts to be deleted.
46
+ */
47
+ export declare const STORAGE_FILE_NOT_FLAGGED_FOR_DELETION_ERROR_CODE = "STORAGE_FILE_NOT_FLAGGED_FOR_DELETION";
48
+ /**
49
+ * Thrown if the target StorageFileDocument is flagged for deletion, but has not reached the time to be deleted yet.
50
+ */
51
+ export declare const STORAGE_FILE_CANNOT_BE_DELETED_YET_ERROR_CODE = "STORAGE_FILE_CANNOT_BE_DELETED_YET";
@@ -0,0 +1,121 @@
1
+ import { type Maybe } from '@dereekb/util';
2
+ import { StorageFileCreationType, type StorageFile, type StorageFileDocument, type StorageFileFirestoreCollections } from './storagefile';
3
+ import { type Transaction } from '../../common/firestore/types';
4
+ import { type FirestoreDocumentAccessor } from '../../common/firestore/accessor/document';
5
+ import { type FirebaseStorageAccessorFile } from '../../common/storage/driver/accessor';
6
+ import { StoragePathRef, type StoragePath } from '../../common/storage/storage';
7
+ import { FirebaseAuthOwnershipKey, type FirebaseAuthUserId } from '../../common/auth/auth';
8
+ import { StorageFileMetadata, StorageFilePurpose } from './storagefile.id';
9
+ export interface CreateStorageFileDocumentPairInput<M extends StorageFileMetadata = StorageFileMetadata> {
10
+ /**
11
+ * Optional "now" value that is assigned to the "cat" value, created at time.
12
+ */
13
+ readonly now?: Maybe<Date>;
14
+ /**
15
+ * The document transaction
16
+ */
17
+ readonly transaction?: Transaction;
18
+ /**
19
+ * The storage path to set on the StorageFile template.
20
+ *
21
+ * Is ignored if file or storagePathRef is provided.
22
+ */
23
+ readonly storagePath?: StoragePath;
24
+ /**
25
+ * The ref of the storage path to set on the StorageFile template.
26
+ *
27
+ * Is ignored if file is provided.
28
+ */
29
+ readonly storagePathRef?: StoragePathRef;
30
+ /**
31
+ * File to use when creating the StorageFile.
32
+ */
33
+ readonly file?: FirebaseStorageAccessorFile;
34
+ /**
35
+ * The user that the file is associated with.
36
+ *
37
+ * Corresponds with the "u" value in the StorageFile template.
38
+ */
39
+ readonly user?: Maybe<FirebaseAuthUserId>;
40
+ /**
41
+ * The user that uploaded the file.
42
+ *
43
+ * Corresponds with the "uby" value in the StorageFile template.
44
+ */
45
+ readonly uploadedBy?: Maybe<FirebaseAuthUserId>;
46
+ /**
47
+ * The ownership key of the file.
48
+ *
49
+ * Corresponds with the "o" value in the StorageFile template.
50
+ */
51
+ readonly ownershipKey?: Maybe<FirebaseAuthOwnershipKey>;
52
+ /**
53
+ * The purpose of the file.
54
+ *
55
+ * Corresponds with the "p" value in the StorageFile template.
56
+ */
57
+ readonly purpose?: Maybe<StorageFilePurpose>;
58
+ /**
59
+ * The metadata of the file.
60
+ *
61
+ * Corresponds with the "m" value in the StorageFile template.
62
+ */
63
+ readonly metadata?: Maybe<M>;
64
+ /**
65
+ * If true, will queue the StorageFile for processing.
66
+ */
67
+ readonly shouldBeProcessed?: Maybe<boolean>;
68
+ /**
69
+ * Template details for the StorageFileDocument.
70
+ */
71
+ readonly template?: Maybe<Omit<Partial<StorageFile<M>>, 'cat'>>;
72
+ /**
73
+ * Context to create the accessor from.
74
+ */
75
+ readonly context?: Pick<StorageFileFirestoreCollections, 'storageFileCollection'>;
76
+ /**
77
+ * Accessor to use directly.
78
+ */
79
+ readonly accessor?: FirestoreDocumentAccessor<StorageFile, StorageFileDocument>;
80
+ }
81
+ export interface CreateStorageFileDocumentPairResult<M extends StorageFileMetadata = StorageFileMetadata> {
82
+ /**
83
+ * The StorageFileDocument that was created.
84
+ */
85
+ readonly storageFileDocument: StorageFileDocument;
86
+ /**
87
+ * The template that was passed to create the StorageFileDocument.
88
+ */
89
+ readonly storageFile: StorageFile<M>;
90
+ }
91
+ export interface CreateStorageFileDocumentPairFactoryConfig {
92
+ /**
93
+ * The default creation type to use.
94
+ *
95
+ * Defaults to StorageFileCreationType.DIRECTLY_CREATED.
96
+ */
97
+ readonly defaultCreationType?: Maybe<StorageFileCreationType>;
98
+ /**
99
+ * The default value for shouldBeProcessed.
100
+ *
101
+ * Defaults to false.
102
+ */
103
+ readonly defaultShouldBeProcessed?: Maybe<boolean>;
104
+ }
105
+ /**
106
+ * Factory function for creating StorageFileDocument pairs.
107
+ */
108
+ export type CreateStorageFileDocumentPairFactory = <M extends StorageFileMetadata = StorageFileMetadata>(input: CreateStorageFileDocumentPairInput<M>) => Promise<CreateStorageFileDocumentPairResult<M>>;
109
+ /**
110
+ * Creates a CreateStorageFileDocumentPairFactory.
111
+ *
112
+ * @param config
113
+ * @returns
114
+ */
115
+ export declare function createStorageFileDocumentPairFactory(config?: CreateStorageFileDocumentPairFactoryConfig): CreateStorageFileDocumentPairFactory;
116
+ /**
117
+ * Convenience function for creating a StorageFileDocumentPair.
118
+ *
119
+ * Calls createStorageFileDocumentPairFactory() with no arguments, then passes the input to the factory and returns the result.
120
+ */
121
+ export declare function createStorageFileDocumentPair<M extends StorageFileMetadata = StorageFileMetadata>(input: CreateStorageFileDocumentPairInput<M>): Promise<CreateStorageFileDocumentPairResult<M>>;
@@ -0,0 +1,164 @@
1
+ import { type Maybe } from '@dereekb/util';
2
+ import { type GrantedReadRole, type GrantedUpdateRole } from '@dereekb/model';
3
+ import { AbstractFirestoreDocument, type CollectionReference, type FirestoreCollection, type FirestoreContext, FirebaseAuthUserId, FirebaseAuthOwnershipKey, StoragePath } from '../../common';
4
+ import { StorageFileMetadata, StorageFilePurpose } from './storagefile.id';
5
+ import { NotificationKey } from '../notification';
6
+ export declare abstract class StorageFileFirestoreCollections {
7
+ abstract readonly storageFileCollection: StorageFileFirestoreCollection;
8
+ }
9
+ export type StorageFileTypes = typeof storageFileIdentity;
10
+ export declare const storageFileIdentity: import("../../common").RootFirestoreModelIdentity<"storageFile", "sf">;
11
+ /**
12
+ * The current file state.
13
+ */
14
+ export declare enum StorageFileCreationType {
15
+ /**
16
+ * No info about how this file was created.
17
+ */
18
+ NONE = 0,
19
+ /**
20
+ * The StorageFile was directly created.
21
+ */
22
+ DIRECTLY_CREATED = 1,
23
+ /**
24
+ * The StorageFile was initialized from an uploaded file.
25
+ */
26
+ INIT_FROM_UPLOAD = 2
27
+ }
28
+ /**
29
+ * The current file state.
30
+ */
31
+ export declare enum StorageFileState {
32
+ /**
33
+ * The StorageFile has no state, or is just being initialized.
34
+ */
35
+ INIT = 0,
36
+ /**
37
+ * The StorageFile failed to initialize properly and is considered invalid.
38
+ *
39
+ * StorageFiles that are marked invalid are deleted after a period of time.
40
+ *
41
+ * Files that are invalid cannot be processed.
42
+ */
43
+ INVALID = 1,
44
+ /**
45
+ * The StorageFile has been initialized and is ok.
46
+ */
47
+ OK = 2,
48
+ /**
49
+ * A previously OK file that is now queued for deletion.
50
+ */
51
+ QUEUED_FOR_DELETE = 3
52
+ }
53
+ /**
54
+ * The current processing state of the file.
55
+ */
56
+ export declare enum StorageFileProcessingState {
57
+ /**
58
+ * The StorageFile has no processing state or is just being initialized.
59
+ */
60
+ INIT_OR_NONE = 0,
61
+ /**
62
+ * The StorageFile is flagged for processing, which will create a NotificationTask for it.
63
+ */
64
+ QUEUED_FOR_PROCESSING = 1,
65
+ /**
66
+ * The StorageFile has an associated NotificationTask for it.
67
+ */
68
+ PROCESSING = 2,
69
+ /**
70
+ * The StorageFile has encountered an error during processing.
71
+ */
72
+ FAILED = 3,
73
+ /**
74
+ * The StorageFile has been processed or required no processing and is done.
75
+ */
76
+ SUCCESS = 4,
77
+ /**
78
+ * The StorageFile has been archived. It should not be processed.
79
+ */
80
+ ARCHIVED = 5,
81
+ /**
82
+ * The StorageFile shouldn't be processed.
83
+ */
84
+ DO_NOT_PROCESS = 6
85
+ }
86
+ /**
87
+ * After 3 hours of being in the PROCESSING state, we can check for retring processing.
88
+ */
89
+ export declare const STORAGE_FILE_PROCESSING_STUCK_THROTTLE_CHECK_MS: number;
90
+ /**
91
+ * A global storage file in the system.
92
+ *
93
+ * Contains file metadata and ownership information, along with other arbitrary metadata.
94
+ */
95
+ export interface StorageFile<M extends StorageFileMetadata = StorageFileMetadata> extends StoragePath {
96
+ /**
97
+ * Created at date
98
+ */
99
+ cat: Date;
100
+ /**
101
+ * Type of creation.
102
+ */
103
+ ct?: Maybe<StorageFileCreationType>;
104
+ /**
105
+ * State of the storage file.
106
+ */
107
+ fs: StorageFileState;
108
+ /**
109
+ * Processing state of the storage file.
110
+ */
111
+ ps: StorageFileProcessingState;
112
+ /**
113
+ * The NotificationTask key for this storage file.
114
+ *
115
+ * Set only if the StorageFile has an associated NotificationTask.
116
+ *
117
+ * Cleared once the processing stage is no longer PROCESSING.
118
+ */
119
+ pn?: Maybe<NotificationKey>;
120
+ /**
121
+ * The date that state was last updated to PROCESSING.
122
+ *
123
+ * Is used as a way to track if processing should be checked on.
124
+ */
125
+ pat?: Maybe<Date>;
126
+ /**
127
+ * The date that the cleanup step of the processing task was run, and the notification ended.
128
+ */
129
+ pcat?: Maybe<Date>;
130
+ /**
131
+ * User this file is associated with, if applicable.
132
+ */
133
+ u?: Maybe<FirebaseAuthUserId>;
134
+ /**
135
+ * User who uploaded this file, if applicable.
136
+ */
137
+ uby?: Maybe<FirebaseAuthUserId>;
138
+ /**
139
+ * Ownership key, if applicable.
140
+ */
141
+ o?: Maybe<FirebaseAuthOwnershipKey>;
142
+ /**
143
+ * Purpose of the file, if applicable.
144
+ */
145
+ p?: Maybe<StorageFilePurpose>;
146
+ /**
147
+ * Arbitrary metadata attached to the StorageFile.
148
+ */
149
+ d?: Maybe<M>;
150
+ /**
151
+ * Scheduled delete at date. The StorageFile cannot be deleted before this set time.
152
+ *
153
+ * Is the main trigger for determining a StorageFile should be deleted.
154
+ */
155
+ sdat?: Maybe<Date>;
156
+ }
157
+ export type StorageFileRoles = 'process' | GrantedUpdateRole | GrantedReadRole;
158
+ export declare class StorageFileDocument extends AbstractFirestoreDocument<StorageFile, StorageFileDocument, typeof storageFileIdentity> {
159
+ get modelIdentity(): import("../../common").RootFirestoreModelIdentity<"storageFile", "sf">;
160
+ }
161
+ export declare const storageFileConverter: import("../../common").SnapshotConverterFunctions<StorageFile<Readonly<Record<string, any>>>, Partial<import("@dereekb/util").ReplaceType<StorageFile<Readonly<Record<string, any>>>, import("@dereekb/util").MaybeMap<object>, any>>>;
162
+ export declare function storageFileCollectionReference(context: FirestoreContext): CollectionReference<StorageFile>;
163
+ export type StorageFileFirestoreCollection = FirestoreCollection<StorageFile, StorageFileDocument>;
164
+ export declare function storageFileFirestoreCollection(firestoreContext: FirestoreContext): StorageFileFirestoreCollection;
@@ -0,0 +1,55 @@
1
+ import { Factory, FactoryWithRequiredInput, Maybe, SlashPathDetails } from '@dereekb/util';
2
+ import { StoragePath } from '../../common/storage/storage';
3
+ import { StorageCustomMetadata } from '../../common/storage/types';
4
+ import { FirebaseStorageAccessorFile } from '../../common/storage/driver/accessor';
5
+ /**
6
+ * Details from the input.
7
+ */
8
+ export type StoredFileReaderInput = StoragePath;
9
+ /**
10
+ * Factory function that creates a StoredFileReader from the input details.
11
+ */
12
+ export type StoredFileReaderFactory = FactoryWithRequiredInput<StoredFileReader, FirebaseStorageAccessorFile>;
13
+ /**
14
+ * A read-only accessor for file in FirebaseStorage.
15
+ *
16
+ * It exposes only read-only methods for accessing details about the file.
17
+ *
18
+ * This accessor is generally a server-side only interface.
19
+ */
20
+ export interface StoredFileReader {
21
+ /**
22
+ * The details that this accessor is for.
23
+ */
24
+ readonly input: StoredFileReaderInput;
25
+ /**
26
+ * Returns details about the path.
27
+ */
28
+ readonly getPathDetails: Factory<SlashPathDetails>;
29
+ /**
30
+ * Loads the file bytes.
31
+ */
32
+ readonly loadFileBytes: FirebaseStorageAccessorFile['getBytes'];
33
+ /**
34
+ * Loads the file stream.
35
+ */
36
+ readonly loadFileStream: FirebaseStorageAccessorFile['getStream'];
37
+ /**
38
+ * Loads the StorageMetadata for this file.
39
+ */
40
+ readonly loadFileMetadata: FirebaseStorageAccessorFile['getMetadata'];
41
+ /**
42
+ * Loads the custom metadata for this file.
43
+ */
44
+ readonly loadCustomMetadata: () => Promise<Maybe<StorageCustomMetadata>>;
45
+ /**
46
+ * Copies this file to the specified destination.
47
+ */
48
+ readonly copy: Required<FirebaseStorageAccessorFile>['copy'];
49
+ }
50
+ /**
51
+ * Creates a StoredFileReaderFactory.
52
+ *
53
+ * Should generally only be used on the server-side, as copy may not be available on the client-side.
54
+ */
55
+ export declare function storedFileReaderFactory(): StoredFileReaderFactory;
@@ -0,0 +1,20 @@
1
+ import { FirestoreModelId, FirestoreModelKey } from '../../common';
2
+ export type StorageFileId = FirestoreModelId;
3
+ export type StorageFileKey = FirestoreModelKey;
4
+ /**
5
+ * Arbitrary string that can be used to describe the file's purpose.
6
+ *
7
+ * It should be unique between different file types.
8
+ *
9
+ * The purpose is generally used while querying for StorageFiles that require processing, but can also be
10
+ * set on files that do not get processed.
11
+ *
12
+ * Can be used for querying.
13
+ */
14
+ export type StorageFilePurpose = string;
15
+ /**
16
+ * Arbitrary metadata to attach to the storage file.
17
+ *
18
+ * Is serialized directly to/from Firestore, so be mindful of what is stored.
19
+ */
20
+ export type StorageFileMetadata = Readonly<Record<string, any>>;