@imqueue/rpc 2.1.0 → 3.0.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.
- package/.github/workflows/build.yml +49 -5
- package/.oxfmtrc.json +9 -0
- package/.oxlintrc.json +37 -0
- package/README.md +68 -0
- package/package.json +21 -58
- package/scripts/strip-comment-coverage.mjs +464 -0
- package/src/IMQCache.d.ts +10 -9
- package/src/IMQCache.js +16 -22
- package/src/IMQClient.d.ts +21 -16
- package/src/IMQClient.js +407 -271
- package/src/IMQDelay.d.ts +14 -0
- package/src/IMQDelay.js +26 -5
- package/src/IMQLock.d.ts +17 -15
- package/src/IMQLock.js +36 -36
- package/src/IMQMetadata.d.ts +8 -0
- package/src/IMQMetadata.js +8 -0
- package/src/IMQRPCDescription.d.ts +2 -2
- package/src/IMQRPCDescription.js +2 -2
- package/src/IMQRPCError.d.ts +7 -7
- package/src/IMQRPCError.js +7 -8
- package/src/IMQRPCOptions.d.ts +27 -3
- package/src/IMQRPCOptions.js +17 -3
- package/src/IMQRPCRequest.d.ts +1 -1
- package/src/IMQRPCResponse.d.ts +1 -1
- package/src/IMQRequestContext.js +1 -2
- package/src/IMQService.d.ts +3 -4
- package/src/IMQService.js +302 -220
- package/src/cache/ICache.d.ts +53 -0
- package/src/cache/RedisCache.d.ts +30 -25
- package/src/cache/RedisCache.js +104 -61
- package/src/decorators/cache.d.ts +12 -0
- package/src/decorators/cache.js +56 -41
- package/src/decorators/classType.d.ts +43 -0
- package/src/decorators/classType.js +83 -0
- package/src/decorators/expose.d.ts +5 -31
- package/src/decorators/expose.js +118 -134
- package/src/decorators/index.d.ts +2 -0
- package/src/decorators/index.js +4 -0
- package/src/decorators/indexed.d.ts +23 -0
- package/src/decorators/indexed.js +22 -13
- package/src/decorators/lock.d.ts +10 -11
- package/src/decorators/lock.js +63 -56
- package/src/decorators/logged.d.ts +11 -9
- package/src/decorators/logged.js +47 -40
- package/src/decorators/metadata.d.ts +24 -0
- package/src/decorators/metadata.js +45 -0
- package/src/decorators/property.d.ts +7 -57
- package/src/decorators/property.js +112 -83
- package/src/decorators/remote.d.ts +7 -7
- package/src/decorators/remote.js +19 -13
- package/src/helpers/fs.d.ts +13 -13
- package/src/helpers/fs.js +19 -19
- package/src/helpers/os-uuid.d.ts +2 -1
- package/src/helpers/os-uuid.js +86 -3
- package/src/helpers/pid.d.ts +19 -9
- package/src/helpers/pid.js +33 -33
- package/src/helpers/signature.d.ts +9 -7
- package/src/helpers/signature.js +80 -10
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -1
- package/tsconfig.json +18 -14
- package/typedoc.json +19 -0
package/src/IMQDelay.d.ts
CHANGED
|
@@ -21,9 +21,23 @@
|
|
|
21
21
|
* purchase a proprietary commercial license. Please contact us at
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* Represents a delay expressed as a numeric timer value in a given time unit.
|
|
26
|
+
* Used to defer IMQ request processing.
|
|
27
|
+
*/
|
|
24
28
|
export declare class IMQDelay {
|
|
25
29
|
timer: number;
|
|
26
30
|
unit: 'ms' | 's' | 'm' | 'h' | 'd';
|
|
31
|
+
/**
|
|
32
|
+
* Returns this delay converted to milliseconds.
|
|
33
|
+
*
|
|
34
|
+
* @return {number}
|
|
35
|
+
*/
|
|
27
36
|
get ms(): number;
|
|
37
|
+
/**
|
|
38
|
+
* @param {number} timer - delay value expressed in the given unit
|
|
39
|
+
* @param {'ms' | 's' | 'm' | 'h' | 'd'} unit - time unit of the timer
|
|
40
|
+
* value, defaults to 'ms'
|
|
41
|
+
*/
|
|
28
42
|
constructor(timer: number, unit?: 'ms' | 's' | 'm' | 'h' | 'd');
|
|
29
43
|
}
|
package/src/IMQDelay.js
CHANGED
|
@@ -24,16 +24,37 @@ exports.IMQDelay = void 0;
|
|
|
24
24
|
* purchase a proprietary commercial license. Please contact us at
|
|
25
25
|
* <support@imqueue.com> to get commercial licensing options.
|
|
26
26
|
*/
|
|
27
|
+
/**
|
|
28
|
+
* Represents a delay expressed as a numeric timer value in a given time unit.
|
|
29
|
+
* Used to defer IMQ request processing.
|
|
30
|
+
*/
|
|
27
31
|
class IMQDelay {
|
|
32
|
+
timer;
|
|
33
|
+
unit;
|
|
34
|
+
/**
|
|
35
|
+
* Returns this delay converted to milliseconds.
|
|
36
|
+
*
|
|
37
|
+
* @return {number}
|
|
38
|
+
*/
|
|
28
39
|
get ms() {
|
|
29
40
|
switch (this.unit) {
|
|
30
|
-
case 'ms':
|
|
31
|
-
|
|
32
|
-
case '
|
|
33
|
-
|
|
34
|
-
case '
|
|
41
|
+
case 'ms':
|
|
42
|
+
return this.timer;
|
|
43
|
+
case 's':
|
|
44
|
+
return this.timer * 1000;
|
|
45
|
+
case 'm':
|
|
46
|
+
return this.timer * 60000;
|
|
47
|
+
case 'h':
|
|
48
|
+
return this.timer * 3600000;
|
|
49
|
+
case 'd':
|
|
50
|
+
return this.timer * 86400000;
|
|
35
51
|
}
|
|
36
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @param {number} timer - delay value expressed in the given unit
|
|
55
|
+
* @param {'ms' | 's' | 'm' | 'h' | 'd'} unit - time unit of the timer
|
|
56
|
+
* value, defaults to 'ms'
|
|
57
|
+
*/
|
|
37
58
|
constructor(timer, unit = 'ms') {
|
|
38
59
|
this.timer = timer;
|
|
39
60
|
this.unit = unit;
|
package/src/IMQLock.d.ts
CHANGED
|
@@ -45,11 +45,11 @@ export interface IMQLockMetadata {
|
|
|
45
45
|
* const lock: AcquiredLock<number> = await IMQLock.acquire<number>('doSomething');
|
|
46
46
|
*
|
|
47
47
|
* if (IMQLock.locked('doSomething')) {
|
|
48
|
-
* //
|
|
49
|
-
* // so it is good
|
|
48
|
+
* // skipping error handling this way can cause dead-locks,
|
|
49
|
+
* // so it is always good to wrap locked calls in try/catch!
|
|
50
50
|
* // BTW, IMQLock uses timeouts to avoid dead-locks
|
|
51
51
|
* try {
|
|
52
|
-
* // this code
|
|
52
|
+
* // this code is called only once across multiple async calls,
|
|
53
53
|
* // so all promises will be resolved with the same value
|
|
54
54
|
* const res = Math.random();
|
|
55
55
|
* IMQLock.release('doSomething', res);
|
|
@@ -85,32 +85,34 @@ export declare class IMQLock {
|
|
|
85
85
|
*/
|
|
86
86
|
static deadlockTimeout: number;
|
|
87
87
|
/**
|
|
88
|
-
* Logger used to log errors
|
|
88
|
+
* Logger used to log errors that appear during locked calls
|
|
89
89
|
*
|
|
90
90
|
* @type {ILogger}
|
|
91
91
|
*/
|
|
92
92
|
static logger: ILogger;
|
|
93
93
|
/**
|
|
94
|
-
* Acquires a lock for a given key
|
|
94
|
+
* Acquires a lock for a given key.
|
|
95
95
|
*
|
|
96
|
-
* @param {string} key
|
|
97
|
-
* @param {(...args: any[]) => any} [callback]
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
96
|
+
* @param {string} key - key to acquire the lock for
|
|
97
|
+
* @param {(...args: any[]) => any} [callback] - callback invoked on
|
|
98
|
+
* lock resolution
|
|
99
|
+
* @param {IMQLockMetadataItem} [metadata] - metadata for the locked call
|
|
100
|
+
* @returns {Promise<AcquiredLock<T>>}
|
|
100
101
|
*/
|
|
101
102
|
static acquire<T>(key: string, callback?: (...args: any[]) => any, metadata?: IMQLockMetadataItem): Promise<AcquiredLock<T>>;
|
|
102
103
|
/**
|
|
103
|
-
* Releases previously acquired lock for a given key
|
|
104
|
+
* Releases a previously acquired lock for a given key.
|
|
104
105
|
*
|
|
105
|
-
* @param {string} key
|
|
106
|
-
* @param {T} value
|
|
107
|
-
* @param {E} err
|
|
106
|
+
* @param {string} key - key to release the lock for
|
|
107
|
+
* @param {T} [value] - value to resolve pending calls with
|
|
108
|
+
* @param {E} [err] - error to reject pending calls with
|
|
109
|
+
* @returns {void}
|
|
108
110
|
*/
|
|
109
111
|
static release<T, E>(key: string, value?: T, err?: E): void;
|
|
110
112
|
/**
|
|
111
|
-
* Returns true if given key is locked, false otherwise
|
|
113
|
+
* Returns true if the given key is locked, false otherwise.
|
|
112
114
|
*
|
|
113
|
-
* @param {string} key
|
|
115
|
+
* @param {string} key - key to check the lock state for
|
|
114
116
|
* @returns {boolean}
|
|
115
117
|
*/
|
|
116
118
|
static locked(key: string): boolean;
|
package/src/IMQLock.js
CHANGED
|
@@ -13,11 +13,11 @@ exports.IMQLock = void 0;
|
|
|
13
13
|
* const lock: AcquiredLock<number> = await IMQLock.acquire<number>('doSomething');
|
|
14
14
|
*
|
|
15
15
|
* if (IMQLock.locked('doSomething')) {
|
|
16
|
-
* //
|
|
17
|
-
* // so it is good
|
|
16
|
+
* // skipping error handling this way can cause dead-locks,
|
|
17
|
+
* // so it is always good to wrap locked calls in try/catch!
|
|
18
18
|
* // BTW, IMQLock uses timeouts to avoid dead-locks
|
|
19
19
|
* try {
|
|
20
|
-
* // this code
|
|
20
|
+
* // this code is called only once across multiple async calls,
|
|
21
21
|
* // so all promises will be resolved with the same value
|
|
22
22
|
* const res = Math.random();
|
|
23
23
|
* IMQLock.release('doSomething', res);
|
|
@@ -43,13 +43,29 @@ exports.IMQLock = void 0;
|
|
|
43
43
|
* ~~~
|
|
44
44
|
*/
|
|
45
45
|
class IMQLock {
|
|
46
|
+
static acquiredLocks = {};
|
|
47
|
+
static queues = {};
|
|
48
|
+
static metadata = {};
|
|
46
49
|
/**
|
|
47
|
-
*
|
|
50
|
+
* Deadlock timeout in milliseconds
|
|
48
51
|
*
|
|
49
|
-
* @
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
* @type {number}
|
|
53
|
+
*/
|
|
54
|
+
static deadlockTimeout = 10000;
|
|
55
|
+
/**
|
|
56
|
+
* Logger used to log errors that appear during locked calls
|
|
57
|
+
*
|
|
58
|
+
* @type {ILogger}
|
|
59
|
+
*/
|
|
60
|
+
static logger = console;
|
|
61
|
+
/**
|
|
62
|
+
* Acquires a lock for a given key.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} key - key to acquire the lock for
|
|
65
|
+
* @param {(...args: any[]) => any} [callback] - callback invoked on
|
|
66
|
+
* lock resolution
|
|
67
|
+
* @param {IMQLockMetadataItem} [metadata] - metadata for the locked call
|
|
68
|
+
* @returns {Promise<AcquiredLock<T>>}
|
|
53
69
|
*/
|
|
54
70
|
static async acquire(key, callback, metadata) {
|
|
55
71
|
IMQLock.queues[key] = IMQLock.queues[key] || [];
|
|
@@ -59,7 +75,6 @@ class IMQLock {
|
|
|
59
75
|
if (IMQLock.locked(key)) {
|
|
60
76
|
return new Promise((resolve, reject) => {
|
|
61
77
|
let timer = null;
|
|
62
|
-
// istanbul ignore else
|
|
63
78
|
if (IMQLock.deadlockTimeout) {
|
|
64
79
|
// avoid dead-locks using timeouts
|
|
65
80
|
timer = setTimeout(() => {
|
|
@@ -67,18 +82,18 @@ class IMQLock {
|
|
|
67
82
|
try {
|
|
68
83
|
dumpStr = JSON.stringify(IMQLock.metadata[key]);
|
|
69
84
|
}
|
|
70
|
-
catch
|
|
85
|
+
catch {
|
|
71
86
|
dumpStr = 'Unable to stringify metadata';
|
|
72
87
|
}
|
|
73
88
|
const err = new Error(`Lock timeout, "${key}" call rejected, metadata: ${dumpStr}`);
|
|
74
|
-
clearTimeout(timer);
|
|
89
|
+
timer && clearTimeout(timer);
|
|
75
90
|
timer = null;
|
|
76
91
|
IMQLock.release(key, null, err);
|
|
77
92
|
}, IMQLock.deadlockTimeout);
|
|
78
93
|
}
|
|
79
94
|
IMQLock.queues[key].push([
|
|
80
|
-
// istanbul ignore next
|
|
81
95
|
(result) => {
|
|
96
|
+
// lock resolve
|
|
82
97
|
try {
|
|
83
98
|
timer && clearTimeout(timer);
|
|
84
99
|
timer = null;
|
|
@@ -89,8 +104,8 @@ class IMQLock {
|
|
|
89
104
|
}
|
|
90
105
|
resolve(result);
|
|
91
106
|
},
|
|
92
|
-
// istanbul ignore next
|
|
93
107
|
(err) => {
|
|
108
|
+
// lock reject
|
|
94
109
|
try {
|
|
95
110
|
timer && clearTimeout(timer);
|
|
96
111
|
timer = null;
|
|
@@ -100,7 +115,7 @@ class IMQLock {
|
|
|
100
115
|
err = e;
|
|
101
116
|
}
|
|
102
117
|
reject(err);
|
|
103
|
-
}
|
|
118
|
+
},
|
|
104
119
|
]);
|
|
105
120
|
});
|
|
106
121
|
}
|
|
@@ -108,11 +123,12 @@ class IMQLock {
|
|
|
108
123
|
return true;
|
|
109
124
|
}
|
|
110
125
|
/**
|
|
111
|
-
* Releases previously acquired lock for a given key
|
|
126
|
+
* Releases a previously acquired lock for a given key.
|
|
112
127
|
*
|
|
113
|
-
* @param {string} key
|
|
114
|
-
* @param {T} value
|
|
115
|
-
* @param {E} err
|
|
128
|
+
* @param {string} key - key to release the lock for
|
|
129
|
+
* @param {T} [value] - value to resolve pending calls with
|
|
130
|
+
* @param {E} [err] - error to reject pending calls with
|
|
131
|
+
* @returns {void}
|
|
116
132
|
*/
|
|
117
133
|
static release(key, value, err) {
|
|
118
134
|
const queue = IMQLock.queues[key];
|
|
@@ -127,30 +143,14 @@ class IMQLock {
|
|
|
127
143
|
}
|
|
128
144
|
}
|
|
129
145
|
/**
|
|
130
|
-
* Returns true if given key is locked, false otherwise
|
|
146
|
+
* Returns true if the given key is locked, false otherwise.
|
|
131
147
|
*
|
|
132
|
-
* @param {string} key
|
|
148
|
+
* @param {string} key - key to check the lock state for
|
|
133
149
|
* @returns {boolean}
|
|
134
150
|
*/
|
|
135
151
|
static locked(key) {
|
|
136
|
-
// noinspection PointlessBooleanExpressionJS
|
|
137
152
|
return !!IMQLock.acquiredLocks[key];
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
155
|
exports.IMQLock = IMQLock;
|
|
141
|
-
IMQLock.acquiredLocks = {};
|
|
142
|
-
IMQLock.queues = {};
|
|
143
|
-
IMQLock.metadata = {};
|
|
144
|
-
/**
|
|
145
|
-
* Deadlock timeout in milliseconds
|
|
146
|
-
*
|
|
147
|
-
* @type {number}
|
|
148
|
-
*/
|
|
149
|
-
IMQLock.deadlockTimeout = 10000;
|
|
150
|
-
/**
|
|
151
|
-
* Logger used to log errors which appears during locked calls
|
|
152
|
-
*
|
|
153
|
-
* @type {ILogger}
|
|
154
|
-
*/
|
|
155
|
-
IMQLock.logger = console;
|
|
156
156
|
//# sourceMappingURL=IMQLock.js.map
|
package/src/IMQMetadata.d.ts
CHANGED
|
@@ -22,7 +22,15 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
import { AnyJson, JsonObject } from '@imqueue/core';
|
|
25
|
+
/**
|
|
26
|
+
* Arbitrary, JSON-serializable metadata bag carried alongside an IMQ request.
|
|
27
|
+
* Each property value must be a valid JSON value.
|
|
28
|
+
*/
|
|
25
29
|
export declare class IMQMetadata {
|
|
26
30
|
[property: string]: AnyJson;
|
|
31
|
+
/**
|
|
32
|
+
* @param {JsonObject} metadata - source object whose own enumerable
|
|
33
|
+
* properties are copied into this instance
|
|
34
|
+
*/
|
|
27
35
|
constructor(metadata: JsonObject);
|
|
28
36
|
}
|
package/src/IMQMetadata.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IMQMetadata = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Arbitrary, JSON-serializable metadata bag carried alongside an IMQ request.
|
|
6
|
+
* Each property value must be a valid JSON value.
|
|
7
|
+
*/
|
|
4
8
|
class IMQMetadata {
|
|
9
|
+
/**
|
|
10
|
+
* @param {JsonObject} metadata - source object whose own enumerable
|
|
11
|
+
* properties are copied into this instance
|
|
12
|
+
*/
|
|
5
13
|
constructor(metadata) {
|
|
6
14
|
for (const property of Object.keys(metadata)) {
|
|
7
15
|
this[property] = metadata[property];
|
|
@@ -67,14 +67,14 @@ export interface ServiceDescription {
|
|
|
67
67
|
[className: string]: ServiceClassDescription;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Type property description
|
|
71
71
|
*/
|
|
72
72
|
export interface PropertyDescription {
|
|
73
73
|
type: string;
|
|
74
74
|
isOptional: boolean;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Type properties collection description
|
|
78
78
|
*/
|
|
79
79
|
export interface TypeDescription {
|
|
80
80
|
[propertyName: string]: PropertyDescription;
|
package/src/IMQRPCDescription.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IMQRPCDescription = void 0;
|
|
4
4
|
class IMQRPCDescription {
|
|
5
|
+
static serviceDescription = {};
|
|
6
|
+
static typesDescription = {};
|
|
5
7
|
}
|
|
6
8
|
exports.IMQRPCDescription = IMQRPCDescription;
|
|
7
|
-
IMQRPCDescription.serviceDescription = {};
|
|
8
|
-
IMQRPCDescription.typesDescription = {};
|
|
9
9
|
//# sourceMappingURL=IMQRPCDescription.js.map
|
package/src/IMQRPCError.d.ts
CHANGED
|
@@ -37,14 +37,14 @@ export interface IMQRPCError extends JsonObject {
|
|
|
37
37
|
original?: any;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Builds JSON representation of IMQ
|
|
40
|
+
* Builds a JSON representation of an IMQ error.
|
|
41
41
|
*
|
|
42
|
-
* @param {string} code
|
|
42
|
+
* @param {string} code - error code
|
|
43
43
|
* @param {string} message - error message
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {
|
|
44
|
+
* @param {any} stack - error stack
|
|
45
|
+
* @param {any} method - IMQ service method that produced the error
|
|
46
|
+
* @param {unknown} args - arguments passed to the service method call
|
|
47
|
+
* @param {unknown} [original] - original error thrown (JSON-serialized), if any
|
|
48
48
|
* @return {IMQRPCError}
|
|
49
49
|
*/
|
|
50
|
-
export declare function IMQError(code: string, message: string, stack: any, method: any, args:
|
|
50
|
+
export declare function IMQError(code: string, message: string, stack: any, method: any, args: unknown, original?: unknown): IMQRPCError;
|
package/src/IMQRPCError.js
CHANGED
|
@@ -4,16 +4,15 @@ exports.AFTER_HOOK_ERROR = exports.BEFORE_HOOK_ERROR = void 0;
|
|
|
4
4
|
exports.IMQError = IMQError;
|
|
5
5
|
exports.BEFORE_HOOK_ERROR = 'Before call hook error:';
|
|
6
6
|
exports.AFTER_HOOK_ERROR = 'After call hook error:';
|
|
7
|
-
// istanbul ignore next
|
|
8
7
|
/**
|
|
9
|
-
* Builds JSON representation of IMQ
|
|
8
|
+
* Builds a JSON representation of an IMQ error.
|
|
10
9
|
*
|
|
11
|
-
* @param {string} code
|
|
10
|
+
* @param {string} code - error code
|
|
12
11
|
* @param {string} message - error message
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
12
|
+
* @param {any} stack - error stack
|
|
13
|
+
* @param {any} method - IMQ service method that produced the error
|
|
14
|
+
* @param {unknown} args - arguments passed to the service method call
|
|
15
|
+
* @param {unknown} [original] - original error thrown (JSON-serialized), if any
|
|
17
16
|
* @return {IMQRPCError}
|
|
18
17
|
*/
|
|
19
18
|
function IMQError(code, message, stack, method, args, original) {
|
|
@@ -27,7 +26,7 @@ function IMQError(code, message, stack, method, args, original) {
|
|
|
27
26
|
try {
|
|
28
27
|
return JSON.stringify(original);
|
|
29
28
|
}
|
|
30
|
-
catch
|
|
29
|
+
catch {
|
|
31
30
|
return undefined;
|
|
32
31
|
}
|
|
33
32
|
})(),
|
package/src/IMQRPCOptions.d.ts
CHANGED
|
@@ -26,17 +26,37 @@ import { IMQRPCRequest } from './IMQRPCRequest';
|
|
|
26
26
|
import { IMQRPCResponse } from './IMQRPCResponse';
|
|
27
27
|
import { IMQService } from './IMQService';
|
|
28
28
|
import { IMQClient } from './IMQClient';
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Hook invoked before a service method call is dispatched.
|
|
31
|
+
*
|
|
32
|
+
* @param {IMQRPCRequest} [req] - the incoming request
|
|
33
|
+
* @param {IMQRPCResponse} [res] - the response being prepared
|
|
34
|
+
* @return {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
export interface IMQBeforeCall<_T> {
|
|
30
37
|
(req?: IMQRPCRequest, res?: IMQRPCResponse): Promise<void>;
|
|
31
38
|
}
|
|
32
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Hook invoked after a service method call has been handled.
|
|
41
|
+
*
|
|
42
|
+
* @param {IMQRPCRequest} req - the handled request
|
|
43
|
+
* @param {IMQRPCResponse} [res] - the produced response
|
|
44
|
+
* @return {Promise<void>}
|
|
45
|
+
*/
|
|
46
|
+
export interface IMQAfterCall<_T> {
|
|
33
47
|
(req: IMQRPCRequest, res?: IMQRPCResponse): Promise<void>;
|
|
34
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for the built-in metrics server.
|
|
51
|
+
*/
|
|
35
52
|
export interface IMQMetricsServerOptions {
|
|
36
53
|
enabled?: boolean;
|
|
37
54
|
port?: number;
|
|
38
55
|
queueLengthFormatter?: (length: number, metricName: string) => string;
|
|
39
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Options accepted by an IMQ service.
|
|
59
|
+
*/
|
|
40
60
|
export interface IMQServiceOptions extends IMQOptions {
|
|
41
61
|
multiProcess: boolean;
|
|
42
62
|
childrenPerCore: number;
|
|
@@ -44,11 +64,15 @@ export interface IMQServiceOptions extends IMQOptions {
|
|
|
44
64
|
beforeCall?: IMQBeforeCall<IMQService>;
|
|
45
65
|
afterCall?: IMQAfterCall<IMQService>;
|
|
46
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Options accepted by a generated IMQ client.
|
|
69
|
+
*/
|
|
47
70
|
export interface IMQClientOptions extends IMQOptions {
|
|
48
71
|
path: string;
|
|
49
72
|
compile: boolean;
|
|
50
73
|
timeout: number;
|
|
51
74
|
write: boolean;
|
|
75
|
+
callTimeout?: number;
|
|
52
76
|
beforeCall?: IMQBeforeCall<IMQClient>;
|
|
53
77
|
afterCall?: IMQAfterCall<IMQClient>;
|
|
54
78
|
singleQueue?: boolean;
|
|
@@ -60,7 +84,7 @@ export interface IMQClientOptions extends IMQOptions {
|
|
|
60
84
|
*/
|
|
61
85
|
export declare const DEFAULT_IMQ_SERVICE_OPTIONS: IMQServiceOptions;
|
|
62
86
|
/**
|
|
63
|
-
* Default
|
|
87
|
+
* Default metrics server options
|
|
64
88
|
*
|
|
65
89
|
* @type {NonNullable<IMQMetricsServerOptions>}
|
|
66
90
|
*/
|
package/src/IMQRPCOptions.js
CHANGED
|
@@ -30,9 +30,15 @@ const core_1 = require("@imqueue/core");
|
|
|
30
30
|
*
|
|
31
31
|
* @type {IMQServiceOptions}
|
|
32
32
|
*/
|
|
33
|
-
exports.DEFAULT_IMQ_SERVICE_OPTIONS =
|
|
33
|
+
exports.DEFAULT_IMQ_SERVICE_OPTIONS = {
|
|
34
|
+
...core_1.DEFAULT_IMQ_OPTIONS,
|
|
35
|
+
cleanup: true,
|
|
36
|
+
cleanupFilter: '*:client',
|
|
37
|
+
multiProcess: false,
|
|
38
|
+
childrenPerCore: 1,
|
|
39
|
+
};
|
|
34
40
|
/**
|
|
35
|
-
* Default
|
|
41
|
+
* Default metrics server options
|
|
36
42
|
*
|
|
37
43
|
* @type {NonNullable<IMQMetricsServerOptions>}
|
|
38
44
|
*/
|
|
@@ -46,5 +52,13 @@ exports.DEFAULT_IMQ_METRICS_SERVER_OPTIONS = {
|
|
|
46
52
|
*
|
|
47
53
|
* @type {IMQClientOptions}
|
|
48
54
|
*/
|
|
49
|
-
exports.DEFAULT_IMQ_CLIENT_OPTIONS =
|
|
55
|
+
exports.DEFAULT_IMQ_CLIENT_OPTIONS = {
|
|
56
|
+
...core_1.DEFAULT_IMQ_OPTIONS,
|
|
57
|
+
cleanup: true,
|
|
58
|
+
cleanupFilter: '*:client',
|
|
59
|
+
path: './src/clients',
|
|
60
|
+
compile: true,
|
|
61
|
+
timeout: 30000,
|
|
62
|
+
write: true,
|
|
63
|
+
};
|
|
50
64
|
//# sourceMappingURL=IMQRPCOptions.js.map
|
package/src/IMQRPCRequest.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { JsonObject } from '@imqueue/core';
|
|
25
25
|
import { IMQMetadata } from './IMQMetadata';
|
|
26
26
|
/**
|
|
27
|
-
* Request message data structure
|
|
27
|
+
* Request message data structure to be handled by a service.
|
|
28
28
|
*/
|
|
29
29
|
export interface IMQRPCRequest extends JsonObject {
|
|
30
30
|
from: string;
|
package/src/IMQRPCResponse.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { JsonObject } from '@imqueue/core';
|
|
25
25
|
import { IMQRPCError, IMQRPCRequest } from '.';
|
|
26
26
|
/**
|
|
27
|
-
* Response message data structure
|
|
27
|
+
* Response message data structure that a service replies with to handled
|
|
28
28
|
* requests.
|
|
29
29
|
*/
|
|
30
30
|
export interface IMQRPCResponse extends JsonObject {
|
package/src/IMQRequestContext.js
CHANGED
|
@@ -52,7 +52,6 @@ function runWithRequest(request, fn) {
|
|
|
52
52
|
* @return {IMQMetadata | undefined}
|
|
53
53
|
*/
|
|
54
54
|
function currentMetadata() {
|
|
55
|
-
|
|
56
|
-
return (_a = storage.getStore()) === null || _a === void 0 ? void 0 : _a.metadata;
|
|
55
|
+
return storage.getStore()?.metadata;
|
|
57
56
|
}
|
|
58
57
|
//# sourceMappingURL=IMQRequestContext.js.map
|
package/src/IMQService.d.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { JsonObject, ILogger, IMessageQueue } from '@imqueue/core';
|
|
25
25
|
import { TypesDescription, IMQRPCRequest, IMQRPCResponse, IMQServiceOptions, ICache, MethodsCollectionDescription } from '.';
|
|
26
|
-
import
|
|
26
|
+
import { type Server } from 'node:http';
|
|
27
27
|
export declare class Description {
|
|
28
28
|
service: {
|
|
29
29
|
name: string;
|
|
@@ -40,13 +40,13 @@ export declare abstract class IMQService {
|
|
|
40
40
|
protected imq: IMessageQueue;
|
|
41
41
|
protected logger: ILogger;
|
|
42
42
|
protected cache: ICache;
|
|
43
|
-
protected metricsServer?:
|
|
43
|
+
protected metricsServer?: Server<any, any>;
|
|
44
|
+
private readonly signalHandlers;
|
|
44
45
|
name: string;
|
|
45
46
|
options: IMQServiceOptions;
|
|
46
47
|
/**
|
|
47
48
|
* Class constructor
|
|
48
49
|
*
|
|
49
|
-
* @constructor
|
|
50
50
|
* @param {Partial<IMQServiceOptions>} options
|
|
51
51
|
* @param {string} [name]
|
|
52
52
|
*/
|
|
@@ -54,7 +54,6 @@ export declare abstract class IMQService {
|
|
|
54
54
|
/**
|
|
55
55
|
* Handles incoming request and produces corresponding response
|
|
56
56
|
*
|
|
57
|
-
* @access private
|
|
58
57
|
* @param {IMQRPCRequest} request - request message
|
|
59
58
|
* @param {string} id - message unique identifier
|
|
60
59
|
* @return {Promise<string>}
|