@hyper-fetch/core 3.3.4 → 4.0.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.
Files changed (51) hide show
  1. package/dist/browser/index.cjs.js +1 -1
  2. package/dist/browser/index.cjs.js.map +4 -4
  3. package/dist/browser/index.esm.js +1 -1
  4. package/dist/browser/index.esm.js.map +4 -4
  5. package/dist/index.cjs.js +1 -1
  6. package/dist/index.cjs.js.map +4 -4
  7. package/dist/index.d.ts +330 -180
  8. package/dist/index.esm.js +1 -1
  9. package/dist/index.esm.js.map +4 -4
  10. package/package.json +4 -2
  11. package/src/adapter/adapter.bindings.ts +124 -35
  12. package/src/adapter/adapter.browser.ts +29 -24
  13. package/src/adapter/adapter.server.ts +81 -81
  14. package/src/adapter/adapter.ts +1 -6
  15. package/src/adapter/adapter.types.ts +100 -12
  16. package/src/adapter/adapter.utils.ts +16 -23
  17. package/src/cache/cache.events.ts +9 -6
  18. package/src/cache/cache.ts +37 -30
  19. package/src/cache/cache.types.ts +32 -15
  20. package/src/cache/cache.utils.ts +7 -9
  21. package/src/client/client.constants.ts +6 -0
  22. package/src/client/client.ts +130 -59
  23. package/src/client/client.types.ts +11 -10
  24. package/src/client/client.utils.ts +20 -6
  25. package/src/dispatcher/dispatcher.ts +20 -26
  26. package/src/dispatcher/dispatcher.types.ts +4 -4
  27. package/src/dispatcher/dispatcher.utils.ts +2 -11
  28. package/src/effect/request.effect.ts +8 -5
  29. package/src/effect/request.effect.types.ts +14 -5
  30. package/src/index.ts +1 -0
  31. package/src/managers/logger/logger.manager.ts +8 -8
  32. package/src/managers/logger/logger.manager.types.ts +5 -8
  33. package/src/managers/logger/logger.manager.utils.ts +2 -2
  34. package/src/managers/request/request.manager.events.ts +7 -7
  35. package/src/managers/request/request.manager.types.ts +0 -1
  36. package/src/mocker/index.ts +2 -0
  37. package/src/mocker/mocker.ts +96 -0
  38. package/src/mocker/mocker.types.ts +26 -0
  39. package/src/request/request.ts +227 -224
  40. package/src/request/request.types.ts +75 -35
  41. package/src/request/request.utils.ts +61 -28
  42. package/src/types/client.types.ts +4 -0
  43. package/src/types/fetch.types.ts +16 -25
  44. package/src/types/http.types.ts +1 -0
  45. package/src/types/index.ts +1 -0
  46. package/{tsconfig.node.json → tsconfig.base.json} +3 -3
  47. package/tsconfig.json +3 -4
  48. package/dist/server/index.cjs.js +0 -2
  49. package/dist/server/index.cjs.js.map +0 -7
  50. package/dist/server/index.esm.js +0 -2
  51. package/dist/server/index.esm.js.map +0 -7
@@ -1,27 +1,34 @@
1
1
  import {
2
2
  RequestSendOptionsType,
3
3
  ParamsType,
4
- getSimpleKey,
5
- getRequestKey,
6
4
  RequestSendType,
7
5
  PayloadType,
8
- RequestDump,
6
+ RequestJSON,
9
7
  RequestOptionsType,
10
8
  ExtractRouteParams,
11
- requestSendRequest,
9
+ sendRequest,
12
10
  RequestCurrentType,
13
11
  PayloadMapperType,
12
+ RequestInstance,
13
+ RequestMapper,
14
+ ResponseMapper,
14
15
  } from "request";
15
16
  import { Client } from "client";
16
17
  import { getUniqueRequestId } from "utils";
17
- import { QueryParamsType } from "adapter";
18
- import { HttpMethodsType, NegativeTypes } from "types";
18
+ import {
19
+ AdapterType,
20
+ ExtractAdapterMethodType,
21
+ ExtractAdapterOptionsType,
22
+ QueryParamsType,
23
+ AdapterInstance,
24
+ } from "adapter";
25
+ import { NegativeTypes } from "types";
19
26
  import { DateInterval } from "constants/time.constants";
20
- import { HttpMethodsEnum } from "constants/http.constants";
27
+ import { GeneratorReturnMockTypes, RequestDataMockTypes } from "mocker";
21
28
 
