@comapeo/core-react 1.1.0 → 2.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 (46) hide show
  1. package/dist/commonjs/hooks/client.d.ts +21 -0
  2. package/dist/commonjs/hooks/client.js +20 -0
  3. package/dist/commonjs/hooks/documents.d.ts +59 -4
  4. package/dist/commonjs/hooks/documents.js +54 -0
  5. package/dist/commonjs/hooks/invites.d.ts +51 -0
  6. package/dist/commonjs/hooks/invites.js +50 -0
  7. package/dist/commonjs/hooks/projects.d.ts +83 -0
  8. package/dist/commonjs/hooks/projects.js +62 -0
  9. package/dist/commonjs/index.d.ts +10 -9
  10. package/dist/commonjs/index.js +21 -21
  11. package/dist/commonjs/lib/react-query/client.d.ts +40 -9
  12. package/dist/commonjs/lib/react-query/client.js +32 -0
  13. package/dist/commonjs/lib/react-query/documents.d.ts +733 -650
  14. package/dist/commonjs/lib/react-query/documents.js +57 -0
  15. package/dist/commonjs/lib/react-query/invites.d.ts +63 -4
  16. package/dist/commonjs/lib/react-query/invites.js +63 -0
  17. package/dist/commonjs/lib/react-query/maps.d.ts +12 -3
  18. package/dist/commonjs/lib/react-query/maps.js +5 -1
  19. package/dist/commonjs/lib/react-query/projects.d.ts +183 -47
  20. package/dist/commonjs/lib/react-query/projects.js +88 -0
  21. package/dist/commonjs/lib/react-query/shared.d.ts +5 -1
  22. package/dist/commonjs/lib/react-query/shared.js +8 -1
  23. package/dist/esm/hooks/client.d.ts +21 -0
  24. package/dist/esm/hooks/client.js +20 -2
  25. package/dist/esm/hooks/documents.d.ts +59 -4
  26. package/dist/esm/hooks/documents.js +53 -2
  27. package/dist/esm/hooks/invites.d.ts +51 -0
  28. package/dist/esm/hooks/invites.js +44 -0
  29. package/dist/esm/hooks/projects.d.ts +83 -0
  30. package/dist/esm/hooks/projects.js +58 -2
  31. package/dist/esm/index.d.ts +10 -9
  32. package/dist/esm/index.js +10 -9
  33. package/dist/esm/lib/react-query/client.d.ts +40 -9
  34. package/dist/esm/lib/react-query/client.js +32 -2
  35. package/dist/esm/lib/react-query/documents.d.ts +733 -650
  36. package/dist/esm/lib/react-query/documents.js +56 -2
  37. package/dist/esm/lib/react-query/invites.d.ts +63 -4
  38. package/dist/esm/lib/react-query/invites.js +61 -2
  39. package/dist/esm/lib/react-query/maps.d.ts +12 -3
  40. package/dist/esm/lib/react-query/maps.js +5 -1
  41. package/dist/esm/lib/react-query/projects.d.ts +183 -47
  42. package/dist/esm/lib/react-query/projects.js +84 -2
  43. package/dist/esm/lib/react-query/shared.d.ts +5 -1
  44. package/dist/esm/lib/react-query/shared.js +7 -1
  45. package/docs/API.md +157 -258
  46. package/package.json +27 -28
@@ -18,6 +18,12 @@ exports.projectOwnRoleQueryOptions = projectOwnRoleQueryOptions;
18
18
  exports.iconUrlQueryOptions = iconUrlQueryOptions;
19
19
  exports.documentCreatedByQueryOptions = documentCreatedByQueryOptions;
20
20
  exports.attachmentUrlQueryOptions = attachmentUrlQueryOptions;
21
+ exports.addServerPeerMutationOptions = addServerPeerMutationOptions;
22
+ exports.createProjectMutationOptions = createProjectMutationOptions;
23
+ exports.leaveProjectMutationOptions = leaveProjectMutationOptions;
24
+ exports.importProjectConfigMutationOptions = importProjectConfigMutationOptions;
25
+ exports.updateProjectSettingsMutationOptions = updateProjectSettingsMutationOptions;
26
+ exports.createBlobMutationOptions = createBlobMutationOptions;
21
27
  const react_query_1 = require("@tanstack/react-query");
22
28
  const shared_js_1 = require("./shared.js");
23
29
  function getProjectsQueryKey() {
@@ -145,3 +151,85 @@ function attachmentUrlQueryOptions({ projectApi, projectId, blobId, }) {
145
151
  },
146
152
  });
