starpc 0.31.6 → 0.31.8
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 +4 -4
- package/cmd/protoc-gen-es-starpc/typescript.ts +17 -16
- package/dist/cmd/protoc-gen-es-starpc/typescript.js +15 -14
- package/dist/e2e/mock/mock_pb.d.ts +5 -12
- package/dist/e2e/mock/mock_pb.js +9 -33
- package/dist/e2e/mock/mock_srpc.pb.d.ts +5 -5
- package/dist/e2e/mock/mock_srpc.pb.js +2 -2
- package/dist/echo/echo_pb.d.ts +5 -12
- package/dist/echo/echo_pb.js +9 -33
- package/dist/echo/echo_srpc.pb.d.ts +17 -17
- package/dist/echo/echo_srpc.pb.js +4 -4
- package/dist/echo/server.d.ts +3 -3
- package/dist/rpcstream/rpcstream.d.ts +3 -3
- package/dist/rpcstream/rpcstream_pb.d.ts +36 -57
- package/dist/rpcstream/rpcstream_pb.js +28 -106
- package/dist/srpc/client-rpc.d.ts +1 -1
- package/dist/srpc/client-rpc.js +1 -1
- package/dist/srpc/common-rpc.d.ts +4 -5
- package/dist/srpc/definition.d.ts +2 -1
- package/dist/srpc/invoker.d.ts +3 -2
- package/dist/srpc/invoker.js +1 -1
- package/dist/srpc/message.d.ts +4 -4
- package/dist/srpc/message.js +3 -3
- package/dist/srpc/pushable.d.ts +2 -2
- package/dist/srpc/pushable.js +1 -1
- package/dist/srpc/rpcproto_pb.d.ts +55 -76
- package/dist/srpc/rpcproto_pb.js +30 -150
- package/e2e/mock/mock_pb.ts +18 -50
- package/e2e/mock/mock_srpc.pb.ts +7 -7
- package/echo/client-test.ts +2 -2
- package/echo/echo_pb.ts +18 -50
- package/echo/echo_srpc.pb.ts +13 -13
- package/echo/server.ts +3 -3
- package/go.mod +1 -1
- package/go.sum +2 -0
- package/package.json +22 -7
- package/srpc/client-rpc.ts +4 -4
- package/srpc/common-rpc.ts +9 -9
- package/srpc/definition.ts +2 -1
- package/srpc/invoker.ts +7 -12
- package/srpc/message.ts +9 -11
- package/srpc/pushable.ts +4 -6
- package/srpc/rpcproto_pb.ts +91 -188
package/dist/srpc/rpcproto_pb.js
CHANGED
|
@@ -1,89 +1,11 @@
|
|
|
1
|
-
// @generated by protoc-gen-es
|
|
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 {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
export class Packet extends Message {
|
|
11
|
-
/**
|
|
12
|
-
* Body is the packet body.
|
|
13
|
-
*
|
|
14
|
-
* @generated from oneof srpc.Packet.body
|
|
15
|
-
*/
|
|
16
|
-
body = { case: undefined };
|
|
17
|
-
constructor(data) {
|
|
18
|
-
super();
|
|
19
|
-
proto3.util.initPartial(data, this);
|
|
20
|
-
}
|
|
21
|
-
static runtime = proto3;
|
|
22
|
-
static typeName = 'srpc.Packet';
|
|
23
|
-
static fields = proto3.util.newFieldList(() => [
|
|
24
|
-
{ no: 1, name: 'call_start', kind: 'message', T: CallStart, oneof: 'body' },
|
|
25
|
-
{ no: 2, name: 'call_data', kind: 'message', T: CallData, oneof: 'body' },
|
|
26
|
-
{
|
|
27
|
-
no: 3,
|
|
28
|
-
name: 'call_cancel',
|
|
29
|
-
kind: 'scalar',
|
|
30
|
-
T: 8 /* ScalarType.BOOL */,
|
|
31
|
-
oneof: 'body',
|
|
32
|
-
},
|
|
33
|
-
]);
|
|
34
|
-
static fromBinary(bytes, options) {
|
|
35
|
-
return new Packet().fromBinary(bytes, options);
|
|
36
|
-
}
|
|
37
|
-
static fromJson(jsonValue, options) {
|
|
38
|
-
return new Packet().fromJson(jsonValue, options);
|
|
39
|
-
}
|
|
40
|
-
static fromJsonString(jsonString, options) {
|
|
41
|
-
return new Packet().fromJsonString(jsonString, options);
|
|
42
|
-
}
|
|
43
|
-
static equals(a, b) {
|
|
44
|
-
return proto3.util.equals(Packet, a, b);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* CallStart requests starting a new RPC call.
|
|
49
|
-
*
|
|
50
|
-
* @generated from message srpc.CallStart
|
|
51
|
-
*/
|
|
52
|
-
export class CallStart extends Message {
|
|
53
|
-
/**
|
|
54
|
-
* RpcService is the service to contact.
|
|
55
|
-
* Must be set.
|
|
56
|
-
*
|
|
57
|
-
* @generated from field: string rpc_service = 1;
|
|
58
|
-
*/
|
|
59
|
-
rpcService = '';
|
|
60
|
-
/**
|
|
61
|
-
* RpcMethod is the RPC method to call.
|
|
62
|
-
* Must be set.
|
|
63
|
-
*
|
|
64
|
-
* @generated from field: string rpc_method = 2;
|
|
65
|
-
*/
|
|
66
|
-
rpcMethod = '';
|
|
67
|
-
/**
|
|
68
|
-
* Data contains the request or the first message in the stream.
|
|
69
|
-
* Optional if streaming.
|
|
70
|
-
*
|
|
71
|
-
* @generated from field: bytes data = 3;
|
|
72
|
-
*/
|
|
73
|
-
data = new Uint8Array(0);
|
|
74
|
-
/**
|
|
75
|
-
* DataIsZero indicates Data is set with an empty message.
|
|
76
|
-
*
|
|
77
|
-
* @generated from field: bool data_is_zero = 4;
|
|
78
|
-
*/
|
|
79
|
-
dataIsZero = false;
|
|
80
|
-
constructor(data) {
|
|
81
|
-
super();
|
|
82
|
-
proto3.util.initPartial(data, this);
|
|
83
|
-
}
|
|
84
|
-
static runtime = proto3;
|
|
85
|
-
static typeName = 'srpc.CallStart';
|
|
86
|
-
static fields = proto3.util.newFieldList(() => [
|
|
4
|
+
import { createMessageType, } from '@aptre/protobuf-es-lite';
|
|
5
|
+
export const protobufPackage = 'srpc';
|
|
6
|
+
export const CallStart = createMessageType({
|
|
7
|
+
typeName: 'srpc.CallStart',
|
|
8
|
+
fields: [
|
|
87
9
|
{
|
|
88
10
|
no: 1,
|
|
89
11
|
name: 'rpc_service',
|
|
@@ -93,73 +15,31 @@ export class CallStart extends Message {
|
|
|
93
15
|
{ no: 2, name: 'rpc_method', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
94
16
|
{ no: 3, name: 'data', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
|
|
95
17
|
{ no: 4, name: 'data_is_zero', kind: 'scalar', T: 8 /* ScalarType.BOOL */ },
|
|
96
|
-
]
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
static fromJsonString(jsonString, options) {
|
|
104
|
-
return new CallStart().fromJsonString(jsonString, options);
|
|
105
|
-
}
|
|
106
|
-
static equals(a, b) {
|
|
107
|
-
return proto3.util.equals(CallStart, a, b);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* CallData contains a message in a streaming RPC sequence.
|
|
112
|
-
*
|
|
113
|
-
* @generated from message srpc.CallData
|
|
114
|
-
*/
|
|
115
|
-
export class CallData extends Message {
|
|
116
|
-
/**
|
|
117
|
-
* Data contains the packet in the sequence.
|
|
118
|
-
*
|
|
119
|
-
* @generated from field: bytes data = 1;
|
|
120
|
-
*/
|
|
121
|
-
data = new Uint8Array(0);
|
|
122
|
-
/**
|
|
123
|
-
* DataIsZero indicates Data is set with an empty message.
|
|
124
|
-
*
|
|
125
|
-
* @generated from field: bool data_is_zero = 2;
|
|
126
|
-
*/
|
|
127
|
-
dataIsZero = false;
|
|
128
|
-
/**
|
|
129
|
-
* Complete indicates the RPC call is completed.
|
|
130
|
-
*
|
|
131
|
-
* @generated from field: bool complete = 3;
|
|
132
|
-
*/
|
|
133
|
-
complete = false;
|
|
134
|
-
/**
|
|
135
|
-
* Error contains any error that caused the RPC to fail.
|
|
136
|
-
* If set, implies complete=true.
|
|
137
|
-
*
|
|
138
|
-
* @generated from field: string error = 4;
|
|
139
|
-
*/
|
|
140
|
-
error = '';
|
|
141
|
-
constructor(data) {
|
|
142
|
-
super();
|
|
143
|
-
proto3.util.initPartial(data, this);
|
|
144
|
-
}
|
|
145
|
-
static runtime = proto3;
|
|
146
|
-
static typeName = 'srpc.CallData';
|
|
147
|
-
static fields = proto3.util.newFieldList(() => [
|
|
18
|
+
],
|
|
19
|
+
packedByDefault: true,
|
|
20
|
+
});
|
|
21
|
+
export const CallData = createMessageType({
|
|
22
|
+
typeName: 'srpc.CallData',
|
|
23
|
+
fields: [
|
|
148
24
|
{ no: 1, name: 'data', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
|
|
149
25
|
{ no: 2, name: 'data_is_zero', kind: 'scalar', T: 8 /* ScalarType.BOOL */ },
|
|
150
26
|
{ no: 3, name: 'complete', kind: 'scalar', T: 8 /* ScalarType.BOOL */ },
|
|
151
27
|
{ no: 4, name: 'error', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
152
|
-
]
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
28
|
+
],
|
|
29
|
+
packedByDefault: true,
|
|
30
|
+
});
|
|
31
|
+
export const Packet = createMessageType({
|
|
32
|
+
typeName: 'srpc.Packet',
|
|
33
|
+
fields: [
|
|
34
|
+
{ no: 1, name: 'call_start', kind: 'message', T: CallStart, oneof: 'body' },
|
|
35
|
+
{ no: 2, name: 'call_data', kind: 'message', T: CallData, oneof: 'body' },
|
|
36
|
+
{
|
|
37
|
+
no: 3,
|
|
38
|
+
name: 'call_cancel',
|
|
39
|
+
kind: 'scalar',
|
|
40
|
+
T: 8 /* ScalarType.BOOL */,
|
|
41
|
+
oneof: 'body',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
packedByDefault: true,
|
|
45
|
+
});
|
package/e2e/mock/mock_pb.ts
CHANGED
|
@@ -1,64 +1,32 @@
|
|
|
1
|
-
// @generated by protoc-gen-es
|
|
1
|
+
// @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
|
|
2
2
|
// @generated from file github.com/aperturerobotics/starpc/e2e/mock/mock.proto (package e2e.mock, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { Message, proto3 } from '@bufbuild/protobuf'
|
|
5
|
+
import {
|
|
6
|
+
createMessageType,
|
|
7
|
+
Message,
|
|
8
|
+
MessageType,
|
|
9
|
+
PartialFieldInfo,
|
|
10
|
+
} from '@aptre/protobuf-es-lite'
|
|
11
|
+
|
|
12
|
+
export const protobufPackage = 'e2e.mock'
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* MockMsg is the mock message body.
|
|
17
16
|
*
|
|
18
17
|
* @generated from message e2e.mock.MockMsg
|
|
19
18
|
*/
|
|
20
|
-
export
|
|
19
|
+
export interface MockMsg extends Message<MockMsg> {
|
|
21
20
|
/**
|
|
22
21
|
* @generated from field: string body = 1;
|
|
23
22
|
*/
|
|
24
|
-
body
|
|
25
|
-
|
|
26
|
-
constructor(data?: PartialMessage<MockMsg>) {
|
|
27
|
-
super()
|
|
28
|
-
proto3.util.initPartial(data, this)
|
|
29
|
-
}
|
|
23
|
+
body?: string
|
|
24
|
+
}
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
export const MockMsg: MessageType<MockMsg> = createMessageType({
|
|
27
|
+
typeName: 'e2e.mock.MockMsg',
|
|
28
|
+
fields: [
|
|
34
29
|
{ no: 1, name: 'body', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
bytes: Uint8Array,
|
|
39
|
-
options?: Partial<BinaryReadOptions>,
|
|
40
|
-
): MockMsg {
|
|
41
|
-
return new MockMsg().fromBinary(bytes, options)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static fromJson(
|
|
45
|
-
jsonValue: JsonValue,
|
|
46
|
-
options?: Partial<JsonReadOptions>,
|
|
47
|
-
): MockMsg {
|
|
48
|
-
return new MockMsg().fromJson(jsonValue, options)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static fromJsonString(
|
|
52
|
-
jsonString: string,
|
|
53
|
-
options?: Partial<JsonReadOptions>,
|
|
54
|
-
): MockMsg {
|
|
55
|
-
return new MockMsg().fromJsonString(jsonString, options)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static equals(
|
|
59
|
-
a: MockMsg | PlainMessage<MockMsg> | undefined,
|
|
60
|
-
b: MockMsg | PlainMessage<MockMsg> | undefined,
|
|
61
|
-
): boolean {
|
|
62
|
-
return proto3.util.equals(MockMsg, a, b)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
30
|
+
] as readonly PartialFieldInfo[],
|
|
31
|
+
packedByDefault: true,
|
|
32
|
+
})
|
package/e2e/mock/mock_srpc.pb.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
|
|
5
5
|
import { MockMsg } from "./mock_pb.js";
|
|
6
|
-
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
7
6
|
import { MethodKind } from "@bufbuild/protobuf";
|
|
7
|
+
import { Message } from "@aptre/protobuf-es-lite";
|
|
8
8
|
import { ProtoRpc } from "starpc";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -41,9 +41,9 @@ export interface Mock {
|
|
|
41
41
|
* @generated from rpc e2e.mock.Mock.MockRequest
|
|
42
42
|
*/
|
|
43
43
|
MockRequest(
|
|
44
|
-
request:
|
|
44
|
+
request: Message<MockMsg>, abortSignal?: AbortSignal
|
|
45
45
|
):
|
|
46
|
-
Promise<
|
|
46
|
+
Promise<Message<MockMsg>>
|
|
47
47
|
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -63,14 +63,14 @@ export class MockClient implements Mock {
|
|
|
63
63
|
* @generated from rpc e2e.mock.Mock.MockRequest
|
|
64
64
|
*/
|
|
65
65
|
async MockRequest(
|
|
66
|
-
request:
|
|
66
|
+
request: Message<MockMsg>, abortSignal?: AbortSignal
|
|
67
67
|
):
|
|
68
|
-
Promise<
|
|
69
|
-
const requestMsg =
|
|
68
|
+
Promise<Message<MockMsg>> {
|
|
69
|
+
const requestMsg = MockMsg.create(request)
|
|
70
70
|
const result = await this.rpc.request(
|
|
71
71
|
this.service,
|
|
72
72
|
MockDefinition.methods.MockRequest.name,
|
|
73
|
-
|
|
73
|
+
MockMsg.toBinary(requestMsg),
|
|
74
74
|
abortSignal || undefined,
|
|
75
75
|
)
|
|
76
76
|
return MockMsg.fromBinary(result)
|
package/echo/client-test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { EchoMsg } from './echo_pb.js'
|
|
|
3
3
|
import { EchoerClient } from './echo_srpc.pb.js'
|
|
4
4
|
import { pushable } from 'it-pushable'
|
|
5
5
|
import { buildRpcStreamOpenStream } from '../rpcstream/rpcstream.js'
|
|
6
|
-
import {
|
|
6
|
+
import { Message } from '@aptre/protobuf-es-lite'
|
|
7
7
|
|
|
8
8
|
export async function runClientTest(client: Client) {
|
|
9
9
|
const demoServiceClient = new EchoerClient(client)
|
|
@@ -15,7 +15,7 @@ export async function runClientTest(client: Client) {
|
|
|
15
15
|
console.log('success: output', result.body)
|
|
16
16
|
|
|
17
17
|
// observable for client requests
|
|
18
|
-
const clientRequestStream = pushable<
|
|
18
|
+
const clientRequestStream = pushable<Message<EchoMsg>>({
|
|
19
19
|
objectMode: true,
|
|
20
20
|
})
|
|
21
21
|
clientRequestStream.push({ body: 'Hello world from streaming request.' })
|
package/echo/echo_pb.ts
CHANGED
|
@@ -1,64 +1,32 @@
|
|
|
1
|
-
// @generated by protoc-gen-es
|
|
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
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { Message, proto3 } from '@bufbuild/protobuf'
|
|
5
|
+
import {
|
|
6
|
+
createMessageType,
|
|
7
|
+
Message,
|
|
8
|
+
MessageType,
|
|
9
|
+
PartialFieldInfo,
|
|
10
|
+
} from '@aptre/protobuf-es-lite'
|
|
11
|
+
|
|
12
|
+
export const protobufPackage = 'echo'
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* EchoMsg is the message body for Echo.
|
|
17
16
|
*
|
|
18
17
|
* @generated from message echo.EchoMsg
|
|
19
18
|
*/
|
|
20
|
-
export
|
|
19
|
+
export interface EchoMsg extends Message<EchoMsg> {
|
|
21
20
|
/**
|
|
22
21
|
* @generated from field: string body = 1;
|
|
23
22
|
*/
|
|
24
|
-
body
|
|
25
|
-
|
|
26
|
-
constructor(data?: PartialMessage<EchoMsg>) {
|
|
27
|
-
super()
|
|
28
|
-
proto3.util.initPartial(data, this)
|
|
29
|
-
}
|
|
23
|
+
body?: string
|
|
24
|
+
}
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
export const EchoMsg: MessageType<EchoMsg> = createMessageType({
|
|
27
|
+
typeName: 'echo.EchoMsg',
|
|
28
|
+
fields: [
|
|
34
29
|
{ no: 1, name: 'body', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
bytes: Uint8Array,
|
|
39
|
-
options?: Partial<BinaryReadOptions>,
|
|
40
|
-
): EchoMsg {
|
|
41
|
-
return new EchoMsg().fromBinary(bytes, options)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static fromJson(
|
|
45
|
-
jsonValue: JsonValue,
|
|
46
|
-
options?: Partial<JsonReadOptions>,
|
|
47
|
-
): EchoMsg {
|
|
48
|
-
return new EchoMsg().fromJson(jsonValue, options)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static fromJsonString(
|
|
52
|
-
jsonString: string,
|
|
53
|
-
options?: Partial<JsonReadOptions>,
|
|
54
|
-
): EchoMsg {
|
|
55
|
-
return new EchoMsg().fromJsonString(jsonString, options)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static equals(
|
|
59
|
-
a: EchoMsg | PlainMessage<EchoMsg> | undefined,
|
|
60
|
-
b: EchoMsg | PlainMessage<EchoMsg> | undefined,
|
|
61
|
-
): boolean {
|
|
62
|
-
return proto3.util.equals(EchoMsg, a, b)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
30
|
+
] as readonly PartialFieldInfo[],
|
|
31
|
+
packedByDefault: true,
|
|
32
|
+
})
|
package/echo/echo_srpc.pb.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
|
|
5
5
|
import { EchoMsg } from "./echo_pb.js";
|
|
6
|
-
import type { PartialMessage } from "@bufbuild/protobuf";
|
|
7
6
|
import { MethodKind } from "@bufbuild/protobuf";
|
|
8
7
|
import { RpcStreamPacket } from "../rpcstream/rpcstream_pb.js";
|
|
8
|
+
import { Message } from "@aptre/protobuf-es-lite";
|
|
9
9
|
import { buildDecodeMessageTransform, buildEncodeMessageTransform, MessageStream, ProtoRpc } from "starpc";
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -86,9 +86,9 @@ export interface Echoer {
|
|
|
86
86
|
* @generated from rpc echo.Echoer.Echo
|
|
87
87
|
*/
|
|
88
88
|
Echo(
|
|
89
|
-
request:
|
|
89
|
+
request: Message<EchoMsg>, abortSignal?: AbortSignal
|
|
90
90
|
):
|
|
91
|
-
Promise<
|
|
91
|
+
Promise<Message<EchoMsg>>
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* EchoServerStream is an example of a server -> client one-way stream.
|
|
@@ -96,7 +96,7 @@ Promise<PartialMessage<EchoMsg>>
|
|
|
96
96
|
* @generated from rpc echo.Echoer.EchoServerStream
|
|
97
97
|
*/
|
|
98
98
|
EchoServerStream(
|
|
99
|
-
request:
|
|
99
|
+
request: Message<EchoMsg>, abortSignal?: AbortSignal
|
|
100
100
|
):
|
|
101
101
|
MessageStream<EchoMsg>
|
|
102
102
|
|
|
@@ -108,7 +108,7 @@ MessageStream<EchoMsg>
|
|
|
108
108
|
EchoClientStream(
|
|
109
109
|
request: MessageStream<EchoMsg>, abortSignal?: AbortSignal
|
|
110
110
|
):
|
|
111
|
-
Promise<
|
|
111
|
+
Promise<Message<EchoMsg>>
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* EchoBidiStream is an example of a two-way stream.
|
|
@@ -152,14 +152,14 @@ export class EchoerClient implements Echoer {
|
|
|
152
152
|
* @generated from rpc echo.Echoer.Echo
|
|
153
153
|
*/
|
|
154
154
|
async Echo(
|
|
155
|
-
request:
|
|
155
|
+
request: Message<EchoMsg>, abortSignal?: AbortSignal
|
|
156
156
|
):
|
|
157
|
-
Promise<
|
|
158
|
-
const requestMsg =
|
|
157
|
+
Promise<Message<EchoMsg>> {
|
|
158
|
+
const requestMsg = EchoMsg.create(request)
|
|
159
159
|
const result = await this.rpc.request(
|
|
160
160
|
this.service,
|
|
161
161
|
EchoerDefinition.methods.Echo.name,
|
|
162
|
-
|
|
162
|
+
EchoMsg.toBinary(requestMsg),
|
|
163
163
|
abortSignal || undefined,
|
|
164
164
|
)
|
|
165
165
|
return EchoMsg.fromBinary(result)
|
|
@@ -171,14 +171,14 @@ Promise<PartialMessage<EchoMsg>> {
|
|
|
171
171
|
* @generated from rpc echo.Echoer.EchoServerStream
|
|
172
172
|
*/
|
|
173
173
|
EchoServerStream(
|
|
174
|
-
request:
|
|
174
|
+
request: Message<EchoMsg>, abortSignal?: AbortSignal
|
|
175
175
|
):
|
|
176
176
|
MessageStream<EchoMsg> {
|
|
177
|
-
const requestMsg =
|
|
177
|
+
const requestMsg = EchoMsg.create(request)
|
|
178
178
|
const result = this.rpc.serverStreamingRequest(
|
|
179
179
|
this.service,
|
|
180
180
|
EchoerDefinition.methods.EchoServerStream.name,
|
|
181
|
-
|
|
181
|
+
EchoMsg.toBinary(requestMsg),
|
|
182
182
|
abortSignal || undefined,
|
|
183
183
|
)
|
|
184
184
|
return buildDecodeMessageTransform(EchoMsg)(result)
|
|
@@ -192,7 +192,7 @@ MessageStream<EchoMsg> {
|
|
|
192
192
|
async EchoClientStream(
|
|
193
193
|
request: MessageStream<EchoMsg>, abortSignal?: AbortSignal
|
|
194
194
|
):
|
|
195
|
-
Promise<
|
|
195
|
+
Promise<Message<EchoMsg>> {
|
|
196
196
|
const result = await this.rpc.clientStreamingRequest(
|
|
197
197
|
this.service,
|
|
198
198
|
EchoerDefinition.methods.EchoClientStream.name,
|
package/echo/server.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import first from 'it-first'
|
|
2
|
+
import { Message } from '@aptre/protobuf-es-lite'
|
|
2
3
|
import { EchoMsg } from './echo_pb.js'
|
|
3
4
|
import { Server } from '../srpc/server.js'
|
|
4
5
|
import { messagePushable, writeToPushable } from '../srpc/pushable.js'
|
|
@@ -6,7 +7,6 @@ import { RpcStreamPacket } from '../rpcstream/rpcstream_pb.js'
|
|
|
6
7
|
import { MessageStream } from '../srpc/message.js'
|
|
7
8
|
import { handleRpcStream, RpcStreamHandler } from '../rpcstream/rpcstream.js'
|
|
8
9
|
import { Echoer } from './echo_srpc.pb.js'
|
|
9
|
-
import { PartialMessage } from '@bufbuild/protobuf'
|
|
10
10
|
|
|
11
11
|
// EchoServer implements the Echoer server.
|
|
12
12
|
export class EchoerServer implements Echoer {
|
|
@@ -17,7 +17,7 @@ export class EchoerServer implements Echoer {
|
|
|
17
17
|
this.proxyServer = proxyServer
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public async Echo(request: EchoMsg): Promise<
|
|
20
|
+
public async Echo(request: EchoMsg): Promise<Message<EchoMsg>> {
|
|
21
21
|
return request
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -30,7 +30,7 @@ export class EchoerServer implements Echoer {
|
|
|
30
30
|
|
|
31
31
|
public async EchoClientStream(
|
|
32
32
|
request: MessageStream<EchoMsg>,
|
|
33
|
-
): Promise<
|
|
33
|
+
): Promise<Message<EchoMsg>> {
|
|
34
34
|
// return the first message sent by the client.
|
|
35
35
|
const message = await first(request)
|
|
36
36
|
if (!message) {
|
package/go.mod
CHANGED
package/go.sum
CHANGED
|
@@ -4,6 +4,8 @@ github.com/aperturerobotics/protobuf-go-lite v0.6.0 h1:EE168e2oov6wmDv8AdSAlz2G1
|
|
|
4
4
|
github.com/aperturerobotics/protobuf-go-lite v0.6.0/go.mod h1:6Bp+C+fI1uh0NmIKpxlxyHMkKtCP9Kb3PHkhOzxG4B8=
|
|
5
5
|
github.com/aperturerobotics/util v1.20.1 h1:A4lcyULNtpID2pykIBLr7putGXFjjGi5EX0BpaVcdtY=
|
|
6
6
|
github.com/aperturerobotics/util v1.20.1/go.mod h1:m6rsllH5ubGZvwFmdY3Tvm6LMgBtghqxPTynimEevl0=
|
|
7
|
+
github.com/aperturerobotics/util v1.20.3 h1:HwPuHzOKLbZCw06AkVIDqrLAnMUJ4qxfWHJvS9gqZMQ=
|
|
8
|
+
github.com/aperturerobotics/util v1.20.3/go.mod h1:4OxnbOvsS3jMZ9iLEUBaW79TQY/008nNWRrZfhe9ORg=
|
|
7
9
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
8
10
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
9
11
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.8",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -59,35 +59,49 @@
|
|
|
59
59
|
"lint": "npm run lint:go && npm run lint:js",
|
|
60
60
|
"lint:go": "make lint",
|
|
61
61
|
"lint:js": "ESLINT_USE_FLAT_CONFIG=false eslint -c .eslintrc.cjs --ignore-pattern *.js --ignore-pattern *.d.ts ./",
|
|
62
|
+
"release:version": "npm version patch -m \"release: v%s\" --no-git-tag-version",
|
|
63
|
+
"release:commit": "git reset && git add package.json && git commit -s -m \"release: v$npm_package_version\" && git tag v$npm_package_version",
|
|
64
|
+
"release:publish": "git push && git push --tags && npm run build && npm publish",
|
|
65
|
+
"release": "npm run release:version && npm run release:commit",
|
|
62
66
|
"prepare": "go mod vendor",
|
|
63
|
-
"precommit": "
|
|
67
|
+
"precommit": "lint-staged"
|
|
68
|
+
},
|
|
69
|
+
"preferUnplugged": true,
|
|
70
|
+
"pre-commit": [
|
|
71
|
+
"precommit"
|
|
72
|
+
],
|
|
73
|
+
"lint-staged": {
|
|
74
|
+
"package.json": "prettier --write",
|
|
75
|
+
"./{srpc,echo,e2e,integration,rpcstream,cmd}/**/(*.ts|*.tsx|*.html|*.css)": "prettier --write"
|
|
64
76
|
},
|
|
65
77
|
"prettier": {
|
|
66
78
|
"semi": false,
|
|
67
79
|
"singleQuote": true
|
|
68
80
|
},
|
|
69
81
|
"devDependencies": {
|
|
70
|
-
"@bufbuild/protoc-gen-es": "^1.9.0",
|
|
71
82
|
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
72
83
|
"@typescript-eslint/parser": "^7.7.1",
|
|
73
84
|
"depcheck": "^1.4.6",
|
|
74
85
|
"esbuild": "^0.20.0",
|
|
75
86
|
"eslint": "^9.1.1",
|
|
76
87
|
"eslint-config-prettier": "^9.1.0",
|
|
88
|
+
"lint-staged": "^15.2.2",
|
|
89
|
+
"pre-commit": "^1.2.2",
|
|
77
90
|
"prettier": "^3.2.4",
|
|
78
91
|
"rimraf": "^5.0.1",
|
|
79
|
-
"tsx": "^4.7.
|
|
92
|
+
"tsx": "^4.7.3",
|
|
80
93
|
"typescript": "^5.3.2"
|
|
81
94
|
},
|
|
82
95
|
"dependencies": {
|
|
83
96
|
"@aptre/it-ws": "^1.0.0",
|
|
97
|
+
"@aptre/protobuf-es-lite": "^0.2.4",
|
|
84
98
|
"@bufbuild/protoplugin": "^1.9.0",
|
|
85
99
|
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
86
|
-
"@libp2p/interface": "^1.
|
|
87
|
-
"@libp2p/logger": "^4.0.
|
|
100
|
+
"@libp2p/interface": "^1.3.0",
|
|
101
|
+
"@libp2p/logger": "^4.0.11",
|
|
88
102
|
"event-iterator": "^2.0.0",
|
|
89
103
|
"isomorphic-ws": "^5.0.0",
|
|
90
|
-
"it-first": "^3.0.
|
|
104
|
+
"it-first": "^3.0.6",
|
|
91
105
|
"it-pipe": "^3.0.1",
|
|
92
106
|
"it-pushable": "^3.2.3",
|
|
93
107
|
"it-stream-types": "^2.0.1",
|
|
@@ -96,6 +110,7 @@
|
|
|
96
110
|
"ws": "^8.15.1"
|
|
97
111
|
},
|
|
98
112
|
"peerDependencies": {
|
|
113
|
+
"@aptre/protobuf-es-lite": "0.2.3",
|
|
99
114
|
"@bufbuild/protobuf": "1.9.0"
|
|
100
115
|
}
|
|
101
116
|
}
|
package/srpc/client-rpc.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { CompleteMessage } from '@aptre/protobuf-es-lite'
|
|
1
2
|
import type { CallStart } from './rpcproto_pb.js'
|
|
2
3
|
import { CommonRPC } from './common-rpc.js'
|
|
3
|
-
import type { PartialMessage } from '@bufbuild/protobuf'
|
|
4
4
|
|
|
5
5
|
// ClientRPC is an ongoing RPC from the client side.
|
|
6
6
|
export class ClientRPC extends CommonRPC {
|
|
@@ -16,7 +16,7 @@ export class ClientRPC extends CommonRPC {
|
|
|
16
16
|
if (!this.service || !this.method) {
|
|
17
17
|
throw new Error('service and method must be set')
|
|
18
18
|
}
|
|
19
|
-
const callStart:
|
|
19
|
+
const callStart: CompleteMessage<CallStart> = {
|
|
20
20
|
rpcService: this.service,
|
|
21
21
|
rpcMethod: this.method,
|
|
22
22
|
data: data || new Uint8Array(0),
|
|
@@ -31,10 +31,10 @@ export class ClientRPC extends CommonRPC {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// handleCallStart handles a CallStart packet.
|
|
34
|
-
public override async handleCallStart(packet:
|
|
34
|
+
public override async handleCallStart(packet: CallStart) {
|
|
35
35
|
// we do not implement server -> client RPCs.
|
|
36
36
|
throw new Error(
|
|
37
|
-
`unexpected server to client rpc: ${packet.rpcService}/${packet.rpcMethod}`,
|
|
37
|
+
`unexpected server to client rpc: ${packet.rpcService || '<empty>'}/${packet.rpcMethod || '<empty>'}`,
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
}
|