@go-avro/avro-js 0.0.2-beta.50 → 0.0.2-beta.51

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.
@@ -50,6 +50,28 @@ AvroQueryClient.prototype.useCreateEvent = function () {
50
50
  onMutate: async ({ companyId, eventData }) => {
51
51
  await queryClient.cancelQueries({ queryKey: ['events'] });
52
52
  const previousEvents = queryClient.getQueryData(['events']);
53
+ const previousJob = queryClient.getQueryData(['job', eventData.job_id]);
54
+ const previousJobs = queryClient.getQueryData(['jobs']);
55
+ if (previousJob) {
56
+ const updatedJob = {
57
+ ...previousJob,
58
+ last_event: eventData,
59
+ last_completed_event: (eventData.time_ended ?? -1) > -1 ? eventData : previousJob.last_completed_event,
60
+ };
61
+ updatedJob.tasks = previousJob.tasks.map((task) => {
62
+ if (eventData.tasks?.includes(task.id)) {
63
+ return {
64
+ ...task,
65
+ last_event: eventData,
66
+ last_completed_event: (eventData.time_ended ?? -1) > -1 ? eventData : task.last_completed_event,
67
+ };
68
+ }
69
+ return task;
70
+ });
71
+ const updatedJobs = previousJobs?.map((job) => job.id === updatedJob.id ? updatedJob : job);
72
+ queryClient.setQueryData(['job', previousJob.id], updatedJob);
73
+ queryClient.setQueryData(['jobs'], updatedJobs);
74
+ }
53
75
  queryClient.setQueryData(['events'], (oldData) => {
54
76
  if (!oldData)
55
77
  return [];
@@ -82,15 +104,23 @@ AvroQueryClient.prototype.useCreateEvent = function () {
82
104
  }
83
105
  return oldData;
84
106
  });
85
- return { previousEvents };
107
+ return { previousEvents, previousJob, previousJobs };
86
108
  },
87
109
  onError: (err, variables, context) => {
88
110
  if (context?.previousEvents) {
89
111
  queryClient.setQueryData(['events'], context.previousEvents);
90
112
  }
113
+ if (context?.previousJob) {
114
+ queryClient.setQueryData(['job', context.previousJob.id], context.previousJob);
115
+ }
116
+ if (context?.previousJobs) {
117
+ queryClient.setQueryData(['jobs'], context.previousJobs);
118
+ }
91
119
  },
92
120
  onSettled: () => {
93
121
  queryClient.invalidateQueries({ queryKey: ['events'] });
122
+ queryClient.invalidateQueries({ queryKey: ['job'] });
123
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
94
124
  },
95
125
  });
96
126
  };
@@ -107,6 +137,28 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
107
137
  await queryClient.cancelQueries({ queryKey: ['events'] });
108
138
  const previousEvent = queryClient.getQueryData(['event', eventId]);
109
139
  const previousEvents = queryClient.getQueryData(['events']);
140
+ const previousJob = queryClient.getQueryData(['job', previousEvent?.job_id]);
141
+ const previousJobs = queryClient.getQueryData(['jobs']);
142
+ if (previousJob) {
143
+ const updatedJob = {
144
+ ...previousJob,
145
+ last_event: updates.id === previousJob.last_event?.id ? { ...previousJob.last_event, ...updates } : previousJob.last_event,
146
+ last_completed_event: (updates.time_ended ?? -1) > -1 ? updates : previousJob.last_completed_event,
147
+ };
148
+ updatedJob.tasks = previousJob.tasks.map((task) => {
149
+ if (updates.tasks?.includes(task.id)) {
150
+ return {
151
+ ...task,
152
+ last_event: task.last_event && updates.id === task.last_event.id ? { ...task.last_event, ...updates } : task.last_event,
153
+ last_completed_event: task.last_completed_event && (updates.time_ended ?? -1) > -1 && updates.id === task.last_completed_event?.id ? { ...task.last_completed_event, ...updates } : task.last_completed_event,
154
+ };
155
+ }
156
+ return task;
157
+ });
158
+ const updatedJobs = previousJobs?.map((job) => job.id === updatedJob.id ? updatedJob : job);
159
+ queryClient.setQueryData(['job', previousJob.id], updatedJob);
160
+ queryClient.setQueryData(['jobs'], updatedJobs);
161
+ }
110
162
  queryClient.setQueryData(['event', eventId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
111
163
  queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
112
164
  if (!oldData)
@@ -120,7 +172,7 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
120
172
  }
121
173
  return oldData;
122
174
  });
123
- return { previousEvent, previousEvents };
175
+ return { previousEvent, previousEvents, previousJob, previousJobs };
124
176
  },
125
177
  onError: (_err, variables, context) => {
126
178
  const { eventId } = variables;
@@ -130,11 +182,19 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
130
182
  if (context?.previousEvents) {
131
183
  queryClient.setQueryData(['events'], context.previousEvents);
132
184
  }
185
+ if (context?.previousJob) {
186
+ queryClient.setQueryData(['job', context.previousJob.id], context.previousJob);
187
+ }
188
+ if (context?.previousJobs) {
189
+ queryClient.setQueryData(['jobs'], context.previousJobs);
190
+ }
133
191
  },
134
192
  onSettled: (_data, _error, variables) => {
135
193
  const { eventId } = variables;
136
194
  queryClient.invalidateQueries({ queryKey: ['event', eventId] });
137
195
  queryClient.invalidateQueries({ queryKey: ['events'] });
196
+ queryClient.invalidateQueries({ queryKey: ['job'] });
197
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
138
198
  },
139
199
  });
140
200
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.50",
3
+ "version": "0.0.2-beta.51",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",