@comapeo/core-react 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/contexts/ClientApi.d.ts +14 -0
- package/dist/commonjs/contexts/ClientApi.js +16 -0
- package/dist/commonjs/hooks/client.d.ts +80 -0
- package/dist/commonjs/hooks/client.js +91 -0
- package/dist/{hooks → commonjs/hooks}/documents.d.ts +60 -5
- package/dist/commonjs/hooks/documents.js +192 -0
- package/dist/commonjs/hooks/invites.d.ts +51 -0
- package/dist/commonjs/hooks/invites.js +50 -0
- package/dist/commonjs/hooks/maps.js +37 -0
- package/dist/commonjs/hooks/projects.d.ts +334 -0
- package/dist/commonjs/hooks/projects.js +320 -0
- package/dist/commonjs/index.d.ts +12 -0
- package/dist/commonjs/index.js +69 -0
- package/dist/commonjs/lib/react-query/client.d.ts +61 -0
- package/dist/commonjs/lib/react-query/client.js +68 -0
- package/dist/{lib → commonjs/lib}/react-query/documents.d.ts +789 -706
- package/dist/commonjs/lib/react-query/documents.js +149 -0
- package/dist/commonjs/lib/react-query/invites.d.ts +71 -0
- package/dist/commonjs/lib/react-query/invites.js +85 -0
- package/dist/commonjs/lib/react-query/maps.d.ts +24 -0
- package/dist/commonjs/lib/react-query/maps.js +27 -0
- package/dist/commonjs/lib/react-query/projects.d.ts +332 -0
- package/dist/commonjs/lib/react-query/projects.js +235 -0
- package/dist/{lib → commonjs/lib}/react-query/shared.d.ts +5 -1
- package/dist/commonjs/lib/react-query/shared.js +23 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/{contexts → esm/contexts}/ClientApi.d.ts +3 -3
- package/dist/{hooks → esm/hooks}/client.d.ts +23 -2
- package/dist/{hooks → esm/hooks}/client.js +21 -3
- package/dist/esm/hooks/documents.d.ts +167 -0
- package/dist/{hooks → esm/hooks}/documents.js +54 -3
- package/dist/esm/hooks/invites.d.ts +51 -0
- package/dist/esm/hooks/invites.js +44 -0
- package/dist/esm/hooks/maps.d.ts +33 -0
- package/dist/{hooks → esm/hooks}/maps.js +2 -2
- package/dist/{hooks → esm/hooks}/projects.d.ts +89 -6
- package/dist/{hooks → esm/hooks}/projects.js +59 -3
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/lib/react-query/client.d.ts +61 -0
- package/dist/esm/lib/react-query/client.js +59 -0
- package/dist/esm/lib/react-query/documents.d.ts +1584 -0
- package/dist/{lib → esm/lib}/react-query/documents.js +56 -2
- package/dist/esm/lib/react-query/invites.d.ts +71 -0
- package/dist/esm/lib/react-query/invites.js +76 -0
- package/dist/esm/lib/react-query/maps.d.ts +24 -0
- package/dist/{lib → esm/lib}/react-query/maps.js +6 -2
- package/dist/esm/lib/react-query/projects.d.ts +332 -0
- package/dist/{lib → esm/lib}/react-query/projects.js +84 -2
- package/dist/esm/lib/react-query/shared.d.ts +9 -0
- package/dist/{lib → esm/lib}/react-query/shared.js +7 -1
- package/dist/esm/package.json +3 -0
- package/docs/API.md +157 -258
- package/package.json +51 -37
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -11
- package/dist/lib/react-query/client.d.ts +0 -30
- package/dist/lib/react-query/client.js +0 -29
- package/dist/lib/react-query/invites.d.ts +0 -12
- package/dist/lib/react-query/invites.js +0 -17
- package/dist/lib/react-query/maps.d.ts +0 -15
- package/dist/lib/react-query/projects.d.ts +0 -196
- /package/dist/{hooks → commonjs/hooks}/maps.d.ts +0 -0
- /package/dist/{contexts → esm/contexts}/ClientApi.js +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { RoleIdForNewInvite } from '@comapeo/core/dist/roles.js' with { 'resolution-mode': 'import' };
|
|
2
|
+
import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
|
|
3
|
+
import { type QueryClient } from '@tanstack/react-query';
|
|
4
|
+
export declare function getInvitesQueryKey(): readonly ["@comapeo/core-react", "invites"];
|
|
5
|
+
export declare function getPendingInvitesQueryKey(): readonly ["@comapeo/core-react", "invites", {
|
|
6
|
+
readonly status: "pending";
|
|
7
|
+
}];
|
|
8
|
+
export declare function pendingInvitesQueryOptions({ clientApi, }: {
|
|
9
|
+
clientApi: MapeoClientApi;
|
|
10
|
+
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/types.js", { with: { "resolution-mode": "import" } }).MapBuffers<import("@comapeo/core/dist/invite-api.js", { with: { "resolution-mode": "import" } }).InviteInternal>[], Error, import("@comapeo/core/dist/types.js", { with: { "resolution-mode": "import" } }).MapBuffers<import("@comapeo/core/dist/invite-api.js", { with: { "resolution-mode": "import" } }).InviteInternal>[], readonly ["@comapeo/core-react", "invites", {
|
|
11
|
+
readonly status: "pending";
|
|
12
|
+
}]>, "queryFn"> & {
|
|
13
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/types.js", { with: { "resolution-mode": "import" } }).MapBuffers<import("@comapeo/core/dist/invite-api.js", { with: { "resolution-mode": "import" } }).InviteInternal>[], readonly ["@comapeo/core-react", "invites", {
|
|
14
|
+
readonly status: "pending";
|
|
15
|
+
}], never> | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
queryKey: readonly ["@comapeo/core-react", "invites", {
|
|
18
|
+
readonly status: "pending";
|
|
19
|
+
}] & {
|
|
20
|
+
[dataTagSymbol]: import("@comapeo/core/dist/types.js", { with: { "resolution-mode": "import" } }).MapBuffers<import("@comapeo/core/dist/invite-api.js", { with: { "resolution-mode": "import" } }).InviteInternal>[];
|
|
21
|
+
[dataTagErrorSymbol]: Error;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare function acceptInviteMutationOptions({ clientApi, queryClient, }: {
|
|
25
|
+
clientApi: MapeoClientApi;
|
|
26
|
+
queryClient: QueryClient;
|
|
27
|
+
}): {
|
|
28
|
+
mutationFn: ({ inviteId }: {
|
|
29
|
+
inviteId: string;
|
|
30
|
+
}) => Promise<string>;
|
|
31
|
+
onSuccess: () => void;
|
|
32
|
+
networkMode: "always";
|
|
33
|
+
retry: false;
|
|
34
|
+
};
|
|
35
|
+
export declare function rejectInviteMutationOptions({ clientApi, queryClient, }: {
|
|
36
|
+
clientApi: MapeoClientApi;
|
|
37
|
+
queryClient: QueryClient;
|
|
38
|
+
}): {
|
|
39
|
+
mutationFn: ({ inviteId }: {
|
|
40
|
+
inviteId: string;
|
|
41
|
+
}) => Promise<void>;
|
|
42
|
+
onSuccess: () => void;
|
|
43
|
+
networkMode: "always";
|
|
44
|
+
retry: false;
|
|
45
|
+
};
|
|
46
|
+
export declare function sendInviteMutationOptions({ projectApi, projectId, queryClient, }: {
|
|
47
|
+
projectApi: MapeoProjectApi;
|
|
48
|
+
projectId: string;
|
|
49
|
+
queryClient: QueryClient;
|
|
50
|
+
}): {
|
|
51
|
+
mutationFn: ({ deviceId, ...role }: {
|
|
52
|
+
deviceId: string;
|
|
53
|
+
roleDescription?: string;
|
|
54
|
+
roleId: RoleIdForNewInvite;
|
|
55
|
+
roleName?: string;
|
|
56
|
+
}) => Promise<"ACCEPT" | "REJECT" | "ALREADY">;
|
|
57
|
+
onSuccess: () => void;
|
|
58
|
+
networkMode: "always";
|
|
59
|
+
retry: false;
|
|
60
|
+
};
|
|
61
|
+
export declare function requestCancelInviteMutationOptions({ projectApi, queryClient, }: {
|
|
62
|
+
projectApi: MapeoProjectApi;
|
|
63
|
+
queryClient: QueryClient;
|
|
64
|
+
}): {
|
|
65
|
+
mutationFn: ({ deviceId }: {
|
|
66
|
+
deviceId: string;
|
|
67
|
+
}) => Promise<void>;
|
|
68
|
+
onSuccess: () => void;
|
|
69
|
+
networkMode: "always";
|
|
70
|
+
retry: false;
|
|
71
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInvitesQueryKey = getInvitesQueryKey;
|
|
4
|
+
exports.getPendingInvitesQueryKey = getPendingInvitesQueryKey;
|
|
5
|
+
exports.pendingInvitesQueryOptions = pendingInvitesQueryOptions;
|
|
6
|
+
exports.acceptInviteMutationOptions = acceptInviteMutationOptions;
|
|
7
|
+
exports.rejectInviteMutationOptions = rejectInviteMutationOptions;
|
|
8
|
+
exports.sendInviteMutationOptions = sendInviteMutationOptions;
|
|
9
|
+
exports.requestCancelInviteMutationOptions = requestCancelInviteMutationOptions;
|
|
10
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
11
|
+
const projects_js_1 = require("./projects.js");
|
|
12
|
+
const shared_js_1 = require("./shared.js");
|
|
13
|
+
function getInvitesQueryKey() {
|
|
14
|
+
return [shared_js_1.ROOT_QUERY_KEY, 'invites'];
|
|
15
|
+
}
|
|
16
|
+
function getPendingInvitesQueryKey() {
|
|
17
|
+
return [shared_js_1.ROOT_QUERY_KEY, 'invites', { status: 'pending' }];
|
|
18
|
+
}
|
|
19
|
+
function pendingInvitesQueryOptions({ clientApi, }) {
|
|
20
|
+
return (0, react_query_1.queryOptions)({
|
|
21
|
+
...(0, shared_js_1.baseQueryOptions)(),
|
|
22
|
+
queryKey: getPendingInvitesQueryKey(),
|
|
23
|
+
queryFn: async () => {
|
|
24
|
+
return clientApi.invite.getPending();
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function acceptInviteMutationOptions({ clientApi, queryClient, }) {
|
|
29
|
+
return {
|
|
30
|
+
...(0, shared_js_1.baseMutationOptions)(),
|
|
31
|
+
mutationFn: async ({ inviteId }) => {
|
|
32
|
+
return clientApi.invite.accept({ inviteId });
|
|
33
|
+
},
|
|
34
|
+
onSuccess: () => {
|
|
35
|
+
queryClient.invalidateQueries({
|
|
36
|
+
queryKey: getInvitesQueryKey(),
|
|
37
|
+
});
|
|
38
|
+
queryClient.invalidateQueries({
|
|
39
|
+
queryKey: (0, projects_js_1.getProjectsQueryKey)(),
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function rejectInviteMutationOptions({ clientApi, queryClient, }) {
|
|
45
|
+
return {
|
|
46
|
+
...(0, shared_js_1.baseMutationOptions)(),
|
|
47
|
+
mutationFn: async ({ inviteId }) => {
|
|
48
|
+
return clientApi.invite.reject({ inviteId });
|
|
49
|
+
},
|
|
50
|
+
onSuccess: () => {
|
|
51
|
+
queryClient.invalidateQueries({
|
|
52
|
+
queryKey: getInvitesQueryKey(),
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function sendInviteMutationOptions({ projectApi, projectId, queryClient, }) {
|
|
58
|
+
return {
|
|
59
|
+
...(0, shared_js_1.baseMutationOptions)(),
|
|
60
|
+
mutationFn: async ({ deviceId, ...role }) => {
|
|
61
|
+
return projectApi.$member.invite(deviceId, role);
|
|
62
|
+
},
|
|
63
|
+
onSuccess: () => {
|
|
64
|
+
queryClient.invalidateQueries({
|
|
65
|
+
queryKey: getInvitesQueryKey(),
|
|
66
|
+
});
|
|
67
|
+
queryClient.invalidateQueries({
|
|
68
|
+
queryKey: (0, projects_js_1.getMembersQueryKey)({ projectId }),
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function requestCancelInviteMutationOptions({ projectApi, queryClient, }) {
|
|
74
|
+
return {
|
|
75
|
+
...(0, shared_js_1.baseMutationOptions)(),
|
|
76
|
+
mutationFn: async ({ deviceId }) => {
|
|
77
|
+
return projectApi.$member.requestCancelInvite(deviceId);
|
|
78
|
+
},
|
|
79
|
+
onSuccess: () => {
|
|
80
|
+
queryClient.invalidateQueries({
|
|
81
|
+
queryKey: getInvitesQueryKey(),
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
|
|
2
|
+
export declare function getMapsQueryKey(): readonly ["@comapeo/core-react", "maps"];
|
|
3
|
+
export declare function getStyleJsonUrlQueryKey({ refreshToken, }: {
|
|
4
|
+
refreshToken?: string;
|
|
5
|
+
}): readonly ["@comapeo/core-react", "maps", "stylejson_url", {
|
|
6
|
+
readonly refreshToken: string | undefined;
|
|
7
|
+
}];
|
|
8
|
+
export declare function mapStyleJsonUrlQueryOptions({ clientApi, refreshToken, }: {
|
|
9
|
+
clientApi: MapeoClientApi;
|
|
10
|
+
refreshToken?: string;
|
|
11
|
+
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, readonly ["@comapeo/core-react", "maps", "stylejson_url", {
|
|
12
|
+
readonly refreshToken: string | undefined;
|
|
13
|
+
}]>, "queryFn"> & {
|
|
14
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<string, readonly ["@comapeo/core-react", "maps", "stylejson_url", {
|
|
15
|
+
readonly refreshToken: string | undefined;
|
|
16
|
+
}], never> | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
queryKey: readonly ["@comapeo/core-react", "maps", "stylejson_url", {
|
|
19
|
+
readonly refreshToken: string | undefined;
|
|
20
|
+
}] & {
|
|
21
|
+
[dataTagSymbol]: string;
|
|
22
|
+
[dataTagErrorSymbol]: Error;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMapsQueryKey = getMapsQueryKey;
|
|
4
|
+
exports.getStyleJsonUrlQueryKey = getStyleJsonUrlQueryKey;
|
|
5
|
+
exports.mapStyleJsonUrlQueryOptions = mapStyleJsonUrlQueryOptions;
|
|
6
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
7
|
+
const shared_js_1 = require("./shared.js");
|
|
8
|
+
function getMapsQueryKey() {
|
|
9
|
+
return [shared_js_1.ROOT_QUERY_KEY, 'maps'];
|
|
10
|
+
}
|
|
11
|
+
function getStyleJsonUrlQueryKey({ refreshToken, }) {
|
|
12
|
+
return [shared_js_1.ROOT_QUERY_KEY, 'maps', 'stylejson_url', { refreshToken }];
|
|
13
|
+
}
|
|
14
|
+
function mapStyleJsonUrlQueryOptions({ clientApi, refreshToken, }) {
|
|
15
|
+
return (0, react_query_1.queryOptions)({
|
|
16
|
+
...(0, shared_js_1.baseQueryOptions)(),
|
|
17
|
+
queryKey: getStyleJsonUrlQueryKey({ refreshToken }),
|
|
18
|
+
queryFn: async () => {
|
|
19
|
+
const result = await clientApi.getMapStyleJsonUrl();
|
|
20
|
+
if (!refreshToken)
|
|
21
|
+
return result;
|
|
22
|
+
const u = new URL(result);
|
|
23
|
+
u.searchParams.set('refresh_token', refreshToken);
|
|
24
|
+
return u.href;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|