@hyper-fetch/core 7.5.2 → 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 (271) 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 +414 -0
  7. package/__tests__/features/adapter/adapter.bindings.spec.ts +1025 -0
  8. package/__tests__/features/adapter/adapter.browser.spec.ts +88 -0
  9. package/__tests__/features/adapter/adapter.server.spec.ts +369 -0
  10. package/__tests__/features/adapter/adapter.utils.spec.ts +165 -0
  11. package/__tests__/features/cache/cache.base.spec.ts +366 -0
  12. package/__tests__/features/cache/cache.events.spec.ts +219 -0
  13. package/__tests__/features/cache/cache.garbage-collector.spec.ts +175 -0
  14. package/__tests__/features/cache/cache.lazy-storage.spec.ts +132 -0
  15. package/__tests__/features/cache/cache.modes.spec.ts +145 -0
  16. package/__tests__/features/cache/cache.scoping.spec.ts +171 -0
  17. package/__tests__/features/cache/cache.typescript.spec.ts +147 -0
  18. package/__tests__/features/cache/cache.utils.spec.ts +126 -0
  19. package/__tests__/features/client/client.auth.spec.ts +125 -0
  20. package/__tests__/features/client/client.base.spec.ts +161 -0
  21. package/__tests__/features/client/client.from-json.spec.ts +182 -0
  22. package/__tests__/features/client/client.hydration.spec.ts +236 -0
  23. package/__tests__/features/client/client.interceptor.spec.ts +225 -0
  24. package/__tests__/features/client/client.methods.spec.ts +189 -0
  25. package/__tests__/features/client/client.middleware.spec.ts +118 -0
  26. package/__tests__/features/client/client.utils.spec.ts +292 -0
  27. package/__tests__/features/dispatcher/dispatcher.base.spec.ts +123 -0
  28. package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +189 -0
  29. package/__tests__/features/dispatcher/dispatcher.events.spec.ts +309 -0
  30. package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +462 -0
  31. package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +241 -0
  32. package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +142 -0
  33. package/__tests__/features/managers/app/app.manager.base.spec.ts +235 -0
  34. package/__tests__/features/managers/app/app.manager.ssr.spec.ts +43 -0
  35. package/__tests__/features/managers/logger/logger.base.spec.ts +109 -0
  36. package/__tests__/features/managers/logger/logger.utils.spec.ts +106 -0
  37. package/__tests__/features/managers/request/request.manager.base.spec.ts +224 -0
  38. package/__tests__/features/managers/request/request.manager.events.spec.ts +364 -0
  39. package/__tests__/features/mocker/mocker.base.spec.ts +639 -0
  40. package/__tests__/features/plugin/plugin.base.spec.ts +255 -0
  41. package/__tests__/features/request/request.base.spec.ts +225 -0
  42. package/__tests__/features/request/request.cloning.spec.ts +47 -0
  43. package/__tests__/features/request/request.hooks.spec.ts +173 -0
  44. package/__tests__/features/request/request.optimistic.spec.ts +93 -0
  45. package/__tests__/features/request/request.retry-on-error.spec.ts +359 -0
  46. package/__tests__/features/request/request.sending.spec.ts +364 -0
  47. package/__tests__/features/request/request.setters.spec.ts +164 -0
  48. package/__tests__/features/request/request.typescript.spec.ts +423 -0
  49. package/__tests__/features/request/request.utils.spec.ts +77 -0
  50. package/__tests__/features/sdk/sdk.base.spec.ts +132 -0
  51. package/__tests__/features/sdk/sdk.configuration.spec.ts +262 -0
  52. package/__tests__/features/utils/emitter.utils.spec.ts +88 -0
  53. package/__tests__/shared/callbacks.shared.ts +11 -0
  54. package/__tests__/shared/index.ts +2 -0
  55. package/__tests__/shared/progress.shared.ts +36 -0
  56. package/__tests__/tsconfig.json +24 -0
  57. package/__tests__/type-stress/generate-stress-test.ts +92 -0
  58. package/__tests__/type-stress/stress-10.ts +35 -0
  59. package/__tests__/type-stress/stress-just-create.ts +2107 -0
  60. package/__tests__/type-stress/stress-minimal.ts +23 -0
  61. package/__tests__/type-stress/stress-test-500.ts +2319 -0
  62. package/__tests__/type-stress/stress-test-sdk.ts +210 -0
  63. package/__tests__/type-stress/tsconfig.json +6 -0
  64. package/__tests__/utils/adapter.utils.ts +39 -0
  65. package/__tests__/utils/cache.utils.ts +20 -0
  66. package/__tests__/utils/callbacks.utils.ts +48 -0
  67. package/__tests__/utils/dispatcher.utils.ts +7 -0
  68. package/__tests__/utils/index.ts +4 -0
  69. package/__tests__/vitest.setup.ts +15 -0
  70. package/dist/adapter/adapter.bindings.d.ts +71 -0
  71. package/dist/adapter/adapter.bindings.d.ts.map +1 -0
  72. package/dist/adapter/adapter.d.ts +127 -0
  73. package/dist/adapter/adapter.d.ts.map +1 -0
  74. package/dist/adapter/adapter.types.d.ts +108 -0
  75. package/dist/adapter/adapter.types.d.ts.map +1 -0
  76. package/dist/adapter/adapter.utils.d.ts +23 -0
  77. package/dist/adapter/adapter.utils.d.ts.map +1 -0
  78. package/dist/adapter/index.d.ts +5 -0
  79. package/dist/adapter/index.d.ts.map +1 -0
  80. package/dist/cache/cache.d.ts +95 -0
  81. package/dist/cache/cache.d.ts.map +1 -0
  82. package/dist/cache/cache.events.d.ts +51 -0
  83. package/dist/cache/cache.events.d.ts.map +1 -0
  84. package/dist/cache/cache.types.d.ts +44 -0
  85. package/dist/cache/cache.types.d.ts.map +1 -0
  86. package/dist/cache/cache.utils.d.ts +11 -0
  87. package/dist/cache/cache.utils.d.ts.map +1 -0
  88. package/dist/cache/index.d.ts +5 -0
  89. package/dist/cache/index.d.ts.map +1 -0
  90. package/dist/client/client.constants.d.ts +10 -0
  91. package/dist/client/client.constants.d.ts.map +1 -0
  92. package/dist/client/client.create.d.ts +8 -0
  93. package/dist/client/client.create.d.ts.map +1 -0
  94. package/dist/client/client.d.ts +195 -0
  95. package/dist/client/client.d.ts.map +1 -0
  96. package/dist/client/client.types.d.ts +71 -0
  97. package/dist/client/client.types.d.ts.map +1 -0
  98. package/dist/client/client.utils.d.ts +11 -0
  99. package/dist/client/client.utils.d.ts.map +1 -0
  100. package/dist/client/index.d.ts +6 -0
  101. package/dist/client/index.d.ts.map +1 -0
  102. package/dist/constants/http.constants.d.ts +8 -0
  103. package/dist/constants/http.constants.d.ts.map +1 -0
  104. package/dist/constants/time.constants.d.ts +12 -0
  105. package/dist/constants/time.constants.d.ts.map +1 -0
  106. package/dist/dispatcher/dispatcher.constants.d.ts +7 -0
  107. package/dist/dispatcher/dispatcher.constants.d.ts.map +1 -0
  108. package/dist/dispatcher/dispatcher.d.ts +168 -0
  109. package/dist/dispatcher/dispatcher.d.ts.map +1 -0
  110. package/dist/dispatcher/dispatcher.events.d.ts +49 -0
  111. package/dist/dispatcher/dispatcher.events.d.ts.map +1 -0
  112. package/dist/dispatcher/dispatcher.types.d.ts +44 -0
  113. package/dist/dispatcher/dispatcher.types.d.ts.map +1 -0
  114. package/dist/dispatcher/dispatcher.utils.d.ts +12 -0
  115. package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -0
  116. package/dist/dispatcher/index.d.ts +6 -0
  117. package/dist/dispatcher/index.d.ts.map +1 -0
  118. package/dist/http-adapter/http-adapter.constants.d.ts +4 -0
  119. package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -0
  120. package/dist/http-adapter/http-adapter.d.ts +3 -0
  121. package/dist/http-adapter/http-adapter.d.ts.map +1 -0
  122. package/dist/http-adapter/http-adapter.fetch.d.ts +6 -0
  123. package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -0
  124. package/dist/http-adapter/http-adapter.types.d.ts +73 -0
  125. package/dist/http-adapter/http-adapter.types.d.ts.map +1 -0
  126. package/dist/http-adapter/http-adapter.utils.d.ts +10 -0
  127. package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -0
  128. package/dist/http-adapter/index.d.ts +6 -0
  129. package/dist/http-adapter/index.d.ts.map +1 -0
  130. package/dist/index.d.ts +15 -2083
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.mjs +4084 -0
  133. package/dist/index.mjs.map +1 -0
  134. package/dist/managers/app/app.manager.constants.d.ts +10 -0
  135. package/dist/managers/app/app.manager.constants.d.ts.map +1 -0
  136. package/dist/managers/app/app.manager.d.ts +35 -0
  137. package/dist/managers/app/app.manager.d.ts.map +1 -0
  138. package/dist/managers/app/app.manager.events.d.ts +12 -0
  139. package/dist/managers/app/app.manager.events.d.ts.map +1 -0
  140. package/dist/managers/app/app.manager.types.d.ts +7 -0
  141. package/dist/managers/app/app.manager.types.d.ts.map +1 -0
  142. package/dist/managers/app/app.manager.utils.d.ts +5 -0
  143. package/dist/managers/app/app.manager.utils.d.ts.map +1 -0
  144. package/dist/managers/app/index.d.ts +6 -0
  145. package/dist/managers/app/index.d.ts.map +1 -0
  146. package/dist/managers/index.d.ts +4 -0
  147. package/dist/managers/index.d.ts.map +1 -0
  148. package/dist/managers/logger/index.d.ts +5 -0
  149. package/dist/managers/logger/index.d.ts.map +1 -0
  150. package/dist/managers/logger/logger.manager.constants.d.ts +5 -0
  151. package/dist/managers/logger/logger.manager.constants.d.ts.map +1 -0
  152. package/dist/managers/logger/logger.manager.d.ts +22 -0
  153. package/dist/managers/logger/logger.manager.d.ts.map +1 -0
  154. package/dist/managers/logger/logger.manager.types.d.ts +43 -0
  155. package/dist/managers/logger/logger.manager.types.d.ts.map +1 -0
  156. package/dist/managers/logger/logger.manager.utils.d.ts +4 -0
  157. package/dist/managers/logger/logger.manager.utils.d.ts.map +1 -0
  158. package/dist/managers/request/index.d.ts +5 -0
  159. package/dist/managers/request/index.d.ts.map +1 -0
  160. package/dist/managers/request/request.manager.d.ts +60 -0
  161. package/dist/managers/request/request.manager.d.ts.map +1 -0
  162. package/dist/managers/request/request.manager.events.d.ts +55 -0
  163. package/dist/managers/request/request.manager.events.d.ts.map +1 -0
  164. package/dist/managers/request/request.manager.types.d.ts +48 -0
  165. package/dist/managers/request/request.manager.types.d.ts.map +1 -0
  166. package/dist/managers/request/request.manager.utils.d.ts +30 -0
  167. package/dist/managers/request/request.manager.utils.d.ts.map +1 -0
  168. package/dist/mocker/index.d.ts +3 -0
  169. package/dist/mocker/index.d.ts.map +1 -0
  170. package/dist/mocker/mocker.d.ts +3 -0
  171. package/dist/mocker/mocker.d.ts.map +1 -0
  172. package/dist/mocker/mocker.types.d.ts +25 -0
  173. package/dist/mocker/mocker.types.d.ts.map +1 -0
  174. package/dist/plugin/index.d.ts +3 -0
  175. package/dist/plugin/index.d.ts.map +1 -0
  176. package/dist/plugin/plugin.d.ts +55 -0
  177. package/dist/plugin/plugin.d.ts.map +1 -0
  178. package/dist/plugin/plugin.types.d.ts +122 -0
  179. package/dist/plugin/plugin.types.d.ts.map +1 -0
  180. package/dist/request/index.d.ts +5 -0
  181. package/dist/request/index.d.ts.map +1 -0
  182. package/dist/request/request.d.ts +195 -0
  183. package/dist/request/request.d.ts.map +1 -0
  184. package/dist/request/request.hooks.d.ts +19 -0
  185. package/dist/request/request.hooks.d.ts.map +1 -0
  186. package/dist/request/request.types.d.ts +240 -0
  187. package/dist/request/request.types.d.ts.map +1 -0
  188. package/dist/request/request.utils.d.ts +25 -0
  189. package/dist/request/request.utils.d.ts.map +1 -0
  190. package/dist/sdk/index.d.ts +2 -0
  191. package/dist/sdk/index.d.ts.map +1 -0
  192. package/dist/sdk/sdk.d.ts +69 -0
  193. package/dist/sdk/sdk.d.ts.map +1 -0
  194. package/dist/types/adapter.types.d.ts +22 -0
  195. package/dist/types/adapter.types.d.ts.map +1 -0
  196. package/dist/types/client.types.d.ts +4 -0
  197. package/dist/types/client.types.d.ts.map +1 -0
  198. package/dist/types/helpers.types.d.ts +17 -0
  199. package/dist/types/helpers.types.d.ts.map +1 -0
  200. package/dist/types/http.types.d.ts +3 -0
  201. package/dist/types/http.types.d.ts.map +1 -0
  202. package/dist/types/hydration.types.d.ts +15 -0
  203. package/dist/types/hydration.types.d.ts.map +1 -0
  204. package/dist/types/index.d.ts +7 -0
  205. package/dist/types/index.d.ts.map +1 -0
  206. package/dist/types/request.types.d.ts +34 -0
  207. package/dist/types/request.types.d.ts.map +1 -0
  208. package/dist/utils/emitter.utils.d.ts +13 -0
  209. package/dist/utils/emitter.utils.d.ts.map +1 -0
  210. package/dist/utils/index.d.ts +3 -0
  211. package/dist/utils/index.d.ts.map +1 -0
  212. package/dist/utils/uuid.utils.d.ts +3 -0
  213. package/dist/utils/uuid.utils.d.ts.map +1 -0
  214. package/package.json +10 -25
  215. package/project.json +4 -0
  216. package/src/adapter/adapter.bindings.ts +8 -12
  217. package/src/adapter/adapter.ts +8 -7
  218. package/src/adapter/adapter.types.ts +10 -6
  219. package/src/adapter/adapter.utils.ts +1 -1
  220. package/src/cache/cache.events.ts +4 -11
  221. package/src/cache/cache.ts +28 -22
  222. package/src/cache/cache.types.ts +8 -4
  223. package/src/cache/cache.utils.ts +3 -3
  224. package/src/client/client.create.ts +4 -3
  225. package/src/client/client.ts +44 -12
  226. package/src/client/client.types.ts +25 -3
  227. package/src/client/client.utils.ts +24 -4
  228. package/src/dispatcher/dispatcher.events.ts +3 -3
  229. package/src/dispatcher/dispatcher.ts +59 -28
  230. package/src/dispatcher/dispatcher.types.ts +19 -2
  231. package/src/dispatcher/dispatcher.utils.ts +5 -4
  232. package/src/http-adapter/http-adapter.constants.ts +1 -1
  233. package/src/http-adapter/http-adapter.fetch.ts +174 -0
  234. package/src/http-adapter/http-adapter.ts +3 -8
  235. package/src/http-adapter/http-adapter.types.ts +17 -9
  236. package/src/http-adapter/http-adapter.utils.ts +6 -9
  237. package/src/http-adapter/index.ts +1 -0
  238. package/src/managers/app/app.manager.constants.ts +2 -2
  239. package/src/managers/app/app.manager.events.ts +1 -1
  240. package/src/managers/app/app.manager.ts +2 -1
  241. package/src/managers/logger/logger.manager.constants.ts +1 -1
  242. package/src/managers/logger/logger.manager.ts +2 -1
  243. package/src/managers/logger/logger.manager.types.ts +2 -2
  244. package/src/managers/logger/logger.manager.utils.ts +2 -1
  245. package/src/managers/request/request.manager.events.ts +13 -11
  246. package/src/managers/request/request.manager.types.ts +6 -3
  247. package/src/mocker/mocker.ts +3 -2
  248. package/src/mocker/mocker.types.ts +1 -1
  249. package/src/plugin/plugin.ts +2 -2
  250. package/src/plugin/plugin.types.ts +9 -9
  251. package/src/request/index.ts +1 -0
  252. package/src/request/request.hooks.ts +87 -0
  253. package/src/request/request.ts +155 -77
  254. package/src/request/request.types.ts +54 -22
  255. package/src/request/request.utils.ts +86 -23
  256. package/src/sdk/sdk.ts +153 -8
  257. package/src/types/adapter.types.ts +1 -1
  258. package/src/types/client.types.ts +1 -1
  259. package/src/types/hydration.types.ts +3 -3
  260. package/src/types/request.types.ts +30 -20
  261. package/src/utils/uuid.utils.ts +1 -1
  262. package/tsconfig.base.json +1 -6
  263. package/tsconfig.json +1 -4
  264. package/vite.config.ts +45 -0
  265. package/.eslintrc.json +0 -11
  266. package/dist/browser/index.js +0 -3751
  267. package/dist/browser/index.js.map +0 -7
  268. package/dist/index.js +0 -3991
  269. package/dist/index.js.map +0 -7
  270. package/src/http-adapter/http-adapter.browser.ts +0 -102
  271. package/src/http-adapter/http-adapter.server.ts +0 -135
