starpc 0.5.1 → 0.6.1

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,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: EchoMsg1): Promise<EchoMsg1>;
25
+ Echo(request: EchoMsg): Promise<EchoMsg>;
27
26
  /** EchoServerStream is an example of a server -> client one-way stream. */
28
- EchoServerStream(request: EchoMsg1): AsyncIterable<EchoMsg1>;
27
+ EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>;
29
28
  /** EchoClientStream is an example of client->server one-way stream. */
30
- EchoClientStream(request: AsyncIterable<EchoMsg1>): Promise<EchoMsg1>;
29
+ EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>;
31
30
  /** EchoBidiStream is an example of a two-way stream. */
32
- EchoBidiStream(request: AsyncIterable<EchoMsg1>): AsyncIterable<EchoMsg1>;
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: EchoMsg1): Promise<EchoMsg1>;
40
- EchoServerStream(request: EchoMsg1): AsyncIterable<EchoMsg1>;
41
- EchoClientStream(request: AsyncIterable<EchoMsg1>): Promise<EchoMsg1>;
42
- EchoBidiStream(request: AsyncIterable<EchoMsg1>): AsyncIterable<EchoMsg1>;
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. */
@@ -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 = EchoMsg1.encode(request).finish();
87
+ const data = EchoMsg.encode(request).finish();
89
88
  const promise = this.rpc.request('echo.Echoer', 'Echo', data);
90
- return promise.then((data) => EchoMsg1.decode(new _m0.Reader(data)));
89
+ return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
91
90
  }
92
91
  EchoServerStream(request) {
93
- const data = EchoMsg1.encode(request).finish();
92
+ const data = EchoMsg.encode(request).finish();
94
93
  const result = this.rpc.serverStreamingRequest('echo.Echoer', 'EchoServerStream', data);
95
- return EchoMsg1.decodeTransform(result);
94
+ return EchoMsg.decodeTransform(result);
96
95
  }
97
96
  EchoClientStream(request) {
98
- const data = EchoMsg1.encodeTransform(request);
97
+ const data = EchoMsg.encodeTransform(request);
99
98
  const promise = this.rpc.clientStreamingRequest('echo.Echoer', 'EchoClientStream', data);
100
- return promise.then((data) => EchoMsg1.decode(new _m0.Reader(data)));
99
+ return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
101
100
  }
102
101
  EchoBidiStream(request) {
103
- const data = EchoMsg1.encodeTransform(request);
102
+ const data = EchoMsg.encodeTransform(request);
104
103
  const result = this.rpc.bidirectionalStreamingRequest('echo.Echoer', 'EchoBidiStream', data);
105
- return EchoMsg1.decodeTransform(result);
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: EchoMsg1,
119
+ requestType: EchoMsg,
121
120
  requestStream: false,
122
- responseType: EchoMsg1,
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: EchoMsg1,
128
+ requestType: EchoMsg,
130
129
  requestStream: false,
131
- responseType: EchoMsg1,
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: EchoMsg1,
137
+ requestType: EchoMsg,
139
138
  requestStream: true,
140
- responseType: EchoMsg1,
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: EchoMsg1,
146
+ requestType: EchoMsg,
148
147
  requestStream: true,
149
- responseType: EchoMsg1,
148
+ responseType: EchoMsg,
150
149
  responseStream: true,
151
150
  options: {},
152
151
  },
@@ -36,7 +36,7 @@ export class EchoerServer {
36
36
  if (!this.proxyServer) {
37
37
  throw new Error('rpc stream proxy server not set');
38
38
  }
39
- return this.proxyServer;
39
+ return this.proxyServer.rpcStreamHandler;
40
40
  });
41
41
  }
42
42
  }
@@ -1,2 +1,2 @@
1
- export { RpcStream, RpcStreamCaller, RpcStreamGetter, handleRpcStream, buildRpcStreamOpenStream, } from './rpcstream.js';
2
- export { RpcStreamPacket, RpcStreamInit } from './rpcstream.pb.js';
1
+ export { RpcStream, RpcStreamCaller, RpcStreamGetter, RpcStreamHandler, openRpcStream, handleRpcStream, buildRpcStreamOpenStream, } from './rpcstream.js';
2
+ export { RpcStreamPacket, RpcStreamInit, RpcAck } from './rpcstream.pb.js';
@@ -1,2 +1,2 @@
1
- export { RpcStream, handleRpcStream, buildRpcStreamOpenStream, } from './rpcstream.js';
2
- export { RpcStreamPacket, RpcStreamInit } from './rpcstream.pb.js';
1
+ export { RpcStream, openRpcStream, handleRpcStream, buildRpcStreamOpenStream, } from './rpcstream.js';
2
+ export { RpcStreamPacket, RpcStreamInit, RpcAck } from './rpcstream.pb.js';
@@ -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 RpcStreamGetter = (componentId: string) => Promise<Server>;
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 server;
52
+ let handler = null;
53
53
  let err;