22
29
  /**
23
30
  * Fetch request it is designed to prepare the necessary setup to execute the request to the server.
24
- * We can setup basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
31
+ * We can set up basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
25
32
  * :::info Usage
26
33
  * We should not use this class directly in the standard development flow. We can initialize it using the `createRequest` method on the **Client** class.
27
34
  * :::
@@ -33,24 +40,23 @@ import { HttpMethodsEnum } from "constants/http.constants";
33
40
  export class Request<
34
41
  Response,
35
42
  Payload,
36
- QueryParams extends QueryParamsType | string,
43
+ QueryParams,
37
44
  GlobalError, // Global Error Type
38
45
  LocalError, // Additional Error for specific endpoint
39
46
  Endpoint extends string,
40
- AdapterOptions,
47
+ Adapter extends AdapterInstance = AdapterType,
41
48
  HasData extends true | false = false,
42
49
  HasParams extends true | false = false,
43
50
  HasQuery extends true | false = false,
44
- MappedData = undefined,
45
51
  > {
46
52
  endpoint: Endpoint;
47
53
  headers?: HeadersInit;
48
54
  auth: boolean;
49
- method: HttpMethodsType;
55
+ method: ExtractAdapterMethodType<Adapter>;
50
56
  params: ExtractRouteParams<Endpoint> | NegativeTypes;
51
- data: PayloadType<Payload, MappedData>;
57
+ data: PayloadType<Payload>;
52
58
  queryParams: QueryParams | NegativeTypes;
53
- options?: AdapterOptions | undefined;
59
+ options?: ExtractAdapterOptionsType<Adapter> | undefined;
54
60
  cancelable: boolean;
55
61
  retry: number;
56
62
  retryTime: number;
@@ -66,6 +72,15 @@ export class Request<
66
72
  used: boolean;
67
73
  deduplicate: boolean;
68
74
  deduplicateTime: number;
75
+ dataMapper?: PayloadMapperType<Payload>;
76
+ mock?: Generator<
77
+ GeneratorReturnMockTypes<Response, this>,
78
+ GeneratorReturnMockTypes<Response, this>,
79
+ GeneratorReturnMockTypes<Response, this>
80
+ >;
81
+ mockData?: RequestDataMockTypes<Response, this>;
82
+ requestMapper?: RequestMapper<this, any>;
83
+ responseMapper?: ResponseMapper<this, any, any>;
69
84
 
70
85
  private updatedAbortKey: boolean;
71
86
  private updatedCacheKey: boolean;
@@ -73,26 +88,27 @@ export class Request<
73
88
  private updatedEffectKey: boolean;
74
89
 
75
90
  constructor(
76
- readonly client: Client<GlobalError, AdapterOptions>,
77
- readonly requestOptions: RequestOptionsType<Endpoint, AdapterOptions>,
78
- readonly requestDump?:
91
+ readonly client: Client<GlobalError, Adapter>,
92
+ readonly requestOptions: RequestOptionsType<
93
+ Endpoint,
94
+ ExtractAdapterOptionsType<Adapter>,
95
+ ExtractAdapterMethodType<Adapter>
96
+ >,
97
+ readonly requestJSON?:
79
98
  | RequestCurrentType<
80
- Response,
81
99
  Payload,
82
100
  QueryParams,
83
- GlobalError | LocalError,
84
101
  Endpoint,
85
- AdapterOptions,
86
- MappedData
102
+ ExtractAdapterOptionsType<Adapter>,
103
+ ExtractAdapterMethodType<Adapter>
87
104
  >
88
105
  | undefined,
89
- readonly dataMapper?: PayloadMapperType<Payload, MappedData>,
90
106
  ) {
91
107
  const {
92
108
  endpoint,
93
109
  headers,
94
110
  auth = true,
95
- method = HttpMethodsEnum.get,
111
+ method = client.defaultMethod,
96
112
  options,
97
113
  cancelable = false,
98
114
  retry = 0,
@@ -110,34 +126,34 @@ export class Request<
110
126
  deduplicateTime = 10,
111
127
  } = { ...this.client.requestDefaultOptions?.(requestOptions), ...requestOptions };
112
128
 
113
- this.endpoint = requestDump?.endpoint ?? endpoint;
114
- this.headers = requestDump?.headers ?? headers;
115
- this.auth = requestDump?.auth ?? auth;
129
+ this.endpoint = requestJSON?.endpoint ?? endpoint;
130
+ this.headers = requestJSON?.headers ?? headers;
131
+ this.auth = requestJSON?.auth ?? auth;
116
132
  this.method = method;
117
- this.params = requestDump?.params;
118
- this.data = requestDump?.data;
119
- this.queryParams = requestDump?.queryParams;
120
- this.options = requestDump?.options ?? options;
121
- this.cancelable = requestDump?.cancelable ?? cancelable;
122
- this.retry = requestDump?.retry ?? retry;
123
- this.retryTime = requestDump?.retryTime ?? retryTime;
124
- this.garbageCollection = requestDump?.garbageCollection ?? garbageCollection;
125
- this.cache = requestDump?.cache ?? cache;
126
- this.cacheTime = requestDump?.cacheTime ?? cacheTime;
127
- this.queued = requestDump?.queued ?? queued;
128
- this.offline = requestDump?.offline ?? offline;
129
- this.abortKey = requestDump?.abortKey ?? abortKey ?? getSimpleKey(this);
130
- this.cacheKey = requestDump?.cacheKey ?? cacheKey ?? getRequestKey(this);
131
- this.queueKey = requestDump?.queueKey ?? queueKey ?? getSimpleKey(this);
132
- this.effectKey = requestDump?.effectKey ?? effectKey ?? getSimpleKey(this);
133
- this.used = requestDump?.used ?? false;
134
- this.deduplicate = requestDump?.deduplicate ?? deduplicate;
135
- this.deduplicateTime = requestDump?.deduplicateTime ?? deduplicateTime;
136
-
137
- this.updatedAbortKey = requestDump?.updatedAbortKey ?? false;
138
- this.updatedCacheKey = requestDump?.updatedCacheKey ?? false;
139
- this.updatedQueueKey = requestDump?.updatedQueueKey ?? false;
140
- this.updatedEffectKey = requestDump?.updatedEffectKey ?? false;
133
+ this.params = requestJSON?.params;
134
+ this.data = requestJSON?.data;
135
+ this.queryParams = requestJSON?.queryParams;
136
+ this.options = requestJSON?.options ?? options;
137
+ this.cancelable = requestJSON?.cancelable ?? cancelable;
138
+ this.retry = requestJSON?.retry ?? retry;
139
+ this.retryTime = requestJSON?.retryTime ?? retryTime;
140
+ this.garbageCollection = requestJSON?.garbageCollection ?? garbageCollection;
141
+ this.cache = requestJSON?.cache ?? cache;
142
+ this.cacheTime = requestJSON?.cacheTime ?? cacheTime;
143
+ this.queued = requestJSON?.queued ?? queued;
144
+ this.offline = requestJSON?.offline ?? offline;
145
+ this.abortKey = requestJSON?.abortKey ?? abortKey ?? this.client.abortKeyMapper(this);
146
+ this.cacheKey = requestJSON?.cacheKey ?? cacheKey ?? this.client.cacheKeyMapper(this);
147
+ this.queueKey = requestJSON?.queueKey ?? queueKey ?? this.client.queueKeyMapper(this);
148
+ this.effectKey = requestJSON?.effectKey ?? effectKey ?? this.client.effectKeyMapper(this);
149
+ this.used = requestJSON?.used ?? false;
150
+ this.deduplicate = requestJSON?.deduplicate ?? deduplicate;
151
+ this.deduplicateTime = requestJSON?.deduplicateTime ?? deduplicateTime;
152
+
153
+ this.updatedAbortKey = requestJSON?.updatedAbortKey ?? false;
154
+ this.updatedCacheKey = requestJSON?.updatedCacheKey ?? false;
155
+ this.updatedQueueKey = requestJSON?.updatedQueueKey ?? false;
156
+ this.updatedEffectKey = requestJSON?.updatedEffectKey ?? false;
141
157
  }
142
158
 
143
159
  public setHeaders = (headers: HeadersInit) => {
@@ -153,9 +169,8 @@ export class Request<
153
169
  };
154
170
 
155
171
  public setData = <D extends Payload>(data: D) => {
156
- const modifiedData = this.dataMapper?.(data) || data;
157
- return this.clone<D extends null ? false : true, HasParams, HasQuery, MappedData>({
158
- data: modifiedData as PayloadType<Payload, MappedData>,
172
+ return this.clone<D extends null ? false : true, HasParams, HasQuery>({
173
+ data,
159
174
  });
160
175
  };
161
176
 
@@ -163,7 +178,7 @@ export class Request<
163
178
  return this.clone<HasData, HasParams, true>({ queryParams });
164
179
  };
165
180
 
166
- public setOptions = (options: AdapterOptions) => {
181
+ public setOptions = (options: ExtractAdapterOptionsType<Adapter>) => {
167
182
  return this.clone<HasData, HasParams, true>({ options });
168
183
  };
169
184
 
@@ -171,25 +186,45 @@ export class Request<
171
186
  return this.clone({ cancelable });
172
187
  };
173
188
 
174
- public setRetry = (retry: RequestOptionsType<Endpoint, AdapterOptions>["retry"]) => {
189
+ public setRetry = (
190
+ retry: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["retry"],
191
+ ) => {
175
192
  return this.clone({ retry });
176
193
  };
177
194
 
178
- public setRetryTime = (retryTime: RequestOptionsType<Endpoint, AdapterOptions>["retryTime"]) => {
195
+ public setRetryTime = (
196
+ retryTime: RequestOptionsType<
197
+ Endpoint,
198
+ ExtractAdapterOptionsType<Adapter>,
199
+ ExtractAdapterMethodType<Adapter>
200
+ >["retryTime"],
201
+ ) => {
179
202
  return this.clone({ retryTime });
180
203
  };
181
204
 
182
205
  public setGarbageCollection = (
183
- garbageCollection: RequestOptionsType<Endpoint, AdapterOptions>["garbageCollection"],
206
+ garbageCollection: RequestOptionsType<
207
+ Endpoint,
208
+ ExtractAdapterOptionsType<Adapter>,
209
+ ExtractAdapterMethodType<Adapter>
210
+ >["garbageCollection"],
184
211
  ) => {
185
212
  return this.clone({ garbageCollection });
186
213
  };
187
214
 
188
- public setCache = (cache: RequestOptionsType<Endpoint, AdapterOptions>["cache"]) => {
215
+ public setCache = (
216
+ cache: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>["cache"],
217
+ ) => {
189
218
  return this.clone({ cache });
190
219
  };
191
220
 
192
- public setCacheTime = (cacheTime: RequestOptionsType<Endpoint, AdapterOptions>["cacheTime"]) => {
221
+ public setCacheTime = (
222
+ cacheTime: RequestOptionsType<
223
+ Endpoint,
224
+ ExtractAdapterOptionsType<Adapter>,
225
+ ExtractAdapterMethodType<Adapter>
226
+ >["cacheTime"],
227
+ ) => {
193
228
  return this.clone({ cacheTime });
194
229
  };
195
230
 
@@ -233,8 +268,86 @@ export class Request<
233
268
  return this.clone({ offline });
234
269
  };
235
270
 
236
- public setDataMapper = <DataMapper extends (data: Payload) => any>(mapper: DataMapper) => {
237
- return this.clone<HasData, HasParams, HasQuery>(undefined, mapper);
271
+ public setMock = (mockData: RequestDataMockTypes<Response, this>) => {
272
+ const mockGenerator = function* mocked(mockedValues: RequestDataMockTypes<Response, RequestInstance>) {
273
+ if (Array.isArray(mockData)) {
274
+ let iteration = 0;
275
+ // eslint-disable-next-line no-restricted-syntax
276
+ while (true) {
277
+ yield mockedValues[iteration];
278
+ iteration = mockData.length === iteration + 1 ? 0 : iteration + 1;
279
+ }
280
+ } else {
281
+ while (true) {
282
+ yield mockData;
283
+ }
284
+ }
285
+ };
286
+ this.mockData = mockData;
287
+ this.mock = mockGenerator(mockData);
288
+ return this;
289
+ };
290
+
291
+ public removeMock = () => {
292
+ this.mockData = null;
293
+ this.mock = null;
294
+ return this;
295
+ };
296
+
297
+ /**
298
+ * Mappers
299
+ */
300
+
301
+ /**
302
+ * Map data before it gets send to the server
303
+ * @param dataMapper
304
+ * @returns
305
+ */
306
+ public setDataMapper = <DataMapper extends (data: Payload) => any | Promise<any>>(dataMapper: DataMapper) => {
307
+ const cloned = this.clone<HasData, HasParams, HasQuery>(undefined);
308
+
309
+ cloned.dataMapper = dataMapper;
310
+
311
+ return cloned;
312
+ };
313
+
314
+ /**
315
+ * Map request before it gets send to the server
316
+ * @param requestMapper mapper of the request
317
+ * @returns new request
318
+ */
319
+ public setRequestMapper = <NewRequest extends RequestInstance>(requestMapper: RequestMapper<this, NewRequest>) => {
320
+ const cloned = this.clone<HasData, HasParams, HasQuery>(undefined);
321
+
322
+ cloned.requestMapper = requestMapper;
323
+
324
+ return cloned;
325
+ };
326
+
327
+ /**
328
+ * Map the response to the new interface
329
+ * @param responseMapper our mapping callback
330
+ * @returns new response
331
+ */
332
+ public setResponseMapper = <NewResponse = Response, NewError = GlobalError | LocalError>(
333
+ responseMapper?: ResponseMapper<this, NewResponse, NewError>,
334
+ ) => {
335
+ const cloned = this.clone<HasData, HasParams, HasQuery>();
336
+
337
+ cloned.responseMapper = responseMapper;
338
+
339
+ return cloned as unknown as Request<
340
+ NewResponse,
341
+ Payload,
342
+ QueryParams,
343
+ GlobalError,
344
+ LocalError,
345
+ Endpoint,
346
+ Adapter,
347
+ HasData,
348
+ HasParams,
349
+ HasQuery
350
+ >;
238
351
  };
