glasswork 0.7.1 → 0.8.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/authorization/ability-middleware.d.ts +61 -0
- package/dist/authorization/ability-middleware.d.ts.map +1 -0
- package/dist/authorization/ability-middleware.js +74 -0
- package/dist/authorization/ability-middleware.js.map +1 -0
- package/dist/authorization/index.d.ts +46 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +46 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/route-helpers.d.ts +106 -0
- package/dist/authorization/route-helpers.d.ts.map +1 -0
- package/dist/authorization/route-helpers.js +136 -0
- package/dist/authorization/route-helpers.js.map +1 -0
- package/dist/authorization/service-proxy.d.ts +59 -0
- package/dist/authorization/service-proxy.d.ts.map +1 -0
- package/dist/authorization/service-proxy.js +110 -0
- package/dist/authorization/service-proxy.js.map +1 -0
- package/dist/authorization/types.d.ts +58 -0
- package/dist/authorization/types.d.ts.map +1 -0
- package/dist/authorization/types.js +7 -0
- package/dist/authorization/types.js.map +1 -0
- package/dist/core/bootstrap.d.ts +1 -1
- package/dist/core/bootstrap.d.ts.map +1 -1
- package/dist/core/bootstrap.js +87 -2
- package/dist/core/bootstrap.js.map +1 -1
- package/dist/core/types.d.ts +71 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/hooks/authorization-hook.d.ts +100 -0
- package/dist/hooks/authorization-hook.d.ts.map +1 -0
- package/dist/hooks/authorization-hook.js +93 -0
- package/dist/hooks/authorization-hook.js.map +1 -0
- package/dist/hooks/index.d.ts +54 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +55 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/service-hooks.d.ts +82 -0
- package/dist/hooks/service-hooks.d.ts.map +1 -0
- package/dist/hooks/service-hooks.js +158 -0
- package/dist/hooks/service-hooks.js.map +1 -0
- package/dist/hooks/types.d.ts +151 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +2 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/http/route-helpers.d.ts +22 -0
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js +11 -8
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/openapi/openapi-transformer.d.ts +0 -5
- package/dist/openapi/openapi-transformer.d.ts.map +1 -1
- package/dist/openapi/openapi-transformer.js +0 -5
- package/dist/openapi/openapi-transformer.js.map +1 -1
- package/dist/utils/pagination.d.ts +48 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +42 -0
- package/dist/utils/pagination.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service hooks system for wrapping service method calls with before/after/error hooks.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a flexible hook system that can be used for:
|
|
5
|
+
* - Authorization (using CASL)
|
|
6
|
+
* - Audit logging
|
|
7
|
+
* - Metrics and tracing
|
|
8
|
+
* - Error handling
|
|
9
|
+
* - Retry logic
|
|
10
|
+
* - Timeouts
|
|
11
|
+
* - Response transformation
|
|
12
|
+
*
|
|
13
|
+
* Hooks are transparent - they wrap service methods without modifying the service
|
|
14
|
+
* implementation, keeping business logic clean and framework-agnostic.
|
|
15
|
+
*
|
|
16
|
+
* @module hooks
|
|
17
|
+
*
|
|
18
|
+
* @example Basic Usage
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { authorizationHook, defineServiceMetadata } from 'glasswork';
|
|
21
|
+
*
|
|
22
|
+
* // Define metadata for service methods
|
|
23
|
+
* export const authServiceMetadata = defineServiceMetadata({
|
|
24
|
+
* deleteSession: {
|
|
25
|
+
* authorize: {
|
|
26
|
+
* action: 'delete',
|
|
27
|
+
* subject: 'Session'
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Configure hooks globally in bootstrap
|
|
33
|
+
* bootstrap({
|
|
34
|
+
* serviceHooks: [authorizationHook],
|
|
35
|
+
* serviceMetadata: {
|
|
36
|
+
* authService: authServiceMetadata
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // In routes, service calls are automatically wrapped
|
|
41
|
+
* export const authRoutes = createRoutes((router, { authService }) => {
|
|
42
|
+
* router.delete('/session', ...route({
|
|
43
|
+
* handler: async ({ context }) => {
|
|
44
|
+
* // This automatically checks authorization before executing!
|
|
45
|
+
* await authService.deleteSession(token);
|
|
46
|
+
* }
|
|
47
|
+
* }));
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
// Built-in hooks
|
|
52
|
+
export { authorizationHook, defineAuthorize, } from './authorization-hook.js';
|
|
53
|
+
// Hook system
|
|
54
|
+
export { defineServiceMetadata, withServiceHooks, withServiceHooksMany, } from './service-hooks.js';
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,iBAAiB;AACjB,OAAO,EAEL,iBAAiB,EACjB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAEjC,cAAc;AACd,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { ServiceHooksConfig, ServiceMethodMetadata } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a service with hooks that run before/after/on-error for method calls.
|
|
5
|
+
* This creates a transparent proxy that intercepts method calls and runs hooks
|
|
6
|
+
* while preserving all service functionality.
|
|
7
|
+
*
|
|
8
|
+
* **Note:** Hooks only run for method calls, not property access.
|
|
9
|
+
*
|
|
10
|
+
* @param service - The service instance to wrap
|
|
11
|
+
* @param config - Hook configuration
|
|
12
|
+
* @param honoContext - The current Hono request context
|
|
13
|
+
* @returns Proxied service with hooks
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const authHook: ServiceHook = {
|
|
18
|
+
* before: async (context) => {
|
|
19
|
+
* if (context.metadata?.authorize) {
|
|
20
|
+
* authorize(context.honoContext, ...);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* const wrappedService = withServiceHooks(authService, {
|
|
26
|
+
* hooks: [authHook],
|
|
27
|
+
* metadata: {
|
|
28
|
+
* deleteSession: {
|
|
29
|
+
* authorize: { action: 'delete', subject: 'Session' }
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* }, honoContext);
|
|
33
|
+
*
|
|
34
|
+
* // Hooks automatically run when calling methods
|
|
35
|
+
* await wrappedService.deleteSession(token);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function withServiceHooks<T extends object>(service: T, config: ServiceHooksConfig, honoContext: Context): T;
|
|
39
|
+
/**
|
|
40
|
+
* Wraps multiple services with the same hooks configuration.
|
|
41
|
+
* Useful when you want to apply the same hooks to all services in a container.
|
|
42
|
+
*
|
|
43
|
+
* @param services - Object containing service instances
|
|
44
|
+
* @param config - Hook configuration (can be a function for per-service config)
|
|
45
|
+
* @param honoContext - The current Hono request context
|
|
46
|
+
* @returns Object with all services wrapped with hooks
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const wrappedServices = withServiceHooksMany(
|
|
51
|
+
* { authService, userService },
|
|
52
|
+
* (serviceName) => ({
|
|
53
|
+
* hooks: [authHook, auditHook],
|
|
54
|
+
* metadata: serviceMetadataRegistry[serviceName],
|
|
55
|
+
* serviceName,
|
|
56
|
+
* }),
|
|
57
|
+
* honoContext
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function withServiceHooksMany<T extends Record<string, object>>(services: T, config: ServiceHooksConfig | ((serviceName: string, service: unknown) => ServiceHooksConfig), honoContext: Context): T;
|
|
62
|
+
/**
|
|
63
|
+
* Helper to define service method metadata with better type inference.
|
|
64
|
+
* This is just an identity function that helps TypeScript understand the structure.
|
|
65
|
+
*
|
|
66
|
+
* @param metadata - Service method metadata mapping
|
|
67
|
+
* @returns The same metadata (identity function)
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* export const authServiceMetadata = defineServiceMetadata({
|
|
72
|
+
* deleteSession: {
|
|
73
|
+
* authorize: { action: 'delete', subject: 'Session' }
|
|
74
|
+
* },
|
|
75
|
+
* findById: {
|
|
76
|
+
* authorize: { action: 'read', subject: 'User' }
|
|
77
|
+
* }
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function defineServiceMetadata(metadata: Record<string, ServiceMethodMetadata>): Record<string, ServiceMethodMetadata>;
|
|
82
|
+
//# sourceMappingURL=service-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-hooks.d.ts","sourceRoot":"","sources":["../../src/hooks/service-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAGV,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAkDpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,kBAAkB,EAC1B,WAAW,EAAE,OAAO,GACnB,CAAC,CAqCH;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnE,QAAQ,EAAE,CAAC,EACX,MAAM,EAAE,kBAAkB,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,kBAAkB,CAAC,EAC5F,WAAW,EAAE,OAAO,GACnB,CAAC,CAcH;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAC9C,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAEvC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a method with hooks (before/after/error).
|
|
3
|
+
* Extracted as a helper to reduce complexity.
|
|
4
|
+
*/
|
|
5
|
+
async function executeWithHooks(hookContext, hooks,
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: Function type requires any
|
|
7
|
+
originalMethod, target, args) {
|
|
8
|
+
try {
|
|
9
|
+
// Run all before hooks
|
|
10
|
+
for (const hook of hooks) {
|
|
11
|
+
if (hook.before) {
|
|
12
|
+
await hook.before(hookContext, args);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// Execute original method
|
|
16
|
+
let result = await originalMethod.apply(target, args);
|
|
17
|
+
// Run all after hooks (in order)
|
|
18
|
+
for (const hook of hooks) {
|
|
19
|
+
if (hook.after) {
|
|
20
|
+
const hookResult = await hook.after(hookContext, args, result);
|
|
21
|
+
// If hook returns a value, use it as the new result
|
|
22
|
+
if (hookResult !== undefined) {
|
|
23
|
+
result = hookResult;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
// Run all error hooks
|
|
31
|
+
for (const hook of hooks) {
|
|
32
|
+
if (hook.onError) {
|
|
33
|
+
await hook.onError(hookContext, args, error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Re-throw the error after hooks
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wraps a service with hooks that run before/after/on-error for method calls.
|
|
42
|
+
* This creates a transparent proxy that intercepts method calls and runs hooks
|
|
43
|
+
* while preserving all service functionality.
|
|
44
|
+
*
|
|
45
|
+
* **Note:** Hooks only run for method calls, not property access.
|
|
46
|
+
*
|
|
47
|
+
* @param service - The service instance to wrap
|
|
48
|
+
* @param config - Hook configuration
|
|
49
|
+
* @param honoContext - The current Hono request context
|
|
50
|
+
* @returns Proxied service with hooks
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const authHook: ServiceHook = {
|
|
55
|
+
* before: async (context) => {
|
|
56
|
+
* if (context.metadata?.authorize) {
|
|
57
|
+
* authorize(context.honoContext, ...);
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* };
|
|
61
|
+
*
|
|
62
|
+
* const wrappedService = withServiceHooks(authService, {
|
|
63
|
+
* hooks: [authHook],
|
|
64
|
+
* metadata: {
|
|
65
|
+
* deleteSession: {
|
|
66
|
+
* authorize: { action: 'delete', subject: 'Session' }
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* }, honoContext);
|
|
70
|
+
*
|
|
71
|
+
* // Hooks automatically run when calling methods
|
|
72
|
+
* await wrappedService.deleteSession(token);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export function withServiceHooks(service, config, honoContext) {
|
|
76
|
+
const { hooks, metadata = {}, serviceName } = config;
|
|
77
|
+
// Try to determine service name
|
|
78
|
+
const inferredServiceName = serviceName || service.constructor?.name || 'UnknownService';
|
|
79
|
+
return new Proxy(service, {
|
|
80
|
+
get(target, prop) {
|
|
81
|
+
// Only intercept string properties (method names)
|
|
82
|
+
if (typeof prop !== 'string') {
|
|
83
|
+
return Reflect.get(target, prop);
|
|
84
|
+
}
|
|
85
|
+
const originalValue = Reflect.get(target, prop);
|
|
86
|
+
// If it's not a function, return as-is
|
|
87
|
+
if (typeof originalValue !== 'function') {
|
|
88
|
+
return originalValue;
|
|
89
|
+
}
|
|
90
|
+
// Get metadata for this method
|
|
91
|
+
const methodMetadata = metadata[prop];
|
|
92
|
+
// Return wrapped function with hooks
|
|
93
|
+
return async function (...args) {
|
|
94
|
+
const hookContext = {
|
|
95
|
+
honoContext,
|
|
96
|
+
serviceName: inferredServiceName,
|
|
97
|
+
methodName: prop,
|
|
98
|
+
metadata: methodMetadata,
|
|
99
|
+
};
|
|
100
|
+
// biome-ignore lint/suspicious/noExplicitAny: originalValue is guaranteed to be a function by the check above
|
|
101
|
+
return executeWithHooks(hookContext, hooks, originalValue, target, args);
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Wraps multiple services with the same hooks configuration.
|
|
108
|
+
* Useful when you want to apply the same hooks to all services in a container.
|
|
109
|
+
*
|
|
110
|
+
* @param services - Object containing service instances
|
|
111
|
+
* @param config - Hook configuration (can be a function for per-service config)
|
|
112
|
+
* @param honoContext - The current Hono request context
|
|
113
|
+
* @returns Object with all services wrapped with hooks
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const wrappedServices = withServiceHooksMany(
|
|
118
|
+
* { authService, userService },
|
|
119
|
+
* (serviceName) => ({
|
|
120
|
+
* hooks: [authHook, auditHook],
|
|
121
|
+
* metadata: serviceMetadataRegistry[serviceName],
|
|
122
|
+
* serviceName,
|
|
123
|
+
* }),
|
|
124
|
+
* honoContext
|
|
125
|
+
* );
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export function withServiceHooksMany(services, config, honoContext) {
|
|
129
|
+
const result = {};
|
|
130
|
+
for (const [serviceName, service] of Object.entries(services)) {
|
|
131
|
+
const serviceConfig = typeof config === 'function' ? config(serviceName, service) : config;
|
|
132
|
+
result[serviceName] = withServiceHooks(service, { ...serviceConfig, serviceName }, honoContext);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Helper to define service method metadata with better type inference.
|
|
138
|
+
* This is just an identity function that helps TypeScript understand the structure.
|
|
139
|
+
*
|
|
140
|
+
* @param metadata - Service method metadata mapping
|
|
141
|
+
* @returns The same metadata (identity function)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* export const authServiceMetadata = defineServiceMetadata({
|
|
146
|
+
* deleteSession: {
|
|
147
|
+
* authorize: { action: 'delete', subject: 'Session' }
|
|
148
|
+
* },
|
|
149
|
+
* findById: {
|
|
150
|
+
* authorize: { action: 'read', subject: 'User' }
|
|
151
|
+
* }
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function defineServiceMetadata(metadata) {
|
|
156
|
+
return metadata;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=service-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-hooks.js","sourceRoot":"","sources":["../../src/hooks/service-hooks.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,KAAK,UAAU,gBAAgB,CAC7B,WAA+B,EAC/B,KAAoB;AACpB,yEAAyE;AACzE,cAAuC,EACvC,MAAe,EACf,IAAe;IAEf,IAAI,CAAC;QACH,uBAAuB;QACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QAED,0BAA0B;QAC1B,IA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AU,qBAAqB,CACnC,QAA+C;IAE/C,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* Context passed to service hooks containing the current Hono request context
|
|
4
|
+
* and any additional metadata about the service call.
|
|
5
|
+
*/
|
|
6
|
+
export interface ServiceHookContext {
|
|
7
|
+
/**
|
|
8
|
+
* The Hono request context, providing access to request data,
|
|
9
|
+
* response helpers, and context variables (like user, ability, etc.)
|
|
10
|
+
*/
|
|
11
|
+
honoContext: Context;
|
|
12
|
+
/**
|
|
13
|
+
* The name of the service being called (e.g., 'authService', 'userService')
|
|
14
|
+
*/
|
|
15
|
+
serviceName: string;
|
|
16
|
+
/**
|
|
17
|
+
* The name of the method being called (e.g., 'deleteSession', 'findById')
|
|
18
|
+
*/
|
|
19
|
+
methodName: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional metadata associated with this service method.
|
|
22
|
+
* Can be used to pass configuration like authorization rules, audit info, etc.
|
|
23
|
+
*/
|
|
24
|
+
metadata?: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Hook function that runs before a service method is executed.
|
|
28
|
+
* Can be used for authorization, validation, logging, etc.
|
|
29
|
+
*
|
|
30
|
+
* @param context - Hook context with Hono context and service info
|
|
31
|
+
* @param args - Arguments being passed to the service method
|
|
32
|
+
* @throws Error to prevent the service method from executing
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const authorizationHook: ServiceBeforeHook = async (context, args) => {
|
|
37
|
+
* const { honoContext, metadata } = context;
|
|
38
|
+
* if (metadata?.authorize) {
|
|
39
|
+
* authorize(honoContext, metadata.authorize.action, metadata.authorize.subject);
|
|
40
|
+
* }
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export type ServiceBeforeHook = (context: ServiceHookContext, args: unknown[]) => Promise<void> | void;
|
|
45
|
+
/**
|
|
46
|
+
* Hook function that runs after a service method successfully executes.
|
|
47
|
+
* Can be used for audit logging, metrics, response transformation, etc.
|
|
48
|
+
*
|
|
49
|
+
* @param context - Hook context with Hono context and service info
|
|
50
|
+
* @param args - Arguments that were passed to the service method
|
|
51
|
+
* @param result - The result returned by the service method
|
|
52
|
+
* @returns Optionally return a transformed result
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const auditHook: ServiceAfterHook = async (context, args, result) => {
|
|
57
|
+
* await auditLog.create({
|
|
58
|
+
* service: context.serviceName,
|
|
59
|
+
* method: context.methodName,
|
|
60
|
+
* args,
|
|
61
|
+
* timestamp: new Date(),
|
|
62
|
+
* });
|
|
63
|
+
* };
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export type ServiceAfterHook = (context: ServiceHookContext, args: unknown[], result: unknown) => Promise<unknown | undefined> | unknown | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Hook function that runs when a service method throws an error.
|
|
69
|
+
* Can be used for error logging, error transformation, retries, etc.
|
|
70
|
+
*
|
|
71
|
+
* @param context - Hook context with Hono context and service info
|
|
72
|
+
* @param args - Arguments that were passed to the service method
|
|
73
|
+
* @param error - The error that was thrown
|
|
74
|
+
* @throws Error to propagate or throw a different error
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const errorLoggingHook: ServiceErrorHook = async (context, args, error) => {
|
|
79
|
+
* logger.error('Service error', {
|
|
80
|
+
* service: context.serviceName,
|
|
81
|
+
* method: context.methodName,
|
|
82
|
+
* error,
|
|
83
|
+
* });
|
|
84
|
+
* // Re-throw to propagate
|
|
85
|
+
* throw error;
|
|
86
|
+
* };
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export type ServiceErrorHook = (context: ServiceHookContext, args: unknown[], error: unknown) => undefined | never | Promise<undefined | never>;
|
|
90
|
+
/**
|
|
91
|
+
* A service hook that can define before, after, and error handlers.
|
|
92
|
+
*/
|
|
93
|
+
export interface ServiceHook {
|
|
94
|
+
/**
|
|
95
|
+
* Optional hook that runs before the service method executes.
|
|
96
|
+
*/
|
|
97
|
+
before?: ServiceBeforeHook;
|
|
98
|
+
/**
|
|
99
|
+
* Optional hook that runs after the service method successfully executes.
|
|
100
|
+
*/
|
|
101
|
+
after?: ServiceAfterHook;
|
|
102
|
+
/**
|
|
103
|
+
* Optional hook that runs when the service method throws an error.
|
|
104
|
+
*/
|
|
105
|
+
onError?: ServiceErrorHook;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Metadata that can be attached to service methods to configure hook behavior.
|
|
109
|
+
*/
|
|
110
|
+
export type ServiceMethodMetadata = Record<string, unknown>;
|
|
111
|
+
/**
|
|
112
|
+
* Configuration for applying hooks to a service.
|
|
113
|
+
*/
|
|
114
|
+
export interface ServiceHooksConfig {
|
|
115
|
+
/**
|
|
116
|
+
* Array of hooks to apply to the service.
|
|
117
|
+
* Hooks run in the order they're defined.
|
|
118
|
+
*/
|
|
119
|
+
hooks: ServiceHook[];
|
|
120
|
+
/**
|
|
121
|
+
* Optional metadata for service methods.
|
|
122
|
+
* Keys are method names, values are metadata objects.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* {
|
|
127
|
+
* deleteSession: {
|
|
128
|
+
* authorize: { action: 'delete', subject: 'Session' }
|
|
129
|
+
* },
|
|
130
|
+
* findById: {
|
|
131
|
+
* authorize: { action: 'read', subject: 'User' },
|
|
132
|
+
* cache: { ttl: 300 }
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
metadata?: Record<string, ServiceMethodMetadata>;
|
|
138
|
+
/**
|
|
139
|
+
* Optional service name for better debugging.
|
|
140
|
+
* If not provided, will try to infer from the service constructor name.
|
|
141
|
+
*/
|
|
142
|
+
serviceName?: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Services registry that maps service names to their wrapped instances.
|
|
146
|
+
* This is used internally by the route context to provide hooked services.
|
|
147
|
+
*/
|
|
148
|
+
export type ServicesRegistry<T = unknown> = {
|
|
149
|
+
[K in keyof T]: T[K];
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,OAAO,EAAE,KACZ,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,OAAO,EAAE,EACf,MAAM,EAAE,OAAO,KACZ,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,OAAO,EAAE,EACf,KAAK,EAAE,OAAO,KACX,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,KAAK,EAAE,WAAW,EAAE,CAAC;IAErB;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAEjD;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,OAAO,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":""}
|
|
@@ -126,6 +126,22 @@ export interface RouteOpenAPIOptions extends Partial<Omit<DescribeRouteOptions,
|
|
|
126
126
|
* ```
|
|
127
127
|
*/
|
|
128
128
|
responseHeaders?: string[] | Record<string, string[]>;
|
|
129
|
+
/**
|
|
130
|
+
* Exclude this route from the OpenAPI specification.
|
|
131
|
+
* Useful for internal or hidden endpoints.
|
|
132
|
+
*/
|
|
133
|
+
exclude?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Mark this route as deprecated.
|
|
136
|
+
*/
|
|
137
|
+
deprecated?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* External documentation for this route.
|
|
140
|
+
*/
|
|
141
|
+
docs?: {
|
|
142
|
+
description?: string;
|
|
143
|
+
url: string;
|
|
144
|
+
};
|
|
129
145
|
}
|
|
130
146
|
/**
|
|
131
147
|
* Route configuration with automatic type inference from Valibot schemas.
|
|
@@ -166,6 +182,12 @@ export interface RouteConfig<TBody extends ValibotSchema | undefined = undefined
|
|
|
166
182
|
*/
|
|
167
183
|
public?: TPublic;
|
|
168
184
|
body?: TBody;
|
|
185
|
+
/**
|
|
186
|
+
* Content type for request body validation.
|
|
187
|
+
* - 'json': application/json (default)
|
|
188
|
+
* - 'form': application/x-www-form-urlencoded or multipart/form-data
|
|
189
|
+
*/
|
|
190
|
+
bodyType?: 'json' | 'form';
|
|
169
191
|
query?: ValibotSchema;
|
|
170
192
|
params?: ValibotSchema;
|
|
171
193
|
responses?: TResponses;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/http/route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE7D,OAAO,EACL,KAAK,oBAAoB,EAI1B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEnF,OAAO,KAAK,EAGV,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EAEzB,MAAM,oCAAoC,CAAC;AAO5C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,wBAAwB,EAAE,CAAC;IACvC,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAQD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,GAAG,c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AAS,OAAO,GAAG,KAAK,EAEpC,MAAM,EAAE,IAAI,EACZ,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,GAC5D,iBAAiB,EAAE,CAmDrB"}
|
|
@@ -105,7 +105,7 @@ function hasPaginationFields(schema) {
|
|
|
105
105
|
* Create a validation middleware for request validation.
|
|
106
106
|
* Returns 422 Unprocessable Entity on validation failure (instead of Hono's default 400).
|
|
107
107
|
*
|
|
108
|
-
* @param type - The validation target ('json' for body, 'query', or 'param')
|
|
108
|
+
* @param type - The validation target ('json' or 'form' for body, 'query', or 'param')
|
|
109
109
|
* @param schema - The Valibot schema to validate against
|
|
110
110
|
*/
|
|
111
111
|
function createValidationMiddleware(type, schema) {
|
|
@@ -185,14 +185,16 @@ export function route(router, config) {
|
|
|
185
185
|
// Detect pagination from query schema
|
|
186
186
|
const hasPagination = hasPaginationFields(config.query);
|
|
187
187
|
// Add OpenAPI metadata
|
|
188
|
-
|
|
188
|
+
if (!config.openapi?.exclude) {
|
|
189
|
+
middlewares.push(buildOpenAPIMiddleware(config, openAPIContext, hasPagination));
|
|
190
|
+
}
|
|
189
191
|
// Add custom middleware (e.g., auth) before validation
|
|
190
192
|
if (config.middleware) {
|
|
191
193
|
middlewares.push(...config.middleware);
|
|
192
194
|
}
|
|
193
195
|
// Add validation middleware (returns 422 instead of Hono's default 400)
|
|
194
196
|
if (config.body) {
|
|
195
|
-
middlewares.push(createValidationMiddleware('json', config.body));
|
|
197
|
+
middlewares.push(createValidationMiddleware(config.bodyType || 'json', config.body));
|
|
196
198
|
}
|
|
197
199
|
if (config.query) {
|
|
198
200
|
middlewares.push(createValidationMiddleware('query', config.query));
|
|
@@ -202,7 +204,7 @@ export function route(router, config) {
|
|
|
202
204
|
}
|
|
203
205
|
// Add handler wrapper
|
|
204
206
|
middlewares.push(async (c) => {
|
|
205
|
-
const routeContext = buildRouteContext(c);
|
|
207
|
+
const routeContext = buildRouteContext(c, config);
|
|
206
208
|
const result = await config.handler(routeContext);
|
|
207
209
|
return handleResponse(result, config.responses, config.serialization, config.strictTypes, config.summary, c);
|
|
208
210
|
});
|
|
@@ -334,13 +336,14 @@ function buildOpenAPIMiddleware(config, openAPIContext, hasPagination) {
|
|
|
334
336
|
const security = config.public
|
|
335
337
|
? []
|
|
336
338
|
: openAPIContext.securitySchemes.map((scheme) => ({ [scheme]: [] }));
|
|
337
|
-
// Extract responseHeaders from openapi config to avoid passing it to hono-openapi
|
|
338
|
-
const { responseHeaders: _responseHeaders, ...restOpenapi } = config.openapi ?? {};
|
|
339
|
+
// Extract responseHeaders and exclude from openapi config to avoid passing it to hono-openapi
|
|
340
|
+
const { responseHeaders: _responseHeaders, exclude: _exclude, docs, ...restOpenapi } = config.openapi ?? {};
|
|
339
341
|
const openApiConfig = {
|
|
340
342
|
operationId: config.operationId || config.summary,
|
|
341
343
|
tags: config.tags,
|
|
342
344
|
summary: config.summary,
|
|
343
345
|
description: config.description,
|
|
346
|
+
externalDocs: docs,
|
|
344
347
|
responses: responses,
|
|
345
348
|
security,
|
|
346
349
|
...restOpenapi,
|
|
@@ -417,7 +420,7 @@ function buildOpenAPIResponses(config, openAPIContext, hasPagination) {
|
|
|
417
420
|
}
|
|
418
421
|
return responses;
|
|
419
422
|
}
|
|
420
|
-
function buildRouteContext(c) {
|
|
423
|
+
function buildRouteContext(c, config) {
|
|
421
424
|
const req = c.req;
|
|
422
425
|
// Spread all context variables (from ContextVariableMap)
|
|
423
426
|
// This includes session, ability, role, and any other middleware-added variables
|
|
@@ -425,7 +428,7 @@ function buildRouteContext(c) {
|
|
|
425
428
|
// The type will be narrowed at the call site based on the route's public setting
|
|
426
429
|
return {
|
|
427
430
|
...c.var,
|
|
428
|
-
body: req.valid('json'),
|
|
431
|
+
body: req.valid(config.bodyType || 'json'),
|
|
429
432
|
query: req.valid('query'),
|
|
430
433
|
params: req.valid('param'),
|
|
431
434
|
services: c.get('services') || {},
|
|
@@ -1 +1 @@
|
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 'openapi-types';
|
|
|
12
12
|
export { type Config, type ConfigOptions, type ConfigProvider, ConfigValidationException, createConfig, type DotenvProviderOptions, dotenvProvider, type EnvProviderOptions, envProvider, objectProvider, parseArray, parseBoolean, parseJson, type SsmProviderOptions, ssmProvider, toCamelCase, toSnakeCase, validateConfig, } from './config/index.js';
|
|
13
13
|
export { bootstrap } from './core/bootstrap.js';
|
|
14
14
|
export { defineModule } from './core/module.js';
|
|
15
|
-
export type { BootstrapOptions, BootstrapResult, Constructor, Environment, LoggerOptions, MiddlewareOptions, ModuleConfig, OpenAPIDocumentation, OpenAPIOptions, OpenAPIProcessorContext, OpenAPIResponseObject, OpenAPIResponseProcessor, ProviderConfig, RateLimitOptions, RateLimitStorage, RouteConfigExtensions, ServiceScope, } from './core/types.js';
|
|
15
|
+
export type { BootstrapOptions, BootstrapResult, Constructor, Environment, LoggerOptions, MiddlewareOptions, ModuleConfig, OnModuleDestroy, OnModuleInit, OpenAPIDocumentation, OpenAPIOptions, OpenAPIProcessorContext, OpenAPIResponseObject, OpenAPIResponseProcessor, ProviderConfig, RateLimitOptions, RateLimitStorage, RouteConfigExtensions, ServiceScope, } from './core/types.js';
|
|
16
16
|
export { createErrorHandler, defaultErrorHandler } from './http/error-handler.js';
|
|
17
17
|
export { type ErrorResponse, ErrorResponseDto, type ValidationErrorResponse, ValidationErrorResponseDto, type ValidationIssue, ValidationIssueDto, } from './http/error-response.dto.js';
|
|
18
18
|
export { BadGatewayException, BadRequestException, ConflictException, DomainException, ForbiddenException, GatewayTimeoutException, GoneException, InternalServerErrorException, LockedException, MethodNotAllowedException, NotFoundException, NotImplementedException, PayloadTooLargeException, PreconditionFailedException, RequestTimeoutException, ServiceUnavailableException, TooManyRequestsException, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, ValidationException, } from './http/errors.js';
|