@comapeo/core-react 1.0.1 → 1.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.
Files changed (57) hide show
  1. package/dist/commonjs/contexts/ClientApi.d.ts +14 -0
  2. package/dist/commonjs/contexts/ClientApi.js +16 -0
  3. package/dist/commonjs/hooks/client.d.ts +59 -0
  4. package/dist/commonjs/hooks/client.js +71 -0
  5. package/dist/{hooks → commonjs/hooks}/documents.d.ts +2 -2
  6. package/dist/commonjs/hooks/documents.js +138 -0
  7. package/dist/commonjs/hooks/maps.js +37 -0
  8. package/dist/commonjs/hooks/projects.d.ts +251 -0
  9. package/dist/commonjs/hooks/projects.js +258 -0
  10. package/dist/commonjs/index.d.ts +11 -0
  11. package/dist/commonjs/index.js +69 -0
  12. package/dist/commonjs/lib/react-query/client.d.ts +30 -0
  13. package/dist/commonjs/lib/react-query/client.js +36 -0
  14. package/dist/{lib → commonjs/lib}/react-query/documents.d.ts +101 -101
  15. package/dist/commonjs/lib/react-query/documents.js +92 -0
  16. package/dist/commonjs/lib/react-query/invites.d.ts +12 -0
  17. package/dist/commonjs/lib/react-query/invites.js +22 -0
  18. package/dist/commonjs/lib/react-query/maps.d.ts +15 -0
  19. package/dist/commonjs/lib/react-query/maps.js +23 -0
  20. package/dist/commonjs/lib/react-query/projects.d.ts +196 -0
  21. package/dist/commonjs/lib/react-query/projects.js +147 -0
  22. package/dist/commonjs/lib/react-query/shared.js +16 -0
  23. package/dist/commonjs/package.json +3 -0
  24. package/dist/{contexts → esm/contexts}/ClientApi.d.ts +3 -3
  25. package/dist/{hooks → esm/hooks}/client.d.ts +2 -2
  26. package/dist/{hooks → esm/hooks}/client.js +2 -2
  27. package/dist/esm/hooks/documents.d.ts +112 -0
  28. package/dist/{hooks → esm/hooks}/documents.js +2 -2
  29. package/dist/esm/hooks/maps.d.ts +33 -0
  30. package/dist/{hooks → esm/hooks}/maps.js +2 -2
  31. package/dist/{hooks → esm/hooks}/projects.d.ts +6 -6
  32. package/dist/{hooks → esm/hooks}/projects.js +2 -2
  33. package/dist/esm/index.d.ts +11 -0
  34. package/dist/esm/index.js +11 -0
  35. package/dist/esm/lib/react-query/client.d.ts +30 -0
  36. package/dist/{lib → esm/lib}/react-query/client.js +1 -1
  37. package/dist/esm/lib/react-query/documents.d.ts +1501 -0
  38. package/dist/{lib → esm/lib}/react-query/documents.js +1 -1
  39. package/dist/esm/lib/react-query/invites.d.ts +12 -0
  40. package/dist/{lib → esm/lib}/react-query/invites.js +1 -1
  41. package/dist/esm/lib/react-query/maps.d.ts +15 -0
  42. package/dist/{lib → esm/lib}/react-query/maps.js +1 -1
  43. package/dist/esm/lib/react-query/projects.d.ts +196 -0
  44. package/dist/{lib → esm/lib}/react-query/projects.js +1 -1
  45. package/dist/esm/lib/react-query/shared.d.ts +5 -0
  46. package/dist/esm/package.json +3 -0
  47. package/package.json +27 -12
  48. package/dist/index.d.ts +0 -11
  49. package/dist/index.js +0 -11
  50. package/dist/lib/react-query/client.d.ts +0 -30
  51. package/dist/lib/react-query/invites.d.ts +0 -12
  52. package/dist/lib/react-query/maps.d.ts +0 -15
  53. package/dist/lib/react-query/projects.d.ts +0 -196
  54. /package/dist/{hooks → commonjs/hooks}/maps.d.ts +0 -0
  55. /package/dist/{lib → commonjs/lib}/react-query/shared.d.ts +0 -0
  56. /package/dist/{contexts → esm/contexts}/ClientApi.js +0 -0
  57. /package/dist/{lib → esm/lib}/react-query/shared.js +0 -0
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInvitesQueryKey = getInvitesQueryKey;
4
+ exports.getPendingInvitesQueryKey = getPendingInvitesQueryKey;
5
+ exports.pendingInvitesQueryOptions = pendingInvitesQueryOptions;
6
+ const react_query_1 = require("@tanstack/react-query");
7
+ const shared_js_1 = require("./shared.js");
8
+ function getInvitesQueryKey() {
9
+ return [shared_js_1.ROOT_QUERY_KEY, 'invites'];
10
+ }
11
+ function getPendingInvitesQueryKey() {
12
+ return [shared_js_1.ROOT_QUERY_KEY, 'invites', { status: 'pending' }];
13
+ }
14
+ function pendingInvitesQueryOptions({ clientApi, }) {
15
+ return (0, react_query_1.queryOptions)({
16
+ ...(0, shared_js_1.baseQueryOptions)(),
17
+ queryKey: getPendingInvitesQueryKey(),
18
+ queryFn: async () => {
19
+ return clientApi.invite.getPending();
20
+ },
21
+ });
22
+ }
@@ -0,0 +1,15 @@
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, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
12
+ queryFn?: import("@tanstack/react-query").QueryFunction<string, import("@tanstack/react-query").QueryKey, never> | undefined;
13
+ } & {
14
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, string>;
15
+ };
@@ -0,0 +1,23 @@
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
+ return refreshToken ? result + `?refresh_token=${refreshToken}` : result;
21
+ },
22
+ });
23
+ }
@@ -0,0 +1,196 @@
1
+ import type { BitmapOpts, SvgOpts } from '@comapeo/core/dist/icon-api.js' with { 'resolution-mode': 'import' };
2
+ import type { BlobId } from '@comapeo/core/dist/types.js' with { 'resolution-mode': 'import' };
3
+ import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
4
+ export declare function getProjectsQueryKey(): readonly ["@comapeo/core-react", "projects"];
5
+ export declare function getProjectByIdQueryKey({ projectId }: {
6
+ projectId: string;
7
+ }): readonly ["@comapeo/core-react", "projects", string];
8
+ export declare function getProjectSettingsQueryKey({ projectId, }: {
9
+ projectId: string;
10
+ }): readonly ["@comapeo/core-react", "projects", string, "project_settings"];
11
+ export declare function getProjectRoleQueryKey({ projectId }: {
12
+ projectId: string;
13
+ }): readonly ["@comapeo/core-react", "projects", string, "role"];
14
+ export declare function getMembersQueryKey({ projectId }: {
15
+ projectId: string;
16
+ }): readonly ["@comapeo/core-react", "projects", string, "members"];
17
+ export declare function getMemberByIdQueryKey({ projectId, deviceId, }: {
18
+ projectId: string;
19
+ deviceId: string;
20
+ }): readonly ["@comapeo/core-react", "projects", string, "members", string];
21
+ export declare function getIconUrlQueryKey({ projectId, iconId, ...mimeBasedOpts }: {
22
+ projectId: string;
23
+ iconId: string;
24
+ } & (BitmapOpts | SvgOpts)): readonly ["@comapeo/core-react", "projects", string, "icons", string, {
25
+ mimeType: Extract<import("@comapeo/core/dist/icon-api.js", { with: { "resolution-mode": "import" } }).IconVariant["mimeType"], "image/png">;
26
+ pixelDensity: Extract<import("@comapeo/core/dist/icon-api.js", { with: { "resolution-mode": "import" } }).IconVariant, {
27
+ mimeType: "image/png";
28
+ }>["pixelDensity"];
29
+ size: import("@comapeo/core/dist/icon-api.js", { with: { "resolution-mode": "import" } }).ValidSizes;
30
+ } | {
31
+ mimeType: Extract<import("@comapeo/core/dist/icon-api.js", { with: { "resolution-mode": "import" } }).IconVariant["mimeType"], "image/svg+xml">;
32
+ size: import("@comapeo/core/dist/icon-api.js", { with: { "resolution-mode": "import" } }).ValidSizes;
33
+ }];
34
+ export declare function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }: {
35
+ projectId: string;
36
+ originalVersionId: string;
37
+ }): readonly ["@comapeo/core-react", "projects", string, "document_created_by", string];
38
+ export declare function getAttachmentUrlQueryKey({ projectId, blobId, }: {
39
+ projectId: string;
40
+ blobId: BlobId;
41
+ }): readonly ["@comapeo/core-react", "projects", string, "attachments", BlobId];
42
+ export declare function projectsQueryOptions({ clientApi, }: {
43
+ clientApi: MapeoClientApi;
44
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<(Pick<{
45
+ schemaName: "projectSettings";
46
+ name?: string | undefined;
47
+ defaultPresets?: {
48
+ point: string[];
49
+ area: string[];
50
+ vertex: string[];
51
+ line: string[];
52
+ relation: string[];
53
+ } | undefined;
54
+ configMetadata?: {
55
+ name: string;
56
+ buildDate: string;
57
+ importDate: string;
58
+ fileVersion: string;
59
+ } | undefined;
60
+ }, "name"> & {
61
+ projectId: string;
62
+ createdAt?: string | undefined;
63
+ updatedAt?: string | undefined;
64
+ })[], Error, (Pick<{
65
+ schemaName: "projectSettings";
66
+ name?: string | undefined;
67
+ defaultPresets?: {
68
+ point: string[];
69
+ area: string[];
70
+ vertex: string[];
71
+ line: string[];
72
+ relation: string[];
73
+ } | undefined;
74
+ configMetadata?: {
75
+ name: string;
76
+ buildDate: string;
77
+ importDate: string;
78
+ fileVersion: string;
79
+ } | undefined;
80
+ }, "name"> & {
81
+ projectId: string;
82
+ createdAt?: string | undefined;
83
+ updatedAt?: string | undefined;
84
+ })[], import("@tanstack/react-query").QueryKey>, "queryFn"> & {
85
+ queryFn?: import("@tanstack/react-query").QueryFunction<(Pick<{
86
+ schemaName: "projectSettings";
87
+ name?: string | undefined;
88
+ defaultPresets?: {
89
+ point: string[];
90
+ area: string[];
91
+ vertex: string[];
92
+ line: string[];
93
+ relation: string[];
94
+ } | undefined;
95
+ configMetadata?: {
96
+ name: string;
97
+ buildDate: string;
98
+ importDate: string;
99
+ fileVersion: string;
100
+ } | undefined;
101
+ }, "name"> & {
102
+ projectId: string;
103
+ createdAt?: string | undefined;
104
+ updatedAt?: string | undefined;
105
+ })[], import("@tanstack/react-query").QueryKey, never> | undefined;
106
+ } & {
107
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, (Pick<{
108
+ schemaName: "projectSettings";
109
+ name?: string | undefined;
110
+ defaultPresets?: {
111
+ point: string[];
112
+ area: string[];
113
+ vertex: string[];
114
+ line: string[];
115
+ relation: string[];
116
+ } | undefined;
117
+ configMetadata?: {
118
+ name: string;
119
+ buildDate: string;
120
+ importDate: string;
121
+ fileVersion: string;
122
+ } | undefined;
123
+ }, "name"> & {
124
+ projectId: string;
125
+ createdAt?: string | undefined;
126
+ updatedAt?: string | undefined;
127
+ })[]>;
128
+ };
129
+ export declare function projectByIdQueryOptions({ clientApi, projectId, }: {
130
+ clientApi: MapeoClientApi;
131
+ projectId: string;
132
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).MapeoProject>, Error, import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).MapeoProject>, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
133
+ queryFn?: import("@tanstack/react-query").QueryFunction<import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).MapeoProject>, import("@tanstack/react-query").QueryKey, never> | undefined;
134
+ } & {
135
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).MapeoProject>>;
136
+ };
137
+ export declare function projectSettingsQueryOptions({ projectApi, projectId, }: {
138
+ projectApi: MapeoProjectApi;
139
+ projectId: string;
140
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings, Error, import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
141
+ queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings, import("@tanstack/react-query").QueryKey, never> | undefined;
142
+ } & {
143
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings>;
144
+ };
145
+ export declare function projectMembersQueryOptions({ projectApi, projectId, }: {
146
+ projectApi: MapeoProjectApi;
147
+ projectId: string;
148
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo[], Error, import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo[], import("@tanstack/react-query").QueryKey>, "queryFn"> & {
149
+ queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo[], import("@tanstack/react-query").QueryKey, never> | undefined;
150
+ } & {
151
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo[]>;
152
+ };
153
+ export declare function projectMemberByIdQueryOptions({ projectApi, projectId, deviceId, }: {
154
+ projectApi: MapeoProjectApi;
155
+ projectId: string;
156
+ deviceId: string;
157
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo, Error, import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
158
+ queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo, import("@tanstack/react-query").QueryKey, never> | undefined;
159
+ } & {
160
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo>;
161
+ };
162
+ export declare function projectOwnRoleQueryOptions({ projectApi, projectId, }: {
163
+ projectApi: MapeoProjectApi;
164
+ projectId: string;
165
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">, Error, import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
166
+ queryFn?: import("@tanstack/react-query").QueryFunction<import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">, import("@tanstack/react-query").QueryKey, never> | undefined;
167
+ } & {
168
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).Role<"a12a6702b93bd7ff" | "f7c150f5a3a9a855" | "012fd2d431c0bf60" | "9e6d29263cba36c9" | "8ced989b1904606b" | "08e4251e36f6e7ed">>;
169
+ };
170
+ export declare function iconUrlQueryOptions({ projectApi, projectId, iconId, ...mimeBasedOpts }: {
171
+ projectApi: MapeoProjectApi;
172
+ projectId: string;
173
+ iconId: Parameters<MapeoProjectApi['$icons']['getIconUrl']>[0];
174
+ } & (BitmapOpts | SvgOpts)): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
175
+ queryFn?: import("@tanstack/react-query").QueryFunction<string, import("@tanstack/react-query").QueryKey, never> | undefined;
176
+ } & {
177
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, string>;
178
+ };
179
+ export declare function documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId, }: {
180
+ projectApi: MapeoProjectApi;
181
+ projectId: string;
182
+ originalVersionId: string;
183
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
184
+ queryFn?: import("@tanstack/react-query").QueryFunction<string, import("@tanstack/react-query").QueryKey, never> | undefined;
185
+ } & {
186
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, string>;
187
+ };
188
+ export declare function attachmentUrlQueryOptions({ projectApi, projectId, blobId, }: {
189
+ projectApi: MapeoProjectApi;
190
+ projectId: string;
191
+ blobId: BlobId;
192
+ }): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<string, Error, string, import("@tanstack/react-query").QueryKey>, "queryFn"> & {
193
+ queryFn?: import("@tanstack/react-query").QueryFunction<string, import("@tanstack/react-query").QueryKey, never> | undefined;
194
+ } & {
195
+ queryKey: import("@tanstack/react-query").DataTag<import("@tanstack/react-query").QueryKey, string>;
196
+ };
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProjectsQueryKey = getProjectsQueryKey;
4
+ exports.getProjectByIdQueryKey = getProjectByIdQueryKey;
5
+ exports.getProjectSettingsQueryKey = getProjectSettingsQueryKey;
6
+ exports.getProjectRoleQueryKey = getProjectRoleQueryKey;
7
+ exports.getMembersQueryKey = getMembersQueryKey;
8
+ exports.getMemberByIdQueryKey = getMemberByIdQueryKey;
9
+ exports.getIconUrlQueryKey = getIconUrlQueryKey;
10
+ exports.getDocumentCreatedByQueryKey = getDocumentCreatedByQueryKey;
11
+ exports.getAttachmentUrlQueryKey = getAttachmentUrlQueryKey;
12
+ exports.projectsQueryOptions = projectsQueryOptions;
13
+ exports.projectByIdQueryOptions = projectByIdQueryOptions;
14
+ exports.projectSettingsQueryOptions = projectSettingsQueryOptions;
15
+ exports.projectMembersQueryOptions = projectMembersQueryOptions;
16
+ exports.projectMemberByIdQueryOptions = projectMemberByIdQueryOptions;
17
+ exports.projectOwnRoleQueryOptions = projectOwnRoleQueryOptions;
18
+ exports.iconUrlQueryOptions = iconUrlQueryOptions;
19
+ exports.documentCreatedByQueryOptions = documentCreatedByQueryOptions;
20
+ exports.attachmentUrlQueryOptions = attachmentUrlQueryOptions;
21
+ const react_query_1 = require("@tanstack/react-query");
22
+ const shared_js_1 = require("./shared.js");
23
+ function getProjectsQueryKey() {
24
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects'];
25
+ }
26
+ function getProjectByIdQueryKey({ projectId }) {
27
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId];
28
+ }
29
+ function getProjectSettingsQueryKey({ projectId, }) {
30
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId, 'project_settings'];
31
+ }
32
+ function getProjectRoleQueryKey({ projectId }) {
33
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId, 'role'];
34
+ }
35
+ function getMembersQueryKey({ projectId }) {
36
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId, 'members'];
37
+ }
38
+ function getMemberByIdQueryKey({ projectId, deviceId, }) {
39
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId, 'members', deviceId];
40
+ }
41
+ function getIconUrlQueryKey({ projectId, iconId, ...mimeBasedOpts }) {
42
+ return [
43
+ shared_js_1.ROOT_QUERY_KEY,
44
+ 'projects',
45
+ projectId,
46
+ 'icons',
47
+ iconId,
48
+ mimeBasedOpts,
49
+ ];
50
+ }
51
+ function getDocumentCreatedByQueryKey({ projectId, originalVersionId, }) {
52
+ return [
53
+ shared_js_1.ROOT_QUERY_KEY,
54
+ 'projects',
55
+ projectId,
56
+ 'document_created_by',
57
+ originalVersionId,
58
+ ];
59
+ }
60
+ function getAttachmentUrlQueryKey({ projectId, blobId, }) {
61
+ return [shared_js_1.ROOT_QUERY_KEY, 'projects', projectId, 'attachments', blobId];
62
+ }
63
+ function projectsQueryOptions({ clientApi, }) {
64
+ return (0, react_query_1.queryOptions)({
65
+ ...(0, shared_js_1.baseQueryOptions)(),
66
+ queryKey: getProjectsQueryKey(),
67
+ queryFn: async () => {
68
+ return clientApi.listProjects();
69
+ },
70
+ });
71
+ }
72
+ function projectByIdQueryOptions({ clientApi, projectId, }) {
73
+ return (0, react_query_1.queryOptions)({
74
+ ...(0, shared_js_1.baseQueryOptions)(),
75
+ queryKey: getProjectByIdQueryKey({ projectId }),
76
+ queryFn: async () => {
77
+ return clientApi.getProject(projectId);
78
+ },
79
+ });
80
+ }
81
+ function projectSettingsQueryOptions({ projectApi, projectId, }) {
82
+ return (0, react_query_1.queryOptions)({
83
+ ...(0, shared_js_1.baseQueryOptions)(),
84
+ queryKey: getProjectSettingsQueryKey({ projectId }),
85
+ queryFn: async () => {
86
+ return projectApi.$getProjectSettings();
87
+ },
88
+ });
89
+ }
90
+ function projectMembersQueryOptions({ projectApi, projectId, }) {
91
+ return (0, react_query_1.queryOptions)({
92
+ ...(0, shared_js_1.baseQueryOptions)(),
93
+ queryKey: getMembersQueryKey({ projectId }),
94
+ queryFn: async () => {
95
+ return projectApi.$member.getMany();
96
+ },
97
+ });
98
+ }
99
+ function projectMemberByIdQueryOptions({ projectApi, projectId, deviceId, }) {
100
+ return (0, react_query_1.queryOptions)({
101
+ ...(0, shared_js_1.baseQueryOptions)(),
102
+ queryKey: getMemberByIdQueryKey({ projectId, deviceId }),
103
+ queryFn: async () => {
104
+ return projectApi.$member.getById(deviceId);
105
+ },
106
+ });
107
+ }
108
+ function projectOwnRoleQueryOptions({ projectApi, projectId, }) {
109
+ return (0, react_query_1.queryOptions)({
110
+ ...(0, shared_js_1.baseQueryOptions)(),
111
+ queryKey: getProjectRoleQueryKey({ projectId }),
112
+ queryFn: async () => {
113
+ return projectApi.$getOwnRole();
114
+ },
115
+ });
116
+ }
117
+ function iconUrlQueryOptions({ projectApi, projectId, iconId, ...mimeBasedOpts }) {
118
+ return (0, react_query_1.queryOptions)({
119
+ ...(0, shared_js_1.baseQueryOptions)(),
120
+ queryKey: getIconUrlQueryKey({ ...mimeBasedOpts, projectId, iconId }),
121
+ queryFn: async () => {
122
+ return projectApi.$icons.getIconUrl(iconId, mimeBasedOpts);
123
+ },
124
+ });
125
+ }
126
+ function documentCreatedByQueryOptions({ projectApi, projectId, originalVersionId, }) {
127
+ return (0, react_query_1.queryOptions)({
128
+ ...(0, shared_js_1.baseQueryOptions)(),
129
+ queryKey: getDocumentCreatedByQueryKey({
130
+ projectId,
131
+ originalVersionId,
132
+ }),
133
+ queryFn: async () => {
134
+ return projectApi.$originalVersionIdToDeviceId(originalVersionId);
135
+ },
136
+ });
137
+ }
138
+ function attachmentUrlQueryOptions({ projectApi, projectId, blobId, }) {
139
+ return (0, react_query_1.queryOptions)({
140
+ ...(0, shared_js_1.baseQueryOptions)(),
141
+ queryKey: getAttachmentUrlQueryKey({ projectId, blobId }),
142
+ queryFn: async () => {
143
+ // TODO: Might need a refresh token? (similar to map style url)
144
+ return projectApi.$blobs.getUrl(blobId);
145
+ },
146
+ });
147
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ROOT_QUERY_KEY = void 0;
4
+ exports.baseQueryOptions = baseQueryOptions;
5
+ exports.ROOT_QUERY_KEY = '@comapeo/core-react';
6
+ // Since the API is running locally, queries should run regardless of network
7
+ // status, and should not be retried. In React Native the API consumer would
8
+ // have to manually set the network mode, but we still should keep these options
9
+ // to avoid surprises. Not using the queryClient `defaultOptions` because the API
10
+ // consumer might also use the same queryClient for network queries
11
+ function baseQueryOptions() {
12
+ return {
13
+ networkMode: 'always',
14
+ retry: 0,
15
+ };
16
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -1,6 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc';
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
2
2
  import { type ReactNode } from 'react';
3
- export declare const ClientApiContext: import("react").Context<import("@comapeo/ipc/dist/client").MapeoClientApi | null>;
3
+ export declare const ClientApiContext: import("react").Context<import("@comapeo/ipc/dist/client.js").MapeoClientApi | null>;
4
4
  /**
5
5
  * Create a context provider that holds a CoMapeo API client instance.
6
6
  *
@@ -11,4 +11,4 @@ export declare const ClientApiContext: import("react").Context<import("@comapeo/
11
11
  export declare function ClientApiProvider({ children, clientApi, }: {
12
12
  children: ReactNode;
13
13
  clientApi: MapeoClientApi;
14
- }): import("react").FunctionComponentElement<import("react").ProviderProps<import("@comapeo/ipc/dist/client").MapeoClientApi | null>>;
14
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<import("@comapeo/ipc/dist/client.js").MapeoClientApi | null>>;
@@ -23,7 +23,7 @@
23
23
  * ```
24
24
  *
25
25
  */
26
- export declare function useClientApi(): import("@comapeo/ipc/dist/client").MapeoClientApi;
26
+ export declare function useClientApi(): import("@comapeo/ipc/dist/client.js").MapeoClientApi;
27
27
  /**
28
28
  * Retrieve info about the current device.
29
29
  *
@@ -38,7 +38,7 @@ export declare function useOwnDeviceInfo(): {
38
38
  data: {
39
39
  deviceId: string;
40
40
  deviceType: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "selfHostedServer" | "UNRECOGNIZED";
41
- } & Partial<import("@comapeo/core/dist/schema/client").DeviceInfoParam>;
41
+ } & Partial<import("@comapeo/core/dist/schema/client.js").DeviceInfoParam>;
42
42
  error: Error | null;
43
43
  isRefetching: boolean;
44
44
  };
@@ -1,7 +1,7 @@
1
1
  import { useSuspenseQuery } from '@tanstack/react-query';
2
2
  import { useContext } from 'react';
3
- import { ClientApiContext } from '../contexts/ClientApi';
4
- import { deviceInfoQueryOptions, isArchiveDeviceQueryOptions, } from '../lib/react-query/client';
3
+ import { ClientApiContext } from '../contexts/ClientApi.js';
4
+ import { deviceInfoQueryOptions, isArchiveDeviceQueryOptions, } from '../lib/react-query/client.js';
5
5
  /**
6
6
  * Access a client API instance. If a ClientApiContext provider is not
7
7
  * set up, it will throw an error.
@@ -0,0 +1,112 @@
1
+ import type { MapeoDoc } from '@comapeo/schema' with { 'resolution-mode': 'import' };
2
+ import { type DocumentType } from '../lib/react-query/documents.js';
3
+ type ReadHookResult<D> = {
4
+ data: D;
5
+ error: Error | null;
6
+ isRefetching: boolean;
7
+ };
8
+ /**
9
+ * Retrieve a single document from the database based on the document's document ID.
10
+ *
11
+ * Triggers the closest error boundary if the document cannot be found
12
+ *
13
+ * @param opts.projectId Project public ID
14
+ * @param opts.docType Document type of interest
15
+ * @param opts.docId Document ID
16
+ * @param opts.lang Language to translate the document into
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * function SingleDocumentByDocIdExample() {
21
+ * const { data } = useSingleDocByDocId({
22
+ * projectId: '...',
23
+ * docType: 'observation',
24
+ * docId: '...',
25
+ * })
26
+ *
27
+ * console.log(data.schemaName) // logs 'observation'
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function useSingleDocByDocId<D extends DocumentType>({ projectId, docType, docId, lang, }: {
32
+ projectId: string;
33
+ docType: D;
34
+ docId: string;
35
+ lang?: string;
36
+ }): ReadHookResult<Extract<MapeoDoc, {
37
+ schemaName: D;
38
+ }>>;
39
+ /**
40
+ * Retrieve a single document from the database based on the document's version ID.
41
+ *
42
+ * Triggers the closest error boundary if the document cannot be found.
43
+ *
44
+ * @param opts.projectId Project public ID
45
+ * @param opts.docType Document type of interest
46
+ * @param opts.versionId Document's version ID
47
+ * @param opts.lang Language to translate the document into
48
+ *
49
+ * * @example
50
+ * ```tsx
51
+ * function SingleDocumentByVersionIdExample() {
52
+ * const { data } = useSingleDocByVersionId({
53
+ * projectId: '...',
54
+ * docType: 'observation',
55
+ * docId: '...',
56
+ * })
57
+ *
58
+ * console.log(data.schemaName) // logs 'observation'
59
+ * }
60
+ * ```
61
+ */
62
+ export declare function useSingleDocByVersionId<D extends DocumentType>({ projectId, docType, versionId, lang, }: {
63
+ projectId: string;
64
+ docType: D;
65
+ versionId: string;
66
+ lang?: string;
67
+ }): ReadHookResult<Extract<MapeoDoc, {
68
+ schemaName: D;
69
+ }>>;
70
+ /**
71
+ * Retrieve all documents of a specific `docType`.
72
+ *
73
+ * @param opts.projectId Project public ID
74
+ * @param opts.docType Document type of interest
75
+ * @param opts.includeDeleted Include documents that have been marked as deleted
76
+ * @param opts.lang Language to translate the documents into
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * function BasicExample() {
81
+ * const { data } = useManyDocs({
82
+ * projectId: '...',
83
+ * docType: 'observations',
84
+ * })
85
+ * }
86
+ * ```
87
+ *
88
+ * ```tsx
89
+ * function useAllObservations(opts) {
90
+ * return useManyDocs({
91
+ * ...opts,
92
+ * docType: 'observations',
93
+ * })
94
+ * }
95
+ *
96
+ * function useAllPresets(opts) {
97
+ * return useManyDocs({
98
+ * ...opts,
99
+ * docType: 'presets',
100
+ * })
101
+ * }
102
+ * ```
103
+ */
104
+ export declare function useManyDocs<D extends DocumentType>({ projectId, docType, includeDeleted, lang, }: {
105
+ projectId: string;
106
+ docType: D;
107
+ includeDeleted?: boolean;
108
+ lang?: string;
109
+ }): ReadHookResult<Extract<MapeoDoc, {
110
+ schemaName: D;
111
+ }>>;
112
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { useSuspenseQuery } from '@tanstack/react-query';
2
- import { documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, } from '../lib/react-query/documents';
3
- import { useSingleProject } from './projects';
2
+ import { documentByDocumentIdQueryOptions, documentByVersionIdQueryOptions, documentsQueryOptions, } from '../lib/react-query/documents.js';
3
+ import { useSingleProject } from './projects.js';
4
4
  /**
5
5
  * Retrieve a single document from the database based on the document's document ID.
6
6
  *
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Get a URL that points to a StyleJSON resource served by the embedded HTTP server.
3
+ *
4
+ * If `opts.refreshToken` is specified, it will be appended to the returned URL as a search param. This is useful for forcing cache busting
5
+ * due to hidden internal details by consuming components (e.g. map component from MapLibre).
6
+ *
7
+ * @param opts.refreshToken String to append to the returned value as a search param
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * function ExampleWithoutRefreshToken() {
12
+ * const { data, isRefetching } = useMapStyleUrl()
13
+ *
14
+ * console.log(data) // logs something like 'http://localhost:...'
15
+ * }
16
+ * ```
17
+ *
18
+ * ```tsx
19
+ * function ExampleWithRefreshToken() {
20
+ * const [refreshToken] = useState('foo')
21
+ * const { data } = useMapStyleUrl({ refreshToken })
22
+ *
23
+ * console.log(data) // logs something like 'http://localhost:...?refresh_token=foo'
24
+ * }
25
+ * ```
26
+ */
27
+ export declare function useMapStyleUrl({ refreshToken, }?: {
28
+ refreshToken?: string;
29
+ }): {
30
+ data: string;
31
+ error: Error | null;
32
+ isRefetching: boolean;
33
+ };
@@ -1,6 +1,6 @@
1
1
  import { useSuspenseQuery } from '@tanstack/react-query';
2
- import { mapStyleJsonUrlQueryOptions } from '../lib/react-query/maps';
3
- import { useClientApi } from './client';
2
+ import { mapStyleJsonUrlQueryOptions } from '../lib/react-query/maps.js';
3
+ import { useClientApi } from './client.js';
4
4
  /**
5
5
  * Get a URL that points to a StyleJSON resource served by the embedded HTTP server.
6
6
  *