@imqueue/rpc 3.4.3 → 3.5.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/index.d.ts +58 -0
  3. package/index.js +58 -0
  4. package/package.json +2 -2
  5. package/src/IMQCache.d.ts +20 -11
  6. package/src/IMQCache.js +20 -11
  7. package/src/IMQClient.d.ts +191 -38
  8. package/src/IMQClient.js +204 -57
  9. package/src/IMQDelay.d.ts +29 -6
  10. package/src/IMQDelay.js +20 -6
  11. package/src/IMQLock.d.ts +81 -35
  12. package/src/IMQLock.js +38 -35
  13. package/src/IMQMetadata.d.ts +9 -1
  14. package/src/IMQMetadata.js +1 -1
  15. package/src/IMQRPCDescription.d.ts +183 -9
  16. package/src/IMQRPCDescription.js +22 -0
  17. package/src/IMQRPCError.d.ts +91 -9
  18. package/src/IMQRPCError.js +23 -7
  19. package/src/IMQRPCOptions.d.ts +221 -18
  20. package/src/IMQRPCOptions.js +22 -6
  21. package/src/IMQRPCRequest.d.ts +39 -1
  22. package/src/IMQRPCResponse.d.ts +34 -0
  23. package/src/IMQRequestContext.d.ts +2 -5
  24. package/src/IMQRequestContext.js +2 -5
  25. package/src/IMQService.d.ts +144 -19
  26. package/src/IMQService.js +151 -33
  27. package/src/cache/ICache.d.ts +58 -16
  28. package/src/cache/RedisCache.d.ts +58 -17
  29. package/src/cache/RedisCache.js +43 -17
  30. package/src/decorators/cache.d.ts +46 -2
  31. package/src/decorators/cache.js +2 -2
  32. package/src/decorators/classType.d.ts +28 -13
  33. package/src/decorators/classType.js +28 -13
  34. package/src/decorators/expose.d.ts +59 -7
  35. package/src/decorators/expose.js +77 -30
  36. package/src/decorators/indexed.d.ts +27 -8
  37. package/src/decorators/indexed.js +27 -8
  38. package/src/decorators/lock.d.ts +20 -2
  39. package/src/decorators/lock.js +2 -2
  40. package/src/decorators/logged.d.ts +29 -2
  41. package/src/decorators/logged.js +2 -2
  42. package/src/decorators/property.d.ts +97 -4
  43. package/src/decorators/property.js +84 -6
  44. package/src/decorators/remote.d.ts +1 -1
  45. package/src/decorators/remote.js +1 -1
  46. package/src/helpers/fs.d.ts +5 -7
  47. package/src/helpers/fs.js +8 -10
  48. package/src/helpers/os-uuid.d.ts +0 -2
  49. package/src/helpers/os-uuid.js +2 -10
  50. package/src/helpers/pid.d.ts +7 -7
  51. package/src/helpers/pid.js +10 -11
  52. package/src/helpers/signature.d.ts +4 -4
  53. package/src/helpers/signature.js +7 -7
package/CHANGELOG.md CHANGED
@@ -6,7 +6,25 @@ log.
6
6
 
7
7
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
- ## [Unreleased]
9
+ ## [3.4.4] - 2026-07-26
10
+
11
+ ### Changed
12
+
13
+ - Raised the `@imqueue/core` dependency to `^3.2.4`, which stops a destroyed
14
+ queue's reader from swallowing one message addressed to the next owner of its
15
+ queue name. That is the same failure 3.4.2 addressed from this side, and the
16
+ two are complementary: 3.4.2 stops a queue name being handed over within a
17
+ process at all, while core 3.2.4 removes the stale consumer however the name
18
+ changes hands — including from another process, which nothing here can
19
+ prevent.
20
+
21
+ ## [3.4.3] - 2026-07-26
22
+
23
+ ### Changed
24
+
25
+ - Raised the `@imqueue/core` dependency to `^3.2.3`.
26
+
27
+ ## [3.4.2] - 2026-07-26
10
28
 
11
29
  ### Fixed
12
30
 
package/index.d.ts CHANGED
@@ -19,5 +19,63 @@
19
19
  * purchase a proprietary commercial license. Please contact us at
20
20
  * <support@imqueue.com> to get commercial licensing options.
21
21
  */
