starpc 0.22.3 → 0.22.5
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/dist/rpcstream/rpcstream.d.ts +4 -4
- package/dist/rpcstream/rpcstream.js +21 -22
- package/dist/srpc/common-rpc.js +1 -1
- package/go.mod +6 -6
- package/go.sum +8 -8
- package/package.json +5 -9
- package/srpc/common-rpc.ts +1 -1
- package/srpc/invoker.go +15 -0
|
@@ -7,13 +7,13 @@ export declare function openRpcStream(componentId: string, caller: RpcStreamCall
|
|
|
7
7
|
export declare function buildRpcStreamOpenStream(componentId: string, caller: RpcStreamCaller): OpenStreamFunc;
|
|
8
8
|
export type RpcStreamHandler = (stream: Stream) => void;
|
|
9
9
|
export type RpcStreamGetter = (componentId: string) => Promise<RpcStreamHandler | null>;
|
|
10
|
-
export declare function handleRpcStream(
|
|
10
|
+
export declare function handleRpcStream(packetRx: AsyncIterator<RpcStreamPacket>, getter: RpcStreamGetter): AsyncIterable<RpcStreamPacket>;
|
|
11
11
|
export declare class RpcStream implements Stream {
|
|
12
12
|
readonly source: AsyncGenerator<Uint8Array>;
|
|
13
13
|
readonly sink: Sink<Source<Uint8Array>, Promise<void>>;
|
|
14
|
-
private readonly
|
|
15
|
-
private readonly
|
|
16
|
-
constructor(
|
|
14
|
+
private readonly _packetRx;
|
|
15
|
+
private readonly _packetTx;
|
|
16
|
+
constructor(packetTx: Pushable<RpcStreamPacket>, packetRx: AsyncIterator<RpcStreamPacket>);
|
|
17
17
|
private _createSink;
|
|
18
18
|
private _createSource;
|
|
19
19
|
}
|
|
@@ -2,17 +2,17 @@ import { pushable } from 'it-pushable';
|
|
|
2
2
|
// openRpcStream attempts to open a stream over a RPC call.
|
|
3
3
|
// if waitAck is set, waits for the remote to ack the stream before returning.
|
|
4
4
|
export async function openRpcStream(componentId, caller, waitAck) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const packetTx = pushable({ objectMode: true });
|
|
6
|
+
const packetRx = caller(packetTx);
|
|
7
7
|
// write the component id
|
|
8
|
-
|
|
8
|
+
packetTx.push({
|
|
9
9
|
body: {
|
|
10
10
|
$case: 'init',
|
|
11
11
|
init: { componentId },
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
14
|
// construct packet stream
|
|
15
|
-
const packetIt =
|
|
15
|
+
const packetIt = packetRx[Symbol.asyncIterator]();
|
|
16
16
|
// wait for ack, if set.
|
|
17
17
|
if (waitAck) {
|
|
18
18
|
const ackPacketIt = await packetIt.next();
|
|
@@ -31,7 +31,7 @@ export async function openRpcStream(componentId, caller, waitAck) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
// build & return the data stream
|
|
34
|
-
return new RpcStream(
|
|
34
|
+
return new RpcStream(packetTx, packetIt);
|
|
35
35
|
}
|
|
36
36
|
// buildRpcStreamOpenStream builds a OpenStream func with a RpcStream.
|
|
37
37
|
export function buildRpcStreamOpenStream(componentId, caller) {
|
|
@@ -40,9 +40,9 @@ export function buildRpcStreamOpenStream(componentId, caller) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
// handleRpcStream handles an incoming RPC stream (remote is the initiator).
|
|
43
|
-
export async function* handleRpcStream(
|
|
43
|
+
export async function* handleRpcStream(packetRx, getter) {
|
|
44
44
|
// read the component id
|
|
45
|
-
const initRpcStreamIt = await
|
|
45
|
+
const initRpcStreamIt = await packetRx.next();
|
|
46
46
|
if (initRpcStreamIt.done) {
|
|
47
47
|
throw new Error('closed before init received');
|
|
48
48
|
}
|
|
@@ -83,23 +83,23 @@ export async function* handleRpcStream(packetStream, getter) {
|
|
|
83
83
|
throw err;
|
|
84
84
|
}
|
|
85
85
|
// build the outgoing packet sink & the packet source
|
|
86
|
-
const
|
|
86
|
+
const packetTx = pushable({ objectMode: true });
|
|
87
87
|
// start the handler
|
|
88
|
-
const rpcStream = new RpcStream(
|
|
88
|
+
const rpcStream = new RpcStream(packetTx, packetRx);
|
|
89
89
|
handler(rpcStream);
|
|
90
90
|
// process packets
|
|
91
|
-
for await (const packet of
|
|
91
|
+
for await (const packet of packetTx) {
|
|
92
92
|
yield* [packet];
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
// RpcStream implements the Stream on top of a RPC call.
|
|
96
96
|
// Note: expects the stream to already have been negotiated.
|
|
97
97
|
export class RpcStream {
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
constructor(
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
98
|
+
// packetTx writes packets to the remote.
|
|
99
|
+
// packetRx receives packets from the remote.
|
|
100
|
+
constructor(packetTx, packetRx) {
|
|
101
|
+
this._packetTx = packetTx;
|
|
102
|
+
this._packetRx = packetRx;
|
|
103
103
|
this.sink = this._createSink();
|
|
104
104
|
this.source = this._createSource();
|
|
105
105
|
}
|
|
@@ -108,23 +108,22 @@ export class RpcStream {
|
|
|
108
108
|
return async (source) => {
|
|
109
109
|
try {
|
|
110
110
|
for await (const arr of source) {
|
|
111
|
-
this.
|
|
111
|
+
this._packetTx.push({
|
|
112
112
|
body: { $case: 'data', data: arr },
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
this.
|
|
115
|
+
this._packetTx.end();
|
|
116
116
|
}
|
|
117
117
|
catch (err) {
|
|
118
|
-
this.
|
|
118
|
+
this._packetTx.end(err);
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
// _createSource initializes the source field.
|
|
123
123
|
_createSource() {
|
|
124
|
-
|
|
125
|
-
return (async function* () {
|
|
124
|
+
return (async function* (packetRx) {
|
|
126
125
|
while (true) {
|
|
127
|
-
const msgIt = await
|
|
126
|
+
const msgIt = await packetRx.next();
|
|
128
127
|
if (msgIt.done) {
|
|
129
128
|
return;
|
|
130
129
|
}
|
|
@@ -144,6 +143,6 @@ export class RpcStream {
|
|
|
144
143
|
break;
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
|
-
})();
|
|
146
|
+
})(this._packetRx);
|
|
148
147
|
}
|
|
149
148
|
}
|
package/dist/srpc/common-rpc.js
CHANGED
|
@@ -120,11 +120,11 @@ export class CommonRPC {
|
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
122
|
this.closed = true;
|
|
123
|
+
this._rpcDataSource.end(err);
|
|
123
124
|
try {
|
|
124
125
|
await this.writeCallCancel();
|
|
125
126
|
}
|
|
126
127
|
finally {
|
|
127
|
-
this._rpcDataSource.end(err);
|
|
128
128
|
// note: don't pass error to _source here.
|
|
129
129
|
this._source.end();
|
|
130
130
|
}
|
package/go.mod
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
module github.com/aperturerobotics/starpc
|
|
2
2
|
|
|
3
|
-
go 1.
|
|
3
|
+
go 1.20
|
|
4
4
|
|
|
5
5
|
require (
|
|
6
6
|
github.com/pkg/errors v0.9.1 // latest
|
|
7
7
|
google.golang.org/protobuf v1.32.0 // latest
|
|
8
|
-
nhooyr.io/websocket v1.8.10 //
|
|
8
|
+
nhooyr.io/websocket v1.8.10 // latest
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
require (
|
|
12
|
-
github.com/aperturerobotics/util v1.
|
|
12
|
+
github.com/aperturerobotics/util v1.11.0 // latest
|
|
13
13
|
github.com/libp2p/go-libp2p v0.32.2 // latest
|
|
14
|
-
github.com/libp2p/go-yamux/v4 v4.0.
|
|
14
|
+
github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512 // master
|
|
15
15
|
github.com/sirupsen/logrus v1.9.3 // latest
|
|
16
16
|
)
|
|
17
17
|
|
|
@@ -31,8 +31,8 @@ require (
|
|
|
31
31
|
github.com/multiformats/go-multistream v0.5.0 // indirect
|
|
32
32
|
github.com/multiformats/go-varint v0.0.7 // indirect
|
|
33
33
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
|
34
|
-
golang.org/x/crypto v0.
|
|
34
|
+
golang.org/x/crypto v0.17.0 // indirect
|
|
35
35
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
|
36
|
-
golang.org/x/sys v0.
|
|
36
|
+
golang.org/x/sys v0.15.0 // indirect
|
|
37
37
|
lukechampine.com/blake3 v1.2.1 // indirect
|
|
38
38
|
)
|
package/go.sum
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
github.com/aperturerobotics/util v1.
|
|
2
|
-
github.com/aperturerobotics/util v1.
|
|
1
|
+
github.com/aperturerobotics/util v1.11.0 h1:SpbpNw23DACYkiZ9cCauP98Nwg73T04YkfD4E/WZ2Hc=
|
|
2
|
+
github.com/aperturerobotics/util v1.11.0/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
|
|
3
3
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
4
4
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
5
5
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
@@ -16,8 +16,8 @@ github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QT
|
|
|
16
16
|
github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4FQ=
|
|
17
17
|
github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk=
|
|
18
18
|
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
|
|
19
|
-
github.com/libp2p/go-yamux/v4 v4.0.
|
|
20
|
-
github.com/libp2p/go-yamux/v4 v4.0.
|
|
19
|
+
github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512 h1:QvLt0Hr2Qmex+9wrv/tBeDsZ5AutKdy6ZF7pGTyEeQY=
|
|
20
|
+
github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512/go.mod h1:OsNeDpmxccy93bUsruLEdsqIuO1VbBOFsQ4c4GfwenE=
|
|
21
21
|
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
|
|
22
22
|
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
|
|
23
23
|
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
|
|
@@ -49,14 +49,14 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2
|
|
|
49
49
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
50
50
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
51
51
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
52
|
-
golang.org/x/crypto v0.
|
|
53
|
-
golang.org/x/crypto v0.
|
|
52
|
+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
|
53
|
+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
|
54
54
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
|
55
55
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
|
56
56
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
57
57
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
58
|
-
golang.org/x/sys v0.
|
|
59
|
-
golang.org/x/sys v0.
|
|
58
|
+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
|
59
|
+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
60
60
|
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
|
61
61
|
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
|
62
62
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.5",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -61,18 +61,14 @@
|
|
|
61
61
|
"singleQuote": true
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@aperturerobotics/ts-common": "^0.8.
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
66
|
-
"@typescript-eslint/parser": "^6.15.0",
|
|
64
|
+
"@aperturerobotics/ts-common": "^0.8.2",
|
|
67
65
|
"bufferutil": "^4.0.7",
|
|
68
66
|
"depcheck": "^1.4.6",
|
|
69
|
-
"esbuild": "^0.19.
|
|
70
|
-
"eslint": "^8.56.0",
|
|
71
|
-
"eslint-config-prettier": "^9.0.0",
|
|
67
|
+
"esbuild": "^0.19.11",
|
|
72
68
|
"prettier": "^3.0.3",
|
|
73
69
|
"rimraf": "^5.0.1",
|
|
74
70
|
"ts-poet": "6.6.0",
|
|
75
|
-
"ts-proto": "^1.
|
|
71
|
+
"ts-proto": "^1.166.1",
|
|
76
72
|
"typescript": "^5.3.2",
|
|
77
73
|
"utf-8-validate": "^6.0.3"
|
|
78
74
|
},
|
|
@@ -84,7 +80,7 @@
|
|
|
84
80
|
"is-promise": "^4.0.0",
|
|
85
81
|
"isomorphic-ws": "^5.0.0",
|
|
86
82
|
"it-first": "^3.0.3",
|
|
87
|
-
"it-length-prefixed": "^9.0.
|
|
83
|
+
"it-length-prefixed": "^9.0.4",
|
|
88
84
|
"it-pipe": "^3.0.1",
|
|
89
85
|
"it-pushable": "^3.2.3",
|
|
90
86
|
"it-stream-types": "^2.0.1",
|
package/srpc/common-rpc.ts
CHANGED
|
@@ -157,10 +157,10 @@ export class CommonRPC {
|
|
|
157
157
|
return
|
|
158
158
|
}
|
|
159
159
|
this.closed = true
|
|
160
|
+
this._rpcDataSource.end(err)
|
|
160
161
|
try {
|
|
161
162
|
await this.writeCallCancel()
|
|
162
163
|
} finally {
|
|
163
|
-
this._rpcDataSource.end(err)
|
|
164
164
|
// note: don't pass error to _source here.
|
|
165
165
|
this._source.end()
|
|
166
166
|
}
|
package/srpc/invoker.go
CHANGED
|
@@ -30,3 +30,18 @@ func (s InvokerSlice) InvokeMethod(serviceID, methodID string, strm Stream) (boo
|
|
|
30
30
|
|
|
31
31
|
// _ is a type assertion
|
|
32
32
|
var _ Invoker = (InvokerSlice)(nil)
|
|
33
|
+
|
|
34
|
+
// InvokerFunc is a function implementing InvokeMethod.
|
|
35
|
+
type InvokerFunc func(serviceID, methodID string, strm Stream) (bool, error)
|
|
36
|
+
|
|
37
|
+
// InvokeMethod invokes the method matching the service & method ID.
|
|
38
|
+
// Returns false, nil if not found.
|
|
39
|
+
// If service string is empty, ignore it.
|
|
40
|
+
func (f InvokerFunc) InvokeMethod(serviceID, methodID string, strm Stream) (bool, error) {
|
|
41
|
+
if f == nil {
|
|
42
|
+
return false, nil
|
|
43
|
+
}
|
|
44
|
+
return f(serviceID, methodID, strm)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var _ Invoker = (InvokerFunc)(nil)
|