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