@wooksjs/event-http 0.6.0 → 0.6.2

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
@@ -394,6 +394,30 @@ interface TWooksErrorBodyExt extends TWooksErrorBody {
394
394
  }
395
395
 
396
396
  declare class HttpErrorRenderer extends BaseHttpResponseRenderer<TWooksErrorBodyExt> {
397
+ protected opts?: {
398
+ version: string;
399
+ poweredBy: string;
400
+ link: string;
401
+ image: string;
402
+ } | undefined;
403
+ constructor(opts?: {
404
+ version: string;
405
+ poweredBy: string;
406
+ link: string;
407
+ image: string;
408
+ } | undefined);
409
+ protected icons: {
410
+ 401: string;
411
+ 403: string;
412
+ 404: string;
413
+ 500: string;
414
+ };
415
+ static registerFramework(opts: {
416
+ version: string;
417
+ poweredBy: string;
418
+ link: string;
419
+ image: string;
420
+ }): void;
397
421
  renderHtml(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
398
422
  renderText(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
399
423
  renderJson(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
@@ -401,6 +425,10 @@ declare class HttpErrorRenderer extends BaseHttpResponseRenderer<TWooksErrorBody
401
425
  }
402
426
 
403
427
  declare function createHttpContext(data: THttpEventData, options: TEventOptions): <T>(cb: (...a: any[]) => T) => T;
428
+ /**
429
+ * Wrapper on useEventContext with HTTP event types
430
+ * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
431
+ */
404
432
  declare function useHttpContext<T extends TEmpty>(): TCtxHelpers<THttpContextStore & T & TGenericContextStore<THttpEventData>>;
405
433
 
406
434
  declare function createWooksResponder(renderer?: TWooksResponseRenderer<any>, errorRenderer?: TWooksResponseRenderer<any>): {
@@ -427,6 +455,11 @@ declare class WooksHttp extends WooksAdapterBase {
427
455
  head<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
428
456
  options<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
429
457
  protected server?: Server;
458
+ /**
459
+ * Starts the http(s) server.
460
+ *
461
+ * Use this only if you rely on Wooks server.
462
+ */
430
463
  listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): Promise<void>;
431
464
  listen(port?: number, hostname?: string, listeningListener?: () => void): Promise<void>;
432
465
  listen(port?: number, backlog?: number, listeningListener?: () => void): Promise<void>;
@@ -436,17 +469,52 @@ declare class WooksHttp extends WooksAdapterBase {
436
469
  listen(options: ListenOptions, listeningListener?: () => void): Promise<void>;
437
470
  listen(handle: any, backlog?: number, listeningListener?: () => void): Promise<void>;
438
471
  listen(handle: any, listeningListener?: () => void): Promise<void>;
472
+ /**
473
+ * Stops the server if it was attached or passed via argument
474
+ * @param server
475
+ */
439
476
  close(server?: Server): Promise<unknown>;
477
+ /**
478
+ * Returns http(s) server that was attached to Wooks
479
+ *
480
+ * See attachServer method docs
481
+ * @returns Server
482
+ */
440
483
  getServer(): Server<typeof IncomingMessage, typeof ServerResponse> | undefined;
484
+ /**
485
+ * Attaches http(s) server instance
486
+ * to Wooks.
487
+ *
488
+ * Use it only if you want to `close` method to stop the server.
489
+ * @param server Server
490
+ */
441
491
  attachServer(server?: Server): void;
442
492
  protected responder: {
443
493
  createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
444
494
  respond: (data: unknown) => Promise<unknown> | undefined;
445
495
  };
446
496
  protected respond(data: unknown): void;
497
+ /**
498
+ * Returns server callback function
499
+ * that can be passed to any node server:
500
+ * ```js
501
+ * import { createHttpApp } from '@wooksjs/event-http'
502
+ * import http from 'http'
503
+ *
504
+ * const app = createHttpApp()
505
+ * const server = http.createServer(app.getServerCb())
506
+ * server.listen(3000)
507
+ * ```
508
+ */
447
509
  getServerCb(): (req: IncomingMessage, res: ServerResponse) => void;
448
510
  protected processHandlers(handlers: TWooksHandler[]): Promise<unknown>;
449
511
  }
512
+ /**
513
+ * Factory for WooksHttp App
514
+ * @param opts TWooksHttpOptions
515
+ * @param wooks Wooks | WooksAdapterBase
516
+ * @returns WooksHttp
517
+ */
450
518
  declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
451
519
 
452
520
  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 };