@syzy/apphost 1.0.1 → 1.0.2

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 (213) hide show
  1. package/dist/App.js +83 -0
  2. package/dist/AppHostProvider.js +4 -0
  3. package/dist/AppHostRoutes.js +7 -0
  4. package/dist/api/image-api.js +45 -0
  5. package/dist/api/mapping-api.js +427 -0
  6. package/dist/bookingModule/components/AmenityForm.js +19 -0
  7. package/dist/bookingModule/components/BillingManagement.js +17 -0
  8. package/dist/bookingModule/components/CreateRoomForm.js +19 -0
  9. package/dist/bookingModule/components/ExtraRequirementForm.js +19 -0
  10. package/dist/bookingModule/components/ReservationForm.js +18 -0
  11. package/dist/bookingModule/components/RoomCategoryForm.js +19 -0
  12. package/dist/bookingModule/components/RoomCategoryPriceForm.js +20 -0
  13. package/dist/bookingModule/components/RoomExtraRequirementCapture.js +18 -0
  14. package/dist/bookingModule/components/RoomFacilityForm.js +19 -0
  15. package/dist/bookingModule/components/RoomReservationAction.js +18 -0
  16. package/dist/components/Home/Home.js +14 -0
  17. package/dist/components/Loader/Loader.js +5 -0
  18. package/dist/components/Login/Login.js +149 -0
  19. package/dist/components/Login/loginSchema.js +41 -0
  20. package/dist/components/Mappings/BranchMapping/Branch.js +135 -0
  21. package/dist/components/Mappings/BranchMapping/BranchTableColumns.js +21 -0
  22. package/dist/components/Mappings/BranchMapping/MappingFormBranchUser.js +150 -0
  23. package/dist/components/Mappings/BranchMapping/MappingTableColumns.js +29 -0
  24. package/dist/components/Mappings/BranchMapping/branchSchema.js +34 -0
  25. package/dist/components/Mappings/ComponentMapping/ComponentRoleMapping.js +98 -0
  26. package/dist/components/Mappings/ComponentMapping/componentRoleColumns.js +29 -0
  27. package/dist/components/Mappings/MappingForm/MappingForm.js +142 -0
  28. package/dist/components/Mappings/MappingForm/mappingSchema.js +32 -0
  29. package/dist/components/Mappings/RoleMapping/MappingFormUserRole.js +194 -0
  30. package/dist/components/Mappings/RoleMapping/UserRoleTableColumns.js +33 -0
  31. package/dist/components/NavBar/Sidebar.js +56 -0
  32. package/dist/components/ProfileForm/ProfileForm.js +190 -0
  33. package/dist/components/ProfileForm/ProfileList.js +33 -0
  34. package/dist/components/ProfileForm/profileColumns.js +67 -0
  35. package/dist/components/ProfileForm/profileSchema.js +50 -0
  36. package/dist/components/SettingsPage/SettingsPage.js +240 -0
  37. package/dist/components/api/settings-api.js +131 -0
  38. package/dist/components/common/Form/FormActionButtons.js +6 -0
  39. package/dist/components/common/Form/FormLabel.js +6 -0
  40. package/dist/components/common/ListTable/ListHeader.js +5 -0
  41. package/dist/components/common/ListTable/ListTable.js +31 -0
  42. package/dist/components/common/Modal/Modal.js +6 -0
  43. package/dist/config/EnvConfig.js +13 -0
  44. package/dist/config/amplifyConfig.js +45 -0
  45. package/dist/configureAppHost.js +5 -0
  46. package/dist/customGraphQL/customMutations.js +53 -0
  47. package/dist/customGraphQL/customQueries.js +104 -0
  48. package/dist/domain/input/input-types.js +1 -0
  49. package/dist/domain/model/BranchDto.js +8 -0
  50. package/dist/domain/model/ComponentMappingDto.js +19 -0
  51. package/dist/domain/model/MappingDto.js +16 -0
  52. package/dist/domain/model/PrefixDescriptionDto.js +13 -0
  53. package/dist/domain/model/ProfileDto.js +20 -0
  54. package/dist/domain/model/RoleMappingDto.js +19 -0
  55. package/dist/domain/model/SettingsDto.js +7 -0
  56. package/dist/domain/model/UserMappingDto.js +28 -0
  57. package/dist/domain/model/imageDto.js +1 -0
  58. package/dist/domain/type/EntityTypes.js +6 -0
  59. package/dist/domain/type/MappingOptions.js +1 -0
  60. package/dist/domain/type/MappingTypes.js +7 -0
  61. package/dist/domain/type/Nullable.js +1 -0
  62. package/dist/domain/type/ResettingPeriodOptions.js +8 -0
  63. package/dist/domain/type/RolesEnum.js +7 -0
  64. package/dist/domain/type/SelectType.js +1 -0
  65. package/dist/domain/type/StatusEnum.js +6 -0
  66. package/dist/domain/type/signUpOptions.js +4 -0
  67. package/dist/domain/type/statusOptions.js +4 -0
  68. package/dist/graphql/profileQueries.js +89 -0
  69. package/dist/hoc/withSyzyAuth.js +87 -0
  70. package/dist/hooks/useCurrentUser.js +6 -0
  71. package/dist/hooks/useDispatch.js +7 -0
  72. package/dist/hooks/usePermission.js +7 -0
  73. package/dist/index.js +3 -15
  74. package/dist/main.js +60 -0
  75. package/dist/services/Client.Service.js +96 -0
  76. package/dist/services/Storage-service.js +26 -0
  77. package/dist/services/navigationMenu.js +9 -0
  78. package/dist/static/constants.js +34 -0
  79. package/dist/store/AppAction.js +5 -0
  80. package/dist/store/AppContext.js +3 -0
  81. package/dist/store/AppContextType.js +6 -0
  82. package/dist/store/AppProvider.js +32 -0
  83. package/dist/store/HostedInContainerContext.js +11 -0
  84. package/dist/store/SesssionReducer.js +16 -0
  85. package/dist/types/App.d.ts +4 -0
  86. package/dist/types/AppHostProvider.d.ts +6 -0
  87. package/dist/types/AppHostRoutes.d.ts +1 -0
  88. package/dist/types/api/image-api.d.ts +8 -0
  89. package/dist/types/api/mapping-api.d.ts +80 -0
  90. package/dist/types/bookingModule/components/AmenityForm.d.ts +3 -0
  91. package/dist/types/bookingModule/components/BillingManagement.d.ts +3 -0
  92. package/dist/types/bookingModule/components/CreateRoomForm.d.ts +3 -0
  93. package/dist/types/bookingModule/components/ExtraRequirementForm.d.ts +3 -0
  94. package/dist/types/bookingModule/components/ReservationForm.d.ts +3 -0
  95. package/dist/types/bookingModule/components/RoomCategoryForm.d.ts +3 -0
  96. package/dist/types/bookingModule/components/RoomCategoryPriceForm.d.ts +3 -0
  97. package/dist/types/bookingModule/components/RoomExtraRequirementCapture.d.ts +3 -0
  98. package/dist/types/bookingModule/components/RoomFacilityForm.d.ts +3 -0
  99. package/dist/types/bookingModule/components/RoomReservationAction.d.ts +3 -0
  100. package/dist/types/components/Home/Home.d.ts +3 -0
  101. package/dist/types/components/Loader/Loader.d.ts +2 -0
  102. package/dist/types/components/Login/Login.d.ts +7 -0
  103. package/dist/types/components/Login/loginSchema.d.ts +27 -0
  104. package/dist/types/components/Mappings/BranchMapping/Branch.d.ts +5 -0
  105. package/dist/types/components/Mappings/BranchMapping/BranchTableColumns.d.ts +10 -0
  106. package/dist/types/components/Mappings/BranchMapping/MappingFormBranchUser.d.ts +3 -0
  107. package/dist/types/components/Mappings/BranchMapping/MappingTableColumns.d.ts +14 -0
  108. package/dist/types/components/Mappings/BranchMapping/branchSchema.d.ts +37 -0
  109. package/dist/types/components/Mappings/ComponentMapping/ComponentRoleMapping.d.ts +3 -0
  110. package/dist/types/components/Mappings/ComponentMapping/componentRoleColumns.d.ts +3 -0
  111. package/dist/types/components/Mappings/MappingForm/MappingForm.d.ts +35 -0
  112. package/dist/types/components/Mappings/MappingForm/mappingSchema.d.ts +23 -0
  113. package/dist/types/components/Mappings/RoleMapping/MappingFormUserRole.d.ts +5 -0
  114. package/dist/types/components/Mappings/RoleMapping/UserRoleTableColumns.d.ts +3 -0
  115. package/dist/types/components/NavBar/Sidebar.d.ts +4 -0
  116. package/dist/types/components/ProfileForm/ProfileForm.d.ts +3 -0
  117. package/dist/types/components/ProfileForm/ProfileList.d.ts +3 -0
  118. package/dist/types/components/ProfileForm/profileColumns.d.ts +3 -0
  119. package/dist/types/components/ProfileForm/profileSchema.d.ts +52 -0
  120. package/dist/types/components/SettingsPage/SettingsPage.d.ts +3 -0
  121. package/dist/types/components/api/settings-api.d.ts +26 -0
  122. package/dist/types/components/common/Form/FormActionButtons.d.ts +11 -0
  123. package/dist/types/components/common/Form/FormLabel.d.ts +8 -0
  124. package/dist/types/components/common/ListTable/ListHeader.d.ts +8 -0
  125. package/dist/types/components/common/ListTable/ListTable.d.ts +17 -0
  126. package/dist/types/components/common/Modal/Modal.d.ts +11 -0
  127. package/dist/types/config/EnvConfig.d.ts +13 -0
  128. package/dist/types/config/amplifyConfig.d.ts +1 -0
  129. package/dist/types/configureAppHost.d.ts +6 -0
  130. package/dist/types/customGraphQL/customMutations.d.ts +3 -0
  131. package/dist/types/customGraphQL/customQueries.d.ts +7 -0
  132. package/dist/types/domain/input/input-types.d.ts +47 -0
  133. package/dist/types/domain/model/BranchDto.d.ts +9 -0
  134. package/dist/types/domain/model/ComponentMappingDto.d.ts +24 -0
  135. package/dist/types/domain/model/MappingDto.d.ts +30 -0
  136. package/dist/types/domain/model/PrefixDescriptionDto.d.ts +16 -0
  137. package/dist/types/domain/model/ProfileDto.d.ts +21 -0
  138. package/dist/types/domain/model/RoleMappingDto.d.ts +14 -0
  139. package/dist/types/domain/model/SettingsDto.d.ts +8 -0
  140. package/dist/types/domain/model/UserMappingDto.d.ts +14 -0
  141. package/dist/types/domain/model/imageDto.d.ts +4 -0
  142. package/dist/types/domain/type/EntityTypes.d.ts +5 -0
  143. package/dist/types/domain/type/MappingOptions.d.ts +5 -0
  144. package/dist/types/domain/type/MappingTypes.d.ts +6 -0
  145. package/dist/types/domain/type/Nullable.d.ts +13 -0
  146. package/dist/types/domain/type/ResettingPeriodOptions.d.ts +2 -0
  147. package/dist/types/domain/type/RolesEnum.d.ts +6 -0
  148. package/dist/types/domain/type/SelectType.d.ts +16 -0
  149. package/dist/types/domain/type/StatusEnum.d.ts +5 -0
  150. package/dist/types/domain/type/signUpOptions.d.ts +2 -0
  151. package/dist/types/domain/type/statusOptions.d.ts +2 -0
  152. package/dist/types/graphql/profileQueries.d.ts +4 -0
  153. package/dist/types/hoc/withSyzyAuth.d.ts +2 -0
  154. package/dist/types/hooks/useCurrentUser.d.ts +3 -0
  155. package/dist/types/hooks/useDispatch.d.ts +3 -0
  156. package/dist/types/hooks/usePermission.d.ts +1 -0
  157. package/dist/types/index.d.ts +3 -0
  158. package/dist/types/main.d.ts +4 -0
  159. package/dist/types/services/Client.Service.d.ts +12 -0
  160. package/dist/types/services/Storage-service.d.ts +2 -0
  161. package/dist/types/services/navigationMenu.d.ts +1 -0
  162. package/dist/types/static/constants.d.ts +34 -0
  163. package/dist/types/store/AppAction.d.ts +11 -0
  164. package/dist/types/store/AppContext.d.ts +3 -0
  165. package/dist/types/store/AppContextType.d.ts +12 -0
  166. package/dist/types/store/AppProvider.d.ts +7 -0
  167. package/dist/types/store/HostedInContainerContext.d.ts +5 -0
  168. package/dist/types/store/SesssionReducer.d.ts +4 -0
  169. package/dist/types/types.d.ts +26 -0
  170. package/dist/types/util/AuthUtils.d.ts +1 -0
  171. package/dist/types/util/LogEnum.d.ts +6 -0
  172. package/dist/types/util/Logger.d.ts +6 -0
  173. package/dist/types/util/SyzyDate.d.ts +69 -0
  174. package/dist/types/util/dateUtils.d.ts +10 -0
  175. package/dist/types/util/hostedinContainer.d.ts +1 -0
  176. package/dist/types/util/model-types.d.ts +96 -0
  177. package/dist/types/util/prefixAndResettingValidation.d.ts +9 -0
  178. package/dist/types/util/transformToData.d.ts +1 -0
  179. package/dist/types.js +14 -0
  180. package/dist/util/AuthUtils.js +10 -0
  181. package/dist/util/LogEnum.js +7 -0
  182. package/dist/util/Logger.js +18 -0
  183. package/dist/util/SyzyDate.js +265 -0
  184. package/dist/util/dateUtils.js +24 -0
  185. package/dist/util/hostedinContainer.js +9 -0
  186. package/dist/util/model-types.js +18 -0
  187. package/dist/util/prefixAndResettingValidation.js +54 -0
  188. package/dist/util/transformToData.js +9 -0
  189. package/package.json +14 -9
  190. package/dist/__federation_shared_@tanstack/react-query-DHuUsaNz.js +0 -2517
  191. package/dist/__federation_shared_react-CikWE6qG.js +0 -7
  192. package/dist/__federation_shared_react-bootstrap-BKlZRvMR.js +0 -7516
  193. package/dist/__federation_shared_react-dom-vrQ70Ay8.js +0 -372
  194. package/dist/__federation_shared_react-router-dom-BKminmS4.js +0 -10448
  195. package/dist/__federation_shared_react-select-B6kehBDI.js +0 -4056
  196. package/dist/__federation_shared_react-toastify-B0S0UGr3.js +0 -412
  197. package/dist/_commonjsHelpers-C6fGbg64.js +0 -6
  198. package/dist/_virtual___federation_fn_import-XZCKozko.js +0 -217
  199. package/dist/favicon.ico +0 -0
  200. package/dist/index-DgtWMtjZ.js +0 -184
  201. package/dist/index-eZknuYwc.js +0 -1219
  202. package/dist/jsx-runtime-D_t4bG-_.js +0 -264
  203. package/dist/manifest.webmanifest +0 -1
  204. package/dist/pwa/Hotel-icon.jpg +0 -0
  205. package/dist/pwa/apple-touch-icon-180x180.png +0 -0
  206. package/dist/pwa/favicon.ico +0 -0
  207. package/dist/pwa/maskable-icon-512x512.png +0 -0
  208. package/dist/pwa/pwa-192x192.png +0 -0
  209. package/dist/pwa/pwa-512x512.png +0 -0
  210. package/dist/pwa/pwa-64x64.png +0 -0
  211. package/dist/registerSW.js +0 -1
  212. package/dist/sw.js +0 -1
  213. package/dist/workbox-1ef09536.js +0 -1
