@comapeo/core-react 9.0.2 → 10.0.0

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.
Files changed (73) hide show
  1. package/README.md +1 -1
  2. package/dist/commonjs/contexts/ClientApi.d.ts +1 -3
  3. package/dist/commonjs/contexts/ClientApi.js +2 -2
  4. package/dist/commonjs/hooks/client.d.ts +74 -33
  5. package/dist/commonjs/hooks/client.js +40 -11
  6. package/dist/commonjs/hooks/documents.d.ts +41 -429
  7. package/dist/commonjs/hooks/documents.js +101 -51
  8. package/dist/commonjs/hooks/invites.d.ts +153 -55
  9. package/dist/commonjs/hooks/invites.js +69 -20
  10. package/dist/commonjs/hooks/maps.d.ts +96 -225
  11. package/dist/commonjs/hooks/maps.js +104 -37
  12. package/dist/commonjs/hooks/projects.d.ts +666 -223
  13. package/dist/commonjs/hooks/projects.js +264 -131
  14. package/dist/commonjs/index.d.ts +2 -2
  15. package/dist/commonjs/lib/map-shares-stores.d.ts +1 -1
  16. package/dist/commonjs/lib/map-shares-stores.js +2 -2
  17. package/dist/commonjs/lib/presets.d.ts +1 -3
  18. package/dist/commonjs/lib/react-query.d.ts +103 -0
  19. package/dist/commonjs/lib/react-query.js +187 -0
  20. package/dist/commonjs/lib/sync.d.ts +2 -5
  21. package/dist/commonjs/lib/sync.js +0 -1
  22. package/dist/commonjs/lib/types.d.ts +4 -6
  23. package/dist/esm/contexts/ClientApi.d.ts +1 -3
  24. package/dist/esm/contexts/ClientApi.js +1 -1
  25. package/dist/esm/hooks/client.d.ts +74 -33
  26. package/dist/esm/hooks/client.js +40 -11
  27. package/dist/esm/hooks/documents.d.ts +41 -429
  28. package/dist/esm/hooks/documents.js +101 -51
  29. package/dist/esm/hooks/invites.d.ts +153 -55
  30. package/dist/esm/hooks/invites.js +69 -20
  31. package/dist/esm/hooks/maps.d.ts +96 -225
  32. package/dist/esm/hooks/maps.js +105 -38
  33. package/dist/esm/hooks/projects.d.ts +666 -223
  34. package/dist/esm/hooks/projects.js +262 -129
  35. package/dist/esm/index.d.ts +2 -2
  36. package/dist/esm/lib/map-shares-stores.d.ts +1 -1
  37. package/dist/esm/lib/map-shares-stores.js +1 -1
  38. package/dist/esm/lib/presets.d.ts +1 -3
  39. package/dist/esm/lib/react-query.d.ts +103 -0
  40. package/dist/esm/lib/react-query.js +162 -0
  41. package/dist/esm/lib/sync.d.ts +2 -5
  42. package/dist/esm/lib/sync.js +1 -1
  43. package/dist/esm/lib/types.d.ts +4 -6
  44. package/docs/API.md +137 -81
  45. package/package.json +39 -35
  46. package/dist/commonjs/lib/react-query/client.d.ts +0 -65
  47. package/dist/commonjs/lib/react-query/client.js +0 -68
  48. package/dist/commonjs/lib/react-query/documents.d.ts +0 -1484
  49. package/dist/commonjs/lib/react-query/documents.js +0 -149
  50. package/dist/commonjs/lib/react-query/invites.d.ts +0 -88
  51. package/dist/commonjs/lib/react-query/invites.js +0 -95
  52. package/dist/commonjs/lib/react-query/maps.d.ts +0 -104
  53. package/dist/commonjs/lib/react-query/maps.js +0 -129
  54. package/dist/commonjs/lib/react-query/mutation-result.d.ts +0 -8
  55. package/dist/commonjs/lib/react-query/mutation-result.js +0 -22
  56. package/dist/commonjs/lib/react-query/projects.d.ts +0 -316
  57. package/dist/commonjs/lib/react-query/projects.js +0 -359
  58. package/dist/commonjs/lib/react-query/shared.d.ts +0 -9
  59. package/dist/commonjs/lib/react-query/shared.js +0 -23
  60. package/dist/esm/lib/react-query/client.d.ts +0 -65
  61. package/dist/esm/lib/react-query/client.js +0 -59
  62. package/dist/esm/lib/react-query/documents.d.ts +0 -1484
  63. package/dist/esm/lib/react-query/documents.js +0 -137
  64. package/dist/esm/lib/react-query/invites.d.ts +0 -88
  65. package/dist/esm/lib/react-query/invites.js +0 -85
  66. package/dist/esm/lib/react-query/maps.d.ts +0 -104
  67. package/dist/esm/lib/react-query/maps.js +0 -119
  68. package/dist/esm/lib/react-query/mutation-result.d.ts +0 -8
  69. package/dist/esm/lib/react-query/mutation-result.js +0 -19
  70. package/dist/esm/lib/react-query/projects.d.ts +0 -316
  71. package/dist/esm/lib/react-query/projects.js +0 -324
  72. package/dist/esm/lib/react-query/shared.d.ts +0 -9
  73. package/dist/esm/lib/react-query/shared.js +0 -18
