Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ function SentShareStatus({ shareId }: { shareId: string }) {

| Type | Type |
| ---------- | ---------- |
| `ClientApiProviderProps` | `PropsWithChildren<{ clientApi: MapeoClientApi }>` |
| `ClientApiProviderProps` | `PropsWithChildren<{ clientApi: ComapeoCoreClientApi }>` |

### MapServerApiOptions

Expand Down
213 changes: 105 additions & 108 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,28 @@
},
"peerDependencies": {
"@comapeo/core": "^7.2.0",
"@comapeo/ipc": "^8.0.0",
"@comapeo/ipc": "^9.0.0",
"@tanstack/react-query": "^5",
"react": "^18 || ^19"
},
"devDependencies": {
"@comapeo/core": "7.3.0",
"@comapeo/ipc": "8.0.0",
"@comapeo/ipc": "9.0.0",
"@eslint/js": "10.0.1",
"@ianvs/prettier-plugin-sort-imports": "4.7.1",
"@mapeo/crypto": "1.1.0",
"@mapeo/default-config": "6.0.0",
"@mapeo/mock-data": "5.0.0",
"@tanstack/eslint-plugin-query": "5.101.0",
"@tanstack/react-query": "5.101.0",
"@tanstack/eslint-plugin-query": "5.101.2",
"@tanstack/react-query": "5.101.2",
"@testing-library/dom": "10.4.1",
"@testing-library/react": "16.3.2",
"@types/jsdom": "28.0.3",
"@types/node": "24.13.2",
"@types/react": "19.2.17",
"@types/react-dom": "19.2.3",
"@vitest/eslint-plugin": "1.6.20",
"eslint": "10.5.0",
"eslint": "10.6.0",
"eslint-plugin-react-hooks": "7.1.1",
"eslint-plugin-testing-library": "7.16.2",
"fastify": "4.29.1",
Expand All @@ -102,15 +102,15 @@
"ky": "2.0.2",
"lint-staged": "17.0.8",
"npm-run-all2": "9.0.2",
"prettier": "3.8.4",
"prettier": "3.9.4",
"random-access-memory": "6.2.1",
"react": "19.2.7",
"react-dom": "19.2.7",
"secret-stream-http": "1.0.1",
"tsdoc-markdown": "1.5.0",
"tshy": "4.1.3",
"typescript": "6.0.3",
"typescript-eslint": "8.61.1",
"typescript-eslint": "8.62.1",
"uint8array-extras": "1.5.0",
"vitest": "4.1.9"
}
Expand Down
8 changes: 4 additions & 4 deletions src/contexts/ClientApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MapeoClientApi } from '@comapeo/ipc'
import type { ComapeoCoreClientApi } from '@comapeo/ipc'
import { useQueryClient } from '@tanstack/react-query'
import {
createContext,
Expand All @@ -11,11 +11,11 @@ import {

import { getInvitesQueryKey } from '../lib/react-query.js'

export const ClientApiContext: Context<MapeoClientApi | null> =
createContext<MapeoClientApi | null>(null)
export const ClientApiContext: Context<ComapeoCoreClientApi | null> =
createContext<ComapeoCoreClientApi | null>(null)

export type ClientApiProviderProps = PropsWithChildren<{
clientApi: MapeoClientApi
clientApi: ComapeoCoreClientApi
}>

/**
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/MapShares.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MapeoClientApi } from '@comapeo/ipc'
import type { ComapeoCoreClientApi } from '@comapeo/ipc'
import type { QueryClient } from '@tanstack/react-query'
import {
createContext,
Expand Down Expand Up @@ -35,7 +35,7 @@ export const SentMapSharesContext: Context<SentMapSharesStore | null> =
createContext<SentMapSharesStore | null>(null)

type MapSharesProviderProps = PropsWithChildren<{
clientApi: MapeoClientApi
clientApi: ComapeoCoreClientApi
mapServerApi: MapServerApi
}>

Expand Down
8 changes: 5 additions & 3 deletions src/hooks/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DeviceInfo } from '@comapeo/core/schema.js'
import type { MapeoClientApi } from '@comapeo/ipc'
import type { ComapeoCoreClientApi } from '@comapeo/ipc'
import {
useMutation,
useQueryClient,
Expand Down Expand Up @@ -43,7 +43,7 @@ import {
* ```
*
*/
export function useClientApi(): MapeoClientApi {
export function useClientApi(): ComapeoCoreClientApi {
const clientApi = useContext(ClientApiContext)

if (!clientApi) {
Expand All @@ -67,7 +67,9 @@ export function useClientApi(): MapeoClientApi {
*/
export function useOwnDeviceInfo(): // NOTE: Needs explicit return type due to TS2742
Pick<
UseSuspenseQueryResult<Awaited<ReturnType<MapeoClientApi['getDeviceInfo']>>>,
UseSuspenseQueryResult<
Awaited<ReturnType<ComapeoCoreClientApi['getDeviceInfo']>>
>,
'data' | 'error' | 'isRefetching'
> {
const clientApi = useClientApi()
Expand Down
16 changes: 9 additions & 7 deletions src/hooks/documents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MapeoProjectApi } from '@comapeo/ipc'
import type { ComapeoProjectClientApi } from '@comapeo/ipc'
import {
useMutation,
useQueryClient,
Expand Down Expand Up @@ -59,7 +59,7 @@ export function useSingleDocByDocId<D extends WriteableDocumentType>({
Pick<
UseSuspenseQueryResult<
// NOTE: Using NonNullable here to get the return type associated with the overload that uses `mustBeFound: true`
NonNullable<Awaited<ReturnType<MapeoProjectApi[D]['getByDocId']>>>
NonNullable<Awaited<ReturnType<ComapeoProjectClientApi[D]['getByDocId']>>>
>,
'data' | 'error' | 'isRefetching'
> {
Expand Down Expand Up @@ -126,7 +126,7 @@ export function useSingleDocByVersionId<D extends WriteableDocumentType>({
}): // NOTE: Needs explicit return type due to TS struggles with inference
Pick<
UseSuspenseQueryResult<
Awaited<ReturnType<MapeoProjectApi[D]['getByVersionId']>>
Awaited<ReturnType<ComapeoProjectClientApi[D]['getByVersionId']>>
>,
'data' | 'error' | 'isRefetching'
> {
Expand Down Expand Up @@ -199,7 +199,9 @@ export function useManyDocs<D extends WriteableDocumentType>({
lang?: string
}): // NOTE: Needs explicit return type due to TS struggles with inference
Pick<
UseSuspenseQueryResult<Awaited<ReturnType<MapeoProjectApi[D]['getMany']>>>,
UseSuspenseQueryResult<
Awaited<ReturnType<ComapeoProjectClientApi[D]['getMany']>>
>,
'data' | 'error' | 'isRefetching'
> {
const { data: projectApi } = useSingleProject({ projectId })
Expand Down Expand Up @@ -243,7 +245,7 @@ export function useCreateDocument<D extends WriteableDocumentType>({
}): // NOTE: Needs explicit return type due to TS struggles with inference
FilteredMutationResult<
UseMutationResult<
Awaited<ReturnType<MapeoProjectApi[D]['create']>>,
Awaited<ReturnType<ComapeoProjectClientApi[D]['create']>>,
Error,
{ value: Omit<WriteableValue<D>, 'schemaName'> }
>
Expand Down Expand Up @@ -293,7 +295,7 @@ export function useUpdateDocument<D extends WriteableDocumentType>({
}): // NOTE: Needs explicit return type due to TS struggles with inference
FilteredMutationResult<
UseMutationResult<
Awaited<ReturnType<MapeoProjectApi[D]['update']>>,
Awaited<ReturnType<ComapeoProjectClientApi[D]['update']>>,
Error,
{ value: Omit<WriteableValue<D>, 'schemaName'>; versionId: string }
>
Expand Down Expand Up @@ -345,7 +347,7 @@ export function useDeleteDocument<D extends WriteableDocumentType>({
}): // NOTE: Needs explicit return type due to TS2742
FilteredMutationResult<
UseMutationResult<
Awaited<ReturnType<MapeoProjectApi[D]['delete']>>,
Awaited<ReturnType<ComapeoProjectClientApi[D]['delete']>>,
Error,
{ docId: string }
>
Expand Down
29 changes: 20 additions & 9 deletions src/hooks/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import type {
IconApi,
MemberApi,
} from '@comapeo/core'
import type { MapeoClientApi, MapeoProjectApi } from '@comapeo/ipc'
import type {
ComapeoCoreClientApi,
ComapeoProjectClientApi,
} from '@comapeo/ipc'
import {
matchQuery,
useMutation,
Expand Down Expand Up @@ -54,7 +57,7 @@ export function useProjectSettings({
}): // NOTE: Needs explicit return type due to TS2742
Pick<
UseSuspenseQueryResult<
Awaited<ReturnType<MapeoProjectApi['$getProjectSettings']>>
Awaited<ReturnType<ComapeoProjectClientApi['$getProjectSettings']>>
>,
'data' | 'error' | 'isRefetching'
> {
Expand Down Expand Up @@ -91,7 +94,7 @@ export function useSingleProject({
projectId: string
}): // NOTE: Needs explicit return type due to TS2742
Pick<
UseSuspenseQueryResult<MapeoProjectApi>,
UseSuspenseQueryResult<ComapeoProjectClientApi>,
'data' | 'error' | 'isRefetching'
> {
const clientApi = useClientApi()
Expand Down Expand Up @@ -127,7 +130,9 @@ Pick<
*/
export function useManyProjects(): // NOTE: Needs explicit return type due to TS2742
Pick<
UseSuspenseQueryResult<Awaited<ReturnType<MapeoClientApi['listProjects']>>>,
UseSuspenseQueryResult<
Awaited<ReturnType<ComapeoCoreClientApi['listProjects']>>
>,
'data' | 'error' | 'isRefetching'
> {
const clientApi = useClientApi()
Expand Down Expand Up @@ -167,7 +172,7 @@ export function useSingleMember({
}): // NOTE: Needs explicit return type due to TS2742
Pick<
UseSuspenseQueryResult<
Awaited<ReturnType<MapeoProjectApi['$member']['getById']>>
Awaited<ReturnType<ComapeoProjectClientApi['$member']['getById']>>
>,
'data' | 'error' | 'isRefetching'
> {
Expand Down Expand Up @@ -371,7 +376,11 @@ const FAKE_BLOB_ID: BlobApi.BlobId = {
* @internal
* Hack to retrieve the media server origin (protocol + host).
*/
function useMediaServerOrigin({ projectApi }: { projectApi: MapeoProjectApi }) {
function useMediaServerOrigin({
projectApi,
}: {
projectApi: ComapeoProjectClientApi
}) {
const { data, error, isRefetching } = useSuspenseQuery({
...baseQueryOptions(),
// HACK: The server doesn't yet expose a method to get its origin, so we use
Expand Down Expand Up @@ -455,7 +464,9 @@ export function useOwnRoleInProject({
projectId: string
}): // NOTE: Needs explicit return type due to TS2742
Pick<
UseSuspenseQueryResult<Awaited<ReturnType<MapeoProjectApi['$getOwnRole']>>>,
UseSuspenseQueryResult<
Awaited<ReturnType<ComapeoProjectClientApi['$getOwnRole']>>
>,
'data' | 'error' | 'isRefetching'
> {
const { data: projectApi } = useSingleProject({ projectId })
Expand Down Expand Up @@ -536,7 +547,7 @@ export function useCreateProject() {
useMutation({
...baseMutationOptions(),
mutationFn: async (
opts?: Parameters<MapeoClientApi['createProject']>[0],
opts?: Parameters<ComapeoCoreClientApi['createProject']>[0],
) => {
// Have to avoid passing `undefined` explicitly
// See https://github.com/digidem/rpc-reflector/issues/21
Expand Down Expand Up @@ -849,7 +860,7 @@ export function useCreateBlob({ projectId }: { projectId: string }) {
)
}

const PROJECT_SYNC_STORE_MAP = new WeakMap<MapeoProjectApi, SyncStore>()
const PROJECT_SYNC_STORE_MAP = new WeakMap<ComapeoProjectClientApi, SyncStore>()

function useSyncStore({ projectId }: { projectId: string }) {
const { data: projectApi } = useSingleProject({ projectId })
Expand Down
6 changes: 3 additions & 3 deletions src/lib/map-shares-stores.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MapShare } from '@comapeo/core'
import type { MapeoClientApi } from '@comapeo/ipc'
import type { ComapeoCoreClientApi } from '@comapeo/ipc'
import { type MapShareState as ServerMapShareState } from '@comapeo/map-server'
import { CUSTOM_MAP_ID } from '@comapeo/map-server/constants.js'
import { errors } from '@comapeo/map-server/errors.js'
Expand Down Expand Up @@ -359,7 +359,7 @@ export function createReceivedMapSharesStore({
mapServerApi,
queryClient,
}: {
clientApi: MapeoClientApi
clientApi: ComapeoCoreClientApi
mapServerApi: MapServerApi
queryClient: QueryClient
}) {
Expand Down Expand Up @@ -487,7 +487,7 @@ export function createSentMapSharesStore({
clientApi,
mapServerApi,
}: {
clientApi: MapeoClientApi
clientApi: ComapeoCoreClientApi
mapServerApi: MapServerApi
}) {
const { subscribe, getSnapshot, update, add, handleError, monitor } =
Expand Down
8 changes: 4 additions & 4 deletions src/lib/sync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MapeoProjectApi } from '@comapeo/ipc'
import type { ComapeoProjectClientApi } from '@comapeo/ipc'

export type SyncState = Awaited<
ReturnType<MapeoProjectApi['$sync']['getState']>
ReturnType<ComapeoProjectClientApi['$sync']['getState']>
>

function getDataSyncCountForDevice(
Expand All @@ -12,7 +12,7 @@ function getDataSyncCountForDevice(
}

export class SyncStore {
#project: MapeoProjectApi
#project: ComapeoProjectClientApi

#listeners = new Set<() => void>()
#isSubscribedInternal = false
Expand All @@ -22,7 +22,7 @@ export class SyncStore {
// Used for calculating sync progress
#perDeviceMaxSyncCount = new Map<string, number>()

constructor(project: MapeoProjectApi) {
constructor(project: ComapeoProjectClientApi) {
this.#project = project
}

Expand Down
14 changes: 8 additions & 6 deletions test/helpers/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createRequire } from 'node:module'
import path from 'node:path'
import { MessageChannel } from 'node:worker_threads'
import { FastifyController, MapeoManager } from '@comapeo/core'
import { closeMapeoClient, createMapeoClient } from '@comapeo/ipc/client.js'
import { createMapeoServer } from '@comapeo/ipc/server.js'
import {
closeComapeoCoreClient,
createComapeoCoreClient,
} from '@comapeo/ipc/client.js'
import { createComapeoCoreServer } from '@comapeo/ipc/server.js'
import { KeyManager } from '@mapeo/crypto'
import Fastify from 'fastify'
import RAM from 'random-access-memory'
Expand Down Expand Up @@ -36,8 +38,8 @@ export function setupCoreIpc() {
fastify,
})

const server = createMapeoServer(manager, port1)
const client = createMapeoClient(port2)
const server = createComapeoCoreServer(manager, port1)
const client = createComapeoCoreClient(port2)

port1.start()
port2.start()
Expand All @@ -53,7 +55,7 @@ export function setupCoreIpc() {
cleanup: async () => {
server.close()
fastifyController.stop()
await closeMapeoClient(client)
await closeComapeoCoreClient(client)
port1.close()
port2.close()
},
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/react.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { type MapeoClientApi } from '@comapeo/ipc'
import type { ComapeoCoreClientApi } from '@comapeo/ipc'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { type PropsWithChildren } from 'react'

import { ComapeoCoreProvider } from '../../src/index.js'
import { createMockClientApi } from './client-api-mock.js'

export function createWrapper({
clientApi = createMockClientApi() as unknown as MapeoClientApi,
clientApi = createMockClientApi() as unknown as ComapeoCoreClientApi,
queryClient = new QueryClient(),
getMapServerBaseUrl = async () => new URL('http://localhost:3000'),
}: {
clientApi?: MapeoClientApi
clientApi?: ComapeoCoreClientApi
queryClient?: QueryClient
getMapServerBaseUrl?: () => Promise<URL>
} = {}) {
Expand Down
Loading
Loading