@go-avro/avro-js 0.0.2-beta.97 → 0.0.2-beta.99

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.
@@ -133,6 +133,12 @@ declare module '../client/QueryClient' {
133
133
  companyId: string;
134
134
  jobData: Partial<Job>;
135
135
  }>>;
136
+ useCreateRoute(): ReturnType<typeof useMutation<{
137
+ id: string;
138
+ }, StandardError, {
139
+ companyId: string;
140
+ routeData: Partial<Route>;
141
+ }>>;
136
142
  useCreateSelf(): ReturnType<typeof useMutation<{
137
143
  msg: string;
138
144
  }, StandardError, {
@@ -179,7 +179,9 @@ AvroQueryClient.prototype.useDeleteJob = function () {
179
179
  onSettled: (_data, _error, variables) => {
180
180
  const { jobId } = variables;
181
181
  queryClient.invalidateQueries({ queryKey: ['jobs'] });
182
+ queryClient.invalidateQueries({ queryKey: ['routes'] });
182
183
  queryClient.invalidateQueries({ queryKey: ['job', jobId] });
184
+ queryClient.invalidateQueries({ queryKey: ['route'] });
183
185
  },
184
186
  });
185
187
  };
@@ -35,6 +35,48 @@ AvroQueryClient.prototype.useGetRoute = function (routeId) {
35
35
  enabled: Boolean(routeId) && routeId.length > 0,
36
36
  });
37
37
  };
38
+ AvroQueryClient.prototype.useCreateRoute = function () {
39
+ const queryClient = useQueryClient();
40
+ return useMutation({
41
+ mutationFn: async ({ companyId, routeData }) => {
42
+ return this.post(`/company/${companyId}/route`, JSON.stringify(routeData), undefined, { "Content-Type": "application/json" });
43
+ },
44
+ onMutate: async ({ companyId, routeData }) => {
45
+ await queryClient.cancelQueries({ queryKey: ['routes'] });
46
+ const previousRoutes = queryClient.getQueryData(['routes']);
47
+ queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
48
+ if (!oldData)
49
+ return oldData;
50
+ if (oldData.pages) {
51
+ return {
52
+ ...oldData,
53
+ pages: [
54
+ [{ ...routeData, id: 'temp-id' }],
55
+ ...oldData.pages,
56
+ ],
57
+ };
58
+ }
59
+ if (Array.isArray(oldData)) {
60
+ return [{ ...routeData, id: 'temp-id' }, ...oldData];
61
+ }
62
+ return oldData;
63
+ });
64
+ return { previousRoutes };
65
+ },
66
+ onError: (_err, _variables, context) => {
67
+ if (context?.previousRoutes) {
68
+ queryClient.setQueryData(['routes'], context.previousRoutes);
69
+ }
70
+ },
71
+ onSettled: (_data, _error, variables) => {
72
+ const { companyId } = variables;
73
+ queryClient.invalidateQueries({ queryKey: ['routes'] });
74
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
75
+ queryClient.invalidateQueries({ queryKey: ['job'] });
76
+ queryClient.invalidateQueries({ queryKey: ['company', companyId] });
77
+ },
78
+ });
79
+ };
38
80
  AvroQueryClient.prototype.useUpdateRoute = function () {
39
81
  const queryClient = useQueryClient();
40
82
  return useMutation({
@@ -74,8 +116,10 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
74
116
  },
75
117
  onSettled: (_data, _error, variables) => {
76
118
  const { routeId } = variables;
77
- queryClient.invalidateQueries({ queryKey: ['route', routeId] });
78
119
  queryClient.invalidateQueries({ queryKey: ['routes'] });
120
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
121
+ queryClient.invalidateQueries({ queryKey: ['route', routeId] });
122
+ queryClient.invalidateQueries({ queryKey: ['job'] });
79
123
  },
80
124
  });
81
125
  };
@@ -117,7 +161,9 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
117
161
  onSettled: (_data, _error, variables) => {
118
162
  const { routeId } = variables;
119
163
  queryClient.invalidateQueries({ queryKey: ['routes'] });
164
+ queryClient.invalidateQueries({ queryKey: ['jobs'] });
120
165
  queryClient.invalidateQueries({ queryKey: ['route', routeId] });
166
+ queryClient.invalidateQueries({ queryKey: ['job'] });
121
167
  },
122
168
  });
123
169
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.97",
3
+ "version": "0.0.2-beta.99",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",