@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/index.d.ts +58 -0
  3. package/index.js +58 -0
  4. package/package.json +1 -1
  5. package/src/IMQCache.d.ts +20 -11
  6. package/src/IMQCache.js +20 -11
  7. package/src/IMQClient.d.ts +191 -38
  8. package/src/IMQClient.js +204 -57
  9. package/src/IMQDelay.d.ts +29 -6
  10. package/src/IMQDelay.js +20 -6
  11. package/src/IMQLock.d.ts +81 -35
  12. package/src/IMQLock.js +38 -35
  13. package/src/IMQMetadata.d.ts +9 -1
  14. package/src/IMQMetadata.js +1 -1
  15. package/src/IMQRPCDescription.d.ts +183 -9
  16. package/src/IMQRPCDescription.js +22 -0
  17. package/src/IMQRPCError.d.ts +91 -9
  18. package/src/IMQRPCError.js +23 -7
  19. package/src/IMQRPCOptions.d.ts +221 -18
  20. package/src/IMQRPCOptions.js +22 -6
  21. package/src/IMQRPCRequest.d.ts +39 -1
  22. package/src/IMQRPCResponse.d.ts +34 -0
  23. package/src/IMQRequestContext.d.ts +2 -5
  24. package/src/IMQRequestContext.js +2 -5
  25. package/src/IMQService.d.ts +144 -19
  26. package/src/IMQService.js +151 -33
  27. package/src/cache/ICache.d.ts +58 -16
  28. package/src/cache/RedisCache.d.ts +58 -17
  29. package/src/cache/RedisCache.js +43 -17
  30. package/src/decorators/cache.d.ts +46 -2
  31. package/src/decorators/cache.js +2 -2
  32. package/src/decorators/classType.d.ts +28 -13
  33. package/src/decorators/classType.js +28 -13
  34. package/src/decorators/expose.d.ts +59 -7
  35. package/src/decorators/expose.js +77 -30
  36. package/src/decorators/indexed.d.ts +27 -8
  37. package/src/decorators/indexed.js +27 -8
  38. package/src/decorators/lock.d.ts +20 -2
  39. package/src/decorators/lock.js +2 -2
  40. package/src/decorators/logged.d.ts +29 -2
  41. package/src/decorators/logged.js +2 -2
  42. package/src/decorators/property.d.ts +97 -4
  43. package/src/decorators/property.js +84 -6
  44. package/src/decorators/remote.d.ts +1 -1
  45. package/src/decorators/remote.js +1 -1
  46. package/src/helpers/fs.d.ts +5 -7
  47. package/src/helpers/fs.js +8 -10
  48. package/src/helpers/os-uuid.d.ts +0 -2
  49. package/src/helpers/os-uuid.js +2 -10
  50. package/src/helpers/pid.d.ts +7 -7
  51. package/src/helpers/pid.js +10 -11
  52. package/src/helpers/signature.d.ts +4 -4
  53. package/src/helpers/signature.js +7 -7
package/src/helpers/fs.js CHANGED
@@ -25,8 +25,8 @@ import { access, mkdir as fsMkdir, writeFile as fsWriteFile } from 'node:fs';
25
25
  /**
26
26
  * Checks whether a file exists at the given path.
27
27
  *
28
- * @param {string} path - path to the file to check
29
- * @return {Promise<boolean>} - true if the file exists, false otherwise
28
+ * @param path - path to the file to check
29
+ * @returns true if the file exists, false otherwise
30
30
  */
