@comapeo/ipc 0.16.0 → 1.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.
- package/README.md +8 -8
- package/dist/client.d.ts +17 -17
- package/dist/client.js +6 -6
- package/dist/server.d.ts +4 -4
- package/dist/server.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @comapeo/ipc
|
|
2
2
|
|
|
3
|
-
IPC wrappers for [
|
|
3
|
+
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.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
@@ -11,17 +11,17 @@ IPC wrappers for [Mapeo Core](https://github.com/digidem/mapeo-core-next). Meant
|
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
|
-
Note that [`@
|
|
14
|
+
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.
|
|
15
15
|
|
|
16
16
|
```sh
|
|
17
|
-
npm install @
|
|
17
|
+
npm install @comapeo/ipc @comapeo/core
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## API
|
|
21
21
|
|
|
22
22
|
### `createMapeoServer(manager: MapeoManager, messagePort: MessagePortLike): { close: () => void }`
|
|
23
23
|
|
|
24
|
-
Creates the IPC server instance. `manager` is a `@
|
|
24
|
+
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).
|
|
25
25
|
|
|
26
26
|
Returns an object with a `close()` method, which removes relevant event listeners from the `messagePort`. Does not close or destroy the `messagePort`.
|
|
27
27
|
|
|
@@ -40,8 +40,8 @@ Closes the IPC client instance. Does not close or destroy the `messagePort` prov
|
|
|
40
40
|
In the server:
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
|
-
import { MapeoManager } from '@
|
|
44
|
-
import { createMapeoServer } from '@
|
|
43
|
+
import { MapeoManager } from '@comapeo/core'
|
|
44
|
+
import { createMapeoServer } from '@comapeo/ipc'
|
|
45
45
|
|
|
46
46
|
// Create Mapeo manager instance
|
|
47
47
|
const manager = new MapeoManager({...})
|
|
@@ -59,7 +59,7 @@ server.close()
|
|
|
59
59
|
In the client:
|
|
60
60
|
|
|
61
61
|
```ts
|
|
62
|
-
import { createMapeoClient, closeMapeoClient } from '@
|
|
62
|
+
import { createMapeoClient, closeMapeoClient } from '@comapeo/ipc'
|
|
63
63
|
|
|
64
64
|
// Create the client instance
|
|
65
65
|
// `messagePort` can vary based on context (e.g. a port from a MessageChannel, a NodeJS Mobile bridge channel, etc.)
|
package/dist/client.d.ts
CHANGED
|
@@ -13,17 +13,17 @@ export function createMapeoClient(messagePort: import('./lib/sub-channel.js').Me
|
|
|
13
13
|
* @returns {Promise<void>}
|
|
14
14
|
*/
|
|
15
15
|
export function closeMapeoClient(client: MapeoClientApi): Promise<void>;
|
|
16
|
-
export type MapeoProjectApi = import('rpc-reflector/client.js').ClientApi<import('@
|
|
16
|
+
export type MapeoProjectApi = import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>;
|
|
17
17
|
export type MapeoClientApi = {
|
|
18
|
-
addListener: <U extends "local-peers">(event: U, listener: import("@
|
|
19
|
-
on: <U_1 extends "local-peers">(event: U_1, listener: import("@
|
|
20
|
-
once: <U_2 extends "local-peers">(event: U_2, listener: import("@
|
|
21
|
-
removeListener: <U_3 extends "local-peers">(event: U_3, listener: import("@
|
|
22
|
-
off: <U_4 extends "local-peers">(event: U_4, listener: import("@
|
|
23
|
-
removeAllListeners: (event?: "local-peers" | undefined) => import("@
|
|
24
|
-
listeners: <U_5 extends "local-peers">(type: U_5) => import("@
|
|
25
|
-
rawListeners: <U_6 extends "local-peers">(type: U_6) => import("@
|
|
26
|
-
emit: <U_7 extends "local-peers">(event: U_7, ...args: Parameters<import("@
|
|
18
|
+
addListener: <U extends "local-peers">(event: U, listener: import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U]) => import("@comapeo/core").MapeoManager;
|
|
19
|
+
on: <U_1 extends "local-peers">(event: U_1, listener: import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_1]) => import("@comapeo/core").MapeoManager;
|
|
20
|
+
once: <U_2 extends "local-peers">(event: U_2, listener: import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_2]) => import("@comapeo/core").MapeoManager;
|
|
21
|
+
removeListener: <U_3 extends "local-peers">(event: U_3, listener: import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_3]) => import("@comapeo/core").MapeoManager;
|
|
22
|
+
off: <U_4 extends "local-peers">(event: U_4, listener: import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_4]) => import("@comapeo/core").MapeoManager;
|
|
23
|
+
removeAllListeners: (event?: "local-peers" | undefined) => import("@comapeo/core").MapeoManager;
|
|
24
|
+
listeners: <U_5 extends "local-peers">(type: U_5) => import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_5][];
|
|
25
|
+
rawListeners: <U_6 extends "local-peers">(type: U_6) => import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_6][];
|
|
26
|
+
emit: <U_7 extends "local-peers">(event: U_7, ...args: Parameters<import("@comapeo/core/dist/mapeo-manager.js").MapeoManagerEvents[U_7]>) => boolean;
|
|
27
27
|
listenerCount: (type: "local-peers") => number;
|
|
28
28
|
eventNames: <U_8 extends "local-peers">() => U_8[];
|
|
29
29
|
readonly deviceId: () => Promise<string>;
|
|
@@ -52,23 +52,23 @@ export type MapeoClientApi = {
|
|
|
52
52
|
createdAt?: string | undefined;
|
|
53
53
|
updatedAt?: string | undefined;
|
|
54
54
|
})[]>;
|
|
55
|
-
addProject: ({ projectKey, encryptionKeys, projectName }: Pick<import("@
|
|
55
|
+
addProject: ({ projectKey, encryptionKeys, projectName }: Pick<import("@comapeo/core/dist/generated/rpc.js").ProjectJoinDetails, "projectKey" | "encryptionKeys"> & {
|
|
56
56
|
projectName: string;
|
|
57
57
|
}, { waitForSync }?: {
|
|
58
58
|
waitForSync?: boolean | undefined;
|
|
59
59
|
} | undefined) => Promise<string>;
|
|
60
|
-
setDeviceInfo: <T extends import("type-fest").IsEqual<import("@
|
|
60
|
+
setDeviceInfo: <T extends import("type-fest").IsEqual<import("@comapeo/core/dist/schema/client.js").DeviceInfoParam & {
|
|
61
61
|
deviceType?: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "UNRECOGNIZED" | undefined;
|
|
62
|
-
}, T> extends true ? import("@
|
|
62
|
+
}, T> extends true ? import("@comapeo/core/dist/schema/client.js").DeviceInfoParam & {
|
|
63
63
|
deviceType?: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "UNRECOGNIZED" | undefined;
|
|
64
|
-
} : import("type-fest/source/exact.js").ExactObject<import("@
|
|
64
|
+
} : import("type-fest/source/exact.js").ExactObject<import("@comapeo/core/dist/schema/client.js").DeviceInfoParam & {
|
|
65
65
|
deviceType?: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "UNRECOGNIZED" | undefined;
|
|
66
66
|
}, T>>(deviceInfo: T) => Promise<void>;
|
|
67
67
|
getDeviceInfo: () => Promise<{
|
|
68
68
|
deviceId: string;
|
|
69
69
|
deviceType: "device_type_unspecified" | "mobile" | "tablet" | "desktop" | "selfHostedServer" | "UNRECOGNIZED";
|
|
70
|
-
} & Partial<import("@
|
|
71
|
-
readonly invite: import("rpc-reflector/lib/types.js").ClientApi<import("@
|
|
70
|
+
} & Partial<import("@comapeo/core/dist/schema/client.js").DeviceInfoParam>>;
|
|
71
|
+
readonly invite: import("rpc-reflector/lib/types.js").ClientApi<import("@comapeo/core/dist/invite-api.js").InviteApi> & (() => Promise<import("@comapeo/core/dist/invite-api.js").InviteApi>);
|
|
72
72
|
startLocalPeerDiscoveryServer: () => Promise<{
|
|
73
73
|
name: string;
|
|
74
74
|
port: number;
|
|
@@ -82,7 +82,7 @@ export type MapeoClientApi = {
|
|
|
82
82
|
port: number;
|
|
83
83
|
name: string;
|
|
84
84
|
}) => Promise<void>;
|
|
85
|
-
listLocalPeers: () => Promise<import("@
|
|
85
|
+
listLocalPeers: () => Promise<import("@comapeo/core/dist/mapeo-manager.js").PublicPeerInfo[]>;
|
|
86
86
|
onBackgrounded: () => Promise<void>;
|
|
87
87
|
onForegrounded: () => Promise<void>;
|
|
88
88
|
leaveProject: (projectPublicId: string) => Promise<void>;
|
package/dist/client.js
CHANGED
|
@@ -2,12 +2,12 @@ import { createClient } from 'rpc-reflector';
|
|
|
2
2
|
import pDefer from 'p-defer';
|
|
3
3
|
import { MANAGER_CHANNEL_ID, MAPEO_RPC_ID, SubChannel, } from './lib/sub-channel.js';
|
|
4
4
|
/**
|
|
5
|
-
* @typedef {import('rpc-reflector/client.js').ClientApi<import('@
|
|
5
|
+
* @typedef {import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>} MapeoProjectApi
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {import('rpc-reflector/client.js').ClientApi<
|
|
9
9
|
* Omit<
|
|
10
|
-
* import('@
|
|
10
|
+
* import('@comapeo/core').MapeoManager,
|
|
11
11
|
* 'getProject'
|
|
12
12
|
* > & {
|
|
13
13
|
* getProject: (projectPublicId: string) => Promise<MapeoProjectApi>
|
|
@@ -22,11 +22,11 @@ const CLOSE = Symbol('close');
|
|
|
22
22
|
* @returns {MapeoClientApi}
|
|
23
23
|
*/
|
|
24
24
|
export function createMapeoClient(messagePort, opts = {}) {
|
|
25
|
-
/** @type {Map<string, Promise<import('rpc-reflector/client.js').ClientApi<import('@
|
|
25
|
+
/** @type {Map<string, Promise<import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>>>} */
|
|
26
26
|
const projectClientPromises = new Map();
|
|
27
27
|
const managerChannel = new SubChannel(messagePort, MANAGER_CHANNEL_ID);
|
|
28
28
|
const mapeoRpcChannel = new SubChannel(messagePort, MAPEO_RPC_ID);
|
|
29
|
-
/** @type {import('rpc-reflector').ClientApi<import('@
|
|
29
|
+
/** @type {import('rpc-reflector').ClientApi<import('@comapeo/core').MapeoManager>} */
|
|
30
30
|
const managerClient = createClient(managerChannel, opts);
|
|
31
31
|
/** @type {import('rpc-reflector').ClientApi<import('./server.js').MapeoRpcApi>} */
|
|
32
32
|
const mapeoRpcClient = createClient(mapeoRpcChannel, opts);
|
|
@@ -62,7 +62,7 @@ export function createMapeoClient(messagePort, opts = {}) {
|
|
|
62
62
|
const existingClientPromise = projectClientPromises.get(projectPublicId);
|
|
63
63
|
if (existingClientPromise)
|
|
64
64
|
return existingClientPromise;
|
|
65
|
-
/** @type {import('p-defer').DeferredPromise<import('rpc-reflector/client.js').ClientApi<import('@
|
|
65
|
+
/** @type {import('p-defer').DeferredPromise<import('rpc-reflector/client.js').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>>}*/
|
|
66
66
|
const deferred = pDefer();
|
|
67
67
|
projectClientPromises.set(projectPublicId, deferred.promise);
|
|
68
68
|
try {
|
|
@@ -73,7 +73,7 @@ export function createMapeoClient(messagePort, opts = {}) {
|
|
|
73
73
|
throw err;
|
|
74
74
|
}
|
|
75
75
|
const projectChannel = new SubChannel(messagePort, projectPublicId);
|
|
76
|
-
/** @type {import('rpc-reflector').ClientApi<import('@
|
|
76
|
+
/** @type {import('rpc-reflector').ClientApi<import('@comapeo/core/dist/mapeo-project.js').MapeoProject>} */
|
|
77
77
|
const projectClient = createClient(projectChannel, opts);
|
|
78
78
|
projectChannel.start();
|
|
79
79
|
deferred.resolve(projectClient);
|
package/dist/server.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {import('@
|
|
2
|
+
* @param {import('@comapeo/core').MapeoManager} manager
|
|
3
3
|
* @param {import('./lib/sub-channel.js').MessagePortLike} messagePort
|
|
4
4
|
*/
|
|
5
|
-
export function createMapeoServer(manager: import('@
|
|
5
|
+
export function createMapeoServer(manager: import('@comapeo/core').MapeoManager, messagePort: import('./lib/sub-channel.js').MessagePortLike): {
|
|
6
6
|
close(): void;
|
|
7
7
|
};
|
|
8
8
|
export class MapeoRpcApi {
|
|
9
9
|
/**
|
|
10
|
-
* @param {import('@
|
|
10
|
+
* @param {import('@comapeo/core').MapeoManager} manager
|
|
11
11
|
*/
|
|
12
|
-
constructor(manager: import('@
|
|
12
|
+
constructor(manager: import('@comapeo/core').MapeoManager);
|
|
13
13
|
/**
|
|
14
14
|
* @param {string} projectId
|
|
15
15
|
* @returns {Promise<boolean>}
|
package/dist/server.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createServer } from 'rpc-reflector';
|
|
|
2
2
|
import { MANAGER_CHANNEL_ID, MAPEO_RPC_ID, SubChannel, } from './lib/sub-channel.js';
|
|
3
3
|
import { extractMessageEventData } from './lib/utils.js';
|
|
4
4
|
/**
|
|
5
|
-
* @param {import('@
|
|
5
|
+
* @param {import('@comapeo/core').MapeoManager} manager
|
|
6
6
|
* @param {import('./lib/sub-channel.js').MessagePortLike} messagePort
|
|
7
7
|
*/
|
|
8
8
|
export function createMapeoServer(manager, messagePort) {
|
|
@@ -70,7 +70,7 @@ export function createMapeoServer(manager, messagePort) {
|
|
|
70
70
|
export class MapeoRpcApi {
|
|
71
71
|
#manager;
|
|
72
72
|
/**
|
|
73
|
-
* @param {import('@
|
|
73
|
+
* @param {import('@comapeo/core').MapeoManager} manager
|
|
74
74
|
*/
|
|
75
75
|
constructor(manager) {
|
|
76
76
|
this.#manager = manager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comapeo/ipc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "IPC wrappers for Mapeo Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"rpc-reflector": "^1.3.11"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@
|
|
48
|
+
"@comapeo/core": "1.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@digidem/types": "^2.1.0",
|