@trenskow/rpc 0.1.0 → 0.1.2

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.
@@ -0,0 +1,16 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type":"node",
9
+ "request":"launch",
10
+ "name":"Run tests",
11
+ "runtimeExecutable":"_mocha",
12
+ "cwd":"${workspaceFolder}",
13
+ "args":[]
14
+ }
15
+ ]
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/rpc",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A simple RPC server and client for JavaScript.",
5
5
  "keywords": [
6
6
  "rpc",
@@ -20,13 +20,16 @@
20
20
  "main": "index.js",
21
21
  "types": "index.d.ts",
22
22
  "scripts": {
23
- "test": "echo \"Error: no test specified\" && exit 1"
23
+ "test": "node ./node_modules/mocha/bin/mocha.js ./test/index.js"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@eslint/eslintrc": "^3.3.3",
27
27
  "@eslint/js": "^9.39.2",
28
+ "chai": "^6.2.1",
29
+ "chai-as-promised": "^8.0.2",
28
30
  "eslint": "^9.39.2",
29
- "globals": "^16.5.0"
31
+ "globals": "^16.5.0",
32
+ "mocha": "^11.7.5"
30
33
  },
31
34
  "dependencies": {
32
35
  "@trenskow/json-compressor": "^0.1.2"
package/test/index.js ADDED
@@ -0,0 +1,76 @@
1
+ //
2
+ // index.js
3
+ // 0-bit-games-frontend-vscode
4
+ //
5
+ // Created by Kristian Trenskow on 2025/12/21
6
+ // See license in LICENSE.
7
+ //
8
+
9
+ import { EventEmitter } from 'events';
10
+
11
+ import { use as chaiUse, expect } from 'chai';
12
+ import chaiAsPromised from 'chai-as-promised';
13
+
14
+ import rpc from '../lib/index.js';
15
+
16
+ class Transport extends EventEmitter {
17
+
18
+ constructor() {
19
+ super();
20
+ this._transports = [];
21
+ }
22
+
23
+ addTransport(transport) {
24
+ this._transports.push(transport);
25
+ }
26
+
27
+ send(command, data) {
28
+ for (const transport of this._transports) {
29
+ transport.emit('message', {
30
+ command,
31
+ data
32
+ });
33
+ }
34
+ }
35
+
36
+ };
37
+
38
+ chaiUse(chaiAsPromised);
39
+
40
+ const serverTransport = new Transport();
41
+ const clientTransport = new Transport();
42
+
43
+ serverTransport.addTransport(clientTransport);
44
+ clientTransport.addTransport(serverTransport);
45
+
46
+ const server = rpc.serve({
47
+ async add(a, b) {
48
+ return a + b;
49
+ }
50
+ }, (command, data) => {
51
+ serverTransport.send(command, data);
52
+ });
53
+
54
+ const client = rpc.connect((command, data) => {
55
+ clientTransport.send(command, data);
56
+ });
57
+
58
+ serverTransport.on('message', ({ command, data }) => {
59
+ server.onMessage(command, ...data);
60
+ });
61
+
62
+ clientTransport.on('message', ({ command, data }) => {
63
+ client.onMessage(command, data);
64
+ });
65
+
66
+ describe('RPC', () => {
67
+
68
+ describe('Basic Functionality', () => {
69
+
70
+ it('should perform a basic RPC call', () => {
71
+ return expect(client.remote.add(2, 3)).to.eventually.equal(5);
72
+ });
73
+
74
+ });
75
+
76
+ });