@comapeo/core-react 7.2.0 → 8.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 (37) hide show
  1. package/dist/commonjs/contexts/ClientApi.d.ts +3 -1
  2. package/dist/commonjs/contexts/ClientApi.js +14 -0
  3. package/dist/commonjs/hooks/client.d.ts +3 -1
  4. package/dist/commonjs/hooks/documents.d.ts +3 -1
  5. package/dist/commonjs/hooks/invites.d.ts +0 -16
  6. package/dist/commonjs/hooks/invites.js +0 -32
  7. package/dist/commonjs/hooks/projects.d.ts +17 -3
  8. package/dist/commonjs/index.d.ts +2 -2
  9. package/dist/commonjs/index.js +1 -4
  10. package/dist/commonjs/lib/presets.d.ts +3 -1
  11. package/dist/commonjs/lib/react-query/client.d.ts +6 -2
  12. package/dist/commonjs/lib/react-query/documents.d.ts +7 -3
  13. package/dist/commonjs/lib/react-query/invites.d.ts +6 -2
  14. package/dist/commonjs/lib/react-query/maps.d.ts +3 -1
  15. package/dist/commonjs/lib/react-query/projects.d.ts +5 -1
  16. package/dist/commonjs/lib/react-query/projects.js +1 -6
  17. package/dist/commonjs/lib/sync.d.ts +3 -1
  18. package/dist/commonjs/lib/types.d.ts +3 -1
  19. package/dist/esm/contexts/ClientApi.d.ts +3 -1
  20. package/dist/esm/contexts/ClientApi.js +15 -1
  21. package/dist/esm/hooks/client.d.ts +3 -1
  22. package/dist/esm/hooks/documents.d.ts +3 -1
  23. package/dist/esm/hooks/invites.d.ts +0 -16
  24. package/dist/esm/hooks/invites.js +1 -32
  25. package/dist/esm/hooks/projects.d.ts +17 -3
  26. package/dist/esm/index.d.ts +2 -2
  27. package/dist/esm/index.js +2 -2
  28. package/dist/esm/lib/presets.d.ts +3 -1
  29. package/dist/esm/lib/react-query/client.d.ts +6 -2
  30. package/dist/esm/lib/react-query/documents.d.ts +7 -3
  31. package/dist/esm/lib/react-query/invites.d.ts +6 -2
  32. package/dist/esm/lib/react-query/maps.d.ts +3 -1
  33. package/dist/esm/lib/react-query/projects.d.ts +5 -1
  34. package/dist/esm/lib/react-query/projects.js +1 -6
  35. package/dist/esm/lib/sync.d.ts +3 -1
  36. package/dist/esm/lib/types.d.ts +3 -1
  37. package/package.json +28 -28
@@ -1,4 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  import { type Context, type JSX, type ReactNode } from 'react';
3
5
  export declare const ClientApiContext: Context<MapeoClientApi | null>;
4
6
  /**
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClientApiContext = void 0;
4
4
  exports.ClientApiProvider = ClientApiProvider;
5
+ const react_query_1 = require("@tanstack/react-query");
5
6
  const react_1 = require("react");
7
+ const invites_js_1 = require("../lib/react-query/invites.js");
6
8
  exports.ClientApiContext = (0, react_1.createContext)(null);
7
9
  /**
8
10
  * Create a context provider that holds a CoMapeo API client instance.
@@ -12,5 +14,17 @@ exports.ClientApiContext = (0, react_1.createContext)(null);
12
14
  *
13
15
  */
14
16
  function ClientApiProvider({ children, clientApi, }) {
17
+ const queryClient = (0, react_query_1.useQueryClient)();
18
+ (0, react_1.useEffect)(() => {
19
+ function invalidateCache() {
20
+ queryClient.invalidateQueries({ queryKey: (0, invites_js_1.getInvitesQueryKey)() });
21
+ }
22
+ clientApi.invite.addListener('invite-received', invalidateCache);
23
+ clientApi.invite.addListener('invite-updated', invalidateCache);
24
+ return () => {
25
+ clientApi.invite.removeListener('invite-received', invalidateCache);
26
+ clientApi.invite.removeListener('invite-updated', invalidateCache);
27
+ };
28
+ }, [clientApi, queryClient]);
15
29
  return (0, react_1.createElement)(exports.ClientApiContext.Provider, { value: clientApi }, children);
16
30
  }
