@hyper-fetch/core 7.5.3 → 8.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 (270) hide show
  1. package/.eslintrc.cjs +12 -0
  2. package/__tests__/e2e/e2e.abort-timeout.spec.ts +101 -0
  3. package/__tests__/e2e/e2e.advanced.spec.ts +423 -0
  4. package/__tests__/e2e/e2e.methods.spec.ts +243 -0
  5. package/__tests__/e2e/e2e.payloads.spec.ts +154 -0
  6. package/__tests__/features/adapter/adapter.base.spec.ts +44 -17
  7. package/__tests__/features/adapter/adapter.bindings.spec.ts +35 -33
  8. package/__tests__/features/adapter/adapter.browser.spec.ts +5 -20
  9. package/__tests__/features/adapter/adapter.server.spec.ts +229 -37
  10. package/__tests__/features/cache/cache.base.spec.ts +23 -15
  11. package/__tests__/features/cache/cache.events.spec.ts +9 -5
  12. package/__tests__/features/cache/cache.garbage-collector.spec.ts +9 -6
  13. package/__tests__/features/cache/cache.lazy-storage.spec.ts +11 -8
  14. package/__tests__/features/cache/cache.modes.spec.ts +145 -0
  15. package/__tests__/features/cache/cache.scoping.spec.ts +171 -0
  16. package/__tests__/features/cache/cache.typescript.spec.ts +147 -0
  17. package/__tests__/features/cache/cache.utils.spec.ts +10 -3
  18. package/__tests__/features/client/client.auth.spec.ts +5 -5
  19. package/__tests__/features/client/client.base.spec.ts +16 -4
  20. package/__tests__/features/client/client.from-json.spec.ts +182 -0
  21. package/__tests__/features/client/client.hydration.spec.ts +69 -4
  22. package/__tests__/features/client/client.interceptor.spec.ts +4 -4
  23. package/__tests__/features/client/client.methods.spec.ts +5 -4
  24. package/__tests__/features/client/client.middleware.spec.ts +4 -4
  25. package/__tests__/features/client/client.utils.spec.ts +3 -3
  26. package/__tests__/features/dispatcher/dispatcher.base.spec.ts +8 -8
  27. package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +189 -0
  28. package/__tests__/features/dispatcher/dispatcher.events.spec.ts +17 -12
  29. package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +31 -31
  30. package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +15 -15
  31. package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +22 -5
  32. package/__tests__/features/managers/app/app.manager.base.spec.ts +23 -23
  33. package/__tests__/features/managers/app/app.manager.ssr.spec.ts +6 -3
  34. package/__tests__/features/managers/logger/logger.base.spec.ts +4 -2
  35. package/__tests__/features/managers/logger/logger.utils.spec.ts +10 -4
  36. package/__tests__/features/managers/request/request.manager.base.spec.ts +21 -19
  37. package/__tests__/features/managers/request/request.manager.events.spec.ts +137 -53
  38. package/__tests__/features/mocker/mocker.base.spec.ts +82 -10
  39. package/__tests__/features/plugin/plugin.base.spec.ts +19 -19
  40. package/__tests__/features/request/request.base.spec.ts +39 -13
  41. package/__tests__/features/request/request.cloning.spec.ts +1 -1
  42. package/__tests__/features/request/request.hooks.spec.ts +173 -0
  43. package/__tests__/features/request/request.optimistic.spec.ts +93 -0
  44. package/__tests__/features/request/request.retry-on-error.spec.ts +359 -0
  45. package/__tests__/features/request/request.sending.spec.ts +107 -15
  46. package/__tests__/features/request/request.setters.spec.ts +11 -4
  47. package/__tests__/features/request/request.typescript.spec.ts +1 -1
  48. package/__tests__/features/request/request.utils.spec.ts +2 -2
  49. package/__tests__/features/sdk/sdk.base.spec.ts +5 -3
  50. package/__tests__/features/sdk/sdk.configuration.spec.ts +262 -0
  51. package/__tests__/features/utils/emitter.utils.spec.ts +88 -0
  52. package/__tests__/shared/callbacks.shared.ts +3 -1
  53. package/__tests__/shared/progress.shared.ts +2 -1
  54. package/__tests__/tsconfig.json +14 -3
  55. package/__tests__/type-stress/generate-stress-test.ts +92 -0
  56. package/__tests__/type-stress/stress-10.ts +35 -0
  57. package/__tests__/type-stress/stress-just-create.ts +2107 -0
  58. package/__tests__/type-stress/stress-minimal.ts +23 -0
  59. package/__tests__/type-stress/stress-test-500.ts +2319 -0
  60. package/__tests__/type-stress/stress-test-sdk.ts +210 -0
  61. package/__tests__/type-stress/tsconfig.json +6 -0
  62. package/__tests__/utils/adapter.utils.ts +3 -2
  63. package/__tests__/utils/cache.utils.ts +3 -2
  64. package/__tests__/utils/callbacks.utils.ts +5 -4
  65. package/__tests__/utils/dispatcher.utils.ts +3 -2
  66. package/__tests__/vitest.setup.ts +15 -0
  67. package/dist/adapter/adapter.bindings.d.ts +71 -0
  68. package/dist/adapter/adapter.bindings.d.ts.map +1 -0
  69. package/dist/adapter/adapter.d.ts +127 -0
  70. package/dist/adapter/adapter.d.ts.map +1 -0
  71. package/dist/adapter/adapter.types.d.ts +108 -0
  72. package/dist/adapter/adapter.types.d.ts.map +1 -0
  73. package/dist/adapter/adapter.utils.d.ts +23 -0
  74. package/dist/adapter/adapter.utils.d.ts.map +1 -0
  75. package/dist/adapter/index.d.ts +5 -0
  76. package/dist/adapter/index.d.ts.map +1 -0
  77. package/dist/cache/cache.d.ts +95 -0
  78. package/dist/cache/cache.d.ts.map +1 -0
  79. package/dist/cache/cache.events.d.ts +51 -0
  80. package/dist/cache/cache.events.d.ts.map +1 -0
  81. package/dist/cache/cache.types.d.ts +44 -0
  82. package/dist/cache/cache.types.d.ts.map +1 -0
  83. package/dist/cache/cache.utils.d.ts +11 -0
  84. package/dist/cache/cache.utils.d.ts.map +1 -0
  85. package/dist/cache/index.d.ts +5 -0
  86. package/dist/cache/index.d.ts.map +1 -0
  87. package/dist/client/client.constants.d.ts +10 -0
  88. package/dist/client/client.constants.d.ts.map +1 -0
  89. package/dist/client/client.create.d.ts +8 -0
  90. package/dist/client/client.create.d.ts.map +1 -0
  91. package/dist/client/client.d.ts +195 -0
  92. package/dist/client/client.d.ts.map +1 -0
  93. package/dist/client/client.types.d.ts +71 -0
  94. package/dist/client/client.types.d.ts.map +1 -0
  95. package/dist/client/client.utils.d.ts +11 -0
  96. package/dist/client/client.utils.d.ts.map +1 -0
  97. package/dist/client/index.d.ts +6 -0
  98. package/dist/client/index.d.ts.map +1 -0
  99. package/dist/constants/http.constants.d.ts +8 -0
  100. package/dist/constants/http.constants.d.ts.map +1 -0
  101. package/dist/constants/time.constants.d.ts +12 -0
  102. package/dist/constants/time.constants.d.ts.map +1 -0
  103. package/dist/dispatcher/dispatcher.constants.d.ts +7 -0
  104. package/dist/dispatcher/dispatcher.constants.d.ts.map +1 -0
  105. package/dist/dispatcher/dispatcher.d.ts +168 -0
  106. package/dist/dispatcher/dispatcher.d.ts.map +1 -0
  107. package/dist/dispatcher/dispatcher.events.d.ts +49 -0
  108. package/dist/dispatcher/dispatcher.events.d.ts.map +1 -0
  109. package/dist/dispatcher/dispatcher.types.d.ts +44 -0
  110. package/dist/dispatcher/dispatcher.types.d.ts.map +1 -0
  111. package/dist/dispatcher/dispatcher.utils.d.ts +12 -0
  112. package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -0
  113. package/dist/dispatcher/index.d.ts +6 -0
  114. package/dist/dispatcher/index.d.ts.map +1 -0
  115. package/dist/http-adapter/http-adapter.constants.d.ts +4 -0
  116. package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -0
  117. package/dist/http-adapter/http-adapter.d.ts +3 -0
  118. package/dist/http-adapter/http-adapter.d.ts.map +1 -0
  119. package/dist/http-adapter/http-adapter.fetch.d.ts +6 -0
  120. package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -0
  121. package/dist/http-adapter/http-adapter.types.d.ts +73 -0
  122. package/dist/http-adapter/http-adapter.types.d.ts.map +1 -0
  123. package/dist/http-adapter/http-adapter.utils.d.ts +10 -0
  124. package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -0
  125. package/dist/http-adapter/index.d.ts +6 -0
  126. package/dist/http-adapter/index.d.ts.map +1 -0
  127. package/dist/index.d.ts +15 -2083
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.mjs +4084 -0
  130. package/dist/index.mjs.map +1 -0
  131. package/dist/managers/app/app.manager.constants.d.ts +10 -0
  132. package/dist/managers/app/app.manager.constants.d.ts.map +1 -0
  133. package/dist/managers/app/app.manager.d.ts +35 -0
  134. package/dist/managers/app/app.manager.d.ts.map +1 -0
  135. package/dist/managers/app/app.manager.events.d.ts +12 -0
  136. package/dist/managers/app/app.manager.events.d.ts.map +1 -0
  137. package/dist/managers/app/app.manager.types.d.ts +7 -0
  138. package/dist/managers/app/app.manager.types.d.ts.map +1 -0
  139. package/dist/managers/app/app.manager.utils.d.ts +5 -0
  140. package/dist/managers/app/app.manager.utils.d.ts.map +1 -0
  141. package/dist/managers/app/index.d.ts +6 -0
  142. package/dist/managers/app/index.d.ts.map +1 -0
  143. package/dist/managers/index.d.ts +4 -0
  144. package/dist/managers/index.d.ts.map +1 -0
  145. package/dist/managers/logger/index.d.ts +5 -0
  146. package/dist/managers/logger/index.d.ts.map +1 -0
  147. package/dist/managers/logger/logger.manager.constants.d.ts +5 -0
  148. package/dist/managers/logger/logger.manager.constants.d.ts.map +1 -0
  149. package/dist/managers/logger/logger.manager.d.ts +22 -0
  150. package/dist/managers/logger/logger.manager.d.ts.map +1 -0
  151. package/dist/managers/logger/logger.manager.types.d.ts +43 -0
  152. package/dist/managers/logger/logger.manager.types.d.ts.map +1 -0
  153. package/dist/managers/logger/logger.manager.utils.d.ts +4 -0
  154. package/dist/managers/logger/logger.manager.utils.d.ts.map +1 -0
  155. package/dist/managers/request/index.d.ts +5 -0
  156. package/dist/managers/request/index.d.ts.map +1 -0
  157. package/dist/managers/request/request.manager.d.ts +60 -0
  158. package/dist/managers/request/request.manager.d.ts.map +1 -0
  159. package/dist/managers/request/request.manager.events.d.ts +55 -0
  160. package/dist/managers/request/request.manager.events.d.ts.map +1 -0
  161. package/dist/managers/request/request.manager.types.d.ts +48 -0
  162. package/dist/managers/request/request.manager.types.d.ts.map +1 -0
  163. package/dist/managers/request/request.manager.utils.d.ts +30 -0
  164. package/dist/managers/request/request.manager.utils.d.ts.map +1 -0
  165. package/dist/mocker/index.d.ts +3 -0
  166. package/dist/mocker/index.d.ts.map +1 -0
  167. package/dist/mocker/mocker.d.ts +3 -0
  168. package/dist/mocker/mocker.d.ts.map +1 -0
  169. package/dist/mocker/mocker.types.d.ts +25 -0
  170. package/dist/mocker/mocker.types.d.ts.map +1 -0
  171. package/dist/plugin/index.d.ts +3 -0
  172. package/dist/plugin/index.d.ts.map +1 -0
  173. package/dist/plugin/plugin.d.ts +55 -0
  174. package/dist/plugin/plugin.d.ts.map +1 -0
  175. package/dist/plugin/plugin.types.d.ts +122 -0
  176. package/dist/plugin/plugin.types.d.ts.map +1 -0
  177. package/dist/request/index.d.ts +5 -0
  178. package/dist/request/index.d.ts.map +1 -0
  179. package/dist/request/request.d.ts +195 -0
  180. package/dist/request/request.d.ts.map +1 -0
  181. package/dist/request/request.hooks.d.ts +19 -0
  182. package/dist/request/request.hooks.d.ts.map +1 -0
  183. package/dist/request/request.types.d.ts +240 -0
  184. package/dist/request/request.types.d.ts.map +1 -0
  185. package/dist/request/request.utils.d.ts +25 -0
  186. package/dist/request/request.utils.d.ts.map +1 -0
  187. package/dist/sdk/index.d.ts +2 -0
  188. package/dist/sdk/index.d.ts.map +1 -0
  189. package/dist/sdk/sdk.d.ts +69 -0
  190. package/dist/sdk/sdk.d.ts.map +1 -0
  191. package/dist/types/adapter.types.d.ts +22 -0
  192. package/dist/types/adapter.types.d.ts.map +1 -0
  193. package/dist/types/client.types.d.ts +4 -0
  194. package/dist/types/client.types.d.ts.map +1 -0
  195. package/dist/types/helpers.types.d.ts +17 -0
  196. package/dist/types/helpers.types.d.ts.map +1 -0
  197. package/dist/types/http.types.d.ts +3 -0
  198. package/dist/types/http.types.d.ts.map +1 -0
  199. package/dist/types/hydration.types.d.ts +15 -0
  200. package/dist/types/hydration.types.d.ts.map +1 -0
  201. package/dist/types/index.d.ts +7 -0
  202. package/dist/types/index.d.ts.map +1 -0
  203. package/dist/types/request.types.d.ts +34 -0
  204. package/dist/types/request.types.d.ts.map +1 -0
  205. package/dist/utils/emitter.utils.d.ts +13 -0
  206. package/dist/utils/emitter.utils.d.ts.map +1 -0
  207. package/dist/utils/index.d.ts +3 -0
  208. package/dist/utils/index.d.ts.map +1 -0
  209. package/dist/utils/uuid.utils.d.ts +3 -0
  210. package/dist/utils/uuid.utils.d.ts.map +1 -0
  211. package/package.json +10 -25
  212. package/src/adapter/adapter.bindings.ts +8 -12
  213. package/src/adapter/adapter.ts +8 -7
  214. package/src/adapter/adapter.types.ts +10 -6
  215. package/src/adapter/adapter.utils.ts +1 -1
  216. package/src/cache/cache.events.ts +4 -11
  217. package/src/cache/cache.ts +28 -22
  218. package/src/cache/cache.types.ts +8 -4
  219. package/src/cache/cache.utils.ts +3 -3
  220. package/src/client/client.create.ts +4 -3
  221. package/src/client/client.ts +44 -12
  222. package/src/client/client.types.ts +25 -3
  223. package/src/client/client.utils.ts +24 -4
  224. package/src/dispatcher/dispatcher.events.ts +3 -3
  225. package/src/dispatcher/dispatcher.ts +59 -28
  226. package/src/dispatcher/dispatcher.types.ts +19 -2
  227. package/src/dispatcher/dispatcher.utils.ts +5 -4
  228. package/src/http-adapter/http-adapter.constants.ts +1 -1
  229. package/src/http-adapter/http-adapter.fetch.ts +174 -0
  230. package/src/http-adapter/http-adapter.ts +3 -8
  231. package/src/http-adapter/http-adapter.types.ts +17 -9
  232. package/src/http-adapter/http-adapter.utils.ts +6 -9
  233. package/src/http-adapter/index.ts +1 -0
  234. package/src/managers/app/app.manager.constants.ts +2 -2
  235. package/src/managers/app/app.manager.events.ts +1 -1
  236. package/src/managers/app/app.manager.ts +2 -1
  237. package/src/managers/logger/logger.manager.constants.ts +1 -1
  238. package/src/managers/logger/logger.manager.ts +2 -1
  239. package/src/managers/logger/logger.manager.types.ts +2 -2
  240. package/src/managers/logger/logger.manager.utils.ts +2 -1
  241. package/src/managers/request/request.manager.events.ts +13 -11
  242. package/src/managers/request/request.manager.types.ts +6 -3
  243. package/src/mocker/mocker.ts +3 -2
  244. package/src/mocker/mocker.types.ts +1 -1
  245. package/src/plugin/plugin.ts +2 -2
  246. package/src/plugin/plugin.types.ts +9 -9
  247. package/src/request/index.ts +1 -0
  248. package/src/request/request.hooks.ts +87 -0
  249. package/src/request/request.ts +155 -77
  250. package/src/request/request.types.ts +54 -22
  251. package/src/request/request.utils.ts +86 -23
  252. package/src/sdk/sdk.ts +153 -8
  253. package/src/types/adapter.types.ts +1 -1
  254. package/src/types/client.types.ts +1 -1
  255. package/src/types/hydration.types.ts +3 -3
  256. package/src/types/request.types.ts +30 -20
  257. package/src/utils/uuid.utils.ts +1 -1
  258. package/tsconfig.base.json +1 -6
  259. package/tsconfig.json +1 -4
  260. package/vite.config.ts +45 -0
  261. package/.eslintrc.json +0 -11
  262. package/__tests__/global.d.ts +0 -1
  263. package/__tests__/jest.setup.ts +0 -13
  264. package/dist/browser/index.js +0 -3751
  265. package/dist/browser/index.js.map +0 -7
  266. package/dist/index.js +0 -4002
  267. package/dist/index.js.map +0 -7
  268. package/jest.config.ts +0 -6
  269. package/src/http-adapter/http-adapter.browser.ts +0 -102
  270. package/src/http-adapter/http-adapter.server.ts +0 -149
