@je-es/server 0.1.2 → 0.1.4
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/README.md +333 -838
- package/dist/main.cjs +2 -2
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.cts +200 -266
- package/dist/main.d.ts +200 -266
- package/dist/main.js +2 -2
- package/dist/main.js.map +1 -1
- package/package.json +7 -4
package/dist/main.d.cts
CHANGED
|
@@ -1,62 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
match(method: string, path: string): {
|
|
5
|
-
handler: any;
|
|
6
|
-
params: Record<string, string>;
|
|
7
|
-
} | null;
|
|
8
|
-
getAll(): {
|
|
9
|
-
method: string;
|
|
10
|
-
path: string;
|
|
11
|
-
handler: any;
|
|
12
|
-
}[];
|
|
13
|
-
clear(): void;
|
|
14
|
-
remove(method: string, path: string): boolean;
|
|
15
|
-
register(method: string, path: string, handler: any, config?: any): void;
|
|
16
|
-
private pathToRegex;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare class SecurityManager {
|
|
20
|
-
private rateLimitStore;
|
|
21
|
-
private csrfTokens;
|
|
22
|
-
private requestLog;
|
|
23
|
-
private readonly MAX_REQUEST_LOG_SIZE;
|
|
24
|
-
checkRateLimit(key: string, max: number, windowMs: number): boolean;
|
|
25
|
-
cleanupRateLimit(): void;
|
|
26
|
-
generateCsrfToken(sessionId: string, ttl?: number): string;
|
|
27
|
-
validateCsrfToken(token: string, sessionId: string): boolean;
|
|
28
|
-
cleanupCsrfTokens(): void;
|
|
29
|
-
sanitizeHtml(html: string): string;
|
|
30
|
-
sanitizeSql(input: string): string;
|
|
31
|
-
logRequest(id: string, method: string, path: string, ip: string, status: number, duration: number): void;
|
|
32
|
-
getRequestLog(id: string): any;
|
|
33
|
-
getAllRequestLogs(): any[];
|
|
34
|
-
clearAll(): void;
|
|
35
|
-
getStats(): {
|
|
36
|
-
rateLimitEntries: number;
|
|
37
|
-
csrfTokens: number;
|
|
38
|
-
requestLogs: number;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
declare class Logger$1 {
|
|
43
|
-
private level;
|
|
44
|
-
private pretty;
|
|
45
|
-
private levels;
|
|
46
|
-
private colors;
|
|
47
|
-
constructor(level?: 'debug' | 'info' | 'warn' | 'error', pretty?: boolean);
|
|
48
|
-
debug(data: any, msg?: string): void;
|
|
49
|
-
info(data: any, msg?: string): void;
|
|
50
|
-
warn(data: any, msg?: string): void;
|
|
51
|
-
error(data: any, msg?: string): void;
|
|
52
|
-
fatal(data: any, msg?: string): void;
|
|
53
|
-
private log;
|
|
54
|
-
private prettyLog;
|
|
55
|
-
private colorizeMethod;
|
|
56
|
-
private colorizeStatus;
|
|
57
|
-
private getLevelIcon;
|
|
58
|
-
private getLevelColor;
|
|
59
|
-
}
|
|
1
|
+
import { DB } from '@je-es/sdb';
|
|
2
|
+
export { ColumnDefinition, ColumnType, DB, QueryBuilder, SqlValue, TableSchema, WhereCondition, blob, column, defaultValue, integer, notNull, numeric, primaryKey, real, references, table, text, unique } from '@je-es/sdb';
|
|
3
|
+
export { Logger } from '@je-es/slog';
|
|
60
4
|
|
|
61
5
|
// src/types.d.ts
|
|
62
6
|
//
|
|
@@ -64,304 +8,294 @@ declare class Logger$1 {
|
|
|
64
8
|
|
|
65
9
|
|
|
66
10
|
|
|
11
|
+
// ╚══════════════════════════════════════════════════════════════════════════════════════╝
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
67
15
|
// ╔════════════════════════════════════════ TYPE ════════════════════════════════════════╗
|
|
68
16
|
|
|
69
|
-
|
|
70
|
-
type
|
|
71
|
-
type
|
|
17
|
+
|
|
18
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
|
19
|
+
type RouteHandler$1 = (c: AppContext) => Response | Promise<Response>;
|
|
20
|
+
type AppMiddleware = (c: AppContext, next: () => Promise<void>) => void | Promise<void>;
|
|
72
21
|
|
|
73
22
|
interface AppContext {
|
|
74
|
-
ip : string
|
|
75
|
-
request : Request
|
|
76
|
-
params : Record<string, string
|
|
77
|
-
query : Record<string,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
23
|
+
ip : string;
|
|
24
|
+
request : Request;
|
|
25
|
+
params : Record<string, string>;
|
|
26
|
+
query : Record<string, string>;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
body : any;
|
|
29
|
+
headers : Headers;
|
|
30
|
+
db : DB | undefined;
|
|
31
|
+
logger : Logger | null;
|
|
32
|
+
user? : unknown;
|
|
33
|
+
requestId : string;
|
|
84
34
|
|
|
85
35
|
// Response methods
|
|
86
|
-
json (data:
|
|
87
|
-
text (data: string, status?: number): Response
|
|
88
|
-
html (data: string, status?: number): Response
|
|
89
|
-
redirect (url: string, status?: number): Response
|
|
90
|
-
file (path: string, contentType?: string): Response
|
|
36
|
+
json (data: unknown, status?: number): Response;
|
|
37
|
+
text (data: string, status?: number): Response;
|
|
38
|
+
html (data: string, status?: number): Response;
|
|
39
|
+
redirect (url: string, status?: number): Response;
|
|
40
|
+
file (path: string, contentType?: string): Response;
|
|
91
41
|
|
|
92
42
|
// Cookie methods
|
|
93
|
-
setCookie (name: string, value: string, options?: CookieOptions): AppContext
|
|
94
|
-
getCookie (name: string): string | undefined
|
|
95
|
-
deleteCookie (name: string, options?: Partial<CookieOptions>): AppContext
|
|
43
|
+
setCookie (name: string, value: string, options?: CookieOptions): AppContext;
|
|
44
|
+
getCookie (name: string): string | undefined;
|
|
45
|
+
deleteCookie (name: string, options?: Partial<CookieOptions>): AppContext;
|
|
96
46
|
|
|
97
47
|
// Header methods
|
|
98
|
-
setHeader(key: string, value: string): AppContext
|
|
99
|
-
getHeader(key: string): string | undefined
|
|
48
|
+
setHeader(key: string, value: string): AppContext;
|
|
49
|
+
getHeader(key: string): string | undefined;
|
|
100
50
|
|
|
101
51
|
// Status code
|
|
102
|
-
status(code: number): AppContext
|
|
103
|
-
statusCode: number
|
|
52
|
+
status(code: number): AppContext;
|
|
53
|
+
statusCode: number;
|
|
54
|
+
|
|
55
|
+
// Internal helper
|
|
56
|
+
_setCookieHeaders(): Record<string, string | string[]>;
|
|
104
57
|
}
|
|
105
58
|
|
|
106
59
|
interface StaticConfig$1 {
|
|
107
|
-
path : string // URL path prefix (e.g., '/public' or '/static')
|
|
108
|
-
directory : string // Local directory to serve from
|
|
109
|
-
maxAge? : number // Cache control in seconds (default: 3600)
|
|
110
|
-
index? : string[] // Index files (default: ['index.html'])
|
|
111
|
-
dotfiles? : 'allow' | 'deny' | 'ignore' // How to handle dotfiles (default: 'deny')
|
|
112
|
-
etag? : boolean // Enable ETag headers (default: true)
|
|
113
|
-
lastModified? : boolean // Enable Last-Modified headers (default: true)
|
|
114
|
-
immutable? : boolean // Add immutable to cache-control (default: false)
|
|
115
|
-
extensions? : string[] // Try these extensions if file not found (e.g., ['html', 'htm'])
|
|
116
|
-
fallthrough? : boolean // Continue to next handler if file not found (default: false)
|
|
117
|
-
setHeaders? : (ctx: AppContext, path: string) => void // Custom header setter
|
|
60
|
+
path : string; // URL path prefix (e.g., '/public' or '/static')
|
|
61
|
+
directory : string; // Local directory to serve from
|
|
62
|
+
maxAge? : number; // Cache control in seconds (default: 3600)
|
|
63
|
+
index? : string[]; // Index files (default: ['index.html'])
|
|
64
|
+
dotfiles? : 'allow' | 'deny' | 'ignore'; // How to handle dotfiles (default: 'deny')
|
|
65
|
+
etag? : boolean; // Enable ETag headers (default: true)
|
|
66
|
+
lastModified? : boolean; // Enable Last-Modified headers (default: true)
|
|
67
|
+
immutable? : boolean; // Add immutable to cache-control (default: false)
|
|
68
|
+
extensions? : string[]; // Try these extensions if file not found (e.g., ['html', 'htm'])
|
|
69
|
+
fallthrough? : boolean; // Continue to next handler if file not found (default: false)
|
|
70
|
+
setHeaders? : (ctx: AppContext, path: string) => void; // Custom header setter
|
|
118
71
|
}
|
|
119
72
|
|
|
120
73
|
interface CookieOptions {
|
|
121
|
-
maxAge? : number
|
|
122
|
-
expires? : Date
|
|
123
|
-
path? : string
|
|
124
|
-
domain? : string
|
|
125
|
-
secure? : boolean
|
|
126
|
-
httpOnly? : boolean
|
|
127
|
-
sameSite? : 'Strict' | 'Lax' | 'None'
|
|
74
|
+
maxAge? : number;
|
|
75
|
+
expires? : Date;
|
|
76
|
+
path? : string;
|
|
77
|
+
domain? : string;
|
|
78
|
+
secure? : boolean;
|
|
79
|
+
httpOnly? : boolean;
|
|
80
|
+
sameSite? : 'Strict' | 'Lax' | 'None';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface ValidationSchema {
|
|
84
|
+
body?: unknown;
|
|
85
|
+
query?: unknown;
|
|
86
|
+
params?: unknown;
|
|
128
87
|
}
|
|
129
88
|
|
|
130
89
|
interface RouteDefinition {
|
|
131
|
-
method : HttpMethod | HttpMethod[]
|
|
132
|
-
path : string
|
|
133
|
-
handler : RouteHandler
|
|
134
|
-
validate? :
|
|
135
|
-
middlewares? : AppMiddleware[]
|
|
136
|
-
timeout? : number
|
|
137
|
-
rateLimit? : { max: number; windowMs: number }
|
|
138
|
-
cache? : number
|
|
139
|
-
tags? : string[]
|
|
90
|
+
method : HttpMethod | HttpMethod[];
|
|
91
|
+
path : string;
|
|
92
|
+
handler : RouteHandler$1;
|
|
93
|
+
validate? : ValidationSchema;
|
|
94
|
+
middlewares? : AppMiddleware[];
|
|
95
|
+
timeout? : number;
|
|
96
|
+
rateLimit? : { max: number; windowMs: number };
|
|
97
|
+
cache? : number;
|
|
98
|
+
tags? : string[];
|
|
140
99
|
}
|
|
141
100
|
|
|
101
|
+
// Database types
|
|
142
102
|
interface DatabaseConfig {
|
|
143
|
-
name? : string
|
|
144
|
-
connection : string // File path or ':memory:'
|
|
145
|
-
schema? : Record<string,
|
|
146
|
-
timeout? : number
|
|
103
|
+
name? : string;
|
|
104
|
+
connection : string; // File path or ':memory:'
|
|
105
|
+
schema? : Record<string, unknown>;
|
|
106
|
+
timeout? : number;
|
|
147
107
|
}
|
|
148
108
|
|
|
149
109
|
interface SecurityConfig {
|
|
150
|
-
cors? : boolean | CorsConfig
|
|
151
|
-
rateLimit? : boolean | RateLimitConfig
|
|
152
|
-
csrf? : boolean | CsrfConfig
|
|
153
|
-
helmet? : boolean | HelmetConfig
|
|
154
|
-
auth? : boolean | AuthConfig
|
|
155
|
-
validation? : boolean
|
|
156
|
-
sanitize? : boolean
|
|
110
|
+
cors? : boolean | CorsConfig;
|
|
111
|
+
rateLimit? : boolean | RateLimitConfig;
|
|
112
|
+
csrf? : boolean | CsrfConfig;
|
|
113
|
+
helmet? : boolean | HelmetConfig;
|
|
114
|
+
auth? : boolean | AuthConfig;
|
|
115
|
+
validation? : boolean;
|
|
116
|
+
sanitize? : boolean;
|
|
157
117
|
}
|
|
158
118
|
|
|
159
119
|
interface CorsConfig {
|
|
160
|
-
origin? : string | string[] | ((origin: string) => boolean)
|
|
161
|
-
methods? : HttpMethod[]
|
|
162
|
-
allowedHeaders? : string[]
|
|
163
|
-
credentials? : boolean
|
|
164
|
-
maxAge? : number
|
|
120
|
+
origin? : string | string[] | ((origin: string) => boolean);
|
|
121
|
+
methods? : HttpMethod[];
|
|
122
|
+
allowedHeaders? : string[];
|
|
123
|
+
credentials? : boolean;
|
|
124
|
+
maxAge? : number;
|
|
165
125
|
}
|
|
166
126
|
|
|
167
127
|
interface RateLimitConfig {
|
|
168
|
-
windowMs? : number
|
|
169
|
-
max? : number
|
|
170
|
-
keyGenerator? : (c: AppContext) => string
|
|
171
|
-
message? : string
|
|
128
|
+
windowMs? : number;
|
|
129
|
+
max? : number;
|
|
130
|
+
keyGenerator? : (c: AppContext) => string;
|
|
131
|
+
message? : string;
|
|
172
132
|
}
|
|
173
133
|
|
|
174
134
|
interface CsrfConfig {
|
|
175
|
-
secret? : string
|
|
176
|
-
headerName? : string
|
|
177
|
-
tokenTTL? : number
|
|
135
|
+
secret? : string;
|
|
136
|
+
headerName? : string;
|
|
137
|
+
tokenTTL? : number;
|
|
178
138
|
}
|
|
179
139
|
|
|
180
140
|
interface HelmetConfig {
|
|
181
|
-
contentSecurityPolicy? : Record<string, string[]> | boolean
|
|
182
|
-
hsts? : boolean | { maxAge?: number; includeSubDomains?: boolean; preload?: boolean }
|
|
183
|
-
frameguard? : boolean | { action: 'deny' | 'sameorigin' }
|
|
184
|
-
noSniff? : boolean
|
|
185
|
-
xssFilter? : boolean
|
|
186
|
-
referrerPolicy? : string | boolean
|
|
141
|
+
contentSecurityPolicy? : Record<string, string[]> | boolean;
|
|
142
|
+
hsts? : boolean | { maxAge?: number; includeSubDomains?: boolean; preload?: boolean };
|
|
143
|
+
frameguard? : boolean | { action: 'deny' | 'sameorigin' };
|
|
144
|
+
noSniff? : boolean;
|
|
145
|
+
xssFilter? : boolean;
|
|
146
|
+
referrerPolicy? : string | boolean;
|
|
187
147
|
}
|
|
188
148
|
|
|
189
149
|
interface AuthConfig {
|
|
190
|
-
jwt? : boolean | { secret: string; expiresIn?: string }
|
|
191
|
-
apiKey? : boolean | { header?: string }
|
|
192
|
-
bearer? : boolean
|
|
150
|
+
jwt? : boolean | { secret: string; expiresIn?: string };
|
|
151
|
+
apiKey? : boolean | { header?: string };
|
|
152
|
+
bearer? : boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
156
|
+
|
|
157
|
+
interface LoggingConfig {
|
|
158
|
+
level?: LogLevel;
|
|
159
|
+
pretty?: boolean;
|
|
193
160
|
}
|
|
194
161
|
|
|
195
162
|
interface ServerConfig {
|
|
196
|
-
port? : number | string
|
|
197
|
-
hostname? : string
|
|
198
|
-
requestTimeout? : number
|
|
199
|
-
maxRequestSize? : number
|
|
200
|
-
maxJsonSize? : number
|
|
163
|
+
port? : number | string;
|
|
164
|
+
hostname? : string;
|
|
165
|
+
requestTimeout? : number;
|
|
166
|
+
maxRequestSize? : number;
|
|
167
|
+
maxJsonSize? : number;
|
|
201
168
|
|
|
202
|
-
database? : DatabaseConfig | DatabaseConfig[]
|
|
169
|
+
database? : DatabaseConfig | DatabaseConfig[];
|
|
203
170
|
|
|
204
|
-
security? : boolean | SecurityConfig
|
|
171
|
+
security? : boolean | SecurityConfig;
|
|
205
172
|
|
|
206
|
-
compression? : boolean | { threshold?: number }
|
|
173
|
+
compression? : boolean | { threshold?: number };
|
|
207
174
|
|
|
208
|
-
logging? : boolean |
|
|
175
|
+
logging? : boolean | LoggingConfig;
|
|
209
176
|
|
|
210
177
|
// Static file serving
|
|
211
|
-
static? : StaticConfig$1 | StaticConfig$1[]
|
|
178
|
+
static? : StaticConfig$1 | StaticConfig$1[];
|
|
212
179
|
|
|
213
|
-
routes? : RouteDefinition[]
|
|
214
|
-
middlewares? : AppMiddleware[]
|
|
180
|
+
routes? : RouteDefinition[];
|
|
181
|
+
middlewares? : AppMiddleware[];
|
|
215
182
|
|
|
216
|
-
errorHandler? : (error: Error, context: AppContext) => void | Promise<void
|
|
217
|
-
onShutdown? : () => void | Promise<void
|
|
183
|
+
errorHandler? : (error: Error, context: AppContext) => void | Promise<void>;
|
|
184
|
+
onShutdown? : () => void | Promise<void>;
|
|
218
185
|
|
|
219
|
-
apiPrefix? : string
|
|
220
|
-
apiVersion? : string
|
|
186
|
+
apiPrefix? : string;
|
|
187
|
+
apiVersion? : string;
|
|
221
188
|
|
|
222
|
-
gracefulShutdownTimeout?: number
|
|
189
|
+
gracefulShutdownTimeout?: number;
|
|
223
190
|
}
|
|
224
191
|
|
|
225
192
|
interface ServerInstance {
|
|
226
|
-
app :
|
|
227
|
-
logger : Logger | null
|
|
228
|
-
db : Map<string,
|
|
229
|
-
bunServer :
|
|
230
|
-
start : () => Promise<void
|
|
231
|
-
stop : () => Promise<void
|
|
232
|
-
addRoute : (route: RouteDefinition) => void
|
|
233
|
-
addRoutes : (routes: RouteDefinition[]) => void
|
|
234
|
-
getRoutes : () => RouteDefinition[]
|
|
193
|
+
app : unknown;
|
|
194
|
+
logger : Logger | null;
|
|
195
|
+
db : Map<string, unknown>;
|
|
196
|
+
bunServer : unknown;
|
|
197
|
+
start : () => Promise<void>;
|
|
198
|
+
stop : () => Promise<void>;
|
|
199
|
+
addRoute : (route: RouteDefinition) => void;
|
|
200
|
+
addRoutes : (routes: RouteDefinition[]) => void;
|
|
201
|
+
getRoutes : () => RouteDefinition[];
|
|
235
202
|
}
|
|
236
203
|
|
|
237
204
|
interface Logger {
|
|
238
|
-
debug (data:
|
|
239
|
-
info (data:
|
|
240
|
-
warn (data:
|
|
241
|
-
error (data:
|
|
242
|
-
fatal (data:
|
|
205
|
+
debug (data: unknown, msg?: string): void;
|
|
206
|
+
info (data: unknown, msg?: string): void;
|
|
207
|
+
warn (data: unknown, msg?: string): void;
|
|
208
|
+
error (data: unknown, msg?: string): void;
|
|
209
|
+
fatal (data: unknown, msg?: string): void;
|
|
243
210
|
}
|
|
244
211
|
|
|
245
212
|
declare class AppError extends Error {
|
|
246
213
|
constructor(public message: string, public statusCode: number = 500, public code?: string) {
|
|
247
|
-
super(message)
|
|
248
|
-
this.name = 'AppError'
|
|
214
|
+
super(message);
|
|
215
|
+
this.name = 'AppError';
|
|
249
216
|
}
|
|
250
217
|
}
|
|
251
218
|
|
|
252
219
|
declare class ValidationError extends AppError {
|
|
253
|
-
constructor(message: string, public issues?:
|
|
254
|
-
super(message, 400, 'VALIDATION_ERROR')
|
|
255
|
-
this.name = 'ValidationError'
|
|
220
|
+
constructor(message: string, public issues?: unknown) {
|
|
221
|
+
super(message, 400, 'VALIDATION_ERROR');
|
|
222
|
+
this.name = 'ValidationError';
|
|
256
223
|
}
|
|
257
224
|
}
|
|
258
225
|
|
|
259
226
|
declare class DatabaseError extends AppError {
|
|
260
227
|
constructor(message: string) {
|
|
261
|
-
super(message, 500, 'DATABASE_ERROR')
|
|
262
|
-
this.name = 'DatabaseError'
|
|
228
|
+
super(message, 500, 'DATABASE_ERROR');
|
|
229
|
+
this.name = 'DatabaseError';
|
|
263
230
|
}
|
|
264
231
|
}
|
|
265
232
|
|
|
266
233
|
declare class TimeoutError extends AppError {
|
|
267
234
|
constructor(message = 'Request timeout') {
|
|
268
|
-
super(message, 408, 'TIMEOUT_ERROR')
|
|
269
|
-
this.name = 'TimeoutError'
|
|
235
|
+
super(message, 408, 'TIMEOUT_ERROR');
|
|
236
|
+
this.name = 'TimeoutError';
|
|
270
237
|
}
|
|
271
238
|
}
|
|
272
239
|
|
|
273
240
|
declare class RateLimitError extends AppError {
|
|
274
241
|
constructor(message = 'Too many requests') {
|
|
275
|
-
super(message, 429, 'RATE_LIMIT_ERROR')
|
|
276
|
-
this.name = 'RateLimitError'
|
|
242
|
+
super(message, 429, 'RATE_LIMIT_ERROR');
|
|
243
|
+
this.name = 'RateLimitError';
|
|
277
244
|
}
|
|
278
245
|
}
|
|
279
246
|
|
|
280
|
-
type
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
type: ColumnType;
|
|
285
|
-
primaryKey?: boolean;
|
|
286
|
-
autoIncrement?: boolean;
|
|
287
|
-
notNull?: boolean;
|
|
288
|
-
unique?: boolean;
|
|
289
|
-
default?: SqlValue;
|
|
290
|
-
references?: {
|
|
291
|
-
table: string;
|
|
292
|
-
column: string;
|
|
293
|
-
};
|
|
247
|
+
type RouteHandler = (ctx: AppContext) => Response | Promise<Response>;
|
|
248
|
+
interface RouteMatch {
|
|
249
|
+
handler: RouteHandler;
|
|
250
|
+
params: Record<string, string>;
|
|
294
251
|
}
|
|
295
|
-
interface
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
name: string;
|
|
300
|
-
columns: string[];
|
|
301
|
-
unique?: boolean;
|
|
302
|
-
}[];
|
|
252
|
+
interface RouteInfo {
|
|
253
|
+
method: string;
|
|
254
|
+
path: string;
|
|
255
|
+
handler: RouteHandler;
|
|
303
256
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
257
|
+
declare class Router {
|
|
258
|
+
private routes;
|
|
259
|
+
private regexRoutes;
|
|
260
|
+
match(method: string, path: string): RouteMatch | null;
|
|
261
|
+
getAll(): RouteInfo[];
|
|
262
|
+
clear(): void;
|
|
263
|
+
remove(method: string, path: string): boolean;
|
|
264
|
+
register(method: string, path: string, handler: RouteHandler, _?: unknown): void;
|
|
265
|
+
private pathToRegex;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
interface RequestLogEntry {
|
|
269
|
+
timestamp: string;
|
|
270
|
+
method: string;
|
|
271
|
+
path: string;
|
|
272
|
+
ip: string;
|
|
273
|
+
status: number;
|
|
274
|
+
duration: number;
|
|
308
275
|
}
|
|
309
|
-
interface
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
and: (condition: WhereCondition) => QueryBuilder;
|
|
314
|
-
or: (condition: WhereCondition) => QueryBuilder;
|
|
315
|
-
orderBy: (column: string, direction?: 'ASC' | 'DESC') => QueryBuilder;
|
|
316
|
-
limit: (count: number) => QueryBuilder;
|
|
317
|
-
offset: (count: number) => QueryBuilder;
|
|
318
|
-
insert: (table: string, data: Record<string, SqlValue>) => QueryBuilder;
|
|
319
|
-
update: (table: string, data: Record<string, SqlValue>) => QueryBuilder;
|
|
320
|
-
delete: (table: string) => QueryBuilder;
|
|
321
|
-
execute: () => any[];
|
|
322
|
-
executeOne: () => any | null;
|
|
323
|
-
executeRaw: (sql: string, params?: SqlValue[]) => any[];
|
|
324
|
-
raw: (sql: string, params?: SqlValue[]) => QueryBuilder;
|
|
276
|
+
interface SecurityStats {
|
|
277
|
+
rateLimitEntries: number;
|
|
278
|
+
csrfTokens: number;
|
|
279
|
+
requestLogs: number;
|
|
325
280
|
}
|
|
326
|
-
declare class
|
|
327
|
-
private
|
|
328
|
-
private
|
|
329
|
-
private
|
|
330
|
-
private
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
update(table: string, id: number | string, data: Record<string, SqlValue>): any | null;
|
|
344
|
-
delete(table: string, id: number | string): boolean;
|
|
345
|
-
transaction(callback: (db: DB) => void): void;
|
|
346
|
-
exec(sql: string): void;
|
|
347
|
-
raw(sql: string, params?: SqlValue[]): any[];
|
|
348
|
-
rawOne(sql: string, params?: SqlValue[]): any | null;
|
|
349
|
-
private reset;
|
|
350
|
-
private createQueryBuilder;
|
|
351
|
-
private generateCreateTableSQL;
|
|
281
|
+
declare class SecurityManager {
|
|
282
|
+
private rateLimitStore;
|
|
283
|
+
private csrfTokens;
|
|
284
|
+
private requestLog;
|
|
285
|
+
private readonly MAX_REQUEST_LOG_SIZE;
|
|
286
|
+
checkRateLimit(key: string, max: number, windowMs: number): boolean;
|
|
287
|
+
cleanupRateLimit(): void;
|
|
288
|
+
generateCsrfToken(sessionId: string, ttl?: number): string;
|
|
289
|
+
validateCsrfToken(token: string, sessionId: string): boolean;
|
|
290
|
+
cleanupCsrfTokens(): void;
|
|
291
|
+
sanitizeHtml(html: string): string;
|
|
292
|
+
sanitizeSql(input: string): string;
|
|
293
|
+
logRequest(id: string, method: string, path: string, ip: string, status: number, duration: number): void;
|
|
294
|
+
getRequestLog(id: string): RequestLogEntry | undefined;
|
|
295
|
+
getAllRequestLogs(): RequestLogEntry[];
|
|
296
|
+
clearAll(): void;
|
|
297
|
+
getStats(): SecurityStats;
|
|
352
298
|
}
|
|
353
|
-
declare function table(name: string, columns: ColumnDefinition[]): TableSchema;
|
|
354
|
-
declare function column(name: string, type: ColumnType): ColumnDefinition;
|
|
355
|
-
declare function integer(name: string): ColumnDefinition;
|
|
356
|
-
declare function text(name: string): ColumnDefinition;
|
|
357
|
-
declare function real(name: string): ColumnDefinition;
|
|
358
|
-
declare function blob(name: string): ColumnDefinition;
|
|
359
|
-
declare function numeric(name: string): ColumnDefinition;
|
|
360
|
-
declare function primaryKey(col: ColumnDefinition, autoIncrement?: boolean): ColumnDefinition;
|
|
361
|
-
declare function notNull(col: ColumnDefinition): ColumnDefinition;
|
|
362
|
-
declare function unique(col: ColumnDefinition): ColumnDefinition;
|
|
363
|
-
declare function defaultValue(col: ColumnDefinition, value: SqlValue): ColumnDefinition;
|
|
364
|
-
declare function references(col: ColumnDefinition, table: string, column: string): ColumnDefinition;
|
|
365
299
|
|
|
366
300
|
interface StaticConfig {
|
|
367
301
|
path: string;
|
|
@@ -417,4 +351,4 @@ declare function createStatic(config: StaticConfig): StaticFileServer;
|
|
|
417
351
|
|
|
418
352
|
declare function server(config?: ServerConfig): ServerInstance;
|
|
419
353
|
|
|
420
|
-
export { type AppContext, AppError, type AppMiddleware, type AuthConfig, type
|
|
354
|
+
export { type AppContext, AppError, type AppMiddleware, type AuthConfig, type CookieOptions, type CorsConfig, type CsrfConfig, type DatabaseConfig, DatabaseError, type HelmetConfig, type HttpMethod, type LogLevel, type LoggingConfig, type RateLimitConfig, RateLimitError, type RouteDefinition, type RouteHandler$1 as RouteHandler, Router, type SecurityConfig, SecurityManager, type ServerConfig, type ServerInstance, type StaticConfig, StaticFileServer, TimeoutError, ValidationError, type ValidationSchema, createStatic, server as default, server };
|