starpc 0.5.0 → 0.6.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/dist/echo/echo.pb.d.ts +8 -9
- package/dist/echo/echo.pb.js +16 -17
- package/dist/echo/server.js +1 -1
- package/dist/rpcstream/rpcstream.d.ts +3 -3
- package/dist/rpcstream/rpcstream.js +7 -5
- package/dist/rpcstream/rpcstream.pb.d.ts +2 -3
- package/dist/rpcstream/rpcstream.pb.js +10 -11
- package/dist/srpc/index.d.ts +1 -1
- package/dist/srpc/index.js +1 -1
- package/dist/srpc/rpcproto.pb.d.ts +6 -7
- package/dist/srpc/rpcproto.pb.js +10 -11
- package/dist/srpc/server.d.ts +2 -0
- package/dist/srpc/server.js +4 -0
- package/echo/echo.pb.ts +24 -25
- package/echo/server.ts +3 -3
- package/package.json +9 -7
- package/patches/{ts-poet+4.14.0.patch → ts-poet+4.15.0.patch} +1 -1
- package/srpc/index.ts +1 -1
- package/srpc/rpcproto.pb.ts +12 -16
- package/srpc/server.ts +6 -0
- package/patches/ts-proto+1.115.5.patch +0 -1339
package/dist/echo/echo.pb.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Long from 'long';
|
|
2
|
-
import { EchoMsg as EchoMsg1 } from './echo.pb.js';
|
|
3
2
|
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
|
|
4
3
|
import * as _m0 from 'protobufjs/minimal';
|
|
5
4
|
export declare const protobufPackage = "echo";
|
|
@@ -23,23 +22,23 @@ export declare const EchoMsg: {
|
|
|
23
22
|
/** Echoer service returns the given message. */
|
|
24
23
|
export interface Echoer {
|
|
25
24
|
/** Echo returns the given message. */
|
|
26
|
-
Echo(request:
|
|
25
|
+
Echo(request: EchoMsg): Promise<EchoMsg>;
|
|
27
26
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
28
|
-
EchoServerStream(request:
|
|
27
|
+
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>;
|
|
29
28
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
30
|
-
EchoClientStream(request: AsyncIterable<
|
|
29
|
+
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>;
|
|
31
30
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
32
|
-
EchoBidiStream(request: AsyncIterable<
|
|
31
|
+
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg>;
|
|
33
32
|
/** RpcStream opens a nested rpc call stream. */
|
|
34
33
|
RpcStream(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket>;
|
|
35
34
|
}
|
|
36
35
|
export declare class EchoerClientImpl implements Echoer {
|
|
37
36
|
private readonly rpc;
|
|
38
37
|
constructor(rpc: Rpc);
|
|
39
|
-
Echo(request:
|
|
40
|
-
EchoServerStream(request:
|
|
41
|
-
EchoClientStream(request: AsyncIterable<
|
|
42
|
-
EchoBidiStream(request: AsyncIterable<
|
|
38
|
+
Echo(request: EchoMsg): Promise<EchoMsg>;
|
|
39
|
+
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>;
|
|
40
|
+
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>;
|
|
41
|
+
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg>;
|
|
43
42
|
RpcStream(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket>;
|
|
44
43
|
}
|
|
45
44
|
/** Echoer service returns the given message. */
|
package/dist/echo/echo.pb.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import Long from 'long';
|
|
3
|
-
import { EchoMsg as EchoMsg1 } from './echo.pb.js';
|
|
4
3
|
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
|
|
5
4
|
import * as _m0 from 'protobufjs/minimal';
|
|
6
5
|
export const protobufPackage = 'echo';
|
|
@@ -85,24 +84,24 @@ export class EchoerClientImpl {
|
|
|
85
84
|
this.RpcStream = this.RpcStream.bind(this);
|
|
86
85
|
}
|
|
87
86
|
Echo(request) {
|
|
88
|
-
const data =
|
|
87
|
+
const data = EchoMsg.encode(request).finish();
|
|
89
88
|
const promise = this.rpc.request('echo.Echoer', 'Echo', data);
|
|
90
|
-
return promise.then((data) =>
|
|
89
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
|
|
91
90
|
}
|
|
92
91
|
EchoServerStream(request) {
|
|
93
|
-
const data =
|
|
92
|
+
const data = EchoMsg.encode(request).finish();
|
|
94
93
|
const result = this.rpc.serverStreamingRequest('echo.Echoer', 'EchoServerStream', data);
|
|
95
|
-
return
|
|
94
|
+
return EchoMsg.decodeTransform(result);
|
|
96
95
|
}
|
|
97
96
|
EchoClientStream(request) {
|
|
98
|
-
const data =
|
|
97
|
+
const data = EchoMsg.encodeTransform(request);
|
|
99
98
|
const promise = this.rpc.clientStreamingRequest('echo.Echoer', 'EchoClientStream', data);
|
|
100
|
-
return promise.then((data) =>
|
|
99
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
|
|
101
100
|
}
|
|
102
101
|
EchoBidiStream(request) {
|
|
103
|
-
const data =
|
|
102
|
+
const data = EchoMsg.encodeTransform(request);
|
|
104
103
|
const result = this.rpc.bidirectionalStreamingRequest('echo.Echoer', 'EchoBidiStream', data);
|
|
105
|
-
return
|
|
104
|
+
return EchoMsg.decodeTransform(result);
|
|
106
105
|
}
|
|
107
106
|
RpcStream(request) {
|
|
108
107
|
const data = RpcStreamPacket.encodeTransform(request);
|
|
@@ -117,36 +116,36 @@ export const EchoerDefinition = {
|
|
|
117
116
|
/** Echo returns the given message. */
|
|
118
117
|
echo: {
|
|
119
118
|
name: 'Echo',
|
|
120
|
-
requestType:
|
|
119
|
+
requestType: EchoMsg,
|
|
121
120
|
requestStream: false,
|
|
122
|
-
responseType:
|
|
121
|
+
responseType: EchoMsg,
|
|
123
122
|
responseStream: false,
|
|
124
123
|
options: {},
|
|
125
124
|
},
|
|
126
125
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
127
126
|
echoServerStream: {
|
|
128
127
|
name: 'EchoServerStream',
|
|
129
|
-
requestType:
|
|
128
|
+
requestType: EchoMsg,
|
|
130
129
|
requestStream: false,
|
|
131
|
-
responseType:
|
|
130
|
+
responseType: EchoMsg,
|
|
132
131
|
responseStream: true,
|
|
133
132
|
options: {},
|
|
134
133
|
},
|
|
135
134
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
136
135
|
echoClientStream: {
|
|
137
136
|
name: 'EchoClientStream',
|
|
138
|
-
requestType:
|
|
137
|
+
requestType: EchoMsg,
|
|
139
138
|
requestStream: true,
|
|
140
|
-
responseType:
|
|
139
|
+
responseType: EchoMsg,
|
|
141
140
|
responseStream: false,
|
|
142
141
|
options: {},
|
|
143
142
|
},
|
|
144
143
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
145
144
|
echoBidiStream: {
|
|
146
145
|
name: 'EchoBidiStream',
|
|
147
|
-
requestType:
|
|
146
|
+
requestType: EchoMsg,
|
|
148
147
|
requestStream: true,
|
|
149
|
-
responseType:
|
|
148
|
+
responseType: EchoMsg,
|
|
150
149
|
responseStream: true,
|
|
151
150
|
options: {},
|
|
152
151
|
},
|
package/dist/echo/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { RpcStreamPacket } from './rpcstream.pb.js';
|
|
2
|
-
import { Server } from '../srpc/server.js';
|
|
3
2
|
import { OpenStreamFunc, Stream } from '../srpc/stream.js';
|
|
4
3
|
import { Pushable } from 'it-pushable';
|
|
5
|
-
import { Source, Sink } from 'it-stream-types';
|
|
4
|
+
import { Duplex, Source, Sink } from 'it-stream-types';
|
|
6
5
|
export declare type RpcStreamCaller = (request: AsyncIterable<RpcStreamPacket>) => AsyncIterable<RpcStreamPacket>;
|
|
7
6
|
export declare function openRpcStream(componentId: string, caller: RpcStreamCaller): Promise<Stream>;
|
|
8
7
|
export declare function buildRpcStreamOpenStream(componentId: string, caller: RpcStreamCaller): OpenStreamFunc;
|
|
9
|
-
export declare type
|
|
8
|
+
export declare type RpcStreamHandler = (stream: Duplex<Uint8Array>) => void;
|
|
9
|
+
export declare type RpcStreamGetter = (componentId: string) => Promise<RpcStreamHandler | null>;
|
|
10
10
|
export declare function handleRpcStream(packetStream: AsyncIterator<RpcStreamPacket>, getter: RpcStreamGetter): AsyncIterable<RpcStreamPacket>;
|
|
11
11
|
export declare class RpcStream implements Stream {
|
|
12
12
|
readonly source: Source<Uint8Array>;
|
|
@@ -49,10 +49,10 @@ export async function* handleRpcStream(packetStream, getter) {
|
|
|
49
49
|
throw new Error('expected init packet');
|
|
50
50
|
}
|
|
51
51
|
// lookup the server for the component id.
|
|
52
|
-
let
|
|
52
|
+
let handler = null;
|
|
53
53
|
let err;
|
|
54
54
|
try {
|
|
55
|
-
|
|
55
|
+
handler = await getter(initRpcStreamPacket.body.init.componentId);
|
|
56
56
|
}
|
|
57
57
|
catch (errAny) {
|
|
58
58
|
err = errAny;
|
|
@@ -63,7 +63,7 @@ export async function* handleRpcStream(packetStream, getter) {
|
|
|
63
63
|
err = new Error(`rpc getter failed: ${err}`);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
if (!
|
|
66
|
+
if (!handler && !err) {
|
|
67
67
|
err = new Error('not implemented');
|
|
68
68
|
}
|
|
69
69
|
yield* [
|
|
@@ -81,9 +81,11 @@ export async function* handleRpcStream(packetStream, getter) {
|
|
|
81
81
|
}
|
|
82
82
|
// build the outgoing packet sink & the packet source
|
|
83
83
|
const packetSink = pushable({ objectMode: true });
|
|
84
|
-
// handle the stream
|
|
84
|
+
// handle the stream in the next event queue tick.
|
|
85
85
|
const rpcStream = new RpcStream(packetSink, packetStream);
|
|
86
|
-
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
handler(rpcStream);
|
|
88
|
+
}, 1);
|
|
87
89
|
// process packets
|
|
88
90
|
for await (const packet of packetSink) {
|
|
89
91
|
yield* [packet];
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import Long from 'long';
|
|
2
2
|
import * as _m0 from 'protobufjs/minimal';
|
|
3
|
-
import { RpcStreamInit as RpcStreamInit1, RpcAck as RpcAck2 } from './rpcstream.pb.js';
|
|
4
3
|
export declare const protobufPackage = "rpcstream";
|
|
5
4
|
/** RpcStreamPacket is a packet encapsulating data for a RPC stream. */
|
|
6
5
|
export interface RpcStreamPacket {
|
|
7
6
|
body?: {
|
|
8
7
|
$case: 'init';
|
|
9
|
-
init:
|
|
8
|
+
init: RpcStreamInit;
|
|
10
9
|
} | {
|
|
11
10
|
$case: 'ack';
|
|
12
|
-
ack:
|
|
11
|
+
ack: RpcAck;
|
|
13
12
|
} | {
|
|
14
13
|
$case: 'data';
|
|
15
14
|
data: Uint8Array;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import Long from 'long';
|
|
3
3
|
import * as _m0 from 'protobufjs/minimal';
|
|
4
|
-
import { RpcStreamInit as RpcStreamInit1, RpcAck as RpcAck2, } from './rpcstream.pb.js';
|
|
5
4
|
export const protobufPackage = 'rpcstream';
|
|
6
5
|
function createBaseRpcStreamPacket() {
|
|
7
6
|
return { body: undefined };
|
|
@@ -9,10 +8,10 @@ function createBaseRpcStreamPacket() {
|
|
|
9
8
|
export const RpcStreamPacket = {
|
|
10
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
11
10
|
if (message.body?.$case === 'init') {
|
|
12
|
-
|
|
11
|
+
RpcStreamInit.encode(message.body.init, writer.uint32(10).fork()).ldelim();
|
|
13
12
|
}
|
|
14
13
|
if (message.body?.$case === 'ack') {
|
|
15
|
-
|
|
14
|
+
RpcAck.encode(message.body.ack, writer.uint32(18).fork()).ldelim();
|
|
16
15
|
}
|
|
17
16
|
if (message.body?.$case === 'data') {
|
|
18
17
|
writer.uint32(26).bytes(message.body.data);
|
|
@@ -29,13 +28,13 @@ export const RpcStreamPacket = {
|
|
|
29
28
|
case 1:
|
|
30
29
|
message.body = {
|
|
31
30
|
$case: 'init',
|
|
32
|
-
init:
|
|
31
|
+
init: RpcStreamInit.decode(reader, reader.uint32()),
|
|
33
32
|
};
|
|
34
33
|
break;
|
|
35
34
|
case 2:
|
|
36
35
|
message.body = {
|
|
37
36
|
$case: 'ack',
|
|
38
|
-
ack:
|
|
37
|
+
ack: RpcAck.decode(reader, reader.uint32()),
|
|
39
38
|
};
|
|
40
39
|
break;
|
|
41
40
|
case 3:
|
|
@@ -79,9 +78,9 @@ export const RpcStreamPacket = {
|
|
|
79
78
|
fromJSON(object) {
|
|
80
79
|
return {
|
|
81
80
|
body: isSet(object.init)
|
|
82
|
-
? { $case: 'init', init:
|
|
81
|
+
? { $case: 'init', init: RpcStreamInit.fromJSON(object.init) }
|
|
83
82
|
: isSet(object.ack)
|
|
84
|
-
? { $case: 'ack', ack:
|
|
83
|
+
? { $case: 'ack', ack: RpcAck.fromJSON(object.ack) }
|
|
85
84
|
: isSet(object.data)
|
|
86
85
|
? { $case: 'data', data: bytesFromBase64(object.data) }
|
|
87
86
|
: undefined,
|
|
@@ -91,11 +90,11 @@ export const RpcStreamPacket = {
|
|
|
91
90
|
const obj = {};
|
|
92
91
|
message.body?.$case === 'init' &&
|
|
93
92
|
(obj.init = message.body?.init
|
|
94
|
-
?
|
|
93
|
+
? RpcStreamInit.toJSON(message.body?.init)
|
|
95
94
|
: undefined);
|
|
96
95
|
message.body?.$case === 'ack' &&
|
|
97
96
|
(obj.ack = message.body?.ack
|
|
98
|
-
?
|
|
97
|
+
? RpcAck.toJSON(message.body?.ack)
|
|
99
98
|
: undefined);
|
|
100
99
|
message.body?.$case === 'data' &&
|
|
101
100
|
(obj.data =
|
|
@@ -111,13 +110,13 @@ export const RpcStreamPacket = {
|
|
|
111
110
|
object.body?.init !== null) {
|
|
112
111
|
message.body = {
|
|
113
112
|
$case: 'init',
|
|
114
|
-
init:
|
|
113
|
+
init: RpcStreamInit.fromPartial(object.body.init),
|
|
115
114
|
};
|
|
116
115
|
}
|
|
117
116
|
if (object.body?.$case === 'ack' &&
|
|
118
117
|
object.body?.ack !== undefined &&
|
|
119
118
|
object.body?.ack !== null) {
|
|
120
|
-
message.body = { $case: 'ack', ack:
|
|
119
|
+
message.body = { $case: 'ack', ack: RpcAck.fromPartial(object.body.ack) };
|
|
121
120
|
}
|
|
122
121
|
if (object.body?.$case === 'data' &&
|
|
123
122
|
object.body?.data !== undefined &&
|
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
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
9
|
export { writeToPushable } from './pushable';
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import Long from 'long';
|
|
2
2
|
import * as _m0 from 'protobufjs/minimal';
|
|
3
|
-
import { CallStart as CallStart1, CallData as CallData2 } from './rpcproto.pb.js';
|
|
4
3
|
export declare const protobufPackage = "srpc";
|
|
5
4
|
/** Packet is a message sent over a srpc packet connection. */
|
|
6
5
|
export interface Packet {
|
|
7
6
|
body?: {
|
|
8
7
|
$case: 'callStart';
|
|
9
|
-
callStart:
|
|
8
|
+
callStart: CallStart;
|
|
10
9
|
} | {
|
|
11
10
|
$case: 'callData';
|
|
12
|
-
callData:
|
|
11
|
+
callData: CallData;
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
/** CallStart requests starting a new RPC call. */
|
|
@@ -94,7 +93,7 @@ export declare const Packet: {
|
|
|
94
93
|
rpcMethod?: string | undefined;
|
|
95
94
|
data?: Uint8Array | undefined;
|
|
96
95
|
dataIsZero?: boolean | undefined;
|
|
97
|
-
} & Record<Exclude<keyof I["body"]["callStart"], keyof
|
|
96
|
+
} & Record<Exclude<keyof I["body"]["callStart"], keyof CallStart>, never>) | undefined;
|
|
98
97
|
$case: "callStart";
|
|
99
98
|
} & Record<Exclude<keyof I["body"], "callStart" | "$case">, never>) | ({
|
|
100
99
|
callData?: {
|
|
@@ -116,7 +115,7 @@ export declare const Packet: {
|
|
|
116
115
|
dataIsZero?: boolean | undefined;
|
|
117
116
|
complete?: boolean | undefined;
|
|
118
117
|
error?: string | undefined;
|
|
119
|
-
} & Record<Exclude<keyof I["body"]["callData"], keyof
|
|
118
|
+
} & Record<Exclude<keyof I["body"]["callData"], keyof CallData>, never>) | undefined;
|
|
120
119
|
$case: "callData";
|
|
121
120
|
} & Record<Exclude<keyof I["body"], "callData" | "$case">, never>) | undefined;
|
|
122
121
|
} & Record<Exclude<keyof I, "body">, never>>(object: I): Packet;
|
|
@@ -138,7 +137,7 @@ export declare const CallStart: {
|
|
|
138
137
|
rpcMethod?: string | undefined;
|
|
139
138
|
data?: Uint8Array | undefined;
|
|
140
139
|
dataIsZero?: boolean | undefined;
|
|
141
|
-
} & Record<Exclude<keyof I, keyof
|
|
140
|
+
} & Record<Exclude<keyof I, keyof CallStart>, never>>(object: I): CallStart;
|
|
142
141
|
};
|
|
143
142
|
export declare const CallData: {
|
|
144
143
|
encode(message: CallData, writer?: _m0.Writer): _m0.Writer;
|
|
@@ -157,7 +156,7 @@ export declare const CallData: {
|
|
|
157
156
|
dataIsZero?: boolean | undefined;
|
|
158
157
|
complete?: boolean | undefined;
|
|
159
158
|
error?: string | undefined;
|
|
160
|
-
} & Record<Exclude<keyof I, keyof
|
|
159
|
+
} & Record<Exclude<keyof I, keyof CallData>, never>>(object: I): CallData;
|
|
161
160
|
};
|
|
162
161
|
declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
163
162
|
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
|
package/dist/srpc/rpcproto.pb.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import Long from 'long';
|
|
3
3
|
import * as _m0 from 'protobufjs/minimal';
|
|
4
|
-
import { CallStart as CallStart1, CallData as CallData2, } from './rpcproto.pb.js';
|
|
5
4
|
export const protobufPackage = 'srpc';
|
|
6
5
|
function createBasePacket() {
|
|
7
6
|
return { body: undefined };
|
|
@@ -9,10 +8,10 @@ function createBasePacket() {
|
|
|
9
8
|
export const Packet = {
|
|
10
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
11
10
|
if (message.body?.$case === 'callStart') {
|
|
12
|
-
|
|
11
|
+
CallStart.encode(message.body.callStart, writer.uint32(10).fork()).ldelim();
|
|
13
12
|
}
|
|
14
13
|
if (message.body?.$case === 'callData') {
|
|
15
|
-
|
|
14
|
+
CallData.encode(message.body.callData, writer.uint32(18).fork()).ldelim();
|
|
16
15
|
}
|
|
17
16
|
return writer;
|
|
18
17
|
},
|
|
@@ -26,13 +25,13 @@ export const Packet = {
|
|
|
26
25
|
case 1:
|
|
27
26
|
message.body = {
|
|
28
27
|
$case: 'callStart',
|
|
29
|
-
callStart:
|
|
28
|
+
callStart: CallStart.decode(reader, reader.uint32()),
|
|
30
29
|
};
|
|
31
30
|
break;
|
|
32
31
|
case 2:
|
|
33
32
|
message.body = {
|
|
34
33
|
$case: 'callData',
|
|
35
|
-
callData:
|
|
34
|
+
callData: CallData.decode(reader, reader.uint32()),
|
|
36
35
|
};
|
|
37
36
|
break;
|
|
38
37
|
default:
|
|
@@ -75,10 +74,10 @@ export const Packet = {
|
|
|
75
74
|
body: isSet(object.callStart)
|
|
76
75
|
? {
|
|
77
76
|
$case: 'callStart',
|
|
78
|
-
callStart:
|
|
77
|
+
callStart: CallStart.fromJSON(object.callStart),
|
|
79
78
|
}
|
|
80
79
|
: isSet(object.callData)
|
|
81
|
-
? { $case: 'callData', callData:
|
|
80
|
+
? { $case: 'callData', callData: CallData.fromJSON(object.callData) }
|
|
82
81
|
: undefined,
|
|
83
82
|
};
|
|
84
83
|
},
|
|
@@ -86,11 +85,11 @@ export const Packet = {
|
|
|
86
85
|
const obj = {};
|
|
87
86
|
message.body?.$case === 'callStart' &&
|
|
88
87
|
(obj.callStart = message.body?.callStart
|
|
89
|
-
?
|
|
88
|
+
? CallStart.toJSON(message.body?.callStart)
|
|
90
89
|
: undefined);
|
|
91
90
|
message.body?.$case === 'callData' &&
|
|
92
91
|
(obj.callData = message.body?.callData
|
|
93
|
-
?
|
|
92
|
+
? CallData.toJSON(message.body?.callData)
|
|
94
93
|
: undefined);
|
|
95
94
|
return obj;
|
|
96
95
|
},
|
|
@@ -101,7 +100,7 @@ export const Packet = {
|
|
|
101
100
|
object.body?.callStart !== null) {
|
|
102
101
|
message.body = {
|
|
103
102
|
$case: 'callStart',
|
|
104
|
-
callStart:
|
|
103
|
+
callStart: CallStart.fromPartial(object.body.callStart),
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
106
|
if (object.body?.$case === 'callData' &&
|
|
@@ -109,7 +108,7 @@ export const Packet = {
|
|
|
109
108
|
object.body?.callData !== null) {
|
|
110
109
|
message.body = {
|
|
111
110
|
$case: 'callData',
|
|
112
|
-
callData:
|
|
111
|
+
callData: CallData.fromPartial(object.body.callData),
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
return message;
|
package/dist/srpc/server.d.ts
CHANGED
|
@@ -4,9 +4,11 @@ import { Mux } from './mux.js';
|
|
|
4
4
|
import { ServerRPC } from './server-rpc.js';
|
|
5
5
|
import { Packet } from './rpcproto.pb.js';
|
|
6
6
|
import { StreamHandler } from './conn.js';
|
|
7
|
+
import { RpcStreamHandler } from '../rpcstream/rpcstream.js';
|
|
7
8
|
export declare class Server implements StreamHandler {
|
|
8
9
|
private mux;
|
|
9
10
|
constructor(mux: Mux);
|
|
11
|
+
get rpcStreamHandler(): RpcStreamHandler;
|
|
10
12
|
startRpc(): ServerRPC;
|
|
11
13
|
handleStream(stream: Stream): ServerRPC;
|
|
12
14
|
handleDuplex(stream: Duplex<Uint8Array>): ServerRPC;
|
package/dist/srpc/server.js
CHANGED
|
@@ -6,6 +6,10 @@ export class Server {
|
|
|
6
6
|
constructor(mux) {
|
|
7
7
|
this.mux = mux;
|
|
8
8
|
}
|
|
9
|
+
// rpcStreamHandler implements the RpcStreamHandler interface.
|
|
10
|
+
get rpcStreamHandler() {
|
|
11
|
+
return this.handleDuplex.bind(this);
|
|
12
|
+
}
|
|
9
13
|
// startRpc starts a new server-side RPC.
|
|
10
14
|
// the returned RPC handles incoming Packets.
|
|
11
15
|
startRpc() {
|
package/echo/echo.pb.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import Long from 'long'
|
|
3
|
-
import { EchoMsg as EchoMsg1 } from './echo.pb.js'
|
|
4
3
|
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
|
|
5
4
|
import * as _m0 from 'protobufjs/minimal'
|
|
6
5
|
|
|
@@ -100,13 +99,13 @@ export const EchoMsg = {
|
|
|
100
99
|
/** Echoer service returns the given message. */
|
|
101
100
|
export interface Echoer {
|
|
102
101
|
/** Echo returns the given message. */
|
|
103
|
-
Echo(request:
|
|
102
|
+
Echo(request: EchoMsg): Promise<EchoMsg>
|
|
104
103
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
105
|
-
EchoServerStream(request:
|
|
104
|
+
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>
|
|
106
105
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
107
|
-
EchoClientStream(request: AsyncIterable<
|
|
106
|
+
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>
|
|
108
107
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
109
|
-
EchoBidiStream(request: AsyncIterable<
|
|
108
|
+
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg>
|
|
110
109
|
/** RpcStream opens a nested rpc call stream. */
|
|
111
110
|
RpcStream(
|
|
112
111
|
request: AsyncIterable<RpcStreamPacket>
|
|
@@ -123,40 +122,40 @@ export class EchoerClientImpl implements Echoer {
|
|
|
123
122
|
this.EchoBidiStream = this.EchoBidiStream.bind(this)
|
|
124
123
|
this.RpcStream = this.RpcStream.bind(this)
|
|
125
124
|
}
|
|
126
|
-
Echo(request:
|
|
127
|
-
const data =
|
|
125
|
+
Echo(request: EchoMsg): Promise<EchoMsg> {
|
|
126
|
+
const data = EchoMsg.encode(request).finish()
|
|
128
127
|
const promise = this.rpc.request('echo.Echoer', 'Echo', data)
|
|
129
|
-
return promise.then((data) =>
|
|
128
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
130
129
|
}
|
|
131
130
|
|
|
132
|
-
EchoServerStream(request:
|
|
133
|
-
const data =
|
|
131
|
+
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg> {
|
|
132
|
+
const data = EchoMsg.encode(request).finish()
|
|
134
133
|
const result = this.rpc.serverStreamingRequest(
|
|
135
134
|
'echo.Echoer',
|
|
136
135
|
'EchoServerStream',
|
|
137
136
|
data
|
|
138
137
|
)
|
|
139
|
-
return
|
|
138
|
+
return EchoMsg.decodeTransform(result)
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
EchoClientStream(request: AsyncIterable<
|
|
143
|
-
const data =
|
|
141
|
+
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg> {
|
|
142
|
+
const data = EchoMsg.encodeTransform(request)
|
|
144
143
|
const promise = this.rpc.clientStreamingRequest(
|
|
145
144
|
'echo.Echoer',
|
|
146
145
|
'EchoClientStream',
|
|
147
146
|
data
|
|
148
147
|
)
|
|
149
|
-
return promise.then((data) =>
|
|
148
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
EchoBidiStream(request: AsyncIterable<
|
|
153
|
-
const data =
|
|
151
|
+
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg> {
|
|
152
|
+
const data = EchoMsg.encodeTransform(request)
|
|
154
153
|
const result = this.rpc.bidirectionalStreamingRequest(
|
|
155
154
|
'echo.Echoer',
|
|
156
155
|
'EchoBidiStream',
|
|
157
156
|
data
|
|
158
157
|
)
|
|
159
|
-
return
|
|
158
|
+
return EchoMsg.decodeTransform(result)
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
RpcStream(
|
|
@@ -181,36 +180,36 @@ export const EchoerDefinition = {
|
|
|
181
180
|
/** Echo returns the given message. */
|
|
182
181
|
echo: {
|
|
183
182
|
name: 'Echo',
|
|
184
|
-
requestType:
|
|
183
|
+
requestType: EchoMsg,
|
|
185
184
|
requestStream: false,
|
|
186
|
-
responseType:
|
|
185
|
+
responseType: EchoMsg,
|
|
187
186
|
responseStream: false,
|
|
188
187
|
options: {},
|
|
189
188
|
},
|
|
190
189
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
191
190
|
echoServerStream: {
|
|
192
191
|
name: 'EchoServerStream',
|
|
193
|
-
requestType:
|
|
192
|
+
requestType: EchoMsg,
|
|
194
193
|
requestStream: false,
|
|
195
|
-
responseType:
|
|
194
|
+
responseType: EchoMsg,
|
|
196
195
|
responseStream: true,
|
|
197
196
|
options: {},
|
|
198
197
|
},
|
|
199
198
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
200
199
|
echoClientStream: {
|
|
201
200
|
name: 'EchoClientStream',
|
|
202
|
-
requestType:
|
|
201
|
+
requestType: EchoMsg,
|
|
203
202
|
requestStream: true,
|
|
204
|
-
responseType:
|
|
203
|
+
responseType: EchoMsg,
|
|
205
204
|
responseStream: false,
|
|
206
205
|
options: {},
|
|
207
206
|
},
|
|
208
207
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
209
208
|
echoBidiStream: {
|
|
210
209
|
name: 'EchoBidiStream',
|
|
211
|
-
requestType:
|
|
210
|
+
requestType: EchoMsg,
|
|
212
211
|
requestStream: true,
|
|
213
|
-
responseType:
|
|
212
|
+
responseType: EchoMsg,
|
|
214
213
|
responseStream: true,
|
|
215
214
|
options: {},
|
|
216
215
|
},
|
package/echo/server.ts
CHANGED
|
@@ -4,7 +4,7 @@ import first from 'it-first'
|
|
|
4
4
|
import { Server } from '../srpc/server.js'
|
|
5
5
|
import { writeToPushable } from '../srpc/pushable.js'
|
|
6
6
|
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
|
|
7
|
-
import { handleRpcStream } from '../rpcstream/rpcstream.js'
|
|
7
|
+
import { handleRpcStream, RpcStreamHandler } from '../rpcstream/rpcstream.js'
|
|
8
8
|
|
|
9
9
|
// EchoServer implements the Echoer server.
|
|
10
10
|
export class EchoerServer implements Echoer {
|
|
@@ -52,11 +52,11 @@ export class EchoerServer implements Echoer {
|
|
|
52
52
|
): AsyncIterable<RpcStreamPacket> {
|
|
53
53
|
return handleRpcStream(
|
|
54
54
|
request[Symbol.asyncIterator](),
|
|
55
|
-
async (_componentId: string): Promise<
|
|
55
|
+
async (_componentId: string): Promise<RpcStreamHandler> => {
|
|
56
56
|
if (!this.proxyServer) {
|
|
57
57
|
throw new Error('rpc stream proxy server not set')
|
|
58
58
|
}
|
|
59
|
-
return this.proxyServer
|
|
59
|
+
return this.proxyServer.rpcStreamHandler
|
|
60
60
|
}
|
|
61
61
|
)
|
|
62
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "rimraf ./dist && tsc --project tsconfig.build.json --outDir ./dist/",
|
|
37
37
|
"check": "tsc",
|
|
38
|
-
"deps": "depcheck",
|
|
38
|
+
"deps": "depcheck --ignores 'bufferutil,utf-8-validate'",
|
|
39
39
|
"codegen": "npm run gen",
|
|
40
40
|
"ci": "npm run build && npm run lint:js && npm run lint:go",
|
|
41
41
|
"format": "prettier --write './{srpc,echo,e2e,integration,rpcstream}/**/(*.ts|*.tsx|*.html|*.css)'",
|
|
@@ -58,16 +58,18 @@
|
|
|
58
58
|
"singleQuote": true
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^5.30.
|
|
62
|
-
"@typescript-eslint/parser": "^5.30.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.30.3",
|
|
62
|
+
"@typescript-eslint/parser": "^5.30.3",
|
|
63
|
+
"bufferutil": "^4.0.6",
|
|
63
64
|
"depcheck": "^1.4.3",
|
|
64
|
-
"esbuild": "^0.14.
|
|
65
|
+
"esbuild": "^0.14.48",
|
|
65
66
|
"eslint": "^8.18.0",
|
|
66
67
|
"eslint-config-prettier": "^8.5.0",
|
|
67
68
|
"prettier": "^2.7.1",
|
|
68
69
|
"rimraf": "^3.0.2",
|
|
69
|
-
"ts-proto": "^1.
|
|
70
|
-
"typescript": "^4.7.4"
|
|
70
|
+
"ts-proto": "^1.116.1",
|
|
71
|
+
"typescript": "^4.7.4",
|
|
72
|
+
"utf-8-validate": "^5.0.9"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
75
|
"@libp2p/interface-connection": "^2.1.1",
|