@imqueue/rpc 3.2.0 → 3.2.2

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 (55) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +2 -18
  3. package/package.json +6 -2
  4. package/src/IMQCache.d.ts +1 -24
  5. package/src/IMQCache.js +37 -6
  6. package/src/IMQClient.d.ts +2 -2
  7. package/src/IMQClient.js +53 -86
  8. package/src/IMQDelay.js +1 -5
  9. package/src/IMQLock.d.ts +2 -2
  10. package/src/IMQLock.js +26 -6
  11. package/src/IMQMetadata.d.ts +1 -1
  12. package/src/IMQMetadata.js +25 -5
  13. package/src/IMQRPCDescription.js +1 -5
  14. package/src/IMQRPCError.d.ts +1 -1
  15. package/src/IMQRPCError.js +27 -7
  16. package/src/IMQRPCOptions.d.ts +5 -5
  17. package/src/IMQRPCOptions.js +10 -9
  18. package/src/IMQRPCRequest.d.ts +2 -2
  19. package/src/IMQRPCRequest.js +25 -2
  20. package/src/IMQRPCResponse.d.ts +2 -2
  21. package/src/IMQRPCResponse.js +25 -2
  22. package/src/IMQRequestContext.d.ts +2 -2
  23. package/src/IMQRequestContext.js +6 -8
  24. package/src/IMQService.d.ts +2 -2
  25. package/src/IMQService.js +36 -75
  26. package/src/cache/ICache.js +1 -2
  27. package/src/cache/RedisCache.d.ts +3 -23
  28. package/src/cache/RedisCache.js +14 -17
  29. package/src/cache/index.d.ts +2 -2
  30. package/src/cache/index.js +2 -18
  31. package/src/decorators/cache.d.ts +1 -1
  32. package/src/decorators/cache.js +14 -15
  33. package/src/decorators/classType.js +3 -6
  34. package/src/decorators/expose.d.ts +18 -0
  35. package/src/decorators/expose.js +188 -18
  36. package/src/decorators/index.d.ts +9 -9
  37. package/src/decorators/index.js +9 -25
  38. package/src/decorators/indexed.d.ts +1 -1
  39. package/src/decorators/indexed.js +6 -9
  40. package/src/decorators/lock.js +8 -11
  41. package/src/decorators/logged.d.ts +1 -1
  42. package/src/decorators/logged.js +25 -4
  43. package/src/decorators/metadata.js +1 -2
  44. package/src/decorators/property.js +7 -11
  45. package/src/decorators/remote.js +1 -4
  46. package/src/helpers/fs.js +7 -12
  47. package/src/helpers/index.d.ts +4 -4
  48. package/src/helpers/index.js +4 -20
  49. package/src/helpers/os-uuid.js +5 -8
  50. package/src/helpers/pid.d.ts +1 -1
  51. package/src/helpers/pid.js +12 -16
  52. package/src/helpers/signature.js +3 -6
  53. package/src/index.d.ts +14 -14
  54. package/src/index.js +14 -30
  55. package/tsconfig.json +5 -2
@@ -1,9 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AFTER_HOOK_ERROR = exports.BEFORE_HOOK_ERROR = void 0;
4
- exports.IMQError = IMQError;
5
- exports.BEFORE_HOOK_ERROR = 'Before call hook error:';
6
- exports.AFTER_HOOK_ERROR = 'After call hook error:';
1
+ /*!
2
+ * IMQ-RPC Interfaces: IMQRPCError
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 {} from '@imqueue/core';
25
+ export const BEFORE_HOOK_ERROR = 'Before call hook error:';
26
+ export const AFTER_HOOK_ERROR = 'After call hook error:';
7
27
  /**
8
28
  * Builds a JSON representation of an IMQ error.
9
29
  *
@@ -15,7 +35,7 @@ exports.AFTER_HOOK_ERROR = 'After call hook error:';
15
35
  * @param {unknown} [original] - original error thrown (JSON-serialized), if any
16
36
  * @return {IMQRPCError}
17
37
  */