@@ -15,7 +15,7 @@ describe("RequestManager [ Events ]", () => {
15
15
 
16
16
  beforeEach(() => {
17
17
  resetMocks();
18
- jest.resetAllMocks();
18
+ vi.resetAllMocks();
19
19
  client = new Client({ url: "shared-base-url" });
20
20
  request = client.createRequest()({ endpoint: "shared-base-endpoint" });
21
21
  });
@@ -28,12 +28,12 @@ describe("RequestManager [ Events ]", () => {
28
28
  it("should trigger request lifecycle events", async () => {
29
29
  mockRequest(request);
30
30
 
31
- const spy1 = jest.fn();
32
- const spy2 = jest.fn();
33
- const spy3 = jest.fn();
34
- const spy4 = jest.fn();
35
- const spy5 = jest.fn();
36
- const spy6 = jest.fn();
31
+ const spy1 = vi.fn();
32
+ const spy2 = vi.fn();
33
+ const spy3 = vi.fn();
34
+ const spy4 = vi.fn();
35
+ const spy5 = vi.fn();
36
+ const spy6 = vi.fn();
37
37
 
38
38
  client.requestManager.events.onRequestStartByQueue(request.queryKey, spy1);
39
39
  client.requestManager.events.onResponseStartByQueue(request.queryKey, spy2);
@@ -48,8 +48,8 @@ describe("RequestManager [ Events ]", () => {
48
48
  await waitFor(() => {
49
49
  expect(spy1).toHaveBeenCalledTimes(1);
50
50
  expect(spy2).toHaveBeenCalledTimes(1);
51
- expect(spy3).toHaveBeenCalledTimes(3);
52
- expect(spy4).toHaveBeenCalledTimes(3);
51
+ expect(spy3.mock.calls.length).toBeGreaterThanOrEqual(1);
52
+ expect(spy4.mock.calls.length).toBeGreaterThanOrEqual(1);
53
53
  expect(spy5).toHaveBeenCalledTimes(1);
54
54
  expect(spy6).toHaveBeenCalledTimes(1);
55
55
  });
@@ -58,14 +58,14 @@ describe("RequestManager [ Events ]", () => {
58
58
  it("should trigger global event handlers", async () => {
59
59
  mockRequest(request);
60
60
 
61
- const loadingSpy = jest.fn();
62
- const requestStartSpy = jest.fn();
63
- const responseStartSpy = jest.fn();
64
- const uploadProgressSpy = jest.fn();
65
- const downloadProgressSpy = jest.fn();
66
- const responseSpy = jest.fn();
67
- const abortSpy = jest.fn();
68
- const removeSpy = jest.fn();
61
+ const loadingSpy = vi.fn();
62
+ const requestStartSpy = vi.fn();
63
+ const responseStartSpy = vi.fn();
64
+ const uploadProgressSpy = vi.fn();
65
+ const downloadProgressSpy = vi.fn();
66
+ const responseSpy = vi.fn();
67
+ const abortSpy = vi.fn();
68
+ const removeSpy = vi.fn();
69
69
 
70
70
  // Set up global event listeners
71
71
  client.requestManager.events.onLoading(loadingSpy);
@@ -86,12 +86,8 @@ describe("RequestManager [ Events ]", () => {
86
86
  client.requestManager.abortByKey(request.abortKey);
87
87
 
88
88
  await waitFor(() => {
89
- expect(loadingSpy).toHaveBeenCalledTimes(2); // Called for start and end
89
+ expect(loadingSpy).toHaveBeenCalledTimes(2);
90
90
  expect(requestStartSpy).toHaveBeenCalledTimes(1);
91
- expect(responseStartSpy).toHaveBeenCalledTimes(1);
92
- expect(uploadProgressSpy).toHaveBeenCalledTimes(3);
93
- expect(downloadProgressSpy).toHaveBeenCalledTimes(3);
94
- expect(responseSpy).toHaveBeenCalledTimes(1);
95
91
  expect(abortSpy).toHaveBeenCalledTimes(1);
96
92
  expect(removeSpy).toHaveBeenCalledTimes(1);
97
93
  });
@@ -124,7 +120,7 @@ describe("RequestManager [ Events ]", () => {
124
120
 
125
121
  it("should properly remove global event listeners", async () => {
126
122
  mockRequest(request);
127
- const spy = jest.fn();
123
+ const spy = vi.fn();
128
124
 
129
125
  // Add and immediately remove event listener
130
126
  const removeListener = client.requestManager.events.onLoading(spy);
@@ -146,31 +142,31 @@ describe("RequestManager [ Events ]", () => {
146
142
  const { abortKey } = request;
147
143
 
148
144
  const spies = {
149
- loading: jest.fn(),
150
- loadingByQueue: jest.fn(),
151
- loadingByCache: jest.fn(),
152
- loadingById: jest.fn(),
153
- requestStart: jest.fn(),
154
- requestStartByQueue: jest.fn(),
155
- requestStartById: jest.fn(),
156
- responseStart: jest.fn(),
157
- responseStartByQueue: jest.fn(),
158
- responseStartById: jest.fn(),
159
- uploadProgress: jest.fn(),
160
- uploadProgressByQueue: jest.fn(),
161
- uploadProgressById: jest.fn(),
162
- downloadProgress: jest.fn(),
163
- downloadProgressByQueue: jest.fn(),
164
- downloadProgressById: jest.fn(),
165
- response: jest.fn(),
166
- responseByCache: jest.fn(),
167
- responseById: jest.fn(),
168
- abort: jest.fn(),
169
- abortByKey: jest.fn(),
170
- abortById: jest.fn(),
171
- remove: jest.fn(),
172
- removeByQueue: jest.fn(),
173
- removeById: jest.fn(),
145
+ loading: vi.fn(),
146
+ loadingByQueue: vi.fn(),
147
+ loadingByCache: vi.fn(),
148
+ loadingById: vi.fn(),
149
+ requestStart: vi.fn(),
150
+ requestStartByQueue: vi.fn(),
151
+ requestStartById: vi.fn(),
152
+ responseStart: vi.fn(),
153
+ responseStartByQueue: vi.fn(),
154
+ responseStartById: vi.fn(),
155
+ uploadProgress: vi.fn(),
156
+ uploadProgressByQueue: vi.fn(),
157
+ uploadProgressById: vi.fn(),
158
+ downloadProgress: vi.fn(),
159
+ downloadProgressByQueue: vi.fn(),
160
+ downloadProgressById: vi.fn(),
161
+ response: vi.fn(),
162
+ responseByCache: vi.fn(),
163
+ responseById: vi.fn(),
164
+ abort: vi.fn(),
165
+ abortByKey: vi.fn(),
166
+ abortById: vi.fn(),
167
+ remove: vi.fn(),
168
+ removeByQueue: vi.fn(),
169
+ removeById: vi.fn(),
174
170
  };
175
171
 
176
172
  // Set up and immediately cleanup all event listeners
@@ -218,11 +214,99 @@ describe("RequestManager [ Events ]", () => {
218
214
  });
219
215
  });
220
216
  });
217
+ describe("When using deduplicated event listeners", () => {
218
+ it("should trigger onDeduplicated callback when emitDeduplicated fires", () => {
219
+ const spy = vi.fn();
220
+ client.requestManager.events.onDeduplicated(spy);
221
+
222
+ const eventData = { request, requestId: "test-id", deduplicatedRequest: request };
223
+ client.requestManager.events.emitDeduplicated(eventData);
224
+
225
+ expect(spy).toHaveBeenCalledTimes(1);
226
+ expect(spy).toHaveBeenCalledWith(eventData);
227
+ });
228
+
229
+ it("should trigger onDeduplicatedByQueue callback for matching queryKey", () => {
230
+ const spy = vi.fn();
231
+ client.requestManager.events.onDeduplicatedByQueue(request.queryKey, spy);
232
+
233
+ const eventData = { request, requestId: "test-id", deduplicatedRequest: request };
234
+ client.requestManager.events.emitDeduplicated(eventData);
235
+
236
+ expect(spy).toHaveBeenCalledTimes(1);
237
+ expect(spy).toHaveBeenCalledWith(eventData);
238
+ });
239
+
240
+ it("should trigger onDeduplicatedByCache callback for matching cacheKey", () => {
241
+ const spy = vi.fn();
242
+ client.requestManager.events.onDeduplicatedByCache(request.cacheKey, spy);
243
+
244
+ const eventData = { request, requestId: "test-id", deduplicatedRequest: request };
245
+ client.requestManager.events.emitDeduplicated(eventData);
246
+
247
+ expect(spy).toHaveBeenCalledTimes(1);
248
+ expect(spy).toHaveBeenCalledWith(eventData);
249
+ });
250
+
251
+ it("should trigger onDeduplicatedById callback for matching requestId", () => {
252
+ const spy = vi.fn();
253
+ const requestId = "specific-request-id";
254
+ client.requestManager.events.onDeduplicatedById(requestId, spy);
255
+
256
+ const eventData = { request, requestId, deduplicatedRequest: request };
257
+ client.requestManager.events.emitDeduplicated(eventData);
258
+
259
+ expect(spy).toHaveBeenCalledTimes(1);
260
+ expect(spy).toHaveBeenCalledWith(eventData);
261
+ });
262
+
263
+ it("should cleanup onDeduplicated listener", () => {
264
+ const spy = vi.fn();
265
+ const cleanup = client.requestManager.events.onDeduplicated(spy);
266
+ cleanup();
267
+
268
+ client.requestManager.events.emitDeduplicated({ request, requestId: "test-id", deduplicatedRequest: request });
269
+
270
+ expect(spy).not.toHaveBeenCalled();
271
+ });
272
+
273
+ it("should cleanup onDeduplicatedByQueue listener", () => {
274
+ const spy = vi.fn();
275
+ const cleanup = client.requestManager.events.onDeduplicatedByQueue(request.queryKey, spy);
276
+ cleanup();
277
+
278
+ client.requestManager.events.emitDeduplicated({ request, requestId: "test-id", deduplicatedRequest: request });
279
+
280
+ expect(spy).not.toHaveBeenCalled();
281
+ });
282
+
283
+ it("should cleanup onDeduplicatedByCache listener", () => {
284
+ const spy = vi.fn();
285
+ const cleanup = client.requestManager.events.onDeduplicatedByCache(request.cacheKey, spy);
286
+ cleanup();
287
+
288
+ client.requestManager.events.emitDeduplicated({ request, requestId: "test-id", deduplicatedRequest: request });
289
+
290
+ expect(spy).not.toHaveBeenCalled();
291
+ });
292
+
293
+ it("should cleanup onDeduplicatedById listener", () => {
294
+ const spy = vi.fn();
295
+ const requestId = "specific-request-id";
296
+ const cleanup = client.requestManager.events.onDeduplicatedById(requestId, spy);
297
+ cleanup();
298
+
299
+ client.requestManager.events.emitDeduplicated({ request, requestId, deduplicatedRequest: request });
300
+
301
+ expect(spy).not.toHaveBeenCalled();
302
+ });
303
+ });
304
+
221
305
  describe("When request manager aborts the request", () => {
222
306
  it("should allow to abort request by id", async () => {
223
307
  mockRequest(request);
224
- const spy1 = jest.fn();
225
- const spy2 = jest.fn();
308
+ const spy1 = vi.fn();
309
+ const spy2 = vi.fn();
226
310
 
227
311
  const requestId = client.fetchDispatcher.add(request);
228
312
  client.requestManager.events.onAbortByKey(request.abortKey, spy1);
@@ -240,8 +324,8 @@ describe("RequestManager [ Events ]", () => {
240
324
  });
241
325
  it("should allow to abort all requests", async () => {
242
326
  mockRequest(request);
243
- const spy1 = jest.fn();
244
- const spy2 = jest.fn();
327
+ const spy1 = vi.fn();
328
+ const spy2 = vi.fn();
245
329
 
246
330
  const requestId = client.fetchDispatcher.add(request);
247
331
  client.requestManager.events.onAbortByKey(request.abortKey, spy1);
@@ -263,7 +347,7 @@ describe("RequestManager [ Events ]", () => {
263
347
 
264
348
  it("should emit abort event once", async () => {
265
349
  mockRequest(request);
266
- const spy1 = jest.fn();
350
+ const spy1 = vi.fn();
267
351
 
268
352
  client.fetchDispatcher.add(request);
269
353
  client.requestManager.events.onAbortByKey(request.abortKey, spy1);
@@ -2,21 +2,19 @@ import { waitFor } from "@testing-library/dom";
2
2
  import { createHttpMockingServer, sleep } from "@hyper-fetch/testing";
3
3
 
4
4
  import { createAdapter, createDispatcher } from "../../utils";
5
- import {
5
+ import type {
6
6
  HttpAdapterType,
7
- Client,
8
- getErrorMessage,
9
7
  RequestInstance,
10
8
  RequestResponseEventType,
11
9
  ResponseDetailsType,
12
10
  ResponseType,
13
- mocker,
14
11
  } from "../../../src";
12
+ import { Client, getErrorMessage, mocker } from "../../../src";
15
13
 
16
14
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
17
15
 
18
16
  describe("Mocker [ Base ]", () => {
19
- const adapterSpy = jest.fn();
17
+ const adapterSpy = vi.fn();
20
18
  const fixture = { test: 1, data: [200, 300, 404] };
21
19
  let adapter = createAdapter({ callback: adapterSpy });
22
20
  let client = new Client({ url: "shared-base-url" }).setAdapter(adapter);
@@ -34,7 +32,7 @@ describe("Mocker [ Base ]", () => {
34
32
  dispatcher = createDispatcher(client);
35
33
  request = client.createRequest<{ response: any }>()({ endpoint: "shared-base-endpoint" }).setMockingEnabled(true);
36
34
 
37
- jest.resetAllMocks();
35
+ vi.resetAllMocks();
38
36
  });
39
37
 
40
38
  afterAll(() => {
@@ -91,8 +89,8 @@ describe("Mocker [ Base ]", () => {
91
89
  });
92
90
 
93
91
  it("should allow to cancel single running request", async () => {
94
- const firstSpy = jest.fn();
95
- const secondSpy = jest.fn();
92
+ const firstSpy = vi.fn();
93
+ const secondSpy = vi.fn();
96
94
  const firstRequest = client
97
95
  .createRequest<{ response: any }>()({ endpoint: "shared-base-endpoint" })
98
96
  .setMock(
@@ -174,6 +172,7 @@ describe("Mocker [ Base ]", () => {
174
172
  retries: 1,
175
173
  isCanceled: false,
176
174
  isOffline: false,
175
+ willRetry: false,
177
176
  requestTimestamp: expect.toBeNumber(),
178
177
  responseTimestamp: expect.toBeNumber(),
179
178
  addedTimestamp: expect.toBeNumber(),
@@ -386,8 +385,8 @@ describe("Mocker [ Base ]", () => {
386
385
  { totalUploaded: 1000, requestTime: 40, totalDownloaded: 1000, responseTime: 60 },
387
386
  );
388
387
 
389
- const requestSpy = jest.fn();
390
- const responseSpy = jest.fn();
388
+ const requestSpy = vi.fn();
389
+ const responseSpy = vi.fn();
391
390
  client.requestManager.events.onUploadProgressByQueue(request.queryKey, requestSpy);
392
391
  client.requestManager.events.onDownloadProgressByQueue(request.queryKey, responseSpy);
393
392
  const response = await mockedRequest.send();
@@ -500,6 +499,79 @@ describe("Mocker [ Base ]", () => {
500
499
  ).rejects.toThrow("Request processing error");
501
500
  });
502
501
 
502
+ describe("When mock returns error without success and without data", () => {
503
+ it("should call onError path when success is false and no data", async () => {
504
+ const errorObj = new Error("mock error");
505
+ const mockedRequest = request.setMock(() => ({
506
+ data: null,
507
+ error: errorObj,
508
+ status: 500,
509
+ success: false,
510
+ }));
511
+
512
+ const response = await mockedRequest.send();
513
+
514
+ expect(response.data).toBe(null);
515
+ expect(response.error).toEqual(errorObj);
516
+ expect(response.status).toBe(500);
517
+ expect(response.success).toBe(false);
518
+ });
519
+ });
520
+
521
+ describe("When mock config has no timeout", () => {
522
+ it("should skip timeout setup when timeout is not a number", async () => {
523
+ const mockedRequest = request.setMock(
524
+ () => ({
525
+ data: fixture,
526
+ status: 200,
527
+ }),
528
+ { requestTime: 20, responseTime: 20 },
529
+ );
530
+
531
+ const response = await mockedRequest.send();
532
+
533
+ expect(response.data).toStrictEqual(fixture);
534
+ expect(response.status).toBe(200);
535
+ expect(response.success).toBe(true);
536
+ });
537
+ });
538
+
539
+ describe("When request is aborted before progress completes", () => {
540
+ it("should handle abort via timeout=0 before response progress starts", async () => {
541
+ const mockedRequest = client
542
+ .createRequest<{ response: any }>()({ endpoint: "shared-base-endpoint" })
543
+ .setMock(
544
+ () => ({
545
+ data: fixture,
546
+ status: 200,
547
+ }),
548
+ { requestTime: 100, responseTime: 100, timeout: 0 },
549
+ );
550
+
551
+ const response = await mockedRequest.send();
552
+
553
+ expect(response.data).toBe(null);
554
+ expect(response.error).toBeDefined();
555
+ });
556
+
557
+ it("should resolve progress immediately when abort already triggered", async () => {
558
+ const mockedRequest = client
559
+ .createRequest<{ response: any }>()({ endpoint: "shared-base-endpoint" })
560
+ .setMock(
561
+ () => ({
562
+ data: fixture,
563
+ status: 200,
564
+ }),
565
+ { requestTime: 200, responseTime: 200, timeout: 1 },
566
+ );
567
+
568
+ const response = await mockedRequest.send();
569
+
570
+ expect(response.data).toBe(null);
571
+ expect(response.error).toBeDefined();
572
+ });
573
+ });
574
+
503
575
  describe("When handling different response scenarios", () => {
504
576
  it("should handle success with data", async () => {
505
577
  const mockedRequest = request.setMock(() => ({
@@ -16,7 +16,7 @@ describe("Plugin [ Base ]", () => {
16
16
 
17
17
  beforeEach(() => {
18
18
  resetMocks();
19
- jest.resetAllMocks();
19
+ vi.resetAllMocks();
20
20
  client = new Client({ url: "shared-base-url" });
21
21
  request = client.createRequest()({ endpoint: "shared-nase-endpoint" });
22
22
  });
@@ -49,7 +49,7 @@ describe("Plugin [ Base ]", () => {
49
49
 
50
50
  describe("When using plugin trigger", () => {
51
51
  it("should trigger registered method", () => {
52
- const callback = jest.fn();
52
+ const callback = vi.fn();
53
53
  const plugin = new Plugin({ name: "test-plugin" });
54
54
 
55
55
  plugin.onDispatcherCleared(callback);
@@ -72,7 +72,7 @@ describe("Plugin [ Base ]", () => {
72
72
  describe("When using dispatcher effects", () => {
73
73
  it("should register dispatcher lifecycle methods", () => {
74
74
  const plugin = new Plugin({ name: "test-plugin" });
75
- const callback = jest.fn();
75
+ const callback = vi.fn();
76
76
 
77
77
  const methods = [
78
78
  "onDispatcherCleared",
@@ -97,7 +97,7 @@ describe("Plugin [ Base ]", () => {
97
97
  describe("When using cache effects", () => {
98
98
  it("should register cache lifecycle methods", () => {
99
99
  const plugin = new Plugin({ name: "test-plugin" });
100
- const callback = jest.fn();
100
+ const callback = vi.fn();
101
101
 
102
102
  const methods = ["onCacheItemChange", "onCacheItemDelete"];
103
103
 
@@ -114,7 +114,7 @@ describe("Plugin [ Base ]", () => {
114
114
  describe("When using adapter effects", () => {
115
115
  it("should register adapter fetch method", () => {
116
116
  const plugin = new Plugin({ name: "test-plugin" });
117
- const callback = jest.fn();
117
+ const callback = vi.fn();
118
118
 
119
119
  const result = plugin.onAdapterFetch(callback);
120
120
  expect(result).toBe(plugin);
@@ -130,11 +130,11 @@ describe("Plugin [ Base ]", () => {
130
130
  describe("When using fetch effects", () => {
131
131
  it("should trigger success effects", async () => {
132
132
  mockRequest(request);
133
- const spy1 = jest.fn();
134
- const spy2 = jest.fn();
135
- const spy3 = jest.fn();
136
- const spy4 = jest.fn();
137
- const spy5 = jest.fn();
133
+ const spy1 = vi.fn();
134
+ const spy2 = vi.fn();
135
+ const spy3 = vi.fn();
136
+ const spy4 = vi.fn();
137
+ const spy5 = vi.fn();
138
138
 
139
139
  const effect = new Plugin({
140
140
  name: "123",
@@ -159,11 +159,11 @@ describe("Plugin [ Base ]", () => {
159
159
  });
160
160
  it("should trigger error effects", async () => {
161
161
  mockRequest(request, { status: 400 });
162
- const spy1 = jest.fn();
163
- const spy2 = jest.fn();
164
- const spy3 = jest.fn();
165
- const spy4 = jest.fn();
166
- const spy5 = jest.fn();
162
+ const spy1 = vi.fn();
163
+ const spy2 = vi.fn();
164
+ const spy3 = vi.fn();
165
+ const spy4 = vi.fn();
166
+ const spy5 = vi.fn();
167
167
 
168
168
  const effect = new Plugin({
169
169
  name: "123",
@@ -202,8 +202,8 @@ describe("Plugin [ Base ]", () => {
202
202
  describe("When using mount/unmount lifecycle", () => {
203
203
  it("should register mount and unmount callbacks", () => {
204
204
  const plugin = new Plugin({ name: "test-plugin" });
205
- const mountCallback = jest.fn();
206
- const unmountCallback = jest.fn();
205
+ const mountCallback = vi.fn();
206
+ const unmountCallback = vi.fn();
207
207
 
208
208
  const mountResult = plugin.onMount(mountCallback);
209
209
  const unmountResult = plugin.onUnmount(unmountCallback);
@@ -222,7 +222,7 @@ describe("Plugin [ Base ]", () => {
222
222
  describe("When using request lifecycle", () => {
223
223
  it("should register request create callback", () => {
224
224
  const plugin = new Plugin({ name: "test-plugin" });
225
- const callback = jest.fn();
225
+ const callback = vi.fn();
226
226
 
227
227
  const result = plugin.onRequestCreate(callback);
228
228
  expect(result).toBe(plugin);
@@ -238,7 +238,7 @@ describe("Plugin [ Base ]", () => {
238
238
 
239
239
  it("should register request trigger callback", () => {
240
240
  const plugin = new Plugin({ name: "test-plugin" });
241
- const callback = jest.fn();
241
+ const callback = vi.fn();
242
242
 
243
243
  const result = plugin.onRequestTrigger(callback);
244
244
  expect(result).toBe(plugin);
@@ -1,6 +1,7 @@
1
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
2
 
3
- import { Client, QueryParamsType } from "../../../src";
3
+ import type { QueryParamsType } from "../../../src";
4
+ import { Client, Request } from "../../../src";
4
5
 
5
6
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
6
7
 
@@ -15,7 +16,7 @@ describe("Fetch Adapter [ Base ]", () => {
15
16
  client = new Client({ url: "shared-base-url" });
16
17
  request = client.createRequest()({ endpoint: "/shared-endpoint" });
17
18
  resetMocks();
18
- jest.resetAllMocks();
19
+ vi.resetAllMocks();
19
20
  });
20
21
 
21
22
  afterAll(() => {
@@ -24,8 +25,8 @@ describe("Fetch Adapter [ Base ]", () => {
24
25
 
25
26
  it("should allow for setting custom header", async () => {
26
27
  // The queue should receive request with the appropriate header
27
- const spy = jest.fn(client.fetchDispatcher.add);
28
- jest.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
28
+ const spy = vi.fn(client.fetchDispatcher.add);
29
+ vi.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
29
30
  const header = { it: "works" };
30
31
  const c = request.setHeaders(header);
31
32
  mockRequest(request);
@@ -39,8 +40,8 @@ describe("Fetch Adapter [ Base ]", () => {
39
40
 
40
41
  it("should allow for setting auth", async () => {
41
42
  // The queue should receive request with the appropriate header
42
- const spy = jest.fn(client.fetchDispatcher.add);
43
- jest.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
43
+ const spy = vi.fn(client.fetchDispatcher.add);
44
+ vi.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
44
45
  mockRequest(request);
45
46
 
46
47
  expect(request.auth).toBe(true);
@@ -59,8 +60,8 @@ describe("Fetch Adapter [ Base ]", () => {
59
60
  const comm = client.createRequest<{ queryParams: QueryParamsType }>()({
60
61
  endpoint: "/some-endpoint/:shopId/:productId",
61
62
  });
62
- const spy = jest.fn(client.fetchDispatcher.add);
63
- jest.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
63
+ const spy = vi.fn(client.fetchDispatcher.add);
64
+ vi.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
64
65
  const params = { shopId: 11, productId: 1 };
65
66
 
66
67
  const c = comm.setParams(params);
@@ -76,8 +77,8 @@ describe("Fetch Adapter [ Base ]", () => {
76
77
  });
77
78
 
78
79
  it("should allow for setting data to the request", async () => {
79
- const spy = jest.fn(client.fetchDispatcher.add);
80
- jest.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
80
+ const spy = vi.fn(client.fetchDispatcher.add);
81
+ vi.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
81
82
  const data = {
82
83
  userId: 11,
83
84
  role: "ADMIN",
@@ -102,8 +103,8 @@ describe("Fetch Adapter [ Base ]", () => {
102
103
  endpoint: "/some-endpoint/",
103
104
  });
104
105
  mockRequest(comm);
105
- const spy = jest.fn(client.fetchDispatcher.add);
106
- jest.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
106
+ const spy = vi.fn(client.fetchDispatcher.add);
107
+ vi.spyOn(client.fetchDispatcher, "add").mockImplementation(spy);
107
108
 
108
109
  const requestQueryParams = comm.setQueryParams(queryParams);
109
110
  requestQueryParams.send({});
@@ -135,7 +136,7 @@ describe("Fetch Adapter [ Base ]", () => {
135
136
  const mapperRequest = client
136
137
  .createRequest<{ response: null }>()({ endpoint: "/some-endpoint/" })
137
138
  .setResponseMapper((res) => {
138
- return { ...res, data: null, error: new Error(message) };
139
+ return { ...res, data: null, error: new Error(message) } as typeof res;
139
140
  });
140
141
  mockRequest(mapperRequest);
141
142
 
@@ -196,4 +197,29 @@ describe("Fetch Adapter [ Base ]", () => {
196
197
  expect(result).toBeUndefined();
197
198
  });
198
199
  });
200
+
201
+ describe("fromJSON()", () => {
202
+ it("should reconstruct a request from its JSON representation", () => {
203
+ const original = client
204
+ .createRequest<{ response: { id: number }; payload: { name: string } }>()({
205
+ endpoint: "/users/:userId",
206
+ method: "POST",
207
+ })
208
+ .setHeaders({ "X-Custom": "value" })
209
+ .setAuth(false)
210
+ .setRetry(3)
211
+ .setRetryTime(500);
212
+
213
+ const json = original.toJSON();
214
+ const restored = Request.fromJSON(client, json);
215
+
216
+ expect(restored).toBeInstanceOf(Request);
217
+ expect(restored.endpoint).toBe(original.endpoint);
218
+ expect(restored.method).toBe(original.method);
219
+ expect(restored.headers).toStrictEqual(original.headers);
220
+ expect(restored.auth).toBe(original.auth);
221
+ expect(restored.retry).toBe(original.retry);
222
+ expect(restored.retryTime).toBe(original.retryTime);
223
+ });
224
+ });
199
225
  });
@@ -15,7 +15,7 @@ describe("Request [ Cloning ]", () => {
15
15
  client = new Client({ url: "shared-base-url" });
16
16
  request = client.createRequest()({ endpoint: "/users/:userId" });
17
17
  resetMocks();
18
- jest.resetAllMocks();
18
+ vi.resetAllMocks();
19
19
  });
20
20
 
21
21
  afterAll(() => {