arky-js
Version:
**Arky.js** is a powerful, annotation-based framework for building serverless applications on **AWS Lambda and API Gateway**. Inspired by Angular and NestJS, Arky.js simplifies serverless development by providing decorators for defining modules, controlle
27 lines (26 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DependencyInjection = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
class DependencyInjection {
static get(target, provideDependancies, moduleName) {
const isInjectable = Reflect.getMetadata("injectable", target);
if (!isInjectable) {
throw new Error("Target is not injectable");
}
const dependencies = Reflect.getMetadata("design:paramtypes", target) || [];
const instances = dependencies.map((dep) => DependencyInjection.get(dep, provideDependancies, moduleName));
if (!DependencyInjection.dependencies.has(target)) {
if (provideDependancies.includes(target.name)) {
DependencyInjection.dependencies.set(target, new target(...instances));
}
else {
throw new Error(target.name +
` cannot be injected, not in ${moduleName} dependany arrays`);
}
}
return DependencyInjection.dependencies.get(target);
}
}
exports.DependencyInjection = DependencyInjection;
DependencyInjection.dependencies = new Map();