veloce-ts 0.1.7 → 0.2.1
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/CHANGELOG.md +78 -1
- package/dist/cjs/src/errors/index.js +2 -2
- package/dist/cjs/src/errors/index.js.map +6 -5
- package/dist/cjs/src/graphql/index.js +6 -6
- package/dist/cjs/src/graphql/index.js.map +4 -4
- package/dist/cjs/src/index.js +24 -22
- package/dist/cjs/src/index.js.map +100 -13
- package/dist/cjs/src/plugins/index.js +7 -7
- package/dist/cjs/src/plugins/index.js.map +4 -4
- package/dist/cjs/src/testing/index.js +4 -4
- package/dist/cjs/src/testing/index.js.map +10 -9
- package/dist/cjs/src/validation/index.js +2 -2
- package/dist/cjs/src/validation/index.js.map +4 -4
- package/dist/esm/{chunk-0zxhx5b8.js → chunk-09p9prja.js} +1 -1
- package/dist/esm/chunk-3nhrrhv9.js +5 -0
- package/dist/esm/chunk-3nhrrhv9.js.map +10 -0
- package/dist/esm/{chunk-159eqj8q.js → chunk-3vd5qsws.js} +2 -2
- package/dist/esm/{chunk-159eqj8q.js.map → chunk-3vd5qsws.js.map} +1 -1
- package/dist/esm/{chunk-qfsjy9bg.js → chunk-4s66h6qw.js} +1 -1
- package/dist/esm/{chunk-awven6dt.js → chunk-9f0s1qbb.js} +2 -2
- package/dist/esm/{chunk-awven6dt.js.map → chunk-9f0s1qbb.js.map} +1 -1
- package/dist/esm/{chunk-82f2j0k2.js → chunk-dpjkne9h.js} +1 -1
- package/dist/esm/{chunk-42h6trpf.js → chunk-f64j5zbr.js} +2 -2
- package/dist/esm/{chunk-42h6trpf.js.map → chunk-f64j5zbr.js.map} +1 -1
- package/dist/esm/{chunk-658zaz9f.js → chunk-gdq186ew.js} +1 -1
- package/dist/esm/chunk-gy9nsvnk.js +6 -0
- package/dist/esm/chunk-gy9nsvnk.js.map +10 -0
- package/dist/esm/{chunk-gv5n8ddb.js → chunk-qg4ngg5j.js} +3 -3
- package/dist/esm/{chunk-gv5n8ddb.js.map → chunk-qg4ngg5j.js.map} +1 -1
- package/dist/esm/chunk-r8ssy5cv.js +5 -0
- package/dist/esm/{chunk-1hqjkm44.js.map → chunk-r8ssy5cv.js.map} +4 -5
- package/dist/esm/chunk-sv2c5krg.js +5 -0
- package/dist/esm/chunk-sv2c5krg.js.map +10 -0
- package/dist/esm/{chunk-9p6d0t33.js → chunk-vzhqg5mb.js} +3 -3
- package/dist/esm/{chunk-9p6d0t33.js.map → chunk-vzhqg5mb.js.map} +1 -1
- package/dist/esm/{chunk-pn7z890c.js → chunk-yyxd7dw5.js} +3 -3
- package/dist/esm/{chunk-pn7z890c.js.map → chunk-yyxd7dw5.js.map} +2 -2
- package/dist/esm/src/cli/index.js +3 -3
- package/dist/esm/src/cli/index.js.map +1 -1
- package/dist/esm/src/docs/index.js +3 -3
- package/dist/esm/src/docs/index.js.map +1 -1
- package/dist/esm/src/errors/index.js +2 -2
- package/dist/esm/src/errors/index.js.map +1 -1
- package/dist/esm/src/graphql/index.js +2 -2
- package/dist/esm/src/graphql/index.js.map +1 -1
- package/dist/esm/src/index.js +4 -2
- package/dist/esm/src/index.js.map +93 -7
- package/dist/esm/src/middleware/index.js +2 -2
- package/dist/esm/src/middleware/index.js.map +1 -1
- package/dist/esm/src/plugins/index.js +2 -2
- package/dist/esm/src/plugins/index.js.map +2 -2
- package/dist/esm/src/testing/index.js +2 -2
- package/dist/esm/src/testing/index.js.map +6 -6
- package/dist/esm/src/types/index.js +2 -2
- package/dist/esm/src/types/index.js.map +1 -1
- package/dist/esm/src/validation/index.js +2 -2
- package/dist/esm/src/validation/index.js.map +1 -1
- package/dist/esm/src/websocket/index.js +1 -1
- package/dist/types/auth/auth-plugin.d.ts +29 -0
- package/dist/types/auth/auth-plugin.d.ts.map +1 -0
- package/dist/types/auth/auth-service.d.ts +84 -0
- package/dist/types/auth/auth-service.d.ts.map +1 -0
- package/dist/types/auth/decorators.d.ts +36 -0
- package/dist/types/auth/decorators.d.ts.map +1 -0
- package/dist/types/auth/exceptions.d.ts +27 -0
- package/dist/types/auth/exceptions.d.ts.map +1 -0
- package/dist/types/auth/index.d.ts +29 -0
- package/dist/types/auth/index.d.ts.map +1 -0
- package/dist/types/auth/jwt-provider.d.ts +98 -0
- package/dist/types/auth/jwt-provider.d.ts.map +1 -0
- package/dist/types/auth/oauth-decorators.d.ts +31 -0
- package/dist/types/auth/oauth-decorators.d.ts.map +1 -0
- package/dist/types/auth/oauth-plugin.d.ts +34 -0
- package/dist/types/auth/oauth-plugin.d.ts.map +1 -0
- package/dist/types/auth/oauth-provider.d.ts +135 -0
- package/dist/types/auth/oauth-provider.d.ts.map +1 -0
- package/dist/types/auth/permission-decorators.d.ts +92 -0
- package/dist/types/auth/permission-decorators.d.ts.map +1 -0
- package/dist/types/auth/permission-plugin.d.ts +31 -0
- package/dist/types/auth/permission-plugin.d.ts.map +1 -0
- package/dist/types/auth/permissions.d.ts +225 -0
- package/dist/types/auth/permissions.d.ts.map +1 -0
- package/dist/types/auth/rbac-decorators.d.ts +63 -0
- package/dist/types/auth/rbac-decorators.d.ts.map +1 -0
- package/dist/types/auth/rbac-plugin.d.ts +31 -0
- package/dist/types/auth/rbac-plugin.d.ts.map +1 -0
- package/dist/types/auth/rbac.d.ts +145 -0
- package/dist/types/auth/rbac.d.ts.map +1 -0
- package/dist/types/auth/session-decorators.d.ts +75 -0
- package/dist/types/auth/session-decorators.d.ts.map +1 -0
- package/dist/types/auth/session-plugin.d.ts +40 -0
- package/dist/types/auth/session-plugin.d.ts.map +1 -0
- package/dist/types/auth/session.d.ts +235 -0
- package/dist/types/auth/session.d.ts.map +1 -0
- package/dist/types/core/application.d.ts +5 -0
- package/dist/types/core/application.d.ts.map +1 -1
- package/dist/types/core/compiled-metadata.d.ts +1 -0
- package/dist/types/core/compiled-metadata.d.ts.map +1 -1
- package/dist/types/core/metadata.d.ts +97 -1
- package/dist/types/core/metadata.d.ts.map +1 -1
- package/dist/types/core/router-compiler.d.ts +11 -1
- package/dist/types/core/router-compiler.d.ts.map +1 -1
- package/dist/types/decorators/http.d.ts +13 -1
- package/dist/types/decorators/http.d.ts.map +1 -1
- package/dist/types/decorators/middleware.d.ts.map +1 -1
- package/dist/types/errors/handler.d.ts.map +1 -1
- package/dist/types/graphql/index.d.ts +1 -0
- package/dist/types/graphql/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +71 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +24 -4
- package/dist/esm/chunk-1hqjkm44.js +0 -5
- package/dist/esm/chunk-2q6s8v3j.js +0 -6
- package/dist/esm/chunk-2q6s8v3j.js.map +0 -10
- /package/dist/esm/{chunk-0zxhx5b8.js.map → chunk-09p9prja.js.map} +0 -0
- /package/dist/esm/{chunk-qfsjy9bg.js.map → chunk-4s66h6qw.js.map} +0 -0
- /package/dist/esm/{chunk-82f2j0k2.js.map → chunk-dpjkne9h.js.map} +0 -0
- /package/dist/esm/{chunk-658zaz9f.js.map → chunk-gdq186ew.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,79 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.1] - 2025-10-14
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **GraphQL Exports**: Fixed missing `Arg` decorator export from GraphQL module
|
|
14
|
+
- **Import Resolution**: GraphQL decorators now properly exported from `veloce-ts/graphql`
|
|
15
|
+
- **Type Definitions**: GraphQL decorators included in TypeScript declarations
|
|
16
|
+
|
|
17
|
+
## [0.2.0] - 2025-10-14
|
|
18
|
+
|
|
19
|
+
### 🚀 Major Features Added
|
|
20
|
+
- **Complete Authentication System**: JWT-based authentication with access/refresh tokens
|
|
21
|
+
- **Role-Based Access Control (RBAC)**: Hierarchical roles with granular permissions system
|
|
22
|
+
- **SQLite Integration**: Built-in SQLite support with Bun's native database
|
|
23
|
+
- **Real-time WebSocket Support**: Enhanced WebSocket handling with decorators
|
|
24
|
+
- **GraphQL Integration**: Complete GraphQL support with resolvers and subscriptions
|
|
25
|
+
- **Advanced Middleware System**: Custom middleware with request/response interceptors
|
|
26
|
+
- **Admin Panel Features**: Comprehensive admin endpoints for user and system management
|
|
27
|
+
|
|
28
|
+
### 🎯 New Decorators & Features
|
|
29
|
+
- **@Auth**: JWT authentication decorator with automatic user injection
|
|
30
|
+
- **@CurrentUser**: Inject current authenticated user into handlers
|
|
31
|
+
- **@MinimumRole**: Role-based endpoint protection
|
|
32
|
+
- **@Permissions**: Granular permission-based access control
|
|
33
|
+
- **@WebSocket**: Enhanced WebSocket decorators with connection management
|
|
34
|
+
- **@Resolver**: GraphQL resolver decorators for queries and mutations
|
|
35
|
+
- **@OnConnect/@OnMessage/@OnDisconnect**: WebSocket lifecycle decorators
|
|
36
|
+
|
|
37
|
+
### 🔧 Core Framework Improvements
|
|
38
|
+
- **Router Compiler Fixes**: Fixed critical bugs with sparse array handling in metadata
|
|
39
|
+
- **Dependency Injection**: Enhanced DI system with better error handling
|
|
40
|
+
- **Parameter Resolution**: Improved parameter and dependency resolution
|
|
41
|
+
- **Type Safety**: Enhanced TypeScript inference and type checking
|
|
42
|
+
- **Error Handling**: Better error messages and debugging capabilities
|
|
43
|
+
|
|
44
|
+
### 📚 Documentation & Examples
|
|
45
|
+
- **Veloce TaskMaster**: Complete real-world example with authentication, RBAC, and frontend
|
|
46
|
+
- **Comprehensive Examples**: Task management system showcasing all framework features
|
|
47
|
+
- **Migration Guides**: Documentation for migrating from Express.js and other frameworks
|
|
48
|
+
- **API Documentation**: Enhanced OpenAPI/Swagger documentation generation
|
|
49
|
+
|
|
50
|
+
### 🛠️ Technical Improvements
|
|
51
|
+
- **Performance**: Optimized router compilation and metadata handling
|
|
52
|
+
- **Memory Management**: Better handling of metadata arrays and object references
|
|
53
|
+
- **Bundle Size**: Reduced framework bundle size through optimizations
|
|
54
|
+
- **Build System**: Improved TypeScript compilation and type generation
|
|
55
|
+
- **Testing**: Enhanced testing utilities and error reporting
|
|
56
|
+
|
|
57
|
+
### 🔒 Security Enhancements
|
|
58
|
+
- **JWT Security**: Secure token generation and validation
|
|
59
|
+
- **Password Hashing**: Built-in password hashing utilities
|
|
60
|
+
- **CSRF Protection**: Enhanced CORS and security middleware
|
|
61
|
+
- **Input Validation**: Improved Zod schema validation
|
|
62
|
+
- **Role Hierarchy**: Configurable role hierarchy with permission inheritance
|
|
63
|
+
|
|
64
|
+
### 🎨 Developer Experience
|
|
65
|
+
- **Better Error Messages**: More descriptive error messages with stack traces
|
|
66
|
+
- **Hot Reload**: Improved development server with better file watching
|
|
67
|
+
- **TypeScript Support**: Enhanced type inference and IntelliSense
|
|
68
|
+
- **Debugging**: Better debugging capabilities with request tracing
|
|
69
|
+
- **CLI Improvements**: Enhanced CLI with better project scaffolding
|
|
70
|
+
|
|
71
|
+
### 🐛 Critical Bug Fixes
|
|
72
|
+
- **Router Compilation**: Fixed sparse array handling in parameter metadata
|
|
73
|
+
- **Dependency Resolution**: Fixed undefined dependency handling
|
|
74
|
+
- **Array Length Errors**: Fixed array creation with invalid indices
|
|
75
|
+
- **Import Path Issues**: Corrected all import paths in generated projects
|
|
76
|
+
- **Metadata Processing**: Fixed metadata compilation edge cases
|
|
77
|
+
|
|
78
|
+
### 📦 New Dependencies
|
|
79
|
+
- **jsonwebtoken**: JWT token generation and validation
|
|
80
|
+
- **reflect-metadata**: Enhanced reflection capabilities for decorators
|
|
81
|
+
- **zod-to-json-schema**: Improved OpenAPI schema generation
|
|
82
|
+
|
|
10
83
|
## [0.1.7] - 2025-10-12
|
|
11
84
|
|
|
12
85
|
### Fixed
|
|
@@ -99,7 +172,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
99
172
|
- CLI tooling
|
|
100
173
|
- Testing utilities
|
|
101
174
|
|
|
102
|
-
[Unreleased]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1
|
|
175
|
+
[Unreleased]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.2.1...HEAD
|
|
176
|
+
[0.2.1]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.2.0...v0.2.1
|
|
177
|
+
[0.2.0]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.7...v0.2.0
|
|
178
|
+
[0.1.7]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.6...v0.1.7
|
|
179
|
+
[0.1.6]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.5...v0.1.6
|
|
103
180
|
[0.1.5]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.4...v0.1.5
|
|
104
181
|
[0.1.4]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.3...v0.1.4
|
|
105
182
|
[0.1.3]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.2...v0.1.3
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _=Object.create;var{getPrototypeOf:$,defineProperty:B,getOwnPropertyNames:Y,getOwnPropertyDescriptor:b}=Object,Z=Object.prototype.hasOwnProperty;var W=(F,U,k)=>{k=F!=null?_($(F)):{};let z=U||!F||!F.__esModule?B(k,"default",{value:F,enumerable:!0}):k;for(let I of Y(F))if(!Z.call(z,I))B(z,I,{get:()=>F[I],enumerable:!0});return z},X=new WeakMap,q=(F)=>{var U=X.get(F),k;if(U)return U;if(U=B({},"__esModule",{value:!0}),F&&typeof F==="object"||typeof F==="function")Y(F).map((z)=>!Z.call(U,z)&&B(U,z,{get:()=>F[z],enumerable:!(k=b(F,z))||k.enumerable}));return X.set(F,U),U},y=(F,U)=>()=>(U||F((U={exports:{}}).exports,U),U.exports);var C=(F,U)=>{for(var k in U)B(F,k,{get:U[k],enumerable:!0,configurable:!0,set:(z)=>U[k]=()=>z})};var J=(F,U)=>()=>(F&&(U=F(F=0)),U);var A,K,L,M,N;var G=J(()=>{A=class A extends Error{statusCode;details;constructor(F,U,k){super(U);this.statusCode=F;this.details=k;if(this.name="HTTPException",Error.captureStackTrace)Error.captureStackTrace(this,this.constructor)}toJSON(){return{error:this.message,statusCode:this.statusCode,...this.details&&{details:this.details}}}};K=class K extends A{constructor(F="Not Found",U){super(404,F,U);this.name="NotFoundException"}toJSON(){return{error:this.message,statusCode:this.statusCode,...this.details&&{details:this.details}}}};L=class L extends A{constructor(F="Unauthorized",U){super(401,F,U);this.name="UnauthorizedException"}toJSON(){return{error:this.message,statusCode:this.statusCode,...this.details&&{details:this.details}}}};M=class M extends A{constructor(F="Forbidden",U){super(403,F,U);this.name="ForbiddenException"}toJSON(){return{error:this.message,statusCode:this.statusCode,...this.details&&{details:this.details}}}};N=class N extends A{constructor(F="Bad Request",U){super(400,F,U);this.name="BadRequestException"}toJSON(){return{error:this.message,statusCode:this.statusCode,...this.details&&{details:this.details}}}}});G();var V={};C(V,{UnauthorizedException:()=>L,NotFoundException:()=>K,HTTPException:()=>A,ForbiddenException:()=>M,ErrorHandler:()=>R,BadRequestException:()=>N});module.exports=q(V);G();G();class Q extends A{zodError;constructor(F){super(422,"Validation failed");this.zodError=F;this.name="ValidationException"}toJSON(){return{error:"Validation Error",statusCode:this.statusCode,details:this.zodError.errors.map((F)=>({path:F.path.join("."),message:F.message,code:F.code}))}}}class R{customHandler;isDevelopment;constructor(F){this.customHandler=F,this.isDevelopment=!0}setCustomHandler(F){this.customHandler=F}async handle(F,U){if(console.log("ErrorHandler.handle called with:",F.constructor.name,F.message),this.customHandler)try{return await this.customHandler(F,U)}catch(k){console.error("Custom error handler failed:",k)}if(F instanceof Q)return console.log("Handling as ValidationException"),this.handleValidationException(F,U);if(F instanceof A)return console.log("Handling as HTTPException"),this.handleHTTPException(F,U);return console.log("Handling as generic error"),this.handleGenericError(F,U)}handleValidationException(F,U){let k=F.toJSON();if(this.isDevelopment)console.error("Validation Error:",{path:U.req.path,method:U.req.method,details:k.details});return U.json(k,F.statusCode)}handleHTTPException(F,U){let k=F.toJSON();if(F.statusCode>=500)console.error("HTTP Exception:",{name:F.name,statusCode:F.statusCode,message:F.message,path:U.req.path,method:U.req.method,...this.isDevelopment&&F.stack?{stack:F.stack}:{}});else if(this.isDevelopment)console.warn("HTTP Exception:",{name:F.name,statusCode:F.statusCode,message:F.message,path:U.req.path,method:U.req.method});return U.json(k,F.statusCode)}handleGenericError(F,U){console.error("Internal Server Error:",{name:F.name,message:F.message,path:U.req.path,method:U.req.method,stack:F.stack});let k={error:"Internal Server Error",statusCode:500};if(this.isDevelopment){if(k.message=F.message,k.name=F.name,F.stack)k.stack=F.stack.split(`
|
|
2
2
|
`).map((z)=>z.trim())}else k.message="An unexpected error occurred";return U.json(k,500)}isDevelopmentMode(){return this.isDevelopment}setDevelopmentMode(F){this.isDevelopment=F}}
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=8C0007C99DF044F464756E2164756E21
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["..\\..\\src\\errors\\exceptions.ts", "..\\..\\src\\
|
|
3
|
+
"sources": ["..\\..\\src\\errors\\exceptions.ts", "..\\..\\src\\errors\\index.ts", "..\\..\\src\\errors\\handler.ts", "..\\..\\src\\validation\\exceptions.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\r\n * Base HTTP exception class\r\n * All HTTP exceptions should extend this class\r\n * Provides consistent error response format\r\n */\r\nexport class HTTPException extends Error {\r\n constructor(\r\n public statusCode: number,\r\n message: string,\r\n public details?: any\r\n ) {\r\n super(message);\r\n this.name = 'HTTPException';\r\n \r\n // Maintains proper stack trace for where error was thrown (V8 only)\r\n if (Error.captureStackTrace) {\r\n Error.captureStackTrace(this, this.constructor);\r\n }\r\n }\r\n\r\n /**\r\n * Convert exception to JSON format for HTTP response\r\n * @returns Object with error details\r\n */\r\n toJSON() {\r\n return {\r\n error: this.message,\r\n statusCode: this.statusCode,\r\n ...(this.details && { details: this.details })\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 404 Not Found exception\r\n * Thrown when a requested resource cannot be found\r\n */\r\nexport class NotFoundException extends HTTPException {\r\n constructor(message: string = 'Not Found', details?: any) {\r\n super(404, message, details);\r\n this.name = 'NotFoundException';\r\n }\r\n\r\n toJSON() {\r\n return {\r\n error: this.message,\r\n statusCode: this.statusCode,\r\n ...(this.details && { details: this.details })\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 401 Unauthorized exception\r\n * Thrown when authentication is required but not provided or invalid\r\n */\r\nexport class UnauthorizedException extends HTTPException {\r\n constructor(message: string = 'Unauthorized', details?: any) {\r\n super(401, message, details);\r\n this.name = 'UnauthorizedException';\r\n }\r\n\r\n toJSON() {\r\n return {\r\n error: this.message,\r\n statusCode: this.statusCode,\r\n ...(this.details && { details: this.details })\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 403 Forbidden exception\r\n * Thrown when user is authenticated but doesn't have permission\r\n */\r\nexport class ForbiddenException extends HTTPException {\r\n constructor(message: string = 'Forbidden', details?: any) {\r\n super(403, message, details);\r\n this.name = 'ForbiddenException';\r\n }\r\n\r\n toJSON() {\r\n return {\r\n error: this.message,\r\n statusCode: this.statusCode,\r\n ...(this.details && { details: this.details })\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * 400 Bad Request exception\r\n * Thrown when the request is malformed or invalid\r\n */\r\nexport class BadRequestException extends HTTPException {\r\n constructor(message: string = 'Bad Request', details?: any) {\r\n super(400, message, details);\r\n this.name = 'BadRequestException';\r\n }\r\n\r\n toJSON() {\r\n return {\r\n error: this.message,\r\n statusCode: this.statusCode,\r\n ...(this.details && { details: this.details })\r\n };\r\n }\r\n}\r\n",
|
|
6
|
-
"
|
|
7
|
-
"import type { Context } from '../types';\r\nimport { HTTPException } from './exceptions.js';\r\nimport { ValidationException } from '../validation/exceptions.js';\r\n\r\n/**\r\n * Custom error handler function type\r\n * Allows users to provide their own error handling logic\r\n */\r\nexport type CustomErrorHandler = (error: Error, c: Context) => Response | Promise<Response>;\r\n\r\n/**\r\n * ErrorHandler processes all errors that occur during request handling\r\n * Provides consistent error responses and handles different error types appropriately\r\n */\r\nexport class ErrorHandler {\r\n private customHandler?: CustomErrorHandler;\r\n private isDevelopment: boolean;\r\n\r\n constructor(customHandler?: CustomErrorHandler) {\r\n this.customHandler = customHandler;\r\n this.isDevelopment = process.env.NODE_ENV !== 'production';\r\n }\r\n\r\n /**\r\n * Set a custom error handler\r\n * @param handler - Custom error handling function\r\n */\r\n setCustomHandler(handler: CustomErrorHandler): void {\r\n this.customHandler = handler;\r\n }\r\n\r\n /**\r\n * Main error handling method\r\n * Processes all error types and returns appropriate HTTP responses\r\n * @param error - The error that occurred\r\n * @param c - Hono context object\r\n * @returns HTTP response with error details\r\n */\r\n async handle(error: Error, c: Context): Promise<Response> {\r\n // If custom handler is provided, use it first\r\n if (this.customHandler) {\r\n try {\r\n return await this.customHandler(error, c);\r\n } catch (customHandlerError) {\r\n // If custom handler fails, fall back to default handling\r\n console.error('Custom error handler failed:', customHandlerError);\r\n }\r\n }\r\n\r\n // Handle ValidationException (422)\r\n if (error instanceof ValidationException) {\r\n return this.handleValidationException(error, c);\r\n }\r\n\r\n // Handle HTTPException and its subclasses\r\n if (error instanceof HTTPException) {\r\n return this.handleHTTPException(error, c);\r\n }\r\n\r\n // Handle generic errors (500)\r\n return this.handleGenericError(error, c);\r\n }\r\n\r\n /**\r\n * Handle validation exceptions (422 Unprocessable Entity)\r\n * @param error - ValidationException instance\r\n * @param c - Hono context\r\n * @returns JSON response with validation error details\r\n */\r\n private handleValidationException(error: ValidationException, c: Context): Response {\r\n const response = error.toJSON();\r\n \r\n // Log validation errors in development\r\n if (this.isDevelopment) {\r\n console.error('Validation Error:', {\r\n path: c.req.path,\r\n method: c.req.method,\r\n details: response.details\r\n });\r\n }\r\n\r\n return c.json(response, error.statusCode as any);\r\n }\r\n\r\n /**\r\n * Handle HTTP exceptions (4xx, 5xx)\r\n * @param error - HTTPException instance\r\n * @param c - Hono context\r\n * @returns JSON response with error details\r\n */\r\n private handleHTTPException(error: HTTPException, c: Context): Response {\r\n const response = error.toJSON();\r\n\r\n // Log HTTP exceptions based on severity\r\n if (error.statusCode >= 500) {\r\n // Server errors - always log\r\n console.error('HTTP Exception:', {\r\n name: error.name,\r\n statusCode: error.statusCode,\r\n message: error.message,\r\n path: c.req.path,\r\n method: c.req.method,\r\n ...(this.isDevelopment && error.stack ? { stack: error.stack } : {})\r\n });\r\n } else if (this.isDevelopment) {\r\n // Client errors - log only in development\r\n console.warn('HTTP Exception:', {\r\n name: error.name,\r\n statusCode: error.statusCode,\r\n message: error.message,\r\n path: c.req.path,\r\n method: c.req.method\r\n });\r\n }\r\n\r\n return c.json(response, error.statusCode as any);\r\n }\r\n\r\n /**\r\n * Handle generic/unexpected errors (500 Internal Server Error)\r\n * Hides internal details in production, shows stack trace in development\r\n * @param error - Generic Error instance\r\n * @param c - Hono context\r\n * @returns JSON response with error details\r\n */\r\n private handleGenericError(error: Error, c: Context): Response {\r\n // Always log generic errors\r\n console.error('Internal Server Error:', {\r\n name: error.name,\r\n message: error.message,\r\n path: c.req.path,\r\n method: c.req.method,\r\n stack: error.stack\r\n });\r\n\r\n // Build response based on environment\r\n const response: any = {\r\n error: 'Internal Server Error',\r\n statusCode: 500\r\n };\r\n\r\n // In development, include error details and stack trace\r\n if (this.isDevelopment) {\r\n response.message = error.message;\r\n response.name = error.name;\r\n \r\n if (error.stack) {\r\n response.stack = error.stack.split('\\n').map(line => line.trim());\r\n }\r\n } else {\r\n // In production, use generic message\r\n response.message = 'An unexpected error occurred';\r\n }\r\n\r\n return c.json(response, 500);\r\n }\r\n\r\n /**\r\n * Check if running in development mode\r\n * @returns true if in development mode\r\n */\r\n isDevelopmentMode(): boolean {\r\n return this.isDevelopment;\r\n }\r\n\r\n /**\r\n * Set development mode manually (useful for testing)\r\n * @param isDev - Whether to enable development mode\r\n */\r\n setDevelopmentMode(isDev: boolean): void {\r\n this.isDevelopment = isDev;\r\n }\r\n}\r\n"
|
|
6
|
+
"/**\r\n * Error handling exports\r\n * Provides all exception classes and error handler\r\n */\r\n\r\nexport {\r\n HTTPException,\r\n NotFoundException,\r\n UnauthorizedException,\r\n ForbiddenException,\r\n BadRequestException\r\n} from './exceptions.js';\r\n\r\nexport { ErrorHandler } from './handler.js';\r\n",
|
|
7
|
+
"import type { Context } from '../types';\r\nimport { HTTPException } from './exceptions.js';\r\nimport { ValidationException } from '../validation/exceptions.js';\r\n\r\n/**\r\n * Custom error handler function type\r\n * Allows users to provide their own error handling logic\r\n */\r\nexport type CustomErrorHandler = (error: Error, c: Context) => Response | Promise<Response>;\r\n\r\n/**\r\n * ErrorHandler processes all errors that occur during request handling\r\n * Provides consistent error responses and handles different error types appropriately\r\n */\r\nexport class ErrorHandler {\r\n private customHandler?: CustomErrorHandler;\r\n private isDevelopment: boolean;\r\n\r\n constructor(customHandler?: CustomErrorHandler) {\r\n this.customHandler = customHandler;\r\n this.isDevelopment = process.env.NODE_ENV !== 'production';\r\n }\r\n\r\n /**\r\n * Set a custom error handler\r\n * @param handler - Custom error handling function\r\n */\r\n setCustomHandler(handler: CustomErrorHandler): void {\r\n this.customHandler = handler;\r\n }\r\n\r\n /**\r\n * Main error handling method\r\n * Processes all error types and returns appropriate HTTP responses\r\n * @param error - The error that occurred\r\n * @param c - Hono context object\r\n * @returns HTTP response with error details\r\n */\r\n async handle(error: Error, c: Context): Promise<Response> {\r\n console.log('ErrorHandler.handle called with:', error.constructor.name, error.message);\r\n \r\n // If custom handler is provided, use it first\r\n if (this.customHandler) {\r\n try {\r\n return await this.customHandler(error, c);\r\n } catch (customHandlerError) {\r\n // If custom handler fails, fall back to default handling\r\n console.error('Custom error handler failed:', customHandlerError);\r\n }\r\n }\r\n\r\n // Handle ValidationException (422)\r\n if (error instanceof ValidationException) {\r\n console.log('Handling as ValidationException');\r\n return this.handleValidationException(error, c);\r\n }\r\n\r\n // Handle HTTPException and its subclasses\r\n if (error instanceof HTTPException) {\r\n console.log('Handling as HTTPException');\r\n return this.handleHTTPException(error, c);\r\n }\r\n\r\n // Handle generic errors (500)\r\n console.log('Handling as generic error');\r\n return this.handleGenericError(error, c);\r\n }\r\n\r\n /**\r\n * Handle validation exceptions (422 Unprocessable Entity)\r\n * @param error - ValidationException instance\r\n * @param c - Hono context\r\n * @returns JSON response with validation error details\r\n */\r\n private handleValidationException(error: ValidationException, c: Context): Response {\r\n const response = error.toJSON();\r\n \r\n // Log validation errors in development\r\n if (this.isDevelopment) {\r\n console.error('Validation Error:', {\r\n path: c.req.path,\r\n method: c.req.method,\r\n details: response.details\r\n });\r\n }\r\n\r\n return c.json(response, error.statusCode as any);\r\n }\r\n\r\n /**\r\n * Handle HTTP exceptions (4xx, 5xx)\r\n * @param error - HTTPException instance\r\n * @param c - Hono context\r\n * @returns JSON response with error details\r\n */\r\n private handleHTTPException(error: HTTPException, c: Context): Response {\r\n const response = error.toJSON();\r\n\r\n // Log HTTP exceptions based on severity\r\n if (error.statusCode >= 500) {\r\n // Server errors - always log\r\n console.error('HTTP Exception:', {\r\n name: error.name,\r\n statusCode: error.statusCode,\r\n message: error.message,\r\n path: c.req.path,\r\n method: c.req.method,\r\n ...(this.isDevelopment && error.stack ? { stack: error.stack } : {})\r\n });\r\n } else if (this.isDevelopment) {\r\n // Client errors - log only in development\r\n console.warn('HTTP Exception:', {\r\n name: error.name,\r\n statusCode: error.statusCode,\r\n message: error.message,\r\n path: c.req.path,\r\n method: c.req.method\r\n });\r\n }\r\n\r\n return c.json(response, error.statusCode as any);\r\n }\r\n\r\n /**\r\n * Handle generic/unexpected errors (500 Internal Server Error)\r\n * Hides internal details in production, shows stack trace in development\r\n * @param error - Generic Error instance\r\n * @param c - Hono context\r\n * @returns JSON response with error details\r\n */\r\n private handleGenericError(error: Error, c: Context): Response {\r\n // Always log generic errors\r\n console.error('Internal Server Error:', {\r\n name: error.name,\r\n message: error.message,\r\n path: c.req.path,\r\n method: c.req.method,\r\n stack: error.stack\r\n });\r\n\r\n // Build response based on environment\r\n const response: any = {\r\n error: 'Internal Server Error',\r\n statusCode: 500\r\n };\r\n\r\n // In development, include error details and stack trace\r\n if (this.isDevelopment) {\r\n response.message = error.message;\r\n response.name = error.name;\r\n \r\n if (error.stack) {\r\n response.stack = error.stack.split('\\n').map(line => line.trim());\r\n }\r\n } else {\r\n // In production, use generic message\r\n response.message = 'An unexpected error occurred';\r\n }\r\n\r\n return c.json(response, 500);\r\n }\r\n\r\n /**\r\n * Check if running in development mode\r\n * @returns true if in development mode\r\n */\r\n isDevelopmentMode(): boolean {\r\n return this.isDevelopment;\r\n }\r\n\r\n /**\r\n * Set development mode manually (useful for testing)\r\n * @param isDev - Whether to enable development mode\r\n */\r\n setDevelopmentMode(isDev: boolean): void {\r\n this.isDevelopment = isDev;\r\n }\r\n}\r\n",
|
|
8
|
+
"import { ZodError } from 'zod';\r\nimport { HTTPException } from '../errors/exceptions.js';\r\n\r\n/**\r\n * ValidationException is thrown when Zod validation fails\r\n * Extends HTTPException with 422 Unprocessable Entity status\r\n * Provides detailed validation error information\r\n */\r\nexport class ValidationException extends HTTPException {\r\n constructor(public zodError: ZodError) {\r\n super(422, 'Validation failed');\r\n this.name = 'ValidationException';\r\n }\r\n\r\n /**\r\n * Converts the validation error to a user-friendly JSON format\r\n * @returns Object with error message and detailed validation errors\r\n */\r\n toJSON() {\r\n return {\r\n error: 'Validation Error',\r\n statusCode: this.statusCode,\r\n details: this.zodError.errors.map(err => ({\r\n path: err.path.join('.'),\r\n message: err.message,\r\n code: err.code\r\n }))\r\n };\r\n }\r\n}\r\n"
|
|
8
9
|
],
|
|
9
|
-
"mappings": "
|
|
10
|
-
"debugId": "
|
|
10
|
+
"mappings": "owBAKa,EAgCA,EAmBA,EAmBA,EAmBA,eAzFA,EAAN,MAAM,UAAsB,KAAM,CAE9B,WAEA,QAHT,WAAW,CACF,EACP,EACO,EACP,CACA,MAAM,CA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