@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.
Files changed (64) 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 +80 -0
  4. package/dist/commonjs/hooks/client.js +91 -0
  5. package/dist/{hooks → commonjs/hooks}/documents.d.ts +60 -5
  6. package/dist/commonjs/hooks/documents.js +192 -0
  7. package/dist/commonjs/hooks/invites.d.ts +51 -0
  8. package/dist/commonjs/hooks/invites.js +50 -0
  9. package/dist/commonjs/hooks/maps.js +37 -0
  10. package/dist/commonjs/hooks/projects.d.ts +334 -0
  11. package/dist/commonjs/hooks/projects.js +320 -0
  12. package/dist/commonjs/index.d.ts +12 -0
  13. package/dist/commonjs/index.js +69 -0
  14. package/dist/commonjs/lib/react-query/client.d.ts +61 -0
  15. package/dist/commonjs/lib/react-query/client.js +68 -0
  16. package/dist/{lib → commonjs/lib}/react-query/documents.d.ts +789 -706
  17. package/dist/commonjs/lib/react-query/documents.js +149 -0
  18. package/dist/commonjs/lib/react-query/invites.d.ts +71 -0
  19. package/dist/commonjs/lib/react-query/invites.js +85 -0
  20. package/dist/commonjs/lib/react-query/maps.d.ts +24 -0
  21. package/dist/commonjs/lib/react-query/maps.js +27 -0
  22. package/dist/commonjs/lib/react-query/projects.d.ts +332 -0
  23. package/dist/commonjs/lib/react-query/projects.js +235 -0
  24. package/dist/{lib → commonjs/lib}/react-query/shared.d.ts +5 -1
  25. package/dist/commonjs/lib/react-query/shared.js +23 -0
  26. package/dist/commonjs/package.json +3 -0
  27. package/dist/{contexts → esm/contexts}/ClientApi.d.ts +3 -3
  28. package/dist/{hooks → esm/hooks}/client.d.ts +23 -2
  29. package/dist/{hooks → esm/hooks}/client.js +21 -3
  30. package/dist/esm/hooks/documents.d.ts +167 -0
  31. package/dist/{hooks → esm/hooks}/documents.js +54 -3
  32. package/dist/esm/hooks/invites.d.ts +51 -0
  33. package/dist/esm/hooks/invites.js +44 -0
  34. package/dist/esm/hooks/maps.d.ts +33 -0
  35. package/dist/{hooks → esm/hooks}/maps.js +2 -2
  36. package/dist/{hooks → esm/hooks}/projects.d.ts +89 -6
  37. package/dist/{hooks → esm/hooks}/projects.js +59 -3
  38. package/dist/esm/index.d.ts +12 -0
  39. package/dist/esm/index.js +12 -0
  40. package/dist/esm/lib/react-query/client.d.ts +61 -0
  41. package/dist/esm/lib/react-query/client.js +59 -0
  42. package/dist/esm/lib/react-query/documents.d.ts +1584 -0
  43. package/dist/{lib → esm/lib}/react-query/documents.js +56 -2
  44. package/dist/esm/lib/react-query/invites.d.ts +71 -0
  45. package/dist/esm/lib/react-query/invites.js +76 -0
  46. package/dist/esm/lib/react-query/maps.d.ts +24 -0
  47. package/dist/{lib → esm/lib}/react-query/maps.js +6 -2
  48. package/dist/esm/lib/react-query/projects.d.ts +332 -0
  49. package/dist/{lib → esm/lib}/react-query/projects.js +84 -2
  50. package/dist/esm/lib/react-query/shared.d.ts +9 -0
  51. package/dist/{lib → esm/lib}/react-query/shared.js +7 -1
  52. package/dist/esm/package.json +3 -0
  53. package/docs/API.md +157 -258
  54. package/package.json +51 -37
  55. package/dist/index.d.ts +0 -11
  56. package/dist/index.js +0 -11
  57. package/dist/lib/react-query/client.d.ts +0 -30
  58. package/dist/lib/react-query/client.js +0 -29
  59. package/dist/lib/react-query/invites.d.ts +0 -12
  60. package/dist/lib/react-query/invites.js +0 -17
  61. package/dist/lib/react-query/maps.d.ts +0 -15
  62. package/dist/lib/react-query/projects.d.ts +0 -196
  63. /package/dist/{hooks → commonjs/hooks}/maps.d.ts +0 -0
  64. /package/dist/{contexts → esm/contexts}/ClientApi.js +0 -0