@@ -1,7 +1,7 @@
1
1
  import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
2
2
  import { useMemo } from 'react';
3
3
  import { getPresetsSelection } from '../lib/presets.js';
4
- import { createDocumentMutationOptions, deleteDocumentMutationOptions, documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, updateDocumentMutationOptions, } from '../lib/react-query/documents.js';
4
+ import { baseMutationOptions, baseQueryOptions, filterMutationResult, getDocumentByDocIdQueryKey, getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, } from '../lib/react-query.js';
5
5
  import { useProjectSettings, useSingleProject } from './projects.js';
6
6
  /**
7
7
  * Retrieve a single document from the database based on the document's document ID.
@@ -28,15 +28,25 @@ import { useProjectSettings, useSingleProject } from './projects.js';
28
28
  */
29
29
  export function useSingleDocByDocId({ projectId, docType, docId, lang, }) {
30
30
  const { data: projectApi } = useSingleProject({ projectId });
31
- const { data, error, isRefetching } = useSuspenseQuery(documentByDocumentIdQueryOptions({
32
- projectApi,
33
- projectId,
34
- docType,
35
- docId,
36
- lang,
37
- }));
31
+ const { data, error, isRefetching } = useSuspenseQuery({
32
+ ...baseQueryOptions(),
33
+ queryKey: getDocumentByDocIdQueryKey({
34
+ projectId,
35
+ docType,
36
+ docId,
37
+ lang,
38
+ }),
39
+ queryFn: async () => {
40
+ return projectApi[docType].getByDocId(docId, {
41
+ lang,
42
+ // We want to make sure that this throws in the case that no match is found
43
+ mustBeFound: true,
44
+ });
45
+ },
46
+ });
38
47
  return {
39
- data: data,
48
+ // @ts-expect-error Not smart enough
49
+ data,
40
50
  error,
41
51
  isRefetching,
42
52
  };
@@ -66,15 +76,21 @@ export function useSingleDocByDocId({ projectId, docType, docId, lang, }) {
66
76
  */
67
77
  export function useSingleDocByVersionId({ projectId, docType, versionId, lang, }) {
68
78
  const { data: projectApi } = useSingleProject({ projectId });
69
- const { data, error, isRefetching } = useSuspenseQuery(documentByVersionIdQueryOptions({
70
- projectApi,
71
- projectId,
72
- docType,
73
- versionId,
74
- lang,
75
- }));
79
+ const { data, error, isRefetching } = useSuspenseQuery({
80
+ ...baseQueryOptions(),
81
+ queryKey: getDocumentByVersionIdQueryKey({
82
+ projectId,
83
+ docType,
84
+ versionId,
85
+ lang,
86
+ }),
87
+ queryFn: async () => {
88
+ return projectApi[docType].getByVersionId(versionId, { lang });
89
+ },
90
+ });
76
91
  return {
77
- data: data,
92
+ // @ts-expect-error Not smart enough
93
+ data,
78
94
  error,
79
95
  isRefetching,
80
96
  };
@@ -115,15 +131,24 @@ export function useSingleDocByVersionId({ projectId, docType, versionId, lang, }
115
131
  */
116
132
  export function useManyDocs({ projectId, docType, includeDeleted, lang, }) {
117
133
  const { data: projectApi } = useSingleProject({ projectId });
118
- const { data, error, isRefetching } = useSuspenseQuery(documentsQueryOptions({
119
- projectApi,
120
- projectId,
121
- docType,
122
- includeDeleted,
123
- lang,
124
- }));
134
+ const { data, error, isRefetching } = useSuspenseQuery({
135
+ ...baseQueryOptions(),
136
+ queryKey: getManyDocumentsQueryKey({
137
+ projectId,
138
+ docType,
139
+ includeDeleted,
140
+ lang,
141
+ }),
142
+ queryFn: async () => {
143
+ return projectApi[docType].getMany({
144
+ includeDeleted,
145
+ lang,
146
+ });
147
+ },
148
+ });
125
149
  return {
126
- data: data,
150
+ // @ts-expect-error Not smart enough
151
+ data,
127
152
  error,
128
153
  isRefetching,
129
154
  };
@@ -137,15 +162,22 @@ export function useManyDocs({ projectId, docType, includeDeleted, lang, }) {
137
162
  export function useCreateDocument({ docType, projectId, }) {
138
163
  const queryClient = useQueryClient();
139
164
  const { data: projectApi } = useSingleProject({ projectId });
140
- const { error, mutate, mutateAsync, reset, status } = useMutation(createDocumentMutationOptions({
141
- docType,
142
- projectApi,
143
- projectId,
144
- queryClient,
165
+ return filterMutationResult(useMutation({
166
+ ...baseMutationOptions(),
167
+ mutationFn: async ({ value, }) => {
168
+ return (projectApi[docType]
169
+ // @ts-expect-error TS not handling this well
170
+ .create({ ...value, schemaName: docType }));
171
+ },
172
+ onSuccess: () => {
173
+ queryClient.invalidateQueries({
174
+ queryKey: getDocumentsQueryKey({
175
+ projectId,
176
+ docType,
177
+ }),
178
+ });
179
+ },
145
180
  }));
146
- return status === 'error'
147
- ? { error, mutate, mutateAsync, reset, status }
148
- : { error: null, mutate, mutateAsync, reset, status };
149
181
  }
150
182
  /**
151
183
  * Update a document within a project.
@@ -153,18 +185,28 @@ export function useCreateDocument({ docType, projectId, }) {
153
185
  * @param opts.docType Document type to update.
154
186
  * @param opts.projectId Public ID of project document belongs to.
155
187
  */
156
- export function useUpdateDocument({ docType, projectId, }) {
188
+ export function useUpdateDocument({
189
+ // TODO: Make this a mutation parameter instead of a hook parameter
190
+ docType, projectId, }) {
157
191
  const queryClient = useQueryClient();
158
192
  const { data: projectApi } = useSingleProject({ projectId });
159
- const { error, mutate, mutateAsync, reset, status } = useMutation(updateDocumentMutationOptions({
160
- docType,
161
- projectApi,
162
- projectId,
163
- queryClient,
193
+ // @ts-expect-error Not sure why TS complains here
194
+ return filterMutationResult(useMutation({
195
+ ...baseMutationOptions(),
196
+ mutationFn: async ({ versionId, value, }) => {
197
+ return (projectApi[docType]
198
+ // @ts-expect-error TS not handling this well
199
+ .update(versionId, value));
200
+ },
201
+ onSuccess: () => {
202
+ queryClient.invalidateQueries({
203
+ queryKey: getDocumentsQueryKey({
204
+ projectId,
205
+ docType,
206
+ }),
207
+ });
208
+ },
164
209
  }));
165
- return status === 'error'
166
- ? { error, mutate, mutateAsync, reset, status }
167
- : { error: null, mutate, mutateAsync, reset, status };
168
210
  }
169
211
  /**
170
212
  * Delete a document within a project.
@@ -172,18 +214,26 @@ export function useUpdateDocument({ docType, projectId, }) {
172
214
  * @param opts.docType Document type to delete.
173
215
  * @param opts.projectId Public ID of project document belongs to.
174
216
  */
175
- export function useDeleteDocument({ docType, projectId, }) {
217
+ export function useDeleteDocument({
218
+ // TODO: Make this a mutation parameter instead of a hook parameter
219
+ docType, projectId, }) {
176
220
  const queryClient = useQueryClient();
177
221
  const { data: projectApi } = useSingleProject({ projectId });
178
- const { error, mutate, mutateAsync, reset, status } = useMutation(deleteDocumentMutationOptions({
179
- docType,
180
- projectApi,
181
- projectId,
182
- queryClient,
222
+ // @ts-expect-error Not sure why TS complains here
223
+ return filterMutationResult(useMutation({
224
+ ...baseMutationOptions(),
225
+ mutationFn: async ({ docId }) => {
226
+ return projectApi[docType].delete(docId);
227
+ },
228
+ onSuccess: () => {
229
+ queryClient.invalidateQueries({
230
+ queryKey: getDocumentsQueryKey({
231
+ projectId,
232
+ docType,
233
+ }),
234
+ });
235
+ },
183
236
  }));
184
- return status === 'error'
185
- ? { error, mutate, mutateAsync, reset, status }
186
- : { error: null, mutate, mutateAsync, reset, status };
187
237
  }
188
238
  const dataTypeToGeometry = {
189
239
  observation: 'point',
@@ -1,3 +1,5 @@
1
+ import type { InviteApi, MemberApi } from '@comapeo/core';
2
+ import { type UseSuspenseQueryResult } from '@tanstack/react-query';
1
3
  /**
2
4
  * Get all invites that the device has received.
3
5
  *
@@ -8,11 +10,7 @@
8
10
  * }
9
11
  * ```
10
12
  */
11
- export declare function useManyInvites(): {
12
- data: import("@comapeo/core/dist/invite/invite-api.js").Invite[];
13
- error: Error | null;
14
- isRefetching: boolean;
15
- };
13
+ export declare function useManyInvites(): Pick<UseSuspenseQueryResult<Array<InviteApi.Invite>>, 'data' | 'error' | 'isRefetching'>;
16
14
  /**
17
15
  * Get a single invite based on its ID.
18
16
  *
@@ -25,61 +23,97 @@ export declare function useManyInvites(): {
25
23
  * }
26
24
  * ```
27
25
  */
28
- export declare function useSingleInvite({ inviteId }: {
26
+ export declare function useSingleInvite({ inviteId, }: {
29
27
  inviteId: string;
30
- }): {
31
- data: import("@comapeo/core/dist/invite/invite-api.js").Invite;
32
- error: Error | null;
33
- isRefetching: boolean;
34
- };
28
+ }): Pick<UseSuspenseQueryResult<InviteApi.Invite>, 'data' | 'error' | 'isRefetching'>;
35
29
  /**
36
30
  * Accept an invite that has been received.
37
31
  */
38
- export declare function useAcceptInvite(): {
39
- error: Error;
32
+ export declare function useAcceptInvite(): Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverIdleResult<string, Error, {
33
+ inviteId: string;
34
+ }, unknown>, {
35
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
36
+ inviteId: string;
37
+ }, unknown>;
38
+ }> & {
39
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
40
+ inviteId: string;
41
+ }, unknown>;
42
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverLoadingResult<string, Error, {
43
+ inviteId: string;
44
+ }, unknown>, {
45
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
46
+ inviteId: string;
47
+ }, unknown>;
48
+ }> & {
49
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
50
+ inviteId: string;
51
+ }, unknown>;
52
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverErrorResult<string, Error, {
53
+ inviteId: string;
54
+ }, unknown>, {
40
55
  mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
41
56
  inviteId: string;
42
57
  }, unknown>;
58
+ }> & {
43
59
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
44
60
  inviteId: string;
45
61
  }, unknown>;
46
- reset: () => void;
47
- status: "error";
48
- } | {
49
- error: null;
62
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverSuccessResult<string, Error, {
63
+ inviteId: string;
64
+ }, unknown>, {
50
65
  mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
51
66
  inviteId: string;
52
67
  }, unknown>;
68
+ }> & {
53
69
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
54
70
  inviteId: string;
55
71
  }, unknown>;
56
- reset: () => void;
57
- status: "pending" | "success" | "idle";
58
- };
72
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
59
73
  /**
60
74
  * Reject an invite that has been received.
61
75
  */
62
- export declare function useRejectInvite(): {
63
- error: Error;
64
- mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
76
+ export declare function useRejectInvite(): Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverIdleResult<string, Error, {
77
+ inviteId: string;
78
+ }, unknown>, {
79
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
65
80
  inviteId: string;
66
81
  }, unknown>;
67
- mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
82
+ }> & {
83
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
68
84
  inviteId: string;
69
85
  }, unknown>;
70
- reset: () => void;
71
- status: "error";
72
- } | {
73
- error: null;
74
- mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
86
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverLoadingResult<string, Error, {
87
+ inviteId: string;
88
+ }, unknown>, {
89
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
75
90
  inviteId: string;
76
91
  }, unknown>;
77
- mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
92
+ }> & {
93
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
94
+ inviteId: string;
95
+ }, unknown>;
96
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverErrorResult<string, Error, {
97
+ inviteId: string;
98
+ }, unknown>, {
99
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
100
+ inviteId: string;
101
+ }, unknown>;
102
+ }> & {
103
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
104
+ inviteId: string;
105
+ }, unknown>;
106
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverSuccessResult<string, Error, {
107
+ inviteId: string;
108
+ }, unknown>, {
109
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
78
110
  inviteId: string;
79
111
  }, unknown>;
80
- reset: () => void;
81
- status: "pending" | "success" | "idle";
82
- };
112
+ }> & {
113
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
114
+ inviteId: string;
115
+ }, unknown>;
116
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
83
117
  /**
84
118
  * Send an invite for a project.
85
119
  *
@@ -87,39 +121,83 @@ export declare function useRejectInvite(): {
87
121
  */
88
122
  export declare function useSendInvite({ projectId }: {
89
123
  projectId: string;
90
- }): {
91
- error: Error;
124
+ }): Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverIdleResult<"ACCEPT" | "REJECT" | "ALREADY", Error, {
125
+ deviceId: string;
126
+ roleDescription?: string;
127
+ roleId: MemberApi.RoleIdForNewInvite;
128
+ roleName?: string;
129
+ }, unknown>, {
130
+ mutate: import("@tanstack/react-query").UseMutateFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
131
+ deviceId: string;
132
+ roleDescription?: string;
133
+ roleId: MemberApi.RoleIdForNewInvite;
134
+ roleName?: string;
135
+ }, unknown>;
136
+ }> & {
137
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
138
+ deviceId: string;
139
+ roleDescription?: string;
140
+ roleId: MemberApi.RoleIdForNewInvite;
141
+ roleName?: string;
142
+ }, unknown>;
143
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverLoadingResult<"ACCEPT" | "REJECT" | "ALREADY", Error, {
144
+ deviceId: string;
145
+ roleDescription?: string;
146
+ roleId: MemberApi.RoleIdForNewInvite;
147
+ roleName?: string;
148
+ }, unknown>, {
149
+ mutate: import("@tanstack/react-query").UseMutateFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
150
+ deviceId: string;
151
+ roleDescription?: string;
152
+ roleId: MemberApi.RoleIdForNewInvite;
153
+ roleName?: string;
154
+ }, unknown>;
155
+ }> & {
156
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
157
+ deviceId: string;
158
+ roleDescription?: string;
159
+ roleId: MemberApi.RoleIdForNewInvite;
160
+ roleName?: string;
161
+ }, unknown>;
162
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverErrorResult<"ACCEPT" | "REJECT" | "ALREADY", Error, {
163
+ deviceId: string;
164
+ roleDescription?: string;
165
+ roleId: MemberApi.RoleIdForNewInvite;
166
+ roleName?: string;
167
+ }, unknown>, {
92
168
  mutate: import("@tanstack/react-query").UseMutateFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
93
169
  deviceId: string;
94
170
  roleDescription?: string;
95
- roleId: import("@comapeo/core").MemberApi.RoleIdForNewInvite;
171
+ roleId: MemberApi.RoleIdForNewInvite;
96
172
  roleName?: string;
97
173
  }, unknown>;
174
+ }> & {
98
175
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
99
176
  deviceId: string;
100
177
  roleDescription?: string;
101
- roleId: import("@comapeo/core").MemberApi.RoleIdForNewInvite;
178
+ roleId: MemberApi.RoleIdForNewInvite;
102
179
  roleName?: string;
103
180
  }, unknown>;
104
- reset: () => void;
105
- status: "error";
106
- } | {
107
- error: null;
181
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverSuccessResult<"ACCEPT" | "REJECT" | "ALREADY", Error, {
182
+ deviceId: string;
183
+ roleDescription?: string;
184
+ roleId: MemberApi.RoleIdForNewInvite;
185
+ roleName?: string;
186
+ }, unknown>, {
108
187
  mutate: import("@tanstack/react-query").UseMutateFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
109
188
  deviceId: string;
110
189
  roleDescription?: string;
111
- roleId: import("@comapeo/core").MemberApi.RoleIdForNewInvite;
190
+ roleId: MemberApi.RoleIdForNewInvite;
112
191
  roleName?: string;
113
192
  }, unknown>;
193
+ }> & {
114
194
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
115
195
  deviceId: string;
116
196
  roleDescription?: string;
117
- roleId: import("@comapeo/core").MemberApi.RoleIdForNewInvite;
197
+ roleId: MemberApi.RoleIdForNewInvite;
118
198
  roleName?: string;
119
199
  }, unknown>;
120
- reset: () => void;
121
- status: "pending" | "success" | "idle";
122
- };
200
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
123
201
  /**
124
202
  * Request a cancellation of an invite sent to another device.
125
203
  *
@@ -127,24 +205,44 @@ export declare function useSendInvite({ projectId }: {
127
205
  */
128
206
  export declare function useRequestCancelInvite({ projectId }: {
129
207
  projectId: string;
130
- }): {
131
- error: Error;
208
+ }): Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverIdleResult<void, Error, {
209
+ deviceId: string;
210
+ }, unknown>, {
211
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
212
+ deviceId: string;
213
+ }, unknown>;
214
+ }> & {
215
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
216
+ deviceId: string;
217
+ }, unknown>;
218
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverLoadingResult<void, Error, {
219
+ deviceId: string;
220
+ }, unknown>, {
221
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
222
+ deviceId: string;
223
+ }, unknown>;
224
+ }> & {
225
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
226
+ deviceId: string;
227
+ }, unknown>;
228
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverErrorResult<void, Error, {
229
+ deviceId: string;
230
+ }, unknown>, {
132
231
  mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
133
232
  deviceId: string;
134
233
  }, unknown>;
234
+ }> & {
135
235
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
136
236
  deviceId: string;
137
237
  }, unknown>;
