@imqueue/rpc 3.3.0 → 3.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/AGENTS.md ADDED
@@ -0,0 +1,112 @@
1
+ # AGENTS.md — orientation for coding agents
2
+
3
+ This file is for AI coding agents (and humans who like density) working on
4
+ `@imqueue/rpc`. It captures how the codebase is built, tested and structured,
5
+ plus the invariants that are easy to get wrong. Read it before making changes.
6
+ For contribution *process/terms* see [CONTRIBUTING.md](./CONTRIBUTING.md); for
7
+ end-user docs see the [README](./README.md) and https://imqueue.org/.
8
+
9
+ ## What this is
10
+
11
+ `@imqueue/rpc` is the typed RPC layer of the @imqueue framework. It provides the
12
+ abstract base classes and decorators to build **self-describing services** and
13
+ the machinery to **generate strongly-typed clients** from them — all over the
14
+ Redis-backed message queue in [`@imqueue/core`](https://github.com/imqueue/core).
15
+ No service discovery, no load balancer, no hand-written HTTP layer: a service
16
+ describes itself and its client is generated from that description.
17
+
18
+ ## Toolchain & invariants (do not fight these)
19
+
20
+ - **ESM only**, `"type": "module"`. Use `import`, not `require()`. Import
21
+ sibling modules with the **`.js`** extension (NodeNext resolves it to the
22
+ `.ts` source).
23
+ - **TypeScript, `module`/`moduleResolution: nodenext`**, `target: es2024`,
24
+ `verbatimModuleSyntax: true`, `isolatedModules: true`, `strict: true`
25
+ (`strictPropertyInitialization: false`). Use `import type` for type-only
26
+ imports.
27
+ - **Standard (TC39) decorators** — `experimentalDecorators` is **false** and the
28
+ `esnext.decorators` lib is enabled. There is **no `emitDecoratorMetadata`**,
29
+ so there is **no runtime type reflection**.
30
+ - **Types are derived from JSDoc.** Because decorators carry no type metadata,
31
+ the RPC layer parses JSDoc `@param`/`@returns` tags (via `acorn`) to build a
32
+ service's description and its generated client's types. Consequences:
33
+ `removeComments` MUST stay **`false`**, and every exposed method MUST carry
34
+ accurate JSDoc — undocumented params fall back to `any` in generated clients.
35
+ - **Node ≥ 22.12.**
36
+ - Runtime deps: `@imqueue/core`, `acorn` (JSDoc/source parsing for client
37
+ generation), `typescript` (compiling generated clients on the fly).
38
+ - **Lint/format:** `oxlint` + `oxfmt`. Run `npm run format` before committing;
39
+ CI checks `npm run format:check`.
40
+ - Build **emits `.js`/`.d.ts`/`.js.map` next to sources**; **gitignored, not
41
+ committed**. `build` runs `build:deps` (builds `../core` if present) then
42
+ `clean-compiled` then `tsc`.
43
+
44
+ ## Commands
45
+
46
+ ```bash
47
+ npm install
48
+ npm run build # build ../core (if present) + clean + tsc
49
+ npm test # build + node:test over every test/**/*.spec.js
50
+ npm run lint # oxlint
51
+ npm run format # oxfmt (write) | npm run format:check (verify)
52
+ npm run test-coverage # tests + experimental coverage
53
+ ```
54
+
55
+ Tests use the native `node:test` runner with
56
+ `--experimental-test-module-mocks` and preload `./test/warmup.mjs`; timeout is
57
+ 15s. A local Redis on `localhost:6379` is expected for the integration-style
58
+ specs.
59
+
60
+ ## Layout
61
+
62
+ | Path | Role |
63
+ |---|---|
64
+ | `index.ts` | `export * from './src/index.js'` **and** `export * from '@imqueue/core'` — consumers get core's queue API re-exported. |
65
+ | `src/IMQService.ts` | `IMQService` abstract base — extend it and decorate methods with `@expose()`. |
66
+ | `src/IMQClient.ts` | `IMQClient` base + `IMQClient.create()` — generates/compiles/loads a client from a running service's description. |
67
+ | `src/decorators/expose.ts` | `@expose()` — marks a service method remotely callable. |
68
+ | `src/decorators/remote.ts` | `@remote()` — marks a hand-written client method. |
69
+ | `src/decorators/classType.ts`, `property.ts`, `indexed.ts` | Complex-type registration: `@classType()` on the class, `@property('type', optional?)` on fields. |
70
+ | `src/decorators/cache.ts`, `lock.ts`, `logged.ts`, `metadata.ts` | Cross-cutting method decorators. |
71
+ | `src/cache/` (`ICache`, `RedisCache`) | Caching layer for RPC results. |
72
+ | `src/helpers/signature.ts` | JSDoc/source signature extraction (acorn). |
73
+ | `src/IMQRPCDescription.ts`, `IMQRPCRequest.ts`, `IMQRPCResponse.ts`, `IMQRPCError.ts`, `IMQDelay.ts`, `IMQLock.ts`, `IMQMetadata.ts`, `IMQRequestContext.ts` | RPC wire types & context. |
74
+
75
+ ## Authoring rules (behavioural invariants that generated clients depend on)
76
+
77
+ - **Only `@expose()`-decorated methods are remotely callable.** Non-exposed
78
+ methods stay private to the service.
79
+ - **Arguments and return values must be JSON-serializable.**
80
+ - **No spread/rest params on exposed methods** — the generated client will not
81
+ compile. Pass an array instead: `foo(args: any[])`, not `foo(...args: any[])`.
82
+ - **Complex types need `@classType()` on the class** *and* `@property()` on each
83
+ field, or they will not appear in generated clients. `@indexed()` registers
84
+ `@property` fields too.
85
+ - **JSDoc is load-bearing**, not documentation-only (see toolchain note). Keep
86
+ `@param`/`@returns` types accurate.
87
+
88
+ ## Using this package correctly (for consumer-facing code an agent writes)
89
+
90
+ ```typescript
91
+ import { IMQService, expose } from '@imqueue/rpc';
92
+
93
+ export class UserService extends IMQService {
94
+ /**
95
+ * Returns a user by id
96
+ * @param {string} id - user identifier
97
+ * @return {Promise<{ id: string; name: string } | null>}
98
+ */
99
+ @expose()
100
+ public async get(id: string): Promise<{ id: string; name: string } | null> {
101
+ return { id, name: 'Jane Doe' };
102
+ }
103
+ }
104
+ ```
105
+
106
+ Generate the client with `@imqueue/cli` (`imq client generate UserService`) or
107
+ at runtime with `IMQClient.create('UserService')`, then
108
+ `const c = new UserServiceClient(); await c.start(); await c.get('42');`.
109
+
110
+ ## License
111
+
112
+ GPL-3.0. Commercial licensing for closed-source products: https://imqueue.com/.
package/CHANGELOG.md ADDED
@@ -0,0 +1,65 @@
1
+ # Changelog
2
+
3
+ Notable changes to `@imqueue/rpc`. Entries start at 3.3.1 — the first release
4
+ whose behavior changes needed a written record; earlier history is in the git
5
+ log.
6
+
7
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
+
9
+ ## [Unreleased]
10
+
11
+ ### Changed
12
+
13
+ - **On a delayed call, a trailing `undefined` is never delivered.** Every
14
+ trailing placeholder is now dropped, and the drop runs *after* both framework
15
+ slots have been stripped. 3.3.1 dropped exactly one, and did it before the
16
+ metadata slot was taken, so whether a placeholder reached the service depended
17
+ on whether metadata was also passed:
18
+
19
+ | call | 3.3.1 sends | now sends |
20
+ | --- | --- | --- |
21
+ | `m(a, undefined, undefined, delay)` | `[a, null]` | `[a]` |
22
+ | `m(a, undefined, metadata, delay)` | `[a, null]` | `[a]` |
23
+
24
+ A declared optional or defaulted parameter skipped this way therefore falls
25
+ back to its default instead of receiving `null`. If a handler persisted such a
26
+ parameter, it now writes the default rather than `null`.
27
+
28
+ Unchanged: calls without a delay never drop anything, declared arguments
29
+ holding real values are always delivered, and every shape 3.3.1 fixed keeps
30
+ working.
31
+
32
+ ## [3.3.1] - 2026-07-25
33
+
34
+ ### Fixed
35
+
36
+ - A delayed call no longer requires inventing a metadata bag.
37
+ `method(data, undefined, delay)` previously failed with
38
+ `IMQ_RPC_INVALID_ARGS_COUNT`, because the two trailing framework parameters are
39
+ stripped by identity rather than by position and the explicit `undefined`
40
+ travelled on as a real call argument. One trailing `undefined` is now dropped
41
+ once a delay has been popped.
42
+ - The client generator stripped only one framework parameter that a service had
43
+ declared itself, so a service declaring both emitted a client with a
44
+ duplicated metadata parameter.
45
+
46
+ ### Changed
47
+
48
+ Behavior deltas against 3.3.0. All three need a cast or plain JavaScript to
49
+ reach — the generated signatures reject them under `tsc` — but on 3.3.0 the cast
50
+ form was the only way to delay a call while skipping an optional parameter, so
51
+ that spelling does occur in real code:
52
+
53
+ - `method(undefined, delay)`, on a method whose declared parameters are all
54
+ required, previously delivered `null` and now fails with
55
+ `IMQ_RPC_INVALID_ARGS_COUNT`. Pass a real value.
56
+ - `method(a, undefined, delay as any)`, on a method with an optional declared
57
+ parameter, previously delivered `null` for it and now omits it, so a defaulted
58
+ parameter falls back to its default. This one is silent: no error, a different
59
+ value.
60
+ - For a service that declares its own `IMQMetadata` parameter, metadata passed
61
+ positionally into that slot now arrives as `request.metadata`, leaving the
62
+ service's own parameter `undefined`.
63
+
64
+ Note that on 3.3.1 the drop applies only to *delayed* calls: `method(a,
65
+ undefined)` without a delay still delivers `null`, on every version.
package/CLAUDE.md ADDED
@@ -0,0 +1,3 @@
1
+ See [AGENTS.md](./AGENTS.md) for build, test, layout and the invariants to
2
+ respect when working on `@imqueue/rpc` (standard TC39 decorators, JSDoc-driven
3
+ types, `@expose()`/`@classType()` rules). End-user docs: https://imqueue.org/.
package/README.md CHANGED
@@ -6,6 +6,16 @@ RPC-like client-service implementation over messaging queue. This module
6
6
  provides base set of abstract classes and decorators to build services and
7
7
  clients for them.
8
8
 
9
+ **Documentation:** full guides, tutorial and API reference at
10
+ [imqueue.org](https://imqueue.org/). Commercial licensing & support for
11
+ closed-source products at [imqueue.com](https://imqueue.com/). Related packages:
12
+ [@imqueue/core](https://github.com/imqueue/core) (the message queue this builds
13
+ on) and [@imqueue/cli](https://github.com/imqueue/cli) (scaffolding & client
14
+ generation).
15
+
16
+ **Using an AI assistant?** Point it at [imqueue.org/llms.txt](https://imqueue.org/llms.txt)
17
+ for a machine-readable index of the docs, or see [AGENTS.md](./AGENTS.md).
18
+
9
19
  ## Why?
10
20
 
11
21
  To provide fast and reliable way of communication between backend services.
package/SECURITY.md ADDED
@@ -0,0 +1,40 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ If you believe you have found a security vulnerability in **@imqueue/rpc** (or any
6
+ `@imqueue/*` package), please report it **privately** — do not open a public issue,
7
+ pull request, or discussion for it.
8
+
9
+ Two private channels:
10
+
11
+ - **GitHub** — use *Security → Report a vulnerability* on this repository to open a
12
+ private advisory (preferred; it keeps the report and the fix coordinated in one
13
+ place).
14
+ - **Email** — <support@imqueue.com> with the details below.
15
+
16
+ Please include:
17
+
18
+ - the affected package and version(s);
19
+ - a description of the issue and its impact;
20
+ - steps to reproduce, or a proof of concept, where possible.
21
+
22
+ ## What to expect
23
+
24
+ - We aim to acknowledge a report within a few business days.
25
+ - We'll confirm the issue, keep you updated on progress, and coordinate a fix and a
26
+ disclosure timeline with you.
27
+ - Once a fix is released we'll credit the reporter in the advisory unless you prefer
28
+ to remain anonymous.
29
+
30
+ ## Supported versions
31
+
32
+ Security fixes land on the latest published release line of each `@imqueue/*`
33
+ package on npm. Please make sure you can reproduce an issue against the current
34
+ release before reporting.
35
+
36
+ ## Scope
37
+
38
+ The `@imqueue` framework is open source under GPL-3.0. This policy covers the code
39
+ in the `@imqueue/*` packages. Vulnerabilities in third-party dependencies should be
40
+ reported to those projects, though we're glad to help coordinate an upgrade.
package/context7.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://context7.com/schema/context7.json",
3
+ "projectTitle": "@imqueue/rpc",
4
+ "description": "Type-safe RPC framework for Node.js & TypeScript microservices over a Redis message queue — self-describing services generate their own strongly-typed clients.",
5
+ "excludeFolders": ["src", "lib", "node_modules", "test", "tests", "coverage", "docs/api"],
6
+ "excludeFiles": ["CHANGELOG.md", "LICENSE"],
7
+ "rules": [
8
+ "Define a service as a class extending IMQService and mark callable methods with the @expose() decorator.",
9
+ "JSDoc on exposed methods is the type source — the client is generated from the running service, not hand-written.",
10
+ "Generate the typed client with the imq CLI: `imq client generate <ServiceName>`.",
11
+ "Correlation, timeouts, at-least-once delivery and serialization are handled by the library, not your service code.",
12
+ "@imqueue is GPL-3.0; a commercial license is available for closed-source use (see imqueue.com/license)."
13
+ ]
14
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imqueue/rpc",
3
- "version": "3.3.0",
4
- "description": "RPC-like client-service implementation over messaging queue",
3
+ "version": "3.4.0",
4
+ "description": "Type-safe RPC framework for Node.js & TypeScript microservices over a Redis message queue — self-describing services generate their own strongly-typed clients (@imqueue framework)",
5
5
  "keywords": [
6
6
  "redis",
7
7
  "redis-queue",
@@ -10,7 +10,14 @@
10
10
  "service",
11
11
  "rpc-service",
12
12
  "rpc",
13
- "message-queue"
13
+ "message-queue",
14
+ "typescript",
15
+ "nodejs",
16
+ "microservices",
17
+ "typed-rpc",
18
+ "soa",
19
+ "inter-service-communication",
20
+ "imqueue"
14
21
  ],
15
22
  "scripts": {
16
23
  "clean-compiled": "npm run clean-js && npm run clean-typedefs && npm run clean-maps",
@@ -39,7 +46,8 @@
39
46
  "bugs": {
40
47
  "url": "https://github.com/imqueue/rpc/issues"
41
48
  },
42
- "homepage": "https://imqueue.com/",
49
+ "homepage": "https://imqueue.org/",
50
+ "funding": "https://imqueue.com/",
43
51
  "author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
44
52
  "license": "GPL-3.0-only",
45
53
  "dependencies": {
package/src/IMQClient.js CHANGED
@@ -175,9 +175,11 @@ let IMQClient = (() => {
175
175
  const from = this.queueName;
176
176
  const to = this.serviceName;
177
177
  let delay = 0;
178
+ let delayed = false;
178
179
  let metadata;
179
180
  if (args[args.length - 1] instanceof IMQDelay) {
180
181
  delay = args.pop().ms;
182
+ delayed = true;
181
183
  if (!isFinite(delay) || isNaN(delay) || delay < 0) {
182
184
  delay = 0;
183
185
  }
@@ -185,6 +187,18 @@ let IMQClient = (() => {
185
187
  if (args[args.length - 1] instanceof IMQMetadata) {
186
188
  metadata = args.pop();
187
189
  }
190
+ // On a delayed call a trailing `undefined` is a placeholder, never a
191
+ // value: it is either the skipped metadata slot or a skipped optional
192
+ // argument, both of which the caller has to spell out to reach the delay
193
+ // in the last position. Delivering it would serialize to `null`, defeat
194
+ // a declared default and, for a method whose params are all required,
195
+ // fail the service-side args count check. Both framework slots are gone
196
+ // by now, so this runs the same whether or not metadata was passed.
197
+ if (delayed) {
198
+ while (args.length && args[args.length - 1] === undefined) {
199
+ args.pop();
200
+ }
201
+ }
188
202
  const request = {
189
203
  from,
190
204
  method,
@@ -537,8 +551,11 @@ export namespace ${namespaceName} {\n`;
537
551
  },
538
552
  ];
539
553
  let retType = ret.tsType.replace(/\r?\n/g, ' ').replace(/\s{2,}/g, ' ');
540
- for (let i = 1; i <= 2; i++) {
541
- const arg = args[args.length - i];
554
+ // drop framework args the service declared itself, so that they are not
555
+ // duplicated by the canonical pair appended below; the last element is
556
+ // re-read on every pass, as the array shrinks as they are removed
557
+ for (let i = 0; i < addArgs.length; i++) {
558
+ const arg = args[args.length - 1];
542
559
  if (arg && ~['IMQDelay', 'IMQMetadata'].indexOf(arg.type)) {
543
560
  args.pop(); // remove it
544
561
  }