@comapeo/core-react 3.2.0 → 4.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/hooks/client.d.ts +15 -1
- package/dist/commonjs/hooks/client.js +6 -6
- package/dist/commonjs/hooks/documents.d.ts +32 -0
- package/dist/commonjs/hooks/documents.js +9 -9
- package/dist/commonjs/hooks/invites.d.ts +80 -0
- package/dist/commonjs/hooks/invites.js +78 -12
- package/dist/commonjs/hooks/projects.d.ts +68 -0
- package/dist/commonjs/hooks/projects.js +24 -24
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.js +4 -1
- package/dist/commonjs/lib/react-query/client.d.ts +4 -4
- package/dist/commonjs/lib/react-query/invites.d.ts +22 -9
- package/dist/commonjs/lib/react-query/invites.js +17 -7
- package/dist/esm/hooks/client.d.ts +15 -1
- package/dist/esm/hooks/client.js +6 -6
- package/dist/esm/hooks/documents.d.ts +32 -0
- package/dist/esm/hooks/documents.js +9 -9
- package/dist/esm/hooks/invites.d.ts +80 -0
- package/dist/esm/hooks/invites.js +77 -14
- package/dist/esm/hooks/projects.d.ts +68 -0
- package/dist/esm/hooks/projects.js +24 -24
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/react-query/client.d.ts +4 -4
- package/dist/esm/lib/react-query/invites.d.ts +22 -9
- package/dist/esm/lib/react-query/invites.js +14 -5
- package/docs/API.md +85 -21
- package/package.json +6 -5
|
@@ -37,7 +37,7 @@ export declare function useClientApi(): import("@comapeo/ipc/dist/client.js", {
|
|
|
37
37
|
export declare function useOwnDeviceInfo(): {
|
|
38
38
|
data: {
|
|
39
39
|
deviceId: string;
|
|
40
|
-
deviceType: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "selfHostedServer"
|
|
40
|
+
deviceType: "UNRECOGNIZED" | "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "selfHostedServer";
|
|
41
41
|
} & Partial<import("@comapeo/core/dist/schema/client.js", { with: { "resolution-mode": "import" } }).DeviceInfoParam>;
|
|
42
42
|
error: Error | null;
|
|
43
43
|
isRefetching: boolean;
|
|
@@ -66,6 +66,10 @@ export declare function useSetOwnDeviceInfo(): {
|
|
|
66
66
|
name: string;
|
|
67
67
|
deviceType: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).DeviceInfo["deviceType"];
|
|
68
68
|
}, unknown>;
|
|
69
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
70
|
+
name: string;
|
|
71
|
+
deviceType: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).DeviceInfo["deviceType"];
|
|
72
|
+
}, unknown>;
|
|
69
73
|
reset: () => void;
|
|
70
74
|
status: "error";
|
|
71
75
|
} | {
|
|
@@ -74,6 +78,10 @@ export declare function useSetOwnDeviceInfo(): {
|
|
|
74
78
|
name: string;
|
|
75
79
|
deviceType: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).DeviceInfo["deviceType"];
|
|
76
80
|
}, unknown>;
|
|
81
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
82
|
+
name: string;
|
|
83
|
+
deviceType: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).DeviceInfo["deviceType"];
|
|
84
|
+
}, unknown>;
|
|
77
85
|
reset: () => void;
|
|
78
86
|
status: "pending" | "success" | "idle";
|
|
79
87
|
};
|
|
@@ -85,6 +93,9 @@ export declare function useSetIsArchiveDevice(): {
|
|
|
85
93
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
86
94
|
isArchiveDevice: boolean;
|
|
87
95
|
}, unknown>;
|
|
96
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
97
|
+
isArchiveDevice: boolean;
|
|
98
|
+
}, unknown>;
|
|
88
99
|
reset: () => void;
|
|
89
100
|
status: "error";
|
|
90
101
|
} | {
|
|
@@ -92,6 +103,9 @@ export declare function useSetIsArchiveDevice(): {
|
|
|
92
103
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
93
104
|
isArchiveDevice: boolean;
|
|
94
105
|
}, unknown>;
|
|
106
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
107
|
+
isArchiveDevice: boolean;
|
|
108
|
+
}, unknown>;
|
|
95
109
|
reset: () => void;
|
|
96
110
|
status: "pending" | "success" | "idle";
|
|
97
111
|
};
|
|
@@ -77,10 +77,10 @@ function useIsArchiveDevice() {
|
|
|
77
77
|
function useSetOwnDeviceInfo() {
|
|
78
78
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
79
79
|
const clientApi = useClientApi();
|
|
80
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, client_js_1.setOwnDeviceInfoMutationOptions)({ clientApi, queryClient }));
|
|
80
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, client_js_1.setOwnDeviceInfoMutationOptions)({ clientApi, queryClient }));
|
|
81
81
|
return status === 'error'
|
|
82
|
-
? { error, mutate, reset, status }
|
|
83
|
-
: { error: null, mutate, reset, status };
|
|
82
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
83
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Set or unset the current device as an archive device.
|
|
@@ -88,8 +88,8 @@ function useSetOwnDeviceInfo() {
|
|
|
88
88
|
function useSetIsArchiveDevice() {
|
|
89
89
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
90
90
|
const clientApi = useClientApi();
|
|
91
|
-
const { error, mutate, status, reset } = (0, react_query_1.useMutation)((0, client_js_1.setIsArchiveDeviceMutationOptions)({ clientApi, queryClient }));
|
|
91
|
+
const { error, mutate, mutateAsync, status, reset } = (0, react_query_1.useMutation)((0, client_js_1.setIsArchiveDeviceMutationOptions)({ clientApi, queryClient }));
|
|
92
92
|
return status === 'error'
|
|
93
|
-
? { error, mutate, reset, status }
|
|
94
|
-
: { error: null, mutate, reset, status };
|
|
93
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
94
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
95
95
|
}
|
|
@@ -125,6 +125,11 @@ export declare function useCreateDocument<D extends WriteableDocumentType>({ doc
|
|
|
125
125
|
}, Error, {
|
|
126
126
|
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
127
127
|
}, unknown>;
|
|
128
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../lib/types.js").WriteableDocument<D> & {
|
|
129
|
+
forks: Array<string>;
|
|
130
|
+
}, Error, {
|
|
131
|
+
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
132
|
+
}, unknown>;
|
|
128
133
|
reset: () => void;
|
|
129
134
|
status: "error";
|
|
130
135
|
} | {
|
|
@@ -134,6 +139,11 @@ export declare function useCreateDocument<D extends WriteableDocumentType>({ doc
|
|
|
134
139
|
}, Error, {
|
|
135
140
|
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
136
141
|
}, unknown>;
|
|
142
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../lib/types.js").WriteableDocument<D> & {
|
|
143
|
+
forks: Array<string>;
|
|
144
|
+
}, Error, {
|
|
145
|
+
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
146
|
+
}, unknown>;
|
|
137
147
|
reset: () => void;
|
|
138
148
|
status: "pending" | "success" | "idle";
|
|
139
149
|
};
|
|
@@ -154,6 +164,12 @@ export declare function useUpdateDocument<D extends WriteableDocumentType>({ doc
|
|
|
154
164
|
versionId: string;
|
|
155
165
|
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
156
166
|
}, unknown>;
|
|
167
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../lib/types.js").WriteableDocument<D> & {
|
|
168
|
+
forks: Array<string>;
|
|
169
|
+
}, Error, {
|
|
170
|
+
versionId: string;
|
|
171
|
+
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
172
|
+
}, unknown>;
|
|
157
173
|
reset: () => void;
|
|
158
174
|
status: "error";
|
|
159
175
|
} | {
|
|
@@ -164,6 +180,12 @@ export declare function useUpdateDocument<D extends WriteableDocumentType>({ doc
|
|
|
164
180
|
versionId: string;
|
|
165
181
|
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
166
182
|
}, unknown>;
|
|
183
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../lib/types.js").WriteableDocument<D> & {
|
|
184
|
+
forks: Array<string>;
|
|
185
|
+
}, Error, {
|
|
186
|
+
versionId: string;
|
|
187
|
+
value: Omit<import("../lib/types.js").WriteableValue<D>, "schemaName">;
|
|
188
|
+
}, unknown>;
|
|
167
189
|
reset: () => void;
|
|
168
190
|
status: "pending" | "success" | "idle";
|
|
169
191
|
};
|
|
@@ -183,6 +205,11 @@ export declare function useDeleteDocument<D extends WriteableDocumentType>({ doc
|
|
|
183
205
|
}, Error, {
|
|
184
206
|
docId: string;
|
|
185
207
|
}, unknown>;
|
|
208
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../lib/types.js").WriteableDocument<D> & {
|
|
209
|
+
forks: Array<string>;
|
|
210
|
+
}, Error, {
|
|
211
|
+
docId: string;
|
|
212
|
+
}, unknown>;
|
|
186
213
|
reset: () => void;
|
|
187
214
|
status: "error";
|
|
188
215
|
} | {
|
|
@@ -192,6 +219,11 @@ export declare function useDeleteDocument<D extends WriteableDocumentType>({ doc
|
|
|
192
219
|
}, Error, {
|
|
193
220
|
docId: string;
|
|
194
221
|
}, unknown>;
|
|
222
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("../lib/types.js").WriteableDocument<D> & {
|
|
223
|
+
forks: Array<string>;
|
|
224
|
+
}, Error, {
|
|
225
|
+
docId: string;
|
|
226
|
+
}, unknown>;
|
|
195
227
|
reset: () => void;
|
|
196
228
|
status: "pending" | "success" | "idle";
|
|
197
229
|
};
|
|
@@ -148,15 +148,15 @@ function useManyDocs({ projectId, docType, includeDeleted, lang, }) {
|
|
|
148
148
|
function useCreateDocument({ docType, projectId, }) {
|
|
149
149
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
150
150
|
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
151
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.createDocumentMutationOptions)({
|
|
151
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.createDocumentMutationOptions)({
|
|
152
152
|
docType,
|
|
153
153
|
projectApi,
|
|
154
154
|
projectId,
|
|
155
155
|
queryClient,
|
|
156
156
|
}));
|
|
157
157
|
return status === 'error'
|
|
158
|
-
? { error, mutate, reset, status }
|
|
159
|
-
: { error: null, mutate, reset, status };
|
|
158
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
159
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
162
|
* Update a document within a project.
|
|
@@ -167,15 +167,15 @@ function useCreateDocument({ docType, projectId, }) {
|
|
|
167
167
|
function useUpdateDocument({ docType, projectId, }) {
|
|
168
168
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
169
169
|
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
170
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.updateDocumentMutationOptions)({
|
|
170
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.updateDocumentMutationOptions)({
|
|
171
171
|
docType,
|
|
172
172
|
projectApi,
|
|
173
173
|
projectId,
|
|
174
174
|
queryClient,
|
|
175
175
|
}));
|
|
176
176
|
return status === 'error'
|
|
177
|
-
? { error, mutate, reset, status }
|
|
178
|
-
: { error: null, mutate, reset, status };
|
|
177
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
178
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
181
|
* Delete a document within a project.
|
|
@@ -186,13 +186,13 @@ function useUpdateDocument({ docType, projectId, }) {
|
|
|
186
186
|
function useDeleteDocument({ docType, projectId, }) {
|
|
187
187
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
188
188
|
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
189
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.deleteDocumentMutationOptions)({
|
|
189
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.deleteDocumentMutationOptions)({
|
|
190
190
|
docType,
|
|
191
191
|
projectApi,
|
|
192
192
|
projectId,
|
|
193
193
|
queryClient,
|
|
194
194
|
}));
|
|
195
195
|
return status === 'error'
|
|
196
|
-
? { error, mutate, reset, status }
|
|
197
|
-
: { error: null, mutate, reset, status };
|
|
196
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
197
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
198
198
|
}
|
|
@@ -1,3 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set up listeners for received and updated invites.
|
|
3
|
+
* It is necessary to use this if you want the invites-related read hooks to update
|
|
4
|
+
* based on invites that are received or changed in the background.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* function App() {
|
|
9
|
+
* // Use this somewhere near the root of the application
|
|
10
|
+
* useSetUpInvitesListeners()
|
|
11
|
+
*
|
|
12
|
+
* return <RestOfApp />
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function useSetUpInvitesListeners(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get all invites that the device has received.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* function Example() {
|
|
23
|
+
* const { data } = useManyInvites()
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useManyInvites(): {
|
|
28
|
+
data: import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite[];
|
|
29
|
+
error: Error | null;
|
|
30
|
+
isRefetching: boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Get a single invite based on its ID.
|
|
34
|
+
*
|
|
35
|
+
* @param opts.inviteId ID of invite
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* function Example() {
|
|
40
|
+
* const { data } = useSingleInvite({ inviteId: '...' })
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function useSingleInvite({ inviteId }: {
|
|
45
|
+
inviteId: string;
|
|
46
|
+
}): {
|
|
47
|
+
data: import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite;
|
|
48
|
+
error: Error | null;
|
|
49
|
+
isRefetching: boolean;
|
|
50
|
+
};
|
|
1
51
|
/**
|
|
2
52
|
* Accept an invite that has been received.
|
|
3
53
|
*/
|
|
@@ -6,6 +56,9 @@ export declare function useAcceptInvite(): {
|
|
|
6
56
|
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
7
57
|
inviteId: string;
|
|
8
58
|
}, unknown>;
|
|
59
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
60
|
+
inviteId: string;
|
|
61
|
+
}, unknown>;
|
|
9
62
|
reset: () => void;
|
|
10
63
|
status: "error";
|
|
11
64
|
} | {
|
|
@@ -13,6 +66,9 @@ export declare function useAcceptInvite(): {
|
|
|
13
66
|
mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
|
|
14
67
|
inviteId: string;
|
|
15
68
|
}, unknown>;
|
|
69
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
70
|
+
inviteId: string;
|
|
71
|
+
}, unknown>;
|
|
16
72
|
reset: () => void;
|
|
17
73
|
status: "pending" | "success" | "idle";
|
|
18
74
|
};
|
|
@@ -24,6 +80,9 @@ export declare function useRejectInvite(): {
|
|
|
24
80
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
25
81
|
inviteId: string;
|
|
26
82
|
}, unknown>;
|
|
83
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
84
|
+
inviteId: string;
|
|
85
|
+
}, unknown>;
|
|
27
86
|
reset: () => void;
|
|
28
87
|
status: "error";
|
|
29
88
|
} | {
|
|
@@ -31,6 +90,9 @@ export declare function useRejectInvite(): {
|
|
|
31
90
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
32
91
|
inviteId: string;
|
|
33
92
|
}, unknown>;
|
|
93
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
94
|
+
inviteId: string;
|
|
95
|
+
}, unknown>;
|
|
34
96
|
reset: () => void;
|
|
35
97
|
status: "pending" | "success" | "idle";
|
|
36
98
|
};
|
|
@@ -49,6 +111,12 @@ export declare function useSendInvite({ projectId }: {
|
|
|
49
111
|
roleId: import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).RoleIdForNewInvite;
|
|
50
112
|
roleName?: string;
|
|
51
113
|
}, unknown>;
|
|
114
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
|
|
115
|
+
deviceId: string;
|
|
116
|
+
roleDescription?: string;
|
|
117
|
+
roleId: import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).RoleIdForNewInvite;
|
|
118
|
+
roleName?: string;
|
|
119
|
+
}, unknown>;
|
|
52
120
|
reset: () => void;
|
|
53
121
|
status: "error";
|
|
54
122
|
} | {
|
|
@@ -59,6 +127,12 @@ export declare function useSendInvite({ projectId }: {
|
|
|
59
127
|
roleId: import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).RoleIdForNewInvite;
|
|
60
128
|
roleName?: string;
|
|
61
129
|
}, unknown>;
|
|
130
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
|
|
131
|
+
deviceId: string;
|
|
132
|
+
roleDescription?: string;
|
|
133
|
+
roleId: import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).RoleIdForNewInvite;
|
|
134
|
+
roleName?: string;
|
|
135
|
+
}, unknown>;
|
|
62
136
|
reset: () => void;
|
|
63
137
|
status: "pending" | "success" | "idle";
|
|
64
138
|
};
|
|
@@ -74,6 +148,9 @@ export declare function useRequestCancelInvite({ projectId }: {
|
|
|
74
148
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
75
149
|
deviceId: string;
|
|
76
150
|
}, unknown>;
|
|
151
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
152
|
+
deviceId: string;
|
|
153
|
+
}, unknown>;
|
|
77
154
|
reset: () => void;
|
|
78
155
|
status: "error";
|
|
79
156
|
} | {
|
|
@@ -81,6 +158,9 @@ export declare function useRequestCancelInvite({ projectId }: {
|
|
|
81
158
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
82
159
|
deviceId: string;
|
|
83
160
|
}, unknown>;
|
|
161
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
162
|
+
deviceId: string;
|
|
163
|
+
}, unknown>;
|
|
84
164
|
reset: () => void;
|
|
85
165
|
status: "pending" | "success" | "idle";
|
|
86
166
|
};
|
|
@@ -1,23 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSetUpInvitesListeners = useSetUpInvitesListeners;
|
|
4
|
+
exports.useManyInvites = useManyInvites;
|
|
5
|
+
exports.useSingleInvite = useSingleInvite;
|
|
3
6
|
exports.useAcceptInvite = useAcceptInvite;
|
|
4
7
|
exports.useRejectInvite = useRejectInvite;
|
|
5
8
|
exports.useSendInvite = useSendInvite;
|
|
6
9
|
exports.useRequestCancelInvite = useRequestCancelInvite;
|
|
7
10
|
const react_query_1 = require("@tanstack/react-query");
|
|
11
|
+
const react_1 = require("react");
|
|
8
12
|
const invites_js_1 = require("../lib/react-query/invites.js");
|
|
9
13
|
const client_js_1 = require("./client.js");
|
|
10
14
|
const projects_js_1 = require("./projects.js");
|
|
15
|
+
/**
|
|
16
|
+
* Set up listeners for received and updated invites.
|
|
17
|
+
* It is necessary to use this if you want the invites-related read hooks to update
|
|
18
|
+
* based on invites that are received or changed in the background.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* function App() {
|
|
23
|
+
* // Use this somewhere near the root of the application
|
|
24
|
+
* useSetUpInvitesListeners()
|
|
25
|
+
*
|
|
26
|
+
* return <RestOfApp />
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function useSetUpInvitesListeners() {
|
|
31
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
32
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
33
|
+
(0, react_1.useEffect)(() => {
|
|
34
|
+
function invalidateCache() {
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: (0, invites_js_1.getInvitesQueryKey)() });
|
|
36
|
+
}
|
|
37
|
+
clientApi.invite.addListener('invite-received', invalidateCache);
|
|
38
|
+
clientApi.invite.addListener('invite-updated', invalidateCache);
|
|
39
|
+
return () => {
|
|
40
|
+
clientApi.invite.removeListener('invite-received', invalidateCache);
|
|
41
|
+
clientApi.invite.removeListener('invite-updated', invalidateCache);
|
|
42
|
+
};
|
|
43
|
+
}, [clientApi, queryClient]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get all invites that the device has received.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* function Example() {
|
|
51
|
+
* const { data } = useManyInvites()
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function useManyInvites() {
|
|
56
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
57
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, invites_js_1.getInvitesQueryOptions)({ clientApi }));
|
|
58
|
+
return { data, error, isRefetching };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get a single invite based on its ID.
|
|
62
|
+
*
|
|
63
|
+
* @param opts.inviteId ID of invite
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* function Example() {
|
|
68
|
+
* const { data } = useSingleInvite({ inviteId: '...' })
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function useSingleInvite({ inviteId }) {
|
|
73
|
+
const clientApi = (0, client_js_1.useClientApi)();
|
|
74
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, invites_js_1.getInviteByIdQueryOptions)({ clientApi, inviteId }));
|
|
75
|
+
return { data, error, isRefetching };
|
|
76
|
+
}
|
|
11
77
|
/**
|
|
12
78
|
* Accept an invite that has been received.
|
|
13
79
|
*/
|
|
14
80
|
function useAcceptInvite() {
|
|
15
81
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
16
82
|
const clientApi = (0, client_js_1.useClientApi)();
|
|
17
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.acceptInviteMutationOptions)({ clientApi, queryClient }));
|
|
83
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.acceptInviteMutationOptions)({ clientApi, queryClient }));
|
|
18
84
|
return status === 'error'
|
|
19
|
-
? { error, mutate, reset, status }
|
|
20
|
-
: { error: null, mutate, reset, status };
|
|
85
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
86
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
21
87
|
}
|
|
22
88
|
/**
|
|
23
89
|
* Reject an invite that has been received.
|
|
@@ -25,10 +91,10 @@ function useAcceptInvite() {
|
|
|
25
91
|
function useRejectInvite() {
|
|
26
92
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
27
93
|
const clientApi = (0, client_js_1.useClientApi)();
|
|
28
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.rejectInviteMutationOptions)({ clientApi, queryClient }));
|
|
94
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.rejectInviteMutationOptions)({ clientApi, queryClient }));
|
|
29
95
|
return status === 'error'
|
|
30
|
-
? { error, mutate, reset, status }
|
|
31
|
-
: { error: null, mutate, reset, status };
|
|
96
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
97
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
32
98
|
}
|
|
33
99
|
/**
|
|
34
100
|
* Send an invite for a project.
|
|
@@ -38,10 +104,10 @@ function useRejectInvite() {
|
|
|
38
104
|
function useSendInvite({ projectId }) {
|
|
39
105
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
40
106
|
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
41
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.sendInviteMutationOptions)({ projectApi, projectId, queryClient }));
|
|
107
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.sendInviteMutationOptions)({ projectApi, projectId, queryClient }));
|
|
42
108
|
return status === 'error'
|
|
43
|
-
? { error, mutate, reset, status }
|
|
44
|
-
: { error: null, mutate, reset, status };
|
|
109
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
110
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
45
111
|
}
|
|
46
112
|
/**
|
|
47
113
|
* Request a cancellation of an invite sent to another device.
|
|
@@ -51,8 +117,8 @@ function useSendInvite({ projectId }) {
|
|
|
51
117
|
function useRequestCancelInvite({ projectId }) {
|
|
52
118
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
53
119
|
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
54
|
-
const { error, mutate, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.requestCancelInviteMutationOptions)({ projectApi, queryClient }));
|
|
120
|
+
const { error, mutate, mutateAsync, reset, status } = (0, react_query_1.useMutation)((0, invites_js_1.requestCancelInviteMutationOptions)({ projectApi, queryClient }));
|
|
55
121
|
return status === 'error'
|
|
56
|
-
? { error, mutate, reset, status }
|
|
57
|
-
: { error: null, mutate, reset, status };
|
|
122
|
+
? { error, mutate, mutateAsync, reset, status }
|
|
123
|
+
: { error: null, mutate, mutateAsync, reset, status };
|
|
58
124
|
}
|
|
@@ -280,6 +280,10 @@ export declare function useAddServerPeer({ projectId }: {
|
|
|
280
280
|
baseUrl: string;
|
|
281
281
|
dangerouslyAllowInsecureConnections?: boolean;
|
|
282
282
|
}, unknown>;
|
|
283
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
284
|
+
baseUrl: string;
|
|
285
|
+
dangerouslyAllowInsecureConnections?: boolean;
|
|
286
|
+
}, unknown>;
|
|
283
287
|
reset: () => void;
|
|
284
288
|
status: "error";
|
|
285
289
|
} | {
|
|
@@ -288,6 +292,10 @@ export declare function useAddServerPeer({ projectId }: {
|
|
|
288
292
|
baseUrl: string;
|
|
289
293
|
dangerouslyAllowInsecureConnections?: boolean;
|
|
290
294
|
}, unknown>;
|
|
295
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
296
|
+
baseUrl: string;
|
|
297
|
+
dangerouslyAllowInsecureConnections?: boolean;
|
|
298
|
+
}, unknown>;
|
|
291
299
|
reset: () => void;
|
|
292
300
|
status: "pending" | "success" | "idle";
|
|
293
301
|
};
|
|
@@ -300,6 +308,10 @@ export declare function useCreateProject(): {
|
|
|
300
308
|
name?: string;
|
|
301
309
|
configPath?: string;
|
|
302
310
|
} | undefined, unknown>;
|
|
311
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
312
|
+
name?: string;
|
|
313
|
+
configPath?: string;
|
|
314
|
+
} | undefined, unknown>;
|
|
303
315
|
reset: () => void;
|
|
304
316
|
status: "error";
|
|
305
317
|
} | {
|
|
@@ -308,6 +320,10 @@ export declare function useCreateProject(): {
|
|
|
308
320
|
name?: string;
|
|
309
321
|
configPath?: string;
|
|
310
322
|
} | undefined, unknown>;
|
|
323
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
|
|
324
|
+
name?: string;
|
|
325
|
+
configPath?: string;
|
|
326
|
+
} | undefined, unknown>;
|
|
311
327
|
reset: () => void;
|
|
312
328
|
status: "pending" | "success" | "idle";
|
|
313
329
|
};
|
|
@@ -319,6 +335,9 @@ export declare function useLeaveProject(): {
|
|
|
319
335
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
320
336
|
projectId: string;
|
|
321
337
|
}, unknown>;
|
|
338
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
339
|
+
projectId: string;
|
|
340
|
+
}, unknown>;
|
|
322
341
|
reset: () => void;
|
|
323
342
|
status: "error";
|
|
324
343
|
} | {
|
|
@@ -326,6 +345,9 @@ export declare function useLeaveProject(): {
|
|
|
326
345
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
327
346
|
projectId: string;
|
|
328
347
|
}, unknown>;
|
|
348
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
349
|
+
projectId: string;
|
|
350
|
+
}, unknown>;
|
|
329
351
|
reset: () => void;
|
|
330
352
|
status: "pending" | "success" | "idle";
|
|
331
353
|
};
|
|
@@ -341,6 +363,9 @@ export declare function useImportProjectConfig({ projectId }: {
|
|
|
341
363
|
mutate: import("@tanstack/react-query").UseMutateFunction<Error[], Error, {
|
|
342
364
|
configPath: string;
|
|
343
365
|
}, unknown>;
|
|
366
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Error[], Error, {
|
|
367
|
+
configPath: string;
|
|
368
|
+
}, unknown>;
|
|
344
369
|
reset: () => void;
|
|
345
370
|
status: "error";
|
|
346
371
|
} | {
|
|
@@ -348,6 +373,9 @@ export declare function useImportProjectConfig({ projectId }: {
|
|
|
348
373
|
mutate: import("@tanstack/react-query").UseMutateFunction<Error[], Error, {
|
|
349
374
|
configPath: string;
|
|
350
375
|
}, unknown>;
|
|
376
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Error[], Error, {
|
|
377
|
+
configPath: string;
|
|
378
|
+
}, unknown>;
|
|
351
379
|
reset: () => void;
|
|
352
380
|
status: "pending" | "success" | "idle";
|
|
353
381
|
};
|
|
@@ -365,6 +393,11 @@ export declare function useUpdateProjectSettings({ projectId }: {
|
|
|
365
393
|
configMetadata?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["configMetadata"];
|
|
366
394
|
defaultPresets?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["defaultPresets"];
|
|
367
395
|
}, unknown>;
|
|
396
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings, Error, {
|
|
397
|
+
name?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["name"];
|
|
398
|
+
configMetadata?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["configMetadata"];
|
|
399
|
+
defaultPresets?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["defaultPresets"];
|
|
400
|
+
}, unknown>;
|
|
368
401
|
reset: () => void;
|
|
369
402
|
status: "error";
|
|
370
403
|
} | {
|
|
@@ -374,6 +407,11 @@ export declare function useUpdateProjectSettings({ projectId }: {
|
|
|
374
407
|
configMetadata?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["configMetadata"];
|
|
375
408
|
defaultPresets?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["defaultPresets"];
|
|
376
409
|
}, unknown>;
|
|
410
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings, Error, {
|
|
411
|
+
name?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["name"];
|
|
412
|
+
configMetadata?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["configMetadata"];
|
|
413
|
+
defaultPresets?: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).ProjectSettings["defaultPresets"];
|
|
414
|
+
}, unknown>;
|
|
377
415
|
reset: () => void;
|
|
378
416
|
status: "pending" | "success" | "idle";
|
|
379
417
|
};
|
|
@@ -397,6 +435,17 @@ export declare function useCreateBlob({ projectId }: {
|
|
|
397
435
|
thumbnail?: string;
|
|
398
436
|
metadata: import("@comapeo/core/dist/blob-api.js", { with: { "resolution-mode": "import" } }).Metadata;
|
|
399
437
|
}, unknown>;
|
|
438
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
439
|
+
driveId: string;
|
|
440
|
+
name: string;
|
|
441
|
+
type: "photo" | "video" | "audio";
|
|
442
|
+
hash: string;
|
|
443
|
+
}, Error, {
|
|
444
|
+
original: string;
|
|
445
|
+
preview?: string;
|
|
446
|
+
thumbnail?: string;
|
|
447
|
+
metadata: import("@comapeo/core/dist/blob-api.js", { with: { "resolution-mode": "import" } }).Metadata;
|
|
448
|
+
}, unknown>;
|
|
400
449
|
reset: () => void;
|
|
401
450
|
status: "error";
|
|
402
451
|
} | {
|
|
@@ -412,6 +461,17 @@ export declare function useCreateBlob({ projectId }: {
|
|
|
412
461
|
thumbnail?: string;
|
|
413
462
|
metadata: import("@comapeo/core/dist/blob-api.js", { with: { "resolution-mode": "import" } }).Metadata;
|
|
414
463
|
}, unknown>;
|
|
464
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
465
|
+
driveId: string;
|
|
466
|
+
name: string;
|
|
467
|
+
type: "photo" | "video" | "audio";
|
|
468
|
+
hash: string;
|
|
469
|
+
}, Error, {
|
|
470
|
+
original: string;
|
|
471
|
+
preview?: string;
|
|
472
|
+
thumbnail?: string;
|
|
473
|
+
metadata: import("@comapeo/core/dist/blob-api.js", { with: { "resolution-mode": "import" } }).Metadata;
|
|
474
|
+
}, unknown>;
|
|
415
475
|
reset: () => void;
|
|
416
476
|
status: "pending" | "success" | "idle";
|
|
417
477
|
};
|
|
@@ -455,6 +515,9 @@ export declare function useStartSync({ projectId }: {
|
|
|
455
515
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
456
516
|
autostopDataSyncAfter: number | null;
|
|
457
517
|
} | undefined, unknown>;
|
|
518
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
519
|
+
autostopDataSyncAfter: number | null;
|
|
520
|
+
} | undefined, unknown>;
|
|
458
521
|
reset: () => void;
|
|
459
522
|
status: "error";
|
|
460
523
|
} | {
|
|
@@ -462,6 +525,9 @@ export declare function useStartSync({ projectId }: {
|
|
|
462
525
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
463
526
|
autostopDataSyncAfter: number | null;
|
|
464
527
|
} | undefined, unknown>;
|
|
528
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
529
|
+
autostopDataSyncAfter: number | null;
|
|
530
|
+
} | undefined, unknown>;
|
|
465
531
|
reset: () => void;
|
|
466
532
|
status: "pending" | "success" | "idle";
|
|
467
533
|
};
|
|
@@ -470,11 +536,13 @@ export declare function useStopSync({ projectId }: {
|
|
|
470
536
|
}): {
|
|
471
537
|
error: Error;
|
|
472
538
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, void, unknown>;
|
|
539
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, void, unknown>;
|
|
473
540
|
reset: () => void;
|
|
474
541
|
status: "error";
|
|
475
542
|
} | {
|
|
476
543
|
error: null;
|
|
477
544
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, void, unknown>;
|
|
545
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, void, unknown>;
|
|
478
546
|
reset: () => void;
|
|
479
547
|
status: "pending" | "success" | "idle";
|
|
480
548
|
};
|