@go-avro/avro-js 0.0.39 → 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.
@@ -17,7 +17,10 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, queryClient, con
17
17
  return () => {
18
18
  try {
19
19
  client.teardownSocketInvalidation();
20
- client.socket?.disconnect();
20
+ // Socket is NOT disconnected here. Its lifecycle is managed by the
21
+ // AvroQueryClient constructor and token refresh callbacks.
22
+ // Disconnecting here breaks React StrictMode — the constructor's
23
+ // async connect flow has already completed, so the socket stays dead.
21
24
  }
22
25
  catch (e) {
23
26
  // ignore
@@ -1,7 +1,7 @@
1
1
  import io from "socket.io-client";
2
2
  import { useMutation, useQueryClient, } from "@tanstack/react-query";
3
3
  import { v4 as uuidv4 } from "uuid";
4
- import { Job, LoginResponse, } from "../types/api";
4
+ import { _Event, Job, LoginResponse, Route, } from "../types/api";
5
5
  import { AuthState } from "../types/auth";
6
6
  import { StandardError } from "../types/error";
7
7
  function isBulkEvent(c) {
@@ -53,11 +53,13 @@ const SOCKET_EVENT_CONFIG = {
53
53
  entityKey: "routes",
54
54
  action: "create",
55
55
  fetchPath: (id) => `/route/${id}`,
56
+ construct: (d) => new Route(d),
56
57
  },
57
58
  update_route: {
58
59
  entityKey: "routes",
59
60
  action: "update",
60
61
  fetchPath: (id) => `/route/${id}`,
62
+ construct: (d) => new Route(d),
61
63
  },
62
64
  delete_route: { entityKey: "routes", action: "delete", fetchPath: null },
63
65
  // ── Events (also refetch parent job — overdueness, last_event, etc.) ──
@@ -65,6 +67,7 @@ const SOCKET_EVENT_CONFIG = {
65
67
  entityKey: "events",
66
68
  action: "create",
67
69
  fetchPath: (id) => `/event/${id}`,
70
+ construct: (d) => new _Event(d),
68
71
  relatedRefetch: [
69
72
  {
70
73
  entityKey: "jobs",
@@ -78,6 +81,7 @@ const SOCKET_EVENT_CONFIG = {
78
81
  entityKey: "events",
79
82
  action: "update",
80
83
  fetchPath: (id) => `/event/${id}`,
84
+ construct: (d) => new _Event(d),
81
85
  relatedRefetch: [
82
86
  {
83
87
  entityKey: "jobs",
@@ -239,7 +243,6 @@ export class AvroQueryClient {
239
243
  ])
240
244
  .then(([id, token]) => {
241
245
  this.companyId = id;
242
- console.log("Initializing socket connection with token:", token);
243
246
  this.socket.auth = { token: token };
244
247
  this.socket.connect();
245
248
  })
@@ -267,7 +270,6 @@ export class AvroQueryClient {
267
270
  this.config.authManager.onTokenRefreshed((newAccessToken) => {
268
271
  if (this.socket && newAccessToken) {
269
272
  this.setAuthState(AuthState.AUTHENTICATED);
270
- console.log("Access token refreshed, updating socket auth...");
271
273
  this.socket.auth = { token: newAccessToken };
272
274
  this.socket.disconnect().connect();
273
275
  }
@@ -336,7 +338,6 @@ export class AvroQueryClient {
336
338
  const { entityKey, action, fetchPath, idField, alsoInvalidate, relatedRefetch, } = config;
337
339
  const handler = async (data) => {
338
340
  const id = data?.[idField ?? "id"];
339
- // No id → old backend or malformed payload → full invalidation
340
341
  if (!id || typeof id !== "string") {
341
342
  invalidateEntity(entityKey);
342
343
  alsoInvalidate?.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
@@ -378,6 +379,9 @@ export class AvroQueryClient {
378
379
  if (this.companyId) {
379
380
  this.socket.emit("join_company", { company_id: this.companyId });
380
381
  }
382
+ else {
383
+ console.warn(`[socket-debug] joinCompanyRoom skipped — companyId is undefined`);
384
+ }
381
385
  };
382
386
  this.socket.on("connect", joinCompanyRoom);
383
387
  handlers.push({ event: "connect", handler: joinCompanyRoom });
@@ -632,7 +636,7 @@ export class AvroQueryClient {
632
636
  // ─── DELETE ─────────────────────────────────────────
633
637
  if (action === "delete") {
634
638
  queryClient.removeQueries({ queryKey: [entityKey, id], exact: true });
635
- queryClient.setQueriesData({ predicate, type: "active" }, (old) => {
639
+ queryClient.setQueriesData({ predicate }, (old) => {
636
640
  if (!old)
637
641
  return old;
638
642
  if (old.pages && Array.isArray(old.pages)) {
@@ -662,7 +666,7 @@ export class AvroQueryClient {
662
666
  const item = construct ? construct(raw) : raw;
663
667
  queryClient.setQueryData([entityKey, id], item);
664
668
  if (action === "create") {
665
- queryClient.setQueriesData({ predicate, type: "active" }, (old) => {
669
+ queryClient.setQueriesData({ predicate }, (old) => {
666
670
  if (!old)
667
671
  return old;
668
672
  if (old.pages && Array.isArray(old.pages)) {
@@ -683,7 +687,7 @@ export class AvroQueryClient {
683
687
  }
684
688
  else {
685
689
  // UPDATE — replace in every active list / infinite-query cache
686
- queryClient.setQueriesData({ predicate, type: "active" }, (old) => {
690
+ queryClient.setQueriesData({ predicate }, (old) => {
687
691
  if (!old)
688
692
  return old;
689
693
  if (old.pages && Array.isArray(old.pages)) {
@@ -700,7 +704,8 @@ export class AvroQueryClient {
700
704
  }
701
705
  return item;
702
706
  }
703
- catch {
707
+ catch (err) {
708
+ console.error(`[socket-debug] _syncEntity fetch FAILED for ${entityKey}/${id}:`, err);
704
709
  invalidate();
705
710
  return undefined;
706
711
  }
@@ -32,14 +32,17 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
32
32
  queryKey: ["companies", "current"],
33
33
  queryFn: async () => {
34
34
  if (!this.companyId) {
35
- this.companyId = await this.config.authManager.getCompanyId();
35
+ const storedId = await this.config.authManager.getCompanyId();
36
+ if (storedId) {
37
+ await this.setCompanyId(storedId);
38
+ }
36
39
  }
37
40
  if (!this.companyId) {
38
41
  const companyList = await this.get({
39
42
  path: `/company/list`,
40
43
  });
41
44
  if (companyList.length > 0) {
42
- this.companyId = companyList[0].id;
45
+ await this.setCompanyId(companyList[0].id);
43
46
  }
44
47
  else {
45
48
  throw new Error("No company ID set and no companies available");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.39",
3
+ "version": "0.0.43",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",