@go-avro/avro-js 0.0.118 → 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 +94 -73
- 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: {
|
|
@@ -605,80 +606,14 @@ export class AvroQueryClient {
|
|
|
605
606
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
606
607
|
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
607
608
|
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
608
|
-
const invalidateJobs = () => {
|
|
609
|
-
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
610
|
-
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
611
|
-
};
|
|
612
609
|
const rawIds = data?.job_ids;
|
|
613
610
|
if (!Array.isArray(rawIds)) {
|
|
614
611
|
// Legacy backend / unknown affected set
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
const jobIds = rawIds.filter((x) => typeof x === 'string');
|
|
619
|
-
if (jobIds.length === 0)
|
|
612
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
613
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
620
614
|
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
615
|
}
|
|
616
|
+
await client._patchJobsByIds(queryClient, rawIds.filter((x) => typeof x === 'string'));
|
|
682
617
|
};
|
|
683
618
|
this.socket.on(event, handler);
|
|
684
619
|
handlers.push({ event, handler });
|
|
@@ -699,9 +634,25 @@ export class AvroQueryClient {
|
|
|
699
634
|
const { entityKey, action, fetchPath, idField, alsoInvalidate, relatedRefetch } = config;
|
|
700
635
|
const handler = async (data) => {
|
|
701
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
|
+
};
|
|
702
652
|
if (!id || typeof id !== 'string') {
|
|
703
653
|
invalidateEntity(entityKey);
|
|
704
654
|
alsoInvalidate?.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
|
|
655
|
+
await syncAffectedJobs();
|
|
705
656
|
return;
|
|
706
657
|
}
|
|
707
658
|
let fetchedItem;
|
|
@@ -716,6 +667,7 @@ export class AvroQueryClient {
|
|
|
716
667
|
});
|
|
717
668
|
// Invalidate any additional keys (e.g. companies → /company/list)
|
|
718
669
|
alsoInvalidate?.forEach((k) => queryClient.invalidateQueries({ queryKey: k }));
|
|
670
|
+
await syncAffectedJobs();
|
|
719
671
|
if (relatedRefetch) {
|
|
720
672
|
for (const related of relatedRefetch) {
|
|
721
673
|
const relatedId = data?.[related.idField] ?? fetchedItem?.[related.idField];
|
|
@@ -1005,6 +957,75 @@ export class AvroQueryClient {
|
|
|
1005
957
|
peekQueryClient() {
|
|
1006
958
|
return this._queryClient;
|
|
1007
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
|
+
}
|
|
1008
1029
|
async _syncEntity(queryClient, params) {
|
|
1009
1030
|
const { action, entityKey, id, fetchPath, construct, matchesQuery } = params;
|
|
1010
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