node-honest 0.0.1 → 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.
Files changed (165) hide show
  1. package/dist/index.cjs +2185 -0
  2. package/dist/index.d.cts +1539 -0
  3. package/dist/index.d.ts +1539 -16
  4. package/dist/index.js +2116 -15
  5. package/package.json +14 -11
  6. package/dist/app.d.ts +0 -1
  7. package/dist/app.js +0 -36
  8. package/dist/application/plugin-entries.d.ts +0 -13
  9. package/dist/application/plugin-entries.js +0 -38
  10. package/dist/application/startup-guide.d.ts +0 -4
  11. package/dist/application/startup-guide.js +0 -53
  12. package/dist/application-context.d.ts +0 -13
  13. package/dist/application-context.js +0 -22
  14. package/dist/application.d.ts +0 -34
  15. package/dist/application.js +0 -224
  16. package/dist/components/index.d.ts +0 -1
  17. package/dist/components/index.js +0 -1
  18. package/dist/components/layout.component.d.ts +0 -31
  19. package/dist/components/layout.component.js +0 -94
  20. package/dist/constants/index.d.ts +0 -2
  21. package/dist/constants/index.js +0 -2
  22. package/dist/constants/pipeline.constants.d.ts +0 -6
  23. package/dist/constants/pipeline.constants.js +0 -6
  24. package/dist/constants/version.constants.d.ts +0 -5
  25. package/dist/constants/version.constants.js +0 -5
  26. package/dist/decorators/controller.decorator.d.ts +0 -9
  27. package/dist/decorators/controller.decorator.js +0 -16
  28. package/dist/decorators/http-method.decorator.d.ts +0 -43
  29. package/dist/decorators/http-method.decorator.js +0 -44
  30. package/dist/decorators/index.d.ts +0 -11
  31. package/dist/decorators/index.js +0 -11
  32. package/dist/decorators/module.decorator.d.ts +0 -8
  33. package/dist/decorators/module.decorator.js +0 -12
  34. package/dist/decorators/mvc.decorator.d.ts +0 -26
  35. package/dist/decorators/mvc.decorator.js +0 -36
  36. package/dist/decorators/parameter.decorator.d.ts +0 -41
  37. package/dist/decorators/parameter.decorator.js +0 -59
  38. package/dist/decorators/service.decorator.d.ts +0 -6
  39. package/dist/decorators/service.decorator.js +0 -11
  40. package/dist/decorators/use-component.decorator.d.ts +0 -10
  41. package/dist/decorators/use-component.decorator.js +0 -19
  42. package/dist/decorators/use-filters.decorator.d.ts +0 -8
  43. package/dist/decorators/use-filters.decorator.js +0 -17
  44. package/dist/decorators/use-guards.decorator.d.ts +0 -9
  45. package/dist/decorators/use-guards.decorator.js +0 -18
  46. package/dist/decorators/use-middleware.decorator.d.ts +0 -9
  47. package/dist/decorators/use-middleware.decorator.js +0 -18
  48. package/dist/decorators/use-pipes.decorator.d.ts +0 -9
  49. package/dist/decorators/use-pipes.decorator.js +0 -18
  50. package/dist/di/container.d.ts +0 -34
  51. package/dist/di/container.js +0 -114
  52. package/dist/di/index.d.ts +0 -1
  53. package/dist/di/index.js +0 -1
  54. package/dist/errors/framework.error.d.ts +0 -19
  55. package/dist/errors/framework.error.js +0 -23
  56. package/dist/errors/index.d.ts +0 -1
  57. package/dist/errors/index.js +0 -1
  58. package/dist/handlers/error.handler.d.ts +0 -28
  59. package/dist/handlers/error.handler.js +0 -17
  60. package/dist/handlers/index.d.ts +0 -2
  61. package/dist/handlers/index.js +0 -2
  62. package/dist/handlers/not-found.handler.d.ts +0 -14
  63. package/dist/handlers/not-found.handler.js +0 -17
  64. package/dist/helpers/create-error-response.helper.d.ts +0 -25
  65. package/dist/helpers/create-error-response.helper.js +0 -90
  66. package/dist/helpers/create-http-method-decorator.helper.d.ts +0 -16
  67. package/dist/helpers/create-http-method-decorator.helper.js +0 -30
  68. package/dist/helpers/create-param-decorator.helper.d.ts +0 -16
  69. package/dist/helpers/create-param-decorator.helper.js +0 -60
  70. package/dist/helpers/index.d.ts +0 -3
  71. package/dist/helpers/index.js +0 -3
  72. package/dist/interfaces/application-context.interface.d.ts +0 -35
  73. package/dist/interfaces/application-context.interface.js +0 -1
  74. package/dist/interfaces/controller-options.interface.d.ts +0 -17
  75. package/dist/interfaces/controller-options.interface.js +0 -1
  76. package/dist/interfaces/di-container.interface.d.ts +0 -35
  77. package/dist/interfaces/di-container.interface.js +0 -1
  78. package/dist/interfaces/error-response.interface.d.ts +0 -13
  79. package/dist/interfaces/error-response.interface.js +0 -1
  80. package/dist/interfaces/filter.interface.d.ts +0 -20
  81. package/dist/interfaces/filter.interface.js +0 -1
  82. package/dist/interfaces/guard.interface.d.ts +0 -21
  83. package/dist/interfaces/guard.interface.js +0 -1
  84. package/dist/interfaces/handler-invocation.interface.d.ts +0 -10
  85. package/dist/interfaces/handler-invocation.interface.js +0 -1
  86. package/dist/interfaces/honest-options.interface.d.ts +0 -121
  87. package/dist/interfaces/honest-options.interface.js +0 -1
  88. package/dist/interfaces/http-method-options.interface.d.ts +0 -38
  89. package/dist/interfaces/http-method-options.interface.js +0 -1
  90. package/dist/interfaces/index.d.ts +0 -21
  91. package/dist/interfaces/index.js +0 -21
  92. package/dist/interfaces/logger.interface.d.ts +0 -23
  93. package/dist/interfaces/logger.interface.js +0 -1
  94. package/dist/interfaces/metadata-repository.interface.d.ts +0 -30
  95. package/dist/interfaces/metadata-repository.interface.js +0 -1
  96. package/dist/interfaces/middleware.interface.d.ts +0 -22
  97. package/dist/interfaces/middleware.interface.js +0 -1
  98. package/dist/interfaces/module-options.interface.d.ts +0 -18
  99. package/dist/interfaces/module-options.interface.js +0 -1
  100. package/dist/interfaces/parameter-metadata.interface.d.ts +0 -27
  101. package/dist/interfaces/parameter-metadata.interface.js +0 -1
  102. package/dist/interfaces/parameter-resolution.interface.d.ts +0 -14
  103. package/dist/interfaces/parameter-resolution.interface.js +0 -1
  104. package/dist/interfaces/pipe.interface.d.ts +0 -37
  105. package/dist/interfaces/pipe.interface.js +0 -1
  106. package/dist/interfaces/pipeline-context.interface.d.ts +0 -9
  107. package/dist/interfaces/pipeline-context.interface.js +0 -1
  108. package/dist/interfaces/plugin.interface.d.ts +0 -74
  109. package/dist/interfaces/plugin.interface.js +0 -1
  110. package/dist/interfaces/route-definition.interface.d.ts +0 -51
  111. package/dist/interfaces/route-definition.interface.js +0 -1
  112. package/dist/interfaces/route-info.interface.d.ts +0 -42
  113. package/dist/interfaces/route-info.interface.js +0 -1
  114. package/dist/interfaces/service-registry.interface.d.ts +0 -7
  115. package/dist/interfaces/service-registry.interface.js +0 -1
  116. package/dist/loggers/console.logger.d.ts +0 -7
  117. package/dist/loggers/console.logger.js +0 -21
  118. package/dist/loggers/index.d.ts +0 -2
  119. package/dist/loggers/index.js +0 -2
  120. package/dist/loggers/noop.logger.d.ts +0 -7
  121. package/dist/loggers/noop.logger.js +0 -8
  122. package/dist/managers/component.manager.d.ts +0 -48
  123. package/dist/managers/component.manager.js +0 -210
  124. package/dist/managers/handler.invoker.d.ts +0 -7
  125. package/dist/managers/handler.invoker.js +0 -37
  126. package/dist/managers/index.d.ts +0 -5
  127. package/dist/managers/index.js +0 -5
  128. package/dist/managers/parameter.resolver.d.ts +0 -13
  129. package/dist/managers/parameter.resolver.js +0 -58
  130. package/dist/managers/pipeline.executor.d.ts +0 -28
  131. package/dist/managers/pipeline.executor.js +0 -71
  132. package/dist/managers/route.manager.d.ts +0 -36
  133. package/dist/managers/route.manager.js +0 -149
  134. package/dist/registries/index.d.ts +0 -4
  135. package/dist/registries/index.js +0 -4
  136. package/dist/registries/metadata.registry.d.ts +0 -163
  137. package/dist/registries/metadata.registry.js +0 -250
  138. package/dist/registries/metadata.repository.d.ts +0 -30
  139. package/dist/registries/metadata.repository.js +0 -151
  140. package/dist/registries/route.registry.d.ts +0 -16
  141. package/dist/registries/route.registry.js +0 -46
  142. package/dist/registries/service.registry.d.ts +0 -8
  143. package/dist/registries/service.registry.js +0 -9
  144. package/dist/testing/create-controller-test-application.d.ts +0 -5
  145. package/dist/testing/create-controller-test-application.js +0 -11
  146. package/dist/testing/create-service-test-container.d.ts +0 -5
  147. package/dist/testing/create-service-test-container.js +0 -31
  148. package/dist/testing/create-test-application.d.ts +0 -5
  149. package/dist/testing/create-test-application.js +0 -20
  150. package/dist/testing/create-testing-module.d.ts +0 -6
  151. package/dist/testing/create-testing-module.js +0 -13
  152. package/dist/testing/fixtures/application-test-fixtures.d.ts +0 -17
  153. package/dist/testing/fixtures/application-test-fixtures.js +0 -230
  154. package/dist/testing/index.d.ts +0 -5
  155. package/dist/testing/index.js +0 -5
  156. package/dist/testing/testing.interface.d.ts +0 -96
  157. package/dist/testing/testing.interface.js +0 -1
  158. package/dist/types/constructor.type.d.ts +0 -12
  159. package/dist/types/constructor.type.js +0 -1
  160. package/dist/types/index.d.ts +0 -1
  161. package/dist/types/index.js +0 -1
  162. package/dist/utils/common.util.d.ts +0 -117
  163. package/dist/utils/common.util.js +0 -140
  164. package/dist/utils/index.d.ts +0 -1
  165. package/dist/utils/index.js +0 -1
