@comapeo/core-react 1.0.1 → 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.
- package/dist/commonjs/contexts/ClientApi.d.ts +14 -0
- package/dist/commonjs/contexts/ClientApi.js +16 -0
- package/dist/commonjs/hooks/client.d.ts +80 -0
- package/dist/commonjs/hooks/client.js +91 -0
- package/dist/{hooks → commonjs/hooks}/documents.d.ts +60 -5
- package/dist/commonjs/hooks/documents.js +192 -0
- package/dist/commonjs/hooks/invites.d.ts +51 -0
- package/dist/commonjs/hooks/invites.js +50 -0
- package/dist/commonjs/hooks/maps.js +37 -0
- package/dist/commonjs/hooks/projects.d.ts +334 -0
- package/dist/commonjs/hooks/projects.js +320 -0
- package/dist/commonjs/index.d.ts +12 -0
- package/dist/commonjs/index.js +69 -0
- package/dist/commonjs/lib/react-query/client.d.ts +61 -0
- package/dist/commonjs/lib/react-query/client.js +68 -0
- package/dist/{lib → commonjs/lib}/react-query/documents.d.ts +789 -706
- package/dist/commonjs/lib/react-query/documents.js +149 -0
- package/dist/commonjs/lib/react-query/invites.d.ts +71 -0
- package/dist/commonjs/lib/react-query/invites.js +85 -0
- package/dist/commonjs/lib/react-query/maps.d.ts +24 -0
- package/dist/commonjs/lib/react-query/maps.js +27 -0
- package/dist/commonjs/lib/react-query/projects.d.ts +332 -0
- package/dist/commonjs/lib/react-query/projects.js +235 -0
- package/dist/{lib → commonjs/lib}/react-query/shared.d.ts +5 -1
- package/dist/commonjs/lib/react-query/shared.js +23 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/{contexts → esm/contexts}/ClientApi.d.ts +3 -3
- package/dist/{hooks → esm/hooks}/client.d.ts +23 -2
- package/dist/{hooks → esm/hooks}/client.js +21 -3
- package/dist/esm/hooks/documents.d.ts +167 -0
- package/dist/{hooks → esm/hooks}/documents.js +54 -3
- package/dist/esm/hooks/invites.d.ts +51 -0
- package/dist/esm/hooks/invites.js +44 -0
- package/dist/esm/hooks/maps.d.ts +33 -0
- package/dist/{hooks → esm/hooks}/maps.js +2 -2
- package/dist/{hooks → esm/hooks}/projects.d.ts +89 -6
- package/dist/{hooks → esm/hooks}/projects.js +59 -3
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/lib/react-query/client.d.ts +61 -0
- package/dist/esm/lib/react-query/client.js +59 -0
- package/dist/esm/lib/react-query/documents.d.ts +1584 -0
- package/dist/{lib → esm/lib}/react-query/documents.js +56 -2
- package/dist/esm/lib/react-query/invites.d.ts +71 -0
- package/dist/esm/lib/react-query/invites.js +76 -0
- package/dist/esm/lib/react-query/maps.d.ts +24 -0
- package/dist/{lib → esm/lib}/react-query/maps.js +6 -2
- package/dist/esm/lib/react-query/projects.d.ts +332 -0
- package/dist/{lib → esm/lib}/react-query/projects.js +84 -2
- package/dist/esm/lib/react-query/shared.d.ts +9 -0
- package/dist/{lib → esm/lib}/react-query/shared.js +7 -1
- package/dist/esm/package.json +3 -0
- package/docs/API.md +157 -258
- package/package.json +51 -37
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -11
- package/dist/lib/react-query/client.d.ts +0 -30
- package/dist/lib/react-query/client.js +0 -29
- package/dist/lib/react-query/invites.d.ts +0 -12
- package/dist/lib/react-query/invites.js +0 -17
- package/dist/lib/react-query/maps.d.ts +0 -15
- package/dist/lib/react-query/projects.d.ts +0 -196
- /package/dist/{hooks → commonjs/hooks}/maps.d.ts +0 -0
- /package/dist/{contexts → esm/contexts}/ClientApi.js +0 -0
|
@@ -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
|
-
import { ClientApiContext } from '../contexts/ClientApi';
|
|
4
|
-
import { deviceInfoQueryOptions, isArchiveDeviceQueryOptions, } from '../lib/react-query/client';
|
|
3
|
+
import { ClientApiContext } from '../contexts/ClientApi.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
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { MapeoDoc } from '@comapeo/schema' with { 'resolution-mode': 'import' };
|
|
2
|
+
import { type WriteableDocumentType } from '../lib/react-query/documents.js';
|
|
3
|
+
type ReadHookResult<D> = {
|
|
4
|
+
data: D;
|
|
5
|
+
error: Error | null;
|
|
6
|
+
isRefetching: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Retrieve a single document from the database based on the document's document ID.
|
|
10
|
+
*
|
|
11
|
+
* Triggers the closest error boundary if the document cannot be found
|
|
12
|
+
*
|
|
13
|
+
* @param opts.projectId Project public ID
|
|
14
|
+
* @param opts.docType Document type of interest
|
|
15
|
+
* @param opts.docId Document ID
|
|
16
|
+
* @param opts.lang Language to translate the document into
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* function SingleDocumentByDocIdExample() {
|
|
21
|
+
* const { data } = useSingleDocByDocId({
|
|
22
|
+
* projectId: '...',
|
|
23
|
+
* docType: 'observation',
|
|
24
|
+
* docId: '...',
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* console.log(data.schemaName) // logs 'observation'
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useSingleDocByDocId<D extends WriteableDocumentType>({ projectId, docType, docId, lang, }: {
|
|
32
|
+
projectId: string;
|
|
33
|
+
docType: D;
|
|
34
|
+
docId: string;
|
|
35
|
+
lang?: string;
|
|
36
|
+
}): ReadHookResult<Extract<MapeoDoc, {
|
|
37
|
+
schemaName: D;
|
|
38
|
+
}>>;
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve a single document from the database based on the document's version ID.
|
|
41
|
+
*
|
|
42
|
+
* Triggers the closest error boundary if the document cannot be found.
|
|
43
|
+
*
|
|
44
|
+
* @param opts.projectId Project public ID
|
|
45
|
+
* @param opts.docType Document type of interest
|
|
46
|
+
* @param opts.versionId Document's version ID
|
|
47
|
+
* @param opts.lang Language to translate the document into
|
|
48
|
+
*
|
|
49
|
+
* * @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* function SingleDocumentByVersionIdExample() {
|
|
52
|
+
* const { data } = useSingleDocByVersionId({
|
|
53
|
+
* projectId: '...',
|
|
54
|
+
* docType: 'observation',
|
|
55
|
+
* docId: '...',
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* console.log(data.schemaName) // logs 'observation'
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function useSingleDocByVersionId<D extends WriteableDocumentType>({ projectId, docType, versionId, lang, }: {
|
|
63
|
+
projectId: string;
|
|
64
|
+
docType: D;
|
|
65
|
+
versionId: string;
|
|
66
|
+
lang?: string;
|
|
67
|
+
}): ReadHookResult<Extract<MapeoDoc, {
|
|
68
|
+
schemaName: D;
|
|
69
|
+
}>>;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieve all documents of a specific `docType`.
|
|
72
|
+
*
|
|
73
|
+
* @param opts.projectId Project public ID
|
|
74
|
+
* @param opts.docType Document type of interest
|
|
75
|
+
* @param opts.includeDeleted Include documents that have been marked as deleted
|
|
76
|
+
* @param opts.lang Language to translate the documents into
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* function BasicExample() {
|
|
81
|
+
* const { data } = useManyDocs({
|
|
82
|
+
* projectId: '...',
|
|
83
|
+
* docType: 'observations',
|
|
84
|
+
* })
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* ```tsx
|
|
89
|
+
* function useAllObservations(opts) {
|
|
90
|
+
* return useManyDocs({
|
|
91
|
+
* ...opts,
|
|
92
|
+
* docType: 'observations',
|
|
93
|
+
* })
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* function useAllPresets(opts) {
|
|
97
|
+
* return useManyDocs({
|
|
98
|
+
* ...opts,
|
|
99
|
+
* docType: 'presets',
|
|
100
|
+
* })
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function useManyDocs<D extends WriteableDocumentType>({ projectId, docType, includeDeleted, lang, }: {
|
|
105
|
+
projectId: string;
|
|
106
|
+
docType: D;
|
|
107
|
+
includeDeleted?: boolean;
|
|
108
|
+
lang?: string;
|
|
109
|
+
}): ReadHookResult<Extract<MapeoDoc, {
|
|
110
|
+
schemaName: D;
|
|
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
|
+
};
|
|
167
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
2
|
-
import { documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, } from '../lib/react-query/documents';
|
|
3
|
-
import { useSingleProject } from './projects';
|
|
1
|
+
import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
|
|
2
|
+
import { createDocumentMutationOptions, deleteDocumentMutationOptions, documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, updateDocumentMutationOptions, } from '../lib/react-query/documents.js';
|
|
3
|
+
import { useSingleProject } from './projects.js';
|
|
4
4
|
/**
|
|
5
5
|
* Retrieve a single document from the database based on the document's document ID.
|
|
6
6
|
*
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a URL that points to a StyleJSON resource served by the embedded HTTP server.
|
|
3
|
+
*
|
|
4
|
+
* If `opts.refreshToken` is specified, it will be appended to the returned URL as a search param. This is useful for forcing cache busting
|
|
5
|
+
* due to hidden internal details by consuming components (e.g. map component from MapLibre).
|
|
6
|
+
*
|
|
7
|
+
* @param opts.refreshToken String to append to the returned value as a search param
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function ExampleWithoutRefreshToken() {
|
|
12
|
+
* const { data, isRefetching } = useMapStyleUrl()
|
|
13
|
+
*
|
|
14
|
+
* console.log(data) // logs something like 'http://localhost:...'
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ```tsx
|
|
19
|
+
* function ExampleWithRefreshToken() {
|
|
20
|
+
* const [refreshToken] = useState('foo')
|
|
21
|
+
* const { data } = useMapStyleUrl({ refreshToken })
|
|
22
|
+
*
|
|
23
|
+
* console.log(data) // logs something like 'http://localhost:...?refresh_token=foo'
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useMapStyleUrl({ refreshToken, }?: {
|
|
28
|
+
refreshToken?: string;
|
|
29
|
+
}): {
|
|
30
|
+
data: string;
|
|
31
|
+
error: Error | null;
|
|
32
|
+
isRefetching: boolean;
|
|
33
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
2
|
-
import { mapStyleJsonUrlQueryOptions } from '../lib/react-query/maps';
|
|
3
|
-
import { useClientApi } from './client';
|
|
2
|
+
import { mapStyleJsonUrlQueryOptions } from '../lib/react-query/maps.js';
|
|
3
|
+
import { useClientApi } from './client.js';
|
|
4
4
|
/**
|
|
5
5
|
* Get a URL that points to a StyleJSON resource served by the embedded HTTP server.
|
|
6
6
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BitmapOpts, SvgOpts } from '@comapeo/core/dist/icon-api';
|
|
2
|
-
import type { BlobId } from '@comapeo/core/dist/types';
|
|
1
|
+
import type { BitmapOpts, SvgOpts } from '@comapeo/core/dist/icon-api.js' with { 'resolution-mode': 'import' };
|
|
2
|
+
import type { BlobId } from '@comapeo/core/dist/types.js' with { 'resolution-mode': 'import' };
|
|
3
3
|
/**
|
|
4
4
|
* Retrieve the project settings for a project.
|
|
5
5
|
*
|
|
@@ -17,7 +17,7 @@ import type { BlobId } from '@comapeo/core/dist/types';
|
|
|
17
17
|
export declare function useProjectSettings({ projectId }: {
|
|
18
18
|
projectId: string;
|
|
19
19
|
}): {
|
|
20
|
-
data: import("@comapeo/core/dist/mapeo-project").EditableProjectSettings;
|
|
20
|
+
data: import("@comapeo/core/dist/mapeo-project.js").EditableProjectSettings;
|
|
21
21
|
error: Error | null;
|
|
22
22
|
isRefetching: boolean;
|
|
23
23
|
};
|
|
@@ -38,7 +38,7 @@ export declare function useProjectSettings({ projectId }: {
|
|
|
38
38
|
export declare function useSingleProject({ projectId }: {
|
|
39
39
|
projectId: string;
|
|
40
40
|
}): {
|
|
41
|
-
data: import("rpc-reflector/lib/types").ClientApi<import("@comapeo/core/dist/mapeo-project").MapeoProject>;
|
|
41
|
+
data: import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js").MapeoProject>;
|
|
42
42
|
error: Error | null;
|
|
43
43
|
isRefetching: boolean;
|
|
44
44
|
};
|
|
@@ -98,7 +98,7 @@ export declare function useSingleMember({ projectId, deviceId, }: {
|
|
|
98
98
|
projectId: string;
|
|
99
99
|
deviceId: string;
|
|
100
100
|
}): {
|
|
101
|
-
data: import("@comapeo/core/dist/member-api").MemberInfo;
|
|
101
|
+
data: import("@comapeo/core/dist/member-api.js").MemberInfo;
|
|
102
102
|
error: Error | null;
|
|
103
103
|
isRefetching: boolean;
|
|
104
104
|
};
|
|
@@ -119,7 +119,7 @@ export declare function useSingleMember({ projectId, deviceId, }: {
|
|
|
119
119
|
export declare function useManyMembers({ projectId }: {
|
|
120
120
|
projectId: string;
|
|
121
121
|
}): {
|
|
122
|
-
data: import("@comapeo/core/dist/member-api").MemberInfo[];
|
|
122
|
+
data: import("@comapeo/core/dist/member-api.js").MemberInfo[];
|
|
123
123
|
error: Error | null;
|
|
124
124
|
isRefetching: boolean;
|
|
125
125
|
};
|
|
@@ -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,6 +1,6 @@
|
|
|
1
|
-
import { useSuspenseQuery } from '@tanstack/react-query';
|
|
2
|
-
import { attachmentUrlQueryOptions, documentCreatedByQueryOptions, iconUrlQueryOptions, projectByIdQueryOptions, projectMemberByIdQueryOptions, projectMembersQueryOptions, projectSettingsQueryOptions, projectsQueryOptions, } from '../lib/react-query/projects';
|
|
3
|
-
import { useClientApi } from './client';
|
|
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
|
+
import { useClientApi } from './client.js';
|
|
4
4
|
/**
|
|
5
5
|
* Retrieve the project settings for a project.
|
|
6
6
|
*
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.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';
|
|
5
|
+
export { useMapStyleUrl } from './hooks/maps.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';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.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';
|
|
5
|
+
export { useMapStyleUrl } from './hooks/maps.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';
|