starpc 0.4.7 → 0.5.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/Makefile +1 -0
- package/README.md +20 -10
- package/dist/echo/client-test.d.ts +1 -0
- package/dist/echo/client-test.js +20 -18
- package/dist/echo/echo.pb.d.ts +165 -12
- package/dist/echo/echo.pb.js +61 -17
- package/dist/echo/server.d.ts +8 -4
- package/dist/echo/server.js +29 -37
- package/dist/rpcstream/rpcstream.d.ts +6 -6
- package/dist/rpcstream/rpcstream.js +92 -51
- package/dist/rpcstream/rpcstream.pb.d.ts +46 -1
- package/dist/rpcstream/rpcstream.pb.js +157 -9
- package/dist/srpc/broadcast-channel.d.ts +2 -2
- package/dist/srpc/broadcast-channel.js +6 -6
- package/dist/srpc/client.d.ts +3 -4
- package/dist/srpc/client.js +12 -46
- package/dist/srpc/common-rpc.d.ts +3 -2
- package/dist/srpc/common-rpc.js +12 -0
- package/dist/srpc/definition.d.ts +3 -3
- package/dist/srpc/handler.d.ts +2 -3
- package/dist/srpc/handler.js +5 -22
- package/dist/srpc/index.d.ts +2 -2
- package/dist/srpc/index.js +2 -2
- package/dist/srpc/packet.js +0 -32
- package/dist/srpc/pushable.d.ts +2 -0
- package/dist/srpc/pushable.js +13 -0
- package/dist/srpc/rpcproto.pb.d.ts +13 -6
- package/dist/srpc/rpcproto.pb.js +95 -10
- package/dist/srpc/server.d.ts +1 -0
- package/dist/srpc/server.js +7 -0
- package/dist/srpc/ts-proto-rpc.d.ts +3 -4
- package/e2e/e2e.ts +4 -3
- package/e2e/e2e_test.go +35 -7
- package/echo/client-test.ts +23 -18
- package/echo/echo.pb.go +33 -20
- package/echo/echo.pb.ts +90 -34
- package/echo/echo.proto +4 -0
- package/echo/echo_srpc.pb.go +77 -0
- package/echo/server.go +18 -0
- package/echo/server.ts +47 -41
- package/integration/integration.go +1 -2
- package/integration/integration.ts +5 -1
- package/integration/integration_srpc.pb.go +139 -0
- package/package.json +13 -11
- package/patches/{ts-poet+4.13.0.patch → ts-poet+4.14.0.patch} +1 -1
- package/patches/ts-proto+1.115.5.patch +1339 -0
- package/srpc/broadcast-channel.ts +8 -8
- package/srpc/client.ts +16 -50
- package/srpc/common-rpc.ts +14 -2
- package/srpc/definition.ts +3 -3
- package/srpc/handler.ts +17 -34
- package/srpc/index.ts +3 -3
- package/srpc/muxed-conn.go +2 -2
- package/srpc/packet-rw.go +4 -6
- package/srpc/packet.ts +0 -33
- package/srpc/pushable.ts +17 -0
- package/srpc/rpcproto.pb.ts +122 -12
- package/srpc/server-pipe.go +2 -2
- package/srpc/server.go +2 -2
- package/srpc/server.ts +8 -0
- package/srpc/ts-proto-rpc.ts +4 -6
- package/srpc/websocket.go +2 -2
- package/dist/echo/sever.d.ts +0 -0
- package/dist/echo/sever.js +0 -1
- package/dist/srpc/observable-source.d.ts +0 -9
- package/dist/srpc/observable-source.js +0 -25
- package/echo/sever.ts +0 -0
- package/srpc/observable-source.ts +0 -40
package/echo/server.ts
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
|
-
import { Observable, from as observableFrom } from 'rxjs'
|
|
2
1
|
import { Echoer, EchoMsg } from './echo.pb.js'
|
|
3
2
|
import { pushable, Pushable } from 'it-pushable'
|
|
3
|
+
import first from 'it-first'
|
|
4
|
+
import { Server } from '../srpc/server.js'
|
|
5
|
+
import { writeToPushable } from '../srpc/pushable.js'
|
|
6
|
+
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
|
|
7
|
+
import { handleRpcStream } from '../rpcstream/rpcstream.js'
|
|
4
8
|
|
|
5
9
|
// EchoServer implements the Echoer server.
|
|
6
10
|
export class EchoerServer implements Echoer {
|
|
11
|
+
// proxyServer is the server used for RpcStream requests.
|
|
12
|
+
private proxyServer?: Server
|
|
13
|
+
|
|
14
|
+
constructor(proxyServer?: Server) {
|
|
15
|
+
this.proxyServer = proxyServer
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
public async Echo(request: EchoMsg): Promise<EchoMsg> {
|
|
8
19
|
return request
|
|
9
20
|
}
|
|
10
21
|
|
|
11
|
-
public EchoServerStream(request: EchoMsg):
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
yield request
|
|
17
|
-
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
18
|
-
}
|
|
19
|
-
})()
|
|
20
|
-
)
|
|
22
|
+
public async *EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg> {
|
|
23
|
+
for (let i = 0; i < 5; i++) {
|
|
24
|
+
yield request
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
26
|
+
}
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
public EchoClientStream(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
complete() {
|
|
33
|
-
reject(new Error('none received'))
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
})
|
|
29
|
+
public async EchoClientStream(
|
|
30
|
+
request: AsyncIterable<EchoMsg>
|
|
31
|
+
): Promise<EchoMsg> {
|
|
32
|
+
// return the first message sent by the client.
|
|
33
|
+
const message = await first(request)
|
|
34
|
+
if (!message) {
|
|
35
|
+
throw new Error('received no messages')
|
|
36
|
+
}
|
|
37
|
+
return message
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
public EchoBidiStream(
|
|
40
|
+
public EchoBidiStream(
|
|
41
|
+
request: AsyncIterable<EchoMsg>
|
|
42
|
+
): AsyncIterable<EchoMsg> {
|
|
40
43
|
// build result observable
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
const result: Pushable<EchoMsg> = pushable({ objectMode: true })
|
|
45
|
+
result.push({ body: 'hello from server' })
|
|
46
|
+
writeToPushable(request, result)
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public RpcStream(
|
|
51
|
+
request: AsyncIterable<RpcStreamPacket>
|
|
52
|
+
): AsyncIterable<RpcStreamPacket> {
|
|
53
|
+
return handleRpcStream(
|
|
54
|
+
request[Symbol.asyncIterator](),
|
|
55
|
+
async (_componentId: string): Promise<Server> => {
|
|
56
|
+
if (!this.proxyServer) {
|
|
57
|
+
throw new Error('rpc stream proxy server not set')
|
|
58
|
+
}
|
|
59
|
+
return this.proxyServer
|
|
60
|
+
}
|
|
61
|
+
)
|
|
56
62
|
}
|
|
57
63
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebSocketConn } from '../srpc/websocket.js'
|
|
2
|
-
import { runClientTest } from '../echo/client-test.js'
|
|
2
|
+
import { runClientTest, runRpcStreamTest } from '../echo/client-test.js'
|
|
3
3
|
import WebSocket from 'isomorphic-ws'
|
|
4
4
|
|
|
5
5
|
async function runRPC() {
|
|
@@ -9,7 +9,11 @@ async function runRPC() {
|
|
|
9
9
|
const channel = new WebSocketConn(ws)
|
|
10
10
|
const client = channel.buildClient()
|
|
11
11
|
|
|
12
|
+
console.log('Running client test via WebSocket..')
|
|
12
13
|
await runClientTest(client)
|
|
14
|
+
|
|
15
|
+
console.log('Running RpcStream test via WebSocket..')
|
|
16
|
+
await runRpcStreamTest(client)
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
runRPC()
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Code generated by protoc-gen-srpc. DO NOT EDIT.
|
|
2
|
+
// protoc-gen-srpc version: v0.0.0-20220611014014-aa9dc5523865
|
|
3
|
+
// source: github.com/aperturerobotics/starpc/integration/integration.proto
|
|
4
|
+
|
|
5
|
+
package main
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
context "context"
|
|
9
|
+
|
|
10
|
+
rpcstream "github.com/aperturerobotics/starpc/rpcstream"
|
|
11
|
+
srpc "github.com/aperturerobotics/starpc/srpc"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
type SRPCIntegrationServiceClient interface {
|
|
15
|
+
SRPCClient() srpc.Client
|
|
16
|
+
|
|
17
|
+
RpcStream(ctx context.Context) (SRPCIntegrationService_RpcStreamClient, error)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type srpcIntegrationServiceClient struct {
|
|
21
|
+
cc srpc.Client
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func NewSRPCIntegrationServiceClient(cc srpc.Client) SRPCIntegrationServiceClient {
|
|
25
|
+
return &srpcIntegrationServiceClient{cc}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func (c *srpcIntegrationServiceClient) SRPCClient() srpc.Client { return c.cc }
|
|
29
|
+
|
|
30
|
+
func (c *srpcIntegrationServiceClient) RpcStream(ctx context.Context) (SRPCIntegrationService_RpcStreamClient, error) {
|
|
31
|
+
stream, err := c.cc.NewStream(ctx, "main.IntegrationService", "RpcStream", nil)
|
|
32
|
+
if err != nil {
|
|
33
|
+
return nil, err
|
|
34
|
+
}
|
|
35
|
+
strm := &srpcIntegrationService_RpcStreamClient{stream}
|
|
36
|
+
return strm, nil
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type SRPCIntegrationService_RpcStreamClient interface {
|
|
40
|
+
srpc.Stream
|
|
41
|
+
Send(*rpcstream.RpcStreamPacket) error
|
|
42
|
+
Recv() (*rpcstream.RpcStreamPacket, error)
|
|
43
|
+
RecvTo(*rpcstream.RpcStreamPacket) error
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type srpcIntegrationService_RpcStreamClient struct {
|
|
47
|
+
srpc.Stream
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func (x *srpcIntegrationService_RpcStreamClient) Send(m *rpcstream.RpcStreamPacket) error {
|
|
51
|
+
return x.MsgSend(m)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
func (x *srpcIntegrationService_RpcStreamClient) Recv() (*rpcstream.RpcStreamPacket, error) {
|
|
55
|
+
m := new(rpcstream.RpcStreamPacket)
|
|
56
|
+
if err := x.MsgRecv(m); err != nil {
|
|
57
|
+
return nil, err
|
|
58
|
+
}
|
|
59
|
+
return m, nil
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func (x *srpcIntegrationService_RpcStreamClient) RecvTo(m *rpcstream.RpcStreamPacket) error {
|
|
63
|
+
return x.MsgRecv(m)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type SRPCIntegrationServiceServer interface {
|
|
67
|
+
RpcStream(SRPCIntegrationService_RpcStreamStream) error
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type SRPCIntegrationServiceUnimplementedServer struct{}
|
|
71
|
+
|
|
72
|
+
func (s *SRPCIntegrationServiceUnimplementedServer) RpcStream(SRPCIntegrationService_RpcStreamStream) error {
|
|
73
|
+
return srpc.ErrUnimplemented
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const SRPCIntegrationServiceServiceID = "main.IntegrationService"
|
|
77
|
+
|
|
78
|
+
type SRPCIntegrationServiceHandler struct {
|
|
79
|
+
impl SRPCIntegrationServiceServer
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func (SRPCIntegrationServiceHandler) GetServiceID() string { return SRPCIntegrationServiceServiceID }
|
|
83
|
+
|
|
84
|
+
func (SRPCIntegrationServiceHandler) GetMethodIDs() []string {
|
|
85
|
+
return []string{
|
|
86
|
+
"RpcStream",
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func (d *SRPCIntegrationServiceHandler) InvokeMethod(
|
|
91
|
+
serviceID, methodID string,
|
|
92
|
+
strm srpc.Stream,
|
|
93
|
+
) (bool, error) {
|
|
94
|
+
if serviceID != "" && serviceID != d.GetServiceID() {
|
|
95
|
+
return false, nil
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
switch methodID {
|
|
99
|
+
case "RpcStream":
|
|
100
|
+
return true, d.InvokeMethod_RpcStream(d.impl, strm)
|
|
101
|
+
default:
|
|
102
|
+
return false, nil
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func (SRPCIntegrationServiceHandler) InvokeMethod_RpcStream(impl SRPCIntegrationServiceServer, strm srpc.Stream) error {
|
|
107
|
+
clientStrm := &srpcIntegrationService_RpcStreamStream{strm}
|
|
108
|
+
return impl.RpcStream(clientStrm)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
func SRPCRegisterIntegrationService(mux srpc.Mux, impl SRPCIntegrationServiceServer) error {
|
|
112
|
+
return mux.Register(&SRPCIntegrationServiceHandler{impl: impl})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type SRPCIntegrationService_RpcStreamStream interface {
|
|
116
|
+
srpc.Stream
|
|
117
|
+
Send(*rpcstream.RpcStreamPacket) error
|
|
118
|
+
Recv() (*rpcstream.RpcStreamPacket, error)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type srpcIntegrationService_RpcStreamStream struct {
|
|
122
|
+
srpc.Stream
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func (x *srpcIntegrationService_RpcStreamStream) Send(m *rpcstream.RpcStreamPacket) error {
|
|
126
|
+
return x.MsgSend(m)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func (x *srpcIntegrationService_RpcStreamStream) Recv() (*rpcstream.RpcStreamPacket, error) {
|
|
130
|
+
m := new(rpcstream.RpcStreamPacket)
|
|
131
|
+
if err := x.MsgRecv(m); err != nil {
|
|
132
|
+
return nil, err
|
|
133
|
+
}
|
|
134
|
+
return m, nil
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
func (x *srpcIntegrationService_RpcStreamStream) RecvTo(m *rpcstream.RpcStreamPacket) error {
|
|
138
|
+
return x.MsgRecv(m)
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
"gen": "make genproto",
|
|
43
43
|
"test": "npm run test:js && npm run test:go",
|
|
44
44
|
"test:go": "make test",
|
|
45
|
-
"
|
|
45
|
+
"build:e2e": "npm run build && cd e2e && esbuild e2e.ts --sourcemap --outfile=e2e.js --bundle --platform=node",
|
|
46
|
+
"test:js": "npm run build:e2e && cd e2e && node ./e2e.js",
|
|
47
|
+
"debug:js": "npm run build:e2e && cd e2e && node --inspect --inspect-brk ./e2e.js",
|
|
46
48
|
"test:integration": "make integration",
|
|
47
49
|
"integration": "npm run test:integration",
|
|
48
50
|
"lint": "npm run lint:go && npm run lint:js",
|
|
@@ -56,23 +58,24 @@
|
|
|
56
58
|
"singleQuote": true
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.30.0",
|
|
62
|
+
"@typescript-eslint/parser": "^5.30.0",
|
|
61
63
|
"depcheck": "^1.4.3",
|
|
62
|
-
"esbuild": "^0.14.
|
|
64
|
+
"esbuild": "^0.14.47",
|
|
63
65
|
"eslint": "^8.18.0",
|
|
64
66
|
"eslint-config-prettier": "^8.5.0",
|
|
65
67
|
"prettier": "^2.7.1",
|
|
66
68
|
"rimraf": "^3.0.2",
|
|
67
|
-
"ts-proto": "^1.115.
|
|
69
|
+
"ts-proto": "^1.115.5",
|
|
68
70
|
"typescript": "^4.7.4"
|
|
69
71
|
},
|
|
70
72
|
"dependencies": {
|
|
71
|
-
"@libp2p/interface-connection": "^2.
|
|
72
|
-
"@libp2p/interface-stream-muxer": "^
|
|
73
|
-
"@libp2p/mplex": "^
|
|
73
|
+
"@libp2p/interface-connection": "^2.1.1",
|
|
74
|
+
"@libp2p/interface-stream-muxer": "^2.0.1",
|
|
75
|
+
"@libp2p/mplex": "^4.0.0",
|
|
74
76
|
"event-iterator": "^2.0.0",
|
|
75
|
-
"isomorphic-ws": "^
|
|
77
|
+
"isomorphic-ws": "^5.0.0",
|
|
78
|
+
"it-first": "^1.0.7",
|
|
76
79
|
"it-length-prefixed": "^7.0.1",
|
|
77
80
|
"it-pipe": "^2.0.3",
|
|
78
81
|
"it-pushable": "^3.0.0",
|
|
@@ -81,7 +84,6 @@
|
|
|
81
84
|
"long": "^5.2.0",
|
|
82
85
|
"patch-package": "^6.4.7",
|
|
83
86
|
"protobufjs": "^6.11.3",
|
|
84
|
-
"rxjs": "^7.5.5",
|
|
85
87
|
"ws": "^8.8.0"
|
|
86
88
|
}
|
|
87
89
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
diff --git a/node_modules/ts-poet/build/Import.js b/node_modules/ts-poet/build/Import.js
|
|
2
|
-
index
|
|
2
|
+
index fe1f6d2..280df8f 100644
|
|
3
3
|
--- a/node_modules/ts-poet/build/Import.js
|
|
4
4
|
+++ b/node_modules/ts-poet/build/Import.js
|
|
5
5
|
@@ -293,6 +293,14 @@ function emitImports(imports, ourModulePath, importMappings) {
|