@nest-omni/core 4.1.3-17 → 4.1.3-19
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/cache/dependencies/db.dependency.d.ts +0 -5
- package/cache/dependencies/db.dependency.js +0 -7
- package/package.json +2 -2
- package/setup/index.d.ts +1 -0
- package/setup/index.js +1 -0
- package/setup/run-in-mode.decorator.d.ts +56 -0
- package/setup/run-in-mode.decorator.js +92 -0
- package/setup/schedule.decorator.js +5 -0
- package/setup/worker.decorator.js +10 -1
|
@@ -89,11 +89,6 @@ export declare class DbDependency implements CacheDependency {
|
|
|
89
89
|
* @param name The data source name (default: 'default')
|
|
90
90
|
*/
|
|
91
91
|
static setDefaultDataSourceName(name: string): void;
|
|
92
|
-
/**
|
|
93
|
-
* Get the current fallback DataSource
|
|
94
|
-
* @deprecated Use DataSourceUtil.getDataSource() instead
|
|
95
|
-
*/
|
|
96
|
-
static getDataSource(): DataSource | null;
|
|
97
92
|
/**
|
|
98
93
|
* Get DataSource for executing queries
|
|
99
94
|
* Priority: 1. Specific dataSourceName from options, 2. Default from getDataSourceByName, 3. Fallback
|
|
@@ -91,13 +91,6 @@ class DbDependency {
|
|
|
91
91
|
static setDefaultDataSourceName(name) {
|
|
92
92
|
this.defaultDataSourceName = name;
|
|
93
93
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Get the current fallback DataSource
|
|
96
|
-
* @deprecated Use DataSourceUtil.getDataSource() instead
|
|
97
|
-
*/
|
|
98
|
-
static getDataSource() {
|
|
99
|
-
return this.fallbackDataSource;
|
|
100
|
-
}
|
|
101
94
|
/**
|
|
102
95
|
* Get DataSource for executing queries
|
|
103
96
|
* Priority: 1. Specific dataSourceName from options, 2. Default from getDataSourceByName, 3. Fallback
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-omni/core",
|
|
3
|
-
"version": "4.1.3-
|
|
3
|
+
"version": "4.1.3-19",
|
|
4
4
|
"description": "A comprehensive NestJS framework for building enterprise-grade applications with best practices",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@dataui/crud": "^5.3.4",
|
|
56
56
|
"@dataui/crud-typeorm": "^5.3.4",
|
|
57
|
-
"@nest-omni/transaction": "
|
|
57
|
+
"@nest-omni/transaction": "*",
|
|
58
58
|
"@nestjs/bull": "^11.0.4",
|
|
59
59
|
"@nestjs/common": "^11.1.7",
|
|
60
60
|
"@nestjs/config": "^4.0.2",
|
package/setup/index.d.ts
CHANGED
package/setup/index.js
CHANGED
|
@@ -18,3 +18,4 @@ __exportStar(require("./bootstrap.setup"), exports);
|
|
|
18
18
|
__exportStar(require("./mode.setup"), exports);
|
|
19
19
|
__exportStar(require("./worker.decorator"), exports);
|
|
20
20
|
__exportStar(require("./schedule.decorator"), exports);
|
|
21
|
+
__exportStar(require("./run-in-mode.decorator"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mode-Aware Method Decorators
|
|
3
|
+
*
|
|
4
|
+
* Conditional method execution based on application mode:
|
|
5
|
+
* - HTTP: Only HTTP server (no workers/schedulers)
|
|
6
|
+
* - WORKER: Only background workers and schedulers (no HTTP server)
|
|
7
|
+
* - HYBRID: Both HTTP server and workers (default)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Method only executes in HTTP mode (skipped in WORKER and HYBRID)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @RunOnlyInHttp()
|
|
15
|
+
* async handleApiRequest() {
|
|
16
|
+
* // Only runs when APP_MODE=http
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function RunOnlyInHttp(): MethodDecorator;
|
|
21
|
+
/**
|
|
22
|
+
* Method only executes in WORKER mode (skipped in HTTP and HYBRID)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* @RunOnlyInWorker()
|
|
27
|
+
* async processBackgroundJob() {
|
|
28
|
+
* // Only runs when APP_MODE=worker
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function RunOnlyInWorker(): MethodDecorator;
|
|
33
|
+
/**
|
|
34
|
+
* Method executes in HTTP or HYBRID mode (skipped in WORKER-only mode)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* @RunInHttpOrHybrid()
|
|
39
|
+
* async handleWebRequest() {
|
|
40
|
+
* // Runs in HTTP or HYBRID mode
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function RunInHttpOrHybrid(): MethodDecorator;
|
|
45
|
+
/**
|
|
46
|
+
* Method executes in WORKER or HYBRID mode (skipped in HTTP-only mode)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* @RunInWorkerOrHybrid()
|
|
51
|
+
* async processScheduledTask() {
|
|
52
|
+
* // Runs in WORKER or HYBRID mode
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function RunInWorkerOrHybrid(): MethodDecorator;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Mode-Aware Method Decorators
|
|
4
|
+
*
|
|
5
|
+
* Conditional method execution based on application mode:
|
|
6
|
+
* - HTTP: Only HTTP server (no workers/schedulers)
|
|
7
|
+
* - WORKER: Only background workers and schedulers (no HTTP server)
|
|
8
|
+
* - HYBRID: Both HTTP server and workers (default)
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.RunOnlyInHttp = RunOnlyInHttp;
|
|
12
|
+
exports.RunOnlyInWorker = RunOnlyInWorker;
|
|
13
|
+
exports.RunInHttpOrHybrid = RunInHttpOrHybrid;
|
|
14
|
+
exports.RunInWorkerOrHybrid = RunInWorkerOrHybrid;
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const mode_setup_1 = require("./mode.setup");
|
|
17
|
+
/**
|
|
18
|
+
* Create mode-restricted decorator
|
|
19
|
+
*/
|
|
20
|
+
function createModeDecorator(allowedModes) {
|
|
21
|
+
return function (target, propertyKey, descriptor) {
|
|
22
|
+
const originalMethod = descriptor.value;
|
|
23
|
+
const className = target.constructor.name;
|
|
24
|
+
const methodName = String(propertyKey);
|
|
25
|
+
const logger = new common_1.Logger(`${className}.${methodName}`);
|
|
26
|
+
descriptor.value = function (...args) {
|
|
27
|
+
const currentMode = (0, mode_setup_1.getApplicationMode)();
|
|
28
|
+
if (!allowedModes.includes(currentMode)) {
|
|
29
|
+
logger.log(`Skipped (current: ${currentMode}, allowed: ${allowedModes.join(', ')})`);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return originalMethod.apply(this, args);
|
|
33
|
+
};
|
|
34
|
+
return descriptor;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Method only executes in HTTP mode (skipped in WORKER and HYBRID)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* @RunOnlyInHttp()
|
|
43
|
+
* async handleApiRequest() {
|
|
44
|
+
* // Only runs when APP_MODE=http
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function RunOnlyInHttp() {
|
|
49
|
+
return createModeDecorator([mode_setup_1.ApplicationMode.HTTP]);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Method only executes in WORKER mode (skipped in HTTP and HYBRID)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* @RunOnlyInWorker()
|
|
57
|
+
* async processBackgroundJob() {
|
|
58
|
+
* // Only runs when APP_MODE=worker
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function RunOnlyInWorker() {
|
|
63
|
+
return createModeDecorator([mode_setup_1.ApplicationMode.WORKER]);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Method executes in HTTP or HYBRID mode (skipped in WORKER-only mode)
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* @RunInHttpOrHybrid()
|
|
71
|
+
* async handleWebRequest() {
|
|
72
|
+
* // Runs in HTTP or HYBRID mode
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function RunInHttpOrHybrid() {
|
|
77
|
+
return createModeDecorator([mode_setup_1.ApplicationMode.HTTP, mode_setup_1.ApplicationMode.HYBRID]);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Method executes in WORKER or HYBRID mode (skipped in HTTP-only mode)
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* @RunInWorkerOrHybrid()
|
|
85
|
+
* async processScheduledTask() {
|
|
86
|
+
* // Runs in WORKER or HYBRID mode
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
function RunInWorkerOrHybrid() {
|
|
91
|
+
return createModeDecorator([mode_setup_1.ApplicationMode.WORKER, mode_setup_1.ApplicationMode.HYBRID]);
|
|
92
|
+
}
|
|
@@ -73,10 +73,14 @@ function executeWithRetry(fn, options) {
|
|
|
73
73
|
function createWorkerDecorator(baseDecorator, decoratorName) {
|
|
74
74
|
return function (target, propertyKey, descriptor) {
|
|
75
75
|
const originalMethod = descriptor.value;
|
|
76
|
+
const className = target.constructor.name;
|
|
77
|
+
const methodName = String(propertyKey);
|
|
78
|
+
const logger = new common_1.Logger(`${className}.${methodName}`);
|
|
76
79
|
descriptor.value = function (...args) {
|
|
77
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
81
|
// Only execute in worker or hybrid mode
|
|
79
82
|
if (!(0, mode_setup_1.shouldProcessQueues)()) {
|
|
83
|
+
logger.log('Skipped (scheduled tasks require WORKER or HYBRID mode)');
|
|
80
84
|
return;
|
|
81
85
|
}
|
|
82
86
|
return originalMethod.apply(this, args);
|
|
@@ -102,6 +106,7 @@ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, op
|
|
|
102
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
107
|
// Only execute in worker or hybrid mode
|
|
104
108
|
if (!(0, mode_setup_1.shouldProcessQueues)()) {
|
|
109
|
+
logger.log('Skipped (scheduled tasks require WORKER or HYBRID mode)');
|
|
105
110
|
return;
|
|
106
111
|
}
|
|
107
112
|
// Get or create global instance - auto-configures from environment variables
|
|
@@ -20,6 +20,7 @@ exports.WorkerOnQueueCleaned = WorkerOnQueueCleaned;
|
|
|
20
20
|
exports.WorkerOnQueueDrained = WorkerOnQueueDrained;
|
|
21
21
|
exports.WorkerOnQueuePaused = WorkerOnQueuePaused;
|
|
22
22
|
exports.WorkerOnQueueResumed = WorkerOnQueueResumed;
|
|
23
|
+
const common_1 = require("@nestjs/common");
|
|
23
24
|
const bull_1 = require("@nestjs/bull");
|
|
24
25
|
const mode_setup_1 = require("./mode.setup");
|
|
25
26
|
/**
|
|
@@ -67,8 +68,16 @@ function WorkerProcess(name) {
|
|
|
67
68
|
if ((0, mode_setup_1.shouldProcessQueues)()) {
|
|
68
69
|
return (0, bull_1.Process)(name);
|
|
69
70
|
}
|
|
70
|
-
// In HTTP-only mode, return a
|
|
71
|
+
// In HTTP-only mode, return a decorator that logs and skips
|
|
71
72
|
return function (target, propertyKey, descriptor) {
|
|
73
|
+
const originalMethod = descriptor.value;
|
|
74
|
+
const className = target.constructor.name;
|
|
75
|
+
const methodName = String(propertyKey);
|
|
76
|
+
const logger = new common_1.Logger(`${className}.${methodName}`);
|
|
77
|
+
descriptor.value = function (...args) {
|
|
78
|
+
logger.log('Skipped (queue processors require WORKER or HYBRID mode)');
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
72
81
|
return descriptor;
|
|
73
82
|
};
|
|
74
83
|
}
|