@comapeo/core-react 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/contexts/ClientApi.d.ts +14 -0
- package/dist/contexts/ClientApi.js +12 -0
- package/dist/hooks/client.d.ts +59 -0
- package/dist/hooks/client.js +66 -0
- package/dist/hooks/documents.d.ts +475 -0
- package/dist/hooks/documents.js +124 -0
- package/dist/hooks/maps.d.ts +34 -0
- package/dist/hooks/maps.js +35 -0
- package/dist/hooks/projects.d.ts +261 -0
- package/dist/hooks/projects.js +257 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/lib/react-query/client.d.ts +30 -0
- package/dist/lib/react-query/client.js +29 -0
- package/dist/lib/react-query/documents.d.ts +1492 -0
- package/dist/lib/react-query/documents.js +62 -0
- package/dist/lib/react-query/invites.d.ts +12 -0
- package/dist/lib/react-query/invites.js +17 -0
- package/dist/lib/react-query/maps.d.ts +15 -0
- package/dist/lib/react-query/maps.js +18 -0
- package/dist/lib/react-query/projects.d.ts +188 -0
- package/dist/lib/react-query/projects.js +120 -0
- package/dist/lib/react-query/shared.d.ts +5 -0
- package/dist/lib/react-query/shared.js +12 -0
- package/docs/API.md +783 -0
- package/package.json +80 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { baseQueryOptions, ROOT_QUERY_KEY } from './shared';
|
|
3
|
+
export function getDocumentsQueryKey({ projectId, docType, }) {
|
|
4
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, docType];
|
|
5
|
+
}
|
|
6
|
+
export function getManyDocumentsQueryKey({ projectId, docType, opts, }) {
|
|
7
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, docType, opts];
|
|
8
|
+
}
|
|
9
|
+
export function getDocumentByDocIdQueryKey({ projectId, docType, docId, opts, }) {
|
|
10
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, docType, docId, opts];
|
|
11
|
+
}
|
|
12
|
+
export function getDocumentByVersionIdQueryKey({ projectId, docType, versionId, opts, }) {
|
|
13
|
+
return [
|
|
14
|
+
ROOT_QUERY_KEY,
|
|
15
|
+
'projects',
|
|
16
|
+
projectId,
|
|
17
|
+
docType,
|
|
18
|
+
versionId,
|
|
19
|
+
opts,
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
export function documentsQueryOptions({ projectApi, projectId, docType, opts, }) {
|
|
23
|
+
return queryOptions({
|
|
24
|
+
...baseQueryOptions(),
|
|
25
|
+
queryKey: getManyDocumentsQueryKey({ projectId, docType, opts }),
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
return projectApi[docType].getMany(opts);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function documentByDocumentIdQueryOptions({ projectApi, projectId, docType, docId, opts, }) {
|
|
32
|
+
return queryOptions({
|
|
33
|
+
...baseQueryOptions(),
|
|
34
|
+
queryKey: getDocumentByDocIdQueryKey({
|
|
35
|
+
projectId,
|
|
36
|
+
docType,
|
|
37
|
+
docId,
|
|
38
|
+
opts,
|
|
39
|
+
}),
|
|
40
|
+
queryFn: async () => {
|
|
41
|
+
return projectApi[docType].getByDocId(docId, {
|
|
42
|
+
...opts,
|
|
43
|
+
// We want to make sure that this throws in the case that no match is found
|
|
44
|
+
mustBeFound: true,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export function documentByVersionIdQueryOptions({ projectApi, projectId, docType, versionId, opts, }) {
|
|
50
|
+
return queryOptions({
|
|
51
|
+
...baseQueryOptions(),
|
|
52
|
+
queryKey: getDocumentByVersionIdQueryKey({
|
|
53
|
+
projectId,
|
|
54
|
+
docType,
|
|
55
|
+
versionId,
|
|
56
|
+
opts,
|
|
57
|
+
}),
|
|
58
|
+
queryFn: async () => {
|
|
59
|
+
return projectApi[docType].getByVersionId(versionId, opts);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MapeoClientApi } from '@comapeo/ipc';
|
|
2
|
+
export declare function getInvitesQueryKey(): readonly ["@comapeo/core-react", "invites"];
|
|
3
|
+
export declare function getPendingInvitesQueryKey(): readonly ["@comapeo/core-react", "invites", {
|
|
4
|
+
readonly status: "pending";
|
|
5
|
+
}];
|
|
6
|
+
export declare function pendingInvitesQueryOptions({ clientApi, }: {
|
|
7
|
+
clientApi: MapeoClientApi;
|
|
8
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/types").MapBuffers<import("@comapeo/core/dist/invite-api").InviteInternal>[], Error, import("@comapeo/core/dist/types").MapBuffers<import("@comapeo/core/dist/invite-api").InviteInternal>[], import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
9
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<import("@comapeo/core/dist/types").MapBuffers<import("@comapeo/core/dist/invite-api").InviteInternal>[], import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
10
|
+
} & {
|
|
11
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, import("@comapeo/core/dist/types").MapBuffers<import("@comapeo/core/dist/invite-api").InviteInternal>[]>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { baseQueryOptions, ROOT_QUERY_KEY } from './shared';
|
|
3
|
+
export function getInvitesQueryKey() {
|
|
4
|
+
return [ROOT_QUERY_KEY, 'invites'];
|
|
5
|
+
}
|
|
6
|
+
export function getPendingInvitesQueryKey() {
|
|
7
|
+
return [ROOT_QUERY_KEY, 'invites', { status: 'pending' }];
|
|
8
|
+
}
|
|
9
|
+
export function pendingInvitesQueryOptions({ clientApi, }) {
|
|
10
|
+
return queryOptions({
|
|
11
|
+
...baseQueryOptions(),
|
|
12
|
+
queryKey: getPendingInvitesQueryKey(),
|
|
13
|
+
queryFn: async () => {
|
|
14
|
+
return clientApi.invite.getPending();
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MapeoClientApi } from '@comapeo/ipc';
|
|
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/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
12
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<string, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
13
|
+
} & {
|
|
14
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, string>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { baseQueryOptions, ROOT_QUERY_KEY } from './shared';
|
|
3
|
+
export function getMapsQueryKey() {
|
|
4
|
+
return [ROOT_QUERY_KEY, 'maps'];
|
|
5
|
+
}
|
|
6
|
+
export function getStyleJsonUrlQueryKey({ refreshToken, }) {
|
|
7
|
+
return [ROOT_QUERY_KEY, 'maps', 'stylejson_url', { refreshToken }];
|
|
8
|
+
}
|
|
9
|
+
export function mapStyleJsonUrlQueryOptions({ clientApi, refreshToken, }) {
|
|
10
|
+
return queryOptions({
|
|
11
|
+
...baseQueryOptions(),
|
|
12
|
+
queryKey: getStyleJsonUrlQueryKey({ refreshToken }),
|
|
13
|
+
queryFn: async () => {
|
|
14
|
+
const result = await clientApi.getMapStyleJsonUrl();
|
|
15
|
+
return refreshToken ? result + `?refresh_token=${refreshToken}` : result;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { BlobId } from '@comapeo/core/dist/types.js';
|
|
2
|
+
import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc';
|
|
3
|
+
export declare function getProjectsQueryKey(): readonly ["@comapeo/core-react", "projects"];
|
|
4
|
+
export declare function getProjectByIdQueryKey({ projectId }: {
|
|
5
|
+
projectId: string;
|
|
6
|
+
}): readonly ["@comapeo/core-react", "projects", string];
|
|
7
|
+
export declare function getProjectSettingsQueryKey({ projectId, }: {
|
|
8
|
+
projectId: string;
|
|
9
|
+
}): readonly ["@comapeo/core-react", "projects", string, "project_settings"];
|
|
10
|
+
export declare function getProjectRoleQueryKey({ projectId }: {
|
|
11
|
+
projectId: string;
|
|
12
|
+
}): readonly ["@comapeo/core-react", "projects", string, "role"];
|
|
13
|
+
export declare function getMembersQueryKey({ projectId }: {
|
|
14
|
+
projectId: string;
|
|
15
|
+
}): readonly ["@comapeo/core-react", "projects", string, "members"];
|
|
16
|
+
export declare function getMemberByIdQueryKey({ projectId, deviceId, }: {
|
|
17
|
+
projectId: string;
|
|
18
|
+
deviceId: string;
|
|
19
|
+
}): readonly ["@comapeo/core-react", "projects", string, "members", string];
|
|
20
|
+
export declare function getIconUrlQueryKey({ projectId, iconId, opts, }: {
|
|
21
|
+
projectId: string;
|
|
22
|
+
iconId: Parameters<MapeoProjectApi['$icons']['getIconUrl']>[0];
|
|
23
|
+
opts: Parameters<MapeoProjectApi['$icons']['getIconUrl']>[1];
|
|
24
|
+
}): readonly ["@comapeo/core-react", "projects", string, "icons", string, import("@comapeo/core/dist/icon-api").BitmapOpts | import("@comapeo/core/dist/icon-api").SvgOpts];
|
|
25
|
+
export declare function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }: {
|
|
26
|
+
projectId: string;
|
|
27
|
+
originalVersionId: string;
|
|
28
|
+
}): readonly ["@comapeo/core-react", "projects", string, "document_created_by", string];
|
|
29
|
+
export declare function getAttachmentUrlQueryKey({ projectId, blobId, }: {
|
|
30
|
+
projectId: string;
|
|
31
|
+
blobId: BlobId;
|
|
32
|
+
}): readonly ["@comapeo/core-react", "projects", string, "attachments", BlobId];
|
|
33
|
+
export declare function projectsQueryOptions({ clientApi, }: {
|
|
34
|
+
clientApi: MapeoClientApi;
|
|
35
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<(Pick<{
|
|
36
|
+
schemaName: "projectSettings";
|
|
37
|
+
name?: string | undefined;
|
|
38
|
+
defaultPresets?: {
|
|
39
|
+
point: string[];
|
|
40
|
+
area: string[];
|
|
41
|
+
vertex: string[];
|
|
42
|
+
line: string[];
|
|
43
|
+
relation: string[];
|
|
44
|
+
} | undefined;
|
|
45
|
+
configMetadata?: {
|
|
46
|
+
name: string;
|
|
47
|
+
buildDate: string;
|
|
48
|
+
importDate: string;
|
|
49
|
+
fileVersion: string;
|
|
50
|
+
} | undefined;
|
|
51
|
+
}, "name"> & {
|
|
52
|
+
projectId: string;
|
|
53
|
+
createdAt?: string | undefined;
|
|
54
|
+
updatedAt?: string | undefined;
|
|
55
|
+
})[], Error, (Pick<{
|
|
56
|
+
schemaName: "projectSettings";
|
|
57
|
+
name?: string | undefined;
|
|
58
|
+
defaultPresets?: {
|
|
59
|
+
point: string[];
|
|
60
|
+
area: string[];
|
|
61
|
+
vertex: string[];
|
|
62
|
+
line: string[];
|
|
63
|
+
relation: string[];
|
|
64
|
+
} | undefined;
|
|
65
|
+
configMetadata?: {
|
|
66
|
+
name: string;
|
|
67
|
+
buildDate: string;
|
|
68
|
+
importDate: string;
|
|
69
|
+
fileVersion: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
}, "name"> & {
|
|
72
|
+
projectId: string;
|
|
73
|
+
createdAt?: string | undefined;
|
|
74
|
+
updatedAt?: string | undefined;
|
|
75
|
+
})[], import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
76
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<(Pick<{
|
|
77
|
+
schemaName: "projectSettings";
|
|
78
|
+
name?: string | undefined;
|
|
79
|
+
defaultPresets?: {
|
|
80
|
+
point: string[];
|
|
81
|
+
area: string[];
|
|
82
|
+
vertex: string[];
|
|
83
|
+
line: string[];
|
|
84
|
+
relation: string[];
|
|
85
|
+
} | undefined;
|
|
86
|
+
configMetadata?: {
|
|
87
|
+
name: string;
|
|
88
|
+
buildDate: string;
|
|
89
|
+
importDate: string;
|
|
90
|
+
fileVersion: string;
|
|
91
|
+
} | undefined;
|
|
92
|
+
}, "name"> & {
|
|
93
|
+
projectId: string;
|
|
94
|
+
createdAt?: string | undefined;
|
|
95
|
+
updatedAt?: string | undefined;
|
|
96
|
+
})[], import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
97
|
+
} & {
|
|
98
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, (Pick<{
|
|
99
|
+
schemaName: "projectSettings";
|
|
100
|
+
name?: string | undefined;
|
|
101
|
+
defaultPresets?: {
|
|
102
|
+
point: string[];
|
|
103
|
+
area: string[];
|
|
104
|
+
vertex: string[];
|
|
105
|
+
line: string[];
|
|
106
|
+
relation: string[];
|
|
107
|
+
} | undefined;
|
|
108
|
+
configMetadata?: {
|
|
109
|
+
name: string;
|
|
110
|
+
buildDate: string;
|
|
111
|
+
importDate: string;
|
|
112
|
+
fileVersion: string;
|
|
113
|
+
} | undefined;
|
|
114
|
+
}, "name"> & {
|
|
115
|
+
projectId: string;
|
|
116
|
+
createdAt?: string | undefined;
|
|
117
|
+
updatedAt?: string | undefined;
|
|
118
|
+
})[]>;
|
|
119
|
+
};
|
|
120
|
+
export declare function projectByIdQueryOptions({ clientApi, projectId, }: {
|
|
121
|
+
clientApi: MapeoClientApi;
|
|
122
|
+
projectId: string;
|
|
123
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("rpc-reflector/lib/types").ClientApi<import("@comapeo/core/dist/mapeo-project").MapeoProject>, Error, import("rpc-reflector/lib/types").ClientApi<import("@comapeo/core/dist/mapeo-project").MapeoProject>, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
124
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<import("rpc-reflector/lib/types").ClientApi<import("@comapeo/core/dist/mapeo-project").MapeoProject>, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
125
|
+
} & {
|
|
126
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, import("rpc-reflector/lib/types").ClientApi<import("@comapeo/core/dist/mapeo-project").MapeoProject>>;
|
|
127
|
+
};
|
|
128
|
+
export declare function projectSettingsQueryOptions({ projectApi, projectId, }: {
|
|
129
|
+
projectApi: MapeoProjectApi;
|
|
130
|
+
projectId: string;
|
|
131
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/mapeo-project").EditableProjectSettings, Error, import("@comapeo/core/dist/mapeo-project").EditableProjectSettings, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
132
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<import("@comapeo/core/dist/mapeo-project").EditableProjectSettings, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
133
|
+
} & {
|
|
134
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, import("@comapeo/core/dist/mapeo-project").EditableProjectSettings>;
|
|
135
|
+
};
|
|
136
|
+
export declare function projectMembersQueryOptions({ projectApi, projectId, }: {
|
|
137
|
+
projectApi: MapeoProjectApi;
|
|
138
|
+
projectId: string;
|
|
139
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/member-api").MemberInfo[], Error, import("@comapeo/core/dist/member-api").MemberInfo[], import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
140
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<import("@comapeo/core/dist/member-api").MemberInfo[], import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
141
|
+
} & {
|
|
142
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, import("@comapeo/core/dist/member-api").MemberInfo[]>;
|
|
143
|
+
};
|
|
144
|
+
export declare function projectMemberByIdQueryOptions({ projectApi, projectId, deviceId, }: {
|
|
145
|
+
projectApi: MapeoProjectApi;
|
|
146
|
+
projectId: string;
|
|
147
|
+
deviceId: string;
|
|
148
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/member-api").MemberInfo, Error, import("@comapeo/core/dist/member-api").MemberInfo, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
149
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<import("@comapeo/core/dist/member-api").MemberInfo, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
150
|
+
} & {
|
|
151
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, import("@comapeo/core/dist/member-api").MemberInfo>;
|
|
152
|
+
};
|
|
153
|
+
export declare function projectOwnRoleQueryOptions({ projectApi, projectId, }: {
|
|
154
|
+
projectApi: MapeoProjectApi;
|
|
155
|
+
projectId: string;
|
|
156
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/roles").Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">, Error, import("@comapeo/core/dist/roles").Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
157
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<import("@comapeo/core/dist/roles").Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
158
|
+
} & {
|
|
159
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, import("@comapeo/core/dist/roles").Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">>;
|
|
160
|
+
};
|
|
161
|
+
export declare function iconUrlQueryOptions({ projectApi, projectId, iconId, opts, }: {
|
|
162
|
+
projectApi: MapeoProjectApi;
|
|
163
|
+
projectId: string;
|
|
164
|
+
iconId: Parameters<MapeoProjectApi['$icons']['getIconUrl']>[0];
|
|
165
|
+
opts: Parameters<MapeoProjectApi['$icons']['getIconUrl']>[1];
|
|
166
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
167
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<string, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
168
|
+
} & {
|
|
169
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, string>;
|
|
170
|
+
};
|
|
171
|
+
export declare function documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId, }: {
|
|
172
|
+
projectApi: MapeoProjectApi;
|
|
173
|
+
projectId: string;
|
|
174
|
+
originalVersionId: string;
|
|
175
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
176
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<string, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
177
|
+
} & {
|
|
178
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, string>;
|
|
179
|
+
};
|
|
180
|
+
export declare function attachmentUrlQueryOptions({ projectApi, projectId, blobId, }: {
|
|
181
|
+
projectApi: MapeoProjectApi;
|
|
182
|
+
projectId: string;
|
|
183
|
+
blobId: BlobId;
|
|
184
|
+
}): import("@tanstack/query-core").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/query-core").QueryKey>, "queryFn"> & {
|
|
185
|
+
queryFn?: import("@tanstack/query-core").QueryFunction<string, import("@tanstack/query-core").QueryKey, never> | undefined;
|
|
186
|
+
} & {
|
|
187
|
+
queryKey: import("@tanstack/query-core").DataTag<import("@tanstack/query-core").QueryKey, string>;
|
|
188
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { baseQueryOptions, ROOT_QUERY_KEY } from './shared';
|
|
3
|
+
export function getProjectsQueryKey() {
|
|
4
|
+
return [ROOT_QUERY_KEY, 'projects'];
|
|
5
|
+
}
|
|
6
|
+
export function getProjectByIdQueryKey({ projectId }) {
|
|
7
|
+
return [ROOT_QUERY_KEY, 'projects', projectId];
|
|
8
|
+
}
|
|
9
|
+
export function getProjectSettingsQueryKey({ projectId, }) {
|
|
10
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'project_settings'];
|
|
11
|
+
}
|
|
12
|
+
export function getProjectRoleQueryKey({ projectId }) {
|
|
13
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'role'];
|
|
14
|
+
}
|
|
15
|
+
export function getMembersQueryKey({ projectId }) {
|
|
16
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'members'];
|
|
17
|
+
}
|
|
18
|
+
export function getMemberByIdQueryKey({ projectId, deviceId, }) {
|
|
19
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'members', deviceId];
|
|
20
|
+
}
|
|
21
|
+
export function getIconUrlQueryKey({ projectId, iconId, opts, }) {
|
|
22
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'icons', iconId, opts];
|
|
23
|
+
}
|
|
24
|
+
export function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }) {
|
|
25
|
+
return [
|
|
26
|
+
ROOT_QUERY_KEY,
|
|
27
|
+
'projects',
|
|
28
|
+
projectId,
|
|
29
|
+
'document_created_by',
|
|
30
|
+
originalVersionId,
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
export function getAttachmentUrlQueryKey({ projectId, blobId, }) {
|
|
34
|
+
return [ROOT_QUERY_KEY, 'projects', projectId, 'attachments', blobId];
|
|
35
|
+
}
|
|
36
|
+
export function projectsQueryOptions({ clientApi, }) {
|
|
37
|
+
return queryOptions({
|
|
38
|
+
...baseQueryOptions(),
|
|
39
|
+
queryKey: getProjectsQueryKey(),
|
|
40
|
+
queryFn: async () => {
|
|
41
|
+
return clientApi.listProjects();
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export function projectByIdQueryOptions({ clientApi, projectId, }) {
|
|
46
|
+
return queryOptions({
|
|
47
|
+
...baseQueryOptions(),
|
|
48
|
+
queryKey: getProjectByIdQueryKey({ projectId }),
|
|
49
|
+
queryFn: async () => {
|
|
50
|
+
return clientApi.getProject(projectId);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function projectSettingsQueryOptions({ projectApi, projectId, }) {
|
|
55
|
+
return queryOptions({
|
|
56
|
+
...baseQueryOptions(),
|
|
57
|
+
queryKey: getProjectSettingsQueryKey({ projectId }),
|
|
58
|
+
queryFn: async () => {
|
|
59
|
+
return projectApi.$getProjectSettings();
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function projectMembersQueryOptions({ projectApi, projectId, }) {
|
|
64
|
+
return queryOptions({
|
|
65
|
+
...baseQueryOptions(),
|
|
66
|
+
queryKey: getMembersQueryKey({ projectId }),
|
|
67
|
+
queryFn: async () => {
|
|
68
|
+
return projectApi.$member.getMany();
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function projectMemberByIdQueryOptions({ projectApi, projectId, deviceId, }) {
|
|
73
|
+
return queryOptions({
|
|
74
|
+
...baseQueryOptions(),
|
|
75
|
+
queryKey: getMemberByIdQueryKey({ projectId, deviceId }),
|
|
76
|
+
queryFn: async () => {
|
|
77
|
+
return projectApi.$member.getById(deviceId);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export function projectOwnRoleQueryOptions({ projectApi, projectId, }) {
|
|
82
|
+
return queryOptions({
|
|
83
|
+
...baseQueryOptions(),
|
|
84
|
+
queryKey: getProjectRoleQueryKey({ projectId }),
|
|
85
|
+
queryFn: async () => {
|
|
86
|
+
return projectApi.$getOwnRole();
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export function iconUrlQueryOptions({ projectApi, projectId, iconId, opts, }) {
|
|
91
|
+
return queryOptions({
|
|
92
|
+
...baseQueryOptions(),
|
|
93
|
+
queryKey: getIconUrlQueryKey({ projectId, iconId, opts }),
|
|
94
|
+
queryFn: async () => {
|
|
95
|
+
return projectApi.$icons.getIconUrl(iconId, opts);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export function documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId, }) {
|
|
100
|
+
return queryOptions({
|
|
101
|
+
...baseQueryOptions(),
|
|
102
|
+
queryKey: getDocumentCreatedByQueryKey({
|
|
103
|
+
projectId,
|
|
104
|
+
originalVersionId,
|
|
105
|
+
}),
|
|
106
|
+
queryFn: async () => {
|
|
107
|
+
return projectApi.$originalVersionIdToDeviceId(originalVersionId);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
export function attachmentUrlQueryOptions({ projectApi, projectId, blobId, }) {
|
|
112
|
+
return queryOptions({
|
|
113
|
+
...baseQueryOptions(),
|
|
114
|
+
queryKey: getAttachmentUrlQueryKey({ projectId, blobId }),
|
|
115
|
+
queryFn: async () => {
|
|
116
|
+
// TODO: Might need a refresh token? (similar to map style url)
|
|
117
|
+
return projectApi.$blobs.getUrl(blobId);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const ROOT_QUERY_KEY = '@comapeo/core-react';
|
|
2
|
+
// Since the API is running locally, queries should run regardless of network
|
|
3
|
+
// status, and should not be retried. In React Native the API consumer would
|
|
4
|
+
// have to manually set the network mode, but we still should keep these options
|
|
5
|
+
// to avoid surprises. Not using the queryClient `defaultOptions` because the API
|
|
6
|
+
// consumer might also use the same queryClient for network queries
|
|
7
|
+
export function baseQueryOptions() {
|
|
8
|
+
return {
|
|
9
|
+
networkMode: 'always',
|
|
10
|
+
retry: 0,
|
|
11
|
+
};
|
|
12
|
+
}
|