@hyper-fetch/core 2.1.0 → 3.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.
- package/README.md +1 -1
- package/dist/adapter/adapter.bindings.d.ts +25 -0
- package/dist/adapter/adapter.browser.d.ts +2 -0
- package/dist/{client/fetch.client.constants.d.ts → adapter/adapter.constants.d.ts} +0 -0
- package/dist/adapter/adapter.d.ts +2 -0
- package/dist/adapter/adapter.server.d.ts +2 -0
- package/dist/adapter/adapter.types.d.ts +57 -0
- package/dist/{client/fetch.client.utils.d.ts → adapter/adapter.utils.d.ts} +3 -3
- package/dist/adapter/index.d.ts +7 -0
- package/dist/cache/cache.d.ts +9 -9
- package/dist/cache/cache.types.d.ts +4 -4
- package/dist/cache/cache.utils.d.ts +3 -3
- package/dist/{builder/builder.constants.d.ts → client/client.constants.d.ts} +0 -0
- package/dist/client/client.d.ts +142 -0
- package/dist/client/client.types.d.ts +41 -0
- package/dist/client/client.utils.d.ts +10 -0
- package/dist/client/index.d.ts +4 -6
- package/dist/dispatcher/dispatcher.d.ts +23 -23
- package/dist/dispatcher/dispatcher.events.d.ts +8 -8
- package/dist/dispatcher/dispatcher.types.d.ts +10 -10
- package/dist/dispatcher/dispatcher.utils.d.ts +5 -5
- package/dist/effect/index.d.ts +2 -2
- package/dist/effect/request.effect.d.ts +14 -0
- package/dist/effect/request.effect.types.d.ts +32 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +4 -4
- package/dist/managers/index.d.ts +1 -1
- package/dist/managers/logger/logger.manager.d.ts +5 -5
- package/dist/managers/logger/logger.manager.types.d.ts +7 -7
- package/dist/managers/request/index.d.ts +4 -0
- package/dist/managers/request/request.manager.d.ts +43 -0
- package/dist/managers/request/request.manager.events.d.ts +36 -0
- package/dist/managers/{command/command.manager.types.d.ts → request/request.manager.types.d.ts} +6 -6
- package/dist/managers/{command/command.manager.utils.d.ts → request/request.manager.utils.d.ts} +0 -0
- package/dist/request/index.d.ts +3 -0
- package/dist/request/request.d.ts +98 -0
- package/dist/request/request.types.d.ts +202 -0
- package/dist/request/request.utils.d.ts +22 -0
- package/dist/types/fetch.types.d.ts +16 -16
- package/package.json +1 -1
- package/src/{client/fetch.client.bindings.ts → adapter/adapter.bindings.ts} +58 -58
- package/src/{client/fetch.client.browser.ts → adapter/adapter.browser.ts} +6 -6
- package/src/{client/fetch.client.constants.ts → adapter/adapter.constants.ts} +0 -0
- package/src/{client/fetch.client.server.ts → adapter/adapter.server.ts} +22 -18
- package/src/adapter/adapter.ts +8 -0
- package/src/adapter/adapter.types.ts +79 -0
- package/src/{client/fetch.client.utils.ts → adapter/adapter.utils.ts} +3 -3
- package/src/adapter/index.ts +7 -0
- package/src/cache/cache.ts +19 -19
- package/src/cache/cache.types.ts +4 -4
- package/src/cache/cache.utils.ts +6 -6
- package/src/{builder/builder.constants.ts → client/client.constants.ts} +0 -0
- package/src/client/client.ts +310 -0
- package/src/client/client.types.ts +52 -0
- package/src/{builder/builder.utils.ts → client/client.utils.ts} +34 -31
- package/src/client/index.ts +4 -6
- package/src/dispatcher/dispatcher.events.ts +11 -11
- package/src/dispatcher/dispatcher.ts +68 -68
- package/src/dispatcher/dispatcher.types.ts +10 -10
- package/src/dispatcher/dispatcher.utils.ts +7 -7
- package/src/effect/index.ts +2 -2
- package/src/effect/request.effect.ts +28 -0
- package/src/effect/request.effect.types.ts +35 -0
- package/src/index.ts +4 -4
- package/src/managers/index.ts +1 -1
- package/src/managers/logger/logger.manager.ts +8 -8
- package/src/managers/logger/logger.manager.types.ts +7 -7
- package/src/managers/request/index.ts +4 -0
- package/src/managers/{command/command.manager.events.ts → request/request.manager.events.ts} +47 -51
- package/src/managers/{command/command.manager.ts → request/request.manager.ts} +5 -5
- package/src/managers/request/request.manager.types.ts +25 -0
- package/src/managers/{command/command.manager.utils.ts → request/request.manager.utils.ts} +0 -0
- package/src/request/index.ts +3 -0
- package/src/{command/command.ts → request/request.ts} +188 -194
- package/src/request/request.types.ts +282 -0
- package/src/{command/command.utils.ts → request/request.utils.ts} +56 -53
- package/src/types/fetch.types.ts +18 -18
- package/dist/builder/builder.d.ts +0 -141
- package/dist/builder/builder.types.d.ts +0 -41
- package/dist/builder/builder.utils.d.ts +0 -10
- package/dist/builder/index.d.ts +0 -4
- package/dist/client/fetch.client.bindings.d.ts +0 -25
- package/dist/client/fetch.client.browser.d.ts +0 -2
- package/dist/client/fetch.client.d.ts +0 -2
- package/dist/client/fetch.client.server.d.ts +0 -2
- package/dist/client/fetch.client.types.d.ts +0 -57
- package/dist/command/command.d.ts +0 -98
- package/dist/command/command.types.d.ts +0 -202
- package/dist/command/command.utils.d.ts +0 -22
- package/dist/command/index.d.ts +0 -3
- package/dist/effect/fetch.effect.d.ts +0 -14
- package/dist/effect/fetch.effect.types.d.ts +0 -32
- package/dist/managers/command/command.manager.d.ts +0 -43
- package/dist/managers/command/command.manager.events.d.ts +0 -36
- package/dist/managers/command/index.d.ts +0 -4
- package/src/builder/builder.ts +0 -308
- package/src/builder/builder.types.ts +0 -53
- package/src/builder/index.ts +0 -4
- package/src/client/fetch.client.ts +0 -9
- package/src/client/fetch.client.types.ts +0 -83
- package/src/command/command.types.ts +0 -273
- package/src/command/index.ts +0 -3
- package/src/effect/fetch.effect.ts +0 -28
- package/src/effect/fetch.effect.types.ts +0 -35
- package/src/managers/command/command.manager.types.ts +0 -25
- package/src/managers/command/index.ts +0 -4
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
RequestSendOptionsType,
|
|
3
3
|
ParamsType,
|
|
4
4
|
getSimpleKey,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
getRequestKey,
|
|
6
|
+
RequestSendType,
|
|
7
|
+
PayloadType,
|
|
8
|
+
RequestDump,
|
|
9
|
+
RequestOptionsType,
|
|
10
10
|
ExtractRouteParams,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "
|
|
15
|
-
import {
|
|
11
|
+
requestSendRequest,
|
|
12
|
+
RequestCurrentType,
|
|
13
|
+
PayloadMapperType,
|
|
14
|
+
} from "request";
|
|
15
|
+
import { Client } from "client";
|
|
16
16
|
import { getUniqueRequestId } from "utils";
|
|
17
|
-
import {
|
|
17
|
+
import { QueryParamsType } from "adapter";
|
|
18
18
|
import { HttpMethodsType, NegativeTypes } from "types";
|
|
19
19
|
import { DateInterval } from "constants/time.constants";
|
|
20
20
|
import { HttpMethodsEnum } from "constants/http.constants";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Fetch
|
|
23
|
+
* Fetch request it is designed to prepare the necessary setup to execute the request to the server.
|
|
24
24
|
* We can setup basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
|
|
25
25
|
* :::info Usage
|
|
26
|
-
* We should not use this class directly in the standard development flow. We can initialize it using the `
|
|
26
|
+
* 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
27
|
* :::
|
|
28
28
|
*
|
|
29
29
|
* @attention
|
|
30
|
-
* The most important thing about the
|
|
30
|
+
* The most important thing about the request is that it keeps data in the format that can be dumped. This is necessary for the persistance and different dispatcher storage types.
|
|
31
31
|
* This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
|
|
32
32
|
*/
|
|
33
|
-
export class
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
export class Request<
|
|
34
|
+
Response,
|
|
35
|
+
Payload,
|
|
36
|
+
QueryParams extends QueryParamsType | string,
|
|
37
|
+
GlobalError, // Global Error Type
|
|
38
|
+
LocalError, // Additional Error for specific endpoint
|
|
39
|
+
Endpoint extends string,
|
|
40
|
+
AdapterOptions,
|
|
41
41
|
HasData extends true | false = false,
|
|
42
42
|
HasParams extends true | false = false,
|
|
43
43
|
HasQuery extends true | false = false,
|
|
44
44
|
MappedData = undefined,
|
|
45
45
|
> {
|
|
46
|
-
endpoint:
|
|
46
|
+
endpoint: Endpoint;
|
|
47
47
|
headers?: HeadersInit;
|
|
48
48
|
auth: boolean;
|
|
49
49
|
method: HttpMethodsType;
|
|
50
|
-
params: ExtractRouteParams<
|
|
51
|
-
data:
|
|
52
|
-
queryParams:
|
|
53
|
-
options?:
|
|
50
|
+
params: ExtractRouteParams<Endpoint> | NegativeTypes;
|
|
51
|
+
data: PayloadType<Payload, MappedData>;
|
|
52
|
+
queryParams: QueryParams | NegativeTypes;
|
|
53
|
+
options?: AdapterOptions | undefined;
|
|
54
54
|
cancelable: boolean;
|
|
55
55
|
retry: number;
|
|
56
56
|
retryTime: number;
|
|
@@ -73,20 +73,20 @@ export class Command<
|
|
|
73
73
|
private updatedEffectKey: boolean;
|
|
74
74
|
|
|
75
75
|
constructor(
|
|
76
|
-
readonly
|
|
77
|
-
readonly
|
|
78
|
-
readonly
|
|
79
|
-
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
readonly client: Client<GlobalError, AdapterOptions>,
|
|
77
|
+
readonly requestOptions: RequestOptionsType<Endpoint, AdapterOptions>,
|
|
78
|
+
readonly requestDump?:
|
|
79
|
+
| RequestCurrentType<
|
|
80
|
+
Response,
|
|
81
|
+
Payload,
|
|
82
|
+
QueryParams,
|
|
83
|
+
GlobalError | LocalError,
|
|
84
|
+
Endpoint,
|
|
85
|
+
AdapterOptions,
|
|
86
86
|
MappedData
|
|
87
87
|
>
|
|
88
88
|
| undefined,
|
|
89
|
-
readonly dataMapper?:
|
|
89
|
+
readonly dataMapper?: PayloadMapperType<Payload, MappedData>,
|
|
90
90
|
) {
|
|
91
91
|
const {
|
|
92
92
|
endpoint,
|
|
@@ -108,36 +108,36 @@ export class Command<
|
|
|
108
108
|
effectKey,
|
|
109
109
|
deduplicate = false,
|
|
110
110
|
deduplicateTime = 10,
|
|
111
|
-
} = { ...this.
|
|
111
|
+
} = { ...this.client.requestDefaultOptions?.(requestOptions), ...requestOptions };
|
|
112
112
|
|
|
113
|
-
this.endpoint =
|
|
114
|
-
this.headers =
|
|
115
|
-
this.auth =
|
|
113
|
+
this.endpoint = requestDump?.endpoint ?? endpoint;
|
|
114
|
+
this.headers = requestDump?.headers ?? headers;
|
|
115
|
+
this.auth = requestDump?.auth ?? auth;
|
|
116
116
|
this.method = method;
|
|
117
|
-
this.params =
|
|
118
|
-
this.data =
|
|
119
|
-
this.queryParams =
|
|
120
|
-
this.options =
|
|
121
|
-
this.cancelable =
|
|
122
|
-
this.retry =
|
|
123
|
-
this.retryTime =
|
|
124
|
-
this.garbageCollection =
|
|
125
|
-
this.cache =
|
|
126
|
-
this.cacheTime =
|
|
127
|
-
this.queued =
|
|
128
|
-
this.offline =
|
|
129
|
-
this.abortKey =
|
|
130
|
-
this.cacheKey =
|
|
131
|
-
this.queueKey =
|
|
132
|
-
this.effectKey =
|
|
133
|
-
this.used =
|
|
134
|
-
this.deduplicate =
|
|
135
|
-
this.deduplicateTime =
|
|
136
|
-
|
|
137
|
-
this.updatedAbortKey =
|
|
138
|
-
this.updatedCacheKey =
|
|
139
|
-
this.updatedQueueKey =
|
|
140
|
-
this.updatedEffectKey =
|
|
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;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
public setHeaders = (headers: HeadersInit) => {
|
|
@@ -148,22 +148,22 @@ export class Command<
|
|
|
148
148
|
return this.clone({ auth });
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
-
public setParams = <P extends ExtractRouteParams<
|
|
151
|
+
public setParams = <P extends ExtractRouteParams<Endpoint>>(params: P) => {
|
|
152
152
|
return this.clone<HasData, P extends null ? false : true, HasQuery>({ params });
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
public setData = <D extends
|
|
155
|
+
public setData = <D extends Payload>(data: D) => {
|
|
156
156
|
const modifiedData = this.dataMapper?.(data) || data;
|
|
157
157
|
return this.clone<D extends null ? false : true, HasParams, HasQuery, MappedData>({
|
|
158
|
-
data: modifiedData as
|
|
158
|
+
data: modifiedData as PayloadType<Payload, MappedData>,
|
|
159
159
|
});
|
|
160
160
|
};
|
|
161
161
|
|
|
162
|
-
public setQueryParams = (queryParams:
|
|
162
|
+
public setQueryParams = (queryParams: QueryParams) => {
|
|
163
163
|
return this.clone<HasData, HasParams, true>({ queryParams });
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
public setOptions = (options:
|
|
166
|
+
public setOptions = (options: AdapterOptions) => {
|
|
167
167
|
return this.clone<HasData, HasParams, true>({ options });
|
|
168
168
|
};
|
|
169
169
|
|
|
@@ -171,25 +171,25 @@ export class Command<
|
|
|
171
171
|
return this.clone({ cancelable });
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
public setRetry = (retry:
|
|
174
|
+
public setRetry = (retry: RequestOptionsType<Endpoint, AdapterOptions>["retry"]) => {
|
|
175
175
|
return this.clone({ retry });
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
-
public setRetryTime = (retryTime:
|
|
178
|
+
public setRetryTime = (retryTime: RequestOptionsType<Endpoint, AdapterOptions>["retryTime"]) => {
|
|
179
179
|
return this.clone({ retryTime });
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
public setGarbageCollection = (
|
|
183
|
-
garbageCollection:
|
|
183
|
+
garbageCollection: RequestOptionsType<Endpoint, AdapterOptions>["garbageCollection"],
|
|
184
184
|
) => {
|
|
185
185
|
return this.clone({ garbageCollection });
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
-
public setCache = (cache:
|
|
188
|
+
public setCache = (cache: RequestOptionsType<Endpoint, AdapterOptions>["cache"]) => {
|
|
189
189
|
return this.clone({ cache });
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
public setCacheTime = (cacheTime:
|
|
192
|
+
public setCacheTime = (cacheTime: RequestOptionsType<Endpoint, AdapterOptions>["cacheTime"]) => {
|
|
193
193
|
return this.clone({ cacheTime });
|
|
194
194
|
};
|
|
195
195
|
|
|
@@ -233,45 +233,42 @@ export class Command<
|
|
|
233
233
|
return this.clone({ offline });
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
-
public setDataMapper = <DataMapper extends (data:
|
|
236
|
+
public setDataMapper = <DataMapper extends (data: Payload) => any>(mapper: DataMapper) => {
|
|
237
237
|
return this.clone<HasData, HasParams, HasQuery>(undefined, mapper);
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
-
private paramsMapper = (
|
|
241
|
-
|
|
242
|
-
queryParams: QueryParamsType | NegativeTypes,
|
|
243
|
-
): string => {
|
|
244
|
-
let endpoint = this.commandOptions.endpoint as string;
|
|
240
|
+
private paramsMapper = (params: ParamsType | null | undefined, queryParams: QueryParams | NegativeTypes): string => {
|
|
241
|
+
let endpoint = this.requestOptions.endpoint as string;
|
|
245
242
|
if (params) {
|
|
246
243
|
Object.entries(params).forEach(([key, value]) => {
|
|
247
244
|
endpoint = endpoint.replace(new RegExp(`:${key}`, "g"), String(value));
|
|
248
245
|
});
|
|
249
246
|
}
|
|
250
247
|
if (queryParams) {
|
|
251
|
-
endpoint += this.
|
|
248
|
+
endpoint += this.client.stringifyQueryParams(queryParams);
|
|
252
249
|
}
|
|
253
250
|
return endpoint;
|
|
254
251
|
};
|
|
255
252
|
|
|
256
|
-
public dump():
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
253
|
+
public dump(): RequestDump<
|
|
254
|
+
Request<
|
|
255
|
+
Response,
|
|
256
|
+
Payload,
|
|
257
|
+
QueryParams,
|
|
258
|
+
GlobalError,
|
|
259
|
+
LocalError,
|
|
260
|
+
Endpoint,
|
|
261
|
+
AdapterOptions,
|
|
265
262
|
HasData,
|
|
266
263
|
HasParams,
|
|
267
264
|
HasQuery,
|
|
268
265
|
MappedData
|
|
269
266
|
>,
|
|
270
|
-
|
|
271
|
-
|
|
267
|
+
AdapterOptions,
|
|
268
|
+
QueryParams
|
|
272
269
|
> {
|
|
273
270
|
return {
|
|
274
|
-
|
|
271
|
+
requestOptions: this.requestOptions,
|
|
275
272
|
endpoint: this.endpoint,
|
|
276
273
|
headers: this.headers,
|
|
277
274
|
auth: this.auth,
|
|
@@ -293,8 +290,8 @@ export class Command<
|
|
|
293
290
|
queueKey: this.queueKey,
|
|
294
291
|
effectKey: this.effectKey,
|
|
295
292
|
used: this.used,
|
|
296
|
-
disableResponseInterceptors: this.
|
|
297
|
-
disableRequestInterceptors: this.
|
|
293
|
+
disableResponseInterceptors: this.requestOptions.disableResponseInterceptors,
|
|
294
|
+
disableRequestInterceptors: this.requestOptions.disableRequestInterceptors,
|
|
298
295
|
updatedAbortKey: this.updatedAbortKey,
|
|
299
296
|
updatedCacheKey: this.updatedCacheKey,
|
|
300
297
|
updatedQueueKey: this.updatedQueueKey,
|
|
@@ -310,37 +307,37 @@ export class Command<
|
|
|
310
307
|
Q extends true | false = HasQuery,
|
|
311
308
|
NewMappedData = MappedData,
|
|
312
309
|
>(
|
|
313
|
-
options?:
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
310
|
+
options?: RequestCurrentType<
|
|
311
|
+
Response,
|
|
312
|
+
Payload,
|
|
313
|
+
QueryParams,
|
|
314
|
+
GlobalError | LocalError,
|
|
315
|
+
Endpoint,
|
|
316
|
+
AdapterOptions,
|
|
320
317
|
NewMappedData
|
|
321
318
|
>,
|
|
322
|
-
mapper?:
|
|
323
|
-
):
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
319
|
+
mapper?: PayloadMapperType<Payload, NewMappedData>,
|
|
320
|
+
): Request<
|
|
321
|
+
Response,
|
|
322
|
+
Payload,
|
|
323
|
+
QueryParams,
|
|
324
|
+
GlobalError,
|
|
325
|
+
LocalError,
|
|
326
|
+
Endpoint,
|
|
327
|
+
AdapterOptions,
|
|
331
328
|
D,
|
|
332
329
|
P,
|
|
333
330
|
Q,
|
|
334
331
|
NewMappedData
|
|
335
332
|
> {
|
|
336
333
|
const dump = this.dump();
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
334
|
+
const requestDump: RequestCurrentType<
|
|
335
|
+
Response,
|
|
336
|
+
Payload,
|
|
337
|
+
QueryParams,
|
|
338
|
+
GlobalError | LocalError,
|
|
339
|
+
Endpoint,
|
|
340
|
+
AdapterOptions,
|
|
344
341
|
NewMappedData
|
|
345
342
|
> = {
|
|
346
343
|
...dump,
|
|
@@ -348,10 +345,7 @@ export class Command<
|
|
|
348
345
|
abortKey: this.updatedAbortKey ? options?.abortKey || this.abortKey : undefined,
|
|
349
346
|
cacheKey: this.updatedCacheKey ? options?.cacheKey || this.cacheKey : undefined,
|
|
350
347
|
queueKey: this.updatedQueueKey ? options?.queueKey || this.queueKey : undefined,
|
|
351
|
-
endpoint: this.paramsMapper(
|
|
352
|
-
options?.params || this.params,
|
|
353
|
-
options?.queryParams || this.queryParams,
|
|
354
|
-
) as EndpointType,
|
|
348
|
+
endpoint: this.paramsMapper(options?.params || this.params, options?.queryParams || this.queryParams) as Endpoint,
|
|
355
349
|
queryParams: options?.queryParams || this.queryParams,
|
|
356
350
|
// Typescript circular types issue - we have to leave any here
|
|
357
351
|
data: (options?.data || this.data) as any,
|
|
@@ -359,32 +353,32 @@ export class Command<
|
|
|
359
353
|
|
|
360
354
|
const mapperFn = (mapper || this.dataMapper) as typeof mapper;
|
|
361
355
|
|
|
362
|
-
const cloned = new
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
356
|
+
const cloned = new Request<
|
|
357
|
+
Response,
|
|
358
|
+
Payload,
|
|
359
|
+
QueryParams,
|
|
360
|
+
GlobalError,
|
|
361
|
+
LocalError,
|
|
362
|
+
Endpoint,
|
|
363
|
+
AdapterOptions,
|
|
370
364
|
D,
|
|
371
365
|
P,
|
|
372
366
|
Q,
|
|
373
367
|
NewMappedData
|
|
374
|
-
>(this.
|
|
368
|
+
>(this.client, this.requestOptions, requestDump, mapperFn);
|
|
375
369
|
|
|
376
370
|
return cloned;
|
|
377
371
|
}
|
|
378
372
|
|
|
379
373
|
public abort = () => {
|
|
380
|
-
const {
|
|
381
|
-
|
|
374
|
+
const { requestManager } = this.client;
|
|
375
|
+
requestManager.abortByKey(this.abortKey);
|
|
382
376
|
|
|
383
377
|
return this.clone();
|
|
384
378
|
};
|
|
385
379
|
|
|
386
380
|
/**
|
|
387
|
-
* Method to use the
|
|
381
|
+
* Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
|
|
388
382
|
* @param options
|
|
389
383
|
* @disableReturns
|
|
390
384
|
* @returns
|
|
@@ -392,30 +386,30 @@ export class Command<
|
|
|
392
386
|
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
393
387
|
* ```
|
|
394
388
|
*/
|
|
395
|
-
public exec:
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
389
|
+
public exec: RequestSendType<
|
|
390
|
+
Request<
|
|
391
|
+
Response,
|
|
392
|
+
Payload,
|
|
393
|
+
QueryParams,
|
|
394
|
+
GlobalError,
|
|
395
|
+
LocalError,
|
|
396
|
+
Endpoint,
|
|
397
|
+
AdapterOptions,
|
|
404
398
|
HasData,
|
|
405
399
|
HasParams,
|
|
406
400
|
HasQuery,
|
|
407
401
|
MappedData
|
|
408
402
|
>
|
|
409
403
|
> = async (
|
|
410
|
-
options?:
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
404
|
+
options?: RequestSendOptionsType<
|
|
405
|
+
Request<
|
|
406
|
+
Response,
|
|
407
|
+
Payload,
|
|
408
|
+
QueryParams,
|
|
409
|
+
GlobalError,
|
|
410
|
+
LocalError,
|
|
411
|
+
Endpoint,
|
|
412
|
+
AdapterOptions,
|
|
419
413
|
HasData,
|
|
420
414
|
HasParams,
|
|
421
415
|
HasQuery,
|
|
@@ -423,12 +417,12 @@ export class Command<
|
|
|
423
417
|
>
|
|
424
418
|
>,
|
|
425
419
|
) => {
|
|
426
|
-
const {
|
|
427
|
-
const
|
|
420
|
+
const { adapter } = this.client;
|
|
421
|
+
const request = this.clone(options as any);
|
|
428
422
|
|
|
429
423
|
const requestId = getUniqueRequestId(this.queueKey);
|
|
430
424
|
|
|
431
|
-
return
|
|
425
|
+
return adapter(request, requestId);
|
|
432
426
|
};
|
|
433
427
|
|
|
434
428
|
/**
|
|
@@ -441,30 +435,30 @@ export class Command<
|
|
|
441
435
|
* Promise<[Data | null, Error | null, HttpStatus]>
|
|
442
436
|
* ```
|
|
443
437
|
*/
|
|
444
|
-
public send:
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
438
|
+
public send: RequestSendType<
|
|
439
|
+
Request<
|
|
440
|
+
Response,
|
|
441
|
+
Payload,
|
|
442
|
+
QueryParams,
|
|
443
|
+
GlobalError,
|
|
444
|
+
LocalError,
|
|
445
|
+
Endpoint,
|
|
446
|
+
AdapterOptions,
|
|
453
447
|
HasData,
|
|
454
448
|
HasParams,
|
|
455
449
|
HasQuery,
|
|
456
450
|
MappedData
|
|
457
451
|
>
|
|
458
452
|
> = async (
|
|
459
|
-
options?:
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
453
|
+
options?: RequestSendOptionsType<
|
|
454
|
+
Request<
|
|
455
|
+
Response,
|
|
456
|
+
Payload,
|
|
457
|
+
QueryParams,
|
|
458
|
+
GlobalError,
|
|
459
|
+
LocalError,
|
|
460
|
+
Endpoint,
|
|
461
|
+
AdapterOptions,
|
|
468
462
|
HasData,
|
|
469
463
|
HasParams,
|
|
470
464
|
HasQuery,
|
|
@@ -474,22 +468,22 @@ export class Command<
|
|
|
474
468
|
) => {
|
|
475
469
|
const { dispatcherType, ...rest } = options || {};
|
|
476
470
|
|
|
477
|
-
const
|
|
478
|
-
return
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
471
|
+
const request = this.clone(rest as any);
|
|
472
|
+
return requestSendRequest<
|
|
473
|
+
Request<
|
|
474
|
+
Response,
|
|
475
|
+
Payload,
|
|
476
|
+
QueryParams,
|
|
477
|
+
GlobalError,
|
|
478
|
+
LocalError,
|
|
479
|
+
Endpoint,
|
|
480
|
+
AdapterOptions,
|
|
487
481
|
HasData,
|
|
488
482
|
HasParams,
|
|
489
483
|
HasQuery,
|
|
490
484
|
MappedData
|
|
491
485
|
>
|
|
492
|
-
>(
|
|
486
|
+
>(request, options);
|
|
493
487
|
};
|
|
494
488
|
}
|
|
495
489
|
|
|
@@ -497,32 +491,32 @@ export class Command<
|
|
|
497
491
|
// * Typescript test cases
|
|
498
492
|
// */
|
|
499
493
|
|
|
500
|
-
// const
|
|
494
|
+
// const client = new Client({
|
|
501
495
|
// url: "http://localhost:3000",
|
|
502
496
|
// });
|
|
503
497
|
|
|
504
|
-
// const getUsers =
|
|
498
|
+
// const getUsers = client.createRequest<{ id: string }[]>()({
|
|
505
499
|
// method: "GET",
|
|
506
500
|
// endpoint: "/users",
|
|
507
501
|
// });
|
|
508
502
|
|
|
509
|
-
// const getUser =
|
|
503
|
+
// const getUser = client.createRequest<{ id: string }>()({
|
|
510
504
|
// method: "GET",
|
|
511
505
|
// endpoint: "/users/:id",
|
|
512
506
|
// });
|
|
513
507
|
|
|
514
|
-
// const postUser =
|
|
508
|
+
// const postUser = client.createRequest<{ id: string }, { name: string }>()({
|
|
515
509
|
// method: "POST",
|
|
516
510
|
// endpoint: "/users",
|
|
517
511
|
// });
|
|
518
512
|
|
|
519
|
-
// const patchUser =
|
|
513
|
+
// const patchUser = client.createRequest<{ id: string }, { name: string }>()({
|
|
520
514
|
// method: "PATCH",
|
|
521
515
|
// endpoint: "/users/:id",
|
|
522
516
|
// });
|
|
523
517
|
|
|
524
|
-
// const mappedReq =
|
|
525
|
-
// .
|
|
518
|
+
// const mappedReq = client
|
|
519
|
+
// .createRequest<{ id: string }, { name: string }>()({
|
|
526
520
|
// method: "POST",
|
|
527
521
|
// endpoint: "/users",
|
|
528
522
|
// })
|