138
- reset: () => void;
139
- status: "error";
140
- } | {
141
- error: null;
238
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverSuccessResult<void, Error, {
239
+ deviceId: string;
240
+ }, unknown>, {
142
241
  mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
143
242
  deviceId: string;
144
243
  }, unknown>;
244
+ }> & {
145
245
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
146
246
  deviceId: string;
147
247
  }, unknown>;
148
- reset: () => void;
149
- status: "pending" | "success" | "idle";
150
- };
248
+ }, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
@@ -1,5 +1,5 @@
1
1
  import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
2
- import { acceptInviteMutationOptions, getInviteByIdQueryOptions, getInvitesQueryOptions, rejectInviteMutationOptions, requestCancelInviteMutationOptions, sendInviteMutationOptions, } from '../lib/react-query/invites.js';
2
+ import { baseMutationOptions, baseQueryOptions, filterMutationResult, getInvitesByIdQueryKey, getInvitesQueryKey, getMembersQueryKey, getProjectsQueryKey, } from '../lib/react-query.js';
3
3
  import { useClientApi } from './client.js';
4
4
  import { useSingleProject } from './projects.js';
5
5
  /**
@@ -14,7 +14,13 @@ import { useSingleProject } from './projects.js';
14
14
  */
15
15
  export function useManyInvites() {
16
16
  const clientApi = useClientApi();
17
- const { data, error, isRefetching } = useSuspenseQuery(getInvitesQueryOptions({ clientApi }));
17
+ const { data, error, isRefetching } = useSuspenseQuery({
18
+ ...baseQueryOptions(),
19
+ queryKey: getInvitesQueryKey(),
20
+ queryFn: async () => {
21
+ return clientApi.invite.getMany();
22
+ },
23
+ });
18
24
  return { data, error, isRefetching };
19
25
  }
