@go-avro/avro-js 0.0.117 → 0.0.118
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 +95 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -360,6 +360,11 @@ const SOCKET_EVENT_CONFIG = {
|
|
|
360
360
|
construct: (d) => new Job(d),
|
|
361
361
|
},
|
|
362
362
|
// ── Scheduling ──
|
|
363
|
+
// Handled surgically in setupSocketInvalidation: when the payload
|
|
364
|
+
// carries `job_ids`, the affected jobs are bulk-fetched and patched
|
|
365
|
+
// in place instead of refetching every jobs query. These keys are
|
|
366
|
+
// the fallback for payloads without ids (legacy backends, runs
|
|
367
|
+
// where the affected set is unknown).
|
|
363
368
|
schedule_complete: {
|
|
364
369
|
invalidateKeys: [
|
|
365
370
|
['routes'],
|
|
@@ -589,6 +594,96 @@ export class AvroQueryClient {
|
|
|
589
594
|
handlers.push({ event, handler });
|
|
590
595
|
continue;
|
|
591
596
|
}
|
|
597
|
+
if (event === 'schedule_complete' && isBulkEvent(config)) {
|
|
598
|
+
// Scheduling touches a known set of jobs; refetching every
|
|
599
|
+
// jobs query on each run is untenable. When the payload
|
|
600
|
+
// names the affected ids, bulk-fetch just those jobs and
|
|
601
|
+
// patch them into the cached lists in place.
|
|
602
|
+
const handler = async (data) => {
|
|
603
|
+
// Always cheap and always stale after a run: the new
|
|
604
|
+
// routes and the company's schedule_locked banner.
|
|
605
|
+
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
606
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
607
|
+
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
608
|
+
const invalidateJobs = () => {
|
|
609
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
610
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
611
|
+
};
|
|
612
|
+
const rawIds = data?.job_ids;
|
|
613
|
+
if (!Array.isArray(rawIds)) {
|
|
614
|
+
// Legacy backend / unknown affected set
|
|
615
|
+
invalidateJobs();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const jobIds = rawIds.filter((x) => typeof x === 'string');
|
|
619
|
+
if (jobIds.length === 0)
|
|
620
|
+
return;
|
|
621
|
+
try {
|
|
622
|
+
// One request for exactly the affected jobs
|
|
623
|
+
// (`unknown_ids` = "only these ids"), serialized
|
|
624
|
+
// server-side with this user's own permissions.
|
|
625
|
+
const raw = await client.fetchJobs({
|
|
626
|
+
unknown_ids: jobIds,
|
|
627
|
+
amt: jobIds.length,
|
|
628
|
+
});
|
|
629
|
+
const fresh = new Map(raw.filter((d) => d?.id).map((d) => [d.id, new Job(d)]));
|
|
630
|
+
const matching = queryClient
|
|
631
|
+
.getQueryCache()
|
|
632
|
+
.findAll({ predicate: (q) => matchesEntityKey(q, 'jobs') });
|
|
633
|
+
for (const query of matching) {
|
|
634
|
+
const queryKey = query.queryKey;
|
|
635
|
+
// Detail cache: ['jobs', jobId]
|
|
636
|
+
if (queryKey.length === 2 && queryKey[0] === 'jobs') {
|
|
637
|
+
const detailId = queryKey[1];
|
|
638
|
+
if (typeof detailId === 'string' && fresh.has(detailId)) {
|
|
639
|
+
queryClient.setQueryData(queryKey, fresh.get(detailId));
|
|
640
|
+
}
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
// Route-filtered lists: scheduling changes
|
|
644
|
+
// membership, and an in-place patch can't
|
|
645
|
+
// insert newly-assigned jobs — refetch those
|
|
646
|
+
// (only mounted route views hold them).
|
|
647
|
+
if (queryKey[0] === 'infinite' &&
|
|
648
|
+
typeof queryKey[5] === 'string' &&
|
|
649
|
+
queryKey[5].length > 0) {
|
|
650
|
+
queryClient.invalidateQueries({ queryKey, exact: true });
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
queryClient.setQueryData(queryKey, (old) => {
|
|
654
|
+
if (!old)
|
|
655
|
+
return old;
|
|
656
|
+
const patchList = (list) => {
|
|
657
|
+
let changed = false;
|
|
658
|
+
const next = list.map((x) => {
|
|
659
|
+
const replacement = x?.id ? fresh.get(x.id) : undefined;
|
|
660
|
+
if (!replacement)
|
|
661
|
+
return x;
|
|
662
|
+
changed = true;
|
|
663
|
+
return replacement;
|
|
664
|
+
});
|
|
665
|
+
return changed ? next : list;
|
|
666
|
+
};
|
|
667
|
+
if (old.pages && Array.isArray(old.pages)) {
|
|
668
|
+
return {
|
|
669
|
+
...old,
|
|
670
|
+
pages: old.pages.map((p) => Array.isArray(p) ? patchList(p) : p),
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
if (Array.isArray(old))
|
|
674
|
+
return patchList(old);
|
|
675
|
+
return old;
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
catch {
|
|
680
|
+
invalidateJobs();
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
this.socket.on(event, handler);
|
|
684
|
+
handlers.push({ event, handler });
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
592
687
|
if (isBulkEvent(config)) {
|
|
593
688
|
// ── Bulk: invalidate all specified keys ──────────────
|
|
594
689
|
const handler = () => {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "0.0.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "0.0.118";
|
package/dist/version.js
CHANGED