@imqueue/rpc 3.4.4 → 3.5.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/CHANGELOG.md +12 -0
- package/index.d.ts +58 -0
- package/index.js +58 -0
- package/package.json +1 -1
- package/src/IMQCache.d.ts +20 -11
- package/src/IMQCache.js +20 -11
- package/src/IMQClient.d.ts +191 -38
- package/src/IMQClient.js +204 -57
- package/src/IMQDelay.d.ts +29 -6
- package/src/IMQDelay.js +20 -6
- package/src/IMQLock.d.ts +81 -35
- package/src/IMQLock.js +38 -35
- package/src/IMQMetadata.d.ts +9 -1
- package/src/IMQMetadata.js +1 -1
- package/src/IMQRPCDescription.d.ts +183 -9
- package/src/IMQRPCDescription.js +22 -0
- package/src/IMQRPCError.d.ts +91 -9
- package/src/IMQRPCError.js +23 -7
- package/src/IMQRPCOptions.d.ts +221 -18
- package/src/IMQRPCOptions.js +22 -6
- package/src/IMQRPCRequest.d.ts +39 -1
- package/src/IMQRPCResponse.d.ts +34 -0
- package/src/IMQRequestContext.d.ts +2 -5
- package/src/IMQRequestContext.js +2 -5
- package/src/IMQService.d.ts +144 -19
- package/src/IMQService.js +151 -33
- package/src/cache/ICache.d.ts +62 -16
- package/src/cache/RedisCache.d.ts +58 -17
- package/src/cache/RedisCache.js +43 -17
- package/src/decorators/cache.d.ts +46 -2
- package/src/decorators/cache.js +2 -2
- package/src/decorators/classType.d.ts +28 -13
- package/src/decorators/classType.js +28 -13
- package/src/decorators/expose.d.ts +59 -7
- package/src/decorators/expose.js +77 -30
- package/src/decorators/indexed.d.ts +27 -8
- package/src/decorators/indexed.js +27 -8
- package/src/decorators/lock.d.ts +20 -2
- package/src/decorators/lock.js +2 -2
- package/src/decorators/logged.d.ts +33 -2
- package/src/decorators/logged.js +2 -2
- package/src/decorators/property.d.ts +97 -4
- package/src/decorators/property.js +84 -6
- package/src/decorators/remote.d.ts +1 -1
- package/src/decorators/remote.js +1 -1
- package/src/helpers/fs.d.ts +5 -7
- package/src/helpers/fs.js +8 -10
- package/src/helpers/os-uuid.d.ts +0 -2
- package/src/helpers/os-uuid.js +2 -10
- package/src/helpers/pid.d.ts +7 -7
- package/src/helpers/pid.js +10 -11
- package/src/helpers/signature.d.ts +4 -4
- package/src/helpers/signature.js +7 -7
package/src/IMQRPCOptions.d.ts
CHANGED
|
@@ -27,23 +27,50 @@ import { type IMQRPCResponse } from './IMQRPCResponse.js';
|
|
|
27
27
|
import { IMQService } from './IMQService.js';
|
|
28
28
|
import { IMQClient } from './IMQClient.js';
|
|
29
29
|
/**
|
|
30
|
-
* Hook invoked before a
|
|
30
|
+
* Hook invoked before a call is dispatched.
|
|
31
31
|
*
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* On a service the hook receives `(request, response)`; on a client it
|
|
34
|
+
* receives `(request)` only, and `res` is always `undefined`.
|
|
35
|
+
*
|
|
36
|
+
* Assigning `res.error` aborts the call — the method is never invoked and the
|
|
37
|
+
* error is returned to the caller. This is the supported way to reject a request
|
|
38
|
+
* from a hook. Assigning `res.data` has no effect, since it is overwritten by the
|
|
39
|
+
* method's result.
|
|
40
|
+
*
|
|
41
|
+
* Throwing does not abort anything: the error is logged as a warning
|
|
42
|
+
* (see {@link BEFORE_HOOK_ERROR}) and dispatch proceeds.
|
|
43
|
+
*
|
|
44
|
+
* The hook is invoked bound to the service or client instance, so a `function`
|
|
45
|
+
* expression can reach `this.logger` and `this.options` — but the type parameter is
|
|
46
|
+
* decorative, so `this` is not typed, and an arrow function does not receive the
|
|
47
|
+
* instance at all.
|
|
35
48
|
*/
|
|
36
49
|
export interface IMQBeforeCall<_T> {
|
|
50
|
+
/**
|
|
51
|
+
* @param req - the incoming request
|
|
52
|
+
* @param res - the response being prepared; service side only
|
|
53
|
+
*/
|
|
37
54
|
(req?: IMQRPCRequest, res?: IMQRPCResponse): Promise<void>;
|
|
38
55
|
}
|
|
39
56
|
/**
|
|
40
|
-
* Hook invoked after a
|
|
57
|
+
* Hook invoked after a call has been handled.
|
|
41
58
|
*
|
|
42
|
-
* @
|
|
43
|
-
*
|
|
44
|
-
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* Purely for observation — logging, metrics, tracing. On a service it runs after
|
|
61
|
+
* the response has already been sent; on a client it runs after the caller's
|
|
62
|
+
* promise has already been resolved or rejected. In both cases it is too late to
|
|
63
|
+
* change the outcome, and the caller does not wait for it.
|
|
64
|
+
*
|
|
65
|
+
* It is also invoked for failures, where `res` may be absent — for example when the
|
|
66
|
+
* request could not be sent at all. Thrown errors are logged as warnings (see
|
|
67
|
+
* {@link AFTER_HOOK_ERROR}) and swallowed; the return value is ignored.
|
|
45
68
|
*/
|
|
46
69
|
export interface IMQAfterCall<_T> {
|
|
70
|
+
/**
|
|
71
|
+
* @param req - the handled request
|
|
72
|
+
* @param res - the produced response; may be absent on a failure
|
|
73
|
+
*/
|
|
47
74
|
(req: IMQRPCRequest, res?: IMQRPCResponse): Promise<void>;
|
|
48
75
|
}
|
|
49
76
|
/**
|
|
@@ -55,61 +82,237 @@ export interface IMQAfterCall<_T> {
|
|
|
55
82
|
* context so any spans the method (and its downstream calls) create nest under
|
|
56
83
|
* the request span. When unset, the method is invoked directly.
|
|
57
84
|
*
|
|
58
|
-
* @
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* Service side only — there is no client equivalent, despite the type parameter.
|
|
87
|
+
*
|
|
88
|
+
* The hook's resolved value is the response data. Calling `next()` exactly once
|
|
89
|
+
* and returning its value is the required pattern, but it is not enforced: omitting
|
|
90
|
+
* `next()` silently skips the method and returns your value instead, and calling it
|
|
91
|
+
* twice runs the method twice.
|
|
92
|
+
*
|
|
93
|
+
* Unlike {@link IMQBeforeCall} and {@link IMQAfterCall}, errors here are not
|
|
94
|
+
* swallowed — anything this hook throws, or that propagates out of `next()`, becomes
|
|
95
|
+
* the call's error response (`IMQ_RPC_CALL_ERROR`, preserving the thrown error's own
|
|
96
|
+
* `code` when it has one). So a wrapping hook can safely let failures through or
|
|
97
|
+
* rethrow enriched errors.
|
|
98
|
+
*
|
|
99
|
+
* Invoked bound to the service instance; `this` is untyped, so do not use an arrow
|
|
100
|
+
* function if you need it.
|
|
62
101
|
*/
|
|
63
102
|
export interface IMQWrapCall<_T> {
|
|
103
|
+
/**
|
|
104
|
+
* @param req - the incoming request
|
|
105
|
+
* @param res - the response being prepared
|
|
106
|
+
* @param next - runs the method and resolves to its result
|
|
107
|
+
* @returns the value to use as the response data
|
|
108
|
+
*/
|
|
64
109
|
(req: IMQRPCRequest, res: IMQRPCResponse, next: () => Promise<any>): Promise<any>;
|
|
65
110
|
}
|
|
66
111
|
/**
|
|
67
112
|
* Options for the built-in metrics server.
|
|
68
113
|
*/
|
|
69
114
|
export interface IMQMetricsServerOptions {
|
|
115
|
+
/**
|
|
116
|
+
* Start the metrics HTTP listener when true.
|
|
117
|
+
*
|
|
118
|
+
* @defaultValue false
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* The listener serves a single route, `GET /metrics`, is unauthenticated, and is
|
|
122
|
+
* bound to all interfaces. Every process that starts the service — including the
|
|
123
|
+
* cluster primary in `multiProcess` mode — attempts to bind the port.
|
|
124
|
+
*/
|
|
70
125
|
enabled?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* TCP port to bind on all interfaces.
|
|
128
|
+
*
|
|
129
|
+
* @defaultValue 9090
|
|
130
|
+
*/
|
|
71
131
|
port?: number;
|
|
132
|
+
/**
|
|
133
|
+
* Renders the response body from the current queue length and the metric name,
|
|
134
|
+
* which is always the literal `'queue_length'`.
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* Defaults to a Prometheus-style rendering. A falsy return falls back to the
|
|
138
|
+
* bare number. Note that the queue length reports `0` while the queue's writer
|
|
139
|
+
* is disconnected.
|
|
140
|
+
*/
|
|
72
141
|
queueLengthFormatter?: (length: number, metricName: string) => string;
|
|
73
142
|
}
|
|
74
143
|
/**
|
|
75
144
|
* Options accepted by an IMQ service.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* Extends the core queue options, so all transport settings — `host`, `port`,
|
|
148
|
+
* `prefix`, `safeDelivery`, `useGzip`, `cluster`, `logger` and the rest — are
|
|
149
|
+
* accepted and forwarded to the queue factory.
|
|
76
150
|
*/
|
|
77
151
|
export interface IMQServiceOptions extends IMQOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Fork one cluster worker per CPU core, multiplied by
|
|
154
|
+
* {@link IMQServiceOptions.childrenPerCore}.
|
|
155
|
+
*
|
|
156
|
+
* @defaultValue false
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* The cluster primary also starts its own queue consumer and metrics listener
|
|
160
|
+
* after forking, so a service configured for N workers runs N+1 consumers.
|
|
161
|
+
* Workers are never respawned: when one dies the whole process exits with code
|
|
162
|
+
* 1, leaving supervision to the process manager.
|
|
163
|
+
*/
|
|
78
164
|
multiProcess: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Workers to fork per CPU core. Ignored unless
|
|
167
|
+
* {@link IMQServiceOptions.multiProcess} is true.
|
|
168
|
+
*
|
|
169
|
+
* @defaultValue 1
|
|
170
|
+
*/
|
|
79
171
|
childrenPerCore: number;
|
|
172
|
+
/**
|
|
173
|
+
* Built-in metrics HTTP listener settings.
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
176
|
+
* Merged separately over {@link DEFAULT_IMQ_METRICS_SERVER_OPTIONS}, so
|
|
177
|
+
* supplying a partial object keeps the default port and formatter.
|
|
178
|
+
*/
|
|
80
179
|
metricsServer?: IMQMetricsServerOptions;
|
|
180
|
+
/**
|
|
181
|
+
* Pre-dispatch hook. See {@link IMQBeforeCall}.
|
|
182
|
+
*/
|
|
81
183
|
beforeCall?: IMQBeforeCall<IMQService>;
|
|
184
|
+
/**
|
|
185
|
+
* Post-response hook. See {@link IMQAfterCall}.
|
|
186
|
+
*/
|
|
82
187
|
afterCall?: IMQAfterCall<IMQService>;
|
|
188
|
+
/**
|
|
189
|
+
* Around hook wrapping the method invocation. See {@link IMQWrapCall}.
|
|
190
|
+
*/
|
|
83
191
|
wrapCall?: IMQWrapCall<IMQService>;
|
|
84
192
|
}
|
|
85
193
|
/**
|
|
86
194
|
* Options accepted by a generated IMQ client.
|
|
195
|
+
*
|
|
196
|
+
* @remarks
|
|
197
|
+
* Extends the core queue options, so all transport settings are accepted as well.
|
|
198
|
+
* Note that `path`, `compile`, `write` and `timeout` affect code generation
|
|
199
|
+
* only and have no effect on an already-generated client at runtime.
|
|
87
200
|
*/
|
|
88
201
|
export interface IMQClientOptions extends IMQOptions {
|
|
202
|
+
/**
|
|
203
|
+
* Directory the generated client is written to, resolved relative to the
|
|
204
|
+
* process working directory.
|
|
205
|
+
*
|
|
206
|
+
* @defaultValue './src/clients'
|
|
207
|
+
*
|
|
208
|
+
* @remarks
|
|
209
|
+
* Created only one level deep, so the parent directories must already exist —
|
|
210
|
+
* the default fails with `ENOENT` on a project that has no `./src` yet.
|
|
211
|
+
*/
|
|
89
212
|
path: string;
|
|
213
|
+
/**
|
|
214
|
+
* Transpile the generated client and evaluate it in-process, returning its
|
|
215
|
+
* exports.
|
|
216
|
+
*
|
|
217
|
+
* @defaultValue true
|
|
218
|
+
*
|
|
219
|
+
* @remarks
|
|
220
|
+
* With `false`, generation only emits files and client creation resolves to
|
|
221
|
+
* `null`.
|
|
222
|
+
*/
|
|
90
223
|
compile: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Milliseconds the client generator waits for the target service to answer
|
|
226
|
+
* its description request before failing.
|
|
227
|
+
*
|
|
228
|
+
* @defaultValue 30000
|
|
229
|
+
*
|
|
230
|
+
* @remarks
|
|
231
|
+
* Despite the name this is not an RPC timeout and has no effect on runtime
|
|
232
|
+
* calls — use {@link IMQClientOptions.callTimeout} for those.
|
|
233
|
+
*/
|
|
91
234
|
timeout: number;
|
|
235
|
+
/**
|
|
236
|
+
* Persist the generated `.ts` and `.js` pair in {@link IMQClientOptions.path}.
|
|
237
|
+
*
|
|
238
|
+
* @defaultValue true
|
|
239
|
+
*
|
|
240
|
+
* @remarks
|
|
241
|
+
* Existing files are silently overwritten.
|
|
242
|
+
*/
|
|
92
243
|
write: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Per-call timeout in milliseconds.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* When set to a positive number, every remote call that has not received a
|
|
249
|
+
* response within the given time — plus any requested {@link IMQDelay} — is
|
|
250
|
+
* rejected with an `IMQ_RPC_CALL_TIMEOUT` error and its pending resolver is
|
|
251
|
+
* released. The internal timer is unref'd, so a pending call does not keep the
|
|
252
|
+
* process alive.
|
|
253
|
+
*
|
|
254
|
+
* Unset by default, which means calls wait indefinitely and a hung or absent
|
|
255
|
+
* service keeps the caller's promise pending forever. Enabling it is recommended
|
|
256
|
+
* for production use.
|
|
257
|
+
*/
|
|
93
258
|
callTimeout?: number;
|
|
259
|
+
/**
|
|
260
|
+
* Pre-dispatch hook. See {@link IMQBeforeCall}; on a client it receives the
|
|
261
|
+
* request only.
|
|
262
|
+
*/
|
|
94
263
|
beforeCall?: IMQBeforeCall<IMQClient>;
|
|
264
|
+
/**
|
|
265
|
+
* Post-settle hook. See {@link IMQAfterCall}.
|
|
266
|
+
*/
|
|
95
267
|
afterCall?: IMQAfterCall<IMQClient>;
|
|
268
|
+
/**
|
|
269
|
+
* Share a single reply queue and transport connection across every client in the
|
|
270
|
+
* process, instead of one per client.
|
|
271
|
+
*
|
|
272
|
+
* @defaultValue false
|
|
273
|
+
*
|
|
274
|
+
* @remarks
|
|
275
|
+
* `queueName` then becomes the shared host-level name rather than a per-client
|
|
276
|
+
* one, and each client keeps a private queue only for subscriptions.
|
|
277
|
+
* Shared-queue teardown is reference-counted, so destroying one client leaves the
|
|
278
|
+
* others working — but stopping one client stops reply delivery for every
|
|
279
|
+
* client in the process.
|
|
280
|
+
*
|
|
281
|
+
* Use it to bound Redis connections when a process instantiates many clients.
|
|
282
|
+
*/
|
|
96
283
|
singleQueue?: boolean;
|
|
97
284
|
}
|
|
98
285
|
/**
|
|
99
|
-
* Default service
|
|
286
|
+
* Default options applied to every IMQ service: the core queue defaults, plus
|
|
287
|
+
* cleanup enabled with a `'*:client'` filter, single-process mode, and one worker
|
|
288
|
+
* per core.
|
|
100
289
|
*
|
|
101
|
-
* @
|
|
290
|
+
* @remarks
|
|
291
|
+
* Note the two deliberate overrides of the core defaults: `cleanup` is `true`
|
|
292
|
+
* (core defaults to `false`) and `cleanupFilter` is `'*:client'` (core `'*'`). So a
|
|
293
|
+
* starting service prunes abandoned client queue keys, and the filter
|
|
294
|
+
* deliberately excludes service queues.
|
|
295
|
+
*
|
|
296
|
+
* Metrics-server defaults are not part of this object — they live in
|
|
297
|
+
* {@link DEFAULT_IMQ_METRICS_SERVER_OPTIONS} and are merged in separately by the
|
|
298
|
+
* service constructor.
|
|
102
299
|
*/
|
|
103
300
|
export declare const DEFAULT_IMQ_SERVICE_OPTIONS: IMQServiceOptions;
|
|
104
301
|
/**
|
|
105
302
|
* Default metrics server options
|
|
106
|
-
*
|
|
107
|
-
* @type {NonNullable<IMQMetricsServerOptions>}
|
|
108
303
|
*/
|
|
109
304
|
export declare const DEFAULT_IMQ_METRICS_SERVER_OPTIONS: NonNullable<IMQMetricsServerOptions>;
|
|
110
305
|
/**
|
|
111
|
-
* Default client
|
|
306
|
+
* Default options applied to every generated IMQ client: the core queue defaults,
|
|
307
|
+
* plus cleanup enabled with a `'*:client'` filter and the code-generation settings.
|
|
308
|
+
*
|
|
309
|
+
* @remarks
|
|
310
|
+
* What is intentionally absent matters as much as what is present:
|
|
311
|
+
* {@link IMQClientOptions.callTimeout} is unset, so runtime calls never time out
|
|
312
|
+
* unless you set it, and {@link IMQClientOptions.singleQueue} is unset, so every
|
|
313
|
+
* client creates its own queue.
|
|
112
314
|
*
|
|
113
|
-
*
|
|
315
|
+
* As with the service defaults, `cleanup: true` and `cleanupFilter: '*:client'`
|
|
316
|
+
* override the core defaults, and `timeout` applies to the generator only.
|
|
114
317
|
*/
|
|
115
318
|
export declare const DEFAULT_IMQ_CLIENT_OPTIONS: IMQClientOptions;
|
package/src/IMQRPCOptions.js
CHANGED
|
@@ -27,9 +27,19 @@ import {} from './IMQRPCResponse.js';
|
|
|
27
27
|
import { IMQService } from './IMQService.js';
|
|
28
28
|
import { IMQClient } from './IMQClient.js';
|
|
29
29
|
/**
|
|
30
|
-
* Default service
|
|
30
|
+
* Default options applied to every IMQ service: the core queue defaults, plus
|
|
31
|
+
* cleanup enabled with a `'*:client'` filter, single-process mode, and one worker
|
|
32
|
+
* per core.
|
|
31
33
|
*
|
|
32
|
-
* @
|
|
34
|
+
* @remarks
|
|
35
|
+
* Note the two deliberate overrides of the core defaults: `cleanup` is `true`
|
|
36
|
+
* (core defaults to `false`) and `cleanupFilter` is `'*:client'` (core `'*'`). So a
|
|
37
|
+
* starting service prunes abandoned client queue keys, and the filter
|
|
38
|
+
* deliberately excludes service queues.
|
|
39
|
+
*
|
|
40
|
+
* Metrics-server defaults are not part of this object — they live in
|
|
41
|
+
* {@link DEFAULT_IMQ_METRICS_SERVER_OPTIONS} and are merged in separately by the
|
|
42
|
+
* service constructor.
|
|
33
43
|
*/
|
|
34
44
|
export const DEFAULT_IMQ_SERVICE_OPTIONS = {
|
|
35
45
|
...DEFAULT_IMQ_OPTIONS,
|
|
@@ -40,8 +50,6 @@ export const DEFAULT_IMQ_SERVICE_OPTIONS = {
|
|
|
40
50
|
};
|
|
41
51
|
/**
|
|
42
52
|
* Default metrics server options
|
|
43
|
-
*
|
|
44
|
-
* @type {NonNullable<IMQMetricsServerOptions>}
|
|
45
53
|
*/
|
|
46
54
|
export const DEFAULT_IMQ_METRICS_SERVER_OPTIONS = {
|
|
47
55
|
enabled: false,
|
|
@@ -49,9 +57,17 @@ export const DEFAULT_IMQ_METRICS_SERVER_OPTIONS = {
|
|
|
49
57
|
queueLengthFormatter: (length, metricName) => `${metricName}{} ${length}`,
|
|
50
58
|
};
|
|
51
59
|
/**
|
|
52
|
-
* Default client
|
|
60
|
+
* Default options applied to every generated IMQ client: the core queue defaults,
|
|
61
|
+
* plus cleanup enabled with a `'*:client'` filter and the code-generation settings.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* What is intentionally absent matters as much as what is present:
|
|
65
|
+
* {@link IMQClientOptions.callTimeout} is unset, so runtime calls never time out
|
|
66
|
+
* unless you set it, and {@link IMQClientOptions.singleQueue} is unset, so every
|
|
67
|
+
* client creates its own queue.
|
|
53
68
|
*
|
|
54
|
-
*
|
|
69
|
+
* As with the service defaults, `cleanup: true` and `cleanupFilter: '*:client'`
|
|
70
|
+
* override the core defaults, and `timeout` applies to the generator only.
|
|
55
71
|
*/
|
|
56
72
|
export const DEFAULT_IMQ_CLIENT_OPTIONS = {
|
|
57
73
|
...DEFAULT_IMQ_OPTIONS,
|
package/src/IMQRPCRequest.d.ts
CHANGED
|
@@ -24,11 +24,49 @@
|
|
|
24
24
|
import { type JsonObject } from '@imqueue/core';
|
|
25
25
|
import { IMQMetadata } from './IMQMetadata.js';
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Wire format of a remote call, produced by a client and consumed by a service.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* `from`, `method` and `args` are always present; `metadata` is absent — not
|
|
31
|
+
* `null` — when the caller passed none. The whole structure is JSON-serialized, so
|
|
32
|
+
* any `undefined` inside it is dropped in transit.
|
|
28
33
|
*/
|
|
29
34
|
export interface IMQRPCRequest extends JsonObject {
|
|
35
|
+
/**
|
|
36
|
+
* Name of the caller's own queue — the call's reply address.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The service publishes the response to exactly this queue, so it is not a
|
|
40
|
+
* human-readable client label. Rewriting it in a `beforeCall` hook redirects
|
|
41
|
+
* the reply.
|
|
42
|
+
*/
|
|
30
43
|
from: string;
|
|
44
|
+
/**
|
|
45
|
+
* Name of the service method to invoke.
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* Not supplied by the caller: the {@link remote} decorator appends it to the
|
|
49
|
+
* argument list and the client pops it back off. The service uses it for the
|
|
50
|
+
* method lookup and to authorize the call against its exposed description.
|
|
51
|
+
*/
|
|
31
52
|
method: string;
|
|
53
|
+
/**
|
|
54
|
+
* Positional arguments for the method, applied in order.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* The client removes the trailing {@link IMQMetadata} and {@link IMQDelay}
|
|
58
|
+
* slots and, on a delayed call, any trailing `undefined` placeholders — so this
|
|
59
|
+
* array carries only real arguments. Its length is checked against the exposed
|
|
60
|
+
* method description before the method runs.
|
|
61
|
+
*/
|
|
32
62
|
args: any[];
|
|
63
|
+
/**
|
|
64
|
+
* Optional metadata attached by the caller.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Absent rather than `null` when none was passed. Service code should read it
|
|
68
|
+
* through `currentMetadata()`; the value there is the JSON round-trip of the
|
|
69
|
+
* caller's bag, so it is a plain object, not an {@link IMQMetadata} instance.
|
|
70
|
+
*/
|
|
33
71
|
metadata?: IMQMetadata;
|
|
34
72
|
}
|
package/src/IMQRPCResponse.d.ts
CHANGED
|
@@ -28,8 +28,42 @@ import { type IMQRPCError, type IMQRPCRequest } from './index.js';
|
|
|
28
28
|
* requests.
|
|
29
29
|
*/
|
|
30
30
|
export interface IMQRPCResponse extends JsonObject {
|
|
31
|
+
/**
|
|
32
|
+
* Correlation identifier: the queue-assigned message id of the request this
|
|
33
|
+
* response answers.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* This is not an address. The client matches it against its table of
|
|
37
|
+
* pending calls, so it must be echoed back exactly. The response is delivered
|
|
38
|
+
* to {@link IMQRPCRequest.from} instead.
|
|
39
|
+
*/
|
|
31
40
|
to: string;
|
|
41
|
+
/**
|
|
42
|
+
* The value the service method returned, as JSON.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Despite the `JsonObject` annotation this may be any JSON value — primitive,
|
|
46
|
+
* array or object — and the key is absent from the delivered message when
|
|
47
|
+
* the method returned nothing. It is `null` on the initial response skeleton
|
|
48
|
+
* and stays `null` when the call failed.
|
|
49
|
+
*/
|
|
32
50
|
data: JsonObject | null;
|
|
51
|
+
/**
|
|
52
|
+
* `null` on success, otherwise the failure descriptor.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* The client checks this field first and rejects the call with it, ignoring
|
|
56
|
+
* {@link IMQRPCResponse.data} — so the two are effectively mutually exclusive.
|
|
57
|
+
*/
|
|
33
58
|
error: IMQRPCError | null;
|
|
59
|
+
/**
|
|
60
|
+
* The originating request, echoed back in full — method, arguments and
|
|
61
|
+
* metadata included.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Always present: the client reads `request.method` when it cannot match the
|
|
65
|
+
* response to a pending call, in order to re-emit it as an event. Note that
|
|
66
|
+
* this round-trips every argument value back to the caller.
|
|
67
|
+
*/
|
|
34
68
|
request: IMQRPCRequest;
|
|
35
69
|
}
|
|
@@ -10,16 +10,13 @@ import { type IMQRPCRequest } from './IMQRPCRequest.js';
|
|
|
10
10
|
* the call and automatically removed afterwards, which keeps concurrent
|
|
11
11
|
* requests isolated from one another.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @return {T}
|
|
13
|
+
* @param request - the request to bind for this execution
|
|
14
|
+
* @param fn - the work to run within the bound context
|
|
16
15
|
*/
|
|
17
16
|
export declare function runWithRequest<T>(request: IMQRPCRequest, fn: () => T): T;
|
|
18
17
|
/**
|
|
19
18
|
* Returns the metadata of the in-flight IMQ request for the current async
|
|
20
19
|
* execution, if any. Returns `undefined` outside of a `runWithRequest()` scope.
|
|
21
20
|
* The transport carries metadata as an opaque bag; callers interpret its fields.
|
|
22
|
-
*
|
|
23
|
-
* @return {IMQMetadata | undefined}
|
|
24
21
|
*/
|
|
25
22
|
export declare function currentMetadata(): IMQMetadata | undefined;
|
package/src/IMQRequestContext.js
CHANGED
|
@@ -35,9 +35,8 @@ const storage = new AsyncLocalStorage();
|
|
|
35
35
|
* the call and automatically removed afterwards, which keeps concurrent
|
|
36
36
|
* requests isolated from one another.
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @return {T}
|
|
38
|
+
* @param request - the request to bind for this execution
|
|
39
|
+
* @param fn - the work to run within the bound context
|
|
41
40
|
*/
|
|
42
41
|
export function runWithRequest(request, fn) {
|
|
43
42
|
return storage.run(request, fn);
|
|
@@ -46,8 +45,6 @@ export function runWithRequest(request, fn) {
|
|
|
46
45
|
* Returns the metadata of the in-flight IMQ request for the current async
|
|
47
46
|
* execution, if any. Returns `undefined` outside of a `runWithRequest()` scope.
|
|
48
47
|
* The transport carries metadata as an opaque bag; callers interpret its fields.
|
|
49
|
-
*
|
|
50
|
-
* @return {IMQMetadata | undefined}
|
|
51
48
|
*/
|
|
52
49
|
export function currentMetadata() {
|
|
53
50
|
return storage.getStore()?.metadata;
|