@uniqbit/mate-core 1.0.0-canary.9 → 1.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 (232) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +5 -4
  3. package/src/cli/commands/artifact/delivery/link.ts +1 -1
  4. package/src/cli/commands/artifact/delivery/output.ts +10 -1
  5. package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
  6. package/src/cli/commands/artifact/delivery/submit.ts +9 -4
  7. package/src/cli/commands/artifact/delivery/take.ts +12 -9
  8. package/src/cli/commands/artifact/finish/command.ts +16 -14
  9. package/src/cli/commands/artifact/finish/engine.ts +8 -8
  10. package/src/cli/commands/artifact/project/command.ts +2 -3
  11. package/src/cli/commands/companion/hub.ts +11 -6
  12. package/src/cli/commands/companion/link.ts +173 -46
  13. package/src/cli/commands/report/contract.ts +0 -17
  14. package/src/cli/commands/studio/access.ts +4 -0
  15. package/src/cli/commands/studio/actions.ts +35 -2
  16. package/src/cli/commands/studio/mcp-manager.ts +162 -0
  17. package/src/cli/commands/studio/routes.ts +12 -0
  18. package/src/cli/commands/studio/selection.ts +44 -11
  19. package/src/cli/commands/studio/server.ts +246 -2
  20. package/src/cli/commands/studio/services.ts +26 -0
  21. package/src/cli/commands/studio/terminal-launch.ts +21 -4
  22. package/src/cli/commands/studio/terminal.ts +3 -14
  23. package/src/cli/commands/studio/work-requests.ts +9 -0
  24. package/src/cli/commands/studio/work.ts +473 -0
  25. package/src/cli/commands/vscode/release-vsix.json +2 -2
  26. package/src/cli/commands/working/cleanup.ts +1 -18
  27. package/src/cli/companion-link-wizard.tsx +158 -91
  28. package/src/cli/usage.ts +1 -1
  29. package/src/lib/agent-credential.ts +131 -0
  30. package/src/lib/credential-kinds.ts +7 -0
  31. package/src/lib/delivery/merge-git.ts +16 -0
  32. package/src/lib/delivery/record-delivery.ts +12 -6
  33. package/src/lib/delivery/record.ts +5 -0
  34. package/src/lib/delivery/refresh.ts +34 -6
  35. package/src/lib/delivery/staging/refs.ts +9 -4
  36. package/src/lib/delivery/staging/submit.ts +81 -22
  37. package/src/lib/mcp-manager/resolve.ts +27 -9
  38. package/src/lib/mcp-manager/store.ts +35 -11
  39. package/src/lib/mcp-manager/types.ts +14 -0
  40. package/src/lib/mcp-manager/validate.ts +6 -10
  41. package/src/lib/opencode-server.ts +2 -17
  42. package/src/lib/orchestrator/repo-local-store.ts +14 -0
  43. package/src/lib/orchestrator/repository-link.ts +80 -52
  44. package/src/lib/orchestrator/root-context.ts +17 -1
  45. package/src/lib/studio-chat/agent.ts +139 -0
  46. package/src/lib/studio-chat/companion-context.ts +136 -0
  47. package/src/lib/studio-chat/credential.ts +79 -0
  48. package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
  49. package/src/lib/studio-chat/host-sandbox.ts +578 -0
  50. package/src/lib/studio-chat/prepare-bridges.ts +95 -0
  51. package/src/lib/studio-chat/session.ts +15 -0
  52. package/src/lib/studio-chat/turns.ts +112 -0
  53. package/src/lib/workset/claims.ts +85 -0
  54. package/src/lib/workset/execution.ts +71 -0
  55. package/src/lib/workset/git-transaction.ts +74 -0
  56. package/src/lib/workset/groups.ts +176 -0
  57. package/src/lib/workset/inventory.ts +196 -0
  58. package/src/lib/workset/projection.ts +237 -0
  59. package/src/lib/workset/record.ts +101 -36
  60. package/src/lib/workset/repositories.ts +24 -0
  61. package/src/lib/workset/sharing.ts +951 -0
  62. package/src/lib/workset/stages.ts +50 -14
  63. package/src/lib/workset/transactions.ts +158 -0
  64. package/src/runtime/companion-git-state.ts +1 -0
  65. package/src/runtime/companion-guidance.ts +2 -2
  66. package/src/runtime/forge-remote.ts +6 -0
  67. package/src/runtime/host-process.ts +28 -0
  68. package/src/runtime/secret-guard.ts +18 -1
  69. package/src/runtime/secret-patterns.ts +4 -3
  70. package/src/runtime/submitted-arrivals.ts +28 -2
  71. package/src/runtime/write-atomic.ts +2 -2
  72. package/src/studio.ts +52 -8
  73. package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
  74. package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
  75. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
  76. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
  77. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
  78. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
  79. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
  80. package/src/tools/setup/capabilities/mcp-manager.ts +1 -2
  81. package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
  82. package/src/tools/setup/plugins/gitignore.ts +1 -0
  83. package/src/tools/setup/providers/claude-format.ts +1 -5
  84. package/src/tools/setup/providers/claude.ts +28 -3
  85. package/src/tools/setup/providers/opencode.ts +7 -18
  86. package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
  87. package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
  88. package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
  89. package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
  90. package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
  91. package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
  92. package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
  93. package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
  94. package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
  95. package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
  96. package/studio-dist/client/assets/{companion-view-C1F0_jbt.js → companion-view-B54_Lj0S.js} +1 -1
  97. package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
  98. package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
  99. package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
  100. package/studio-dist/client/assets/{getting-started-BN4aTpsz.js → getting-started-CAszmdDJ.js} +1 -1
  101. package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
  102. package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
  103. package/studio-dist/client/assets/{graph-canvas-Be5qgdDt.js → graph-canvas-BdNk2F9O.js} +1 -1
  104. package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
  105. package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
  106. package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
  107. package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
  108. package/studio-dist/client/assets/{markdown-view-dku7MGPn.js → markdown-view-CJ8JsLb7.js} +1 -1
  109. package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
  110. package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
  111. package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
  112. package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
  113. package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
  114. package/studio-dist/client/assets/{prepaint-BkoDSw5X.js → prepaint-sD_LlrDN.js} +1 -1
  115. package/studio-dist/client/assets/{queries-CMvC2OkU.js → queries-COL925ML.js} +1 -1
  116. package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
  117. package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
  118. package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
  119. package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
  120. package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
  121. package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
  122. package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
  123. package/studio-dist/client/assets/{specs-Bqd1ajyD.js → specs-C_tZnAvF.js} +1 -1
  124. package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
  125. package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
  126. package/studio-dist/client/assets/{store-BYnEU33C.js → store-pY9gU4uS.js} +1 -1
  127. package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
  128. package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
  129. package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
  130. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
  131. package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
  132. package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
  133. package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
  134. package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
  135. package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
  136. package/studio-dist/client/assets/{warnings-Cnw99ugO.js → warnings-D7YY1HSG.js} +1 -1
  137. package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
  138. package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
  139. package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
  140. package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
  141. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-CS3QRY4Q.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
  142. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
  143. package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
  144. package/studio-dist/server/assets/{cn-DWFJaP_9.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
  145. package/studio-dist/server/assets/{button-Ct_WeYLc.js → button-BqA1urbl.js} +14 -7
  146. package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
  147. package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
  148. package/studio-dist/server/assets/{combobox-17vO5Uz8.js → combobox-iTjvPCtS.js} +7 -6
  149. package/studio-dist/server/assets/{companion-view-JkxnGLlp.js → companion-view-DIQ6AFIY.js} +2 -2
  150. package/studio-dist/server/assets/{companions-YNLsbnch.js → companions-aVwjRL8j.js} +1 -1
  151. package/studio-dist/server/assets/{fields-VytPpqBq.js → fields-BMap2_Ju.js} +10 -3
  152. package/studio-dist/server/assets/{friction-BW86PCPM.js → friction-BER50hoD.js} +2 -2
  153. package/studio-dist/server/assets/{friction-B6osqFSm.js → friction-BPs9KWdq.js} +8 -8
  154. package/studio-dist/server/assets/{getting-started-CFHSeX5h.js → getting-started-DGfRVmZ_.js} +2 -2
  155. package/studio-dist/server/assets/{getting-started._topic-BK2eU6AS.js → getting-started._topic-BgrBA4Vj.js} +2 -2
  156. package/studio-dist/server/assets/{getting-started.index-DZLuXnNO.js → getting-started.index-BaFfQ9Mn.js} +2 -2
  157. package/studio-dist/server/assets/{graph-BJVZBevL.js → graph-Cgzlrv3P.js} +8 -8
  158. package/studio-dist/server/assets/{graph-DGZHV-Ek.js → graph-DODpuOy_.js} +1 -1
  159. package/studio-dist/server/assets/{graph-canvas-lrNT6jbl.js → graph-canvas-DW_zU1nA.js} +2 -2
  160. package/studio-dist/server/assets/{guides-_G8Vucsk.js → guides-CA_EMG7E.js} +1 -1
  161. package/studio-dist/server/assets/{guides-CEwLOZb9.js → guides-D0SpoD32.js} +1 -1
  162. package/studio-dist/server/assets/{guides.server-ZWFKX2XJ.js → guides.server-DJjQuy03.js} +1 -1
  163. package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
  164. package/studio-dist/server/assets/{markdown-view-Bmjghg_Z.js → markdown-view-CvVBGMZV.js} +1 -1
  165. package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
  166. package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
  167. package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
  168. package/studio-dist/server/assets/{panel-DvRjyil3.js → panel-D1K6Bsux.js} +4 -32
  169. package/studio-dist/server/assets/{plugins._service._view-B32LzraG.js → plugins._service._view-DdO1nELF.js} +4 -4
  170. package/studio-dist/server/assets/{prepaint-BEHwKl51.js → prepaint-BB3dwSmz.js} +1 -1
  171. package/studio-dist/server/assets/{queries-D6Vq0AuZ.js → queries-BwiDxQy5.js} +1 -1
  172. package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
  173. package/studio-dist/server/assets/{reports-Dn92pLap.js → reports-9Pr7Bz6o.js} +7 -7
  174. package/studio-dist/server/assets/{reports-DDaH5k0H.js → reports-Cc9M3phM.js} +1 -1
  175. package/studio-dist/server/assets/{router-Bjf4S9tO.js → router-DcWe0J7Y.js} +827 -548
  176. package/studio-dist/server/assets/{routes-B4sNiE0X.js → routes-BEXxl0py.js} +8 -8
  177. package/studio-dist/server/assets/{search-DKeJRvg8.js → search-bltT7gwy.js} +39 -7
  178. package/studio-dist/server/assets/{select-CVHYL7oR.js → select-CZvHgGCi.js} +7 -6
  179. package/studio-dist/server/assets/{shell-BxbYYaAk.js → shell-BQ0vMKXN.js} +13 -4
  180. package/studio-dist/server/assets/{skills-Bj8eOgzR.js → skills-Be_52h0i.js} +1 -1
  181. package/studio-dist/server/assets/{skills-B4-0qpqN.js → skills-BpGGUl6L.js} +8 -8
  182. package/studio-dist/server/assets/{specs-rfMug6qW.js → specs-CCGgXE-V.js} +5 -5
  183. package/studio-dist/server/assets/{specs-view-qi1SE1Sl.js → specs-view-DtL5JxYM.js} +12 -11
  184. package/studio-dist/server/assets/{steps-rger6HJc.js → steps-BWFSO6dM.js} +1 -1
  185. package/studio-dist/server/assets/{store-Dg9T7oWs.js → store-X7yLPp7v.js} +1 -1
  186. package/studio-dist/server/assets/{studio-queries-CeFfmIuM.js → studio-queries-ur1ygXi3.js} +117 -13
  187. package/studio-dist/server/assets/{studio-D79JzDLc.js → studio-qzH-UETC.js} +209 -180
  188. package/studio-dist/server/assets/{usage-Dw_UQFX-.js → usage-C1o0DLzS.js} +1 -1
  189. package/studio-dist/server/assets/{usage-BJgYWRCX.js → usage-DWbSPrPD.js} +10 -9
  190. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-ciS_sEq3.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
  191. package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
  192. package/studio-dist/server/assets/{useMutation-DnWK0PhO.js → useMutation-NjlA8oFY.js} +2 -2
  193. package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
  194. package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
  195. package/studio-dist/server/assets/{vault-BzarssiL.js → vault-B_kfi1h-.js} +1 -1
  196. package/studio-dist/server/assets/{vault-CvlrLd2H.js → vault-dL79JlKH.js} +8 -115
  197. package/studio-dist/server/assets/{views-CAxwKHMK.js → views-BSGH56lb.js} +3 -3
  198. package/studio-dist/server/assets/{warnings-BpVCugHm.js → warnings-DtUVPV-k.js} +2 -2
  199. package/studio-dist/server/assets/work-D789VXGH.js +110 -0
  200. package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
  201. package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
  202. package/studio-dist/server/assets/{workflow-BdrzcCt8.js → workflow-BOZ2sRYg.js} +9 -9
  203. package/studio-dist/server/server.js +3 -3
  204. package/wrappers/bin/openspec +87 -2
  205. package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
  206. package/studio-dist/client/assets/button-C9SQW3kI.js +0 -1
  207. package/studio-dist/client/assets/cn-DC80MJV0.js +0 -1
  208. package/studio-dist/client/assets/combobox-D7mKYCBb.js +0 -1
  209. package/studio-dist/client/assets/fields-CEep8IFT.js +0 -1
  210. package/studio-dist/client/assets/friction-D9dBU7WN.js +0 -1
  211. package/studio-dist/client/assets/getting-started-BDyGvHhc.js +0 -1
  212. package/studio-dist/client/assets/getting-started._topic-B9ajbF4o.js +0 -1
  213. package/studio-dist/client/assets/getting-started.index-CYiBPtb7.js +0 -1
  214. package/studio-dist/client/assets/graph-ah7ZXfTa.js +0 -2
  215. package/studio-dist/client/assets/guides-CsL0660B.js +0 -1
  216. package/studio-dist/client/assets/index-zmRH87D4.js +0 -40
  217. package/studio-dist/client/assets/panel-COgk0vP5.js +0 -1
  218. package/studio-dist/client/assets/plugins._service._view-Cn3WBHab.js +0 -1
  219. package/studio-dist/client/assets/reports-C_AqLBYH.js +0 -1
  220. package/studio-dist/client/assets/routes-BokQmHtC.js +0 -1
  221. package/studio-dist/client/assets/search-DxidNK2M.js +0 -1
  222. package/studio-dist/client/assets/select-CYFCbHUd.js +0 -1
  223. package/studio-dist/client/assets/skills-R3vttWHM.js +0 -1
  224. package/studio-dist/client/assets/specs-view-znqFPx9p.js +0 -1
  225. package/studio-dist/client/assets/steps-tVDWn7j6.js +0 -1
  226. package/studio-dist/client/assets/studio-ndtFcS2Y.js +0 -100
  227. package/studio-dist/client/assets/studio-queries-CkUSByy7.js +0 -2
  228. package/studio-dist/client/assets/usage-Kuhr8dSl.js +0 -55
  229. package/studio-dist/client/assets/useAnchoredPopupScrollLock-dc_kP4Go.js +0 -1
  230. package/studio-dist/client/assets/useMutation-CqtM9COw.js +0 -1
  231. package/studio-dist/client/assets/vault-CSP8kwRg.js +0 -1
  232. package/studio-dist/client/assets/workflow-BPJAmmZi.js +0 -1
@@ -1,2053 +1,3 @@
1
- import { n as require_react, o as __toESM, t as require_jsx_runtime } from "./jsx-runtime-Bt0s0YKS.js";
2
- import { $ as systemSetTimeoutZero, A as addConsumeAwareSignal, G as replaceData, J as shallowEqualObjects, M as addToStart, N as ensureQueryFn, P as fetchSignal, Q as timeUntilStale, R as isServer$1, U as noop, X as skipToken, Y as shouldThrowError, Z as sleep, et as timeoutManager, j as addToEnd, q as resolveQueryValue, z as isValidTimeout } from "./studio-queries-CeFfmIuM.js";
3
- // ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js
4
- var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
5
- var import_jsx_runtime = require_jsx_runtime();
6
- /**
7
- * The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
8
- */
9
- var QueryClientContext = import_react.createContext(void 0);
10
- /**
11
- * The `useQueryClient` hook returns the current `QueryClient` instance.
12
- * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
13
- * be used.
14
- * @returns The current `QueryClient` instance.
15
- * @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
16
- * component tree.
17
- */
18
- var useQueryClient = (queryClient) => {
19
- const client = import_react.useContext(QueryClientContext);
20
- if (queryClient) return queryClient;
21
- if (!client) throw new Error("No QueryClient set, use QueryClientProvider to set one");
22
- return client;
23
- };
24
- /**
25
- * Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
26
- * calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
27
- * focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
28
- * comes back online).
29
- * @param props - The `client` to provide, and the `children` that get access to it.
30
- * @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
31
- * @example
32
- * ```tsx
33
- * import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
34
- *
35
- * const queryClient = new QueryClient()
36
- *
37
- * function App() {
38
- * return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
39
- * }
40
- * ```
41
- */
42
- var QueryClientProvider = ({ client, children }) => {
43
- import_react.useEffect(() => {
44
- client.mount();
45
- return () => {
46
- client.unmount();
47
- };
48
- }, [client]);
49
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QueryClientContext.Provider, {
50
- value: client,
51
- children
52
- });
53
- };
54
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/environmentManager.js
55
- var isServerFn = () => isServer$1;
56
- /**
57
- * Returns whether the current runtime should be treated as a server environment.
58
- * @returns `true` if the runtime is treated as a server.
59
- */
60
- var isServer = () => isServerFn();
61
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/subscribable.js
62
- /**
63
- * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
64
- * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
65
- * Subclasses decide what a listener receives and when it is called.
66
- */
67
- var Subscribable = class {
68
- constructor() {
69
- this.listeners = /* @__PURE__ */ new Set();
70
- this.subscribe = this.subscribe.bind(this);
71
- }
72
- /**
73
- * Registers a listener to be called on every update this object notifies about. Returns a function
74
- * that removes the listener again — call it to stop listening. The base class never drops a listener
75
- * on its own, though some subclasses clear all of theirs in `destroy()`.
76
- * @param listener - Called on each update, with whatever the subclass passes to its subscribers.
77
- * @returns A function that removes the listener.
78
- * @example
79
- * ```ts
80
- * const unsubscribe = subscribable.subscribe(() => {
81
- * // react to the update
82
- * })
83
- *
84
- * unsubscribe()
85
- * ```
86
- */
87
- subscribe(listener) {
88
- this.listeners.add(listener);
89
- this.onSubscribe();
90
- return () => {
91
- this.listeners.delete(listener);
92
- this.onUnsubscribe();
93
- };
94
- }
95
- /**
96
- * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
97
- * @returns `true` if at least one listener is registered.
98
- */
99
- hasListeners() {
100
- return this.listeners.size > 0;
101
- }
102
- /**
103
- * Called after a listener is added. Does nothing here; subclasses override it, e.g. to start
104
- * tracking what they observe once the first listener subscribes.
105
- */
106
- onSubscribe() {}
107
- /**
108
- * Called after a listener is removed. Does nothing here; subclasses override it, e.g. to clean up
109
- * once the last listener unsubscribes.
110
- */
111
- onUnsubscribe() {}
112
- };
113
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/focusManager.js
114
- /**
115
- * The `FocusManager` manages the focus state within TanStack Query.
116
- *
117
- * It can be used to change the default event listeners or to manually change the focus state.
118
- */
119
- var FocusManager = class extends Subscribable {
120
- #focused;
121
- #cleanup;
122
- #setup;
123
- constructor() {
124
- super();
125
- this.#setup = (onFocus) => {
126
- if (typeof window !== "undefined" && window.addEventListener) {
127
- const listener = () => onFocus();
128
- window.addEventListener("visibilitychange", listener, false);
129
- return () => {
130
- window.removeEventListener("visibilitychange", listener);
131
- };
132
- }
133
- };
134
- }
135
- onSubscribe() {
136
- if (!this.#cleanup) this.setEventListener(this.#setup);
137
- }
138
- onUnsubscribe() {
139
- if (!this.hasListeners()) {
140
- this.#cleanup?.();
141
- this.#cleanup = void 0;
142
- }
143
- }
144
- /**
145
- * `setEventListener` can be used to set a custom event listener that will
146
- * be used to determine the focus state. The provided `setup` function
147
- * receives a `setFocused` callback: call it with a `boolean` to manually
148
- * set the focus state, or with no arguments to re-evaluate the current
149
- * focus state and notify subscribers.
150
- * @param setup - Receives the `setFocused` callback, registers the event listener, and may return
151
- * a cleanup function that is called when the listener is replaced or no longer needed.
152
- * @example
153
- * ```ts
154
- * import { focusManager } from '@tanstack/query-core'
155
- *
156
- * focusManager.setEventListener((handleFocus) => {
157
- * const listener = () => handleFocus()
158
- * // Listen to visibilitychange
159
- * if (typeof window !== 'undefined' && window.addEventListener) {
160
- * window.addEventListener('visibilitychange', listener, false)
161
- * }
162
- *
163
- * return () => {
164
- * // Be sure to unsubscribe if a new handler is set
165
- * window.removeEventListener('visibilitychange', listener)
166
- * }
167
- * })
168
- * ```
169
- */
170
- setEventListener(setup) {
171
- this.#setup = setup;
172
- this.#cleanup?.();
173
- this.#cleanup = setup((focused) => {
174
- if (typeof focused === "boolean") this.setFocused(focused);
175
- else this.onFocus();
176
- });
177
- }
178
- /**
179
- * `setFocused` can be used to manually set the focus state. Set `undefined`
180
- * to fall back to the default focus check.
181
- * @param focused - The focus state, or `undefined` to use the default focus check.
182
- * @example
183
- * ```ts
184
- * import { focusManager } from '@tanstack/query-core'
185
- *
186
- * // Set focused
187
- * focusManager.setFocused(true)
188
- *
189
- * // Set unfocused
190
- * focusManager.setFocused(false)
191
- *
192
- * // Fallback to the default focus check
193
- * focusManager.setFocused(undefined)
194
- * ```
195
- */
196
- setFocused(focused) {
197
- if (this.#focused !== focused) {
198
- this.#focused = focused;
199
- this.onFocus();
200
- }
201
- }
202
- /**
203
- * `onFocus` notifies all subscribed listeners with the current focus state.
204
- */
205
- onFocus() {
206
- const isFocused = this.isFocused();
207
- this.listeners.forEach((listener) => {
208
- listener(isFocused);
209
- });
210
- }
211
- /**
212
- * `isFocused` can be used to get the current focus state.
213
- * @returns The focus state set with `setFocused`, or otherwise whether the document is visible.
214
- */
215
- isFocused() {
216
- if (typeof this.#focused === "boolean") return this.#focused;
217
- return globalThis.document?.visibilityState !== "hidden";
218
- }
219
- };
220
- /**
221
- * Singleton instance of {@link FocusManager}, used to manage and observe the focus state within TanStack Query.
222
- */
223
- var focusManager = new FocusManager();
224
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/notifyManager.js
225
- /**
226
- * Default scheduling function used by the notify manager.
227
- * Schedules the callback with the system's `setTimeout(callback, 0)`.
228
- */
229
- var defaultScheduler = systemSetTimeoutZero;
230
- /**
231
- * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
232
- * single instance of it, exported as {@link notifyManager}.
233
- * @returns A new notify manager.
234
- */
235
- function createNotifyManager() {
236
- let queue = [];
237
- let transactions = 0;
238
- let notifyFn = (callback) => {
239
- callback();
240
- };
241
- let batchNotifyFn = (callback) => {
242
- callback();
243
- };
244
- let scheduleFn = defaultScheduler;
245
- const schedule = (callback) => {
246
- if (transactions) queue.push(callback);
247
- else scheduleFn(() => {
248
- notifyFn(callback);
249
- });
250
- };
251
- const flush = () => {
252
- const originalQueue = queue;
253
- queue = [];
254
- if (originalQueue.length) scheduleFn(() => {
255
- batchNotifyFn(() => {
256
- originalQueue.forEach((callback) => {
257
- notifyFn(callback);
258
- });
259
- });
260
- });
261
- };
262
- return {
263
- /**
264
- * Batches all updates scheduled inside the passed callback.
265
- * This is mainly used internally to optimize query client updating.
266
- * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
267
- * The return value of `callback` is passed through.
268
- * @param callback - The function to run in the batch.
269
- * @returns The return value of `callback`.
270
- */
271
- batch: (callback) => {
272
- let result;
273
- transactions++;
274
- try {
275
- result = callback();
276
- } finally {
277
- transactions--;
278
- if (!transactions) flush();
279
- }
280
- return result;
281
- },
282
- /**
283
- * All calls to the wrapped function will be batched.
284
- * @param callback - The function to wrap.
285
- * @returns A function that schedules a call to `callback` with the given arguments.
286
- */
287
- batchCalls: (callback) => {
288
- return (...args) => {
289
- schedule(() => {
290
- callback(...args);
291
- });
292
- };
293
- },
294
- /**
295
- * Schedules a function to be run on the next batch.
296
- * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
297
- */
298
- schedule,
299
- /**
300
- * Use this method to set a custom notify function.
301
- * This can be used to for example wrap notifications with `React.act` while running tests.
302
- * @param fn - Receives each notification callback and must call it.
303
- */
304
- setNotifyFunction: (fn) => {
305
- notifyFn = fn;
306
- },
307
- /**
308
- * Use this method to set a custom function to batch notifications together into a single tick.
309
- * Framework adapters use this to plug in their own batching primitive, so that a single query
310
- * update only triggers one re-render instead of one per subscriber.
311
- * @param fn - Receives a function that runs a batch of notifications and must call it.
312
- * @example
313
- * ```ts
314
- * import { notifyManager } from '@tanstack/query-core'
315
- * import { batch } from 'solid-js'
316
- *
317
- * notifyManager.setBatchNotifyFunction(batch)
318
- * ```
319
- */
320
- setBatchNotifyFunction: (fn) => {
321
- batchNotifyFn = fn;
322
- },
323
- /**
324
- * Configures a custom callback that schedules when the next batch runs.
325
- * The default behavior is `setTimeout(callback, 0)`.
326
- * @param fn - Receives a callback that runs the next batch, and schedules it.
327
- * @example
328
- * ```ts
329
- * import { notifyManager } from '@tanstack/query-core'
330
- *
331
- * // Schedule batches in the next microtask
332
- * notifyManager.setScheduler(queueMicrotask)
333
- *
334
- * // Schedule batches before the next frame is rendered
335
- * notifyManager.setScheduler(requestAnimationFrame)
336
- *
337
- * // Schedule batches some time in the future
338
- * notifyManager.setScheduler((cb) => setTimeout(cb, 10))
339
- * ```
340
- */
341
- setScheduler: (fn) => {
342
- scheduleFn = fn;
343
- }
344
- };
345
- }
346
- /**
347
- * Handles scheduling and batching callbacks in TanStack Query.
348
- */
349
- var notifyManager = createNotifyManager();
350
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/onlineManager.js
351
- /**
352
- * The `OnlineManager` manages the online state within TanStack Query. It can
353
- * be used to change the default event listeners or to manually change the
354
- * online state.
355
- *
356
- * By default, the `onlineManager` assumes an active network connection, and
357
- * listens to the `online` and `offline` events on the `window` object to
358
- * detect changes.
359
- */
360
- var OnlineManager = class extends Subscribable {
361
- #online = true;
362
- #cleanup;
363
- #setup;
364
- constructor() {
365
- super();
366
- this.#setup = (onOnline) => {
367
- if (typeof window !== "undefined" && window.addEventListener) {
368
- const onlineListener = () => onOnline(true);
369
- const offlineListener = () => onOnline(false);
370
- window.addEventListener("online", onlineListener, false);
371
- window.addEventListener("offline", offlineListener, false);
372
- return () => {
373
- window.removeEventListener("online", onlineListener);
374
- window.removeEventListener("offline", offlineListener);
375
- };
376
- }
377
- };
378
- }
379
- onSubscribe() {
380
- if (!this.#cleanup) this.setEventListener(this.#setup);
381
- }
382
- onUnsubscribe() {
383
- if (!this.hasListeners()) {
384
- this.#cleanup?.();
385
- this.#cleanup = void 0;
386
- }
387
- }
388
- /**
389
- * `setEventListener` can be used to set a custom event listener that will
390
- * be used to determine the online state. The provided `setup` function
391
- * receives a `setOnline` callback that should be called with a `boolean`
392
- * whenever the online state changes.
393
- * @param setup - Receives the `setOnline` callback, registers the event listener, and may return
394
- * a cleanup function that is called when the listener is replaced or no longer needed.
395
- * @example
396
- * ```ts
397
- * import NetInfo from '@react-native-community/netinfo'
398
- * import { onlineManager } from '@tanstack/query-core'
399
- *
400
- * onlineManager.setEventListener((setOnline) => {
401
- * return NetInfo.addEventListener((state) => {
402
- * setOnline(!!state.isConnected)
403
- * })
404
- * })
405
- * ```
406
- */
407
- setEventListener(setup) {
408
- this.#setup = setup;
409
- this.#cleanup?.();
410
- this.#cleanup = setup(this.setOnline.bind(this));
411
- }
412
- /**
413
- * `setOnline` can be used to manually set the online state.
414
- * @param online - The online state.
415
- * @example
416
- * ```ts
417
- * import { onlineManager } from '@tanstack/query-core'
418
- *
419
- * // Set to online
420
- * onlineManager.setOnline(true)
421
- *
422
- * // Set to offline
423
- * onlineManager.setOnline(false)
424
- * ```
425
- */
426
- setOnline(online) {
427
- if (this.#online !== online) {
428
- this.#online = online;
429
- this.listeners.forEach((listener) => {
430
- listener(online);
431
- });
432
- }
433
- }
434
- /**
435
- * `isOnline` can be used to get the current online state.
436
- * @returns `true` if online.
437
- */
438
- isOnline() {
439
- return this.#online;
440
- }
441
- };
442
- /**
443
- * Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.
444
- */
445
- var onlineManager = new OnlineManager();
446
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/retryer.js
447
- /**
448
- * The default `retryDelay`: doubles with every failure, starting at 1 second, up to 30 seconds.
449
- * @param failureCount - The number of failures so far.
450
- * @returns The delay before the next retry, in milliseconds.
451
- */
452
- function defaultRetryDelay(failureCount) {
453
- return Math.min(1e3 * 2 ** failureCount, 3e4);
454
- }
455
- /**
456
- * Checks whether a fetch can run for the given network mode.
457
- * @param networkMode - The `networkMode` option. Defaults to `'online'`.
458
- * @returns `true` if the network mode is not `'online'`, or if it is and the client is online.
459
- */
460
- function canFetch(networkMode) {
461
- return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
462
- }
463
- /**
464
- * The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via
465
- * `query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch
466
- * started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead
467
- * resolve with the promise of the fetch that triggered the cancellation.
468
- * @example
469
- * ```ts
470
- * query.cancel()
471
- *
472
- * try {
473
- * await query.promise
474
- * } catch (error) {
475
- * if (error instanceof CancelledError) {
476
- * // the fetch was cancelled, e.g. via `query.cancel()`
477
- * }
478
- * }
479
- * ```
480
- */
481
- var CancelledError = class extends Error {
482
- constructor(options) {
483
- super("CancelledError");
484
- this.revert = options?.revert;
485
- this.silent = options?.silent;
486
- }
487
- };
488
- /**
489
- * Creates a retryer, which runs a function and retries it on failure according to the `retry` and
490
- * `retryDelay` options. It pauses while the network mode doesn't allow fetching or `canRun` returns
491
- * `false`, and can be cancelled. Queries and mutations use it to run their `queryFn` and
492
- * `mutationFn`.
493
- * @param config - The function to run, the retry options, and the callbacks for failures, pausing,
494
- * continuing, and cancellation.
495
- * @returns The retryer, whose `promise` settles with the result of the function.
496
- */
497
- function createRetryer(config) {
498
- let isRetryCancelled = false;
499
- let failureCount = 0;
500
- let continueFn;
501
- let status = "pending";
502
- let promiseResolve;
503
- let promiseReject;
504
- const promise = new Promise((resolve, reject) => {
505
- promiseResolve = resolve;
506
- promiseReject = reject;
507
- });
508
- promise.catch(noop);
509
- const isResolved = () => status !== "pending";
510
- const cancel = (cancelOptions) => {
511
- if (!isResolved()) {
512
- const error = new CancelledError(cancelOptions);
513
- reject(error);
514
- config.onCancel?.(error);
515
- }
516
- };
517
- const cancelRetry = () => {
518
- isRetryCancelled = true;
519
- };
520
- const continueRetry = () => {
521
- isRetryCancelled = false;
522
- };
523
- const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
524
- const canStart = () => canFetch(config.networkMode) && config.canRun();
525
- const resolve = (value) => {
526
- if (!isResolved()) {
527
- continueFn?.();
528
- status = "resolved";
529
- promiseResolve(value);
530
- }
531
- };
532
- const reject = (value) => {
533
- if (!isResolved()) {
534
- continueFn?.();
535
- status = "rejected";
536
- promiseReject(value);
537
- }
538
- };
539
- const pause = (canResume) => {
540
- return new Promise((continueResolve) => {
541
- continueFn = (value) => {
542
- if (isResolved() || canResume()) continueResolve(value);
543
- };
544
- config.onPause?.();
545
- }).then(() => {
546
- continueFn = void 0;
547
- if (!isResolved()) config.onContinue?.();
548
- });
549
- };
550
- const run = () => {
551
- if (isResolved()) return;
552
- let promiseOrValue;
553
- const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
554
- try {
555
- promiseOrValue = initialPromise ?? config.fn();
556
- } catch (error) {
557
- promiseOrValue = Promise.reject(error);
558
- }
559
- Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
560
- if (isResolved()) return;
561
- const retry = config.retry ?? (isServer() ? 0 : 3);
562
- const retryDelay = config.retryDelay ?? defaultRetryDelay;
563
- const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
564
- const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
565
- if (isRetryCancelled || !shouldRetry) {
566
- reject(error);
567
- return;
568
- }
569
- failureCount++;
570
- config.onFail?.(failureCount, error);
571
- sleep(delay).then(() => {
572
- return isResolved() || canContinue() ? void 0 : pause(canContinue);
573
- }).then(() => {
574
- if (isRetryCancelled) reject(error);
575
- else run();
576
- });
577
- });
578
- };
579
- return {
580
- promise,
581
- status: () => status,
582
- cancel,
583
- continue: () => {
584
- continueFn?.();
585
- return promise;
586
- },
587
- cancelRetry,
588
- continueRetry,
589
- canStart,
590
- start: () => {
591
- if (canStart()) run();
592
- else pause(canStart).then(run);
593
- return promise;
594
- }
595
- };
596
- }
597
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/removable.js
598
- /**
599
- * The base class for cache entries that are garbage collected once nothing is using them —
600
- * `Query` and `Mutation` both extend it. `gcTime` controls how long an unused entry is kept.
601
- */
602
- var Removable = class {
603
- #gcTimeout;
604
- /**
605
- * Clears the pending garbage collection timeout, so the entry is no longer scheduled for removal.
606
- * A subclass may override this to release what it holds on to as well — `Query` also cancels any
607
- * in-flight fetch.
608
- */
609
- destroy() {
610
- this.clearGcTimeout();
611
- }
612
- /**
613
- * Schedules the entry to be removed from its cache after `gcTime`, replacing any timeout scheduled
614
- * before. Nothing is scheduled if `gcTime` is `Infinity`.
615
- */
616
- scheduleGc() {
617
- this.clearGcTimeout();
618
- if (isValidTimeout(this.gcTime)) this.#gcTimeout = timeoutManager.setTimeout(() => {
619
- this.optionalRemove();
620
- }, this.gcTime);
621
- }
622
- /**
623
- * Updates `gcTime`, keeping the longest one seen so far. Without a value, it defaults to 5 minutes
624
- * on the client and `Infinity` on the server.
625
- * @param newGcTime - The `gcTime` from the latest options, if any.
626
- */
627
- updateGcTime(newGcTime) {
628
- this.gcTime = Math.max(this.gcTime || 0, newGcTime ?? (isServer() ? Infinity : 3e5));
629
- }
630
- /**
631
- * Cancels the scheduled removal, if there is one.
632
- */
633
- clearGcTimeout() {
634
- if (this.#gcTimeout !== void 0) {
635
- timeoutManager.clearTimeout(this.#gcTimeout);
636
- this.#gcTimeout = void 0;
637
- }
638
- }
639
- };
640
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
641
- /**
642
- * Creates the behavior that fetches the pages of an infinite query: the next or previous page for
643
- * `fetchNextPage`/`fetchPreviousPage`, or all pages again from the start on a refetch.
644
- * @param pages - The number of pages to fetch from the start when all pages are fetched again,
645
- * e.g. from the `pages` option of `queryClient.infiniteQuery`. Defaults to the number of cached
646
- * pages.
647
- * @returns The query behavior to set on an infinite query.
648
- */
649
- function infiniteQueryBehavior(pages) {
650
- return { onFetch: (context, query) => {
651
- const options = context.options;
652
- const direction = context.fetchOptions?.meta?.fetchMore?.direction;
653
- const oldPages = context.state.data?.pages || [];
654
- const oldPageParams = context.state.data?.pageParams || [];
655
- let result = {
656
- pages: [],
657
- pageParams: []
658
- };
659
- let currentPage = 0;
660
- const fetchFn = async () => {
661
- let cancelled = false;
662
- const signalContext = context;
663
- const addSignalProperty = (object) => {
664
- addConsumeAwareSignal(object, () => context.signal, () => cancelled = true, signalContext[fetchSignal]);
665
- };
666
- const queryFn = ensureQueryFn(context.options, context.fetchOptions);
667
- const fetchPage = async (data, param, previous) => {
668
- if (cancelled) return Promise.reject(context.signal.reason);
669
- if (param == null && data.pages.length) return Promise.resolve(data);
670
- const createQueryFnContext = () => {
671
- const queryFnContext = {
672
- client: context.client,
673
- queryKey: context.queryKey,
674
- pageParam: param,
675
- direction: previous ? "backward" : "forward",
676
- meta: context.options.meta
677
- };
678
- addSignalProperty(queryFnContext);
679
- return queryFnContext;
680
- };
681
- const queryFnContext = createQueryFnContext();
682
- const page = await queryFn(queryFnContext);
683
- const { maxPages } = context.options;
684
- const addTo = previous ? addToStart : addToEnd;
685
- return {
686
- pages: addTo(data.pages, page, maxPages),
687
- pageParams: addTo(data.pageParams, param, maxPages)
688
- };
689
- };
690
- if (direction && oldPages.length) {
691
- const previous = direction === "backward";
692
- const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
693
- const oldData = {
694
- pages: oldPages,
695
- pageParams: oldPageParams
696
- };
697
- result = await fetchPage(oldData, pageParamFn(options, oldData), previous);
698
- } else {
699
- const remainingPages = pages ?? oldPages.length;
700
- do {
701
- const param = currentPage === 0 ? oldPageParams[0] === void 0 ? options.initialPageParam : oldPageParams[0] : getNextPageParam(options, result);
702
- if (currentPage > 0 && param == null) break;
703
- result = await fetchPage(result, param);
704
- currentPage++;
705
- } while (currentPage < remainingPages);
706
- }
707
- return result;
708
- };
709
- if (context.options.persister) context.fetchFn = () => {
710
- return context.options.persister?.(fetchFn, {
711
- client: context.client,
712
- queryKey: context.queryKey,
713
- meta: context.options.meta,
714
- signal: context.signal
715
- }, query);
716
- };
717
- else context.fetchFn = fetchFn;
718
- } };
719
- }
720
- /**
721
- * Computes the page param of the page after the last one, with the `getNextPageParam` option.
722
- * @param options - The infinite query options.
723
- * @param data - The current pages and page params.
724
- * @returns The next page param, or `undefined` if there are no pages yet.
725
- */
726
- function getNextPageParam(options, { pages, pageParams }) {
727
- const lastIndex = pages.length - 1;
728
- return pages.length > 0 ? options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams) : void 0;
729
- }
730
- /**
731
- * Computes the page param of the page before the first one, with the `getPreviousPageParam`
732
- * option.
733
- * @param options - The infinite query options.
734
- * @param data - The current pages and page params.
735
- * @returns The previous page param, or `undefined` if there are no pages yet or no
736
- * `getPreviousPageParam` option.
737
- */
738
- function getPreviousPageParam(options, { pages, pageParams }) {
739
- return pages.length > 0 ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0;
740
- }
741
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/query.js
742
- /**
743
- * Represents a single cached query. A `Query` holds the query's key, options,
744
- * state (data/error/status), and the observers currently subscribed to it.
745
- *
746
- * Instances are created and managed internally by `QueryCache`; application
747
- * code typically interacts with queries indirectly through `QueryClient` or
748
- * a framework hook like `useQuery`. Direct access to a `Query` instance is
749
- * possible via `queryCache.find()`/`findAll()` for inspecting cache state.
750
- * @example
751
- * ```ts
752
- * const queryCache = queryClient.getQueryCache()
753
- * const query = queryCache.find({ queryKey: ['posts'] })
754
- *
755
- * if (query) {
756
- * console.log(query.state.dataUpdatedAt)
757
- * }
758
- * ```
759
- */
760
- var Query = class extends Removable {
761
- #queryType;
762
- #initialState;
763
- #revertState;
764
- #cache;
765
- #client;
766
- #retryer;
767
- #fetchPromise;
768
- #defaultOptions;
769
- #abortSignalConsumed;
770
- constructor(config) {
771
- super();
772
- this.#abortSignalConsumed = false;
773
- this.#defaultOptions = config.defaultOptions;
774
- this.setOptions(config.options);
775
- this.observers = [];
776
- this.#client = config.client;
777
- this.#cache = this.#client.getQueryCache();
778
- this.queryKey = config.queryKey;
779
- this.queryHash = config.queryHash;
780
- this.#initialState = getDefaultState(this.options);
781
- this.state = config.state ?? this.#initialState;
782
- this.scheduleGc();
783
- }
784
- /**
785
- * The `meta` object passed in the query's options, if any.
786
- * @returns The query's `meta`, or `undefined` if none was set.
787
- */
788
- get meta() {
789
- return this.options.meta;
790
- }
791
- /**
792
- * `'infinite'` for an infinite query, otherwise `undefined`.
793
- * @internal
794
- * @returns The type of the query, set from the `_type` option (e.g. `'infinite'`).
795
- */
796
- get queryType() {
797
- return this.#queryType;
798
- }
799
- /**
800
- * The promise for the currently in-flight fetch, if the query is fetching.
801
- * `undefined` when the query is not fetching.
802
- * @returns The promise of the in-flight fetch, or `undefined`.
803
- */
804
- get promise() {
805
- return this.#retryer?.promise;
806
- }
807
- /**
808
- * Replaces the query's options and applies their `gcTime`. If the query has no data yet, it gets
809
- * the `initialData` from the new options, if any.
810
- * @internal
811
- * @param options - The new query options, merged on top of the query's default options.
812
- */
813
- setOptions(options) {
814
- this.options = {
815
- ...this.#defaultOptions,
816
- ...options
817
- };
818
- if (options?._type) this.#queryType = options._type;
819
- this.updateGcTime(this.options.gcTime);
820
- if (this.state && this.state.data === void 0) {
821
- const defaultState = getDefaultState(this.options);
822
- if (defaultState.data !== void 0) {
823
- this.setState(successState(defaultState.data, defaultState.dataUpdatedAt));
824
- this.#initialState = defaultState;
825
- }
826
- }
827
- }
828
- optionalRemove() {
829
- if (!this.observers.length && this.state.fetchStatus === "idle") this.#cache.remove(this);
830
- }
831
- /**
832
- * Writes new data to the query and marks it as successfully fetched.
833
- * @internal
834
- * @param newData - The data to write. Structural sharing with the current data is applied.
835
- * @param options - Set `updatedAt` to override the timestamp, and `manual` to mark the write as
836
- * manual (e.g. from `queryClient.setQueryData`).
837
- * @returns The data that was written.
838
- */
839
- setData(newData, options) {
840
- const data = replaceData(this.state.data, newData, this.options);
841
- this.#dispatch({
842
- data,
843
- type: "success",
844
- dataUpdatedAt: options?.updatedAt,
845
- manual: options?.manual
846
- });
847
- return data;
848
- }
849
- /**
850
- * Merges the given partial state directly into this query's state, notifying observers. Used
851
- * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a
852
- * user manually trigger a loading/error state or edit the cached data.
853
- * @param state - The partial state to merge into the query's state.
854
- */
855
- setState(state) {
856
- this.#dispatch({
857
- type: "setState",
858
- state
859
- });
860
- }
861
- /**
862
- * Cancels the query's currently in-flight fetch, if any.
863
- * - Returns a promise that resolves once the cancellation has settled.
864
- * - If no fetch is in progress, resolves immediately.
865
- * @param options - Set `revert` to restore the state from before the fetch started, and `silent`
866
- * to suppress the cancellation error when a new fetch replaces the cancelled one.
867
- * @returns A promise that resolves once the cancellation has settled.
868
- * @example
869
- * ```ts
870
- * await query.cancel()
871
- * ```
872
- */
873
- cancel(options) {
874
- const promise = this.#retryer?.promise;
875
- this.#retryer?.cancel(options);
876
- return promise ? promise.then(noop).catch(noop) : Promise.resolve();
877
- }
878
- /**
879
- * Clears the query's garbage collection timeout and silently cancels any
880
- * in-flight fetch. Called by `QueryCache` when the query is removed from
881
- * the cache.
882
- * @see {@link Query#cancel}
883
- */
884
- destroy() {
885
- super.destroy();
886
- this.cancel({ silent: true });
887
- }
888
- /**
889
- * The state the query was created with.
890
- * @internal
891
- * @returns The state the query had when it was first created, used by {@link Query#reset}.
892
- */
893
- get resetState() {
894
- return this.#initialState;
895
- }
896
- /**
897
- * Resets the query back to its initial state (the state it had when it was
898
- * first created, e.g. any `initialData`), destroying it first to cancel any
899
- * in-flight fetch.
900
- */
901
- reset() {
902
- this.destroy();
903
- this.setState(this.resetState);
904
- }
905
- /**
906
- * Returns `true` if the query has at least one observer for which `enabled`
907
- * does not resolve to `false`.
908
- * @returns `true` if the query has an enabled observer.
909
- */
910
- isActive() {
911
- return this.observers.some((observer) => resolveQueryValue(observer.options.enabled, this) !== false);
912
- }
913
- /**
914
- * Returns `true` if the query is disabled, meaning it will not fetch
915
- * automatically.
916
- * - If the query has observers, it is disabled when none of them are active
917
- * (see `isActive`).
918
- * - If the query has no observers, it is disabled when its `queryFn` is
919
- * `skipToken` or it has never been fetched.
920
- * @returns `true` if the query is disabled.
921
- */
922
- isDisabled() {
923
- if (this.getObserversCount() > 0) return !this.isActive();
924
- return this.options.queryFn === skipToken || !this.isFetched();
925
- }
926
- /**
927
- * Returns `true` if the query has been fetched, i.e. it has resolved with
928
- * either data or an error at least once.
929
- * @returns `true` if the query has been fetched.
930
- */
931
- isFetched() {
932
- return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
933
- }
934
- /**
935
- * Returns `true` if the query has data and at least one observer configured with
936
- * `staleTime: 'static'`, meaning it is treated as never stale.
937
- * @returns `true` if the query is static.
938
- */
939
- isStatic() {
940
- if (this.state.data === void 0) return false;
941
- if (this.getObserversCount() > 0) return this.observers.some((observer) => resolveQueryValue(observer.options.staleTime, this) === "static");
942
- return false;
943
- }
944
- /**
945
- * Returns `true` if the query is stale.
946
- * - If the query has observers, defers to whether any observer's current
947
- * result reports `isStale` (which accounts for each observer's own
948
- * `staleTime` and `enabled` state).
949
- * - If the query has no observers, it is considered stale when it has no
950
- * data or has been invalidated.
951
- * @returns `true` if the query is stale.
952
- * @see {@link Query#isStaleByTime}
953
- * @example
954
- * ```ts
955
- * if (query.isStale()) {
956
- * // refetch or otherwise treat the cached data as outdated
957
- * }
958
- * ```
959
- */
960
- isStale() {
961
- if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale);
962
- return this.state.data === void 0 || this.state.isInvalidated;
963
- }
964
- /**
965
- * Returns `true` if the query's data is stale relative to the given
966
- * `staleTime` (defaults to `0`).
967
- * - A query with no data is always stale.
968
- * - `staleTime: 'static'` is never stale.
969
- * - An invalidated query is always stale.
970
- * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.
971
- * @param staleTime - The time, in milliseconds, after which data is considered stale, or
972
- * `'static'` to never treat existing data as stale. A query without data is stale either way.
973
- * @returns `true` if the query's data is stale.
974
- * @see {@link Query#isStale}
975
- * @example
976
- * ```ts
977
- * const isStale = query.isStaleByTime(60 * 1000)
978
- * ```
979
- */
980
- isStaleByTime(staleTime = 0) {
981
- if (this.state.data === void 0) return true;
982
- if (staleTime === "static") return false;
983
- if (this.state.isInvalidated) return true;
984
- return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
985
- }
986
- /**
987
- * Refetches the query when the window regains focus, if an observer wants that, and continues a
988
- * paused fetch.
989
- * @internal
990
- */
991
- onFocus() {
992
- this.observers.find((x) => x.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: false });
993
- this.#retryer?.continue();
994
- }
995
- /**
996
- * Refetches the query when the app reconnects, if an observer wants that, and continues a paused
997
- * fetch.
998
- * @internal
999
- */
1000
- onOnline() {
1001
- this.observers.find((x) => x.shouldFetchOnReconnect())?.refetch({ cancelRefetch: false });
1002
- this.#retryer?.continue();
1003
- }
1004
- /**
1005
- * Subscribes an observer to the query and stops its garbage collection.
1006
- * @internal
1007
- * @param observer - The observer to add. Adding an observer that is already subscribed does
1008
- * nothing.
1009
- */
1010
- addObserver(observer) {
1011
- if (!this.observers.includes(observer)) {
1012
- this.observers.push(observer);
1013
- this.clearGcTimeout();
1014
- this.#cache.notify({
1015
- type: "observerAdded",
1016
- query: this,
1017
- observer
1018
- });
1019
- }
1020
- }
1021
- /**
1022
- * Unsubscribes an observer from the query.
1023
- * @internal
1024
- * @param observer - The observer to remove. When the last observer is removed, the in-flight
1025
- * fetch is cancelled if its abort signal was consumed (otherwise only its retries are stopped),
1026
- * and garbage collection is scheduled.
1027
- */
1028
- removeObserver(observer) {
1029
- const index = this.observers.indexOf(observer);
1030
- if (index !== -1) {
1031
- this.observers.splice(index, 1);
1032
- if (!this.observers.length) {
1033
- if (this.#retryer) {
1034
- if (this.#abortSignalConsumed || this.state.fetchStatus === "paused" && this.state.status === "pending") this.#retryer.cancel({ revert: true });
1035
- else this.#retryer.cancelRetry();
1036
- }
1037
- this.scheduleGc();
1038
- }
1039
- this.#cache.notify({
1040
- type: "observerRemoved",
1041
- query: this,
1042
- observer
1043
- });
1044
- }
1045
- }
1046
- /**
1047
- * Returns the number of observers currently subscribed to this query.
1048
- * @returns The number of observers.
1049
- * @example
1050
- * ```ts
1051
- * if (query.getObserversCount() === 0) {
1052
- * // no component is currently watching this query
1053
- * }
1054
- * ```
1055
- */
1056
- getObserversCount() {
1057
- return this.observers.length;
1058
- }
1059
- /**
1060
- * Marks the query as invalidated, unless it is already invalidated. This
1061
- * updates `state.isInvalidated` and notifies observers, but does not by
1062
- * itself trigger a refetch.
1063
- * @example
1064
- * ```ts
1065
- * query.invalidate()
1066
- * ```
1067
- */
1068
- invalidate() {
1069
- if (!this.state.isInvalidated) this.#dispatch({ type: "invalidate" });
1070
- }
1071
- /**
1072
- * Fetches the query, i.e. runs its `queryFn` (through any configured
1073
- * retryer/behavior) and updates the query's state with the result.
1074
- * - If a fetch is already in flight, returns its promise instead of
1075
- * starting a new one, unless `fetchOptions.cancelRefetch` is set and the
1076
- * query already has data, in which case the current fetch is silently
1077
- * cancelled first.
1078
- * - If `options` is passed, it replaces the query's current options
1079
- * before fetching.
1080
- * @param options - Query options that replace the query's current options before fetching. They
1081
- * are not applied when an in-flight fetch is reused.
1082
- * @param fetchOptions - Set `cancelRefetch` to cancel an in-flight fetch first (only if the query
1083
- * already has data), and `meta` to pass extra information to the query's behavior.
1084
- * @returns A promise that resolves with the fetched data, or rejects with the fetch error. If the
1085
- * fetch is cancelled with `revert` while the query has data, it resolves with the restored data
1086
- * instead.
1087
- */
1088
- async fetch(options, fetchOptions) {
1089
- if (this.state.fetchStatus !== "idle" && this.#retryer?.status() !== "rejected") {
1090
- if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) this.cancel({ silent: true });
1091
- else if (this.#retryer && this.#fetchPromise) {
1092
- this.#retryer.continueRetry();
1093
- return this.#fetchPromise;
1094
- }
1095
- }
1096
- if (options) this.setOptions(options);
1097
- if (!this.options.queryFn) {
1098
- const observer = this.observers.find((x) => x.options.queryFn);
1099
- if (observer) this.setOptions(observer.options);
1100
- }
1101
- const abortController = new AbortController();
1102
- const addSignalProperty = (object) => {
1103
- Object.defineProperties(object, {
1104
- [fetchSignal]: {
1105
- value: abortController.signal,
1106
- enumerable: true
1107
- },
1108
- signal: {
1109
- enumerable: true,
1110
- get: () => {
1111
- this.#abortSignalConsumed = true;
1112
- return abortController.signal;
1113
- }
1114
- }
1115
- });
1116
- };
1117
- const fetchFn = () => {
1118
- const queryFn = ensureQueryFn(this.options, fetchOptions);
1119
- const createQueryFnContext = () => {
1120
- const queryFnContext = {
1121
- client: this.#client,
1122
- queryKey: this.queryKey,
1123
- meta: this.meta
1124
- };
1125
- addSignalProperty(queryFnContext);
1126
- return queryFnContext;
1127
- };
1128
- const queryFnContext = createQueryFnContext();
1129
- this.#abortSignalConsumed = false;
1130
- if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this);
1131
- return queryFn(queryFnContext);
1132
- };
1133
- const createFetchContext = () => {
1134
- const context = {
1135
- fetchOptions,
1136
- options: this.options,
1137
- queryKey: this.queryKey,
1138
- client: this.#client,
1139
- state: this.state,
1140
- fetchFn
1141
- };
1142
- addSignalProperty(context);
1143
- return context;
1144
- };
1145
- const context = createFetchContext();
1146
- (this.#queryType === "infinite" ? infiniteQueryBehavior(this.options.pages) : this.options.behavior)?.onFetch(context, this);
1147
- this.#revertState = this.state;
1148
- if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) this.#dispatch({
1149
- type: "fetch",
1150
- meta: context.fetchOptions?.meta
1151
- });
1152
- const retryer = this.#retryer = createRetryer({
1153
- initialPromise: fetchOptions?.initialPromise,
1154
- fn: context.fetchFn,
1155
- onCancel: (error) => {
1156
- if (error instanceof CancelledError && error.revert) this.setState({
1157
- ...this.#revertState,
1158
- fetchStatus: "idle"
1159
- });
1160
- abortController.abort();
1161
- },
1162
- onFail: (failureCount, error) => {
1163
- this.#dispatch({
1164
- type: "failed",
1165
- failureCount,
1166
- error
1167
- });
1168
- },
1169
- onPause: () => {
1170
- this.#dispatch({ type: "pause" });
1171
- },
1172
- onContinue: () => {
1173
- this.#dispatch({ type: "continue" });
1174
- },
1175
- retry: context.options.retry,
1176
- retryDelay: context.options.retryDelay,
1177
- networkMode: context.options.networkMode,
1178
- canRun: () => true
1179
- });
1180
- const fetchPromise = (async () => {
1181
- try {
1182
- const data = await retryer.promise;
1183
- if (data === void 0) throw new Error(`${this.queryHash} data is undefined`);
1184
- this.setData(data);
1185
- this.#cache.config.onSuccess?.(data, this);
1186
- this.#cache.config.onSettled?.(data, this.state.error, this);
1187
- return data;
1188
- } catch (error) {
1189
- if (error instanceof CancelledError) {
1190
- if (error.silent) {
1191
- if (this.#retryer !== retryer && this.#fetchPromise) return this.#fetchPromise;
1192
- throw error;
1193
- } else if (error.revert) {
1194
- if (this.state.data === void 0) throw error;
1195
- return this.state.data;
1196
- }
1197
- }
1198
- this.#dispatch({
1199
- type: "error",
1200
- error
1201
- });
1202
- this.#cache.config.onError?.(error, this);
1203
- this.#cache.config.onSettled?.(this.state.data, error, this);
1204
- throw error;
1205
- } finally {
1206
- if (this.#retryer === retryer) {
1207
- this.#retryer = void 0;
1208
- this.#fetchPromise = void 0;
1209
- }
1210
- this.scheduleGc();
1211
- }
1212
- })();
1213
- this.#fetchPromise = fetchPromise;
1214
- retryer.start();
1215
- return fetchPromise;
1216
- }
1217
- #dispatch(action) {
1218
- const reducer = (state) => {
1219
- switch (action.type) {
1220
- case "failed": return {
1221
- ...state,
1222
- fetchFailureCount: action.failureCount,
1223
- fetchFailureReason: action.error
1224
- };
1225
- case "pause": return {
1226
- ...state,
1227
- fetchStatus: "paused"
1228
- };
1229
- case "continue": return {
1230
- ...state,
1231
- fetchStatus: "fetching"
1232
- };
1233
- case "fetch": return {
1234
- ...state,
1235
- ...fetchState(state.data, this.options),
1236
- fetchMeta: action.meta ?? null
1237
- };
1238
- case "success":
1239
- const newState = {
1240
- ...state,
1241
- ...successState(action.data, action.dataUpdatedAt),
1242
- dataUpdateCount: state.dataUpdateCount + 1,
1243
- ...!action.manual && {
1244
- fetchStatus: "idle",
1245
- fetchFailureCount: 0,
1246
- fetchFailureReason: null
1247
- }
1248
- };
1249
- this.#revertState = action.manual ? newState : void 0;
1250
- return newState;
1251
- case "error":
1252
- const error = action.error;
1253
- return {
1254
- ...state,
1255
- error,
1256
- errorUpdateCount: state.errorUpdateCount + 1,
1257
- errorUpdatedAt: Date.now(),
1258
- fetchFailureCount: state.fetchFailureCount + 1,
1259
- fetchFailureReason: error,
1260
- fetchStatus: "idle",
1261
- status: "error",
1262
- isInvalidated: true
1263
- };
1264
- case "invalidate": return {
1265
- ...state,
1266
- isInvalidated: true
1267
- };
1268
- case "setState": return {
1269
- ...state,
1270
- ...action.state
1271
- };
1272
- }
1273
- };
1274
- this.state = reducer(this.state);
1275
- notifyManager.batch(() => {
1276
- this.observers.slice().forEach((observer) => {
1277
- observer.onQueryUpdate();
1278
- });
1279
- this.#cache.notify({
1280
- query: this,
1281
- type: "updated",
1282
- action
1283
- });
1284
- });
1285
- }
1286
- };
1287
- /**
1288
- * Returns the state changes applied when a query starts fetching.
1289
- * @param data - The query's current data. If it is `undefined`, the query is also reset to
1290
- * `'pending'` with no error.
1291
- * @param options - The query options, whose `networkMode` decides whether the query is `'fetching'`
1292
- * or `'paused'`.
1293
- * @returns The partial query state for a starting fetch.
1294
- */
1295
- function fetchState(data, options) {
1296
- return {
1297
- fetchFailureCount: 0,
1298
- fetchFailureReason: null,
1299
- fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
1300
- ...data === void 0 && {
1301
- error: null,
1302
- status: "pending"
1303
- }
1304
- };
1305
- }
1306
- /**
1307
- * Returns the state changes applied when a query receives data.
1308
- * @param data - The new data.
1309
- * @param dataUpdatedAt - The timestamp the data is recorded with. Defaults to the current time.
1310
- * @returns The partial query state for a successful update.
1311
- */
1312
- function successState(data, dataUpdatedAt) {
1313
- return {
1314
- data,
1315
- dataUpdatedAt: dataUpdatedAt ?? Date.now(),
1316
- error: null,
1317
- isInvalidated: false,
1318
- status: "success"
1319
- };
1320
- }
1321
- /**
1322
- * Returns the initial state of a query, based on its `initialData` and `initialDataUpdatedAt`
1323
- * options.
1324
- * @param options - The query options.
1325
- * @returns The initial query state: `'success'` if `initialData` is set, otherwise `'pending'`.
1326
- */
1327
- function getDefaultState(options) {
1328
- const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
1329
- const hasData = data !== void 0;
1330
- const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
1331
- return {
1332
- data,
1333
- dataUpdateCount: 0,
1334
- dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
1335
- error: null,
1336
- errorUpdateCount: 0,
1337
- errorUpdatedAt: 0,
1338
- fetchFailureCount: 0,
1339
- fetchFailureReason: null,
1340
- fetchMeta: null,
1341
- isInvalidated: false,
1342
- status: hasData ? "success" : "pending",
1343
- fetchStatus: "idle"
1344
- };
1345
- }
1346
- // ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/queryObserver.js
1347
- /**
1348
- * A `QueryObserver` watches a single query in the `QueryCache` and computes a
1349
- * `QueryObserverResult` from its state, recomputing and notifying subscribers
1350
- * whenever the underlying query (or the observer's options) changes. It is
1351
- * the primitive that framework adapters (e.g. `useQuery`) build their hooks
1352
- * on top of, but it can also be used directly to observe and switch between
1353
- * queries outside of any framework.
1354
- * @example
1355
- * ```ts
1356
- * const observer = new QueryObserver(queryClient, {
1357
- * queryKey: ['posts'],
1358
- * queryFn: fetchPosts,
1359
- * })
1360
- *
1361
- * const unsubscribe = observer.subscribe((result) => {
1362
- * console.log(result.data)
1363
- * })
1364
- * ```
1365
- */
1366
- var QueryObserver = class extends Subscribable {
1367
- #client;
1368
- #currentQuery = void 0;
1369
- #currentQueryInitialState = void 0;
1370
- #currentResult = void 0;
1371
- #currentResultState;
1372
- #currentResultOptions;
1373
- #selectError;
1374
- #selectFn;
1375
- #selectResult;
1376
- #lastQueryWithDefinedData;
1377
- #staleTimeoutId;
1378
- #refetchIntervalId;
1379
- #currentRefetchInterval;
1380
- #trackedProps = /* @__PURE__ */ new Set();
1381
- constructor(client, options) {
1382
- super();
1383
- this.options = options;
1384
- this.#client = client;
1385
- this.#selectError = null;
1386
- this.bindMethods();
1387
- this.setOptions(options);
1388
- }
1389
- /**
1390
- * Binds the methods of the result (`refetch`) to the observer, so they keep working when destructured
1391
- * from it. Subclasses override it to bind their own result methods as well.
1392
- */
1393
- bindMethods() {
1394
- this.refetch = this.refetch.bind(this);
1395
- }
1396
- onSubscribe() {
1397
- if (this.listeners.size === 1) {
1398
- this.#currentQuery.addObserver(this);
1399
- if (shouldFetchOnMount(this.#currentQuery, this.options)) this.#executeFetch();
1400
- else this.updateResult();
1401
- this.#updateTimers();
1402
- }
1403
- }
1404
- onUnsubscribe() {
1405
- if (!this.hasListeners()) this.destroy();
1406
- }
1407
- /**
1408
- * Returns whether the observed query is currently stale and configured
1409
- * (via the `refetchOnReconnect` option) to refetch when the network
1410
- * reconnects.
1411
- * @returns `true` if the observer should refetch the query on reconnect.
1412
- */
1413
- shouldFetchOnReconnect() {
1414
- return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
1415
- }
1416
- /**
1417
- * Returns whether the observed query is currently stale and configured
1418
- * (via the `refetchOnWindowFocus` option) to refetch when the window
1419
- * regains focus.
1420
- * @returns `true` if the observer should refetch the query on window focus.
1421
- */
1422
- shouldFetchOnWindowFocus() {
1423
- return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
1424
- }
1425
- /**
1426
- * Stops observing the current query: clears all listeners, cancels the
1427
- * stale and refetch-interval timers, and removes this observer from the
1428
- * query it was observing.
1429
- */
1430
- destroy() {
1431
- this.listeners = /* @__PURE__ */ new Set();
1432
- this.#clearStaleTimeout();
1433
- this.#clearRefetchInterval();
1434
- this.#currentQuery.removeObserver(this);
1435
- }
1436
- /**
1437
- * Updates the observer's options. This will re-resolve the query being
1438
- * observed (switching to a different query if the `queryKey` changed),
1439
- * trigger a fetch if the new options require one and the observer has
1440
- * subscribers, recompute the current result, and reschedule the stale and
1441
- * refetch-interval timers as needed.
1442
- * @param options - The new observer options. They are defaulted with {@link
1443
- * QueryClient#defaultQueryOptions} before being applied.
1444
- * @throws {Error} If `enabled` is neither a boolean nor a function.
1445
- * @example
1446
- * ```ts
1447
- * observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
1448
- * // later: switch to a different query, reusing the same observer
1449
- * observer.setOptions({ queryKey: ['posts', 2], queryFn: () => fetchPost(2) })
1450
- * ```
1451
- */
1452
- setOptions(options) {
1453
- const prevOptions = this.options;
1454
- const prevQuery = this.#currentQuery;
1455
- this.options = this.#client.defaultQueryOptions(options);
1456
- if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof resolveQueryValue(this.options.enabled, this.#currentQuery) !== "boolean") throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
1457
- this.#updateQuery();
1458
- this.#currentQuery.setOptions(this.options);
1459
- if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) this.#client.getQueryCache().notify({
1460
- type: "observerOptionsUpdated",
1461
- query: this.#currentQuery,
1462
- observer: this
1463
- });
1464
- const mounted = this.hasListeners();
1465
- if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) this.#executeFetch();
1466
- this.updateResult();
1467
- if (mounted && (this.#currentQuery !== prevQuery || resolveQueryValue(this.options.enabled, this.#currentQuery) !== resolveQueryValue(prevOptions.enabled, this.#currentQuery) || resolveQueryValue(this.options.staleTime, this.#currentQuery) !== resolveQueryValue(prevOptions.staleTime, this.#currentQuery))) this.#updateStaleTimeout();
1468
- const nextRefetchInterval = this.#computeRefetchInterval();
1469
- if (mounted && (this.#currentQuery !== prevQuery || resolveQueryValue(this.options.enabled, this.#currentQuery) !== resolveQueryValue(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) this.#updateRefetchInterval(nextRefetchInterval);
1470
- }
1471
- /**
1472
- * Computes the result the observer would produce for the given (already-defaulted) options
1473
- * right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
1474
- * subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
1475
- * returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
1476
- * @param options - The defaulted observer options to compute the result for.
1477
- * @returns The result for the given options.
1478
- */
1479
- getOptimisticResult(options) {
1480
- const query = this.#client.getQueryCache().build(this.#client, options);
1481
- const result = this.createResult(query, options);
1482
- if (!shallowEqualObjects(this.getCurrentResult(), result)) {
1483
- this.#currentResult = result;
1484
- this.#currentResultOptions = this.options;
1485
- this.#currentResultState = this.#currentQuery.state;
1486
- }
1487
- return result;
1488
- }
1489
- /**
1490
- * Returns the most recently computed `QueryObserverResult` for the
1491
- * observed query. This is a point-in-time read; to be notified of updates
1492
- * as they happen, subscribe to the observer instead (its inherited
1493
- * `subscribe` method).
1494
- * @returns The observer's latest result.
1495
- * @example
1496
- * ```ts
1497
- * const result = observer.getCurrentResult()
1498
- * console.log(result.status, result.data)
1499
- * ```
1500
- */
1501
- getCurrentResult() {
1502
- return this.#currentResult;
1503
- }
1504
- /**
1505
- * Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via
1506
- * {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
1507
- * adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
1508
- * properties you actually read" behavior.
1509
- * @param result - The result to wrap.
1510
- * @param onPropTracked - Called with the name of each property that is read.
1511
- * @returns A proxy of `result` that tracks property reads.
1512
- */
1513
- trackResult(result, onPropTracked) {
1514
- return new Proxy(result, { get: (target, key) => {
1515
- this.trackProp(key);
1516
- onPropTracked?.(key);
1517
- return Reflect.get(target, key);
1518
- } });
1519
- }
1520
- /**
1521
- * Records that the given `QueryObserverResult` property was read, so a subsequent update only
1522
- * notifies this observer if a tracked property actually changed. Normally called indirectly via
1523
- * {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
1524
- * access themselves (e.g. through their own reactivity system) instead of via the proxy.
1525
- * @param key - The name of the property that was read.
1526
- */
1527
- trackProp(key) {
1528
- this.#trackedProps.add(key);
1529
- }
1530
- /**
1531
- * Returns the `Query` instance this observer is currently observing.
1532
- * @returns The observed query.
1533
- */
1534
- getCurrentQuery() {
1535
- return this.#currentQuery;
1536
- }
1537
- /**
1538
- * Refetches the observed query and returns a promise that resolves with
1539
- * the resulting `QueryObserverResult`.
1540
- * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
1541
- * it, and `throwOnError` to `true` to reject when the refetch fails.
1542
- * @returns A promise that resolves with the result after the refetch.
1543
- * @example
1544
- * ```ts
1545
- * const result = await observer.refetch({ cancelRefetch: false })
1546
- * console.log(result.data)
1547
- * ```
1548
- */
1549
- refetch({ ...options } = {}) {
1550
- return this.fetch({ ...options });
1551
- }
1552
- /**
1553
- * Fetches a query defined by the given options without affecting this
1554
- * observer's own tracked query or result, and returns a promise that
1555
- * resolves with the `QueryObserverResult` for that fetch. This is useful
1556
- * for prefetching data that another observer (e.g. a query about to be
1557
- * navigated to) will need, ahead of time.
1558
- * @param options - The observer options of the query to fetch.
1559
- * @returns A promise that resolves with the result for the fetched query.
1560
- * @example
1561
- * ```ts
1562
- * const result = await observer.fetchOptimistic({
1563
- * queryKey: ['posts', 2],
1564
- * queryFn: () => fetchPost(2),
1565
- * })
1566
- * console.log(result.data)
1567
- * ```
1568
- */
1569
- fetchOptimistic(options) {
1570
- const defaultedOptions = this.#client.defaultQueryOptions(options);
1571
- const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
1572
- let unsubscribe = () => {};
1573
- let resolveEarly;
1574
- const cachePromise = new Promise((resolve) => {
1575
- resolveEarly = resolve;
1576
- unsubscribe = this.#client.getQueryCache().subscribe((event) => {
1577
- if (event.type === "updated" && event.query.queryHash === query.queryHash && query.state.data !== void 0) {
1578
- unsubscribe();
1579
- resolve(this.createResult(query, defaultedOptions));
1580
- }
1581
- });
1582
- });
1583
- return Promise.race([query.fetch(defaultedOptions).then(() => {
1584
- const result = this.createResult(query, defaultedOptions);
1585
- resolveEarly?.(result);
1586
- return result;
1587
- }).finally(() => {
1588
- unsubscribe();
1589
- }), cachePromise]);
1590
- }
1591
- /**
1592
- * Fetches the observed query and updates the result once the fetch settles. Used by `refetch` and,
1593
- * in `InfiniteQueryObserver`, to fetch more pages.
1594
- * @param fetchOptions - Options for this fetch. `cancelRefetch` defaults to `true`.
1595
- * @returns A promise that resolves with the updated result.
1596
- */
1597
- fetch(fetchOptions) {
1598
- return this.#executeFetch({
1599
- ...fetchOptions,
1600
- cancelRefetch: fetchOptions.cancelRefetch ?? true
1601
- }).then(() => {
1602
- this.updateResult();
1603
- return this.#currentResult;
1604
- });
1605
- }
1606
- #executeFetch(fetchOptions) {
1607
- this.#updateQuery();
1608
- let promise = this.#currentQuery.fetch(this.options, fetchOptions);
1609
- if (!fetchOptions?.throwOnError) promise = promise.catch(noop);
1610
- return promise;
1611
- }
1612
- #shouldScheduleTimer(timeout) {
1613
- return !isServer() && resolveQueryValue(this.options.enabled, this.#currentQuery) !== false && isValidTimeout(timeout);
1614
- }
1615
- #updateStaleTimeout() {
1616
- this.#clearStaleTimeout();
1617
- const staleTime = resolveQueryValue(this.options.staleTime, this.#currentQuery);
1618
- if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) return;
1619
- const timeout = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) + 1;
1620
- this.#staleTimeoutId = timeoutManager.setTimeout(() => {
1621
- if (!this.#currentResult.isStale) this.updateResult();
1622
- }, timeout);
1623
- }
1624
- #computeRefetchInterval() {
1625
- return resolveQueryValue(this.options.refetchInterval, this.#currentQuery) ?? false;
1626
- }
1627
- #updateRefetchInterval(nextInterval) {
1628
- this.#clearRefetchInterval();
1629
- this.#currentRefetchInterval = nextInterval;
1630
- if (this.#currentRefetchInterval === 0 || !this.#shouldScheduleTimer(this.#currentRefetchInterval)) return;
1631
- this.#refetchIntervalId = timeoutManager.setInterval(() => {
1632
- if (this.options.refetchIntervalInBackground || focusManager.isFocused()) this.#executeFetch();
1633
- }, this.#currentRefetchInterval);
1634
- }
1635
- #updateTimers() {
1636
- this.#updateStaleTimeout();
1637
- this.#updateRefetchInterval(this.#computeRefetchInterval());
1638
- }
1639
- #clearStaleTimeout() {
1640
- if (this.#staleTimeoutId !== void 0) {
1641
- timeoutManager.clearTimeout(this.#staleTimeoutId);
1642
- this.#staleTimeoutId = void 0;
1643
- }
1644
- }
1645
- #clearRefetchInterval() {
1646
- if (this.#refetchIntervalId !== void 0) {
1647
- timeoutManager.clearInterval(this.#refetchIntervalId);
1648
- this.#refetchIntervalId = void 0;
1649
- }
1650
- }
1651
- /**
1652
- * Computes the result for a query and options from the query's state, applying `select`,
1653
- * `placeholderData`, and the derived flags. Subclasses override it to add their own fields.
1654
- * @param query - The query to compute the result for.
1655
- * @param options - The observer options to compute the result with.
1656
- * @returns The computed result.
1657
- */
1658
- createResult(query, options) {
1659
- const prevQuery = this.#currentQuery;
1660
- const prevOptions = this.options;
1661
- const prevResult = this.#currentResult;
1662
- const prevResultState = this.#currentResultState;
1663
- const prevResultOptions = this.#currentResultOptions;
1664
- const queryInitialState = query !== prevQuery ? query.state : this.#currentQueryInitialState;
1665
- const { state } = query;
1666
- let newState = { ...state };
1667
- let isPlaceholderData = false;
1668
- let data;
1669
- if (options._optimisticResults) {
1670
- const mounted = this.hasListeners();
1671
- const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
1672
- const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
1673
- if (fetchOnMount || fetchOptionally) newState = {
1674
- ...newState,
1675
- ...fetchState(state.data, query.options)
1676
- };
1677
- if (options._optimisticResults === "isRestoring") newState.fetchStatus = "idle";
1678
- }
1679
- let { error, errorUpdatedAt, status } = newState;
1680
- data = newState.data;
1681
- let skipSelect = false;
1682
- if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
1683
- let placeholderData;
1684
- if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
1685
- placeholderData = prevResult.data;
1686
- skipSelect = true;
1687
- } else placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
1688
- if (placeholderData !== void 0) {
1689
- status = "success";
1690
- data = replaceData(prevResult?.data, placeholderData, options);
1691
- isPlaceholderData = true;
1692
- }
1693
- }
1694
- if (options.select && data !== void 0 && !skipSelect) {
1695
- if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) data = this.#selectResult;
1696
- else try {
1697
- this.#selectFn = options.select;
1698
- data = options.select(data);
1699
- data = replaceData(prevResult?.data, data, options);
1700
- this.#selectResult = data;
1701
- this.#selectError = null;
1702
- } catch (selectError) {
1703
- this.#selectError = selectError;
1704
- }
1705
- } else if (data === void 0) this.#selectError = null;
1706
- if (this.#selectError) {
1707
- error = this.#selectError;
1708
- data = this.#selectResult;
1709
- errorUpdatedAt = Date.now();
1710
- status = "error";
1711
- isPlaceholderData = false;
1712
- }
1713
- const isFetching = newState.fetchStatus === "fetching";
1714
- const isPending = status === "pending";
1715
- const isError = status === "error";
1716
- const isLoading = isPending && isFetching;
1717
- const hasData = data !== void 0;
1718
- return {
1719
- status,
1720
- fetchStatus: newState.fetchStatus,
1721
- isPending,
1722
- isSuccess: status === "success",
1723
- isError,
1724
- isInitialLoading: isLoading,
1725
- isLoading,
1726
- data,
1727
- dataUpdatedAt: newState.dataUpdatedAt,
1728
- error,
1729
- errorUpdatedAt,
1730
- failureCount: newState.fetchFailureCount,
1731
- failureReason: newState.fetchFailureReason,
1732
- errorUpdateCount: newState.errorUpdateCount,
1733
- isFetched: query.isFetched(),
1734
- isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
1735
- isFetching,
1736
- isRefetching: isFetching && !isPending,
1737
- isLoadingError: isError && !hasData,
1738
- isPaused: newState.fetchStatus === "paused",
1739
- isPlaceholderData,
1740
- isRefetchError: isError && hasData,
1741
- isStale: isStale(query, options),
1742
- refetch: this.refetch,
1743
- isEnabled: resolveQueryValue(options.enabled, query) !== false
1744
- };
1745
- }
1746
- /**
1747
- * Recomputes and stores the current result from the current query/options, notifying listeners
1748
- * if it changed. Framework adapters call this right after subscribing to make sure no query
1749
- * update was missed in the gap between creating the observer and subscribing to it.
1750
- */
1751
- updateResult() {
1752
- const prevResult = this.#currentResult;
1753
- const nextResult = this.createResult(this.#currentQuery, this.options);
1754
- this.#currentResultState = this.#currentQuery.state;
1755
- this.#currentResultOptions = this.options;
1756
- if (this.#currentResultState.data !== void 0) this.#lastQueryWithDefinedData = this.#currentQuery;
1757
- if (shallowEqualObjects(nextResult, prevResult)) return;
1758
- this.#currentResult = nextResult;
1759
- const shouldNotifyListeners = () => {
1760
- if (!prevResult) return true;
1761
- const { notifyOnChangeProps } = this.options;
1762
- const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
1763
- if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) return true;
1764
- if (this.options.throwOnError && this.#currentResult.error !== prevResult.error) return true;
1765
- for (const key of notifyOnChangePropsValue ?? this.#trackedProps) if (this.#currentResult[key] !== prevResult[key]) return true;
1766
- return false;
1767
- };
1768
- const notifyListeners = shouldNotifyListeners();
1769
- notifyManager.batch(() => {
1770
- if (notifyListeners) this.listeners.forEach((listener) => {
1771
- listener(this.#currentResult);
1772
- });
1773
- this.#client.getQueryCache().notify({
1774
- query: this.#currentQuery,
1775
- type: "observerResultsUpdated"
1776
- });
1777
- });
1778
- }
1779
- #updateQuery() {
1780
- const query = this.#client.getQueryCache().build(this.#client, this.options);
1781
- if (query === this.#currentQuery) return;
1782
- const prevQuery = this.#currentQuery;
1783
- this.#currentQuery = query;
1784
- this.#currentQueryInitialState = query.state;
1785
- if (this.hasListeners()) {
1786
- prevQuery?.removeObserver(this);
1787
- query.addObserver(this);
1788
- }
1789
- }
1790
- /**
1791
- * Updates the observer's result when the observed query changes, and reschedules its timers if it
1792
- * has listeners.
1793
- * @internal
1794
- */
1795
- onQueryUpdate() {
1796
- this.updateResult();
1797
- if (this.hasListeners()) this.#updateTimers();
1798
- }
1799
- };
1800
- /**
1801
- * Checks whether a query has no data yet and should do its initial load when an observer mounts.
1802
- * @param query - The query to check.
1803
- * @param options - The observer options.
1804
- * @returns `true` if the query is enabled, has no data, and isn't in an error state with
1805
- * `retryOnMount: false`.
1806
- */
1807
- function shouldLoadOnMount(query, options) {
1808
- return resolveQueryValue(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && resolveQueryValue(options.retryOnMount, query) === false);
1809
- }
1810
- /**
1811
- * Checks whether a query should fetch when an observer mounts: either for its initial load, or
1812
- * because it has data and `refetchOnMount` asks for a refetch.
1813
- * @param query - The query to check.
1814
- * @param options - The observer options.
1815
- * @returns `true` if the query should fetch on mount.
1816
- */
1817
- function shouldFetchOnMount(query, options) {
1818
- return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
1819
- }
1820
- /**
1821
- * Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or
1822
- * `refetchOnReconnect` option.
1823
- * @param query - The query to check.
1824
- * @param options - The observer options.
1825
- * @param field - The value of the option to check.
1826
- * @returns `true` if the query is enabled, not static, and the option is `'always'`, or is not
1827
- * `false` and the query is stale.
1828
- */
1829
- function shouldFetchOn(query, options, field) {
1830
- if (resolveQueryValue(options.enabled, query) !== false && resolveQueryValue(options.staleTime, query) !== "static") {
1831
- const value = resolveQueryValue(field, query);
1832
- return value === "always" || value !== false && isStale(query, options);
1833
- }
1834
- return false;
1835
- }
1836
- /**
1837
- * Checks whether a query should fetch after the observer's options change.
1838
- * @param query - The query observed with the new options.
1839
- * @param prevQuery - The query observed with the previous options.
1840
- * @param options - The new observer options.
1841
- * @param prevOptions - The previous observer options.
1842
- * @returns `true` if the query changed or was disabled before, it isn't a suspense query in an
1843
- * error state, and it is stale.
1844
- */
1845
- function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
1846
- return (query !== prevQuery || resolveQueryValue(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
1847
- }
1848
- /**
1849
- * Checks whether a query is stale for the given observer options.
1850
- * @param query - The query to check.
1851
- * @param options - The observer options, whose `enabled` and `staleTime` are used.
1852
- * @returns `true` if the query is enabled and its data is stale for `staleTime`.
1853
- */
1854
- function isStale(query, options) {
1855
- return resolveQueryValue(options.enabled, query) !== false && query.isStaleByTime(resolveQueryValue(options.staleTime, query));
1856
- }
1857
- // ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/IsRestoringProvider.js
1858
- var IsRestoringContext = import_react.createContext(false);
1859
- /**
1860
- * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` hook alongside it to
1861
- * check if a restore is currently in progress. `useQuery` and friends also check this internally to avoid
1862
- * race conditions between the restore and mounting queries.
1863
- * @returns `true` while a persisted client is being restored, `false` otherwise.
1864
- */
1865
- var useIsRestoring = () => import_react.useContext(IsRestoringContext);
1866
- IsRestoringContext.Provider;
1867
- // ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js
1868
- /**
1869
- * Creates the value shared through the boundary's context, which tracks whether a reset was
1870
- * requested.
1871
- * @returns The `clearReset`, `isReset`, and `reset` functions of the boundary.
1872
- */
1873
- function createValue() {
1874
- let isReset = false;
1875
- return {
1876
- /**
1877
- * Clears the reset state, so queries know not to try again until the boundary is reset again.
1878
- */
1879
- clearReset: () => {
1880
- isReset = false;
1881
- },
1882
- /**
1883
- * Resets any query errors within the boundary, so queries know they can try again.
1884
- */
1885
- reset: () => {
1886
- isReset = true;
1887
- },
1888
- /**
1889
- * Returns whether the boundary has been reset and not yet cleared.
1890
- * @returns `true` if the boundary has been reset and not yet cleared.
1891
- */
1892
- isReset: () => {
1893
- return isReset;
1894
- }
1895
- };
1896
- }
1897
- var QueryErrorResetBoundaryContext = import_react.createContext(createValue());
1898
- /**
1899
- * This hook will reset any query errors within the closest `QueryErrorResetBoundary`. If there is no boundary
1900
- * defined it will reset them globally.
1901
- * @returns The boundary's {@link QueryErrorResetBoundaryValue}.
1902
- * @example
1903
- * ```tsx
1904
- * import { ErrorBoundary } from 'react-error-boundary'
1905
- * import { useQueryErrorResetBoundary } from '@tanstack/react-query'
1906
- *
1907
- * function App({ children }: { children: React.ReactNode }) {
1908
- * const { reset } = useQueryErrorResetBoundary()
1909
- *
1910
- * return (
1911
- * <ErrorBoundary
1912
- * onReset={reset}
1913
- * fallbackRender={({ resetErrorBoundary }) => (
1914
- * <div>
1915
- * There was an error!
1916
- * <button onClick={() => resetErrorBoundary()}>Try again</button>
1917
- * </div>
1918
- * )}
1919
- * >
1920
- * {children}
1921
- * </ErrorBoundary>
1922
- * )
1923
- * }
1924
- * ```
1925
- */
1926
- var useQueryErrorResetBoundary = () => import_react.useContext(QueryErrorResetBoundaryContext);
1927
- // ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js
1928
- /**
1929
- * Turns off `retryOnMount` for a query that throws its errors (with `suspense` or `throwOnError`),
1930
- * unless the error boundary has been reset, so a remount doesn't retry the failed query before the
1931
- * user resets the boundary. Mutates the options.
1932
- * @param options - The defaulted query options to adjust.
1933
- * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
1934
- * @param query - The query, used to evaluate a `throwOnError` function against its error.
1935
- */
1936
- var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary, query) => {
1937
- const throwOnError = query?.state.status === "error" && typeof options.throwOnError === "function" ? shouldThrowError(options.throwOnError, [query.state.error, query]) : options.throwOnError;
1938
- if (options.suspense || throwOnError) {
1939
- if (!errorResetBoundary.isReset()) options.retryOnMount = false;
1940
- }
1941
- };
1942
- /**
1943
- * Clears the reset state of the error boundary after the component mounts, so later errors are
1944
- * thrown to the boundary again.
1945
- * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
1946
- */
1947
- var useClearResetErrorBoundary = (errorResetBoundary) => {
1948
- import_react.useEffect(() => {
1949
- errorResetBoundary.clearReset();
1950
- }, [errorResetBoundary]);
1951
- };
1952
- /**
1953
- * Checks whether the query error should be thrown to the nearest error boundary: the query errored
1954
- * and isn't fetching, the boundary hasn't been reset, and either `suspense` is enabled with no data
1955
- * or `throwOnError` says so.
1956
- * @param params - The observer `result`, the `errorResetBoundary`, the `throwOnError` option, the
1957
- * `query`, and the `suspense` option.
1958
- * @returns `true` if the error should be thrown.
1959
- */
1960
- var getHasError = ({ result, errorResetBoundary, throwOnError, query, suspense }) => {
1961
- return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || shouldThrowError(throwOnError, [result.error, query]));
1962
- };
1963
- // ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/suspense.js
1964
- /**
1965
- * The default `throwOnError` of the suspense hooks: throws the error to the nearest error boundary
1966
- * only if the query has no data to show.
1967
- * @param _error - The error of the query. Unused.
1968
- * @param query - The query that errored.
1969
- * @returns `true` if the query has no data.
1970
- */
1971
- var defaultThrowOnError = (_error, query) => query.state.data === void 0;
1972
- /**
1973
- * Raises `staleTime` and a numeric `gcTime` to at least 1000ms when `suspense` is enabled, so a
1974
- * component that remounts after suspending doesn't refetch right away or find the query garbage
1975
- * collected. A `'static'` `staleTime` is kept as is. Mutates the options.
1976
- * @param defaultedOptions - The defaulted query options to adjust.
1977
- */
1978
- var ensureSuspenseTimers = (defaultedOptions) => {
1979
- if (defaultedOptions.suspense) {
1980
- const MIN_SUSPENSE_TIME_MS = 1e3;
1981
- const clamp = (value) => value === "static" ? value : Math.max(value ?? MIN_SUSPENSE_TIME_MS, MIN_SUSPENSE_TIME_MS);
1982
- const originalStaleTime = defaultedOptions.staleTime;
1983
- defaultedOptions.staleTime = typeof originalStaleTime === "function" ? (...args) => clamp(originalStaleTime(...args)) : clamp(originalStaleTime);
1984
- if (typeof defaultedOptions.gcTime === "number") defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, MIN_SUSPENSE_TIME_MS);
1985
- }
1986
- };
1987
- /**
1988
- * Checks whether a query should suspend: `suspense` is enabled and the result is still `pending`.
1989
- * @param defaultedOptions - The defaulted query options, if any.
1990
- * @param result - The current result of the observer.
1991
- * @returns `true` if the component should suspend.
1992
- */
1993
- var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
1994
- /**
1995
- * Fetches the query for a suspending component, without affecting the observer's own result. If
1996
- * the fetch fails, the reset state of the error boundary is cleared, so the error is thrown to it.
1997
- * @param defaultedOptions - The defaulted query options to fetch with.
1998
- * @param observer - The observer of the query.
1999
- * @param errorResetBoundary - The value of the nearest `QueryErrorResetBoundary`.
2000
- * @returns A promise that resolves once the fetch settles. It never rejects.
2001
- */
2002
- var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
2003
- errorResetBoundary.clearReset();
2004
- });
2005
- // ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/useBaseQuery.js
2006
- /**
2007
- * Base implementation shared by `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and
2008
- * `useSuspenseInfiniteQuery`.
2009
- * @param options - The options passed to the calling hook.
2010
- * @param Observer - The observer class from query-core (`QueryObserver` or
2011
- * `InfiniteQueryObserver`).
2012
- * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest
2013
- * context will be used.
2014
- * @returns The query result, tracking which properties are read unless `notifyOnChangeProps` is
2015
- * set.
2016
- * @throws {Error} If `options` is not an object (outside production), or the query error when it should be
2017
- * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
2018
- */
2019
- function useBaseQuery(options, Observer, queryClient) {
2020
- const isRestoring = useIsRestoring();
2021
- const errorResetBoundary = useQueryErrorResetBoundary();
2022
- const client = useQueryClient(queryClient);
2023
- const defaultedOptions = client.defaultQueryOptions(options);
2024
- const query = client.getQueryCache().get(defaultedOptions.queryHash);
2025
- const subscribed = options.subscribed !== false;
2026
- defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : subscribed ? "optimistic" : void 0;
2027
- ensureSuspenseTimers(defaultedOptions);
2028
- ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query);
2029
- useClearResetErrorBoundary(errorResetBoundary);
2030
- const [observer] = import_react.useState(() => new Observer(client, defaultedOptions));
2031
- const result = observer.getOptimisticResult(defaultedOptions);
2032
- import_react.useEffect(() => {
2033
- observer.setOptions(defaultedOptions);
2034
- }, [defaultedOptions, observer]);
2035
- const shouldSubscribe = !isRestoring && subscribed;
2036
- import_react.useSyncExternalStore(import_react.useCallback((onStoreChange) => {
2037
- const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;
2038
- observer.updateResult();
2039
- return unsubscribe;
2040
- }, [observer, shouldSubscribe]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
2041
- if (shouldSuspend(defaultedOptions, result)) throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
2042
- if (getHasError({
2043
- result,
2044
- errorResetBoundary,
2045
- throwOnError: defaultedOptions.throwOnError,
2046
- query,
2047
- suspense: defaultedOptions.suspense
2048
- })) throw result.error;
2049
- return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
2050
- }
2051
1
  // ../../node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
2052
2
  function r(e) {
2053
3
  var t, f, n = "";
@@ -5520,9 +3470,4 @@ var getDefaultConfig = () => {
5520
3470
  };
5521
3471
  };
5522
3472
  var twMerge = /*#__PURE__*/ createTailwindMerge(getDefaultConfig);
5523
- // src/lib/cn.ts
5524
- /** Joins class names, letting a later Tailwind utility replace a conflicting earlier one. */
5525
- function cn(...inputs) {
5526
- return twMerge(clsx(inputs));
5527
- }
5528
- export { QueryObserver as a, createRetryer as c, focusManager as d, Subscribable as f, defaultThrowOnError as i, onlineManager as l, useQueryClient as m, clsx as n, Query as o, QueryClientProvider as p, useBaseQuery as r, Removable as s, cn as t, notifyManager as u };
3473
+ export { clsx as n, twMerge as t };