starpc 0.10.9 → 0.11.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 +5 -5
- package/dist/echo/echo.pb.js +20 -20
- package/dist/rpcstream/rpcstream.pb.d.ts +7 -7
- package/dist/rpcstream/rpcstream.pb.js +64 -39
- package/dist/srpc/handler.d.ts +1 -1
- package/dist/srpc/handler.js +6 -2
- package/dist/srpc/rpcproto.pb.d.ts +6 -6
- package/dist/srpc/rpcproto.pb.js +75 -38
- package/echo/echo.pb.ts +144 -88
- package/echo/echo_srpc.pb.go +17 -10
- package/package.json +1 -1
- package/srpc/conn.ts +3 -1
- package/srpc/definition.ts +1 -0
- package/srpc/handler.ts +11 -2
- package/srpc/rpcproto.pb.ts +273 -183
- package/srpc/server.ts +1 -3
package/dist/srpc/rpcproto.pb.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import Long from
|
|
3
|
-
import _m0 from
|
|
4
|
-
export const protobufPackage =
|
|
2
|
+
import Long from 'long';
|
|
3
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
4
|
+
export const protobufPackage = 'srpc';
|
|
5
5
|
function createBasePacket() {
|
|
6
6
|
return { body: undefined };
|
|
7
7
|
}
|
|
8
8
|
export const Packet = {
|
|
9
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
10
|
-
if (message.body?.$case ===
|
|
10
|
+
if (message.body?.$case === 'callStart') {
|
|
11
11
|
CallStart.encode(message.body.callStart, writer.uint32(10).fork()).ldelim();
|
|
12
12
|
}
|
|
13
|
-
if (message.body?.$case ===
|
|
13
|
+
if (message.body?.$case === 'callData') {
|
|
14
14
|
CallData.encode(message.body.callData, writer.uint32(18).fork()).ldelim();
|
|
15
15
|
}
|
|
16
16
|
return writer;
|
|
@@ -23,10 +23,16 @@ export const Packet = {
|
|
|
23
23
|
const tag = reader.uint32();
|
|
24
24
|
switch (tag >>> 3) {
|
|
25
25
|
case 1:
|
|
26
|
-
message.body = {
|
|
26
|
+
message.body = {
|
|
27
|
+
$case: 'callStart',
|
|
28
|
+
callStart: CallStart.decode(reader, reader.uint32()),
|
|
29
|
+
};
|
|
27
30
|
break;
|
|
28
31
|
case 2:
|
|
29
|
-
message.body = {
|
|
32
|
+
message.body = {
|
|
33
|
+
$case: 'callData',
|
|
34
|
+
callData: CallData.decode(reader, reader.uint32()),
|
|
35
|
+
};
|
|
30
36
|
break;
|
|
31
37
|
default:
|
|
32
38
|
reader.skipType(tag & 7);
|
|
@@ -66,40 +72,62 @@ export const Packet = {
|
|
|
66
72
|
fromJSON(object) {
|
|
67
73
|
return {
|
|
68
74
|
body: isSet(object.callStart)
|
|
69
|
-
? {
|
|
75
|
+
? {
|
|
76
|
+
$case: 'callStart',
|
|
77
|
+
callStart: CallStart.fromJSON(object.callStart),
|
|
78
|
+
}
|
|
70
79
|
: isSet(object.callData)
|
|
71
|
-
? { $case:
|
|
80
|
+
? { $case: 'callData', callData: CallData.fromJSON(object.callData) }
|
|
72
81
|
: undefined,
|
|
73
82
|
};
|
|
74
83
|
},
|
|
75
84
|
toJSON(message) {
|
|
76
85
|
const obj = {};
|
|
77
|
-
message.body?.$case ===
|
|
78
|
-
(obj.callStart = message.body?.callStart
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
message.body?.$case === 'callStart' &&
|
|
87
|
+
(obj.callStart = message.body?.callStart
|
|
88
|
+
? CallStart.toJSON(message.body?.callStart)
|
|
89
|
+
: undefined);
|
|
90
|
+
message.body?.$case === 'callData' &&
|
|
91
|
+
(obj.callData = message.body?.callData
|
|
92
|
+
? CallData.toJSON(message.body?.callData)
|
|
93
|
+
: undefined);
|
|
81
94
|
return obj;
|
|
82
95
|
},
|
|
83
96
|
fromPartial(object) {
|
|
84
97
|
const message = createBasePacket();
|
|
85
|
-
if (object.body?.$case ===
|
|
86
|
-
|
|
98
|
+
if (object.body?.$case === 'callStart' &&
|
|
99
|
+
object.body?.callStart !== undefined &&
|
|
100
|
+
object.body?.callStart !== null) {
|
|
101
|
+
message.body = {
|
|
102
|
+
$case: 'callStart',
|
|
103
|
+
callStart: CallStart.fromPartial(object.body.callStart),
|
|
104
|
+
};
|
|
87
105
|
}
|
|
88
|
-
if (object.body?.$case ===
|
|
89
|
-
|
|
106
|
+
if (object.body?.$case === 'callData' &&
|
|
107
|
+
object.body?.callData !== undefined &&
|
|
108
|
+
object.body?.callData !== null) {
|
|
109
|
+
message.body = {
|
|
110
|
+
$case: 'callData',
|
|
111
|
+
callData: CallData.fromPartial(object.body.callData),
|
|
112
|
+
};
|
|
90
113
|
}
|
|
91
114
|
return message;
|
|
92
115
|
},
|
|
93
116
|
};
|
|
94
117
|
function createBaseCallStart() {
|
|
95
|
-
return {
|
|
118
|
+
return {
|
|
119
|
+
rpcService: '',
|
|
120
|
+
rpcMethod: '',
|
|
121
|
+
data: new Uint8Array(),
|
|
122
|
+
dataIsZero: false,
|
|
123
|
+
};
|
|
96
124
|
}
|
|
97
125
|
export const CallStart = {
|
|
98
126
|
encode(message, writer = _m0.Writer.create()) {
|
|
99
|
-
if (message.rpcService !==
|
|
127
|
+
if (message.rpcService !== '') {
|
|
100
128
|
writer.uint32(10).string(message.rpcService);
|
|
101
129
|
}
|
|
102
|
-
if (message.rpcMethod !==
|
|
130
|
+
if (message.rpcMethod !== '') {
|
|
103
131
|
writer.uint32(18).string(message.rpcMethod);
|
|
104
132
|
}
|
|
105
133
|
if (message.data.length !== 0) {
|
|
@@ -166,9 +194,11 @@ export const CallStart = {
|
|
|
166
194
|
},
|
|
167
195
|
fromJSON(object) {
|
|
168
196
|
return {
|
|
169
|
-
rpcService: isSet(object.rpcService) ? String(object.rpcService) :
|
|
170
|
-
rpcMethod: isSet(object.rpcMethod) ? String(object.rpcMethod) :
|
|
171
|
-
data: isSet(object.data)
|
|
197
|
+
rpcService: isSet(object.rpcService) ? String(object.rpcService) : '',
|
|
198
|
+
rpcMethod: isSet(object.rpcMethod) ? String(object.rpcMethod) : '',
|
|
199
|
+
data: isSet(object.data)
|
|
200
|
+
? bytesFromBase64(object.data)
|
|
201
|
+
: new Uint8Array(),
|
|
172
202
|
dataIsZero: isSet(object.dataIsZero) ? Boolean(object.dataIsZero) : false,
|
|
173
203
|
};
|
|
174
204
|
},
|
|
@@ -183,15 +213,20 @@ export const CallStart = {
|
|
|
183
213
|
},
|
|
184
214
|
fromPartial(object) {
|
|
185
215
|
const message = createBaseCallStart();
|
|
186
|
-
message.rpcService = object.rpcService ??
|
|
187
|
-
message.rpcMethod = object.rpcMethod ??
|
|
216
|
+
message.rpcService = object.rpcService ?? '';
|
|
217
|
+
message.rpcMethod = object.rpcMethod ?? '';
|
|
188
218
|
message.data = object.data ?? new Uint8Array();
|
|
189
219
|
message.dataIsZero = object.dataIsZero ?? false;
|
|
190
220
|
return message;
|
|
191
221
|
},
|
|
192
222
|
};
|
|
193
223
|
function createBaseCallData() {
|
|
194
|
-
return {
|
|
224
|
+
return {
|
|
225
|
+
data: new Uint8Array(),
|
|
226
|
+
dataIsZero: false,
|
|
227
|
+
complete: false,
|
|
228
|
+
error: '',
|
|
229
|
+
};
|
|
195
230
|
}
|
|
196
231
|
export const CallData = {
|
|
197
232
|
encode(message, writer = _m0.Writer.create()) {
|
|
@@ -204,7 +239,7 @@ export const CallData = {
|
|
|
204
239
|
if (message.complete === true) {
|
|
205
240
|
writer.uint32(24).bool(message.complete);
|
|
206
241
|
}
|
|
207
|
-
if (message.error !==
|
|
242
|
+
if (message.error !== '') {
|
|
208
243
|
writer.uint32(34).string(message.error);
|
|
209
244
|
}
|
|
210
245
|
return writer;
|
|
@@ -265,10 +300,12 @@ export const CallData = {
|
|
|
265
300
|
},
|
|
266
301
|
fromJSON(object) {
|
|
267
302
|
return {
|
|
268
|
-
data: isSet(object.data)
|
|
303
|
+
data: isSet(object.data)
|
|
304
|
+
? bytesFromBase64(object.data)
|
|
305
|
+
: new Uint8Array(),
|
|
269
306
|
dataIsZero: isSet(object.dataIsZero) ? Boolean(object.dataIsZero) : false,
|
|
270
307
|
complete: isSet(object.complete) ? Boolean(object.complete) : false,
|
|
271
|
-
error: isSet(object.error) ? String(object.error) :
|
|
308
|
+
error: isSet(object.error) ? String(object.error) : '',
|
|
272
309
|
};
|
|
273
310
|
},
|
|
274
311
|
toJSON(message) {
|
|
@@ -285,28 +322,28 @@ export const CallData = {
|
|
|
285
322
|
message.data = object.data ?? new Uint8Array();
|
|
286
323
|
message.dataIsZero = object.dataIsZero ?? false;
|
|
287
324
|
message.complete = object.complete ?? false;
|
|
288
|
-
message.error = object.error ??
|
|
325
|
+
message.error = object.error ?? '';
|
|
289
326
|
return message;
|
|
290
327
|
},
|
|
291
328
|
};
|
|
292
329
|
var globalThis = (() => {
|
|
293
|
-
if (typeof globalThis !==
|
|
330
|
+
if (typeof globalThis !== 'undefined') {
|
|
294
331
|
return globalThis;
|
|
295
332
|
}
|
|
296
|
-
if (typeof self !==
|
|
333
|
+
if (typeof self !== 'undefined') {
|
|
297
334
|
return self;
|
|
298
335
|
}
|
|
299
|
-
if (typeof window !==
|
|
336
|
+
if (typeof window !== 'undefined') {
|
|
300
337
|
return window;
|
|
301
338
|
}
|
|
302
|
-
if (typeof global !==
|
|
339
|
+
if (typeof global !== 'undefined') {
|
|
303
340
|
return global;
|
|
304
341
|
}
|
|
305
|
-
throw
|
|
342
|
+
throw 'Unable to locate global object';
|
|
306
343
|
})();
|
|
307
344
|
function bytesFromBase64(b64) {
|
|
308
345
|
if (globalThis.Buffer) {
|
|
309
|
-
return Uint8Array.from(globalThis.Buffer.from(b64,
|
|
346
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
|
|
310
347
|
}
|
|
311
348
|
else {
|
|
312
349
|
const bin = globalThis.atob(b64);
|
|
@@ -319,14 +356,14 @@ function bytesFromBase64(b64) {
|
|
|
319
356
|
}
|
|
320
357
|
function base64FromBytes(arr) {
|
|
321
358
|
if (globalThis.Buffer) {
|
|
322
|
-
return globalThis.Buffer.from(arr).toString(
|
|
359
|
+
return globalThis.Buffer.from(arr).toString('base64');
|
|
323
360
|
}
|
|
324
361
|
else {
|
|
325
362
|
const bin = [];
|
|
326
363
|
arr.forEach((byte) => {
|
|
327
364
|
bin.push(String.fromCharCode(byte));
|
|
328
365
|
});
|
|
329
|
-
return globalThis.btoa(bin.join(
|
|
366
|
+
return globalThis.btoa(bin.join(''));
|
|
330
367
|
}
|
|
331
368
|
}
|
|
332
369
|
if (_m0.util.Long !== Long) {
|
package/echo/echo.pb.ts
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import Long from
|
|
3
|
-
import _m0 from
|
|
4
|
-
import { RpcStreamPacket } from
|
|
2
|
+
import Long from 'long'
|
|
3
|
+
import _m0 from 'protobufjs/minimal.js'
|
|
4
|
+
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
|
|
5
5
|
|
|
6
|
-
export const protobufPackage =
|
|
6
|
+
export const protobufPackage = 'echo'
|
|
7
7
|
|
|
8
8
|
/** EchoMsg is the message body for Echo. */
|
|
9
9
|
export interface EchoMsg {
|
|
10
|
-
body: string
|
|
10
|
+
body: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function createBaseEchoMsg(): EchoMsg {
|
|
14
|
-
return { body:
|
|
14
|
+
return { body: '' }
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const EchoMsg = {
|
|
18
|
-
encode(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
encode(
|
|
19
|
+
message: EchoMsg,
|
|
20
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
21
|
+
): _m0.Writer {
|
|
22
|
+
if (message.body !== '') {
|
|
23
|
+
writer.uint32(10).string(message.body)
|
|
21
24
|
}
|
|
22
|
-
return writer
|
|
25
|
+
return writer
|
|
23
26
|
},
|
|
24
27
|
|
|
25
28
|
decode(input: _m0.Reader | Uint8Array, length?: number): EchoMsg {
|
|
26
|
-
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input)
|
|
27
|
-
let end = length === undefined ? reader.len : reader.pos + length
|
|
28
|
-
const message = createBaseEchoMsg()
|
|
29
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input)
|
|
30
|
+
let end = length === undefined ? reader.len : reader.pos + length
|
|
31
|
+
const message = createBaseEchoMsg()
|
|
29
32
|
while (reader.pos < end) {
|
|
30
|
-
const tag = reader.uint32()
|
|
33
|
+
const tag = reader.uint32()
|
|
31
34
|
switch (tag >>> 3) {
|
|
32
35
|
case 1:
|
|
33
|
-
message.body = reader.string()
|
|
34
|
-
break
|
|
36
|
+
message.body = reader.string()
|
|
37
|
+
break
|
|
35
38
|
default:
|
|
36
|
-
reader.skipType(tag & 7)
|
|
37
|
-
break
|
|
39
|
+
reader.skipType(tag & 7)
|
|
40
|
+
break
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
return message
|
|
43
|
+
return message
|
|
41
44
|
},
|
|
42
45
|
|
|
43
46
|
// encodeTransform encodes a source of message objects.
|
|
44
47
|
// Transform<EchoMsg, Uint8Array>
|
|
45
48
|
async *encodeTransform(
|
|
46
|
-
source: AsyncIterable<EchoMsg | EchoMsg[]> | Iterable<EchoMsg | EchoMsg[]
|
|
49
|
+
source: AsyncIterable<EchoMsg | EchoMsg[]> | Iterable<EchoMsg | EchoMsg[]>
|
|
47
50
|
): AsyncIterable<Uint8Array> {
|
|
48
51
|
for await (const pkt of source) {
|
|
49
52
|
if (Array.isArray(pkt)) {
|
|
50
53
|
for (const p of pkt) {
|
|
51
|
-
yield* [EchoMsg.encode(p).finish()]
|
|
54
|
+
yield* [EchoMsg.encode(p).finish()]
|
|
52
55
|
}
|
|
53
56
|
} else {
|
|
54
|
-
yield* [EchoMsg.encode(pkt).finish()]
|
|
57
|
+
yield* [EchoMsg.encode(pkt).finish()]
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
},
|
|
@@ -59,100 +62,122 @@ export const EchoMsg = {
|
|
|
59
62
|
// decodeTransform decodes a source of encoded messages.
|
|
60
63
|
// Transform<Uint8Array, EchoMsg>
|
|
61
64
|
async *decodeTransform(
|
|
62
|
-
source:
|
|
65
|
+
source:
|
|
66
|
+
| AsyncIterable<Uint8Array | Uint8Array[]>
|
|
67
|
+
| Iterable<Uint8Array | Uint8Array[]>
|
|
63
68
|
): AsyncIterable<EchoMsg> {
|
|
64
69
|
for await (const pkt of source) {
|
|
65
70
|
if (Array.isArray(pkt)) {
|
|
66
71
|
for (const p of pkt) {
|
|
67
|
-
yield* [EchoMsg.decode(p)]
|
|
72
|
+
yield* [EchoMsg.decode(p)]
|
|
68
73
|
}
|
|
69
74
|
} else {
|
|
70
|
-
yield* [EchoMsg.decode(pkt)]
|
|
75
|
+
yield* [EchoMsg.decode(pkt)]
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
},
|
|
74
79
|
|
|
75
80
|
fromJSON(object: any): EchoMsg {
|
|
76
|
-
return { body: isSet(object.body) ? String(object.body) :
|
|
81
|
+
return { body: isSet(object.body) ? String(object.body) : '' }
|
|
77
82
|
},
|
|
78
83
|
|
|
79
84
|
toJSON(message: EchoMsg): unknown {
|
|
80
|
-
const obj: any = {}
|
|
81
|
-
message.body !== undefined && (obj.body = message.body)
|
|
82
|
-
return obj
|
|
85
|
+
const obj: any = {}
|
|
86
|
+
message.body !== undefined && (obj.body = message.body)
|
|
87
|
+
return obj
|
|
83
88
|
},
|
|
84
89
|
|
|
85
90
|
fromPartial<I extends Exact<DeepPartial<EchoMsg>, I>>(object: I): EchoMsg {
|
|
86
|
-
const message = createBaseEchoMsg()
|
|
87
|
-
message.body = object.body ??
|
|
88
|
-
return message
|
|
91
|
+
const message = createBaseEchoMsg()
|
|
92
|
+
message.body = object.body ?? ''
|
|
93
|
+
return message
|
|
89
94
|
},
|
|
90
|
-
}
|
|
95
|
+
}
|
|
91
96
|
|
|
92
97
|
/** Echoer service returns the given message. */
|
|
93
98
|
export interface Echoer {
|
|
94
99
|
/** Echo returns the given message. */
|
|
95
|
-
Echo(request: EchoMsg): Promise<EchoMsg
|
|
100
|
+
Echo(request: EchoMsg): Promise<EchoMsg>
|
|
96
101
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
97
|
-
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg
|
|
102
|
+
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>
|
|
98
103
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
99
|
-
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg
|
|
104
|
+
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>
|
|
100
105
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
101
|
-
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg
|
|
106
|
+
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg>
|
|
102
107
|
/** RpcStream opens a nested rpc call stream. */
|
|
103
|
-
RpcStream(
|
|
108
|
+
RpcStream(
|
|
109
|
+
request: AsyncIterable<RpcStreamPacket>
|
|
110
|
+
): AsyncIterable<RpcStreamPacket>
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
export class EchoerClientImpl implements Echoer {
|
|
107
|
-
private readonly rpc: Rpc
|
|
114
|
+
private readonly rpc: Rpc
|
|
108
115
|
constructor(rpc: Rpc) {
|
|
109
|
-
this.rpc = rpc
|
|
110
|
-
this.Echo = this.Echo.bind(this)
|
|
111
|
-
this.EchoServerStream = this.EchoServerStream.bind(this)
|
|
112
|
-
this.EchoClientStream = this.EchoClientStream.bind(this)
|
|
113
|
-
this.EchoBidiStream = this.EchoBidiStream.bind(this)
|
|
114
|
-
this.RpcStream = this.RpcStream.bind(this)
|
|
116
|
+
this.rpc = rpc
|
|
117
|
+
this.Echo = this.Echo.bind(this)
|
|
118
|
+
this.EchoServerStream = this.EchoServerStream.bind(this)
|
|
119
|
+
this.EchoClientStream = this.EchoClientStream.bind(this)
|
|
120
|
+
this.EchoBidiStream = this.EchoBidiStream.bind(this)
|
|
121
|
+
this.RpcStream = this.RpcStream.bind(this)
|
|
115
122
|
}
|
|
116
123
|
Echo(request: EchoMsg): Promise<EchoMsg> {
|
|
117
|
-
const data = EchoMsg.encode(request).finish()
|
|
118
|
-
const promise = this.rpc.request(
|
|
119
|
-
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
124
|
+
const data = EchoMsg.encode(request).finish()
|
|
125
|
+
const promise = this.rpc.request('echo.Echoer', 'Echo', data)
|
|
126
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg> {
|
|
123
|
-
const data = EchoMsg.encode(request).finish()
|
|
124
|
-
const result = this.rpc.serverStreamingRequest(
|
|
125
|
-
|
|
130
|
+
const data = EchoMsg.encode(request).finish()
|
|
131
|
+
const result = this.rpc.serverStreamingRequest(
|
|
132
|
+
'echo.Echoer',
|
|
133
|
+
'EchoServerStream',
|
|
134
|
+
data
|
|
135
|
+
)
|
|
136
|
+
return EchoMsg.decodeTransform(result)
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg> {
|
|
129
|
-
const data = EchoMsg.encodeTransform(request)
|
|
130
|
-
const promise = this.rpc.clientStreamingRequest(
|
|
131
|
-
|
|
140
|
+
const data = EchoMsg.encodeTransform(request)
|
|
141
|
+
const promise = this.rpc.clientStreamingRequest(
|
|
142
|
+
'echo.Echoer',
|
|
143
|
+
'EchoClientStream',
|
|
144
|
+
data
|
|
145
|
+
)
|
|
146
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
132
147
|
}
|
|
133
148
|
|
|
134
149
|
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg> {
|
|
135
|
-
const data = EchoMsg.encodeTransform(request)
|
|
136
|
-
const result = this.rpc.bidirectionalStreamingRequest(
|
|
137
|
-
|
|
150
|
+
const data = EchoMsg.encodeTransform(request)
|
|
151
|
+
const result = this.rpc.bidirectionalStreamingRequest(
|
|
152
|
+
'echo.Echoer',
|
|
153
|
+
'EchoBidiStream',
|
|
154
|
+
data
|
|
155
|
+
)
|
|
156
|
+
return EchoMsg.decodeTransform(result)
|
|
138
157
|
}
|
|
139
158
|
|
|
140
|
-
RpcStream(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
159
|
+
RpcStream(
|
|
160
|
+
request: AsyncIterable<RpcStreamPacket>
|
|
161
|
+
): AsyncIterable<RpcStreamPacket> {
|
|
162
|
+
const data = RpcStreamPacket.encodeTransform(request)
|
|
163
|
+
const result = this.rpc.bidirectionalStreamingRequest(
|
|
164
|
+
'echo.Echoer',
|
|
165
|
+
'RpcStream',
|
|
166
|
+
data
|
|
167
|
+
)
|
|
168
|
+
return RpcStreamPacket.decodeTransform(result)
|
|
144
169
|
}
|
|
145
170
|
}
|
|
146
171
|
|
|
147
172
|
/** Echoer service returns the given message. */
|
|
148
|
-
export type EchoerDefinition = typeof EchoerDefinition
|
|
173
|
+
export type EchoerDefinition = typeof EchoerDefinition
|
|
149
174
|
export const EchoerDefinition = {
|
|
150
|
-
name:
|
|
151
|
-
fullName:
|
|
175
|
+
name: 'Echoer',
|
|
176
|
+
fullName: 'echo.Echoer',
|
|
152
177
|
methods: {
|
|
153
178
|
/** Echo returns the given message. */
|
|
154
179
|
echo: {
|
|
155
|
-
name:
|
|
180
|
+
name: 'Echo',
|
|
156
181
|
requestType: EchoMsg,
|
|
157
182
|
requestStream: false,
|
|
158
183
|
responseType: EchoMsg,
|
|
@@ -161,7 +186,7 @@ export const EchoerDefinition = {
|
|
|
161
186
|
},
|
|
162
187
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
163
188
|
echoServerStream: {
|
|
164
|
-
name:
|
|
189
|
+
name: 'EchoServerStream',
|
|
165
190
|
requestType: EchoMsg,
|
|
166
191
|
requestStream: false,
|
|
167
192
|
responseType: EchoMsg,
|
|
@@ -170,7 +195,7 @@ export const EchoerDefinition = {
|
|
|
170
195
|
},
|
|
171
196
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
172
197
|
echoClientStream: {
|
|
173
|
-
name:
|
|
198
|
+
name: 'EchoClientStream',
|
|
174
199
|
requestType: EchoMsg,
|
|
175
200
|
requestStream: true,
|
|
176
201
|
responseType: EchoMsg,
|
|
@@ -179,7 +204,7 @@ export const EchoerDefinition = {
|
|
|
179
204
|
},
|
|
180
205
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
181
206
|
echoBidiStream: {
|
|
182
|
-
name:
|
|
207
|
+
name: 'EchoBidiStream',
|
|
183
208
|
requestType: EchoMsg,
|
|
184
209
|
requestStream: true,
|
|
185
210
|
responseType: EchoMsg,
|
|
@@ -188,7 +213,7 @@ export const EchoerDefinition = {
|
|
|
188
213
|
},
|
|
189
214
|
/** RpcStream opens a nested rpc call stream. */
|
|
190
215
|
rpcStream: {
|
|
191
|
-
name:
|
|
216
|
+
name: 'RpcStream',
|
|
192
217
|
requestType: RpcStreamPacket,
|
|
193
218
|
requestStream: true,
|
|
194
219
|
responseType: RpcStreamPacket,
|
|
@@ -196,37 +221,68 @@ export const EchoerDefinition = {
|
|
|
196
221
|
options: {},
|
|
197
222
|
},
|
|
198
223
|
},
|
|
199
|
-
} as const
|
|
224
|
+
} as const
|
|
200
225
|
|
|
201
226
|
interface Rpc {
|
|
202
|
-
request(
|
|
203
|
-
|
|
204
|
-
|
|
227
|
+
request(
|
|
228
|
+
service: string,
|
|
229
|
+
method: string,
|
|
230
|
+
data: Uint8Array
|
|
231
|
+
): Promise<Uint8Array>
|
|
232
|
+
clientStreamingRequest(
|
|
233
|
+
service: string,
|
|
234
|
+
method: string,
|
|
235
|
+
data: AsyncIterable<Uint8Array>
|
|
236
|
+
): Promise<Uint8Array>
|
|
237
|
+
serverStreamingRequest(
|
|
238
|
+
service: string,
|
|
239
|
+
method: string,
|
|
240
|
+
data: Uint8Array
|
|
241
|
+
): AsyncIterable<Uint8Array>
|
|
205
242
|
bidirectionalStreamingRequest(
|
|
206
243
|
service: string,
|
|
207
244
|
method: string,
|
|
208
|
-
data: AsyncIterable<Uint8Array
|
|
209
|
-
): AsyncIterable<Uint8Array
|
|
245
|
+
data: AsyncIterable<Uint8Array>
|
|
246
|
+
): AsyncIterable<Uint8Array>
|
|
210
247
|
}
|
|
211
248
|
|
|
212
|
-
type Builtin =
|
|
249
|
+
type Builtin =
|
|
250
|
+
| Date
|
|
251
|
+
| Function
|
|
252
|
+
| Uint8Array
|
|
253
|
+
| string
|
|
254
|
+
| number
|
|
255
|
+
| boolean
|
|
256
|
+
| undefined
|
|
213
257
|
|
|
214
|
-
export type DeepPartial<T> = T extends Builtin
|
|
215
|
-
|
|
216
|
-
: T extends
|
|
217
|
-
|
|
218
|
-
: T extends
|
|
219
|
-
|
|
258
|
+
export type DeepPartial<T> = T extends Builtin
|
|
259
|
+
? T
|
|
260
|
+
: T extends Long
|
|
261
|
+
? string | number | Long
|
|
262
|
+
: T extends Array<infer U>
|
|
263
|
+
? Array<DeepPartial<U>>
|
|
264
|
+
: T extends ReadonlyArray<infer U>
|
|
265
|
+
? ReadonlyArray<DeepPartial<U>>
|
|
266
|
+
: T extends { $case: string }
|
|
267
|
+
? { [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]> } & {
|
|
268
|
+
$case: T['$case']
|
|
269
|
+
}
|
|
270
|
+
: T extends {}
|
|
271
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
272
|
+
: Partial<T>
|
|
220
273
|
|
|
221
|
-
type KeysOfUnion<T> = T extends T ? keyof T : never
|
|
222
|
-
export type Exact<P, I extends P> = P extends Builtin
|
|
223
|
-
|
|
274
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never
|
|
275
|
+
export type Exact<P, I extends P> = P extends Builtin
|
|
276
|
+
? P
|
|
277
|
+
: P & { [K in keyof P]: Exact<P[K], I[K]> } & {
|
|
278
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never
|
|
279
|
+
}
|
|
224
280
|
|
|
225
281
|
if (_m0.util.Long !== Long) {
|
|
226
|
-
_m0.util.Long = Long as any
|
|
227
|
-
_m0.configure()
|
|
282
|
+
_m0.util.Long = Long as any
|
|
283
|
+
_m0.configure()
|
|
228
284
|
}
|
|
229
285
|
|
|
230
286
|
function isSet(value: any): boolean {
|
|
231
|
-
return value !== null && value !== undefined
|
|
287
|
+
return value !== null && value !== undefined
|
|
232
288
|
}
|
package/echo/echo_srpc.pb.go
CHANGED
|
@@ -220,10 +220,25 @@ func (s *SRPCEchoerUnimplementedServer) RpcStream(SRPCEchoer_RpcStreamStream) er
|
|
|
220
220
|
const SRPCEchoerServiceID = "echo.Echoer"
|
|
221
221
|
|
|
222
222
|
type SRPCEchoerHandler struct {
|
|
223
|
-
|
|
223
|
+
serviceID string
|
|
224
|
+
impl SRPCEchoerServer
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
|
|
227
|
+
// NewSRPCEchoerHandler constructs a new RPC handler.
|
|
228
|
+
// serviceID: if empty, uses default: echo.Echoer
|
|
229
|
+
func NewSRPCEchoerHandler(impl SRPCEchoerServer, serviceID string) srpc.Handler {
|
|
230
|
+
if serviceID == "" {
|
|
231
|
+
serviceID = SRPCEchoerServiceID
|
|
232
|
+
}
|
|
233
|
+
return &SRPCEchoerHandler{impl: impl, serviceID: serviceID}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// SRPCRegisterEchoer registers the implementation with the mux.
|
|
237
|
+
// Uses the default serviceID: echo.Echoer
|
|
238
|
+
func SRPCRegisterEchoer(mux srpc.Mux, impl SRPCEchoerServer) error {
|
|
239
|
+
return mux.Register(NewSRPCEchoerHandler(impl, ""))
|
|
240
|
+
}
|
|
241
|
+
func (d *SRPCEchoerHandler) GetServiceID() string { return d.serviceID }
|
|
227
242
|
|
|
228
243
|
func (SRPCEchoerHandler) GetMethodIDs() []string {
|
|
229
244
|
return []string{
|
|
@@ -295,14 +310,6 @@ func (SRPCEchoerHandler) InvokeMethod_RpcStream(impl SRPCEchoerServer, strm srpc
|
|
|
295
310
|
return impl.RpcStream(clientStrm)
|
|
296
311
|
}
|
|
297
312
|
|
|
298
|
-
func NewSRPCEchoerHandler(impl SRPCEchoerServer) srpc.Handler {
|
|
299
|
-
return &SRPCEchoerHandler{impl: impl}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
func SRPCRegisterEchoer(mux srpc.Mux, impl SRPCEchoerServer) error {
|
|
303
|
-
return mux.Register(&SRPCEchoerHandler{impl: impl})
|
|
304
|
-
}
|
|
305
|
-
|
|
306
313
|
type SRPCEchoer_EchoStream interface {
|
|
307
314
|
srpc.Stream
|
|
308
315
|
SendAndClose(*EchoMsg) error
|
package/package.json
CHANGED
package/srpc/conn.ts
CHANGED
|
@@ -29,7 +29,9 @@ export interface StreamHandler {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// streamToSRPCStream converts a Stream to a SRPCStream.
|
|
32
|
-
export function streamToSRPCStream(
|
|
32
|
+
export function streamToSRPCStream(
|
|
33
|
+
stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>
|
|
34
|
+
): SRPCStream {
|
|
33
35
|
return {
|
|
34
36
|
source: pipe(stream, combineUint8ArrayListTransform()),
|
|
35
37
|
sink: stream.sink,
|
package/srpc/definition.ts
CHANGED