@xnestjs/rabbitmq 1.12.3 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -25
- package/{esm/rabbitmq-core.module.js → rabbitmq-core.module.js} +3 -0
- package/cjs/constants.js +0 -5
- package/cjs/get-rabbitmq-config.js +0 -35
- package/cjs/index.js +0 -7
- package/cjs/package.json +0 -3
- package/cjs/rabbitmq-core.module.js +0 -118
- package/cjs/rabbitmq.module.js +0 -25
- package/cjs/types.js +0 -6
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -4
- /package/{types/constants.d.ts → constants.d.ts} +0 -0
- /package/{esm/constants.js → constants.js} +0 -0
- /package/{types/get-rabbitmq-config.d.ts → get-rabbitmq-config.d.ts} +0 -0
- /package/{esm/get-rabbitmq-config.js → get-rabbitmq-config.js} +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/rabbitmq-core.module.d.ts → rabbitmq-core.module.d.ts} +0 -0
- /package/{types/rabbitmq.module.d.ts → rabbitmq.module.d.ts} +0 -0
- /package/{esm/rabbitmq.module.js → rabbitmq.module.js} +0 -0
- /package/{types/types.d.ts → types.d.ts} +0 -0
- /package/{esm/types.js → types.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xnestjs/rabbitmq",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "NestJS extension library for RabbitMQ",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,40 +17,27 @@
|
|
|
17
17
|
"rabbitmq-client": ">=5.0.0 <6"
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
|
+
"module": "./index.js",
|
|
21
|
+
"types": "./index.d.ts",
|
|
20
22
|
"exports": {
|
|
21
23
|
".": {
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"default": "./esm/index.js"
|
|
25
|
-
},
|
|
26
|
-
"require": {
|
|
27
|
-
"types": "./types/index.d.cts",
|
|
28
|
-
"default": "./cjs/index.js"
|
|
29
|
-
},
|
|
30
|
-
"default": "./esm/index.js"
|
|
24
|
+
"types": "./index.d.ts",
|
|
25
|
+
"default": "./index.js"
|
|
31
26
|
},
|
|
32
27
|
"./package.json": "./package.json"
|
|
33
28
|
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20.0"
|
|
31
|
+
},
|
|
37
32
|
"repository": {
|
|
38
33
|
"registry": "https://github.com/panates/xnestjs.git",
|
|
39
34
|
"directory": "packages/rabitmq"
|
|
40
35
|
},
|
|
41
|
-
"engines": {
|
|
42
|
-
"node": ">=16.0",
|
|
43
|
-
"npm": ">=7.0.0"
|
|
44
|
-
},
|
|
45
|
-
"files": [
|
|
46
|
-
"cjs/",
|
|
47
|
-
"esm/",
|
|
48
|
-
"types/",
|
|
49
|
-
"LICENSE",
|
|
50
|
-
"README.md"
|
|
51
|
-
],
|
|
52
36
|
"keywords": [
|
|
53
37
|
"nestjs",
|
|
54
38
|
"rabitmq"
|
|
55
|
-
]
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
56
43
|
}
|
|
@@ -9,6 +9,9 @@ import { getRabbitmqConfig } from './get-rabbitmq-config.js';
|
|
|
9
9
|
import { RmqClient, } from './types.js';
|
|
10
10
|
const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
|
|
11
11
|
let RabbitmqCoreModule = RabbitmqCoreModule_1 = class RabbitmqCoreModule {
|
|
12
|
+
client;
|
|
13
|
+
connectionOptions;
|
|
14
|
+
logger;
|
|
12
15
|
/**
|
|
13
16
|
*
|
|
14
17
|
*/
|
package/cjs/constants.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRabbitmqConfig = getRabbitmqConfig;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_process_1 = tslib_1.__importDefault(require("node:process"));
|
|
6
|
-
const objects_1 = require("@jsopen/objects");
|
|
7
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
8
|
-
function getRabbitmqConfig(init, prefix = 'RMQ_') {
|
|
9
|
-
const env = node_process_1.default.env;
|
|
10
|
-
const options = {};
|
|
11
|
-
if (Array.isArray(init))
|
|
12
|
-
options.hosts = init;
|
|
13
|
-
else if (typeof init === 'object') {
|
|
14
|
-
(0, objects_1.merge)(options, init, { deep: true });
|
|
15
|
-
}
|
|
16
|
-
else
|
|
17
|
-
options.hosts = (init || env[prefix + 'HOSTS'] || 'localhost:5672').split(/\s*,\s*/);
|
|
18
|
-
options.vhost = options.vhost ?? env[prefix + 'VHOST'];
|
|
19
|
-
options.username = options.username ?? env[prefix + 'USERNAME'];
|
|
20
|
-
options.password = options.password ?? env[prefix + 'PASSWORD'];
|
|
21
|
-
options.acquireTimeout =
|
|
22
|
-
options.acquireTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'ACQUIRE_TIMEOUT']);
|
|
23
|
-
options.connectionTimeout =
|
|
24
|
-
options.connectionTimeout ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'CONNECTION_TIMEOUT']);
|
|
25
|
-
options.frameMax = options.frameMax ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'FRAME_MAX']);
|
|
26
|
-
options.heartbeat =
|
|
27
|
-
options.heartbeat ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_INTERVAL']);
|
|
28
|
-
options.maxChannels =
|
|
29
|
-
options.maxChannels ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CHANNELS']);
|
|
30
|
-
options.retryHigh = options.retryHigh ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'RETRY_HIGH']);
|
|
31
|
-
options.retryLow = options.retryLow ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'NO_DELAY']);
|
|
32
|
-
options.lazyConnect =
|
|
33
|
-
options.lazyConnect ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LAZY_CONNECT']);
|
|
34
|
-
return (0, objects_1.omitNullish)(options);
|
|
35
|
-
}
|
package/cjs/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./constants.js"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./get-rabbitmq-config.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./rabbitmq.module.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./types.js"), exports);
|
package/cjs/package.json
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var RabbitmqCoreModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.RabbitmqCoreModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
7
|
-
const crypto = tslib_1.__importStar(require("node:crypto"));
|
|
8
|
-
const common_1 = require("@nestjs/common");
|
|
9
|
-
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
10
|
-
const constants_js_1 = require("./constants.js");
|
|
11
|
-
const get_rabbitmq_config_js_1 = require("./get-rabbitmq-config.js");
|
|
12
|
-
const types_js_1 = require("./types.js");
|
|
13
|
-
const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
|
|
14
|
-
let RabbitmqCoreModule = RabbitmqCoreModule_1 = class RabbitmqCoreModule {
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
static forRoot(moduleOptions) {
|
|
19
|
-
const connectionOptions = (0, get_rabbitmq_config_js_1.getRabbitmqConfig)(moduleOptions.useValue, moduleOptions.envPrefix);
|
|
20
|
-
return this._createDynamicModule(moduleOptions, {
|
|
21
|
-
global: moduleOptions.global,
|
|
22
|
-
providers: [
|
|
23
|
-
{
|
|
24
|
-
provide: constants_js_1.RMQ_CONNECTION_OPTIONS,
|
|
25
|
-
useValue: connectionOptions,
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
static forRootAsync(asyncOptions) {
|
|
34
|
-
node_assert_1.default.ok(asyncOptions.useFactory, 'useFactory is required');
|
|
35
|
-
return this._createDynamicModule(asyncOptions, {
|
|
36
|
-
global: asyncOptions.global,
|
|
37
|
-
providers: [
|
|
38
|
-
{
|
|
39
|
-
provide: constants_js_1.RMQ_CONNECTION_OPTIONS,
|
|
40
|
-
inject: asyncOptions.inject,
|
|
41
|
-
useFactory: async (...args) => {
|
|
42
|
-
const opts = await asyncOptions.useFactory(...args);
|
|
43
|
-
return (0, get_rabbitmq_config_js_1.getRabbitmqConfig)(opts, asyncOptions.envPrefix);
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
static _createDynamicModule(opts, metadata) {
|
|
50
|
-
const token = opts.token ?? types_js_1.RmqClient;
|
|
51
|
-
// const name = typeof token === 'string' ? token : 'RabbitMQ';
|
|
52
|
-
const logger = typeof opts.logger === 'string' ? new common_1.Logger(opts.logger) : opts.logger;
|
|
53
|
-
const providers = [
|
|
54
|
-
...(metadata.providers ?? []),
|
|
55
|
-
{
|
|
56
|
-
provide: common_1.Logger,
|
|
57
|
-
useValue: logger,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
provide: CLIENT_TOKEN,
|
|
61
|
-
useExisting: token,
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
provide: constants_js_1.RMQ_MODULE_ID,
|
|
65
|
-
useValue: crypto.randomUUID(),
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
provide: token,
|
|
69
|
-
inject: [constants_js_1.RMQ_CONNECTION_OPTIONS],
|
|
70
|
-
useFactory: async (connectionOptions) => {
|
|
71
|
-
const client = new types_js_1.RmqClient(connectionOptions);
|
|
72
|
-
if (logger) {
|
|
73
|
-
client.on('connection', () => {
|
|
74
|
-
logger.log('RabbitMQ client connected');
|
|
75
|
-
});
|
|
76
|
-
client.on('error', err => {
|
|
77
|
-
logger.error('RabbitMQ connection error: ' + err?.message);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return client;
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
return {
|
|
85
|
-
global: opts.global,
|
|
86
|
-
module: RabbitmqCoreModule_1,
|
|
87
|
-
imports: opts.imports,
|
|
88
|
-
providers,
|
|
89
|
-
exports: [constants_js_1.RMQ_CONNECTION_OPTIONS, token, ...(metadata.exports ?? [])],
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
* @constructor
|
|
95
|
-
*/
|
|
96
|
-
constructor(client, connectionOptions, logger) {
|
|
97
|
-
this.client = client;
|
|
98
|
-
this.connectionOptions = connectionOptions;
|
|
99
|
-
this.logger = logger;
|
|
100
|
-
}
|
|
101
|
-
async onApplicationBootstrap() {
|
|
102
|
-
const options = this.connectionOptions;
|
|
103
|
-
if (options.lazyConnect || !options.hosts?.length)
|
|
104
|
-
return;
|
|
105
|
-
this.logger?.log('Connecting to RabbitMQ at ' + ansi_colors_1.default.blue(options.hosts.toString()));
|
|
106
|
-
common_1.Logger.flush();
|
|
107
|
-
await this.client.onConnect();
|
|
108
|
-
}
|
|
109
|
-
onApplicationShutdown() {
|
|
110
|
-
return this.client.close();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
exports.RabbitmqCoreModule = RabbitmqCoreModule;
|
|
114
|
-
exports.RabbitmqCoreModule = RabbitmqCoreModule = RabbitmqCoreModule_1 = tslib_1.__decorate([
|
|
115
|
-
tslib_1.__param(0, (0, common_1.Inject)(CLIENT_TOKEN)),
|
|
116
|
-
tslib_1.__param(1, (0, common_1.Inject)(constants_js_1.RMQ_CONNECTION_OPTIONS)),
|
|
117
|
-
tslib_1.__metadata("design:paramtypes", [types_js_1.RmqClient, Object, common_1.Logger])
|
|
118
|
-
], RabbitmqCoreModule);
|
package/cjs/rabbitmq.module.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var RabbitmqModule_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.RabbitmqModule = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const common_1 = require("@nestjs/common");
|
|
7
|
-
const rabbitmq_core_module_js_1 = require("./rabbitmq-core.module.js");
|
|
8
|
-
let RabbitmqModule = RabbitmqModule_1 = class RabbitmqModule {
|
|
9
|
-
static forRoot(options) {
|
|
10
|
-
return {
|
|
11
|
-
module: RabbitmqModule_1,
|
|
12
|
-
imports: [rabbitmq_core_module_js_1.RabbitmqCoreModule.forRoot(options)],
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
static forRootAsync(options) {
|
|
16
|
-
return {
|
|
17
|
-
module: RabbitmqModule_1,
|
|
18
|
-
imports: [rabbitmq_core_module_js_1.RabbitmqCoreModule.forRootAsync(options)],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.RabbitmqModule = RabbitmqModule;
|
|
23
|
-
exports.RabbitmqModule = RabbitmqModule = RabbitmqModule_1 = tslib_1.__decorate([
|
|
24
|
-
(0, common_1.Module)({})
|
|
25
|
-
], RabbitmqModule);
|
package/cjs/types.js
DELETED
package/esm/package.json
DELETED
package/types/index.d.cts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|