147
153
  }
154
+ function addServerPeerMutationOptions({ projectApi, projectId, queryClient, }) {
155
+ return {
156
+ ...(0, shared_js_1.baseMutationOptions)(),
157
+ mutationFn: async ({ baseUrl, dangerouslyAllowInsecureConnections }) => {
158
+ return projectApi.$member.addServerPeer(baseUrl, {
159
+ dangerouslyAllowInsecureConnections,
160
+ });
161
+ },
162
+ onSuccess: () => {
163
+ queryClient.invalidateQueries({
164
+ queryKey: getMembersQueryKey({ projectId }),
165
+ });
166
+ },
167
+ };
168
+ }
169
+ function createProjectMutationOptions({ clientApi, queryClient, }) {
170
+ return {
171
+ ...(0, shared_js_1.baseMutationOptions)(),
172
+ mutationFn: async (opts) => {
173
+ // Have to avoid passing `undefined` explicitly
174
+ // See https://github.com/digidem/rpc-reflector/issues/21
175
+ return opts
176
+ ? clientApi.createProject({
177
+ configPath: opts.configPath,
178
+ name: opts.name,
179
+ })
180
+ : clientApi.createProject();
181
+ },
182
+ onSuccess: () => {
183
+ queryClient.invalidateQueries({
184
+ queryKey: getProjectsQueryKey(),
185
+ });
186
+ },
187
+ };
188
+ }
189
+ function leaveProjectMutationOptions({ clientApi, queryClient, }) {
190
+ return {
191
+ ...(0, shared_js_1.baseMutationOptions)(),
192
+ mutationFn: async ({ projectId }) => {
193
+ return clientApi.leaveProject(projectId);
194
+ },
195
+ onSuccess: () => {
196
+ queryClient.invalidateQueries({
197
+ queryKey: getProjectsQueryKey(),
198
+ });
199
+ },
200
+ };
201
+ }
202
+ function importProjectConfigMutationOptions({ projectApi, projectId, queryClient, }) {
203
+ return {
204
+ ...(0, shared_js_1.baseMutationOptions)(),
205
+ mutationFn: ({ configPath }) => {
206
+ return projectApi.importConfig({ configPath });
207
+ },
208
+ onSuccess: () => {
209
+ queryClient.invalidateQueries({
210
+ queryKey: getProjectByIdQueryKey({ projectId }),
211
+ });
212
+ },
213
+ };
214
+ }
215
+ function updateProjectSettingsMutationOptions({ projectApi, queryClient, }) {
216
+ return {
217
+ ...(0, shared_js_1.baseMutationOptions)(),
218
+ mutationFn: async (value) => {
219
+ return projectApi.$setProjectSettings(value);
220
+ },
221
+ onSuccess: () => {
222
+ queryClient.invalidateQueries({
223
+ queryKey: getProjectsQueryKey(),
224
+ });
225
+ },
226
+ };
227
+ }
228
+ function createBlobMutationOptions({ projectApi, }) {
229
+ return {
230
+ ...(0, shared_js_1.baseMutationOptions)(),
231
+ mutationFn: async ({ original, preview, thumbnail, metadata }) => {
232
+ return projectApi.$blobs.create({ original, preview, thumbnail }, metadata);
233
+ },
234
+ };
235
+ }
@@ -1,5 +1,9 @@
1
1
  export declare const ROOT_QUERY_KEY = "@comapeo/core-react";
