starpc 0.9.2 → 0.10.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.
package/Makefile CHANGED
@@ -145,7 +145,7 @@ fix: $(GOLANGCI_LINT)
145
145
 
146
146
  .PHONY: test
147
147
  test:
148
- go test -v ./...
148
+ go test -timeout=30s -v ./...
149
149
 
150
150
  .PHONY: integration
151
151
  integration: node_modules vendor
@@ -1,6 +1,6 @@
1
- import Long from 'long';
2
- import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
3
- import _m0 from 'protobufjs/minimal.js';
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal.js";
3
+ import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
4
4
  export declare const protobufPackage = "echo";
5
5
  /** EchoMsg is the message body for Echo. */
6
6
  export interface EchoMsg {
@@ -17,7 +17,7 @@ export declare const EchoMsg: {
17
17
  body?: string | undefined;
18
18
  } & {
19
19
  body?: string | undefined;
20
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
20
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
21
21
  };
22
22
  /** Echoer service returns the given message. */
23
23
  export interface Echoer {
@@ -61,7 +61,7 @@ export declare const EchoerDefinition: {
61
61
  body?: string | undefined;
62
62
  } & {
63
63
  body?: string | undefined;
64
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
64
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
65
65
  };
66
66
  readonly requestStream: false;
67
67
  readonly responseType: {
@@ -75,7 +75,7 @@ export declare const EchoerDefinition: {
75
75
  body?: string | undefined;
76
76
  } & {
77
77
  body?: string | undefined;
78
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
78
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
79
79
  };
80
80
  readonly responseStream: false;
81
81
  readonly options: {};
@@ -94,7 +94,7 @@ export declare const EchoerDefinition: {
94
94
  body?: string | undefined;
95
95
  } & {
96
96
  body?: string | undefined;
97
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
97
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
98
98
  };
99
99
  readonly requestStream: false;
100
100
  readonly responseType: {
@@ -108,7 +108,7 @@ export declare const EchoerDefinition: {
108
108
  body?: string | undefined;
109
109
  } & {
110
110
  body?: string | undefined;
111
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
111
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
112
112
  };
113
113
  readonly responseStream: true;
114
114
  readonly options: {};
@@ -127,7 +127,7 @@ export declare const EchoerDefinition: {
127
127
  body?: string | undefined;
128
128
  } & {
129
129
  body?: string | undefined;
130
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
130
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
131
131
  };
132
132
  readonly requestStream: true;
133
133
  readonly responseType: {
@@ -141,7 +141,7 @@ export declare const EchoerDefinition: {
141
141
  body?: string | undefined;
142
142
  } & {
143
143
  body?: string | undefined;
144
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
144
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
145
145
  };
146
146
  readonly responseStream: false;
147
147
  readonly options: {};
@@ -160,7 +160,7 @@ export declare const EchoerDefinition: {
160
160
  body?: string | undefined;
161
161
  } & {
162
162
  body?: string | undefined;
163
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
163
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
164
164
  };
165
165
  readonly requestStream: true;
166
166
  readonly responseType: {
@@ -174,7 +174,7 @@ export declare const EchoerDefinition: {
174
174
  body?: string | undefined;
175
175
  } & {
176
176
  body?: string | undefined;
177
- } & Record<Exclude<keyof I, "body">, never>>(object: I): EchoMsg;
177
+ } & { [K in Exclude<keyof I, "body">]: never; }>(object: I): EchoMsg;
178
178
  };
179
179
  readonly responseStream: true;
180
180
  readonly options: {};
@@ -219,9 +219,9 @@ export declare const EchoerDefinition: {
219
219
  componentId?: string | undefined;
220
220
  } & {
221
221
  componentId?: string | undefined;
222
- } & Record<Exclude<keyof I_1["body"]["init"], "componentId">, never>) | undefined;
222
+ } & { [K in Exclude<keyof I_1["body"]["init"], "componentId">]: never; }) | undefined;
223
223
  $case: "init";
224
- } & Record<Exclude<keyof I_1["body"], "$case" | "init">, never>) | ({
224
+ } & { [K_1 in Exclude<keyof I_1["body"], "$case" | "init">]: never; }) | ({
225
225
  ack?: {
226
226
  error?: string | undefined;
227
227
  } | undefined;
@@ -232,17 +232,17 @@ export declare const EchoerDefinition: {
232
232
  error?: string | undefined;
233
233
  } & {
234
234
  error?: string | undefined;
235
- } & Record<Exclude<keyof I_1["body"]["ack"], "error">, never>) | undefined;
235
+ } & { [K_2 in Exclude<keyof I_1["body"]["ack"], "error">]: never; }) | undefined;
236
236
  $case: "ack";
