glasswork 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/config/config-service.d.ts +101 -0
- package/dist/config/config-service.d.ts.map +1 -0
- package/dist/config/config-service.js +164 -0
- package/dist/config/config-service.js.map +1 -0
- package/dist/config/helpers.d.ts +101 -0
- package/dist/config/helpers.d.ts.map +1 -0
- package/dist/config/helpers.js +122 -0
- package/dist/config/helpers.js.map +1 -0
- package/dist/config/index.d.ts +39 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +41 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/providers.d.ts +163 -0
- package/dist/config/providers.d.ts.map +1 -0
- package/dist/config/providers.js +188 -0
- package/dist/config/providers.js.map +1 -0
- package/dist/config/types.d.ts +98 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +7 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/bootstrap.js +9 -3
- package/dist/core/bootstrap.js.map +1 -1
- package/dist/core/types.d.ts +2 -1
- 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.map +1 -0
- package/dist/http/errors.d.ts +39 -0
- package/dist/http/errors.d.ts.map +1 -1
- package/dist/http/errors.js +78 -0
- package/dist/http/errors.js.map +1 -1
- package/dist/http/route-helpers.d.ts +39 -13
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js +45 -2
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/middleware/rate-limit.d.ts.map +1 -1
- package/dist/middleware/rate-limit.js +2 -16
- package/dist/middleware/rate-limit.js.map +1 -1
- package/dist/openapi/openapi.d.ts +1 -1
- package/dist/openapi/openapi.d.ts.map +1 -1
- package/dist/openapi/openapi.js +21 -3
- package/dist/openapi/openapi.js.map +1 -1
- package/package.json +22 -1
- package/dist/bootstrap.d.ts +0 -55
- package/dist/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap.js +0 -359
- package/dist/bootstrap.js.map +0 -1
- package/dist/environment.d.ts +0 -21
- package/dist/environment.d.ts.map +0 -1
- package/dist/environment.js +0 -29
- package/dist/environment.js.map +0 -1
- package/dist/error-handler.d.ts +0 -33
- package/dist/error-handler.d.ts.map +0 -1
- package/dist/error-handler.js +0 -53
- package/dist/error-handler.js.map +0 -1
- package/dist/errors.d.ts +0 -36
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -65
- package/dist/errors.js.map +0 -1
- package/dist/get-client-ip.d.ts +0 -24
- package/dist/get-client-ip.d.ts.map +0 -1
- package/dist/get-client-ip.js +0 -49
- package/dist/get-client-ip.js.map +0 -1
- package/dist/logger.d.ts +0 -37
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -52
- package/dist/logger.js.map +0 -1
- package/dist/module.d.ts +0 -21
- package/dist/module.d.ts.map +0 -1
- package/dist/module.js +0 -85
- package/dist/module.js.map +0 -1
- package/dist/omit.d.ts +0 -20
- package/dist/omit.d.ts.map +0 -1
- package/dist/omit.js +0 -28
- package/dist/omit.js.map +0 -1
- package/dist/openapi-defaults.d.ts +0 -11
- package/dist/openapi-defaults.d.ts.map +0 -1
- package/dist/openapi-defaults.js +0 -127
- package/dist/openapi-defaults.js.map +0 -1
- package/dist/openapi-hooks.d.ts +0 -14
- package/dist/openapi-hooks.d.ts.map +0 -1
- package/dist/openapi-hooks.js +0 -80
- package/dist/openapi-hooks.js.map +0 -1
- package/dist/openapi.d.ts +0 -24
- package/dist/openapi.d.ts.map +0 -1
- package/dist/openapi.js +0 -106
- package/dist/openapi.js.map +0 -1
- package/dist/pagination.d.ts +0 -48
- package/dist/pagination.d.ts.map +0 -1
- package/dist/pagination.js +0 -43
- package/dist/pagination.js.map +0 -1
- package/dist/pick.d.ts +0 -20
- package/dist/pick.d.ts.map +0 -1
- package/dist/pick.js +0 -28
- package/dist/pick.js.map +0 -1
- package/dist/rate-limit.d.ts +0 -7
- package/dist/rate-limit.d.ts.map +0 -1
- package/dist/rate-limit.js +0 -180
- package/dist/rate-limit.js.map +0 -1
- package/dist/route-helpers.d.ts +0 -172
- package/dist/route-helpers.d.ts.map +0 -1
- package/dist/route-helpers.js +0 -249
- package/dist/route-helpers.js.map +0 -1
- package/dist/serialize-dates.d.ts +0 -27
- package/dist/serialize-dates.d.ts.map +0 -1
- package/dist/serialize-dates.js +0 -39
- package/dist/serialize-dates.js.map +0 -1
- package/dist/testing.d.ts +0 -87
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -94
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -273
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -9
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -31
- package/dist/utils.js.map +0 -1
- /package/dist/{types.js → hooks/types.js} +0 -0
|
@@ -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":""}
|
package/dist/http/errors.d.ts
CHANGED
|
@@ -29,6 +29,45 @@ export declare class BadRequestException extends DomainException {
|
|
|
29
29
|
export declare class TooManyRequestsException extends DomainException {
|
|
30
30
|
constructor(message?: string);
|
|
31
31
|
}
|
|
32
|
+
export declare class MethodNotAllowedException extends DomainException {
|
|
33
|
+
constructor(message?: string);
|
|
34
|
+
}
|
|
35
|
+
export declare class RequestTimeoutException extends DomainException {
|
|
36
|
+
constructor(message?: string);
|
|
37
|
+
}
|
|
38
|
+
export declare class GoneException extends DomainException {
|
|
39
|
+
constructor(message?: string);
|
|
40
|
+
}
|
|
41
|
+
export declare class PayloadTooLargeException extends DomainException {
|
|
42
|
+
constructor(message?: string);
|
|
43
|
+
}
|
|
44
|
+
export declare class UnsupportedMediaTypeException extends DomainException {
|
|
45
|
+
constructor(message?: string);
|
|
46
|
+
}
|
|
47
|
+
export declare class UnprocessableEntityException extends DomainException {
|
|
48
|
+
constructor(message?: string);
|
|
49
|
+
}
|
|
50
|
+
export declare class LockedException extends DomainException {
|
|
51
|
+
constructor(message?: string);
|
|
52
|
+
}
|
|
53
|
+
export declare class PreconditionFailedException extends DomainException {
|
|
54
|
+
constructor(message?: string);
|
|
55
|
+
}
|
|
56
|
+
export declare class InternalServerErrorException extends DomainException {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
export declare class NotImplementedException extends DomainException {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
export declare class BadGatewayException extends DomainException {
|
|
63
|
+
constructor(message?: string);
|
|
64
|
+
}
|
|
65
|
+
export declare class ServiceUnavailableException extends DomainException {
|
|
66
|
+
constructor(message?: string);
|
|
67
|
+
}
|
|
68
|
+
export declare class GatewayTimeoutException extends DomainException {
|
|
69
|
+
constructor(message?: string);
|
|
70
|
+
}
|
|
32
71
|
/**
|
|
33
72
|
* Map error codes to HTTP status codes
|
|
34
73
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,IAAI,EAAE,MAAM;gBAD5B,OAAO,EAAE,MA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AChD,OAAO,SAAuB;CAG3C;AAED,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,SAAoB;CAGxC;AAED,qBAAa,aAAc,SAAQ,eAAe;gBACpC,OAAO,SAAS;CAG7B;AAED,qBAAa,wBAAyB,SAAQ,eAAe;gBAC/C,OAAO,SAAsB;CAG1C;AAED,qBAAa,6BAA8B,SAAQ,eAAe;gBACpD,OAAO,SAA2B;CAG/C;AAED,qBAAa,4BAA6B,SAAQ,eAAe;gBACnD,OAAO,SAAyB;CAG7C;AAED,qBAAa,eAAgB,SAAQ,eAAe;gBACtC,OAAO,SAAW;CAG/B;AAED,qBAAa,2BAA4B,SAAQ,eAAe;gBAClD,OAAO,SAAwB;CAG5C;AAED,qBAAa,4BAA6B,SAAQ,eAAe;gBACnD,OAAO,SAA0B;CAG9C;AAED,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,SAAoB;CAGxC;AAED,qBAAa,mBAAoB,SAAQ,eAAe;gBAC1C,OAAO,SAAgB;CAGpC;AAED,qBAAa,2BAA4B,SAAQ,eAAe;gBAClD,OAAO,SAAwB;CAG5C;AAED,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,SAAoB;CAGxC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAyB/D"}
|
package/dist/http/errors.js
CHANGED
|
@@ -47,6 +47,71 @@ export class TooManyRequestsException extends DomainException {
|
|
|
47
47
|
super(message, 'TOO_MANY_REQUESTS');
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
export class MethodNotAllowedException extends DomainException {
|
|
51
|
+
constructor(message = 'Method not allowed') {
|
|
52
|
+
super(message, 'METHOD_NOT_ALLOWED');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class RequestTimeoutException extends DomainException {
|
|
56
|
+
constructor(message = 'Request timeout') {
|
|
57
|
+
super(message, 'REQUEST_TIMEOUT');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class GoneException extends DomainException {
|
|
61
|
+
constructor(message = 'Gone') {
|
|
62
|
+
super(message, 'GONE');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class PayloadTooLargeException extends DomainException {
|
|
66
|
+
constructor(message = 'Payload too large') {
|
|
67
|
+
super(message, 'PAYLOAD_TOO_LARGE');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class UnsupportedMediaTypeException extends DomainException {
|
|
71
|
+
constructor(message = 'Unsupported media type') {
|
|
72
|
+
super(message, 'UNSUPPORTED_MEDIA_TYPE');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class UnprocessableEntityException extends DomainException {
|
|
76
|
+
constructor(message = 'Unprocessable entity') {
|
|
77
|
+
super(message, 'UNPROCESSABLE_ENTITY');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export class LockedException extends DomainException {
|
|
81
|
+
constructor(message = 'Locked') {
|
|
82
|
+
super(message, 'LOCKED');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export class PreconditionFailedException extends DomainException {
|
|
86
|
+
constructor(message = 'Precondition failed') {
|
|
87
|
+
super(message, 'PRECONDITION_FAILED');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export class InternalServerErrorException extends DomainException {
|
|
91
|
+
constructor(message = 'Internal server error') {
|
|
92
|
+
super(message, 'INTERNAL_SERVER_ERROR');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export class NotImplementedException extends DomainException {
|
|
96
|
+
constructor(message = 'Not implemented') {
|
|
97
|
+
super(message, 'NOT_IMPLEMENTED');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export class BadGatewayException extends DomainException {
|
|
101
|
+
constructor(message = 'Bad gateway') {
|
|
102
|
+
super(message, 'BAD_GATEWAY');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export class ServiceUnavailableException extends DomainException {
|
|
106
|
+
constructor(message = 'Service unavailable') {
|
|
107
|
+
super(message, 'SERVICE_UNAVAILABLE');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class GatewayTimeoutException extends DomainException {
|
|
111
|
+
constructor(message = 'Gateway timeout') {
|
|
112
|
+
super(message, 'GATEWAY_TIMEOUT');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
50
115
|
/**
|
|
51
116
|
* Map error codes to HTTP status codes
|
|
52
117
|
*/
|
|
@@ -56,9 +121,22 @@ export function getStatusCodeFromErrorCode(code) {
|
|
|
56
121
|
UNAUTHORIZED: 401,
|
|
57
122
|
FORBIDDEN: 403,
|
|
58
123
|
NOT_FOUND: 404,
|
|
124
|
+
METHOD_NOT_ALLOWED: 405,
|
|
125
|
+
REQUEST_TIMEOUT: 408,
|
|
59
126
|
CONFLICT: 409,
|
|
127
|
+
GONE: 410,
|
|
128
|
+
PRECONDITION_FAILED: 412,
|
|
129
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
130
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
60
131
|
VALIDATION_ERROR: 422,
|
|
132
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
133
|
+
LOCKED: 423,
|
|
61
134
|
TOO_MANY_REQUESTS: 429,
|
|
135
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
136
|
+
NOT_IMPLEMENTED: 501,
|
|
137
|
+
BAD_GATEWAY: 502,
|
|
138
|
+
SERVICE_UNAVAILABLE: 503,
|
|
139
|
+
GATEWAY_TIMEOUT: 504,
|
|
62
140
|
};
|
|
63
141
|
return codeMap[code] || 500;
|
|
64
142
|
}
|
package/dist/http/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAGtB;IAFlB,YACE,OAAe,EACC,IAAY;QAE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eAAe,EAAE,GAAG;QACpB,WAAW,EAAE,GAAG;QAChB,mBAAmB,EAAE,GAAG;QACxB,eAAe,EAAE,GAAG;KACrB,CAAC;IAEF,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;AAC9B,CAAC"}
|
|
@@ -15,6 +15,19 @@ export declare function setGlobalResponseHooks(hooks: OpenAPIResponseHook[]): vo
|
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export declare function getGlobalResponseHooks(): OpenAPIResponseHook[];
|
|
18
|
+
/**
|
|
19
|
+
* Set the global OpenAPI security schemes.
|
|
20
|
+
* This is called during bootstrap and makes security schemes available to route definitions.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function setGlobalSecuritySchemes(schemes: string[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current global OpenAPI security schemes.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function getGlobalSecuritySchemes(): string[];
|
|
18
31
|
/**
|
|
19
32
|
* Valibot schema type (compatible with both sync and async schemas)
|
|
20
33
|
*/
|
|
@@ -24,16 +37,17 @@ export type ValibotSchema = BaseSchema<unknown, unknown, BaseIssue<unknown>> | B
|
|
|
24
37
|
*/
|
|
25
38
|
type InferSchemaType<T> = T extends ValibotSchema ? InferOutput<T> : never;
|
|
26
39
|
/**
|
|
27
|
-
* Helper type to
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
* Helper type to extract and create a union of all 2xx response types
|
|
41
|
+
*/
|
|
42
|
+
type InferResponseUnion<TResponses> = {
|
|
43
|
+
[K in keyof TResponses]: K extends 200 | 201 ? TResponses[K] extends ValibotSchema ? InferOutput<TResponses[K]> : never : never;
|
|
44
|
+
}[keyof TResponses];
|
|
45
|
+
/**
|
|
46
|
+
* Helper type to infer the response type from all 2xx status code schemas
|
|
47
|
+
* Returns a union type of all defined 2xx responses (200, 201, etc.)
|
|
48
|
+
* Falls back to unknown if no 2xx responses are defined
|
|
31
49
|
*/
|
|
32
|
-
type InferResponseType<
|
|
33
|
-
200: infer TSchema;
|
|
34
|
-
} ? TSchema extends ValibotSchema ? InferOutput<TSchema> : unknown : T extends {
|
|
35
|
-
201: infer TSchema;
|
|
36
|
-
} ? TSchema extends ValibotSchema ? InferOutput<TSchema> : unknown : unknown;
|
|
50
|
+
type InferResponseType<TResponses> = InferResponseUnion<TResponses> extends never ? unknown : InferResponseUnion<TResponses>;
|
|
37
51
|
/**
|
|
38
52
|
* HTTP status codes with descriptions
|
|
39
53
|
*/
|
|
@@ -108,9 +122,6 @@ export interface RouteConfig<TBody extends ValibotSchema | undefined = undefined
|
|
|
108
122
|
/**
|
|
109
123
|
* Route handler - body and return types are automatically inferred from schemas
|
|
110
124
|
* Session is required by default (unless public: true)
|
|
111
|
-
*
|
|
112
|
-
* Prisma client extension converts Date → string at the database layer,
|
|
113
|
-
* so handler return types match the response schema output type.
|
|
114
125
|
*/
|
|
115
126
|
handler: (context: RouteContext<TBody extends ValibotSchema ? InferSchemaType<TBody> : never, TPublic extends true ? false : true>) => Promise<InferResponseType<TResponses>> | InferResponseType<TResponses>;
|
|
116
127
|
}
|
|
@@ -153,10 +164,11 @@ export interface RouteContext<TBody = never, TSessionRequired extends boolean =
|
|
|
153
164
|
*
|
|
154
165
|
* Type inference works automatically:
|
|
155
166
|
* - Body type is inferred from the `body` schema
|
|
156
|
-
* - Return type is inferred
|
|
167
|
+
* - Return type is inferred as a union of all 2xx response schemas (200, 201, etc.)
|
|
157
168
|
*
|
|
158
169
|
* @example
|
|
159
170
|
* ```typescript
|
|
171
|
+
* // Single response type
|
|
160
172
|
* route({
|
|
161
173
|
* body: StartSessionDto,
|
|
162
174
|
* responses: { 200: StartSessionResponseDto },
|
|
@@ -165,6 +177,20 @@ export interface RouteContext<TBody = never, TSessionRequired extends boolean =
|
|
|
165
177
|
* return { email: body.email }; // Must match StartSessionResponseDto
|
|
166
178
|
* }
|
|
167
179
|
* })
|
|
180
|
+
*
|
|
181
|
+
* // Union response type (multiple 2xx responses)
|
|
182
|
+
* route({
|
|
183
|
+
* body: LoginDto,
|
|
184
|
+
* responses: {
|
|
185
|
+
* 200: MfaRequiredDto,
|
|
186
|
+
* 201: SessionDto
|
|
187
|
+
* },
|
|
188
|
+
* handler: async ({ body }) => {
|
|
189
|
+
* // Return type is: MfaRequiredDto | SessionDto
|
|
190
|
+
* if (needsMfa) return { mfaRequired: true, methods: ['totp'] };
|
|
191
|
+
* return { sessionId: '123', token: 'abc' };
|
|
192
|
+
* }
|
|
193
|
+
* })
|
|
168
194
|
* ```
|
|
169
195
|
*/
|
|
170
196
|
export declare function route<TBody extends ValibotSchema | undefined = undefined, TResponses extends Partial<Record<keyof typeof STATUS_DESCRIPTIONS, ValibotSchema | undefined>> = Record<never, never>, TPublic extends boolean = false>(config: RouteConfig<TBody, TResponses, TPublic>): MiddlewareHandler[];
|
|
@@ -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;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACnF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;
|
|
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;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,KAA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AE,CA+DtE"}
|
|
@@ -6,6 +6,12 @@ import { getClientIp } from '../utils/get-client-ip.js';
|
|
|
6
6
|
* Set during bootstrap and used when defining routes.
|
|
7
7
|
*/
|
|
8
8
|
let globalResponseHooks = [];
|
|
9
|
+
/**
|
|
10
|
+
* Global storage for OpenAPI security scheme names.
|
|
11
|
+
* Set during bootstrap from the documentation's securitySchemes.
|
|
12
|
+
* Used when building route security (public: false routes).
|
|
13
|
+
*/
|
|
14
|
+
let globalSecuritySchemes = [];
|
|
9
15
|
/**
|
|
10
16
|
* Set the global OpenAPI response hooks.
|
|
11
17
|
* This is called during bootstrap and makes hooks available to route definitions.
|
|
@@ -23,6 +29,23 @@ export function setGlobalResponseHooks(hooks) {
|
|
|
23
29
|
export function getGlobalResponseHooks() {
|
|
24
30
|
return globalResponseHooks;
|
|
25
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Set the global OpenAPI security schemes.
|
|
34
|
+
* This is called during bootstrap and makes security schemes available to route definitions.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export function setGlobalSecuritySchemes(schemes) {
|
|
39
|
+
globalSecuritySchemes = schemes;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the current global OpenAPI security schemes.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function getGlobalSecuritySchemes() {
|
|
47
|
+
return globalSecuritySchemes;
|
|
48
|
+
}
|
|
26
49
|
/**
|
|
27
50
|
* HTTP status codes with descriptions
|
|
28
51
|
*/
|
|
@@ -66,10 +89,11 @@ export function createRoutes(factory) {
|
|
|
66
89
|
*
|
|
67
90
|
* Type inference works automatically:
|
|
68
91
|
* - Body type is inferred from the `body` schema
|
|
69
|
-
* - Return type is inferred
|
|
92
|
+
* - Return type is inferred as a union of all 2xx response schemas (200, 201, etc.)
|
|
70
93
|
*
|
|
71
94
|
* @example
|
|
72
95
|
* ```typescript
|
|
96
|
+
* // Single response type
|
|
73
97
|
* route({
|
|
74
98
|
* body: StartSessionDto,
|
|
75
99
|
* responses: { 200: StartSessionResponseDto },
|
|
@@ -78,6 +102,20 @@ export function createRoutes(factory) {
|
|
|
78
102
|
* return { email: body.email }; // Must match StartSessionResponseDto
|
|
79
103
|
* }
|
|
80
104
|
* })
|
|
105
|
+
*
|
|
106
|
+
* // Union response type (multiple 2xx responses)
|
|
107
|
+
* route({
|
|
108
|
+
* body: LoginDto,
|
|
109
|
+
* responses: {
|
|
110
|
+
* 200: MfaRequiredDto,
|
|
111
|
+
* 201: SessionDto
|
|
112
|
+
* },
|
|
113
|
+
* handler: async ({ body }) => {
|
|
114
|
+
* // Return type is: MfaRequiredDto | SessionDto
|
|
115
|
+
* if (needsMfa) return { mfaRequired: true, methods: ['totp'] };
|
|
116
|
+
* return { sessionId: '123', token: 'abc' };
|
|
117
|
+
* }
|
|
118
|
+
* })
|
|
81
119
|
* ```
|
|
82
120
|
*/
|
|
83
121
|
export function route(config) {
|
|
@@ -131,13 +169,18 @@ export function route(config) {
|
|
|
131
169
|
}
|
|
132
170
|
function buildOpenAPIMiddleware(config) {
|
|
133
171
|
const responses = buildOpenAPIResponses(config);
|
|
172
|
+
// Build security requirement based on global security schemes
|
|
173
|
+
// Public routes have no security, authenticated routes use all available schemes
|
|
174
|
+
const security = config.public
|
|
175
|
+
? []
|
|
176
|
+
: getGlobalSecuritySchemes().map((scheme) => ({ [scheme]: [] }));
|
|
134
177
|
const openApiConfig = {
|
|
135
178
|
operationId: config.operationId || config.summary,
|
|
136
179
|
tags: config.tags,
|
|
137
180
|
summary: config.summary,
|
|
138
181
|
description: config.description,
|
|
139
182
|
responses: responses,
|
|
140
|
-
security
|
|
183
|
+
security,
|
|
141
184
|
...(config.paginate && { parameters: buildPaginationParameters() }),
|
|
142
185
|
...config.openapi,
|
|
143
186
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.js","sourceRoot":"","sources":["../../src/http/route-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;GAGG;AACH,IAAI,mBAAmB,GAA0B,EAAE,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAA4B;IACjE,mBAAmB,GAAG,KAAK,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,mBAAmB,CAAC;AAC7B,CAAC;
|
|
1
|
+
{"version":3,"file":"route-helpers.js","sourceRoot":"","sources":["../../src/http/route-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;GAGG;AACH,IAAI,mBAAmB,GAA0B,EAAE,CAAC;AAEpD;;;;GAIG;AACH,IAAI,qBAAqB,GAAa,EAAE,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAA4B;IACjE,mBAAmB,GAAG,KAAK,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAiB;IACxD,qBAAqB,GAAG,OAAO,CAAC;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAmCD;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,GAAG,EAAE,SAAS;I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
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Glasswork - A transparent,
|
|
2
|
+
* Glasswork - A transparent, serverless-optimized web framework for building
|
|
3
|
+
* OpenAPI-compliant REST APIs.
|
|
3
4
|
*
|
|
4
|
-
* Built on Hono, Awilix, and
|
|
5
|
+
* Built on Hono, Awilix, and Valibot.
|
|
5
6
|
*
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
*/
|
|
8
9
|
export type { AwilixContainer } from 'awilix';
|
|
9
10
|
export type { ErrorHandler, Hono } from 'hono';
|
|
10
11
|
export type { OpenAPIV3 } from 'openapi-types';
|
|
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';
|
|
11
13
|
export { bootstrap } from './core/bootstrap.js';
|
|
12
14
|
export { defineModule } from './core/module.js';
|
|
13
15
|
export type { BootstrapOptions, BootstrapResult, Constructor, Environment, LoggerOptions, MiddlewareOptions, ModuleConfig, OpenAPIDocumentation, OpenAPIOptions, OpenAPIResponseHook, ProviderConfig, RateLimitOptions, RateLimitStorage, ServiceScope, } from './core/types.js';
|
|
14
16
|
export { createErrorHandler, defaultErrorHandler } from './http/error-handler.js';
|
|
15
17
|
export { type ErrorResponse, ErrorResponseDto, type ValidationErrorResponse, ValidationErrorResponseDto, type ValidationIssue, ValidationIssueDto, } from './http/error-response.dto.js';
|
|
16
|
-
export { BadRequestException, ConflictException, DomainException, ForbiddenException, NotFoundException, TooManyRequestsException, UnauthorizedException, ValidationException, } from './http/errors.js';
|
|
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';
|
|
17
19
|
export type { RouteConfig, RouteContext, RouteFactory, ValibotSchema, } from './http/route-helpers.js';
|
|
18
20
|
export { createRoutes, route } from './http/route-helpers.js';
|
|
19
21
|
export { createRateLimitMiddleware } from './middleware/rate-limit.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EACL,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,yBAAyB,EACzB,YAAY,EACZ,KAAK,qBAAqB,EAC1B,cAAc,EACd,KAAK,kBAAkB,EACvB,WAAW,EACX,cAAc,EACd,UAAU,EACV,YAAY,EACZ,SAAS,EACT,KAAK,kBAAkB,EACvB,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,GACb,MAAM,i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E,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Glasswork - A transparent,
|
|
2
|
+
* Glasswork - A transparent, serverless-optimized web framework for building
|
|
3
|
+
* OpenAPI-compliant REST APIs.
|
|
3
4
|
*
|
|
4
|
-
* Built on Hono, Awilix, and
|
|
5
|
+
* Built on Hono, Awilix, and Valibot.
|
|
5
6
|
*
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
*/
|
|
9
|
+
// Configuration
|
|
10
|
+
export { ConfigValidationException, createConfig, dotenvProvider, envProvider, objectProvider, parseArray, parseBoolean, parseJson, ssmProvider, toCamelCase, toSnakeCase, validateConfig, } from './config/index.js';
|
|
8
11
|
// Core framework
|
|
9
12
|
export { bootstrap } from './core/bootstrap.js';
|
|
10
13
|
export { defineModule } from './core/module.js';
|
|
14
|
+
// HTTP/Routing
|
|
11
15
|
export { createErrorHandler, defaultErrorHandler } from './http/error-handler.js';
|
|
12
16
|
export { ErrorResponseDto, ValidationErrorResponseDto, ValidationIssueDto, } from './http/error-response.dto.js';
|
|
13
|
-
export { BadRequestException, ConflictException, DomainException, ForbiddenException, NotFoundException, TooManyRequestsException, UnauthorizedException, ValidationException, } from './http/errors.js';
|
|
17
|
+
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';
|
|
14
18
|
export { createRoutes, route } from './http/route-helpers.js';
|
|
15
19
|
// Middleware
|
|
16
20
|
export { createRateLimitMiddleware } from './middleware/rate-limit.js';
|
|
21
|
+
// OpenAPI
|
|
17
22
|
export { defaultOpenAPIComponents } from './openapi/defaults.js';
|
|
18
23
|
export { createCorsHeadersHook, createPaginationHeadersHook, createRateLimitHeadersHook, } from './openapi/hooks.js';
|
|
19
|
-
// OpenAPI
|
|
20
24
|
export { configureOpenAPI } from './openapi/openapi.js';
|
|
21
|
-
export { deepMerge } from './utils/deep-merge.js';
|
|
22
25
|
// Utilities
|
|
26
|
+
export { deepMerge } from './utils/deep-merge.js';
|
|
23
27
|
export { isDevelopment, isLambda, isProduction, isTest } from './utils/environment.js';
|
|
24
28
|
export { getClientIp } from './utils/get-client-ip.js';
|
|
25
29
|
export { createLogger, createPlainLogger, defaultLogger } from './utils/logger.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,gBAAgB;AAChB,OAAO,EAIL,yBAAyB,EACzB,YAAY,EAEZ,cAAc,EAEd,WAAW,EACX,cAAc,EACd,UAAU,EACV,YAAY,EACZ,SAAS,EAET,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,iBAAiB;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAkBhD,eAAe;A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I,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAkJzD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,GAAG,iBAAiB,CAuDtF"}
|