@rozenite/tanstack-query-plugin 1.13.0 → 2.1.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 (29) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/devtools/assets/{CXEL7IU7-DmbowaBr.js → CXEL7IU7-BWccRGN3.js} +1 -1
  3. package/dist/devtools/assets/{tanstack-query-DRBLkSCy.js → tanstack-query-CbF_imft.js} +13 -13
  4. package/dist/devtools/tanstack-query.html +1 -1
  5. package/dist/react-native/chunks/useTanStackQueryDevTools.require.cjs +1 -1
  6. package/dist/react-native/chunks/useTanStackQueryDevTools.require.js +165 -173
  7. package/dist/rozenite.json +1 -1
  8. package/dist/sdk/index.cjs +1 -1
  9. package/dist/sdk/index.js +65 -33
  10. package/package.json +30 -34
  11. package/sdk.ts +1 -4
  12. package/src/react-native/agent/__tests__/tanstack-query-agent.test.ts +32 -31
  13. package/src/react-native/agent/tanstack-query-agent.ts +33 -97
  14. package/src/react-native/agent/useTanStackQueryAgentTools.ts +2 -7
  15. package/src/react-native/devtools-actions.ts +3 -10
  16. package/src/react-native/useHandleDevToolsMessages.ts +12 -16
  17. package/src/react-native/useHandleInitialData.ts +8 -1
  18. package/src/react-native/useSyncTanStackCache.ts +7 -22
  19. package/src/shared/agent-tools.ts +59 -44
  20. package/src/shared/dehydrate.ts +1 -3
  21. package/src/shared/hydrate.ts +11 -21
  22. package/src/shared/messaging.ts +8 -2
  23. package/src/shared/query-data-sync.test.ts +1 -5
  24. package/src/shared/query-data-sync.ts +8 -35
  25. package/src/shared/useSyncOnlineStatus.ts +4 -9
  26. package/src/ui/useHandleSyncMessages.ts +23 -31
  27. package/src/ui/useSyncDevToolsEvents.ts +4 -13
  28. package/src/ui/useSyncInitialData.test.tsx +76 -0
  29. package/src/ui/useSyncInitialData.ts +17 -4
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@rozenite/agent-shared"),a="@rozenite/tanstack-query-plugin",t={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},o={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},r={limit:{type:"number",description:"Maximum number of items to return. Defaults to 20. Maximum 100."},cursor:{type:"string",description:"Opaque pagination cursor from a previous list call."}},n={type:"object",properties:{}},i={getCacheSummary:e.defineAgentToolContract({name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:n}),getOnlineStatus:e.defineAgentToolContract({name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:n}),setOnlineStatus:e.defineAgentToolContract({name:"set-online-status",description:"Set the TanStack Query onlineManager status for testing offline/online behavior.",inputSchema:{type:"object",properties:{online:{type:"boolean",description:"Whether the TanStack Query onlineManager should be online."}},required:["online"]}}),listQueries:e.defineAgentToolContract({name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:r}}),getQueryDetails:e.defineAgentToolContract({name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),refetchQuery:e.defineAgentToolContract({name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),setQueryLoading:e.defineAgentToolContract({name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...t,enabled:{type:"boolean",description:"Whether the loading-state simulation should be enabled."}},required:["queryHash","enabled"]}}),setQueryError:e.defineAgentToolContract({name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...t,enabled:{type:"boolean",description:"Whether the error-state simulation should be enabled."}},required:["queryHash","enabled"]}}),invalidateQuery:e.defineAgentToolContract({name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),resetQuery:e.defineAgentToolContract({name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),removeQuery:e.defineAgentToolContract({name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),clearQueryCache:e.defineAgentToolContract({name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:n}),listMutations:e.defineAgentToolContract({name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:r}}),getMutationDetails:e.defineAgentToolContract({name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:o,required:["mutationId"]}}),clearMutationCache:e.defineAgentToolContract({name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:n})},u=e.defineAgentToolDescriptors(a,i);exports.TANSTACK_QUERY_AGENT_PLUGIN_ID=a;exports.tanstackQueryToolDefinitions=i;exports.tanstackQueryTools=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@rozenite/agent-shared"),n="@rozenite/tanstack-query-plugin",t={queryHash:{type:"string",description:"TanStack Query queryHash identifying the query."}},o={mutationId:{type:"number",description:"TanStack Query mutationId identifying the mutation."}},r={limit:{type:"number",description:"Maximum number of items to return. Defaults to 20. Maximum 100."},cursor:{type:"string",description:"Opaque pagination cursor from a previous list call."}},a={type:"object",properties:{}},i={getCacheSummary:e.defineAgentToolContract({name:"get-cache-summary",description:"Return aggregate TanStack Query cache health and count information.",inputSchema:a}),getOnlineStatus:e.defineAgentToolContract({name:"get-online-status",description:"Return the current TanStack Query onlineManager status.",inputSchema:a}),setOnlineStatus:e.defineAgentToolContract({name:"set-online-status",description:"Set the TanStack Query onlineManager status for testing offline/online behavior.",inputSchema:{type:"object",properties:{online:{type:"boolean",description:"Whether the TanStack Query onlineManager should be online."}},required:["online"]}}),listQueries:e.definePaginatedAgentToolContract({name:"list-queries",description:"List TanStack Query query summaries using cursor pagination.",inputSchema:{type:"object",properties:r},pagination:{kind:"cursor",fields:["queryHash","queryKey","status","fetchStatus","observersCount","isInvalidated","dataUpdatedAt","errorUpdatedAt","hasData","hasError"],defaultFields:["queryHash","queryKey","status","fetchStatus","hasError"]}}),getQueryDetails:e.defineAgentToolContract({name:"get-query-details",description:"Return a JSON-safe TanStack Query query snapshot and observer summary.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),refetchQuery:e.defineAgentToolContract({name:"refetch-query",description:"Refetch a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),setQueryLoading:e.defineAgentToolContract({name:"set-query-loading",description:"Enable or disable TanStack Query loading-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...t,enabled:{type:"boolean",description:"Whether the loading-state simulation should be enabled."}},required:["queryHash","enabled"]}}),setQueryError:e.defineAgentToolContract({name:"set-query-error",description:"Enable or disable TanStack Query error-state simulation for a query by queryHash.",inputSchema:{type:"object",properties:{...t,enabled:{type:"boolean",description:"Whether the error-state simulation should be enabled."}},required:["queryHash","enabled"]}}),invalidateQuery:e.defineAgentToolContract({name:"invalidate-query",description:"Invalidate a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),resetQuery:e.defineAgentToolContract({name:"reset-query",description:"Reset a TanStack Query query by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),removeQuery:e.defineAgentToolContract({name:"remove-query",description:"Remove a TanStack Query query from the cache by queryHash.",inputSchema:{type:"object",properties:t,required:["queryHash"]}}),clearQueryCache:e.defineAgentToolContract({name:"clear-query-cache",description:"Clear the full TanStack Query query cache.",inputSchema:a}),listMutations:e.definePaginatedAgentToolContract({name:"list-mutations",description:"List TanStack Query mutation summaries using cursor pagination.",inputSchema:{type:"object",properties:r},pagination:{kind:"cursor",fields:["mutationId","mutationKey","status","isPaused","submittedAt","failureCount","hasData","hasError"],defaultFields:["mutationId","mutationKey","status","hasError"]}}),getMutationDetails:e.defineAgentToolContract({name:"get-mutation-details",description:"Return a JSON-safe TanStack Query mutation snapshot for a mutationId.",inputSchema:{type:"object",properties:o,required:["mutationId"]}}),clearMutationCache:e.defineAgentToolContract({name:"clear-mutation-cache",description:"Clear the full TanStack Query mutation cache.",inputSchema:a})},u=e.defineAgentToolDescriptors(n,i);exports.TANSTACK_QUERY_AGENT_PLUGIN_ID=n;exports.tanstackQueryToolDefinitions=i;exports.tanstackQueryTools=u;
package/dist/sdk/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { defineAgentToolContract as e, defineAgentToolDescriptors as n } from "@rozenite/agent-shared";
2
- const i = "@rozenite/tanstack-query-plugin", t = {
1
+ import { defineAgentToolContract as e, definePaginatedAgentToolContract as r, defineAgentToolDescriptors as i } from "@rozenite/agent-shared";
2
+ const u = "@rozenite/tanstack-query-plugin", t = {
3
3
  queryHash: {
4
4
  type: "string",
5
5
  description: "TanStack Query queryHash identifying the query."
@@ -9,7 +9,7 @@ const i = "@rozenite/tanstack-query-plugin", t = {
9
9
  type: "number",
10
10
  description: "TanStack Query mutationId identifying the mutation."
11
11
  }
12
- }, a = {
12
+ }, n = {
13
13
  limit: {
14
14
  type: "number",
15
15
  description: "Maximum number of items to return. Defaults to 20. Maximum 100."
@@ -18,19 +18,19 @@ const i = "@rozenite/tanstack-query-plugin", t = {
18
18
  type: "string",
19
19
  description: "Opaque pagination cursor from a previous list call."
20
20
  }
21
- }, r = {
21
+ }, a = {
22
22
  type: "object",
23
23
  properties: {}
24
- }, u = {
24
+ }, s = {
25
25
  getCacheSummary: e({
26
26
  name: "get-cache-summary",
27
27
  description: "Return aggregate TanStack Query cache health and count information.",
28
- inputSchema: r
28
+ inputSchema: a
29
29
  }),
30
30
  getOnlineStatus: e({
31
31
  name: "get-online-status",
32
32
  description: "Return the current TanStack Query onlineManager status.",
33
- inputSchema: r
33
+ inputSchema: a
34
34
  }),
35
35
  setOnlineStatus: e({
36
36
  name: "set-online-status",
@@ -46,12 +46,28 @@ const i = "@rozenite/tanstack-query-plugin", t = {
46
46
  required: ["online"]
47
47
  }
48
48
  }),
49
- listQueries: e({
49
+ listQueries: r({
50
50
  name: "list-queries",
51
51
  description: "List TanStack Query query summaries using cursor pagination.",
52
52
  inputSchema: {
53
53
  type: "object",
54
- properties: a
54
+ properties: n
55
+ },
56
+ pagination: {
57
+ kind: "cursor",
58
+ fields: [
59
+ "queryHash",
60
+ "queryKey",
61
+ "status",
62
+ "fetchStatus",
63
+ "observersCount",
64
+ "isInvalidated",
65
+ "dataUpdatedAt",
66
+ "errorUpdatedAt",
67
+ "hasData",
68
+ "hasError"
69
+ ],
70
+ defaultFields: ["queryHash", "queryKey", "status", "fetchStatus", "hasError"]
55
71
  }
56
72
  }),
57
73
  getQueryDetails: e({
@@ -87,21 +103,23 @@ const i = "@rozenite/tanstack-query-plugin", t = {
87
103
  required: ["queryHash", "enabled"]
88
104
  }
89
105
  }),
90
- setQueryError: e({
91
- name: "set-query-error",
92
- description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
93
- inputSchema: {
94
- type: "object",
95
- properties: {
96
- ...t,
97
- enabled: {
98
- type: "boolean",
99
- description: "Whether the error-state simulation should be enabled."
100
- }
101
- },
102
- required: ["queryHash", "enabled"]
106
+ setQueryError: e(
107
+ {
108
+ name: "set-query-error",
109
+ description: "Enable or disable TanStack Query error-state simulation for a query by queryHash.",
110
+ inputSchema: {
111
+ type: "object",
112
+ properties: {
113
+ ...t,
114
+ enabled: {
115
+ type: "boolean",
116
+ description: "Whether the error-state simulation should be enabled."
117
+ }
118
+ },
119
+ required: ["queryHash", "enabled"]
120
+ }
103
121
  }
104
- }),
122
+ ),
105
123
  invalidateQuery: e({
106
124
  name: "invalidate-query",
107
125
  description: "Invalidate a TanStack Query query by queryHash.",
@@ -132,14 +150,28 @@ const i = "@rozenite/tanstack-query-plugin", t = {
132
150
  clearQueryCache: e({
133
151
  name: "clear-query-cache",
134
152
  description: "Clear the full TanStack Query query cache.",
135
- inputSchema: r
153
+ inputSchema: a
136
154
  }),
137
- listMutations: e({
155
+ listMutations: r({
138
156
  name: "list-mutations",
139
157
  description: "List TanStack Query mutation summaries using cursor pagination.",
140
158
  inputSchema: {
141
159
  type: "object",
142
- properties: a
160
+ properties: n
161
+ },
162
+ pagination: {
163
+ kind: "cursor",
164
+ fields: [
165
+ "mutationId",
166
+ "mutationKey",
167
+ "status",
168
+ "isPaused",
169
+ "submittedAt",
170
+ "failureCount",
171
+ "hasData",
172
+ "hasError"
173
+ ],
174
+ defaultFields: ["mutationId", "mutationKey", "status", "hasError"]
143
175
  }
144
176
  }),
145
177
  getMutationDetails: e({
@@ -154,14 +186,14 @@ const i = "@rozenite/tanstack-query-plugin", t = {
154
186
  clearMutationCache: e({
155
187
  name: "clear-mutation-cache",
156
188
  description: "Clear the full TanStack Query mutation cache.",
157
- inputSchema: r
189
+ inputSchema: a
158
190
  })
159
- }, c = n(
160
- i,
161
- u
191
+ }, y = i(
192
+ u,
193
+ s
162
194
  );
163
195
  export {
164
- i as TANSTACK_QUERY_AGENT_PLUGIN_ID,
165
- u as tanstackQueryToolDefinitions,
166
- c as tanstackQueryTools
196
+ u as TANSTACK_QUERY_AGENT_PLUGIN_ID,
197
+ s as tanstackQueryToolDefinitions,
198
+ y as tanstackQueryTools
167
199
  };
package/package.json CHANGED
@@ -1,48 +1,20 @@
1
1
  {
2
2
  "name": "@rozenite/tanstack-query-plugin",
3
- "version": "1.13.0",
3
+ "version": "2.1.0",
4
4
  "description": "TanStack Query for Rozenite.",
5
- "type": "module",
6
- "main": "./dist/react-native/index.cjs",
7
- "module": "./dist/react-native/index.js",
8
- "types": "./dist/react-native/index.d.ts",
9
5
  "homepage": "https://github.com/callstackincubator/rozenite#readme",
10
6
  "bugs": {
11
7
  "url": "https://github.com/callstackincubator/rozenite/issues"
12
8
  },
9
+ "license": "MIT",
13
10
  "repository": {
14
11
  "type": "git",
15
12
  "url": "https://github.com/callstackincubator/rozenite.git"
16
13
  },
17
- "dependencies": {
18
- "fast-deep-equal": "^3.1.3",
19
- "@rozenite/agent-shared": "1.13.0",
20
- "@rozenite/agent-bridge": "1.13.0",
21
- "@rozenite/plugin-bridge": "1.13.0"
22
- },
23
- "devDependencies": {
24
- "@tanstack/react-query": "^5.0.0",
25
- "@tanstack/react-query-devtools": "^5.0.0",
26
- "@types/react": "~19.2.2",
27
- "autoprefixer": "^10.4.21",
28
- "postcss": "^8.5.6",
29
- "react": "19.2.0",
30
- "react-dom": "19.2.0",
31
- "react-native": "0.83.1",
32
- "react-native-web": "^0.21.2",
33
- "tailwindcss": "^3.4.17",
34
- "tailwindcss-animate": "^1.0.7",
35
- "typescript": "~5.9.3",
36
- "vite": "^7.3.1",
37
- "rozenite": "1.13.0",
38
- "@rozenite/vite-plugin": "1.13.0"
39
- },
40
- "peerDependencies": {
41
- "@tanstack/react-query": "^5.0.0",
42
- "react": "*",
43
- "react-native": "*"
44
- },
45
- "license": "MIT",
14
+ "type": "module",
15
+ "main": "./dist/react-native/index.cjs",
16
+ "module": "./dist/react-native/index.js",
17
+ "types": "./dist/react-native/index.d.ts",
46
18
  "exports": {
47
19
  ".": {
48
20
  "types": "./dist/react-native/index.d.ts",
@@ -60,6 +32,30 @@
60
32
  "publishConfig": {
61
33
  "access": "public"
62
34
  },
35
+ "dependencies": {
36
+ "fast-deep-equal": "^3.1.3",
37
+ "@rozenite/agent-bridge": "2.1.0",
38
+ "@rozenite/agent-shared": "2.1.0",
39
+ "@rozenite/plugin-bridge": "2.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@tanstack/react-query": "^5.0.0",
43
+ "@tanstack/react-query-devtools": "^5.0.0",
44
+ "@types/react": "~19.2.3",
45
+ "react": "19.2.3",
46
+ "react-dom": "19.2.3",
47
+ "react-native": "0.86.0",
48
+ "react-native-web": "^0.21.2",
49
+ "typescript": "~5.9.3",
50
+ "vite": "^7.3.1",
51
+ "@rozenite/vite-plugin": "2.1.0",
52
+ "rozenite": "2.1.0"
53
+ },
54
+ "peerDependencies": {
55
+ "@tanstack/react-query": "^5.0.0",
56
+ "react": "*",
57
+ "react-native": "*"
58
+ },
63
59
  "scripts": {
64
60
  "build": "rozenite build",
65
61
  "dev": "rozenite dev",
package/sdk.ts CHANGED
@@ -4,10 +4,7 @@ import {
4
4
  tanstackQueryToolDefinitions,
5
5
  } from './src/shared/agent-tools.js';
6
6
 
7
- export {
8
- TANSTACK_QUERY_AGENT_PLUGIN_ID,
9
- tanstackQueryToolDefinitions,
10
- };
7
+ export { TANSTACK_QUERY_AGENT_PLUGIN_ID, tanstackQueryToolDefinitions };
11
8
 
12
9
  export const tanstackQueryTools = defineAgentToolDescriptors(
13
10
  TANSTACK_QUERY_AGENT_PLUGIN_ID,
@@ -1,15 +1,7 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import {
3
- Mutation,
4
- QueryClient,
5
- QueryObserver,
6
- onlineManager,
7
- } from '@tanstack/react-query';
2
+ import { Mutation, QueryClient, QueryObserver, onlineManager } from '@tanstack/react-query';
8
3
  import { applyTanStackQueryDevtoolsAction } from '../../devtools-actions';
9
- import {
10
- createTanStackQueryAgentController,
11
- serializeForAgent,
12
- } from '../tanstack-query-agent';
4
+ import { createTanStackQueryAgentController, serializeForAgent } from '../tanstack-query-agent';
13
5
  import { tanstackQueryToolDefinitions } from '../../../shared/agent-tools';
14
6
 
15
7
  const createQueryClient = () =>
@@ -87,9 +79,7 @@ afterEach(() => {
87
79
 
88
80
  describe('tanstack query agent controller', () => {
89
81
  it('exposes the expected tool names', () => {
90
- expect(
91
- Object.values(tanstackQueryToolDefinitions).map((tool) => tool.name),
92
- ).toEqual([
82
+ expect(Object.values(tanstackQueryToolDefinitions).map((tool) => tool.name)).toEqual([
93
83
  'get-cache-summary',
94
84
  'get-online-status',
95
85
  'set-online-status',
@@ -110,6 +100,29 @@ describe('tanstack query agent controller', () => {
110
100
  'queryHash',
111
101
  'enabled',
112
102
  ]);
103
+ expect(tanstackQueryToolDefinitions.listQueries.pagination).toMatchObject({
104
+ kind: 'cursor',
105
+ fields: expect.arrayContaining(['queryHash', 'status', 'fetchStatus']),
106
+ });
107
+ });
108
+
109
+ it('trims listQueries/listMutations defaultFields narrower than the full field set', () => {
110
+ const listQueriesPagination = tanstackQueryToolDefinitions.listQueries.pagination;
111
+ const listMutationsPagination = tanstackQueryToolDefinitions.listMutations.pagination;
112
+
113
+ expect(listQueriesPagination?.defaultFields?.length).toBeLessThan(
114
+ listQueriesPagination?.fields.length ?? 0,
115
+ );
116
+ for (const field of listQueriesPagination?.defaultFields ?? []) {
117
+ expect(listQueriesPagination?.fields).toContain(field);
118
+ }
119
+
120
+ expect(listMutationsPagination?.defaultFields?.length).toBeLessThan(
121
+ listMutationsPagination?.fields.length ?? 0,
122
+ );
123
+ for (const field of listMutationsPagination?.defaultFields ?? []) {
124
+ expect(listMutationsPagination?.fields).toContain(field);
125
+ }
113
126
  });
114
127
 
115
128
  it('lists queries with cursor pagination and invalidates stale cursors after additions', async () => {
@@ -131,9 +144,7 @@ describe('tanstack query agent controller', () => {
131
144
  limit: 1,
132
145
  cursor: firstPage.page.nextCursor,
133
146
  }),
134
- ).toThrow(
135
- 'Cursor does not match the requested listing. Run the command again.',
136
- );
147
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
137
148
 
138
149
  unsubscribe();
139
150
  });
@@ -154,9 +165,7 @@ describe('tanstack query agent controller', () => {
154
165
  limit: 1,
155
166
  cursor: firstPage.page.nextCursor,
156
167
  }),
157
- ).toThrow(
158
- 'Cursor does not match the requested listing. Run the command again.',
159
- );
168
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
160
169
 
161
170
  queryClient.setQueryData(['third'], { value: 3 });
162
171
  queryClient.setQueryData(['fourth'], { value: 4 });
@@ -168,9 +177,7 @@ describe('tanstack query agent controller', () => {
168
177
  limit: 1,
169
178
  cursor: secondPageSeed.page.nextCursor,
170
179
  }),
171
- ).toThrow(
172
- 'Cursor does not match the requested listing. Run the command again.',
173
- );
180
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
174
181
 
175
182
  unsubscribe();
176
183
  });
@@ -205,9 +212,7 @@ describe('tanstack query agent controller', () => {
205
212
  limit: 1,
206
213
  cursor: firstPage.page.nextCursor,
207
214
  }),
208
- ).toThrow(
209
- 'Cursor does not match the requested listing. Run the command again.',
210
- );
215
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
211
216
 
212
217
  const mutation = queryClient.getMutationCache().getAll()[0];
213
218
  queryClient.getMutationCache().remove(mutation);
@@ -220,9 +225,7 @@ describe('tanstack query agent controller', () => {
220
225
  limit: 1,
221
226
  cursor: secondPageSeed.page.nextCursor,
222
227
  }),
223
- ).toThrow(
224
- 'Cursor does not match the requested listing. Run the command again.',
225
- );
228
+ ).toThrow('Cursor does not match the requested listing. Run the command again.');
226
229
 
227
230
  unsubscribe();
228
231
  });
@@ -248,9 +251,7 @@ describe('tanstack query agent controller', () => {
248
251
  queryFn,
249
252
  });
250
253
 
251
- const queryHash = queryClient
252
- .getQueryCache()
253
- .find({ queryKey: ['todos', 1] })!.queryHash;
254
+ const queryHash = queryClient.getQueryCache().find({ queryKey: ['todos', 1] })!.queryHash;
254
255
  const details = controller.getQueryDetails({ queryHash });
255
256
 
256
257
  expect(details.query).toMatchObject({
@@ -32,17 +32,10 @@ type CursorState = {
32
32
  };
33
33
 
34
34
  const isPlainObject = (value: unknown): value is Record<string, unknown> => {
35
- return (
36
- !!value &&
37
- typeof value === 'object' &&
38
- Object.getPrototypeOf(value) === Object.prototype
39
- );
35
+ return !!value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype;
40
36
  };
41
37
 
42
- export const serializeForAgent = (
43
- value: unknown,
44
- seen = new WeakSet<object>()
45
- ): AgentSafeValue => {
38
+ export const serializeForAgent = (value: unknown, seen = new WeakSet<object>()): AgentSafeValue => {
46
39
  if (value == null) {
47
40
  return null;
48
41
  }
@@ -72,10 +65,7 @@ export const serializeForAgent = (
72
65
  name: value.name,
73
66
  message: value.message,
74
67
  stack: value.stack ?? null,
75
- cause: serializeForAgent(
76
- (value as Error & { cause?: unknown }).cause,
77
- seen
78
- ),
68
+ cause: serializeForAgent((value as Error & { cause?: unknown }).cause, seen),
79
69
  };
80
70
  }
81
71
 
@@ -85,7 +75,7 @@ export const serializeForAgent = (
85
75
 
86
76
  if (ArrayBuffer.isView(value)) {
87
77
  return Array.from(value as unknown as ArrayLike<number>).map((item) =>
88
- typeof item === 'number' ? item : Number(item)
78
+ typeof item === 'number' ? item : Number(item),
89
79
  );
90
80
  }
91
81
 
@@ -128,33 +118,21 @@ const sanitizeLimit = (limit?: number) => {
128
118
  return Math.min(limit, MAX_PAGE_LIMIT);
129
119
  };
130
120
 
131
- const encodeCursor = (
132
- kind: CursorKind,
133
- generation: number,
134
- offset: number
135
- ): string => {
121
+ const encodeCursor = (kind: CursorKind, generation: number, offset: number): string => {
136
122
  return `${kind}:${generation}:${offset}`;
137
123
  };
138
124
 
139
- const decodeCursor = (
140
- cursor: string,
141
- kind: CursorKind,
142
- generation: number
143
- ): number => {
125
+ const decodeCursor = (cursor: string, kind: CursorKind, generation: number): number => {
144
126
  const [cursorKind, rawGeneration, rawOffset] = cursor.split(':', 3);
145
127
  if (cursorKind !== kind || !rawGeneration || !rawOffset) {
146
- throw new Error(
147
- 'Cursor does not match the requested listing. Run the command again.'
148
- );
128
+ throw new Error('Cursor does not match the requested listing. Run the command again.');
149
129
  }
150
130
 
151
131
  const cursorGeneration = Number(rawGeneration);
152
132
  const offset = Number(rawOffset);
153
133
 
154
134
  if (!Number.isInteger(cursorGeneration) || cursorGeneration !== generation) {
155
- throw new Error(
156
- 'Cursor does not match the requested listing. Run the command again.'
157
- );
135
+ throw new Error('Cursor does not match the requested listing. Run the command again.');
158
136
  }
159
137
 
160
138
  if (!Number.isInteger(offset) || offset < 0) {
@@ -164,16 +142,9 @@ const decodeCursor = (
164
142
  return offset;
165
143
  };
166
144
 
167
- const paginate = <T>(
168
- rows: T[],
169
- kind: CursorKind,
170
- generation: number,
171
- input: PaginationInput
172
- ) => {
145
+ const paginate = <T>(rows: T[], kind: CursorKind, generation: number, input: PaginationInput) => {
173
146
  const limit = sanitizeLimit(input.limit);
174
- const startIndex = input.cursor
175
- ? decodeCursor(input.cursor, kind, generation)
176
- : 0;
147
+ const startIndex = input.cursor ? decodeCursor(input.cursor, kind, generation) : 0;
177
148
  const endIndex = Math.min(startIndex + limit, rows.length);
178
149
  const hasMore = endIndex < rows.length;
179
150
 
@@ -182,9 +153,7 @@ const paginate = <T>(
182
153
  page: {
183
154
  limit,
184
155
  hasMore,
185
- ...(hasMore
186
- ? { nextCursor: encodeCursor(kind, generation, endIndex) }
187
- : {}),
156
+ ...(hasMore ? { nextCursor: encodeCursor(kind, generation, endIndex) } : {}),
188
157
  },
189
158
  };
190
159
  };
@@ -202,16 +171,12 @@ export const resetQueryTool = tanstackQueryToolDefinitions.resetQuery;
202
171
  export const removeQueryTool = tanstackQueryToolDefinitions.removeQuery;
203
172
  export const clearQueryCacheTool = tanstackQueryToolDefinitions.clearQueryCache;
204
173
  export const listMutationsTool = tanstackQueryToolDefinitions.listMutations;
205
- export const getMutationDetailsTool =
206
- tanstackQueryToolDefinitions.getMutationDetails;
207
- export const clearMutationCacheTool =
208
- tanstackQueryToolDefinitions.clearMutationCache;
209
- export const TANSTACK_QUERY_AGENT_TOOLS = Object.values(
210
- tanstackQueryToolDefinitions,
211
- );
174
+ export const getMutationDetailsTool = tanstackQueryToolDefinitions.getMutationDetails;
175
+ export const clearMutationCacheTool = tanstackQueryToolDefinitions.clearMutationCache;
176
+ export const TANSTACK_QUERY_AGENT_TOOLS = Object.values(tanstackQueryToolDefinitions);
212
177
 
213
178
  const pickObserverOptionsSummary = (
214
- options: Record<string, unknown> | undefined
179
+ options: Record<string, unknown> | undefined,
215
180
  ): TanStackQueryObserverOptionsSummary | null => {
216
181
  if (!options) {
217
182
  return null;
@@ -238,7 +203,7 @@ const pickObserverOptionsSummary = (
238
203
  };
239
204
 
240
205
  const pickMutationOptionsSummary = (
241
- options: MutationObserverOptions<unknown, Error, unknown, unknown>
206
+ options: MutationObserverOptions<unknown, Error, unknown, unknown>,
242
207
  ): TanStackQueryMutationOptionsSummary => {
243
208
  return {
244
209
  mutationKey: serializeForAgent(options.mutationKey),
@@ -270,12 +235,9 @@ const compareQueries = (a: Query, b: Query) => {
270
235
 
271
236
  const compareMutations = (
272
237
  a: Mutation<unknown, Error, unknown, unknown>,
273
- b: Mutation<unknown, Error, unknown, unknown>
238
+ b: Mutation<unknown, Error, unknown, unknown>,
274
239
  ) => {
275
- return (
276
- b.state.submittedAt - a.state.submittedAt ||
277
- b.mutationId - a.mutationId
278
- );
240
+ return b.state.submittedAt - a.state.submittedAt || b.mutationId - a.mutationId;
279
241
  };
280
242
 
281
243
  const getQuerySummary = (query: Query) => {
@@ -293,15 +255,11 @@ const getQuerySummary = (query: Query) => {
293
255
  };
294
256
  };
295
257
 
296
- const getMutationStatus = (
297
- state: MutationState<unknown, Error, unknown, unknown>
298
- ) => {
258
+ const getMutationStatus = (state: MutationState<unknown, Error, unknown, unknown>) => {
299
259
  return state.status;
300
260
  };
301
261
 
302
- const getMutationSummary = (
303
- mutation: Mutation<unknown, Error, unknown, unknown>
304
- ) => {
262
+ const getMutationSummary = (mutation: Mutation<unknown, Error, unknown, unknown>) => {
305
263
  return {
306
264
  mutationId: mutation.mutationId,
307
265
  mutationKey: serializeForAgent(mutation.options.mutationKey),
@@ -322,9 +280,7 @@ const resolveQuery = (queryClient: QueryClient, queryHash: string) => {
322
280
  .getAll()
323
281
  .map((entry) => entry.queryHash)
324
282
  .join(', ');
325
- throw new Error(
326
- `Unknown queryHash "${queryHash}". Available: ${available || '(none)'}`
327
- );
283
+ throw new Error(`Unknown queryHash "${queryHash}". Available: ${available || '(none)'}`);
328
284
  }
329
285
 
330
286
  return query;
@@ -342,9 +298,7 @@ const resolveMutation = (queryClient: QueryClient, mutationId: number) => {
342
298
  .getAll()
343
299
  .map((entry) => entry.mutationId)
344
300
  .join(', ');
345
- throw new Error(
346
- `Unknown mutationId "${mutationId}". Available: ${available || '(none)'}`
347
- );
301
+ throw new Error(`Unknown mutationId "${mutationId}". Available: ${available || '(none)'}`);
348
302
  }
349
303
 
350
304
  return mutation;
@@ -359,26 +313,17 @@ export const buildTanStackQueryCacheSummary = (queryClient: QueryClient) => {
359
313
  queries: {
360
314
  total: queries.length,
361
315
  active: queries.filter((query) => query.getObserversCount() > 0).length,
362
- fetching: queries.filter(
363
- (query) => query.state.fetchStatus === 'fetching'
364
- ).length,
365
- pending: queries.filter((query) => query.state.status === 'pending')
366
- .length,
367
- success: queries.filter((query) => query.state.status === 'success')
368
- .length,
316
+ fetching: queries.filter((query) => query.state.fetchStatus === 'fetching').length,
317
+ pending: queries.filter((query) => query.state.status === 'pending').length,
318
+ success: queries.filter((query) => query.state.status === 'success').length,
369
319
  error: queries.filter((query) => query.state.status === 'error').length,
370
320
  invalidated: queries.filter((query) => query.state.isInvalidated).length,
371
321
  },
372
322
  mutations: {
373
323
  total: mutations.length,
374
- pending: mutations.filter(
375
- (mutation) => mutation.state.status === 'pending'
376
- ).length,
377
- success: mutations.filter(
378
- (mutation) => mutation.state.status === 'success'
379
- ).length,
380
- error: mutations.filter((mutation) => mutation.state.status === 'error')
381
- .length,
324
+ pending: mutations.filter((mutation) => mutation.state.status === 'pending').length,
325
+ success: mutations.filter((mutation) => mutation.state.status === 'success').length,
326
+ error: mutations.filter((mutation) => mutation.state.status === 'error').length,
382
327
  paused: mutations.filter((mutation) => mutation.state.isPaused).length,
383
328
  },
384
329
  };
@@ -425,12 +370,7 @@ export const createTanStackQueryAgentController = (queryClient: QueryClient) =>
425
370
  return {
426
371
  ...buildTanStackQueryCacheSummary(queryClient),
427
372
  total: queries.length,
428
- ...paginate(
429
- queries.map(getQuerySummary),
430
- 'queries',
431
- cursorState.queriesGeneration,
432
- input
433
- ),
373
+ ...paginate(queries.map(getQuerySummary), 'queries', cursorState.queriesGeneration, input),
434
374
  };
435
375
  },
436
376
 
@@ -446,7 +386,7 @@ export const createTanStackQueryAgentController = (queryClient: QueryClient) =>
446
386
  observers: query.observers.map((observer) => ({
447
387
  queryHash: query.queryHash,
448
388
  options: pickObserverOptionsSummary(
449
- observer.options as unknown as Record<string, unknown>
389
+ observer.options as unknown as Record<string, unknown>,
450
390
  ),
451
391
  })),
452
392
  },
@@ -502,9 +442,7 @@ export const createTanStackQueryAgentController = (queryClient: QueryClient) =>
502
442
  },
503
443
 
504
444
  listMutations(input: PaginationInput = {}) {
505
- const mutations = [...queryClient.getMutationCache().getAll()].sort(
506
- compareMutations
507
- );
445
+ const mutations = [...queryClient.getMutationCache().getAll()].sort(compareMutations);
508
446
 
509
447
  return {
510
448
  ...buildTanStackQueryCacheSummary(queryClient),
@@ -513,7 +451,7 @@ export const createTanStackQueryAgentController = (queryClient: QueryClient) =>
513
451
  mutations.map(getMutationSummary),
514
452
  'mutations',
515
453
  cursorState.mutationsGeneration,
516
- input
454
+ input,
517
455
  ),
518
456
  };
519
457
  },
@@ -543,6 +481,4 @@ export const createTanStackQueryAgentController = (queryClient: QueryClient) =>
543
481
  };
544
482
  };
545
483
 
546
- export type TanStackQueryAgentController = ReturnType<
547
- typeof createTanStackQueryAgentController
548
- >;
484
+ export type TanStackQueryAgentController = ReturnType<typeof createTanStackQueryAgentController>;