@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.
- package/dist/commonjs/contexts/ClientApi.d.ts +14 -0
- package/dist/commonjs/contexts/ClientApi.js +16 -0
- package/dist/commonjs/hooks/client.d.ts +59 -0
- package/dist/commonjs/hooks/client.js +71 -0
- package/dist/{hooks → commonjs/hooks}/documents.d.ts +2 -2
- package/dist/commonjs/hooks/documents.js +138 -0
- package/dist/commonjs/hooks/maps.js +37 -0
- package/dist/commonjs/hooks/projects.d.ts +251 -0
- package/dist/commonjs/hooks/projects.js +258 -0
- package/dist/commonjs/index.d.ts +11 -0
- package/dist/commonjs/index.js +69 -0
- package/dist/commonjs/lib/react-query/client.d.ts +30 -0
- package/dist/commonjs/lib/react-query/client.js +36 -0
- package/dist/{lib → commonjs/lib}/react-query/documents.d.ts +101 -101
- package/dist/commonjs/lib/react-query/documents.js +92 -0
- package/dist/commonjs/lib/react-query/invites.d.ts +12 -0
- package/dist/commonjs/lib/react-query/invites.js +22 -0
- package/dist/commonjs/lib/react-query/maps.d.ts +15 -0
- package/dist/commonjs/lib/react-query/maps.js +23 -0
- package/dist/commonjs/lib/react-query/projects.d.ts +196 -0
- package/dist/commonjs/lib/react-query/projects.js +147 -0
- package/dist/commonjs/lib/react-query/shared.js +16 -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 +2 -2
- package/dist/{hooks → esm/hooks}/client.js +2 -2
- package/dist/esm/hooks/documents.d.ts +112 -0
- package/dist/{hooks → esm/hooks}/documents.js +2 -2
- 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 +6 -6
- package/dist/{hooks → esm/hooks}/projects.js +2 -2
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/lib/react-query/client.d.ts +30 -0
- package/dist/{lib → esm/lib}/react-query/client.js +1 -1
- package/dist/esm/lib/react-query/documents.d.ts +1501 -0
- package/dist/{lib → esm/lib}/react-query/documents.js +1 -1
- package/dist/esm/lib/react-query/invites.d.ts +12 -0
- package/dist/{lib → esm/lib}/react-query/invites.js +1 -1
- package/dist/esm/lib/react-query/maps.d.ts +15 -0
- package/dist/{lib → esm/lib}/react-query/maps.js +1 -1
- package/dist/esm/lib/react-query/projects.d.ts +196 -0
- package/dist/{lib → esm/lib}/react-query/projects.js +1 -1
- package/dist/esm/lib/react-query/shared.d.ts +5 -0
- package/dist/esm/package.json +3 -0
- package/package.json +27 -12
- 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/invites.d.ts +0 -12
- 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/{lib → commonjs/lib}/react-query/shared.d.ts +0 -0
- /package/dist/{contexts → esm/contexts}/ClientApi.js +0 -0
- /package/dist/{lib → esm/lib}/react-query/shared.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,59 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useClientApi = useClientApi;
|
|
4
|
+
exports.useOwnDeviceInfo = useOwnDeviceInfo;
|
|
5
|
+
exports.useIsArchiveDevice = useIsArchiveDevice;
|
|
6
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const ClientApi_js_1 = require("../contexts/ClientApi.js");
|
|
9
|
+
const client_js_1 = require("../lib/react-query/client.js");
|
|
10
|
+
/**
|
|
11
|
+
* Access a client API instance. If a ClientApiContext provider is not
|
|
12
|
+
* set up, it will throw an error.
|
|
13
|
+
*
|
|
14
|
+
* @returns Client API instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function ClientExample() {
|
|
19
|
+
* return (
|
|
20
|
+
* // Creation of clientApi omitted for brevity
|
|
21
|
+
* <ClientApiContext.Provider clientApi={clientApi}>
|
|
22
|
+
* <ComponentThatUsesClient />
|
|
23
|
+
* </ClientApiContext.Provider>
|
|
24
|
+
* )
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* function ComponentThatUsesClient() {
|
|
28
|
+
* const clientApi = useClientApi()
|
|
29
|
+
*
|
|
30
|
+
* // Rest omitted for brevity.
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
function useClientApi() {
|
|
36
|
+
const clientApi = (0, react_1.useContext)(ClientApi_js_1.ClientApiContext);
|
|
37
|
+
if (!clientApi) {
|
|
38
|
+
throw new Error('No client API set. Make sure you set up the ClientApiContext provider properly');
|
|
39
|
+
}
|
|
40
|
+
return clientApi;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve info about the current device.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* function DeviceInfoExample() {
|
|
48
|
+
* const { data } = useDeviceInfo()
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
function useOwnDeviceInfo() {
|
|
53
|
+
const clientApi = useClientApi();
|
|
54
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, client_js_1.deviceInfoQueryOptions)({ clientApi }));
|
|
55
|
+
return { data, error, isRefetching };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve whether the current device is an archive device or not.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* function IsArchiveDeviceExample() {
|
|
63
|
+
* const { data } = useIsArchiveDevice()
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function useIsArchiveDevice() {
|
|
68
|
+
const clientApi = useClientApi();
|
|
69
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, client_js_1.isArchiveDeviceQueryOptions)({ clientApi }));
|
|
70
|
+
return { data, error, isRefetching };
|
|
71
|
+
}
|
|
@@ -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 DocumentType } from '../lib/react-query/documents.js';
|
|
3
3
|
type ReadHookResult<D> = {
|
|
4
4
|
data: D;
|
|
5
5
|
error: Error | null;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSingleDocByDocId = useSingleDocByDocId;
|
|
4
|
+
exports.useSingleDocByVersionId = useSingleDocByVersionId;
|
|
5
|
+
exports.useManyDocs = useManyDocs;
|
|
6
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
7
|
+
const documents_js_1 = require("../lib/react-query/documents.js");
|
|
8
|
+
const projects_js_1 = require("./projects.js");
|
|
9
|
+
/**
|
|
10
|
+
* Retrieve a single document from the database based on the document's document ID.
|
|
11
|
+
*
|
|
12
|
+
* Triggers the closest error boundary if the document cannot be found
|
|
13
|
+
*
|
|
14
|
+
* @param opts.projectId Project public ID
|
|
15
|
+
* @param opts.docType Document type of interest
|
|
16
|
+
* @param opts.docId Document ID
|
|
17
|
+
* @param opts.lang Language to translate the document into
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* function SingleDocumentByDocIdExample() {
|
|
22
|
+
* const { data } = useSingleDocByDocId({
|
|
23
|
+
* projectId: '...',
|
|
24
|
+
* docType: 'observation',
|
|
25
|
+
* docId: '...',
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* console.log(data.schemaName) // logs 'observation'
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function useSingleDocByDocId({ projectId, docType, docId, lang, }) {
|
|
33
|
+
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
34
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, documents_js_1.documentByDocumentIdQueryOptions)({
|
|
35
|
+
projectApi,
|
|
36
|
+
projectId,
|
|
37
|
+
docType,
|
|
38
|
+
docId,
|
|
39
|
+
lang,
|
|
40
|
+
}));
|
|
41
|
+
return {
|
|
42
|
+
// @ts-expect-error - TS does not handle dependent types, so this will not
|
|
43
|
+
// be narrowed properly within the function body. See for example
|
|
44
|
+
// https://github.com/microsoft/TypeScript/issues/33014#event-15134418011
|
|
45
|
+
data,
|
|
46
|
+
error,
|
|
47
|
+
isRefetching,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve a single document from the database based on the document's version ID.
|
|
52
|
+
*
|
|
53
|
+
* Triggers the closest error boundary if the document cannot be found.
|
|
54
|
+
*
|
|
55
|
+
* @param opts.projectId Project public ID
|
|
56
|
+
* @param opts.docType Document type of interest
|
|
57
|
+
* @param opts.versionId Document's version ID
|
|
58
|
+
* @param opts.lang Language to translate the document into
|
|
59
|
+
*
|
|
60
|
+
* * @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* function SingleDocumentByVersionIdExample() {
|
|
63
|
+
* const { data } = useSingleDocByVersionId({
|
|
64
|
+
* projectId: '...',
|
|
65
|
+
* docType: 'observation',
|
|
66
|
+
* docId: '...',
|
|
67
|
+
* })
|
|
68
|
+
*
|
|
69
|
+
* console.log(data.schemaName) // logs 'observation'
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
function useSingleDocByVersionId({ projectId, docType, versionId, lang, }) {
|
|
74
|
+
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
75
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, documents_js_1.documentByVersionIdQueryOptions)({
|
|
76
|
+
projectApi,
|
|
77
|
+
projectId,
|
|
78
|
+
docType,
|
|
79
|
+
versionId,
|
|
80
|
+
lang,
|
|
81
|
+
}));
|
|
82
|
+
return {
|
|
83
|
+
// @ts-expect-error - TS does not handle dependent types, see above
|
|
84
|
+
data,
|
|
85
|
+
error,
|
|
86
|
+
isRefetching,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieve all documents of a specific `docType`.
|
|
91
|
+
*
|
|
92
|
+
* @param opts.projectId Project public ID
|
|
93
|
+
* @param opts.docType Document type of interest
|
|
94
|
+
* @param opts.includeDeleted Include documents that have been marked as deleted
|
|
95
|
+
* @param opts.lang Language to translate the documents into
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* function BasicExample() {
|
|
100
|
+
* const { data } = useManyDocs({
|
|
101
|
+
* projectId: '...',
|
|
102
|
+
* docType: 'observations',
|
|
103
|
+
* })
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* ```tsx
|
|
108
|
+
* function useAllObservations(opts) {
|
|
109
|
+
* return useManyDocs({
|
|
110
|
+
* ...opts,
|
|
111
|
+
* docType: 'observations',
|
|
112
|
+
* })
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* function useAllPresets(opts) {
|
|
116
|
+
* return useManyDocs({
|
|
117
|
+
* ...opts,
|
|
118
|
+
* docType: 'presets',
|
|
119
|
+
* })
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
function useManyDocs({ projectId, docType, includeDeleted, lang, }) {
|
|
124
|
+
const { data: projectApi } = (0, projects_js_1.useSingleProject)({ projectId });
|
|
125
|
+
const { data, error, isRefetching } = (0, react_query_1.useSuspenseQuery)((0, documents_js_1.documentsQueryOptions)({
|
|
126
|
+
projectApi,
|
|
127
|
+
projectId,
|
|
128
|
+
docType,
|
|
129
|
+
includeDeleted,
|
|
130
|
+
lang,
|
|
131
|
+
}));
|
|
132
|
+
return {
|
|
133
|
+
// @ts-expect-error - TS does not handle dependent types, see above
|
|
134
|
+
data,
|
|
135
|
+
error,
|
|
136
|
+
isRefetching,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
/**
|
|
4
|
+
* Retrieve the project settings for a project.
|
|
5
|
+
*
|
|
6
|
+
* @param opts.projectId Project public ID
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* function BasicExample() {
|
|
11
|
+
* const { data } = useProjectSettings({ projectId: '...' })
|
|
12
|
+
*
|
|
13
|
+
* console.log(data.name)
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useProjectSettings({ projectId }: {
|
|
18
|
+
projectId: string;
|
|
19
|
+
}): {
|
|
20
|
+
data: import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).EditableProjectSettings;
|
|
21
|
+
error: Error | null;
|
|
22
|
+
isRefetching: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve a project API instance for a project.
|
|
26
|
+
*
|
|
27
|
+
* This is mostly used internally by the other hooks and should only be used if certain project APIs are not exposed via the hooks.
|
|
28
|
+
*
|
|
29
|
+
* @param opts.projectId Project public ID
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* function BasicExample() {
|
|
34
|
+
* const { data } = useSingleProject({ projectId: '...' })
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function useSingleProject({ projectId }: {
|
|
39
|
+
projectId: string;
|
|
40
|
+
}): {
|
|
41
|
+
data: import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/mapeo-project.js", { with: { "resolution-mode": "import" } }).MapeoProject>;
|
|
42
|
+
error: Error | null;
|
|
43
|
+
isRefetching: boolean;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve project information for each project that exists.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* function BasicExample() {
|
|
51
|
+
* const { data } = useManyProjects()
|
|
52
|
+
*
|
|
53
|
+
* console.log(data.map(project => project.name))
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function useManyProjects(): {
|
|
58
|
+
data: (Pick<{
|
|
59
|
+
schemaName: "projectSettings";
|
|
60
|
+
name?: string | undefined;
|
|
61
|
+
defaultPresets?: {
|
|
62
|
+
point: string[];
|
|
63
|
+
area: string[];
|
|
64
|
+
vertex: string[];
|
|
65
|
+
line: string[];
|
|
66
|
+
relation: string[];
|
|
67
|
+
} | undefined;
|
|
68
|
+
configMetadata?: {
|
|
69
|
+
name: string;
|
|
70
|
+
buildDate: string;
|
|
71
|
+
importDate: string;
|
|
72
|
+
fileVersion: string;
|
|
73
|
+
} | undefined;
|
|
74
|
+
}, "name"> & {
|
|
75
|
+
projectId: string;
|
|
76
|
+
createdAt?: string | undefined;
|
|
77
|
+
updatedAt?: string | undefined;
|
|
78
|
+
})[];
|
|
79
|
+
error: Error | null;
|
|
80
|
+
isRefetching: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Retrieve a single member of a project.
|
|
84
|
+
*
|
|
85
|
+
* @param opts.projectId Project public ID
|
|
86
|
+
* @param opts.projectId Device ID of interest
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* function BasicExample() {
|
|
91
|
+
* const { data } = useSingleMember({ projectId: '...', deviceId: '...' })
|
|
92
|
+
*
|
|
93
|
+
* console.log(data.role)
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function useSingleMember({ projectId, deviceId, }: {
|
|
98
|
+
projectId: string;
|
|
99
|
+
deviceId: string;
|
|
100
|
+
}): {
|
|
101
|
+
data: import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo;
|
|
102
|
+
error: Error | null;
|
|
103
|
+
isRefetching: boolean;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Retrieve all members of a project.
|
|
107
|
+
*
|
|
108
|
+
* @param opts.projectId Project public ID
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* function BasicExample() {
|
|
113
|
+
* const { data } = useManyMembers({ projectId: '...' })
|
|
114
|
+
*
|
|
115
|
+
* console.log(data.role)
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function useManyMembers({ projectId }: {
|
|
120
|
+
projectId: string;
|
|
121
|
+
}): {
|
|
122
|
+
data: import("@comapeo/core/dist/member-api.js", { with: { "resolution-mode": "import" } }).MemberInfo[];
|
|
123
|
+
error: Error | null;
|
|
124
|
+
isRefetching: boolean;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve a URL that points to icon resources served by the embedded HTTP server.
|
|
128
|
+
*
|
|
129
|
+
* _TODO: Explain bitmap opts vs svg opts_
|
|
130
|
+
*
|
|
131
|
+
* @param opts.projectId Project public ID
|
|
132
|
+
* @param opts.iconId Icon ID of interest
|
|
133
|
+
* @param opts.mimeType MIME type of desired resource
|
|
134
|
+
* @param opts.pixelDensity Pixel density resource (only applicable when `mimeType` is `'image/png'`)
|
|
135
|
+
* @param opts.size Size of desired resource
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* function PngExample() {
|
|
140
|
+
* const { data } = useIconUrl({
|
|
141
|
+
* projectId: '...',
|
|
142
|
+
* iconId: '...',
|
|
143
|
+
* mimeType: 'image/png',
|
|
144
|
+
* pixelDensity: 1,
|
|
145
|
+
* size: 'medium'
|
|
146
|
+
* })
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* ```tsx
|
|
151
|
+
* function SvgExample() {
|
|
152
|
+
* const { data } = useIconUrl({
|
|
153
|
+
* projectId: '...',
|
|
154
|
+
* iconId: '...',
|
|
155
|
+
* mimeType: 'image/svg',
|
|
156
|
+
* size: 'medium'
|
|
157
|
+
* })
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function useIconUrl({ projectId, iconId, ...mimeBasedOpts }: {
|
|
162
|
+
projectId: string;
|
|
163
|
+
iconId: string;
|
|
164
|
+
} & (BitmapOpts | SvgOpts)): {
|
|
165
|
+
data: string;
|
|
166
|
+
error: Error | null;
|
|
167
|
+
isRefetching: boolean;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Retrieve a URL that points to a desired blob resource.
|
|
171
|
+
*
|
|
172
|
+
* _TODO: Explain BlobId in more depth_
|
|
173
|
+
*
|
|
174
|
+
* @param opts.projectId Project public Id
|
|
175
|
+
* @param opts.blobId Blob ID of the desired resource
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```tsx
|
|
179
|
+
* function PhotoExample() {
|
|
180
|
+
* const { data } = useAttachmentUrl({
|
|
181
|
+
* projectId: '...',
|
|
182
|
+
* blobId: {
|
|
183
|
+
* type: 'photo',
|
|
184
|
+
* variant: 'thumbnail',
|
|
185
|
+
* name: '...',
|
|
186
|
+
* driveId: '...',
|
|
187
|
+
* }
|
|
188
|
+
* })
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* ```tsx
|
|
193
|
+
* function AudioExample() {
|
|
194
|
+
* const { data } = useAttachmentUrl({
|
|
195
|
+
* projectId: '...',
|
|
196
|
+
* blobId: {
|
|
197
|
+
* type: 'audio',
|
|
198
|
+
* variant: 'original',
|
|
199
|
+
* name: '...',
|
|
200
|
+
* driveId: '...',
|
|
201
|
+
* }
|
|
202
|
+
* })
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* ```tsx
|
|
207
|
+
* function VideoExample() {
|
|
208
|
+
* const { data } = useAttachmentUrl({
|
|
209
|
+
* projectId: '...',
|
|
210
|
+
* blobId: {
|
|
211
|
+
* type: 'video',
|
|
212
|
+
* variant: 'original',
|
|
213
|
+
* name: '...',
|
|
214
|
+
* driveId: '...',
|
|
215
|
+
* }
|
|
216
|
+
* })
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function useAttachmentUrl({ projectId, blobId, }: {
|
|
221
|
+
projectId: string;
|
|
222
|
+
blobId: BlobId;
|
|
223
|
+
}): {
|
|
224
|
+
data: string;
|
|
225
|
+
error: Error | null;
|
|
226
|
+
isRefetching: boolean;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Retrieve the device ID that created a document.
|
|
230
|
+
*
|
|
231
|
+
* @param opts.projectId Project public ID
|
|
232
|
+
* @param opts.originalVersionId Version ID of document
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```tsx
|
|
236
|
+
* function BasicExample() {
|
|
237
|
+
* const { data } = useDocumentCreatedBy({
|
|
238
|
+
* projectId: '...',
|
|
239
|
+
* originalVersionId: '...',
|
|
240
|
+
* })
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export declare function useDocumentCreatedBy({ projectId, originalVersionId, }: {
|
|
245
|
+
projectId: string;
|
|
246
|
+
originalVersionId: string;
|
|
247
|
+
}): {
|
|
248
|
+
data: string;
|
|
249
|
+
error: Error | null;
|
|
250
|
+
isRefetching: boolean;
|
|
251
|
+
};
|