Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 2026df7

Browse files
committed
fix: stringify query keys in debug messages
1 parent b3d37df commit 2026df7

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

.changeset/dirty-dingos-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-query-pocketbase': patch
3+
---
4+
5+
fix: stringify query keys in debug messages

src/lib/queries/collection.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export const createCollectionQuery = <
132132
)
133133
.then((r) => {
134134
console.log(
135-
`(C) [${queryKey}]: updating with realtime action:`,
135+
`(C) [${JSON.stringify(queryKey)}]: updating with realtime action:`,
136136
data.action,
137137
data.record.id
138138
);
@@ -145,7 +145,10 @@ export const createCollectionQuery = <
145145
);
146146
})
147147
.catch((e) => {
148-
console.log(`(C) [${queryKey}]: invalidating query due to callback error:`, e);
148+
console.log(
149+
`(C) [${JSON.stringify(queryKey)}]: invalidating query due to callback error:`,
150+
e
151+
);
149152
if (invalidateQueryOnRealtimeError) {
150153
queryClient.invalidateQueries({ queryKey, exact: true });
151154
}
@@ -154,7 +157,9 @@ export const createCollectionQuery = <
154157
})
155158
.catch((e) => {
156159
console.log(
157-
`(C) [${queryKey}]: invalidating query due to realtime subscription error:`,
160+
`(C) [${JSON.stringify(
161+
queryKey
162+
)}]: invalidating query due to realtime subscription error:`,
158163
e
159164
);
160165
if (invalidateQueryOnRealtimeError) {
@@ -165,10 +170,10 @@ export const createCollectionQuery = <
165170

166171
return {
167172
subscribe: (...args) => {
168-
console.log(`(C) [${queryKey}]: subscribing to changes...`);
173+
console.log(`(C) [${JSON.stringify(queryKey)}]: subscribing to changes...`);
169174
let unsubscriber = store.subscribe(...args);
170175
return () => {
171-
console.log(`(C) [${queryKey}]: unsubscribing from store.`);
176+
console.log(`(C) [${JSON.stringify(queryKey)}]: unsubscribing from store.`);
172177
(async () => {
173178
await (
174179
await unsubscribePromise
@@ -178,7 +183,9 @@ export const createCollectionQuery = <
178183
`${collection.collectionIdOrName}/*`
179184
)
180185
) {
181-
console.log(`(C) [${queryKey}]: no realtime listeners, marking query as stale.`);
186+
console.log(
187+
`(C) [${JSON.stringify(queryKey)}]: no realtime listeners, marking query as stale.`
188+
);
182189
queryClient.invalidateQueries({ queryKey, exact: true });
183190
}
184191
})();

src/lib/queries/infinite-collection.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const createInfiniteCollectionQuery = <
257257
)
258258
.then((r) => {
259259
console.log(
260-
`(IC) [${queryKey}]: updating with realtime action:`,
260+
`(IC) [${JSON.stringify(queryKey)}]: updating with realtime action:`,
261261
data.action,
262262
data.record.id
263263
);
@@ -270,7 +270,10 @@ export const createInfiniteCollectionQuery = <
270270
});
271271
})
272272
.catch((e) => {
273-
console.log(`(IC) [${queryKey}]: invalidating query due to callback error:`, e);
273+
console.log(
274+
`(IC) [${JSON.stringify(queryKey)}]: invalidating query due to callback error:`,
275+
e
276+
);
274277
if (invalidateQueryOnRealtimeError) {
275278
queryClient.invalidateQueries({ queryKey, exact: true });
276279
}
@@ -279,7 +282,9 @@ export const createInfiniteCollectionQuery = <
279282
})
280283
.catch((e) => {
281284
console.log(
282-
`(IC) [${queryKey}]: invalidating query due to realtime subscription error:`,
285+
`(IC) [${JSON.stringify(
286+
queryKey
287+
)}]: invalidating query due to realtime subscription error:`,
283288
e
284289
);
285290
if (invalidateQueryOnRealtimeError) {
@@ -290,10 +295,10 @@ export const createInfiniteCollectionQuery = <
290295

291296
return {
292297
subscribe: (...args) => {
293-
console.log(`(IC) [${queryKey}]: subscribing to changes...`);
298+
console.log(`(IC) [${JSON.stringify(queryKey)}]: subscribing to changes...`);
294299
let unsubscriber = store.subscribe(...args);
295300
return () => {
296-
console.log(`(IC) [${queryKey}]: unsubscribing from store.`);
301+
console.log(`(IC) [${JSON.stringify(queryKey)}]: unsubscribing from store.`);
297302
(async () => {
298303
await (
299304
await unsubscribePromise
@@ -303,7 +308,9 @@ export const createInfiniteCollectionQuery = <
303308
`${collection.collectionIdOrName}/*`
304309
)
305310
) {
306-
console.log(`(IC) [${queryKey}]: no realtime listeners, marking query as stale.`);
311+
console.log(
312+
`(IC) [${JSON.stringify(queryKey)}]: no realtime listeners, marking query as stale.`
313+
);
307314
queryClient.invalidateQueries({ queryKey, exact: true });
308315
}
309316
})();

src/lib/queries/record.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,17 @@ export const createRecordQuery = <
129129
)
130130
.then((r) => {
131131
console.log(
132-
`(R) [${queryKey}]: updating with realtime action:`,
132+
`(R) [${JSON.stringify(queryKey)}]: updating with realtime action:`,
133133
data.action,
134134
data.record.id
135135
);
136136
queryClient.setQueryData<T | null>(queryKey, () => r);
137137
})
138138
.catch((e) => {
139-
console.log(`(R) [${queryKey}]: invalidating query due to callback error:`, e);
139+
console.log(
140+
`(R) [${JSON.stringify(queryKey)}]: invalidating query due to callback error:`,
141+
e
142+
);
140143
if (invalidateQueryOnRealtimeError) {
141144
queryClient.invalidateQueries({ queryKey, exact: true });
142145
}
@@ -145,7 +148,9 @@ export const createRecordQuery = <
145148
})
146149
.catch((e) => {
147150
console.log(
148-
`(R) [${queryKey}]: invalidating query due to realtime subscription error:`,
151+
`(R) [${JSON.stringify(
152+
queryKey
153+
)}]: invalidating query due to realtime subscription error:`,
149154
e
150155
);
151156
if (invalidateQueryOnRealtimeError) {
@@ -156,10 +161,10 @@ export const createRecordQuery = <
156161

157162
return {
158163
subscribe: (...args) => {
159-
console.log(`(R) [${queryKey}]: subscribing to changes...`);
164+
console.log(`(R) [${JSON.stringify(queryKey)}]: subscribing to changes...`);
160165
let unsubscriber = store.subscribe(...args);
161166
return () => {
162-
console.log(`(R) [${queryKey}]: unsubscribing from store.`);
167+
console.log(`(R) [${JSON.stringify(queryKey)}]: unsubscribing from store.`);
163168
(async () => {
164169
await (
165170
await unsubscribePromise
@@ -169,7 +174,9 @@ export const createRecordQuery = <
169174
`${collection.collectionIdOrName}/${id}`
170175
)
171176
) {
172-
console.log(`(R) [${queryKey}]: no realtime listeners, marking query as stale.`);
177+
console.log(
178+
`(R) [${JSON.stringify(queryKey)}]: no realtime listeners, marking query as stale.`
179+
);
173180
queryClient.invalidateQueries({ queryKey, exact: true });
174181
}
175182
})();

0 commit comments

Comments
 (0)