@hyper-fetch/core 10.2.0 → 10.3.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.bindings.spec.ts +27 -27
- package/__tests__/features/cache/cache.base.spec.ts +4 -4
- package/__tests__/features/cache/cache.events.spec.ts +4 -4
- package/__tests__/features/cache/cache.garbage-collector.spec.ts +2 -2
- package/__tests__/features/cache/cache.lazy-storage.spec.ts +2 -2
- package/__tests__/features/cache/cache.modes.spec.ts +2 -2
- package/__tests__/features/cache/cache.scoped-events.spec.ts +2 -2
- package/__tests__/features/cache/cache.scoping.spec.ts +2 -2
- package/__tests__/features/cache/cache.semantics.spec.ts +6 -1
- package/__tests__/features/cache/cache.typescript.spec.ts +2 -2
- package/__tests__/features/cache/cache.utils.spec.ts +9 -9
- package/__tests__/features/client/client.hydration.round-trip.spec.ts +2 -2
- package/__tests__/features/client/client.hydration.spec.ts +3 -3
- package/__tests__/features/client/client.interceptor.spec.ts +7 -7
- package/__tests__/features/client/client.interceptors.pipeline.spec.ts +3 -3
- package/__tests__/features/client/client.set-url.spec.ts +2 -2
- package/__tests__/features/dispatcher/dispatcher.events.spec.ts +2 -2
- package/__tests__/features/http-adapter/http-adapter.extra.spec.ts +21 -0
- package/__tests__/features/request/request.sending.spec.ts +7 -7
- package/__tests__/utils/callbacks.utils.ts +2 -2
- package/__tests__/utils/fixtures.utils.ts +4 -4
- package/dist/http-adapter/http-adapter.constants.d.ts +8 -0
- package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -1
- package/dist/index.mjs +11 -3
- package/dist/index.mjs.map +1 -1
- package/dist/request/request.types.d.ts +2 -1
- package/dist/request/request.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/http-adapter/http-adapter.constants.ts +10 -1
- package/src/http-adapter/http-adapter.fetch.ts +2 -2
- package/src/request/request.types.ts +2 -1
|
@@ -3,7 +3,7 @@ import type { ResponseType, ResponseErrorType } from "adapter";
|
|
|
3
3
|
import { getAdapterBindings, getErrorMessage } from "adapter";
|
|
4
4
|
import { Client } from "client";
|
|
5
5
|
import type { FetchAdapterOptionsType, HttpAdapterType } from "http-adapter";
|
|
6
|
-
import {
|
|
6
|
+
import { httpExtra } from "http-adapter";
|
|
7
7
|
import { Plugin } from "plugin";
|
|
8
8
|
import type { RequestInstance } from "request";
|
|
9
9
|
|
|
@@ -25,7 +25,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
25
25
|
error: null,
|
|
26
26
|
success: true,
|
|
27
27
|
status: 200,
|
|
28
|
-
extra:
|
|
28
|
+
extra: httpExtra,
|
|
29
29
|
};
|
|
30
30
|
const errorResponse: Omit<
|
|
31
31
|
ResponseType<unknown, unknown, HttpAdapterType>,
|
|
@@ -35,7 +35,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
35
35
|
error: data,
|
|
36
36
|
success: false,
|
|
37
37
|
status: 400,
|
|
38
|
-
extra:
|
|
38
|
+
extra: httpExtra,
|
|
39
39
|
};
|
|
40
40
|
const requestConfig: FetchAdapterOptionsType = { timeout: 1000 };
|
|
41
41
|
|
|
@@ -153,7 +153,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
153
153
|
const spy = vi.fn();
|
|
154
154
|
request.client.requestManager.addAbortController(request.abortKey, requestId);
|
|
155
155
|
const controller = getAbortController();
|
|
156
|
-
const unmount = createAbortListener({ status: 0, extra:
|
|
156
|
+
const unmount = createAbortListener({ status: 0, extra: httpExtra, onAbort: spy });
|
|
157
157
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
158
158
|
expect(resolveSpy).toHaveBeenCalledTimes(0);
|
|
159
159
|
controller?.abort();
|
|
@@ -175,7 +175,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
175
175
|
const spy = vi.fn();
|
|
176
176
|
const resolveSpy = vi.fn();
|
|
177
177
|
const controller = getAbortController();
|
|
178
|
-
const unmount = createAbortListener({ status: 0, extra:
|
|
178
|
+
const unmount = createAbortListener({ status: 0, extra: httpExtra, onAbort: spy });
|
|
179
179
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
180
180
|
expect(resolveSpy).toHaveBeenCalledTimes(0);
|
|
181
181
|
unmount();
|
|
@@ -193,7 +193,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
193
193
|
internalErrorMapping: (error) => error,
|
|
194
194
|
});
|
|
195
195
|
client.requestManager.abortControllers.clear();
|
|
196
|
-
expect(() => createAbortListener({ status: 0, extra:
|
|
196
|
+
expect(() => createAbortListener({ status: 0, extra: httpExtra, onAbort: () => null })).toThrow();
|
|
197
197
|
});
|
|
198
198
|
it("should call onAbort when signal is aborted", async () => {
|
|
199
199
|
request.client.requestManager.addAbortController(request.abortKey, requestId);
|
|
@@ -211,7 +211,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
211
211
|
internalErrorMapping: (error) => error,
|
|
212
212
|
});
|
|
213
213
|
|
|
214
|
-
createAbortListener({ status: 0, extra:
|
|
214
|
+
createAbortListener({ status: 0, extra: httpExtra, onAbort: spy });
|
|
215
215
|
|
|
216
216
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
217
217
|
});
|
|
@@ -228,7 +228,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
228
228
|
|
|
229
229
|
const resolveSpy = vi.fn();
|
|
230
230
|
const controller = getAbortController();
|
|
231
|
-
const unmount = createAbortListener({ status: 0, extra:
|
|
231
|
+
const unmount = createAbortListener({ status: 0, extra: httpExtra }); // No onAbort provided
|
|
232
232
|
|
|
233
233
|
expect(resolveSpy).toHaveBeenCalledTimes(0);
|
|
234
234
|
controller?.abort();
|
|
@@ -730,7 +730,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
730
730
|
const { responseTimestamp, requestTimestamp, ...response } = await onSuccess({
|
|
731
731
|
data,
|
|
732
732
|
status: 200,
|
|
733
|
-
extra:
|
|
733
|
+
extra: httpExtra,
|
|
734
734
|
});
|
|
735
735
|
expect(response).toEqual(expect.objectContaining(successResponse));
|
|
736
736
|
expect(requestTimestamp).toBeNumber();
|
|
@@ -744,7 +744,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
744
744
|
onStartTime: () => null,
|
|
745
745
|
internalErrorMapping: (error) => error,
|
|
746
746
|
});
|
|
747
|
-
await onSuccess({ data, status: 200, extra:
|
|
747
|
+
await onSuccess({ data, status: 200, extra: httpExtra });
|
|
748
748
|
expect(onSuccessSpy).toHaveBeenCalledTimes(1);
|
|
749
749
|
expect(onFinishedSpy).toHaveBeenCalledTimes(1);
|
|
750
750
|
expect(onSuccessSpy).toHaveBeenCalledWith({ response: expect.objectContaining(successResponse), request });
|
|
@@ -763,7 +763,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
763
763
|
responseTimestamp: expect.toBeNumber(),
|
|
764
764
|
requestTimestamp: expect.toBeNumber(),
|
|
765
765
|
}));
|
|
766
|
-
const response = await onSuccess({ data, status: 200, extra:
|
|
766
|
+
const response = await onSuccess({ data, status: 200, extra: httpExtra });
|
|
767
767
|
client.unstable_onResponseCallbacks = [];
|
|
768
768
|
expect(response).toEqual(expect.objectContaining(successResponse));
|
|
769
769
|
});
|
|
@@ -780,7 +780,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
780
780
|
responseTimestamp: expect.toBeNumber(),
|
|
781
781
|
requestTimestamp: expect.toBeNumber(),
|
|
782
782
|
}));
|
|
783
|
-
const response = await onSuccess({ data, status: 200, extra:
|
|
783
|
+
const response = await onSuccess({ data, status: 200, extra: httpExtra });
|
|
784
784
|
client.unstable_onSuccessCallbacks = [];
|
|
785
785
|
expect(response).toEqual(expect.objectContaining(successResponse));
|
|
786
786
|
});
|
|
@@ -797,7 +797,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
797
797
|
error: null,
|
|
798
798
|
success: true,
|
|
799
799
|
status: 222,
|
|
800
|
-
extra:
|
|
800
|
+
extra: httpExtra,
|
|
801
801
|
requestTimestamp: expect.toBeNumber(),
|
|
802
802
|
responseTimestamp: expect.toBeNumber(),
|
|
803
803
|
};
|
|
@@ -807,7 +807,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
807
807
|
responseTimestamp: expect.toBeNumber(),
|
|
808
808
|
}));
|
|
809
809
|
client.unstable_onSuccessCallbacks.push(() => newData);
|
|
810
|
-
const response = await onSuccess({ data, status: 200, extra:
|
|
810
|
+
const response = await onSuccess({ data, status: 200, extra: httpExtra });
|
|
811
811
|
client.unstable_onResponseCallbacks = [];
|
|
812
812
|
client.unstable_onSuccessCallbacks = [];
|
|
813
813
|
expect(response).toEqual(expect.objectContaining(newData));
|
|
@@ -827,7 +827,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
827
827
|
const { requestTimestamp, responseTimestamp, ...response } = await onError({
|
|
828
828
|
error: data,
|
|
829
829
|
status: 400,
|
|
830
|
-
extra:
|
|
830
|
+
extra: httpExtra,
|
|
831
831
|
});
|
|
832
832
|
expect(response).toEqual(errorResponse);
|
|
833
833
|
expect(requestTimestamp).toBeNumber();
|
|
@@ -841,7 +841,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
841
841
|
onStartTime: () => null,
|
|
842
842
|
internalErrorMapping: (error) => error,
|
|
843
843
|
});
|
|
844
|
-
await onError({ error: data, status: 400, extra:
|
|
844
|
+
await onError({ error: data, status: 400, extra: httpExtra });
|
|
845
845
|
expect(onErrorSpy).toHaveBeenCalledTimes(1);
|
|
846
846
|
expect(onFinishedSpy).toHaveBeenCalledTimes(1);
|
|
847
847
|
expect(onErrorSpy).toHaveBeenCalledWith({ response: expect.objectContaining(errorResponse), request });
|
|
@@ -860,7 +860,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
860
860
|
requestTimestamp: expect.toBeNumber(),
|
|
861
861
|
responseTimestamp: expect.toBeNumber(),
|
|
862
862
|
}));
|
|
863
|
-
const response = await onError({ error: data, status: 400, extra:
|
|
863
|
+
const response = await onError({ error: data, status: 400, extra: httpExtra });
|
|
864
864
|
client.unstable_onResponseCallbacks = [];
|
|
865
865
|
expect(response).toEqual(expect.objectContaining(errorResponse));
|
|
866
866
|
});
|
|
@@ -877,7 +877,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
877
877
|
requestTimestamp: expect.toBeNumber(),
|
|
878
878
|
responseTimestamp: expect.toBeNumber(),
|
|
879
879
|
}));
|
|
880
|
-
const response = await onError({ error: data, status: 400, extra:
|
|
880
|
+
const response = await onError({ error: data, status: 400, extra: httpExtra });
|
|
881
881
|
client.unstable_onErrorCallbacks = [];
|
|
882
882
|
expect(response).toEqual(expect.objectContaining(errorResponse));
|
|
883
883
|
});
|
|
@@ -894,7 +894,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
894
894
|
error: 444,
|
|
895
895
|
success: false,
|
|
896
896
|
status: null,
|
|
897
|
-
extra:
|
|
897
|
+
extra: httpExtra,
|
|
898
898
|
requestTimestamp: expect.toBeNumber(),
|
|
899
899
|
responseTimestamp: expect.toBeNumber(),
|
|
900
900
|
};
|
|
@@ -904,7 +904,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
904
904
|
requestTimestamp: expect.toBeNumber(),
|
|
905
905
|
}));
|
|
906
906
|
client.unstable_onErrorCallbacks.push(() => newData);
|
|
907
|
-
const response = await onError({ error: data, status: 400, extra:
|
|
907
|
+
const response = await onError({ error: data, status: 400, extra: httpExtra });
|
|
908
908
|
client.unstable_onErrorCallbacks = [];
|
|
909
909
|
client.unstable_onResponseCallbacks = [];
|
|
910
910
|
expect(response).toEqual(newData);
|
|
@@ -921,13 +921,13 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
921
921
|
onStartTime: () => null,
|
|
922
922
|
internalErrorMapping: (error) => error,
|
|
923
923
|
});
|
|
924
|
-
const response = await onAbortError({ status: 0, extra:
|
|
924
|
+
const response = await onAbortError({ status: 0, extra: httpExtra });
|
|
925
925
|
expect(response).toEqual({
|
|
926
926
|
data: null,
|
|
927
927
|
error: getErrorMessage("abort"),
|
|
928
928
|
status: 0,
|
|
929
929
|
success: false,
|
|
930
|
-
extra:
|
|
930
|
+
extra: httpExtra,
|
|
931
931
|
requestTimestamp: expect.toBeNumber(),
|
|
932
932
|
responseTimestamp: expect.toBeNumber(),
|
|
933
933
|
} satisfies ResponseErrorType<any, HttpAdapterType>);
|
|
@@ -940,13 +940,13 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
940
940
|
onStartTime: () => null,
|
|
941
941
|
internalErrorMapping: (error) => error,
|
|
942
942
|
});
|
|
943
|
-
const response = await onTimeoutError({ status: 0, extra:
|
|
943
|
+
const response = await onTimeoutError({ status: 0, extra: httpExtra });
|
|
944
944
|
expect(response).toEqual({
|
|
945
945
|
data: null,
|
|
946
946
|
error: getErrorMessage("timeout"),
|
|
947
947
|
status: 0,
|
|
948
948
|
success: false,
|
|
949
|
-
extra:
|
|
949
|
+
extra: httpExtra,
|
|
950
950
|
requestTimestamp: expect.toBeNumber(),
|
|
951
951
|
responseTimestamp: expect.toBeNumber(),
|
|
952
952
|
} satisfies ResponseErrorType<any, HttpAdapterType>);
|
|
@@ -959,13 +959,13 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
959
959
|
onStartTime: () => null,
|
|
960
960
|
internalErrorMapping: (error) => error,
|
|
961
961
|
});
|
|
962
|
-
const response = await onUnexpectedError({ status: 0, extra:
|
|
962
|
+
const response = await onUnexpectedError({ status: 0, extra: httpExtra });
|
|
963
963
|
expect(response).toEqual({
|
|
964
964
|
data: null,
|
|
965
965
|
error: getErrorMessage(),
|
|
966
966
|
status: 0,
|
|
967
967
|
success: false,
|
|
968
|
-
extra:
|
|
968
|
+
extra: httpExtra,
|
|
969
969
|
requestTimestamp: expect.toBeNumber(),
|
|
970
970
|
responseTimestamp: expect.toBeNumber(),
|
|
971
971
|
} satisfies ResponseErrorType<any, HttpAdapterType>);
|
|
@@ -983,7 +983,7 @@ describe("Adapter [ Bindings ]", () => {
|
|
|
983
983
|
internalErrorMapping: (internalError) => ({ mapped: internalError }),
|
|
984
984
|
});
|
|
985
985
|
|
|
986
|
-
const response = await bindings[method]({ status: 0, extra:
|
|
986
|
+
const response = await bindings[method]({ status: 0, extra: httpExtra });
|
|
987
987
|
|
|
988
988
|
expect(response.error).toEqual({ mapped: error });
|
|
989
989
|
});
|
|
@@ -2,7 +2,7 @@ import { createHttpMockingServer, sleep } from "@hyper-fetch/testing";
|
|
|
2
2
|
import type { ResponseSuccessType } from "adapter";
|
|
3
3
|
import { Client } from "client";
|
|
4
4
|
import type { HttpAdapterType } from "http-adapter";
|
|
5
|
-
import {
|
|
5
|
+
import { httpExtra } from "http-adapter";
|
|
6
6
|
import type { ResponseDetailsType } from "managers";
|
|
7
7
|
|
|
8
8
|
import { createCache } from "../../utils";
|
|
@@ -15,7 +15,7 @@ describe("Cache [ Base ]", () => {
|
|
|
15
15
|
error: null,
|
|
16
16
|
status: 200,
|
|
17
17
|
success: true,
|
|
18
|
-
extra:
|
|
18
|
+
extra: httpExtra,
|
|
19
19
|
requestTimestamp: Date.now(),
|
|
20
20
|
responseTimestamp: Date.now(),
|
|
21
21
|
};
|
|
@@ -311,7 +311,7 @@ describe("Cache [ Base ]", () => {
|
|
|
311
311
|
responseTimestamp: Date.now(),
|
|
312
312
|
error: null,
|
|
313
313
|
status: 200,
|
|
314
|
-
extra:
|
|
314
|
+
extra: httpExtra,
|
|
315
315
|
requestTimestamp: Date.now(),
|
|
316
316
|
retries: 0,
|
|
317
317
|
isCanceled: false,
|
|
@@ -406,7 +406,7 @@ describe("Cache [ Base ]", () => {
|
|
|
406
406
|
responseTimestamp: Date.now(),
|
|
407
407
|
error: null,
|
|
408
408
|
status: 200,
|
|
409
|
-
extra:
|
|
409
|
+
extra: httpExtra,
|
|
410
410
|
requestTimestamp: Date.now(),
|
|
411
411
|
retries: 0,
|
|
412
412
|
isCanceled: false,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sleep } from "@hyper-fetch/testing";
|
|
2
2
|
import type { CacheValueType } from "cache";
|
|
3
3
|
import { Client } from "client";
|
|
4
|
-
import {
|
|
4
|
+
import { httpExtra } from "http-adapter";
|
|
5
5
|
import { Plugin } from "plugin";
|
|
6
6
|
|
|
7
7
|
import { createCache } from "../../utils";
|
|
@@ -19,7 +19,7 @@ describe("Cache [ Events ]", () => {
|
|
|
19
19
|
error: null,
|
|
20
20
|
status: 200,
|
|
21
21
|
success: true,
|
|
22
|
-
extra:
|
|
22
|
+
extra: httpExtra,
|
|
23
23
|
retries: 0,
|
|
24
24
|
requestTimestamp: Date.now(),
|
|
25
25
|
responseTimestamp: Date.now(),
|
|
@@ -149,7 +149,7 @@ describe("Cache [ Events ]", () => {
|
|
|
149
149
|
error: null,
|
|
150
150
|
status: 200,
|
|
151
151
|
success: true,
|
|
152
|
-
extra:
|
|
152
|
+
extra: httpExtra,
|
|
153
153
|
retries: 0,
|
|
154
154
|
requestTimestamp: Date.now(),
|
|
155
155
|
responseTimestamp: Date.now(),
|
|
@@ -170,7 +170,7 @@ describe("Cache [ Events ]", () => {
|
|
|
170
170
|
error: null,
|
|
171
171
|
status: 200,
|
|
172
172
|
success: true,
|
|
173
|
-
extra:
|
|
173
|
+
extra: httpExtra,
|
|
174
174
|
retries: 0,
|
|
175
175
|
requestTimestamp: Date.now(),
|
|
176
176
|
responseTimestamp: Date.now(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { waitFor } from "@testing-library/dom";
|
|
2
2
|
import type { CacheValueType } from "cache";
|
|
3
|
-
import { Client, Time,
|
|
3
|
+
import { Client, Time, httpExtra } from "index";
|
|
4
4
|
|
|
5
5
|
import { createCache, createLazyCacheAdapter } from "../../utils";
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ describe("Cache [ Garbage Collector ]", () => {
|
|
|
14
14
|
error: null,
|
|
15
15
|
status: 200,
|
|
16
16
|
success: true,
|
|
17
|
-
extra:
|
|
17
|
+
extra: httpExtra,
|
|
18
18
|
retries: 0,
|
|
19
19
|
requestTimestamp: Date.now(),
|
|
20
20
|
responseTimestamp: Date.now(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sleep } from "@hyper-fetch/testing";
|
|
2
2
|
import type { CacheAsyncStorageType, CacheValueType } from "cache";
|
|
3
3
|
import { Client } from "client";
|
|
4
|
-
import {
|
|
4
|
+
import { httpExtra } from "http-adapter";
|
|
5
5
|
|
|
6
6
|
import { createCache, createLazyCacheAdapter } from "../../utils";
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ describe("Cache [ Lazy Storage ]", () => {
|
|
|
14
14
|
error: null,
|
|
15
15
|
status: 200,
|
|
16
16
|
success: true,
|
|
17
|
-
extra:
|
|
17
|
+
extra: httpExtra,
|
|
18
18
|
retries: 0,
|
|
19
19
|
addedTimestamp: Date.now(),
|
|
20
20
|
requestTimestamp: Date.now(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResponseSuccessType } from "adapter";
|
|
2
2
|
import { Client } from "client";
|
|
3
3
|
import type { HttpAdapterType } from "http-adapter";
|
|
4
|
-
import {
|
|
4
|
+
import { httpExtra } from "http-adapter";
|
|
5
5
|
import type { ResponseDetailsType } from "managers";
|
|
6
6
|
|
|
7
7
|
import { createCache } from "../../utils";
|
|
@@ -14,7 +14,7 @@ describe("Cache [ Modes ]", () => {
|
|
|
14
14
|
error: null,
|
|
15
15
|
status: 200,
|
|
16
16
|
success: true,
|
|
17
|
-
extra:
|
|
17
|
+
extra: httpExtra,
|
|
18
18
|
requestTimestamp: Date.now(),
|
|
19
19
|
responseTimestamp: Date.now(),
|
|
20
20
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from "client";
|
|
2
|
-
import {
|
|
2
|
+
import { httpExtra } from "http-adapter";
|
|
3
3
|
import { scopeKey } from "request";
|
|
4
4
|
|
|
5
5
|
const createResponse = (data: unknown) => ({
|
|
@@ -7,7 +7,7 @@ const createResponse = (data: unknown) => ({
|
|
|
7
7
|
error: null,
|
|
8
8
|
status: 200,
|
|
9
9
|
success: true as const,
|
|
10
|
-
extra:
|
|
10
|
+
extra: httpExtra,
|
|
11
11
|
retries: 0,
|
|
12
12
|
isCanceled: false,
|
|
13
13
|
isOffline: false,
|
|
@@ -2,7 +2,7 @@ import { waitFor } from "@testing-library/dom";
|
|
|
2
2
|
import type { ResponseSuccessType } from "adapter";
|
|
3
3
|
import { Client } from "client";
|
|
4
4
|
import type { HttpAdapterType } from "http-adapter";
|
|
5
|
-
import {
|
|
5
|
+
import { httpExtra } from "http-adapter";
|
|
6
6
|
import type { ResponseDetailsType } from "managers";
|
|
7
7
|
import { scopeKey } from "request";
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ describe("Cache [ Scoping ]", () => {
|
|
|
14
14
|
error: null,
|
|
15
15
|
status: 200,
|
|
16
16
|
success: true,
|
|
17
|
-
extra:
|
|
17
|
+
extra: httpExtra,
|
|
18
18
|
requestTimestamp: Date.now(),
|
|
19
19
|
responseTimestamp: Date.now(),
|
|
20
20
|
};
|
|
@@ -18,6 +18,7 @@ describe("Cache [ Semantics ]", () => {
|
|
|
18
18
|
|
|
19
19
|
afterEach(() => {
|
|
20
20
|
client.cache.clear();
|
|
21
|
+
vi.useRealTimers();
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
describe("When reading the data", () => {
|
|
@@ -255,8 +256,12 @@ describe("Cache [ Semantics ]", () => {
|
|
|
255
256
|
});
|
|
256
257
|
|
|
257
258
|
it("should merge the partial response with the cached element", () => {
|
|
259
|
+
// The update stamps its own time, so the clock is pinned: set and update must not share a millisecond by luck
|
|
260
|
+
vi.useFakeTimers({ toFake: ["Date"] });
|
|
261
|
+
vi.setSystemTime(1_000);
|
|
258
262
|
const response = createCacheResponse<User>({ id: 1, name: "Kate" }, { status: 201 });
|
|
259
263
|
client.cache.set(request, response);
|
|
264
|
+
vi.setSystemTime(2_000);
|
|
260
265
|
|
|
261
266
|
client.cache.update(request, { data: { id: 1, name: "Maya" } });
|
|
262
267
|
|
|
@@ -265,7 +270,7 @@ describe("Cache [ Semantics ]", () => {
|
|
|
265
270
|
data: { id: 1, name: "Maya" },
|
|
266
271
|
status: 201,
|
|
267
272
|
success: true,
|
|
268
|
-
responseTimestamp:
|
|
273
|
+
responseTimestamp: 2_000,
|
|
269
274
|
requestTimestamp: response.requestTimestamp,
|
|
270
275
|
}),
|
|
271
276
|
);
|
|
@@ -3,7 +3,7 @@ import { expectFunctionParametersType, expectNotFunctionParametersType } from "@
|
|
|
3
3
|
import type { ResponseSuccessType } from "adapter";
|
|
4
4
|
import { Client } from "client";
|
|
5
5
|
import type { HttpAdapterType } from "http-adapter";
|
|
6
|
-
import {
|
|
6
|
+
import { httpExtra } from "http-adapter";
|
|
7
7
|
import type { ResponseDetailsType } from "managers";
|
|
8
8
|
|
|
9
9
|
import { createCache } from "../../utils";
|
|
@@ -37,7 +37,7 @@ const successResponse: ResponseSuccessType<UserResponse, HttpAdapterType> & Resp
|
|
|
37
37
|
error: null,
|
|
38
38
|
status: 200,
|
|
39
39
|
success: true,
|
|
40
|
-
extra:
|
|
40
|
+
extra: httpExtra,
|
|
41
41
|
requestTimestamp: Date.now(),
|
|
42
42
|
responseTimestamp: Date.now(),
|
|
43
43
|
retries: 0,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResponseErrorType, ResponseSuccessType } from "adapter";
|
|
2
2
|
import { getCacheData, getCacheByKey, getInvalidateByKey } from "cache";
|
|
3
3
|
import type { HttpAdapterType } from "http-adapter";
|
|
4
|
-
import {
|
|
4
|
+
import { httpExtra } from "http-adapter";
|
|
5
5
|
import type { ResponseDetailsType } from "managers";
|
|
6
6
|
|
|
7
7
|
describe("Cache [ Utils ]", () => {
|
|
@@ -12,14 +12,14 @@ describe("Cache [ Utils ]", () => {
|
|
|
12
12
|
error: null,
|
|
13
13
|
status: 200,
|
|
14
14
|
success: true,
|
|
15
|
-
extra:
|
|
15
|
+
extra: httpExtra,
|
|
16
16
|
} as unknown as Parameters<typeof getCacheData>[0];
|
|
17
17
|
const response = {
|
|
18
18
|
data,
|
|
19
19
|
error: null,
|
|
20
20
|
status: 200,
|
|
21
21
|
success: true,
|
|
22
|
-
extra:
|
|
22
|
+
extra: httpExtra,
|
|
23
23
|
} as unknown as Parameters<typeof getCacheData>[1];
|
|
24
24
|
|
|
25
25
|
expect(getCacheData(previousResponse, response).data).toBe(data);
|
|
@@ -29,14 +29,14 @@ describe("Cache [ Utils ]", () => {
|
|
|
29
29
|
data: {},
|
|
30
30
|
error: null,
|
|
31
31
|
status: 200,
|
|
32
|
-
extra:
|
|
32
|
+
extra: httpExtra,
|
|
33
33
|
} as ResponseSuccessType<Record<string, string>, HttpAdapterType>;
|
|
34
34
|
const errorResponse: ResponseErrorType<Record<string, string>, HttpAdapterType> & ResponseDetailsType = {
|
|
35
35
|
data: null,
|
|
36
36
|
error: {},
|
|
37
37
|
status: 400,
|
|
38
38
|
success: false,
|
|
39
|
-
extra:
|
|
39
|
+
extra: httpExtra,
|
|
40
40
|
retries: 0,
|
|
41
41
|
requestTimestamp: Date.now(),
|
|
42
42
|
responseTimestamp: Date.now(),
|
|
@@ -70,7 +70,7 @@ describe("Cache [ Utils ]", () => {
|
|
|
70
70
|
error: null,
|
|
71
71
|
status: 200,
|
|
72
72
|
success: true,
|
|
73
|
-
extra:
|
|
73
|
+
extra: httpExtra,
|
|
74
74
|
retries: 0,
|
|
75
75
|
requestTimestamp: Date.now(),
|
|
76
76
|
responseTimestamp: Date.now(),
|
|
@@ -85,7 +85,7 @@ describe("Cache [ Utils ]", () => {
|
|
|
85
85
|
error: null,
|
|
86
86
|
status: 200,
|
|
87
87
|
success: true,
|
|
88
|
-
extra:
|
|
88
|
+
extra: httpExtra,
|
|
89
89
|
retries: 0,
|
|
90
90
|
requestTimestamp: Date.now(),
|
|
91
91
|
responseTimestamp: Date.now(),
|
|
@@ -104,7 +104,7 @@ describe("Cache [ Utils ]", () => {
|
|
|
104
104
|
error: null,
|
|
105
105
|
status: 200,
|
|
106
106
|
success: true,
|
|
107
|
-
extra:
|
|
107
|
+
extra: httpExtra,
|
|
108
108
|
retries: 0,
|
|
109
109
|
requestTimestamp: expect.toBeNumber(),
|
|
110
110
|
responseTimestamp: expect.toBeNumber(),
|
|
@@ -119,7 +119,7 @@ describe("Cache [ Utils ]", () => {
|
|
|
119
119
|
error: {},
|
|
120
120
|
status: 400,
|
|
121
121
|
success: false,
|
|
122
|
-
extra:
|
|
122
|
+
extra: httpExtra,
|
|
123
123
|
retries: 0,
|
|
124
124
|
requestTimestamp: expect.toBeNumber(),
|
|
125
125
|
responseTimestamp: expect.toBeNumber(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResponseType } from "adapter";
|
|
2
2
|
import { Client } from "client";
|
|
3
3
|
import type { HttpAdapterType } from "http-adapter";
|
|
4
|
-
import {
|
|
4
|
+
import { httpExtra } from "http-adapter";
|
|
5
5
|
import { scopeKey } from "request";
|
|
6
6
|
import type { HydrateDataType } from "types";
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ const createResponse = <Data>(
|
|
|
15
15
|
error: null,
|
|
16
16
|
status: 200,
|
|
17
17
|
success: true,
|
|
18
|
-
extra:
|
|
18
|
+
extra: httpExtra,
|
|
19
19
|
requestTimestamp: Date.now(),
|
|
20
20
|
responseTimestamp: Date.now(),
|
|
21
21
|
...overrides,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CacheValueType } from "cache";
|
|
2
2
|
import { Client } from "client";
|
|
3
|
-
import {
|
|
3
|
+
import { httpExtra } from "http-adapter";
|
|
4
4
|
import { scopeKey } from "request";
|
|
5
5
|
|
|
6
6
|
describe("Client [ Hydration ]", () => {
|
|
@@ -200,7 +200,7 @@ describe("Client [ Hydration ]", () => {
|
|
|
200
200
|
status: 200,
|
|
201
201
|
success: true,
|
|
202
202
|
error: null,
|
|
203
|
-
extra:
|
|
203
|
+
extra: httpExtra,
|
|
204
204
|
requestTimestamp: ts,
|
|
205
205
|
responseTimestamp: ts,
|
|
206
206
|
},
|
|
@@ -217,7 +217,7 @@ describe("Client [ Hydration ]", () => {
|
|
|
217
217
|
error: null,
|
|
218
218
|
status: 200,
|
|
219
219
|
success: true,
|
|
220
|
-
extra:
|
|
220
|
+
extra: httpExtra,
|
|
221
221
|
retries: 0,
|
|
222
222
|
requestTimestamp: Date.now(),
|
|
223
223
|
responseTimestamp: Date.now(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHttpMockingServer } from "@hyper-fetch/testing";
|
|
2
2
|
import { Client } from "client";
|
|
3
|
-
import {
|
|
3
|
+
import { httpExtra } from "http-adapter";
|
|
4
4
|
|
|
5
5
|
import { testCallbacksExecution } from "../../shared";
|
|
6
6
|
import { interceptorCallback } from "../../utils";
|
|
@@ -70,7 +70,7 @@ describe("Client [ Interceptor ]", () => {
|
|
|
70
70
|
error: null,
|
|
71
71
|
status: 400,
|
|
72
72
|
success: false,
|
|
73
|
-
extra:
|
|
73
|
+
extra: httpExtra,
|
|
74
74
|
responseTimestamp: Date.now(),
|
|
75
75
|
requestTimestamp: Date.now(),
|
|
76
76
|
},
|
|
@@ -91,7 +91,7 @@ describe("Client [ Interceptor ]", () => {
|
|
|
91
91
|
error: null,
|
|
92
92
|
status: 400,
|
|
93
93
|
success: false,
|
|
94
|
-
extra:
|
|
94
|
+
extra: httpExtra,
|
|
95
95
|
responseTimestamp: Date.now(),
|
|
96
96
|
requestTimestamp: Date.now(),
|
|
97
97
|
},
|
|
@@ -112,7 +112,7 @@ describe("Client [ Interceptor ]", () => {
|
|
|
112
112
|
error: null,
|
|
113
113
|
status: 400,
|
|
114
114
|
success: false,
|
|
115
|
-
extra:
|
|
115
|
+
extra: httpExtra,
|
|
116
116
|
requestTimestamp: Date.now(),
|
|
117
117
|
responseTimestamp: Date.now(),
|
|
118
118
|
},
|
|
@@ -133,7 +133,7 @@ describe("Client [ Interceptor ]", () => {
|
|
|
133
133
|
error: null,
|
|
134
134
|
status: 400,
|
|
135
135
|
success: false,
|
|
136
|
-
extra:
|
|
136
|
+
extra: httpExtra,
|
|
137
137
|
requestTimestamp: Date.now(),
|
|
138
138
|
responseTimestamp: Date.now(),
|
|
139
139
|
},
|
|
@@ -154,7 +154,7 @@ describe("Client [ Interceptor ]", () => {
|
|
|
154
154
|
error: null,
|
|
155
155
|
status: 400,
|
|
156
156
|
success: false,
|
|
157
|
-
extra:
|
|
157
|
+
extra: httpExtra,
|
|
158
158
|
requestTimestamp: Date.now(),
|
|
159
159
|
responseTimestamp: Date.now(),
|
|
160
160
|
},
|
|
@@ -175,7 +175,7 @@ describe("Client [ Interceptor ]", () => {
|
|
|
175
175
|
error: null,
|
|
176
176
|
status: 400,
|
|
177
177
|
success: false,
|
|
178
|
-
extra:
|
|
178
|
+
extra: httpExtra,
|
|
179
179
|
requestTimestamp: Date.now(),
|
|
180
180
|
responseTimestamp: Date.now(),
|
|
181
181
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResponseType } from "adapter";
|
|
2
2
|
import { Client } from "client";
|
|
3
3
|
import type { HttpAdapterType } from "http-adapter";
|
|
4
|
-
import {
|
|
4
|
+
import { httpExtra } from "http-adapter";
|
|
5
5
|
import { LoggerManager } from "managers";
|
|
6
6
|
import type { RequestInstance } from "request";
|
|
7
7
|
|
|
@@ -18,7 +18,7 @@ const createResponse = (
|
|
|
18
18
|
error: null,
|
|
19
19
|
status: 200,
|
|
20
20
|
success: true,
|
|
21
|
-
extra:
|
|
21
|
+
extra: httpExtra,
|
|
22
22
|
requestTimestamp: Date.now(),
|
|
23
23
|
responseTimestamp: Date.now(),
|
|
24
24
|
...overrides,
|
|
@@ -544,7 +544,7 @@ describe("Client [ Interceptors Pipeline ]", () => {
|
|
|
544
544
|
error: new Error("Interceptor failed"),
|
|
545
545
|
status: 0,
|
|
546
546
|
success: false,
|
|
547
|
-
extra:
|
|
547
|
+
extra: httpExtra,
|
|
548
548
|
requestTimestamp: 100,
|
|
549
549
|
responseTimestamp: 200,
|
|
550
550
|
});
|
|
@@ -3,7 +3,7 @@ import type { ResponseSuccessType } from "adapter";
|
|
|
3
3
|
import { getErrorMessage } from "adapter";
|
|
4
4
|
import { Client } from "client";
|
|
5
5
|
import type { HttpAdapterType } from "http-adapter";
|
|
6
|
-
import {
|
|
6
|
+
import { httpExtra } from "http-adapter";
|
|
7
7
|
import type { ResponseDetailsType } from "managers";
|
|
8
8
|
import { http, HttpResponse } from "msw";
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ describe("Client [ setUrl ]", () => {
|
|
|
15
15
|
error: null,
|
|
16
16
|
status: 200,
|
|
17
17
|
success: true,
|
|
18
|
-
extra:
|
|
18
|
+
extra: httpExtra,
|
|
19
19
|
requestTimestamp: Date.now(),
|
|
20
20
|
responseTimestamp: Date.now(),
|
|
21
21
|
};
|