@wooksjs/event-http 0.7.2 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _wooksjs_event_core from '@wooksjs/event-core';
2
- import { EventContext as EventContext$1, Logger, EventContextOptions } from '@wooksjs/event-core';
2
+ import { EventContext, Logger, EventContextOptions, EventKindSeeds } from '@wooksjs/event-core';
3
3
  export { EventContext, EventContextOptions, useLogger, useRouteParams } from '@wooksjs/event-core';
4
4
  import * as http from 'http';
5
5
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse, Server } from 'http';
@@ -19,7 +19,7 @@ import { Duplex } from 'stream';
19
19
  * const sessionId = getCookie('session_id')
20
20
  * ```
21
21
  */
22
- declare const useCookies: (ctx?: EventContext$1) => {
22
+ declare const useCookies: (ctx?: EventContext) => {
23
23
  raw: string | undefined;
24
24
  getCookie: (name: string) => string | null;
25
25
  };
@@ -27,7 +27,7 @@ declare const useCookies: (ctx?: EventContext$1) => {
27
27
  /** Short names for common Accept MIME types. */
28
28
  type KnownAcceptType = 'json' | 'html' | 'xml' | 'text';
29
29
  /** Provides helpers to check the request's Accept header for supported MIME types. */
30
- declare const useAccept: (ctx?: EventContext$1) => {
30
+ declare const useAccept: (ctx?: EventContext) => {
31
31
  accept: string | undefined;
32
32
  has: (type: KnownAcceptType | (string & {})) => boolean;
33
33
  };
@@ -42,7 +42,7 @@ type KnownAuthType = 'basic' | 'bearer';
42
42
  * if (is('bearer')) { const token = credentials() }
43
43
  * ```
44
44
  */
