@nestjsplus/lib-starter
Version:
Boilerplate for building installable NestJS libraries
75 lines (74 loc) • 3.22 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var ConfigManagerModule_1;
const common_1 = require("@nestjs/common");
const constants_1 = require("./constants");
let ConfigManagerModule = ConfigManagerModule_1 = class ConfigManagerModule {
static register(options) {
return {
module: ConfigManagerModule_1,
providers: [
{
provide: constants_1.CONFIG_OPTIONS,
useValue: options,
},
],
exports: [constants_1.CONFIG_OPTIONS],
};
}
static registerAsync(options) {
return {
module: ConfigManagerModule_1,
imports: options.imports || [],
providers: this.createAsyncProviders(options),
exports: [constants_1.CONFIG_OPTIONS],
};
}
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: constants_1.CONFIG_OPTIONS,
useFactory: options.useFactory,
inject: options.inject || [],
};
}
return {
name: constants_1.CONFIG_OPTIONS,
provide: constants_1.CONFIG_OPTIONS,
useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () {
return optionsFactory.createConfigOptions();
}),
inject: [options.useExisting || options.useClass],
};
}
};
ConfigManagerModule = ConfigManagerModule_1 = __decorate([
common_1.Module({})
], ConfigManagerModule);
exports.ConfigManagerModule = ConfigManagerModule;
;