starpc 0.3.6 → 0.4.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.
Files changed (43) hide show
  1. package/Makefile +2 -1
  2. package/dist/echo/client-test.js +1 -1
  3. package/dist/echo/{echo.d.ts → echo.pb.d.ts} +0 -0
  4. package/dist/echo/{echo.js → echo.pb.js} +0 -0
  5. package/dist/echo/index.d.ts +1 -1
  6. package/dist/echo/index.js +1 -1
  7. package/dist/echo/server.d.ts +1 -1
  8. package/dist/srpc/client-rpc.d.ts +1 -1
  9. package/dist/srpc/client.d.ts +5 -5
  10. package/dist/srpc/client.js +19 -19
  11. package/dist/srpc/common-rpc.d.ts +2 -2
  12. package/dist/srpc/common-rpc.js +1 -1
  13. package/dist/srpc/index.d.ts +1 -1
  14. package/dist/srpc/packet.d.ts +1 -1
  15. package/dist/srpc/packet.js +1 -1
  16. package/dist/srpc/{rpcproto.d.ts → rpcproto.pb.d.ts} +0 -0
  17. package/dist/srpc/{rpcproto.js → rpcproto.pb.js} +0 -0
  18. package/dist/srpc/server-rpc.d.ts +1 -1
  19. package/dist/srpc/server.d.ts +1 -1
  20. package/dist/srpc/stream.d.ts +1 -1
  21. package/echo/client-test.ts +1 -1
  22. package/echo/{echo.ts → echo.pb.ts} +0 -0
  23. package/echo/index.ts +1 -1
  24. package/echo/server.ts +1 -1
  25. package/integration/integration.ts +2 -2
  26. package/package.json +1 -1
  27. package/srpc/broadcast-channel.ts +1 -1
  28. package/srpc/client-rpc.ts +1 -1
  29. package/srpc/client.go +2 -2
  30. package/srpc/client.ts +23 -23
  31. package/srpc/common-rpc.ts +2 -2
  32. package/srpc/index.ts +1 -1
  33. package/srpc/{rpc-stream.go → msg-stream.go} +11 -11
  34. package/srpc/muxed-conn.go +1 -1
  35. package/srpc/packet.ts +1 -1
  36. package/srpc/{rpcproto.ts → rpcproto.pb.ts} +0 -0
  37. package/srpc/server-pipe.go +1 -1
  38. package/srpc/server-rpc.go +1 -1
  39. package/srpc/server-rpc.ts +1 -1
  40. package/srpc/server.go +5 -0
  41. package/srpc/server.ts +1 -1
  42. package/srpc/stream.ts +1 -1
  43. package/srpc/websocket.go +1 -1
package/Makefile CHANGED
@@ -99,9 +99,10 @@ gents: $(PROTOWRAP) node_modules
99
99
  -I $$(pwd)/vendor \
100
100
  --plugin=./node_modules/.bin/protoc-gen-ts_proto \
101
101
  --ts_proto_out=$$(pwd)/vendor \
102
+ --ts_proto_opt=esModuleInterop=true \
103
+ --ts_proto_opt=fileSuffix=.pb \
102
104
  --ts_proto_opt=forceLong=long \
103
105
  --ts_proto_opt=oneof=unions \
104
- --ts_proto_opt=esModuleInterop=true \
105
106
  --ts_proto_opt=outputServices=default,outputServices=generic-definitions \
106
107
  --proto_path $$(pwd)/vendor \
107
108
  --print_structure \
@@ -1,4 +1,4 @@
1
- import { EchoerClientImpl } from './echo.js';
1
+ import { EchoerClientImpl } from './echo.pb.js';
2
2
  import { Observable } from 'rxjs';
