nestjs-tencent-sms
Version:
A nestjs Tencent Sms Service
89 lines (88 loc) • 3.81 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) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var TencentSmsModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TencentSmsModule = void 0;
const common_1 = require("@nestjs/common");
const constant_1 = require("./constant");
const tencent_sms_service_1 = require("./tencent-sms.service");
let TencentSmsModule = TencentSmsModule_1 = class TencentSmsModule {
static forRoot(options) {
const provider = {
provide: constant_1.TENCENT_SMS_MODULE_OPTIONS,
useValue: options,
};
return {
global: true,
module: TencentSmsModule_1,
providers: [provider],
exports: [provider],
};
}
static forRootAsync(options) {
const imports = this.getUniqImports([options]);
const providers = this.createTencentSmsConfigurations(options);
return {
global: true,
module: TencentSmsModule_1,
imports,
providers,
exports: providers,
};
}
static createTencentSmsConfigurations(options) {
if (options.useExisting || options.useFactory) {
return [this.createTencentSmsConfiguration(options)];
}
const useClass = options.useClass;
return [
this.createTencentSmsConfiguration(options),
{
provide: useClass,
useClass,
},
];
}
static getUniqImports(options) {
return (options
.map((option) => option.imports)
.reduce((acc, i) => acc.concat(i || []), [])
.filter((v, i, a) => a.indexOf(v) === i) || []);
}
static createTencentSmsConfiguration(options) {
if (options.useFactory) {
return {
provide: constant_1.TENCENT_SMS_MODULE_OPTIONS,
useFactory: options.useFactory,
inject: options.inject || [],
};
}
const inject = [(options.useClass || options.useExisting)];
return {
provide: constant_1.TENCENT_SMS_MODULE_OPTIONS,
useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () { return optionsFactory.createTencentSmsConfiguration(); }),
inject,
};
}
};
TencentSmsModule = TencentSmsModule_1 = __decorate([
common_1.Module({
providers: [tencent_sms_service_1.TencentSmsService],
exports: [tencent_sms_service_1.TencentSmsService],
})
], TencentSmsModule);
exports.TencentSmsModule = TencentSmsModule;