@buoy-gg/react-query 7.0.40 → 7.0.42

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 (244) hide show
  1. package/README.md +11 -69
  2. package/lib/commonjs/checkPeer.js +1 -0
  3. package/lib/commonjs/checkPeer.web.js +1 -0
  4. package/lib/commonjs/index.js +1 -736
  5. package/lib/commonjs/preset.js +1 -243
  6. package/lib/commonjs/react-query/components/DataEditorMode.js +1 -317
  7. package/lib/commonjs/react-query/components/FilterStatusBadge.js +1 -55
  8. package/lib/commonjs/react-query/components/MutationBrowserMode.js +1 -52
  9. package/lib/commonjs/react-query/components/MutationEditorMode.js +1 -276
  10. package/lib/commonjs/react-query/components/QueryBrowserMode.js +1 -99
  11. package/lib/commonjs/react-query/components/QueryDebugInfo.js +1 -107
  12. package/lib/commonjs/react-query/components/QueryFilterViewV3.js +1 -224
  13. package/lib/commonjs/react-query/components/QuerySelector.js +1 -209
  14. package/lib/commonjs/react-query/components/ReactQueryDevToolsModal.js +1 -91
  15. package/lib/commonjs/react-query/components/ReactQuerySection.js +1 -47
  16. package/lib/commonjs/react-query/components/ReactQueryTracker.js +1 -38
  17. package/lib/commonjs/react-query/components/WifiToggle.js +1 -51
  18. package/lib/commonjs/react-query/components/modals/DataEditorModal.js +1 -103
  19. package/lib/commonjs/react-query/components/modals/MutationBrowserFooter.js +1 -61
  20. package/lib/commonjs/react-query/components/modals/MutationBrowserModal.js +1 -164
  21. package/lib/commonjs/react-query/components/modals/MutationEditorModal.js +1 -106
  22. package/lib/commonjs/react-query/components/modals/QueryBrowserFooter.js +1 -56
  23. package/lib/commonjs/react-query/components/modals/QueryBrowserModal.js +1 -254
  24. package/lib/commonjs/react-query/components/modals/ReactQueryModal.js +1 -83
  25. package/lib/commonjs/react-query/components/modals/ReactQueryModalHeader.js +1 -194
  26. package/lib/commonjs/react-query/components/modals/SwipeIndicator.js +1 -204
  27. package/lib/commonjs/react-query/components/query-browser/ActionButton.js +1 -100
  28. package/lib/commonjs/react-query/components/query-browser/ClearCacheButton.js +1 -53
  29. package/lib/commonjs/react-query/components/query-browser/Explorer.js +1 -75
  30. package/lib/commonjs/react-query/components/query-browser/MutationButton.js +1 -190
  31. package/lib/commonjs/react-query/components/query-browser/MutationDetails.js +1 -124
  32. package/lib/commonjs/react-query/components/query-browser/MutationDetailsChips.js +1 -68
  33. package/lib/commonjs/react-query/components/query-browser/MutationInformation.js +1 -118
  34. package/lib/commonjs/react-query/components/query-browser/MutationStatusCount.js +1 -84
  35. package/lib/commonjs/react-query/components/query-browser/MutationsList.js +1 -220
  36. package/lib/commonjs/react-query/components/query-browser/NetworkToggleButton.js +1 -54
  37. package/lib/commonjs/react-query/components/query-browser/QueryActions.js +1 -124
  38. package/lib/commonjs/react-query/components/query-browser/QueryBrowser.js +1 -181
  39. package/lib/commonjs/react-query/components/query-browser/QueryDetails.js +1 -141
  40. package/lib/commonjs/react-query/components/query-browser/QueryDetailsChip.js +1 -78
  41. package/lib/commonjs/react-query/components/query-browser/QueryInformation.js +1 -95
  42. package/lib/commonjs/react-query/components/query-browser/QueryRow.js +1 -96
  43. package/lib/commonjs/react-query/components/query-browser/QueryStatus.js +1 -167
  44. package/lib/commonjs/react-query/components/query-browser/QueryStatusCount.js +1 -100
  45. package/lib/commonjs/react-query/components/query-browser/StorageStatusCount.js +1 -61
  46. package/lib/commonjs/react-query/components/query-browser/index.js +1 -170
  47. package/lib/commonjs/react-query/components/query-browser/svgs.js +1 -72
  48. package/lib/commonjs/react-query/hooks/useActionButtons.js +1 -51
  49. package/lib/commonjs/react-query/hooks/useAllMutations.js +1 -85
  50. package/lib/commonjs/react-query/hooks/useAllQueries.js +1 -117
  51. package/lib/commonjs/react-query/hooks/useModalManager.js +1 -178
  52. package/lib/commonjs/react-query/hooks/useModalPersistence.js +1 -71
  53. package/lib/commonjs/react-query/hooks/useMutationActionButtons.js +1 -21
  54. package/lib/commonjs/react-query/hooks/useQueryStatusCounts.js +1 -114
  55. package/lib/commonjs/react-query/hooks/useReactQueryState.js +1 -24
  56. package/lib/commonjs/react-query/hooks/useSelectedMutation.js +1 -30
  57. package/lib/commonjs/react-query/hooks/useSelectedQuery.js +1 -96
  58. package/lib/commonjs/react-query/hooks/useStorageQueryCounts.js +1 -28
  59. package/lib/commonjs/react-query/hooks/useWifiState.js +1 -67
  60. package/lib/commonjs/react-query/stores/reactQueryEventStore.js +1 -302
  61. package/lib/commonjs/react-query/sync/dehydrate.js +1 -166
  62. package/lib/commonjs/react-query/sync/reactQuerySyncAdapter.js +1 -593
  63. package/lib/commonjs/react-query/sync/snapshotProvider.js +1 -289
  64. package/lib/commonjs/react-query/sync/useReactQuerySyncAdapter.js +1 -34
  65. package/lib/commonjs/react-query/types/types.js +1 -14
  66. package/lib/commonjs/react-query/utils/actions/deleteItem.js +1 -23
  67. package/lib/commonjs/react-query/utils/actions/emitDevToolsEvent.js +1 -40
  68. package/lib/commonjs/react-query/utils/actions/invalidate.js +1 -15
  69. package/lib/commonjs/react-query/utils/actions/refetch.js +1 -17
  70. package/lib/commonjs/react-query/utils/actions/remove.js +1 -15
  71. package/lib/commonjs/react-query/utils/actions/reset.js +1 -17
  72. package/lib/commonjs/react-query/utils/actions/triggerError.js +1 -33
  73. package/lib/commonjs/react-query/utils/actions/triggerLoading.js +1 -54
  74. package/lib/commonjs/react-query/utils/deleteNestedDataByPath.js +1 -56
  75. package/lib/commonjs/react-query/utils/getQueryStatusColor.js +1 -16
  76. package/lib/commonjs/react-query/utils/getQueryStatusLabel.js +1 -23
  77. package/lib/commonjs/react-query/utils/getStorageQueryCounts.js +1 -35
  78. package/lib/commonjs/react-query/utils/modalStorageOperations.js +1 -127
  79. package/lib/commonjs/react-query/utils/storageQueryUtils.js +1 -149
  80. package/lib/commonjs/react-query/utils/testIDs.js +1 -61
  81. package/lib/commonjs/react-query/utils/updateNestedDataByPath.js +1 -61
  82. package/lib/module/checkPeer.js +1 -0
  83. package/lib/module/checkPeer.web.js +1 -0
  84. package/lib/module/index.js +1 -135
  85. package/lib/module/preset.js +1 -239
  86. package/lib/module/react-query/components/DataEditorMode.js +1 -311
  87. package/lib/module/react-query/components/FilterStatusBadge.js +1 -51
  88. package/lib/module/react-query/components/MutationBrowserMode.js +1 -47
  89. package/lib/module/react-query/components/MutationEditorMode.js +1 -270
  90. package/lib/module/react-query/components/QueryBrowserMode.js +1 -94
  91. package/lib/module/react-query/components/QueryDebugInfo.js +1 -104
  92. package/lib/module/react-query/components/QueryFilterViewV3.js +1 -221
  93. package/lib/module/react-query/components/QuerySelector.js +1 -205
  94. package/lib/module/react-query/components/ReactQueryDevToolsModal.js +1 -87
  95. package/lib/module/react-query/components/ReactQuerySection.js +1 -43
  96. package/lib/module/react-query/components/ReactQueryTracker.js +1 -35
  97. package/lib/module/react-query/components/WifiToggle.js +1 -48
  98. package/lib/module/react-query/components/modals/DataEditorModal.js +1 -99
  99. package/lib/module/react-query/components/modals/MutationBrowserFooter.js +1 -56
  100. package/lib/module/react-query/components/modals/MutationBrowserModal.js +1 -161
  101. package/lib/module/react-query/components/modals/MutationEditorModal.js +1 -102
  102. package/lib/module/react-query/components/modals/QueryBrowserFooter.js +1 -51
  103. package/lib/module/react-query/components/modals/QueryBrowserModal.js +1 -250
  104. package/lib/module/react-query/components/modals/ReactQueryModal.js +1 -79
  105. package/lib/module/react-query/components/modals/ReactQueryModalHeader.js +1 -190
  106. package/lib/module/react-query/components/modals/SwipeIndicator.js +1 -201
  107. package/lib/module/react-query/components/query-browser/ActionButton.js +1 -96
  108. package/lib/module/react-query/components/query-browser/ClearCacheButton.js +1 -49
  109. package/lib/module/react-query/components/query-browser/Explorer.js +1 -70
  110. package/lib/module/react-query/components/query-browser/MutationButton.js +1 -186
  111. package/lib/module/react-query/components/query-browser/MutationDetails.js +1 -119
  112. package/lib/module/react-query/components/query-browser/MutationDetailsChips.js +1 -64
  113. package/lib/module/react-query/components/query-browser/MutationInformation.js +1 -113
  114. package/lib/module/react-query/components/query-browser/MutationStatusCount.js +1 -79
  115. package/lib/module/react-query/components/query-browser/MutationsList.js +1 -215
  116. package/lib/module/react-query/components/query-browser/NetworkToggleButton.js +1 -50
  117. package/lib/module/react-query/components/query-browser/QueryActions.js +1 -119
  118. package/lib/module/react-query/components/query-browser/QueryBrowser.js +1 -176
  119. package/lib/module/react-query/components/query-browser/QueryDetails.js +1 -136
  120. package/lib/module/react-query/components/query-browser/QueryDetailsChip.js +1 -74
  121. package/lib/module/react-query/components/query-browser/QueryInformation.js +1 -90
  122. package/lib/module/react-query/components/query-browser/QueryRow.js +1 -92
  123. package/lib/module/react-query/components/query-browser/QueryStatus.js +1 -163
  124. package/lib/module/react-query/components/query-browser/QueryStatusCount.js +1 -95
  125. package/lib/module/react-query/components/query-browser/StorageStatusCount.js +1 -56
  126. package/lib/module/react-query/components/query-browser/index.js +1 -22
  127. package/lib/module/react-query/components/query-browser/svgs.js +1 -64
  128. package/lib/module/react-query/hooks/useActionButtons.js +1 -46
  129. package/lib/module/react-query/hooks/useAllMutations.js +1 -82
  130. package/lib/module/react-query/hooks/useAllQueries.js +1 -114
  131. package/lib/module/react-query/hooks/useModalManager.js +1 -175
  132. package/lib/module/react-query/hooks/useModalPersistence.js +1 -67
  133. package/lib/module/react-query/hooks/useMutationActionButtons.js +1 -17
  134. package/lib/module/react-query/hooks/useQueryStatusCounts.js +1 -112
  135. package/lib/module/react-query/hooks/useReactQueryState.js +1 -20
  136. package/lib/module/react-query/hooks/useSelectedMutation.js +1 -27
  137. package/lib/module/react-query/hooks/useSelectedQuery.js +1 -92
  138. package/lib/module/react-query/hooks/useStorageQueryCounts.js +1 -25
  139. package/lib/module/react-query/hooks/useWifiState.js +1 -64
  140. package/lib/module/react-query/stores/reactQueryEventStore.js +1 -293
  141. package/lib/module/react-query/sync/dehydrate.js +1 -156
  142. package/lib/module/react-query/sync/reactQuerySyncAdapter.js +1 -589
  143. package/lib/module/react-query/sync/snapshotProvider.js +1 -284
  144. package/lib/module/react-query/sync/useReactQuerySyncAdapter.js +1 -31
  145. package/lib/module/react-query/types/types.js +1 -10
  146. package/lib/module/react-query/utils/actions/deleteItem.js +1 -19
  147. package/lib/module/react-query/utils/actions/emitDevToolsEvent.js +1 -36
  148. package/lib/module/react-query/utils/actions/invalidate.js +1 -11
  149. package/lib/module/react-query/utils/actions/refetch.js +1 -13
  150. package/lib/module/react-query/utils/actions/remove.js +1 -11
  151. package/lib/module/react-query/utils/actions/reset.js +1 -13
  152. package/lib/module/react-query/utils/actions/triggerError.js +1 -29
  153. package/lib/module/react-query/utils/actions/triggerLoading.js +1 -50
  154. package/lib/module/react-query/utils/deleteNestedDataByPath.js +1 -51
  155. package/lib/module/react-query/utils/getQueryStatusColor.js +1 -12
  156. package/lib/module/react-query/utils/getQueryStatusLabel.js +1 -19
  157. package/lib/module/react-query/utils/getStorageQueryCounts.js +1 -31
  158. package/lib/module/react-query/utils/modalStorageOperations.js +1 -117
  159. package/lib/module/react-query/utils/storageQueryUtils.js +1 -140
  160. package/lib/module/react-query/utils/testIDs.js +1 -54
  161. package/lib/module/react-query/utils/updateNestedDataByPath.js +1 -56
  162. package/lib/typescript/checkPeer.d.ts +1 -0
  163. package/lib/typescript/checkPeer.web.d.ts +2 -0
  164. package/lib/typescript/index.d.ts +1 -0
  165. package/lib/web/index.mjs +11 -0
  166. package/package.json +36 -12
  167. package/lib/typescript/index.d.ts.map +0 -1
  168. package/lib/typescript/preset.d.ts.map +0 -1
  169. package/lib/typescript/react-query/components/DataEditorMode.d.ts.map +0 -1
  170. package/lib/typescript/react-query/components/FilterStatusBadge.d.ts.map +0 -1
  171. package/lib/typescript/react-query/components/MutationBrowserMode.d.ts.map +0 -1
  172. package/lib/typescript/react-query/components/MutationEditorMode.d.ts.map +0 -1
  173. package/lib/typescript/react-query/components/QueryBrowserMode.d.ts.map +0 -1
  174. package/lib/typescript/react-query/components/QueryDebugInfo.d.ts.map +0 -1
  175. package/lib/typescript/react-query/components/QueryFilterViewV3.d.ts.map +0 -1
  176. package/lib/typescript/react-query/components/QuerySelector.d.ts.map +0 -1
  177. package/lib/typescript/react-query/components/ReactQueryDevToolsModal.d.ts.map +0 -1
  178. package/lib/typescript/react-query/components/ReactQuerySection.d.ts.map +0 -1
  179. package/lib/typescript/react-query/components/ReactQueryTracker.d.ts.map +0 -1
  180. package/lib/typescript/react-query/components/WifiToggle.d.ts.map +0 -1
  181. package/lib/typescript/react-query/components/modals/DataEditorModal.d.ts.map +0 -1
  182. package/lib/typescript/react-query/components/modals/MutationBrowserFooter.d.ts.map +0 -1
  183. package/lib/typescript/react-query/components/modals/MutationBrowserModal.d.ts.map +0 -1
  184. package/lib/typescript/react-query/components/modals/MutationEditorModal.d.ts.map +0 -1
  185. package/lib/typescript/react-query/components/modals/QueryBrowserFooter.d.ts.map +0 -1
  186. package/lib/typescript/react-query/components/modals/QueryBrowserModal.d.ts.map +0 -1
  187. package/lib/typescript/react-query/components/modals/ReactQueryModal.d.ts.map +0 -1
  188. package/lib/typescript/react-query/components/modals/ReactQueryModalHeader.d.ts.map +0 -1
  189. package/lib/typescript/react-query/components/modals/SwipeIndicator.d.ts.map +0 -1
  190. package/lib/typescript/react-query/components/query-browser/ActionButton.d.ts.map +0 -1
  191. package/lib/typescript/react-query/components/query-browser/ClearCacheButton.d.ts.map +0 -1
  192. package/lib/typescript/react-query/components/query-browser/Explorer.d.ts.map +0 -1
  193. package/lib/typescript/react-query/components/query-browser/MutationButton.d.ts.map +0 -1
  194. package/lib/typescript/react-query/components/query-browser/MutationDetails.d.ts.map +0 -1
  195. package/lib/typescript/react-query/components/query-browser/MutationDetailsChips.d.ts.map +0 -1
  196. package/lib/typescript/react-query/components/query-browser/MutationInformation.d.ts.map +0 -1
  197. package/lib/typescript/react-query/components/query-browser/MutationStatusCount.d.ts.map +0 -1
  198. package/lib/typescript/react-query/components/query-browser/MutationsList.d.ts.map +0 -1
  199. package/lib/typescript/react-query/components/query-browser/NetworkToggleButton.d.ts.map +0 -1
  200. package/lib/typescript/react-query/components/query-browser/QueryActions.d.ts.map +0 -1
  201. package/lib/typescript/react-query/components/query-browser/QueryBrowser.d.ts.map +0 -1
  202. package/lib/typescript/react-query/components/query-browser/QueryDetails.d.ts.map +0 -1
  203. package/lib/typescript/react-query/components/query-browser/QueryDetailsChip.d.ts.map +0 -1
  204. package/lib/typescript/react-query/components/query-browser/QueryInformation.d.ts.map +0 -1
  205. package/lib/typescript/react-query/components/query-browser/QueryRow.d.ts.map +0 -1
  206. package/lib/typescript/react-query/components/query-browser/QueryStatus.d.ts.map +0 -1
  207. package/lib/typescript/react-query/components/query-browser/QueryStatusCount.d.ts.map +0 -1
  208. package/lib/typescript/react-query/components/query-browser/StorageStatusCount.d.ts.map +0 -1
  209. package/lib/typescript/react-query/components/query-browser/index.d.ts.map +0 -1
  210. package/lib/typescript/react-query/components/query-browser/svgs.d.ts.map +0 -1
  211. package/lib/typescript/react-query/hooks/useActionButtons.d.ts.map +0 -1
  212. package/lib/typescript/react-query/hooks/useAllMutations.d.ts.map +0 -1
  213. package/lib/typescript/react-query/hooks/useAllQueries.d.ts.map +0 -1
  214. package/lib/typescript/react-query/hooks/useModalManager.d.ts.map +0 -1
  215. package/lib/typescript/react-query/hooks/useModalPersistence.d.ts.map +0 -1
  216. package/lib/typescript/react-query/hooks/useMutationActionButtons.d.ts.map +0 -1
  217. package/lib/typescript/react-query/hooks/useQueryStatusCounts.d.ts.map +0 -1
  218. package/lib/typescript/react-query/hooks/useReactQueryState.d.ts.map +0 -1
  219. package/lib/typescript/react-query/hooks/useSelectedMutation.d.ts.map +0 -1
  220. package/lib/typescript/react-query/hooks/useSelectedQuery.d.ts.map +0 -1
  221. package/lib/typescript/react-query/hooks/useStorageQueryCounts.d.ts.map +0 -1
  222. package/lib/typescript/react-query/hooks/useWifiState.d.ts.map +0 -1
  223. package/lib/typescript/react-query/stores/reactQueryEventStore.d.ts.map +0 -1
  224. package/lib/typescript/react-query/sync/dehydrate.d.ts.map +0 -1
  225. package/lib/typescript/react-query/sync/reactQuerySyncAdapter.d.ts.map +0 -1
  226. package/lib/typescript/react-query/sync/snapshotProvider.d.ts.map +0 -1
  227. package/lib/typescript/react-query/sync/useReactQuerySyncAdapter.d.ts.map +0 -1
  228. package/lib/typescript/react-query/types/types.d.ts.map +0 -1
  229. package/lib/typescript/react-query/utils/actions/deleteItem.d.ts.map +0 -1
  230. package/lib/typescript/react-query/utils/actions/emitDevToolsEvent.d.ts.map +0 -1
  231. package/lib/typescript/react-query/utils/actions/invalidate.d.ts.map +0 -1
  232. package/lib/typescript/react-query/utils/actions/refetch.d.ts.map +0 -1
  233. package/lib/typescript/react-query/utils/actions/remove.d.ts.map +0 -1
  234. package/lib/typescript/react-query/utils/actions/reset.d.ts.map +0 -1
  235. package/lib/typescript/react-query/utils/actions/triggerError.d.ts.map +0 -1
  236. package/lib/typescript/react-query/utils/actions/triggerLoading.d.ts.map +0 -1
  237. package/lib/typescript/react-query/utils/deleteNestedDataByPath.d.ts.map +0 -1
  238. package/lib/typescript/react-query/utils/getQueryStatusColor.d.ts.map +0 -1
  239. package/lib/typescript/react-query/utils/getQueryStatusLabel.d.ts.map +0 -1
  240. package/lib/typescript/react-query/utils/getStorageQueryCounts.d.ts.map +0 -1
  241. package/lib/typescript/react-query/utils/modalStorageOperations.d.ts.map +0 -1
  242. package/lib/typescript/react-query/utils/storageQueryUtils.d.ts.map +0 -1
  243. package/lib/typescript/react-query/utils/testIDs.d.ts.map +0 -1
  244. package/lib/typescript/react-query/utils/updateNestedDataByPath.d.ts.map +0 -1
