@go-avro/avro-js 0.0.2-beta.48 → 0.0.2-beta.49

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.
@@ -153,6 +153,9 @@ declare module '../client/QueryClient' {
153
153
  }, StandardError, {
154
154
  routeId: string;
155
155
  }>>;
156
+ useDeleteSelf(): ReturnType<typeof useMutation<{
157
+ msg: string;
158
+ }, StandardError, void>>;
156
159
  }
157
160
  }
158
161
  export declare class AvroQueryClient {
@@ -1,4 +1,4 @@
1
- import { useQuery } from "@tanstack/react-query";
1
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2
2
  import { AvroQueryClient } from "../../client/QueryClient";
3
3
  AvroQueryClient.prototype.useGetUser = function (userId) {
4
4
  return useQuery({
@@ -14,3 +14,25 @@ AvroQueryClient.prototype.useGetSelf = function () {
14
14
  enabled: Boolean(this),
15
15
  });
16
16
  };
17
+ AvroQueryClient.prototype.useDeleteSelf = function () {
18
+ const queryClient = useQueryClient();
19
+ return useMutation({
20
+ mutationFn: async () => {
21
+ return this.delete(`/user`);
22
+ },
23
+ onMutate: async () => {
24
+ await queryClient.cancelQueries({ queryKey: ['user'] });
25
+ const previousUser = queryClient.getQueryData(['user']);
26
+ queryClient.removeQueries({ queryKey: ['user'] });
27
+ return { previousUser };
28
+ },
29
+ onError: (err, _, context) => {
30
+ if (context?.previousUser) {
31
+ queryClient.setQueryData(['user'], context.previousUser);
32
+ }
33
+ },
34
+ onSettled: () => {
35
+ queryClient.invalidateQueries({ queryKey: ['user'] });
36
+ },
37
+ });
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.48",
3
+ "version": "0.0.2-beta.49",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",