45
- declare const useAuthorization: (ctx?: EventContext$1) => {
45
+ declare const useAuthorization: (ctx?: EventContext) => {
46
46
  authorization: string | undefined;
47
47
  type: () => string | null;
48
48
  credentials: () => string | null;
@@ -60,7 +60,7 @@ declare const useAuthorization: (ctx?: EventContext$1) => {
60
60
  * const { host, authorization } = useHeaders()
61
61
  * ```
62
62
  */
63
- declare function useHeaders(ctx?: EventContext$1): IncomingHttpHeaders;
63
+ declare function useHeaders(ctx?: EventContext): IncomingHttpHeaders;
64
64
 
65
65
  /** Default safety limits for request body reading (size, ratio, timeout). */
66
66
  declare const DEFAULT_LIMITS: {
@@ -79,7 +79,7 @@ declare const rawBodySlot: _wooksjs_event_core.Cached<Promise<Buffer$1<ArrayBuff
79
79
  * const body = await rawBody()
80
80
  * ```
81
81
  */
82
- declare const useRequest: (ctx?: EventContext$1) => {
82
+ declare const useRequest: (ctx?: EventContext) => {
83
83
  raw: http.IncomingMessage;
84
84
  url: string | undefined;
85
85
  method: string | undefined;
@@ -410,9 +410,9 @@ declare class HttpResponse {
410
410
  /** Whether the response has already been sent (or the underlying stream is no longer writable). */
411
411
  get responded(): boolean;
412
412
  protected renderBody(): string | Uint8Array;
413
- protected renderError(data: TWooksErrorBodyExt, _ctx: EventContext$1): void;
413
+ protected renderError(data: TWooksErrorBodyExt, _ctx: EventContext): void;
414
414
  /** Renders and sends an HTTP error response. Called automatically by the framework when a handler throws an `HttpError`. */
415
- sendError(error: HttpError, ctx: EventContext$1): void | Promise<void>;
415
+ sendError(error: HttpError, ctx: EventContext): void | Promise<void>;
416
416
  /**
417
417
  * Finalizes and sends the response.
418
418
  *
@@ -442,7 +442,7 @@ declare class HttpResponse {
442
442
  * response.setCookie('session', 'abc', { httpOnly: true })
443
443
  * ```
444
444
  */
445
- declare function useResponse(ctx?: EventContext$1): HttpResponse;
445
+ declare function useResponse(ctx?: EventContext): HttpResponse;
446
446
 
447
447
  /**
448
448
  * Extended `URLSearchParams` with safe JSON conversion.
@@ -463,14 +463,21 @@ declare class WooksURLSearchParams extends URLSearchParams {
463
463
  * const page = params().get('page')
464
464
  * ```
465
465
  */
466
- declare const useUrlParams: (ctx?: EventContext$1) => {
466
+ declare const useUrlParams: (ctx?: EventContext) => {
467
467
  raw: () => string;
468
468
  params: () => WooksURLSearchParams;
469
469
  toJson: () => unknown;
470
470
  };
471
471
 
472
- /** Creates an async event context for an incoming HTTP request/response pair. */
473
- declare function createHttpContext(data: THttpEventData, options: EventContextOptions, ResponseClass?: typeof HttpResponse): <R>(fn: () => R) => R;
472
+ /** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
473
+ declare const httpKind: _wooksjs_event_core.EventKind<{
474
+ req: _wooksjs_event_core.SlotMarker<IncomingMessage>;
475
+ response: _wooksjs_event_core.SlotMarker<HttpResponse | undefined>;
476
+ requestLimits: _wooksjs_event_core.SlotMarker<TRequestLimits | undefined>;
477
+ }>;
478
+
479
+ /** Creates an HTTP event context and runs `fn` inside it. */
480
+ declare function createHttpContext<R>(options: EventContextOptions, seeds: EventKindSeeds<typeof httpKind>, fn: () => R): R;
474
481
  /** Returns the current HTTP event context. */
475
482
  declare function useHttpContext(ctx?: EventContext): EventContext;
476
483
 
@@ -488,7 +495,7 @@ declare class WooksHttpResponse extends HttpResponse {
488
495
  link: string;
489
496
  image: string;
490
497
  }): void;
491
- protected renderError(data: TWooksErrorBodyExt, ctx: EventContext$1): void;
498
+ protected renderError(data: TWooksErrorBodyExt, ctx: EventContext): void;
492
499
  }
493
500
 
494
501
  /** Configuration options for the WooksHttp adapter. */
@@ -566,7 +573,7 @@ declare class WooksHttp extends WooksAdapterBase {
566
573
  * @param server Server
567
574
  */
568
575
  attachServer(server?: Server): void;
569
- protected respond(data: unknown, response: HttpResponse, ctx: EventContext$1): void | Promise<void>;
576
+ protected respond(data: unknown, response: HttpResponse, ctx: EventContext): void | Promise<void>;
570
577
  /**
571
578
  * Returns server callback function
572
579
  * that can be passed to any node server:
@@ -585,8 +592,8 @@ declare class WooksHttp extends WooksAdapterBase {
585
592
  * Creates an HTTP context, seeds it with upgrade data, and routes as method 'UPGRADE'.
586
593
  */
587
594
  getUpgradeCb(): (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
588
- protected processUpgradeHandlers(handlers: TWooksHandler[], ctx: EventContext$1, socket: Duplex): void | Promise<unknown>;
589
- protected processHandlers(handlers: TWooksHandler[], ctx: EventContext$1, response: HttpResponse): void | Promise<unknown>;
595
+ protected processUpgradeHandlers(handlers: TWooksHandler[], ctx: EventContext, socket: Duplex): void | Promise<unknown>;
596
+ protected processHandlers(handlers: TWooksHandler[], ctx: EventContext, response: HttpResponse): void | Promise<unknown>;
590
597
  private processAsyncResult;
591
598
  }
592
599
  /**
@@ -600,13 +607,6 @@ declare class WooksHttp extends WooksAdapterBase {
600
607
  */
601
608
  declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
602
609
 
603
- /** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
604
- declare const httpKind: _wooksjs_event_core.EventKind<{
605
- req: _wooksjs_event_core.SlotMarker<IncomingMessage>;
606
- response: _wooksjs_event_core.SlotMarker<HttpResponse>;
607
- requestLimits: _wooksjs_event_core.SlotMarker<TRequestLimits | undefined>;
608
- }>;
609
-
610
610
  /**
611
611
  * Configuration for `securityHeaders()`. Each option accepts a `string` (override value),
612
612
  * `false` (disable), or `undefined` (use default). `strictTransportSecurity` has no default (opt-in only).