@imqueue/rpc 3.4.3 → 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 +19 -1
- package/index.d.ts +58 -0
- package/index.js +58 -0
- package/package.json +2 -2
- 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/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
|
|
29
|
-
* @
|
|
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
|
|
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
|
|
47
|
-
* @param
|
|
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
|
|
58
|
-
* @param
|
|
59
|
-
* @param
|
|
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) {
|
package/src/helpers/os-uuid.d.ts
CHANGED
package/src/helpers/os-uuid.js
CHANGED
|
@@ -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
|
|
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
|
|
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) {
|
package/src/helpers/pid.d.ts
CHANGED
|
@@ -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
|
|
22
|
-
* @param
|
|
23
|
-
* @returns
|
|
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
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
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;
|
package/src/helpers/pid.js
CHANGED
|
@@ -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
|
|
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
|
|
60
|
-
* @param
|
|
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
|
|
74
|
-
* @param
|
|
75
|
-
* @returns
|
|
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
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
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
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
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;
|
package/src/helpers/signature.js
CHANGED
|
@@ -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
|
|
40
|
-
* @param
|
|
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
|
|
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
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
100
|
-
* @returns
|
|
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], []);
|