2
2
  export declare function baseQueryOptions(): {
3
3
  networkMode: "always";
4
- retry: number;
4
+ retry: false;
5
+ };
6
+ export declare function baseMutationOptions(): {
7
+ networkMode: "always";
8
+ retry: false;
5
9
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ROOT_QUERY_KEY = void 0;
4
4
  exports.baseQueryOptions = baseQueryOptions;
5
+ exports.baseMutationOptions = baseMutationOptions;
5
6
  exports.ROOT_QUERY_KEY = '@comapeo/core-react';
6
7
  // Since the API is running locally, queries should run regardless of network
7
8
  // status, and should not be retried. In React Native the API consumer would
@@ -11,6 +12,12 @@ exports.ROOT_QUERY_KEY = '@comapeo/core-react';
11
12
  function baseQueryOptions() {
12
13
  return {
13
14
  networkMode: 'always',
14
- retry: 0,
15
+ retry: false,
16
+ };
17
+ }
18
+ function baseMutationOptions() {
19
+ return {
20
+ networkMode: 'always',
21
+ retry: false,
15
22
  };
16
23
  }
@@ -57,3 +57,24 @@ export declare function useIsArchiveDevice(): {
57
57
  error: Error | null;
58
58
  isRefetching: boolean;
59
59
  };
60
+ /**
61
+ * Update the device info for the current device.
62
+ */
63
+ export declare function useSetOwnDeviceInfo(): {
64
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
65
+ name: string;
66
+ deviceType: import("@comapeo/schema").DeviceInfo["deviceType"];
67
+ }, unknown>;
68
+ reset: () => void;
69
+ status: "pending" | "error" | "success" | "idle";
70
+ };
71
+ /**
72
+ * Set or unset the current device as an archive device.
73
+ */
74
+ export declare function useSetIsArchiveDevice(): {
75
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
76
+ isArchiveDevice: boolean;
77
+ }, unknown>;
78
+ reset: () => void;
79
+ status: "pending" | "error" | "success" | "idle";
80
+ };
@@ -1,7 +1,7 @@
1
- import { useSuspenseQuery } from '@tanstack/react-query';
1
+ import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
2
2
  import { useContext } from 'react';
3
3
  import { ClientApiContext } from '../contexts/ClientApi.js';
4
- import { deviceInfoQueryOptions, isArchiveDeviceQueryOptions, } from '../lib/react-query/client.js';
4
+ import { deviceInfoQueryOptions, isArchiveDeviceQueryOptions, setIsArchiveDeviceMutationOptions, setOwnDeviceInfoMutationOptions, } from '../lib/react-query/client.js';
5
5
  /**
6
6
  * Access a client API instance. If a ClientApiContext provider is not
7
7
  * set up, it will throw an error.
@@ -64,3 +64,21 @@ export function useIsArchiveDevice() {
64
64
  const { data, error, isRefetching } = useSuspenseQuery(isArchiveDeviceQueryOptions({ clientApi }));
65
65
  return { data, error, isRefetching };
66
66
  }
67
+ /**
68
+ * Update the device info for the current device.
69
+ */
70
+ export function useSetOwnDeviceInfo() {
71
+ const queryClient = useQueryClient();
72
+ const clientApi = useClientApi();
73
+ const { mutate, status, reset } = useMutation(setOwnDeviceInfoMutationOptions({ clientApi, queryClient }));
74
+ return { mutate, reset, status };
75
+ }
76
+ /**
77
+ * Set or unset the current device as an archive device.
78
+ */
79
+ export function useSetIsArchiveDevice() {
80
+ const queryClient = useQueryClient();
81
+ const clientApi = useClientApi();
82
+ const { mutate, status, reset } = useMutation(setIsArchiveDeviceMutationOptions({ clientApi, queryClient }));
83
+ return { mutate, reset, status };
84
+ }
@@ -1,5 +1,5 @@
1
1
  import type { MapeoDoc } from '@comapeo/schema' with { 'resolution-mode': 'import' };
