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 +1 -1
- package/dist/srpc/common-rpc.js +6 -1
- package/dist/srpc/mux.d.ts +2 -2
- package/dist/srpc/mux.js +4 -4
- package/dist/srpc/server.test.js +1 -1
- package/package.json +1 -1
- package/srpc/common-rpc.go +1 -1
- package/srpc/common-rpc.ts +5 -1
- package/srpc/mux.ts +4 -4
- package/srpc/server.test.ts +1 -1
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.
|
|
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()
|
package/dist/srpc/common-rpc.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/dist/srpc/mux.d.ts
CHANGED
|
@@ -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
|
|
10
|
+
get lookupMethod(): LookupMethod;
|
|
11
11
|
register(handler: Handler): void;
|
|
12
12
|
registerLookupMethod(lookupMethod: LookupMethod): void;
|
|
13
|
-
|
|
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
|
-
//
|
|
14
|
-
get
|
|
15
|
-
return 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
|
|
33
|
+
async _lookupMethod(serviceID, methodID) {
|
|
34
34
|
if (serviceID) {
|
|
35
35
|
const invokeFn = await this.lookupViaMap(serviceID, methodID);
|
|
36
36
|
if (invokeFn) {
|
package/dist/srpc/server.test.js
CHANGED
|
@@ -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.
|
|
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
package/srpc/common-rpc.go
CHANGED
|
@@ -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,
|
|
119
|
+
outPkt := NewCallDataPacket(data, len(data) == 0, complete, err)
|
|
120
120
|
return c.writer.WritePacket(outPkt)
|
|
121
121
|
}
|
|
122
122
|
|
package/srpc/common-rpc.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
//
|
|
34
|
-
public get
|
|
35
|
-
return 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
|
-
|
|
56
|
+
private async _lookupMethod(
|
|
57
57
|
serviceID: string,
|
|
58
58
|
methodID: string,
|
|
59
59
|
): Promise<InvokeFn | null> {
|
package/srpc/server.test.ts
CHANGED
|
@@ -21,7 +21,7 @@ describe('srpc server', () => {
|
|
|
21
21
|
|
|
22
22
|
beforeEach(async () => {
|
|
23
23
|
const mux = createMux()
|
|
24
|
-
const server = new Server(mux.
|
|
24
|
+
const server = new Server(mux.lookupMethod)
|
|
25
25
|
const echoer = new EchoerServer(server)
|
|
26
26
|
mux.register(createHandler(EchoerDefinition, echoer))
|
|
27
27
|
|