nestjs-tsx-views
Version:
Server-side JSX/TSX rendering for your NestJS application 🚀
86 lines • 3.39 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 __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var TsxViewsModule_1;
import { Inject, Module, } from '@nestjs/common';
import { TSX_VIEWS_OPTIONS } from './tsx-views.constants.js';
import { TsxViewsMiddleware } from './tsx-views.middleware.js';
import { TsxViewsService } from './tsx-views.service.js';
export let TsxViewsModule = TsxViewsModule_1 = class TsxViewsModule {
constructor(options) {
this.options = options;
}
configure(consumer) {
var _a, _b;
consumer
.apply(TsxViewsMiddleware)
.exclude(...((_a = this.options.exclude) !== null && _a !== void 0 ? _a : []))
.forRoutes(...((_b = this.options.forRoutes) !== null && _b !== void 0 ? _b : '*'));
}
static register(options) {
return {
module: TsxViewsModule_1,
providers: [
{
provide: TSX_VIEWS_OPTIONS,
useValue: options,
},
],
};
}
static registerAsync(options) {
var _a;
const providers = this.createProviders(options);
return {
module: TsxViewsModule_1,
imports: options.imports,
providers: [
TsxViewsService,
...((_a = options.extraProviders) !== null && _a !== void 0 ? _a : []),
...providers,
],
exports: [TsxViewsService, ...providers],
};
}
static createProviders(options) {
if (options.useExisting || options.useFactory) {
return [this.createOptionsProvider(options)];
}
return [
this.createOptionsProvider(options),
{
provide: options.useClass,
useClass: options.useClass,
},
];
}
static createOptionsProvider(options) {
if (options.useFactory) {
return {
provide: TSX_VIEWS_OPTIONS,
useFactory: options.useFactory,
inject: options.inject,
};
}
return {
provide: TSX_VIEWS_OPTIONS,
useFactory: async (optionsFactory) => await optionsFactory.createTsxViewsOptions(),
inject: [options.useExisting || options.useClass],
};
}
};
TsxViewsModule = TsxViewsModule_1 = __decorate([
Module({}),
__param(0, Inject(TSX_VIEWS_OPTIONS)),
__metadata("design:paramtypes", [Object])
], TsxViewsModule);
//# sourceMappingURL=tsx-views.module.js.map