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

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,29 @@ 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: previousEvent ? { ...previousEvent, ...updates } : previousJob.last_event,
146
+ last_completed_event: (updates.time_ended ?? -1) > -1 && previousEvent ? { ...previousEvent, ...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: previousEvent ? { ...previousEvent, ...updates } : task.last_event,
153
+ last_completed_event: (updates.time_ended ?? -1) > -1 ? (previousEvent ? { ...previousEvent, ...updates } : task.last_completed_event) : task.last_completed_event,
154
+ overdue_time: -task.frequency - task.delay,
155
+ };
156
+ }
157
+ return task;
158
+ });
159
+ const updatedJobs = previousJobs?.map((job) => job.id === updatedJob.id ? updatedJob : job);
160
+ queryClient.setQueryData(['job', previousJob.id], updatedJob);
161
+ queryClient.setQueryData(['jobs'], updatedJobs);
162
+ }
110
163
  queryClient.setQueryData(['event', eventId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
111
164
  queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
112
165
  if (!oldData)
@@ -120,7 +173,7 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
120
173
  }
121
174
  return oldData;
122
175
  });
123
- return { previousEvent, previousEvents };
176
+ return { previousEvent, previousEvents, previousJob, previousJobs };
124
177
  },
125
178
  onError: (_err, variables, context) => {
126
179
  const { eventId } = variables;
@@ -130,11 +183,19 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
130
183
  if (context?.previousEvents) {
131
184
  queryClient.setQueryData(['events'], context.previousEvents);
132
185
  }
186
+ if (context?.previousJob) {
187
+ queryClient.setQueryData(['job', context.previousJob.id], context.previousJob);
188
+ }
189
+ if (context?.previousJobs) {
190
+ queryClient.setQueryData(['jobs'], context.previousJobs);
191
+ }
133
192
  },
134
193
  onSettled: (_data, _error, variables) => {
135
194
  const { eventId } = variables;
136
195
  queryClient.invalidateQueries({ queryKey: ['event', eventId] });
137
196
  queryClient.invalidateQueries({ queryKey: ['events'] });
197
+ queryClient.invalidateQueries({ queryKey: ['job'] });
198
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
138
199
  },
139
200
  });
140
201
  };
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.52",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",