zents
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
66 lines • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Injector = void 0;
const InjectorAction_1 = require("./InjectorAction");
const AllContextAction_1 = require("./InjectorAction/AllContextAction");
const BodyContextAction_1 = require("./InjectorAction/BodyContextAction");
const CookieContextAction_1 = require("./InjectorAction/CookieContextAction");
const EmailAction_1 = require("./InjectorAction/EmailAction");
const ErrorContextAction_1 = require("./InjectorAction/ErrorContextAction");
const ParamsContextAction_1 = require("./InjectorAction/ParamsContextAction");
const QueryContextAction_1 = require("./InjectorAction/QueryContextAction");
const RequestContextAction_1 = require("./InjectorAction/RequestContextAction");
const ResponseContextAction_1 = require("./InjectorAction/ResponseContextAction");
class Injector {
constructor(context) {
this.context = context;
}
inject(module, ctorArgs) {
const instance = new module(...ctorArgs);
const actions = [
new InjectorAction_1.DependenciesAction(this),
new InjectorAction_1.ConnectionAction(this),
new InjectorAction_1.RedisAction(this),
new InjectorAction_1.EntityManagerAction(this),
];
for (const action of actions) {
action.run(instance);
}
return instance;
}
async injectFunctionParameters(instance, method, context, loadedUser, injectedSessions) {
const actions = [
new InjectorAction_1.RepositoryAction(this),
new InjectorAction_1.SecurityProviderAction(this),
new InjectorAction_1.SessionAction(this, context, loadedUser, injectedSessions),
new BodyContextAction_1.BodyContextAction(this, context),
new QueryContextAction_1.QueryContextAction(this, context),
new ParamsContextAction_1.ParamsContextAction(this, context),
new CookieContextAction_1.CookieContextAction(this, context),
new RequestContextAction_1.RequestContextAction(this, context),
new ResponseContextAction_1.ResponseContextAction(this, context),
new EmailAction_1.EmailAction(this),
new ErrorContextAction_1.ErrorContextAction(this, context),
new AllContextAction_1.AllContextAction(this, context),
];
let params = [];
for (const action of actions) {
const result = await action.run(instance, method);
if (Array.isArray(result)) {
if (result.length) {
params = [...params, ...result.filter((val) => val !== null)];
}
}
else if (result) {
params.push(result);
}
}
if (!params.length) {
return [];
}
params.sort((a, b) => a.index - b.index);
return params.map((param) => param.value);
}
}
exports.Injector = Injector;
//# sourceMappingURL=Injector.js.map