@hyper-fetch/core 2.0.0 → 3.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.
Files changed (109) hide show
  1. package/README.md +14 -13
  2. package/dist/adapter/adapter.bindings.d.ts +25 -0
  3. package/dist/adapter/adapter.browser.d.ts +2 -0
  4. package/dist/{client/fetch.client.constants.d.ts → adapter/adapter.constants.d.ts} +0 -0
  5. package/dist/adapter/adapter.d.ts +2 -0
  6. package/dist/adapter/adapter.server.d.ts +2 -0
  7. package/dist/adapter/adapter.types.d.ts +57 -0
  8. package/dist/{client/fetch.client.utils.d.ts → adapter/adapter.utils.d.ts} +3 -3
  9. package/dist/adapter/index.d.ts +7 -0
  10. package/dist/cache/cache.d.ts +9 -9
  11. package/dist/cache/cache.types.d.ts +4 -4
  12. package/dist/cache/cache.utils.d.ts +3 -3
  13. package/dist/{builder/builder.constants.d.ts → client/client.constants.d.ts} +0 -0
  14. package/dist/client/client.d.ts +142 -0
  15. package/dist/client/client.types.d.ts +41 -0
  16. package/dist/client/client.utils.d.ts +10 -0
  17. package/dist/client/index.d.ts +4 -6
  18. package/dist/dispatcher/dispatcher.d.ts +23 -23
  19. package/dist/dispatcher/dispatcher.events.d.ts +8 -8
  20. package/dist/dispatcher/dispatcher.types.d.ts +10 -10
  21. package/dist/dispatcher/dispatcher.utils.d.ts +5 -5
  22. package/dist/effect/index.d.ts +2 -2
  23. package/dist/effect/request.effect.d.ts +14 -0
  24. package/dist/effect/request.effect.types.d.ts +32 -0
  25. package/dist/index.cjs.js +1 -1
  26. package/dist/index.cjs.js.map +4 -4
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.esm.js +1 -1
  29. package/dist/index.esm.js.map +4 -4
  30. package/dist/managers/index.d.ts +1 -1
  31. package/dist/managers/logger/logger.manager.d.ts +5 -5
  32. package/dist/managers/logger/logger.manager.types.d.ts +7 -7
  33. package/dist/managers/request/index.d.ts +4 -0
  34. package/dist/managers/request/request.manager.d.ts +43 -0
  35. package/dist/managers/request/request.manager.events.d.ts +36 -0
  36. package/dist/managers/{command/command.manager.types.d.ts → request/request.manager.types.d.ts} +6 -6
  37. package/dist/managers/{command/command.manager.utils.d.ts → request/request.manager.utils.d.ts} +0 -0
  38. package/dist/request/index.d.ts +3 -0
  39. package/dist/request/request.d.ts +98 -0
  40. package/dist/request/request.types.d.ts +202 -0
  41. package/dist/request/request.utils.d.ts +22 -0
  42. package/dist/types/fetch.types.d.ts +16 -16
  43. package/package.json +1 -1
  44. package/src/{client/fetch.client.bindings.ts → adapter/adapter.bindings.ts} +58 -58
  45. package/src/{client/fetch.client.browser.ts → adapter/adapter.browser.ts} +6 -6
  46. package/src/{client/fetch.client.constants.ts → adapter/adapter.constants.ts} +0 -0
  47. package/src/{client/fetch.client.server.ts → adapter/adapter.server.ts} +12 -12
  48. package/src/adapter/adapter.ts +8 -0
  49. package/src/adapter/adapter.types.ts +79 -0
  50. package/src/{client/fetch.client.utils.ts → adapter/adapter.utils.ts} +3 -3
  51. package/src/adapter/index.ts +7 -0
  52. package/src/cache/cache.ts +19 -19
  53. package/src/cache/cache.types.ts +4 -4
  54. package/src/cache/cache.utils.ts +6 -6
  55. package/src/{builder/builder.constants.ts → client/client.constants.ts} +0 -0
  56. package/src/client/client.ts +310 -0
  57. package/src/client/client.types.ts +52 -0
  58. package/src/{builder/builder.utils.ts → client/client.utils.ts} +34 -31
  59. package/src/client/index.ts +4 -6
  60. package/src/dispatcher/dispatcher.events.ts +11 -11
  61. package/src/dispatcher/dispatcher.ts +68 -68
  62. package/src/dispatcher/dispatcher.types.ts +10 -10
  63. package/src/dispatcher/dispatcher.utils.ts +7 -7
  64. package/src/effect/index.ts +2 -2
  65. package/src/effect/request.effect.ts +28 -0
  66. package/src/effect/request.effect.types.ts +35 -0
  67. package/src/index.ts +4 -4
  68. package/src/managers/index.ts +1 -1
  69. package/src/managers/logger/logger.manager.ts +8 -8
  70. package/src/managers/logger/logger.manager.types.ts +7 -7
  71. package/src/managers/request/index.ts +4 -0
  72. package/src/managers/{command/command.manager.events.ts → request/request.manager.events.ts} +47 -51
  73. package/src/managers/{command/command.manager.ts → request/request.manager.ts} +5 -5
  74. package/src/managers/request/request.manager.types.ts +25 -0
  75. package/src/managers/{command/command.manager.utils.ts → request/request.manager.utils.ts} +0 -0
  76. package/src/request/index.ts +3 -0
  77. package/src/{command/command.ts → request/request.ts} +188 -194
  78. package/src/request/request.types.ts +282 -0
  79. package/src/{command/command.utils.ts → request/request.utils.ts} +56 -53
  80. package/src/types/fetch.types.ts +18 -18
  81. package/dist/builder/builder.d.ts +0 -141
  82. package/dist/builder/builder.types.d.ts +0 -41
  83. package/dist/builder/builder.utils.d.ts +0 -10
  84. package/dist/builder/index.d.ts +0 -4
  85. package/dist/client/fetch.client.bindings.d.ts +0 -25
  86. package/dist/client/fetch.client.browser.d.ts +0 -2
  87. package/dist/client/fetch.client.d.ts +0 -2
  88. package/dist/client/fetch.client.server.d.ts +0 -2
  89. package/dist/client/fetch.client.types.d.ts +0 -57
  90. package/dist/command/command.d.ts +0 -98
  91. package/dist/command/command.types.d.ts +0 -202
  92. package/dist/command/command.utils.d.ts +0 -22
  93. package/dist/command/index.d.ts +0 -3
  94. package/dist/effect/fetch.effect.d.ts +0 -14
  95. package/dist/effect/fetch.effect.types.d.ts +0 -32
  96. package/dist/managers/command/command.manager.d.ts +0 -43
  97. package/dist/managers/command/command.manager.events.d.ts +0 -36
  98. package/dist/managers/command/index.d.ts +0 -4
  99. package/src/builder/builder.ts +0 -308
  100. package/src/builder/builder.types.ts +0 -53
  101. package/src/builder/index.ts +0 -4
  102. package/src/client/fetch.client.ts +0 -9
  103. package/src/client/fetch.client.types.ts +0 -83
  104. package/src/command/command.types.ts +0 -273
  105. package/src/command/index.ts +0 -3
  106. package/src/effect/fetch.effect.ts +0 -28
  107. package/src/effect/fetch.effect.types.ts +0 -35
  108. package/src/managers/command/command.manager.types.ts +0 -25
  109. package/src/managers/command/index.ts +0 -4