@@ -1,114 +0,0 @@
1
- import { NoopLogger } from '../loggers';
2
- import { StaticServiceRegistry } from '../registries';
3
- /**
4
- * Dependency Injection container that manages class instances and their dependencies
5
- */
6
- export class Container {
7
- serviceRegistry;
8
- logger;
9
- debugDi;
10
- constructor(serviceRegistry = new StaticServiceRegistry(), logger = new NoopLogger(), debugDi = false) {
11
- this.serviceRegistry = serviceRegistry;
12
- this.logger = logger;
13
- this.debugDi = debugDi;
14
- }
15
- /**
16
- * Map of class constructors to their instances
17
- */
18
- instances = new Map();
19
- emitLog(event) {
20
- if (!this.debugDi) {
21
- return;
22
- }
23
- this.logger.emit(event);
24
- }
25
- /**
26
- * Resolves a class instance, creating it if necessary and injecting its dependencies
27
- * @param target - The class constructor to resolve
28
- * @returns An instance of the target class
29
- */
30
- resolve(target) {
31
- return this.resolveWithTracking(target, new Set());
32
- }
33
- /**
34
- * Internal recursive resolver with circular dependency tracking
35
- */
36
- resolveWithTracking(target, resolving) {
37
- if (this.instances.has(target)) {
38
- this.emitLog({
39
- level: 'debug',
40
- category: 'di',
41
- message: `Resolved ${target.name} from DI cache`
42
- });
43
- return this.instances.get(target);
44
- }
45
- if (resolving.has(target)) {
46
- const cycle = [...resolving.keys(), target].map((t) => t.name).join(' -> ');
47
- this.emitLog({
48
- level: 'error',
49
- category: 'di',
50
- message: `Circular dependency detected while resolving ${target.name}`,
51
- details: { cycle }
52
- });
53
- throw new Error(`Circular dependency detected: ${cycle}`);
54
- }
55
- resolving.add(target);
56
- this.emitLog({
57
- level: 'debug',
58
- category: 'di',
59
- message: `Resolving ${target.name}`,
60
- details: { resolving: [...resolving].map((constructor) => constructor.name) }
61
- });
62
- const paramTypes = Reflect.getMetadata('design:paramtypes', target) || [];
63
- if (target.length > 0 && paramTypes.length === 0) {
64
- if (!this.serviceRegistry.isService(target)) {
65
- this.emitLog({
66
- level: 'error',
67
- category: 'di',
68
- message: `Cannot resolve ${target.name}: missing @Service() decorator`
69
- });
70
- throw new Error(`Cannot resolve ${target.name}: it is not decorated with @Service(). Did you forget to add @Service() to the class?`);
71
- }
72
- this.emitLog({
73
- level: 'error',
74
- category: 'di',
75
- message: `Cannot resolve ${target.name}: missing constructor metadata`
76
- });
77
- throw new Error(`Cannot resolve dependencies for ${target.name}: constructor metadata is missing. Ensure 'reflect-metadata' is imported and 'emitDecoratorMetadata' is enabled.`);
78
- }
79
- const dependencies = paramTypes.map((paramType, index) => {
80
- if (!paramType || paramType === Object || paramType === Array || paramType === Function) {
81
- this.emitLog({
82
- level: 'error',
83
- category: 'di',
84
- message: `Cannot resolve dependency at index ${index} of ${target.name}`
85
- });
86
- throw new Error(`Cannot resolve dependency at index ${index} of ${target.name}. Use concrete class types for constructor dependencies.`);
87
- }
88
- return this.resolveWithTracking(paramType, new Set(resolving));
89
- });
90
- const instance = new target(...dependencies);
91
- this.instances.set(target, instance);
92
- this.emitLog({
93
- level: 'debug',
94
- category: 'di',
95
- message: `Created ${target.name} instance`,
96
- details: { dependencyCount: dependencies.length }
97
- });
98
- return instance;
99
- }
100
- /**
101
- * Registers a pre-created instance for a class
102
- * @param target - The class constructor to register
103
- * @param instance - The instance to register
104
- */
105
- register(target, instance) {
106
- this.instances.set(target, instance);
107
- }
108
- has(target) {
109
- return this.instances.has(target);
110
- }
111
- clear() {
112
- this.instances.clear();
113
- }
114
- }
@@ -1 +0,0 @@
1
- export * from './container';
package/dist/di/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './container';
@@ -1,19 +0,0 @@
1
- export interface FrameworkErrorOptions {
2
- status?: number;
3
- code: string;
4
- category: string;
5
- remediation?: string;
6
- details?: Record<string, unknown>;
7
- cause?: unknown;
8
- }
9
- /**
10
- * Structured framework-level error with machine-readable metadata.
11
- */
12
- export declare class FrameworkError extends Error {
13
- readonly status?: number;
14
- readonly code: string;
15
- readonly category: string;
16
- readonly remediation?: string;
17
- readonly details?: Record<string, unknown>;
18
- constructor(message: string, options: FrameworkErrorOptions);
19
- }
@@ -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
- }
@@ -1 +0,0 @@
1
- export * from './framework.error';
@@ -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
- }
@@ -1,2 +0,0 @@
1
- export * from './error.handler';
2
- export * from './not-found.handler';
@@ -1,2 +0,0 @@
1
- export * from './error.handler';
2
- export * from './not-found.handler';
@@ -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
- }
@@ -1,3 +0,0 @@
1
- export * from './create-error-response.helper';
2
- export * from './create-http-method-decorator.helper';
3
- export * from './create-param-decorator.helper';
@@ -1,3 +0,0 @@
1
- export * from './create-error-response.helper';
2
- export * from './create-http-method-decorator.helper';
3
- export * from './create-param-decorator.helper';
@@ -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 {};