starpc 0.9.2 → 0.10.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 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
1
  import Long from 'long';
2
- import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
3
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: {};
@@ -331,5 +331,7 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
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,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  import Long from 'long';
3
- import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
4
3
  import _m0 from 'protobufjs/minimal.js';
4
+ import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js';
5
5
  export const protobufPackage = 'echo';
6
6
  function createBaseEchoMsg() {
7
7
  return { body: '' };
@@ -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 = {};
@@ -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
  }
@@ -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,7 +110,7 @@ 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 {
@@ -125,5 +125,7 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
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 {};
@@ -253,9 +253,7 @@ export const RpcAck = {
253
253
  }
254
254
  },
255
255
  fromJSON(object) {
256
- return {
257
- error: isSet(object.error) ? String(object.error) : '',
258
- };
256
+ return { error: isSet(object.error) ? String(object.error) : '' };
259
257
  },
260
258
  toJSON(message) {
261
259
  const obj = {};
@@ -269,34 +267,44 @@ export const RpcAck = {
269
267
  },
270
268
  };
271
269
  var globalThis = (() => {
272
- if (typeof globalThis !== 'undefined')
270
+ if (typeof globalThis !== 'undefined') {
273
271
  return globalThis;
274
- if (typeof self !== 'undefined')
272
+ }
273
+ if (typeof self !== 'undefined') {
275
274
  return self;
276
- if (typeof window !== 'undefined')
275
+ }
276
+ if (typeof window !== 'undefined') {
277
277
  return window;
278
- if (typeof global !== 'undefined')
278
+ }
279
+ if (typeof global !== 'undefined') {
279
280
  return global;
281
+ }
280
282
  throw 'Unable to locate global object';
281
283
  })();
