@imqueue/rpc 3.1.1 → 3.2.1
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/index.d.ts +1 -1
- package/index.js +2 -18
- package/package.json +9 -5
- package/src/IMQCache.d.ts +1 -24
- package/src/IMQCache.js +37 -6
- package/src/IMQClient.d.ts +2 -2
- package/src/IMQClient.js +53 -86
- package/src/IMQDelay.js +1 -5
- package/src/IMQLock.d.ts +2 -2
- package/src/IMQLock.js +26 -6
- package/src/IMQMetadata.d.ts +1 -1
- package/src/IMQMetadata.js +25 -5
- package/src/IMQRPCDescription.js +1 -5
- package/src/IMQRPCError.d.ts +1 -1
- package/src/IMQRPCError.js +27 -7
- package/src/IMQRPCOptions.d.ts +5 -5
- package/src/IMQRPCOptions.js +10 -9
- package/src/IMQRPCRequest.d.ts +2 -2
- package/src/IMQRPCRequest.js +25 -2
- package/src/IMQRPCResponse.d.ts +2 -2
- package/src/IMQRPCResponse.js +25 -2
- package/src/IMQRequestContext.d.ts +2 -2
- package/src/IMQRequestContext.js +6 -8
- package/src/IMQService.d.ts +2 -2
- package/src/IMQService.js +36 -75
- package/src/cache/ICache.js +1 -2
- package/src/cache/RedisCache.d.ts +3 -23
- package/src/cache/RedisCache.js +14 -17
- package/src/cache/index.d.ts +2 -2
- package/src/cache/index.js +2 -18
- package/src/decorators/cache.d.ts +1 -1
- package/src/decorators/cache.js +14 -15
- package/src/decorators/classType.js +3 -6
- package/src/decorators/expose.js +6 -9
- package/src/decorators/index.d.ts +9 -9
- package/src/decorators/index.js +9 -25
- package/src/decorators/indexed.d.ts +1 -1
- package/src/decorators/indexed.js +6 -9
- package/src/decorators/lock.js +8 -11
- package/src/decorators/logged.d.ts +1 -1
- package/src/decorators/logged.js +25 -4
- package/src/decorators/metadata.js +1 -2
- package/src/decorators/property.js +7 -11
- package/src/decorators/remote.js +1 -4
- package/src/helpers/fs.js +7 -12
- package/src/helpers/index.d.ts +4 -4
- package/src/helpers/index.js +4 -20
- package/src/helpers/os-uuid.js +5 -8
- package/src/helpers/pid.d.ts +1 -1
- package/src/helpers/pid.js +12 -16
- package/src/helpers/signature.js +3 -6
- package/src/index.d.ts +14 -14
- package/src/index.js +14 -30
- package/tsconfig.json +5 -2
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,19 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
1
|
/*!
|
|
18
2
|
* I'm Queue Software Project
|
|
19
3
|
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
|
|
@@ -35,6 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
35
19
|
* purchase a proprietary commercial license. Please contact us at
|
|
36
20
|
* <support@imqueue.com> to get commercial licensing options.
|
|
37
21
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
export * from './src/index.js';
|
|
23
|
+
export * from '@imqueue/core';
|
|
40
24
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imqueue/rpc",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "RPC-like client-service implementation over messaging queue",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"redis",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"lint": "oxlint",
|
|
21
21
|
"format": "oxfmt \"index.ts\" \"debug.ts\" \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
22
22
|
"format:check": "oxfmt --check \"index.ts\" \"debug.ts\" \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
23
|
-
"test": "npm run build && node --experimental-test-module-mocks --test --test-timeout=15000 $(find test -name '*.spec.js')",
|
|
24
|
-
"test-coverage": "npm run build && node --experimental-test-module-mocks --enable-source-maps --test --experimental-test-coverage --test-timeout=15000 $(find test -name '*.spec.js')",
|
|
25
|
-
"test-lcov": "npm run build && mkdir -p coverage && node --experimental-test-module-mocks --enable-source-maps --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-timeout=15000 $(find test -name '*.spec.js'); node scripts/strip-comment-coverage.mjs coverage/lcov.info",
|
|
23
|
+
"test": "npm run build && node --experimental-test-module-mocks --import ./test/warmup.mjs --test --test-timeout=15000 $(find test -name '*.spec.js')",
|
|
24
|
+
"test-coverage": "npm run build && node --experimental-test-module-mocks --enable-source-maps --import ./test/warmup.mjs --test --experimental-test-coverage --test-timeout=15000 $(find test -name '*.spec.js')",
|
|
25
|
+
"test-lcov": "npm run build && mkdir -p coverage && node --experimental-test-module-mocks --enable-source-maps --import ./test/warmup.mjs --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-timeout=15000 $(find test -name '*.spec.js'); node scripts/strip-comment-coverage.mjs coverage/lcov.info",
|
|
26
26
|
"test-coverage-html": "npm run test-lcov; genhtml coverage/lcov.info --output-directory coverage/html --ignore-errors inconsistent,corrupt,format,mismatch && echo \"Coverage report: file://$(pwd)/coverage/html/index.html\"",
|
|
27
27
|
"test-dev": "npm run test && npm run clean-js && npm run clean-typedefs && npm run clean-maps",
|
|
28
28
|
"clean-typedefs": "find . -name '*.d.ts' -not -wholename '*node_modules*' -not -wholename '*generator*' -type f -delete",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"author": "imqueue.com <support@imqueue.com> (https://imqueue.com)",
|
|
44
44
|
"license": "GPL-3.0-only",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@imqueue/core": "^3.1
|
|
46
|
+
"@imqueue/core": "^3.2.1",
|
|
47
47
|
"acorn": "^8.17.0",
|
|
48
48
|
"typescript": "^7.0.2"
|
|
49
49
|
},
|
|
@@ -59,5 +59,9 @@
|
|
|
59
59
|
"types": "./index.d.ts",
|
|
60
60
|
"default": "./index.js"
|
|
61
61
|
}
|
|
62
|
+
},
|
|
63
|
+
"type": "module",
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=22.12.0"
|
|
62
66
|
}
|
|
63
67
|
}
|
package/src/IMQCache.d.ts
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* IMQCache implementation
|
|
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 { ICache, ICacheAdapter } from '.';
|
|
1
|
+
import { type ICache, type ICacheAdapter } from './index.js';
|
|
25
2
|
/**
|
|
26
3
|
* Generic cache registry
|
|
27
4
|
*/
|
package/src/IMQCache.js
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* IMQCache implementation
|
|
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 { RedisCache } from './cache/index.js';
|
|
25
|
+
import {} from './index.js';
|
|
26
|
+
// ES modules provide no synchronous dynamic loading, so the built-in cache
|
|
27
|
+
// adapters registrable by name are enumerated statically; custom adapters
|
|
28
|
+
// are still registrable by class or instance
|
|
29
|
+
const BUILT_IN_ADAPTERS = {
|
|
30
|
+
RedisCache: RedisCache,
|
|
31
|
+
};
|
|
4
32
|
/**
|
|
5
33
|
* Generic cache registry
|
|
6
34
|
*/
|
|
7
|
-
class IMQCache {
|
|
35
|
+
export class IMQCache {
|
|
8
36
|
static options = {};
|
|
9
37
|
static adapters = {};
|
|
10
38
|
/**
|
|
@@ -19,7 +47,11 @@ class IMQCache {
|
|
|
19
47
|
const self = IMQCache;
|
|
20
48
|
if (typeof adapter === 'string') {
|
|
21
49
|
if (!self.adapters[adapter]) {
|
|
22
|
-
|
|
50
|
+
const Adapter = BUILT_IN_ADAPTERS[adapter];
|
|
51
|
+
if (!Adapter) {
|
|
52
|
+
throw new TypeError(`IMQCache: unknown cache adapter requested: ${adapter}`);
|
|
53
|
+
}
|
|
54
|
+
self.adapters[adapter] = new Adapter();
|
|
23
55
|
}
|
|
24
56
|
}
|
|
25
57
|
else {
|
|
@@ -80,5 +112,4 @@ class IMQCache {
|
|
|
80
112
|
return IMQCache.adapters[typeof adapter === 'string' ? adapter : adapter.name];
|
|
81
113
|
}
|
|
82
114
|
}
|
|
83
|
-
exports.IMQCache = IMQCache;
|
|
84
115
|
//# sourceMappingURL=IMQCache.js.map
|
package/src/IMQClient.d.ts
CHANGED
|
@@ -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 { IMQClientOptions, IMQRPCResponse, IMQRPCRequest, IMQDelay, Description } from '.';
|
|
24
|
+
import { type JsonObject } from '@imqueue/core';
|
|
25
|
+
import { type IMQClientOptions, type IMQRPCResponse, type IMQRPCRequest, IMQDelay, Description } from './index.js';
|
|
26
26
|
import { EventEmitter } from 'node:events';
|
|
27
27
|
/**
|
|
28
28
|
* Class IMQClient - base abstract class for service clients.
|
package/src/IMQClient.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,27 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
-
exports.IMQClient = void 0;
|
|
71
|
-
exports.imqCallResolver = imqCallResolver;
|
|
72
|
-
exports.imqCallRejector = imqCallRejector;
|
|
73
35
|
/*!
|
|
74
36
|
* IMQClient implementation
|
|
75
37
|
*
|
|
@@ -93,30 +55,35 @@ exports.imqCallRejector = imqCallRejector;
|
|
|
93
55
|
* purchase a proprietary commercial license. Please contact us at
|
|
94
56
|
* <support@imqueue.com> to get commercial licensing options.
|
|
95
57
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
58
|
+
import IMQ, { IMQ_SHUTDOWN_TIMEOUT, } from '@imqueue/core';
|
|
59
|
+
import { DEFAULT_IMQ_CLIENT_OPTIONS, IMQDelay, IMQError, remote, Description, IMQMetadata, BEFORE_HOOK_ERROR, AFTER_HOOK_ERROR, } from './index.js';
|
|
60
|
+
import { pid, forgetPid, osUuid, fileExists, mkdir, writeFile, SIGNALS, } from './helpers/index.js';
|
|
61
|
+
import { EventEmitter } from 'node:events';
|
|
62
|
+
import { Script } from 'node:vm';
|
|
63
|
+
import { spawnSync } from 'node:child_process';
|
|
64
|
+
import { mkdtempSync, writeFileSync, readFileSync, existsSync, rmSync, } from 'node:fs';
|
|
65
|
+
import { createRequire } from 'node:module';
|
|
66
|
+
import { tmpdir } from 'node:os';
|
|
67
|
+
import { join, dirname } from 'node:path';
|
|
68
|
+
import {} from './IMQRPCOptions.js';
|
|
69
|
+
// CommonJS require scoped to this module: resolves the typescript package
|
|
70
|
+
// and loads generated CommonJS client modules from the ESM host
|
|
71
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
72
|
+
// Read as a file (not a static import) so that consumers which type-check
|
|
106
73
|
// this source through a file: link do not need `resolveJsonModule` enabled.
|
|
107
|
-
const tsOptions =
|
|
74
|
+
const tsOptions = JSON.parse(readFileSync(new URL('../tsconfig.json', import.meta.url), 'utf8')).compilerOptions;
|
|
108
75
|
const RX_SEMICOLON = /;+$/g;
|
|
109
76
|
/**
|
|
110
77
|
* Class IMQClient - base abstract class for service clients.
|
|
111
78
|
*/
|
|
112
79
|
let IMQClient = (() => {
|
|
113
|
-
let _classSuper =
|
|
80
|
+
let _classSuper = EventEmitter;
|
|
114
81
|
let _instanceExtraInitializers = [];
|
|
115
82
|
let _describe_decorators;
|
|
116
83
|
return class IMQClient extends _classSuper {
|
|
117
84
|
static {
|
|
118
85
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
119
|
-
_describe_decorators = [
|
|
86
|
+
_describe_decorators = [remote()];
|
|
120
87
|
__esDecorate(this, null, _describe_decorators, { kind: "method", name: "describe", static: false, private: false, access: { has: obj => "describe" in obj, get: obj => obj.describe }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
121
88
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
122
89
|
}
|
|
@@ -151,11 +118,11 @@ let IMQClient = (() => {
|
|
|
151
118
|
throw new TypeError('IMQClient class is abstract and cannot ' +
|
|
152
119
|
'be instantiated directly!');
|
|
153
120
|
}
|
|
154
|
-
this.options = { ...
|
|
155
|
-
this.id =
|
|
121
|
+
this.options = { ...DEFAULT_IMQ_CLIENT_OPTIONS, ...options };
|
|
122
|
+
this.id = pid(baseName);
|
|
156
123
|
this.logger = this.options.logger || /* istanbul ignore next */ console;
|
|
157
124
|
this.hostName =
|
|
158
|
-
IMQClient.singleImq?.name || `${
|
|
125
|
+
IMQClient.singleImq?.name || `${osUuid()}-${this.id}:client`;
|
|
159
126
|
this.name = `${baseName}-${this.hostName}`;
|
|
160
127
|
this.serviceName = serviceName || baseName.replace(/Client$/, '');
|
|
161
128
|
this.queueName = this.options.singleQueue ? this.hostName : this.name;
|
|
@@ -167,10 +134,10 @@ let IMQClient = (() => {
|
|
|
167
134
|
IMQClient.maxListenersBumped = true;
|
|
168
135
|
process.setMaxListeners(10000);
|
|
169
136
|
}
|
|
170
|
-
|
|
137
|
+
SIGNALS.forEach((signal) => {
|
|
171
138
|
const handler = () => {
|
|
172
139
|
this.destroy().catch(this.logger.error);
|
|
173
|
-
setTimeout(() => process.exit(0),
|
|
140
|
+
setTimeout(() => process.exit(0), IMQ_SHUTDOWN_TIMEOUT);
|
|
174
141
|
};
|
|
175
142
|
// tracked so destroy() can unregister them (see below)
|
|
176
143
|
this.signalHandlers.push([signal, handler]);
|
|
@@ -179,10 +146,10 @@ let IMQClient = (() => {
|
|
|
179
146
|
}
|
|
180
147
|
createImq() {
|
|
181
148
|
if (!this.options.singleQueue) {
|
|
182
|
-
return
|
|
149
|
+
return IMQ.create(this.queueName, this.options);
|
|
183
150
|
}
|
|
184
151
|
if (!IMQClient.singleImq) {
|
|
185
|
-
IMQClient.singleImq =
|
|
152
|
+
IMQClient.singleImq = IMQ.create(this.queueName, this.options);
|
|
186
153
|
}
|
|
187
154
|
// the shared queue is reference-counted so that destroying one client
|
|
188
155
|
// does not tear the transport down under the others
|
|
@@ -193,7 +160,7 @@ let IMQClient = (() => {
|
|
|
193
160
|
if (!this.options.singleQueue) {
|
|
194
161
|
return this.imq;
|
|
195
162
|
}
|
|
196
|
-
return
|
|
163
|
+
return IMQ.create(this.name, this.options);
|
|
197
164
|
}
|
|
198
165
|
/**
|
|
199
166
|
* Sends call to remote service method
|
|
@@ -209,13 +176,13 @@ let IMQClient = (() => {
|
|
|
209
176
|
const to = this.serviceName;
|
|
210
177
|
let delay = 0;
|
|
211
178
|
let metadata;
|
|
212
|
-
if (args[args.length - 1] instanceof
|
|
179
|
+
if (args[args.length - 1] instanceof IMQDelay) {
|
|
213
180
|
delay = args.pop().ms;
|
|
214
181
|
if (!isFinite(delay) || isNaN(delay) || delay < 0) {
|
|
215
182
|
delay = 0;
|
|
216
183
|
}
|
|
217
184
|
}
|
|
218
|
-
if (args[args.length - 1] instanceof
|
|
185
|
+
if (args[args.length - 1] instanceof IMQMetadata) {
|
|
219
186
|
metadata = args.pop();
|
|
220
187
|
}
|
|
221
188
|
const request = {
|
|
@@ -230,7 +197,7 @@ let IMQClient = (() => {
|
|
|
230
197
|
await beforeCall(request);
|
|
231
198
|
}
|
|
232
199
|
catch (err) {
|
|
233
|
-
logger.warn(
|
|
200
|
+
logger.warn(BEFORE_HOOK_ERROR, err);
|
|
234
201
|
}
|
|
235
202
|
}
|
|
236
203
|
const callTimeout = this.options.callTimeout;
|
|
@@ -263,7 +230,7 @@ let IMQClient = (() => {
|
|
|
263
230
|
// extends the budget accordingly
|
|
264
231
|
timer = setTimeout(() => {
|
|
265
232
|
delete this.resolvers[id];
|
|
266
|
-
doReject(
|
|
233
|
+
doReject(IMQError('IMQ_RPC_CALL_TIMEOUT', `Call to ${to}.${method}() timed out after ${callTimeout} ms.`, new Error().stack, method, args));
|
|
267
234
|
}, callTimeout + delay);
|
|
268
235
|
timer.unref?.();
|
|
269
236
|
}
|
|
@@ -356,7 +323,7 @@ let IMQClient = (() => {
|
|
|
356
323
|
}
|
|
357
324
|
this.signalHandlers.length = 0;
|
|
358
325
|
await this.subscriptionImq.unsubscribe();
|
|
359
|
-
|
|
326
|
+
forgetPid(this.baseName, this.id, this.logger);
|
|
360
327
|
this.removeAllListeners();
|
|
361
328
|
// in singleQueue mode the subscription queue is a separate,
|
|
362
329
|
// per-client instance and must be torn down with the client
|
|
@@ -394,14 +361,14 @@ let IMQClient = (() => {
|
|
|
394
361
|
*/
|
|
395
362
|
static async create(name, options) {
|
|
396
363
|
const clientOptions = {
|
|
397
|
-
...
|
|
364
|
+
...DEFAULT_IMQ_CLIENT_OPTIONS,
|
|
398
365
|
...options,
|
|
399
366
|
};
|
|
400
367
|
return await generator(name, clientOptions);
|
|
401
368
|
}
|
|
402
369
|
};
|
|
403
370
|
})();
|
|
404
|
-
|
|
371
|
+
export { IMQClient };
|
|
405
372
|
/**
|
|
406
373
|
* Builds a call resolver that resolves the pending promise and then runs the
|
|
407
374
|
* optional after-call hook.
|
|
@@ -411,7 +378,7 @@ exports.IMQClient = IMQClient;
|
|
|
411
378
|
* @param {IMQClient} client - the client the call belongs to
|
|
412
379
|
* @return {(data: any, res: IMQRPCResponse) => void} - a hook-aware resolver
|
|
413
380
|
*/
|
|
414
|
-
function imqCallResolver(resolve, req, client) {
|
|
381
|
+
export function imqCallResolver(resolve, req, client) {
|
|
415
382
|
return async (data, res) => {
|
|
416
383
|
const logger = client.options.logger || console;
|
|
417
384
|
resolve(data);
|
|
@@ -421,7 +388,7 @@ function imqCallResolver(resolve, req, client) {
|
|
|
421
388
|
await afterCall(req, res);
|
|
422
389
|
}
|
|
423
390
|
catch (err) {
|
|
424
|
-
logger.warn(
|
|
391
|
+
logger.warn(AFTER_HOOK_ERROR, err);
|
|
425
392
|
}
|
|
426
393
|
}
|
|
427
394
|
};
|
|
@@ -435,7 +402,7 @@ function imqCallResolver(resolve, req, client) {
|
|
|
435
402
|
* @param {IMQClient} client - the client the call belongs to
|
|
436
403
|
* @return {(err: any, res?: IMQRPCResponse) => void} - a hook-aware rejector
|
|
437
404
|
*/
|
|
438
|
-
function imqCallRejector(reject, req, client) {
|
|
405
|
+
export function imqCallRejector(reject, req, client) {
|
|
439
406
|
return async (err, res) => {
|
|
440
407
|
const logger = client.options.logger || console;
|
|
441
408
|
reject(err);
|
|
@@ -445,7 +412,7 @@ function imqCallRejector(reject, req, client) {
|
|
|
445
412
|
await afterCall(req, res);
|
|
446
413
|
}
|
|
447
414
|
catch (err) {
|
|
448
|
-
logger.warn(
|
|
415
|
+
logger.warn(AFTER_HOOK_ERROR, err);
|
|
449
416
|
}
|
|
450
417
|
}
|
|
451
418
|
};
|
|
@@ -668,13 +635,13 @@ function toComment(typedef, promised = false) {
|
|
|
668
635
|
* @returns {string} - emitted CommonJS JavaScript
|
|
669
636
|
*/
|
|
670
637
|
function transpileClient(src) {
|
|
671
|
-
const dir =
|
|
638
|
+
const dir = mkdtempSync(join(tmpdir(), 'imq-client-'));
|
|
672
639
|
try {
|
|
673
|
-
const tsFile =
|
|
674
|
-
const jsFile =
|
|
675
|
-
const cfgFile =
|
|
676
|
-
|
|
677
|
-
|
|
640
|
+
const tsFile = join(dir, '__client__.ts');
|
|
641
|
+
const jsFile = join(dir, '__client__.js');
|
|
642
|
+
const cfgFile = join(dir, 'tsconfig.json');
|
|
643
|
+
writeFileSync(tsFile, src);
|
|
644
|
+
writeFileSync(cfgFile, JSON.stringify({
|
|
678
645
|
compilerOptions: {
|
|
679
646
|
...tsOptions,
|
|
680
647
|
// transform-only: always emit, ignoring type and
|
|
@@ -697,19 +664,19 @@ function transpileClient(src) {
|
|
|
697
664
|
// resolve the compiler entry via the package root (its `exports` map
|
|
698
665
|
// blocks `typescript/lib/*`, so build a raw path that Node runs
|
|
699
666
|
// directly)
|
|
700
|
-
const tscJs =
|
|
701
|
-
const result =
|
|
667
|
+
const tscJs = join(dirname(cjsRequire.resolve('typescript/package.json')), 'lib', 'tsc.js');
|
|
668
|
+
const result = spawnSync(process.execPath, [tscJs, '-p', cfgFile], {
|
|
702
669
|
encoding: 'utf8',
|
|
703
670
|
});
|
|
704
|
-
if (!
|
|
671
|
+
if (!existsSync(jsFile)) {
|
|
705
672
|
throw new Error('IMQClient: client transpilation produced no output' +
|
|
706
673
|
(result.stdout ? `\n${result.stdout}` : '') +
|
|
707
674
|
(result.stderr ? `\n${result.stderr}` : ''));
|
|
708
675
|
}
|
|
709
|
-
return
|
|
676
|
+
return readFileSync(jsFile, 'utf8');
|
|
710
677
|
}
|
|
711
678
|
finally {
|
|
712
|
-
|
|
679
|
+
rmSync(dir, { recursive: true, force: true });
|
|
713
680
|
}
|
|
714
681
|
}
|
|
715
682
|
/**
|
|
@@ -726,14 +693,14 @@ async function compile(name, src, options) {
|
|
|
726
693
|
const jsFile = `${path}/${name}.js`;
|
|
727
694
|
const js = transpileClient(src);
|
|
728
695
|
if (options.write) {
|
|
729
|
-
if (!(await
|
|
730
|
-
await
|
|
696
|
+
if (!(await fileExists(path))) {
|
|
697
|
+
await mkdir(path);
|
|
731
698
|
}
|
|
732
|
-
await Promise.all([
|
|
699
|
+
await Promise.all([writeFile(srcFile, src), writeFile(jsFile, js)]);
|
|
733
700
|
}
|
|
734
701
|
if (options.compile) {
|
|
735
|
-
const script = new
|
|
736
|
-
const context = { exports: {}, require };
|
|
702
|
+
const script = new Script(js);
|
|
703
|
+
const context = { exports: {}, require: cjsRequire };
|
|
737
704
|
script.runInNewContext(context, { filename: jsFile });
|
|
738
705
|
return context.exports;
|
|
739
706
|
}
|
package/src/IMQDelay.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IMQDelay = void 0;
|
|
4
1
|
/*!
|
|
5
2
|
* IMQDelay implementation
|
|
6
3
|
*
|
|
@@ -28,7 +25,7 @@ exports.IMQDelay = void 0;
|
|
|
28
25
|
* Represents a delay expressed as a numeric timer value in a given time unit.
|
|
29
26
|
* Used to defer IMQ request processing.
|
|
30
27
|
*/
|
|
31
|
-
class IMQDelay {
|
|
28
|
+
export class IMQDelay {
|
|
32
29
|
timer;
|
|
33
30
|
unit;
|
|
34
31
|
/**
|
|
@@ -60,5 +57,4 @@ class IMQDelay {
|
|
|
60
57
|
this.unit = unit;
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
|
-
exports.IMQDelay = IMQDelay;
|
|
64
60
|
//# sourceMappingURL=IMQDelay.js.map
|
package/src/IMQLock.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
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 } from '@imqueue/core';
|
|
24
|
+
import { type ILogger } from '@imqueue/core';
|
|
25
25
|
export type AcquiredLock<T> = T | boolean;
|
|
26
26
|
export type IMQLockTask = [(...args: any[]) => any, (...args: any[]) => any];
|
|
27
27
|
export type IMQLockQueue = Array<IMQLockTask>;
|
|
@@ -39,7 +39,7 @@ export interface IMQLockMetadata {
|
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ~~~typescript
|
|
42
|
-
* import { IMQLock, AcquiredLock } from '.';
|
|
42
|
+
* import { IMQLock, AcquiredLock } from './index.js';
|
|
43
43
|
*
|
|
44
44
|
* async function doSomething(): Promise<number | AcquiredLock<number>> {
|
|
45
45
|
* const lock: AcquiredLock<number> = await IMQLock.acquire<number>('doSomething');
|
package/src/IMQLock.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* IMQLock implementation
|
|
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';
|
|
4
25
|
/**
|
|
5
26
|
* Class IMQLock.
|
|
6
27
|
* Implements promise-based locks.
|
|
7
28
|
*
|
|
8
29
|
* @example
|
|
9
30
|
* ~~~typescript
|
|
10
|
-
* import { IMQLock, AcquiredLock } from '.';
|
|
31
|
+
* import { IMQLock, AcquiredLock } from './index.js';
|
|
11
32
|
*
|
|
12
33
|
* async function doSomething(): Promise<number | AcquiredLock<number>> {
|
|
13
34
|
* const lock: AcquiredLock<number> = await IMQLock.acquire<number>('doSomething');
|
|
@@ -42,7 +63,7 @@ exports.IMQLock = void 0;
|
|
|
42
63
|
* })();
|
|
43
64
|
* ~~~
|
|
44
65
|
*/
|
|
45
|
-
class IMQLock {
|
|
66
|
+
export class IMQLock {
|
|
46
67
|
static acquiredLocks = {};
|
|
47
68
|
static queues = {};
|
|
48
69
|
static metadata = {};
|
|
@@ -152,5 +173,4 @@ class IMQLock {
|
|
|
152
173
|
return !!IMQLock.acquiredLocks[key];
|
|
153
174
|
}
|
|
154
175
|
}
|
|
155
|
-
exports.IMQLock = IMQLock;
|
|
156
176
|
//# sourceMappingURL=IMQLock.js.map
|
package/src/IMQMetadata.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
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 { AnyJson, JsonObject } from '@imqueue/core';
|
|
24
|
+
import { type AnyJson, type JsonObject } from '@imqueue/core';
|
|
25
25
|
/**
|
|
26
26
|
* Arbitrary, JSON-serializable metadata bag carried alongside an IMQ request.
|
|
27
27
|
* Each property value must be a valid JSON value.
|
package/src/IMQMetadata.js
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* IMQMetadata implementation
|
|
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';
|
|
4
25
|
/**
|
|
5
26
|
* Arbitrary, JSON-serializable metadata bag carried alongside an IMQ request.
|
|
6
27
|
* Each property value must be a valid JSON value.
|
|
7
28
|
*/
|
|
8
|
-
class IMQMetadata {
|
|
29
|
+
export class IMQMetadata {
|
|
9
30
|
/**
|
|
10
31
|
* @param {JsonObject} metadata - source object whose own enumerable
|
|
11
32
|
* properties are copied into this instance
|
|
@@ -16,5 +37,4 @@ class IMQMetadata {
|
|
|
16
37
|
}
|
|
17
38
|
}
|
|
18
39
|
}
|
|
19
|
-
exports.IMQMetadata = IMQMetadata;
|
|
20
40
|
//# sourceMappingURL=IMQMetadata.js.map
|
package/src/IMQRPCDescription.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IMQRPCDescription = void 0;
|
|
4
|
-
class IMQRPCDescription {
|
|
1
|
+
export class IMQRPCDescription {
|
|
5
2
|
static serviceDescription = {};
|
|
6
3
|
static typesDescription = {};
|
|
7
4
|
}
|
|
8
|
-
exports.IMQRPCDescription = IMQRPCDescription;
|
|
9
5
|
//# sourceMappingURL=IMQRPCDescription.js.map
|
package/src/IMQRPCError.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
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';
|
|
24
|
+
import { type JsonObject } from '@imqueue/core';
|
|
25
25
|
export declare const BEFORE_HOOK_ERROR = "Before call hook error:";
|
|
26
26
|
export declare const AFTER_HOOK_ERROR = "After call hook error:";
|
|
27
27
|
/**
|