@@ -0,0 +1,282 @@
1
+ import {
2
+ NullableKeys,
3
+ NegativeTypes,
4
+ ExtractParamsType,
5
+ ExtractPayloadType,
6
+ HttpMethodsType,
7
+ ExtractQueryParamsType,
8
+ ExtractAdapterOptionsType,
9
+ ExtractEndpointType,
10
+ ExtractHasDataType,
11
+ ExtractHasParamsType,
12
+ ExtractHasQueryParamsType,
13
+ ExtractErrorType,
14
+ ExtractResponseType,
15
+ } from "types";
16
+ import { Request } from "request";
17
+ import { ResponseType, QueryParamsType, ProgressType } from "adapter";
18
+ import { RequestEventType, ResponseDetailsType } from "managers";
19
+
20
+ // Progress
21
+ export type AdapterProgressEventType = { total: number; loaded: number };
22
+ export type AdapterProgressType = {
23
+ progress: number;
24
+ timeLeft: number;
25
+ sizeLeft: number;
26
+ };
27
+
28
+ // Dump
29
+
30
+ /**
31
+ * Dump of the request used to later recreate it
32
+ */
33
+ export type RequestDump<
34
+ Request extends RequestInstance,
35
+ // Bellow generics provided only to overcome the typescript bugs
36
+ AdapterOptions = unknown,
37
+ QueryParams = QueryParamsType,
38
+ Params = ExtractParamsType<Request>,
39
+ > = {
40
+ requestOptions: RequestOptionsType<string, AdapterOptions | ExtractAdapterOptionsType<Request>>;
41
+ endpoint: string;
42
+ method: HttpMethodsType;
43
+ headers?: HeadersInit;
44
+ auth: boolean;
45
+ cancelable: boolean;
46
+ retry: number;
47
+ retryTime: number;
48
+ garbageCollection: number;
49
+ cache: boolean;
50
+ cacheTime: number;
51
+ queued: boolean;
52
+ offline: boolean;
53
+ disableResponseInterceptors: boolean | undefined;
54
+ disableRequestInterceptors: boolean | undefined;
55
+ options?: AdapterOptions | ExtractAdapterOptionsType<Request>;
56
+ data: PayloadType<ExtractPayloadType<Request>, unknown>;
57
+ params: Params | NegativeTypes;
58
+ queryParams: QueryParams | NegativeTypes;
59
+ abortKey: string;
60
+ cacheKey: string;
61
+ queueKey: string;
62
+ effectKey: string;
63
+ used: boolean;
64
+ updatedAbortKey: boolean;
65
+ updatedCacheKey: boolean;
66
+ updatedQueueKey: boolean;
67
+ updatedEffectKey: boolean;
68
+ deduplicate: boolean;
69
+ deduplicateTime: number;
70
+ };
71
+
72
+ // Request
73
+
74
+ /**
75
+ * Configuration options for request creation
76
+ */
77
+ export type RequestOptionsType<GenericEndpoint extends string, AdapterOptions> = {
78
+ /**
79
+ * Determine the endpoint for request request
80
+ */
81
+ endpoint: GenericEndpoint;
82
+ /**
83
+ * Custom headers for request
84
+ */
85
+ headers?: HeadersInit;
86
+ /**
87
+ * Should the onAuth method get called on this request
88
+ */
89
+ auth?: boolean;
90
+ /**
91
+ * Request method GET | POST | PATCH | PUT | DELETE
92
+ */
93
+ method?: HttpMethodsType;
94
+ /**
95
+ * Should enable cancelable mode in the Dispatcher
96
+ */
97
+ cancelable?: boolean;
98
+ /**
99
+ * Retry count when request is failed
100
+ */
101
+ retry?: number;
102
+ /**
103
+ * Retry time delay between retries
104
+ */
105
+ retryTime?: number;
106
+ /**
107
+ * Should we trigger garbage collection or leave data in memory
108
+ */
109
+ garbageCollection?: number;
110
+ /**
111
+ * Should we save the response to cache
112
+ */
113
+ cache?: boolean;
114
+ /**
115
+ * Time for which the cache is considered up-to-date
116
+ */
117
+ cacheTime?: number;
118
+ /**
119
+ * Should the requests from this request be send one-by-one
120
+ */
121
+ queued?: boolean;
122
+ /**
123
+ * Do we want to store request made in offline mode for latter use when we go back online
124
+ */
125
+ offline?: boolean;
126
+ /**
127
+ * Disable post-request interceptors
128
+ */
129
+ disableResponseInterceptors?: boolean;
130
+ /**
131
+ * Disable pre-request interceptors
132
+ */
133
+ disableRequestInterceptors?: boolean;
134
+ /**
135
+ * Additional options for your adapter, by default XHR options
136
+ */
137
+ options?: AdapterOptions;
138
+ /**
139
+ * Key which will be used to cancel requests. Autogenerated by default.
140
+ */
141
+ abortKey?: string;
142
+ /**
143
+ * Key which will be used to cache requests. Autogenerated by default.
144
+ */
145
+ cacheKey?: string;
146
+ /**
147
+ * Key which will be used to queue requests. Autogenerated by default.
148
+ */
149
+ queueKey?: string;
150
+ /**
151
+ * Key which will be used to use effects. Autogenerated by default.
152
+ */
153
+ effectKey?: string;
154
+ /**
155
+ * Should we deduplicate two requests made at the same time into one
156
+ */
157
+ deduplicate?: boolean;
158
+ /**
159
+ * Time of pooling for the deduplication to be active (default 10ms)
160
+ */
161
+ deduplicateTime?: number;
162
+ };
163
+
164
+ export type PayloadMapperType<PayloadType, MappedData> = (data: PayloadType) => MappedData;
165
+
166
+ export type PayloadType<Payload, MappedData> = (MappedData extends never ? Payload : MappedData) | NegativeTypes;
167
+
168
+ export type RequestCurrentType<
169
+ Response,
170
+ Payload,
171
+ QueryParams,
172
+ ErrorType,
173
+ GenericEndpoint extends string,
174
+ AdapterOptions,
175
+ MappedData,
176
+ > = {
177
+ used?: boolean;
178
+ params?: ExtractRouteParams<GenericEndpoint> | NegativeTypes;
179
+ queryParams?: QueryParams | NegativeTypes;
180
+ data?: PayloadType<Payload, MappedData>;
181
+ mockCallback?: ((data: Payload) => ResponseType<Response, ErrorType>) | undefined;
182
+ headers?: HeadersInit;
183
+ updatedAbortKey?: boolean;
184
+ updatedCacheKey?: boolean;
185
+ updatedQueueKey?: boolean;
186
+ updatedEffectKey?: boolean;
187
+ } & Partial<NullableKeys<RequestOptionsType<GenericEndpoint, AdapterOptions>>>;
188
+
189
+ export type ParamType = string | number;
190
+ export type ParamsType = Record<string, ParamType>;
191
+
192
+ export type ExtractRouteParams<T extends string> = string extends T
193
+ ? NegativeTypes
194
+ : T extends `${string}:${infer Param}/${infer Rest}`
195
+ ? { [k in Param | keyof ExtractRouteParams<Rest>]: ParamType }
196
+ : T extends `${string}:${infer Param}`
197
+ ? { [k in Param]: ParamType }
198
+ : NegativeTypes;
199
+
200
+ export type FetchOptionsType<AdapterOptions> = Omit<
201
+ Partial<RequestOptionsType<string, AdapterOptions>>,
202
+ "endpoint" | "method"
203
+ >;
204
+
205
+ /**
206
+ * It will check if the query params are already set
207
+ */
208
+ export type FetchQueryParamsType<
209
+ QueryParams extends QueryParamsType | string,
210
+ HasQuery extends true | false = false,
211
+ > = HasQuery extends true
212
+ ? { queryParams?: NegativeTypes }
213
+ : {
214
+ queryParams?: QueryParams | string;
215
+ };
216
+
217
+ /**
218
+ * If the request endpoint parameters are not filled it will throw an error
219
+ */
220
+ export type FetchParamsType<
221
+ Endpoint extends string,
222
+ HasParams extends true | false,
223
+ > = ExtractRouteParams<Endpoint> extends NegativeTypes
224
+ ? { params?: NegativeTypes }
225
+ : true extends HasParams
226
+ ? { params?: NegativeTypes }
227
+ : { params: NonNullable<ExtractRouteParams<Endpoint>> };
228
+
229
+ /**
230
+ * If the request data is not filled it will throw an error
231
+ */
232
+ export type FetchPayloadType<Payload, HasData extends true | false> = Payload extends NegativeTypes
233
+ ? { data?: NegativeTypes }
234
+ : HasData extends true
235
+ ? { data?: NegativeTypes }
236
+ : { data: NonNullable<Payload> };
237
+
238
+ export type RequestQueueOptions = {
239
+ dispatcherType?: "auto" | "fetch" | "submit";
240
+ };
241
+
242
+ // Request making
243
+
244
+ export type RequestSendOptionsType<Request extends RequestInstance> = FetchQueryParamsType<
245
+ ExtractQueryParamsType<Request>,
246
+ ExtractHasQueryParamsType<Request>
247
+ > &
248
+ FetchParamsType<ExtractEndpointType<Request>, ExtractHasParamsType<Request>> &
249
+ FetchPayloadType<ExtractPayloadType<Request>, ExtractHasDataType<Request>> &
250
+ Omit<FetchOptionsType<ExtractAdapterOptionsType<Request>>, "params" | "data"> &
251
+ FetchSendActionsType<Request> &
252
+ RequestQueueOptions;
253
+
254
+ export type FetchSendActionsType<Request extends RequestInstance> = {
255
+ onSettle?: (requestId: string, request: Request) => void;
256
+ onRequestStart?: (details: RequestEventType<Request>) => void;
257
+ onResponseStart?: (details: RequestEventType<Request>) => void;
258
+ onUploadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
259
+ onDownloadProgress?: (values: ProgressType, details: RequestEventType<Request>) => void;
260
+ onResponse?: (
261
+ response: ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>,
262
+ details: ResponseDetailsType,
263
+ ) => void;
264
+ onRemove?: (details: RequestEventType<Request>) => void;
265
+ };
266
+
267
+ export type RequestSendType<Request extends RequestInstance> =
268
+ RequestSendOptionsType<Request>["data"] extends NegativeTypes
269
+ ? RequestSendOptionsType<Request>["params"] extends NegativeTypes
270
+ ? (
271
+ options?: RequestSendOptionsType<Request>,
272
+ ) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>>
273
+ : (
274
+ options: RequestSendOptionsType<Request>,
275
+ ) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>>
276
+ : (
277
+ options: RequestSendOptionsType<Request>,
278
+ ) => Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>>;
279
+
280
+ // Instance
281
+
282
+ export type RequestInstance = Request<any, any, any, any, any, any, any, any, any, any, any>;
@@ -1,8 +1,8 @@
1
- import { FetchProgressType, ClientResponseType, getErrorMessage } from "client";
2
- import { ClientProgressEvent, CommandInstance, CommandDump, FetchType } from "command";
1
+ import { ProgressType, ResponseType, getErrorMessage } from "adapter";
2
+ import { AdapterProgressEventType, RequestInstance, RequestDump, RequestSendOptionsType } from "request";
3
3
  import { HttpMethodsEnum } from "constants/http.constants";