237
- } & Record<Exclude<keyof I_1["body"], "$case" | "ack">, never>) | ({
237
+ } & { [K_3 in Exclude<keyof I_1["body"], "$case" | "ack">]: never; }) | ({
238
238
  data?: Uint8Array | undefined;
239
239
  } & {
240
240
  $case: "data";
241
241
  } & {
242
242
  data?: Uint8Array | undefined;
243
243
  $case: "data";
244
- } & Record<Exclude<keyof I_1["body"], "$case" | "data">, never>) | undefined;
245
- } & Record<Exclude<keyof I_1, "body">, never>>(object: I_1): RpcStreamPacket;
244
+ } & { [K_4 in Exclude<keyof I_1["body"], "$case" | "data">]: never; }) | undefined;
245
+ } & { [K_5 in Exclude<keyof I_1, "body">]: never; }>(object: I_1): RpcStreamPacket;
246
246
  };
247
247
  readonly requestStream: true;
248
248
  readonly responseType: {
@@ -282,9 +282,9 @@ export declare const EchoerDefinition: {
282
282
  componentId?: string | undefined;
283
283
  } & {
284
284
  componentId?: string | undefined;
285
- } & Record<Exclude<keyof I_1["body"]["init"], "componentId">, never>) | undefined;
285
+ } & { [K in Exclude<keyof I_1["body"]["init"], "componentId">]: never; }) | undefined;
286
286
  $case: "init";
287
- } & Record<Exclude<keyof I_1["body"], "$case" | "init">, never>) | ({
287
+ } & { [K_1 in Exclude<keyof I_1["body"], "$case" | "init">]: never; }) | ({
288
288
  ack?: {
289
289
  error?: string | undefined;
290
290
  } | undefined;
@@ -295,17 +295,17 @@ export declare const EchoerDefinition: {
295
295
  error?: string | undefined;
296
296
  } & {
297
297
  error?: string | undefined;
298
- } & Record<Exclude<keyof I_1["body"]["ack"], "error">, never>) | undefined;
298
+ } & { [K_2 in Exclude<keyof I_1["body"]["ack"], "error">]: never; }) | undefined;
299
299
  $case: "ack";
300
- } & Record<Exclude<keyof I_1["body"], "$case" | "ack">, never>) | ({
300
+ } & { [K_3 in Exclude<keyof I_1["body"], "$case" | "ack">]: never; }) | ({
301
301
  data?: Uint8Array | undefined;
302
302
  } & {
303
303
  $case: "data";
304
304
  } & {
305
305
  data?: Uint8Array | undefined;
306
306
  $case: "data";
307
- } & Record<Exclude<keyof I_1["body"], "$case" | "data">, never>) | undefined;
308
- } & Record<Exclude<keyof I_1, "body">, never>>(object: I_1): RpcStreamPacket;
307
+ } & { [K_4 in Exclude<keyof I_1["body"], "$case" | "data">]: never; }) | undefined;
308
+ } & { [K_5 in Exclude<keyof I_1, "body">]: never; }>(object: I_1): RpcStreamPacket;
309
309
  };
310
310
  readonly responseStream: true;
311
311
  readonly options: {};
@@ -322,14 +322,16 @@ declare type Builtin = Date | Function | Uint8Array | string | number | boolean
322
322
  export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
323
323
  $case: string;
324
324
  } ? {
325
- [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
325
+ [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
326
326
  } & {
327
- $case: T['$case'];
327
+ $case: T["$case"];
328
328
  } : T extends {} ? {
329
329
  [K in keyof T]?: DeepPartial<T[K]>;
330
330
  } : Partial<T>;
331
331
  declare type KeysOfUnion<T> = T extends T ? keyof T : never;
332
332
  export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
333
333
  [K in keyof P]: Exact<P[K], I[K]>;
334
- } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
334
+ } & {
335
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
336
+ };
335
337
  export {};
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable */
2
- import Long from 'long';
3
- import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
4
- import _m0 from 'protobufjs/minimal.js';
5
- export const protobufPackage = 'echo';
2
+ import Long from "long";
3
+ import _m0 from "protobufjs/minimal.js";
4
+ import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
5
+ export const protobufPackage = "echo";
6
6
  function createBaseEchoMsg() {
7
- return { body: '' };
7
+ return { body: "" };
8
8
  }
