Skip to content

Commit

Permalink
Broke up decorators into individual files for cleaner commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Joey Kilpatrick committed Feb 6, 2020
1 parent be9655b commit 132006f
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 297 deletions.
1 change: 1 addition & 0 deletions src/core/lib/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* created by Sean Maxwell Aug 26, 2018
*/

import 'reflect-metadata';
import * as express from 'express';
import { Application, Request, Response, Router, NextFunction, ErrorRequestHandler, RequestHandler } from 'express';
import { ClassKeys } from './decorators';
Expand Down
297 changes: 0 additions & 297 deletions src/core/lib/decorators.ts

This file was deleted.

86 changes: 86 additions & 0 deletions src/core/lib/decorators/class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Route Decorators for the Overnight web-framework. Link to all routes for ExpressJS:
* https://expressjs.com/en/api.html#routing-methods.
*
* created by Sean Maxwell Aug 27, 2018
*/

import {RouterOptions} from 'express';
import {ErrorMiddleware, Middleware, WrapperFunction, Controller} from './types';

export enum ClassKeys {
BasePath = 'BASE_PATH',
Middleware = 'MIDDLEWARE',
ErrorMiddleware = 'ERROR_MIDDLEWARE',
Wrapper = 'WRAPPER',
Children = 'CHILDREN',
Options = 'OPTIONS',
}

export function Controller(path: string): ClassDecorator {

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.BasePath, '/' + path, target.prototype);
return target;
};
}

export function ClassMiddleware(middleware: Middleware | Middleware[]): ClassDecorator {

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.Middleware, middleware, target.prototype);
return target;
};
}

export function ClassErrorMiddleware(middleware: ErrorMiddleware | ErrorMiddleware[]): ClassDecorator {

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.ErrorMiddleware, middleware, target.prototype);
return target;
};
}


export function ClassWrapper(wrapperFunction: WrapperFunction): ClassDecorator {

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.Wrapper, wrapperFunction, target.prototype);
return target;
};
}

export function ClassOptions(options: RouterOptions): ClassDecorator {

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.Options, options, target.prototype);
return target;
};
}

export function Children(controllers: Controller | Controller[]): ClassDecorator {

// tslint:disable-next-line: no-console
console.log('Warning: @Children decorator is deprecated. Use ChildControllers instead.');

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.Children, controllers, target.prototype);
return target;
};
}

export function ChildControllers(controllers: Controller | Controller[]): ClassDecorator {

// tslint:disable-next-line:ban-types
return <TFunction extends Function>(target: TFunction) => {
Reflect.defineMetadata(ClassKeys.Children, controllers, target.prototype);
return target;
};
}

Loading

0 comments on commit 132006f

Please sign in to comment.