yinzerflow 0.1.18 → 0.2.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/README.md +0 -296
- package/YinzerFlow.d.ts +565 -0
- package/YinzerFlow.js +24 -0
- package/YinzerFlow.js.map +42 -0
- package/docs/advanced-configuration-options.md +175 -0
- package/docs/body-parsing.md +294 -0
- package/docs/cors.md +187 -0
- package/docs/ip-security.md +232 -0
- package/docs/request.md +145 -0
- package/docs/response.md +251 -0
- package/docs/start-here.MD +116 -0
- package/example/index.ts +109 -53
- package/package.json +15 -17
- package/constants/index.d.ts +0 -86
- package/constants/index.js +0 -3
- package/constants/index.js.map +0 -13
- package/docs/README.md +0 -327
- package/docs/content-types.md +0 -390
- package/docs/error-handling.md +0 -266
- package/docs/file-parsers.md +0 -276
- package/docs/hooks.md +0 -289
- package/docs/routing.md +0 -204
- package/example/bun.lock +0 -866
- package/example/hooks/authentication.middleware.ts +0 -77
- package/example/package.json +0 -61
- package/example/routes/authentication.routes.ts +0 -243
- package/example/routes/content-types.ts +0 -116
- package/example/tsconfig.json +0 -32
- package/index.d.ts +0 -395
- package/index.js +0 -23
- package/index.js.map +0 -33
package/index.d.ts
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
export declare const HttpStatus: {
|
|
2
|
-
readonly OK: "OK";
|
|
3
|
-
readonly CREATED: "Created";
|
|
4
|
-
readonly NO_CONTENT: "No Content";
|
|
5
|
-
readonly BAD_REQUEST: "Bad Request";
|
|
6
|
-
readonly UNAUTHORIZED: "Unauthorized";
|
|
7
|
-
readonly FORBIDDEN: "Forbidden";
|
|
8
|
-
readonly NOT_FOUND: "Not Found";
|
|
9
|
-
readonly METHOD_NOT_ALLOWED: "Method Not Allowed";
|
|
10
|
-
readonly CONFLICT: "Conflict";
|
|
11
|
-
readonly UNSUPPORTED_MEDIA_TYPE: "Unsupported Media Type";
|
|
12
|
-
readonly TOO_MANY_REQUESTS: "Too Many Requests";
|
|
13
|
-
readonly INTERNAL_SERVER_ERROR: "Internal Server Error";
|
|
14
|
-
};
|
|
15
|
-
export declare const HttpStatusCode: {
|
|
16
|
-
readonly OK: 200;
|
|
17
|
-
readonly CREATED: 201;
|
|
18
|
-
readonly NO_CONTENT: 204;
|
|
19
|
-
readonly BAD_REQUEST: 400;
|
|
20
|
-
readonly UNAUTHORIZED: 401;
|
|
21
|
-
readonly FORBIDDEN: 403;
|
|
22
|
-
readonly NOT_FOUND: 404;
|
|
23
|
-
readonly METHOD_NOT_ALLOWED: 405;
|
|
24
|
-
readonly CONFLICT: 409;
|
|
25
|
-
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
26
|
-
readonly TOO_MANY_REQUESTS: 429;
|
|
27
|
-
readonly INTERNAL_SERVER_ERROR: 500;
|
|
28
|
-
};
|
|
29
|
-
export declare const HttpMethod: {
|
|
30
|
-
readonly DELETE: "DELETE";
|
|
31
|
-
readonly GET: "GET";
|
|
32
|
-
readonly POST: "POST";
|
|
33
|
-
readonly PUT: "PUT";
|
|
34
|
-
readonly PATCH: "PATCH";
|
|
35
|
-
readonly HEAD: "HEAD";
|
|
36
|
-
readonly OPTIONS: "OPTIONS";
|
|
37
|
-
};
|
|
38
|
-
export declare const ContentType: {
|
|
39
|
-
readonly JSON: "application/json";
|
|
40
|
-
readonly HTML: "text/html";
|
|
41
|
-
readonly FORM: "application/x-www-form-urlencoded";
|
|
42
|
-
readonly MULTIPART: "multipart/form-data";
|
|
43
|
-
readonly XML: "application/xml";
|
|
44
|
-
readonly TEXT: "text/plain";
|
|
45
|
-
readonly CSV: "text/csv";
|
|
46
|
-
readonly YAML_APPLICATION: "application/yaml";
|
|
47
|
-
readonly YAML_TEXT: "text/yaml";
|
|
48
|
-
readonly URL_ENCODED_JSON: "application/x-www-form-urlencoded+json";
|
|
49
|
-
};
|
|
50
|
-
type Enum<T> = T[keyof T];
|
|
51
|
-
declare const PathMatchingPattern: {
|
|
52
|
-
readonly ALL_BUT_EXCLUDED: "allButExcluded";
|
|
53
|
-
};
|
|
54
|
-
type THttpMethod = Enum<typeof HttpMethod>;
|
|
55
|
-
type TRequestBody<T = unknown> = IMultipartFormData | TJsonData<T> | string | null;
|
|
56
|
-
type TRequestQuery<T = unknown> = T;
|
|
57
|
-
type TRequestParams<T = unknown> = T;
|
|
58
|
-
interface IRequest {
|
|
59
|
-
protocol: string;
|
|
60
|
-
method: THttpMethod;
|
|
61
|
-
path: string;
|
|
62
|
-
headers: IHeaders;
|
|
63
|
-
body: TRequestBody;
|
|
64
|
-
query: Record<string, string> | TRequestQuery;
|
|
65
|
-
params: Record<string, string> | TRequestParams;
|
|
66
|
-
}
|
|
67
|
-
type THttpStatus = Enum<typeof HttpStatus>;
|
|
68
|
-
export type THttpStatusCode = Enum<typeof HttpStatusCode>;
|
|
69
|
-
interface IHeaders {
|
|
70
|
-
Authorization?: string;
|
|
71
|
-
Proxy_Authorization?: string;
|
|
72
|
-
"WWW-Authenticate"?: string;
|
|
73
|
-
Age?: string;
|
|
74
|
-
"Cache-Control"?: string;
|
|
75
|
-
"Clear-Site-Data"?: string;
|
|
76
|
-
Expires?: string;
|
|
77
|
-
"No-Vary-Search"?: string;
|
|
78
|
-
"Last-Modified"?: string;
|
|
79
|
-
ETag?: string;
|
|
80
|
-
"If-Match"?: string;
|
|
81
|
-
"If-None-Match"?: string;
|
|
82
|
-
"If-Modified-Since"?: string;
|
|
83
|
-
"If-Unmodified-Since"?: string;
|
|
84
|
-
Vary?: string;
|
|
85
|
-
Connection?: string;
|
|
86
|
-
"Keep-Alive"?: string;
|
|
87
|
-
Accept?: string;
|
|
88
|
-
"Accept-Encoding"?: string;
|
|
89
|
-
"Accept-Language"?: string;
|
|
90
|
-
Expect?: string;
|
|
91
|
-
"Max-Forwards"?: string;
|
|
92
|
-
Cookie?: string;
|
|
93
|
-
"Set-Cookie"?: string;
|
|
94
|
-
"Access-Control-Allow-Credentials"?: string;
|
|
95
|
-
"Access-Control-Allow-Methods"?: string;
|
|
96
|
-
"Access-Control-Allow-Headers"?: string;
|
|
97
|
-
"Access-Control-Allow-Origin"?: string;
|
|
98
|
-
"Access-Control-Expose-Headers"?: string;
|
|
99
|
-
"Access-Control-Max-Age"?: string;
|
|
100
|
-
"Access-Control-Request-Headers"?: string;
|
|
101
|
-
"Access-Control-Request-Method"?: string;
|
|
102
|
-
Origin?: string;
|
|
103
|
-
"Timing-Allow-Origin"?: string;
|
|
104
|
-
"Content-Disposition"?: string;
|
|
105
|
-
"Content-Length"?: string;
|
|
106
|
-
"Content-Type"?: (typeof ContentType)[keyof typeof ContentType] | string;
|
|
107
|
-
"Content-Encoding"?: string;
|
|
108
|
-
"Content-Language"?: string;
|
|
109
|
-
"Content-Location"?: string;
|
|
110
|
-
Forwarded?: string;
|
|
111
|
-
Via?: string;
|
|
112
|
-
Location?: string;
|
|
113
|
-
Refresh?: string;
|
|
114
|
-
From?: string;
|
|
115
|
-
Host?: string;
|
|
116
|
-
Referer?: string;
|
|
117
|
-
"Referrer-Policy"?: string;
|
|
118
|
-
"User-Agent"?: string;
|
|
119
|
-
Allow?: string;
|
|
120
|
-
Server?: string;
|
|
121
|
-
Range?: string;
|
|
122
|
-
"Accept-Ranges"?: string;
|
|
123
|
-
"Content-Range"?: string;
|
|
124
|
-
"If-Range"?: string;
|
|
125
|
-
"Cross-Origin-Embedder-Policy"?: string;
|
|
126
|
-
"Cross-Origin-Opener-Policy"?: string;
|
|
127
|
-
"Cross-Origin-Resource-Policy"?: string;
|
|
128
|
-
"Content-Security-Policy"?: string;
|
|
129
|
-
"Content-Security-Policy-Report-Only"?: string;
|
|
130
|
-
"Permissions-Policy"?: string;
|
|
131
|
-
"Strict-Transport-Security"?: string;
|
|
132
|
-
"Upgrade-Insecure-Requests"?: string;
|
|
133
|
-
"X-Content-Type-Options"?: string;
|
|
134
|
-
"X-Frames-Options"?: string;
|
|
135
|
-
"X-Permitted-Cross-Domain-Policies"?: string;
|
|
136
|
-
"X-Powered-By"?: string;
|
|
137
|
-
"X-XSS-Protection"?: string;
|
|
138
|
-
"Report-To"?: string;
|
|
139
|
-
TE?: string;
|
|
140
|
-
Trailer?: string;
|
|
141
|
-
"Transfer-Encoding"?: string;
|
|
142
|
-
"Alt-Svc"?: string;
|
|
143
|
-
"Alt-Used"?: string;
|
|
144
|
-
Date?: string;
|
|
145
|
-
Link?: string;
|
|
146
|
-
"Retry-After"?: string;
|
|
147
|
-
"Server-Timing"?: string;
|
|
148
|
-
"Service-Worker-Allowed"?: string;
|
|
149
|
-
SourceMap?: string;
|
|
150
|
-
Upgrade?: string;
|
|
151
|
-
Priority?: string;
|
|
152
|
-
"Sec-GPC"?: string;
|
|
153
|
-
[key: string]: string | undefined;
|
|
154
|
-
}
|
|
155
|
-
export type TResponseBody<T> = T;
|
|
156
|
-
interface IResponse {
|
|
157
|
-
status: THttpStatus;
|
|
158
|
-
statusCode: THttpStatusCode;
|
|
159
|
-
protocol: string;
|
|
160
|
-
method: THttpMethod;
|
|
161
|
-
path: string;
|
|
162
|
-
headers: IHeaders;
|
|
163
|
-
body: TResponseBody<unknown>;
|
|
164
|
-
}
|
|
165
|
-
type TResponseFunction = (ctx: Context) => Promise<TResponseBody<unknown>> | TResponseBody<unknown>;
|
|
166
|
-
type TUndefinableResponseFunction = TResponseFunction | ((ctx: Context) => Promise<void> | void);
|
|
167
|
-
export interface IRoute extends IRouteOptions {
|
|
168
|
-
path: string;
|
|
169
|
-
method: THttpMethod;
|
|
170
|
-
handler: TResponseFunction;
|
|
171
|
-
}
|
|
172
|
-
interface IRouteOptions {
|
|
173
|
-
beforeHandler?: TResponseFunction | TUndefinableResponseFunction | undefined;
|
|
174
|
-
afterHandler?: TUndefinableResponseFunction | undefined;
|
|
175
|
-
beforeGroup?: TResponseFunction | TUndefinableResponseFunction | undefined;
|
|
176
|
-
}
|
|
177
|
-
export declare class Request$1 {
|
|
178
|
-
readonly protocol: IRequest["protocol"];
|
|
179
|
-
readonly method: IRequest["method"];
|
|
180
|
-
readonly path: IRequest["path"];
|
|
181
|
-
readonly headers: IRequest["headers"];
|
|
182
|
-
readonly body: IRequest["body"];
|
|
183
|
-
readonly query: IRequest["query"];
|
|
184
|
-
params: IRequest["params"];
|
|
185
|
-
constructor(request: string, parserOptions: IServerOptions["parserOptions"]);
|
|
186
|
-
parseParams: (route: IRoute) => Record<string, string>;
|
|
187
|
-
private readonly _parseRequest;
|
|
188
|
-
private readonly _parseBody;
|
|
189
|
-
private readonly _parseHeaders;
|
|
190
|
-
private readonly _parseQuery;
|
|
191
|
-
}
|
|
192
|
-
export declare class Response$1 {
|
|
193
|
-
protected readonly protocol: IResponse["protocol"];
|
|
194
|
-
protected readonly method: IResponse["method"];
|
|
195
|
-
protected readonly path: IResponse["path"];
|
|
196
|
-
protected status: IResponse["status"];
|
|
197
|
-
protected statusCode: IResponse["statusCode"];
|
|
198
|
-
protected statusText: string;
|
|
199
|
-
protected headers: IResponse["headers"];
|
|
200
|
-
protected body: IResponse["body"];
|
|
201
|
-
protected _formattedBody: string;
|
|
202
|
-
constructor(request: Request$1);
|
|
203
|
-
addHeaders(headers: Array<IResponse["headers"]>): void;
|
|
204
|
-
removeHeaders(headers: Array<keyof IHeaders>): void;
|
|
205
|
-
modifyHeader(header: keyof IHeaders, value: string): void;
|
|
206
|
-
setStatus(status: THttpStatusCode): void;
|
|
207
|
-
setBody(body: TResponseBody<unknown>): void;
|
|
208
|
-
formatHttpResponse(): string;
|
|
209
|
-
private _formatResponseBody;
|
|
210
|
-
}
|
|
211
|
-
export export declare class Context {
|
|
212
|
-
request: Request$1;
|
|
213
|
-
response: Response$1;
|
|
214
|
-
constructor(request: Request$1, response: Response$1);
|
|
215
|
-
}
|
|
216
|
-
export type TErrorFunction = ((ctx: Context, error: unknown) => Promise<TResponseBody<unknown>> | TResponseBody<unknown>) | ((ctx: Context, error: unknown) => Promise<void> | void);
|
|
217
|
-
export interface IServerOptions {
|
|
218
|
-
port?: number;
|
|
219
|
-
errorHandler?: TErrorFunction;
|
|
220
|
-
connectionOptions?: {
|
|
221
|
-
socketTimeout: number;
|
|
222
|
-
gracefulShutdownTimeout: number;
|
|
223
|
-
keepAliveTimeout: number;
|
|
224
|
-
headersTimeout: number;
|
|
225
|
-
};
|
|
226
|
-
parserOptions?: {
|
|
227
|
-
json?: {
|
|
228
|
-
raw?: boolean;
|
|
229
|
-
};
|
|
230
|
-
yaml?: {
|
|
231
|
-
raw?: boolean;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
export interface IMultipartFormData {
|
|
236
|
-
fields: Record<string, string>;
|
|
237
|
-
files: Array<IUploadedFile>;
|
|
238
|
-
}
|
|
239
|
-
interface IUploadedFile {
|
|
240
|
-
filename: string;
|
|
241
|
-
contentType: string;
|
|
242
|
-
size: number;
|
|
243
|
-
content: TYamlData | string;
|
|
244
|
-
metadata?: Record<string, string>;
|
|
245
|
-
}
|
|
246
|
-
type TYamlData = Array<TYamlData> | boolean | number | string | {
|
|
247
|
-
[key: string]: TYamlData;
|
|
248
|
-
} | null;
|
|
249
|
-
export type TJsonData<T = unknown> = Record<string, unknown> & T;
|
|
250
|
-
export declare class ConfigManager {
|
|
251
|
-
readonly port: number;
|
|
252
|
-
readonly errorHandler: TErrorFunction;
|
|
253
|
-
readonly connectionOptions: Required<IServerOptions>["connectionOptions"];
|
|
254
|
-
readonly parserOptions: Required<IServerOptions>["parserOptions"];
|
|
255
|
-
constructor(options?: IServerOptions);
|
|
256
|
-
private _setPort;
|
|
257
|
-
private _setErrorHandler;
|
|
258
|
-
private _setConnectionOptions;
|
|
259
|
-
private _normalizeTimeout;
|
|
260
|
-
private _setParserOptions;
|
|
261
|
-
}
|
|
262
|
-
export export declare class HooksManager extends EventEmitter {
|
|
263
|
-
private readonly hooks;
|
|
264
|
-
private readonly pathMatchCache;
|
|
265
|
-
add(fn: TUndefinableResponseFunction, options?: {
|
|
266
|
-
paths?: Array<string> | typeof PathMatchingPattern.ALL_BUT_EXCLUDED;
|
|
267
|
-
excluded?: Array<string>;
|
|
268
|
-
}): this;
|
|
269
|
-
private clearPathMatchCache;
|
|
270
|
-
private getHooksForPath;
|
|
271
|
-
private isPathIncluded;
|
|
272
|
-
private isPathExcluded;
|
|
273
|
-
processBeforeAll(route: IRoute, ctx: Context): Promise<TResponseBody<unknown> | void>;
|
|
274
|
-
processBeforeGroup(route: IRoute, ctx: Context): Promise<TResponseBody<unknown> | void>;
|
|
275
|
-
processBeforeHandler(route: IRoute, ctx: Context): Promise<TResponseBody<unknown> | void>;
|
|
276
|
-
processAfterHandler(route: IRoute, ctx: Context): Promise<TResponseBody<unknown> | void>;
|
|
277
|
-
clear(): this;
|
|
278
|
-
get hooksCount(): number;
|
|
279
|
-
}
|
|
280
|
-
export export declare class YinzerFlow {
|
|
281
|
-
private readonly routeRegistry;
|
|
282
|
-
private readonly routeFinder;
|
|
283
|
-
private readonly hooksManager;
|
|
284
|
-
private readonly connectionManager;
|
|
285
|
-
private readonly requestHandler;
|
|
286
|
-
private readonly configManager;
|
|
287
|
-
private readonly _ip;
|
|
288
|
-
get hooks(): HooksManager;
|
|
289
|
-
get config(): ConfigManager;
|
|
290
|
-
constructor(options?: IServerOptions);
|
|
291
|
-
get: (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
292
|
-
post: (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
293
|
-
put: (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
294
|
-
delete: (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
295
|
-
patch: (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
296
|
-
group(prefix: IRoute["path"], routes: Array<IRoute>, options?: {
|
|
297
|
-
beforeGroup: IRoute["beforeGroup"];
|
|
298
|
-
}): void;
|
|
299
|
-
beforeAll(fn: Parameters<HooksManager["add"]>[0], options?: Parameters<HooksManager["add"]>[1]): this;
|
|
300
|
-
listen(): Promise<void>;
|
|
301
|
-
close(): Promise<void>;
|
|
302
|
-
getStatus(): {
|
|
303
|
-
isListening: boolean;
|
|
304
|
-
port: number;
|
|
305
|
-
ip: string;
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
export export declare class RouteRegistry extends EventEmitter {
|
|
309
|
-
private readonly _routes;
|
|
310
|
-
getRoutes(): Map<string, IRoute>;
|
|
311
|
-
hasRoute(method: string, path: string): boolean;
|
|
312
|
-
getRoute(method: string, path: string): IRoute | undefined;
|
|
313
|
-
private createRouteKey;
|
|
314
|
-
private validatePath;
|
|
315
|
-
addRoute(options: {
|
|
316
|
-
path: IRoute["path"];
|
|
317
|
-
handler: IRoute["handler"];
|
|
318
|
-
method: IRoute["method"];
|
|
319
|
-
beforeHandler?: IRoute["beforeHandler"];
|
|
320
|
-
afterHandler?: IRoute["afterHandler"];
|
|
321
|
-
}): IRoute;
|
|
322
|
-
removeRoute(method: string, path: string): boolean;
|
|
323
|
-
addGroup(prefix: IRoute["path"], routes: Array<IRoute>, options?: {
|
|
324
|
-
beforeGroup: IRoute["beforeGroup"];
|
|
325
|
-
}): void;
|
|
326
|
-
addRoutes(routes: Array<IRoute>): void;
|
|
327
|
-
clearRoutes(): void;
|
|
328
|
-
get routeCount(): number;
|
|
329
|
-
}
|
|
330
|
-
export export declare class RouteFinder {
|
|
331
|
-
private readonly routeRegistry;
|
|
332
|
-
private readonly patternRouteCache;
|
|
333
|
-
constructor(routeRegistry: RouteRegistry);
|
|
334
|
-
private buildPatternRouteCache;
|
|
335
|
-
private createRouteRegex;
|
|
336
|
-
findRoute(method: string, path: string): IRoute | undefined;
|
|
337
|
-
findRouteFromRequest(request: Request$1): IRoute | undefined;
|
|
338
|
-
extractParamsFromPath(path: string, pattern: string): Record<string, string>;
|
|
339
|
-
updatePatternRouteCache(): void;
|
|
340
|
-
}
|
|
341
|
-
export export declare class RequestHandler {
|
|
342
|
-
private readonly routeFinder;
|
|
343
|
-
private readonly hooksManager;
|
|
344
|
-
private readonly errorHandler;
|
|
345
|
-
private readonly configManager;
|
|
346
|
-
constructor(routeFinder: RouteFinder, hooksManager: HooksManager, configManager: ConfigManager);
|
|
347
|
-
handleSocketRequest(socket: Socket, buffer: Buffer): Promise<void>;
|
|
348
|
-
private _sendResponse;
|
|
349
|
-
private _handleError;
|
|
350
|
-
private _processRequest;
|
|
351
|
-
private _processHooksChain;
|
|
352
|
-
private _createNotFoundResponse;
|
|
353
|
-
}
|
|
354
|
-
interface IConnectionStats {
|
|
355
|
-
activeConnections: number;
|
|
356
|
-
totalConnections: number;
|
|
357
|
-
connectionErrors: number;
|
|
358
|
-
uptime: number;
|
|
359
|
-
}
|
|
360
|
-
export export declare class ConnectionManager extends EventEmitter {
|
|
361
|
-
private readonly _connections;
|
|
362
|
-
private _server;
|
|
363
|
-
private _isListening;
|
|
364
|
-
private _startTime;
|
|
365
|
-
private _totalConnections;
|
|
366
|
-
private _connectionErrors;
|
|
367
|
-
private readonly _configManager;
|
|
368
|
-
constructor(configManager: ConfigManager);
|
|
369
|
-
setServer(server: Server | null): void;
|
|
370
|
-
addConnection(socket: Socket): void;
|
|
371
|
-
getConnections(): Set<Socket>;
|
|
372
|
-
getConnectionCount(): number;
|
|
373
|
-
setListening(isListening: boolean): void;
|
|
374
|
-
isListening(): boolean;
|
|
375
|
-
getServer(): Server | null;
|
|
376
|
-
getStats(): IConnectionStats;
|
|
377
|
-
closeAllConnections(): Promise<void>;
|
|
378
|
-
}
|
|
379
|
-
export declare const addGetRoute: (registry: RouteRegistry) => (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
380
|
-
export declare const addPostRoute: (registry: RouteRegistry) => (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
381
|
-
export declare const addPutRoute: (registry: RouteRegistry) => (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
382
|
-
export declare const addDeleteRoute: (registry: RouteRegistry) => (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
383
|
-
export declare const addPatchRoute: (registry: RouteRegistry) => (path: IRoute["path"], handler: IRoute["handler"], options?: IRouteOptions) => IRoute;
|
|
384
|
-
export declare const parseMultipartFormData: (body: string, parserOptions: IServerOptions["parserOptions"]) => TRequestBody;
|
|
385
|
-
export declare const parseApplicationJson: (body: string) => TRequestBody;
|
|
386
|
-
export declare const parseYaml: (body: string) => TYamlData;
|
|
387
|
-
export declare const isJsonData: <T = unknown>(body: TRequestBody) => body is TJsonData<T>;
|
|
388
|
-
export declare const isMultipartFormData: (body: TRequestBody) => body is IMultipartFormData;
|
|
389
|
-
|
|
390
|
-
export {
|
|
391
|
-
Request$1 as Request,
|
|
392
|
-
Response$1 as Response,
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
export {};
|
package/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import{createRequire as t$}from"node:module";var o$=Object.create;var{getPrototypeOf:r$,defineProperty:V$,getOwnPropertyNames:s$}=Object;var a$=Object.prototype.hasOwnProperty;var E$=($,D,M)=>{M=$!=null?o$(r$($)):{};let _=D||!$||!$.__esModule?V$(M,"default",{value:$,enumerable:!0}):M;for(let W of s$($))if(!a$.call(_,W))V$(_,W,{get:()=>$[W],enumerable:!0});return _};var H$=($,D)=>()=>(D||$((D={exports:{}}).exports,D),D.exports);var N$=t$(import.meta.url);var C$=H$((g$)=>{var G=g$,{Buffer:Y$}=N$("buffer"),e$=N$("os");G.toBuffer=function($,D,M){M=~~M;let _;if(this.isV4Format($))_=D||Y$.alloc(M+4),$.split(/\./g).map((W)=>{_[M++]=parseInt(W,10)&255});else if(this.isV6Format($)){let W=$.split(":",8),Y;for(Y=0;Y<W.length;Y++){let R=this.isV4Format(W[Y]),Z;if(R)Z=this.toBuffer(W[Y]),W[Y]=Z.slice(0,2).toString("hex");if(Z&&++Y<8)W.splice(Y,0,Z.slice(2,4).toString("hex"))}if(W[0]==="")while(W.length<8)W.unshift("0");else if(W[W.length-1]==="")while(W.length<8)W.push("0");else if(W.length<8){for(Y=0;Y<W.length&&W[Y]!=="";Y++);let R=[Y,1];for(Y=9-W.length;Y>0;Y--)R.push("0");W.splice(...R)}_=D||Y$.alloc(M+16);for(Y=0;Y<W.length;Y++){let R=parseInt(W[Y],16);_[M++]=R>>8&255,_[M++]=R&255}}if(!_)throw Error(`Invalid ip address: ${$}`);return _};G.toString=function($,D,M){D=~~D,M=M||$.length-D;let _=[];if(M===4){for(let W=0;W<M;W++)_.push($[D+W]);_=_.join(".")}else if(M===16){for(let W=0;W<M;W+=2)_.push($.readUInt16BE(D+W).toString(16));_=_.join(":"),_=_.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),_=_.replace(/:{3,4}/,"::")}return _};var $1=/^(\d{1,3}\.){3,3}\d{1,3}$/,D1=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;G.isV4Format=function($){return $1.test($)};G.isV6Format=function($){return D1.test($)};function l($){if($===4)return"ipv4";if($===6)return"ipv6";return $?$.toLowerCase():"ipv4"}G.fromPrefixLen=function($,D){if($>32)D="ipv6";else D=l(D);let M=4;if(D==="ipv6")M=16;let _=Y$.alloc(M);for(let W=0,Y=_.length;W<Y;++W){let R=8;if($<8)R=$;$-=R,_[W]=~(255>>R)&255}return G.toString(_)};G.mask=function($,D){$=G.toBuffer($),D=G.toBuffer(D);let M=Y$.alloc(Math.max($.length,D.length)),_;if($.length===D.length)for(_=0;_<$.length;_++)M[_]=$[_]&D[_];else if(D.length===4)for(_=0;_<D.length;_++)M[_]=$[$.length-4+_]&D[_];else{for(_=0;_<M.length-6;_++)M[_]=0;M[10]=255,M[11]=255;for(_=0;_<$.length;_++)M[_+12]=$[_]&D[_+12];_+=12}for(;_<M.length;_++)M[_]=0;return G.toString(M)};G.cidr=function($){let D=$.split("/"),M=D[0];if(D.length!==2)throw new Error(`invalid CIDR subnet: ${M}`);let _=G.fromPrefixLen(parseInt(D[1],10));return G.mask(M,_)};G.subnet=function($,D){let M=G.toLong(G.mask($,D)),_=G.toBuffer(D),W=0;for(let R=0;R<_.length;R++)if(_[R]===255)W+=8;else{let Z=_[R]&255;while(Z)Z=Z<<1&255,W++}let Y=2**(32-W);return{networkAddress:G.fromLong(M),firstAddress:Y<=2?G.fromLong(M):G.fromLong(M+1),lastAddress:Y<=2?G.fromLong(M+Y-1):G.fromLong(M+Y-2),broadcastAddress:G.fromLong(M+Y-1),subnetMask:D,subnetMaskLength:W,numHosts:Y<=2?Y:Y-2,length:Y,contains(R){return M===G.toLong(G.mask(R,D))}}};G.cidrSubnet=function($){let D=$.split("/"),M=D[0];if(D.length!==2)throw new Error(`invalid CIDR subnet: ${M}`);let _=G.fromPrefixLen(parseInt(D[1],10));return G.subnet(M,_)};G.not=function($){let D=G.toBuffer($);for(let M=0;M<D.length;M++)D[M]=255^D[M];return G.toString(D)};G.or=function($,D){if($=G.toBuffer($),D=G.toBuffer(D),$.length===D.length){for(let Y=0;Y<$.length;++Y)$[Y]|=D[Y];return G.toString($)}let M=$,_=D;if(D.length>$.length)M=D,_=$;let W=M.length-_.length;for(let Y=W;Y<M.length;++Y)M[Y]|=_[Y-W];return G.toString(M)};G.isEqual=function($,D){if($=G.toBuffer($),D=G.toBuffer(D),$.length===D.length){for(let _=0;_<$.length;_++)if($[_]!==D[_])return!1;return!0}if(D.length===4){let _=D;D=$,$=_}for(let _=0;_<10;_++)if(D[_]!==0)return!1;let M=D.readUInt16BE(10);if(M!==0&&M!==65535)return!1;for(let _=0;_<4;_++)if($[_]!==D[_+12])return!1;return!0};G.isPrivate=function($){if(G.isLoopback($))return!0;if(!G.isV6Format($)){let D=G.normalizeToLong($);if(D<0)throw new Error("invalid ipv4 address");$=G.fromLong(D)}return/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^f[cd][0-9a-f]{2}:/i.test($)||/^fe80:/i.test($)||/^::1$/.test($)||/^::$/.test($)};G.isPublic=function($){return!G.isPrivate($)};G.isLoopback=function($){if(!/\./.test($)&&!/:/.test($))$=G.fromLong(Number($));return/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test($)||/^0177\./.test($)||/^0x7f\./i.test($)||/^fe80::1$/i.test($)||/^::1$/.test($)||/^::$/.test($)};G.loopback=function($){if($=l($),$!=="ipv4"&&$!=="ipv6")throw new Error("family must be ipv4 or ipv6");return $==="ipv4"?"127.0.0.1":"fe80::1"};G.address=function($,D){let M=e$.networkInterfaces();if(D=l(D),$&&$!=="private"&&$!=="public"){let W=M[$].filter((Y)=>{return l(Y.family)===D});if(W.length===0)return;return W[0].address}let _=Object.keys(M).map((W)=>{let Y=M[W].filter((R)=>{if(R.family=l(R.family),R.family!==D||G.isLoopback(R.address))return!1;if(!$)return!0;return $==="public"?G.isPrivate(R.address):G.isPublic(R.address)});return Y.length?Y[0].address:void 0}).filter(Boolean);return!_.length?G.loopback(D):_[0]};G.toLong=function($){let D=0;return $.split(".").forEach((M)=>{D<<=8,D+=parseInt(M)}),D>>>0};G.fromLong=function($){return`${$>>>24}.${$>>16&255}.${$>>8&255}.${$&255}`};G.normalizeToLong=function($){let D=$.split(".").map((W)=>{if(W.startsWith("0x")||W.startsWith("0X"))return parseInt(W,16);else if(W.startsWith("0")&&W!=="0"&&/^[0-7]+$/.test(W))return parseInt(W,8);else if(/^[1-9]\d*$/.test(W)||W==="0")return parseInt(W,10);else return NaN});if(D.some(isNaN))return-1;let M=0;switch(D.length){case 1:M=D[0];break;case 2:if(D[0]>255||D[1]>16777215)return-1;M=D[0]<<24|D[1]&16777215;break;case 3:if(D[0]>255||D[1]>255||D[2]>65535)return-1;M=D[0]<<24|D[1]<<16|D[2]&65535;break;case 4:if(D.some((W)=>W>255))return-1;M=D[0]<<24|D[1]<<16|D[2]<<8|D[3];break;default:return-1}return M>>>0}});var m$=H$((z$,K$)=>{(function($,D){typeof z$=="object"&&typeof K$!="undefined"?K$.exports=D():typeof define=="function"&&define.amd?define(D):($=typeof globalThis!="undefined"?globalThis:$||self).dayjs=D()})(z$,function(){var $=1000,D=60000,M=3600000,_="millisecond",W="second",Y="minute",R="hour",Z="day",O="week",w="month",C="quarter",T="year",x="date",T$="Invalid Date",i$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,p$=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,l$={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(j){var J=["th","st","nd","rd"],Q=j%100;return"["+j+(J[(Q-20)%10]||J[Q]||J[0])+"]"}},w$=function(j,J,Q){var U=String(j);return!U||U.length>=J?j:""+Array(J+1-U.length).join(Q)+j},n$={s:w$,z:function(j){var J=-j.utcOffset(),Q=Math.abs(J),U=Math.floor(Q/60),X=Q%60;return(J<=0?"+":"-")+w$(U,2,"0")+":"+w$(X,2,"0")},m:function j(J,Q){if(J.date()<Q.date())return-j(Q,J);var U=12*(Q.year()-J.year())+(Q.month()-J.month()),X=J.clone().add(U,w),B=Q-X<0,F=J.clone().add(U+(B?-1:1),w);return+(-(U+(Q-X)/(B?X-F:F-X))||0)},a:function(j){return j<0?Math.ceil(j)||0:Math.floor(j)},p:function(j){return{M:w,y:T,w:O,d:Z,D:x,h:R,m:Y,s:W,ms:_,Q:C}[j]||String(j||"").toLowerCase().replace(/s$/,"")},u:function(j){return j===void 0}},c="en",v={};v[c]=l$;var P$="$isDayjsObject",j$=function(j){return j instanceof _$||!(!j||!j[P$])},M$=function j(J,Q,U){var X;if(!J)return c;if(typeof J=="string"){var B=J.toLowerCase();v[B]&&(X=B),Q&&(v[B]=Q,X=B);var F=J.split("-");if(!X&&F.length>1)return j(F[0])}else{var K=J.name;v[K]=J,X=K}return!U&&X&&(c=X),X||!U&&c},A=function(j,J){if(j$(j))return j.clone();var Q=typeof J=="object"?J:{};return Q.date=j,Q.args=arguments,new _$(Q)},z=n$;z.l=M$,z.i=j$,z.w=function(j,J){return A(j,{locale:J.$L,utc:J.$u,x:J.$x,$offset:J.$offset})};var _$=function(){function j(Q){this.$L=M$(Q.locale,null,!0),this.parse(Q),this.$x=this.$x||Q.x||{},this[P$]=!0}var J=j.prototype;return J.parse=function(Q){this.$d=function(U){var{date:X,utc:B}=U;if(X===null)return new Date(NaN);if(z.u(X))return new Date;if(X instanceof Date)return new Date(X);if(typeof X=="string"&&!/Z$/i.test(X)){var F=X.match(i$);if(F){var K=F[2]-1||0,P=(F[7]||"0").substring(0,3);return B?new Date(Date.UTC(F[1],K,F[3]||1,F[4]||0,F[5]||0,F[6]||0,P)):new Date(F[1],K,F[3]||1,F[4]||0,F[5]||0,F[6]||0,P)}}return new Date(X)}(Q),this.init()},J.init=function(){var Q=this.$d;this.$y=Q.getFullYear(),this.$M=Q.getMonth(),this.$D=Q.getDate(),this.$W=Q.getDay(),this.$H=Q.getHours(),this.$m=Q.getMinutes(),this.$s=Q.getSeconds(),this.$ms=Q.getMilliseconds()},J.$utils=function(){return z},J.isValid=function(){return this.$d.toString()!==T$},J.isSame=function(Q,U){var X=A(Q);return this.startOf(U)<=X&&X<=this.endOf(U)},J.isAfter=function(Q,U){return A(Q)<this.startOf(U)},J.isBefore=function(Q,U){return this.endOf(U)<A(Q)},J.$g=function(Q,U,X){return z.u(Q)?this[U]:this.set(X,Q)},J.unix=function(){return Math.floor(this.valueOf()/1000)},J.valueOf=function(){return this.$d.getTime()},J.startOf=function(Q,U){var X=this,B=!!z.u(U)||U,F=z.p(Q),K=function(y,H){var S=z.w(X.$u?Date.UTC(X.$y,H,y):new Date(X.$y,H,y),X);return B?S:S.endOf(Z)},P=function(y,H){return z.w(X.toDate()[y].apply(X.toDate("s"),(B?[0,0,0,0]:[23,59,59,999]).slice(H)),X)},V=this.$W,E=this.$M,g=this.$D,m="set"+(this.$u?"UTC":"");switch(F){case T:return B?K(1,0):K(31,11);case w:return B?K(1,E):K(0,E+1);case O:var h=this.$locale().weekStart||0,i=(V<h?V+7:V)-h;return K(B?g-i:g+(6-i),E);case Z:case x:return P(m+"Hours",0);case R:return P(m+"Minutes",1);case Y:return P(m+"Seconds",2);case W:return P(m+"Milliseconds",3);default:return this.clone()}},J.endOf=function(Q){return this.startOf(Q,!1)},J.$set=function(Q,U){var X,B=z.p(Q),F="set"+(this.$u?"UTC":""),K=(X={},X[Z]=F+"Date",X[x]=F+"Date",X[w]=F+"Month",X[T]=F+"FullYear",X[R]=F+"Hours",X[Y]=F+"Minutes",X[W]=F+"Seconds",X[_]=F+"Milliseconds",X)[B],P=B===Z?this.$D+(U-this.$W):U;if(B===w||B===T){var V=this.clone().set(x,1);V.$d[K](P),V.init(),this.$d=V.set(x,Math.min(this.$D,V.daysInMonth())).$d}else K&&this.$d[K](P);return this.init(),this},J.set=function(Q,U){return this.clone().$set(Q,U)},J.get=function(Q){return this[z.p(Q)]()},J.add=function(Q,U){var X,B=this;Q=Number(Q);var F=z.p(U),K=function(E){var g=A(B);return z.w(g.date(g.date()+Math.round(E*Q)),B)};if(F===w)return this.set(w,this.$M+Q);if(F===T)return this.set(T,this.$y+Q);if(F===Z)return K(1);if(F===O)return K(7);var P=(X={},X[Y]=D,X[R]=M,X[W]=$,X)[F]||1,V=this.$d.getTime()+Q*P;return z.w(V,this)},J.subtract=function(Q,U){return this.add(-1*Q,U)},J.format=function(Q){var U=this,X=this.$locale();if(!this.isValid())return X.invalidDate||T$;var B=Q||"YYYY-MM-DDTHH:mm:ssZ",F=z.z(this),K=this.$H,P=this.$m,V=this.$M,E=X.weekdays,g=X.months,m=X.meridiem,h=function(H,S,p,W$){return H&&(H[S]||H(U,B))||p[S].slice(0,W$)},i=function(H){return z.s(K%12||12,H,"0")},y=m||function(H,S,p){var W$=H<12?"AM":"PM";return p?W$.toLowerCase():W$};return B.replace(p$,function(H,S){return S||function(p){switch(p){case"YY":return String(U.$y).slice(-2);case"YYYY":return z.s(U.$y,4,"0");case"M":return V+1;case"MM":return z.s(V+1,2,"0");case"MMM":return h(X.monthsShort,V,g,3);case"MMMM":return h(g,V);case"D":return U.$D;case"DD":return z.s(U.$D,2,"0");case"d":return String(U.$W);case"dd":return h(X.weekdaysMin,U.$W,E,2);case"ddd":return h(X.weekdaysShort,U.$W,E,3);case"dddd":return E[U.$W];case"H":return String(K);case"HH":return z.s(K,2,"0");case"h":return i(1);case"hh":return i(2);case"a":return y(K,P,!0);case"A":return y(K,P,!1);case"m":return String(P);case"mm":return z.s(P,2,"0");case"s":return String(U.$s);case"ss":return z.s(U.$s,2,"0");case"SSS":return z.s(U.$ms,3,"0");case"Z":return F}return null}(H)||F.replace(":","")})},J.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},J.diff=function(Q,U,X){var B,F=this,K=z.p(U),P=A(Q),V=(P.utcOffset()-this.utcOffset())*D,E=this-P,g=function(){return z.m(F,P)};switch(K){case T:B=g()/12;break;case w:B=g();break;case C:B=g()/3;break;case O:B=(E-V)/604800000;break;case Z:B=(E-V)/86400000;break;case R:B=E/M;break;case Y:B=E/D;break;case W:B=E/$;break;default:B=E}return X?B:z.a(B)},J.daysInMonth=function(){return this.endOf(w).$D},J.$locale=function(){return v[this.$L]},J.locale=function(Q,U){if(!Q)return this.$L;var X=this.clone(),B=M$(Q,U,!0);return B&&(X.$L=B),X},J.clone=function(){return z.w(this.$d,this)},J.toDate=function(){return new Date(this.valueOf())},J.toJSON=function(){return this.isValid()?this.toISOString():null},J.toISOString=function(){return this.$d.toISOString()},J.toString=function(){return this.$d.toUTCString()},j}(),A$=_$.prototype;return A.prototype=A$,[["$ms",_],["$s",W],["$m",Y],["$H",R],["$W",Z],["$M",w],["$y",T],["$D",x]].forEach(function(j){A$[j[1]]=function(J){return this.$g(J,j[0],j[1])}}),A.extend=function(j,J){return j.$i||(j(J,_$,A),j.$i=!0),A},A.locale=M$,A.isDayjs=j$,A.unix=function(j){return A(1000*j)},A.en=v[c],A.Ls=v,A.p={},A})});import{HttpMethod as K2,HttpStatus as L2,HttpStatusCode as T2,ContentType as P2}from "yinzerflow/constants/index.js";var c$=E$(C$(),1);import{createServer as b1}from"net";import{DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT as M1,DEFAULT_HEADERS_TIMEOUT as _1,DEFAULT_KEEP_ALIVE_TIMEOUT as W1,DEFAULT_PORT as Y1,DEFAULT_SOCKET_TIMEOUT as R1}from "yinzerflow/constants/index.js";import{HttpStatusCode as Z1}from "yinzerflow/constants/index.js";class B${port;errorHandler;connectionOptions;parserOptions;constructor($){this.port=this._setPort($?.port),this.errorHandler=this._setErrorHandler($?.errorHandler),this.connectionOptions=this._setConnectionOptions($?.connectionOptions),this.parserOptions=this._setParserOptions($?.parserOptions)}_setPort($){let D=typeof $==="string"?parseInt($,10):$??Y1;if(isNaN(D)||D<0||D>65535)throw new Error("Invalid port number");return D}_setErrorHandler($){if($&&typeof $!=="function")throw new Error("Error handler must be a function");return $??(({response:D},M)=>{if(console.error(`Server error:
|
|
2
|
-
`,M),D.setStatus(Z1.INTERNAL_SERVER_ERROR),M instanceof Error)return{success:!1,message:M.message};return{success:!1,message:"An unknown error occurred"}})}_setConnectionOptions($){let D={socketTimeout:this._normalizeTimeout($?.socketTimeout,R1),gracefulShutdownTimeout:this._normalizeTimeout($?.gracefulShutdownTimeout,M1),keepAliveTimeout:this._normalizeTimeout($?.keepAliveTimeout,W1),headersTimeout:this._normalizeTimeout($?.headersTimeout,_1)};if(D.headersTimeout<=D.keepAliveTimeout)throw new Error("headersTimeout must be greater than keepAliveTimeout");return D}_normalizeTimeout($,D){let M=typeof $==="string"?parseInt($,10):$??D;if(isNaN(M)||M<0)throw new Error("Timeout must be a positive number");return M}_setParserOptions($){let D=$??{};if(D.json?.raw!==void 0&&typeof D.json.raw!=="boolean")throw new Error("JSON parser raw option must be a boolean");if(D.yaml?.raw!==void 0&&typeof D.yaml.raw!=="boolean")throw new Error("YAML parser raw option must be a boolean");return D}}import{HttpMethod as Q1}from "yinzerflow/constants/index.js";var n=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:Q1.GET,..._});import{HttpMethod as X1}from "yinzerflow/constants/index.js";var o=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:X1.POST,..._});import{HttpMethod as J1}from "yinzerflow/constants/index.js";var r=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:J1.PUT,..._});import{HttpMethod as G1}from "yinzerflow/constants/index.js";var s=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:G1.DELETE,..._});import{HttpMethod as U1}from "yinzerflow/constants/index.js";var a=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:U1.PATCH,..._});import{EventEmitter as O1}from"events";import{RouteRegistryEvent as q}from "yinzerflow/constants/index.js";class t extends O1{_routes=new Map;getRoutes(){return this._routes}hasRoute($,D){let M=this.createRouteKey($,D);return this._routes.has(M)}getRoute($,D){let M=this.createRouteKey($,D);return this._routes.get(M)}createRouteKey($,D){return`${$}:${D}`}validatePath($){if(!$.startsWith("/"))throw new Error(`Route path must start with a slash: ${$}`);if($.includes("//"))throw new Error(`Route path must not contain consecutive slashes: ${$}`);let D=/:\w+/g,M=$.match(D)??[];for(let _ of M)if(_===":")throw new Error(`Route path parameter must have a name: ${$}`)}addRoute($){let{path:D,handler:M,method:_,beforeHandler:W,afterHandler:Y}=$;this.validatePath(D);let R={path:D,method:_,handler:M,beforeHandler:W??void 0,afterHandler:Y??void 0},Z=this.createRouteKey(_,D);if(this._routes.has(Z))console.warn(`Route already exists and will be overwritten: ${_} ${D}`);return this._routes.set(Z,R),this.emit(q.ROUTE_ADDED,R),this.emit(q.ROUTES_CHANGED),R}removeRoute($,D){let M=this.createRouteKey($,D),_=this._routes.get(M);if(!_)return!1;let W=this._routes.delete(M);if(W)this.emit(q.ROUTE_REMOVED,_),this.emit(q.ROUTES_CHANGED);return W}addGroup($,D,M){this.validatePath($);let _="";if($==="/")_="";else if($.endsWith("/"))_=$;else _=`${$}/`;for(let W of D){let Y=W.path.startsWith("/")?W.path:`/${W.path}`,R=`${_}${Y.substring(1)}`,Z=this.createRouteKey(W.method,R);this._routes.set(Z,{...W,path:R,beforeGroup:M?.beforeGroup}),this.emit(q.ROUTE_ADDED,this._routes.get(Z))}this.emit(q.ROUTES_CHANGED)}addRoutes($){for(let D of $){this.validatePath(D.path);let M=this.createRouteKey(D.method,D.path);this._routes.set(M,D),this.emit(q.ROUTE_ADDED,D)}this.emit(q.ROUTES_CHANGED)}clearRoutes(){this._routes.clear(),this.emit(q.ROUTES_CHANGED)}get routeCount(){return this._routes.size}}import{RouteRegistryEvent as k1}from "yinzerflow/constants/index.js";class e{routeRegistry;patternRouteCache=new Map;constructor($){this.routeRegistry=$;this.buildPatternRouteCache()}buildPatternRouteCache(){let $=this.routeRegistry.getRoutes();this.patternRouteCache.clear();for(let[,D]of $)if(D.path.includes(":")){let{method:M}=D,_=this.patternRouteCache.get(M)??[],W=this.createRouteRegex(D.path);_.push({pattern:W,route:D}),this.patternRouteCache.set(M,_)}}createRouteRegex($){let D=$.replace(/:[^/]+/g,"([^/]+)").replace(/(?:[.+*?^$()[\]{}|])/g,"\\$&");return new RegExp(`^${D}$`)}findRoute($,D){return this.routeRegistry.getRoute($,D)}findRouteFromRequest($){let D=$.path!=="/"&&$.path.endsWith("/")?$.path.slice(0,-1):$.path,M=this.findRoute($.method,D);if(M)return M;let _=this.patternRouteCache.get($.method);if(!_)return;for(let{pattern:W,route:Y}of _)if(W.test(D))return Y;return}extractParamsFromPath($,D){let M={};if(!D.includes(":"))return M;let W=($.split("?")[0]??"").split("/").filter(Boolean),Y=D.split("/").filter(Boolean);for(let R=0;R<Y.length;R++){let Z=Y[R];if(Z?.startsWith(":")){let O=Z.substring(1);if(R<W.length){let w=W[R];if(w)M[O]=decodeURIComponent(w)}}}return M}updatePatternRouteCache(){this.buildPatternRouteCache()}}import{ContentType as h$}from "yinzerflow/constants/index.js";var F$=($,D)=>{let M=$.indexOf(D);if(M===-1)return[$,""];let _=$.slice(0,M),W=$.slice(M+D.length);return[_,W]},R$=($)=>new TextEncoder().encode($).length;var Z$=($)=>{try{return w1($)}catch(D){throw new Error(`Invalid YAML: ${D instanceof Error?D.message:String(D)}`)}},w1=($)=>{let D=Object.create(null),M=$.split(/\r?\n/),_=[{indent:-1,obj:D}],W={};for(let Y=0;Y<M.length;Y++)try{let R=M[Y];if(R!==void 0)I$(R,_,Y+1,W)}catch(R){throw new Error(`Line ${Y+1}: ${R instanceof Error?R.message:String(R)}`)}return D},I$=($,D,M=0,_={})=>{if(!$||$.trim()===""||$.trim().startsWith("#"))return;let W=$.search(/\S/),Y=$.trim();if(D[D.length-1]?.multilineKey){F1($,W,D);return}j1(Y,W,D,M,_)},j1=($,D,M,_,W)=>{if($.startsWith("-"))K1($,D,M,_,W);else if($.includes(":"))f$($,D,M,_,W);else if($.startsWith("&"));else if($.startsWith("*"))B1($,M,W)},B1=($,D,M)=>{let _=$.substring(1).trim();if(!(_ in M))throw new Error(`Unknown alias: ${_}`);let W=M[_],Y=D[D.length-1];if(!Y)return;if(Y.isArray&&Array.isArray(Y.obj))Y.obj.push(W)},F1=($,D,M)=>{let _=M[M.length-1];if(!_||!_.multilineKey)return;if(D<=_.indent){z1(_),I$($,M);return}let W=$.slice(_.indent+2);if(_.multilineValue)_.multilineValue+=`
|
|
3
|
-
${W}`;else _.multilineValue=W},z1=($)=>{if(typeof $.obj==="object"&&$.obj!==null&&!Array.isArray($.obj)&&$.multilineKey){let D=$.obj,M=$.multilineValue??"",_=$.multilineKey;if($.multilineType==="literal")D[_]=M;else D[_]=M.replace(/\n/g," ")}delete $.multilineKey,delete $.multilineValue,delete $.multilineType},K1=($,D,M,_=0,W={})=>{let Y=$.substring(1).trim();v$(M,D);let R=M[M.length-1];if(!R)return;if(R.isArray&&Array.isArray(R.obj))q$({itemContent:Y,indent:D,stack:M,array:R.obj,lineNumber:_},W);else{if(typeof R.obj==="object"&&R.obj!==null&&!Array.isArray(R.obj)){let{obj:Z,arrayKey:O}=R;if(O&&O in Z){if(!Array.isArray(Z[O]))Z[O]=[];let w=Z[O];q$({itemContent:Y,indent:D,stack:M,array:w,lineNumber:_},W),M.push({indent:D,obj:w,isArray:!0});return}}L1({itemContent:Y,indent:D,stack:M,lastStackItem:R,lineNumber:_},W)}},q$=($,D={})=>{let{itemContent:M,indent:_,stack:W,array:Y,lineNumber:R}=$;if(!Y)return;let{processedContent:Z,anchorName:O}=x$(M);if(Z.includes(":")){let w=Object.create(null);if(Y.push(w),O)D[O]=w;let[C,T]=Z.split(":",2);if(C)S$({key:C,value:T,indent:_,stack:W,obj:w,lineNumber:R??0})}else{let w=Q$(Z);if(Y.push(w),O)D[O]=w}},x$=($)=>{let D=$,M=null;if($.startsWith("&")){let _=$.indexOf(" ");if(_>1)M=$.substring(1,_),D=$.substring(_+1)}return{processedContent:D,anchorName:M}},S$=($)=>{let{key:D,value:M,indent:_,stack:W,obj:Y}=$;if(typeof Y!=="object"||Y===null||Array.isArray(Y))return;let R=Y,Z=D.trim(),O=M?.trim()??"";if(O==="")R[Z]=Object.create(null),W.push({indent:_+2,obj:R[Z]});else if(O==="|"||O===">"){if(W.length>0){let w=W[W.length-1];if(w)w.multilineKey=Z,w.multilineType=O==="|"?"literal":"folded"}}else R[Z]=Q$(O)},L1=($,D={})=>{let{itemContent:M,indent:_,stack:W,lastStackItem:Y}=$;if(!Y)return;if(typeof Y.obj==="object"&&Y.obj!==null&&!Array.isArray(Y.obj)){let R=Y.obj,Z=Y.arrayKey??"items";R[Z]=[];let O=R[Z];T1(M,_,W,O,D)}},T1=($,D,M,_,W)=>{let{processedContent:Y,anchorName:R}=x$($);if(Y.includes(":")){let Z=Object.create(null);if(_.push(Z),R)W[R]=Z;let[O,w]=Y.split(":",2);if(O)S$({key:O,value:w,indent:D,stack:M,obj:Z,lineNumber:0})}else{let Z=Q$(Y);if(_.push(Z),R)W[R]=Z}M.push({indent:D,obj:_,isArray:!0})},f$=($,D,M,_=0,W={})=>{let{processedContent:Y,key:R,value:Z,anchorName:O}=P1($);if(!R)return;let w=R.trim(),C=Z?.trim()??"";v$(M,D);let T=M[M.length-1];if(!T)return;if(A1($,D,M,T,_,W))return;if(typeof T.obj!=="object"||T.obj===null||Array.isArray(T.obj))return;let x=T.obj;V1(w,C,Y,D,M,x,T,O,W)},P1=($)=>{let D=$,M=null,_=$.indexOf(":");if(_!==-1){let R=$.substring(0,_).trim(),Z=$.substring(_+1).trim();if(Z.startsWith("&")){let O=Z.indexOf(" ");if(O>1)M=Z.substring(1,O),Z=Z.substring(O+1),D=`${R}: ${Z}`}}let[W,Y]=D.split(":",2);return{processedContent:D,key:W,value:Y,anchorName:M}},A1=($,D,M,_,W,Y)=>{if(_.isArray)return M.pop(),f$($,D,M,W,Y),!0;return!1},V1=($,D,M,_,W,Y,R,Z,O)=>{if(D==="")E1($,M,_,W,Y,Z,O);else if(D==="|"||D===">")R.multilineKey=$,R.multilineType=D==="|"?"literal":"folded";else{let w=Q$(D);if(Y[$]=w,Z)O[Z]=w}},E1=($,D,M,_,W,Y,R)=>{if(D.endsWith(":")){if(W[$]=Object.create(null),Y)R[Y]=W[$];_.push({indent:M,obj:W[$],arrayKey:$})}else{if(W[$]=Object.create(null),Y)R[Y]=W[$];_.push({indent:M,obj:W[$]})}},v$=($,D)=>{while($.length>1){let M=$[$.length-1];if(M&&M.indent>=D)$.pop();else break}},Q$=($)=>{if($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))return $.slice(1,-1);if(H1($))return null;let D=N1($);if(D!==void 0)return D;let M=g1($);if(M!==void 0)return M;let _=C1($);if(_ instanceof Date)return _.toISOString();let W=q1($);if(W!==void 0)return W;return $},H1=($)=>$==="null"||$==="~"||$==="",N1=($)=>{let D=$.toLowerCase();if(D==="true")return!0;if(D==="false")return!1;return},g1=($)=>{if($===".inf"||$===".Inf"||$===".INF")return 1/0;if($==="-.inf"||$==="-.Inf"||$==="-.INF")return-1/0;if($===".nan"||$===".NaN"||$===".NAN")return NaN;return},C1=($)=>{if(/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?$/.test($)){let M=new Date($);return isNaN(M.getTime())?$:M}return $},q1=($)=>{if(/^-?\d+(?:\.\d+)?$/.test($))return Number($);if(/^0x[0-9a-fA-F]+$/.test($))return parseInt($,16);if(/^0o[0-7]+$/.test($))return parseInt($.substring(2),8);return};var I1=($)=>{let M=$.split(`\r
|
|
4
|
-
`).find((W)=>W.toLowerCase().startsWith("content-type:"));if(!M)return;return M.slice(M.indexOf(":")+1).trim()},x1=($)=>{let D={name:""},_=$.split(`\r
|
|
5
|
-
`).find((R)=>R.toLowerCase().startsWith("content-disposition:"));if(!_)return D;let W=/name="(?<name>[^"]*)"/.exec(_),Y=/filename="(?<filename>[^"]*)"/.exec(_);if(W?.groups?.name)D.name=W.groups.name;if(Y?.groups?.filename)Object.assign(D,{filename:Y.groups.filename});return D},S1=($)=>{let D=$.startsWith(`\r
|
|
6
|
-
`)?$.slice(2):$,M=D.indexOf(`\r
|
|
7
|
-
\r
|
|
8
|
-
`);if(M===-1)return["",""];let _=D.slice(0,M),W=D.slice(M+4).trim();return[_,W]},X$=($,D)=>{let M={fields:{},files:[]},W=/^--(?<boundary>[^\r\n]+)/.exec($)?.groups?.boundary??null;if(!W)throw new Error("Invalid multipart form data: missing boundary");let Y=$.split(`--${W}`).slice(1);for(let R of Y){if(!R||R.trim()==="--")continue;let[Z,O]=S1(R);if(!Z||!O)continue;let w=x1(Z);if(!w.name)continue;if(w.filename)M.files.push(f1({contentDisposition:w,contentSection:O,headersSection:Z,parserOptions:D}));else M.fields[w.name]=O}return M},f1=({contentDisposition:$,contentSection:D,headersSection:M,parserOptions:_})=>{let W=I1(M)??"application/octet-stream",Y={filename:$.filename??"",contentType:W,size:R$(D),content:D};if((W===h$.YAML_APPLICATION||W===h$.YAML_TEXT)&&typeof Y.content==="string"){if(_?.yaml?.raw)return Y;Y.content=Z$(Y.content)}return Y};var J$=($)=>{try{return JSON.parse($)}catch(D){throw new Error(`Invalid JSON: ${D instanceof Error?D.message:String(D)}`)}};var G$=($)=>$!==null&&typeof $==="object"&&("fields"in $)&&("files"in $)&&Array.isArray($.files)&&typeof $.fields==="object";var y$=($)=>!G$($)&&typeof $==="object";import{ContentType as b$,HttpMethod as k$}from "yinzerflow/constants/index.js";class u{protocol;method;path;headers;body;query;params;constructor($,D){let{protocol:M,method:_,path:W,headers:Y,body:R,query:Z,params:O}=this._parseRequest($,D);this.protocol=M,this.method=_,this.path=W,this.headers=Y,this.body=R,this.query=Z,this.params=O}parseParams=($)=>{let D={};if(typeof $.path!=="string")return D;if(typeof this.path!=="string")return D;let M=$.path.match(/:[^/]+/g),_=M?M.map((Z)=>Z.slice(1)):[];if(_.length===0)return D;let W=$.path.replace(/:[^/]+/g,"([^/]+)"),Y=new RegExp(`^${W}$`),R=this.path.match(Y);if(!R)return D;for(let Z=0;Z<_.length;Z++){let O=R[Z+1],w=_[Z];if(O&&w)D[w]=O}return D};_parseRequest=($,D)=>{if(!$)throw new Error("Invalid request");let[M,_]=F$($,`\r
|
|
9
|
-
`),[W,Y,R]=M.split(" ",3),[Z,O]=F$(_,`\r
|
|
10
|
-
\r
|
|
11
|
-
`),w=this._parseHeaders(Z),C=this._parseQuery(Y),T={};if(O&&W!==k$.GET&&W!==k$.HEAD)T=this._parseBody(w,O,D);return{protocol:R,method:W,path:Y,headers:w,body:T,query:C,params:{}}};_parseBody=($,D,M)=>{if(!$["Content-Type"])throw new Error("Missing Content-Type header");let _=$["Content-Type"];if(_===b$.JSON){if(M?.json?.raw)return D;return J$(D)}if(_.includes(b$.MULTIPART))return X$(D,M);return D};_parseHeaders=($)=>{let D={};if(!$)return D;let _=$.replace(/\r\n|\r|\n/g,`
|
|
12
|
-
`).split(`
|
|
13
|
-
`);for(let W of _){if(!W)continue;let Y=W.indexOf(":");if(Y===-1)continue;let R=W.slice(0,Y).trim(),Z=W.slice(Y+1).trim();if(R)D[R]=Z}return D};_parseQuery=($)=>{if(!$)return{};if(!$.includes("?"))return{};let[,D]=$.split("?");if(!D)return{};let M={},_=D.split("&");for(let W of _){let[Y,R]=W.split("=");if(Y)M[decodeURIComponent(Y)]=R?decodeURIComponent(R):""}return M}}var d$=E$(m$(),1);import{ContentType as u$,HttpStatus as L,HttpStatusCode as N}from "yinzerflow/constants/index.js";class b{protocol;method;path;status;statusCode;statusText;headers={};body="";_formattedBody="";constructor($){this.method=$.method,this.path=$.path,this.protocol=$.protocol,this.statusCode=N.OK,this.status=L.OK,this.statusText=L.OK,this.headers={Date:d$.default().format("ddd, DD MMM YYYY HH:mm:ss [GMT]"),Connection:"keep-alive","Keep-Alive":"timeout=5, max=1000","Content-Type":u$.JSON,"Content-Length":"0"}}addHeaders($){for(let D of $)this.headers={...this.headers,...D}}removeHeaders($){for(let D of $)delete this.headers[D]}modifyHeader($,D){this.headers[$]=D}setStatus($){let D={[N.OK]:{status:L.OK,text:L.OK},[N.CREATED]:{status:L.CREATED,text:L.CREATED},[N.NO_CONTENT]:{status:L.NO_CONTENT,text:L.NO_CONTENT},[N.BAD_REQUEST]:{status:L.BAD_REQUEST,text:L.BAD_REQUEST},[N.UNAUTHORIZED]:{status:L.UNAUTHORIZED,text:L.UNAUTHORIZED},[N.FORBIDDEN]:{status:L.FORBIDDEN,text:L.FORBIDDEN},[N.NOT_FOUND]:{status:L.NOT_FOUND,text:L.NOT_FOUND},[N.METHOD_NOT_ALLOWED]:{status:L.METHOD_NOT_ALLOWED,text:L.METHOD_NOT_ALLOWED},[N.CONFLICT]:{status:L.CONFLICT,text:L.CONFLICT},[N.UNSUPPORTED_MEDIA_TYPE]:{status:L.UNSUPPORTED_MEDIA_TYPE,text:L.UNSUPPORTED_MEDIA_TYPE},[N.TOO_MANY_REQUESTS]:{status:L.TOO_MANY_REQUESTS,text:L.TOO_MANY_REQUESTS},[N.INTERNAL_SERVER_ERROR]:{status:L.INTERNAL_SERVER_ERROR,text:L.INTERNAL_SERVER_ERROR}},M=D[$]||D[N.OK];this.statusCode=$,this.status=M.status,this.statusText=M.text}setBody($){if(this.body=$,this._formattedBody=this._formatResponseBody($),!this.headers["Content-Type"])this.headers["Content-Type"]=u$.JSON;this.headers["Content-Length"]=String(R$(this._formattedBody))}formatHttpResponse(){let $=`${this.protocol} ${this.statusCode} ${String(this.status)}`,D=Object.entries(this.headers).map(([M,_])=>`${M}: ${_}`).join(`\r
|
|
14
|
-
`);return`${$}\r
|
|
15
|
-
${D}\r
|
|
16
|
-
\r
|
|
17
|
-
${this._formattedBody}`}_formatResponseBody($){if($===null)return"null";switch(typeof $){case"string":return $;case"object":return JSON.stringify($);default:return String($)}}}class k{request;response;constructor($,D){this.request=$,this.response=D}}import{HttpStatusCode as v1}from "yinzerflow/constants/index.js";class d{routeFinder;hooksManager;errorHandler;configManager;constructor($,D,M){this.routeFinder=$,this.hooksManager=D,this.configManager=M,this.errorHandler=M.errorHandler}async handleSocketRequest($,D){let M=new u(D.toString(),this.configManager.parserOptions);try{let _=this.routeFinder.findRouteFromRequest(M),W=_?(M.parseParams(_),await this._processRequest(M,_)):this._createNotFoundResponse(M);await this._sendResponse($,W)}catch(_){let W=await this._handleError(M,_);await this._sendResponse($,W)}}async _sendResponse($,D){await new Promise((M)=>{$.write(D.formatHttpResponse(),()=>M()),$.end()})}async _handleError($,D){let M=new k($,new b($)),_=await Promise.resolve(this.errorHandler(M,D));return M.response.setBody(_),M.response}async _processRequest($,D){let M=new k($,new b($)),_=await this._processHooksChain(D,M);if(_)return _;let W=await Promise.resolve(D.handler(M));return await this.hooksManager.processAfterHandler(D,M),M.response.setBody(W),M.response}async _processHooksChain($,D){let M=await this.hooksManager.processBeforeAll($,D);if(M)return D.response.setBody(M),D.response;let _=await this.hooksManager.processBeforeGroup($,D);if(_)return D.response.setBody(_),D.response;let W=await this.hooksManager.processBeforeHandler($,D);if(W)return D.response.setBody(W),D.response;return}_createNotFoundResponse($){let D=new k($,new b($));return D.response.setStatus(v1.NOT_FOUND),D.response.setBody({success:!1,message:"Not found"}),D.response}}import{EventEmitter as h1}from"events";import{ConnectionEvent as f}from "yinzerflow/constants/index.js";class $$ extends h1{_connections=new Set;_server=null;_isListening=!1;_startTime=0;_totalConnections=0;_connectionErrors=0;_configManager;constructor($){super();this._configManager=$}setServer($){if(this._server=$,$)this._totalConnections=0,this._connectionErrors=0}addConnection($){try{let{socketTimeout:D,keepAliveTimeout:M}=this._configManager.connectionOptions;$.setTimeout(D),$.setKeepAlive(!0,M),this._connections.add($),this._totalConnections++,this.emit(f.CONNECTION_ADDED,$),$.on("close",()=>{this._connections.delete($),this.emit(f.CONNECTION_CLOSED,$)}),$.on("error",(_)=>{this._connectionErrors++,this.emit(f.CONNECTION_ERROR,$,_)}),$.on("timeout",()=>{$.end(`HTTP/1.1 408 Request Timeout\r
|
|
18
|
-
\r
|
|
19
|
-
`),$.destroy()})}catch(D){this._connectionErrors++,this.emit(f.CONNECTION_ERROR,$,D)}}getConnections(){return this._connections}getConnectionCount(){return this._connections.size}setListening($){let D=this._isListening;if(this._isListening=$,$&&!D)this._startTime=Date.now(),this.emit(f.SERVER_STARTED);else if(!$&&D)this.emit(f.SERVER_STOPPED)}isListening(){return this._isListening}getServer(){return this._server}getStats(){return{activeConnections:this._connections.size,totalConnections:this._totalConnections,connectionErrors:this._connectionErrors,uptime:this._isListening?Date.now()-this._startTime:0}}async closeAllConnections(){if(this._connections.size===0){this.emit(f.ALL_CONNECTIONS_CLOSED);return}let $=[...this._connections],{gracefulShutdownTimeout:D}=this._configManager.connectionOptions;if(D>0){for(let M of $)try{M.end(`HTTP/1.1 503 Service Unavailable\r
|
|
20
|
-
\r
|
|
21
|
-
`)}catch(_){}await new Promise((M)=>{setTimeout(()=>M(),D)})}for(let M of this._connections)try{M.destroy()}catch(_){}this._connections.clear(),this.emit(f.ALL_CONNECTIONS_CLOSED)}}import{EventEmitter as y1}from"events";import{HookManagerEvent as I,HookPhase as U$,PathMatchingPattern as O$}from "yinzerflow/constants/index.js";class D$ extends y1{hooks=[];pathMatchCache=new Map;add($,D){let M={paths:[],excluded:[],fn:$};if(!D);else if(D.paths===O$.ALL_BUT_EXCLUDED&&Array.isArray(D.excluded))M={paths:O$.ALL_BUT_EXCLUDED,excluded:D.excluded,fn:$};else if(Array.isArray(D.paths))M={paths:D.paths,excluded:D.excluded??[],fn:$};return this.hooks.push(M),this.clearPathMatchCache(),this.emit(I.HOOK_ADDED,M),this}clearPathMatchCache(){this.pathMatchCache.clear()}getHooksForPath($){if(this.pathMatchCache.has($))return this.pathMatchCache.get($)??[];let D=this.hooks.filter((M)=>{if(M.paths===O$.ALL_BUT_EXCLUDED)return!this.isPathExcluded($,M.excluded);if(Array.isArray(M.paths))return this.isPathIncluded($,M.paths)&&!this.isPathExcluded($,M.excluded);return!1});return this.pathMatchCache.set($,D),D}isPathIncluded($,D){if(D.length===0)return!0;return D.some((M)=>{if(M===$)return!0;if(M.endsWith("*")){let _=M.slice(0,-1);return $.startsWith(_)}return!1})}isPathExcluded($,D){return this.isPathIncluded($,D)}async processBeforeAll($,D){if(!this.hooks.length)return;let M=this.getHooksForPath($.path);for(let _ of M)try{let W=await Promise.resolve(_.fn(D));if(this.emit(I.HOOK_EXECUTED,{phase:U$.BEFORE_ALL,path:$.path,result:W?"short-circuit":"continue"}),this.emit(I.BEFORE_ALL_EXECUTED,D,_),W)return W}catch(W){throw console.error(`Hook error for path ${$.path}:`,W),W}return}async processBeforeGroup($,D){if(!$.beforeGroup)return;try{let M=await Promise.resolve($.beforeGroup(D));return this.emit(I.HOOK_EXECUTED,{phase:U$.BEFORE_GROUP,path:$.path,result:M?"short-circuit":"continue"}),this.emit(I.BEFORE_GROUP_EXECUTED,D,$.beforeGroup),M}catch(M){throw console.error(`BeforeGroup hook error for path ${$.path}:`,M),M}}async processBeforeHandler($,D){if(!$.beforeHandler)return;try{let M=await Promise.resolve($.beforeHandler(D));return this.emit(I.HOOK_EXECUTED,{phase:U$.BEFORE_HANDLER,path:$.path,result:M?"short-circuit":"continue"}),this.emit(I.BEFORE_HANDLER_EXECUTED,D,$.beforeHandler),M}catch(M){throw console.error(`BeforeHandler hook error for path ${$.path}:`,M),M}}async processAfterHandler($,D){if(!$.afterHandler)return;try{let M=await Promise.resolve($.afterHandler(D));return this.emit(I.HOOK_EXECUTED,{phase:U$.AFTER_HANDLER,path:$.path,result:M?"modified":"unmodified"}),this.emit(I.AFTER_HANDLER_EXECUTED,D,$.afterHandler),M}catch(M){throw console.error(`AfterHandler hook error for path ${$.path}:`,M),M}}clear(){while(this.hooks.length>0)this.hooks.pop();return this.clearPathMatchCache(),this}get hooksCount(){return this.hooks.length}}class L${routeRegistry=new t;routeFinder=new e(this.routeRegistry);hooksManager=new D$;connectionManager;requestHandler;configManager;_ip=c$.default.address();get hooks(){return this.hooksManager}get config(){return this.configManager}constructor($){this.configManager=new B$($),this.connectionManager=new $$(this.configManager),this.requestHandler=new d(this.routeFinder,this.hooksManager,this.configManager),this.routeRegistry.on(k1.ROUTES_CHANGED,()=>{this.routeFinder.updatePatternRouteCache()})}get=n(this.routeRegistry);post=o(this.routeRegistry);put=r(this.routeRegistry);delete=s(this.routeRegistry);patch=a(this.routeRegistry);group($,D,M){this.routeRegistry.addGroup($,D,M)}beforeAll($,D){return this.hooksManager.add($,D),this}async listen(){return new Promise(($)=>{let{port:D}=this.configManager,M=b1();M.listen(D,this._ip),this.connectionManager.setServer(M),M.on("listening",()=>{this.connectionManager.setListening(!0),$()}),M.on("connection",(_)=>{this.connectionManager.addConnection(_),_.on("data",(W)=>{this.requestHandler.handleSocketRequest(_,W).catch((Y)=>{console.error("Error handling request:",Y)})}),_.on("error",(W)=>{console.error("An error occurred with yinzerflow. Please open an issue on GitHub.",W)})}),M.on("error",(_)=>{console.error("An error occurred with yinzerflow. Please open an issue on GitHub.",_)})})}async close(){if(!this.connectionManager.isListening()||!this.connectionManager.getServer())return;await this.connectionManager.closeAllConnections();let $=this.connectionManager.getServer();if(!$)return;return new Promise((D)=>{$.close(()=>{this.connectionManager.setListening(!1),D()})})}getStatus(){return{isListening:this.connectionManager.isListening(),port:this.configManager.port,ip:this._ip}}}export{Z$ as parseYaml,X$ as parseMultipartFormData,J$ as parseApplicationJson,G$ as isMultipartFormData,y$ as isJsonData,r as addPutRoute,o as addPostRoute,a as addPatchRoute,n as addGetRoute,s as addDeleteRoute,L$ as YinzerFlow,t as RouteRegistry,e as RouteFinder,b as Response,d as RequestHandler,u as Request,T2 as HttpStatusCode,L2 as HttpStatus,K2 as HttpMethod,D$ as HooksManager,k as Context,P2 as ContentType,$$ as ConnectionManager};
|
|
22
|
-
|
|
23
|
-
//# debugId=44C4E8D87004813F64756E2164756E21
|