@qavajs/core
Version:
qavajs framework core
61 lines • 1.86 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_path_1 = __importDefault(require("node:path"));
class ServiceHandler {
config;
services;
constructor(config) {
this.config = config;
this.services = this.loadServices();
}
async loadServices() {
if (!this.config.service)
return [];
const services = this.config.service.map(async (svcDef) => {
const svc = await svcDef;
if (typeof svc === 'string') {
try {
return import(svc);
}
catch (e) {
return import(node_path_1.default.join(process.cwd(), svc));
}
}
else if (Array.isArray(svc)) {
const [svcPath, options] = svc;
let service;
try {
service = await import(svcPath);
}
catch (e) {
service = import(node_path_1.default.join(process.cwd(), svcPath));
}
service.options = options;
return service;
}
else {
return svc;
}
});
return Promise.all(services);
}
async before() {
for (const svc of await this.services) {
if (svc.before) {
await svc.before();
}
}
}
async after(result) {
for (const svc of await this.services) {
if (svc.after) {
await svc.after(result);
}
}
}
}
exports.default = ServiceHandler;
//# sourceMappingURL=ServiceHandler.js.map