@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
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDocumentsQueryKey = getDocumentsQueryKey;
|
|
4
|
-
exports.getManyDocumentsQueryKey = getManyDocumentsQueryKey;
|
|
5
|
-
exports.getDocumentByDocIdQueryKey = getDocumentByDocIdQueryKey;
|
|
6
|
-
exports.getDocumentByVersionIdQueryKey = getDocumentByVersionIdQueryKey;
|
|
7
|
-
exports.documentsQueryOptions = documentsQueryOptions;
|
|
8
|
-
exports.documentByDocumentIdQueryOptions = documentByDocumentIdQueryOptions;
|
|
9
|
-
exports.documentByVersionIdQueryOptions = documentByVersionIdQueryOptions;
|
|
10
|
-
exports.createDocumentMutationOptions = createDocumentMutationOptions;
|
|
11
|
-
exports.updateDocumentMutationOptions = updateDocumentMutationOptions;
|
|
12
|
-
exports.deleteDocumentMutationOptions = deleteDocumentMutationOptions;
|
|
13
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
-
const shared_js_1 = require("./shared.js");
|
|
15
|
-
function getDocumentsQueryKey({ projectId, docType, }) {
|
|
16
|
-
return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId, docType];
|
|
17
|
-
}
|
|
18
|
-
function getManyDocumentsQueryKey({ projectId, docType, includeDeleted, lang, }) {
|
|
19
|
-
return [
|
|
20
|
-
shared_js_1.ROOT_QUERY_KEY,
|
|
21
|
-
'projects',
|
|
22
|
-
projectId,
|
|
23
|
-
docType,
|
|
24
|
-
{ includeDeleted, lang },
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
function getDocumentByDocIdQueryKey({ projectId, docType, docId, lang, }) {
|
|
28
|
-
return [
|
|
29
|
-
shared_js_1.ROOT_QUERY_KEY,
|
|
30
|
-
'projects',
|
|
31
|
-
projectId,
|
|
32
|
-
docType,
|
|
33
|
-
docId,
|
|
34
|
-
{ lang },
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
function getDocumentByVersionIdQueryKey({ projectId, docType, versionId, lang, }) {
|
|
38
|
-
return [
|
|
39
|
-
shared_js_1.ROOT_QUERY_KEY,
|
|
40
|
-
'projects',
|
|
41
|
-
projectId,
|
|
42
|
-
docType,
|
|
43
|
-
versionId,
|
|
44
|
-
{ lang },
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
function documentsQueryOptions({ projectApi, projectId, docType, includeDeleted, lang, }) {
|
|
48
|
-
return (0, react_query_1.queryOptions)({
|
|
49
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
50
|
-
queryKey: getManyDocumentsQueryKey({
|
|
51
|
-
projectId,
|
|
52
|
-
docType,
|
|
53
|
-
includeDeleted,
|
|
54
|
-
lang,
|
|
55
|
-
}),
|
|
56
|
-
queryFn: async () => {
|
|
57
|
-
return projectApi[docType].getMany({
|
|
58
|
-
includeDeleted,
|
|
59
|
-
lang,
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function documentByDocumentIdQueryOptions({ projectApi, projectId, docType, docId, lang, }) {
|
|
65
|
-
return (0, react_query_1.queryOptions)({
|
|
66
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
67
|
-
queryKey: getDocumentByDocIdQueryKey({
|
|
68
|
-
projectId,
|
|
69
|
-
docType,
|
|
70
|
-
docId,
|
|
71
|
-
lang,
|
|
72
|
-
}),
|
|
73
|
-
queryFn: async () => {
|
|
74
|
-
return projectApi[docType].getByDocId(docId, {
|
|
75
|
-
lang,
|
|
76
|
-
// We want to make sure that this throws in the case that no match is found
|
|
77
|
-
mustBeFound: true,
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function documentByVersionIdQueryOptions({ projectApi, projectId, docType, versionId, lang, }) {
|
|
83
|
-
return (0, react_query_1.queryOptions)({
|
|
84
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
85
|
-
queryKey: getDocumentByVersionIdQueryKey({
|
|
86
|
-
projectId,
|
|
87
|
-
docType,
|
|
88
|
-
versionId,
|
|
89
|
-
lang,
|
|
90
|
-
}),
|
|
91
|
-
queryFn: async () => {
|
|
92
|
-
return projectApi[docType].getByVersionId(versionId, { lang });
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function createDocumentMutationOptions({ docType, projectApi, projectId, queryClient, }) {
|
|
97
|
-
return {
|
|
98
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
99
|
-
mutationFn: async ({ value }) => {
|
|
100
|
-
// @ts-expect-error TS not handling this well
|
|
101
|
-
return projectApi[docType].create({
|
|
102
|
-
...value,
|
|
103
|
-
schemaName: docType,
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
onSuccess: () => {
|
|
107
|
-
queryClient.invalidateQueries({
|
|
108
|
-
queryKey: getDocumentsQueryKey({
|
|
109
|
-
projectId,
|
|
110
|
-
docType,
|
|
111
|
-
}),
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function updateDocumentMutationOptions({ docType, projectApi, projectId, queryClient, }) {
|
|
117
|
-
return {
|
|
118
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
119
|
-
mutationFn: async ({ versionId, value }) => {
|
|
120
|
-
// @ts-expect-error TS not handling this well
|
|
121
|
-
return projectApi[docType].update(versionId, value);
|
|
122
|
-
},
|
|
123
|
-
onSuccess: () => {
|
|
124
|
-
queryClient.invalidateQueries({
|
|
125
|
-
queryKey: getDocumentsQueryKey({
|
|
126
|
-
projectId,
|
|
127
|
-
docType,
|
|
128
|
-
}),
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function deleteDocumentMutationOptions({ docType, projectApi, projectId, queryClient, }) {
|
|
134
|
-
return {
|
|
135
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
136
|
-
mutationFn: async ({ docId }) => {
|
|
137
|
-
// @ts-expect-error TS not handling this well
|
|
138
|
-
return projectApi[docType].delete(docId);
|
|
139
|
-
},
|
|
140
|
-
onSuccess: () => {
|
|
141
|
-
queryClient.invalidateQueries({
|
|
142
|
-
queryKey: getDocumentsQueryKey({
|
|
143
|
-
projectId,
|
|
144
|
-
docType,
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { MemberApi } from '@comapeo/core' with {
|
|
2
|
-
'resolution-mode': 'import'
|
|
3
|
-
};
|
|
4
|
-
import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with {
|
|
5
|
-
'resolution-mode': 'import'
|
|
6
|
-
};
|
|
7
|
-
import { type QueryClient } from '@tanstack/react-query';
|
|
8
|
-
export declare function getInvitesQueryKey(): readonly ["@comapeo/core-react", "invites"];
|
|
9
|
-
export declare function getInvitesByIdQueryKey({ inviteId }: {
|
|
10
|
-
inviteId: string;
|
|
11
|
-
}): readonly ["@comapeo/core-react", "invites", {
|
|
12
|
-
readonly inviteId: string;
|
|
13
|
-
}];
|
|
14
|
-
export declare function getInvitesQueryOptions({ clientApi, }: {
|
|
15
|
-
clientApi: MapeoClientApi;
|
|
16
|
-
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite[], Error, import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite[], readonly ["@comapeo/core-react", "invites"]>, "queryFn"> & {
|
|
17
|
-
queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite[], readonly ["@comapeo/core-react", "invites"], never> | undefined;
|
|
18
|
-
} & {
|
|
19
|
-
queryKey: readonly ["@comapeo/core-react", "invites"] & {
|
|
20
|
-
[dataTagSymbol]: import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite[];
|
|
21
|
-
[dataTagErrorSymbol]: Error;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export declare function getInviteByIdQueryOptions({ clientApi, inviteId, }: {
|
|
25
|
-
clientApi: MapeoClientApi;
|
|
26
|
-
inviteId: string;
|
|
27
|
-
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite, Error, import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite, readonly ["@comapeo/core-react", "invites", {
|
|
28
|
-
readonly inviteId: string;
|
|
29
|
-
}]>, "queryFn"> & {
|
|
30
|
-
queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite, readonly ["@comapeo/core-react", "invites", {
|
|
31
|
-
readonly inviteId: string;
|
|
32
|
-
}], never> | undefined;
|
|
33
|
-
} & {
|
|
34
|
-
queryKey: readonly ["@comapeo/core-react", "invites", {
|
|
35
|
-
readonly inviteId: string;
|
|
36
|
-
}] & {
|
|
37
|
-
[dataTagSymbol]: import("@comapeo/core/dist/invite/invite-api.js", { with: { "resolution-mode": "import" } }).Invite;
|
|
38
|
-
[dataTagErrorSymbol]: Error;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
export declare function acceptInviteMutationOptions({ clientApi, queryClient, }: {
|
|
42
|
-
clientApi: MapeoClientApi;
|
|
43
|
-
queryClient: QueryClient;
|
|
44
|
-
}): {
|
|
45
|
-
mutationFn: ({ inviteId }: {
|
|
46
|
-
inviteId: string;
|
|
47
|
-
}) => Promise<string>;
|
|
48
|
-
onSuccess: () => void;
|
|
49
|
-
networkMode: "always";
|
|
50
|
-
retry: false;
|
|
51
|
-
};
|
|
52
|
-
export declare function rejectInviteMutationOptions({ clientApi, queryClient, }: {
|
|
53
|
-
clientApi: MapeoClientApi;
|
|
54
|
-
queryClient: QueryClient;
|
|
55
|
-
}): {
|
|
56
|
-
mutationFn: ({ inviteId }: {
|
|
57
|
-
inviteId: string;
|
|
58
|
-
}) => Promise<void>;
|
|
59
|
-
onSuccess: () => void;
|
|
60
|
-
networkMode: "always";
|
|
61
|
-
retry: false;
|
|
62
|
-
};
|
|
63
|
-
export declare function sendInviteMutationOptions({ projectApi, projectId, queryClient, }: {
|
|
64
|
-
projectApi: MapeoProjectApi;
|
|
65
|
-
projectId: string;
|
|
66
|
-
queryClient: QueryClient;
|
|
67
|
-
}): {
|
|
68
|
-
mutationFn: ({ deviceId, ...role }: {
|
|
69
|
-
deviceId: string;
|
|
70
|
-
roleDescription?: string;
|
|
71
|
-
roleId: MemberApi.RoleIdForNewInvite;
|
|
72
|
-
roleName?: string;
|
|
73
|
-
}) => Promise<"ACCEPT" | "REJECT" | "ALREADY">;
|
|
74
|
-
onSuccess: () => void;
|
|
75
|
-
networkMode: "always";
|
|
76
|
-
retry: false;
|
|
77
|
-
};
|
|
78
|
-
export declare function requestCancelInviteMutationOptions({ projectApi, queryClient, }: {
|
|
79
|
-
projectApi: MapeoProjectApi;
|
|
80
|
-
queryClient: QueryClient;
|
|
81
|
-
}): {
|
|
82
|
-
mutationFn: ({ deviceId }: {
|
|
83
|
-
deviceId: string;
|
|
84
|
-
}) => Promise<void>;
|
|
85
|
-
onSuccess: () => void;
|
|
86
|
-
networkMode: "always";
|
|
87
|
-
retry: false;
|
|
88
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInvitesQueryKey = getInvitesQueryKey;
|
|
4
|
-
exports.getInvitesByIdQueryKey = getInvitesByIdQueryKey;
|
|
5
|
-
exports.getInvitesQueryOptions = getInvitesQueryOptions;
|
|
6
|
-
exports.getInviteByIdQueryOptions = getInviteByIdQueryOptions;
|
|
7
|
-
exports.acceptInviteMutationOptions = acceptInviteMutationOptions;
|
|
8
|
-
exports.rejectInviteMutationOptions = rejectInviteMutationOptions;
|
|
9
|
-
exports.sendInviteMutationOptions = sendInviteMutationOptions;
|
|
10
|
-
exports.requestCancelInviteMutationOptions = requestCancelInviteMutationOptions;
|
|
11
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
12
|
-
const projects_js_1 = require("./projects.js");
|
|
13
|
-
const shared_js_1 = require("./shared.js");
|
|
14
|
-
function getInvitesQueryKey() {
|
|
15
|
-
return [shared_js_1.ROOT_QUERY_KEY, 'invites'];
|
|
16
|
-
}
|
|
17
|
-
function getInvitesByIdQueryKey({ inviteId }) {
|
|
18
|
-
return [shared_js_1.ROOT_QUERY_KEY, 'invites', { inviteId }];
|
|
19
|
-
}
|
|
20
|
-
function getInvitesQueryOptions({ clientApi, }) {
|
|
21
|
-
return (0, react_query_1.queryOptions)({
|
|
22
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
23
|
-
queryKey: getInvitesQueryKey(),
|
|
24
|
-
queryFn: async () => {
|
|
25
|
-
return clientApi.invite.getMany();
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function getInviteByIdQueryOptions({ clientApi, inviteId, }) {
|
|
30
|
-
return (0, react_query_1.queryOptions)({
|
|
31
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
32
|
-
queryKey: getInvitesByIdQueryKey({ inviteId }),
|
|
33
|
-
queryFn: async () => {
|
|
34
|
-
return clientApi.invite.getById(inviteId);
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function acceptInviteMutationOptions({ clientApi, queryClient, }) {
|
|
39
|
-
return {
|
|
40
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
41
|
-
mutationFn: async ({ inviteId }) => {
|
|
42
|
-
return clientApi.invite.accept({ inviteId });
|
|
43
|
-
},
|
|
44
|
-
onSuccess: () => {
|
|
45
|
-
queryClient.invalidateQueries({
|
|
46
|
-
queryKey: getInvitesQueryKey(),
|
|
47
|
-
});
|
|
48
|
-
queryClient.invalidateQueries({
|
|
49
|
-
queryKey: (0, projects_js_1.getProjectsQueryKey)(),
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function rejectInviteMutationOptions({ clientApi, queryClient, }) {
|
|
55
|
-
return {
|
|
56
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
57
|
-
mutationFn: async ({ inviteId }) => {
|
|
58
|
-
return clientApi.invite.reject({ inviteId });
|
|
59
|
-
},
|
|
60
|
-
onSuccess: () => {
|
|
61
|
-
queryClient.invalidateQueries({
|
|
62
|
-
queryKey: getInvitesQueryKey(),
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function sendInviteMutationOptions({ projectApi, projectId, queryClient, }) {
|
|
68
|
-
return {
|
|
69
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
70
|
-
mutationFn: async ({ deviceId, ...role }) => {
|
|
71
|
-
return projectApi.$member.invite(deviceId, role);
|
|
72
|
-
},
|
|
73
|
-
onSuccess: () => {
|
|
74
|
-
queryClient.invalidateQueries({
|
|
75
|
-
queryKey: getInvitesQueryKey(),
|
|
76
|
-
});
|
|
77
|
-
queryClient.invalidateQueries({
|
|
78
|
-
queryKey: (0, projects_js_1.getMembersQueryKey)({ projectId }),
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function requestCancelInviteMutationOptions({ projectApi, queryClient, }) {
|
|
84
|
-
return {
|
|
85
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
86
|
-
mutationFn: async ({ deviceId }) => {
|
|
87
|
-
return projectApi.$member.requestCancelInvite(deviceId);
|
|
88
|
-
},
|
|
89
|
-
onSuccess: () => {
|
|
90
|
-
queryClient.invalidateQueries({
|
|
91
|
-
queryKey: getInvitesQueryKey(),
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { type QueryClient, type UseMutationOptions } from '@tanstack/react-query';
|
|
2
|
-
import type { MapServerApi } from '../../contexts/MapServer.js';
|
|
3
|
-
import type { ReceivedMapSharesStore, SentMapSharesStore } from '../map-shares-stores.js';
|
|
4
|
-
type CompatFile = Omit<File, 'lastModified' | 'webkitRelativePath'>;
|
|
5
|
-
type ExpoFileDuckType = CompatFile & {
|
|
6
|
-
exists: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare function getMapQueryKey({ mapId }: {
|
|
9
|
-
mapId: string;
|
|
10
|
-
}): readonly ["@comapeo/core-react", "maps", string];
|
|
11
|
-
export declare function getStyleJsonUrlQueryKey({ mapId }: {
|
|
12
|
-
mapId: string;
|
|
13
|
-
}): readonly ["@comapeo/core-react", "maps", string, "stylejson_url"];
|
|
14
|
-
/**
|
|
15
|
-
* Invalidate queries for this map and the default map (which internally
|
|
16
|
-
* redirects to custom) so that they will be refetched with the new map data.
|
|
17
|
-
*/
|
|
18
|
-
export declare function invalidateMapQueries(queryClient: QueryClient, { mapId }: {
|
|
19
|
-
mapId: string;
|
|
20
|
-
}): Promise<void>;
|
|
21
|
-
export declare function mapStyleJsonUrlQueryOptions({ mapServerApi, mapId, }: {
|
|
22
|
-
mapServerApi: MapServerApi;
|
|
23
|
-
mapId?: string;
|
|
24
|
-
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "maps", string, "stylejson_url"]>, "queryFn"> & {
|
|
25
|
-
queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "maps", string, "stylejson_url"], never> | undefined;
|
|
26
|
-
} & {
|
|
27
|
-
queryKey: readonly ["@comapeo/core-react", "maps", string, "stylejson_url"] & {
|
|
28
|
-
[dataTagSymbol]: string;
|
|
29
|
-
[dataTagErrorSymbol]: Error;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export declare function mapInfoQueryOptions({ mapServerApi, mapId, }: {
|
|
33
|
-
mapServerApi: MapServerApi;
|
|
34
|
-
mapId?: string;
|
|
35
|
-
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<{
|
|
36
|
-
mapId: string;
|
|
37
|
-
mapName: string;
|
|
38
|
-
estimatedSizeBytes: number;
|
|
39
|
-
bounds: readonly [number, number, number, number];
|
|
40
|
-
minzoom: number;
|
|
41
|
-
maxzoom: number;
|
|
42
|
-
mapCreatedAt: number;
|
|
43
|
-
}, Error, {
|
|
44
|
-
mapId: string;
|
|
45
|
-
mapName: string;
|
|
46
|
-
estimatedSizeBytes: number;
|
|
47
|
-
bounds: readonly [number, number, number, number];
|
|
48
|
-
minzoom: number;
|
|
49
|
-
maxzoom: number;
|
|
50
|
-
mapCreatedAt: number;
|
|
51
|
-
}, readonly ["@comapeo/core-react", "maps", string, "info"]>, "queryFn"> & {
|
|
52
|
-
queryFn?: import("@tanstack/react-query").QueryFunction<{
|
|
53
|
-
mapId: string;
|
|
54
|
-
mapName: string;
|
|
55
|
-
estimatedSizeBytes: number;
|
|
56
|
-
bounds: readonly [number, number, number, number];
|
|
57
|
-
minzoom: number;
|
|
58
|
-
maxzoom: number;
|
|
59
|
-
mapCreatedAt: number;
|
|
60
|
-
}, readonly ["@comapeo/core-react", "maps", string, "info"], never> | undefined;
|
|
61
|
-
} & {
|
|
62
|
-
queryKey: readonly ["@comapeo/core-react", "maps", string, "info"] & {
|
|
63
|
-
[dataTagSymbol]: {
|
|
64
|
-
mapId: string;
|
|
65
|
-
mapName: string;
|
|
66
|
-
estimatedSizeBytes: number;
|
|
67
|
-
bounds: readonly [number, number, number, number];
|
|
68
|
-
minzoom: number;
|
|
69
|
-
maxzoom: number;
|
|
70
|
-
mapCreatedAt: number;
|
|
71
|
-
};
|
|
72
|
-
[dataTagErrorSymbol]: Error;
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
export declare function mapImportMutationOptions({ mapServerApi, queryClient, }: {
|
|
76
|
-
mapServerApi: MapServerApi;
|
|
77
|
-
queryClient: QueryClient;
|
|
78
|
-
}): {
|
|
79
|
-
mutationFn: ({ file }: {
|
|
80
|
-
file: File | ExpoFileDuckType;
|
|
81
|
-
}) => Promise<Response>;
|
|
82
|
-
onSuccess: () => Promise<void>;
|
|
83
|
-
networkMode: "always";
|
|
84
|
-
retry: false;
|
|
85
|
-
};
|
|
86
|
-
export declare function mapRemoveMutationOptions({ mapServerApi, queryClient, }: {
|
|
87
|
-
mapServerApi: MapServerApi;
|
|
88
|
-
queryClient: QueryClient;
|
|
89
|
-
}): {
|
|
90
|
-
mutationFn: () => Promise<Response>;
|
|
91
|
-
onSuccess: () => Promise<void>;
|
|
92
|
-
networkMode: "always";
|
|
93
|
-
retry: false;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Mutation options for actions on sent map shares
|
|
97
|
-
*/
|
|
98
|
-
export declare function mapSharesMutationOptions<TAction extends SentMapSharesStore['actions'][keyof SentMapSharesStore['actions']] | keyof ReceivedMapSharesStore['actions'][keyof ReceivedMapSharesStore['actions']]>(options: {
|
|
99
|
-
action: Exclude<TAction, SentMapSharesStore['actions']['createAndSend']>;
|
|
100
|
-
} | {
|
|
101
|
-
action: SentMapSharesStore['actions']['createAndSend'];
|
|
102
|
-
projectId: string;
|
|
103
|
-
}): UseMutationOptions<ReturnType<TAction>, Error, TAction extends SentMapSharesStore['actions']['createAndSend'] ? Parameters<TAction>[0] : Omit<Parameters<TAction>[0], 'projectId'>>;
|
|
104
|
-
export {};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMapQueryKey = getMapQueryKey;
|
|
4
|
-
exports.getStyleJsonUrlQueryKey = getStyleJsonUrlQueryKey;
|
|
5
|
-
exports.invalidateMapQueries = invalidateMapQueries;
|
|
6
|
-
exports.mapStyleJsonUrlQueryOptions = mapStyleJsonUrlQueryOptions;
|
|
7
|
-
exports.mapInfoQueryOptions = mapInfoQueryOptions;
|
|
8
|
-
exports.mapImportMutationOptions = mapImportMutationOptions;
|
|
9
|
-
exports.mapRemoveMutationOptions = mapRemoveMutationOptions;
|
|
10
|
-
exports.mapSharesMutationOptions = mapSharesMutationOptions;
|
|
11
|
-
const constants_js_1 = require("@comapeo/map-server/constants.js");
|
|
12
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
13
|
-
const shared_js_1 = require("./shared.js");
|
|
14
|
-
// ============================================
|
|
15
|
-
// QUERY KEYS
|
|
16
|
-
// ============================================
|
|
17
|
-
const MAPS_ROOT_QUERY_KEY = [shared_js_1.ROOT_QUERY_KEY, 'maps'];
|
|
18
|
-
function getMapQueryKey({ mapId }) {
|
|
19
|
-
return [...MAPS_ROOT_QUERY_KEY, mapId];
|
|
20
|
-
}
|
|
21
|
-
function getStyleJsonUrlQueryKey({ mapId }) {
|
|
22
|
-
return [...getMapQueryKey({ mapId }), 'stylejson_url'];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Invalidate queries for this map and the default map (which internally
|
|
26
|
-
* redirects to custom) so that they will be refetched with the new map data.
|
|
27
|
-
*/
|
|
28
|
-
async function invalidateMapQueries(queryClient, { mapId }) {
|
|
29
|
-
await Promise.all([
|
|
30
|
-
queryClient.invalidateQueries({
|
|
31
|
-
queryKey: getMapQueryKey({ mapId }),
|
|
32
|
-
}),
|
|
33
|
-
queryClient.invalidateQueries({
|
|
34
|
-
queryKey: getMapQueryKey({ mapId: constants_js_1.DEFAULT_MAP_ID }),
|
|
35
|
-
}),
|
|
36
|
-
]);
|
|
37
|
-
}
|
|
38
|
-
// ============================================
|
|
39
|
-
// QUERY OPTIONS
|
|
40
|
-
// ============================================
|
|
41
|
-
function mapStyleJsonUrlQueryOptions({ mapServerApi, mapId = constants_js_1.DEFAULT_MAP_ID, }) {
|
|
42
|
-
if (mapId !== constants_js_1.DEFAULT_MAP_ID) {
|
|
43
|
-
throw new Error('Custom map IDs are not supported yet');
|
|
44
|
-
}
|
|
45
|
-
return (0, react_query_1.queryOptions)({
|
|
46
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
47
|
-
queryKey: getStyleJsonUrlQueryKey({ mapId }),
|
|
48
|
-
queryFn: async () => {
|
|
49
|
-
const result = await mapServerApi.getMapStyleJsonUrl(mapId);
|
|
50
|
-
const u = new URL(result);
|
|
51
|
-
// This ensures that every time this query is refetched, it will have a different search param, forcing the map to reload.
|
|
52
|
-
u.searchParams.set('refresh_token', Date.now().toString());
|
|
53
|
-
return u.href;
|
|
54
|
-
},
|
|
55
|
-
// Keep this cached until the cache is manually invalidated by a map upload
|
|
56
|
-
staleTime: Infinity,
|
|
57
|
-
gcTime: Infinity,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function mapInfoQueryOptions({ mapServerApi, mapId = constants_js_1.DEFAULT_MAP_ID, }) {
|
|
61
|
-
if (mapId !== constants_js_1.CUSTOM_MAP_ID) {
|
|
62
|
-
throw new Error('Only custom map ID is currently supported');
|
|
63
|
-
}
|
|
64
|
-
return (0, react_query_1.queryOptions)({
|
|
65
|
-
...(0, shared_js_1.baseQueryOptions)(),
|
|
66
|
-
queryKey: [...getMapQueryKey({ mapId }), 'info'],
|
|
67
|
-
queryFn: async () => {
|
|
68
|
-
return mapServerApi.get(`maps/${mapId}/info`).json();
|
|
69
|
-
},
|
|
70
|
-
// Keep this cached until the cache is manually invalidated by a map upload
|
|
71
|
-
staleTime: Infinity,
|
|
72
|
-
gcTime: Infinity,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
// ============================================
|
|
76
|
-
// MUTATION OPTIONS
|
|
77
|
-
// ============================================
|
|
78
|
-
function mapImportMutationOptions({ mapServerApi, queryClient, }) {
|
|
79
|
-
// TODO: Support importing to custom map IDs, to support multiple maps.
|
|
80
|
-
const mapId = constants_js_1.CUSTOM_MAP_ID;
|
|
81
|
-
return {
|
|
82
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
83
|
-
mutationFn: async ({ file }) => {
|
|
84
|
-
if ('exists' in file && !file.exists) {
|
|
85
|
-
throw new Error('File does not exist or is not accessible');
|
|
86
|
-
}
|
|
87
|
-
return mapServerApi.put(`maps/${mapId}`, {
|
|
88
|
-
body: file,
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/octet-stream',
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
onSuccess: async () => {
|
|
95
|
-
await invalidateMapQueries(queryClient, { mapId });
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function mapRemoveMutationOptions({ mapServerApi, queryClient, }) {
|
|
100
|
-
// TODO: Support removing from custom map IDs, to support multiple maps.
|
|
101
|
-
const mapId = constants_js_1.CUSTOM_MAP_ID;
|
|
102
|
-
return {
|
|
103
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
104
|
-
mutationFn: async () => {
|
|
105
|
-
return mapServerApi.delete(`maps/${mapId}`);
|
|
106
|
-
},
|
|
107
|
-
onSuccess: async () => {
|
|
108
|
-
await invalidateMapQueries(queryClient, { mapId });
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Mutation options for actions on sent map shares
|
|
114
|
-
*/
|
|
115
|
-
function mapSharesMutationOptions(options) {
|
|
116
|
-
return {
|
|
117
|
-
...(0, shared_js_1.baseMutationOptions)(),
|
|
118
|
-
mutationFn: async (variables) => {
|
|
119
|
-
// For consistency with other hooks, we use `projectId` as a parameter of
|
|
120
|
-
// the hook, rather than a parameter of the mutate function.
|
|
121
|
-
const actionOptions = 'projectId' in options
|
|
122
|
-
? { ...variables, projectId: options.projectId }
|
|
123
|
-
: variables;
|
|
124
|
-
return options.action(
|
|
125
|
-
// @ts-expect-error - TS can't help us here
|
|
126
|
-
actionOptions);
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { UseMutationResult } from '@tanstack/react-query';
|
|
2
|
-
import type { DistributedPick } from 'type-fest';
|
|
3
|
-
/**
|
|
4
|
-
* Filters a `UseMutationResult` to only include a subset of its keys, and uses
|
|
5
|
-
* `DistributedPick` to preserve the discriminated union types of the mutation
|
|
6
|
-
* result based on the `status` property.
|
|
7
|
-
*/
|
|
8
|
-
export declare function filterMutationResult<TResult extends UseMutationResult<any, any, any, any>>(mutationResult: TResult): DistributedPick<TResult, "error" | "status" | "mutate" | "reset" | "mutateAsync">;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterMutationResult = filterMutationResult;
|
|
4
|
-
const PICKED_MUTATION_RESULT_KEYS = [
|
|
5
|
-
'error',
|
|
6
|
-
'mutate',
|
|
7
|
-
'mutateAsync',
|
|
8
|
-
'reset',
|
|
9
|
-
'status',
|
|
10
|
-
];
|
|
11
|
-
/**
|
|
12
|
-
* Filters a `UseMutationResult` to only include a subset of its keys, and uses
|
|
13
|
-
* `DistributedPick` to preserve the discriminated union types of the mutation
|
|
14
|
-
* result based on the `status` property.
|
|
15
|
-
*/
|
|
16
|
-
function filterMutationResult(mutationResult) {
|
|
17
|
-
const filteredResult = {};
|
|
18
|
-
for (const key of PICKED_MUTATION_RESULT_KEYS) {
|
|
19
|
-
filteredResult[key] = mutationResult[key];
|
|
20
|
-
}
|
|
21
|
-
return filteredResult;
|
|
22
|
-
}
|