starpc 0.37.0 → 0.38.0

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.
@@ -1,4 +1,4 @@
1
- import type { MessageType } from "@aptre/protobuf-es-lite";
1
+ import type { MessageType } from '@aptre/protobuf-es-lite';
2
2
  export declare const protobufPackage = "echo";
3
3
  /**
4
4
  * EchoMsg is the message body for Echo.
@@ -1,14 +1,13 @@
1
1
  // @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
2
2
  // @generated from file github.com/aperturerobotics/starpc/echo/echo.proto (package echo, syntax proto3)
3
3
  /* eslint-disable */
4
- import { createMessageType, ScalarType } from "@aptre/protobuf-es-lite";
5
- export const protobufPackage = "echo";
6
- ;
4
+ import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
5
+ export const protobufPackage = 'echo';
7
6
  // EchoMsg contains the message type declaration for EchoMsg.
8
7
  export const EchoMsg = createMessageType({
9
- typeName: "echo.EchoMsg",
8
+ typeName: 'echo.EchoMsg',
10
9
  fields: [
11
- { no: 1, name: "body", kind: "scalar", T: ScalarType.STRING },
10
+ { no: 1, name: 'body', kind: 'scalar', T: ScalarType.STRING },
12
11
  ],
13
12
  packedByDefault: true,
14
13
  });
@@ -1,7 +1,7 @@
1
- import { EchoMsg } from "./echo.pb.js";
2
- import { Empty, MethodKind } from "@aptre/protobuf-es-lite";
3
- import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
4
- import { MessageStream, ProtoRpc } from "starpc";
1
+ import { EchoMsg } from './echo.pb.js';
2
+ import { Empty, MethodKind } from '@aptre/protobuf-es-lite';
3
+ import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
4
+ import { MessageStream, ProtoRpc } from 'starpc';
5
5
  /**
6
6
  * Echoer service returns the given message.
7
7
  *
@@ -1,17 +1,17 @@
1
1
  // @generated by protoc-gen-es-starpc none with parameter "target=ts,ts_nocheck=false"
2
2
  // @generated from file github.com/aperturerobotics/starpc/echo/echo.proto (package echo, syntax proto3)
3
3
  /* eslint-disable */
4
- import { EchoMsg } from "./echo.pb.js";
5
- import { Empty, MethodKind } from "@aptre/protobuf-es-lite";
6
- import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
7
- import { buildDecodeMessageTransform, buildEncodeMessageTransform } from "starpc";
4
+ import { EchoMsg } from './echo.pb.js';
5
+ import { Empty, MethodKind } from '@aptre/protobuf-es-lite';
6
+ import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
7
+ import { buildDecodeMessageTransform, buildEncodeMessageTransform, } from 'starpc';
8
8
  /**
9
9
  * Echoer service returns the given message.
10
10
  *
11
11
  * @generated from service echo.Echoer
12
12
  */
