starpc 0.36.2 → 0.36.4

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/README.md CHANGED
@@ -166,7 +166,7 @@ import { pushable } from 'it-pushable'
166
166
  const mux = createMux()
167
167
  const echoer = new EchoerServer()
168
168
  mux.register(createHandler(EchoerDefinition, echoer))
169
- const server = new Server(mux.lookupMethodFunc)
169
+ const server = new Server(mux.lookupMethod)
170
170
 
171
171
  // Create the client connection to the server with an in-memory pipe.
172
172
  const clientConn = new Conn()
@@ -148,7 +148,12 @@ export class CommonRPC {
148
148
  }
149
149
  this.closed = err ?? true;
150
150
  // note: this does nothing if _source is already ended.
151
- await this.writeCallCancel();
151
+ if (err && err.message) {
152
+ await this.writeCallData(undefined, true, err.message);
153
+ }
154
+ else {
155
+ await this.writeCallCancel();
156
+ }
152
157
  this._source.end();
153
158
  this._rpcDataSource.end(err);
154
159
  }
@@ -7,10 +7,10 @@ export declare function createMux(): StaticMux;
7
7
  export declare class StaticMux implements Mux {
8
8
  private services;
9
9
  private lookups;
10
- get lookupMethodFunc(): LookupMethod;
10
+ get lookupMethod(): LookupMethod;
11
11
  register(handler: Handler): void;
12
12
  registerLookupMethod(lookupMethod: LookupMethod): void;
13
- lookupMethod(serviceID: string, methodID: string): Promise<InvokeFn | null>;
13
+ private _lookupMethod;
14
14
  private lookupViaMap;
15
15
  private lookupViaLookups;
16
16
  }
package/dist/srpc/mux.js CHANGED
@@ -10,9 +10,9 @@ export class StaticMux {
10
10
  // lookups is the list of lookup methods to call.
11
11
  // called if the method is not resolved by the services list.
12
12
  lookups = [];
13
- // lookupMethodFunc implements the LookupMethod type.
14
- get lookupMethodFunc() {
15
- return this.lookupMethod.bind(this);
13
+ // lookupMethod implements the LookupMethod type.
14
+ get lookupMethod() {
15
+ return this._lookupMethod.bind(this);
16
16
  }
17
17
  register(handler) {
18
18
  const serviceID = handler?.getServiceID();
@@ -30,7 +30,7 @@ export class StaticMux {
30
30
  registerLookupMethod(lookupMethod) {
31
31
  this.lookups.push(lookupMethod);
32
32
  }
33
- async lookupMethod(serviceID, methodID) {
33
+ async _lookupMethod(serviceID, methodID) {
34
34
  if (serviceID) {
35
35
  const invokeFn = await this.lookupViaMap(serviceID, methodID);
36
36
  if (invokeFn) {
@@ -7,7 +7,7 @@ describe('srpc server', () => {
7
7
  let client;
8
8
  beforeEach(async () => {
9
9
  const mux = createMux();
10
- const server = new Server(mux.lookupMethodFunc);
10
+ const server = new Server(mux.lookupMethod);
11
11
  const echoer = new EchoerServer(server);
12
12
  mux.register(createHandler(EchoerDefinition, echoer));
13
13
  // StreamConn is unnecessary since ChannelStream has packet framing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.36.2",
3
+ "version": "0.36.4",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -116,7 +116,7 @@ func (c *commonRPC) ReadOne() ([]byte, error) {
116
116
 
117
117
  // WriteCallData writes a call data packet.
118
118
  func (c *commonRPC) WriteCallData(data []byte, complete bool, err error) error {
119
- outPkt := NewCallDataPacket(data, len(data) == 0, false, nil)
119
+ outPkt := NewCallDataPacket(data, len(data) == 0, complete, err)
120
120
  return c.writer.WritePacket(outPkt)
121
121
  }
122
122
 
@@ -176,7 +176,11 @@ export class CommonRPC {
176
176
  }
177
177
  this.closed = err ?? true
178
178
  // note: this does nothing if _source is already ended.
179
- await this.writeCallCancel()
179
+ if (err && err.message) {
180
+ await this.writeCallData(undefined, true, err.message)
181
+ } else {
182
+ await this.writeCallCancel()
183
+ }
180
184
  this._source.end()
181
185
  this._rpcDataSource.end(err)
182
186
  }
package/srpc/mux.ts CHANGED
@@ -30,9 +30,9 @@ export class StaticMux implements Mux {
30
30
  // called if the method is not resolved by the services list.
31
31
  private lookups: LookupMethod[] = []
32
32
 
33
- // lookupMethodFunc implements the LookupMethod type.
34
- public get lookupMethodFunc(): LookupMethod {
35
- return this.lookupMethod.bind(this)
33
+ // lookupMethod implements the LookupMethod type.
34
+ public get lookupMethod(): LookupMethod {
35
+ return this._lookupMethod.bind(this)
36
36
  }
37
37
 
38
38
  public register(handler: Handler): void {
@@ -53,7 +53,7 @@ export class StaticMux implements Mux {
53
53
  this.lookups.push(lookupMethod)
54
54
  }
55
55
 
56
- public async lookupMethod(
56
+ private async _lookupMethod(
57
57
  serviceID: string,
58
58
  methodID: string,
59
59
  ): Promise<InvokeFn | null> {
@@ -21,7 +21,7 @@ describe('srpc server', () => {
21
21
 
22
22
  beforeEach(async () => {
23
23
  const mux = createMux()
24
- const server = new Server(mux.lookupMethodFunc)
24
+ const server = new Server(mux.lookupMethod)
25
25
  const echoer = new EchoerServer(server)
26
26
  mux.register(createHandler(EchoerDefinition, echoer))
27
27