UNPKG

4.37 kBTypeScriptView Raw
1import { StorageCopySource, StorageCopyDestination, StorageGetConfig, StorageProvider, StoragePutConfig, StorageRemoveConfig, StorageListConfig, StorageCopyConfig, StorageGetOutput, StoragePutOutput, StorageRemoveOutput, StorageListOutput, StorageCopyOutput, UploadTask } from './types';
2/**
3 * Provide storage methods to use AWS S3
4 */
5export declare class Storage {
6 /**
7 * @private
8 */
9 private _config;
10 private _pluggables;
11 /**
12 * Similar to the API module. This weak map allows users to cancel their in-flight request made using the Storage
13 * module. For every get or put request, a unique cancel token will be generated and injected to it's underlying
14 * AxiosHttpHandler. This map maintains a mapping of Request to CancelTokenSource. When .cancel is invoked, it will
15 * attempt to retrieve it's corresponding cancelTokenSource and cancel the in-flight request.
16 */
17 private _cancelTokenSourceMap;
18 /**
19 * @public
20 */
21 vault: Storage;
22 /**
23 * Initialize Storage
24 * @param {Object} config - Configuration object for storage
25 */
26 constructor();
27 getModuleName(): string;
28 /**
29 * add plugin into Storage category
30 * @param {Object} pluggable - an instance of the plugin
31 */
32 addPluggable(pluggable: StorageProvider): {};
33 /**
34 * Get the plugin object
35 * @param providerName - the name of the plugin
36 */
37 getPluggable(providerName: string): StorageProvider;
38 /**
39 * Remove the plugin object
40 * @param providerName - the name of the plugin
41 */
42 removePluggable(providerName: string): void;
43 /**
44 * Configure Storage
45 * @param {Object} config - Configuration object for storage
46 * @return {Object} - Current configuration
47 */
48 configure(config?: any): any;
49 private getCancellableTokenSource;
50 private updateRequestToBeCancellable;
51 private isUploadTask;
52 /**
53 * Cancels an inflight request
54 *
55 * @param request - The request to cancel
56 * @param [message] - A message to include in the cancelation exception
57 */
58 cancel(request: UploadTask, message?: string): Promise<boolean>;
59 cancel(request: Promise<any>, message?: string): void;
60 /**
61 * Copies a file from src to dest.
62 *
63 * @param src - The source object.
64 * @param dest - The destination object.
65 * @param [config] - config for the Storage operation.
66 * @return A promise resolves to the copied object's key.
67 */
68 copy<T extends Record<string, any>>(src: StorageCopySource, dest: StorageCopyDestination, config?: StorageCopyConfig<T>): StorageCopyOutput<T>;
69 /**
70 * Get a presigned URL of the file or the object data when download:true
71 *
72 * @param key - key of the object
73 * @param [config] - config for the Storage operation.
74 * @return - A promise resolves to either a presigned url or the object
75 */
76 get<T extends Record<string, any> & {
77 download?: boolean;
78 }>(key: string, config?: StorageGetConfig<T>): StorageGetOutput<T>;
79 isCancelError(error: any): boolean;
80 /**
81 * Put a file in storage bucket specified to configure method
82 * @param key - key of the object
83 * @param object - File to be put in bucket
84 * @param [config] - { level : private|protected|public, contentType: MIME Types,
85 * progressCallback: function }
86 * @return - promise resolves to object on success
87 */
88 put<T extends Record<string, any>>(key: string, object: any, config?: StoragePutConfig<T>): StoragePutOutput<T>;
89 /**
90 * Remove the object for specified key
91 * @param key - key of the object
92 * @param [config] - { level : private|protected|public }
93 * @return - Promise resolves upon successful removal of the object
94 */
95 remove<T extends Record<string, any>>(key: string, config?: StorageRemoveConfig<T>): StorageRemoveOutput<T>;
96 /**
97 * List bucket objects relative to the level and prefix specified
98 * @param path - the path that contains objects
99 * @param [config] - { level : private|protected|public, maxKeys: NUMBER }
100 * @return - Promise resolves to list of keys for all objects in path
101 */
102 list<T extends Record<string, any>>(key: string, config?: StorageListConfig<T>): StorageListOutput<T>;
103}
104/**
105 * @deprecated use named import
106 */
107export default Storage;