@imqueue/rpc 2.1.0 → 3.0.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 (62) hide show
  1. package/.github/workflows/build.yml +49 -5
  2. package/.oxfmtrc.json +9 -0
  3. package/.oxlintrc.json +37 -0
  4. package/README.md +68 -0
  5. package/package.json +21 -58
  6. package/scripts/strip-comment-coverage.mjs +464 -0
  7. package/src/IMQCache.d.ts +10 -9
  8. package/src/IMQCache.js +16 -22
  9. package/src/IMQClient.d.ts +21 -16
  10. package/src/IMQClient.js +407 -271
  11. package/src/IMQDelay.d.ts +14 -0
  12. package/src/IMQDelay.js +26 -5
  13. package/src/IMQLock.d.ts +17 -15
  14. package/src/IMQLock.js +36 -36
  15. package/src/IMQMetadata.d.ts +8 -0
  16. package/src/IMQMetadata.js +8 -0
  17. package/src/IMQRPCDescription.d.ts +2 -2
  18. package/src/IMQRPCDescription.js +2 -2
  19. package/src/IMQRPCError.d.ts +7 -7
  20. package/src/IMQRPCError.js +7 -8
  21. package/src/IMQRPCOptions.d.ts +27 -3
  22. package/src/IMQRPCOptions.js +17 -3
  23. package/src/IMQRPCRequest.d.ts +1 -1
  24. package/src/IMQRPCResponse.d.ts +1 -1
  25. package/src/IMQRequestContext.js +1 -2
  26. package/src/IMQService.d.ts +3 -4
  27. package/src/IMQService.js +302 -220
  28. package/src/cache/ICache.d.ts +53 -0
  29. package/src/cache/RedisCache.d.ts +30 -25
  30. package/src/cache/RedisCache.js +104 -61
  31. package/src/decorators/cache.d.ts +12 -0
  32. package/src/decorators/cache.js +56 -41
  33. package/src/decorators/classType.d.ts +43 -0
  34. package/src/decorators/classType.js +83 -0
  35. package/src/decorators/expose.d.ts +5 -31
  36. package/src/decorators/expose.js +118 -134
  37. package/src/decorators/index.d.ts +2 -0
  38. package/src/decorators/index.js +4 -0
  39. package/src/decorators/indexed.d.ts +23 -0
  40. package/src/decorators/indexed.js +22 -13
  41. package/src/decorators/lock.d.ts +10 -11
  42. package/src/decorators/lock.js +63 -56
  43. package/src/decorators/logged.d.ts +11 -9
  44. package/src/decorators/logged.js +47 -40
  45. package/src/decorators/metadata.d.ts +24 -0
  46. package/src/decorators/metadata.js +45 -0
  47. package/src/decorators/property.d.ts +7 -57
  48. package/src/decorators/property.js +112 -83
  49. package/src/decorators/remote.d.ts +7 -7
  50. package/src/decorators/remote.js +19 -13
  51. package/src/helpers/fs.d.ts +13 -13
  52. package/src/helpers/fs.js +19 -19
  53. package/src/helpers/os-uuid.d.ts +2 -1
  54. package/src/helpers/os-uuid.js +86 -3
  55. package/src/helpers/pid.d.ts +19 -9
  56. package/src/helpers/pid.js +33 -33
  57. package/src/helpers/signature.d.ts +9 -7
  58. package/src/helpers/signature.js +80 -10
  59. package/src/index.d.ts +0 -1
  60. package/src/index.js +0 -1
  61. package/tsconfig.json +18 -14
  62. package/typedoc.json +19 -0
@@ -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;
@@ -25,22 +25,28 @@ exports.remote = remote;
25
25
  * <support@imqueue.com> to get commercial licensing options.
26
26
  */
27
27
  /**
28
- * Implements '@remote' decorator factory
28
+ * Creates a `@remote()` method decorator for client classes. The decorated
29
+ * method has the remote method name appended to its arguments and is then
30
+ * forwarded to `remoteCall()`. The returned decorator is dual-mode: it works
31
+ * both as a standard (TC39) and as a legacy (experimentalDecorators) method
32
+ * decorator.
29
33
  *
30
- * @return {(
31
- * target: any,
32
- * methodName: (string),
33
- * descriptor: TypedPropertyDescriptor<(...args: any[]) => any>
34
- * ) => void}
34
+ * @return {Function} - a dual-mode method decorator
35
35
  */