31
31
  export function fileExists(path) {
32
32
  return new Promise(resolve => access(path, err => resolve(!err)));
@@ -34,8 +34,7 @@ export function fileExists(path) {
34
34
  /**
35
35
  * Asynchronously creates a directory at the given path.
36
36
  *
37
- * @param {string} path - path of the directory to create
38
- * @return {Promise<void>}
37
+ * @param path - path of the directory to create
39
38
  */
40
39
  export function mkdir(path) {
41
40
  return new Promise((resolve, reject) => fsMkdir(path, generalCallback.bind(null, resolve, reject)));
@@ -43,9 +42,8 @@ export function mkdir(path) {
43
42
  /**
44
43
  * Asynchronously writes the given content to a file at the given path.
45
44
  *
46
- * @param {string} path - path of the file to write
47
- * @param {string} content - content to write to the file
48
- * @return {Promise<void>}
45
+ * @param path - path of the file to write
46
+ * @param content - content to write to the file
49
47
  */
50
48
  export function writeFile(path, content) {
51
49
  return new Promise((resolve, reject) => fsWriteFile(path, content, { encoding: 'utf8' }, generalCallback.bind(null, resolve, reject)));
@@ -54,9 +52,9 @@ export function writeFile(path, content) {
54
52
  * Constructs a callback that settles a promise using the given resolve and
55
53
  * reject functions, rejecting when an error is provided.
56
54
  *
57
- * @param {(value: void | PromiseLike<void>) => void} resolve - promise resolver
58
- * @param {(reason?: unknown) => void} reject - promise rejecter
59
- * @param {Error | null} [err] - error passed by the underlying fs operation
55
+ * @param resolve - promise resolver
56
+ * @param reject - promise rejecter
57
+ * @param err - error passed by the underlying fs operation
60
58
  */
61
59
  function generalCallback(resolve, reject, err) {
62
60
  if (err) {
@@ -1,7 +1,5 @@
1
1
  /**
2
2
  * Returns the machine UUID. The underlying platform command runs only once
3
3
  * per process; subsequent calls return the memoized value.
4
- *
5
- * @returns {string}
6
4
  */
7
5
  export declare function osUuid(): string;
@@ -27,8 +27,6 @@ import { createHash } from 'node:crypto';
27
27
  * Returns the base path to the Windows registry query tool, accounting for
28
28
  * 32-bit processes running on 64-bit Windows (which must go through the
29
29
  * "sysnative" redirector to reach the real System32).
30
- *
31
- * @returns {string}
32
30
  */
33
31
  function winRegBase() {
34
32
  const useSysnative = process.arch === 'ia32' &&
@@ -40,8 +38,6 @@ function winRegBase() {
40
38
  /**
41
39
  * Returns the platform-specific shell command that emits the raw machine
42
40
  * identifier. Mirrors the commands used by the node-machine-id package.
43
- *
44
- * @returns {string}
45
41
  */
46
42
  function idCommand() {
47
43
  switch (process.platform) {
@@ -63,8 +59,7 @@ function idCommand() {
63
59
  /**
64
60
  * Extracts the bare GUID from the raw command output for the current platform.
65
61
  *
66
- * @param {string} raw - unprocessed command output
67
- * @returns {string}
62
+ * @param raw - unprocessed command output
68
63
  */
69
64
  function parseId(raw) {
70
65
  switch (process.platform) {
@@ -89,9 +84,8 @@ function parseId(raw) {
89
84
  * parses out the GUID, and, unless the original id is requested, returns its
90
85
  * sha256 hash.
91
86
  *
92
- * @param {boolean} [original] - when true returns the raw machine GUID,
87
+ * @param original - when true returns the raw machine GUID,
93
88
  * otherwise returns its sha256 hash
94
- * @returns {string}
95
89
  */
96
90
  function machineIdSync(original) {
97
91
  const id = parseId(execSync(idCommand()).toString());
@@ -104,8 +98,6 @@ let cachedUuid;
104
98
  /**
105
99
  * Returns the machine UUID. The underlying platform command runs only once
106
100
  * per process; subsequent calls return the memoized value.
107
- *
108
- * @returns {string}
109
101
  */
110
102
  export function osUuid() {
111
103
  if (cachedUuid === undefined) {
@@ -18,9 +18,9 @@ export declare const IMQ_PID_DIR: string;
18
18
  * Identifiers this process has released through `forgetPid()` are skipped, see
19
19
  * `retiredIds`.
20
20
  *
21
- * @param {string} name - name of the service to create the pid file for
22
- * @param {string} [path] - directory to store the pid file in
23
- * @returns {number} - the allocated increment-based identifier
21
+ * @param name - name of the service to create the pid file for
22
+ * @param path - directory to store the pid file in
23
+ * @returns the allocated increment-based identifier
24
24
  */
25
25
  export declare function pid(name: string, path?: string): number;
26
26
  /**
@@ -28,9 +28,9 @@ export declare function pid(name: string, path?: string): number;
28
28
  * the identifier as retired so that `pid()` does not hand it out again for the
29
29
  * lifetime of this process, see `retiredIds`.
30
30
  *
31
- * @param {string} name - name of the service whose pid file to remove
32
- * @param {number} id - increment-based identifier of the pid file
33
- * @param {ILogger} logger - logger instance
34
- * @param {string} [path] - directory the pid file is stored in
31
+ * @param name - name of the service whose pid file to remove
32
+ * @param id - increment-based identifier of the pid file
33
+ * @param logger - logger instance
34
+ * @param path - directory the pid file is stored in
35
35
  */
36
36
  export declare function forgetPid(name: string, id: number, logger: ILogger, path?: string): void;
@@ -47,7 +47,7 @@ export const IMQ_PID_DIR = resolve(IMQ_TMP_DIR, '.imq-rpc');
47
47
  * which outlives `destroy()` and consumes the first message addressed to the
48
48
  * new owner — that reply is then lost, and its caller waits forever.
49
49
  *
50
- * Identifiers freed by *another* process (or left behind by one that died) are
50
+ * Identifiers freed by another process (or left behind by one that died) are
51
51
  * still re-used, which is what keeps names dense across restarts.
52
52
  */
53
53
  const retiredIds = new Map();
@@ -56,9 +56,8 @@ const retiredIds = new Map();
56
56
  * path so that pid files kept in different directories cannot influence each
57
57
  * other.
58
58
  *
59
- * @param {string} name - name of the service
60
- * @param {string} path - directory the pid files are stored in
61
- * @returns {string}
59
+ * @param name - name of the service
60
+ * @param path - directory the pid files are stored in
62
61
  */
63
62
  function retiredKey(name, path) {
64
63
  return `${path}/${name}`;
@@ -70,9 +69,9 @@ function retiredKey(name, path) {
70
69
  * Identifiers this process has released through `forgetPid()` are skipped, see
71
70
  * `retiredIds`.
72
71
  *
73
- * @param {string} name - name of the service to create the pid file for
74
- * @param {string} [path] - directory to store the pid file in
75
- * @returns {number} - the allocated increment-based identifier
72
+ * @param name - name of the service to create the pid file for
73
+ * @param path - directory to store the pid file in
74
+ * @returns the allocated increment-based identifier
76
75
  */
77
76
  export function pid(name, path = IMQ_PID_DIR) {
78
77
  const pidFile = `${path}/${name}`;
@@ -108,10 +107,10 @@ export function pid(name, path = IMQ_PID_DIR) {
108
107
  * the identifier as retired so that `pid()` does not hand it out again for the
109
108
  * lifetime of this process, see `retiredIds`.
110
109
  *
111
- * @param {string} name - name of the service whose pid file to remove
112
- * @param {number} id - increment-based identifier of the pid file
113
- * @param {ILogger} logger - logger instance
114
- * @param {string} [path] - directory the pid file is stored in
110
+ * @param name - name of the service whose pid file to remove
111
+ * @param id - increment-based identifier of the pid file
112
+ * @param logger - logger instance
113
+ * @param path - directory the pid file is stored in
115
114
  */
116
115
  export function forgetPid(name, id, logger, path = IMQ_PID_DIR) {
117
116
  try {
@@ -4,9 +4,9 @@
4
4
  * differ only in key insertion order produce the same signature, and circular
5
5
  * arguments are handled without throwing.
6
6
  *
7
- * @param {string} className - name of the class the method belongs to
8
- * @param {string | symbol} methodName - name of the method being called
9
- * @param {readonly unknown[]} args - arguments passed to the method
10
- * @returns {string} - hexadecimal hash string
7
+ * @param className - name of the class the method belongs to
8
+ * @param methodName - name of the method being called
9
+ * @param args - arguments passed to the method
10
+ * @returns hexadecimal hash string
11
11
  */
12
12
  export declare function signature(className: string, methodName: string | symbol, args: readonly unknown[]): string;
@@ -36,10 +36,10 @@ import { hash } from 'node:crypto';
36
36
  * of throwing. Repeated non-circular references to the same object are
37
37
  * serialized in full each time, exactly as `JSON.stringify` does.
38
38
  *
39
- * @param {unknown} value - value to serialize
40
- * @param {object[]} ancestors - stack of objects on the current descent path,
39
+ * @param value - value to serialize
40
+ * @param ancestors - stack of objects on the current descent path,
41
41
  * used for cycle detection
42
- * @returns {string | undefined} - the serialized value, or `undefined` where
42
+ * @returns the serialized value, or `undefined` where
43
43
  * JSON would omit it (`undefined`, functions, and symbols)
44
44
  */
45
45
  function serialize(value, ancestors) {
@@ -94,10 +94,10 @@ function serialize(value, ancestors) {
94
94
  * differ only in key insertion order produce the same signature, and circular
95
95
  * arguments are handled without throwing.
96
96
  *
97
- * @param {string} className - name of the class the method belongs to
98
- * @param {string | symbol} methodName - name of the method being called
99
- * @param {readonly unknown[]} args - arguments passed to the method
100
- * @returns {string} - hexadecimal hash string
97
+ * @param className - name of the class the method belongs to
98
+ * @param methodName - name of the method being called
99
+ * @param args - arguments passed to the method
100
+ * @returns hexadecimal hash string
101
101
  */
102
102
  export function signature(className, methodName, args) {
103
103
  const data = serialize([className, methodName, args], []);