@go-avro/avro-js 0.1.1 → 0.1.2

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.
@@ -576,6 +576,19 @@ declare module '../client/QueryClient' {
576
576
  breakId: string;
577
577
  updates: Partial<Break>;
578
578
  }>>;
579
+ useUpdateCompanySession(): ReturnType<typeof useMutation<{
580
+ msg: string;
581
+ }, StandardError, {
582
+ sessionId: string;
583
+ updates: Partial<Session>;
584
+ companyId?: string;
585
+ }>>;
586
+ useDeleteCompanySession(): ReturnType<typeof useMutation<{
587
+ msg: string;
588
+ }, StandardError, {
589
+ sessionId: string;
590
+ companyId?: string;
591
+ }>>;
579
592
  useUpdateUser(userId: string): ReturnType<typeof useMutation<{
580
593
  msg: string;
581
594
  }, StandardError, Partial<User>>>;
@@ -231,3 +231,55 @@ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
231
231
  },
232
232
  });
233
233
  };
234
+ /** Edit another member's session (requires can_write_others_sessions). */
235
+ AvroQueryClient.prototype.useUpdateCompanySession = function () {
236
+ const queryClient = this.getQueryClient();
237
+ return useMutation({
238
+ mutationFn: ({ sessionId, updates, companyId, }) => {
239
+ return this.put({
240
+ path: `/company/${companyId ?? this.companyId}/session/${sessionId}`,
241
+ data: JSON.stringify(updates),
242
+ headers: { 'Content-Type': 'application/json' },
243
+ });
244
+ },
245
+ onMutate: async ({ sessionId, updates }) => {
246
+ await queryClient.cancelQueries({ queryKey: [NS] });
247
+ const previous = snapshotSessionLists(queryClient);
248
+ patchSessionLists(queryClient, (items) => items.map((session) => session.id === sessionId ? new Session({ ...session, ...updates }) : session));
249
+ queryClient.setQueryData(keys.detail(NS, sessionId), (old) => old ? new Session({ ...old, ...updates }) : old);
250
+ return { previous };
251
+ },
252
+ onError: (_err, _vars, context) => {
253
+ if (context?.previous)
254
+ restoreSessionLists(queryClient, context.previous);
255
+ },
256
+ onSettled: () => {
257
+ this.syncAfterMutation('session', 'timecard');
258
+ },
259
+ });
260
+ };
261
+ /** Delete another member's session (requires can_write_others_sessions). */
262
+ AvroQueryClient.prototype.useDeleteCompanySession = function () {
263
+ const queryClient = this.getQueryClient();
264
+ return useMutation({
265
+ mutationFn: ({ sessionId, companyId }) => {
266
+ return this.delete({
267
+ path: `/company/${companyId ?? this.companyId}/session/${sessionId}`,
268
+ });
269
+ },
270
+ onMutate: async ({ sessionId }) => {
271
+ await queryClient.cancelQueries({ queryKey: [NS] });
272
+ const previous = snapshotSessionLists(queryClient);
273
+ patchSessionLists(queryClient, (items) => items.filter((s) => s.id !== sessionId));
274
+ queryClient.removeQueries({ queryKey: keys.detail(NS, sessionId), exact: true });
275
+ return { previous };
276
+ },
277
+ onError: (_err, _vars, context) => {
278
+ if (context?.previous)
279
+ restoreSessionLists(queryClient, context.previous);
280
+ },
281
+ onSettled: () => {
282
+ this.syncAfterMutation('session', 'timecard');
283
+ },
284
+ });
285
+ };
@@ -43,7 +43,6 @@ AvroQueryClient.prototype.useGetTimecard = function (timecardId, enabled = true)
43
43
  });
44
44
  };
45
45
  AvroQueryClient.prototype.useCreateTimecard = function () {
46
- const queryClient = this.getQueryClient();
47
46
  return useMutation({
48
47
  mutationFn: ({ companyId, data, }) => {
49
48
  const targetCompanyId = companyId ?? this.companyId;
@@ -53,13 +52,12 @@ AvroQueryClient.prototype.useCreateTimecard = function () {
53
52
  headers: { 'Content-Type': 'application/json' },
54
53
  });
55
54
  },
56
- onSuccess: () => {
57
- queryClient.invalidateQueries({ queryKey: ['timecards'] });
55
+ onSettled: () => {
56
+ this.syncAfterMutation('timecard');
58
57
  },
59
58
  });
60
59
  };
61
60
  AvroQueryClient.prototype.useUpdateTimecard = function () {
62
- const queryClient = this.getQueryClient();
63
61
  return useMutation({
64
62
  mutationFn: ({ timecardId, updates, }) => {
65
63
  return this.put({
@@ -68,8 +66,8 @@ AvroQueryClient.prototype.useUpdateTimecard = function () {
68
66
  headers: { 'Content-Type': 'application/json' },
69
67
  });
70
68
  },
71
- onSuccess: () => {
72
- queryClient.invalidateQueries({ queryKey: ['timecards'] });
69
+ onSettled: () => {
70
+ this.syncAfterMutation('timecard');
73
71
  },
74
72
  });
75
73
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AVRO_JS_VERSION = "0.1.1";
1
+ export declare const AVRO_JS_VERSION = "0.1.2";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED by scripts/gen-version.js — do not edit by hand.
2
2
  // Regenerated from package.json by the `prebuild` npm hook.
3
- export const AVRO_JS_VERSION = '0.1.1';
3
+ export const AVRO_JS_VERSION = '0.1.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",