@go-avro/avro-js 0.0.42 → 0.0.43
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.
- package/dist/client/QueryClient.js +3 -20
- package/package.json +1 -1
|
@@ -243,7 +243,6 @@ export class AvroQueryClient {
|
|
|
243
243
|
])
|
|
244
244
|
.then(([id, token]) => {
|
|
245
245
|
this.companyId = id;
|
|
246
|
-
console.log("Initializing socket connection with token:", token);
|
|
247
246
|
this.socket.auth = { token: token };
|
|
248
247
|
this.socket.connect();
|
|
249
248
|
})
|
|
@@ -271,7 +270,6 @@ export class AvroQueryClient {
|
|
|
271
270
|
this.config.authManager.onTokenRefreshed((newAccessToken) => {
|
|
272
271
|
if (this.socket && newAccessToken) {
|
|
273
272
|
this.setAuthState(AuthState.AUTHENTICATED);
|
|
274
|
-
console.log("Access token refreshed, updating socket auth...");
|
|
275
273
|
this.socket.auth = { token: newAccessToken };
|
|
276
274
|
this.socket.disconnect().connect();
|
|
277
275
|
}
|
|
@@ -328,7 +326,6 @@ export class AvroQueryClient {
|
|
|
328
326
|
if (isBulkEvent(config)) {
|
|
329
327
|
// ── Bulk: invalidate all specified keys ──────────────
|
|
330
328
|
const handler = () => {
|
|
331
|
-
console.log(`[socket-debug] bulk event: ${event}`, config.invalidateKeys);
|
|
332
329
|
for (const key of config.invalidateKeys) {
|
|
333
330
|
queryClient.invalidateQueries({ queryKey: key });
|
|
334
331
|
}
|
|
@@ -340,11 +337,8 @@ export class AvroQueryClient {
|
|
|
340
337
|
// ── Targeted: surgical cache update ──────────────────
|
|
341
338
|
const { entityKey, action, fetchPath, idField, alsoInvalidate, relatedRefetch, } = config;
|
|
342
339
|
const handler = async (data) => {
|
|
343
|
-
console.log(`[socket-debug] targeted event: ${event}`, data);
|
|
344
340
|
const id = data?.[idField ?? "id"];
|
|
345
|
-
// No id → old backend or malformed payload → full invalidation
|
|
346
341
|
if (!id || typeof id !== "string") {
|
|
347
|
-
console.log(`[socket-debug] no id found, falling back to full invalidation for ${entityKey}`);
|
|
348
342
|
invalidateEntity(entityKey);
|
|
349
343
|
alsoInvalidate?.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
|
|
350
344
|
return;
|
|
@@ -382,10 +376,8 @@ export class AvroQueryClient {
|
|
|
382
376
|
}
|
|
383
377
|
// Auto join/leave company room
|
|
384
378
|
const joinCompanyRoom = () => {
|
|
385
|
-
console.log(`[socket-debug] joinCompanyRoom called, companyId=${this.companyId}, connected=${this.socket.connected}`);
|
|
386
379
|
if (this.companyId) {
|
|
387
380
|
this.socket.emit("join_company", { company_id: this.companyId });
|
|
388
|
-
console.log(`[socket-debug] emitted join_company for ${this.companyId}`);
|
|
389
381
|
}
|
|
390
382
|
else {
|
|
391
383
|
console.warn(`[socket-debug] joinCompanyRoom skipped — companyId is undefined`);
|
|
@@ -397,7 +389,6 @@ export class AvroQueryClient {
|
|
|
397
389
|
if (this.socket.connected && this.companyId) {
|
|
398
390
|
joinCompanyRoom();
|
|
399
391
|
}
|
|
400
|
-
console.log(`[socket-debug] setupSocketInvalidation complete, socket.connected=${this.socket.connected}, companyId=${this.companyId}`);
|
|
401
392
|
this._socketInvalidationCleanup = () => {
|
|
402
393
|
for (const { event, handler } of handlers) {
|
|
403
394
|
this.socket.off(event, handler);
|
|
@@ -580,17 +571,12 @@ export class AvroQueryClient {
|
|
|
580
571
|
setCompanyId(companyId) {
|
|
581
572
|
const previousId = this.companyId;
|
|
582
573
|
this.companyId = companyId;
|
|
583
|
-
console.log(`[socket-debug] setCompanyId called: ${companyId}, socket.connected=${this.socket.connected}, prev=${previousId}`);
|
|
584
574
|
// If the socket is already connected, leave the old room and join the new one.
|
|
585
575
|
if (this.socket.connected) {
|
|
586
576
|
if (previousId && previousId !== companyId) {
|
|
587
577
|
this.socket.emit("leave_company", { company_id: previousId });
|
|
588
578
|
}
|
|
589
579
|
this.socket.emit("join_company", { company_id: companyId });
|
|
590
|
-
console.log(`[socket-debug] setCompanyId emitted join_company for ${companyId}`);
|
|
591
|
-
}
|
|
592
|
-
else {
|
|
593
|
-
console.warn(`[socket-debug] setCompanyId: socket not connected, will join on next connect`);
|
|
594
580
|
}
|
|
595
581
|
return this.config.authManager.setCompanyId(companyId);
|
|
596
582
|
}
|
|
@@ -645,13 +631,12 @@ export class AvroQueryClient {
|
|
|
645
631
|
*/
|
|
646
632
|
async _syncEntity(queryClient, params) {
|
|
647
633
|
const { action, entityKey, id, fetchPath, construct } = params;
|
|
648
|
-
console.log(`[socket-debug] _syncEntity: action=${action}, entity=${entityKey}, id=${id}, fetchPath=${fetchPath}`);
|
|
649
634
|
const predicate = (q) => matchesEntityKey(q, entityKey);
|
|
650
635
|
const invalidate = () => queryClient.invalidateQueries({ predicate });
|
|
651
636
|
// ─── DELETE ─────────────────────────────────────────
|
|
652
637
|
if (action === "delete") {
|
|
653
638
|
queryClient.removeQueries({ queryKey: [entityKey, id], exact: true });
|
|
654
|
-
queryClient.setQueriesData({ predicate
|
|
639
|
+
queryClient.setQueriesData({ predicate }, (old) => {
|
|
655
640
|
if (!old)
|
|
656
641
|
return old;
|
|
657
642
|
if (old.pages && Array.isArray(old.pages)) {
|
|
@@ -679,10 +664,9 @@ export class AvroQueryClient {
|
|
|
679
664
|
staleTime: 0,
|
|
680
665
|
});
|
|
681
666
|
const item = construct ? construct(raw) : raw;
|
|
682
|
-
console.log(`[socket-debug] _syncEntity fetched ${entityKey}/${id}:`, item);
|
|
683
667
|
queryClient.setQueryData([entityKey, id], item);
|
|
684
668
|
if (action === "create") {
|
|
685
|
-
queryClient.setQueriesData({ predicate
|
|
669
|
+
queryClient.setQueriesData({ predicate }, (old) => {
|
|
686
670
|
if (!old)
|
|
687
671
|
return old;
|
|
688
672
|
if (old.pages && Array.isArray(old.pages)) {
|
|
@@ -703,7 +687,7 @@ export class AvroQueryClient {
|
|
|
703
687
|
}
|
|
704
688
|
else {
|
|
705
689
|
// UPDATE — replace in every active list / infinite-query cache
|
|
706
|
-
queryClient.setQueriesData({ predicate
|
|
690
|
+
queryClient.setQueriesData({ predicate }, (old) => {
|
|
707
691
|
if (!old)
|
|
708
692
|
return old;
|
|
709
693
|
if (old.pages && Array.isArray(old.pages)) {
|
|
@@ -718,7 +702,6 @@ export class AvroQueryClient {
|
|
|
718
702
|
return old;
|
|
719
703
|
});
|
|
720
704
|
}
|
|
721
|
-
console.log(`[socket-debug] _syncEntity completed ${action} for ${entityKey}/${id}`);
|
|
722
705
|
return item;
|
|
723
706
|
}
|
|
724
707
|
catch (err) {
|