282
- const atob = globalThis.atob ||
283
- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
284
284
  function bytesFromBase64(b64) {
285
- const bin = atob(b64);
286
- const arr = new Uint8Array(bin.length);
287
- for (let i = 0; i < bin.length; ++i) {
288
- arr[i] = bin.charCodeAt(i);
285
+ if (globalThis.Buffer) {
286
+ return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
287
+ }
288
+ else {
289
+ const bin = globalThis.atob(b64);
290
+ const arr = new Uint8Array(bin.length);
291
+ for (let i = 0; i < bin.length; ++i) {
292
+ arr[i] = bin.charCodeAt(i);
293
+ }
294
+ return arr;
289
295
  }
290
- return arr;
291
296
  }
292
- const btoa = globalThis.btoa ||
293
- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
294
297
  function base64FromBytes(arr) {
295
- const bin = [];
296
- arr.forEach((byte) => {
297
- bin.push(String.fromCharCode(byte));
298
- });
299
- return btoa(bin.join(''));
298
+ if (globalThis.Buffer) {
299
+ return globalThis.Buffer.from(arr).toString('base64');
300
+ }
301
+ else {
302
+ const bin = [];
303
+ arr.forEach((byte) => {
304
+ bin.push(String.fromCharCode(byte));
305
+ });
306
+ return globalThis.btoa(bin.join(''));
307
+ }
300
308
  }
301
309
  if (_m0.util.Long !== Long) {
302
310
  _m0.util.Long = Long;
@@ -101,7 +101,7 @@ export class Client {
101
101
  const openStreamFn = await this.openStreamFn;
102
102
  const conn = await openStreamFn();
103
103
  const call = new ClientRPC(rpcService, rpcMethod);
104
- pipe(conn, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, call, encodePacketSource, prependLengthPrefixTransform(), combineUint8ArrayListTransform(), conn);
104
+ pipe(conn, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, call, encodePacketSource, prependLengthPrefixTransform(), conn);
105
105
  await call.writeCallStart(data || undefined);
106
106
  return call;
107
107
  }
@@ -1,6 +1,7 @@
1
1
  import type { Direction, Stream } from '@libp2p/interface-connection';
2
2
  import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer';
3
3
  import type { Duplex } from 'it-stream-types';
4
+ import { Uint8ArrayList } from 'uint8arraylist';
4
5
  import type { OpenStreamFunc, Stream as SRPCStream } from './stream.js';
5
6
  import { Client } from './client.js';
6
7
  export interface ConnParams {
@@ -8,7 +9,7 @@ export interface ConnParams {
8
9
  direction?: Direction;
9
10
  }
10
11
  export interface StreamHandler {
11
- handleStream(strm: Duplex<Uint8Array>): void;
12
+ handleStream(strm: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>): void;
12
13
  }
13
14
  export declare class Conn implements Duplex<Uint8Array> {
14
15
  private muxer;
@@ -3,7 +3,7 @@ import { Uint8ArrayList } from 'uint8arraylist';
3
3
  import { Transform } from 'it-pipe';
4
4
  export declare const decodePacketSource: (source: import("it-stream-types").Source<Uint8Array | Uint8Array[]>) => AsyncIterable<Packet>;
5
5
  export declare const encodePacketSource: (source: import("it-stream-types").Source<Packet | Packet[]>) => AsyncIterable<Uint8Array>;
6
- export declare function prependLengthPrefixTransform(): Transform<Uint8Array | Uint8ArrayList, Uint8ArrayList>;
6
+ export declare function prependLengthPrefixTransform(): Transform<Uint8Array | Uint8ArrayList, Uint8Array>;
7
7
  export declare function parseLengthPrefixTransform(): Transform<Uint8Array | Uint8ArrayList, Uint8ArrayList>;
8
8
  export declare function encodeUint32Le(value: number): Uint8Array;
9
9
  export declare function decodeUint32Le(data: Uint8Array): number;
@@ -93,9 +93,9 @@ export declare const Packet: {
93
93
  rpcMethod?: string | undefined;
94
94
  data?: Uint8Array | undefined;
95
95
  dataIsZero?: boolean | undefined;
96
- } & Record<Exclude<keyof I["body"]["callStart"], keyof CallStart>, never>) | undefined;
96
+ } & { [K in Exclude<keyof I["body"]["callStart"], keyof CallStart>]: never; }) | undefined;
97
97
  $case: "callStart";
98
- } & Record<Exclude<keyof I["body"], "callStart" | "$case">, never>) | ({
98
+ } & { [K_1 in Exclude<keyof I["body"], "callStart" | "$case">]: never; }) | ({
99
99
  callData?: {
100
100
  data?: Uint8Array | undefined;
101
101
  dataIsZero?: boolean | undefined;
@@ -115,10 +115,10 @@ export declare const Packet: {
115
115
  dataIsZero?: boolean | undefined;
116
116
  complete?: boolean | undefined;
117
117
  error?: string | undefined;
118
- } & Record<Exclude<keyof I["body"]["callData"], keyof CallData>, never>) | undefined;
118
+ } & { [K_2 in Exclude<keyof I["body"]["callData"], keyof CallData>]: never; }) | undefined;
119
119
  $case: "callData";
120
- } & Record<Exclude<keyof I["body"], "callData" | "$case">, never>) | undefined;
121
- } & Record<Exclude<keyof I, "body">, never>>(object: I): Packet;
120
+ } & { [K_3 in Exclude<keyof I["body"], "callData" | "$case">]: never; }) | undefined;
121
+ } & { [K_4 in Exclude<keyof I, "body">]: never; }>(object: I): Packet;
122
122
  };
123
123
  export declare const CallStart: {
124
124
  encode(message: CallStart, writer?: _m0.Writer): _m0.Writer;
@@ -137,7 +137,7 @@ export declare const CallStart: {
137
137
  rpcMethod?: string | undefined;
138
138
  data?: Uint8Array | undefined;
139
139
  dataIsZero?: boolean | undefined;
140
- } & Record<Exclude<keyof I, keyof CallStart>, never>>(object: I): CallStart;
140
+ } & { [K in Exclude<keyof I, keyof CallStart>]: never; }>(object: I): CallStart;
141
141
  };
