@go-avro/avro-js 0.1.14 → 1.6.0
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/auth/AuthManager.d.ts +28 -0
- package/dist/auth/AuthManager.js +119 -43
- package/dist/client/QueryClient.d.ts +56 -1
- package/dist/client/QueryClient.js +264 -80
- package/dist/client/cache.d.ts +24 -0
- package/dist/client/cache.js +51 -0
- package/dist/client/core/fetch.js +58 -49
- package/dist/client/core/policy.d.ts +17 -0
- package/dist/client/core/policy.js +35 -0
- package/dist/client/core/xhr.js +16 -14
- package/dist/client/hooks/bills.js +10 -14
- package/dist/client/hooks/catalog_items.js +18 -8
- package/dist/client/hooks/chats.js +2 -8
- package/dist/client/hooks/companies.js +11 -5
- package/dist/client/hooks/events.js +46 -35
- package/dist/client/hooks/groups.js +11 -26
- package/dist/client/hooks/jobs.js +3 -8
- package/dist/client/hooks/labels.js +11 -26
- package/dist/client/hooks/messages.js +3 -8
- package/dist/client/hooks/months.js +28 -22
- package/dist/client/hooks/payouts.js +3 -8
- package/dist/client/hooks/prepayments.js +28 -22
- package/dist/client/hooks/proposal.js +1 -0
- package/dist/client/hooks/routes.js +8 -6
- package/dist/client/hooks/sessions.js +11 -27
- package/dist/client/hooks/skills.js +6 -4
- package/dist/client/hooks/teams.js +6 -4
- package/dist/client/hooks/timecards.js +7 -7
- package/dist/client/hooks/waivers.js +6 -4
- package/dist/client/persist.js +21 -2
- package/dist/client/realtime.d.ts +12 -0
- package/dist/client/realtime.js +160 -46
- package/dist/types/api/Company.d.ts +2 -0
- package/dist/types/api/DelayEvent.d.ts +1 -1
- package/dist/types/api/LineItem.d.ts +4 -0
- package/dist/types/api/LineItem.js +8 -1
- package/dist/types/api/Task.d.ts +20 -0
- package/dist/types/api/Task.js +11 -1
- package/dist/types/api.d.ts +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
|
+
import { restoreNs, snapshotNs } from '../cache.js';
|
|
3
4
|
import { keys } from '../realtime.js';
|
|
4
5
|
import { Route } from '../../types/api.js';
|
|
5
6
|
const dedupeJobTasks = (payload) => payload.jobs
|
|
@@ -42,6 +43,7 @@ AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
|
42
43
|
const routes = pages.flat().map((route) => new Route(route));
|
|
43
44
|
return routes;
|
|
44
45
|
},
|
|
46
|
+
enabled: Boolean(this.companyId),
|
|
45
47
|
});
|
|
46
48
|
};
|
|
47
49
|
AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
@@ -67,7 +69,7 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
67
69
|
},
|
|
68
70
|
onMutate: async ({ routeData: { optimize: _optimize, ...routeData } }) => {
|
|
69
71
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
70
|
-
const previousRoutes = queryClient
|
|
72
|
+
const previousRoutes = snapshotNs(queryClient, 'routes');
|
|
71
73
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
72
74
|
if (!oldData)
|
|
73
75
|
return oldData;
|
|
@@ -97,7 +99,7 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
97
99
|
},
|
|
98
100
|
onError: (_err, _variables, context) => {
|
|
99
101
|
if (context?.previousRoutes) {
|
|
100
|
-
queryClient
|
|
102
|
+
restoreNs(queryClient, context.previousRoutes);
|
|
101
103
|
}
|
|
102
104
|
},
|
|
103
105
|
onSettled: () => {
|
|
@@ -152,7 +154,7 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
152
154
|
await queryClient.cancelQueries({ queryKey: ['routes', routeId] });
|
|
153
155
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
154
156
|
const previousRoute = queryClient.getQueryData(['routes', routeId]);
|
|
155
|
-
const previousRoutes = queryClient
|
|
157
|
+
const previousRoutes = snapshotNs(queryClient, 'routes');
|
|
156
158
|
queryClient.setQueryData(['routes', routeId], (oldData) => oldData ? new Route({ ...oldData, ...updates }) : undefined);
|
|
157
159
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
158
160
|
if (!oldData)
|
|
@@ -179,7 +181,7 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
179
181
|
queryClient.setQueryData(['routes', routeId], context.previousRoute);
|
|
180
182
|
}
|
|
181
183
|
if (context?.previousRoutes) {
|
|
182
|
-
queryClient
|
|
184
|
+
restoreNs(queryClient, context.previousRoutes);
|
|
183
185
|
}
|
|
184
186
|
},
|
|
185
187
|
});
|
|
@@ -193,7 +195,7 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
193
195
|
onMutate: async ({ routeId }) => {
|
|
194
196
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
195
197
|
await queryClient.cancelQueries({ queryKey: ['routes', routeId] });
|
|
196
|
-
const previousRoutes = queryClient
|
|
198
|
+
const previousRoutes = snapshotNs(queryClient, 'routes');
|
|
197
199
|
const previousRoute = queryClient.getQueryData(['routes', routeId]);
|
|
198
200
|
queryClient.setQueryData(['routes', routeId], undefined);
|
|
199
201
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
@@ -216,7 +218,7 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
216
218
|
onError: (_err, variables, context) => {
|
|
217
219
|
const { routeId } = variables;
|
|
218
220
|
if (context?.previousRoutes) {
|
|
219
|
-
queryClient
|
|
221
|
+
restoreNs(queryClient, context.previousRoutes);
|
|
220
222
|
}
|
|
221
223
|
if (context?.previousRoute) {
|
|
222
224
|
queryClient.setQueryData(['routes', routeId], context.previousRoute);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
3
|
import { keys, isListKey } from '../realtime.js';
|
|
4
|
+
import { removeOptimisticRow, seedDetails } from '../cache.js';
|
|
4
5
|
import { Session } from '../../types/api.js';
|
|
5
6
|
const NS = 'sessions';
|
|
6
7
|
function listFilters(body) {
|
|
@@ -46,16 +47,9 @@ AvroQueryClient.prototype.useGetSessions = function (body = {}) {
|
|
|
46
47
|
return undefined;
|
|
47
48
|
return allPages.flat().length;
|
|
48
49
|
},
|
|
49
|
-
queryFn: ({ pageParam = 0 }) => this.fetchSessions({ ...body, amt, offset: pageParam }).then((sessions) => sessions.map((s) => new Session(s))),
|
|
50
|
+
queryFn: ({ pageParam = 0 }) => this.fetchSessions({ ...body, amt, offset: pageParam }).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
50
51
|
enabled: Boolean(this.companyId),
|
|
51
52
|
});
|
|
52
|
-
if (result.data) {
|
|
53
|
-
result.data.pages.forEach((page) => {
|
|
54
|
-
page.forEach((session) => {
|
|
55
|
-
queryClient.setQueryData(keys.detail(NS, session.id), session);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
53
|
return result;
|
|
60
54
|
};
|
|
61
55
|
/** The caller's own open sessions (any company). */
|
|
@@ -63,14 +57,9 @@ AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
|
63
57
|
const queryClient = this.getQueryClient();
|
|
64
58
|
const result = useQuery({
|
|
65
59
|
queryKey: keys.list(NS, 'mine', { active: true }),
|
|
66
|
-
queryFn: () => this.get({ path: '/session' }).then((sessions) => (Array.isArray(sessions) ? sessions : []).map((s) => new Session(s))),
|
|
60
|
+
queryFn: () => this.get({ path: '/session' }).then((sessions) => seedDetails(queryClient, NS, (Array.isArray(sessions) ? sessions : []).map((s) => new Session(s)))),
|
|
67
61
|
enabled: Boolean(this.companyId),
|
|
68
62
|
});
|
|
69
|
-
if (result.data) {
|
|
70
|
-
result.data.forEach((session) => {
|
|
71
|
-
queryClient.setQueryData(keys.detail(NS, session.id), session);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
63
|
return result;
|
|
75
64
|
};
|
|
76
65
|
/** Exactly the given sessions, in one request. */
|
|
@@ -80,14 +69,9 @@ AvroQueryClient.prototype.useGetCompanySessionsByIds = function (sessionIds, par
|
|
|
80
69
|
const sortedIds = [...sessionIds].sort();
|
|
81
70
|
const result = useQuery({
|
|
82
71
|
queryKey: keys.list(NS, companyId, listFilters({ unknown_ids: sortedIds })),
|
|
83
|
-
queryFn: () => this.fetchSessions({ unknown_ids: sortedIds, amt: sortedIds.length }).then((sessions) => sessions.map((s) => new Session(s))),
|
|
72
|
+
queryFn: () => this.fetchSessions({ unknown_ids: sortedIds, amt: sortedIds.length }).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
84
73
|
enabled: Boolean(companyId) && sortedIds.length > 0 && (params.enabled ?? true),
|
|
85
74
|
});
|
|
86
|
-
if (result.data) {
|
|
87
|
-
result.data.forEach((session) => {
|
|
88
|
-
queryClient.setQueryData(keys.detail(NS, session.id), session);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
75
|
return result;
|
|
92
76
|
};
|
|
93
77
|
/** Currently-open sessions across the company, in one request. */
|
|
@@ -96,14 +80,9 @@ AvroQueryClient.prototype.useGetActiveCompanySessions = function (params = {}) {
|
|
|
96
80
|
const companyId = params.companyId ?? this.companyId;
|
|
97
81
|
const result = useQuery({
|
|
98
82
|
queryKey: keys.list(NS, companyId, listFilters({ active: true })),
|
|
99
|
-
queryFn: () => this.fetchSessions({ active: true, amt: 500 }).then((sessions) => sessions.map((s) => new Session(s))),
|
|
83
|
+
queryFn: () => this.fetchSessions({ active: true, amt: 500 }).then((sessions) => seedDetails(queryClient, NS, sessions.map((s) => new Session(s)))),
|
|
100
84
|
enabled: Boolean(companyId) && (params.enabled ?? true),
|
|
101
85
|
});
|
|
102
|
-
if (result.data) {
|
|
103
|
-
result.data.forEach((session) => {
|
|
104
|
-
queryClient.setQueryData(keys.detail(NS, session.id), session);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
86
|
return result;
|
|
108
87
|
};
|
|
109
88
|
// ─── Mutations ──────────────────────────────────────────────────────
|
|
@@ -129,7 +108,12 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
129
108
|
company_id: this.companyId,
|
|
130
109
|
});
|
|
131
110
|
patchSessionLists(queryClient, (items) => [optimistic, ...items]);
|
|
132
|
-
return { previous };
|
|
111
|
+
return { previous, tempId: optimistic.id };
|
|
112
|
+
},
|
|
113
|
+
onSuccess: (_data, _vars, context) => {
|
|
114
|
+
// The echoed change (or the fallback refetch) brings the real row.
|
|
115
|
+
if (context?.tempId)
|
|
116
|
+
removeOptimisticRow(queryClient, NS, context.tempId);
|
|
133
117
|
},
|
|
134
118
|
onError: (_err, _vars, context) => {
|
|
135
119
|
if (context?.previous)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
|
+
import { restoreNs, snapshotNs } from '../cache.js';
|
|
3
4
|
import { keys } from '../realtime.js';
|
|
4
5
|
AvroQueryClient.prototype.useCreateSkill = function () {
|
|
5
6
|
const queryClient = this.getQueryClient();
|
|
@@ -44,6 +45,7 @@ AvroQueryClient.prototype.useGetSkills = function (body, total, onProgress) {
|
|
|
44
45
|
const skills = pages.flat();
|
|
45
46
|
return skills;
|
|
46
47
|
},
|
|
48
|
+
enabled: Boolean(this.companyId),
|
|
47
49
|
});
|
|
48
50
|
};
|
|
49
51
|
AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
@@ -59,7 +61,7 @@ AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
|
59
61
|
onMutate: async ({ skillId, updates }) => {
|
|
60
62
|
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
61
63
|
await queryClient.cancelQueries({ queryKey: ['skills', skillId] });
|
|
62
|
-
const previousSkills = queryClient
|
|
64
|
+
const previousSkills = snapshotNs(queryClient, 'skills');
|
|
63
65
|
const previousSkill = queryClient.getQueryData(['skills', skillId]);
|
|
64
66
|
queryClient.setQueryData(['skills', skillId], (oldData) => {
|
|
65
67
|
if (!oldData)
|
|
@@ -86,7 +88,7 @@ AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
|
86
88
|
onError: (_err, variables, context) => {
|
|
87
89
|
const { skillId } = variables;
|
|
88
90
|
if (context?.previousSkills) {
|
|
89
|
-
queryClient
|
|
91
|
+
restoreNs(queryClient, context.previousSkills);
|
|
90
92
|
}
|
|
91
93
|
if (context?.previousSkill) {
|
|
92
94
|
queryClient.setQueryData(['skills', skillId], context.previousSkill);
|
|
@@ -102,7 +104,7 @@ AvroQueryClient.prototype.useDeleteSkill = function () {
|
|
|
102
104
|
},
|
|
103
105
|
onMutate: async ({ skillId }) => {
|
|
104
106
|
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
105
|
-
const previousSkills = queryClient
|
|
107
|
+
const previousSkills = snapshotNs(queryClient, 'skills');
|
|
106
108
|
queryClient.setQueriesData({ queryKey: ['skills'] }, (oldData) => {
|
|
107
109
|
if (!oldData)
|
|
108
110
|
return oldData;
|
|
@@ -122,7 +124,7 @@ AvroQueryClient.prototype.useDeleteSkill = function () {
|
|
|
122
124
|
},
|
|
123
125
|
onError: (_err, variables, context) => {
|
|
124
126
|
if (context?.previousSkills) {
|
|
125
|
-
queryClient
|
|
127
|
+
restoreNs(queryClient, context.previousSkills);
|
|
126
128
|
}
|
|
127
129
|
},
|
|
128
130
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
|
+
import { restoreNs, snapshotNs } from '../cache.js';
|
|
3
4
|
import { keys } from '../realtime.js';
|
|
4
5
|
AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
|
|
5
6
|
return useQuery({
|
|
@@ -29,6 +30,7 @@ AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
|
|
|
29
30
|
const teams = pages.flat();
|
|
30
31
|
return teams;
|
|
31
32
|
},
|
|
33
|
+
enabled: Boolean(this.companyId),
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
36
|
AvroQueryClient.prototype.useCreateTeam = function () {
|
|
@@ -59,7 +61,7 @@ AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
|
59
61
|
onMutate: async ({ teamId, teamData }) => {
|
|
60
62
|
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
61
63
|
await queryClient.cancelQueries({ queryKey: ['teams', teamId] });
|
|
62
|
-
const previousTeams = queryClient
|
|
64
|
+
const previousTeams = snapshotNs(queryClient, 'teams');
|
|
63
65
|
const previousTeam = queryClient.getQueryData(['teams', teamId]);
|
|
64
66
|
queryClient.setQueryData(['teams', teamId], (oldData) => {
|
|
65
67
|
if (!oldData)
|
|
@@ -86,7 +88,7 @@ AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
|
86
88
|
onError: (_err, variables, context) => {
|
|
87
89
|
const { teamId } = variables;
|
|
88
90
|
if (context?.previousTeams) {
|
|
89
|
-
queryClient
|
|
91
|
+
restoreNs(queryClient, context.previousTeams);
|
|
90
92
|
}
|
|
91
93
|
if (context?.previousTeam) {
|
|
92
94
|
queryClient.setQueryData(['teams', teamId], context.previousTeam);
|
|
@@ -103,7 +105,7 @@ AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
|
103
105
|
onMutate: async ({ teamId }) => {
|
|
104
106
|
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
105
107
|
await queryClient.cancelQueries({ queryKey: ['teams', teamId] });
|
|
106
|
-
const previousRoutes = queryClient
|
|
108
|
+
const previousRoutes = snapshotNs(queryClient, 'teams');
|
|
107
109
|
const previousRoute = queryClient.getQueryData(['teams', teamId]);
|
|
108
110
|
queryClient.setQueryData(['teams', teamId], undefined);
|
|
109
111
|
queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
|
|
@@ -126,7 +128,7 @@ AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
|
126
128
|
onError: (_err, variables, context) => {
|
|
127
129
|
const { teamId } = variables;
|
|
128
130
|
if (context?.previousRoutes) {
|
|
129
|
-
queryClient
|
|
131
|
+
restoreNs(queryClient, context.previousRoutes);
|
|
130
132
|
}
|
|
131
133
|
if (context?.previousRoute) {
|
|
132
134
|
queryClient.setQueryData(['teams', teamId], context.previousRoute);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
|
+
import { keys } from '../realtime.js';
|
|
3
4
|
AvroQueryClient.prototype.useGetCompanyTimecards = function (params = {}) {
|
|
4
5
|
const companyId = params.companyId ?? this.companyId;
|
|
5
6
|
return useQuery({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
params.
|
|
10
|
-
params.
|
|
11
|
-
|
|
12
|
-
],
|
|
7
|
+
// keys.list so realtime `timecard` changes patch it (matchTimecards).
|
|
8
|
+
queryKey: keys.list('timecards', companyId, {
|
|
9
|
+
periodStart: params.periodStart ?? null,
|
|
10
|
+
userCompanyId: params.userCompanyId ?? null,
|
|
11
|
+
status: params.status ?? null,
|
|
12
|
+
}),
|
|
13
13
|
queryFn: async () => {
|
|
14
14
|
const search = new URLSearchParams();
|
|
15
15
|
if (typeof params.periodStart === 'number') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../QueryClient.js';
|
|
3
|
+
import { restoreNs, snapshotNs } from '../cache.js';
|
|
3
4
|
import { keys } from '../realtime.js';
|
|
4
5
|
AvroQueryClient.prototype.useCreateWaiver = function () {
|
|
5
6
|
const queryClient = this.getQueryClient();
|
|
@@ -47,6 +48,7 @@ AvroQueryClient.prototype.useGetWaivers = function (body, total, onProgress) {
|
|
|
47
48
|
const waivers = pages.flat();
|
|
48
49
|
return waivers;
|
|
49
50
|
},
|
|
51
|
+
enabled: Boolean(this.companyId),
|
|
50
52
|
});
|
|
51
53
|
};
|
|
52
54
|
AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
@@ -64,7 +66,7 @@ AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
|
64
66
|
await queryClient.cancelQueries({
|
|
65
67
|
queryKey: ['waivers', waiverId],
|
|
66
68
|
});
|
|
67
|
-
const previousWaivers = queryClient
|
|
69
|
+
const previousWaivers = snapshotNs(queryClient, 'waivers');
|
|
68
70
|
const previousWaiver = queryClient.getQueryData(['waivers', waiverId]);
|
|
69
71
|
queryClient.setQueryData(['waivers', waiverId], (oldData) => {
|
|
70
72
|
if (!oldData)
|
|
@@ -91,7 +93,7 @@ AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
|
91
93
|
onError: (_err, variables, context) => {
|
|
92
94
|
const { waiverId } = variables;
|
|
93
95
|
if (context?.previousWaivers) {
|
|
94
|
-
queryClient
|
|
96
|
+
restoreNs(queryClient, context.previousWaivers);
|
|
95
97
|
}
|
|
96
98
|
if (context?.previousWaiver) {
|
|
97
99
|
queryClient.setQueryData(['waivers', waiverId], context.previousWaiver);
|
|
@@ -109,7 +111,7 @@ AvroQueryClient.prototype.useDeleteWaiver = function () {
|
|
|
109
111
|
},
|
|
110
112
|
onMutate: async ({ waiverId }) => {
|
|
111
113
|
await queryClient.cancelQueries({ queryKey: ['waivers'] });
|
|
112
|
-
const previousWaivers = queryClient
|
|
114
|
+
const previousWaivers = snapshotNs(queryClient, 'waivers');
|
|
113
115
|
queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
|
|
114
116
|
if (!oldData)
|
|
115
117
|
return oldData;
|
|
@@ -129,7 +131,7 @@ AvroQueryClient.prototype.useDeleteWaiver = function () {
|
|
|
129
131
|
},
|
|
130
132
|
onError: (_err, variables, context) => {
|
|
131
133
|
if (context?.previousWaivers) {
|
|
132
|
-
queryClient
|
|
134
|
+
restoreNs(queryClient, context.previousWaivers);
|
|
133
135
|
}
|
|
134
136
|
},
|
|
135
137
|
});
|
package/dist/client/persist.js
CHANGED
|
@@ -71,9 +71,28 @@ export const PERSISTED_NAMESPACES = [
|
|
|
71
71
|
'health',
|
|
72
72
|
];
|
|
73
73
|
/** JSON loses class instances; restore the ones hooks hand out. */
|
|
74
|
+
/** Revive list (`T[]`), paged (`{pages}`) and detail (`{id,…}`) data alike. */
|
|
75
|
+
function reviver(construct) {
|
|
76
|
+
return (data) => {
|
|
77
|
+
if (Array.isArray(data))
|
|
78
|
+
return data.map((raw) => construct(raw));
|
|
79
|
+
if (data && typeof data === 'object') {
|
|
80
|
+
const pages = data.pages;
|
|
81
|
+
if (Array.isArray(pages)) {
|
|
82
|
+
return {
|
|
83
|
+
...data,
|
|
84
|
+
pages: pages.map((p) => Array.isArray(p) ? p.map((raw) => construct(raw)) : p),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (typeof data.id === 'string')
|
|
88
|
+
return construct(data);
|
|
89
|
+
}
|
|
90
|
+
return data;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
74
93
|
const REVIVERS = {
|
|
75
|
-
jobs: (
|
|
76
|
-
routes: (
|
|
94
|
+
jobs: reviver(constructJob),
|
|
95
|
+
routes: reviver((raw) => new Route(raw)),
|
|
77
96
|
};
|
|
78
97
|
export class QueryPersister {
|
|
79
98
|
constructor(qc, opts) {
|
|
@@ -51,7 +51,19 @@ export declare class ChangeApplier {
|
|
|
51
51
|
private qc;
|
|
52
52
|
private pending;
|
|
53
53
|
private timer;
|
|
54
|
+
/**
|
|
55
|
+
* Latest change sequence per `type:id`. Every change (enqueue, inline
|
|
56
|
+
* data, delete) takes a fresh number; a fetch only applies results for
|
|
57
|
+
* ids whose number is unchanged since it started, so an in-flight
|
|
58
|
+
* fetch can't resurrect a deleted entity or overwrite a newer one.
|
|
59
|
+
*/
|
|
60
|
+
private seq;
|
|
61
|
+
private latest;
|
|
62
|
+
private inflight;
|
|
54
63
|
constructor(client: AvroQueryClient, qc: QueryClient);
|
|
64
|
+
private mark;
|
|
65
|
+
/** Settle a change applied inline: only an in-flight fetch needs the mark. */
|
|
66
|
+
private markApplied;
|
|
55
67
|
apply(payload: ChangesPayload): void;
|
|
56
68
|
private enqueue;
|
|
57
69
|
flush(): Promise<void>;
|