@@ -1,2517 +0,0 @@
1
- import { i as C } from "../_virtual___federation_fn_import-XZCKozko.js";
2
- import { j as Et } from "../jsx-runtime-D_t4bG-_.js";
3
- var x = class {
4
- constructor() {
5
- this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
6
- }
7
- subscribe(t) {
8
- return this.listeners.add(t), this.onSubscribe(), () => {
9
- this.listeners.delete(t), this.onUnsubscribe();
10
- };
11
- }
12
- hasListeners() {
13
- return this.listeners.size > 0;
14
- }
15
- onSubscribe() {
16
- }
17
- onUnsubscribe() {
18
- }
19
- }, Wt = {
20
- // We need the wrapper function syntax below instead of direct references to
21
- // global setTimeout etc.
22
- //
23
- // BAD: `setTimeout: setTimeout`
24
- // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
25
- //
26
- // If we use direct references here, then anything that wants to spy on or
27
- // replace the global setTimeout (like tests) won't work since we'll already
28
- // have a hard reference to the original implementation at the time when this
29
- // file was imported.
30
- setTimeout: (t, e) => setTimeout(t, e),
31
- clearTimeout: (t) => clearTimeout(t),
32
- setInterval: (t, e) => setInterval(t, e),
33
- clearInterval: (t) => clearInterval(t)
34
- }, Jt = class {
35
- // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
36
- // type at app boot; and if we leave that type, then any new timer provider
37
- // would need to support ReturnType<typeof setTimeout>, which is infeasible.
38
- //
39
- // We settle for type safety for the TimeoutProvider type, and accept that
40
- // this class is unsafe internally to allow for extension.
41
- #e = Wt;
42
- #t = !1;
43
- setTimeoutProvider(t) {
44
- process.env.NODE_ENV !== "production" && this.#t && t !== this.#e && console.error(
45
- "[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",
46
- { previous: this.#e, provider: t }
47
- ), this.#e = t, process.env.NODE_ENV !== "production" && (this.#t = !1);
48
- }
49
- setTimeout(t, e) {
50
- return process.env.NODE_ENV !== "production" && (this.#t = !0), this.#e.setTimeout(t, e);
51
- }
52
- clearTimeout(t) {
53
- this.#e.clearTimeout(t);
54
- }
55
- setInterval(t, e) {
56
- return process.env.NODE_ENV !== "production" && (this.#t = !0), this.#e.setInterval(t, e);
57
- }
58
- clearInterval(t) {
59
- this.#e.clearInterval(t);
60
- }
61
- }, D = new Jt();
62
- function Zt(t) {
63
- setTimeout(t, 0);
64
- }
65
- var q = typeof window > "u" || "Deno" in globalThis;
66
- function b() {
67
- }
68
- function Xt(t, e) {
69
- return typeof t == "function" ? t(e) : t;
70
- }
71
- function tt(t) {
72
- return typeof t == "number" && t >= 0 && t !== 1 / 0;
73
- }
74
- function Ct(t, e) {
75
- return Math.max(t + (e || 0) - Date.now(), 0);
76
- }
77
- function M(t, e) {
78
- return typeof t == "function" ? t(e) : t;
79
- }
80
- function S(t, e) {
81
- return typeof t == "function" ? t(e) : t;
82
- }
83
- function dt(t, e) {
84
- const {
85
- type: s = "all",
86
- exact: r,
87
- fetchStatus: i,
88
- predicate: n,
89
- queryKey: o,
90
- stale: a
91
- } = t;
92
- if (o) {
93
- if (r) {
94
- if (e.queryHash !== ot(o, e.options))
95
- return !1;
96
- } else if (!_(e.queryKey, o))
97
- return !1;
98
- }
99
- if (s !== "all") {
100
- const u = e.isActive();
101
- if (s === "active" && !u || s === "inactive" && u)
102
- return !1;
103
- }
104
- return !(typeof a == "boolean" && e.isStale() !== a || i && i !== e.state.fetchStatus || n && !n(e));
105
- }
106
- function pt(t, e) {
107
- const { exact: s, status: r, predicate: i, mutationKey: n } = t;
108
- if (n) {
109
- if (!e.options.mutationKey)
110
- return !1;
111
- if (s) {
112
- if (T(e.options.mutationKey) !== T(n))
113
- return !1;
114
- } else if (!_(e.options.mutationKey, n))
115
- return !1;
116
- }
117
- return !(r && e.state.status !== r || i && !i(e));
118
- }
119
- function ot(t, e) {
120
- return (e?.queryKeyHashFn || T)(t);
121
- }
122
- function T(t) {
123
- return JSON.stringify(
124
- t,
125
- (e, s) => et(s) ? Object.keys(s).sort().reduce((r, i) => (r[i] = s[i], r), {}) : s
126
- );
127
- }
128
- function _(t, e) {
129
- return t === e ? !0 : typeof t != typeof e ? !1 : t && e && typeof t == "object" && typeof e == "object" ? Object.keys(e).every((s) => _(t[s], e[s])) : !1;
130
- }
131
- var Yt = Object.prototype.hasOwnProperty;
132
- function K(t, e) {
133
- if (t === e)
134
- return t;
135
- const s = yt(t) && yt(e);
136
- if (!s && !(et(t) && et(e))) return e;
137
- const i = (s ? t : Object.keys(t)).length, n = s ? e : Object.keys(e), o = n.length, a = s ? new Array(o) : {};
138
- let u = 0;
139
- for (let h = 0; h < o; h++) {
140
- const c = s ? h : n[h], d = t[c], l = e[c];
141
- if (d === l) {
142
- a[c] = d, (s ? h < i : Yt.call(t, c)) && u++;
143
- continue;
144
- }
145
- if (d === null || l === null || typeof d != "object" || typeof l != "object") {
146
- a[c] = l;
147
- continue;
148
- }
149
- const m = K(d, l);
150
- a[c] = m, m === d && u++;
151
- }
152
- return i === o && u === i ? t : a;
153
- }
154
- function H(t, e) {
155
- if (!e || Object.keys(t).length !== Object.keys(e).length)
156
- return !1;
157
- for (const s in t)
158
- if (t[s] !== e[s])
159
- return !1;
160
- return !0;
161
- }
162
- function yt(t) {
163
- return Array.isArray(t) && t.length === Object.keys(t).length;
164
- }
165
- function et(t) {
166
- if (!vt(t))
167
- return !1;
168
- const e = t.constructor;
169
- if (e === void 0)
170
- return !0;
171
- const s = e.prototype;
172
- return !(!vt(s) || !s.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(t) !== Object.prototype);
173
- }
174
- function vt(t) {
175
- return Object.prototype.toString.call(t) === "[object Object]";
176
- }
177
- function te(t) {
178
- return new Promise((e) => {
179
- D.setTimeout(e, t);
180
- });
181
- }
182
- function st(t, e, s) {
183
- if (typeof s.structuralSharing == "function")
184
- return s.structuralSharing(t, e);
185
- if (s.structuralSharing !== !1) {
186
- if (process.env.NODE_ENV !== "production")
187
- try {
188
- return K(t, e);
189
- } catch (r) {
190
- throw console.error(
191
- `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${s.queryHash}]: ${r}`
192
- ), r;
193
- }
194
- return K(t, e);
195
- }
196
- return e;
197
- }
198
- function Me(t) {
199
- return t;
200
- }
201
- function Pt(t, e, s = 0) {
202
- const r = [...t, e];
203
- return s && r.length > s ? r.slice(1) : r;
204
- }
205
- function ee(t, e, s = 0) {
206
- const r = [e, ...t];
207
- return s && r.length > s ? r.slice(0, -1) : r;
208
- }
209
- var I = Symbol();
210
- function Qt(t, e) {
211
- return process.env.NODE_ENV !== "production" && t.queryFn === I && console.error(
212
- `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${t.queryHash}'`
213
- ), !t.queryFn && e?.initialPromise ? () => e.initialPromise : !t.queryFn || t.queryFn === I ? () => Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)) : t.queryFn;
214
- }
215
- function Ft(t, e) {
216
- return typeof t == "function" ? t(...e) : !!t;
217
- }
218
- var se = class extends x {
219
- #e;
220
- #t;
221
- #s;
222
- constructor() {
223
- super(), this.#s = (t) => {
224
- if (!q && window.addEventListener) {
225
- const e = () => t();
226
- return window.addEventListener("visibilitychange", e, !1), () => {
227
- window.removeEventListener("visibilitychange", e);
228
- };
229
- }
230
- };
231
- }
232
- onSubscribe() {
233
- this.#t || this.setEventListener(this.#s);
234
- }
235
- onUnsubscribe() {
236
- this.hasListeners() || (this.#t?.(), this.#t = void 0);
237
- }
238
- setEventListener(t) {
239
- this.#s = t, this.#t?.(), this.#t = t((e) => {
240
- typeof e == "boolean" ? this.setFocused(e) : this.onFocus();
241
- });
242
- }
243
- setFocused(t) {
244
- this.#e !== t && (this.#e = t, this.onFocus());
245
- }
246
- onFocus() {
247
- const t = this.isFocused();
248
- this.listeners.forEach((e) => {
249
- e(t);
250
- });
251
- }
252
- isFocused() {
253
- return typeof this.#e == "boolean" ? this.#e : globalThis.document?.visibilityState !== "hidden";
254
- }
255
- }, ut = new se();
256
- function rt() {
257
- let t, e;
258
- const s = new Promise((i, n) => {
259
- t = i, e = n;
260
- });
261
- s.status = "pending", s.catch(() => {
262
- });
263
- function r(i) {
264
- Object.assign(s, i), delete s.resolve, delete s.reject;
265
- }
266
- return s.resolve = (i) => {
267
- r({
268
- status: "fulfilled",
269
- value: i
270
- }), t(i);
271
- }, s.reject = (i) => {
272
- r({
273
- status: "rejected",
274
- reason: i
275
- }), e(i);
276
- }, s;
277
- }
278
- function re(t) {
279
- let e;
280
- if (t.then((s) => (e = s, s), b)?.catch(b), e !== void 0)
281
- return { data: e };
282
- }
283
- function Mt(t) {
284
- return t;
285
- }
286
- function ie(t) {
287
- return {
288
- mutationKey: t.options.mutationKey,
289
- state: t.state,
290
- ...t.options.scope && { scope: t.options.scope },
291
- ...t.meta && { meta: t.meta }
292
- };
293
- }
294
- function ne(t, e, s) {
295
- return {
296
- dehydratedAt: Date.now(),
297
- state: {
298
- ...t.state,
299
- ...t.state.data !== void 0 && {
300
- data: e(t.state.data)
301
- }
302
- },
303
- queryKey: t.queryKey,
304
- queryHash: t.queryHash,
305
- ...t.state.status === "pending" && {
306
- promise: t.promise?.then(e).catch((r) => s(r) ? (process.env.NODE_ENV !== "production" && console.error(
307
- `A query that was dehydrated as pending ended up rejecting. [${t.queryHash}]: ${r}; The error will be redacted in production builds`
308
- ), Promise.reject(new Error("redacted"))) : Promise.reject(r))
309
- },
310
- ...t.meta && { meta: t.meta }
311
- };
312
- }
313
- function ae(t) {
314
- return t.state.isPaused;
315
- }
316
- function oe(t) {
317
- return t.state.status === "success";
318
- }
319
- function ue(t) {
320
- return !0;
321
- }
322
- function De(t, e = {}) {
323
- const s = e.shouldDehydrateMutation ?? t.getDefaultOptions().dehydrate?.shouldDehydrateMutation ?? ae, r = t.getMutationCache().getAll().flatMap(
324
- (u) => s(u) ? [ie(u)] : []
325
- ), i = e.shouldDehydrateQuery ?? t.getDefaultOptions().dehydrate?.shouldDehydrateQuery ?? oe, n = e.shouldRedactErrors ?? t.getDefaultOptions().dehydrate?.shouldRedactErrors ?? ue, o = e.serializeData ?? t.getDefaultOptions().dehydrate?.serializeData ?? Mt, a = t.getQueryCache().getAll().flatMap(
326
- (u) => i(u) ? [ne(u, o, n)] : []
327
- );
328
- return { mutations: r, queries: a };
329
- }
330
- function gt(t, e, s) {
331
- if (typeof e != "object" || e === null)
332
- return;
333
- const r = t.getMutationCache(), i = t.getQueryCache(), n = s?.defaultOptions?.deserializeData ?? t.getDefaultOptions().hydrate?.deserializeData ?? Mt, o = e.mutations || [], a = e.queries || [];
334
- o.forEach(({ state: u, ...h }) => {
335
- r.build(
336
- t,
337
- {
338
- ...t.getDefaultOptions().hydrate?.mutations,
339
- ...s?.defaultOptions?.mutations,
340
- ...h
341
- },
342
- u
343
- );
344
- }), a.forEach(
345
- ({ queryKey: u, state: h, queryHash: c, meta: d, promise: l, dehydratedAt: m }) => {
346
- const v = l ? re(l) : void 0, f = h.data === void 0 ? v?.data : h.data, y = f === void 0 ? f : n(f);
347
- let p = i.get(c);
348
- const O = p?.state.status === "pending", R = p?.state.fetchStatus === "fetching";
349
- if (p) {
350
- const P = v && // We only need this undefined check to handle older dehydration
351
- // payloads that might not have dehydratedAt
352
- m !== void 0 && m > p.state.dataUpdatedAt;
353
- if (h.dataUpdatedAt > p.state.dataUpdatedAt || P) {
354
- const { fetchStatus: F, ...k } = h;
355
- p.setState({
356
- ...k,
357
- data: y
358
- });
359
- }
360
- } else
361
- p = i.build(
362
- t,
363
- {
364
- ...t.getDefaultOptions().hydrate?.queries,
365
- ...s?.defaultOptions?.queries,
366
- queryKey: u,
367
- queryHash: c,
368
- meta: d
369
- },
370
- // Reset fetch status to idle to avoid
371
- // query being stuck in fetching state upon hydration
372
- {
373
- ...h,
374
- data: y,
375
- fetchStatus: "idle",
376
- status: y !== void 0 ? "success" : h.status
377
- }
378
- );
379
- l && !O && !R && // Only hydrate if dehydration is newer than any existing data,
380
- // this is always true for new queries
381
- (m === void 0 || m > p.state.dataUpdatedAt) && p.fetch(void 0, {
382
- // RSC transformed promises are not thenable
383
- initialPromise: Promise.resolve(l).then(n)
384
- });
385
- }
386
- );
387
- }
388
- var ce = Zt;
389
- function he() {
390
- let t = [], e = 0, s = (a) => {
391
- a();
392
- }, r = (a) => {
393
- a();
394
- }, i = ce;
395
- const n = (a) => {
396
- e ? t.push(a) : i(() => {
397
- s(a);
398
- });
399
- }, o = () => {
400
- const a = t;
401
- t = [], a.length && i(() => {
402
- r(() => {
403
- a.forEach((u) => {
404
- s(u);
405
- });
406
- });
407
- });
408
- };
409
- return {
410
- batch: (a) => {
411
- let u;
412
- e++;
413
- try {
414
- u = a();
415
- } finally {
416
- e--, e || o();
417
- }
418
- return u;
419
- },
420
- /**
421
- * All calls to the wrapped function will be batched.
422
- */
423
- batchCalls: (a) => (...u) => {
424
- n(() => {
425
- a(...u);
426
- });
427
- },
428
- schedule: n,
429
- /**
430
- * Use this method to set a custom notify function.
431
- * This can be used to for example wrap notifications with `React.act` while running tests.
432
- */
433
- setNotifyFunction: (a) => {
434
- s = a;
435
- },
436
- /**
437
- * Use this method to set a custom function to batch notifications together into a single tick.
438
- * By default React Query will use the batch function provided by ReactDOM or React Native.
439
- */
440
- setBatchNotifyFunction: (a) => {
441
- r = a;
442
- },
443
- setScheduler: (a) => {
444
- i = a;
445
- }
446
- };
447
- }
448
- var g = he(), le = class extends x {
449
- #e = !0;
450
- #t;
451
- #s;
452
- constructor() {
453
- super(), this.#s = (t) => {
454
- if (!q && window.addEventListener) {
455
- const e = () => t(!0), s = () => t(!1);
456
- return window.addEventListener("online", e, !1), window.addEventListener("offline", s, !1), () => {
457
- window.removeEventListener("online", e), window.removeEventListener("offline", s);
458
- };
459
- }
460
- };
461
- }
462
- onSubscribe() {
463
- this.#t || this.setEventListener(this.#s);
464
- }
465
- onUnsubscribe() {
466
- this.hasListeners() || (this.#t?.(), this.#t = void 0);
467
- }
468
- setEventListener(t) {
469
- this.#s = t, this.#t?.(), this.#t = t(this.setOnline.bind(this));
470
- }
471
- setOnline(t) {
472
- this.#e !== t && (this.#e = t, this.listeners.forEach((s) => {
473
- s(t);
474
- }));
475
- }
476
- isOnline() {
477
- return this.#e;
478
- }
479
- }, G = new le();
480
- function fe(t) {
481
- return Math.min(1e3 * 2 ** t, 3e4);
482
- }
483
- function Dt(t) {
484
- return (t ?? "online") === "online" ? G.isOnline() : !0;
485
- }
486
- var W = class extends Error {
487
- constructor(t) {
488
- super("CancelledError"), this.revert = t?.revert, this.silent = t?.silent;
489
- }
490
- };
491
- function qe(t) {
492
- return t instanceof W;
493
- }
494
- function qt(t) {
495
- let e = !1, s = 0, r;
496
- const i = rt(), n = () => i.status !== "pending", o = (f) => {
497
- if (!n()) {
498
- const y = new W(f);
499
- l(y), t.onCancel?.(y);
500
- }
501
- }, a = () => {
502
- e = !0;
503
- }, u = () => {
504
- e = !1;
505
- }, h = () => ut.isFocused() && (t.networkMode === "always" || G.isOnline()) && t.canRun(), c = () => Dt(t.networkMode) && t.canRun(), d = (f) => {
506
- n() || (r?.(), i.resolve(f));
507
- }, l = (f) => {
508
- n() || (r?.(), i.reject(f));
509
- }, m = () => new Promise((f) => {
510
- r = (y) => {
511
- (n() || h()) && f(y);
512
- }, t.onPause?.();
513
- }).then(() => {
514
- r = void 0, n() || t.onContinue?.();
515
- }), v = () => {
516
- if (n())
517
- return;
518
- let f;
519
- const y = s === 0 ? t.initialPromise : void 0;
520
- try {
521
- f = y ?? t.fn();
522
- } catch (p) {
523
- f = Promise.reject(p);
524
- }
525
- Promise.resolve(f).then(d).catch((p) => {
526
- if (n())
527
- return;
528
- const O = t.retry ?? (q ? 0 : 3), R = t.retryDelay ?? fe, P = typeof R == "function" ? R(s, p) : R, F = O === !0 || typeof O == "number" && s < O || typeof O == "function" && O(s, p);
529
- if (e || !F) {
530
- l(p);
531
- return;
532
- }
533
- s++, t.onFail?.(s, p), te(P).then(() => h() ? void 0 : m()).then(() => {
534
- e ? l(p) : v();
535
- });
536
- });
537
- };
538
- return {
539
- promise: i,
540
- status: () => i.status,
541
- cancel: o,
542
- continue: () => (r?.(), i),
543
- cancelRetry: a,
544
- continueRetry: u,
545
- canStart: c,
546
- start: () => (c() ? v() : m().then(v), i)
547
- };
548
- }
549
- var Tt = class {
550
- #e;
551
- destroy() {
552
- this.clearGcTimeout();
553
- }
554
- scheduleGc() {
555
- this.clearGcTimeout(), tt(this.gcTime) && (this.#e = D.setTimeout(() => {
556
- this.optionalRemove();
557
- }, this.gcTime));
558
- }
559
- updateGcTime(t) {
560
- this.gcTime = Math.max(
561
- this.gcTime || 0,
562
- t ?? (q ? 1 / 0 : 300 * 1e3)
563
- );
564
- }
565
- clearGcTimeout() {
566
- this.#e && (D.clearTimeout(this.#e), this.#e = void 0);
567
- }
568
- }, de = class extends Tt {
569
- #e;
570
- #t;
571
- #s;
572
- #i;
573
- #r;
574
- #n;
575
- #o;
576
- constructor(t) {
577
- super(), this.#o = !1, this.#n = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#i = t.client, this.#s = this.#i.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#e = mt(this.options), this.state = t.state ?? this.#e, this.scheduleGc();
578
- }
579
- get meta() {
580
- return this.options.meta;
581
- }
582
- get promise() {
583
- return this.#r?.promise;
584
- }
585
- setOptions(t) {
586
- if (this.options = { ...this.#n, ...t }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
587
- const e = mt(this.options);
588
- e.data !== void 0 && (this.setData(e.data, {
589
- updatedAt: e.dataUpdatedAt,
590
- manual: !0
591
- }), this.#e = e);
592
- }
593
- }
594
- optionalRemove() {
595
- !this.observers.length && this.state.fetchStatus === "idle" && this.#s.remove(this);
596
- }
597
- setData(t, e) {
598
- const s = st(this.state.data, t, this.options);
599
- return this.#a({
600
- data: s,
601
- type: "success",
602
- dataUpdatedAt: e?.updatedAt,
603
- manual: e?.manual
604
- }), s;
605
- }
606
- setState(t, e) {
607
- this.#a({ type: "setState", state: t, setStateOptions: e });
608
- }
609
- cancel(t) {
610
- const e = this.#r?.promise;
611
- return this.#r?.cancel(t), e ? e.then(b).catch(b) : Promise.resolve();
612
- }
613
- destroy() {
614
- super.destroy(), this.cancel({ silent: !0 });
615
- }
616
- reset() {
617
- this.destroy(), this.setState(this.#e);
618
- }
619
- isActive() {
620
- return this.observers.some(
621
- (t) => S(t.options.enabled, this) !== !1
622
- );
623
- }
624
- isDisabled() {
625
- return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === I || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
626
- }
627
- isStatic() {
628
- return this.getObserversCount() > 0 ? this.observers.some(
629
- (t) => M(t.options.staleTime, this) === "static"
630
- ) : !1;
631
- }
632
- isStale() {
633
- return this.getObserversCount() > 0 ? this.observers.some(
634
- (t) => t.getCurrentResult().isStale
635
- ) : this.state.data === void 0 || this.state.isInvalidated;
636
- }
637
- isStaleByTime(t = 0) {
638
- return this.state.data === void 0 ? !0 : t === "static" ? !1 : this.state.isInvalidated ? !0 : !Ct(this.state.dataUpdatedAt, t);
639
- }
640
- onFocus() {
641
- this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#r?.continue();
642
- }
643
- onOnline() {
644
- this.observers.find((e) => e.shouldFetchOnReconnect())?.refetch({ cancelRefetch: !1 }), this.#r?.continue();
645
- }
646
- addObserver(t) {
647
- this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#s.notify({ type: "observerAdded", query: this, observer: t }));
648
- }
649
- removeObserver(t) {
650
- this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#r && (this.#o ? this.#r.cancel({ revert: !0 }) : this.#r.cancelRetry()), this.scheduleGc()), this.#s.notify({ type: "observerRemoved", query: this, observer: t }));
651
- }
652
- getObserversCount() {
653
- return this.observers.length;
654
- }
655
- invalidate() {
656
- this.state.isInvalidated || this.#a({ type: "invalidate" });
657
- }
658
- async fetch(t, e) {
659
- if (this.state.fetchStatus !== "idle" && // If the promise in the retyer is already rejected, we have to definitely
660
- // re-start the fetch; there is a chance that the query is still in a
661
- // pending state when that happens
662
- this.#r?.status() !== "rejected") {
663
- if (this.state.data !== void 0 && e?.cancelRefetch)
664
- this.cancel({ silent: !0 });
665
- else if (this.#r)
666
- return this.#r.continueRetry(), this.#r.promise;
667
- }
668
- if (t && this.setOptions(t), !this.options.queryFn) {
669
- const a = this.observers.find((u) => u.options.queryFn);
670
- a && this.setOptions(a.options);
671
- }
672
- process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
673
- "As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"
674
- ));
675
- const s = new AbortController(), r = (a) => {
676
- Object.defineProperty(a, "signal", {
677
- enumerable: !0,
678
- get: () => (this.#o = !0, s.signal)
679
- });
680
- }, i = () => {
681
- const a = Qt(this.options, e), h = (() => {
682
- const c = {
683
- client: this.#i,
684
- queryKey: this.queryKey,
685
- meta: this.meta
686
- };
687
- return r(c), c;
688
- })();
689
- return this.#o = !1, this.options.persister ? this.options.persister(
690
- a,
691
- h,
692
- this
693
- ) : a(h);
694
- }, o = (() => {
695
- const a = {
696
- fetchOptions: e,
697
- options: this.options,
698
- queryKey: this.queryKey,
699
- client: this.#i,
700
- state: this.state,
701
- fetchFn: i
702
- };
703
- return r(a), a;
704
- })();
705
- this.options.behavior?.onFetch(o, this), this.#t = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== o.fetchOptions?.meta) && this.#a({ type: "fetch", meta: o.fetchOptions?.meta }), this.#r = qt({
706
- initialPromise: e?.initialPromise,
707
- fn: o.fetchFn,
708
- onCancel: (a) => {
709
- a instanceof W && a.revert && this.setState({
710
- ...this.#t,
711
- fetchStatus: "idle"
712
- }), s.abort();
713
- },
714
- onFail: (a, u) => {
715
- this.#a({ type: "failed", failureCount: a, error: u });
716
- },
717
- onPause: () => {
718
- this.#a({ type: "pause" });
719
- },
720
- onContinue: () => {
721
- this.#a({ type: "continue" });
722
- },
723
- retry: o.options.retry,
724
- retryDelay: o.options.retryDelay,
725
- networkMode: o.options.networkMode,
726
- canRun: () => !0
727
- });
728
- try {
729
- const a = await this.#r.start();
730
- if (a === void 0)
731
- throw process.env.NODE_ENV !== "production" && console.error(
732
- `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
733
- ), new Error(`${this.queryHash} data is undefined`);
734
- return this.setData(a), this.#s.config.onSuccess?.(a, this), this.#s.config.onSettled?.(
735
- a,
736
- this.state.error,
737
- this
738
- ), a;
739
- } catch (a) {
740
- if (a instanceof W) {
741
- if (a.silent)
742
- return this.#r.promise;
743
- if (a.revert) {
744
- if (this.state.data === void 0)
745
- throw a;
746
- return this.state.data;
747
- }
748
- }
749
- throw this.#a({
750
- type: "error",
751
- error: a
752
- }), this.#s.config.onError?.(
753
- a,
754
- this
755
- ), this.#s.config.onSettled?.(
756
- this.state.data,
757
- a,
758
- this
759
- ), a;
760
- } finally {
761
- this.scheduleGc();
762
- }
763
- }
764
- #a(t) {
765
- const e = (s) => {
766
- switch (t.type) {
767
- case "failed":
768
- return {
769
- ...s,
770
- fetchFailureCount: t.failureCount,
771
- fetchFailureReason: t.error
772
- };
773
- case "pause":
774
- return {
775
- ...s,
776
- fetchStatus: "paused"
777
- };
778
- case "continue":
779
- return {
780
- ...s,
781
- fetchStatus: "fetching"
782
- };
783
- case "fetch":
784
- return {
785
- ...s,
786
- ...It(s.data, this.options),
787
- fetchMeta: t.meta ?? null
788
- };
789
- case "success":
790
- const r = {
791
- ...s,
792
- data: t.data,
793
- dataUpdateCount: s.dataUpdateCount + 1,
794
- dataUpdatedAt: t.dataUpdatedAt ?? Date.now(),
795
- error: null,
796
- isInvalidated: !1,
797
- status: "success",
798
- ...!t.manual && {
799
- fetchStatus: "idle",
800
- fetchFailureCount: 0,
801
- fetchFailureReason: null
802
- }
803
- };
804
- return this.#t = t.manual ? r : void 0, r;
805
- case "error":
806
- const i = t.error;
807
- return {
808
- ...s,
809
- error: i,
810
- errorUpdateCount: s.errorUpdateCount + 1,
811
- errorUpdatedAt: Date.now(),
812
- fetchFailureCount: s.fetchFailureCount + 1,
813
- fetchFailureReason: i,
814
- fetchStatus: "idle",
815
- status: "error"
816
- };
817
- case "invalidate":
818
- return {
819
- ...s,
820
- isInvalidated: !0
821
- };
822
- case "setState":
823
- return {
824
- ...s,
825
- ...t.state
826
- };
827
- }
828
- };
829
- this.state = e(this.state), g.batch(() => {
830
- this.observers.forEach((s) => {
831
- s.onQueryUpdate();
832
- }), this.#s.notify({ query: this, type: "updated", action: t });
833
- });
834
- }
835
- };
836
- function It(t, e) {
837
- return {
838
- fetchFailureCount: 0,
839
- fetchFailureReason: null,
840
- fetchStatus: Dt(e.networkMode) ? "fetching" : "paused",
841
- ...t === void 0 && {
842
- error: null,
843
- status: "pending"
844
- }
845
- };
846
- }
847
- function mt(t) {
848
- const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, s = e !== void 0, r = s ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
849
- return {
850
- data: e,
851
- dataUpdateCount: 0,
852
- dataUpdatedAt: s ? r ?? Date.now() : 0,
853
- error: null,
854
- errorUpdateCount: 0,
855
- errorUpdatedAt: 0,
856
- fetchFailureCount: 0,
857
- fetchFailureReason: null,
858
- fetchMeta: null,
859
- isInvalidated: !1,
860
- status: s ? "success" : "pending",
861
- fetchStatus: "idle"
862
- };
863
- }
864
- var L = class extends x {
865
- constructor(t, e) {
866
- super(), this.options = e, this.#e = t, this.#a = null, this.#o = rt(), this.bindMethods(), this.setOptions(e);
867
- }
868
- #e;
869
- #t = void 0;
870
- #s = void 0;
871
- #i = void 0;
872
- #r;
873
- #n;
874
- #o;
875
- #a;
876
- #d;
877
- #l;
878
- // This property keeps track of the last query with defined data.
879
- // It will be used to pass the previous data and query to the placeholder function between renders.
880
- #f;
881
- #c;
882
- #h;
883
- #u;
884
- #y = /* @__PURE__ */ new Set();
885
- bindMethods() {
886
- this.refetch = this.refetch.bind(this);
887
- }
888
- onSubscribe() {
889
- this.listeners.size === 1 && (this.#t.addObserver(this), bt(this.#t, this.options) ? this.#p() : this.updateResult(), this.#b());
890
- }
891
- onUnsubscribe() {
892
- this.hasListeners() || this.destroy();
893
- }
894
- shouldFetchOnReconnect() {
895
- return it(
896
- this.#t,
897
- this.options,
898
- this.options.refetchOnReconnect
899
- );
900
- }
901
- shouldFetchOnWindowFocus() {
902
- return it(
903
- this.#t,
904
- this.options,
905
- this.options.refetchOnWindowFocus
906
- );
907
- }
908
- destroy() {
909
- this.listeners = /* @__PURE__ */ new Set(), this.#O(), this.#w(), this.#t.removeObserver(this);
910
- }
911
- setOptions(t) {
912
- const e = this.options, s = this.#t;
913
- if (this.options = this.#e.defaultQueryOptions(t), this.options.enabled !== void 0 && typeof this.options.enabled != "boolean" && typeof this.options.enabled != "function" && typeof S(this.options.enabled, this.#t) != "boolean")
914
- throw new Error(
915
- "Expected enabled to be a boolean or a callback that returns a boolean"
916
- );
917
- this.#S(), this.#t.setOptions(this.options), e._defaulted && !H(this.options, e) && this.#e.getQueryCache().notify({
918
- type: "observerOptionsUpdated",
919
- query: this.#t,
920
- observer: this
921
- });
922
- const r = this.hasListeners();
923
- r && Ot(
924
- this.#t,
925
- s,
926
- this.options,
927
- e
928
- ) && this.#p(), this.updateResult(), r && (this.#t !== s || S(this.options.enabled, this.#t) !== S(e.enabled, this.#t) || M(this.options.staleTime, this.#t) !== M(e.staleTime, this.#t)) && this.#v();
929
- const i = this.#g();
930
- r && (this.#t !== s || S(this.options.enabled, this.#t) !== S(e.enabled, this.#t) || i !== this.#u) && this.#m(i);
931
- }
932
- getOptimisticResult(t) {
933
- const e = this.#e.getQueryCache().build(this.#e, t), s = this.createResult(e, t);
934
- return ye(this, s) && (this.#i = s, this.#n = this.options, this.#r = this.#t.state), s;
935
- }
936
- getCurrentResult() {
937
- return this.#i;
938
- }
939
- trackResult(t, e) {
940
- return new Proxy(t, {
941
- get: (s, r) => (this.trackProp(r), e?.(r), r === "promise" && !this.options.experimental_prefetchInRender && this.#o.status === "pending" && this.#o.reject(
942
- new Error(
943
- "experimental_prefetchInRender feature flag is not enabled"
944
- )
945
- ), Reflect.get(s, r))
946
- });
947
- }
948
- trackProp(t) {
949
- this.#y.add(t);
950
- }
951
- getCurrentQuery() {
952
- return this.#t;
953
- }
954
- refetch({ ...t } = {}) {
955
- return this.fetch({
956
- ...t
957
- });
958
- }
959
- fetchOptimistic(t) {
960
- const e = this.#e.defaultQueryOptions(t), s = this.#e.getQueryCache().build(this.#e, e);
961
- return s.fetch().then(() => this.createResult(s, e));
962
- }
963
- fetch(t) {
964
- return this.#p({
965
- ...t,
966
- cancelRefetch: t.cancelRefetch ?? !0
967
- }).then(() => (this.updateResult(), this.#i));
968
- }
969
- #p(t) {
970
- this.#S();
971
- let e = this.#t.fetch(
972
- this.options,
973
- t
974
- );
975
- return t?.throwOnError || (e = e.catch(b)), e;
976
- }
977
- #v() {
978
- this.#O();
979
- const t = M(
980
- this.options.staleTime,
981
- this.#t
982
- );
983
- if (q || this.#i.isStale || !tt(t))
984
- return;
985
- const s = Ct(this.#i.dataUpdatedAt, t) + 1;
986
- this.#c = D.setTimeout(() => {
987
- this.#i.isStale || this.updateResult();
988
- }, s);
989
- }
990
- #g() {
991
- return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.#t) : this.options.refetchInterval) ?? !1;
992
- }
993
- #m(t) {
994
- this.#w(), this.#u = t, !(q || S(this.options.enabled, this.#t) === !1 || !tt(this.#u) || this.#u === 0) && (this.#h = D.setInterval(() => {
995
- (this.options.refetchIntervalInBackground || ut.isFocused()) && this.#p();
996
- }, this.#u));
997
- }
998
- #b() {
999
- this.#v(), this.#m(this.#g());
1000
- }
1001
- #O() {
1002
- this.#c && (D.clearTimeout(this.#c), this.#c = void 0);
1003
- }
1004
- #w() {
1005
- this.#h && (D.clearInterval(this.#h), this.#h = void 0);
1006
- }
1007
- createResult(t, e) {
1008
- const s = this.#t, r = this.options, i = this.#i, n = this.#r, o = this.#n, u = t !== s ? t.state : this.#s, { state: h } = t;
1009
- let c = { ...h }, d = !1, l;
1010
- if (e._optimisticResults) {
1011
- const w = this.hasListeners(), $ = !w && bt(t, e), A = w && Ot(t, s, e, r);
1012
- ($ || A) && (c = {
1013
- ...c,
1014
- ...It(h.data, t.options)
1015
- }), e._optimisticResults === "isRestoring" && (c.fetchStatus = "idle");
1016
- }
1017
- let { error: m, errorUpdatedAt: v, status: f } = c;
1018
- l = c.data;
1019
- let y = !1;
1020
- if (e.placeholderData !== void 0 && l === void 0 && f === "pending") {
1021
- let w;
1022
- i?.isPlaceholderData && e.placeholderData === o?.placeholderData ? (w = i.data, y = !0) : w = typeof e.placeholderData == "function" ? e.placeholderData(
1023
- this.#f?.state.data,
1024
- this.#f
1025
- ) : e.placeholderData, w !== void 0 && (f = "success", l = st(
1026
- i?.data,
1027
- w,
1028
- e
1029
- ), d = !0);
1030
- }
1031
- if (e.select && l !== void 0 && !y)
1032
- if (i && l === n?.data && e.select === this.#d)
1033
- l = this.#l;
1034
- else
1035
- try {
1036
- this.#d = e.select, l = e.select(l), l = st(i?.data, l, e), this.#l = l, this.#a = null;
1037
- } catch (w) {
1038
- this.#a = w;
1039
- }
1040
- this.#a && (m = this.#a, l = this.#l, v = Date.now(), f = "error");
1041
- const p = c.fetchStatus === "fetching", O = f === "pending", R = f === "error", P = O && p, F = l !== void 0, E = {
1042
- status: f,
1043
- fetchStatus: c.fetchStatus,
1044
- isPending: O,
1045
- isSuccess: f === "success",
1046
- isError: R,
1047
- isInitialLoading: P,
1048
- isLoading: P,
1049
- data: l,
1050
- dataUpdatedAt: c.dataUpdatedAt,
1051
- error: m,
1052
- errorUpdatedAt: v,
1053
- failureCount: c.fetchFailureCount,
1054
- failureReason: c.fetchFailureReason,
1055
- errorUpdateCount: c.errorUpdateCount,
1056
- isFetched: c.dataUpdateCount > 0 || c.errorUpdateCount > 0,
1057
- isFetchedAfterMount: c.dataUpdateCount > u.dataUpdateCount || c.errorUpdateCount > u.errorUpdateCount,
1058
- isFetching: p,
1059
- isRefetching: p && !O,
1060
- isLoadingError: R && !F,
1061
- isPaused: c.fetchStatus === "paused",
1062
- isPlaceholderData: d,
1063
- isRefetchError: R && F,
1064
- isStale: ct(t, e),
1065
- refetch: this.refetch,
1066
- promise: this.#o,
1067
- isEnabled: S(e.enabled, t) !== !1
1068
- };
1069
- if (this.options.experimental_prefetchInRender) {
1070
- const w = (z) => {
1071
- E.status === "error" ? z.reject(E.error) : E.data !== void 0 && z.resolve(E.data);
1072
- }, $ = () => {
1073
- const z = this.#o = E.promise = rt();
1074
- w(z);
1075
- }, A = this.#o;
1076
- switch (A.status) {
1077
- case "pending":
1078
- t.queryHash === s.queryHash && w(A);
1079
- break;
1080
- case "fulfilled":
1081
- (E.status === "error" || E.data !== A.value) && $();
1082
- break;
1083
- case "rejected":
1084
- (E.status !== "error" || E.error !== A.reason) && $();
1085
- break;
1086
- }
1087
- }
1088
- return E;
1089
- }
1090
- updateResult() {
1091
- const t = this.#i, e = this.createResult(this.#t, this.options);
1092
- if (this.#r = this.#t.state, this.#n = this.options, this.#r.data !== void 0 && (this.#f = this.#t), H(e, t))
1093
- return;
1094
- this.#i = e;
1095
- const s = () => {
1096
- if (!t)
1097
- return !0;
1098
- const { notifyOnChangeProps: r } = this.options, i = typeof r == "function" ? r() : r;
1099
- if (i === "all" || !i && !this.#y.size)
1100
- return !0;
1101
- const n = new Set(
1102
- i ?? this.#y
1103
- );
1104
- return this.options.throwOnError && n.add("error"), Object.keys(this.#i).some((o) => {
1105
- const a = o;
1106
- return this.#i[a] !== t[a] && n.has(a);
1107
- });
1108
- };
1109
- this.#R({ listeners: s() });
1110
- }
1111
- #S() {
1112
- const t = this.#e.getQueryCache().build(this.#e, this.options);
1113
- if (t === this.#t)
1114
- return;
1115
- const e = this.#t;
1116
- this.#t = t, this.#s = t.state, this.hasListeners() && (e?.removeObserver(this), t.addObserver(this));
1117
- }
1118
- onQueryUpdate() {
1119
- this.updateResult(), this.hasListeners() && this.#b();
1120
- }
1121
- #R(t) {
1122
- g.batch(() => {
1123
- t.listeners && this.listeners.forEach((e) => {
1124
- e(this.#i);
1125
- }), this.#e.getQueryCache().notify({
1126
- query: this.#t,
1127
- type: "observerResultsUpdated"
1128
- });
1129
- });
1130
- }
1131
- };
1132
- function pe(t, e) {
1133
- return S(e.enabled, t) !== !1 && t.state.data === void 0 && !(t.state.status === "error" && e.retryOnMount === !1);
1134
- }
1135
- function bt(t, e) {
1136
- return pe(t, e) || t.state.data !== void 0 && it(t, e, e.refetchOnMount);
1137
- }
1138
- function it(t, e, s) {
1139
- if (S(e.enabled, t) !== !1 && M(e.staleTime, t) !== "static") {
1140
- const r = typeof s == "function" ? s(t) : s;
1141
- return r === "always" || r !== !1 && ct(t, e);
1142
- }
1143
- return !1;
1144
- }
1145
- function Ot(t, e, s, r) {
1146
- return (t !== e || S(r.enabled, t) === !1) && (!s.suspense || t.state.status !== "error") && ct(t, s);
1147
- }
1148
- function ct(t, e) {
1149
- return S(e.enabled, t) !== !1 && t.isStaleByTime(M(e.staleTime, t));
1150
- }
1151
- function ye(t, e) {
1152
- return !H(t.getCurrentResult(), e);
1153
- }
1154
- function J(t) {
1155
- return {
1156
- onFetch: (e, s) => {
1157
- const r = e.options, i = e.fetchOptions?.meta?.fetchMore?.direction, n = e.state.data?.pages || [], o = e.state.data?.pageParams || [];
1158
- let a = { pages: [], pageParams: [] }, u = 0;
1159
- const h = async () => {
1160
- let c = !1;
1161
- const d = (v) => {
1162
- Object.defineProperty(v, "signal", {
1163
- enumerable: !0,
1164
- get: () => (e.signal.aborted ? c = !0 : e.signal.addEventListener("abort", () => {
1165
- c = !0;
1166
- }), e.signal)
1167
- });
1168
- }, l = Qt(e.options, e.fetchOptions), m = async (v, f, y) => {
1169
- if (c)
1170
- return Promise.reject();
1171
- if (f == null && v.pages.length)
1172
- return Promise.resolve(v);
1173
- const O = (() => {
1174
- const k = {
1175
- client: e.client,
1176
- queryKey: e.queryKey,
1177
- pageParam: f,
1178
- direction: y ? "backward" : "forward",
1179
- meta: e.options.meta
1180
- };
1181
- return d(k), k;
1182
- })(), R = await l(O), { maxPages: P } = e.options, F = y ? ee : Pt;
1183
- return {
1184
- pages: F(v.pages, R, P),
1185
- pageParams: F(v.pageParams, f, P)
1186
- };
1187
- };
1188
- if (i && n.length) {
1189
- const v = i === "backward", f = v ? xt : nt, y = {
1190
- pages: n,
1191
- pageParams: o
1192
- }, p = f(r, y);
1193
- a = await m(y, p, v);
1194
- } else {
1195
- const v = t ?? n.length;
1196
- do {
1197
- const f = u === 0 ? o[0] ?? r.initialPageParam : nt(r, a);
1198
- if (u > 0 && f == null)
1199
- break;
1200
- a = await m(a, f), u++;
1201
- } while (u < v);
1202
- }
1203
- return a;
1204
- };
1205
- e.options.persister ? e.fetchFn = () => e.options.persister?.(
1206
- h,
1207
- {
1208
- client: e.client,
1209
- queryKey: e.queryKey,
1210
- meta: e.options.meta,
1211
- signal: e.signal
1212
- },
1213
- s
1214
- ) : e.fetchFn = h;
1215
- }
1216
- };
1217
- }
1218
- function nt(t, { pages: e, pageParams: s }) {
1219
- const r = e.length - 1;
1220
- return e.length > 0 ? t.getNextPageParam(
1221
- e[r],
1222
- e,
1223
- s[r],
1224
- s
1225
- ) : void 0;
1226
- }
1227
- function xt(t, { pages: e, pageParams: s }) {
1228
- return e.length > 0 ? t.getPreviousPageParam?.(e[0], e, s[0], s) : void 0;
1229
- }
1230
- function ve(t, e) {
1231
- return e ? nt(t, e) != null : !1;
1232
- }
1233
- function ge(t, e) {
1234
- return !e || !t.getPreviousPageParam ? !1 : xt(t, e) != null;
1235
- }
1236
- var At = class extends L {
1237
- constructor(t, e) {
1238
- super(t, e);
1239
- }
1240
- bindMethods() {
1241
- super.bindMethods(), this.fetchNextPage = this.fetchNextPage.bind(this), this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
1242
- }
1243
- setOptions(t) {
1244
- super.setOptions({
1245
- ...t,
1246
- behavior: J()
1247
- });
1248
- }
1249
- getOptimisticResult(t) {
1250
- return t.behavior = J(), super.getOptimisticResult(t);
1251
- }
1252
- fetchNextPage(t) {
1253
- return this.fetch({
1254
- ...t,
1255
- meta: {
1256
- fetchMore: { direction: "forward" }
1257
- }
1258
- });
1259
- }
1260
- fetchPreviousPage(t) {
1261
- return this.fetch({
1262
- ...t,
1263
- meta: {
1264
- fetchMore: { direction: "backward" }
1265
- }
1266
- });
1267
- }
1268
- createResult(t, e) {
1269
- const { state: s } = t, r = super.createResult(t, e), { isFetching: i, isRefetching: n, isError: o, isRefetchError: a } = r, u = s.fetchMeta?.fetchMore?.direction, h = o && u === "forward", c = i && u === "forward", d = o && u === "backward", l = i && u === "backward";
1270
- return {
1271
- ...r,
1272
- fetchNextPage: this.fetchNextPage,
1273
- fetchPreviousPage: this.fetchPreviousPage,
1274
- hasNextPage: ve(e, s.data),
1275
- hasPreviousPage: ge(e, s.data),
1276
- isFetchNextPageError: h,
1277
- isFetchingNextPage: c,
1278
- isFetchPreviousPageError: d,
1279
- isFetchingPreviousPage: l,
1280
- isRefetchError: a && !h && !d,
1281
- isRefetching: n && !c && !l
1282
- };
1283
- }
1284
- }, me = class extends Tt {
1285
- #e;
1286
- #t;
1287
- #s;
1288
- #i;
1289
- constructor(t) {
1290
- super(), this.#e = t.client, this.mutationId = t.mutationId, this.#s = t.mutationCache, this.#t = [], this.state = t.state || kt(), this.setOptions(t.options), this.scheduleGc();
1291
- }
1292
- setOptions(t) {
1293
- this.options = t, this.updateGcTime(this.options.gcTime);
1294
- }
1295
- get meta() {
1296
- return this.options.meta;
1297
- }
1298
- addObserver(t) {
1299
- this.#t.includes(t) || (this.#t.push(t), this.clearGcTimeout(), this.#s.notify({
1300
- type: "observerAdded",
1301
- mutation: this,
1302
- observer: t
1303
- }));
1304
- }
1305
- removeObserver(t) {
1306
- this.#t = this.#t.filter((e) => e !== t), this.scheduleGc(), this.#s.notify({
1307
- type: "observerRemoved",
1308
- mutation: this,
1309
- observer: t
1310
- });
1311
- }
1312
- optionalRemove() {
1313
- this.#t.length || (this.state.status === "pending" ? this.scheduleGc() : this.#s.remove(this));
1314
- }
1315
- continue() {
1316
- return this.#i?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
1317
- this.execute(this.state.variables);
1318
- }
1319
- async execute(t) {
1320
- const e = () => {
1321
- this.#r({ type: "continue" });
1322
- }, s = {
1323
- client: this.#e,
1324
- meta: this.options.meta,
1325
- mutationKey: this.options.mutationKey
1326
- };
1327
- this.#i = qt({
1328
- fn: () => this.options.mutationFn ? this.options.mutationFn(t, s) : Promise.reject(new Error("No mutationFn found")),
1329
- onFail: (n, o) => {
1330
- this.#r({ type: "failed", failureCount: n, error: o });
1331
- },
1332
- onPause: () => {
1333
- this.#r({ type: "pause" });
1334
- },
1335
- onContinue: e,
1336
- retry: this.options.retry ?? 0,
1337
- retryDelay: this.options.retryDelay,
1338
- networkMode: this.options.networkMode,
1339
- canRun: () => this.#s.canRun(this)
1340
- });
1341
- const r = this.state.status === "pending", i = !this.#i.canStart();
1342
- try {
1343
- if (r)
1344
- e();
1345
- else {
1346
- this.#r({ type: "pending", variables: t, isPaused: i }), await this.#s.config.onMutate?.(
1347
- t,
1348
- this,
1349
- s
1350
- );
1351
- const o = await this.options.onMutate?.(
1352
- t,
1353
- s
1354
- );
1355
- o !== this.state.context && this.#r({
1356
- type: "pending",
1357
- context: o,
1358
- variables: t,
1359
- isPaused: i
1360
- });
1361
- }
1362
- const n = await this.#i.start();
1363
- return await this.#s.config.onSuccess?.(
1364
- n,
1365
- t,
1366
- this.state.context,
1367
- this,
1368
- s
1369
- ), await this.options.onSuccess?.(
1370
- n,
1371
- t,
1372
- this.state.context,
1373
- s
1374
- ), await this.#s.config.onSettled?.(
1375
- n,
1376
- null,
1377
- this.state.variables,
1378
- this.state.context,
1379
- this,
1380
- s
1381
- ), await this.options.onSettled?.(
1382
- n,
1383
- null,
1384
- t,
1385
- this.state.context,
1386
- s
1387
- ), this.#r({ type: "success", data: n }), n;
1388
- } catch (n) {
1389
- try {
1390
- throw await this.#s.config.onError?.(
1391
- n,
1392
- t,
1393
- this.state.context,
1394
- this,
1395
- s
1396
- ), await this.options.onError?.(
1397
- n,
1398
- t,
1399
- this.state.context,
1400
- s
1401
- ), await this.#s.config.onSettled?.(
1402
- void 0,
1403
- n,
1404
- this.state.variables,
1405
- this.state.context,
1406
- this,
1407
- s
1408
- ), await this.options.onSettled?.(
1409
- void 0,
1410
- n,
1411
- t,
1412
- this.state.context,
1413
- s
1414
- ), n;
1415
- } finally {
1416
- this.#r({ type: "error", error: n });
1417
- }
1418
- } finally {
1419
- this.#s.runNext(this);
1420
- }
1421
- }
1422
- #r(t) {
1423
- const e = (s) => {
1424
- switch (t.type) {
1425
- case "failed":
1426
- return {
1427
- ...s,
1428
- failureCount: t.failureCount,
1429
- failureReason: t.error
1430
- };
1431
- case "pause":
1432
- return {
1433
- ...s,
1434
- isPaused: !0
1435
- };
1436
- case "continue":
1437
- return {
1438
- ...s,
1439
- isPaused: !1
1440
- };
1441
- case "pending":
1442
- return {
1443
- ...s,
1444
- context: t.context,
1445
- data: void 0,
1446
- failureCount: 0,
1447
- failureReason: null,
1448
- error: null,
1449
- isPaused: t.isPaused,
1450
- status: "pending",
1451
- variables: t.variables,
1452
- submittedAt: Date.now()
1453
- };
1454
- case "success":
1455
- return {
1456
- ...s,
1457
- data: t.data,
1458
- failureCount: 0,
1459
- failureReason: null,
1460
- error: null,
1461
- status: "success",
1462
- isPaused: !1
1463
- };
1464
- case "error":
1465
- return {
1466
- ...s,
1467
- data: void 0,
1468
- error: t.error,
1469
- failureCount: s.failureCount + 1,
1470
- failureReason: t.error,
1471
- isPaused: !1,
1472
- status: "error"
1473
- };
1474
- }
1475
- };
1476
- this.state = e(this.state), g.batch(() => {
1477
- this.#t.forEach((s) => {
1478
- s.onMutationUpdate(t);
1479
- }), this.#s.notify({
1480
- mutation: this,
1481
- type: "updated",
1482
- action: t
1483
- });
1484
- });
1485
- }
1486
- };
1487
- function kt() {
1488
- return {
1489
- context: void 0,
1490
- data: void 0,
1491
- error: null,
1492
- failureCount: 0,
1493
- failureReason: null,
1494
- isPaused: !1,
1495
- status: "idle",
1496
- variables: void 0,
1497
- submittedAt: 0
1498
- };
1499
- }
1500
- var be = class extends x {
1501
- constructor(t = {}) {
1502
- super(), this.config = t, this.#e = /* @__PURE__ */ new Set(), this.#t = /* @__PURE__ */ new Map(), this.#s = 0;
1503
- }
1504
- #e;
1505
- #t;
1506
- #s;
1507
- build(t, e, s) {
1508
- const r = new me({
1509
- client: t,
1510
- mutationCache: this,
1511
- mutationId: ++this.#s,
1512
- options: t.defaultMutationOptions(e),
1513
- state: s
1514
- });
1515
- return this.add(r), r;
1516
- }
1517
- add(t) {
1518
- this.#e.add(t);
1519
- const e = V(t);
1520
- if (typeof e == "string") {
1521
- const s = this.#t.get(e);
1522
- s ? s.push(t) : this.#t.set(e, [t]);
1523
- }
1524
- this.notify({ type: "added", mutation: t });
1525
- }
1526
- remove(t) {
1527
- if (this.#e.delete(t)) {
1528
- const e = V(t);
1529
- if (typeof e == "string") {
1530
- const s = this.#t.get(e);
1531
- if (s)
1532
- if (s.length > 1) {
1533
- const r = s.indexOf(t);
1534
- r !== -1 && s.splice(r, 1);
1535
- } else s[0] === t && this.#t.delete(e);
1536
- }
1537
- }
1538
- this.notify({ type: "removed", mutation: t });
1539
- }
1540
- canRun(t) {
1541
- const e = V(t);
1542
- if (typeof e == "string") {
1543
- const r = this.#t.get(e)?.find(
1544
- (i) => i.state.status === "pending"
1545
- );
1546
- return !r || r === t;
1547
- } else
1548
- return !0;
1549
- }
1550
- runNext(t) {
1551
- const e = V(t);
1552
- return typeof e == "string" ? this.#t.get(e)?.find((r) => r !== t && r.state.isPaused)?.continue() ?? Promise.resolve() : Promise.resolve();
1553
- }
1554
- clear() {
1555
- g.batch(() => {
1556
- this.#e.forEach((t) => {
1557
- this.notify({ type: "removed", mutation: t });
1558
- }), this.#e.clear(), this.#t.clear();
1559
- });
1560
- }
1561
- getAll() {
1562
- return Array.from(this.#e);
1563
- }
1564
- find(t) {
1565
- const e = { exact: !0, ...t };
1566
- return this.getAll().find(
1567
- (s) => pt(e, s)
1568
- );
1569
- }
1570
- findAll(t = {}) {
1571
- return this.getAll().filter((e) => pt(t, e));
1572
- }
1573
- notify(t) {
1574
- g.batch(() => {
1575
- this.listeners.forEach((e) => {
1576
- e(t);
1577
- });
1578
- });
1579
- }
1580
- resumePausedMutations() {
1581
- const t = this.getAll().filter((e) => e.state.isPaused);
1582
- return g.batch(
1583
- () => Promise.all(
1584
- t.map((e) => e.continue().catch(b))
1585
- )
1586
- );
1587
- }
1588
- };
1589
- function V(t) {
1590
- return t.options.scope?.id;
1591
- }
1592
- var Oe = class extends x {
1593
- #e;
1594
- #t = void 0;
1595
- #s;
1596
- #i;
1597
- constructor(t, e) {
1598
- super(), this.#e = t, this.setOptions(e), this.bindMethods(), this.#r();
1599
- }
1600
- bindMethods() {
1601
- this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
1602
- }
1603
- setOptions(t) {
1604
- const e = this.options;
1605
- this.options = this.#e.defaultMutationOptions(t), H(this.options, e) || this.#e.getMutationCache().notify({
1606
- type: "observerOptionsUpdated",
1607
- mutation: this.#s,
1608
- observer: this
1609
- }), e?.mutationKey && this.options.mutationKey && T(e.mutationKey) !== T(this.options.mutationKey) ? this.reset() : this.#s?.state.status === "pending" && this.#s.setOptions(this.options);
1610
- }
1611
- onUnsubscribe() {
1612
- this.hasListeners() || this.#s?.removeObserver(this);
1613
- }
1614
- onMutationUpdate(t) {
1615
- this.#r(), this.#n(t);
1616
- }
1617
- getCurrentResult() {
1618
- return this.#t;
1619
- }
1620
- reset() {
1621
- this.#s?.removeObserver(this), this.#s = void 0, this.#r(), this.#n();
1622
- }
1623
- mutate(t, e) {
1624
- return this.#i = e, this.#s?.removeObserver(this), this.#s = this.#e.getMutationCache().build(this.#e, this.options), this.#s.addObserver(this), this.#s.execute(t);
1625
- }
1626
- #r() {
1627
- const t = this.#s?.state ?? kt();
1628
- this.#t = {
1629
- ...t,
1630
- isPending: t.status === "pending",
1631
- isSuccess: t.status === "success",
1632
- isError: t.status === "error",
1633
- isIdle: t.status === "idle",
1634
- mutate: this.mutate,
1635
- reset: this.reset
1636
- };
1637
- }
1638
- #n(t) {
1639
- g.batch(() => {
1640
- if (this.#i && this.hasListeners()) {
1641
- const e = this.#t.variables, s = this.#t.context, r = {
1642
- client: this.#e,
1643
- meta: this.options.meta,
1644
- mutationKey: this.options.mutationKey
1645
- };
1646
- t?.type === "success" ? (this.#i.onSuccess?.(
1647
- t.data,
1648
- e,
1649
- s,
1650
- r
1651
- ), this.#i.onSettled?.(
1652
- t.data,
1653
- null,
1654
- e,
1655
- s,
1656
- r
1657
- )) : t?.type === "error" && (this.#i.onError?.(
1658
- t.error,
1659
- e,
1660
- s,
1661
- r
1662
- ), this.#i.onSettled?.(
1663
- void 0,
1664
- t.error,
1665
- e,
1666
- s,
1667
- r
1668
- ));
1669
- }
1670
- this.listeners.forEach((e) => {
1671
- e(this.#t);
1672
- });
1673
- });
1674
- }
1675
- };
1676
- function wt(t, e) {
1677
- const s = new Set(e);
1678
- return t.filter((r) => !s.has(r));
1679
- }
1680
- function we(t, e, s) {
1681
- const r = t.slice(0);
1682
- return r[e] = s, r;
1683
- }
1684
- var Se = class extends x {
1685
- #e;
1686
- #t;
1687
- #s;
1688
- #i;
1689
- #r;
1690
- #n;
1691
- #o;
1692
- #a;
1693
- #d = [];
1694
- constructor(t, e, s) {
1695
- super(), this.#e = t, this.#i = s, this.#s = [], this.#r = [], this.#t = [], this.setQueries(e);
1696
- }
1697
- onSubscribe() {
1698
- this.listeners.size === 1 && this.#r.forEach((t) => {
1699
- t.subscribe((e) => {
1700
- this.#h(t, e);
1701
- });
1702
- });
1703
- }
1704
- onUnsubscribe() {
1705
- this.listeners.size || this.destroy();
1706
- }
1707
- destroy() {
1708
- this.listeners = /* @__PURE__ */ new Set(), this.#r.forEach((t) => {
1709
- t.destroy();
1710
- });
1711
- }
1712
- setQueries(t, e) {
1713
- if (this.#s = t, this.#i = e, process.env.NODE_ENV !== "production") {
1714
- const s = t.map(
1715
- (r) => this.#e.defaultQueryOptions(r).queryHash
1716
- );
1717
- new Set(s).size !== s.length && console.warn(
1718
- "[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior."
1719
- );
1720
- }
1721
- g.batch(() => {
1722
- const s = this.#r, r = this.#c(this.#s);
1723
- this.#d = r, r.forEach(
1724
- (c) => c.observer.setOptions(c.defaultedQueryOptions)
1725
- );
1726
- const i = r.map((c) => c.observer), n = i.map(
1727
- (c) => c.getCurrentResult()
1728
- ), o = s.length !== i.length, a = i.some(
1729
- (c, d) => c !== s[d]
1730
- ), u = o || a, h = u ? !0 : n.some((c, d) => {
1731
- const l = this.#t[d];
1732
- return !l || !H(c, l);
1733
- });
1734
- !u && !h || (u && (this.#r = i), this.#t = n, this.hasListeners() && (u && (wt(s, i).forEach((c) => {
1735
- c.destroy();
1736
- }), wt(i, s).forEach((c) => {
1737
- c.subscribe((d) => {
1738
- this.#h(c, d);
1739
- });
1740
- })), this.#u()));
1741
- });
1742
- }
1743
- getCurrentResult() {
1744
- return this.#t;
1745
- }
1746
- getQueries() {
1747
- return this.#r.map((t) => t.getCurrentQuery());
1748
- }
1749
- getObservers() {
1750
- return this.#r;
1751
- }
1752
- getOptimisticResult(t, e) {
1753
- const s = this.#c(t), r = s.map(
1754
- (i) => i.observer.getOptimisticResult(i.defaultedQueryOptions)
1755
- );
1756
- return [
1757
- r,
1758
- (i) => this.#f(i ?? r, e),
1759
- () => this.#l(r, s)
1760
- ];
1761
- }
1762
- #l(t, e) {
1763
- return e.map((s, r) => {
1764
- const i = t[r];
1765
- return s.defaultedQueryOptions.notifyOnChangeProps ? i : s.observer.trackResult(i, (n) => {
1766
- e.forEach((o) => {
1767
- o.observer.trackProp(n);
1768
- });
1769
- });
1770
- });
1771
- }
1772
- #f(t, e) {
1773
- return e ? ((!this.#n || this.#t !== this.#a || e !== this.#o) && (this.#o = e, this.#a = this.#t, this.#n = K(
1774
- this.#n,
1775
- e(t)
1776
- )), this.#n) : t;
1777
- }
1778
- #c(t) {
1779
- const e = new Map(
1780
- this.#r.map((r) => [r.options.queryHash, r])
1781
- ), s = [];
1782
- return t.forEach((r) => {
1783
- const i = this.#e.defaultQueryOptions(r), n = e.get(i.queryHash);
1784
- n ? s.push({
1785
- defaultedQueryOptions: i,
1786
- observer: n
1787
- }) : s.push({
1788
- defaultedQueryOptions: i,
1789
- observer: new L(this.#e, i)
1790
- });
1791
- }), s;
1792
- }
1793
- #h(t, e) {
1794
- const s = this.#r.indexOf(t);
1795
- s !== -1 && (this.#t = we(this.#t, s, e), this.#u());
1796
- }
1797
- #u() {
1798
- if (this.hasListeners()) {
1799
- const t = this.#n, e = this.#l(this.#t, this.#d), s = this.#f(e, this.#i?.combine);
1800
- t !== s && g.batch(() => {
1801
- this.listeners.forEach((r) => {
1802
- r(this.#t);
1803
- });
1804
- });
1805
- }
1806
- }
1807
- }, Re = class extends x {
1808
- constructor(t = {}) {
1809
- super(), this.config = t, this.#e = /* @__PURE__ */ new Map();
1810
- }
1811
- #e;
1812
- build(t, e, s) {
1813
- const r = e.queryKey, i = e.queryHash ?? ot(r, e);
1814
- let n = this.get(i);
1815
- return n || (n = new de({
1816
- client: t,
1817
- queryKey: r,
1818
- queryHash: i,
1819
- options: t.defaultQueryOptions(e),
1820
- state: s,
1821
- defaultOptions: t.getQueryDefaults(r)
1822
- }), this.add(n)), n;
1823
- }
1824
- add(t) {
1825
- this.#e.has(t.queryHash) || (this.#e.set(t.queryHash, t), this.notify({
1826
- type: "added",
1827
- query: t
1828
- }));
1829
- }
1830
- remove(t) {
1831
- const e = this.#e.get(t.queryHash);
1832
- e && (t.destroy(), e === t && this.#e.delete(t.queryHash), this.notify({ type: "removed", query: t }));
1833
- }
1834
- clear() {
1835
- g.batch(() => {
1836
- this.getAll().forEach((t) => {
1837
- this.remove(t);
1838
- });
1839
- });
1840
- }
1841
- get(t) {
1842
- return this.#e.get(t);
1843
- }
1844
- getAll() {
1845
- return [...this.#e.values()];
1846
- }
1847
- find(t) {
1848
- const e = { exact: !0, ...t };
1849
- return this.getAll().find(
1850
- (s) => dt(e, s)
1851
- );
1852
- }
1853
- findAll(t = {}) {
1854
- const e = this.getAll();
1855
- return Object.keys(t).length > 0 ? e.filter((s) => dt(t, s)) : e;
1856
- }
1857
- notify(t) {
1858
- g.batch(() => {
1859
- this.listeners.forEach((e) => {
1860
- e(t);
1861
- });
1862
- });
1863
- }
1864
- onFocus() {
1865
- g.batch(() => {
1866
- this.getAll().forEach((t) => {
1867
- t.onFocus();
1868
- });
1869
- });
1870
- }
1871
- onOnline() {
1872
- g.batch(() => {
1873
- this.getAll().forEach((t) => {
1874
- t.onOnline();
1875
- });
1876
- });
1877
- }
1878
- }, Te = class {
1879
- #e;
1880
- #t;
1881
- #s;
1882
- #i;
1883
- #r;
1884
- #n;
1885
- #o;
1886
- #a;
1887
- constructor(t = {}) {
1888
- this.#e = t.queryCache || new Re(), this.#t = t.mutationCache || new be(), this.#s = t.defaultOptions || {}, this.#i = /* @__PURE__ */ new Map(), this.#r = /* @__PURE__ */ new Map(), this.#n = 0;
1889
- }
1890
- mount() {
1891
- this.#n++, this.#n === 1 && (this.#o = ut.subscribe(async (t) => {
1892
- t && (await this.resumePausedMutations(), this.#e.onFocus());
1893
- }), this.#a = G.subscribe(async (t) => {
1894
- t && (await this.resumePausedMutations(), this.#e.onOnline());
1895
- }));
1896
- }
1897
- unmount() {
1898
- this.#n--, this.#n === 0 && (this.#o?.(), this.#o = void 0, this.#a?.(), this.#a = void 0);
1899
- }
1900
- isFetching(t) {
1901
- return this.#e.findAll({ ...t, fetchStatus: "fetching" }).length;
1902
- }
1903
- isMutating(t) {
1904
- return this.#t.findAll({ ...t, status: "pending" }).length;
1905
- }
1906
- /**
1907
- * Imperative (non-reactive) way to retrieve data for a QueryKey.
1908
- * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
1909
- *
1910
- * Hint: Do not use this function inside a component, because it won't receive updates.
1911
- * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
1912
- */
1913
- getQueryData(t) {
1914
- const e = this.defaultQueryOptions({ queryKey: t });
1915
- return this.#e.get(e.queryHash)?.state.data;
1916
- }
1917
- ensureQueryData(t) {
1918
- const e = this.defaultQueryOptions(t), s = this.#e.build(this, e), r = s.state.data;
1919
- return r === void 0 ? this.fetchQuery(t) : (t.revalidateIfStale && s.isStaleByTime(M(e.staleTime, s)) && this.prefetchQuery(e), Promise.resolve(r));
1920
- }
1921
- getQueriesData(t) {
1922
- return this.#e.findAll(t).map(({ queryKey: e, state: s }) => {
1923
- const r = s.data;
1924
- return [e, r];
1925
- });
1926
- }
1927
- setQueryData(t, e, s) {
1928
- const r = this.defaultQueryOptions({ queryKey: t }), n = this.#e.get(
1929
- r.queryHash
1930
- )?.state.data, o = Xt(e, n);
1931
- if (o !== void 0)
1932
- return this.#e.build(this, r).setData(o, { ...s, manual: !0 });
1933
- }
1934
- setQueriesData(t, e, s) {
1935
- return g.batch(
1936
- () => this.#e.findAll(t).map(({ queryKey: r }) => [
1937
- r,
1938
- this.setQueryData(r, e, s)
1939
- ])
1940
- );
1941
- }
1942
- getQueryState(t) {
1943
- const e = this.defaultQueryOptions({ queryKey: t });
1944
- return this.#e.get(
1945
- e.queryHash
1946
- )?.state;
1947
- }
1948
- removeQueries(t) {
1949
- const e = this.#e;
1950
- g.batch(() => {
1951
- e.findAll(t).forEach((s) => {
1952
- e.remove(s);
1953
- });
1954
- });
1955
- }
1956
- resetQueries(t, e) {
1957
- const s = this.#e;
1958
- return g.batch(() => (s.findAll(t).forEach((r) => {
1959
- r.reset();
1960
- }), this.refetchQueries(
1961
- {
1962
- type: "active",
1963
- ...t
1964
- },
1965
- e
1966
- )));
1967
- }
1968
- cancelQueries(t, e = {}) {
1969
- const s = { revert: !0, ...e }, r = g.batch(
1970
- () => this.#e.findAll(t).map((i) => i.cancel(s))
1971
- );
1972
- return Promise.all(r).then(b).catch(b);
1973
- }
1974
- invalidateQueries(t, e = {}) {
1975
- return g.batch(() => (this.#e.findAll(t).forEach((s) => {
1976
- s.invalidate();
1977
- }), t?.refetchType === "none" ? Promise.resolve() : this.refetchQueries(
1978
- {
1979
- ...t,
1980
- type: t?.refetchType ?? t?.type ?? "active"
1981
- },
1982
- e
1983
- )));
1984
- }
1985
- refetchQueries(t, e = {}) {
1986
- const s = {
1987
- ...e,
1988
- cancelRefetch: e.cancelRefetch ?? !0
1989
- }, r = g.batch(
1990
- () => this.#e.findAll(t).filter((i) => !i.isDisabled() && !i.isStatic()).map((i) => {
1991
- let n = i.fetch(void 0, s);
1992
- return s.throwOnError || (n = n.catch(b)), i.state.fetchStatus === "paused" ? Promise.resolve() : n;
1993
- })
1994
- );
1995
- return Promise.all(r).then(b);
1996
- }
1997
- fetchQuery(t) {
1998
- const e = this.defaultQueryOptions(t);
1999
- e.retry === void 0 && (e.retry = !1);
2000
- const s = this.#e.build(this, e);
2001
- return s.isStaleByTime(
2002
- M(e.staleTime, s)
2003
- ) ? s.fetch(e) : Promise.resolve(s.state.data);
2004
- }
2005
- prefetchQuery(t) {
2006
- return this.fetchQuery(t).then(b).catch(b);
2007
- }
2008
- fetchInfiniteQuery(t) {
2009
- return t.behavior = J(t.pages), this.fetchQuery(t);
2010
- }
2011
- prefetchInfiniteQuery(t) {
2012
- return this.fetchInfiniteQuery(t).then(b).catch(b);
2013
- }
2014
- ensureInfiniteQueryData(t) {
2015
- return t.behavior = J(t.pages), this.ensureQueryData(t);
2016
- }
2017
- resumePausedMutations() {
2018
- return G.isOnline() ? this.#t.resumePausedMutations() : Promise.resolve();
2019
- }
2020
- getQueryCache() {
2021
- return this.#e;
2022
- }
2023
- getMutationCache() {
2024
- return this.#t;
2025
- }
2026
- getDefaultOptions() {
2027
- return this.#s;
2028
- }
2029
- setDefaultOptions(t) {
2030
- this.#s = t;
2031
- }
2032
- setQueryDefaults(t, e) {
2033
- this.#i.set(T(t), {
2034
- queryKey: t,
2035
- defaultOptions: e
2036
- });
2037
- }
2038
- getQueryDefaults(t) {
2039
- const e = [...this.#i.values()], s = {};
2040
- return e.forEach((r) => {
2041
- _(t, r.queryKey) && Object.assign(s, r.defaultOptions);
2042
- }), s;
2043
- }
2044
- setMutationDefaults(t, e) {
2045
- this.#r.set(T(t), {
2046
- mutationKey: t,
2047
- defaultOptions: e
2048
- });
2049
- }
2050
- getMutationDefaults(t) {
2051
- const e = [...this.#r.values()], s = {};
2052
- return e.forEach((r) => {
2053
- _(t, r.mutationKey) && Object.assign(s, r.defaultOptions);
2054
- }), s;
2055
- }
2056
- defaultQueryOptions(t) {
2057
- if (t._defaulted)
2058
- return t;
2059
- const e = {
2060
- ...this.#s.queries,
2061
- ...this.getQueryDefaults(t.queryKey),
2062
- ...t,
2063
- _defaulted: !0
2064
- };
2065
- return e.queryHash || (e.queryHash = ot(
2066
- e.queryKey,
2067
- e
2068
- )), e.refetchOnReconnect === void 0 && (e.refetchOnReconnect = e.networkMode !== "always"), e.throwOnError === void 0 && (e.throwOnError = !!e.suspense), !e.networkMode && e.persister && (e.networkMode = "offlineFirst"), e.queryFn === I && (e.enabled = !1), e;
2069
- }
2070
- defaultMutationOptions(t) {
2071
- return t?._defaulted ? t : {
2072
- ...this.#s.mutations,
2073
- ...t?.mutationKey && this.getMutationDefaults(t.mutationKey),
2074
- ...t,
2075
- _defaulted: !0
2076
- };
2077
- }
2078
- clear() {
2079
- this.#e.clear(), this.#t.clear();
2080
- }
2081
- };
2082
- function Ie({
2083
- streamFn: t,
2084
- refetchMode: e = "reset",
2085
- reducer: s = (i, n) => Pt(i, n),
2086
- initialValue: r = []
2087
- }) {
2088
- return async (i) => {
2089
- const n = i.client.getQueryCache().find({ queryKey: i.queryKey, exact: !0 }), o = !!n && n.state.data !== void 0;
2090
- o && e === "reset" && n.setState({
2091
- status: "pending",
2092
- data: void 0,
2093
- error: null,
2094
- fetchStatus: "fetching"
2095
- });
2096
- let a = r;
2097
- const u = await t(i);
2098
- for await (const h of u) {
2099
- if (i.signal.aborted)
2100
- break;
2101
- (!o || e !== "replace") && i.client.setQueryData(
2102
- i.queryKey,
2103
- (c) => s(c === void 0 ? r : c, h)
2104
- ), a = s(a, h);
2105
- }
2106
- return o && e === "replace" && !i.signal.aborted && i.client.setQueryData(i.queryKey, a), i.client.getQueryData(i.queryKey);
2107
- };
2108
- }
2109
- var xe = Symbol("dataTagSymbol"), Ae = Symbol("dataTagErrorSymbol"), ke = Symbol("unsetMarker");
2110
- const ht = await C("react");
2111
- var Nt = ht.createContext(
2112
- void 0
2113
- ), Q = (t) => {
2114
- const e = ht.useContext(Nt);
2115
- if (t)
2116
- return t;
2117
- if (!e)
2118
- throw new Error("No QueryClient set, use QueryClientProvider to set one");
2119
- return e;
2120
- }, Ne = ({
2121
- client: t,
2122
- children: e
2123
- }) => (ht.useEffect(() => (t.mount(), () => {
2124
- t.unmount();
2125
- }), [t]), /* @__PURE__ */ Et.jsx(Nt.Provider, { value: t, children: e }));
2126
- const Ut = await C("react");
2127
- var jt = Ut.createContext(!1), _t = () => Ut.useContext(jt), Ue = jt.Provider;
2128
- const lt = await C("react");
2129
- function Kt() {
2130
- let t = !1;
2131
- return {
2132
- clearReset: () => {
2133
- t = !1;
2134
- },
2135
- reset: () => {
2136
- t = !0;
2137
- },
2138
- isReset: () => t
2139
- };
2140
- }
2141
- var Ht = lt.createContext(Kt()), Lt = () => lt.useContext(Ht), je = ({
2142
- children: t
2143
- }) => {
2144
- const [e] = lt.useState(() => Kt());
2145
- return /* @__PURE__ */ Et.jsx(Ht.Provider, { value: e, children: typeof t == "function" ? t(e) : t });
2146
- };
2147
- const Ee = await C("react");
2148
- var $t = (t, e) => {
2149
- (t.suspense || t.throwOnError || t.experimental_prefetchInRender) && (e.isReset() || (t.retryOnMount = !1));
2150
- }, zt = (t) => {
2151
- Ee.useEffect(() => {
2152
- t.clearReset();
2153
- }, [t]);
2154
- }, Vt = ({
2155
- result: t,
2156
- errorResetBoundary: e,
2157
- throwOnError: s,
2158
- query: r,
2159
- suspense: i
2160
- }) => t.isError && !e.isReset() && !t.isFetching && r && (i && t.data === void 0 || Ft(s, [t.error, r])), ft = (t, e) => e.state.data === void 0, Bt = (t) => {
2161
- if (t.suspense) {
2162
- const s = (i) => i === "static" ? i : Math.max(i ?? 1e3, 1e3), r = t.staleTime;
2163
- t.staleTime = typeof r == "function" ? (...i) => s(r(...i)) : s(r), typeof t.gcTime == "number" && (t.gcTime = Math.max(
2164
- t.gcTime,
2165
- 1e3
2166
- ));
2167
- }
2168
- }, Gt = (t, e) => t.isLoading && t.isFetching && !e, at = (t, e) => t?.suspense && e.isPending, Z = (t, e, s) => e.fetchOptimistic(t).catch(() => {
2169
- s.clearReset();
2170
- });
2171
- const N = await C("react");
2172
- function Ce({
2173
- queries: t,
2174
- ...e
2175
- }, s) {
2176
- const r = Q(s), i = _t(), n = Lt(), o = N.useMemo(
2177
- () => t.map((f) => {
2178
- const y = r.defaultQueryOptions(
2179
- f
2180
- );
2181
- return y._optimisticResults = i ? "isRestoring" : "optimistic", y;
2182
- }),
2183
- [t, r, i]
2184
- );
2185
- o.forEach((f) => {
2186
- Bt(f), $t(f, n);
2187
- }), zt(n);
2188
- const [a] = N.useState(
2189
- () => new Se(
2190
- r,
2191
- o,
2192
- e
2193
- )
2194
- ), [u, h, c] = a.getOptimisticResult(
2195
- o,
2196
- e.combine
2197
- ), d = !i && e.subscribed !== !1;
2198
- N.useSyncExternalStore(
2199
- N.useCallback(
2200
- (f) => d ? a.subscribe(g.batchCalls(f)) : b,
2201
- [a, d]
2202
- ),
2203
- () => a.getCurrentResult(),
2204
- () => a.getCurrentResult()
2205
- ), N.useEffect(() => {
2206
- a.setQueries(
2207
- o,
2208
- e
2209
- );
2210
- }, [o, e, a]);
2211
- const m = u.some(
2212
- (f, y) => at(o[y], f)
2213
- ) ? u.flatMap((f, y) => {
2214
- const p = o[y];
2215
- if (p) {
2216
- const O = new L(r, p);
2217
- if (at(p, f))
2218
- return Z(p, O, n);
2219
- Gt(f, i) && Z(p, O, n);
2220
- }
2221
- return [];
2222
- }) : [];
2223
- if (m.length > 0)
2224
- throw Promise.all(m);
2225
- const v = u.find(
2226
- (f, y) => {
2227
- const p = o[y];
2228
- return p && Vt({
2229
- result: f,
2230
- errorResetBoundary: n,
2231
- throwOnError: p.throwOnError,
2232
- query: r.getQueryCache().get(p.queryHash),
2233
- suspense: p.suspense
2234
- });
2235
- }
2236
- );
2237
- if (v?.error)
2238
- throw v.error;
2239
- return h(c());
2240
- }
2241
- const B = await C("react");
2242
- function X(t, e, s) {
2243
- if (process.env.NODE_ENV !== "production" && (typeof t != "object" || Array.isArray(t)))
2244
- throw new Error(
2245
- 'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
2246
- );
2247
- const r = _t(), i = Lt(), n = Q(s), o = n.defaultQueryOptions(t);
2248
- n.getDefaultOptions().queries?._experimental_beforeQuery?.(
2249
- o
2250
- ), process.env.NODE_ENV !== "production" && (o.queryFn || console.error(
2251
- `[${o.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`
2252
- )), o._optimisticResults = r ? "isRestoring" : "optimistic", Bt(o), $t(o, i), zt(i);
2253
- const a = !n.getQueryCache().get(o.queryHash), [u] = B.useState(
2254
- () => new e(
2255
- n,
2256
- o
2257
- )
2258
- ), h = u.getOptimisticResult(o), c = !r && t.subscribed !== !1;
2259
- if (B.useSyncExternalStore(
2260
- B.useCallback(
2261
- (d) => {
2262
- const l = c ? u.subscribe(g.batchCalls(d)) : b;
2263
- return u.updateResult(), l;
2264
- },
2265
- [u, c]
2266
- ),
2267
- () => u.getCurrentResult(),
2268
- () => u.getCurrentResult()
2269
- ), B.useEffect(() => {
2270
- u.setOptions(o);
2271
- }, [o, u]), at(o, h))
2272
- throw Z(o, u, i);
2273
- if (Vt({
2274
- result: h,
2275
- errorResetBoundary: i,
2276
- throwOnError: o.throwOnError,
2277
- query: n.getQueryCache().get(o.queryHash),
2278
- suspense: o.suspense
2279
- }))
2280
- throw h.error;
2281
- return n.getDefaultOptions().queries?._experimental_afterQuery?.(
2282
- o,
2283
- h
2284
- ), o.experimental_prefetchInRender && !q && Gt(h, r) && (a ? (
2285
- // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
2286
- Z(o, u, i)
2287
- ) : (
2288
- // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
2289
- n.getQueryCache().get(o.queryHash)?.promise
2290
- ))?.catch(b).finally(() => {
2291
- u.updateResult();
2292
- }), o.notifyOnChangeProps ? h : u.trackResult(h);
2293
- }
2294
- function _e(t, e) {
2295
- return X(t, L, e);
2296
- }
2297
- function Ke(t, e) {
2298
- return process.env.NODE_ENV !== "production" && t.queryFn === I && console.error("skipToken is not allowed for useSuspenseQuery"), X(
2299
- {
2300
- ...t,
2301
- enabled: !0,
2302
- suspense: !0,
2303
- throwOnError: ft,
2304
- placeholderData: void 0
2305
- },
2306
- L,
2307
- e
2308
- );
2309
- }
2310
- function He(t, e) {
2311
- return process.env.NODE_ENV !== "production" && t.queryFn === I && console.error("skipToken is not allowed for useSuspenseInfiniteQuery"), X(
2312
- {
2313
- ...t,
2314
- enabled: !0,
2315
- suspense: !0,
2316
- throwOnError: ft
2317
- },
2318
- At,
2319
- e
2320
- );
2321
- }
2322
- function Le(t, e) {
2323
- return Ce(
2324
- {
2325
- ...t,
2326
- queries: t.queries.map((s) => (process.env.NODE_ENV !== "production" && s.queryFn === I && console.error("skipToken is not allowed for useSuspenseQueries"), {
2327
- ...s,
2328
- suspense: !0,
2329
- throwOnError: ft,
2330
- enabled: !0,
2331
- placeholderData: void 0
2332
- }))
2333
- },
2334
- e
2335
- );
2336
- }
2337
- function $e(t, e) {
2338
- const s = Q(e);
2339
- s.getQueryState(t.queryKey) || s.prefetchQuery(t);
2340
- }
2341
- function ze(t, e) {
2342
- const s = Q(e);
2343
- s.getQueryState(t.queryKey) || s.prefetchInfiniteQuery(t);
2344
- }
2345
- function Ve(t) {
2346
- return t;
2347
- }
2348
- function Be(t) {
2349
- return t;
2350
- }
2351
- const Y = await C("react");
2352
- var Ge = ({
2353
- children: t,
2354
- options: e = {},
2355
- state: s,
2356
- queryClient: r
2357
- }) => {
2358
- const i = Q(r), n = Y.useRef(e);
2359
- n.current = e;
2360
- const o = Y.useMemo(() => {
2361
- if (s) {
2362
- if (typeof s != "object")
2363
- return;
2364
- const a = i.getQueryCache(), u = s.queries || [], h = [], c = [];
2365
- for (const d of u) {
2366
- const l = a.get(d.queryHash);
2367
- l ? (d.state.dataUpdatedAt > l.state.dataUpdatedAt || d.promise && l.state.status !== "pending" && l.state.fetchStatus !== "fetching" && d.dehydratedAt !== void 0 && d.dehydratedAt > l.state.dataUpdatedAt) && c.push(d) : h.push(d);
2368
- }
2369
- if (h.length > 0 && gt(i, { queries: h }, n.current), c.length > 0)
2370
- return c;
2371
- }
2372
- }, [i, s]);
2373
- return Y.useEffect(() => {
2374
- o && gt(i, { queries: o }, n.current);
2375
- }, [i, o]), t;
2376
- };
2377
- const St = await C("react");
2378
- function We(t, e) {
2379
- const s = Q(e), r = s.getQueryCache();
2380
- return St.useSyncExternalStore(
2381
- St.useCallback(
2382
- (i) => r.subscribe(g.batchCalls(i)),
2383
- [r]
2384
- ),
2385
- () => s.isFetching(t),
2386
- () => s.isFetching(t)
2387
- );
2388
- }
2389
- const U = await C("react");
2390
- function Je(t, e) {
2391
- const s = Q(e);
2392
- return Pe(
2393
- { filters: { ...t, status: "pending" } },
2394
- s
2395
- ).length;
2396
- }
2397
- function Rt(t, e) {
2398
- return t.findAll(e.filters).map(
2399
- (s) => e.select ? e.select(s) : s.state
2400
- );
2401
- }
2402
- function Pe(t = {}, e) {
2403
- const s = Q(e).getMutationCache(), r = U.useRef(t), i = U.useRef(null);
2404
- return i.current || (i.current = Rt(s, t)), U.useEffect(() => {
2405
- r.current = t;
2406
- }), U.useSyncExternalStore(
2407
- U.useCallback(
2408
- (n) => s.subscribe(() => {
2409
- const o = K(
2410
- i.current,
2411
- Rt(s, r.current)
2412
- );
2413
- i.current !== o && (i.current = o, g.schedule(n));
2414
- }),
2415
- [s]
2416
- ),
2417
- () => i.current,
2418
- () => i.current
2419
- );
2420
- }
2421
- const j = await C("react");
2422
- function Ze(t, e) {
2423
- const s = Q(e), [r] = j.useState(
2424
- () => new Oe(
2425
- s,
2426
- t
2427
- )
2428
- );
2429
- j.useEffect(() => {
2430
- r.setOptions(t);
2431
- }, [r, t]);
2432
- const i = j.useSyncExternalStore(
2433
- j.useCallback(
2434
- (o) => r.subscribe(g.batchCalls(o)),
2435
- [r]
2436
- ),
2437
- () => r.getCurrentResult(),
2438
- () => r.getCurrentResult()
2439
- ), n = j.useCallback(
2440
- (o, a) => {
2441
- r.mutate(o, a).catch(b);
2442
- },
2443
- [r]
2444
- );
2445
- if (i.error && Ft(r.options.throwOnError, [i.error]))
2446
- throw i.error;
2447
- return { ...i, mutate: n, mutateAsync: i.mutate };
2448
- }
2449
- function Xe(t) {
2450
- return t;
2451
- }
2452
- function Ye(t, e) {
2453
- return X(
2454
- t,
2455
- At,
2456
- e
2457
- );
2458
- }
2459
- export {
2460
- W as CancelledError,
2461
- Ge as HydrationBoundary,
2462
- At as InfiniteQueryObserver,
2463
- Ue as IsRestoringProvider,
2464
- me as Mutation,
2465
- be as MutationCache,
2466
- Oe as MutationObserver,
2467
- Se as QueriesObserver,
2468
- de as Query,
2469
- Re as QueryCache,
2470
- Te as QueryClient,
2471
- Nt as QueryClientContext,
2472
- Ne as QueryClientProvider,
2473
- je as QueryErrorResetBoundary,
2474
- L as QueryObserver,
2475
- Ae as dataTagErrorSymbol,
2476
- xe as dataTagSymbol,
2477
- ce as defaultScheduler,
2478
- ae as defaultShouldDehydrateMutation,
2479
- oe as defaultShouldDehydrateQuery,
2480
- De as dehydrate,
2481
- Ie as experimental_streamedQuery,
2482
- ut as focusManager,
2483
- T as hashKey,
2484
- gt as hydrate,
2485
- Be as infiniteQueryOptions,
2486
- qe as isCancelledError,
2487
- q as isServer,
2488
- Me as keepPreviousData,
2489
- pt as matchMutation,
2490
- dt as matchQuery,
2491
- Xe as mutationOptions,
2492
- b as noop,
2493
- g as notifyManager,
2494
- G as onlineManager,
2495
- _ as partialMatchKey,
2496
- Ve as queryOptions,
2497
- K as replaceEqualDeep,
2498
- Ft as shouldThrowError,
2499
- I as skipToken,
2500
- D as timeoutManager,
2501
- ke as unsetMarker,
2502
- Ye as useInfiniteQuery,
2503
- We as useIsFetching,
2504
- Je as useIsMutating,
2505
- _t as useIsRestoring,
2506
- Ze as useMutation,
2507
- Pe as useMutationState,
2508
- ze as usePrefetchInfiniteQuery,
2509
- $e as usePrefetchQuery,
2510
- Ce as useQueries,
2511
- _e as useQuery,
2512
- Q as useQueryClient,
2513
- Lt as useQueryErrorResetBoundary,
2514
- He as useSuspenseInfiniteQuery,
2515
- Le as useSuspenseQueries,
2516
- Ke as useSuspenseQuery
2517
- };