glasswork 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/dist/bootstrap.d.ts +55 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +359 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/core/bootstrap.d.ts +55 -0
- package/dist/core/bootstrap.d.ts.map +1 -0
- package/dist/core/bootstrap.js +329 -0
- package/dist/core/bootstrap.js.map +1 -0
- package/dist/core/module.d.ts +21 -0
- package/dist/core/module.d.ts.map +1 -0
- package/dist/core/module.js +85 -0
- package/dist/core/module.js.map +1 -0
- package/dist/core/types.d.ts +273 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/environment.d.ts +21 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +29 -0
- package/dist/environment.js.map +1 -0
- package/dist/error-handler.d.ts +33 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +53 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -0
- package/dist/get-client-ip.d.ts +24 -0
- package/dist/get-client-ip.d.ts.map +1 -0
- package/dist/get-client-ip.js +49 -0
- package/dist/get-client-ip.js.map +1 -0
- package/dist/http/error-handler.d.ts +33 -0
- package/dist/http/error-handler.d.ts.map +1 -0
- package/dist/http/error-handler.js +55 -0
- package/dist/http/error-handler.js.map +1 -0
- package/dist/http/errors.d.ts +36 -0
- package/dist/http/errors.d.ts.map +1 -0
- package/dist/http/errors.js +65 -0
- package/dist/http/errors.js.map +1 -0
- package/dist/http/route-helpers.d.ts +172 -0
- package/dist/http/route-helpers.d.ts.map +1 -0
- package/dist/http/route-helpers.js +249 -0
- package/dist/http/route-helpers.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +37 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +52 -0
- package/dist/logger.js.map +1 -0
- package/dist/middleware/rate-limit.d.ts +7 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/middleware/rate-limit.js +182 -0
- package/dist/middleware/rate-limit.js.map +1 -0
- package/dist/module.d.ts +21 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +85 -0
- package/dist/module.js.map +1 -0
- package/dist/omit.d.ts +20 -0
- package/dist/omit.d.ts.map +1 -0
- package/dist/omit.js +28 -0
- package/dist/omit.js.map +1 -0
- package/dist/openapi/defaults.d.ts +11 -0
- package/dist/openapi/defaults.d.ts.map +1 -0
- package/dist/openapi/defaults.js +127 -0
- package/dist/openapi/defaults.js.map +1 -0
- package/dist/openapi/hooks.d.ts +14 -0
- package/dist/openapi/hooks.d.ts.map +1 -0
- package/dist/openapi/hooks.js +80 -0
- package/dist/openapi/hooks.js.map +1 -0
- package/dist/openapi/openapi.d.ts +24 -0
- package/dist/openapi/openapi.d.ts.map +1 -0
- package/dist/openapi/openapi.js +108 -0
- package/dist/openapi/openapi.js.map +1 -0
- package/dist/openapi-defaults.d.ts +11 -0
- package/dist/openapi-defaults.d.ts.map +1 -0
- package/dist/openapi-defaults.js +127 -0
- package/dist/openapi-defaults.js.map +1 -0
- package/dist/openapi-hooks.d.ts +14 -0
- package/dist/openapi-hooks.d.ts.map +1 -0
- package/dist/openapi-hooks.js +80 -0
- package/dist/openapi-hooks.js.map +1 -0
- package/dist/openapi.d.ts +24 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +106 -0
- package/dist/openapi.js.map +1 -0
- package/dist/pagination.d.ts +48 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +43 -0
- package/dist/pagination.js.map +1 -0
- package/dist/pick.d.ts +20 -0
- package/dist/pick.d.ts.map +1 -0
- package/dist/pick.js +28 -0
- package/dist/pick.js.map +1 -0
- package/dist/rate-limit.d.ts +7 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +180 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/route-helpers.d.ts +172 -0
- package/dist/route-helpers.d.ts.map +1 -0
- package/dist/route-helpers.js +249 -0
- package/dist/route-helpers.js.map +1 -0
- package/dist/serialize-dates.d.ts +27 -0
- package/dist/serialize-dates.d.ts.map +1 -0
- package/dist/serialize-dates.js +39 -0
- package/dist/serialize-dates.js.map +1 -0
- package/dist/testing.d.ts +87 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +94 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +273 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +5 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +21 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/utils/environment.d.ts +21 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/environment.js +29 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/get-client-ip.d.ts +24 -0
- package/dist/utils/get-client-ip.d.ts.map +1 -0
- package/dist/utils/get-client-ip.js +49 -0
- package/dist/utils/get-client-ip.js.map +1 -0
- package/dist/utils/logger.d.ts +37 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +52 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/omit.d.ts +20 -0
- package/dist/utils/omit.d.ts.map +1 -0
- package/dist/utils/omit.js +28 -0
- package/dist/utils/omit.js.map +1 -0
- 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/dist/utils/pick.d.ts +20 -0
- package/dist/utils/pick.d.ts.map +1 -0
- package/dist/utils/pick.js +28 -0
- package/dist/utils/pick.js.map +1 -0
- package/dist/utils/serialize-dates.d.ts +27 -0
- package/dist/utils/serialize-dates.d.ts.map +1 -0
- package/dist/utils/serialize-dates.js +39 -0
- package/dist/utils/serialize-dates.js.map +1 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +31 -0
- package/dist/utils.js.map +1 -0
- package/package.json +79 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { AwilixContainer } from 'awilix';
|
|
2
|
+
import type { ErrorHandler, Hono } from 'hono';
|
|
3
|
+
/**
|
|
4
|
+
* Service lifetime scope for dependency injection
|
|
5
|
+
*/
|
|
6
|
+
export type ServiceScope = 'SINGLETON' | 'SCOPED' | 'TRANSIENT';
|
|
7
|
+
/**
|
|
8
|
+
* Constructor type for class providers
|
|
9
|
+
*
|
|
10
|
+
* We use `any[]` for constructor arguments because in dependency injection,
|
|
11
|
+
* we can't know at compile time what arguments will be injected - that's
|
|
12
|
+
* determined by the DI container at runtime. This is a legitimate use of `any`.
|
|
13
|
+
*/
|
|
14
|
+
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
15
|
+
/**
|
|
16
|
+
* Provider configuration for dependency injection
|
|
17
|
+
*/
|
|
18
|
+
export type ProviderConfig = Constructor | {
|
|
19
|
+
provide: string | Constructor;
|
|
20
|
+
useClass: Constructor;
|
|
21
|
+
scope?: ServiceScope;
|
|
22
|
+
} | {
|
|
23
|
+
provide: string;
|
|
24
|
+
useValue: unknown;
|
|
25
|
+
} | {
|
|
26
|
+
provide: string;
|
|
27
|
+
useFactory: (container: unknown) => unknown;
|
|
28
|
+
inject?: string[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Route factory function that receives Hono router and services
|
|
32
|
+
*/
|
|
33
|
+
export type RouteFactory = (router: Hono, services: Record<string, unknown>) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Module configuration
|
|
36
|
+
*/
|
|
37
|
+
export interface ModuleConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Unique module name
|
|
40
|
+
*/
|
|
41
|
+
name: string;
|
|
42
|
+
/**
|
|
43
|
+
* Base path for routes (e.g., 'auth' becomes /api/auth)
|
|
44
|
+
*/
|
|
45
|
+
basePath?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Service providers to register
|
|
48
|
+
*/
|
|
49
|
+
providers?: ProviderConfig[];
|
|
50
|
+
/**
|
|
51
|
+
* Modules to import (access their exported providers)
|
|
52
|
+
*/
|
|
53
|
+
imports?: ModuleConfig[];
|
|
54
|
+
/**
|
|
55
|
+
* Providers to export (available to importing modules)
|
|
56
|
+
*/
|
|
57
|
+
exports?: (Constructor | string)[];
|
|
58
|
+
/**
|
|
59
|
+
* Route factory function
|
|
60
|
+
*/
|
|
61
|
+
routes?: RouteFactory;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Environment type for conditional behavior
|
|
65
|
+
*/
|
|
66
|
+
export type Environment = 'development' | 'production' | 'test';
|
|
67
|
+
/**
|
|
68
|
+
* OpenAPI documentation configuration
|
|
69
|
+
*/
|
|
70
|
+
export interface OpenAPIDocumentation {
|
|
71
|
+
info: {
|
|
72
|
+
title: string;
|
|
73
|
+
version: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
contact?: {
|
|
76
|
+
name?: string;
|
|
77
|
+
email?: string;
|
|
78
|
+
url?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
tags?: Array<{
|
|
82
|
+
name: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
}>;
|
|
85
|
+
servers?: Array<{
|
|
86
|
+
url: string;
|
|
87
|
+
description?: string;
|
|
88
|
+
}>;
|
|
89
|
+
components?: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hook function for customizing OpenAPI responses
|
|
93
|
+
*
|
|
94
|
+
* Receives the response object and context, returns modified response.
|
|
95
|
+
* This allows both framework and applications to add headers, modify
|
|
96
|
+
* descriptions, etc. globally across all routes.
|
|
97
|
+
*/
|
|
98
|
+
export type OpenAPIResponseHook = (response: {
|
|
99
|
+
description: string;
|
|
100
|
+
headers?: Record<string, {
|
|
101
|
+
$ref: string;
|
|
102
|
+
}>;
|
|
103
|
+
content?: Record<string, unknown>;
|
|
104
|
+
}, context: {
|
|
105
|
+
statusCode: string;
|
|
106
|
+
routeConfig: {
|
|
107
|
+
public?: boolean;
|
|
108
|
+
paginate?: boolean;
|
|
109
|
+
tags?: string[];
|
|
110
|
+
summary?: string;
|
|
111
|
+
};
|
|
112
|
+
}) => {
|
|
113
|
+
description: string;
|
|
114
|
+
headers?: Record<string, {
|
|
115
|
+
$ref: string;
|
|
116
|
+
}>;
|
|
117
|
+
content?: Record<string, unknown>;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* OpenAPI configuration options
|
|
121
|
+
*/
|
|
122
|
+
export interface OpenAPIOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Whether to enable OpenAPI generation
|
|
125
|
+
*/
|
|
126
|
+
enabled?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Serve OpenAPI specs at /api/openapi.json (default: true in development)
|
|
129
|
+
*/
|
|
130
|
+
serveSpecs?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Serve Swagger UI at /api (default: true in development)
|
|
133
|
+
*/
|
|
134
|
+
serveUI?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Write OpenAPI specs to file (path relative to cwd)
|
|
137
|
+
*/
|
|
138
|
+
writeToFile?: string;
|
|
139
|
+
/**
|
|
140
|
+
* OpenAPI documentation
|
|
141
|
+
*/
|
|
142
|
+
documentation?: OpenAPIDocumentation;
|
|
143
|
+
/**
|
|
144
|
+
* Response hooks for customizing OpenAPI responses
|
|
145
|
+
*
|
|
146
|
+
* Hooks are applied in order to each response object.
|
|
147
|
+
* Use this to add custom headers, modify descriptions, etc.
|
|
148
|
+
*/
|
|
149
|
+
responseHooks?: OpenAPIResponseHook[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Rate limiting storage backend
|
|
153
|
+
*/
|
|
154
|
+
export type RateLimitStorage = 'memory' | 'dynamodb';
|
|
155
|
+
/**
|
|
156
|
+
* Rate limiting configuration
|
|
157
|
+
*/
|
|
158
|
+
export interface RateLimitOptions {
|
|
159
|
+
/**
|
|
160
|
+
* Whether rate limiting is enabled
|
|
161
|
+
*/
|
|
162
|
+
enabled: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Storage backend
|
|
165
|
+
*/
|
|
166
|
+
storage: RateLimitStorage;
|
|
167
|
+
/**
|
|
168
|
+
* Rate limit window in milliseconds (default: 60000 = 1 minute)
|
|
169
|
+
*/
|
|
170
|
+
windowMs?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Maximum requests per window (default: 100)
|
|
173
|
+
*/
|
|
174
|
+
maxRequests?: number;
|
|
175
|
+
/**
|
|
176
|
+
* DynamoDB configuration (required if storage is 'dynamodb')
|
|
177
|
+
*/
|
|
178
|
+
dynamodb?: {
|
|
179
|
+
tableName: string;
|
|
180
|
+
region?: string;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Middleware configuration options
|
|
185
|
+
*/
|
|
186
|
+
export interface MiddlewareOptions {
|
|
187
|
+
/**
|
|
188
|
+
* Enable request ID middleware
|
|
189
|
+
* @default true
|
|
190
|
+
*/
|
|
191
|
+
requestId?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Enable secure headers middleware
|
|
194
|
+
* @default true in production
|
|
195
|
+
*/
|
|
196
|
+
secureHeaders?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* CORS configuration
|
|
199
|
+
*/
|
|
200
|
+
cors?: {
|
|
201
|
+
origin: string | string[];
|
|
202
|
+
credentials?: boolean;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Logger configuration options
|
|
207
|
+
*/
|
|
208
|
+
export interface LoggerOptions {
|
|
209
|
+
/**
|
|
210
|
+
* Enable HTTP request logging
|
|
211
|
+
* @default true
|
|
212
|
+
*/
|
|
213
|
+
enabled?: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Use plain logger (no ANSI colors) for Lambda/CloudWatch
|
|
216
|
+
* Auto-detected based on environment if not specified
|
|
217
|
+
*/
|
|
218
|
+
plain?: boolean;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Bootstrap options
|
|
222
|
+
*/
|
|
223
|
+
export interface BootstrapOptions {
|
|
224
|
+
/**
|
|
225
|
+
* Environment (auto-detected from NODE_ENV if not provided)
|
|
226
|
+
*/
|
|
227
|
+
environment?: Environment;
|
|
228
|
+
/**
|
|
229
|
+
* API base path (default: '/api')
|
|
230
|
+
*/
|
|
231
|
+
apiBasePath?: string;
|
|
232
|
+
/**
|
|
233
|
+
* Error handler middleware
|
|
234
|
+
* Set to false to disable default error handler
|
|
235
|
+
* Provide a custom ErrorHandler to override
|
|
236
|
+
* @default Glasswork's default error handler
|
|
237
|
+
*/
|
|
238
|
+
errorHandler?: ErrorHandler | false;
|
|
239
|
+
/**
|
|
240
|
+
* OpenAPI configuration
|
|
241
|
+
*/
|
|
242
|
+
openapi?: OpenAPIOptions;
|
|
243
|
+
/**
|
|
244
|
+
* Rate limiting configuration
|
|
245
|
+
*/
|
|
246
|
+
rateLimit?: RateLimitOptions;
|
|
247
|
+
/**
|
|
248
|
+
* Common middleware configuration
|
|
249
|
+
*/
|
|
250
|
+
middleware?: MiddlewareOptions;
|
|
251
|
+
/**
|
|
252
|
+
* Logger configuration
|
|
253
|
+
*/
|
|
254
|
+
logger?: LoggerOptions;
|
|
255
|
+
/**
|
|
256
|
+
* Enable debug logging
|
|
257
|
+
*/
|
|
258
|
+
debug?: boolean;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Bootstrap result
|
|
262
|
+
*/
|
|
263
|
+
export interface BootstrapResult {
|
|
264
|
+
/**
|
|
265
|
+
* Hono application instance
|
|
266
|
+
*/
|
|
267
|
+
app: Hono;
|
|
268
|
+
/**
|
|
269
|
+
* Awilix container (fully accessible)
|
|
270
|
+
*/
|
|
271
|
+
container: AwilixContainer;
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-merge.d.ts","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,GAAG,OAAO,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,GAC1C,CAAC,CAqBH"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep merge objects (simple implementation for small objects)
|
|
3
|
+
*/
|
|
4
|
+
export function deepMerge(...objects) {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const obj of objects) {
|
|
7
|
+
for (const key in obj) {
|
|
8
|
+
if (Object.hasOwn(obj, key)) {
|
|
9
|
+
const value = obj[key];
|
|
10
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
11
|
+
result[key] = deepMerge(result[key] || {}, value);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
result[key] = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=deep-merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,SAAS,CACvB,GAAG,OAAwC;IAE3C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;YACtB,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;gBAEvB,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBAChE,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CACpB,MAAM,CAAC,GAAG,CAA6B,IAAI,EAAE,EAC9C,KAAgC,CACjC,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection utilities for serverless and local development.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if running in AWS Lambda environment
|
|
6
|
+
*/
|
|
7
|
+
export declare function isLambda(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if running in production environment
|
|
10
|
+
* (either NODE_ENV=production or in Lambda)
|
|
11
|
+
*/
|
|
12
|
+
export declare function isProduction(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if running in test environment
|
|
15
|
+
*/
|
|
16
|
+
export declare function isTest(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Check if running in development environment
|
|
19
|
+
*/
|
|
20
|
+
export declare function isDevelopment(): boolean;
|
|
21
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAElC;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection utilities for serverless and local development.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Check if running in AWS Lambda environment
|
|
6
|
+
*/
|
|
7
|
+
export function isLambda() {
|
|
8
|
+
return !!(process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.LAMBDA_TASK_ROOT);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Check if running in production environment
|
|
12
|
+
* (either NODE_ENV=production or in Lambda)
|
|
13
|
+
*/
|
|
14
|
+
export function isProduction() {
|
|
15
|
+
return process.env.NODE_ENV === 'production' || isLambda();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if running in test environment
|
|
19
|
+
*/
|
|
20
|
+
export function isTest() {
|
|
21
|
+
return process.env.NODE_ENV === 'test';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if running in development environment
|
|
25
|
+
*/
|
|
26
|
+
export function isDevelopment() {
|
|
27
|
+
return !isProduction() && !isTest();
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAClF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,QAAQ,EAAE,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the client IP address from Hono context.
|
|
4
|
+
*
|
|
5
|
+
* Checks headers in order:
|
|
6
|
+
* 1. x-forwarded-for (proxy/load balancer)
|
|
7
|
+
* 2. x-real-ip (nginx)
|
|
8
|
+
* 3. Direct connection info (if available)
|
|
9
|
+
*
|
|
10
|
+
* @param c - Hono context
|
|
11
|
+
* @returns Client IP address or 'unknown' if not determinable
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* router.post('/login', route({
|
|
16
|
+
* handler: async ({ ip }) => {
|
|
17
|
+
* // ip is automatically populated
|
|
18
|
+
* await authService.logLoginAttempt(email, ip);
|
|
19
|
+
* }
|
|
20
|
+
* }));
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function getClientIp(c: Context): string;
|
|
24
|
+
//# sourceMappingURL=get-client-ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-client-ip.d.ts","sourceRoot":"","sources":["../../src/utils/get-client-ip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CA0B9C"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the client IP address from Hono context.
|
|
3
|
+
*
|
|
4
|
+
* Checks headers in order:
|
|
5
|
+
* 1. x-forwarded-for (proxy/load balancer)
|
|
6
|
+
* 2. x-real-ip (nginx)
|
|
7
|
+
* 3. Direct connection info (if available)
|
|
8
|
+
*
|
|
9
|
+
* @param c - Hono context
|
|
10
|
+
* @returns Client IP address or 'unknown' if not determinable
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* router.post('/login', route({
|
|
15
|
+
* handler: async ({ ip }) => {
|
|
16
|
+
* // ip is automatically populated
|
|
17
|
+
* await authService.logLoginAttempt(email, ip);
|
|
18
|
+
* }
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function getClientIp(c) {
|
|
23
|
+
// Check x-forwarded-for header (proxy/load balancer)
|
|
24
|
+
const xForwardedFor = c.req.header('x-forwarded-for');
|
|
25
|
+
if (xForwardedFor) {
|
|
26
|
+
const ip = xForwardedFor.split(',')[0].trim();
|
|
27
|
+
if (ip)
|
|
28
|
+
return ip;
|
|
29
|
+
}
|
|
30
|
+
// Check x-real-ip header (nginx)
|
|
31
|
+
const xRealIp = c.req.header('x-real-ip');
|
|
32
|
+
if (xRealIp)
|
|
33
|
+
return xRealIp;
|
|
34
|
+
// Try to get connection info (Node.js server)
|
|
35
|
+
try {
|
|
36
|
+
// Dynamic import to avoid bundling @hono/node-server in Lambda
|
|
37
|
+
// This will throw in non-Node environments
|
|
38
|
+
const { getConnInfo } = require('@hono/node-server/conninfo');
|
|
39
|
+
const info = getConnInfo(c);
|
|
40
|
+
if (info?.remote?.address) {
|
|
41
|
+
return info.remote.address;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Not in Node.js environment or module not available
|
|
46
|
+
}
|
|
47
|
+
return 'unknown';
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=get-client-ip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-client-ip.js","sourceRoot":"","sources":["../../src/utils/get-client-ip.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,qDAAqD;IACrD,MAAM,aAAa,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACtD,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,EAAE;YAAE,OAAO,EAAE,CAAC;IACpB,CAAC;IAED,iCAAiC;IACjC,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAE5B,8CAA8C;IAC9C,IAAI,CAAC;QACH,+DAA+D;QAC/D,2CAA2C;QAC3C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7B,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,qDAAqD;IACvD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger interface for framework and application logging
|
|
3
|
+
*/
|
|
4
|
+
export interface Logger {
|
|
5
|
+
debug(message: string, ...meta: unknown[]): void;
|
|
6
|
+
info(message: string, ...meta: unknown[]): void;
|
|
7
|
+
warn(message: string, ...meta: unknown[]): void;
|
|
8
|
+
error(message: string, ...meta: unknown[]): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Default console logger (used by framework internally)
|
|
12
|
+
*/
|
|
13
|
+
export declare const defaultLogger: Logger;
|
|
14
|
+
/**
|
|
15
|
+
* Create a logger with a prefix for namespacing
|
|
16
|
+
*
|
|
17
|
+
* @param prefix - Prefix to add to all log messages
|
|
18
|
+
* @param enabled - Whether logging is enabled (default: true)
|
|
19
|
+
* @returns Logger instance
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const logger = createLogger('MyService', debug);
|
|
24
|
+
* logger.info('Starting service'); // [MyService] Starting service
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function createLogger(prefix: string, enabled?: boolean): Logger;
|
|
28
|
+
/**
|
|
29
|
+
* Create a plain logger middleware for Lambda (strips ANSI color codes).
|
|
30
|
+
*
|
|
31
|
+
* CloudWatch Logs doesn't render ANSI colors well, so this middleware
|
|
32
|
+
* strips them for cleaner logs in production.
|
|
33
|
+
*
|
|
34
|
+
* @returns Hono logger middleware with ANSI codes stripped
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPlainLogger(): import("hono").MiddlewareHandler;
|
|
37
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAK3B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,UAAO,GAAG,MAAM,CAYnE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,qCAQhC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { logger as honoLogger } from 'hono/logger';
|
|
2
|
+
/**
|
|
3
|
+
* Default console logger (used by framework internally)
|
|
4
|
+
*/
|
|
5
|
+
export const defaultLogger = {
|
|
6
|
+
debug: console.debug.bind(console),
|
|
7
|
+
info: console.log.bind(console),
|
|
8
|
+
warn: console.warn.bind(console),
|
|
9
|
+
error: console.error.bind(console),
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Create a logger with a prefix for namespacing
|
|
13
|
+
*
|
|
14
|
+
* @param prefix - Prefix to add to all log messages
|
|
15
|
+
* @param enabled - Whether logging is enabled (default: true)
|
|
16
|
+
* @returns Logger instance
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const logger = createLogger('MyService', debug);
|
|
21
|
+
* logger.info('Starting service'); // [MyService] Starting service
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createLogger(prefix, enabled = true) {
|
|
25
|
+
if (!enabled) {
|
|
26
|
+
const noop = () => { };
|
|
27
|
+
return { debug: noop, info: noop, warn: noop, error: noop };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
debug: (msg, ...meta) => console.debug(`[${prefix}] ${msg}`, ...meta),
|
|
31
|
+
info: (msg, ...meta) => console.log(`[${prefix}] ${msg}`, ...meta),
|
|
32
|
+
warn: (msg, ...meta) => console.warn(`[${prefix}] ${msg}`, ...meta),
|
|
33
|
+
error: (msg, ...meta) => console.error(`[${prefix}] ${msg}`, ...meta),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a plain logger middleware for Lambda (strips ANSI color codes).
|
|
38
|
+
*
|
|
39
|
+
* CloudWatch Logs doesn't render ANSI colors well, so this middleware
|
|
40
|
+
* strips them for cleaner logs in production.
|
|
41
|
+
*
|
|
42
|
+
* @returns Hono logger middleware with ANSI codes stripped
|
|
43
|
+
*/
|
|
44
|
+
export function createPlainLogger() {
|
|
45
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: we want to strip ANSI color codes
|
|
46
|
+
const stripAnsi = (input) => input.replace(/\u001B\[[0-9;]*m/g, '');
|
|
47
|
+
return honoLogger((str, ...rest) => {
|
|
48
|
+
const message = [str, ...rest].join(' ');
|
|
49
|
+
console.log(stripAnsi(message));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAYnD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,OAAO,GAAG,IAAI;IACzD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;QACtB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC9D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,KAAK,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;QACrE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,KAAK,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;QAClE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,MAAM,KAAK,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;QACnE,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,KAAK,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;KACtE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB;IAC/B,6FAA6F;IAC7F,MAAM,SAAS,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IAEpF,OAAO,UAAU,CAAC,CAAC,GAAW,EAAE,GAAG,IAAc,EAAE,EAAE;QACnD,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object by omitting specified keys from the source object.
|
|
3
|
+
*
|
|
4
|
+
* This implementation preserves the object's prototype, making it suitable
|
|
5
|
+
* for use with class instances and objects with custom prototypes.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of the source object
|
|
8
|
+
* @template K - The type of keys to omit (must be keys of T)
|
|
9
|
+
* @param object - The source object to omit keys from
|
|
10
|
+
* @param paths - Array of keys to omit from the object
|
|
11
|
+
* @returns A new object with the specified keys omitted
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const user = { id: 1, name: 'John', email: 'john@example.com', password: 'secret' };
|
|
16
|
+
* const publicUser = omit(user, ['password']); // { id: 1, name: 'John', email: 'john@example.com' }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function omit<T extends object, K extends keyof T>(object: T, paths: K[]): Omit<T, K>;
|
|
20
|
+
//# sourceMappingURL=omit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.d.ts","sourceRoot":"","sources":["../../src/utils/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAU3F"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object by omitting specified keys from the source object.
|
|
3
|
+
*
|
|
4
|
+
* This implementation preserves the object's prototype, making it suitable
|
|
5
|
+
* for use with class instances and objects with custom prototypes.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of the source object
|
|
8
|
+
* @template K - The type of keys to omit (must be keys of T)
|
|
9
|
+
* @param object - The source object to omit keys from
|
|
10
|
+
* @param paths - Array of keys to omit from the object
|
|
11
|
+
* @returns A new object with the specified keys omitted
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const user = { id: 1, name: 'John', email: 'john@example.com', password: 'secret' };
|
|
16
|
+
* const publicUser = omit(user, ['password']); // { id: 1, name: 'John', email: 'john@example.com' }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function omit(object, paths) {
|
|
20
|
+
const result = Object.create(Object.getPrototypeOf(object));
|
|
21
|
+
for (const key in object) {
|
|
22
|
+
if (Object.hasOwn(object, key) && !paths.includes(key)) {
|
|
23
|
+
result[key] = object[key];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=omit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/utils/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAsC,MAAS,EAAE,KAAU;IAC7E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5D,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAmB,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
/**
|
|
3
|
+
* Pagination input parameters
|
|
4
|
+
*/
|
|
5
|
+
export interface PaginationInput {
|
|
6
|
+
page: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Paginated output structure
|
|
11
|
+
*/
|
|
12
|
+
export interface PaginatedOutput<T> {
|
|
13
|
+
data: T[];
|
|
14
|
+
total: number;
|
|
15
|
+
page: number;
|
|
16
|
+
limit: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Execute a paginated query and set response headers.
|
|
20
|
+
*
|
|
21
|
+
* This helper extracts pagination parameters from the query string,
|
|
22
|
+
* executes the provided function, and sets the appropriate response headers.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of items in the result
|
|
25
|
+
* @param c - Hono context
|
|
26
|
+
* @param fn - Function that executes the paginated query
|
|
27
|
+
* @returns Array of items (headers are set as side effect)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* router.get('/users', route({
|
|
32
|
+
* paginate: true,
|
|
33
|
+
* handler: async ({ context }) => {
|
|
34
|
+
* return await paginate(context, (p) => userService.getUsers(p));
|
|
35
|
+
* }
|
|
36
|
+
* }));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function paginate<T>(c: Context, fn: (p: PaginationInput) => Promise<PaginatedOutput<T>>): Promise<T[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Extract pagination parameters from Hono context.
|
|
42
|
+
*
|
|
43
|
+
* @param c - Hono context
|
|
44
|
+
* @param defaultLimit - Default limit if not provided (default: 100)
|
|
45
|
+
* @returns Pagination input with page and limit
|
|
46
|
+
*/
|
|
47
|
+
export declare function paginationInput(c: Context, defaultLimit?: number): PaginationInput;
|
|
48
|
+
//# sourceMappingURL=pagination.d.ts.map
|