@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.
Files changed (59) hide show
  1. package/README.md +68 -0
  2. package/package.json +26 -61
  3. package/src/IMQCache.d.ts +10 -9
  4. package/src/IMQCache.js +16 -22
  5. package/src/IMQClient.d.ts +21 -16
  6. package/src/IMQClient.js +466 -270
  7. package/src/IMQDelay.d.ts +14 -0
  8. package/src/IMQDelay.js +26 -5
  9. package/src/IMQLock.d.ts +17 -15
  10. package/src/IMQLock.js +36 -36
  11. package/src/IMQMetadata.d.ts +8 -0
  12. package/src/IMQMetadata.js +8 -0
  13. package/src/IMQRPCDescription.d.ts +2 -2
  14. package/src/IMQRPCDescription.js +2 -2
  15. package/src/IMQRPCError.d.ts +7 -7
  16. package/src/IMQRPCError.js +7 -8
  17. package/src/IMQRPCOptions.d.ts +27 -3
  18. package/src/IMQRPCOptions.js +17 -3
  19. package/src/IMQRPCRequest.d.ts +1 -1
  20. package/src/IMQRPCResponse.d.ts +1 -1
  21. package/src/IMQRequestContext.js +1 -2
  22. package/src/IMQService.d.ts +3 -4
  23. package/src/IMQService.js +302 -220
  24. package/src/cache/ICache.d.ts +53 -0
  25. package/src/cache/RedisCache.d.ts +36 -31
  26. package/src/cache/RedisCache.js +104 -61
  27. package/src/decorators/cache.d.ts +12 -0
  28. package/src/decorators/cache.js +56 -41
  29. package/src/decorators/classType.d.ts +43 -0
  30. package/src/decorators/classType.js +83 -0
  31. package/src/decorators/expose.d.ts +5 -31
  32. package/src/decorators/expose.js +147 -129
  33. package/src/decorators/index.d.ts +2 -0
  34. package/src/decorators/index.js +4 -0
  35. package/src/decorators/indexed.d.ts +23 -0
  36. package/src/decorators/indexed.js +22 -13
  37. package/src/decorators/lock.d.ts +10 -11
  38. package/src/decorators/lock.js +63 -56
  39. package/src/decorators/logged.d.ts +11 -9
  40. package/src/decorators/logged.js +47 -40
  41. package/src/decorators/metadata.d.ts +24 -0
  42. package/src/decorators/metadata.js +45 -0
  43. package/src/decorators/property.d.ts +7 -57
  44. package/src/decorators/property.js +112 -83
  45. package/src/decorators/remote.d.ts +7 -7
  46. package/src/decorators/remote.js +19 -13
  47. package/src/helpers/fs.d.ts +13 -13
  48. package/src/helpers/fs.js +19 -19
  49. package/src/helpers/os-uuid.d.ts +2 -1
  50. package/src/helpers/os-uuid.js +86 -3
  51. package/src/helpers/pid.d.ts +19 -9
  52. package/src/helpers/pid.js +33 -33
  53. package/src/helpers/signature.d.ts +9 -7
  54. package/src/helpers/signature.js +80 -10
  55. package/src/index.d.ts +0 -1
  56. package/src/index.js +0 -1
  57. package/tsconfig.json +18 -14
  58. package/.github/workflows/build.yml +0 -28
  59. package/debug.d.ts +0 -1
@@ -25,69 +25,76 @@ exports.lock = lock;
25
25
  * <support@imqueue.com> to get commercial licensing options.
26
26
  */
27
27
  const __1 = require("..");
28
+ const helpers_1 = require("../helpers");
28
29
  /**
29
- * \@lock() decorator implementation
30
- * Will make all simultaneous similar method calls locked to be resolved with
31
- * the first obtained values. Similarity is identified by a bypassed method
32
- * argument values.
30
+ * Creates a `@lock()` method decorator. Concurrent calls to the decorated
31
+ * method that share the same arguments are coalesced: only the first call is
32
+ * executed, and all the others resolve with its result. Call similarity is
33
+ * determined by the method's argument values. The returned decorator is
34
+ * dual-mode: it works both as a standard (TC39) and as a legacy method
35
+ * decorator.
33
36
  *
34
- * @param {boolean|LockOptions} enabledOrOptions - whether to enable locks or not
35
- * @return {(
36
- * target: any,
37
- * methodName: (string),
38
- * descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
39
- * ) => void}
37
+ * @param {boolean | LockOptions} enabledOrOptions - whether locking is enabled,
38
+ * or the lock options
39
+ * @return {Function} - a dual-mode method decorator
40
40
  */