36
36
  function remote() {
37
- return function (target, methodName, descriptor) {
38
- const original = descriptor.value;
39
- descriptor.value = function (...args) {
40
- args.push(methodName);
41
- // istanbul ignore next
42
- return (original ? original.apply(this, args) : undefined);
43
- };
37
+ const wrap = (original, methodName) => function (...args) {
38
+ args.push(methodName);
39
+ // istanbul ignore next
40
+ return original ? original.apply(this, args) : undefined;
41
+ };
42
+ // Dual-mode: standard (TC39) invocations pass a context object with a
43
+ // `kind` property; legacy ones pass (target, propertyKey, descriptor).
44
+ return function (target, context, descriptor) {
45
+ if (context && typeof context === 'object' && 'kind' in context) {
46
+ return wrap(target, String(context.name));
47
+ }
48
+ descriptor.value = wrap(descriptor.value, String(context));
49
+ return descriptor;
44
50
  };
45
51
  }
46
52
  //# sourceMappingURL=remote.js.map
@@ -1,22 +1,22 @@
1
1
  /**
2
- * Checks if file exists at given path
2
+ * Checks whether a file exists at the given path.
3
3
  *
4
- * @param {string} path
5
- * @return {Promise<any>}
4
+ * @param {string} path - path to the file to check
5
+ * @return {Promise<boolean>} - true if the file exists, false otherwise
6
6
  */
7
- export declare function fileExists(path: string): Promise<unknown>;
7
+ export declare function fileExists(path: string): Promise<boolean>;
8
8
  /**
9
- * Async mkdir
9
+ * Asynchronously creates a directory at the given path.
10
10
  *
11
- * @param {string} path
12
- * @return {Promise<any>}
11
+ * @param {string} path - path of the directory to create
12
+ * @return {Promise<void>}
13
13
  */
14
- export declare function mkdir(path: string): Promise<unknown>;
14
+ export declare function mkdir(path: string): Promise<void>;
15
15
  /**
16
- * Async writeFile
16
+ * Asynchronously writes the given content to a file at the given path.
17
17
  *
18
- * @param {string} path
19
- * @param {string} content
20
- * @return {Promise<any>}
18
+ * @param {string} path - path of the file to write
19
+ * @param {string} content - content to write to the file
20
+ * @return {Promise<void>}
21
21
  */
22
- export declare function writeFile(path: string, content: string): Promise<unknown>;
22
+ export declare function writeFile(path: string, content: string): Promise<void>;
package/src/helpers/fs.js CHANGED
@@ -26,42 +26,42 @@ exports.writeFile = writeFile;
26
26
  * purchase a proprietary commercial license. Please contact us at
27
27
  * <support@imqueue.com> to get commercial licensing options.
28
28
  */
29
- const fs = require("fs");
29
+ const node_fs_1 = require("node:fs");
30
30
  /**
31
- * Checks if file exists at given path
31
+ * Checks whether a file exists at the given path.
32
32
  *
33
- * @param {string} path
34
- * @return {Promise<any>}
33
+ * @param {string} path - path to the file to check
34
+ * @return {Promise<boolean>} - true if the file exists, false otherwise
35
35
  */
36
36
  function fileExists(path) {
37
- return new Promise(resolve => fs.access(path, err => resolve(!err)));
37
+ return new Promise(resolve => (0, node_fs_1.access)(path, err => resolve(!err)));
38
38
  }
39
39
  /**
40
- * Async mkdir
40
+ * Asynchronously creates a directory at the given path.
41
41
  *
42
- * @param {string} path
43
- * @return {Promise<any>}
42
+ * @param {string} path - path of the directory to create
43
+ * @return {Promise<void>}
44
44
  */
45
45
  function mkdir(path) {
46
- return new Promise((resolve, reject) => fs.mkdir(path, generalCallback.bind(null, resolve, reject)));
46
+ return new Promise((resolve, reject) => (0, node_fs_1.mkdir)(path, generalCallback.bind(null, resolve, reject)));
47
47
  }
48
48
  /**
49
- * Async writeFile
49
+ * Asynchronously writes the given content to a file at the given path.
50
50
  *
51
- * @param {string} path
52
- * @param {string} content
53
- * @return {Promise<any>}
51
+ * @param {string} path - path of the file to write
52
+ * @param {string} content - content to write to the file
53
+ * @return {Promise<void>}
54
54
  */
55
55
  function writeFile(path, content) {
56
- return new Promise((resolve, reject) => fs.writeFile(path, content, { encoding: 'utf8' }, generalCallback.bind(null, resolve, reject)));
56
+ return new Promise((resolve, reject) => (0, node_fs_1.writeFile)(path, content, { encoding: 'utf8' }, generalCallback.bind(null, resolve, reject)));
57
57
  }
58
58
  /**
59
- * Constructs and return callback which will resolve promise using
60
- * given resolver and reject'or
59
+ * Constructs a callback that settles a promise using the given resolve and
60
+ * reject functions, rejecting when an error is provided.
61
61
  *
62
- * @param {() => void} resolve
63
- * @param {(err: Error) => void} reject
64
- * @param {Error} err
62
+ * @param {(value: void | PromiseLike<void>) => void} resolve - promise resolver
63
+ * @param {(reason?: unknown) => void} reject - promise rejecter
64
+ * @param {Error | null} [err] - error passed by the underlying fs operation
65
65
  */
66
66
  function generalCallback(resolve, reject, err) {
67
67
  if (err) {
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Returns machine UUID
2
+ * Returns the machine UUID. The underlying platform command runs only once
3
+ * per process; subsequent calls return the memoized value.
3
4
  *
4
5
  * @returns {string}
5
6
  */