nestjs-cls
Advanced tools
Comparing version 4.0.4 to 4.1.0
@@ -23,3 +23,3 @@ "use strict"; | ||
const cls_service_1 = require("./cls.service"); | ||
const cls_plugin_module_1 = require("./plugin/cls-plugin.module"); | ||
const cls_plugin_manager_1 = require("./plugin/cls-plugin-manager"); | ||
const proxy_provider_manager_1 = require("./proxy-provider/proxy-provider-manager"); | ||
@@ -75,3 +75,3 @@ const clsServiceProvider = { | ||
module: ClsModule_1, | ||
imports: [cls_plugin_module_1.ClsPluginModule.forRoot(options.plugins)], | ||
imports: cls_plugin_manager_1.ClsPluginManager.registerPlugins(options.plugins), | ||
providers: [ | ||
@@ -102,3 +102,3 @@ { | ||
...((_a = asyncOptions.imports) !== null && _a !== void 0 ? _a : []), | ||
cls_plugin_module_1.ClsPluginModule.forRoot(asyncOptions.plugins), | ||
...cls_plugin_manager_1.ClsPluginManager.registerPlugins(asyncOptions.plugins), | ||
], | ||
@@ -105,0 +105,0 @@ providers: [ |
@@ -5,9 +5,16 @@ import { ClsPlugin } from './cls-plugin.interface'; | ||
private static plugins; | ||
static add(plugins?: ClsPlugin[]): void; | ||
static registerPlugins(plugins?: ClsPlugin[]): { | ||
module: { | ||
new (): { | ||
onModuleInit(): Promise<void>; | ||
onModuleDestroy(): Promise<void>; | ||
}; | ||
forRoot(): any; | ||
}; | ||
imports: any[] | undefined; | ||
providers: import("@nestjs/common").Provider<any>[] | undefined; | ||
exports: any[] | undefined; | ||
}[]; | ||
static getPlugins(): ClsPlugin[]; | ||
static getPluginImports(): any[]; | ||
static getPluginProviders(): import("@nestjs/common").Provider<any>[]; | ||
static onClsInit(): Promise<void>; | ||
static onModuleInit(): Promise<void>; | ||
static onModuleDestroy(): Promise<void>; | ||
} |
@@ -5,5 +5,7 @@ "use strict"; | ||
const cls_service_globals_1 = require("../cls-service.globals"); | ||
const cls_plugin_module_1 = require("./cls-plugin.module"); | ||
class ClsPluginManager { | ||
static add(plugins = []) { | ||
static registerPlugins(plugins = []) { | ||
this.plugins.push(...plugins); | ||
return plugins.map((plugin) => (0, cls_plugin_module_1.createClsPluginModule)(plugin)); | ||
} | ||
@@ -13,8 +15,2 @@ static getPlugins() { | ||
} | ||
static getPluginImports() { | ||
return this.plugins.flatMap((plugin) => { var _a; return (_a = plugin.imports) !== null && _a !== void 0 ? _a : []; }); | ||
} | ||
static getPluginProviders() { | ||
return this.plugins.flatMap((plugin) => { var _a; return (_a = plugin.providers) !== null && _a !== void 0 ? _a : []; }); | ||
} | ||
static async onClsInit() { | ||
@@ -26,14 +22,2 @@ var _a; | ||
} | ||
static async onModuleInit() { | ||
var _a; | ||
for (const plugin of this.plugins) { | ||
await ((_a = plugin.onModuleInit) === null || _a === void 0 ? void 0 : _a.call(plugin)); | ||
} | ||
} | ||
static async onModuleDestroy() { | ||
var _a; | ||
for (const plugin of this.plugins) { | ||
await ((_a = plugin.onModuleDestroy) === null || _a === void 0 ? void 0 : _a.call(plugin)); | ||
} | ||
} | ||
} | ||
@@ -40,0 +24,0 @@ exports.ClsPluginManager = ClsPluginManager; |
import { ClsPlugin } from './cls-plugin.interface'; | ||
export declare class ClsPluginModule { | ||
static forRoot(plugins?: ClsPlugin[]): { | ||
module: typeof ClsPluginModule; | ||
imports: any[]; | ||
providers: import("@nestjs/common").Provider<any>[]; | ||
exports: import("@nestjs/common").Provider<any>[]; | ||
export declare function createClsPluginModule(plugin: ClsPlugin): { | ||
module: { | ||
new (): { | ||
onModuleInit(): Promise<void>; | ||
onModuleDestroy(): Promise<void>; | ||
}; | ||
forRoot(): any; | ||
}; | ||
onModuleInit(): Promise<void>; | ||
onModuleDestroy(): Promise<void>; | ||
} | ||
imports: any[] | undefined; | ||
providers: import("@nestjs/common").Provider<any>[] | undefined; | ||
exports: any[] | undefined; | ||
}; |
@@ -8,30 +8,31 @@ "use strict"; | ||
}; | ||
var ClsPluginModule_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ClsPluginModule = void 0; | ||
exports.createClsPluginModule = void 0; | ||
const common_1 = require("@nestjs/common"); | ||
const cls_plugin_manager_1 = require("./cls-plugin-manager"); | ||
let ClsPluginModule = ClsPluginModule_1 = class ClsPluginModule { | ||
static forRoot(plugins = []) { | ||
cls_plugin_manager_1.ClsPluginManager.add(plugins); | ||
const imports = cls_plugin_manager_1.ClsPluginManager.getPluginImports(); | ||
const providers = cls_plugin_manager_1.ClsPluginManager.getPluginProviders(); | ||
return { | ||
module: ClsPluginModule_1, | ||
imports: imports, | ||
providers: providers, | ||
exports: providers, | ||
}; | ||
} | ||
async onModuleInit() { | ||
await cls_plugin_manager_1.ClsPluginManager.onModuleInit(); | ||
} | ||
async onModuleDestroy() { | ||
await cls_plugin_manager_1.ClsPluginManager.onModuleDestroy(); | ||
} | ||
}; | ||
ClsPluginModule = ClsPluginModule_1 = __decorate([ | ||
(0, common_1.Global)() | ||
], ClsPluginModule); | ||
exports.ClsPluginModule = ClsPluginModule; | ||
function createClsPluginModule(plugin) { | ||
var ClsPluginModule_1; | ||
let ClsPluginModule = ClsPluginModule_1 = class ClsPluginModule { | ||
static forRoot() { | ||
return { | ||
module: ClsPluginModule_1, | ||
imports: plugin.imports, | ||
providers: plugin.providers, | ||
exports: plugin.exports, | ||
}; | ||
} | ||
async onModuleInit() { | ||
var _a; | ||
await ((_a = plugin.onModuleInit) === null || _a === void 0 ? void 0 : _a.call(plugin)); | ||
} | ||
async onModuleDestroy() { | ||
var _a; | ||
await ((_a = plugin.onModuleDestroy) === null || _a === void 0 ? void 0 : _a.call(plugin)); | ||
} | ||
}; | ||
ClsPluginModule = ClsPluginModule_1 = __decorate([ | ||
(0, common_1.Global)() | ||
], ClsPluginModule); | ||
return ClsPluginModule.forRoot(); | ||
} | ||
exports.createClsPluginModule = createClsPluginModule; | ||
//# sourceMappingURL=cls-plugin.module.js.map |
{ | ||
"name": "nestjs-cls", | ||
"version": "4.0.4", | ||
"version": "4.1.0", | ||
"description": "A continuation-local storage module compatible with NestJS's dependency injection.", | ||
@@ -5,0 +5,0 @@ "author": "papooch", |
81984
1784