22
+ /**
23
+ * Type-safe RPC over a message queue — services, clients and the decorators that
24
+ * describe them, built on `@imqueue/core`.
25
+ *
26
+ * Write a service by extending `IMQService` and marking each remotely callable
27
+ * method with `@expose()`. Complex argument and return types need a class-level
28
+ * `@classType()` (or `@indexed()`) plus `@property()` on each field. Then generate a
29
+ * typed client for that service with `IMQClient.create()`, which reads the running
30
+ * service's own description.
31
+ *
32
+ * @remarks
33
+ * Decorator protocol. This package targets standard (TC39) decorators.
34
+ * Consuming projects must compile with `experimentalDecorators: false`,
35
+ * `removeComments: false`, and `esnext.decorators` in `lib`. The decorators still
36
+ * work under legacy compilation, but behaviour differs — see `classType`, which is
37
+ * required under standard decorators and a no-op under legacy, and `expose`, whose
38
+ * registration is deferred to first construction under standard decorators.
39
+ *
40
+ * `removeComments: false` is not optional: standard decorators provide no runtime
41
+ * type reflection, so an exposed method's JSDoc is the only source of argument
42
+ * and return types for the generated client, and the documented `@param` list is
43
+ * what the service's argument-count check validates.
44
+ *
45
+ * Importing this package installs a global `Symbol.metadata` polyfill, which
46
+ * standard decorator metadata depends on.
47
+ *
48
+ * Re-exports. This package re-exports the entire `@imqueue/core` surface, so
49
+ * core types and helpers can be imported from either package. The one exception is
50
+ * core's default-exported `IMQ` factory: `export *` never forwards a default, so
51
+ * `import IMQ from '@imqueue/rpc'` yields `undefined` — import it from
52
+ * `@imqueue/core` directly.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { IMQService, IMQClient, expose } from '@imqueue/rpc';
57
+ *
58
+ * class UserService extends IMQService {
59
+ * // NOTE: a real service needs a JSDoc block here with typed
60
+ * // @param / @returns tags — that is where the generated client
61
+ * // gets its types from
62
+ * @expose()
63
+ * public async count(active: boolean): Promise<number> {
64
+ * return 42;
65
+ * }
66
+ * }
67
+ *
68
+ * await new UserService().start();
69
+ *
70
+ * // elsewhere — generates and loads a typed client
71
+ * const ns = await IMQClient.create('UserService');
72
+ * const client = new ns.UserClient();
73
+ *
74
+ * await client.start();
75
+ * console.log(await client.count(true));
76
+ * ```
77
+ *
78
+ * @packageDocumentation
79
+ */
22
80
  export * from './src/index.js';
23
81
  export * from '@imqueue/core';
package/index.js CHANGED
@@ -19,6 +19,64 @@
19
19
  * purchase a proprietary commercial license. Please contact us at
20
20
  * <support@imqueue.com> to get commercial licensing options.
21
21
  */
22
+ /**
23
+ * Type-safe RPC over a message queue — services, clients and the decorators that
24
+ * describe them, built on `@imqueue/core`.
25
+ *
26
+ * Write a service by extending `IMQService` and marking each remotely callable
27
+ * method with `@expose()`. Complex argument and return types need a class-level
28
+ * `@classType()` (or `@indexed()`) plus `@property()` on each field. Then generate a
29
+ * typed client for that service with `IMQClient.create()`, which reads the running
30
+ * service's own description.
31
+ *
32
+ * @remarks
33
+ * Decorator protocol. This package targets standard (TC39) decorators.
34
+ * Consuming projects must compile with `experimentalDecorators: false`,
35
+ * `removeComments: false`, and `esnext.decorators` in `lib`. The decorators still
36
+ * work under legacy compilation, but behaviour differs — see `classType`, which is
37
+ * required under standard decorators and a no-op under legacy, and `expose`, whose
38
+ * registration is deferred to first construction under standard decorators.
39
+ *
40
+ * `removeComments: false` is not optional: standard decorators provide no runtime
41
+ * type reflection, so an exposed method's JSDoc is the only source of argument
42
+ * and return types for the generated client, and the documented `@param` list is
43
+ * what the service's argument-count check validates.
44
+ *
45
+ * Importing this package installs a global `Symbol.metadata` polyfill, which
46
+ * standard decorator metadata depends on.
47
+ *
48
+ * Re-exports. This package re-exports the entire `@imqueue/core` surface, so
49
+ * core types and helpers can be imported from either package. The one exception is
50
+ * core's default-exported `IMQ` factory: `export *` never forwards a default, so
51
+ * `import IMQ from '@imqueue/rpc'` yields `undefined` — import it from
52
+ * `@imqueue/core` directly.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { IMQService, IMQClient, expose } from '@imqueue/rpc';
57
+ *
58
+ * class UserService extends IMQService {
59
+ * // NOTE: a real service needs a JSDoc block here with typed
60
+ * // @param / @returns tags — that is where the generated client
61
+ * // gets its types from
62
+ * @expose()
63
+ * public async count(active: boolean): Promise<number> {
64
+ * return 42;
65
+ * }
66
+ * }
67
+ *
68
+ * await new UserService().start();
69
+ *
70
+ * // elsewhere — generates and loads a typed client
71
+ * const ns = await IMQClient.create('UserService');
72
+ * const client = new ns.UserClient();
73
+ *
74
+ * await client.start();
75
+ * console.log(await client.count(true));
76
+ * ```
77
+ *
78
+ * @packageDocumentation
79
+ */
22
80
  export * from './src/index.js';
