@go-avro/avro-js 0.0.113 → 0.0.114

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.
@@ -365,6 +365,9 @@ const SOCKET_EVENT_CONFIG = {
365
365
  invalidateKeys: [['companies'], ['/company/list']],
366
366
  },
367
367
  // ── Location ──
368
+ // Handled surgically in setupSocketInvalidation (patches
369
+ // `current_location` / `last_location` in place); these keys are
370
+ // only the fallback for malformed payloads.
368
371
  location_update: { invalidateKeys: [['teams']] },
369
372
  // ── Prepayments ──
370
373
  update_prepayments: { invalidateKeys: [['prepayments']] },
@@ -531,13 +534,46 @@ export class AvroQueryClient {
531
534
  };
532
535
  queryClient.setQueriesData({ queryKey: ['users', 'company'] }, (old) => Array.isArray(old) ? patchMembers(old) : old);
533
536
  };
537
+ const patchTeamLocation = (data) => {
538
+ const teamId = data.team_id;
539
+ if (!teamId || typeof teamId !== 'string')
540
+ return;
541
+ const patchTeams = (teams) => {
542
+ let changed = false;
543
+ const next = teams.map((t) => {
544
+ if (t?.id !== teamId)
545
+ return t;
546
+ changed = true;
547
+ return { ...t, current_location: data };
548
+ });
549
+ return changed ? next : teams;
550
+ };
551
+ queryClient.setQueriesData({ queryKey: ['teams'] }, (old) => {
552
+ if (Array.isArray(old))
553
+ return patchTeams(old);
554
+ if (old?.pages) {
555
+ return {
556
+ ...old,
557
+ pages: old.pages.map((page) => Array.isArray(page) ? patchTeams(page) : page),
558
+ };
559
+ }
560
+ if (old?.id === teamId)
561
+ return { ...old, current_location: data };
562
+ return old;
563
+ });
564
+ };
534
565
  for (const [event, config] of Object.entries(SOCKET_EVENT_CONFIG)) {
535
566
  if (event === 'location_update' && isBulkEvent(config)) {
536
567
  const handler = (data) => {
537
- patchMemberLocation(data);
538
- for (const key of config.invalidateKeys) {
539
- queryClient.invalidateQueries({ queryKey: key });
568
+ if (!data || typeof data.latitude !== 'number') {
569
+ for (const key of config.invalidateKeys) {
570
+ queryClient.invalidateQueries({ queryKey: key });
571
+ }
540
572
  }
573
+ else {
574
+ patchTeamLocation(data);
575
+ }
576
+ patchMemberLocation(data);
541
577
  };
542
578
  this.socket.on(event, handler);
543
579
  handlers.push({ event, handler });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.0.113";
1
+ export declare const AVRO_JS_VERSION = "0.0.114";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.0.113';
3
+ export const AVRO_JS_VERSION = '0.0.114';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.113",
3
+ "version": "0.0.114",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",