4
4
  import { canRetryRequest, Dispatcher, isFailedRequest } from "dispatcher";
5
- import { ExtractError, ExtractResponse } from "types";
5
+ import { ExtractErrorType, ExtractResponseType } from "types";
6
6
 
7
7
  export const stringifyKey = (value: unknown): string => {
8
8
  try {
@@ -16,7 +16,7 @@ export const stringifyKey = (value: unknown): string => {
16
16
  }
17
17
  };
18
18
 
19
- export const getProgressValue = ({ loaded, total }: ClientProgressEvent): number => {
19
+ export const getProgressValue = ({ loaded, total }: AdapterProgressEventType): number => {
20
20
  if (!loaded || !total) return 0;
21
21
  return Number(((loaded * 100) / total).toFixed(0));
22
22
  };
@@ -24,7 +24,7 @@ export const getProgressValue = ({ loaded, total }: ClientProgressEvent): number
24
24
  export const getRequestEta = (
25
25
  startDate: Date,
26
26
  progressDate: Date,
27
- { total, loaded }: ClientProgressEvent,
27
+ { total, loaded }: AdapterProgressEventType,
28
28
  ): { sizeLeft: number; timeLeft: number | null } => {
29
29
  const timeElapsed = +progressDate - +startDate || 1;
30
30
  const uploadSpeed = loaded / timeElapsed;
@@ -39,8 +39,8 @@ export const getRequestEta = (
39
39
  export const getProgressData = (
40
40
  requestStartTime: Date,
41
41
  progressDate: Date,
42
- progressEvent: ClientProgressEvent,
43
- ): FetchProgressType => {
42
+ progressEvent: AdapterProgressEventType,
43
+ ): ProgressType => {
44
44
  const { total, loaded } = progressEvent;
45
45
  if (Number.isNaN(total) || Number.isNaN(loaded)) {
46
46
  return {
@@ -66,19 +66,19 @@ export const getProgressData = (
66
66
  };
67
67
 
68
68
  // Keys
69
- export const getSimpleKey = (command: CommandInstance | CommandDump<CommandInstance>): string => {
70
- return `${command.method}_${command.commandOptions.endpoint}_${command.cancelable}`;
69
+ export const getSimpleKey = (request: RequestInstance | RequestDump<RequestInstance>): string => {
70
+ return `${request.method}_${request.requestOptions.endpoint}_${request.cancelable}`;
71
71
  };
72
72
 
73
73
  /**
74
- * Cache instance for individual command that collects individual requests responses from
74
+ * Cache instance for individual request that collects individual requests responses from
75
75
  * the same endpoint (they may differ base on the custom key, endpoint params etc)
76
- * @param command
76
+ * @param request
77
77
  * @param useInitialValues
78
78
  * @returns
79
79
  */
80
- export const getCommandKey = (
81
- command: CommandInstance | CommandDump<CommandInstance>,
80
+ export const getRequestKey = (
81
+ request: RequestInstance | RequestDump<RequestInstance>,
82
82
  useInitialValues?: boolean,
83
83
  ): string => {
84
84
  /**
@@ -92,75 +92,78 @@ export const getCommandKey = (
92
92
  * queryParams: string;
93
93
  * params: string;
94
94
  */
95
- const methodKey = stringifyKey(command.method);
96
- const endpointKey = useInitialValues ? command.commandOptions.endpoint : stringifyKey(command.endpoint);
95
+ const methodKey = stringifyKey(request.method);
96
+ const endpointKey = useInitialValues ? request.requestOptions.endpoint : stringifyKey(request.endpoint);
97
97
 
98
98
  return `${methodKey}_${endpointKey}`;
99
99
  };
100
100
 
101
- export const getCommandDispatcher = <Command extends CommandInstance>(
102
- command: Command,
101
+ export const getRequestDispatcher = <Request extends RequestInstance>(
102
+ request: Request,
103
103
  dispatcherType: "auto" | "fetch" | "submit" = "auto",
104
104
  ): [Dispatcher, boolean] => {
105
- const { fetchDispatcher, submitDispatcher } = command.builder;
106
- const isGet = command.method === HttpMethodsEnum.get;
105
+ const { fetchDispatcher, submitDispatcher } = request.client;
106
+ const isGet = request.method === HttpMethodsEnum.get;
107
107
  const isFetchDispatcher = (dispatcherType === "auto" && isGet) || dispatcherType === "fetch";
108
108
  const dispatcher = isFetchDispatcher ? fetchDispatcher : submitDispatcher;
109
109
 
110
110
  return [dispatcher, isFetchDispatcher];
111
111
  };
112
112
 
113
- export const commandSendRequest = <Command extends CommandInstance>(command: Command, options?: FetchType<Command>) => {
114
- const { commandManager } = command.builder;
115
- const [dispatcher] = getCommandDispatcher(command, options?.dispatcherType);
113
+ export const requestSendRequest = <Request extends RequestInstance>(
114
+ request: Request,
115
+ options?: RequestSendOptionsType<Request>,
116
+ ) => {
117
+ const { requestManager } = request.client;
118
+ const [dispatcher] = getRequestDispatcher(request, options?.dispatcherType);
116
119
 
117
- return new Promise<ClientResponseType<ExtractResponse<Command>, ExtractError<Command>>>((resolve) => {
118
- const requestId = dispatcher.add(command);
119
- options?.onSettle?.(requestId, command);
120
+ return new Promise<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>>>((resolve) => {
121
+ const requestId = dispatcher.add(request);
122
+ options?.onSettle?.(requestId, request);
120
123
 
121
- const unmountRequestStart = commandManager.events.onRequestStartById<Command>(requestId, (...props) =>
124
+ const unmountRequestStart = requestManager.events.onRequestStartById<Request>(requestId, (...props) =>
122
125
  options?.onRequestStart?.(...props),
123
126
  );
124
127
 
125
- const unmountResponseStart = commandManager.events.onResponseStartById<Command>(requestId, (...props) =>
128
+ const unmountResponseStart = requestManager.events.onResponseStartById<Request>(requestId, (...props) =>
126
129
  options?.onResponseStart?.(...props),
127
130
  );
128
131
 
129
- const unmountUpload = commandManager.events.onUploadProgressById<Command>(requestId, (...props) =>
132
+ const unmountUpload = requestManager.events.onUploadProgressById<Request>(requestId, (...props) =>
130
133
  options?.onUploadProgress?.(...props),
131
134
  );
132
135
 
133
- const unmountDownload = commandManager.events.onDownloadProgressById<Command>(requestId, (...props) =>
136
+ const unmountDownload = requestManager.events.onDownloadProgressById<Request>(requestId, (...props) =>
134
137
  options?.onDownloadProgress?.(...props),
135
138
  );
136
139
 
137
140
  // When resolved
138
- const unmountResponse = commandManager.events.onResponseById<ExtractResponse<Command>, ExtractError<Command>>(
139
- requestId,
140
- (response, details) => {
141
- const isFailed = isFailedRequest(response);
142
- const isOfflineStatus = command.offline && details.isOffline;
143
- const willRetry = canRetryRequest(details.retries, command.retry);
144
-
145
- // When going offline we can't handle the request as it will be postponed to later resolve
146
- if (isFailed && isOfflineStatus) return;
147
-
148
- // When command is in retry mode we need to listen for retries end
149
- if (isFailed && willRetry) return;
150
-
151
- options?.onResponse?.(response, details);
152
- resolve(response);
153
-
154
- // Unmount Listeners
155
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
156
- umountAll();
157
- },
158
- );
141
+ const unmountResponse = requestManager.events.onResponseById<
142
+ ExtractResponseType<Request>,
143
+ ExtractErrorType<Request>
144
+ >(requestId, (response, details) => {
145
+ const isFailed = isFailedRequest(response);
146
+ const isOfflineStatus = request.offline && details.isOffline;
147
+ const willRetry = canRetryRequest(details.retries, request.retry);
148
+
149
+ // When going offline we can't handle the request as it will be postponed to later resolve
150
+ if (isFailed && isOfflineStatus) return;
151
+
152
+ // When request is in retry mode we need to listen for retries end
153
+ if (isFailed && willRetry) return;
154
+
155
+ options?.onResponse?.(response, details);
156
+ resolve(response);
157
+
158
+ // Unmount Listeners
159
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
160
+ umountAll();
161
+ });
159
162
 
160
163
  // When removed from queue storage we need to clean event listeners and return proper error
161
- const unmountRemoveQueueElement = commandManager.events.onRemoveById<Command>(requestId, (...props) => {
162
- options?.onRemove?.(...props);
163
- resolve([null, getErrorMessage("deleted") as unknown as ExtractError<Command>, 0]);
164
+ const unmountRemoveQueueElement = requestManager.events.onRemoveById<Request>(requestId, (...props) => {
165
+ options.onRemove?.(...props);
166
+ resolve([null, getErrorMessage("deleted") as unknown as ExtractErrorType<Request>, 0]);
164
167
 
165
168
  // Unmount Listeners
166
169
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -1,59 +1,59 @@
1
- import { ClientResponseType } from "client";
2
- import { ExtractRouteParams, Command, CommandInstance } from "command";
1
+ import { ResponseType } from "adapter";
2
+ import { ExtractRouteParams, Request, RequestInstance } from "request";
3
3
 
4
- export type ExtractClientReturnType<T extends CommandInstance> = ClientResponseType<
5
- ExtractResponse<T>,
6
- ExtractError<T>
4
+ export type ExtractAdapterReturnType<T extends RequestInstance> = ResponseType<
5
+ ExtractResponseType<T>,
6
+ ExtractErrorType<T>
7
7
  >;
8
8
 
9
- export type ExtractResponse<T> = T extends Command<infer D, any, any, any, any, any, any, any, any, any, any>
9
+ export type ExtractResponseType<T> = T extends Request<infer D, any, any, any, any, any, any, any, any, any, any>
10
10
  ? D
11
11
  : never;
12
12
 
13
- export type ExtractRequestData<T> = T extends Command<any, infer D, any, any, any, any, any, any, any, any, any>
13
+ export type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any, any, any>
14
14
  ? D
15
15
  : never;
16
16
 
17
- export type ExtractQueryParams<T> = T extends Command<any, any, infer Q, any, any, any, any, any, any, any, any>
17
+ export type ExtractQueryParamsType<T> = T extends Request<any, any, infer Q, any, any, any, any, any, any, any, any>
18
18
  ? Q
19
19
  : never;
20
20
 
21
- export type ExtractError<T> = T extends Command<any, any, any, infer G, infer L, any, any, any, any, any, any>
21
+ export type ExtractErrorType<T> = T extends Request<any, any, any, infer G, infer L, any, any, any, any, any, any>
22
22
  ? G | L
23
23
  : never;
24
24
 
25
- export type ExtractGlobalError<T> = T extends Command<any, any, any, infer E, any, any, any, any, any, any, any>
25
+ export type ExtractGlobalErrorType<T> = T extends Request<any, any, any, infer E, any, any, any, any, any, any, any>
26
26
  ? E
27
27
  : never;
28
28
 
29
- export type ExtractLocalError<T> = T extends Command<any, any, any, any, infer E, any, any, any, any, any, any>
29
+ export type ExtractLocalErrorType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any, any, any>
30
30
  ? E
31
31
  : never;
32
32
 
33
- export type ExtractParams<T> = T extends Command<any, any, any, any, any, infer P, any, any, any, any, any>
33
+ export type ExtractParamsType<T> = T extends Request<any, any, any, any, any, infer P, any, any, any, any, any>
34
34
  ? ExtractRouteParams<P>
35
35
  : never;
36
36
 
37
- export type ExtractEndpoint<T> = T extends Command<any, any, any, any, any, infer E, any, any, any, any, any>
37
+ export type ExtractEndpointType<T> = T extends Request<any, any, any, any, any, infer E, any, any, any, any, any>
38
38
  ? E
39
39
  : never;
40
40
 
41
- export type ExtractClientOptions<T> = T extends Command<any, any, any, any, any, any, infer O, any, any, any, any>
41
+ export type ExtractAdapterOptionsType<T> = T extends Request<any, any, any, any, any, any, infer O, any, any, any, any>
42
42
  ? O
43
43
  : never;
44
44
 
45
- export type ExtractHasData<T> = T extends Command<any, any, any, any, any, any, any, infer D, any, any, any>
45
+ export type ExtractHasDataType<T> = T extends Request<any, any, any, any, any, any, any, infer D, any, any, any>
46
46
  ? D
47
47
  : never;
48
48
 
49
- export type ExtractHasParams<T> = T extends Command<any, any, any, any, any, any, any, any, infer P, any, any>
49
+ export type ExtractHasParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, infer P, any, any>
50
50
  ? P
51
51
  : never;
52
52
 
53
- export type ExtractHasQueryParams<T> = T extends Command<any, any, any, any, any, any, any, any, any, infer Q, any>
53
+ export type ExtractHasQueryParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, any, infer Q, any>
54
54
  ? Q
55
55
  : never;
56
56
 
57
- export type ExtractHasMappedData<T> = T extends Command<any, any, any, any, any, any, any, any, any, any, infer M>
57
+ export type ExtractHasMappedDataType<T> = T extends Request<any, any, any, any, any, any, any, any, any, any, infer M>
58
58
  ? M
59
59
  : never;