starpc 0.5.2 → 0.6.2
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/Makefile +1 -0
- package/dist/echo/server.js +1 -1
- package/dist/rpcstream/index.d.ts +2 -2
- package/dist/rpcstream/index.js +2 -2
- package/dist/rpcstream/rpcstream.d.ts +3 -3
- package/dist/rpcstream/rpcstream.js +7 -5
- package/dist/srpc/server.d.ts +2 -0
- package/dist/srpc/server.js +4 -0
- package/echo/server.ts +3 -3
- package/package.json +5 -5
- package/srpc/server.ts +6 -0
- package/patches/ts-proto+1.116.0.patch +0 -14
package/Makefile
CHANGED
|
@@ -106,6 +106,7 @@ gents: $(PROTOWRAP) node_modules
|
|
|
106
106
|
--ts_proto_out=$$(pwd)/vendor \
|
|
107
107
|
--ts_proto_opt=esModuleInterop=true \
|
|
108
108
|
--ts_proto_opt=fileSuffix=.pb \
|
|
109
|
+
--ts_proto_opt=importSuffix=.js \
|
|
109
110
|
--ts_proto_opt=forceLong=long \
|
|
110
111
|
--ts_proto_opt=oneof=unions \
|
|
111
112
|
--ts_proto_opt=outputServices=default,outputServices=generic-definitions \
|
package/dist/echo/server.js
CHANGED
|
@@ -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';
|
package/dist/rpcstream/index.js
CHANGED
|
@@ -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
|
|
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
|
|
52
|
+
let handler = null;
|
|
53
53
|
let err;
|
|
54
54
|
try {
|
|
55
|
-
|
|
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 (!
|
|
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
|
-
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
handler(rpcStream);
|
|
88
|
+
}, 1);
|
|
87
89
|
// process packets
|
|
88
90
|
for await (const packet of packetSink) {
|
|
89
91
|
yield* [packet];
|
package/dist/srpc/server.d.ts
CHANGED
|
@@ -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;
|
package/dist/srpc/server.js
CHANGED
|
@@ -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/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<
|
|
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.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
"singleQuote": true
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^5.30.
|
|
62
|
-
"@typescript-eslint/parser": "^5.30.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
62
|
+
"@typescript-eslint/parser": "^5.30.5",
|
|
63
63
|
"bufferutil": "^4.0.6",
|
|
64
64
|
"depcheck": "^1.4.3",
|
|
65
65
|
"esbuild": "^0.14.48",
|
|
66
|
-
"eslint": "^8.
|
|
66
|
+
"eslint": "^8.19.0",
|
|
67
67
|
"eslint-config-prettier": "^8.5.0",
|
|
68
68
|
"prettier": "^2.7.1",
|
|
69
69
|
"rimraf": "^3.0.2",
|
|
70
|
-
"ts-proto": "^1.
|
|
70
|
+
"ts-proto": "^1.117.0",
|
|
71
71
|
"typescript": "^4.7.4",
|
|
72
72
|
"utf-8-validate": "^5.0.9"
|
|
73
73
|
},
|
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
|
-
}
|