54
54
  try {
55
- server = await getter(initRpcStreamPacket.body.init.componentId);
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 (!server && !err) {
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
- server.handleDuplex(rpcStream);
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: RpcStreamInit1;
8
+ init: RpcStreamInit;
10
9
  } | {
11
10
  $case: 'ack';
12
- ack: RpcAck2;
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
- RpcStreamInit1.encode(message.body.init, writer.uint32(10).fork()).ldelim();
11
+ RpcStreamInit.encode(message.body.init, writer.uint32(10).fork()).ldelim();
13
12
  }
14
13
  if (message.body?.$case === 'ack') {
15
- RpcAck2.encode(message.body.ack, writer.uint32(18).fork()).ldelim();
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: RpcStreamInit1.decode(reader, reader.uint32()),
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: RpcAck2.decode(reader, reader.uint32()),
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: RpcStreamInit1.fromJSON(object.init) }
81
+ ? { $case: 'init', init: RpcStreamInit.fromJSON(object.init) }
83
82
  : isSet(object.ack)
84
- ? { $case: 'ack', ack: RpcAck2.fromJSON(object.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
- ? RpcStreamInit1.toJSON(message.body?.init)
93
+ ? RpcStreamInit.toJSON(message.body?.init)
95
94
  : undefined);
96
95
  message.body?.$case === 'ack' &&
97
96
  (obj.ack = message.body?.ack
98
- ? RpcAck2.toJSON(message.body?.ack)
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: RpcStreamInit1.fromPartial(object.body.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: RpcAck2.fromPartial(object.body.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 &&
@@ -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';
@@ -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: CallStart1;
8
+ callStart: CallStart;
10
9
  } | {
11
10
  $case: 'callData';
12
- callData: CallData2;
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 CallStart1>, never>) | undefined;
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 CallData2>, never>) | undefined;
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 CallStart1>, never>>(object: I): CallStart;
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 CallData2>, never>>(object: I): CallData;
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 {
@@ -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
- CallStart1.encode(message.body.callStart, writer.uint32(10).fork()).ldelim();
11
+ CallStart.encode(message.body.callStart, writer.uint32(10).fork()).ldelim();
13
12
  }
14
13
  if (message.body?.$case === 'callData') {
15
- CallData2.encode(message.body.callData, writer.uint32(18).fork()).ldelim();
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: CallStart1.decode(reader, reader.uint32()),
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: CallData2.decode(reader, reader.uint32()),
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: CallStart1.fromJSON(object.callStart),
77
+ callStart: CallStart.fromJSON(object.callStart),
79
78
  }
80
79
  : isSet(object.callData)
81
- ? { $case: 'callData', callData: CallData2.fromJSON(object.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
- ? CallStart1.toJSON(message.body?.callStart)
88
+ ? CallStart.toJSON(message.body?.callStart)
90
89
  : undefined);
91
90
  message.body?.$case === 'callData' &&
92
91
  (obj.callData = message.body?.callData
93
- ? CallData2.toJSON(message.body?.callData)
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: CallStart1.fromPartial(object.body.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: CallData2.fromPartial(object.body.callData),
111
+ callData: CallData.fromPartial(object.body.callData),
113
112
  };
114
113
  }
115
114
  return message;
@@ -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;
@@ -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: EchoMsg1): Promise<EchoMsg1>
102
+ Echo(request: EchoMsg): Promise<EchoMsg>
104
103
  /** EchoServerStream is an example of a server -> client one-way stream. */
105
- EchoServerStream(request: EchoMsg1): AsyncIterable<EchoMsg1>
104
+ EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>
106
105
  /** EchoClientStream is an example of client->server one-way stream. */
107
- EchoClientStream(request: AsyncIterable<EchoMsg1>): Promise<EchoMsg1>
106
+ EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>
108
107
  /** EchoBidiStream is an example of a two-way stream. */
109
- EchoBidiStream(request: AsyncIterable<EchoMsg1>): AsyncIterable<EchoMsg1>
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: EchoMsg1): Promise<EchoMsg1> {
127
- const data = EchoMsg1.encode(request).finish()
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) => EchoMsg1.decode(new _m0.Reader(data)))
128
+ return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
130
129
  }