@@ -1,4 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  /**
3
5
  * Access a client API instance. If a ClientApiContext provider is not
4
6
  * set up, it will throw an error.
@@ -1,4 +1,6 @@
1
- import type { Preset } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { Preset } from '@comapeo/schema' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  import type { WriteableDocumentType } from '../lib/types.js';
3
5
  /**
4
6
  * Retrieve a single document from the database based on the document's document ID.
@@ -1,19 +1,3 @@
1
- /**
2
- * Set up listeners for received and updated invites.
3
- * It is necessary to use this if you want the invites-related read hooks to update
4
- * based on invites that are received or changed in the background.
5
- *
6
- * @example
7
- * ```tsx
8
- * function App() {
9
- * // Use this somewhere near the root of the application
10
- * useSetUpInvitesListeners()
11
- *
12
- * return <RestOfApp />
13
- * }
14
- * ```
15
- */
16
- export declare function useSetUpInvitesListeners(): void;
17
1
  /**
18
2
  * Get all invites that the device has received.
19
3
  *
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSetUpInvitesListeners = useSetUpInvitesListeners;
4
3
  exports.useManyInvites = useManyInvites;
5
4
  exports.useSingleInvite = useSingleInvite;
6
5
  exports.useAcceptInvite = useAcceptInvite;
@@ -8,40 +7,9 @@ exports.useRejectInvite = useRejectInvite;
8
7
  exports.useSendInvite = useSendInvite;
9
8
  exports.useRequestCancelInvite = useRequestCancelInvite;
10
9
  const react_query_1 = require("@tanstack/react-query");
11
- const react_1 = require("react");
12
10
  const invites_js_1 = require("../lib/react-query/invites.js");
13
11
  const client_js_1 = require("./client.js");
14
12
  const projects_js_1 = require("./projects.js");
15
- /**
16
- * Set up listeners for received and updated invites.
17
- * It is necessary to use this if you want the invites-related read hooks to update
18
- * based on invites that are received or changed in the background.
19
- *
20
- * @example
21
- * ```tsx
22
- * function App() {
23
- * // Use this somewhere near the root of the application
24
- * useSetUpInvitesListeners()
25
- *
26
- * return <RestOfApp />
27
- * }
28
- * ```
29
- */
30
- function useSetUpInvitesListeners() {
31
- const queryClient = (0, react_query_1.useQueryClient)();
32
- const clientApi = (0, client_js_1.useClientApi)();
33
- (0, react_1.useEffect)(() => {
34
- function invalidateCache() {
35
- queryClient.invalidateQueries({ queryKey: (0, invites_js_1.getInvitesQueryKey)() });
36
- }
37
- clientApi.invite.addListener('invite-received', invalidateCache);
38
- clientApi.invite.addListener('invite-updated', invalidateCache);
39
- return () => {
40
- clientApi.invite.removeListener('invite-received', invalidateCache);
41
- clientApi.invite.removeListener('invite-updated', invalidateCache);
42
- };
43
- }, [clientApi, queryClient]);
44
- }
45
13
  /**
46
14
  * Get all invites that the device has received.
47
15
  *
@@ -1,6 +1,12 @@
1
- import type { BlobApi, IconApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { RoleChangeEvent } from '@comapeo/core/dist/mapeo-project.js' with { 'resolution-mode': 'import' };
3
- import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { BlobApi, IconApi } from '@comapeo/core' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { RoleChangeEvent } from '@comapeo/core/dist/mapeo-project.js' with {
5
+ 'resolution-mode': 'import'
6
+ };
7
+ import type { MapeoProjectApi } from '@comapeo/ipc' with {
8
+ 'resolution-mode': 'import'
9
+ };
4
10
  import { type SyncState } from '../lib/sync.js';
5
11
  /**
6
12
  * Retrieve the project settings for a project.
@@ -319,10 +325,14 @@ export declare function useCreateProject(): {
319
325
  mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
320
326
  name?: string;
321
327
  configPath?: string;
328
+ projectColor?: string;
329
+ projectDescription?: string;
322
330
  } | undefined, unknown>;
323
331
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
324
332
  name?: string;
325
333
  configPath?: string;
334
+ projectColor?: string;
335
+ projectDescription?: string;
326
336
  } | undefined, unknown>;
327
337
  reset: () => void;
328
338
  status: "error";
@@ -331,10 +341,14 @@ export declare function useCreateProject(): {
331
341
  mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
332
342
  name?: string;
333
343
  configPath?: string;
344
+ projectColor?: string;
345
+ projectDescription?: string;
334
346
  } | undefined, unknown>;
335
347
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
336
348
  name?: string;
337
349
  configPath?: string;
350
+ projectColor?: string;
351
+ projectDescription?: string;
338
352
  } | undefined, unknown>;
339
353
  reset: () => void;
340
354
  status: "pending" | "success" | "idle";
@@ -1,7 +1,7 @@
1
- export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
1
+ export { ClientApiProvider } from './contexts/ClientApi.js';
2
2
  export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
3
3
  export { useCreateDocument, useDeleteDocument, useManyDocs, usePresetsSelection, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
4
- export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSetUpInvitesListeners, useSingleInvite, } from './hooks/invites.js';
4
+ export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSingleInvite, } from './hooks/invites.js';
5
5
  export { useMapStyleUrl } from './hooks/maps.js';
6
6
  export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectCategories, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectOwnRoleChangeListener, useProjectSettings, useRemoveServerPeer, useRemoveMember, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
7
7
  export { type SyncState } from './lib/sync.js';
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useExportGeoJSON = exports.useChangeMemberRole = exports.useUpdateProjectSettings = exports.useSyncState = exports.useStopSync = exports.useStartSync = exports.useSingleProject = exports.useSingleMember = exports.useSetAutostopDataSyncTimeout = exports.useRemoveMember = exports.useRemoveServerPeer = exports.useProjectSettings = exports.useProjectOwnRoleChangeListener = exports.useOwnRoleInProject = exports.useManyProjects = exports.useManyMembers = exports.useLeaveProject = exports.useImportProjectConfig = exports.useImportProjectCategories = exports.useIconUrl = exports.useDocumentCreatedBy = exports.useDisconnectSyncServers = exports.useDataSyncProgress = exports.useCreateProject = exports.useCreateBlob = exports.useConnectSyncServers = exports.useAttachmentUrl = exports.useAddServerPeer = exports.useMapStyleUrl = exports.useSingleInvite = exports.useSetUpInvitesListeners = exports.useSendInvite = exports.useRequestCancelInvite = exports.useRejectInvite = exports.useManyInvites = exports.useAcceptInvite = exports.useUpdateDocument = exports.useSingleDocByVersionId = exports.useSingleDocByDocId = exports.usePresetsSelection = exports.useManyDocs = exports.useDeleteDocument = exports.useCreateDocument = exports.useSetOwnDeviceInfo = exports.useSetIsArchiveDevice = exports.useOwnDeviceInfo = exports.useIsArchiveDevice = exports.useClientApi = exports.ClientApiProvider = exports.ClientApiContext = void 0;
4
- exports.useExportZipFile = void 0;
3
+ exports.useExportZipFile = exports.useExportGeoJSON = exports.useChangeMemberRole = exports.useUpdateProjectSettings = exports.useSyncState = exports.useStopSync = exports.useStartSync = exports.useSingleProject = exports.useSingleMember = exports.useSetAutostopDataSyncTimeout = exports.useRemoveMember = exports.useRemoveServerPeer = exports.useProjectSettings = exports.useProjectOwnRoleChangeListener = exports.useOwnRoleInProject = exports.useManyProjects = exports.useManyMembers = exports.useLeaveProject = exports.useImportProjectConfig = exports.useImportProjectCategories = exports.useIconUrl = exports.useDocumentCreatedBy = exports.useDisconnectSyncServers = exports.useDataSyncProgress = exports.useCreateProject = exports.useCreateBlob = exports.useConnectSyncServers = exports.useAttachmentUrl = exports.useAddServerPeer = exports.useMapStyleUrl = exports.useSingleInvite = exports.useSendInvite = exports.useRequestCancelInvite = exports.useRejectInvite = exports.useManyInvites = exports.useAcceptInvite = exports.useUpdateDocument = exports.useSingleDocByVersionId = exports.useSingleDocByDocId = exports.usePresetsSelection = exports.useManyDocs = exports.useDeleteDocument = exports.useCreateDocument = exports.useSetOwnDeviceInfo = exports.useSetIsArchiveDevice = exports.useOwnDeviceInfo = exports.useIsArchiveDevice = exports.useClientApi = exports.ClientApiProvider = void 0;
5
4
  var ClientApi_js_1 = require("./contexts/ClientApi.js");
6
- Object.defineProperty(exports, "ClientApiContext", { enumerable: true, get: function () { return ClientApi_js_1.ClientApiContext; } });
7
5
  Object.defineProperty(exports, "ClientApiProvider", { enumerable: true, get: function () { return ClientApi_js_1.ClientApiProvider; } });
8
6
  var client_js_1 = require("./hooks/client.js");
9
7
  Object.defineProperty(exports, "useClientApi", { enumerable: true, get: function () { return client_js_1.useClientApi; } });
@@ -25,7 +23,6 @@ Object.defineProperty(exports, "useManyInvites", { enumerable: true, get: functi
25
23
  Object.defineProperty(exports, "useRejectInvite", { enumerable: true, get: function () { return invites_js_1.useRejectInvite; } });
26
24
  Object.defineProperty(exports, "useRequestCancelInvite", { enumerable: true, get: function () { return invites_js_1.useRequestCancelInvite; } });
27
25
  Object.defineProperty(exports, "useSendInvite", { enumerable: true, get: function () { return invites_js_1.useSendInvite; } });
28
- Object.defineProperty(exports, "useSetUpInvitesListeners", { enumerable: true, get: function () { return invites_js_1.useSetUpInvitesListeners; } });
29
26
  Object.defineProperty(exports, "useSingleInvite", { enumerable: true, get: function () { return invites_js_1.useSingleInvite; } });
30
27
  var maps_js_1 = require("./hooks/maps.js");
31
28
  Object.defineProperty(exports, "useMapStyleUrl", { enumerable: true, get: function () { return maps_js_1.useMapStyleUrl; } });
@@ -1,2 +1,4 @@
1
- import type { Preset } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { Preset } from '@comapeo/schema' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export declare function getPresetsSelection(presets: Array<Preset>, orderedPresetIds?: Array<string>): Array<Preset>;
@@ -1,5 +1,9 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
2
- import type { DeviceInfo } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { DeviceInfo } from '@comapeo/schema' with {
5
+ 'resolution-mode': 'import'
6
+ };
3
7
  import { type QueryClient } from '@tanstack/react-query';
4
8
  export declare function getClientQueryKey(): readonly ["@comapeo/core-react", "client"];
5
9
  export declare function getDeviceInfoQueryKey(): readonly ["@comapeo/core-react", "client", "device_info"];
@@ -1,7 +1,11 @@
1
- import type { DerivedDocFields } from '@comapeo/core/dist/datatype/index.js' with { 'resolution-mode': 'import' };
2
- import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { DerivedDocFields } from '@comapeo/core/dist/datatype/index.js' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { MapeoProjectApi } from '@comapeo/ipc' with {
5
+ 'resolution-mode': 'import'
6
+ };
3
7
  import { type QueryClient } from '@tanstack/react-query';
4
- import { WriteableDocument, WriteableDocumentType, WriteableValue } from '../types.js';
8
+ import type { WriteableDocument, WriteableDocumentType, WriteableValue } from '../types.js';
5
9
  export declare function getDocumentsQueryKey<D extends WriteableDocumentType>({ projectId, docType, }: {
6
10
  projectId: string;
7
11
  docType: D;
@@ -1,5 +1,9 @@
1
- import type { MemberApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MemberApi } from '@comapeo/core' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with {
5
+ 'resolution-mode': 'import'
6
+ };
3
7
  import { type QueryClient } from '@tanstack/react-query';
4
8
  export declare function getInvitesQueryKey(): readonly ["@comapeo/core-react", "invites"];
5
9
  export declare function getInvitesByIdQueryKey({ inviteId }: {
@@ -1,4 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export declare function getMapsQueryKey(): readonly ["@comapeo/core-react", "maps"];
3
5
  export declare function getStyleJsonUrlQueryKey({ refreshToken, }: {
4
6
  refreshToken?: string;
@@ -1,5 +1,7 @@
1
1
  import type { BlobApi, MemberApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
2
+ import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with {
3
+ 'resolution-mode': 'import'
4
+ };
3
5
  import { type QueryClient, type UnusedSkipTokenOptions } from '@tanstack/react-query';
4
6
  export declare function getProjectsQueryKey(): readonly ["@comapeo/core-react", "projects"];
5
7
  export declare function getProjectByIdQueryKey({ projectId }: {
@@ -150,6 +152,8 @@ export declare function createProjectMutationOptions({ clientApi, queryClient, }
150
152
  mutationFn: (opts: {
151
153
  name?: string;
152
154
  configPath?: string;
155
+ projectColor?: string;
156
+ projectDescription?: string;
153
157
  } | undefined) => Promise<string>;
154
158
  onSuccess: () => void;
155
159
  networkMode: "always";
@@ -197,12 +197,7 @@ function createProjectMutationOptions({ clientApi, queryClient, }) {
197
197
  mutationFn: async (opts) => {
198
198
  // Have to avoid passing `undefined` explicitly
199
199
  // See https://github.com/digidem/rpc-reflector/issues/21
200
- return opts
201
- ? clientApi.createProject({
202
- configPath: opts.configPath,
203
- name: opts.name,
204
- })
205
- : clientApi.createProject();
200
+ return opts ? clientApi.createProject(opts) : clientApi.createProject();
206
201
  },
207
202
  onSuccess: () => {
208
203
  queryClient.invalidateQueries({
@@ -1,4 +1,6 @@
1
- import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoProjectApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export type SyncState = Awaited<ReturnType<MapeoProjectApi['$sync']['getState']>>;
3
5
  export declare function getDataSyncCountForDevice(syncStateForDevice: SyncState['remoteDeviceSyncState'][string]): number;
4
6
  export declare class SyncStore {
@@ -1,4 +1,6 @@
1
- import type { MapeoDoc, MapeoValue } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { MapeoDoc, MapeoValue } from '@comapeo/schema' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export type WriteableDocumentType = Extract<MapeoDoc['schemaName'], 'field' | 'observation' | 'preset' | 'track' | 'remoteDetectionAlert'>;
3
5
  export type WriteableValue<D extends WriteableDocumentType> = Extract<MapeoValue, {
4
6
  schemaName: D;
@@ -1,4 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  import { type Context, type JSX, type ReactNode } from 'react';
3
5
  export declare const ClientApiContext: Context<MapeoClientApi | null>;
4
6
  /**
@@ -1,4 +1,6 @@
1
- import { createContext, createElement, } from 'react';
1
+ import { useQueryClient } from '@tanstack/react-query';
2
+ import { createContext, createElement, useEffect, } from 'react';
3
+ import { getInvitesQueryKey } from '../lib/react-query/invites.js';
2
4
  export const ClientApiContext = createContext(null);
3
5
  /**
4
6
  * Create a context provider that holds a CoMapeo API client instance.
@@ -8,5 +10,17 @@ export const ClientApiContext = createContext(null);
8
10
  *
9
11
  */
