@imqueue/core 3.2.5 → 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/.claude/settings.local.json +9 -0
- package/index.d.ts +70 -9
- package/index.js +70 -9
- package/package.json +1 -5
- package/src/ClusterManager.d.ts +81 -2
- package/src/ClusterManager.js +51 -2
- package/src/ClusteredRedisQueue.d.ts +361 -67
- package/src/ClusteredRedisQueue.js +340 -67
- package/src/IMQMode.d.ts +24 -0
- package/src/IMQMode.js +24 -0
- package/src/IMessageQueue.d.ts +385 -132
- package/src/RedisQueue.d.ts +284 -158
- package/src/RedisQueue.js +282 -163
- package/src/UDPClusterManager.d.ts +149 -33
- package/src/UDPClusterManager.js +74 -9
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/profile.d.ts +170 -31
- package/src/profile.js +138 -32
- package/src/redis.d.ts +14 -4
- package/src/redis.js +1 -1
package/src/profile.d.ts
CHANGED
|
@@ -22,58 +22,141 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
import { type ILogger } from './index.js';
|
|
25
|
+
/**
|
|
26
|
+
* Logger method to which profiling output is dispatched. Each value is the
|
|
27
|
+
* literal name of the corresponding {@link ILogger} method, so the level is used
|
|
28
|
+
* as a property lookup on the logger.
|
|
29
|
+
*/
|
|
25
30
|
export declare enum LogLevel {
|
|
31
|
+
/**
|
|
32
|
+
* Dispatches to {@link ILogger.log}.
|
|
33
|
+
*/
|
|
26
34
|
LOG = "log",
|
|
35
|
+
/**
|
|
36
|
+
* Dispatches to {@link ILogger.info}. This is the default level.
|
|
37
|
+
*/
|
|
27
38
|
INFO = "info",
|
|
39
|
+
/**
|
|
40
|
+
* Dispatches to {@link ILogger.warn}.
|
|
41
|
+
*/
|
|
28
42
|
WARN = "warn",
|
|
43
|
+
/**
|
|
44
|
+
* Dispatches to {@link ILogger.error}.
|
|
45
|
+
*/
|
|
29
46
|
ERROR = "error"
|
|
30
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Options accepted by the {@link profile} decorator.
|
|
50
|
+
*
|
|
51
|
+
* Every field is optional; omitted fields fall back to the {@link IMQ_LOG_TIME},
|
|
52
|
+
* {@link IMQ_LOG_ARGS} and {@link IMQ_LOG_LEVEL} environment defaults.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* `enableDebugTime` and `enableDebugArgs` override the environment defaults only
|
|
56
|
+
* when passed as real booleans — any other value is ignored and the environment
|
|
57
|
+
* default applies.
|
|
58
|
+
*/
|
|
31
59
|
export interface ProfileDecoratorOptions {
|
|
32
60
|
/**
|
|
33
|
-
* Turns on/off execution time debugging
|
|
61
|
+
* Turns on/off execution time debugging, overriding {@link IMQ_LOG_TIME}.
|
|
34
62
|
*/
|
|
35
63
|
enableDebugTime?: boolean;
|
|
36
64
|
/**
|
|
37
|
-
* Turns on/off arguments debugging
|
|
65
|
+
* Turns on/off arguments debugging, overriding {@link IMQ_LOG_ARGS}.
|
|
38
66
|
*/
|
|
39
67
|
enableDebugArgs?: boolean;
|
|
40
68
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
69
|
+
* Logger method used for the profiling output — one of `log`, `info`, `warn`
|
|
70
|
+
* or `error`. Overrides {@link IMQ_LOG_LEVEL}, which itself defaults to
|
|
71
|
+
* `info`.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* An unrecognized level resolves to `info` rather than falling back to the
|
|
75
|
+
* environment value.
|
|
43
76
|
*/
|
|
44
77
|
logLevel?: LogLevel;
|
|
45
78
|
}
|
|
46
79
|
/**
|
|
47
|
-
*
|
|
80
|
+
* Normalizes an arbitrary value into a {@link LogLevel}.
|
|
48
81
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @returns
|
|
82
|
+
* @param level - the value to validate
|
|
83
|
+
* @returns `level` unchanged when it is one of `log`, `info`, `warn` or `error`;
|
|
84
|
+
* otherwise {@link LogLevel.INFO}
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* Never throws — `null`, `undefined` and unrelated types all resolve to
|
|
88
|
+
* {@link LogLevel.INFO}, which makes this the safe way to sanitize an untrusted
|
|
89
|
+
* level string.
|
|
51
90
|
*/
|
|
52
91
|
export declare function verifyLogLevel(level: unknown): LogLevel;
|
|
92
|
+
/**
|
|
93
|
+
* Default logger method for profiling output, from the `IMQ_LOG_LEVEL`
|
|
94
|
+
* environment variable.
|
|
95
|
+
*
|
|
96
|
+
* Accepts `log`, `info`, `warn` or `error`; any other or missing value resolves
|
|
97
|
+
* to `info` without warning.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* Read once when the module is first imported, so later changes to
|
|
101
|
+
* `process.env` have no effect. Individual decorators override it via
|
|
102
|
+
* {@link ProfileDecoratorOptions.logLevel}.
|
|
103
|
+
*/
|
|
53
104
|
export declare const IMQ_LOG_LEVEL: LogLevel;
|
|
105
|
+
/**
|
|
106
|
+
* Units in which profiled execution time can be rendered.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* Used as the declared type of {@link IMQ_LOG_TIME_FORMAT}. Note that the
|
|
110
|
+
* environment value is cast rather than validated, so an out-of-range string is
|
|
111
|
+
* possible at runtime and behaves as `microseconds`.
|
|
112
|
+
*/
|
|
54
113
|
export type AllowedTimeFormat = 'microseconds' | 'milliseconds' | 'seconds';
|
|
55
114
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
115
|
+
* Whether execution-time profiling is on by default, from the `IMQ_LOG_TIME`
|
|
116
|
+
* environment variable.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* The value is coerced numerically: any non-zero number enables it, while `0`, an
|
|
120
|
+
* empty value, or any non-numeric string — including `true` — disables it. Use
|
|
121
|
+
* `IMQ_LOG_TIME=1`.
|
|
58
122
|
*
|
|
59
|
-
*
|
|
123
|
+
* Read once when the module is first imported, so later changes to `process.env`
|
|
124
|
+
* are ignored. Individual decorators override this via
|
|
125
|
+
* {@link ProfileDecoratorOptions.enableDebugTime}.
|
|
60
126
|
*/
|
|
61
127
|
export declare const IMQ_LOG_TIME: boolean;
|
|
62
128
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
129
|
+
* Whether call-argument profiling is on by default, from the `IMQ_LOG_ARGS`
|
|
130
|
+
* environment variable.
|
|
65
131
|
*
|
|
66
|
-
* @
|
|
132
|
+
* @remarks
|
|
133
|
+
* Coerced numerically exactly as {@link IMQ_LOG_TIME} is, with the same caveat
|
|
134
|
+
* that `IMQ_LOG_ARGS=true` evaluates to disabled — use `IMQ_LOG_ARGS=1`.
|
|
135
|
+
*
|
|
136
|
+
* Read once when the module is first imported. Individual decorators override
|
|
137
|
+
* this via {@link ProfileDecoratorOptions.enableDebugArgs}.
|
|
67
138
|
*/
|
|
68
139
|
export declare const IMQ_LOG_ARGS: boolean;
|
|
69
140
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
141
|
+
* Unit used when rendering profiled execution time, from the
|
|
142
|
+
* `IMQ_LOG_TIME_FORMAT` environment variable. Accepts `microseconds`,
|
|
143
|
+
* `milliseconds` or `seconds`, and defaults to `microseconds`.
|
|
144
|
+
*
|
|
145
|
+
* @remarks
|
|
146
|
+
* The value is not validated, so any unrecognized string falls back to
|
|
147
|
+
* `microseconds` silently. Read once when the module is first imported and
|
|
148
|
+
* applied globally — there is no per-decorator or per-call override.
|
|
73
149
|
*
|
|
74
|
-
*
|
|
150
|
+
* Output is rendered as `<n> μs` (unrounded), `<n.nnn> ms`, or `<n.nnn> sec`.
|
|
75
151
|
*/
|
|
76
152
|
export declare const IMQ_LOG_TIME_FORMAT: AllowedTimeFormat;
|
|
153
|
+
/**
|
|
154
|
+
* Fully-resolved description of a single profiled call, as passed to
|
|
155
|
+
* {@link logDebugInfo}.
|
|
156
|
+
*
|
|
157
|
+
* Normally constructed by the {@link profile} decorator; supply it directly only
|
|
158
|
+
* to emit profiling output by hand. Every field except `logger` is required.
|
|
159
|
+
*/
|
|
77
160
|
export interface DebugInfoOptions {
|
|
78
161
|
/**
|
|
79
162
|
* Enable or disable execution time debugging
|
|
@@ -96,7 +179,13 @@ export interface DebugInfoOptions {
|
|
|
96
179
|
*/
|
|
97
180
|
methodName: string;
|
|
98
181
|
/**
|
|
99
|
-
*
|
|
182
|
+
* Nanosecond-resolution start reading, as returned by
|
|
183
|
+
* `process.hrtime.bigint()`.
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* A `number` is accepted but must be an integral nanosecond count: a
|
|
187
|
+
* non-integer throws a `RangeError`, and a millisecond timestamp such as
|
|
188
|
+
* `Date.now()` produces a meaningless duration.
|
|
100
189
|
*/
|
|
101
190
|
start: bigint | number;
|
|
102
191
|
/**
|
|
@@ -109,36 +198,86 @@ export interface DebugInfoOptions {
|
|
|
109
198
|
logLevel: LogLevel;
|
|
110
199
|
}
|
|
111
200
|
/**
|
|
112
|
-
*
|
|
201
|
+
* Emits the profiling output for a single call: the elapsed time computed from
|
|
202
|
+
* `input.start`, and/or the call arguments serialized as indented JSON.
|
|
203
|
+
*
|
|
204
|
+
* @param input - fully-resolved description of the profiled call
|
|
113
205
|
*
|
|
114
|
-
* @
|
|
206
|
+
* @remarks
|
|
207
|
+
* Nothing is written when no logger is supplied, or when the logger does not
|
|
208
|
+
* implement the requested level — the work is still done, silently.
|
|
209
|
+
*
|
|
210
|
+
* Circular and merely repeated object references are omitted from the argument
|
|
211
|
+
* dump. If the arguments cannot be serialized at all (a `BigInt`, for example),
|
|
212
|
+
* the failure is reported through `logger.error` regardless of the configured
|
|
213
|
+
* level and the arguments are logged as an empty string.
|
|
115
214
|
*/
|
|
116
|
-
export declare function logDebugInfo(
|
|
215
|
+
export declare function logDebugInfo(input: DebugInfoOptions): void;
|
|
117
216
|
/**
|
|
118
|
-
*
|
|
217
|
+
* Wraps a class method so that its execution time and/or its call arguments are
|
|
218
|
+
* logged through the `logger` property of the decorated instance.
|
|
219
|
+
*
|
|
220
|
+
* @param options - profiling options; omitted fields fall back to the
|
|
221
|
+
* {@link IMQ_LOG_TIME}, {@link IMQ_LOG_ARGS} and {@link IMQ_LOG_LEVEL}
|
|
222
|
+
* environment defaults
|
|
223
|
+
* @returns a dual-mode method decorator. Under standard (TC39) decorators it is
|
|
224
|
+
* called as `(method, context)` and returns the replacement method;
|
|
225
|
+
* under legacy decorators it is called as
|
|
226
|
+
* `(target, propertyKey, descriptor)`, replaces `descriptor.value` and
|
|
227
|
+
* returns that same descriptor object. Only method decoration is
|
|
228
|
+
* supported.
|
|
119
229
|
*
|
|
120
230
|
* @example
|
|
121
|
-
*
|
|
231
|
+
* ```typescript
|
|
122
232
|
* import { profile } from '@imqueue/core';
|
|
123
233
|
*
|
|
124
234
|
* class MyClass {
|
|
235
|
+
* // the decorator logs through this property only;
|
|
236
|
+
* // without a logger nothing is ever written
|
|
237
|
+
* public logger = console;
|
|
125
238
|
*
|
|
126
|
-
*
|
|
239
|
+
* // always profiled, whatever IMQ_LOG_TIME / IMQ_LOG_ARGS say
|
|
240
|
+
* @profile({ enableDebugTime: true, enableDebugArgs: true })
|
|
127
241
|
* public myMethod() {
|
|
128
242
|
* // ...
|
|
129
243
|
* }
|
|
130
244
|
*
|
|
131
|
-
*
|
|
245
|
+
* // profiled only when IMQ_LOG_TIME=1 and/or IMQ_LOG_ARGS=1
|
|
246
|
+
* @profile()
|
|
132
247
|
* private innerMethod() {
|
|
133
248
|
* // ...
|
|
134
249
|
* }
|
|
135
250
|
* }
|
|
136
|
-
*
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @remarks
|
|
254
|
+
* Output is written through the decorated instance's `logger` property (any
|
|
255
|
+
* {@link ILogger}). If the instance has no `logger`, or its logger lacks the
|
|
256
|
+
* selected level method, profiling runs and produces no output at all — no
|
|
257
|
+
* warning is emitted. Static methods are never logged, because the logger is
|
|
258
|
+
* looked up on instances only.
|
|
259
|
+
*
|
|
260
|
+
* Async methods are handled: when the wrapped method returns a thenable, logging
|
|
261
|
+
* is deferred until it settles and the measured time covers the full
|
|
262
|
+
* asynchronous duration. The original promise is returned unchanged, so identity,
|
|
263
|
+
* chaining and rejection propagation are unaffected. A rejection is logged with
|
|
264
|
+
* the same message as a success — the error itself is neither included nor
|
|
265
|
+
* captured.
|
|
266
|
+
*
|
|
267
|
+
* The wrapper is installed unconditionally; when profiling is disabled it
|
|
268
|
+
* delegates straight to the original method. Because decoration replaces the
|
|
269
|
+
* method, its `name` becomes `"wrapper"` and its `length` becomes `0` — do not
|
|
270
|
+
* rely on the reflected name or arity of a profiled method. Whether timing and
|
|
271
|
+
* argument logging are enabled is resolved once, when the class is defined.
|
|
272
|
+
*
|
|
273
|
+
* Precedence: `enableDebugTime` and `enableDebugArgs` override the environment
|
|
274
|
+
* defaults only when passed as real booleans; any other value is ignored.
|
|
275
|
+
* `logLevel` overrides {@link IMQ_LOG_LEVEL}, but an unrecognized level resolves
|
|
276
|
+
* to `info` rather than falling back to the environment value.
|
|
137
277
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* ) => void}
|
|
278
|
+
* Under legacy decorators the supplied property descriptor is mutated in place.
|
|
279
|
+
* Only method decoration is supported: applied to anything else it either throws
|
|
280
|
+
* a `TypeError` (legacy form, no descriptor) or installs the wrapper in the wrong
|
|
281
|
+
* slot (standard form — `context.kind` is not validated).
|
|
143
282
|
*/
|
|
144
283
|
export declare function profile(options?: ProfileDecoratorOptions): any;
|
package/src/profile.js
CHANGED
|
@@ -22,18 +22,41 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
import {} from './index.js';
|
|
25
|
+
/**
|
|
26
|
+
* Logger method to which profiling output is dispatched. Each value is the
|
|
27
|
+
* literal name of the corresponding {@link ILogger} method, so the level is used
|
|
28
|
+
* as a property lookup on the logger.
|
|
29
|
+
*/
|
|
25
30
|
export var LogLevel;
|
|
26
31
|
(function (LogLevel) {
|
|
32
|
+
/**
|
|
33
|
+
* Dispatches to {@link ILogger.log}.
|
|
34
|
+
*/
|
|
27
35
|
LogLevel["LOG"] = "log";
|
|
36
|
+
/**
|
|
37
|
+
* Dispatches to {@link ILogger.info}. This is the default level.
|
|
38
|
+
*/
|
|
28
39
|
LogLevel["INFO"] = "info";
|
|
40
|
+
/**
|
|
41
|
+
* Dispatches to {@link ILogger.warn}.
|
|
42
|
+
*/
|
|
29
43
|
LogLevel["WARN"] = "warn";
|
|
44
|
+
/**
|
|
45
|
+
* Dispatches to {@link ILogger.error}.
|
|
46
|
+
*/
|
|
30
47
|
LogLevel["ERROR"] = "error";
|
|
31
48
|
})(LogLevel || (LogLevel = {}));
|
|
32
49
|
/**
|
|
33
|
-
*
|
|
50
|
+
* Normalizes an arbitrary value into a {@link LogLevel}.
|
|
51
|
+
*
|
|
52
|
+
* @param level - the value to validate
|
|
53
|
+
* @returns `level` unchanged when it is one of `log`, `info`, `warn` or `error`;
|
|
54
|
+
* otherwise {@link LogLevel.INFO}
|
|
34
55
|
*
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* Never throws — `null`, `undefined` and unrelated types all resolve to
|
|
58
|
+
* {@link LogLevel.INFO}, which makes this the safe way to sanitize an untrusted
|
|
59
|
+
* level string.
|
|
37
60
|
*/
|
|
38
61
|
export function verifyLogLevel(level) {
|
|
39
62
|
switch (level) {
|
|
@@ -46,38 +69,78 @@ export function verifyLogLevel(level) {
|
|
|
46
69
|
return LogLevel.INFO;
|
|
47
70
|
}
|
|
48
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Default logger method for profiling output, from the `IMQ_LOG_LEVEL`
|
|
74
|
+
* environment variable.
|
|
75
|
+
*
|
|
76
|
+
* Accepts `log`, `info`, `warn` or `error`; any other or missing value resolves
|
|
77
|
+
* to `info` without warning.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Read once when the module is first imported, so later changes to
|
|
81
|
+
* `process.env` have no effect. Individual decorators override it via
|
|
82
|
+
* {@link ProfileDecoratorOptions.logLevel}.
|
|
83
|
+
*/
|
|
49
84
|
export const IMQ_LOG_LEVEL = verifyLogLevel(process.env.IMQ_LOG_LEVEL);
|
|
50
85
|
const DEFAULT_OPTIONS = {
|
|
51
86
|
logLevel: IMQ_LOG_LEVEL,
|
|
52
87
|
};
|
|
53
88
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
89
|
+
* Whether execution-time profiling is on by default, from the `IMQ_LOG_TIME`
|
|
90
|
+
* environment variable.
|
|
56
91
|
*
|
|
57
|
-
* @
|
|
92
|
+
* @remarks
|
|
93
|
+
* The value is coerced numerically: any non-zero number enables it, while `0`, an
|
|
94
|
+
* empty value, or any non-numeric string — including `true` — disables it. Use
|
|
95
|
+
* `IMQ_LOG_TIME=1`.
|
|
96
|
+
*
|
|
97
|
+
* Read once when the module is first imported, so later changes to `process.env`
|
|
98
|
+
* are ignored. Individual decorators override this via
|
|
99
|
+
* {@link ProfileDecoratorOptions.enableDebugTime}.
|
|
58
100
|
*/
|
|
59
101
|
export const IMQ_LOG_TIME = !!+(process.env.IMQ_LOG_TIME || 0);
|
|
60
102
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
103
|
+
* Whether call-argument profiling is on by default, from the `IMQ_LOG_ARGS`
|
|
104
|
+
* environment variable.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* Coerced numerically exactly as {@link IMQ_LOG_TIME} is, with the same caveat
|
|
108
|
+
* that `IMQ_LOG_ARGS=true` evaluates to disabled — use `IMQ_LOG_ARGS=1`.
|
|
63
109
|
*
|
|
64
|
-
*
|
|
110
|
+
* Read once when the module is first imported. Individual decorators override
|
|
111
|
+
* this via {@link ProfileDecoratorOptions.enableDebugArgs}.
|
|
65
112
|
*/
|
|
66
113
|
export const IMQ_LOG_ARGS = !!+(process.env.IMQ_LOG_ARGS || 0);
|
|
67
114
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
115
|
+
* Unit used when rendering profiled execution time, from the
|
|
116
|
+
* `IMQ_LOG_TIME_FORMAT` environment variable. Accepts `microseconds`,
|
|
117
|
+
* `milliseconds` or `seconds`, and defaults to `microseconds`.
|
|
71
118
|
*
|
|
72
|
-
* @
|
|
119
|
+
* @remarks
|
|
120
|
+
* The value is not validated, so any unrecognized string falls back to
|
|
121
|
+
* `microseconds` silently. Read once when the module is first imported and
|
|
122
|
+
* applied globally — there is no per-decorator or per-call override.
|
|
123
|
+
*
|
|
124
|
+
* Output is rendered as `<n> μs` (unrounded), `<n.nnn> ms`, or `<n.nnn> sec`.
|
|
73
125
|
*/
|
|
74
126
|
export const IMQ_LOG_TIME_FORMAT = process.env.IMQ_LOG_TIME_FORMAT || 'microseconds';
|
|
75
127
|
/**
|
|
76
|
-
*
|
|
128
|
+
* Emits the profiling output for a single call: the elapsed time computed from
|
|
129
|
+
* `input.start`, and/or the call arguments serialized as indented JSON.
|
|
130
|
+
*
|
|
131
|
+
* @param input - fully-resolved description of the profiled call
|
|
77
132
|
*
|
|
78
|
-
* @
|
|
133
|
+
* @remarks
|
|
134
|
+
* Nothing is written when no logger is supplied, or when the logger does not
|
|
135
|
+
* implement the requested level — the work is still done, silently.
|
|
136
|
+
*
|
|
137
|
+
* Circular and merely repeated object references are omitted from the argument
|
|
138
|
+
* dump. If the arguments cannot be serialized at all (a `BigInt`, for example),
|
|
139
|
+
* the failure is reported through `logger.error` regardless of the configured
|
|
140
|
+
* level and the arguments are logged as an empty string.
|
|
79
141
|
*/
|
|
80
|
-
export function logDebugInfo(
|
|
142
|
+
export function logDebugInfo(input) {
|
|
143
|
+
const { debugTime, debugArgs, className, args, methodName, start, logger, logLevel, } = input;
|
|
81
144
|
const log = logger && typeof logger[logLevel] === 'function'
|
|
82
145
|
? logger[logLevel].bind(logger)
|
|
83
146
|
: undefined;
|
|
@@ -130,8 +193,9 @@ export function logDebugInfo({ debugTime, debugArgs, className, args, methodName
|
|
|
130
193
|
* Resolves the class name of a decorated call target — the class itself for
|
|
131
194
|
* a static call, or the instance's constructor for an instance call.
|
|
132
195
|
*
|
|
133
|
-
* @param
|
|
134
|
-
* @returns
|
|
196
|
+
* @param target - the decorated call target
|
|
197
|
+
* @returns the resolved class name, or an empty string when it cannot be
|
|
198
|
+
* determined
|
|
135
199
|
*/
|
|
136
200
|
function resolveClassName(target) {
|
|
137
201
|
if (typeof target === 'function') {
|
|
@@ -146,8 +210,10 @@ function resolveClassName(target) {
|
|
|
146
210
|
/**
|
|
147
211
|
* Extracts the logger instance from a decorated target, if present.
|
|
148
212
|
*
|
|
149
|
-
* @param
|
|
150
|
-
* @returns
|
|
213
|
+
* @param target - the decorated target object
|
|
214
|
+
* @returns the target's logger, or `undefined` when it carries none — including
|
|
215
|
+
* for a static call, where the target is a function rather than an
|
|
216
|
+
* instance
|
|
151
217
|
*/
|
|
152
218
|
function resolveLogger(target) {
|
|
153
219
|
if (typeof target === 'object' && target !== null) {
|
|
@@ -161,8 +227,8 @@ function resolveLogger(target) {
|
|
|
161
227
|
* to PromiseLike<unknown> — this keeps the guard usable on a generic return
|
|
162
228
|
* value under stricter/older compiler configurations used by consumers.
|
|
163
229
|
*
|
|
164
|
-
* @param
|
|
165
|
-
* @returns
|
|
230
|
+
* @param value - the value to test
|
|
231
|
+
* @returns true when the value exposes a callable `then` method
|
|
166
232
|
*/
|
|
167
233
|
function isThenable(value) {
|
|
168
234
|
return ((typeof value === 'object' || typeof value === 'function') &&
|
|
@@ -170,31 +236,71 @@ function isThenable(value) {
|
|
|
170
236
|
typeof value.then === 'function');
|
|
171
237
|
}
|
|
172
238
|
/**
|
|
173
|
-
*
|
|
239
|
+
* Wraps a class method so that its execution time and/or its call arguments are
|
|
240
|
+
* logged through the `logger` property of the decorated instance.
|
|
241
|
+
*
|
|
242
|
+
* @param options - profiling options; omitted fields fall back to the
|
|
243
|
+
* {@link IMQ_LOG_TIME}, {@link IMQ_LOG_ARGS} and {@link IMQ_LOG_LEVEL}
|
|
244
|
+
* environment defaults
|
|
245
|
+
* @returns a dual-mode method decorator. Under standard (TC39) decorators it is
|
|
246
|
+
* called as `(method, context)` and returns the replacement method;
|
|
247
|
+
* under legacy decorators it is called as
|
|
248
|
+
* `(target, propertyKey, descriptor)`, replaces `descriptor.value` and
|
|
249
|
+
* returns that same descriptor object. Only method decoration is
|
|
250
|
+
* supported.
|
|
174
251
|
*
|
|
175
252
|
* @example
|
|
176
|
-
*
|
|
253
|
+
* ```typescript
|
|
177
254
|
* import { profile } from '@imqueue/core';
|
|
178
255
|
*
|
|
179
256
|
* class MyClass {
|
|
257
|
+
* // the decorator logs through this property only;
|
|
258
|
+
* // without a logger nothing is ever written
|
|
259
|
+
* public logger = console;
|
|
180
260
|
*
|
|
181
|
-
*
|
|
261
|
+
* // always profiled, whatever IMQ_LOG_TIME / IMQ_LOG_ARGS say
|
|
262
|
+
* @profile({ enableDebugTime: true, enableDebugArgs: true })
|
|
182
263
|
* public myMethod() {
|
|
183
264
|
* // ...
|
|
184
265
|
* }
|
|
185
266
|
*
|
|
186
|
-
*
|
|
267
|
+
* // profiled only when IMQ_LOG_TIME=1 and/or IMQ_LOG_ARGS=1
|
|
268
|
+
* @profile()
|
|
187
269
|
* private innerMethod() {
|
|
188
270
|
* // ...
|
|
189
271
|
* }
|
|
190
272
|
* }
|
|
191
|
-
*
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @remarks
|
|
276
|
+
* Output is written through the decorated instance's `logger` property (any
|
|
277
|
+
* {@link ILogger}). If the instance has no `logger`, or its logger lacks the
|
|
278
|
+
* selected level method, profiling runs and produces no output at all — no
|
|
279
|
+
* warning is emitted. Static methods are never logged, because the logger is
|
|
280
|
+
* looked up on instances only.
|
|
281
|
+
*
|
|
282
|
+
* Async methods are handled: when the wrapped method returns a thenable, logging
|
|
283
|
+
* is deferred until it settles and the measured time covers the full
|
|
284
|
+
* asynchronous duration. The original promise is returned unchanged, so identity,
|
|
285
|
+
* chaining and rejection propagation are unaffected. A rejection is logged with
|
|
286
|
+
* the same message as a success — the error itself is neither included nor
|
|
287
|
+
* captured.
|
|
288
|
+
*
|
|
289
|
+
* The wrapper is installed unconditionally; when profiling is disabled it
|
|
290
|
+
* delegates straight to the original method. Because decoration replaces the
|
|
291
|
+
* method, its `name` becomes `"wrapper"` and its `length` becomes `0` — do not
|
|
292
|
+
* rely on the reflected name or arity of a profiled method. Whether timing and
|
|
293
|
+
* argument logging are enabled is resolved once, when the class is defined.
|
|
294
|
+
*
|
|
295
|
+
* Precedence: `enableDebugTime` and `enableDebugArgs` override the environment
|
|
296
|
+
* defaults only when passed as real booleans; any other value is ignored.
|
|
297
|
+
* `logLevel` overrides {@link IMQ_LOG_LEVEL}, but an unrecognized level resolves
|
|
298
|
+
* to `info` rather than falling back to the environment value.
|
|
192
299
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* ) => void}
|
|
300
|
+
* Under legacy decorators the supplied property descriptor is mutated in place.
|
|
301
|
+
* Only method decoration is supported: applied to anything else it either throws
|
|
302
|
+
* a `TypeError` (legacy form, no descriptor) or installs the wrapper in the wrong
|
|
303
|
+
* slot (standard form — `context.kind` is not validated).
|
|
198
304
|
*/
|
|
199
305
|
export function profile(options) {
|
|
200
306
|
options = Object.assign({}, DEFAULT_OPTIONS, options);
|
package/src/redis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
2
|
+
* Redis client re-export and the internal client type augmentation
|
|
3
3
|
*
|
|
4
4
|
* I'm Queue Software Project
|
|
5
5
|
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
|
|
@@ -23,12 +23,22 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { Redis } from 'ioredis';
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* The ioredis `Redis` client type augmented with the two internal bookkeeping
|
|
27
|
+
* flags imq stamps onto the connections it creates. Not intended for use as an
|
|
28
|
+
* option or parameter type by consumers.
|
|
29
29
|
*/
|
|
30
30
|
export interface IRedisClient extends Redis {
|
|
31
|
+
/**
|
|
32
|
+
* Internal flag marking a watcher connection whose keyspace subscriptions
|
|
33
|
+
* and maintenance interval have already been installed, so watcher setup
|
|
34
|
+
* runs at most once per connection. Not part of the supported API.
|
|
35
|
+
*/
|
|
31
36
|
__ready__?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Internal marker stamped on every Redis connection created by the queue,
|
|
39
|
+
* identifying it as imq-owned. Currently written but not read by the
|
|
40
|
+
* framework. Not part of the supported API.
|
|
41
|
+
*/
|
|
32
42
|
__imq?: boolean;
|
|
33
43
|
}
|
|
34
44
|
export { Redis };
|
package/src/redis.js
CHANGED