@hyper-fetch/core 7.5.3 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/.eslintrc.cjs +12 -0
  2. package/__tests__/e2e/e2e.abort-timeout.spec.ts +101 -0
  3. package/__tests__/e2e/e2e.advanced.spec.ts +423 -0
  4. package/__tests__/e2e/e2e.methods.spec.ts +243 -0
  5. package/__tests__/e2e/e2e.payloads.spec.ts +154 -0
  6. package/__tests__/features/adapter/adapter.base.spec.ts +44 -17
  7. package/__tests__/features/adapter/adapter.bindings.spec.ts +35 -33
  8. package/__tests__/features/adapter/adapter.browser.spec.ts +5 -20
  9. package/__tests__/features/adapter/adapter.server.spec.ts +229 -37
  10. package/__tests__/features/cache/cache.base.spec.ts +23 -15
  11. package/__tests__/features/cache/cache.events.spec.ts +9 -5
  12. package/__tests__/features/cache/cache.garbage-collector.spec.ts +9 -6
  13. package/__tests__/features/cache/cache.lazy-storage.spec.ts +11 -8
  14. package/__tests__/features/cache/cache.modes.spec.ts +145 -0
  15. package/__tests__/features/cache/cache.scoping.spec.ts +171 -0
  16. package/__tests__/features/cache/cache.typescript.spec.ts +147 -0
  17. package/__tests__/features/cache/cache.utils.spec.ts +10 -3
  18. package/__tests__/features/client/client.auth.spec.ts +5 -5
  19. package/__tests__/features/client/client.base.spec.ts +16 -4
  20. package/__tests__/features/client/client.from-json.spec.ts +182 -0
  21. package/__tests__/features/client/client.hydration.spec.ts +69 -4
  22. package/__tests__/features/client/client.interceptor.spec.ts +4 -4
  23. package/__tests__/features/client/client.methods.spec.ts +5 -4
  24. package/__tests__/features/client/client.middleware.spec.ts +4 -4
  25. package/__tests__/features/client/client.utils.spec.ts +3 -3
  26. package/__tests__/features/dispatcher/dispatcher.base.spec.ts +8 -8
  27. package/__tests__/features/dispatcher/dispatcher.custom-storage.spec.ts +189 -0
  28. package/__tests__/features/dispatcher/dispatcher.events.spec.ts +17 -12
  29. package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +31 -31
  30. package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +15 -15
  31. package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +22 -5
  32. package/__tests__/features/managers/app/app.manager.base.spec.ts +23 -23
  33. package/__tests__/features/managers/app/app.manager.ssr.spec.ts +6 -3
  34. package/__tests__/features/managers/logger/logger.base.spec.ts +4 -2
  35. package/__tests__/features/managers/logger/logger.utils.spec.ts +10 -4
  36. package/__tests__/features/managers/request/request.manager.base.spec.ts +21 -19
  37. package/__tests__/features/managers/request/request.manager.events.spec.ts +137 -53
  38. package/__tests__/features/mocker/mocker.base.spec.ts +82 -10
  39. package/__tests__/features/plugin/plugin.base.spec.ts +19 -19
  40. package/__tests__/features/request/request.base.spec.ts +39 -13
  41. package/__tests__/features/request/request.cloning.spec.ts +1 -1
  42. package/__tests__/features/request/request.hooks.spec.ts +173 -0
  43. package/__tests__/features/request/request.optimistic.spec.ts +93 -0
  44. package/__tests__/features/request/request.retry-on-error.spec.ts +359 -0
  45. package/__tests__/features/request/request.sending.spec.ts +107 -15
  46. package/__tests__/features/request/request.setters.spec.ts +11 -4
  47. package/__tests__/features/request/request.typescript.spec.ts +1 -1
  48. package/__tests__/features/request/request.utils.spec.ts +2 -2
  49. package/__tests__/features/sdk/sdk.base.spec.ts +5 -3
  50. package/__tests__/features/sdk/sdk.configuration.spec.ts +262 -0
  51. package/__tests__/features/utils/emitter.utils.spec.ts +88 -0
  52. package/__tests__/shared/callbacks.shared.ts +3 -1
  53. package/__tests__/shared/progress.shared.ts +2 -1
  54. package/__tests__/tsconfig.json +14 -3
  55. package/__tests__/type-stress/generate-stress-test.ts +92 -0
  56. package/__tests__/type-stress/stress-10.ts +35 -0
  57. package/__tests__/type-stress/stress-just-create.ts +2107 -0
  58. package/__tests__/type-stress/stress-minimal.ts +23 -0
  59. package/__tests__/type-stress/stress-test-500.ts +2319 -0
  60. package/__tests__/type-stress/stress-test-sdk.ts +210 -0
  61. package/__tests__/type-stress/tsconfig.json +6 -0
  62. package/__tests__/utils/adapter.utils.ts +3 -2
  63. package/__tests__/utils/cache.utils.ts +3 -2
  64. package/__tests__/utils/callbacks.utils.ts +5 -4
  65. package/__tests__/utils/dispatcher.utils.ts +3 -2
  66. package/__tests__/vitest.setup.ts +15 -0
  67. package/dist/adapter/adapter.bindings.d.ts +71 -0
  68. package/dist/adapter/adapter.bindings.d.ts.map +1 -0
  69. package/dist/adapter/adapter.d.ts +127 -0
  70. package/dist/adapter/adapter.d.ts.map +1 -0
  71. package/dist/adapter/adapter.types.d.ts +108 -0
  72. package/dist/adapter/adapter.types.d.ts.map +1 -0
  73. package/dist/adapter/adapter.utils.d.ts +23 -0
  74. package/dist/adapter/adapter.utils.d.ts.map +1 -0
  75. package/dist/adapter/index.d.ts +5 -0
  76. package/dist/adapter/index.d.ts.map +1 -0
  77. package/dist/cache/cache.d.ts +95 -0
  78. package/dist/cache/cache.d.ts.map +1 -0
  79. package/dist/cache/cache.events.d.ts +51 -0
  80. package/dist/cache/cache.events.d.ts.map +1 -0
  81. package/dist/cache/cache.types.d.ts +44 -0
  82. package/dist/cache/cache.types.d.ts.map +1 -0
  83. package/dist/cache/cache.utils.d.ts +11 -0
  84. package/dist/cache/cache.utils.d.ts.map +1 -0
  85. package/dist/cache/index.d.ts +5 -0
  86. package/dist/cache/index.d.ts.map +1 -0
  87. package/dist/client/client.constants.d.ts +10 -0
  88. package/dist/client/client.constants.d.ts.map +1 -0
  89. package/dist/client/client.create.d.ts +8 -0
  90. package/dist/client/client.create.d.ts.map +1 -0
  91. package/dist/client/client.d.ts +195 -0
  92. package/dist/client/client.d.ts.map +1 -0
  93. package/dist/client/client.types.d.ts +71 -0
  94. package/dist/client/client.types.d.ts.map +1 -0
  95. package/dist/client/client.utils.d.ts +11 -0
  96. package/dist/client/client.utils.d.ts.map +1 -0
  97. package/dist/client/index.d.ts +6 -0
  98. package/dist/client/index.d.ts.map +1 -0
  99. package/dist/constants/http.constants.d.ts +8 -0
  100. package/dist/constants/http.constants.d.ts.map +1 -0
  101. package/dist/constants/time.constants.d.ts +12 -0
  102. package/dist/constants/time.constants.d.ts.map +1 -0
  103. package/dist/dispatcher/dispatcher.constants.d.ts +7 -0
  104. package/dist/dispatcher/dispatcher.constants.d.ts.map +1 -0
  105. package/dist/dispatcher/dispatcher.d.ts +168 -0
  106. package/dist/dispatcher/dispatcher.d.ts.map +1 -0
  107. package/dist/dispatcher/dispatcher.events.d.ts +49 -0
  108. package/dist/dispatcher/dispatcher.events.d.ts.map +1 -0
  109. package/dist/dispatcher/dispatcher.types.d.ts +44 -0
  110. package/dist/dispatcher/dispatcher.types.d.ts.map +1 -0
  111. package/dist/dispatcher/dispatcher.utils.d.ts +12 -0
  112. package/dist/dispatcher/dispatcher.utils.d.ts.map +1 -0
  113. package/dist/dispatcher/index.d.ts +6 -0
  114. package/dist/dispatcher/index.d.ts.map +1 -0
  115. package/dist/http-adapter/http-adapter.constants.d.ts +4 -0
  116. package/dist/http-adapter/http-adapter.constants.d.ts.map +1 -0
  117. package/dist/http-adapter/http-adapter.d.ts +3 -0
  118. package/dist/http-adapter/http-adapter.d.ts.map +1 -0
  119. package/dist/http-adapter/http-adapter.fetch.d.ts +6 -0
  120. package/dist/http-adapter/http-adapter.fetch.d.ts.map +1 -0
  121. package/dist/http-adapter/http-adapter.types.d.ts +73 -0
  122. package/dist/http-adapter/http-adapter.types.d.ts.map +1 -0
  123. package/dist/http-adapter/http-adapter.utils.d.ts +10 -0
  124. package/dist/http-adapter/http-adapter.utils.d.ts.map +1 -0
  125. package/dist/http-adapter/index.d.ts +6 -0
  126. package/dist/http-adapter/index.d.ts.map +1 -0
  127. package/dist/index.d.ts +15 -2083
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.mjs +4084 -0
  130. package/dist/index.mjs.map +1 -0
  131. package/dist/managers/app/app.manager.constants.d.ts +10 -0
  132. package/dist/managers/app/app.manager.constants.d.ts.map +1 -0
  133. package/dist/managers/app/app.manager.d.ts +35 -0
  134. package/dist/managers/app/app.manager.d.ts.map +1 -0
  135. package/dist/managers/app/app.manager.events.d.ts +12 -0
  136. package/dist/managers/app/app.manager.events.d.ts.map +1 -0
  137. package/dist/managers/app/app.manager.types.d.ts +7 -0
  138. package/dist/managers/app/app.manager.types.d.ts.map +1 -0
  139. package/dist/managers/app/app.manager.utils.d.ts +5 -0
  140. package/dist/managers/app/app.manager.utils.d.ts.map +1 -0
  141. package/dist/managers/app/index.d.ts +6 -0
  142. package/dist/managers/app/index.d.ts.map +1 -0
  143. package/dist/managers/index.d.ts +4 -0
  144. package/dist/managers/index.d.ts.map +1 -0
  145. package/dist/managers/logger/index.d.ts +5 -0
  146. package/dist/managers/logger/index.d.ts.map +1 -0
  147. package/dist/managers/logger/logger.manager.constants.d.ts +5 -0
  148. package/dist/managers/logger/logger.manager.constants.d.ts.map +1 -0
  149. package/dist/managers/logger/logger.manager.d.ts +22 -0
  150. package/dist/managers/logger/logger.manager.d.ts.map +1 -0
  151. package/dist/managers/logger/logger.manager.types.d.ts +43 -0
  152. package/dist/managers/logger/logger.manager.types.d.ts.map +1 -0
  153. package/dist/managers/logger/logger.manager.utils.d.ts +4 -0
  154. package/dist/managers/logger/logger.manager.utils.d.ts.map +1 -0
  155. package/dist/managers/request/index.d.ts +5 -0
  156. package/dist/managers/request/index.d.ts.map +1 -0
  157. package/dist/managers/request/request.manager.d.ts +60 -0
  158. package/dist/managers/request/request.manager.d.ts.map +1 -0
  159. package/dist/managers/request/request.manager.events.d.ts +55 -0
  160. package/dist/managers/request/request.manager.events.d.ts.map +1 -0
  161. package/dist/managers/request/request.manager.types.d.ts +48 -0
  162. package/dist/managers/request/request.manager.types.d.ts.map +1 -0
  163. package/dist/managers/request/request.manager.utils.d.ts +30 -0
  164. package/dist/managers/request/request.manager.utils.d.ts.map +1 -0
  165. package/dist/mocker/index.d.ts +3 -0
  166. package/dist/mocker/index.d.ts.map +1 -0
  167. package/dist/mocker/mocker.d.ts +3 -0
  168. package/dist/mocker/mocker.d.ts.map +1 -0
  169. package/dist/mocker/mocker.types.d.ts +25 -0
  170. package/dist/mocker/mocker.types.d.ts.map +1 -0
  171. package/dist/plugin/index.d.ts +3 -0
  172. package/dist/plugin/index.d.ts.map +1 -0
  173. package/dist/plugin/plugin.d.ts +55 -0
  174. package/dist/plugin/plugin.d.ts.map +1 -0
  175. package/dist/plugin/plugin.types.d.ts +122 -0
  176. package/dist/plugin/plugin.types.d.ts.map +1 -0
  177. package/dist/request/index.d.ts +5 -0
  178. package/dist/request/index.d.ts.map +1 -0
  179. package/dist/request/request.d.ts +195 -0
  180. package/dist/request/request.d.ts.map +1 -0
  181. package/dist/request/request.hooks.d.ts +19 -0
  182. package/dist/request/request.hooks.d.ts.map +1 -0
  183. package/dist/request/request.types.d.ts +240 -0
  184. package/dist/request/request.types.d.ts.map +1 -0
  185. package/dist/request/request.utils.d.ts +25 -0
  186. package/dist/request/request.utils.d.ts.map +1 -0
  187. package/dist/sdk/index.d.ts +2 -0
  188. package/dist/sdk/index.d.ts.map +1 -0
  189. package/dist/sdk/sdk.d.ts +69 -0
  190. package/dist/sdk/sdk.d.ts.map +1 -0
  191. package/dist/types/adapter.types.d.ts +22 -0
  192. package/dist/types/adapter.types.d.ts.map +1 -0
  193. package/dist/types/client.types.d.ts +4 -0
  194. package/dist/types/client.types.d.ts.map +1 -0
  195. package/dist/types/helpers.types.d.ts +17 -0
  196. package/dist/types/helpers.types.d.ts.map +1 -0
  197. package/dist/types/http.types.d.ts +3 -0
  198. package/dist/types/http.types.d.ts.map +1 -0
  199. package/dist/types/hydration.types.d.ts +15 -0
  200. package/dist/types/hydration.types.d.ts.map +1 -0
  201. package/dist/types/index.d.ts +7 -0
  202. package/dist/types/index.d.ts.map +1 -0
  203. package/dist/types/request.types.d.ts +34 -0
  204. package/dist/types/request.types.d.ts.map +1 -0
  205. package/dist/utils/emitter.utils.d.ts +13 -0
  206. package/dist/utils/emitter.utils.d.ts.map +1 -0
  207. package/dist/utils/index.d.ts +3 -0
  208. package/dist/utils/index.d.ts.map +1 -0
  209. package/dist/utils/uuid.utils.d.ts +3 -0
  210. package/dist/utils/uuid.utils.d.ts.map +1 -0
  211. package/package.json +10 -25
  212. package/src/adapter/adapter.bindings.ts +8 -12
  213. package/src/adapter/adapter.ts +8 -7
  214. package/src/adapter/adapter.types.ts +10 -6
  215. package/src/adapter/adapter.utils.ts +1 -1
  216. package/src/cache/cache.events.ts +4 -11
  217. package/src/cache/cache.ts +28 -22
  218. package/src/cache/cache.types.ts +8 -4
  219. package/src/cache/cache.utils.ts +3 -3
  220. package/src/client/client.create.ts +4 -3
  221. package/src/client/client.ts +44 -12
  222. package/src/client/client.types.ts +25 -3
  223. package/src/client/client.utils.ts +24 -4
  224. package/src/dispatcher/dispatcher.events.ts +3 -3
  225. package/src/dispatcher/dispatcher.ts +59 -28
  226. package/src/dispatcher/dispatcher.types.ts +19 -2
  227. package/src/dispatcher/dispatcher.utils.ts +5 -4
  228. package/src/http-adapter/http-adapter.constants.ts +1 -1
  229. package/src/http-adapter/http-adapter.fetch.ts +174 -0
  230. package/src/http-adapter/http-adapter.ts +3 -8
  231. package/src/http-adapter/http-adapter.types.ts +17 -9
  232. package/src/http-adapter/http-adapter.utils.ts +6 -9
  233. package/src/http-adapter/index.ts +1 -0
  234. package/src/managers/app/app.manager.constants.ts +2 -2
  235. package/src/managers/app/app.manager.events.ts +1 -1
  236. package/src/managers/app/app.manager.ts +2 -1
  237. package/src/managers/logger/logger.manager.constants.ts +1 -1
  238. package/src/managers/logger/logger.manager.ts +2 -1
  239. package/src/managers/logger/logger.manager.types.ts +2 -2
  240. package/src/managers/logger/logger.manager.utils.ts +2 -1
  241. package/src/managers/request/request.manager.events.ts +13 -11
  242. package/src/managers/request/request.manager.types.ts +6 -3
  243. package/src/mocker/mocker.ts +3 -2
  244. package/src/mocker/mocker.types.ts +1 -1
  245. package/src/plugin/plugin.ts +2 -2
  246. package/src/plugin/plugin.types.ts +9 -9
  247. package/src/request/index.ts +1 -0
  248. package/src/request/request.hooks.ts +87 -0
  249. package/src/request/request.ts +155 -77
  250. package/src/request/request.types.ts +54 -22
  251. package/src/request/request.utils.ts +86 -23
  252. package/src/sdk/sdk.ts +153 -8
  253. package/src/types/adapter.types.ts +1 -1
  254. package/src/types/client.types.ts +1 -1
  255. package/src/types/hydration.types.ts +3 -3
  256. package/src/types/request.types.ts +30 -20
  257. package/src/utils/uuid.utils.ts +1 -1
  258. package/tsconfig.base.json +1 -6
  259. package/tsconfig.json +1 -4
  260. package/vite.config.ts +45 -0
  261. package/.eslintrc.json +0 -11
  262. package/__tests__/global.d.ts +0 -1
  263. package/__tests__/jest.setup.ts +0 -13
  264. package/dist/browser/index.js +0 -3751
  265. package/dist/browser/index.js.map +0 -7
  266. package/dist/index.js +0 -4002
  267. package/dist/index.js.map +0 -7
  268. package/jest.config.ts +0 -6
  269. package/src/http-adapter/http-adapter.browser.ts +0 -102
  270. package/src/http-adapter/http-adapter.server.ts +0 -149