10
12
  export function ClientApiProvider({ children, clientApi, }) {
13
+ const queryClient = useQueryClient();
14
+ useEffect(() => {
15
+ function invalidateCache() {
16
+ queryClient.invalidateQueries({ queryKey: getInvitesQueryKey() });
17
+ }
18
+ clientApi.invite.addListener('invite-received', invalidateCache);
19
+ clientApi.invite.addListener('invite-updated', invalidateCache);
20
+ return () => {
21
+ clientApi.invite.removeListener('invite-received', invalidateCache);
22
+ clientApi.invite.removeListener('invite-updated', invalidateCache);
23
+ };
24
+ }, [clientApi, queryClient]);
11
25
  return createElement(ClientApiContext.Provider, { value: clientApi }, children);
12
26
  }
@@ -1,4 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  /**
3
5
  * Access a client API instance. If a ClientApiContext provider is not
4
6
  * set up, it will throw an error.
@@ -1,4 +1,6 @@
1
- import type { Preset } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { Preset } from '@comapeo/schema' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  import type { WriteableDocumentType } from '../lib/types.js';
3
5
  /**
4
6
  * Retrieve a single document from the database based on the document's document ID.
@@ -1,19 +1,3 @@
1
- /**
2
- * Set up listeners for received and updated invites.
3
- * It is necessary to use this if you want the invites-related read hooks to update
4
- * based on invites that are received or changed in the background.
5
- *
6
- * @example
7
- * ```tsx
8
- * function App() {
9
- * // Use this somewhere near the root of the application
10
- * useSetUpInvitesListeners()
11
- *
12
- * return <RestOfApp />
13
- * }
14
- * ```
15
- */
16
- export declare function useSetUpInvitesListeners(): void;
17
1
  /**
18
2
  * Get all invites that the device has received.
19
3
  *
@@ -1,38 +1,7 @@
1
1
  import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query';
2
- import { useEffect } from 'react';
3
- import { acceptInviteMutationOptions, getInviteByIdQueryOptions, getInvitesQueryKey, getInvitesQueryOptions, rejectInviteMutationOptions, requestCancelInviteMutationOptions, sendInviteMutationOptions, } from '../lib/react-query/invites.js';
2
+ import { acceptInviteMutationOptions, getInviteByIdQueryOptions, getInvitesQueryOptions, rejectInviteMutationOptions, requestCancelInviteMutationOptions, sendInviteMutationOptions, } from '../lib/react-query/invites.js';
4
3
  import { useClientApi } from './client.js';
5
4
  import { useSingleProject } from './projects.js';
6
- /**
7
- * Set up listeners for received and updated invites.
8
- * It is necessary to use this if you want the invites-related read hooks to update
9
- * based on invites that are received or changed in the background.
10
- *
11
- * @example
12
- * ```tsx
13
- * function App() {
14
- * // Use this somewhere near the root of the application
15
- * useSetUpInvitesListeners()
16
- *
17
- * return <RestOfApp />
18
- * }
19
- * ```
20
- */
21
- export function useSetUpInvitesListeners() {
22
- const queryClient = useQueryClient();
23
- const clientApi = useClientApi();
24
- useEffect(() => {
25
- function invalidateCache() {
26
- queryClient.invalidateQueries({ queryKey: getInvitesQueryKey() });
27
- }
28
- clientApi.invite.addListener('invite-received', invalidateCache);
29
- clientApi.invite.addListener('invite-updated', invalidateCache);
30
- return () => {
31
- clientApi.invite.removeListener('invite-received', invalidateCache);
32
- clientApi.invite.removeListener('invite-updated', invalidateCache);
33
- };
34
- }, [clientApi, queryClient]);
35
- }
36
5
  /**
37
6
  * Get all invites that the device has received.
38
7
  *
@@ -1,6 +1,12 @@
1
- import type { BlobApi, IconApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { RoleChangeEvent } from '@comapeo/core/dist/mapeo-project.js' with { 'resolution-mode': 'import' };
3
- import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { BlobApi, IconApi } from '@comapeo/core' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { RoleChangeEvent } from '@comapeo/core/dist/mapeo-project.js' with {
5
+ 'resolution-mode': 'import'
6
+ };
7
+ import type { MapeoProjectApi } from '@comapeo/ipc' with {
8
+ 'resolution-mode': 'import'
9
+ };
4
10
  import { type SyncState } from '../lib/sync.js';
5
11
  /**
6
12
  * Retrieve the project settings for a project.
@@ -319,10 +325,14 @@ export declare function useCreateProject(): {
319
325
  mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
320
326
  name?: string;
321
327
  configPath?: string;
328
+ projectColor?: string;
329
+ projectDescription?: string;
322
330
  } | undefined, unknown>;
323
331
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
324
332
  name?: string;
325
333
  configPath?: string;
334
+ projectColor?: string;
335
+ projectDescription?: string;
326
336
  } | undefined, unknown>;
327
337
  reset: () => void;
328
338
  status: "error";
@@ -331,10 +341,14 @@ export declare function useCreateProject(): {
331
341
  mutate: import("@tanstack/react-query").UseMutateFunction<string, Error, {
332
342
  name?: string;
333
343
  configPath?: string;
344
+ projectColor?: string;
345
+ projectDescription?: string;
334
346
  } | undefined, unknown>;
335
347
  mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<string, Error, {
336
348
  name?: string;
337
349
  configPath?: string;
350
+ projectColor?: string;
351
+ projectDescription?: string;
338
352
  } | undefined, unknown>;
339
353
  reset: () => void;
340
354
  status: "pending" | "success" | "idle";
@@ -1,7 +1,7 @@
1
- export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
1
+ export { ClientApiProvider } from './contexts/ClientApi.js';
2
2
  export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
3
3
  export { useCreateDocument, useDeleteDocument, useManyDocs, usePresetsSelection, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
4
- export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSetUpInvitesListeners, useSingleInvite, } from './hooks/invites.js';
4
+ export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSingleInvite, } from './hooks/invites.js';
5
5
  export { useMapStyleUrl } from './hooks/maps.js';
6
6
  export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectCategories, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectOwnRoleChangeListener, useProjectSettings, useRemoveServerPeer, useRemoveMember, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
7
7
  export { type SyncState } from './lib/sync.js';
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { ClientApiContext, ClientApiProvider } from './contexts/ClientApi.js';
1
+ export { ClientApiProvider } from './contexts/ClientApi.js';
2
2
  export { useClientApi, useIsArchiveDevice, useOwnDeviceInfo, useSetIsArchiveDevice, useSetOwnDeviceInfo, } from './hooks/client.js';
3
3
  export { useCreateDocument, useDeleteDocument, useManyDocs, usePresetsSelection, useSingleDocByDocId, useSingleDocByVersionId, useUpdateDocument, } from './hooks/documents.js';
4
- export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSetUpInvitesListeners, useSingleInvite, } from './hooks/invites.js';
4
+ export { useAcceptInvite, useManyInvites, useRejectInvite, useRequestCancelInvite, useSendInvite, useSingleInvite, } from './hooks/invites.js';
5
5
  export { useMapStyleUrl } from './hooks/maps.js';
6
6
  export { useAddServerPeer, useAttachmentUrl, useConnectSyncServers, useCreateBlob, useCreateProject, useDataSyncProgress, useDisconnectSyncServers, useDocumentCreatedBy, useIconUrl, useImportProjectCategories, useImportProjectConfig, useLeaveProject, useManyMembers, useManyProjects, useOwnRoleInProject, useProjectOwnRoleChangeListener, useProjectSettings, useRemoveServerPeer, useRemoveMember, useSetAutostopDataSyncTimeout, useSingleMember, useSingleProject, useStartSync, useStopSync, useSyncState, useUpdateProjectSettings, useChangeMemberRole, useExportGeoJSON, useExportZipFile, } from './hooks/projects.js';
@@ -1,2 +1,4 @@
1
- import type { Preset } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { Preset } from '@comapeo/schema' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export declare function getPresetsSelection(presets: Array<Preset>, orderedPresetIds?: Array<string>): Array<Preset>;
@@ -1,5 +1,9 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
2
- import type { DeviceInfo } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { DeviceInfo } from '@comapeo/schema' with {
5
+ 'resolution-mode': 'import'
6
+ };
3
7
  import { type QueryClient } from '@tanstack/react-query';
4
8
  export declare function getClientQueryKey(): readonly ["@comapeo/core-react", "client"];
5
9
  export declare function getDeviceInfoQueryKey(): readonly ["@comapeo/core-react", "client", "device_info"];
@@ -1,7 +1,11 @@
1
- import type { DerivedDocFields } from '@comapeo/core/dist/datatype/index.js' with { 'resolution-mode': 'import' };
2
- import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { DerivedDocFields } from '@comapeo/core/dist/datatype/index.js' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { MapeoProjectApi } from '@comapeo/ipc' with {
5
+ 'resolution-mode': 'import'
6
+ };
3
7
  import { type QueryClient } from '@tanstack/react-query';
4
- import { WriteableDocument, WriteableDocumentType, WriteableValue } from '../types.js';
8
+ import type { WriteableDocument, WriteableDocumentType, WriteableValue } from '../types.js';
5
9
  export declare function getDocumentsQueryKey<D extends WriteableDocumentType>({ projectId, docType, }: {
6
10
  projectId: string;
7
11
  docType: D;
@@ -1,5 +1,9 @@
1
- import type { MemberApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MemberApi } from '@comapeo/core' with {
2
+ 'resolution-mode': 'import'
3
+ };
4
+ import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with {
5
+ 'resolution-mode': 'import'
6
+ };
3
7
  import { type QueryClient } from '@tanstack/react-query';
4
8
  export declare function getInvitesQueryKey(): readonly ["@comapeo/core-react", "invites"];
5
9
  export declare function getInvitesByIdQueryKey({ inviteId }: {
@@ -1,4 +1,6 @@
1
- import type { MapeoClientApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoClientApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export declare function getMapsQueryKey(): readonly ["@comapeo/core-react", "maps"];
3
5
  export declare function getStyleJsonUrlQueryKey({ refreshToken, }: {
4
6
  refreshToken?: string;
@@ -1,5 +1,7 @@
1
1
  import type { BlobApi, MemberApi } from '@comapeo/core' with { 'resolution-mode': 'import' };
2
- import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
2
+ import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc' with {
3
+ 'resolution-mode': 'import'
4
+ };
3
5
  import { type QueryClient, type UnusedSkipTokenOptions } from '@tanstack/react-query';
4
6
  export declare function getProjectsQueryKey(): readonly ["@comapeo/core-react", "projects"];
5
7
  export declare function getProjectByIdQueryKey({ projectId }: {
@@ -150,6 +152,8 @@ export declare function createProjectMutationOptions({ clientApi, queryClient, }
150
152
  mutationFn: (opts: {
151
153
  name?: string;
152
154
  configPath?: string;
155
+ projectColor?: string;
156
+ projectDescription?: string;
153
157
  } | undefined) => Promise<string>;
154
158
  onSuccess: () => void;
155
159
  networkMode: "always";
@@ -162,12 +162,7 @@ export function createProjectMutationOptions({ clientApi, queryClient, }) {
162
162
  mutationFn: async (opts) => {
163
163
  // Have to avoid passing `undefined` explicitly
164
164
  // See https://github.com/digidem/rpc-reflector/issues/21
165
- return opts
166
- ? clientApi.createProject({
167
- configPath: opts.configPath,
168
- name: opts.name,
169
- })
170
- : clientApi.createProject();
165
+ return opts ? clientApi.createProject(opts) : clientApi.createProject();
171
166
  },
172
167
  onSuccess: () => {
173
168
  queryClient.invalidateQueries({
@@ -1,4 +1,6 @@
1
- import type { MapeoProjectApi } from '@comapeo/ipc' with { 'resolution-mode': 'import' };
1
+ import type { MapeoProjectApi } from '@comapeo/ipc' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export type SyncState = Awaited<ReturnType<MapeoProjectApi['$sync']['getState']>>;
3
5
  export declare function getDataSyncCountForDevice(syncStateForDevice: SyncState['remoteDeviceSyncState'][string]): number;
4
6
  export declare class SyncStore {
@@ -1,4 +1,6 @@
1
- import type { MapeoDoc, MapeoValue } from '@comapeo/schema' with { 'resolution-mode': 'import' };
1
+ import type { MapeoDoc, MapeoValue } from '@comapeo/schema' with {
2
+ 'resolution-mode': 'import'
3
+ };
2
4
  export type WriteableDocumentType = Extract<MapeoDoc['schemaName'], 'field' | 'observation' | 'preset' | 'track' | 'remoteDetectionAlert'>;
3
5
  export type WriteableValue<D extends WriteableDocumentType> = Extract<MapeoValue, {
4
6
  schemaName: D;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comapeo/core-react",
3
- "version": "7.2.0",
3
+ "version": "8.0.0",
4
4
  "description": "React wrapper for working with @comapeo/core",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,47 +57,47 @@
57
57
  "types": "tsc"
58
58
  },
59
59
  "peerDependencies": {
60
- "@comapeo/core": "^5.1.1",
61
- "@comapeo/ipc": "^6.0.0",
60
+ "@comapeo/core": "^5.2.1",
61
+ "@comapeo/ipc": "^6.0.2",
62
62
  "@comapeo/schema": "*",
63
63
  "@tanstack/react-query": "^5",
64
64
  "react": "^18 || ^19"
65
65
  },
66
66
  "devDependencies": {
67
- "@comapeo/core": "5.1.1",
68
- "@comapeo/ipc": "6.0.0",
67
+ "@comapeo/core": "5.2.1",
68
+ "@comapeo/ipc": "6.0.2",
69
69
  "@comapeo/schema": "2.2.0",
70
- "@eslint/compat": "1.3.2",
71
- "@eslint/js": "9.35.0",
70
+ "@eslint/compat": "2.0.0",
71
+ "@eslint/js": "9.39.2",
72
72
  "@ianvs/prettier-plugin-sort-imports": "4.7.0",
73
73
  "@mapeo/crypto": "1.0.0-alpha.10",
74
74
  "@mapeo/default-config": "6.0.0",
75
75
  "@mapeo/mock-data": "5.0.0",
76
- "@tanstack/eslint-plugin-query": "5.89.0",
77
- "@tanstack/react-query": "5.89.0",
76
+ "@tanstack/eslint-plugin-query": "5.91.2",
77
+ "@tanstack/react-query": "5.90.12",
78
78
  "@testing-library/dom": "10.4.1",
79
- "@testing-library/react": "16.3.0",
80
- "@types/node": "22.18.6",
81
- "@types/react": "19.1.13",
82
- "@types/react-dom": "19.1.9",
83
- "@vitest/eslint-plugin": "1.3.12",
84
- "eslint": "9.35.0",
85
- "eslint-plugin-react-hooks": "5.2.0",
86
- "eslint-plugin-testing-library": "7.8.0",
79
+ "@testing-library/react": "16.3.1",
80
+ "@types/node": "22.19.3",
81
+ "@types/react": "19.2.7",
82
+ "@types/react-dom": "19.2.3",
83
+ "@vitest/eslint-plugin": "1.5.2",
84
+ "eslint": "9.39.2",
85
+ "eslint-plugin-react-hooks": "7.0.1",
86
+ "eslint-plugin-testing-library": "7.14.0",
87
87
  "fastify": "4.29.1",
88
- "globals": "16.4.0",
89
- "happy-dom": "18.0.1",
88
+ "globals": "16.5.0",
89
+ "happy-dom": "20.0.11",
90
90
  "husky": "9.1.7",
91
- "lint-staged": "15.5.2",
92
- "npm-run-all2": "7.0.2",
93
- "prettier": "3.6.2",
91
+ "lint-staged": "16.2.7",
92
+ "npm-run-all2": "8.0.4",
93
+ "prettier": "3.7.4",
94
94
  "random-access-memory": "6.2.1",
95
- "react": "19.1.1",
96
- "react-dom": "19.1.1",
95
+ "react": "19.2.3",
96
+ "react-dom": "19.2.3",
97
97
  "tsdoc-markdown": "1.4.1",
98
- "tshy": "3.0.2",
99
- "typescript": "5.9.2",
100
- "typescript-eslint": "8.44.0",
101
- "vitest": "3.2.4"
98
+ "tshy": "3.1.0",
99
+ "typescript": "5.9.3",
100
+ "typescript-eslint": "8.49.0",
101
+ "vitest": "4.0.15"
102
102
  }
103
103
  }