node-honest 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2185 -0
- package/dist/index.d.cts +1539 -0
- package/dist/index.d.ts +1539 -16
- package/dist/index.js +2116 -15
- package/package.json +12 -9
- package/dist/application/plugin-entries.d.ts +0 -13
- package/dist/application/plugin-entries.js +0 -38
- package/dist/application/startup-guide.d.ts +0 -4
- package/dist/application/startup-guide.js +0 -53
- package/dist/application-context.d.ts +0 -13
- package/dist/application-context.js +0 -22
- package/dist/application.d.ts +0 -34
- package/dist/application.js +0 -224
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -1
- package/dist/components/layout.component.d.ts +0 -31
- package/dist/components/layout.component.js +0 -94
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.js +0 -2
- package/dist/constants/pipeline.constants.d.ts +0 -6
- package/dist/constants/pipeline.constants.js +0 -6
- package/dist/constants/version.constants.d.ts +0 -5
- package/dist/constants/version.constants.js +0 -5
- package/dist/decorators/controller.decorator.d.ts +0 -9
- package/dist/decorators/controller.decorator.js +0 -16
- package/dist/decorators/http-method.decorator.d.ts +0 -43
- package/dist/decorators/http-method.decorator.js +0 -44
- package/dist/decorators/index.d.ts +0 -11
- package/dist/decorators/index.js +0 -11
- package/dist/decorators/module.decorator.d.ts +0 -8
- package/dist/decorators/module.decorator.js +0 -12
- package/dist/decorators/mvc.decorator.d.ts +0 -26
- package/dist/decorators/mvc.decorator.js +0 -36
- package/dist/decorators/parameter.decorator.d.ts +0 -41
- package/dist/decorators/parameter.decorator.js +0 -59
- package/dist/decorators/service.decorator.d.ts +0 -6
- package/dist/decorators/service.decorator.js +0 -11
- package/dist/decorators/use-component.decorator.d.ts +0 -10
- package/dist/decorators/use-component.decorator.js +0 -19
- package/dist/decorators/use-filters.decorator.d.ts +0 -8
- package/dist/decorators/use-filters.decorator.js +0 -17
- package/dist/decorators/use-guards.decorator.d.ts +0 -9
- package/dist/decorators/use-guards.decorator.js +0 -18
- package/dist/decorators/use-middleware.decorator.d.ts +0 -9
- package/dist/decorators/use-middleware.decorator.js +0 -18
- package/dist/decorators/use-pipes.decorator.d.ts +0 -9
- package/dist/decorators/use-pipes.decorator.js +0 -18
- package/dist/di/container.d.ts +0 -34
- package/dist/di/container.js +0 -114
- package/dist/di/index.d.ts +0 -1
- package/dist/di/index.js +0 -1
- package/dist/errors/framework.error.d.ts +0 -19
- package/dist/errors/framework.error.js +0 -23
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/handlers/error.handler.d.ts +0 -28
- package/dist/handlers/error.handler.js +0 -17
- package/dist/handlers/index.d.ts +0 -2
- package/dist/handlers/index.js +0 -2
- package/dist/handlers/not-found.handler.d.ts +0 -14
- package/dist/handlers/not-found.handler.js +0 -17
- package/dist/helpers/create-error-response.helper.d.ts +0 -25
- package/dist/helpers/create-error-response.helper.js +0 -90
- package/dist/helpers/create-http-method-decorator.helper.d.ts +0 -16
- package/dist/helpers/create-http-method-decorator.helper.js +0 -30
- package/dist/helpers/create-param-decorator.helper.d.ts +0 -16
- package/dist/helpers/create-param-decorator.helper.js +0 -60
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/index.js +0 -3
- package/dist/interfaces/application-context.interface.d.ts +0 -35
- package/dist/interfaces/application-context.interface.js +0 -1
- package/dist/interfaces/controller-options.interface.d.ts +0 -17
- package/dist/interfaces/controller-options.interface.js +0 -1
- package/dist/interfaces/di-container.interface.d.ts +0 -35
- package/dist/interfaces/di-container.interface.js +0 -1
- package/dist/interfaces/error-response.interface.d.ts +0 -13
- package/dist/interfaces/error-response.interface.js +0 -1
- package/dist/interfaces/filter.interface.d.ts +0 -20
- package/dist/interfaces/filter.interface.js +0 -1
- package/dist/interfaces/guard.interface.d.ts +0 -21
- package/dist/interfaces/guard.interface.js +0 -1
- package/dist/interfaces/handler-invocation.interface.d.ts +0 -10
- package/dist/interfaces/handler-invocation.interface.js +0 -1
- package/dist/interfaces/honest-options.interface.d.ts +0 -121
- package/dist/interfaces/honest-options.interface.js +0 -1
- package/dist/interfaces/http-method-options.interface.d.ts +0 -38
- package/dist/interfaces/http-method-options.interface.js +0 -1
- package/dist/interfaces/index.d.ts +0 -21
- package/dist/interfaces/index.js +0 -21
- package/dist/interfaces/logger.interface.d.ts +0 -23
- package/dist/interfaces/logger.interface.js +0 -1
- package/dist/interfaces/metadata-repository.interface.d.ts +0 -30
- package/dist/interfaces/metadata-repository.interface.js +0 -1
- package/dist/interfaces/middleware.interface.d.ts +0 -22
- package/dist/interfaces/middleware.interface.js +0 -1
- package/dist/interfaces/module-options.interface.d.ts +0 -18
- package/dist/interfaces/module-options.interface.js +0 -1
- package/dist/interfaces/parameter-metadata.interface.d.ts +0 -27
- package/dist/interfaces/parameter-metadata.interface.js +0 -1
- package/dist/interfaces/parameter-resolution.interface.d.ts +0 -14
- package/dist/interfaces/parameter-resolution.interface.js +0 -1
- package/dist/interfaces/pipe.interface.d.ts +0 -37
- package/dist/interfaces/pipe.interface.js +0 -1
- package/dist/interfaces/pipeline-context.interface.d.ts +0 -9
- package/dist/interfaces/pipeline-context.interface.js +0 -1
- package/dist/interfaces/plugin.interface.d.ts +0 -74
- package/dist/interfaces/plugin.interface.js +0 -1
- package/dist/interfaces/route-definition.interface.d.ts +0 -51
- package/dist/interfaces/route-definition.interface.js +0 -1
- package/dist/interfaces/route-info.interface.d.ts +0 -42
- package/dist/interfaces/route-info.interface.js +0 -1
- package/dist/interfaces/service-registry.interface.d.ts +0 -7
- package/dist/interfaces/service-registry.interface.js +0 -1
- package/dist/loggers/console.logger.d.ts +0 -7
- package/dist/loggers/console.logger.js +0 -21
- package/dist/loggers/index.d.ts +0 -2
- package/dist/loggers/index.js +0 -2
- package/dist/loggers/noop.logger.d.ts +0 -7
- package/dist/loggers/noop.logger.js +0 -8
- package/dist/managers/component.manager.d.ts +0 -48
- package/dist/managers/component.manager.js +0 -209
- package/dist/managers/handler.invoker.d.ts +0 -7
- package/dist/managers/handler.invoker.js +0 -37
- package/dist/managers/index.d.ts +0 -5
- package/dist/managers/index.js +0 -5
- package/dist/managers/parameter.resolver.d.ts +0 -13
- package/dist/managers/parameter.resolver.js +0 -57
- package/dist/managers/pipeline.executor.d.ts +0 -28
- package/dist/managers/pipeline.executor.js +0 -68
- package/dist/managers/route.manager.d.ts +0 -36
- package/dist/managers/route.manager.js +0 -147
- package/dist/registries/index.d.ts +0 -4
- package/dist/registries/index.js +0 -4
- package/dist/registries/metadata.registry.d.ts +0 -163
- package/dist/registries/metadata.registry.js +0 -250
- package/dist/registries/metadata.repository.d.ts +0 -30
- package/dist/registries/metadata.repository.js +0 -151
- package/dist/registries/route.registry.d.ts +0 -16
- package/dist/registries/route.registry.js +0 -46
- package/dist/registries/service.registry.d.ts +0 -8
- package/dist/registries/service.registry.js +0 -9
- package/dist/testing/create-controller-test-application.d.ts +0 -5
- package/dist/testing/create-controller-test-application.js +0 -11
- package/dist/testing/create-service-test-container.d.ts +0 -5
- package/dist/testing/create-service-test-container.js +0 -31
- package/dist/testing/create-test-application.d.ts +0 -5
- package/dist/testing/create-test-application.js +0 -20
- package/dist/testing/create-testing-module.d.ts +0 -6
- package/dist/testing/create-testing-module.js +0 -13
- package/dist/testing/fixtures/application-test-fixtures.d.ts +0 -17
- package/dist/testing/fixtures/application-test-fixtures.js +0 -230
- package/dist/testing/index.d.ts +0 -5
- package/dist/testing/index.js +0 -5
- package/dist/testing/testing.interface.d.ts +0 -96
- package/dist/testing/testing.interface.js +0 -1
- package/dist/types/constructor.type.d.ts +0 -12
- package/dist/types/constructor.type.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/utils/common.util.d.ts +0 -117
- package/dist/utils/common.util.js +0 -140
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structured framework-level error with machine-readable metadata.
|
|
3
|
-
*/
|
|
4
|
-
export class FrameworkError extends Error {
|
|
5
|
-
status;
|
|
6
|
-
code;
|
|
7
|
-
category;
|
|
8
|
-
remediation;
|
|
9
|
-
details;
|
|
10
|
-
constructor(message, options) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = 'FrameworkError';
|
|
13
|
-
this.status = options.status;
|
|
14
|
-
this.code = options.code;
|
|
15
|
-
this.category = options.category;
|
|
16
|
-
this.remediation = options.remediation;
|
|
17
|
-
this.details = options.details;
|
|
18
|
-
if (options.cause !== undefined) {
|
|
19
|
-
;
|
|
20
|
-
this.cause = options.cause;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
package/dist/errors/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './framework.error';
|
package/dist/errors/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './framework.error';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
/**
|
|
3
|
-
* Handler for managing application-wide error responses
|
|
4
|
-
* Provides a consistent way to handle and format error responses across the application
|
|
5
|
-
*/
|
|
6
|
-
export declare class ErrorHandler {
|
|
7
|
-
/**
|
|
8
|
-
* Creates a middleware function that handles error responses
|
|
9
|
-
* @returns A middleware function that formats and returns error responses using createErrorResponse
|
|
10
|
-
*/
|
|
11
|
-
static handle(): (err: unknown, c: Context) => Promise<Response & import("hono").TypedResponse<{
|
|
12
|
-
status: number;
|
|
13
|
-
message: string;
|
|
14
|
-
timestamp: string;
|
|
15
|
-
path: string;
|
|
16
|
-
requestId?: string | undefined;
|
|
17
|
-
code?: string | undefined;
|
|
18
|
-
details?: {
|
|
19
|
-
[x: string]: any;
|
|
20
|
-
} | undefined;
|
|
21
|
-
errors?: {
|
|
22
|
-
property: string;
|
|
23
|
-
constraints: {
|
|
24
|
-
[x: string]: string;
|
|
25
|
-
};
|
|
26
|
-
}[] | undefined;
|
|
27
|
-
}, -1 | 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511, "json">>;
|
|
28
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createErrorResponse } from '../helpers';
|
|
2
|
-
/**
|
|
3
|
-
* Handler for managing application-wide error responses
|
|
4
|
-
* Provides a consistent way to handle and format error responses across the application
|
|
5
|
-
*/
|
|
6
|
-
export class ErrorHandler {
|
|
7
|
-
/**
|
|
8
|
-
* Creates a middleware function that handles error responses
|
|
9
|
-
* @returns A middleware function that formats and returns error responses using createErrorResponse
|
|
10
|
-
*/
|
|
11
|
-
static handle() {
|
|
12
|
-
return async (err, c) => {
|
|
13
|
-
const { response, status } = createErrorResponse(err, c);
|
|
14
|
-
return c.json(response, status);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
package/dist/handlers/index.d.ts
DELETED
package/dist/handlers/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
/**
|
|
3
|
-
* Handler for managing 404 Not Found responses
|
|
4
|
-
* Provides a consistent way to handle requests to non-existent routes
|
|
5
|
-
*/
|
|
6
|
-
export declare class NotFoundHandler {
|
|
7
|
-
/**
|
|
8
|
-
* Creates a middleware function that handles 404 Not Found responses
|
|
9
|
-
* @returns A middleware function that returns a JSON response with a 404 status
|
|
10
|
-
*/
|
|
11
|
-
static handle(): (c: Context) => Promise<Response & import("hono").TypedResponse<{
|
|
12
|
-
message: string;
|
|
13
|
-
}, 404, "json">>;
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handler for managing 404 Not Found responses
|
|
3
|
-
* Provides a consistent way to handle requests to non-existent routes
|
|
4
|
-
*/
|
|
5
|
-
export class NotFoundHandler {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a middleware function that handles 404 Not Found responses
|
|
8
|
-
* @returns A middleware function that returns a JSON response with a 404 status
|
|
9
|
-
*/
|
|
10
|
-
static handle() {
|
|
11
|
-
return async (c) => {
|
|
12
|
-
return c.json({
|
|
13
|
-
message: `Not Found - ${c.req.path}`
|
|
14
|
-
}, 404);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
import type { ContentfulStatusCode } from 'hono/utils/http-status';
|
|
3
|
-
import type { ErrorResponse } from '../interfaces';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a standardized error response object
|
|
6
|
-
* @param exception - The error or exception object to process
|
|
7
|
-
* @param context - The Hono context object containing request information
|
|
8
|
-
* @param options - Optional configuration for the error response
|
|
9
|
-
* @param options.status - HTTP status code to override the default
|
|
10
|
-
* @param options.title - Custom error message to override the default
|
|
11
|
-
* @param options.detail - Additional error details
|
|
12
|
-
* @param options.code - Custom error code
|
|
13
|
-
* @param options.additionalDetails - Extra information to include in the response
|
|
14
|
-
* @returns Object containing the formatted error response and HTTP status code
|
|
15
|
-
*/
|
|
16
|
-
export declare function createErrorResponse(exception: unknown, context: Context, options?: {
|
|
17
|
-
status?: number;
|
|
18
|
-
title?: string;
|
|
19
|
-
detail?: string;
|
|
20
|
-
code?: string;
|
|
21
|
-
additionalDetails?: Record<string, unknown>;
|
|
22
|
-
}): {
|
|
23
|
-
response: ErrorResponse;
|
|
24
|
-
status: ContentfulStatusCode;
|
|
25
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { HTTPException } from 'hono/http-exception';
|
|
2
|
-
import { FrameworkError } from '../errors';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a standardized error response object
|
|
5
|
-
* @param exception - The error or exception object to process
|
|
6
|
-
* @param context - The Hono context object containing request information
|
|
7
|
-
* @param options - Optional configuration for the error response
|
|
8
|
-
* @param options.status - HTTP status code to override the default
|
|
9
|
-
* @param options.title - Custom error message to override the default
|
|
10
|
-
* @param options.detail - Additional error details
|
|
11
|
-
* @param options.code - Custom error code
|
|
12
|
-
* @param options.additionalDetails - Extra information to include in the response
|
|
13
|
-
* @returns Object containing the formatted error response and HTTP status code
|
|
14
|
-
*/
|
|
15
|
-
export function createErrorResponse(exception, context, options) {
|
|
16
|
-
const normalizedException = exception instanceof Error ? exception : new Error(String(exception));
|
|
17
|
-
const timestamp = new Date().toISOString();
|
|
18
|
-
const requestId = context.get('requestId');
|
|
19
|
-
const path = context.req.path;
|
|
20
|
-
// Handle HTTPException (Hono's built-in exception)
|
|
21
|
-
if (normalizedException instanceof HTTPException) {
|
|
22
|
-
const response = {
|
|
23
|
-
status: options?.status || normalizedException.status,
|
|
24
|
-
message: options?.title || normalizedException.message,
|
|
25
|
-
timestamp,
|
|
26
|
-
path,
|
|
27
|
-
requestId,
|
|
28
|
-
code: options?.code,
|
|
29
|
-
details: options?.additionalDetails,
|
|
30
|
-
...(options?.detail && { detail: options.detail })
|
|
31
|
-
};
|
|
32
|
-
return { response, status: (options?.status || normalizedException.status) };
|
|
33
|
-
}
|
|
34
|
-
if (normalizedException instanceof FrameworkError) {
|
|
35
|
-
const status = (options?.status || normalizedException.status || 500);
|
|
36
|
-
const response = {
|
|
37
|
-
status,
|
|
38
|
-
message: options?.title || normalizedException.message,
|
|
39
|
-
timestamp,
|
|
40
|
-
path,
|
|
41
|
-
requestId,
|
|
42
|
-
code: options?.code || normalizedException.code,
|
|
43
|
-
details: {
|
|
44
|
-
category: normalizedException.category,
|
|
45
|
-
remediation: normalizedException.remediation,
|
|
46
|
-
...normalizedException.details,
|
|
47
|
-
...options?.additionalDetails
|
|
48
|
-
},
|
|
49
|
-
...(options?.detail && { detail: options.detail })
|
|
50
|
-
};
|
|
51
|
-
return { response, status };
|
|
52
|
-
}
|
|
53
|
-
// Combined status handling
|
|
54
|
-
if (normalizedException.statusCode ||
|
|
55
|
-
normalizedException.status) {
|
|
56
|
-
const defaultStatus = normalizedException.statusCode ||
|
|
57
|
-
normalizedException.status ||
|
|
58
|
-
500;
|
|
59
|
-
const status = options?.status || defaultStatus;
|
|
60
|
-
const response = {
|
|
61
|
-
status,
|
|
62
|
-
message: options?.title || normalizedException.message,
|
|
63
|
-
timestamp,
|
|
64
|
-
path,
|
|
65
|
-
requestId,
|
|
66
|
-
code: options?.code || normalizedException.name,
|
|
67
|
-
details: options?.additionalDetails,
|
|
68
|
-
...(options?.detail && { detail: options.detail })
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
response,
|
|
72
|
-
status: status
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
// Handle unexpected errors
|
|
76
|
-
const status = (options?.status || 500);
|
|
77
|
-
const response = {
|
|
78
|
-
status,
|
|
79
|
-
message: options?.title ||
|
|
80
|
-
(process.env.NODE_ENV === 'production' ? 'Internal Server Error' : normalizedException.message),
|
|
81
|
-
timestamp,
|
|
82
|
-
path,
|
|
83
|
-
requestId,
|
|
84
|
-
code: options?.code || normalizedException.name,
|
|
85
|
-
details: options?.additionalDetails ||
|
|
86
|
-
(process.env.NODE_ENV === 'development' ? { stack: normalizedException.stack } : undefined),
|
|
87
|
-
...(options?.detail && { detail: options.detail })
|
|
88
|
-
};
|
|
89
|
-
return { response, status };
|
|
90
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { HttpMethodOptions } from '../interfaces';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a decorator factory for HTTP method handlers
|
|
4
|
-
* @param method - The HTTP method type (GET, POST, PUT, etc.)
|
|
5
|
-
* @returns A method decorator factory that accepts a path and options
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const Get = createHttpMethodDecorator(HttpMethod.GET);
|
|
9
|
-
*
|
|
10
|
-
* class Controller {
|
|
11
|
-
* @Get('/users')
|
|
12
|
-
* getUsers() { }
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function createHttpMethodDecorator(method: string): (path?: string, options?: HttpMethodOptions) => MethodDecorator;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { MetadataRegistry } from '../registries';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a decorator factory for HTTP method handlers
|
|
4
|
-
* @param method - The HTTP method type (GET, POST, PUT, etc.)
|
|
5
|
-
* @returns A method decorator factory that accepts a path and options
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* const Get = createHttpMethodDecorator(HttpMethod.GET);
|
|
9
|
-
*
|
|
10
|
-
* class Controller {
|
|
11
|
-
* @Get('/users')
|
|
12
|
-
* getUsers() { }
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export function createHttpMethodDecorator(method) {
|
|
17
|
-
return (path = '', options = {}) => {
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
-
return (target, propertyKey, descriptor) => {
|
|
20
|
-
const controllerClass = target.constructor;
|
|
21
|
-
MetadataRegistry.addRoute(controllerClass, {
|
|
22
|
-
path,
|
|
23
|
-
method,
|
|
24
|
-
handlerName: propertyKey,
|
|
25
|
-
version: options.version,
|
|
26
|
-
prefix: options.prefix
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a parameter decorator factory for route handlers
|
|
4
|
-
* @template T - The type of the parameter value after transformation
|
|
5
|
-
* @param type - The type identifier for the parameter
|
|
6
|
-
* @param factory - Optional function to transform the parameter value
|
|
7
|
-
* @returns A parameter decorator function that registers parameter metadata
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const Body = createParamDecorator('body', async (data, ctx) => {
|
|
11
|
-
* const body = await ctx.req.json();
|
|
12
|
-
* return data ? body[data] : body;
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function createParamDecorator<T = unknown>(type: string, factory?: (data: unknown, ctx: Context) => T | Promise<T>): (data?: unknown) => (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { MetadataRegistry } from '../registries';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a parameter decorator factory for route handlers
|
|
4
|
-
* @template T - The type of the parameter value after transformation
|
|
5
|
-
* @param type - The type identifier for the parameter
|
|
6
|
-
* @param factory - Optional function to transform the parameter value
|
|
7
|
-
* @returns A parameter decorator function that registers parameter metadata
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const Body = createParamDecorator('body', async (data, ctx) => {
|
|
11
|
-
* const body = await ctx.req.json();
|
|
12
|
-
* return data ? body[data] : body;
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export function createParamDecorator(type, factory) {
|
|
17
|
-
const fallbackFactory = (data, ctx) => {
|
|
18
|
-
// Safe default when a custom decorator doesn't provide a factory.
|
|
19
|
-
// Returning context keeps the value usable and avoids hard runtime crashes.
|
|
20
|
-
if (data === undefined) {
|
|
21
|
-
return ctx;
|
|
22
|
-
}
|
|
23
|
-
return ctx.get(String(data));
|
|
24
|
-
};
|
|
25
|
-
return (data) => {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
|
|
27
|
-
return (target, propertyKey, parameterIndex) => {
|
|
28
|
-
const controllerClass = target.constructor;
|
|
29
|
-
// Initialize parameters map for the controller if not exists
|
|
30
|
-
if (!MetadataRegistry.getParameters(controllerClass).size) {
|
|
31
|
-
MetadataRegistry.setParameterMap(controllerClass, new Map());
|
|
32
|
-
}
|
|
33
|
-
const parametersMap = MetadataRegistry.getParameters(controllerClass);
|
|
34
|
-
// Initialize parameter metadata array for the method if not exists
|
|
35
|
-
if (!parametersMap.has(propertyKey)) {
|
|
36
|
-
parametersMap.set(propertyKey, []);
|
|
37
|
-
}
|
|
38
|
-
// Get the parameter type from the method signature using reflect-metadata
|
|
39
|
-
const paramTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
40
|
-
const metatype = paramTypes?.[parameterIndex];
|
|
41
|
-
// Add parameter metadata
|
|
42
|
-
const parameters = parametersMap.get(propertyKey);
|
|
43
|
-
parameters.push({
|
|
44
|
-
index: parameterIndex,
|
|
45
|
-
name: type,
|
|
46
|
-
data,
|
|
47
|
-
factory: (factory || fallbackFactory),
|
|
48
|
-
metatype
|
|
49
|
-
});
|
|
50
|
-
// If it's a context parameter, track its index
|
|
51
|
-
if (type === 'context') {
|
|
52
|
-
if (!MetadataRegistry.getContextIndices(controllerClass).size) {
|
|
53
|
-
MetadataRegistry.setContextIndices(controllerClass, new Map());
|
|
54
|
-
}
|
|
55
|
-
const contextIndices = MetadataRegistry.getContextIndices(controllerClass);
|
|
56
|
-
contextIndices.set(propertyKey, parameterIndex);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
}
|
package/dist/helpers/index.d.ts
DELETED
package/dist/helpers/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App-level registry where your application can publish and read pipeline data by key.
|
|
3
|
-
* Available to bootstrap code, services, and any code with access to `app`.
|
|
4
|
-
* Enables composition without hard coupling: producers and consumers use namespaced keys.
|
|
5
|
-
*/
|
|
6
|
-
export interface IApplicationContext {
|
|
7
|
-
/**
|
|
8
|
-
* Get a value by key. Caller provides type for type safety.
|
|
9
|
-
* @param key - Namespaced registry key (e.g. 'app.config', 'openapi.spec')
|
|
10
|
-
* @returns The value or undefined if not set
|
|
11
|
-
*/
|
|
12
|
-
get<T>(key: string): T | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* Set a value by key.
|
|
15
|
-
* @param key - Namespaced registry key
|
|
16
|
-
* @param value - Value to store
|
|
17
|
-
*/
|
|
18
|
-
set<T>(key: string, value: T): void;
|
|
19
|
-
/**
|
|
20
|
-
* Check if a key is present.
|
|
21
|
-
* @param key - Registry key
|
|
22
|
-
* @returns true if the key exists
|
|
23
|
-
*/
|
|
24
|
-
has(key: string): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Remove a key and its value.
|
|
27
|
-
* @param key - Registry key
|
|
28
|
-
* @returns true if the key existed and was removed
|
|
29
|
-
*/
|
|
30
|
-
delete(key: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Iterate over all registered keys.
|
|
33
|
-
*/
|
|
34
|
-
keys(): IterableIterator<string>;
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { VERSION_NEUTRAL } from '../constants';
|
|
2
|
-
/**
|
|
3
|
-
* Interface for controller configuration options
|
|
4
|
-
*/
|
|
5
|
-
export interface ControllerOptions {
|
|
6
|
-
/**
|
|
7
|
-
* API prefix for this controller's routes, overrides global prefix
|
|
8
|
-
*/
|
|
9
|
-
prefix?: string | null;
|
|
10
|
-
/**
|
|
11
|
-
* API version for this controller's routes (e.g. 1 becomes /v1), overrides global version
|
|
12
|
-
* Set to null to explicitly opt out of versioning even when global version is set
|
|
13
|
-
* Set to VERSION_NEUTRAL to make routes accessible both with and without version prefix
|
|
14
|
-
* Set to an array of numbers to make routes available at multiple versions
|
|
15
|
-
*/
|
|
16
|
-
version?: number | null | typeof VERSION_NEUTRAL | number[];
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Constructor } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Interface for dependency injection containers
|
|
4
|
-
* Defines the contract that DI containers must implement to work with the Honest framework
|
|
5
|
-
* Handles the creation and management of dependency instances
|
|
6
|
-
*/
|
|
7
|
-
export interface DiContainer {
|
|
8
|
-
/**
|
|
9
|
-
* Resolves a dependency from the container
|
|
10
|
-
* Creates a new instance or returns an existing one based on the container's configuration
|
|
11
|
-
* @param target - The class constructor to resolve
|
|
12
|
-
* @returns An instance of the requested class with all dependencies injected
|
|
13
|
-
* @throws {Error} If the dependency cannot be resolved
|
|
14
|
-
*/
|
|
15
|
-
resolve<T>(target: Constructor<T>): T;
|
|
16
|
-
/**
|
|
17
|
-
* Registers a pre-created instance in the container
|
|
18
|
-
* Used for singleton instances or mocks in testing
|
|
19
|
-
* @param target - The class constructor to register the instance for
|
|
20
|
-
* @param instance - The pre-created instance to use
|
|
21
|
-
* @throws {Error} If registration fails
|
|
22
|
-
*/
|
|
23
|
-
register<T>(target: Constructor<T>, instance: T): void;
|
|
24
|
-
/**
|
|
25
|
-
* Checks whether the container already holds an instance for the given class
|
|
26
|
-
* @param target - The class constructor to check
|
|
27
|
-
* @returns true if an instance has been resolved or registered
|
|
28
|
-
*/
|
|
29
|
-
has<T>(target: Constructor<T>): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Removes all cached instances from the container
|
|
32
|
-
* Useful for resetting state between tests
|
|
33
|
-
*/
|
|
34
|
-
clear(): void;
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface ErrorResponse {
|
|
2
|
-
status: number;
|
|
3
|
-
message: string;
|
|
4
|
-
timestamp: string;
|
|
5
|
-
path: string;
|
|
6
|
-
requestId?: string;
|
|
7
|
-
code?: string;
|
|
8
|
-
details?: Record<string, any>;
|
|
9
|
-
errors?: Array<{
|
|
10
|
-
property: string;
|
|
11
|
-
constraints: Record<string, string>;
|
|
12
|
-
}>;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
import type { Constructor } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Interface for exception filters
|
|
5
|
-
* Filters handle and transform exceptions thrown during request processing
|
|
6
|
-
*/
|
|
7
|
-
export interface IFilter {
|
|
8
|
-
/**
|
|
9
|
-
* Method to catch and handle exceptions
|
|
10
|
-
* @param exception - The exception that was thrown
|
|
11
|
-
* @param context - The Hono context object
|
|
12
|
-
* @returns A Response object or undefined if the exception should be passed to the next filter
|
|
13
|
-
*/
|
|
14
|
-
catch(exception: Error, context: Context): Promise<Response | undefined> | Response | undefined;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Type for exception filters
|
|
18
|
-
* Can be either a class implementing IFilter or an instance of IFilter
|
|
19
|
-
*/
|
|
20
|
-
export type FilterType = Constructor<IFilter> | IFilter;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Constructor } from '../types';
|
|
2
|
-
import type { Context } from 'hono';
|
|
3
|
-
/**
|
|
4
|
-
* Interface defining a guard.
|
|
5
|
-
* Guards determine whether a request should be handled by the route handler or not.
|
|
6
|
-
*/
|
|
7
|
-
export interface IGuard {
|
|
8
|
-
/**
|
|
9
|
-
* Method to implement the guard logic.
|
|
10
|
-
* Return true to allow the request to proceed, false to deny.
|
|
11
|
-
*
|
|
12
|
-
* @param context - The Hono context object
|
|
13
|
-
* @returns A boolean or Promise<boolean> indicating if the request is allowed
|
|
14
|
-
*/
|
|
15
|
-
canActivate(context: Context): boolean | Promise<boolean>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Type for guard classes
|
|
19
|
-
* Can be either a constructor of IGuard or an instance of IGuard
|
|
20
|
-
*/
|
|
21
|
-
export type GuardType = Constructor<IGuard> | IGuard;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
/**
|
|
3
|
-
* Input contract for invoking route handlers and mapping results to HTTP responses.
|
|
4
|
-
*/
|
|
5
|
-
export interface HandlerInvocationInput {
|
|
6
|
-
handler: (...args: unknown[]) => Promise<unknown> | unknown;
|
|
7
|
-
args: unknown[];
|
|
8
|
-
context: Context;
|
|
9
|
-
contextIndex?: number;
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|