2
- import { type DocumentType } from '../lib/react-query/documents.js';
2
+ import { type WriteableDocumentType } from '../lib/react-query/documents.js';
3
3
  type ReadHookResult<D> = {
4
4
  data: D;
5
5
  error: Error | null;
@@ -28,7 +28,7 @@ type ReadHookResult<D> = {
28
28
  * }
29
29
  * ```
30
30
  */
31
- export declare function useSingleDocByDocId<D extends DocumentType>({ projectId, docType, docId, lang, }: {
31
+ export declare function useSingleDocByDocId<D extends WriteableDocumentType>({ projectId, docType, docId, lang, }: {
32
32
  projectId: string;
33
33
  docType: D;
34
34
  docId: string;
@@ -59,7 +59,7 @@ export declare function useSingleDocByDocId<D extends DocumentType>({ projectId,
59
59
  * }
60
60
  * ```
61
61
  */
62
- export declare function useSingleDocByVersionId<D extends DocumentType>({ projectId, docType, versionId, lang, }: {
62
+ export declare function useSingleDocByVersionId<D extends WriteableDocumentType>({ projectId, docType, versionId, lang, }: {
63
63
  projectId: string;
64
64
  docType: D;
65
65
  versionId: string;
@@ -101,7 +101,7 @@ export declare function useSingleDocByVersionId<D extends DocumentType>({ projec
101
101
  * }
102
102
  * ```
103
103
  */
104
- export declare function useManyDocs<D extends DocumentType>({ projectId, docType, includeDeleted, lang, }: {
104
+ export declare function useManyDocs<D extends WriteableDocumentType>({ projectId, docType, includeDeleted, lang, }: {
105
105
  projectId: string;
106
106
  docType: D;
107
107
  includeDeleted?: boolean;
@@ -109,4 +109,59 @@ export declare function useManyDocs<D extends DocumentType>({ projectId, docType
109
109
  }): ReadHookResult<Extract<MapeoDoc, {
110
110
  schemaName: D;
111
111
  }>>;
112
+ /**
113
+ * Create a document for a project.
114
+ *
115
+ * @param opts.docType Document type to create.
116
+ * @param opts.projectId Public ID of project to create document for.
117
+ */
118
+ export declare function useCreateDocument<D extends WriteableDocumentType>({ docType, projectId, }: {
119
+ docType: D;
120
+ projectId: string;
121
+ }): {
122
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("../lib/react-query/documents.js").WriteableDocument<D> & {
123
+ forks: Array<string>;
124
+ }, Error, {
125
+ value: Omit<import("../lib/react-query/documents.js").WriteableValue<D>, "schemaName">;
126
+ }, unknown>;
127
+ reset: () => void;
128
+ status: "pending" | "error" | "success" | "idle";
129
+ };
130
+ /**
131
+ * Update a document within a project.
132
+ *
133
+ * @param opts.docType Document type to update.
134
+ * @param opts.projectId Public ID of project document belongs to.
135
+ */
136
+ export declare function useUpdateDocument<D extends WriteableDocumentType>({ docType, projectId, }: {
137
+ docType: D;
138
+ projectId: string;
139
+ }): {
140
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("../lib/react-query/documents.js").WriteableDocument<D> & {
141
+ forks: Array<string>;
142
+ }, Error, {
143
+ versionId: string;
144
+ value: Omit<import("../lib/react-query/documents.js").WriteableValue<D>, "schemaName">;
145
+ }, unknown>;
146
+ reset: () => void;
147
+ status: "pending" | "error" | "success" | "idle";
148
+ };
149
+ /**
150
+ * Delete a document within a project.
151
+ *
152
+ * @param opts.docType Document type to delete.
153
+ * @param opts.projectId Public ID of project document belongs to.
154
+ */
155
+ export declare function useDeleteDocument<D extends WriteableDocumentType>({ docType, projectId, }: {
156
+ docType: D;
157
+ projectId: string;
158
+ }): {
159
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("../lib/react-query/documents.js").WriteableDocument<D> & {
160
+ forks: Array<string>;
161
+ }, Error, {
162
+ docId: string;
163
+ }, unknown>;
164
+ reset: () => void;
165
+ status: "pending" | "error" | "success" | "idle";
166
+ };
112
167
  export {};
@@ -1,5 +1,5 @@
1
- import { useSuspenseQuery } from '@tanstack/react-query';
2
- import { documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, } from '../lib/react-query/documents.js';
1
+ import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
2
+ import { createDocumentMutationOptions, deleteDocumentMutationOptions, documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, updateDocumentMutationOptions, } from '../lib/react-query/documents.js';
3
3
  import { useSingleProject } from './projects.js';
4
4
  /**
5
5
  * Retrieve a single document from the database based on the document's document ID.
@@ -131,3 +131,54 @@ export function useManyDocs({ projectId, docType, includeDeleted, lang, }) {
131
131
  isRefetching,
132
132
  };
133
133
  }
134
+ /**
135
+ * Create a document for a project.
136
+ *
137
+ * @param opts.docType Document type to create.
138
+ * @param opts.projectId Public ID of project to create document for.
139
+ */
140
+ export function useCreateDocument({ docType, projectId, }) {
141
+ const queryClient = useQueryClient();
142
+ const { data: projectApi } = useSingleProject({ projectId });
143
+ const { mutate, reset, status } = useMutation(createDocumentMutationOptions({
144
+ docType,
145
+ projectApi,
146
+ projectId,
147
+ queryClient,
148
+ }));
149
+ return { mutate, reset, status };
150
+ }
151
+ /**
152
+ * Update a document within a project.
153
+ *
154
+ * @param opts.docType Document type to update.
155
+ * @param opts.projectId Public ID of project document belongs to.
156
+ */
157
+ export function useUpdateDocument({ docType, projectId, }) {
158
+ const queryClient = useQueryClient();
159
+ const { data: projectApi } = useSingleProject({ projectId });
160
+ const { mutate, reset, status } = useMutation(updateDocumentMutationOptions({
161
+ docType,
162
+ projectApi,
163
+ projectId,
164
+ queryClient,
165
+ }));
166
+ return { mutate, reset, status };
167
+ }
168
+ /**
169
+ * Delete a document within a project.
170
+ *
171
+ * @param opts.docType Document type to delete.
172
+ * @param opts.projectId Public ID of project document belongs to.
173
+ */
174
+ export function useDeleteDocument({ docType, projectId, }) {
175
+ const queryClient = useQueryClient();
176
+ const { data: projectApi } = useSingleProject({ projectId });
177
+ const { mutate, reset, status } = useMutation(deleteDocumentMutationOptions({
178
+ docType,
179
+ projectApi,
180
+ projectId,
181
+ queryClient,
182
+ }));
183
+ return { mutate, reset, status };
184
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Accept an invite that has been received.
3
+ */
4
+ export declare function useAcceptInvite(): {
5
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
6
+ inviteId: string;
7
+ }, unknown>;
8
+ reset: () => void;
9
+ status: "pending" | "error" | "success" | "idle";
10
+ };
11
+ /**
12
+ * Reject an invite that has been received.
13
+ */
14
+ export declare function useRejectInvite(): {
15
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
16
+ inviteId: string;
17
+ }, unknown>;
18
+ reset: () => void;
19
+ status: "pending" | "error" | "success" | "idle";
20
+ };
21
+ /**
22
+ * Send an invite for a project.
23
+ *
24
+ * @param opts.projectId Public ID of project to send the invite on behalf of.
25
+ */
26
+ export declare function useSendInvite({ projectId }: {
27
+ projectId: string;
28
+ }): {
29
+ mutate: import("@tanstack/react-query").UseMutateFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
30
+ deviceId: string;
31
+ roleDescription?: string;
32
+ roleId: import("@comapeo/core/dist/roles.js").RoleIdForNewInvite;
33
+ roleName?: string;
34
+ }, unknown>;
35
+ reset: () => void;
36
+ status: "pending" | "error" | "success" | "idle";
37
+ };
38
+ /**
39
+ * Request a cancellation of an invite sent to another device.
40
+ *
41
+ * @param opts.projectId Public ID of project to request the invite cancellation for.
42
+ */
43
+ export declare function useRequestCancelInvite({ projectId }: {
44
+ projectId: string;
45
+ }): {
46
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
47
+ deviceId: string;
48
+ }, unknown>;
49
+ reset: () => void;
50
+ status: "pending" | "error" | "success" | "idle";
51
+ };
@@ -0,0 +1,44 @@
1
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
2
+ import { acceptInviteMutationOptions, rejectInviteMutationOptions, requestCancelInviteMutationOptions, sendInviteMutationOptions, } from '../lib/react-query/invites.js';
3
+ import { useClientApi } from './client.js';
4
+ import { useSingleProject } from './projects.js';
5
+ /**
6
+ * Accept an invite that has been received.
7
+ */
8
+ export function useAcceptInvite() {
9
+ const queryClient = useQueryClient();
10
+ const clientApi = useClientApi();
11
+ const { mutate, status, reset } = useMutation(acceptInviteMutationOptions({ clientApi, queryClient }));
12
+ return { mutate, reset, status };
13
+ }
14
+ /**
15
+ * Reject an invite that has been received.
16
+ */
17
+ export function useRejectInvite() {
18
+ const queryClient = useQueryClient();
19
+ const clientApi = useClientApi();
20
+ const { mutate, status, reset } = useMutation(rejectInviteMutationOptions({ clientApi, queryClient }));
21
+ return { mutate, reset, status };
22
+ }
23
+ /**
24
+ * Send an invite for a project.
25
+ *
26
+ * @param opts.projectId Public ID of project to send the invite on behalf of.
27
+ */
28
+ export function useSendInvite({ projectId }) {
29
+ const queryClient = useQueryClient();
30
+ const { data: projectApi } = useSingleProject({ projectId });
31
+ const { mutate, status, reset } = useMutation(sendInviteMutationOptions({ projectApi, projectId, queryClient }));
32
+ return { mutate, reset, status };
33
+ }
34
+ /**
35
+ * Request a cancellation of an invite sent to another device.
36
+ *
37
+ * @param opts.projectId Public ID of project to request the invite cancellation for.
38
+ */
39
+ export function useRequestCancelInvite({ projectId }) {
40
+ const queryClient = useQueryClient();
41
+ const { data: projectApi } = useSingleProject({ projectId });
42
+ const { mutate, status, reset } = useMutation(requestCancelInviteMutationOptions({ projectApi, queryClient }));
43
+ return { mutate, reset, status };
44
+ }
@@ -249,3 +249,86 @@ export declare function useDocumentCreatedBy({ projectId, originalVersionId, }:
249
249
  error: Error | null;
250
250
  isRefetching: boolean;
251
251
  };
252
+ export declare function useAddServerPeer({ projectId }: {
253
+ projectId: string;
254
+ }): {
255
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
256
+ baseUrl: string;
257
+ dangerouslyAllowInsecureConnections?: boolean;
258
+ }, unknown>;
259
+ reset: () => void;
260
+ status: "pending" | "error" | "success" | "idle";
261
+ };
262
+ /**
263
+ * Create a new project.
264
+ */
265
+ export declare function useCreateProject(): {
266
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
267
+ name?: string;
268
+ configPath?: string;
269
+ } | undefined, unknown>;
270
+ reset: () => void;
271
+ status: "pending" | "error" | "success" | "idle";
272
+ };
273
+ /**
274
+ * Leave an existing project.
275
+ */
276
+ export declare function useLeaveProject(): {
277
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
278
+ projectId: string;
279
+ }, unknown>;
280
+ reset: () => void;
281
+ status: "pending" | "error" | "success" | "idle";
282
+ };
283
+ /**
284
+ * Update the configuration of a project using an external file.
285
+ *
286
+ * @param opts.projectId Public ID of the project to apply changes to.
287
+ */
288
+ export declare function useImportProjectConfig({ projectId }: {
289
+ projectId: string;
290
+ }): {
291
+ mutate: import("@tanstack/react-query").UseMutateFunction<Error[], Error, {
292
+ configPath: string;
293
+ }, unknown>;
294
+ reset: () => void;
295
+ status: "pending" | "error" | "success" | "idle";
296
+ };
297
+ /**
298
+ * Update the settings of a project.
299
+ *
300
+ * @param opts.projectId Public ID of the project to apply changes to.
301
+ */
302
+ export declare function useUpdateProjectSettings({ projectId }: {
303
+ projectId: string;
304
+ }): {
305
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings, Error, {
306
+ name?: import("@comapeo/schema").ProjectSettings["name"];
307
+ configMetadata?: import("@comapeo/schema").ProjectSettings["configMetadata"];
308
+ defaultPresets?: import("@comapeo/schema").ProjectSettings["defaultPresets"];
309
+ }, unknown>;
310
+ reset: () => void;
311
+ status: "pending" | "error" | "success" | "idle";
312
+ };
313
+ /**
314
+ * Create a blob for a project.
315
+ *
316
+ * @param opts.projectId Public project ID of project to apply to changes to.
317
+ */
318
+ export declare function useCreateBlob({ projectId }: {
319
+ projectId: string;
320
+ }): {
321
+ mutate: import("@tanstack/react-query").UseMutateFunction<{
322
+ driveId: string;
323
+ name: string;
324
+ type: "photo" | "video" | "audio";
325
+ hash: string;
326
+ }, Error, {
327
+ original: string;
328
+ preview?: string;
329
+ thumbnail?: string;
330
+ metadata: import("@comapeo/core/dist/blob-api.js").Metadata;
331
+ }, unknown>;
332
+ reset: () => void;
333
+ status: "pending" | "error" | "success" | "idle";
334
+ };
@@ -1,5 +1,5 @@
1
- import { useSuspenseQuery } from '@tanstack/react-query';
2
- import { attachmentUrlQueryOptions, documentCreatedByQueryOptions, iconUrlQueryOptions, projectByIdQueryOptions, projectMemberByIdQueryOptions, projectMembersQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, } from '../lib/react-query/projects.js';
1
+ import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
2
+ import { addServerPeerMutationOptions, attachmentUrlQueryOptions, createBlobMutationOptions, createProjectMutationOptions, documentCreatedByQueryOptions, iconUrlQueryOptions, importProjectConfigMutationOptions, leaveProjectMutationOptions, projectByIdQueryOptions, projectMemberByIdQueryOptions, projectMembersQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, updateProjectSettingsMutationOptions, } from '../lib/react-query/projects.js';
3
3
  import { useClientApi } from './client.js';
4
4
  /**
5
5
  * Retrieve the project settings for a project.
@@ -246,3 +246,59 @@ export function useDocumentCreatedBy({ projectId, originalVersionId, }) {
246
246
  const { data, error, isRefetching } = useSuspenseQuery(documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId }));
247
247
  return { data, error, isRefetching };
248
248
  }
249
+ export function useAddServerPeer({ projectId }) {
250
+ const queryClient = useQueryClient();
251
+ const { data: projectApi } = useSingleProject({ projectId });
252
+ const { mutate, reset, status } = useMutation(addServerPeerMutationOptions({ projectApi, projectId, queryClient }));
253
+ return { mutate, reset, status };
254
+ }
255
+ /**
256
+ * Create a new project.
257
+ */
258
+ export function useCreateProject() {
259
+ const queryClient = useQueryClient();
260
+ const clientApi = useClientApi();
261
+ const { mutate, status, reset } = useMutation(createProjectMutationOptions({ clientApi, queryClient }));
262
+ return { mutate, reset, status };
263
+ }
264
+ /**
265
+ * Leave an existing project.
266
+ */
267
+ export function useLeaveProject() {
268
+ const queryClient = useQueryClient();
269
+ const clientApi = useClientApi();
270
+ const { mutate, status, reset } = useMutation(leaveProjectMutationOptions({ clientApi, queryClient }));
271
+ return { mutate, reset, status };
272
+ }
273
+ /**
274
+ * Update the configuration of a project using an external file.
275
+ *
276
+ * @param opts.projectId Public ID of the project to apply changes to.
277
+ */
278
+ export function useImportProjectConfig({ projectId }) {
279
+ const queryClient = useQueryClient();
280
+ const { data: projectApi } = useSingleProject({ projectId });
281
+ const { mutate, status, reset } = useMutation(importProjectConfigMutationOptions({ queryClient, projectApi, projectId }));
282
+ return { mutate, reset, status };
283
+ }
284
+ /**
285
+ * Update the settings of a project.
286
+ *
287
+ * @param opts.projectId Public ID of the project to apply changes to.
288
+ */
289
+ export function useUpdateProjectSettings({ projectId }) {
290
+ const queryClient = useQueryClient();
291
+ const { data: projectApi } = useSingleProject({ projectId });
292
+ const { mutate, reset, status } = useMutation(updateProjectSettingsMutationOptions({ projectApi, queryClient }));
293
+ return { mutate, reset, status };
294
+ }
295
+ /**
296
+ * Create a blob for a project.
297
+ *
298
+ * @param opts.projectId Public project ID of project to apply to changes to.
299
+ */
300
+ export function useCreateBlob({ projectId }) {
301
+ const { data: projectApi } = useSingleProject({ projectId });
302
+ const { mutate, reset, status } = useMutation(createBlobMutationOptions({ projectApi }));
303
+ return { mutate, reset, status };
304
+ }
@@ -1,11 +1,12 @@
1
1
  export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
2
- export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, } from './hooks/client.js';
3
- export { useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, } from './hooks/documents.js';
2
+ export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
3
+ export { useCreateDocument, useDeleteDocument, useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
4
+ export { useAcceptInvite, useRejectInvite, useRequestCancelInvite, useSendInvite, } from './hooks/invites.js';
4
5
  export { useMapStyleUrl } from './hooks/maps.js';
5
- export { useAttachmentUrl, useDocumentCreatedBy, useIconUrl, useManyMembers, useManyProjects, useProjectSettings, useSingleMember, useSingleProject, } from './hooks/projects.js';
6
- export { deviceInfoQueryOptions, getClientQueryKey, getDeviceInfoQueryKey, getIsArchiveDeviceQueryKey, isArchiveDeviceQueryOptions, } from './lib/react-query/client.js';
7
- export { documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, getDocumentByDocIdQueryKey, getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, type DocumentType, } from './lib/react-query/documents.js';
8
- export { getInvitesQueryKey, getPendingInvitesQueryKey, pendingInvitesQueryOptions, } from './lib/react-query/invites.js';
9
- export { getMapsQueryKey, getStyleJsonUrlQueryKey, mapStyleJsonUrlQueryOptions, } from './lib/react-query/maps.js';
10
- export { attachmentUrlQueryOptions, documentCreatedByQueryOptions, getAttachmentUrlQueryKey, getDocumentCreatedByQueryKey, getIconUrlQueryKey, getMemberByIdQueryKey, getMembersQueryKey, getProjectByIdQueryKey, getProjectRoleQueryKey, getProjectSettingsQueryKey, getProjectsQueryKey, iconUrlQueryOptions, projectByIdQueryOptions, projectMembersQueryOptions, projectOwnRoleQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, } from './lib/react-query/projects.js';
11
- export { ROOT_QUERY_KEY, baseQueryOptions } from './lib/react-query/shared.js';
6
+ export { useAddServerPeer, useAttachmentUrl, useCreateBlob, useCreateProject, useDocumentCreatedBy, useIconUrl, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useProjectSettings, useSingleMember, useSingleProject, useUpdateProjectSettings, } from './hooks/projects.js';
7
+ export { getClientQueryKey, getDeviceInfoQueryKey, getIsArchiveDeviceQueryKey, } from './lib/react-query/client.js';
8
+ export { getDocumentByDocIdQueryKey, getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, type WriteableDocument, type WriteableDocumentType, type WriteableValue, } from './lib/react-query/documents.js';
9
+ export { getInvitesQueryKey, getPendingInvitesQueryKey, } from './lib/react-query/invites.js';
10
+ export { getMapsQueryKey, getStyleJsonUrlQueryKey, } from './lib/react-query/maps.js';
11
+ export { getAttachmentUrlQueryKey, getDocumentCreatedByQueryKey, getIconUrlQueryKey, getMemberByIdQueryKey, getMembersQueryKey, getProjectByIdQueryKey, getProjectRoleQueryKey, getProjectSettingsQueryKey, getProjectsQueryKey, } from './lib/react-query/projects.js';
12
+ export { ROOT_QUERY_KEY } from './lib/react-query/shared.js';
package/dist/esm/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
2
- export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, } from './hooks/client.js';
3
- export { useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, } from './hooks/documents.js';
2
+ export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
3
+ export { useCreateDocument, useDeleteDocument, useManyDocs, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
4
+ export { useAcceptInvite, useRejectInvite, useRequestCancelInvite, useSendInvite, } from './hooks/invites.js';
4
5
  export { useMapStyleUrl } from './hooks/maps.js';
5
- export { useAttachmentUrl, useDocumentCreatedBy, useIconUrl, useManyMembers, useManyProjects, useProjectSettings, useSingleMember, useSingleProject, } from './hooks/projects.js';
6
- export { deviceInfoQueryOptions, getClientQueryKey, getDeviceInfoQueryKey, getIsArchiveDeviceQueryKey, isArchiveDeviceQueryOptions, } from './lib/react-query/client.js';
7
- export { documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, getDocumentByDocIdQueryKey, getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, } from './lib/react-query/documents.js';
8
- export { getInvitesQueryKey, getPendingInvitesQueryKey, pendingInvitesQueryOptions, } from './lib/react-query/invites.js';
9
- export { getMapsQueryKey, getStyleJsonUrlQueryKey, mapStyleJsonUrlQueryOptions, } from './lib/react-query/maps.js';
10
- export { attachmentUrlQueryOptions, documentCreatedByQueryOptions, getAttachmentUrlQueryKey, getDocumentCreatedByQueryKey, getIconUrlQueryKey, getMemberByIdQueryKey, getMembersQueryKey, getProjectByIdQueryKey, getProjectRoleQueryKey, getProjectSettingsQueryKey, getProjectsQueryKey, iconUrlQueryOptions, projectByIdQueryOptions, projectMembersQueryOptions, projectOwnRoleQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, } from './lib/react-query/projects.js';
11
- export { ROOT_QUERY_KEY, baseQueryOptions } from './lib/react-query/shared.js';
6
+ export { useAddServerPeer, useAttachmentUrl, useCreateBlob, useCreateProject, useDocumentCreatedBy, useIconUrl, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useProjectSettings, useSingleMember, useSingleProject, useUpdateProjectSettings, } from './hooks/projects.js';
7
+ export { getClientQueryKey, getDeviceInfoQueryKey, getIsArchiveDeviceQueryKey, } from './lib/react-query/client.js';
8
+ export { getDocumentByDocIdQueryKey, getDocumentByVersionIdQueryKey, getDocumentsQueryKey, getManyDocumentsQueryKey, } from './lib/react-query/documents.js';
9
+ export { getInvitesQueryKey, getPendingInvitesQueryKey, } from './lib/react-query/invites.js';
10
+ export { getMapsQueryKey, getStyleJsonUrlQueryKey, } from './lib/react-query/maps.js';
11
+ export { getAttachmentUrlQueryKey, getDocumentCreatedByQueryKey, getIconUrlQueryKey, getMemberByIdQueryKey, getMembersQueryKey, getProjectByIdQueryKey, getProjectRoleQueryKey, getProjectSettingsQueryKey, getProjectsQueryKey, } from './lib/react-query/projects.js';
12
+ export { ROOT_QUERY_KEY } from './lib/react-query/shared.js';