@go-avro/avro-js 0.0.33 → 0.0.35
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.
|
@@ -148,6 +148,7 @@ export class AvroQueryClient {
|
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
150
|
config.authManager.onTokenRefreshFailed(() => {
|
|
151
|
+
this.clearCache();
|
|
151
152
|
this.setAuthState(AuthState.UNAUTHENTICATED);
|
|
152
153
|
if (this.socket && this.socket.connected) {
|
|
153
154
|
this.socket.disconnect();
|
|
@@ -215,6 +216,7 @@ export class AvroQueryClient {
|
|
|
215
216
|
return;
|
|
216
217
|
}
|
|
217
218
|
const entityPredicate = (q) => matchesEntityKey(q, entityKey);
|
|
219
|
+
let fetchedItem;
|
|
218
220
|
switch (action) {
|
|
219
221
|
// ─── CREATE ─────────────────────────────────
|
|
220
222
|
case 'create': {
|
|
@@ -225,6 +227,7 @@ export class AvroQueryClient {
|
|
|
225
227
|
queryFn: () => client.get({ path: fetchPath(id) }),
|
|
226
228
|
staleTime: 0,
|
|
227
229
|
});
|
|
230
|
+
fetchedItem = item;
|
|
228
231
|
queryClient.setQueriesData({ predicate: entityPredicate, type: 'active' }, (old) => {
|
|
229
232
|
if (!old)
|
|
230
233
|
return old;
|
|
@@ -269,6 +272,7 @@ export class AvroQueryClient {
|
|
|
269
272
|
queryFn: () => client.get({ path: fetchPath(id) }),
|
|
270
273
|
staleTime: 0,
|
|
271
274
|
});
|
|
275
|
+
fetchedItem = item;
|
|
272
276
|
// Patch it into every active list / infinite-query cache
|
|
273
277
|
queryClient.setQueriesData({ predicate: entityPredicate, type: 'active' }, (old) => {
|
|
274
278
|
if (!old)
|
|
@@ -322,7 +326,7 @@ export class AvroQueryClient {
|
|
|
322
326
|
// Refetch & patch related entities (e.g. event → parent job)
|
|
323
327
|
if (relatedRefetch) {
|
|
324
328
|
for (const related of relatedRefetch) {
|
|
325
|
-
const relatedId = data?.[related.idField];
|
|
329
|
+
const relatedId = data?.[related.idField] ?? fetchedItem?.[related.idField];
|
|
326
330
|
if (!relatedId || typeof relatedId !== 'string')
|
|
327
331
|
continue;
|
|
328
332
|
try {
|
|
@@ -551,6 +555,8 @@ export class AvroQueryClient {
|
|
|
551
555
|
return this.config.authManager.getCompanyId();
|
|
552
556
|
}
|
|
553
557
|
clearCache() {
|
|
558
|
+
this.companyId = undefined;
|
|
559
|
+
this.company = undefined;
|
|
554
560
|
return this.config.authManager.clearCache();
|
|
555
561
|
}
|
|
556
562
|
onAuthStateChange(cb) {
|
|
@@ -134,15 +134,31 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
134
134
|
onMutate: async ({ eventId, updates }) => {
|
|
135
135
|
await queryClient.cancelQueries({ queryKey: ['events', eventId] });
|
|
136
136
|
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
137
|
-
|
|
137
|
+
// Try individual cache first; fall back to scanning the events list
|
|
138
|
+
let previousEvent = queryClient.getQueryData(['events', eventId]);
|
|
139
|
+
if (!previousEvent) {
|
|
140
|
+
const eventsData = queryClient.getQueryData(['events']);
|
|
141
|
+
const pages = eventsData?.pages ?? (Array.isArray(eventsData) ? [eventsData] : undefined);
|
|
142
|
+
if (pages) {
|
|
143
|
+
for (const page of pages) {
|
|
144
|
+
const found = page.find((e) => e.id === eventId);
|
|
145
|
+
if (found) {
|
|
146
|
+
previousEvent = found;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
138
152
|
const previousEvents = queryClient.getQueryData(['events']);
|
|
139
153
|
const previousJob = queryClient.getQueryData(['jobs', previousEvent?.job_id]);
|
|
140
154
|
const previousJobs = queryClient.getQueryData(['jobs']);
|
|
141
155
|
if (previousJob) {
|
|
156
|
+
const isEnding = (updates.time_ended ?? -1) > -1;
|
|
157
|
+
const mergedEvent = previousEvent ? { ...previousEvent, ...updates } : null;
|
|
142
158
|
const updatedJob = {
|
|
143
159
|
...previousJob,
|
|
144
|
-
current_event:
|
|
145
|
-
last_completed_event:
|
|
160
|
+
current_event: isEnding ? null : (mergedEvent ?? previousJob.current_event),
|
|
161
|
+
last_completed_event: isEnding && mergedEvent ? mergedEvent : previousJob.last_completed_event,
|
|
146
162
|
};
|
|
147
163
|
updatedJob.tasks = previousJob.tasks.map((task) => {
|
|
148
164
|
if (updates.tasks?.includes(task.id ?? "")) {
|