@imqueue/rpc 2.1.0 → 3.1.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/README.md +68 -0
- package/package.json +26 -61
- package/src/IMQCache.d.ts +10 -9
- package/src/IMQCache.js +16 -22
- package/src/IMQClient.d.ts +21 -16
- package/src/IMQClient.js +466 -270
- 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 +36 -31
- 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 +147 -129
- 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/.github/workflows/build.yml +0 -28
- package/debug.d.ts +0 -1
|
@@ -1,34 +1,8 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* IMQ-RPC Decorators: expose
|
|
3
|
-
*
|
|
4
|
-
* I'm Queue Software Project
|
|
5
|
-
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
|
|
6
|
-
*
|
|
7
|
-
* This program is free software: you can redistribute it and/or modify
|
|
8
|
-
* it under the terms of the GNU General Public License as published by
|
|
9
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
-
* (at your option) any later version.
|
|
11
|
-
*
|
|
12
|
-
* This program is distributed in the hope that it will be useful,
|
|
13
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
-
* GNU General Public License for more details.
|
|
16
|
-
*
|
|
17
|
-
* You should have received a copy of the GNU General Public License
|
|
18
|
-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
-
*
|
|
20
|
-
* If you want to use this code in a closed source (commercial) project, you can
|
|
21
|
-
* purchase a proprietary commercial license. Please contact us at
|
|
22
|
-
* <support@imqueue.com> to get commercial licensing options.
|
|
23
|
-
*/
|
|
24
|
-
import 'reflect-metadata';
|
|
25
1
|
/**
|
|
26
|
-
* Expose decorator factory
|
|
2
|
+
* Expose decorator factory. Applied to a service method, it registers that
|
|
3
|
+
* method in the RPC service description. (Complex argument/return types are
|
|
4
|
+
* registered separately via the '@classType' decorator on those classes.)
|
|
27
5
|
*
|
|
28
|
-
* @return {(
|
|
29
|
-
* target: object,
|
|
30
|
-
* methodName: (string),
|
|
31
|
-
* descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
|
|
32
|
-
* ) => void} - decorator function
|
|
6
|
+
* @return {(value: any, context: ClassMethodDecoratorContext) => void}
|
|
33
7
|
*/
|
|
34
|
-
export declare function expose():
|
|
8
|
+
export declare function expose(): any;
|
package/src/decorators/expose.js
CHANGED
|
@@ -24,28 +24,17 @@ exports.expose = expose;
|
|
|
24
24
|
* purchase a proprietary commercial license. Please contact us at
|
|
25
25
|
* <support@imqueue.com> to get commercial licensing options.
|
|
26
26
|
*/
|
|
27
|
-
require("
|
|
28
|
-
const acorn = require("acorn");
|
|
27
|
+
const acorn_1 = require("acorn");
|
|
29
28
|
const __1 = require("..");
|
|
30
|
-
const TS_TYPES = [
|
|
31
|
-
'object',
|
|
32
|
-
'string',
|
|
33
|
-
'number',
|
|
34
|
-
'boolean',
|
|
35
|
-
'null',
|
|
36
|
-
'undefined',
|
|
37
|
-
];
|
|
38
29
|
const descriptions = {};
|
|
39
30
|
const RX_ARG_NAMES = /^(\S+)([=\s]+.*?)?$/;
|
|
40
31
|
const RX_COMMA_SPLIT = /\s*,\s*/;
|
|
41
32
|
const RX_MULTILINE_CLEANUP = /\*?\n +\* ?/g;
|
|
42
33
|
const RX_DESCRIPTION = /^([\s\S]*?)@/;
|
|
43
34
|
const RX_TAG = /(@[^@]+)/g;
|
|
44
|
-
// noinspection RegExpRedundantEscape
|
|
45
35
|
const RX_TYPE = /\{([\s\S]+)\}/;
|
|
46
36
|
const RX_LI_CLEANUP = /^\s*-\s*/;
|
|
47
37
|
const RX_SPACE_SPLIT = / /;
|
|
48
|
-
// noinspection RegExpRedundantEscape
|
|
49
38
|
const RX_OPTIONAL = /^\[(.*?)\]$/;
|
|
50
39
|
/**
|
|
51
40
|
* Lookup and returns a list of argument names for a given function
|
|
@@ -55,7 +44,11 @@ const RX_OPTIONAL = /^\[(.*?)\]$/;
|
|
|
55
44
|
*/
|
|
56
45
|
function argumentNames(fn) {
|
|
57
46
|
let src = fn.toString();
|
|
58
|
-
return src
|
|
47
|
+
return src
|
|
48
|
+
.slice(src.indexOf('(') + 1, src.indexOf(')'))
|
|
49
|
+
.split(RX_COMMA_SPLIT)
|
|
50
|
+
.map(arg => arg.trim().replace(RX_ARG_NAMES, '$1'))
|
|
51
|
+
.filter(arg => arg);
|
|
59
52
|
}
|
|
60
53
|
/**
|
|
61
54
|
* Parses given multi-line comment block
|
|
@@ -72,10 +65,9 @@ function parseComment(src) {
|
|
|
72
65
|
description: '',
|
|
73
66
|
type: '',
|
|
74
67
|
tsType: '',
|
|
75
|
-
}
|
|
68
|
+
},
|
|
76
69
|
};
|
|
77
70
|
let match, tags = [];
|
|
78
|
-
// istanbul ignore next
|
|
79
71
|
data.description = String((cleanSrc.match(RX_DESCRIPTION) || [])[1] || '').trim();
|
|
80
72
|
while ((match = RX_TAG.exec(cleanSrc))) {
|
|
81
73
|
tags.push(match[1].trim());
|
|
@@ -121,9 +113,13 @@ function parseComment(src) {
|
|
|
121
113
|
}
|
|
122
114
|
return data;
|
|
123
115
|
}
|
|
124
|
-
// codebeat:disable[LOC,ABC]
|
|
125
116
|
/**
|
|
126
|
-
* Finds and parses methods and their comment blocks for a given class
|
|
117
|
+
* Finds and parses methods and their comment blocks for a given class.
|
|
118
|
+
*
|
|
119
|
+
* The class source (from `Function.prototype.toString`) is always compiled
|
|
120
|
+
* JavaScript, so it is parsed with acorn; a method's doc is the last block
|
|
121
|
+
* comment between the previous class member (or the class body start) and
|
|
122
|
+
* the method itself, i.e. the last block comment in its leading trivia.
|
|
127
123
|
*
|
|
128
124
|
* @param {string} name - class name
|
|
129
125
|
* @param {string} src - class source code
|
|
@@ -131,75 +127,70 @@ function parseComment(src) {
|
|
|
131
127
|
function parseDescriptions(name, src) {
|
|
132
128
|
const comments = [];
|
|
133
129
|
const options = {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
// 'latest' so we can parse whatever modern syntax the configured
|
|
131
|
+
// compilation target emits into the class source we introspect
|
|
132
|
+
ecmaVersion: 'latest',
|
|
137
133
|
allowReserved: true,
|
|
138
134
|
onComment: comments,
|
|
139
135
|
};
|
|
140
|
-
|
|
136
|
+
// the local `inherits` is a placeholder only: the public description's
|
|
137
|
+
// `inherits` is derived from the runtime prototype chain in
|
|
138
|
+
// buildMethodDescription(), never from the parsed source (standard
|
|
139
|
+
// decorators compile the heritage clause to a helper like `_classSuper`,
|
|
140
|
+
// so the source name is unusable)
|
|
141
141
|
descriptions[name] = {
|
|
142
|
-
inherits: 'Function'
|
|
142
|
+
inherits: 'Function',
|
|
143
143
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
let body;
|
|
145
|
+
try {
|
|
146
|
+
body = (0, acorn_1.parse)(src, options).body;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// tolerate unparseable sources (e.g. bound or native functions) the
|
|
150
|
+
// same way the previous error-tolerant parsers did
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
for (const node of body) {
|
|
154
|
+
if (!(node &&
|
|
155
|
+
node.type === 'ClassDeclaration' &&
|
|
156
|
+
node.id &&
|
|
157
|
+
node.id.name === name &&
|
|
158
|
+
node.body &&
|
|
148
159
|
node.body.type === 'ClassBody')) {
|
|
149
160
|
continue;
|
|
150
161
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
for (let method of node.body.body) {
|
|
163
|
-
// istanbul ignore if
|
|
164
|
-
if (method.type !== 'MethodDefinition') {
|
|
162
|
+
const members = node.body.body;
|
|
163
|
+
for (let i = 0; i < members.length; i++) {
|
|
164
|
+
const member = members[i];
|
|
165
|
+
// plain (non-accessor, non-constructor) methods with literal
|
|
166
|
+
// identifier names only — same filter the previous
|
|
167
|
+
// implementations applied
|
|
168
|
+
if (member.type !== 'MethodDefinition' ||
|
|
169
|
+
member.kind !== 'method' ||
|
|
170
|
+
member.computed ||
|
|
171
|
+
!member.key ||
|
|
172
|
+
member.key.type !== 'Identifier') {
|
|
165
173
|
continue;
|
|
166
174
|
}
|
|
167
|
-
|
|
168
|
-
|
|
175
|
+
// the doc block must lie after the previous member of any kind
|
|
176
|
+
// (so comments inside earlier bodies and field initializers can
|
|
177
|
+
// never match) and before the method itself
|
|
178
|
+
const lowerBound = i
|
|
179
|
+
? members[i - 1].end
|
|
180
|
+
: node.body.start + 1;
|
|
181
|
+
const blocks = comments.filter(comment => comment.type === 'Block' &&
|
|
182
|
+
comment.start >= lowerBound &&
|
|
183
|
+
comment.end <= member.start);
|
|
169
184
|
if (!blocks.length) {
|
|
170
185
|
continue;
|
|
171
186
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const dif = methodStart - comment.end;
|
|
177
|
-
if (dif < 0) {
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
if (dif >= lastDif) {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
lastDif = dif;
|
|
184
|
-
foundBlock = comment;
|
|
185
|
-
}
|
|
186
|
-
if (!method.range || foundBlock.start > method.range[1]) {
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
const index = methods.indexOf(method);
|
|
190
|
-
const prev = index && methods[index - 1];
|
|
191
|
-
const prevBeforeComment = !prev
|
|
192
|
-
|| (prev && prev.range && prev.range[1] <= foundBlock.start);
|
|
193
|
-
if (prevBeforeComment) {
|
|
194
|
-
// it's a method comment block!!!!
|
|
195
|
-
descriptions[name][methodName] = {
|
|
196
|
-
comment: parseComment(foundBlock.value),
|
|
197
|
-
};
|
|
198
|
-
}
|
|
187
|
+
descriptions[name][member.key.name] = {
|
|
188
|
+
// acorn comment values exclude the /* and */ delimiters
|
|
189
|
+
comment: parseComment(blocks[blocks.length - 1].value),
|
|
190
|
+
};
|
|
199
191
|
}
|
|
200
192
|
}
|
|
201
193
|
}
|
|
202
|
-
// codebeat:enable[LOC,ABC]
|
|
203
194
|
/**
|
|
204
195
|
* Helper function to make easy descriptions parts extractions
|
|
205
196
|
*
|
|
@@ -211,8 +202,8 @@ function parseDescriptions(name, src) {
|
|
|
211
202
|
*/
|
|
212
203
|
function get(prop, className, method, defaults) {
|
|
213
204
|
if (descriptions[className] && descriptions[className][method]) {
|
|
214
|
-
let comment = descriptions[className][method]
|
|
215
|
-
|
|
205
|
+
let comment = descriptions[className][method]
|
|
206
|
+
.comment;
|
|
216
207
|
if (comment[prop]) {
|
|
217
208
|
return comment[prop];
|
|
218
209
|
}
|
|
@@ -220,74 +211,101 @@ function get(prop, className, method, defaults) {
|
|
|
220
211
|
return defaults;
|
|
221
212
|
}
|
|
222
213
|
/**
|
|
223
|
-
*
|
|
214
|
+
* Builds and registers the RPC description for a single exposed method.
|
|
215
|
+
*
|
|
216
|
+
* Types are taken from the method's JSDoc (parsed from the class source,
|
|
217
|
+
* preserved by `removeComments: false`); standard decorators provide no
|
|
218
|
+
* runtime `design:type` metadata, so JSDoc is the sole type source.
|
|
224
219
|
*
|
|
225
|
-
* @param
|
|
226
|
-
* @
|
|
220
|
+
* @param {Function} ctor - class that declares the method
|
|
221
|
+
* @param {string} methodName - exposed method name
|
|
222
|
+
* @param {(...args: any[]) => any} fn - the method implementation
|
|
227
223
|
*/
|
|
228
|
-
function
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
224
|
+
function buildMethodDescription(ctor, methodName, fn) {
|
|
225
|
+
const className = ctor.name;
|
|
226
|
+
const argNames = argumentNames(fn);
|
|
227
|
+
if (!descriptions[className]) {
|
|
228
|
+
parseDescriptions(className, ctor.toString());
|
|
232
229
|
}
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
const args = get('params', className, methodName, []);
|
|
231
|
+
const ret = get('returns', className, methodName, {
|
|
232
|
+
description: '',
|
|
233
|
+
type: '',
|
|
234
|
+
tsType: '',
|
|
235
|
+
});
|
|
236
|
+
if (!args || !args.length) {
|
|
237
|
+
for (let i = 0, s = argNames.length; i < s; i++) {
|
|
238
|
+
args[i] = {
|
|
239
|
+
description: '',
|
|
240
|
+
name: argNames[i],
|
|
241
|
+
type: '',
|
|
242
|
+
tsType: '',
|
|
243
|
+
isOptional: false,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
235
246
|
}
|
|
236
|
-
|
|
237
|
-
|
|
247
|
+
// JSDoc is the sole type source; mirror the parsed tsType into `type`
|
|
248
|
+
// (the only consumer of `type` is the client generator's
|
|
249
|
+
// IMQDelay/IMQMetadata stripping) and default any undocumented type to
|
|
250
|
+
// 'any' so generated clients are always valid TypeScript
|
|
251
|
+
for (const arg of args) {
|
|
252
|
+
arg.tsType = arg.tsType || 'any';
|
|
253
|
+
arg.type = arg.type || arg.tsType;
|
|
238
254
|
}
|
|
239
|
-
|
|
255
|
+
ret.tsType = ret.tsType || 'any';
|
|
256
|
+
ret.type = ret.type || ret.tsType;
|
|
257
|
+
// derive the parent from the runtime prototype chain rather than the
|
|
258
|
+
// parsed source: standard-decorator output aliases the `extends` clause
|
|
259
|
+
// to a helper (e.g. `extends _classSuper`), so the source name is unusable
|
|
260
|
+
const parent = Object.getPrototypeOf(ctor);
|
|
261
|
+
const inherits = parent && parent.name ? parent.name : 'Function';
|
|
262
|
+
__1.IMQRPCDescription.serviceDescription[className] = __1.IMQRPCDescription
|
|
263
|
+
.serviceDescription[className] || {
|
|
264
|
+
inherits,
|
|
265
|
+
methods: {},
|
|
266
|
+
};
|
|
267
|
+
__1.IMQRPCDescription.serviceDescription[className].methods[methodName] = {
|
|
268
|
+
description: get('description', className, methodName, ''),
|
|
269
|
+
arguments: args,
|
|
270
|
+
returns: ret,
|
|
271
|
+
};
|
|
240
272
|
}
|
|
241
273
|
/**
|
|
242
|
-
* Expose decorator factory
|
|
274
|
+
* Expose decorator factory. Applied to a service method, it registers that
|
|
275
|
+
* method in the RPC service description. (Complex argument/return types are
|
|
276
|
+
* registered separately via the '@classType' decorator on those classes.)
|
|
243
277
|
*
|
|
244
|
-
* @return {(
|
|
245
|
-
* target: object,
|
|
246
|
-
* methodName: (string),
|
|
247
|
-
* descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
|
|
248
|
-
* ) => void} - decorator function
|
|
278
|
+
* @return {(value: any, context: ClassMethodDecoratorContext) => void}
|
|
249
279
|
*/
|
|
250
280
|
function expose() {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
};
|
|
275
|
-
}
|
|
281
|
+
// Dual-mode: standard (TC39) invocations pass a context object with a
|
|
282
|
+
// `kind` property; legacy ones pass (target, propertyKey, descriptor).
|
|
283
|
+
return function exposeDecorator(target, context, descriptor) {
|
|
284
|
+
if (context && typeof context === 'object' && 'kind' in context) {
|
|
285
|
+
const value = target;
|
|
286
|
+
const methodName = String(context.name);
|
|
287
|
+
// the class is not available at decoration time, so defer to an
|
|
288
|
+
// initializer that runs at construction, where `this` is known
|
|
289
|
+
context.addInitializer(function () {
|
|
290
|
+
// register the method under the class that actually declares
|
|
291
|
+
// it (inherited methods are described under the base class,
|
|
292
|
+
// matching decoration-time behavior)
|
|
293
|
+
let proto = this.constructor.prototype;
|
|
294
|
+
while (proto &&
|
|
295
|
+
!Object.prototype.hasOwnProperty.call(proto, methodName)) {
|
|
296
|
+
proto = Object.getPrototypeOf(proto);
|
|
297
|
+
}
|
|
298
|
+
const ctor = proto
|
|
299
|
+
? proto.constructor
|
|
300
|
+
: this.constructor;
|
|
301
|
+
buildMethodDescription(ctor, methodName, value);
|
|
302
|
+
});
|
|
303
|
+
return;
|
|
276
304
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
__1.IMQRPCDescription.serviceDescription[className] =
|
|
282
|
-
__1.IMQRPCDescription.serviceDescription[className] || {
|
|
283
|
-
inherits: descriptions[className].inherits,
|
|
284
|
-
methods: {},
|
|
285
|
-
};
|
|
286
|
-
__1.IMQRPCDescription.serviceDescription[className].methods[methodName] = {
|
|
287
|
-
description: get('description', className, methodName, ''),
|
|
288
|
-
arguments: args,
|
|
289
|
-
returns: ret,
|
|
290
|
-
};
|
|
305
|
+
// legacy: `target` is the prototype, so its constructor is the class
|
|
306
|
+
// that declares the method — available immediately at decoration time
|
|
307
|
+
buildMethodDescription(target.constructor, String(context), descriptor.value);
|
|
308
|
+
return descriptor;
|
|
291
309
|
};
|
|
292
310
|
}
|
|
293
311
|
//# sourceMappingURL=expose.js.map
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
* purchase a proprietary commercial license. Please contact us at
|
|
22
22
|
* <support@imqueue.com> to get commercial licensing options.
|
|
23
23
|
*/
|
|
24
|
+
import './metadata';
|
|
24
25
|
export * from './expose';
|
|
26
|
+
export * from './classType';
|
|
25
27
|
export * from './remote';
|
|
26
28
|
export * from './lock';
|
|
27
29
|
export * from './cache';
|
package/src/decorators/index.js
CHANGED
|
@@ -37,7 +37,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
* purchase a proprietary commercial license. Please contact us at
|
|
38
38
|
* <support@imqueue.com> to get commercial licensing options.
|
|
39
39
|
*/
|
|
40
|
+
// must load first: installs the Symbol.metadata polyfill required by the
|
|
41
|
+
// standard-decorator metadata used across the decorators below
|
|
42
|
+
require("./metadata");
|
|
40
43
|
__exportStar(require("./expose"), exports);
|
|
44
|
+
__exportStar(require("./classType"), exports);
|
|
41
45
|
__exportStar(require("./remote"), exports);
|
|
42
46
|
__exportStar(require("./lock"), exports);
|
|
43
47
|
__exportStar(require("./cache"), exports);
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* IMQ-RPC Decorators: property
|
|
3
|
+
*
|
|
4
|
+
* I'm Queue Software Project
|
|
5
|
+
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*
|
|
20
|
+
* If you want to use this code in a closed source (commercial) project, you can
|
|
21
|
+
* purchase a proprietary commercial license. Please contact us at
|
|
22
|
+
* <support@imqueue.com> to get commercial licensing options.
|
|
23
|
+
*/
|
|
1
24
|
import { Thunk } from '..';
|
|
2
25
|
/**
|
|
3
26
|
* Implements '@indexed' decorator factory
|
|
@@ -25,6 +25,7 @@ exports.indexed = indexed;
|
|
|
25
25
|
* <support@imqueue.com> to get commercial licensing options.
|
|
26
26
|
*/
|
|
27
27
|
const __1 = require("..");
|
|
28
|
+
const property_1 = require("./property");
|
|
28
29
|
/**
|
|
29
30
|
* Implements '@indexed' decorator factory
|
|
30
31
|
* This is used to specify complex service types which are need to expose
|
|
@@ -43,27 +44,35 @@ const __1 = require("..");
|
|
|
43
44
|
* @return {(constructor: Function) => void}
|
|
44
45
|
*/
|
|
45
46
|
function indexed(indexTypedef) {
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
// Dual-mode: standard (TC39) class decorators pass a context object with a
|
|
48
|
+
// `kind` property; legacy ones pass only the constructor.
|
|
49
|
+
return function (value, context) {
|
|
50
|
+
const isStandard = context && typeof context === 'object' && 'kind' in context;
|
|
48
51
|
if (!indexTypedef) {
|
|
49
|
-
return; // nothing to do here
|
|
52
|
+
return isStandard ? undefined : value; // nothing to do here
|
|
50
53
|
}
|
|
51
54
|
if (typeof indexTypedef === 'function') {
|
|
52
55
|
indexTypedef = indexTypedef();
|
|
53
56
|
}
|
|
54
|
-
// istanbul ignore if
|
|
55
57
|
if (typeof indexTypedef !== 'string') {
|
|
56
58
|
indexTypedef = String(indexTypedef);
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
if (isStandard) {
|
|
61
|
+
// registers any @property fields on this class plus the index type
|
|
62
|
+
(0, property_1.registerType)(value, context.metadata, indexTypedef);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// legacy: @property already registered the fields directly, so only
|
|
66
|
+
// the index type needs to be attached to the existing description
|
|
67
|
+
const typeName = value.name;
|
|
68
|
+
__1.IMQRPCDescription.typesDescription[typeName] = __1.IMQRPCDescription
|
|
69
|
+
.typesDescription[typeName] || {
|
|
70
|
+
properties: {},
|
|
71
|
+
inherits: Object.getPrototypeOf(value).name,
|
|
72
|
+
};
|
|
73
|
+
__1.IMQRPCDescription.typesDescription[typeName].indexType =
|
|
74
|
+
indexTypedef;
|
|
75
|
+
return value;
|
|
67
76
|
};
|
|
68
77
|
}
|
|
69
78
|
//# sourceMappingURL=indexed.js.map
|
package/src/decorators/lock.d.ts
CHANGED
|
@@ -3,16 +3,15 @@ export interface LockOptions {
|
|
|
3
3
|
skipArgs?: number[];
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* argument values.
|
|
6
|
+
* Creates a `@lock()` method decorator. Concurrent calls to the decorated
|
|
7
|
+
* method that share the same arguments are coalesced: only the first call is
|
|
8
|
+
* executed, and all the others resolve with its result. Call similarity is
|
|
9
|
+
* determined by the method's argument values. The returned decorator is
|
|
10
|
+
* dual-mode: it works both as a standard (TC39) and as a legacy method
|
|
11
|
+
* decorator.
|
|
10
12
|
*
|
|
11
|
-
* @param {boolean|LockOptions} enabledOrOptions - whether
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* methodName: (string),
|
|
15
|
-
* descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
|
|
16
|
-
* ) => void}
|
|
13
|
+
* @param {boolean | LockOptions} enabledOrOptions - whether locking is enabled,
|
|
14
|
+
* or the lock options
|
|
15
|
+
* @return {Function} - a dual-mode method decorator
|
|
17
16
|
*/
|
|
18
|
-
export declare function lock(enabledOrOptions?: boolean | LockOptions):
|
|
17
|
+
export declare function lock(enabledOrOptions?: boolean | LockOptions): any;
|