@@ -1,3751 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
33
- var __async = (__this, __arguments, generator) => {
34
- return new Promise((resolve, reject) => {
35
- var fulfilled = (value) => {
36
- try {
37
- step(generator.next(value));
38
- } catch (e) {
39
- reject(e);
40
- }
41
- };
42
- var rejected = (value) => {
43
- try {
44
- step(generator.throw(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
50
- step((generator = generator.apply(__this, __arguments)).next());
51
- });
52
- };
53
-
54
- // src/plugin/plugin.ts
55
- var Plugin = class {
56
- constructor(config) {
57
- this.config = config;
58
- __publicField(this, "name");
59
- __publicField(this, "data");
60
- __publicField(this, "client");
61
- __publicField(this, "pluginMethods", {});
62
- __publicField(this, "initialize", (client) => {
63
- this.client = client;
64
- return this;
65
- });
66
- __publicField(this, "trigger", (method, data) => {
67
- const callback = this.pluginMethods[method];
68
- if (callback) {
69
- callback(data);
70
- }
71
- });
72
- /* -------------------------------------------------------------------------------------------------
73
- * Plugin lifecycle
74
- * -----------------------------------------------------------------------------------------------*/
75
- /**
76
- * Callback that will be executed when plugin is mounted
77
- */
78
- __publicField(this, "onMount", (callback) => {
79
- this.pluginMethods.onMount = callback;
80
- return this;
81
- });
82
- /**
83
- * Callback that will be executed when plugin is unmounted
84
- */
85
- __publicField(this, "onUnmount", (callback) => {
86
- this.pluginMethods.onUnmount = callback;
87
- return this;
88
- });
89
- /* -------------------------------------------------------------------------------------------------
90
- * Request lifecycle
91
- * -----------------------------------------------------------------------------------------------*/
92
- /**
93
- * Callback that will be executed when request is created
94
- */
95
- __publicField(this, "onRequestCreate", (callback) => {
96
- this.pluginMethods.onRequestCreate = callback;
97
- return this;
98
- });
99
- /**
100
- * Callback that will be executed when request gets triggered
101
- */
102
- __publicField(this, "onRequestTrigger", (callback) => {
103
- this.pluginMethods.onRequestTrigger = callback;
104
- return this;
105
- });
106
- /**
107
- * Callback that will be executed when request starts
108
- */
109
- __publicField(this, "onRequestStart", (callback) => {
110
- this.pluginMethods.onRequestStart = callback;
111
- return this;
112
- });
113
- /**
114
- * Callback that will be executed when response is successful
115
- */
116
- __publicField(this, "onRequestSuccess", (callback) => {
117
- this.pluginMethods.onRequestSuccess = callback;
118
- return this;
119
- });
120
- /**
121
- * Callback that will be executed when response is failed
122
- */
123
- __publicField(this, "onRequestError", (callback) => {
124
- this.pluginMethods.onRequestError = callback;
125
- return this;
126
- });
127
- /**
128
- * Callback that will be executed when response is finished
129
- */
130
- __publicField(this, "onRequestFinished", (callback) => {
131
- this.pluginMethods.onRequestFinished = callback;
132
- return this;
133
- });
134
- /* -------------------------------------------------------------------------------------------------
135
- * Dispatcher lifecycle
136
- * -----------------------------------------------------------------------------------------------*/
137
- __publicField(this, "onDispatcherCleared", (callback) => {
138
- this.pluginMethods.onDispatcherCleared = callback;
139
- return this;
140
- });
141
- __publicField(this, "onDispatcherQueueDrained", (callback) => {
142
- this.pluginMethods.onDispatcherQueueDrained = callback;
143
- return this;
144
- });
145
- __publicField(this, "onDispatcherQueueRunning", (callback) => {
146
- this.pluginMethods.onDispatcherQueueRunning = callback;
147
- return this;
148
- });
149
- __publicField(this, "onDispatcherItemAdded", (callback) => {
150
- this.pluginMethods.onDispatcherItemAdded = callback;
151
- return this;
152
- });
153
- __publicField(this, "onDispatcherItemDeleted", (callback) => {
154
- this.pluginMethods.onDispatcherItemDeleted = callback;
155
- return this;
156
- });
157
- __publicField(this, "onDispatcherQueueCreated", (callback) => {
158
- this.pluginMethods.onDispatcherQueueCreated = callback;
159
- return this;
160
- });
161
- __publicField(this, "onDispatcherQueueCleared", (callback) => {
162
- this.pluginMethods.onDispatcherQueueCleared = callback;
163
- return this;
164
- });
165
- /* -------------------------------------------------------------------------------------------------
166
- * Cache lifecycle
167
- * -----------------------------------------------------------------------------------------------*/
168
- __publicField(this, "onCacheItemChange", (callback) => {
169
- this.pluginMethods.onCacheItemChange = callback;
170
- return this;
171
- });
172
- __publicField(this, "onCacheItemDelete", (callback) => {
173
- this.pluginMethods.onCacheItemDelete = callback;
174
- return this;
175
- });
176
- /* -------------------------------------------------------------------------------------------------
177
- * Adapter lifecycle
178
- * -----------------------------------------------------------------------------------------------*/
179
- __publicField(this, "onAdapterFetch", (callback) => {
180
- this.pluginMethods.onAdapterFetch = callback;
181
- return this;
182
- });
183
- this.name = config.name;
184
- if (config.data) {
185
- this.data = config.data;
186
- }
187
- }
188
- };
189
-
190
- // src/constants/time.constants.ts
191
- var Time = /* @__PURE__ */ ((Time2) => {
192
- Time2[Time2["SEC"] = 1e3] = "SEC";
193
- Time2[Time2["MIN"] = 6e4] = "MIN";
194
- Time2[Time2["HOUR"] = 36e5] = "HOUR";
195
- Time2[Time2["DAY"] = 864e5] = "DAY";
196
- Time2[Time2["WEEK"] = 6048e5] = "WEEK";
197
- Time2[Time2["MONTH_30"] = 2592e6] = "MONTH_30";
198
- Time2[Time2["MONTH_31"] = 26784e5] = "MONTH_31";
199
- Time2[Time2["YEAR"] = 31536e6] = "YEAR";
200
- Time2[Time2["YEAR_LEAP"] = 316224e5] = "YEAR_LEAP";
201
- return Time2;
202
- })(Time || {});
203
-
204
- // src/request/request.ts
205
- var _Request = class _Request {
206
- constructor(client, requestOptions, initialRequestConfiguration) {
207
- this.client = client;
208
- this.requestOptions = requestOptions;
209
- this.initialRequestConfiguration = initialRequestConfiguration;
210
- __publicField(this, "endpoint");
211
- __publicField(this, "headers");
212
- __publicField(this, "auth");
213
- __publicField(this, "method");
214
- __publicField(this, "params");
215
- __publicField(this, "payload");
216
- __publicField(this, "queryParams");
217
- __publicField(this, "options");
218
- __publicField(this, "cancelable");
219
- __publicField(this, "retry");
220
- __publicField(this, "retryTime");
221
- __publicField(this, "cacheTime");
222
- __publicField(this, "cache");
223
- __publicField(this, "staleTime");
224
- __publicField(this, "queued");
225
- __publicField(this, "offline");
226
- __publicField(this, "abortKey");
227
- __publicField(this, "cacheKey");
228
- __publicField(this, "queryKey");
229
- __publicField(this, "used");
230
- __publicField(this, "deduplicate");
231
- __publicField(this, "deduplicateTime");
232
- __publicField(this, "isMockerEnabled", false);
233
- __publicField(this, "unstable_mock");
234
- /** @internal */
235
- __publicField(this, "unstable_payloadMapper");
236
- /** @internal */
237
- __publicField(this, "unstable_requestMapper");
238
- /** @internal */
239
- __publicField(this, "unstable_responseMapper");
240
- __publicField(this, "unstable_hasParams", false);
241
- __publicField(this, "unstable_hasPayload", false);
242
- __publicField(this, "unstable_hasQuery", false);
243
- __publicField(this, "updatedAbortKey");
244
- __publicField(this, "updatedCacheKey");
245
- __publicField(this, "updatedQueryKey");
246
- __publicField(this, "setHeaders", (headers) => {
247
- return this.clone({ headers });
248
- });
249
- __publicField(this, "setAuth", (auth) => {
250
- return this.clone({ auth });
251
- });
252
- __publicField(this, "setParams", (params) => {
253
- return this.clone({ params });
254
- });
255
- __publicField(this, "setPayload", (payload) => {
256
- return this.clone({
257
- payload
258
- });
259
- });
260
- __publicField(this, "setQueryParams", (queryParams) => {
261
- return this.clone({ queryParams });
262
- });
263
- __publicField(this, "setOptions", (options) => {
264
- return this.clone({ options });
265
- });
266
- __publicField(this, "setCancelable", (cancelable) => {
267
- return this.clone({ cancelable });
268
- });
269
- __publicField(this, "setRetry", (retry) => {
270
- return this.clone({ retry });
271
- });
272
- __publicField(this, "setRetryTime", (retryTime) => {
273
- return this.clone({ retryTime });
274
- });
275
- __publicField(this, "setCacheTime", (cacheTime) => {
276
- return this.clone({ cacheTime });
277
- });
278
- __publicField(this, "setCache", (cache) => {
279
- return this.clone({ cache });
280
- });
281
- __publicField(this, "setStaleTime", (staleTime) => {
282
- return this.clone({ staleTime });
283
- });
284
- __publicField(this, "setQueued", (queued) => {
285
- return this.clone({ queued });
286
- });
287
- __publicField(this, "setAbortKey", (abortKey) => {
288
- this.updatedAbortKey = true;
289
- return this.clone({ abortKey });
290
- });
291
- __publicField(this, "setCacheKey", (cacheKey) => {
292
- this.updatedCacheKey = true;
293
- return this.clone({ cacheKey });
294
- });
295
- __publicField(this, "setQueryKey", (queryKey) => {
296
- this.updatedQueryKey = true;
297
- return this.clone({ queryKey });
298
- });
299
- __publicField(this, "setDeduplicate", (deduplicate) => {
300
- return this.clone({ deduplicate });
301
- });
302
- __publicField(this, "setDeduplicateTime", (deduplicateTime) => {
303
- return this.clone({ deduplicateTime });
304
- });
305
- __publicField(this, "setUsed", (used) => {
306
- return this.clone({ used });
307
- });
308
- __publicField(this, "setOffline", (offline) => {
309
- return this.clone({ offline });
310
- });
311
- __publicField(this, "setMock", (fn, config = {}) => {
312
- this.unstable_mock = { fn, config };
313
- this.isMockerEnabled = true;
314
- return this;
315
- });
316
- __publicField(this, "clearMock", () => {
317
- this.unstable_mock = void 0;
318
- this.isMockerEnabled = false;
319
- return this;
320
- });
321
- __publicField(this, "setMockingEnabled", (isMockerEnabled) => {
322
- this.isMockerEnabled = isMockerEnabled;
323
- return this;
324
- });
325
- /**
326
- * Map data before it gets send to the server
327
- * @param payloadMapper
328
- * @returns
329
- */
330
- __publicField(this, "setPayloadMapper", (payloadMapper) => {
331
- const cloned = this.clone(void 0);
332
- cloned.unstable_payloadMapper = payloadMapper;
333
- return cloned;
334
- });
335
- /**
336
- * Map request before it gets send to the server
337
- * @param requestMapper mapper of the request
338
- * @returns new request
339
- */
340
- __publicField(this, "setRequestMapper", (requestMapper) => {
341
- const cloned = this.clone(void 0);
342
- cloned.unstable_requestMapper = requestMapper;
343
- return cloned;
344
- });
345
- /**
346
- * Map the response to the new interface
347
- * @param responseMapper our mapping callback
348
- * @returns new response
349
- */
350
- __publicField(this, "setResponseMapper", (responseMapper) => {
351
- const cloned = this.clone();
352
- cloned.unstable_responseMapper = responseMapper;
353
- return cloned;
354
- });
355
- __publicField(this, "paramsMapper", (params) => {
356
- const { endpoint } = this.requestOptions;
357
- let stringEndpoint = String(endpoint);
358
- if (params) {
359
- Object.entries(params).forEach(([key, value]) => {
360
- stringEndpoint = stringEndpoint.replace(new RegExp(`:${key}`, "g"), String(value));
361
- });
362
- }
363
- return stringEndpoint;
364
- });
365
- __publicField(this, "abort", () => {
366
- const { requestManager } = this.client;
367
- requestManager.abortByKey(this.abortKey);
368
- return this.clone();
369
- });
370
- __publicField(this, "dehydrate", (config) => {
371
- const { response, override = true } = config || {};
372
- if (response) {
373
- return {
374
- override,
375
- cacheTime: this.cacheTime,
376
- staleTime: this.staleTime,
377
- cacheKey: this.cacheKey,
378
- timestamp: +/* @__PURE__ */ new Date(),
379
- hydrated: true,
380
- cache: true,
381
- response
382
- };
383
- }
384
- const cacheData = this.client.cache.get(this.cacheKey);
385
- if (!cacheData) {
386
- return void 0;
387
- }
388
- return {
389
- override,
390
- cacheTime: this.cacheTime,
391
- staleTime: this.staleTime,
392
- cacheKey: this.cacheKey,
393
- timestamp: +/* @__PURE__ */ new Date(),
394
- hydrated: true,
395
- cache: true,
396
- response: {
397
- data: cacheData.data,
398
- error: cacheData.error,
399
- status: cacheData.status,
400
- success: cacheData.success,
401
- extra: cacheData.extra,
402
- requestTimestamp: cacheData.requestTimestamp,
403
- responseTimestamp: cacheData.responseTimestamp
404
- }
405
- };
406
- });
407
- /**
408
- * Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.
409
- * @param options
410
- * @disableReturns
411
- * @returns
412
- * ```tsx
413
- * Promise<[Data | null, Error | null, HttpStatus]>
414
- * ```
415
- */
416
- __publicField(this, "exec", (options) => __async(this, null, function* () {
417
- const { adapter, requestManager } = this.client;
418
- const request = this.clone(options);
419
- const requestId = this.client.unstable_requestIdMapper(this);
420
- requestManager.addAbortController(this.abortKey, requestId);
421
- const response = yield adapter.fetch(request, requestId);
422
- requestManager.removeAbortController(this.abortKey, requestId);
423
- if (request.unstable_responseMapper) {
424
- return request.unstable_responseMapper(response);
425
- }
426
- return response;
427
- }));
428
- /**
429
- * Method used to perform requests with usage of cache and queues
430
- * @param options
431
- * @param requestCallback
432
- * @disableReturns
433
- * @returns
434
- * ```tsx
435
- * Promise<[Data | null, Error | null, HttpStatus]>
436
- * ```
437
- */
438
- __publicField(this, "send", (options) => __async(this, null, function* () {
439
- const _a = options || {}, { dispatcherType } = _a, configuration = __objRest(_a, ["dispatcherType"]);
440
- const request = this.clone(configuration);
441
- return sendRequest(request, options);
442
- }));
443
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
444
- const configuration = __spreadValues(__spreadValues({}, (_b = (_a = this.client.adapter).unstable_getRequestDefaults) == null ? void 0 : _b.call(_a, requestOptions)), requestOptions);
445
- const {
446
- endpoint,
447
- headers,
448
- auth = true,
449
- method = client.adapter.defaultMethod,
450
- options,
451
- cancelable = false,
452
- retry = 0,
453
- retryTime = 500,
454
- cacheTime = 6e4 /* MIN */ * 5,
455
- cache = true,
456
- staleTime = 6e4 /* MIN */ * 5,
457
- queued = false,
458
- offline = true,
459
- abortKey,
460
- cacheKey,
461
- queryKey,
462
- deduplicate = false,
463
- deduplicateTime = null
464
- } = configuration;
465
- this.endpoint = (_c = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.endpoint) != null ? _c : endpoint;
466
- this.headers = (_d = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.headers) != null ? _d : headers;
467
- this.auth = (_e = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.auth) != null ? _e : auth;
468
- this.method = method;
469
- this.params = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.params;
470
- this.payload = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.payload;
471
- this.queryParams = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.queryParams;
472
- this.options = (_f = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.options) != null ? _f : options;
473
- this.cancelable = (_g = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.cancelable) != null ? _g : cancelable;
474
- this.retry = (_h = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.retry) != null ? _h : retry;
475
- this.retryTime = (_i = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.retryTime) != null ? _i : retryTime;
476
- this.cacheTime = (_j = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.cacheTime) != null ? _j : cacheTime;
477
- this.cache = (_k = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.cache) != null ? _k : cache;
478
- this.staleTime = (_l = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.staleTime) != null ? _l : staleTime;
479
- this.queued = (_m = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.queued) != null ? _m : queued;
480
- this.offline = (_n = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.offline) != null ? _n : offline;
481
- this.abortKey = (_p = (_o = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.abortKey) != null ? _o : abortKey) != null ? _p : this.client.unstable_abortKeyMapper(this);
482
- this.cacheKey = (_r = (_q = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.cacheKey) != null ? _q : cacheKey) != null ? _r : this.client.unstable_cacheKeyMapper(this);
483
- this.queryKey = (_t = (_s = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.queryKey) != null ? _s : queryKey) != null ? _t : this.client.unstable_queryKeyMapper(this);
484
- this.used = (_u = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.used) != null ? _u : false;
485
- this.deduplicate = (_v = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.deduplicate) != null ? _v : deduplicate;
486
- this.deduplicateTime = (_w = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.deduplicateTime) != null ? _w : deduplicateTime;
487
- this.updatedAbortKey = (_x = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.updatedAbortKey) != null ? _x : false;
488
- this.updatedCacheKey = (_y = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.updatedCacheKey) != null ? _y : false;
489
- this.updatedQueryKey = (_z = initialRequestConfiguration == null ? void 0 : initialRequestConfiguration.updatedQueryKey) != null ? _z : false;
490
- }
491
- toJSON() {
492
- return {
493
- requestOptions: this.requestOptions,
494
- endpoint: this.endpoint,
495
- headers: this.headers,
496
- auth: this.auth,
497
- // TODO: fix this type
498
- method: this.method,
499
- params: this.params,
500
- payload: this.payload,
501
- queryParams: this.queryParams,
502
- options: this.options,
503
- cancelable: this.cancelable,
504
- retry: this.retry,
505
- retryTime: this.retryTime,
506
- cacheTime: this.cacheTime,
507
- cache: this.cache,
508
- staleTime: this.staleTime,
509
- queued: this.queued,
510
- offline: this.offline,
511
- abortKey: this.abortKey,
512
- cacheKey: this.cacheKey,
513
- queryKey: this.queryKey,
514
- used: this.used,
515
- disableResponseInterceptors: this.requestOptions.disableResponseInterceptors,
516
- disableRequestInterceptors: this.requestOptions.disableRequestInterceptors,
517
- updatedAbortKey: this.updatedAbortKey,
518
- updatedCacheKey: this.updatedCacheKey,
519
- updatedQueryKey: this.updatedQueryKey,
520
- deduplicate: this.deduplicate,
521
- deduplicateTime: this.deduplicateTime,
522
- isMockerEnabled: this.isMockerEnabled,
523
- hasMock: !!this.unstable_mock
524
- };
525
- }
526
- clone(configuration) {
527
- const json = this.toJSON();
528
- const initialRequestConfiguration = __spreadProps(__spreadValues(__spreadValues({}, json), configuration), {
529
- options: (configuration == null ? void 0 : configuration.options) || this.options,
530
- abortKey: this.updatedAbortKey ? (configuration == null ? void 0 : configuration.abortKey) || this.abortKey : void 0,
531
- cacheKey: this.updatedCacheKey ? (configuration == null ? void 0 : configuration.cacheKey) || this.cacheKey : void 0,
532
- queryKey: this.updatedQueryKey ? (configuration == null ? void 0 : configuration.queryKey) || this.queryKey : void 0,
533
- endpoint: this.paramsMapper((configuration == null ? void 0 : configuration.params) || this.params),
534
- queryParams: (configuration == null ? void 0 : configuration.queryParams) || this.queryParams,
535
- payload: (configuration == null ? void 0 : configuration.payload) || this.payload,
536
- params: (configuration == null ? void 0 : configuration.params) || this.params
537
- });
538
- const cloned = new _Request(this.client, this.requestOptions, initialRequestConfiguration);
539
- cloned.unstable_payloadMapper = this.unstable_payloadMapper;
540
- cloned.unstable_responseMapper = this.unstable_responseMapper;
541
- cloned.unstable_requestMapper = this.unstable_requestMapper;
542
- cloned.unstable_mock = this.unstable_mock;
543
- cloned.isMockerEnabled = this.isMockerEnabled;
544
- return cloned;
545
- }
546
- /**
547
- * Read the response from cache data
548
- *
549
- * If it returns error and data at the same time, it means that latest request was failed
550
- * and we show previous data from cache together with error received from actual request
551
- */
552
- read() {
553
- const cacheData = this.client.cache.get(this.cacheKey);
554
- if (cacheData) {
555
- return {
556
- data: cacheData.data,
557
- error: cacheData.error,
558
- status: cacheData.status,
559
- success: cacheData.success,
560
- extra: cacheData.extra,
561
- requestTimestamp: cacheData.requestTimestamp,
562
- responseTimestamp: cacheData.responseTimestamp
563
- };
564
- }
565
- return void 0;
566
- }
567
- };
568
- __publicField(_Request, "fromJSON", (client, json) => {
569
- return new _Request(client, json.requestOptions, json);
570
- });
571
- var Request = _Request;
572
-
573
- // src/constants/http.constants.ts
574
- var HttpMethods = /* @__PURE__ */ ((HttpMethods2) => {
575
- HttpMethods2["GET"] = "GET";
576
- HttpMethods2["POST"] = "POST";
577
- HttpMethods2["PUT"] = "PUT";
578
- HttpMethods2["PATCH"] = "PATCH";
579
- HttpMethods2["DELETE"] = "DELETE";
580
- return HttpMethods2;
581
- })(HttpMethods || {});
582
-
583
- // src/dispatcher/dispatcher.constants.ts
584
- var DispatcherMode = /* @__PURE__ */ ((DispatcherMode2) => {
585
- DispatcherMode2["ONE_BY_ONE"] = "one-by-one";
586
- DispatcherMode2["ALL_AT_ONCE"] = "all-at-once";
587
- DispatcherMode2["PREVIOUS_CANCELED"] = "previous-canceled";
588
- DispatcherMode2["DEDUPLICATED"] = "deduplicated";
589
- return DispatcherMode2;
590
- })(DispatcherMode || {});
591
-
592
- // src/dispatcher/dispatcher.events.ts
593
- var getDispatcherEvents = (emitter) => ({
594
- emitDrained: (values, isTriggeredExternally) => {
595
- emitter.emit(getDispatcherDrainedKey(), values, isTriggeredExternally);
596
- emitter.emit(getDispatcherDrainedByKey(values.queryKey), values, isTriggeredExternally);
597
- },
598
- emitQueueStatusChanged: (values, isTriggeredExternally) => {
599
- emitter.emit(getDispatcherStatusKey(), values, isTriggeredExternally);
600
- emitter.emit(getDispatcherStatusByKey(values.queryKey), values, isTriggeredExternally);
601
- },
602
- emitQueueChanged: (values, isTriggeredExternally) => {
603
- emitter.emit(getDispatcherChangeKey(), values, isTriggeredExternally);
604
- emitter.emit(getDispatcherChangeByKey(values.queryKey), values, isTriggeredExternally);
605
- },
606
- /**
607
- * When queue becomes empty
608
- * @param callback
609
- * @returns
610
- */
611
- onDrained: (callback) => {
612
- emitter.on(getDispatcherDrainedKey(), callback);
613
- return () => emitter.removeListener(getDispatcherDrainedKey(), callback);
614
- },
615
- /**
616
- * When queue becomes empty
617
- * @param queryKey
618
- * @param callback
619
- * @returns
620
- */
621
- onDrainedByKey: (queryKey, callback) => {
622
- emitter.on(getDispatcherDrainedByKey(queryKey), callback);
623
- return () => emitter.removeListener(getDispatcherDrainedByKey(queryKey), callback);
624
- },
625
- /**
626
- * When queue status change from enabled to paused or vice versa
627
- * @param callback
628
- * @returns
629
- */
630
- onQueueStatusChange: (callback) => {
631
- emitter.on(getDispatcherStatusKey(), callback);
632
- return () => emitter.removeListener(getDispatcherStatusKey(), callback);
633
- },
634
- /**
635
- * When queue status change from enabled to paused or vice versa
636
- * @param queryKey
637
- * @param callback
638
- * @returns
639
- */
640
- onQueueStatusChangeByKey: (queryKey, callback) => {
641
- emitter.on(getDispatcherStatusByKey(queryKey), callback);
642
- return () => emitter.removeListener(getDispatcherStatusByKey(queryKey), callback);
643
- },
644
- /**
645
- * When new elements are added or removed from the queue
646
- * @param queryKey
647
- * @param callback
648
- * @returns
649
- */
650
- onQueueChange: (callback) => {
651
- emitter.on(getDispatcherChangeKey(), callback);
652
- return () => emitter.removeListener(getDispatcherChangeKey(), callback);
653
- },
654
- /**
655
- * When new elements are added or removed from the queue
656
- * @param queryKey
657
- * @param callback
658
- * @returns
659
- */
660
- onQueueChangeByKey: (queryKey, callback) => {
661
- emitter.on(getDispatcherChangeByKey(queryKey), callback);
662
- return () => emitter.removeListener(getDispatcherChangeByKey(queryKey), callback);
663
- }
664
- });
665
-
666
- // src/utils/uuid.utils.ts
667
- var getUniqueRequestId = (request) => {
668
- return `${request.queryKey}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`;
669
- };
670
-
671
- // src/utils/emitter.utils.ts
672
- import Emitter from "events";
673
- var getListenName = (event) => `listen_${String(event)}`;
674
- var EventEmitter = class extends Emitter {
675
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor
676
- constructor(options) {
677
- super(options);
678
- __publicField(this, "emitCallbacks", []);
679
- __publicField(this, "onEmit", (callback) => {
680
- var _a;
681
- (_a = this.emitCallbacks) == null ? void 0 : _a.push(callback);
682
- return () => {
683
- var _a2;
684
- this.emitCallbacks = (_a2 = this.emitCallbacks) == null ? void 0 : _a2.filter((cb) => cb !== callback);
685
- };
686
- });
687
- __publicField(this, "onListener", (event, listener) => {
688
- super.on(getListenName(event), listener);
689
- return () => {
690
- super.off(getListenName(event), listener);
691
- };
692
- });
693
- __publicField(this, "on", (event, listener) => {
694
- super.on(event, listener);
695
- super.emit(getListenName(event), super.listeners(event).length);
696
- return this;
697
- });
698
- __publicField(this, "off", (event, listener) => {
699
- super.off(event, listener);
700
- super.emit(getListenName(event), super.listeners(event).length);
701
- return this;
702
- });
703
- __publicField(this, "addListener", this.on);
704
- __publicField(this, "removeListener", this.off);
705
- }
706
- emit(type, data, isTriggeredExternally) {
707
- var _a;
708
- const params = [type, data];
709
- if (isTriggeredExternally) {
710
- params.push(isTriggeredExternally);
711
- }
712
- (_a = this.emitCallbacks) == null ? void 0 : _a.forEach((callback) => callback(...params));
713
- return super.emit(...params);
714
- }
715
- };
716
-
717
- // src/dispatcher/dispatcher.ts
718
- var Dispatcher = class {
719
- constructor(options) {
720
- this.options = options;
721
- __publicField(this, "emitter", new EventEmitter());
722
- __publicField(this, "events", getDispatcherEvents(this.emitter));
723
- __publicField(this, "storage", /* @__PURE__ */ new Map());
724
- __publicField(this, "requestCount", /* @__PURE__ */ new Map());
725
- __publicField(this, "runningRequests", /* @__PURE__ */ new Map());
726
- __publicField(this, "logger");
727
- __publicField(this, "client");
728
- __publicField(this, "initialize", (client) => {
729
- this.client = client;
730
- this.logger = client.loggerManager.initialize(client, "Dispatcher");
731
- this.client.appManager.events.onOnline(() => {
732
- this.flush();
733
- });
734
- return this;
735
- });
736
- // *********************************************************************
737
- // *********************************************************************
738
- // Queue
739
- // *********************************************************************
740
- // *********************************************************************
741
- /**
742
- * Start request handling by queryKey
743
- */
744
- __publicField(this, "start", (queryKey) => {
745
- const queue = this.getQueue(queryKey);
746
- queue.stopped = false;
747
- this.setQueue(queryKey, queue);
748
- this.flushQueue(queryKey);
749
- this.client.triggerPlugins("onDispatcherQueueRunning", { dispatcher: this, queue, status: "running" });
750
- this.events.emitQueueStatusChanged(queue);
751
- });
752
- /**
753
- * Pause request queue, but do not cancel already started requests
754
- */
755
- __publicField(this, "pause", (queryKey) => {
756
- const queue = this.getQueue(queryKey);
757
- queue.stopped = true;
758
- this.setQueue(queryKey, queue);
759
- this.client.triggerPlugins("onDispatcherQueueRunning", { dispatcher: this, queue, status: "paused" });
760
- this.events.emitQueueStatusChanged(queue);
761
- });
762
- /**
763
- * Stop request queue and cancel all started requests - those will be treated like not started
764
- */
765
- __publicField(this, "stop", (queryKey) => {
766
- const queue = this.getQueue(queryKey);
767
- queue.stopped = true;
768
- this.setQueue(queryKey, queue);
769
- this.cancelRunningRequests(queryKey);
770
- this.client.triggerPlugins("onDispatcherQueueRunning", { dispatcher: this, queue, status: "stopped" });
771
- this.events.emitQueueStatusChanged(queue);
772
- });
773
- /**
774
- * Return all
775
- */
776
- __publicField(this, "getQueuesKeys", () => {
777
- return Array.from(this.storage.keys());
778
- });
779
- /**
780
- * Return queue state object
781
- */
782
- __publicField(this, "getQueue", (queryKey) => {
783
- const initialQueueState = { queryKey, requests: [], stopped: false };
784
- const storedEntity = this.storage.get(queryKey);
785
- return storedEntity || initialQueueState;
786
- });
787
- /**
788
- * Return request from queue state
789
- */
790
- __publicField(this, "getRequest", (queryKey, requestId) => {
791
- const initialQueueState = { queryKey, requests: [], stopped: false };
792
- const storedEntity = this.storage.get(queryKey) || initialQueueState;
793
- return storedEntity.requests.find((req) => req.requestId === requestId);
794
- });
795
- /**
796
- * Get value of the active queue status based on the stopped status
797
- */
798
- __publicField(this, "getIsActiveQueue", (queryKey) => {
799
- const queue = this.getQueue(queryKey);
800
- const hasAvailableRequests = queue.requests.some((req) => !req.stopped);
801
- const isRunningQueue = !queue.stopped;
802
- return hasAvailableRequests && isRunningQueue;
803
- });
804
- /**
805
- * Add new element to storage
806
- */
807
- __publicField(this, "addQueueItem", (queryKey, element) => {
808
- const queue = this.getQueue(queryKey);
809
- queue.requests.push(element);
810
- this.client.triggerPlugins("onDispatcherItemAdded", { dispatcher: this, queue, queueItem: element });
811
- this.setQueue(queryKey, queue);
812
- });
813
- /**
814
- * Set new queue storage value
815
- */
816
- __publicField(this, "setQueue", (queryKey, queue) => {
817
- this.storage.set(queryKey, queue);
818
- this.client.triggerPlugins("onDispatcherQueueCreated", { dispatcher: this, queue });
819
- this.events.emitQueueChanged(queue);
820
- return queue;
821
- });
822
- /**
823
- * Clear requests from queue cache
824
- */
825
- __publicField(this, "clearQueue", (queryKey) => {
826
- const queue = this.getQueue(queryKey);
827
- const newQueue = { queryKey, requests: [], stopped: queue.stopped };
828
- this.storage.set(queryKey, newQueue);
829
- this.client.triggerPlugins("onDispatcherQueueCleared", { dispatcher: this, queue: newQueue });
830
- this.events.emitQueueChanged(newQueue);
831
- this.events.emitDrained(newQueue);
832
- return newQueue;
833
- });
834
- /**
835
- * Method used to flush the queue requests
836
- */
837
- __publicField(this, "flushQueue", (queryKey) => __async(this, null, function* () {
838
- const queue = this.getQueue(queryKey);
839
- const runningRequests = this.getRunningRequests(queryKey);
840
- const queueItem = queue.requests.find((request) => !request.stopped);
841
- const isStopped = queue && queue.stopped;
842
- const isOffline = !this.client.appManager.isOnline;
843
- const isConcurrent = !(queueItem == null ? void 0 : queueItem.request.queued);
844
- const isInactive = !runningRequests.length;
845
- const isEmpty = !queueItem;
846
- if (isStopped || isOffline || isEmpty) {
847
- this.logger.debug({ title: "Skipping queue trigger", type: "system", extra: { isStopped, isOffline, isEmpty } });
848
- } else if (isConcurrent) {
849
- queue.requests.forEach((element) => {
850
- if (!this.hasRunningRequest(queryKey, element.requestId)) {
851
- this.performRequest(element);
852
- }
853
- });
854
- } else if (isInactive) {
855
- yield this.performRequest(queueItem);
856
- this.flushQueue(queryKey);
857
- }
858
- }));
859
- /**
860
- * Flush all available requests from all queues
861
- */
862
- __publicField(this, "flush", () => __async(this, null, function* () {
863
- const keys = this.getQueuesKeys();
864
- for (const key of keys) {
865
- const storageItem = this.getQueue(key);
866
- if (storageItem) {
867
- this.flushQueue(key);
868
- }
869
- }
870
- }));
871
- /**
872
- * Clear all running requests and storage
873
- */
874
- __publicField(this, "clear", () => {
875
- const keys = this.getQueuesKeys();
876
- keys.forEach((queryKey) => this.cancelRunningRequests(queryKey));
877
- this.runningRequests.clear();
878
- this.storage.clear();
879
- this.client.triggerPlugins("onDispatcherCleared", { dispatcher: this });
880
- });
881
- // *********************************************************************
882
- // *********************************************************************
883
- // Requests
884
- // *********************************************************************
885
- // *********************************************************************
886
- /**
887
- * Start particular request
888
- */
889
- __publicField(this, "startRequest", (queryKey, requestId) => {
890
- const queue = this.getQueue(queryKey);
891
- const request = queue.requests.find((element) => element.requestId === requestId);
892
- if (request) {
893
- request.stopped = false;
894
- this.setQueue(queryKey, queue);
895
- this.flushQueue(queryKey);
896
- this.events.emitQueueStatusChanged(queue);
897
- }
898
- });
899
- /**
900
- * Stop particular request
901
- */
902
- __publicField(this, "stopRequest", (queryKey, requestId) => {
903
- const queue = this.getQueue(queryKey);
904
- const request = queue.requests.find((element) => element.requestId === requestId);
905
- if (request) {
906
- request.stopped = true;
907
- this.setQueue(queryKey, queue);
908
- this.cancelRunningRequest(queryKey, requestId);
909
- this.events.emitQueueStatusChanged(queue);
910
- }
911
- });
912
- /**
913
- * Get currently running requests from all queryKeys
914
- */
915
- __publicField(this, "getAllRunningRequests", () => {
916
- return Array.from(this.runningRequests.values()).flat();
917
- });
918
- /**
919
- * Get currently running requests
920
- */
921
- __publicField(this, "getRunningRequests", (queryKey) => {
922
- return this.runningRequests.get(queryKey) || [];
923
- });
924
- /**
925
- * Get running request by id
926
- */
927
- __publicField(this, "getRunningRequest", (queryKey, requestId) => {
928
- const runningRequests = this.getRunningRequests(queryKey);
929
- return runningRequests.find((req) => req.requestId === requestId);
930
- });
931
- /**
932
- * Add request to the running requests list
933
- */
934
- __publicField(this, "addRunningRequest", (queryKey, requestId, request) => {
935
- const newRunningRequest = { requestId, request, timestamp: Date.now() };
936
- const runningRequests = this.getRunningRequests(queryKey);
937
- runningRequests.push(newRunningRequest);
938
- this.runningRequests.set(queryKey, runningRequests);
939
- return newRunningRequest;
940
- });
941
- /**
942
- * Get the value based on the currently running requests
943
- */
944
- __publicField(this, "hasRunningRequests", (queryKey) => {
945
- return !!this.getRunningRequests(queryKey).length;
946
- });
947
- /**
948
- * Check if request is currently processing
949
- */
950
- __publicField(this, "hasRunningRequest", (queryKey, requestId) => {
951
- const runningRequests = this.getRunningRequests(queryKey);
952
- return !!runningRequests.find((req) => req.requestId === requestId);
953
- });
954
- /**
955
- * Cancel all started requests, but do NOT remove it from main storage
956
- */
957
- __publicField(this, "cancelRunningRequests", (queryKey) => {
958
- var _a;
959
- (_a = this.runningRequests.get(queryKey)) == null ? void 0 : _a.forEach((request) => {
960
- this.client.requestManager.abortByRequestId(request.request.abortKey, request.requestId);
961
- });
962
- this.deleteRunningRequests(queryKey);
963
- });
964
- /**
965
- * Cancel started request, but do NOT remove it from main storage
966
- */
967
- __publicField(this, "cancelRunningRequest", (queryKey, requestId) => {
968
- const requests = this.getRunningRequests(queryKey).filter((request) => {
969
- if (request.requestId === requestId) {
970
- this.client.requestManager.abortByRequestId(request.request.abortKey, request.requestId);
971
- return false;
972
- }
973
- return true;
974
- });
975
- this.runningRequests.set(queryKey, requests);
976
- });
977
- /**
978
- * Delete all started requests, but do NOT clear it from queue and do NOT cancel them
979
- */
980
- __publicField(this, "deleteRunningRequests", (queryKey) => {
981
- this.runningRequests.set(queryKey, []);
982
- });
983
- /**
984
- * Delete request by id, but do NOT clear it from queue and do NOT cancel them
985
- */
986
- __publicField(this, "deleteRunningRequest", (queryKey, requestId) => {
987
- const runningRequests = this.getRunningRequests(queryKey);
988
- this.runningRequests.set(
989
- queryKey,
990
- runningRequests.filter((req) => req.requestId !== requestId)
991
- );
992
- });
993
- /**
994
- * Get count of requests from the same queryKey
995
- */
996
- __publicField(this, "getQueueRequestCount", (queryKey) => {
997
- return this.requestCount.get(queryKey) || 0;
998
- });
999
- /**
1000
- * Add request count to the queryKey
1001
- */
1002
- __publicField(this, "incrementQueueRequestCount", (queryKey) => {
1003
- const count = this.requestCount.get(queryKey) || 0;
1004
- this.requestCount.set(queryKey, count + 1);
1005
- });
1006
- /**
1007
- * Create storage element from request
1008
- */
1009
- // eslint-disable-next-line class-methods-use-this
1010
- __publicField(this, "createStorageItem", (request) => {
1011
- const requestId = this.client.unstable_requestIdMapper(request);
1012
- const storageItem = {
1013
- requestId,
1014
- timestamp: +/* @__PURE__ */ new Date(),
1015
- request,
1016
- retries: 0,
1017
- stopped: false,
1018
- resolved: false
1019
- };
1020
- return storageItem;
1021
- });
1022
- // *********************************************************************
1023
- // *********************************************************************
1024
- // Dispatching
1025
- // *********************************************************************
1026
- // *********************************************************************
1027
- /**
1028
- * Add request to the dispatcher handler
1029
- */
1030
- __publicField(this, "add", (request) => {
1031
- const { queryKey } = request;
1032
- const storageItem = this.createStorageItem(request);
1033
- const { requestId } = storageItem;
1034
- const queue = this.getQueue(queryKey);
1035
- const [latestRequest] = queue.requests.slice(-1);
1036
- const requestType = getRequestType(request, latestRequest);
1037
- this.logger.debug({ title: "Adding request to queue", type: "system", extra: { requestType, request, requestId } });
1038
- switch (requestType) {
1039
- case "one-by-one" /* ONE_BY_ONE */: {
1040
- this.addQueueItem(queryKey, storageItem);
1041
- this.flushQueue(queryKey);
1042
- return requestId;
1043
- }
1044
- case "previous-canceled" /* PREVIOUS_CANCELED */: {
1045
- this.cancelRunningRequests(queryKey);
1046
- this.clearQueue(queryKey);
1047
- this.addQueueItem(queryKey, storageItem);
1048
- this.flushQueue(queryKey);
1049
- return requestId;
1050
- }
1051
- case "deduplicated" /* DEDUPLICATED */: {
1052
- this.client.requestManager.events.emitDeduplicated({
1053
- request: latestRequest.request,
1054
- requestId,
1055
- deduplicatedRequest: request
1056
- });
1057
- return latestRequest.requestId;
1058
- }
1059
- default: {
1060
- this.addQueueItem(queryKey, storageItem);
1061
- this.flushQueue(queryKey);
1062
- return requestId;
1063
- }
1064
- }
1065
- });
1066
- /**
1067
- * Delete from the storage and cancel request
1068
- */
1069
- __publicField(this, "delete", (queryKey, requestId, abortKey) => {
1070
- this.logger.debug({ title: "Deleting request", type: "system", extra: { queryKey, requestId, abortKey } });
1071
- const queue = this.getQueue(queryKey);
1072
- const queueItem = queue.requests.find((req) => req.requestId === requestId);
1073
- if (!queueItem) return;
1074
- queue.requests = queue.requests.filter((req) => req.requestId !== requestId);
1075
- this.storage.set(queryKey, queue);
1076
- if (this.hasRunningRequest(queryKey, requestId)) {
1077
- this.deleteRunningRequest(queryKey, requestId);
1078
- this.client.requestManager.abortByRequestId(abortKey, requestId);
1079
- }
1080
- this.client.triggerPlugins("onDispatcherItemDeleted", { queue, dispatcher: this, queueItem });
1081
- this.events.emitQueueChanged(queue);
1082
- this.client.requestManager.events.emitRemove({
1083
- requestId,
1084
- request: queueItem.request,
1085
- resolved: queueItem.resolved
1086
- });
1087
- if (!queue.requests.length) {
1088
- this.client.triggerPlugins("onDispatcherQueueDrained", { queue, dispatcher: this });
1089
- this.events.emitDrained(queue);
1090
- }
1091
- return queue;
1092
- });
1093
- /**
1094
- * Request can run for some time, once it's done, we have to check if it's successful or if it was aborted
1095
- * It can be different once the previous call was set as cancelled and removed from queue before this request got resolved
1096
- */
1097
- __publicField(this, "performRequest", (storageItem) => __async(this, null, function* () {
1098
- var _a;
1099
- const { request, requestId } = storageItem;
1100
- this.logger.debug({ title: "Performing request", type: "system", extra: { request, requestId } });
1101
- const { retry, retryTime, queryKey, abortKey, offline } = request;
1102
- const { adapter, requestManager, cache, appManager } = this.client;
1103
- const canRetry = canRetryRequest(storageItem.retries, retry);
1104
- const isOffline = !appManager.isOnline && offline;
1105
- const isAlreadyRunning = this.hasRunningRequest(queryKey, requestId);
1106
- const isStopped = storageItem.stopped;
1107
- if (isOffline || isAlreadyRunning || isStopped) {
1108
- return this.logger.warning({
1109
- title: "Unable to perform request",
1110
- type: "system",
1111
- extra: { isOffline, isAlreadyRunning, isStopped }
1112
- });
1113
- }
1114
- const runningRequest = this.addRunningRequest(queryKey, requestId, request);
1115
- requestManager.events.emitLoading({
1116
- request,
1117
- requestId,
1118
- loading: true,
1119
- isRetry: !!storageItem.retries,
1120
- isOffline
1121
- });
1122
- this.incrementQueueRequestCount(queryKey);
1123
- requestManager.addAbortController(abortKey, requestId);
1124
- const response = yield adapter.fetch(request, requestId);
1125
- storageItem.resolved = true;
1126
- requestManager.removeAbortController(abortKey, requestId);
1127
- const isOfflineResponseStatus = !appManager.isOnline;
1128
- const isCancelMessage = getErrorMessage("abort").message === ((_a = response.error) == null ? void 0 : _a.message);
1129
- const isCanceled = !this.hasRunningRequest(queryKey, requestId) || isCancelMessage;
1130
- this.deleteRunningRequest(queryKey, requestId);
1131
- const requestDetails = {
1132
- isCanceled,
1133
- isOffline: isOfflineResponseStatus,
1134
- retries: storageItem.retries,
1135
- addedTimestamp: storageItem.timestamp,
1136
- triggerTimestamp: runningRequest.timestamp,
1137
- requestTimestamp: response.requestTimestamp,
1138
- responseTimestamp: response.responseTimestamp
1139
- };
1140
- requestManager.events.emitResponse({ request, requestId, response, details: requestDetails });
1141
- requestManager.events.emitLoading({
1142
- request,
1143
- requestId,
1144
- loading: false,
1145
- isRetry: !!storageItem.retries,
1146
- isOffline
1147
- });
1148
- cache.set(request, __spreadValues(__spreadValues({}, response), requestDetails));
1149
- this.logger.debug({
1150
- title: "Dispatcher processing response",
1151
- type: "system",
1152
- extra: { requestId, request, response, details: requestDetails }
1153
- });
1154
- if (isCanceled) {
1155
- const queue = this.getQueue(queryKey);
1156
- const queueItem = queue.requests.find((req) => req.requestId === requestId);
1157
- if (!queue.stopped && !(queueItem == null ? void 0 : queueItem.stopped)) {
1158
- this.logger.debug({ title: "Request paused", type: "system", extra: { response, requestDetails, request } });
1159
- return this.delete(queryKey, requestId, abortKey);
1160
- }
1161
- return this.logger.debug({
1162
- title: "Request canceled",
1163
- type: "system",
1164
- extra: { response, requestDetails, request }
1165
- });
1166
- }
1167
- if (!response.success && isOfflineResponseStatus) {
1168
- if (!offline) {
1169
- this.logger.warning({
1170
- title: "Removing non-offline request",
1171
- type: "system",
1172
- extra: { response, requestDetails, request }
1173
- });
1174
- return this.delete(queryKey, requestId, abortKey);
1175
- }
1176
- return this.logger.debug({
1177
- title: "Awaiting for network restoration",
1178
- type: "system",
1179
- extra: { response, requestDetails, request }
1180
- });
1181
- }
1182
- if (response.success) {
1183
- this.delete(queryKey, requestId, abortKey);
1184
- return this.logger.debug({
1185
- title: "Successful response, removing request from queue.",
1186
- type: "system",
1187
- extra: {
1188
- response,
1189
- requestDetails,
1190
- request
1191
- }
1192
- });
1193
- }
1194
- if (!response.success && canRetry) {
1195
- this.logger.debug({ title: "Waiting for retry", type: "system", extra: { response, requestDetails, request } });
1196
- setTimeout(() => {
1197
- this.logger.warning({
1198
- title: "Error response, performing retry",
1199
- type: "request",
1200
- extra: { response, requestDetails, request, requestId }
1201
- });
1202
- this.performRequest(__spreadProps(__spreadValues({}, storageItem), {
1203
- retries: storageItem.retries + 1
1204
- }));
1205
- }, retryTime || 0);
1206
- } else {
1207
- if (request.retry) {
1208
- this.logger.error({
1209
- title: "All retries have been used. Removing request from queue.",
1210
- type: "request",
1211
- extra: { response, requestDetails, request, requestId }
1212
- });
1213
- }
1214
- this.delete(queryKey, requestId, abortKey);
1215
- }
1216
- }));
1217
- var _a, _b;
1218
- (_a = this.emitter) == null ? void 0 : _a.setMaxListeners(1e3);
1219
- if ((_b = this.options) == null ? void 0 : _b.storage) {
1220
- this.storage = this.options.storage;
1221
- }
1222
- }
1223
- };
1224
-
1225
- // src/dispatcher/dispatcher.utils.ts
1226
- var getDispatcherDrainedKey = () => {
1227
- return `drained-event`;
1228
- };
1229
- var getDispatcherDrainedByKey = (key) => {
1230
- return `${key}-drained-event`;
1231
- };
1232
- var getDispatcherStatusKey = () => {
1233
- return `status-event`;
1234
- };
1235
- var getDispatcherStatusByKey = (key) => {
1236
- return `${key}-status-event`;
1237
- };
1238
- var getDispatcherChangeKey = () => {
1239
- return `change-event`;
1240
- };
1241
- var getDispatcherChangeByKey = (key) => {
1242
- return `${key}-change-event`;
1243
- };
1244
- var getIsEqualTimestamp = (currentTimestamp, threshold, queueTimestamp) => {
1245
- if (!queueTimestamp) {
1246
- return false;
1247
- }
1248
- return queueTimestamp - currentTimestamp <= threshold;
1249
- };
1250
- var canRetryRequest = (currentRetries, retry) => {
1251
- if (retry && currentRetries < retry) {
1252
- return true;
1253
- }
1254
- return false;
1255
- };
1256
- var isInDeduplicateRange = (request, latestRequest) => {
1257
- if (request.deduplicateTime) {
1258
- return +/* @__PURE__ */ new Date() - latestRequest.timestamp <= request.deduplicateTime;
1259
- }
1260
- return true;
1261
- };
1262
- var getRequestType = (request, latestRequest) => {
1263
- const { queued, cancelable, deduplicate } = request;
1264
- const canDeduplicate = latestRequest ? isInDeduplicateRange(request, latestRequest) : false;
1265
- if (queued) {
1266
- return "one-by-one" /* ONE_BY_ONE */;
1267
- }
1268
- if (cancelable) {
1269
- return "previous-canceled" /* PREVIOUS_CANCELED */;
1270
- }
1271
- if (canDeduplicate && deduplicate) {
1272
- return "deduplicated" /* DEDUPLICATED */;
1273
- }
1274
- return "all-at-once" /* ALL_AT_ONCE */;
1275
- };
1276
-
1277
- // src/request/request.utils.ts
1278
- var stringifyKey = (value) => {
1279
- try {
1280
- if (typeof value === "string") return value;
1281
- if (value === void 0 || value === null) return "";
1282
- const data = JSON.stringify(value);
1283
- if (typeof data !== "string") throw new Error();
1284
- return data;
1285
- } catch (_) {
1286
- return "";
1287
- }
1288
- };
1289
- var getProgressValue = ({ loaded, total }) => {
1290
- if (!loaded || !total) return 0;
1291
- return Number((loaded * 100 / total).toFixed(0));
1292
- };
1293
- var getRequestEta = (startDate, progressDate, { total, loaded }) => {
1294
- const timeElapsed = +progressDate - +startDate || 1;
1295
- const uploadSpeed = loaded / timeElapsed;
1296
- const totalValue = Math.max(total, loaded);
1297
- const sizeLeft = totalValue - loaded;
1298
- const estimatedTimeValue = uploadSpeed ? sizeLeft / uploadSpeed : null;
1299
- const timeLeft = totalValue === loaded ? 0 : estimatedTimeValue;
1300
- return { timeLeft, sizeLeft };
1301
- };
1302
- var getProgressData = (requestStartTime, progressDate, progressEvent) => {
1303
- const { total, loaded } = progressEvent;
1304
- if (Number.isNaN(total) || Number.isNaN(loaded)) {
1305
- return {
1306
- progress: 0,
1307
- timeLeft: 0,
1308
- sizeLeft: 0,
1309
- total: 0,
1310
- loaded: 0,
1311
- startTimestamp: +requestStartTime
1312
- };
1313
- }
1314
- const { timeLeft, sizeLeft } = getRequestEta(requestStartTime, progressDate, progressEvent);
1315
- return {
1316
- progress: getProgressValue(progressEvent),
1317
- timeLeft,
1318
- sizeLeft,
1319
- total,
1320
- loaded,
1321
- startTimestamp: +requestStartTime
1322
- };
1323
- };
1324
- var getSimpleKey = (request) => {
1325
- return `${request.method}_${request.requestOptions.endpoint}_${request.cancelable}`;
1326
- };
1327
- var getRequestKey = (request, useInitialValues) => {
1328
- const methodKey = stringifyKey(request.method);
1329
- const endpointKey = useInitialValues ? request.requestOptions.endpoint : stringifyKey(request.endpoint);
1330
- const queryParamsKey = useInitialValues ? "" : stringifyKey(request.queryParams);
1331
- return `${methodKey}_${endpointKey}_${queryParamsKey}`;
1332
- };
1333
- var getRequestDispatcher = (request, dispatcherType = "auto") => {
1334
- const { fetchDispatcher, submitDispatcher } = request.client;
1335
- const isGet = request.method === "GET" /* GET */;
1336
- const isFetchDispatcher = dispatcherType === "auto" && isGet || dispatcherType === "fetch";
1337
- const dispatcher = isFetchDispatcher ? fetchDispatcher : submitDispatcher;
1338
- return [dispatcher, isFetchDispatcher];
1339
- };
1340
- var sendRequest = (request, options) => {
1341
- const { client } = request;
1342
- const { requestManager } = client;
1343
- const [dispatcher] = getRequestDispatcher(request, options == null ? void 0 : options.dispatcherType);
1344
- return new Promise((resolve) => {
1345
- var _a;
1346
- let isResolved = false;
1347
- const requestId = dispatcher.add(request);
1348
- (_a = options == null ? void 0 : options.onBeforeSent) == null ? void 0 : _a.call(options, { requestId, request });
1349
- const unmountRequestStart = requestManager.events.onRequestStartById(
1350
- requestId,
1351
- (data) => {
1352
- var _a2;
1353
- return (_a2 = options == null ? void 0 : options.onRequestStart) == null ? void 0 : _a2.call(options, data);
1354
- }
1355
- );
1356
- const unmountResponseStart = requestManager.events.onResponseStartById(
1357
- requestId,
1358
- (data) => {
1359
- var _a2;
1360
- return (_a2 = options == null ? void 0 : options.onResponseStart) == null ? void 0 : _a2.call(options, data);
1361
- }
1362
- );
1363
- const unmountUpload = requestManager.events.onUploadProgressById(
1364
- requestId,
1365
- (data) => {
1366
- var _a2;
1367
- return (_a2 = options == null ? void 0 : options.onUploadProgress) == null ? void 0 : _a2.call(options, data);
1368
- }
1369
- );
1370
- const unmountDownload = requestManager.events.onDownloadProgressById(
1371
- requestId,
1372
- (data) => {
1373
- var _a2;
1374
- return (_a2 = options == null ? void 0 : options.onDownloadProgress) == null ? void 0 : _a2.call(options, data);
1375
- }
1376
- );
1377
- const unmountResponse = requestManager.events.onResponseById(requestId, (values) => {
1378
- var _a2;
1379
- const { details, response } = values;
1380
- isResolved = true;
1381
- const mapping = (_a2 = request.unstable_responseMapper) == null ? void 0 : _a2.call(
1382
- request,
1383
- response
1384
- );
1385
- const isOfflineStatus = request.offline && details.isOffline;
1386
- const willRetry = canRetryRequest(details.retries, request.retry);
1387
- const handleResponse2 = (success, data) => {
1388
- var _a3;
1389
- if (!success && isOfflineStatus) return;
1390
- if (!success && willRetry) return;
1391
- (_a3 = options == null ? void 0 : options.onResponse) == null ? void 0 : _a3.call(options, values);
1392
- resolve(data);
1393
- umountAll();
1394
- };
1395
- if (mapping instanceof Promise) {
1396
- (() => __async(null, null, function* () {
1397
- const responseData = yield mapping;
1398
- const { success } = responseData;
1399
- handleResponse2(success, responseData);
1400
- }))();
1401
- } else {
1402
- const data = mapping || response;
1403
- const { success } = data;
1404
- handleResponse2(success, data);
1405
- }
1406
- });
1407
- const unmountRemoveQueueElement = requestManager.events.onRemoveById(requestId, (...props) => {
1408
- var _a2;
1409
- if (!isResolved) {
1410
- (_a2 = options == null ? void 0 : options.onRemove) == null ? void 0 : _a2.call(options, ...props);
1411
- resolve({
1412
- data: null,
1413
- status: null,
1414
- success: false,
1415
- error: getErrorMessage("deleted"),
1416
- extra: request.client.adapter.defaultExtra,
1417
- requestTimestamp: +/* @__PURE__ */ new Date(),
1418
- responseTimestamp: +/* @__PURE__ */ new Date()
1419
- });
1420
- umountAll();
1421
- }
1422
- });
1423
- function umountAll() {
1424
- unmountRequestStart();
1425
- unmountResponseStart();
1426
- unmountUpload();
1427
- unmountDownload();
1428
- unmountResponse();
1429
- unmountRemoveQueueElement();
1430
- }
1431
- });
1432
- };
1433
-
1434
- // src/adapter/adapter.bindings.ts
1435
- var getAdapterBindings = (_0) => __async(null, [_0], function* ({
1436
- request: baseRequest,
1437
- requestId,
1438
- resolve,
1439
- onStartTime,
1440
- internalErrorMapping
1441
- }) {
1442
- const { requestManager, loggerManager } = baseRequest.client;
1443
- const { unstable_payloadMapper } = baseRequest.client.adapter;
1444
- const logger2 = loggerManager.initialize(baseRequest.client, "Adapter");
1445
- let requestStartTimestamp = null;
1446
- let responseStartTimestamp = null;
1447
- let request = baseRequest;
1448
- let requestTotal = 1;
1449
- let responseTotal = 1;
1450
- let previousRequestTotal = 0;
1451
- let previousResponseTotal = 0;
1452
- logger2.debug({
1453
- title: `Running middleware callbacks`,
1454
- type: "request",
1455
- extra: {
1456
- request,
1457
- requestId
1458
- }
1459
- });
1460
- request = yield request.client.unstable_modifyRequest(request);
1461
- if (request.auth) {
1462
- request = yield request.client.unstable_modifyAuth(request);
1463
- }
1464
- if (request.unstable_requestMapper) {
1465
- request = yield request.unstable_requestMapper(request, requestId);
1466
- }
1467
- const { client, abortKey } = request;
1468
- let payload = request.payload;
1469
- if (request.unstable_payloadMapper) {
1470
- payload = yield request.unstable_payloadMapper(request.payload);
1471
- } else if (unstable_payloadMapper) {
1472
- payload = yield unstable_payloadMapper(payload);
1473
- }
1474
- const adapterOptions = request.options;
1475
- const startTime = +/* @__PURE__ */ new Date();
1476
- onStartTime(startTime);
1477
- const getRequestStartTimestamp = () => {
1478
- return requestStartTimestamp;
1479
- };
1480
- const getResponseStartTimestamp = () => {
1481
- return responseStartTimestamp;
1482
- };
1483
- const getTotal = (previousTotal, progress) => {
1484
- if (!progress) return previousTotal;
1485
- const total = Number(progress.total || 0);
1486
- const loaded = Number(progress.loaded || 0);
1487
- return Math.max(total, loaded, previousTotal);
1488
- };
1489
- const handleRequestProgress = (startTimestamp, progressTimestamp, progressEvent) => {
1490
- const progress = getProgressData(new Date(startTimestamp), new Date(progressTimestamp), progressEvent);
1491
- if (previousRequestTotal !== 100) {
1492
- previousRequestTotal = progress.total;
1493
- requestManager.events.emitUploadProgress(__spreadProps(__spreadValues({}, progress), { requestId, request }));
1494
- }
1495
- };
1496
- const handleResponseProgress = (startTimestamp, progressTimestamp, progressEvent) => {
1497
- const progress = getProgressData(new Date(startTimestamp), new Date(progressTimestamp), progressEvent);
1498
- if (previousResponseTotal !== 100) {
1499
- previousResponseTotal = progress.total;
1500
- requestManager.events.emitDownloadProgress(__spreadProps(__spreadValues({}, progress), { requestId, request }));
1501
- }
1502
- };
1503
- const onBeforeRequest = () => {
1504
- logger2.debug({
1505
- title: `Request about to be sent`,
1506
- type: "request",
1507
- extra: {
1508
- request,
1509
- requestId
1510
- }
1511
- });
1512
- client.triggerPlugins("onRequestTrigger", { request });
1513
- };
1514
- const onRequestStart = (progress) => {
1515
- logger2.info({
1516
- title: `Request start`,
1517
- type: "request",
1518
- extra: {
1519
- request,
1520
- requestId
1521
- }
1522
- });
1523
- client.triggerPlugins("onRequestStart", { request });
1524
- if (progress == null ? void 0 : progress.total) {
1525
- requestTotal = getTotal(requestTotal, progress);
1526
- }
1527
- const initialPayload = {
1528
- total: requestTotal,
1529
- loaded: (progress == null ? void 0 : progress.loaded) || 0
1530
- };
1531
- requestStartTimestamp = +/* @__PURE__ */ new Date();
1532
- handleRequestProgress(requestStartTimestamp, requestStartTimestamp, initialPayload);
1533
- requestManager.events.emitRequestStart({ requestId, request });
1534
- return requestStartTimestamp;
1535
- };
1536
- const onRequestProgress = (progress) => {
1537
- if (!requestStartTimestamp) {
1538
- requestStartTimestamp = +/* @__PURE__ */ new Date();
1539
- }
1540
- requestTotal = getTotal(requestTotal, progress);
1541
- const progressTimestamp = +/* @__PURE__ */ new Date();
1542
- handleRequestProgress(requestStartTimestamp, progressTimestamp, {
1543
- total: requestTotal,
1544
- loaded: progress.loaded || 0
1545
- });
1546
- return progressTimestamp;
1547
- };
1548
- const onRequestEnd = () => {
1549
- if (!requestStartTimestamp) {
1550
- requestStartTimestamp = +/* @__PURE__ */ new Date();
1551
- }
1552
- const progressTimestamp = +/* @__PURE__ */ new Date();
1553
- handleRequestProgress(requestStartTimestamp, progressTimestamp, {
1554
- total: requestTotal,
1555
- loaded: requestTotal
1556
- });
1557
- return progressTimestamp;
1558
- };
1559
- const onResponseStart = (progress) => {
1560
- responseStartTimestamp = +/* @__PURE__ */ new Date();
1561
- responseTotal = getTotal(responseTotal, progress);
1562
- const initialPayload = {
1563
- total: responseTotal,
1564
- loaded: (progress == null ? void 0 : progress.loaded) || 0
1565
- };
1566
- handleResponseProgress(responseStartTimestamp, responseStartTimestamp, initialPayload);
1567
- requestManager.events.emitResponseStart({ requestId, request });
1568
- return responseStartTimestamp;
1569
- };
1570
- const onResponseProgress = (progress) => {
1571
- if (!responseStartTimestamp) {
1572
- responseStartTimestamp = +/* @__PURE__ */ new Date();
1573
- }
1574
- const progressTimestamp = +/* @__PURE__ */ new Date();
1575
- responseTotal = getTotal(responseTotal, progress);
1576
- handleResponseProgress(responseStartTimestamp, progressTimestamp, {
1577
- total: progress.total || responseTotal,
1578
- loaded: progress.loaded || 0
1579
- });
1580
- return progressTimestamp;
1581
- };
1582
- const onResponseEnd = () => {
1583
- if (!responseStartTimestamp) {
1584
- responseStartTimestamp = +/* @__PURE__ */ new Date();
1585
- }
1586
- const progressTimestamp = +/* @__PURE__ */ new Date();
1587
- handleResponseProgress(responseStartTimestamp, progressTimestamp, {
1588
- total: responseTotal,
1589
- loaded: responseTotal
1590
- });
1591
- return progressTimestamp;
1592
- };
1593
- const onSuccess = (_02) => __async(null, [_02], function* ({
1594
- data,
1595
- error,
1596
- status,
1597
- extra
1598
- }) {
1599
- var _a, _b, _c, _d;
1600
- let response = {
1601
- data,
1602
- error: error != null ? error : null,
1603
- success: true,
1604
- status,
1605
- extra,
1606
- requestTimestamp: startTime,
1607
- responseTimestamp: +/* @__PURE__ */ new Date()
1608
- };
1609
- response = yield (_b = (_a = request.client).unstable_modifyResponse) == null ? void 0 : _b.call(_a, response, request);
1610
- response = yield (_d = (_c = request.client).unstable_modifySuccessResponse) == null ? void 0 : _d.call(_c, response, request);
1611
- client.triggerPlugins("onRequestSuccess", { response, request });
1612
- client.triggerPlugins("onRequestFinished", { response, request });
1613
- resolve(response);
1614
- logger2.info({
1615
- title: `Response success`,
1616
- type: "response",
1617
- extra: {
1618
- request,
1619
- requestId,
1620
- response
1621
- }
1622
- });
1623
- return response;
1624
- });
1625
- const onError = getAdapterOnError({
1626
- request,
1627
- requestId,
1628
- startTime,
1629
- logger: logger2,
1630
- resolve
1631
- });
1632
- const onAbortError = ({
1633
- status,
1634
- extra
1635
- }) => {
1636
- logger2.error({
1637
- title: `Abort error`,
1638
- type: "request",
1639
- extra: {
1640
- request,
1641
- requestId
1642
- }
1643
- });
1644
- const error = internalErrorMapping(getErrorMessage("abort"));
1645
- return onError({ error, status, extra });
1646
- };
1647
- const onTimeoutError = ({
1648
- status,
1649
- extra
1650
- }) => {
1651
- logger2.error({
1652
- title: `Timeout error`,
1653
- type: "request",
1654
- extra: {
1655
- request,
1656
- requestId
1657
- }
1658
- });
1659
- const error = getErrorMessage("timeout");
1660
- return onError({ error, status, extra });
1661
- };
1662
- const onUnexpectedError = ({
1663
- status,
1664
- extra
1665
- }) => {
1666
- logger2.error({
1667
- title: `Unexpected error`,
1668
- type: "request",
1669
- extra: {
1670
- request,
1671
- requestId
1672
- }
1673
- });
1674
- const error = getErrorMessage();
1675
- return onError({ error, status, extra });
1676
- };
1677
- const getAbortController = () => {
1678
- return requestManager.getAbortController(abortKey, requestId);
1679
- };
1680
- const createAbortListener = ({
1681
- status,
1682
- extra,
1683
- onAbort = () => {
1684
- }
1685
- }) => {
1686
- const controller = getAbortController();
1687
- if (!controller) {
1688
- throw new RequestProcessingError("Controller is not found");
1689
- }
1690
- const abort = () => {
1691
- onAbortError({ status, extra });
1692
- onAbort();
1693
- requestManager.events.emitAbort({ requestId, request });
1694
- };
1695
- if (controller.signal.aborted) {
1696
- abort();
1697
- }
1698
- controller.signal.addEventListener("abort", abort);
1699
- return () => controller.signal.removeEventListener("abort", abort);
1700
- };
1701
- logger2.debug({
1702
- title: `Mounted adapter bindings`,
1703
- type: "request",
1704
- extra: {
1705
- request,
1706
- requestId,
1707
- payload,
1708
- adapterOptions
1709
- }
1710
- });
1711
- const queryParams = baseRequest.client.adapter.unstable_queryParamsMapper(request.queryParams);
1712
- const endpoint = baseRequest.client.adapter.unstable_endpointMapper(request.endpoint);
1713
- const headers = baseRequest.client.adapter.unstable_headerMapper(request);
1714
- const { url } = baseRequest.client;
1715
- return {
1716
- request,
1717
- requestId,
1718
- url,
1719
- endpoint,
1720
- queryParams,
1721
- payload,
1722
- headers,
1723
- adapter: baseRequest.client.adapter,
1724
- adapterOptions,
1725
- getAbortController,
1726
- getRequestStartTimestamp,
1727
- getResponseStartTimestamp,
1728
- createAbortListener,
1729
- onBeforeRequest,
1730
- onRequestStart,
1731
- onRequestProgress,
1732
- onRequestEnd,
1733
- onResponseStart,
1734
- onResponseProgress,
1735
- onResponseEnd,
1736
- onSuccess,
1737
- onAbortError,
1738
- onTimeoutError,
1739
- onUnexpectedError,
1740
- onError
1741
- };
1742
- });
1743
- function getAdapterOnError({
1744
- request,
1745
- requestId,
1746
- startTime,
1747
- resolve,
1748
- logger: logger2
1749
- }) {
1750
- const { client } = request;
1751
- return (_0) => __async(null, [_0], function* ({
1752
- error,
1753
- status,
1754
- extra
1755
- }) {
1756
- let response = {
1757
- data: null,
1758
- status,
1759
- error,
1760
- success: false,
1761
- extra,
1762
- requestTimestamp: startTime,
1763
- responseTimestamp: +/* @__PURE__ */ new Date()
1764
- };
1765
- response = yield client.unstable_modifyResponse(response, request);
1766
- response = yield client.unstable_modifyErrorResponse(response, request);
1767
- client.triggerPlugins("onRequestError", { response, request });
1768
- client.triggerPlugins("onRequestFinished", { response, request });
1769
- resolve(response);
1770
- logger2.error({
1771
- title: `Request error`,
1772
- type: "request",
1773
- extra: {
1774
- request,
1775
- requestId,
1776
- response
1777
- }
1778
- });
1779
- return response;
1780
- });
1781
- }
1782
-
1783
- // src/mocker/mocker.ts
1784
- var mocker = (_0) => __async(null, [_0], function* ({
1785
- request,
1786
- requestId,
1787
- onError,
1788
- onResponseEnd,
1789
- onTimeoutError,
1790
- onRequestEnd,
1791
- createAbortListener,
1792
- onResponseProgress,
1793
- onRequestProgress,
1794
- onResponseStart,
1795
- onBeforeRequest,
1796
- onRequestStart,
1797
- onSuccess,
1798
- onAbortError,
1799
- adapter
1800
- }) {
1801
- if (!request.unstable_mock) {
1802
- throw new RequestProcessingError("Mock should be defined when calling mocker");
1803
- }
1804
- let thrown = false;
1805
- const {
1806
- requestTime = 20,
1807
- responseTime = 20,
1808
- totalUploaded = 1e3,
1809
- totalDownloaded = 1e3,
1810
- timeout
1811
- } = request.unstable_mock.config;
1812
- const result = yield request.unstable_mock.fn({ request, requestId });
1813
- const { data, error, status, success = true, extra = request.client.adapter.defaultExtra } = result;
1814
- createAbortListener({
1815
- status: adapter.systemErrorStatus,
1816
- extra: adapter.systemErrorExtra,
1817
- onAbort: () => {
1818
- thrown = true;
1819
- }
1820
- });
1821
- onBeforeRequest();
1822
- onRequestStart();
1823
- const progress = (totalTime, totalSize, progressFunction) => new Promise((resolveProgress) => {
1824
- if (thrown) {
1825
- resolveProgress(true);
1826
- return;
1827
- }
1828
- const interval = 20;
1829
- const dataStart = +/* @__PURE__ */ new Date();
1830
- const intervals = Math.ceil(totalTime / interval);
1831
- const chunkSize = Math.ceil(totalSize / intervals);
1832
- let currentlyLoaded = 0;
1833
- const timer = setInterval(function handleProgressInterval() {
1834
- if (thrown) {
1835
- resolveProgress(true);
1836
- clearInterval(timer);
1837
- }
1838
- const currentTime = Math.min(totalTime, +/* @__PURE__ */ new Date() - dataStart);
1839
- currentlyLoaded += currentlyLoaded + chunkSize >= totalSize ? totalSize - currentlyLoaded : chunkSize;
1840
- progressFunction({
1841
- total: totalSize,
1842
- loaded: currentTime >= totalTime ? totalSize : currentlyLoaded
1843
- });
1844
- if (currentTime >= totalTime) {
1845
- resolveProgress(true);
1846
- clearInterval(timer);
1847
- }
1848
- }, interval);
1849
- });
1850
- if (typeof timeout === "number") {
1851
- setTimeout(() => {
1852
- thrown = true;
1853
- onTimeoutError({
1854
- status: 0,
1855
- extra
1856
- });
1857
- }, timeout);
1858
- }
1859
- if (!thrown) {
1860
- yield progress(requestTime, totalUploaded, onRequestProgress);
1861
- }
1862
- if (!thrown) {
1863
- onRequestEnd();
1864
- onResponseStart();
1865
- }
1866
- if (!thrown) {
1867
- yield progress(responseTime, totalDownloaded, onResponseProgress);
1868
- }
1869
- if (thrown) {
1870
- onAbortError({
1871
- status: adapter.systemErrorStatus,
1872
- extra: adapter.systemErrorExtra
1873
- });
1874
- } else if (success || error && data) {
1875
- onSuccess({
1876
- data,
1877
- error,
1878
- status,
1879
- extra
1880
- });
1881
- } else {
1882
- onError({
1883
- error,
1884
- status,
1885
- extra
1886
- });
1887
- }
1888
- if (!thrown) {
1889
- onResponseEnd();
1890
- }
1891
- });
1892
-
1893
- // src/managers/app/app.manager.ts
1894
- var AppManager = class {
1895
- constructor(options) {
1896
- this.options = options;
1897
- __publicField(this, "emitter", new EventEmitter());
1898
- __publicField(this, "events", getAppManagerEvents(this.emitter));
1899
- __publicField(this, "isBrowser");
1900
- __publicField(this, "isOnline");
1901
- __publicField(this, "isFocused");
1902
- __publicField(this, "initialize", () => {
1903
- const { focusEvent = appManagerInitialOptions.focusEvent, onlineEvent = appManagerInitialOptions.onlineEvent } = this.options || appManagerInitialOptions;
1904
- focusEvent(this.setFocused);
1905
- onlineEvent(this.setOnline);
1906
- });
1907
- __publicField(this, "setInitialFocus", (initValue) => __async(this, null, function* () {
1908
- if (typeof initValue === "function") {
1909
- this.isFocused = false;
1910
- this.isFocused = yield initValue();
1911
- } else {
1912
- this.isFocused = initValue;
1913
- }
1914
- }));
1915
- __publicField(this, "setInitialOnline", (initValue) => __async(this, null, function* () {
1916
- if (typeof initValue === "function") {
1917
- this.isOnline = false;
1918
- this.isOnline = yield initValue();
1919
- } else {
1920
- this.isOnline = initValue;
1921
- }
1922
- }));
1923
- __publicField(this, "setFocused", (isFocused) => {
1924
- this.isFocused = isFocused;
1925
- if (isFocused) {
1926
- this.events.emitFocus();
1927
- } else {
1928
- this.events.emitBlur();
1929
- }
1930
- });
1931
- __publicField(this, "setOnline", (isOnline) => {
1932
- this.isOnline = isOnline;
1933
- if (isOnline) {
1934
- this.events.emitOnline();
1935
- } else {
1936
- this.events.emitOffline();
1937
- }
1938
- });
1939
- var _a;
1940
- (_a = this.emitter) == null ? void 0 : _a.setMaxListeners(1e3);
1941
- const {
1942
- initiallyFocused = appManagerInitialOptions.initiallyFocused,
1943
- initiallyOnline = appManagerInitialOptions.initiallyOnline
1944
- } = this.options || appManagerInitialOptions;
1945
- this.setInitialFocus(initiallyFocused);
1946
- this.setInitialOnline(initiallyOnline);
1947
- this.isBrowser = hasDocument();
1948
- }
1949
- };
1950
-
1951
- // src/managers/app/app.manager.utils.ts
1952
- var hasWindow = () => {
1953
- try {
1954
- return Boolean(window && window.addEventListener);
1955
- } catch (err) {
1956
- return false;
1957
- }
1958
- };
1959
- var hasDocument = () => {
1960
- try {
1961
- return Boolean(hasWindow() && window.document && window.document.addEventListener);
1962
- } catch (err) {
1963
- return false;
1964
- }
1965
- };
1966
- var onWindowEvent = (key, listener, options) => {
1967
- if (hasWindow()) {
1968
- window.addEventListener(key, listener, options);
1969
- return () => window.removeEventListener(key, listener, options);
1970
- }
1971
- return () => null;
1972
- };
1973
- var onDocumentEvent = (key, listener, options) => {
1974
- if (hasDocument()) {
1975
- window.document.addEventListener(key, listener, options);
1976
- return () => window.document.removeEventListener(key, listener, options);
1977
- }
1978
- return () => null;
1979
- };
1980
-
1981
- // src/managers/app/app.manager.events.ts
1982
- var getAppManagerEvents = (emitter) => ({
1983
- emitFocus: () => {
1984
- emitter.emit("focus" /* FOCUS */);
1985
- },
1986
- emitBlur: () => {
1987
- emitter.emit("blur" /* BLUR */);
1988
- },
1989
- emitOnline: () => {
1990
- emitter.emit("online" /* ONLINE */);
1991
- },
1992
- emitOffline: () => {
1993
- emitter.emit("offline" /* OFFLINE */);
1994
- },
1995
- onFocus: (callback) => {
1996
- emitter.on("focus" /* FOCUS */, callback);
1997
- return () => emitter.removeListener("focus" /* FOCUS */, callback);
1998
- },
1999
- onBlur: (callback) => {
2000
- emitter.on("blur" /* BLUR */, callback);
2001
- return () => emitter.removeListener("blur" /* BLUR */, callback);
2002
- },
2003
- onOnline: (callback) => {
2004
- emitter.on("online" /* ONLINE */, callback);
2005
- return () => emitter.removeListener("online" /* ONLINE */, callback);
2006
- },
2007
- onOffline: (callback) => {
2008
- emitter.on("offline" /* OFFLINE */, callback);
2009
- return () => emitter.removeListener("offline" /* OFFLINE */, callback);
2010
- }
2011
- });
2012
-
2013
- // src/managers/app/app.manager.constants.ts
2014
- var AppEvents = /* @__PURE__ */ ((AppEvents2) => {
2015
- AppEvents2["FOCUS"] = "focus";
2016
- AppEvents2["BLUR"] = "blur";
2017
- AppEvents2["ONLINE"] = "online";
2018
- AppEvents2["OFFLINE"] = "offline";
2019
- return AppEvents2;
2020
- })(AppEvents || {});
2021
- var appManagerInitialOptions = {
2022
- initiallyFocused: true,
2023
- initiallyOnline: true,
2024
- focusEvent: (setFocused) => {
2025
- onDocumentEvent("visibilitychange", () => setFocused(true));
2026
- onWindowEvent("focus", () => setFocused(true));
2027
- onWindowEvent("blur", () => setFocused(false));
2028
- },
2029
- onlineEvent: (setOnline) => {
2030
- onWindowEvent("online", () => setOnline(true));
2031
- onWindowEvent("offline", () => setOnline(false));
2032
- }
2033
- };
2034
-
2035
- // src/managers/request/request.manager.ts
2036
- var RequestManager = class {
2037
- constructor() {
2038
- __publicField(this, "emitter", new EventEmitter());
2039
- __publicField(this, "events", getRequestManagerEvents(this.emitter));
2040
- __publicField(this, "abortControllers", /* @__PURE__ */ new Map());
2041
- __publicField(this, "addAbortController", (abortKey, requestId) => {
2042
- let abortGroup = this.abortControllers.get(abortKey);
2043
- if (!abortGroup) {
2044
- const newAbortGroup = /* @__PURE__ */ new Map();
2045
- abortGroup = newAbortGroup;
2046
- this.abortControllers.set(abortKey, newAbortGroup);
2047
- }
2048
- const abortController = abortGroup.get(requestId);
2049
- if (!abortController || abortController.signal.aborted) {
2050
- abortGroup.set(requestId, new AbortController());
2051
- }
2052
- });
2053
- __publicField(this, "getAbortController", (abortKey, requestId) => {
2054
- var _a;
2055
- return (_a = this.abortControllers.get(abortKey)) == null ? void 0 : _a.get(requestId);
2056
- });
2057
- __publicField(this, "removeAbortController", (abortKey, requestId) => {
2058
- var _a;
2059
- (_a = this.abortControllers.get(abortKey)) == null ? void 0 : _a.delete(requestId);
2060
- });
2061
- // Aborting
2062
- __publicField(this, "useAbortController", (abortKey, requestId) => {
2063
- var _a;
2064
- const controller = (_a = this.abortControllers.get(abortKey)) == null ? void 0 : _a.get(requestId);
2065
- controller == null ? void 0 : controller.abort();
2066
- });
2067
- __publicField(this, "abortByKey", (abortKey) => {
2068
- const controllers = this.abortControllers.get(abortKey);
2069
- if (controllers) {
2070
- const entries = Array.from(controllers.entries());
2071
- entries.forEach(([key]) => {
2072
- this.useAbortController(abortKey, key);
2073
- });
2074
- }
2075
- });
2076
- __publicField(this, "abortByRequestId", (abortKey, requestId) => {
2077
- this.useAbortController(abortKey, requestId);
2078
- });
2079
- __publicField(this, "abortAll", () => {
2080
- const entries = Array.from(this.abortControllers.entries());
2081
- entries.forEach(([abortKey, value]) => {
2082
- const controllers = Array.from(value.entries());
2083
- controllers.forEach(([requestId]) => {
2084
- this.useAbortController(abortKey, requestId);
2085
- });
2086
- });
2087
- });
2088
- var _a;
2089
- (_a = this.emitter) == null ? void 0 : _a.setMaxListeners(1e3);
2090
- }
2091
- };
2092
-
2093
- // src/managers/request/request.manager.utils.ts
2094
- var getLoadingKey = () => `loading-event-any`;
2095
- var getLoadingByQueryKey = (queryKey) => `${queryKey}-loading-event`;
2096
- var getLoadingByCacheKey = (cacheKey) => `${cacheKey}-loading-cache-event`;
2097
- var getLoadingByIdKey = (id) => `${id}-loading-event-by-id`;
2098
- var getRemoveKey = () => `remove-event-any`;
2099
- var getRemoveByQueryKey = (queryKey) => `${queryKey}-remove-event`;
2100
- var getRemoveByIdKey = (id) => `${id}-remove-event-by-id`;
2101
- var getAbortKey = () => `request-abort-any`;
2102
- var getAbortByAbortKey = (abortKey) => `${abortKey}-request-abort`;
2103
- var getAbortByIdKey = (id) => `${id}-request-abort-by-id`;
2104
- var getResponseKey = () => `response-any`;
2105
- var getResponseByCacheKey = (cacheKey) => `${cacheKey}-response`;
2106
- var getResponseByIdKey = (id) => `${id}-response-by-id`;
2107
- var getRequestStartKey = () => `request-start-any`;
2108
- var getRequestStarByQueryKey = (queryKey) => `${queryKey}-request-start`;
2109
- var getRequestStartByIdKey = (id) => `${id}-request-start-by-id`;
2110
- var getResponseStartKey = () => `response-start-any`;
2111
- var getResponseStartByQueryKey = (queryKey) => `${queryKey}-response-start`;
2112
- var getResponseStartByIdKey = (id) => `${id}-response-start-by-id`;
2113
- var getUploadProgressKey = () => `request-progress-any`;
2114
- var getUploadProgressByQueryKey = (queryKey) => `${queryKey}-request-progress`;
2115
- var getUploadProgressByIdKey = (id) => `${id}-request-progress-by-id`;
2116
- var getDownloadProgressKey = () => `response-progress-any`;
2117
- var getDownloadProgressByQueryKey = (queryKey) => `${queryKey}-response-progress`;
2118
- var getDownloadProgressByIdKey = (id) => `${id}-response-progress-by-id`;
2119
- var getRequestDeduplicatedKey = () => `request-deduplicated-any`;
2120
- var getRequestDeduplicatedByQueryKey = (queryKey) => `${queryKey}-query-request-deduplicated`;
2121
- var getRequestDeduplicatedByCacheKey = (cacheKey) => `${cacheKey}-cache-request-deduplicated`;
2122
- var getRequestDeduplicatedByIdKey = (id) => `${id}-request-deduplicated-by-id`;
2123
-
2124
- // src/managers/request/request.manager.events.ts
2125
- var getRequestManagerEvents = (emitter) => ({
2126
- /**
2127
- * Emiter
2128
- */
2129
- // Deduplicated
2130
- emitDeduplicated: (data, isTriggeredExternally = false) => {
2131
- emitter.emit(getRequestDeduplicatedKey(), data, isTriggeredExternally);
2132
- emitter.emit(getRequestDeduplicatedByIdKey(data.requestId), data, isTriggeredExternally);
2133
- emitter.emit(getRequestDeduplicatedByCacheKey(data.request.cacheKey), data, isTriggeredExternally);
2134
- emitter.emit(getRequestDeduplicatedByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2135
- },
2136
- // Loading
2137
- emitLoading: (data, isTriggeredExternally = false) => {
2138
- emitter.emit(getLoadingKey(), data, isTriggeredExternally);
2139
- emitter.emit(getLoadingByIdKey(data.requestId), data, isTriggeredExternally);
2140
- emitter.emit(getLoadingByCacheKey(data.request.cacheKey), data, isTriggeredExternally);
2141
- emitter.emit(getLoadingByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2142
- },
2143
- // Start
2144
- emitRequestStart: (data, isTriggeredExternally = false) => {
2145
- emitter.emit(getRequestStartKey(), data, isTriggeredExternally);
2146
- emitter.emit(getRequestStartByIdKey(data.requestId), data, isTriggeredExternally);
2147
- emitter.emit(getRequestStarByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2148
- },
2149
- emitResponseStart: (data, isTriggeredExternally = false) => {
2150
- emitter.emit(getResponseStartKey(), data, isTriggeredExternally);
2151
- emitter.emit(getResponseStartByIdKey(data.requestId), data, isTriggeredExternally);
2152
- emitter.emit(getResponseStartByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2153
- },
2154
- // Progress
2155
- emitUploadProgress: (data, isTriggeredExternally = false) => {
2156
- emitter.emit(getUploadProgressKey(), data, isTriggeredExternally);
2157
- emitter.emit(getUploadProgressByIdKey(data.requestId), data, isTriggeredExternally);
2158
- emitter.emit(getUploadProgressByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2159
- },
2160
- emitDownloadProgress: (data, isTriggeredExternally = false) => {
2161
- emitter.emit(getDownloadProgressKey(), data, isTriggeredExternally);
2162
- emitter.emit(getDownloadProgressByIdKey(data.requestId), data, isTriggeredExternally);
2163
- emitter.emit(getDownloadProgressByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2164
- },
2165
- // Response
2166
- emitResponse: (data, isTriggeredExternally = false) => {
2167
- emitter.emit(getResponseKey(), data, isTriggeredExternally);
2168
- emitter.emit(getResponseByIdKey(data.requestId), data, isTriggeredExternally);
2169
- emitter.emit(getResponseByCacheKey(data.request.cacheKey), data, isTriggeredExternally);
2170
- },
2171
- // Abort
2172
- emitAbort: (data, isTriggeredExternally = false) => {
2173
- emitter.emit(getAbortKey(), data, isTriggeredExternally);
2174
- emitter.emit(getAbortByIdKey(data.requestId), data, isTriggeredExternally);
2175
- emitter.emit(getAbortByAbortKey(data.request.abortKey), data, isTriggeredExternally);
2176
- },
2177
- // Remove
2178
- emitRemove: (data, isTriggeredExternally = false) => {
2179
- emitter.emit(getRemoveKey(), data, isTriggeredExternally);
2180
- emitter.emit(getRemoveByIdKey(data.requestId), data, isTriggeredExternally);
2181
- emitter.emit(getRemoveByQueryKey(data.request.queryKey), data, isTriggeredExternally);
2182
- },
2183
- /**
2184
- * Listeners
2185
- */
2186
- // Deduplicated
2187
- onDeduplicated: (callback) => {
2188
- emitter.on(getRequestDeduplicatedKey(), callback);
2189
- return () => emitter.removeListener(getRequestDeduplicatedKey(), callback);
2190
- },
2191
- onDeduplicatedByQueue: (queryKey, callback) => {
2192
- emitter.on(getRequestDeduplicatedByQueryKey(queryKey), callback);
2193
- return () => emitter.removeListener(getRequestDeduplicatedByQueryKey(queryKey), callback);
2194
- },
2195
- onDeduplicatedByCache: (cacheKey, callback) => {
2196
- emitter.on(getRequestDeduplicatedByCacheKey(cacheKey), callback);
2197
- return () => emitter.removeListener(getRequestDeduplicatedByCacheKey(cacheKey), callback);
2198
- },
2199
- onDeduplicatedById: (requestId, callback) => {
2200
- emitter.on(getRequestDeduplicatedByIdKey(requestId), callback);
2201
- return () => emitter.removeListener(getRequestDeduplicatedByIdKey(requestId), callback);
2202
- },
2203
- // Loading
2204
- onLoading: (callback) => {
2205
- emitter.on(getLoadingKey(), callback);
2206
- return () => emitter.removeListener(getLoadingKey(), callback);
2207
- },
2208
- onLoadingByQueue: (queryKey, callback) => {
2209
- emitter.on(getLoadingByQueryKey(queryKey), callback);
2210
- return () => emitter.removeListener(getLoadingByQueryKey(queryKey), callback);
2211
- },
2212
- onLoadingByCache: (cacheKey, callback) => {
2213
- emitter.on(getLoadingByCacheKey(cacheKey), callback);
2214
- return () => emitter.removeListener(getLoadingByCacheKey(cacheKey), callback);
2215
- },
2216
- onLoadingById: (requestId, callback) => {
2217
- emitter.on(getLoadingByIdKey(requestId), callback);
2218
- return () => emitter.removeListener(getLoadingByIdKey(requestId), callback);
2219
- },
2220
- // Request Start
2221
- onRequestStart: (callback) => {
2222
- emitter.on(getRequestStartKey(), callback);
2223
- return () => emitter.removeListener(getRequestStartKey(), callback);
2224
- },
2225
- onRequestStartByQueue: (queryKey, callback) => {
2226
- emitter.on(getRequestStarByQueryKey(queryKey), callback);
2227
- return () => emitter.removeListener(getRequestStarByQueryKey(queryKey), callback);
2228
- },
2229
- onRequestStartById: (requestId, callback) => {
2230
- emitter.on(getRequestStartByIdKey(requestId), callback);
2231
- return () => emitter.removeListener(getRequestStartByIdKey(requestId), callback);
2232
- },
2233
- // Response Start
2234
- onResponseStart: (callback) => {
2235
- emitter.on(getResponseStartKey(), callback);
2236
- return () => emitter.removeListener(getResponseStartKey(), callback);
2237
- },
2238
- onResponseStartByQueue: (queryKey, callback) => {
2239
- emitter.on(getResponseStartByQueryKey(queryKey), callback);
2240
- return () => emitter.removeListener(getResponseStartByQueryKey(queryKey), callback);
2241
- },
2242
- onResponseStartById: (requestId, callback) => {
2243
- emitter.on(getResponseStartByIdKey(requestId), callback);
2244
- return () => emitter.removeListener(getResponseStartByIdKey(requestId), callback);
2245
- },
2246
- // Progress
2247
- onUploadProgress: (callback) => {
2248
- emitter.on(getUploadProgressKey(), callback);
2249
- return () => emitter.removeListener(getUploadProgressKey(), callback);
2250
- },
2251
- onUploadProgressByQueue: (queryKey, callback) => {
2252
- emitter.on(getUploadProgressByQueryKey(queryKey), callback);
2253
- return () => emitter.removeListener(getUploadProgressByQueryKey(queryKey), callback);
2254
- },
2255
- onUploadProgressById: (requestId, callback) => {
2256
- emitter.on(getUploadProgressByIdKey(requestId), callback);
2257
- return () => emitter.removeListener(getUploadProgressByIdKey(requestId), callback);
2258
- },
2259
- onDownloadProgress: (callback) => {
2260
- emitter.on(getDownloadProgressKey(), callback);
2261
- return () => emitter.removeListener(getDownloadProgressKey(), callback);
2262
- },
2263
- onDownloadProgressByQueue: (queryKey, callback) => {
2264
- emitter.on(getDownloadProgressByQueryKey(queryKey), callback);
2265
- return () => emitter.removeListener(getDownloadProgressByQueryKey(queryKey), callback);
2266
- },
2267
- onDownloadProgressById: (requestId, callback) => {
2268
- emitter.on(getDownloadProgressByIdKey(requestId), callback);
2269
- return () => emitter.removeListener(getDownloadProgressByIdKey(requestId), callback);
2270
- },
2271
- // Response
2272
- onResponse: (callback) => {
2273
- emitter.on(getResponseKey(), callback);
2274
- return () => emitter.removeListener(getResponseKey(), callback);
2275
- },
2276
- onResponseByCache: (cacheKey, callback) => {
2277
- emitter.on(getResponseByCacheKey(cacheKey), callback);
2278
- return () => emitter.removeListener(getResponseByCacheKey(cacheKey), callback);
2279
- },
2280
- onResponseById: (requestId, callback) => {
2281
- emitter.on(getResponseByIdKey(requestId), callback);
2282
- return () => emitter.removeListener(getResponseByIdKey(requestId), callback);
2283
- },
2284
- // Abort
2285
- onAbort: (callback) => {
2286
- emitter.on(getAbortKey(), callback);
2287
- return () => emitter.removeListener(getAbortKey(), callback);
2288
- },
2289
- onAbortByKey: (abortKey, callback) => {
2290
- emitter.on(getAbortByAbortKey(abortKey), callback);
2291
- return () => emitter.removeListener(getAbortByAbortKey(abortKey), callback);
2292
- },
2293
- onAbortById: (requestId, callback) => {
2294
- emitter.on(getAbortByIdKey(requestId), callback);
2295
- return () => emitter.removeListener(getAbortByIdKey(requestId), callback);
2296
- },
2297
- // Remove
2298
- onRemove: (callback) => {
2299
- emitter.on(getRemoveKey(), callback);
2300
- return () => emitter.removeListener(getRemoveKey(), callback);
2301
- },
2302
- onRemoveByQueue: (queryKey, callback) => {
2303
- emitter.on(getRemoveByQueryKey(queryKey), callback);
2304
- return () => emitter.removeListener(getRemoveByQueryKey(queryKey), callback);
2305
- },
2306
- onRemoveById: (requestId, callback) => {
2307
- emitter.on(getRemoveByIdKey(requestId), callback);
2308
- return () => emitter.removeListener(getRemoveByIdKey(requestId), callback);
2309
- }
2310
- });
2311
-
2312
- // src/managers/logger/logger.manager.ts
2313
- import EventEmitter2 from "events";
2314
- var LoggerManager = class {
2315
- constructor(options) {
2316
- this.options = options;
2317
- __publicField(this, "logger");
2318
- __publicField(this, "level");
2319
- __publicField(this, "modules");
2320
- __publicField(this, "emitter", new EventEmitter2());
2321
- __publicField(this, "client");
2322
- __publicField(this, "setSeverity", (level) => {
2323
- this.level = level;
2324
- });
2325
- __publicField(this, "setModules", (modules) => {
2326
- this.modules = modules;
2327
- });
2328
- __publicField(this, "initialize", (client, module) => {
2329
- this.client = client;
2330
- return {
2331
- error: (data) => this.log(__spreadProps(__spreadValues({}, data), { level: "error", module })),
2332
- warning: (data) => this.log(__spreadProps(__spreadValues({}, data), { level: "warning", module })),
2333
- info: (data) => this.log(__spreadProps(__spreadValues({}, data), { level: "info", module })),
2334
- debug: (data) => this.log(__spreadProps(__spreadValues({}, data), { level: "debug", module }))
2335
- };
2336
- });
2337
- __publicField(this, "log", (data) => {
2338
- if (!this.client.debug) {
2339
- return;
2340
- }
2341
- if (logLevelOrder.indexOf(this.level) <= logLevelOrder.indexOf(data.level)) {
2342
- return;
2343
- }
2344
- if (this.modules && !this.modules.includes(data.module)) {
2345
- return;
2346
- }
2347
- this.logger(data);
2348
- });
2349
- var _a, _b, _c, _d;
2350
- (_a = this.emitter) == null ? void 0 : _a.setMaxListeners(1e3);
2351
- this.logger = ((_b = this.options) == null ? void 0 : _b.logger) || logger;
2352
- this.level = ((_c = this.options) == null ? void 0 : _c.level) || "warning";
2353
- this.modules = (_d = this.options) == null ? void 0 : _d.modules;
2354
- }
2355
- };
2356
-
2357
- // src/managers/logger/logger.manager.utils.ts
2358
- var getTime = () => {
2359
- const d = /* @__PURE__ */ new Date();
2360
- return `${d.toLocaleTimeString()}`;
2361
- };
2362
- var getModuleName = (data) => {
2363
- if (data.type === "request" || data.type === "response") {
2364
- return `${data.extra.request.endpoint}`;
2365
- }
2366
- return `[${data.module}]`;
2367
- };
2368
- var logger = (log) => {
2369
- var _a;
2370
- const styles = loggerStyles[log.level];
2371
- const color = loggerColors[log.level];
2372
- const message = `%c[${getTime()}]%c${log.title}%c${getModuleName(log)}`;
2373
- const style1 = `${styles}${color}font-weight:600;border-radius: 4px 0 0 4px;`;
2374
- const style2 = `${styles}${color}font-weight:600;`;
2375
- const style3 = `${styles}font-weight:normal;border-radius: 0 4px 4px 0;`;
2376
- if (log.extra ? (_a = Object.keys(log.extra)) == null ? void 0 : _a.length : false) {
2377
- console.groupCollapsed(message, style1, style2, style3);
2378
- console.log(log.extra);
2379
- console.groupEnd();
2380
- } else {
2381
- console.log(message, styles);
2382
- }
2383
- };
2384
-
2385
- // src/managers/logger/logger.manager.constants.ts
2386
- var logLevelOrder = ["error", "warning", "info", "debug"];
2387
- var defaultStyles = "padding:2px 5px;";
2388
- var loggerStyles = {
2389
- error: `${defaultStyles};background:#db252520;`,
2390
- warning: `${defaultStyles};background:#e1941e20;`,
2391
- info: `${defaultStyles};background:#1e74e120;`,
2392
- debug: `${defaultStyles};background:#00000020;`
2393
- };
2394
- var loggerColors = {
2395
- error: "color:#ff3737;",
2396
- warning: "color:#ffc107;",
2397
- info: "color:#34a8ff;",
2398
- debug: "color:#cccccc;"
2399
- };
2400
-
2401
- // src/adapter/adapter.utils.ts
2402
- var TimeoutError = class extends Error {
2403
- constructor() {
2404
- super("Request timeout");
2405
- this.name = "TimeoutError";
2406
- }
2407
- };
2408
- var AbortError = class extends Error {
2409
- constructor() {
2410
- super("Request aborted");
2411
- this.name = "AbortError";
2412
- }
2413
- };
2414
- var DeletedError = class extends Error {
2415
- constructor() {
2416
- super("Request deleted");
2417
- this.name = "DeletedError";
2418
- }
2419
- };
2420
- var RequestProcessingError = class extends Error {
2421
- constructor(description) {
2422
- super("Request processing error");
2423
- __publicField(this, "description");
2424
- this.description = description;
2425
- this.name = "RequestProcessingError";
2426
- }
2427
- };
2428
- var UnexpectedError = class extends Error {
2429
- constructor(description) {
2430
- super("Unexpected error");
2431
- __publicField(this, "description");
2432
- this.description = description;
2433
- this.name = "UnexpectedError";
2434
- }
2435
- };
2436
- var getErrorMessage = (errorCase) => {
2437
- if (errorCase === "timeout") {
2438
- return new TimeoutError();
2439
- }
2440
- if (errorCase === "abort") {
2441
- return new AbortError();
2442
- }
2443
- if (errorCase === "deleted") {
2444
- return new DeletedError();
2445
- }
2446
- if (errorCase === "processing") {
2447
- return new RequestProcessingError();
2448
- }
2449
- return new UnexpectedError();
2450
- };
2451
- var stringifyValue = (response) => {
2452
- try {
2453
- return JSON.stringify(response);
2454
- } catch (err) {
2455
- return "";
2456
- }
2457
- };
2458
- var getAdapterHeaders = (request) => {
2459
- const isFormData = hasWindow() && request.payload instanceof FormData;
2460
- const isObject = typeof request.payload === "object" && request.payload !== null;
2461
- const headers = {};
2462
- if (!isFormData && isObject) headers["Content-Type"] = "application/json";
2463
- Object.assign(headers, request.headers);
2464
- return headers;
2465
- };
2466
- var getAdapterPayload = (data) => {
2467
- const isFormData = hasWindow() && data instanceof FormData;
2468
- if (isFormData) return data;
2469
- return stringifyValue(data);
2470
- };
2471
-
2472
- // src/adapter/adapter.ts
2473
- var defaultMapper = (value) => value;
2474
- var Adapter = class {
2475
- constructor(options) {
2476
- this.options = options;
2477
- /** Fetching function */
2478
- __publicField(this, "unstable_fetcher");
2479
- /**
2480
- * ********************
2481
- * Defaults
2482
- * ********************
2483
- */
2484
- __publicField(this, "name");
2485
- __publicField(this, "defaultMethod");
2486
- __publicField(this, "defaultExtra");
2487
- __publicField(this, "systemErrorStatus");
2488
- __publicField(this, "systemErrorExtra");
2489
- __publicField(this, "defaultRequestOptions");
2490
- __publicField(this, "logger");
2491
- __publicField(this, "initialized", false);
2492
- __publicField(this, "client");
2493
- __publicField(this, "unstable_onInitializeCallback");
2494
- __publicField(this, "unstable_queryParamsMapperConfig");
2495
- __publicField(this, "unstable_headerMapperConfig");
2496
- __publicField(this, "unstable_payloadMapperConfig");
2497
- __publicField(this, "unstable_endpointMapperConfig");
2498
- __publicField(this, "initialize", (client) => {
2499
- var _a;
2500
- this.logger = client.loggerManager.initialize(client, "Adapter");
2501
- this.initialized = true;
2502
- this.client = client;
2503
- (_a = this.unstable_onInitializeCallback) == null ? void 0 : _a.call(this, { client });
2504
- return this;
2505
- });
2506
- __publicField(this, "onInitialize", (callback) => {
2507
- this.unstable_onInitializeCallback = callback;
2508
- return this;
2509
- });
2510
- /**
2511
- * ********************
2512
- * Options Setters
2513
- * ********************
2514
- */
2515
- __publicField(this, "unstable_internalErrorMapping", (error) => error);
2516
- /** Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats. */
2517
- __publicField(this, "unstable_headerMapper", getAdapterHeaders);
2518
- /** Method to get request data and transform them to the required format. It handles FormData and JSON by default. */
2519
- __publicField(this, "unstable_payloadMapper", getAdapterPayload);
2520
- /** Method to get the endpoint for the adapter request. */
2521
- __publicField(this, "unstable_endpointMapper", defaultMapper);
2522
- /** Method to get request data and transform them to the required format. */
2523
- __publicField(this, "unstable_queryParamsMapper", defaultMapper);
2524
- /** Get default adapter options for the request. */
2525
- __publicField(this, "unstable_getAdapterDefaults");
2526
- /** Get default request options for the request. */
2527
- __publicField(this, "unstable_getRequestDefaults");
2528
- /**
2529
- * Get formatted endpoint name of the request.
2530
- * Helpful in displaying long endpoints like in case of graphql schemas etc.
2531
- */
2532
- __publicField(this, "unstable_devtoolsEndpointGetter", (endpoint) => endpoint);
2533
- /**
2534
- * ********************
2535
- * Methods
2536
- * ********************
2537
- */
2538
- __publicField(this, "setDefaultMethod", (method) => {
2539
- this.defaultMethod = method;
2540
- return this;
2541
- });
2542
- __publicField(this, "setDefaultExtra", (extra) => {
2543
- this.defaultExtra = extra;
2544
- return this;
2545
- });
2546
- __publicField(this, "setDevtoolsEndpointGetter", (callback) => {
2547
- this.unstable_devtoolsEndpointGetter = callback;
2548
- return this;
2549
- });
2550
- /**
2551
- * This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.
2552
- */
2553
- __publicField(this, "setRequestDefaults", (callback) => {
2554
- this.unstable_getRequestDefaults = callback;
2555
- return this;
2556
- });
2557
- /**
2558
- * Set the adapter default options added to every sent request
2559
- */
2560
- __publicField(this, "setAdapterDefaults", (callback) => {
2561
- this.unstable_getAdapterDefaults = callback;
2562
- return this;
2563
- });
2564
- __publicField(this, "setInternalErrorMapping", (callback) => {
2565
- this.unstable_internalErrorMapping = callback;
2566
- return this;
2567
- });
2568
- /**
2569
- * Set the custom header mapping function
2570
- */
2571
- __publicField(this, "setHeaderMapper", (headerMapper) => {
2572
- this.unstable_headerMapper = (req) => headerMapper(req, this.unstable_headerMapperConfig);
2573
- return this;
2574
- });
2575
- /**
2576
- * Set the request payload mapping function which gets triggered before request is send
2577
- */
2578
- __publicField(this, "setPayloadMapper", (payloadMapper) => {
2579
- this.unstable_payloadMapper = (req) => payloadMapper(
2580
- req,
2581
- this.unstable_payloadMapperConfig
2582
- );
2583
- return this;
2584
- });
2585
- /**
2586
- * Set the request payload mapping function which get triggered before request get sent
2587
- */
2588
- __publicField(this, "setEndpointMapper", (endpointMapper) => {
2589
- this.unstable_endpointMapper = (endpoint) => endpointMapper(
2590
- endpoint,
2591
- this.unstable_endpointMapperConfig
2592
- );
2593
- return this;
2594
- });
2595
- /**
2596
- * Set the query params mapping function which get triggered before request get sent
2597
- */
2598
- __publicField(this, "setQueryParamsMapper", (queryParamsMapper) => {
2599
- this.unstable_queryParamsMapper = (queryParams) => queryParamsMapper(
2600
- queryParams,
2601
- this.unstable_queryParamsMapperConfig
2602
- );
2603
- return this;
2604
- });
2605
- __publicField(this, "setQueryParamsMapperConfig", (config) => {
2606
- this.unstable_queryParamsMapperConfig = config;
2607
- return this;
2608
- });
2609
- __publicField(this, "setHeaderMapperConfig", (config) => {
2610
- this.unstable_headerMapperConfig = config;
2611
- return this;
2612
- });
2613
- __publicField(this, "setEndpointMapperConfig", (config) => {
2614
- this.unstable_endpointMapperConfig = config;
2615
- return this;
2616
- });
2617
- __publicField(this, "setPayloadMapperConfig", (config) => {
2618
- this.unstable_payloadMapperConfig = config;
2619
- return this;
2620
- });
2621
- this.name = options.name;
2622
- this.defaultMethod = options.defaultMethod;
2623
- this.defaultExtra = options.defaultExtra;
2624
- this.systemErrorStatus = options.systemErrorStatus;
2625
- this.systemErrorExtra = options.systemErrorExtra;
2626
- this.defaultRequestOptions = options.defaultRequestOptions;
2627
- }
2628
- /**
2629
- * ********************
2630
- * Fetching
2631
- * ********************
2632
- */
2633
- setFetcher(fetcher) {
2634
- this.unstable_fetcher = fetcher.bind(this);
2635
- return this;
2636
- }
2637
- fetch(request, requestId) {
2638
- return __async(this, null, function* () {
2639
- let startTime;
2640
- const execute = (resolve) => __async(this, null, function* () {
2641
- try {
2642
- if (!this.initialized) {
2643
- throw new RequestProcessingError(`Adapter ${this.options.name} is not initialized`);
2644
- }
2645
- if (!this.unstable_fetcher) {
2646
- throw new RequestProcessingError(`Fetcher for ${this.options.name} adapter is not set`);
2647
- }
2648
- this.client.triggerPlugins("onAdapterFetch", {
2649
- adapter: this,
2650
- request,
2651
- requestId
2652
- });
2653
- const bindings = yield getAdapterBindings({
2654
- request,
2655
- requestId,
2656
- resolve,
2657
- internalErrorMapping: this.unstable_internalErrorMapping,
2658
- onStartTime: (time) => {
2659
- startTime = time;
2660
- }
2661
- });
2662
- if (request.unstable_mock && request.isMockerEnabled && request.client.isMockerEnabled) {
2663
- return mocker(bindings);
2664
- }
2665
- return this.unstable_fetcher(bindings);
2666
- } catch (error) {
2667
- const onError = getAdapterOnError({
2668
- request,
2669
- requestId,
2670
- startTime: startTime || Date.now(),
2671
- logger: this.logger,
2672
- resolve
2673
- });
2674
- return onError({
2675
- error: this.unstable_internalErrorMapping(error),
2676
- status: this.options.systemErrorStatus,
2677
- extra: this.options.systemErrorExtra
2678
- });
2679
- }
2680
- });
2681
- const promise = new Promise((resolve) => {
2682
- execute(resolve);
2683
- });
2684
- return promise;
2685
- });
2686
- }
2687
- };
2688
-
2689
- // src/http-adapter/http-adapter.utils.ts
2690
- var getResponseHeaders = (headersString) => {
2691
- const arr = headersString.trim().split(/[\r\n]+/);
2692
- const headers = {};
2693
- arr.forEach((line) => {
2694
- const parts = line.split(": ");
2695
- const header = parts.shift();
2696
- const value = parts.join(": ");
2697
- if (header) {
2698
- headers[header] = value;
2699
- }
2700
- });
2701
- return headers;
2702
- };
2703
- var parseResponse = (response) => {
2704
- try {
2705
- return JSON.parse(response);
2706
- } catch (err) {
2707
- return response;
2708
- }
2709
- };
2710
- var handleResponse = (responseChunks, responseType, responseEncoding) => {
2711
- const bufferedResponse = Buffer.concat(responseChunks);
2712
- switch (responseType) {
2713
- case "arraybuffer":
2714
- return bufferedResponse;
2715
- case "json":
2716
- return parseResponse(bufferedResponse.toString(responseEncoding));
2717
- default:
2718
- return bufferedResponse.toString(responseEncoding);
2719
- }
2720
- };
2721
- var parseErrorResponse = (response) => {
2722
- return response ? parseResponse(response) : getErrorMessage();
2723
- };
2724
- var isValidValue = (options) => {
2725
- return (value) => {
2726
- const { skipNull, skipEmptyString } = options;
2727
- if (skipEmptyString && value === void 0) {
2728
- return false;
2729
- }
2730
- if (skipEmptyString && value === "") {
2731
- return false;
2732
- }
2733
- if (skipNull && value === null) {
2734
- return false;
2735
- }
2736
- return true;
2737
- };
2738
- };
2739
- var encodeValue = (value, { encode, strict }) => {
2740
- if (encode && strict) {
2741
- return encodeURIComponent(value).replace(/[!'()*]/g, (s) => `%${s.charCodeAt(0).toString(16).toUpperCase()}`);
2742
- }
2743
- if (encode) {
2744
- return encodeURIComponent(value);
2745
- }
2746
- return value;
2747
- };
2748
- var encodeParams = (key, value, options) => {
2749
- const shouldSkip = !isValidValue(options)(value);
2750
- if (!key || shouldSkip) {
2751
- return "";
2752
- }
2753
- const parsedValue = () => {
2754
- var _a, _b;
2755
- if (value instanceof Date) {
2756
- return ((_a = options.dateParser) == null ? void 0 : _a.call(options, value)) || value.toISOString();
2757
- }
2758
- if (typeof value === "object" && !Array.isArray(value)) {
2759
- return ((_b = options.objectParser) == null ? void 0 : _b.call(options, value)) || JSON.stringify(value);
2760
- }
2761
- return String(value);
2762
- };
2763
- return `${encodeValue(key, options)}=${encodeValue(parsedValue(), options)}`;
2764
- };
2765
- var encodeArray = (key, array, options) => {
2766
- const { arrayFormat, arraySeparator } = options;
2767
- return array.filter(isValidValue(options)).reduce((acc, value, index) => {
2768
- switch (arrayFormat) {
2769
- case "index": {
2770
- const keyValue = `${encodeValue(key, options)}[${encodeValue(String(index), options)}]=`;
2771
- acc.push(`${keyValue}${encodeValue(String(value), options)}`);
2772
- break;
2773
- }
2774
- case "bracket": {
2775
- const keyValue = `${encodeValue(key, options)}[]=`;
2776
- acc.push(`${keyValue}${encodeValue(String(value), options)}`);
2777
- break;
2778
- }
2779
- case "comma": {
2780
- const keyValue = !acc.length && `${encodeValue(key, options)}=` || "";
2781
- return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(",")];
2782
- }
2783
- case "separator": {
2784
- const keyValue = !acc.length && `${encodeValue(key, options)}=` || "";
2785
- return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
2786
- }
2787
- case "bracket-separator": {
2788
- const keyValue = !acc.length && `${encodeValue(key, options)}[]=` || "";
2789
- return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
2790
- }
2791
- default: {
2792
- const keyValue = `${encodeValue(key, options)}=`;
2793
- acc.push(`${keyValue}${encodeValue(String(value), options)}`);
2794
- }
2795
- }
2796
- return acc;
2797
- }, []).join("&");
2798
- };
2799
- var stringifyQueryParams = (queryParams, options = stringifyDefaultOptions) => {
2800
- if (!queryParams || !Object.keys(queryParams).length) {
2801
- return "";
2802
- }
2803
- if (typeof queryParams === "string") {
2804
- const hasQuestionMark = queryParams[0] === "?";
2805
- return hasQuestionMark ? queryParams : `?${queryParams}`;
2806
- }
2807
- const stringified = Object.entries(queryParams).map(([key, value]) => {
2808
- if (Array.isArray(value)) {
2809
- return encodeArray(key, value, options);
2810
- }
2811
- return encodeParams(key, value, options);
2812
- }).filter(Boolean).join("&");
2813
- if (stringified) {
2814
- return `?${stringified}`;
2815
- }
2816
- return "";
2817
- };
2818
-
2819
- // src/http-adapter/http-adapter.constants.ts
2820
- var defaultTimeout = 1e3 /* SEC */ * 5;
2821
- var xhrExtra = {
2822
- headers: {}
2823
- };
2824
-
2825
- // src/http-adapter/http-adapter.browser.ts
2826
- var getAdapter = () => new Adapter({
2827
- name: "http-browser",
2828
- defaultMethod: "GET" /* GET */,
2829
- defaultExtra: xhrExtra,
2830
- systemErrorStatus: 0,
2831
- systemErrorExtra: xhrExtra
2832
- }).setQueryParamsMapper(stringifyQueryParams).setFetcher(
2833
- (_0) => __async(null, [_0], function* ({
2834
- request,
2835
- adapterOptions,
2836
- headers,
2837
- payload,
2838
- onError,
2839
- onResponseEnd,
2840
- onTimeoutError,
2841
- onRequestEnd,
2842
- createAbortListener,
2843
- onResponseProgress,
2844
- onResponseStart,
2845
- onBeforeRequest,
2846
- onRequestStart,
2847
- onRequestProgress,
2848
- onSuccess
2849
- }) {
2850
- const { method, client, endpoint, queryParams } = request;
2851
- const queryString = queryParams ? stringifyQueryParams(queryParams) : "";
2852
- const fullUrl = `${client.url}${endpoint}${queryString}`;
2853
- const xhr = new XMLHttpRequest();
2854
- xhr.timeout = defaultTimeout;
2855
- const onAbort = () => xhr.abort();
2856
- if (adapterOptions) {
2857
- Object.entries(adapterOptions).forEach(([name, value]) => {
2858
- xhr[name] = value;
2859
- });
2860
- }
2861
- xhr.open(method, fullUrl, true);
2862
- Object.entries(headers).forEach(([name, value]) => xhr.setRequestHeader(name, value));
2863
- const unmountListener = createAbortListener({ status: 0, extra: xhrExtra, onAbort });
2864
- xhr.upload.onprogress = onRequestProgress;
2865
- xhr.onloadstart = () => {
2866
- onRequestEnd();
2867
- onResponseStart();
2868
- };
2869
- xhr.onprogress = onResponseProgress;
2870
- xhr.onloadend = () => {
2871
- onResponseEnd();
2872
- unmountListener();
2873
- };
2874
- xhr.ontimeout = () => onTimeoutError({ status: 0, extra: xhrExtra });
2875
- xhr.onreadystatechange = (e) => {
2876
- const event = e;
2877
- const finishedState = 4;
2878
- if (event.target && event.target.readyState === finishedState) {
2879
- const { status } = event.target;
2880
- const success = String(status).startsWith("2") || String(status).startsWith("3");
2881
- const responseHeaders = getResponseHeaders(xhr.getAllResponseHeaders());
2882
- if (success) {
2883
- const data = parseResponse(event.target.response);
2884
- onSuccess({ data, status, extra: { headers: responseHeaders } });
2885
- } else {
2886
- const error = parseErrorResponse(event.target.response);
2887
- onError({ error, status, extra: { headers: responseHeaders } });
2888
- }
2889
- }
2890
- };
2891
- onBeforeRequest();
2892
- onRequestStart();
2893
- xhr.send(payload);
2894
- })
2895
- );
2896
-
2897
- // src/http-adapter/http-adapter.ts
2898
- var HttpAdapter = () => {
2899
- if (typeof XMLHttpRequest !== "undefined") {
2900
- return getAdapter();
2901
- }
2902
- return getAdapter();
2903
- };
2904
-
2905
- // src/cache/cache.ts
2906
- var Cache = class {
2907
- constructor(options) {
2908
- this.options = options;
2909
- __publicField(this, "emitter", new EventEmitter());
2910
- __publicField(this, "events");
2911
- __publicField(this, "storage");
2912
- __publicField(this, "lazyStorage");
2913
- __publicField(this, "version");
2914
- __publicField(this, "garbageCollectors", /* @__PURE__ */ new Map());
2915
- __publicField(this, "logger");
2916
- __publicField(this, "client");
2917
- __publicField(this, "initialize", (client) => {
2918
- this.client = client;
2919
- this.logger = client.loggerManager.initialize(client, "Cache");
2920
- client.appManager.events.onOnline(() => {
2921
- [...this.storage.keys()].forEach(this.scheduleGarbageCollector);
2922
- });
2923
- [...this.storage.keys()].forEach(this.scheduleGarbageCollector);
2924
- return this;
2925
- });
2926
- /**
2927
- * Set the cache data to the storage
2928
- * @param request
2929
- * @param response
2930
- * @returns
2931
- */
2932
- __publicField(this, "set", (request, response) => {
2933
- var _a;
2934
- this.logger.debug({ title: "Processing cache response", type: "system", extra: { request, response } });
2935
- const { cacheKey, cache, staleTime, cacheTime } = request;
2936
- const previousCacheData = this.storage.get(cacheKey);
2937
- const processedResponse = typeof response === "function" ? response(previousCacheData || null) : response;
2938
- const data = getCacheData(previousCacheData, processedResponse);
2939
- const newCacheData = __spreadProps(__spreadValues({}, data), {
2940
- staleTime,
2941
- version: this.version,
2942
- cacheKey,
2943
- cacheTime,
2944
- cached: !!request.cache
2945
- });
2946
- if (processedResponse.success && cache) {
2947
- this.logger.debug({ title: "Saving response to cache storage", type: "system", extra: { request, data } });
2948
- this.storage.set(cacheKey, newCacheData);
2949
- (_a = this.lazyStorage) == null ? void 0 : _a.set(cacheKey, newCacheData);
2950
- this.client.triggerPlugins("onCacheItemChange", {
2951
- cache: this,
2952
- cacheKey,
2953
- prevData: previousCacheData || null,
2954
- newData: newCacheData
2955
- });
2956
- this.scheduleGarbageCollector(cacheKey);
2957
- } else {
2958
- this.logger.debug({ title: "Prevented saving response to cache", type: "system", extra: { request, data } });
2959
- }
2960
- this.logger.debug({ title: "Emitting cache response", type: "system", extra: { request, data } });
2961
- this.events.emitCacheData(
2962
- newCacheData
2963
- );
2964
- });
2965
- /**
2966
- * Update the cache data with partial response data
2967
- * @param request
2968
- * @param partialResponse
2969
- * @param isTriggeredExtrenally - informs whether an update was triggered due to internal logic or externally, e.g.
2970
- * via plugin.
2971
- * @returns
2972
- */
2973
- __publicField(this, "update", (request, partialResponse) => {
2974
- this.logger.debug({ title: "Processing cache update", type: "system", extra: { request, partialResponse } });
2975
- const { cacheKey } = request;
2976
- const cachedData = this.storage.get(cacheKey);
2977
- const processedResponse = typeof partialResponse === "function" ? partialResponse(cachedData || null) : partialResponse;
2978
- if (cachedData) {
2979
- this.set(request, __spreadValues(__spreadValues({}, cachedData), processedResponse));
2980
- }
2981
- });
2982
- /**
2983
- * Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.
2984
- * @param cacheKey
2985
- * @returns
2986
- */
2987
- __publicField(this, "get", (cacheKey) => {
2988
- this.getLazyResource(cacheKey);
2989
- const cachedData = this.storage.get(cacheKey);
2990
- return cachedData;
2991
- });
2992
- /**
2993
- * Get sync storage keys, lazyStorage keys will not be included
2994
- * @returns
2995
- */
2996
- __publicField(this, "keys", () => {
2997
- const values = this.storage.keys();
2998
- return Array.from(values);
2999
- });
3000
- /**
3001
- * Delete record from storages and trigger invalidation event
3002
- * @param cacheKey
3003
- */
3004
- __publicField(this, "delete", (cacheKey) => {
3005
- var _a;
3006
- this.logger.debug({ title: "Deleting cache element", type: "system", extra: { cacheKey } });
3007
- this.storage.delete(cacheKey);
3008
- (_a = this.lazyStorage) == null ? void 0 : _a.delete(cacheKey);
3009
- this.client.triggerPlugins("onCacheItemDelete", {
3010
- cache: this,
3011
- cacheKey
3012
- });
3013
- this.events.emitDelete(cacheKey);
3014
- });
3015
- /**
3016
- * Invalidate cache by cacheKey or partial matching with RegExp
3017
- * It emits invalidation event for each matching cacheKey and sets staleTime to 0 to indicate out of time cache
3018
- * @param key - cacheKey or Request instance or RegExp for partial matching
3019
- */
3020
- __publicField(this, "invalidate", (cacheKeys) => {
3021
- this.logger.debug({ title: "Revalidating cache element", type: "system", extra: { cacheKeys } });
3022
- const onInvalidate = (key) => {
3023
- const keys = Array.from(this.storage.keys());
3024
- const handleInvalidation = (cacheKey) => {
3025
- const value = this.storage.get(cacheKey);
3026
- if (value) {
3027
- this.storage.set(cacheKey, __spreadProps(__spreadValues({}, value), { staleTime: 0 }));
3028
- }
3029
- this.client.triggerPlugins("onCacheItemInvalidate", {
3030
- cache: this,
3031
- cacheKey
3032
- });
3033
- this.events.emitInvalidation(cacheKey);
3034
- };
3035
- if (key instanceof Request) {
3036
- handleInvalidation(key.cacheKey);
3037
- } else if (typeof key === "string") {
3038
- handleInvalidation(key);
3039
- } else if (keys.length) {
3040
- keys.forEach((entityKey) => {
3041
- if (key.test(entityKey)) {
3042
- handleInvalidation(entityKey);
3043
- }
3044
- });
3045
- }
3046
- };
3047
- if (Array.isArray(cacheKeys)) {
3048
- cacheKeys.forEach(onInvalidate.bind(this));
3049
- } else {
3050
- onInvalidate.bind(this)(cacheKeys);
3051
- }
3052
- });
3053
- /**
3054
- * Used to receive data from lazy storage
3055
- * @param cacheKey
3056
- */
3057
- __publicField(this, "getLazyResource", (cacheKey) => __async(this, null, function* () {
3058
- var _a, _b;
3059
- const data = yield (_a = this.lazyStorage) == null ? void 0 : _a.get(cacheKey);
3060
- const syncData = this.storage.get(cacheKey);
3061
- const hasLazyData = this.lazyStorage && data;
3062
- if (hasLazyData) {
3063
- const now = +/* @__PURE__ */ new Date();
3064
- const isNewestData = syncData ? syncData.responseTimestamp < data.responseTimestamp : true;
3065
- const isStaleData = data.staleTime <= now - data.responseTimestamp;
3066
- const isValidLazyData = data.version === this.version;
3067
- if (!isValidLazyData) {
3068
- (_b = this.lazyStorage) == null ? void 0 : _b.delete(cacheKey);
3069
- }
3070
- if (isNewestData && !isStaleData && isValidLazyData) {
3071
- this.storage.set(cacheKey, data);
3072
- this.events.emitCacheData(__spreadProps(__spreadValues({}, data), { cacheKey, cached: true }));
3073
- return data;
3074
- }
3075
- }
3076
- const isValidData = (syncData == null ? void 0 : syncData.version) === this.version;
3077
- if (syncData && !isValidData) {
3078
- this.delete(cacheKey);
3079
- }
3080
- return syncData;
3081
- }));
3082
- /**
3083
- * Used to receive keys from sync storage and lazy storage
3084
- * @param cacheKey
3085
- */
3086
- __publicField(this, "getLazyKeys", () => __async(this, null, function* () {
3087
- var _a;
3088
- const keys = (yield (_a = this.lazyStorage) == null ? void 0 : _a.keys()) || [];
3089
- return [...new Set(keys)];
3090
- }));
3091
- /**
3092
- * Used to receive keys from sync storage and lazy storage
3093
- * @param cacheKey
3094
- */
3095
- __publicField(this, "getAllKeys", () => __async(this, null, function* () {
3096
- var _a;
3097
- const keys = yield (_a = this.lazyStorage) == null ? void 0 : _a.keys();
3098
- const asyncKeys = Array.from(keys || []);
3099
- const syncKeys = Array.from(this.storage.keys());
3100
- return [.../* @__PURE__ */ new Set([...asyncKeys, ...syncKeys])];
3101
- }));
3102
- /**
3103
- * Schedule garbage collection for given key
3104
- * @param cacheKey
3105
- * @returns
3106
- */
3107
- __publicField(this, "scheduleGarbageCollector", (cacheKey) => {
3108
- const cacheData = this.storage.get(cacheKey);
3109
- clearTimeout(this.garbageCollectors.get(cacheKey));
3110
- if (cacheData) {
3111
- const timeLeft = cacheData.cacheTime + cacheData.responseTimestamp - +/* @__PURE__ */ new Date();
3112
- if (cacheData.cacheTime === null) {
3113
- this.logger.debug({ title: "Cache time is null", type: "system", extra: { cacheKey } });
3114
- } else if (cacheData.cacheTime !== null && JSON.stringify(cacheData.cacheTime) === "null" || cacheData.cacheTime === Infinity) {
3115
- this.logger.debug({ title: "Cache time is Infinite", type: "system", extra: { cacheKey } });
3116
- } else if (timeLeft >= 0) {
3117
- this.garbageCollectors.set(
3118
- cacheKey,
3119
- setTimeout(() => {
3120
- if (this.client.appManager.isOnline) {
3121
- this.logger.info({ title: "Garbage collecting cache data", type: "system", extra: { cacheKey } });
3122
- this.delete(cacheKey);
3123
- }
3124
- }, timeLeft)
3125
- );
3126
- } else if (this.client.appManager.isOnline) {
3127
- this.logger.info({ title: "Garbage collecting cache data", type: "system", extra: { cacheKey } });
3128
- this.delete(cacheKey);
3129
- }
3130
- }
3131
- });
3132
- /**
3133
- * Clear cache storages
3134
- */
3135
- __publicField(this, "clear", () => __async(this, null, function* () {
3136
- this.garbageCollectors.forEach((timeout) => clearTimeout(timeout));
3137
- this.storage.clear();
3138
- }));
3139
- var _a;
3140
- const { storage = /* @__PURE__ */ new Map(), lazyStorage, version = "0.0.1" } = options != null ? options : {};
3141
- (_a = this.emitter) == null ? void 0 : _a.setMaxListeners(1e3);
3142
- this.events = getCacheEvents(this.emitter);
3143
- this.storage = storage;
3144
- this.version = version;
3145
- this.lazyStorage = lazyStorage;
3146
- }
3147
- };
3148
-
3149
- // src/cache/cache.utils.ts
3150
- var getCacheData = (previousResponse, response) => {
3151
- const { data, success } = response;
3152
- const previousData = !success && previousResponse ? previousResponse.data : null;
3153
- const computedData = data || previousData;
3154
- return __spreadProps(__spreadValues({}, response), { data: computedData });
3155
- };
3156
- var getInvalidateKey = () => {
3157
- return `invalidate`;
3158
- };
3159
- var getInvalidateByKey = (key) => {
3160
- return `${key}_invalidate`;
3161
- };
3162
- var getDeleteKey = () => {
3163
- return `delete`;
3164
- };
3165
- var getDeleteByKey = (key) => {
3166
- return `${key}_delete`;
3167
- };
3168
- var getCacheByKey = (key) => {
3169
- return `${key}_cache`;
3170
- };
3171
- var getCacheKey = () => {
3172
- return `cache`;
3173
- };
3174
-
3175
- // src/cache/cache.events.ts
3176
- var getCacheEvents = (emitter) => ({
3177
- /**
3178
- * Set cache data
3179
- * @param data
3180
- */
3181
- emitCacheData: (data, isTriggeredExternally = false) => {
3182
- emitter.emit(getCacheKey(), data, isTriggeredExternally);
3183
- emitter.emit(getCacheByKey(data.cacheKey), data, isTriggeredExternally);
3184
- },
3185
- /**
3186
- * Invalidate cache values event
3187
- */
3188
- emitInvalidation: (cacheKey, isTriggeredExternally = false) => {
3189
- emitter.emit(getInvalidateKey(), cacheKey, isTriggeredExternally);
3190
- emitter.emit(getInvalidateByKey(cacheKey), isTriggeredExternally);
3191
- },
3192
- /**
3193
- * Delete of cache values
3194
- */
3195
- emitDelete: (cacheKey, isTriggeredExternally = false) => {
3196
- emitter.emit(getDeleteKey(), cacheKey, isTriggeredExternally);
3197
- emitter.emit(getDeleteByKey(cacheKey), isTriggeredExternally);
3198
- },
3199
- /**
3200
- * Cache data listener
3201
- * @param callback
3202
- * @returns
3203
- */
3204
- onData: (callback) => {
3205
- emitter.on(getCacheKey(), callback);
3206
- return () => emitter.removeListener(getCacheKey(), callback);
3207
- },
3208
- /**
3209
- * Cache data listener
3210
- * @param cacheKey
3211
- * @param callback
3212
- * @returns
3213
- */
3214
- onDataByKey: (cacheKey, callback) => {
3215
- emitter.on(getCacheByKey(cacheKey), callback);
3216
- return () => emitter.removeListener(getCacheByKey(cacheKey), callback);
3217
- },
3218
- /**
3219
- * Cache invalidation listener
3220
- * @param callback
3221
- * @returns
3222
- */
3223
- onInvalidate: (callback) => {
3224
- emitter.on(getInvalidateKey(), callback);
3225
- return () => emitter.removeListener(getInvalidateKey(), callback);
3226
- },
3227
- /**
3228
- * Cache invalidation listener
3229
- * @param cacheKey
3230
- * @param callback
3231
- * @returns
3232
- */
3233
- onInvalidateByKey: (cacheKey, callback) => {
3234
- emitter.on(getInvalidateByKey(cacheKey), callback);
3235
- return () => emitter.removeListener(getInvalidateByKey(cacheKey), callback);
3236
- },
3237
- onDelete: (callback) => {
3238
- emitter.on(getDeleteKey(), callback);
3239
- return () => emitter.removeListener(getDeleteKey(), callback);
3240
- },
3241
- onDeleteByKey: (cacheKey, callback) => {
3242
- emitter.on(getDeleteByKey(cacheKey), callback);
3243
- return () => emitter.removeListener(getDeleteByKey(cacheKey), callback);
3244
- }
3245
- });
3246
-
3247
- // src/client/client.utils.ts
3248
- var interceptRequest = (interceptors, request) => __async(null, null, function* () {
3249
- let newRequest = request;
3250
- if (!request.requestOptions.disableRequestInterceptors) {
3251
- for (const interceptor of interceptors) {
3252
- newRequest = yield interceptor(request);
3253
- if (!newRequest) throw new Error("Request modifier must return request");
3254
- }
3255
- }
3256
- return newRequest;
3257
- });
3258
- var interceptResponse = (interceptors, response, request) => __async(null, null, function* () {
3259
- let newResponse = response;
3260
- if (!request.requestOptions.disableResponseInterceptors) {
3261
- for (const interceptor of interceptors) {
3262
- newResponse = yield interceptor(response, request);
3263
- if (!newResponse) throw new Error("Response modifier must return data");
3264
- }
3265
- }
3266
- return newResponse;
3267
- });
3268
-
3269
- // src/client/client.ts
3270
- var Client = class {
3271
- constructor(options) {
3272
- this.options = options;
3273
- __publicField(this, "url");
3274
- __publicField(this, "debug");
3275
- // Private
3276
- __publicField(this, "unstable_onErrorCallbacks", []);
3277
- __publicField(this, "unstable_onSuccessCallbacks", []);
3278
- __publicField(this, "unstable_onResponseCallbacks", []);
3279
- __publicField(this, "unstable_onAuthCallbacks", []);
3280
- __publicField(this, "unstable_onRequestCallbacks", []);
3281
- // Managers
3282
- __publicField(this, "loggerManager", new LoggerManager());
3283
- __publicField(this, "requestManager", new RequestManager());
3284
- __publicField(this, "appManager");
3285
- // Config
3286
- __publicField(this, "adapter");
3287
- __publicField(this, "cache");
3288
- __publicField(this, "fetchDispatcher");
3289
- __publicField(this, "submitDispatcher");
3290
- __publicField(this, "isMockerEnabled", true);
3291
- // Registered requests effect
3292
- __publicField(this, "plugins", []);
3293
- /** @internal */
3294
- __publicField(this, "unstable_abortKeyMapper", getSimpleKey);
3295
- /** @internal */
3296
- __publicField(this, "unstable_cacheKeyMapper", getRequestKey);
3297
- /** @internal */
3298
- __publicField(this, "unstable_queryKeyMapper", getRequestKey);
3299
- /** @internal */
3300
- __publicField(this, "unstable_requestIdMapper", getUniqueRequestId);
3301
- // Logger
3302
- __publicField(this, "logger", this.loggerManager.initialize(this, "Client"));
3303
- /**
3304
- * This method enables the logger usage and display the logs in console
3305
- */
3306
- __publicField(this, "setDebug", (enabled) => {
3307
- this.debug = enabled;
3308
- return this;
3309
- });
3310
- /**
3311
- * Set the logger severity of the messages displayed to the console
3312
- */
3313
- __publicField(this, "setLogLevel", (severity) => {
3314
- this.loggerManager.setSeverity(severity);
3315
- return this;
3316
- });
3317
- /**
3318
- * Set the new logger instance to the Client
3319
- */
3320
- __publicField(this, "setLogger", (callback) => {
3321
- this.loggerManager = callback(this);
3322
- this.loggerManager.initialize(this, "Client");
3323
- return this;
3324
- });
3325
- /**
3326
- * Set globally if mocking should be enabled or disabled for all client requests.
3327
- * @param isMockerEnabled
3328
- */
3329
- __publicField(this, "setEnableGlobalMocking", (isMockerEnabled) => {
3330
- this.isMockerEnabled = isMockerEnabled;
3331
- return this;
3332
- });
3333
- /**
3334
- * Set custom http adapter to handle graphql, rest, firebase or others
3335
- */
3336
- __publicField(this, "setAdapter", (adapter) => {
3337
- this.adapter = adapter;
3338
- this.adapter.initialize(this);
3339
- return this;
3340
- });
3341
- /**
3342
- * 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.
3343
- */
3344
- __publicField(this, "onAuth", (callback) => {
3345
- this.unstable_onAuthCallbacks.push(callback);
3346
- return this;
3347
- });
3348
- /**
3349
- * Method for removing listeners on auth.
3350
- * */
3351
- __publicField(this, "removeOnAuthInterceptors", (callbacks) => {
3352
- this.unstable_onAuthCallbacks = this.unstable_onAuthCallbacks.filter((callback) => !callbacks.includes(callback));
3353
- return this;
3354
- });
3355
- /**
3356
- * Method for intercepting error responses. It can be used for example to refresh tokens.
3357
- */
3358
- __publicField(this, "onError", (callback) => {
3359
- this.unstable_onErrorCallbacks.push(callback);
3360
- return this;
3361
- });
3362
- /**
3363
- * Method for removing listeners on error.
3364
- * */
3365
- __publicField(this, "removeOnErrorInterceptors", (callbacks) => {
3366
- this.unstable_onErrorCallbacks = this.unstable_onErrorCallbacks.filter((callback) => !callbacks.includes(callback));
3367
- return this;
3368
- });
3369
- /**
3370
- * Method for intercepting success responses.
3371
- */
3372
- __publicField(this, "onSuccess", (callback) => {
3373
- this.unstable_onSuccessCallbacks.push(callback);
3374
- return this;
3375
- });
3376
- /**
3377
- * Method for removing listeners on success.
3378
- * */
3379
- __publicField(this, "removeOnSuccessInterceptors", (callbacks) => {
3380
- this.unstable_onSuccessCallbacks = this.unstable_onSuccessCallbacks.filter(
3381
- (callback) => !callbacks.includes(callback)
3382
- );
3383
- return this;
3384
- });
3385
- /**
3386
- * Method of manipulating requests before sending the request.
3387
- */
3388
- __publicField(this, "onRequest", (callback) => {
3389
- this.unstable_onRequestCallbacks.push(callback);
3390
- return this;
3391
- });
3392
- /**
3393
- * Method for removing listeners on request.
3394
- * */
3395
- __publicField(this, "removeOnRequestInterceptors", (callbacks) => {
3396
- this.unstable_onRequestCallbacks = this.unstable_onRequestCallbacks.filter(
3397
- (callback) => !callbacks.includes(callback)
3398
- );
3399
- return this;
3400
- });
3401
- /**
3402
- * Method for intercepting any responses.
3403
- */
3404
- __publicField(this, "onResponse", (callback) => {
3405
- this.unstable_onResponseCallbacks.push(callback);
3406
- return this;
3407
- });
3408
- /**
3409
- * Method for removing listeners on request.
3410
- * */
3411
- __publicField(this, "removeOnResponseInterceptors", (callbacks) => {
3412
- this.unstable_onResponseCallbacks = this.unstable_onResponseCallbacks.filter(
3413
- (callback) => !callbacks.includes(callback)
3414
- );
3415
- return this;
3416
- });
3417
- /**
3418
- * Add persistent plugins which trigger on the request lifecycle
3419
- */
3420
- __publicField(this, "addPlugin", (plugin) => {
3421
- this.plugins.push(plugin);
3422
- plugin.initialize(this);
3423
- plugin.trigger("onMount", { client: this });
3424
- return this;
3425
- });
3426
- /**
3427
- * Remove plugins from Client
3428
- */
3429
- __publicField(this, "removePlugin", (plugin) => {
3430
- const pluginCount = this.plugins.length;
3431
- this.plugins = this.plugins.filter((p) => p !== plugin);
3432
- if (this.plugins.length !== pluginCount) {
3433
- plugin.trigger("onUnmount", { client: this });
3434
- }
3435
- return this;
3436
- });
3437
- __publicField(this, "triggerPlugins", (key, data) => {
3438
- if (!this.plugins.length) {
3439
- return this;
3440
- }
3441
- this.plugins.forEach((plugin) => {
3442
- plugin.trigger(key, data);
3443
- });
3444
- return this;
3445
- });
3446
- /**
3447
- * Key setters
3448
- */
3449
- __publicField(this, "setAbortKeyMapper", (callback) => {
3450
- this.unstable_abortKeyMapper = callback;
3451
- return this;
3452
- });
3453
- __publicField(this, "setCacheKeyMapper", (callback) => {
3454
- this.unstable_cacheKeyMapper = callback;
3455
- return this;
3456
- });
3457
- __publicField(this, "setQueryKeyMapper", (callback) => {
3458
- this.unstable_queryKeyMapper = callback;
3459
- return this;
3460
- });
3461
- __publicField(this, "setRequestIdMapper", (callback) => {
3462
- this.unstable_requestIdMapper = callback;
3463
- return this;
3464
- });
3465
- /**
3466
- * Helper used by http adapter to apply the modifications on response error
3467
- * @private
3468
- */
3469
- __publicField(this, "unstable_modifyAuth", (request) => __async(this, null, function* () {
3470
- return interceptRequest(this.unstable_onAuthCallbacks, request);
3471
- }));
3472
- /**
3473
- * Private helper to run async pre-request processing
3474
- * @private
3475
- */
3476
- __publicField(this, "unstable_modifyRequest", (request) => __async(this, null, function* () {
3477
- return interceptRequest(this.unstable_onRequestCallbacks, request);
3478
- }));
3479
- /**
3480
- * Private helper to run async on-error response processing
3481
- * @private
3482
- */
3483
- __publicField(this, "unstable_modifyErrorResponse", (response, request) => __async(this, null, function* () {
3484
- return interceptResponse(this.unstable_onErrorCallbacks, response, request);
3485
- }));
3486
- /**
3487
- * Private helper to run async on-success response processing
3488
- * @private
3489
- */
3490
- __publicField(this, "unstable_modifySuccessResponse", (response, request) => __async(this, null, function* () {
3491
- return interceptResponse(this.unstable_onSuccessCallbacks, response, request);
3492
- }));
3493
- /**
3494
- * Private helper to run async response processing
3495
- * @private
3496
- */
3497
- __publicField(this, "unstable_modifyResponse", (response, request) => __async(this, null, function* () {
3498
- return interceptResponse(this.unstable_onResponseCallbacks, response, request);
3499
- }));
3500
- /**
3501
- * Clears the Client instance and remove all listeners on it's dependencies
3502
- */
3503
- __publicField(this, "clear", () => {
3504
- const { appManager, cache, fetchDispatcher, submitDispatcher } = this.options;
3505
- this.requestManager.abortControllers.clear();
3506
- this.fetchDispatcher.clear();
3507
- this.submitDispatcher.clear();
3508
- this.cache.clear();
3509
- this.requestManager.emitter.removeAllListeners();
3510
- this.fetchDispatcher.emitter.removeAllListeners();
3511
- this.submitDispatcher.emitter.removeAllListeners();
3512
- this.cache.emitter.removeAllListeners();
3513
- this.cache = (cache == null ? void 0 : cache()) || new Cache();
3514
- this.appManager = (appManager == null ? void 0 : appManager()) || new AppManager();
3515
- this.fetchDispatcher = (fetchDispatcher == null ? void 0 : fetchDispatcher()) || new Dispatcher();
3516
- this.submitDispatcher = (submitDispatcher == null ? void 0 : submitDispatcher()) || new Dispatcher();
3517
- this.appManager.initialize();
3518
- this.cache.initialize(this);
3519
- this.fetchDispatcher.initialize(this);
3520
- this.submitDispatcher.initialize(this);
3521
- });
3522
- /**
3523
- * Hydrate your SSR cache data
3524
- * @param hydrationData
3525
- * @param options
3526
- */
3527
- __publicField(this, "hydrate", (hydrationData, options) => {
3528
- hydrationData == null ? void 0 : hydrationData.forEach((item) => {
3529
- if (!item) return;
3530
- const _a = item, { cacheKey, response } = _a, fallbackOptions = __objRest(_a, ["cacheKey", "response"]);
3531
- const defaults = {
3532
- cache: true,
3533
- override: true
3534
- };
3535
- const config = typeof options === "function" ? __spreadValues(__spreadValues(__spreadValues({}, defaults), fallbackOptions), options(item)) : __spreadValues(__spreadValues(__spreadValues({}, defaults), fallbackOptions), options);
3536
- if (!config.override) {
3537
- const cachedData = this.cache.get(cacheKey);
3538
- if (cachedData) {
3539
- return;
3540
- }
3541
- }
3542
- const parsedData = parseResponse(response);
3543
- this.cache.set(__spreadProps(__spreadValues({}, config), { cacheKey }), parsedData);
3544
- });
3545
- });
3546
- /**
3547
- * Create requests based on the Client setup
3548
- *
3549
- * @template Response Your response
3550
- */
3551
- __publicField(this, "createRequest", (_USE_DOUBLE_INITIALIZATION) => {
3552
- return (params) => {
3553
- const endpoint = this.adapter.unstable_endpointMapper(params.endpoint);
3554
- const mappedParams = __spreadProps(__spreadValues({}, params), {
3555
- endpoint: String(endpoint)
3556
- });
3557
- const request = new Request(this, mappedParams);
3558
- this.plugins.forEach((plugin) => plugin.trigger("onRequestCreate", { request }));
3559
- return request;
3560
- };
3561
- });
3562
- const { url, appManager, cache, fetchDispatcher, submitDispatcher } = this.options;
3563
- this.url = url;
3564
- this.adapter = HttpAdapter();
3565
- this.appManager = (appManager == null ? void 0 : appManager()) || new AppManager();
3566
- this.cache = (cache == null ? void 0 : cache()) || new Cache();
3567
- this.fetchDispatcher = (fetchDispatcher == null ? void 0 : fetchDispatcher()) || new Dispatcher();
3568
- this.submitDispatcher = (submitDispatcher == null ? void 0 : submitDispatcher()) || new Dispatcher();
3569
- this.adapter.initialize(this);
3570
- this.appManager.initialize();
3571
- this.cache.initialize(this);
3572
- this.fetchDispatcher.initialize(this);
3573
- this.submitDispatcher.initialize(this);
3574
- }
3575
- };
3576
-
3577
- // src/client/client.constants.ts
3578
- var stringifyDefaultOptions = {
3579
- strict: true,
3580
- encode: true,
3581
- arrayFormat: "bracket",
3582
- arraySeparator: "bracket",
3583
- sort: false,
3584
- skipNull: true,
3585
- skipEmptyString: true
3586
- };
3587
-
3588
- // src/client/client.create.ts
3589
- function createClient(options) {
3590
- return new Client(options);
3591
- }
3592
-
3593
- // src/sdk/sdk.ts
3594
- var getMethod = (key, options) => {
3595
- const { methodTransform = (method) => method.toUpperCase() } = options != null ? options : {};
3596
- return methodTransform(key);
3597
- };
3598
- var createRecursiveProxy = (client, path, options) => {
3599
- return new Proxy(() => {
3600
- }, {
3601
- get: (_target, key) => {
3602
- if (typeof key === "symbol" || key === "inspect") {
3603
- return void 0;
3604
- }
3605
- let isMethod = false;
3606
- let methodName = key;
3607
- let pathSegment = key;
3608
- if (key.startsWith("$")) {
3609
- isMethod = true;
3610
- methodName = key.slice(1);
3611
- pathSegment = `:${key.slice(1)}`;
3612
- } else if (options == null ? void 0 : options.camelCaseToKebabCase) {
3613
- pathSegment = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
3614
- }
3615
- const endpoint = `/${path.join("/")}`;
3616
- const method = getMethod(isMethod ? methodName : key, options);
3617
- const request = client.createRequest()({ endpoint, method });
3618
- const newPath = [...path, pathSegment];
3619
- const deeperProxy = createRecursiveProxy(client, newPath, options);
3620
- return new Proxy(request, {
3621
- get: (reqTarget, reqKey) => {
3622
- if (reqKey in reqTarget) {
3623
- return reqTarget[reqKey];
3624
- }
3625
- return deeperProxy[reqKey];
3626
- }
3627
- });
3628
- }
3629
- });
3630
- };
3631
- var createSdk = (client, options) => {
3632
- const _a = options != null ? options : {}, {
3633
- camelCaseToKebabCase = true,
3634
- methodTransform = (method) => method.toUpperCase()
3635
- } = _a, rest = __objRest(_a, [
3636
- "camelCaseToKebabCase",
3637
- "methodTransform"
3638
- ]);
3639
- return createRecursiveProxy(client, [], __spreadValues({ camelCaseToKebabCase, methodTransform }, rest));
3640
- };
3641
- export {
3642
- AbortError,
3643
- Adapter,
3644
- AppEvents,
3645
- AppManager,
3646
- Cache,
3647
- Client,
3648
- DeletedError,
3649
- Dispatcher,
3650
- DispatcherMode,
3651
- EventEmitter,
3652
- HttpAdapter,
3653
- HttpMethods,
3654
- LoggerManager,
3655
- Plugin,
3656
- Request,
3657
- RequestManager,
3658
- RequestProcessingError,
3659
- Time,
3660
- TimeoutError,
3661
- UnexpectedError,
3662
- appManagerInitialOptions,
3663
- canRetryRequest,
3664
- createClient,
3665
- createSdk,
3666
- defaultMapper,
3667
- defaultTimeout,
3668
- getAbortByAbortKey,
3669
- getAbortByIdKey,
3670
- getAbortKey,
3671
- getAdapterBindings,
3672
- getAdapterHeaders,
3673
- getAdapterOnError,
3674
- getAdapterPayload,
3675
- getAppManagerEvents,
3676
- getCacheByKey,
3677
- getCacheData,
3678
- getCacheEvents,
3679
- getCacheKey,
3680
- getDeleteByKey,
3681
- getDeleteKey,
3682
- getDispatcherChangeByKey,
3683
- getDispatcherChangeKey,
3684
- getDispatcherDrainedByKey,
3685
- getDispatcherDrainedKey,
3686
- getDispatcherEvents,
3687
- getDispatcherStatusByKey,
3688
- getDispatcherStatusKey,
3689
- getDownloadProgressByIdKey,
3690
- getDownloadProgressByQueryKey,
3691
- getDownloadProgressKey,
3692
- getErrorMessage,
3693
- getInvalidateByKey,
3694
- getInvalidateKey,
3695
- getIsEqualTimestamp,
3696
- getLoadingByCacheKey,
3697
- getLoadingByIdKey,
3698
- getLoadingByQueryKey,
3699
- getLoadingKey,
3700
- getProgressData,
3701
- getProgressValue,
3702
- getRemoveByIdKey,
3703
- getRemoveByQueryKey,
3704
- getRemoveKey,
3705
- getRequestDeduplicatedByCacheKey,
3706
- getRequestDeduplicatedByIdKey,
3707
- getRequestDeduplicatedByQueryKey,
3708
- getRequestDeduplicatedKey,
3709
- getRequestDispatcher,
3710
- getRequestEta,
3711
- getRequestKey,
3712
- getRequestManagerEvents,
3713
- getRequestStarByQueryKey,
3714
- getRequestStartByIdKey,
3715
- getRequestStartKey,
3716
- getRequestType,
3717
- getResponseByCacheKey,
3718
- getResponseByIdKey,
3719
- getResponseHeaders,
3720
- getResponseKey,
3721
- getResponseStartByIdKey,
3722
- getResponseStartByQueryKey,
3723
- getResponseStartKey,
3724
- getSimpleKey,
3725
- getTime,
3726
- getUniqueRequestId,
3727
- getUploadProgressByIdKey,
3728
- getUploadProgressByQueryKey,
3729
- getUploadProgressKey,
3730
- handleResponse,
3731
- hasDocument,
3732
- hasWindow,
3733
- interceptRequest,
3734
- interceptResponse,
3735
- logLevelOrder,
3736
- logger,
3737
- loggerColors,
3738
- loggerStyles,
3739
- mocker,
3740
- onDocumentEvent,
3741
- onWindowEvent,
3742
- parseErrorResponse,
3743
- parseResponse,
3744
- sendRequest,
3745
- stringifyDefaultOptions,
3746
- stringifyKey,
3747
- stringifyQueryParams,
3748
- stringifyValue,
3749
- xhrExtra
3750
- };
3751
- //# sourceMappingURL=index.js.map