@wooksjs/event-http 0.7.1 → 0.7.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.cjs +18 -21
- package/dist/index.d.ts +14 -14
- package/dist/index.mjs +19 -22
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1028,13 +1028,12 @@ var HttpResponse = class {
|
|
|
1028
1028
|
//#region packages/event-http/src/event-http.ts
|
|
1029
1029
|
/** Creates an async event context for an incoming HTTP request/response pair. */
|
|
1030
1030
|
function createHttpContext(data, options, ResponseClass = HttpResponse) {
|
|
1031
|
-
const
|
|
1032
|
-
|
|
1033
|
-
return (fn) => (0, __wooksjs_event_core.run)(ctx, () => ctx.seed(httpKind, {
|
|
1031
|
+
const response = new ResponseClass(data.res, data.req, options.logger);
|
|
1032
|
+
return (fn) => (0, __wooksjs_event_core.createEventContext)(options, httpKind, {
|
|
1034
1033
|
req: data.req,
|
|
1035
1034
|
response,
|
|
1036
1035
|
requestLimits: data.requestLimits
|
|
1037
|
-
}, fn)
|
|
1036
|
+
}, fn);
|
|
1038
1037
|
}
|
|
1039
1038
|
/** Returns the current HTTP event context. */
|
|
1040
1039
|
function useHttpContext(ctx) {
|
|
@@ -1394,10 +1393,10 @@ function error_tl_default(ctx) {
|
|
|
1394
1393
|
//#endregion
|
|
1395
1394
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1396
1395
|
let framework = {
|
|
1397
|
-
version: "0.7.
|
|
1396
|
+
version: "0.7.1",
|
|
1398
1397
|
poweredBy: "wooksjs",
|
|
1399
1398
|
link: "https://wooks.moost.org/",
|
|
1400
|
-
image: "https://wooks.moost.org/wooks-full-logo.
|
|
1399
|
+
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
|
1401
1400
|
};
|
|
1402
1401
|
const icons = {
|
|
1403
1402
|
401: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
|
|
@@ -1601,16 +1600,15 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1601
1600
|
const notFoundHandler = this.opts?.onNotFound;
|
|
1602
1601
|
const defaultHeaders = this.opts?.defaultHeaders;
|
|
1603
1602
|
return (req, res) => {
|
|
1604
|
-
const
|
|
1605
|
-
const response = new this.ResponseClass(res, req, ctx.logger, defaultHeaders);
|
|
1603
|
+
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders);
|
|
1606
1604
|
const method = req.method || "";
|
|
1607
1605
|
const url$1 = req.url || "";
|
|
1608
|
-
(0, __wooksjs_event_core.
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1606
|
+
(0, __wooksjs_event_core.createEventContext)(ctxOptions, httpKind, {
|
|
1607
|
+
req,
|
|
1608
|
+
response,
|
|
1609
|
+
requestLimits: RequestLimits
|
|
1610
|
+
}, () => {
|
|
1611
|
+
const ctx = (0, __wooksjs_event_core.current)();
|
|
1614
1612
|
const handlers = this.wooks.lookupHandlers(method, url$1, ctx);
|
|
1615
1613
|
if (handlers || notFoundHandler) {
|
|
1616
1614
|
const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
|
|
@@ -1639,14 +1637,13 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1639
1637
|
socket.destroy();
|
|
1640
1638
|
return;
|
|
1641
1639
|
}
|
|
1642
|
-
const ctx = new __wooksjs_event_core.EventContext(ctxOptions);
|
|
1643
1640
|
const url$1 = req.url || "";
|
|
1644
|
-
(0, __wooksjs_event_core.
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1641
|
+
(0, __wooksjs_event_core.createEventContext)(ctxOptions, httpKind, {
|
|
1642
|
+
req,
|
|
1643
|
+
response: void 0,
|
|
1644
|
+
requestLimits
|
|
1645
|
+
}, () => {
|
|
1646
|
+
const ctx = (0, __wooksjs_event_core.current)();
|
|
1650
1647
|
ctx.set(wsHandler.reqKey, req);
|
|
1651
1648
|
ctx.set(wsHandler.socketKey, socket);
|
|
1652
1649
|
ctx.set(wsHandler.headKey, head);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _wooksjs_event_core from '@wooksjs/event-core';
|
|
2
|
-
import { EventContext, Logger, EventContextOptions } from '@wooksjs/event-core';
|
|
2
|
+
import { EventContext as EventContext$1, Logger, EventContextOptions } 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) => {
|
|
22
|
+
declare const useCookies: (ctx?: EventContext$1) => {
|
|
23
23
|
raw: string | undefined;
|
|
24
24
|
getCookie: (name: string) => string | null;
|
|
25
25
|
};
|
|
@@ -27,7 +27,7 @@ declare const useCookies: (ctx?: EventContext) => {
|
|
|
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) => {
|
|
30
|
+
declare const useAccept: (ctx?: EventContext$1) => {
|
|
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) => {
|
|
45
|
+
declare const useAuthorization: (ctx?: EventContext$1) => {
|
|
46
46
|
authorization: string | undefined;
|
|
47
47
|
type: () => string | null;
|
|
48
48
|
credentials: () => string | null;
|
|
@@ -60,7 +60,7 @@ declare const useAuthorization: (ctx?: EventContext) => {
|
|
|
60
60
|
* const { host, authorization } = useHeaders()
|
|
61
61
|
* ```
|
|
62
62
|
*/
|
|
63
|
-
declare function useHeaders(ctx?: EventContext): IncomingHttpHeaders;
|
|
63
|
+
declare function useHeaders(ctx?: EventContext$1): 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) => {
|
|
82
|
+
declare const useRequest: (ctx?: EventContext$1) => {
|
|
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): void;
|
|
413
|
+
protected renderError(data: TWooksErrorBodyExt, _ctx: EventContext$1): 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): void | Promise<void>;
|
|
415
|
+
sendError(error: HttpError, ctx: EventContext$1): 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): HttpResponse;
|
|
445
|
+
declare function useResponse(ctx?: EventContext$1): HttpResponse;
|
|
446
446
|
|
|
447
447
|
/**
|
|
448
448
|
* Extended `URLSearchParams` with safe JSON conversion.
|
|
@@ -463,7 +463,7 @@ declare class WooksURLSearchParams extends URLSearchParams {
|
|
|
463
463
|
* const page = params().get('page')
|
|
464
464
|
* ```
|
|
465
465
|
*/
|
|
466
|
-
declare const useUrlParams: (ctx?: EventContext) => {
|
|
466
|
+
declare const useUrlParams: (ctx?: EventContext$1) => {
|
|
467
467
|
raw: () => string;
|
|
468
468
|
params: () => WooksURLSearchParams;
|
|
469
469
|
toJson: () => unknown;
|
|
@@ -488,7 +488,7 @@ declare class WooksHttpResponse extends HttpResponse {
|
|
|
488
488
|
link: string;
|
|
489
489
|
image: string;
|
|
490
490
|
}): void;
|
|
491
|
-
protected renderError(data: TWooksErrorBodyExt, ctx: EventContext): void;
|
|
491
|
+
protected renderError(data: TWooksErrorBodyExt, ctx: EventContext$1): void;
|
|
492
492
|
}
|
|
493
493
|
|
|
494
494
|
/** Configuration options for the WooksHttp adapter. */
|
|
@@ -566,7 +566,7 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
566
566
|
* @param server Server
|
|
567
567
|
*/
|
|
568
568
|
attachServer(server?: Server): void;
|
|
569
|
-
protected respond(data: unknown, response: HttpResponse, ctx: EventContext): void | Promise<void>;
|
|
569
|
+
protected respond(data: unknown, response: HttpResponse, ctx: EventContext$1): void | Promise<void>;
|
|
570
570
|
/**
|
|
571
571
|
* Returns server callback function
|
|
572
572
|
* that can be passed to any node server:
|
|
@@ -585,8 +585,8 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
585
585
|
* Creates an HTTP context, seeds it with upgrade data, and routes as method 'UPGRADE'.
|
|
586
586
|
*/
|
|
587
587
|
getUpgradeCb(): (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
|
|
588
|
-
protected processUpgradeHandlers(handlers: TWooksHandler[], ctx: EventContext, socket: Duplex): void | Promise<unknown>;
|
|
589
|
-
protected processHandlers(handlers: TWooksHandler[], ctx: EventContext, response: HttpResponse): void | Promise<unknown>;
|
|
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>;
|
|
590
590
|
private processAsyncResult;
|
|
591
591
|
}
|
|
592
592
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventContext, cached, cachedBy, current, defineEventKind, defineWook, routeParamsKey, run, slot, useEventId, useLogger, useRouteParams } from "@wooksjs/event-core";
|
|
1
|
+
import { EventContext, cached, cachedBy, createEventContext, current, defineEventKind, defineWook, routeParamsKey, run, slot, useEventId, useLogger, useRouteParams } from "@wooksjs/event-core";
|
|
2
2
|
import { Buffer as Buffer$1 } from "buffer";
|
|
3
3
|
import { Readable, pipeline } from "node:stream";
|
|
4
4
|
import { promisify } from "node:util";
|
|
@@ -1005,13 +1005,12 @@ var HttpResponse = class {
|
|
|
1005
1005
|
//#region packages/event-http/src/event-http.ts
|
|
1006
1006
|
/** Creates an async event context for an incoming HTTP request/response pair. */
|
|
1007
1007
|
function createHttpContext(data, options, ResponseClass = HttpResponse) {
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
return (fn) => run(ctx, () => ctx.seed(httpKind, {
|
|
1008
|
+
const response = new ResponseClass(data.res, data.req, options.logger);
|
|
1009
|
+
return (fn) => createEventContext(options, httpKind, {
|
|
1011
1010
|
req: data.req,
|
|
1012
1011
|
response,
|
|
1013
1012
|
requestLimits: data.requestLimits
|
|
1014
|
-
}, fn)
|
|
1013
|
+
}, fn);
|
|
1015
1014
|
}
|
|
1016
1015
|
/** Returns the current HTTP event context. */
|
|
1017
1016
|
function useHttpContext(ctx) {
|
|
@@ -1371,10 +1370,10 @@ function error_tl_default(ctx) {
|
|
|
1371
1370
|
//#endregion
|
|
1372
1371
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1373
1372
|
let framework = {
|
|
1374
|
-
version: "0.7.
|
|
1373
|
+
version: "0.7.1",
|
|
1375
1374
|
poweredBy: "wooksjs",
|
|
1376
1375
|
link: "https://wooks.moost.org/",
|
|
1377
|
-
image: "https://wooks.moost.org/wooks-full-logo.
|
|
1376
|
+
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
|
1378
1377
|
};
|
|
1379
1378
|
const icons = {
|
|
1380
1379
|
401: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
|
|
@@ -1578,16 +1577,15 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1578
1577
|
const notFoundHandler = this.opts?.onNotFound;
|
|
1579
1578
|
const defaultHeaders = this.opts?.defaultHeaders;
|
|
1580
1579
|
return (req, res) => {
|
|
1581
|
-
const
|
|
1582
|
-
const response = new this.ResponseClass(res, req, ctx.logger, defaultHeaders);
|
|
1580
|
+
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders);
|
|
1583
1581
|
const method = req.method || "";
|
|
1584
1582
|
const url = req.url || "";
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1583
|
+
createEventContext(ctxOptions, httpKind, {
|
|
1584
|
+
req,
|
|
1585
|
+
response,
|
|
1586
|
+
requestLimits: RequestLimits
|
|
1587
|
+
}, () => {
|
|
1588
|
+
const ctx = current();
|
|
1591
1589
|
const handlers = this.wooks.lookupHandlers(method, url, ctx);
|
|
1592
1590
|
if (handlers || notFoundHandler) {
|
|
1593
1591
|
const result = this.processHandlers(handlers || [notFoundHandler], ctx, response);
|
|
@@ -1616,14 +1614,13 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1616
1614
|
socket.destroy();
|
|
1617
1615
|
return;
|
|
1618
1616
|
}
|
|
1619
|
-
const ctx = new EventContext(ctxOptions);
|
|
1620
1617
|
const url = req.url || "";
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1618
|
+
createEventContext(ctxOptions, httpKind, {
|
|
1619
|
+
req,
|
|
1620
|
+
response: void 0,
|
|
1621
|
+
requestLimits
|
|
1622
|
+
}, () => {
|
|
1623
|
+
const ctx = current();
|
|
1627
1624
|
ctx.set(wsHandler.reqKey, req);
|
|
1628
1625
|
ctx.set(wsHandler.socketKey, socket);
|
|
1629
1626
|
ctx.set(wsHandler.headKey, head);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "@wooksjs/event-http",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vitest": "^3.2.4",
|
|
50
|
-
"@wooksjs/event-core": "^0.7.
|
|
51
|
-
"wooks": "^0.7.
|
|
50
|
+
"@wooksjs/event-core": "^0.7.2",
|
|
51
|
+
"wooks": "^0.7.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@prostojs/logger": "^0.4.3",
|
|
55
55
|
"@prostojs/router": "^0.3.2",
|
|
56
|
-
"@wooksjs/event-core": "^0.7.
|
|
57
|
-
"wooks": "^0.7.
|
|
56
|
+
"@wooksjs/event-core": "^0.7.2",
|
|
57
|
+
"wooks": "^0.7.2"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "rolldown -c ../../rolldown.config.mjs",
|