41
41
  function lock(enabledOrOptions = true) {
42
- return function (target, methodName, descriptor) {
43
- const enabled = typeof enabledOrOptions === 'boolean'
44
- ? enabledOrOptions
45
- : !enabledOrOptions.disabled;
46
- const skipArgs = typeof enabledOrOptions === 'boolean'
47
- ? undefined
48
- : enabledOrOptions.skipArgs;
49
- const original = descriptor.value;
50
- const className = typeof target === 'function'
51
- ? target.name // static
52
- : target.constructor.name; // dynamic
53
- descriptor.value = async function (...args) {
54
- const withLocks = !parseInt(process.env['DISABLE_LOCKS'] + '') && enabled;
55
- let lock;
56
- let sig = '';
57
- if (withLocks) {
58
- sig = (0, __1.signature)(className, methodName, skipArgs ? args.filter((_, index) => !~skipArgs.indexOf(index)) : args);
59
- lock = await __1.IMQLock.acquire(sig, undefined, {
60
- className,
61
- methodName,
62
- args,
63
- });
64
- if (!__1.IMQLock.locked(sig)) {
65
- return lock;
66
- }
42
+ const enabled = typeof enabledOrOptions === 'boolean'
43
+ ? enabledOrOptions
44
+ : !enabledOrOptions.disabled;
45
+ const skipArgs = typeof enabledOrOptions === 'boolean'
46
+ ? undefined
47
+ : enabledOrOptions.skipArgs;
48
+ const wrap = (original, methodName, isStatic) => async function (...args) {
49
+ const className = isStatic
50
+ ? this.name // static: `this` is the class
51
+ : this.constructor.name; // dynamic: `this` is the instance
52
+ const withLocks = !parseInt(process.env['DISABLE_LOCKS'] + '') && enabled;
53
+ let lock;
54
+ let sig = '';
55
+ if (withLocks) {
56
+ sig = (0, helpers_1.signature)(className, methodName, skipArgs
57
+ ? args.filter((_, index) => !~skipArgs.indexOf(index))
58
+ : args);
59
+ lock = await __1.IMQLock.acquire(sig, undefined, {
60
+ className,
61
+ methodName,
62
+ args,
63
+ });
64
+ if (!__1.IMQLock.locked(sig)) {
65
+ return lock;
67
66
  }
68
- try {
69
- // istanbul ignore next
70
- let result = original
71
- ? original.apply(this, args)
72
- : undefined;
73
- if (result && result.then &&
74
- typeof result.then === 'function') {
75
- result = await result;
76
- }
77
- if (withLocks) {
78
- __1.IMQLock.release(sig, result);
79
- }
80
- return result;
67
+ }
68
+ try {
69
+ let result = original
70
+ ? original.apply(this, args)
71
+ : undefined;
72
+ if (result &&
73
+ result.then &&
74
+ typeof result.then === 'function') {
75
+ result = await result;
81
76
  }
82
- catch (err) {
83
- // istanbul ignore next
84
- if (withLocks) {
85
- __1.IMQLock.release(sig, null, err);
86
- }
87
- // istanbul ignore next
88
- throw err;
77
+ if (withLocks) {
78
+ __1.IMQLock.release(sig, result);
89
79
  }
90
- };
80
+ return result;
81
+ }
82
+ catch (err) {
83
+ if (withLocks) {
84
+ __1.IMQLock.release(sig, null, err);
85
+ }
86
+ throw err;
87
+ }
88
+ };
89
+ // Dual-mode: standard (TC39) invocations pass a context object with a
90
+ // `kind` property; legacy ones pass (target, propertyKey, descriptor).
91
+ return function (target, context, descriptor) {
92
+ if (context && typeof context === 'object' && 'kind' in context) {
93
+ return wrap(target, context.name, context.static);
94
+ }
95
+ const isStatic = typeof target === 'function';
96
+ descriptor.value = wrap(descriptor.value, context, isStatic);
97
+ return descriptor;
91
98
  };
92
99
  }
93
100
  //# sourceMappingURL=lock.js.map
@@ -29,14 +29,16 @@ export interface LoggedDecoratorOptions {
29
29
  doNotThrow?: boolean;
30
30
  }
31
31
  /**
32
- * Logger decorator factory for class methods. Will try, catch and log errors
33
- * during method calls. If logger is bypassed, will use given logger, otherwise
34
- * will try to use logger defined on class dynamically or statically or will
35
- * fallback to console.
32
+ * Creates a `@logged()` method decorator that wraps the decorated method in a
33
+ * try/catch and logs any error it throws. The logger is resolved in this
34
+ * order: an explicitly passed logger, then a `logger` defined on the instance
35
+ * or on the class, and finally the global `console`. By default the error is
36
+ * re-thrown after being logged; pass `{ doNotThrow: true }` to swallow it. The
37
+ * returned decorator is dual-mode: it works both as a standard (TC39) and as a
38
+ * legacy method decorator.
36
39
  *
37
- * @param {ILogger | LoggedDecoratorOptions} [options] - custom logger or
38
- * logged decorator
39
- * options
40
- * @return {Function} - decorator function
40
+ * @param {ILogger | LoggedDecoratorOptions} [options] - a logger to use, or the
41
+ * logged-decorator options
42
+ * @return {Function} - a dual-mode method decorator
41
43
  */
42
- export declare function logged(options?: ILogger | LoggedDecoratorOptions): (target: any, methodName: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => void;
44
+ export declare function logged(options?: ILogger | LoggedDecoratorOptions): any;
@@ -1,52 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logged = logged;
4
- // noinspection JSUnusedGlobalSymbols
5
4
  /**
6
- * Logger decorator factory for class methods. Will try, catch and log errors
7
- * during method calls. If logger is bypassed, will use given logger, otherwise
8
- * will try to use logger defined on class dynamically or statically or will
9
- * fallback to console.
5
+ * Creates a `@logged()` method decorator that wraps the decorated method in a
6
+ * try/catch and logs any error it throws. The logger is resolved in this
7
+ * order: an explicitly passed logger, then a `logger` defined on the instance
8
+ * or on the class, and finally the global `console`. By default the error is
9
+ * re-thrown after being logged; pass `{ doNotThrow: true }` to swallow it. The
10
+ * returned decorator is dual-mode: it works both as a standard (TC39) and as a
11
+ * legacy method decorator.
10
12
  *
11
- * @param {ILogger | LoggedDecoratorOptions} [options] - custom logger or
12
- * logged decorator
13
- * options
14
- * @return {Function} - decorator function
13
+ * @param {ILogger | LoggedDecoratorOptions} [options] - a logger to use, or the
14
+ * logged-decorator options
15
+ * @return {Function} - a dual-mode method decorator
15
16
  */
16
17
  function logged(options) {
17
- return (target, methodName, descriptor) => {
18
- const original = descriptor.value;
19
- const level = (options &&
20
- options.level)
21
- ? options.level
22
- : 'error';
23
- const doThrow = !options ||
24
- !options.doNotThrow;
25
- descriptor.value = async function (...args) {
26
- try {
27
- const ctx = (typeof this !== 'undefined' && this !== null)
28
- ? this
29
- : target;
30
- if (original) {
31
- return await original.apply(ctx, args);
32
- }
18
+ const level = options && options.level
19
+ ? options.level
20
+ : 'error';
21
+ const doThrow = !options || !options.doNotThrow;
22
+ const wrap = (original) => async function (...args) {
23
+ try {
24
+ if (original) {
25
+ return await original.apply(this, args);
33
26
  }
34
- catch (err) {
35
- const logger = (options && options.logger)
36
- ? options.logger
37
- : (options && options.error)
38
- ? options
39
- : (this && this.logger)
40
- ? this.logger
41
- : (target && target.logger)
42
- ? target.logger
43
- : console;
44
- logger[level](err);
45
- if (doThrow) {
46
- throw err;
47
- }
27
+ }
28
+ catch (err) {
29
+ const logger = options && options.logger
30
+ ? options
31
+ .logger
32
+ : options && options.error
33
+ ? options
34
+ : this && this.logger
35
+ ? this.logger
36
+ : this &&
37
+ this.constructor &&
38
+ this.constructor.logger
39
+ ? this.constructor.logger
40
+ : console;
41
+ logger[level](err);
42
+ if (doThrow) {
43
+ throw err;
48
44
  }
49
- };
45
+ }
46
+ };
47
+ // Dual-mode: works as both a standard (TC39) and a legacy
48
+ // (experimentalDecorators) method decorator. Standard invocations pass a
49
+ // context object with a `kind` property; legacy ones pass
50
+ // (target, propertyKey, descriptor).
51
+ return function (target, context, descriptor) {
52
+ if (context && typeof context === 'object' && 'kind' in context) {
53
+ return wrap(target);
54
+ }
55
+ descriptor.value = wrap(descriptor.value);
56
+ return descriptor;
50
57
  };
51
58
  }
52
59
  //# sourceMappingURL=logged.js.map
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * IMQ-RPC Decorators: Symbol.metadata polyfill
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
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*!
3
+ * IMQ-RPC Decorators: Symbol.metadata polyfill
4
+ *
5
+ * I'm Queue Software Project
6
+ * Copyright (C) 2025 imqueue.com <support@imqueue.com>
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ * If you want to use this code in a closed source (commercial) project, you can
22
+ * purchase a proprietary commercial license. Please contact us at
23
+ * <support@imqueue.com> to get commercial licensing options.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ /**
27
+ * Standard (TC39) decorator metadata relies on the well-known
28
+ * `Symbol.metadata`. Node.js does not implement it natively yet, so without
29
+ * this polyfill the compiler emits `context.metadata` as `undefined` and
30
+ * decorator metadata (used by @property/@expose/@indexed to collect complex
31
+ * type definitions) is unavailable.
32
+ *
33
+ * This module must be imported before any decorated class is defined; it is
34
+ * imported first by the decorator barrel, which every decorator consumer
35
+ * loads transitively.
36
+ */
37
+ if (!Symbol.metadata) {
38
+ Object.defineProperty(Symbol, 'metadata', {
39
+ value: Symbol.for('Symbol.metadata'),
40
+ writable: false,
41
+ enumerable: false,
42
+ configurable: true,
43
+ });
44
+ }
45
+ //# sourceMappingURL=metadata.js.map
@@ -2,63 +2,13 @@ export interface Thunk {
2
2
  (): any;
3
3
  }
4
4
  /**
5
- * Implements '@property' decorator factory
6
- * This is used to specify complex service types to be exposed
5
+ * Flushes @property definitions collected on a class into the RPC type
6
+ * description. Invoked by class-level decorators once the class (and hence
7
+ * its name) is available.
7
8
  *
8
- * @example
9
- * ~~~typescript
10
- * import { property, expose, IMQService } from '@imqueue/rpc';
11
- *
12
- * class Address {
13
- * @property('string')
14
- * country: string;
15
- *
16
- * @property('string')
17
- * city: string;
18
- *
19
- * @property('string')
20
- * address: string;
21
- *
22
- * @property('string', true)
23
- * zipCode?: string; // this is optional
24
- * }
25
- *
26
- * class User {
27
- * @property('string')
28
- * firstName: string;
29
- *
30
- * @property('string')
31
- * lastName: string;
32
- *
33
- * @property('string')
34
- * email: string;
35
- *
36
- * @property('Array<Address>', true)
37
- * address?: Array<Address>;
38
- * }
39
- *
40
- * // now we can use those complex types as service methods args
41
- * // and them will be properly exposed to service clients
42
- *
43
- * class UserService extends IMQService {
44
- *
45
- * @expose()
46
- * public save(user: User) {
47
- * // do smth with given user data to persis it
48
- * }
49
- *
50
- * @expose()
51
- * public find(id: number): User {
52
- * // find and return user
53
- * }
54
- *
55
- * }
56
- * ~~~
57
- *
58
- * @return {(
59
- * target: any,
60
- * methodName: (string),
61
- * descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
62
- * ) => void}
9
+ * @param {Function} ctor - the decorated class constructor
10
+ * @param {DecoratorMetadata | undefined} metadata - shared decorator metadata
11
+ * @param {string} [indexType] - optional index signature definition
63
12
  */
13
+ export declare function registerType(ctor: Function, metadata: DecoratorMetadata | undefined, indexType?: string): void;
64
14
  export declare function property(type: string | Thunk | any, isOptional?: boolean): any;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerType = registerType;
3
4
  exports.property = property;
4
5
  /*!
5
6
  * IMQ-RPC Decorators: property
@@ -26,97 +27,125 @@ exports.property = property;
26
27
  */
27
28
  const __1 = require("..");
28
29
  /**
29
- * Implements '@property' decorator factory
30
- * This is used to specify complex service types to be exposed
31
- *
32
- * @example
33
- * ~~~typescript
34
- * import { property, expose, IMQService } from '@imqueue/rpc';
35
- *
36
- * class Address {
37
- * @property('string')
38
- * country: string;
39
- *
40
- * @property('string')
41
- * city: string;
42
- *
43
- * @property('string')
44
- * address: string;
45
- *
46
- * @property('string', true)
47
- * zipCode?: string; // this is optional
48
- * }
49
- *
50
- * class User {
51
- * @property('string')
52
- * firstName: string;
53
- *
54
- * @property('string')
55
- * lastName: string;
56
- *
57
- * @property('string')
58
- * email: string;
59
- *
60
- * @property('Array<Address>', true)
61
- * address?: Array<Address>;
62
- * }
63
- *
64
- * // now we can use those complex types as service methods args
65
- * // and them will be properly exposed to service clients
66
- *
67
- * class UserService extends IMQService {
68
- *
69
- * @expose()
70
- * public save(user: User) {
71
- * // do smth with given user data to persis it
72
- * }
73
- *
74
- * @expose()
75
- * public find(id: number): User {
76
- * // find and return user
77
- * }
30
+ * Per-class store of collected @property definitions, keyed off the shared
31
+ * decorator metadata object. Standard field decorators cannot see their
32
+ * class at decoration time, so properties are stashed here and flushed to
33
+ * the RPC type description by a class-level decorator (@expose on a type,
34
+ * or @indexed) once the class name is available.
35
+ */
36
+ const PROPERTIES = Symbol('@imqueue/rpc:properties');
37
+ /**
38
+ * Resolves a @property type argument (string, constructor, thunk, or array
39
+ * form) to its RPC type-definition string.
78
40
  *
79
- * }
80
- * ~~~
41
+ * @param {string | Thunk | any} input
42
+ * @return {string}
43
+ */
44
+ function resolveTypeDef(input) {
45
+ let type = input;
46
+ if (typeof type === 'function' && !type.name) {
47
+ type = type();
48
+ }
49
+ let typeDef = type;
50
+ if (Array.isArray(typeDef)) {
51
+ typeDef = typeDef[0];
52
+ }
53
+ if (typeDef && typeof typeDef !== 'string') {
54
+ typeDef = typeDef.name;
55
+ }
56
+ if (Array.isArray(type)) {
57
+ typeDef += '[]';
58
+ }
59
+ if (!typeDef) {
60
+ typeDef = String(type);
61
+ }
62
+ return typeDef;
63
+ }
64
+ /**
65
+ * Flushes @property definitions collected on a class into the RPC type
66
+ * description. Invoked by class-level decorators once the class (and hence
67
+ * its name) is available.
81
68
  *
82
- * @return {(
83
- * target: any,
84
- * methodName: (string),
85
- * descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
86
- * ) => void}
69
+ * @param {Function} ctor - the decorated class constructor
70
+ * @param {DecoratorMetadata | undefined} metadata - shared decorator metadata
71
+ * @param {string} [indexType] - optional index signature definition
87
72
  */
73
+ function registerType(ctor, metadata, indexType) {
74
+ const typeName = ctor.name;
75
+ const collected = metadata && Object.prototype.hasOwnProperty.call(metadata, PROPERTIES)
76
+ ? metadata[PROPERTIES]
77
+ : {};
78
+ __1.IMQRPCDescription.typesDescription[typeName] = __1.IMQRPCDescription
79
+ .typesDescription[typeName] || {
80
+ properties: {},
81
+ inherits: Object.getPrototypeOf(ctor).name,
82
+ };
83
+ const description = __1.IMQRPCDescription.typesDescription[typeName];
84
+ description.inherits = Object.getPrototypeOf(ctor).name;
85
+ for (const key of Object.keys(collected)) {
86
+ const { rawType, isOptional } = collected[key];
87
+ let resolved;
88
+ // resolve the type lazily on first read: standard decorators run
89
+ // before class bindings are initialized, so a thunk referencing the
90
+ // (self- or forward-referenced) type cannot be called during
91
+ // decoration — only once the description is actually consumed
92
+ Object.defineProperty(description.properties, key, {
93
+ enumerable: true,
94
+ configurable: true,
95
+ value: {
96
+ isOptional,
97
+ get type() {
98
+ if (resolved === undefined) {
99
+ resolved = resolveTypeDef(rawType);
100
+ }
101
+ return resolved;
102
+ },
103
+ },
104
+ });
105
+ }
106
+ if (indexType !== undefined) {
107
+ description.indexType = indexType;
108
+ }
109
+ }
88
110
  function property(type, isOptional = false) {
89
- // istanbul ignore if
90
111
  if (!type) {
91
112
  return;
92
113
  }
93
- return function (target, propertyKey) {
94
- const typeName = target.constructor.name;
95
- let typeDef;
96
- if (typeof type === 'function' && !type.name) {
97
- type = type();
98
- }
99
- typeDef = type;
100
- if (Array.isArray(typeDef)) {
101
- typeDef = typeDef[0];
102
- }
103
- if (typeDef && typeof typeDef !== 'string') {
104
- typeDef = typeDef.name;
105
- }
106
- if (Array.isArray(type)) {
107
- typeDef += '[]';
108
- }
109
- // istanbul ignore if
110
- if (!typeDef) {
111
- typeDef = String(type);
112
- }
113
- __1.IMQRPCDescription.typesDescription[typeName] =
114
- __1.IMQRPCDescription.typesDescription[typeName] || {
115
- properties: {},
116
- inherits: Object.getPrototypeOf(target.constructor).name,
114
+ // Dual-mode: standard (TC39) field decorators pass a context object with a
115
+ // `kind` property; legacy ones pass (prototype, propertyKey).
116
+ return function (target, context) {
117
+ if (context && typeof context === 'object' && 'kind' in context) {
118
+ const metadata = context.metadata;
119
+ // each class keeps its OWN property bag (metadata prototype-
120
+ // inherits from a base class, so we must not mutate the inherited
121
+ // one)
122
+ if (!Object.prototype.hasOwnProperty.call(metadata, PROPERTIES)) {
123
+ Object.defineProperty(metadata, PROPERTIES, {
124
+ value: {},
125
+ enumerable: false,
126
+ writable: true,
127
+ configurable: true,
128
+ });
129
+ }
130
+ // store the raw type; resolution is deferred to first read (see
131
+ // registerType) to avoid touching not-yet-initialized bindings
132
+ metadata[PROPERTIES][String(context.name)] = {
133
+ rawType: type,
134
+ isOptional,
117
135
  };
118
- __1.IMQRPCDescription.typesDescription[typeName].properties[propertyKey] = {
119
- type: typeDef,
136
+ return;
137
+ }
138
+ // legacy: the class is available at decoration time, so write the
139
+ // property straight into the RPC type description (no @classType flush
140
+ // is required in this mode)
141
+ const typeName = target.constructor.name;
142
+ __1.IMQRPCDescription.typesDescription[typeName] = __1.IMQRPCDescription
143
+ .typesDescription[typeName] || {
144
+ properties: {},
145
+ inherits: Object.getPrototypeOf(target.constructor).name,
146
+ };
147
+ __1.IMQRPCDescription.typesDescription[typeName].properties[String(context)] = {
148
+ type: resolveTypeDef(type),
120
149
  isOptional,
121
150
  };
122
151
  };
@@ -22,12 +22,12 @@
22
22
  * <support@imqueue.com> to get commercial licensing options.
23
23
  */
24
24
  /**
25
- * Implements '@remote' decorator factory
25
+ * Creates a `@remote()` method decorator for client classes. The decorated
26
+ * method has the remote method name appended to its arguments and is then
27
+ * forwarded to `remoteCall()`. The returned decorator is dual-mode: it works
28
+ * both as a standard (TC39) and as a legacy (experimentalDecorators) method
29
+ * decorator.
26
30
  *
27
- * @return {(
28
- * target: any,
29
- * methodName: (string),
30
- * descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
31
- * ) => void}
31
+ * @return {Function} - a dual-mode method decorator
32
32
  */
33
- export declare function remote(): (target: any, methodName: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => void;
33
+ export declare function remote(): any;