@wooksjs/event-http 0.4.11 → 0.4.13

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/dist/index.d.ts CHANGED
@@ -1,559 +1,519 @@
1
- /// <reference types="node" />
2
-
3
- import http from 'http';
4
- import { IncomingHttpHeaders } from 'http';
5
- import { IncomingMessage } from 'http';
6
- import { Server } from 'http';
7
- import { ServerResponse } from 'http';
8
- import { TConsoleBase } from '@prostojs/logger';
9
- import { TEmpty } from '@wooksjs/event-core';
10
- import { TEventOptions } from '@wooksjs/event-core';
11
- import { TGenericContextStore } from '@wooksjs/event-core';
12
- import { THook } from '@wooksjs/event-core';
13
- import { TProstoRouterPathHandle } from '@prostojs/router';
14
- import { TWooksHandler } from 'wooks';
15
- import { TWooksOptions } from 'wooks';
16
- import { URLSearchParams as URLSearchParams_2 } from 'url';
17
- import { Wooks } from 'wooks';
18
- import { WooksAdapterBase } from 'wooks';
19
-
20
- export declare class BaseHttpResponse<BodyType = unknown> {
21
- protected renderer: BaseHttpResponseRenderer;
22
- constructor(renderer?: BaseHttpResponseRenderer);
23
- protected _status: EHttpStatusCode;
24
- protected _body?: BodyType;
25
- protected _headers: Record<string, string | string[]>;
26
- get status(): EHttpStatusCode;
27
- set status(value: EHttpStatusCode);
28
- get body(): BodyType | undefined;
29
- set body(value: BodyType | undefined);
30
- setStatus(value: EHttpStatusCode): this;
31
- setBody(value: BodyType): this;
32
- getContentType(): string | string[];
33
- setContentType(value: string): this;
34
- enableCors(origin?: string): this;
35
- setCookie(name: string, value: string, attrs?: Partial<TCookieAttributes>): this;
36
- setCacheControl(data: TCacheControl): void;
37
- setCookieRaw(rawValue: string): this;
38
- header(name: string, value: string): this;
39
- setHeader(name: string, value: string): this;
40
- getHeader(name: string): string | string[];
41
- protected mergeHeaders(): this;
42
- protected mergeStatus(renderedBody: string | Uint8Array): this;
43
- protected mergeFetchStatus(fetchStatus: number): void;
44
- protected panic(text: string, logger: TConsoleBase): void;
45
- respond(): Promise<unknown>;
46
- }
47
-
48
- export declare class BaseHttpResponseRenderer<T = unknown> implements TWooksResponseRenderer<T> {
49
- render(response: BaseHttpResponse<T>): string | Uint8Array;
50
- }
51
-
52
- /**
53
- * Factory for WooksHttp App
54
- * @param opts TWooksHttpOptions
55
- * @param wooks Wooks | WooksAdapterBase
56
- * @returns WooksHttp
57
- */
58
- export declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
59
-
60
- export declare function createHttpContext(data: THttpEventData, options: TEventOptions): {
61
- getCtx: () => THttpContextStore & TGenericContextStore<THttpEventData>;
62
- restoreCtx: () => TGenericContextStore<TEmpty>;
63
- clearCtx: () => null;
64
- store: <K extends keyof THttpContextStore | keyof TGenericContextStore<THttpEventData>>(key: K) => {
65
- value: (THttpContextStore & TGenericContextStore<THttpEventData>)[K];
66
- hook: <K2 extends keyof Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
67
- value: Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K][K2];
68
- isDefined: boolean;
69
- };
70
- init: <K2_1 extends keyof Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>(key2: K2_1, getter: () => Required<Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>[K2_1]) => Required<Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>[K2_1];
71
- set: <K2_2 extends keyof Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>(key2: K2_2, v: Required<(THttpContextStore & TGenericContextStore<THttpEventData>)[K]>[K2_2]) => Required<(THttpContextStore & TGenericContextStore<THttpEventData>)[K]>[K2_2];
72
- get: <K2_3 extends keyof Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>(key2: K2_3) => Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K][K2_3];
73
- has: <K2_4 extends keyof Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>(key2: K2_4) => boolean;
74
- del: <K2_5 extends keyof Required<THttpContextStore & TGenericContextStore<THttpEventData>>[K]>(key2: K2_5) => void;
75
- entries: () => [string, unknown][];
76
- clear: () => void;
77
- };
78
- getStore: <K_1 extends keyof THttpContextStore | keyof TGenericContextStore<THttpEventData>>(key: K_1) => (THttpContextStore & TGenericContextStore<THttpEventData>)[K_1];
79
- setStore: <K_2 extends keyof THttpContextStore | keyof TGenericContextStore<THttpEventData>>(key: K_2, v: (THttpContextStore & TGenericContextStore<THttpEventData>)[K_2]) => void;
80
- };
81
-
82
- export declare function createWooksResponder(renderer?: TWooksResponseRenderer<any>, errorRenderer?: TWooksResponseRenderer<any>): {
83
- createResponse: <T = unknown>(data: T) => BaseHttpResponse<TWooksErrorBodyExt | T> | null;
84
- respond: (data: unknown) => Promise<unknown> | undefined;
85
- };
86
-
87
- export declare enum EHttpStatusCode {
88
- Continue = 100,
89
- SwitchingProtocols = 101,
90
- Processing = 102,
91
- EarlyHints = 103,
92
- OK = 200,
93
- Created = 201,
94
- Accepted = 202,
95
- NonAuthoritativeInformation = 203,
96
- NoContent = 204,
97
- ResetContent = 205,
98
- PartialContent = 206,
99
- MultiStatus = 207,
100
- AlreadyReported = 208,
101
- IMUsed = 226,
102
- MultipleChoices = 300,
103
- MovedPermanently = 301,
104
- Found = 302,
105
- SeeOther = 303,
106
- NotModified = 304,
107
- UseProxy = 305,
108
- SwitchProxy = 306,
109
- TemporaryRedirect = 307,
110
- PermanentRedirect = 308,
111
- BadRequest = 400,
112
- Unauthorized = 401,
113
- PaymentRequired = 402,
114
- Forbidden = 403,
115
- NotFound = 404,
116
- MethodNotAllowed = 405,
117
- NotAcceptable = 406,
118
- ProxyAuthenticationRequired = 407,
119
- RequestTimeout = 408,
120
- Conflict = 409,
121
- Gone = 410,
122
- LengthRequired = 411,
123
- PreconditionFailed = 412,
124
- PayloadTooLarge = 413,
125
- URITooLong = 414,
126
- UnsupportedMediaType = 415,
127
- RangeNotSatisfiable = 416,
128
- ExpectationFailed = 417,
129
- ImATeapot = 418,
130
- MisdirectedRequest = 421,
131
- UnprocessableEntity = 422,
132
- Locked = 423,
133
- FailedDependency = 424,
134
- TooEarly = 425,
135
- UpgradeRequired = 426,
136
- PreconditionRequired = 428,
137
- TooManyRequests = 429,
138
- RequestHeaderFieldsTooLarge = 431,
139
- UnavailableForLegalReasons = 451,
140
- InternalServerError = 500,
141
- NotImplemented = 501,
142
- BadGateway = 502,
143
- ServiceUnavailable = 503,
144
- GatewayTimeout = 504,
145
- HTTPVersionNotSupported = 505,
146
- VariantAlsoNegotiates = 506,
147
- InsufficientStorage = 507,
148
- LoopDetected = 508,
149
- NotExtended = 510,
150
- NetworkAuthenticationRequired = 511
151
- }
152
-
153
- export declare class HttpError<T extends TWooksErrorBody = TWooksErrorBody> extends Error {
154
- protected code: THttpErrorCodes;
155
- protected _body: string | T;
156
- constructor(code?: THttpErrorCodes, _body?: string | T);
157
- get body(): TWooksErrorBodyExt;
158
- protected renderer?: HttpErrorRenderer;
159
- attachRenderer(renderer: HttpErrorRenderer): void;
160
- getRenderer(): HttpErrorRenderer | undefined;
161
- }
162
-
163
- export declare class HttpErrorRenderer extends BaseHttpResponseRenderer<TWooksErrorBodyExt> {
164
- renderHtml(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
165
- renderText(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
166
- renderJson(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
167
- render(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
168
- }
169
-
170
- export declare const httpStatusCodes: {
171
- 100: string;
172
- 101: string;
173
- 102: string;
174
- 103: string;
175
- 200: string;
176
- 201: string;
177
- 202: string;
178
- 203: string;
179
- 204: string;
180
- 205: string;
181
- 206: string;
182
- 207: string;
183
- 208: string;
184
- 226: string;
185
- 300: string;
186
- 301: string;
187
- 302: string;
188
- 303: string;
189
- 304: string;
190
- 305: string;
191
- 306: string;
192
- 307: string;
193
- 308: string;
194
- 400: string;
195
- 401: string;
196
- 402: string;
197
- 403: string;
198
- 404: string;
199
- 405: string;
200
- 406: string;
201
- 407: string;
202
- 408: string;
203
- 409: string;
204
- 410: string;
205
- 411: string;
206
- 412: string;
207
- 413: string;
208
- 414: string;
209
- 415: string;
210
- 416: string;
211
- 417: string;
212
- 418: string;
213
- 421: string;
214
- 422: string;
215
- 423: string;
216
- 424: string;
217
- 425: string;
218
- 426: string;
219
- 428: string;
220
- 429: string;
221
- 431: string;
222
- 451: string;
223
- 500: string;
224
- 501: string;
225
- 502: string;
226
- 503: string;
227
- 504: string;
228
- 505: string;
229
- 506: string;
230
- 507: string;
231
- 508: string;
232
- 510: string;
233
- 511: string;
234
- };
235
-
236
- export declare function renderCacheControl(data: TCacheControl): string;
237
-
238
- export declare type TAuthCache = {
239
- type: string | null;
240
- credentials: string | null;
241
- basicCredentials: {
242
- username: string;
243
- password: string;
244
- } | null;
245
- };
246
-
247
- export declare type TCacheControl = {
248
- mustRevalidate?: boolean;
249
- noCache?: boolean | string;
250
- noStore?: boolean;
251
- noTransform?: boolean;
252
- public?: boolean;
253
- private?: boolean | string;
254
- proxyRevalidate?: boolean;
255
- maxAge?: number | TTimeMultiString;
256
- sMaxage?: number | TTimeMultiString;
257
- };
258
-
259
- export declare interface TCookieAttributes {
260
- expires: Date | string | number;
261
- maxAge: number | TTimeMultiString;
262
- domain: string;
263
- path: string;
264
- secure: boolean;
265
- httpOnly: boolean;
266
- sameSite: boolean | 'Lax' | 'None' | 'Strict';
267
- }
268
-
269
- export declare type TCookieAttributesInput = Partial<TCookieAttributes>;
270
-
271
- export declare type TCookieHook = ReturnType<typeof useSetCookie>;
272
-
273
- export declare type THeaderHook = ReturnType<typeof useSetHeader>;
274
-
275
- declare type THttpBadRequestCodes = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
276
-
277
- export declare interface THttpContextStore {
278
- searchParams?: TSearchParamsCache;
279
- cookies?: {
280
- [name: string]: string | null;
281
- };
282
- setCookies?: {
283
- [name: string]: TSetCookieData;
284
- };
285
- accept?: {
286
- [name: string]: boolean;
287
- };
288
- authorization?: TAuthCache;
289
- setHeader?: {
290
- [name: string]: string | string[];
291
- };
292
- request?: TRequestCache;
293
- response?: {
294
- responded: boolean;
295
- };
296
- status?: {
297
- code: EHttpStatusCode;
298
- };
299
- }
300
-
301
- declare type THttpErrorCodes = THttpBadRequestCodes | THttpServerErrorCodes;
302
-
303
- export declare interface THttpEvent {
304
- type: 'HTTP';
305
- }
306
-
307
- export declare interface THttpEventData {
308
- req: IncomingMessage;
309
- res: ServerResponse;
310
- }
311
-
312
- declare type THttpServerErrorCodes = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
313
-
314
- export declare type TRequestCache = {
315
- rawBody: Promise<Buffer>;
316
- parsed: unknown;
317
- forwardedIp?: string;
318
- remoteIp?: string;
319
- ipList?: {
320
- remoteIp: string;
321
- forwarded: string[];
322
- };
323
- };
324
-
325
- export declare type TSearchParamsCache = {
326
- raw?: string;
327
- urlSearchParams?: WooksURLSearchParams;
328
- };
329
-
330
- export declare type TSetCookieData = {
331
- value: string;
332
- attrs: TCookieAttributesInput;
333
- };
334
-
335
- export declare type TStatusHook = ReturnType<typeof useStatus>;
336
-
337
- declare type TTimeMultiString = `${TTimeSingleString}${TTimeSingleString | ''}${TTimeSingleString | ''}${TTimeSingleString | ''}`;
338
-
339
- declare type TTimeSingleString = `${number}${TTimeUnit}`;
340
-
341
- declare type TTimeUnit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'Y';
342
-
343
- declare type TUseResponseOptions = {
344
- passthrough: boolean;
345
- };
346
-
347
- export declare interface TWooksErrorBody {
348
- message: string;
349
- statusCode: EHttpStatusCode;
350
- error?: string;
351
- }
352
-
353
- export declare interface TWooksErrorBodyExt extends TWooksErrorBody {
354
- error: string;
355
- }
356
-
357
- export declare interface TWooksHttpOptions {
358
- logger?: TConsoleBase;
359
- eventOptions?: TEventOptions;
360
- onNotFound?: TWooksHandler<unknown>;
361
- router?: TWooksOptions['router'];
362
- }
363
-
364
- export declare interface TWooksResponseRenderer<T = unknown> {
365
- render: (response: BaseHttpResponse<T>) => string | Uint8Array;
366
- }
367
-
368
- export declare function useAccept(): {
369
- accept: string | undefined;
370
- accepts: (mime: string) => unknown;
371
- acceptsJson: () => unknown;
372
- acceptsXml: () => unknown;
373
- acceptsText: () => unknown;
374
- acceptsHtml: () => unknown;
375
- };
376
-
377
- export declare function useAuthorization(): {
378
- authorization: string | undefined;
379
- authType: () => string | null;
380
- authRawCredentials: () => string | null;
381
- isBasic: () => boolean;
382
- isBearer: () => boolean;
383
- basicCredentials: () => {
384
- username: string;
385
- password: string;
386
- } | null;
387
- };
388
-
389
- export declare function useCookies(): {
390
- rawCookies: string | undefined;
391
- getCookie: (name: string) => string | null;
392
- };
393
-
394
- export declare function useHeaders(): IncomingHttpHeaders;
395
-
396
- /**
397
- * Wrapper on useEventContext with HTTP event types
398
- * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
399
- */
400
- export declare function useHttpContext<T extends TEmpty>(): {
401
- getCtx: () => THttpContextStore & T & TGenericContextStore<THttpEventData>;
402
- restoreCtx: () => TGenericContextStore<TEmpty>;
403
- clearCtx: () => null;
404
- store: <K extends keyof THttpContextStore | keyof TGenericContextStore<THttpEventData> | keyof T>(key: K) => {
405
- value: (THttpContextStore & T & TGenericContextStore<THttpEventData>)[K];
406
- hook: <K2 extends keyof Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
407
- value: Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K][K2];
408
- isDefined: boolean;
409
- };
410
- init: <K2_1 extends keyof Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>(key2: K2_1, getter: () => Required<Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>[K2_1]) => Required<Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>[K2_1];
411
- set: <K2_2 extends keyof Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>(key2: K2_2, v: Required<(THttpContextStore & T & TGenericContextStore<THttpEventData>)[K]>[K2_2]) => Required<(THttpContextStore & T & TGenericContextStore<THttpEventData>)[K]>[K2_2];
412
- get: <K2_3 extends keyof Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>(key2: K2_3) => Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K][K2_3];
413
- has: <K2_4 extends keyof Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>(key2: K2_4) => boolean;
414
- del: <K2_5 extends keyof Required<THttpContextStore & T & TGenericContextStore<THttpEventData>>[K]>(key2: K2_5) => void;
415
- entries: () => [string, unknown][];
416
- clear: () => void;
417
- };
418
- getStore: <K_1 extends keyof THttpContextStore | keyof TGenericContextStore<THttpEventData> | keyof T>(key: K_1) => (THttpContextStore & T & TGenericContextStore<THttpEventData>)[K_1];
419
- setStore: <K_2 extends keyof THttpContextStore | keyof TGenericContextStore<THttpEventData> | keyof T>(key: K_2, v: (THttpContextStore & T & TGenericContextStore<THttpEventData>)[K_2]) => void;
420
- };
421
-
422
- export declare function useRequest(): {
423
- rawRequest: IncomingMessage;
424
- url: string | undefined;
425
- method: string | undefined;
426
- headers: IncomingHttpHeaders;
427
- rawBody: () => Promise<Buffer>;
428
- reqId: () => string;
429
- getIp: (options?: {
430
- trustProxy: boolean;
431
- }) => string;
432
- getIpList: () => {
433
- remoteIp: string;
434
- forwarded: string[];
435
- };
436
- };
437
-
438
- export declare function useResponse(): {
439
- rawResponse: (options?: TUseResponseOptions) => ServerResponse<IncomingMessage>;
440
- hasResponded: () => boolean;
441
- status: ((code?: EHttpStatusCode) => EHttpStatusCode) & THook<EHttpStatusCode, "value">;
442
- };
443
-
444
- export declare function useSearchParams(): {
445
- rawSearchParams: () => string;
446
- urlSearchParams: () => WooksURLSearchParams;
447
- jsonSearchParams: () => unknown;
448
- };
449
-
450
- export declare function useSetCacheControl(): {
451
- setExpires: (value: Date | string | number) => void;
452
- setAge: (value: number | TTimeMultiString) => void;
453
- setPragmaNoCache: (value?: boolean) => void;
454
- setCacheControl: (data: TCacheControl) => void;
455
- };
456
-
457
- export declare function useSetCookie(name: string): {
458
- name: string;
459
- type: string;
460
- } & THook<string, "value"> & THook<TCookieAttributes, "attrs">;
461
-
462
- export declare function useSetCookies(): {
463
- setCookie: (name: string, value: string, attrs?: Partial<TCookieAttributes>) => void;
464
- getCookie: <K2 extends string | number>(key2: K2) => {
465
- [name: string]: TSetCookieData;
466
- }[K2];
467
- removeCookie: <K2_1 extends string | number>(key2: K2_1) => void;
468
- clearCookies: () => void;
469
- cookies: () => string[];
470
- };
471
-
472
- export declare function useSetHeader(name: string): {
473
- value: string | string[];
474
- isDefined: boolean;
475
- };
476
-
477
- export declare function useSetHeaders(): {
478
- setHeader: (name: string, value: string | number) => void;
479
- getHeader: <K2 extends string | number>(key2: K2) => {
480
- [name: string]: string | string[];
481
- }[K2];
482
- removeHeader: <K2_1 extends string | number>(key2: K2_1) => void;
483
- setContentType: (value: string) => void;
484
- headers: () => {
485
- [name: string]: string | string[];
486
- };
487
- enableCors: (origin?: string) => void;
488
- };
489
-
490
- export declare function useStatus(): {
491
- value: EHttpStatusCode;
492
- isDefined: boolean;
493
- };
494
-
495
- export declare class WooksHttp extends WooksAdapterBase {
496
- protected opts?: TWooksHttpOptions | undefined;
497
- protected logger: TConsoleBase;
498
- constructor(opts?: TWooksHttpOptions | undefined, wooks?: Wooks | WooksAdapterBase);
499
- all<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
500
- get<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
501
- post<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
502
- put<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
503
- patch<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
504
- delete<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
505
- head<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
506
- options<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
507
- protected server?: Server;
508
- /**
509
- * Starts the http(s) server.
510
- *
511
- * Use this only if you rely on Wooks server.
512
- */
513
- listen(...args: Parameters<Server['listen']>): Promise<unknown>;
514
- /**
515
- * Stops the server if it was attached or passed via argument
516
- * @param server
517
- */
518
- close(server?: Server): Promise<unknown>;
519
- /**
520
- * Returns http(s) server that was attached to Wooks
521
- *
522
- * See attachServer method docs
523
- * @returns Server
524
- */
525
- getServer(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
526
- /**
527
- * Attaches http(s) server instance
528
- * to Wooks.
529
- *
530
- * Use it only if you want to `close` method to stop the server.
531
- * @param server Server
532
- */
533
- attachServer(server?: Server): void;
534
- protected responder: {
535
- createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
536
- respond: (data: unknown) => Promise<unknown> | undefined;
537
- };
538
- protected respond(data: unknown): void;
539
- /**
540
- * Returns server callback function
541
- * that can be passed to any node server:
542
- * ```js
543
- * import { createHttpApp } from '@wooksjs/event-http'
544
- * import http from 'http'
545
- *
546
- * const app = createHttpApp()
547
- * const server = http.createServer(app.getServerCb())
548
- * server.listen(3000)
549
- * ```
550
- */
551
- getServerCb(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
552
- protected processHandlers(handlers: TWooksHandler<unknown>[]): Promise<void>;
553
- }
554
-
555
- export declare class WooksURLSearchParams extends URLSearchParams_2 {
556
- toJson<T = unknown>(): T;
557
- }
558
-
559
- export { }
1
+ import * as http from 'http';
2
+ import http__default, { IncomingHttpHeaders, IncomingMessage, ServerResponse, Server } from 'http';
3
+ import * as _wooksjs_event_core from '@wooksjs/event-core';
4
+ import { TEventOptions, TEmpty } from '@wooksjs/event-core';
5
+ import { URLSearchParams } from 'url';
6
+ import { TConsoleBase } from '@prostojs/logger';
7
+ import * as _prostojs_router from '@prostojs/router';
8
+ import { TWooksHandler, TWooksOptions, WooksAdapterBase, Wooks } from 'wooks';
9
+
10
+ declare function useHeaders(): IncomingHttpHeaders;
11
+ declare function useSetHeaders(): {
12
+ setHeader: (name: string, value: string | number) => void;
13
+ getHeader: <K2 extends string | number>(key2: K2) => {
14
+ [name: string]: string | string[];
15
+ }[K2];
16
+ removeHeader: <K2_1 extends string | number>(key2: K2_1) => void;
17
+ setContentType: (value: string) => void;
18
+ headers: () => {
19
+ [name: string]: string | string[];
20
+ };
21
+ enableCors: (origin?: string) => void;
22
+ };
23
+ declare function useSetHeader(name: string): {
24
+ value: string | string[];
25
+ isDefined: boolean;
26
+ };
27
+ type THeaderHook = ReturnType<typeof useSetHeader>;
28
+
29
+ declare function useAccept(): {
30
+ accept: string | undefined;
31
+ accepts: (mime: string) => unknown;
32
+ acceptsJson: () => unknown;
33
+ acceptsXml: () => unknown;
34
+ acceptsText: () => unknown;
35
+ acceptsHtml: () => unknown;
36
+ };
37
+
38
+ declare function useAuthorization(): {
39
+ authorization: string | undefined;
40
+ authType: () => string | null;
41
+ authRawCredentials: () => string | null;
42
+ isBasic: () => boolean;
43
+ isBearer: () => boolean;
44
+ basicCredentials: () => {
45
+ username: string;
46
+ password: string;
47
+ } | null;
48
+ };
49
+
50
+ type TTimeUnit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'Y';
51
+ type TTimeSingleString = `${number}${TTimeUnit}`;
52
+ type TTimeMultiString = `${TTimeSingleString}${TTimeSingleString | ''}${TTimeSingleString | ''}${TTimeSingleString | ''}`;
53
+
54
+ type TCacheControl = {
55
+ mustRevalidate?: boolean;
56
+ noCache?: boolean | string;
57
+ noStore?: boolean;
58
+ noTransform?: boolean;
59
+ public?: boolean;
60
+ private?: boolean | string;
61
+ proxyRevalidate?: boolean;
62
+ maxAge?: number | TTimeMultiString;
63
+ sMaxage?: number | TTimeMultiString;
64
+ };
65
+ declare function renderCacheControl(data: TCacheControl): string;
66
+
67
+ declare function useSetCacheControl(): {
68
+ setExpires: (value: Date | string | number) => void;
69
+ setAge: (value: number | TTimeMultiString) => void;
70
+ setPragmaNoCache: (value?: boolean) => void;
71
+ setCacheControl: (data: TCacheControl) => void;
72
+ };
73
+
74
+ declare function useRequest(): {
75
+ rawRequest: http.IncomingMessage;
76
+ url: string | undefined;
77
+ method: string | undefined;
78
+ headers: http.IncomingHttpHeaders;
79
+ rawBody: () => Promise<Buffer>;
80
+ reqId: () => string;
81
+ getIp: (options?: {
82
+ trustProxy: boolean;
83
+ }) => string;
84
+ getIpList: () => {
85
+ remoteIp: string;
86
+ forwarded: string[];
87
+ };
88
+ };
89
+
90
+ declare const httpStatusCodes: {
91
+ 100: string;
92
+ 101: string;
93
+ 102: string;
94
+ 103: string;
95
+ 200: string;
96
+ 201: string;
97
+ 202: string;
98
+ 203: string;
99
+ 204: string;
100
+ 205: string;
101
+ 206: string;
102
+ 207: string;
103
+ 208: string;
104
+ 226: string;
105
+ 300: string;
106
+ 301: string;
107
+ 302: string;
108
+ 303: string;
109
+ 304: string;
110
+ 305: string;
111
+ 306: string;
112
+ 307: string;
113
+ 308: string;
114
+ 400: string;
115
+ 401: string;
116
+ 402: string;
117
+ 403: string;
118
+ 404: string;
119
+ 405: string;
120
+ 406: string;
121
+ 407: string;
122
+ 408: string;
123
+ 409: string;
124
+ 410: string;
125
+ 411: string;
126
+ 412: string;
127
+ 413: string;
128
+ 414: string;
129
+ 415: string;
130
+ 416: string;
131
+ 417: string;
132
+ 418: string;
133
+ 421: string;
134
+ 422: string;
135
+ 423: string;
136
+ 424: string;
137
+ 425: string;
138
+ 426: string;
139
+ 428: string;
140
+ 429: string;
141
+ 431: string;
142
+ 451: string;
143
+ 500: string;
144
+ 501: string;
145
+ 502: string;
146
+ 503: string;
147
+ 504: string;
148
+ 505: string;
149
+ 506: string;
150
+ 507: string;
151
+ 508: string;
152
+ 510: string;
153
+ 511: string;
154
+ };
155
+ declare enum EHttpStatusCode {
156
+ Continue = 100,
157
+ SwitchingProtocols = 101,
158
+ Processing = 102,
159
+ EarlyHints = 103,
160
+ OK = 200,
161
+ Created = 201,
162
+ Accepted = 202,
163
+ NonAuthoritativeInformation = 203,
164
+ NoContent = 204,
165
+ ResetContent = 205,
166
+ PartialContent = 206,
167
+ MultiStatus = 207,
168
+ AlreadyReported = 208,
169
+ IMUsed = 226,
170
+ MultipleChoices = 300,
171
+ MovedPermanently = 301,
172
+ Found = 302,
173
+ SeeOther = 303,
174
+ NotModified = 304,
175
+ UseProxy = 305,
176
+ SwitchProxy = 306,
177
+ TemporaryRedirect = 307,
178
+ PermanentRedirect = 308,
179
+ BadRequest = 400,
180
+ Unauthorized = 401,
181
+ PaymentRequired = 402,
182
+ Forbidden = 403,
183
+ NotFound = 404,
184
+ MethodNotAllowed = 405,
185
+ NotAcceptable = 406,
186
+ ProxyAuthenticationRequired = 407,
187
+ RequestTimeout = 408,
188
+ Conflict = 409,
189
+ Gone = 410,
190
+ LengthRequired = 411,
191
+ PreconditionFailed = 412,
192
+ PayloadTooLarge = 413,
193
+ URITooLong = 414,
194
+ UnsupportedMediaType = 415,
195
+ RangeNotSatisfiable = 416,
196
+ ExpectationFailed = 417,
197
+ ImATeapot = 418,
198
+ MisdirectedRequest = 421,
199
+ UnprocessableEntity = 422,
200
+ Locked = 423,
201
+ FailedDependency = 424,
202
+ TooEarly = 425,
203
+ UpgradeRequired = 426,
204
+ PreconditionRequired = 428,
205
+ TooManyRequests = 429,
206
+ RequestHeaderFieldsTooLarge = 431,
207
+ UnavailableForLegalReasons = 451,
208
+ InternalServerError = 500,
209
+ NotImplemented = 501,
210
+ BadGateway = 502,
211
+ ServiceUnavailable = 503,
212
+ GatewayTimeout = 504,
213
+ HTTPVersionNotSupported = 505,
214
+ VariantAlsoNegotiates = 506,
215
+ InsufficientStorage = 507,
216
+ LoopDetected = 508,
217
+ NotExtended = 510,
218
+ NetworkAuthenticationRequired = 511
219
+ }
220
+ type THttpBadRequestCodes = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
221
+ type THttpServerErrorCodes = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
222
+ type THttpErrorCodes = THttpBadRequestCodes | THttpServerErrorCodes;
223
+
224
+ type TUseResponseOptions = {
225
+ passthrough: boolean;
226
+ };
227
+ declare function useResponse(): {
228
+ rawResponse: (options?: TUseResponseOptions) => http.ServerResponse<http.IncomingMessage>;
229
+ hasResponded: () => boolean;
230
+ status: ((code?: EHttpStatusCode) => EHttpStatusCode) & _wooksjs_event_core.THook<EHttpStatusCode, "value">;
231
+ };
232
+ declare function useStatus(): {
233
+ value: EHttpStatusCode;
234
+ isDefined: boolean;
235
+ };
236
+ type TStatusHook = ReturnType<typeof useStatus>;
237
+
238
+ declare class WooksURLSearchParams extends URLSearchParams {
239
+ toJson<T = unknown>(): T;
240
+ }
241
+
242
+ interface THttpEventData {
243
+ req: IncomingMessage;
244
+ res: ServerResponse;
245
+ }
246
+ interface THttpEvent {
247
+ type: 'HTTP';
248
+ }
249
+ interface THttpContextStore {
250
+ searchParams?: TSearchParamsCache;
251
+ cookies?: {
252
+ [name: string]: string | null;
253
+ };
254
+ setCookies?: {
255
+ [name: string]: TSetCookieData;
256
+ };
257
+ accept?: {
258
+ [name: string]: boolean;
259
+ };
260
+ authorization?: TAuthCache;
261
+ setHeader?: {
262
+ [name: string]: string | string[];
263
+ };
264
+ request?: TRequestCache;
265
+ response?: {
266
+ responded: boolean;
267
+ };
268
+ status?: {
269
+ code: EHttpStatusCode;
270
+ };
271
+ }
272
+ type TSetCookieData = {
273
+ value: string;
274
+ attrs: TCookieAttributesInput;
275
+ };
276
+ type TCookieAttributesInput = Partial<TCookieAttributes>;
277
+ interface TCookieAttributes {
278
+ expires: Date | string | number;
279
+ maxAge: number | TTimeMultiString;
280
+ domain: string;
281
+ path: string;
282
+ secure: boolean;
283
+ httpOnly: boolean;
284
+ sameSite: boolean | 'Lax' | 'None' | 'Strict';
285
+ }
286
+ type TAuthCache = {
287
+ type: string | null;
288
+ credentials: string | null;
289
+ basicCredentials: {
290
+ username: string;
291
+ password: string;
292
+ } | null;
293
+ };
294
+ type TRequestCache = {
295
+ rawBody: Promise<Buffer>;
296
+ parsed: unknown;
297
+ forwardedIp?: string;
298
+ remoteIp?: string;
299
+ ipList?: {
300
+ remoteIp: string;
301
+ forwarded: string[];
302
+ };
303
+ };
304
+ type TSearchParamsCache = {
305
+ raw?: string;
306
+ urlSearchParams?: WooksURLSearchParams;
307
+ };
308
+
309
+ declare function useCookies(): {
310
+ rawCookies: string | undefined;
311
+ getCookie: (name: string) => string | null;
312
+ };
313
+ declare function useSetCookies(): {
314
+ setCookie: (name: string, value: string, attrs?: Partial<TCookieAttributes>) => void;
315
+ getCookie: <K2 extends string | number>(key2: K2) => {
316
+ [name: string]: TSetCookieData;
317
+ }[K2];
318
+ removeCookie: <K2_1 extends string | number>(key2: K2_1) => void;
319
+ clearCookies: () => void;
320
+ cookies: () => string[];
321
+ };
322
+ declare function useSetCookie(name: string): {
323
+ name: string;
324
+ type: string;
325
+ } & _wooksjs_event_core.THook<string, "value"> & _wooksjs_event_core.THook<TCookieAttributes, "attrs">;
326
+ type TCookieHook = ReturnType<typeof useSetCookie>;
327
+
328
+ declare function useSearchParams(): {
329
+ rawSearchParams: () => string;
330
+ urlSearchParams: () => WooksURLSearchParams;
331
+ jsonSearchParams: () => unknown;
332
+ };
333
+
334
+ declare class BaseHttpResponseRenderer<T = unknown> implements TWooksResponseRenderer<T> {
335
+ render(response: BaseHttpResponse<T>): string | Uint8Array;
336
+ }
337
+ interface TWooksResponseRenderer<T = unknown> {
338
+ render: (response: BaseHttpResponse<T>) => string | Uint8Array;
339
+ }
340
+
341
+ declare class BaseHttpResponse<BodyType = unknown> {
342
+ protected renderer: BaseHttpResponseRenderer;
343
+ constructor(renderer?: BaseHttpResponseRenderer);
344
+ protected _status: EHttpStatusCode;
345
+ protected _body?: BodyType;
346
+ protected _headers: Record<string, string | string[]>;
347
+ get status(): EHttpStatusCode;
348
+ set status(value: EHttpStatusCode);
349
+ get body(): BodyType | undefined;
350
+ set body(value: BodyType | undefined);
351
+ setStatus(value: EHttpStatusCode): this;
352
+ setBody(value: BodyType): this;
353
+ getContentType(): string | string[];
354
+ setContentType(value: string): this;
355
+ enableCors(origin?: string): this;
356
+ setCookie(name: string, value: string, attrs?: Partial<TCookieAttributes>): this;
357
+ setCacheControl(data: TCacheControl): void;
358
+ setCookieRaw(rawValue: string): this;
359
+ header(name: string, value: string): this;
360
+ setHeader(name: string, value: string): this;
361
+ getHeader(name: string): string | string[];
362
+ protected mergeHeaders(): this;
363
+ protected mergeStatus(renderedBody: string | Uint8Array): this;
364
+ protected mergeFetchStatus(fetchStatus: number): void;
365
+ protected panic(text: string, logger: TConsoleBase): void;
366
+ respond(): Promise<unknown>;
367
+ }
368
+
369
+ declare class HttpErrorRenderer extends BaseHttpResponseRenderer<TWooksErrorBodyExt> {
370
+ renderHtml(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
371
+ renderText(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
372
+ renderJson(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
373
+ render(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
374
+ }
375
+
376
+ declare class HttpError<T extends TWooksErrorBody = TWooksErrorBody> extends Error {
377
+ protected code: THttpErrorCodes;
378
+ protected _body: string | T;
379
+ constructor(code?: THttpErrorCodes, _body?: string | T);
380
+ get body(): TWooksErrorBodyExt;
381
+ protected renderer?: HttpErrorRenderer;
382
+ attachRenderer(renderer: HttpErrorRenderer): void;
383
+ getRenderer(): HttpErrorRenderer | undefined;
384
+ }
385
+ interface TWooksErrorBody {
386
+ message: string;
387
+ statusCode: EHttpStatusCode;
388
+ error?: string;
389
+ }
390
+ interface TWooksErrorBodyExt extends TWooksErrorBody {
391
+ error: string;
392
+ }
393
+
394
+ declare function createWooksResponder(renderer?: TWooksResponseRenderer<any>, errorRenderer?: TWooksResponseRenderer<any>): {
395
+ createResponse: <T = unknown>(data: T) => BaseHttpResponse<TWooksErrorBodyExt | T> | null;
396
+ respond: (data: unknown) => Promise<unknown> | undefined;
397
+ };
398
+
399
+ declare function createHttpContext(data: THttpEventData, options: TEventOptions): {
400
+ getCtx: () => THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>;
401
+ restoreCtx: () => _wooksjs_event_core.TGenericContextStore<TEmpty>;
402
+ clearCtx: () => null;
403
+ store: <K extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData>>(key: K) => {
404
+ value: (THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K];
405
+ hook: <K2 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
406
+ value: Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K][K2];
407
+ isDefined: boolean;
408
+ };
409
+ init: <K2_1 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_1, getter: () => Required<Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>[K2_1]) => Required<Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>[K2_1];
410
+ set: <K2_2 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_2, v: Required<(THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K]>[K2_2]) => Required<(THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K]>[K2_2];
411
+ get: <K2_3 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_3) => Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K][K2_3];
412
+ has: <K2_4 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_4) => boolean;
413
+ del: <K2_5 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_5) => void;
414
+ entries: () => [string, unknown][];
415
+ clear: () => void;
416
+ };
417
+ getStore: <K_1 extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData>>(key: K_1) => (THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K_1];
418
+ setStore: <K_2 extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData>>(key: K_2, v: (THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K_2]) => void;
419
+ };
420
+ /**
421
+ * Wrapper on useEventContext with HTTP event types
422
+ * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
423
+ */
424
+ declare function useHttpContext<T extends TEmpty>(): {
425
+ getCtx: () => THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>;
426
+ restoreCtx: () => _wooksjs_event_core.TGenericContextStore<TEmpty>;
427
+ clearCtx: () => null;
428
+ store: <K extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData> | keyof T>(key: K) => {
429
+ value: (THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K];
430
+ hook: <K2 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
431
+ value: Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K][K2];
432
+ isDefined: boolean;
433
+ };
434
+ init: <K2_1 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_1, getter: () => Required<Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>[K2_1]) => Required<Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>[K2_1];
435
+ set: <K2_2 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_2, v: Required<(THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K]>[K2_2]) => Required<(THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K]>[K2_2];
436
+ get: <K2_3 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_3) => Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K][K2_3];
437
+ has: <K2_4 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_4) => boolean;
438
+ del: <K2_5 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2_5) => void;
439
+ entries: () => [string, unknown][];
440
+ clear: () => void;
441
+ };
442
+ getStore: <K_1 extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData> | keyof T>(key: K_1) => (THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K_1];
443
+ setStore: <K_2 extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData> | keyof T>(key: K_2, v: (THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K_2]) => void;
444
+ };
445
+
446
+ interface TWooksHttpOptions {
447
+ logger?: TConsoleBase;
448
+ eventOptions?: TEventOptions;
449
+ onNotFound?: TWooksHandler<unknown>;
450
+ router?: TWooksOptions['router'];
451
+ }
452
+ declare class WooksHttp extends WooksAdapterBase {
453
+ protected opts?: TWooksHttpOptions | undefined;
454
+ protected logger: TConsoleBase;
455
+ constructor(opts?: TWooksHttpOptions | undefined, wooks?: Wooks | WooksAdapterBase);
456
+ all<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
457
+ get<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
458
+ post<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
459
+ put<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
460
+ patch<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
461
+ delete<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
462
+ head<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
463
+ options<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): _prostojs_router.TProstoRouterPathHandle<ParamsType>;
464
+ protected server?: Server;
465
+ /**
466
+ * Starts the http(s) server.
467
+ *
468
+ * Use this only if you rely on Wooks server.
469
+ */
470
+ listen(...args: Parameters<Server['listen']>): Promise<unknown>;
471
+ /**
472
+ * Stops the server if it was attached or passed via argument
473
+ * @param server
474
+ */
475
+ close(server?: Server): Promise<unknown>;
476
+ /**
477
+ * Returns http(s) server that was attached to Wooks
478
+ *
479
+ * See attachServer method docs
480
+ * @returns Server
481
+ */
482
+ getServer(): http__default.Server<typeof http__default.IncomingMessage, typeof http__default.ServerResponse> | undefined;
483
+ /**
484
+ * Attaches http(s) server instance
485
+ * to Wooks.
486
+ *
487
+ * Use it only if you want to `close` method to stop the server.
488
+ * @param server Server
489
+ */
490
+ attachServer(server?: Server): void;
491
+ protected responder: {
492
+ createResponse: <T = unknown>(data: T) => BaseHttpResponse<TWooksErrorBodyExt | T> | null;
493
+ respond: (data: unknown) => Promise<unknown> | undefined;
494
+ };
495
+ protected respond(data: unknown): void;
496
+ /**
497
+ * Returns server callback function
498
+ * that can be passed to any node server:
499
+ * ```js
500
+ * import { createHttpApp } from '@wooksjs/event-http'
501
+ * import http from 'http'
502
+ *
503
+ * const app = createHttpApp()
504
+ * const server = http.createServer(app.getServerCb())
505
+ * server.listen(3000)
506
+ * ```
507
+ */
508
+ getServerCb(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
509
+ protected processHandlers(handlers: TWooksHandler<unknown>[]): Promise<void>;
510
+ }
511
+ /**
512
+ * Factory for WooksHttp App
513
+ * @param opts TWooksHttpOptions
514
+ * @param wooks Wooks | WooksAdapterBase
515
+ * @returns WooksHttp
516
+ */
517
+ declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
518
+
519
+ export { BaseHttpResponse, BaseHttpResponseRenderer, EHttpStatusCode, HttpError, HttpErrorRenderer, type TAuthCache, type TCacheControl, type TCookieAttributes, type TCookieAttributesInput, type TCookieHook, type THeaderHook, type THttpContextStore, type THttpEvent, type THttpEventData, type TRequestCache, type TSearchParamsCache, type TSetCookieData, type TStatusHook, type TWooksErrorBody, type TWooksErrorBodyExt, type TWooksHttpOptions, type TWooksResponseRenderer, WooksHttp, WooksURLSearchParams, createHttpApp, createHttpContext, createWooksResponder, httpStatusCodes, renderCacheControl, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useSearchParams, useSetCacheControl, useSetCookie, useSetCookies, useSetHeader, useSetHeaders, useStatus };