131
130
 
132
- EchoServerStream(request: EchoMsg1): AsyncIterable<EchoMsg1> {
133
- const data = EchoMsg1.encode(request).finish()
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 EchoMsg1.decodeTransform(result)
138
+ return EchoMsg.decodeTransform(result)
140
139
  }
141
140
 
142
- EchoClientStream(request: AsyncIterable<EchoMsg1>): Promise<EchoMsg1> {
143
- const data = EchoMsg1.encodeTransform(request)
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) => EchoMsg1.decode(new _m0.Reader(data)))
148
+ return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
150
149
  }
151
150
 
152
- EchoBidiStream(request: AsyncIterable<EchoMsg1>): AsyncIterable<EchoMsg1> {
153
- const data = EchoMsg1.encodeTransform(request)
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 EchoMsg1.decodeTransform(result)
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: EchoMsg1,
183
+ requestType: EchoMsg,
185
184
  requestStream: false,
186
- responseType: EchoMsg1,
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: EchoMsg1,
192
+ requestType: EchoMsg,
194
193
  requestStream: false,
195
- responseType: EchoMsg1,
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: EchoMsg1,
201
+ requestType: EchoMsg,
203
202
  requestStream: true,
204
- responseType: EchoMsg1,
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: EchoMsg1,
210
+ requestType: EchoMsg,
212
211
  requestStream: true,
213
- responseType: EchoMsg1,
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<Server> => {
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.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -67,7 +67,7 @@
67
67
  "eslint-config-prettier": "^8.5.0",
68
68
  "prettier": "^2.7.1",
69
69
  "rimraf": "^3.0.2",
70
- "ts-proto": "^1.116.0",
70
+ "ts-proto": "^1.116.1",
71
71
  "typescript": "^4.7.4",
72
72
  "utf-8-validate": "^5.0.9"
73
73
  },
@@ -1,5 +1,5 @@
1
1
  diff --git a/node_modules/ts-poet/build/Import.js b/node_modules/ts-poet/build/Import.js
2
- index fe1f6d2..280df8f 100644
2
+ index b92bea3..608add9 100644
3
3
  --- a/node_modules/ts-poet/build/Import.js
4
4
  +++ b/node_modules/ts-poet/build/Import.js
5
5
  @@ -293,6 +293,14 @@ function emitImports(imports, ourModulePath, importMappings) {
package/srpc/index.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 {
9
9
  BroadcastChannelDuplex,
10
10
  newBroadcastChannelDuplex,
@@ -1,18 +1,14 @@
1
1
  /* eslint-disable */
2
2
  import Long from 'long'
3
3
  import * as _m0 from 'protobufjs/minimal'
4
- import {
5
- CallStart as CallStart1,
6
- CallData as CallData2,
7
- } from './rpcproto.pb.js'
8
4
 
9
5
  export const protobufPackage = 'srpc'
10
6
 
11
7
  /** Packet is a message sent over a srpc packet connection. */
12
8
  export interface Packet {
13
9
  body?:
14
- | { $case: 'callStart'; callStart: CallStart1 }
15
- | { $case: 'callData'; callData: CallData2 }
10
+ | { $case: 'callStart'; callStart: CallStart }
11
+ | { $case: 'callData'; callData: CallData }
16
12
  }
17
13
 
18
14
  /** CallStart requests starting a new RPC call. */
@@ -61,13 +57,13 @@ export const Packet = {
61
57
  writer: _m0.Writer = _m0.Writer.create()
62
58
  ): _m0.Writer {
63
59
  if (message.body?.$case === 'callStart') {
64
- CallStart1.encode(
60
+ CallStart.encode(
65
61
  message.body.callStart,
66
62
  writer.uint32(10).fork()
67
63
  ).ldelim()
68
64
  }
69
65
  if (message.body?.$case === 'callData') {
70
- CallData2.encode(message.body.callData, writer.uint32(18).fork()).ldelim()
66
+ CallData.encode(message.body.callData, writer.uint32(18).fork()).ldelim()
71
67
  }
72
68
  return writer
73
69
  },
@@ -82,13 +78,13 @@ export const Packet = {
82
78
  case 1:
83
79
  message.body = {
84
80
  $case: 'callStart',
85
- callStart: CallStart1.decode(reader, reader.uint32()),
81
+ callStart: CallStart.decode(reader, reader.uint32()),
86
82
  }
87
83
  break
88
84
  case 2:
89
85
  message.body = {
90
86
  $case: 'callData',
91
- callData: CallData2.decode(reader, reader.uint32()),
87
+ callData: CallData.decode(reader, reader.uint32()),
92
88
  }
93
89
  break
94
90
  default:
@@ -138,10 +134,10 @@ export const Packet = {
138
134
  body: isSet(object.callStart)
139
135
  ? {
140
136
  $case: 'callStart',
141
- callStart: CallStart1.fromJSON(object.callStart),
137
+ callStart: CallStart.fromJSON(object.callStart),
142
138
  }
143
139
  : isSet(object.callData)
144
- ? { $case: 'callData', callData: CallData2.fromJSON(object.callData) }
140
+ ? { $case: 'callData', callData: CallData.fromJSON(object.callData) }
145
141
  : undefined,
146
142
  }
147
143
  },
@@ -150,11 +146,11 @@ export const Packet = {
150
146
  const obj: any = {}
151
147
  message.body?.$case === 'callStart' &&
152
148
  (obj.callStart = message.body?.callStart
153
- ? CallStart1.toJSON(message.body?.callStart)
149
+ ? CallStart.toJSON(message.body?.callStart)
154
150
  : undefined)
155
151
  message.body?.$case === 'callData' &&
156
152
  (obj.callData = message.body?.callData
157
- ? CallData2.toJSON(message.body?.callData)
153
+ ? CallData.toJSON(message.body?.callData)
158
154
  : undefined)
159
155
  return obj
160
156
  },
@@ -168,7 +164,7 @@ export const Packet = {
168
164
  ) {
169
165
  message.body = {
170
166
  $case: 'callStart',
171
- callStart: CallStart1.fromPartial(object.body.callStart),
167
+ callStart: CallStart.fromPartial(object.body.callStart),
172
168
  }
173
169
  }
174
170
  if (
@@ -178,7 +174,7 @@ export const Packet = {
178
174
  ) {
179
175
  message.body = {
180
176
  $case: 'callData',
181
- callData: CallData2.fromPartial(object.body.callData),
177
+ callData: CallData.fromPartial(object.body.callData),
182
178
  }
183
179
  }
184
180
  return message
package/srpc/server.ts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  encodePacketSource,
13
13
  } from './packet.js'
14
14
  import { StreamHandler } from './conn.js'
15
+ import { RpcStreamHandler } from '../rpcstream/rpcstream.js'
15
16
 
16
17
  // Server implements the SRPC server in TypeScript with a Mux.
17
18
  export class Server implements StreamHandler {
@@ -22,6 +23,11 @@ export class Server implements StreamHandler {
22
23
  this.mux = mux
23
24
  }
24
25
 
26
+ // rpcStreamHandler implements the RpcStreamHandler interface.
27
+ public get rpcStreamHandler(): RpcStreamHandler {
28
+ return this.handleDuplex.bind(this)
29
+ }
30
+
25
31
  // startRpc starts a new server-side RPC.
26
32
  // the returned RPC handles incoming Packets.
27
33
  public startRpc(): ServerRPC {
@@ -1,14 +0,0 @@
1
- diff --git a/node_modules/ts-proto/build/utils.js b/node_modules/ts-proto/build/utils.js
2
- index 2148e97..e19b35f 100644
3
- --- a/node_modules/ts-proto/build/utils.js
4
- +++ b/node_modules/ts-proto/build/utils.js
5
- @@ -170,7 +170,8 @@ function getPropertyAccessor(objectName, propertyName, optional = false) {
6
- }
7
- exports.getPropertyAccessor = getPropertyAccessor;
8
- function impProto(options, module, type) {
9
- - const importString = `${type}@./${module}${options.fileSuffix}`;
10
- + // NOTE: TypeScript resolves importing foo.js to importing foo.ts.
11
- + const importString = `${type}@./${module}${options.fileSuffix}.js`;
12
- if (options.onlyTypes) {
13
- return (0, ts_poet_1.imp)('t:' + importString);
14
- }