-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.d.ts
142 lines (119 loc) · 3.62 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Type definitions for @kesha-antonov/react-native-background-downloader 2.6
// Project: https://github.com/kesha-antonov/react-native-background-downloader
// Definitions by: Philip Su <https://github.com/fivecar>,
// Adam Hunter <https://github.com/adamrhunter>,
// Junseong Park <https://github.com/Kweiza>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface DownloadHeaders {
[key: string]: string | null;
}
export interface Config {
headers: DownloadHeaders,
progressInterval: number,
isLogsEnabled: boolean
}
type SetConfig = (config: Partial<Config>) => void;
export interface BeginHandlerObject {
expectedBytes: number;
headers: { [key: string]: string };
}
export type BeginHandler = ({
expectedBytes,
headers,
}: BeginHandlerObject) => void;
export interface ProgressHandlerObject {
bytesDownloaded: number
bytesTotal: number
}
export type ProgressHandler = ({
bytesDownloaded,
bytesTotal,
}: ProgressHandlerObject) => void;
export interface DoneHandlerObject {
bytesDownloaded: number
bytesTotal: number
}
export type DoneHandler = ({
bytesDownloaded,
bytesTotal,
}: DoneHandlerObject) => void;
export interface ErrorHandlerObject {
error: string
errorCode: number
}
export type ErrorHandler = ({
error,
errorCode,
}: ErrorHandlerObject) => void;
export interface TaskInfoObject {
id: string;
metadata: object | string;
bytesDownloaded?: number;
bytesTotal?: number;
beginHandler?: BeginHandler;
progressHandler?: ProgressHandler;
doneHandler?: DoneHandler;
errorHandler?: ErrorHandler;
}
export type TaskInfo = TaskInfoObject;
export type DownloadTaskState =
| 'PENDING'
| 'DOWNLOADING'
| 'PAUSED'
| 'DONE'
| 'FAILED'
| 'STOPPED';
export interface DownloadTask {
constructor: (taskInfo: TaskInfo) => DownloadTask;
id: string;
state: DownloadTaskState;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metadata: Record<string, any>;
bytesDownloaded: number;
bytesTotal: number;
begin: (handler: BeginHandler) => DownloadTask;
progress: (handler: ProgressHandler) => DownloadTask;
done: (handler: DoneHandler) => DownloadTask;
error: (handler: ErrorHandler) => DownloadTask;
_beginHandler: BeginHandler;
_progressHandler: ProgressHandler;
_doneHandler: DoneHandler;
_errorHandler: ErrorHandler;
pause: () => void;
resume: () => void;
stop: () => void;
}
export type CheckForExistingDownloads = () => Promise<DownloadTask[]>;
export type EnsureDownloadsAreRunning = () => Promise<void>;
export interface DownloadOption {
id: string;
url: string;
destination: string;
headers?: DownloadHeaders | undefined;
metadata?: object;
isAllowedOverRoaming?: boolean;
isAllowedOverMetered?: boolean;
isNotificationVisible?: boolean;
notificationTitle?: string;
}
export type Download = (options: DownloadOption) => DownloadTask;
export type CompleteHandler = (id: string) => void;
export interface Directories {
documents: string;
}
export const setConfig: SetConfig
export const checkForExistingDownloads: CheckForExistingDownloads
export const ensureDownloadsAreRunning: EnsureDownloadsAreRunning
export const download: Download
export const completeHandler: CompleteHandler
export const directories: Directories
export interface RNBackgroundDownloader {
setConfig: SetConfig;
checkForExistingDownloads: CheckForExistingDownloads;
ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
download: Download;
completeHandler: CompleteHandler;
directories: Directories;
}
declare const RNBackgroundDownloader: RNBackgroundDownloader
export default RNBackgroundDownloader