@hyper-fetch/core 9.2.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/__tests__/features/cache/cache.base.spec.ts +48 -0
- package/__tests__/features/cache/cache.replace-equal-deep.spec.ts +125 -0
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +52 -0
- package/__tests__/features/request/request.setters.spec.ts +7 -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/cache/cache.d.ts.map +1 -1
- package/dist/cache/cache.types.d.ts +3 -1
- package/dist/cache/cache.types.d.ts.map +1 -1
- package/dist/cache/cache.utils.d.ts +14 -0
- package/dist/cache/cache.utils.d.ts.map +1 -1
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.d.ts +7 -0
- package/dist/dispatcher/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.events.d.ts +15 -1
- package/dist/dispatcher/dispatcher.events.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.types.d.ts +4 -0
- package/dist/dispatcher/dispatcher.types.d.ts.map +1 -1
- package/dist/dispatcher/dispatcher.utils.d.ts +2 -0
- package/dist/dispatcher/dispatcher.utils.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 +89 -8
- package/dist/index.mjs.map +1 -1
- package/dist/request/request.d.ts +3 -0
- package/dist/request/request.d.ts.map +1 -1
- package/dist/request/request.types.d.ts +6 -0
- package/dist/request/request.types.d.ts.map +1 -1
- package/dist/sdk/sdk.d.ts +1 -0
- package/dist/sdk/sdk.d.ts.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/cache/cache.ts +6 -1
- package/src/cache/cache.types.ts +1 -1
- package/src/cache/cache.utils.ts +56 -0
- package/src/client/client.ts +2 -1
- package/src/dispatcher/dispatcher.events.ts +29 -1
- package/src/dispatcher/dispatcher.ts +19 -6
- package/src/dispatcher/dispatcher.types.ts +5 -0
- package/src/dispatcher/dispatcher.utils.ts +6 -0
- package/src/request/request.ts +9 -0
- package/src/request/request.types.ts +6 -0
- package/src/sdk/sdk.ts +4 -0
- package/src/types/adapter.types.ts +18 -11
|
@@ -22,6 +22,12 @@ export const getDispatcherChangeKey = (): string => {
|
|
|
22
22
|
export const getDispatcherChangeByKey = (key: string): string => {
|
|
23
23
|
return `${key}-change-event`;
|
|
24
24
|
};
|
|
25
|
+
export const getDispatcherRunningKey = (): string => {
|
|
26
|
+
return `running-event`;
|
|
27
|
+
};
|
|
28
|
+
export const getDispatcherRunningByKey = (key: string): string => {
|
|
29
|
+
return `${key}-running-event`;
|
|
30
|
+
};
|
|
25
31
|
|
|
26
32
|
// Requesting
|
|
27
33
|
|
package/src/request/request.ts
CHANGED
|
@@ -98,6 +98,7 @@ export class Request<
|
|
|
98
98
|
used: boolean;
|
|
99
99
|
deduplicate: boolean;
|
|
100
100
|
deduplicateTime: number | null;
|
|
101
|
+
structuralSharing: boolean;
|
|
101
102
|
scope: string | null;
|
|
102
103
|
|
|
103
104
|
/**
|
|
@@ -190,6 +191,7 @@ export class Request<
|
|
|
190
191
|
queryKey,
|
|
191
192
|
deduplicate = false,
|
|
192
193
|
deduplicateTime = null,
|
|
194
|
+
structuralSharing = true,
|
|
193
195
|
} = configuration;
|
|
194
196
|
this.endpoint = initialRequestConfiguration?.endpoint ?? endpoint;
|
|
195
197
|
this.headers = initialRequestConfiguration?.headers ?? headers;
|
|
@@ -213,6 +215,7 @@ export class Request<
|
|
|
213
215
|
this.used = initialRequestConfiguration?.used ?? false;
|
|
214
216
|
this.deduplicate = initialRequestConfiguration?.deduplicate ?? deduplicate;
|
|
215
217
|
this.deduplicateTime = initialRequestConfiguration?.deduplicateTime ?? deduplicateTime;
|
|
218
|
+
this.structuralSharing = initialRequestConfiguration?.structuralSharing ?? structuralSharing;
|
|
216
219
|
this.scope = initialRequestConfiguration?.scope ?? null;
|
|
217
220
|
this.updatedAbortKey = initialRequestConfiguration?.updatedAbortKey ?? false;
|
|
218
221
|
this.updatedCacheKey = initialRequestConfiguration?.updatedCacheKey ?? false;
|
|
@@ -365,6 +368,11 @@ export class Request<
|
|
|
365
368
|
return this.clone({ deduplicateTime });
|
|
366
369
|
};
|
|
367
370
|
|
|
371
|
+
/** Enable or disable structural sharing - keeping references of unchanged parts of the response data in cache. */
|
|
372
|
+
public setStructuralSharing = (structuralSharing: boolean) => {
|
|
373
|
+
return this.clone({ structuralSharing });
|
|
374
|
+
};
|
|
375
|
+
|
|
368
376
|
/** Mark the request as used (prevents automatic refetching in hooks). */
|
|
369
377
|
public setUsed = (used: boolean) => {
|
|
370
378
|
return this.clone({ used });
|
|
@@ -506,6 +514,7 @@ export class Request<
|
|
|
506
514
|
updatedQueryKey: this.updatedQueryKey,
|
|
507
515
|
deduplicate: this.deduplicate,
|
|
508
516
|
deduplicateTime: this.deduplicateTime,
|
|
517
|
+
structuralSharing: this.structuralSharing,
|
|
509
518
|
scope: this.scope,
|
|
510
519
|
isMockerEnabled: this.isMockerEnabled,
|
|
511
520
|
hasMock: !!this.unstable_mock,
|
|
@@ -198,6 +198,7 @@ export type RequestJSON<Request extends RequestInstance> = {
|
|
|
198
198
|
updatedQueryKey: boolean;
|
|
199
199
|
deduplicate: boolean;
|
|
200
200
|
deduplicateTime: number | null;
|
|
201
|
+
structuralSharing: boolean;
|
|
201
202
|
scope: string | null;
|
|
202
203
|
isMockerEnabled: boolean;
|
|
203
204
|
hasMock: boolean;
|
|
@@ -290,6 +291,11 @@ export type RequestOptionsType<GenericEndpoint, AdapterOptions, RequestMethods =
|
|
|
290
291
|
* Time of pooling for the deduplication to be active (default 10ms)
|
|
291
292
|
*/
|
|
292
293
|
deduplicateTime?: number;
|
|
294
|
+
/**
|
|
295
|
+
* Keep references of the unchanged parts of the response data when saving it to cache (default true).
|
|
296
|
+
* Deeply equal responses keep the previous data reference, which limits rerenders and recalculations.
|
|
297
|
+
*/
|
|
298
|
+
structuralSharing?: boolean;
|
|
293
299
|
};
|
|
294
300
|
|
|
295
301
|
export type PayloadMapperType<Payload> = <NewDataType>(payload: Payload) => NewDataType;
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -64,6 +64,7 @@ export type SdkRequestDefaults = {
|
|
|
64
64
|
offline?: boolean;
|
|
65
65
|
deduplicate?: boolean;
|
|
66
66
|
deduplicateTime?: number | null;
|
|
67
|
+
structuralSharing?: boolean;
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
/**
|
|
@@ -175,6 +176,9 @@ const applyObjectDefaults = (request: RequestInstance, config: SdkRequestDefault
|
|
|
175
176
|
if (config.deduplicateTime !== undefined && config.deduplicateTime !== null) {
|
|
176
177
|
result = result.setDeduplicateTime(config.deduplicateTime);
|
|
177
178
|
}
|
|
179
|
+
if (config.structuralSharing !== undefined) {
|
|
180
|
+
result = result.setStructuralSharing(config.structuralSharing);
|
|
181
|
+
}
|
|
178
182
|
return result;
|
|
179
183
|
};
|
|
180
184
|
|
|
@@ -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<
|