@beincom/node-profile
Version:
``` npm install @beincom/node-profile # yarn add @beincom/node-profile ```
75 lines • 2.94 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 ProfileModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProfileModule = void 0;
const common_1 = require("@nestjs/common");
const profiling_service_1 = require("./profiling.service");
let ProfileModule = ProfileModule_1 = class ProfileModule {
static forRoot(config) {
return {
module: ProfileModule_1,
imports: [],
providers: [
{
provide: profiling_service_1.PROFILE_SERVICE_TOKEN,
useFactory: () => {
return new profiling_service_1.ProfileService(config);
},
},
],
exports: [profiling_service_1.PROFILE_SERVICE_TOKEN],
};
}
static forRootAsync(options) {
return {
module: ProfileModule_1,
imports: [...(options.imports || [])],
providers: [
...this._createAsyncProviders(options),
...(options.extraProviders || []),
],
exports: [
...this._createAsyncProviders(options),
...(options.extraProviders || []),
],
};
}
static _createAsyncProviders(options) {
if (options.useExisting || options.useFactory) {
return [this._createAsyncOptionsProvider(options)];
}
return [
this._createAsyncOptionsProvider(options),
{
provide: options.useClass,
useClass: options.useClass,
},
];
}
static _createAsyncOptionsProvider(options) {
if (options.useFactory) {
return {
provide: profiling_service_1.PROFILE_SERVICE_TOKEN,
useFactory: options.useFactory,
inject: options.inject || [],
};
}
return {
provide: profiling_service_1.PROFILE_SERVICE_TOKEN,
useFactory: async (optionsFactory) => optionsFactory.createOptions(),
inject: [options.useExisting || options.useClass],
};
}
};
exports.ProfileModule = ProfileModule;
exports.ProfileModule = ProfileModule = ProfileModule_1 = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({})
], ProfileModule);
//# sourceMappingURL=profiling.module.js.map