@@ -1,593 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createReactQuerySyncAdapter = createReactQuerySyncAdapter;
7
- var _sharedUi = require("@buoy-gg/shared-ui");
8
- var _reactQuery = require("@tanstack/react-query");
9
- var _dehydrate = require("./dehydrate");
10
- var _getQueryStatusLabel = require("../utils/getQueryStatusLabel");
11
- /**
12
- * Sync adapter for the React Query tool, consumed by @buoy-gg/external-sync's
13
- * `useExternalSync` (structurally matches its ToolSyncAdapter interface so
14
- * this package doesn't need a dependency on it).
15
- *
16
- * Action handlers are ported from buoy-desktop's react-query-external-sync
17
- * (useSyncQueries.ts) so the dashboard keeps identical behavior, including
18
- * the trigger/restore loading and error simulations used by the TanStack
19
- * devtools UI.
20
- *
21
- * v2: oversized / unserializable query (and mutation) data is replaced with
22
- * on-device markers. Dashboards fetch real data via `getQueryData`.
23
- */
24
-
25
- /**
26
- * Does this patch write into the list at `path`? Only then is an
27
- * unchecked-shape warning about that list worth saying — a patch that changes
28
- * `promoCode` should not be told about an empty `results`. Mirrors the same
29
- * helper in the zustand adapter, which has warned about this since it shipped.
30
- */
31
- function touchesList(patch, path) {
32
- let cur = patch;
33
- for (const seg of path.split(".")) {
34
- if (!cur || typeof cur !== "object" || Array.isArray(cur)) return false;
35
- if (!(seg in cur)) return false;
36
- cur = cur[seg];
37
- }
38
- // An empty list stays empty; there is no new item to be unsure about.
39
- return Array.isArray(cur) ? cur.length > 0 : !!cur && typeof cur === "object";
40
- }
41
- const isPlainObject = v => !!v && typeof v === "object" && !Array.isArray(v);
42
- /** The shape category the screen depends on: array vs object vs the rest. */
43
- function shapeKind(v) {
44
- if (Array.isArray(v)) return "array";
45
- if (v === null) return "null";
46
- if (typeof v === "object") return "object";
47
- return typeof v;
48
- }
49
-
50
- /**
51
- * Objects merge key by key; arrays and primitives are replaced. Two dangers a
52
- * remote caller (an LLM most of all) hits are collected instead of silently
53
- * written:
54
- *
55
- * - `shrunk`: a non-empty array shorter than the one it replaces — "change
56
- * item 0" sent as only item 0, dropping the rest.
57
- * - `breaks`: a field whose SHAPE changes — an array or object overwritten by
58
- * null or a primitive. This is the crash we actually shipped: a model set
59
- * the siblings it wasn't changing (`sizes:null, store:null`) thinking it had
60
- * to name them, and the screen's `sizes.map(s => s.multiplier)` threw. Merge
61
- * KEEPS untouched fields, so nulling them is never necessary and never safe.
62
- *
63
- * The handler refuses either unless forced. An empty array (explicit clear)
64
- * and null→value / value→value-of-same-kind are fine.
65
- */
66
- function deepMerge(base, patch, path = "", issues = {
67
- shrunk: [],
68
- breaks: []
69
- }) {
70
- if (Array.isArray(base) && Array.isArray(patch)) {
71
- if (patch.length > 0 && patch.length < base.length) {
72
- issues.shrunk.push({
73
- path: path || "(root)",
74
- have: base.length,
75
- sent: patch.length
76
- });
77
- }
78
- return patch;
79
- }
80
- if (!isPlainObject(base) || !isPlainObject(patch)) return patch;
81
- const out = {
82
- ...base
83
- };
84
- for (const [k, v] of Object.entries(patch)) {
85
- const p = path ? `${path}.${k}` : k;
86
- if (k in base) {
87
- const from = shapeKind(base[k]);
88
- const to = shapeKind(v);
89
- // A populated array/object being replaced by null or a primitive breaks
90
- // the shape the screen renders. (object→object and array→array recurse
91
- // or replace normally; null/primitive→anything is a real value change.)
92
- if ((from === "array" || from === "object") && from !== to) {
93
- issues.breaks.push({
94
- path: p,
95
- from,
96
- to
97
- });
98
- }
99
- out[k] = deepMerge(base[k], v, p, issues);
100
- } else {
101
- out[k] = v;
102
- }
103
- }
104
- return out;
105
- }
106
- /** Parse a loose, non-hash key spelling into comparable string parts, or null. */
107
- function looseKeyParts(raw) {
108
- const trimmed = raw.trim();
109
- try {
110
- const parsed = JSON.parse(trimmed);
111
- if (Array.isArray(parsed)) {
112
- return parsed.map(k => typeof k === "object" && k !== null ? JSON.stringify(k) : String(k));
113
- }
114
- } catch {
115
- /* not JSON — fall through to comma splitting */
116
- }
117
- if (trimmed.includes(",") && !trimmed.startsWith("[")) {
118
- return trimmed.split(",").map(s => s.trim().replace(/^["']|["']$/g, ""));
119
- }
120
- return null;
121
- }
122
- function createReactQuerySyncAdapter(queryClient) {
123
- const getQuery = params => {
124
- const {
125
- queryHash
126
- } = params;
127
- const cache = queryClient.getQueryCache();
128
- let query = queryHash ? cache.get(queryHash) : undefined;
129
- // Tolerate a key that is not an exact hash. Models routinely send a
130
- // comma-joined key ("pokemon-detail,mewtwo,fetch") or a JSON array where a
131
- // hash is wanted; resolve it against the live cache by comparing each
132
- // query's key parts, so one malformed hash does not cost a turn.
133
- if (!query && typeof queryHash === "string") {
134
- const wanted = looseKeyParts(queryHash);
135
- if (wanted) {
136
- query = cache.getAll().find(q => {
137
- const parts = q.queryKey.map(k => typeof k === "object" ? JSON.stringify(k) : String(k));
138
- return parts.length === wanted.length && parts.every((p, i) => p === wanted[i]);
139
- });
140
- }
141
- }
142
- if (!query) {
143
- throw new Error(`Query with hash "${queryHash}" not found`);
144
- }
145
- return query;
146
- };
147
- return {
148
- version: 2,
149
- getSnapshot: () => ({
150
- dehydratedState: (0, _dehydrate.dehydrateQueryClient)(queryClient),
151
- isOnlineManagerOnline: _reactQuery.onlineManager.isOnline()
152
- }),
153
- subscribe: onChange => {
154
- const unsubQueries = queryClient.getQueryCache().subscribe(onChange);
155
- const unsubMutations = queryClient.getMutationCache().subscribe(onChange);
156
- const unsubOnline = _reactQuery.onlineManager.subscribe(onChange);
157
- return () => {
158
- unsubQueries();
159
- unsubMutations();
160
- unsubOnline();
161
- };
162
- },
163
- actions: {
164
- /**
165
- * On-demand detail: one query's real cached `data`. Wire-form snapshots
166
- * replace oversized / unserializable data with markers; this is the
167
- * explicit, size-guarded channel for the detail pane.
168
- */
169
- getQueryData: params => {
170
- const {
171
- queryHash,
172
- path
173
- } = params ?? {};
174
- if (!queryHash) return {
175
- found: false,
176
- reason: "missing queryHash"
177
- };
178
- const query = queryClient.getQueryCache().get(queryHash);
179
- if (!query) return {
180
- found: false,
181
- reason: "unknown queryHash"
182
- };
183
- if (path) {
184
- const at = (0, _sharedUi.readPath)(query.state.data, path);
185
- if (!at.ok) return {
186
- found: false,
187
- reason: at.error
188
- };
189
- return {
190
- found: true,
191
- queryHash,
192
- path,
193
- shape: (0, _sharedUi.shapeSummary)(at.value),
194
- data: at.value
195
- };
196
- }
197
- // Before the data, not after: a long payload is sliced at the engine's
198
- // 24,000-character cap, and the shape is what a caller needs in order to
199
- // send a correctly NESTED edit back. Ten of eleven measured `query`
200
- // write failures were one level too shallow — `{name}` for a payload
201
- // that is `{item: {name}}` — and the sketch is where that is visible in
202
- // one line even when the data is not.
203
- // A query with no data is not the same as a query holding nothing, and
204
- // the two used to be indistinguishable: an errored query, a disabled
205
- // one and an empty one all came back as a bare `{found:true}`. A reader
206
- // — an LLM most of all — then reports "the query is empty" when the
207
- // truth is "it failed with X". `listQueries` has always known; this is
208
- // the call where anyone actually asks.
209
- if (query.state.data === undefined) {
210
- const status = query.state.status;
211
- const err = query.state.error;
212
- return {
213
- found: true,
214
- queryHash,
215
- hasData: false,
216
- status,
217
- fetchStatus: query.state.fetchStatus,
218
- ...(err ? {
219
- error: err instanceof Error ? err.message : String(err)
220
- } : {}),
221
- reason: status === "error" ? "This query has no data because it FAILED. Report the error, not an empty result." : query.state.fetchStatus === "fetching" ? "No data yet — this query is still fetching." : "This query has never resolved (it may be disabled, or never enabled). It is not empty — it has nothing."
222
- };
223
- }
224
- const shape = (0, _sharedUi.shapeSummary)(query.state.data);
225
- return {
226
- found: true,
227
- queryHash,
228
- hasData: true,
229
- ...(shape ? {
230
- shape
231
- } : {}),
232
- data: (0, _dehydrate.capQueryDetail)(query.state.data)
233
- };
234
- },
235
- /**
236
- * Compact, token-bounded cache reader for a remote driver (MCP/LLM):
237
- * projects each live query to light fields (hash, key, status label,
238
- * staleness, observers, error message) — the heavy cached `data` stays on
239
- * the device unless `includeData` is set. Unlike getSnapshot (full
240
- * dehydrated cache), this is safe to read repeatedly.
241
- */
242
- listQueries: params => {
243
- const {
244
- includeData = false,
245
- staleOnly = false,
246
- limit
247
- } = params ?? {};
248
- const all = queryClient.getQueryCache().getAll();
249
- const filtered = staleOnly ? all.filter(q => q.isStale()) : all;
250
- // MOUNTED FIRST, then most-recently-updated. `limit` exists to keep
251
- // this cheap for a remote reader, and sorting by recency alone made it
252
- // lossy in the one way that matters: a detail screen's query settles
253
- // once and is then older than every background refetch, so on a cache
254
- // with more live queries than the limit the query the user is actually
255
- // LOOKING AT was the first thing dropped. Nothing downstream can undo
256
- // that — a caller re-sorting the response can only reorder survivors.
257
- const sorted = [...filtered].sort((a, b) => {
258
- const mounted = Number(b.getObserversCount() > 0) - Number(a.getObserversCount() > 0);
259
- return mounted !== 0 ? mounted : (b.state.dataUpdatedAt ?? 0) - (a.state.dataUpdatedAt ?? 0);
260
- });
261
- const capped = typeof limit === "number" && limit > 0 ? sorted.slice(0, limit) : sorted;
262
- const queries = capped.map(q => {
263
- const err = q.state.error;
264
- return {
265
- queryHash: q.queryHash,
266
- queryKey: q.queryKey,
267
- status: (0, _getQueryStatusLabel.getQueryStatusLabel)(q),
268
- fetchStatus: q.state.fetchStatus,
269
- isStale: q.isStale(),
270
- observers: q.getObserversCount(),
271
- updatedAt: q.state.dataUpdatedAt,
272
- error: err ? err.message ?? String(err) : undefined,
273
- ...(includeData ? {
274
- data: q.state.data
275
- } : {}),
276
- // The compact view exists so a caller can survey the cache without
277
- // pulling payloads; the shape is the part of a payload it actually
278
- // needs to write a correct edit, and it costs one line.
279
- ...((0, _sharedUi.shapeSummary)(q.state.data) ? {
280
- shape: (0, _sharedUi.shapeSummary)(q.state.data)
281
- } : {})
282
- };
283
- });
284
- return {
285
- queries,
286
- total: all.length,
287
- returned: queries.length,
288
- includedData: includeData
289
- };
290
- },
291
- refetch: params => {
292
- const query = getQuery(params);
293
- // Swallow fetch rejections — the resulting error state syncs anyway
294
- return query.fetch().catch(() => undefined);
295
- },
296
- invalidate: params => queryClient.invalidateQueries(getQuery(params)),
297
- reset: params => queryClient.resetQueries(getQuery(params)),
298
- /**
299
- * Dropping a query does NOT re-drive the screen watching it.
300
- *
301
- * React Query removes the cache entry; a mounted observer keeps its last
302
- * result in local state until something makes it fetch again. So the app
303
- * carries on rendering a value that now exists nowhere — including one
304
- * the agent itself wrote a moment earlier. Measured on device: `remove`
305
- * on the live menu query left the storefront showing a single fabricated
306
- * item, with no skeleton, no refetch and no error, while the cache held
307
- * no menu at all. Returning a bare null let that be reported as "done".
308
- *
309
- * `reset` is the action that actually re-drives an observed query, so
310
- * the note names it rather than leaving the caller to find out from a
311
- * screen that looks fine.
312
- */
313
- remove: params => {
314
- const target = getQuery(params);
315
- const watched = queryClient.getQueryCache().findAll(target).some(q => q.getObserversCount() > 0);
316
- queryClient.removeQueries(target);
317
- return {
318
- ok: true,
319
- ...(watched ? {
320
- note: "Removed — but a screen is still watching this query, and React Query leaves that screen rendering its LAST value (including anything written into the cache before this) until something refetches. Nothing on screen will change on its own. Use `reset` instead when you want the screen to go back to loading and fetch again."
321
- } : {})
322
- };
323
- },
324
- setQueryData: params => {
325
- const {
326
- data,
327
- merge,
328
- force,
329
- path,
330
- value
331
- } = params;
332
- /**
333
- * Address the query the way EVERY OTHER action here does.
334
- *
335
- * This action took `queryKey` and silently ignored `queryHash` — while
336
- * `listQueries` hands out `queryHash` and getQueryData / invalidate /
337
- * refetch / reset / remove / triggerError / triggerLoading all take it.
338
- * A caller that used the hash got `getQueryData(undefined)` →
339
- * `undefined`, and so a refusal about "(root): undefined → object"
340
- * that named the wrong problem. With `force:true` — which that refusal
341
- * literally suggests — it wrote under an undefined key and still
342
- * returned `{ok:true, changedKeys:[…]}`: a success report for a write
343
- * that touched nothing, which is the one outcome this codebase refuses
344
- * to ship. Ask Buoy itself was covered because the ENGINE aliases hash
345
- * → key before dispatch; the MCP server, the desktop dashboard and
346
- * Scenarios all call straight in here and were not.
347
- */
348
- const {
349
- queryKey: rawKey,
350
- queryHash
351
- } = params;
352
- let queryKey = rawKey;
353
- if (queryKey === undefined && typeof queryHash === "string") {
354
- const found = queryClient.getQueryCache().get(queryHash);
355
- if (!found) {
356
- return {
357
- ok: false,
358
- error: `Refused: no query with hash ${queryHash} is in the cache. Read listQueries for the current hashes — a query that has been removed or whose key includes changing params (a search term, a cart payload) will not match an older hash.`
359
- };
360
- }
361
- queryKey = found.queryKey;
362
- }
363
- if (queryKey === undefined) {
364
- return {
365
- ok: false,
366
- error: `Refused: no query was named. Send \`queryKey\` (the array from listQueries) or \`queryHash\` (its string form).`
367
- };
368
- }
369
- const current = queryClient.getQueryData(queryKey);
370
- /**
371
- * There is nothing to merge INTO.
372
- *
373
- * The typed-edit guard answers this with "`(root)`: undefined →
374
- * object", which describes the symptom and not the cause — and it is
375
- * the same sentence a caller used to get when the query simply could
376
- * not be found, so it taught nothing. A query with no data is usually
377
- * one that FAILED or was never enabled, and that is what the caller
378
- * needs to hear.
379
- */
380
- const existing = queryClient.getQueryCache().find({
381
- queryKey,
382
- exact: true
383
- });
384
- // Only when the query is THERE and holds nothing. A key that is not in
385
- // the cache at all is a deliberate seed — `setQueryData(["new"], …)`
386
- // creates the entry, and that has always worked.
387
- if (current === undefined && existing && (data !== undefined || path !== undefined)) {
388
- const q = existing;
389
- const status = q?.state.status;
390
- const why = status === "error" ? `it FAILED${q?.state.error ? ` (${q.state.error instanceof Error ? q.state.error.message : String(q.state.error)})` : ""}` : status === "pending" ? "it has never resolved (it may be disabled, or still loading)" : "it holds no data";
391
- return {
392
- ok: false,
393
- error: `Refused: this query has no data to edit — ${why}. There is nothing to merge into. Fix the cause first (restoreError, or let it fetch), or send force:true with the COMPLETE value if you mean to seed the cache from nothing.`,
394
- status
395
- };
396
- }
397
- // `path` is sugar over a merge, resolved against the data as it is now.
398
- // It only ever produces a patch; everything below — the keyed expansion,
399
- // the typed-edit guard, the receipt — then runs unchanged, so the guard
400
- // stays the single place that decides what a write may do.
401
- // `data` stopped being schema-required when `path` became an
402
- // alternative, so the handler has to reject NEITHER — the same hole that
403
- // let a bare `setState` fall through to a whole-store replace. Here it
404
- // would write `undefined` over a cached value.
405
- if (data === undefined && path === undefined) {
406
- return {
407
- ok: false,
408
- error: `Refused: no change was described. Send \`data\` (with merge:true for a partial edit), or \`path\` and \`value\` to set one value.`
409
- };
410
- }
411
- let patch = data;
412
- if (path !== undefined) {
413
- if (value === undefined) {
414
- return {
415
- ok: false,
416
- error: `Refused: sent \`path\` without \`value\`. Say what to set "${path}" to; if you mean to clear it, send value:null and the field must already be nullable.`
417
- };
418
- }
419
- const built = (0, _sharedUi.patchFromPath)(current, path, value);
420
- if (!built.ok) return {
421
- ok: false,
422
- error: `Refused: ${built.error}`
423
- };
424
- patch = built.patch;
425
- }
426
- if (merge || path !== undefined) {
427
- // Address list items by their own id instead of resending the list:
428
- // {"results": {"pikachu": {"name": "test123"}}}
429
- // Expanded BEFORE the guard below, so the typed-edit rule still holds
430
- // over the result. This is the only form that works when the read was
431
- // truncated — and a capped read is the normal case here, not the edge
432
- // one. See packages/shared/src/sync/keyedArrays.ts for the measurement.
433
- const expandedKeyed = force ? {
434
- patch,
435
- notes: [],
436
- error: undefined
437
- } : (0, _sharedUi.expandKeyedArrays)(current, patch);
438
- // An id that contradicts its own address is refused HERE, where we
439
- // still know both halves; the typed-edit guard downstream would only
440
- // see the item we picked and could not name the ambiguity.
441
- if (expandedKeyed.error) {
442
- return {
443
- ok: false,
444
- error: `Refused: ${expandedKeyed.error}`
445
- };
446
- }
447
- const effective = expandedKeyed.patch;
448
- // Edit like the devtools value editor: only same-type changes to
449
- // fields that already exist. One rule replaces every ad-hoc guard —
450
- // no new keys, no type changes, no null-ing a rendered array/object,
451
- // no resizing a list. This is what makes a crash structurally
452
- // impossible. `force` drops to a raw write for the rare real case.
453
- if (!force) {
454
- const violations = (0, _sharedUi.typedEditViolations)(current, effective, {
455
- noun: "data"
456
- });
457
- if (violations.length > 0) {
458
- const suggestion = (0, _sharedUi.suggestedPatch)(effective, violations);
459
- return {
460
- ok: false,
461
- error: (0, _sharedUi.refusalText)(violations, "data", suggestion),
462
- violations,
463
- ...(suggestion ? {
464
- suggestedData: suggestion
465
- } : {})
466
- };
467
- }
468
- }
469
- const next = deepMerge(current, effective);
470
- // A list that was EMPTY had no item shape for anything to check the
471
- // new item against — not the guard above, not the reader, not the
472
- // app. The zustand tool has always said so; this one stayed silent
473
- // while the system prompt told the model the note always arrives, so
474
- // a write of an invented shape into an empty list came back a clean
475
- // success and got reported as one.
476
- const unchecked = (0, _sharedUi.unshapedLists)(current).filter(p => touchesList(effective, p));
477
- queryClient.setQueryData(queryKey, next, {
478
- updatedAt: Date.now()
479
- });
480
- return {
481
- ok: true,
482
- mode: "merge",
483
- ...(path !== undefined ? {
484
- path
485
- } : {}),
486
- changedKeys: isPlainObject(effective) ? Object.keys(effective) : undefined,
487
- ...(expandedKeyed.notes.length ? {
488
- keyed: expandedKeyed.notes
489
- } : {}),
490
- ...(unchecked.length ? {
491
- unchecked: unchecked.map(p => `\`${p}\` was empty, so nothing in the app knows what its items look like and the shape of what you added was NOT checked. If the screen renders a field you left out, it will render undefined — read the query back and compare against how the screen uses it.`)
492
- } : {})
493
- };
494
- }
495
- // THE GUARD. A remote caller — an LLM most of all — reads the cached
496
- // value through a wire that truncates big payloads, edits one field,
497
- // and writes the torn object back. The screen then renders
498
- // `data.stats.map` over a field that no longer exists and the app
499
- // dies. If the replacement silently drops top-level keys the cache
500
- // has, that is almost never intended, so refuse and name the fix.
501
- if (!force && isPlainObject(current) && isPlainObject(data)) {
502
- const missing = Object.keys(current).filter(k => !(k in data));
503
- if (missing.length > 0) {
504
- return {
505
- ok: false,
506
- error: `Refused: the new value drops ${missing.length} top-level field(s) the cached value has (${missing.slice(0, 8).join(", ")}${missing.length > 8 ? ", …" : ""}). A screen rendering those fields would crash. To change some fields, send merge:true with ONLY the fields that change. To really replace the whole value, send force:true.`,
507
- missingKeys: missing
508
- };
509
- }
510
- }
511
- queryClient.setQueryData(queryKey, data, {
512
- updatedAt: Date.now()
513
- });
514
- return {
515
- ok: true,
516
- mode: "replace"
517
- };
518
- },
519
- triggerError: params => {
520
- const query = getQuery(params);
521
- const __previousQueryOptions = query.options;
522
- query.setState({
523
- status: "error",
524
- error: new Error("Unknown error from devtools"),
525
- fetchMeta: {
526
- ...query.state.fetchMeta,
527
- // @ts-expect-error This does exist
528
- __previousQueryOptions
529
- }
530
- });
531
- },
532
- restoreError: params => queryClient.resetQueries(getQuery(params)),
533
- triggerLoading: params => {
534
- const query = getQuery(params);
535
- const __previousQueryOptions = query.options;
536
- // Trigger a fetch in order to trigger suspense as well
537
- query.fetch({
538
- ...__previousQueryOptions,
539
- queryFn: () => new Promise(() => {
540
- // Never resolve — simulates perpetual loading
541
- }),
542
- gcTime: -1
543
- }).catch(() => undefined);
544
- query.setState({
545
- data: undefined,
546
- status: "pending",
547
- fetchMeta: {
548
- ...query.state.fetchMeta,
549
- // @ts-expect-error This does exist
550
- __previousQueryOptions
551
- }
552
- });
553
- },
554
- restoreLoading: params => {
555
- const query = getQuery(params);
556
- const previousState = query.state;
557
- const previousOptions = query.state.fetchMeta ? query.state.fetchMeta.__previousQueryOptions : null;
558
- query.cancel({
559
- silent: true
560
- });
561
- query.setState({
562
- ...previousState,
563
- fetchStatus: "idle",
564
- fetchMeta: null
565
- });
566
- if (previousOptions) {
567
- query.fetch(previousOptions).catch(() => undefined);
568
- }
569
- },
570
- clearQueryCache: () => {
571
- // Same trap as `remove`, across every screen at once. See its note.
572
- const watched = queryClient.getQueryCache().getAll().filter(q => q.getObserversCount() > 0).length;
573
- queryClient.getQueryCache().clear();
574
- return {
575
- ok: true,
576
- cleared: true,
577
- ...(watched ? {
578
- note: `Cleared — but ${watched} quer${watched === 1 ? "y is" : "ies are"} still being watched by a screen, and React Query leaves those screens rendering their LAST value until something refetches. The cache is empty; the app on screen is not. Use \`reset\` on a query when you want its screen to reload.`
579
- } : {})
580
- };
581
- },
582
- clearMutationCache: () => {
583
- queryClient.getMutationCache().clear();
584
- },
585
- setOnline: params => {
586
- const {
587
- online
588
- } = params;
589
- _reactQuery.onlineManager.setOnline(online);
590
- }
591
- }
592
- };
593
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createReactQuerySyncAdapter=createReactQuerySyncAdapter;var _sharedUi=require("@buoy-gg/shared-ui");var _reactQuery=require("@tanstack/react-query");var _dehydrate=require("./dehydrate");var _getQueryStatusLabel=require("../utils/getQueryStatusLabel");function touchesList(r,o){let t=r;for(const e of o.split(".")){if(!t||typeof t!=="object"||Array.isArray(t))return false;if(!(e in t))return false;t=t[e]}return Array.isArray(t)?t.length>0:!!t&&typeof t==="object"}const isPlainObject=r=>!!r&&typeof r==="object"&&!Array.isArray(r);function shapeKind(r){if(Array.isArray(r))return"array";if(r===null)return"null";if(typeof r==="object")return"object";return typeof r}function deepMerge(r,o,t="",e={shrunk:[],breaks:[]}){if(Array.isArray(r)&&Array.isArray(o)){if(o.length>0&&o.length<r.length){e.shrunk.push({path:t||"(root)",have:r.length,sent:o.length})}return o}if(!isPlainObject(r)||!isPlainObject(o))return o;const s={...r};for(const[a,u]of Object.entries(o)){const c=t?`${t}.${a}`:a;if(a in r){const d=shapeKind(r[a]);const h=shapeKind(u);if((d==="array"||d==="object")&&d!==h){e.breaks.push({path:c,from:d,to:h})}s[a]=deepMerge(r[a],u,c,e)}else{s[a]=u}}return s}function looseKeyParts(r){const o=r.trim();try{const t=JSON.parse(o);if(Array.isArray(t)){return t.map(e=>typeof e==="object"&&e!==null?JSON.stringify(e):String(e))}}catch{}if(o.includes(",")&&!o.startsWith("[")){return o.split(",").map(t=>t.trim().replace(/^["']|["']$/g,""))}return null}function createReactQuerySyncAdapter(r){const o=t=>{const{queryHash:e}=t;const s=r.getQueryCache();let a=e?s.get(e):void 0;if(!a&&typeof e==="string"){const u=looseKeyParts(e);if(u){a=s.getAll().find(c=>{const d=c.queryKey.map(h=>typeof h==="object"?JSON.stringify(h):String(h));return d.length===u.length&&d.every((h,l)=>h===u[l])})}}if(!a){throw new Error(`Query with hash "${e}" not found`)}return a};return{version:2,getSnapshot:()=>({dehydratedState:(0,_dehydrate.dehydrateQueryClient)(r),isOnlineManagerOnline:_reactQuery.onlineManager.isOnline()}),subscribe:t=>{const e=r.getQueryCache().subscribe(t);const s=r.getMutationCache().subscribe(t);const a=_reactQuery.onlineManager.subscribe(t);return()=>{e();s();a()}},actions:{getQueryData:t=>{const{queryHash:e,path:s}=t??{};if(!e)return{found:false,reason:"missing queryHash"};const a=r.getQueryCache().get(e);if(!a)return{found:false,reason:"unknown queryHash"};if(s){const c=(0,_sharedUi.readPath)(a.state.data,s);if(!c.ok)return{found:false,reason:c.error};return{found:true,queryHash:e,path:s,shape:(0,_sharedUi.shapeSummary)(c.value),data:c.value}}if(a.state.data===void 0){const c=a.state.status;const d=a.state.error;return{found:true,queryHash:e,hasData:false,status:c,fetchStatus:a.state.fetchStatus,...d?{error:d instanceof Error?d.message:String(d)}:{},reason:c==="error"?"This query has no data because it FAILED. Report the error, not an empty result.":a.state.fetchStatus==="fetching"?"No data yet \u2014 this query is still fetching.":"This query has never resolved (it may be disabled, or never enabled). It is not empty \u2014 it has nothing."}}const u=(0,_sharedUi.shapeSummary)(a.state.data);return{found:true,queryHash:e,hasData:true,...u?{shape:u}:{},data:(0,_dehydrate.capQueryDetail)(a.state.data)}},listQueries:t=>{const{includeData:e=false,staleOnly:s=false,limit:a}=t??{};const u=r.getQueryCache().getAll();const c=s?u.filter(n=>n.isStale()):u;const d=[...c].sort((n,y)=>{const p=Number(y.getObserversCount()>0)-Number(n.getObserversCount()>0);return p!==0?p:(y.state.dataUpdatedAt??0)-(n.state.dataUpdatedAt??0)});const h=typeof a==="number"&&a>0?d.slice(0,a):d;const l=h.map(n=>{const y=n.state.error;return{queryHash:n.queryHash,queryKey:n.queryKey,status:(0,_getQueryStatusLabel.getQueryStatusLabel)(n),fetchStatus:n.state.fetchStatus,isStale:n.isStale(),observers:n.getObserversCount(),updatedAt:n.state.dataUpdatedAt,error:y?y.message??String(y):void 0,...e?{data:n.state.data}:{},...(0,_sharedUi.shapeSummary)(n.state.data)?{shape:(0,_sharedUi.shapeSummary)(n.state.data)}:{}}});return{queries:l,total:u.length,returned:l.length,includedData:e}},refetch:t=>{const e=o(t);return e.fetch().catch(()=>void 0)},invalidate:t=>r.invalidateQueries(o(t)),reset:t=>r.resetQueries(o(t)),remove:t=>{const e=o(t);const s=r.getQueryCache().findAll(e).some(a=>a.getObserversCount()>0);r.removeQueries(e);return{ok:true,...s?{note:"Removed \u2014 but a screen is still watching this query, and React Query leaves that screen rendering its LAST value (including anything written into the cache before this) until something refetches. Nothing on screen will change on its own. Use `reset` instead when you want the screen to go back to loading and fetch again."}:{}}},setQueryData:t=>{const{data:e,merge:s,force:a,path:u,value:c}=t;const{queryKey:d,queryHash:h}=t;let l=d;if(l===void 0&&typeof h==="string"){const i=r.getQueryCache().get(h);if(!i){return{ok:false,error:`Refused: no query with hash ${h} is in the cache. Read listQueries for the current hashes \u2014 a query that has been removed or whose key includes changing params (a search term, a cart payload) will not match an older hash.`}}l=i.queryKey}if(l===void 0){return{ok:false,error:`Refused: no query was named. Send \`queryKey\` (the array from listQueries) or \`queryHash\` (its string form).`}}const n=r.getQueryData(l);const y=r.getQueryCache().find({queryKey:l,exact:true});if(n===void 0&&y&&(e!==void 0||u!==void 0)){const i=y;const f=i?.state.status;const m=f==="error"?`it FAILED${i?.state.error?` (${i.state.error instanceof Error?i.state.error.message:String(i.state.error)})`:""}`:f==="pending"?"it has never resolved (it may be disabled, or still loading)":"it holds no data";return{ok:false,error:`Refused: this query has no data to edit \u2014 ${m}. There is nothing to merge into. Fix the cause first (restoreError, or let it fetch), or send force:true with the COMPLETE value if you mean to seed the cache from nothing.`,status:f}}if(e===void 0&&u===void 0){return{ok:false,error:`Refused: no change was described. Send \`data\` (with merge:true for a partial edit), or \`path\` and \`value\` to set one value.`}}let p=e;if(u!==void 0){if(c===void 0){return{ok:false,error:`Refused: sent \`path\` without \`value\`. Say what to set "${u}" to; if you mean to clear it, send value:null and the field must already be nullable.`}}const i=(0,_sharedUi.patchFromPath)(n,u,c);if(!i.ok)return{ok:false,error:`Refused: ${i.error}`};p=i.patch}if(s||u!==void 0){const i=a?{patch:p,notes:[],error:void 0}:(0,_sharedUi.expandKeyedArrays)(n,p);if(i.error){return{ok:false,error:`Refused: ${i.error}`}}const f=i.patch;if(!a){const g=(0,_sharedUi.typedEditViolations)(n,f,{noun:"data"});if(g.length>0){const b=(0,_sharedUi.suggestedPatch)(f,g);return{ok:false,error:(0,_sharedUi.refusalText)(g,"data",b),violations:g,...b?{suggestedData:b}:{}}}}const m=deepMerge(n,f);const v=(0,_sharedUi.unshapedLists)(n).filter(g=>touchesList(f,g));r.setQueryData(l,m,{updatedAt:Date.now()});return{ok:true,mode:"merge",...u!==void 0?{path:u}:{},changedKeys:isPlainObject(f)?Object.keys(f):void 0,...i.notes.length?{keyed:i.notes}:{},...v.length?{unchecked:v.map(g=>`\`${g}\` was empty, so nothing in the app knows what its items look like and the shape of what you added was NOT checked. If the screen renders a field you left out, it will render undefined \u2014 read the query back and compare against how the screen uses it.`)}:{}}}if(!a&&isPlainObject(n)&&isPlainObject(e)){const i=Object.keys(n).filter(f=>!(f in e));if(i.length>0){return{ok:false,error:`Refused: the new value drops ${i.length} top-level field(s) the cached value has (${i.slice(0,8).join(", ")}${i.length>8?", \u2026":""}). A screen rendering those fields would crash. To change some fields, send merge:true with ONLY the fields that change. To really replace the whole value, send force:true.`,missingKeys:i}}}r.setQueryData(l,e,{updatedAt:Date.now()});return{ok:true,mode:"replace"}},triggerError:t=>{const e=o(t);const s=e.options;e.setState({status:"error",error:new Error("Unknown error from devtools"),fetchMeta:{...e.state.fetchMeta,__previousQueryOptions:s}})},restoreError:t=>r.resetQueries(o(t)),triggerLoading:t=>{const e=o(t);const s=e.options;e.fetch({...s,queryFn:()=>new Promise(()=>{}),gcTime:-1}).catch(()=>void 0);e.setState({data:void 0,status:"pending",fetchMeta:{...e.state.fetchMeta,__previousQueryOptions:s}})},restoreLoading:t=>{const e=o(t);const s=e.state;const a=e.state.fetchMeta?e.state.fetchMeta.__previousQueryOptions:null;e.cancel({silent:true});e.setState({...s,fetchStatus:"idle",fetchMeta:null});if(a){e.fetch(a).catch(()=>void 0)}},clearQueryCache:()=>{const t=r.getQueryCache().getAll().filter(e=>e.getObserversCount()>0).length;r.getQueryCache().clear();return{ok:true,cleared:true,...t?{note:`Cleared \u2014 but ${t} quer${t===1?"y is":"ies are"} still being watched by a screen, and React Query leaves those screens rendering their LAST value until something refetches. The cache is empty; the app on screen is not. Use \`reset\` on a query when you want its screen to reload.`}:{}}},clearMutationCache:()=>{r.getMutationCache().clear()},setOnline:t=>{const{online:e}=t;_reactQuery.onlineManager.setOnline(e)}}}}