@imqueue/rpc 3.3.0 → 3.3.1

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/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.3.1",
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
@@ -181,6 +181,13 @@ let IMQClient = (() => {
181
181
  if (!isFinite(delay) || isNaN(delay) || delay < 0) {
182
182
  delay = 0;
183
183
  }
184
+ // The metadata slot sits between the declared arguments and the
185
+ // delay, so callers who only need a delay may skip it with an
186
+ // explicit `undefined`. Drop it here, or it would travel on as a
187
+ // real call argument and break the service-side args count check.
188
+ if (args.length && args[args.length - 1] === undefined) {
189
+ args.pop();
190
+ }
184
191
  }
185
192
  if (args[args.length - 1] instanceof IMQMetadata) {
186
193
  metadata = args.pop();
@@ -537,8 +544,11 @@ export namespace ${namespaceName} {\n`;
537
544
  },
538
545
  ];
539
546
  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];
547
+ // drop framework args the service declared itself, so that they are not
548
+ // duplicated by the canonical pair appended below; the last element is
549
+ // re-read on every pass, as the array shrinks as they are removed
550
+ for (let i = 0; i < addArgs.length; i++) {
551
+ const arg = args[args.length - 1];
542
552
  if (arg && ~['IMQDelay', 'IMQMetadata'].indexOf(arg.type)) {
543
553
  args.pop(); // remove it
544
554
  }