@memberjunction/storage 2.38.0 → 2.40.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 (38) hide show
  1. package/dist/drivers/AWSFileStorage.d.ts +360 -4
  2. package/dist/drivers/AWSFileStorage.d.ts.map +1 -1
  3. package/dist/drivers/AWSFileStorage.js +357 -4
  4. package/dist/drivers/AWSFileStorage.js.map +1 -1
  5. package/dist/drivers/AzureFileStorage.d.ts +362 -2
  6. package/dist/drivers/AzureFileStorage.d.ts.map +1 -1
  7. package/dist/drivers/AzureFileStorage.js +357 -2
  8. package/dist/drivers/AzureFileStorage.js.map +1 -1
  9. package/dist/drivers/BoxFileStorage.d.ts +539 -20
  10. package/dist/drivers/BoxFileStorage.d.ts.map +1 -1
  11. package/dist/drivers/BoxFileStorage.js +521 -20
  12. package/dist/drivers/BoxFileStorage.js.map +1 -1
  13. package/dist/drivers/DropboxFileStorage.d.ts +437 -15
  14. package/dist/drivers/DropboxFileStorage.d.ts.map +1 -1
  15. package/dist/drivers/DropboxFileStorage.js +431 -15
  16. package/dist/drivers/DropboxFileStorage.js.map +1 -1
  17. package/dist/drivers/GoogleDriveFileStorage.d.ts +342 -16
  18. package/dist/drivers/GoogleDriveFileStorage.d.ts.map +1 -1
  19. package/dist/drivers/GoogleDriveFileStorage.js +340 -16
  20. package/dist/drivers/GoogleDriveFileStorage.js.map +1 -1
  21. package/dist/drivers/GoogleFileStorage.d.ts +358 -2
  22. package/dist/drivers/GoogleFileStorage.d.ts.map +1 -1
  23. package/dist/drivers/GoogleFileStorage.js +356 -2
  24. package/dist/drivers/GoogleFileStorage.js.map +1 -1
  25. package/dist/drivers/SharePointFileStorage.d.ts +434 -20
  26. package/dist/drivers/SharePointFileStorage.d.ts.map +1 -1
  27. package/dist/drivers/SharePointFileStorage.js +453 -22
  28. package/dist/drivers/SharePointFileStorage.js.map +1 -1
  29. package/dist/generic/FileStorageBase.d.ts +326 -108
  30. package/dist/generic/FileStorageBase.d.ts.map +1 -1
  31. package/dist/generic/FileStorageBase.js +54 -6
  32. package/dist/generic/FileStorageBase.js.map +1 -1
  33. package/dist/util.d.ts +125 -18
  34. package/dist/util.d.ts.map +1 -1
  35. package/dist/util.js +125 -18
  36. package/dist/util.js.map +1 -1
  37. package/package.json +4 -4
  38. package/readme.md +211 -1
@@ -1,8 +1,31 @@
1
1
  /// <reference types="node" />
2
+ /**
3
+ * Represents the payload returned by the CreatePreAuthUploadUrl method.
4
+ * This type contains the necessary information for uploading a file to a storage provider.
5
+ *
6
+ * @property UploadUrl - The pre-authenticated URL to which the file should be uploaded
7
+ * @property ProviderKey - Optional. Some storage providers assign their own unique key to the object
8
+ * that should be used for future operations instead of the original object name
9
+ */
2
10
  export type CreatePreAuthUploadUrlPayload = {
3
11
  UploadUrl: string;
4
12
  ProviderKey?: string | undefined;
5
13
  };
