honestjs 0.1.17 → 0.1.19
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/README.md +24 -3
- package/dist/application.d.ts +1 -1
- package/dist/application.di-harness.test.d.ts +1 -0
- package/dist/application.diagnostics.test.d.ts +1 -0
- package/dist/application.isolation.test.d.ts +1 -0
- package/dist/application.plugins.test.d.ts +1 -0
- package/dist/application.regressions.test.d.ts +1 -0
- package/dist/application.routing-errors.test.d.ts +1 -0
- package/dist/application.runtime-metadata.test.d.ts +1 -0
- package/dist/di/container.d.ts +4 -4
- package/dist/diagnostics/console-diagnostics.emitter.d.ts +4 -4
- package/dist/diagnostics/noop-diagnostics.emitter.d.ts +4 -4
- package/dist/index.js +16 -16
- package/dist/interfaces/honest-options.interface.d.ts +3 -3
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/logger.interface.d.ts +23 -0
- package/dist/interfaces/plugin.interface.d.ts +10 -6
- package/dist/managers/component.manager.d.ts +3 -3
- package/dist/managers/pipeline.executor.d.ts +3 -3
- package/dist/managers/route.manager.d.ts +3 -3
- package/dist/registries/metadata.registry.d.ts +7 -1
- package/dist/testing/fixtures/application-test-fixtures.d.ts +17 -0
- package/dist/testing/testing.interface.d.ts +3 -3
- package/package.json +2 -1
- package/dist/interfaces/diagnostics.interface.d.ts +0 -23
- /package/dist/{application.test.d.ts → application.bootstrap.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -144,7 +144,7 @@ const { app, hono } = await Application.create(AppModule, {
|
|
|
144
144
|
di: true,
|
|
145
145
|
startup: true
|
|
146
146
|
},
|
|
147
|
-
|
|
147
|
+
logger: myLogger,
|
|
148
148
|
strict: { requireRoutes: true },
|
|
149
149
|
deprecations: { printPreV1Warning: true },
|
|
150
150
|
container: myContainer,
|
|
@@ -166,7 +166,12 @@ const { app, hono } = await Application.create(AppModule, {
|
|
|
166
166
|
plugins: [
|
|
167
167
|
new RPCPlugin(),
|
|
168
168
|
new ApiDocsPlugin(),
|
|
169
|
-
{
|
|
169
|
+
{
|
|
170
|
+
plugin: MyPlugin,
|
|
171
|
+
name: 'core',
|
|
172
|
+
preProcessors: [pre],
|
|
173
|
+
postProcessors: [post]
|
|
174
|
+
},
|
|
170
175
|
{ plugin: MetricsPlugin, name: 'metrics', after: ['core'] }
|
|
171
176
|
],
|
|
172
177
|
onError: (err, c) => c.json({ error: err.message }, 500),
|
|
@@ -219,7 +224,7 @@ If constraints are invalid (missing dependency, cycle, or missing required capab
|
|
|
219
224
|
Honest exports lightweight helpers for common test setups.
|
|
220
225
|
|
|
221
226
|
```typescript
|
|
222
|
-
import {
|
|
227
|
+
import { createControllerTestApplication, createServiceTestContainer, createTestApplication } from 'honestjs'
|
|
223
228
|
|
|
224
229
|
const app = await createTestApplication({
|
|
225
230
|
controllers: [UsersController],
|
|
@@ -238,6 +243,22 @@ const services = createServiceTestContainer({
|
|
|
238
243
|
})
|
|
239
244
|
```
|
|
240
245
|
|
|
246
|
+
### Running tests in this package
|
|
247
|
+
|
|
248
|
+
This repo uses [Bun's test runner](https://bun.sh/docs/cli/test). From the package root:
|
|
249
|
+
|
|
250
|
+
- `bun test` — run all tests once
|
|
251
|
+
- `bun test --watch` — watch mode
|
|
252
|
+
- `bun test <pattern>` — limit to matching file or test names (for example `bun test application.bootstrap`)
|
|
253
|
+
- `bun run test:coverage` — same suite with coverage (summary in the terminal and `coverage/lcov.info`)
|
|
254
|
+
|
|
255
|
+
Co-locate tests as `*.test.ts` next to sources. Import `reflect-metadata` first in any file that loads decorated
|
|
256
|
+
classes, same as in application code.
|
|
257
|
+
|
|
258
|
+
Integration-style cases use `*.integration.test.ts` where the whole `Application` stack is exercised (for example the
|
|
259
|
+
request pipeline). Shared HTTP fixtures for application tests live under `src/testing/fixtures/` as **factory
|
|
260
|
+
functions** so each test gets fresh decorator metadata after `MetadataRegistry.clear()` in `afterEach`.
|
|
261
|
+
|
|
241
262
|
## Startup diagnostics guide mode
|
|
242
263
|
|
|
243
264
|
Enable startup guidance to get actionable remediation hints when initialization fails.
|
package/dist/application.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Application {
|
|
|
16
16
|
private readonly metadataRepository;
|
|
17
17
|
private readonly componentManager;
|
|
18
18
|
private readonly routeManager;
|
|
19
|
-
private readonly
|
|
19
|
+
private readonly logger;
|
|
20
20
|
private readonly options;
|
|
21
21
|
private static readonly DEFAULT_PLUGIN_NAME;
|
|
22
22
|
constructor(options?: HonestOptions, metadataRepository?: IMetadataRepository);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
package/dist/di/container.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { DiContainer,
|
|
1
|
+
import type { DiContainer, ILogger, IServiceRegistry } from '../interfaces';
|
|
2
2
|
import type { Constructor } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Dependency Injection container that manages class instances and their dependencies
|
|
5
5
|
*/
|
|
6
6
|
export declare class Container implements DiContainer {
|
|
7
7
|
private readonly serviceRegistry;
|
|
8
|
-
private readonly
|
|
8
|
+
private readonly logger;
|
|
9
9
|
private readonly debugDi;
|
|
10
|
-
constructor(serviceRegistry?: IServiceRegistry,
|
|
10
|
+
constructor(serviceRegistry?: IServiceRegistry, logger?: ILogger, debugDi?: boolean);
|
|
11
11
|
/**
|
|
12
12
|
* Map of class constructors to their instances
|
|
13
13
|
*/
|
|
14
14
|
private instances;
|
|
15
|
-
private
|
|
15
|
+
private emitLog;
|
|
16
16
|
/**
|
|
17
17
|
* Resolves a class instance, creating it if necessary and injecting its dependencies
|
|
18
18
|
* @param target - The class constructor to resolve
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LogEvent, ILogger } from '../interfaces';
|
|
2
2
|
/**
|
|
3
|
-
* Default
|
|
3
|
+
* Default logger that writes structured events to console.
|
|
4
4
|
*/
|
|
5
|
-
export declare class
|
|
6
|
-
emit(event:
|
|
5
|
+
export declare class ConsoleLogger implements ILogger {
|
|
6
|
+
emit(event: LogEvent): void;
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LogEvent, ILogger } from '../interfaces';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Logger implementation that intentionally does nothing.
|
|
4
4
|
*/
|
|
5
|
-
export declare class
|
|
6
|
-
emit(_event:
|
|
5
|
+
export declare class NoopLogger implements ILogger {
|
|
6
|
+
emit(_event: LogEvent): void;
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import"reflect-metadata";import{Hono as B$}from"hono";class h{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 g{emit($){let _=`[HonestJS:${$.category}]`,W=$.details?[_,$.message,$.details]:[_,$.message];switch($.level){case"debug":case"info":console.info(...W);break;case"warn":console.warn(...W);break;case"error":console.error(...W);break}}}class H{emit($){}}class L{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 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 registerController($,_,W){let Q=this.controller.get($);if(!Q.has(_))Q.set(_,[]);Q.get(_).push(W)}static getController($,_){return this.controller.get($).get(_)||[]}static registerHandler($,_,W){let Q=this.handler.get($);if(!Q.has(_))Q.set(_,[]);Q.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.controller.values())$.clear();for(let $ of this.handler.values())$.clear()}}class D{hasController($){return L.hasController($)}getControllerPath($){return L.getControllerPath($)}getControllerOptions($){return L.getControllerOptions($)}getRoutes($){return L.getRoutes($)}getParameters($){return L.getParameters($)}getContextIndices($){return L.getContextIndices($)}getModuleOptions($){return L.getModuleOptions($)}getControllerComponents($,_){return L.getController($,_)}getHandlerComponents($,_){return L.getHandler($,_)}}class C{controllerPaths=new Map;controllerOptions=new Map;routes=new Map;parameters=new Map;contextIndices=new Map;modules=new Map;controllerComponents=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);handlerComponents=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);static fromRootModule($,_=new D){let W=new C;return W.captureModuleGraph($,_),W}hasController($){return this.controllerPaths.has($)}getControllerPath($){return this.controllerPaths.get($)||""}getControllerOptions($){let _=this.controllerOptions.get($);return _?{..._}:{}}getRoutes($){return(this.routes.get($)||[]).map((_)=>this.cloneRouteDefinition(_))}getParameters($){let _=this.parameters.get($);if(!_)return new Map;let W=new Map;for(let[Q,X]of _.entries())W.set(Q,X.map((Z)=>({...Z})));return W}getContextIndices($){return new Map(this.contextIndices.get($)||new Map)}getModuleOptions($){let _=this.modules.get($);if(!_)return;return{controllers:_.controllers?[..._.controllers]:void 0,services:_.services?[..._.services]:void 0,imports:_.imports?[..._.imports]:void 0}}getControllerComponents($,_){return[...this.controllerComponents.get($).get(_)||[]]}getHandlerComponents($,_){return[...this.handlerComponents.get($).get(_)||[]]}captureModuleGraph($,_){let W=new Set,Q=new Set,X=(Z)=>{if(W.has(Z))return;W.add(Z);let U=_.getModuleOptions(Z);if(!U)return;let J={controllers:U.controllers?[...U.controllers]:void 0,services:U.services?[...U.services]:void 0,imports:U.imports?[...U.imports]:void 0};this.modules.set(Z,J);for(let Y of J.controllers||[])Q.add(Y);for(let Y of J.imports||[])X(Y)};X($);for(let Z of Q)this.captureController(Z,_)}captureController($,_){if(!_.hasController($))return;this.controllerPaths.set($,_.getControllerPath($)||""),this.controllerOptions.set($,{..._.getControllerOptions($)});let W=(_.getRoutes($)||[]).map((Z)=>this.cloneRouteDefinition(Z));this.routes.set($,W);let Q=_.getParameters($),X=new Map;for(let[Z,U]of Q.entries())X.set(Z,(U||[]).map((J)=>({...J})));this.parameters.set($,X),this.contextIndices.set($,new Map(_.getContextIndices($)||new Map));for(let Z of["middleware","guard","pipe","filter"])this.controllerComponents.get(Z).set($,[..._.getControllerComponents(Z,$)||[]]);for(let Z of W){let U=`${$.name}:${String(Z.handlerName)}`;for(let J of["middleware","guard","pipe","filter"])this.handlerComponents.get(J).set(U,[..._.getHandlerComponents(J,U)||[]])}}cloneRouteDefinition($){return{...$,version:Array.isArray($.version)?[...$.version]:$.version}}}class m{routes=[];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($)}getRoutes(){return this.routes}getRoutesByController($){return this.routes.filter((_)=>_.controller===$)}getRoutesByMethod($){return this.routes.filter((_)=>_.method.toUpperCase()===$.toUpperCase())}getRoutesByPath($){return this.routes.filter((_)=>$.test(_.fullPath))}clear(){this.routes.length=0}}class u{isService($){return L.isService($)}}class E{serviceRegistry;diagnosticsEmitter;debugDi;constructor($=new u,_=new H,W=!1){this.serviceRegistry=$;this.diagnosticsEmitter=_;this.debugDi=W}instances=new Map;emitDiagnostic($){if(!this.debugDi)return;this.diagnosticsEmitter.emit($)}resolve($){return this.resolveWithTracking($,new Set)}resolveWithTracking($,_){if(this.instances.has($))return this.emitDiagnostic({level:"debug",category:"di",message:`Resolved ${$.name} from DI cache`}),this.instances.get($);if(_.has($)){let Z=[..._.keys(),$].map((U)=>U.name).join(" -> ");throw this.emitDiagnostic({level:"error",category:"di",message:`Circular dependency detected while resolving ${$.name}`,details:{cycle:Z}}),Error(`Circular dependency detected: ${Z}`)}_.add($),this.emitDiagnostic({level:"debug",category:"di",message:`Resolving ${$.name}`,details:{resolving:[..._].map((Z)=>Z.name)}});let W=Reflect.getMetadata("design:paramtypes",$)||[];if($.length>0&&W.length===0){if(!this.serviceRegistry.isService($))throw this.emitDiagnostic({level:"error",category:"di",message:`Cannot resolve ${$.name}: missing @Service() decorator`}),Error(`Cannot resolve ${$.name}: it is not decorated with @Service(). Did you forget to add @Service() to the class?`);throw this.emitDiagnostic({level:"error",category:"di",message:`Cannot resolve ${$.name}: missing constructor metadata`}),Error(`Cannot resolve dependencies for ${$.name}: constructor metadata is missing. Ensure 'reflect-metadata' is imported and 'emitDecoratorMetadata' is enabled.`)}let Q=W.map((Z,U)=>{if(!Z||Z===Object||Z===Array||Z===Function)throw this.emitDiagnostic({level:"error",category:"di",message:`Cannot resolve dependency at index ${U} of ${$.name}`}),Error(`Cannot resolve dependency at index ${U} of ${$.name}. Use concrete class types for constructor dependencies.`);return this.resolveWithTracking(Z,new Set(_))}),X=new $(...Q);return this.instances.set($,X),this.emitDiagnostic({level:"debug",category:"di",message:`Created ${$.name} instance`,details:{dependencyCount:Q.length}}),X}register($,_){this.instances.set($,_)}has($){return this.instances.has($)}clear(){this.instances.clear()}}import{HTTPException as U$}from"hono/http-exception";class d extends Error{status;code;category;remediation;details;constructor($,_){super($);if(this.name="FrameworkError",this.status=_.status,this.code=_.code,this.category=_.category,this.remediation=_.remediation,this.details=_.details,_.cause!==void 0)this.cause=_.cause}}function R($,_,W){let Q=$ instanceof Error?$:Error(String($)),X=new Date().toISOString(),Z=_.get("requestId"),U=_.req.path;if(Q instanceof U$)return{response:{status:W?.status||Q.status,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:W?.status||Q.status};if(Q instanceof d){let B=W?.status||Q.status||500;return{response:{status:B,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code||Q.code,details:{category:Q.category,remediation:Q.remediation,...Q.details,...W?.additionalDetails},...W?.detail&&{detail:W.detail}},status:B}}if(Q.statusCode||Q.status){let B=Q.statusCode||Q.status||500,q=W?.status||B;return{response:{status:q,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code||Q.name,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:q}}let J=W?.status||500;return{response:{status:J,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code||Q.name,details:W?.additionalDetails||{stack:Q.stack},...W?.detail&&{detail:W.detail}},status:J}}function T($){return(_="",W={})=>{return(Q,X,Z)=>{let U=Q.constructor;L.addRoute(U,{path:_,method:$,handlerName:X,version:W.version,prefix:W.prefix})}}}function z($,_){let W=(Q,X)=>{if(Q===void 0)return X;return X.get(String(Q))};return(Q)=>{return(X,Z,U)=>{let J=X.constructor;if(!L.getParameters(J).size)L.setParameterMap(J,new Map);let Y=L.getParameters(J);if(!Y.has(Z))Y.set(Z,[]);let q=Reflect.getMetadata("design:paramtypes",X,Z)?.[U];if(Y.get(Z).push({index:U,name:$,data:Q,factory:_||W,metatype:q}),$==="context"){if(!L.getContextIndices(J).size)L.setContextIndices(J,new Map);L.getContextIndices(J).set(Z,U)}}}}class c{static handle(){return async($,_)=>{let{response:W,status:Q}=R($,_);return _.json(W,Q)}}}class p{static handle(){return async($)=>{return $.json({message:`Not Found - ${$.req.path}`},404)}}}var i=Symbol("VERSION_NEUTRAL");var I="__honest_controllerClass",M="__honest_handlerName",l="__honest.body.cache";var X_=($)=>typeof $>"u",S=($)=>$===null||typeof $>"u",K=($)=>$!==null&&typeof $==="object",Z_=($)=>{if(!K($))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)},_$=($)=>typeof $==="function",f=($)=>typeof $==="string",J_=($)=>typeof $==="number",U_=($)=>$.length===0,Y_=($)=>typeof $==="symbol",B_=($)=>typeof $==="string"?$.charAt(0)!=="/"?"/"+$:$:"",s=($)=>$?$.startsWith("/")?("/"+$.replace(/\/+$/,"")).replace(/\/+/g,"/"):"/"+$.replace(/\/+$/,""):"/",L_=($)=>$.endsWith("/")?$.slice(0,-1):$,W$=($)=>{return _$($)&&!S($.prototype)&&!_$($.prototype)&&Object.getOwnPropertyNames($.prototype).length>=1};class n{container;metadataRepository;diagnosticsEmitter;globalComponents=new Map([["middleware",new Set],["guard",new Set],["pipe",new Set],["filter",new Set]]);constructor($,_=new D,W=new H){this.container=$;this.metadataRepository=_;this.diagnosticsEmitter=W}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)}registerGlobal($,..._){_.forEach((W)=>{this.globalComponents.get($).add(W)})}getGlobal($){return this.globalComponents.get($)}getComponents($,_,W){let Q=`${_.name}:${String(W)}`,X=this.metadataRepository.getHandlerComponents($,Q),Z=this.metadataRepository.getControllerComponents($,_);return[...Array.from(this.globalComponents.get($)||[]),...Z,...X]}resolveMiddleware($){return $.map((_)=>{if(K(_)&&"use"in _)return _.use.bind(_);let W=this.container.resolve(_);return W.use.bind(W)})}getHandlerMiddleware($,_){let W=this.getComponents("middleware",$,_);return this.resolveMiddleware(W)}getGlobalMiddleware(){let $=Array.from(this.globalComponents.get("middleware")||[]);return this.resolveMiddleware($)}resolveGuards($){return $.map((_)=>{if(K(_)&&"canActivate"in _)return _;return this.container.resolve(_)})}getHandlerGuards($,_){let W=this.getComponents("guard",$,_);return this.resolveGuards(W)}resolvePipes($){return $.map((_)=>{if(K(_)&&"transform"in _)return _;return this.container.resolve(_)})}getHandlerPipes($,_){let W=this.getComponents("pipe",$,_);return this.resolvePipes(W)}async executePipes($,_,W){let Q=$;for(let X of W)Q=await X.transform(Q,_);return Q}async handleException($,_){let W=_.get(I),Q=_.get(M);if(W&&Q){let J=this.metadataRepository.getHandlerComponents("filter",`${W.name}:${Q}`);if(J.length>0){let Y=await this.executeFilters(J,$,_);if(Y)return Y}}if(W){let J=this.metadataRepository.getControllerComponents("filter",W);if(J.length>0){let Y=await this.executeFilters(J,$,_);if(Y)return Y}}let X=Array.from(this.globalComponents.get("filter")||[]);if(X.length>0){let J=await this.executeFilters(X,$,_);if(J)return J}let{response:Z,status:U}=R($,_);return _.json(Z,U)}async executeFilters($,_,W){for(let Q of $){let X;if(K(Q)&&"catch"in Q)X=Q;else X=this.container.resolve(Q);try{let Z=await X.catch(_,W);if(Z!==void 0)return Z}catch(Z){let U=X.constructor?.name||"UnknownFilter";this.diagnosticsEmitter.emit({level:"error",category:"errors",message:`Error in exception filter ${U}`,details:{error:Z instanceof Error?Z.message:String(Z)}});let{response:J,status:Y}=R(Z,W);return W.json(J,Y)}}return}async registerModule($,_=new Set){if(_.has($))return[];_.add($);let W=this.metadataRepository.getModuleOptions($);if(!W)throw this.diagnosticsEmitter.emit({level:"error",category:"startup",message:`Module ${$.name} is not properly decorated with @Module()`}),Error(`Module ${$.name} is not properly decorated with @Module()`);let Q=[];if(W.imports&&W.imports.length>0)for(let X of W.imports){let Z=await this.registerModule(X,_);Q.push(...Z)}if(W.services&&W.services.length>0)for(let X of W.services)this.container.resolve(X);if(W.controllers&&W.controllers.length>0)Q.push(...W.controllers);return Q}}class a{async invoke({handler:$,args:_,context:W,contextIndex:Q}){let X=await $(..._);if(Q!==void 0)return X;if(X instanceof Response)return X;if(S(X))return W.json(null);if(f(X))return W.text(X);return W.json(X)}}class o{componentManager;constructor($){this.componentManager=$}async resolveArguments($){let{controllerName:_,handlerName:W,handlerArity:Q,handlerParams:X,handlerPipes:Z,context:U}=$,J=X.length>0?Math.max(...X.map((B)=>B.index)):-1,Y=Array(Math.max(Q,J+1));for(let B of X){if(typeof B.factory!=="function")throw Error(`Invalid parameter decorator metadata for ${_}.${String(W)}`);let q=await B.factory(B.data,U),F=await this.componentManager.executePipes(q,{type:B.name,metatype:B.metatype,data:typeof B.data==="string"||typeof B.data>"u"?B.data:String(B.data)},Z);Y[B.index]=F}return Y}}import{HTTPException as Y$}from"hono/http-exception";class r{componentManager;parameterResolver;handlerInvoker;diagnosticsEmitter;debugPipeline;constructor($,_,W,Q=new H,X=!1){this.componentManager=$;this.parameterResolver=_;this.handlerInvoker=W;this.diagnosticsEmitter=Q;this.debugPipeline=X}async execute($){let{controllerClass:_,handlerName:W,handler:Q,handlerParams:X,handlerPipes:Z,contextIndex:U,context:J}=$;J.set(I,_),J.set(M,String(W));let Y=this.componentManager.getHandlerGuards(_,W);for(let q of Y)if(!await q.canActivate(J)){if(this.debugPipeline)this.diagnosticsEmitter.emit({level:"warn",category:"pipeline",message:`Guard rejected request at ${_.name}.${String(W)}`,details:{guard:q.constructor?.name||"UnknownGuard"}});throw new Y$(403,{message:`Forbidden by ${q.constructor?.name||"UnknownGuard"} at ${_.name}.${String(W)}`})}let B=await this.parameterResolver.resolveArguments({controllerName:_.name,handlerName:W,handlerArity:Q.length,handlerParams:X,handlerPipes:Z,context:J});if(this.debugPipeline)this.diagnosticsEmitter.emit({level:"debug",category:"pipeline",message:`Resolved handler arguments for ${_.name}.${String(W)}`,details:{guardCount:Y.length,parameterCount:X.length,pipeCount:Z.length}});return this.handlerInvoker.invoke({handler:Q,args:B,context:J,contextIndex:U})}}class t{hono;container;routeRegistry;componentManager;parameterResolver;pipelineExecutor;metadataRepository;diagnosticsEmitter;globalPrefix;globalVersion;constructor($,_,W,Q,X=new D,Z=new H,U={}){this.hono=$,this.container=_,this.routeRegistry=W,this.componentManager=Q,this.parameterResolver=new o(this.componentManager),this.diagnosticsEmitter=Z,this.pipelineExecutor=new r(this.componentManager,this.parameterResolver,new a,this.diagnosticsEmitter,Boolean(U.debugPipeline)),this.metadataRepository=X,this.globalPrefix=U.prefix!==void 0?this.normalizePath(U.prefix):void 0,this.globalVersion=U.version,this.applyGlobalMiddleware()}applyGlobalMiddleware(){let $=this.componentManager.getGlobalMiddleware();for(let _ of $)this.hono.use("*",_)}normalizePath($){if(!f($))throw Error(`Invalid path: expected a string but received ${typeof $}. Check your @Controller() and route decorator arguments.`);return s($)}registerRouteHandler($,_,W,Q){if(W.length>0)this.hono.on($.toUpperCase(),[_],...W,Q);else this.hono.on($.toUpperCase(),[_],Q)}buildRoutePath($,_,W,Q){return s(`${$}${_}${W}${Q}`)}formatVersionSegment($){if(S($))return"";return $===i?"":`/v${String($)}`}async registerController($){if(!this.metadataRepository.hasController($))throw Error(`Controller ${$.name} is not decorated with @Controller()`);let _=this.metadataRepository.getControllerPath($)||"",W=this.metadataRepository.getControllerOptions($)||{},Q=this.metadataRepository.getRoutes($)||[],X=this.metadataRepository.getParameters($)||new Map,Z=this.metadataRepository.getContextIndices($)||new Map,U=this.normalizePath(_),J=this.container.resolve($),Y=W.prefix!==void 0?W.prefix:this.globalPrefix,B=W.version!==void 0?W.version:this.globalVersion;if(Q.length===0)throw Error(`Controller ${$.name} has no route handlers. Add HTTP method decorators like @Get()`);for(let q of Q){let{path:F,method:A,version:V,prefix:G}=q,O=G!==void 0?G:Y,k=!S(O)?this.normalizePath(O):"",N=V!==void 0?V:B,P=this.normalizePath(F);if(S(N)){this.registerRoute(J,q,X,Z,$,k,"",U,P,A);continue}if(N===i){this.registerRoute(J,q,X,Z,$,k,"",U,P,A),this.registerRoute(J,q,X,Z,$,k,"/:version{v[0-9]+}",U,P,A);continue}if(Array.isArray(N)){for(let b of N){let y=this.formatVersionSegment(b);this.registerRoute(J,q,X,Z,$,k,y,U,P,A)}continue}let v=this.formatVersionSegment(N);this.registerRoute(J,q,X,Z,$,k,v,U,P,A)}}registerRoute($,_,W,Q,X,Z,U,J,Y,B){let{handlerName:q}=_,F=this.buildRoutePath(Z,U,J,Y),A=$[q].bind($),V=W.get(q)||[],G=Q.get(q),O=this.componentManager.getHandlerMiddleware(X,q),k=this.componentManager.getHandlerPipes(X,q);this.routeRegistry.registerRoute({controller:X.name,handler:q,method:B,prefix:Z,version:U,route:J,path:Y,fullPath:F,parameters:V});let N=this.componentManager,P=this.pipelineExecutor,v=async(b)=>{try{return await P.execute({controllerClass:X,handlerName:q,handler:A,handlerParams:V,handlerPipes:k,contextIndex:G,context:b})}catch(y){return N.handleException(y,b)}};this.registerRouteHandler(B,F,O,v)}}class w{hono;container;context;routeRegistry;metadataRepository;componentManager;routeManager;diagnosticsEmitter;options;static DEFAULT_PLUGIN_NAME="AnonymousPlugin";constructor($={},_=new D){this.options=K($)?$:{};let W=this.options.debug===!0||typeof this.options.debug==="object"&&Boolean(this.options.debug.pipeline),Q=this.options.debug===!0||typeof this.options.debug==="object"&&Boolean(this.options.debug.di);if(this.hono=new B$(this.options.hono),this.diagnosticsEmitter=this.options.diagnostics||new g,this.container=this.options.container||new E(void 0,this.diagnosticsEmitter,Q),this.context=new h,this.routeRegistry=new m,this.metadataRepository=_,this.componentManager=new n(this.container,this.metadataRepository,this.diagnosticsEmitter),this.componentManager.setupGlobalComponents(this.options),this.setupErrorHandlers(),this.routeManager=new t(this.hono,this.container,this.routeRegistry,this.componentManager,this.metadataRepository,this.diagnosticsEmitter,{prefix:this.options.routing?.prefix,version:this.options.routing?.version,debugPipeline:W}),this.options.deprecations?.printPreV1Warning)this.diagnosticsEmitter.emit({level:"warn",category:"deprecations",message:"Pre-v1 warning: APIs may change before 1.0.0."})}setupErrorHandlers(){this.hono.notFound(this.options.notFound||p.handle()),this.hono.onError(this.options.onError||c.handle())}resolvePlugin($){if(W$($))return new $;return $}normalizePluginEntry($,_){if($&&typeof $==="object"&&"plugin"in $){let Q=$,X=this.resolvePlugin(Q.plugin),Z=this.resolvePluginName(X,_,Q.name);return{plugin:X,name:Z,before:Q.before??[],after:Q.after??[],provides:X.meta?.provides??[],requires:X.meta?.requires??[],index:_,preProcessors:Q.preProcessors??[],postProcessors:Q.postProcessors??[]}}let W=this.resolvePlugin($);return{plugin:W,name:this.resolvePluginName(W,_),before:[],after:[],provides:W.meta?.provides??[],requires:W.meta?.requires??[],index:_,preProcessors:[],postProcessors:[]}}resolvePluginName($,_,W){let Q=W||$.meta?.name||$.constructor?.name;if(!Q||Q===w.DEFAULT_PLUGIN_NAME)return`${w.DEFAULT_PLUGIN_NAME}#${_+1}`;return Q}resolvePluginExecutionOrder($){if($.length===0)return $;let _=new Map;for(let J=0;J<$.length;J++){let Y=$[J];if(_.has(Y.name))throw Error(`Duplicate plugin name detected: ${Y.name}. Use unique plugin names in options.plugins.`);_.set(Y.name,J)}let W=Array($.length).fill(0),Q=new Map,X=(J,Y)=>{if(!Q.has(J))Q.set(J,new Set);let B=Q.get(J);if(!B.has(Y))B.add(Y),W[Y]++};for(let J=0;J<$.length;J++){let Y=$[J];for(let B of Y.after){let q=_.get(B);if(q===void 0)throw Error(`Plugin ordering error: ${Y.name} declares after '${B}', but no such plugin is registered.`);X(q,J)}for(let B of Y.before){let q=_.get(B);if(q===void 0)throw Error(`Plugin ordering error: ${Y.name} declares before '${B}', but no such plugin is registered.`);X(J,q)}}let Z=[];for(let J=0;J<$.length;J++)if(W[J]===0)Z.push(J);Z.sort((J,Y)=>$[J].index-$[Y].index);let U=[];while(Z.length>0){let J=Z.shift();U.push(J);let Y=Q.get(J);if(!Y)continue;for(let B of Y)if(W[B]--,W[B]===0)Z.push(B);Z.sort((B,q)=>$[B].index-$[q].index)}if(U.length!==$.length)throw Error("Plugin ordering cycle detected. Check before/after constraints in options.plugins.");return U.map((J)=>$[J])}validatePluginCapabilities($){if($.length===0)return;let _=new Set;for(let W of $){for(let Q of W.requires)if(!_.has(Q))throw Error(`Plugin capability error: ${W.name} requires '${Q}', but it was not provided by any previous plugin. Use before/after ordering or register the provider plugin earlier.`);for(let Q of W.provides)_.add(Q)}}shouldEmitRouteDiagnostics(){let $=this.options.debug;return $===!0||typeof $==="object"&&Boolean($.routes)}emitStartupGuide($,_){let W=this.options.startupGuide;if(!W)return;let Q=typeof W==="object"&&Boolean(W.verbose),X=$ instanceof Error?$.message:String($),Z=this.createStartupGuideHints(X);if(this.diagnosticsEmitter.emit({level:"warn",category:"startup",message:"Startup guide",details:{rootModule:_.name,errorMessage:X,hints:Z,verbose:Q}}),Q)this.diagnosticsEmitter.emit({level:"warn",category:"startup",message:"Startup guide (verbose)",details:{steps:["Verify decorators are present for controllers/services used by DI and routing.","Ensure 'reflect-metadata' is imported once at entry and 'emitDecoratorMetadata' is enabled.","Enable debug.startup for extra startup diagnostics and timing details."]}})}createStartupGuideHints($){let _=new Set;if(_.add("Check module wiring: root module imports, controllers, and services should be registered correctly."),$.includes("not decorated with @Controller()"))_.add("Add @Controller() to the class or remove it from module.controllers.");if($.includes("has no route handlers"))_.add("Add at least one HTTP method decorator such as @Get() or @Post() in the controller.");if($.includes("not decorated with @Service()"))_.add("Add @Service() to injectable classes used in constructor dependencies.");if($.includes("constructor metadata is missing")||$.includes("reflect-metadata"))_.add("Import 'reflect-metadata' in your entry file and enable 'emitDecoratorMetadata' in tsconfig.");if($.includes("Strict mode: no routes were registered"))_.add("Disable strict.requireRoutes for empty modules, or add a controller with at least one route.");if($.includes("Plugin ordering error")||$.includes("Plugin capability error"))_.add("Check plugin order and before/after constraints, then ensure required capabilities are provided earlier.");return[..._]}async register($){let _=await this.componentManager.registerModule($),W=this.shouldEmitRouteDiagnostics();for(let Q of _){let X=Date.now(),Z=this.routeRegistry.getRoutes().length;try{if(await this.routeManager.registerController(Q),W)this.diagnosticsEmitter.emit({level:"info",category:"routes",message:"Registered controller routes",details:{controller:Q.name,routeCountAdded:this.routeRegistry.getRoutes().length-Z,registrationDurationMs:Date.now()-X}})}catch(U){if(W)this.diagnosticsEmitter.emit({level:"error",category:"routes",message:"Failed to register controller routes",details:{controller:Q.name,registrationDurationMs:Date.now()-X,errorMessage:U instanceof Error?U.message:String(U)}});throw U}}return this}static async create($,_={}){let W=Date.now(),Q=C.fromRootModule($),X=new w(_,Q),Z=(_.plugins||[]).map((V,G)=>X.normalizePluginEntry(V,G)),U=X.resolvePluginExecutionOrder(Z);X.validatePluginCapabilities(U);let J=X.getContext(),Y=_.debug,B=Y===!0||typeof Y==="object"&&Y.plugins,q=Y===!0||typeof Y==="object"&&Y.routes,F=Y===!0||typeof Y==="object"&&(Y.startup||q),A=!1;try{if(B&&U.length>0)X.diagnosticsEmitter.emit({level:"info",category:"plugins",message:`Plugin order: ${U.map(({name:G})=>G).join(" -> ")}`});for(let{plugin:G,preProcessors:O}of U){for(let k of O)await k(X,X.hono,J);if(G.beforeModulesRegistered)await G.beforeModulesRegistered(X,X.hono)}await X.register($);let V=X.getRoutes();if(F)X.diagnosticsEmitter.emit({level:"info",category:"startup",message:`Application registered ${V.length} route(s)`,details:{routeCount:V.length,rootModule:$.name}});if(_.strict?.requireRoutes&&V.length===0){A=!0,X.diagnosticsEmitter.emit({level:"error",category:"startup",message:"Strict mode failed: no routes were registered",details:{rootModule:$.name,requireRoutes:!0,startupDurationMs:Date.now()-W}});let G=Error("Strict mode: no routes were registered. Check your module/controller decorators.");throw X.emitStartupGuide(G,$),G}if(q)X.diagnosticsEmitter.emit({level:"info",category:"routes",message:"Registered routes",details:{routes:V.map((G)=>`${G.method.toUpperCase()} ${G.fullPath}`)}});for(let{plugin:G,postProcessors:O}of U){if(G.afterModulesRegistered)await G.afterModulesRegistered(X,X.hono);for(let k of O)await k(X,X.hono,J)}if(F)X.diagnosticsEmitter.emit({level:"info",category:"startup",message:"Application startup completed",details:{rootModule:$.name,pluginCount:U.length,routeCount:V.length,startupDurationMs:Date.now()-W}});return{app:X,hono:X.getApp()}}catch(V){if(X.emitStartupGuide(V,$),F&&!A)X.diagnosticsEmitter.emit({level:"error",category:"startup",message:"Application startup failed",details:{rootModule:$.name,startupDurationMs:Date.now()-W,errorMessage:V instanceof Error?V.message:String(V)}});throw V}}getApp(){return this.hono}getContainer(){return this.container}getContext(){return this.context}getRoutes(){return this.routeRegistry.getRoutes()}}import{html as j,raw as e}from"hono/html";var L$={type:"website",locale:"en_US"},$$=($)=>{if(!$)return"";return Object.entries($).map(([_,W])=>{if(typeof W==="boolean")return W?_:"";let Q=String(W).replace(/"/g,""");return`${_}="${Q}"`}).filter(Boolean).join(" ")},r_=($)=>{let _={...L$,...$};return j`
|
|
1
|
+
import"reflect-metadata";import{Hono as B$}from"hono";class h{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 g{emit($){let _=`[HonestJS:${$.category}]`,W=$.details?[_,$.message,$.details]:[_,$.message];switch($.level){case"debug":case"info":console.info(...W);break;case"warn":console.warn(...W);break;case"error":console.error(...W);break}}}class D{emit($){}}class q{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 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 registerController($,_,W){let Q=this.controller.get($);if(!Q.has(_))Q.set(_,[]);Q.get(_).push(W)}static getController($,_){return this.controller.get($).get(_)||[]}static registerHandler($,_,W){let Q=this.handler.get($);if(!Q.has(_))Q.set(_,[]);Q.get(_).push(W)}static getHandler($,_){return this.handler.get($).get(_)||[]}static clearHandlerComponents(){for(let $ of this.handler.values())$.clear()}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.controller.values())$.clear();for(let $ of this.handler.values())$.clear()}}class O{hasController($){return q.hasController($)}getControllerPath($){return q.getControllerPath($)}getControllerOptions($){return q.getControllerOptions($)}getRoutes($){return q.getRoutes($)}getParameters($){return q.getParameters($)}getContextIndices($){return q.getContextIndices($)}getModuleOptions($){return q.getModuleOptions($)}getControllerComponents($,_){return q.getController($,_)}getHandlerComponents($,_){return q.getHandler($,_)}}class C{controllerPaths=new Map;controllerOptions=new Map;routes=new Map;parameters=new Map;contextIndices=new Map;modules=new Map;controllerComponents=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);handlerComponents=new Map([["middleware",new Map],["guard",new Map],["pipe",new Map],["filter",new Map]]);static fromRootModule($,_=new O){let W=new C;return W.captureModuleGraph($,_),W}hasController($){return this.controllerPaths.has($)}getControllerPath($){return this.controllerPaths.get($)||""}getControllerOptions($){let _=this.controllerOptions.get($);return _?{..._}:{}}getRoutes($){return(this.routes.get($)||[]).map((_)=>this.cloneRouteDefinition(_))}getParameters($){let _=this.parameters.get($);if(!_)return new Map;let W=new Map;for(let[Q,X]of _.entries())W.set(Q,X.map((Z)=>({...Z})));return W}getContextIndices($){return new Map(this.contextIndices.get($)||new Map)}getModuleOptions($){let _=this.modules.get($);if(!_)return;return{controllers:_.controllers?[..._.controllers]:void 0,services:_.services?[..._.services]:void 0,imports:_.imports?[..._.imports]:void 0}}getControllerComponents($,_){return[...this.controllerComponents.get($).get(_)||[]]}getHandlerComponents($,_){return[...this.handlerComponents.get($).get(_)||[]]}captureModuleGraph($,_){let W=new Set,Q=new Set,X=(Z)=>{if(W.has(Z))return;W.add(Z);let U=_.getModuleOptions(Z);if(!U)return;let J={controllers:U.controllers?[...U.controllers]:void 0,services:U.services?[...U.services]:void 0,imports:U.imports?[...U.imports]:void 0};this.modules.set(Z,J);for(let Y of J.controllers||[])Q.add(Y);for(let Y of J.imports||[])X(Y)};X($);for(let Z of Q)this.captureController(Z,_)}captureController($,_){if(!_.hasController($))return;this.controllerPaths.set($,_.getControllerPath($)||""),this.controllerOptions.set($,{..._.getControllerOptions($)});let W=(_.getRoutes($)||[]).map((Z)=>this.cloneRouteDefinition(Z));this.routes.set($,W);let Q=_.getParameters($),X=new Map;for(let[Z,U]of Q.entries())X.set(Z,(U||[]).map((J)=>({...J})));this.parameters.set($,X),this.contextIndices.set($,new Map(_.getContextIndices($)||new Map));for(let Z of["middleware","guard","pipe","filter"])this.controllerComponents.get(Z).set($,[..._.getControllerComponents(Z,$)||[]]);for(let Z of W){let U=`${$.name}:${String(Z.handlerName)}`;for(let J of["middleware","guard","pipe","filter"])this.handlerComponents.get(J).set(U,[..._.getHandlerComponents(J,U)||[]])}}cloneRouteDefinition($){return{...$,version:Array.isArray($.version)?[...$.version]:$.version}}}class m{routes=[];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($)}getRoutes(){return this.routes}getRoutesByController($){return this.routes.filter((_)=>_.controller===$)}getRoutesByMethod($){return this.routes.filter((_)=>_.method.toUpperCase()===$.toUpperCase())}getRoutesByPath($){return this.routes.filter((_)=>$.test(_.fullPath))}clear(){this.routes.length=0}}class u{isService($){return q.isService($)}}class E{serviceRegistry;logger;debugDi;constructor($=new u,_=new D,W=!1){this.serviceRegistry=$;this.logger=_;this.debugDi=W}instances=new Map;emitLog($){if(!this.debugDi)return;this.logger.emit($)}resolve($){return this.resolveWithTracking($,new Set)}resolveWithTracking($,_){if(this.instances.has($))return this.emitLog({level:"debug",category:"di",message:`Resolved ${$.name} from DI cache`}),this.instances.get($);if(_.has($)){let Z=[..._.keys(),$].map((U)=>U.name).join(" -> ");throw this.emitLog({level:"error",category:"di",message:`Circular dependency detected while resolving ${$.name}`,details:{cycle:Z}}),Error(`Circular dependency detected: ${Z}`)}_.add($),this.emitLog({level:"debug",category:"di",message:`Resolving ${$.name}`,details:{resolving:[..._].map((Z)=>Z.name)}});let W=Reflect.getMetadata("design:paramtypes",$)||[];if($.length>0&&W.length===0){if(!this.serviceRegistry.isService($))throw this.emitLog({level:"error",category:"di",message:`Cannot resolve ${$.name}: missing @Service() decorator`}),Error(`Cannot resolve ${$.name}: it is not decorated with @Service(). Did you forget to add @Service() to the class?`);throw this.emitLog({level:"error",category:"di",message:`Cannot resolve ${$.name}: missing constructor metadata`}),Error(`Cannot resolve dependencies for ${$.name}: constructor metadata is missing. Ensure 'reflect-metadata' is imported and 'emitDecoratorMetadata' is enabled.`)}let Q=W.map((Z,U)=>{if(!Z||Z===Object||Z===Array||Z===Function)throw this.emitLog({level:"error",category:"di",message:`Cannot resolve dependency at index ${U} of ${$.name}`}),Error(`Cannot resolve dependency at index ${U} of ${$.name}. Use concrete class types for constructor dependencies.`);return this.resolveWithTracking(Z,new Set(_))}),X=new $(...Q);return this.instances.set($,X),this.emitLog({level:"debug",category:"di",message:`Created ${$.name} instance`,details:{dependencyCount:Q.length}}),X}register($,_){this.instances.set($,_)}has($){return this.instances.has($)}clear(){this.instances.clear()}}import{HTTPException as U$}from"hono/http-exception";class d extends Error{status;code;category;remediation;details;constructor($,_){super($);if(this.name="FrameworkError",this.status=_.status,this.code=_.code,this.category=_.category,this.remediation=_.remediation,this.details=_.details,_.cause!==void 0)this.cause=_.cause}}function R($,_,W){let Q=$ instanceof Error?$:Error(String($)),X=new Date().toISOString(),Z=_.get("requestId"),U=_.req.path;if(Q instanceof U$)return{response:{status:W?.status||Q.status,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:W?.status||Q.status};if(Q instanceof d){let B=W?.status||Q.status||500;return{response:{status:B,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code||Q.code,details:{category:Q.category,remediation:Q.remediation,...Q.details,...W?.additionalDetails},...W?.detail&&{detail:W.detail}},status:B}}if(Q.statusCode||Q.status){let B=Q.statusCode||Q.status||500,G=W?.status||B;return{response:{status:G,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code||Q.name,details:W?.additionalDetails,...W?.detail&&{detail:W.detail}},status:G}}let J=W?.status||500;return{response:{status:J,message:W?.title||Q.message,timestamp:X,path:U,requestId:Z,code:W?.code||Q.name,details:W?.additionalDetails||{stack:Q.stack},...W?.detail&&{detail:W.detail}},status:J}}function T($){return(_="",W={})=>{return(Q,X,Z)=>{let U=Q.constructor;q.addRoute(U,{path:_,method:$,handlerName:X,version:W.version,prefix:W.prefix})}}}function z($,_){let W=(Q,X)=>{if(Q===void 0)return X;return X.get(String(Q))};return(Q)=>{return(X,Z,U)=>{let J=X.constructor;if(!q.getParameters(J).size)q.setParameterMap(J,new Map);let Y=q.getParameters(J);if(!Y.has(Z))Y.set(Z,[]);let G=Reflect.getMetadata("design:paramtypes",X,Z)?.[U];if(Y.get(Z).push({index:U,name:$,data:Q,factory:_||W,metatype:G}),$==="context"){if(!q.getContextIndices(J).size)q.setContextIndices(J,new Map);q.getContextIndices(J).set(Z,U)}}}}class c{static handle(){return async($,_)=>{let{response:W,status:Q}=R($,_);return _.json(W,Q)}}}class p{static handle(){return async($)=>{return $.json({message:`Not Found - ${$.req.path}`},404)}}}var i=Symbol("VERSION_NEUTRAL");var I="__honest_controllerClass",M="__honest_handlerName",l="__honest.body.cache";var X_=($)=>typeof $>"u",w=($)=>$===null||typeof $>"u",K=($)=>$!==null&&typeof $==="object",Z_=($)=>{if(!K($))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)},_$=($)=>typeof $==="function",f=($)=>typeof $==="string",J_=($)=>typeof $==="number",U_=($)=>$.length===0,Y_=($)=>typeof $==="symbol",B_=($)=>typeof $==="string"?$.charAt(0)!=="/"?"/"+$:$:"",s=($)=>$?$.startsWith("/")?("/"+$.replace(/\/+$/,"")).replace(/\/+/g,"/"):"/"+$.replace(/\/+$/,""):"/",q_=($)=>$.endsWith("/")?$.slice(0,-1):$,W$=($)=>{return _$($)&&!w($.prototype)&&!_$($.prototype)&&Object.getOwnPropertyNames($.prototype).length>=1};class n{container;metadataRepository;logger;globalComponents=new Map([["middleware",new Set],["guard",new Set],["pipe",new Set],["filter",new Set]]);constructor($,_=new O,W=new D){this.container=$;this.metadataRepository=_;this.logger=W}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)}registerGlobal($,..._){_.forEach((W)=>{this.globalComponents.get($).add(W)})}getGlobal($){return this.globalComponents.get($)}getComponents($,_,W){let Q=`${_.name}:${String(W)}`,X=this.metadataRepository.getHandlerComponents($,Q),Z=this.metadataRepository.getControllerComponents($,_);return[...Array.from(this.globalComponents.get($)||[]),...Z,...X]}resolveMiddleware($){return $.map((_)=>{if(K(_)&&"use"in _)return _.use.bind(_);let W=this.container.resolve(_);return W.use.bind(W)})}getHandlerMiddleware($,_){let W=this.getComponents("middleware",$,_);return this.resolveMiddleware(W)}getGlobalMiddleware(){let $=Array.from(this.globalComponents.get("middleware")||[]);return this.resolveMiddleware($)}resolveGuards($){return $.map((_)=>{if(K(_)&&"canActivate"in _)return _;return this.container.resolve(_)})}getHandlerGuards($,_){let W=this.getComponents("guard",$,_);return this.resolveGuards(W)}resolvePipes($){return $.map((_)=>{if(K(_)&&"transform"in _)return _;return this.container.resolve(_)})}getHandlerPipes($,_){let W=this.getComponents("pipe",$,_);return this.resolvePipes(W)}async executePipes($,_,W){let Q=$;for(let X of W)Q=await X.transform(Q,_);return Q}async handleException($,_){let W=_.get(I),Q=_.get(M);if(W&&Q){let J=this.metadataRepository.getHandlerComponents("filter",`${W.name}:${Q}`);if(J.length>0){let Y=await this.executeFilters(J,$,_);if(Y)return Y}}if(W){let J=this.metadataRepository.getControllerComponents("filter",W);if(J.length>0){let Y=await this.executeFilters(J,$,_);if(Y)return Y}}let X=Array.from(this.globalComponents.get("filter")||[]);if(X.length>0){let J=await this.executeFilters(X,$,_);if(J)return J}let{response:Z,status:U}=R($,_);return _.json(Z,U)}async executeFilters($,_,W){for(let Q of $){let X;if(K(Q)&&"catch"in Q)X=Q;else X=this.container.resolve(Q);try{let Z=await X.catch(_,W);if(Z!==void 0)return Z}catch(Z){let U=X.constructor?.name||"UnknownFilter";this.logger.emit({level:"error",category:"errors",message:`Error in exception filter ${U}`,details:{error:Z instanceof Error?Z.message:String(Z)}});let{response:J,status:Y}=R(Z,W);return W.json(J,Y)}}return}async registerModule($,_=new Set){if(_.has($))return[];_.add($);let W=this.metadataRepository.getModuleOptions($);if(!W)throw this.logger.emit({level:"error",category:"startup",message:`Module ${$.name} is not properly decorated with @Module()`}),Error(`Module ${$.name} is not properly decorated with @Module()`);let Q=[];if(W.imports&&W.imports.length>0)for(let X of W.imports){let Z=await this.registerModule(X,_);Q.push(...Z)}if(W.services&&W.services.length>0)for(let X of W.services)this.container.resolve(X);if(W.controllers&&W.controllers.length>0)Q.push(...W.controllers);return Q}}class a{async invoke({handler:$,args:_,context:W,contextIndex:Q}){let X=await $(..._);if(Q!==void 0)return X;if(X instanceof Response)return X;if(w(X))return W.json(null);if(f(X))return W.text(X);return W.json(X)}}class o{componentManager;constructor($){this.componentManager=$}async resolveArguments($){let{controllerName:_,handlerName:W,handlerArity:Q,handlerParams:X,handlerPipes:Z,context:U}=$,J=X.length>0?Math.max(...X.map((B)=>B.index)):-1,Y=Array(Math.max(Q,J+1));for(let B of X){if(typeof B.factory!=="function")throw Error(`Invalid parameter decorator metadata for ${_}.${String(W)}`);let G=await B.factory(B.data,U),L=await this.componentManager.executePipes(G,{type:B.name,metatype:B.metatype,data:typeof B.data==="string"||typeof B.data>"u"?B.data:String(B.data)},Z);Y[B.index]=L}return Y}}import{HTTPException as Y$}from"hono/http-exception";class r{componentManager;parameterResolver;handlerInvoker;logger;debugPipeline;constructor($,_,W,Q=new D,X=!1){this.componentManager=$;this.parameterResolver=_;this.handlerInvoker=W;this.logger=Q;this.debugPipeline=X}async execute($){let{controllerClass:_,handlerName:W,handler:Q,handlerParams:X,handlerPipes:Z,contextIndex:U,context:J}=$;J.set(I,_),J.set(M,String(W));let Y=this.componentManager.getHandlerGuards(_,W);for(let G of Y)if(!await G.canActivate(J)){if(this.debugPipeline)this.logger.emit({level:"warn",category:"pipeline",message:`Guard rejected request at ${_.name}.${String(W)}`,details:{guard:G.constructor?.name||"UnknownGuard"}});throw new Y$(403,{message:`Forbidden by ${G.constructor?.name||"UnknownGuard"} at ${_.name}.${String(W)}`})}let B=await this.parameterResolver.resolveArguments({controllerName:_.name,handlerName:W,handlerArity:Q.length,handlerParams:X,handlerPipes:Z,context:J});if(this.debugPipeline)this.logger.emit({level:"debug",category:"pipeline",message:`Resolved handler arguments for ${_.name}.${String(W)}`,details:{guardCount:Y.length,parameterCount:X.length,pipeCount:Z.length}});return this.handlerInvoker.invoke({handler:Q,args:B,context:J,contextIndex:U})}}class t{hono;container;routeRegistry;componentManager;parameterResolver;pipelineExecutor;metadataRepository;logger;globalPrefix;globalVersion;constructor($,_,W,Q,X=new O,Z=new D,U={}){this.hono=$,this.container=_,this.routeRegistry=W,this.componentManager=Q,this.parameterResolver=new o(this.componentManager),this.logger=Z,this.pipelineExecutor=new r(this.componentManager,this.parameterResolver,new a,this.logger,Boolean(U.debugPipeline)),this.metadataRepository=X,this.globalPrefix=U.prefix!==void 0?this.normalizePath(U.prefix):void 0,this.globalVersion=U.version,this.applyGlobalMiddleware()}applyGlobalMiddleware(){let $=this.componentManager.getGlobalMiddleware();for(let _ of $)this.hono.use("*",_)}normalizePath($){if(!f($))throw Error(`Invalid path: expected a string but received ${typeof $}. Check your @Controller() and route decorator arguments.`);return s($)}registerRouteHandler($,_,W,Q){if(W.length>0)this.hono.on($.toUpperCase(),[_],...W,Q);else this.hono.on($.toUpperCase(),[_],Q)}buildRoutePath($,_,W,Q){return s(`${$}${_}${W}${Q}`)}formatVersionSegment($){if(w($))return"";return $===i?"":`/v${String($)}`}async registerController($){if(!this.metadataRepository.hasController($))throw Error(`Controller ${$.name} is not decorated with @Controller()`);let _=this.metadataRepository.getControllerPath($)||"",W=this.metadataRepository.getControllerOptions($)||{},Q=this.metadataRepository.getRoutes($)||[],X=this.metadataRepository.getParameters($)||new Map,Z=this.metadataRepository.getContextIndices($)||new Map,U=this.normalizePath(_),J=this.container.resolve($),Y=W.prefix!==void 0?W.prefix:this.globalPrefix,B=W.version!==void 0?W.version:this.globalVersion;if(Q.length===0)throw Error(`Controller ${$.name} has no route handlers. Add HTTP method decorators like @Get()`);for(let G of Q){let{path:L,method:A,version:j,prefix:V}=G,H=V!==void 0?V:Y,k=!w(H)?this.normalizePath(H):"",N=j!==void 0?j:B,P=this.normalizePath(L);if(w(N)){this.registerRoute(J,G,X,Z,$,k,"",U,P,A);continue}if(N===i){this.registerRoute(J,G,X,Z,$,k,"",U,P,A),this.registerRoute(J,G,X,Z,$,k,"/:version{v[0-9]+}",U,P,A);continue}if(Array.isArray(N)){for(let b of N){let y=this.formatVersionSegment(b);this.registerRoute(J,G,X,Z,$,k,y,U,P,A)}continue}let v=this.formatVersionSegment(N);this.registerRoute(J,G,X,Z,$,k,v,U,P,A)}}registerRoute($,_,W,Q,X,Z,U,J,Y,B){let{handlerName:G}=_,L=this.buildRoutePath(Z,U,J,Y),A=$[G].bind($),j=W.get(G)||[],V=Q.get(G),H=this.componentManager.getHandlerMiddleware(X,G),k=this.componentManager.getHandlerPipes(X,G);this.routeRegistry.registerRoute({controller:X.name,handler:G,method:B,prefix:Z,version:U,route:J,path:Y,fullPath:L,parameters:j});let N=this.componentManager,P=this.pipelineExecutor,v=async(b)=>{try{return await P.execute({controllerClass:X,handlerName:G,handler:A,handlerParams:j,handlerPipes:k,contextIndex:V,context:b})}catch(y){return N.handleException(y,b)}};this.registerRouteHandler(B,L,H,v)}}class S{hono;container;context;routeRegistry;metadataRepository;componentManager;routeManager;logger;options;static DEFAULT_PLUGIN_NAME="AnonymousPlugin";constructor($={},_=new O){this.options=K($)?$:{};let W=this.options.debug===!0||typeof this.options.debug==="object"&&Boolean(this.options.debug.pipeline),Q=this.options.debug===!0||typeof this.options.debug==="object"&&Boolean(this.options.debug.di);if(this.hono=new B$(this.options.hono),this.logger=this.options.logger||new g,this.container=this.options.container||new E(void 0,this.logger,Q),this.context=new h,this.routeRegistry=new m,this.metadataRepository=_,this.componentManager=new n(this.container,this.metadataRepository,this.logger),this.componentManager.setupGlobalComponents(this.options),this.setupErrorHandlers(),this.routeManager=new t(this.hono,this.container,this.routeRegistry,this.componentManager,this.metadataRepository,this.logger,{prefix:this.options.routing?.prefix,version:this.options.routing?.version,debugPipeline:W}),this.options.deprecations?.printPreV1Warning)this.logger.emit({level:"warn",category:"deprecations",message:"Pre-v1 warning: APIs may change before 1.0.0."})}setupErrorHandlers(){this.hono.notFound(this.options.notFound||p.handle()),this.hono.onError(this.options.onError||c.handle())}resolvePlugin($){if(W$($))return new $;return $}normalizePluginEntry($,_){if($&&typeof $==="object"&&"plugin"in $){let Q=$,X=this.resolvePlugin(Q.plugin),Z=this.resolvePluginName(X,_,Q.name);return{plugin:X,name:Z,before:Q.before??[],after:Q.after??[],provides:X.meta?.provides??[],requires:X.meta?.requires??[],index:_,preProcessors:Q.preProcessors??[],postProcessors:Q.postProcessors??[]}}let W=this.resolvePlugin($);return{plugin:W,name:this.resolvePluginName(W,_),before:[],after:[],provides:W.meta?.provides??[],requires:W.meta?.requires??[],index:_,preProcessors:[],postProcessors:[]}}resolvePluginName($,_,W){let Q=W||$.meta?.name||$.constructor?.name;if(!Q||Q===S.DEFAULT_PLUGIN_NAME)return`${S.DEFAULT_PLUGIN_NAME}#${_+1}`;return Q}resolvePluginExecutionOrder($){if($.length===0)return $;let _=new Map;for(let J=0;J<$.length;J++){let Y=$[J];if(_.has(Y.name))throw Error(`Duplicate plugin name detected: ${Y.name}. Use unique plugin names in options.plugins.`);_.set(Y.name,J)}let W=Array($.length).fill(0),Q=new Map,X=(J,Y)=>{if(!Q.has(J))Q.set(J,new Set);let B=Q.get(J);if(!B.has(Y))B.add(Y),W[Y]++};for(let J=0;J<$.length;J++){let Y=$[J];for(let B of Y.after){let G=_.get(B);if(G===void 0)throw Error(`Plugin ordering error: ${Y.name} declares after '${B}', but no such plugin is registered.`);X(G,J)}for(let B of Y.before){let G=_.get(B);if(G===void 0)throw Error(`Plugin ordering error: ${Y.name} declares before '${B}', but no such plugin is registered.`);X(J,G)}}let Z=[];for(let J=0;J<$.length;J++)if(W[J]===0)Z.push(J);Z.sort((J,Y)=>$[J].index-$[Y].index);let U=[];while(Z.length>0){let J=Z.shift();U.push(J);let Y=Q.get(J);if(!Y)continue;for(let B of Y)if(W[B]--,W[B]===0)Z.push(B);Z.sort((B,G)=>$[B].index-$[G].index)}if(U.length!==$.length)throw Error("Plugin ordering cycle detected. Check before/after constraints in options.plugins.");return U.map((J)=>$[J])}validatePluginCapabilities($){if($.length===0)return;let _=new Set;for(let W of $){for(let Q of W.requires)if(!_.has(Q))throw Error(`Plugin capability error: ${W.name} requires '${Q}', but it was not provided by any previous plugin. Use before/after ordering or register the provider plugin earlier.`);for(let Q of W.provides)_.add(Q)}}shouldEmitRouteDiagnostics(){let $=this.options.debug;return $===!0||typeof $==="object"&&Boolean($.routes)}emitStartupGuide($,_){let W=this.options.startupGuide;if(!W)return;let Q=typeof W==="object"&&Boolean(W.verbose),X=$ instanceof Error?$.message:String($),Z=this.createStartupGuideHints(X);if(this.logger.emit({level:"warn",category:"startup",message:"Startup guide",details:{rootModule:_.name,errorMessage:X,hints:Z,verbose:Q}}),Q)this.logger.emit({level:"warn",category:"startup",message:"Startup guide (verbose)",details:{steps:["Verify decorators are present for controllers/services used by DI and routing.","Ensure 'reflect-metadata' is imported once at entry and 'emitDecoratorMetadata' is enabled.","Enable debug.startup for extra startup diagnostics and timing details."]}})}createStartupGuideHints($){let _=new Set;if(_.add("Check module wiring: root module imports, controllers, and services should be registered correctly."),$.includes("not decorated with @Controller()"))_.add("Add @Controller() to the class or remove it from module.controllers.");if($.includes("has no route handlers"))_.add("Add at least one HTTP method decorator such as @Get() or @Post() in the controller.");if($.includes("not decorated with @Service()"))_.add("Add @Service() to injectable classes used in constructor dependencies.");if($.includes("constructor metadata is missing")||$.includes("reflect-metadata"))_.add("Import 'reflect-metadata' in your entry file and enable 'emitDecoratorMetadata' in tsconfig.");if($.includes("Strict mode: no routes were registered"))_.add("Disable strict.requireRoutes for empty modules, or add a controller with at least one route.");if($.includes("Plugin ordering error")||$.includes("Plugin capability error"))_.add("Check plugin order and before/after constraints, then ensure required capabilities are provided earlier.");return[..._]}async register($){let _=await this.componentManager.registerModule($),W=this.shouldEmitRouteDiagnostics();for(let Q of _){let X=Date.now(),Z=this.routeRegistry.getRoutes().length;try{if(await this.routeManager.registerController(Q),W)this.logger.emit({level:"info",category:"routes",message:"Registered controller routes",details:{controller:Q.name,routeCountAdded:this.routeRegistry.getRoutes().length-Z,registrationDurationMs:Date.now()-X}})}catch(U){if(W)this.logger.emit({level:"error",category:"routes",message:"Failed to register controller routes",details:{controller:Q.name,registrationDurationMs:Date.now()-X,errorMessage:U instanceof Error?U.message:String(U)}});throw U}}return this}static async create($,_={}){let W=Date.now(),Q=C.fromRootModule($),X=new S(_,Q),Z=(_.plugins||[]).map((j,V)=>X.normalizePluginEntry(j,V)),U=X.resolvePluginExecutionOrder(Z);X.validatePluginCapabilities(U);let J=X.getContext(),Y=_.debug,B=Y===!0||typeof Y==="object"&&Y.plugins,G=Y===!0||typeof Y==="object"&&Y.routes,L=Y===!0||typeof Y==="object"&&(Y.startup||G),A=!1;try{if(B&&U.length>0)X.logger.emit({level:"info",category:"plugins",message:`Plugin order: ${U.map(({name:V})=>V).join(" -> ")}`});for(let{plugin:V,preProcessors:H}of U){V.logger=X.logger;for(let k of H)await k(X,X.hono,J);if(V.beforeModulesRegistered)await V.beforeModulesRegistered(X,X.hono)}await X.register($);let j=X.getRoutes();if(L)X.logger.emit({level:"info",category:"startup",message:`Application registered ${j.length} route(s)`,details:{routeCount:j.length,rootModule:$.name}});if(_.strict?.requireRoutes&&j.length===0){A=!0,X.logger.emit({level:"error",category:"startup",message:"Strict mode failed: no routes were registered",details:{rootModule:$.name,requireRoutes:!0,startupDurationMs:Date.now()-W}});let V=Error("Strict mode: no routes were registered. Check your module/controller decorators.");throw X.emitStartupGuide(V,$),V}if(G)X.logger.emit({level:"info",category:"routes",message:"Registered routes",details:{routes:j.map((V)=>`${V.method.toUpperCase()} ${V.fullPath}`)}});for(let{plugin:V,postProcessors:H}of U){if(V.afterModulesRegistered)await V.afterModulesRegistered(X,X.hono);for(let k of H)await k(X,X.hono,J)}if(L)X.logger.emit({level:"info",category:"startup",message:"Application startup completed",details:{rootModule:$.name,pluginCount:U.length,routeCount:j.length,startupDurationMs:Date.now()-W}});return{app:X,hono:X.getApp()}}catch(j){if(X.emitStartupGuide(j,$),L&&!A)X.logger.emit({level:"error",category:"startup",message:"Application startup failed",details:{rootModule:$.name,startupDurationMs:Date.now()-W,errorMessage:j instanceof Error?j.message:String(j)}});throw j}}getApp(){return this.hono}getContainer(){return this.container}getContext(){return this.context}getRoutes(){return this.routeRegistry.getRoutes()}}import{html as F,raw as e}from"hono/html";var q$={type:"website",locale:"en_US"},$$=($)=>{if(!$)return"";return Object.entries($).map(([_,W])=>{if(typeof W==="boolean")return W?_:"";let Q=String(W).replace(/"/g,""");return`${_}="${Q}"`}).filter(Boolean).join(" ")},r_=($)=>{let _={...q$,...$};return F`
|
|
2
2
|
<!DOCTYPE html>
|
|
3
3
|
<html lang="${_.locale?.split("_")[0]||"en"}" ${e($$(_.htmlAttributes))}>
|
|
4
4
|
<head ${e($$(_.headAttributes))}>
|
|
5
5
|
<meta charset="UTF-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
${_.csp?
|
|
7
|
+
${_.csp?F`<meta http-equiv="Content-Security-Policy" content="${_.csp}" />`:""}
|
|
8
8
|
<title>${_.title}</title>
|
|
9
|
-
${_.description?
|
|
9
|
+
${_.description?F`<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?
|
|
15
|
-
${_.image?
|
|
16
|
-
${_.url?
|
|
17
|
-
${_.locale?
|
|
18
|
-
${_.type?
|
|
19
|
-
${_.siteName?
|
|
14
|
+
${_.description?F`<meta property="og:description" content="${_.description}" />`:""}
|
|
15
|
+
${_.image?F`<meta property="og:image" content="${_.image}" />`:""}
|
|
16
|
+
${_.url?F`<meta property="og:url" content="${_.url}" />`:""}
|
|
17
|
+
${_.locale?F`<meta property="og:locale" content="${_.locale}" />`:""}
|
|
18
|
+
${_.type?F`<meta property="og:type" content="${_.type}" />`:""}
|
|
19
|
+
${_.siteName?F`<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 B$}from"hono";class h{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?
|
|
28
|
-
${_.image?
|
|
27
|
+
${_.description?F`<meta name="twitter:description" content="${_.description}" />`:""}
|
|
28
|
+
${_.image?F`<meta name="twitter:image" content="${_.image}" />`:""}
|
|
29
29
|
|
|
30
30
|
<!-- Custom Meta Tags -->
|
|
31
|
-
${_.customMeta?_.customMeta.map((W)=>{let Q=W.name?`name="${W.name}"`:"",X=W.property?`property="${W.property}"`:"";return
|
|
31
|
+
${_.customMeta?_.customMeta.map((W)=>{let Q=W.name?`name="${W.name}"`:"",X=W.property?`property="${W.property}"`:"";return F`<meta ${Q} ${X} content="${W.content}" />`}):""}
|
|
32
32
|
|
|
33
33
|
<!-- Favicon -->
|
|
34
|
-
${_.favicon?
|
|
34
|
+
${_.favicon?F`<link rel="icon" href="${_.favicon}" />`:""}
|
|
35
35
|
|
|
36
36
|
<!-- Stylesheets -->
|
|
37
|
-
${_.stylesheets?_.stylesheets.map((W)=>
|
|
37
|
+
${_.stylesheets?_.stylesheets.map((W)=>F`<link rel="stylesheet" href="${W}" />`):""}
|
|
38
38
|
|
|
39
39
|
<!-- Scripts -->
|
|
40
|
-
${_.scripts?_.scripts.map((W)=>{if(typeof W==="string")return
|
|
40
|
+
${_.scripts?_.scripts.map((W)=>{if(typeof W==="string")return F`<script src="${W}"></script>`;let{src:Q,async:X,defer:Z}=W;if(X&&Z)return F`<script src="${Q}" async defer></script>`;if(X)return F`<script src="${Q}" async></script>`;if(Z)return F`<script src="${Q}" defer></script>`;return F`<script src="${Q}"></script>`}):""}
|
|
41
41
|
</head>
|
|
42
42
|
<body ${e($$(_.bodyAttributes))}>
|
|
43
43
|
${_.children}
|
|
44
44
|
</body>
|
|
45
45
|
</html>
|
|
46
|
-
`};function Q$($="",_={}){return(W)=>{
|
|
46
|
+
`};function Q$($="",_={}){return(W)=>{q.setControllerPath(W,$),q.setControllerOptions(W,_)}}var X$=T("get"),XW=T("post"),ZW=T("put"),JW=T("delete"),UW=T("patch"),YW=T("options"),BW=T("all");function x($={}){return(_)=>{q.setModuleOptions(_,$)}}function zW($="",_={prefix:null,version:null}){return Q$($,_)}var AW=X$;function kW($={}){return x({imports:$.imports,services:$.services,controllers:($.views||[]).concat($.controllers||[])})}var TW=z("body",async($,_)=>{let W=_.get(l);if(W===void 0)W=await _.req.json(),_.set(l,W);if($&&W&&typeof W==="object")return W[String($)];return W}),KW=z("param",($,_)=>{return $?_.req.param(String($)):_.req.param()}),NW=z("query",($,_)=>{return $?_.req.query(String($)):_.req.query()}),PW=z("header",($,_)=>{return $?_.req.header(String($)):_.req.header()}),wW=z("request",($,_)=>_.req),SW=z("request",($,_)=>_.req),EW=z("response",($,_)=>_.res),RW=z("response",($,_)=>_.res),bW=z("context",($,_)=>_),CW=z("context",($,_)=>_),IW=z("variable",($,_)=>$===void 0?void 0:_.get(String($))),MW=z("variable",($,_)=>$===void 0?void 0:_.get(String($)));function vW(){return($)=>{q.addService($)}}function gW($,..._){return(W,Q)=>{if(Q){let Z=`${W.constructor.name}:${String(Q)}`;_.forEach((U)=>q.registerHandler($,Z,U))}else _.forEach((X)=>q.registerController($,W,X))}}function dW(...$){return(_,W)=>{if(W){let X=`${_.constructor.name}:${String(W)}`;$.forEach((Z)=>q.registerHandler("filter",X,Z))}else $.forEach((Q)=>q.registerController("filter",_,Q))}}function iW(...$){return(_,W)=>{if(W){let X=`${_.constructor.name}:${String(W)}`;$.forEach((Z)=>q.registerHandler("guard",X,Z))}else $.forEach((Q)=>q.registerController("guard",_,Q))}}function nW(...$){return(_,W)=>{if(W){let X=`${_.constructor.name}:${String(W)}`;$.forEach((Z)=>q.registerHandler("middleware",X,Z))}else $.forEach((Q)=>q.registerController("middleware",_,Q))}}function rW(...$){return(_,W)=>{if(W){let X=`${_.constructor.name}:${String(W)}`;$.forEach((Z)=>q.registerHandler("pipe",X,Z))}else $.forEach((Q)=>q.registerController("pipe",_,Q))}}function Z$($={}){let{controllers:_,services:W,imports:Q,name:X="TestModule"}=$,Z={[X]:class{}}[X];return x({controllers:_,services:W,imports:Q})(Z),Z}async function J$($={}){let{module:_,appOptions:W,...Q}=$,X=_??Z$(Q),{app:Z,hono:U}=await S.create(X,W);return{app:Z,hono:U,request:(Y,B)=>{if(typeof Y==="string"){let G=Y.startsWith("http://")||Y.startsWith("https://")?Y:`http://localhost${Y.startsWith("/")?Y:`/${Y}`}`;return Promise.resolve(U.request(G,B))}return Promise.resolve(U.request(Y))}}}async function g8($){let{controller:_,...W}=$;return J$({...W,controllers:[_]})}function c8($={}){let _=$.logger??new D,W=new E(void 0,_,Boolean($.debugDi));for(let Q of $.overrides??[]){let X=Q;W.register(X.provide,X.useValue)}for(let Q of $.preload??[])W.resolve(Q);return{container:W,get(Q){return W.resolve(Q)},register(Q,X){W.register(Q,X)},has(Q){return W.has(Q)},clear(){W.clear()}}}export{q_ as stripEndSlash,s as normalizePath,X_ as isUndefined,Y_ as isSymbol,f as isString,Z_ as isPlainObject,K as isObject,J_ as isNumber,w as isNil,_$ as isFunction,U_ as isEmpty,W$ as isConstructor,Z$ as createTestingModule,J$ as createTestApplication,c8 as createServiceTestContainer,z as createParamDecorator,T as createHttpMethodDecorator,R as createErrorResponse,g8 as createControllerTestApplication,B_ as addLeadingSlash,zW as View,MW as Variable,IW as Var,i as VERSION_NEUTRAL,rW as UsePipes,nW as UseMiddleware,iW as UseGuards,dW as UseFilters,gW as UseComponent,u as StaticServiceRegistry,O as StaticMetadataRepository,C as SnapshotMetadataRepository,vW as Service,m as RouteRegistry,RW as Response,EW as Res,SW as Request,wW as Req,NW as Query,ZW as Put,XW as Post,UW as Patch,KW as Param,AW as Page,YW as Options,p as NotFoundHandler,D as NoopLogger,kW as MvcModule,x as Module,q as MetadataRegistry,r_ as Layout,PW as Header,M as HONEST_PIPELINE_HANDLER_KEY,I as HONEST_PIPELINE_CONTROLLER_KEY,l as HONEST_PIPELINE_BODY_CACHE_KEY,X$ as Get,d as FrameworkError,c as ErrorHandler,JW as Delete,bW as Ctx,Q$ as Controller,CW as Context,E as Container,g as ConsoleLogger,TW as Body,h as ApplicationContext,S as Application,BW as All};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
import type { VERSION_NEUTRAL } from '../constants';
|
|
3
|
-
import type { FilterType, GuardType,
|
|
3
|
+
import type { FilterType, GuardType, ILogger, MiddlewareType, PipeType, PluginEntry } from '../interfaces';
|
|
4
4
|
import type { DiContainer } from './di-container.interface';
|
|
5
5
|
/**
|
|
6
6
|
* Options for configuring the Honest application
|
|
@@ -27,9 +27,9 @@ export interface HonestOptions {
|
|
|
27
27
|
startup?: boolean;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* Optional
|
|
30
|
+
* Optional logger for structured framework events.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
logger?: ILogger;
|
|
33
33
|
/**
|
|
34
34
|
* Optional strict-mode checks for startup validation.
|
|
35
35
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './application-context.interface';
|
|
2
2
|
export * from './controller-options.interface';
|
|
3
3
|
export * from './di-container.interface';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './logger.interface';
|
|
5
5
|
export * from './error-response.interface';
|
|
6
6
|
export * from './filter.interface';
|
|
7
7
|
export * from './guard.interface';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
+
/**
|
|
6
|
+
* Log category used to filter or route events.
|
|
7
|
+
*/
|
|
8
|
+
export type LogCategory = 'startup' | 'routes' | 'plugins' | 'deprecations' | 'pipeline' | 'di' | 'errors';
|
|
9
|
+
/**
|
|
10
|
+
* Structured log event emitted by Honest runtime components.
|
|
11
|
+
*/
|
|
12
|
+
export interface LogEvent {
|
|
13
|
+
level: LogLevel;
|
|
14
|
+
category: LogCategory;
|
|
15
|
+
message: string;
|
|
16
|
+
details?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Logger contract.
|
|
20
|
+
*/
|
|
21
|
+
export interface ILogger {
|
|
22
|
+
emit(event: LogEvent): void;
|
|
23
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import type { Application } from '../application';
|
|
3
3
|
import type { IApplicationContext } from './application-context.interface';
|
|
4
|
+
import type { ILogger } from './logger.interface';
|
|
4
5
|
import type { Constructor } from '../types';
|
|
5
6
|
/**
|
|
6
7
|
* Processor callback for plugin pre/post hooks.
|
|
@@ -57,19 +58,22 @@ export interface IPlugin {
|
|
|
57
58
|
*/
|
|
58
59
|
meta?: PluginMeta;
|
|
59
60
|
/**
|
|
60
|
-
*
|
|
61
|
-
* Use this to
|
|
61
|
+
* Application logger, injected by the framework before lifecycle hooks run.
|
|
62
|
+
* Use this to emit structured log events from within plugin code.
|
|
63
|
+
*/
|
|
64
|
+
logger?: ILogger;
|
|
65
|
+
/**
|
|
66
|
+
* Hook that runs before module registration begins.
|
|
67
|
+
* Use this to set up plugin functionality that modules might depend on.
|
|
62
68
|
* @param app - The Honest application instance
|
|
63
69
|
* @param hono - The underlying Hono application instance
|
|
64
|
-
* @returns Void or a Promise that resolves to void
|
|
65
70
|
*/
|
|
66
71
|
beforeModulesRegistered?: (app: Application, hono: Hono) => void | Promise<void>;
|
|
67
72
|
/**
|
|
68
|
-
* Hook that runs after all modules have been registered
|
|
69
|
-
* Use this to perform cleanup or setup that requires all modules to be ready
|
|
73
|
+
* Hook that runs after all modules have been registered.
|
|
74
|
+
* Use this to perform cleanup or setup that requires all modules to be ready.
|
|
70
75
|
* @param app - The Honest application instance
|
|
71
76
|
* @param hono - The underlying Hono application instance
|
|
72
|
-
* @returns Void or a Promise that resolves to void
|
|
73
77
|
*/
|
|
74
78
|
afterModulesRegistered?: (app: Application, hono: Hono) => void | Promise<void>;
|
|
75
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context, Next } from 'hono';
|
|
2
|
-
import type { ArgumentMetadata, DiContainer, FilterType, GuardType,
|
|
2
|
+
import type { ArgumentMetadata, DiContainer, FilterType, GuardType, ILogger, IMetadataRepository, IGuard, IPipe, MiddlewareType, PipeType } from '../interfaces';
|
|
3
3
|
import { type ComponentType, type ComponentTypeMap } from '../registries';
|
|
4
4
|
import type { Constructor } from '../types';
|
|
5
5
|
/**
|
|
@@ -13,9 +13,9 @@ import type { Constructor } from '../types';
|
|
|
13
13
|
export declare class ComponentManager {
|
|
14
14
|
private readonly container;
|
|
15
15
|
private readonly metadataRepository;
|
|
16
|
-
private readonly
|
|
16
|
+
private readonly logger;
|
|
17
17
|
private readonly globalComponents;
|
|
18
|
-
constructor(container: DiContainer, metadataRepository?: IMetadataRepository,
|
|
18
|
+
constructor(container: DiContainer, metadataRepository?: IMetadataRepository, logger?: ILogger);
|
|
19
19
|
/**
|
|
20
20
|
* Configures global components from application options.
|
|
21
21
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ILogger, ParameterMetadata } from '../interfaces';
|
|
3
3
|
import type { IPipe } from '../interfaces';
|
|
4
4
|
import { ComponentManager } from './component.manager';
|
|
5
5
|
import { HandlerInvoker } from './handler.invoker';
|
|
@@ -21,8 +21,8 @@ export declare class PipelineExecutor {
|
|
|
21
21
|
private readonly componentManager;
|
|
22
22
|
private readonly parameterResolver;
|
|
23
23
|
private readonly handlerInvoker;
|
|
24
|
-
private readonly
|
|
24
|
+
private readonly logger;
|
|
25
25
|
private readonly debugPipeline;
|
|
26
|
-
constructor(componentManager: ComponentManager, parameterResolver: ParameterResolver, handlerInvoker: HandlerInvoker,
|
|
26
|
+
constructor(componentManager: ComponentManager, parameterResolver: ParameterResolver, handlerInvoker: HandlerInvoker, logger?: ILogger, debugPipeline?: boolean);
|
|
27
27
|
execute(input: PipelineExecutionInput): Promise<unknown>;
|
|
28
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import { VERSION_NEUTRAL } from '../constants';
|
|
3
|
-
import type { DiContainer,
|
|
3
|
+
import type { DiContainer, ILogger, IMetadataRepository } from '../interfaces';
|
|
4
4
|
import { ComponentManager } from './component.manager';
|
|
5
5
|
import { RouteRegistry } from '../registries/route.registry';
|
|
6
6
|
import type { Constructor } from '../types';
|
|
@@ -18,10 +18,10 @@ export declare class RouteManager {
|
|
|
18
18
|
private parameterResolver;
|
|
19
19
|
private pipelineExecutor;
|
|
20
20
|
private metadataRepository;
|
|
21
|
-
private
|
|
21
|
+
private logger;
|
|
22
22
|
private globalPrefix?;
|
|
23
23
|
private globalVersion?;
|
|
24
|
-
constructor(hono: Hono, container: DiContainer, routeRegistry: RouteRegistry, componentManager: ComponentManager, metadataRepository?: IMetadataRepository,
|
|
24
|
+
constructor(hono: Hono, container: DiContainer, routeRegistry: RouteRegistry, componentManager: ComponentManager, metadataRepository?: IMetadataRepository, logger?: ILogger, options?: {
|
|
25
25
|
prefix?: string;
|
|
26
26
|
version?: number | typeof VERSION_NEUTRAL | number[];
|
|
27
27
|
debugPipeline?: boolean;
|
|
@@ -148,9 +148,15 @@ export declare class MetadataRegistry {
|
|
|
148
148
|
* Get all handler-level components of a specific type for a handler
|
|
149
149
|
*/
|
|
150
150
|
static getHandler<T extends ComponentType>(type: T, handlerKey: string): ComponentTypeMap[T][];
|
|
151
|
+
/**
|
|
152
|
+
* Clears handler-level component registrations created via {@link registerHandler}.
|
|
153
|
+
* Does not remove decorator-defined routes, controllers, or modules.
|
|
154
|
+
*/
|
|
155
|
+
static clearHandlerComponents(): void;
|
|
151
156
|
/**
|
|
152
157
|
* Clears all registered decorator metadata.
|
|
153
|
-
* Primarily used for testing.
|
|
158
|
+
* Primarily used for testing. Warning: clearing after importing decorated classes
|
|
159
|
+
* (e.g. shared fixtures) removes their metadata until those modules are re-evaluated.
|
|
154
160
|
*/
|
|
155
161
|
static clear(): void;
|
|
156
162
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Constructor } from '../../types';
|
|
2
|
+
export declare function createTestController(): Constructor;
|
|
3
|
+
export declare function createPayloadController(): Constructor;
|
|
4
|
+
export declare function createRawResponseController(): Constructor;
|
|
5
|
+
export declare function createOnlyAController(): Constructor;
|
|
6
|
+
export declare function createOnlyBController(): Constructor;
|
|
7
|
+
export declare function createUndecoratedController(): Constructor;
|
|
8
|
+
export declare function createBrokenControllerModule(): Constructor;
|
|
9
|
+
export declare function createEmptyModule(): Constructor;
|
|
10
|
+
export declare function createDuplicateRouteControllers(): {
|
|
11
|
+
a: Constructor;
|
|
12
|
+
b: Constructor;
|
|
13
|
+
};
|
|
14
|
+
export declare function createUnsafeParamController(): Constructor;
|
|
15
|
+
export declare function createDiagnosticsAController(): Constructor;
|
|
16
|
+
export declare function createDiagnosticsBController(): Constructor;
|
|
17
|
+
export declare function createRuntimeMetadataController(): Constructor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import type { Application } from '../application';
|
|
3
|
-
import type { DiContainer, HonestOptions,
|
|
3
|
+
import type { DiContainer, HonestOptions, ILogger, ModuleOptions } from '../interfaces';
|
|
4
4
|
import type { Constructor } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Options for creating a lightweight test module.
|
|
@@ -76,9 +76,9 @@ export interface CreateServiceTestContainerOptions {
|
|
|
76
76
|
*/
|
|
77
77
|
preload?: Constructor[];
|
|
78
78
|
/**
|
|
79
|
-
* Optional
|
|
79
|
+
* Optional logger used when debugDi is enabled.
|
|
80
80
|
*/
|
|
81
|
-
|
|
81
|
+
logger?: ILogger;
|
|
82
82
|
/**
|
|
83
83
|
* Enable DI diagnostics while resolving services.
|
|
84
84
|
*/
|
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.
|
|
4
|
+
"version": "0.1.19",
|
|
5
5
|
"author": "Orkhan Karimov <karimovok1@gmail.com> (https://github.com/kerimovok)",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"prepare": "husky",
|
|
54
54
|
"test": "bun test",
|
|
55
55
|
"test:watch": "bun test --watch",
|
|
56
|
+
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov",
|
|
56
57
|
"build": "bun run clean && bun build ./src/index.ts --outdir=dist --target=node --minify --external hono --external reflect-metadata && bun run build:types",
|
|
57
58
|
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
58
59
|
"lint": "eslint .",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Diagnostic log level.
|
|
3
|
-
*/
|
|
4
|
-
export type DiagnosticLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
-
/**
|
|
6
|
-
* Diagnostic category used to filter or route events.
|
|
7
|
-
*/
|
|
8
|
-
export type DiagnosticCategory = 'startup' | 'routes' | 'plugins' | 'deprecations' | 'pipeline' | 'di' | 'errors';
|
|
9
|
-
/**
|
|
10
|
-
* Structured diagnostic event emitted by Honest runtime components.
|
|
11
|
-
*/
|
|
12
|
-
export interface DiagnosticEvent {
|
|
13
|
-
level: DiagnosticLevel;
|
|
14
|
-
category: DiagnosticCategory;
|
|
15
|
-
message: string;
|
|
16
|
-
details?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Diagnostics emitter contract.
|
|
20
|
-
*/
|
|
21
|
-
export interface IDiagnosticsEmitter {
|
|
22
|
-
emit(event: DiagnosticEvent): void;
|
|
23
|
-
}
|
|
File without changes
|