@go-avro/avro-js 0.0.117 → 0.0.119
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.d.ts +10 -0
- package/dist/client/QueryClient.js +120 -4
- package/dist/types/api/Task.d.ts +1 -0
- package/dist/types/api/Task.js +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -783,6 +783,16 @@ export declare class AvroQueryClient {
|
|
|
783
783
|
getQueryClient(): QueryClient;
|
|
784
784
|
attachQueryClient(queryClient: QueryClient): void;
|
|
785
785
|
peekQueryClient(): QueryClient | null;
|
|
786
|
+
/**
|
|
787
|
+
* Bulk-refresh a known set of jobs after a route/scheduling change:
|
|
788
|
+
* one request for exactly those ids (`unknown_ids` = "only these
|
|
789
|
+
* ids", serialized server-side with this user's own permissions),
|
|
790
|
+
* then patch the fresh items into every cached jobs query in place.
|
|
791
|
+
* Route-filtered lists are invalidated instead — membership may have
|
|
792
|
+
* changed and an in-place patch can't insert newly-assigned jobs.
|
|
793
|
+
* Falls back to full jobs invalidation if the fetch fails.
|
|
794
|
+
*/
|
|
795
|
+
_patchJobsByIds(queryClient: QueryClient, jobIds: string[]): Promise<void>;
|
|
786
796
|
_syncEntity(queryClient: QueryClient, params: {
|
|
787
797
|
action: 'create' | 'update' | 'delete';
|
|
788
798
|
entityKey: string;
|
|
@@ -157,14 +157,15 @@ const SOCKET_EVENT_CONFIG = {
|
|
|
157
157
|
// ── Routes ──
|
|
158
158
|
// Route membership lives on jobs too (task.route_ids), so every
|
|
159
159
|
// route mutation must refresh the jobs caches or unrouted/routed
|
|
160
|
-
// state goes stale.
|
|
160
|
+
// state goes stale. The backend names the affected jobs in the
|
|
161
|
+
// payload's `job_ids`; only those get refetched and patched.
|
|
161
162
|
create_route: {
|
|
162
163
|
entityKey: 'routes',
|
|
163
164
|
action: 'create',
|
|
164
165
|
fetchPath: (id) => `/route/${id}`,
|
|
165
166
|
construct: (d) => new Route(d),
|
|
166
167
|
matchesQuery: matchesRoutesListQuery,
|
|
167
|
-
|
|
168
|
+
patchJobsFromPayload: true,
|
|
168
169
|
},
|
|
169
170
|
update_route: {
|
|
170
171
|
entityKey: 'routes',
|
|
@@ -172,13 +173,13 @@ const SOCKET_EVENT_CONFIG = {
|
|
|
172
173
|
fetchPath: (id) => `/route/${id}`,
|
|
173
174
|
construct: (d) => new Route(d),
|
|
174
175
|
matchesQuery: matchesRoutesListQuery,
|
|
175
|
-
|
|
176
|
+
patchJobsFromPayload: true,
|
|
176
177
|
},
|
|
177
178
|
delete_route: {
|
|
178
179
|
entityKey: 'routes',
|
|
179
180
|
action: 'delete',
|
|
180
181
|
fetchPath: null,
|
|
181
|
-
|
|
182
|
+
patchJobsFromPayload: true,
|
|
182
183
|
},
|
|
183
184
|
// ── Events (also refetch parent job — overdueness, last_event, etc.) ──
|
|
184
185
|
create_event: {
|
|
@@ -360,6 +361,11 @@ const SOCKET_EVENT_CONFIG = {
|
|
|
360
361
|
construct: (d) => new Job(d),
|
|
361
362
|
},
|
|
362
363
|
// ── Scheduling ──
|
|
364
|
+
// Handled surgically in setupSocketInvalidation: when the payload
|
|
365
|
+
// carries `job_ids`, the affected jobs are bulk-fetched and patched
|
|
366
|
+
// in place instead of refetching every jobs query. These keys are
|
|
367
|
+
// the fallback for payloads without ids (legacy backends, runs
|
|
368
|
+
// where the affected set is unknown).
|
|
363
369
|
schedule_complete: {
|
|
364
370
|
invalidateKeys: [
|
|
365
371
|
['routes'],
|
|
@@ -589,6 +595,30 @@ export class AvroQueryClient {
|
|
|
589
595
|
handlers.push({ event, handler });
|
|
590
596
|
continue;
|
|
591
597
|
}
|
|
598
|
+
if (event === 'schedule_complete' && isBulkEvent(config)) {
|
|
599
|
+
// Scheduling touches a known set of jobs; refetching every
|
|
600
|
+
// jobs query on each run is untenable. When the payload
|
|
601
|
+
// names the affected ids, bulk-fetch just those jobs and
|
|
602
|
+
// patch them into the cached lists in place.
|
|
603
|
+
const handler = async (data) => {
|
|
604
|
+
// Always cheap and always stale after a run: the new
|
|
605
|
+
// routes and the company's schedule_locked banner.
|
|
606
|
+
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
607
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
608
|
+
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
609
|
+
const rawIds = data?.job_ids;
|
|
610
|
+
if (!Array.isArray(rawIds)) {
|
|
611
|
+
// Legacy backend / unknown affected set
|
|
612
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
613
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
await client._patchJobsByIds(queryClient, rawIds.filter((x) => typeof x === 'string'));
|
|
617
|
+
};
|
|
618
|
+
this.socket.on(event, handler);
|
|
619
|
+
handlers.push({ event, handler });
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
592
622
|
if (isBulkEvent(config)) {
|
|
593
623
|
// ── Bulk: invalidate all specified keys ──────────────
|
|
594
624
|
const handler = () => {
|
|
@@ -604,9 +634,25 @@ export class AvroQueryClient {
|
|
|
604
634
|
const { entityKey, action, fetchPath, idField, alsoInvalidate, relatedRefetch } = config;
|
|
605
635
|
const handler = async (data) => {
|
|
606
636
|
const id = data?.[idField ?? 'id'];
|
|
637
|
+
// Refresh the jobs whose route associations this event
|
|
638
|
+
// changed: patch the ids named in the payload, or fall
|
|
639
|
+
// back to full jobs invalidation when a legacy backend
|
|
640
|
+
// didn't send any.
|
|
641
|
+
const syncAffectedJobs = async () => {
|
|
642
|
+
if (!config.patchJobsFromPayload)
|
|
643
|
+
return;
|
|
644
|
+
const rawIds = data?.job_ids;
|
|
645
|
+
if (!Array.isArray(rawIds)) {
|
|
646
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
647
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
await client._patchJobsByIds(queryClient, rawIds.filter((x) => typeof x === 'string'));
|
|
651
|
+
};
|
|
607
652
|
if (!id || typeof id !== 'string') {
|
|
608
653
|
invalidateEntity(entityKey);
|
|
609
654
|
alsoInvalidate?.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
|
|
655
|
+
await syncAffectedJobs();
|
|
610
656
|
return;
|
|
611
657
|
}
|
|
612
658
|
let fetchedItem;
|
|
@@ -621,6 +667,7 @@ export class AvroQueryClient {
|
|
|
621
667
|
});
|
|
622
668
|
// Invalidate any additional keys (e.g. companies → /company/list)
|
|
623
669
|
alsoInvalidate?.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
|
|
670
|
+
await syncAffectedJobs();
|
|
624
671
|
if (relatedRefetch) {
|
|
625
672
|
for (const related of relatedRefetch) {
|
|
626
673
|
const relatedId = data?.[related.idField] ?? fetchedItem?.[related.idField];
|
|
@@ -910,6 +957,75 @@ export class AvroQueryClient {
|
|
|
910
957
|
peekQueryClient() {
|
|
911
958
|
return this._queryClient;
|
|
912
959
|
}
|
|
960
|
+
/**
|
|
961
|
+
* Bulk-refresh a known set of jobs after a route/scheduling change:
|
|
962
|
+
* one request for exactly those ids (`unknown_ids` = "only these
|
|
963
|
+
* ids", serialized server-side with this user's own permissions),
|
|
964
|
+
* then patch the fresh items into every cached jobs query in place.
|
|
965
|
+
* Route-filtered lists are invalidated instead — membership may have
|
|
966
|
+
* changed and an in-place patch can't insert newly-assigned jobs.
|
|
967
|
+
* Falls back to full jobs invalidation if the fetch fails.
|
|
968
|
+
*/
|
|
969
|
+
async _patchJobsByIds(queryClient, jobIds) {
|
|
970
|
+
if (jobIds.length === 0)
|
|
971
|
+
return;
|
|
972
|
+
try {
|
|
973
|
+
const raw = await this.fetchJobs({
|
|
974
|
+
unknown_ids: jobIds,
|
|
975
|
+
amt: jobIds.length,
|
|
976
|
+
});
|
|
977
|
+
const fresh = new Map(raw.filter((d) => d?.id).map((d) => [d.id, new Job(d)]));
|
|
978
|
+
const matching = queryClient
|
|
979
|
+
.getQueryCache()
|
|
980
|
+
.findAll({ predicate: (q) => matchesEntityKey(q, 'jobs') });
|
|
981
|
+
for (const query of matching) {
|
|
982
|
+
const queryKey = query.queryKey;
|
|
983
|
+
// Detail cache: ['jobs', jobId]
|
|
984
|
+
if (queryKey.length === 2 && queryKey[0] === 'jobs') {
|
|
985
|
+
const detailId = queryKey[1];
|
|
986
|
+
if (typeof detailId === 'string' && fresh.has(detailId)) {
|
|
987
|
+
queryClient.setQueryData(queryKey, fresh.get(detailId));
|
|
988
|
+
}
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
// Route-filtered lists (only mounted route views hold them)
|
|
992
|
+
if (queryKey[0] === 'infinite' &&
|
|
993
|
+
typeof queryKey[5] === 'string' &&
|
|
994
|
+
queryKey[5].length > 0) {
|
|
995
|
+
queryClient.invalidateQueries({ queryKey, exact: true });
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
queryClient.setQueryData(queryKey, (old) => {
|
|
999
|
+
if (!old)
|
|
1000
|
+
return old;
|
|
1001
|
+
const patchList = (list) => {
|
|
1002
|
+
let changed = false;
|
|
1003
|
+
const next = list.map((x) => {
|
|
1004
|
+
const replacement = x?.id ? fresh.get(x.id) : undefined;
|
|
1005
|
+
if (!replacement)
|
|
1006
|
+
return x;
|
|
1007
|
+
changed = true;
|
|
1008
|
+
return replacement;
|
|
1009
|
+
});
|
|
1010
|
+
return changed ? next : list;
|
|
1011
|
+
};
|
|
1012
|
+
if (old.pages && Array.isArray(old.pages)) {
|
|
1013
|
+
return {
|
|
1014
|
+
...old,
|
|
1015
|
+
pages: old.pages.map((p) => Array.isArray(p) ? patchList(p) : p),
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
if (Array.isArray(old))
|
|
1019
|
+
return patchList(old);
|
|
1020
|
+
return old;
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
catch {
|
|
1025
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
1026
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
913
1029
|
async _syncEntity(queryClient, params) {
|
|
914
1030
|
const { action, entityKey, id, fetchPath, construct, matchesQuery } = params;
|
|
915
1031
|
const predicate = (q) => matchesEntityKey(q, entityKey);
|
package/dist/types/api/Task.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const UnroutedReason: {
|
|
|
23
23
|
readonly LOW_PRIORITY: "LOW_PRIORITY";
|
|
24
24
|
readonly DISPLACED_BY_CHEAPER: "DISPLACED_BY_CHEAPER";
|
|
25
25
|
readonly SCHEDULE_FULL: "SCHEDULE_FULL";
|
|
26
|
+
readonly MANDATORY_UNSERVED: "MANDATORY_UNSERVED";
|
|
26
27
|
readonly DID_NOT_FIT: "DID_NOT_FIT";
|
|
27
28
|
};
|
|
28
29
|
export type UnroutedReason = (typeof UnroutedReason)[keyof typeof UnroutedReason];
|
package/dist/types/api/Task.js
CHANGED
|
@@ -18,6 +18,7 @@ export const UnroutedReason = {
|
|
|
18
18
|
LOW_PRIORITY: 'LOW_PRIORITY',
|
|
19
19
|
DISPLACED_BY_CHEAPER: 'DISPLACED_BY_CHEAPER',
|
|
20
20
|
SCHEDULE_FULL: 'SCHEDULE_FULL',
|
|
21
|
+
MANDATORY_UNSERVED: 'MANDATORY_UNSERVED',
|
|
21
22
|
DID_NOT_FIT: 'DID_NOT_FIT',
|
|
22
23
|
};
|
|
23
24
|
export const UNROUTED_REASON_LABELS = {
|
|
@@ -30,6 +31,7 @@ export const UNROUTED_REASON_LABELS = {
|
|
|
30
31
|
LOW_PRIORITY: 'Crowded out by more urgent tasks',
|
|
31
32
|
DISPLACED_BY_CHEAPER: 'Lost its spot to a quicker-to-reach job',
|
|
32
33
|
SCHEDULE_FULL: 'No room left in the schedule',
|
|
34
|
+
MANDATORY_UNSERVED: 'Far past due and forced onto the day, but the day could not hold it',
|
|
33
35
|
DID_NOT_FIT: 'Did not fit any schedule',
|
|
34
36
|
};
|
|
35
37
|
export class Task {
|
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.119";
|
package/dist/version.js
CHANGED