23
81
  export * from '@imqueue/core';
24
82
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imqueue/rpc",
3
- "version": "3.4.3",
3
+ "version": "3.5.0",
4
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",
@@ -51,7 +51,7 @@
51
51
  "author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
52
52
  "license": "GPL-3.0-only",
53
53
  "dependencies": {
54
- "@imqueue/core": "^3.2.3",
54
+ "@imqueue/core": "^3.2.4",
55
55
  "acorn": "^8.17.0",
56
56
  "typescript": "^7.0.2"
57
57
  },
package/src/IMQCache.d.ts CHANGED
@@ -1,40 +1,49 @@
1
1
  import { type ICache, type ICacheAdapter } from './index.js';
2
2
  /**
3
- * Generic cache registry
3
+ * Process-wide static registry of cache adapters.
4
+ *
5
+ * @remarks
6
+ * All state is static and shared by every consumer in the process; there is no
7
+ * instance form and no way to unregister or reset an adapter. Adapters are keyed by
8
+ * name, so a single adapter class can only be registered once — two different
9
+ * configurations of the same class cannot coexist.
4
10
  */
5
11
  export declare class IMQCache {
6
12
  private static options;
13
+ /**
14
+ * The registry of adapter instances, keyed by adapter name.
15
+ *
16
+ * @remarks
17
+ * Exposed for inspection. Mutating it directly bypasses the option staging that
18
+ * {@link IMQCache.register} and {@link IMQCache.apply} perform.
19
+ */
7
20
  static adapters: {
8
21
  [name: string]: ICache;
9
22
  };
10
23
  /**
11
24
  * Registers the given cache adapter.
12
25
  *
13
- * @param {ICacheAdapter | string} adapter - adapter name, class or
26
+ * @param adapter - adapter name, class or
14
27
  * instance
15
- * @param {any} [options] - adapter-specific options
16
- * @returns {IMQCache}
28
+ * @param options - adapter-specific options
17
29
  */
18
30
  static register(adapter: ICacheAdapter | string, options?: any): typeof IMQCache;
19
31
  /**
20
32
  * Overrides existing adapter options with the given ones.
21
33
  *
22
- * @param {ICacheAdapter | string} adapter - adapter to apply options to
23
- * @param {any} options - adapter-specific options
24
- * @returns {IMQCache}
34
+ * @param adapter - adapter to apply options to
35
+ * @param options - adapter-specific options
25
36
  */
26
37
  static apply(adapter: ICacheAdapter | string, options: any): typeof IMQCache;
27
38
  /**
28
39
  * Initializes all registered cache adapters.
29
- *
30
- * @returns {Promise<any>}
31
40
  */
32
41
  static init(): Promise<any>;
33
42
  /**
34
43
  * Returns a registered cache adapter by its given name or class.
35
44
  *
36
- * @param {ICacheAdapter} adapter - adapter name, class or instance
37
- * @returns {ICache} - adapter instance
45
+ * @param adapter - adapter name, class or instance
46
+ * @returns adapter instance
38
47
  */
39
48
  static get(adapter: ICacheAdapter): ICache;
40
49
  }
package/src/IMQCache.js CHANGED
@@ -30,18 +30,30 @@ const BUILT_IN_ADAPTERS = {
30
30
  RedisCache: RedisCache,
31
31
  };
