@go-avro/avro-js 0.0.10 → 0.0.11

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.
@@ -91,32 +91,7 @@ AvroQueryClient.prototype.useCreateJob = function () {
91
91
  headers: { "Content-Type": "application/json" }
92
92
  });
93
93
  },
94
- onMutate: async ({ jobData }) => {
95
- await queryClient.cancelQueries({ queryKey: ['jobs'] });
96
- const previousJobs = queryClient.getQueryData(['jobs']);
97
- queryClient.setQueryData(['jobs'], (oldData) => {
98
- if (!oldData)
99
- return [jobData];
100
- if (oldData.pages) {
101
- const firstPage = oldData.pages[0] || [];
102
- return {
103
- ...oldData,
104
- pages: [[jobData, ...firstPage], ...oldData.pages.slice(1)],
105
- };
106
- }
107
- if (Array.isArray(oldData)) {
108
- return [jobData, ...oldData];
109
- }
110
- return oldData;
111
- });
112
- return { previousJobs };
113
- },
114
- onError: (err, variables, context) => {
115
- if (context?.previousJobs) {
116
- queryClient.setQueryData(['jobs'], context.previousJobs);
117
- }
118
- },
119
- onSettled: (data, error, variables) => {
94
+ onSettled: (data) => {
120
95
  const { id: jobId } = data ?? {};
121
96
  queryClient.invalidateQueries({ queryKey: ['jobs'] });
122
97
  queryClient.invalidateQueries({ queryKey: ['job', jobId] });
@@ -134,38 +109,9 @@ AvroQueryClient.prototype.useManageJobs = function () {
134
109
  headers: { "Content-Type": "application/json" }
135
110
  });
136
111
  },
137
- onMutate: async ({ jobs }) => {
138
- await queryClient.cancelQueries({ queryKey: ['jobs'] });
139
- const previousJobs = queryClient.getQueryData(['jobs']);
140
- queryClient.setQueryData(['jobs'], (oldData) => {
141
- if (!oldData)
142
- return oldData;
143
- if (oldData.pages) {
144
- return {
145
- ...oldData,
146
- pages: oldData.pages.map((page) => page.map((job) => {
147
- const updatedJob = jobs.find((j) => j.id === job.id);
148
- return updatedJob ? { ...job, ...updatedJob } : job;
149
- })),
150
- };
151
- }
152
- if (Array.isArray(oldData)) {
153
- return oldData.map((job) => {
154
- const updatedJob = jobs.find((j) => j.id === job.id);
155
- return updatedJob ? { ...job, ...updatedJob } : job;
156
- });
157
- }
158
- return oldData;
159
- });
160
- return { previousJobs };
161
- },
162
- onError: (err, variables, context) => {
163
- if (context?.previousJobs) {
164
- queryClient.setQueryData(['jobs'], context.previousJobs);
165
- }
166
- },
167
112
  onSettled: (_data, _error, _variables) => {
168
113
  queryClient.invalidateQueries({ queryKey: ['jobs'] });
114
+ queryClient.invalidateQueries({ queryKey: ['job'] });
169
115
  },
170
116
  });
171
117
  };
@@ -179,37 +125,6 @@ AvroQueryClient.prototype.useUpdateJob = function () {
179
125
  headers: { "Content-Type": "application/json" }
180
126
  });
181
127
  },
