@imqueue/rpc 3.4.4 → 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.
- 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 +58 -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 +29 -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/IMQLock.js
CHANGED
|
@@ -23,30 +23,43 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import {} from '@imqueue/core';
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* In-process, promise-based locks used to collapse concurrent identical calls: the
|
|
27
|
+
* first caller executes the work while later callers for the same key wait and are
|
|
28
|
+
* then resolved with the first caller's result.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* These are not distributed locks. The lock table is a set of plain static
|
|
32
|
+
* objects held in memory, and nothing here touches Redis, the network or any
|
|
33
|
+
* shared store. Separate processes, cluster workers and service replicas each
|
|
34
|
+
* maintain their own independent locks and will run the guarded code
|
|
35
|
+
* concurrently. {@link lock} inherits the same limitation. Use a Redis- or
|
|
36
|
+
* database-backed lock if you need mutual exclusion across processes.
|
|
37
|
+
*
|
|
38
|
+
* Keys are used verbatim, with no prefixing or namespacing, so they are global to
|
|
39
|
+
* the process and unrelated call sites sharing a string share a lock.
|
|
28
40
|
*
|
|
29
41
|
* @example
|
|
30
|
-
*
|
|
31
|
-
* import { IMQLock, AcquiredLock } from '
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { IMQLock, type AcquiredLock } from '@imqueue/rpc';
|
|
32
44
|
*
|
|
33
45
|
* async function doSomething(): Promise<number | AcquiredLock<number>> {
|
|
34
|
-
* const lock: AcquiredLock<number> =
|
|
46
|
+
* const lock: AcquiredLock<number> =
|
|
47
|
+
* await IMQLock.acquire<number>('doSomething');
|
|
35
48
|
*
|
|
49
|
+
* // locked() is the only reliable way to tell holder from waiter
|
|
36
50
|
* if (IMQLock.locked('doSomething')) {
|
|
37
|
-
* //
|
|
38
|
-
* //
|
|
39
|
-
* // BTW, IMQLock uses timeouts to avoid dead-locks
|
|
51
|
+
* // always wrap locked work in try/catch and release on both paths,
|
|
52
|
+
* // otherwise waiters hang until the deadlock timeout fires
|
|
40
53
|
* try {
|
|
41
|
-
* //
|
|
42
|
-
* //
|
|
54
|
+
* // runs only once across all concurrent calls; every waiter
|
|
55
|
+
* // resolves with this same value
|
|
43
56
|
* const res = Math.random();
|
|
57
|
+
*
|
|
44
58
|
* IMQLock.release('doSomething', res);
|
|
45
|
-
* return res;
|
|
46
|
-
* }
|
|
47
59
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
60
|
+
* return res;
|
|
61
|
+
* } catch (err) {
|
|
62
|
+
* // reject every waiter with the same error
|
|
50
63
|
* IMQLock.release('doSomething', null, err);
|
|
51
64
|
* throw err;
|
|
52
65
|
* }
|
|
@@ -55,13 +68,10 @@ import {} from '@imqueue/core';
|
|
|
55
68
|
* return lock;
|
|
56
69
|
* }
|
|
57
70
|
*
|
|
58
|
-
* (
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* }
|
|
63
|
-
* })();
|
|
64
|
-
* ~~~
|
|
71
|
+
* for (let i = 0; i < 10; ++i) {
|
|
72
|
+
* doSomething().then(res => console.log(res));
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
65
75
|
*/
|
|
66
76
|
export class IMQLock {
|
|
67
77
|
static acquiredLocks = {};
|
|
@@ -69,24 +79,19 @@ export class IMQLock {
|
|
|
69
79
|
static metadata = {};
|
|
70
80
|
/**
|
|
71
81
|
* Deadlock timeout in milliseconds
|
|
72
|
-
*
|
|
73
|
-
* @type {number}
|
|
74
82
|
*/
|
|
75
83
|
static deadlockTimeout = 10000;
|
|
76
84
|
/**
|
|
77
85
|
* Logger used to log errors that appear during locked calls
|
|
78
|
-
*
|
|
79
|
-
* @type {ILogger}
|
|
80
86
|
*/
|
|
81
87
|
static logger = console;
|
|
82
88
|
/**
|
|
83
89
|
* Acquires a lock for a given key.
|
|
84
90
|
*
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
91
|
+
* @param key - key to acquire the lock for
|
|
92
|
+
* @param callback - callback invoked on
|
|
87
93
|
* lock resolution
|
|
88
|
-
* @param
|
|
89
|
-
* @returns {Promise<AcquiredLock<T>>}
|
|
94
|
+
* @param metadata - metadata for the locked call
|
|
90
95
|
*/
|
|
91
96
|
static async acquire(key, callback, metadata) {
|
|
92
97
|
IMQLock.queues[key] = IMQLock.queues[key] || [];
|
|
@@ -146,10 +151,9 @@ export class IMQLock {
|
|
|
146
151
|
/**
|
|
147
152
|
* Releases a previously acquired lock for a given key.
|
|
148
153
|
*
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @returns {void}
|
|
154
|
+
* @param key - key to release the lock for
|
|
155
|
+
* @param value - value to resolve pending calls with
|
|
156
|
+
* @param err - error to reject pending calls with
|
|
153
157
|
*/
|
|
154
158
|
static release(key, value, err) {
|
|
155
159
|
const queue = IMQLock.queues[key];
|
|
@@ -166,8 +170,7 @@ export class IMQLock {
|
|
|
166
170
|
/**
|
|
167
171
|
* Returns true if the given key is locked, false otherwise.
|
|
168
172
|
*
|
|
169
|
-
* @param
|
|
170
|
-
* @returns {boolean}
|
|
173
|
+
* @param key - key to check the lock state for
|
|
171
174
|
*/
|
|
172
175
|
static locked(key) {
|
|
173
176
|
return !!IMQLock.acquiredLocks[key];
|
package/src/IMQMetadata.d.ts
CHANGED
|
@@ -27,9 +27,17 @@ import { type AnyJson, type JsonObject } from '@imqueue/core';
|
|
|
27
27
|
* Each property value must be a valid JSON value.
|
|
28
28
|
*/
|
|
29
29
|
export declare class IMQMetadata {
|
|
30
|
+
/**
|
|
31
|
+
* Any string key mapping to any JSON value.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* The constructor performs a shallow copy of the source object's own
|
|
35
|
+
* enumerable string keys — symbol keys and inherited properties are not copied,
|
|
36
|
+
* and nested objects are shared by reference until serialization.
|
|
37
|
+
*/
|
|
30
38
|
[property: string]: AnyJson;
|
|
31
39
|
/**
|
|
32
|
-
* @param
|
|
40
|
+
* @param metadata - source object whose own enumerable
|
|
33
41
|
* properties are copied into this instance
|
|
34
42
|
*/
|
|
35
43
|
constructor(metadata: JsonObject);
|
package/src/IMQMetadata.js
CHANGED
|
@@ -28,7 +28,7 @@ import {} from '@imqueue/core';
|
|
|
28
28
|
*/
|
|
29
29
|
export class IMQMetadata {
|
|
30
30
|
/**
|
|
31
|
-
* @param
|
|
31
|
+
* @param metadata - source object whose own enumerable
|
|
32
32
|
* properties are copied into this instance
|
|
33
33
|
*/
|
|
34
34
|
constructor(metadata) {
|
|
@@ -22,74 +22,248 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Description of one argument of an exposed method, as parsed from its JSDoc.
|
|
26
26
|
*/
|
|
27
27
|
export interface ArgDescription {
|
|
28
|
+
/**
|
|
29
|
+
* Prose describing the argument, taken from the text after the name on the
|
|
30
|
+
* JSDoc `@param` line. Empty string when undocumented.
|
|
31
|
+
*/
|
|
28
32
|
description: string;
|
|
33
|
+
/**
|
|
34
|
+
* Parameter name, from the JSDoc `@param` when documented, otherwise read from
|
|
35
|
+
* the method's own signature.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Emitted verbatim into generated client code, so it must be a valid
|
|
39
|
+
* identifier.
|
|
40
|
+
*/
|
|
29
41
|
name: string;
|
|
42
|
+
/**
|
|
43
|
+
* Legacy duplicate of {@link ArgDescription.tsType} — always the identical
|
|
44
|
+
* string.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Despite the pairing there is no wire-type/language-type distinction here.
|
|
48
|
+
* This field is only read to recognise the framework's own {@link IMQDelay}
|
|
49
|
+
* and {@link IMQMetadata} argument slots. Treat `tsType` as the single source
|
|
50
|
+
* of truth.
|
|
51
|
+
*/
|
|
30
52
|
type: string;
|
|
53
|
+
/**
|
|
54
|
+
* The argument's type as written in the method's JSDoc, defaulting to `'any'`
|
|
55
|
+
* when undocumented. This is what a generated client emits into the method
|
|
56
|
+
* signature. Never empty.
|
|
57
|
+
*/
|
|
31
58
|
tsType: string;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the argument was documented as optional, i.e. written `[name]` in
|
|
61
|
+
* the JSDoc. A TypeScript `?` or a default value alone does not set this.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Affects the service's argument-count check: as soon as one argument is
|
|
65
|
+
* optional, any call with at most the declared number of arguments is
|
|
66
|
+
* accepted — including calls that omit required ones.
|
|
67
|
+
*/
|
|
32
68
|
isOptional: boolean;
|
|
33
69
|
}
|
|
34
70
|
/**
|
|
35
|
-
*
|
|
71
|
+
* Description of an exposed method's return value, as parsed from its JSDoc.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* Always present on a {@link MethodDescription}, even when the method has no
|
|
75
|
+
* `@returns` tag — in which case the type is `'any'`.
|
|
36
76
|
*/
|
|
37
77
|
export interface ReturnValueDescription {
|
|
78
|
+
/**
|
|
79
|
+
* Prose describing the return value, from the `@returns` JSDoc line.
|
|
80
|
+
*/
|
|
38
81
|
description: string;
|
|
82
|
+
/**
|
|
83
|
+
* Legacy duplicate of {@link ReturnValueDescription.tsType} — always the
|
|
84
|
+
* identical string.
|
|
85
|
+
*/
|
|
39
86
|
type: string;
|
|
87
|
+
/**
|
|
88
|
+
* The return type from the method's `@returns` JSDoc, defaulting to `'any'`.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* May span multiple lines. A generated client collapses whitespace and
|
|
92
|
+
* rewrites a bare `Promise` to `Promise<any>`, so this is not necessarily what
|
|
93
|
+
* ends up in the client verbatim.
|
|
94
|
+
*/
|
|
40
95
|
tsType: string;
|
|
41
96
|
}
|
|
42
97
|
/**
|
|
43
|
-
*
|
|
98
|
+
* Description of one exposed method: its summary, its positional arguments and
|
|
99
|
+
* its return value.
|
|
44
100
|
*/
|
|
45
101
|
export interface MethodDescription {
|
|
102
|
+
/**
|
|
103
|
+
* The method's JSDoc summary, or an empty string when undocumented.
|
|
104
|
+
*/
|
|
46
105
|
description: string;
|
|
106
|
+
/**
|
|
107
|
+
* The method's arguments, in positional order.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* The client generator rewrites this array in place — it drops framework
|
|
111
|
+
* arguments the service declared and appends the canonical optional
|
|
112
|
+
* `imqMetadata`/`imqDelay` pair — so it can differ before and after client
|
|
113
|
+
* generation in the same process.
|
|
114
|
+
*/
|
|
47
115
|
arguments: ArgDescription[];
|
|
116
|
+
/**
|
|
117
|
+
* The method's return value description. Always present.
|
|
118
|
+
*/
|
|
48
119
|
returns: ReturnValueDescription;
|
|
49
120
|
}
|
|
50
121
|
/**
|
|
51
|
-
*
|
|
122
|
+
* Map of method name to method description.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* In {@link ServiceClassDescription.methods} this holds only the methods that
|
|
126
|
+
* class itself declares. In the description a service serves to clients it is the
|
|
127
|
+
* whole inheritance chain flattened, with subclass methods overriding same-named
|
|
128
|
+
* parent methods.
|
|
52
129
|
*/
|
|
53
130
|
export interface MethodsCollectionDescription {
|
|
131
|
+
/**
|
|
132
|
+
* Description of the method with the given name.
|
|
133
|
+
*/
|
|
54
134
|
[methodName: string]: MethodDescription;
|
|
55
135
|
}
|
|
56
136
|
/**
|
|
57
|
-
*
|
|
137
|
+
* The exposed methods a single class declares, plus its parent's name.
|
|
58
138
|
*/
|
|
59
139
|
export interface ServiceClassDescription {
|
|
140
|
+
/**
|
|
141
|
+
* Name of the class this one extends, read from the runtime prototype chain.
|
|
142
|
+
* The literal `'Function'` means there is no class parent.
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* This differs from {@link TypesDescription}'s `inherits`, which uses an empty
|
|
146
|
+
* string in that situation — one "has a parent?" check cannot serve both.
|
|
147
|
+
*/
|
|
60
148
|
inherits: string;
|
|
149
|
+
/**
|
|
150
|
+
* Methods declared directly by this class, keyed by name.
|
|
151
|
+
*
|
|
152
|
+
* @remarks
|
|
153
|
+
* Inherited methods live under their declaring class and are merged only when
|
|
154
|
+
* a service builds the description it serves. Includes the inherited framework
|
|
155
|
+
* `describe` method, which client generators skip.
|
|
156
|
+
*/
|
|
61
157
|
methods: MethodsCollectionDescription;
|
|
62
158
|
}
|
|
63
159
|
/**
|
|
64
|
-
*
|
|
160
|
+
* Raw registry of every class that declares exposed methods, keyed by class
|
|
161
|
+
* name — the storage format behind {@link IMQRPCDescription.serviceDescription}.
|
|
162
|
+
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* This is not the payload a service returns from `describe()`. That is
|
|
165
|
+
* {@link Description}, whose `service` field is `\{ name, methods \}` with the
|
|
166
|
+
* inheritance chain already flattened.
|
|
65
167
|
*/
|
|
66
168
|
export interface ServiceDescription {
|
|
169
|
+
/**
|
|
170
|
+
* Description of the class with the given name.
|
|
171
|
+
*/
|
|
67
172
|
[className: string]: ServiceClassDescription;
|
|
68
173
|
}
|
|
69
174
|
/**
|
|
70
|
-
*
|
|
175
|
+
* Description of one property of an exposed complex type.
|
|
71
176
|
*/
|
|
72
177
|
export interface PropertyDescription {
|
|
178
|
+
/**
|
|
179
|
+
* The property's RPC type as a string — a literal type name, a constructor's
|
|
180
|
+
* name, or a name with `[]` appended for the array form.
|
|
181
|
+
*
|
|
182
|
+
* @remarks
|
|
183
|
+
* With standard decorators this is a read-only lazy getter, not a writable
|
|
184
|
+
* field: the type is resolved the first time it is read, so a {@link Thunk}
|
|
185
|
+
* runs then rather than at class-definition time, and assignment has no
|
|
186
|
+
* effect. With legacy decorators it is an already-resolved plain string.
|
|
187
|
+
*/
|
|
73
188
|
type: string;
|
|
189
|
+
/**
|
|
190
|
+
* Whether the property is optional, from the second argument of
|
|
191
|
+
* {@link property}. Defaults to `false`, and is never inferred from a
|
|
192
|
+
* TypeScript `?` modifier.
|
|
193
|
+
*/
|
|
74
194
|
isOptional: boolean;
|
|
75
195
|
}
|
|
76
196
|
/**
|
|
77
|
-
*
|
|
197
|
+
* The property bag of a single exposed type: property name to property
|
|
198
|
+
* description.
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* Despite the singular name this does not describe a whole type — the per-type
|
|
202
|
+
* record, which also carries `inherits` and `indexType`, is the value type of
|
|
203
|
+
* {@link TypesDescription}.
|
|
78
204
|
*/
|
|
79
205
|
export interface TypeDescription {
|
|
206
|
+
/**
|
|
207
|
+
* Description of the property with the given name.
|
|
208
|
+
*/
|
|
80
209
|
[propertyName: string]: PropertyDescription;
|
|
81
210
|
}
|
|
82
211
|
/**
|
|
83
|
-
*
|
|
212
|
+
* Every exposed complex type, keyed by class name.
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* This map is process-global and is embedded by reference into every service's
|
|
216
|
+
* description without filtering, so each service advertises every registered type
|
|
217
|
+
* in its process — including types it does not use — and each becomes a generated
|
|
218
|
+
* interface in every client. Because the reference is live, types registered after
|
|
219
|
+
* a service first described itself still show up. Same-named classes collide.
|
|
84
220
|
*/
|
|
85
221
|
export interface TypesDescription {
|
|
222
|
+
/**
|
|
223
|
+
* Description of the type with the given class name.
|
|
224
|
+
*/
|
|
86
225
|
[typeName: string]: {
|
|
226
|
+
/**
|
|
227
|
+
* The type's properties.
|
|
228
|
+
*/
|
|
87
229
|
properties: TypeDescription;
|
|
230
|
+
/**
|
|
231
|
+
* Name of the parent class, or an empty string when there is no class
|
|
232
|
+
* parent. A generated client only emits an `extends` clause when that
|
|
233
|
+
* parent is itself registered here.
|
|
234
|
+
*/
|
|
88
235
|
inherits: string;
|
|
236
|
+
/**
|
|
237
|
+
* Index signature as raw source text, present only for types decorated
|
|
238
|
+
* with {@link indexed}. Injected verbatim into the generated interface and
|
|
239
|
+
* not validated.
|
|
240
|
+
*/
|
|
89
241
|
indexType?: string;
|
|
90
242
|
};
|
|
91
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Process-global registry of RPC metadata gathered by the decorators.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* Not instantiable and has no instance members — the two static maps are the whole
|
|
249
|
+
* API. {@link expose} populates `serviceDescription`; {@link property} and
|
|
250
|
+
* {@link indexed} populate `typesDescription`. A service's `describe()` reads both
|
|
251
|
+
* to build the description it serves to clients, which is what the client
|
|
252
|
+
* generator consumes.
|
|
253
|
+
*/
|
|
92
254
|
export declare class IMQRPCDescription {
|
|
255
|
+
/**
|
|
256
|
+
* All classes that declare exposed methods, keyed by class name (not service
|
|
257
|
+
* name).
|
|
258
|
+
*
|
|
259
|
+
* @remarks
|
|
260
|
+
* Filled in as decorators run at class-definition time, so it is only complete
|
|
261
|
+
* once every service module has been loaded. Entries are never removed.
|
|
262
|
+
*/
|
|
93
263
|
static serviceDescription: ServiceDescription;
|
|
264
|
+
/**
|
|
265
|
+
* All complex types registered via {@link property} or {@link indexed}, keyed
|
|
266
|
+
* by class name.
|
|
267
|
+
*/
|
|
94
268
|
static typesDescription: TypesDescription;
|
|
95
269
|
}
|
package/src/IMQRPCDescription.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-global registry of RPC metadata gathered by the decorators.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Not instantiable and has no instance members — the two static maps are the whole
|
|
6
|
+
* API. {@link expose} populates `serviceDescription`; {@link property} and
|
|
7
|
+
* {@link indexed} populate `typesDescription`. A service's `describe()` reads both
|
|
8
|
+
* to build the description it serves to clients, which is what the client
|
|
9
|
+
* generator consumes.
|
|
10
|
+
*/
|
|
1
11
|
export class IMQRPCDescription {
|
|
12
|
+
/**
|
|
13
|
+
* All classes that declare exposed methods, keyed by class name (not service
|
|
14
|
+
* name).
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Filled in as decorators run at class-definition time, so it is only complete
|
|
18
|
+
* once every service module has been loaded. Entries are never removed.
|
|
19
|
+
*/
|
|
2
20
|
static serviceDescription = {};
|
|
21
|
+
/**
|
|
22
|
+
* All complex types registered via {@link property} or {@link indexed}, keyed
|
|
23
|
+
* by class name.
|
|
24
|
+
*/
|
|
3
25
|
static typesDescription = {};
|
|
4
26
|
}
|
|
5
27
|
//# sourceMappingURL=IMQRPCDescription.js.map
|
package/src/IMQRPCError.d.ts
CHANGED
|
@@ -22,29 +22,111 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
import { type JsonObject } from '@imqueue/core';
|
|
25
|
+
/**
|
|
26
|
+
* Prefix used when logging a failure inside a `beforeCall` hook.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* A throwing before-hook is warned about and then ignored — the call proceeds — so
|
|
30
|
+
* this string is how such failures are recognized in logs. It is a log prefix, not
|
|
31
|
+
* an {@link IMQRPCError.code} value.
|
|
32
|
+
*/
|
|
25
33
|
export declare const BEFORE_HOOK_ERROR = "Before call hook error:";
|
|
34
|
+
/**
|
|
35
|
+
* Prefix used when logging a failure inside an `afterCall` hook.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* The hook always runs after the response has been sent (service side) or after
|
|
39
|
+
* the call promise has settled (client side), so a throwing after-hook cannot
|
|
40
|
+
* change the call's outcome. It is a log prefix, not an {@link IMQRPCError.code}
|
|
41
|
+
* value.
|
|
42
|
+
*/
|
|
26
43
|
export declare const AFTER_HOOK_ERROR = "After call hook error:";
|
|
27
44
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
45
|
+
* Failure descriptor for a remote call.
|
|
46
|
+
*
|
|
47
|
+
* Produced by a service when a method throws, and also before dispatch when the
|
|
48
|
+
* method does not exist, is not exposed, or was called with the wrong number of
|
|
49
|
+
* arguments. A client additionally synthesizes one locally on call timeout.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* A rejected client call rejects with this object as-is — it is not an `Error`
|
|
53
|
+
* instance, so `err instanceof Error` is false, `err.stack` describes the remote
|
|
54
|
+
* process rather than the caller's frames, and `message` is a plain property rather
|
|
55
|
+
* than an `Error` message.
|
|
30
56
|
*/
|
|
31
57
|
export interface IMQRPCError extends JsonObject {
|
|
58
|
+
/**
|
|
59
|
+
* Machine-readable failure code.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* The framework emits `IMQ_RPC_NO_METHOD`, `IMQ_RPC_NO_ACCESS`,
|
|
63
|
+
* `IMQ_RPC_INVALID_ARGS_COUNT` and `IMQ_RPC_CALL_ERROR` on the service side,
|
|
64
|
+
* and `IMQ_RPC_CALL_TIMEOUT` on the client side. When a service method throws
|
|
65
|
+
* an error carrying its own `code`, that value is used verbatim instead of
|
|
66
|
+
* `IMQ_RPC_CALL_ERROR`, so application-specific codes also surface here.
|
|
67
|
+
*
|
|
68
|
+
* These codes are not exported as constants — compare against the string
|
|
69
|
+
* literals.
|
|
70
|
+
*/
|
|
32
71
|
code: string;
|
|
72
|
+
/**
|
|
73
|
+
* Human-readable failure description.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* Framework-generated messages name the service and method. For a method
|
|
77
|
+
* failure it is the thrown value's `message` copied verbatim, so throwing a
|
|
78
|
+
* non-`Error` leaves this absent from the delivered message.
|
|
79
|
+
*/
|
|
33
80
|
message: string;
|
|
81
|
+
/**
|
|
82
|
+
* Stack trace as a string, from the service process. Empty string rather
|
|
83
|
+
* than absent when unavailable.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* For pre-dispatch failures it is captured at the framework check and points
|
|
87
|
+
* into the service internals, not into application code; for a method failure
|
|
88
|
+
* it is the thrown error's own stack.
|
|
89
|
+
*/
|
|
34
90
|
stack: string;
|
|
91
|
+
/**
|
|
92
|
+
* Bare name of the method the call targeted, unqualified by service name.
|
|
93
|
+
* Empty string rather than absent when unknown.
|
|
94
|
+
*/
|
|
35
95
|
method: string;
|
|
96
|
+
/**
|
|
97
|
+
* The call's arguments serialized as a pretty-printed JSON string, not an
|
|
98
|
+
* array — parse it before use.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* This embeds every argument value in the error, which is also written to the
|
|
102
|
+
* service log, so treat it as potentially sensitive. Serialization of this field
|
|
103
|
+
* is not guarded: constructing an error throws if `args` is not
|
|
104
|
+
* JSON-serializable, unlike {@link IMQRPCError.original}.
|
|
105
|
+
*/
|
|
36
106
|
args: string;
|
|
107
|
+
/**
|
|
108
|
+
* The error the service method threw, as a JSON string — not an object,
|
|
109
|
+
* despite the `any` type.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* Present only for method failures, and `undefined` when the value could not be
|
|
113
|
+
* serialized (circular references, `BigInt`).
|
|
114
|
+
*
|
|
115
|
+
* Because `Error`'s `message` and `stack` are non-enumerable, an ordinary
|
|
116
|
+
* thrown `Error` serializes to `"\{\}"` here: this field carries only the
|
|
117
|
+
* error's own enumerable properties, and never the stack. Read
|
|
118
|
+
* {@link IMQRPCError.stack} and {@link IMQRPCError.message} for those.
|
|
119
|
+
*/
|
|
37
120
|
original?: any;
|
|
38
121
|
}
|
|
39
122
|
/**
|
|
40
123
|
* Builds a JSON representation of an IMQ error.
|
|
41
124
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @return {IMQRPCError}
|
|
125
|
+
* @param code - error code
|
|
126
|
+
* @param message - error message
|
|
127
|
+
* @param stack - error stack
|
|
128
|
+
* @param method - IMQ service method that produced the error
|
|
129
|
+
* @param args - arguments passed to the service method call
|
|
130
|
+
* @param original - original error thrown (JSON-serialized), if any
|
|
49
131
|
*/
|
|
50
132
|
export declare function IMQError(code: string, message: string, stack: any, method: any, args: unknown, original?: unknown): IMQRPCError;
|
package/src/IMQRPCError.js
CHANGED
|
@@ -22,18 +22,34 @@
|
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
24
|
import {} from '@imqueue/core';
|
|
25
|
+
/**
|
|
26
|
+
* Prefix used when logging a failure inside a `beforeCall` hook.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* A throwing before-hook is warned about and then ignored — the call proceeds — so
|
|
30
|
+
* this string is how such failures are recognized in logs. It is a log prefix, not
|
|
31
|
+
* an {@link IMQRPCError.code} value.
|
|
32
|
+
*/
|
|
25
33
|
export const BEFORE_HOOK_ERROR = 'Before call hook error:';
|
|
34
|
+
/**
|
|
35
|
+
* Prefix used when logging a failure inside an `afterCall` hook.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* The hook always runs after the response has been sent (service side) or after
|
|
39
|
+
* the call promise has settled (client side), so a throwing after-hook cannot
|
|
40
|
+
* change the call's outcome. It is a log prefix, not an {@link IMQRPCError.code}
|
|
41
|
+
* value.
|
|
42
|
+
*/
|
|
26
43
|
export const AFTER_HOOK_ERROR = 'After call hook error:';
|
|
27
44
|
/**
|
|
28
45
|
* Builds a JSON representation of an IMQ error.
|
|
29
46
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @return {IMQRPCError}
|
|
47
|
+
* @param code - error code
|
|
48
|
+
* @param message - error message
|
|
49
|
+
* @param stack - error stack
|
|
50
|
+
* @param method - IMQ service method that produced the error
|
|
51
|
+
* @param args - arguments passed to the service method call
|
|
52
|
+
* @param original - original error thrown (JSON-serialized), if any
|
|
37
53
|
*/
|
|
38
54
|
export function IMQError(code, message, stack, method, args, original) {
|
|
39
55
|
return {
|