9
9
  export const EchoMsg = {
10
10
  encode(message, writer = _m0.Writer.create()) {
11
- if (message.body !== '') {
11
+ if (message.body !== "") {
12
12
  writer.uint32(10).string(message.body);
13
13
  }
14
14
  return writer;
@@ -59,9 +59,7 @@ export const EchoMsg = {
59
59
  }
60
60
  },
61
61
  fromJSON(object) {
62
- return {
63
- body: isSet(object.body) ? String(object.body) : '',
64
- };
62
+ return { body: isSet(object.body) ? String(object.body) : "" };
65
63
  },
66
64
  toJSON(message) {
67
65
  const obj = {};
@@ -70,7 +68,7 @@ export const EchoMsg = {
70
68
  },
71
69
  fromPartial(object) {
72
70
  const message = createBaseEchoMsg();
73
- message.body = object.body ?? '';
71
+ message.body = object.body ?? "";
74
72
  return message;
75
73
  },
76
74
  };
@@ -85,37 +83,37 @@ export class EchoerClientImpl {
85
83
  }
86
84
  Echo(request) {
87
85
  const data = EchoMsg.encode(request).finish();
88
- const promise = this.rpc.request('echo.Echoer', 'Echo', data);
86
+ const promise = this.rpc.request("echo.Echoer", "Echo", data);
89
87
  return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
90
88
  }
91
89
  EchoServerStream(request) {
92
90
  const data = EchoMsg.encode(request).finish();
93
- const result = this.rpc.serverStreamingRequest('echo.Echoer', 'EchoServerStream', data);
91
+ const result = this.rpc.serverStreamingRequest("echo.Echoer", "EchoServerStream", data);
94
92
  return EchoMsg.decodeTransform(result);
95
93
  }
96
94
  EchoClientStream(request) {
97
95
  const data = EchoMsg.encodeTransform(request);
98
- const promise = this.rpc.clientStreamingRequest('echo.Echoer', 'EchoClientStream', data);
96
+ const promise = this.rpc.clientStreamingRequest("echo.Echoer", "EchoClientStream", data);
99
97
  return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
100
98
  }
101
99
  EchoBidiStream(request) {
102
100
  const data = EchoMsg.encodeTransform(request);
103
- const result = this.rpc.bidirectionalStreamingRequest('echo.Echoer', 'EchoBidiStream', data);
101
+ const result = this.rpc.bidirectionalStreamingRequest("echo.Echoer", "EchoBidiStream", data);
104
102
  return EchoMsg.decodeTransform(result);
105
103
  }
106
104
  RpcStream(request) {
107
105
  const data = RpcStreamPacket.encodeTransform(request);
108
- const result = this.rpc.bidirectionalStreamingRequest('echo.Echoer', 'RpcStream', data);
106
+ const result = this.rpc.bidirectionalStreamingRequest("echo.Echoer", "RpcStream", data);
109
107
  return RpcStreamPacket.decodeTransform(result);
110
108
  }
111
109
  }
112
110
  export const EchoerDefinition = {
113
- name: 'Echoer',
114
- fullName: 'echo.Echoer',
111
+ name: "Echoer",
112
+ fullName: "echo.Echoer",
115
113
  methods: {
116
114
  /** Echo returns the given message. */
117
115
  echo: {
118
- name: 'Echo',
116
+ name: "Echo",
119
117
  requestType: EchoMsg,
120
118
  requestStream: false,
121
119
  responseType: EchoMsg,
@@ -124,7 +122,7 @@ export const EchoerDefinition = {
124
122
  },
125
123
  /** EchoServerStream is an example of a server -> client one-way stream. */
126
124
  echoServerStream: {
127
- name: 'EchoServerStream',
125
+ name: "EchoServerStream",
128
126
  requestType: EchoMsg,
129
127
  requestStream: false,
130
128
  responseType: EchoMsg,
@@ -133,7 +131,7 @@ export const EchoerDefinition = {
133
131
  },
134
132
  /** EchoClientStream is an example of client->server one-way stream. */
135
133
  echoClientStream: {
136
- name: 'EchoClientStream',
134
+ name: "EchoClientStream",
137
135
  requestType: EchoMsg,
138
136
  requestStream: true,
139
137
  responseType: EchoMsg,
@@ -142,7 +140,7 @@ export const EchoerDefinition = {
142
140
  },
143
141
  /** EchoBidiStream is an example of a two-way stream. */
144
142
  echoBidiStream: {
145
- name: 'EchoBidiStream',
143
+ name: "EchoBidiStream",
146
144
  requestType: EchoMsg,
147
145
  requestStream: true,
148
146
  responseType: EchoMsg,
@@ -151,7 +149,7 @@ export const EchoerDefinition = {
151
149
  },
152
150
  /** RpcStream opens a nested rpc call stream. */
153
151
  rpcStream: {
154
- name: 'RpcStream',
152
+ name: "RpcStream",
155
153
  requestType: RpcStreamPacket,
156
154
  requestStream: true,
157
155
  responseType: RpcStreamPacket,
@@ -2,15 +2,16 @@ import { RpcStreamPacket } from './rpcstream.pb.js';
2
2
  import { OpenStreamFunc, Stream } from '../srpc/stream.js';
3
3
  import { Pushable } from 'it-pushable';
4
4
  import { Duplex, Source, Sink } from 'it-stream-types';
5
+ import { Uint8ArrayList } from 'uint8arraylist';
5
6
  export declare type RpcStreamCaller = (request: AsyncIterable<RpcStreamPacket>) => AsyncIterable<RpcStreamPacket>;
6
7
  export declare function openRpcStream(componentId: string, caller: RpcStreamCaller): Promise<Stream>;
7
8
  export declare function buildRpcStreamOpenStream(componentId: string, caller: RpcStreamCaller): OpenStreamFunc;
8
- export declare type RpcStreamHandler = (stream: Duplex<Uint8Array>) => void;
9
+ export declare type RpcStreamHandler = (stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>) => void;
9
10
  export declare type RpcStreamGetter = (componentId: string) => Promise<RpcStreamHandler | null>;
10
11
  export declare function handleRpcStream(packetStream: AsyncIterator<RpcStreamPacket>, getter: RpcStreamGetter): AsyncIterable<RpcStreamPacket>;
11
12
  export declare class RpcStream implements Stream {
12
- readonly source: Source<Uint8Array>;
13
- readonly sink: Sink<Uint8Array>;
13
+ readonly source: Source<Uint8ArrayList>;
14
+ readonly sink: Sink<Uint8ArrayList | Uint8Array>;
14
15
  private readonly _packetStream;
15
16
  private readonly _packetSink;
16
17
  constructor(packetSink: Pushable<RpcStreamPacket>, packetStream: AsyncIterator<RpcStreamPacket>);
@@ -1,4 +1,5 @@
1
1
  import { pushable } from 'it-pushable';
2
+ import { Uint8ArrayList } from 'uint8arraylist';
2
3
  // openRpcStream attempts to open a stream over a RPC call.
3
4
  // waits for the remote to ack the stream before returning.
4
5
  export async function openRpcStream(componentId, caller) {
@@ -106,10 +107,19 @@ export class RpcStream {
106
107
  _createSink() {
107
108
  return async (source) => {
108
109
  try {
109
- for await (const msg of source) {
110
- this._packetSink.push({
111
- body: { $case: 'data', data: msg },
112
- });
110
+ for await (const arr of source) {
111
+ if (arr instanceof Uint8Array) {
112
+ this._packetSink.push({
113
+ body: { $case: 'data', data: arr },
114
+ });
115
+ }
116
+ else {
117
+ for (const msg of arr) {
118
+ this._packetSink.push({
119
+ body: { $case: 'data', data: msg },
120
+ });
121
+ }
122
+ }
113
123
  }
114
124
  this._packetSink.end();
115
125
  }
@@ -132,7 +142,7 @@ export class RpcStream {
132
142
  if (!body || body.$case !== 'data') {
133
143
  continue;
134
144
  }
135
- yield* [body.data];
145
+ yield* [new Uint8ArrayList(body.data)];
136
146
  }
137
147
  })();
138
148
  }
@@ -1,16 +1,16 @@
1
- import Long from 'long';
2
- import _m0 from 'protobufjs/minimal.js';
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal.js";
3
3
  export declare const protobufPackage = "rpcstream";
4
4
  /** RpcStreamPacket is a packet encapsulating data for a RPC stream. */
5
5
  export interface RpcStreamPacket {
6
6
  body?: {
7
- $case: 'init';
7
+ $case: "init";
8
8
  init: RpcStreamInit;
9
9
  } | {
10
- $case: 'ack';
10
+ $case: "ack";
11
11
  ack: RpcAck;
12
12
  } | {
13
- $case: 'data';
13
+ $case: "data";
14
14
  data: Uint8Array;
15
15
  };
16
16
  }
@@ -61,9 +61,9 @@ export declare const RpcStreamPacket: {
61
61
  componentId?: string | undefined;
62
62
  } & {
63
63
  componentId?: string | undefined;
64
- } & Record<Exclude<keyof I["body"]["init"], "componentId">, never>) | undefined;
64
+ } & { [K in Exclude<keyof I["body"]["init"], "componentId">]: never; }) | undefined;
65
65
  $case: "init";
66
- } & Record<Exclude<keyof I["body"], "$case" | "init">, never>) | ({
66
+ } & { [K_1 in Exclude<keyof I["body"], "$case" | "init">]: never; }) | ({
67
67
  ack?: {
68
68
  error?: string | undefined;
69
69
  } | undefined;
@@ -74,17 +74,17 @@ export declare const RpcStreamPacket: {
74
74
  error?: string | undefined;
75
75
  } & {
76
76
  error?: string | undefined;
77
- } & Record<Exclude<keyof I["body"]["ack"], "error">, never>) | undefined;
77
+ } & { [K_2 in Exclude<keyof I["body"]["ack"], "error">]: never; }) | undefined;
78
78
  $case: "ack";
79
- } & Record<Exclude<keyof I["body"], "$case" | "ack">, never>) | ({
79
+ } & { [K_3 in Exclude<keyof I["body"], "$case" | "ack">]: never; }) | ({
80
80
  data?: Uint8Array | undefined;
81
81
  } & {
82
82
  $case: "data";
83
83
  } & {
84
84
  data?: Uint8Array | undefined;
85
85
  $case: "data";
86
- } & Record<Exclude<keyof I["body"], "$case" | "data">, never>) | undefined;
87
- } & Record<Exclude<keyof I, "body">, never>>(object: I): RpcStreamPacket;
86
+ } & { [K_4 in Exclude<keyof I["body"], "$case" | "data">]: never; }) | undefined;
87
+ } & { [K_5 in Exclude<keyof I, "body">]: never; }>(object: I): RpcStreamPacket;
88
88
  };
