Skip to content

Commit

Permalink
rm GenericShield and use TShield as typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed Nov 25, 2023
1 parent 83aae8b commit 3b8a762
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/constants/fort_global.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ErrorHandler, Logger } from "../models";
import { ViewEngine, XmlParser, ComponentOption } from "../abstracts";
import { EtagOption, FolderMap, TGuard, TSessionStore } from "../types";
import { GenericShield, GenericWall, GenericXmlParser } from "../generics";
import { EtagOption, FolderMap, TGuard, TSessionStore, TShield } from "../types";
import { GenericWall, GenericXmlParser } from "../generics";
import { MustacheViewEngine, DtoValidator } from "../extra";
import { APP_NAME, CURRENT_PATH } from "./index";
import * as path from "path";
Expand All @@ -23,7 +23,7 @@ export class FortGlobal {
walls: Array<typeof GenericWall> = [];
errorHandler: typeof ErrorHandler;
connectonKeepAliveTimeout?: number;
shields: typeof GenericShield[] = [];
shields: TShield[] = [];
guards: TGuard[] = [];

appName: string;
Expand Down
4 changes: 2 additions & 2 deletions src/decorators/shields.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Shield } from "../abstracts";
import { RouteHandler } from "../handlers";
import { GenericShield } from "../generics";
import { TShield } from "../types";

export const shields = (...shields: Array<typeof Shield>): ClassDecorator => {
return (target: any) => {
const className = target.name;
RouteHandler.addShields(shields as Array<typeof GenericShield>, className);
RouteHandler.addShields(shields as Array<TShield>, className);
};
};
13 changes: 0 additions & 13 deletions src/generics/generic_shield.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/generics/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './generic_shield';
export * from "./generic_wall";
export * from './generic_xml_parser';
2 changes: 1 addition & 1 deletion src/handlers/request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class RequestHandler extends ControllerResultHandler {
const methodArgsValues = InjectorHandler.getMethodValues(shield.name, 'protect', shieldObj);

return shieldObj.protect(...methodArgsValues).then(result => {
result == null ? executeShieldByIndex() : res(this.onResultFromComponent(result));
result == null ? executeShieldByIndex() : res(this.onResultFromComponent(result as IHttpResult));
}).catch(rej);
}
else {
Expand Down
5 changes: 2 additions & 3 deletions src/handlers/route_handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IWorkerInfo, ParentRoute, TGuard } from "../types";
import { GenericShield } from "../generics";
import { IWorkerInfo, ParentRoute, TGuard, TShield } from "../types";
import { compareString, isNull } from "../utils";
import { RouteInfo, WorkerInfo } from "../models";
import { IRouteInfo } from "../interfaces";
Expand Down Expand Up @@ -75,7 +74,7 @@ export class RouteHandler {
}
}

static addShields(shields: Array<typeof GenericShield>, className: string) {
static addShields(shields: Array<TShield>, className: string) {
const route = routerCollection.get(className);
if (route == null) {
pushRouterIntoCollection({
Expand Down
5 changes: 2 additions & 3 deletions src/interfaces/route_info.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { GenericShield } from "../generics";
import { WorkerInfo } from "../models";
import { TController } from "../types";
import { TController, TShield } from "../types";

export interface IRouteInfo {
controller: TController;
controllerName: string;
path: string;
// workerName => WorkerInfo
workers: Map<string, WorkerInfo>;
shields: Array<typeof GenericShield>;
shields: Array<TShield>;
values: any[];
}
5 changes: 2 additions & 3 deletions src/models/route_info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GenericShield } from "../generics";
import { IRouteInfo } from "../interfaces";
import { TController } from "../types";
import { TController, TShield } from "../types";
import { WorkerInfo } from "./worker_info";

export class RouteInfo implements IRouteInfo {
Expand All @@ -15,7 +14,7 @@ export class RouteInfo implements IRouteInfo {
});
}

shields: Array<typeof GenericShield>;
shields: Array<TShield>;
values: any[];

pathSplitted: string[];
Expand Down
5 changes: 3 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Guard } from '../abstracts';
import { Controller, Guard, Shield } from '../abstracts';
import { IHttpResult, ISessonStore } from '../interfaces';

export * from './view_engine_data';
Expand All @@ -20,4 +20,5 @@ export type ErrorResultMapper = (error: any) => IHttpResult;
type Class<I, Args extends any[] = any[]> = new (...args: Args) => I;
export type TSessionStore = Class<ISessonStore, [string]>;
export type TController = Class<Controller>;
export type TGuard = Class<Guard>;
export type TGuard = Class<Guard>;
export type TShield = Class<Shield>;
5 changes: 2 additions & 3 deletions src/types/route_match.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { IWorkerInfo, TController } from ".";
import { IWorkerInfo, TController, TShield } from ".";
import { HTTP_METHOD } from "../enums";
import { GenericShield } from "../generics";

export type RouteMatch = {
controller: TController;
workerInfo: IWorkerInfo;
params: any;
shields: Array<typeof GenericShield>;
shields: Array<TShield>;
allowedHttpMethod: HTTP_METHOD[];
controllerName: string;
};
Expand Down

0 comments on commit 3b8a762

Please sign in to comment.