18
- function IMQError(code, message, stack, method, args, original) {
38
+ export function IMQError(code, message, stack, method, args, original) {
19
39
  return {
20
40
  code,
21
41
  message,
@@ -21,11 +21,11 @@
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 { IMQOptions } from '@imqueue/core';
25
- import { IMQRPCRequest } from './IMQRPCRequest';
26
- import { IMQRPCResponse } from './IMQRPCResponse';
27
- import { IMQService } from './IMQService';
28
- import { IMQClient } from './IMQClient';
24
+ import { type IMQOptions } from '@imqueue/core';
25
+ import { type IMQRPCRequest } from './IMQRPCRequest.js';
26
+ import { type IMQRPCResponse } from './IMQRPCResponse.js';
27
+ import { IMQService } from './IMQService.js';
28
+ import { IMQClient } from './IMQClient.js';
29
29
  /**
30
30
  * Hook invoked before a service method call is dispatched.
31
31
  *
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_IMQ_CLIENT_OPTIONS = exports.DEFAULT_IMQ_METRICS_SERVER_OPTIONS = exports.DEFAULT_IMQ_SERVICE_OPTIONS = void 0;
4
1
  /*!
5
2
  * IMQ-RPC Interfaces: IMQServiceOptions
6
3
  *
@@ -24,14 +21,18 @@ exports.DEFAULT_IMQ_CLIENT_OPTIONS = exports.DEFAULT_IMQ_METRICS_SERVER_OPTIONS
24
21
  * purchase a proprietary commercial license. Please contact us at
25
22
  * <support@imqueue.com> to get commercial licensing options.
26
23
  */
27
- const core_1 = require("@imqueue/core");
24
+ import { DEFAULT_IMQ_OPTIONS } from '@imqueue/core';
25
+ import {} from './IMQRPCRequest.js';
26
+ import {} from './IMQRPCResponse.js';
27
+ import { IMQService } from './IMQService.js';
28
+ import { IMQClient } from './IMQClient.js';
28
29
  /**
29
30
  * Default service options
30
31
  *
31
32
  * @type {IMQServiceOptions}
32
33
  */
33
- exports.DEFAULT_IMQ_SERVICE_OPTIONS = {
34
- ...core_1.DEFAULT_IMQ_OPTIONS,
34
+ export const DEFAULT_IMQ_SERVICE_OPTIONS = {
35
+ ...DEFAULT_IMQ_OPTIONS,
35
36
  cleanup: true,
36
37
  cleanupFilter: '*:client',
37
38
  multiProcess: false,
@@ -42,7 +43,7 @@ exports.DEFAULT_IMQ_SERVICE_OPTIONS = {
42
43
  *
43
44
  * @type {NonNullable<IMQMetricsServerOptions>}
44
45
  */
45
- exports.DEFAULT_IMQ_METRICS_SERVER_OPTIONS = {
46
+ export const DEFAULT_IMQ_METRICS_SERVER_OPTIONS = {
46
47
  enabled: false,
47
48
  port: 9090,
48
49
  queueLengthFormatter: (length, metricName) => `${metricName}{} ${length}`,
@@ -52,8 +53,8 @@ exports.DEFAULT_IMQ_METRICS_SERVER_OPTIONS = {
52
53
  *
53
54
  * @type {IMQClientOptions}
54
55
  */
55
- exports.DEFAULT_IMQ_CLIENT_OPTIONS = {
56
- ...core_1.DEFAULT_IMQ_OPTIONS,
56
+ export const DEFAULT_IMQ_CLIENT_OPTIONS = {
57
+ ...DEFAULT_IMQ_OPTIONS,
57
58
  cleanup: true,
58
59
  cleanupFilter: '*:client',
59
60
  path: './src/clients',
@@ -21,8 +21,8 @@
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 { JsonObject } from '@imqueue/core';
25
- import { IMQMetadata } from './IMQMetadata';
24
+ import { type JsonObject } from '@imqueue/core';
25
+ import { IMQMetadata } from './IMQMetadata.js';
26
26
  /**
27
27
  * Request message data structure to be handled by a service.
28
28
  */
@@ -1,3 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ /*!
2
+ * IMQ-RPC Interfaces: IMQRPCRequest
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 {} from '@imqueue/core';
25
+ import { IMQMetadata } from './IMQMetadata.js';
3
26
  //# sourceMappingURL=IMQRPCRequest.js.map
@@ -21,8 +21,8 @@
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 { JsonObject } from '@imqueue/core';
25
- import { IMQRPCError, IMQRPCRequest } from '.';
24
+ import { type JsonObject } from '@imqueue/core';
25
+ import { type IMQRPCError, type IMQRPCRequest } from './index.js';
26
26
  /**
27
27
  * Response message data structure that a service replies with to handled
28
28
  * requests.
@@ -1,3 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ /*!
2
+ * IMQ-RPC Interfaces: IMQRPCResponse
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 {} from '@imqueue/core';
25
+ import {} from './index.js';
3
26
  //# sourceMappingURL=IMQRPCResponse.js.map
@@ -1,5 +1,5 @@
1
- import { IMQMetadata } from './IMQMetadata';
2
- import { IMQRPCRequest } from './IMQRPCRequest';
1
+ import { IMQMetadata } from './IMQMetadata.js';
2
+ import { type IMQRPCRequest } from './IMQRPCRequest.js';
3
3
  /**
4
4
  * Runs the given function with `request` bound to the current async execution
5
5
  * context, so any code reached from it (and its asynchronous continuations) can
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runWithRequest = runWithRequest;
4
- exports.currentMetadata = currentMetadata;
5
1
  /*!
6
2
  * IMQRequestContext implementation
7
3
  *
@@ -25,8 +21,10 @@ exports.currentMetadata = currentMetadata;
25
21
  * purchase a proprietary commercial license. Please contact us at
26
22
  * <support@imqueue.com> to get commercial licensing options.
27
23
  */
28
- const node_async_hooks_1 = require("node:async_hooks");
29
- const storage = new node_async_hooks_1.AsyncLocalStorage();
24
+ import { AsyncLocalStorage } from 'node:async_hooks';
25
+ import { IMQMetadata } from './IMQMetadata.js';
26
+ import {} from './IMQRPCRequest.js';
27
+ const storage = new AsyncLocalStorage();
30
28
  /**
31
29
  * Runs the given function with `request` bound to the current async execution
32
30
  * context, so any code reached from it (and its asynchronous continuations) can
@@ -41,7 +39,7 @@ const storage = new node_async_hooks_1.AsyncLocalStorage();
41
39
  * @param {() => T} fn - the work to run within the bound context
42
40
  * @return {T}
43
41
  */
44
- function runWithRequest(request, fn) {
42
+ export function runWithRequest(request, fn) {
45
43
  return storage.run(request, fn);
46
44
  }
47
45
  /**
@@ -51,7 +49,7 @@ function runWithRequest(request, fn) {
51
49
  *
52
50
  * @return {IMQMetadata | undefined}
53
51
  */
54
- function currentMetadata() {
52
+ export function currentMetadata() {
55
53
  return storage.getStore()?.metadata;
56
54
  }
57
55
  //# sourceMappingURL=IMQRequestContext.js.map
@@ -21,8 +21,8 @@
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 { JsonObject, ILogger, IMessageQueue } from '@imqueue/core';
25
- import { TypesDescription, IMQRPCRequest, IMQRPCResponse, IMQServiceOptions, ICache, MethodsCollectionDescription } from '.';
24
+ import { type JsonObject, type ILogger, type IMessageQueue } from '@imqueue/core';
25
+ import { type TypesDescription, type IMQRPCRequest, type IMQRPCResponse, type IMQServiceOptions, type ICache, type MethodsCollectionDescription } from './index.js';
26
26
  import { type Server } from 'node:http';
27
27
  export declare class Description {
28
28
  service: {
package/src/IMQService.js CHANGED
@@ -1,20 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
1
  var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
19
2
  var useValue = arguments.length > 2;
20
3
  for (var i = 0; i < initializers.length; i++) {
@@ -49,29 +32,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
49
32
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
50
33
  done = true;
51
34
  };
52
- var __importStar = (this && this.__importStar) || (function () {
53
- var ownKeys = function(o) {
54
- ownKeys = Object.getOwnPropertyNames || function (o) {
55
- var ar = [];
56
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
57
- return ar;
58
- };
59
- return ownKeys(o);
60
- };
61
- return function (mod) {
62
- if (mod && mod.__esModule) return mod;
63
- var result = {};
64
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
65
- __setModuleDefault(result, mod);
66
- return result;
67
- };
68
- })();
69
- var __importDefault = (this && this.__importDefault) || function (mod) {
70
- return (mod && mod.__esModule) ? mod : { "default": mod };
71
- };
72
- Object.defineProperty(exports, "__esModule", { value: true });
73
- exports.IMQService = exports.Description = void 0;
74
- exports.send = send;
75
35
  /*!
76
36
  * IMQService implementation
77
37
  *
@@ -95,18 +55,19 @@ exports.send = send;
95
55
  * purchase a proprietary commercial license. Please contact us at
96
56
  * <support@imqueue.com> to get commercial licensing options.
97
57
  */
98
- const core_1 = __importStar(require("@imqueue/core"));
99
- const _1 = require(".");
100
- const helpers_1 = require("./helpers");
101
- const node_os_1 = require("node:os");
102
- const node_cluster_1 = __importDefault(require("node:cluster"));
103
- const IMQRequestContext_1 = require("./IMQRequestContext");
104
- const node_http_1 = require("node:http");
105
- class Description {
58
+ import IMQ, { profile, IMQ_SHUTDOWN_TIMEOUT, } from '@imqueue/core';
59
+ import { IMQRPCDescription, IMQError, expose, DEFAULT_IMQ_SERVICE_OPTIONS, AFTER_HOOK_ERROR, BEFORE_HOOK_ERROR, DEFAULT_IMQ_METRICS_SERVER_OPTIONS, } from './index.js';
60
+ import { SIGNALS } from './helpers/index.js';
61
+ import { cpus } from 'node:os';
62
+ import cluster, {} from 'node:cluster';
63
+ import {} from './IMQRPCDescription.js';
64
+ import {} from './IMQRPCOptions.js';
65
+ import { runWithRequest } from './IMQRequestContext.js';
66
+ import { createServer } from 'node:http';
67
+ export class Description {
106
68
  service;
107
69
  types;
108
70
  }
109
- exports.Description = Description;
110
71
  const serviceDescriptions = new Map();
111
72
  /**
112
73
  * Returns collection of class methods metadata even those are inherited
@@ -117,9 +78,9 @@ const serviceDescriptions = new Map();
117
78
  */
118
79
  function getClassMethods(className) {
119
80
  let methods = {};
120
- let classInfo = _1.IMQRPCDescription.serviceDescription[className];
81
+ let classInfo = IMQRPCDescription.serviceDescription[className];
121
82
  if (classInfo.inherits &&
122
- _1.IMQRPCDescription.serviceDescription[classInfo.inherits]) {
83
+ IMQRPCDescription.serviceDescription[classInfo.inherits]) {
123
84
  Object.assign(methods, getClassMethods(classInfo.inherits));
124
85
  }
125
86
  Object.assign(methods, classInfo.methods);
@@ -150,10 +111,10 @@ let IMQService = (() => {
150
111
  return class IMQService {
151
112
  static {
152
113
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
153
- _start_decorators = [(0, core_1.profile)()];
154
- _stop_decorators = [(0, core_1.profile)()];
155
- _destroy_decorators = [(0, core_1.profile)()];
156
- _describe_decorators = [(0, _1.expose)()];
114
+ _start_decorators = [profile()];
115
+ _stop_decorators = [profile()];
116
+ _destroy_decorators = [profile()];
117
+ _describe_decorators = [expose()];
157
118
  __esDecorate(this, null, _start_decorators, { kind: "method", name: "start", static: false, private: false, access: { has: obj => "start" in obj, get: obj => obj.start }, metadata: _metadata }, null, _instanceExtraInitializers);
158
119
  __esDecorate(this, null, _stop_decorators, { kind: "method", name: "stop", static: false, private: false, access: { has: obj => "stop" in obj, get: obj => obj.stop }, metadata: _metadata }, null, _instanceExtraInitializers);
159
120
  __esDecorate(this, null, _destroy_decorators, { kind: "method", name: "destroy", static: false, private: false, access: { has: obj => "destroy" in obj, get: obj => obj.destroy }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -180,23 +141,23 @@ let IMQService = (() => {
180
141
  'be instantiated directly!');
181
142
  }
182
143
  this.options = {
183
- ..._1.DEFAULT_IMQ_SERVICE_OPTIONS,
144
+ ...DEFAULT_IMQ_SERVICE_OPTIONS,
184
145
  ...options,
185
146
  metricsServer: {
186
- ..._1.DEFAULT_IMQ_METRICS_SERVER_OPTIONS,
147
+ ...DEFAULT_IMQ_METRICS_SERVER_OPTIONS,
187
148
  ...options?.metricsServer,
188
149
  },
189
150
  };
190
151
  this.logger = this.options.logger || /* istanbul ignore next */ console;
191
- this.imq = core_1.default.create(this.name, this.options);
152
+ this.imq = IMQ.create(this.name, this.options);
192
153
  this.handleRequest = this.handleRequest.bind(this);
193
- helpers_1.SIGNALS.forEach((signal) => {
154
+ SIGNALS.forEach((signal) => {
194
155
  const handler = () => {
195
156
  this.destroy().catch(this.logger.error);
196
157
  if (this.metricsServer) {
197
158
  this.metricsServer.close();
198
159
  }
199
- setTimeout(() => process.exit(0), core_1.IMQ_SHUTDOWN_TIMEOUT);
160
+ setTimeout(() => process.exit(0), IMQ_SHUTDOWN_TIMEOUT);
200
161
  };
201
162
  // tracked so destroy() can unregister them (see below)
202
163
  this.signalHandlers.push([signal, handler]);
@@ -215,7 +176,7 @@ let IMQService = (() => {
215
176
  * @return {Promise<string>}
216
177
  */
217
178
  async handleRequest(request, id) {
218
- return (0, IMQRequestContext_1.runWithRequest)(request, () => this.processRequest(request, id));
179
+ return runWithRequest(request, () => this.processRequest(request, id));
219
180
  }
220
181
  async processRequest(request, id) {
221
182
  const logger = this.options.logger || console;
@@ -234,11 +195,11 @@ let IMQService = (() => {
234
195
  await beforeCall(request, response);
235
196
  }
236
197
  catch (err) {
237
- logger.warn(_1.BEFORE_HOOK_ERROR, err);
198
+ logger.warn(BEFORE_HOOK_ERROR, err);
238
199
  }
239
200
  }
240
201
  if (!this[method]) {
241
- response.error = (0, _1.IMQError)('IMQ_RPC_NO_METHOD', `Method ${this.name}.${method}() does not exist.`, new Error().stack, method, args);
202
+ response.error = IMQError('IMQ_RPC_NO_METHOD', `Method ${this.name}.${method}() does not exist.`, new Error().stack, method, args);
242
203
  }
243
204
  else if (!description.service.methods[method]) {
244
205
  // Allow calling runtime-attached methods (own props) even if
@@ -251,11 +212,11 @@ let IMQService = (() => {
251
212
  const isSameAsProto = typeof protoValue === 'function' && value === protoValue;
252
213
  // Allow only truly dynamic own-instance functions (not the same as prototype)
253
214
  if (!(isOwn && typeof value === 'function' && !isSameAsProto)) {
254
- response.error = (0, _1.IMQError)('IMQ_RPC_NO_ACCESS', `Access to ${this.name}.${method}() denied!`, new Error().stack, method, args);
215
+ response.error = IMQError('IMQ_RPC_NO_ACCESS', `Access to ${this.name}.${method}() denied!`, new Error().stack, method, args);
255
216
  }
256
217
  }
257
218
  else if (!isValidArgsCount(description.service.methods[method].arguments, args)) {
258
- response.error = (0, _1.IMQError)('IMQ_RPC_INVALID_ARGS_COUNT', `Invalid args count for ${this.name}.${method}().`, new Error().stack, method, args);
219
+ response.error = IMQError('IMQ_RPC_INVALID_ARGS_COUNT', `Invalid args count for ${this.name}.${method}().`, new Error().stack, method, args);
259
220
  }
260
221
  if (response.error) {
261
222
  this.logger.warn(response.error);
@@ -268,7 +229,7 @@ let IMQService = (() => {
268
229
  }
269
230
  }
270
231
  catch (err) {
271
- response.error = (0, _1.IMQError)(err.code || 'IMQ_RPC_CALL_ERROR', err.message, err.stack, method, args, err);
232
+ response.error = IMQError(err.code || 'IMQ_RPC_CALL_ERROR', err.message, err.stack, method, args, err);
272
233
  }
273
234
  return await send(request, response, this);
274
235
  }
@@ -284,14 +245,14 @@ let IMQService = (() => {
284
245
  this.describe();
285
246
  return this.startWithMetricsServer();
286
247
  }
287
- if (node_cluster_1.default.isMaster) {
288
- const numCpus = (0, node_os_1.cpus)().length;
248
+ if (cluster.isMaster) {
249
+ const numCpus = cpus().length;
289
250
  const numWorkers = numCpus * this.options.childrenPerCore;
290
251
  for (let i = 0; i < numWorkers; i++) {
291
252
  this.logger.info('%s: starting worker #%s ...', this.name, i);
292
- node_cluster_1.default.fork({ workerId: i });
253
+ cluster.fork({ workerId: i });
293
254
  }
294
- node_cluster_1.default.on('exit', (worker) => {
255
+ cluster.on('exit', (worker) => {
295
256
  /* node:coverage disable */
296
257
  // exercised by tests, but V8 will not record coverage for an
297
258
  // inline listener body that terminates via process.exit()
@@ -351,7 +312,7 @@ let IMQService = (() => {
351
312
  name: this.name,
352
313
  methods: getClassMethods(this.constructor.name),
353
314
  },
354
- types: _1.IMQRPCDescription.typesDescription,
315
+ types: IMQRPCDescription.typesDescription,
355
316
  };
356
317
  serviceDescriptions.set(this.name, description);
357
318
  }
@@ -364,7 +325,7 @@ let IMQService = (() => {
364
325
  return service;
365
326
  }
366
327
  this.logger.log('Starting metrics server...');
367
- this.metricsServer = (0, node_http_1.createServer)(async (req, res) => {
328
+ this.metricsServer = createServer(async (req, res) => {
368
329
  if (req.url === '/metrics') {
369
330
  const length = await this.imq.queueLength();
370
331
  const content = metricServerOptions.queueLengthFormatter?.(length, 'queue_length') || String(length);
@@ -384,7 +345,7 @@ let IMQService = (() => {
384
345
  }
385
346
  };
386
347
  })();
387
- exports.IMQService = IMQService;
348
+ export { IMQService };
388
349
  /**
389
350
  * Sends IMQ response with support of after call optional hook
390
351
  *
@@ -393,7 +354,7 @@ exports.IMQService = IMQService;
393
354
  * @param {IMQService} service - imq service to bind
394
355
  * @return {Promise<string>} - send result message identifier
395
356
  */
396
- async function send(request, response, service) {
357
+ export async function send(request, response, service) {
397
358
  const logger = service.options.logger || console;
398
359
  const id = await service.imq.send(request.from, response);
399
360
  if (typeof service.options.afterCall === 'function') {
@@ -402,7 +363,7 @@ async function send(request, response, service) {
402
363
  await afterCall(request, response);
403
364
  }
404
365
  catch (err) {
405
- logger.warn(_1.AFTER_HOOK_ERROR, err);
366
+ logger.warn(AFTER_HOOK_ERROR, err);
406
367
  }
407
368
  }
408
369
  return id;
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=ICache.js.map
@@ -21,32 +21,12 @@
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 { ILogger, IRedisClient, IMQOptions } from '@imqueue/core';
25
- import { ICache } from '.';
24
+ import { type IRedisClient, type IMQOptions } from '@imqueue/core';
25
+ import { type ICache } from './index.js';
26
26
  export interface IRedisCacheOptions extends Partial<IMQOptions> {
27
27
  conn?: IRedisClient;
28
28
  }
29
- export declare const DEFAULT_REDIS_CACHE_OPTIONS: {
30
- id?: string;
31
- host?: string | undefined;
32
- port?: number | undefined;
33
- username?: string;
34
- password?: string;
35
- cleanup: boolean;
36
- cleanupFilter: string;
37
- vendor?: string;
38
- logger?: ILogger;
39
- watcherCheckDelay?: number;
40
- useGzip?: boolean;
41
- safeDelivery?: boolean;
42
- safeDeliveryTtl?: number;
43
- cluster?: import("@imqueue/core", { with: { "resolution-mode": "import" } }).IMessageQueueConnection[];
44
- clusterManagers?: import("../../node_modules/@imqueue/core/src/ClusterManager.js", { with: { "resolution-mode": "import" } }).ClusterManager[];
45
- handleSignals?: boolean;
46
- verbose?: boolean;
47
- verboseExtended?: boolean;
48
- prefix: string;
49
- };
29
+ export declare const DEFAULT_REDIS_CACHE_OPTIONS: IMQOptions;
50
30
  export declare const REDIS_CLIENT_INIT_ERROR = "Redis client is not initialized!";
51
31
  /**
52
32
  * Class RedisCache. Implements a cache engine on top of Redis.
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisCache = exports.REDIS_CLIENT_INIT_ERROR = exports.DEFAULT_REDIS_CACHE_OPTIONS = void 0;
4
1
  /*!
5
2
  * RedisCache adapter implementation
6
3
  *
@@ -24,17 +21,18 @@ exports.RedisCache = exports.REDIS_CLIENT_INIT_ERROR = exports.DEFAULT_REDIS_CAC
24
21
  * purchase a proprietary commercial license. Please contact us at
25
22
  * <support@imqueue.com> to get commercial licensing options.
26
23
  */
27
- const core_1 = require("@imqueue/core");
28
- const node_os_1 = require("node:os");
29
- exports.DEFAULT_REDIS_CACHE_OPTIONS = {
30
- ...core_1.DEFAULT_IMQ_OPTIONS,
24
+ import { DEFAULT_IMQ_OPTIONS, Redis, } from '@imqueue/core';
25
+ import { hostname } from 'node:os';
26
+ import {} from './index.js';
27
+ export const DEFAULT_REDIS_CACHE_OPTIONS = {
28
+ ...DEFAULT_IMQ_OPTIONS,
31
29
  prefix: 'imq-cache',
32
30
  };
33
- exports.REDIS_CLIENT_INIT_ERROR = 'Redis client is not initialized!';
31
+ export const REDIS_CLIENT_INIT_ERROR = 'Redis client is not initialized!';
34
32
  /**
35
33
  * Class RedisCache. Implements a cache engine on top of Redis.
36
34
  */
37
- class RedisCache {
35
+ export class RedisCache {
38
36
  static redis;
39
37
  // pending shared connection attempt; concurrent init() calls await this
40
38
  // single promise instead of opening one connection each
@@ -53,7 +51,7 @@ class RedisCache {
53
51
  */
54
52
  async init(options) {
55
53
  this.options = {
56
- ...exports.DEFAULT_REDIS_CACHE_OPTIONS,
54
+ ...DEFAULT_REDIS_CACHE_OPTIONS,
57
55
  ...options,
58
56
  };
59
57
  this.logger = this.options.logger || console;
@@ -69,8 +67,8 @@ class RedisCache {
69
67
  }
70
68
  if (!RedisCache.initPromise) {
71
69
  RedisCache.initPromise = new Promise((resolve, reject) => {
72
- const connectionName = `${this.options.prefix}:${this.name}:pid:${process.pid}:host:${(0, node_os_1.hostname)()}`;
73
- RedisCache.redis = new core_1.Redis({
70
+ const connectionName = `${this.options.prefix}:${this.name}:pid:${process.pid}:host:${hostname()}`;
71
+ RedisCache.redis = new Redis({
74
72
  port: Number(this.options.port),
75
73
  host: String(this.options.host),
76
74
  username: this.options.username,
@@ -116,7 +114,7 @@ class RedisCache {
116
114
  */
117
115
  async get(key) {
118
116
  if (!RedisCache.redis) {
119
- throw new TypeError(exports.REDIS_CLIENT_INIT_ERROR);
117
+ throw new TypeError(REDIS_CLIENT_INIT_ERROR);
120
118
  }
121
119
  const data = await RedisCache.redis.get(this.key(key));
122
120
  if (data) {
@@ -139,7 +137,7 @@ class RedisCache {
139
137
  */
140
138
  async set(key, value, ttl, nx = false) {
141
139
  if (!RedisCache.redis) {
142
- throw new TypeError(exports.REDIS_CLIENT_INIT_ERROR);
140
+ throw new TypeError(REDIS_CLIENT_INIT_ERROR);
143
141
  }
144
142
  const args = [
145
143
  this.key(key),
@@ -161,7 +159,7 @@ class RedisCache {
161
159
  */
162
160
  async del(key) {
163
161
  if (!RedisCache.redis) {
164
- throw new TypeError(exports.REDIS_CLIENT_INIT_ERROR);
162
+ throw new TypeError(REDIS_CLIENT_INIT_ERROR);
165
163
  }
166
164
  return !!(await RedisCache.redis.del(this.key(key)));
167
165
  }
@@ -173,7 +171,7 @@ class RedisCache {
173
171
  */
174
172
  async purge(keyMask) {
175
173
  if (!RedisCache.redis) {
176
- throw new TypeError(exports.REDIS_CLIENT_INIT_ERROR);
174
+ throw new TypeError(REDIS_CLIENT_INIT_ERROR);
177
175
  }
178
176
  try {
179
177
  await RedisCache.redis.eval(`for _,k in ipairs(redis.call('keys','${keyMask}')) do redis.call('del',k) end`, 0);
@@ -202,5 +200,4 @@ class RedisCache {
202
200
  catch { }
203
201
  }
204
202
  }
205
- exports.RedisCache = RedisCache;
206
203
  //# sourceMappingURL=RedisCache.js.map
@@ -21,5 +21,5 @@
21
21
  * purchase a proprietary commercial license. Please contact us at
22
22
  * <support@imqueue.com> to get commercial licensing options.
23
23
  */
24
- export * from './ICache';
25
- export * from './RedisCache';
24
+ export * from './ICache.js';
25
+ export * from './RedisCache.js';