182
- onMutate: async ({ jobId, updates }) => {
183
- await queryClient.cancelQueries({ queryKey: ['jobs'] });
184
- await queryClient.cancelQueries({ queryKey: ['job', jobId] });
185
- const previousJobs = queryClient.getQueryData(['jobs']);
186
- const previousJob = queryClient.getQueryData(['job', jobId]);
187
- queryClient.setQueryData(['job', jobId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
188
- queryClient.setQueriesData({ queryKey: ['jobs'] }, (oldData) => {
189
- if (!oldData)
190
- return oldData;
191
- if (oldData.pages) {
192
- return {
193
- ...oldData,
194
- pages: oldData.pages.map((page) => page.map((job) => job.id === jobId ? { ...job, ...updates } : job)),
195
- };
196
- }
197
- if (Array.isArray(oldData)) {
198
- return oldData.map((job) => job.id === jobId ? { ...job, ...updates } : job);
199
- }
200
- return oldData;
201
- });
202
- return { previousJobs, previousJob };
203
- },
204
- onError: (err, variables, context) => {
205
- const { jobId } = variables;
206
- if (context?.previousJobs) {
207
- queryClient.setQueryData(['jobs'], context.previousJobs);
208
- }
209
- if (context?.previousJob) {
210
- queryClient.setQueryData(['job', jobId], context.previousJob);
211
- }
212
- },
213
128
  onSettled: (data, error, variables) => {
214
129
  const { jobId } = variables;
215
130
  queryClient.invalidateQueries({ queryKey: ['jobs'] });
@@ -227,28 +142,6 @@ AvroQueryClient.prototype.useDeleteJobs = function () {
227
142
  headers: { "Content-Type": "application/json" }
228
143
  });
229
144
  },
230
- onMutate: async ({ ids }) => {
231
- await queryClient.cancelQueries({ queryKey: ['jobs'] });
232
- const previousJobs = queryClient.getQueryData(['jobs']);
233
- queryClient.setQueryData(['jobs'], (oldData) => {
234
- if (!oldData)
235
- return oldData;
236
- if (oldData.pages) {
237
- const updatedPages = oldData.pages.map((page) => page.filter((job) => !ids.includes(job.id)));
238
- return { ...oldData, pages: updatedPages };
239
- }
240
- if (Array.isArray(oldData)) {
241
- return oldData.filter((job) => !ids.includes(job.id));
242
- }
243
- return oldData;
244
- });
245
- return { previousJobs };
246
- },
247
- onError: (_err, variables, context) => {
248
- if (context?.previousJobs) {
249
- queryClient.setQueryData(['jobs'], context.previousJobs);
250
- }
251
- },
252
145
  onSettled: (_data, _error, _variables) => {
253
146
  queryClient.invalidateQueries({ queryKey: ['jobs'] });
254
147
  queryClient.invalidateQueries({ queryKey: ['routes'] });
@@ -268,35 +161,6 @@ AvroQueryClient.prototype.useDeleteJob = function () {
268
161
  }
269
162
  });
270
163
  },
271
- onMutate: async ({ jobId }) => {
272
- await queryClient.cancelQueries({ queryKey: ['jobs'] });
273
- await queryClient.cancelQueries({ queryKey: ['job', jobId] });
274
- const previousJobs = queryClient.getQueryData(['jobs']);
275
- const previousJob = queryClient.getQueryData(['job', jobId]);
276
- queryClient.setQueryData(['job', jobId], undefined);
277
- queryClient.setQueriesData({ queryKey: ['jobs'] }, (oldData) => {
278
- if (!oldData)
279
- return oldData;
280
- if (oldData.pages) {
281
- const updatedPages = oldData.pages.map((page) => page.filter((job) => job.id !== jobId));
282
- return { ...oldData, pages: updatedPages };
283
- }
284
- if (Array.isArray(oldData)) {
285
- return oldData.filter((job) => job.id !== jobId);
286
- }
287
- return oldData;
288
- });
289
- return { previousJobs, previousJob };
290
- },
291
- onError: (_err, variables, context) => {
292
- const { jobId } = variables;
293
- if (context?.previousJobs) {
294
- queryClient.setQueryData(['jobs'], context.previousJobs);
295
- }
296
- if (context?.previousJob) {
297
- queryClient.setQueryData(['job', jobId], context.previousJob);
298
- }
299
- },
300
164
  onSettled: (_data, _error, variables) => {
301
165
  const { jobId } = variables;
302
166
  queryClient.invalidateQueries({ queryKey: ['jobs'] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",