@agatee/core
Advanced tools
| import 'reflect-metadata'; | ||
| export declare function GatModule(options: any): ClassDecorator; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.GatModule = void 0; | ||
| require("reflect-metadata"); | ||
| const injectable_decorators_1 = require("./injectable.decorators"); | ||
| function GatModule(options) { | ||
| return function (constructorFunc) { | ||
| // console.log('args in decorators', args); | ||
| if (options.imports) { | ||
| for (const module of options.imports) { | ||
| (() => new module())(); | ||
| } | ||
| } | ||
| let newConstructorFunc = function (...args) { | ||
| let func = function () { | ||
| let metadata = Reflect.getMetadata('design:paramtypes', constructorFunc) || []; | ||
| let injections = metadata.map(token => injectable_decorators_1.Injector.resolve(token)); | ||
| return new constructorFunc(...injections); | ||
| }; | ||
| func.prototype = constructorFunc.prototype; | ||
| let newInstance = new func(); | ||
| if (options.routes && newInstance.server) { | ||
| for (let route of options.routes.map(el => new el())) { | ||
| newInstance.server.use(route.path, route.router); | ||
| } | ||
| } | ||
| return newInstance; | ||
| }; | ||
| newConstructorFunc.prototype = constructorFunc.prototype; | ||
| return newConstructorFunc; | ||
| }; | ||
| } | ||
| exports.GatModule = GatModule; |
| import 'reflect-metadata'; | ||
| export declare const instanceMap: Map<any, any>; | ||
| export declare const Injector: { | ||
| resolve<T>(target: any): T; | ||
| }; | ||
| export declare const Injectable: () => any; | ||
| export declare function createInstanceOfInjectable(target: any): any; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createInstanceOfInjectable = exports.Injectable = exports.Injector = exports.instanceMap = void 0; | ||
| require("reflect-metadata"); | ||
| exports.instanceMap = new Map(); | ||
| exports.Injector = new class { | ||
| resolve(target) { | ||
| // tokens are required dependencies, while injections are resolved tokens from the Injector | ||
| let tokens = Reflect.getMetadata('design:paramtypes', target) || [], injections = tokens.map(token => exports.Injector.resolve(token)); | ||
| if (!exports.instanceMap.get(target)) { | ||
| exports.instanceMap.set(target, new target(...injections)); | ||
| } | ||
| return exports.instanceMap.get(target); | ||
| } | ||
| }; | ||
| const Injectable = () => { | ||
| return function (constructorFunc) { | ||
| let newConstructorFunc = function (...args) { | ||
| let func = function () { | ||
| let metadata = Reflect.getMetadata('design:paramtypes', constructorFunc) || []; | ||
| let injections = metadata.map(token => exports.Injector.resolve(token)); | ||
| return new constructorFunc(...injections); | ||
| }; | ||
| func.prototype = constructorFunc.prototype; | ||
| let newInstance = new func(); | ||
| return newInstance; | ||
| }; | ||
| newConstructorFunc.prototype = constructorFunc.prototype; | ||
| return newConstructorFunc; | ||
| }; | ||
| }; | ||
| exports.Injectable = Injectable; | ||
| function createInstanceOfInjectable(target) { | ||
| return new target(); | ||
| } | ||
| exports.createInstanceOfInjectable = createInstanceOfInjectable; |
@@ -1,7 +0,6 @@ | ||
| import { Route } from '../interfaces/router.interface'; | ||
| export declare function RouterModule(options: { | ||
| routes: Route[]; | ||
| }): <T extends new (...args: any[]) => {}>(constructor: T) => { | ||
| new (...args: any[]): {}; | ||
| router: any; | ||
| } & T; | ||
| export declare function GatRouterModule(options: any): ClassDecorator; | ||
| export declare function GET(endpoint?: string): (target: any, key: any, descriptor: any) => void; | ||
| export declare function POST(endpoint?: string): (target: any, key: any, descriptor: any) => void; | ||
| export declare function PUT(endpoint?: string): (target: any, key: any, descriptor: any) => void; | ||
| export declare function DELETE(endpoint?: string): (target: any, key: any, descriptor: any) => void; | ||
| export declare function Middlewares(middlewares: any[]): (target: any, key: any, descriptor: any) => void; |
@@ -6,26 +6,90 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RouterModule = void 0; | ||
| exports.Middlewares = exports.DELETE = exports.PUT = exports.POST = exports.GET = exports.GatRouterModule = void 0; | ||
| const express_1 = __importDefault(require("express")); | ||
| function RouterModule(options) { | ||
| return function (constructor) { | ||
| var _a; | ||
| const router = express_1.default.Router(); | ||
| options.routes.forEach(route => { | ||
| if (route.middleWares && route.middleWares.length) { | ||
| router[route.method](route.path, ...route.middleWares, (...args) => { | ||
| route.action(...args); | ||
| }); | ||
| const injectable_decorators_1 = require("./injectable.decorators"); | ||
| const GETMethods = Symbol('GETMethods'); | ||
| const POSTMethods = Symbol('POSTMethods'); | ||
| const PUTMethods = Symbol('PUTMethods'); | ||
| const DELETEMethods = Symbol('DELETEMethods'); | ||
| const MiddlewaresMethods = Symbol('MiddlewaresMethods'); | ||
| function GatRouterModule(options) { | ||
| return function (constructorFunc) { | ||
| let newConstructorFunc = function (...args) { | ||
| var _a, _b, _c, _d; | ||
| let func = function () { | ||
| let metadata = Reflect.getMetadata('design:paramtypes', constructorFunc) || []; | ||
| let injections = metadata.map(token => injectable_decorators_1.Injector.resolve(token)); | ||
| return new constructorFunc(...injections); | ||
| }; | ||
| func.prototype = constructorFunc.prototype; | ||
| func.prototype.path = options.path; | ||
| let newInstance = new func(); | ||
| // Setting GET, POST, PUT, DELETE decoratorated methods | ||
| const router = express_1.default.Router(); | ||
| if (func.prototype[GETMethods]) { // cheking for methods decorate with @GET | ||
| for (let [method, route] of func.prototype[GETMethods]) { | ||
| const middlewares = ((_a = func.prototype[MiddlewaresMethods]) === null || _a === void 0 ? void 0 : _a.get(method)) || []; | ||
| router.get(route, ...middlewares, newInstance[method].bind(newInstance)); | ||
| } | ||
| } | ||
| else { | ||
| router[route.method](route.path, (...args) => { | ||
| route.action(...args); | ||
| }); | ||
| if (func.prototype[POSTMethods]) { // cheking for methods decorate with @POST | ||
| for (let [method, route] of func.prototype[POSTMethods]) { | ||
| const middlewares = ((_b = func.prototype[MiddlewaresMethods]) === null || _b === void 0 ? void 0 : _b.get(method)) || []; | ||
| router.post(route, ...middlewares, newInstance[method].bind(newInstance)); | ||
| } | ||
| } | ||
| }); | ||
| return _a = class extends constructor { | ||
| }, | ||
| _a.router = router, | ||
| _a; | ||
| if (func.prototype[PUTMethods]) { // cheking for methods decorate with @PUT | ||
| for (let [method, route] of func.prototype[PUTMethods]) { | ||
| const middlewares = ((_c = func.prototype[MiddlewaresMethods]) === null || _c === void 0 ? void 0 : _c.get(method)) || []; | ||
| router.put(route, ...middlewares, newInstance[method].bind(newInstance)); | ||
| } | ||
| } | ||
| if (func.prototype[DELETEMethods]) { // cheking for methods decorate with @DELETE | ||
| for (let [method, route] of func.prototype[DELETEMethods]) { | ||
| const middlewares = ((_d = func.prototype[MiddlewaresMethods]) === null || _d === void 0 ? void 0 : _d.get(method)) || []; | ||
| router.delete(route, ...middlewares, newInstance[method].bind(newInstance)); | ||
| } | ||
| } | ||
| func.prototype.router = router; // bind router to new all instance | ||
| return newInstance; | ||
| }; | ||
| newConstructorFunc.prototype = constructorFunc.prototype; | ||
| return newConstructorFunc; | ||
| }; | ||
| } | ||
| exports.RouterModule = RouterModule; | ||
| exports.GatRouterModule = GatRouterModule; | ||
| function GET(endpoint) { | ||
| return function (target, key, descriptor) { | ||
| target[GETMethods] = target[GETMethods] || new Map(); | ||
| target[GETMethods].set(key, endpoint || key.toLowerCase()); | ||
| }; | ||
| } | ||
| exports.GET = GET; | ||
| function POST(endpoint) { | ||
| return function (target, key, descriptor) { | ||
| target[POSTMethods] = target[POSTMethods] || new Map(); | ||
| target[POSTMethods].set(key, endpoint || key.toLowerCase()); | ||
| }; | ||
| } | ||
| exports.POST = POST; | ||
| function PUT(endpoint) { | ||
| return function (target, key, descriptor) { | ||
| target[PUTMethods] = target[PUTMethods] || new Map(); | ||
| target[PUTMethods].set(key, endpoint || key.toLowerCase()); | ||
| }; | ||
| } | ||
| exports.PUT = PUT; | ||
| function DELETE(endpoint) { | ||
| return function (target, key, descriptor) { | ||
| target[DELETEMethods] = target[DELETEMethods] || new Map(); | ||
| target[DELETEMethods].set(key, endpoint || key.toLowerCase()); | ||
| }; | ||
| } | ||
| exports.DELETE = DELETE; | ||
| function Middlewares(middlewares) { | ||
| return function (target, key, descriptor) { | ||
| target[MiddlewaresMethods] = target[MiddlewaresMethods] || new Map(); | ||
| target[MiddlewaresMethods].set(key, middlewares); | ||
| }; | ||
| } | ||
| exports.Middlewares = Middlewares; |
+2
-4
@@ -1,5 +0,3 @@ | ||
| export * from './decorators/app-module.decorators'; | ||
| export * from './decorators/component.decorators'; | ||
| export * from './decorators/injectable.decorators'; | ||
| export * from './decorators/gat-module.decorators'; | ||
| export * from './decorators/router-module.decorators'; | ||
| export * from './interfaces/component.interface'; | ||
| export * from './interfaces/router.interface'; |
+2
-4
@@ -13,6 +13,4 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./decorators/app-module.decorators"), exports); | ||
| __exportStar(require("./decorators/component.decorators"), exports); | ||
| __exportStar(require("./decorators/injectable.decorators"), exports); | ||
| __exportStar(require("./decorators/gat-module.decorators"), exports); | ||
| __exportStar(require("./decorators/router-module.decorators"), exports); | ||
| __exportStar(require("./interfaces/component.interface"), exports); | ||
| __exportStar(require("./interfaces/router.interface"), exports); |
+5
-4
| { | ||
| "name": "@agatee/core", | ||
| "version": "0.0.2", | ||
| "description": "", | ||
| "version": "1.0.0", | ||
| "description": "A lightweight Typescript framework for express app", | ||
| "main": "index.js", | ||
@@ -9,8 +9,9 @@ "scripts": { | ||
| }, | ||
| "keywords": ["typescript", "express", "generator"], | ||
| "keywords": ["typescript", "express", "generator", "decorator", "framework"], | ||
| "author": "niainaratsima@gmail.com", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "express": "^4.17.1" | ||
| "express": "^4.17.1", | ||
| "reflect-metadata": "^0.1.13" | ||
| } | ||
| } |
+3
-1
| # Tyran | ||
| A lightweight module for Express app including some interfaces and decorators. | ||
| A lightweight framework for Express app. | ||
@@ -9,2 +9,4 @@ --- | ||
| Express | ||
| Nodemon | ||
| Reflect-metadata | ||
@@ -11,0 +13,0 @@ ## Install |
+1
-0
| { | ||
| "compilerOptions": { | ||
| "emitDecoratorMetadata": true, | ||
| "experimentalDecorators": true, | ||
@@ -4,0 +5,0 @@ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ |
| export declare function AppModule(options: any): <T extends new (...constructorArgs: any[]) => any>(constructorFunc: T) => any; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.AppModule = void 0; | ||
| function AppModule(options) { | ||
| return function (constructorFunc) { | ||
| let newConstructorFunc = function (...args) { | ||
| let func = function () { | ||
| return new constructorFunc(...args); | ||
| }; | ||
| func.prototype = constructorFunc.prototype; | ||
| let newInstance = new func(); | ||
| // console.log('args', args); | ||
| // setting middlewares | ||
| newInstance['useMiddlewares'](args[0].middlewares); | ||
| // use all route | ||
| options.declarations.forEach(component => { | ||
| let c = new component(); | ||
| newInstance['use'](c.path, c.router); | ||
| }); | ||
| return newInstance; | ||
| }; | ||
| newConstructorFunc.prototype = constructorFunc.prototype; | ||
| return newConstructorFunc; | ||
| }; | ||
| } | ||
| exports.AppModule = AppModule; |
| import { ComponentOptions } from "../interfaces/component.interface"; | ||
| export declare function Component(options: ComponentOptions<any>): (target: Function) => void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Component = void 0; | ||
| function Component(options) { | ||
| return function (target) { | ||
| target.prototype.router = options.Router['router']; | ||
| target.prototype.path = options.path; | ||
| }; | ||
| } | ||
| exports.Component = Component; |
| export interface Class<T> { | ||
| new (...args: any[]): T; | ||
| } | ||
| export interface ComponentOptions<T> { | ||
| path: string; | ||
| Router: Class<T>; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| export interface Route { | ||
| path: string; | ||
| method: 'get' | 'post' | 'put' | 'delete' | 'update'; | ||
| middleWares?: any[]; | ||
| action: Function; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11255
83.55%216
61.19%2
-33.33%19
11.76%2
100%11
-26.67%1
Infinity%+ Added
+ Added