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.
@@ -1,16 +1,16 @@
1
1
  /* eslint-disable */
2
- import Long from "long";
3
- import _m0 from "protobufjs/minimal.js";
4
- export const protobufPackage = "srpc";
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 === "callStart") {
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 === "callData") {
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 = { $case: "callStart", callStart: CallStart.decode(reader, reader.uint32()) };
26
+ message.body = {
27
+ $case: 'callStart',
28
+ callStart: CallStart.decode(reader, reader.uint32()),
29
+ };
27
30
  break;
28
31
  case 2:
29
- message.body = { $case: "callData", callData: CallData.decode(reader, reader.uint32()) };
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
- ? { $case: "callStart", callStart: CallStart.fromJSON(object.callStart) }
75
+ ? {
76
+ $case: 'callStart',
77
+ callStart: CallStart.fromJSON(object.callStart),
78
+ }
70
79
  : isSet(object.callData)
71
- ? { $case: "callData", callData: CallData.fromJSON(object.callData) }
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 === "callStart" &&
78
- (obj.callStart = message.body?.callStart ? CallStart.toJSON(message.body?.callStart) : undefined);
79
- message.body?.$case === "callData" &&
80
- (obj.callData = message.body?.callData ? CallData.toJSON(message.body?.callData) : undefined);
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 === "callStart" && object.body?.callStart !== undefined && object.body?.callStart !== null) {
86
- message.body = { $case: "callStart", callStart: CallStart.fromPartial(object.body.callStart) };
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 === "callData" && object.body?.callData !== undefined && object.body?.callData !== null) {
89
- message.body = { $case: "callData", callData: CallData.fromPartial(object.body.callData) };
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 { rpcService: "", rpcMethod: "", data: new Uint8Array(), dataIsZero: false };
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) ? bytesFromBase64(object.data) : new Uint8Array(),
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 { data: new Uint8Array(), dataIsZero: false, complete: false, error: "" };
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) ? bytesFromBase64(object.data) : new Uint8Array(),
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 !== "undefined") {
330
+ if (typeof globalThis !== 'undefined') {
294
331
  return globalThis;
295
332
  }
296
- if (typeof self !== "undefined") {
333
+ if (typeof self !== 'undefined') {
297
334
  return self;
298
335
  }
299
- if (typeof window !== "undefined") {
336
+ if (typeof window !== 'undefined') {
300
337
  return window;
301
338
  }
302
- if (typeof global !== "undefined") {
339
+ if (typeof global !== 'undefined') {
303
340
  return global;
304
341
  }
305
- throw "Unable to locate global object";
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, "base64"));
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("base64");
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 "long";
3
- import _m0 from "protobufjs/minimal.js";
4
- import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
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 = "echo";
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(message: EchoMsg, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
19
- if (message.body !== "") {
20
- writer.uint32(10).string(message.body);
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: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>,
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(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket>;
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("echo.Echoer", "Echo", data);
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("echo.Echoer", "EchoServerStream", data);
125
- return EchoMsg.decodeTransform(result);
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("echo.Echoer", "EchoClientStream", data);
131
- return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
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("echo.Echoer", "EchoBidiStream", data);
137
- return EchoMsg.decodeTransform(result);
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(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket> {
141
- const data = RpcStreamPacket.encodeTransform(request);
142
- const result = this.rpc.bidirectionalStreamingRequest("echo.Echoer", "RpcStream", data);
143
- return RpcStreamPacket.decodeTransform(result);
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: "Echoer",
151
- fullName: "echo.Echoer",
175
+ name: 'Echoer',
176
+ fullName: 'echo.Echoer',
152
177
  methods: {
153
178
  /** Echo returns the given message. */
154
179
  echo: {
155
- name: "Echo",
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: "EchoServerStream",
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: "EchoClientStream",
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: "EchoBidiStream",
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: "RpcStream",
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(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
203
- clientStreamingRequest(service: string, method: string, data: AsyncIterable<Uint8Array>): Promise<Uint8Array>;
204
- serverStreamingRequest(service: string, method: string, data: Uint8Array): AsyncIterable<Uint8Array>;
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 = Date | Function | Uint8Array | string | number | boolean | undefined;
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 ? T
215
- : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>>
216
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
217
- : T extends { $case: string } ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { $case: T["$case"] }
218
- : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
219
- : Partial<T>;
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 ? P
223
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
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
  }
@@ -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
- impl SRPCEchoerServer
223
+ serviceID string
224
+ impl SRPCEchoerServer
224
225
  }
225
226
 
226
- func (SRPCEchoerHandler) GetServiceID() string { return SRPCEchoerServiceID }
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.10.9",
3
+ "version": "0.11.0",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
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(stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>): SRPCStream {
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,
@@ -7,6 +7,7 @@ export interface Definition {
7
7
  // e.x.: Echo
8
8
  name: string
9
9
  // fullName is the fully qualified name of the service
10
+ // this is also referred to as the "service ID"
10
11
  // e.x.: echoer.Echoer
11
12
  fullName: string
12
13
  // methods is the set of RPC methods.