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.
@@ -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
  }
@@ -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) {
@@ -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, Uint8ArrayList | Uint8Array>;
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>;
@@ -1 +1,6 @@
1
- export {};
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.10.2",
3
+ "version": "0.10.5",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
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, Uint8ArrayList | Uint8Array>
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
+ }