starpc 0.13.2 → 0.14.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/dist/e2e/mock/mock.pb.d.ts +94 -0
- package/dist/e2e/mock/mock.pb.js +107 -0
- package/dist/echo/echo.pb.d.ts +5 -5
- package/dist/echo/echo.pb.js +21 -21
- package/dist/rpcstream/rpcstream.pb.d.ts +7 -7
- package/dist/rpcstream/rpcstream.pb.js +64 -39
- package/dist/srpc/common-rpc.d.ts +1 -0
- package/dist/srpc/common-rpc.js +19 -4
- package/dist/srpc/rpcproto.pb.d.ts +22 -8
- package/dist/srpc/rpcproto.pb.js +91 -39
- package/e2e/e2e_test.go +65 -15
- package/e2e/mock/mock.go +29 -0
- package/e2e/mock/mock.pb.go +151 -0
- package/e2e/mock/mock.pb.ts +182 -0
- package/e2e/mock/mock.proto +13 -0
- package/e2e/mock/mock_srpc.pb.go +128 -0
- package/e2e/mock/mock_vtproto.pb.go +290 -0
- package/echo/echo.pb.ts +146 -90
- package/go.mod +10 -10
- package/go.sum +20 -20
- package/package.json +3 -3
- package/srpc/client-rpc.go +6 -0
- package/srpc/client.go +3 -0
- package/srpc/common-rpc.ts +21 -4
- package/srpc/msg-stream.go +8 -11
- package/srpc/muxed-conn.go +0 -1
- package/srpc/packet-rw.go +2 -3
- package/srpc/packet.go +7 -0
- package/srpc/rpcproto.pb.go +43 -25
- package/srpc/rpcproto.pb.ts +294 -183
- package/srpc/rpcproto.proto +2 -0
- package/srpc/rpcproto_vtproto.pb.go +74 -0
- package/srpc/server-http.go +1 -1
- package/srpc/server-rpc.go +5 -0
- package/srpc/stream.go +1 -1
- package/srpc/websocket.go +5 -1
- package/srpc/websocket.ts +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import Long from 'long';
|
|
2
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
3
|
+
export declare const protobufPackage = "e2e.mock";
|
|
4
|
+
/** MockMsg is the mock message body. */
|
|
5
|
+
export interface MockMsg {
|
|
6
|
+
body: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const MockMsg: {
|
|
9
|
+
encode(message: MockMsg, writer?: _m0.Writer): _m0.Writer;
|
|
10
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): MockMsg;
|
|
11
|
+
encodeTransform(source: AsyncIterable<MockMsg | MockMsg[]> | Iterable<MockMsg | MockMsg[]>): AsyncIterable<Uint8Array>;
|
|
12
|
+
decodeTransform(source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>): AsyncIterable<MockMsg>;
|
|
13
|
+
fromJSON(object: any): MockMsg;
|
|
14
|
+
toJSON(message: MockMsg): unknown;
|
|
15
|
+
fromPartial<I extends {
|
|
16
|
+
body?: string | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
body?: string | undefined;
|
|
19
|
+
} & { [K in Exclude<keyof I, "body">]: never; }>(object: I): MockMsg;
|
|
20
|
+
};
|
|
21
|
+
/** Mock service mocks some RPCs for the e2e tests. */
|
|
22
|
+
export interface Mock {
|
|
23
|
+
/** MockRequest runs a mock unary request. */
|
|
24
|
+
MockRequest(request: MockMsg): Promise<MockMsg>;
|
|
25
|
+
}
|
|
26
|
+
export declare class MockClientImpl implements Mock {
|
|
27
|
+
private readonly rpc;
|
|
28
|
+
private readonly service;
|
|
29
|
+
constructor(rpc: Rpc, opts?: {
|
|
30
|
+
service?: string;
|
|
31
|
+
});
|
|
32
|
+
MockRequest(request: MockMsg): Promise<MockMsg>;
|
|
33
|
+
}
|
|
34
|
+
/** Mock service mocks some RPCs for the e2e tests. */
|
|
35
|
+
export declare type MockDefinition = typeof MockDefinition;
|
|
36
|
+
export declare const MockDefinition: {
|
|
37
|
+
readonly name: "Mock";
|
|
38
|
+
readonly fullName: "e2e.mock.Mock";
|
|
39
|
+
readonly methods: {
|
|
40
|
+
/** MockRequest runs a mock unary request. */
|
|
41
|
+
readonly mockRequest: {
|
|
42
|
+
readonly name: "MockRequest";
|
|
43
|
+
readonly requestType: {
|
|
44
|
+
encode(message: MockMsg, writer?: _m0.Writer): _m0.Writer;
|
|
45
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): MockMsg;
|
|
46
|
+
encodeTransform(source: AsyncIterable<MockMsg | MockMsg[]> | Iterable<MockMsg | MockMsg[]>): AsyncIterable<Uint8Array>;
|
|
47
|
+
decodeTransform(source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>): AsyncIterable<MockMsg>;
|
|
48
|
+
fromJSON(object: any): MockMsg;
|
|
49
|
+
toJSON(message: MockMsg): unknown;
|
|
50
|
+
fromPartial<I extends {
|
|
51
|
+
body?: string | undefined;
|
|
52
|
+
} & {
|
|
53
|
+
body?: string | undefined;
|
|
54
|
+
} & { [K in Exclude<keyof I, "body">]: never; }>(object: I): MockMsg;
|
|
55
|
+
};
|
|
56
|
+
readonly requestStream: false;
|
|
57
|
+
readonly responseType: {
|
|
58
|
+
encode(message: MockMsg, writer?: _m0.Writer): _m0.Writer;
|
|
59
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): MockMsg;
|
|
60
|
+
encodeTransform(source: AsyncIterable<MockMsg | MockMsg[]> | Iterable<MockMsg | MockMsg[]>): AsyncIterable<Uint8Array>;
|
|
61
|
+
decodeTransform(source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>): AsyncIterable<MockMsg>;
|
|
62
|
+
fromJSON(object: any): MockMsg;
|
|
63
|
+
toJSON(message: MockMsg): unknown;
|
|
64
|
+
fromPartial<I extends {
|
|
65
|
+
body?: string | undefined;
|
|
66
|
+
} & {
|
|
67
|
+
body?: string | undefined;
|
|
68
|
+
} & { [K in Exclude<keyof I, "body">]: never; }>(object: I): MockMsg;
|
|
69
|
+
};
|
|
70
|
+
readonly responseStream: false;
|
|
71
|
+
readonly options: {};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
interface Rpc {
|
|
76
|
+
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
|
77
|
+
}
|
|
78
|
+
declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
79
|
+
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 {
|
|
80
|
+
$case: string;
|
|
81
|
+
} ? {
|
|
82
|
+
[K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
|
|
83
|
+
} & {
|
|
84
|
+
$case: T['$case'];
|
|
85
|
+
} : T extends {} ? {
|
|
86
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
87
|
+
} : Partial<T>;
|
|
88
|
+
declare type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
89
|
+
export declare type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
90
|
+
[K in keyof P]: Exact<P[K], I[K]>;
|
|
91
|
+
} & {
|
|
92
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
93
|
+
};
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import Long from 'long';
|
|
3
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
4
|
+
export const protobufPackage = 'e2e.mock';
|
|
5
|
+
function createBaseMockMsg() {
|
|
6
|
+
return { body: '' };
|
|
7
|
+
}
|
|
8
|
+
export const MockMsg = {
|
|
9
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
10
|
+
if (message.body !== '') {
|
|
11
|
+
writer.uint32(10).string(message.body);
|
|
12
|
+
}
|
|
13
|
+
return writer;
|
|
14
|
+
},
|
|
15
|
+
decode(input, length) {
|
|
16
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
|
|
17
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
18
|
+
const message = createBaseMockMsg();
|
|
19
|
+
while (reader.pos < end) {
|
|
20
|
+
const tag = reader.uint32();
|
|
21
|
+
switch (tag >>> 3) {
|
|
22
|
+
case 1:
|
|
23
|
+
message.body = reader.string();
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
reader.skipType(tag & 7);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return message;
|
|
31
|
+
},
|
|
32
|
+
// encodeTransform encodes a source of message objects.
|
|
33
|
+
// Transform<MockMsg, Uint8Array>
|
|
34
|
+
async *encodeTransform(source) {
|
|
35
|
+
for await (const pkt of source) {
|
|
36
|
+
if (Array.isArray(pkt)) {
|
|
37
|
+
for (const p of pkt) {
|
|
38
|
+
yield* [MockMsg.encode(p).finish()];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
yield* [MockMsg.encode(pkt).finish()];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
// decodeTransform decodes a source of encoded messages.
|
|
47
|
+
// Transform<Uint8Array, MockMsg>
|
|
48
|
+
async *decodeTransform(source) {
|
|
49
|
+
for await (const pkt of source) {
|
|
50
|
+
if (Array.isArray(pkt)) {
|
|
51
|
+
for (const p of pkt) {
|
|
52
|
+
yield* [MockMsg.decode(p)];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
yield* [MockMsg.decode(pkt)];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
fromJSON(object) {
|
|
61
|
+
return { body: isSet(object.body) ? String(object.body) : '' };
|
|
62
|
+
},
|
|
63
|
+
toJSON(message) {
|
|
64
|
+
const obj = {};
|
|
65
|
+
message.body !== undefined && (obj.body = message.body);
|
|
66
|
+
return obj;
|
|
67
|
+
},
|
|
68
|
+
fromPartial(object) {
|
|
69
|
+
const message = createBaseMockMsg();
|
|
70
|
+
message.body = object.body ?? '';
|
|
71
|
+
return message;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
export class MockClientImpl {
|
|
75
|
+
constructor(rpc, opts) {
|
|
76
|
+
this.service = opts?.service || 'e2e.mock.Mock';
|
|
77
|
+
this.rpc = rpc;
|
|
78
|
+
this.MockRequest = this.MockRequest.bind(this);
|
|
79
|
+
}
|
|
80
|
+
MockRequest(request) {
|
|
81
|
+
const data = MockMsg.encode(request).finish();
|
|
82
|
+
const promise = this.rpc.request(this.service, 'MockRequest', data);
|
|
83
|
+
return promise.then((data) => MockMsg.decode(new _m0.Reader(data)));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export const MockDefinition = {
|
|
87
|
+
name: 'Mock',
|
|
88
|
+
fullName: 'e2e.mock.Mock',
|
|
89
|
+
methods: {
|
|
90
|
+
/** MockRequest runs a mock unary request. */
|
|
91
|
+
mockRequest: {
|
|
92
|
+
name: 'MockRequest',
|
|
93
|
+
requestType: MockMsg,
|
|
94
|
+
requestStream: false,
|
|
95
|
+
responseType: MockMsg,
|
|
96
|
+
responseStream: false,
|
|
97
|
+
options: {},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
if (_m0.util.Long !== Long) {
|
|
102
|
+
_m0.util.Long = Long;
|
|
103
|
+
_m0.configure();
|
|
104
|
+
}
|
|
105
|
+
function isSet(value) {
|
|
106
|
+
return value !== null && value !== undefined;
|
|
107
|
+
}
|
package/dist/echo/echo.pb.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Long from
|
|
2
|
-
import _m0 from
|
|
3
|
-
import { RpcStreamPacket } from
|
|
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 {
|
|
@@ -325,9 +325,9 @@ declare type Builtin = Date | Function | Uint8Array | string | number | boolean
|
|
|
325
325
|
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 {
|
|
326
326
|
$case: string;
|
|
327
327
|
} ? {
|
|
328
|
-
[K in keyof Omit<T,
|
|
328
|
+
[K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
|
|
329
329
|
} & {
|
|
330
|
-
$case: T[
|
|
330
|
+
$case: T['$case'];
|
|
331
331
|
} : T extends {} ? {
|
|
332
332
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
333
333
|
} : Partial<T>;
|
package/dist/echo/echo.pb.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import Long from
|
|
3
|
-
import _m0 from
|
|
4
|
-
import { RpcStreamPacket } from
|
|
5
|
-
export const protobufPackage =
|
|
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,7 +59,7 @@ export const EchoMsg = {
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
fromJSON(object) {
|
|
62
|
-
return { body: isSet(object.body) ? String(object.body) :
|
|
62
|
+
return { body: isSet(object.body) ? String(object.body) : '' };
|
|
63
63
|
},
|
|
64
64
|
toJSON(message) {
|
|
65
65
|
const obj = {};
|
|
@@ -68,13 +68,13 @@ export const EchoMsg = {
|
|
|
68
68
|
},
|
|
69
69
|
fromPartial(object) {
|
|
70
70
|
const message = createBaseEchoMsg();
|
|
71
|
-
message.body = object.body ??
|
|
71
|
+
message.body = object.body ?? '';
|
|
72
72
|
return message;
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
export class EchoerClientImpl {
|
|
76
76
|
constructor(rpc, opts) {
|
|
77
|
-
this.service = opts?.service ||
|
|
77
|
+
this.service = opts?.service || 'echo.Echoer';
|
|
78
78
|
this.rpc = rpc;
|
|
79
79
|
this.Echo = this.Echo.bind(this);
|
|
80
80
|
this.EchoServerStream = this.EchoServerStream.bind(this);
|
|
@@ -84,37 +84,37 @@ export class EchoerClientImpl {
|
|
|
84
84
|
}
|
|
85
85
|
Echo(request) {
|
|
86
86
|
const data = EchoMsg.encode(request).finish();
|
|
87
|
-
const promise = this.rpc.request(this.service,
|
|
87
|
+
const promise = this.rpc.request(this.service, 'Echo', data);
|
|
88
88
|
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
|
|
89
89
|
}
|
|
90
90
|
EchoServerStream(request) {
|
|
91
91
|
const data = EchoMsg.encode(request).finish();
|
|
92
|
-
const result = this.rpc.serverStreamingRequest(this.service,
|
|
92
|
+
const result = this.rpc.serverStreamingRequest(this.service, 'EchoServerStream', data);
|
|
93
93
|
return EchoMsg.decodeTransform(result);
|
|
94
94
|
}
|
|
95
95
|
EchoClientStream(request) {
|
|
96
96
|
const data = EchoMsg.encodeTransform(request);
|
|
97
|
-
const promise = this.rpc.clientStreamingRequest(this.service,
|
|
97
|
+
const promise = this.rpc.clientStreamingRequest(this.service, 'EchoClientStream', data);
|
|
98
98
|
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
|
|
99
99
|
}
|
|
100
100
|
EchoBidiStream(request) {
|
|
101
101
|
const data = EchoMsg.encodeTransform(request);
|
|
102
|
-
const result = this.rpc.bidirectionalStreamingRequest(this.service,
|
|
102
|
+
const result = this.rpc.bidirectionalStreamingRequest(this.service, 'EchoBidiStream', data);
|
|
103
103
|
return EchoMsg.decodeTransform(result);
|
|
104
104
|
}
|
|
105
105
|
RpcStream(request) {
|
|
106
106
|
const data = RpcStreamPacket.encodeTransform(request);
|
|
107
|
-
const result = this.rpc.bidirectionalStreamingRequest(this.service,
|
|
107
|
+
const result = this.rpc.bidirectionalStreamingRequest(this.service, 'RpcStream', data);
|
|
108
108
|
return RpcStreamPacket.decodeTransform(result);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
export const EchoerDefinition = {
|
|
112
|
-
name:
|
|
113
|
-
fullName:
|
|
112
|
+
name: 'Echoer',
|
|
113
|
+
fullName: 'echo.Echoer',
|
|
114
114
|
methods: {
|
|
115
115
|
/** Echo returns the given message. */
|
|
116
116
|
echo: {
|
|
117
|
-
name:
|
|
117
|
+
name: 'Echo',
|
|
118
118
|
requestType: EchoMsg,
|
|
119
119
|
requestStream: false,
|
|
120
120
|
responseType: EchoMsg,
|
|
@@ -123,7 +123,7 @@ export const EchoerDefinition = {
|
|
|
123
123
|
},
|
|
124
124
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
125
125
|
echoServerStream: {
|
|
126
|
-
name:
|
|
126
|
+
name: 'EchoServerStream',
|
|
127
127
|
requestType: EchoMsg,
|
|
128
128
|
requestStream: false,
|
|
129
129
|
responseType: EchoMsg,
|
|
@@ -132,7 +132,7 @@ export const EchoerDefinition = {
|
|
|
132
132
|
},
|
|
133
133
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
134
134
|
echoClientStream: {
|
|
135
|
-
name:
|
|
135
|
+
name: 'EchoClientStream',
|
|
136
136
|
requestType: EchoMsg,
|
|
137
137
|
requestStream: true,
|
|
138
138
|
responseType: EchoMsg,
|
|
@@ -141,7 +141,7 @@ export const EchoerDefinition = {
|
|
|
141
141
|
},
|
|
142
142
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
143
143
|
echoBidiStream: {
|
|
144
|
-
name:
|
|
144
|
+
name: 'EchoBidiStream',
|
|
145
145
|
requestType: EchoMsg,
|
|
146
146
|
requestStream: true,
|
|
147
147
|
responseType: EchoMsg,
|
|
@@ -150,7 +150,7 @@ export const EchoerDefinition = {
|
|
|
150
150
|
},
|
|
151
151
|
/** RpcStream opens a nested rpc call stream. */
|
|
152
152
|
rpcStream: {
|
|
153
|
-
name:
|
|
153
|
+
name: 'RpcStream',
|
|
154
154
|
requestType: RpcStreamPacket,
|
|
155
155
|
requestStream: true,
|
|
156
156
|
responseType: RpcStreamPacket,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import Long from
|
|
2
|
-
import _m0 from
|
|
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:
|
|
7
|
+
$case: 'init';
|
|
8
8
|
init: RpcStreamInit;
|
|
9
9
|
} | {
|
|
10
|
-
$case:
|
|
10
|
+
$case: 'ack';
|
|
11
11
|
ack: RpcAck;
|
|
12
12
|
} | {
|
|
13
|
-
$case:
|
|
13
|
+
$case: 'data';
|
|
14
14
|
data: Uint8Array;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -116,9 +116,9 @@ declare type Builtin = Date | Function | Uint8Array | string | number | boolean
|
|
|
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,
|
|
119
|
+
[K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]>;
|
|
120
120
|
} & {
|
|
121
|
-
$case: T[
|
|
121
|
+
$case: T['$case'];
|
|
122
122
|
} : T extends {} ? {
|
|
123
123
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
124
124
|
} : Partial<T>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import Long from
|
|
3
|
-
import _m0 from
|
|
4
|
-
export const protobufPackage =
|
|
2
|
+
import Long from 'long';
|
|
3
|
+
import _m0 from 'protobufjs/minimal.js';
|
|
4
|
+
export const protobufPackage = 'rpcstream';
|
|
5
5
|
function createBaseRpcStreamPacket() {
|
|
6
6
|
return { body: undefined };
|
|
7
7
|
}
|
|
8
8
|
export const RpcStreamPacket = {
|
|
9
9
|
encode(message, writer = _m0.Writer.create()) {
|
|
10
|
-
if (message.body?.$case ===
|
|
10
|
+
if (message.body?.$case === 'init') {
|
|
11
11
|
RpcStreamInit.encode(message.body.init, writer.uint32(10).fork()).ldelim();
|
|
12
12
|
}
|
|
13
|
-
if (message.body?.$case ===
|
|
13
|
+
if (message.body?.$case === 'ack') {
|
|
14
14
|
RpcAck.encode(message.body.ack, writer.uint32(18).fork()).ldelim();
|
|
15
15
|
}
|
|
16
|
-
if (message.body?.$case ===
|
|
16
|
+
if (message.body?.$case === 'data') {
|
|
17
17
|
writer.uint32(26).bytes(message.body.data);
|
|
18
18
|
}
|
|
19
19
|
return writer;
|
|
@@ -26,13 +26,19 @@ export const RpcStreamPacket = {
|
|
|
26
26
|
const tag = reader.uint32();
|
|
27
27
|
switch (tag >>> 3) {
|
|
28
28
|
case 1:
|
|
29
|
-
message.body = {
|
|
29
|
+
message.body = {
|
|
30
|
+
$case: 'init',
|
|
31
|
+
init: RpcStreamInit.decode(reader, reader.uint32()),
|
|
32
|
+
};
|
|
30
33
|
break;
|
|
31
34
|
case 2:
|
|
32
|
-
message.body = {
|
|
35
|
+
message.body = {
|
|
36
|
+
$case: 'ack',
|
|
37
|
+
ack: RpcAck.decode(reader, reader.uint32()),
|
|
38
|
+
};
|
|
33
39
|
break;
|
|
34
40
|
case 3:
|
|
35
|
-
message.body = { $case:
|
|
41
|
+
message.body = { $case: 'data', data: reader.bytes() };
|
|
36
42
|
break;
|
|
37
43
|
default:
|
|
38
44
|
reader.skipType(tag & 7);
|
|
@@ -72,43 +78,60 @@ export const RpcStreamPacket = {
|
|
|
72
78
|
fromJSON(object) {
|
|
73
79
|
return {
|
|
74
80
|
body: isSet(object.init)
|
|
75
|
-
? { $case:
|
|
81
|
+
? { $case: 'init', init: RpcStreamInit.fromJSON(object.init) }
|
|
76
82
|
: isSet(object.ack)
|
|
77
|
-
? { $case:
|
|
83
|
+
? { $case: 'ack', ack: RpcAck.fromJSON(object.ack) }
|
|
78
84
|
: isSet(object.data)
|
|
79
|
-
? { $case:
|
|
85
|
+
? { $case: 'data', data: bytesFromBase64(object.data) }
|
|
80
86
|
: undefined,
|
|
81
87
|
};
|
|
82
88
|
},
|
|
83
89
|
toJSON(message) {
|
|
84
90
|
const obj = {};
|
|
85
|
-
message.body?.$case ===
|
|
86
|
-
(obj.init = message.body?.init
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
message.body?.$case === 'init' &&
|
|
92
|
+
(obj.init = message.body?.init
|
|
93
|
+
? RpcStreamInit.toJSON(message.body?.init)
|
|
94
|
+
: undefined);
|
|
95
|
+
message.body?.$case === 'ack' &&
|
|
96
|
+
(obj.ack = message.body?.ack
|
|
97
|
+
? RpcAck.toJSON(message.body?.ack)
|
|
98
|
+
: undefined);
|
|
99
|
+
message.body?.$case === 'data' &&
|
|
100
|
+
(obj.data =
|
|
101
|
+
message.body?.data !== undefined
|
|
102
|
+
? base64FromBytes(message.body?.data)
|
|
103
|
+
: undefined);
|
|
90
104
|
return obj;
|
|
91
105
|
},
|
|
92
106
|
fromPartial(object) {
|
|
93
107
|
const message = createBaseRpcStreamPacket();
|
|
94
|
-
if (object.body?.$case ===
|
|
95
|
-
|
|
108
|
+
if (object.body?.$case === 'init' &&
|
|
109
|
+
object.body?.init !== undefined &&
|
|
110
|
+
object.body?.init !== null) {
|
|
111
|
+
message.body = {
|
|
112
|
+
$case: 'init',
|
|
113
|
+
init: RpcStreamInit.fromPartial(object.body.init),
|
|
114
|
+
};
|
|
96
115
|
}
|
|
97
|
-
if (object.body?.$case ===
|
|
98
|
-
|
|
116
|
+
if (object.body?.$case === 'ack' &&
|
|
117
|
+
object.body?.ack !== undefined &&
|
|
118
|
+
object.body?.ack !== null) {
|
|
119
|
+
message.body = { $case: 'ack', ack: RpcAck.fromPartial(object.body.ack) };
|
|
99
120
|
}
|
|
100
|
-
if (object.body?.$case ===
|
|
101
|
-
|
|
121
|
+
if (object.body?.$case === 'data' &&
|
|
122
|
+
object.body?.data !== undefined &&
|
|
123
|
+
object.body?.data !== null) {
|
|
124
|
+
message.body = { $case: 'data', data: object.body.data };
|
|
102
125
|
}
|
|
103
126
|
return message;
|
|
104
127
|
},
|
|
105
128
|
};
|
|
106
129
|
function createBaseRpcStreamInit() {
|
|
107
|
-
return { componentId:
|
|
130
|
+
return { componentId: '' };
|
|
108
131
|
}
|
|
109
132
|
export const RpcStreamInit = {
|
|
110
133
|
encode(message, writer = _m0.Writer.create()) {
|
|
111
|
-
if (message.componentId !==
|
|
134
|
+
if (message.componentId !== '') {
|
|
112
135
|
writer.uint32(10).string(message.componentId);
|
|
113
136
|
}
|
|
114
137
|
return writer;
|
|
@@ -159,7 +182,9 @@ export const RpcStreamInit = {
|
|
|
159
182
|
}
|
|
160
183
|
},
|
|
161
184
|
fromJSON(object) {
|
|
162
|
-
return {
|
|
185
|
+
return {
|
|
186
|
+
componentId: isSet(object.componentId) ? String(object.componentId) : '',
|
|
187
|
+
};
|
|
163
188
|
},
|
|
164
189
|
toJSON(message) {
|
|
165
190
|
const obj = {};
|
|
@@ -168,16 +193,16 @@ export const RpcStreamInit = {
|
|
|
168
193
|
},
|
|
169
194
|
fromPartial(object) {
|
|
170
195
|
const message = createBaseRpcStreamInit();
|
|
171
|
-
message.componentId = object.componentId ??
|
|
196
|
+
message.componentId = object.componentId ?? '';
|
|
172
197
|
return message;
|
|
173
198
|
},
|
|
174
199
|
};
|
|
175
200
|
function createBaseRpcAck() {
|
|
176
|
-
return { error:
|
|
201
|
+
return { error: '' };
|
|
177
202
|
}
|
|
178
203
|
export const RpcAck = {
|
|
179
204
|
encode(message, writer = _m0.Writer.create()) {
|
|
180
|
-
if (message.error !==
|
|
205
|
+
if (message.error !== '') {
|
|
181
206
|
writer.uint32(10).string(message.error);
|
|
182
207
|
}
|
|
183
208
|
return writer;
|
|
@@ -228,7 +253,7 @@ export const RpcAck = {
|
|
|
228
253
|
}
|
|
229
254
|
},
|
|
230
255
|
fromJSON(object) {
|
|
231
|
-
return { error: isSet(object.error) ? String(object.error) :
|
|
256
|
+
return { error: isSet(object.error) ? String(object.error) : '' };
|
|
232
257
|
},
|
|
233
258
|
toJSON(message) {
|
|
234
259
|
const obj = {};
|
|
@@ -237,28 +262,28 @@ export const RpcAck = {
|
|
|
237
262
|
},
|
|
238
263
|
fromPartial(object) {
|
|
239
264
|
const message = createBaseRpcAck();
|
|
240
|
-
message.error = object.error ??
|
|
265
|
+
message.error = object.error ?? '';
|
|
241
266
|
return message;
|
|
242
267
|
},
|
|
243
268
|
};
|
|
244
269
|
var globalThis = (() => {
|
|
245
|
-
if (typeof globalThis !==
|
|
270
|
+
if (typeof globalThis !== 'undefined') {
|
|
246
271
|
return globalThis;
|
|
247
272
|
}
|
|
248
|
-
if (typeof self !==
|
|
273
|
+
if (typeof self !== 'undefined') {
|
|
249
274
|
return self;
|
|
250
275
|
}
|
|
251
|
-
if (typeof window !==
|
|
276
|
+
if (typeof window !== 'undefined') {
|
|
252
277
|
return window;
|
|
253
278
|
}
|
|
254
|
-
if (typeof global !==
|
|
279
|
+
if (typeof global !== 'undefined') {
|
|
255
280
|
return global;
|
|
256
281
|
}
|
|
257
|
-
throw
|
|
282
|
+
throw 'Unable to locate global object';
|
|
258
283
|
})();
|
|
259
284
|
function bytesFromBase64(b64) {
|
|
260
285
|
if (globalThis.Buffer) {
|
|
261
|
-
return Uint8Array.from(globalThis.Buffer.from(b64,
|
|
286
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
|
|
262
287
|
}
|
|
263
288
|
else {
|
|
264
289
|
const bin = globalThis.atob(b64);
|
|
@@ -271,14 +296,14 @@ function bytesFromBase64(b64) {
|
|
|
271
296
|
}
|
|
272
297
|
function base64FromBytes(arr) {
|
|
273
298
|
if (globalThis.Buffer) {
|
|
274
|
-
return globalThis.Buffer.from(arr).toString(
|
|
299
|
+
return globalThis.Buffer.from(arr).toString('base64');
|
|
275
300
|
}
|
|
276
301
|
else {
|
|
277
302
|
const bin = [];
|
|
278
303
|
arr.forEach((byte) => {
|
|
279
304
|
bin.push(String.fromCharCode(byte));
|
|
280
305
|
});
|
|
281
|
-
return globalThis.btoa(bin.join(
|
|
306
|
+
return globalThis.btoa(bin.join(''));
|
|
282
307
|
}
|
|
283
308
|
}
|
|
284
309
|
if (_m0.util.Long !== Long) {
|
|
@@ -11,6 +11,7 @@ export declare class CommonRPC {
|
|
|
11
11
|
protected method?: string;
|
|
12
12
|
constructor();
|
|
13
13
|
writeCallData(data?: Uint8Array, complete?: boolean, error?: string): Promise<void>;
|
|
14
|
+
writeCallCancel(): Promise<void>;
|
|
14
15
|
writeCallDataFromSource(dataSource: AsyncIterable<Uint8Array>): Promise<void>;
|
|
15
16
|
protected writePacket(packet: Packet): Promise<void>;
|
|
16
17
|
handleMessage(message: Uint8Array): Promise<void>;
|
package/dist/srpc/common-rpc.js
CHANGED
|
@@ -26,6 +26,15 @@ export class CommonRPC {
|
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
// writeCallCancel writes the call cancel packet.
|
|
30
|
+
async writeCallCancel() {
|
|
31
|
+
await this.writePacket({
|
|
32
|
+
body: {
|
|
33
|
+
$case: 'callCancel',
|
|
34
|
+
callCancel: true,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
29
38
|
// writeCallDataFromSource writes all call data from the iterable.
|
|
30
39
|
async writeCallDataFromSource(dataSource) {
|
|
31
40
|
try {
|
|
@@ -101,10 +110,15 @@ export class CommonRPC {
|
|
|
101
110
|
this._rpcDataSource.end();
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
|
-
// close
|
|
113
|
+
// close closes the call, optionally with an error.
|
|
105
114
|
async close(err) {
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
try {
|
|
116
|
+
await this.writeCallCancel();
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
this._rpcDataSource.end(err);
|
|
120
|
+
this._source.end(err);
|
|
121
|
+
}
|
|
108
122
|
}
|
|
109
123
|
// _createSink returns a value for the sink field.
|
|
110
124
|
_createSink() {
|
|
@@ -116,7 +130,8 @@ export class CommonRPC {
|
|
|
116
130
|
}
|
|
117
131
|
catch (err) {
|
|
118
132
|
const anyErr = err;
|
|
119
|
-
if (anyErr?.code !== 'ERR_STREAM_RESET' &&
|
|
133
|
+
if (anyErr?.code !== 'ERR_STREAM_RESET' &&
|
|
134
|
+
anyErr?.code !== 'ERR_STREAM_ABORT') {
|
|
120
135
|
this.close(err);
|
|
121
136
|
}
|
|
122
137
|
}
|