honestjs 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -8,7 +8,6 @@ export * from './di';
8
8
  export * from './handlers';
9
9
  export * from './helpers';
10
10
  export * from './interfaces';
11
- export * from './managers';
12
11
  export * from './registries';
13
12
  export * from './types';
14
13
  export * from './utils';
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
- import"reflect-metadata";import{Hono as t}from"hono";class M{store=new Map;get($){return this.store.get($)}set($,_){this.store.set($,_)}has($){return this.store.has($)}delete($){return this.store.delete($)}keys(){return this.store.keys()}}class C{instances=new Map;resolve($,_=new Set){if(this.instances.has($))return this.instances.get($);if(_.has($))throw Error(`Circular dependency detected: ${[..._.keys(),$].map((Q)=>Q.name).join(" -> ")}`);_.add($);let Y=(Reflect.getMetadata("design:paramtypes",$)||[]).map((Q)=>{return this.resolve(Q,new Set(_))}),q=new $(...Y);return this.instances.set($,q),q}register($,_){this.instances.set($,_)}}import{HTTPException as r}from"hono/http-exception";function K($,_,W){let Y=new Date().toISOString(),q=_.get("requestId"),Q=_.req.path;if($ instanceof r)return{response:{status:W?.status||$.status,message:W?.title||$.message,timestamp:Y,path:Q,requestId:q,code:W?.code,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:W?.status||$.status};if($.statusCode||$.status){let L=$.statusCode||$.status,E=W?.status||L;return{response:{status:E,message:W?.title||$.message,timestamp:Y,path:Q,requestId:q,code:W?.code||$.name,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:E}}let Z=W?.status||500;return{response:{status:Z,message:W?.title||$.message,timestamp:Y,path:Q,requestId:q,code:W?.code||$.name,details:W?.additionalDetails||{stack:$.stack},...W?.detail&&{detail:W.detail}},status:Z}}class X{static routes=new Map;static controllers=new Map;static controllerOptions=new Map;static services=new Set;static modules=new Map;static parameters=new Map;static contextIndices=new Map;static global=new Map([["middleware",new Set],["guard",new Set],["pipe",new Set],["filter",new Set]]);static controller=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);static handler=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);static getRoutes($){return this.routes.get($)||[]}static setRoutes($,_){this.routes.set($,_)}static addRoute($,_){if(!this.routes.has($))this.routes.set($,[]);this.routes.get($).push(_)}static getControllerPath($){return this.controllers.get($)||""}static setControllerPath($,_){this.controllers.set($,_)}static getControllerOptions($){return this.controllerOptions.get($)||{}}static setControllerOptions($,_){this.controllerOptions.set($,_)}static isService($){return this.services.has($)}static addService($){this.services.add($)}static getAllServices(){return this.services}static getModuleOptions($){return this.modules.get($)}static setModuleOptions($,_){this.modules.set($,_)}static getParameters($){return this.parameters.get($)||new Map}static setParameterMap($,_){this.parameters.set($,_)}static getContextIndices($){return this.contextIndices.get($)||new Map}static setContextIndices($,_){this.contextIndices.set($,_)}static registerGlobal($,_){this.global.get($).add(_)}static getGlobal($){return this.global.get($)}static registerController($,_,W){let Y=this.controller.get($);if(!Y.has(_))Y.set(_,[]);Y.get(_).push(W)}static getController($,_){return this.controller.get($).get(_)||[]}static registerHandler($,_,W){let Y=this.handler.get($);if(!Y.has(_))Y.set(_,[]);Y.get(_).push(W)}static getHandler($,_){return this.handler.get($).get(_)||[]}static clear(){this.routes.clear(),this.controllers.clear(),this.controllerOptions.clear(),this.services.clear(),this.modules.clear(),this.parameters.clear(),this.contextIndices.clear();for(let $ of this.global.values())$.clear();for(let $ of this.controller.values())$.clear();for(let $ of this.handler.values())$.clear()}}class S{static routes=[];static registerRoute($){if(!$)throw Error("Route info is required");if(!$.controller)throw Error("Route controller is required");if(!$.handler)throw Error("Route handler is required");if(!$.method)throw Error("Route method is required");if(!$.fullPath)throw Error("Route fullPath is required");this.routes.push($)}static getRoutes(){return this.routes}static getRoutesByController($){return this.routes.filter((_)=>_.controller===$)}static getRoutesByMethod($){return this.routes.filter((_)=>_.method.toUpperCase()===$.toUpperCase())}static getRoutesByPath($){return this.routes.filter((_)=>$.test(_.fullPath))}static clear(){this.routes.length=0}}function k($){return(_="",W={})=>{return(Y,q,Q)=>{let Z=Y.constructor;X.addRoute(Z,{path:_,method:$,handlerName:q,parameterMetadata:[],version:W.version,prefix:W.prefix})}}}function G($,_){return(W)=>{return(Y,q,Q)=>{let Z=Y.constructor;if(!X.getParameters(Z).size)X.setParameterMap(Z,new Map);let B=X.getParameters(Z);if(!B.has(q))B.set(q,[]);let E=Reflect.getMetadata("design:paramtypes",Y,q)?.[Q];if(B.get(q).push({index:Q,name:$,data:W,factory:_,metatype:E}),$==="context"){if(!X.getContextIndices(Z).size)X.setContextIndices(Z,new Map);X.getContextIndices(Z).set(q,Q)}}}}class x{static handle(){return async($,_)=>{let{response:W,status:Y}=K($,_);return _.json(W,Y)}}}class I{static handle(){return async($)=>{return $.json({message:`Not Found - ${$.req.path}`},404)}}}var S$=($)=>typeof $>"u",b=($)=>$===null||typeof $>"u",D=($)=>$!==null&&typeof $==="object",N$=($)=>{if(!D($))return!1;let _=Object.getPrototypeOf($);if(_===null)return!0;let W=Object.prototype.hasOwnProperty.call(_,"constructor")&&_.constructor;return typeof W==="function"&&W instanceof W&&Function.prototype.toString.call(W)===Function.prototype.toString.call(Object)},i=($)=>typeof $==="function",v=($)=>typeof $==="string",w$=($)=>typeof $==="number",P$=($)=>$.length===0,R$=($)=>typeof $==="symbol",K$=($)=>typeof $==="string"?$.charAt(0)!=="/"?"/"+$:$:"",y=($)=>$?$.startsWith("/")?("/"+$.replace(/\/+$/,"")).replace(/\/+/g,"/"):"/"+$.replace(/\/+$/,""):"/",f$=($)=>$.endsWith("/")?$.slice(0,-1):$,c=($)=>{return i($)&&!b($.prototype)&&!i($.prototype)&&Object.getOwnPropertyNames($.prototype).length>=1};class J{static container;static init($){this.container=$}static setupGlobalComponents($){let _=$.components||{};if(_.middleware)this.registerGlobal("middleware",..._.middleware);if(_.guards)this.registerGlobal("guard",..._.guards);if(_.pipes)this.registerGlobal("pipe",..._.pipes);if(_.filters)this.registerGlobal("filter",..._.filters)}static registerGlobal($,..._){_.forEach((W)=>{X.registerGlobal($,W)})}static registerController($,_,...W){W.forEach((Y)=>{X.registerController($,_,Y)})}static registerHandler($,_,W,...Y){let q=`${_.name}:${String(W)}`;Y.forEach((Q)=>{X.registerHandler($,q,Q)})}static getComponents($,_,W){let Y=`${_.name}:${String(W)}`,q=X.getHandler($,Y),Q=X.getController($,_);return[...Array.from(X.getGlobal($)),...Q,...q]}static resolveMiddleware($){return $.map((_)=>{if(D(_)&&"use"in _)return _.use.bind(_);let W=this.container.resolve(_);return W.use.bind(W)})}static getHandlerMiddleware($,_){let W=this.getComponents("middleware",$,_);return this.resolveMiddleware(W)}static getGlobalMiddleware(){let $=Array.from(X.getGlobal("middleware"));return this.resolveMiddleware($)}static resolveGuards($){return $.map((_)=>{if(D(_)&&"canActivate"in _)return _;return this.container.resolve(_)})}static getHandlerGuards($,_){let W=this.getComponents("guard",$,_);return this.resolveGuards(W)}static resolvePipes($){return $.map((_)=>{if(D(_)&&"transform"in _)return _;return this.container.resolve(_)})}static getHandlerPipes($,_){let W=this.getComponents("pipe",$,_);return this.resolvePipes(W)}static async executePipes($,_,W){let Y=$;for(let q of W)Y=await q.transform(Y,_);return Y}static async handleException($,_){let W=_.get("controllerClass"),Y=_.get("handlerName");if(W&&Y){let B=X.getHandler("filter",`${W.name}:${Y}`);if(B.length>0){let L=await this.executeFilters(B,$,_);if(L)return L}}if(W){let B=X.getController("filter",W);if(B.length>0){let L=await this.executeFilters(B,$,_);if(L)return L}}let q=Array.from(X.getGlobal("filter"));if(q.length>0){let B=await this.executeFilters(q,$,_);if(B)return B}let{response:Q,status:Z}=K($,_);return _.json(Q,Z)}static async executeFilters($,_,W){for(let Y of $){let q;if(D(Y)&&"catch"in Y)q=Y;else q=this.container.resolve(Y);try{let Q=await q.catch(_,W);if(Q!==void 0)return Q}catch(Q){console.error("Error in exception filter:",Q)}}return}static async registerModule($,_){let W=X.getModuleOptions($);if(!W)throw Error(`Module ${$.name} is not properly decorated with @Module()`);let Y=[];if(W.imports&&W.imports.length>0)for(let q of W.imports){let Q=await this.registerModule(q,_);Y.push(...Q)}if(W.services&&W.services.length>0)for(let q of W.services)_.resolve(q);if(W.controllers&&W.controllers.length>0)Y.push(...W.controllers);return Y}}import{HTTPException as o}from"hono/http-exception";var g=Symbol("VERSION_NEUTRAL");class h{hono;container;globalPrefix;globalVersion;constructor($,_,W={}){this.hono=$,this.container=_,this.globalPrefix=W.prefix!==void 0?this.normalizePath(W.prefix):void 0,this.globalVersion=W.version,this.applyGlobalMiddleware()}applyGlobalMiddleware(){let $=J.getGlobalMiddleware();for(let _ of $)this.hono.use("*",_)}normalizePath($){if(v($))return y($);return $?`/${$}`:""}registerRouteHandler($,_,W,Y){if(W.length>0)this.hono.on($.toUpperCase(),_,...W,Y);else this.hono.on($.toUpperCase(),_,Y)}buildRoutePath($,_,W,Y){return y(`${$}${_}${W}${Y}`)}formatVersionSegment($){if(b($))return"";return $===g?"":`/v${String($)}`}async registerController($){let _=X.getControllerPath($)||"",W=X.getControllerOptions($)||{},Y=X.getRoutes($)||[],q=X.getParameters($)||new Map,Q=X.getContextIndices($)||new Map,Z=this.normalizePath(_),B=this.container.resolve($),L=W.prefix!==void 0?W.prefix:this.globalPrefix,E=W.version!==void 0?W.version:this.globalVersion;for(let A of Y){let{path:T,method:V,handlerName:f,version:N,prefix:w}=A,P=w!==void 0?w:L,H=!b(P)?this.normalizePath(P):"",U=N!==void 0?N:E,j=this.normalizePath(T);if(b(U)){this.registerRoute(B,A,q,Q,$,H,"",Z,j,V);continue}if(U===g){this.registerRoute(B,A,q,Q,$,H,"",Z,j,V),this.registerRoute(B,A,q,Q,$,H,"/:version{v[0-9]+}",Z,j,V);continue}if(Array.isArray(U)){for(let O of U){let F=this.formatVersionSegment(O);this.registerRoute(B,A,q,Q,$,H,F,Z,j,V)}continue}let R=this.formatVersionSegment(U);this.registerRoute(B,A,q,Q,$,H,R,Z,j,V)}}registerRoute($,_,W,Y,q,Q,Z,B,L,E){let{handlerName:A}=_,T=this.buildRoutePath(Q,Z,B,L),V=$[A].bind($),f=W.get(A)||[],N=Y.get(A),w=J.getHandlerMiddleware(q,A),P=J.getHandlerPipes(q,A);S.registerRoute({controller:q.name,handler:A,method:E,prefix:Q,version:Z,route:B,path:L,fullPath:T,parameters:f});let H=async(U)=>{try{U.set("controllerClass",q),U.set("handlerName",String(A));let j=J.getHandlerGuards(q,A);for(let F of j)if(!await F.canActivate(U))throw new o(403,{message:"Forbidden"});let R=Array(V.length);for(let F of f){let d=F.factory(F.data,U),a=await J.executePipes(d,{type:F.name,metatype:F.metatype,data:F.data},P);R[F.index]=a}let O=await V(...R);if(N!==void 0)return O;if(b(O))return U.json(null);if(v(O))return U.text(O);return U.json(O)}catch(j){return J.handleException(j,U)}};this.registerRouteHandler(E,T,w,H)}}class p{hono;container;context;routeManager;options;constructor($={}){this.options=D($)?$:{},this.hono=new t(this.options.hono),this.container=this.options.container||new C,this.context=new M,this.setupComponents(),this.setupErrorHandlers(),this.routeManager=new h(this.hono,this.container,{prefix:this.options.routing?.prefix,version:this.options.routing?.version})}setupComponents(){J.init(this.container),J.setupGlobalComponents(this.options)}setupErrorHandlers(){this.hono.notFound(this.options.notFound||I.handle()),this.hono.onError(this.options.onError||x.handle())}resolvePlugin($){if(c($))return new $;return $}normalizePluginEntry($){if($&&typeof $==="object"&&"plugin"in $){let _=$;return{plugin:this.resolvePlugin(_.plugin),preProcessors:_.preProcessors??[],postProcessors:_.postProcessors??[]}}return{plugin:this.resolvePlugin($),preProcessors:[],postProcessors:[]}}async register($){let _=await J.registerModule($,this.container);for(let W of _)await this.routeManager.registerController(W);return this}static async create($,_={}){let W=new p(_),Y=(_.plugins||[]).map((Q)=>W.normalizePluginEntry(Q)),q=W.getContext();for(let{plugin:Q,preProcessors:Z}of Y){for(let B of Z)await B(W,W.hono,q);if(Q.beforeModulesRegistered)await Q.beforeModulesRegistered(W,W.hono)}await W.register($);for(let{plugin:Q,postProcessors:Z}of Y){if(Q.afterModulesRegistered)await Q.afterModulesRegistered(W,W.hono);for(let B of Z)await B(W,W.hono,q)}return{app:W,hono:W.getApp()}}getApp(){return this.hono}getContext(){return this.context}getRoutes(){return S.getRoutes()}}import{html as z,raw as u}from"hono/html";var e={type:"website",locale:"en_US"},m=($)=>{if(!$)return"";return Object.entries($).map(([_,W])=>{if(typeof W==="boolean")return W?_:"";let Y=String(W).replace(/"/g,""");return`${_}="${Y}"`}).filter(Boolean).join(" ")},X_=($)=>{let _={...e,...$};return z`
1
+ import"reflect-metadata";import{Hono as t}from"hono";class M{store=new Map;get($){return this.store.get($)}set($,_){this.store.set($,_)}has($){return this.store.has($)}delete($){return this.store.delete($)}keys(){return this.store.keys()}}class C{instances=new Map;resolve($,_=new Set){if(this.instances.has($))return this.instances.get($);if(_.has($))throw Error(`Circular dependency detected: ${[..._.keys(),$].map((Q)=>Q.name).join(" -> ")}`);_.add($);let W=Reflect.getMetadata("design:paramtypes",$)||[];if($.length>0&&W.length===0)throw Error(`Cannot resolve dependencies for ${$.name}: constructor metadata is missing. Ensure 'reflect-metadata' is imported and 'emitDecoratorMetadata' is enabled.`);let Y=W.map((Q,B)=>{if(!Q||Q===Object||Q===Array||Q===Function)throw Error(`Cannot resolve dependency at index ${B} of ${$.name}. Use concrete class types for constructor dependencies.`);return this.resolve(Q,new Set(_))}),q=new $(...Y);return this.instances.set($,q),q}register($,_){this.instances.set($,_)}}import{HTTPException as r}from"hono/http-exception";function R($,_,W){let Y=new Date().toISOString(),q=_.get("requestId"),Q=_.req.path;if($ instanceof r)return{response:{status:W?.status||$.status,message:W?.title||$.message,timestamp:Y,path:Q,requestId:q,code:W?.code,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:W?.status||$.status};if($.statusCode||$.status){let L=$.statusCode||$.status,A=W?.status||L;return{response:{status:A,message:W?.title||$.message,timestamp:Y,path:Q,requestId:q,code:W?.code||$.name,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:A}}let B=W?.status||500;return{response:{status:B,message:W?.title||$.message,timestamp:Y,path:Q,requestId:q,code:W?.code||$.name,details:W?.additionalDetails||{stack:$.stack},...W?.detail&&{detail:W.detail}},status:B}}class X{static routes=new Map;static controllers=new Map;static controllerOptions=new Map;static services=new Set;static modules=new Map;static parameters=new Map;static contextIndices=new Map;static global=new Map([["middleware",new Set],["guard",new Set],["pipe",new Set],["filter",new Set]]);static controller=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);static handler=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);static getRoutes($){return this.routes.get($)||[]}static setRoutes($,_){this.routes.set($,_)}static addRoute($,_){if(!this.routes.has($))this.routes.set($,[]);this.routes.get($).push(_)}static getControllerPath($){return this.controllers.get($)||""}static hasController($){return this.controllers.has($)}static setControllerPath($,_){this.controllers.set($,_)}static getControllerOptions($){return this.controllerOptions.get($)||{}}static setControllerOptions($,_){this.controllerOptions.set($,_)}static isService($){return this.services.has($)}static addService($){this.services.add($)}static getAllServices(){return this.services}static getModuleOptions($){return this.modules.get($)}static setModuleOptions($,_){this.modules.set($,_)}static getParameters($){return this.parameters.get($)||new Map}static setParameterMap($,_){this.parameters.set($,_)}static getContextIndices($){return this.contextIndices.get($)||new Map}static setContextIndices($,_){this.contextIndices.set($,_)}static registerGlobal($,_){this.global.get($).add(_)}static getGlobal($){return this.global.get($)}static registerController($,_,W){let Y=this.controller.get($);if(!Y.has(_))Y.set(_,[]);Y.get(_).push(W)}static getController($,_){return this.controller.get($).get(_)||[]}static registerHandler($,_,W){let Y=this.handler.get($);if(!Y.has(_))Y.set(_,[]);Y.get(_).push(W)}static getHandler($,_){return this.handler.get($).get(_)||[]}static clear(){this.routes.clear(),this.controllers.clear(),this.controllerOptions.clear(),this.services.clear(),this.modules.clear(),this.parameters.clear(),this.contextIndices.clear();for(let $ of this.global.values())$.clear();for(let $ of this.controller.values())$.clear();for(let $ of this.handler.values())$.clear()}}class T{static routes=[];static registerRoute($){if(!$)throw Error("Route info is required");if(!$.controller)throw Error("Route controller is required");if(!$.handler)throw Error("Route handler is required");if(!$.method)throw Error("Route method is required");if(!$.fullPath)throw Error("Route fullPath is required");if(this.routes.some((W)=>W.fullPath===$.fullPath&&W.method.toUpperCase()===$.method.toUpperCase()))throw Error(`Duplicate route detected: ${$.method.toUpperCase()} ${$.fullPath} (${String($.controller)}.${String($.handler)})`);this.routes.push($)}static getRoutes(){return this.routes}static getRoutesByController($){return this.routes.filter((_)=>_.controller===$)}static getRoutesByMethod($){return this.routes.filter((_)=>_.method.toUpperCase()===$.toUpperCase())}static getRoutesByPath($){return this.routes.filter((_)=>$.test(_.fullPath))}static clear(){this.routes.length=0}}function H($){return(_="",W={})=>{return(Y,q,Q)=>{let B=Y.constructor;X.addRoute(B,{path:_,method:$,handlerName:q,parameterMetadata:[],version:W.version,prefix:W.prefix})}}}function E($,_){let W=(Y,q)=>{if(Y===void 0)return q;return q.get(Y)};return(Y)=>{return(q,Q,B)=>{let Z=q.constructor;if(!X.getParameters(Z).size)X.setParameterMap(Z,new Map);let L=X.getParameters(Z);if(!L.has(Q))L.set(Q,[]);let z=Reflect.getMetadata("design:paramtypes",q,Q)?.[B];if(L.get(Q).push({index:B,name:$,data:Y,factory:_||W,metatype:z}),$==="context"){if(!X.getContextIndices(Z).size)X.setContextIndices(Z,new Map);X.getContextIndices(Z).set(Q,B)}}}}class x{static handle(){return async($,_)=>{let{response:W,status:Y}=R($,_);return _.json(W,Y)}}}class I{static handle(){return async($)=>{return $.json({message:`Not Found - ${$.req.path}`},404)}}}var N$=($)=>typeof $>"u",N=($)=>$===null||typeof $>"u",O=($)=>$!==null&&typeof $==="object",b$=($)=>{if(!O($))return!1;let _=Object.getPrototypeOf($);if(_===null)return!0;let W=Object.prototype.hasOwnProperty.call(_,"constructor")&&_.constructor;return typeof W==="function"&&W instanceof W&&Function.prototype.toString.call(W)===Function.prototype.toString.call(Object)},i=($)=>typeof $==="function",v=($)=>typeof $==="string",w$=($)=>typeof $==="number",P$=($)=>$.length===0,K$=($)=>typeof $==="symbol",R$=($)=>typeof $==="string"?$.charAt(0)!=="/"?"/"+$:$:"",y=($)=>$?$.startsWith("/")?("/"+$.replace(/\/+$/,"")).replace(/\/+/g,"/"):"/"+$.replace(/\/+$/,""):"/",f$=($)=>$.endsWith("/")?$.slice(0,-1):$,c=($)=>{return i($)&&!N($.prototype)&&!i($.prototype)&&Object.getOwnPropertyNames($.prototype).length>=1};class J{static container;static init($){this.container=$}static setupGlobalComponents($){let _=$.components||{};if(_.middleware)this.registerGlobal("middleware",..._.middleware);if(_.guards)this.registerGlobal("guard",..._.guards);if(_.pipes)this.registerGlobal("pipe",..._.pipes);if(_.filters)this.registerGlobal("filter",..._.filters)}static registerGlobal($,..._){_.forEach((W)=>{X.registerGlobal($,W)})}static registerController($,_,...W){W.forEach((Y)=>{X.registerController($,_,Y)})}static registerHandler($,_,W,...Y){let q=`${_.name}:${String(W)}`;Y.forEach((Q)=>{X.registerHandler($,q,Q)})}static getComponents($,_,W){let Y=`${_.name}:${String(W)}`,q=X.getHandler($,Y),Q=X.getController($,_);return[...Array.from(X.getGlobal($)),...Q,...q]}static resolveMiddleware($){return $.map((_)=>{if(O(_)&&"use"in _)return _.use.bind(_);let W=this.container.resolve(_);return W.use.bind(W)})}static getHandlerMiddleware($,_){let W=this.getComponents("middleware",$,_);return this.resolveMiddleware(W)}static getGlobalMiddleware(){let $=Array.from(X.getGlobal("middleware"));return this.resolveMiddleware($)}static resolveGuards($){return $.map((_)=>{if(O(_)&&"canActivate"in _)return _;return this.container.resolve(_)})}static getHandlerGuards($,_){let W=this.getComponents("guard",$,_);return this.resolveGuards(W)}static resolvePipes($){return $.map((_)=>{if(O(_)&&"transform"in _)return _;return this.container.resolve(_)})}static getHandlerPipes($,_){let W=this.getComponents("pipe",$,_);return this.resolvePipes(W)}static async executePipes($,_,W){let Y=$;for(let q of W)Y=await q.transform(Y,_);return Y}static async handleException($,_){let W=_.get("controllerClass"),Y=_.get("handlerName");if(W&&Y){let Z=X.getHandler("filter",`${W.name}:${Y}`);if(Z.length>0){let L=await this.executeFilters(Z,$,_);if(L)return L}}if(W){let Z=X.getController("filter",W);if(Z.length>0){let L=await this.executeFilters(Z,$,_);if(L)return L}}let q=Array.from(X.getGlobal("filter"));if(q.length>0){let Z=await this.executeFilters(q,$,_);if(Z)return Z}let{response:Q,status:B}=R($,_);return _.json(Q,B)}static async executeFilters($,_,W){for(let Y of $){let q;if(O(Y)&&"catch"in Y)q=Y;else q=this.container.resolve(Y);try{let Q=await q.catch(_,W);if(Q!==void 0)return Q}catch(Q){console.error("Error in exception filter:",Q)}}return}static async registerModule($,_){let W=X.getModuleOptions($);if(!W)throw Error(`Module ${$.name} is not properly decorated with @Module()`);let Y=[];if(W.imports&&W.imports.length>0)for(let q of W.imports){let Q=await this.registerModule(q,_);Y.push(...Q)}if(W.services&&W.services.length>0)for(let q of W.services)_.resolve(q);if(W.controllers&&W.controllers.length>0)Y.push(...W.controllers);return Y}}import{HTTPException as o}from"hono/http-exception";var h=Symbol("VERSION_NEUTRAL");class g{hono;container;globalPrefix;globalVersion;constructor($,_,W={}){this.hono=$,this.container=_,this.globalPrefix=W.prefix!==void 0?this.normalizePath(W.prefix):void 0,this.globalVersion=W.version,this.applyGlobalMiddleware()}applyGlobalMiddleware(){let $=J.getGlobalMiddleware();for(let _ of $)this.hono.use("*",_)}normalizePath($){if(v($))return y($);return $?`/${$}`:""}registerRouteHandler($,_,W,Y){if(W.length>0)this.hono.on($.toUpperCase(),_,...W,Y);else this.hono.on($.toUpperCase(),_,Y)}buildRoutePath($,_,W,Y){return y(`${$}${_}${W}${Y}`)}formatVersionSegment($){if(N($))return"";return $===h?"":`/v${String($)}`}async registerController($){if(!X.hasController($))throw Error(`Controller ${$.name} is not decorated with @Controller()`);let _=X.getControllerPath($)||"",W=X.getControllerOptions($)||{},Y=X.getRoutes($)||[],q=X.getParameters($)||new Map,Q=X.getContextIndices($)||new Map,B=this.normalizePath(_),Z=this.container.resolve($),L=W.prefix!==void 0?W.prefix:this.globalPrefix,A=W.version!==void 0?W.version:this.globalVersion;if(Y.length===0)throw Error(`Controller ${$.name} has no route handlers. Add HTTP method decorators like @Get()`);for(let z of Y){let{path:j,method:V,handlerName:f,version:b,prefix:w}=z,P=w!==void 0?w:L,S=!N(P)?this.normalizePath(P):"",G=b!==void 0?b:A,k=this.normalizePath(j);if(N(G)){this.registerRoute(Z,z,q,Q,$,S,"",B,k,V);continue}if(G===h){this.registerRoute(Z,z,q,Q,$,S,"",B,k,V),this.registerRoute(Z,z,q,Q,$,S,"/:version{v[0-9]+}",B,k,V);continue}if(Array.isArray(G)){for(let D of G){let F=this.formatVersionSegment(D);this.registerRoute(Z,z,q,Q,$,S,F,B,k,V)}continue}let K=this.formatVersionSegment(G);this.registerRoute(Z,z,q,Q,$,S,K,B,k,V)}}registerRoute($,_,W,Y,q,Q,B,Z,L,A){let{handlerName:z}=_,j=this.buildRoutePath(Q,B,Z,L),V=$[z].bind($),f=W.get(z)||[],b=Y.get(z),w=J.getHandlerMiddleware(q,z),P=J.getHandlerPipes(q,z);T.registerRoute({controller:q.name,handler:z,method:A,prefix:Q,version:B,route:Z,path:L,fullPath:j,parameters:f});let S=async(G)=>{try{G.set("controllerClass",q),G.set("handlerName",String(z));let k=J.getHandlerGuards(q,z);for(let F of k)if(!await F.canActivate(G))throw new o(403,{message:`Forbidden by ${F.constructor?.name||"UnknownGuard"} at ${q.name}.${String(z)}`});let K=Array(V.length);for(let F of f){if(typeof F.factory!=="function")throw Error(`Invalid parameter decorator metadata for ${q.name}.${String(z)}`);let d=F.factory(F.data,G),a=await J.executePipes(d,{type:F.name,metatype:F.metatype,data:F.data},P);K[F.index]=a}let D=await V(...K);if(b!==void 0)return D;if(D instanceof Response)return D;if(N(D))return G.json(null);if(v(D))return G.text(D);return G.json(D)}catch(k){return J.handleException(k,G)}};this.registerRouteHandler(A,j,w,S)}}class p{hono;container;context;routeManager;options;constructor($={}){if(this.options=O($)?$:{},T.clear(),this.hono=new t(this.options.hono),this.container=this.options.container||new C,this.context=new M,this.setupComponents(),this.setupErrorHandlers(),this.routeManager=new g(this.hono,this.container,{prefix:this.options.routing?.prefix,version:this.options.routing?.version}),this.options.deprecations?.printPreV1Warning)console.warn("[HonestJS] Pre-v1 warning: APIs may change before 1.0.0.")}setupComponents(){J.init(this.container),J.setupGlobalComponents(this.options)}setupErrorHandlers(){this.hono.notFound(this.options.notFound||I.handle()),this.hono.onError(this.options.onError||x.handle())}resolvePlugin($){if(c($))return new $;return $}normalizePluginEntry($){if($&&typeof $==="object"&&"plugin"in $){let _=$;return{plugin:this.resolvePlugin(_.plugin),preProcessors:_.preProcessors??[],postProcessors:_.postProcessors??[]}}return{plugin:this.resolvePlugin($),preProcessors:[],postProcessors:[]}}async register($){let _=await J.registerModule($,this.container);for(let W of _)await this.routeManager.registerController(W);return this}static async create($,_={}){let W=new p(_),Y=(_.plugins||[]).map((A)=>W.normalizePluginEntry(A)),q=W.getContext(),Q=_.debug,B=Q===!0||typeof Q==="object"&&Q.plugins,Z=Q===!0||typeof Q==="object"&&Q.routes;if(B&&Y.length>0)console.info("[HonestJS] Plugin order:",Y.map(({plugin:A})=>A.constructor?.name||"AnonymousPlugin").join(" -> "));for(let{plugin:A,preProcessors:z}of Y){for(let j of z)await j(W,W.hono,q);if(A.beforeModulesRegistered)await A.beforeModulesRegistered(W,W.hono)}await W.register($);let L=W.getRoutes();if(_.strict?.requireRoutes&&L.length===0)throw Error("Strict mode: no routes were registered. Check your module/controller decorators.");if(Z)console.info("[HonestJS] Registered routes:",L.map((A)=>`${A.method.toUpperCase()} ${A.fullPath}`));for(let{plugin:A,postProcessors:z}of Y){if(A.afterModulesRegistered)await A.afterModulesRegistered(W,W.hono);for(let j of z)await j(W,W.hono,q)}return{app:W,hono:W.getApp()}}getApp(){return this.hono}getContext(){return this.context}getRoutes(){return T.getRoutes()}}import{html as U,raw as u}from"hono/html";var e={type:"website",locale:"en_US"},m=($)=>{if(!$)return"";return Object.entries($).map(([_,W])=>{if(typeof W==="boolean")return W?_:"";let Y=String(W).replace(/"/g,""");return`${_}="${Y}"`}).filter(Boolean).join(" ")},X_=($)=>{let _={...e,...$};return U`
2
2
  <!DOCTYPE html>
3
3
  <html lang="${_.locale?.split("_")[0]||"en"}" ${u(m(_.htmlAttributes))}>
4
4
  <head ${u(m(_.headAttributes))}>
5
5
  <meta charset="UTF-8" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- ${_.csp?z`<meta http-equiv="Content-Security-Policy" content="${_.csp}" />`:""}
7
+ ${_.csp?U`<meta http-equiv="Content-Security-Policy" content="${_.csp}" />`:""}
8
8
  <title>${_.title}</title>
9
- ${_.description?z`<meta name="description" content="${_.description}" />`:""}
9
+ ${_.description?U`<meta name="description" content="${_.description}" />`:""}
10
10
 
11
11
  <!-- Open Graph / Facebook -->
12
12
  <meta prefix="og: http://ogp.me/ns#" />
13
13
  <meta property="og:title" content="${_.title}" />
14
- ${_.description?z`<meta property="og:description" content="${_.description}" />`:""}
15
- ${_.image?z`<meta property="og:image" content="${_.image}" />`:""}
16
- ${_.url?z`<meta property="og:url" content="${_.url}" />`:""}
17
- ${_.locale?z`<meta property="og:locale" content="${_.locale}" />`:""}
18
- ${_.type?z`<meta property="og:type" content="${_.type}" />`:""}
19
- ${_.siteName?z`<meta property="og:site_name" content="${_.siteName}" />`:""}
14
+ ${_.description?U`<meta property="og:description" content="${_.description}" />`:""}
15
+ ${_.image?U`<meta property="og:image" content="${_.image}" />`:""}
16
+ ${_.url?U`<meta property="og:url" content="${_.url}" />`:""}
17
+ ${_.locale?U`<meta property="og:locale" content="${_.locale}" />`:""}
18
+ ${_.type?U`<meta property="og:type" content="${_.type}" />`:""}
19
+ ${_.siteName?U`<meta property="og:site_name" content="${_.siteName}" />`:""}
20
20
 
21
21
  <!-- Twitter -->
22
22
  <meta
@@ -24,23 +24,23 @@ import"reflect-metadata";import{Hono as t}from"hono";class M{store=new Map;get($
24
24
  content="${_.twitterCard||(_.image?"summary_large_image":"summary")}"
25
25
  />
26
26
  <meta name="twitter:title" content="${_.title}" />
27
- ${_.description?z`<meta name="twitter:description" content="${_.description}" />`:""}
28
- ${_.image?z`<meta name="twitter:image" content="${_.image}" />`:""}
27
+ ${_.description?U`<meta name="twitter:description" content="${_.description}" />`:""}
28
+ ${_.image?U`<meta name="twitter:image" content="${_.image}" />`:""}
29
29
 
30
30
  <!-- Custom Meta Tags -->
31
- ${_.customMeta?_.customMeta.map((W)=>{let Y=W.name?`name="${W.name}"`:"",q=W.property?`property="${W.property}"`:"";return z`<meta ${Y} ${q} content="${W.content}" />`}):""}
31
+ ${_.customMeta?_.customMeta.map((W)=>{let Y=W.name?`name="${W.name}"`:"",q=W.property?`property="${W.property}"`:"";return U`<meta ${Y} ${q} content="${W.content}" />`}):""}
32
32
 
33
33
  <!-- Favicon -->
34
- ${_.favicon?z`<link rel="icon" href="${_.favicon}" />`:""}
34
+ ${_.favicon?U`<link rel="icon" href="${_.favicon}" />`:""}
35
35
 
36
36
  <!-- Stylesheets -->
37
- ${_.stylesheets?_.stylesheets.map((W)=>z`<link rel="stylesheet" href="${W}" />`):""}
37
+ ${_.stylesheets?_.stylesheets.map((W)=>U`<link rel="stylesheet" href="${W}" />`):""}
38
38
 
39
39
  <!-- Scripts -->
40
- ${_.scripts?_.scripts.map((W)=>{if(typeof W==="string")return z`<script src="${W}"></script>`;let{src:Y,async:q,defer:Q}=W;if(q&&Q)return z`<script src="${Y}" async defer></script>`;if(q)return z`<script src="${Y}" async></script>`;if(Q)return z`<script src="${Y}" defer></script>`;return z`<script src="${Y}"></script>`}):""}
40
+ ${_.scripts?_.scripts.map((W)=>{if(typeof W==="string")return U`<script src="${W}"></script>`;let{src:Y,async:q,defer:Q}=W;if(q&&Q)return U`<script src="${Y}" async defer></script>`;if(q)return U`<script src="${Y}" async></script>`;if(Q)return U`<script src="${Y}" defer></script>`;return U`<script src="${Y}"></script>`}):""}
41
41
  </head>
42
42
  <body ${u(m(_.bodyAttributes))}>
43
43
  ${_.children}
44
44
  </body>
45
45
  </html>
46
- `};function s($="",_={}){return(W)=>{X.setControllerPath(W,$),X.setControllerOptions(W,_)}}var l=k("get"),U_=k("post"),G_=k("put"),F_=k("delete"),E_=k("patch"),j_=k("options"),V_=k("all");function n($={}){return(_)=>{X.setModuleOptions(_,$)}}function S_($="",_={prefix:null,version:null}){return s($,_)}var N_=l;function w_($={}){return n({imports:$.imports,services:$.services,controllers:($.views||[]).concat($.controllers||[])})}var K_=G("body",async($,_)=>{let W=await _.req.json();return $?W[$]:W}),f_=G("param",($,_)=>{return $?_.req.param($):_.req.param()}),M_=G("query",($,_)=>{return $?_.req.query($):_.req.query()}),C_=G("header",($,_)=>{return $?_.req.header($):_.req.header()}),x_=G("request",($,_)=>_.req),I_=G("request",($,_)=>_.req),v_=G("response",($,_)=>_.res),y_=G("response",($,_)=>_.res),g_=G("context",($,_)=>_),h_=G("context",($,_)=>_),u_=G("variable",($,_)=>_.get($)),m_=G("variable",($,_)=>_.get($));function c_(){return($)=>{X.addService($)}}function l_($,..._){return(W,Y)=>{if(Y){let q=W.constructor;J.registerHandler($,q,Y,..._)}else J.registerController($,W,..._)}}function r_(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("filter",Y,W,...$)}else J.registerController("filter",_,...$)}}function e_(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("guard",Y,W,...$)}else J.registerController("guard",_,...$)}}function WW(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("middleware",Y,W,...$)}else J.registerController("middleware",_,...$)}}function QW(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("pipe",Y,W,...$)}else J.registerController("pipe",_,...$)}}export{f$ as stripEndSlash,y as normalizePath,S$ as isUndefined,R$ as isSymbol,v as isString,N$ as isPlainObject,D as isObject,w$ as isNumber,b as isNil,i as isFunction,P$ as isEmpty,c as isConstructor,G as createParamDecorator,k as createHttpMethodDecorator,K as createErrorResponse,K$ as addLeadingSlash,S_ as View,m_ as Variable,u_ as Var,g as VERSION_NEUTRAL,QW as UsePipes,WW as UseMiddleware,e_ as UseGuards,r_ as UseFilters,l_ as UseComponent,c_ as Service,S as RouteRegistry,h as RouteManager,y_ as Response,v_ as Res,I_ as Request,x_ as Req,M_ as Query,G_ as Put,U_ as Post,E_ as Patch,f_ as Param,N_ as Page,j_ as Options,I as NotFoundHandler,w_ as MvcModule,n as Module,X as MetadataRegistry,X_ as Layout,C_ as Header,l as Get,x as ErrorHandler,F_ as Delete,g_ as Ctx,s as Controller,h_ as Context,C as Container,J as ComponentManager,K_ as Body,M as ApplicationContext,p as Application,V_ as All};
46
+ `};function s($="",_={}){return(W)=>{X.setControllerPath(W,$),X.setControllerOptions(W,_)}}var l=H("get"),U_=H("post"),G_=H("put"),E_=H("delete"),F_=H("patch"),j_=H("options"),V_=H("all");function n($={}){return(_)=>{X.setModuleOptions(_,$)}}function N_($="",_={prefix:null,version:null}){return s($,_)}var b_=l;function w_($={}){return n({imports:$.imports,services:$.services,controllers:($.views||[]).concat($.controllers||[])})}var R_=E("body",async($,_)=>{let W=_.get("__honest.body.cache");if(W===void 0)W=await _.req.json(),_.set("__honest.body.cache",W);if($&&W&&typeof W==="object")return W[String($)];return W}),f_=E("param",($,_)=>{return $?_.req.param($):_.req.param()}),M_=E("query",($,_)=>{return $?_.req.query($):_.req.query()}),C_=E("header",($,_)=>{return $?_.req.header($):_.req.header()}),x_=E("request",($,_)=>_.req),I_=E("request",($,_)=>_.req),v_=E("response",($,_)=>_.res),y_=E("response",($,_)=>_.res),h_=E("context",($,_)=>_),g_=E("context",($,_)=>_),u_=E("variable",($,_)=>_.get($)),m_=E("variable",($,_)=>_.get($));function c_(){return($)=>{X.addService($)}}function l_($,..._){return(W,Y)=>{if(Y){let q=W.constructor;J.registerHandler($,q,Y,..._)}else J.registerController($,W,..._)}}function r_(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("filter",Y,W,...$)}else J.registerController("filter",_,...$)}}function e_(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("guard",Y,W,...$)}else J.registerController("guard",_,...$)}}function WW(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("middleware",Y,W,...$)}else J.registerController("middleware",_,...$)}}function QW(...$){return(_,W)=>{if(W){let Y=_.constructor;J.registerHandler("pipe",Y,W,...$)}else J.registerController("pipe",_,...$)}}export{f$ as stripEndSlash,y as normalizePath,N$ as isUndefined,K$ as isSymbol,v as isString,b$ as isPlainObject,O as isObject,w$ as isNumber,N as isNil,i as isFunction,P$ as isEmpty,c as isConstructor,E as createParamDecorator,H as createHttpMethodDecorator,R as createErrorResponse,R$ as addLeadingSlash,N_ as View,m_ as Variable,u_ as Var,h as VERSION_NEUTRAL,QW as UsePipes,WW as UseMiddleware,e_ as UseGuards,r_ as UseFilters,l_ as UseComponent,c_ as Service,T as RouteRegistry,y_ as Response,v_ as Res,I_ as Request,x_ as Req,M_ as Query,G_ as Put,U_ as Post,F_ as Patch,f_ as Param,b_ as Page,j_ as Options,I as NotFoundHandler,w_ as MvcModule,n as Module,X as MetadataRegistry,X_ as Layout,C_ as Header,l as Get,x as ErrorHandler,E_ as Delete,h_ as Ctx,s as Controller,g_ as Context,C as Container,R_ as Body,M as ApplicationContext,p as Application,V_ as All};
@@ -6,6 +6,33 @@ import type { DiContainer } from './di-container.interface';
6
6
  * Options for configuring the Honest application
