@hyper-fetch/core 9.3.0 → 9.4.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/__tests__/features/adapter/adapter.request-options.spec.ts +116 -0
- package/dist/adapter/adapter.d.ts +17 -12
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.types.d.ts +5 -3
- package/dist/adapter/adapter.types.d.ts.map +1 -1
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts +1 -1
- package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -1
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types/adapter.types.d.ts +13 -11
- package/dist/types/adapter.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapter/adapter.ts +33 -13
- package/src/adapter/adapter.types.ts +7 -3
- package/src/client/client.ts +2 -1
- package/src/types/adapter.types.ts +18 -11
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Adapter, AdapterInstance } from '../adapter';
|
|
2
|
-
export type ExtractAdapterOptionsType<T> = T extends Adapter<infer O, any, any, any, any, any, any, any, any, any, any> ? O : never;
|
|
3
|
-
export type ExtractAdapterMethodType<T> = T extends Adapter<any, infer M, any, any, any, any, any, any, any, any, any> ? M : never;
|
|
4
|
-
export type ExtractAdapterStatusType<T> = T extends Adapter<any, any, infer S, any, any, any, any, any, any, any, any> ? S : never;
|
|
5
|
-
export type ExtractAdapterExtraType<T> = T extends Adapter<any, any, any, infer A, any, any, any, any, any, any, any> ? A : never;
|
|
6
|
-
export type ExtractAdapterQueryParamsType<T> = T extends Adapter<any, any, any, any, infer Q, any, any, any, any, any, any> ? Q : never;
|
|
7
|
-
export type ExtractAdapterDefaultQueryParamsType<T> = T extends Adapter<any, any, any, any, any, infer Q, any, any, any, any, any> ? Q : never;
|
|
8
|
-
export type ExtractAdapterEndpointType<T> = T extends Adapter<any, any, any, any, any, any, infer E, any, any, any, any> ? E : never;
|
|
9
|
-
export type ExtractAdapterEndpointMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, infer EM, any, any, any> ? EM : never;
|
|
10
|
-
export type ExtractAdapterQueryParamsMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, infer QPM, any, any> ? QPM : never;
|
|
11
|
-
export type ExtractAdapterHeaderMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, infer HM, any> ? HM : never;
|
|
12
|
-
export type ExtractAdapterPayloadMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, any, infer PM> ? PM : never;
|
|
2
|
+
export type ExtractAdapterOptionsType<T> = T extends Adapter<infer O, any, any, any, any, any, any, any, any, any, any, any> ? O : never;
|
|
3
|
+
export type ExtractAdapterMethodType<T> = T extends Adapter<any, infer M, any, any, any, any, any, any, any, any, any, any> ? M : never;
|
|
4
|
+
export type ExtractAdapterStatusType<T> = T extends Adapter<any, any, infer S, any, any, any, any, any, any, any, any, any> ? S : never;
|
|
5
|
+
export type ExtractAdapterExtraType<T> = T extends Adapter<any, any, any, infer A, any, any, any, any, any, any, any, any> ? A : never;
|
|
6
|
+
export type ExtractAdapterQueryParamsType<T> = T extends Adapter<any, any, any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
7
|
+
export type ExtractAdapterDefaultQueryParamsType<T> = T extends Adapter<any, any, any, any, any, infer Q, any, any, any, any, any, any> ? Q : never;
|
|
8
|
+
export type ExtractAdapterEndpointType<T> = T extends Adapter<any, any, any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
9
|
+
export type ExtractAdapterEndpointMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, infer EM, any, any, any, any> ? EM : never;
|
|
10
|
+
export type ExtractAdapterQueryParamsMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, infer QPM, any, any, any> ? QPM : never;
|
|
11
|
+
export type ExtractAdapterHeaderMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, infer HM, any, any> ? HM : never;
|
|
12
|
+
export type ExtractAdapterPayloadMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, any, infer PM, any> ? PM : never;
|
|
13
|
+
/** `any` (e.g. `AdapterInstance`) resolves to `{}`, otherwise it would erase the type of the whole `createRequest` params */
|
|
14
|
+
export type ExtractAdapterRequestOptionsType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, any, any, infer RO> ? 0 extends 1 & RO ? {} : RO : never;
|
|
13
15
|
export type ExtractUnionAdapter<AdapterType extends AdapterInstance, Values extends {
|
|
14
16
|
method?: any;
|
|
15
17
|
options?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.types.d.ts","sourceRoot":"","sources":["../../src/types/adapter.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACrC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.types.d.ts","sourceRoot":"","sources":["../../src/types/adapter.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExD,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACrC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChG,MAAM,M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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "Cache, Queue and Persist your requests no matter if you are online or offline!",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|
package/src/adapter/adapter.ts
CHANGED
|
@@ -39,6 +39,7 @@ export class Adapter<
|
|
|
39
39
|
QueryParamsMapperType extends QueryParamsMapper<QueryParams> | DefaultMapperType = DefaultMapperType,
|
|
40
40
|
HeaderMapperType extends HeaderMappingType | DefaultMapperType = DefaultMapperType,
|
|
41
41
|
PayloadMapperType extends AdapterPayloadMappingType | DefaultMapperType = DefaultMapperType,
|
|
42
|
+
RequestOptions extends Record<string, any> = {},
|
|
42
43
|
> {
|
|
43
44
|
/** Fetching function */
|
|
44
45
|
public unstable_fetcher: AdapterFetcherType<
|
|
@@ -53,7 +54,8 @@ export class Adapter<
|
|
|
53
54
|
EndpointMapperType,
|
|
54
55
|
QueryParamsMapperType,
|
|
55
56
|
HeaderMapperType,
|
|
56
|
-
PayloadMapperType
|
|
57
|
+
PayloadMapperType,
|
|
58
|
+
RequestOptions
|
|
57
59
|
>
|
|
58
60
|
>;
|
|
59
61
|
|
|
@@ -80,6 +82,12 @@ export class Adapter<
|
|
|
80
82
|
public unstable_payloadMapperConfig: Parameters<PayloadMapperType>[1];
|
|
81
83
|
public unstable_endpointMapperConfig: Parameters<EndpointMapperType>[1];
|
|
82
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Type-only carrier of the additional `createRequest` fields declared by this adapter.
|
|
87
|
+
* It has no runtime value - adapters read those fields from `request.requestOptions`.
|
|
88
|
+
*/
|
|
89
|
+
public unstable_requestOptionsType?: RequestOptions = undefined;
|
|
90
|
+
|
|
83
91
|
constructor(
|
|
84
92
|
public options: {
|
|
85
93
|
name: string;
|
|
@@ -147,7 +155,8 @@ export class Adapter<
|
|
|
147
155
|
EndpointMapperType,
|
|
148
156
|
QueryParamsMapperType,
|
|
149
157
|
HeaderMapperType,
|
|
150
|
-
PayloadMapperType
|
|
158
|
+
PayloadMapperType,
|
|
159
|
+
RequestOptions
|
|
151
160
|
>
|
|
152
161
|
>;
|
|
153
162
|
}
|
|
@@ -161,7 +170,9 @@ export class Adapter<
|
|
|
161
170
|
* Get formatted endpoint name of the request.
|
|
162
171
|
* Helpful in displaying long endpoints like in case of graphql schemas etc.
|
|
163
172
|
*/
|
|
164
|
-
public unstable_devtoolsEndpointGetter: (endpoint: string) => string = (
|
|
173
|
+
public unstable_devtoolsEndpointGetter: (endpoint: string, requestOptions?: Record<string, any>) => string = (
|
|
174
|
+
endpoint,
|
|
175
|
+
) => endpoint;
|
|
165
176
|
|
|
166
177
|
/**
|
|
167
178
|
* ********************
|
|
@@ -182,7 +193,7 @@ export class Adapter<
|
|
|
182
193
|
};
|
|
183
194
|
|
|
184
195
|
/** Set a function that formats the endpoint string for display in devtools. */
|
|
185
|
-
setDevtoolsEndpointGetter = (callback: (endpoint: string) => string) => {
|
|
196
|
+
setDevtoolsEndpointGetter = (callback: (endpoint: string, requestOptions?: Record<string, any>) => string) => {
|
|
186
197
|
this.unstable_devtoolsEndpointGetter = callback;
|
|
187
198
|
return this;
|
|
188
199
|
};
|
|
@@ -217,7 +228,8 @@ export class Adapter<
|
|
|
217
228
|
EndpointMapperType,
|
|
218
229
|
QueryParamsMapperType,
|
|
219
230
|
HeaderMapperType,
|
|
220
|
-
PayloadMapperType
|
|
231
|
+
PayloadMapperType,
|
|
232
|
+
RequestOptions
|
|
221
233
|
>
|
|
222
234
|
>;
|
|
223
235
|
}
|
|
@@ -251,7 +263,8 @@ export class Adapter<
|
|
|
251
263
|
EndpointMapperType,
|
|
252
264
|
QueryParamsMapperType,
|
|
253
265
|
NewMapper,
|
|
254
|
-
PayloadMapperType
|
|
266
|
+
PayloadMapperType,
|
|
267
|
+
RequestOptions
|
|
255
268
|
>;
|
|
256
269
|
};
|
|
257
270
|
|
|
@@ -275,7 +288,8 @@ export class Adapter<
|
|
|
275
288
|
EndpointMapperType,
|
|
276
289
|
QueryParamsMapperType,
|
|
277
290
|
HeaderMapperType,
|
|
278
|
-
NewMapper
|
|
291
|
+
NewMapper,
|
|
292
|
+
RequestOptions
|
|
279
293
|
>;
|
|
280
294
|
};
|
|
281
295
|
|
|
@@ -299,7 +313,8 @@ export class Adapter<
|
|
|
299
313
|
NewEndpointMapper,
|
|
300
314
|
QueryParamsMapperType,
|
|
301
315
|
HeaderMapperType,
|
|
302
|
-
PayloadMapperType
|
|
316
|
+
PayloadMapperType,
|
|
317
|
+
RequestOptions
|
|
303
318
|
>;
|
|
304
319
|
};
|
|
305
320
|
|
|
@@ -325,7 +340,8 @@ export class Adapter<
|
|
|
325
340
|
EndpointMapperType,
|
|
326
341
|
NewQueryParamsMapper,
|
|
327
342
|
HeaderMapperType,
|
|
328
|
-
PayloadMapperType
|
|
343
|
+
PayloadMapperType,
|
|
344
|
+
RequestOptions
|
|
329
345
|
>;
|
|
330
346
|
};
|
|
331
347
|
|
|
@@ -381,7 +397,8 @@ export class Adapter<
|
|
|
381
397
|
EndpointMapperType,
|
|
382
398
|
QueryParamsMapperType,
|
|
383
399
|
HeaderMapperType,
|
|
384
|
-
PayloadMapperType
|
|
400
|
+
PayloadMapperType,
|
|
401
|
+
RequestOptions
|
|
385
402
|
>
|
|
386
403
|
>,
|
|
387
404
|
) {
|
|
@@ -408,7 +425,8 @@ export class Adapter<
|
|
|
408
425
|
EndpointMapperType,
|
|
409
426
|
QueryParamsMapperType,
|
|
410
427
|
HeaderMapperType,
|
|
411
|
-
PayloadMapperType
|
|
428
|
+
PayloadMapperType,
|
|
429
|
+
RequestOptions
|
|
412
430
|
>
|
|
413
431
|
>;
|
|
414
432
|
}
|
|
@@ -445,7 +463,8 @@ export class Adapter<
|
|
|
445
463
|
EndpointMapperType,
|
|
446
464
|
QueryParamsMapperType,
|
|
447
465
|
HeaderMapperType,
|
|
448
|
-
PayloadMapperType
|
|
466
|
+
PayloadMapperType,
|
|
467
|
+
RequestOptions
|
|
449
468
|
>
|
|
450
469
|
>({
|
|
451
470
|
request,
|
|
@@ -470,7 +489,8 @@ export class Adapter<
|
|
|
470
489
|
EndpointMapperType,
|
|
471
490
|
QueryParamsMapperType,
|
|
472
491
|
HeaderMapperType,
|
|
473
|
-
PayloadMapperType
|
|
492
|
+
PayloadMapperType,
|
|
493
|
+
RequestOptions
|
|
474
494
|
>
|
|
475
495
|
>(bindings);
|
|
476
496
|
}
|
|
@@ -21,7 +21,7 @@ import type { getAdapterBindings } from "./adapter.bindings";
|
|
|
21
21
|
* Base Adapter
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
export type AdapterInstance = Adapter<any, any, any, any, any, any, any, any, any, any, any>;
|
|
24
|
+
export type AdapterInstance = Adapter<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
25
25
|
|
|
26
26
|
export type AdapterGenericType<
|
|
27
27
|
AdapterOptions,
|
|
@@ -35,6 +35,7 @@ export type AdapterGenericType<
|
|
|
35
35
|
QueryParamsMapperType extends QueryParamsMapper<QueryParams> | DefaultMapperType = DefaultMapperType,
|
|
36
36
|
HeaderMapperType extends HeaderMappingType | DefaultMapperType = DefaultMapperType,
|
|
37
37
|
PayloadMapperType extends AdapterPayloadMappingType | DefaultMapperType = DefaultMapperType,
|
|
38
|
+
RequestOptions extends Record<string, any> = {},
|
|
38
39
|
> = {
|
|
39
40
|
adapterOptions: AdapterOptions;
|
|
40
41
|
methodType: MethodType;
|
|
@@ -47,10 +48,12 @@ export type AdapterGenericType<
|
|
|
47
48
|
queryParamsMapperType?: QueryParamsMapperType;
|
|
48
49
|
headerMapperType?: HeaderMapperType;
|
|
49
50
|
payloadMapperType?: PayloadMapperType;
|
|
51
|
+
/** Additional fields accepted by `createRequest` on clients using this adapter */
|
|
52
|
+
requestOptions?: RequestOptions;
|
|
50
53
|
};
|
|
51
54
|
|
|
52
55
|
export type DeclareAdapterType<
|
|
53
|
-
Properties extends AdapterGenericType<any, any, any, any, any, any, any, any, any, any>,
|
|
56
|
+
Properties extends AdapterGenericType<any, any, any, any, any, any, any, any, any, any, any, any>,
|
|
54
57
|
> = Adapter<
|
|
55
58
|
TypeWithDefaults<Properties, "adapterOptions", any>,
|
|
56
59
|
TypeWithDefaults<Properties, "methodType", any>,
|
|
@@ -62,7 +65,8 @@ export type DeclareAdapterType<
|
|
|
62
65
|
TypeWithDefaults<Properties, "endpointMapperType", DefaultMapperType>,
|
|
63
66
|
TypeWithDefaults<Properties, "queryParamsMapperType", DefaultMapperType>,
|
|
64
67
|
TypeWithDefaults<Properties, "headerMapperType", DefaultMapperType>,
|
|
65
|
-
NonNullable<TypeWithDefaults<Properties, "payloadMapperType", DefaultMapperType
|
|
68
|
+
NonNullable<TypeWithDefaults<Properties, "payloadMapperType", DefaultMapperType>>,
|
|
69
|
+
TypeWithDefaults<Properties, "requestOptions", {}>
|
|
66
70
|
>;
|
|
67
71
|
|
|
68
72
|
export type AdapterFetcherType<Adapter extends AdapterInstance> = (
|
package/src/client/client.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
HydrateDataType,
|
|
29
29
|
HydrationOptions,
|
|
30
30
|
ExtractAdapterDefaultQueryParamsType,
|
|
31
|
+
ExtractAdapterRequestOptionsType,
|
|
31
32
|
} from "types";
|
|
32
33
|
import { getUniqueRequestId } from "utils";
|
|
33
34
|
|
|
@@ -505,7 +506,7 @@ export class Client<
|
|
|
505
506
|
AdapterOptions extends ExtractAdapterOptionsType<Adapter>,
|
|
506
507
|
MethodType extends ExtractAdapterMethodType<Adapter>,
|
|
507
508
|
>(
|
|
508
|
-
params: RequestOptionsType<EndpointType, AdapterOptions, MethodType>,
|
|
509
|
+
params: RequestOptionsType<EndpointType, AdapterOptions, MethodType> & ExtractAdapterRequestOptionsType<Adapter>,
|
|
509
510
|
) => {
|
|
510
511
|
type Endpoint = TypeWithDefaults<RequestProperties, "endpoint", EndpointType>;
|
|
511
512
|
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import type { Adapter, AdapterInstance } from "adapter";
|
|
2
2
|
|
|
3
3
|
export type ExtractAdapterOptionsType<T> =
|
|
4
|
-
T extends Adapter<infer O, any, any, any, any, any, any, any, any, any, any> ? O : never;
|
|
4
|
+
T extends Adapter<infer O, any, any, any, any, any, any, any, any, any, any, any> ? O : never;
|
|
5
5
|
export type ExtractAdapterMethodType<T> =
|
|
6
|
-
T extends Adapter<any, infer M, any, any, any, any, any, any, any, any, any> ? M : never;
|
|
6
|
+
T extends Adapter<any, infer M, any, any, any, any, any, any, any, any, any, any> ? M : never;
|
|
7
7
|
export type ExtractAdapterStatusType<T> =
|
|
8
|
-
T extends Adapter<any, any, infer S, any, any, any, any, any, any, any, any> ? S : never;
|
|
8
|
+
T extends Adapter<any, any, infer S, any, any, any, any, any, any, any, any, any> ? S : never;
|
|
9
9
|
export type ExtractAdapterExtraType<T> =
|
|
10
|
-
T extends Adapter<any, any, any, infer A, any, any, any, any, any, any, any> ? A : never;
|
|
10
|
+
T extends Adapter<any, any, any, infer A, any, any, any, any, any, any, any, any> ? A : never;
|
|
11
11
|
export type ExtractAdapterQueryParamsType<T> =
|
|
12
|
-
T extends Adapter<any, any, any, any, infer Q, any, any, any, any, any, any> ? Q : never;
|
|
12
|
+
T extends Adapter<any, any, any, any, infer Q, any, any, any, any, any, any, any> ? Q : never;
|
|
13
13
|
export type ExtractAdapterDefaultQueryParamsType<T> =
|
|
14
|
-
T extends Adapter<any, any, any, any, any, infer Q, any, any, any, any, any> ? Q : never;
|
|
14
|
+
T extends Adapter<any, any, any, any, any, infer Q, any, any, any, any, any, any> ? Q : never;
|
|
15
15
|
export type ExtractAdapterEndpointType<T> =
|
|
16
|
-
T extends Adapter<any, any, any, any, any, any, infer E, any, any, any, any> ? E : never;
|
|
16
|
+
T extends Adapter<any, any, any, any, any, any, infer E, any, any, any, any, any> ? E : never;
|
|
17
17
|
export type ExtractAdapterEndpointMapperType<T> =
|
|
18
|
-
T extends Adapter<any, any, any, any, any, any, any, infer EM, any, any, any> ? EM : never;
|
|
18
|
+
T extends Adapter<any, any, any, any, any, any, any, infer EM, any, any, any, any> ? EM : never;
|
|
19
19
|
export type ExtractAdapterQueryParamsMapperType<T> =
|
|
20
|
-
T extends Adapter<any, any, any, any, any, any, any, any, infer QPM, any, any> ? QPM : never;
|
|
20
|
+
T extends Adapter<any, any, any, any, any, any, any, any, infer QPM, any, any, any> ? QPM : never;
|
|
21
21
|
export type ExtractAdapterHeaderMapperType<T> =
|
|
22
|
-
T extends Adapter<any, any, any, any, any, any, any, any, any, infer HM, any> ? HM : never;
|
|
22
|
+
T extends Adapter<any, any, any, any, any, any, any, any, any, infer HM, any, any> ? HM : never;
|
|
23
23
|
export type ExtractAdapterPayloadMapperType<T> =
|
|
24
|
-
T extends Adapter<any, any, any, any, any, any, any, any, any, any, infer PM> ? PM : never;
|
|
24
|
+
T extends Adapter<any, any, any, any, any, any, any, any, any, any, infer PM, any> ? PM : never;
|
|
25
|
+
/** `any` (e.g. `AdapterInstance`) resolves to `{}`, otherwise it would erase the type of the whole `createRequest` params */
|
|
26
|
+
export type ExtractAdapterRequestOptionsType<T> =
|
|
27
|
+
T extends Adapter<any, any, any, any, any, any, any, any, any, any, any, infer RO>
|
|
28
|
+
? 0 extends 1 & RO
|
|
29
|
+
? {}
|
|
30
|
+
: RO
|
|
31
|
+
: never;
|
|
25
32
|
|
|
26
33
|
// Special type only for selecting appropriate AdapterType union version (check FirebaseAdapterType).
|
|
27
34
|
export type ExtractUnionAdapter<
|