starpc 0.4.9 → 0.5.2
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 +162 -10
- package/dist/echo/echo.pb.js +48 -5
- 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 +44 -0
- package/dist/rpcstream/rpcstream.pb.js +151 -4
- 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 +6 -0
- package/dist/srpc/rpcproto.pb.js +84 -0
- 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 +24 -1
- package/echo/client-test.ts +23 -18
- package/echo/echo.pb.go +33 -20
- package/echo/echo.pb.ts +75 -20
- 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 -9
- package/patches/{ts-poet+4.14.0.patch → ts-poet+4.15.0.patch} +1 -1
- package/patches/ts-proto+1.116.0.patch +14 -0
- 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 +2 -2
- 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 +106 -0
- 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/dist/srpc/handler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pipe } from 'it-pipe';
|
|
2
2
|
import { pushable } from 'it-pushable';
|
|
3
|
-
import { from as observableFrom } from 'rxjs';
|
|
4
3
|
import { buildDecodeMessageTransform, buildEncodeMessageTransform, } from './message.js';
|
|
4
|
+
import { writeToPushable } from './pushable.js';
|
|
5
5
|
// StaticHandler is a handler with a definition and implementation.
|
|
6
6
|
export class StaticHandler {
|
|
7
7
|
constructor(serviceID, methods) {
|
|
@@ -40,8 +40,8 @@ export function createInvokeFn(methodInfo, methodProto) {
|
|
|
40
40
|
// build the request argument.
|
|
41
41
|
let requestArg;
|
|
42
42
|
if (methodInfo.requestStream) {
|
|
43
|
-
//
|
|
44
|
-
requestArg =
|
|
43
|
+
// use the request source as the argument.
|
|
44
|
+
requestArg = requestSource;
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
// receive a single message for the argument.
|
|
@@ -62,25 +62,8 @@ export function createInvokeFn(methodInfo, methodProto) {
|
|
|
62
62
|
throw new Error('return value was undefined');
|
|
63
63
|
}
|
|
64
64
|
if (methodInfo.responseStream) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
throw new Error('expected return value to be an Observable');
|
|
68
|
-
}
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
responseObs.subscribe({
|
|
71
|
-
next(value) {
|
|
72
|
-
responseSink.push(value);
|
|
73
|
-
},
|
|
74
|
-
error: (err) => {
|
|
75
|
-
responseSink.throw(err);
|
|
76
|
-
reject(err);
|
|
77
|
-
},
|
|
78
|
-
complete: () => {
|
|
79
|
-
responseSink.end();
|
|
80
|
-
resolve();
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
});
|
|
65
|
+
const response = responseObj;
|
|
66
|
+
return writeToPushable(response, responseSink);
|
|
84
67
|
}
|
|
85
68
|
else {
|
|
86
69
|
const responsePromise = responseObj;
|
package/dist/srpc/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { Server } from './server.js';
|
|
|
4
4
|
export { Conn, ConnParams } from './conn.js';
|
|
5
5
|
export { Handler, InvokeFn, createHandler, createInvokeFn } from './handler.js';
|
|
6
6
|
export { Packet, CallStart, CallData } from './rpcproto.pb.js';
|
|
7
|
-
export { Mux, createMux } from './mux.js';
|
|
7
|
+
export { Mux, StaticMux, createMux } from './mux.js';
|
|
8
8
|
export { BroadcastChannelDuplex, newBroadcastChannelDuplex, BroadcastChannelConn, } from './broadcast-channel.js';
|
|
9
9
|
export { MessagePortIterable, newMessagePortIterable, MessagePortConn, } from './message-port.js';
|
|
10
|
-
export {
|
|
10
|
+
export { writeToPushable } from './pushable';
|
package/dist/srpc/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { Server } from './server.js';
|
|
|
3
3
|
export { Conn } from './conn.js';
|
|
4
4
|
export { createHandler, createInvokeFn } from './handler.js';
|
|
5
5
|
export { Packet, CallStart, CallData } from './rpcproto.pb.js';
|
|
6
|
-
export { createMux } from './mux.js';
|
|
6
|
+
export { StaticMux, createMux } from './mux.js';
|
|
7
7
|
export { BroadcastChannelDuplex, newBroadcastChannelDuplex, BroadcastChannelConn, } from './broadcast-channel.js';
|
|
8
8
|
export { MessagePortIterable, newMessagePortIterable, MessagePortConn, } from './message-port.js';
|
|
9
|
-
export {
|
|
9
|
+
export { writeToPushable } from './pushable';
|
package/dist/srpc/packet.js
CHANGED
|
@@ -66,35 +66,3 @@ export function prependPacketLen(msgData) {
|
|
|
66
66
|
merged.set(msgData, msgLenData.length);
|
|
67
67
|
return merged;
|
|
68
68
|
}
|
|
69
|
-
/*
|
|
70
|
-
// buildCallDataPacket builds a CallData packet.
|
|
71
|
-
function buildCallDataPacket(data: Uint8Array): Packet {
|
|
72
|
-
const callData: CallData = {
|
|
73
|
-
data: p,
|
|
74
|
-
complete: false,
|
|
75
|
-
error: '',
|
|
76
|
-
}
|
|
77
|
-
const pkt: Packet = {
|
|
78
|
-
body: {
|
|
79
|
-
$case: 'callData',
|
|
80
|
-
callData: callData,
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return pkt
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// wrapCallDataTransform is a transformer that wraps call data into a Packet.
|
|
87
|
-
export async function* wrapCallDataTransform(
|
|
88
|
-
source: Source<Uint8Array | Uint8Array>
|
|
89
|
-
): AsyncIterable<Packet> {
|
|
90
|
-
for await (const pkt of source) {
|
|
91
|
-
if (Array.isArray(pkt)) {
|
|
92
|
-
for (const p of pkt) {
|
|
93
|
-
yield* [buildCallDataPacket(p)]
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
yield* [buildCallDataPacket(pkt)]
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
*/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// writeToPushable writes the incoming server data to the pushable.
|
|
2
|
+
export async function writeToPushable(dataSource, out) {
|
|
3
|
+
try {
|
|
4
|
+
for await (const data of dataSource) {
|
|
5
|
+
out.push(data);
|
|
6
|
+
}
|
|
7
|
+
out.end();
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
out.end(err);
|
|
11
|
+
throw err;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -48,6 +48,8 @@ export interface CallData {
|
|
|
48
48
|
export declare const Packet: {
|
|
49
49
|
encode(message: Packet, writer?: _m0.Writer): _m0.Writer;
|
|
50
50
|
decode(input: _m0.Reader | Uint8Array, length?: number): Packet;
|
|
51
|
+
encodeTransform(source: AsyncIterable<Packet | Packet[]> | Iterable<Packet | Packet[]>): AsyncIterable<Uint8Array>;
|
|
52
|
+
decodeTransform(source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>): AsyncIterable<Packet>;
|
|
51
53
|
fromJSON(object: any): Packet;
|
|
52
54
|
toJSON(message: Packet): unknown;
|
|
53
55
|
fromPartial<I extends {
|
|
@@ -121,6 +123,8 @@ export declare const Packet: {
|
|
|
121
123
|
export declare const CallStart: {
|
|
122
124
|
encode(message: CallStart, writer?: _m0.Writer): _m0.Writer;
|
|
123
125
|
decode(input: _m0.Reader | Uint8Array, length?: number): CallStart;
|
|
126
|
+
encodeTransform(source: AsyncIterable<CallStart | CallStart[]> | Iterable<CallStart | CallStart[]>): AsyncIterable<Uint8Array>;
|
|
127
|
+
decodeTransform(source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>): AsyncIterable<CallStart>;
|
|
124
128
|
fromJSON(object: any): CallStart;
|
|
125
129
|
toJSON(message: CallStart): unknown;
|
|
126
130
|
fromPartial<I extends {
|
|
@@ -138,6 +142,8 @@ export declare const CallStart: {
|
|
|
138
142
|
export declare const CallData: {
|
|
139
143
|
encode(message: CallData, writer?: _m0.Writer): _m0.Writer;
|
|
140
144
|
decode(input: _m0.Reader | Uint8Array, length?: number): CallData;
|
|
145
|
+
encodeTransform(source: AsyncIterable<CallData | CallData[]> | Iterable<CallData | CallData[]>): AsyncIterable<Uint8Array>;
|
|
146
|
+
decodeTransform(source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>): AsyncIterable<CallData>;
|
|
141
147
|
fromJSON(object: any): CallData;
|
|
142
148
|
toJSON(message: CallData): unknown;
|
|
143
149
|
fromPartial<I extends {
|
package/dist/srpc/rpcproto.pb.js
CHANGED
|
@@ -41,6 +41,34 @@ export const Packet = {
|
|
|
41
41
|
}
|
|
42
42
|
return message;
|
|
43
43
|
},
|
|
44
|
+
// encodeTransform encodes a source of message objects.
|
|
45
|
+
// Transform<Packet, Uint8Array>
|
|
46
|
+
async *encodeTransform(source) {
|
|
47
|
+
for await (const pkt of source) {
|
|
48
|
+
if (Array.isArray(pkt)) {
|
|
49
|
+
for (const p of pkt) {
|
|
50
|
+
yield* [Packet.encode(p).finish()];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
yield* [Packet.encode(pkt).finish()];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
// decodeTransform decodes a source of encoded messages.
|
|
59
|
+
// Transform<Uint8Array, Packet>
|
|
60
|
+
async *decodeTransform(source) {
|
|
61
|
+
for await (const pkt of source) {
|
|
62
|
+
if (Array.isArray(pkt)) {
|
|
63
|
+
for (const p of pkt) {
|
|
64
|
+
yield* [Packet.decode(p)];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
yield* [Packet.decode(pkt)];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
44
72
|
fromJSON(object) {
|
|
45
73
|
return {
|
|
46
74
|
body: isSet(object.callStart)
|
|
@@ -136,6 +164,34 @@ export const CallStart = {
|
|
|
136
164
|
}
|
|
137
165
|
return message;
|
|
138
166
|
},
|
|
167
|
+
// encodeTransform encodes a source of message objects.
|
|
168
|
+
// Transform<CallStart, Uint8Array>
|
|
169
|
+
async *encodeTransform(source) {
|
|
170
|
+
for await (const pkt of source) {
|
|
171
|
+
if (Array.isArray(pkt)) {
|
|
172
|
+
for (const p of pkt) {
|
|
173
|
+
yield* [CallStart.encode(p).finish()];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
yield* [CallStart.encode(pkt).finish()];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
// decodeTransform decodes a source of encoded messages.
|
|
182
|
+
// Transform<Uint8Array, CallStart>
|
|
183
|
+
async *decodeTransform(source) {
|
|
184
|
+
for await (const pkt of source) {
|
|
185
|
+
if (Array.isArray(pkt)) {
|
|
186
|
+
for (const p of pkt) {
|
|
187
|
+
yield* [CallStart.decode(p)];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
yield* [CallStart.decode(pkt)];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
139
195
|
fromJSON(object) {
|
|
140
196
|
return {
|
|
141
197
|
rpcService: isSet(object.rpcService) ? String(object.rpcService) : '',
|
|
@@ -214,6 +270,34 @@ export const CallData = {
|
|
|
214
270
|
}
|
|
215
271
|
return message;
|
|
216
272
|
},
|
|
273
|
+
// encodeTransform encodes a source of message objects.
|
|
274
|
+
// Transform<CallData, Uint8Array>
|
|
275
|
+
async *encodeTransform(source) {
|
|
276
|
+
for await (const pkt of source) {
|
|
277
|
+
if (Array.isArray(pkt)) {
|
|
278
|
+
for (const p of pkt) {
|
|
279
|
+
yield* [CallData.encode(p).finish()];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
yield* [CallData.encode(pkt).finish()];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
// decodeTransform decodes a source of encoded messages.
|
|
288
|
+
// Transform<Uint8Array, CallData>
|
|
289
|
+
async *decodeTransform(source) {
|
|
290
|
+
for await (const pkt of source) {
|
|
291
|
+
if (Array.isArray(pkt)) {
|
|
292
|
+
for (const p of pkt) {
|
|
293
|
+
yield* [CallData.decode(p)];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
yield* [CallData.decode(pkt)];
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
},
|
|
217
301
|
fromJSON(object) {
|
|
218
302
|
return {
|
|
219
303
|
data: isSet(object.data)
|
package/dist/srpc/server.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare class Server implements StreamHandler {
|
|
|
10
10
|
startRpc(): ServerRPC;
|
|
11
11
|
handleStream(stream: Stream): ServerRPC;
|
|
12
12
|
handleDuplex(stream: Duplex<Uint8Array>): ServerRPC;
|
|
13
|
+
handlePacketDuplex(stream: Duplex<Uint8Array>): ServerRPC;
|
|
13
14
|
handlePacketStream(stream: Duplex<Packet>): ServerRPC;
|
|
14
15
|
}
|
package/dist/srpc/server.js
CHANGED
|
@@ -21,6 +21,13 @@ export class Server {
|
|
|
21
21
|
pipe(stream, parseLengthPrefixTransform(), decodePacketSource, rpc, encodePacketSource, prependLengthPrefixTransform(), stream);
|
|
22
22
|
return rpc;
|
|
23
23
|
}
|
|
24
|
+
// handlePacketDuplex handles an incoming Uint8Array duplex.
|
|
25
|
+
// skips the packet length prefix transform.
|
|
26
|
+
handlePacketDuplex(stream) {
|
|
27
|
+
const rpc = this.startRpc();
|
|
28
|
+
pipe(stream, decodePacketSource, rpc, encodePacketSource, stream);
|
|
29
|
+
return rpc;
|
|
30
|
+
}
|
|
24
31
|
// handlePacketStream handles an incoming Packet duplex.
|
|
25
32
|
handlePacketStream(stream) {
|
|
26
33
|
const rpc = this.startRpc();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Observable } from 'rxjs';
|
|
2
1
|
export interface TsProtoRpc {
|
|
3
2
|
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
|
4
|
-
clientStreamingRequest(service: string, method: string, data:
|
|
5
|
-
serverStreamingRequest(service: string, method: string, data: Uint8Array):
|
|
6
|
-
bidirectionalStreamingRequest(service: string, method: string, data:
|
|
3
|
+
clientStreamingRequest(service: string, method: string, data: AsyncIterable<Uint8Array>): Promise<Uint8Array>;
|
|
4
|
+
serverStreamingRequest(service: string, method: string, data: Uint8Array): AsyncIterable<Uint8Array>;
|
|
5
|
+
bidirectionalStreamingRequest(service: string, method: string, data: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array>;
|
|
7
6
|
}
|
package/e2e/e2e.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { pipe } from 'it-pipe'
|
|
2
2
|
import { createHandler, createMux, Server, Client, Conn } from '../srpc'
|
|
3
3
|
import { EchoerDefinition, EchoerServer, runClientTest } from '../echo'
|
|
4
|
+
import { runRpcStreamTest } from '../echo/client-test'
|
|
4
5
|
|
|
5
6
|
async function runRPC() {
|
|
6
7
|
const mux = createMux()
|
|
7
|
-
const echoer = new EchoerServer()
|
|
8
|
-
mux.register(createHandler(EchoerDefinition, echoer))
|
|
9
8
|
const server = new Server(mux)
|
|
9
|
+
const echoer = new EchoerServer(server)
|
|
10
|
+
mux.register(createHandler(EchoerDefinition, echoer))
|
|
10
11
|
|
|
11
12
|
const clientConn = new Conn()
|
|
12
13
|
const serverConn = new Conn(server)
|
|
13
14
|
pipe(clientConn, serverConn, clientConn)
|
|
14
15
|
const client = new Client(clientConn.buildOpenStreamFunc())
|
|
15
16
|
|
|
17
|
+
await runRpcStreamTest(client)
|
|
16
18
|
await runClientTest(client)
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -21,7 +23,6 @@ runRPC()
|
|
|
21
23
|
console.log('finished successfully')
|
|
22
24
|
})
|
|
23
25
|
.catch((err) => {
|
|
24
|
-
console.log('failed')
|
|
25
26
|
console.error(err)
|
|
26
27
|
process.exit(1)
|
|
27
28
|
})
|
package/e2e/e2e_test.go
CHANGED
|
@@ -8,6 +8,7 @@ import (
|
|
|
8
8
|
"time"
|
|
9
9
|
|
|
10
10
|
"github.com/aperturerobotics/starpc/echo"
|
|
11
|
+
"github.com/aperturerobotics/starpc/rpcstream"
|
|
11
12
|
"github.com/aperturerobotics/starpc/srpc"
|
|
12
13
|
"github.com/libp2p/go-libp2p/p2p/muxer/mplex"
|
|
13
14
|
mp "github.com/libp2p/go-mplex"
|
|
@@ -17,8 +18,8 @@ import (
|
|
|
17
18
|
// RunE2E runs an end to end test with a callback.
|
|
18
19
|
func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
19
20
|
// construct the server
|
|
20
|
-
echoServer := &echo.EchoServer{}
|
|
21
21
|
mux := srpc.NewMux()
|
|
22
|
+
echoServer := echo.NewEchoServer(mux)
|
|
22
23
|
if err := echo.SRPCRegisterEchoer(mux, echoServer); err != nil {
|
|
23
24
|
t.Fatal(err.Error())
|
|
24
25
|
}
|
|
@@ -179,3 +180,25 @@ func TestE2E_BidiStream(t *testing.T) {
|
|
|
179
180
|
return strm.Close()
|
|
180
181
|
})
|
|
181
182
|
}
|
|
183
|
+
|
|
184
|
+
func TestE2E_RpcStream(t *testing.T) {
|
|
185
|
+
ctx := context.Background()
|
|
186
|
+
RunE2E(t, func(client echo.SRPCEchoerClient) error {
|
|
187
|
+
openStreamFn := rpcstream.NewRpcStreamOpenStream(func(ctx context.Context) (rpcstream.RpcStream, error) {
|
|
188
|
+
return client.RpcStream(ctx)
|
|
189
|
+
}, "test")
|
|
190
|
+
proxiedClient := srpc.NewClient(openStreamFn)
|
|
191
|
+
proxiedSvc := echo.NewSRPCEchoerClient(proxiedClient)
|
|
192
|
+
|
|
193
|
+
// run a RPC proxied over another RPC
|
|
194
|
+
resp, err := proxiedSvc.Echo(ctx, &echo.EchoMsg{Body: "hello world"})
|
|
195
|
+
if err != nil {
|
|
196
|
+
return err
|
|
197
|
+
}
|
|
198
|
+
if resp.GetBody() != "hello world" {
|
|
199
|
+
return errors.Errorf("response body incorrect: %q", resp.GetBody())
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return nil
|
|
203
|
+
})
|
|
204
|
+
}
|
package/echo/client-test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client } from '../srpc/index.js'
|
|
2
2
|
import { EchoerClientImpl, EchoMsg } from './echo.pb.js'
|
|
3
|
-
import {
|
|
3
|
+
import { pushable } from 'it-pushable'
|
|
4
|
+
import { buildRpcStreamOpenStream } from '../rpcstream/rpcstream.js'
|
|
4
5
|
|
|
5
6
|
export async function runClientTest(client: Client) {
|
|
6
7
|
const demoServiceClient = new EchoerClientImpl(client)
|
|
@@ -12,10 +13,9 @@ export async function runClientTest(client: Client) {
|
|
|
12
13
|
console.log('success: output', result.body)
|
|
13
14
|
|
|
14
15
|
// observable for client requests
|
|
15
|
-
const clientRequestStream =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
16
|
+
const clientRequestStream = pushable<EchoMsg>({ objectMode: true })
|
|
17
|
+
clientRequestStream.push({ body: 'Hello world from streaming request.' })
|
|
18
|
+
clientRequestStream.end()
|
|
19
19
|
|
|
20
20
|
console.log('Calling EchoClientStream: client -> server...')
|
|
21
21
|
result = await demoServiceClient.EchoClientStream(clientRequestStream)
|
|
@@ -25,17 +25,22 @@ export async function runClientTest(client: Client) {
|
|
|
25
25
|
const serverStream = demoServiceClient.EchoServerStream({
|
|
26
26
|
body: 'Hello world from server to client streaming request.',
|
|
27
27
|
})
|
|
28
|
-
await
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
for await (const msg of serverStream) {
|
|
29
|
+
console.log('server: output', msg.body)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// runRpcStreamTest tests a RPCStream.
|
|
34
|
+
export async function runRpcStreamTest(client: Client) {
|
|
35
|
+
console.log('Calling RpcStream to open a RPC stream client...')
|
|
36
|
+
const service = new EchoerClientImpl(client)
|
|
37
|
+
const openStreamFn = buildRpcStreamOpenStream(
|
|
38
|
+
'test',
|
|
39
|
+
service.RpcStream.bind(service)
|
|
40
|
+
)
|
|
41
|
+
const proxiedClient = new Client(openStreamFn)
|
|
42
|
+
const proxiedService = new EchoerClientImpl(proxiedClient)
|
|
43
|
+
console.log('Calling Echo via RPC stream...')
|
|
44
|
+
const resp = await proxiedService.Echo({ body: 'hello world via proxy' })
|
|
45
|
+
console.log('rpc stream test: succeeded: response: ' + resp.body)
|
|
41
46
|
}
|
package/echo/echo.pb.go
CHANGED
|
@@ -10,6 +10,7 @@ import (
|
|
|
10
10
|
reflect "reflect"
|
|
11
11
|
sync "sync"
|
|
12
12
|
|
|
13
|
+
rpcstream "github.com/aperturerobotics/starpc/rpcstream"
|
|
13
14
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
14
15
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
15
16
|
)
|
|
@@ -75,22 +76,31 @@ var file_github_com_aperturerobotics_starpc_echo_echo_proto_rawDesc = []byte{
|
|
|
75
76
|
0x0a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x65,
|
|
76
77
|
0x72, 0x74, 0x75, 0x72, 0x65, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x69, 0x63, 0x73, 0x2f, 0x73, 0x74,
|
|
77
78
|
0x61, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x70,
|
|
78
|
-
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x65, 0x63, 0x68, 0x6f,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x65, 0x63, 0x68, 0x6f, 0x1a, 0x3c, 0x67, 0x69, 0x74, 0x68,
|
|
80
|
+
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x65, 0x72, 0x74, 0x75, 0x72, 0x65, 0x72,
|
|
81
|
+
0x6f, 0x62, 0x6f, 0x74, 0x69, 0x63, 0x73, 0x2f, 0x73, 0x74, 0x61, 0x72, 0x70, 0x63, 0x2f, 0x72,
|
|
82
|
+
0x70, 0x63, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2f, 0x72, 0x70, 0x63, 0x73, 0x74, 0x72, 0x65,
|
|
83
|
+
0x61, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1d, 0x0a, 0x07, 0x45, 0x63, 0x68, 0x6f,
|
|
84
|
+
0x4d, 0x73, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
|
|
85
|
+
0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x32, 0x93, 0x02, 0x0a, 0x06, 0x45, 0x63, 0x68, 0x6f,
|
|
86
|
+
0x65, 0x72, 0x12, 0x24, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x0d, 0x2e, 0x65, 0x63, 0x68,
|
|
87
|
+
0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x1a, 0x0d, 0x2e, 0x65, 0x63, 0x68, 0x6f,
|
|
88
|
+
0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x12, 0x32, 0x0a, 0x10, 0x45, 0x63, 0x68, 0x6f,
|
|
89
|
+
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x0d, 0x2e, 0x65,
|
|
82
90
|
0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x1a, 0x0d, 0x2e, 0x65, 0x63,
|
|
83
|
-
0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x12, 0x32, 0x0a, 0x10,
|
|
84
|
-
0x68, 0x6f,
|
|
85
|
-
0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x1a,
|
|
86
|
-
0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67,
|
|
87
|
-
0x0a,
|
|
91
|
+
0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x30, 0x01, 0x12, 0x32, 0x0a, 0x10,
|
|
92
|
+
0x45, 0x63, 0x68, 0x6f, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d,
|
|
93
|
+
0x12, 0x0d, 0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x1a,
|
|
94
|
+
0x0d, 0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67, 0x28, 0x01,
|
|
95
|
+
0x12, 0x32, 0x0a, 0x0e, 0x45, 0x63, 0x68, 0x6f, 0x42, 0x69, 0x64, 0x69, 0x53, 0x74, 0x72, 0x65,
|
|
88
96
|
0x61, 0x6d, 0x12, 0x0d, 0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73,
|
|
89
97
|
0x67, 0x1a, 0x0d, 0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x73, 0x67,
|
|
90
|
-
0x28, 0x01,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
0x73,
|
|
98
|
+
0x28, 0x01, 0x30, 0x01, 0x12, 0x47, 0x0a, 0x09, 0x52, 0x70, 0x63, 0x53, 0x74, 0x72, 0x65, 0x61,
|
|
99
|
+
0x6d, 0x12, 0x1a, 0x2e, 0x72, 0x70, 0x63, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x52, 0x70,
|
|
100
|
+
0x63, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x1a, 0x2e,
|
|
101
|
+
0x72, 0x70, 0x63, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x52, 0x70, 0x63, 0x53, 0x74, 0x72,
|
|
102
|
+
0x65, 0x61, 0x6d, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x28, 0x01, 0x30, 0x01, 0x62, 0x06, 0x70,
|
|
103
|
+
0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
var (
|
|
@@ -107,19 +117,22 @@ func file_github_com_aperturerobotics_starpc_echo_echo_proto_rawDescGZIP() []byt
|
|
|
107
117
|
|
|
108
118
|
var file_github_com_aperturerobotics_starpc_echo_echo_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
|
109
119
|
var file_github_com_aperturerobotics_starpc_echo_echo_proto_goTypes = []interface{}{
|
|
110
|
-
(*EchoMsg)(nil),
|
|
120
|
+
(*EchoMsg)(nil), // 0: echo.EchoMsg
|
|
121
|
+
(*rpcstream.RpcStreamPacket)(nil), // 1: rpcstream.RpcStreamPacket
|
|
111
122
|
}
|
|
112
123
|
var file_github_com_aperturerobotics_starpc_echo_echo_proto_depIdxs = []int32{
|
|
113
124
|
0, // 0: echo.Echoer.Echo:input_type -> echo.EchoMsg
|
|
114
125
|
0, // 1: echo.Echoer.EchoServerStream:input_type -> echo.EchoMsg
|
|
115
126
|
0, // 2: echo.Echoer.EchoClientStream:input_type -> echo.EchoMsg
|
|
116
127
|
0, // 3: echo.Echoer.EchoBidiStream:input_type -> echo.EchoMsg
|
|
117
|
-
|
|
118
|
-
0, // 5: echo.Echoer.
|
|
119
|
-
0, // 6: echo.Echoer.
|
|
120
|
-
0, // 7: echo.Echoer.
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
1, // 4: echo.Echoer.RpcStream:input_type -> rpcstream.RpcStreamPacket
|
|
129
|
+
0, // 5: echo.Echoer.Echo:output_type -> echo.EchoMsg
|
|
130
|
+
0, // 6: echo.Echoer.EchoServerStream:output_type -> echo.EchoMsg
|
|
131
|
+
0, // 7: echo.Echoer.EchoClientStream:output_type -> echo.EchoMsg
|
|
132
|
+
0, // 8: echo.Echoer.EchoBidiStream:output_type -> echo.EchoMsg
|
|
133
|
+
1, // 9: echo.Echoer.RpcStream:output_type -> rpcstream.RpcStreamPacket
|
|
134
|
+
5, // [5:10] is the sub-list for method output_type
|
|
135
|
+
0, // [0:5] is the sub-list for method input_type
|
|
123
136
|
0, // [0:0] is the sub-list for extension type_name
|
|
124
137
|
0, // [0:0] is the sub-list for extension extendee
|
|
125
138
|
0, // [0:0] is the sub-list for field type_name
|