7
7
  */
8
8
  export interface HonestOptions {
9
+ /**
10
+ * Enable debug logging for startup diagnostics.
11
+ * - `true` enables all debug logs
12
+ * - object form enables specific categories
13
+ */
14
+ debug?: boolean | {
15
+ routes?: boolean;
16
+ plugins?: boolean;
17
+ };
18
+ /**
19
+ * Optional strict-mode checks for startup validation.
20
+ */
21
+ strict?: {
22
+ /**
23
+ * When enabled, startup fails if no routes were registered.
24
+ */
25
+ requireRoutes?: boolean;
26
+ };
27
+ /**
28
+ * Optional warnings for unstable/deprecated behavior.
29
+ */
30
+ deprecations?: {
31
+ /**
32
+ * Print pre-v1 instability warning during startup.
33
+ */
34
+ printPreV1Warning?: boolean;
35
+ };
9
36
  /**
10
37
  * Container instance for dependency injection
11
38
  */
@@ -97,6 +97,10 @@ export declare class MetadataRegistry {
97
97
  * Get controller path
98
98
  */
99
99
  static getControllerPath(controller: Constructor): string;
100
+ /**
101
+ * Check if a class is registered as a controller.
102
+ */
103
+ static hasController(controller: Constructor): boolean;
100
104
  /**
101
105
  * Set controller path
102
106
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "honestjs",
3
3
  "description": "HonestJS - a modern web framework built on top of Hono",
4
- "version": "0.1.9",
4
+ "version": "0.1.11",
5
5
  "author": "Orkhan Karimov <karimovok1@gmail.com> (https://github.com/kerimovok)",
6
6
  "repository": {
7
7
  "type": "git",