nestjs-cls
Version:
A continuation-local storage module compatible with NestJS's dependency injection.
63 lines (62 loc) • 2.73 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var ClsPluginsModule_1, ClsPluginModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClsPluginsModule = void 0;
const common_1 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
const cls_plugin_hooks_host_1 = require("./cls-plugin-hooks-host");
let ClsPluginsModule = ClsPluginsModule_1 = class ClsPluginsModule {
static createPluginModules(plugins) {
return (plugins?.map((plugin) => this.createClsPluginModule(plugin)) ?? []);
}
static registerPluginHooks() {
return {
module: ClsPluginsModule_1,
global: true,
imports: [core_1.DiscoveryModule],
providers: [cls_plugin_hooks_host_1.ClsPluginsHooksHost],
exports: [cls_plugin_hooks_host_1.ClsPluginsHooksHost],
};
}
static createClsPluginModule(plugin) {
let ClsPluginModule = ClsPluginModule_1 = class ClsPluginModule {
static forRoot() {
return {
module: ClsPluginModule_1,
imports: plugin.imports,
providers: plugin.providers,
exports: plugin.exports,
};
}
async onModuleInit() {
await plugin.onModuleInit?.();
}
async onModuleDestroy() {
await plugin.onModuleDestroy?.();
}
async onApplicationBootstrap() {
await plugin.onApplicationBootstrap?.();
}
async onApplicationShutdown(signal) {
await plugin.onApplicationShutdown?.(signal);
}
async beforeApplicationShutdown(signal) {
await plugin.beforeApplicationShutdown?.(signal);
}
};
ClsPluginModule = ClsPluginModule_1 = __decorate([
(0, common_1.Global)()
], ClsPluginModule);
return ClsPluginModule.forRoot();
}
};
exports.ClsPluginsModule = ClsPluginsModule;
exports.ClsPluginsModule = ClsPluginsModule = ClsPluginsModule_1 = __decorate([
(0, common_1.Global)()
], ClsPluginsModule);