$ open source · GPL-3.0 — need a commercial license? imqueue.com →

Home > @imqueue/rpc

rpc package

Classes

Class

Description

Description

IMQCache

Generic cache registry

IMQDelay

Represents a delay expressed as a numeric timer value in a given time unit. Used to defer IMQ request processing.

IMQLock

Class IMQLock. Implements promise-based locks.

IMQMetadata

Arbitrary, JSON-serializable metadata bag carried alongside an IMQ request. Each property value must be a valid JSON value.

IMQRPCDescription

RedisCache

Class RedisCache. Implements a cache engine on top of Redis.

Abstract Classes

Abstract Class

Description

IMQClient

Class IMQClient - base abstract class for service clients.

IMQService

Class IMQService Basic abstract service (server-side) implementation

Functions

Function

Description

classType()

Implements the '@classType' decorator factory.

Applied to a complex-type class, it registers the class's '@property' field definitions into the RPC type description so the type can be exposed to service clients. It is required on any class that uses '@property': standard (TC39) field decorators cannot see the class they belong to, so a class-level decorator is needed to flush the collected properties under the class name.

currentMetadata()

Returns the metadata of the in-flight IMQ request for the current async execution, if any. Returns undefined outside of a runWithRequest() scope. The transport carries metadata as an opaque bag; callers interpret its fields.

{IMQMetadata | undefined}

expose()

Expose decorator factory. Applied to a service method, it registers that method in the RPC service description. (Complex argument/return types are registered separately via the '@classType' decorator on those classes.)

{(value: any, context: ClassMethodDecoratorContext) => void}

imqCallRejector(reject, req, client)

Builds a call rejector that rejects the pending promise and then runs the optional after-call hook.

imqCallResolver(resolve, req, client)

Builds a call resolver that resolves the pending promise and then runs the optional after-call hook.

IMQError(code, message, stack, method, args, original)

Builds a JSON representation of an IMQ error.

indexed(indexTypedef)

Implements '@indexed' decorator factory This is used to specify complex service types which are need to expose types containing indexed definition, for example:

lock(enabledOrOptions)

Creates a @lock() method decorator. Concurrent calls to the decorated method that share the same arguments are coalesced: only the first call is executed, and all the others resolve with its result. Call similarity is determined by the method's argument values. The returned decorator is dual-mode: it works both as a standard (TC39) and as a legacy method decorator.

logged(options)

Creates a @logged() method decorator that wraps the decorated method in a try/catch and logs any error it throws. The logger is resolved in this order: an explicitly passed logger, then a logger defined on the instance or on the class, and finally the global console. By default the error is re-thrown after being logged; pass { doNotThrow: true } to swallow it. The returned decorator is dual-mode: it works both as a standard (TC39) and as a legacy method decorator.

parseSourceComments(src, className)

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.

property(type, isOptional)

registerType(ctor, metadata, indexType)

Flushes definitions collected on a class into the RPC type description. Invoked by class-level decorators once the class (and hence its name) is available.

remote()

Creates a @remote() method decorator for client classes. The decorated method has the remote method name appended to its arguments and is then forwarded to remoteCall(). The returned decorator is dual-mode: it works both as a standard (TC39) and as a legacy (experimentalDecorators) method decorator.

{Function} - a dual-mode method decorator

runWithRequest(request, fn)

Runs the given function with request bound to the current async execution context, so any code reached from it (and its asynchronous continuations) can access the in-flight request's metadata via currentMetadata() without threading it through call signatures.

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.

send(request, response, service)

Sends IMQ response with support of after call optional hook

Interfaces

Interface

Description

ArgDescription

Method argument description

CacheDecorator

CacheDecoratorOptions

ICache

Generic cache adapter interface. Any cache engine implementation must conform to this contract to be usable within IMQ.

ICacheConstructor

Constructor signature for cache adapter implementations.

IMQAfterCall

Hook invoked after a service method call has been handled.

IMQBeforeCall

Hook invoked before a service method call is dispatched.

IMQClientOptions

Options accepted by a generated IMQ client.

IMQLockMetadata

IMQLockMetadataItem

IMQMetricsServerOptions

Options for the built-in metrics server.

IMQRPCError

Response error data structure, which service returns if error occurred during service method execution.

IMQRPCRequest

Request message data structure to be handled by a service.

IMQRPCResponse

Response message data structure that a service replies with to handled requests.

IMQServiceOptions

Options accepted by an IMQ service.

IMQWrapCall

Around hook wrapping the actual service method invocation. It receives the request/response and a next callback that runs the method and resolves to its return value; it MUST call next() (returning its resolved value) to produce the response data. Unlike beforeCall/afterCall, this lets a hook run the method inside its own scope — e.g. establishing an OpenTelemetry context so any spans the method (and its downstream calls) create nest under the request span. When unset, the method is invoked directly.

IRedisCacheOptions

LockOptions

LoggedDecoratorOptions

MethodDescription

Method description

MethodsCollectionDescription

Methods collection description

PropertyDescription

Type property description

ReturnValueDescription

Return value description

ServiceClassDescription

Service class description

ServiceDescription

Service description

Thunk

TypeDescription

Type properties collection description

TypesDescription

Entire service types metadata structure

Variables

Variable

Description

AFTER_HOOK_ERROR

BEFORE_HOOK_ERROR

cache

Creates a @cache() method decorator that memoizes the decorated method's result in a cache adapter (RedisCache by default). On each call the cache is checked first; on a miss the method runs, and its result is stored under a key derived from the class name, method name, and arguments. The returned decorator is dual-mode: it works both as a standard (TC39) and as a legacy method decorator.

DEFAULT_IMQ_CLIENT_OPTIONS

Default client options

{IMQClientOptions}

DEFAULT_IMQ_METRICS_SERVER_OPTIONS

Default metrics server options

{NonNullable}

DEFAULT_IMQ_SERVICE_OPTIONS

Default service options

{IMQServiceOptions}

DEFAULT_REDIS_CACHE_OPTIONS

REDIS_CLIENT_INIT_ERROR

Type Aliases

Type Alias

Description

AcquiredLock

ICacheAdapter

Accepted cache adapter references: a constructor, an instance, or an adapter name.

IMQLockQueue

IMQLockTask

LoggedLogLevel