@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
|
@@ -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,162 @@
|
|
|
1
|
+
import { DEFAULT_MAP_ID } from '@comapeo/map-server';
|
|
2
|
+
// #region Shared
|
|
3
|
+
const ROOT_QUERY_KEY = '@comapeo/core-react';
|
|
4
|
+
// Since the API is running locally, queries should run regardless of network
|
|
5
|
+
// status, and should not be retried. In React Native the API consumer would
|
|
6
|
+
// have to manually set the network mode, but we still should keep these options
|
|
7
|
+
// to avoid surprises. Not using the queryClient `defaultOptions` because the API
|
|
8
|
+
// consumer might also use the same queryClient for network queries
|
|
9
|
+
export function baseQueryOptions() {
|
|
10
|
+
return {
|
|
11
|
+
networkMode: 'always',
|
|
12
|
+
retry: false,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function baseMutationOptions() {
|
|
16
|
+
return {
|
|
17
|
+
networkMode: 'always',
|
|
18
|
+
retry: false,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const PICKED_MUTATION_RESULT_KEYS = [
|
|
22
|
+
'error',
|
|
23
|
+
'mutate',
|
|
24
|
+
'mutateAsync',
|
|
25
|
+
'reset',
|
|
26
|
+
'status',
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Filters a `UseMutationResult` to only include a subset of its keys, and uses
|
|
30
|
+
* `DistributedPick` to preserve the discriminated union types of the mutation
|
|
31
|
+
* result based on the `status` property.
|
|
32
|
+
*/
|
|
33
|
+
export function filterMutationResult(mutationResult) {
|
|
34
|
+
const filteredResult = {};
|
|
35
|
+
for (const key of PICKED_MUTATION_RESULT_KEYS) {
|
|
36
|
+
filteredResult[key] = mutationResult[key];
|
|
37
|
+
}
|
|
38
|
+
return filteredResult;
|
|
39
|
+
}
|
|
40
|
+
// #endregion
|
|
41
|
+
// #region Client
|
|
42
|
+
function getClientQueryKey() {
|
|
43
|
+
return [ROOT_QUERY_KEY, 'client'];
|
|
44
|
+
}
|
|
45
|
+
export function getDeviceInfoQueryKey() {
|
|
46
|
+
return [...getClientQueryKey(), 'device_info'];
|
|
47
|
+
}
|
|
48
|
+
export function getIsArchiveDeviceQueryKey() {
|
|
49
|
+
return [...getClientQueryKey(), 'is_archive_device'];
|
|
50
|
+
}
|
|
51
|
+
// #endregion
|
|
52
|
+
// #region Invites
|
|
53
|
+
export function getInvitesQueryKey() {
|
|
54
|
+
return [ROOT_QUERY_KEY, 'invites'];
|
|
55
|
+
}
|
|
56
|
+
export function getInvitesByIdQueryKey({ inviteId }) {
|
|
57
|
+
return [ROOT_QUERY_KEY, 'invites', { inviteId }];
|
|
58
|
+
}
|
|
59
|
+
// #endregion
|
|
60
|
+
// #region Maps
|
|
61
|
+
const MAPS_ROOT_QUERY_KEY = [ROOT_QUERY_KEY, 'maps'];
|
|
62
|
+
export function getMapQueryKey({ mapId }) {
|
|
63
|
+
return [...MAPS_ROOT_QUERY_KEY, mapId];
|
|
64
|
+
}
|
|
65
|
+
export function getMapInfoQueryKey({ mapId }) {
|
|
66
|
+
return [...getMapQueryKey({ mapId }), 'info'];
|
|
67
|
+
}
|
|
68
|
+
export function getStyleJsonUrlQueryKey({ mapId }) {
|
|
69
|
+
return [...getMapQueryKey({ mapId }), 'stylejson_url'];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Invalidate queries for this map and the default map (which internally
|
|
73
|
+
* redirects to custom) so that they will be refetched with the new map data.
|
|
74
|
+
*/
|
|
75
|
+
export async function invalidateMapQueries(queryClient, { mapId }) {
|
|
76
|
+
await Promise.all([
|
|
77
|
+
queryClient.invalidateQueries({
|
|
78
|
+
queryKey: getMapQueryKey({ mapId }),
|
|
79
|
+
}),
|
|
80
|
+
queryClient.invalidateQueries({
|
|
81
|
+
queryKey: getMapQueryKey({ mapId: DEFAULT_MAP_ID }),
|
|
82
|
+
}),
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
// #endregion
|
|
86
|
+
// #region Projects
|
|
87
|
+
export function getProjectsQueryKey() {
|
|
88
|
+
return [ROOT_QUERY_KEY, 'projects'];
|
|
89
|
+
}
|
|
90
|
+
export function getProjectByIdQueryKey({ projectId }) {
|
|
91
|
+
return [ROOT_QUERY_KEY, 'projects', projectId];
|
|
92
|
+
}
|
|
93
|
+
export function getProjectSettingsQueryKey({ projectId, }) {
|
|
94
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'project_settings'];
|
|
95
|
+
}
|
|
96
|
+
export function getProjectRoleQueryKey({ projectId }) {
|
|
97
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'role'];
|
|
98
|
+
}
|
|
99
|
+
export function getMembersQueryKey({ projectId, includeLeft, }) {
|
|
100
|
+
return [
|
|
101
|
+
ROOT_QUERY_KEY,
|
|
102
|
+
'projects',
|
|
103
|
+
projectId,
|
|
104
|
+
'members',
|
|
105
|
+
{ includeLeft },
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
export function getMemberByIdQueryKey({ projectId, deviceId, }) {
|
|
109
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'members', deviceId];
|
|
110
|
+
}
|
|
111
|
+
export function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }) {
|
|
112
|
+
return [
|
|
113
|
+
ROOT_QUERY_KEY,
|
|
114
|
+
'projects',
|
|
115
|
+
projectId,
|
|
116
|
+
'document_created_by',
|
|
117
|
+
originalVersionId,
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* We call this within a project hook, because that's the only place the API is
|
|
122
|
+
* exposed right now, but it is the same for all projects, so no need for
|
|
123
|
+
* scoping the query key to the project
|
|
124
|
+
*/
|
|
125
|
+
export function getMediaServerOriginQueryKey() {
|
|
126
|
+
return [ROOT_QUERY_KEY, 'media_server_origin'];
|
|
127
|
+
}
|
|
128
|
+
// #endregion
|
|
129
|
+
// #region Documents
|
|
130
|
+
export function getDocumentsQueryKey({ projectId, docType, }) {
|
|
131
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, docType];
|
|
132
|
+
}
|
|
133
|
+
export function getManyDocumentsQueryKey({ projectId, docType, includeDeleted, lang, }) {
|
|
134
|
+
return [
|
|
135
|
+
ROOT_QUERY_KEY,
|
|
136
|
+
'projects',
|
|
137
|
+
projectId,
|
|
138
|
+
docType,
|
|
139
|
+
{ includeDeleted, lang },
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
export function getDocumentByDocIdQueryKey({ projectId, docType, docId, lang, }) {
|
|
143
|
+
return [
|
|
144
|
+
ROOT_QUERY_KEY,
|
|
145
|
+
'projects',
|
|
146
|
+
projectId,
|
|
147
|
+
docType,
|
|
148
|
+
docId,
|
|
149
|
+
{ lang },
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
export function getDocumentByVersionIdQueryKey({ projectId, docType, versionId, lang, }) {
|
|
153
|
+
return [
|
|
154
|
+
ROOT_QUERY_KEY,
|
|
155
|
+
'projects',
|
|
156
|
+
projectId,
|
|
157
|
+
docType,
|
|
158
|
+
versionId,
|
|
159
|
+
{ lang },
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
// #endregion
|
package/dist/esm/lib/sync.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/esm/lib/sync.js
CHANGED
package/dist/esm/lib/types.d.ts
CHANGED
|
@@ -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 {};
|