142
142
  export declare const CallData: {
143
143
  encode(message: CallData, writer?: _m0.Writer): _m0.Writer;
@@ -156,7 +156,7 @@ export declare const CallData: {
156
156
  dataIsZero?: boolean | undefined;
157
157
  complete?: boolean | undefined;
158
158
  error?: string | undefined;
159
- } & Record<Exclude<keyof I, keyof CallData>, never>>(object: I): CallData;
159
+ } & { [K in Exclude<keyof I, keyof CallData>]: never; }>(object: I): CallData;
160
160
  };
161
161
  declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
162
162
  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 {
@@ -171,5 +171,7 @@ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? st
171
171
  declare type KeysOfUnion<T> = T extends T ? keyof T : never;
172
172
  export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
173
173
  [K in keyof P]: Exact<P[K], I[K]>;
174
- } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
174
+ } & {
175
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
176
+ };
175
177
  export {};
@@ -327,34 +327,44 @@ export const CallData = {
327
327
  },
328
328
  };
329
329
  var globalThis = (() => {
330
- if (typeof globalThis !== 'undefined')
330
+ if (typeof globalThis !== 'undefined') {
331
331
  return globalThis;
332
- if (typeof self !== 'undefined')
332
+ }
333
+ if (typeof self !== 'undefined') {
333
334
  return self;
334
- if (typeof window !== 'undefined')
335
+ }
336
+ if (typeof window !== 'undefined') {
335
337
  return window;
336
- if (typeof global !== 'undefined')
338
+ }
339
+ if (typeof global !== 'undefined') {
337
340
  return global;
341
+ }
338
342
  throw 'Unable to locate global object';
339
343
  })();
