@hyper-fetch/core 3.3.4 → 4.0.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.
- package/dist/browser/index.cjs.js +1 -1
- package/dist/browser/index.cjs.js.map +4 -4
- package/dist/browser/index.esm.js +1 -1
- package/dist/browser/index.esm.js.map +4 -4
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.d.ts +330 -180
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +4 -4
- package/package.json +4 -2
- package/src/adapter/adapter.bindings.ts +124 -35
- package/src/adapter/adapter.browser.ts +29 -25
- package/src/adapter/adapter.server.ts +81 -81
- package/src/adapter/adapter.ts +1 -6
- package/src/adapter/adapter.types.ts +100 -12
- package/src/adapter/adapter.utils.ts +16 -23
- package/src/cache/cache.events.ts +9 -6
- package/src/cache/cache.ts +37 -30
- package/src/cache/cache.types.ts +32 -15
- package/src/cache/cache.utils.ts +7 -9
- package/src/client/client.constants.ts +6 -0
- package/src/client/client.ts +130 -59
- package/src/client/client.types.ts +11 -10
- package/src/client/client.utils.ts +20 -6
- package/src/dispatcher/dispatcher.ts +20 -26
- package/src/dispatcher/dispatcher.types.ts +4 -4
- package/src/dispatcher/dispatcher.utils.ts +2 -11
- package/src/effect/request.effect.ts +8 -5
- package/src/effect/request.effect.types.ts +14 -5
- package/src/index.ts +1 -0
- package/src/managers/logger/logger.manager.ts +8 -8
- package/src/managers/logger/logger.manager.types.ts +5 -8
- package/src/managers/logger/logger.manager.utils.ts +2 -2
- package/src/managers/request/request.manager.events.ts +7 -7
- package/src/managers/request/request.manager.types.ts +0 -1
- package/src/mocker/index.ts +2 -0
- package/src/mocker/mocker.ts +96 -0
- package/src/mocker/mocker.types.ts +26 -0
- package/src/request/request.ts +227 -224
- package/src/request/request.types.ts +75 -35
- package/src/request/request.utils.ts +61 -28
- package/src/types/client.types.ts +4 -0
- package/src/types/fetch.types.ts +16 -25
- package/src/types/http.types.ts +1 -0
- package/src/types/index.ts +1 -0
- package/{tsconfig.node.json → tsconfig.base.json} +3 -3
- package/tsconfig.json +3 -4
- package/dist/server/index.cjs.js +0 -2
- package/dist/server/index.cjs.js.map +0 -7
- package/dist/server/index.esm.js +0 -2
- package/dist/server/index.esm.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type RequiredKeys<T> = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
type HttpMethodsType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
16
|
+
type HttpStatusType = number;
|
|
16
17
|
|
|
17
18
|
declare const adapter: AdapterType;
|
|
18
19
|
|
|
@@ -91,7 +92,7 @@ declare class RequestManager {
|
|
|
91
92
|
emitResponseStart: (queueKey: string, requestId: string, details: RequestEventType<RequestInstance>) => void;
|
|
92
93
|
emitUploadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
93
94
|
emitDownloadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
94
|
-
emitResponse: (cacheKey: string, requestId: string, response:
|
|
95
|
+
emitResponse: <Adapter extends AdapterInstance>(cacheKey: string, requestId: string, response: ResponseReturnType<unknown, unknown, Adapter>, details: ResponseDetailsType) => void;
|
|
95
96
|
emitAbort: (abortKey: string, requestId: string, request: RequestInstance) => void;
|
|
96
97
|
emitRemove: <T extends RequestInstance>(queueKey: string, requestId: string, details: RequestEventType<T>) => void;
|
|
97
98
|
onLoading: (queueKey: string, callback: (values: RequestLoadingEventType) => void) => VoidFunction;
|
|
@@ -104,8 +105,8 @@ declare class RequestManager {
|
|
|
104
105
|
onUploadProgressById: <T_6 extends RequestInstance = RequestInstance>(requestId: string, callback: (values: ProgressType, details: RequestEventType<T_6>) => void) => VoidFunction;
|
|
105
106
|
onDownloadProgress: <T_7 extends RequestInstance = RequestInstance>(queueKey: string, callback: (values: ProgressType, details: RequestEventType<T_7>) => void) => VoidFunction;
|
|
106
107
|
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:
|
|
108
|
-
onResponseById: <Response_2, ErrorType_1>(requestId: string, callback: (response:
|
|
108
|
+
onResponse: <Response_1, ErrorType, Adapter_1 extends AdapterInstance>(cacheKey: string, callback: (response: ResponseReturnType<Response_1, ErrorType, Adapter_1>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
109
|
+
onResponseById: <Response_2, ErrorType_1, Adapter_2 extends AdapterInstance>(requestId: string, callback: (response: ResponseReturnType<Response_2, ErrorType_1, Adapter_2>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
109
110
|
onAbort: (abortKey: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
110
111
|
onAbortById: (requestId: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
111
112
|
onRemove: <T_9 extends RequestInstance = RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_9>) => void) => VoidFunction;
|
|
@@ -147,7 +148,7 @@ declare const getRequestManagerEvents: (emitter: EventEmitter) => {
|
|
|
147
148
|
emitResponseStart: (queueKey: string, requestId: string, details: RequestEventType<RequestInstance>) => void;
|
|
148
149
|
emitUploadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
149
150
|
emitDownloadProgress: (queueKey: string, requestId: string, values: ProgressType, details: RequestEventType<RequestInstance>) => void;
|
|
150
|
-
emitResponse: (cacheKey: string, requestId: string, response:
|
|
151
|
+
emitResponse: <Adapter extends AdapterInstance>(cacheKey: string, requestId: string, response: ResponseReturnType<unknown, unknown, Adapter>, details: ResponseDetailsType) => void;
|
|
151
152
|
emitAbort: (abortKey: string, requestId: string, request: RequestInstance) => void;
|
|
152
153
|
emitRemove: <T extends RequestInstance>(queueKey: string, requestId: string, details: RequestEventType<T>) => void;
|
|
153
154
|
/**
|
|
@@ -163,8 +164,8 @@ declare const getRequestManagerEvents: (emitter: EventEmitter) => {
|
|
|
163
164
|
onUploadProgressById: <T_6 extends RequestInstance = RequestInstance>(requestId: string, callback: (values: ProgressType, details: RequestEventType<T_6>) => void) => VoidFunction;
|
|
164
165
|
onDownloadProgress: <T_7 extends RequestInstance = RequestInstance>(queueKey: string, callback: (values: ProgressType, details: RequestEventType<T_7>) => void) => VoidFunction;
|
|
165
166
|
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:
|
|
167
|
-
onResponseById: <Response_2, ErrorType_1>(requestId: string, callback: (response:
|
|
167
|
+
onResponse: <Response_1, ErrorType, Adapter_1 extends AdapterInstance>(cacheKey: string, callback: (response: ResponseReturnType<Response_1, ErrorType, Adapter_1>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
168
|
+
onResponseById: <Response_2, ErrorType_1, Adapter_2 extends AdapterInstance>(requestId: string, callback: (response: ResponseReturnType<Response_2, ErrorType_1, Adapter_2>, details: ResponseDetailsType) => void) => VoidFunction;
|
|
168
169
|
onAbort: (abortKey: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
169
170
|
onAbortById: (requestId: string, callback: (request: RequestInstance) => void) => VoidFunction;
|
|
170
171
|
onRemove: <T_9 extends RequestInstance = RequestInstance>(queueKey: string, callback: (details: RequestEventType<T_9>) => void) => VoidFunction;
|
|
@@ -185,7 +186,6 @@ type RequestEventType<T extends RequestInstance> = {
|
|
|
185
186
|
type ResponseDetailsType = {
|
|
186
187
|
retries: number;
|
|
187
188
|
timestamp: number;
|
|
188
|
-
isFailed: boolean;
|
|
189
189
|
isCanceled: boolean;
|
|
190
190
|
isOffline: boolean;
|
|
191
191
|
};
|
|
@@ -214,7 +214,7 @@ declare const getTime: () => string;
|
|
|
214
214
|
declare const logger: LoggerFunctionType;
|
|
215
215
|
|
|
216
216
|
type SeverityType = 0 | 1 | 2 | 3;
|
|
217
|
-
type LoggerType = Record<LoggerLevelType, (message: LoggerMessageType, ...
|
|
217
|
+
type LoggerType = Record<LoggerLevelType, (message: LoggerMessageType, ...extra: LoggerMessageType[]) => void>;
|
|
218
218
|
type LoggerFunctionType = (log: LogType) => void;
|
|
219
219
|
type LoggerOptionsType = {
|
|
220
220
|
logger?: LoggerFunctionType;
|
|
@@ -224,7 +224,7 @@ type LogType = {
|
|
|
224
224
|
module: string;
|
|
225
225
|
level: LoggerLevelType;
|
|
226
226
|
message: LoggerMessageType;
|
|
227
|
-
|
|
227
|
+
extra?: LoggerMessageType[];
|
|
228
228
|
enabled: boolean;
|
|
229
229
|
severity: SeverityType;
|
|
230
230
|
};
|
|
@@ -234,10 +234,10 @@ type LoggerRequestEventData = {
|
|
|
234
234
|
requestId: string;
|
|
235
235
|
request: RequestInstance;
|
|
236
236
|
};
|
|
237
|
-
type LoggerResponseEventData = {
|
|
237
|
+
type LoggerResponseEventData<Adapter extends AdapterInstance> = {
|
|
238
238
|
requestId: string;
|
|
239
239
|
request: RequestInstance;
|
|
240
|
-
response:
|
|
240
|
+
response: ResponseReturnType<unknown, unknown, Adapter>;
|
|
241
241
|
details: ResponseDetailsType;
|
|
242
242
|
};
|
|
243
243
|
|
|
@@ -252,8 +252,8 @@ declare const severity: Record<LoggerLevelType, number>;
|
|
|
252
252
|
* Keys used to save the values are created dynamically on the Request class
|
|
253
253
|
*
|
|
254
254
|
*/
|
|
255
|
-
declare class Cache {
|
|
256
|
-
client:
|
|
255
|
+
declare class Cache<C extends ClientInstance> {
|
|
256
|
+
client: C;
|
|
257
257
|
options?: CacheOptionsType;
|
|
258
258
|
emitter: EventEmitter;
|
|
259
259
|
events: ReturnType<typeof getCacheEvents>;
|
|
@@ -262,7 +262,7 @@ declare class Cache {
|
|
|
262
262
|
clearKey: string;
|
|
263
263
|
garbageCollectors: Map<string, NodeJS.Timeout>;
|
|
264
264
|
private logger;
|
|
265
|
-
constructor(client:
|
|
265
|
+
constructor(client: C, options?: CacheOptionsType);
|
|
266
266
|
/**
|
|
267
267
|
* Set the cache data to the storage
|
|
268
268
|
* @param request
|
|
@@ -270,13 +270,13 @@ declare class Cache {
|
|
|
270
270
|
* @param details
|
|
271
271
|
* @returns
|
|
272
272
|
*/
|
|
273
|
-
set: <Response_1, Error_1>(request: RequestInstance |
|
|
273
|
+
set: <Response_1, Error_1>(request: RequestInstance | RequestJSON<RequestInstance>, response: ResponseReturnType<Response_1, Error_1, ExtractAdapterTypeFromClient<C>> & ResponseDetailsType) => void;
|
|
274
274
|
/**
|
|
275
275
|
* Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.
|
|
276
276
|
* @param cacheKey
|
|
277
277
|
* @returns
|
|
278
278
|
*/
|
|
279
|
-
get: <Response_1, Error_1>(cacheKey: string) => CacheValueType<Response_1, Error_1>;
|
|
279
|
+
get: <Response_1, Error_1, Adapter extends AdapterInstance>(cacheKey: string) => CacheValueType<Response_1, Error_1, Adapter>;
|
|
280
280
|
/**
|
|
281
281
|
* Get sync storage keys, lazyStorage keys will not be included
|
|
282
282
|
* @returns
|
|
@@ -296,7 +296,7 @@ declare class Cache {
|
|
|
296
296
|
* Used to receive data from lazy storage
|
|
297
297
|
* @param cacheKey
|
|
298
298
|
*/
|
|
299
|
-
getLazyResource: <Response_1, Error_1>(cacheKey: string) => Promise<CacheValueType<Response_1, Error_1>>;
|
|
299
|
+
getLazyResource: <Response_1, Error_1, Adapter extends AdapterInstance>(cacheKey: string) => Promise<CacheValueType<Response_1, Error_1, Adapter>>;
|
|
300
300
|
/**
|
|
301
301
|
* Used to receive keys from sync storage and lazy storage
|
|
302
302
|
* @param cacheKey
|
|
@@ -314,7 +314,7 @@ declare class Cache {
|
|
|
314
314
|
clear: () => Promise<void>;
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
type CacheOptionsType = {
|
|
317
|
+
type CacheOptionsType<C extends ClientInstance = ClientInstance> = {
|
|
318
318
|
/**
|
|
319
319
|
* Assign your custom sync storage
|
|
320
320
|
*/
|
|
@@ -330,39 +330,37 @@ type CacheOptionsType = {
|
|
|
330
330
|
/**
|
|
331
331
|
* Initialization callback
|
|
332
332
|
*/
|
|
333
|
-
onInitialization?: (cache: Cache) => void;
|
|
333
|
+
onInitialization?: (cache: Cache<C>) => void;
|
|
334
334
|
/**
|
|
335
335
|
* Callback for every change in the storage
|
|
336
336
|
*/
|
|
337
|
-
onChange?: <Response = any, Error = any>(key: string, data: CacheValueType<Response, Error>) => void;
|
|
337
|
+
onChange?: <Response = any, Error = any, Adapter extends AdapterInstance = AdapterInstance>(key: string, data: CacheValueType<Response, Error, Adapter>) => void;
|
|
338
338
|
/**
|
|
339
339
|
* Callback for every delete in the storage
|
|
340
340
|
*/
|
|
341
341
|
onDelete?: (key: string) => void;
|
|
342
342
|
};
|
|
343
|
-
type CacheValueType<Response = any, Error = any> = {
|
|
344
|
-
data: ResponseType<Response, Error>;
|
|
345
|
-
details: ResponseDetailsType;
|
|
343
|
+
type CacheValueType<Response = any, Error = any, Adapter extends AdapterInstance = AdapterInstance> = ResponseReturnType<Response, Error, Adapter> & ResponseDetailsType & {
|
|
346
344
|
cacheTime: number;
|
|
347
345
|
clearKey: string;
|
|
348
346
|
garbageCollection: number;
|
|
349
347
|
};
|
|
350
348
|
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>;
|
|
349
|
+
set: <Response, Error, Adapter extends AdapterInstance>(key: string, data: CacheValueType<Response, Error, Adapter>) => Promise<void>;
|
|
350
|
+
get: <Response, Error, Adapter extends AdapterInstance>(key: string) => Promise<CacheValueType<Response, Error, Adapter> | undefined>;
|
|
353
351
|
keys: () => Promise<string[] | IterableIterator<string> | string[]>;
|
|
354
352
|
delete: (key: string) => Promise<void>;
|
|
355
353
|
};
|
|
356
354
|
type CacheStorageType = {
|
|
357
|
-
set: <Response, Error>(key: string, data: CacheValueType<Response, Error>) => void;
|
|
358
|
-
get: <Response, Error>(key: string) => CacheValueType<Response, Error> | undefined;
|
|
355
|
+
set: <Response, Error, Adapter extends AdapterInstance>(key: string, data: CacheValueType<Response, Error, Adapter>) => void;
|
|
356
|
+
get: <Response, Error, Adapter extends AdapterInstance>(key: string) => CacheValueType<Response, Error, Adapter> | undefined;
|
|
359
357
|
keys: () => string[] | IterableIterator<string> | string[];
|
|
360
358
|
delete: (key: string) => void;
|
|
361
359
|
clear: () => void;
|
|
362
360
|
};
|
|
363
361
|
type CacheInitialData = Record<string, CacheValueType>;
|
|
364
362
|
|
|
365
|
-
declare const getCacheData: <T extends RequestInstance>(previousResponse: ExtractAdapterReturnType<T>, response: ExtractAdapterReturnType<T>) => ExtractAdapterReturnType<T
|
|
363
|
+
declare const getCacheData: <T extends RequestInstance>(previousResponse: ExtractAdapterReturnType<T>, response: ExtractAdapterReturnType<T> & ResponseDetailsType) => ExtractAdapterReturnType<T> & ResponseDetailsType;
|
|
366
364
|
declare const getRevalidateEventKey: (key: string) => string;
|
|
367
365
|
declare const getCacheKey: (key: string) => string;
|
|
368
366
|
declare const getCacheIdKey: (key: string) => string;
|
|
@@ -373,18 +371,18 @@ declare const getCacheEvents: (emitter: EventEmitter) => {
|
|
|
373
371
|
* @param cacheKey
|
|
374
372
|
* @param data
|
|
375
373
|
*/
|
|
376
|
-
emitCacheData: <Response_1, Error_1>(cacheKey: string, data: CacheValueType<Response_1, Error_1>) => void;
|
|
374
|
+
emitCacheData: <Response_1, Error_1, Adapter extends AdapterInstance>(cacheKey: string, data: CacheValueType<Response_1, Error_1, Adapter>) => void;
|
|
377
375
|
/**
|
|
378
376
|
* Revalidate cache values event
|
|
379
377
|
*/
|
|
380
378
|
emitRevalidation: (cacheKey: string) => void;
|
|
381
|
-
/**
|
|
379
|
+
/** StatusType
|
|
382
380
|
* Cache data listener
|
|
383
381
|
* @param cacheKey
|
|
384
382
|
* @param callback
|
|
385
383
|
* @returns
|
|
386
384
|
*/
|
|
387
|
-
onData: <Response_2, Error_2>(cacheKey: string, callback: (data: CacheValueType<Response_2, Error_2>) => void) => VoidFunction;
|
|
385
|
+
onData: <Response_2, Error_2, Adapter_1 extends AdapterInstance>(cacheKey: string, callback: (data: CacheValueType<Response_2, Error_2, Adapter_1>) => void) => VoidFunction;
|
|
388
386
|
/**
|
|
389
387
|
* Cache invalidation listener
|
|
390
388
|
* @param cacheKey
|
|
@@ -454,7 +452,7 @@ declare class Dispatcher {
|
|
|
454
452
|
/**
|
|
455
453
|
* Return request from queue state
|
|
456
454
|
*/
|
|
457
|
-
getRequest: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, requestId: string) =>
|
|
455
|
+
getRequest: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, requestId: string) => QueueElementType<Request_1>;
|
|
458
456
|
/**
|
|
459
457
|
* Get value of the active queue status based on the stopped status
|
|
460
458
|
*/
|
|
@@ -462,7 +460,7 @@ declare class Dispatcher {
|
|
|
462
460
|
/**
|
|
463
461
|
* Add new element to storage
|
|
464
462
|
*/
|
|
465
|
-
addQueueElement: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, dispatcherDump:
|
|
463
|
+
addQueueElement: <Request_1 extends RequestInstance = RequestInstance>(queueKey: string, dispatcherDump: QueueElementType<Request_1>) => void;
|
|
466
464
|
/**
|
|
467
465
|
* Set new queue storage value
|
|
468
466
|
*/
|
|
@@ -545,7 +543,7 @@ declare class Dispatcher {
|
|
|
545
543
|
/**
|
|
546
544
|
* Create storage element from request
|
|
547
545
|
*/
|
|
548
|
-
createStorageElement: <Request_1 extends RequestInstance>(request: Request_1) =>
|
|
546
|
+
createStorageElement: <Request_1 extends RequestInstance>(request: Request_1) => QueueElementType<Request_1>;
|
|
549
547
|
/**
|
|
550
548
|
* Add request to the dispatcher handler
|
|
551
549
|
*/
|
|
@@ -558,7 +556,7 @@ declare class Dispatcher {
|
|
|
558
556
|
* Request can run for some time, once it's done, we have to check if it's successful or if it was aborted
|
|
559
557
|
* It can be different once the previous call was set as cancelled and removed from queue before this request got resolved
|
|
560
558
|
*/
|
|
561
|
-
performRequest: (storageElement:
|
|
559
|
+
performRequest: (storageElement: QueueElementType) => Promise<void | QueueDataType<RequestInstance>>;
|
|
562
560
|
}
|
|
563
561
|
|
|
564
562
|
type DispatcherOptionsType = {
|
|
@@ -568,15 +566,15 @@ type DispatcherOptionsType = {
|
|
|
568
566
|
onDeleteFromStorage?: <Request extends RequestInstance>(queueKey: string, data: QueueDataType<Request>) => void;
|
|
569
567
|
onClearStorage?: (dispatcherInstance: Dispatcher) => void;
|
|
570
568
|
};
|
|
571
|
-
type
|
|
569
|
+
type QueueElementType<Request extends RequestInstance = RequestInstance> = {
|
|
572
570
|
requestId: string;
|
|
573
|
-
|
|
571
|
+
request: Request;
|
|
574
572
|
retries: number;
|
|
575
573
|
timestamp: number;
|
|
576
574
|
stopped: boolean;
|
|
577
575
|
};
|
|
578
576
|
type QueueDataType<Request extends RequestInstance = RequestInstance> = {
|
|
579
|
-
requests:
|
|
577
|
+
requests: QueueElementType<Request>[];
|
|
580
578
|
stopped: boolean;
|
|
581
579
|
};
|
|
582
580
|
type DispatcherStorageType = {
|
|
@@ -596,17 +594,15 @@ declare const getDispatcherStatusEventKey: (key: string) => string;
|
|
|
596
594
|
declare const getDispatcherChangeEventKey: (key: string) => string;
|
|
597
595
|
declare const getIsEqualTimestamp: (currentTimestamp: number, threshold: number, queueTimestamp?: number) => boolean;
|
|
598
596
|
declare const canRetryRequest: (currentRetries: number, retry: number | undefined) => boolean;
|
|
599
|
-
declare const getRequestType: (request: RequestInstance, latestRequest:
|
|
600
|
-
declare const isFailedRequest: (data: ResponseType<unknown, unknown>) => boolean;
|
|
597
|
+
declare const getRequestType: (request: RequestInstance, latestRequest: QueueElementType | undefined) => DispatcherRequestType;
|
|
601
598
|
|
|
602
599
|
/**
|
|
603
600
|
* **Client** is a class that allows you to configure the connection with the server and then use it to create
|
|
604
601
|
* requests which, when called using the appropriate method, will cause the server to be queried for the endpoint and
|
|
605
602
|
* method specified in the request.
|
|
606
|
-
* @position 1
|
|
607
603
|
*/
|
|
608
|
-
declare class Client<GlobalErrorType extends ClientErrorType = Error,
|
|
609
|
-
options: ClientOptionsType
|
|
604
|
+
declare class Client<GlobalErrorType extends ClientErrorType = Error, Adapter extends AdapterInstance = AdapterType> {
|
|
605
|
+
options: ClientOptionsType<Client<GlobalErrorType, Adapter>>;
|
|
610
606
|
readonly url: string;
|
|
611
607
|
debug: boolean;
|
|
612
608
|
__onErrorCallbacks: ResponseInterceptorType[];
|
|
@@ -617,14 +613,20 @@ declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOpt
|
|
|
617
613
|
requestManager: RequestManager;
|
|
618
614
|
appManager: AppManager;
|
|
619
615
|
loggerManager: LoggerManager;
|
|
620
|
-
adapter:
|
|
621
|
-
cache: Cache
|
|
616
|
+
adapter: Adapter;
|
|
617
|
+
cache: Cache<this>;
|
|
622
618
|
fetchDispatcher: Dispatcher;
|
|
623
619
|
submitDispatcher: Dispatcher;
|
|
620
|
+
defaultMethod: ExtractAdapterMethodType<Adapter>;
|
|
621
|
+
defaultExtra: ExtractAdapterExtraType<Adapter>;
|
|
624
622
|
effects: RequestEffectInstance[];
|
|
625
623
|
queryParamsConfig?: QueryStringifyOptionsType;
|
|
626
|
-
adapterDefaultOptions?: (request: RequestInstance) =>
|
|
627
|
-
requestDefaultOptions?: (options: RequestOptionsType<string,
|
|
624
|
+
adapterDefaultOptions?: (request: RequestInstance) => ExtractAdapterOptionsType<Adapter>;
|
|
625
|
+
requestDefaultOptions?: (options: RequestOptionsType<string, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>) => Partial<RequestOptionsType<string, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>>;
|
|
626
|
+
abortKeyMapper?: (request: RequestInstance) => string;
|
|
627
|
+
cacheKeyMapper?: (request: RequestInstance) => string;
|
|
628
|
+
queueKeyMapper?: (request: RequestInstance) => string;
|
|
629
|
+
effectKeyMapper?: (request: RequestInstance) => string;
|
|
628
630
|
/**
|
|
629
631
|
* Method to stringify query params from objects.
|
|
630
632
|
*/
|
|
@@ -638,65 +640,73 @@ declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOpt
|
|
|
638
640
|
*/
|
|
639
641
|
payloadMapper: AdapterPayloadMappingType;
|
|
640
642
|
logger: LoggerType;
|
|
641
|
-
constructor(options: ClientOptionsType);
|
|
643
|
+
constructor(options: ClientOptionsType<Client<GlobalErrorType, Adapter>>);
|
|
642
644
|
/**
|
|
643
645
|
* This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
|
|
644
646
|
*/
|
|
645
|
-
setRequestDefaultOptions: (callback: (request: RequestInstance) => Partial<RequestOptionsType<string,
|
|
646
|
-
setAdapterDefaultOptions: (callback: (request: RequestInstance) =>
|
|
647
|
+
setRequestDefaultOptions: (callback: (request: RequestInstance) => Partial<RequestOptionsType<string, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>>) => Client<GlobalErrorType, Adapter>;
|
|
648
|
+
setAdapterDefaultOptions: (callback: (request: RequestInstance) => ExtractAdapterOptionsType<Adapter>) => Client<GlobalErrorType, Adapter>;
|
|
647
649
|
/**
|
|
648
650
|
* This method enables the logger usage and display the logs in console
|
|
649
651
|
*/
|
|
650
|
-
setDebug: (debug: boolean) => Client<GlobalErrorType,
|
|
652
|
+
setDebug: (debug: boolean) => Client<GlobalErrorType, Adapter>;
|
|
651
653
|
/**
|
|
652
654
|
* Set the logger severity of the messages displayed to the console
|
|
653
655
|
*/
|
|
654
|
-
setLoggerSeverity: (severity: SeverityType) => Client<GlobalErrorType,
|
|
656
|
+
setLoggerSeverity: (severity: SeverityType) => Client<GlobalErrorType, Adapter>;
|
|
655
657
|
/**
|
|
656
658
|
* Set the new logger instance to the Client
|
|
657
659
|
*/
|
|
658
|
-
setLogger: (callback: (Client: ClientInstance) => LoggerManager) => Client<GlobalErrorType,
|
|
660
|
+
setLogger: (callback: (Client: ClientInstance) => LoggerManager) => Client<GlobalErrorType, Adapter>;
|
|
659
661
|
/**
|
|
660
662
|
* Set config for the query params stringify method, we can set here, among others, arrayFormat, skipNull, encode, skipEmptyString and more
|
|
661
663
|
*/
|
|
662
|
-
setQueryParamsConfig: (queryParamsConfig: QueryStringifyOptionsType) => Client<GlobalErrorType,
|
|
664
|
+
setQueryParamsConfig: (queryParamsConfig: QueryStringifyOptionsType) => Client<GlobalErrorType, Adapter>;
|
|
663
665
|
/**
|
|
664
666
|
* Set the custom query params stringify method to the Client
|
|
665
667
|
* @param stringifyFn Custom callback handling query params stringify
|
|
666
668
|
*/
|
|
667
|
-
setStringifyQueryParams: (stringifyFn: StringifyCallbackType) => Client<GlobalErrorType,
|
|
669
|
+
setStringifyQueryParams: (stringifyFn: StringifyCallbackType) => Client<GlobalErrorType, Adapter>;
|
|
668
670
|
/**
|
|
669
671
|
* Set the custom header mapping function
|
|
670
672
|
*/
|
|
671
|
-
setHeaderMapper: (headerMapper: HeaderMappingType) => Client<GlobalErrorType,
|
|
673
|
+
setHeaderMapper: (headerMapper: HeaderMappingType) => Client<GlobalErrorType, Adapter>;
|
|
672
674
|
/**
|
|
673
675
|
* Set the request payload mapping function which get triggered before request get send
|
|
674
676
|
*/
|
|
675
|
-
setPayloadMapper: (payloadMapper: AdapterPayloadMappingType) => Client<GlobalErrorType,
|
|
677
|
+
setPayloadMapper: (payloadMapper: AdapterPayloadMappingType) => Client<GlobalErrorType, Adapter>;
|
|
678
|
+
/**
|
|
679
|
+
* Set custom http adapter to handle graphql, rest, firebase or others
|
|
680
|
+
*/
|
|
681
|
+
setAdapter: <NewAdapter extends AdapterInstance>(callback: (Client: ClientInstance) => NewAdapter) => Client<GlobalErrorType, NewAdapter>;
|
|
682
|
+
/**
|
|
683
|
+
* Set default method for requests.
|
|
684
|
+
*/
|
|
685
|
+
setDefaultMethod: (defaultMethod: ExtractAdapterMethodType<Adapter>) => ClientInstance;
|
|
676
686
|
/**
|
|
677
|
-
* Set
|
|
687
|
+
* Set default additional data for initial state.
|
|
678
688
|
*/
|
|
679
|
-
|
|
689
|
+
setDefaultExtra: (defaultExtra: ExtractAdapterExtraType<Adapter>) => ClientInstance;
|
|
680
690
|
/**
|
|
681
691
|
* 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
692
|
*/
|
|
683
|
-
onAuth: (callback: RequestInterceptorType) => Client<GlobalErrorType,
|
|
693
|
+
onAuth: (callback: RequestInterceptorType) => Client<GlobalErrorType, Adapter>;
|
|
684
694
|
/**
|
|
685
695
|
* Method for intercepting error responses. It can be used for example to refresh tokens.
|
|
686
696
|
*/
|
|
687
|
-
onError: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType,
|
|
697
|
+
onError: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType, Adapter>) => Client<GlobalErrorType, Adapter>;
|
|
688
698
|
/**
|
|
689
699
|
* Method for intercepting success responses.
|
|
690
700
|
*/
|
|
691
|
-
onSuccess: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType,
|
|
701
|
+
onSuccess: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType, Adapter>) => Client<GlobalErrorType, Adapter>;
|
|
692
702
|
/**
|
|
693
703
|
* Method of manipulating requests before sending the request.
|
|
694
704
|
*/
|
|
695
|
-
onRequest: (callback: RequestInterceptorType) => Client<GlobalErrorType,
|
|
705
|
+
onRequest: (callback: RequestInterceptorType) => Client<GlobalErrorType, Adapter>;
|
|
696
706
|
/**
|
|
697
707
|
* Method for intercepting any responses.
|
|
698
708
|
*/
|
|
699
|
-
onResponse: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType>) => Client<GlobalErrorType,
|
|
709
|
+
onResponse: <ErrorType = null>(callback: ResponseInterceptorType<any, GlobalErrorType | ErrorType, Adapter>) => Client<GlobalErrorType, Adapter>;
|
|
700
710
|
/**
|
|
701
711
|
* Add persistent effects which trigger on the request lifecycle
|
|
702
712
|
*/
|
|
@@ -705,6 +715,13 @@ declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOpt
|
|
|
705
715
|
* Remove effects from Client
|
|
706
716
|
*/
|
|
707
717
|
removeEffect: (effect: RequestEffectInstance | string) => this;
|
|
718
|
+
/**
|
|
719
|
+
* Key setters
|
|
720
|
+
*/
|
|
721
|
+
setAbortKeyMapper: (callback: (request: RequestInstance) => string) => void;
|
|
722
|
+
setCacheKeyMapper: (callback: (request: RequestInstance) => string) => void;
|
|
723
|
+
setQueueKeyMapper: (callback: (request: RequestInstance) => string) => void;
|
|
724
|
+
setEffectKeyMapper: (callback: (request: RequestInstance) => string) => void;
|
|
708
725
|
/**
|
|
709
726
|
* Helper used by http adapter to apply the modifications on response error
|
|
710
727
|
*/
|
|
@@ -716,15 +733,15 @@ declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOpt
|
|
|
716
733
|
/**
|
|
717
734
|
* Private helper to run async on-error response processing
|
|
718
735
|
*/
|
|
719
|
-
__modifyErrorResponse: (response:
|
|
736
|
+
__modifyErrorResponse: (response: ResponseReturnType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>;
|
|
720
737
|
/**
|
|
721
738
|
* Private helper to run async on-success response processing
|
|
722
739
|
*/
|
|
723
|
-
__modifySuccessResponse: (response:
|
|
740
|
+
__modifySuccessResponse: (response: ResponseReturnType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>;
|
|
724
741
|
/**
|
|
725
742
|
* Private helper to run async response processing
|
|
726
743
|
*/
|
|
727
|
-
__modifyResponse: (response:
|
|
744
|
+
__modifyResponse: (response: ResponseReturnType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>;
|
|
728
745
|
/**
|
|
729
746
|
* Clears the Client instance and remove all listeners on it's dependencies
|
|
730
747
|
*/
|
|
@@ -732,15 +749,20 @@ declare class Client<GlobalErrorType extends ClientErrorType = Error, AdapterOpt
|
|
|
732
749
|
/**
|
|
733
750
|
* Create requests based on the Client setup
|
|
734
751
|
*/
|
|
735
|
-
createRequest: <Response_1, Payload = undefined, LocalError extends ClientErrorType = undefined, QueryParams
|
|
752
|
+
createRequest: <Response_1, Payload = undefined, LocalError extends ClientErrorType = undefined, QueryParams = ExtractAdapterQueryParamsType<Adapter>>() => <EndpointType extends string, AdapterOptions extends ExtractAdapterOptionsType<Adapter>, MethodType extends ExtractAdapterMethodType<Adapter>>(params: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Request<Response_1, Payload, QueryParams, GlobalErrorType, LocalError, EndpointType, ExtractUnionAdapter<Adapter, {
|
|
753
|
+
method: MethodType;
|
|
754
|
+
options: AdapterOptions;
|
|
755
|
+
queryParams: QueryParams;
|
|
756
|
+
}>, false, false, false>;
|
|
736
757
|
}
|
|
737
758
|
|
|
738
759
|
type ClientErrorType = Record<string, any> | string;
|
|
739
|
-
type ClientInstance = Client<any, any
|
|
760
|
+
type ClientInstance = Client<any, AdapterType<any, any, any, any>>;
|
|
761
|
+
type ExtractAdapterTypeFromClient<T> = T extends Client<any, infer A> ? A : never;
|
|
740
762
|
/**
|
|
741
763
|
* Configuration setup for the client
|
|
742
764
|
*/
|
|
743
|
-
type ClientOptionsType = {
|
|
765
|
+
type ClientOptionsType<C extends ClientInstance> = {
|
|
744
766
|
/**
|
|
745
767
|
* Url to your server
|
|
746
768
|
*/
|
|
@@ -752,27 +774,27 @@ type ClientOptionsType = {
|
|
|
752
774
|
/**
|
|
753
775
|
* Custom cache initialization prop
|
|
754
776
|
*/
|
|
755
|
-
cache?:
|
|
777
|
+
cache?: (client: C) => C["cache"];
|
|
756
778
|
/**
|
|
757
779
|
* Custom app manager initialization prop
|
|
758
780
|
*/
|
|
759
|
-
appManager?:
|
|
781
|
+
appManager?: (client: C) => C["appManager"];
|
|
760
782
|
/**
|
|
761
783
|
* Custom fetch dispatcher initialization prop
|
|
762
784
|
*/
|
|
763
|
-
fetchDispatcher?:
|
|
785
|
+
fetchDispatcher?: (client: C) => C["submitDispatcher"];
|
|
764
786
|
/**
|
|
765
787
|
* Custom submit dispatcher initialization prop
|
|
766
788
|
*/
|
|
767
|
-
submitDispatcher?:
|
|
789
|
+
submitDispatcher?: (client: C) => C["fetchDispatcher"];
|
|
768
790
|
};
|
|
769
791
|
type RequestInterceptorType = (request: RequestInstance) => Promise<RequestInstance> | RequestInstance;
|
|
770
|
-
type ResponseInterceptorType<Response = any, Error = any> = (response:
|
|
792
|
+
type ResponseInterceptorType<Response = any, Error = any, Adapter extends AdapterInstance = AdapterType> = (response: ResponseReturnType<Response, Error, Adapter>, request: RequestInstance) => Promise<ResponseReturnType<any, any, Adapter>> | ResponseReturnType<any, any, Adapter>;
|
|
771
793
|
type StringifyCallbackType = (queryParams: QueryParamsType | string | NegativeTypes) => string;
|
|
772
794
|
|
|
773
795
|
declare const stringifyValue: (response: string | unknown) => string;
|
|
774
796
|
declare const interceptRequest: (interceptors: RequestInterceptorType[], request: RequestInstance) => Promise<RequestInstance>;
|
|
775
|
-
declare const interceptResponse: <GlobalErrorType>(interceptors: ResponseInterceptorType[], response:
|
|
797
|
+
declare const interceptResponse: <GlobalErrorType, Adapter extends AdapterInstance>(interceptors: ResponseInterceptorType[], response: ResponseReturnType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>;
|
|
776
798
|
declare const getAdapterHeaders: (request: RequestInstance) => HeadersInit;
|
|
777
799
|
declare const getAdapterPayload: (data: unknown) => string | FormData;
|
|
778
800
|
declare const stringifyQueryParams: (queryParams: QueryParamsType | string | NegativeTypes, options?: QueryStringifyOptionsType) => string;
|
|
@@ -786,10 +808,50 @@ declare const stringifyDefaultOptions: {
|
|
|
786
808
|
readonly skipNull: true;
|
|
787
809
|
readonly skipEmptyString: true;
|
|
788
810
|
};
|
|
811
|
+
declare const xhrExtra: AdapterExtraType;
|
|
812
|
+
|
|
813
|
+
declare const mocker: <T extends AdapterInstance = AdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterExtraType, string | QueryParamsType>>(request: RequestInstance, { onError, onResponseEnd, onTimeoutError, onRequestEnd, createAbortListener, onResponseProgress, onRequestProgress, onResponseStart, onBeforeRequest, onRequestStart, onSuccess, }: Pick<{
|
|
814
|
+
fullUrl: string;
|
|
815
|
+
data: any;
|
|
816
|
+
headers: HeadersInit;
|
|
817
|
+
payload: any;
|
|
818
|
+
config: ExtractAdapterOptionsType<T>;
|
|
819
|
+
getAbortController: () => AbortController;
|
|
820
|
+
getRequestStartTimestamp: () => number;
|
|
821
|
+
getResponseStartTimestamp: () => number;
|
|
822
|
+
createAbortListener: (status: ExtractAdapterStatusType<T>, abortExtra: ExtractAdapterExtraType<T>, callback: () => void, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => () => void;
|
|
823
|
+
onBeforeRequest: () => void;
|
|
824
|
+
onRequestStart: (progress?: ProgressDataType) => number;
|
|
825
|
+
onRequestProgress: (progress: ProgressDataType) => number;
|
|
826
|
+
onRequestEnd: () => number;
|
|
827
|
+
onResponseStart: (progress?: ProgressDataType) => number;
|
|
828
|
+
onResponseProgress: (progress: ProgressDataType) => number;
|
|
829
|
+
onResponseEnd: () => number;
|
|
830
|
+
onSuccess: (responseData: any, status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<any, T>) => void) => Promise<ResponseReturnSuccessType<ExtractResponseType<T>, T>>;
|
|
831
|
+
onAbortError: (status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
832
|
+
onTimeoutError: (status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
833
|
+
onUnexpectedError: (status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
834
|
+
onError: (error: any, status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<any, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
835
|
+
makeRequest: (apiCall: (resolve: (value: ResponseReturnType<any, any, T> | PromiseLike<ResponseReturnType<any, any, T>>) => void) => void) => Promise<ResponseReturnType<any, any, T>>;
|
|
836
|
+
}, "onRequestStart" | "onResponseStart" | "onError" | "onResponseEnd" | "onTimeoutError" | "onRequestEnd" | "createAbortListener" | "onResponseProgress" | "onRequestProgress" | "onBeforeRequest" | "onSuccess">) => Promise<ResponseReturnType<any, any, any>>;
|
|
837
|
+
|
|
838
|
+
type RequestMockType<Response> = {
|
|
839
|
+
data: Response | Response[] | (() => Response);
|
|
840
|
+
config?: {
|
|
841
|
+
status?: number | string;
|
|
842
|
+
success?: boolean;
|
|
843
|
+
responseDelay?: number;
|
|
844
|
+
requestSentDuration?: number;
|
|
845
|
+
responseReceivedDuration?: number;
|
|
846
|
+
};
|
|
847
|
+
extra?: any;
|
|
848
|
+
};
|
|
849
|
+
type RequestDataMockTypes<Response, Request extends RequestInstance> = RequestMockType<Response> | RequestMockType<Response>[] | ((r: Request) => RequestMockType<Response>) | ((r: Request) => RequestMockType<Response>)[] | ((r: Request) => Promise<RequestMockType<Response>>) | ((r: Request) => Promise<RequestMockType<Response>>)[];
|
|
850
|
+
type GeneratorReturnMockTypes<Response, Request extends RequestInstance> = RequestMockType<Response> | ((r: Request) => RequestMockType<Response>) | ((r: Request) => Promise<RequestMockType<Response>>);
|
|
789
851
|
|
|
790
852
|
/**
|
|
791
853
|
* Fetch request it is designed to prepare the necessary setup to execute the request to the server.
|
|
792
|
-
* We can
|
|
854
|
+
* We can set up basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
|
|
793
855
|
* :::info Usage
|
|
794
856
|
* 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
857
|
* :::
|
|
@@ -798,21 +860,20 @@ declare const stringifyDefaultOptions: {
|
|
|
798
860
|
* 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
861
|
* This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
|
|
800
862
|
*/
|
|
801
|
-
declare class Request<Response, Payload, QueryParams
|
|
863
|
+
declare class Request<Response, Payload, QueryParams, GlobalError, // Global Error Type
|
|
802
864
|
LocalError, // Additional Error for specific endpoint
|
|
803
|
-
Endpoint extends string,
|
|
804
|
-
readonly client: Client<GlobalError,
|
|
805
|
-
readonly requestOptions: RequestOptionsType<Endpoint,
|
|
806
|
-
readonly
|
|
807
|
-
readonly dataMapper?: PayloadMapperType<Payload, MappedData>;
|
|
865
|
+
Endpoint extends string, Adapter extends AdapterInstance = AdapterType, HasData extends true | false = false, HasParams extends true | false = false, HasQuery extends true | false = false> {
|
|
866
|
+
readonly client: Client<GlobalError, Adapter>;
|
|
867
|
+
readonly requestOptions: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>;
|
|
868
|
+
readonly requestJSON?: RequestCurrentType<Payload, QueryParams, Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>> | undefined;
|
|
808
869
|
endpoint: Endpoint;
|
|
809
870
|
headers?: HeadersInit;
|
|
810
871
|
auth: boolean;
|
|
811
|
-
method:
|
|
872
|
+
method: ExtractAdapterMethodType<Adapter>;
|
|
812
873
|
params: ExtractRouteParams<Endpoint> | NegativeTypes;
|
|
813
|
-
data: PayloadType<Payload
|
|
874
|
+
data: PayloadType<Payload>;
|
|
814
875
|
queryParams: QueryParams | NegativeTypes;
|
|
815
|
-
options?:
|
|
876
|
+
options?: ExtractAdapterOptionsType<Adapter> | undefined;
|
|
816
877
|
cancelable: boolean;
|
|
817
878
|
retry: number;
|
|
818
879
|
retryTime: number;
|
|
@@ -828,37 +889,64 @@ Endpoint extends string, AdapterOptions, HasData extends true | false = false, H
|
|
|
828
889
|
used: boolean;
|
|
829
890
|
deduplicate: boolean;
|
|
830
891
|
deduplicateTime: number;
|
|
892
|
+
dataMapper?: PayloadMapperType<Payload>;
|
|
893
|
+
mock?: Generator<GeneratorReturnMockTypes<Response, this>, GeneratorReturnMockTypes<Response, this>, GeneratorReturnMockTypes<Response, this>>;
|
|
894
|
+
mockData?: RequestDataMockTypes<Response, this>;
|
|
895
|
+
requestMapper?: RequestMapper<this, any>;
|
|
896
|
+
responseMapper?: ResponseMapper<this, any, any>;
|
|
831
897
|
private updatedAbortKey;
|
|
832
898
|
private updatedCacheKey;
|
|
833
899
|
private updatedQueueKey;
|
|
834
900
|
private updatedEffectKey;
|
|
835
|
-
constructor(client: Client<GlobalError,
|
|
836
|
-
setHeaders: (headers: HeadersInit) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
837
|
-
setAuth: (auth: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
838
|
-
setParams: <P extends ExtractRouteParams<Endpoint>>(params: P) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
839
|
-
setData: <D extends Payload>(data: D) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
840
|
-
setQueryParams: (queryParams: QueryParams) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
841
|
-
setOptions: (options:
|
|
842
|
-
setCancelable: (cancelable: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
843
|
-
setRetry: (retry: RequestOptionsType<Endpoint,
|
|
844
|
-
setRetryTime: (retryTime: RequestOptionsType<Endpoint,
|
|
845
|
-
setGarbageCollection: (garbageCollection: RequestOptionsType<Endpoint,
|
|
846
|
-
setCache: (cache: RequestOptionsType<Endpoint,
|
|
847
|
-
setCacheTime: (cacheTime: RequestOptionsType<Endpoint,
|
|
848
|
-
setQueued: (queued: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
849
|
-
setAbortKey: (abortKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
850
|
-
setCacheKey: (cacheKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
851
|
-
setQueueKey: (queueKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
852
|
-
setEffectKey: (effectKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
853
|
-
setDeduplicate: (deduplicate: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
854
|
-
setDeduplicateTime: (deduplicateTime: number) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
855
|
-
setUsed: (used: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
856
|
-
setOffline: (offline: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
857
|
-
|
|
901
|
+
constructor(client: Client<GlobalError, Adapter>, requestOptions: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>, requestJSON?: RequestCurrentType<Payload, QueryParams, Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>> | undefined);
|
|
902
|
+
setHeaders: (headers: HeadersInit) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
903
|
+
setAuth: (auth: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
904
|
+
setParams: <P extends ExtractRouteParams<Endpoint>>(params: P) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, P extends null ? false : true, HasQuery>;
|
|
905
|
+
setData: <D extends Payload>(data: D) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, D extends null ? false : true, HasParams, HasQuery>;
|
|
906
|
+
setQueryParams: (queryParams: QueryParams) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, true>;
|
|
907
|
+
setOptions: (options: ExtractAdapterOptionsType<Adapter>) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, true>;
|
|
908
|
+
setCancelable: (cancelable: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
909
|
+
setRetry: (retry: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["retry"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
910
|
+
setRetryTime: (retryTime: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["retryTime"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
911
|
+
setGarbageCollection: (garbageCollection: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["garbageCollection"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
912
|
+
setCache: (cache: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["cache"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
913
|
+
setCacheTime: (cacheTime: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["cacheTime"]) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
914
|
+
setQueued: (queued: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
915
|
+
setAbortKey: (abortKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
916
|
+
setCacheKey: (cacheKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
917
|
+
setQueueKey: (queueKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
918
|
+
setEffectKey: (effectKey: string) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
919
|
+
setDeduplicate: (deduplicate: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
920
|
+
setDeduplicateTime: (deduplicateTime: number) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
921
|
+
setUsed: (used: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
922
|
+
setOffline: (offline: boolean) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
923
|
+
setMock: (mockData: RequestDataMockTypes<Response, this>) => this;
|
|
924
|
+
removeMock: () => this;
|
|
925
|
+
/**
|
|
926
|
+
* Mappers
|
|
927
|
+
*/
|
|
928
|
+
/**
|
|
929
|
+
* Map data before it gets send to the server
|
|
930
|
+
* @param dataMapper
|
|
931
|
+
* @returns
|
|
932
|
+
*/
|
|
933
|
+
setDataMapper: <DataMapper extends (data: Payload) => any | Promise<any>>(dataMapper: DataMapper) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
934
|
+
/**
|
|
935
|
+
* Map request before it gets send to the server
|
|
936
|
+
* @param requestMapper mapper of the request
|
|
937
|
+
* @returns new request
|
|
938
|
+
*/
|
|
939
|
+
setRequestMapper: <NewRequest extends RequestInstance>(requestMapper: RequestMapper<this, NewRequest>) => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
940
|
+
/**
|
|
941
|
+
* Map the response to the new interface
|
|
942
|
+
* @param responseMapper our mapping callback
|
|
943
|
+
* @returns new response
|
|
944
|
+
*/
|
|
945
|
+
setResponseMapper: <NewResponse = Response, NewError = GlobalError | LocalError>(responseMapper?: ResponseMapper<this, NewResponse, NewError>) => Request<NewResponse, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
858
946
|
private paramsMapper;
|
|
859
|
-
|
|
860
|
-
clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery
|
|
861
|
-
abort: () => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint,
|
|
947
|
+
toJSON(): RequestJSON<this, ExtractAdapterOptionsType<Adapter>, QueryParams>;
|
|
948
|
+
clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery>(options?: RequestCurrentType<Payload, QueryParams, Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>): Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, D, P, Q>;
|
|
949
|
+
abort: () => Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>;
|
|
862
950
|
/**
|
|
863
951
|
* Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
|
|
864
952
|
* @param options
|
|
@@ -868,7 +956,7 @@ Endpoint extends string, AdapterOptions, HasData extends true | false = false, H
|
|
|
868
956
|
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
869
957
|
* ```
|
|
870
958
|
*/
|
|
871
|
-
exec: RequestSendType<
|
|
959
|
+
exec: RequestSendType<this>;
|
|
872
960
|
/**
|
|
873
961
|
* Method used to perform requests with usage of cache and queues
|
|
874
962
|
* @param options
|
|
@@ -879,7 +967,7 @@ Endpoint extends string, AdapterOptions, HasData extends true | false = false, H
|
|
|
879
967
|
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
880
968
|
* ```
|
|
881
969
|
*/
|
|
882
|
-
send: RequestSendType<
|
|
970
|
+
send: RequestSendType<this>;
|
|
883
971
|
}
|
|
884
972
|
|
|
885
973
|
type AdapterProgressEventType = {
|
|
@@ -894,10 +982,10 @@ type AdapterProgressType = {
|
|
|
894
982
|
/**
|
|
895
983
|
* Dump of the request used to later recreate it
|
|
896
984
|
*/
|
|
897
|
-
type
|
|
898
|
-
requestOptions: RequestOptionsType<string, AdapterOptions |
|
|
985
|
+
type RequestJSON<Request extends RequestInstance, AdapterOptions = unknown, QueryParams = QueryParamsType, Params = ExtractParamsType<Request>> = {
|
|
986
|
+
requestOptions: RequestOptionsType<string, AdapterOptions | ExtractAdapterType<Request>, ExtractAdapterMethodType<ExtractAdapterType<Request>>>;
|
|
899
987
|
endpoint: string;
|
|
900
|
-
method:
|
|
988
|
+
method: ExtractAdapterMethodType<ExtractAdapterType<Request>>;
|
|
901
989
|
headers?: HeadersInit;
|
|
902
990
|
auth: boolean;
|
|
903
991
|
cancelable: boolean;
|
|
@@ -910,8 +998,8 @@ type RequestDump<Request extends RequestInstance, AdapterOptions = unknown, Quer
|
|
|
910
998
|
offline: boolean;
|
|
911
999
|
disableResponseInterceptors: boolean | undefined;
|
|
912
1000
|
disableRequestInterceptors: boolean | undefined;
|
|
913
|
-
options?: AdapterOptions | ExtractAdapterOptionsType<Request
|
|
914
|
-
data: PayloadType<ExtractPayloadType<Request
|
|
1001
|
+
options?: AdapterOptions | ExtractAdapterOptionsType<ExtractAdapterType<Request>>;
|
|
1002
|
+
data: PayloadType<ExtractPayloadType<Request>>;
|
|
915
1003
|
params: Params | NegativeTypes;
|
|
916
1004
|
queryParams: QueryParams | NegativeTypes;
|
|
917
1005
|
abortKey: string;
|
|
@@ -929,7 +1017,7 @@ type RequestDump<Request extends RequestInstance, AdapterOptions = unknown, Quer
|
|
|
929
1017
|
/**
|
|
930
1018
|
* Configuration options for request creation
|
|
931
1019
|
*/
|
|
932
|
-
type RequestOptionsType<GenericEndpoint extends string, AdapterOptions> = {
|
|
1020
|
+
type RequestOptionsType<GenericEndpoint extends string, AdapterOptions extends Record<string, any>, RequestMethods = HttpMethodsType> = {
|
|
933
1021
|
/**
|
|
934
1022
|
* Determine the endpoint for request request
|
|
935
1023
|
*/
|
|
@@ -943,9 +1031,9 @@ type RequestOptionsType<GenericEndpoint extends string, AdapterOptions> = {
|
|
|
943
1031
|
*/
|
|
944
1032
|
auth?: boolean;
|
|
945
1033
|
/**
|
|
946
|
-
* Request method GET | POST | PATCH | PUT | DELETE
|
|
1034
|
+
* Request method GET | POST | PATCH | PUT | DELETE or set of method names handled by adapter
|
|
947
1035
|
*/
|
|
948
|
-
method?:
|
|
1036
|
+
method?: RequestMethods;
|
|
949
1037
|
/**
|
|
950
1038
|
* Should enable cancelable mode in the Dispatcher
|
|
951
1039
|
*/
|
|
@@ -1015,20 +1103,19 @@ type RequestOptionsType<GenericEndpoint extends string, AdapterOptions> = {
|
|
|
1015
1103
|
*/
|
|
1016
1104
|
deduplicateTime?: number;
|
|
1017
1105
|
};
|
|
1018
|
-
type PayloadMapperType<
|
|
1019
|
-
type PayloadType<Payload
|
|
1020
|
-
type RequestCurrentType<
|
|
1106
|
+
type PayloadMapperType<Payload> = <NewDataType>(data: Payload) => NewDataType;
|
|
1107
|
+
type PayloadType<Payload> = Payload | NegativeTypes;
|
|
1108
|
+
type RequestCurrentType<Payload, QueryParams, GenericEndpoint extends string, AdapterOptions, MethodsType = HttpMethodsType> = {
|
|
1021
1109
|
used?: boolean;
|
|
1022
1110
|
params?: ExtractRouteParams<GenericEndpoint> | NegativeTypes;
|
|
1023
1111
|
queryParams?: QueryParams | NegativeTypes;
|
|
1024
|
-
data?: PayloadType<Payload
|
|
1025
|
-
mockCallback?: ((data: Payload) => ResponseType<Response, ErrorType>) | undefined;
|
|
1112
|
+
data?: PayloadType<Payload>;
|
|
1026
1113
|
headers?: HeadersInit;
|
|
1027
1114
|
updatedAbortKey?: boolean;
|
|
1028
1115
|
updatedCacheKey?: boolean;
|
|
1029
1116
|
updatedQueueKey?: boolean;
|
|
1030
1117
|
updatedEffectKey?: boolean;
|
|
1031
|
-
} & Partial<NullableKeys<RequestOptionsType<GenericEndpoint, AdapterOptions>>>;
|
|
1118
|
+
} & Partial<NullableKeys<RequestOptionsType<GenericEndpoint, AdapterOptions, MethodsType>>>;
|
|
1032
1119
|
type ParamType = string | number;
|
|
1033
1120
|
type ParamsType = Record<string, ParamType>;
|
|
1034
1121
|
type ExtractRouteParams<T extends string> = string extends T ? NegativeTypes : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
@@ -1040,17 +1127,17 @@ type FetchOptionsType<AdapterOptions> = Omit<Partial<RequestOptionsType<string,
|
|
|
1040
1127
|
/**
|
|
1041
1128
|
* It will check if the query params are already set
|
|
1042
1129
|
*/
|
|
1043
|
-
type FetchQueryParamsType<QueryParams
|
|
1130
|
+
type FetchQueryParamsType<QueryParams, HasQuery extends true | false = false> = HasQuery extends true ? {
|
|
1044
1131
|
queryParams?: NegativeTypes;
|
|
1045
1132
|
} : {
|
|
1046
|
-
queryParams?: QueryParams
|
|
1133
|
+
queryParams?: QueryParams;
|
|
1047
1134
|
};
|
|
1048
1135
|
/**
|
|
1049
1136
|
* If the request endpoint parameters are not filled it will throw an error
|
|
1050
1137
|
*/
|
|
1051
1138
|
type FetchParamsType<Endpoint extends string, HasParams extends true | false> = ExtractRouteParams<Endpoint> extends NegativeTypes ? {
|
|
1052
1139
|
params?: NegativeTypes;
|
|
1053
|
-
} :
|
|
1140
|
+
} : HasParams extends true ? {
|
|
1054
1141
|
params?: NegativeTypes;
|
|
1055
1142
|
} : {
|
|
1056
1143
|
params: NonNullable<ExtractRouteParams<Endpoint>>;
|
|
@@ -1068,18 +1155,20 @@ type FetchPayloadType<Payload, HasData extends true | false> = Payload extends N
|
|
|
1068
1155
|
type RequestQueueOptions = {
|
|
1069
1156
|
dispatcherType?: "auto" | "fetch" | "submit";
|
|
1070
1157
|
};
|
|
1071
|
-
type RequestSendOptionsType<Request extends RequestInstance> = FetchQueryParamsType<
|
|
1158
|
+
type RequestSendOptionsType<Request extends RequestInstance> = FetchQueryParamsType<ExtractRequestQueryParamsType<Request>, ExtractHasQueryParamsType<Request>> & FetchParamsType<ExtractEndpointType<Request>, ExtractHasParamsType<Request>> & FetchPayloadType<ExtractPayloadType<Request>, ExtractHasDataType<Request>> & Omit<FetchOptionsType<ExtractAdapterType<Request>>, "params" | "data"> & FetchSendActionsType<Request> & RequestQueueOptions;
|
|
1072
1159
|
type FetchSendActionsType<Request extends RequestInstance> = {
|
|
1073
1160
|
onSettle?: (requestId: string, request: Request) => void;
|
|
1074
1161
|
onRequestStart?: (details: RequestEventType<Request>) => void;
|
|
1075
1162
|
onResponseStart?: (details: RequestEventType<Request>) => void;
|
|
1076
1163
|
onUploadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
|
|
1077
1164
|
onDownloadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
|
|
1078
|
-
onResponse?: (response:
|
|
1165
|
+
onResponse?: (response: ResponseReturnType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>, details: ResponseDetailsType) => void;
|
|
1079
1166
|
onRemove?: (details: RequestEventType<Request>) => void;
|
|
1080
1167
|
};
|
|
1081
|
-
type RequestSendType<Request extends RequestInstance> = RequestSendOptionsType<Request>["data"] extends NegativeTypes ? RequestSendOptionsType<Request>["params"] extends NegativeTypes ? (options?: RequestSendOptionsType<Request>) => Promise<
|
|
1082
|
-
type RequestInstance = Request<any, any, any, any, any, any, any, any, any, any, any>;
|
|
1168
|
+
type RequestSendType<Request extends RequestInstance> = RequestSendOptionsType<Request>["data"] extends NegativeTypes ? RequestSendOptionsType<Request>["params"] extends NegativeTypes ? (options?: RequestSendOptionsType<Request>) => Promise<ResponseReturnType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>> : (options: RequestSendOptionsType<Request>) => Promise<ResponseReturnType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>> : (options: RequestSendOptionsType<Request>) => Promise<ResponseReturnType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>>;
|
|
1169
|
+
type RequestInstance = Request<any, any, any, any, any, any, AdapterType<any, any, any, any, any>, any, any, any>;
|
|
1170
|
+
type RequestMapper<Request extends RequestInstance, NewRequest extends RequestInstance> = (request: Request, requestId: string) => NewRequest | Promise<NewRequest>;
|
|
1171
|
+
type ResponseMapper<Request extends RequestInstance, NewResponse, NewError> = (response: ResponseReturnType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>) => ResponseReturnType<NewResponse, NewError, ExtractAdapterType<Request>> | Promise<ResponseReturnType<NewResponse, NewError, ExtractAdapterType<Request>>>;
|
|
1083
1172
|
|
|
1084
1173
|
declare const stringifyKey: (value: unknown) => string;
|
|
1085
1174
|
declare const getProgressValue: ({ loaded, total }: AdapterProgressEventType) => number;
|
|
@@ -1088,7 +1177,7 @@ declare const getRequestEta: (startDate: Date, progressDate: Date, { total, load
|
|
|
1088
1177
|
timeLeft: number | null;
|
|
1089
1178
|
};
|
|
1090
1179
|
declare const getProgressData: (requestStartTime: Date, progressDate: Date, progressEvent: AdapterProgressEventType) => ProgressType;
|
|
1091
|
-
declare const getSimpleKey: (request: RequestInstance |
|
|
1180
|
+
declare const getSimpleKey: (request: RequestInstance | RequestJSON<RequestInstance>) => string;
|
|
1092
1181
|
/**
|
|
1093
1182
|
* Cache instance for individual request that collects individual requests responses from
|
|
1094
1183
|
* the same endpoint (they may differ base on the custom key, endpoint params etc)
|
|
@@ -1096,21 +1185,66 @@ declare const getSimpleKey: (request: RequestInstance | RequestDump<RequestInsta
|
|
|
1096
1185
|
* @param useInitialValues
|
|
1097
1186
|
* @returns
|
|
1098
1187
|
*/
|
|
1099
|
-
declare const getRequestKey: (request: RequestInstance |
|
|
1188
|
+
declare const getRequestKey: (request: RequestInstance | RequestJSON<RequestInstance>, useInitialValues?: boolean) => string;
|
|
1100
1189
|
declare const getRequestDispatcher: <Request_1 extends RequestInstance>(request: Request_1, dispatcherType?: "auto" | "fetch" | "submit") => [Dispatcher, boolean];
|
|
1101
|
-
declare const
|
|
1190
|
+
declare const sendRequest: <Request_1 extends RequestInstance>(request: Request_1, options?: RequestSendOptionsType<Request_1>) => Promise<ResponseReturnType<ExtractResponseType<Request_1>, ExtractErrorType<Request_1>, ExtractAdapterType<Request_1>>>;
|
|
1102
1191
|
|
|
1103
|
-
|
|
1192
|
+
/**
|
|
1193
|
+
* Base Adapter
|
|
1194
|
+
*/
|
|
1195
|
+
type AdapterInstance = AdapterType<any, any, any, any, any>;
|
|
1196
|
+
type AdapterType<AdapterOptions = AdapterOptionsType, MethodType = HttpMethodsType, StatusType = HttpStatusType, Extra extends Record<string, any> = AdapterExtraType, QueryParams = QueryParamsType | string> = (request: RequestInstance, requestId: string, DO_NOT_USE?: {
|
|
1197
|
+
method?: MethodType;
|
|
1198
|
+
options?: AdapterOptions;
|
|
1199
|
+
status?: StatusType;
|
|
1200
|
+
extra?: Extra;
|
|
1201
|
+
queryParams?: QueryParams;
|
|
1202
|
+
}) => Promise<ResponseReturnType<any, any, any>>;
|
|
1203
|
+
/**
|
|
1204
|
+
* Extractors
|
|
1205
|
+
*/
|
|
1206
|
+
type ExtractAdapterOptionsType<T> = T extends AdapterType<infer O, any, any, any, any> ? O : never;
|
|
1207
|
+
type ExtractAdapterMethodType<T> = T extends AdapterType<any, infer M, any, any, any> ? M : never;
|
|
1208
|
+
type ExtractAdapterStatusType<T> = T extends AdapterType<any, any, infer S, any, any> ? S : never;
|
|
1209
|
+
type ExtractAdapterExtraType<T> = T extends AdapterType<any, any, any, infer A, any> ? A : never;
|
|
1210
|
+
type ExtractAdapterQueryParamsType<T> = T extends AdapterType<any, any, any, any, infer Q> ? Q : never;
|
|
1211
|
+
type ExtractUnionAdapter<Adapter extends AdapterInstance, Values extends {
|
|
1212
|
+
method?: any;
|
|
1213
|
+
options?: any;
|
|
1214
|
+
status?: any;
|
|
1215
|
+
extra?: any;
|
|
1216
|
+
queryParams?: any;
|
|
1217
|
+
}> = Extract<Adapter, AdapterType<Values["options"], Values["method"], Values["status"], Values["extra"], Values["queryParams"]>> extends AdapterInstance ? Extract<Adapter, AdapterType<Values["options"], Values["method"], Values["status"], Values["extra"], Values["queryParams"]>> : never;
|
|
1218
|
+
/**
|
|
1219
|
+
* Options
|
|
1220
|
+
*/
|
|
1104
1221
|
type AdapterOptionsType = Partial<XMLHttpRequest>;
|
|
1222
|
+
type AdapterExtraType = {
|
|
1223
|
+
headers: Record<string, string>;
|
|
1224
|
+
};
|
|
1105
1225
|
type AdapterPayloadMappingType = (data: unknown) => string | FormData;
|
|
1106
|
-
type
|
|
1107
|
-
GenericDataType | null
|
|
1108
|
-
GenericErrorType | null
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
type
|
|
1226
|
+
type ResponseReturnType<GenericDataType, GenericErrorType, Adapter extends AdapterInstance> = {
|
|
1227
|
+
data: GenericDataType | null;
|
|
1228
|
+
error: GenericErrorType | null;
|
|
1229
|
+
status: ExtractAdapterStatusType<Adapter> | null;
|
|
1230
|
+
success: boolean;
|
|
1231
|
+
extra: ExtractAdapterExtraType<Adapter> | null;
|
|
1232
|
+
};
|
|
1233
|
+
type ResponseReturnSuccessType<GenericDataType, Adapter extends AdapterInstance> = {
|
|
1234
|
+
data: GenericDataType;
|
|
1235
|
+
error: null;
|
|
1236
|
+
status: ExtractAdapterStatusType<Adapter> | null;
|
|
1237
|
+
success: boolean;
|
|
1238
|
+
extra: ExtractAdapterExtraType<Adapter> | null;
|
|
1239
|
+
};
|
|
1240
|
+
type ResponseReturnErrorType<GenericErrorType, Adapter extends AdapterInstance> = {
|
|
1241
|
+
data: null;
|
|
1242
|
+
error: GenericErrorType;
|
|
1243
|
+
status: ExtractAdapterStatusType<Adapter> | null;
|
|
1244
|
+
success: boolean;
|
|
1245
|
+
extra: ExtractAdapterExtraType<Adapter> | null;
|
|
1246
|
+
};
|
|
1247
|
+
type QueryParamValuesType = number | string | boolean | null | undefined | Record<any, any>;
|
|
1114
1248
|
type QueryParamType = QueryParamValuesType | Array<QueryParamValuesType> | Record<string, QueryParamValuesType>;
|
|
1115
1249
|
type QueryParamsType = Record<string, QueryParamType>;
|
|
1116
1250
|
type HeaderMappingType = <T extends RequestInstance>(request: T) => HeadersInit;
|
|
@@ -1143,6 +1277,14 @@ type QueryStringifyOptionsType = {
|
|
|
1143
1277
|
* Skip keys with empty string
|
|
1144
1278
|
*/
|
|
1145
1279
|
skipEmptyString?: boolean;
|
|
1280
|
+
/**
|
|
1281
|
+
* Parsing function for date type query param
|
|
1282
|
+
*/
|
|
1283
|
+
dateParser?: (value: QueryParamType) => string;
|
|
1284
|
+
/**
|
|
1285
|
+
* Parsing function for object type query param
|
|
1286
|
+
*/
|
|
1287
|
+
objectParser?: (value: QueryParamType) => string;
|
|
1146
1288
|
};
|
|
1147
1289
|
type ProgressDataType = {
|
|
1148
1290
|
total?: number;
|
|
@@ -1156,23 +1298,28 @@ type ProgressType = {
|
|
|
1156
1298
|
loaded: number;
|
|
1157
1299
|
startTimestamp: number;
|
|
1158
1300
|
};
|
|
1301
|
+
type AdapterBindingsReturnType = {
|
|
1302
|
+
fullUrl: string;
|
|
1303
|
+
config: any;
|
|
1304
|
+
};
|
|
1159
1305
|
|
|
1160
1306
|
declare const getErrorMessage: (errorCase?: "timeout" | "abort" | "deleted") => Error;
|
|
1307
|
+
declare const getResponseHeaders: (headersString: string) => Record<string, string>;
|
|
1161
1308
|
declare const parseResponse: (response: string | unknown) => any;
|
|
1162
1309
|
declare const parseErrorResponse: <T extends RequestInstance>(response: unknown) => ExtractErrorType<T>;
|
|
1163
|
-
declare const getUploadSize: (payload:
|
|
1164
|
-
declare const
|
|
1165
|
-
declare const getStreamPayload: (payload: FormData | string | null) => string | Promise<(string | Uint8Array)[]>;
|
|
1310
|
+
declare const getUploadSize: (payload: string) => number;
|
|
1311
|
+
declare const getStreamPayload: (payload: string | null) => string;
|
|
1166
1312
|
|
|
1167
|
-
declare const getAdapterBindings: <
|
|
1313
|
+
declare const getAdapterBindings: <T extends AdapterInstance = AdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterExtraType, string | QueryParamsType>>(req: RequestInstance, requestId: string, systemErrorStatus: ExtractAdapterStatusType<T>, systemErrorExtra: ExtractAdapterExtraType<T>) => Promise<{
|
|
1168
1314
|
fullUrl: string;
|
|
1315
|
+
data: any;
|
|
1169
1316
|
headers: HeadersInit;
|
|
1170
|
-
payload:
|
|
1171
|
-
config:
|
|
1317
|
+
payload: any;
|
|
1318
|
+
config: ExtractAdapterOptionsType<T>;
|
|
1172
1319
|
getAbortController: () => AbortController;
|
|
1173
1320
|
getRequestStartTimestamp: () => number;
|
|
1174
1321
|
getResponseStartTimestamp: () => number;
|
|
1175
|
-
createAbortListener: <T
|
|
1322
|
+
createAbortListener: (status: ExtractAdapterStatusType<T>, abortExtra: ExtractAdapterExtraType<T>, callback: () => void, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => () => void;
|
|
1176
1323
|
onBeforeRequest: () => void;
|
|
1177
1324
|
onRequestStart: (progress?: ProgressDataType) => number;
|
|
1178
1325
|
onRequestProgress: (progress: ProgressDataType) => number;
|
|
@@ -1180,29 +1327,32 @@ declare const getAdapterBindings: <ConfigType = any>(cmd: RequestInstance, reque
|
|
|
1180
1327
|
onResponseStart: (progress?: ProgressDataType) => number;
|
|
1181
1328
|
onResponseProgress: (progress: ProgressDataType) => number;
|
|
1182
1329
|
onResponseEnd: () => number;
|
|
1183
|
-
onSuccess:
|
|
1184
|
-
onAbortError: <
|
|
1185
|
-
onTimeoutError: <
|
|
1186
|
-
onUnexpectedError: <
|
|
1187
|
-
onError:
|
|
1330
|
+
onSuccess: (responseData: any, status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<any, T>) => void) => Promise<ResponseReturnSuccessType<ExtractResponseType<T>, T>>;
|
|
1331
|
+
onAbortError: (status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
1332
|
+
onTimeoutError: (status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
1333
|
+
onUnexpectedError: (status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<ExtractErrorType<T>, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
1334
|
+
onError: (error: any, status: ExtractAdapterStatusType<T>, extra: ExtractAdapterExtraType<T>, resolve: (value: ResponseReturnErrorType<any, T>) => void) => Promise<ResponseReturnErrorType<any, T>>;
|
|
1335
|
+
makeRequest: (apiCall: (resolve: (value: ResponseReturnType<any, any, T> | PromiseLike<ResponseReturnType<any, any, T>>) => void) => void) => Promise<ResponseReturnType<any, any, T>>;
|
|
1188
1336
|
}>;
|
|
1189
1337
|
|
|
1190
1338
|
declare const defaultTimeout: number;
|
|
1191
1339
|
|
|
1192
|
-
type ExtractAdapterReturnType<T extends RequestInstance> =
|
|
1193
|
-
type ExtractResponseType<T> = T extends Request<infer D, any, any, any, any, any, any, any, any, any
|
|
1194
|
-
type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any, any
|
|
1195
|
-
type
|
|
1196
|
-
type ExtractErrorType<T> = T extends Request<any, any, any, infer G, infer L, any, any, any, any, any
|
|
1197
|
-
type ExtractGlobalErrorType<T> = T extends Request<any, any, any, infer E, any, any, any, any, any, any
|
|
1198
|
-
type ExtractLocalErrorType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any, any
|
|
1199
|
-
type ExtractParamsType<T> = T extends Request<any, any, any, any, any, infer P, any, any, any, any
|
|
1200
|
-
type ExtractEndpointType<T> = T extends Request<any, any, any, any, any, infer E, any, any, any, any
|
|
1201
|
-
type
|
|
1202
|
-
type ExtractHasDataType<T> = T extends Request<any, any, any, any, any, any, any, infer D, any, any
|
|
1203
|
-
type ExtractHasParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, infer P, any
|
|
1204
|
-
type ExtractHasQueryParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, any, infer Q
|
|
1205
|
-
|
|
1340
|
+
type ExtractAdapterReturnType<T extends RequestInstance> = ResponseReturnType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>;
|
|
1341
|
+
type ExtractResponseType<T> = T extends Request<infer D, any, any, any, any, any, any, any, any, any> ? D : never;
|
|
1342
|
+
type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any, any> ? D : never;
|
|
1343
|
+
type ExtractRequestQueryParamsType<T> = T extends Request<any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
1344
|
+
type ExtractErrorType<T> = T extends Request<any, any, any, infer G, infer L, any, any, any, any, any> ? G | L : never;
|
|
1345
|
+
type ExtractGlobalErrorType<T> = T extends Request<any, any, any, infer E, any, any, any, any, any, any> ? E : never;
|
|
1346
|
+
type ExtractLocalErrorType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
1347
|
+
type ExtractParamsType<T> = T extends Request<any, any, any, any, any, infer P, any, any, any, any> ? ExtractRouteParams<P> : never;
|
|
1348
|
+
type ExtractEndpointType<T> = T extends Request<any, any, any, any, any, infer E, any, any, any, any> ? E : never;
|
|
1349
|
+
type ExtractAdapterType<T> = T extends Request<any, any, any, any, any, any, infer A, any, any, any> ? A : never;
|
|
1350
|
+
type ExtractHasDataType<T> = T extends Request<any, any, any, any, any, any, any, infer D, any, any> ? D : never;
|
|
1351
|
+
type ExtractHasParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, infer P, any> ? P : never;
|
|
1352
|
+
type ExtractHasQueryParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, any, infer Q> ? Q : never;
|
|
1353
|
+
|
|
1354
|
+
type ExtractClientGlobalError<T> = T extends Client<infer G, any> ? G : never;
|
|
1355
|
+
type ExtractClientAdapterType<T> = T extends Client<any, infer A> ? A : never;
|
|
1206
1356
|
|
|
1207
1357
|
declare class RequestEffect<T extends RequestInstance> {
|
|
1208
1358
|
config: RequestEffectOptionsType<T>;
|
|
@@ -1210,9 +1360,9 @@ declare class RequestEffect<T extends RequestInstance> {
|
|
|
1210
1360
|
getEffectKey: () => string;
|
|
1211
1361
|
onTrigger: (request: T) => void;
|
|
1212
1362
|
onStart: (request: T) => void;
|
|
1213
|
-
onSuccess: (response:
|
|
1214
|
-
onError: (response:
|
|
1215
|
-
onFinished: (response:
|
|
1363
|
+
onSuccess: (response: ResponseReturnSuccessType<ExtractResponseType<T>, ExtractAdapterType<T>>, request: T) => void;
|
|
1364
|
+
onError: (response: ResponseReturnErrorType<ExtractErrorType<T>, ExtractAdapterType<T>>, request: T) => void;
|
|
1365
|
+
onFinished: (response: ResponseReturnType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>, request: T) => void;
|
|
1216
1366
|
}
|
|
1217
1367
|
|
|
1218
1368
|
type RequestEffectLifecycle = "trigger" | "start" | "success" | "error" | "finished";
|
|
@@ -1233,15 +1383,15 @@ type RequestEffectOptionsType<T extends RequestInstance> = {
|
|
|
1233
1383
|
/**
|
|
1234
1384
|
* Callback that will be executed when response is successful
|
|
1235
1385
|
*/
|
|
1236
|
-
onSuccess?: (response:
|
|
1386
|
+
onSuccess?: (response: ResponseReturnSuccessType<ExtractResponseType<T>, ExtractAdapterType<T>>, request: RequestInstance) => void;
|
|
1237
1387
|
/**
|
|
1238
1388
|
* Callback that will be executed when response is failed
|
|
1239
1389
|
*/
|
|
1240
|
-
onError?: (response:
|
|
1390
|
+
onError?: (response: ResponseReturnErrorType<ExtractErrorType<T>, ExtractAdapterType<T>>, request: RequestInstance) => void;
|
|
1241
1391
|
/**
|
|
1242
1392
|
* Callback that will be executed when response is finished
|
|
1243
1393
|
*/
|
|
1244
|
-
onFinished?: (response:
|
|
1394
|
+
onFinished?: (response: ResponseReturnType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>, request: RequestInstance) => void;
|
|
1245
1395
|
};
|
|
1246
1396
|
|
|
1247
1397
|
declare enum DateInterval {
|
|
@@ -1266,4 +1416,4 @@ declare enum HttpMethodsEnum {
|
|
|
1266
1416
|
|
|
1267
1417
|
declare const getUniqueRequestId: (key: string) => string;
|
|
1268
1418
|
|
|
1269
|
-
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,
|
|
1419
|
+
export { AdapterBindingsReturnType, AdapterExtraType, AdapterHeadersProps, AdapterInstance, AdapterOptionsType, AdapterPayloadMappingType, AdapterProgressEventType, AdapterProgressType, AdapterType, AppEvents, AppManager, AppManagerOptionsType, Cache, CacheAsyncStorageType, CacheInitialData, CacheOptionsType, CacheStorageType, CacheValueType, Client, ClientErrorType, ClientInstance, ClientOptionsType, DateInterval, Dispatcher, DispatcherOptionsType, DispatcherRequestType, DispatcherStorageType, ExtractAdapterExtraType, ExtractAdapterMethodType, ExtractAdapterOptionsType, ExtractAdapterQueryParamsType, ExtractAdapterReturnType, ExtractAdapterStatusType, ExtractAdapterType, ExtractAdapterTypeFromClient, ExtractClientAdapterType, ExtractClientGlobalError, ExtractEndpointType, ExtractErrorType, ExtractGlobalErrorType, ExtractHasDataType, ExtractHasParamsType, ExtractHasQueryParamsType, ExtractLocalErrorType, ExtractParamsType, ExtractPayloadType, ExtractRequestQueryParamsType, ExtractResponseType, ExtractRouteParams, ExtractUnionAdapter, FetchOptionsType, FetchParamsType, FetchPayloadType, FetchQueryParamsType, FetchSendActionsType, GeneratorReturnMockTypes, HeaderMappingType, HttpMethodsEnum, HttpMethodsType, HttpStatusType, LogType, LoggerFunctionType, LoggerLevelType, LoggerManager, LoggerMessageType, LoggerOptionsType, LoggerRequestEventData, LoggerResponseEventData, LoggerType, NegativeTypes, NonNullableKeys, NullableKeys, NullableType, ParamType, ParamsType, PayloadMapperType, PayloadType, ProgressDataType, ProgressType, QueryParamType, QueryParamValuesType, QueryParamsType, QueryStringifyOptionsType, QueueDataType, QueueElementType, Request, RequestCurrentType, RequestDataMockTypes, RequestEffect, RequestEffectInstance, RequestEffectLifecycle, RequestEffectOptionsType, RequestEventType, RequestInstance, RequestInterceptorType, RequestJSON, RequestLoadingEventType, RequestManager, RequestMapper, RequestMockType, RequestOptionsType, RequestQueueOptions, RequestRemoveDataType, RequestSendOptionsType, RequestSendType, RequiredKeys, ResponseDetailsType, ResponseInterceptorType, ResponseMapper, ResponseReturnErrorType, ResponseReturnSuccessType, ResponseReturnType, RunningRequestValueType, SeverityType, StringifyCallbackType, adapter, appManagerInitialOptions, canRetryRequest, defaultTimeout, 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, getResponseHeaders, getResponseIdEventKey, getResponseStartEventKey, getResponseStartIdEventKey, getRevalidateEventKey, getSimpleKey, getStreamPayload, getTime, getUniqueRequestId, getUploadProgressEventKey, getUploadProgressIdEventKey, getUploadSize, hasDocument, hasWindow, interceptRequest, interceptResponse, logger, loggerIconLevels, loggerStyles, mocker, onDocumentEvent, onWindowEvent, parseErrorResponse, parseResponse, sendRequest, severity, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue, xhrExtra };
|