@dxos/rpc 2.19.5 → 2.19.7-dev.3aa68bc8
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/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/proto/gen/dxos/rpc.d.ts +13 -2
- package/dist/src/proto/gen/dxos/rpc.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/rpc.js +9 -0
- package/dist/src/proto/gen/dxos/rpc.js.map +1 -1
- package/dist/src/proto/gen/google/protobuf.d.ts +4 -0
- package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/src/proto/gen/index.d.ts +3 -0
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/src/rpc.d.ts +5 -4
- package/dist/src/rpc.d.ts.map +1 -1
- package/dist/src/rpc.js.map +1 -1
- package/dist/src/rpc.test.js +42 -42
- package/dist/src/rpc.test.js.map +1 -1
- package/dist/src/trace.d.ts +11 -0
- package/dist/src/trace.d.ts.map +1 -0
- package/dist/src/trace.js +37 -0
- package/dist/src/trace.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -6
- package/src/index.ts +1 -0
- package/src/proto/gen/dxos/rpc.ts +12 -2
- package/src/proto/gen/google/protobuf.ts +4 -0
- package/src/proto/gen/index.ts +4 -1
- package/src/proto/import.proto +9 -0
- package/src/rpc.test.ts +46 -45
- package/src/rpc.ts +5 -4
- package/src/trace.ts +42 -0
- package/src/proto/schema.proto +0 -48
package/src/rpc.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { StackTrace } from '@dxos/debug';
|
|
|
12
12
|
import { RpcClosedError, RpcNotOpenError, SerializedRpcError } from './errors';
|
|
13
13
|
import { schema } from './proto/gen';
|
|
14
14
|
import { Request, Response, Error as ErrorResponse, RpcMessage } from './proto/gen/dxos/rpc';
|
|
15
|
+
import { Any } from './proto/gen/google/protobuf';
|
|
15
16
|
|
|
16
17
|
const DEFAULT_TIMEOUT = 3000;
|
|
17
18
|
|
|
@@ -20,8 +21,8 @@ const log = debug('dxos:rpc');
|
|
|
20
21
|
type MaybePromise<T> = Promise<T> | T
|
|
21
22
|
|
|
22
23
|
export interface RpcPeerOptions {
|
|
23
|
-
messageHandler: (method: string, request:
|
|
24
|
-
streamHandler?: (method: string, request:
|
|
24
|
+
messageHandler: (method: string, request: Any) => MaybePromise<Any>
|
|
25
|
+
streamHandler?: (method: string, request: Any) => Stream<Any>
|
|
25
26
|
port: RpcPort,
|
|
26
27
|
timeout?: number,
|
|
27
28
|
}
|
|
@@ -169,7 +170,7 @@ export class RpcPeer {
|
|
|
169
170
|
*
|
|
170
171
|
* Peer should be open before making this call.
|
|
171
172
|
*/
|
|
172
|
-
async call (method: string, request:
|
|
173
|
+
async call (method: string, request: Any): Promise<Any> {
|
|
173
174
|
if (!this._open) {
|
|
174
175
|
throw new RpcNotOpenError();
|
|
175
176
|
}
|
|
@@ -223,7 +224,7 @@ export class RpcPeer {
|
|
|
223
224
|
*
|
|
224
225
|
* Peer should be open before making this call.
|
|
225
226
|
*/
|
|
226
|
-
callStream (method: string, request:
|
|
227
|
+
callStream (method: string, request: Any): Stream<Any> {
|
|
227
228
|
if (!this._open) {
|
|
228
229
|
throw new RpcNotOpenError();
|
|
229
230
|
}
|
package/src/trace.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2021 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Event } from '@dxos/async';
|
|
6
|
+
|
|
7
|
+
import { MessageTrace } from './proto/gen/dxos/rpc';
|
|
8
|
+
import { RpcPort } from './rpc';
|
|
9
|
+
|
|
10
|
+
export class PortTracer {
|
|
11
|
+
readonly message = new Event<MessageTrace>();
|
|
12
|
+
|
|
13
|
+
private readonly _port: RpcPort;
|
|
14
|
+
|
|
15
|
+
constructor (
|
|
16
|
+
private readonly _wrappedPort: RpcPort
|
|
17
|
+
) {
|
|
18
|
+
this._port = {
|
|
19
|
+
send: (msg: Uint8Array) => {
|
|
20
|
+
this.message.emit({
|
|
21
|
+
direction: MessageTrace.Direction.OUTGOING,
|
|
22
|
+
data: msg
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return this._wrappedPort.send(msg);
|
|
26
|
+
},
|
|
27
|
+
subscribe: (cb: (msg: Uint8Array) => void) => {
|
|
28
|
+
return this._wrappedPort.subscribe(msg => {
|
|
29
|
+
this.message.emit({
|
|
30
|
+
direction: MessageTrace.Direction.INCOMING,
|
|
31
|
+
data: msg
|
|
32
|
+
});
|
|
33
|
+
cb(msg);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public get port () {
|
|
40
|
+
return this._port;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/proto/schema.proto
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2020 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
syntax = "proto3";
|
|
6
|
-
|
|
7
|
-
package dxos.rpc;
|
|
8
|
-
|
|
9
|
-
message RpcMessage {
|
|
10
|
-
oneof content {
|
|
11
|
-
Request request = 1;
|
|
12
|
-
Response response = 2;
|
|
13
|
-
|
|
14
|
-
/// Means that the node is open to receiving requests. Second stage of the hasnshake protocol.
|
|
15
|
-
bool open = 3;
|
|
16
|
-
|
|
17
|
-
StreamClose streamClose = 4;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
message Request {
|
|
22
|
-
int32 id = 1;
|
|
23
|
-
string method = 2;
|
|
24
|
-
bytes payload = 3;
|
|
25
|
-
bool stream = 4;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
message Response {
|
|
29
|
-
int32 id = 1;
|
|
30
|
-
oneof content {
|
|
31
|
-
bytes payload = 2;
|
|
32
|
-
Error error = 3;
|
|
33
|
-
// Sent when stream is closed without an error.
|
|
34
|
-
bool close = 4;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Sent by client to end the streaming response.
|
|
39
|
-
message StreamClose {
|
|
40
|
-
int32 id = 1;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
message Error {
|
|
45
|
-
string name = 1;
|
|
46
|
-
string message = 2;
|
|
47
|
-
string stack = 3;
|
|
48
|
-
}
|