rpc package
Type-safe RPC over a message queue — services, clients and the decorators that describe them, built on @imqueue/core.
Write a service by extending IMQService and marking each remotely callable method with @expose(). Complex argument and return types need a class-level @classType() (or @indexed()) plus @property() on each field. Then generate a typed client for that service with IMQClient.create(), which reads the running service's own description.
Remarks
Decorator protocol. This package targets standard (TC39) decorators. Consuming projects must compile with experimentalDecorators: false, removeComments: false, and esnext.decorators in lib. The decorators still work under legacy compilation, but behaviour differs — see classType, which is required under standard decorators and a no-op under legacy, and expose, whose registration is deferred to first construction under standard decorators.
removeComments: false is not optional: standard decorators provide no runtime type reflection, so an exposed method's JSDoc is the only source of argument and return types for the generated client, and the documented @param list is what the service's argument-count check validates.
Importing this package installs a global Symbol.metadata polyfill, which standard decorator metadata depends on.
Re-exports. This package re-exports the entire @imqueue/core surface, so core types and helpers can be imported from either package. The one exception is core's default-exported IMQ factory: export * never forwards a default, so import IMQ from '@imqueue/rpc' yields undefined — import it from @imqueue/core directly.
Example
import { IMQService, IMQClient, expose } from '@imqueue/rpc';
class UserService extends IMQService {
// NOTE: a real service needs a JSDoc block here with typed
// @param / @returns tags — that is where the generated client
// gets its types from
@expose()
public async count(active: boolean): Promise<number> {
return 42;
}
}
await new UserService().start();
// elsewhere — generates and loads a typed client
const ns = await IMQClient.create('UserService');
const client = new ns.UserClient();
await client.start();
console.log(await client.count(true));
Classes
|
Class |
Description |
|---|---|
|
The self-description a service serves to its clients, and the input to client generation. | |
|
Process-wide static registry of cache adapters. | |
|
Represents a delay expressed as a numeric timer value in a given time unit. Used to defer IMQ request processing. | |
|
In-process, promise-based locks used to collapse concurrent identical calls: the first caller executes the work while later callers for the same key wait and are then resolved with the first caller's result. | |
|
Arbitrary, JSON-serializable metadata bag carried alongside an IMQ request. Each property value must be a valid JSON value. | |
|
Process-global registry of RPC metadata gathered by the decorators. | |
|
Class RedisCache. Implements a cache engine on top of Redis. |
Abstract Classes
|
Abstract Class |
Description |
|---|---|
|
Base class for service clients. Subclass it and declare every remote method as | |
|
Class IMQService Basic abstract service (server-side) implementation |
Functions
|
Function |
Description |
|---|---|
|
Registers a complex-type class's | |
|
Returns the metadata of the in-flight IMQ request for the current async execution, if any. Returns | |
|
Makes a service method callable remotely by registering it in the RPC service description. | |
|
Builds a call rejector that rejects the pending promise and then runs the optional after-call hook. | |
|
Builds a call resolver that resolves the pending promise and then runs the optional after-call hook. | |
|
Builds a JSON representation of an IMQ error. | |
|
Exposes a complex service type that carries an index signature. | |
|
Creates a | |
|
Creates a | |
|
Extracts method JSDoc blocks from original source text of a given class. The text may be TypeScript (type annotations, generics, modifiers, decorators), which acorn cannot parse — so extraction is textual: the search is narrowed to the class region (from the class declaration to the next class declaration or EOF), and each doc block is attributed to the method whose declaration head immediately follows it. When several blocks precede a method, the closest one wins, matching the runtime parser. | |
|
Marks a class field as part of an exposed complex type, so it is described to clients and appears in the generated client interfaces. | |
|
Flushes | |
|
Creates a | |
|
Runs the given function with The binding is scoped to the function: it is established for the duration of the call and automatically removed afterwards, which keeps concurrent requests isolated from one another. | |
|
Sends IMQ response with support of after call optional hook |
Interfaces
|
Interface |
Description |
|---|---|
|
Description of one argument of an exposed method, as parsed from its JSDoc. | |
|
The type of the cache export: a decorator factory that also carries process-wide defaults. | |
|
Per-method options for the cache decorator. | |
|
Generic cache adapter interface. Any cache engine implementation must conform to this contract to be usable within IMQ. | |
|
Constructor signature the registry uses to instantiate a cache adapter class. | |
|
Hook invoked after a call has been handled. | |
|
Hook invoked before a call is dispatched. | |
|
Options accepted by a generated IMQ client. | |
|
Map from lock key to the metadata describing the call currently associated with that key. | |
|
Diagnostic description of a locked call. | |
|
Options for the built-in metrics server. | |
|
Failure descriptor for a remote call. Produced by a service when a method throws, and also before dispatch when the method does not exist, is not exposed, or was called with the wrong number of arguments. A client additionally synthesizes one locally on call timeout. | |
|
Wire format of a remote call, produced by a client and consumed by a service. | |
|
Response message data structure that a service replies with to handled requests. | |
|
Options accepted by an IMQ service. | |
|
Around hook wrapping the actual service method invocation. It receives the request/response and a | |
|
Options accepted by RedisCache.init(). | |
|
Options for the lock() decorator. | |
|
Options for the logged() decorator. | |
|
Description of one exposed method: its summary, its positional arguments and its return value. | |
|
Map of method name to method description. | |
|
Description of one property of an exposed complex type. | |
|
Description of an exposed method's return value, as parsed from its JSDoc. | |
|
The exposed methods a single class declares, plus its parent's name. | |
|
Raw registry of every class that declares exposed methods, keyed by class name — the storage format behind IMQRPCDescription.serviceDescription. | |
|
A zero-argument function whose return value is resolved lazily. Used by property() and indexed() so a type definition can reference a class that is not yet initialized at decoration time — self-references and forward references. | |
|
The property bag of a single exposed type: property name to property description. | |
|
Every exposed complex type, keyed by class name. |
Variables
|
Variable |
Description |
|---|---|
|
Prefix used when logging a failure inside an | |
|
Prefix used when logging a failure inside a | |
|
Creates a | |
|
Default options applied to every generated IMQ client: the core queue defaults, plus cleanup enabled with a | |
|
Default metrics server options | |
|
Default options applied to every IMQ service: the core queue defaults, plus cleanup enabled with a | |
|
Default options for RedisCache: the standard queue defaults, with | |
|
Message of the |
Type Aliases
|
Type Alias |
Description |
|---|---|
|
What IMQLock.acquire() resolves to: the literal | |
|
Accepted cache adapter references: a constructor, an instance, or an adapter name. | |
|
The FIFO queue of callers waiting on a single lock key, drained in arrival order when the lock is released. | |
|
Internal representation of one queued waiter: its promise's | |
|
Names of the |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.