From a7dbaed3bd4fe89d1651fe8cbc92ac3763c54fd4 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Thu, 2 Jul 2026 06:48:45 +0200 Subject: [PATCH 1/2] chore: update usage docs of ComapeoCoreProvider --- README.md | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 384e39c..35af06f 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,47 @@ npm install react @tanstack/react-query@5 @comapeo/core-react @comapeo/core @com Wrap your application with `ComapeoCoreProvider` and a React Query `QueryClientProvider`. You will need to be running an instance of [`@comapeo/map-server`](https://github.com/digidem/comapeo-map-server) and provide a `getMapServerBaseUrl` function that returns a Promise resolving to the base URL of your map server: -```tsx +In the server: + +```ts import { ComapeoCoreProvider } from '@comapeo/core-react' +import { + createComapeoCoreServer, + createComapeoServicesServer, +} from '@comapeo/ipc/server.js' import { createServer } from '@comapeo/map-server' + +const mapServer = createServer() +const listenPromise = mapServer.listen() + +const servicesServer = createComapeoServicesServer( + { + mapServer: { + getBaseUrl: async () => { + const { localPort } = await listenPromise() + return `http://localhost:${localPort}` + }, + }, + }, + port, +) +``` + +In the client: + +```tsx +import { + createComapeoCoreClient, + createComapeoServicesClient, +} from '@comapeo/ipc/client.js' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' const queryClient = new QueryClient() -const server = createServer() -const listenPromise = server.listen() +const servicesClient = createComapeoServicesClient(port) const getMapServerBaseUrl = async () => { - const { localPort } = await listenPromise - return new URL(`http://localhost:${localPort}/`) + return new URL(await servicesClient.mapServer.getBaseUrl()) } function App() { From b44176eb9cd41837c0fc10039fed50be1ca5f2ad Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Thu, 2 Jul 2026 17:45:57 +0200 Subject: [PATCH 2/2] update getBaseUrl prop type to allow returning strings --- README.md | 6 +----- docs/API.md | 2 +- src/contexts/ComapeoCore.ts | 2 +- src/contexts/MapServer.ts | 2 +- test/helpers/react.tsx | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 35af06f..f236a35 100644 --- a/README.md +++ b/README.md @@ -55,17 +55,13 @@ const queryClient = new QueryClient() const servicesClient = createComapeoServicesClient(port) -const getMapServerBaseUrl = async () => { - return new URL(await servicesClient.mapServer.getBaseUrl()) -} - function App() { return ( diff --git a/docs/API.md b/docs/API.md index eafd3e1..3094c74 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1462,7 +1462,7 @@ function SentShareStatus({ shareId }: { shareId: string }) { | Type | Type | | ---------- | ---------- | -| `MapServerApiOptions` | `{ getBaseUrl(): Promise /** * We assume the passed fetch implementation will only accept a `string` as * input, not a `URL` or `Request`, because right now the expo/fetch * implementation will only accept a `string`. Adding this restriction will * catch potential issues if we try to pass a URL in our code. Can be relaxed * when https://github.com/expo/expo/issues/43193 is fixed upstream. */ fetch?(input: string, options?: RequestInit): Promise }` | +| `MapServerApiOptions` | `{ getBaseUrl(): Promise /** * We assume the passed fetch implementation will only accept a `string` as * input, not a `URL` or `Request`, because right now the expo/fetch * implementation will only accept a `string`. Adding this restriction will * catch potential issues if we try to pass a URL in our code. Can be relaxed * when https://github.com/expo/expo/issues/43193 is fixed upstream. */ fetch?(input: string, options?: RequestInit): Promise }` | ### MapServerApi diff --git a/src/contexts/ComapeoCore.ts b/src/contexts/ComapeoCore.ts index ecfaf18..493436b 100644 --- a/src/contexts/ComapeoCore.ts +++ b/src/contexts/ComapeoCore.ts @@ -5,7 +5,7 @@ import { MapServerProvider, type MapServerProviderProps } from './MapServer.js' type ComapeoCoreProviderProps = ClientApiProviderProps & Omit & { - getMapServerBaseUrl(): Promise + getMapServerBaseUrl(): Promise } export function ComapeoCoreProvider({ diff --git a/src/contexts/MapServer.ts b/src/contexts/MapServer.ts index 98c4015..50b3dc5 100644 --- a/src/contexts/MapServer.ts +++ b/src/contexts/MapServer.ts @@ -22,7 +22,7 @@ import { } from './MapShares.js' export type MapServerApiOptions = { - getBaseUrl(): Promise + getBaseUrl(): Promise /** * We assume the passed fetch implementation will only accept a `string` as * input, not a `URL` or `Request`, because right now the expo/fetch diff --git a/test/helpers/react.tsx b/test/helpers/react.tsx index 3ca77aa..4f95a83 100644 --- a/test/helpers/react.tsx +++ b/test/helpers/react.tsx @@ -12,7 +12,7 @@ export function createWrapper({ }: { clientApi?: ComapeoCoreClientApi queryClient?: QueryClient - getMapServerBaseUrl?: () => Promise + getMapServerBaseUrl?: () => Promise } = {}) { return ({ children }: PropsWithChildren) => { return (