@tsed/formio
Version:
Formio package for Ts.ED framework
100 lines (99 loc) • 2.79 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { promisify } from "node:util";
import { Inject, Injectable, InjectorService } from "@tsed/di";
// @ts-ignore
import createRouter from "formio";
// @ts-ignore
import swagger from "formio/src/util/swagger.js";
// @ts-ignore
import util from "formio/src/util/util.js";
let FormioService = class FormioService {
get audit() {
return this.formio.audit || (() => { });
}
get auth() {
return this.formio.auth;
}
// istanbul ignore next
get swagger() {
return (...args) => new Promise((resolve) => swagger(...args, resolve));
}
get config() {
return this.formio.config;
}
get db() {
return this.formio.db;
}
get resources() {
return this.formio.resources;
}
get mongoose() {
return this.formio.mongoose;
}
get middleware() {
return this.formio.middleware;
}
get schemas() {
return this.formio.schemas;
}
get formio() {
return this.router.formio;
}
get hook() {
return this.formio.hook;
}
get util() {
return this.formio.util;
}
get template() {
return this.formio.template;
}
get Action() {
return this.formio.Action;
}
exportTemplate(options = {}) {
return promisify(this.formio.template.export)(options);
}
importTemplate(template) {
return promisify(this.formio.template.import.template)(template);
}
encrypt(text) {
return promisify(this.formio.encrypt)(text);
}
isInit() {
return !!this.router;
}
// istanbul ignore next
createRouter(options) {
return createRouter(options);
}
init(options, hooks = {}) {
if (options && Object.keys(options).length) {
this.router = this.createRouter(this.mapConfiguration(options));
this.bindLogger();
return this.router.init(hooks);
}
}
mapConfiguration(options) {
const { injector } = this;
const mongooseSettings = injector.settings.get("mongoose.0");
if (mongooseSettings) {
options.mongo = options.mongo || mongooseSettings.url;
options.mongoConfig = options.mongoConfig || JSON.stringify(mongooseSettings.connectionOptions);
}
return options;
}
bindLogger() {
const { injector } = this;
util.log = injector.logger.info.bind(injector.logger);
util.error = injector.logger.error.bind(injector.logger);
}
};
__decorate([
Inject(),
__metadata("design:type", InjectorService)
], FormioService.prototype, "injector", void 0);
FormioService = __decorate([
Injectable()
], FormioService);
export { FormioService };