starpc 0.1.6 → 0.1.7
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 +2 -2
- package/dist/srpc/conn.d.ts +6 -2
- package/dist/srpc/conn.js +7 -5
- package/dist/srpc/websocket.js +4 -1
- package/package.json +2 -1
- package/srpc/conn.ts +16 -7
- package/srpc/websocket.ts +4 -1
- package/patches/@libp2p+mplex+2.0.0.patch +0 -23
package/README.md
CHANGED
|
@@ -9,11 +9,11 @@ supported by any of the major RPC libraries.
|
|
|
9
9
|
|
|
10
10
|
The [rpcproto](./srpc/rpcproto.proto) file describes the protocol.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Can use any Stream multiplexer: defaults to [libp2p-mplex] over a WebSocket.
|
|
13
13
|
|
|
14
14
|
[libp2p-mplex]: https://github.com/libp2p/js-libp2p-mplex
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Note: the server has not yet been implemented in TypeScript.
|
|
17
17
|
|
|
18
18
|
# Usage
|
|
19
19
|
|
package/dist/srpc/conn.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { Stream } from '@libp2p/interface-connection';
|
|
2
|
+
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer';
|
|
2
3
|
import type { Duplex } from 'it-stream-types';
|
|
3
4
|
import type { Stream as SRPCStream } from './stream';
|
|
4
5
|
import { Client } from './client';
|
|
6
|
+
export interface ConnParams {
|
|
7
|
+
muxerFactory?: StreamMuxerFactory;
|
|
8
|
+
}
|
|
5
9
|
export declare class Conn implements Duplex<Uint8Array> {
|
|
6
10
|
private muxer;
|
|
7
|
-
constructor();
|
|
11
|
+
constructor(connParams?: ConnParams);
|
|
8
12
|
get sink(): import("it-stream-types").Sink<Uint8Array, Promise<void>>;
|
|
9
|
-
get source():
|
|
13
|
+
get source(): import("it-stream-types").Source<Uint8Array>;
|
|
10
14
|
get streams(): Stream[];
|
|
11
15
|
buildClient(): Client;
|
|
12
16
|
openStream(): Promise<SRPCStream>;
|
package/dist/srpc/conn.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MplexStreamMuxer } from '@libp2p/mplex';
|
|
1
|
+
import { Mplex } from '@libp2p/mplex';
|
|
3
2
|
import { Client } from './client';
|
|
4
3
|
// Conn implements a generic connection with a two-way stream.
|
|
5
4
|
export class Conn {
|
|
6
5
|
// muxer is the mplex stream muxer.
|
|
7
6
|
muxer;
|
|
8
|
-
constructor() {
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
constructor(connParams) {
|
|
8
|
+
let muxerFactory = connParams?.muxerFactory;
|
|
9
|
+
if (!muxerFactory) {
|
|
10
|
+
muxerFactory = new Mplex();
|
|
11
|
+
}
|
|
12
|
+
this.muxer = muxerFactory.createStreamMuxer({
|
|
11
13
|
onIncomingStream: this.handleIncomingStream.bind(this),
|
|
12
14
|
});
|
|
13
15
|
}
|
package/dist/srpc/websocket.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Conn } from './conn.js';
|
|
2
2
|
import { duplex } from 'it-ws';
|
|
3
3
|
import { pipe } from 'it-pipe';
|
|
4
|
+
import { Mplex } from '@libp2p/mplex';
|
|
4
5
|
// WebSocketConn implements a connection with a WebSocket.
|
|
5
6
|
export class WebSocketConn extends Conn {
|
|
6
7
|
// socket is the web socket
|
|
7
8
|
socket;
|
|
8
9
|
constructor(socket) {
|
|
9
|
-
super(
|
|
10
|
+
super({
|
|
11
|
+
muxerFactory: new Mplex(),
|
|
12
|
+
});
|
|
10
13
|
this.socket = socket;
|
|
11
14
|
const socketDuplex = duplex(socket);
|
|
12
15
|
pipe(this.source, socketDuplex, this.sink);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"gen": "make genproto",
|
|
43
43
|
"test": "make test && npm run check",
|
|
44
44
|
"test:integration": "make integration",
|
|
45
|
+
"integration": "npm run test:integration",
|
|
45
46
|
"lint": "npm run lint:go && npm run lint:js",
|
|
46
47
|
"lint:go": "make lint",
|
|
47
48
|
"lint:js": "eslint -c .eslintrc.js --ext .ts ./{srpc,echo}/**/*.ts",
|
package/srpc/conn.ts
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { Stream } from '@libp2p/interface-connection'
|
|
2
|
+
import type { StreamMuxer, StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
2
3
|
import type { Duplex } from 'it-stream-types'
|
|
3
|
-
import {
|
|
4
|
-
import { MplexStreamMuxer } from '@libp2p/mplex'
|
|
4
|
+
import { Mplex } from '@libp2p/mplex'
|
|
5
5
|
import type { Stream as SRPCStream } from './stream'
|
|
6
6
|
import { Client } from './client'
|
|
7
7
|
|
|
8
|
+
// ConnParams are parameters that can be passed to the Conn constructor.
|
|
9
|
+
export interface ConnParams {
|
|
10
|
+
// muxerFactory overrides using the default factory (@libp2p/mplex).
|
|
11
|
+
muxerFactory?: StreamMuxerFactory
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
// Conn implements a generic connection with a two-way stream.
|
|
9
15
|
export class Conn implements Duplex<Uint8Array> {
|
|
10
16
|
// muxer is the mplex stream muxer.
|
|
11
|
-
private muxer:
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
private muxer: StreamMuxer
|
|
18
|
+
|
|
19
|
+
constructor(connParams?: ConnParams) {
|
|
20
|
+
let muxerFactory = connParams?.muxerFactory
|
|
21
|
+
if (!muxerFactory) {
|
|
22
|
+
muxerFactory = new Mplex()
|
|
23
|
+
}
|
|
24
|
+
this.muxer = muxerFactory.createStreamMuxer({
|
|
16
25
|
onIncomingStream: this.handleIncomingStream.bind(this),
|
|
17
26
|
})
|
|
18
27
|
}
|
package/srpc/websocket.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Conn } from './conn.js'
|
|
2
2
|
import { duplex } from 'it-ws'
|
|
3
3
|
import { pipe } from 'it-pipe'
|
|
4
|
+
import { Mplex } from '@libp2p/mplex'
|
|
4
5
|
import type WebSocket from 'isomorphic-ws'
|
|
5
6
|
|
|
6
7
|
// WebSocketConn implements a connection with a WebSocket.
|
|
@@ -9,7 +10,9 @@ export class WebSocketConn extends Conn {
|
|
|
9
10
|
private socket: WebSocket
|
|
10
11
|
|
|
11
12
|
constructor(socket: WebSocket) {
|
|
12
|
-
super(
|
|
13
|
+
super({
|
|
14
|
+
muxerFactory: new Mplex(),
|
|
15
|
+
})
|
|
13
16
|
this.socket = socket
|
|
14
17
|
const socketDuplex = duplex(socket)
|
|
15
18
|
pipe(this.source, socketDuplex, this.sink)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
diff --git a/node_modules/@libp2p/mplex/dist/src/index.d.ts b/node_modules/@libp2p/mplex/dist/src/index.d.ts
|
|
2
|
-
index 14c5f6e..32d0ee0 100644
|
|
3
|
-
--- a/node_modules/@libp2p/mplex/dist/src/index.d.ts
|
|
4
|
-
+++ b/node_modules/@libp2p/mplex/dist/src/index.d.ts
|
|
5
|
-
@@ -1,6 +1,7 @@
|
|
6
|
-
import { Components, Initializable } from '@libp2p/components';
|
|
7
|
-
import type { StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
|
|
8
|
-
import { MplexStreamMuxer } from './mplex.js';
|
|
9
|
-
+export { MplexStreamMuxer } from './mplex.js';
|
|
10
|
-
export interface MplexInit {
|
|
11
|
-
/**
|
|
12
|
-
* The maximum size of message that can be sent in one go in bytes.
|
|
13
|
-
diff --git a/node_modules/@libp2p/mplex/dist/src/index.js b/node_modules/@libp2p/mplex/dist/src/index.js
|
|
14
|
-
index 4d692df..7bf592c 100644
|
|
15
|
-
--- a/node_modules/@libp2p/mplex/dist/src/index.js
|
|
16
|
-
+++ b/node_modules/@libp2p/mplex/dist/src/index.js
|
|
17
|
-
@@ -1,5 +1,6 @@
|
|
18
|
-
import { Components } from '@libp2p/components';
|
|
19
|
-
import { MplexStreamMuxer } from './mplex.js';
|
|
20
|
-
+export { MplexStreamMuxer } from './mplex.js';
|
|
21
|
-
export class Mplex {
|
|
22
|
-
constructor(init = {}) {
|
|
23
|
-
this.protocol = '/mplex/6.7.0';
|