3
3
  export async function runClientTest(client) {
4
4
  const demoServiceClient = new EchoerClientImpl(client);
File without changes
File without changes
@@ -1,3 +1,3 @@
1
- export * from './echo.js';
1
+ export * from './echo.pb.js';
2
2
  export * from './server.js';
3
3
  export { runClientTest } from './client-test.js';
@@ -1,3 +1,3 @@
1
- export * from './echo.js';
1
+ export * from './echo.pb.js';
2
2
  export * from './server.js';
3
3
  export { runClientTest } from './client-test.js';
@@ -1,5 +1,5 @@
1
1
  import { Observable } from 'rxjs';
2
- import { Echoer, EchoMsg } from './echo';
2
+ import { Echoer, EchoMsg } from './echo.pb.js';
3
3
  export declare class EchoerServer implements Echoer {
4
4
  Echo(request: EchoMsg): Promise<EchoMsg>;
5
5
  EchoServerStream(request: EchoMsg): Observable<EchoMsg>;
@@ -1,4 +1,4 @@
1
- import type { CallStart } from './rpcproto.js';
1
+ import type { CallStart } from './rpcproto.pb.js';
2
2
  import { CommonRPC } from './common-rpc.js';
3
3
  export declare class ClientRPC extends CommonRPC {
4
4
  constructor(service: string, method: string);
@@ -2,11 +2,11 @@ import { Observable } from 'rxjs';
2
2
  import type { TsProtoRpc } from './ts-proto-rpc.js';
3
3
  import type { OpenStreamFunc } from './stream.js';
4
4
  export declare class Client implements TsProtoRpc {
5
- private openConnFn;
6
- private _openConnFn?;
7
- constructor(openConnFn?: OpenStreamFunc);
8
- setOpenConnFn(openConnFn?: OpenStreamFunc): Promise<OpenStreamFunc>;
9
- private initOpenConnFn;
5
+ private openStreamFn;
6
+ private _openStreamFn?;
7
+ constructor(openStreamFn?: OpenStreamFunc);
8
+ setOpenStreamFn(openStreamFn?: OpenStreamFunc): Promise<OpenStreamFunc>;
9
+ private initOpenStreamFn;
10
10
  request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
11
11
  clientStreamingRequest(service: string, method: string, data: Observable<Uint8Array>): Promise<Uint8Array>;
12
12
  serverStreamingRequest(service: string, method: string, data: Uint8Array): Observable<Uint8Array>;
@@ -19,31 +19,31 @@ function writeClientStream(call, data) {
19
19
  }
20
20
  // Client implements the ts-proto Rpc interface with the drpcproto protocol.
21
21
  export class Client {
22
- constructor(openConnFn) {
23
- this.openConnFn = this.setOpenConnFn(openConnFn);
22
+ constructor(openStreamFn) {
23
+ this.openStreamFn = this.setOpenStreamFn(openStreamFn);
24
24
  }
25
- // setOpenConnFn updates the openConnFn for the Client.
26
- setOpenConnFn(openConnFn) {
27
- if (this._openConnFn) {
28
- if (openConnFn) {
29
- this._openConnFn(openConnFn);
30
- this._openConnFn = undefined;
25
+ // setOpenStreamFn updates the openStreamFn for the Client.
26
+ setOpenStreamFn(openStreamFn) {
27
+ if (this._openStreamFn) {
28
+ if (openStreamFn) {
29
+ this._openStreamFn(openStreamFn);
30
+ this._openStreamFn = undefined;
31
31
  }
32
32
  }
33
33
  else {
34
- if (openConnFn) {
35
- this.openConnFn = Promise.resolve(openConnFn);
34
+ if (openStreamFn) {
35
+ this.openStreamFn = Promise.resolve(openStreamFn);
36
36
  }
37
37
  else {
38
- this.initOpenConnFn();
38
+ this.initOpenStreamFn();
39
39
  }
40
40
  }
41
- return this.openConnFn;
41
+ return this.openStreamFn;
42
42
  }
43
- // initOpenConnFn creates the empty Promise for openConnFn.
44
- initOpenConnFn() {
43
+ // initOpenStreamFn creates the empty Promise for openStreamFn.
44
+ initOpenStreamFn() {
45
45
  const openPromise = new Promise((resolve, reject) => {
46
- this._openConnFn = (conn, err) => {
46
+ this._openStreamFn = (conn, err) => {
47
47
  if (err) {
48
48
  reject(err);
49
49
  }
@@ -52,8 +52,8 @@ export class Client {
52
52
  }
53
53
  };
54
54
  });
55
- this.openConnFn = openPromise;
56
- return this.openConnFn;
55
+ this.openStreamFn = openPromise;
56
+ return this.openStreamFn;
57
57
  }
58
58
  // request starts a non-streaming request.
59
59
  async request(service, method, data) {
@@ -131,8 +131,8 @@ export class Client {
131
131
  // throws any error starting the rpc call
132
132
  // if data == null and data.length == 0, sends a separate data packet.
133
133
  async startRpc(rpcService, rpcMethod, data) {
134
- const openConnFn = await this.openConnFn;
135
- const conn = await openConnFn();
134
+ const openStreamFn = await this.openStreamFn;
135
+ const conn = await openStreamFn();
136
136
  const call = new ClientRPC(rpcService, rpcMethod);
137
137
  pipe(conn, parseLengthPrefixTransform(), decodePacketSource, call, encodePacketSource, prependLengthPrefixTransform(), conn);
138
138
  await call.writeCallStart(data || undefined);
@@ -1,6 +1,6 @@
1
1
  import type { Source, Sink } from 'it-stream-types';
2
- import type { CallData, CallStart } from './rpcproto.js';
3
- import { Packet } from './rpcproto.js';
2
+ import type { CallData, CallStart } from './rpcproto.pb.js';
3
+ import { Packet } from './rpcproto.pb.js';
4
4
  export declare class CommonRPC {
5
5
  sink: Sink<Packet>;
6
6
  source: AsyncIterable<Packet>;
@@ -1,5 +1,5 @@
1
1
  import { pushable } from 'it-pushable';
2
- import { Packet } from './rpcproto.js';
2
+ import { Packet } from './rpcproto.pb.js';
3
3
  // CommonRPC is common logic between server and client RPCs.
4
4
  export class CommonRPC {
5
5
  constructor() {
@@ -1,4 +1,4 @@
1
- export type { OpenStreamFunc } from './stream.js';
1
+ export type { PacketHandler, Stream, OpenStreamFunc } from './stream.js';
2
2
  export { Client } from './client.js';
3
3
  export { Server } from './server.js';
4
4
  export { Conn, ConnParams } from './conn.js';
@@ -1,5 +1,5 @@
1
1
  import type { Transform } from 'it-stream-types';
2
- import { Packet } from './rpcproto.js';
2
+ import { Packet } from './rpcproto.pb.js';
3
3
  export declare const decodePacketSource: (source: import("it-stream-types").Source<Uint8Array | Uint8Array[]>) => AsyncIterable<Packet>;
4
4
  export declare const encodePacketSource: (source: import("it-stream-types").Source<Packet | Packet[]>) => AsyncIterable<Uint8Array>;
5
5
  export declare function prependLengthPrefixTransform(): Transform<Uint8Array>;
@@ -1,5 +1,5 @@
1
1
  import { encode as lengthPrefixEncode, decode as lengthPrefixDecode, } from 'it-length-prefixed';
2
- import { Packet } from './rpcproto.js';
2
+ import { Packet } from './rpcproto.pb.js';
3
3
  import { buildDecodeMessageTransform, buildEncodeMessageTransform, } from './message.js';
4
4
  // decodePacketSource decodes packets from a binary data stream.
5
5
  export const decodePacketSource = buildDecodeMessageTransform(Packet);
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import type { CallData, CallStart } from './rpcproto.js';
1
+ import type { CallData, CallStart } from './rpcproto.pb.js';
2
2
  import { CommonRPC } from './common-rpc.js';
3
3
  import { Mux } from './mux.js';
4
4
  export declare class ServerRPC extends CommonRPC {
@@ -2,7 +2,7 @@ import { Stream } from '@libp2p/interface-connection';
2
2
  import { Duplex } from 'it-stream-types';
3
3
  import { Mux } from './mux.js';
4
4
  import { ServerRPC } from './server-rpc.js';
5
- import { Packet } from './rpcproto.js';
5
+ import { Packet } from './rpcproto.pb.js';
6
6
  import { StreamHandler } from './conn.js';
7
7
  export declare class Server implements StreamHandler {
8
8
  private mux;
@@ -1,4 +1,4 @@
1
- import type { Packet } from './rpcproto';
1
+ import type { Packet } from './rpcproto.pb.js';
2
2
  import type { Duplex } from 'it-stream-types';
3
3
  export declare type PacketHandler = (packet: Packet) => Promise<void>;
4
4
  export declare type Stream = Duplex<Uint8Array>;
@@ -1,5 +1,5 @@
1
1
  import { Client } from '../srpc/index.js'
2
- import { EchoerClientImpl, EchoMsg } from './echo.js'
2
+ import { EchoerClientImpl, EchoMsg } from './echo.pb.js'
3
3
  import { Observable } from 'rxjs'
4
4
 
5
5
  export async function runClientTest(client: Client) {
File without changes
package/echo/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './echo.js'
1
+ export * from './echo.pb.js'
2
2
  export * from './server.js'
3
3
  export { runClientTest } from './client-test.js'
package/echo/server.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Observable, from as observableFrom } from 'rxjs'
2
- import { Echoer, EchoMsg } from './echo'
2
+ import { Echoer, EchoMsg } from './echo.pb.js'
3
3
  import { pushable, Pushable } from 'it-pushable'
4
4
 
5
5
  // EchoServer implements the Echoer server.
@@ -1,5 +1,5 @@
1
- import { WebSocketConn } from '../srpc/websocket'
2
- import { runClientTest } from '../echo'
1
+ import { WebSocketConn } from '../srpc/websocket.js'
2
+ import { runClientTest } from '../echo/client-test.js'
3
3
  import WebSocket from 'isomorphic-ws'
4
4
 
5
5
  async function runRPC() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -46,8 +46,8 @@ export class BroadcastChannelIterable<T> implements Duplex<T> {
46
46
  queue.push(ev.data)
47
47
  }
48
48
  }
49
- this.readChannel.addEventListener('message', messageListener)
50
49
 
50
+ this.readChannel.addEventListener('message', messageListener)
51
51
  return () => {
52
52
  this.readChannel.removeEventListener('message', messageListener)
53
53
  }
@@ -1,4 +1,4 @@
1
- import type { CallStart } from './rpcproto.js'
1
+ import type { CallStart } from './rpcproto.pb.js'
2
2
  import { CommonRPC } from './common-rpc.js'
3
3
 
4
4
  // ClientRPC is an ongoing RPC from the client side.
package/srpc/client.go CHANGED
@@ -19,7 +19,7 @@ type Client interface {
19
19
 
20
20
  // OpenStreamFunc opens a stream with a remote.
21
21
  // msgHandler must not be called concurrently.
22
- type OpenStreamFunc = func(ctx context.Context, msgHandler func(pkt *Packet) error) (Writer, error)
22
+ type OpenStreamFunc = func(ctx context.Context, msgHandler PacketHandler) (Writer, error)
23
23
 
24
24
  // client implements Client with a transport.
25
25
  type client struct {
@@ -89,7 +89,7 @@ func (c *client) NewStream(ctx context.Context, service, method string, firstMsg
89
89
  return nil, err
90
90
  }
91
91
 
92
- return NewRPCStream(ctx, clientRPC.writer, clientRPC.dataCh), nil
92
+ return NewMsgStream(ctx, clientRPC.writer, clientRPC.dataCh), nil
93
93
  }
94
94
 
95
95
  // _ is a type assertion
package/srpc/client.ts CHANGED
@@ -29,36 +29,36 @@ function writeClientStream(call: ClientRPC, data: Observable<Uint8Array>) {
29
29
 
30
30
  // Client implements the ts-proto Rpc interface with the drpcproto protocol.
31
31
  export class Client implements TsProtoRpc {
32
- // openConnFn is a promise which contains the OpenStreamFunc.
33
- private openConnFn: Promise<OpenStreamFunc>
34
- // _openConnFn resolves openConnFn.
35
- private _openConnFn?: (conn?: OpenStreamFunc, err?: Error) => void
32
+ // openStreamFn is a promise which contains the OpenStreamFunc.
33
+ private openStreamFn: Promise<OpenStreamFunc>
34
+ // _openStreamFn resolves openStreamFn.
35
+ private _openStreamFn?: (conn?: OpenStreamFunc, err?: Error) => void
36
36
 
37
- constructor(openConnFn?: OpenStreamFunc) {
38
- this.openConnFn = this.setOpenConnFn(openConnFn)
37
+ constructor(openStreamFn?: OpenStreamFunc) {
38
+ this.openStreamFn = this.setOpenStreamFn(openStreamFn)
39
39
  }
40
40
 
41
- // setOpenConnFn updates the openConnFn for the Client.
42
- public setOpenConnFn(openConnFn?: OpenStreamFunc): Promise<OpenStreamFunc> {
43
- if (this._openConnFn) {
44
- if (openConnFn) {
45
- this._openConnFn(openConnFn)
46
- this._openConnFn = undefined
41
+ // setOpenStreamFn updates the openStreamFn for the Client.
42
+ public setOpenStreamFn(openStreamFn?: OpenStreamFunc): Promise<OpenStreamFunc> {
43
+ if (this._openStreamFn) {
44
+ if (openStreamFn) {
45
+ this._openStreamFn(openStreamFn)
46
+ this._openStreamFn = undefined
47
47
  }
48
48
  } else {
49
- if (openConnFn) {
50
- this.openConnFn = Promise.resolve(openConnFn)
49
+ if (openStreamFn) {
50
+ this.openStreamFn = Promise.resolve(openStreamFn)
51
51
  } else {
52
- this.initOpenConnFn()
52
+ this.initOpenStreamFn()
53
53
  }
54
54
  }
55
- return this.openConnFn
55
+ return this.openStreamFn
56
56
  }
57
57
 
58
- // initOpenConnFn creates the empty Promise for openConnFn.
59
- private initOpenConnFn(): Promise<OpenStreamFunc> {
58
+ // initOpenStreamFn creates the empty Promise for openStreamFn.
59
+ private initOpenStreamFn(): Promise<OpenStreamFunc> {
60
60
  const openPromise = new Promise<OpenStreamFunc>((resolve, reject) => {
61
- this._openConnFn = (conn?: OpenStreamFunc, err?: Error) => {
61
+ this._openStreamFn = (conn?: OpenStreamFunc, err?: Error) => {
62
62
  if (err) {
63
63
  reject(err)
64
64
  } else if (conn) {
@@ -66,8 +66,8 @@ export class Client implements TsProtoRpc {
66
66
  }
67
67
  }
68
68
  })
69
- this.openConnFn = openPromise
70
- return this.openConnFn
69
+ this.openStreamFn = openPromise
70
+ return this.openStreamFn
71
71
  }
72
72
 
73
73
  // request starts a non-streaming request.
@@ -168,8 +168,8 @@ export class Client implements TsProtoRpc {
168
168
  rpcMethod: string,
169
169
  data: Uint8Array | null
170
170
  ): Promise<ClientRPC> {
171
- const openConnFn = await this.openConnFn
172
- const conn = await openConnFn()
171
+ const openStreamFn = await this.openStreamFn
172
+ const conn = await openStreamFn()
173
173
  const call = new ClientRPC(rpcService, rpcMethod)
174
174
  pipe(
175
175
  conn,
@@ -1,8 +1,8 @@
1
1
  import type { Source, Sink } from 'it-stream-types'
2
2
  import { pushable } from 'it-pushable'
3
3
 
4
- import type { CallData, CallStart } from './rpcproto.js'
5
- import { Packet } from './rpcproto.js'
4
+ import type { CallData, CallStart } from './rpcproto.pb.js'
5
+ import { Packet } from './rpcproto.pb.js'
6
6
 
7
7
  // CommonRPC is common logic between server and client RPCs.
8
8
  export class CommonRPC {
package/srpc/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { OpenStreamFunc } from './stream.js'
1
+ export type { PacketHandler, Stream, OpenStreamFunc } from './stream.js'
2
2
  export { Client } from './client.js'
3
3
  export { Server } from './server.js'
4
4
  export { Conn, ConnParams } from './conn.js'
@@ -5,8 +5,8 @@ import (
5
5
  "io"
6
6
  )
7
7
 
8
- // RPCStream implements the stream interface passed to implementations.
9
- type RPCStream struct {
8
+ // MsgStream implements the stream interface passed to implementations.
9
+ type MsgStream struct {
10
10
  // ctx is the stream context
11
11
  ctx context.Context
12
12
  // writer is the stream writer
@@ -15,10 +15,10 @@ type RPCStream struct {
15
15
  dataCh chan []byte
16
16
  }
17
17
 
18
- // NewRPCStream constructs a new Stream with a ClientRPC.
18
+ // NewMsgStream constructs a new Stream with a ClientRPC.
19
19
  // dataCh should be closed when no more messages will arrive.
20
- func NewRPCStream(ctx context.Context, writer Writer, dataCh chan []byte) *RPCStream {
21
- return &RPCStream{
20
+ func NewMsgStream(ctx context.Context, writer Writer, dataCh chan []byte) *MsgStream {
21
+ return &MsgStream{
22
22
  ctx: ctx,
23
23
  writer: writer,
24
24
  dataCh: dataCh,
@@ -26,12 +26,12 @@ func NewRPCStream(ctx context.Context, writer Writer, dataCh chan []byte) *RPCSt
26
26
  }
27
27
 
28
28
  // Context is canceled when the Stream is no longer valid.
29
- func (r *RPCStream) Context() context.Context {
29
+ func (r *MsgStream) Context() context.Context {
30
30
  return r.ctx
31
31
  }
32
32
 
33
33
  // MsgSend sends the message to the remote.
34
- func (r *RPCStream) MsgSend(msg Message) error {
34
+ func (r *MsgStream) MsgSend(msg Message) error {
35
35
  select {
36
36
  case <-r.ctx.Done():
37
37
  return context.Canceled
@@ -48,7 +48,7 @@ func (r *RPCStream) MsgSend(msg Message) error {
48
48
 
49
49
  // MsgRecv receives an incoming message from the remote.
50
50
  // Parses the message into the object at msg.
51
- func (r *RPCStream) MsgRecv(msg Message) error {
51
+ func (r *MsgStream) MsgRecv(msg Message) error {
52
52
  select {
53
53
  case <-r.Context().Done():
54
54
  return context.Canceled
@@ -61,16 +61,16 @@ func (r *RPCStream) MsgRecv(msg Message) error {
61
61
  }
62
62
 
63
63
  // CloseSend signals to the remote that we will no longer send any messages.
64
- func (r *RPCStream) CloseSend() error {
64
+ func (r *MsgStream) CloseSend() error {
65
65
  outPkt := NewCallDataPacket(nil, false, true, nil)
66
66
  return r.writer.WritePacket(outPkt)
67
67
  }
68
68
 
69
69
  // Close closes the stream.
70
- func (r *RPCStream) Close() error {
70
+ func (r *MsgStream) Close() error {
71
71
  _ = r.writer.Close()
72
72
  return nil
73
73
  }
74
74
 
75
75
  // _ is a type assertion
76
- var _ Stream = ((*RPCStream)(nil))
76
+ var _ Stream = ((*MsgStream)(nil))
@@ -14,7 +14,7 @@ func NewClientWithMuxedConn(conn network.MuxedConn) Client {
14
14
 
15
15
  // NewOpenStreamWithMuxedConn constructs a OpenStream func with a MuxedConn.
16
16
  func NewOpenStreamWithMuxedConn(conn network.MuxedConn) OpenStreamFunc {
17
- return func(ctx context.Context, msgHandler func(pkt *Packet) error) (Writer, error) {
17
+ return func(ctx context.Context, msgHandler PacketHandler) (Writer, error) {
18
18
  mstrm, err := conn.OpenStream(ctx)
19
19
  if err != nil {
20
20
  return nil, err
package/srpc/packet.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  decode as lengthPrefixDecode,
5
5
  } from 'it-length-prefixed'
6
6
 
7
- import { Packet } from './rpcproto.js'
7
+ import { Packet } from './rpcproto.pb.js'
8
8
  import {
9
9
  buildDecodeMessageTransform,
10
10
  buildEncodeMessageTransform,
File without changes
@@ -9,7 +9,7 @@ import (
9
9
  // Stream with the given Server. Starts read pumps for both. Starts the
10
10
  // HandleStream function on the server in a separate goroutine.
11
11
  func NewServerPipe(server *Server) OpenStreamFunc {
12
- return func(ctx context.Context, msgHandler func(pkt *Packet) error) (Writer, error) {
12
+ return func(ctx context.Context, msgHandler PacketHandler) (Writer, error) {
13
13
  srvPipe, clientPipe := net.Pipe()
14
14
  go func() {
15
15
  _ = server.HandleStream(ctx, srvPipe)
@@ -133,7 +133,7 @@ func (r *ServerRPC) HandleCallData(pkt *CallData) error {
133
133
  func (r *ServerRPC) invokeRPC() {
134
134
  // ctx := r.ctx
135
135
  serviceID, methodID := r.service, r.method
136
- strm := NewRPCStream(r.ctx, r.writer, r.dataCh)
136
+ strm := NewMsgStream(r.ctx, r.writer, r.dataCh)
137
137
  ok, err := r.mux.InvokeMethod(serviceID, methodID, strm)
138
138
  if err == nil && !ok {
139
139
  err = ErrUnimplemented
@@ -1,6 +1,6 @@
1
1
  import type { Sink } from 'it-stream-types'
2
2
 
3
- import type { CallData, CallStart } from './rpcproto.js'
3
+ import type { CallData, CallStart } from './rpcproto.pb.js'
4
4
  import { CommonRPC } from './common-rpc.js'
5
5
  import { InvokeFn } from './handler.js'
6
6
  import { Mux } from './mux.js'
package/srpc/server.go CHANGED
@@ -20,6 +20,11 @@ func NewServer(mux Mux) *Server {
20
20
  }
21
21
  }
22
22
 
23
+ // GetMux returns the mux.
24
+ func (s *Server) GetMux() Mux {
25
+ return s.mux
26
+ }
27
+
23
28
  // HandleStream handles an incoming ReadWriteCloser stream.
24
29
  func (s *Server) HandleStream(ctx context.Context, rwc io.ReadWriteCloser) error {
25
30
  subCtx, subCtxCancel := context.WithCancel(ctx)
package/srpc/server.ts CHANGED
@@ -4,7 +4,7 @@ import { pipe } from 'it-pipe'
4
4
 
5
5
  import { Mux } from './mux.js'
6
6
  import { ServerRPC } from './server-rpc.js'
7
- import { Packet } from './rpcproto.js'
7
+ import { Packet } from './rpcproto.pb.js'
8
8
  import {
9
9
  parseLengthPrefixTransform,
10
10
  prependLengthPrefixTransform,
package/srpc/stream.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Packet } from './rpcproto'
1
+ import type { Packet } from './rpcproto.pb.js'
2
2
  import type { Duplex } from 'it-stream-types'
3
3
 
4
4
  // PacketHandler handles incoming packets.
package/srpc/websocket.go CHANGED
@@ -43,7 +43,7 @@ func (w *WebSocketConn) AcceptStream() (io.ReadWriteCloser, error) {
43
43
  }
44
44
 
45
45
  // OpenStream tries to open a stream with the remote.
46
- func (w *WebSocketConn) OpenStream(ctx context.Context, msgHandler func(pkt *Packet) error) (Writer, error) {
46
+ func (w *WebSocketConn) OpenStream(ctx context.Context, msgHandler PacketHandler) (Writer, error) {
47
47
  muxedStream, err := w.mconn.OpenStream(ctx)
48
48
  if err != nil {
49
49
  return nil, err