veloce-ts 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/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +442 -0
- package/bin/veloce.ts +2 -0
- package/dist/cjs/src/cli/index.js +425 -0
- package/dist/cjs/src/cli/index.js.map +22 -0
- package/dist/cjs/src/docs/index.js +7 -0
- package/dist/cjs/src/docs/index.js.map +55 -0
- package/dist/cjs/src/errors/index.js +4 -0
- package/dist/cjs/src/errors/index.js.map +12 -0
- package/dist/cjs/src/graphql/index.js +83 -0
- package/dist/cjs/src/graphql/index.js.map +24 -0
- package/dist/cjs/src/index.js +126 -0
- package/dist/cjs/src/index.js.map +108 -0
- package/dist/cjs/src/middleware/index.js +3 -0
- package/dist/cjs/src/middleware/index.js.map +12 -0
- package/dist/cjs/src/plugins/index.js +125 -0
- package/dist/cjs/src/plugins/index.js.map +67 -0
- package/dist/cjs/src/testing/index.js +17 -0
- package/dist/cjs/src/testing/index.js.map +54 -0
- package/dist/cjs/src/types/index.js +3 -0
- package/dist/cjs/src/types/index.js.map +16 -0
- package/dist/cjs/src/validation/index.js +3 -0
- package/dist/cjs/src/validation/index.js.map +19 -0
- package/dist/cjs/src/websocket/index.js +3 -0
- package/dist/cjs/src/websocket/index.js.map +12 -0
- package/dist/esm/chunk-0zxhx5b8.js +7 -0
- package/dist/esm/chunk-0zxhx5b8.js.map +10 -0
- package/dist/esm/chunk-159eqj8q.js +5 -0
- package/dist/esm/chunk-159eqj8q.js.map +12 -0
- package/dist/esm/chunk-1hqjkm44.js +5 -0
- package/dist/esm/chunk-1hqjkm44.js.map +11 -0
- package/dist/esm/chunk-2q6s8v3j.js +6 -0
- package/dist/esm/chunk-2q6s8v3j.js.map +10 -0
- package/dist/esm/chunk-42h6trpf.js +5 -0
- package/dist/esm/chunk-42h6trpf.js.map +9 -0
- package/dist/esm/chunk-82f2j0k2.js +60 -0
- package/dist/esm/chunk-82f2j0k2.js.map +10 -0
- package/dist/esm/chunk-8wrnr45g.js +338 -0
- package/dist/esm/chunk-8wrnr45g.js.map +10 -0
- package/dist/esm/chunk-9p6d0t33.js +5 -0
- package/dist/esm/chunk-9p6d0t33.js.map +10 -0
- package/dist/esm/chunk-awven6dt.js +4 -0
- package/dist/esm/chunk-awven6dt.js.map +16 -0
- package/dist/esm/chunk-gv5n8ddb.js +18 -0
- package/dist/esm/chunk-gv5n8ddb.js.map +10 -0
- package/dist/esm/chunk-pn7z890c.js +72 -0
- package/dist/esm/chunk-pn7z890c.js.map +13 -0
- package/dist/esm/chunk-qfsjy9bg.js +7 -0
- package/dist/esm/chunk-qfsjy9bg.js.map +10 -0
- package/dist/esm/chunk-vkkzgaf7.js +5 -0
- package/dist/esm/chunk-vkkzgaf7.js.map +12 -0
- package/dist/esm/src/cli/index.js +30 -0
- package/dist/esm/src/cli/index.js.map +18 -0
- package/dist/esm/src/docs/index.js +8 -0
- package/dist/esm/src/docs/index.js.map +48 -0
- package/dist/esm/src/errors/index.js +4 -0
- package/dist/esm/src/errors/index.js.map +9 -0
- package/dist/esm/src/graphql/index.js +4 -0
- package/dist/esm/src/graphql/index.js.map +9 -0
- package/dist/esm/src/index.js +4 -0
- package/dist/esm/src/index.js.map +16 -0
- package/dist/esm/src/middleware/index.js +4 -0
- package/dist/esm/src/middleware/index.js.map +9 -0
- package/dist/esm/src/plugins/index.js +42 -0
- package/dist/esm/src/plugins/index.js.map +10 -0
- package/dist/esm/src/testing/index.js +4 -0
- package/dist/esm/src/testing/index.js.map +39 -0
- package/dist/esm/src/types/index.js +4 -0
- package/dist/esm/src/types/index.js.map +9 -0
- package/dist/esm/src/validation/index.js +4 -0
- package/dist/esm/src/validation/index.js.map +9 -0
- package/dist/esm/src/websocket/index.js +4 -0
- package/dist/esm/src/websocket/index.js.map +9 -0
- package/dist/types/adapters/base.d.ts +24 -0
- package/dist/types/adapters/base.d.ts.map +1 -0
- package/dist/types/adapters/express.d.ts +44 -0
- package/dist/types/adapters/express.d.ts.map +1 -0
- package/dist/types/adapters/hono.d.ts +44 -0
- package/dist/types/adapters/hono.d.ts.map +1 -0
- package/dist/types/cli/commands/build.d.ts +3 -0
- package/dist/types/cli/commands/build.d.ts.map +1 -0
- package/dist/types/cli/commands/dev.d.ts +3 -0
- package/dist/types/cli/commands/dev.d.ts.map +1 -0
- package/dist/types/cli/commands/generate.d.ts +3 -0
- package/dist/types/cli/commands/generate.d.ts.map +1 -0
- package/dist/types/cli/commands/new.d.ts +3 -0
- package/dist/types/cli/commands/new.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/core/application.d.ts +268 -0
- package/dist/types/core/application.d.ts.map +1 -0
- package/dist/types/core/compiled-metadata.d.ts +58 -0
- package/dist/types/core/compiled-metadata.d.ts.map +1 -0
- package/dist/types/core/metadata.d.ts +175 -0
- package/dist/types/core/metadata.d.ts.map +1 -0
- package/dist/types/core/plugin.d.ts +63 -0
- package/dist/types/core/plugin.d.ts.map +1 -0
- package/dist/types/core/router-compiler.d.ts +61 -0
- package/dist/types/core/router-compiler.d.ts.map +1 -0
- package/dist/types/decorators/dependencies.d.ts +28 -0
- package/dist/types/decorators/dependencies.d.ts.map +1 -0
- package/dist/types/decorators/docs.d.ts +38 -0
- package/dist/types/decorators/docs.d.ts.map +1 -0
- package/dist/types/decorators/graphql.d.ts +126 -0
- package/dist/types/decorators/graphql.d.ts.map +1 -0
- package/dist/types/decorators/http.d.ts +74 -0
- package/dist/types/decorators/http.d.ts.map +1 -0
- package/dist/types/decorators/middleware.d.ts +30 -0
- package/dist/types/decorators/middleware.d.ts.map +1 -0
- package/dist/types/decorators/params.d.ts +82 -0
- package/dist/types/decorators/params.d.ts.map +1 -0
- package/dist/types/decorators/websocket.d.ts +61 -0
- package/dist/types/decorators/websocket.d.ts.map +1 -0
- package/dist/types/dependencies/container.d.ts +93 -0
- package/dist/types/dependencies/container.d.ts.map +1 -0
- package/dist/types/docs/index.d.ts +3 -0
- package/dist/types/docs/index.d.ts.map +1 -0
- package/dist/types/docs/openapi-generator.d.ts +50 -0
- package/dist/types/docs/openapi-generator.d.ts.map +1 -0
- package/dist/types/docs/zod-to-json-schema.d.ts +46 -0
- package/dist/types/docs/zod-to-json-schema.d.ts.map +1 -0
- package/dist/types/errors/exceptions.d.ts +48 -0
- package/dist/types/errors/exceptions.d.ts.map +1 -0
- package/dist/types/errors/handler.d.ts +61 -0
- package/dist/types/errors/handler.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +7 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/graphql/index.d.ts +4 -0
- package/dist/types/graphql/index.d.ts.map +1 -0
- package/dist/types/graphql/plugin.d.ts +60 -0
- package/dist/types/graphql/plugin.d.ts.map +1 -0
- package/dist/types/graphql/schema-builder.d.ts +46 -0
- package/dist/types/graphql/schema-builder.d.ts.map +1 -0
- package/dist/types/graphql/zod-to-graphql.d.ts +22 -0
- package/dist/types/graphql/zod-to-graphql.d.ts.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/middleware/compression.d.ts +7 -0
- package/dist/types/middleware/compression.d.ts.map +1 -0
- package/dist/types/middleware/cors.d.ts +7 -0
- package/dist/types/middleware/cors.d.ts.map +1 -0
- package/dist/types/middleware/index.d.ts +4 -0
- package/dist/types/middleware/index.d.ts.map +1 -0
- package/dist/types/middleware/rate-limit.d.ts +7 -0
- package/dist/types/middleware/rate-limit.d.ts.map +1 -0
- package/dist/types/plugins/index.d.ts +4 -0
- package/dist/types/plugins/index.d.ts.map +1 -0
- package/dist/types/plugins/openapi.d.ts +23 -0
- package/dist/types/plugins/openapi.d.ts.map +1 -0
- package/dist/types/responses/response.d.ts +200 -0
- package/dist/types/responses/response.d.ts.map +1 -0
- package/dist/types/testing/helpers.d.ts +98 -0
- package/dist/types/testing/helpers.d.ts.map +1 -0
- package/dist/types/testing/index.d.ts +4 -0
- package/dist/types/testing/index.d.ts.map +1 -0
- package/dist/types/testing/test-client.d.ts +86 -0
- package/dist/types/testing/test-client.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +232 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/validation/exceptions.d.ts +25 -0
- package/dist/types/validation/exceptions.d.ts.map +1 -0
- package/dist/types/validation/index.d.ts +3 -0
- package/dist/types/validation/index.d.ts.map +1 -0
- package/dist/types/validation/validator.d.ts +54 -0
- package/dist/types/validation/validator.d.ts.map +1 -0
- package/dist/types/websocket/connection.d.ts +51 -0
- package/dist/types/websocket/connection.d.ts.map +1 -0
- package/dist/types/websocket/index.d.ts +4 -0
- package/dist/types/websocket/index.d.ts.map +1 -0
- package/dist/types/websocket/manager.d.ts +82 -0
- package/dist/types/websocket/manager.d.ts.map +1 -0
- package/dist/types/websocket/plugin.d.ts +51 -0
- package/dist/types/websocket/plugin.d.ts.map +1 -0
- package/package.json +149 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { Context } from '../types';
|
|
2
|
+
export interface FileOptions {
|
|
3
|
+
filename?: string;
|
|
4
|
+
contentType?: string;
|
|
5
|
+
download?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface StreamOptions {
|
|
8
|
+
contentType?: string;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Response builder class providing static factory methods
|
|
13
|
+
* for creating different types of HTTP responses
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Return JSON response
|
|
18
|
+
* return Response.json({ id: 1, name: 'John' });
|
|
19
|
+
*
|
|
20
|
+
* // Return HTML
|
|
21
|
+
* return Response.html('<h1>Hello World</h1>');
|
|
22
|
+
*
|
|
23
|
+
* // Serve a file
|
|
24
|
+
* return Response.file('./uploads/document.pdf', { download: true });
|
|
25
|
+
*
|
|
26
|
+
* // Redirect
|
|
27
|
+
* return Response.redirect('/login', 302);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class Response {
|
|
31
|
+
/**
|
|
32
|
+
* Create a JSON response
|
|
33
|
+
* @param data - The data to serialize as JSON
|
|
34
|
+
* @param status - HTTP status code (default: 200)
|
|
35
|
+
* @param headers - Optional custom headers
|
|
36
|
+
* @returns JSONResponse instance
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @Get('/users/:id')
|
|
41
|
+
* getUser(@Param('id') id: string) {
|
|
42
|
+
* return Response.json({ id, name: 'John' }, 200);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
static json(data: any, status?: number, headers?: Record<string, string>): JSONResponse;
|
|
47
|
+
/**
|
|
48
|
+
* Create an HTML response
|
|
49
|
+
* @param content - HTML content string
|
|
50
|
+
* @param status - HTTP status code (default: 200)
|
|
51
|
+
* @returns HTMLResponse instance
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* @Get('/page')
|
|
56
|
+
* getPage() {
|
|
57
|
+
* return Response.html('<h1>Welcome</h1>');
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static html(content: string, status?: number): HTMLResponse;
|
|
62
|
+
/**
|
|
63
|
+
* Create a file response to serve static files
|
|
64
|
+
* @param path - Path to the file
|
|
65
|
+
* @param options - File serving options (filename, contentType, download)
|
|
66
|
+
* @returns FileResponse instance
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* @Get('/download/:filename')
|
|
71
|
+
* downloadFile(@Param('filename') filename: string) {
|
|
72
|
+
* return Response.file(`./uploads/${filename}`, { download: true });
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
static file(path: string, options?: FileOptions): FileResponse;
|
|
77
|
+
/**
|
|
78
|
+
* Create a streaming response for large data or real-time content
|
|
79
|
+
* @param stream - ReadableStream to send
|
|
80
|
+
* @param options - Stream options (contentType, headers)
|
|
81
|
+
* @returns StreamResponse instance
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* @Get('/stream')
|
|
86
|
+
* streamData() {
|
|
87
|
+
* const stream = new ReadableStream({
|
|
88
|
+
* start(controller) {
|
|
89
|
+
* controller.enqueue('chunk 1');
|
|
90
|
+
* controller.close();
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
93
|
+
* return Response.stream(stream, { contentType: 'text/plain' });
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
static stream(stream: ReadableStream, options?: StreamOptions): StreamResponse;
|
|
98
|
+
/**
|
|
99
|
+
* Create a redirect response
|
|
100
|
+
* @param url - URL to redirect to
|
|
101
|
+
* @param status - HTTP status code (default: 302)
|
|
102
|
+
* @returns RedirectResponse instance
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* @Post('/login')
|
|
107
|
+
* login(@Body(LoginSchema) credentials: LoginData) {
|
|
108
|
+
* // ... authenticate user
|
|
109
|
+
* return Response.redirect('/dashboard', 302);
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static redirect(url: string, status?: number): RedirectResponse;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* JSON response class
|
|
117
|
+
* Serializes data as JSON with specified status code and headers
|
|
118
|
+
*/
|
|
119
|
+
export declare class JSONResponse {
|
|
120
|
+
data: any;
|
|
121
|
+
status: number;
|
|
122
|
+
headers: Record<string, string>;
|
|
123
|
+
constructor(data: any, status?: number, headers?: Record<string, string>);
|
|
124
|
+
/**
|
|
125
|
+
* Convert to Hono response format
|
|
126
|
+
* @param c - Hono context
|
|
127
|
+
* @returns Hono JSON response
|
|
128
|
+
*/
|
|
129
|
+
toHonoResponse(c: Context): globalThis.Response & import("hono").TypedResponse<any, any, "json">;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* HTML response class
|
|
133
|
+
* Returns HTML content with proper Content-Type header
|
|
134
|
+
*/
|
|
135
|
+
export declare class HTMLResponse {
|
|
136
|
+
content: string;
|
|
137
|
+
status: number;
|
|
138
|
+
constructor(content: string, status?: number);
|
|
139
|
+
/**
|
|
140
|
+
* Convert to Hono response format
|
|
141
|
+
* @param c - Hono context
|
|
142
|
+
* @returns Hono HTML response
|
|
143
|
+
*/
|
|
144
|
+
toHonoResponse(c: Context): globalThis.Response;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Redirect response class
|
|
148
|
+
* Performs HTTP redirect to specified URL
|
|
149
|
+
*/
|
|
150
|
+
export declare class RedirectResponse {
|
|
151
|
+
url: string;
|
|
152
|
+
status: number;
|
|
153
|
+
constructor(url: string, status?: number);
|
|
154
|
+
/**
|
|
155
|
+
* Convert to Hono response format
|
|
156
|
+
* @param c - Hono context
|
|
157
|
+
* @returns Hono redirect response
|
|
158
|
+
*/
|
|
159
|
+
toHonoResponse(c: Context): globalThis.Response & import("hono").TypedResponse<undefined, any, "redirect">;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* FileResponse serves a file from the filesystem
|
|
163
|
+
* Supports custom filenames, content types, and download mode
|
|
164
|
+
*/
|
|
165
|
+
export declare class FileResponse {
|
|
166
|
+
path: string;
|
|
167
|
+
options?: FileOptions | undefined;
|
|
168
|
+
constructor(path: string, options?: FileOptions | undefined);
|
|
169
|
+
toHonoResponse(c: Context): Promise<(globalThis.Response & import("hono").TypedResponse<any, 200, "body">) | (globalThis.Response & import("hono").TypedResponse<{
|
|
170
|
+
error: string;
|
|
171
|
+
message: string;
|
|
172
|
+
}, 404, "json">)>;
|
|
173
|
+
private readFileNode;
|
|
174
|
+
private guessContentType;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* StreamResponse sends data as a stream
|
|
178
|
+
* Useful for large files, real-time data, or server-sent events
|
|
179
|
+
*/
|
|
180
|
+
export declare class StreamResponse {
|
|
181
|
+
stream: ReadableStream;
|
|
182
|
+
options?: StreamOptions | undefined;
|
|
183
|
+
constructor(stream: ReadableStream, options?: StreamOptions | undefined);
|
|
184
|
+
toHonoResponse(c: Context): globalThis.Response & import("hono").TypedResponse<any, 200, "body">;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* ResponseSerializer handles automatic serialization of handler return values
|
|
188
|
+
* Converts different return types into appropriate HTTP responses
|
|
189
|
+
*/
|
|
190
|
+
export declare class ResponseSerializer {
|
|
191
|
+
/**
|
|
192
|
+
* Serialize a handler result into an HTTP response
|
|
193
|
+
*
|
|
194
|
+
* @param c - Hono context
|
|
195
|
+
* @param result - The value returned from the handler
|
|
196
|
+
* @returns Serialized HTTP response
|
|
197
|
+
*/
|
|
198
|
+
static serialize(c: Context, result: any): any;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../src/responses/response.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,QAAQ;IACnB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,GAAE,MAAY,EAAE,OAAO,CA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,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,YAAA;IAGxB,cAAc,CAAC,CAAC,EAAE,OAAO;;;;YA0CjB,YAAY;IAM1B,OAAO,CAAC,gBAAgB;CAkBzB;AAED;;;GAGG;AACH,qBAAa,cAAc;IAEhB,MAAM,EAAE,cAAc;IACtB,OAAO,CAAC,EAAE,aAAa;gBADvB,MAAM,EAAE,cAAc,EACtB,OAAO,CAAC,EAAE,aAAa,YAAA;IAGhC,cAAc,CAAC,CAAC,EAAE,OAAO;CAS1B;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,GAAG;CAwC/C"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { VeloceTS } from '../core/application';
|
|
2
|
+
import { TestClient } from './test-client';
|
|
3
|
+
import type { VeloceTSConfig, Provider, ProviderConfig } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Create a test instance of VeloceTS application
|
|
6
|
+
* This is useful for creating isolated test instances with specific configurations
|
|
7
|
+
*
|
|
8
|
+
* @param config - Optional configuration for the test app
|
|
9
|
+
* @returns A new VeloceTS instance configured for testing
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const app = createTestApp({ docs: false });
|
|
14
|
+
* app.get('/test', { handler: () => ({ message: 'test' }) });
|
|
15
|
+
* await app.compile();
|
|
16
|
+
*
|
|
17
|
+
* const client = new TestClient(app);
|
|
18
|
+
* const response = await client.get('/test');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createTestApp(config?: VeloceTSConfig): VeloceTS;
|
|
22
|
+
/**
|
|
23
|
+
* Mock a dependency in the DI container
|
|
24
|
+
* This allows you to replace real dependencies with mocks for testing
|
|
25
|
+
*
|
|
26
|
+
* @param app - The VeloceTS application instance
|
|
27
|
+
* @param provider - The provider to mock
|
|
28
|
+
* @param mockValue - The mock value or factory function
|
|
29
|
+
* @param config - Optional provider configuration
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* class UserService {
|
|
34
|
+
* getUser(id: string) { return { id, name: 'Real User' }; }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* const app = createTestApp();
|
|
38
|
+
* const mockUserService = { getUser: (id: string) => ({ id, name: 'Mock User' }) };
|
|
39
|
+
*
|
|
40
|
+
* mockDependency(app, UserService, mockUserService);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function mockDependency<T>(app: VeloceTS, provider: Provider<T>, mockValue: T | (() => T | Promise<T>), config?: ProviderConfig): void;
|
|
44
|
+
/**
|
|
45
|
+
* Create a test client for an application
|
|
46
|
+
* This is a convenience function that creates a TestClient instance
|
|
47
|
+
*
|
|
48
|
+
* @param app - The VeloceTS application instance
|
|
49
|
+
* @returns A TestClient instance for making test requests
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const app = createTestApp();
|
|
54
|
+
* app.get('/hello', { handler: () => ({ message: 'Hello' }) });
|
|
55
|
+
* await app.compile();
|
|
56
|
+
*
|
|
57
|
+
* const client = createTestClient(app);
|
|
58
|
+
* const response = await client.get('/hello');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function createTestClient(app: VeloceTS): TestClient;
|
|
62
|
+
/**
|
|
63
|
+
* Setup a test application with routes and compile it
|
|
64
|
+
* This is a convenience function for quickly setting up test scenarios
|
|
65
|
+
*
|
|
66
|
+
* @param setup - Function that sets up routes on the app
|
|
67
|
+
* @param config - Optional configuration for the test app
|
|
68
|
+
* @returns Object containing the app and client
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const { app, client } = await setupTestApp((app) => {
|
|
73
|
+
* app.get('/users', { handler: () => [{ id: 1, name: 'User' }] });
|
|
74
|
+
* app.post('/users', { handler: (c) => ({ id: 2, name: 'New User' }) });
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* const response = await client.get('/users');
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function setupTestApp(setup: (app: VeloceTS) => void | Promise<void>, config?: VeloceTSConfig): Promise<{
|
|
81
|
+
app: VeloceTS;
|
|
82
|
+
client: TestClient;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Clear all mocked dependencies from an application
|
|
86
|
+
* This is useful for cleaning up between tests
|
|
87
|
+
*
|
|
88
|
+
* @param app - The VeloceTS application instance
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* afterEach(() => {
|
|
93
|
+
* clearMocks(app);
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function clearMocks(app: VeloceTS): void;
|
|
98
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/testing/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAEzE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,QAAQ,CAS/D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EACrC,MAAM,CAAC,EAAE,cAAc,GACtB,IAAI,CAaN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,UAAU,CAE1D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC9C,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC;IAAE,GAAG,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,CAShD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAG9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,UAAU,GACX,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { VeloceTS } from '../core/application';
|
|
2
|
+
/**
|
|
3
|
+
* Options for making test requests
|
|
4
|
+
*/
|
|
5
|
+
export interface TestRequestOptions {
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
query?: Record<string, string>;
|
|
8
|
+
body?: any;
|
|
9
|
+
json?: any;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Response from a test request
|
|
13
|
+
*/
|
|
14
|
+
export interface TestResponse {
|
|
15
|
+
status: number;
|
|
16
|
+
headers: Headers;
|
|
17
|
+
body: any;
|
|
18
|
+
text: string;
|
|
19
|
+
json: () => Promise<any>;
|
|
20
|
+
ok: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* TestClient provides a convenient interface for testing VeloceTS applications
|
|
24
|
+
* Wraps the Hono app.request method with helper methods for common HTTP verbs
|
|
25
|
+
*/
|
|
26
|
+
export declare class TestClient {
|
|
27
|
+
private hono;
|
|
28
|
+
constructor(app: VeloceTS);
|
|
29
|
+
/**
|
|
30
|
+
* Make a GET request
|
|
31
|
+
* @param path - The path to request
|
|
32
|
+
* @param options - Optional request options
|
|
33
|
+
* @returns The test response
|
|
34
|
+
*/
|
|
35
|
+
get(path: string, options?: TestRequestOptions): Promise<TestResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Make a POST request
|
|
38
|
+
* @param path - The path to request
|
|
39
|
+
* @param options - Optional request options
|
|
40
|
+
* @returns The test response
|
|
41
|
+
*/
|
|
42
|
+
post(path: string, options?: TestRequestOptions): Promise<TestResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Make a PUT request
|
|
45
|
+
* @param path - The path to request
|
|
46
|
+
* @param options - Optional request options
|
|
47
|
+
* @returns The test response
|
|
48
|
+
*/
|
|
49
|
+
put(path: string, options?: TestRequestOptions): Promise<TestResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Make a DELETE request
|
|
52
|
+
* @param path - The path to request
|
|
53
|
+
* @param options - Optional request options
|
|
54
|
+
* @returns The test response
|
|
55
|
+
*/
|
|
56
|
+
delete(path: string, options?: TestRequestOptions): Promise<TestResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Make a PATCH request
|
|
59
|
+
* @param path - The path to request
|
|
60
|
+
* @param options - Optional request options
|
|
61
|
+
* @returns The test response
|
|
62
|
+
*/
|
|
63
|
+
patch(path: string, options?: TestRequestOptions): Promise<TestResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Make a generic HTTP request
|
|
66
|
+
* @param method - The HTTP method
|
|
67
|
+
* @param path - The path to request
|
|
68
|
+
* @param options - Optional request options
|
|
69
|
+
* @returns The test response
|
|
70
|
+
*/
|
|
71
|
+
request(method: string, path: string, options?: TestRequestOptions): Promise<TestResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Build URL with query parameters
|
|
74
|
+
* @param path - The base path
|
|
75
|
+
* @param query - Optional query parameters
|
|
76
|
+
* @returns The complete URL
|
|
77
|
+
*/
|
|
78
|
+
private buildUrl;
|
|
79
|
+
/**
|
|
80
|
+
* Build headers for the request
|
|
81
|
+
* @param options - Request options
|
|
82
|
+
* @returns Headers object
|
|
83
|
+
*/
|
|
84
|
+
private buildHeaders;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=test-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-client.d.ts","sourceRoot":"","sources":["../../../src/testing/test-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,EAAE,EAAE,OAAO,CAAC;CACb;AAED;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAO;gBAEP,GAAG,EAAE,QAAQ;IAIzB;;;;;OAKG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAI5E;;;;;OAKG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAI7E;;;;;OAKG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAI5E;;;;;OAKG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAI/E;;;;;OAKG;IACG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAI9E;;;;;;OAMG;IACG,OAAO,CACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,YAAY,CAAC;IAwCxB;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAShB;;;;OAIG;IACH,OAAO,CAAC,YAAY;CAYrB"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
|
2
|
+
import type { ZodSchema, z } from 'zod';
|
|
3
|
+
export { z } from 'zod';
|
|
4
|
+
export type { infer as Infer } from 'zod';
|
|
5
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'ALL';
|
|
6
|
+
export type Class<T = any> = new (...args: any[]) => T;
|
|
7
|
+
export type Provider<T = any> = Class<T> | (() => T | Promise<T>);
|
|
8
|
+
export type Scope = 'singleton' | 'request' | 'transient';
|
|
9
|
+
export type Context = HonoContext;
|
|
10
|
+
export type Middleware = MiddlewareHandler;
|
|
11
|
+
export interface RouteMetadata {
|
|
12
|
+
target: Class;
|
|
13
|
+
propertyKey: string;
|
|
14
|
+
method: HTTPMethod;
|
|
15
|
+
path: string;
|
|
16
|
+
middleware: Middleware[];
|
|
17
|
+
parameters: ParameterMetadata[];
|
|
18
|
+
dependencies: DependencyMetadata[];
|
|
19
|
+
responses: ResponseMetadata[];
|
|
20
|
+
docs?: RouteDocumentation;
|
|
21
|
+
}
|
|
22
|
+
export interface ParameterMetadata {
|
|
23
|
+
index: number;
|
|
24
|
+
type: 'body' | 'query' | 'param' | 'header' | 'cookie' | 'request' | 'response' | 'context';
|
|
25
|
+
schema?: ZodSchema;
|
|
26
|
+
name?: string;
|
|
27
|
+
required: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface DependencyMetadata {
|
|
30
|
+
index: number;
|
|
31
|
+
provider: Provider;
|
|
32
|
+
scope: Scope;
|
|
33
|
+
}
|
|
34
|
+
export interface ResponseMetadata {
|
|
35
|
+
statusCode: number;
|
|
36
|
+
description?: string;
|
|
37
|
+
schema?: ZodSchema;
|
|
38
|
+
}
|
|
39
|
+
export interface ControllerMetadata {
|
|
40
|
+
prefix: string;
|
|
41
|
+
middleware: Middleware[];
|
|
42
|
+
}
|
|
43
|
+
export interface RouteDocumentation {
|
|
44
|
+
summary?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
tags?: string[];
|
|
47
|
+
deprecated?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface VeloceTSConfig {
|
|
50
|
+
adapter?: 'hono' | 'express' | 'native';
|
|
51
|
+
title?: string;
|
|
52
|
+
version?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
docs?: boolean | {
|
|
55
|
+
path?: string;
|
|
56
|
+
openapi?: string;
|
|
57
|
+
};
|
|
58
|
+
cors?: CorsOptions | boolean;
|
|
59
|
+
plugins?: any[];
|
|
60
|
+
}
|
|
61
|
+
export interface CorsOptions {
|
|
62
|
+
origin?: string | string[] | ((origin: string) => boolean);
|
|
63
|
+
methods?: string[];
|
|
64
|
+
allowedHeaders?: string[];
|
|
65
|
+
exposedHeaders?: string[];
|
|
66
|
+
credentials?: boolean;
|
|
67
|
+
maxAge?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface RateLimitOptions {
|
|
70
|
+
windowMs?: number;
|
|
71
|
+
max?: number;
|
|
72
|
+
keyGenerator?: (c: Context) => string;
|
|
73
|
+
}
|
|
74
|
+
export interface CompressionOptions {
|
|
75
|
+
threshold?: number;
|
|
76
|
+
level?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface RouteConfig {
|
|
79
|
+
handler: (c: Context, ...args: any[]) => any | Promise<any>;
|
|
80
|
+
schema?: {
|
|
81
|
+
body?: ZodSchema;
|
|
82
|
+
query?: ZodSchema;
|
|
83
|
+
params?: ZodSchema;
|
|
84
|
+
headers?: ZodSchema;
|
|
85
|
+
};
|
|
86
|
+
middleware?: Middleware[];
|
|
87
|
+
docs?: RouteDocumentation;
|
|
88
|
+
responses?: ResponseMetadata[];
|
|
89
|
+
}
|
|
90
|
+
export interface ProviderConfig {
|
|
91
|
+
scope?: Scope;
|
|
92
|
+
factory?: () => any;
|
|
93
|
+
}
|
|
94
|
+
export interface OpenAPIOptions {
|
|
95
|
+
title?: string;
|
|
96
|
+
version?: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
path?: string;
|
|
99
|
+
docsPath?: string;
|
|
100
|
+
docs?: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface OpenAPISpec {
|
|
103
|
+
openapi: string;
|
|
104
|
+
info: {
|
|
105
|
+
title: string;
|
|
106
|
+
version: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
};
|
|
109
|
+
paths: Record<string, any>;
|
|
110
|
+
components?: {
|
|
111
|
+
schemas?: Record<string, any>;
|
|
112
|
+
securitySchemes?: Record<string, any>;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export interface WebSocketMetadata {
|
|
116
|
+
target: Class;
|
|
117
|
+
path: string;
|
|
118
|
+
onConnect?: string;
|
|
119
|
+
onMessage?: string;
|
|
120
|
+
onDisconnect?: string;
|
|
121
|
+
messageSchema?: ZodSchema;
|
|
122
|
+
}
|
|
123
|
+
export interface WebSocketHandlerMetadata {
|
|
124
|
+
type: 'connect' | 'message' | 'disconnect';
|
|
125
|
+
method: string;
|
|
126
|
+
schema?: ZodSchema;
|
|
127
|
+
}
|
|
128
|
+
export type GraphQLOperationType = 'query' | 'mutation' | 'subscription';
|
|
129
|
+
export interface GraphQLResolverMetadata {
|
|
130
|
+
target: Class;
|
|
131
|
+
name?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface GraphQLFieldMetadata {
|
|
134
|
+
target: Class;
|
|
135
|
+
propertyKey: string;
|
|
136
|
+
type: GraphQLOperationType;
|
|
137
|
+
name?: string;
|
|
138
|
+
returnType?: any;
|
|
139
|
+
description?: string;
|
|
140
|
+
deprecated?: boolean;
|
|
141
|
+
deprecationReason?: string;
|
|
142
|
+
}
|
|
143
|
+
export interface GraphQLArgumentMetadata {
|
|
144
|
+
index: number;
|
|
145
|
+
name: string;
|
|
146
|
+
schema?: ZodSchema;
|
|
147
|
+
description?: string;
|
|
148
|
+
defaultValue?: any;
|
|
149
|
+
nullable?: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface GraphQLContextMetadata {
|
|
152
|
+
index: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Infer TypeScript type from a Zod schema
|
|
156
|
+
* @example
|
|
157
|
+
* const UserSchema = z.object({ name: z.string(), age: z.number() });
|
|
158
|
+
* type User = InferSchema<typeof UserSchema>; // { name: string; age: number }
|
|
159
|
+
*/
|
|
160
|
+
export type InferSchema<T extends ZodSchema> = z.infer<T>;
|
|
161
|
+
/**
|
|
162
|
+
* Infer the body type from a route handler
|
|
163
|
+
* @example
|
|
164
|
+
* const handler = (body: InferBody<typeof UserSchema>) => { ... }
|
|
165
|
+
*/
|
|
166
|
+
export type InferBody<T extends ZodSchema> = z.infer<T>;
|
|
167
|
+
/**
|
|
168
|
+
* Infer the query parameters type from a route handler
|
|
169
|
+
* @example
|
|
170
|
+
* const handler = (query: InferQuery<typeof QuerySchema>) => { ... }
|
|
171
|
+
*/
|
|
172
|
+
export type InferQuery<T extends ZodSchema> = z.infer<T>;
|
|
173
|
+
/**
|
|
174
|
+
* Infer the route parameters type from a route handler
|
|
175
|
+
* @example
|
|
176
|
+
* const handler = (params: InferParams<typeof ParamsSchema>) => { ... }
|
|
177
|
+
*/
|
|
178
|
+
export type InferParams<T extends ZodSchema> = z.infer<T>;
|
|
179
|
+
/**
|
|
180
|
+
* Infer the headers type from a route handler
|
|
181
|
+
* @example
|
|
182
|
+
* const handler = (headers: InferHeaders<typeof HeadersSchema>) => { ... }
|
|
183
|
+
*/
|
|
184
|
+
export type InferHeaders<T extends ZodSchema> = z.infer<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Extract the return type of a handler function
|
|
187
|
+
* @example
|
|
188
|
+
* const handler = async () => ({ id: 1, name: 'John' });
|
|
189
|
+
* type Response = InferResponse<typeof handler>; // { id: number; name: string }
|
|
190
|
+
*/
|
|
191
|
+
export type InferResponse<T extends (...args: any[]) => any> = Awaited<ReturnType<T>>;
|
|
192
|
+
/**
|
|
193
|
+
* Extract the dependency type from a provider
|
|
194
|
+
* @example
|
|
195
|
+
* class UserService { ... }
|
|
196
|
+
* type Service = InferDependency<typeof UserService>; // UserService
|
|
197
|
+
*/
|
|
198
|
+
export type InferDependency<T extends Provider> = T extends Class<infer R> ? R : T extends () => infer R ? R : T extends () => Promise<infer R> ? R : never;
|
|
199
|
+
/**
|
|
200
|
+
* Type-safe route handler with inferred parameter types
|
|
201
|
+
* @example
|
|
202
|
+
* const handler: TypedHandler<typeof BodySchema, typeof QuerySchema> =
|
|
203
|
+
* async (body, query) => { ... }
|
|
204
|
+
*/
|
|
205
|
+
export type TypedHandler<TBody extends ZodSchema = any, TQuery extends ZodSchema = any, TParams extends ZodSchema = any, TResponse = any> = (body?: z.infer<TBody>, query?: z.infer<TQuery>, params?: z.infer<TParams>, context?: Context) => TResponse | Promise<TResponse>;
|
|
206
|
+
/**
|
|
207
|
+
* Utility type to make all properties of T optional recursively
|
|
208
|
+
*/
|
|
209
|
+
export type DeepPartial<T> = {
|
|
210
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Utility type to make all properties of T required recursively
|
|
214
|
+
*/
|
|
215
|
+
export type DeepRequired<T> = {
|
|
216
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Extract keys from T that are of type U
|
|
220
|
+
*/
|
|
221
|
+
export type KeysOfType<T, U> = {
|
|
222
|
+
[K in keyof T]: T[K] extends U ? K : never;
|
|
223
|
+
}[keyof T];
|
|
224
|
+
/**
|
|
225
|
+
* Make specific keys K of T optional
|
|
226
|
+
*/
|
|
227
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
228
|
+
/**
|
|
229
|
+
* Make specific keys K of T required
|
|
230
|
+
*/
|
|
231
|
+
export type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
232
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAQ,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,YAAY,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC;AAG1C,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ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AAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ZodError } from 'zod';
|
|
2
|
+
import { HTTPException } from '../errors/exceptions.js';
|
|
3
|
+
/**
|
|
4
|
+
* ValidationException is thrown when Zod validation fails
|
|
5
|
+
* Extends HTTPException with 422 Unprocessable Entity status
|
|
6
|
+
* Provides detailed validation error information
|
|
7
|
+
*/
|
|
8
|
+
export declare class ValidationException extends HTTPException {
|
|
9
|
+
zodError: ZodError;
|
|
10
|
+
constructor(zodError: ZodError);
|
|
11
|
+
/**
|
|
12
|
+
* Converts the validation error to a user-friendly JSON format
|
|
13
|
+
* @returns Object with error message and detailed validation errors
|
|
14
|
+
*/
|
|
15
|
+
toJSON(): {
|
|
16
|
+
error: string;
|
|
17
|
+
statusCode: number;
|
|
18
|
+
details: {
|
|
19
|
+
path: string;
|
|
20
|
+
message: string;
|
|
21
|
+
code: "custom" | "invalid_type" | "invalid_literal" | "unrecognized_keys" | "invalid_union" | "invalid_union_discriminator" | "invalid_enum_value" | "invalid_arguments" | "invalid_return_type" | "invalid_date" | "invalid_string" | "too_small" | "too_big" | "invalid_intersection_types" | "not_multiple_of" | "not_finite";
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../../src/validation/exceptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;IACjC,QAAQ,EAAE,QAAQ;gBAAlB,QAAQ,EAAE,QAAQ;IAKrC;;;OAGG;IACH,MAAM;;;;;;;;;CAWP"}
|