239
352
 
240
353
  private paramsMapper = (params: ParamsType | null | undefined, queryParams: QueryParams | NegativeTypes): string => {
@@ -245,36 +358,20 @@ export class Request<
245
358
  });
246
359
  }
247
360
  if (queryParams) {
248
- endpoint += this.client.stringifyQueryParams(queryParams);
361
+ endpoint += this.client.stringifyQueryParams(queryParams as unknown as QueryParamsType);
249
362
  }
250
363
  return endpoint;
251
364
  };
252
365
 
253
- public dump(): RequestDump<
254
- Request<
255
- Response,
256
- Payload,
257
- QueryParams,
258
- GlobalError,
259
- LocalError,
260
- Endpoint,
261
- AdapterOptions,
262
- HasData,
263
- HasParams,
264
- HasQuery,
265
- MappedData
266
- >,
267
- AdapterOptions,
268
- QueryParams
269
- > {
366
+ public toJSON(): RequestJSON<this, ExtractAdapterOptionsType<Adapter>, QueryParams> {
270
367
  return {
271
368
  requestOptions: this.requestOptions,
272
369
  endpoint: this.endpoint,
273
370
  headers: this.headers,
274
371
  auth: this.auth,
275
372
  method: this.method,
276
- params: this.params,
277
- data: this.data,
373
+ params: this.params as any,
374
+ data: this.data as any,
278
375
  queryParams: this.queryParams,
279
376
  options: this.options,
280
377
  cancelable: this.cancelable,
@@ -301,46 +398,24 @@ export class Request<
301
398
  };
302
399
  }
303
400
 
304
- public clone<
305
- D extends true | false = HasData,
306
- P extends true | false = HasParams,
307
- Q extends true | false = HasQuery,
308
- NewMappedData = MappedData,
309
- >(
401
+ public clone<D extends true | false = HasData, P extends true | false = HasParams, Q extends true | false = HasQuery>(
310
402
  options?: RequestCurrentType<
311
- Response,
312
403
  Payload,
313
404
  QueryParams,
314
- GlobalError | LocalError,
315
405
  Endpoint,
316
- AdapterOptions,
317
- NewMappedData
406
+ ExtractAdapterOptionsType<Adapter>,
407
+ ExtractAdapterMethodType<Adapter>
318
408
  >,
319
- mapper?: PayloadMapperType<Payload, NewMappedData>,
320
- ): Request<
321
- Response,
322
- Payload,
323
- QueryParams,
324
- GlobalError,
325
- LocalError,
326
- Endpoint,
327
- AdapterOptions,
328
- D,
329
- P,
330
- Q,
331
- NewMappedData
332
- > {
333
- const dump = this.dump();
334
- const requestDump: RequestCurrentType<
335
- Response,
409
+ ): Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, D, P, Q> {
410
+ const json = this.toJSON();
411
+ const requestJSON: RequestCurrentType<
336
412
  Payload,
337
413
  QueryParams,
338
- GlobalError | LocalError,
339
414
  Endpoint,
340
- AdapterOptions,
341
- NewMappedData
415
+ ExtractAdapterOptionsType<Adapter>,
416
+ ExtractAdapterMethodType<Adapter>
342
417
  > = {
343
- ...dump,
418
+ ...json,
344
419
  ...options,
345
420
  abortKey: this.updatedAbortKey ? options?.abortKey || this.abortKey : undefined,
346
421
  cacheKey: this.updatedCacheKey ? options?.cacheKey || this.cacheKey : undefined,
@@ -351,21 +426,19 @@ export class Request<
351
426
  data: (options?.data || this.data) as any,
352
427
  };
353
428
 
354
- const mapperFn = (mapper || this.dataMapper) as typeof mapper;
429
+ const cloned = new Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, D, P, Q>(
430
+ this.client,
431
+ this.requestOptions,
432
+ requestJSON,
433
+ );
355
434
 
356
- const cloned = new Request<
357
- Response,
358
- Payload,
359
- QueryParams,
360
- GlobalError,
361
- LocalError,
362
- Endpoint,
363
- AdapterOptions,
364
- D,
365
- P,
366
- Q,
367
- NewMappedData
368
- >(this.client, this.requestOptions, requestDump, mapperFn);
435
+ // Inherit methods
436
+ cloned.dataMapper = this.dataMapper;
437
+ cloned.responseMapper = this.responseMapper;
438
+ cloned.requestMapper = this.requestMapper;
439
+
440
+ cloned.mockData = this.mockData;
441
+ cloned.mock = this.mock;
369
442
 
370
443
  return cloned;
371
444
  }
@@ -386,39 +459,9 @@ export class Request<
386
459
  * Promise<[Data | null, Error | null, HttpStatus]>
387
460
  * ```
388
461
  */
389
- public exec: RequestSendType<
390
- Request<
391
- Response,
392
- Payload,
393
- QueryParams,
394
- GlobalError,
395
- LocalError,
396
- Endpoint,
397
- AdapterOptions,
398
- HasData,
399
- HasParams,
400
- HasQuery,
401
- MappedData
402
- >
403
- > = async (
404
- options?: RequestSendOptionsType<
405
- Request<
406
- Response,
407
- Payload,
408
- QueryParams,
409
- GlobalError,
410
- LocalError,
411
- Endpoint,
412
- AdapterOptions,
413
- HasData,
414
- HasParams,
415
- HasQuery,
416
- MappedData
417
- >
418
- >,
419
- ) => {
462
+ public exec: RequestSendType<this> = async (options?: RequestSendOptionsType<this>) => {
420
463
  const { adapter, requestManager } = this.client;
421
- const request = this.clone(options as any);
464
+ const request = this.clone(options as any) as this;
422
465
 
423
466
  const requestId = getUniqueRequestId(this.queueKey);
424
467
 
@@ -430,6 +473,10 @@ export class Request<
430
473
  // Stop listening for aborting
431
474
  requestManager.removeAbortController(this.abortKey, requestId);
432
475
 
476
+ if (request.responseMapper) {
477
+ return request.responseMapper(response);
478
+ }
479
+
433
480
  return response;
434
481
  };
435
482
 
@@ -443,86 +490,42 @@ export class Request<
443
490
  * Promise<[Data | null, Error | null, HttpStatus]>
444
491
  * ```
445
492
  */
446
- public send: RequestSendType<
447
- Request<
448
- Response,
449
- Payload,
450
- QueryParams,
451
- GlobalError,
452
- LocalError,
453
- Endpoint,
454
- AdapterOptions,
455
- HasData,
456
- HasParams,
457
- HasQuery,
458
- MappedData
459
- >
460
- > = async (
461
- options?: RequestSendOptionsType<
462
- Request<
463
- Response,
464
- Payload,
465
- QueryParams,
466
- GlobalError,
467
- LocalError,
468
- Endpoint,
469
- AdapterOptions,
470
- HasData,
471
- HasParams,
472
- HasQuery,
473
- MappedData
474
- >
475
- >,
476
- ) => {
493
+ public send: RequestSendType<this> = async (options?: RequestSendOptionsType<this>) => {
477
494
  const { dispatcherType, ...rest } = options || {};
478
495
 
479
- const request = this.clone(rest as any);
480
- return requestSendRequest<
481
- Request<
482
- Response,
483
- Payload,
484
- QueryParams,
485
- GlobalError,
486
- LocalError,
487
- Endpoint,
488
- AdapterOptions,
489
- HasData,
490
- HasParams,
491
- HasQuery,
492
- MappedData
493
- >
494
- >(request, options);
496
+ const request = this.clone(rest as any) as any;
497
+ return sendRequest<this>(request, options);
495
498
  };
496
499
  }
497
500
 
498
501
  // /**
499
502
  // * Typescript test cases
500
503
  // */
501
-
504
+ //
502
505
  // const client = new Client({
503
506
  // url: "http://localhost:3000",
504
507
  // });
505
-
508
+ //
506
509
  // const getUsers = client.createRequest<{ id: string }[]>()({
507
510
  // method: "GET",
508
511
  // endpoint: "/users",
509
512
  // });
510
-
513
+ //
511
514
  // const getUser = client.createRequest<{ id: string }>()({
512
515
  // method: "GET",
513
516
  // endpoint: "/users/:id",
514
517
  // });
515
-
518
+ //
516
519
  // const postUser = client.createRequest<{ id: string }, { name: string }>()({
517
520
  // method: "POST",
518
521
  // endpoint: "/users",
519
522
  // });
520
-
523
+ //
521
524
  // const patchUser = client.createRequest<{ id: string }, { name: string }>()({
522
525
  // method: "PATCH",
523
526
  // endpoint: "/users/:id",
524
527
  // });
525
-
528
+ //
526
529
  // const mappedReq = client
527
530
  // .createRequest<{ id: string }, { name: string }>()({
528
531
  // method: "POST",
@@ -533,9 +536,9 @@ export class Request<
533
536
  // formData.append("key", data.name);
534
537
  // return formData;
535
538
  // });
536
-
539
+ //
537
540
  // // ================>
538
-
541
+ //
539
542
  // // OK
540
543
  // getUsers.send({ queryParams: "" });
541
544
  // getUsers.setQueryParams("").send();
@@ -543,9 +546,9 @@ export class Request<
543
546
  // getUsers.send({ data: "" });
544
547
  // getUsers.send({ params: "" });
545
548
  // getUsers.setQueryParams("").send({ queryParams: "" });
546
-
549
+ //
547
550
  // // ================>
548
-
551
+ //
549
552
  // // OK
550
553
  // getUser.send({ params: { id: "" }, queryParams: "" });
551
554
  // getUser.setParams({ id: "" }).send({ queryParams: "" });
@@ -554,22 +557,22 @@ export class Request<
554
557
  // getUser.send();
555
558
  // getUser.setParams({ id: "" }).send({ params: { id: "" } });
556
559
  // getUser.setParams(null).send();
557
- // getUser.send({ params: { id: null } });
558
-
560
+ // getUser.send({ params: { id: null } }); // <----- Should fail
561
+ //
559
562
  // // ================>
560
-
563
+ //
561
564
  // // OK
562
565
  // postUser.send({ data: { name: "" } });
563
566
  // postUser.setData({ name: "" }).send();
564
567
  // // Fail
565
568
  // postUser.send({ queryParams: "" });
566
- // postUser.send({ data: null });
569
+ // postUser.send({ data: null }); // <------ Should fail
567
570
  // postUser.setData(null).send();
568
571
  // postUser.send();
569
572
  // postUser.setData({ name: "" }).send({ data: { name: "" } });
570
-
573
+ //
571
574
  // // ================>
572
-
575
+ //
573
576
  // // OK
574
577
  // patchUser.send({ params: { id: "" }, data: { name: "" } });
575
578
  // patchUser.setParams({ id: "" }).setData({ name: "" }).send();
@@ -586,15 +589,15 @@ export class Request<
586
589
  // .setParams({ id: "" })
587
590
  // .setData({ name: "" })
588
591
  // .send({ params: { id: "" } });
589
-
592
+ //
590
593
  // // ================>
591
-
594
+ //
592
595
  // // OK
593
596
  // mappedReq.send({ data: { name: "" } });
594
597
  // mappedReq.setData({ name: "" }).send();
595
598
  // // Fail
596
599
  // mappedReq.send({ queryParams: "" });
597
- // mappedReq.send({ data: undefined });
600
+ // mappedReq.send({ data: undefined }); // <---- should fail
598
601
  // mappedReq.setData(null).send();
599
602
  // mappedReq.setData(null).send({ data: null, queryParams: () => null });
600
603
  // mappedReq.send();