@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.
- package/README.md +1 -1
- package/dist/commonjs/contexts/ClientApi.d.ts +1 -3
- package/dist/commonjs/contexts/ClientApi.js +2 -2
- package/dist/commonjs/hooks/client.d.ts +74 -33
- package/dist/commonjs/hooks/client.js +40 -11
- package/dist/commonjs/hooks/documents.d.ts +41 -429
- package/dist/commonjs/hooks/documents.js +101 -51
- package/dist/commonjs/hooks/invites.d.ts +153 -55
- package/dist/commonjs/hooks/invites.js +69 -20
- package/dist/commonjs/hooks/maps.d.ts +98 -219
- package/dist/commonjs/hooks/maps.js +104 -37
- package/dist/commonjs/hooks/projects.d.ts +666 -223
- package/dist/commonjs/hooks/projects.js +264 -131
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/lib/map-shares-stores.d.ts +1 -1
- package/dist/commonjs/lib/map-shares-stores.js +2 -2
- package/dist/commonjs/lib/presets.d.ts +1 -3
- package/dist/commonjs/lib/react-query.d.ts +103 -0
- package/dist/commonjs/lib/react-query.js +187 -0
- package/dist/commonjs/lib/sync.d.ts +2 -5
- package/dist/commonjs/lib/sync.js +0 -1
- package/dist/commonjs/lib/types.d.ts +4 -6
- package/dist/esm/contexts/ClientApi.d.ts +1 -3
- package/dist/esm/contexts/ClientApi.js +1 -1
- package/dist/esm/hooks/client.d.ts +74 -33
- package/dist/esm/hooks/client.js +40 -11
- package/dist/esm/hooks/documents.d.ts +41 -429
- package/dist/esm/hooks/documents.js +101 -51
- package/dist/esm/hooks/invites.d.ts +153 -55
- package/dist/esm/hooks/invites.js +69 -20
- package/dist/esm/hooks/maps.d.ts +98 -219
- package/dist/esm/hooks/maps.js +105 -38
- package/dist/esm/hooks/projects.d.ts +666 -223
- package/dist/esm/hooks/projects.js +262 -129
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/lib/map-shares-stores.d.ts +1 -1
- package/dist/esm/lib/map-shares-stores.js +1 -1
- package/dist/esm/lib/presets.d.ts +1 -3
- package/dist/esm/lib/react-query.d.ts +103 -0
- package/dist/esm/lib/react-query.js +162 -0
- package/dist/esm/lib/sync.d.ts +2 -5
- package/dist/esm/lib/sync.js +1 -1
- package/dist/esm/lib/types.d.ts +4 -6
- package/docs/API.md +137 -81
- package/package.json +39 -35
- package/dist/commonjs/lib/react-query/client.d.ts +0 -65
- package/dist/commonjs/lib/react-query/client.js +0 -68
- package/dist/commonjs/lib/react-query/documents.d.ts +0 -1484
- package/dist/commonjs/lib/react-query/documents.js +0 -149
- package/dist/commonjs/lib/react-query/invites.d.ts +0 -88
- package/dist/commonjs/lib/react-query/invites.js +0 -95
- package/dist/commonjs/lib/react-query/maps.d.ts +0 -72
- package/dist/commonjs/lib/react-query/maps.js +0 -129
- package/dist/commonjs/lib/react-query/mutation-result.d.ts +0 -8
- package/dist/commonjs/lib/react-query/mutation-result.js +0 -22
- package/dist/commonjs/lib/react-query/projects.d.ts +0 -316
- package/dist/commonjs/lib/react-query/projects.js +0 -359
- package/dist/commonjs/lib/react-query/shared.d.ts +0 -9
- package/dist/commonjs/lib/react-query/shared.js +0 -23
- package/dist/esm/lib/react-query/client.d.ts +0 -65
- package/dist/esm/lib/react-query/client.js +0 -59
- package/dist/esm/lib/react-query/documents.d.ts +0 -1484
- package/dist/esm/lib/react-query/documents.js +0 -137
- package/dist/esm/lib/react-query/invites.d.ts +0 -88
- package/dist/esm/lib/react-query/invites.js +0 -85
- package/dist/esm/lib/react-query/maps.d.ts +0 -72
- package/dist/esm/lib/react-query/maps.js +0 -119
- package/dist/esm/lib/react-query/mutation-result.d.ts +0 -8
- package/dist/esm/lib/react-query/mutation-result.js +0 -19
- package/dist/esm/lib/react-query/projects.d.ts +0 -316
- package/dist/esm/lib/react-query/projects.js +0 -324
- package/dist/esm/lib/react-query/shared.d.ts +0 -9
- package/dist/esm/lib/react-query/shared.js +0 -18
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ React wrapper for working with [`@comapeo/core`](https://github.com/digidem/coma
|
|
|
7
7
|
`react`, `@tanstack/react-query`, `@comapeo/schema`, `@comapeo/core`, and `@comapeo/ipc` are peer deps and must be installed alongside this package. You may want to pin these to specific versions depending on your needs.
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install react @tanstack/react-query@5 @comapeo/core-react @comapeo/
|
|
10
|
+
npm install react @tanstack/react-query@5 @comapeo/core-react @comapeo/core @comapeo/ipc
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Setup
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { MapeoClientApi } from '@comapeo/ipc'
|
|
2
|
-
'resolution-mode': 'import'
|
|
3
|
-
};
|
|
1
|
+
import type { MapeoClientApi } from '@comapeo/ipc';
|
|
4
2
|
import { type Context, type JSX, type PropsWithChildren } from 'react';
|
|
5
3
|
export declare const ClientApiContext: Context<MapeoClientApi | null>;
|
|
6
4
|
export type ClientApiProviderProps = PropsWithChildren<{
|
|
@@ -4,7 +4,7 @@ exports.ClientApiContext = void 0;
|
|
|
4
4
|
exports.ClientApiProvider = ClientApiProvider;
|
|
5
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
-
const
|
|
7
|
+
const react_query_js_1 = require("../lib/react-query.js");
|
|
8
8
|
exports.ClientApiContext = (0, react_1.createContext)(null);
|
|
9
9
|
/**
|
|
10
10
|
* Create a context provider that holds a CoMapeo API client instance.
|
|
@@ -17,7 +17,7 @@ function ClientApiProvider({ children, clientApi, }) {
|
|
|
17
17
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
18
18
|
(0, react_1.useEffect)(() => {
|
|
19
19
|
function invalidateInviteCache() {
|
|
20
|
-
queryClient.invalidateQueries({ queryKey: (0,
|
|
20
|
+
queryClient.invalidateQueries({ queryKey: (0, react_query_js_1.getInvitesQueryKey)() });
|
|
21
21
|
}
|
|
22
22
|
// Invite listeners
|
|
23
23
|
clientApi.invite.addListener('invite-received', invalidateInviteCache);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
};
|
|
1
|
+
import type { DeviceInfo } from '@comapeo/core/schema.js';
|
|
2
|
+
import type { MapeoClientApi } from '@comapeo/ipc';
|
|
3
|
+
import { type UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
/**
|
|
5
5
|
* Access a client API instance. If a ClientApiContext provider is not
|
|
6
6
|
* set up, it will throw an error.
|
|
@@ -37,14 +37,7 @@ export declare function useClientApi(): MapeoClientApi;
|
|
|
37
37
|
* }
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export declare function useOwnDeviceInfo():
|
|
41
|
-
data: {
|
|
42
|
-
deviceId: string;
|
|
43
|
-
deviceType: import("@comapeo/core/dist/schema/client.js", { with: { "resolution-mode": "import" } }).DeviceInfoParam["deviceType"];
|
|
44
|
-
} & Partial<import("@comapeo/core/dist/schema/client.js", { with: { "resolution-mode": "import" } }).DeviceInfoParam>;
|
|
45
|
-
error: Error | null;
|
|
46
|
-
isRefetching: boolean;
|
|
47
|
-
};
|
|
40
|
+
export declare function useOwnDeviceInfo(): Pick<UseSuspenseQueryResult<Awaited<ReturnType<MapeoClientApi['getDeviceInfo']>>>, 'data' | 'error' | 'isRefetching'>;
|
|
48
41
|
/**
|
|
49
42
|
* Retrieve whether the current device is an archive device or not.
|
|
50
43
|
*
|
|
@@ -63,52 +56,100 @@ export declare function useIsArchiveDevice(): {
|
|
|
63
56
|
/**
|
|
64
57
|
* Update the device info for the current device.
|
|
65
58
|
*/
|
|
66
|
-
export declare function useSetOwnDeviceInfo(): {
|
|
67
|
-
|
|
59
|
+
export declare function useSetOwnDeviceInfo(): Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverIdleResult<void, Error, {
|
|
60
|
+
name: string;
|
|
61
|
+
deviceType: DeviceInfo["deviceType"];
|
|
62
|
+
}, unknown>, {
|
|
68
63
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
69
64
|
name: string;
|
|
70
|
-
deviceType:
|
|
65
|
+
deviceType: DeviceInfo["deviceType"];
|
|
71
66
|
}, unknown>;
|
|
67
|
+
}> & {
|
|
72
68
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
73
69
|
name: string;
|
|
74
|
-
deviceType:
|
|
70
|
+
deviceType: DeviceInfo["deviceType"];
|
|
75
71
|
}, unknown>;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverLoadingResult<void, Error, {
|
|
73
|
+
name: string;
|
|
74
|
+
deviceType: DeviceInfo["deviceType"];
|
|
75
|
+
}, unknown>, {
|
|
80
76
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
81
77
|
name: string;
|
|
82
|
-
deviceType:
|
|
78
|
+
deviceType: DeviceInfo["deviceType"];
|
|
83
79
|
}, unknown>;
|
|
80
|
+
}> & {
|
|
84
81
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
85
82
|
name: string;
|
|
86
|
-
deviceType:
|
|
83
|
+
deviceType: DeviceInfo["deviceType"];
|
|
87
84
|
}, unknown>;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverErrorResult<void, Error, {
|
|
86
|
+
name: string;
|
|
87
|
+
deviceType: DeviceInfo["deviceType"];
|
|
88
|
+
}, unknown>, {
|
|
89
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
90
|
+
name: string;
|
|
91
|
+
deviceType: DeviceInfo["deviceType"];
|
|
92
|
+
}, unknown>;
|
|
93
|
+
}> & {
|
|
94
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
95
|
+
name: string;
|
|
96
|
+
deviceType: DeviceInfo["deviceType"];
|
|
97
|
+
}, unknown>;
|
|
98
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverSuccessResult<void, Error, {
|
|
99
|
+
name: string;
|
|
100
|
+
deviceType: DeviceInfo["deviceType"];
|
|
101
|
+
}, unknown>, {
|
|
102
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
103
|
+
name: string;
|
|
104
|
+
deviceType: DeviceInfo["deviceType"];
|
|
105
|
+
}, unknown>;
|
|
106
|
+
}> & {
|
|
107
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
108
|
+
name: string;
|
|
109
|
+
deviceType: DeviceInfo["deviceType"];
|
|
110
|
+
}, unknown>;
|
|
111
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
|
|
91
112
|
/**
|
|
92
113
|
* Set or unset the current device as an archive device.
|
|
93
114
|
*/
|
|
94
|
-
export declare function useSetIsArchiveDevice(): {
|
|
95
|
-
|
|
115
|
+
export declare function useSetIsArchiveDevice(): Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverIdleResult<void, Error, {
|
|
116
|
+
isArchiveDevice: boolean;
|
|
117
|
+
}, unknown>, {
|
|
96
118
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
97
119
|
isArchiveDevice: boolean;
|
|
98
120
|
}, unknown>;
|
|
121
|
+
}> & {
|
|
99
122
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
100
123
|
isArchiveDevice: boolean;
|
|
101
124
|
}, unknown>;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
error: null;
|
|
125
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverLoadingResult<void, Error, {
|
|
126
|
+
isArchiveDevice: boolean;
|
|
127
|
+
}, unknown>, {
|
|
106
128
|
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
107
129
|
isArchiveDevice: boolean;
|
|
108
130
|
}, unknown>;
|
|
131
|
+
}> & {
|
|
109
132
|
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
110
133
|
isArchiveDevice: boolean;
|
|
111
134
|
}, unknown>;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
135
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverErrorResult<void, Error, {
|
|
136
|
+
isArchiveDevice: boolean;
|
|
137
|
+
}, unknown>, {
|
|
138
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
139
|
+
isArchiveDevice: boolean;
|
|
140
|
+
}, unknown>;
|
|
141
|
+
}> & {
|
|
142
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
143
|
+
isArchiveDevice: boolean;
|
|
144
|
+
}, unknown>;
|
|
145
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync"> | Pick<import("@tanstack/react-query").Override<import("@tanstack/react-query").MutationObserverSuccessResult<void, Error, {
|
|
146
|
+
isArchiveDevice: boolean;
|
|
147
|
+
}, unknown>, {
|
|
148
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
|
|
149
|
+
isArchiveDevice: boolean;
|
|
150
|
+
}, unknown>;
|
|
151
|
+
}> & {
|
|
152
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<void, Error, {
|
|
153
|
+
isArchiveDevice: boolean;
|
|
154
|
+
}, unknown>;
|
|
155
|
+
}, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
|
|
@@ -8,7 +8,7 @@ exports.useSetIsArchiveDevice = useSetIsArchiveDevice;
|
|
|
8
8
|
const react_query_1 = require("@tanstack/react-query");
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const ClientApi_js_1 = require("../contexts/ClientApi.js");
|
|
11
|
-
const
|
|
11
|
+
const react_query_js_1 = require("../lib/react-query.js");
|
|
12
12
|
/**
|
|
13
13
|
* Access a client API instance. If a ClientApiContext provider is not
|
|
14
14
|
* set up, it will throw an error.
|
|
@@ -53,7 +53,13 @@ function useClientApi() {
|
|
|
53
53
|
*/
|
|
54
54
|
function useOwnDeviceInfo() {
|
|
55
55
|
const clientApi = useClientApi();
|
|
56
|
-
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)(
|
|
56
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)({
|
|
57
|
+
...(0, react_query_js_1.baseQueryOptions)(),
|
|
58
|
+
queryKey: (0, react_query_js_1.getDeviceInfoQueryKey)(),
|
|
59
|
+
queryFn: async () => {
|
|
60
|
+
return clientApi.getDeviceInfo();
|
|
61
|
+
},
|
|
62
|
+
});
|
|
57
63
|
return { data, error, isRefetching };
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
@@ -68,7 +74,13 @@ function useOwnDeviceInfo() {
|
|
|
68
74
|
*/
|
|
69
75
|
function useIsArchiveDevice() {
|
|
70
76
|
const clientApi = useClientApi();
|
|
71
|
-
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)(
|
|
77
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)({
|
|
78
|
+
...(0, react_query_js_1.baseQueryOptions)(),
|
|
79
|
+
queryKey: (0, react_query_js_1.getIsArchiveDeviceQueryKey)(),
|
|
80
|
+
queryFn: async () => {
|
|
81
|
+
return clientApi.getIsArchiveDevice();
|
|
82
|
+
},
|
|
83
|
+
});
|
|
72
84
|
return { data, error, isRefetching };
|
|
73
85
|
}
|
|
74
86
|
/**
|
|
@@ -77,10 +89,20 @@ function useIsArchiveDevice() {
|
|
|
77
89
|
function useSetOwnDeviceInfo() {
|
|
78
90
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
79
91
|
const clientApi = useClientApi();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
93
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
94
|
+
mutationFn: async ({ name, deviceType, }) => {
|
|
95
|
+
return clientApi.setDeviceInfo({ name, deviceType });
|
|
96
|
+
},
|
|
97
|
+
onSuccess: () => {
|
|
98
|
+
queryClient.invalidateQueries({
|
|
99
|
+
queryKey: (0, react_query_js_1.getDeviceInfoQueryKey)(),
|
|
100
|
+
});
|
|
101
|
+
queryClient.invalidateQueries({
|
|
102
|
+
queryKey: (0, react_query_js_1.getProjectsQueryKey)(),
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
}));
|
|
84
106
|
}
|
|
85
107
|
/**
|
|
86
108
|
* Set or unset the current device as an archive device.
|
|
@@ -88,8 +110,15 @@ function useSetOwnDeviceInfo() {
|
|
|
88
110
|
function useSetIsArchiveDevice() {
|
|
89
111
|
const queryClient = (0, react_query_1.useQueryClient)();
|
|
90
112
|
const clientApi = useClientApi();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
return (0, react_query_js_1.filterMutationResult)((0, react_query_1.useMutation)({
|
|
114
|
+
...(0, react_query_js_1.baseMutationOptions)(),
|
|
115
|
+
mutationFn: async ({ isArchiveDevice }) => {
|
|
116
|
+
return clientApi.setIsArchiveDevice(isArchiveDevice);
|
|
117
|
+
},
|
|
118
|
+
onSuccess: () => {
|
|
119
|
+
queryClient.invalidateQueries({
|
|
120
|
+
queryKey: (0, react_query_js_1.getIsArchiveDeviceQueryKey)(),
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
}));
|
|
95
124
|
}
|