@comapeo/core-react 9.0.1 → 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 +98 -219
  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 +98 -219
  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 -72
  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 -72
  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,316 +0,0 @@
1
- import type { BlobApi, MemberApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with {
3
- 'resolution-mode': 'import'
4
- };
5
- import { type QueryClient, type UnusedSkipTokenOptions } from '@tanstack/react-query';
6
- export declare function getProjectsQueryKey(): readonly ["@comapeo/core-react", "projects"];
7
- export declare function getProjectByIdQueryKey({ projectId }: {
8
- projectId: string;
9
- }): readonly ["@comapeo/core-react", "projects", string];
10
- export declare function getProjectSettingsQueryKey({ projectId, }: {
11
- projectId: string;
12
- }): readonly ["@comapeo/core-react", "projects", string, "project_settings"];
13
- export declare function getProjectRoleQueryKey({ projectId }: {
14
- projectId: string;
15
- }): readonly ["@comapeo/core-react", "projects", string, "role"];
16
- export declare function getMembersQueryKey({ projectId }: {
17
- projectId: string;
18
- }): readonly ["@comapeo/core-react", "projects", string, "members"];
19
- export declare function getMemberByIdQueryKey({ projectId, deviceId, }: {
20
- projectId: string;
21
- deviceId: string;
22
- }): readonly ["@comapeo/core-react", "projects", string, "members", string];
23
- export declare function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }: {
24
- projectId: string;
25
- originalVersionId: string;
26
- }): readonly ["@comapeo/core-react", "projects", string, "document_created_by", string];
27
- /**
28
- * We call this within a project hook, because that's the only place the API is
29
- * exposed right now, but it is the same for all projects, so no need for
30
- * scoping the query key to the project
31
- */
32
- export declare function getMediaServerOriginQueryKey(): readonly ["@comapeo/core-react", "media_server_origin"];
33
- export declare function projectsQueryOptions({ clientApi, }: {
34
- clientApi: MapeoClientApi;
35
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/mapeo-manager.js").ListedProject[], Error, import("@comapeo/core/dist/mapeo-manager.js").ListedProject[], readonly ["@comapeo/core-react", "projects"]>, "queryFn"> & {
36
- queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/mapeo-manager.js").ListedProject[], readonly ["@comapeo/core-react", "projects"], never> | undefined;
37
- } & {
38
- queryKey: readonly ["@comapeo/core-react", "projects"] & {
39
- [dataTagSymbol]: import("@comapeo/core/dist/mapeo-manager.js").ListedProject[];
40
- [dataTagErrorSymbol]: Error;
41
- };
42
- };
43
- export declare function projectByIdQueryOptions({ clientApi, projectId, }: {
44
- clientApi: MapeoClientApi;
45
- projectId: string;
46
- }): UnusedSkipTokenOptions<MapeoProjectApi, Error, MapeoProjectApi, ReturnType<typeof getProjectByIdQueryKey>>;
47
- export declare function projectSettingsQueryOptions({ projectApi, projectId, }: {
48
- projectApi: MapeoProjectApi;
49
- projectId: string;
50
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings, Error, import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings, readonly ["@comapeo/core-react", "projects", string, "project_settings"]>, "queryFn"> & {
51
- queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings, readonly ["@comapeo/core-react", "projects", string, "project_settings"], never> | undefined;
52
- } & {
53
- queryKey: readonly ["@comapeo/core-react", "projects", string, "project_settings"] & {
54
- [dataTagSymbol]: import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings;
55
- [dataTagErrorSymbol]: Error;
56
- };
57
- };
58
- export declare function projectMembersQueryOptions({ projectApi, projectId, }: {
59
- projectApi: MapeoProjectApi;
60
- projectId: string;
61
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/member-api.js").MemberInfo[], Error, import("@comapeo/core/dist/member-api.js").MemberInfo[], readonly ["@comapeo/core-react", "projects", string, "members"]>, "queryFn"> & {
62
- queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/member-api.js").MemberInfo[], readonly ["@comapeo/core-react", "projects", string, "members"], never> | undefined;
63
- } & {
64
- queryKey: readonly ["@comapeo/core-react", "projects", string, "members"] & {
65
- [dataTagSymbol]: import("@comapeo/core/dist/member-api.js").MemberInfo[];
66
- [dataTagErrorSymbol]: Error;
67
- };
68
- };
69
- export declare function projectMemberByIdQueryOptions({ projectApi, projectId, deviceId, }: {
70
- projectApi: MapeoProjectApi;
71
- projectId: string;
72
- deviceId: string;
73
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/member-api.js").MemberInfo, Error, import("@comapeo/core/dist/member-api.js").MemberInfo, readonly ["@comapeo/core-react", "projects", string, "members", string]>, "queryFn"> & {
74
- queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/member-api.js").MemberInfo, readonly ["@comapeo/core-react", "projects", string, "members", string], never> | undefined;
75
- } & {
76
- queryKey: readonly ["@comapeo/core-react", "projects", string, "members", string] & {
77
- [dataTagSymbol]: import("@comapeo/core/dist/member-api.js").MemberInfo;
78
- [dataTagErrorSymbol]: Error;
79
- };
80
- };
81
- export declare function projectOwnRoleQueryOptions({ projectApi, projectId, }: {
82
- projectApi: MapeoProjectApi;
83
- projectId: string;
84
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/roles.js").Role & {
85
- reason: string | undefined;
86
- }, Error, import("@comapeo/core/dist/roles.js").Role & {
87
- reason: string | undefined;
88
- }, readonly ["@comapeo/core-react", "projects", string, "role"]>, "queryFn"> & {
89
- queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/roles.js").Role & {
90
- reason: string | undefined;
91
- }, readonly ["@comapeo/core-react", "projects", string, "role"], never> | undefined;
92
- } & {
93
- queryKey: readonly ["@comapeo/core-react", "projects", string, "role"] & {
94
- [dataTagSymbol]: import("@comapeo/core/dist/roles.js").Role & {
95
- reason: string | undefined;
96
- };
97
- [dataTagErrorSymbol]: Error;
98
- };
99
- };
100
- export declare function documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId, }: {
101
- projectApi: MapeoProjectApi;
102
- projectId: string;
103
- originalVersionId: string;
104
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "projects", string, "document_created_by", string]>, "queryFn"> & {
105
- queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "projects", string, "document_created_by", string], never> | undefined;
106
- } & {
107
- queryKey: readonly ["@comapeo/core-react", "projects", string, "document_created_by", string] & {
108
- [dataTagSymbol]: string;
109
- [dataTagErrorSymbol]: Error;
110
- };
111
- };
112
- export declare function mediaServerOriginQueryOptions({ projectApi, }: {
113
- projectApi: MapeoProjectApi;
114
- }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "media_server_origin"]>, "queryFn"> & {
115
- queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "media_server_origin"], never> | undefined;
116
- } & {
117
- queryKey: readonly ["@comapeo/core-react", "media_server_origin"] & {
118
- [dataTagSymbol]: string;
119
- [dataTagErrorSymbol]: Error;
120
- };
121
- };
122
- export declare function addServerPeerMutationOptions({ projectApi, projectId, queryClient, }: {
123
- projectApi: MapeoProjectApi;
124
- projectId: string;
125
- queryClient: QueryClient;
126
- }): {
127
- mutationFn: ({ baseUrl, dangerouslyAllowInsecureConnections }: {
128
- baseUrl: string;
129
- dangerouslyAllowInsecureConnections?: boolean;
130
- }) => Promise<void>;
131
- onSuccess: () => void;
132
- networkMode: "always";
133
- retry: false;
134
- };
135
- export declare function removeServerPeerMutationOptions({ projectApi, projectId, queryClient, }: {
136
- projectApi: MapeoProjectApi;
137
- projectId: string;
138
- queryClient: QueryClient;
139
- }): {
140
- mutationFn: ({ serverDeviceId, dangerouslyAllowInsecureConnections, }: {
141
- serverDeviceId: string;
142
- dangerouslyAllowInsecureConnections?: boolean;
143
- }) => Promise<void>;
144
- onSuccess: () => void;
145
- networkMode: "always";
146
- retry: false;
147
- };
148
- export declare function createProjectMutationOptions({ clientApi, queryClient, }: {
149
- clientApi: MapeoClientApi;
150
- queryClient: QueryClient;
151
- }): {
152
- mutationFn: (opts: {
153
- name?: string;
154
- configPath?: string;
155
- projectColor?: string;
156
- projectDescription?: string;
157
- } | undefined) => Promise<string>;
158
- onSuccess: () => void;
159
- networkMode: "always";
160
- retry: false;
161
- };
162
- export declare function leaveProjectMutationOptions({ clientApi, queryClient, }: {
163
- clientApi: MapeoClientApi;
164
- queryClient: QueryClient;
165
- }): {
166
- mutationFn: ({ projectId }: {
167
- projectId: string;
168
- }) => Promise<void>;
169
- onSuccess: () => void;
170
- networkMode: "always";
171
- retry: false;
172
- };
173
- export declare function importProjectCategoriesMutationOptions({ projectApi, projectId, queryClient, }: {
174
- projectApi: MapeoProjectApi;
175
- projectId: string;
176
- queryClient: QueryClient;
177
- }): {
178
- mutationFn: ({ filePath }: {
179
- filePath: string;
180
- }) => Promise<void>;
181
- onSuccess: () => void;
182
- networkMode: "always";
183
- retry: false;
184
- };
185
- export declare function importProjectConfigMutationOptions({ projectApi, projectId, queryClient, }: {
186
- projectApi: MapeoProjectApi;
187
- projectId: string;
188
- queryClient: QueryClient;
189
- }): {
190
- mutationFn: ({ configPath }: {
191
- configPath: string;
192
- }) => Promise<Error[]>;
193
- onSuccess: () => void;
194
- networkMode: "always";
195
- retry: false;
196
- };
197
- export declare function updateProjectSettingsMutationOptions({ projectApi, queryClient, }: {
198
- projectApi: MapeoProjectApi;
199
- queryClient: QueryClient;
200
- }): {
201
- mutationFn: (value: Partial<import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings>) => Promise<import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings>;
202
- onSuccess: () => void;
203
- networkMode: "always";
204
- retry: false;
205
- };
206
- export declare function changeMemberRoleMutationOptions({ projectApi, projectId, queryClient, }: {
207
- projectApi: MapeoProjectApi;
208
- projectId: string;
209
- queryClient: QueryClient;
210
- }): {
211
- mutationFn: ({ deviceId, roleId }: {
212
- deviceId: string;
213
- roleId: MemberApi.RoleIdAssignableToOthers;
214
- }) => Promise<void>;
215
- onSuccess: () => void;
216
- networkMode: "always";
217
- retry: false;
218
- };
219
- export declare function removeProjectMemberMutationOptions({ projectApi, projectId, queryClient, }: {
220
- projectApi: MapeoProjectApi;
221
- projectId: string;
222
- queryClient: QueryClient;
223
- }): {
224
- mutationFn: ({ deviceId, reason }: {
225
- deviceId: string;
226
- reason?: string;
227
- }) => Promise<void>;
228
- onSuccess: () => void;
229
- networkMode: "always";
230
- retry: false;
231
- };
232
- export declare function createBlobMutationOptions({ projectApi, }: {
233
- projectApi: MapeoProjectApi;
234
- }): {
235
- mutationFn: ({ original, preview, thumbnail, metadata }: {
236
- original: string;
237
- preview?: string;
238
- thumbnail?: string;
239
- metadata: BlobApi.Metadata;
240
- }) => Promise<{
241
- driveId: string;
242
- name: string;
243
- type: "photo" | "video" | "audio";
244
- hash: string;
245
- }>;
246
- networkMode: "always";
247
- retry: false;
248
- };
249
- export declare function startSyncMutationOptions({ projectApi, }: {
250
- projectApi: MapeoProjectApi;
251
- }): {
252
- mutationFn: (opts: {
253
- autostopDataSyncAfter: number | null;
254
- } | undefined) => Promise<void>;
255
- networkMode: "always";
256
- retry: false;
257
- };
258
- export declare function stopSyncMutationOptions({ projectApi, }: {
259
- projectApi: MapeoProjectApi;
260
- }): {
261
- mutationFn: () => Promise<void>;
262
- networkMode: "always";
263
- retry: false;
264
- };
265
- export declare function connectSyncServersMutationOptions({ projectApi, }: {
266
- projectApi: MapeoProjectApi;
267
- }): {
268
- mutationFn: () => Promise<void>;
269
- networkMode: "always";
270
- retry: false;
271
- };
272
- export declare function disconnectSyncServersMutationOptions({ projectApi, }: {
273
- projectApi: MapeoProjectApi;
274
- }): {
275
- mutationFn: () => Promise<void>;
276
- networkMode: "always";
277
- retry: false;
278
- };
279
- export declare function setAutostopDataSyncTimeoutMutationOptions({ projectApi, }: {
280
- projectApi: MapeoProjectApi;
281
- }): {
282
- mutationFn: ({ after }: {
283
- after: number | null;
284
- }) => Promise<void>;
285
- networkMode: "always";
286
- retry: false;
287
- };
288
- export declare function exportGeoJSONMutationOptions({ projectApi, }: {
289
- projectApi: MapeoProjectApi;
290
- }): {
291
- mutationFn: (opts: {
292
- path: string;
293
- exportOptions: {
294
- observations?: boolean;
295
- tracks?: boolean;
296
- lang?: string;
297
- };
298
- }) => Promise<string>;
299
- networkMode: "always";
300
- retry: false;
301
- };
302
- export declare function exportZipFileMutationOptions({ projectApi, }: {
303
- projectApi: MapeoProjectApi;
304
- }): {
305
- mutationFn: (opts: {
306
- path: string;
307
- exportOptions: {
308
- observations?: boolean;
309
- tracks?: boolean;
310
- lang?: string;
311
- attachments?: boolean;
312
- };
313
- }) => Promise<string>;
314
- networkMode: "always";
315
- retry: false;
316
- };
@@ -1,324 +0,0 @@
1
- import { queryOptions, } from '@tanstack/react-query';
2
- import { baseMutationOptions, baseQueryOptions, ROOT_QUERY_KEY, } from './shared.js';
3
- export function getProjectsQueryKey() {
4
- return [ROOT_QUERY_KEY, 'projects'];
5
- }
6
- export function getProjectByIdQueryKey({ projectId }) {
7
- return [ROOT_QUERY_KEY, 'projects', projectId];
8
- }
9
- export function getProjectSettingsQueryKey({ projectId, }) {
10
- return [ROOT_QUERY_KEY, 'projects', projectId, 'project_settings'];
11
- }
12
- export function getProjectRoleQueryKey({ projectId }) {
13
- return [ROOT_QUERY_KEY, 'projects', projectId, 'role'];
14
- }
15
- export function getMembersQueryKey({ projectId }) {
16
- return [ROOT_QUERY_KEY, 'projects', projectId, 'members'];
17
- }
18
- export function getMemberByIdQueryKey({ projectId, deviceId, }) {
19
- return [ROOT_QUERY_KEY, 'projects', projectId, 'members', deviceId];
20
- }
21
- export function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }) {
22
- return [
23
- ROOT_QUERY_KEY,
24
- 'projects',
25
- projectId,
26
- 'document_created_by',
27
- originalVersionId,
28
- ];
29
- }
30
- /**
31
- * We call this within a project hook, because that's the only place the API is
32
- * exposed right now, but it is the same for all projects, so no need for
33
- * scoping the query key to the project
34
- */
35
- export function getMediaServerOriginQueryKey() {
36
- return [ROOT_QUERY_KEY, 'media_server_origin'];
37
- }
38
- export function projectsQueryOptions({ clientApi, }) {
39
- return queryOptions({
40
- ...baseQueryOptions(),
41
- queryKey: getProjectsQueryKey(),
42
- queryFn: async () => {
43
- return clientApi.listProjects();
44
- },
45
- });
46
- }
47
- export function projectByIdQueryOptions({ clientApi, projectId, }) {
48
- return queryOptions({
49
- ...baseQueryOptions(),
50
- queryKey: getProjectByIdQueryKey({ projectId }),
51
- queryFn: async () => {
52
- return clientApi.getProject(projectId);
53
- },
54
- });
55
- }
56
- export function projectSettingsQueryOptions({ projectApi, projectId, }) {
57
- return queryOptions({
58
- ...baseQueryOptions(),
59
- queryKey: getProjectSettingsQueryKey({ projectId }),
60
- queryFn: async () => {
61
- return projectApi.$getProjectSettings();
62
- },
63
- });
64
- }
65
- export function projectMembersQueryOptions({ projectApi, projectId, }) {
66
- return queryOptions({
67
- ...baseQueryOptions(),
68
- queryKey: getMembersQueryKey({ projectId }),
69
- queryFn: async () => {
70
- return projectApi.$member.getMany();
71
- },
72
- });
73
- }
74
- export function projectMemberByIdQueryOptions({ projectApi, projectId, deviceId, }) {
75
- return queryOptions({
76
- ...baseQueryOptions(),
77
- queryKey: getMemberByIdQueryKey({ projectId, deviceId }),
78
- queryFn: async () => {
79
- return projectApi.$member.getById(deviceId);
80
- },
81
- });
82
- }
83
- export function projectOwnRoleQueryOptions({ projectApi, projectId, }) {
84
- return queryOptions({
85
- ...baseQueryOptions(),
86
- queryKey: getProjectRoleQueryKey({ projectId }),
87
- queryFn: async () => {
88
- return projectApi.$getOwnRole();
89
- },
90
- });
91
- }
92
- export function documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId, }) {
93
- return queryOptions({
94
- ...baseQueryOptions(),
95
- queryKey: getDocumentCreatedByQueryKey({
96
- projectId,
97
- originalVersionId,
98
- }),
99
- queryFn: async () => {
100
- return projectApi.$originalVersionIdToDeviceId(originalVersionId);
101
- },
102
- staleTime: 'static',
103
- gcTime: Infinity,
104
- });
105
- }
106
- // Used as a placeholder so that we can read the server port from the $blobs.getUrl() method
107
- const FAKE_BLOB_ID = {
108
- type: 'photo',
109
- variant: 'original',
110
- name: 'name',
111
- driveId: 'drive-id',
112
- };
113
- export function mediaServerOriginQueryOptions({ projectApi, }) {
114
- return queryOptions({
115
- ...baseQueryOptions(),
116
- // HACK: The server doesn't yet expose a method to get its origin, so we use
117
- // the existing $blobs.getUrl() to get the origin with a fake BlobId. The origin
118
- // is the same regardless of the blobId, so it's not necessary to include it
119
- // as a dep for the query key.
120
- queryKey: getMediaServerOriginQueryKey(),
121
- queryFn: async () => {
122
- const url = await projectApi.$blobs.getUrl(FAKE_BLOB_ID);
123
- return new URL(url).origin;
124
- },
125
- staleTime: 'static',
126
- gcTime: Infinity,
127
- });
128
- }
129
- export function addServerPeerMutationOptions({ projectApi, projectId, queryClient, }) {
130
- return {
131
- ...baseMutationOptions(),
132
- mutationFn: async ({ baseUrl, dangerouslyAllowInsecureConnections }) => {
133
- return projectApi.$member.addServerPeer(baseUrl, {
134
- dangerouslyAllowInsecureConnections,
135
- });
136
- },
137
- onSuccess: () => {
138
- queryClient.invalidateQueries({
139
- queryKey: getMembersQueryKey({ projectId }),
140
- });
141
- },
142
- };
143
- }
144
- export function removeServerPeerMutationOptions({ projectApi, projectId, queryClient, }) {
145
- return {
146
- ...baseMutationOptions(),
147
- mutationFn: async ({ serverDeviceId, dangerouslyAllowInsecureConnections, }) => {
148
- return projectApi.$member.removeServerPeer(serverDeviceId, {
149
- dangerouslyAllowInsecureConnections,
150
- });
151
- },
152
- onSuccess: () => {
153
- queryClient.invalidateQueries({
154
- queryKey: getMembersQueryKey({ projectId }),
155
- });
156
- },
157
- };
158
- }
159
- export function createProjectMutationOptions({ clientApi, queryClient, }) {
160
- return {
161
- ...baseMutationOptions(),
162
- mutationFn: async (opts) => {
163
- // Have to avoid passing `undefined` explicitly
164
- // See https://github.com/digidem/rpc-reflector/issues/21
165
- return opts ? clientApi.createProject(opts) : clientApi.createProject();
166
- },
167
- onSuccess: () => {
168
- queryClient.invalidateQueries({
169
- queryKey: getProjectsQueryKey(),
170
- });
171
- },
172
- };
173
- }
174
- export function leaveProjectMutationOptions({ clientApi, queryClient, }) {
175
- return {
176
- ...baseMutationOptions(),
177
- mutationFn: async ({ projectId }) => {
178
- return clientApi.leaveProject(projectId);
179
- },
180
- onSuccess: () => {
181
- queryClient.invalidateQueries({
182
- queryKey: getProjectsQueryKey(),
183
- });
184
- },
185
- };
186
- }
187
- export function importProjectCategoriesMutationOptions({ projectApi, projectId, queryClient, }) {
188
- return {
189
- ...baseMutationOptions(),
190
- mutationFn: ({ filePath }) => {
191
- return projectApi.$importCategories({ filePath });
192
- },
193
- onSuccess: () => {
194
- queryClient.invalidateQueries({
195
- queryKey: getProjectByIdQueryKey({ projectId }),
196
- });
197
- },
198
- };
199
- }
200
- export function importProjectConfigMutationOptions({ projectApi, projectId, queryClient, }) {
201
- return {
202
- ...baseMutationOptions(),
203
- mutationFn: ({ configPath }) => {
204
- return projectApi.importConfig({ configPath });
205
- },
206
- onSuccess: () => {
207
- queryClient.invalidateQueries({
208
- queryKey: getProjectByIdQueryKey({ projectId }),
209
- });
210
- },
211
- };
212
- }
213
- export function updateProjectSettingsMutationOptions({ projectApi, queryClient, }) {
214
- return {
215
- ...baseMutationOptions(),
216
- mutationFn: async (value) => {
217
- return projectApi.$setProjectSettings(value);
218
- },
219
- onSuccess: () => {
220
- queryClient.invalidateQueries({
221
- queryKey: getProjectsQueryKey(),
222
- });
223
- },
224
- };
225
- }
226
- export function changeMemberRoleMutationOptions({ projectApi, projectId, queryClient, }) {
227
- return {
228
- ...baseMutationOptions(),
229
- mutationFn: async ({ deviceId, roleId }) => {
230
- return projectApi.$member.assignRole(deviceId, roleId);
231
- },
232
- onSuccess: () => {
233
- queryClient.invalidateQueries({
234
- queryKey: getMembersQueryKey({ projectId }),
235
- });
236
- queryClient.invalidateQueries({
237
- queryKey: getProjectRoleQueryKey({ projectId }),
238
- });
239
- },
240
- };
241
- }
242
- export function removeProjectMemberMutationOptions({ projectApi, projectId, queryClient, }) {
243
- return {
244
- ...baseMutationOptions(),
245
- mutationFn: async ({ deviceId, reason }) => {
246
- // Have to avoid passing `undefined` explicitly
247
- // See https://github.com/digidem/rpc-reflector/issues/21
248
- return reason
249
- ? projectApi.$member.remove(deviceId, { reason })
250
- : projectApi.$member.remove(deviceId);
251
- },
252
- onSuccess: () => {
253
- queryClient.invalidateQueries({
254
- queryKey: getMembersQueryKey({ projectId }),
255
- });
256
- },
257
- };
258
- }
259
- export function createBlobMutationOptions({ projectApi, }) {
260
- return {
261
- ...baseMutationOptions(),
262
- mutationFn: async ({ original, preview, thumbnail, metadata }) => {
263
- return projectApi.$blobs.create({ original, preview, thumbnail }, metadata);
264
- },
265
- };
266
- }
267
- export function startSyncMutationOptions({ projectApi, }) {
268
- return {
269
- ...baseMutationOptions(),
270
- mutationFn: async (opts) => {
271
- // Have to avoid passing `undefined` explicitly
272
- // See https://github.com/digidem/rpc-reflector/issues/21
273
- return opts ? projectApi.$sync.start(opts) : projectApi.$sync.start();
274
- },
275
- };
276
- }
277
- export function stopSyncMutationOptions({ projectApi, }) {
278
- return {
279
- ...baseMutationOptions(),
280
- mutationFn: async () => {
281
- return projectApi.$sync.stop();
282
- },
283
- };
284
- }
285
- export function connectSyncServersMutationOptions({ projectApi, }) {
286
- return {
287
- ...baseMutationOptions(),
288
- mutationFn: async () => {
289
- return projectApi.$sync.connectServers();
290
- },
291
- };
292
- }
293
- export function disconnectSyncServersMutationOptions({ projectApi, }) {
294
- return {
295
- ...baseMutationOptions(),
296
- mutationFn: async () => {
297
- return projectApi.$sync.disconnectServers();
298
- },
299
- };
300
- }
301
- export function setAutostopDataSyncTimeoutMutationOptions({ projectApi, }) {
302
- return {
303
- ...baseMutationOptions(),
304
- mutationFn: async ({ after }) => {
305
- return projectApi.$sync.setAutostopDataSyncTimeout(after);
306
- },
307
- };
308
- }
309
- export function exportGeoJSONMutationOptions({ projectApi, }) {
310
- return {
311
- ...baseMutationOptions(),
312
- mutationFn: async (opts) => {
313
- return projectApi.exportGeoJSONFile(opts.path, opts.exportOptions);
314
- },
315
- };
316
- }
317
- export function exportZipFileMutationOptions({ projectApi, }) {
318
- return {
319
- ...baseMutationOptions(),
320
- mutationFn: async (opts) => {
321
- return projectApi.exportZipFile(opts.path, opts.exportOptions);
322
- },
323
- };
324
- }
@@ -1,9 +0,0 @@
1
- export declare const ROOT_QUERY_KEY = "@comapeo/core-react";
2
- export declare function baseQueryOptions(): {
3
- networkMode: "always";
4
- retry: false;
5
- };
6
- export declare function baseMutationOptions(): {
7
- networkMode: "always";
8
- retry: false;
9
- };
@@ -1,18 +0,0 @@
1
- export const ROOT_QUERY_KEY = '@comapeo/core-react';
2
- // Since the API is running locally, queries should run regardless of network
3
- // status, and should not be retried. In React Native the API consumer would
4
- // have to manually set the network mode, but we still should keep these options
5
- // to avoid surprises. Not using the queryClient `defaultOptions` because the API
6
- // consumer might also use the same queryClient for network queries
7
- export function baseQueryOptions() {
8
- return {
9
- networkMode: 'always',
10
- retry: false,
11
- };
12
- }
13
- export function baseMutationOptions() {
14
- return {
15
- networkMode: 'always',
16
- retry: false,
17
- };
18
- }