@wooksjs/event-http 0.7.25 → 0.7.26

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 CHANGED
@@ -428,7 +428,7 @@ const isCompressedSlot = (0, _wooksjs_event_core.cached)((ctx) => {
428
428
  ].includes(p)) return true;
429
429
  return false;
430
430
  });
431
- /** @internal Exported for test pre-seeding via `ctx.set(rawBodySlot, ...)`. */
431
+ /** @internal Exported for test pre-seeding — use {@link seedRawBody} instead. */
432
432
  const rawBodySlot = (0, _wooksjs_event_core.cached)(async (ctx) => {
433
433
  const req = ctx.get(httpKind.keys.req);
434
434
  const encs = ctx.get(contentEncodingsSlot);
@@ -568,6 +568,29 @@ const useRequest = (0, _wooksjs_event_core.defineWook)((ctx) => {
568
568
  setMaxRatio
569
569
  };
570
570
  });
571
+ /**
572
+ * Seeds the raw request body of `ctx`: `useRequest(ctx).rawBody()` resolves to `raw` instead of
573
+ * reading the incoming request stream. To seed what `useBody()` (`@wooksjs/http-body`) parses,
574
+ * use its `seedBody()` — a parent's already parsed body is otherwise read through.
575
+ *
576
+ * Use it for a child event context (`new EventContext({ logger, parent })`) that runs a handler
577
+ * with its own payload: the child still reads everything else (request, headers, auth) through
578
+ * its parent, but never the parent's body. Call it before anything in the child reads the body.
579
+ *
580
+ * @param ctx - The context to seed — usually a child of the current HTTP event
581
+ * @param raw - The body bytes (a string is encoded as UTF-8)
582
+ *
583
+ * @example
584
+ * ```ts
585
+ * const child = new EventContext({ logger: parent.logger, parent })
586
+ * seedRawBody(child, JSON.stringify({ ids: [1, 2] }))
587
+ * await run(child, () => useRequest().rawBody()) // Buffer of '{"ids":[1,2]}'
588
+ * ```
589
+ */
590
+ function seedRawBody(ctx, raw) {
591
+ ctx.setOwn(rawBodySlot, Promise.resolve(buffer.Buffer.isBuffer(raw) ? raw : buffer.Buffer.from(raw)));
592
+ if (ctx.parent) ctx.getOwn(useRequest._slot);
593
+ }
571
594
 
572
595
  //#endregion
573
596
  //#region packages/event-http/src/composables/headers.ts
@@ -1474,7 +1497,7 @@ function escapeHtml(value) {
1474
1497
  //#endregion
1475
1498
  //#region packages/event-http/src/response/wooks-http-response.ts
1476
1499
  let framework = {
1477
- version: "0.7.25",
1500
+ version: "0.7.26",
1478
1501
  poweredBy: "wooksjs",
1479
1502
  link: "https://wooks.moost.org/",
1480
1503
  image: "https://wooks.moost.org/wooks-full-logo.svg"
@@ -1884,7 +1907,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
1884
1907
  requestLimits
1885
1908
  }, async () => {
1886
1909
  const ctx = (0, _wooksjs_event_core.current)();
1887
- if (bodyBuffer) ctx.set(rawBodySlot, Promise.resolve(bodyBuffer));
1910
+ if (bodyBuffer) seedRawBody(ctx, bodyBuffer);
1888
1911
  try {
1889
1912
  const handlers = this.wooks.lookupHandlers(method, pathname, ctx);
1890
1913
  if (handlers) {
@@ -2088,10 +2111,7 @@ function prepareTestHttpContext(options) {
2088
2111
  requestLimits: options.requestLimits
2089
2112
  });
2090
2113
  if (options.params) ctx.set(_wooksjs_event_core.routeParamsKey, options.params);
2091
- if (options.rawBody !== void 0) {
2092
- const buf = buffer.Buffer.isBuffer(options.rawBody) ? options.rawBody : buffer.Buffer.from(options.rawBody);
2093
- ctx.set(rawBodySlot, Promise.resolve(buf));
2094
- }
2114
+ if (options.rawBody !== void 0) seedRawBody(ctx, options.rawBody);
2095
2115
  return (cb) => (0, _wooksjs_event_core.run)(ctx, cb);
2096
2116
  }
2097
2117
 
@@ -2113,6 +2133,7 @@ exports.rawBodySlot = rawBodySlot;
2113
2133
  exports.recordToWebHeaders = recordToWebHeaders;
2114
2134
  exports.renderCacheControl = renderCacheControl;
2115
2135
  exports.securityHeaders = securityHeaders;
2136
+ exports.seedRawBody = seedRawBody;
2116
2137
  exports.useAccept = useAccept;
2117
2138
  exports.useAuthorization = useAuthorization;
2118
2139
  exports.useCookies = useCookies;
package/dist/index.d.ts CHANGED
@@ -69,7 +69,7 @@ declare const DEFAULT_LIMITS: {
69
69
  readonly maxRatio: 100;
70
70
  readonly readTimeoutMs: 10000;
71
71
  };
72
- /** @internal Exported for test pre-seeding via `ctx.set(rawBodySlot, ...)`. */
72
+ /** @internal Exported for test pre-seeding — use {@link seedRawBody} instead. */
73
73
  declare const rawBodySlot: _wooksjs_event_core.Cached<Promise<Buffer<ArrayBufferLike>>>;
74
74
  /**
75
75
  * Provides access to the incoming HTTP request (method, url, headers, body, IP).
@@ -103,6 +103,26 @@ declare const useRequest: _wooksjs_event_core.WookComposable<{
103
103
  getMaxRatio: () => number;
104
104
  setMaxRatio: (limit: number) => void;
105
105
  }>;
106
+ /**
107
+ * Seeds the raw request body of `ctx`: `useRequest(ctx).rawBody()` resolves to `raw` instead of
108
+ * reading the incoming request stream. To seed what `useBody()` (`@wooksjs/http-body`) parses,
109
+ * use its `seedBody()` — a parent's already parsed body is otherwise read through.
110
+ *
111
+ * Use it for a child event context (`new EventContext({ logger, parent })`) that runs a handler
112
+ * with its own payload: the child still reads everything else (request, headers, auth) through
113
+ * its parent, but never the parent's body. Call it before anything in the child reads the body.
114
+ *
115
+ * @param ctx - The context to seed — usually a child of the current HTTP event
116
+ * @param raw - The body bytes (a string is encoded as UTF-8)
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const child = new EventContext({ logger: parent.logger, parent })
121
+ * seedRawBody(child, JSON.stringify({ ids: [1, 2] }))
122
+ * await run(child, () => useRequest().rawBody()) // Buffer of '{"ids":[1,2]}'
123
+ * ```
124
+ */
125
+ declare function seedRawBody(ctx: EventContext, raw: Buffer | string): void;
106
126
 
107
127
  /** Maps numeric HTTP status codes to their human-readable descriptions. */
108
128
  declare const httpStatusCodes: {
@@ -773,5 +793,5 @@ interface TTestHttpContext {
773
793
  */
774
794
  declare function prepareTestHttpContext(options: TTestHttpContext): <T>(cb: (...a: any[]) => T) => T;
775
795
 
776
- export { DEFAULT_FORWARD_HEADERS, DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, recordToWebHeaders, renderCacheControl, securityHeaders, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useUrlParams };
796
+ export { DEFAULT_FORWARD_HEADERS, DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, recordToWebHeaders, renderCacheControl, securityHeaders, seedRawBody, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useUrlParams };
777
797
  export type { KnownAcceptType, KnownAuthType, SecurityHeadersOptions, TCacheControl, TCookieAttributes, TCookieAttributesInput, THttpEventData, TRequestLimits, TSetCookieData, TTestHttpContext, TWooksErrorBody, TWooksErrorBodyExt, TWooksHttpOptions };
package/dist/index.mjs CHANGED
@@ -399,7 +399,7 @@ const isCompressedSlot = cached((ctx) => {
399
399
  ].includes(p)) return true;
400
400
  return false;
401
401
  });
402
- /** @internal Exported for test pre-seeding via `ctx.set(rawBodySlot, ...)`. */
402
+ /** @internal Exported for test pre-seeding — use {@link seedRawBody} instead. */
403
403
  const rawBodySlot = cached(async (ctx) => {
404
404
  const req = ctx.get(httpKind.keys.req);
405
405
  const encs = ctx.get(contentEncodingsSlot);
@@ -539,6 +539,29 @@ const useRequest = defineWook((ctx) => {
539
539
  setMaxRatio
540
540
  };
541
541
  });
542
+ /**
543
+ * Seeds the raw request body of `ctx`: `useRequest(ctx).rawBody()` resolves to `raw` instead of
544
+ * reading the incoming request stream. To seed what `useBody()` (`@wooksjs/http-body`) parses,
545
+ * use its `seedBody()` — a parent's already parsed body is otherwise read through.
546
+ *
547
+ * Use it for a child event context (`new EventContext({ logger, parent })`) that runs a handler
548
+ * with its own payload: the child still reads everything else (request, headers, auth) through
549
+ * its parent, but never the parent's body. Call it before anything in the child reads the body.
550
+ *
551
+ * @param ctx - The context to seed — usually a child of the current HTTP event
552
+ * @param raw - The body bytes (a string is encoded as UTF-8)
553
+ *
554
+ * @example
555
+ * ```ts
556
+ * const child = new EventContext({ logger: parent.logger, parent })
557
+ * seedRawBody(child, JSON.stringify({ ids: [1, 2] }))
558
+ * await run(child, () => useRequest().rawBody()) // Buffer of '{"ids":[1,2]}'
559
+ * ```
560
+ */
561
+ function seedRawBody(ctx, raw) {
562
+ ctx.setOwn(rawBodySlot, Promise.resolve(Buffer$1.isBuffer(raw) ? raw : Buffer$1.from(raw)));
563
+ if (ctx.parent) ctx.getOwn(useRequest._slot);
564
+ }
542
565
 
543
566
  //#endregion
544
567
  //#region packages/event-http/src/composables/headers.ts
@@ -1445,7 +1468,7 @@ function escapeHtml(value) {
1445
1468
  //#endregion
1446
1469
  //#region packages/event-http/src/response/wooks-http-response.ts
1447
1470
  let framework = {
1448
- version: "0.7.25",
1471
+ version: "0.7.26",
1449
1472
  poweredBy: "wooksjs",
1450
1473
  link: "https://wooks.moost.org/",
1451
1474
  image: "https://wooks.moost.org/wooks-full-logo.svg"
@@ -1855,7 +1878,7 @@ var WooksHttp = class extends WooksAdapterBase {
1855
1878
  requestLimits
1856
1879
  }, async () => {
1857
1880
  const ctx = current();
1858
- if (bodyBuffer) ctx.set(rawBodySlot, Promise.resolve(bodyBuffer));
1881
+ if (bodyBuffer) seedRawBody(ctx, bodyBuffer);
1859
1882
  try {
1860
1883
  const handlers = this.wooks.lookupHandlers(method, pathname, ctx);
1861
1884
  if (handlers) {
@@ -2059,12 +2082,9 @@ function prepareTestHttpContext(options) {
2059
2082
  requestLimits: options.requestLimits
2060
2083
  });
2061
2084
  if (options.params) ctx.set(routeParamsKey, options.params);
2062
- if (options.rawBody !== void 0) {
2063
- const buf = Buffer$1.isBuffer(options.rawBody) ? options.rawBody : Buffer$1.from(options.rawBody);
2064
- ctx.set(rawBodySlot, Promise.resolve(buf));
2065
- }
2085
+ if (options.rawBody !== void 0) seedRawBody(ctx, options.rawBody);
2066
2086
  return (cb) => run(ctx, cb);
2067
2087
  }
2068
2088
 
2069
2089
  //#endregion
2070
- export { DEFAULT_FORWARD_HEADERS, DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, recordToWebHeaders, renderCacheControl, securityHeaders, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useLogger, useRequest, useResponse, useRouteParams, useUrlParams };
2090
+ export { DEFAULT_FORWARD_HEADERS, DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, recordToWebHeaders, renderCacheControl, securityHeaders, seedRawBody, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useLogger, useRequest, useResponse, useRouteParams, useUrlParams };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-http",
3
- "version": "0.7.25",
3
+ "version": "0.7.26",
4
4
  "description": "@wooksjs/event-http",
5
5
  "keywords": [
6
6
  "api",
@@ -42,14 +42,14 @@
42
42
  "devDependencies": {
43
43
  "typescript": "^5.9.3",
44
44
  "vitest": "^3.2.7",
45
- "@wooksjs/event-core": "^0.7.25",
46
- "wooks": "^0.7.25"
45
+ "@wooksjs/event-core": "^0.7.26",
46
+ "wooks": "^0.7.26"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@prostojs/logger": "^0.4.3",
50
50
  "@prostojs/router": "^0.3.4",
51
- "@wooksjs/event-core": "^0.7.25",
52
- "wooks": "^0.7.25"
51
+ "@wooksjs/event-core": "^0.7.26",
52
+ "wooks": "^0.7.26"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "rolldown -c ../../rolldown.config.mjs"