@comapeo/core-react 9.0.2 → 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 +96 -225
- 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 +96 -225
- 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 -104
- 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 -104
- 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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { QueryClient, UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import { DistributedPick } from 'type-fest';
|
|
3
|
+
import type { WriteableDocumentType } from './types.js';
|
|
4
|
+
export declare function baseQueryOptions(): {
|
|
5
|
+
networkMode: "always";
|
|
6
|
+
retry: false;
|
|
7
|
+
};
|
|
8
|
+
export declare function baseMutationOptions(): {
|
|
9
|
+
networkMode: "always";
|
|
10
|
+
retry: false;
|
|
11
|
+
};
|
|
12
|
+
declare const PICKED_MUTATION_RESULT_KEYS: readonly ["error", "mutate", "mutateAsync", "reset", "status"];
|
|
13
|
+
export type FilteredMutationResult<TResult extends UseMutationResult<any, any, any, any>> = DistributedPick<TResult, (typeof PICKED_MUTATION_RESULT_KEYS)[number]>;
|
|
14
|
+
/**
|
|
15
|
+
* Filters a `UseMutationResult` to only include a subset of its keys, and uses
|
|
16
|
+
* `DistributedPick` to preserve the discriminated union types of the mutation
|
|
17
|
+
* result based on the `status` property.
|
|
18
|
+
*/
|
|
19
|
+
export declare function filterMutationResult<TResult extends UseMutationResult<any, any, any, any>>(mutationResult: TResult): DistributedPick<TResult, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
|
|
20
|
+
export declare function getDeviceInfoQueryKey(): readonly ["@comapeo/core-react", "client", "device_info"];
|
|
21
|
+
export declare function getIsArchiveDeviceQueryKey(): readonly ["@comapeo/core-react", "client", "is_archive_device"];
|
|
22
|
+
export declare function getInvitesQueryKey(): readonly ["@comapeo/core-react", "invites"];
|
|
23
|
+
export declare function getInvitesByIdQueryKey({ inviteId }: {
|
|
24
|
+
inviteId: string;
|
|
25
|
+
}): readonly ["@comapeo/core-react", "invites", {
|
|
26
|
+
readonly inviteId: string;
|
|
27
|
+
}];
|
|
28
|
+
export declare function getMapQueryKey({ mapId }: {
|
|
29
|
+
mapId: string;
|
|
30
|
+
}): readonly ["@comapeo/core-react", "maps", string];
|
|
31
|
+
export declare function getMapInfoQueryKey({ mapId }: {
|
|
32
|
+
mapId: string;
|
|
33
|
+
}): readonly ["@comapeo/core-react", "maps", string, "info"];
|
|
34
|
+
export declare function getStyleJsonUrlQueryKey({ mapId }: {
|
|
35
|
+
mapId: string;
|
|
36
|
+
}): readonly ["@comapeo/core-react", "maps", string, "stylejson_url"];
|
|
37
|
+
/**
|
|
38
|
+
* Invalidate queries for this map and the default map (which internally
|
|
39
|
+
* redirects to custom) so that they will be refetched with the new map data.
|
|
40
|
+
*/
|
|
41
|
+
export declare function invalidateMapQueries(queryClient: QueryClient, { mapId }: {
|
|
42
|
+
mapId: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
export declare function getProjectsQueryKey(): readonly ["@comapeo/core-react", "projects"];
|
|
45
|
+
export declare function getProjectByIdQueryKey({ projectId }: {
|
|
46
|
+
projectId: string;
|
|
47
|
+
}): readonly ["@comapeo/core-react", "projects", string];
|
|
48
|
+
export declare function getProjectSettingsQueryKey({ projectId, }: {
|
|
49
|
+
projectId: string;
|
|
50
|
+
}): readonly ["@comapeo/core-react", "projects", string, "project_settings"];
|
|
51
|
+
export declare function getProjectRoleQueryKey({ projectId }: {
|
|
52
|
+
projectId: string;
|
|
53
|
+
}): readonly ["@comapeo/core-react", "projects", string, "role"];
|
|
54
|
+
export declare function getMembersQueryKey({ projectId, includeLeft, }: {
|
|
55
|
+
projectId: string;
|
|
56
|
+
includeLeft?: boolean;
|
|
57
|
+
}): readonly ["@comapeo/core-react", "projects", string, "members", {
|
|
58
|
+
readonly includeLeft: boolean | undefined;
|
|
59
|
+
}];
|
|
60
|
+
export declare function getMemberByIdQueryKey({ projectId, deviceId, }: {
|
|
61
|
+
projectId: string;
|
|
62
|
+
deviceId: string;
|
|
63
|
+
}): readonly ["@comapeo/core-react", "projects", string, "members", string];
|
|
64
|
+
export declare function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }: {
|
|
65
|
+
projectId: string;
|
|
66
|
+
originalVersionId: string;
|
|
67
|
+
}): readonly ["@comapeo/core-react", "projects", string, "document_created_by", string];
|
|
68
|
+
/**
|
|
69
|
+
* We call this within a project hook, because that's the only place the API is
|
|
70
|
+
* exposed right now, but it is the same for all projects, so no need for
|
|
71
|
+
* scoping the query key to the project
|
|
72
|
+
*/
|
|
73
|
+
export declare function getMediaServerOriginQueryKey(): readonly ["@comapeo/core-react", "media_server_origin"];
|
|
74
|
+
export declare function getDocumentsQueryKey<D extends WriteableDocumentType>({ projectId, docType, }: {
|
|
75
|
+
projectId: string;
|
|
76
|
+
docType: D;
|
|
77
|
+
}): readonly ["@comapeo/core-react", "projects", string, D];
|
|
78
|
+
export declare function getManyDocumentsQueryKey<D extends WriteableDocumentType>({ projectId, docType, includeDeleted, lang, }: {
|
|
79
|
+
projectId: string;
|
|
80
|
+
docType: D;
|
|
81
|
+
includeDeleted?: boolean;
|
|
82
|
+
lang?: string;
|
|
83
|
+
}): readonly ["@comapeo/core-react", "projects", string, D, {
|
|
84
|
+
readonly includeDeleted: boolean | undefined;
|
|
85
|
+
readonly lang: string | undefined;
|
|
86
|
+
}];
|
|
87
|
+
export declare function getDocumentByDocIdQueryKey<D extends WriteableDocumentType>({ projectId, docType, docId, lang, }: {
|
|
88
|
+
projectId: string;
|
|
89
|
+
docType: D;
|
|
90
|
+
docId: string;
|
|
91
|
+
lang?: string;
|
|
92
|
+
}): readonly ["@comapeo/core-react", "projects", string, D, string, {
|
|
93
|
+
readonly lang: string | undefined;
|
|
94
|
+
}];
|
|
95
|
+
export declare function getDocumentByVersionIdQueryKey<D extends WriteableDocumentType>({ projectId, docType, versionId, lang, }: {
|
|
96
|
+
projectId: string;
|
|
97
|
+
docType: D;
|
|
98
|
+
versionId: string;
|
|
99
|
+
lang?: string;
|
|
100
|
+
}): readonly ["@comapeo/core-react", "projects", string, D, string, {
|
|
101
|
+
readonly lang: string | undefined;
|
|
102
|
+
}];
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseQueryOptions = baseQueryOptions;
|
|
4
|
+
exports.baseMutationOptions = baseMutationOptions;
|
|
5
|
+
exports.filterMutationResult = filterMutationResult;
|
|
6
|
+
exports.getDeviceInfoQueryKey = getDeviceInfoQueryKey;
|
|
7
|
+
exports.getIsArchiveDeviceQueryKey = getIsArchiveDeviceQueryKey;
|
|
8
|
+
exports.getInvitesQueryKey = getInvitesQueryKey;
|
|
9
|
+
exports.getInvitesByIdQueryKey = getInvitesByIdQueryKey;
|
|
10
|
+
exports.getMapQueryKey = getMapQueryKey;
|
|
11
|
+
exports.getMapInfoQueryKey = getMapInfoQueryKey;
|
|
12
|
+
exports.getStyleJsonUrlQueryKey = getStyleJsonUrlQueryKey;
|
|
13
|
+
exports.invalidateMapQueries = invalidateMapQueries;
|
|
14
|
+
exports.getProjectsQueryKey = getProjectsQueryKey;
|
|
15
|
+
exports.getProjectByIdQueryKey = getProjectByIdQueryKey;
|
|
16
|
+
exports.getProjectSettingsQueryKey = getProjectSettingsQueryKey;
|
|
17
|
+
exports.getProjectRoleQueryKey = getProjectRoleQueryKey;
|
|
18
|
+
exports.getMembersQueryKey = getMembersQueryKey;
|
|
19
|
+
exports.getMemberByIdQueryKey = getMemberByIdQueryKey;
|
|
20
|
+
exports.getDocumentCreatedByQueryKey = getDocumentCreatedByQueryKey;
|
|
21
|
+
exports.getMediaServerOriginQueryKey = getMediaServerOriginQueryKey;
|
|
22
|
+
exports.getDocumentsQueryKey = getDocumentsQueryKey;
|
|
23
|
+
exports.getManyDocumentsQueryKey = getManyDocumentsQueryKey;
|
|
24
|
+
exports.getDocumentByDocIdQueryKey = getDocumentByDocIdQueryKey;
|
|
25
|
+
exports.getDocumentByVersionIdQueryKey = getDocumentByVersionIdQueryKey;
|
|
26
|
+
const map_server_1 = require("@comapeo/map-server");
|
|
27
|
+
// #region Shared
|
|
28
|
+
const ROOT_QUERY_KEY = '@comapeo/core-react';
|
|
29
|
+
// Since the API is running locally, queries should run regardless of network
|
|
30
|
+
// status, and should not be retried. In React Native the API consumer would
|
|
31
|
+
// have to manually set the network mode, but we still should keep these options
|
|
32
|
+
// to avoid surprises. Not using the queryClient `defaultOptions` because the API
|
|
33
|
+
// consumer might also use the same queryClient for network queries
|
|
34
|
+
function baseQueryOptions() {
|
|
35
|
+
return {
|
|
36
|
+
networkMode: 'always',
|
|
37
|
+
retry: false,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function baseMutationOptions() {
|
|
41
|
+
return {
|
|
42
|
+
networkMode: 'always',
|
|
43
|
+
retry: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const PICKED_MUTATION_RESULT_KEYS = [
|
|
47
|
+
'error',
|
|
48
|
+
'mutate',
|
|
49
|
+
'mutateAsync',
|
|
50
|
+
'reset',
|
|
51
|
+
'status',
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Filters a `UseMutationResult` to only include a subset of its keys, and uses
|
|
55
|
+
* `DistributedPick` to preserve the discriminated union types of the mutation
|
|
56
|
+
* result based on the `status` property.
|
|
57
|
+
*/
|
|
58
|
+
function filterMutationResult(mutationResult) {
|
|
59
|
+
const filteredResult = {};
|
|
60
|
+
for (const key of PICKED_MUTATION_RESULT_KEYS) {
|
|
61
|
+
filteredResult[key] = mutationResult[key];
|
|
62
|
+
}
|
|
63
|
+
return filteredResult;
|
|
64
|
+
}
|
|
65
|
+
// #endregion
|
|
66
|
+
// #region Client
|
|
67
|
+
function getClientQueryKey() {
|
|
68
|
+
return [ROOT_QUERY_KEY, 'client'];
|
|
69
|
+
}
|
|
70
|
+
function getDeviceInfoQueryKey() {
|
|
71
|
+
return [...getClientQueryKey(), 'device_info'];
|
|
72
|
+
}
|
|
73
|
+
function getIsArchiveDeviceQueryKey() {
|
|
74
|
+
return [...getClientQueryKey(), 'is_archive_device'];
|
|
75
|
+
}
|
|
76
|
+
// #endregion
|
|
77
|
+
// #region Invites
|
|
78
|
+
function getInvitesQueryKey() {
|
|
79
|
+
return [ROOT_QUERY_KEY, 'invites'];
|
|
80
|
+
}
|
|
81
|
+
function getInvitesByIdQueryKey({ inviteId }) {
|
|
82
|
+
return [ROOT_QUERY_KEY, 'invites', { inviteId }];
|
|
83
|
+
}
|
|
84
|
+
// #endregion
|
|
85
|
+
// #region Maps
|
|
86
|
+
const MAPS_ROOT_QUERY_KEY = [ROOT_QUERY_KEY, 'maps'];
|
|
87
|
+
function getMapQueryKey({ mapId }) {
|
|
88
|
+
return [...MAPS_ROOT_QUERY_KEY, mapId];
|
|
89
|
+
}
|
|
90
|
+
function getMapInfoQueryKey({ mapId }) {
|
|
91
|
+
return [...getMapQueryKey({ mapId }), 'info'];
|
|
92
|
+
}
|
|
93
|
+
function getStyleJsonUrlQueryKey({ mapId }) {
|
|
94
|
+
return [...getMapQueryKey({ mapId }), 'stylejson_url'];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Invalidate queries for this map and the default map (which internally
|
|
98
|
+
* redirects to custom) so that they will be refetched with the new map data.
|
|
99
|
+
*/
|
|
100
|
+
async function invalidateMapQueries(queryClient, { mapId }) {
|
|
101
|
+
await Promise.all([
|
|
102
|
+
queryClient.invalidateQueries({
|
|
103
|
+
queryKey: getMapQueryKey({ mapId }),
|
|
104
|
+
}),
|
|
105
|
+
queryClient.invalidateQueries({
|
|
106
|
+
queryKey: getMapQueryKey({ mapId: map_server_1.DEFAULT_MAP_ID }),
|
|
107
|
+
}),
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
// #endregion
|
|
111
|
+
// #region Projects
|
|
112
|
+
function getProjectsQueryKey() {
|
|
113
|
+
return [ROOT_QUERY_KEY, 'projects'];
|
|
114
|
+
}
|
|
115
|
+
function getProjectByIdQueryKey({ projectId }) {
|
|
116
|
+
return [ROOT_QUERY_KEY, 'projects', projectId];
|
|
117
|
+
}
|
|
118
|
+
function getProjectSettingsQueryKey({ projectId, }) {
|
|
119
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'project_settings'];
|
|
120
|
+
}
|
|
121
|
+
function getProjectRoleQueryKey({ projectId }) {
|
|
122
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'role'];
|
|
123
|
+
}
|
|
124
|
+
function getMembersQueryKey({ projectId, includeLeft, }) {
|
|
125
|
+
return [
|
|
126
|
+
ROOT_QUERY_KEY,
|
|
127
|
+
'projects',
|
|
128
|
+
projectId,
|
|
129
|
+
'members',
|
|
130
|
+
{ includeLeft },
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
function getMemberByIdQueryKey({ projectId, deviceId, }) {
|
|
134
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'members', deviceId];
|
|
135
|
+
}
|
|
136
|
+
function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }) {
|
|
137
|
+
return [
|
|
138
|
+
ROOT_QUERY_KEY,
|
|
139
|
+
'projects',
|
|
140
|
+
projectId,
|
|
141
|
+
'document_created_by',
|
|
142
|
+
originalVersionId,
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* We call this within a project hook, because that's the only place the API is
|
|
147
|
+
* exposed right now, but it is the same for all projects, so no need for
|
|
148
|
+
* scoping the query key to the project
|
|
149
|
+
*/
|
|
150
|
+
function getMediaServerOriginQueryKey() {
|
|
151
|
+
return [ROOT_QUERY_KEY, 'media_server_origin'];
|
|
152
|
+
}
|
|
153
|
+
// #endregion
|
|
154
|
+
// #region Documents
|
|
155
|
+
function getDocumentsQueryKey({ projectId, docType, }) {
|
|
156
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, docType];
|
|
157
|
+
}
|
|
158
|
+
function getManyDocumentsQueryKey({ projectId, docType, includeDeleted, lang, }) {
|
|
159
|
+
return [
|
|
160
|
+
ROOT_QUERY_KEY,
|
|
161
|
+
'projects',
|
|
162
|
+
projectId,
|
|
163
|
+
docType,
|
|
164
|
+
{ includeDeleted, lang },
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
function getDocumentByDocIdQueryKey({ projectId, docType, docId, lang, }) {
|
|
168
|
+
return [
|
|
169
|
+
ROOT_QUERY_KEY,
|
|
170
|
+
'projects',
|
|
171
|
+
projectId,
|
|
172
|
+
docType,
|
|
173
|
+
docId,
|
|
174
|
+
{ lang },
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
function getDocumentByVersionIdQueryKey({ projectId, docType, versionId, lang, }) {
|
|
178
|
+
return [
|
|
179
|
+
ROOT_QUERY_KEY,
|
|
180
|
+
'projects',
|
|
181
|
+
projectId,
|
|
182
|
+
docType,
|
|
183
|
+
versionId,
|
|
184
|
+
{ lang },
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
// #endregion
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type { MapeoProjectApi } from '@comapeo/ipc'
|
|
2
|
-
'resolution-mode': 'import'
|
|
3
|
-
};
|
|
1
|
+
import type { MapeoProjectApi } from '@comapeo/ipc';
|
|
4
2
|
export type SyncState = Awaited<ReturnType<MapeoProjectApi['$sync']['getState']>>;
|
|
5
|
-
export declare function getDataSyncCountForDevice(syncStateForDevice: SyncState['remoteDeviceSyncState'][string]): number;
|
|
6
3
|
export declare class SyncStore {
|
|
7
4
|
#private;
|
|
8
5
|
constructor(project: MapeoProjectApi);
|
|
9
6
|
subscribe: (listener: () => void) => () => void;
|
|
10
|
-
getStateSnapshot: () =>
|
|
7
|
+
getStateSnapshot: () => SyncState | null;
|
|
11
8
|
getDataProgressSnapshot: () => number | null;
|
|
12
9
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SyncStore = void 0;
|
|
4
|
-
exports.getDataSyncCountForDevice = getDataSyncCountForDevice;
|
|
5
4
|
function getDataSyncCountForDevice(syncStateForDevice) {
|
|
6
5
|
const { data } = syncStateForDevice;
|
|
7
6
|
return data.want + data.wanted;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type WriteableDocumentType = Extract<MapeoDoc['schemaName'], 'field' | 'observation' | 'preset' | 'track' | 'remoteDetectionAlert'>;
|
|
5
|
-
export type WriteableValue<D extends WriteableDocumentType> = Extract<MapeoValue, {
|
|
1
|
+
import type { ComapeoDoc, ComapeoValue } from '@comapeo/core/schema.js';
|
|
2
|
+
export type WriteableDocumentType = Extract<ComapeoDoc['schemaName'], 'field' | 'observation' | 'preset' | 'track' | 'remoteDetectionAlert'>;
|
|
3
|
+
export type WriteableValue<D extends WriteableDocumentType> = Extract<ComapeoValue, {
|
|
6
4
|
schemaName: D;
|
|
7
5
|
}>;
|
|
8
|
-
export type WriteableDocument<D extends WriteableDocumentType> = Extract<
|
|
6
|
+
export type WriteableDocument<D extends WriteableDocumentType> = Extract<ComapeoDoc, {
|
|
9
7
|
schemaName: D;
|
|
10
8
|
}>;
|
|
11
9
|
export {};
|
|
@@ -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<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { createContext, createElement, useEffect, } from 'react';
|
|
3
|
-
import { getInvitesQueryKey } from '../lib/react-query
|
|
3
|
+
import { getInvitesQueryKey } from '../lib/react-query.js';
|
|
4
4
|
export const ClientApiContext = createContext(null);
|
|
5
5
|
/**
|
|
6
6
|
* Create a context provider that holds a CoMapeo API client instance.
|
|
@@ -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").DeviceInfoParam["deviceType"];
|
|
44
|
-
} & Partial<import("@comapeo/core/dist/schema/client.js").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">;
|
package/dist/esm/hooks/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { ClientApiContext } from '../contexts/ClientApi.js';
|
|
4
|
-
import {
|
|
4
|
+
import { baseMutationOptions, baseQueryOptions, filterMutationResult, getDeviceInfoQueryKey, getIsArchiveDeviceQueryKey, getProjectsQueryKey, } from '../lib/react-query.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.
|
|
@@ -46,7 +46,13 @@ export function useClientApi() {
|
|
|
46
46
|
*/
|
|
47
47
|
export function useOwnDeviceInfo() {
|
|
48
48
|
const clientApi = useClientApi();
|
|
49
|
-
const { data, error, isRefetching } = useSuspenseQuery(
|
|
49
|
+
const { data, error, isRefetching } = useSuspenseQuery({
|
|
50
|
+
...baseQueryOptions(),
|
|
51
|
+
queryKey: getDeviceInfoQueryKey(),
|
|
52
|
+
queryFn: async () => {
|
|
53
|
+
return clientApi.getDeviceInfo();
|
|
54
|
+
},
|
|
55
|
+
});
|
|
50
56
|
return { data, error, isRefetching };
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
@@ -61,7 +67,13 @@ export function useOwnDeviceInfo() {
|
|
|
61
67
|
*/
|
|
62
68
|
export function useIsArchiveDevice() {
|
|
63
69
|
const clientApi = useClientApi();
|
|
64
|
-
const { data, error, isRefetching } = useSuspenseQuery(
|
|
70
|
+
const { data, error, isRefetching } = useSuspenseQuery({
|
|
71
|
+
...baseQueryOptions(),
|
|
72
|
+
queryKey: getIsArchiveDeviceQueryKey(),
|
|
73
|
+
queryFn: async () => {
|
|
74
|
+
return clientApi.getIsArchiveDevice();
|
|
75
|
+
},
|
|
76
|
+
});
|
|
65
77
|
return { data, error, isRefetching };
|
|
66
78
|
}
|
|
67
79
|
/**
|
|
@@ -70,10 +82,20 @@ export function useIsArchiveDevice() {
|
|
|
70
82
|
export function useSetOwnDeviceInfo() {
|
|
71
83
|
const queryClient = useQueryClient();
|
|
72
84
|
const clientApi = useClientApi();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
85
|
+
return filterMutationResult(useMutation({
|
|
86
|
+
...baseMutationOptions(),
|
|
87
|
+
mutationFn: async ({ name, deviceType, }) => {
|
|
88
|
+
return clientApi.setDeviceInfo({ name, deviceType });
|
|
89
|
+
},
|
|
90
|
+
onSuccess: () => {
|
|
91
|
+
queryClient.invalidateQueries({
|
|
92
|
+
queryKey: getDeviceInfoQueryKey(),
|
|
93
|
+
});
|
|
94
|
+
queryClient.invalidateQueries({
|
|
95
|
+
queryKey: getProjectsQueryKey(),
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
}));
|
|
77
99
|
}
|
|
78
100
|
/**
|
|
79
101
|
* Set or unset the current device as an archive device.
|
|
@@ -81,8 +103,15 @@ export function useSetOwnDeviceInfo() {
|
|
|
81
103
|
export function useSetIsArchiveDevice() {
|
|
82
104
|
const queryClient = useQueryClient();
|
|
83
105
|
const clientApi = useClientApi();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
106
|
+
return filterMutationResult(useMutation({
|
|
107
|
+
...baseMutationOptions(),
|
|
108
|
+
mutationFn: async ({ isArchiveDevice }) => {
|
|
109
|
+
return clientApi.setIsArchiveDevice(isArchiveDevice);
|
|
110
|
+
},
|
|
111
|
+
onSuccess: () => {
|
|
112
|
+
queryClient.invalidateQueries({
|
|
113
|
+
queryKey: getIsArchiveDeviceQueryKey(),
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
}));
|
|
88
117
|
}
|