@velajs/vela 0.5.0 → 0.5.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.
@@ -20,7 +20,8 @@ export declare enum HttpMethod {
20
20
  PATCH = "patch",
21
21
  DELETE = "delete",
22
22
  OPTIONS = "options",
23
- HEAD = "head"
23
+ HEAD = "head",
24
+ ALL = "all"
24
25
  }
25
26
  export declare enum ParamType {
26
27
  BODY = "body",
package/dist/constants.js CHANGED
@@ -26,6 +26,7 @@ export var HttpMethod = /*#__PURE__*/ function(HttpMethod) {
26
26
  HttpMethod["DELETE"] = "delete";
27
27
  HttpMethod["OPTIONS"] = "options";
28
28
  HttpMethod["HEAD"] = "head";
29
+ HttpMethod["ALL"] = "all";
29
30
  return HttpMethod;
30
31
  }({});
31
32
  export var ParamType = /*#__PURE__*/ function(ParamType) {
@@ -172,7 +172,10 @@ export class Container {
172
172
  if (!registration.useFactory) {
173
173
  throw new Error('Factory function is missing');
174
174
  }
175
- const dependencies = (registration.inject || []).map((token)=>this.resolve(token));
175
+ const dependencies = (registration.inject || []).map((token)=>{
176
+ const resolved = token instanceof ForwardRef ? token.factory() : token;
177
+ return this.resolve(resolved);
178
+ });
176
179
  const result = registration.useFactory(...dependencies);
177
180
  if (result instanceof Promise) {
178
181
  throw new Error(`Async factory for ${this.tokenToString(registration.provide)} returned a Promise. ` + `Use resolveAsync() for async providers.`);
@@ -1,61 +1,61 @@
1
1
  export declare class HttpException extends Error {
2
2
  readonly statusCode: number;
3
- readonly response?: unknown | undefined;
4
- constructor(message: string, statusCode: number, response?: unknown | undefined);
3
+ private readonly _response;
4
+ constructor(response: string | object, statusCode: number);
5
5
  getStatus(): number;
6
6
  getResponse(): unknown;
7
7
  }
8
8
  export declare class BadRequestException extends HttpException {
9
- constructor(message?: string, response?: unknown);
9
+ constructor(message?: string | object);
10
10
  }
11
11
  export declare class UnauthorizedException extends HttpException {
12
- constructor(message?: string, response?: unknown);
12
+ constructor(message?: string | object);
13
13
  }
14
14
  export declare class ForbiddenException extends HttpException {
15
- constructor(message?: string, response?: unknown);
15
+ constructor(message?: string | object);
16
16
  }
17
17
  export declare class NotFoundException extends HttpException {
18
- constructor(message?: string, response?: unknown);
18
+ constructor(message?: string | object);
19
19
  }
20
20
  export declare class MethodNotAllowedException extends HttpException {
21
- constructor(message?: string, response?: unknown);
21
+ constructor(message?: string | object);
22
22
  }
23
23
  export declare class NotAcceptableException extends HttpException {
24
- constructor(message?: string, response?: unknown);
24
+ constructor(message?: string | object);
25
25
  }
26
26
  export declare class RequestTimeoutException extends HttpException {
27
- constructor(message?: string, response?: unknown);
27
+ constructor(message?: string | object);
28
28
  }
29
29
  export declare class ConflictException extends HttpException {
30
- constructor(message?: string, response?: unknown);
30
+ constructor(message?: string | object);
31
31
  }
32
32
  export declare class GoneException extends HttpException {
33
- constructor(message?: string, response?: unknown);
33
+ constructor(message?: string | object);
34
34
  }
35
35
  export declare class PayloadTooLargeException extends HttpException {
36
- constructor(message?: string, response?: unknown);
36
+ constructor(message?: string | object);
37
37
  }
38
38
  export declare class UnsupportedMediaTypeException extends HttpException {
39
- constructor(message?: string, response?: unknown);
39
+ constructor(message?: string | object);
40
40
  }
41
41
  export declare class UnprocessableEntityException extends HttpException {
42
- constructor(message?: string, response?: unknown);
42
+ constructor(message?: string | object);
43
43
  }
44
44
  export declare class TooManyRequestsException extends HttpException {
45
- constructor(message?: string, response?: unknown);
45
+ constructor(message?: string | object);
46
46
  }
47
47
  export declare class InternalServerErrorException extends HttpException {
48
- constructor(message?: string, response?: unknown);
48
+ constructor(message?: string | object);
49
49
  }
50
50
  export declare class NotImplementedException extends HttpException {
51
- constructor(message?: string, response?: unknown);
51
+ constructor(message?: string | object);
52
52
  }
53
53
  export declare class BadGatewayException extends HttpException {
54
- constructor(message?: string, response?: unknown);
54
+ constructor(message?: string | object);
55
55
  }
56
56
  export declare class ServiceUnavailableException extends HttpException {
57
- constructor(message?: string, response?: unknown);
57
+ constructor(message?: string | object);
58
58
  }
59
59
  export declare class GatewayTimeoutException extends HttpException {
60
- constructor(message?: string, response?: unknown);
60
+ constructor(message?: string | object);
61
61
  }
@@ -1,128 +1,134 @@
1
1
  export class HttpException extends Error {
2
2
  statusCode;
3
- response;
4
- constructor(message, statusCode, response){
5
- super(message), this.statusCode = statusCode, this.response = response;
3
+ _response;
4
+ constructor(response, statusCode){
5
+ const message = typeof response === 'string' ? response : JSON.stringify(response);
6
+ super(message);
6
7
  this.name = 'HttpException';
8
+ this.statusCode = statusCode;
9
+ this._response = response;
7
10
  Object.setPrototypeOf(this, new.target.prototype);
8
11
  }
9
12
  getStatus() {
10
13
  return this.statusCode;
11
14
  }
12
15
  getResponse() {
13
- return this.response ?? {
16
+ if (typeof this._response === 'object' && this._response !== null) {
17
+ return this._response;
18
+ }
19
+ return {
14
20
  statusCode: this.statusCode,
15
- message: this.message
21
+ message: this._response
16
22
  };
17
23
  }
18
24
  }
19
25
  // 4xx
20
26
  export class BadRequestException extends HttpException {
21
- constructor(message = 'Bad Request', response){
22
- super(message, 400, response);
27
+ constructor(message = 'Bad Request'){
28
+ super(message, 400);
23
29
  this.name = 'BadRequestException';
24
30
  }
25
31
  }
26
32
  export class UnauthorizedException extends HttpException {
27
- constructor(message = 'Unauthorized', response){
28
- super(message, 401, response);
33
+ constructor(message = 'Unauthorized'){
34
+ super(message, 401);
29
35
  this.name = 'UnauthorizedException';
30
36
  }
31
37
  }
32
38
  export class ForbiddenException extends HttpException {
33
- constructor(message = 'Forbidden', response){
34
- super(message, 403, response);
39
+ constructor(message = 'Forbidden'){
40
+ super(message, 403);
35
41
  this.name = 'ForbiddenException';
36
42
  }
37
43
  }
38
44
  export class NotFoundException extends HttpException {
39
- constructor(message = 'Not Found', response){
40
- super(message, 404, response);
45
+ constructor(message = 'Not Found'){
46
+ super(message, 404);
41
47
  this.name = 'NotFoundException';
42
48
  }
43
49
  }
44
50
  export class MethodNotAllowedException extends HttpException {
45
- constructor(message = 'Method Not Allowed', response){
46
- super(message, 405, response);
51
+ constructor(message = 'Method Not Allowed'){
52
+ super(message, 405);
47
53
  this.name = 'MethodNotAllowedException';
48
54
  }
49
55
  }
50
56
  export class NotAcceptableException extends HttpException {
51
- constructor(message = 'Not Acceptable', response){
52
- super(message, 406, response);
57
+ constructor(message = 'Not Acceptable'){
58
+ super(message, 406);
53
59
  this.name = 'NotAcceptableException';
54
60
  }
55
61
  }
56
62
  export class RequestTimeoutException extends HttpException {
57
- constructor(message = 'Request Timeout', response){
58
- super(message, 408, response);
63
+ constructor(message = 'Request Timeout'){
64
+ super(message, 408);
59
65
  this.name = 'RequestTimeoutException';
60
66
  }
61
67
  }
62
68
  export class ConflictException extends HttpException {
63
- constructor(message = 'Conflict', response){
64
- super(message, 409, response);
69
+ constructor(message = 'Conflict'){
70
+ super(message, 409);
65
71
  this.name = 'ConflictException';
66
72
  }
67
73
  }
68
74
  export class GoneException extends HttpException {
69
- constructor(message = 'Gone', response){
70
- super(message, 410, response);
75
+ constructor(message = 'Gone'){
76
+ super(message, 410);
71
77
  this.name = 'GoneException';
72
78
  }
73
79
  }
74
80
  export class PayloadTooLargeException extends HttpException {
75
- constructor(message = 'Payload Too Large', response){
76
- super(message, 413, response);
81
+ constructor(message = 'Payload Too Large'){
82
+ super(message, 413);
77
83
  this.name = 'PayloadTooLargeException';
78
84
  }
79
85
  }
80
86
  export class UnsupportedMediaTypeException extends HttpException {
81
- constructor(message = 'Unsupported Media Type', response){
82
- super(message, 415, response);
87
+ constructor(message = 'Unsupported Media Type'){
88
+ super(message, 415);
83
89
  this.name = 'UnsupportedMediaTypeException';
84
90
  }
85
91
  }
86
92
  export class UnprocessableEntityException extends HttpException {
87
- constructor(message = 'Unprocessable Entity', response){
88
- super(message, 422, response);
93
+ constructor(message = 'Unprocessable Entity'){
94
+ super(message, 422);
89
95
  this.name = 'UnprocessableEntityException';
90
96
  }
91
97
  }
92
98
  export class TooManyRequestsException extends HttpException {
93
- constructor(message = 'Too Many Requests', response){
94
- super(message, 429, response);
99
+ constructor(message = 'Too Many Requests'){
100
+ super(message, 429);
95
101
  this.name = 'TooManyRequestsException';
96
102
  }
97
103
  }
98
104
  // 5xx
99
105
  export class InternalServerErrorException extends HttpException {
100
- constructor(message = 'Internal Server Error', response){
101
- super(message, 500, response);
106
+ constructor(message = 'Internal Server Error'){
107
+ super(message, 500);
102
108
  this.name = 'InternalServerErrorException';
103
109
  }
104
110
  }
105
111
  export class NotImplementedException extends HttpException {
106
- constructor(message = 'Not Implemented', response){
107
- super(message, 501, response);
112
+ constructor(message = 'Not Implemented'){
113
+ super(message, 501);
108
114
  this.name = 'NotImplementedException';
109
115
  }
110
116
  }
111
117
  export class BadGatewayException extends HttpException {
112
- constructor(message = 'Bad Gateway', response){
113
- super(message, 502, response);
118
+ constructor(message = 'Bad Gateway'){
119
+ super(message, 502);
114
120
  this.name = 'BadGatewayException';
115
121
  }
116
122
  }
117
123
  export class ServiceUnavailableException extends HttpException {
118
- constructor(message = 'Service Unavailable', response){
119
- super(message, 503, response);
124
+ constructor(message = 'Service Unavailable'){
125
+ super(message, 503);
120
126
  this.name = 'ServiceUnavailableException';
121
127
  }
122
128
  }
123
129
  export class GatewayTimeoutException extends HttpException {
124
- constructor(message = 'Gateway Timeout', response){
125
- super(message, 504, response);
130
+ constructor(message = 'Gateway Timeout'){
131
+ super(message, 504);
126
132
  this.name = 'GatewayTimeoutException';
127
133
  }
128
134
  }
@@ -19,7 +19,7 @@ export class HealthCheckService {
19
19
  error: {},
20
20
  details: {}
21
21
  };
22
- throw new ServiceUnavailableException('Service Unavailable', result);
22
+ throw new ServiceUnavailableException(result);
23
23
  }
24
24
  const results = await Promise.allSettled(indicators.map((fn)=>fn()));
25
25
  const info = {};
@@ -55,7 +55,7 @@ export class HealthCheckService {
55
55
  details
56
56
  };
57
57
  if (status === 'error') {
58
- throw new ServiceUnavailableException('Service Unavailable', checkResult);
58
+ throw new ServiceUnavailableException(checkResult);
59
59
  }
60
60
  return checkResult;
61
61
  }
@@ -38,6 +38,7 @@ export declare const Patch: (path?: string) => MethodDecorator;
38
38
  export declare const Delete: (path?: string) => MethodDecorator;
39
39
  export declare const Options: (path?: string) => MethodDecorator;
40
40
  export declare const Head: (path?: string) => MethodDecorator;
41
+ export declare const All: (path?: string) => MethodDecorator;
41
42
  export declare const Sse: (path?: string) => MethodDecorator;
42
43
  export declare const Param: (nameOrPipe?: string | PipeType, ...pipes: PipeType[]) => ParameterDecorator;
43
44
  export declare const Query: (nameOrPipe?: string | PipeType, ...pipes: PipeType[]) => ParameterDecorator;
@@ -22,7 +22,7 @@ function normalizePath(path) {
22
22
  if (typeof prefixOrOptions === 'string') {
23
23
  prefix = prefixOrOptions;
24
24
  } else if (prefixOrOptions) {
25
- prefix = prefixOrOptions.prefix ?? '';
25
+ prefix = prefixOrOptions.path ?? prefixOrOptions.prefix ?? '';
26
26
  version = prefixOrOptions.version;
27
27
  } else {
28
28
  prefix = '';
@@ -96,6 +96,7 @@ export const Patch = createMethodDecorator(HttpMethod.PATCH);
96
96
  export const Delete = createMethodDecorator(HttpMethod.DELETE);
97
97
  export const Options = createMethodDecorator(HttpMethod.OPTIONS);
98
98
  export const Head = createMethodDecorator(HttpMethod.HEAD);
99
+ export const All = createMethodDecorator(HttpMethod.ALL);
99
100
  export const Sse = createMethodDecorator(HttpMethod.GET);
100
101
  // Parameter decorators
101
102
  const CUSTOM_PARAM_TYPE = 'custom';
@@ -1,5 +1,5 @@
1
1
  export { RouteManager } from './route.manager';
2
2
  export { MiddlewareBuilder, RequestMethod } from './middleware-consumer';
3
3
  export type { MiddlewareConsumer, MiddlewareConfigProxy, RouteInfo, NestModule, MiddlewareRouteDefinition } from './middleware-consumer';
4
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators, isController, } from './decorators';
4
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, All, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators, isController, } from './decorators';
5
5
  export type { RouteMetadata, ControllerMetadata, ControllerOptions, ParamMetadata, ControllerRegistration, } from './types';
@@ -1,3 +1,3 @@
1
1
  export { RouteManager } from "./route.manager.js";
2
2
  export { MiddlewareBuilder, RequestMethod } from "./middleware-consumer.js";
3
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators, isController } from "./decorators.js";
3
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, All, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators, isController } from "./decorators.js";
@@ -352,10 +352,17 @@ export class RouteManager {
352
352
  case ParamType.QUERY:
353
353
  return param.name ? c.req.query(param.name) : c.req.query();
354
354
  case ParamType.BODY:
355
- try {
356
- return await c.req.json();
357
- } catch {
358
- return undefined;
355
+ {
356
+ let body;
357
+ try {
358
+ body = await c.req.json();
359
+ } catch {
360
+ return undefined;
361
+ }
362
+ if (param.name && body !== null && typeof body === 'object') {
363
+ return body[param.name];
364
+ }
365
+ return body;
359
366
  }
360
367
  case ParamType.HEADERS:
361
368
  if (param.name) {
@@ -432,7 +439,11 @@ export class RouteManager {
432
439
  app.options(normalizedPath, handler);
433
440
  break;
434
441
  case HttpMethod.HEAD:
435
- app.on('HEAD', normalizedPath, handler);
442
+ // Hono converts HEAD to GET internally, so register as GET
443
+ app.get(normalizedPath, handler);
444
+ break;
445
+ case HttpMethod.ALL:
446
+ app.all(normalizedPath, handler);
436
447
  break;
437
448
  default:
438
449
  app.on(method.toUpperCase(), normalizedPath, handler);
@@ -9,6 +9,7 @@ export interface RouteMetadata {
9
9
  }
10
10
  export interface ControllerOptions {
11
11
  prefix?: string;
12
+ path?: string;
12
13
  version?: number | number[];
13
14
  }
14
15
  export interface ControllerMetadata {
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { VelaApplication } from './application';
5
5
  export { Container, Injectable, Inject, Optional, InjectionToken, ForwardRef, forwardRef, ModuleRef, mixin } from './container/index';
6
6
  export type { Type, Token, InjectableOptions, ProviderOptions, } from './container/index';
7
7
  export { METADATA_KEYS, HttpMethod, ParamType, Scope } from './constants';
8
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators, } from './http/index';
8
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, All, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators, } from './http/index';
9
9
  export { Logger, LogLevel } from './services/index';
10
10
  export type { LoggerService } from './services/index';
11
11
  export { ConfigModule, ConfigService, CONFIG_OPTIONS } from './config/index';
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ export { Container, Injectable, Inject, Optional, InjectionToken, ForwardRef, fo
8
8
  // Constants
9
9
  export { METADATA_KEYS, HttpMethod, ParamType, Scope } from "./constants.js";
10
10
  // HTTP Decorators
11
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators } from "./http/index.js";
11
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, All, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, applyDecorators } from "./http/index.js";
12
12
  // Services
13
13
  export { Logger, LogLevel } from "./services/index.js";
14
14
  // Config
@@ -7,7 +7,7 @@ export class ValidationPipe {
7
7
  return metatype.schema.parse(value);
8
8
  } catch (error) {
9
9
  if (error && typeof error === 'object' && 'issues' in error && Array.isArray(error.issues)) {
10
- throw new BadRequestException('Validation failed', {
10
+ throw new BadRequestException({
11
11
  statusCode: 400,
12
12
  message: 'Validation failed',
13
13
  errors: error.issues
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/vela",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "NestJS-compatible framework for edge runtimes, powered by Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",