starpc 0.10.2 → 0.10.5
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/dist/srpc/server.d.ts +2 -1
- package/dist/srpc/server.js +5 -0
- package/dist/srpc/stream.d.ts +2 -1
- package/dist/srpc/stream.js +6 -1
- package/package.json +1 -1
- package/srpc/server.ts +19 -1
- package/srpc/stream.ts +8 -1
package/dist/srpc/server.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ export declare class Server implements StreamHandler {
|
|
|
12
12
|
get rpcStreamHandler(): RpcStreamHandler;
|
|
13
13
|
startRpc(): ServerRPC;
|
|
14
14
|
handleStream(stream: Stream): ServerRPC;
|
|
15
|
-
handleDuplex(stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>): ServerRPC;
|
|
15
|
+
handleDuplex(stream: Duplex<Uint8ArrayList | Uint8Array, Uint8ArrayList | Uint8Array>): ServerRPC;
|
|
16
|
+
handleUint8ArrayDuplex(stream: Duplex<Uint8Array>): ServerRPC;
|
|
16
17
|
handlePacketDuplex(stream: Duplex<Uint8Array>): ServerRPC;
|
|
17
18
|
handlePacketStream(stream: Duplex<Packet>): ServerRPC;
|
|
18
19
|
}
|
package/dist/srpc/server.js
CHANGED
|
@@ -26,6 +26,11 @@ export class Server {
|
|
|
26
26
|
pipe(stream, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, rpc, encodePacketSource, prependLengthPrefixTransform(), stream);
|
|
27
27
|
return rpc;
|
|
28
28
|
}
|
|
29
|
+
handleUint8ArrayDuplex(stream) {
|
|
30
|
+
const rpc = this.startRpc();
|
|
31
|
+
pipe(stream, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, rpc, encodePacketSource, prependLengthPrefixTransform(), combineUint8ArrayListTransform(), stream);
|
|
32
|
+
return rpc;
|
|
33
|
+
}
|
|
29
34
|
// handlePacketDuplex handles an incoming Uint8Array duplex.
|
|
30
35
|
// skips the packet length prefix transform.
|
|
31
36
|
handlePacketDuplex(stream) {
|
package/dist/srpc/stream.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import type { Packet } from './rpcproto.pb.js';
|
|
|
2
2
|
import type { Duplex } from 'it-stream-types';
|
|
3
3
|
import { Uint8ArrayList } from 'uint8arraylist';
|
|
4
4
|
export declare type PacketHandler = (packet: Packet) => Promise<void>;
|
|
5
|
-
export declare type Stream = Duplex<Uint8ArrayList
|
|
5
|
+
export declare type Stream = Duplex<Uint8ArrayList | Uint8Array, Uint8Array>;
|
|
6
6
|
export declare type OpenStreamFunc = () => Promise<Stream>;
|
|
7
|
+
export declare function streamToUint8ArrayDuplex(stream: Stream): Duplex<Uint8Array, Uint8Array>;
|
package/dist/srpc/stream.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// streamToUint8ArrayDuplex converts a Stream to a Duplex<Uint8Array>
|
|
2
|
+
// This should be possible without the cast:
|
|
3
|
+
// https://github.com/achingbrain/it-stream-types/issues/28
|
|
4
|
+
export function streamToUint8ArrayDuplex(stream) {
|
|
5
|
+
return stream; // eslint-disable-line
|
|
6
|
+
}
|
package/package.json
CHANGED
package/srpc/server.ts
CHANGED
|
@@ -43,7 +43,7 @@ export class Server implements StreamHandler {
|
|
|
43
43
|
|
|
44
44
|
// handleDuplex handles an incoming message duplex.
|
|
45
45
|
public handleDuplex(
|
|
46
|
-
stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>
|
|
46
|
+
stream: Duplex<Uint8ArrayList | Uint8Array, Uint8ArrayList | Uint8Array>
|
|
47
47
|
): ServerRPC {
|
|
48
48
|
const rpc = this.startRpc()
|
|
49
49
|
pipe(
|
|
@@ -59,6 +59,24 @@ export class Server implements StreamHandler {
|
|
|
59
59
|
return rpc
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
public handleUint8ArrayDuplex(
|
|
63
|
+
stream: Duplex<Uint8Array>
|
|
64
|
+
): ServerRPC {
|
|
65
|
+
const rpc = this.startRpc()
|
|
66
|
+
pipe(
|
|
67
|
+
stream,
|
|
68
|
+
parseLengthPrefixTransform(),
|
|
69
|
+
combineUint8ArrayListTransform(),
|
|
70
|
+
decodePacketSource,
|
|
71
|
+
rpc,
|
|
72
|
+
encodePacketSource,
|
|
73
|
+
prependLengthPrefixTransform(),
|
|
74
|
+
combineUint8ArrayListTransform(),
|
|
75
|
+
stream
|
|
76
|
+
)
|
|
77
|
+
return rpc
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
// handlePacketDuplex handles an incoming Uint8Array duplex.
|
|
63
81
|
// skips the packet length prefix transform.
|
|
64
82
|
public handlePacketDuplex(stream: Duplex<Uint8Array>): ServerRPC {
|
package/srpc/stream.ts
CHANGED
|
@@ -6,7 +6,14 @@ import { Uint8ArrayList } from 'uint8arraylist'
|
|
|
6
6
|
export type PacketHandler = (packet: Packet) => Promise<void>
|
|
7
7
|
|
|
8
8
|
// Stream is an open connection.
|
|
9
|
-
export type Stream = Duplex<Uint8ArrayList
|
|
9
|
+
export type Stream = Duplex<Uint8ArrayList | Uint8Array, Uint8Array>
|
|
10
10
|
|
|
11
11
|
// OpenStreamFunc is a function to start a new RPC by opening a Stream.
|
|
12
12
|
export type OpenStreamFunc = () => Promise<Stream>
|
|
13
|
+
|
|
14
|
+
// streamToUint8ArrayDuplex converts a Stream to a Duplex<Uint8Array>
|
|
15
|
+
// This should be possible without the cast:
|
|
16
|
+
// https://github.com/achingbrain/it-stream-types/issues/28
|
|
17
|
+
export function streamToUint8ArrayDuplex(stream: Stream): Duplex<Uint8Array, Uint8Array> {
|
|
18
|
+
return stream as Duplex<Uint8Array> // eslint-disable-line
|
|
19
|
+
}
|