13
13
  export const EchoerDefinition = {
14
- typeName: "echo.Echoer",
14
+ typeName: 'echo.Echoer',
15
15
  methods: {
16
16
  /**
17
17
  * Echo returns the given message.
@@ -19,7 +19,7 @@ export const EchoerDefinition = {
19
19
  * @generated from rpc echo.Echoer.Echo
20
20
  */
21
21
  Echo: {
22
- name: "Echo",
22
+ name: 'Echo',
23
23
  I: EchoMsg,
24
24
  O: EchoMsg,
25
25
  kind: MethodKind.Unary,
@@ -30,7 +30,7 @@ export const EchoerDefinition = {
30
30
  * @generated from rpc echo.Echoer.EchoServerStream
31
31
  */
32
32
  EchoServerStream: {
33
- name: "EchoServerStream",
33
+ name: 'EchoServerStream',
34
34
  I: EchoMsg,
35
35
  O: EchoMsg,
36
36
  kind: MethodKind.ServerStreaming,
@@ -41,7 +41,7 @@ export const EchoerDefinition = {
41
41
  * @generated from rpc echo.Echoer.EchoClientStream
42
42
  */
43
43
  EchoClientStream: {
44
- name: "EchoClientStream",
44
+ name: 'EchoClientStream',
45
45
  I: EchoMsg,
46
46
  O: EchoMsg,
47
47
  kind: MethodKind.ClientStreaming,
@@ -52,7 +52,7 @@ export const EchoerDefinition = {
52
52
  * @generated from rpc echo.Echoer.EchoBidiStream
53
53
  */
54
54
  EchoBidiStream: {
55
- name: "EchoBidiStream",
55
+ name: 'EchoBidiStream',
56
56
  I: EchoMsg,
57
57
  O: EchoMsg,
58
58
  kind: MethodKind.BiDiStreaming,
@@ -63,7 +63,7 @@ export const EchoerDefinition = {
63
63
  * @generated from rpc echo.Echoer.RpcStream
64
64
  */
65
65
  RpcStream: {
66
- name: "RpcStream",
66
+ name: 'RpcStream',
67
67
  I: RpcStreamPacket,
68
68
  O: RpcStreamPacket,
69
69
  kind: MethodKind.BiDiStreaming,
@@ -74,12 +74,12 @@ export const EchoerDefinition = {
74
74
  * @generated from rpc echo.Echoer.DoNothing
75
75
  */
76
76
  DoNothing: {
77
- name: "DoNothing",
77
+ name: 'DoNothing',
78
78
  I: Empty,
79
79
  O: Empty,
80
80
  kind: MethodKind.Unary,
81
81
  },
82
- }
82
+ },
83
83
  };
84
84
  export const EchoerServiceName = EchoerDefinition.typeName;
85
85
  export class EchoerClient {
@@ -2,12 +2,12 @@ import { Pushable } from 'it-pushable';
2
2
  import { Source, Sink } from 'it-stream-types';
3
3
  import { Message } from '@aptre/protobuf-es-lite';
4
4
  import { RpcStreamPacket } from './rpcstream.pb.js';
5
- import { OpenStreamFunc, PacketStream } from '../srpc/stream.js';
5
+ import { OpenStreamFunc, PacketStream, HandleStreamFunc } from '../srpc/stream.js';
6
6
  import { MessageStream } from '../srpc/message.js';
7
7
  export type RpcStreamCaller = (request: MessageStream<RpcStreamPacket>) => MessageStream<RpcStreamPacket>;
8
8
  export declare function openRpcStream(componentId: string, caller: RpcStreamCaller, waitAck?: boolean): Promise<PacketStream>;
9
9
  export declare function buildRpcStreamOpenStream(componentId: string, caller: RpcStreamCaller): OpenStreamFunc;
10
- export type RpcStreamHandler = (stream: PacketStream) => Promise<void>;
10
+ export type RpcStreamHandler = HandleStreamFunc;
11
11
  export type RpcStreamGetter = (componentId: string) => Promise<RpcStreamHandler | null>;
12
12
  export declare function handleRpcStream(packetRx: AsyncIterator<Message<RpcStreamPacket>>, getter: RpcStreamGetter): AsyncIterable<Message<RpcStreamPacket>>;
13
13
  export declare class RpcStream implements PacketStream {
@@ -1,4 +1,4 @@
1
- import type { MessageType } from "@aptre/protobuf-es-lite";
1
+ import type { MessageType } from '@aptre/protobuf-es-lite';
2
2
  export declare const protobufPackage = "rpcstream";
3
3
  /**
4
4
  * RpcStreamInit is the first message in a RPC stream.
@@ -48,7 +48,7 @@ export interface RpcStreamPacket {
48
48
  * @generated from field: rpcstream.RpcStreamInit init = 1;
49
49
  */
50
50
  value: RpcStreamInit;
51
- case: "init";
51
+ case: 'init';
52
52
  } | {
53
53
  /**
54
54
  * Ack is sent in response to Init.
@@ -57,7 +57,7 @@ export interface RpcStreamPacket {
57
57
  * @generated from field: rpcstream.RpcAck ack = 2;
58
58
  */
59
59
  value: RpcAck;
60
- case: "ack";
60
+ case: 'ack';
61
61
  } | {
62
62
  /**
63
63
  * Data is the encapsulated data packet.
@@ -65,7 +65,7 @@ export interface RpcStreamPacket {
65
65
  * @generated from field: bytes data = 3;
66
66
  */
67
67
  value: Uint8Array;
68
- case: "data";
68
+ case: 'data';
69
69
  };
70
70
  }
71
71
  export declare const RpcStreamPacket: MessageType<RpcStreamPacket>;
@@ -1,34 +1,37 @@
1
1
  // @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
2
2
  // @generated from file github.com/aperturerobotics/starpc/rpcstream/rpcstream.proto (package rpcstream, syntax proto3)
3
3
  /* eslint-disable */
4
- import { createMessageType, ScalarType } from "@aptre/protobuf-es-lite";
5
- export const protobufPackage = "rpcstream";
6
- ;
4
+ import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
5
+ export const protobufPackage = 'rpcstream';
7
6
  // RpcStreamInit contains the message type declaration for RpcStreamInit.
8
7
  export const RpcStreamInit = createMessageType({
9
- typeName: "rpcstream.RpcStreamInit",
8
+ typeName: 'rpcstream.RpcStreamInit',
10
9
  fields: [
11
- { no: 1, name: "component_id", kind: "scalar", T: ScalarType.STRING },
10
+ { no: 1, name: 'component_id', kind: 'scalar', T: ScalarType.STRING },
12
11
  ],
13
12
  packedByDefault: true,
14
13
  });
15
- ;
16
14
  // RpcAck contains the message type declaration for RpcAck.
17
15
  export const RpcAck = createMessageType({
18
- typeName: "rpcstream.RpcAck",
16
+ typeName: 'rpcstream.RpcAck',
19
17
  fields: [
20
- { no: 1, name: "error", kind: "scalar", T: ScalarType.STRING },
18
+ { no: 1, name: 'error', kind: 'scalar', T: ScalarType.STRING },
21
19
  ],
22
20
  packedByDefault: true,
23
21
  });
24
- ;
25
22
  // RpcStreamPacket contains the message type declaration for RpcStreamPacket.
26
23
  export const RpcStreamPacket = createMessageType({
27
- typeName: "rpcstream.RpcStreamPacket",
24
+ typeName: 'rpcstream.RpcStreamPacket',
28
25
  fields: [
29
- { no: 1, name: "init", kind: "message", T: () => RpcStreamInit, oneof: "body" },
30
- { no: 2, name: "ack", kind: "message", T: () => RpcAck, oneof: "body" },
31
- { no: 3, name: "data", kind: "scalar", T: ScalarType.BYTES, oneof: "body" },
26
+ {
27
+ no: 1,
28
+ name: 'init',
29
+ kind: 'message',
30
+ T: () => RpcStreamInit,
31
+ oneof: 'body',
32
+ },
33
+ { no: 2, name: 'ack', kind: 'message', T: () => RpcAck, oneof: 'body' },
34
+ { no: 3, name: 'data', kind: 'scalar', T: ScalarType.BYTES, oneof: 'body' },
32
35
  ],
33
36
  packedByDefault: true,
34
37
  });
@@ -0,0 +1,6 @@
1
+ import { HandleStreamFunc } from './stream.js';
2
+ import { ValueCtr } from './value-ctr.js';
3
+ export declare class HandleStreamCtr extends ValueCtr<HandleStreamFunc> {
4
+ constructor(handleStreamFn?: HandleStreamFunc);
5
+ get handleStreamFunc(): HandleStreamFunc;
6
+ }
@@ -0,0 +1,17 @@
1
+ import { ValueCtr } from './value-ctr.js';
2
+ // HandleStreamCtr contains an OpenStream func which can be awaited.
3
+ export class HandleStreamCtr extends ValueCtr {
4
+ constructor(handleStreamFn) {
5
+ super(handleStreamFn);
6
+ }
7
+ // handleStreamFunc returns an HandleStreamFunc which waits for the underlying HandleStreamFunc.
8
+ get handleStreamFunc() {
9
+ return async (stream) => {
10
+ let handleFn = this.value;
11
+ if (!handleFn) {
12
+ handleFn = await this.wait();
13
+ }
14
+ return handleFn(stream);
15
+ };
16
+ }
17
+ }
@@ -3,7 +3,7 @@ export { Client } from './client.js';
3
3
  export { Server } from './server.js';
4
4
  export { StreamConn, StreamConnParams, StreamHandler } from './conn.js';
5
5
  export { WebSocketConn } from './websocket.js';
6
- export type { PacketHandler, OpenStreamFunc, PacketStream, streamToPacketStream, } from './stream.js';
6
+ export type { PacketHandler, OpenStreamFunc, HandleStreamFunc, PacketStream, streamToPacketStream, } from './stream.js';
7
7
  export { Handler, InvokeFn, MethodMap, StaticHandler, createHandler, } from './handler.js';
8
8
  export { MethodProto, createInvokeFn } from './invoker.js';
9
9
  export { Packet, CallStart, CallData } from './rpcproto.pb.js';
@@ -16,6 +16,7 @@ export { parseLengthPrefixTransform, prependLengthPrefixTransform, decodePacketS
16
16
  export { combineUint8ArrayListTransform } from './array-list.js';
17
17
  export { ValueCtr } from './value-ctr.js';
18
18
  export { OpenStreamCtr } from './open-stream-ctr.js';
19
+ export { HandleStreamCtr } from './handle-stream-ctr.js';
19
20
  export { writeToPushable, buildPushableSink, messagePushable, } from './pushable.js';
20
21
  export { Watchdog } from './watchdog.js';
21
22
  export { ProtoRpc } from './proto-rpc.js';
@@ -15,5 +15,6 @@ export { parseLengthPrefixTransform, prependLengthPrefixTransform, decodePacketS
15
15
  export { combineUint8ArrayListTransform } from './array-list.js';
16
16
  export { ValueCtr } from './value-ctr.js';
17
17
  export { OpenStreamCtr } from './open-stream-ctr.js';
18
+ export { HandleStreamCtr } from './handle-stream-ctr.js';
18
19
  export { writeToPushable, buildPushableSink, messagePushable, } from './pushable.js';
19
20
  export { Watchdog } from './watchdog.js';
@@ -1,4 +1,4 @@
1
- import type { MessageType } from "@aptre/protobuf-es-lite";
1
+ import type { MessageType } from '@aptre/protobuf-es-lite';
2
2
  export declare const protobufPackage = "srpc";
3
3
  /**
4
4
  * CallStart requests starting a new RPC call.
@@ -89,7 +89,7 @@ export interface Packet {
89
89
  * @generated from field: srpc.CallStart call_start = 1;
90
90
  */
91
91
  value: CallStart;
92
- case: "callStart";
92
+ case: 'callStart';
93
93
  } | {
94
94
  /**
95
95
  * CallData is a message in a streaming RPC sequence.
@@ -97,7 +97,7 @@ export interface Packet {
97
97
  * @generated from field: srpc.CallData call_data = 2;
98
98
  */
99
99
  value: CallData;
100
- case: "callData";
100
+ case: 'callData';
101
101
  } | {
102
102
  /**
103
103
  * CallCancel cancels the call.
@@ -105,7 +105,7 @@ export interface Packet {
105
105
  * @generated from field: bool call_cancel = 3;
106
106
  */
107
107
  value: boolean;
108
- case: "callCancel";
108
+ case: 'callCancel';
109
109
  };
110
110
  }
111
111
  export declare const Packet: MessageType<Packet>;
@@ -1,40 +1,55 @@
1
1
  // @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
2
2
  // @generated from file github.com/aperturerobotics/starpc/srpc/rpcproto.proto (package srpc, syntax proto3)
3
3
  /* eslint-disable */
4
- import { createMessageType, ScalarType } from "@aptre/protobuf-es-lite";
5
- export const protobufPackage = "srpc";
6
- ;
4
+ import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
5
+ export const protobufPackage = 'srpc';
7
6
  // CallStart contains the message type declaration for CallStart.
8
7
  export const CallStart = createMessageType({
9
- typeName: "srpc.CallStart",
8
+ typeName: 'srpc.CallStart',
10
9
  fields: [
11
- { no: 1, name: "rpc_service", kind: "scalar", T: ScalarType.STRING },
12
- { no: 2, name: "rpc_method", kind: "scalar", T: ScalarType.STRING },
13
- { no: 3, name: "data", kind: "scalar", T: ScalarType.BYTES },
14
- { no: 4, name: "data_is_zero", kind: "scalar", T: ScalarType.BOOL },
10
+ { no: 1, name: 'rpc_service', kind: 'scalar', T: ScalarType.STRING },
11
+ { no: 2, name: 'rpc_method', kind: 'scalar', T: ScalarType.STRING },
12
+ { no: 3, name: 'data', kind: 'scalar', T: ScalarType.BYTES },
13
+ { no: 4, name: 'data_is_zero', kind: 'scalar', T: ScalarType.BOOL },
15
14
  ],
16
15
  packedByDefault: true,
17
16
  });
18
- ;
19
17
  // CallData contains the message type declaration for CallData.
20
18
  export const CallData = createMessageType({
21
- typeName: "srpc.CallData",
19
+ typeName: 'srpc.CallData',
22
20
  fields: [
23
- { no: 1, name: "data", kind: "scalar", T: ScalarType.BYTES },
24
- { no: 2, name: "data_is_zero", kind: "scalar", T: ScalarType.BOOL },
25
- { no: 3, name: "complete", kind: "scalar", T: ScalarType.BOOL },
26
- { no: 4, name: "error", kind: "scalar", T: ScalarType.STRING },
21
+ { no: 1, name: 'data', kind: 'scalar', T: ScalarType.BYTES },
22
+ { no: 2, name: 'data_is_zero', kind: 'scalar', T: ScalarType.BOOL },
23
+ { no: 3, name: 'complete', kind: 'scalar', T: ScalarType.BOOL },
24
+ { no: 4, name: 'error', kind: 'scalar', T: ScalarType.STRING },
27
25
  ],
28
26
  packedByDefault: true,
29
27
  });
30
- ;
31
28
  // Packet contains the message type declaration for Packet.
32
29
  export const Packet = createMessageType({
33
- typeName: "srpc.Packet",
30
+ typeName: 'srpc.Packet',
34
31
  fields: [
35
- { no: 1, name: "call_start", kind: "message", T: () => CallStart, oneof: "body" },
36
- { no: 2, name: "call_data", kind: "message", T: () => CallData, oneof: "body" },
37
- { no: 3, name: "call_cancel", kind: "scalar", T: ScalarType.BOOL, oneof: "body" },
32
+ {
33
+ no: 1,
34
+ name: 'call_start',
35
+ kind: 'message',
36
+ T: () => CallStart,
37
+ oneof: 'body',
38
+ },
39
+ {
40
+ no: 2,
41
+ name: 'call_data',
42
+ kind: 'message',
43
+ T: () => CallData,
44
+ oneof: 'body',
45
+ },
46
+ {
47
+ no: 3,
48
+ name: 'call_cancel',
49
+ kind: 'scalar',
50
+ T: ScalarType.BOOL,
51
+ oneof: 'body',
52
+ },
38
53
  ],
39
54
  packedByDefault: true,
40
55
  });
@@ -4,4 +4,5 @@ import type { Packet } from './rpcproto.pb.js';
4
4
  export type PacketHandler = (packet: Packet) => Promise<void>;
5
5
  export type PacketStream = Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>;
6
6
  export type OpenStreamFunc = () => Promise<PacketStream>;
7
+ export type HandleStreamFunc = (ch: PacketStream) => Promise<void>;
7
8
  export declare function streamToPacketStream(stream: Stream): PacketStream;
package/echo/echo.pb.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  // @generated from file github.com/aperturerobotics/starpc/echo/echo.proto (package echo, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
5
- import type { MessageType, PartialFieldInfo } from "@aptre/protobuf-es-lite";
6
- import { createMessageType, ScalarType } from "@aptre/protobuf-es-lite";
5
+ import type { MessageType, PartialFieldInfo } from '@aptre/protobuf-es-lite'
6
+ import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite'
7
7
 
8
- export const protobufPackage = "echo";
8
+ export const protobufPackage = 'echo'
9
9
 
10
10
  /**
11
11
  * EchoMsg is the message body for Echo.
@@ -16,16 +16,14 @@ export interface EchoMsg {
16
16
  /**
17
17
  * @generated from field: string body = 1;
18
18
  */
19
- body?: string;
20
-
21
- };
19
+ body?: string
20
+ }
22
21
 
23
22
  // EchoMsg contains the message type declaration for EchoMsg.
24
23
  export const EchoMsg: MessageType<EchoMsg> = createMessageType({
25
- typeName: "echo.EchoMsg",
26
- fields: [
27
- { no: 1, name: "body", kind: "scalar", T: ScalarType.STRING },
28
- ] as readonly PartialFieldInfo[],
29
- packedByDefault: true,
30
- });
31
-
24
+ typeName: 'echo.EchoMsg',
25
+ fields: [
26
+ { no: 1, name: 'body', kind: 'scalar', T: ScalarType.STRING },
27
+ ] as readonly PartialFieldInfo[],
28
+ packedByDefault: true,
29
+ })
@@ -2,10 +2,15 @@
2
2
  // @generated from file github.com/aperturerobotics/starpc/echo/echo.proto (package echo, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
5
- import { EchoMsg } from "./echo.pb.js";
6
- import { Empty, MethodKind } from "@aptre/protobuf-es-lite";
7
- import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
8
- import { buildDecodeMessageTransform, buildEncodeMessageTransform, MessageStream, ProtoRpc } from "starpc";
5
+ import { EchoMsg } from './echo.pb.js'
6
+ import { Empty, MethodKind } from '@aptre/protobuf-es-lite'
7
+ import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
8
+ import {
9
+ buildDecodeMessageTransform,
10
+ buildEncodeMessageTransform,
11
+ MessageStream,
12
+ ProtoRpc,
13
+ } from 'starpc'
9
14
 
10
15
  /**
11
16
  * Echoer service returns the given message.
@@ -13,7 +18,7 @@ import { buildDecodeMessageTransform, buildEncodeMessageTransform, MessageStream
13
18
  * @generated from service echo.Echoer
14
19
  */
15
20
  export const EchoerDefinition = {
16
- typeName: "echo.Echoer",
21
+ typeName: 'echo.Echoer',
17
22
  methods: {
18
23
  /**
19
24
  * Echo returns the given message.
@@ -21,7 +26,7 @@ export const EchoerDefinition = {
21
26
  * @generated from rpc echo.Echoer.Echo
22
27
  */
23
28
  Echo: {
24
- name: "Echo",
29
+ name: 'Echo',
25
30
  I: EchoMsg,
26
31
  O: EchoMsg,
27
32
  kind: MethodKind.Unary,
@@ -32,7 +37,7 @@ export const EchoerDefinition = {
32
37
  * @generated from rpc echo.Echoer.EchoServerStream
33
38
  */
34
39
  EchoServerStream: {
35
- name: "EchoServerStream",
40
+ name: 'EchoServerStream',
36
41
  I: EchoMsg,
37
42
  O: EchoMsg,
38
43
  kind: MethodKind.ServerStreaming,
@@ -43,7 +48,7 @@ export const EchoerDefinition = {
43
48
  * @generated from rpc echo.Echoer.EchoClientStream
44
49
  */
45
50
  EchoClientStream: {
46
- name: "EchoClientStream",
51
+ name: 'EchoClientStream',
47
52
  I: EchoMsg,
48
53
  O: EchoMsg,
49
54
  kind: MethodKind.ClientStreaming,
@@ -54,7 +59,7 @@ export const EchoerDefinition = {
54
59
  * @generated from rpc echo.Echoer.EchoBidiStream
55
60
  */
56
61
  EchoBidiStream: {
57
- name: "EchoBidiStream",
62
+ name: 'EchoBidiStream',
58
63
  I: EchoMsg,
59
64
  O: EchoMsg,
60
65
  kind: MethodKind.BiDiStreaming,
@@ -65,7 +70,7 @@ export const EchoerDefinition = {
65
70
  * @generated from rpc echo.Echoer.RpcStream
66
71
  */
67
72
  RpcStream: {
68
- name: "RpcStream",
73
+ name: 'RpcStream',
69
74
  I: RpcStreamPacket,
70
75
  O: RpcStreamPacket,
71
76
  kind: MethodKind.BiDiStreaming,
@@ -76,13 +81,13 @@ export const EchoerDefinition = {
76
81
  * @generated from rpc echo.Echoer.DoNothing
77
82
  */
78
83
  DoNothing: {
79
- name: "DoNothing",
84
+ name: 'DoNothing',
80
85
  I: Empty,
81
86
  O: Empty,
82
87
  kind: MethodKind.Unary,
83
88
  },
84
- }
85
- } as const;
89
+ },
90
+ } as const
86
91
 
87
92
  /**
88
93
  * Echoer service returns the given message.
@@ -95,10 +100,7 @@ export interface Echoer {
95
100
  *
96
101
  * @generated from rpc echo.Echoer.Echo
97
102
  */
98
- Echo(
99
- request: EchoMsg, abortSignal?: AbortSignal
100
- ):
101
- Promise<EchoMsg>
103
+ Echo(request: EchoMsg, abortSignal?: AbortSignal): Promise<EchoMsg>
102
104
 
103
105
  /**
104
106
  * EchoServerStream is an example of a server -> client one-way stream.
@@ -106,9 +108,9 @@ Promise<EchoMsg>
106
108
  * @generated from rpc echo.Echoer.EchoServerStream
107
109
  */
108
110
  EchoServerStream(
109
- request: EchoMsg, abortSignal?: AbortSignal
110
- ):
111
- MessageStream<EchoMsg>
111
+ request: EchoMsg,
112
+ abortSignal?: AbortSignal,
113
+ ): MessageStream<EchoMsg>
112
114
 
113
115
  /**
114
116
  * EchoClientStream is an example of client->server one-way stream.
@@ -116,9 +118,9 @@ MessageStream<EchoMsg>
116
118
  * @generated from rpc echo.Echoer.EchoClientStream
117
119
  */
118
120
  EchoClientStream(
119
- request: MessageStream<EchoMsg>, abortSignal?: AbortSignal
120
- ):
121
- Promise<EchoMsg>
121
+ request: MessageStream<EchoMsg>,
122
+ abortSignal?: AbortSignal,
123
+ ): Promise<EchoMsg>
122
124
 
123
125
  /**
124
126
  * EchoBidiStream is an example of a two-way stream.
@@ -126,9 +128,9 @@ Promise<EchoMsg>
126
128
  * @generated from rpc echo.Echoer.EchoBidiStream
127
129
  */
128
130
  EchoBidiStream(
129
- request: MessageStream<EchoMsg>, abortSignal?: AbortSignal
130
- ):
131
- MessageStream<EchoMsg>
131
+ request: MessageStream<EchoMsg>,
132
+ abortSignal?: AbortSignal,
133
+ ): MessageStream<EchoMsg>
132
134
 
133
135
  /**
134
136
  * RpcStream opens a nested rpc call stream.
@@ -136,20 +138,16 @@ MessageStream<EchoMsg>
136
138
  * @generated from rpc echo.Echoer.RpcStream
137
139
  */
138
140
  RpcStream(
139
- request: MessageStream<RpcStreamPacket>, abortSignal?: AbortSignal
140
- ):
141
- MessageStream<RpcStreamPacket>
141
+ request: MessageStream<RpcStreamPacket>,
142
+ abortSignal?: AbortSignal,
143
+ ): MessageStream<RpcStreamPacket>
142
144
 
143
145
  /**
144
146
  * DoNothing does nothing.
145
147
  *
146
148
  * @generated from rpc echo.Echoer.DoNothing
147
149
  */
148
- DoNothing(
149
- request: Empty, abortSignal?: AbortSignal
150
- ):
151
- Promise<Empty>
152
-
150
+ DoNothing(request: Empty, abortSignal?: AbortSignal): Promise<Empty>
153
151
  }
154
152
 
155
153
  export const EchoerServiceName = EchoerDefinition.typeName
@@ -172,10 +170,7 @@ export class EchoerClient implements Echoer {
172
170
  *
173
171
  * @generated from rpc echo.Echoer.Echo
174
172
  */
175
- async Echo(
176
- request: EchoMsg, abortSignal?: AbortSignal
177
- ):
178
- Promise<EchoMsg> {
173
+ async Echo(request: EchoMsg, abortSignal?: AbortSignal): Promise<EchoMsg> {
179
174
  const requestMsg = EchoMsg.create(request)
180
175
  const result = await this.rpc.request(
181
176
  this.service,
@@ -192,9 +187,9 @@ Promise<EchoMsg> {
192
187
  * @generated from rpc echo.Echoer.EchoServerStream
193
188
  */
194
189
  EchoServerStream(
195
- request: EchoMsg, abortSignal?: AbortSignal
196
- ):
197
- MessageStream<EchoMsg> {
190
+ request: EchoMsg,
191
+ abortSignal?: AbortSignal,
192
+ ): MessageStream<EchoMsg> {
198
193
  const requestMsg = EchoMsg.create(request)
199
194
  const result = this.rpc.serverStreamingRequest(
200
195
  this.service,
@@ -211,9 +206,9 @@ MessageStream<EchoMsg> {
211
206
  * @generated from rpc echo.Echoer.EchoClientStream
212
207
  */
213
208
  async EchoClientStream(
214
- request: MessageStream<EchoMsg>, abortSignal?: AbortSignal
215
- ):
216
- Promise<EchoMsg> {
209
+ request: MessageStream<EchoMsg>,
210
+ abortSignal?: AbortSignal,
211
+ ): Promise<EchoMsg> {
217
212
  const result = await this.rpc.clientStreamingRequest(
218
213
  this.service,
219
214
  EchoerDefinition.methods.EchoClientStream.name,
@@ -229,9 +224,9 @@ Promise<EchoMsg> {
229
224
  * @generated from rpc echo.Echoer.EchoBidiStream
230
225
  */
231
226
  EchoBidiStream(
232
- request: MessageStream<EchoMsg>, abortSignal?: AbortSignal
233
- ):
234
- MessageStream<EchoMsg> {
227
+ request: MessageStream<EchoMsg>,
228
+ abortSignal?: AbortSignal,
229
+ ): MessageStream<EchoMsg> {
235
230
  const result = this.rpc.bidirectionalStreamingRequest(
236
231
  this.service,
237
232
  EchoerDefinition.methods.EchoBidiStream.name,
@@ -247,9 +242,9 @@ MessageStream<EchoMsg> {
247
242
  * @generated from rpc echo.Echoer.RpcStream
248
243
  */
249
244
  RpcStream(
250
- request: MessageStream<RpcStreamPacket>, abortSignal?: AbortSignal
251
- ):
252
- MessageStream<RpcStreamPacket> {
245
+ request: MessageStream<RpcStreamPacket>,
246
+ abortSignal?: AbortSignal,
247
+ ): MessageStream<RpcStreamPacket> {
253
248
  const result = this.rpc.bidirectionalStreamingRequest(
254
249
  this.service,
255
250
  EchoerDefinition.methods.RpcStream.name,
@@ -264,10 +259,7 @@ MessageStream<RpcStreamPacket> {
264
259
  *
265
260
  * @generated from rpc echo.Echoer.DoNothing
266
261
  */
267
- async DoNothing(
268
- request: Empty, abortSignal?: AbortSignal
269
- ):
270
- Promise<Empty> {
262
+ async DoNothing(request: Empty, abortSignal?: AbortSignal): Promise<Empty> {
271
263
  const requestMsg = Empty.create(request)
272
264
  const result = await this.rpc.request(
273
265
  this.service,
@@ -277,5 +269,4 @@ Promise<Empty> {
277
269
  )
278
270
  return Empty.fromBinary(result)
279
271
  }
280
-
281
272
  }
package/go.mod CHANGED
@@ -1,8 +1,8 @@
1
1
  module github.com/aperturerobotics/starpc
2
2
 
3
- go 1.23.0
3
+ go 1.24
4
4
 
5
- toolchain go1.24.0
5
+ toolchain go1.24.2
6
6
 
7
7
  replace (
8
8
  // This fork uses go-protobuf-lite and adds post-quantum crypto support.
@@ -13,16 +13,16 @@ replace (
13
13
  )
14
14
 
15
15
  require (
16
- github.com/aperturerobotics/protobuf-go-lite v0.8.0 // latest
17
- github.com/aperturerobotics/util v1.28.1 // latest
16
+ github.com/aperturerobotics/protobuf-go-lite v0.9.0 // latest
17
+ github.com/aperturerobotics/util v1.29.2 // latest
18
18
  )
19
19
 
20
20
  require (
21
- github.com/coder/websocket v1.8.12 // latest
22
- github.com/libp2p/go-libp2p v0.41.0 // latest
21
+ github.com/coder/websocket v1.8.13 // latest
22
+ github.com/libp2p/go-libp2p v0.41.1 // latest
23
23
  github.com/pkg/errors v0.9.1 // latest
24
24
  github.com/sirupsen/logrus v1.9.3 // latest
25
- google.golang.org/protobuf v1.36.5 // latest
25
+ google.golang.org/protobuf v1.36.6 // latest
26
26
  )
27
27
 
28
28
  require github.com/libp2p/go-yamux/v4 v4.0.1
@@ -43,7 +43,7 @@ require (
43
43
  github.com/multiformats/go-varint v0.0.7 // indirect
44
44
  github.com/spaolacci/murmur3 v1.1.0 // indirect
45
45
  golang.org/x/crypto v0.31.0 // indirect
46
- golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect
46
+ golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
47
47
  golang.org/x/sys v0.28.0 // indirect
48
48
  lukechampine.com/blake3 v1.3.0 // indirect
49
49
  )
package/go.sum CHANGED
@@ -2,17 +2,17 @@ github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0 h1:t
2
2
  github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0/go.mod h1:FJkAtQcP9XxqG1NNLNHKm+wLVIGSCQX2s6CEoD+w97g=
3
3
  github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008 h1:So9JeziaWKx2Fw8sK4AUN/szqKtJ0jEMhS6bU4sHbxs=
4
4
  github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008/go.mod h1:snaApCEDtrHHP6UWSLKiYNOZU9A5NyzccKenx9oZEzg=
5
- github.com/aperturerobotics/protobuf-go-lite v0.8.0 h1:SoiTAVArmOrNTX31e6CC5Bem6HuOElg3YYNhp4AAPQc=
6
- github.com/aperturerobotics/protobuf-go-lite v0.8.0/go.mod h1:y49wVEezRHg78uQ2OzLLZbtTTWuox+ChmaTuh6FLJW8=
7
- github.com/aperturerobotics/util v1.28.1 h1:FpTOt/tsawTrxDz4lrdglK47ZR2p0UM+GBB3zHhSUsc=
8
- github.com/aperturerobotics/util v1.28.1/go.mod h1:tFCW8S1eUGvEohv9IebTxq5bgVZNfaKGLV9ELa6iKbI=
9
- github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
10
- github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
5
+ github.com/aperturerobotics/protobuf-go-lite v0.9.0 h1:zY3+qG0FPZiqhmEMQbVPW3wFLJ//aitvYy1zdgO8Hwo=
6
+ github.com/aperturerobotics/protobuf-go-lite v0.9.0/go.mod h1:fULrxQxEBWKQm7vvju9AfjTp9yfHoLgwMQWTiZQ2tg0=
7
+ github.com/aperturerobotics/util v1.29.2 h1:4mF7PfltK2g9KuD5gYUx3zvfEQXA/7F/V6EIEwJA35Q=
8
+ github.com/aperturerobotics/util v1.29.2/go.mod h1:wfEm6n6evCQCGu+NjR8qINo0feaPEgeXxDZK6/oSuk8=
9
+ github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
10
+ github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
11
11
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12
12
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
13
13
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14
- github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
15
- github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
14
+ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
15
+ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
16
16
  github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
17
17
  github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
18
18
  github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
@@ -51,18 +51,18 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
51
51
  github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
52
52
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
53
53
  github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
54
- github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
55
- github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
54
+ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
55
+ github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
56
56
  golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
57
57
  golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
58
- golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrCPyJZ+eyRsABUPs1mz4=
59
- golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk=
58
+ golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
59
+ golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
60
60
  golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
61
61
  golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
62
62
  golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
63
63
  golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
64
- google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
65
- google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
64
+ google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
65
+ google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
66
66
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
67
67
  gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
68
68
  gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -45,21 +45,26 @@ func (c *commonRPC) Context() context.Context {
45
45
  // Wait waits for the RPC to finish (remote end closed the stream).
46
46
  func (c *commonRPC) Wait(ctx context.Context) error {
47
47
  for {
48
- var dataClosed bool
49
48
  var err error
50
49
  var waitCh <-chan struct{}
50
+ var rpcCtx context.Context
51
51
  c.bcast.HoldLock(func(broadcast func(), getWaitCh func() <-chan struct{}) {
52
- dataClosed, err = c.dataClosed, c.remoteErr
52
+ rpcCtx, err = c.ctx, c.remoteErr
53
53
  waitCh = getWaitCh()
54
54
  })
55
55
 
56
- if dataClosed {
56
+ if err != nil {
57
57
  return err
58
58
  }
59
+ if rpcCtx.Err() != nil {
60
+ // rpc must have ended w/o an error being set
61
+ return context.Canceled
62
+ }
59
63
 
60
64
  select {
61
65
  case <-ctx.Done():
62
66
  return context.Canceled
67
+ case <-rpcCtx.Done():
63
68
  case <-waitCh:
64
69
  }
65
70
  }
@@ -0,0 +1,20 @@
1
+ import { HandleStreamFunc } from './stream.js'
2
+ import { ValueCtr } from './value-ctr.js'
3
+
4
+ // HandleStreamCtr contains an OpenStream func which can be awaited.
5
+ export class HandleStreamCtr extends ValueCtr<HandleStreamFunc> {
6
+ constructor(handleStreamFn?: HandleStreamFunc) {
7
+ super(handleStreamFn)
8
+ }
9
+
10
+ // handleStreamFunc returns an HandleStreamFunc which waits for the underlying HandleStreamFunc.
11
+ get handleStreamFunc(): HandleStreamFunc {
12
+ return async (stream) => {
13
+ let handleFn = this.value
14
+ if (!handleFn) {
15
+ handleFn = await this.wait()
16
+ }
17
+ return handleFn(stream)
18
+ }
19
+ }
20
+ }
package/srpc/index.ts CHANGED
@@ -12,6 +12,7 @@ export { WebSocketConn } from './websocket.js'
12
12
  export type {
13
13
  PacketHandler,
14
14
  OpenStreamFunc,
15
+ HandleStreamFunc,
15
16
  PacketStream,
16
17
  streamToPacketStream,
17
18
  } from './stream.js'
@@ -65,6 +66,7 @@ export {
65
66
  export { combineUint8ArrayListTransform } from './array-list.js'
66
67
  export { ValueCtr } from './value-ctr.js'
67
68
  export { OpenStreamCtr } from './open-stream-ctr.js'
69
+ export { HandleStreamCtr } from './handle-stream-ctr.js'
68
70
  export {
69
71
  writeToPushable,
70
72
  buildPushableSink,
@@ -2,10 +2,10 @@
2
2
  // @generated from file github.com/aperturerobotics/starpc/srpc/rpcproto.proto (package srpc, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
5
- import type { MessageType, PartialFieldInfo } from "@aptre/protobuf-es-lite";
6
- import { createMessageType, ScalarType } from "@aptre/protobuf-es-lite";
5
+ import type { MessageType, PartialFieldInfo } from '@aptre/protobuf-es-lite'
6
+ import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite'
7
7
 
8
- export const protobufPackage = "srpc";
8
+ export const protobufPackage = 'srpc'
9
9
 
10
10
  /**
11
11
  * CallStart requests starting a new RPC call.
@@ -19,41 +19,40 @@ export interface CallStart {
19
19
  *
20
20
  * @generated from field: string rpc_service = 1;
21
21
  */
22
- rpcService?: string;
22
+ rpcService?: string
23
23
  /**
24
24
  * RpcMethod is the RPC method to call.
25
25
  * Must be set.
26
26
  *
27
27
  * @generated from field: string rpc_method = 2;
28
28
  */
29
- rpcMethod?: string;
29
+ rpcMethod?: string
30
30
  /**
31
31
  * Data contains the request or the first message in the stream.
32
32
  * Optional if streaming.
33
33
  *
34
34
  * @generated from field: bytes data = 3;
35
35
  */
36
- data?: Uint8Array;
36
+ data?: Uint8Array
37
37
  /**
38
38
  * DataIsZero indicates Data is set with an empty message.
39
39
  *
40
40
  * @generated from field: bool data_is_zero = 4;
41
41
  */
42
- dataIsZero?: boolean;
43
-
44
- };
42
+ dataIsZero?: boolean
43
+ }
45
44
 
46
45
  // CallStart contains the message type declaration for CallStart.
47
46
  export const CallStart: MessageType<CallStart> = createMessageType({
48
- typeName: "srpc.CallStart",
49
- fields: [
50
- { no: 1, name: "rpc_service", kind: "scalar", T: ScalarType.STRING },
51
- { no: 2, name: "rpc_method", kind: "scalar", T: ScalarType.STRING },
52
- { no: 3, name: "data", kind: "scalar", T: ScalarType.BYTES },
53
- { no: 4, name: "data_is_zero", kind: "scalar", T: ScalarType.BOOL },
54
- ] as readonly PartialFieldInfo[],
55
- packedByDefault: true,
56
- });
47
+ typeName: 'srpc.CallStart',
48
+ fields: [
49
+ { no: 1, name: 'rpc_service', kind: 'scalar', T: ScalarType.STRING },
50
+ { no: 2, name: 'rpc_method', kind: 'scalar', T: ScalarType.STRING },
51
+ { no: 3, name: 'data', kind: 'scalar', T: ScalarType.BYTES },
52
+ { no: 4, name: 'data_is_zero', kind: 'scalar', T: ScalarType.BOOL },
53
+ ] as readonly PartialFieldInfo[],
54
+ packedByDefault: true,
55
+ })
57
56
 
58
57
  /**
59
58
  * CallData contains a message in a streaming RPC sequence.
@@ -66,40 +65,39 @@ export interface CallData {
66
65
  *
67
66
  * @generated from field: bytes data = 1;
68
67
  */
69
- data?: Uint8Array;
68
+ data?: Uint8Array
70
69
  /**
71
70
  * DataIsZero indicates Data is set with an empty message.
72
71
  *
73
72
  * @generated from field: bool data_is_zero = 2;
74
73
  */
75
- dataIsZero?: boolean;
74
+ dataIsZero?: boolean
76
75
  /**
77
76
  * Complete indicates the RPC call is completed.
78
77
  *
79
78
  * @generated from field: bool complete = 3;
80
79
  */
81
- complete?: boolean;
80
+ complete?: boolean
82
81
  /**
83
82
  * Error contains any error that caused the RPC to fail.
84
83
  * If set, implies complete=true.
85
84
  *
86
85
  * @generated from field: string error = 4;
87
86
  */
88
- error?: string;
89
-
90
- };
87
+ error?: string
88
+ }
91
89
 
92
90
  // CallData contains the message type declaration for CallData.
93
91
  export const CallData: MessageType<CallData> = createMessageType({
94
- typeName: "srpc.CallData",
95
- fields: [
96
- { no: 1, name: "data", kind: "scalar", T: ScalarType.BYTES },
97
- { no: 2, name: "data_is_zero", kind: "scalar", T: ScalarType.BOOL },
98
- { no: 3, name: "complete", kind: "scalar", T: ScalarType.BOOL },
99
- { no: 4, name: "error", kind: "scalar", T: ScalarType.STRING },
100
- ] as readonly PartialFieldInfo[],
101
- packedByDefault: true,
102
- });
92
+ typeName: 'srpc.CallData',
93
+ fields: [
94
+ { no: 1, name: 'data', kind: 'scalar', T: ScalarType.BYTES },
95
+ { no: 2, name: 'data_is_zero', kind: 'scalar', T: ScalarType.BOOL },
96
+ { no: 3, name: 'complete', kind: 'scalar', T: ScalarType.BOOL },
97
+ { no: 4, name: 'error', kind: 'scalar', T: ScalarType.STRING },
98
+ ] as readonly PartialFieldInfo[],
99
+ packedByDefault: true,
100
+ })
103
101
 
104
102
  /**
105
103
  * Packet is a message sent over a srpc packet connection.
@@ -107,51 +105,70 @@ export const CallData: MessageType<CallData> = createMessageType({
107
105
  * @generated from message srpc.Packet
108
106
  */
109
107
  export interface Packet {
110
-
111
108
  /**
112
109
  * Body is the packet body.
113
110
  *
114
111
  * @generated from oneof srpc.Packet.body
115
112
  */
116
- body?: {
117
- value?: undefined,
118
- case: undefined
119
- } | {
120
- /**
121
- * CallStart initiates a new call.
122
- *
123
- * @generated from field: srpc.CallStart call_start = 1;
124
- */
125
- value: CallStart;
126
- case: "callStart";
127
- } | {
128
- /**
129
- * CallData is a message in a streaming RPC sequence.
130
- *
131
- * @generated from field: srpc.CallData call_data = 2;
132
- */
133
- value: CallData;
134
- case: "callData";
135
- } | {
136
- /**
137
- * CallCancel cancels the call.
138
- *
139
- * @generated from field: bool call_cancel = 3;
140
- */
141
- value: boolean;
142
- case: "callCancel";
143
- };
144
-
145
- };
113
+ body?:
114
+ | {
115
+ value?: undefined
116
+ case: undefined
117
+ }
118
+ | {
119
+ /**
120
+ * CallStart initiates a new call.
121
+ *
122
+ * @generated from field: srpc.CallStart call_start = 1;
123
+ */
124
+ value: CallStart
125
+ case: 'callStart'
126
+ }
127
+ | {
128
+ /**
129
+ * CallData is a message in a streaming RPC sequence.
130
+ *
131
+ * @generated from field: srpc.CallData call_data = 2;
132
+ */
133
+ value: CallData
134
+ case: 'callData'
135
+ }
136
+ | {
137
+ /**
138
+ * CallCancel cancels the call.
139
+ *
140
+ * @generated from field: bool call_cancel = 3;
141
+ */
142
+ value: boolean
143
+ case: 'callCancel'
144
+ }
145
+ }
146
146
 
147
147
  // Packet contains the message type declaration for Packet.
148
148
  export const Packet: MessageType<Packet> = createMessageType({
149
- typeName: "srpc.Packet",
150
- fields: [
151
- { no: 1, name: "call_start", kind: "message", T: () => CallStart, oneof: "body" },
152
- { no: 2, name: "call_data", kind: "message", T: () => CallData, oneof: "body" },
153
- { no: 3, name: "call_cancel", kind: "scalar", T: ScalarType.BOOL, oneof: "body" },
154
- ] as readonly PartialFieldInfo[],
155
- packedByDefault: true,
156
- });
157
-
149
+ typeName: 'srpc.Packet',
150
+ fields: [
151
+ {
152
+ no: 1,
153
+ name: 'call_start',
154
+ kind: 'message',
155
+ T: () => CallStart,
156
+ oneof: 'body',
157
+ },
158
+ {
159
+ no: 2,
160
+ name: 'call_data',
161
+ kind: 'message',
162
+ T: () => CallData,
163
+ oneof: 'body',
164
+ },
165
+ {
166
+ no: 3,
167
+ name: 'call_cancel',
168
+ kind: 'scalar',
169
+ T: ScalarType.BOOL,
170
+ oneof: 'body',
171
+ },
172
+ ] as readonly PartialFieldInfo[],
173
+ packedByDefault: true,
174
+ })
@@ -94,6 +94,7 @@ func CheckServerStream(t *testing.T, out echo.SRPCEchoer_EchoServerStreamClient,
94
94
  }
95
95
  return err
96
96
  }
97
+
97
98
  body := echoMsg.GetBody()
98
99
  bodyTxt := req.GetBody()
99
100
  if body != bodyTxt {
@@ -101,10 +102,17 @@ func CheckServerStream(t *testing.T, out echo.SRPCEchoer_EchoServerStreamClient,
101
102
  }
102
103
  t.Logf("server->client message %d/%d", totalExpected-expectedRx+1, totalExpected)
103
104
  expectedRx--
105
+
106
+ if out.Context().Err() != nil {
107
+ return errors.New("expected context not canceled yet")
108
+ }
104
109
  }
105
110
  if expectedRx < 0 {
106
111
  return errors.Errorf("got %d more messages than expected", -1*expectedRx)
107
112
  }
113
+ if expectedRx > 0 {
114
+ return errors.Errorf("got %d less messages than expected", expectedRx)
115
+ }
108
116
  return nil
109
117
  }
110
118
 
package/srpc/stream.ts CHANGED
@@ -22,6 +22,11 @@ export type PacketStream = Duplex<
22
22
  // OpenStreamFunc is a function to start a new RPC by opening a Stream.
23
23
  export type OpenStreamFunc = () => Promise<PacketStream>
24
24
 
25
+ // HandleStreamFunc handles an incoming RPC stream.
26
+ // Returns as soon as the stream has been passed off to be handled.
27
+ // Throws an error if we can't handle the incoming stream.
28
+ export type HandleStreamFunc = (ch: PacketStream) => Promise<void>
29
+
25
30
  // streamToPacketStream converts a Stream into a PacketStream using length-prefix framing.
26
31
  //
27
32
  // The stream is closed when the source writing to the sink ends.