@dxos/rpc 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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/LICENSE +102 -5
- package/README.md +5 -5
- package/dist/lib/{browser → neutral}/index.mjs +113 -286
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/rpc.d.ts +1 -3
- package/dist/types/src/rpc.d.ts.map +1 -1
- package/dist/types/src/service.d.ts +2 -2
- package/dist/types/src/service.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/trace.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/rpc.test.ts +1 -2
- package/src/rpc.ts +59 -21
- package/src/service.test.ts +126 -3
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -924
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/rpc",
|
|
3
|
-
"version": "0.8.4-
|
|
3
|
+
"version": "0.8.4-staging.60fe92afc8",
|
|
4
4
|
"description": "A lightweight, transport-agnostic RPC implementation",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
13
17
|
"source": "./src/index.ts",
|
|
14
18
|
"types": "./dist/types/src/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
19
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
17
20
|
}
|
|
18
21
|
},
|
|
19
22
|
"types": "dist/types/src/index.d.ts",
|
|
20
|
-
"typesVersions": {
|
|
21
|
-
"*": {}
|
|
22
|
-
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
25
|
"src"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/util": "0.8.4-
|
|
28
|
+
"@dxos/context": "0.8.4-staging.60fe92afc8",
|
|
29
|
+
"@dxos/async": "0.8.4-staging.60fe92afc8",
|
|
30
|
+
"@dxos/codec-protobuf": "0.8.4-staging.60fe92afc8",
|
|
31
|
+
"@dxos/debug": "0.8.4-staging.60fe92afc8",
|
|
32
|
+
"@dxos/log": "0.8.4-staging.60fe92afc8",
|
|
33
|
+
"@dxos/protocols": "0.8.4-staging.60fe92afc8",
|
|
34
|
+
"@dxos/node-std": "0.8.4-staging.60fe92afc8",
|
|
35
|
+
"@dxos/util": "0.8.4-staging.60fe92afc8",
|
|
36
|
+
"@dxos/invariant": "0.8.4-staging.60fe92afc8"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"access": "public"
|
package/src/rpc.test.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { describe, expect, test } from 'vitest';
|
|
|
7
7
|
import { Trigger, sleep } from '@dxos/async';
|
|
8
8
|
import { type Any, Stream, type TaggedType } from '@dxos/codec-protobuf';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
-
import { SystemError } from '@dxos/protocols';
|
|
11
10
|
import { type TYPES } from '@dxos/protocols/proto';
|
|
12
11
|
|
|
13
12
|
import { RpcPeer } from './rpc';
|
|
@@ -266,7 +265,7 @@ describe('RpcPeer', () => {
|
|
|
266
265
|
error = err;
|
|
267
266
|
}
|
|
268
267
|
|
|
269
|
-
expect(error).toBeInstanceOf(
|
|
268
|
+
expect(error).toBeInstanceOf(Error);
|
|
270
269
|
expect(error.message).toEqual('My error');
|
|
271
270
|
expect(error.stack?.includes('handlerFn')).toEqual(true);
|
|
272
271
|
expect(error.stack?.includes('RpcMethodName')).toEqual(true);
|
package/src/rpc.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Trigger, asyncTimeout, synchronized } from '@dxos/async';
|
|
6
6
|
import { type Any, type ProtoCodec, type RequestOptions, Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { type Context, ContextRpcCodec } from '@dxos/context';
|
|
7
8
|
import { StackTrace } from '@dxos/debug';
|
|
8
9
|
import { invariant } from '@dxos/invariant';
|
|
9
10
|
import { log } from '@dxos/log';
|
|
@@ -14,7 +15,7 @@ import { exponentialBackoffInterval } from '@dxos/util';
|
|
|
14
15
|
|
|
15
16
|
import { decodeRpcError } from './errors';
|
|
16
17
|
|
|
17
|
-
const DEFAULT_TIMEOUT =
|
|
18
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
18
19
|
const BYE_SEND_TIMEOUT = 2_000;
|
|
19
20
|
|
|
20
21
|
const DEBUG_CALLS = true;
|
|
@@ -260,7 +261,7 @@ export class RpcPeer {
|
|
|
260
261
|
*/
|
|
261
262
|
private async _receive(msg: Uint8Array): Promise<void> {
|
|
262
263
|
const decoded = getRpcMessageCodec().decode(msg, { preserveAny: true });
|
|
263
|
-
DEBUG_CALLS && log('received message', { type: Object.keys(decoded)[0] });
|
|
264
|
+
DEBUG_CALLS && log.trace('received message', { type: Object.keys(decoded)[0] });
|
|
264
265
|
|
|
265
266
|
if (decoded.request) {
|
|
266
267
|
if (this._state !== RpcState.OPENED && this._state !== RpcState.OPENING) {
|
|
@@ -278,7 +279,7 @@ export class RpcPeer {
|
|
|
278
279
|
if (req.stream) {
|
|
279
280
|
log('stream request', { method: req.method });
|
|
280
281
|
this._callStreamHandler(req, (response) => {
|
|
281
|
-
log('sending stream response', {
|
|
282
|
+
log.trace('sending stream response', {
|
|
282
283
|
method: req.method,
|
|
283
284
|
response: response.payload?.type_url,
|
|
284
285
|
error: response.error,
|
|
@@ -290,10 +291,10 @@ export class RpcPeer {
|
|
|
290
291
|
});
|
|
291
292
|
});
|
|
292
293
|
} else {
|
|
293
|
-
DEBUG_CALLS && log('requesting...', { method: req.method });
|
|
294
|
+
DEBUG_CALLS && log.trace('requesting...', { method: req.method });
|
|
294
295
|
const response = await this._callHandler(req);
|
|
295
296
|
DEBUG_CALLS &&
|
|
296
|
-
log('sending response', {
|
|
297
|
+
log.trace('sending response', {
|
|
297
298
|
method: req.method,
|
|
298
299
|
response: response.payload?.type_url,
|
|
299
300
|
error: response.error,
|
|
@@ -309,7 +310,7 @@ export class RpcPeer {
|
|
|
309
310
|
const responseId = decoded.response.id;
|
|
310
311
|
invariant(typeof responseId === 'number');
|
|
311
312
|
if (!this._outgoingRequests.has(responseId)) {
|
|
312
|
-
log('received response with invalid id', { responseId });
|
|
313
|
+
log.trace('received response with invalid id', { responseId });
|
|
313
314
|
return; // Ignore requests with incorrect id.
|
|
314
315
|
}
|
|
315
316
|
|
|
@@ -319,7 +320,7 @@ export class RpcPeer {
|
|
|
319
320
|
this._outgoingRequests.delete(responseId);
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
DEBUG_CALLS && log('response', { type_url: decoded.response.payload?.type_url });
|
|
323
|
+
DEBUG_CALLS && log.trace('response', { type_url: decoded.response.payload?.type_url });
|
|
323
324
|
item.resolve(decoded.response);
|
|
324
325
|
} else if (decoded.open) {
|
|
325
326
|
log('received open message', { state: this._state });
|
|
@@ -374,7 +375,7 @@ export class RpcPeer {
|
|
|
374
375
|
* Peer should be open before making this call.
|
|
375
376
|
*/
|
|
376
377
|
async call(method: string, request: Any, options?: RequestOptions): Promise<Any> {
|
|
377
|
-
DEBUG_CALLS && log('calling...', { method });
|
|
378
|
+
DEBUG_CALLS && log.trace('calling...', { method });
|
|
378
379
|
throwIfNotOpen(this._state);
|
|
379
380
|
|
|
380
381
|
let response: Response;
|
|
@@ -385,6 +386,13 @@ export class RpcPeer {
|
|
|
385
386
|
this._outgoingRequests.set(id, new PendingRpcRequest(resolve, reject, false));
|
|
386
387
|
});
|
|
387
388
|
|
|
389
|
+
let traceContext;
|
|
390
|
+
try {
|
|
391
|
+
traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : undefined;
|
|
392
|
+
} catch (err) {
|
|
393
|
+
log.warn('failed to encode trace context', { err });
|
|
394
|
+
}
|
|
395
|
+
|
|
388
396
|
// Send request call.
|
|
389
397
|
const sending = this._sendMessage({
|
|
390
398
|
request: {
|
|
@@ -392,6 +400,7 @@ export class RpcPeer {
|
|
|
392
400
|
method,
|
|
393
401
|
payload: request,
|
|
394
402
|
stream: false,
|
|
403
|
+
...(traceContext ? { traceContext } : {}),
|
|
395
404
|
},
|
|
396
405
|
});
|
|
397
406
|
|
|
@@ -460,16 +469,30 @@ export class RpcPeer {
|
|
|
460
469
|
|
|
461
470
|
this._outgoingRequests.set(id, new PendingRpcRequest(onResponse, closeStream, true));
|
|
462
471
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
472
|
+
let traceContext;
|
|
473
|
+
try {
|
|
474
|
+
traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : undefined;
|
|
475
|
+
} catch (err) {
|
|
476
|
+
log.warn('failed to encode trace context', { err });
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
try {
|
|
480
|
+
this._sendMessage({
|
|
481
|
+
request: {
|
|
482
|
+
id,
|
|
483
|
+
method,
|
|
484
|
+
payload: request,
|
|
485
|
+
stream: true,
|
|
486
|
+
...(traceContext ? { traceContext } : {}),
|
|
487
|
+
},
|
|
488
|
+
}).catch((err) => {
|
|
489
|
+
this._outgoingRequests.delete(id);
|
|
490
|
+
close(err);
|
|
491
|
+
});
|
|
492
|
+
} catch (err) {
|
|
493
|
+
this._outgoingRequests.delete(id);
|
|
494
|
+
throw err;
|
|
495
|
+
}
|
|
473
496
|
|
|
474
497
|
return () => {
|
|
475
498
|
this._sendMessage({
|
|
@@ -483,17 +506,32 @@ export class RpcPeer {
|
|
|
483
506
|
}
|
|
484
507
|
|
|
485
508
|
private async _sendMessage(message: RpcMessage, timeout?: number): Promise<void> {
|
|
486
|
-
DEBUG_CALLS && log('sending message', { type: Object.keys(message)[0] });
|
|
509
|
+
DEBUG_CALLS && log.trace('sending message', { type: Object.keys(message)[0] });
|
|
487
510
|
await this._params.port.send(getRpcMessageCodec().encode(message, { preserveAny: true }), timeout);
|
|
488
511
|
}
|
|
489
512
|
|
|
513
|
+
private _getHandlerRpcOptions(req: Request): RequestOptions | undefined {
|
|
514
|
+
let traceCtx: Context | undefined;
|
|
515
|
+
if (req.traceContext) {
|
|
516
|
+
try {
|
|
517
|
+
traceCtx = ContextRpcCodec.decode(req.traceContext);
|
|
518
|
+
} catch (err) {
|
|
519
|
+
log.warn('failed to decode trace context', { traceContext: req.traceContext, err });
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (!traceCtx && !this._params.handlerRpcOptions) {
|
|
523
|
+
return undefined;
|
|
524
|
+
}
|
|
525
|
+
return { ...this._params.handlerRpcOptions, ...(traceCtx ? { ctx: traceCtx } : {}) };
|
|
526
|
+
}
|
|
527
|
+
|
|
490
528
|
private async _callHandler(req: Request): Promise<Response> {
|
|
491
529
|
try {
|
|
492
530
|
invariant(typeof req.id === 'number');
|
|
493
531
|
invariant(req.payload);
|
|
494
532
|
invariant(req.method);
|
|
495
533
|
|
|
496
|
-
const response = await this._params.callHandler(req.method, req.payload, this.
|
|
534
|
+
const response = await this._params.callHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
|
|
497
535
|
return {
|
|
498
536
|
id: req.id,
|
|
499
537
|
payload: response,
|
|
@@ -513,7 +551,7 @@ export class RpcPeer {
|
|
|
513
551
|
invariant(req.payload);
|
|
514
552
|
invariant(req.method);
|
|
515
553
|
|
|
516
|
-
const responseStream = this._params.streamHandler(req.method, req.payload, this.
|
|
554
|
+
const responseStream = this._params.streamHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
|
|
517
555
|
responseStream.onReady(() => {
|
|
518
556
|
callback({
|
|
519
557
|
id: req.id,
|
package/src/service.test.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import { beforeEach, describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { latch, sleep } from '@dxos/async';
|
|
8
|
-
import { Stream } from '@dxos/codec-protobuf
|
|
9
|
-
import {
|
|
8
|
+
import { type RequestOptions, Stream } from '@dxos/codec-protobuf';
|
|
9
|
+
import { Context, TRACE_SPAN_ATTRIBUTE } from '@dxos/context';
|
|
10
10
|
import { schema } from '@dxos/protocols/proto';
|
|
11
11
|
import {
|
|
12
12
|
type TestRpcResponse,
|
|
@@ -94,7 +94,7 @@ describe('Protobuf service', () => {
|
|
|
94
94
|
error = err;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
expect(error).toBeInstanceOf(
|
|
97
|
+
expect(error).toBeInstanceOf(Error);
|
|
98
98
|
expect(error.message).toEqual('TestError');
|
|
99
99
|
expect(error.stack?.includes('handlerFn')).toEqual(true);
|
|
100
100
|
expect(error.stack?.includes('TestCall')).toEqual(true);
|
|
@@ -585,4 +585,127 @@ describe('Protobuf service', () => {
|
|
|
585
585
|
);
|
|
586
586
|
await expect(promise).rejects.toThrow(/Timeout/);
|
|
587
587
|
});
|
|
588
|
+
|
|
589
|
+
test('W3C trace context propagates to handler options', async ({ expect }) => {
|
|
590
|
+
const traceContext = {
|
|
591
|
+
traceparent: '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01',
|
|
592
|
+
tracestate: 'vendorkey=vendorvalue',
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
const [alicePort, bobPort] = createLinkedPorts();
|
|
596
|
+
let receivedCtx: Context | undefined;
|
|
597
|
+
|
|
598
|
+
const server = createProtoRpcPeer({
|
|
599
|
+
exposed: {
|
|
600
|
+
TestService: schema.getService('example.testing.rpc.TestService'),
|
|
601
|
+
},
|
|
602
|
+
handlers: {
|
|
603
|
+
TestService: {
|
|
604
|
+
testCall: async (req: any, options?: RequestOptions) => {
|
|
605
|
+
receivedCtx = options?.ctx;
|
|
606
|
+
return { data: 'responseData' };
|
|
607
|
+
},
|
|
608
|
+
voidCall: async () => {},
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
port: alicePort,
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
const callerCtx = new Context({ attributes: { [TRACE_SPAN_ATTRIBUTE]: traceContext } });
|
|
615
|
+
|
|
616
|
+
const client = createProtoRpcPeer({
|
|
617
|
+
requested: {
|
|
618
|
+
TestService: schema.getService('example.testing.rpc.TestService'),
|
|
619
|
+
},
|
|
620
|
+
port: bobPort,
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
await Promise.all([server.open(), client.open()]);
|
|
624
|
+
|
|
625
|
+
await client.rpc.TestService.testCall({ data: 'requestData' }, { ctx: callerCtx });
|
|
626
|
+
|
|
627
|
+
expect(receivedCtx).toBeInstanceOf(Context);
|
|
628
|
+
const received = receivedCtx!.getAttribute(TRACE_SPAN_ATTRIBUTE);
|
|
629
|
+
expect(received.traceparent).toEqual(traceContext.traceparent);
|
|
630
|
+
expect(received.tracestate).toEqual(traceContext.tracestate);
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
test('handler receives no ctx when caller sends no trace context', async ({ expect }) => {
|
|
634
|
+
const [alicePort, bobPort] = createLinkedPorts();
|
|
635
|
+
let receivedOptions: RequestOptions | undefined;
|
|
636
|
+
|
|
637
|
+
const server = createProtoRpcPeer({
|
|
638
|
+
exposed: {
|
|
639
|
+
TestService: schema.getService('example.testing.rpc.TestService'),
|
|
640
|
+
},
|
|
641
|
+
handlers: {
|
|
642
|
+
TestService: {
|
|
643
|
+
testCall: async (req: any, options?: RequestOptions) => {
|
|
644
|
+
receivedOptions = options;
|
|
645
|
+
return { data: 'responseData' };
|
|
646
|
+
},
|
|
647
|
+
voidCall: async () => {},
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
port: alicePort,
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
const client = createProtoRpcPeer({
|
|
654
|
+
requested: {
|
|
655
|
+
TestService: schema.getService('example.testing.rpc.TestService'),
|
|
656
|
+
},
|
|
657
|
+
port: bobPort,
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
await Promise.all([server.open(), client.open()]);
|
|
661
|
+
|
|
662
|
+
await client.rpc.TestService.testCall({ data: 'requestData' });
|
|
663
|
+
|
|
664
|
+
expect(receivedOptions).toBeUndefined();
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
test('W3C trace context propagates on streaming RPC', async ({ expect }) => {
|
|
668
|
+
const traceContext = {
|
|
669
|
+
traceparent: '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01',
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
const [alicePort, bobPort] = createLinkedPorts();
|
|
673
|
+
let receivedCtx: Context | undefined;
|
|
674
|
+
|
|
675
|
+
const server = createProtoRpcPeer({
|
|
676
|
+
exposed: {
|
|
677
|
+
TestStreamService: schema.getService('example.testing.rpc.TestStreamService'),
|
|
678
|
+
},
|
|
679
|
+
handlers: {
|
|
680
|
+
TestStreamService: {
|
|
681
|
+
testCall: (_req: any, options?: RequestOptions) => {
|
|
682
|
+
receivedCtx = options?.ctx;
|
|
683
|
+
return new Stream<{ data: string }>(({ next, close }) => {
|
|
684
|
+
next({ data: 'streamData' });
|
|
685
|
+
close();
|
|
686
|
+
});
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
port: alicePort,
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
const callerCtx = new Context({ attributes: { [TRACE_SPAN_ATTRIBUTE]: traceContext } });
|
|
694
|
+
|
|
695
|
+
const client = createProtoRpcPeer({
|
|
696
|
+
requested: {
|
|
697
|
+
TestStreamService: schema.getService('example.testing.rpc.TestStreamService'),
|
|
698
|
+
},
|
|
699
|
+
port: bobPort,
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
await Promise.all([server.open(), client.open()]);
|
|
703
|
+
|
|
704
|
+
const stream = client.rpc.TestStreamService.testCall({ data: 'requestData' }, { ctx: callerCtx });
|
|
705
|
+
await Stream.consumeData(stream);
|
|
706
|
+
|
|
707
|
+
expect(receivedCtx).toBeInstanceOf(Context);
|
|
708
|
+
const received = receivedCtx!.getAttribute(TRACE_SPAN_ATTRIBUTE);
|
|
709
|
+
expect(received.traceparent).toEqual(traceContext.traceparent);
|
|
710
|
+
});
|
|
588
711
|
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/errors.ts", "../../../src/rpc.ts", "../../../src/service.ts", "../../../src/testing.ts", "../../../src/trace.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport { StackTrace } from '@dxos/debug';\nimport { decodeError } from '@dxos/protocols';\nimport { type Error as ErrorResponse } from '@dxos/protocols/proto/dxos/error';\n\nexport const decodeRpcError = (err: ErrorResponse, rpcMethod: string): Error =>\n decodeError(err, {\n appendStack: `\\n at RPC ${rpcMethod} \\n` + new StackTrace().getStack(1),\n });\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { Trigger, asyncTimeout, synchronized } from '@dxos/async';\nimport { type Any, type ProtoCodec, type RequestOptions, Stream } from '@dxos/codec-protobuf';\nimport { StackTrace } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { RpcClosedError, RpcNotOpenError, encodeError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Request, type Response, type RpcMessage } from '@dxos/protocols/proto/dxos/rpc';\nimport { exponentialBackoffInterval } from '@dxos/util';\n\nimport { decodeRpcError } from './errors';\n\nconst DEFAULT_TIMEOUT = 3_000;\nconst BYE_SEND_TIMEOUT = 2_000;\n\nconst DEBUG_CALLS = true;\n\ntype MaybePromise<T> = Promise<T> | T;\n\nexport interface RpcPeerOptions {\n port: RpcPort;\n\n /**\n * Time to wait for a response to an RPC call.\n */\n timeout?: number;\n\n callHandler: (method: string, request: Any, options?: RequestOptions) => MaybePromise<Any>;\n streamHandler?: (method: string, request: Any, options?: RequestOptions) => Stream<Any>;\n\n /**\n * Do not require or send handshake messages.\n */\n noHandshake?: boolean;\n\n /**\n * What options get passed to the `callHandler` and `streamHandler`.\n */\n handlerRpcOptions?: RequestOptions;\n}\n\n/**\n * Interface for a transport-agnostic port to send/receive binary messages.\n */\nexport interface RpcPort {\n send: (msg: Uint8Array, timeout?: number) => MaybePromise<void>;\n subscribe: (cb: (msg: Uint8Array) => void) => (() => void) | void;\n}\n\nconst CLOSE_TIMEOUT = 3_000;\n\nexport type CloseOptions = {\n /**\n * Time to wait for the other side to confirm close.\n */\n timeout?: number;\n};\n\nclass PendingRpcRequest {\n constructor(\n public readonly resolve: (response: Response) => void,\n public readonly reject: (error?: Error) => void,\n public readonly stream: boolean,\n ) {}\n}\n\n// NOTE: Lazy so that code that doesn't use indexing doesn't need to load the codec (breaks in workerd).\nlet RpcMessageCodec!: ProtoCodec<RpcMessage>;\nconst getRpcMessageCodec = () => (RpcMessageCodec ??= schema.getCodecForType('dxos.rpc.RpcMessage'));\n\nenum RpcState {\n INITIAL = 'INITIAL',\n\n OPENING = 'OPENING',\n\n OPENED = 'OPENED',\n\n /**\n * Bye message sent, waiting for the other side to close.\n * Not possible to send requests.\n * All pending requests will be rejected.\n */\n CLOSING = 'CLOSING',\n\n /**\n * Connection fully closed.\n * The underlying transport can be disposed.\n */\n CLOSED = 'CLOSED',\n}\n\n/**\n * A remote procedure call peer.\n *\n * Provides a away to make RPC calls and get a response back as a promise.\n * Does not handle encoding/decoding and only works with byte buffers.\n * For type safe approach see `createRpcClient` and `createRpcServer`.\n *\n * Must be connected with another instance on the other side via `send`/`receive` methods.\n * Both sides must be opened before making any RPC calls.\n *\n * Errors inside the handler get serialized and sent to the other side.\n *\n * Inspired by JSON-RPC 2.0 https://www.jsonrpc.org/specification.\n */\nexport class RpcPeer {\n private readonly _params: RpcPeerOptions;\n\n private readonly _outgoingRequests = new Map<number, PendingRpcRequest>();\n private readonly _localStreams = new Map<number, Stream<any>>();\n private readonly _remoteOpenTrigger = new Trigger();\n\n /**\n * Triggered when the peer starts closing.\n */\n private readonly _closingTrigger = new Trigger();\n\n /**\n * Triggered when peer receives a bye message.\n */\n private readonly _byeTrigger = new Trigger();\n\n private _nextId = 0;\n private _state: RpcState = RpcState.INITIAL;\n private _unsubscribeFromPort: (() => void) | undefined = undefined;\n private _clearOpenInterval: (() => void) | undefined = undefined;\n\n constructor(params: RpcPeerOptions) {\n this._params = {\n timeout: undefined,\n streamHandler: undefined,\n noHandshake: false,\n ...params,\n };\n }\n\n /**\n * Open the peer. Required before making any calls.\n *\n * Will block before the other peer calls `open`.\n */\n @synchronized\n async open(): Promise<void> {\n if (this._state !== RpcState.INITIAL) {\n return;\n }\n\n this._unsubscribeFromPort = this._params.port.subscribe(async (msg) => {\n try {\n await this._receive(msg);\n } catch (err: any) {\n log.catch(err);\n }\n }) as any;\n\n this._state = RpcState.OPENING;\n\n if (this._params.noHandshake) {\n this._state = RpcState.OPENED;\n this._remoteOpenTrigger.wake();\n return;\n }\n\n log('sending open message', { state: this._state });\n await this._sendMessage({ open: true });\n\n if (this._state !== RpcState.OPENING) {\n return;\n }\n\n // Retry sending.\n this._clearOpenInterval = exponentialBackoffInterval(() => {\n void this._sendMessage({ open: true }).catch((err) => log.warn(err));\n }, 50);\n\n await Promise.race([this._remoteOpenTrigger.wait(), this._closingTrigger.wait()]);\n\n this._clearOpenInterval?.();\n\n if ((this._state as RpcState) !== RpcState.OPENED) {\n // Closed while opening.\n return; // TODO(dmaretskyi): Throw error?\n }\n\n // TODO(burdon): This seems error prone.\n // Send an \"open\" message in case the other peer has missed our first \"open\" message and is still waiting.\n log('resending open message', { state: this._state });\n await this._sendMessage({ openAck: true });\n }\n\n /**\n * Close the peer.\n * Stop taking or making requests.\n * Will wait for confirmation from the other side.\n * Any responses for RPC calls made before close will be delivered.\n */\n async close({ timeout = CLOSE_TIMEOUT }: CloseOptions = {}): Promise<void> {\n if (this._state === RpcState.CLOSED) {\n return;\n }\n\n this._abortRequests();\n\n if (this._state === RpcState.OPENED && !this._params.noHandshake) {\n try {\n this._state = RpcState.CLOSING;\n await this._sendMessage({ bye: {} }, BYE_SEND_TIMEOUT);\n } catch (err: any) {\n log('error closing peer, sending bye', { err });\n }\n try {\n log('closing waiting on bye');\n await this._byeTrigger.wait({ timeout });\n } catch (err: any) {\n log('error closing peer', { err });\n return;\n }\n }\n\n this._disposeAndClose();\n }\n\n /**\n * Dispose the connection without waiting for the other side.\n */\n async abort(): Promise<void> {\n if (this._state === RpcState.CLOSED) {\n return;\n }\n\n this._abortRequests();\n this._disposeAndClose();\n }\n\n private _abortRequests(): void {\n // Abort open\n this._clearOpenInterval?.();\n this._closingTrigger.wake();\n\n // Abort pending requests\n for (const req of this._outgoingRequests.values()) {\n req.reject(new RpcClosedError());\n }\n this._outgoingRequests.clear();\n }\n\n private _disposeAndClose(): void {\n this._unsubscribeFromPort?.();\n this._unsubscribeFromPort = undefined;\n this._clearOpenInterval?.();\n this._state = RpcState.CLOSED;\n }\n\n /**\n * Handle incoming message. Should be called as the result of other peer's `send` callback.\n */\n private async _receive(msg: Uint8Array): Promise<void> {\n const decoded = getRpcMessageCodec().decode(msg, { preserveAny: true });\n DEBUG_CALLS && log('received message', { type: Object.keys(decoded)[0] });\n\n if (decoded.request) {\n if (this._state !== RpcState.OPENED && this._state !== RpcState.OPENING) {\n log('received request while closed');\n await this._sendMessage({\n response: {\n id: decoded.request.id,\n error: encodeError(new RpcClosedError()),\n },\n });\n return;\n }\n\n const req = decoded.request;\n if (req.stream) {\n log('stream request', { method: req.method });\n this._callStreamHandler(req, (response) => {\n log('sending stream response', {\n method: req.method,\n response: response.payload?.type_url,\n error: response.error,\n close: response.close,\n });\n\n void this._sendMessage({ response }).catch((err) => {\n log.warn('failed during close', err);\n });\n });\n } else {\n DEBUG_CALLS && log('requesting...', { method: req.method });\n const response = await this._callHandler(req);\n DEBUG_CALLS &&\n log('sending response', {\n method: req.method,\n response: response.payload?.type_url,\n error: response.error,\n });\n await this._sendMessage({ response });\n }\n } else if (decoded.response) {\n if (this._state !== RpcState.OPENED) {\n log('received response while closed');\n return; // Ignore when not open.\n }\n\n const responseId = decoded.response.id;\n invariant(typeof responseId === 'number');\n if (!this._outgoingRequests.has(responseId)) {\n log('received response with invalid id', { responseId });\n return; // Ignore requests with incorrect id.\n }\n\n const item = this._outgoingRequests.get(responseId)!;\n // Delete the request record if no more responses are expected.\n if (!item.stream) {\n this._outgoingRequests.delete(responseId);\n }\n\n DEBUG_CALLS && log('response', { type_url: decoded.response.payload?.type_url });\n item.resolve(decoded.response);\n } else if (decoded.open) {\n log('received open message', { state: this._state });\n if (this._params.noHandshake) {\n return;\n }\n\n await this._sendMessage({ openAck: true });\n } else if (decoded.openAck) {\n log('received openAck message', { state: this._state });\n if (this._params.noHandshake) {\n return;\n }\n\n this._state = RpcState.OPENED;\n this._remoteOpenTrigger.wake();\n } else if (decoded.streamClose) {\n if (this._state !== RpcState.OPENED) {\n log('received stream close while closed');\n return; // Ignore when not open.\n }\n\n log('received stream close', { id: decoded.streamClose.id });\n invariant(typeof decoded.streamClose.id === 'number');\n const stream = this._localStreams.get(decoded.streamClose.id);\n if (!stream) {\n log('no local stream', { id: decoded.streamClose.id });\n return; // Ignore requests with incorrect id.\n }\n\n this._localStreams.delete(decoded.streamClose.id);\n await stream.close();\n } else if (decoded.bye) {\n this._byeTrigger.wake();\n // If we haven't already started closing, close now.\n if (this._state !== RpcState.CLOSING && this._state !== RpcState.CLOSED) {\n log('replying to bye');\n this._state = RpcState.CLOSING;\n await this._sendMessage({ bye: {} });\n\n this._abortRequests();\n this._disposeAndClose();\n }\n } else {\n log.error('received malformed message', { msg });\n throw new Error('Malformed message.');\n }\n }\n\n /**\n * Make RPC call. Will trigger a handler on the other side.\n * Peer should be open before making this call.\n */\n async call(method: string, request: Any, options?: RequestOptions): Promise<Any> {\n DEBUG_CALLS && log('calling...', { method });\n throwIfNotOpen(this._state);\n\n let response: Response;\n try {\n // Set-up response listener.\n const id = this._nextId++;\n const responseReceived = new Promise<Response>((resolve, reject) => {\n this._outgoingRequests.set(id, new PendingRpcRequest(resolve, reject, false));\n });\n\n // Send request call.\n const sending = this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: false,\n },\n });\n\n // Wait until send completes or throws an error (or response throws a timeout), the resume waiting.\n const timeout = options?.timeout ?? this._params.timeout;\n const waiting =\n timeout === 0 ? responseReceived : asyncTimeout<any>(responseReceived, timeout ?? DEFAULT_TIMEOUT);\n\n await Promise.race([sending, waiting]);\n response = await waiting;\n invariant(response.id === id);\n } catch (err) {\n if (err instanceof RpcClosedError) {\n // Rethrow the error here to have the correct stack-trace.\n const error = new RpcClosedError();\n error.stack += `\\n\\n info: RPC client was closed at:\\n${err.stack?.split('\\n').slice(1).join('\\n')}`;\n throw error;\n }\n\n throw err;\n }\n\n if (response.payload) {\n return response.payload;\n } else if (response.error) {\n throw decodeRpcError(response.error, method);\n } else {\n throw new Error('Malformed response.');\n }\n }\n\n /**\n * Make RPC call with a streaming response.\n * Will trigger a handler on the other side.\n * Peer should be open before making this call.\n */\n callStream(method: string, request: Any, options?: RequestOptions): Stream<Any> {\n throwIfNotOpen(this._state);\n const id = this._nextId++;\n\n return new Stream(({ ready, next, close }) => {\n const onResponse = (response: Response) => {\n if (response.streamReady) {\n ready();\n } else if (response.close) {\n close();\n } else if (response.error) {\n // TODO(dmaretskyi): Stack trace might be lost because the stream producer function is called asynchronously.\n close(decodeRpcError(response.error, method));\n } else if (response.payload) {\n next(response.payload);\n } else {\n throw new Error('Malformed response.');\n }\n };\n\n const stack = new StackTrace();\n const closeStream = (err?: Error) => {\n if (!err) {\n close();\n } else {\n err.stack += `\\n\\nError happened in the stream at:\\n${stack.getStack()}`;\n close(err);\n }\n };\n\n this._outgoingRequests.set(id, new PendingRpcRequest(onResponse, closeStream, true));\n\n this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: true,\n },\n }).catch((err) => {\n close(err);\n });\n\n return () => {\n this._sendMessage({\n streamClose: { id },\n }).catch((err) => {\n log.catch(err);\n });\n this._outgoingRequests.delete(id);\n };\n });\n }\n\n private async _sendMessage(message: RpcMessage, timeout?: number): Promise<void> {\n DEBUG_CALLS && log('sending message', { type: Object.keys(message)[0] });\n await this._params.port.send(getRpcMessageCodec().encode(message, { preserveAny: true }), timeout);\n }\n\n private async _callHandler(req: Request): Promise<Response> {\n try {\n invariant(typeof req.id === 'number');\n invariant(req.payload);\n invariant(req.method);\n\n const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);\n return {\n id: req.id,\n payload: response,\n };\n } catch (err) {\n return {\n id: req.id,\n error: encodeError(err),\n };\n }\n }\n\n private _callStreamHandler(req: Request, callback: (response: Response) => void): void {\n try {\n invariant(this._params.streamHandler, 'Requests with streaming responses are not supported.');\n invariant(typeof req.id === 'number');\n invariant(req.payload);\n invariant(req.method);\n\n const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);\n responseStream.onReady(() => {\n callback({\n id: req.id,\n streamReady: true,\n });\n });\n\n responseStream.subscribe(\n (msg) => {\n callback({\n id: req.id,\n payload: msg,\n });\n },\n (error) => {\n if (error) {\n callback({\n id: req.id,\n error: encodeError(error),\n });\n } else {\n callback({\n id: req.id,\n close: true,\n });\n }\n },\n );\n\n this._localStreams.set(req.id, responseStream);\n } catch (err: any) {\n callback({\n id: req.id,\n error: encodeError(err),\n });\n }\n }\n}\n\nconst throwIfNotOpen = (state: RpcState) => {\n switch (state) {\n case RpcState.OPENED: {\n return;\n }\n case RpcState.INITIAL: {\n throw new RpcNotOpenError();\n }\n case RpcState.CLOSED: {\n throw new RpcClosedError();\n }\n }\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport {\n type EncodingOptions,\n type ServiceDescriptor,\n type ServiceHandler,\n type ServiceProvider,\n} from '@dxos/codec-protobuf';\nimport { invariant } from '@dxos/invariant';\n\nimport { RpcPeer, type RpcPeerOptions } from './rpc';\n\n/**\n * Map of service definitions.\n */\n// TODO(burdon): Rename ServiceMap.\nexport type ServiceBundle<Services> = { [Key in keyof Services]: ServiceDescriptor<Services[Key]> };\n\nexport type ServiceHandlers<Services> = { [ServiceName in keyof Services]: ServiceProvider<Services[ServiceName]> };\n\nexport type ServiceTypesOf<Bundle extends ServiceBundle<any>> =\n Bundle extends ServiceBundle<infer Services> ? Services : never;\n\n/**\n * Groups multiple services together to be served by a single RPC peer.\n */\nexport const createServiceBundle = <Service>(services: ServiceBundle<Service>): ServiceBundle<Service> => services;\n\n/**\n * Type-safe RPC peer.\n */\nexport class ProtoRpcPeer<Service> {\n constructor(\n public readonly rpc: Service,\n private readonly _peer: RpcPeer,\n ) {}\n\n async open(): Promise<void> {\n await this._peer.open();\n }\n\n async close(): Promise<void> {\n await this._peer.close();\n }\n\n async abort(): Promise<void> {\n await this._peer.abort();\n }\n}\n\nexport interface ProtoRpcPeerOptions<Client, Server> extends Omit<RpcPeerOptions, 'callHandler' | 'streamHandler'> {\n /**\n * Services that are expected to be implemented by the counter-space.\n */\n // TODO(burdon): Rename proxy.\n requested?: ServiceBundle<Client>;\n\n /**\n * Services exposed to the counter-space.\n */\n // TODO(burdon): Rename service.\n exposed?: ServiceBundle<Server>;\n\n /**\n * Handlers for the exposed services\n */\n handlers?: ServiceHandlers<Server>;\n\n /**\n * Encoding options passed to the underlying proto codec.\n */\n encodingOptions?: EncodingOptions;\n}\n\n/**\n * Create type-safe RPC peer from a service bundle.\n * Can both handle and issue requests.\n */\n// TODO(burdon): Currently assumes that the proto service name is unique.\n// Support multiple instances services definitions (e.g., halo/space invitations).\nexport const createProtoRpcPeer = <Client = {}, Server = {}>({\n requested,\n exposed,\n handlers,\n encodingOptions,\n ...rest\n}: ProtoRpcPeerOptions<Client, Server>): ProtoRpcPeer<Client> => {\n // Create map of RPCs.\n const exposedRpcs: Record<string, ServiceHandler<any>> = {};\n if (exposed) {\n invariant(handlers);\n for (const serviceName of Object.keys(exposed) as (keyof Server)[]) {\n // Get full service name with the package name without '.' at the beginning.\n const serviceFqn = exposed[serviceName].serviceProto.fullName.slice(1);\n const serviceProvider = handlers[serviceName];\n exposedRpcs[serviceFqn] = exposed[serviceName].createServer(serviceProvider, encodingOptions);\n }\n }\n\n // Create peer.\n const peer = new RpcPeer({\n ...rest,\n\n callHandler: (method, request, options) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!exposedRpcs[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return exposedRpcs[serviceName].call(methodName, request, options);\n },\n\n streamHandler: (method, request, options) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!exposedRpcs[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return exposedRpcs[serviceName].callStream(methodName, request, options);\n },\n });\n\n const requestedRpcs: Client = {} as Client;\n if (requested) {\n for (const serviceName of Object.keys(requested) as (keyof Client)[]) {\n // Get full service name with the package name without '.' at the beginning.\n const serviceFqn = requested[serviceName].serviceProto.fullName.slice(1);\n\n requestedRpcs[serviceName] = requested[serviceName].createClient(\n {\n call: (method, req, options) => peer.call(`${serviceFqn}.${method}`, req, options),\n callStream: (method, req, options) => peer.callStream(`${serviceFqn}.${method}`, req, options),\n },\n encodingOptions,\n );\n }\n }\n\n return new ProtoRpcPeer(requestedRpcs, peer);\n};\n\nexport const parseMethodName = (method: string): [serviceName: string, methodName: string] => {\n const separator = method.lastIndexOf('.');\n const serviceName = method.slice(0, separator);\n const methodName = method.slice(separator + 1);\n if (serviceName.length === 0 || methodName.length === 0) {\n throw new Error(`Invalid method: ${method}`);\n }\n\n return [serviceName, methodName];\n};\n\n//\n// TODO(burdon): Remove deprecated (only bot factory).\n//\n\n/**\n * Create a type-safe RPC client.\n * @deprecated Use createProtoRpcPeer instead.\n */\nexport const createRpcClient = <S>(\n serviceDef: ServiceDescriptor<S>,\n options: Omit<RpcPeerOptions, 'callHandler'>,\n): ProtoRpcPeer<S> => {\n const peer = new RpcPeer({\n ...options,\n callHandler: () => {\n throw new Error('Requests to client are not supported.');\n },\n });\n\n const client = serviceDef.createClient({\n call: peer.call.bind(peer),\n callStream: peer.callStream.bind(peer),\n });\n\n return new ProtoRpcPeer(client, peer);\n};\n\n/**\n * @deprecated\n */\nexport interface RpcServerOptions<S> extends Omit<RpcPeerOptions, 'callHandler'> {\n service: ServiceDescriptor<S>;\n handlers: S;\n}\n\n/**\n * Create a type-safe RPC server.\n * @deprecated Use createProtoRpcPeer instead.\n */\nexport const createRpcServer = <S>({ service, handlers, ...rest }: RpcServerOptions<S>): RpcPeer => {\n const server = service.createServer(handlers);\n return new RpcPeer({\n ...rest,\n callHandler: server.call.bind(server),\n streamHandler: server.callStream.bind(server),\n });\n};\n\n/**\n * Create type-safe RPC client from a service bundle.\n * @deprecated Use createProtoRpcPeer instead.\n */\nexport const createBundledRpcClient = <S>(\n descriptors: ServiceBundle<S>,\n options: Omit<RpcPeerOptions, 'callHandler' | 'streamHandler'>,\n): ProtoRpcPeer<S> => {\n return createProtoRpcPeer({\n requested: descriptors,\n ...options,\n });\n};\n\n/**\n * @deprecated\n */\nexport interface RpcBundledServerOptions<S> extends Omit<RpcPeerOptions, 'callHandler'> {\n services: ServiceBundle<S>;\n handlers: S;\n}\n\n/**\n * Create type-safe RPC server from a service bundle.\n * @deprecated Use createProtoRpcPeer instead.\n */\n// TODO(burdon): Support late-binding via providers.\nexport const createBundledRpcServer = <S>({ services, handlers, ...rest }: RpcBundledServerOptions<S>): RpcPeer => {\n const rpc: Record<string, ServiceHandler<any>> = {};\n for (const serviceName of Object.keys(services) as (keyof S)[]) {\n // Get full service name with the package name without '.' at the beginning.\n const serviceFqn = services[serviceName].serviceProto.fullName.slice(1);\n rpc[serviceFqn] = services[serviceName].createServer(handlers[serviceName] as any);\n }\n\n return new RpcPeer({\n ...rest,\n\n callHandler: (method, request) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!rpc[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return rpc[serviceName].call(methodName, request);\n },\n\n streamHandler: (method, request) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!rpc[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return rpc[serviceName].callStream(methodName, request);\n },\n });\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { isNode } from '@dxos/util';\n\nimport { type RpcPort } from './rpc';\n\nexport type CreateLinkedPortsOptions = {\n delay?: number;\n};\n\n/**\n * Create bi-directionally linked ports.\n */\nexport const createLinkedPorts = ({ delay }: CreateLinkedPortsOptions = {}): [RpcPort, RpcPort] => {\n let port1Received: RpcPort['send'] | undefined;\n let port2Received: RpcPort['send'] | undefined;\n\n const send = (handler: RpcPort['send'] | undefined, msg: Uint8Array) => {\n if (delay) {\n setTimeout(() => handler?.(msg), delay);\n } else {\n void handler?.(msg);\n }\n };\n\n const port1: RpcPort = {\n send: (msg) => send(port2Received, msg),\n subscribe: (cb) => {\n port1Received = cb;\n },\n };\n\n const port2: RpcPort = {\n send: (msg) => send(port1Received, msg),\n subscribe: (cb) => {\n port2Received = cb;\n },\n };\n\n return [port1, port2];\n};\n\nexport const encodeMessage = (msg: string): Uint8Array => (isNode() ? Buffer.from(msg) : new TextEncoder().encode(msg));\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { MessageTrace } from '@dxos/protocols/proto/dxos/rpc';\n\nimport { type RpcPort } from './rpc';\n\nexport class PortTracer {\n readonly message = new Event<MessageTrace>();\n\n private readonly _port: RpcPort;\n\n constructor(private readonly _wrappedPort: RpcPort) {\n this._port = {\n send: (msg: Uint8Array) => {\n this.message.emit({\n direction: MessageTrace.Direction.OUTGOING,\n data: msg,\n });\n\n return this._wrappedPort.send(msg);\n },\n subscribe: (cb: (msg: Uint8Array) => void) => {\n return this._wrappedPort.subscribe((msg) => {\n this.message.emit({\n direction: MessageTrace.Direction.INCOMING,\n data: msg,\n });\n cb(msg);\n });\n },\n };\n }\n\n public get port() {\n return this._port;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,kBAAkB;AAC3B,SAASC,mBAAmB;AAGrB,IAAMC,iBAAiB,CAACC,KAAoBC,cACjDC,YAAYF,KAAK;EACfG,aAAa;aAAgBF,SAAAA;IAAiB,IAAIG,WAAAA,EAAaC,SAAS,CAAA;AAC1E,CAAA;;;ACPF,SAASC,SAASC,cAAcC,oBAAoB;AACpD,SAAyDC,cAAc;AACvE,SAASC,cAAAA,mBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,gBAAgBC,iBAAiBC,mBAAmB;AAC7D,SAASC,cAAc;AAEvB,SAASC,kCAAkC;;;;;;;;AAI3C,IAAMC,kBAAkB;AACxB,IAAMC,mBAAmB;AAEzB,IAAMC,cAAc;AAkCpB,IAAMC,gBAAgB;AAStB,IAAMC,oBAAN,MAAMA;;;;EACJ,YACkBC,SACAC,QACAC,QAChB;SAHgBF,UAAAA;SACAC,SAAAA;SACAC,SAAAA;EACf;AACL;AAGA,IAAIC;AACJ,IAAMC,qBAAqB,MAAOD,oBAAoBE,OAAOC,gBA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,eAAeG,GAAAA;IACnCG,WAAW,CAACC,OAAAA;AACVR,sBAAgBQ;IAClB;EACF;AAEA,QAAMC,QAAiB;IACrBP,MAAM,CAACE,QAAQF,KAAKF,eAAeI,GAAAA;IACnCG,WAAW,CAACC,OAAAA;AACVP,sBAAgBO;IAClB;EACF;AAEA,SAAO;IAACF;IAAOG;;AACjB;AAEO,IAAMC,gBAAgB,CAACN,QAA6BO,OAAAA,IAAWC,OAAOC,KAAKT,GAAAA,IAAO,IAAIU,YAAAA,EAAcC,OAAOX,GAAAA;;;ACxClH,SAASY,aAAa;AACtB,SAASC,oBAAoB;AAItB,IAAMC,aAAN,MAAMA;;EACFC;EAEQC;EAEjB,YAA6BC,cAAuB;SAAvBA,eAAAA;SAJpBF,UAAU,IAAIG,MAAAA;AAKrB,SAAKF,QAAQ;MACXG,MAAM,CAACC,QAAAA;AACL,aAAKL,QAAQM,KAAK;UAChBC,WAAWC,aAAaC,UAAUC;UAClCC,MAAMN;QACR,CAAA;AAEA,eAAO,KAAKH,aAAaE,KAAKC,GAAAA;MAChC;MACAO,WAAW,CAACC,OAAAA;AACV,eAAO,KAAKX,aAAaU,UAAU,CAACP,QAAAA;AAClC,eAAKL,QAAQM,KAAK;YAChBC,WAAWC,aAAaC,UAAUK;YAClCH,MAAMN;UACR,CAAA;AACAQ,aAAGR,GAAAA;QACL,CAAA;MACF;IACF;EACF;EAEA,IAAWU,OAAO;AAChB,WAAO,KAAKd;EACd;AACF;",
|
|
6
|
-
"names": ["StackTrace", "decodeError", "decodeRpcError", "err", "rpcMethod", "decodeError", "appendStack", "StackTrace", "getStack", "Trigger", "asyncTimeout", "synchronized", "Stream", "StackTrace", "invariant", "log", "RpcClosedError", "RpcNotOpenError", "encodeError", "schema", "exponentialBackoffInterval", "DEFAULT_TIMEOUT", "BYE_SEND_TIMEOUT", "DEBUG_CALLS", "CLOSE_TIMEOUT", "PendingRpcRequest", "resolve", "reject", "stream", "RpcMessageCodec", "getRpcMessageCodec", "schema", "getCodecForType", "RpcPeer", "_params", "_outgoingRequests", "Map", "_localStreams", "_remoteOpenTrigger", "Trigger", "_closingTrigger", "_byeTrigger", "_nextId", "_state", "_unsubscribeFromPort", "undefined", "_clearOpenInterval", "params", "timeout", "streamHandler", "noHandshake", "open", "port", "subscribe", "msg", "_receive", "err", "log", "catch", "wake", "state", "_sendMessage", "exponentialBackoffInterval", "warn", "Promise", "race", "wait", "openAck", "close", "CLOSE_TIMEOUT", "_abortRequests", "bye", "BYE_SEND_TIMEOUT", "_disposeAndClose", "abort", "req", "values", "reject", "RpcClosedError", "clear", "decoded", "getRpcMessageCodec", "decode", "preserveAny", "DEBUG_CALLS", "type", "Object", "keys", "request", "response", "id", "error", "encodeError", "stream", "method", "_callStreamHandler", "payload", "type_url", "_callHandler", "responseId", "invariant", "has", "item", "get", "delete", "resolve", "streamClose", "Error", "call", "options", "throwIfNotOpen", "responseReceived", "set", "PendingRpcRequest", "sending", "waiting", "asyncTimeout", "DEFAULT_TIMEOUT", "stack", "split", "slice", "join", "decodeRpcError", "callStream", "Stream", "ready", "next", "onResponse", "streamReady", "StackTrace", "closeStream", "getStack", "message", "send", "encode", "callHandler", "handlerRpcOptions", "callback", "responseStream", "onReady", "RpcNotOpenError", "invariant", "createServiceBundle", "services", "ProtoRpcPeer", "rpc", "_peer", "open", "close", "abort", "createProtoRpcPeer", "requested", "exposed", "handlers", "encodingOptions", "rest", "exposedRpcs", "invariant", "serviceName", "Object", "keys", "serviceFqn", "serviceProto", "fullName", "slice", "serviceProvider", "createServer", "peer", "RpcPeer", "callHandler", "method", "request", "options", "methodName", "parseMethodName", "Error", "call", "streamHandler", "callStream", "requestedRpcs", "createClient", "req", "separator", "lastIndexOf", "length", "createRpcClient", "serviceDef", "client", "bind", "createRpcServer", "service", "server", "createBundledRpcClient", "descriptors", "createBundledRpcServer", "isNode", "createLinkedPorts", "delay", "port1Received", "port2Received", "send", "handler", "msg", "setTimeout", "port1", "subscribe", "cb", "port2", "encodeMessage", "isNode", "Buffer", "from", "TextEncoder", "encode", "Event", "MessageTrace", "PortTracer", "message", "_port", "_wrappedPort", "Event", "send", "msg", "emit", "direction", "MessageTrace", "Direction", "OUTGOING", "data", "subscribe", "cb", "INCOMING", "port"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"inputs":{"src/errors.ts":{"bytes":1469,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"src/rpc.ts":{"bytes":62498,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"},"src/service.ts":{"bytes":22364,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/rpc.ts","kind":"import-statement","original":"./rpc"}],"format":"esm"},"src/testing.ts":{"bytes":3557,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/trace.ts":{"bytes":3510,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/rpc","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":773,"imports":[{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/rpc.ts","kind":"import-statement","original":"./rpc"},{"path":"src/service.ts","kind":"import-statement","original":"./service"},{"path":"src/testing.ts","kind":"import-statement","original":"./testing"},{"path":"src/trace.ts","kind":"import-statement","original":"./trace"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":43643},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/rpc","kind":"import-statement","external":true}],"exports":["PortTracer","ProtoRpcPeer","RpcPeer","createBundledRpcClient","createBundledRpcServer","createLinkedPorts","createProtoRpcPeer","createRpcClient","createRpcServer","createServiceBundle","decodeRpcError","encodeMessage","parseMethodName"],"entryPoint":"src/index.ts","inputs":{"src/errors.ts":{"bytesInOutput":228},"src/index.ts":{"bytesInOutput":0},"src/rpc.ts":{"bytesInOutput":17843},"src/service.ts":{"bytesInOutput":4245},"src/testing.ts":{"bytesInOutput":655},"src/trace.ts":{"bytesInOutput":768}},"bytes":24157}}}
|