UNPKG

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

57 lines (56 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetaObjectParser = void 0; const convert_file_name_pattern_1 = require("../../utils/convert-file-name-pattern"); class MetaObjectParser { constructor(dependencyTreeWalker) { this.dependencyTreeWalker = dependencyTreeWalker; } getControllerMetaObjects(controllerDeclarations) { // const sourceFiles = this.project.addSourceFilesAtPaths(sourcePath); const controllers = []; for (const controllerDeclaration of controllerDeclarations) { const controllerMeta = this.createControllerMetaObj(controllerDeclaration.controller); if (controllerMeta) controllers.push(controllerMeta); } return controllers; } createControllerMetaObj(cls) { var _a; const controllerDecorator = cls.getDecorator("Controller"); if (!controllerDecorator) return null; const controllerRouterPath = ((_a = controllerDecorator .getArguments()[0]) === null || _a === void 0 ? void 0 : _a.getText().replace(/'/g, "").replace(/["\\/]/g, "")) || "/"; const classFilePath = cls.getSourceFile().getFilePath(); return { name: (0, convert_file_name_pattern_1.getClassNameWithSuffix)(cls.getName(), classFilePath), functionName: (0, convert_file_name_pattern_1.getFunctionName)(cls.getName(), classFilePath), fileName: (0, convert_file_name_pattern_1.getFilePathName)(cls.getName(), classFilePath), basePath: controllerRouterPath, methods: this.createMethodMetas(cls, [controllerRouterPath]), dependancyTree: this.dependencyTreeWalker.buildDependencyMap(cls), }; } createMethodMetas(cls, controllerRouterPath) { return cls.getMethods().reduce((acc, method) => { ["Get", "Post", "Put", "Delete"].forEach((httpMethod) => { var _a; const decorator = method.getDecorator(httpMethod); const parameters = method.getParameters(); if (decorator) { acc.push({ name: method.getName(), httpMethod: httpMethod.toLowerCase(), basePaths: controllerRouterPath, path: (_a = decorator.getArguments()[0]) === null || _a === void 0 ? void 0 : _a.getText().replace(/['"]/g, ""), isParameterized: parameters.length > 0, }); } }); return acc; }, []); } } exports.MetaObjectParser = MetaObjectParser;