@dxos/rpc 0.6.12-staging.e11e696 → 0.6.12
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/lib/browser/index.mjs +0 -3
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +0 -4
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/testing.d.ts +0 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/rpc.test.ts +24 -26
- package/src/service.test.ts +11 -9
- package/src/testing.ts +0 -4
- package/dist/lib/node-esm/index.mjs +0 -925
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/testing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/testing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,OAAO,CAAC;AAErC,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAAe,wBAAwB,KAAQ,CAAC,OAAO,EAAE,OAAO,CA2B7F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/rpc",
|
|
3
|
-
"version": "0.6.12
|
|
3
|
+
"version": "0.6.12",
|
|
4
4
|
"description": "A lightweight, transport-agnostic RPC implementation",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"browser": "./dist/lib/browser/index.mjs",
|
|
12
12
|
"node": {
|
|
13
|
-
"
|
|
14
|
-
"default": "./dist/lib/node-esm/index.mjs"
|
|
13
|
+
"default": "./dist/lib/node/index.cjs"
|
|
15
14
|
},
|
|
16
15
|
"types": "./dist/types/src/index.d.ts"
|
|
17
16
|
}
|
|
@@ -25,14 +24,18 @@
|
|
|
25
24
|
"src"
|
|
26
25
|
],
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@dxos/async": "0.6.12
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/log": "0.6.12
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
27
|
+
"@dxos/async": "0.6.12",
|
|
28
|
+
"@dxos/debug": "0.6.12",
|
|
29
|
+
"@dxos/invariant": "0.6.12",
|
|
30
|
+
"@dxos/codec-protobuf": "0.6.12",
|
|
31
|
+
"@dxos/log": "0.6.12",
|
|
32
|
+
"@dxos/protocols": "0.6.12",
|
|
33
|
+
"@dxos/node-std": "0.6.12",
|
|
34
|
+
"@dxos/util": "0.6.12"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"earljs": "~0.1.10",
|
|
38
|
+
"typescript": "^5.5.4"
|
|
36
39
|
},
|
|
37
40
|
"publishConfig": {
|
|
38
41
|
"access": "public"
|
package/src/rpc.test.ts
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'earljs';
|
|
6
6
|
|
|
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
10
|
import { SystemError } from '@dxos/protocols';
|
|
11
11
|
import { type TYPES } from '@dxos/protocols/proto';
|
|
12
|
+
import { describe, test } from '@dxos/test';
|
|
12
13
|
|
|
13
14
|
import { RpcPeer } from './rpc';
|
|
14
|
-
import { createLinkedPorts
|
|
15
|
+
import { createLinkedPorts } from './testing';
|
|
15
16
|
|
|
16
17
|
const createPayload = (value = ''): TaggedType<TYPES, 'google.protobuf.Any'> => ({
|
|
17
18
|
'@type': 'google.protobuf.Any',
|
|
18
19
|
type_url: 'dxos.test',
|
|
19
|
-
value:
|
|
20
|
+
value: Buffer.from(value),
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
// TODO(dmaretskyi): Rename alice and bob to peer1 and peer2.
|
|
@@ -183,7 +184,7 @@ describe('RpcPeer', () => {
|
|
|
183
184
|
const alice = new RpcPeer({
|
|
184
185
|
callHandler: async (method, msg) => {
|
|
185
186
|
expect(method).toEqual('method');
|
|
186
|
-
expect(msg.value).toEqual(
|
|
187
|
+
expect(msg.value).toEqual(Buffer.from('request'));
|
|
187
188
|
return createPayload('response');
|
|
188
189
|
},
|
|
189
190
|
port: alicePort,
|
|
@@ -201,7 +202,7 @@ describe('RpcPeer', () => {
|
|
|
201
202
|
await Promise.all([alice.close(), bob.close()]);
|
|
202
203
|
});
|
|
203
204
|
|
|
204
|
-
test
|
|
205
|
+
test('can send multiple requests', async () => {
|
|
205
206
|
const [alicePort, bobPort] = createLinkedPorts();
|
|
206
207
|
|
|
207
208
|
const alice: RpcPeer = new RpcPeer({
|
|
@@ -226,7 +227,7 @@ describe('RpcPeer', () => {
|
|
|
226
227
|
|
|
227
228
|
await Promise.all([alice.open(), bob.open()]);
|
|
228
229
|
|
|
229
|
-
expect((await bob.call('method', createPayload('request'))).value).toEqual(
|
|
230
|
+
expect((await bob.call('method', createPayload('request'))).value).toEqual(Buffer.from('request'));
|
|
230
231
|
|
|
231
232
|
const parallel1 = bob.call('method', createPayload('p1'));
|
|
232
233
|
const parallel2 = bob.call('method', createPayload('p2'));
|
|
@@ -234,8 +235,8 @@ describe('RpcPeer', () => {
|
|
|
234
235
|
|
|
235
236
|
await expect(await parallel1).toEqual(createPayload('p1'));
|
|
236
237
|
await expect(await parallel2).toEqual(createPayload('p2'));
|
|
237
|
-
await expect(error).
|
|
238
|
-
});
|
|
238
|
+
await expect(error).toBeRejected();
|
|
239
|
+
}).tag('flaky');
|
|
239
240
|
|
|
240
241
|
test('errors get serialized', async () => {
|
|
241
242
|
const [alicePort, bobPort] = createLinkedPorts();
|
|
@@ -266,7 +267,7 @@ describe('RpcPeer', () => {
|
|
|
266
267
|
error = err;
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
expect(error).
|
|
270
|
+
expect(error).toBeA(SystemError);
|
|
270
271
|
expect(error.message).toEqual('My error');
|
|
271
272
|
expect(error.stack?.includes('handlerFn')).toEqual(true);
|
|
272
273
|
expect(error.stack?.includes('RpcMethodName')).toEqual(true);
|
|
@@ -294,7 +295,7 @@ describe('RpcPeer', () => {
|
|
|
294
295
|
const req = bob.call('method', createPayload('request'));
|
|
295
296
|
await bob.close();
|
|
296
297
|
|
|
297
|
-
await expect(req).
|
|
298
|
+
await expect(req).toBeRejected();
|
|
298
299
|
});
|
|
299
300
|
|
|
300
301
|
test('closing remote endpoint stops pending requests on timeout', async () => {
|
|
@@ -320,7 +321,7 @@ describe('RpcPeer', () => {
|
|
|
320
321
|
await alice.close();
|
|
321
322
|
const req = bob.call('method', createPayload('request'));
|
|
322
323
|
|
|
323
|
-
await expect(req).
|
|
324
|
+
await expect(req).toBeRejected();
|
|
324
325
|
});
|
|
325
326
|
|
|
326
327
|
test('requests failing on timeout', async () => {
|
|
@@ -344,7 +345,7 @@ describe('RpcPeer', () => {
|
|
|
344
345
|
await Promise.all([alice.open(), bob.open()]);
|
|
345
346
|
|
|
346
347
|
const req = bob.call('method', createPayload('request'));
|
|
347
|
-
await expect(req).
|
|
348
|
+
await expect(req).toBeRejected();
|
|
348
349
|
});
|
|
349
350
|
});
|
|
350
351
|
|
|
@@ -356,7 +357,7 @@ describe('RpcPeer', () => {
|
|
|
356
357
|
callHandler: async (msg) => createPayload(),
|
|
357
358
|
streamHandler: (method, msg) => {
|
|
358
359
|
expect(method).toEqual('method');
|
|
359
|
-
expect(msg.value!).toEqual(
|
|
360
|
+
expect(msg.value!).toEqual(Buffer.from('request'));
|
|
360
361
|
return new Stream<Any>(({ next, close }) => {
|
|
361
362
|
next(createPayload('res1'));
|
|
362
363
|
next(createPayload('res2'));
|
|
@@ -374,7 +375,7 @@ describe('RpcPeer', () => {
|
|
|
374
375
|
await Promise.all([alice.open(), bob.open()]);
|
|
375
376
|
|
|
376
377
|
const stream = await bob.callStream('method', createPayload('request'));
|
|
377
|
-
expect(stream).
|
|
378
|
+
expect(stream).toBeA(Stream);
|
|
378
379
|
|
|
379
380
|
expect(await Stream.consume(stream)).toEqual([
|
|
380
381
|
{ ready: true },
|
|
@@ -391,7 +392,7 @@ describe('RpcPeer', () => {
|
|
|
391
392
|
callHandler: async (msg) => createPayload(),
|
|
392
393
|
streamHandler: (method, msg) => {
|
|
393
394
|
expect(method).toEqual('method');
|
|
394
|
-
expect(msg.value).toEqual(
|
|
395
|
+
expect(msg.value).toEqual(Buffer.from('request'));
|
|
395
396
|
return new Stream<Any>(({ next, close }) => {
|
|
396
397
|
close(new Error('Test error'));
|
|
397
398
|
});
|
|
@@ -407,12 +408,11 @@ describe('RpcPeer', () => {
|
|
|
407
408
|
await Promise.all([alice.open(), bob.open()]);
|
|
408
409
|
|
|
409
410
|
const stream = await bob.callStream('method', createPayload('request'));
|
|
410
|
-
expect(stream).
|
|
411
|
+
expect(stream).toBeA(Stream);
|
|
411
412
|
|
|
412
413
|
const msgs = await Stream.consume(stream);
|
|
413
|
-
expect(msgs
|
|
414
|
-
|
|
415
|
-
expect((msgs[0] as any).error).toBeInstanceOf(Error);
|
|
414
|
+
expect(msgs).toEqual([{ closed: true, error: expect.a(Error) }]);
|
|
415
|
+
|
|
416
416
|
expect((msgs[0] as any).error.message).toEqual('Test error');
|
|
417
417
|
});
|
|
418
418
|
|
|
@@ -451,7 +451,7 @@ describe('RpcPeer', () => {
|
|
|
451
451
|
callHandler: async (msg) => createPayload(),
|
|
452
452
|
streamHandler: (method, msg) => {
|
|
453
453
|
expect(method).toEqual('method');
|
|
454
|
-
expect(msg.value!).toEqual(
|
|
454
|
+
expect(msg.value!).toEqual(Buffer.from('request'));
|
|
455
455
|
return new Stream<Any>(({ ready, close }) => {
|
|
456
456
|
ready();
|
|
457
457
|
close();
|
|
@@ -468,7 +468,7 @@ describe('RpcPeer', () => {
|
|
|
468
468
|
await Promise.all([alice.open(), bob.open()]);
|
|
469
469
|
|
|
470
470
|
const stream = await bob.callStream('method', createPayload('request'));
|
|
471
|
-
expect(stream).
|
|
471
|
+
expect(stream).toBeA(Stream);
|
|
472
472
|
|
|
473
473
|
await stream.waitUntilReady();
|
|
474
474
|
|
|
@@ -494,12 +494,10 @@ describe('RpcPeer', () => {
|
|
|
494
494
|
await Promise.all([alice.open(), bob.open()]);
|
|
495
495
|
|
|
496
496
|
const stream = await bob.callStream('method', createPayload('request'));
|
|
497
|
-
expect(stream).
|
|
497
|
+
expect(stream).toBeA(Stream);
|
|
498
498
|
|
|
499
499
|
const msgs = await Stream.consume(stream);
|
|
500
|
-
expect(msgs
|
|
501
|
-
expect((msgs[0] as any).closed).toEqual(true);
|
|
502
|
-
expect((msgs[0] as any).error).toBeInstanceOf(Error);
|
|
500
|
+
expect(msgs).toEqual([{ closed: true, error: expect.a(Error) }]);
|
|
503
501
|
expect((msgs[0] as any).error.message).toEqual('Test error');
|
|
504
502
|
});
|
|
505
503
|
});
|
|
@@ -523,7 +521,7 @@ describe('RpcPeer', () => {
|
|
|
523
521
|
const alice = new RpcPeer({
|
|
524
522
|
callHandler: async (method, msg) => {
|
|
525
523
|
expect(method).toEqual('method');
|
|
526
|
-
expect(msg.value).toEqual(
|
|
524
|
+
expect(msg.value).toEqual(Buffer.from('request'));
|
|
527
525
|
return createPayload('response');
|
|
528
526
|
},
|
|
529
527
|
port: alicePort,
|
package/src/service.test.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'earljs';
|
|
6
|
+
import expectJest from 'expect';
|
|
6
7
|
|
|
7
8
|
import { sleep, latch } from '@dxos/async';
|
|
8
9
|
import { Stream } from '@dxos/codec-protobuf';
|
|
@@ -13,9 +14,10 @@ import {
|
|
|
13
14
|
type TestRpcResponse,
|
|
14
15
|
type TestService,
|
|
15
16
|
} from '@dxos/protocols/proto/example/testing/rpc';
|
|
17
|
+
import { describe, test } from '@dxos/test';
|
|
16
18
|
|
|
17
19
|
import { createProtoRpcPeer, type ProtoRpcPeer, createServiceBundle } from './service';
|
|
18
|
-
import { createLinkedPorts
|
|
20
|
+
import { createLinkedPorts } from './testing';
|
|
19
21
|
|
|
20
22
|
// TODO(dmaretskyi): Rename alice and bob to peer1 and peer2.
|
|
21
23
|
|
|
@@ -94,7 +96,7 @@ describe('Protobuf service', () => {
|
|
|
94
96
|
error = err;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
expect(error).
|
|
99
|
+
expect(error).toBeA(SystemError);
|
|
98
100
|
expect(error.message).toEqual('TestError');
|
|
99
101
|
expect(error.stack?.includes('handlerFn')).toEqual(true);
|
|
100
102
|
expect(error.stack?.includes('TestCall')).toEqual(true);
|
|
@@ -447,7 +449,7 @@ describe('Protobuf service', () => {
|
|
|
447
449
|
const stream = await client.rpc.TestStreamService.testCall({
|
|
448
450
|
data: 'requestData',
|
|
449
451
|
});
|
|
450
|
-
expect(await Stream.consume(stream)).toEqual([expect.
|
|
452
|
+
expect(await Stream.consume(stream)).toEqual([expect.objectWith({ closed: true })]);
|
|
451
453
|
});
|
|
452
454
|
});
|
|
453
455
|
|
|
@@ -508,11 +510,11 @@ describe('Protobuf service', () => {
|
|
|
508
510
|
testCall: async (req) => {
|
|
509
511
|
expect(req.payload['@type']).toEqual('google.protobuf.Any');
|
|
510
512
|
expect(req.payload.type_url).toEqual('example.testing.Example');
|
|
511
|
-
expect(req.payload.value).toEqual(
|
|
513
|
+
expect(req.payload.value).toEqual(Buffer.from('hello'));
|
|
512
514
|
return {
|
|
513
515
|
payload: {
|
|
514
516
|
type_url: 'example.testing.Example',
|
|
515
|
-
value:
|
|
517
|
+
value: Buffer.from('world'),
|
|
516
518
|
},
|
|
517
519
|
};
|
|
518
520
|
},
|
|
@@ -539,12 +541,12 @@ describe('Protobuf service', () => {
|
|
|
539
541
|
const response = await client.rpc.TestAnyService.testCall({
|
|
540
542
|
payload: {
|
|
541
543
|
type_url: 'example.testing.Example',
|
|
542
|
-
value:
|
|
544
|
+
value: Buffer.from('hello'),
|
|
543
545
|
},
|
|
544
546
|
});
|
|
545
547
|
|
|
546
548
|
expect(response.payload.type_url).toEqual('example.testing.Example');
|
|
547
|
-
expect(response.payload.value).toEqual(
|
|
549
|
+
expect(response.payload.value).toEqual(Buffer.from('world'));
|
|
548
550
|
});
|
|
549
551
|
});
|
|
550
552
|
|
|
@@ -583,6 +585,6 @@ describe('Protobuf service', () => {
|
|
|
583
585
|
},
|
|
584
586
|
{ timeout: 1 },
|
|
585
587
|
);
|
|
586
|
-
await
|
|
588
|
+
await expectJest(promise).rejects.toThrow(/Timeout/);
|
|
587
589
|
});
|
|
588
590
|
});
|
package/src/testing.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { isNode } from '@dxos/util';
|
|
6
|
-
|
|
7
5
|
import { type RpcPort } from './rpc';
|
|
8
6
|
|
|
9
7
|
export type CreateLinkedPortsOptions = {
|
|
@@ -41,5 +39,3 @@ export const createLinkedPorts = ({ delay }: CreateLinkedPortsOptions = {}): [Rp
|
|
|
41
39
|
|
|
42
40
|
return [port1, port2];
|
|
43
41
|
};
|
|
44
|
-
|
|
45
|
-
export const encodeMessage = (msg: string): Uint8Array => (isNode() ? Buffer.from(msg) : new TextEncoder().encode(msg));
|