Skip to content

Commit

Permalink
chore!: update to @comapeo/core@1
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn committed Sep 17, 2024
1 parent 8eb588b commit 744faf8
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 133 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @mapeo/ipc
# @comapeo/ipc

IPC wrappers for [Mapeo Core](https://github.com/digidem/mapeo-core-next). Meant to be used in contexts where there is a communication boundary between the contexts your code runs in e.g. Electron, React Native (with NodeJS Mobile), and NodeJS worker threads. The [channel messaging API](https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API) is an example where this usage applies.
IPC wrappers for [CoMapeo Core](https://github.com/digidem/comapeo-core). Meant to be used in contexts where there is a communication boundary between the contexts your code runs in e.g. Electron, React Native (with NodeJS Mobile), and NodeJS worker threads. The [channel messaging API](https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API) is an example where this usage applies.

## Table of Contents

Expand All @@ -11,17 +11,17 @@ IPC wrappers for [Mapeo Core](https://github.com/digidem/mapeo-core-next). Meant

## Installation

Note that [`@mapeo/core`](https://github.com/digidem/mapeo-core-next) is a peer dependency, so you may have to install it manually depending on your package manager.
Note that [`@comapeo/core`](https://github.com/digidem/comapeo-core) is a peer dependency, so you may have to install it manually depending on your package manager.

```sh
npm install @mapeo/ipc @mapeo/core
npm install @comapeo/ipc @comapeo/core
```

## API

### `createMapeoServer(manager: MapeoManager, messagePort: MessagePortLike): { close: () => void }`

Creates the IPC server instance. `manager` is a `@mapeo/core` `MapeoManager` instance and `messagePort` is an interface that resembles a [`MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort).
Creates the IPC server instance. `manager` is a `@comapeo/core` `MapeoManager` instance and `messagePort` is an interface that resembles a [`MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort).

Returns an object with a `close()` method, which removes relevant event listeners from the `messagePort`. Does not close or destroy the `messagePort`.

Expand All @@ -40,8 +40,8 @@ Closes the IPC client instance. Does not close or destroy the `messagePort` prov
In the server:

```ts
import { MapeoManager } from '@mapeo/core'
import { createMapeoServer } from '@mapeo/ipc'
import { MapeoManager } from '@comapeo/core'
import { createMapeoServer } from '@comapeo/ipc'

// Create Mapeo manager instance
const manager = new MapeoManager({...})
Expand All @@ -59,7 +59,7 @@ server.close()
In the client:

```ts
import { createMapeoClient, closeMapeoClient } from '@mapeo/ipc'
import { createMapeoClient, closeMapeoClient } from '@comapeo/ipc'

// Create the client instance
// `messagePort` can vary based on context (e.g. a port from a MessageChannel, a NodeJS Mobile bridge channel, etc.)
Expand Down
223 changes: 112 additions & 111 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"rpc-reflector": "^1.3.11"
},
"peerDependencies": {
"@mapeo/core": "9.0.0-alpha.25"
"@comapeo/core": "1.0.0"
},
"devDependencies": {
"@digidem/types": "^2.1.0",
Expand Down
12 changes: 6 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from './lib/sub-channel.js'

/**
* @typedef {import('rpc-reflector/client.js').ClientApi<import('@mapeo/core/dist/mapeo-project.js').MapeoProject>} MapeoProjectApi
* @typedef {import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>} MapeoProjectApi
*/

/**
* @typedef {import('rpc-reflector/client.js').ClientApi<
* Omit<
* import('@mapeo/core').MapeoManager,
* import('@comapeo/core').MapeoManager,
* 'getProject'
* > & {
* getProject: (projectPublicId: string) => Promise<MapeoProjectApi>
Expand All @@ -31,13 +31,13 @@ const CLOSE = Symbol('close')
* @returns {MapeoClientApi}
*/
export function createMapeoClient(messagePort, opts = {}) {
/** @type {Map<string, Promise<import('rpc-reflector/client.js').ClientApi<import('@mapeo/core/dist/mapeo-project.js').MapeoProject>>>} */
/** @type {Map<string, Promise<import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>>>} */
const projectClientPromises = new Map()

const managerChannel = new SubChannel(messagePort, MANAGER_CHANNEL_ID)
const mapeoRpcChannel = new SubChannel(messagePort, MAPEO_RPC_ID)

/** @type {import('rpc-reflector').ClientApi<import('@mapeo/core').MapeoManager>} */
/** @type {import('rpc-reflector').ClientApi<import('@comapeo/core').MapeoManager>} */
const managerClient = createClient(managerChannel, opts)
/** @type {import('rpc-reflector').ClientApi<import('./server.js').MapeoRpcApi>} */
const mapeoRpcClient = createClient(mapeoRpcChannel, opts)
Expand Down Expand Up @@ -84,7 +84,7 @@ export function createMapeoClient(messagePort, opts = {}) {

if (existingClientPromise) return existingClientPromise

/** @type {import('p-defer').DeferredPromise<import('rpc-reflector/client.js').ClientApi<import('@mapeo/core/dist/mapeo-project.js').MapeoProject>>}*/
/** @type {import('p-defer').DeferredPromise<import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>>}*/
const deferred = pDefer()

projectClientPromises.set(projectPublicId, deferred.promise)
Expand All @@ -98,7 +98,7 @@ export function createMapeoClient(messagePort, opts = {}) {

const projectChannel = new SubChannel(messagePort, projectPublicId)

/** @type {import('rpc-reflector').ClientApi<import('@mapeo/core/dist/mapeo-project.js').MapeoProject>} */
/** @type {import('rpc-reflector').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>} */
const projectClient = createClient(projectChannel, opts)
projectChannel.start()

Expand Down
4 changes: 2 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { extractMessageEventData } from './lib/utils.js'

/**
* @param {import('@mapeo/core').MapeoManager} manager
* @param {import('@comapeo/core').MapeoManager} manager
* @param {import('./lib/sub-channel.js').MessagePortLike} messagePort
*/
export function createMapeoServer(manager, messagePort) {
Expand Down Expand Up @@ -96,7 +96,7 @@ export class MapeoRpcApi {
#manager

/**
* @param {import('@mapeo/core').MapeoManager} manager
* @param {import('@comapeo/core').MapeoManager} manager
*/
constructor(manager) {
this.#manager = manager
Expand Down
Loading

0 comments on commit 744faf8

Please sign in to comment.