From 21307b40789f8a75b7e41eb68ed12825b084cf32 Mon Sep 17 00:00:00 2001 From: Ujjwal Gupta Date: Sun, 14 Jan 2024 21:52:25 +0400 Subject: [PATCH] save worker info in component prop --- src/abstracts/guard.ts | 2 +- src/abstracts/shield.ts | 2 +- src/handlers/request_handler.ts | 3 +-- src/helpers/test/init_controller.ts | 4 +++- src/interfaces/component_prop.ts | 3 ++- src/providers/cache_guard.ts | 1 + 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/abstracts/guard.ts b/src/abstracts/guard.ts index bf4cca9..011ba47 100644 --- a/src/abstracts/guard.ts +++ b/src/abstracts/guard.ts @@ -18,7 +18,7 @@ export abstract class Guard extends Component { } get workerName() { - return this['componentProp_'].workerName; + return this['componentProp_'].workerInfo.workerName; } abstract check(...args): Promise; diff --git a/src/abstracts/shield.ts b/src/abstracts/shield.ts index a298855..18e1167 100644 --- a/src/abstracts/shield.ts +++ b/src/abstracts/shield.ts @@ -6,7 +6,7 @@ import { Component } from "./component"; export abstract class Shield extends Component { get workerName() { - return this['componentProp_'].workerName; + return this['componentProp_'].workerInfo.workerName; } get logger(): Logger { diff --git a/src/handlers/request_handler.ts b/src/handlers/request_handler.ts index ffebd66..541ff52 100644 --- a/src/handlers/request_handler.ts +++ b/src/handlers/request_handler.ts @@ -129,11 +129,10 @@ export class RequestHandler extends RequestHandlerHelper { this.componentProps.param = routeMatchInfo.params; this.componentProps.controllerName = routeMatchInfo.controllerName; - this.componentProps.workerName = workerInfo.workerName; + this.componentProps.workerInfo = workerInfo; const shieldResult = await this.executeShieldsProtection_(); if (shieldResult) return shieldResult; - const guardResult = await this.executeGuardsCheck_( workerInfo.guards ); diff --git a/src/helpers/test/init_controller.ts b/src/helpers/test/init_controller.ts index c596ef8..97d2ff1 100644 --- a/src/helpers/test/init_controller.ts +++ b/src/helpers/test/init_controller.ts @@ -31,7 +31,9 @@ export const initController = (controllerInstance: Controller, data?: IControlle param: data.param || {}, data: data.data || {}, file: new FileManager(data.file || {}), - workerName: (data as any).workerName, + workerInfo: { + workerName: (data as any).workerName + } as any, global: FORT_GLOBAL, cache: cacheManager }; diff --git a/src/interfaces/component_prop.ts b/src/interfaces/component_prop.ts index d09dcff..3919491 100644 --- a/src/interfaces/component_prop.ts +++ b/src/interfaces/component_prop.ts @@ -4,6 +4,7 @@ import { FortGlobal } from "../constants"; import { SessionManager } from "../utils"; import { TComponentQuery } from "../types"; import { CacheManager } from "../utils/cache_manager"; +import { IWorkerInfo } from "./worker_info"; export interface IComponentProp { request: http.IncomingMessage; @@ -15,8 +16,8 @@ export interface IComponentProp { param?: { [key: string]: string }; data: { [key: string]: any }; file?: FileManager; - workerName?: string; controllerName?: string; global: FortGlobal; cache: CacheManager; + workerInfo?: IWorkerInfo; } \ No newline at end of file diff --git a/src/providers/cache_guard.ts b/src/providers/cache_guard.ts index 36cd83d..c27c1cf 100644 --- a/src/providers/cache_guard.ts +++ b/src/providers/cache_guard.ts @@ -3,6 +3,7 @@ import { IHttpResult } from "../interfaces"; export class CacheGuard extends Guard { async check(...args: any[]): Promise { + const cache = this['componentProp_'].workerInfo.cache; // get cache condition from routes // and check if condition exist