20
26
  /**
@@ -29,9 +35,15 @@ export function useManyInvites() {
29
35
  * }
30
36
  * ```
31
37
  */
32
- export function useSingleInvite({ inviteId }) {
38
+ export function useSingleInvite({ inviteId, }) {
33
39
  const clientApi = useClientApi();
34
- const { data, error, isRefetching } = useSuspenseQuery(getInviteByIdQueryOptions({ clientApi, inviteId }));
40
+ const { data, error, isRefetching } = useSuspenseQuery({
41
+ ...baseQueryOptions(),
42
+ queryKey: getInvitesByIdQueryKey({ inviteId }),
43
+ queryFn: async () => {
44
+ return clientApi.invite.getById(inviteId);
45
+ },
46
+ });
35
47
  return { data, error, isRefetching };
36
48
  }
37
49
  /**
@@ -40,10 +52,20 @@ export function useSingleInvite({ inviteId }) {
40
52
  export function useAcceptInvite() {
41
53
  const queryClient = useQueryClient();
42
54
  const clientApi = useClientApi();
43
- const { error, mutate, mutateAsync, reset, status } = useMutation(acceptInviteMutationOptions({ clientApi, queryClient }));
44
- return status === 'error'
45
- ? { error, mutate, mutateAsync, reset, status }
46
- : { error: null, mutate, mutateAsync, reset, status };
55
+ return filterMutationResult(useMutation({
56
+ ...baseMutationOptions(),
57
+ mutationFn: async ({ inviteId }) => {
58
+ return clientApi.invite.accept({ inviteId });
59
+ },
60
+ onSuccess: () => {
61
+ queryClient.invalidateQueries({
62
+ queryKey: getInvitesQueryKey(),
63
+ });
64
+ queryClient.invalidateQueries({
65
+ queryKey: getProjectsQueryKey(),
66
+ });
67
+ },
68
+ }));
47
69
  }
48
70
  /**
49
71
  * Reject an invite that has been received.
@@ -51,10 +73,20 @@ export function useAcceptInvite() {
51
73
  export function useRejectInvite() {
52
74
  const queryClient = useQueryClient();
53
75
  const clientApi = useClientApi();
54
- const { error, mutate, mutateAsync, reset, status } = useMutation(rejectInviteMutationOptions({ clientApi, queryClient }));
55
- return status === 'error'
56
- ? { error, mutate, mutateAsync, reset, status }
57
- : { error: null, mutate, mutateAsync, reset, status };
76
+ return filterMutationResult(useMutation({
77
+ ...baseMutationOptions(),
78
+ mutationFn: async ({ inviteId }) => {
79
+ return clientApi.invite.accept({ inviteId });
80
+ },
81
+ onSuccess: () => {
82
+ queryClient.invalidateQueries({
83
+ queryKey: getInvitesQueryKey(),
84
+ });
85
+ queryClient.invalidateQueries({
86
+ queryKey: getProjectsQueryKey(),
87
+ });
88
+ },
89
+ }));
58
90
  }
59
91
  /**
60
92
  * Send an invite for a project.
@@ -64,10 +96,20 @@ export function useRejectInvite() {
64
96
  export function useSendInvite({ projectId }) {
65
97
  const queryClient = useQueryClient();
66
98
  const { data: projectApi } = useSingleProject({ projectId });
67
- const { error, mutate, mutateAsync, reset, status } = useMutation(sendInviteMutationOptions({ projectApi, projectId, queryClient }));
68
- return status === 'error'
69
- ? { error, mutate, mutateAsync, reset, status }
70
- : { error: null, mutate, mutateAsync, reset, status };
99
+ return filterMutationResult(useMutation({
100
+ ...baseMutationOptions(),
101
+ mutationFn: async ({ deviceId, ...role }) => {
102
+ return projectApi.$member.invite(deviceId, role);
103
+ },
104
+ onSuccess: () => {
105
+ queryClient.invalidateQueries({
106
+ queryKey: getInvitesQueryKey(),
107
+ });
108
+ queryClient.invalidateQueries({
109
+ queryKey: getMembersQueryKey({ projectId }),
110
+ });
111
+ },
112
+ }));
71
113
  }
72
114
  /**
73
115
  * Request a cancellation of an invite sent to another device.
@@ -77,8 +119,15 @@ export function useSendInvite({ projectId }) {
77
119
  export function useRequestCancelInvite({ projectId }) {
78
120
  const queryClient = useQueryClient();
79
121
  const { data: projectApi } = useSingleProject({ projectId });
80
- const { error, mutate, mutateAsync, reset, status } = useMutation(requestCancelInviteMutationOptions({ projectApi, queryClient }));
81
- return status === 'error'
82
- ? { error, mutate, mutateAsync, reset, status }
83
- : { error: null, mutate, mutateAsync, reset, status };
122
+ return filterMutationResult(useMutation({
123
+ ...baseMutationOptions(),
124
+ mutationFn: async ({ deviceId }) => {
125
+ return projectApi.$member.requestCancelInvite(deviceId);
126
+ },
127
+ onSuccess: () => {
128
+ queryClient.invalidateQueries({
129
+ queryKey: getInvitesQueryKey(),
130
+ });
131
+ },
132
+ }));
84
133
  }