rpc-express-toolkit 4.3.5 → 4.4.0

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/README.md CHANGED
@@ -6,21 +6,34 @@
6
6
  [![npm version](https://img.shields.io/npm/v/rpc-express-toolkit.svg)](https://www.npmjs.com/package/rpc-express-toolkit)
7
7
  [![npm downloads](https://img.shields.io/npm/dm/rpc-express-toolkit.svg)](https://www.npmjs.com/package/rpc-express-toolkit)
8
8
  [![node](https://img.shields.io/node/v/rpc-express-toolkit.svg)](https://www.npmjs.com/package/rpc-express-toolkit)
9
+ [![Status](https://img.shields.io/badge/status-stable-green.svg)](https://github.com/n-car/rpc-express-toolkit/releases)
9
10
 
10
11
  JSON-RPC 2.0 toolkit for Express.js with simplified APIs, middleware, schema validation, batch support, and optional Safe Mode type preservation.
11
12
 
13
+ ## Which Package Should I Use?
14
+
15
+ - Use `rpc-express-toolkit` if you are building a JSON-RPC endpoint on Express.
16
+ - Use [`rpc-node-toolkit`](https://github.com/n-car/rpc-node-toolkit) if you want framework-agnostic Node.js or plain `node:http`.
17
+ - Use [`rpc-toolkit-js-client`](https://github.com/n-car/rpc-toolkit-js-client) if you only need a browser or Node.js client.
18
+ - Use [`rpc-toolkit`](https://github.com/n-car/rpc-toolkit) as the ecosystem hub and compatibility reference.
19
+
12
20
  ## Quick Start
13
21
 
14
22
  ### Installation
15
23
 
16
24
  ```bash
17
- npm install rpc-express-toolkit
25
+ npm install express rpc-express-toolkit
18
26
  # or
19
- yarn add rpc-express-toolkit
27
+ yarn add express rpc-express-toolkit
20
28
  ```
21
29
 
22
30
  Requirements:
23
31
  - Node.js 18+ (uses `globalThis.fetch`)
32
+ - Express 4.21+ or Express 5.x
33
+
34
+ ### Compatibility
35
+
36
+ `rpc-express-toolkit` is tested with Node.js 18, 20, 22, and 24 across Express 4 and Express 5. See [Compatibility](docs/COMPATIBILITY.md) for the current runtime matrix.
24
37
 
25
38
  ### Server
26
39
 
@@ -142,7 +155,7 @@ Calls to methods outside the whitelist are rejected. This is a basic method rest
142
155
  [![npm (proxy)](https://img.shields.io/npm/v/rpc-express-toolkit-safe.svg)](https://www.npmjs.com/package/rpc-express-toolkit-safe)
143
156
  [![safe preset](https://img.shields.io/badge/safe%20preset-available-blue)](#safe-import-opt-in)
144
157
 
145
- When you control both client and server and want safer type round-trips, import the safe preset. It enables safe serialization by default (and strict mode on the server):
158
+ When you control both client and server and want safer type round-trips, import the built-in safe preset from `rpc-express-toolkit/safe`. It enables safe serialization by default and strict mode on the server:
146
159
 
147
160
  ```js
148
161
  // Server (safe preset)
@@ -161,9 +174,9 @@ const client = new RpcSafeClient('http://localhost:3000/api');
161
174
 
162
175
  This keeps JSON-RPC 2.0 compliance as default for the main entrypoint, while offering a convenient safe-mode import for projects that prefer explicit type disambiguation.
163
176
 
164
- Alternative: npm proxy package
177
+ #### Alternative Compatibility Package
165
178
 
166
- If you prefer a dedicated package name, you can install the thin proxy `rpc-express-toolkit-safe` which simply re-exports the safe preset:
179
+ `rpc-express-toolkit-safe` is a thin compatibility package that re-exports the same safe preset. Use it only when a separate package name is useful for dependency policy or migration; new projects can import `rpc-express-toolkit/safe` directly.
167
180
 
168
181
  ```bash
169
182
  npm install rpc-express-toolkit-safe
@@ -227,7 +240,7 @@ In `__rpc.capabilities`, `auth` is a boolean indicating whether authentication m
227
240
 
228
241
  For advanced configuration, middleware, structured logging, safe serialization, error handling, and more, see `README_ADVANCED.md`.
229
242
 
230
- ## 🔗 Related Projects
243
+ ## Related Projects
231
244
 
232
245
  - [rpc-php-toolkit](https://github.com/n-car/rpc-php-toolkit) - PHP implementation
233
246
  - [rpc-dotnet-toolkit](https://github.com/n-car/rpc-dotnet-toolkit) - .NET implementation
@@ -0,0 +1,37 @@
1
+ # Compatibility
2
+
3
+ `rpc-express-toolkit` is tested as an Express integration library, not as an application framework replacement.
4
+
5
+ ## Runtime Matrix
6
+
7
+ | Runtime | Status |
8
+ | --- | --- |
9
+ | Node.js 18.x | CI tested |
10
+ | Node.js 20.x | CI tested |
11
+ | Node.js 22.x | CI tested |
12
+ | Node.js 24.x | CI tested |
13
+ | Express 4.x | CI tested |
14
+ | Express 5.x | CI tested |
15
+
16
+ The GitHub Actions matrix runs the test suite across Node.js 18, 20, 22, and 24 with both Express 4 and Express 5.
17
+
18
+ ## Express Dependency
19
+
20
+ Express is declared as a peer dependency:
21
+
22
+ ```json
23
+ "express": "^4.21.2 || ^5.0.0"
24
+ ```
25
+
26
+ Applications should install Express directly alongside `rpc-express-toolkit`.
27
+
28
+ ## Compatibility Coverage
29
+
30
+ The Express compatibility tests cover:
31
+
32
+ - standard JSON-RPC endpoint calls;
33
+ - batch requests;
34
+ - Safe Mode endpoints;
35
+ - introspection reporting of the active Express runtime.
36
+
37
+ Broader RPC behavior is covered by the main test suite and is expected to run identically on Express 4 and Express 5.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpc-express-toolkit",
3
- "version": "4.3.5",
3
+ "version": "4.4.0",
4
4
  "description": "JSON-RPC 2.0 toolkit for Express.js with simplified APIs, structured logging, middleware, schema validation, batch support, and optional Safe Mode.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "files": [
20
20
  "src/",
21
21
  "examples/",
22
+ "docs/COMPATIBILITY.md",
22
23
  "README.md",
23
24
  "LICENSE"
24
25
  ],
@@ -66,7 +67,7 @@
66
67
  "rate-limit",
67
68
  "authentication"
68
69
  ],
69
- "author": "Nicola Carpanese \u003cnicola.carpanese@gmail.com\u003e",
70
+ "author": "Nicola Carpanese (https://github.com/n-car)",
70
71
  "license": "MIT",
71
72
  "bugs": {
72
73
  "url": "https://github.com/n-car/rpc-express-toolkit/issues"
@@ -81,6 +82,7 @@
81
82
  "eslint-config-prettier": "^9.1.2",
82
83
  "eslint-plugin-import": "^2.31.0",
83
84
  "eslint-plugin-prettier": "^5.5.3",
85
+ "express": "^4.21.2 || ^5.0.0",
84
86
  "husky": "^8.0.0",
85
87
  "jest": "^29.7.0",
86
88
  "lint-staged": "^13.0.0",
@@ -88,10 +90,12 @@
88
90
  "supertest": "^6.3.3",
89
91
  "terser": "^5.43.1"
90
92
  },
93
+ "peerDependencies": {
94
+ "express": "^4.21.2 || ^5.0.0"
95
+ },
91
96
  "dependencies": {
92
97
  "ajv": "^8.12.0",
93
98
  "ajv-formats": "^2.1.1",
94
- "express": "^4.21.2",
95
99
  "nested-error-stacks": "^2.1.1",
96
100
  "rpc-toolkit-js-client": "^1.1.2"
97
101
  },
@@ -101,7 +105,6 @@
101
105
  "contributors": [
102
106
  {
103
107
  "name": "Nicola Carpanese",
104
- "email": "nicola.carpanese@gmail.com",
105
108
  "url": "https://github.com/n-car"
106
109
  }
107
110
  ],
package/src/index.js CHANGED
@@ -288,21 +288,23 @@ class RpcEndpoint {
288
288
  this.addMethod(
289
289
  `${this.#introspectionPrefix}.describeAll`,
290
290
  async (_req, _context, _params) => {
291
- const publicMethods = [];
291
+ const publicMethods = Object.entries(this.#methods)
292
+ .filter(([name]) => !name.startsWith(this.#introspectionPrefix))
293
+ .map(([name, methodConfig]) => {
294
+ const config =
295
+ typeof methodConfig === 'function' ? {} : methodConfig;
292
296
 
293
- for (const [name, methodConfig] of Object.entries(this.#methods)) {
294
- // Skip introspection methods
295
- if (name.startsWith(this.#introspectionPrefix)) continue;
297
+ if (!config.exposeSchema) {
298
+ return null;
299
+ }
296
300
 
297
- const config = typeof methodConfig === 'function' ? {} : methodConfig;
298
- if (config.exposeSchema) {
299
- publicMethods.push({
301
+ return {
300
302
  name,
301
303
  schema: config.schema || null,
302
304
  description: config.description || '',
303
- });
304
- }
305
- }
305
+ };
306
+ })
307
+ .filter(Boolean);
306
308
 
307
309
  return publicMethods;
308
310
  },