89
89
  export declare const RpcStreamInit: {
90
90
  encode(message: RpcStreamInit, writer?: _m0.Writer): _m0.Writer;
@@ -97,7 +97,7 @@ export declare const RpcStreamInit: {
97
97
  componentId?: string | undefined;
98
98
  } & {
99
99
  componentId?: string | undefined;
100
- } & Record<Exclude<keyof I, "componentId">, never>>(object: I): RpcStreamInit;
100
+ } & { [K in Exclude<keyof I, "componentId">]: never; }>(object: I): RpcStreamInit;
101
101
  };
102
102
  export declare const RpcAck: {
103
103
  encode(message: RpcAck, writer?: _m0.Writer): _m0.Writer;
@@ -110,20 +110,22 @@ export declare const RpcAck: {
110
110
  error?: string | undefined;
111
111
  } & {
112
112
  error?: string | undefined;
113
- } & Record<Exclude<keyof I, "error">, never>>(object: I): RpcAck;
113
+ } & { [K in Exclude<keyof I, "error">]: never; }>(object: I): RpcAck;
114
114
  };
115
115
  declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
116
116
  export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {
117
117
  $case: string;
118
118
  } ? {
119
- [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
119
+ [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]>;
120
120
  } & {
121
- $case: T['$case'];
121
+ $case: T["$case"];
122
122
  } : T extends {} ? {
123
123
  [K in keyof T]?: DeepPartial<T[K]>;
124
124
  } : Partial<T>;
125
125
  declare type KeysOfUnion<T> = T extends T ? keyof T : never;
126
126
  export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
127
127
  [K in keyof P]: Exact<P[K], I[K]>;
128
- } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
128
+ } & {
129
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
130
+ };
129
131
  export {};