@@ -0,0 +1,14 @@
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
2
+ import { type ReactNode } from 'react';
3
+ export declare const ClientApiContext: import("react").Context<import("@comapeo/ipc/dist/client.js", { with: { "resolution-mode": "import" } }).MapeoClientApi | null>;
4
+ /**
5
+ * Create a context provider that holds a CoMapeo API client instance.
6
+ *
7
+ * @param opts
8
+ * @param {ReactNode} opts.children React children node
9
+ * @param {MapeoClientApi} opts.clientApi Client API instance
10
+ */
11
+ export declare function ClientApiProvider({ children, clientApi, }: {
12
+ children: ReactNode;
13
+ clientApi: MapeoClientApi;
14
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<import("@comapeo/ipc/dist/client.js", { with: { "resolution-mode": "import" } }).MapeoClientApi | null>>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientApiContext = void 0;
4
+ exports.ClientApiProvider = ClientApiProvider;
5
+ const react_1 = require("react");
6
+ exports.ClientApiContext = (0, react_1.createContext)(null);
7
+ /**
8
+ * Create a context provider that holds a CoMapeo API client instance.
9
+ *
10
+ * @param opts
11
+ * @param {ReactNode} opts.children React children node
12
+ * @param {MapeoClientApi} opts.clientApi Client API instance
13
+ */
14
+ function ClientApiProvider({ children, clientApi, }) {
15
+ return (0, react_1.createElement)(exports.ClientApiContext.Provider, { value: clientApi }, children);
16
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Access a client API instance. If a ClientApiContext provider is not
3
+ * set up, it will throw an error.
4
+ *
5
+ * @returns Client API instance
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * function ClientExample() {
10
+ * return (
11
+ * // Creation of clientApi omitted for brevity
12
+ * <ClientApiContext.Provider clientApi={clientApi}>
13
+ * <ComponentThatUsesClient />
14
+ * </ClientApiContext.Provider>
15
+ * )
16
+ * }
17
+ *
18
+ * function ComponentThatUsesClient() {
19
+ * const clientApi = useClientApi()
20
+ *
21
+ * // Rest omitted for brevity.
22
+ * }
23
+ * ```
24
+ *
25
+ */
26
+ export declare function useClientApi(): import("@comapeo/ipc/dist/client.js", { with: { "resolution-mode": "import" } }).MapeoClientApi;
27
+ /**
28
+ * Retrieve info about the current device.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * function DeviceInfoExample() {
33
+ * const { data } = useDeviceInfo()
34
+ * }
35
+ * ```
36
+ */
37
+ export declare function useOwnDeviceInfo(): {
38
+ data: {
39
+ deviceId: string;
40
+ deviceType: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "selfHostedServer" | "UNRECOGNIZED";
41
+ } & Partial<import("@comapeo/core/dist/schema/client.js", { with: { "resolution-mode": "import" } }).DeviceInfoParam>;
42
+ error: Error | null;
43
+ isRefetching: boolean;
44
+ };
45
+ /**
46
+ * Retrieve whether the current device is an archive device or not.
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * function IsArchiveDeviceExample() {
51
+ * const { data } = useIsArchiveDevice()
52
+ * }
53
+ * ```
54
+ */
55
+ export declare function useIsArchiveDevice(): {
56
+ data: boolean;
57
+ error: Error | null;
58
+ isRefetching: boolean;
59
+ };
60
+ /**
61
+ * Update the device info for the current device.
62
+ */
63
+ export declare function useSetOwnDeviceInfo(): {
64
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
65
+ name: string;
66
+ deviceType: import("@comapeo/schema", { with: { "resolution-mode": "import" } }).DeviceInfo["deviceType"];
67
+ }, unknown>;
68
+ reset: () => void;
69
+ status: "pending" | "error" | "success" | "idle";
70
+ };
71
+ /**
72
+ * Set or unset the current device as an archive device.
73
+ */
74
+ export declare function useSetIsArchiveDevice(): {
75
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
76
+ isArchiveDevice: boolean;
77
+ }, unknown>;
78
+ reset: () => void;
79
+ status: "pending" | "error" | "success" | "idle";
80
+ };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useClientApi = useClientApi;
4
+ exports.useOwnDeviceInfo = useOwnDeviceInfo;
5
+ exports.useIsArchiveDevice = useIsArchiveDevice;
6
+ exports.useSetOwnDeviceInfo = useSetOwnDeviceInfo;
7
+ exports.useSetIsArchiveDevice = useSetIsArchiveDevice;
8
+ const react_query_1 = require("@tanstack/react-query");
9
+ const react_1 = require("react");
10
+ const ClientApi_js_1 = require("../contexts/ClientApi.js");
11
+ const client_js_1 = require("../lib/react-query/client.js");
12
+ /**
13
+ * Access a client API instance. If a ClientApiContext provider is not
14
+ * set up, it will throw an error.
15
+ *
16
+ * @returns Client API instance
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * function ClientExample() {
21
+ * return (
22
+ * // Creation of clientApi omitted for brevity
23
+ * <ClientApiContext.Provider clientApi={clientApi}>
24
+ * <ComponentThatUsesClient />
25
+ * </ClientApiContext.Provider>
26
+ * )
27
+ * }
28
+ *
29
+ * function ComponentThatUsesClient() {
30
+ * const clientApi = useClientApi()
31
+ *
32
+ * // Rest omitted for brevity.
33
+ * }
34
+ * ```
35
+ *
36
+ */
37
+ function useClientApi() {
38
+ const clientApi = (0, react_1.useContext)(ClientApi_js_1.ClientApiContext);
39
+ if (!clientApi) {
40
+ throw new Error('No client API set. Make sure you set up the ClientApiContext provider properly');
41
+ }
42
+ return clientApi;
43
+ }
44
+ /**
45
+ * Retrieve info about the current device.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * function DeviceInfoExample() {
50
+ * const { data } = useDeviceInfo()
51
+ * }
52
+ * ```
53
+ */
54
+ function useOwnDeviceInfo() {
55
+ const clientApi = useClientApi();
56
+ const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, client_js_1.deviceInfoQueryOptions)({ clientApi }));
57
+ return { data, error, isRefetching };
58
+ }
59
+ /**
60
+ * Retrieve whether the current device is an archive device or not.
61
+ *
62
+ * @example
63
+ * ```tsx
64
+ * function IsArchiveDeviceExample() {
65
+ * const { data } = useIsArchiveDevice()
66
+ * }
67
+ * ```
68
+ */
69
+ function useIsArchiveDevice() {
70
+ const clientApi = useClientApi();
71
+ const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, client_js_1.isArchiveDeviceQueryOptions)({ clientApi }));
72
+ return { data, error, isRefetching };
73
+ }
74
+ /**
75
+ * Update the device info for the current device.
76
+ */
77
+ function useSetOwnDeviceInfo() {
78
+ const queryClient = (0, react_query_1.useQueryClient)();
79
+ const clientApi = useClientApi();
80
+ const { mutate, status, reset } = (0, react_query_1.useMutation)((0, client_js_1.setOwnDeviceInfoMutationOptions)({ clientApi, queryClient }));
81
+ return { mutate, reset, status };
82
+ }
83
+ /**
84
+ * Set or unset the current device as an archive device.
85
+ */
86
+ function useSetIsArchiveDevice() {
87
+ const queryClient = (0, react_query_1.useQueryClient)();
88
+ const clientApi = useClientApi();
89
+ const { mutate, status, reset } = (0, react_query_1.useMutation)((0, client_js_1.setIsArchiveDeviceMutationOptions)({ clientApi, queryClient }));
90
+ return { mutate, reset, status };
91
+ }
@@ -1,5 +1,5 @@
1
- import type { MapeoDoc } from '@comapeo/schema';
2
- import { type DocumentType } from '../lib/react-query/documents';
1
+ import type { MapeoDoc } from '@comapeo/schema' with { 'resolution-mode': 'import' };
2
+ import { type WriteableDocumentType } from '../lib/react-query/documents.js';
3
3
  type ReadHookResult<D> = {
4
4
  data: D;
5
5
  error: Error | null;
@@ -28,7 +28,7 @@ type ReadHookResult<D> = {
28
28
  * }
29
29
  * ```
30
30
  */
31
- export declare function useSingleDocByDocId<D extends DocumentType>({ projectId, docType, docId, lang, }: {
31
+ export declare function useSingleDocByDocId<D extends WriteableDocumentType>({ projectId, docType, docId, lang, }: {
32
32
  projectId: string;
33
33
  docType: D;
34
34
  docId: string;
@@ -59,7 +59,7 @@ export declare function useSingleDocByDocId<D extends DocumentType>({ projectId,
59
59
  * }
60
60
  * ```
61
61
  */
62
- export declare function useSingleDocByVersionId<D extends DocumentType>({ projectId, docType, versionId, lang, }: {
62
+ export declare function useSingleDocByVersionId<D extends WriteableDocumentType>({ projectId, docType, versionId, lang, }: {
63
63
  projectId: string;
64
64
  docType: D;
65
65
  versionId: string;
@@ -101,7 +101,7 @@ export declare function useSingleDocByVersionId<D extends DocumentType>({ projec
101
101
  * }
102
102
  * ```
103
103
  */
104
- export declare function useManyDocs<D extends DocumentType>({ projectId, docType, includeDeleted, lang, }: {
104
+ export declare function useManyDocs<D extends WriteableDocumentType>({ projectId, docType, includeDeleted, lang, }: {
105
105
  projectId: string;
106
106
  docType: D;
107
107
  includeDeleted?: boolean;
@@ -109,4 +109,59 @@ export declare function useManyDocs<D extends DocumentType>({ projectId, docType
109
109
  }): ReadHookResult<Extract<MapeoDoc, {
110
110
  schemaName: D;
111
111
  }>>;
112
+ /**
113
+ * Create a document for a project.
114
+ *
115
+ * @param opts.docType Document type to create.
116
+ * @param opts.projectId Public ID of project to create document for.
117
+ */
118
+ export declare function useCreateDocument<D extends WriteableDocumentType>({ docType, projectId, }: {
119
+ docType: D;
120
+ projectId: string;
121
+ }): {
122
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("../lib/react-query/documents.js").WriteableDocument<D> & {
123
+ forks: Array<string>;
124
+ }, Error, {
125
+ value: Omit<import("../lib/react-query/documents.js").WriteableValue<D>, "schemaName">;
126
+ }, unknown>;
127
+ reset: () => void;
128
+ status: "pending" | "error" | "success" | "idle";
129
+ };
130
+ /**
131
+ * Update a document within a project.
132
+ *
133
+ * @param opts.docType Document type to update.
134
+ * @param opts.projectId Public ID of project document belongs to.
135
+ */
136
+ export declare function useUpdateDocument<D extends WriteableDocumentType>({ docType, projectId, }: {
137
+ docType: D;
138
+ projectId: string;
139
+ }): {
140
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("../lib/react-query/documents.js").WriteableDocument<D> & {
141
+ forks: Array<string>;
142
+ }, Error, {
143
+ versionId: string;
144
+ value: Omit<import("../lib/react-query/documents.js").WriteableValue<D>, "schemaName">;
145
+ }, unknown>;
146
+ reset: () => void;
147
+ status: "pending" | "error" | "success" | "idle";
148
+ };
149
+ /**
150
+ * Delete a document within a project.
151
+ *
152
+ * @param opts.docType Document type to delete.
153
+ * @param opts.projectId Public ID of project document belongs to.
154
+ */
155
+ export declare function useDeleteDocument<D extends WriteableDocumentType>({ docType, projectId, }: {
156
+ docType: D;
157
+ projectId: string;
158
+ }): {
159
+ mutate: import("@tanstack/react-query").UseMutateFunction<import("../lib/react-query/documents.js").WriteableDocument<D> & {
160
+ forks: Array<string>;
161
+ }, Error, {
162
+ docId: string;
163
+ }, unknown>;
164
+ reset: () => void;
165
+ status: "pending" | "error" | "success" | "idle";
166
+ };
112
167
  export {};
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSingleDocByDocId = useSingleDocByDocId;
4
+ exports.useSingleDocByVersionId = useSingleDocByVersionId;
5
+ exports.useManyDocs = useManyDocs;
6
+ exports.useCreateDocument = useCreateDocument;
7
+ exports.useUpdateDocument = useUpdateDocument;
8
+ exports.useDeleteDocument = useDeleteDocument;
9
+ const react_query_1 = require("@tanstack/react-query");
10
+ const documents_js_1 = require("../lib/react-query/documents.js");
11
+ const projects_js_1 = require("./projects.js");
12
+ /**
13
+ * Retrieve a single document from the database based on the document's document ID.
14
+ *
15
+ * Triggers the closest error boundary if the document cannot be found
16
+ *
17
+ * @param opts.projectId Project public ID
18
+ * @param opts.docType Document type of interest
19
+ * @param opts.docId Document ID
20
+ * @param opts.lang Language to translate the document into
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * function SingleDocumentByDocIdExample() {
25
+ * const { data } = useSingleDocByDocId({
26
+ * projectId: '...',
27
+ * docType: 'observation',
28
+ * docId: '...',
29
+ * })
30
+ *
31
+ * console.log(data.schemaName) // logs 'observation'
32
+ * }
33
+ * ```
34
+ */
35
+ function useSingleDocByDocId({ projectId, docType, docId, lang, }) {
36
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
37
+ const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, documents_js_1.documentByDocumentIdQueryOptions)({
38
+ projectApi,
39
+ projectId,
40
+ docType,
41
+ docId,
42
+ lang,
43
+ }));
44
+ return {
45
+ // @ts-expect-error - TS does not handle dependent types, so this will not
46
+ // be narrowed properly within the function body. See for example
47
+ // https://github.com/microsoft/TypeScript/issues/33014#event-15134418011
48
+ data,
49
+ error,
50
+ isRefetching,
51
+ };
52
+ }
53
+ /**
54
+ * Retrieve a single document from the database based on the document's version ID.
55
+ *
56
+ * Triggers the closest error boundary if the document cannot be found.
57
+ *
58
+ * @param opts.projectId Project public ID
59
+ * @param opts.docType Document type of interest
60
+ * @param opts.versionId Document's version ID
61
+ * @param opts.lang Language to translate the document into
62
+ *
63
+ * * @example
64
+ * ```tsx
65
+ * function SingleDocumentByVersionIdExample() {
66
+ * const { data } = useSingleDocByVersionId({
67
+ * projectId: '...',
68
+ * docType: 'observation',
69
+ * docId: '...',
70
+ * })
71
+ *
72
+ * console.log(data.schemaName) // logs 'observation'
73
+ * }
74
+ * ```
75
+ */
76
+ function useSingleDocByVersionId({ projectId, docType, versionId, lang, }) {
77
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
78
+ const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, documents_js_1.documentByVersionIdQueryOptions)({
79
+ projectApi,
80
+ projectId,
81
+ docType,
82
+ versionId,
83
+ lang,
84
+ }));
85
+ return {
86
+ // @ts-expect-error - TS does not handle dependent types, see above
87
+ data,
88
+ error,
89
+ isRefetching,
90
+ };
91
+ }
92
+ /**
93
+ * Retrieve all documents of a specific `docType`.
94
+ *
95
+ * @param opts.projectId Project public ID
96
+ * @param opts.docType Document type of interest
97
+ * @param opts.includeDeleted Include documents that have been marked as deleted
98
+ * @param opts.lang Language to translate the documents into
99
+ *
100
+ * @example
101
+ * ```tsx
102
+ * function BasicExample() {
103
+ * const { data } = useManyDocs({
104
+ * projectId: '...',
105
+ * docType: 'observations',
106
+ * })
107
+ * }
108
+ * ```
109
+ *
110
+ * ```tsx
111
+ * function useAllObservations(opts) {
112
+ * return useManyDocs({
113
+ * ...opts,
114
+ * docType: 'observations',
115
+ * })
116
+ * }
117
+ *
118
+ * function useAllPresets(opts) {
119
+ * return useManyDocs({
120
+ * ...opts,
121
+ * docType: 'presets',
122
+ * })
123
+ * }
124
+ * ```
125
+ */
126
+ function useManyDocs({ projectId, docType, includeDeleted, lang, }) {
127
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
128
+ const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, documents_js_1.documentsQueryOptions)({
129
+ projectApi,
130
+ projectId,
131
+ docType,
132
+ includeDeleted,
133
+ lang,
134
+ }));
135
+ return {
136
+ // @ts-expect-error - TS does not handle dependent types, see above
137
+ data,
138
+ error,
139
+ isRefetching,
140
+ };
141
+ }
142
+ /**
143
+ * Create a document for a project.
144
+ *
145
+ * @param opts.docType Document type to create.
146
+ * @param opts.projectId Public ID of project to create document for.
147
+ */
148
+ function useCreateDocument({ docType, projectId, }) {
149
+ const queryClient = (0, react_query_1.useQueryClient)();
150
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
151
+ const { mutate, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.createDocumentMutationOptions)({
152
+ docType,
153
+ projectApi,
154
+ projectId,
155
+ queryClient,
156
+ }));
157
+ return { mutate, reset, status };
158
+ }
159
+ /**
160
+ * Update a document within a project.
161
+ *
162
+ * @param opts.docType Document type to update.
163
+ * @param opts.projectId Public ID of project document belongs to.
164
+ */
165
+ function useUpdateDocument({ docType, projectId, }) {
166
+ const queryClient = (0, react_query_1.useQueryClient)();
167
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
168
+ const { mutate, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.updateDocumentMutationOptions)({
169
+ docType,
170
+ projectApi,
171
+ projectId,
172
+ queryClient,
173
+ }));
174
+ return { mutate, reset, status };
175
+ }
176
+ /**
177
+ * Delete a document within a project.
178
+ *
179
+ * @param opts.docType Document type to delete.
180
+ * @param opts.projectId Public ID of project document belongs to.
181
+ */
182
+ function useDeleteDocument({ docType, projectId, }) {
183
+ const queryClient = (0, react_query_1.useQueryClient)();
184
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
185
+ const { mutate, reset, status } = (0, react_query_1.useMutation)((0, documents_js_1.deleteDocumentMutationOptions)({
186
+ docType,
187
+ projectApi,
188
+ projectId,
189
+ queryClient,
190
+ }));
191
+ return { mutate, reset, status };
192
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Accept an invite that has been received.
3
+ */
4
+ export declare function useAcceptInvite(): {
5
+ mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
6
+ inviteId: string;
7
+ }, unknown>;
8
+ reset: () => void;
9
+ status: "pending" | "error" | "success" | "idle";
10
+ };
11
+ /**
12
+ * Reject an invite that has been received.
13
+ */
14
+ export declare function useRejectInvite(): {
15
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
16
+ inviteId: string;
17
+ }, unknown>;
18
+ reset: () => void;
19
+ status: "pending" | "error" | "success" | "idle";
20
+ };
21
+ /**
22
+ * Send an invite for a project.
23
+ *
24
+ * @param opts.projectId Public ID of project to send the invite on behalf of.
25
+ */
26
+ export declare function useSendInvite({ projectId }: {
27
+ projectId: string;
28
+ }): {
29
+ mutate: import("@tanstack/react-query").UseMutateFunction<"ACCEPT" | "REJECT" | "ALREADY", Error, {
30
+ deviceId: string;
31
+ roleDescription?: string;
32
+ roleId: import("@comapeo/core/dist/roles.js", { with: { "resolution-mode": "import" } }).RoleIdForNewInvite;
33
+ roleName?: string;
34
+ }, unknown>;
35
+ reset: () => void;
36
+ status: "pending" | "error" | "success" | "idle";
37
+ };
38
+ /**
39
+ * Request a cancellation of an invite sent to another device.
40
+ *
41
+ * @param opts.projectId Public ID of project to request the invite cancellation for.
42
+ */
43
+ export declare function useRequestCancelInvite({ projectId }: {
44
+ projectId: string;
45
+ }): {
46
+ mutate: import("@tanstack/react-query").UseMutateFunction<void, Error, {
47
+ deviceId: string;
48
+ }, unknown>;
49
+ reset: () => void;
50
+ status: "pending" | "error" | "success" | "idle";
51
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAcceptInvite = useAcceptInvite;
4
+ exports.useRejectInvite = useRejectInvite;
5
+ exports.useSendInvite = useSendInvite;
6
+ exports.useRequestCancelInvite = useRequestCancelInvite;
7
+ const react_query_1 = require("@tanstack/react-query");
8
+ const invites_js_1 = require("../lib/react-query/invites.js");
9
+ const client_js_1 = require("./client.js");
10
+ const projects_js_1 = require("./projects.js");
11
+ /**
12
+ * Accept an invite that has been received.
13
+ */
14
+ function useAcceptInvite() {
15
+ const queryClient = (0, react_query_1.useQueryClient)();
16
+ const clientApi = (0, client_js_1.useClientApi)();
17
+ const { mutate, status, reset } = (0, react_query_1.useMutation)((0, invites_js_1.acceptInviteMutationOptions)({ clientApi, queryClient }));
18
+ return { mutate, reset, status };
19
+ }
20
+ /**
21
+ * Reject an invite that has been received.
22
+ */
23
+ function useRejectInvite() {
24
+ const queryClient = (0, react_query_1.useQueryClient)();
25
+ const clientApi = (0, client_js_1.useClientApi)();
26
+ const { mutate, status, reset } = (0, react_query_1.useMutation)((0, invites_js_1.rejectInviteMutationOptions)({ clientApi, queryClient }));
27
+ return { mutate, reset, status };
28
+ }
29
+ /**
30
+ * Send an invite for a project.
31
+ *
32
+ * @param opts.projectId Public ID of project to send the invite on behalf of.
33
+ */
34
+ function useSendInvite({ projectId }) {
35
+ const queryClient = (0, react_query_1.useQueryClient)();
36
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
37
+ const { mutate, status, reset } = (0, react_query_1.useMutation)((0, invites_js_1.sendInviteMutationOptions)({ projectApi, projectId, queryClient }));
38
+ return { mutate, reset, status };
39
+ }
40
+ /**
41
+ * Request a cancellation of an invite sent to another device.
42
+ *
43
+ * @param opts.projectId Public ID of project to request the invite cancellation for.
44
+ */
45
+ function useRequestCancelInvite({ projectId }) {
46
+ const queryClient = (0, react_query_1.useQueryClient)();
47
+ const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
48
+ const { mutate, status, reset } = (0, react_query_1.useMutation)((0, invites_js_1.requestCancelInviteMutationOptions)({ projectApi, queryClient }));
49
+ return { mutate, reset, status };
50
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMapStyleUrl = useMapStyleUrl;
4
+ const react_query_1 = require("@tanstack/react-query");
5
+ const maps_js_1 = require("../lib/react-query/maps.js");
6
+ const client_js_1 = require("./client.js");
7
+ /**
8
+ * Get a URL that points to a StyleJSON resource served by the embedded HTTP server.
9
+ *
10
+ * If `opts.refreshToken` is specified, it will be appended to the returned URL as a search param. This is useful for forcing cache busting
11
+ * due to hidden internal details by consuming components (e.g. map component from MapLibre).
12
+ *
13
+ * @param opts.refreshToken String to append to the returned value as a search param
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * function ExampleWithoutRefreshToken() {
18
+ * const { data, isRefetching } = useMapStyleUrl()
19
+ *
20
+ * console.log(data) // logs something like 'http://localhost:...'
21
+ * }
22
+ * ```
23
+ *
24
+ * ```tsx
25
+ * function ExampleWithRefreshToken() {
26
+ * const [refreshToken] = useState('foo')
27
+ * const { data } = useMapStyleUrl({ refreshToken })
28
+ *
29
+ * console.log(data) // logs something like 'http://localhost:...?refresh_token=foo'
30
+ * }
31
+ * ```
32
+ */
33
+ function useMapStyleUrl({ refreshToken, } = {}) {
34
+ const clientApi = (0, client_js_1.useClientApi)();
35
+ const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, maps_js_1.mapStyleJsonUrlQueryOptions)({ clientApi, refreshToken }));
36
+ return { data, error, isRefetching };
37
+ }