-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
126 lines (107 loc) · 3.04 KB
/
Copy pathindex.d.ts
File metadata and controls
126 lines (107 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// index.d.ts
declare module "simple_framework_js" {
import { IncomingMessage, ServerResponse, Server } from "http";
import { ParsedUrlQuery } from "querystring";
import { Pool, PoolOptions } from "mysql2/promise";
export interface DatabaseConfig {
host?: string;
user: string;
password: string;
database: string;
[key: string]: any;
}
export interface RouteParams {
[key: string]: string;
}
export interface Request extends IncomingMessage {
path: string;
params: RouteParams;
body: any;
query(sql: string, params?: any[]): Promise<any>;
}
export interface Response extends ServerResponse {
json(data: any): void;
send(data: string | number): void;
status(code: number): Response;
}
export type RouteHandler = (
req: Request,
res: Response
) => void | Promise<void>;
export interface RouteMatch {
handler: RouteHandler;
params: RouteParams;
}
export interface Routes {
GET: { [path: string]: RouteHandler };
POST: { [path: string]: RouteHandler };
}
export class SimpleFramework {
routes: Routes;
dbConfig: DatabaseConfig | null;
dbPool: Pool | null;
constructor();
/**
* Configure database connection
* @param config Database configuration object
*/
database(config: DatabaseConfig): void;
/**
* Execute SQL queries
* @param sql SQL query string
* @param params Query parameters
* @returns Promise resolving to query results
*/
query(sql: string, params?: any[]): Promise<any>;
/**
* Register GET route handler
* @param path Route path (supports parameters like /users/:id)
* @param handler Route handler function
*/
get(path: string, handler: RouteHandler): void;
/**
* Register POST route handler
* @param path Route path (supports parameters like /users/:id)
* @param handler Route handler function
*/
post(path: string, handler: RouteHandler): void;
/**
* Parse request body for POST requests
* @param req Incoming request
* @returns Promise resolving to parsed body
*/
parseBody(req: IncomingMessage): Promise<any>;
/**
* Create enhanced request and response objects
* @param req Incoming request
* @param res Server response
* @returns Enhanced request and response objects
*/
createReqRes(
req: IncomingMessage,
res: ServerResponse
): {
request: Request;
response: Response;
};
/**
* Match route with parameters
* @param method HTTP method
* @param path Request path
* @returns Route match object or null
*/
matchRoute(method: string, path: string): RouteMatch | null;
/**
* Start the HTTP server
* @param port Port number to listen on
* @param callback Optional callback function
* @returns HTTP Server instance
*/
listen(port: number, callback?: () => void): Server;
/**
* Close database connections
*/
close(): Promise<void>;
}
export default SimpleFramework;
}