package/dist/index.d.ts CHANGED
@@ -1,2083 +1,15 @@
1
- import EventEmitter$1 from 'events';
2
-
3
- type Prettify<T> = {
4
- [K in keyof T]: T[K];
5
- } & {};
6
- type EmptyTypes = null | undefined;
7
- type NullableType<T> = T | EmptyTypes;
8
- type NullableKeys<T> = {
9
- [P in keyof T]-?: NullableType<T[P]>;
10
- };
11
- type NonNullableKeys<T> = {
12
- [P in keyof T]-?: NonNullable<T[P]>;
13
- };
14
- type RequiredKeys<T> = {
15
- [P in keyof T]-?: Exclude<T[P], EmptyTypes>;
16
- };
17
- type TypeWithDefaults<Types extends Record<string, any>, Key extends keyof Types, Value, ExcludedTypes = void | never> = Key extends keyof Types ? Exclude<Types[Key], ExcludedTypes> extends never ? Value : Exclude<Types[Key], ExcludedTypes> : Value;
18
- type SyncOrAsync<T> = T | Promise<T>;
19
-
20
- type HttpMethodsType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
21
- type HttpStatusType = number;
22
-
23
- type ExtractAdapterOptionsType<T> = T extends Adapter<infer O, any, any, any, any, any, any, any, any, any, any> ? O : never;
24
- type ExtractAdapterMethodType<T> = T extends Adapter<any, infer M, any, any, any, any, any, any, any, any, any> ? M : never;
25
- type ExtractAdapterStatusType<T> = T extends Adapter<any, any, infer S, any, any, any, any, any, any, any, any> ? S : never;
26
- type ExtractAdapterExtraType<T> = T extends Adapter<any, any, any, infer A, any, any, any, any, any, any, any> ? A : never;
27
- type ExtractAdapterQueryParamsType<T> = T extends Adapter<any, any, any, any, infer Q, any, any, any, any, any, any> ? Q : never;
28
- type ExtractAdapterDefaultQueryParamsType<T> = T extends Adapter<any, any, any, any, any, infer Q, any, any, any, any, any> ? Q : never;
29
- type ExtractAdapterEndpointType<T> = T extends Adapter<any, any, any, any, any, any, infer E, any, any, any, any> ? E : never;
30
- type ExtractAdapterEndpointMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, infer EM, any, any, any> ? EM : never;
31
- type ExtractAdapterQueryParamsMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, infer QPM, any, any> ? QPM : never;
32
- type ExtractAdapterHeaderMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, infer HM, any> ? HM : never;
33
- type ExtractAdapterPayloadMapperType<T> = T extends Adapter<any, any, any, any, any, any, any, any, any, any, infer PM> ? PM : never;
34
- type ExtractUnionAdapter<AdapterType extends AdapterInstance, Values extends {
35
- method?: any;
36
- options?: any;
37
- status?: any;
38
- extra?: any;
39
- queryParams?: any;
40
- endpointType?: any;
41
- defaultQueryParams?: any;
42
- }> = Extract<AdapterType, Adapter<Values["options"], Values["method"], Values["status"], Values["extra"], Values["queryParams"], Values["defaultQueryParams"], Values["endpointType"]>> extends AdapterInstance ? Extract<AdapterType, Adapter<Values["options"], Values["method"], Values["status"], Values["extra"], Values["queryParams"], Values["defaultQueryParams"], Values["endpointType"]>> : never;
43
-
44
- type ExtractClientGlobalError<T extends ClientInstance> = T extends Client$1<infer P, any> ? P : never;
45
- type ExtractClientAdapterType<T extends ClientInstance> = T extends Client$1<any, infer P> ? P : never;
46
-
47
- type ExtractAdapterResolvedType<T extends RequestInstance> = ResponseType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>;
48
- type ExtractResponseType<T> = T extends Request<infer D, any, any, any, any, any, any, any, any> ? D : never;
49
- type ExtractPayloadType<T> = T extends Request<any, infer D, any, any, any, any, any, any, any> ? D : never;
50
- type ExtractQueryParamsType<T> = T extends Request<any, any, infer Q, any, any, any, any, any, any> ? Q : never;
51
- type ExtractErrorType<T> = T extends Request<any, any, any, infer G, any, infer C, any, any, any> ? G | ExtractClientGlobalError<C> : never;
52
- type ExtractGlobalErrorType<T> = T extends Request<any, any, any, any, any, infer C, any, any, any> ? ExtractClientGlobalError<C> : never;
53
- type ExtractLocalErrorType<T> = T extends Request<any, any, any, infer E, any, any, any, any, any> ? E : never;
54
- type ExtractParamsType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any> ? E extends string ? ExtractUrlParams<E> : never : never;
55
- type ExtractEndpointType<T> = T extends Request<any, any, any, any, infer E, any, any, any, any> ? E : never;
56
- type ExtractClientType<T> = T extends Request<any, any, any, any, any, infer C, any, any, any> ? C : never;
57
- type ExtractAdapterType<T> = T extends Request<any, any, any, any, any, infer C, any, any, any> ? ExtractClientAdapterType<C> : never;
58
- type ExtractHasPayloadType<T> = T extends Request<any, any, any, any, any, any, infer D, any, any> ? D : never;
59
- type ExtractHasParamsType<T> = T extends Request<any, any, any, any, any, any, any, infer P, any> ? P : never;
60
- type ExtractHasQueryParamsType<T> = T extends Request<any, any, any, any, any, any, any, any, infer Q> ? Q : never;
61
- type ExtendRequest<Req extends RequestInstance, Properties extends {
62
- response?: any;
63
- payload?: any;
64
- queryParams?: any;
65
- globalError?: any;
66
- localError?: any;
67
- endpoint?: ExtractAdapterEndpointType<ExtractAdapterType<Req>>;
68
- client?: Client$1<any, any>;
69
- hasData?: true | false;
70
- hasParams?: true | false;
71
- hasQuery?: true | false;
72
- }> = Request<TypeWithDefaults<Properties, "response", ExtractResponseType<Req>>, TypeWithDefaults<Properties, "payload", ExtractPayloadType<Req>>, TypeWithDefaults<Properties, "queryParams", ExtractQueryParamsType<Req>>, TypeWithDefaults<Properties, "localError", ExtractLocalErrorType<Req>>, Properties["endpoint"] extends string ? Properties["endpoint"] : ExtractEndpointType<Req>, Properties["client"] extends ClientInstance ? Properties["client"] : ExtractClientType<Req>, Properties["hasData"] extends true ? true : ExtractHasPayloadType<Req>, Properties["hasParams"] extends true ? true : ExtractHasParamsType<Req>, Properties["hasQuery"] extends true ? true : ExtractHasQueryParamsType<Req>>;
73
-
74
- /**
75
- * Cache class handles the data exchange with the dispatchers.
76
- *
77
- * @note
78
- * Keys used to save the values are created dynamically on the Request class
79
- *
80
- */
81
- declare class Cache<Adapter extends AdapterInstance> {
82
- options?: CacheOptionsType | undefined;
83
- emitter: EventEmitter;
84
- events: ReturnType<typeof getCacheEvents>;
85
- storage: CacheStorageType;
86
- lazyStorage?: CacheAsyncStorageType;
87
- version: string;
88
- garbageCollectors: Map<string, NodeJS.Timeout>;
89
- private logger;
90
- private client;
91
- constructor(options?: CacheOptionsType | undefined);
92
- initialize: (client: ClientInstance<{
93
- adapter: Adapter;
94
- }>) => this;
95
- /**
96
- * Set the cache data to the storage
97
- * @param request
98
- * @param response
99
- * @returns
100
- */
101
- set: <Request extends RequestCacheType<RequestInstance>>(request: Request, response: CacheSetState<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>> & ResponseDetailsType> & {
102
- hydrated?: boolean;
103
- }) => void;
104
- /**
105
- * Update the cache data with partial response data
106
- * @param request
107
- * @param partialResponse
108
- * @param isTriggeredExtrenally - informs whether an update was triggered due to internal logic or externally, e.g.
109
- * via plugin.
110
- * @returns
111
- */
112
- update: <Request extends RequestCacheType<RequestInstance>>(request: Request, partialResponse: CacheSetState<Partial<ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>> & ResponseDetailsType>>) => void;
113
- /**
114
- * Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.
115
- * @param cacheKey
116
- * @returns
117
- */
118
- get: <Response, Error>(cacheKey: string) => CacheValueType<Response, Error, Adapter> | undefined;
119
- /**
120
- * Get sync storage keys, lazyStorage keys will not be included
121
- * @returns
122
- */
123
- keys: () => string[];
124
- /**
125
- * Delete record from storages and trigger invalidation event
126
- * @param cacheKey
127
- */
128
- delete: (cacheKey: string) => void;
129
- /**
130
- * Invalidate cache by cacheKey or partial matching with RegExp
131
- * It emits invalidation event for each matching cacheKey and sets staleTime to 0 to indicate out of time cache
132
- * @param key - cacheKey or Request instance or RegExp for partial matching
133
- */
134
- invalidate: (cacheKeys: string | RegExp | RequestInstance | Array<string | RegExp | RequestInstance>) => void;
135
- /**
136
- * Used to receive data from lazy storage
137
- * @param cacheKey
138
- */
139
- getLazyResource: <Response, Error>(cacheKey: string) => Promise<CacheValueType<Response, Error, Adapter> | undefined>;
140
- /**
141
- * Used to receive keys from sync storage and lazy storage
142
- * @param cacheKey
143
- */
144
- getLazyKeys: () => Promise<string[]>;
145
- /**
146
- * Used to receive keys from sync storage and lazy storage
147
- * @param cacheKey
148
- */
149
- getAllKeys: () => Promise<string[]>;
150
- /**
151
- * Schedule garbage collection for given key
152
- * @param cacheKey
153
- * @returns
154
- */
155
- scheduleGarbageCollector: (cacheKey: string) => void;
156
- /**
157
- * Clear cache storages
158
- */
159
- clear: () => Promise<void>;
160
- }
161
-
162
- type CacheOptionsType = {
163
- /**
164
- * Assign your custom sync storage
165
- */
166
- storage?: CacheStorageType;
167
- /**
168
- * Lazy loading from remote resources - possibly persistent
169
- */
170
- lazyStorage?: CacheAsyncStorageType;
171
- /**
172
- * Key to clear lazy storage data, often used for versioning
173
- * If the new key is different from the old one, the cache will be cleared
174
- */
175
- version?: string;
176
- };
177
- type CacheValueType<Response = any, Error = any, Adapter extends AdapterInstance = AdapterInstance> = ResponseType<Response, Error, Adapter> & ResponseDetailsType & {
178
- cacheKey: string;
179
- staleTime: number;
180
- version: string;
181
- cacheTime: number;
182
- cached: boolean;
183
- hydrated?: boolean;
184
- };
185
- type CacheAsyncStorageType = {
186
- set: <Response, Error, Adapter extends AdapterInstance>(key: string, data: CacheValueType<Response, Error, Adapter>) => Promise<void>;
187
- get: <Response, Error, Adapter extends AdapterInstance>(key: string) => Promise<CacheValueType<Response, Error, Adapter> | undefined>;
188
- keys: () => Promise<string[] | IterableIterator<string> | string[]>;
189
- delete: (key: string) => Promise<void>;
190
- };
191
- type CacheStorageType = {
192
- set: <Response, Error, Adapter extends AdapterInstance>(key: string, data: CacheValueType<Response, Error, Adapter>) => void;
193
- get: <Response, Error, Adapter extends AdapterInstance>(key: string) => CacheValueType<Response, Error, Adapter> | undefined;
194
- keys: () => string[] | IterableIterator<string> | string[];
195
- delete: (key: string) => void;
196
- clear: () => void;
197
- };
198
- type CacheInitialData = Record<string, CacheValueType>;
199
- type CacheSetState<CacheData> = CacheData | ((previousData: CacheData | null) => CacheData);
200
- type RequestCacheType<R extends RequestInstance> = Pick<R, "cacheKey" | "cache" | "staleTime" | "cacheTime">;
201
-
202
- declare const getCacheData: <T extends RequestInstance>(previousResponse: ExtractAdapterResolvedType<T> | undefined, response: ExtractAdapterResolvedType<T> & ResponseDetailsType) => ExtractAdapterResolvedType<T> & ResponseDetailsType;
203
- declare const getInvalidateKey: () => string;
204
- declare const getInvalidateByKey: (key: string) => string;
205
- declare const getDeleteKey: () => string;
206
- declare const getDeleteByKey: (key: string) => string;
207
- declare const getCacheByKey: (key: string) => string;
208
- declare const getCacheKey: () => string;
209
-
210
- declare const getCacheEvents: (emitter: EventEmitter$1) => {
211
- /**
212
- * Set cache data
213
- * @param data
214
- */
215
- emitCacheData: <Response, Error, Adapter extends AdapterInstance>(data: CacheValueType<Response, Error, Adapter> & {
216
- cached: boolean;
217
- }, isTriggeredExternally?: boolean) => void;
218
- /**
219
- * Invalidate cache values event
220
- */
221
- emitInvalidation: (cacheKey: string, isTriggeredExternally?: boolean) => void;
222
- /**
223
- * Delete of cache values
224
- */
225
- emitDelete: (cacheKey: string, isTriggeredExternally?: boolean) => void;
226
- /**
227
- * Cache data listener
228
- * @param callback
229
- * @returns
230
- */
231
- onData: <Response, Error, Adapter extends AdapterInstance>(callback: (data: CacheValueType<Response, Error, Adapter> & {
232
- cached: boolean;
233
- }) => void) => VoidFunction;
234
- /**
235
- * Cache data listener
236
- * @param cacheKey
237
- * @param callback
238
- * @returns
239
- */
240
- onDataByKey: <Response, Error, Adapter extends AdapterInstance>(cacheKey: string, callback: (data: CacheValueType<Response, Error, Adapter>) => void) => VoidFunction;
241
- /**
242
- * Cache invalidation listener
243
- * @param callback
244
- * @returns
245
- */
246
- onInvalidate: (callback: (cacheKey: string) => void) => VoidFunction;
247
- /**
248
- * Cache invalidation listener
249
- * @param cacheKey
250
- * @param callback
251
- * @returns
252
- */
253
- onInvalidateByKey: (cacheKey: string, callback: () => void) => VoidFunction;
254
- onDelete: (callback: (cacheKey: string) => void) => VoidFunction;
255
- onDeleteByKey: (cacheKey: string, callback: () => void) => VoidFunction;
256
- };
257
-
258
- type HydrationOptions = RequestCacheType<RequestInstance> & {
259
- override: boolean;
260
- };
261
- type HydrateDataType<Data = any, Error = any, Adapter extends AdapterInstance = any> = HydrationOptions & {
262
- /** Hydration timestamp */
263
- timestamp: number;
264
- /** Hydrated response */
265
- response: ResponseType<Data, Error, Adapter>;
266
- /** Hydrated flag */
267
- hydrated: true;
268
- };
269
-
270
- declare const getAdapterBindings: <T extends AdapterInstance>({ request: baseRequest, requestId, resolve, onStartTime, internalErrorMapping, }: {
271
- request: RequestInstance;
272
- requestId: string;
273
- resolve: (value: ResponseSuccessType<any, T> | ResponseErrorType<any, T>) => void;
274
- onStartTime: (timestamp: number) => void;
275
- internalErrorMapping: (error: ReturnType<typeof getErrorMessage>) => any;
276
- }) => Promise<{
277
- request: RequestInstance;
278
- requestId: string;
279
- url: string;
280
- endpoint: any;
281
- queryParams: any;
282
- payload: any;
283
- headers: any;
284
- adapter: AdapterInstance;
285
- adapterOptions: ExtractAdapterOptionsType<T> | undefined;
286
- getAbortController: () => AbortController | undefined;
287
- getRequestStartTimestamp: () => number | null;
288
- getResponseStartTimestamp: () => number | null;
289
- createAbortListener: ({ status, extra, onAbort, }: {
290
- status: ExtractAdapterStatusType<T>;
291
- extra: ExtractAdapterExtraType<T>;
292
- onAbort?: () => void;
293
- }) => () => void;
294
- onBeforeRequest: () => void;
295
- onRequestStart: (progress?: ProgressDataType) => number;
296
- onRequestProgress: (progress: ProgressDataType) => number;
297
- onRequestEnd: () => number;
298
- onResponseStart: (progress?: ProgressDataType) => number;
299
- onResponseProgress: (progress: ProgressDataType) => number;
300
- onResponseEnd: () => number;
301
- onSuccess: ({ data, error, status, extra, }: {
302
- data: any;
303
- status: ExtractAdapterStatusType<T>;
304
- extra: ExtractAdapterExtraType<T>;
305
- error?: ExtractErrorType<T>;
306
- }) => Promise<ResponseSuccessType<ExtractResponseType<T>, T>>;
307
- onAbortError: ({ status, extra, }: {
308
- status: ExtractAdapterStatusType<T>;
309
- extra: ExtractAdapterExtraType<T>;
310
- }) => Promise<ResponseErrorType<any, T>>;
311
- onTimeoutError: ({ status, extra, }: {
312
- status: ExtractAdapterStatusType<T>;
313
- extra: ExtractAdapterExtraType<T>;
314
- }) => Promise<ResponseErrorType<any, T>>;
315
- onUnexpectedError: ({ status, extra, }: {
316
- status: ExtractAdapterStatusType<T>;
317
- extra: ExtractAdapterExtraType<T>;
318
- }) => Promise<ResponseErrorType<any, T>>;
319
- onError: ({ error, status, extra, }: {
320
- error: any;
321
- status: ExtractAdapterStatusType<T>;
322
- extra: ExtractAdapterExtraType<T>;
323
- }) => Promise<ResponseErrorType<any, T>>;
324
- }>;
325
- declare function getAdapterOnError<T extends AdapterInstance>({ request, requestId, startTime, resolve, logger, }: {
326
- request: RequestInstance;
327
- requestId: string;
328
- startTime: number;
329
- logger: LoggerMethods;
330
- resolve: (value: ResponseSuccessType<any, T> | ResponseErrorType<any, T>) => void;
331
- }): ({ error, status, extra, }: {
332
- error: any;
333
- status: ExtractAdapterStatusType<T>;
334
- extra: ExtractAdapterExtraType<T>;
335
- }) => Promise<ResponseErrorType<any, T>>;
336
-
337
- /**
338
- * Base Adapter
339
- */
340
- type AdapterInstance = Adapter<any, any, any, any, any, any, any, any, any, any, any>;
341
- type AdapterGenericType<AdapterOptions, MethodType extends string, StatusType extends number | string, Extra extends Record<string, any>, QueryParams = QueryParamsType | string | EmptyTypes, DefaultQueryParams = undefined, EndpointType = string, EndpointMapperType extends EndpointMapper<EndpointType> | DefaultMapperType = DefaultMapperType, QueryParamsMapperType extends QueryParamsMapper<QueryParams> | DefaultMapperType = DefaultMapperType, HeaderMapperType extends HeaderMappingType | DefaultMapperType = DefaultMapperType, PayloadMapperType extends AdapterPayloadMappingType | DefaultMapperType = DefaultMapperType> = {
342
- adapterOptions: AdapterOptions;
343
- methodType: MethodType;
344
- statusType: StatusType;
345
- extra: Extra;
346
- queryParams?: QueryParams;
347
- defaultQueryParams?: DefaultQueryParams;
348
- endpointType: EndpointType;
349
- endpointMapperType?: EndpointMapperType;
350
- queryParamsMapperType?: QueryParamsMapperType;
351
- headerMapperType?: HeaderMapperType;
352
- payloadMapperType?: PayloadMapperType;
353
- };
354
- type DeclareAdapterType<Properties extends AdapterGenericType<any, any, any, any, any, any, any, any, any, any>> = Adapter<TypeWithDefaults<Properties, "adapterOptions", any>, TypeWithDefaults<Properties, "methodType", any>, TypeWithDefaults<Properties, "statusType", any>, TypeWithDefaults<Properties, "extra", any>, TypeWithDefaults<Properties, "queryParams", QueryParamsType | string | EmptyTypes>, TypeWithDefaults<Properties, "defaultQueryParams", undefined>, TypeWithDefaults<Properties, "endpointType", string>, TypeWithDefaults<Properties, "endpointMapperType", DefaultMapperType>, TypeWithDefaults<Properties, "queryParamsMapperType", DefaultMapperType>, TypeWithDefaults<Properties, "headerMapperType", DefaultMapperType>, NonNullable<TypeWithDefaults<Properties, "payloadMapperType", DefaultMapperType>>>;
355
- type AdapterFetcherType<Adapter extends AdapterInstance> = (options: Omit<Awaited<ReturnType<typeof getAdapterBindings<Adapter>>>, "payload"> & {
356
- url: string;
357
- endpoint: ReturnType<ExtractAdapterEndpointMapperType<Adapter>>;
358
- queryParams: ReturnType<ExtractAdapterQueryParamsMapperType<Adapter>>;
359
- headers: ReturnType<ExtractAdapterHeaderMapperType<Adapter>>;
360
- payload: ReturnType<ExtractAdapterPayloadMapperType<Adapter>>;
361
- requestId: string;
362
- request: RequestInstance;
363
- }) => void;
364
- type HeaderMappingType<Config = never> = (request: RequestInstance, config?: Config) => HeadersInit;
365
- type EndpointMapper<EndpointType, Config = never> = (endpoint: EndpointType, config?: Config) => string;
366
- type QueryParamsMapper<QueryParams, Config = never> = (queryParams: QueryParams | EmptyTypes, config?: Config) => any;
367
- type AdapterPayloadMappingType<Config = never> = (options: {
368
- request: RequestInstance;
369
- payload: unknown;
370
- }, config?: Config) => any;
371
- type DefaultEndpointMapper = (endpoint: string) => string;
372
- type DefaultQueryParamsMapper = (queryParams: QueryParamsType | string | EmptyTypes) => QueryParamsType | string | EmptyTypes;
373
- type DefaultHeaderMapper = (request: RequestInstance) => HeadersInit;
374
- type DefaultPayloadMapper = (options: {
375
- request: RequestInstance;
376
- payload: unknown;
377
- }) => string;
378
- type QueryParamValuesType = number | string | boolean | null | undefined | Record<any, any>;
379
- type QueryParamType = QueryParamValuesType | Array<QueryParamValuesType> | Record<string, QueryParamValuesType>;
380
- type QueryParamsType = Record<string, QueryParamType>;
381
- type RequestResponseType<Request extends RequestInstance> = {
382
- data: ExtractResponseType<Request> | null;
383
- error: ExtractErrorType<Request> | null;
384
- status: ExtractAdapterStatusType<ExtractAdapterType<Request>> | null;
385
- success: true | false;
386
- extra: ExtractAdapterExtraType<ExtractAdapterType<Request>> | null;
387
- responseTimestamp: number;
388
- requestTimestamp: number;
389
- };
390
- type ResponseType<GenericDataType, GenericErrorType, Adapter extends AdapterInstance> = {
391
- data: GenericDataType | null;
392
- error: GenericErrorType | null;
393
- status: ExtractAdapterStatusType<Adapter> | null;
394
- success: true | false;
395
- extra: ExtractAdapterExtraType<Adapter> | null;
396
- responseTimestamp: number;
397
- requestTimestamp: number;
398
- };
399
- type ResponseSuccessType<GenericDataType, Adapter extends AdapterInstance> = {
400
- data: GenericDataType;
401
- error: null;
402
- status: ExtractAdapterStatusType<Adapter> | null;
403
- success: true;
404
- extra: ExtractAdapterExtraType<Adapter> | null;
405
- responseTimestamp: number;
406
- requestTimestamp: number;
407
- };
408
- type ResponseErrorType<GenericErrorType, Adapter extends AdapterInstance> = {
409
- data: null;
410
- error: GenericErrorType;
411
- status: ExtractAdapterStatusType<Adapter> | null;
412
- success: false;
413
- extra: ExtractAdapterExtraType<Adapter> | null;
414
- responseTimestamp: number;
415
- requestTimestamp: number;
416
- };
417
- type ProgressDataType = {
418
- /** Total size in bytes */
419
- total?: number;
420
- /** Loaded size in bytes */
421
- loaded?: number;
422
- };
423
- type ProgressType = {
424
- /** Progress in percentage (0-100) */
425
- progress: number;
426
- /** Time left in seconds (null if not available) */
427
- timeLeft: number | null;
428
- /** Size left in bytes */
429
- sizeLeft: number;
430
- /** Total size in bytes */
431
- total: number;
432
- /** Loaded size in bytes */
433
- loaded: number;
434
- /** Start timestamp in milliseconds */
435
- startTimestamp: number;
436
- };
437
-
438
- declare class TimeoutError extends Error {
439
- constructor();
440
- }
441
- declare class AbortError extends Error {
442
- constructor();
443
- }
444
- declare class DeletedError extends Error {
445
- constructor();
446
- }
447
- declare class RequestProcessingError extends Error {
448
- description?: string;
449
- constructor(description?: string);
450
- }
451
- declare class UnexpectedError extends Error {
452
- description?: string;
453
- constructor(description?: string);
454
- }
455
- declare const getErrorMessage: (errorCase?: "timeout" | "abort" | "deleted" | "processing" | "unexpected") => TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError;
456
- declare const stringifyValue: (response: string | unknown) => string;
457
- declare const getAdapterHeaders: (request: RequestInstance) => HeadersInit;
458
- declare const getAdapterPayload: (data: unknown) => string | FormData;
459
-
460
- type DefaultMapperType = <V, C>(value: V, config: C) => V;
461
- declare const defaultMapper: DefaultMapperType;
462
- declare class Adapter<AdapterOptions, MethodType extends string, StatusType extends number | string, Extra extends Record<string, any>, QueryParams = QueryParamsType | string | EmptyTypes, DefaultQueryParams = undefined, EndpointType = string, EndpointMapperType extends EndpointMapper<EndpointType> | DefaultMapperType = DefaultMapperType, QueryParamsMapperType extends QueryParamsMapper<QueryParams> | DefaultMapperType = DefaultMapperType, HeaderMapperType extends HeaderMappingType | DefaultMapperType = DefaultMapperType, PayloadMapperType extends AdapterPayloadMappingType | DefaultMapperType = DefaultMapperType> {
463
- options: {
464
- name: string;
465
- defaultMethod: MethodType;
466
- defaultExtra: Extra;
467
- systemErrorStatus: StatusType;
468
- systemErrorExtra: Extra;
469
- defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
470
- };
471
- /** Fetching function */
472
- unstable_fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
473
- /**
474
- * ********************
475
- * Defaults
476
- * ********************
477
- */
478
- name: string;
479
- defaultMethod: MethodType;
480
- defaultExtra: Extra;
481
- systemErrorStatus: StatusType;
482
- systemErrorExtra: Extra;
483
- defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
484
- logger: LoggerMethods;
485
- initialized: boolean;
486
- client: ClientInstance;
487
- unstable_onInitializeCallback?: (options: {
488
- client: ClientInstance;
489
- }) => void;
490
- unstable_queryParamsMapperConfig: Parameters<QueryParamsMapperType>[1];
491
- unstable_headerMapperConfig: Parameters<HeaderMapperType>[1];
492
- unstable_payloadMapperConfig: Parameters<PayloadMapperType>[1];
493
- unstable_endpointMapperConfig: Parameters<EndpointMapperType>[1];
494
- constructor(options: {
495
- name: string;
496
- defaultMethod: MethodType;
497
- defaultExtra: Extra;
498
- systemErrorStatus: StatusType;
499
- systemErrorExtra: Extra;
500
- defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
501
- });
502
- initialize: (client: ClientInstance) => this;
503
- onInitialize: (callback: (options: {
504
- client: ClientInstance;
505
- }) => void) => this;
506
- /**
507
- * ********************
508
- * Options Setters
509
- * ********************
510
- */
511
- unstable_internalErrorMapping: (error: ReturnType<typeof getErrorMessage>) => any;
512
- /** Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats. */
513
- unstable_headerMapper: HeaderMapperType;
514
- /** Method to get request data and transform them to the required format. It handles FormData and JSON by default. */
515
- unstable_payloadMapper: PayloadMapperType;
516
- /** Method to get the endpoint for the adapter request. */
517
- unstable_endpointMapper: EndpointMapperType;
518
- /** Method to get request data and transform them to the required format. */
519
- unstable_queryParamsMapper: QueryParamsMapperType;
520
- /** Get default adapter options for the request. */
521
- unstable_getAdapterDefaults?: (request: ExtendRequest<RequestInstance, {
522
- client: Client$1<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
523
- }>) => AdapterOptions;
524
- /** Get default request options for the request. */
525
- unstable_getRequestDefaults?: (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>;
526
- /**
527
- * Get formatted endpoint name of the request.
528
- * Helpful in displaying long endpoints like in case of graphql schemas etc.
529
- */
530
- unstable_devtoolsEndpointGetter: (endpoint: string) => string;
531
- /**
532
- * ********************
533
- * Methods
534
- * ********************
535
- */
536
- setDefaultMethod: (method: MethodType) => this;
537
- setDefaultExtra: (extra: Extra) => this;
538
- setDevtoolsEndpointGetter: (callback: (endpoint: string) => string) => this;
539
- /**
540
- * This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
541
- */
542
- setRequestDefaults: (callback: typeof this.unstable_getRequestDefaults) => this;
543
- /**
544
- * Set the adapter default options added to every sent request
545
- */
546
- setAdapterDefaults: (callback: (request: ExtendRequest<RequestInstance, {
547
- client: Client$1<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
548
- }>) => AdapterOptions) => this;
549
- setInternalErrorMapping: (callback: (error: ReturnType<typeof getErrorMessage>) => any) => this;
550
- /**
551
- * Set the custom header mapping function
552
- */
553
- setHeaderMapper: <NewMapper extends HeaderMappingType>(headerMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, NewMapper, PayloadMapperType>;
554
- /**
555
- * Set the request payload mapping function which gets triggered before request is send
556
- */
557
- setPayloadMapper: <NewMapper extends AdapterPayloadMappingType>(payloadMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>;
558
- /**
559
- * Set the request payload mapping function which get triggered before request get sent
560
- */
561
- setEndpointMapper: <NewEndpointMapper extends EndpointMapper<EndpointType>>(endpointMapper: NewEndpointMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
562
- /**
563
- * Set the query params mapping function which get triggered before request get sent
564
- */
565
- setQueryParamsMapper: <NewQueryParamsMapper extends QueryParamsMapper<QueryParams>>(queryParamsMapper: NewQueryParamsMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>;
566
- setQueryParamsMapperConfig: <NewQueryParamsMapperConfig extends Parameters<QueryParamsMapperType>[1]>(config: NewQueryParamsMapperConfig) => this;
567
- setHeaderMapperConfig: <NewHeaderMapperConfig extends Parameters<HeaderMapperType>[1]>(config: NewHeaderMapperConfig) => this;
568
- setEndpointMapperConfig: <NewEndpointMapperConfig extends Parameters<EndpointMapperType>[1]>(config: NewEndpointMapperConfig) => this;
569
- setPayloadMapperConfig: <NewPayloadMapperConfig extends Parameters<PayloadMapperType>[1]>(config: NewPayloadMapperConfig) => this;
570
- /**
571
- * ********************
572
- * Fetching
573
- * ********************
574
- */
575
- setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>): this;
576
- fetch(request: ExtendRequest<RequestInstance, {
577
- client: Client$1<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
578
- }>, requestId: string): Promise<RequestResponseType<RequestInstance>>;
579
- }
580
-
581
- declare const mocker: <T extends AdapterInstance>({ request, requestId, onError, onResponseEnd, onTimeoutError, onRequestEnd, createAbortListener, onResponseProgress, onRequestProgress, onResponseStart, onBeforeRequest, onRequestStart, onSuccess, onAbortError, adapter, }: Awaited<ReturnType<typeof getAdapterBindings<T>>>) => Promise<void>;
582
-
583
- type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
584
- type MockerConfigType = {
585
- /** Informs how long the request should take before returning a timeout error (in milliseconds) */
586
- timeout?: number;
587
- /** Simulates how long the request to the server should take (in milliseconds) */
588
- requestTime?: number;
589
- /** Indicates how long the response from the server should take (in milliseconds).
590
- * If their combined total takes longer than provided timeout, each value will be automatically
591
- * adjusted to last half of the timeout time */
592
- responseTime?: number;
593
- /** total number of 'bytes' to be uploaded. */
594
- totalUploaded?: number;
595
- /** total number of 'bytes' to be downloaded. */
596
- totalDownloaded?: number;
597
- };
598
- type MockResponseType<Response, Error, AdapterType extends AdapterInstance> = PartialBy<Omit<ResponseType<Response, Error, AdapterType>, "data" | "error" | "responseTimestamp" | "requestTimestamp">, "extra" | "success"> & ({
599
- data: Response;
600
- error?: Error;
601
- } | {
602
- data?: Response;
603
- error: Error;
604
- });
605
-
606
- /**
607
- * Request is a class that represents a request sent to the server. It contains all the necessary information to make a request, like endpoint, method, headers, data, and much more.
608
- * It is executed at any time via methods like `send` or `exec`.
609
- *
610
- * We can set it up with options like endpoint, method, headers and more.
611
- * We can choose some of advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.
612
- *
613
- * @info We should not use this class directly in the standard development flow.
614
- * We can initialize it using the `createRequest` method on the **Client** class.
615
- *
616
- * @attention The most important thing about the request is that it keeps data in the format that can be dumped.
617
- * This is necessary for the persistence and different dispatcher storage types.
618
- * This class doesn't have any callback methods by design and communicate with dispatcher and cache by events.
619
- *
620
- * It should be serializable to JSON and deserializable back to the class.
621
- * Serialization should not affect the result of the request, so it's methods and functional part should be only syntax sugar for given runtime.
622
- */
623
- declare class Request<Response, Payload, QueryParams, LocalError, Endpoint extends string, Client extends ClientInstance, HasPayload extends true | false = false, HasParams extends true | false = false, HasQuery extends true | false = false> {
624
- readonly client: Client;
625
- readonly requestOptions: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>;
626
- readonly initialRequestConfiguration?: RequestConfigurationType<Payload, Endpoint extends string ? ExtractUrlParams<Endpoint> : never, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>> | undefined;
627
- endpoint: Endpoint;
628
- headers?: HeadersInit;
629
- auth: boolean;
630
- method: ExtractAdapterMethodType<ExtractClientAdapterType<Client>>;
631
- params: ExtractUrlParams<Endpoint> | EmptyTypes;
632
- payload: PayloadType<Payload>;
633
- queryParams: QueryParams | EmptyTypes;
634
- options?: ExtractAdapterOptionsType<ExtractClientAdapterType<Client>> | undefined;
635
- cancelable: boolean;
636
- retry: number;
637
- retryTime: number;
638
- cacheTime: number;
639
- cache: boolean;
640
- staleTime: number;
641
- queued: boolean;
642
- offline: boolean;
643
- abortKey: string;
644
- cacheKey: string;
645
- queryKey: string;
646
- used: boolean;
647
- deduplicate: boolean;
648
- deduplicateTime: number | null;
649
- isMockerEnabled: boolean;
650
- unstable_mock?: {
651
- fn: (options: {
652
- request: RequestInstance;
653
- requestId: string;
654
- }) => MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>>;
655
- config: MockerConfigType;
656
- };
657
- /** @internal */
658
- unstable_payloadMapper?: PayloadMapperType<Payload>;
659
- /** @internal */
660
- unstable_requestMapper?: RequestMapper<any, any>;
661
- /** @internal */
662
- unstable_responseMapper?: ResponseMapper<this, ResponseSuccessType<any, any> | ResponseErrorType<any, any>>;
663
- unstable_hasParams: HasParams;
664
- unstable_hasPayload: HasPayload;
665
- unstable_hasQuery: HasQuery;
666
- private updatedAbortKey;
667
- private updatedCacheKey;
668
- private updatedQueryKey;
669
- constructor(client: Client, requestOptions: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>, initialRequestConfiguration?: RequestConfigurationType<Payload, Endpoint extends string ? ExtractUrlParams<Endpoint> : never, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>> | undefined);
670
- setHeaders: (headers: HeadersInit) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
671
- setAuth: (auth: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
672
- setParams: <P extends ExtractParamsType<this>>(params: P) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, P extends null ? false : true, HasQuery>;
673
- setPayload: <P extends Payload>(payload: P) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, P extends null ? false : true, HasParams, HasQuery>;
674
- setQueryParams: (queryParams: QueryParams) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, true>;
675
- setOptions: (options: ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, true>;
676
- setCancelable: (cancelable: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
677
- setRetry: (retry: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>["retry"]) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
678
- setRetryTime: (retryTime: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>["retryTime"]) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
679
- setCacheTime: (cacheTime: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>["cacheTime"]) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
680
- setCache: (cache: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>["cache"]) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
681
- setStaleTime: (staleTime: RequestOptionsType<Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>["staleTime"]) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
682
- setQueued: (queued: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
683
- setAbortKey: (abortKey: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
684
- setCacheKey: (cacheKey: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
685
- setQueryKey: (queryKey: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
686
- setDeduplicate: (deduplicate: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
687
- setDeduplicateTime: (deduplicateTime: number) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
688
- setUsed: (used: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
689
- setOffline: (offline: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
690
- setMock: (fn: (options: {
691
- request: Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
692
- requestId: string;
693
- }) => SyncOrAsync<MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>>>, config?: MockerConfigType) => this;
694
- clearMock: () => this;
695
- setMockingEnabled: (isMockerEnabled: boolean) => this;
696
- /**
697
- * Map data before it gets send to the server
698
- * @param payloadMapper
699
- * @returns
700
- */
701
- setPayloadMapper: <MappedPayload extends any | Promise<any>>(payloadMapper: (data: Payload) => MappedPayload) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
702
- /**
703
- * Map request before it gets send to the server
704
- * @param requestMapper mapper of the request
705
- * @returns new request
706
- */
707
- setRequestMapper: <NewRequest extends RequestInstance>(requestMapper: RequestMapper<this, NewRequest>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
708
- /**
709
- * Map the response to the new interface
710
- * @param responseMapper our mapping callback
711
- * @returns new response
712
- */
713
- setResponseMapper: <MappedResponse extends ResponseSuccessType<any, any> | ResponseErrorType<any, any>>(responseMapper?: ResponseMapper<this, MappedResponse>) => Request<MappedResponse extends ResponseType<infer R, any, any> ? R : Response, Payload, QueryParams, MappedResponse extends ResponseType<any, infer E, any> ? E : LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
714
- private paramsMapper;
715
- toJSON(): RequestJSON<this>;
716
- clone<NewData extends true | false = HasPayload, NewParams extends true | false = HasParams, NewQueryParams extends true | false = HasQuery>(configuration?: RequestConfigurationType<Payload, (typeof this)["params"], QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>): Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, NewData, NewParams, NewQueryParams>;
717
- abort: () => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery>;
718
- dehydrate: (config?: {
719
- /** in case of using adapter without cache we can provide response to dehydrate */
720
- response?: ResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>>;
721
- /** override cache data */
722
- override?: boolean;
723
- }) => HydrateDataType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> | undefined;
724
- /**
725
- * Read the response from cache data
726
- *
727
- * If it returns error and data at the same time, it means that latest request was failed
728
- * and we show previous data from cache together with error received from actual request
729
- */
730
- read(): ResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> | undefined;
731
- /**
732
- * Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
733
- * @param options
734
- * @disableReturns
735
- * @returns
736
- * ```tsx
737
- * Promise<[Data | null, Error | null, HttpStatus]>
738
- * ```
739
- */
740
- exec: RequestSendType<this>;
741
- /**
742
- * Method used to perform requests with usage of cache and queues
743
- * @param options
744
- * @param requestCallback
745
- * @disableReturns
746
- * @returns
747
- * ```tsx
748
- * Promise<[Data | null, Error | null, HttpStatus]>
749
- * ```
750
- */
751
- send: RequestSendType<this>;
752
- static fromJSON: <NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint extends string, NewClient extends ClientInstance, NewHasPayload extends true | false = false, NewHasParams extends true | false = false, NewHasQuery extends true | false = false>(client: NewClient, json: RequestJSON<Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery>>) => Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery>;
753
- }
754
-
755
- type RequestInstanceProperties = {
756
- response?: any;
757
- payload?: any;
758
- error?: any;
759
- client?: ClientInstance;
760
- queryParams?: any;
761
- endpoint?: string;
762
- hasParams?: boolean;
763
- hasQueryParams?: boolean;
764
- hasPayload?: boolean;
765
- };
766
- type RequestInstance<RequestProperties extends RequestInstanceProperties = {
767
- response?: any;
768
- payload?: any;
769
- queryParams?: any;
770
- error?: any;
771
- client?: ClientInstance;
772
- }> = Request<TypeWithDefaults<RequestProperties, "response", any>, TypeWithDefaults<RequestProperties, "payload", any>, TypeWithDefaults<RequestProperties, "queryParams", any>, TypeWithDefaults<RequestProperties, "error", any>, TypeWithDefaults<RequestProperties, "endpoint", any>, TypeWithDefaults<RequestProperties, "client", ClientInstance>, TypeWithDefaults<RequestProperties, "hasParams", any>, TypeWithDefaults<RequestProperties, "hasQueryParams", any>, TypeWithDefaults<RequestProperties, "hasPayload", any>>;
773
- type ProgressEventType = {
774
- total: number;
775
- loaded: number;
776
- };
777
- /**
778
- * Dump of the request used to later recreate it
779
- */
780
- type RequestJSON<Request extends RequestInstance> = {
781
- requestOptions: RequestOptionsType<ExtractEndpointType<Request>, ExtractAdapterOptionsType<ExtractAdapterType<Request>>, ExtractAdapterMethodType<ExtractAdapterType<Request>>>;
782
- endpoint: ExtractEndpointType<Request>;
783
- method: ExtractAdapterMethodType<ExtractAdapterType<Request>>;
784
- headers?: HeadersInit;
785
- auth: boolean;
786
- cancelable: boolean;
787
- retry: number;
788
- retryTime: number;
789
- cacheTime: number;
790
- cache: boolean;
791
- staleTime: number;
792
- queued: boolean;
793
- offline: boolean;
794
- disableResponseInterceptors: boolean | undefined;
795
- disableRequestInterceptors: boolean | undefined;
796
- options?: ExtractAdapterOptionsType<ExtractAdapterType<Request>>;
797
- payload: PayloadType<ExtractPayloadType<Request>>;
798
- params: ExtractParamsType<Request> | EmptyTypes;
799
- queryParams: ExtractQueryParamsType<Request> | EmptyTypes;
800
- abortKey: string;
801
- cacheKey: string;
802
- queryKey: string;
803
- used: boolean;
804
- updatedAbortKey: boolean;
805
- updatedCacheKey: boolean;
806
- updatedQueryKey: boolean;
807
- deduplicate: boolean;
808
- deduplicateTime: number | null;
809
- isMockerEnabled: boolean;
810
- hasMock: boolean;
811
- };
812
- /**
813
- * Configuration options for request creation
814
- */
815
- type RequestOptionsType<GenericEndpoint, AdapterOptions, RequestMethods = HttpMethodsType> = {
816
- /**
817
- * Determine the endpoint for request request
818
- */
819
- endpoint: GenericEndpoint;
820
- /**
821
- * Custom headers for request
822
- */
823
- headers?: HeadersInit;
824
- /**
825
- * Should the onAuth method get called on this request
826
- */
827
- auth?: boolean;
828
- /**
829
- * Request method picked from method names handled by adapter
830
- * With default adapter it is GET | POST | PATCH | PUT | DELETE
831
- */
832
- method?: RequestMethods;
833
- /**
834
- * Should enable cancelable mode in the Dispatcher
835
- */
836
- cancelable?: boolean;
837
- /**
838
- * Retry count when request is failed
839
- */
840
- retry?: number;
841
- /**
842
- * Retry time delay between retries
843
- */
844
- retryTime?: number;
845
- /**
846
- * Should we trigger garbage collection or leave data in memory
847
- */
848
- cacheTime?: number;
849
- /**
850
- * Should we save the response to cache
851
- */
852
- cache?: boolean;
853
- /**
854
- * Time for which the cache is considered up-to-date
855
- */
856
- staleTime?: number;
857
- /**
858
- * Should the requests from this request be send one-by-one
859
- */
860
- queued?: boolean;
861
- /**
862
- * Do we want to store request made in offline mode for latter use when we go back online
863
- */
864
- offline?: boolean;
865
- /**
866
- * Disable post-request interceptors
867
- */
868
- disableResponseInterceptors?: boolean;
869
- /**
870
- * Disable pre-request interceptors
871
- */
872
- disableRequestInterceptors?: boolean;
873
- /**
874
- * Additional options for your adapter, by default XHR options
875
- */
876
- options?: AdapterOptions;
877
- /**
878
- * Key which will be used to cancel requests. Autogenerated by default.
879
- */
880
- abortKey?: string;
881
- /**
882
- * Key which will be used to cache requests. Autogenerated by default.
883
- */
884
- cacheKey?: string;
885
- /**
886
- * Key which will be used to queue requests. Autogenerated by default.
887
- */
888
- queryKey?: string;
889
- /**
890
- * Should we deduplicate two requests made at the same time into one
891
- */
892
- deduplicate?: boolean;
893
- /**
894
- * Time of pooling for the deduplication to be active (default 10ms)
895
- */
896
- deduplicateTime?: number;
897
- };
898
- type PayloadMapperType<Payload> = <NewDataType>(payload: Payload) => NewDataType;
899
- type PayloadType<Payload> = Payload | EmptyTypes;
900
- type RequestConfigurationType<Payload, Params, QueryParams, GenericEndpoint extends string, AdapterOptions, MethodsType> = {
901
- used?: boolean;
902
- params?: Params | EmptyTypes;
903
- queryParams?: QueryParams | EmptyTypes;
904
- payload?: PayloadType<Payload>;
905
- headers?: HeadersInit;
906
- updatedAbortKey?: boolean;
907
- updatedCacheKey?: boolean;
908
- updatedQueryKey?: boolean;
909
- updatedEffectKey?: boolean;
910
- } & Partial<NullableKeys<RequestOptionsType<GenericEndpoint, AdapterOptions, MethodsType>>>;
911
- type ParamType = string | number;
912
- type ParamsType = Record<string, ParamType>;
913
- type ExtractUrlParams<T extends string> = string extends T ? EmptyTypes : T extends `${string}:${infer Param}/${infer Rest}` ? {
914
- [k in Param | keyof ExtractUrlParams<Rest>]: ParamType;
915
- } : T extends `${string}:${infer Param}` ? {
916
- [k in Param]: ParamType;
917
- } : EmptyTypes;
918
- /**
919
- * If the request endpoint parameters are not filled it will throw an error
920
- */
921
- type FetchParamsType<Params, HasParams extends true | false> = Params extends EmptyTypes | void | never ? {
922
- params?: EmptyTypes;
923
- } : HasParams extends true ? {
924
- params?: EmptyTypes;
925
- } : {
926
- params: Params;
927
- };
928
- /**
929
- * If the request data is not filled it will throw an error
930
- */
931
- type FetchPayloadType<Payload, HasPayload extends true | false> = Payload extends EmptyTypes | void | never ? {
932
- payload?: EmptyTypes;
933
- } : HasPayload extends true ? {
934
- payload?: EmptyTypes;
935
- } : {
936
- payload: Payload;
937
- };
938
- /**
939
- * It will check if the query params are already set
940
- */
941
- type FetchQueryParamsType<QueryParams, HasQuery extends true | false = false> = HasQuery extends true ? {
942
- queryParams?: EmptyTypes | undefined;
943
- } : HasQuery extends true ? {
944
- queryParams?: EmptyTypes;
945
- } : QueryParams extends EmptyTypes | void | never ? {
946
- queryParams?: QueryParams;
947
- } : {
948
- queryParams: QueryParams;
949
- };
950
- type RequestDynamicSendOptionsType<Request extends RequestInstance> = Omit<Partial<RequestOptionsType<string, ExtractAdapterOptionsType<ExtractAdapterType<Request>>>>, "params" | "data" | "endpoint" | "method"> & {
951
- dispatcherType?: "auto" | "fetch" | "submit";
952
- };
953
- type RequestSendOptionsType<Request extends RequestInstance> = FetchQueryParamsType<ExtractQueryParamsType<Request>, ExtractHasQueryParamsType<Request>> & FetchParamsType<ExtractParamsType<Request>, ExtractHasParamsType<Request>> & FetchPayloadType<ExtractPayloadType<Request>, ExtractHasPayloadType<Request>> & FetchQueryParamsType<ExtractQueryParamsType<Request>, ExtractHasQueryParamsType<Request>> & RequestSendActionsType<Request> & RequestDynamicSendOptionsType<Request>;
954
- type RequestSendActionsType<Request extends RequestInstance> = {
955
- onBeforeSent?: (eventData: RequestEventType<Request>) => void;
956
- onRequestStart?: (eventData: RequestEventType<Request>) => void;
957
- onResponseStart?: (eventData: RequestEventType<Request>) => void;
958
- onUploadProgress?: (eventData: RequestProgressEventType<Request>) => void;
959
- onDownloadProgress?: (eventData: RequestProgressEventType<Request>) => void;
960
- onResponse?: (eventData: RequestResponseEventType<Request>) => void;
961
- onRemove?: (eventData: RequestEventType<Request>) => void;
962
- };
963
- type IsNegativeType<T> = void extends T ? EmptyTypes : undefined extends T ? EmptyTypes : null extends T ? EmptyTypes : T;
964
- type RequestSendType<Request extends RequestInstance> = IsNegativeType<RequestSendOptionsType<Request>["payload"]> extends EmptyTypes | void | never ? IsNegativeType<RequestSendOptionsType<Request>["params"]> extends EmptyTypes | void | never ? IsNegativeType<RequestSendOptionsType<Request>["queryParams"]> extends EmptyTypes | void | never ? (options?: RequestSendOptionsType<Request>) => Promise<RequestResponseType<Request>> : (options: RequestSendOptionsType<Request>) => Promise<RequestResponseType<Request>> : (options: RequestSendOptionsType<Request>) => Promise<RequestResponseType<Request>> : (options: RequestSendOptionsType<Request>) => Promise<RequestResponseType<Request>>;
965
- type RequestMapper<Request extends RequestInstance, NewRequest extends RequestInstance> = (request: Request, requestId: string) => NewRequest | Promise<NewRequest>;
966
- type ResponseMapper<Request extends RequestInstance, MappedResponse extends ResponseSuccessType<any, any> | ResponseErrorType<any, any>> = (response: ResponseSuccessType<ExtractResponseType<Request>, ExtractAdapterType<Request>> | ResponseErrorType<ExtractErrorType<Request>, ExtractAdapterType<Request>>) => MappedResponse | Promise<MappedResponse>;
967
-
968
- declare enum DispatcherMode {
969
- ONE_BY_ONE = "one-by-one",
970
- ALL_AT_ONCE = "all-at-once",
971
- PREVIOUS_CANCELED = "previous-canceled",
972
- DEDUPLICATED = "deduplicated"
973
- }
974
-
975
- declare const getDispatcherEvents: (emitter: EventEmitter$1) => {
976
- emitDrained: <Request extends RequestInstance>(values: QueueDataType<Request>, isTriggeredExternally?: boolean) => void;
977
- emitQueueStatusChanged: <Request extends RequestInstance>(values: QueueDataType<Request>, isTriggeredExternally?: boolean) => void;
978
- emitQueueChanged: <Request extends RequestInstance>(values: QueueDataType<Request>, isTriggeredExternally?: boolean) => void;
979
- /**
980
- * When queue becomes empty
981
- * @param callback
982
- * @returns
983
- */
984
- onDrained: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void) => VoidFunction;
985
- /**
986
- * When queue becomes empty
987
- * @param queryKey
988
- * @param callback
989
- * @returns
990
- */
991
- onDrainedByKey: <Request extends RequestInstance>(queryKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction;
992
- /**
993
- * When queue status change from enabled to paused or vice versa
994
- * @param callback
995
- * @returns
996
- */
997
- onQueueStatusChange: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void) => VoidFunction;
998
- /**
999
- * When queue status change from enabled to paused or vice versa
1000
- * @param queryKey
1001
- * @param callback
1002
- * @returns
1003
- */
1004
- onQueueStatusChangeByKey: <Request extends RequestInstance>(queryKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1005
- /**
1006
- * When new elements are added or removed from the queue
1007
- * @param queryKey
1008
- * @param callback
1009
- * @returns
1010
- */
1011
- onQueueChange: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1012
- /**
1013
- * When new elements are added or removed from the queue
1014
- * @param queryKey
1015
- * @param callback
1016
- * @returns
1017
- */
1018
- onQueueChangeByKey: <Request extends RequestInstance>(queryKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1019
- };
1020
-
1021
- /**
1022
- * Dispatcher controls and manages the requests that are going to be executed with adapter. It manages them based on the options provided with request.
1023
- * This class can also run them with different modes like deduplication, cancelation, queueing or run-all-at-once mode. With it's help we can pause,
1024
- * stop, start and cancel requests.
1025
- */
1026
- declare class Dispatcher<Adapter extends AdapterInstance> {
1027
- options?: DispatcherOptionsType | undefined;
1028
- emitter: EventEmitter;
1029
- events: {
1030
- emitDrained: <Request extends RequestInstance>(values: QueueDataType<Request>, isTriggeredExternally?: boolean) => void;
1031
- emitQueueStatusChanged: <Request extends RequestInstance>(values: QueueDataType<Request>, isTriggeredExternally?: boolean) => void;
1032
- emitQueueChanged: <Request extends RequestInstance>(values: QueueDataType<Request>, isTriggeredExternally?: boolean) => void;
1033
- onDrained: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1034
- onDrainedByKey: <Request extends RequestInstance>(queryKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1035
- onQueueStatusChange: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1036
- onQueueStatusChangeByKey: <Request extends RequestInstance>(queryKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1037
- onQueueChange: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1038
- onQueueChangeByKey: <Request extends RequestInstance>(queryKey: string, callback: (values: QueueDataType<Request>) => void) => VoidFunction;
1039
- };
1040
- storage: DispatcherStorageType;
1041
- private requestCount;
1042
- private runningRequests;
1043
- private logger;
1044
- private client;
1045
- constructor(options?: DispatcherOptionsType | undefined);
1046
- initialize: (client: ClientInstance<{
1047
- adapter: Adapter;
1048
- }>) => this;
1049
- /**
1050
- * Start request handling by queryKey
1051
- */
1052
- start: (queryKey: string) => void;
1053
- /**
1054
- * Pause request queue, but do not cancel already started requests
1055
- */
1056
- pause: (queryKey: string) => void;
1057
- /**
1058
- * Stop request queue and cancel all started requests - those will be treated like not started
1059
- */
1060
- stop: (queryKey: string) => void;
1061
- /**
1062
- * Return all
1063
- */
1064
- getQueuesKeys: () => string[];
1065
- /**
1066
- * Return queue state object
1067
- */
1068
- getQueue: <Request extends RequestInstance = RequestInstance>(queryKey: string) => QueueDataType<Request>;
1069
- /**
1070
- * Return request from queue state
1071
- */
1072
- getRequest: <Request extends RequestInstance = RequestInstance>(queryKey: string, requestId: string) => QueueItemType<Request> | undefined;
1073
- /**
1074
- * Get value of the active queue status based on the stopped status
1075
- */
1076
- getIsActiveQueue: (queryKey: string) => boolean;
1077
- /**
1078
- * Add new element to storage
1079
- */
1080
- addQueueItem: <Request extends RequestInstance = RequestInstance>(queryKey: string, element: QueueItemType<Request>) => void;
1081
- /**
1082
- * Set new queue storage value
1083
- */
1084
- setQueue: <Request extends RequestInstance = RequestInstance>(queryKey: string, queue: QueueDataType<Request>) => QueueDataType<Request>;
1085
- /**
1086
- * Clear requests from queue cache
1087
- */
1088
- clearQueue: (queryKey: string) => {
1089
- queryKey: string;
1090
- requests: never[];
1091
- stopped: boolean;
1092
- };
1093
- /**
1094
- * Method used to flush the queue requests
1095
- */
1096
- flushQueue: (queryKey: string) => Promise<void>;
1097
- /**
1098
- * Flush all available requests from all queues
1099
- */
1100
- flush: () => Promise<void>;
1101
- /**
1102
- * Clear all running requests and storage
1103
- */
1104
- clear: () => void;
1105
- /**
1106
- * Start particular request
1107
- */
1108
- startRequest: (queryKey: string, requestId: string) => void;
1109
- /**
1110
- * Stop particular request
1111
- */
1112
- stopRequest: (queryKey: string, requestId: string) => void;
1113
- /**
1114
- * Get currently running requests from all queryKeys
1115
- */
1116
- getAllRunningRequests: () => RunningRequestValueType[];
1117
- /**
1118
- * Get currently running requests
1119
- */
1120
- getRunningRequests: (queryKey: string) => RunningRequestValueType[];
1121
- /**
1122
- * Get running request by id
1123
- */
1124
- getRunningRequest: (queryKey: string, requestId: string) => RunningRequestValueType | undefined;
1125
- /**
1126
- * Add request to the running requests list
1127
- */
1128
- addRunningRequest: (queryKey: string, requestId: string, request: RequestInstance) => RunningRequestValueType;
1129
- /**
1130
- * Get the value based on the currently running requests
1131
- */
1132
- hasRunningRequests: (queryKey: string) => boolean;
1133
- /**
1134
- * Check if request is currently processing
1135
- */
1136
- hasRunningRequest: (queryKey: string, requestId: string) => boolean;
1137
- /**
1138
- * Cancel all started requests, but do NOT remove it from main storage
1139
- */
1140
- cancelRunningRequests: (queryKey: string) => void;
1141
- /**
1142
- * Cancel started request, but do NOT remove it from main storage
1143
- */
1144
- cancelRunningRequest: (queryKey: string, requestId: string) => void;
1145
- /**
1146
- * Delete all started requests, but do NOT clear it from queue and do NOT cancel them
1147
- */
1148
- deleteRunningRequests: (queryKey: string) => void;
1149
- /**
1150
- * Delete request by id, but do NOT clear it from queue and do NOT cancel them
1151
- */
1152
- deleteRunningRequest: (queryKey: string, requestId: string) => void;
1153
- /**
1154
- * Get count of requests from the same queryKey
1155
- */
1156
- getQueueRequestCount: (queryKey: string) => number;
1157
- /**
1158
- * Add request count to the queryKey
1159
- */
1160
- incrementQueueRequestCount: (queryKey: string) => void;
1161
- /**
1162
- * Create storage element from request
1163
- */
1164
- createStorageItem: <Request extends RequestInstance>(request: Request) => QueueItemType<Request>;
1165
- /**
1166
- * Add request to the dispatcher handler
1167
- */
1168
- add: (request: RequestInstance) => string;
1169
- /**
1170
- * Delete from the storage and cancel request
1171
- */
1172
- delete: (queryKey: string, requestId: string, abortKey: string) => QueueDataType<RequestInstance> | undefined;
1173
- /**
1174
- * Request can run for some time, once it's done, we have to check if it's successful or if it was aborted
1175
- * It can be different once the previous call was set as cancelled and removed from queue before this request got resolved
1176
- */
1177
- performRequest: (storageItem: QueueItemType) => Promise<void | QueueDataType<RequestInstance>>;
1178
- }
1179
-
1180
- type DispatcherOptionsType = {
1181
- storage?: DispatcherStorageType;
1182
- };
1183
- type QueueItemType<Request extends RequestInstance = RequestInstance> = {
1184
- requestId: string;
1185
- request: Request;
1186
- retries: number;
1187
- timestamp: number;
1188
- stopped: boolean;
1189
- /** Resolved when we receive response */
1190
- resolved: boolean;
1191
- };
1192
- type QueueDataType<Request extends RequestInstance = RequestInstance> = {
1193
- queryKey: string;
1194
- requests: QueueItemType<Request>[];
1195
- stopped: boolean;
1196
- };
1197
- type DispatcherStorageType = {
1198
- set: <Request extends RequestInstance = RequestInstance>(key: string, data: QueueDataType<Request>) => void;
1199
- get: <Request extends RequestInstance = RequestInstance>(key: string) => QueueDataType<Request> | undefined;
1200
- keys: () => string[] | IterableIterator<string>;
1201
- entries: () => [string, QueueDataType] | IterableIterator<[string, QueueDataType<any>]>;
1202
- delete: (key: string) => void;
1203
- clear: () => void;
1204
- };
1205
- type RunningRequestValueType = {
1206
- requestId: string;
1207
- request: RequestInstance;
1208
- timestamp: number;
1209
- };
1210
-
1211
- declare const getDispatcherDrainedKey: () => string;
1212
- declare const getDispatcherDrainedByKey: (key: string) => string;
1213
- declare const getDispatcherStatusKey: () => string;
1214
- declare const getDispatcherStatusByKey: (key: string) => string;
1215
- declare const getDispatcherChangeKey: () => string;
1216
- declare const getDispatcherChangeByKey: (key: string) => string;
1217
- declare const getIsEqualTimestamp: (currentTimestamp: number, threshold: number, queueTimestamp?: number) => boolean;
1218
- declare const canRetryRequest: (currentRetries: number, retry: number | undefined) => boolean;
1219
- declare const getRequestType: (request: RequestInstance, latestRequest: QueueItemType | undefined) => DispatcherMode;
1220
-
1221
- declare const stringifyKey: (value: unknown) => string;
1222
- declare const getProgressValue: ({ loaded, total }: ProgressEventType) => number;
1223
- declare const getRequestEta: (startDate: Date, progressDate: Date, { total, loaded }: ProgressEventType) => {
1224
- sizeLeft: number;
1225
- timeLeft: number | null;
1226
- };
1227
- declare const getProgressData: (requestStartTime: Date, progressDate: Date, progressEvent: ProgressEventType) => ProgressType;
1228
- declare const getSimpleKey: (request: RequestInstance | RequestJSON<RequestInstance>) => string;
1229
- /**
1230
- * Cache instance for individual request that collects individual requests responses from
1231
- * the same endpoint (they may differ base on the custom key, endpoint params etc)
1232
- * @param request
1233
- * @param useInitialValues
1234
- * @returns
1235
- */
1236
- declare const getRequestKey: (request: RequestInstance | RequestJSON<RequestInstance>, useInitialValues?: boolean) => string;
1237
- declare const getRequestDispatcher: <Request extends RequestInstance>(request: Request, dispatcherType?: "auto" | "fetch" | "submit") => [Dispatcher<ExtractAdapterType<Request>>, isFetchDispatcher: boolean];
1238
- declare const sendRequest: <Request extends RequestInstance>(request: Request, options?: RequestSendOptionsType<Request>) => Promise<RequestResponseType<Request>>;
1239
-
1240
- declare const getUniqueRequestId: (request: Pick<RequestInstance, "queryKey">) => string;
1241
-
1242
- declare class EventEmitter extends EventEmitter$1 {
1243
- emitCallbacks: Array<(event: string, data: any, isTriggeredExternally?: true) => void>;
1244
- constructor(options?: ConstructorParameters<typeof EventEmitter$1>[0]);
1245
- emit(type: string, data: any, isTriggeredExternally: boolean): boolean;
1246
- onEmit: (callback: (event: string, data: any, isTriggeredExternally?: true) => void) => () => void;
1247
- onListener: (event: string, listener: (count: number) => void) => () => void;
1248
- on: (event: string | symbol, listener: (...args: any[]) => void) => this;
1249
- off: (event: string | symbol, listener: (...args: any[]) => void) => this;
1250
- addListener: (event: string | symbol, listener: (...args: any[]) => void) => this;
1251
- removeListener: (event: string | symbol, listener: (...args: any[]) => void) => this;
1252
- }
1253
-
1254
- /**
1255
- * App manager handles main application states - focus and online. Those two values can answer questions:
1256
- * - Is the tab or current view instance focused and visible for user?
1257
- * - Is our application online or offline?
1258
- * With the app manager it is not a problem to get the valid answer for this question.
1259
- *
1260
- * @caution
1261
- * Make sure to apply valid focus/online handlers for different environments like for example for native mobile applications.
1262
- */
1263
- declare class AppManager {
1264
- options?: AppManagerOptionsType | undefined;
1265
- emitter: EventEmitter;
1266
- events: {
1267
- emitFocus: () => void;
1268
- emitBlur: () => void;
1269
- emitOnline: () => void;
1270
- emitOffline: () => void;
1271
- onFocus: (callback: () => void) => VoidFunction;
1272
- onBlur: (callback: () => void) => VoidFunction;
1273
- onOnline: (callback: () => void) => VoidFunction;
1274
- onOffline: (callback: () => void) => VoidFunction;
1275
- };
1276
- isBrowser: boolean;
1277
- isOnline: boolean;
1278
- isFocused: boolean;
1279
- constructor(options?: AppManagerOptionsType | undefined);
1280
- initialize: () => void;
1281
- private setInitialFocus;
1282
- private setInitialOnline;
1283
- setFocused: (isFocused: boolean) => void;
1284
- setOnline: (isOnline: boolean) => void;
1285
- }
1286
-
1287
- type AppManagerOptionsType = {
1288
- initiallyFocused?: boolean | (() => boolean | Promise<boolean>);
1289
- initiallyOnline?: boolean | (() => boolean | Promise<boolean>);
1290
- focusEvent?: (setFocused: (isFocused: boolean) => void) => void;
1291
- onlineEvent?: (setOnline: (isOnline: boolean) => void) => void;
1292
- };
1293
-
1294
- declare const hasWindow: () => boolean;
1295
- declare const hasDocument: () => boolean;
1296
- declare const onWindowEvent: <K extends keyof WindowEventMap>(key: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined) => VoidFunction;
1297
- declare const onDocumentEvent: <K extends keyof DocumentEventMap>(key: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined) => VoidFunction;
1298
-
1299
- declare const getAppManagerEvents: (emitter: EventEmitter$1) => {
1300
- emitFocus: () => void;
1301
- emitBlur: () => void;
1302
- emitOnline: () => void;
1303
- emitOffline: () => void;
1304
- onFocus: (callback: () => void) => VoidFunction;
1305
- onBlur: (callback: () => void) => VoidFunction;
1306
- onOnline: (callback: () => void) => VoidFunction;
1307
- onOffline: (callback: () => void) => VoidFunction;
1308
- };
1309
-
1310
- declare enum AppEvents {
1311
- FOCUS = "focus",
1312
- BLUR = "blur",
1313
- ONLINE = "online",
1314
- OFFLINE = "offline"
1315
- }
1316
- declare const appManagerInitialOptions: RequiredKeys<AppManagerOptionsType>;
1317
-
1318
- /**
1319
- * **Request Manager** is used to emit `request lifecycle events` like - request start, request end, upload and download progress.
1320
- * It is also the place of `request aborting` system, here we store all the keys and controllers that are isolated for each client instance.
1321
- */
1322
- declare class RequestManager {
1323
- emitter: EventEmitter;
1324
- events: {
1325
- emitDeduplicated: (data: RequestDeduplicatedEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1326
- emitLoading: (data: RequestLoadingEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1327
- emitRequestStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1328
- emitResponseStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1329
- emitUploadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1330
- emitDownloadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1331
- emitResponse: <Adapter extends AdapterInstance>(data: RequestResponseEventType<ExtendRequest<RequestInstance, {
1332
- client: Client$1<any, Adapter>;
1333
- }>>, isTriggeredExternally?: boolean) => void;
1334
- emitAbort: (data: RequestEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1335
- emitRemove: (data: RequestRemovedEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1336
- onDeduplicated: <T extends RequestInstance>(callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1337
- onDeduplicatedByQueue: <T extends RequestInstance>(queryKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1338
- onDeduplicatedByCache: <T extends RequestInstance>(cacheKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1339
- onDeduplicatedById: <T extends RequestInstance>(requestId: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1340
- onLoading: <T extends RequestInstance>(callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1341
- onLoadingByQueue: <T extends RequestInstance>(queryKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1342
- onLoadingByCache: <T extends RequestInstance>(cacheKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1343
- onLoadingById: <T extends RequestInstance>(requestId: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1344
- onRequestStart: <T extends RequestInstance>(callback: (details: RequestEventType<T>) => void) => VoidFunction;
1345
- onRequestStartByQueue: <T extends RequestInstance>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1346
- onRequestStartById: <T extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1347
- onResponseStart: <T extends RequestInstance>(callback: (details: RequestEventType<T>) => void) => VoidFunction;
1348
- onResponseStartByQueue: <T extends RequestInstance>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1349
- onResponseStartById: <T extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1350
- onUploadProgress: <T extends RequestInstance = RequestInstance>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1351
- onUploadProgressByQueue: <T extends RequestInstance = RequestInstance>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1352
- onUploadProgressById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1353
- onDownloadProgress: <T extends RequestInstance = RequestInstance>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1354
- onDownloadProgressByQueue: <T extends RequestInstance = RequestInstance>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1355
- onDownloadProgressById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1356
- onResponse: <T extends RequestInstance>(callback: (data: RequestResponseEventType<T>) => void) => VoidFunction;
1357
- onResponseByCache: <T extends RequestInstance>(cacheKey: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction;
1358
- onResponseById: <T extends RequestInstance>(requestId: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction;
1359
- onAbort: <T extends RequestInstance = RequestInstance>(callback: (request: RequestEventType<T>) => void) => VoidFunction;
1360
- onAbortByKey: <T extends RequestInstance = RequestInstance>(abortKey: string, callback: (request: RequestEventType<T>) => void) => VoidFunction;
1361
- onAbortById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestEventType<T>) => void) => VoidFunction;
1362
- onRemove: <T extends RequestInstance = RequestInstance>(callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction;
1363
- onRemoveByQueue: <T extends RequestInstance = RequestInstance>(queryKey: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction;
1364
- onRemoveById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction;
1365
- };
1366
- constructor();
1367
- abortControllers: Map<string, Map<string, AbortController>>;
1368
- addAbortController: (abortKey: string, requestId: string) => void;
1369
- getAbortController: (abortKey: string, requestId: string) => AbortController | undefined;
1370
- removeAbortController: (abortKey: string, requestId: string) => void;
1371
- useAbortController: (abortKey: string, requestId: string) => void;
1372
- abortByKey: (abortKey: string) => void;
1373
- abortByRequestId: (abortKey: string, requestId: string) => void;
1374
- abortAll: () => void;
1375
- }
1376
-
1377
- declare const getLoadingKey: () => string;
1378
- declare const getLoadingByQueryKey: (queryKey: string) => string;
1379
- declare const getLoadingByCacheKey: (cacheKey: string) => string;
1380
- declare const getLoadingByIdKey: (id: string) => string;
1381
- declare const getRemoveKey: () => string;
1382
- declare const getRemoveByQueryKey: (queryKey: string) => string;
1383
- declare const getRemoveByIdKey: (id: string) => string;
1384
- declare const getAbortKey: () => string;
1385
- declare const getAbortByAbortKey: (abortKey: string) => string;
1386
- declare const getAbortByIdKey: (id: string) => string;
1387
- declare const getResponseKey: () => string;
1388
- declare const getResponseByCacheKey: (cacheKey: string) => string;
1389
- declare const getResponseByIdKey: (id: string) => string;
1390
- declare const getRequestStartKey: () => string;
1391
- declare const getRequestStarByQueryKey: (queryKey: string) => string;
1392
- declare const getRequestStartByIdKey: (id: string) => string;
1393
- declare const getResponseStartKey: () => string;
1394
- declare const getResponseStartByQueryKey: (queryKey: string) => string;
1395
- declare const getResponseStartByIdKey: (id: string) => string;
1396
- declare const getUploadProgressKey: () => string;
1397
- declare const getUploadProgressByQueryKey: (queryKey: string) => string;
1398
- declare const getUploadProgressByIdKey: (id: string) => string;
1399
- declare const getDownloadProgressKey: () => string;
1400
- declare const getDownloadProgressByQueryKey: (queryKey: string) => string;
1401
- declare const getDownloadProgressByIdKey: (id: string) => string;
1402
- declare const getRequestDeduplicatedKey: () => string;
1403
- declare const getRequestDeduplicatedByQueryKey: (queryKey: string) => string;
1404
- declare const getRequestDeduplicatedByCacheKey: (cacheKey: string) => string;
1405
- declare const getRequestDeduplicatedByIdKey: (id: string) => string;
1406
-
1407
- declare const getRequestManagerEvents: (emitter: EventEmitter$1) => {
1408
- /**
1409
- * Emiter
1410
- */
1411
- emitDeduplicated: (data: RequestDeduplicatedEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1412
- emitLoading: (data: RequestLoadingEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1413
- emitRequestStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1414
- emitResponseStart: (data: RequestEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1415
- emitUploadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1416
- emitDownloadProgress: (data: RequestProgressEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1417
- emitResponse: <Adapter extends AdapterInstance>(data: RequestResponseEventType<ExtendRequest<RequestInstance, {
1418
- client: Client$1<any, Adapter>;
1419
- }>>, isTriggeredExternally?: boolean) => void;
1420
- emitAbort: (data: RequestEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1421
- emitRemove: (data: RequestRemovedEventType<RequestInstance>, isTriggeredExternally?: boolean) => void;
1422
- /**
1423
- * Listeners
1424
- */
1425
- onDeduplicated: <T extends RequestInstance>(callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1426
- onDeduplicatedByQueue: <T extends RequestInstance>(queryKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1427
- onDeduplicatedByCache: <T extends RequestInstance>(cacheKey: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1428
- onDeduplicatedById: <T extends RequestInstance>(requestId: string, callback: (data: RequestDeduplicatedEventType<T>) => void) => VoidFunction;
1429
- onLoading: <T extends RequestInstance>(callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1430
- onLoadingByQueue: <T extends RequestInstance>(queryKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1431
- onLoadingByCache: <T extends RequestInstance>(cacheKey: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1432
- onLoadingById: <T extends RequestInstance>(requestId: string, callback: (data: RequestLoadingEventType<T>) => void) => VoidFunction;
1433
- onRequestStart: <T extends RequestInstance>(callback: (details: RequestEventType<T>) => void) => VoidFunction;
1434
- onRequestStartByQueue: <T extends RequestInstance>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1435
- onRequestStartById: <T extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1436
- onResponseStart: <T extends RequestInstance>(callback: (details: RequestEventType<T>) => void) => VoidFunction;
1437
- onResponseStartByQueue: <T extends RequestInstance>(queryKey: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1438
- onResponseStartById: <T extends RequestInstance>(requestId: string, callback: (details: RequestEventType<T>) => void) => VoidFunction;
1439
- onUploadProgress: <T extends RequestInstance = RequestInstance>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1440
- onUploadProgressByQueue: <T extends RequestInstance = RequestInstance>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1441
- onUploadProgressById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1442
- onDownloadProgress: <T extends RequestInstance = RequestInstance>(callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1443
- onDownloadProgressByQueue: <T extends RequestInstance = RequestInstance>(queryKey: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1444
- onDownloadProgressById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestProgressEventType<T>) => void) => VoidFunction;
1445
- onResponse: <T extends RequestInstance>(callback: (data: RequestResponseEventType<T>) => void) => VoidFunction;
1446
- onResponseByCache: <T extends RequestInstance>(cacheKey: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction;
1447
- onResponseById: <T extends RequestInstance>(requestId: string, callback: (data: RequestResponseEventType<T>) => void) => VoidFunction;
1448
- onAbort: <T extends RequestInstance = RequestInstance>(callback: (request: RequestEventType<T>) => void) => VoidFunction;
1449
- onAbortByKey: <T extends RequestInstance = RequestInstance>(abortKey: string, callback: (request: RequestEventType<T>) => void) => VoidFunction;
1450
- onAbortById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestEventType<T>) => void) => VoidFunction;
1451
- onRemove: <T extends RequestInstance = RequestInstance>(callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction;
1452
- onRemoveByQueue: <T extends RequestInstance = RequestInstance>(queryKey: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction;
1453
- onRemoveById: <T extends RequestInstance = RequestInstance>(requestId: string, callback: (data: RequestRemovedEventType<T>) => void) => VoidFunction;
1454
- };
1455
-
1456
- type RequestLoadingEventType<T extends RequestInstance> = {
1457
- loading: boolean;
1458
- isRetry: boolean;
1459
- isOffline: boolean;
1460
- } & RequestEventType<T>;
1461
- type RequestProgressEventType<T extends RequestInstance> = ProgressType & RequestEventType<T>;
1462
- type RequestEventType<T extends RequestInstance> = {
1463
- request: T;
1464
- requestId: string;
1465
- };
1466
- type RequestRemovedEventType<T extends RequestInstance> = {
1467
- request: T;
1468
- requestId: string;
1469
- /** @true when we receive any response, @false if removed before response is received */
1470
- resolved: boolean;
1471
- };
1472
- type RequestResponseEventType<T extends RequestInstance> = {
1473
- request: T;
1474
- requestId: string;
1475
- response: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>;
1476
- details: ResponseDetailsType;
1477
- };
1478
- type RequestDeduplicatedEventType<T extends RequestInstance> = RequestEventType<T> & {
1479
- deduplicatedRequest: T;
1480
- };
1481
- type ResponseDetailsType = {
1482
- /** If it's retry request we can see which attempt is it */
1483
- retries: number;
1484
- /** If request was canceled */
1485
- isCanceled: boolean;
1486
- /** If error from offline status */
1487
- isOffline: boolean;
1488
- /** When added to dispatcher's queue (pre-middleware which could take time) */
1489
- addedTimestamp: number;
1490
- /** When request is picked from queue and started to be sent */
1491
- triggerTimestamp: number;
1492
- /** When adapter triggers request (after all middlewares) */
1493
- requestTimestamp: number;
1494
- /** When we receive response */
1495
- responseTimestamp: number;
1496
- };
1497
-
1498
- /**
1499
- * This class is used across the Hyper Fetch library to provide unified logging system with necessary setup per each client.
1500
- * We can set up the logging level based on available values. This manager enable to initialize the logging instance per individual module
1501
- * like Client, Request etc. Which can give you better feedback on the logging itself.
1502
- */
1503
- declare class LoggerManager {
1504
- private options?;
1505
- logger: LoggerType;
1506
- level: LogLevel;
1507
- modules: string[] | undefined;
1508
- emitter: EventEmitter$1;
1509
- private client;
1510
- constructor(options?: LoggerOptionsType | undefined);
1511
- setSeverity: (level: LogLevel) => void;
1512
- setModules: (modules: string[] | undefined) => void;
1513
- initialize: (client: Pick<ClientInstance, "debug">, module: string) => LoggerMethods;
1514
- private log;
1515
- }
1516
-
1517
- declare const getTime: () => string;
1518
- declare const logger: LoggerType;
1519
-
1520
- type LogLevel = "debug" | "info" | "warning" | "error";
1521
- type LoggerOptionsType = {
1522
- logger?: LoggerType;
1523
- level?: LogLevel;
1524
- modules?: string[];
1525
- };
1526
- type LogData<Data extends Record<string, any>> = {
1527
- /** Some Message / https://google.com */
1528
- title: string;
1529
- /** Some contextual data */
1530
- extra: Data;
1531
- };
1532
- type LoggerArgs = LogDataTypes & {
1533
- /** "debug" | "info" | "warning" | "error" */
1534
- level: LogLevel;
1535
- /** Client / Request / Cache / Dispatcher / useFetch etc. */
1536
- module: string;
1537
- };
1538
- type LoggerType = (data: LoggerArgs) => void;
1539
- type LoggerMethods = Record<LogLevel, (data: LogDataTypes) => void>;
1540
- type LogRequestEventType = LogData<{
1541
- request: RequestInstance;
1542
- [key: string]: unknown;
1543
- }>;
1544
- type LogResponseEventType = LogData<{
1545
- request: RequestInstance;
1546
- response: ResponseType<any, any, AdapterInstance>;
1547
- requestId: string;
1548
- [key: string]: unknown;
1549
- }>;
1550
- type LogSystemEventType = LogData<{
1551
- [key: string]: unknown;
1552
- }>;
1553
- type LogDataTypes = ({
1554
- type: "request";
1555
- } & LogRequestEventType) | ({
1556
- type: "response";
1557
- } & LogResponseEventType) | ({
1558
- type: "system";
1559
- } & LogSystemEventType);
1560
-
1561
- declare const logLevelOrder: LogLevel[];
1562
- declare const loggerStyles: Record<LogLevel, string>;
1563
- declare const loggerColors: Record<LogLevel, string>;
1564
-
1565
- declare const getResponseHeaders: (headersString: string) => Record<string, string>;
1566
- declare const parseResponse: (response: string | unknown) => any;
1567
- declare const handleResponse: (responseChunks: any[], responseType: HttpAdapterRequest["responseType"], responseEncoding: BufferEncoding) => any;
1568
- declare const parseErrorResponse: <T extends RequestInstance>(response: unknown) => ExtractErrorType<T>;
1569
- declare const stringifyQueryParams: (queryParams: QueryParamsType | string | EmptyTypes, options?: QueryStringifyOptionsType) => string;
1570
-
1571
- /**
1572
- * Base Adapter
1573
- */
1574
- type HttpAdapterType = DeclareAdapterType<{
1575
- adapterOptions: HttpAdapterOptionsType;
1576
- methodType: HttpMethodsType;
1577
- statusType: HttpStatusType;
1578
- extra: HttpAdapterExtraType;
1579
- queryParams: QueryParamsType | string | null;
1580
- endpointType: string;
1581
- queryParamsMapperType: typeof stringifyQueryParams;
1582
- }>;
1583
- /**
1584
- * Options
1585
- */
1586
- interface HttpAdapterRequest extends Omit<XMLHttpRequest, "responseType"> {
1587
- responseType: XMLHttpRequestResponseType | "stream";
1588
- }
1589
- type HttpAdapterOptionsType = Partial<HttpAdapterRequest>;
1590
- type HttpAdapterExtraType = {
1591
- headers: Record<string, string>;
1592
- };
1593
- type HttpAdapterHeadersProps = {
1594
- isFormData: boolean;
1595
- headers: HeadersInit | undefined;
1596
- };
1597
- type QueryStringifyOptionsType = {
1598
- /**
1599
- * Strict URI encoding
1600
- */
1601
- strict?: boolean;
1602
- /**
1603
- * Encode keys and values
1604
- */
1605
- encode?: boolean;
1606
- /**
1607
- * Array encoding type
1608
- */
1609
- arrayFormat?: "bracket" | "index" | "comma" | "separator" | "bracket-separator" | "none";
1610
- /**
1611
- * Array format separator
1612
- */
1613
- arraySeparator?: string;
1614
- /**
1615
- * Skip keys with null values
1616
- */
1617
- skipNull?: boolean;
1618
- /**
1619
- * Skip keys with empty string
1620
- */
1621
- skipEmptyString?: boolean;
1622
- /**
1623
- * Parsing function for date type query param
1624
- */
1625
- dateParser?: (value: QueryParamType) => string;
1626
- /**
1627
- * Parsing function for object type query param
1628
- */
1629
- objectParser?: (value: QueryParamType) => string;
1630
- };
1631
- type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
1632
-
1633
- declare const HttpAdapter: () => HttpAdapterType;
1634
-
1635
- declare const defaultTimeout: number;
1636
- declare const xhrExtra: HttpAdapterExtraType;
1637
-
1638
- /**
1639
- * **Client** is a class that allows you to configure the connection with the server and then use it to create
1640
- * requests. It allows you to set global defaults for the requests configuration, query params configuration.
1641
- * It is also orchestrator for all of the HyperFetch modules like Cache, Dispatcher, AppManager, LoggerManager,
1642
- * RequestManager and more.
1643
- */
1644
- declare class Client$1<GlobalErrorType extends ClientErrorType = Error, Adapter extends AdapterInstance = HttpAdapterType> {
1645
- options: ClientOptionsType<Client$1<GlobalErrorType, Adapter>>;
1646
- readonly url: string;
1647
- debug: boolean;
1648
- unstable_onErrorCallbacks: ResponseInterceptorType<ClientInstance>[];
1649
- unstable_onSuccessCallbacks: ResponseInterceptorType<ClientInstance>[];
1650
- unstable_onResponseCallbacks: ResponseInterceptorType<ClientInstance>[];
1651
- unstable_onAuthCallbacks: RequestInterceptorType[];
1652
- unstable_onRequestCallbacks: RequestInterceptorType[];
1653
- loggerManager: LoggerManager;
1654
- requestManager: RequestManager;
1655
- appManager: AppManager;
1656
- adapter: Adapter;
1657
- cache: Cache<Adapter>;
1658
- fetchDispatcher: Dispatcher<Adapter>;
1659
- submitDispatcher: Dispatcher<Adapter>;
1660
- isMockerEnabled: boolean;
1661
- plugins: PluginInstance[];
1662
- /** @internal */
1663
- unstable_abortKeyMapper: (request: RequestInstance) => string;
1664
- /** @internal */
1665
- unstable_cacheKeyMapper: (request: RequestInstance) => string;
1666
- /** @internal */
1667
- unstable_queryKeyMapper: (request: RequestInstance) => string;
1668
- /** @internal */
1669
- unstable_requestIdMapper: (request: RequestInstance) => string;
1670
- logger: LoggerMethods;
1671
- constructor(options: ClientOptionsType<Client$1<GlobalErrorType, Adapter>>);
1672
- /**
1673
- * This method enables the logger usage and display the logs in console
1674
- */
1675
- setDebug: (enabled: boolean) => Client$1<GlobalErrorType, Adapter>;
1676
- /**
1677
- * Set the logger severity of the messages displayed to the console
1678
- */
1679
- setLogLevel: (severity: LogLevel) => Client$1<GlobalErrorType, Adapter>;
1680
- /**
1681
- * Set the new logger instance to the Client
1682
- */
1683
- setLogger: (callback: (Client: ClientInstance) => LoggerManager) => Client$1<GlobalErrorType, Adapter>;
1684
- /**
1685
- * Set globally if mocking should be enabled or disabled for all client requests.
1686
- * @param isMockerEnabled
1687
- */
1688
- setEnableGlobalMocking: (isMockerEnabled: boolean) => this;
1689
- /**
1690
- * Set custom http adapter to handle graphql, rest, firebase or others
1691
- */
1692
- setAdapter: <NewAdapter extends AdapterInstance>(adapter: NewAdapter) => Client$1<GlobalErrorType, NewAdapter>;
1693
- /**
1694
- * Method of manipulating requests before sending the request. We can for example add custom header with token to the request which request had the auth set to true.
1695
- */
1696
- onAuth: (callback: RequestInterceptorType) => Client$1<GlobalErrorType, Adapter>;
1697
- /**
1698
- * Method for removing listeners on auth.
1699
- * */
1700
- removeOnAuthInterceptors: (callbacks: RequestInterceptorType[]) => Client$1<GlobalErrorType, Adapter>;
1701
- /**
1702
- * Method for intercepting error responses. It can be used for example to refresh tokens.
1703
- */
1704
- onError: <ErrorType = null>(callback: ResponseInterceptorType<ClientInstance, any, ErrorType | GlobalErrorType>) => Client$1<GlobalErrorType, Adapter>;
1705
- /**
1706
- * Method for removing listeners on error.
1707
- * */
1708
- removeOnErrorInterceptors: (callbacks: ResponseInterceptorType<ClientInstance, any, null | GlobalErrorType>[]) => Client$1<GlobalErrorType, Adapter>;
1709
- /**
1710
- * Method for intercepting success responses.
1711
- */
1712
- onSuccess: <ErrorType = null>(callback: ResponseInterceptorType<ClientInstance, any, ErrorType | GlobalErrorType>) => Client$1<GlobalErrorType, Adapter>;
1713
- /**
1714
- * Method for removing listeners on success.
1715
- * */
1716
- removeOnSuccessInterceptors: (callbacks: ResponseInterceptorType<ClientInstance, any, null | GlobalErrorType>[]) => Client$1<GlobalErrorType, Adapter>;
1717
- /**
1718
- * Method of manipulating requests before sending the request.
1719
- */
1720
- onRequest: (callback: RequestInterceptorType) => Client$1<GlobalErrorType, Adapter>;
1721
- /**
1722
- * Method for removing listeners on request.
1723
- * */
1724
- removeOnRequestInterceptors: (callbacks: RequestInterceptorType[]) => Client$1<GlobalErrorType, Adapter>;
1725
- /**
1726
- * Method for intercepting any responses.
1727
- */
1728
- onResponse: <ErrorType = null>(callback: ResponseInterceptorType<ClientInstance, any, ErrorType | GlobalErrorType>) => Client$1<GlobalErrorType, Adapter>;
1729
- /**
1730
- * Method for removing listeners on request.
1731
- * */
1732
- removeOnResponseInterceptors: (callbacks: ResponseInterceptorType<ClientInstance, any, null | GlobalErrorType>[]) => Client$1<GlobalErrorType, Adapter>;
1733
- /**
1734
- * Add persistent plugins which trigger on the request lifecycle
1735
- */
1736
- addPlugin: (plugin: PluginInstance) => this;
1737
- /**
1738
- * Remove plugins from Client
1739
- */
1740
- removePlugin: (plugin: PluginInstance) => this;
1741
- triggerPlugins: <Key extends keyof PluginMethods<Client$1>>(key: Key, data: PluginMethodParameters<Key, Client$1>) => this;
1742
- /**
1743
- * Key setters
1744
- */
1745
- setAbortKeyMapper: (callback: (request: RequestInstance) => string) => this;
1746
- setCacheKeyMapper: (callback: (request: RequestInstance) => string) => this;
1747
- setQueryKeyMapper: (callback: (request: RequestInstance) => string) => this;
1748
- setRequestIdMapper: (callback: (request: RequestInstance) => string) => this;
1749
- /**
1750
- * Helper used by http adapter to apply the modifications on response error
1751
- * @private
1752
- */
1753
- unstable_modifyAuth: (request: RequestInstance) => Promise<RequestInstance>;
1754
- /**
1755
- * Private helper to run async pre-request processing
1756
- * @private
1757
- */
1758
- unstable_modifyRequest: (request: RequestInstance) => Promise<RequestInstance>;
1759
- /**
1760
- * Private helper to run async on-error response processing
1761
- * @private
1762
- */
1763
- unstable_modifyErrorResponse: (response: ResponseType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType, AdapterInstance>>;
1764
- /**
1765
- * Private helper to run async on-success response processing
1766
- * @private
1767
- */
1768
- unstable_modifySuccessResponse: (response: ResponseType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType, AdapterInstance>>;
1769
- /**
1770
- * Private helper to run async response processing
1771
- * @private
1772
- */
1773
- unstable_modifyResponse: (response: ResponseType<any, GlobalErrorType, Adapter>, request: RequestInstance) => Promise<ResponseType<any, GlobalErrorType, AdapterInstance>>;
1774
- /**
1775
- * Clears the Client instance and remove all listeners on it's dependencies
1776
- */
1777
- clear: () => void;
1778
- /**
1779
- * Hydrate your SSR cache data
1780
- * @param hydrationData
1781
- * @param options
1782
- */
1783
- hydrate: (hydrationData: (HydrateDataType | EmptyTypes)[], options?: Partial<HydrationOptions> | ((item: HydrateDataType) => Partial<HydrationOptions>)) => void;
1784
- /**
1785
- * Create requests based on the Client setup
1786
- *
1787
- * @template Response Your response
1788
- */
1789
- createRequest: <RequestProperties extends RequestGenericType<ExtractAdapterQueryParamsType<Adapter>> = {}>(
1790
- /**
1791
- * `createRequest` must be initialized twice(currying).
1792
- *
1793
- * ✅ Good:
1794
- * ```ts
1795
- * const request = createRequest<RequestProperties>()(params)
1796
- * ```
1797
- * ⛔ Bad:
1798
- * ```ts
1799
- * const request = createRequest<RequestProperties>(params)
1800
- * ```
1801
- *
1802
- * We are using currying to achieve auto generated types for the endpoint string.
1803
- *
1804
- * This solution will be removed once https://github.com/microsoft/TypeScript/issues/10571 get resolved.
1805
- */
1806
- _USE_DOUBLE_INITIALIZATION?: never) => <EndpointType extends ExtractAdapterEndpointType<Adapter>, AdapterOptions extends ExtractAdapterOptionsType<Adapter>, MethodType extends ExtractAdapterMethodType<Adapter>>(params: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Request<TypeWithDefaults<RequestProperties, "response", undefined>, TypeWithDefaults<RequestProperties, "payload", undefined>, TypeWithDefaults<RequestProperties, "queryParams", ExtractAdapterDefaultQueryParamsType<Adapter>, never>, TypeWithDefaults<RequestProperties, "error", GlobalErrorType>, TypeWithDefaults<RequestProperties, "endpoint", EndpointType> extends string ? TypeWithDefaults<RequestProperties, "endpoint", EndpointType> : any, Client$1<GlobalErrorType, ExtractUnionAdapter<Adapter, {
1807
- method: MethodType;
1808
- options: AdapterOptions;
1809
- queryParams: TypeWithDefaults<RequestProperties, "queryParams", ExtractAdapterDefaultQueryParamsType<Adapter>, never>;
1810
- }> extends EmptyTypes ? Adapter : ExtractUnionAdapter<Adapter, {
1811
- method: MethodType;
1812
- options: AdapterOptions;
1813
- queryParams: TypeWithDefaults<RequestProperties, "queryParams", ExtractAdapterDefaultQueryParamsType<Adapter>, never>;
1814
- }>>, false, false, false>;
1815
- }
1816
-
1817
- type ClientErrorType = Record<string, any> | string;
1818
- type ClientInstanceProperties = {
1819
- error?: any;
1820
- adapter?: AdapterInstance;
1821
- };
1822
- type ClientInstance<ClientProperties extends ClientInstanceProperties = {
1823
- error?: any;
1824
- adapter?: AdapterInstance;
1825
- }> = Client$1<TypeWithDefaults<ClientProperties, "error", any>, TypeWithDefaults<ClientProperties, "adapter", AdapterInstance>>;
1826
- type RequestGenericType<QueryParams> = {
1827
- response?: any;
1828
- payload?: any;
1829
- error?: any;
1830
- queryParams?: QueryParams;
1831
- endpoint?: string;
1832
- params?: Record<string, string | number>;
1833
- };
1834
- /**
1835
- * Configuration setup for the client
1836
- */
1837
- type ClientOptionsType<C extends ClientInstance> = {
1838
- /**
1839
- * Url to your server
1840
- */
1841
- url: string;
1842
- /**
1843
- * Custom cache initialization prop
1844
- */
1845
- cache?: () => C["cache"];
1846
- /**
1847
- * Custom app manager initialization prop
1848
- */
1849
- appManager?: () => C["appManager"];
1850
- /**
1851
- * Custom fetch dispatcher initialization prop
1852
- */
1853
- fetchDispatcher?: () => C["submitDispatcher"];
1854
- /**
1855
- * Custom submit dispatcher initialization prop
1856
- */
1857
- submitDispatcher?: () => C["fetchDispatcher"];
1858
- };
1859
- type RequestInterceptorType = (request: RequestInstance) => Promise<RequestInstance> | RequestInstance;
1860
- type ResponseInterceptorType<Client extends ClientInstance, Response = any, Error = any> = (response: ResponseType<Response, Error, ExtractClientAdapterType<Client>>, request: ExtendRequest<RequestInstance, {
1861
- client: Client;
1862
- }>) => Promise<ResponseType<any, any, ExtractClientAdapterType<Client>>> | ResponseType<any, any, ExtractClientAdapterType<Client>>;
1863
- type ModifyQueryParamsCallbackType<QueryParams, ModifiedQueryParams> = (queryParams: QueryParams) => ModifiedQueryParams;
1864
-
1865
- declare const interceptRequest: (interceptors: RequestInterceptorType[], request: RequestInstance) => Promise<RequestInstance>;
1866
- declare const interceptResponse: <GlobalErrorType, Client extends ClientInstance>(interceptors: ResponseInterceptorType<Client>[], response: ResponseType<any, GlobalErrorType, ExtractClientAdapterType<Client>>, request: ExtendRequest<RequestInstance, {
1867
- client: Client;
1868
- }>) => Promise<ResponseType<any, GlobalErrorType, ExtractClientAdapterType<Client>>>;
1869
-
1870
- declare const stringifyDefaultOptions: {
1871
- readonly strict: true;
1872
- readonly encode: true;
1873
- readonly arrayFormat: "bracket";
1874
- readonly arraySeparator: "bracket";
1875
- readonly sort: false;
1876
- readonly skipNull: true;
1877
- readonly skipEmptyString: true;
1878
- };
1879
-
1880
- type ClientGenericType = {
1881
- error?: ClientErrorType;
1882
- };
1883
- declare function createClient<ClientProperties extends ClientGenericType = {}>(options: ClientOptionsType<Client$1<NonNullable<TypeWithDefaults<ClientProperties, "error", Error>>>>): Client$1<NonNullable<TypeWithDefaults<ClientProperties, "error", Error>>, HttpAdapterType>;
1884
-
1885
- declare class Plugin<Client extends ClientInstance = ClientInstance, PluginData = void> {
1886
- config: PluginOptionsType<PluginData>;
1887
- name: string;
1888
- data: PluginData;
1889
- client: Client | undefined;
1890
- private pluginMethods;
1891
- constructor(config: PluginOptionsType<PluginData>);
1892
- initialize: (client: Client) => this;
1893
- trigger: <Key extends keyof PluginMethods<Client>>(method: Key, data: PluginMethodParameters<Key, Client>) => void;
1894
- /**
1895
- * Callback that will be executed when plugin is mounted
1896
- */
1897
- onMount: (callback: PluginMethods<Client>["onMount"]) => this;
1898
- /**
1899
- * Callback that will be executed when plugin is unmounted
1900
- */
1901
- onUnmount: (callback: PluginMethods<Client>["onUnmount"]) => this;
1902
- /**
1903
- * Callback that will be executed when request is created
1904
- */
1905
- onRequestCreate: (callback: PluginMethods<Client>["onRequestCreate"]) => this;
1906
- /**
1907
- * Callback that will be executed when request gets triggered
1908
- */
1909
- onRequestTrigger: (callback: PluginMethods<Client>["onRequestTrigger"]) => this;
1910
- /**
1911
- * Callback that will be executed when request starts
1912
- */
1913
- onRequestStart: (callback: PluginMethods<Client>["onRequestStart"]) => this;
1914
- /**
1915
- * Callback that will be executed when response is successful
1916
- */
1917
- onRequestSuccess: (callback: PluginMethods<Client>["onRequestSuccess"]) => this;
1918
- /**
1919
- * Callback that will be executed when response is failed
1920
- */
1921
- onRequestError: (callback: PluginMethods<Client>["onRequestError"]) => this;
1922
- /**
1923
- * Callback that will be executed when response is finished
1924
- */
1925
- onRequestFinished: (callback: PluginMethods<Client>["onRequestFinished"]) => this;
1926
- onDispatcherCleared: (callback: PluginMethods<Client>["onDispatcherCleared"]) => this;
1927
- onDispatcherQueueDrained: (callback: PluginMethods<Client>["onDispatcherQueueDrained"]) => this;
1928
- onDispatcherQueueRunning: (callback: PluginMethods<Client>["onDispatcherQueueRunning"]) => this;
1929
- onDispatcherItemAdded: (callback: PluginMethods<Client>["onDispatcherItemAdded"]) => this;
1930
- onDispatcherItemDeleted: (callback: PluginMethods<Client>["onDispatcherItemDeleted"]) => this;
1931
- onDispatcherQueueCreated: (callback: PluginMethods<Client>["onDispatcherQueueCreated"]) => this;
1932
- onDispatcherQueueCleared: (callback: PluginMethods<Client>["onDispatcherQueueCleared"]) => this;
1933
- onCacheItemChange: (callback: PluginMethods<Client>["onCacheItemChange"]) => this;
1934
- onCacheItemDelete: (callback: PluginMethods<Client>["onCacheItemDelete"]) => this;
1935
- onAdapterFetch: (callback: PluginMethods<Client>["onAdapterFetch"]) => this;
1936
- }
1937
-
1938
- type PluginLifecycle = "trigger" | "start" | "success" | "error" | "finished";
1939
- type PluginInstance = Plugin<any, any>;
1940
- type PluginRequest<C extends ClientInstance> = ExtendRequest<RequestInstance, {
1941
- client: C;
1942
- }>;
1943
- type PluginOptionsType<PluginData> = {
1944
- /**
1945
- * Name of the plugin
1946
- */
1947
- name: string;
1948
- /**
1949
- * Data stored in a plugin
1950
- */
1951
- data?: PluginData;
1952
- };
1953
- type PluginMethods<Client extends ClientInstance> = {
1954
- onMount?: (data: {
1955
- client: Client;
1956
- }) => void;
1957
- onUnmount?: (data: {
1958
- client: Client;
1959
- }) => void;
1960
- onRequestCreate?: (data: {
1961
- request: PluginRequest<Client>;
1962
- }) => void;
1963
- onRequestTrigger?: (data: {
1964
- request: PluginRequest<Client>;
1965
- }) => void;
1966
- onRequestStart?: (data: {
1967
- request: PluginRequest<Client>;
1968
- }) => void;
1969
- onRequestSuccess?: (data: {
1970
- response: ResponseSuccessType<ExtractResponseType<PluginRequest<Client>>, ExtractAdapterType<PluginRequest<Client>>>;
1971
- request: PluginRequest<Client>;
1972
- }) => void;
1973
- onRequestError?: (data: {
1974
- response: ResponseErrorType<ExtractErrorType<PluginRequest<Client>>, ExtractAdapterType<PluginRequest<Client>>>;
1975
- request: PluginRequest<Client>;
1976
- }) => void;
1977
- onRequestFinished?: (data: {
1978
- response: ResponseType<ExtractResponseType<PluginRequest<Client>>, ExtractErrorType<PluginRequest<Client>>, ExtractAdapterType<PluginRequest<Client>>>;
1979
- request: PluginRequest<Client>;
1980
- }) => void;
1981
- onCacheItemChange?: <Requests extends {
1982
- cacheKey: string;
1983
- response: any;
1984
- error: any;
1985
- }>(data: {
1986
- cache: Cache<ExtractClientAdapterType<Client>>;
1987
- cacheKey: Requests["cacheKey"];
1988
- prevData: CacheValueType<Requests["response"], Requests["error"], ExtractClientAdapterType<Client>> | null;
1989
- newData: CacheValueType<Requests["response"], Requests["error"], ExtractClientAdapterType<Client>>;
1990
- }) => void;
1991
- onCacheItemDelete?: (data: {
1992
- cacheKey: string;
1993
- cache: Cache<ExtractClientAdapterType<Client>>;
1994
- }) => void;
1995
- onCacheItemInvalidate?: (data: {
1996
- cacheKey: string;
1997
- cache: Cache<ExtractClientAdapterType<Client>>;
1998
- }) => void;
1999
- onDispatcherCleared?: (data: {
2000
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2001
- }) => void;
2002
- onDispatcherQueueDrained?: (data: {
2003
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2004
- queue: QueueDataType<ExtendRequest<RequestInstance, {
2005
- client: Client;
2006
- }>>;
2007
- }) => void;
2008
- onDispatcherItemAdded?: (data: {
2009
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2010
- queue: QueueDataType<ExtendRequest<RequestInstance, {
2011
- client: Client;
2012
- }>>;
2013
- queueItem: QueueItemType<ExtendRequest<RequestInstance, {
2014
- client: Client;
2015
- }>>;
2016
- }) => void;
2017
- onDispatcherItemDeleted?: (data: {
2018
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2019
- queue: QueueDataType<ExtendRequest<RequestInstance, {
2020
- client: Client;
2021
- }>>;
2022
- queueItem: QueueItemType<ExtendRequest<RequestInstance, {
2023
- client: Client;
2024
- }>>;
2025
- }) => void;
2026
- onDispatcherQueueRunning?: (data: {
2027
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2028
- queue: QueueDataType<ExtendRequest<RequestInstance, {
2029
- client: Client;
2030
- }>>;
2031
- status: "paused" | "stopped" | "running";
2032
- }) => void;
2033
- onDispatcherQueueCreated?: (data: {
2034
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2035
- queue: QueueDataType<ExtendRequest<RequestInstance, {
2036
- client: Client;
2037
- }>>;
2038
- }) => void;
2039
- onDispatcherQueueCleared?: (data: {
2040
- dispatcher: Dispatcher<ExtractClientAdapterType<Client>>;
2041
- queue: QueueDataType<ExtendRequest<RequestInstance, {
2042
- client: Client;
2043
- }>>;
2044
- }) => void;
2045
- onAdapterFetch?: (data: {
2046
- request: RequestInstance;
2047
- requestId: string;
2048
- adapter: AdapterInstance;
2049
- }) => void;
2050
- };
2051
- type PluginMethodParameters<Key extends keyof PluginMethods<Client>, Client extends ClientInstance> = Parameters<NonNullable<PluginMethods<Client>[Key]>>[0];
2052
-
2053
- type RecursiveSchemaType = Record<string, // for example users / $userId / posts / $postId
2054
- any>;
2055
- type CreateSdkOptions = {
2056
- /** @default true */
2057
- camelCaseToKebabCase?: boolean;
2058
- /** @default (method) => method.toUpperCase() */
2059
- methodTransform?: (method: string) => string;
2060
- };
2061
- declare const createSdk: <Client extends ClientInstance, RecursiveSchema extends RecursiveSchemaType>(client: Client, options?: CreateSdkOptions) => RecursiveSchema;
2062
-
2063
- declare enum Time {
2064
- SEC = 1000,
2065
- MIN = 60000,
2066
- HOUR = 3600000,
2067
- DAY = 86400000,
2068
- WEEK = 604800000,
2069
- MONTH_30 = 2592000000,
2070
- MONTH_31 = 2678400000,
2071
- YEAR = 31536000000,
2072
- YEAR_LEAP = 31622400000
2073
- }
2074
-
2075
- declare enum HttpMethods {
2076
- GET = "GET",
2077
- POST = "POST",
2078
- PUT = "PUT",
2079
- PATCH = "PATCH",
2080
- DELETE = "DELETE"
2081
- }
2082
-
2083
- export { AbortError, Adapter, type AdapterFetcherType, type AdapterGenericType, type AdapterInstance, type AdapterPayloadMappingType, AppEvents, AppManager, type AppManagerOptionsType, type BufferEncoding, Cache, type CacheAsyncStorageType, type CacheInitialData, type CacheOptionsType, type CacheSetState, type CacheStorageType, type CacheValueType, Client$1 as Client, type ClientErrorType, type ClientGenericType, type ClientInstance, type ClientInstanceProperties, type ClientOptionsType, type CreateSdkOptions, type DeclareAdapterType, type DefaultEndpointMapper, type DefaultHeaderMapper, type DefaultMapperType, type DefaultPayloadMapper, type DefaultQueryParamsMapper, DeletedError, Dispatcher, DispatcherMode, type DispatcherOptionsType, type DispatcherStorageType, type EmptyTypes, type EndpointMapper, EventEmitter, type ExtendRequest, type ExtractAdapterDefaultQueryParamsType, type ExtractAdapterEndpointMapperType, type ExtractAdapterEndpointType, type ExtractAdapterExtraType, type ExtractAdapterHeaderMapperType, type ExtractAdapterMethodType, type ExtractAdapterOptionsType, type ExtractAdapterPayloadMapperType, type ExtractAdapterQueryParamsMapperType, type ExtractAdapterQueryParamsType, type ExtractAdapterResolvedType, type ExtractAdapterStatusType, type ExtractAdapterType, type ExtractClientAdapterType, type ExtractClientGlobalError, type ExtractClientType, type ExtractEndpointType, type ExtractErrorType, type ExtractGlobalErrorType, type ExtractHasParamsType, type ExtractHasPayloadType, type ExtractHasQueryParamsType, type ExtractLocalErrorType, type ExtractParamsType, type ExtractPayloadType, type ExtractQueryParamsType, type ExtractResponseType, type ExtractUnionAdapter, type ExtractUrlParams, type FetchParamsType, type FetchPayloadType, type FetchQueryParamsType, type HeaderMappingType, HttpAdapter, type HttpAdapterExtraType, type HttpAdapterHeadersProps, type HttpAdapterOptionsType, type HttpAdapterRequest, type HttpAdapterType, HttpMethods, type HttpMethodsType, type HttpStatusType, type HydrateDataType, type HydrationOptions, type LogData, type LogDataTypes, type LogLevel, type LogRequestEventType, type LogResponseEventType, type LogSystemEventType, type LoggerArgs, LoggerManager, type LoggerMethods, type LoggerOptionsType, type LoggerType, type MockResponseType, type MockerConfigType, type ModifyQueryParamsCallbackType, type NonNullableKeys, type NullableKeys, type NullableType, type ParamType, type ParamsType, type PayloadMapperType, type PayloadType, Plugin, type PluginInstance, type PluginLifecycle, type PluginMethodParameters, type PluginMethods, type PluginOptionsType, type PluginRequest, type Prettify, type ProgressDataType, type ProgressEventType, type ProgressType, type QueryParamType, type QueryParamValuesType, type QueryParamsMapper, type QueryParamsType, type QueryStringifyOptionsType, type QueueDataType, type QueueItemType, type RecursiveSchemaType, Request, type RequestCacheType, type RequestConfigurationType, type RequestDeduplicatedEventType, type RequestDynamicSendOptionsType, type RequestEventType, type RequestGenericType, type RequestInstance, type RequestInstanceProperties, type RequestInterceptorType, type RequestJSON, type RequestLoadingEventType, RequestManager, type RequestMapper, type RequestOptionsType, RequestProcessingError, type RequestProgressEventType, type RequestRemovedEventType, type RequestResponseEventType, type RequestResponseType, type RequestSendActionsType, type RequestSendOptionsType, type RequestSendType, type RequiredKeys, type ResponseDetailsType, type ResponseErrorType, type ResponseInterceptorType, type ResponseMapper, type ResponseSuccessType, type ResponseType, type RunningRequestValueType, type SyncOrAsync, Time, TimeoutError, type TypeWithDefaults, UnexpectedError, appManagerInitialOptions, canRetryRequest, createClient, createSdk, defaultMapper, defaultTimeout, getAbortByAbortKey, getAbortByIdKey, getAbortKey, getAdapterBindings, getAdapterHeaders, getAdapterOnError, getAdapterPayload, getAppManagerEvents, getCacheByKey, getCacheData, getCacheEvents, getCacheKey, getDeleteByKey, getDeleteKey, getDispatcherChangeByKey, getDispatcherChangeKey, getDispatcherDrainedByKey, getDispatcherDrainedKey, getDispatcherEvents, getDispatcherStatusByKey, getDispatcherStatusKey, getDownloadProgressByIdKey, getDownloadProgressByQueryKey, getDownloadProgressKey, getErrorMessage, getInvalidateByKey, getInvalidateKey, getIsEqualTimestamp, getLoadingByCacheKey, getLoadingByIdKey, getLoadingByQueryKey, getLoadingKey, getProgressData, getProgressValue, getRemoveByIdKey, getRemoveByQueryKey, getRemoveKey, getRequestDeduplicatedByCacheKey, getRequestDeduplicatedByIdKey, getRequestDeduplicatedByQueryKey, getRequestDeduplicatedKey, getRequestDispatcher, getRequestEta, getRequestKey, getRequestManagerEvents, getRequestStarByQueryKey, getRequestStartByIdKey, getRequestStartKey, getRequestType, getResponseByCacheKey, getResponseByIdKey, getResponseHeaders, getResponseKey, getResponseStartByIdKey, getResponseStartByQueryKey, getResponseStartKey, getSimpleKey, getTime, getUniqueRequestId, getUploadProgressByIdKey, getUploadProgressByQueryKey, getUploadProgressKey, handleResponse, hasDocument, hasWindow, interceptRequest, interceptResponse, logLevelOrder, logger, loggerColors, loggerStyles, mocker, onDocumentEvent, onWindowEvent, parseErrorResponse, parseResponse, sendRequest, stringifyDefaultOptions, stringifyKey, stringifyQueryParams, stringifyValue, xhrExtra };
1
+ export * from './plugin';
2
+ export * from './client';
3
+ export * from './cache';
4
+ export * from './adapter';
5
+ export * from './sdk';
6
+ export * from './http-adapter';
7
+ export * from './request';
8
+ export * from './constants/time.constants';
9
+ export * from './constants/http.constants';
10
+ export * from './managers';
11
+ export * from './dispatcher';
12
+ export * from './mocker';
13
+ export * from './types';
14
+ export * from './utils';
15
+ //# sourceMappingURL=index.d.ts.map