340
- const atob = globalThis.atob ||
341
- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
342
344
  function bytesFromBase64(b64) {
343
- const bin = atob(b64);
344
- const arr = new Uint8Array(bin.length);
345
- for (let i = 0; i < bin.length; ++i) {
346
- arr[i] = bin.charCodeAt(i);
345
+ if (globalThis.Buffer) {
346
+ return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
347
+ }
348
+ else {
349
+ const bin = globalThis.atob(b64);
350
+ const arr = new Uint8Array(bin.length);
351
+ for (let i = 0; i < bin.length; ++i) {
352
+ arr[i] = bin.charCodeAt(i);
353
+ }
354
+ return arr;
347
355
  }
348
- return arr;
349
356
  }
350
- const btoa = globalThis.btoa ||
351
- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
352
357
  function base64FromBytes(arr) {
353
- const bin = [];
354
- arr.forEach((byte) => {
355
- bin.push(String.fromCharCode(byte));
356
- });
357
- return btoa(bin.join(''));
358
+ if (globalThis.Buffer) {
359
+ return globalThis.Buffer.from(arr).toString('base64');
360
+ }
361
+ else {
362
+ const bin = [];
363
+ arr.forEach((byte) => {
364
+ bin.push(String.fromCharCode(byte));
365
+ });
366
+ return globalThis.btoa(bin.join(''));
367
+ }
358
368
  }
359
369
  if (_m0.util.Long !== Long) {
360
370
  _m0.util.Long = Long;
@@ -1,5 +1,6 @@
1
1
  import { Stream } from '@libp2p/interface-connection';
2
2
  import { Duplex } from 'it-stream-types';
3
+ import { Uint8ArrayList } from 'uint8arraylist';
3
4
  import { LookupMethod } from './mux.js';
4
5
  import { ServerRPC } from './server-rpc.js';
5
6
  import { Packet } from './rpcproto.pb.js';
@@ -11,7 +12,7 @@ export declare class Server implements StreamHandler {
11
12
  get rpcStreamHandler(): RpcStreamHandler;
12
13
  startRpc(): ServerRPC;
13
14
  handleStream(stream: Stream): ServerRPC;
14
- handleDuplex(stream: Duplex<Uint8Array>): ServerRPC;
15
+ handleDuplex(stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>): ServerRPC;
15
16
  handlePacketDuplex(stream: Duplex<Uint8Array>): ServerRPC;
16
17
  handlePacketStream(stream: Duplex<Packet>): ServerRPC;
17
18
  }
@@ -23,7 +23,7 @@ export class Server {
23
23
  // handleDuplex handles an incoming message duplex.
24
24
  handleDuplex(stream) {
25
25
  const rpc = this.startRpc();
26
- pipe(stream, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, rpc, encodePacketSource, prependLengthPrefixTransform(), combineUint8ArrayListTransform(), stream);
26
+ pipe(stream, parseLengthPrefixTransform(), combineUint8ArrayListTransform(), decodePacketSource, rpc, encodePacketSource, prependLengthPrefixTransform(), stream);
27
27
  return rpc;
28
28
  }
29
29
  // handlePacketDuplex handles an incoming Uint8Array duplex.
@@ -1,5 +1,6 @@
1
1
  import type { Packet } from './rpcproto.pb.js';
2
2
  import type { Duplex } from 'it-stream-types';
3
+ import { Uint8ArrayList } from 'uint8arraylist';
3
4
  export declare type PacketHandler = (packet: Packet) => Promise<void>;
4
- export declare type Stream = Duplex<Uint8Array>;
5
+ export declare type Stream = Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>;
5
6
  export declare type OpenStreamFunc = () => Promise<Stream>;
package/e2e/e2e.ts CHANGED
@@ -10,7 +10,7 @@ async function runRPC() {
10
10
  mux.register(createHandler(EchoerDefinition, echoer))
11
11
 
12
12
  const clientConn = new Conn()
13
- const serverConn = new Conn(server, {direction: 'inbound'})
13
+ const serverConn = new Conn(server, { direction: 'inbound' })
14
14
  pipe(clientConn, serverConn, clientConn)
15
15
  const client = new Client(clientConn.buildOpenStreamFunc())
16
16
 
package/echo/echo.pb.go CHANGED
@@ -1,6 +1,6 @@
1
1
  // Code generated by protoc-gen-go. DO NOT EDIT.
2
2
  // versions:
3
- // protoc-gen-go v1.27.1-devel
3
+ // protoc-gen-go v1.28.1-devel
4
4
  // protoc v3.19.3
5
5
  // source: github.com/aperturerobotics/starpc/echo/echo.proto
6
6
 
package/echo/echo.pb.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  import Long from 'long'
3
- import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
4
3
  import _m0 from 'protobufjs/minimal.js'
4
+ import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
5
5
 
6
6
  export const protobufPackage = 'echo'
7
7
 
@@ -78,9 +78,7 @@ export const EchoMsg = {
78
78
  },
79
79
 
80
80
  fromJSON(object: any): EchoMsg {
81
- return {
82
- body: isSet(object.body) ? String(object.body) : '',
83
- }
81
+ return { body: isSet(object.body) ? String(object.body) : '' }
84
82
  },
85
83
 
86
84
  toJSON(message: EchoMsg): unknown {
@@ -276,10 +274,9 @@ export type DeepPartial<T> = T extends Builtin
276
274
  type KeysOfUnion<T> = T extends T ? keyof T : never
277
275
  export type Exact<P, I extends P> = P extends Builtin
278
276
  ? P
279
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
280
- Exclude<keyof I, KeysOfUnion<P>>,
281
- never
282
- >
277
+ : P & { [K in keyof P]: Exact<P[K], I[K]> } & {
278
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never
279
+ }
283
280
 
284
281
  if (_m0.util.Long !== Long) {
285
282
  _m0.util.Long = Long as any
@@ -1,5 +1,5 @@
1
1
  // Code generated by protoc-gen-srpc. DO NOT EDIT.
2
- // protoc-gen-srpc version: v0.8.6
2
+ // protoc-gen-srpc version: v0.9.2
3
3
  // source: github.com/aperturerobotics/starpc/echo/echo.proto
4
4
 
5
5
  package echo