@hyper-fetch/core 3.2.0 → 3.2.1
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.
- package/.eslintrc.json +1 -2
- package/dist/index.d.ts +1273 -11
- package/package.json +2 -2
- package/tsconfig.json +1 -0
- package/dist/adapter/adapter.bindings.d.ts +0 -25
- package/dist/adapter/adapter.browser.d.ts +0 -2
- package/dist/adapter/adapter.constants.d.ts +0 -1
- package/dist/adapter/adapter.d.ts +0 -2
- package/dist/adapter/adapter.server.d.ts +0 -2
- package/dist/adapter/adapter.types.d.ts +0 -57
- package/dist/adapter/adapter.utils.d.ts +0 -8
- package/dist/adapter/index.d.ts +0 -7
- package/dist/cache/cache.d.ts +0 -76
- package/dist/cache/cache.events.d.ts +0 -28
- package/dist/cache/cache.types.d.ts +0 -50
- package/dist/cache/cache.utils.d.ts +0 -6
- package/dist/cache/index.d.ts +0 -4
- package/dist/client/client.constants.d.ts +0 -9
- package/dist/client/client.d.ts +0 -142
- package/dist/client/client.types.d.ts +0 -41
- package/dist/client/client.utils.d.ts +0 -10
- package/dist/client/index.d.ts +0 -4
- package/dist/constants/http.constants.d.ts +0 -7
- package/dist/constants/time.constants.d.ts +0 -11
- package/dist/dispatcher/dispatcher.constants.d.ts +0 -6
- package/dist/dispatcher/dispatcher.d.ts +0 -155
- package/dist/dispatcher/dispatcher.events.d.ts +0 -11
- package/dist/dispatcher/dispatcher.types.d.ts +0 -31
- package/dist/dispatcher/dispatcher.utils.d.ts +0 -10
- package/dist/dispatcher/index.d.ts +0 -5
- package/dist/effect/index.d.ts +0 -2
- package/dist/effect/request.effect.d.ts +0 -14
- package/dist/effect/request.effect.types.d.ts +0 -32
- package/dist/managers/app/app.manager.constants.d.ts +0 -9
- package/dist/managers/app/app.manager.d.ts +0 -34
- package/dist/managers/app/app.manager.events.d.ts +0 -11
- package/dist/managers/app/app.manager.types.d.ts +0 -6
- package/dist/managers/app/app.manager.utils.d.ts +0 -4
- package/dist/managers/app/index.d.ts +0 -5
- package/dist/managers/index.d.ts +0 -3
- package/dist/managers/logger/index.d.ts +0 -4
- package/dist/managers/logger/logger.manager.constants.d.ts +0 -4
- package/dist/managers/logger/logger.manager.d.ts +0 -19
- package/dist/managers/logger/logger.manager.types.d.ts +0 -30
- package/dist/managers/logger/logger.manager.utils.d.ts +0 -3
- package/dist/managers/request/index.d.ts +0 -4
- package/dist/managers/request/request.manager.d.ts +0 -43
- package/dist/managers/request/request.manager.events.d.ts +0 -36
- package/dist/managers/request/request.manager.types.d.ts +0 -23
- package/dist/managers/request/request.manager.utils.d.ts +0 -16
- package/dist/request/index.d.ts +0 -3
- package/dist/request/request.d.ts +0 -98
- package/dist/request/request.types.d.ts +0 -202
- package/dist/request/request.utils.d.ts +0 -22
- package/dist/types/fetch.types.d.ts +0 -16
- package/dist/types/helpers.types.d.ts +0 -11
- package/dist/types/http.types.d.ts +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/uuid.utils.d.ts +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,1273 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
type NegativeTypes = null | undefined;
|
|
4
|
+
type NullableType<T> = T | NegativeTypes;
|
|
5
|
+
type NullableKeys<T> = {
|
|
6
|
+
[P in keyof T]-?: NullableType<T[P]>;
|
|
7
|
+
};
|
|
8
|
+
type NonNullableKeys<T> = {
|
|
9
|
+
[P in keyof T]-?: NonNullable<T[P]>;
|
|
10
|
+
};
|
|
11
|
+
type RequiredKeys<T> = {
|
|
12
|
+
[P in keyof T]-?: Exclude<T[P], NegativeTypes>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type HttpMethodsType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
16
|
+
|
|
17
|
+
declare const adapter: AdapterType;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* App manager handles main application states - focus and online. Those two values can answer questions:
|
|
21
|
+
* - Is the tab or current view instance focused and visible for user?
|
|
22
|
+
* - Is our application online or offline?
|
|
23
|
+
* With the app manager it is not a problem to get the valid answer for this question.
|
|
24
|
+
*
|
|
25
|
+
* @caution
|
|
26
|
+
* Make sure to apply valid focus/online handlers for different environments like for example for native mobile applications.
|
|
27
|
+
*/
|
|
28
|
+
declare class AppManager {
|
|
29
|
+
options?: AppManagerOptionsType;
|
|
30
|
+
emitter: EventEmitter;
|
|
31
|
+
events: {
|
|
32
|
+
emitFocus: () => void;
|
|
33
|
+
emitBlur: () => void;
|
|
34
|
+
emitOnline: () => void;
|
|
35
|
+
emitOffline: () => void;
|
|
36
|
+
onFocus: (callback: () => void) => VoidFunction;
|
|
37
|
+
onBlur: (callback: () => void) => VoidFunction;
|
|
38
|
+
onOnline: (callback: () => void) => VoidFunction;
|
|
39
|
+
onOffline: (callback: () => void) => VoidFunction;
|
|
40
|
+
};
|
|
41
|
+
isBrowser: boolean;
|
|
42
|
+
isOnline: boolean;
|
|
43
|
+
isFocused: boolean;
|
|
44
|
+
constructor(options?: AppManagerOptionsType);
|
|
45
|
+
private setInitialFocus;
|
|
46
|
+
private setInitialOnline;
|
|
47
|
+
setFocused: (isFocused: boolean) => void;
|
|
48
|
+
setOnline: (isOnline: boolean) => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type AppManagerOptionsType = {
|
|
52
|
+
initiallyFocused?: boolean | (() => boolean | Promise<boolean>);
|
|
53
|
+
initiallyOnline?: boolean | (() => boolean | Promise<boolean>);
|
|
54
|
+
focusEvent?: (setFocused: (isFocused: boolean) => void) => void;
|
|
55
|
+
onlineEvent?: (setOnline: (isOnline: boolean) => void) => void;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
declare const hasWindow: () => boolean;
|
|
59
|
+
declare const hasDocument: () => boolean;
|
|
60
|
+
declare const onWindowEvent: <K extends keyof WindowEventMap>(key: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined) => void;
|
|
61
|
+
declare const onDocumentEvent: <K extends keyof DocumentEventMap>(key: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined) => void;
|
|
62
|
+
|
|
63
|
+
declare const getAppManagerEvents: (emitter: EventEmitter) => {
|
|
64
|
+
emitFocus: () => void;
|
|
65
|
+
emitBlur: () => void;
|
|
66
|
+
emitOnline: () => void;
|
|
67
|
+
emitOffline: () => void;
|
|
68
|
+
onFocus: (callback: () => void) => VoidFunction;
|
|
69
|
+
onBlur: (callback: () => void) => VoidFunction;
|
|
70
|
+
onOnline: (callback: () => void) => VoidFunction;
|
|
71
|
+
onOffline: (callback: () => void) => VoidFunction;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
declare enum AppEvents {
|
|
75
|
+
focus = "focus",
|
|
76
|
+
blur = "blur",
|
|
77
|
+
online = "online",
|
|
78
|
+
offline = "offline"
|
|
79
|
+
}
|
|
80
|
+
declare const appManagerInitialOptions: RequiredKeys<AppManagerOptionsType>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* **Request Manager** is used to emit `request lifecycle events` like - request start, request end, upload and download progress.
|
|
84
|
+
* It is also the place of `request aborting` system, here we store all the keys and controllers that are isolated for each client instance.
|
|
85
|
+
*/
|
|
86
|
+
declare class RequestManager {
|
|
87
|
+
emitter: EventEmitter;
|
|
88
|
+
events: {
|
|
89
|
+
emitLoading: (queueKey: string, requestId: string, values: RequestLoadingEventType) => void;
|
|
90
|
+
emitRequestStart: (queueKey: string, requestId: string, details: RequestEventType<RequestInstance>) => void;
|
|
91
|
+
emitResponseStart: (queueKey: string, requestId: string, details: RequestEventType<RequestInstance>) => void;
|
|
92
|
+
emitUploadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
93
|
+
emitDownloadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
94
|
+
emitResponse: (cacheKey: string, requestId: string, response: ResponseType<unknown, unknown>, details: ResponseDetailsType) => void;
|
|
95
|
+
emitAbort: (abortKey: string, requestId: string, request: RequestInstance) => void;
|
|
96
|
+
emitRemove: <T extends RequestInstance>(queueKey: string, requestId: string, details: RequestEventType<T>) => void;
|
|
97
|
+
onLoading: (queueKey: string, callback: (values: RequestLoadingEventType) => void) => VoidFunction;
|
|
98
|
+
onLoadingById: (requestId: string, callback: (values: RequestLoadingEventType) => void) => VoidFunction;
|
|
99
|
+
onRequestStart: <T_1 extends RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_1>) => void) => VoidFunction;
|
|
100
|
+
onRequestStartById: <T_2 extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T_2>) => void) => VoidFunction;
|
|
101
|
+
onResponseStart: <T_3 extends RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_3>) => void) => VoidFunction;
|
|
102
|
+
onResponseStartById: <T_4 extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T_4>) => void) => VoidFunction;
|
|
103
|
+
onUploadProgress: <T_5 extends RequestInstance = RequestInstance>(queueKey: string, callback: (values: ProgressType, details: RequestEventType<T_5>) => void) => VoidFunction;
|
|
104
|
+
onUploadProgressById: <T_6 extends RequestInstance = RequestInstance>(requestId: string, callback: (values: ProgressType, details: RequestEventType<T_6>) => void) => VoidFunction;
|
|
105
|
+
onDownloadProgress: <T_7 extends RequestInstance = RequestInstance>(queueKey: string, callback: (values: ProgressType, details: RequestEventType<T_7>) => void) => VoidFunction;
|
|
106
|
+
onDownloadProgressById: <T_8 extends RequestInstance = RequestInstance>(requestId: string, callback: (values: ProgressType, details: RequestEventType<T_8>) => void) => VoidFunction;
|
|
107
|
+
onResponse: <Response_1, ErrorType>(cacheKey: string, callback: (response: ResponseType<Response_1, ErrorType>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
108
|
+
onResponseById: <Response_2, ErrorType_1>(requestId: string, callback: (response: ResponseType<Response_2, ErrorType_1>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
109
|
+
onAbort: (abortKey: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
110
|
+
onAbortById: (requestId: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
111
|
+
onRemove: <T_9 extends RequestInstance = RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_9>) => void) => VoidFunction;
|
|
112
|
+
onRemoveById: <T_10 extends RequestInstance = RequestInstance>(requestId: string, callback: (details: RequestEventType<T_10>) => void) => VoidFunction;
|
|
113
|
+
};
|
|
114
|
+
abortControllers: Map<string, Map<string, AbortController>>;
|
|
115
|
+
addAbortController: (abortKey: string, requestId: string) => void;
|
|
116
|
+
getAbortController: (abortKey: string, requestId: string) => AbortController;
|
|
117
|
+
removeAbortController: (abortKey: string, requestId: string) => void;
|
|
118
|
+
useAbortController: (abortKey: string, requestId: string) => void;
|
|
119
|
+
abortByKey: (abortKey: string) => void;
|
|
120
|
+
abortByRequestId: (abortKey: string, requestId: string) => void;
|
|
121
|
+
abortAll: () => void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare const getLoadingEventKey: (key: string) => string;
|
|
125
|
+
declare const getLoadingIdEventKey: (key: string) => string;
|
|
126
|
+
declare const getRemoveEventKey: (key: string) => string;
|
|
127
|
+
declare const getRemoveIdEventKey: (key: string) => string;
|
|
128
|
+
declare const getAbortEventKey: (key: string) => string;
|
|
129
|
+
declare const getAbortByIdEventKey: (key: string) => string;
|
|
130
|
+
declare const getResponseEventKey: (key: string) => string;
|
|
131
|
+
declare const getResponseIdEventKey: (key: string) => string;
|
|
132
|
+
declare const getRequestStartEventKey: (key: string) => string;
|
|
133
|
+
declare const getRequestStartIdEventKey: (key: string) => string;
|
|
134
|
+
declare const getResponseStartEventKey: (key: string) => string;
|
|
135
|
+
declare const getResponseStartIdEventKey: (key: string) => string;
|
|
136
|
+
declare const getUploadProgressEventKey: (key: string) => string;
|
|
137
|
+
declare const getUploadProgressIdEventKey: (key: string) => string;
|
|
138
|
+
declare const getDownloadProgressEventKey: (key: string) => string;
|
|
139
|
+
declare const getDownloadProgressIdEventKey: (key: string) => string;
|
|
140
|
+
|
|
141
|
+
declare const getRequestManagerEvents: (emitter: EventEmitter) => {
|
|
142
|
+
/**
|
|
143
|
+
* Emiter
|
|
144
|
+
*/
|
|
145
|
+
emitLoading: (queueKey: string, requestId: string, values: RequestLoadingEventType) => void;
|
|
146
|
+
emitRequestStart: (queueKey: string, requestId: string, details: RequestEventType<RequestInstance>) => void;
|
|
147
|
+
emitResponseStart: (queueKey: string, requestId: string, details: RequestEventType<RequestInstance>) => void;
|
|
148
|
+
emitUploadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
149
|
+
emitDownloadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
150
|
+
emitResponse: (cacheKey: string, requestId: string, response: ResponseType<unknown, unknown>, details: ResponseDetailsType) => void;
|
|
151
|
+
emitAbort: (abortKey: string, requestId: string, request: RequestInstance) => void;
|
|
152
|
+
emitRemove: <T extends RequestInstance>(queueKey: string, requestId: string, details: RequestEventType<T>) => void;
|
|
153
|
+
/**
|
|
154
|
+
* Listeners
|
|
155
|
+
*/
|
|
156
|
+
onLoading: (queueKey: string, callback: (values: RequestLoadingEventType) => void) => VoidFunction;
|
|
157
|
+
onLoadingById: (requestId: string, callback: (values: RequestLoadingEventType) => void) => VoidFunction;
|
|
158
|
+
onRequestStart: <T_1 extends RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_1>) => void) => VoidFunction;
|
|
159
|
+
onRequestStartById: <T_2 extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T_2>) => void) => VoidFunction;
|
|
160
|
+
onResponseStart: <T_3 extends RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_3>) => void) => VoidFunction;
|
|
161
|
+
onResponseStartById: <T_4 extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T_4>) => void) => VoidFunction;
|
|
162
|
+
onUploadProgress: <T_5 extends RequestInstance = RequestInstance>(queueKey: string, callback: (values: ProgressType, details: RequestEventType<T_5>) => void) => VoidFunction;
|
|
163
|
+
onUploadProgressById: <T_6 extends RequestInstance = RequestInstance>(requestId: string, callback: (values: ProgressType, details: RequestEventType<T_6>) => void) => VoidFunction;
|
|
164
|
+
onDownloadProgress: <T_7 extends RequestInstance = RequestInstance>(queueKey: string, callback: (values: ProgressType, details: RequestEventType<T_7>) => void) => VoidFunction;
|
|
165
|
+
onDownloadProgressById: <T_8 extends RequestInstance = RequestInstance>(requestId: string, callback: (values: ProgressType, details: RequestEventType<T_8>) => void) => VoidFunction;
|
|
166
|
+
onResponse: <Response_1, ErrorType>(cacheKey: string, callback: (response: ResponseType<Response_1, ErrorType>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
167
|
+
onResponseById: <Response_2, ErrorType_1>(requestId: string, callback: (response: ResponseType<Response_2, ErrorType_1>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
168
|
+
onAbort: (abortKey: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
169
|
+
onAbortById: (requestId: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
170
|
+
onRemove: <T_9 extends RequestInstance = RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_9>) => void) => VoidFunction;
|
|
171
|
+
onRemoveById: <T_10 extends RequestInstance = RequestInstance>(requestId: string, callback: (details: RequestEventType<T_10>) => void) => VoidFunction;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
type RequestLoadingEventType = {
|
|
175
|
+
queueKey: string;
|
|
176
|
+
requestId: string;
|
|
177
|
+
loading: boolean;
|
|
178
|
+
isRetry: boolean;
|
|
179
|
+
isOffline: boolean;
|
|
180
|
+
};
|
|
181
|
+
type RequestEventType<T extends RequestInstance> = {
|
|
182
|
+
requestId: string;
|
|
183
|
+
request: T;
|
|
184
|
+
};
|
|
185
|
+
type ResponseDetailsType = {
|
|
186
|
+
retries: number;
|
|
187
|
+
timestamp: number;
|
|
188
|
+
isFailed: boolean;
|
|
189
|
+
isCanceled: boolean;
|
|
190
|
+
isOffline: boolean;
|
|
191
|
+
};
|
|
192
|
+
type RequestRemoveDataType = {
|
|
193
|
+
queueKey: string;
|
|
194
|
+
requestId: string;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* This class is used across the Hyper Fetch library to provide unified logging system with necessary setup per each client.
|
|
199
|
+
* We can set up the logging level based on available values. This manager enable to initialize the logging instance per individual module
|
|
200
|
+
* like Client, Request etc. Which can give you better feedback on the logging itself.
|
|
201
|
+
*/
|
|
202
|
+
declare class LoggerManager {
|
|
203
|
+
private client;
|
|
204
|
+
private options?;
|
|
205
|
+
logger: LoggerFunctionType;
|
|
206
|
+
severity: SeverityType;
|
|
207
|
+
emitter: EventEmitter;
|
|
208
|
+
constructor(client: Pick<ClientInstance, "debug">, options?: LoggerOptionsType);
|
|
209
|
+
setSeverity: (severity: SeverityType) => void;
|
|
210
|
+
init: (module: string) => LoggerType;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
declare const getTime: () => string;
|
|
214
|
+
declare const logger: LoggerFunctionType;
|
|
215
|
+
|
|
216
|
+
type SeverityType = 0 | 1 | 2 | 3;
|
|
217
|
+
type LoggerType = Record<LoggerLevelType, (message: LoggerMessageType, ...additionalData: LoggerMessageType[]) => void>;
|
|
218
|
+
type LoggerFunctionType = (log: LogType) => void;
|
|
219
|
+
type LoggerOptionsType = {
|
|
220
|
+
logger?: LoggerFunctionType;
|
|
221
|
+
severity?: SeverityType;
|
|
222
|
+
};
|
|
223
|
+
type LogType = {
|
|
224
|
+
module: string;
|
|
225
|
+
level: LoggerLevelType;
|
|
226
|
+
message: LoggerMessageType;
|
|
227
|
+
additionalData?: LoggerMessageType[];
|
|
228
|
+
enabled: boolean;
|
|
229
|
+
severity: SeverityType;
|
|
230
|
+
};
|
|
231
|
+
type LoggerLevelType = "error" | "warning" | "info" | "debug";
|
|
232
|
+
type LoggerMessageType = string | Record<string, unknown> | Array<unknown>;
|
|
233
|
+
type LoggerRequestEventData = {
|
|
234
|
+
requestId: string;
|
|
235
|
+
request: RequestInstance;
|
|
236
|
+
};
|
|
237
|
+
type LoggerResponseEventData = {
|
|
238
|
+
requestId: string;
|
|
239
|
+
request: RequestInstance;
|
|
240
|
+
response: ResponseType<unknown, unknown>;
|
|
241
|
+
details: ResponseDetailsType;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
declare const loggerStyles: Record<LoggerLevelType, string>;
|
|
245
|
+
declare const loggerIconLevels: Record<LoggerLevelType, string>;
|
|
246
|
+
declare const severity: Record<LoggerLevelType, number>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Cache class handles the data exchange with the dispatchers.
|
|
250
|
+
*
|
|
251
|
+
* @note
|
|
252
|
+
* Keys used to save the values are created dynamically on the Request class
|
|
253
|
+
*
|
|
254
|
+
*/
|
|
255
|
+
declare class Cache {
|
|
256
|
+
client: ClientInstance;
|
|
257
|
+
options?: CacheOptionsType;
|
|
258
|
+
emitter: EventEmitter;
|
|
259
|
+
events: ReturnType<typeof getCacheEvents>;
|
|
260
|
+
storage: CacheStorageType;
|
|
261
|
+
lazyStorage?: CacheAsyncStorageType;
|
|
262
|
+
clearKey: string;
|
|
263
|
+
garbageCollectors: Map<string, NodeJS.Timeout>;
|
|
264
|
+
private logger;
|
|
265
|
+
constructor(client: ClientInstance, options?: CacheOptionsType);
|
|
266
|
+
/**
|
|
267
|
+
* Set the cache data to the storage
|
|
268
|
+
* @param request
|
|
269
|
+
* @param response
|
|
270
|
+
* @param details
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
set: <Response_1, Error_1>(request: RequestInstance | RequestDump<RequestInstance>, response: ResponseType<Response_1, Error_1>, details: ResponseDetailsType) => void;
|
|
274
|
+
/**
|
|
275
|
+
* Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.
|
|
276
|
+
* @param cacheKey
|
|
277
|
+
* @returns
|
|
278
|
+
*/
|
|
279
|
+
get: <Response_1, Error_1>(cacheKey: string) => CacheValueType<Response_1, Error_1>;
|
|
280
|
+
/**
|
|
281
|
+
* Get sync storage keys, lazyStorage keys will not be included
|
|
282
|
+
* @returns
|
|
283
|
+
*/
|
|
284
|
+
keys: () => string[];
|
|
285
|
+
/**
|
|
286
|
+
* Delete record from storages and trigger revalidation
|
|
287
|
+
* @param cacheKey
|
|
288
|
+
*/
|
|
289
|
+
delete: (cacheKey: string) => void;
|
|
290
|
+
/**
|
|
291
|
+
* Revalidate cache by cacheKey or partial matching with RegExp
|
|
292
|
+
* @param cacheKey
|
|
293
|
+
*/
|
|
294
|
+
revalidate: (cacheKey: string | RegExp) => Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Used to receive data from lazy storage
|
|
297
|
+
* @param cacheKey
|
|
298
|
+
*/
|
|
299
|
+
getLazyResource: <Response_1, Error_1>(cacheKey: string) => Promise<CacheValueType<Response_1, Error_1>>;
|
|
300
|
+
/**
|
|
301
|
+
* Used to receive keys from sync storage and lazy storage
|
|
302
|
+
* @param cacheKey
|
|
303
|
+
*/
|
|
304
|
+
getLazyKeys: () => Promise<string[]>;
|
|
305
|
+
/**
|
|
306
|
+
* Schedule garbage collection for given key
|
|
307
|
+
* @param cacheKey
|
|
308
|
+
* @returns
|
|
309
|
+
*/
|
|
310
|
+
scheduleGarbageCollector: (cacheKey: string) => Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Clear cache storages
|
|
313
|
+
*/
|
|
314
|
+
clear: () => Promise<void>;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
type CacheOptionsType = {
|
|
318
|
+
/**
|
|
319
|
+
* Assign your custom sync storage
|
|
320
|
+
*/
|
|
321
|
+
storage?: CacheStorageType;
|
|
322
|
+
/**
|
|
323
|
+
* Lazy loading from remote resources - possibly persistent
|
|
324
|
+
*/
|
|
325
|
+
lazyStorage?: CacheAsyncStorageType;
|
|
326
|
+
/**
|
|
327
|
+
* Key to clear lazy storage data
|
|
328
|
+
*/
|
|
329
|
+
clearKey?: string;
|
|
330
|
+
/**
|
|
331
|
+
* Initialization callback
|
|
332
|
+
*/
|
|
333
|
+
onInitialization?: (cache: Cache) => void;
|
|
334
|
+
/**
|
|
335
|
+
* Callback for every change in the storage
|
|
336
|
+
*/
|
|
337
|
+
onChange?: <Response = any, Error = any>(key: string, data: CacheValueType<Response, Error>) => void;
|
|
338
|
+
/**
|
|
339
|
+
* Callback for every delete in the storage
|
|
340
|
+
*/
|
|
341
|
+
onDelete?: (key: string) => void;
|
|
342
|
+
};
|
|
343
|
+
type CacheValueType<Response = any, Error = any> = {
|
|
344
|
+
data: ResponseType<Response, Error>;
|
|
345
|
+
details: ResponseDetailsType;
|
|
346
|
+
cacheTime: number;
|
|
347
|
+
clearKey: string;
|
|
348
|
+
garbageCollection: number;
|
|
349
|
+
};
|
|
350
|
+
type CacheAsyncStorageType = {
|
|
351
|
+
set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => Promise<void>;
|
|
352
|
+
get: <Response, Error>(key: string) => Promise<CacheValueType<Response, Error> | undefined>;
|
|
353
|
+
keys: () => Promise<string[] | IterableIterator<string> | string[]>;
|
|
354
|
+
delete: (key: string) => Promise<void>;
|
|
355
|
+
};
|
|
356
|
+
type CacheStorageType = {
|
|
357
|
+
set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => void;
|
|
358
|
+
get: <Response, Error>(key: string) => CacheValueType<Response, Error> | undefined;
|
|
359
|
+
keys: () => string[] | IterableIterator<string> | string[];
|
|
360
|
+
delete: (key: string) => void;
|
|
361
|
+
clear: () => void;
|
|
362
|
+
};
|
|
363
|
+
type CacheInitialData = Record<string, CacheValueType>;
|
|
364
|
+
|
|
365
|
+
declare const getCacheData: <T extends RequestInstance>(previousResponse: ExtractAdapterReturnType<T>, response: ExtractAdapterReturnType<T>) => ExtractAdapterReturnType<T>;
|
|
366
|
+
declare const getRevalidateEventKey: (key: string) => string;
|
|
367
|
+
declare const getCacheKey: (key: string) => string;
|
|
368
|
+
declare const getCacheIdKey: (key: string) => string;
|
|
369
|
+
|
|
370
|
+
declare const getCacheEvents: (emitter: EventEmitter) => {
|
|
371
|
+
/**
|
|
372
|
+
* Set cache data
|
|
373
|
+
* @param cacheKey
|
|
374
|
+
* @param data
|
|
375
|
+
*/
|
|
376
|
+
emitCacheData: <Response_1, Error_1>(cacheKey: string, data: CacheValueType<Response_1, Error_1>) => void;
|
|
377
|
+
/**
|
|
378
|
+
* Revalidate cache values event
|
|
379
|
+
*/
|
|
380
|
+
emitRevalidation: (cacheKey: string) => void;
|
|
381
|
+
/**
|
|
382
|
+
* Cache data listener
|
|
383
|
+
* @param cacheKey
|
|
384
|
+
* @param callback
|
|
385
|
+
* @returns
|
|
386
|
+
*/
|
|
387
|
+
onData: <Response_2, Error_2>(cacheKey: string, callback: (data: CacheValueType<Response_2, Error_2>) => void) => VoidFunction;
|
|
388
|
+
/**
|
|
389
|
+
* Cache invalidation listener
|
|
390
|
+
* @param cacheKey
|
|
391
|
+
* @param callback
|
|
392
|
+
* @returns
|
|
393
|
+
*/
|
|
394
|
+
onRevalidate: (cacheKey: string, callback: () => void) => VoidFunction;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
declare enum DispatcherRequestType {
|
|
398
|
+
oneByOne = "one-by-one",
|
|
399
|
+
allAtOnce = "all-at-once",
|
|
400
|
+
previousCanceled = "previous-canceled",
|
|
401
|
+
deduplicated = "deduplicated"
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
declare const getDispatcherEvents: (emitter: EventEmitter) => {
|
|
405
|
+
setDrained: <Request_1 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_1>) => void;
|
|
406
|
+
setQueueStatus: <Request_2 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_2>) => void;
|
|
407
|
+
setQueueChanged: <Request_3 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_3>) => void;
|
|
408
|
+
onDrained: <Request_4 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_4>) => void) => VoidFunction;
|
|
409
|
+
onQueueStatus: <Request_5 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_5>) => void) => VoidFunction;
|
|
410
|
+
onQueueChange: <Request_6 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_6>) => void) => VoidFunction;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Dispatcher class was made to store controlled request Fetches, and firing them all-at-once or one-by-one in request queue.
|
|
415
|
+
* Generally requests should be flushed at the same time, the queue provide mechanism to fire them in the order.
|
|
416
|
+
*/
|
|
417
|
+
declare class Dispatcher {
|
|
418
|
+
client: ClientInstance;
|
|
419
|
+
options?: DispatcherOptionsType;
|
|
420
|
+
emitter: EventEmitter;
|
|
421
|
+
events: {
|
|
422
|
+
setDrained: <Request_1 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_1>) => void;
|
|
423
|
+
setQueueStatus: <Request_2 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_2>) => void;
|
|
424
|
+
setQueueChanged: <Request_3 extends RequestInstance>(queueKey: string, values: QueueDataType<Request_3>) => void;
|
|
425
|
+
onDrained: <Request_4 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_4>) => void) => VoidFunction;
|
|
426
|
+
onQueueStatus: <Request_5 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_5>) => void) => VoidFunction;
|
|
427
|
+
onQueueChange: <Request_6 extends RequestInstance>(queueKey: string, callback: (values: QueueDataType<Request_6>) => void) => VoidFunction;
|
|
428
|
+
};
|
|
429
|
+
storage: DispatcherStorageType;
|
|
430
|
+
private requestCount;
|
|
431
|
+
private runningRequests;
|
|
432
|
+
private logger;
|
|
433
|
+
constructor(client: ClientInstance, options?: DispatcherOptionsType);
|
|
434
|
+
/**
|
|
435
|
+
* Start request handling by queueKey
|
|
436
|
+
*/
|
|
437
|
+
start: (queueKey: string) => void;
|
|
438
|
+
/**
|
|
439
|
+
* Pause request queue, but not cancel already started requests
|
|
440
|
+
*/
|
|
441
|
+
pause: (queueKey: string) => void;
|
|
442
|
+
/**
|
|
443
|
+
* Stop request queue and cancel all started requests - those will be treated like not started
|
|
444
|
+
*/
|
|
445
|
+
stop: (queueKey: string) => void;
|
|
446
|
+
/**
|
|
447
|
+
* Return all
|
|
448
|
+
*/
|
|
449
|
+
getQueuesKeys: () => string[];
|
|
450
|
+
/**
|
|
451
|
+
* Return queue state object
|
|
452
|
+
*/
|
|
453
|
+
getQueue: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string) => QueueDataType<Request_1>;
|
|
454
|
+
/**
|
|
455
|
+
* Return request from queue state
|
|
456
|
+
*/
|
|
457
|
+
getRequest: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, requestId: string) => DispatcherStorageValueType<Request_1>;
|
|
458
|
+
/**
|
|
459
|
+
* Get value of the active queue status based on the stopped status
|
|
460
|
+
*/
|
|
461
|
+
getIsActiveQueue: (queueKey: string) => boolean;
|
|
462
|
+
/**
|
|
463
|
+
* Add new element to storage
|
|
464
|
+
*/
|
|
465
|
+
addQueueElement: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, dispatcherDump: DispatcherStorageValueType<Request_1>) => void;
|
|
466
|
+
/**
|
|
467
|
+
* Set new queue storage value
|
|
468
|
+
*/
|
|
469
|
+
setQueue: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, queue: QueueDataType<Request_1>) => QueueDataType<Request_1>;
|
|
470
|
+
/**
|
|
471
|
+
* Clear requests from queue cache
|
|
472
|
+
*/
|
|
473
|
+
clearQueue: (queueKey: string) => {
|
|
474
|
+
requests: any[];
|
|
475
|
+
stopped: boolean;
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* Method used to flush the queue requests
|
|
479
|
+
*/
|
|
480
|
+
flushQueue: (queueKey: string) => Promise<void>;
|
|
481
|
+
/**
|
|
482
|
+
* Flush all available requests from all queues
|
|
483
|
+
*/
|
|
484
|
+
flush: () => Promise<void>;
|
|
485
|
+
/**
|
|
486
|
+
* Clear all running requests and storage
|
|
487
|
+
*/
|
|
488
|
+
clear: () => void;
|
|
489
|
+
/**
|
|
490
|
+
* Start particular request
|
|
491
|
+
*/
|
|
492
|
+
startRequest: (queueKey: string, requestId: string) => void;
|
|
493
|
+
/**
|
|
494
|
+
* Stop particular request
|
|
495
|
+
*/
|
|
496
|
+
stopRequest: (queueKey: string, requestId: string) => void;
|
|
497
|
+
/**
|
|
498
|
+
* Get currently running requests from all queueKeys
|
|
499
|
+
*/
|
|
500
|
+
getAllRunningRequest: () => RunningRequestValueType[];
|
|
501
|
+
/**
|
|
502
|
+
* Get currently running requests
|
|
503
|
+
*/
|
|
504
|
+
getRunningRequests: (queueKey: string) => RunningRequestValueType[];
|
|
505
|
+
/**
|
|
506
|
+
* Get running request by id
|
|
507
|
+
*/
|
|
508
|
+
getRunningRequest: (queueKey: string, requestId: string) => RunningRequestValueType;
|
|
509
|
+
/**
|
|
510
|
+
* Add request to the running requests list
|
|
511
|
+
*/
|
|
512
|
+
addRunningRequest: (queueKey: string, requestId: string, request: RequestInstance) => void;
|
|
513
|
+
/**
|
|
514
|
+
* Get the value based on the currently running requests
|
|
515
|
+
*/
|
|
516
|
+
hasRunningRequests: (queueKey: string) => boolean;
|
|
517
|
+
/**
|
|
518
|
+
* Check if request is currently processing
|
|
519
|
+
*/
|
|
520
|
+
hasRunningRequest: (queueKey: string, requestId: string) => boolean;
|
|
521
|
+
/**
|
|
522
|
+
* Cancel all started requests, but do NOT remove it from main storage
|
|
523
|
+
*/
|
|
524
|
+
cancelRunningRequests: (queueKey: string) => void;
|
|
525
|
+
/**
|
|
526
|
+
* Cancel started request, but do NOT remove it from main storage
|
|
527
|
+
*/
|
|
528
|
+
cancelRunningRequest: (queueKey: string, requestId: string) => void;
|
|
529
|
+
/**
|
|
530
|
+
* Delete all started requests, but do NOT clear it from queue and do NOT cancel them
|
|
531
|
+
*/
|
|
532
|
+
deleteRunningRequests: (queueKey: string) => void;
|
|
533
|
+
/**
|
|
534
|
+
* Delete request by id, but do NOT clear it from queue and do NOT cancel them
|
|
535
|
+
*/
|
|
536
|
+
deleteRunningRequest: (queueKey: string, requestId: string) => void;
|
|
537
|
+
/**
|
|
538
|
+
* Get count of requests from the same queueKey
|
|
539
|
+
*/
|
|
540
|
+
getQueueRequestCount: (queueKey: string) => number;
|
|
541
|
+
/**
|
|
542
|
+
* Add request count to the queueKey
|
|
543
|
+
*/
|
|
544
|
+
incrementQueueRequestCount: (queueKey: string) => void;
|
|
545
|
+
/**
|
|
546
|
+
* Create storage element from request
|
|
547
|
+
*/
|
|
548
|
+
createStorageElement: <Request_1 extends RequestInstance>(request: Request_1) => DispatcherStorageValueType<Request_1>;
|
|
549
|
+
/**
|
|
550
|
+
* Add request to the dispatcher handler
|
|
551
|
+
*/
|
|
552
|
+
add: (request: RequestInstance) => string;
|
|
553
|
+
/**
|
|
554
|
+
* Delete from the storage and cancel request
|
|
555
|
+
*/
|
|
556
|
+
delete: (queueKey: string, requestId: string, abortKey: string) => QueueDataType<RequestInstance>;
|
|
557
|
+
/**
|
|
558
|
+
* Request can run for some time, once it's done, we have to check if it's successful or if it was aborted
|
|
559
|
+
* It can be different once the previous call was set as cancelled and removed from queue before this request got resolved
|
|
560
|
+
*/
|
|
561
|
+
performRequest: (storageElement: DispatcherStorageValueType) => Promise<void | QueueDataType<RequestInstance>>;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
type DispatcherOptionsType = {
|
|
565
|
+
storage?: DispatcherStorageType;
|
|
566
|
+
onInitialization?: (dispatcherInstance: Dispatcher) => void;
|
|
567
|
+
onUpdateStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
|
|
568
|
+
onDeleteFromStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
|
|
569
|
+
onClearStorage?: (dispatcherInstance: Dispatcher) => void;
|
|
570
|
+
};
|
|
571
|
+
type DispatcherStorageValueType<Request extends RequestInstance = RequestInstance> = {
|
|
572
|
+
requestId: string;
|
|
573
|
+
requestDump: RequestDump<Request>;
|
|
574
|
+
retries: number;
|
|
575
|
+
timestamp: number;
|
|
576
|
+
stopped: boolean;
|
|
577
|
+
};
|
|
578
|
+
type QueueDataType<Request extends RequestInstance = RequestInstance> = {
|
|
579
|
+
requests: DispatcherStorageValueType<Request>[];
|
|
580
|
+
stopped: boolean;
|
|
581
|
+
};
|
|
582
|
+
type DispatcherStorageType = {
|
|
583
|
+
set: <Request extends RequestInstance = RequestInstance>(key: string, data: QueueDataType<Request>) => void;
|
|
584
|
+
get: <Request extends RequestInstance = RequestInstance>(key: string) => QueueDataType<Request> | undefined;
|
|
585
|
+
keys: () => string[] | IterableIterator<string>;
|
|
586
|
+
delete: (key: string) => void;
|
|
587
|
+
clear: () => void;
|
|
588
|
+
};
|
|
589
|
+
type RunningRequestValueType = {
|
|
590
|
+
requestId: string;
|
|
591
|
+
request: RequestInstance;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
declare const getDispatcherDrainedEventKey: (key: string) => string;
|
|
595
|
+
declare const getDispatcherStatusEventKey: (key: string) => string;
|
|
596
|
+
declare const getDispatcherChangeEventKey: (key: string) => string;
|
|
597
|
+
declare const getIsEqualTimestamp: (currentTimestamp: number, threshold: number, queueTimestamp?: number) => boolean;
|
|
598
|
+
declare const canRetryRequest: (currentRetries: number, retry: number | undefined) => boolean;
|
|
599
|
+
declare const getRequestType: (request: RequestInstance, latestRequest: DispatcherStorageValueType | undefined) => DispatcherRequestType;
|
|
600
|
+
declare const isFailedRequest: (data: ResponseType<unknown, unknown>) => boolean;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* **Client** is a class that allows you to configure the connection with the server and then use it to create
|
|
604
|
+
* requests which, when called using the appropriate method, will cause the server to be queried for the endpoint and
|
|
605
|
+
* method specified in the request.
|
|
606
|
+
* @position 1
|
|
607
|
+
*/
|
|
608
|
+
declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOptions = AdapterOptionsType> {
|
|
609
|
+
options: ClientOptionsType;
|
|
610
|
+
readonly url: string;
|
|
611
|
+
debug: boolean;
|
|
612
|
+
__onErrorCallbacks: ResponseInterceptorType[];
|
|
613
|
+
__onSuccessCallbacks: ResponseInterceptorType[];
|
|
614
|
+
__onResponseCallbacks: ResponseInterceptorType[];
|
|
615
|
+
__onAuthCallbacks: RequestInterceptorType[];
|
|
616
|
+
__onRequestCallbacks: RequestInterceptorType[];
|
|
617
|
+
requestManager: RequestManager;
|
|
618
|
+
appManager: AppManager;
|
|
619
|
+
loggerManager: LoggerManager;
|
|
620
|
+
adapter: AdapterType;
|
|
621
|
+
cache: Cache;
|
|
622
|
+
fetchDispatcher: Dispatcher;
|
|
623
|
+
submitDispatcher: Dispatcher;
|
|
624
|
+
effects: RequestEffectInstance[];
|
|
625
|
+
queryParamsConfig?: QueryStringifyOptionsType;
|
|
626
|
+
adapterDefaultOptions?: (request: RequestInstance) => AdapterOptions;
|
|
627
|
+
requestDefaultOptions?: (options: RequestOptionsType<string, AdapterOptions>) => Partial<RequestOptionsType<string, AdapterOptions>>;
|
|
628
|
+
/**
|
|
629
|
+
* Method to stringify query params from objects.
|
|
630
|
+
*/
|
|
631
|
+
stringifyQueryParams: StringifyCallbackType;
|
|
632
|
+
/**
|
|
633
|
+
* Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats.
|
|
634
|
+
*/
|
|
635
|
+
headerMapper: HeaderMappingType;
|
|
636
|
+
/**
|
|
637
|
+
* Method to get request data and transform them to the required format. It handles FormData and JSON by default.
|
|
638
|
+
*/
|
|
639
|
+
payloadMapper: AdapterPayloadMappingType;
|
|
640
|
+
logger: LoggerType;
|
|
641
|
+
constructor(options: ClientOptionsType);
|
|
642
|
+
/**
|
|
643
|
+
* This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
|
|
644
|
+
*/
|
|
645
|
+
setRequestDefaultOptions: (callback: (request: RequestInstance) => Partial<RequestOptionsType<string, AdapterOptions>>) => Client<GlobalErrorType, AdapterOptions>;
|
|
646
|
+
setAdapterDefaultOptions: (callback: (request: RequestInstance) => AdapterOptions) => Client<GlobalErrorType, AdapterOptions>;
|
|
647
|
+
/**
|
|
648
|
+
* This method enables the logger usage and display the logs in console
|
|
649
|
+
*/
|
|
650
|
+
setDebug: (debug: boolean) => Client<GlobalErrorType, AdapterOptions>;
|
|
651
|
+
/**
|
|
652
|
+
* Set the logger severity of the messages displayed to the console
|
|
653
|
+
*/
|
|
654
|
+
setLoggerSeverity: (severity: SeverityType) => Client<GlobalErrorType, AdapterOptions>;
|
|
655
|
+
/**
|
|
656
|
+
* Set the new logger instance to the Client
|
|
657
|
+
*/
|
|
658
|
+
setLogger: (callback: (Client: ClientInstance) => LoggerManager) => Client<GlobalErrorType, AdapterOptions>;
|
|
659
|
+
/**
|
|
660
|
+
* Set config for the query params stringify method, we can set here, among others, arrayFormat, skipNull, encode, skipEmptyString and more
|
|
661
|
+
*/
|
|
662
|
+
setQueryParamsConfig: (queryParamsConfig: QueryStringifyOptionsType) => Client<GlobalErrorType, AdapterOptions>;
|
|
663
|
+
/**
|
|
664
|
+
* Set the custom query params stringify method to the Client
|
|
665
|
+
* @param stringifyFn Custom callback handling query params stringify
|
|
666
|
+
*/
|
|
667
|
+
setStringifyQueryParams: (stringifyFn: StringifyCallbackType) => Client<GlobalErrorType, AdapterOptions>;
|
|
668
|
+
/**
|
|
669
|
+
* Set the custom header mapping function
|
|
670
|
+
*/
|
|
671
|
+
setHeaderMapper: (headerMapper: HeaderMappingType) => Client<GlobalErrorType, AdapterOptions>;
|
|
672
|
+
/**
|
|
673
|
+
* Set the request payload mapping function which get triggered before request get send
|
|
674
|
+
*/
|
|
675
|
+
setPayloadMapper: (payloadMapper: AdapterPayloadMappingType) => Client<GlobalErrorType, AdapterOptions>;
|
|
676
|
+
/**
|
|
677
|
+
* Set custom http adapter to handle graphql, rest, firebase or other
|
|
678
|
+
*/
|
|
679
|
+
setAdapter: (callback: (Client: ClientInstance) => AdapterType) => Client<GlobalErrorType, AdapterOptions>;
|
|
680
|
+
/**
|
|
681
|
+
* Method of manipulating requests before sending the request. We can for example add custom header with token to the request which request had the auth set to true.
|
|
682
|
+
*/
|
|
683
|
+
onAuth: (callback: RequestInterceptorType) => Client<GlobalErrorType, AdapterOptions>;
|
|
684
|
+
/**
|
|
685
|
+
* Method for intercepting error responses. It can be used for example to refresh tokens.
|
|
686
|
+
*/
|
|
687
|
+
onError: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType, AdapterOptions>;
|
|
688
|
+
/**
|
|
689
|
+
* Method for intercepting success responses.
|
|
690
|
+
*/
|
|
691
|
+
onSuccess: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType, AdapterOptions>;
|
|
692
|
+
/**
|
|
693
|
+
* Method of manipulating requests before sending the request.
|
|
694
|
+
*/
|
|
695
|
+
onRequest: (callback: RequestInterceptorType) => Client<GlobalErrorType, AdapterOptions>;
|
|
696
|
+
/**
|
|
697
|
+
* Method for intercepting any responses.
|
|
698
|
+
*/
|
|
699
|
+
onResponse: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType, AdapterOptions>;
|
|
700
|
+
/**
|
|
701
|
+
* Add persistent effects which trigger on the request lifecycle
|
|
702
|
+
*/
|
|
703
|
+
addEffect: (effect: RequestEffectInstance | RequestEffectInstance[]) => this;
|
|
704
|
+
/**
|
|
705
|
+
* Remove effects from Client
|
|
706
|
+
*/
|
|
707
|
+
removeEffect: (effect: RequestEffectInstance | string) => this;
|
|
708
|
+
/**
|
|
709
|
+
* Helper used by http adapter to apply the modifications on response error
|
|
710
|
+
*/
|
|
711
|
+
__modifyAuth: (request: RequestInstance) => Promise<RequestInstance>;
|
|
712
|
+
/**
|
|
713
|
+
* Private helper to run async pre-request processing
|
|
714
|
+
*/
|
|
715
|
+
__modifyRequest: (request: RequestInstance) => Promise<RequestInstance>;
|
|
716
|
+
/**
|
|
717
|
+
* Private helper to run async on-error response processing
|
|
718
|
+
*/
|
|
719
|
+
__modifyErrorResponse: (response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
|
|
720
|
+
/**
|
|
721
|
+
* Private helper to run async on-success response processing
|
|
722
|
+
*/
|
|
723
|
+
__modifySuccessResponse: (response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
|
|
724
|
+
/**
|
|
725
|
+
* Private helper to run async response processing
|
|
726
|
+
*/
|
|
727
|
+
__modifyResponse: (response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
|
|
728
|
+
/**
|
|
729
|
+
* Clears the Client instance and remove all listeners on it's dependencies
|
|
730
|
+
*/
|
|
731
|
+
clear: () => void;
|
|
732
|
+
/**
|
|
733
|
+
* Create requests based on the Client setup
|
|
734
|
+
*/
|
|
735
|
+
createRequest: <Response_1, Payload = undefined, LocalError extends ClientErrorType = undefined, QueryParams extends string | QueryParamsType = string | QueryParamsType>() => <EndpointType extends string>(params: RequestOptionsType<EndpointType, AdapterOptions>) => Request<Response_1, Payload, QueryParams, GlobalErrorType, LocalError, EndpointType, AdapterOptions, false, false, false, undefined>;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
type ClientErrorType = Record<string, any> | string;
|
|
739
|
+
type ClientInstance = Client<any, any>;
|
|
740
|
+
/**
|
|
741
|
+
* Configuration setup for the client
|
|
742
|
+
*/
|
|
743
|
+
type ClientOptionsType = {
|
|
744
|
+
/**
|
|
745
|
+
* Url to your server
|
|
746
|
+
*/
|
|
747
|
+
url: string;
|
|
748
|
+
/**
|
|
749
|
+
* Custom adapter initialization prop
|
|
750
|
+
*/
|
|
751
|
+
adapter?: AdapterType;
|
|
752
|
+
/**
|
|
753
|
+
* Custom cache initialization prop
|
|
754
|
+
*/
|
|
755
|
+
cache?: <B extends ClientInstance, C extends Cache>(client: B) => C;
|
|
756
|
+
/**
|
|
757
|
+
* Custom app manager initialization prop
|
|
758
|
+
*/
|
|
759
|
+
appManager?: <B extends ClientInstance, A extends AppManager>(client: B) => A;
|
|
760
|
+
/**
|
|
761
|
+
* Custom fetch dispatcher initialization prop
|
|
762
|
+
*/
|
|
763
|
+
fetchDispatcher?: <B extends ClientInstance, D extends Dispatcher>(client: B) => D;
|
|
764
|
+
/**
|
|
765
|
+
* Custom submit dispatcher initialization prop
|
|
766
|
+
*/
|
|
767
|
+
submitDispatcher?: <B extends ClientInstance, D extends Dispatcher>(client: B) => D;
|
|
768
|
+
};
|
|
769
|
+
type RequestInterceptorType = (request: RequestInstance) => Promise<RequestInstance> | RequestInstance;
|
|
770
|
+
type ResponseInterceptorType<Response = any, Error = any> = (response: ResponseType<Response, Error>, request: RequestInstance) => Promise<ResponseType<any, any>> | ResponseType<any, any>;
|
|
771
|
+
type StringifyCallbackType = (queryParams: QueryParamsType | string | NegativeTypes) => string;
|
|
772
|
+
|
|
773
|
+
declare const stringifyValue: (response: string | unknown) => string;
|
|
774
|
+
declare const interceptRequest: (interceptors: RequestInterceptorType[], request: RequestInstance) => Promise<RequestInstance>;
|
|
775
|
+
declare const interceptResponse: <GlobalErrorType>(interceptors: ResponseInterceptorType[], response: ResponseType<any, GlobalErrorType>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType>>;
|
|
776
|
+
declare const getAdapterHeaders: (request: RequestInstance) => HeadersInit;
|
|
777
|
+
declare const getAdapterPayload: (data: unknown) => string | FormData;
|
|
778
|
+
declare const stringifyQueryParams: (queryParams: QueryParamsType | string | NegativeTypes, options?: QueryStringifyOptionsType) => string;
|
|
779
|
+
|
|
780
|
+
declare const stringifyDefaultOptions: {
|
|
781
|
+
readonly strict: true;
|
|
782
|
+
readonly encode: true;
|
|
783
|
+
readonly arrayFormat: "bracket";
|
|
784
|
+
readonly arraySeparator: "";
|
|
785
|
+
readonly sort: false;
|
|
786
|
+
readonly skipNull: true;
|
|
787
|
+
readonly skipEmptyString: true;
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Fetch request it is designed to prepare the necessary setup to execute the request to the server.
|
|
792
|
+
* We can setup basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
|
|
793
|
+
* :::info Usage
|
|
794
|
+
* We should not use this class directly in the standard development flow. We can initialize it using the `createRequest` method on the **Client** class.
|
|
795
|
+
* :::
|
|
796
|
+
*
|
|
797
|
+
* @attention
|
|
798
|
+
* The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistence and different dispatcher storage types.
|
|
799
|
+
* This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
|
|
800
|
+
*/
|
|
801
|
+
declare class Request<Response, Payload, QueryParams extends QueryParamsType | string, GlobalError, // Global Error Type
|
|
802
|
+
LocalError, // Additional Error for specific endpoint
|
|
803
|
+
Endpoint extends string, AdapterOptions, HasData extends true | false = false, HasParams extends true | false = false, HasQuery extends true | false = false, MappedData = undefined> {
|
|
804
|
+
readonly client: Client<GlobalError, AdapterOptions>;
|
|
805
|
+
readonly requestOptions: RequestOptionsType<Endpoint, AdapterOptions>;
|
|
806
|
+
readonly requestDump?: RequestCurrentType<Response, Payload, QueryParams, GlobalError | LocalError, Endpoint, AdapterOptions, MappedData> | undefined;
|
|
807
|
+
readonly dataMapper?: PayloadMapperType<Payload, MappedData>;
|
|
808
|
+
endpoint: Endpoint;
|
|
809
|
+
headers?: HeadersInit;
|
|
810
|
+
auth: boolean;
|
|
811
|
+
method: HttpMethodsType;
|
|
812
|
+
params: ExtractRouteParams<Endpoint> | NegativeTypes;
|
|
813
|
+
data: PayloadType<Payload, MappedData>;
|
|
814
|
+
queryParams: QueryParams | NegativeTypes;
|
|
815
|
+
options?: AdapterOptions | undefined;
|
|
816
|
+
cancelable: boolean;
|
|
817
|
+
retry: number;
|
|
818
|
+
retryTime: number;
|
|
819
|
+
garbageCollection: number;
|
|
820
|
+
cache: boolean;
|
|
821
|
+
cacheTime: number;
|
|
822
|
+
queued: boolean;
|
|
823
|
+
offline: boolean;
|
|
824
|
+
abortKey: string;
|
|
825
|
+
cacheKey: string;
|
|
826
|
+
queueKey: string;
|
|
827
|
+
effectKey: string;
|
|
828
|
+
used: boolean;
|
|
829
|
+
deduplicate: boolean;
|
|
830
|
+
deduplicateTime: number;
|
|
831
|
+
private updatedAbortKey;
|
|
832
|
+
private updatedCacheKey;
|
|
833
|
+
private updatedQueueKey;
|
|
834
|
+
private updatedEffectKey;
|
|
835
|
+
constructor(client: Client<GlobalError, AdapterOptions>, requestOptions: RequestOptionsType<Endpoint, AdapterOptions>, requestDump?: RequestCurrentType<Response, Payload, QueryParams, GlobalError | LocalError, Endpoint, AdapterOptions, MappedData> | undefined, dataMapper?: PayloadMapperType<Payload, MappedData>);
|
|
836
|
+
setHeaders: (headers: HeadersInit) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
837
|
+
setAuth: (auth: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
838
|
+
setParams: <P extends ExtractRouteParams<Endpoint>>(params: P) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, P extends null ? false : true, HasQuery, MappedData>;
|
|
839
|
+
setData: <D extends Payload>(data: D) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, D extends null ? false : true, HasParams, HasQuery, MappedData>;
|
|
840
|
+
setQueryParams: (queryParams: QueryParams) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, true, MappedData>;
|
|
841
|
+
setOptions: (options: AdapterOptions) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, true, MappedData>;
|
|
842
|
+
setCancelable: (cancelable: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
843
|
+
setRetry: (retry: RequestOptionsType<Endpoint, AdapterOptions>["retry"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
844
|
+
setRetryTime: (retryTime: RequestOptionsType<Endpoint, AdapterOptions>["retryTime"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
845
|
+
setGarbageCollection: (garbageCollection: RequestOptionsType<Endpoint, AdapterOptions>["garbageCollection"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
846
|
+
setCache: (cache: RequestOptionsType<Endpoint, AdapterOptions>["cache"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
847
|
+
setCacheTime: (cacheTime: RequestOptionsType<Endpoint, AdapterOptions>["cacheTime"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
848
|
+
setQueued: (queued: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
849
|
+
setAbortKey: (abortKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
850
|
+
setCacheKey: (cacheKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
851
|
+
setQueueKey: (queueKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
852
|
+
setEffectKey: (effectKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
853
|
+
setDeduplicate: (deduplicate: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
854
|
+
setDeduplicateTime: (deduplicateTime: number) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
855
|
+
setUsed: (used: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
856
|
+
setOffline: (offline: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
857
|
+
setDataMapper: <DataMapper extends (data: Payload) => any>(mapper: DataMapper) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
858
|
+
private paramsMapper;
|
|
859
|
+
dump(): RequestDump<Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>, AdapterOptions, QueryParams>;
|
|
860
|
+
clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery, NewMappedData = MappedData>(options?: RequestCurrentType<Response, Payload, QueryParams, GlobalError | LocalError, Endpoint, AdapterOptions, NewMappedData>, mapper?: PayloadMapperType<Payload, NewMappedData>): Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, D, P, Q, NewMappedData>;
|
|
861
|
+
abort: () => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>;
|
|
862
|
+
/**
|
|
863
|
+
* Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
|
|
864
|
+
* @param options
|
|
865
|
+
* @disableReturns
|
|
866
|
+
* @returns
|
|
867
|
+
* ```tsx
|
|
868
|
+
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
exec: RequestSendType<Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>>;
|
|
872
|
+
/**
|
|
873
|
+
* Method used to perform requests with usage of cache and queues
|
|
874
|
+
* @param options
|
|
875
|
+
* @param requestCallback
|
|
876
|
+
* @disableReturns
|
|
877
|
+
* @returns
|
|
878
|
+
* ```tsx
|
|
879
|
+
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
880
|
+
* ```
|
|
881
|
+
*/
|
|
882
|
+
send: RequestSendType<Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, AdapterOptions, HasData, HasParams, HasQuery, MappedData>>;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
type AdapterProgressEventType = {
|
|
886
|
+
total: number;
|
|
887
|
+
loaded: number;
|
|
888
|
+
};
|
|
889
|
+
type AdapterProgressType = {
|
|
890
|
+
progress: number;
|
|
891
|
+
timeLeft: number;
|
|
892
|
+
sizeLeft: number;
|
|
893
|
+
};
|
|
894
|
+
/**
|
|
895
|
+
* Dump of the request used to later recreate it
|
|
896
|
+
*/
|
|
897
|
+
type RequestDump<Request extends RequestInstance, AdapterOptions = unknown, QueryParams = QueryParamsType, Params = ExtractParamsType<Request>> = {
|
|
898
|
+
requestOptions: RequestOptionsType<string, AdapterOptions | ExtractAdapterOptionsType<Request>>;
|
|
899
|
+
endpoint: string;
|
|
900
|
+
method: HttpMethodsType;
|
|
901
|
+
headers?: HeadersInit;
|
|
902
|
+
auth: boolean;
|
|
903
|
+
cancelable: boolean;
|
|
904
|
+
retry: number;
|
|
905
|
+
retryTime: number;
|
|
906
|
+
garbageCollection: number;
|
|
907
|
+
cache: boolean;
|
|
908
|
+
cacheTime: number;
|
|
909
|
+
queued: boolean;
|
|
910
|
+
offline: boolean;
|
|
911
|
+
disableResponseInterceptors: boolean | undefined;
|
|
912
|
+
disableRequestInterceptors: boolean | undefined;
|
|
913
|
+
options?: AdapterOptions | ExtractAdapterOptionsType<Request>;
|
|
914
|
+
data: PayloadType<ExtractPayloadType<Request>, unknown>;
|
|
915
|
+
params: Params | NegativeTypes;
|
|
916
|
+
queryParams: QueryParams | NegativeTypes;
|
|
917
|
+
abortKey: string;
|
|
918
|
+
cacheKey: string;
|
|
919
|
+
queueKey: string;
|
|
920
|
+
effectKey: string;
|
|
921
|
+
used: boolean;
|
|
922
|
+
updatedAbortKey: boolean;
|
|
923
|
+
updatedCacheKey: boolean;
|
|
924
|
+
updatedQueueKey: boolean;
|
|
925
|
+
updatedEffectKey: boolean;
|
|
926
|
+
deduplicate: boolean;
|
|
927
|
+
deduplicateTime: number;
|
|
928
|
+
};
|
|
929
|
+
/**
|
|
930
|
+
* Configuration options for request creation
|
|
931
|
+
*/
|
|
932
|
+
type RequestOptionsType<GenericEndpoint extends string, AdapterOptions> = {
|
|
933
|
+
/**
|
|
934
|
+
* Determine the endpoint for request request
|
|
935
|
+
*/
|
|
936
|
+
endpoint: GenericEndpoint;
|
|
937
|
+
/**
|
|
938
|
+
* Custom headers for request
|
|
939
|
+
*/
|
|
940
|
+
headers?: HeadersInit;
|
|
941
|
+
/**
|
|
942
|
+
* Should the onAuth method get called on this request
|
|
943
|
+
*/
|
|
944
|
+
auth?: boolean;
|
|
945
|
+
/**
|
|
946
|
+
* Request method GET | POST | PATCH | PUT | DELETE
|
|
947
|
+
*/
|
|
948
|
+
method?: HttpMethodsType;
|
|
949
|
+
/**
|
|
950
|
+
* Should enable cancelable mode in the Dispatcher
|
|
951
|
+
*/
|
|
952
|
+
cancelable?: boolean;
|
|
953
|
+
/**
|
|
954
|
+
* Retry count when request is failed
|
|
955
|
+
*/
|
|
956
|
+
retry?: number;
|
|
957
|
+
/**
|
|
958
|
+
* Retry time delay between retries
|
|
959
|
+
*/
|
|
960
|
+
retryTime?: number;
|
|
961
|
+
/**
|
|
962
|
+
* Should we trigger garbage collection or leave data in memory
|
|
963
|
+
*/
|
|
964
|
+
garbageCollection?: number;
|
|
965
|
+
/**
|
|
966
|
+
* Should we save the response to cache
|
|
967
|
+
*/
|
|
968
|
+
cache?: boolean;
|
|
969
|
+
/**
|
|
970
|
+
* Time for which the cache is considered up-to-date
|
|
971
|
+
*/
|
|
972
|
+
cacheTime?: number;
|
|
973
|
+
/**
|
|
974
|
+
* Should the requests from this request be send one-by-one
|
|
975
|
+
*/
|
|
976
|
+
queued?: boolean;
|
|
977
|
+
/**
|
|
978
|
+
* Do we want to store request made in offline mode for latter use when we go back online
|
|
979
|
+
*/
|
|
980
|
+
offline?: boolean;
|
|
981
|
+
/**
|
|
982
|
+
* Disable post-request interceptors
|
|
983
|
+
*/
|
|
984
|
+
disableResponseInterceptors?: boolean;
|
|
985
|
+
/**
|
|
986
|
+
* Disable pre-request interceptors
|
|
987
|
+
*/
|
|
988
|
+
disableRequestInterceptors?: boolean;
|
|
989
|
+
/**
|
|
990
|
+
* Additional options for your adapter, by default XHR options
|
|
991
|
+
*/
|
|
992
|
+
options?: AdapterOptions;
|
|
993
|
+
/**
|
|
994
|
+
* Key which will be used to cancel requests. Autogenerated by default.
|
|
995
|
+
*/
|
|
996
|
+
abortKey?: string;
|
|
997
|
+
/**
|
|
998
|
+
* Key which will be used to cache requests. Autogenerated by default.
|
|
999
|
+
*/
|
|
1000
|
+
cacheKey?: string;
|
|
1001
|
+
/**
|
|
1002
|
+
* Key which will be used to queue requests. Autogenerated by default.
|
|
1003
|
+
*/
|
|
1004
|
+
queueKey?: string;
|
|
1005
|
+
/**
|
|
1006
|
+
* Key which will be used to use effects. Autogenerated by default.
|
|
1007
|
+
*/
|
|
1008
|
+
effectKey?: string;
|
|
1009
|
+
/**
|
|
1010
|
+
* Should we deduplicate two requests made at the same time into one
|
|
1011
|
+
*/
|
|
1012
|
+
deduplicate?: boolean;
|
|
1013
|
+
/**
|
|
1014
|
+
* Time of pooling for the deduplication to be active (default 10ms)
|
|
1015
|
+
*/
|
|
1016
|
+
deduplicateTime?: number;
|
|
1017
|
+
};
|
|
1018
|
+
type PayloadMapperType<PayloadType, MappedData> = (data: PayloadType) => MappedData;
|
|
1019
|
+
type PayloadType<Payload, MappedData> = (MappedData extends never ? Payload : MappedData) | NegativeTypes;
|
|
1020
|
+
type RequestCurrentType<Response, Payload, QueryParams, ErrorType, GenericEndpoint extends string, AdapterOptions, MappedData> = {
|
|
1021
|
+
used?: boolean;
|
|
1022
|
+
params?: ExtractRouteParams<GenericEndpoint> | NegativeTypes;
|
|
1023
|
+
queryParams?: QueryParams | NegativeTypes;
|
|
1024
|
+
data?: PayloadType<Payload, MappedData>;
|
|
1025
|
+
mockCallback?: ((data: Payload) => ResponseType<Response, ErrorType>) | undefined;
|
|
1026
|
+
headers?: HeadersInit;
|
|
1027
|
+
updatedAbortKey?: boolean;
|
|
1028
|
+
updatedCacheKey?: boolean;
|
|
1029
|
+
updatedQueueKey?: boolean;
|
|
1030
|
+
updatedEffectKey?: boolean;
|
|
1031
|
+
} & Partial<NullableKeys<RequestOptionsType<GenericEndpoint, AdapterOptions>>>;
|
|
1032
|
+
type ParamType = string | number;
|
|
1033
|
+
type ParamsType = Record<string, ParamType>;
|
|
1034
|
+
type ExtractRouteParams<T extends string> = string extends T ? NegativeTypes : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
1035
|
+
[k in Param | keyof ExtractRouteParams<Rest>]: ParamType;
|
|
1036
|
+
} : T extends `${string}:${infer Param}` ? {
|
|
1037
|
+
[k in Param]: ParamType;
|
|
1038
|
+
} : NegativeTypes;
|
|
1039
|
+
type FetchOptionsType<AdapterOptions> = Omit<Partial<RequestOptionsType<string, AdapterOptions>>, "endpoint" | "method">;
|
|
1040
|
+
/**
|
|
1041
|
+
* It will check if the query params are already set
|
|
1042
|
+
*/
|
|
1043
|
+
type FetchQueryParamsType<QueryParams extends QueryParamsType | string, HasQuery extends true | false = false> = HasQuery extends true ? {
|
|
1044
|
+
queryParams?: NegativeTypes;
|
|
1045
|
+
} : {
|
|
1046
|
+
queryParams?: QueryParams | string;
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
1049
|
+
* If the request endpoint parameters are not filled it will throw an error
|
|
1050
|
+
*/
|
|
1051
|
+
type FetchParamsType<Endpoint extends string, HasParams extends true | false> = ExtractRouteParams<Endpoint> extends NegativeTypes ? {
|
|
1052
|
+
params?: NegativeTypes;
|
|
1053
|
+
} : true extends HasParams ? {
|
|
1054
|
+
params?: NegativeTypes;
|
|
1055
|
+
} : {
|
|
1056
|
+
params: NonNullable<ExtractRouteParams<Endpoint>>;
|
|
1057
|
+
};
|
|
1058
|
+
/**
|
|
1059
|
+
* If the request data is not filled it will throw an error
|
|
1060
|
+
*/
|
|
1061
|
+
type FetchPayloadType<Payload, HasData extends true | false> = Payload extends NegativeTypes ? {
|
|
1062
|
+
data?: NegativeTypes;
|
|
1063
|
+
} : HasData extends true ? {
|
|
1064
|
+
data?: NegativeTypes;
|
|
1065
|
+
} : {
|
|
1066
|
+
data: NonNullable<Payload>;
|
|
1067
|
+
};
|
|
1068
|
+
type RequestQueueOptions = {
|
|
1069
|
+
dispatcherType?: "auto" | "fetch" | "submit";
|
|
1070
|
+
};
|
|
1071
|
+
type RequestSendOptionsType<Request extends RequestInstance> = FetchQueryParamsType<ExtractQueryParamsType<Request>, ExtractHasQueryParamsType<Request>> & FetchParamsType<ExtractEndpointType<Request>, ExtractHasParamsType<Request>> & FetchPayloadType<ExtractPayloadType<Request>, ExtractHasDataType<Request>> & Omit<FetchOptionsType<ExtractAdapterOptionsType<Request>>, "params" | "data"> & FetchSendActionsType<Request> & RequestQueueOptions;
|
|
1072
|
+
type FetchSendActionsType<Request extends RequestInstance> = {
|
|
1073
|
+
onSettle?: (requestId: string, request: Request) => void;
|
|
1074
|
+
onRequestStart?: (details: RequestEventType<Request>) => void;
|
|
1075
|
+
onResponseStart?: (details: RequestEventType<Request>) => void;
|
|
1076
|
+
onUploadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
|
|
1077
|
+
onDownloadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
|
|
1078
|
+
onResponse?: (response: ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>, details: ResponseDetailsType) => void;
|
|
1079
|
+
onRemove?: (details: RequestEventType<Request>) => void;
|
|
1080
|
+
};
|
|
1081
|
+
type RequestSendType<Request extends RequestInstance> = RequestSendOptionsType<Request>["data"] extends NegativeTypes ? RequestSendOptionsType<Request>["params"] extends NegativeTypes ? (options?: RequestSendOptionsType<Request>) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>> : (options: RequestSendOptionsType<Request>) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>> : (options: RequestSendOptionsType<Request>) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>>;
|
|
1082
|
+
type RequestInstance = Request<any, any, any, any, any, any, any, any, any, any, any>;
|
|
1083
|
+
|
|
1084
|
+
declare const stringifyKey: (value: unknown) => string;
|
|
1085
|
+
declare const getProgressValue: ({ loaded, total }: AdapterProgressEventType) => number;
|
|
1086
|
+
declare const getRequestEta: (startDate: Date, progressDate: Date, { total, loaded }: AdapterProgressEventType) => {
|
|
1087
|
+
sizeLeft: number;
|
|
1088
|
+
timeLeft: number | null;
|
|
1089
|
+
};
|
|
1090
|
+
declare const getProgressData: (requestStartTime: Date, progressDate: Date, progressEvent: AdapterProgressEventType) => ProgressType;
|
|
1091
|
+
declare const getSimpleKey: (request: RequestInstance | RequestDump<RequestInstance>) => string;
|
|
1092
|
+
/**
|
|
1093
|
+
* Cache instance for individual request that collects individual requests responses from
|
|
1094
|
+
* the same endpoint (they may differ base on the custom key, endpoint params etc)
|
|
1095
|
+
* @param request
|
|
1096
|
+
* @param useInitialValues
|
|
1097
|
+
* @returns
|
|
1098
|
+
*/
|
|
1099
|
+
declare const getRequestKey: (request: RequestInstance | RequestDump<RequestInstance>, useInitialValues?: boolean) => string;
|
|
1100
|
+
declare const getRequestDispatcher: <Request_1 extends RequestInstance>(request: Request_1, dispatcherType?: "auto" | "fetch" | "submit") => [Dispatcher, boolean];
|
|
1101
|
+
declare const requestSendRequest: <Request_1 extends RequestInstance>(request: Request_1, options?: RequestSendOptionsType<Request_1>) => Promise<ResponseType<ExtractResponseType<Request_1>, ExtractErrorType<Request_1>>>;
|
|
1102
|
+
|
|
1103
|
+
type AdapterType = (request: RequestInstance, requestId: string) => Promise<ResponseType<any, any>>;
|
|
1104
|
+
type AdapterOptionsType = Partial<XMLHttpRequest>;
|
|
1105
|
+
type AdapterPayloadMappingType = (data: unknown) => string | FormData;
|
|
1106
|
+
type ResponseType<GenericDataType, GenericErrorType> = [
|
|
1107
|
+
GenericDataType | null,
|
|
1108
|
+
GenericErrorType | null,
|
|
1109
|
+
number | null
|
|
1110
|
+
];
|
|
1111
|
+
type ResponseSuccessType<GenericDataType> = [GenericDataType, null, number | null];
|
|
1112
|
+
type ResponseErrorType<GenericErrorType> = [null, GenericErrorType, number | null];
|
|
1113
|
+
type QueryParamValuesType = number | string | boolean | null | undefined;
|
|
1114
|
+
type QueryParamType = QueryParamValuesType | Array<QueryParamValuesType> | Record<string, QueryParamValuesType>;
|
|
1115
|
+
type QueryParamsType = Record<string, QueryParamType>;
|
|
1116
|
+
type HeaderMappingType = <T extends RequestInstance>(request: T) => HeadersInit;
|
|
1117
|
+
type AdapterHeadersProps = {
|
|
1118
|
+
isFormData: boolean;
|
|
1119
|
+
headers: HeadersInit | undefined;
|
|
1120
|
+
};
|
|
1121
|
+
type QueryStringifyOptionsType = {
|
|
1122
|
+
/**
|
|
1123
|
+
* Strict URI encoding
|
|
1124
|
+
*/
|
|
1125
|
+
strict?: boolean;
|
|
1126
|
+
/**
|
|
1127
|
+
* Encode keys and values
|
|
1128
|
+
*/
|
|
1129
|
+
encode?: boolean;
|
|
1130
|
+
/**
|
|
1131
|
+
* Array encoding type
|
|
1132
|
+
*/
|
|
1133
|
+
arrayFormat?: "bracket" | "index" | "comma" | "separator" | "bracket-separator" | "none";
|
|
1134
|
+
/**
|
|
1135
|
+
* Array format separator
|
|
1136
|
+
*/
|
|
1137
|
+
arraySeparator?: string;
|
|
1138
|
+
/**
|
|
1139
|
+
* Skip keys with null values
|
|
1140
|
+
*/
|
|
1141
|
+
skipNull?: boolean;
|
|
1142
|
+
/**
|
|
1143
|
+
* Skip keys with empty string
|
|
1144
|
+
*/
|
|
1145
|
+
skipEmptyString?: boolean;
|
|
1146
|
+
};
|
|
1147
|
+
type ProgressDataType = {
|
|
1148
|
+
total?: number;
|
|
1149
|
+
loaded?: number;
|
|
1150
|
+
};
|
|
1151
|
+
type ProgressType = {
|
|
1152
|
+
progress: number;
|
|
1153
|
+
timeLeft: number | null;
|
|
1154
|
+
sizeLeft: number;
|
|
1155
|
+
total: number;
|
|
1156
|
+
loaded: number;
|
|
1157
|
+
startTimestamp: number;
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
declare const getErrorMessage: (errorCase?: "timeout" | "abort" | "deleted") => Error;
|
|
1161
|
+
declare const parseResponse: (response: string | unknown) => any;
|
|
1162
|
+
declare const parseErrorResponse: <T extends RequestInstance>(response: unknown) => ExtractErrorType<T>;
|
|
1163
|
+
declare const getUploadSize: (payload: FormData | string) => number;
|
|
1164
|
+
declare const fileToBuffer: (file: File | Blob) => Promise<Uint8Array>;
|
|
1165
|
+
declare const getStreamPayload: (payload: FormData | string | null) => string | Promise<(string | Uint8Array)[]>;
|
|
1166
|
+
|
|
1167
|
+
declare const serverAdapter: AdapterType;
|
|
1168
|
+
|
|
1169
|
+
declare const browserAdapter: AdapterType;
|
|
1170
|
+
|
|
1171
|
+
declare const getAdapterBindings: <ConfigType = any>(cmd: RequestInstance, requestId: string) => Promise<{
|
|
1172
|
+
fullUrl: string;
|
|
1173
|
+
headers: HeadersInit;
|
|
1174
|
+
payload: string | FormData;
|
|
1175
|
+
config: ConfigType;
|
|
1176
|
+
getAbortController: () => AbortController;
|
|
1177
|
+
getRequestStartTimestamp: () => number;
|
|
1178
|
+
getResponseStartTimestamp: () => number;
|
|
1179
|
+
createAbortListener: <T extends RequestInstance>(callback: () => void, resolve: (value: ResponseErrorType<ExtractErrorType<T>>) => void) => () => void;
|
|
1180
|
+
onBeforeRequest: () => void;
|
|
1181
|
+
onRequestStart: (progress?: ProgressDataType) => number;
|
|
1182
|
+
onRequestProgress: (progress: ProgressDataType) => number;
|
|
1183
|
+
onRequestEnd: () => number;
|
|
1184
|
+
onResponseStart: (progress?: ProgressDataType) => number;
|
|
1185
|
+
onResponseProgress: (progress: ProgressDataType) => number;
|
|
1186
|
+
onResponseEnd: () => number;
|
|
1187
|
+
onSuccess: <T_1 extends RequestInstance>(responseData: unknown, status: number, resolve: (value: ResponseErrorType<ExtractErrorType<T_1>>) => void) => Promise<ResponseSuccessType<ExtractResponseType<T_1>>>;
|
|
1188
|
+
onAbortError: <T_2 extends RequestInstance>(resolve: (value: ResponseErrorType<ExtractErrorType<T_2>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_2>>>;
|
|
1189
|
+
onTimeoutError: <T_3 extends RequestInstance>(resolve: (value: ResponseErrorType<ExtractErrorType<T_3>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_3>>>;
|
|
1190
|
+
onUnexpectedError: <T_4 extends RequestInstance>(resolve: (value: ResponseErrorType<ExtractErrorType<T_4>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_4>>>;
|
|
1191
|
+
onError: <T_5 extends RequestInstance>(error: Error | ExtractErrorType<T_5>, status: number, resolve: (value: ResponseErrorType<ExtractErrorType<T_5>>) => void) => Promise<ResponseErrorType<ExtractErrorType<T_5>>>;
|
|
1192
|
+
}>;
|
|
1193
|
+
|
|
1194
|
+
declare const defaultTimeout: number;
|
|
1195
|
+
|
|
1196
|
+
type ExtractAdapterReturnType<T extends RequestInstance> = ResponseType<ExtractResponseType<T>, ExtractErrorType<T>>;
|
|
1197
|
+
type ExtractResponseType<T> = T extends Request<infer D, any, any, any, any, any, any, any, any, any, any> ? D : never;
|
|
1198
|
+
type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any, any, any> ? D : never;
|
|
1199
|
+
type ExtractQueryParamsType<T> = T extends Request<any, any, infer Q, any, any, any, any, any, any, any, any> ? Q : never;
|
|
1200
|
+
type ExtractErrorType<T> = T extends Request<any, any, any, infer G, infer L, any, any, any, any, any, any> ? G | L : never;
|
|
1201
|
+
type ExtractGlobalErrorType<T> = T extends Request<any, any, any, infer E, any, any, any, any, any, any, any> ? E : never;
|
|
1202
|
+
type ExtractLocalErrorType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any, any, any> ? E : never;
|
|
1203
|
+
type ExtractParamsType<T> = T extends Request<any, any, any, any, any, infer P, any, any, any, any, any> ? ExtractRouteParams<P> : never;
|
|
1204
|
+
type ExtractEndpointType<T> = T extends Request<any, any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
1205
|
+
type ExtractAdapterOptionsType<T> = T extends Request<any, any, any, any, any, any, infer O, any, any, any, any> ? O : never;
|
|
1206
|
+
type ExtractHasDataType<T> = T extends Request<any, any, any, any, any, any, any, infer D, any, any, any> ? D : never;
|
|
1207
|
+
type ExtractHasParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, infer P, any, any> ? P : never;
|
|
1208
|
+
type ExtractHasQueryParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, any, infer Q, any> ? Q : never;
|
|
1209
|
+
type ExtractHasMappedDataType<T> = T extends Request<any, any, any, any, any, any, any, any, any, any, infer M> ? M : never;
|
|
1210
|
+
|
|
1211
|
+
declare class RequestEffect<T extends RequestInstance> {
|
|
1212
|
+
config: RequestEffectOptionsType<T>;
|
|
1213
|
+
constructor(config: RequestEffectOptionsType<T>);
|
|
1214
|
+
getEffectKey: () => string;
|
|
1215
|
+
onTrigger: (request: T) => void;
|
|
1216
|
+
onStart: (request: T) => void;
|
|
1217
|
+
onSuccess: (response: ResponseSuccessType<ExtractResponseType<T>>, request: T) => void;
|
|
1218
|
+
onError: (response: ResponseErrorType<ExtractErrorType<T>>, request: T) => void;
|
|
1219
|
+
onFinished: (response: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>>, request: T) => void;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
type RequestEffectLifecycle = "trigger" | "start" | "success" | "error" | "finished";
|
|
1223
|
+
type RequestEffectInstance = RequestEffect<RequestInstance>;
|
|
1224
|
+
type RequestEffectOptionsType<T extends RequestInstance> = {
|
|
1225
|
+
/**
|
|
1226
|
+
* It should match effectKey on the request for which given effect should be triggered.
|
|
1227
|
+
*/
|
|
1228
|
+
effectKey: string;
|
|
1229
|
+
/**
|
|
1230
|
+
* Callback that will be executed when request gets triggered
|
|
1231
|
+
*/
|
|
1232
|
+
onTrigger?: (request: RequestInstance) => void;
|
|
1233
|
+
/**
|
|
1234
|
+
* Callback that will be executed when request starts
|
|
1235
|
+
*/
|
|
1236
|
+
onStart?: (request: RequestInstance) => void;
|
|
1237
|
+
/**
|
|
1238
|
+
* Callback that will be executed when response is successful
|
|
1239
|
+
*/
|
|
1240
|
+
onSuccess?: (response: ResponseSuccessType<ExtractResponseType<T>>, request: RequestInstance) => void;
|
|
1241
|
+
/**
|
|
1242
|
+
* Callback that will be executed when response is failed
|
|
1243
|
+
*/
|
|
1244
|
+
onError?: (response: ResponseErrorType<ExtractErrorType<T>>, request: RequestInstance) => void;
|
|
1245
|
+
/**
|
|
1246
|
+
* Callback that will be executed when response is finished
|
|
1247
|
+
*/
|
|
1248
|
+
onFinished?: (response: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>>, request: RequestInstance) => void;
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
declare enum DateInterval {
|
|
1252
|
+
second = 1000,
|
|
1253
|
+
minute = 60000,
|
|
1254
|
+
hour = 3600000,
|
|
1255
|
+
day = 86400000,
|
|
1256
|
+
week = 604800000,
|
|
1257
|
+
month30 = 2592000000,
|
|
1258
|
+
month31 = 2678400000,
|
|
1259
|
+
year = 31536000000,
|
|
1260
|
+
yearLeap = 31622400000
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
declare enum HttpMethodsEnum {
|
|
1264
|
+
get = "GET",
|
|
1265
|
+
post = "POST",
|
|
1266
|
+
put = "PUT",
|
|
1267
|
+
patch = "PATCH",
|
|
1268
|
+
delete = "DELETE"
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
declare const getUniqueRequestId: (key: string) => string;
|
|
1272
|
+
|
|
1273
|
+
export { AdapterHeadersProps, AdapterOptionsType, AdapterPayloadMappingType, AdapterProgressEventType, AdapterProgressType, AdapterType, AppEvents, AppManager, AppManagerOptionsType, Cache, CacheAsyncStorageType, CacheInitialData, CacheOptionsType, CacheStorageType, CacheValueType, Client, ClientErrorType, ClientInstance, ClientOptionsType, DateInterval, Dispatcher, DispatcherOptionsType, DispatcherRequestType, DispatcherStorageType, DispatcherStorageValueType, ExtractAdapterOptionsType, ExtractAdapterReturnType, ExtractEndpointType, ExtractErrorType, ExtractGlobalErrorType, ExtractHasDataType, ExtractHasMappedDataType, ExtractHasParamsType, ExtractHasQueryParamsType, ExtractLocalErrorType, ExtractParamsType, ExtractPayloadType, ExtractQueryParamsType, ExtractResponseType, ExtractRouteParams, FetchOptionsType, FetchParamsType, FetchPayloadType, FetchQueryParamsType, FetchSendActionsType, HeaderMappingType, HttpMethodsEnum, HttpMethodsType, LogType, LoggerFunctionType, LoggerLevelType, LoggerManager, LoggerMessageType, LoggerOptionsType, LoggerRequestEventData, LoggerResponseEventData, LoggerType, NegativeTypes, NonNullableKeys, NullableKeys, NullableType, ParamType, ParamsType, PayloadMapperType, PayloadType, ProgressDataType, ProgressType, QueryParamType, QueryParamValuesType, QueryParamsType, QueryStringifyOptionsType, QueueDataType, Request, RequestCurrentType, RequestDump, RequestEffect, RequestEffectInstance, RequestEffectLifecycle, RequestEffectOptionsType, RequestEventType, RequestInstance, RequestInterceptorType, RequestLoadingEventType, RequestManager, RequestOptionsType, RequestQueueOptions, RequestRemoveDataType, RequestSendOptionsType, RequestSendType, RequiredKeys, ResponseDetailsType, ResponseErrorType, ResponseInterceptorType, ResponseSuccessType, ResponseType, RunningRequestValueType, SeverityType, StringifyCallbackType, adapter, appManagerInitialOptions, browserAdapter, canRetryRequest, defaultTimeout, fileToBuffer, getAbortByIdEventKey, getAbortEventKey, getAdapterBindings, getAdapterHeaders, getAdapterPayload, getAppManagerEvents, getCacheData, getCacheEvents, getCacheIdKey, getCacheKey, getDispatcherChangeEventKey, getDispatcherDrainedEventKey, getDispatcherEvents, getDispatcherStatusEventKey, getDownloadProgressEventKey, getDownloadProgressIdEventKey, getErrorMessage, getIsEqualTimestamp, getLoadingEventKey, getLoadingIdEventKey, getProgressData, getProgressValue, getRemoveEventKey, getRemoveIdEventKey, getRequestDispatcher, getRequestEta, getRequestKey, getRequestManagerEvents, getRequestStartEventKey, getRequestStartIdEventKey, getRequestType, getResponseEventKey, getResponseIdEventKey, getResponseStartEventKey, getResponseStartIdEventKey, getRevalidateEventKey, getSimpleKey, getStreamPayload, getTime, getUniqueRequestId, getUploadProgressEventKey, getUploadProgressIdEventKey, getUploadSize, hasDocument, hasWindow, interceptRequest, interceptResponse, isFailedRequest, logger, loggerIconLevels, loggerStyles, onDocumentEvent, onWindowEvent, parseErrorResponse, parseResponse, requestSendRequest, serverAdapter, severity, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue };
|