@saihu/common 1.1.49 → 1.1.51
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/dist/consts/common.consts.d.ts +1 -1
- package/dist/consts/common.consts.d.ts.map +1 -1
- package/dist/consts/common.consts.js +1 -1
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +17 -0
- package/dist/decorators/saihu-subscribe.decorator.d.ts +12 -0
- package/dist/decorators/saihu-subscribe.decorator.d.ts.map +1 -0
- package/dist/decorators/saihu-subscribe.decorator.js +73 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -3,6 +3,6 @@ export declare const LOGIN_USER_KEY = "login_user:";
|
|
|
3
3
|
export declare const COMMON_MODULE_OPTIONS = "COMMON_MODULE_OPTIONS";
|
|
4
4
|
export declare const REDIS_SERVICE = "REDIS_SERVICE";
|
|
5
5
|
export declare const RABBITMQ_SERVICE = "RABBITMQ_SERVICE";
|
|
6
|
-
export declare const OPER_LOG_QUEUE = "
|
|
6
|
+
export declare const OPER_LOG_QUEUE = "q.oper.log.created.im-id";
|
|
7
7
|
export declare const OPER_LOG_EXCHANGE = "oper_log_exchange";
|
|
8
8
|
//# sourceMappingURL=common.consts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.consts.d.ts","sourceRoot":"","sources":["../../src/consts/common.consts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.consts.d.ts","sourceRoot":"","sources":["../../src/consts/common.consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAC5C,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,cAAc,6BAA6B,CAAC;AACzD,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
|
|
@@ -6,5 +6,5 @@ exports.LOGIN_USER_KEY = 'login_user:';
|
|
|
6
6
|
exports.COMMON_MODULE_OPTIONS = 'COMMON_MODULE_OPTIONS';
|
|
7
7
|
exports.REDIS_SERVICE = 'REDIS_SERVICE';
|
|
8
8
|
exports.RABBITMQ_SERVICE = 'RABBITMQ_SERVICE';
|
|
9
|
-
exports.OPER_LOG_QUEUE = '
|
|
9
|
+
exports.OPER_LOG_QUEUE = 'q.oper.log.created.im-id';
|
|
10
10
|
exports.OPER_LOG_EXCHANGE = 'oper_log_exchange';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./saihu-subscribe.decorator"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MessageHandlerOptions } from '@golevelup/nestjs-rabbitmq';
|
|
2
|
+
type SaihuSubscribeProps = Omit<MessageHandlerOptions, 'connection' | 'queue' | 'routingKey'> & {
|
|
3
|
+
/** Defaults to 'core' */
|
|
4
|
+
connection?: string;
|
|
5
|
+
/** Your service slug, e.g. 'im-accounting' */
|
|
6
|
+
service: string;
|
|
7
|
+
/** Single routing key string (recommended). If you pass an array, we’ll use the first to name the queue. */
|
|
8
|
+
routingKey: string | string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function SaihuSubscribe(props: SaihuSubscribeProps): MethodDecorator;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=saihu-subscribe.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saihu-subscribe.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/saihu-subscribe.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,KAAK,mBAAmB,GAAG,IAAI,CAC7B,qBAAqB,EACrB,YAAY,GAAG,OAAO,GAAG,YAAY,CACtC,GAAG;IACF,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,4GAA4G;IAC5G,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC/B,CAAC;AAuCF,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,eAAe,CA2C1E"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaihuSubscribe = SaihuSubscribe;
|
|
4
|
+
// libs/common/src/rabbit/saihu-subscribe.decorator.ts
|
|
5
|
+
const nestjs_rabbitmq_1 = require("@golevelup/nestjs-rabbitmq");
|
|
6
|
+
const topology_1 = require("../messaging/topology");
|
|
7
|
+
// --- helpers ---
|
|
8
|
+
function enumKeyFromValue(enm, val) {
|
|
9
|
+
return Object.keys(enm).find((k) => enm[k] === val);
|
|
10
|
+
}
|
|
11
|
+
function deriveDlxExchange(exchangeValue) {
|
|
12
|
+
const key = enumKeyFromValue(topology_1.Exchanges, exchangeValue);
|
|
13
|
+
if (!key)
|
|
14
|
+
return undefined;
|
|
15
|
+
return topology_1.Exchanges[`${key}_DLX`];
|
|
16
|
+
}
|
|
17
|
+
function deriveDlxRoutingKey(exchangeValue, routingKey) {
|
|
18
|
+
try {
|
|
19
|
+
const group = topology_1.RoutingKeys[exchangeValue];
|
|
20
|
+
const entry = Object.entries(group || {}).find(([, v]) => v === routingKey);
|
|
21
|
+
const logicalKey = entry === null || entry === void 0 ? void 0 : entry[0];
|
|
22
|
+
if (!logicalKey)
|
|
23
|
+
return routingKey;
|
|
24
|
+
const dlxExchange = deriveDlxExchange(exchangeValue);
|
|
25
|
+
if (!dlxExchange)
|
|
26
|
+
return routingKey;
|
|
27
|
+
const dlxGroup = topology_1.RoutingKeys[dlxExchange];
|
|
28
|
+
return (dlxGroup === null || dlxGroup === void 0 ? void 0 : dlxGroup[logicalKey]) || routingKey;
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
return routingKey;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// --- main decorator ---
|
|
35
|
+
function SaihuSubscribe(props) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const defaults = {
|
|
38
|
+
connection: 'core',
|
|
39
|
+
queueOptions: { durable: true },
|
|
40
|
+
errorHandler: (ch, msg) => ch.nack(msg, false, false),
|
|
41
|
+
};
|
|
42
|
+
// choose one routing key for queue naming if an array is provided
|
|
43
|
+
const rk = Array.isArray(props.routingKey)
|
|
44
|
+
? props.routingKey[0]
|
|
45
|
+
: props.routingKey;
|
|
46
|
+
const merged = {
|
|
47
|
+
...defaults,
|
|
48
|
+
...props,
|
|
49
|
+
routingKey: props.routingKey, // keep original (string or string[])
|
|
50
|
+
queue: (0, topology_1.q)(props.service, rk),
|
|
51
|
+
queueOptions: {
|
|
52
|
+
...(defaults.queueOptions || {}),
|
|
53
|
+
...(props.queueOptions || {}),
|
|
54
|
+
arguments: {
|
|
55
|
+
...(((_a = defaults.queueOptions) === null || _a === void 0 ? void 0 : _a.arguments) || {}),
|
|
56
|
+
...(((_b = props.queueOptions) === null || _b === void 0 ? void 0 : _b.arguments) || {}),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
// Auto-DLX (respect explicit overrides)
|
|
61
|
+
const args = merged.queueOptions.arguments || {};
|
|
62
|
+
const hasExplicitDLX = 'x-dead-letter-exchange' in args || 'x-dead-letter-routing-key' in args;
|
|
63
|
+
if (!hasExplicitDLX && merged.exchange && rk) {
|
|
64
|
+
const dlxExchange = deriveDlxExchange(merged.exchange);
|
|
65
|
+
const dlxRoutingKey = deriveDlxRoutingKey(merged.exchange, rk);
|
|
66
|
+
if (dlxExchange) {
|
|
67
|
+
args['x-dead-letter-exchange'] = dlxExchange;
|
|
68
|
+
args['x-dead-letter-routing-key'] = dlxRoutingKey;
|
|
69
|
+
}
|
|
70
|
+
merged.queueOptions.arguments = args;
|
|
71
|
+
}
|
|
72
|
+
return (0, nestjs_rabbitmq_1.RabbitSubscribe)(merged);
|
|
73
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './auth';
|
|
|
6
6
|
export * from './util';
|
|
7
7
|
export * from './logger';
|
|
8
8
|
export * from './messaging';
|
|
9
|
+
export * from './decorators';
|
|
9
10
|
export { SaihuCommonModule } from './saihu-common.module';
|
|
10
11
|
export { BaseService } from './services/base.service';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __exportStar(require("./auth"), exports);
|
|
|
23
23
|
__exportStar(require("./util"), exports);
|
|
24
24
|
__exportStar(require("./logger"), exports);
|
|
25
25
|
__exportStar(require("./messaging"), exports);
|
|
26
|
+
__exportStar(require("./decorators"), exports);
|
|
26
27
|
var saihu_common_module_1 = require("./saihu-common.module");
|
|
27
28
|
Object.defineProperty(exports, "SaihuCommonModule", { enumerable: true, get: function () { return saihu_common_module_1.SaihuCommonModule; } });
|
|
28
29
|
var base_service_1 = require("./services/base.service");
|