32
32
  /**
33
- * Generic cache registry
33
+ * Process-wide static registry of cache adapters.
34
+ *
35
+ * @remarks
36
+ * All state is static and shared by every consumer in the process; there is no
37
+ * instance form and no way to unregister or reset an adapter. Adapters are keyed by
38
+ * name, so a single adapter class can only be registered once — two different
39
+ * configurations of the same class cannot coexist.
34
40
  */
35
41
  export class IMQCache {
36
42
  static options = {};
43
+ /**
44
+ * The registry of adapter instances, keyed by adapter name.
45
+ *
46
+ * @remarks
47
+ * Exposed for inspection. Mutating it directly bypasses the option staging that
48
+ * {@link IMQCache.register} and {@link IMQCache.apply} perform.
49
+ */
37
50
  static adapters = {};
38
51
  /**
39
52
  * Registers the given cache adapter.
40
53
  *
41
- * @param {ICacheAdapter | string} adapter - adapter name, class or
54
+ * @param adapter - adapter name, class or
42
55
  * instance
43
- * @param {any} [options] - adapter-specific options
44
- * @returns {IMQCache}
56
+ * @param options - adapter-specific options
45
57
  */
46
58
  static register(adapter, options) {
47
59
  const self = IMQCache;
@@ -72,9 +84,8 @@ export class IMQCache {
72
84
  /**
73
85
  * Overrides existing adapter options with the given ones.
74
86
  *
75
- * @param {ICacheAdapter | string} adapter - adapter to apply options to
76
- * @param {any} options - adapter-specific options
77
- * @returns {IMQCache}
87
+ * @param adapter - adapter to apply options to
88
+ * @param options - adapter-specific options
78
89
  */
79
90
  static apply(adapter, options) {
80
91
  const self = IMQCache;
@@ -88,8 +99,6 @@ export class IMQCache {
88
99
  }
89
100
  /**
90
101
  * Initializes all registered cache adapters.
91
- *
92
- * @returns {Promise<any>}
93
102
  */
94
103
  static async init() {
95
104
  const self = IMQCache;
@@ -105,8 +114,8 @@ export class IMQCache {
105
114
  /**
106
115
  * Returns a registered cache adapter by its given name or class.
107
116
  *
108
- * @param {ICacheAdapter} adapter - adapter name, class or instance
109
- * @returns {ICache} - adapter instance
117
+ * @param adapter - adapter name, class or instance
118
+ * @returns adapter instance
110
119
  */
111
120
  static get(adapter) {
112
121
  return IMQCache.adapters[typeof adapter === 'string' ? adapter : adapter.name];
@@ -25,14 +25,79 @@ import { type JsonObject } from '@imqueue/core';
25
25
  import { type IMQClientOptions, type IMQRPCResponse, type IMQRPCRequest, IMQDelay, Description } from './index.js';
26
26
  import { EventEmitter } from 'node:events';
27
27
  /**
28
- * Class IMQClient - base abstract class for service clients.
28
+ * Base class for service clients.
29
+ *
30
+ * Subclass it and declare every remote method as
31
+ * `@remote() async m(...args) \{ return await this.remoteCall<T>(...arguments); \}`,
32
+ * or let {@link IMQClient.create} generate the subclass from a running service's
33
+ * description.
34
+ *
35
+ * @remarks
36
+ * Abstractness is enforced at runtime as well as by the type system: constructing
37
+ * `IMQClient` directly throws a `TypeError`.
38
+ *
39
+ * Instances are `EventEmitter`s. Besides ordinary calls, any response that no
40
+ * longer has a pending caller is emitted as an event named after the remote
41
+ * method, carrying the raw {@link IMQRPCResponse} — the escape hatch for replies to
42
+ * calls made by a process that has since died.
43
+ *
44
+ * The identity properties pair up as follows: {@link IMQClient.serviceName} is
45
+ * where calls go, {@link IMQClient.queueName} is where answers come back,
46
+ * {@link IMQClient.name} identifies this client, {@link IMQClient.hostName}
47
+ * identifies the machine plus instance, and {@link IMQClient.id} is the per-host
48
+ * instance slot.
29
49
  */
30
50
  export declare abstract class IMQClient extends EventEmitter {
51
+ /**
52
+ * The effective options for this client: {@link DEFAULT_IMQ_CLIENT_OPTIONS}
53
+ * merged with the values passed to the constructor.
54
+ */
31
55
  readonly options: IMQClientOptions;
56
+ /**
57
+ * Per-host instance slot number — not an OS process id.
58
+ *
59
+ * @remarks
60
+ * Allocated by claiming the lowest free pid file under `$TMPDIR/.imq-rpc`; the
61
+ * file itself contains the real `process.pid`. Ids released by
62
+ * {@link IMQClient.destroy} are not re-issued within the same process.
63
+ */
32
64
  readonly id: number;
65
+ /**
66
+ * This client's unique identity, `"<baseName>-<hostName>"`.
67
+ *
68
+ * @remarks
69
+ * Also used as the name of the dedicated subscription queue in `singleQueue`
70
+ * mode.
71
+ */
33
72
  readonly name: string;
73
+ /**
74
+ * Machine-scoped identity, `"<osUuid>-<id>:client"`, where `osUuid` is a hash of
75
+ * the OS machine id.
76
+ *
77
+ * @remarks
78
+ * This is not a network hostname. The `:client` suffix is what makes the
79
+ * default `cleanupFilter` of `'*:client'` match client queues. In `singleQueue`
80
+ * mode it is inherited from the shared queue's name instead.
81
+ */
34
82
  readonly hostName: string;
83
+ /**
84
+ * The remote side: the queue every request is addressed to, and the pub/sub
85
+ * channel {@link IMQClient.subscribe} listens on.
86
+ *
87
+ * @remarks
88
+ * Defaults to this client's base name with a trailing `Client` removed, so
89
+ * `UserClient` talks to the queue `User`.
90
+ */
35
91
  readonly serviceName: string;
92
+ /**
93
+ * The local side: the queue replies come back on, and the value placed in
94
+ * `request.from`.
95
+ *
96
+ * @remarks
97
+ * Equals {@link IMQClient.name}, or {@link IMQClient.hostName} when
98
+ * `singleQueue` is enabled. Also the channel {@link IMQClient.broadcast}
99
+ * publishes to.
100
+ */
36
101
  readonly queueName: string;
37
102
  private readonly baseName;
38
103
  private readonly imq;
@@ -45,76 +110,164 @@ export declare abstract class IMQClient extends EventEmitter {
45
110
  private readonly logger;
46
111
  private resolvers;
47
112
  /**
48
- * Class constructor
113
+ * Constructs a client.
114
+ *
115
+ * @param options - client options, merged over
116
+ * {@link DEFAULT_IMQ_CLIENT_OPTIONS}
117
+ * @param serviceName - the queue calls are addressed to. Defaults to this
118
+ * client's own name with a trailing `Client` removed.
119
+ * @param name - this client's base name. Defaults to the constructor's name, so
120
+ * pass it explicitly if your build renames classes — a minifier would
121
+ * otherwise silently retarget the RPC.
122
+ * @throws TypeError when {@link IMQClient} is constructed directly rather than
123
+ * through a subclass
49
124
  *
50
- * @param {Partial<IMQClientOptions>} options
51
- * @param {string} serviceName
52
- * @param {string} name
125
+ * @remarks
126
+ * Construction has side effects. It reserves an instance id by creating a pid
127
+ * file under `$TMPDIR/.imq-rpc`, opens its message queue (two in `singleQueue`
128
+ * mode), raises the process max-listener limit once per process, and installs
129
+ * `SIGTERM`/`SIGINT`/`SIGHUP`/`SIGQUIT` handlers that destroy the client and
130
+ * then exit the process after `IMQ_SHUTDOWN_TIMEOUT`. Any library embedding
131
+ * a client inherits that process-terminating behaviour.
132
+ *
133
+ * Only {@link IMQClient.destroy} releases the pid file and removes those
134
+ * handlers.
53
135
  */
54
136
  constructor(options?: Partial<IMQClientOptions>, serviceName?: string, name?: string);
55
137
  private createImq;
56
138
  private createSubscriptionImq;
57
139
  /**
58
- * Sends call to remote service method
140
+ * Sends a call to the remote service method.
141
+ *
142
+ * Intended to be invoked as `this.remoteCall<T>(...arguments)` from a method
143
+ * decorated with {@link remote}, which appends the method name for you.
59
144
  *
60
- * @param {...any[]} args
61
- * @template T
62
- * @returns {Promise<T>}
145
+ * @typeParam T - the type the remote method resolves to
146
+ * @param args - the method's own arguments, followed by the remote method
147
+ * name as the last element. An optional trailing {@link IMQDelay}
148
+ * (delivery delay) and {@link IMQMetadata} (tracing metadata) are
149
+ * consumed by the framework and never reach the service; on a delayed
150
+ * call, trailing `undefined` placeholders are dropped so service-side
151
+ * defaults still apply.
152
+ * @returns the service's response payload, cast to `T`
153
+ *
154
+ * @remarks
155
+ * {@link IMQClient.start} must have completed first. Otherwise the request is
156
+ * sent but no reply router is installed, so the returned promise never
157
+ * settles.
158
+ *
159
+ * Rejections are plain {@link IMQRPCError} objects, not `Error`
160
+ * instances — `err instanceof Error` is false, and `err.stack` describes the
161
+ * remote process. The code is `IMQ_RPC_CALL_ERROR` for a service-side failure
162
+ * and `IMQ_RPC_CALL_TIMEOUT` once {@link IMQClientOptions.callTimeout} elapses
163
+ * (plus any requested delay). With `callTimeout` unset — the default — a hung
164
+ * service leaves the promise pending indefinitely.
165
+ *
166
+ * `beforeCall` and `afterCall` hook failures are logged as warnings and
167
+ * otherwise ignored.
63
168
  */
64
169
  protected remoteCall<T>(...args: any[]): Promise<T>;
65
170
  /**
66
- * Adds subscription to service event channel
171
+ * Subscribes to the service's event channel, named after
172
+ * {@link IMQClient.serviceName} — the same channel a service's `publish()`
173
+ * writes to, so every client of that service receives every published payload.
174
+ *
175
+ * @param handler - invoked with the parsed JSON payload of each published
176
+ * message
67
177
  *
68
- * @param {(data: JsonObject) => any} handler
69
- * @return {Promise<void>}
178
+ * @remarks
179
+ * This is fan-out, not a private channel. Subscribing uses a dedicated
180
+ * connection and does not require {@link IMQClient.start}. Calling it more
181
+ * than once registers additional handlers rather than replacing the existing
182
+ * one, and the subscription is re-established automatically on reconnect.
70
183
  */
71
184
  subscribe(handler: (data: JsonObject) => any): Promise<void>;
72
185
  /**
73
- * Destroys subscription channel to service
186
+ * Stops receiving service events: unsubscribes the channel, discards every
187
+ * handler registered through {@link IMQClient.subscribe}, and closes the
188
+ * dedicated subscription connection.
74
189
  *
75
- * @return {Promise<void>}
190
+ * @remarks
191
+ * Safe when not subscribed, and it does not affect remote calls.
192
+ * {@link IMQClient.destroy} performs it automatically; afterwards
193
+ * {@link IMQClient.subscribe} can be used again with a fresh connection.
76
194
  */
77
195
  unsubscribe(): Promise<void>;
78
196
  /**
79
- * Broadcasts given payload to all other service clients subscribed.
80
- * So this is like client-to-clients publishing.
197
+ * Publishes the given payload on this client's own queue channel
198
+ * ({@link IMQClient.queueName}).
81
199
  *
82
- * @param {JsonObject} payload
83
- * @return {Promise<void>}
200
+ * @param payload - data to publish
201
+ * @throws TypeError when the client's queue has no writer connection, i.e. when
202
+ * called before {@link IMQClient.start}
203
+ *
204
+ * @remarks
205
+ * Note that {@link IMQClient.subscribe} listens on the service channel, so a
206
+ * broadcast is not received by other clients of the same service through the
207
+ * standard client API — a consumer must subscribe to this client's `queueName`
208
+ * channel explicitly.
84
209
  */
85
210
  broadcast(payload: JsonObject): Promise<void>;
86
211
  /**
87
212
  * Initializes client work
88
- *
89
- * @returns {Promise<void>}
90
213
  */
91
214
  start(): Promise<void>;
92
215
  /**
93
216
  * Stops client work
94
- *
95
- * @returns {Promise<void>}
96
217
  */
97
218
  stop(): Promise<void>;
98
219
  /**
99
220
  * Destroys client
100
- *
101
- * @returns {Promise<void>}
102
221
  */
103
222
  destroy(): Promise<void>;
104
223
  /**
105
224
  * Returns service description metadata.
106
225
  *
107
- * @param {IMQDelay} [_delay] - optional delivery delay; forwarded to the
226
+ * @param _delay - optional delivery delay; forwarded to the
108
227
  * service through `arguments` by the `@remote` decorator
109
- * @returns {Promise<Description>}
110
228
  */
111
229
  describe(_delay?: IMQDelay): Promise<Description>;
112
230
  /**
113
- * Creates client for a service with the given name
231
+ * Generates a client for the service registered under the given queue name and
232
+ * resolves to the generated namespace object — not to a client instance, and
233
+ * not to an {@link IMQClient}.
234
+ *
235
+ * @param name - name of the queue the target service listens on (its service
236
+ * name, which is the class name by default). Also used as the base name
237
+ * of the generated files.
238
+ * @param options - client options, merged over
239
+ * {@link DEFAULT_IMQ_CLIENT_OPTIONS}
240
+ * @returns the generated namespace object, exposing the generated client class
241
+ * (`<Service>Client`, with a trailing `Service` replaced by `Client`)
242
+ * plus one interface per registered service type. It is produced at
243
+ * runtime, so it is typed `any` — cast it or type the call site
244
+ * yourself. Resolves to `null` instead when
245
+ * {@link IMQClientOptions.compile} is false.
246
+ * @throws EvalError when the target service does not answer within
247
+ * {@link IMQClientOptions.timeout} milliseconds
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const ns = await IMQClient.create('UserService');
252
+ * const client = new ns.UserClient();
253
+ *
254
+ * await client.start();
255
+ * ```
256
+ *
257
+ * @remarks
258
+ * Generating a client requires the target service to be running: this sends
259
+ * a live description request over the queue and fails if no answer arrives in
260
+ * time.
261
+ *
262
+ * It always transpiles the generated source by spawning TypeScript
263
+ * synchronously, so the call blocks the event loop, and it rejects if
264
+ * transpilation emits nothing. When {@link IMQClientOptions.write} is set — the
265
+ * default — it writes both `<path>/<name>.ts` and `<path>/<name>.js`, silently
266
+ * overwriting any existing files, and creates `path` only one level deep.
114
267
  *
115
- * @param {string} name
116
- * @param {Partial<IMQServiceOptions>} options
117
- * @returns {IMQClient}
268
+ * The identifiers inside the generated module come from the service's own
269
+ * reported class name, so if that differs from `name` the file name and the
270
+ * namespace/class names differ too.
118
271
  */
119
272
  static create(name: string, options?: Partial<IMQClientOptions>): Promise<any>;
120
273
  }
@@ -122,19 +275,19 @@ export declare abstract class IMQClient extends EventEmitter {
122
275
  * Builds a call resolver that resolves the pending promise and then runs the
123
276
  * optional after-call hook.
124
277
  *
125
- * @param {(data: any) => void} resolve - the underlying promise resolver
126
- * @param {IMQRPCRequest} req - the originating request message
127
- * @param {IMQClient} client - the client the call belongs to
128
- * @return {(data: any, res: IMQRPCResponse) => void} - a hook-aware resolver
278
+ * @param resolve - the underlying promise resolver
279
+ * @param req - the originating request message
280
+ * @param client - the client the call belongs to
281
+ * @returns a hook-aware resolver
129
282
  */
130
283
  export declare function imqCallResolver(resolve: (data: any) => void, req: IMQRPCRequest, client: IMQClient): (data: any, res: IMQRPCResponse) => void;
131
284
  /**
132
285
  * Builds a call rejector that rejects the pending promise and then runs the
133
286
  * optional after-call hook.
134
287
  *
135
- * @param {(err: any) => void} reject - the underlying promise rejector
136
- * @param {IMQRPCRequest} req - the originating request message
137
- * @param {IMQClient} client - the client the call belongs to
138
- * @return {(err: any, res?: IMQRPCResponse) => void} - a hook-aware rejector
288
+ * @param reject - the underlying promise rejector
289
+ * @param req - the originating request message
290
+ * @param client - the client the call belongs to
291
+ * @returns a hook-aware rejector
139
292
  */
140
293
  export declare function imqCallRejector(reject: (err: any) => void, req: IMQRPCRequest, client: IMQClient): (err: any, res?: IMQRPCResponse) => void;