14
+ /**
15
+ * Represents metadata information about a stored object or file.
16
+ * This comprehensive type includes common file metadata properties available across different storage providers.
17
+ *
18
+ * @property name - The name of the object (typically the filename without path)
19
+ * @property path - The directory path where the object is stored, without the object name
20
+ * @property fullPath - The complete path to the object including both path and name
21
+ * @property size - The size of the object in bytes
22
+ * @property contentType - The MIME type of the object
23
+ * @property lastModified - The date when the object was last modified
24
+ * @property isDirectory - Boolean flag indicating whether the object is a directory/folder
25
+ * @property etag - Optional. Entity tag used for cache validation and conditional operations
26
+ * @property cacheControl - Optional. Cache control directives for the object
27
+ * @property customMetadata - Optional. Additional custom metadata as key-value pairs
28
+ */
6
29
  export type StorageObjectMetadata = {
7
30
  name: string;
8
31
  path: string;
@@ -15,48 +38,84 @@ export type StorageObjectMetadata = {
15
38
  cacheControl?: string;
16
39
  customMetadata?: Record<string, string>;
17
40
  };
41
+ /**
42
+ * Represents the result of a ListObjects operation.
43
+ * Contains both the objects (files) and prefixes (directories) found in the storage provider.
44
+ *
45
+ * @property objects - Array of StorageObjectMetadata for all objects/files found in the specified path
46
+ * @property prefixes - Array of directory path strings found in the specified path
47
+ */
18
48
  export type StorageListResult = {
19
49
  objects: StorageObjectMetadata[];
20
50
  prefixes: string[];
21
51
  };
22
52
  /**
23
- * Error thrown when a method is not supported by a storage provider
53
+ * Error thrown when a storage provider does not support a particular operation.
54
+ * This custom error provides clear information about which operation was attempted
55
+ * and which provider doesn't support it.
24
56
  */
25
57
  export declare class UnsupportedOperationError extends Error {
58
+ /**
59
+ * Creates a new UnsupportedOperationError instance.
60
+ *
61
+ * @param methodName - The name of the method that is not supported
62
+ * @param providerName - The name of the storage provider that doesn't support the method
63
+ */
26
64
  constructor(methodName: string, providerName: string);
27
65
  }
28
66
  /**
29
- * Represents an abstract base class for file storage. Provides methods for creating pre-authorized upload and download URLs, as well as deleting objects. This
30
- * interface is implemented in specific driver classes for each storage provider.
67
+ * Represents an abstract base class for file storage operations.
68
+ *
69
+ * This class defines a common interface for interacting with various cloud storage providers,
70
+ * allowing for consistent file operations regardless of the underlying storage system.
71
+ * Each storage provider implementation extends this base class and provides
72
+ * concrete implementations for all abstract methods.
73
+ *
74
+ * The class provides methods for:
75
+ * - Generating pre-authenticated upload and download URLs
76
+ * - Managing files (creating, copying, moving, deleting)
77
+ * - Managing directories (creating, deleting, listing contents)
78
+ * - Retrieving file metadata and content
79
+ * - Checking for file and directory existence
80
+ *
81
+ * Implementation notes:
82
+ * - All methods are designed to be provider-agnostic
83
+ * - Error handling should be implemented in derived classes to provide consistent behavior
84
+ * - Methods return Promises to support asynchronous operations across various providers
85
+ * - When a storage provider doesn't support a particular operation, implementations should throw UnsupportedOperationError
31
86
  */
32
87
  export declare abstract class FileStorageBase {
33
88
  /**
34
- * The name of this storage provider, used in error messages
89
+ * The name of this storage provider, used in error messages and logging.
90
+ * Each implementation must define this property with a descriptive name.
35
91
  */
36
92
  protected abstract readonly providerName: string;
37
93
  /**
38
- * Helper method to throw an UnsupportedOperationError
39
- * @param methodName The name of the method that is not supported
94
+ * Helper method to throw an UnsupportedOperationError with appropriate context.
95
+ * This method simplifies implementation of methods not supported by specific providers.
96
+ *
97
+ * @param methodName - The name of the method that is not supported
98
+ * @throws UnsupportedOperationError with information about the unsupported method and provider
40
99
  */
41
100
  protected throwUnsupportedOperationError(methodName: string): never;
42
101
  /**
43
- * This method is designed to generate a pre-authenticated URL for uploading files to a storage provider. It abstracts over different storage providers,
44
- * allowing for a unified interface to obtain upload URLs, regardless of the underlying provider's specifics. The method takes the name of the file (or
45
- * object) you wish to upload as input and returns a Promise. This Promise, when resolved, provides a payload containing two key pieces of information:
102
+ * Generates a pre-authenticated URL for uploading files to a storage provider.
46
103
  *
47
- * 1. `UploadUrl`: The URL to which the file should be uploaded. This URL is pre-authenticated, meaning it includes any necessary authentication tokens or
48
- * signatures. The URL's format and the authentication method depend on the storage provider being used.
104
+ * This method abstracts over different storage providers, allowing for a unified interface
105
+ * to obtain upload URLs, regardless of the underlying provider's specifics. The method
106
+ * takes the name of the file (or object) you wish to upload as input and returns a Promise.
107
+ * This Promise, when resolved, provides a payload containing two key pieces of information:
49
108
  *
50
- * 2. `ProviderKey` (optional): Some storage providers assign their own unique key or name to the uploaded object instead of using the name provided by the
51
- * user. If the provider you are using does this, the `ProviderKey` will be included in the payload. This key can be useful for future reference to the
52
- * object within the storage provider's system.
109
+ * 1. `UploadUrl`: The URL to which the file should be uploaded. This URL is pre-authenticated,
110
+ * meaning it includes any necessary authentication tokens or signatures. The URL's format
111
+ * and the authentication method depend on the storage provider being used.
53
112
  *
54
- * @usage
55
- *
56
- * Suppose you have a file named "photo.jpg" that you want to upload to your storage provider. You would call this method with the object name "photo.jpg".
57
- * After the Promise resolves, you will receive the upload URL and, if applicable, the provider's object key. You can then use this URL to upload your file
58
- * directly to the storage provider.
113
+ * 2. `ProviderKey` (optional): Some storage providers assign their own unique key or name to
114
+ * the uploaded object instead of using the name provided by the user. If the provider you
115
+ * are using does this, the `ProviderKey` will be included in the payload. This key can be
116
+ * useful for future reference to the object within the storage provider's system.
59
117
  *
118
+ * @example
60
119
  * ```typescript
61
120
  * const uploadPayload = await CreatePreAuthUploadUrl("photo.jpg");
62
121
  * console.log(uploadPayload.UploadUrl); // Use this URL to upload your file
@@ -66,149 +125,208 @@ export declare abstract class FileStorageBase {
66
125
  * }
67
126
  * ```
68
127
  *
69
- * Note: This method is abstract and must be implemented by a subclass that specifies the logic for interacting with a specific storage provider.
128
+ * Note: This method is abstract and must be implemented by a subclass that specifies the logic
129
+ * for interacting with a specific storage provider.
70
130
  *
71
- * @param objectName - The name of the object or file to be uploaded. This name is used by the storage provider and may also be included in the
72
- * pre-authenticated URL.
73
- * @returns A Promise that resolves to a payload containing the upload URL and, optionally, the provider's object key. This payload allows you to proceed with
74
- * uploading your file to the storage provider.
131
+ * @param objectName - The name of the object or file to be uploaded. This name is used by the
132
+ * storage provider and may also be included in the pre-authenticated URL.
133
+ * @returns A Promise that resolves to a payload containing the upload URL and, optionally, the
134
+ * provider's object key. This payload allows you to proceed with uploading your file
135
+ * to the storage provider.
75
136
  */
76
137
  abstract CreatePreAuthUploadUrl(objectName: string): Promise<CreatePreAuthUploadUrlPayload>;
77
138
  /**
78
- * This abstract method is designed to generate a pre-authenticated URL that allows for the downloading of files or objects from a storage provider. Being
79
- * abstract, it requires implementation in a subclass tailored to the specifics of the storage provider you're using. This method abstracts the process of
80
- * generating download URLs across different storage providers, offering a unified interface for obtaining these URLs.
81
- *
82
- * When you call this method with the name of the file or object you wish to download, it initiates a process to create a URL. This URL is not just any link;
83
- * it is pre-authenticated. This means it includes any necessary authentication tokens or signatures directly in the URL, allowing for secure access without
84
- * requiring additional authentication steps at the time of download. The format of the URL and the authentication method depend on the storage provider.
85
- *
86
- * @usage
139
+ * Generates a pre-authenticated URL for downloading files from a storage provider.
87
140
  *
88
- * Suppose you have a file named "report.pdf" stored in your cloud storage, and you want to generate a URL to download this file. You would call this method
89
- * with the object name "report.pdf". After the Promise resolves, you will receive a URL that is ready to use for downloading the file.
141
+ * This method abstracts the process of generating download URLs across different storage providers,
142
+ * offering a unified interface for obtaining these URLs. When called with the name of the file
143
+ * or object to download, it creates a URL that includes necessary authentication tokens directly
144
+ * in the URL, allowing for secure access without requiring additional authentication at download time.
90
145
  *
146
+ * @example
91
147
  * ```typescript
92
148
  * const downloadUrl = await CreatePreAuthDownloadUrl("report.pdf");
93
149
  * console.log(downloadUrl); // Use this URL to download your file directly
94
150
  * ```
95
151
  *
96
- * If a `ProviderKey` was previously returned by `CreatePreAuthUploadUrl`, use that as the `objectName` instead of the object's natural name.
152
+ * If a `ProviderKey` was previously returned by `CreatePreAuthUploadUrl`, use that as the
153
+ * `objectName` instead of the object's natural name:
97
154
  *
98
155
  * ```typescript
99
156
  * const downloadUrl = await CreatePreAuthDownloadUrl(file.ProviderKey);
100
157
  * console.log(downloadUrl); // Use this URL to download your file directly
101
158
  * ```
102
159
  *
103
- * This method simplifies the process of securely sharing or accessing files stored in cloud storage by providing a direct, pre-authenticated link to the
104
- * file. It's particularly useful in applications where files need to be accessed or shared without navigating through the storage provider's standard
160
+ * This method simplifies the process of securely sharing or accessing files stored in cloud storage
161
+ * by providing a direct, pre-authenticated link to the file. It's particularly useful in applications
162
+ * where files need to be accessed or shared without navigating through the storage provider's standard
105
163
  * authentication flow each time.
106
164
  *
107
- * Note: Since this method is abstract, you must implement it in a subclass that defines the specific interactions with your chosen storage provider.
108
- *
109
- * @param objectName - The name of the object or file for which you want to generate a download URL. This is the name as it is known to the storage provider,
110
- * and it will be used to locate the file and generate the URL.
111
- * @returns A Promise that resolves to a string, which is the pre-authenticated download URL for the specified object or file. This URL can be used
112
- * immediately for downloading the file without further authentication.
165
+ * @param objectName - The name of the object or file for which you want to generate a download URL.
166
+ * This is the name as it is known to the storage provider, and it will be used
167
+ * to locate the file and generate the URL.
168
+ * @returns A Promise that resolves to a string, which is the pre-authenticated download URL for the
169
+ * specified object or file. This URL can be used immediately for downloading the file
170
+ * without further authentication.
113
171
  */
114
172
  abstract CreatePreAuthDownloadUrl(objectName: string): Promise<string>;
115
173
  /**
116
- * This abstract method is designed to move an object or file from one location to another within a storage provider's system. Being abstract, it requires concrete implementation in subclasses that are tailored to interact with specific storage providers. The method aims to provide a unified interface for moving objects across different storage providers, simplifying the process regardless of the underlying provider's specifics.
174
+ * Moves an object or file from one location to another within a storage provider's system.
117
175
  *
118
- * When invoking this method, you need to specify the name of the object you wish to move (`oldObjectName`) and the new name or location where you want to move the object (`newObjectName`). These names should match exactly as they are known to the storage provider, ensuring the correct object is targeted for the move operation.
176
+ * This method provides a unified interface for moving objects across different storage providers.
177
+ * It takes the original object name and the new desired name/location, and handles the
178
+ * appropriate operations to move the object while preserving its content.
119
179
  *
120
- * The method returns a Promise that, when resolved, indicates the success or failure of the move operation. A resolved value of `true` means the object was successfully moved, while `false` indicates a failure to move the object. It's important to handle both outcomes to ensure your application can respond appropriately to the move operation's result.
180
+ * Some implementations may perform this as a copy followed by a delete operation,
181
+ * while others might use native move capabilities of the underlying storage system.
121
182
  *
122
- * @param oldObjectName - The name of the object or file to be moved. This is the identifier used by the storage provider to locate the object for moving.
123
- * @param newObjectName - The new name or location where you want to move the object. This name should match exactly as it is known to the storage provider.
124
- * @returns A Promise that resolves to a boolean value. `true` indicates that the object was successfully moved, while `false` indicates a failure in the move process.
183
+ * @example
184
+ * ```typescript
185
+ * const moved = await storage.MoveObject('documents/draft.docx', 'documents/final/report.docx');
186
+ * if (moved) {
187
+ * console.log('File successfully moved');
188
+ * } else {
189
+ * console.log('Failed to move file');
190
+ * }
191
+ * ```
192
+ *
193
+ * @param oldObjectName - The current name/path of the object to be moved. This is the identifier
194
+ * used by the storage provider to locate the object for moving.
195
+ * @param newObjectName - The new name/path where you want to move the object. This should match
196
+ * exactly as it is expected to be known to the storage provider after moving.
197
+ * @returns A Promise that resolves to a boolean value. `true` indicates that the object was
198
+ * successfully moved, while `false` indicates a failure in the move process.
125
199
  */
126
200
  abstract MoveObject(oldObjectName: string, newObjectName: string): Promise<boolean>;
127
201
  /**
128
- * This abstract method is designed for deleting an object or file from a storage provider's system. Being abstract, it requires concrete implementation in
129
- * subclasses that are tailored to interact with specific storage providers. The method aims to provide a unified interface for object deletion across
130
- * different storage providers, simplifying the deletion process regardless of the underlying provider's specifics.
131
- *
132
- * When invoking this method, you need to specify the name of the object you wish to delete. This name should match exactly as it is known to the storage
133
- * provider, ensuring the correct object is targeted for deletion.
202
+ * Deletes an object or file from a storage provider's system.
134
203
  *
135
- * The method returns a Promise that, when resolved, indicates the success or failure of the deletion operation. A resolved value of `true` means the object
136
- * was successfully deleted, while `false` indicates a failure to delete the object. It's important to handle both outcomes to ensure your application can
137
- * respond appropriately to the deletion operation's result.
138
- *
139
- * @usage
140
- *
141
- * Suppose you have a file named "old_report.pdf" that is no longer needed and you want to delete it from your cloud storage. You would call this method with
142
- * the object name "old_report.pdf". After the Promise resolves, you can check the result to confirm the deletion.
204
+ * This method provides a unified interface for object deletion across different storage providers.
205
+ * It takes the name of the object to delete and handles the provider-specific operations to
206
+ * remove it from storage.
143
207
  *
208
+ * @example
144
209
  * ```typescript
145
- * DeleteObject("old_report.pdf").then((isDeleted) => {
146
- * if (isDeleted) {
147
- * console.log("The file was successfully deleted.");
148
- * } else {
149
- * console.log("Failed to delete the file. It may not exist or there was an error in the deletion process.");
150
- * }
151
- * });
210
+ * const deleted = await storage.DeleteObject('documents/old_report.pdf');
211
+ * if (deleted) {
212
+ * console.log('File successfully deleted');
213
+ * } else {
214
+ * console.log('Failed to delete file - it may not exist or there was an error');
215
+ * }
152
216
  * ```
153
217
  *
154
- * If a `ProviderKey` was previously returned by `CreatePreAuthUploadUrl`, use that as the `objectName` instead of the object's natural name.
218
+ * If a `ProviderKey` was previously returned by `CreatePreAuthUploadUrl`, use that as the
219
+ * `objectName` instead of the object's natural name:
155
220
  *
156
221
  * ```typescript
157
- * DeleteObject(file.ProviderKey).then((isDeleted) => {
158
- * if (isDeleted) {
159
- * console.log("The file was successfully deleted.");
160
- * } else {
161
- * console.log("Failed to delete the file. It may not exist or there was an error in the deletion process.");
162
- * }
163
- * });
222
+ * const deleted = await storage.DeleteObject(file.ProviderKey);
223
+ * if (deleted) {
224
+ * console.log('File successfully deleted');
225
+ * } else {
226
+ * console.log('Failed to delete file');
227
+ * }
164
228
  * ```
165
229
  *
166
- * Note: Since this method is abstract, it must be implemented in a subclass that defines the specific logic for interacting with your chosen storage
167
- * provider. This implementation should handle the intricacies of the deletion process, including any authentication and authorization required by the storage
168
- * provider.
169
- *
170
- * @param objectName - The name of the object or file to be deleted. This is the identifier used by the storage provider to locate the object for deletion.
171
- * @returns A Promise that resolves to a boolean value. `true` indicates that the object was successfully deleted, while `false` indicates a failure in the
172
- * deletion process.
230
+ * @param objectName - The name of the object or file to be deleted. This is the identifier
231
+ * used by the storage provider to locate the object for deletion.
232
+ * @returns A Promise that resolves to a boolean value. `true` indicates that the object was
233
+ * successfully deleted, while `false` indicates a failure in the deletion process.
173
234
  */
174
235
  abstract DeleteObject(objectName: string): Promise<boolean>;
175
236
  /**
176
237
  * Lists objects in a storage provider's system with the given prefix path.
177
238
  *
178
- * This method returns a list of objects and prefixes (directories) under the specified path.
179
- * The method supports a hierarchical directory-like structure through the use of prefixes
180
- * that can represent "folders" within the storage.
239
+ * This method returns a list of objects (files) and prefixes (directories) under the specified path.
240
+ * It supports a hierarchical directory-like structure through the use of prefixes that can represent
241
+ * "folders" within the storage, even for providers that don't natively support directories.
181
242
  *
182
- * @param prefix - The path prefix to list objects from. Use "/" for the root, or paths like "documents/"
183
- * for specific directories.
184
- * @param delimiter - The character used to group keys. Typically "/" is used to simulate directory structure.
185
- * Defaults to "/".
186
- * @returns A Promise that resolves to a StorageListResult containing both objects and prefixes (directories).
243
+ * @example
244
+ * ```typescript
245
+ * // List all objects in the "documents" directory
246
+ * const result = await storage.ListObjects('documents/');
247
+ *
248
+ * // Access the files
249
+ * for (const file of result.objects) {
250
+ * console.log(`File: ${file.name}, Size: ${file.size}, Type: ${file.contentType}`);
251
+ * }
252
+ *
253
+ * // Access the subdirectories
254
+ * for (const dir of result.prefixes) {
255
+ * console.log(`Directory: ${dir}`);
256
+ * }
257
+ * ```
258
+ *
259
+ * @param prefix - The path prefix to list objects from. Use "/" for the root, or paths like
260
+ * "documents/" for specific directories.
261
+ * @param delimiter - The character used to group keys. Typically "/" is used to simulate
262
+ * directory structure. Defaults to "/".
263
+ * @returns A Promise that resolves to a StorageListResult containing both objects and
264
+ * prefixes (directories).
187
265
  */
188
266
  abstract ListObjects(prefix: string, delimiter?: string): Promise<StorageListResult>;
189
267
  /**
190
268
  * Creates a directory in the storage system.
191
269
  *
192
- * For storage systems that don't natively support directories, this may create a zero-byte object with
193
- * a trailing delimiter to simulate a directory. For systems with native directory support, this will
194
- * create an actual directory.
270
+ * For storage systems that don't natively support directories (like AWS S3 or Google Cloud Storage),
271
+ * this may create a zero-byte object with a trailing delimiter to simulate a directory. For systems
272
+ * with native directory support, this will create an actual directory.
195
273
  *
196
- * @param directoryPath - The path of the directory to create. Should end with a delimiter (typically "/").
197
- * @returns A Promise that resolves to a boolean indicating success.
274
+ * @example
275
+ * ```typescript
276
+ * // Create a "reports" directory inside "documents"
277
+ * const created = await storage.CreateDirectory('documents/reports/');
278
+ * if (created) {
279
+ * console.log('Directory created successfully');
280
+ * } else {
281
+ * console.log('Failed to create directory');
282
+ * }
283
+ * ```
284
+ *
285
+ * @param directoryPath - The path of the directory to create. Should typically end with a
286
+ * delimiter (typically "/").
287
+ * @returns A Promise that resolves to a boolean indicating success of the directory creation.
198
288
  */
199
289
  abstract CreateDirectory(directoryPath: string): Promise<boolean>;
200
290
  /**
201
291
  * Deletes a directory and optionally all of its contents recursively.
202
292
  *
293
+ * This method can be used to remove empty directories or, with the recursive flag set to true,
294
+ * to delete entire directory trees including all contained files and subdirectories.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * // Delete an empty directory
299
+ * const deleted = await storage.DeleteDirectory('documents/temp/');
300
+ *
301
+ * // Delete a directory and all its contents
302
+ * const deletedRecursively = await storage.DeleteDirectory('documents/old_project/', true);
303
+ * ```
304
+ *
203
305
  * @param directoryPath - The path of the directory to delete.
204
- * @param recursive - If true, deletes all contents recursively. If false and the directory is not empty,
205
- * the operation will fail. Defaults to false.
206
- * @returns A Promise that resolves to a boolean indicating success.
306
+ * @param recursive - If true, deletes all contents recursively. If false and the directory
307
+ * is not empty, the operation will fail. Defaults to false.
308
+ * @returns A Promise that resolves to a boolean indicating success of the deletion operation.
207
309
  */
208
310
  abstract DeleteDirectory(directoryPath: string, recursive?: boolean): Promise<boolean>;
209
311
  /**
210
312
  * Retrieves metadata for a specific object without downloading its contents.
211
313
  *
314
+ * This method allows for checking properties of an object such as its size, content type,
315
+ * and last modified date without transferring the actual data, which can be efficient
316
+ * for large files.
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * try {
321
+ * const metadata = await storage.GetObjectMetadata('documents/large_file.zip');
322
+ * console.log(`File size: ${metadata.size} bytes`);
323
+ * console.log(`Last modified: ${metadata.lastModified}`);
324
+ * console.log(`Content type: ${metadata.contentType}`);
325
+ * } catch (error) {
326
+ * console.error('File not found or error retrieving metadata', error);
327
+ * }
328
+ * ```
329
+ *
212
330
  * @param objectName - The name of the object to retrieve metadata for.
213
331
  * @returns A Promise that resolves to a StorageObjectMetadata object containing the metadata.
214
332
  * If the object does not exist, the promise will be rejected.
@@ -217,6 +335,21 @@ export declare abstract class FileStorageBase {
217
335
  /**
218
336
  * Downloads an object's content as a Buffer.
219
337
  *
338
+ * This method retrieves the full content of an object from the storage provider
339
+ * and returns it as a Buffer for processing in memory.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * try {
344
+ * const fileContent = await storage.GetObject('documents/config.json');
345
+ * // Parse the JSON content
346
+ * const config = JSON.parse(fileContent.toString('utf8'));
347
+ * console.log('Loaded configuration:', config);
348
+ * } catch (error) {
349
+ * console.error('Error downloading file', error);
350
+ * }
351
+ * ```
352
+ *
220
353
  * @param objectName - The name of the object to download.
221
354
  * @returns A Promise that resolves to a Buffer containing the object's data.
222
355
  * If the object does not exist, the promise will be rejected.
@@ -225,29 +358,80 @@ export declare abstract class FileStorageBase {
225
358
  /**
226
359
  * Uploads object data to the storage provider.
227
360
  *
228
- * This is a direct upload method that doesn't use a pre-authorized URL.
361
+ * This is a direct upload method that doesn't use a pre-authorized URL. Instead,
362
+ * it takes the data as a Buffer and handles the upload directly, making it suitable
363
+ * for server-side operations where you already have the data in memory.
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * // Upload a text file
368
+ * const content = Buffer.from('Hello, World!', 'utf8');
369
+ * const uploaded = await storage.PutObject(
370
+ * 'documents/hello.txt',
371
+ * content,
372
+ * 'text/plain',
373
+ * { author: 'John Doe', department: 'Engineering' }
374
+ * );
375
+ *
376
+ * if (uploaded) {
377
+ * console.log('File uploaded successfully');
378
+ * } else {
379
+ * console.log('Failed to upload file');
380
+ * }
381
+ * ```
229
382
  *
230
383
  * @param objectName - The name to assign to the uploaded object.
231
384
  * @param data - The Buffer containing the data to upload.
232
- * @param contentType - Optional MIME type of the content.
385
+ * @param contentType - Optional MIME type of the content. If not provided,
386
+ * it may be inferred from the object name or set to a default.
233
387
  * @param metadata - Optional custom metadata to associate with the object.
234
- * @returns A Promise that resolves to a boolean indicating success.
388
+ * @returns A Promise that resolves to a boolean indicating success of the upload.
235
389
  */
236
390
  abstract PutObject(objectName: string, data: Buffer, contentType?: string, metadata?: Record<string, string>): Promise<boolean>;
237
391
  /**
238
392
  * Copies an object within the storage system.
239
393
  *
240
394
  * Unlike MoveObject which removes the source object, this creates a copy while
241
- * leaving the original intact.
395
+ * leaving the original intact. This is useful for creating backups or versions
396
+ * of files.
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * // Create a backup copy of a file
401
+ * const copied = await storage.CopyObject(
402
+ * 'documents/important.docx',
403
+ * 'documents/backups/important_backup.docx'
404
+ * );
405
+ *
406
+ * if (copied) {
407
+ * console.log('File copied successfully');
408
+ * } else {
409
+ * console.log('Failed to copy file');
410
+ * }
411
+ * ```
242
412
  *
243
413
  * @param sourceObjectName - The name of the object to copy.
244
414
  * @param destinationObjectName - The name to assign to the copied object.
245
- * @returns A Promise that resolves to a boolean indicating success.
415
+ * @returns A Promise that resolves to a boolean indicating success of the copy operation.
246
416
  */
247
417
  abstract CopyObject(sourceObjectName: string, destinationObjectName: string): Promise<boolean>;
248
418
  /**
249
419
  * Checks if an object exists in the storage system.
250
420
  *
421
+ * This method provides a way to verify the existence of an object without
422
+ * transferring its data or metadata, which can be more efficient when you only
423
+ * need to know if something exists.
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const exists = await storage.ObjectExists('documents/may_not_exist.pdf');
428
+ * if (exists) {
429
+ * console.log('The file exists');
430
+ * } else {
431
+ * console.log('The file does not exist');
432
+ * }
433
+ * ```
434
+ *
251
435
  * @param objectName - The name of the object to check.
252
436
  * @returns A Promise that resolves to a boolean indicating if the object exists.
253
437
  */
@@ -255,14 +439,48 @@ export declare abstract class FileStorageBase {
255
439
  /**
256
440
  * Checks if a directory exists in the storage system.
257
441
  *
442
+ * For storage systems that don't natively support directories, this may check for
443
+ * the existence of a directory placeholder object or for any objects with the given
444
+ * prefix.
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * const exists = await storage.DirectoryExists('documents/reports/');
449
+ * if (exists) {
450
+ * console.log('The directory exists');
451
+ * } else {
452
+ * console.log('The directory does not exist');
453
+ * }
454
+ * ```
455
+ *
258
456
  * @param directoryPath - The path of the directory to check.
259
457
  * @returns A Promise that resolves to a boolean indicating if the directory exists.
260
458
  */
261
459
  abstract DirectoryExists(directoryPath: string): Promise<boolean>;
262
460
  /**
263
461
  * Optional initialization method for storage providers that require async setup.
462
+ *
264
463
  * This method can be overridden by subclasses that need to perform async initialization
265
- * after construction, such as setting up access tokens or establishing connections.
464
+ * after construction, such as setting up access tokens, establishing connections,
465
+ * or verifying permissions.
466
+ *
467
+ * The default implementation does nothing and resolves immediately. Storage provider
468
+ * implementations should override this method if they need to perform async setup.
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * // In a specific provider implementation:
473
+ * public async initialize(): Promise<void> {
474
+ * // Set up OAuth tokens or other async initialization
475
+ * await this.refreshAccessToken();
476
+ * await this.verifyBucketAccess();
477
+ * }
478
+ *
479
+ * // Usage:
480
+ * const storage = new MyStorageProvider();
481
+ * await storage.initialize();
482
+ * // Now the provider is ready to use
483
+ * ```
266
484
  *
267
485
  * @returns A Promise that resolves when initialization is complete.
268
486
  */
@@ -1 +1 @@
1
- {"version":3,"file":"FileStorageBase.d.ts","sourceRoot":"","sources":["../../src/generic/FileStorageBase.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,IAAI,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAIrD;AAED;;;GAGG;AACH,8BAAsB,eAAe;IACnC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAEjD;;;OAGG;IACH,SAAS,CAAC,8BAA8B,CAAC,UAAU,EAAE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