@wooksjs/event-http 0.5.25 → 0.6.1

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,5 +1,5 @@
1
1
  import * as _wooksjs_event_core from '@wooksjs/event-core';
2
- import { TEventOptions, TEmpty } from '@wooksjs/event-core';
2
+ import { TEventOptions, TEmpty, TCtxHelpers, TGenericContextStore } from '@wooksjs/event-core';
3
3
  export { useEventLogger, useRouteParams } from '@wooksjs/event-core';
4
4
  import * as http from 'http';
5
5
  import { IncomingMessage, ServerResponse, IncomingHttpHeaders, Server } from 'http';
@@ -205,6 +205,12 @@ interface TRequestCache {
205
205
  remoteIp: string;
206
206
  forwarded: string[];
207
207
  };
208
+ contentEncodings?: string[];
209
+ isCompressed?: boolean;
210
+ maxCompressed?: number;
211
+ maxInflated?: number;
212
+ maxRatio?: number;
213
+ readTimeoutMs?: number;
208
214
  }
209
215
  interface TSearchParamsCache {
210
216
  raw?: string;
@@ -284,6 +290,12 @@ declare function useSetHeader(name: string): {
284
290
  };
285
291
  type THeaderHook = ReturnType<typeof useSetHeader>;
286
292
 
293
+ declare const DEFAULT_LIMITS: {
294
+ readonly maxCompressed: number;
295
+ readonly maxInflated: number;
296
+ readonly maxRatio: 100;
297
+ readonly readTimeoutMs: 10000;
298
+ };
287
299
  declare function useRequest(): {
288
300
  rawRequest: http.IncomingMessage;
289
301
  url: string | undefined;
@@ -298,6 +310,13 @@ declare function useRequest(): {
298
310
  remoteIp: string;
299
311
  forwarded: string[];
300
312
  };
313
+ isCompressed: () => boolean;
314
+ getMaxCompressed: () => number;
315
+ setMaxCompressed: (limit: number) => unknown;
316
+ getReadTimeoutMs: () => number;
317
+ setReadTimeoutMs: (limit: number) => unknown;
318
+ getMaxInflated: () => number;
319
+ setMaxInflated: (limit: number) => unknown;
301
320
  };
302
321
 
303
322
  interface TUseResponseOptions {
@@ -382,7 +401,11 @@ declare class HttpErrorRenderer extends BaseHttpResponseRenderer<TWooksErrorBody
382
401
  }
383
402
 
384
403
  declare function createHttpContext(data: THttpEventData, options: TEventOptions): <T>(cb: (...a: any[]) => T) => T;
385
- declare function useHttpContext<T extends TEmpty>(): _wooksjs_event_core.TCtxHelpers<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>;
404
+ /**
405
+ * Wrapper on useEventContext with HTTP event types
406
+ * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
407
+ */
408
+ declare function useHttpContext<T extends TEmpty>(): TCtxHelpers<THttpContextStore & T & TGenericContextStore<THttpEventData>>;
386
409
 
387
410
  declare function createWooksResponder(renderer?: TWooksResponseRenderer<any>, errorRenderer?: TWooksResponseRenderer<any>): {
388
411
  createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
@@ -408,6 +431,11 @@ declare class WooksHttp extends WooksAdapterBase {
408
431
  head<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
409
432
  options<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
410
433
  protected server?: Server;
434
+ /**
435
+ * Starts the http(s) server.
436
+ *
437
+ * Use this only if you rely on Wooks server.
438
+ */
411
439
  listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): Promise<void>;
412
440
  listen(port?: number, hostname?: string, listeningListener?: () => void): Promise<void>;
413
441
  listen(port?: number, backlog?: number, listeningListener?: () => void): Promise<void>;
@@ -417,17 +445,52 @@ declare class WooksHttp extends WooksAdapterBase {
417
445
  listen(options: ListenOptions, listeningListener?: () => void): Promise<void>;
418
446
  listen(handle: any, backlog?: number, listeningListener?: () => void): Promise<void>;
419
447
  listen(handle: any, listeningListener?: () => void): Promise<void>;
448
+ /**
449
+ * Stops the server if it was attached or passed via argument
450
+ * @param server
451
+ */
420
452
  close(server?: Server): Promise<unknown>;
453
+ /**
454
+ * Returns http(s) server that was attached to Wooks
455
+ *
456
+ * See attachServer method docs
457
+ * @returns Server
458
+ */
421
459
  getServer(): Server<typeof IncomingMessage, typeof ServerResponse> | undefined;
460
+ /**
461
+ * Attaches http(s) server instance
462
+ * to Wooks.
463
+ *
464
+ * Use it only if you want to `close` method to stop the server.
465
+ * @param server Server
466
+ */
422
467
  attachServer(server?: Server): void;
423
468
  protected responder: {
424
469
  createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
425
470
  respond: (data: unknown) => Promise<unknown> | undefined;
426
471
  };
427
472
  protected respond(data: unknown): void;
473
+ /**
474
+ * Returns server callback function
475
+ * that can be passed to any node server:
476
+ * ```js
477
+ * import { createHttpApp } from '@wooksjs/event-http'
478
+ * import http from 'http'
479
+ *
480
+ * const app = createHttpApp()
481
+ * const server = http.createServer(app.getServerCb())
482
+ * server.listen(3000)
483
+ * ```
484
+ */
428
485
  getServerCb(): (req: IncomingMessage, res: ServerResponse) => void;
429
486
  protected processHandlers(handlers: TWooksHandler[]): Promise<unknown>;
430
487
  }
488
+ /**
489
+ * Factory for WooksHttp App
490
+ * @param opts TWooksHttpOptions
491
+ * @param wooks Wooks | WooksAdapterBase
492
+ * @returns WooksHttp
493
+ */
431
494
  declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
432
495
 
433
- 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 };
496
+ export { BaseHttpResponse, BaseHttpResponseRenderer, DEFAULT_LIMITS, 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 };