forked from mybigday/react-native-s3
-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.d.ts
72 lines (58 loc) · 2.48 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
declare module "react-native-s3" {
interface BasicOptions {
region: string; // a S3 Region (default: eu-west-1)
access_key: string; // the AWS access key ID
secret_key: string; // the AWS secret access key
session_token: string; // (optional)
remember_last_instance: boolean; // keep the last transferUtility instance when JS reload (default: true) __(iOS)__
}
interface CognitoOptions {
region: string; // a S3 Region (default: eu-west-1)
identity_pool_id: string; // the Amazon Cogntio identity pool
cognito_region: string; // a Cognito Region (default: eu-west-1)
caching: boolean; // use `CognitoCachingCredentialsProvider` instead of `CognitoCredentialsProvider` __(Android)__
remember_last_instance: boolean; // keep the last transferUtility instance when JS reload (default: true) __(iOS)__
}
interface UploadOptions {
bucket: string; // a S3 bucket name
key: string; // the object key/destination in the bucket
file: string; // the file path to upload
meta: {
"Content-Type": string; // the file content-type
};
}
interface DownloadOptions {
bucket: String; // a S3 bucket name
key: String; // the object key/destination in the bucket
file: String; // donwload save file path
}
interface Task {
id: number;
state: "waiting" | "in_progress" | "paused" | "canceled" | "completed" | "failed";
bytes: number;
totalBytes: number;
bucket: string;
key: string;
}
type TaskMap = { [id: string]: Task; };
interface TransferUtility {
setupWithNative(): Promise<boolean>;
setupWithBasic(options: BasicOptions): Promise<boolean>;
setupWithCognito(options: CognitoOptions): Promise<boolean>;
enableProgressSent(enabled: boolean): Promise<void>;
upload(options: UploadOptions): Promise<Task>;
download(options: DownloadOptions): Promise<Task>;
pause(taskID: number);
resume(taskID: number);
cancel(taskID: number);
deleteRecord(taskID: number): Promise<boolean>; // __(Android)__
getTask(taskID: number): Promise<Task>;
getTasks(type: "upload" | "download", idAsKey: boolean): Task[] | TaskMap;
// Subscribe to task changes with the given id.
subscribe(taskID: number, eventHandler: (err: object, task: Task) => void): void;
// Unsubscribe task change listener `eventHandler` with the given id.
// If `eventHandler` is not exists, it will unsubscribe all task change listeners with the given id.
unsubscribe(taskID: number, eventHandler?: (err: object, task: Task) => void): void;
}
export const transferUtility: TransferUtility;
}