@znight/http 0.1.1 → 0.1.3

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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +83 -32
  3. package/dist/{adapter-CGSceVEN.d.mts → adapter-J0UXFnNM.d.mts} +7 -1
  4. package/dist/compiler.d.mts +1 -1
  5. package/dist/compiler.mjs +82 -13
  6. package/dist/compiler.mjs.map +1 -1
  7. package/dist/express.d.mts +1 -1
  8. package/dist/express.mjs +3 -2
  9. package/dist/express.mjs.map +1 -1
  10. package/dist/fastify.d.mts +1 -1
  11. package/dist/fastify.mjs +254 -42
  12. package/dist/fastify.mjs.map +1 -1
  13. package/dist/hono.d.mts +1 -1
  14. package/dist/hono.mjs +272 -67
  15. package/dist/hono.mjs.map +1 -1
  16. package/dist/index.d.mts +10 -2
  17. package/dist/index.mjs +930 -278
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{node-BUnkdSsa.mjs → node-DnYv_AMI.mjs} +4 -3
  20. package/dist/{node-BUnkdSsa.mjs.map → node-DnYv_AMI.mjs.map} +1 -1
  21. package/dist/{node-io-BY1ZDLRQ.mjs → node-io-BkdRSQeg.mjs} +151 -86
  22. package/dist/{node-io-BY1ZDLRQ.mjs.map → node-io-BkdRSQeg.mjs.map} +1 -1
  23. package/dist/node.d.mts +1 -1
  24. package/dist/node.mjs +1 -1
  25. package/dist/utils-DIWdzVht.mjs +46 -0
  26. package/dist/utils-DIWdzVht.mjs.map +1 -0
  27. package/package.json +4 -4
  28. package/src/adapter.ts +6 -0
  29. package/src/adapters/express.ts +4 -1
  30. package/src/adapters/fastify.ts +329 -44
  31. package/src/adapters/hono.ts +341 -86
  32. package/src/adapters/node-io.ts +185 -82
  33. package/src/adapters/node.ts +4 -1
  34. package/src/body.ts +31 -2
  35. package/src/coerce.ts +31 -0
  36. package/src/compiler/generate.ts +127 -22
  37. package/src/context.ts +151 -78
  38. package/src/index.ts +1 -1
  39. package/src/pipeline.ts +809 -208
  40. package/src/plugin.ts +10 -4
  41. package/src/query.ts +7 -1
  42. package/src/response.ts +6 -8
  43. package/src/serialize.ts +83 -16
  44. package/src/utils.ts +25 -2
  45. package/src/validate.ts +28 -12
  46. package/dist/utils-DCbu3a4w.mjs +0 -27
  47. package/dist/utils-DCbu3a4w.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"node-io-BY1ZDLRQ.mjs","names":[],"sources":["../src/status.ts","../src/exceptions.ts","../src/stream.ts","../src/cookies.ts","../src/adapters/shared.ts","../src/adapters/node-io.ts"],"sourcesContent":["/** Standard reason phrases (RFC 9110 and common extensions), used in error bodies. */\nconst REASONS: Readonly<Record<number, string>> = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: \"I'm a Teapot\",\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 511: 'Network Authentication Required',\n}\n\n/** Reason phrase of `status` (`404` → `Not Found`), or a generic one for unknown codes. */\nexport function statusText(status: number): string {\n const reason = REASONS[status]\n if (reason !== undefined) return reason\n if (status >= 500) return 'Server Error'\n return status >= 400 ? 'Client Error' : 'Unknown Status'\n}\n\n/** Whether `status` is an integer in the 100–599 range. */\nexport function isValidStatus(status: unknown): status is number {\n return typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599\n}\n\n/** Statuses whose responses never have a body. */\nexport function isBodylessStatus(status: number): boolean {\n return status === 204 || status === 304 || (status >= 100 && status < 200)\n}\n","import type { StandardSchemaV1Issue } from './standard-schema.ts'\n\nimport { isValidStatus, statusText } from './status.ts'\n\n/** Response header values: a single value or several (`set-cookie`). */\nexport type HeaderValue = string | readonly string[]\n\n/** Options of {@link HttpException}. */\nexport interface HttpExceptionOptions extends ErrorOptions {\n /** Headers added to the error response (`www-authenticate`, `retry-after`, `allow`...). */\n readonly headers?: Readonly<Record<string, HeaderValue>>\n}\n\n/** JSON body of an error response. */\nexport interface HttpErrorBody {\n readonly statusCode: number\n /** Reason phrase of the status (`Not Found`). */\n readonly error: string\n readonly message: string\n /** Structured details (validation issues...), omitted when absent. */\n readonly details?: unknown\n}\n\n/** One entry of the `details` of a validation error. */\nexport interface ValidationIssueDetail {\n /** Dotted path of the invalid value inside the validated input (`user.email`, `items.0`), `''` for the root. */\n readonly path: string\n readonly message: string\n}\n\nconst NO_HEADERS: Readonly<Record<string, HeaderValue>> = Object.freeze({})\n\n/**\n * An error carrying an HTTP status. Thrown from handlers, guards, interceptors or services, it is\n * rendered as `{ statusCode, error, message, details? }` with its status and headers.\n *\n * ```ts\n * throw new HttpException(409, 'Email already used', { field: 'email' })\n * throw new NotFoundException(`User ${id} not found`)\n * throw new UnauthorizedException('Token expired', undefined, { headers: { 'www-authenticate': 'Bearer' } })\n * ```\n *\n * Invalid statuses (not an integer in 100–599) become `500`.\n */\nexport class HttpException extends Error {\n /** HTTP status of the response. */\n readonly status: number\n /** Structured details rendered in the body (omitted when `undefined`). */\n readonly details: unknown\n /** Headers added to the response. */\n readonly headers: Readonly<Record<string, HeaderValue>>\n\n constructor(status: number, message?: string, details?: unknown, options: HttpExceptionOptions = {}) {\n const code = isValidStatus(status) ? status : 500\n super(message ?? statusText(code), options.cause === undefined ? undefined : { cause: options.cause })\n this.name = 'HttpException'\n this.status = code\n this.details = details\n this.headers = options.headers ?? NO_HEADERS\n }\n\n /** The `statusCode` field of the body (alias of {@link status}). */\n get statusCode(): number {\n return this.status\n }\n\n /** Body of the error response. Override it in a subclass to change the shape. */\n toBody(): HttpErrorBody {\n const body: { statusCode: number; error: string; message: string; details?: unknown } = {\n statusCode: this.status,\n error: statusText(this.status),\n message: this.message,\n }\n if (this.details !== undefined) body.details = this.details\n return body\n }\n}\n\n/** Whether `value` is an {@link HttpException} (also across duplicated package copies). */\nexport function isHttpException(value: unknown): value is HttpException {\n return (\n value instanceof HttpException ||\n (value instanceof Error &&\n typeof (value as { status?: unknown }).status === 'number' &&\n typeof (value as { toBody?: unknown }).toBody === 'function')\n )\n}\n\n/** 400 Bad Request. */\nexport class BadRequestException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(400, message, details, options)\n this.name = 'BadRequestException'\n }\n}\n\n/**\n * 400 Bad Request raised when an input fails its schema (`@Body(schema)`, `@Query(schema)`...).\n * `details` lists the issues as `{ path, message }`; the raw Standard Schema issues are kept in\n * {@link issues} for exception mappers.\n */\nexport class ValidationException extends BadRequestException {\n /** What was validated: `body`, `query`, `query \"page\"`, `param \"id\"`... */\n readonly location: string\n readonly issues: readonly StandardSchemaV1Issue[]\n\n constructor(location: string, issues: readonly StandardSchemaV1Issue[], options?: HttpExceptionOptions) {\n super(`Invalid ${location}`, issues.map(toIssueDetail), options)\n this.name = 'ValidationException'\n this.location = location\n this.issues = issues\n }\n}\n\n/**\n * The `details` of a 400 raised by the framework for one invalid input (a multipart field...): the\n * shape of the issues of {@link ValidationException}, documented by `@znight/openapi`.\n */\nexport function issue(path: string, message: string): readonly ValidationIssueDetail[] {\n return [{ path, message }]\n}\n\n/** Converts a Standard Schema issue to `{ path, message }` (`path` dotted, `''` for the root). */\nexport function toIssueDetail(issue: StandardSchemaV1Issue): ValidationIssueDetail {\n return { path: formatIssuePath(issue.path), message: issue.message }\n}\n\nfunction formatIssuePath(path: StandardSchemaV1Issue['path']): string {\n if (path === undefined || path.length === 0) return ''\n let result = ''\n for (const segment of path) {\n const key = typeof segment === 'object' && segment !== null ? segment.key : segment\n const text = typeof key === 'symbol' ? (key.description ?? 'symbol') : String(key)\n result = result === '' ? text : `${result}.${text}`\n }\n return result\n}\n\n/** 401 Unauthorized. */\nexport class UnauthorizedException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(401, message, details, options)\n this.name = 'UnauthorizedException'\n }\n}\n\n/** 403 Forbidden (also the response of a guard returning `false`). */\nexport class ForbiddenException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(403, message, details, options)\n this.name = 'ForbiddenException'\n }\n}\n\n/** 404 Not Found. */\nexport class NotFoundException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(404, message, details, options)\n this.name = 'NotFoundException'\n }\n}\n\n/** 405 Method Not Allowed (pass the `allow` header in `options.headers`). */\nexport class MethodNotAllowedException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(405, message, details, options)\n this.name = 'MethodNotAllowedException'\n }\n}\n\n/** 409 Conflict. */\nexport class ConflictException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(409, message, details, options)\n this.name = 'ConflictException'\n }\n}\n\n/** 410 Gone. */\nexport class GoneException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(410, message, details, options)\n this.name = 'GoneException'\n }\n}\n\n/** 413 Payload Too Large (request body above `bodyLimit`). */\nexport class PayloadTooLargeException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(413, message, details, options)\n this.name = 'PayloadTooLargeException'\n }\n}\n\n/** 415 Unsupported Media Type. */\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(415, message, details, options)\n this.name = 'UnsupportedMediaTypeException'\n }\n}\n\n/** 422 Unprocessable Entity. */\nexport class UnprocessableEntityException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(422, message, details, options)\n this.name = 'UnprocessableEntityException'\n }\n}\n\n/** 429 Too Many Requests (pass `retry-after` in `options.headers`). */\nexport class TooManyRequestsException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(429, message, details, options)\n this.name = 'TooManyRequestsException'\n }\n}\n\n/** 500 Internal Server Error (its message is always sent, unlike unexpected errors). */\nexport class InternalServerErrorException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(500, message, details, options)\n this.name = 'InternalServerErrorException'\n }\n}\n\n/** 501 Not Implemented. */\nexport class NotImplementedException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(501, message, details, options)\n this.name = 'NotImplementedException'\n }\n}\n\n/** 502 Bad Gateway. */\nexport class BadGatewayException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(502, message, details, options)\n this.name = 'BadGatewayException'\n }\n}\n\n/** 503 Service Unavailable. */\nexport class ServiceUnavailableException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(503, message, details, options)\n this.name = 'ServiceUnavailableException'\n }\n}\n\n/** 504 Gateway Timeout. */\nexport class GatewayTimeoutException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(504, message, details, options)\n this.name = 'GatewayTimeoutException'\n }\n}\n","/**\n * Web stream helpers shared by the pipeline and the adapters (internal): conversion of handler\n * stream sources (`ReadableStream`, Node.js `Readable`, async iterables) to byte streams, tracking of\n * response streams (request scope lifetime) and small constructors.\n */\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\n/**\n * A stream source accepted by `HttpResponse.stream()`: a Web `ReadableStream`, a Node.js `Readable`\n * or any async iterable (async generator...) of `Uint8Array` / `string` chunks (strings are encoded\n * as UTF-8).\n */\nexport type StreamSource = ReadableStream<Uint8Array | string> | AsyncIterable<Uint8Array | string>\n\n/** Runs a function in a captured async context (`AsyncLocalStorage.snapshot()`). */\nexport type ContextRunner = <R>(fn: () => R) => R\n\nconst ENCODER = new TextEncoder()\n\n/** The current async context, to run stream reads in it later (the request scope of a response). */\nexport function captureContext(): ContextRunner {\n const snapshot = (AsyncLocalStorage as { snapshot?: () => ContextRunner }).snapshot\n return typeof snapshot === 'function' ? snapshot() : run => run()\n}\n\n/** Whether `value` is a stream source (Web stream, Node.js readable or async iterable). */\nexport function isStreamSource(value: unknown): value is StreamSource {\n return (\n value instanceof ReadableStream ||\n (value !== null &&\n typeof value === 'object' &&\n typeof (value as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === 'function')\n )\n}\n\n/** Byte streams created by {@link toByteStream} (already normalised: not wrapped again). */\nconst BYTE_STREAMS = new WeakSet<ReadableStream<Uint8Array>>()\n\n/** Whether `stream` was created by {@link toByteStream}. */\nexport function isByteStream(stream: ReadableStream<unknown>): boolean {\n return BYTE_STREAMS.has(stream as ReadableStream<Uint8Array>)\n}\n\n/**\n * Converts a stream source to a pull-based byte stream: the source is read only when the consumer\n * reads (backpressure), strings are encoded as UTF-8, `ArrayBuffer`s and views are converted, empty\n * chunks are skipped and cancelling the stream cancels the source (`iterator.return()`, which\n * destroys a Node.js `Readable`; a `Readable` that was never read is destroyed directly).\n *\n * @throws TypeError (as a stream error) for chunks that are neither bytes nor strings.\n */\nexport function toByteStream(source: StreamSource): ReadableStream<Uint8Array> {\n let iterator: AsyncIterator<unknown> | undefined\n let reader: ChunkReader | undefined\n const next = (): Promise<IteratorResult<unknown>> => {\n if (source instanceof ReadableStream) {\n const current: ChunkReader = reader ?? source.getReader()\n reader = current\n return current.read() as Promise<IteratorResult<unknown>>\n }\n iterator ??= source[Symbol.asyncIterator]()\n return iterator.next()\n }\n const stream = new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n for (;;) {\n const result = await next()\n if (result.done === true) {\n controller.close()\n return\n }\n const chunk = toChunk(result.value)\n if (chunk.byteLength > 0) {\n controller.enqueue(chunk)\n return\n }\n }\n },\n async cancel(reason) {\n if (reader !== undefined) await reader.cancel(reason)\n else if (source instanceof ReadableStream) await source.cancel(reason)\n else if (iterator === undefined) {\n // never read: an async generator has nothing to clean up, a Node.js `Readable` holds its resource\n const destroyable = source as { destroy?: unknown }\n if (typeof destroyable.destroy === 'function') destroyable.destroy()\n } else await iterator.return?.(reason)\n },\n },\n { highWaterMark: 0 },\n )\n BYTE_STREAMS.add(stream)\n return stream\n}\n\n/** The part of a stream reader used here (Node.js and Bun declare different reader types). */\ninterface ChunkReader {\n read(): Promise<{ readonly done?: boolean; readonly value?: unknown }>\n cancel(reason?: unknown): Promise<void>\n}\n\nfunction toChunk(value: unknown): Uint8Array {\n if (value instanceof Uint8Array) return value\n if (typeof value === 'string') return ENCODER.encode(value)\n if (value instanceof ArrayBuffer) return new Uint8Array(value)\n if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength)\n throw new TypeError(\n `Invalid stream chunk: expected a Uint8Array or a string, received ${value === null ? 'null' : typeof value}`,\n )\n}\n\n/** The part of a byte stream reader used by {@link trackStream}. */\ninterface ByteReader {\n read(): Promise<{ readonly done?: boolean; readonly value?: Uint8Array | undefined }>\n cancel(reason?: unknown): Promise<void>\n}\n\n/** A response stream whose completion is observed. */\nexport interface TrackedStream {\n readonly stream: ReadableStream<Uint8Array>\n /**\n * Resolves once the source was fully read (`undefined`), cancelled by the consumer (`undefined`:\n * client disconnected, HEAD...) or failed (the error). Never rejects.\n */\n readonly done: Promise<unknown>\n}\n\n/**\n * Wraps a response body so that the pipeline knows when it has been fully sent (or abandoned) and\n * reads the source in `run` (the async context of the request scope, so that stream producers can\n * use request-scoped providers). The wrapper is pull-based (no read-ahead): backpressure is the\n * consumer's. A `Blob` is read through `blob.stream()`, opened on the first read only. `onCancel`\n * runs when the consumer cancels the stream (the client left), before the source is cancelled.\n */\nexport function trackStream(\n body: ReadableStream<Uint8Array> | Blob,\n run: ContextRunner,\n onCancel?: () => void,\n): TrackedStream {\n let reader: ByteReader | undefined = body instanceof Blob ? undefined : body.getReader()\n let settle: (error: unknown) => void = () => undefined\n const done = new Promise<unknown>(resolve => {\n settle = resolve\n })\n let finished = false\n const finish = (error?: unknown): void => {\n if (finished) return\n finished = true\n settle(error)\n }\n const stream = new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n let result: Awaited<ReturnType<ByteReader['read']>>\n try {\n result = await run(() => {\n reader ??= (body as Blob).stream().getReader()\n return reader.read()\n })\n } catch (error) {\n finish(error)\n throw error\n }\n if (result.done === true) {\n controller.close()\n finish()\n return\n }\n controller.enqueue(result.value as Uint8Array)\n },\n async cancel(reason) {\n onCancel?.()\n try {\n const current = reader\n if (current !== undefined) await run(() => current.cancel(reason))\n } catch {\n // the source failed while being cancelled: nothing left to send anyway\n } finally {\n finish()\n }\n },\n },\n { highWaterMark: 0 },\n )\n return { stream, done }\n}\n\n/** A stream failing with `error` on first read. */\nexport function failedStream(error: unknown): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.error(error)\n },\n })\n}\n\n/** Cancels a stream, ignoring failures (unconsumed response bodies). */\nexport function discardStream(stream: ReadableStream<Uint8Array> | null | undefined): void {\n if (stream instanceof ReadableStream && !stream.locked) stream.cancel().catch(() => undefined)\n}\n","/**\n * Cookies (RFC 0006): parsing of the `cookie` request header, canonical value encoding, strict\n * `Set-Cookie` serialisation (RFC 6265bis: attribute validation, name prefixes, size limits),\n * `Set-Cookie` parsing (tests) and the response cookie jar.\n *\n * This module is import-free (pure functions): safe to import from anywhere, the compiler excepted\n * (it has its own token grammar).\n */\n\n/** Options of a cookie set on a response (`ctx.setCookie()`, `HttpResponse.withCookie()`). */\nexport interface CookieOptions {\n /** Lifetime in seconds (integer). `0` or less expires the cookie now. Default: session cookie. */\n readonly maxAge?: number\n /**\n * Absolute expiry (sent as an IMF-fixdate), in the years 1601 to 9999 (browsers ignore other\n * years). Browsers cap lifetimes at 400 days: prefer `maxAge` for long-lived cookies.\n */\n readonly expires?: Date\n /**\n * Domain (sub-domains included). Default: none, a host-only cookie. `null`: host-only even when\n * `cookies.defaults` sets a domain. `__Host-` cookies never take the default domain.\n */\n readonly domain?: string | null\n /** Default: `'/'`. */\n readonly path?: string\n /** Default: `true` (browsers only send it over HTTPS, `http://localhost` excepted). */\n readonly secure?: boolean\n /** Default: `true` (not readable from JavaScript). */\n readonly httpOnly?: boolean\n /** Default: `'lax'`. `'none'` requires `secure`. */\n readonly sameSite?: 'strict' | 'lax' | 'none'\n /** CHIPS partitioned cookie. Requires `secure`. Default: `false`. */\n readonly partitioned?: boolean\n /** Chromium `Priority`. Default: none. */\n readonly priority?: 'low' | 'medium' | 'high'\n /** Signs the value with the first secret of the plugin option `cookies.secrets`. Default: `false`. */\n readonly signed?: boolean\n}\n\n/** Plugin-wide defaults (`cookies.defaults`). Lifetime and signing are per cookie. */\nexport type CookieDefaults = Omit<CookieOptions, 'maxAge' | 'expires' | 'signed'>\n\n/** What identifies a cookie to clear (and keeps prefixed names valid). */\nexport type ClearCookieOptions = Pick<\n CookieOptions,\n 'domain' | 'path' | 'secure' | 'httpOnly' | 'sameSite' | 'partitioned'\n>\n\n/** A cookie to send, as given (defaults and signing are applied when the response is serialised). */\nexport interface ResponseCookie {\n readonly name: string\n /** `undefined`: a clearing cookie. */\n readonly value: string | undefined\n readonly options: CookieOptions\n}\n\n/** A parsed `Set-Cookie` line (see {@link parseSetCookie}). */\nexport interface SetCookieInfo {\n readonly name: string\n /** Decoded value (a signed cookie: `\"<value>.<signature>\"`, decoded). */\n readonly value: string\n /** The header line. */\n readonly raw: string\n readonly expires?: Date\n readonly maxAge?: number\n readonly domain?: string\n readonly path?: string\n readonly secure: boolean\n readonly httpOnly: boolean\n readonly sameSite?: 'strict' | 'lax' | 'none'\n readonly partitioned: boolean\n readonly priority?: 'low' | 'medium' | 'high'\n}\n\n/** The secure defaults: `Path=/; Secure; HttpOnly; SameSite=Lax`, host-only. */\nexport const DEFAULT_COOKIE_OPTIONS: Readonly<{\n path: string\n secure: boolean\n httpOnly: boolean\n sameSite: 'strict' | 'lax' | 'none'\n}> = Object.freeze({ path: '/', secure: true, httpOnly: true, sameSite: 'lax' })\n\n/** Largest `name=value` (bytes on the wire, after encoding and signing). */\nexport const MAX_COOKIE_SIZE = 4096\n/** Largest `Domain` / `Path` attribute value (bytes). */\nexport const MAX_COOKIE_ATTRIBUTE_SIZE = 1024\nconst MAX_DOMAIN_LENGTH = 253\nconst EPOCH = 'Thu, 01 Jan 1970 00:00:00 GMT'\n/** Years a cookie-date can carry (RFC 6265 §5.1.1; four digits in an IMF-fixdate). */\nconst MIN_EXPIRES_YEAR = 1601\nconst MAX_EXPIRES_YEAR = 9999\n\nconst OPTION_KEYS: ReadonlySet<string> = new Set([\n 'maxAge',\n 'expires',\n 'domain',\n 'path',\n 'secure',\n 'httpOnly',\n 'sameSite',\n 'partitioned',\n 'priority',\n 'signed',\n])\nconst SAME_SITE: Readonly<Record<string, string>> = { strict: 'Strict', lax: 'Lax', none: 'None' }\nconst PRIORITY: Readonly<Record<string, string>> = { low: 'Low', medium: 'Medium', high: 'High' }\n\n// -------------------------------------------------------------------------------------------------\n// Request cookies\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Parses a `cookie` request header into a prototype-less, frozen record (`__proto__` is just a\n * name). Pairs are split on `;` only (never `,`) and trimmed; a pair without `=` or with an empty\n * name is ignored; names are kept as sent (case-sensitive); a value wrapped in double quotes is\n * unquoted, and percent-decoded when it contains `%` (a malformed sequence keeps the raw value).\n * When a name repeats, the first occurrence wins (browsers send the most specific path first).\n * Linear time, never throws.\n */\nexport function parseCookieHeader(header: string | undefined): Readonly<Record<string, string>> {\n const result = Object.create(null) as Record<string, string>\n if (typeof header === 'string') {\n let start = 0\n const length = header.length\n // the next `=` at or after `start`, searched again only once passed: every character is scanned\n // at most twice, even for a header made of `;` without `=` (linear time)\n let equals = -1\n while (start < length) {\n let end = header.indexOf(';', start)\n if (end === -1) end = length\n if (equals < start) {\n equals = header.indexOf('=', start)\n if (equals === -1) equals = length\n }\n if (equals < end) {\n const name = trim(header, start, equals)\n if (name !== '' && !Object.hasOwn(result, name)) {\n result[name] = decodeCookieValue(unquote(trim(header, equals + 1, end)))\n }\n }\n start = end + 1\n }\n }\n return Object.freeze(result)\n}\n\n/** `text.slice(start, end)` without leading and trailing SP / HTAB. */\nfunction trim(text: string, start: number, end: number): string {\n let from = start\n let to = end\n while (from < to && isBlank(text.charCodeAt(from))) from++\n while (to > from && isBlank(text.charCodeAt(to - 1))) to--\n return text.slice(from, to)\n}\n\nfunction isBlank(code: number): boolean {\n return code === 0x20 || code === 0x09\n}\n\nfunction unquote(value: string): string {\n return value.length >= 2 && value.charCodeAt(0) === 0x22 && value.charCodeAt(value.length - 1) === 0x22\n ? value.slice(1, -1)\n : value\n}\n\n/**\n * Decodes a cookie value produced by {@link encodeCookieValue} (`decodeURIComponent` when it\n * contains `%`; a malformed sequence keeps the raw value). Never throws.\n */\nexport function decodeCookieValue(value: string): string {\n if (!value.includes('%')) return value\n try {\n return decodeURIComponent(value)\n } catch {\n return value\n }\n}\n\n/**\n * Encodes a cookie value canonically: the UTF-8 bytes outside RFC 6265 `cookie-octet` (space, `\"`,\n * `,`, `;`, `\\`, controls, non-ASCII) and `%` are percent-encoded (upper-case hex), so that\n * {@link decodeCookieValue} restores the value exactly (`a b;c` → `a%20b%3Bc`), and\n * `encode(decode(w)) === w` for every encoded `w`. Quotes are never emitted.\n *\n * @throws TypeError for a non-string or a string with lone surrogates (they cannot round-trip).\n */\nexport function encodeCookieValue(value: string): string {\n if (typeof value !== 'string') {\n throw new TypeError(`A cookie value must be a string (received ${describe(value)})`)\n }\n if (!value.isWellFormed()) {\n throw new TypeError('A cookie value must be a well-formed string (it contains a lone surrogate)')\n }\n let encoded = ''\n let plain = 0\n for (let index = 0; index < value.length; index++) {\n const code = value.charCodeAt(index)\n if (isCookieOctet(code)) continue\n encoded += value.slice(plain, index)\n if (code < 0x80) {\n encoded += `%${HEX[code] as string}`\n plain = index + 1\n } else {\n // a whole code point (a surrogate pair is two UTF-16 units): `encodeURIComponent` gives its UTF-8 bytes\n const point = value.codePointAt(index) as number\n const width = point > 0xffff ? 2 : 1\n encoded += encodeURIComponent(value.slice(index, index + width))\n index += width - 1\n plain = index + 1\n }\n }\n return plain === 0 ? value : encoded + value.slice(plain)\n}\n\nconst HEX: readonly string[] = Array.from({ length: 128 }, (_, code) =>\n code.toString(16).toUpperCase().padStart(2, '0'),\n)\n\n/** RFC 6265 `cookie-octet`, `%` excluded (the escape character). */\nfunction isCookieOctet(code: number): boolean {\n return (\n code === 0x21 ||\n (code >= 0x23 && code <= 0x2b && code !== 0x25) ||\n (code >= 0x2d && code <= 0x3a) ||\n (code >= 0x3c && code <= 0x5b) ||\n (code >= 0x5d && code <= 0x7e)\n )\n}\n\n/** Whether `name` is an RFC 9110 token (a cookie name Znight can set). */\nexport function isCookieName(name: unknown): name is string {\n if (typeof name !== 'string' || name === '') return false\n for (let index = 0; index < name.length; index++) {\n if (!isTokenChar(name.charCodeAt(index))) return false\n }\n return true\n}\n\nfunction isTokenChar(code: number): boolean {\n // ! # $ % & ' * + - . ^ _ ` | ~ DIGIT ALPHA\n return (\n (code >= 0x30 && code <= 0x39) ||\n (code >= 0x41 && code <= 0x5a) ||\n (code >= 0x61 && code <= 0x7a) ||\n code === 0x21 ||\n (code >= 0x23 && code <= 0x27) ||\n code === 0x2a ||\n code === 0x2b ||\n code === 0x2d ||\n code === 0x2e ||\n code === 0x5e ||\n code === 0x5f ||\n code === 0x60 ||\n code === 0x7c ||\n code === 0x7e\n )\n}\n\n// -------------------------------------------------------------------------------------------------\n// Response cookies\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Checks what a cookie says about itself, without plugin defaults: the name, the value type, the\n * options (types, `maxAge`, `expires`, `domain`, `path`) and the size before signing. Run by\n * `HttpResponse.withCookie()` / `withoutCookie()` at call time; the rules depending on the defaults\n * (prefixes, `SameSite=None` and `partitioned` with `secure`), signing and the final size are checked\n * when the response is serialised.\n *\n * @throws TypeError / RangeError naming the cookie.\n */\nexport function checkCookie(name: string, value: string | undefined, options: CookieOptions | undefined): void {\n checkName(name)\n const checked = checkOptions(name, options)\n if (value !== undefined) {\n const encoded = encodeValue(name, value)\n checkSize(name, encoded)\n }\n if (typeof checked.domain === 'string') normalizeDomain(name, checked.domain)\n if (checked.path !== undefined) checkPath(name, checked.path)\n}\n\n/** A cookie resolved with the defaults: its `Set-Cookie` line and its jar key. */\nexport interface SerializedCookie {\n /** `name` + domain + path: a later cookie with the same key replaces an earlier one. */\n readonly key: string\n readonly line: string\n}\n\n/**\n * Serialises a response cookie with `defaults` (merged under the options): every rule of RFC 0006\n * §4.3 is checked. `sign` turns the encoded value into its signed wire form (`signed: true`).\n *\n * @throws TypeError / RangeError naming the cookie.\n */\nexport function serializeResponseCookie(\n cookie: ResponseCookie,\n defaults: CookieDefaults,\n sign?: (name: string, encoded: string) => string,\n): SerializedCookie {\n const { name, value } = cookie\n checkName(name)\n const options = checkOptions(name, cookie.options)\n checkOptions(name, defaults, true)\n const attributes = resolveAttributes(name, { ...applicableDefaults(name, defaults), ...definedOnly(options) })\n let wire: string\n let maxAge: number | undefined\n let expires: string | undefined\n if (value === undefined) {\n wire = ''\n maxAge = 0\n expires = EPOCH\n } else {\n wire = encodeValue(name, value)\n if (options.signed === true) {\n if (sign === undefined) throw new TypeError(`Cannot sign the cookie \"${name}\": no signing key`)\n wire = sign(name, wire)\n }\n if (options.maxAge !== undefined) maxAge = Math.max(options.maxAge, 0)\n if (options.expires !== undefined) expires = options.expires.toUTCString()\n }\n checkSize(name, wire)\n let line = `${name}=${wire}`\n if (maxAge !== undefined) line += `; Max-Age=${maxAge}`\n if (expires !== undefined) line += `; Expires=${expires}`\n if (attributes.domain !== undefined) line += `; Domain=${attributes.domain}`\n line += `; Path=${attributes.path}`\n if (attributes.secure) line += '; Secure'\n if (attributes.httpOnly) line += '; HttpOnly'\n if (attributes.sameSite !== undefined) line += `; SameSite=${SAME_SITE[attributes.sameSite] as string}`\n if (attributes.partitioned) line += '; Partitioned'\n if (attributes.priority !== undefined && value !== undefined) {\n line += `; Priority=${PRIORITY[attributes.priority] as string}`\n }\n return { key: cookieKey(name, attributes.domain, attributes.path), line }\n}\n\n/**\n * The `Set-Cookie` line of a cookie with the secure defaults\n * (`Path=/; Secure; HttpOnly; SameSite=Lax`, overridable per cookie), in the order\n * `name=value; Max-Age; Expires; Domain; Path; Secure; HttpOnly; SameSite; Partitioned; Priority`.\n * The value is percent-encoded (see {@link encodeCookieValue}). Signing (`signed: true`) needs the\n * secrets of the plugin: use `ctx.setCookie()` or `HttpPlugin.signCookie()`.\n *\n * ```ts\n * serializeCookie('theme', 'dark', { maxAge: 86_400, httpOnly: false })\n * // theme=dark; Max-Age=86400; Path=/; Secure; SameSite=Lax\n * ```\n *\n * @throws TypeError for an invalid name, value or attribute, a `SameSite=None` or partitioned cookie\n * without `Secure`, a broken `__Secure-` / `__Host-` / `__Http-` / `__Host-Http-` prefix rule.\n * @throws RangeError when `name=value` exceeds 4096 bytes, or `Domain` / `Path` 1024 bytes.\n */\nexport function serializeCookie(name: string, value: string, options: CookieOptions = {}): string {\n return serializeResponseCookie({ name, value, options }, DEFAULT_COOKIE_OPTIONS).line\n}\n\n/**\n * The `Set-Cookie` line clearing a cookie: `name=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT`\n * plus `Domain`, `Path`, `Secure`, `HttpOnly`, `SameSite` and `Partitioned` (secure defaults merged\n * with `options`), so that a prefixed cookie is cleared with valid attributes.\n */\nexport function serializeClearCookie(name: string, options: ClearCookieOptions = {}): string {\n return serializeResponseCookie({ name, value: undefined, options }, DEFAULT_COOKIE_OPTIONS).line\n}\n\n/** The jar key of a cookie (RFC 6265: a cookie is identified by its name, domain and path). */\nexport function cookieKey(name: string, domain: string | undefined, path: string): string {\n return `${name}\\u0000${domain ?? ''}\\u0000${path}`\n}\n\ninterface Attributes {\n readonly domain: string | undefined\n readonly path: string\n readonly secure: boolean\n readonly httpOnly: boolean\n readonly sameSite: 'strict' | 'lax' | 'none' | undefined\n readonly partitioned: boolean\n readonly priority: 'low' | 'medium' | 'high' | undefined\n}\n\n/**\n * The defaults a cookie takes: all of them, but a `__Host-` cookie (host-only, `Path=/` by\n * definition) never takes a default domain or path. Its own options are still checked.\n */\nfunction applicableDefaults(name: string, defaults: CookieDefaults): CookieDefaults {\n if (!name.toLowerCase().startsWith('__host-')) return defaults\n const { domain: _domain, path: _path, ...rest } = defaults\n return rest\n}\n\n/** Attributes after the defaults, checked against the cross-attribute and prefix rules. */\nfunction resolveAttributes(name: string, options: CookieOptions): Attributes {\n // `null`: host-only, whatever the defaults\n const domain = typeof options.domain === 'string' ? normalizeDomain(name, options.domain) : undefined\n const path = options.path ?? '/'\n checkPath(name, path)\n const attributes: Attributes = {\n domain,\n path,\n secure: options.secure === true,\n httpOnly: options.httpOnly === true,\n sameSite: options.sameSite,\n partitioned: options.partitioned === true,\n priority: options.priority,\n }\n if (attributes.sameSite === 'none' && !attributes.secure) {\n throw invalid(name, 'SameSite=None requires secure: true (browsers reject it otherwise)')\n }\n if (attributes.partitioned && !attributes.secure) {\n throw invalid(name, 'partitioned cookies require secure: true')\n }\n checkPrefix(name, attributes)\n return attributes\n}\n\n/** `__Secure-`, `__Host-`, `__Http-`, `__Host-Http-` (case-insensitive, like browsers). */\nfunction checkPrefix(name: string, attributes: Attributes): void {\n const lower = name.toLowerCase()\n const host = lower.startsWith('__host-')\n const http = lower.startsWith('__http-') || lower.startsWith('__host-http-')\n if (!host && !http && !lower.startsWith('__secure-')) return\n const prefix = prefixName(host, http)\n if (!attributes.secure) throw invalid(name, `the ${prefix} prefix requires secure: true`)\n if (http && !attributes.httpOnly) throw invalid(name, `the ${prefix} prefix requires httpOnly: true`)\n if (host) {\n if (attributes.domain !== undefined) throw invalid(name, `the ${prefix} prefix forbids a domain`)\n if (attributes.path !== '/') throw invalid(name, `the ${prefix} prefix requires path: '/'`)\n }\n}\n\nfunction checkName(name: string): void {\n if (!isCookieName(name)) {\n throw new TypeError(\n `Invalid cookie name ${describe(name)}: expected a token (letters, digits and ! # $ % & ' * + - . ^ _ \\` | ~)`,\n )\n }\n}\n\nfunction encodeValue(name: string, value: string): string {\n if (typeof value !== 'string') throw invalid(name, `the value must be a string (received ${describe(value)})`)\n if (!value.isWellFormed()) throw invalid(name, 'the value contains a lone surrogate')\n return encodeCookieValue(value)\n}\n\nfunction checkSize(name: string, wire: string): void {\n const size = byteLength(name) + 1 + wire.length // the wire value is ASCII\n if (size > MAX_COOKIE_SIZE) {\n throw new RangeError(\n `Invalid cookie \"${name}\": name=value is ${size} bytes on the wire, above the limit of ${MAX_COOKIE_SIZE} (browsers drop it)`,\n )\n }\n}\n\n/** Checks the type of every option (and rejects unknown keys); returns the options. */\nfunction checkOptions(name: string, options: CookieOptions | undefined, defaults = false): CookieOptions {\n if (options === undefined) return {}\n const what = defaults ? 'cookies.defaults' : 'options'\n if (options === null || typeof options !== 'object' || Array.isArray(options)) {\n throw invalid(name, `${what} must be an object (received ${describe(options)})`)\n }\n for (const key of Object.keys(options)) {\n if (!OPTION_KEYS.has(key)) throw invalid(name, `unknown option \"${key}\"`)\n }\n const { maxAge, expires, domain, path, secure, httpOnly, sameSite, partitioned, priority, signed } = options\n if (maxAge !== undefined && !(typeof maxAge === 'number' && Number.isSafeInteger(maxAge))) {\n throw invalid(name, `maxAge must be an integer number of seconds (received ${describe(maxAge)})`)\n }\n if (expires !== undefined && !(expires instanceof Date && !Number.isNaN(expires.getTime()))) {\n throw invalid(name, `expires must be a valid Date (received ${describe(expires)})`)\n }\n if (expires !== undefined) {\n const year = expires.getUTCFullYear()\n if (year < MIN_EXPIRES_YEAR || year > MAX_EXPIRES_YEAR) {\n throw invalid(\n name,\n `expires must be in the years ${MIN_EXPIRES_YEAR} to ${MAX_EXPIRES_YEAR} (received ${expires.toISOString()}): browsers ignore other dates; use maxAge for a long lifetime (browsers cap it at 400 days)`,\n )\n }\n }\n if (domain !== undefined && domain !== null && typeof domain !== 'string') {\n throw invalid(name, `domain must be a string or null (received ${describe(domain)})`)\n }\n if (path !== undefined && typeof path !== 'string') {\n throw invalid(name, `path must be a string (received ${describe(path)})`)\n }\n for (const [key, flag] of [\n ['secure', secure],\n ['httpOnly', httpOnly],\n ['partitioned', partitioned],\n ['signed', signed],\n ] as const) {\n if (flag !== undefined && typeof flag !== 'boolean') {\n throw invalid(name, `${key} must be a boolean (received ${describe(flag)})`)\n }\n }\n if (sameSite !== undefined && !Object.hasOwn(SAME_SITE, sameSite)) {\n throw invalid(name, `sameSite must be 'strict', 'lax' or 'none' (received ${describe(sameSite)})`)\n }\n if (priority !== undefined && !Object.hasOwn(PRIORITY, priority)) {\n throw invalid(name, `priority must be 'low', 'medium' or 'high' (received ${describe(priority)})`)\n }\n return options\n}\n\n/** Lower-cased, one leading `.` removed; an ASCII host name of at most 253 characters. */\nfunction normalizeDomain(name: string, domain: string): string {\n const normalized = (domain.startsWith('.') ? domain.slice(1) : domain).toLowerCase()\n if (normalized.length > MAX_COOKIE_ATTRIBUTE_SIZE) {\n throw new RangeError(`Invalid cookie \"${name}\": the domain exceeds ${MAX_COOKIE_ATTRIBUTE_SIZE} bytes`)\n }\n if (!isHostName(normalized)) {\n throw invalid(\n name,\n `invalid domain ${describe(domain)}: expected an ASCII host name (letters, digits, -, dot-separated labels; IDNs in punycode)`,\n )\n }\n return normalized\n}\n\nfunction isHostName(domain: string): boolean {\n if (domain === '' || domain.length > MAX_DOMAIN_LENGTH) return false\n let label = 0\n for (let index = 0; index < domain.length; index++) {\n const code = domain.charCodeAt(index)\n if (code === 0x2e) {\n if (label === 0) return false\n label = 0\n continue\n }\n const valid = (code >= 0x30 && code <= 0x39) || (code >= 0x61 && code <= 0x7a) || code === 0x2d\n if (!valid) return false\n label++\n }\n return label > 0\n}\n\n/** Starts with `/`, `%x20-7E` except `;`, at most 1024 bytes. */\nfunction checkPath(name: string, path: string): void {\n if (path.length > MAX_COOKIE_ATTRIBUTE_SIZE) {\n throw new RangeError(`Invalid cookie \"${name}\": the path exceeds ${MAX_COOKIE_ATTRIBUTE_SIZE} bytes`)\n }\n let valid = path.startsWith('/')\n for (let index = 0; valid && index < path.length; index++) {\n const code = path.charCodeAt(index)\n valid = code >= 0x20 && code <= 0x7e && code !== 0x3b\n }\n if (!valid) {\n throw invalid(name, `invalid path ${describe(path)}: expected \"/...\" made of visible ASCII characters without \";\"`)\n }\n}\n\n/** The options without `undefined` values (they would erase defaults when spread). */\nfunction definedOnly(options: CookieOptions): CookieOptions {\n const result: Record<string, unknown> = {}\n for (const key of Object.keys(options)) {\n const value = (options as Record<string, unknown>)[key]\n if (value !== undefined) result[key] = value\n }\n return result as CookieOptions\n}\n\n// -------------------------------------------------------------------------------------------------\n// Set-Cookie parsing\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Parses a `Set-Cookie` line (attribute names are case-insensitive; the value is decoded like a\n * request cookie). Used by `inject()` to fill `response.cookies`.\n *\n * @throws TypeError when the line has no `name=value` pair.\n */\nexport function parseSetCookie(line: string): SetCookieInfo {\n const parts = String(line).split(';')\n const pair = parts[0] as string\n const equals = pair.indexOf('=')\n const name = equals === -1 ? '' : trim(pair, 0, equals)\n if (name === '') throw new TypeError(`Invalid Set-Cookie line ${describe(line)}: missing name=value`)\n const info: {\n -readonly [K in keyof SetCookieInfo]: SetCookieInfo[K]\n } = {\n name,\n value: decodeCookieValue(unquote(trim(pair, equals + 1, pair.length))),\n raw: line,\n secure: false,\n httpOnly: false,\n partitioned: false,\n }\n for (const part of parts.slice(1)) {\n const separator = part.indexOf('=')\n const key = trim(part, 0, separator === -1 ? part.length : separator).toLowerCase()\n const value = separator === -1 ? '' : trim(part, separator + 1, part.length)\n switch (key) {\n case 'max-age': {\n const seconds = /^-?\\d+$/.test(value) ? Number(value) : Number.NaN\n if (Number.isSafeInteger(seconds)) info.maxAge = seconds\n break\n }\n case 'expires': {\n const date = new Date(value)\n if (!Number.isNaN(date.getTime())) info.expires = date\n break\n }\n case 'domain':\n if (value !== '') info.domain = (value.startsWith('.') ? value.slice(1) : value).toLowerCase()\n break\n case 'path':\n if (value.startsWith('/')) info.path = value\n break\n case 'secure':\n info.secure = true\n break\n case 'httponly':\n info.httpOnly = true\n break\n case 'partitioned':\n info.partitioned = true\n break\n case 'samesite': {\n const sameSite = value.toLowerCase()\n if (sameSite === 'strict' || sameSite === 'lax' || sameSite === 'none') info.sameSite = sameSite\n break\n }\n case 'priority': {\n const priority = value.toLowerCase()\n if (priority === 'low' || priority === 'medium' || priority === 'high') info.priority = priority\n break\n }\n default:\n break\n }\n }\n return Object.freeze(info)\n}\n\n/** The `set-cookie` lines of a response parsed by name (the last one wins), prototype-less and frozen. */\nexport function parseSetCookies(\n lines: readonly string[] | string | undefined,\n): Readonly<Record<string, SetCookieInfo>> {\n const result = Object.create(null) as Record<string, SetCookieInfo>\n const list = typeof lines === 'string' ? [lines] : (lines ?? [])\n for (const line of list) {\n try {\n const info = parseSetCookie(line)\n result[info.name] = info\n } catch {\n // not a cookie line: ignored\n }\n }\n return Object.freeze(result)\n}\n\n// -------------------------------------------------------------------------------------------------\n// Jar\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Cookies of a response in insertion order, keyed by name, domain and path: a later cookie with\n * the same key replaces the earlier one in place (set then clear gives one clearing cookie).\n */\nexport class CookieJar<T> {\n readonly #entries = new Map<string, T>()\n\n /** Adds or replaces (in place) the entry of `key`. */\n set(key: string, entry: T): void {\n this.#entries.set(key, entry)\n }\n\n get size(): number {\n return this.#entries.size\n }\n\n values(): T[] {\n return [...this.#entries.values()]\n }\n\n entries(): [string, T][] {\n return [...this.#entries.entries()]\n }\n}\n\n/**\n * The jar key of a cookie as given (`HttpResponse.withCookie()`, before the defaults are known):\n * an absent domain or path is keyed as \"default\", a `null` domain as host-only.\n */\nexport function givenCookieKey(name: string, options: CookieOptions): string {\n const given = options.domain\n let domain: string\n if (given === undefined) domain = '\\u0001'\n else if (given === null) domain = ''\n else domain = (given.startsWith('.') ? given.slice(1) : given).toLowerCase()\n return `${name}\\u0000${domain}\\u0000${options.path ?? '\\u0001'}`\n}\n\n// -------------------------------------------------------------------------------------------------\n// Helpers\n// -------------------------------------------------------------------------------------------------\n\nfunction prefixName(host: boolean, http: boolean): string {\n if (host) return http ? '__Host-Http-' : '__Host-'\n return http ? '__Http-' : '__Secure-'\n}\n\nfunction invalid(name: string, reason: string): TypeError {\n return new TypeError(`Invalid cookie \"${name}\": ${reason}`)\n}\n\nfunction byteLength(text: string): number {\n let size = 0\n for (let index = 0; index < text.length; index++) {\n const code = text.charCodeAt(index)\n if (code < 0x80) size += 1\n else if (code < 0x800 || (code >= 0xd800 && code <= 0xdfff))\n size += 2 // a surrogate pair: 4 bytes\n else size += 3\n }\n return size\n}\n\nfunction describe(value: unknown): string {\n if (typeof value === 'string') return JSON.stringify(value.length > 64 ? `${value.slice(0, 64)}…` : value)\n if (value instanceof Date) return 'an invalid Date'\n if (value === null) return 'null'\n if (typeof value === 'object') return 'an object'\n return typeof value === 'bigint' ? `${value}n` : String(value)\n}\n","/** Helpers shared by the adapters (internal). */\nimport type { Readable } from 'node:stream'\nimport type {\n HttpServerAddress,\n InjectRequest,\n InjectResponse,\n InjectStreamRequest,\n InjectStreamResponse,\n} from '../adapter.ts'\n\nimport { encodeCookieValue, parseSetCookies } from '../cookies.ts'\nimport { BadRequestException, PayloadTooLargeException } from '../exceptions.ts'\nimport { failedStream } from '../stream.ts'\n\n/** An inject request normalised for the underlying tools. */\nexport interface NormalizedInject {\n readonly method: string\n readonly url: string\n readonly headers: Record<string, string>\n readonly payload: string | Uint8Array | undefined\n}\n\n/**\n * Applies the defaults of {@link InjectRequest}: query merged in the URL, cookies appended to the\n * `cookie` header (encoded values joined with `; `), body encoding and content type (`FormData` →\n * `multipart/form-data`, `Blob` → its type).\n */\nexport async function normalizeInject(request: InjectRequest): Promise<NormalizedInject> {\n if (request === null || typeof request !== 'object') throw new TypeError('inject() expects a request object')\n if (typeof request.url !== 'string' || !request.url.startsWith('/')) {\n throw new TypeError(`inject() expects a url starting with \"/\" (received ${JSON.stringify(request.url)})`)\n }\n const method = (request.method ?? 'GET').toUpperCase()\n let url = request.url\n if (request.query !== undefined) {\n const search = new URLSearchParams()\n for (const [key, value] of Object.entries(request.query)) {\n if (typeof value === 'string') search.append(key, value)\n else for (const item of value) search.append(key, item)\n }\n const query = search.toString()\n if (query !== '') url += `${url.includes('?') ? '&' : '?'}${query}`\n }\n const headers: Record<string, string> = {}\n for (const [name, value] of Object.entries(request.headers ?? {})) headers[name.toLowerCase()] = value\n if (request.signedCookies !== undefined) {\n throw new TypeError('inject(): signedCookies are signed by HttpPlugin.inject() (adapters only accept cookies)')\n }\n const cookie = cookieHeader(request.cookies)\n if (cookie !== '') headers['cookie'] = headers['cookie'] === undefined ? cookie : `${headers['cookie']}; ${cookie}`\n const body = request.body\n let payload: string | Uint8Array | undefined\n if (body === undefined) {\n payload = undefined\n } else if (typeof body === 'string') {\n payload = body\n headers['content-type'] ??= 'text/plain; charset=utf-8'\n } else if (body instanceof Uint8Array || body instanceof ArrayBuffer) {\n payload = body instanceof Uint8Array ? body : new Uint8Array(body)\n headers['content-type'] ??= 'application/octet-stream'\n } else if (body instanceof FormData) {\n // the Fetch API encodes forms (the boundary of the generated content type must be used)\n const encoded = new Response(body)\n // read the generated content type (with its boundary) before consuming the body (Bun sets it lazily)\n const type = encoded.headers.get('content-type')\n payload = new Uint8Array(await encoded.arrayBuffer())\n headers['content-type'] = type ?? encoded.headers.get('content-type') ?? 'multipart/form-data'\n } else if (body instanceof Blob) {\n payload = new Uint8Array(await body.arrayBuffer())\n headers['content-type'] ??= body.type === '' ? 'application/octet-stream' : body.type\n } else {\n payload = JSON.stringify(body)\n headers['content-type'] ??= 'application/json'\n }\n return { method, url, headers, payload }\n}\n\n/** The `cookie` header of inject cookies: `name=encoded` pairs joined with `; `. */\nfunction cookieHeader(cookies: Readonly<Record<string, string>> | undefined): string {\n if (cookies === undefined) return ''\n if (cookies === null || typeof cookies !== 'object') throw new TypeError('inject(): cookies must be an object')\n const pairs: string[] = []\n for (const name of Object.keys(cookies)) {\n if (!isRequestCookieName(name)) {\n throw new TypeError(\n `inject(): invalid cookie name ${JSON.stringify(name)} (empty, or with \";\", \"=\", spaces or controls)`,\n )\n }\n const value = cookies[name]\n if (typeof value !== 'string') throw new TypeError(`inject(): the value of the cookie \"${name}\" must be a string`)\n pairs.push(`${name}=${encodeCookieValue(value)}`)\n }\n return pairs.join('; ')\n}\n\n/** A name a `cookie` header can carry: no `;`, `=`, whitespace or controls, Latin-1. */\nfunction isRequestCookieName(name: string): boolean {\n if (name === '') return false\n for (let index = 0; index < name.length; index++) {\n const code = name.charCodeAt(index)\n if (code <= 0x20 || code === 0x3b || code === 0x3d || code === 0x7f || code > 0xff) return false\n }\n return true\n}\n\nconst DECODER = new TextDecoder()\n\n/**\n * Normalises response headers: lower-case names, repeated values joined with `, `, except\n * `set-cookie` (one entry per cookie: an `Expires` attribute contains `, `).\n */\nexport function injectHeaders(\n headers: Readonly<Record<string, string | number | readonly string[] | undefined>>,\n): Record<string, string | string[]> {\n const normalized: Record<string, string | string[]> = {}\n for (const [name, value] of Object.entries(headers)) {\n if (value === undefined) continue\n const key = name.toLowerCase()\n if (key === 'set-cookie') normalized[key] = typeof value === 'object' ? [...value] : [String(value)]\n else normalized[key] = typeof value === 'object' ? value.join(', ') : String(value)\n }\n return normalized\n}\n\n/** Builds an {@link InjectResponse} (headers normalised by {@link injectHeaders}, cookies parsed). */\nexport function injectResponse(\n status: number,\n headers: Readonly<Record<string, string | number | readonly string[] | undefined>>,\n bytes: Uint8Array,\n): InjectResponse {\n const normalized = injectHeaders(headers)\n const body = DECODER.decode(bytes)\n return {\n status,\n headers: normalized,\n body,\n bytes,\n cookies: parseSetCookies(normalized['set-cookie']),\n json: <T = unknown>(): T => JSON.parse(body) as T,\n }\n}\n\n/** Whether a `content-type` is `text/event-stream`. */\nexport function isEventStreamType(contentType: string | readonly string[] | undefined): boolean {\n if (typeof contentType !== 'string') return false\n const semicolon = contentType.indexOf(';')\n return (semicolon === -1 ? contentType : contentType.slice(0, semicolon)).trim().toLowerCase() === 'text/event-stream'\n}\n\n/**\n * `inject()` on top of `injectStream()`: reads the body to its end, except for an event stream\n * (which would never end): its body is cancelled (the server sees a disconnect) and the call\n * rejects with a hint.\n */\nexport async function bufferInjectStream(\n injectStream: (request: InjectStreamRequest) => Promise<InjectStreamResponse>,\n request: InjectRequest,\n): Promise<InjectResponse> {\n const response = await injectStream(request)\n const method = (request.method ?? 'GET').toUpperCase()\n if (method !== 'HEAD' && isEventStreamType(response.headers['content-type'])) {\n await response.body.cancel().catch(() => undefined)\n throw new TypeError(\n `inject(): ${method} ${request.url} answered an event stream (text/event-stream): use injectSse() or injectStream()`,\n )\n }\n const reader = response.body.getReader()\n const chunks: Uint8Array[] = []\n let size = 0\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n size += value.byteLength\n chunks.push(value)\n }\n const bytes = concat(chunks, size)\n const body = DECODER.decode(bytes)\n return {\n status: response.status,\n headers: response.headers,\n body,\n bytes,\n cookies: response.cookies,\n json: <T = unknown>(): T => JSON.parse(body) as T,\n }\n}\n\n/** Builds an {@link InjectStreamResponse}. */\nexport function injectStreamResponse(\n status: number,\n headers: Readonly<Record<string, string | number | readonly string[] | undefined>>,\n body: ReadableStream<Uint8Array>,\n): InjectStreamResponse {\n const normalized = injectHeaders(headers)\n return { status, headers: normalized, cookies: parseSetCookies(normalized['set-cookie']), body }\n}\n\n/** Builds an {@link HttpServerAddress} from a bound address. */\nexport function serverAddress(address: string, port: number, family?: string | number): HttpServerAddress {\n const ipv6 = family === 'IPv6' || family === 6 || address.includes(':')\n let client = address\n if (address === '0.0.0.0') client = '127.0.0.1'\n else if (address === '::') client = '::1'\n const url = `http://${client.includes(':') ? `[${client}]` : client}:${port}`\n return Object.freeze({\n host: address,\n port,\n family: ipv6 ? 'IPv6' : 'IPv4',\n url,\n toString: () => url,\n })\n}\n\n/** The 413 error of a body above `limit` bytes. */\nexport function payloadTooLarge(limit: number): PayloadTooLargeException {\n return new PayloadTooLargeException(`Request body exceeds the limit of ${limit} bytes`, undefined, {\n headers: { connection: 'close' },\n })\n}\n\n/** Rejects early when `content-length` announces more than `limit` bytes. */\nexport function exceedsDeclaredLength(contentLength: string | undefined, limit: number): boolean {\n if (contentLength === undefined) return false\n const length = Number(contentLength)\n return Number.isFinite(length) && length > limit\n}\n\n/** Bytes read (and discarded) from an abandoned Web request body before it is cancelled. */\nconst MAX_DISCARD_BYTES = 64 * 1024 * 1024\n\n/**\n * The body of a Web request as a pull-based stream enforcing `limit` (see\n * `AdapterRequest.streamBody`). `body` is only read when needed (a Node.js-backed request body\n * starts buffering once accessed). On overflow or cancellation the rest of the body is read and\n * discarded in the background (up to 64 MiB, then cancelled), so the server can write the response\n * and keep the connection usable instead of resetting it.\n */\nexport function webBodyStream(\n body: () => ReadableStream<Uint8Array> | null,\n limit: number,\n contentLength: string | undefined,\n): ReadableStream<Uint8Array> {\n if (exceedsDeclaredLength(contentLength, limit)) return failedStream(payloadTooLarge(limit))\n const source = body()\n if (source === null) return new ReadableStream<Uint8Array>({ start: controller => controller.close() })\n const reader = source.getReader()\n let size = 0\n let abandoned = false\n const abandon = (): void => {\n if (abandoned) return\n abandoned = true\n discardReader(reader)\n }\n return new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n let result: Awaited<ReturnType<typeof reader.read>>\n try {\n result = await reader.read()\n } catch (error) {\n abandoned = true\n throw new BadRequestException('Failed to read the request body', undefined, { cause: error })\n }\n if (result.done) {\n abandoned = true\n controller.close()\n return\n }\n size += result.value.byteLength\n if (size > limit) {\n abandon()\n throw payloadTooLarge(limit)\n }\n controller.enqueue(result.value)\n },\n cancel: abandon,\n },\n { highWaterMark: 0 },\n )\n}\n\n/** The part of a stream reader used to discard a body. */\ninterface BodyReader {\n read(): Promise<{ readonly done: boolean; readonly value?: Uint8Array | undefined }>\n cancel(): Promise<void>\n}\n\n/** Reads and drops the rest of a request body in the background, cancelling it past 64 MiB. */\nfunction discardReader(reader: BodyReader): void {\n let discarded = 0\n const next = (): void => {\n reader.read().then(\n result => {\n if (result.done) return\n discarded += result.value?.byteLength ?? 0\n if (discarded > MAX_DISCARD_BYTES) reader.cancel().catch(() => undefined)\n else next()\n },\n () => undefined,\n )\n }\n next()\n}\n\n/** Reads a Web request body fully, enforcing `limit` (see {@link webBodyStream}). */\nexport async function readWebStream(\n body: () => ReadableStream<Uint8Array> | null,\n limit: number,\n contentLength: string | undefined,\n): Promise<Uint8Array> {\n const reader = webBodyStream(body, limit, contentLength).getReader()\n const chunks: Uint8Array[] = []\n let size = 0\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n size += value.byteLength\n chunks.push(value)\n }\n return concat(chunks, size)\n}\n\n/** Concatenates chunks (no copy for a single chunk). */\nexport function concat(chunks: readonly Uint8Array[], size: number): Uint8Array {\n if (chunks.length === 0) return new Uint8Array(0)\n if (chunks.length === 1) return chunks[0] as Uint8Array\n const result = new Uint8Array(size)\n let offset = 0\n for (const chunk of chunks) {\n result.set(chunk, offset)\n offset += chunk.byteLength\n }\n return result\n}\n\n/** The light-my-request response of a streaming inject (`payloadAsStream: true`). */\ninterface LightStreamResponse {\n readonly statusCode: number\n readonly headers: Record<string, string | number | string[] | undefined>\n stream(): Readable\n readonly raw: { readonly res: { destroy(error?: Error): void } }\n}\n\n/** Minimal typing of `light-my-request` (optional peer dependency). */\nexport interface LightMyRequest {\n inject(dispatch: (req: never, res: never) => void, options: LightInjectOptions): PromiseLike<LightStreamResponse>\n}\n\n/** Options of a streaming light-my-request inject (also `fastify.inject()`). */\nexport interface LightInjectOptions {\n method: string\n url: string\n headers: Record<string, string>\n payload?: string | Buffer\n remoteAddress?: string\n payloadAsStream: true\n}\n\nlet lightMyRequest: Promise<LightMyRequest> | undefined\n\n/** Loads `light-my-request`, with an actionable error when it is not installed. */\nexport function loadLightMyRequest(adapter: string): Promise<LightMyRequest> {\n lightMyRequest ??= import('light-my-request').then(\n module => {\n const loaded = module as unknown as { default?: LightMyRequest } & LightMyRequest\n return loaded.default ?? loaded\n },\n (error: unknown) => {\n lightMyRequest = undefined\n throw new Error(\n `inject() with the ${adapter} adapter requires the optional peer dependency \"light-my-request\" ` +\n '(bun add -d light-my-request / npm i -D light-my-request)',\n { cause: error },\n )\n },\n )\n return lightMyRequest\n}\n\n/**\n * The light-my-request options of a normalised inject request (streaming mode). The signal is\n * handled by {@link lightStreamResponse} (light-my-request would destroy its fake request with an\n * unhandled error); an already aborted signal rejects at once, like `fetch()`.\n */\nexport async function lightInjectOptions(request: InjectStreamRequest): Promise<LightInjectOptions> {\n request.signal?.throwIfAborted()\n const normalized = await normalizeInject(request)\n return {\n method: normalized.method,\n url: normalized.url,\n headers: normalized.headers,\n remoteAddress: '127.0.0.1',\n payloadAsStream: true,\n ...(normalized.payload === undefined ? {} : { payload: toBuffer(normalized.payload) }),\n }\n}\n\n/** Runs a request through a Node.js request listener with `light-my-request`, streaming the body. */\nexport async function injectNodeStream(\n adapter: string,\n dispatch: (req: never, res: never) => void,\n request: InjectStreamRequest,\n): Promise<InjectStreamResponse> {\n const options = await lightInjectOptions(request)\n const { inject } = await loadLightMyRequest(adapter)\n return lightStreamResponse(await inject(dispatch, options), request.signal)\n}\n\n/**\n * An {@link InjectStreamResponse} of a light-my-request streaming response. Cancelling the body\n * (or aborting `signal`) destroys the server response: the server sees a client disconnect.\n */\nexport function lightStreamResponse(response: LightStreamResponse, signal?: AbortSignal): InjectStreamResponse {\n const readable = response.stream()\n const disconnect = (): void => {\n response.raw.res.destroy()\n readable.destroy()\n }\n let finished = false\n const body = new ReadableStream<Uint8Array>(\n {\n start(controller) {\n readable.on('data', (chunk: Buffer) => {\n if (finished) return\n controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength))\n if ((controller.desiredSize ?? 0) <= 0) readable.pause()\n })\n readable.once('end', () => {\n if (finished) return\n finished = true\n controller.close()\n })\n readable.once('error', error => {\n if (finished) return\n finished = true\n controller.error(error)\n })\n },\n pull() {\n if (readable.isPaused()) readable.resume()\n },\n cancel() {\n finished = true\n disconnect()\n },\n },\n { highWaterMark: 0 },\n )\n if (signal !== undefined) {\n if (signal.aborted) disconnect()\n else signal.addEventListener('abort', disconnect, { once: true })\n }\n return injectStreamResponse(response.statusCode, response.headers, body)\n}\n\n/** A `Buffer` view of bytes (tools such as light-my-request JSON-encode other objects). */\nexport function toBuffer(payload: string | Uint8Array): string | Buffer {\n return typeof payload === 'string' ? payload : Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength)\n}\n\n/**\n * Runs a request through a Fetch handler (`(request: Request) => Promise<Response>`), streaming\n * the body. Cancelling the body (or aborting `signal`) aborts the request signal and cancels the\n * response body.\n */\nexport async function injectFetchStream(\n fetch: (request: Request) => Response | Promise<Response>,\n request: InjectStreamRequest,\n): Promise<InjectStreamResponse> {\n const signal = request.signal\n signal?.throwIfAborted()\n const normalized = await normalizeInject(request)\n const abort = new AbortController()\n signal?.addEventListener('abort', () => abort.abort(signal.reason), { once: true })\n const init: RequestInit = { method: normalized.method, headers: normalized.headers, signal: abort.signal }\n if (normalized.payload !== undefined && normalized.method !== 'GET' && normalized.method !== 'HEAD') {\n init.body = normalized.payload\n }\n const response = await fetch(new Request(`http://localhost${normalized.url}`, init))\n const headers: Record<string, string | readonly string[]> = {}\n for (const [name, value] of response.headers) if (name !== 'set-cookie') headers[name] = value\n const cookies = response.headers.getSetCookie()\n if (cookies.length > 0) headers['set-cookie'] = cookies\n const source = response.body\n const reader = source?.getReader()\n const body = new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n if (reader === undefined) {\n controller.close()\n return\n }\n const result = await reader.read()\n if (result.done) controller.close()\n else controller.enqueue(result.value)\n },\n async cancel(reason) {\n abort.abort(reason)\n await reader?.cancel(reason).catch(() => undefined)\n },\n },\n { highWaterMark: 0 },\n )\n abort.signal.addEventListener('abort', () => reader?.cancel(abort.signal.reason).catch(() => undefined), {\n once: true,\n })\n return injectStreamResponse(response.status, headers, body)\n}\n","/** Node.js `IncomingMessage` / `ServerResponse` helpers shared by the Node and Express adapters (internal). */\nimport type { IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders, Server, ServerResponse } from 'node:http'\nimport type { Socket } from 'node:net'\nimport type { AdapterReply, AdapterRequest } from '../adapter.ts'\nimport type { HeaderValue } from '../exceptions.ts'\n\nimport { Readable } from 'node:stream'\nimport { pipeline } from 'node:stream/promises'\n\nimport { BadRequestException } from '../exceptions.ts'\nimport { discardStream, failedStream } from '../stream.ts'\nimport { concat, exceedsDeclaredLength, payloadTooLarge } from './shared.ts'\n\n/** Bytes buffered by a request body stream before the request is paused. */\nconst BODY_HIGH_WATER_MARK = 64 * 1024\n\n/** Request headers with array values (only `set-cookie` in Node.js) joined with `, `. */\nexport function normalizeNodeHeaders(headers: IncomingHttpHeaders): Record<string, string | undefined> {\n for (const name in headers) {\n if (typeof headers[name] !== 'string') return copyHeaders(headers)\n }\n return headers as Record<string, string | undefined>\n}\n\nfunction copyHeaders(headers: IncomingHttpHeaders): Record<string, string | undefined> {\n const result: Record<string, string | undefined> = {}\n for (const name in headers) {\n const value = headers[name]\n result[name] = Array.isArray(value) ? value.join(', ') : value\n }\n return result\n}\n\n/**\n * Whether the body was already read by someone else: an Express body parser (`express.json()`...)\n * marks the request with `_body`; otherwise a declared body that already ended.\n */\nfunction consumedElsewhere(request: IncomingMessage): boolean {\n if ((request as { _body?: unknown })._body === true) return true\n if (!request.readableEnded) return false\n const length = request.headers['content-length']\n return request.headers['transfer-encoding'] !== undefined || (length !== undefined && length.trim() !== '0')\n}\n\n/** The error of a body consumed before Znight read it (an empty body would be silently wrong). */\nfunction consumedError(): Error {\n return new Error(\n 'The request body was already read by a middleware (an Express body parser such as express.json()?): ' +\n 'Znight reads the bodies of its routes itself, do not register body parsers for them',\n )\n}\n\n/** Reads a Node.js request body, enforcing `limit` (on `content-length`, then while streaming). */\nexport function readNodeBody(request: IncomingMessage, limit: number): Promise<Uint8Array> {\n if (exceedsDeclaredLength(request.headers['content-length'], limit)) {\n request.resume()\n return Promise.reject(payloadTooLarge(limit))\n }\n if (consumedElsewhere(request)) return Promise.reject(consumedError())\n if (request.readableEnded) return Promise.resolve(new Uint8Array(0))\n if (request.destroyed) return Promise.reject(new BadRequestException('The request was aborted'))\n return new Promise((resolve, reject) => {\n const chunks: Uint8Array[] = []\n let size = 0\n const cleanup = (): void => {\n request.off('data', onData)\n request.off('end', onEnd)\n request.off('error', onError)\n request.off('close', onClose)\n }\n const onData = (chunk: Uint8Array | string): void => {\n const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk\n size += bytes.byteLength\n if (size > limit) {\n cleanup()\n request.resume() // discard the rest; the 413 response closes the connection\n reject(payloadTooLarge(limit))\n return\n }\n chunks.push(bytes)\n }\n const onEnd = (): void => {\n cleanup()\n resolve(concat(chunks, size))\n }\n const onError = (error: Error): void => {\n cleanup()\n reject(new BadRequestException('Failed to read the request body', undefined, { cause: error }))\n }\n const onClose = (): void => {\n if (request.complete) return\n cleanup()\n reject(new BadRequestException('The request was aborted'))\n }\n request.on('data', onData)\n request.on('end', onEnd)\n request.on('error', onError)\n request.on('close', onClose)\n })\n}\n\n/**\n * A Node.js request body as a Web stream (see `AdapterRequest.streamBody`): the request is paused\n * while the consumer does not read (backpressure); past `limit` bytes the stream errors with 413 and\n * the rest of the body is discarded (`request.resume()`), like when the consumer cancels the stream,\n * so the response can still be written (it carries `connection: close`).\n */\nexport function nodeBodyStream(request: IncomingMessage, limit: number): ReadableStream<Uint8Array> {\n if (exceedsDeclaredLength(request.headers['content-length'], limit)) {\n request.resume()\n return failedStream(payloadTooLarge(limit))\n }\n if (consumedElsewhere(request)) return failedStream(consumedError())\n if (request.readableEnded) return new ReadableStream<Uint8Array>({ start: controller => controller.close() })\n if (request.destroyed) return failedStream(new BadRequestException('The request was aborted'))\n let size = 0\n let cleanup = (): void => undefined\n return new ReadableStream<Uint8Array>(\n {\n start(controller) {\n const onData = (chunk: Uint8Array | string): void => {\n const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk\n size += bytes.byteLength\n if (size > limit) {\n cleanup()\n request.resume() // discard the rest; the 413 response closes the connection\n controller.error(payloadTooLarge(limit))\n return\n }\n controller.enqueue(bytes)\n if ((controller.desiredSize ?? 0) <= 0) request.pause()\n }\n const onEnd = (): void => {\n cleanup()\n controller.close()\n }\n const onError = (error: Error): void => {\n cleanup()\n controller.error(new BadRequestException('Failed to read the request body', undefined, { cause: error }))\n }\n const onClose = (): void => {\n if (request.complete) return\n cleanup()\n controller.error(new BadRequestException('The request was aborted'))\n }\n cleanup = (): void => {\n request.off('data', onData)\n request.off('end', onEnd)\n request.off('error', onError)\n request.off('close', onClose)\n }\n request.on('data', onData)\n request.on('end', onEnd)\n request.on('error', onError)\n request.on('close', onClose)\n },\n pull() {\n if (request.isPaused()) request.resume()\n },\n cancel() {\n cleanup()\n request.resume() // discard the rest of the body\n },\n },\n { highWaterMark: BODY_HIGH_WATER_MARK, size: (chunk: Uint8Array | undefined) => chunk?.byteLength ?? 0 },\n )\n}\n\n/** Options of {@link nodeAdapterRequest}. */\nexport interface NodeRequestOptions {\n /** Request target (default: `request.url`). */\n readonly url?: string\n /** `@Req()` value (default: the `IncomingMessage`). */\n readonly raw?: unknown\n /** `@Res()` value (default: the `ServerResponse`). */\n readonly rawResponse?: unknown\n readonly ip?: string | undefined\n}\n\n/** Wraps a Node.js request/response pair as an {@link AdapterRequest}. */\nexport function nodeAdapterRequest(\n request: IncomingMessage,\n response: ServerResponse,\n options: NodeRequestOptions = {},\n): AdapterRequest {\n let body: Promise<Uint8Array> | undefined\n return {\n method: request.method ?? 'GET',\n url: options.url ?? request.url ?? '/',\n headers: normalizeNodeHeaders(request.headers),\n ip: options.ip ?? request.socket?.remoteAddress,\n remoteAddress: request.socket?.remoteAddress,\n encrypted: isEncrypted(request),\n raw: options.raw ?? request,\n rawResponse: options.rawResponse ?? response,\n readBody: (limit: number): Promise<Uint8Array> => {\n body ??= readNodeBody(request, limit)\n return body\n },\n streamBody: (limit: number): ReadableStream<Uint8Array> => nodeBodyStream(request, limit),\n rawStatus: (): number => response.statusCode,\n onAbort: (listener: () => void): void => onResponseAbort(response, listener),\n }\n}\n\n/**\n * Calls `listener` once when `response` closes before it was fully written (the client left): on\n * the next microtask when it is already destroyed, never after a complete response.\n */\nexport function onResponseAbort(response: ServerResponse, listener: () => void): void {\n if (response.writableFinished) return\n if (response.destroyed) {\n queueMicrotask(listener)\n return\n }\n response.once('close', () => {\n if (!response.writableFinished) listener()\n })\n}\n\n/** Whether the request came over TLS (`node:https`, `node:http2` secure servers). */\nexport function isEncrypted(request: IncomingMessage): boolean {\n return (request.socket as { readonly encrypted?: unknown } | undefined)?.encrypted === true\n}\n\n/**\n * Writes a reply to a `ServerResponse`. Resolves when the response is complete (streams included);\n * never rejects (a failing stream destroys the response).\n */\nexport async function writeNodeReply(response: ServerResponse, reply: AdapterReply): Promise<void> {\n if (reply.raw === true) {\n discardStream(reply.body instanceof ReadableStream ? reply.body : null)\n return\n }\n if (response.headersSent || response.destroyed) {\n discardStream(reply.body instanceof ReadableStream ? reply.body : null)\n if (!response.writableEnded && !response.destroyed) response.end()\n return\n }\n try {\n // one call (merged over headers set earlier with setHeader(), e.g. by Express middleware); the\n // cookies set earlier are kept before the reply's own (writeHead would replace them)\n const headers = withNativeCookies(response.getHeader('set-cookie'), reply.headers)\n response.writeHead(reply.status, headers as OutgoingHttpHeaders)\n } catch {\n // invalid header name or value set by user code\n discardStream(reply.body instanceof ReadableStream ? reply.body : null)\n if (!response.headersSent) {\n for (const name of response.getHeaderNames()) response.removeHeader(name)\n response.statusCode = 500\n response.setHeader('content-type', 'application/json; charset=utf-8')\n response.end('{\"statusCode\":500,\"error\":\"Internal Server Error\"}')\n }\n return\n }\n const body = reply.body\n if (body === null) {\n response.end()\n return\n }\n // an event stream may stay quiet longer than a socket timeout (`server.timeout`, Bun's emulation)\n if (reply.eventStream === true && (response as { isLightMyRequest?: boolean }).isLightMyRequest !== true) {\n response.setTimeout(0)\n }\n if (body instanceof Uint8Array) {\n response.end(body)\n return\n }\n const stream = body instanceof Blob ? body.stream() : body\n try {\n await pipeline(Readable.fromWeb(stream as import('node:stream/web').ReadableStream), response)\n } catch {\n if (!response.destroyed) response.destroy()\n }\n}\n\n/**\n * `headers` with the `set-cookie` lines already set on the native response (Express middleware\n * `res.cookie()`, Fastify hooks `reply.header('set-cookie', ...)`) before its own: `headers`\n * unchanged when either side has none.\n */\nexport function withNativeCookies(\n native: number | string | readonly string[] | undefined,\n headers: Readonly<Record<string, HeaderValue>>,\n): Readonly<Record<string, HeaderValue>> {\n const own = headers['set-cookie']\n if (own === undefined || native === undefined || typeof native === 'number') return headers\n const before = typeof native === 'string' ? [native] : native\n if (before.length === 0) return headers\n return { ...headers, 'set-cookie': [...before, ...(typeof own === 'string' ? [own] : own)] }\n}\n\n/** Last-resort 500 when a handler promise rejected (should not happen: the pipeline maps errors). */\nexport function writeNodeFailure(response: ServerResponse): void {\n if (response.headersSent) {\n if (!response.writableEnded) response.destroy()\n return\n }\n response.statusCode = 500\n response.setHeader('content-type', 'application/json; charset=utf-8')\n response.end('{\"statusCode\":500,\"error\":\"Internal Server Error\"}')\n}\n\n/**\n * Tracks the connections of a `node:http` server to close them on shutdown: idle keep-alive\n * connections first (graceful), every connection when forced. `server.closeIdleConnections()` /\n * `closeAllConnections()` are not reliable on every runtime (Bun), so sockets are tracked here.\n */\nexport class ConnectionTracker {\n /** Socket → number of requests in progress. */\n readonly #sockets = new Map<Socket, number>()\n #closing = false\n\n constructor(server: Server) {\n server.on('connection', (socket: Socket) => {\n this.#sockets.set(socket, 0)\n socket.once('close', () => this.#sockets.delete(socket))\n })\n server.on('request', (request: IncomingMessage, response: ServerResponse) => {\n const socket = request.socket\n if (!this.#sockets.has(socket)) return\n this.#sockets.set(socket, (this.#sockets.get(socket) ?? 0) + 1)\n response.once('close', () => {\n const active = this.#sockets.get(socket)\n if (active === undefined) return\n this.#sockets.set(socket, active - 1)\n if (active - 1 === 0 && this.#closing) socket.end()\n })\n })\n }\n\n /** Ends idle connections now and the others once their requests completed. */\n closeIdle(): void {\n this.#closing = true\n for (const [socket, active] of this.#sockets) if (active === 0) socket.end()\n }\n\n /** Destroys every connection. */\n destroyAll(): void {\n this.#closing = true\n for (const socket of this.#sockets.keys()) socket.destroy()\n }\n}\n\n/** Closes a `node:http` server: graceful (idle connections ended), then forced when asked. */\nexport function closeServer(\n server: Server,\n tracker: ConnectionTracker,\n closing: Promise<void> | undefined,\n force: boolean,\n): Promise<void> {\n const promise =\n closing ??\n new Promise<void>(resolve => {\n if (!server.listening) {\n resolve()\n return\n }\n server.close(() => resolve())\n server.closeIdleConnections?.()\n tracker.closeIdle()\n })\n if (force) {\n server.closeAllConnections?.()\n tracker.destroyAll()\n }\n return promise\n}\n"],"mappings":";;;;;AACA,MAAM,UAA4C;CAChD,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;C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AAG,OAAO,IAAI;CAC7E;;CAGA,aAAmB;EACjB,KAAK,WAAW;EAChB,KAAK,MAAM,UAAU,KAAK,SAAS,KAAK,GAAG,OAAO,QAAQ;CAC5D;AACF;;AAGA,SAAgB,YACd,QACA,SACA,SACA,OACe;CACf,MAAM,UACJ,WACA,IAAI,SAAc,YAAW;EAC3B,IAAI,CAAC,OAAO,WAAW;GACrB,QAAQ;GACR;EACF;EACA,OAAO,YAAY,QAAQ,CAAC;EAC5B,OAAO,uBAAuB;EAC9B,QAAQ,UAAU;CACpB,CAAC;CACH,IAAI,OAAO;EACT,OAAO,sBAAsB;EAC7B,QAAQ,WAAW;CACrB;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"node-io-BkdRSQeg.mjs","names":[],"sources":["../src/status.ts","../src/exceptions.ts","../src/stream.ts","../src/cookies.ts","../src/adapters/shared.ts","../src/adapters/node-io.ts"],"sourcesContent":["/** Standard reason phrases (RFC 9110 and common extensions), used in error bodies. */\nconst REASONS: Readonly<Record<number, string>> = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: \"I'm a Teapot\",\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 511: 'Network Authentication Required',\n}\n\n/** Reason phrase of `status` (`404` → `Not Found`), or a generic one for unknown codes. */\nexport function statusText(status: number): string {\n const reason = REASONS[status]\n if (reason !== undefined) return reason\n if (status >= 500) return 'Server Error'\n return status >= 400 ? 'Client Error' : 'Unknown Status'\n}\n\n/** Whether `status` is an integer in the 100–599 range. */\nexport function isValidStatus(status: unknown): status is number {\n return typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599\n}\n\n/** Statuses whose responses never have a body. */\nexport function isBodylessStatus(status: number): boolean {\n return status === 204 || status === 304 || (status >= 100 && status < 200)\n}\n","import type { StandardSchemaV1Issue } from './standard-schema.ts'\n\nimport { isValidStatus, statusText } from './status.ts'\n\n/** Response header values: a single value or several (`set-cookie`). */\nexport type HeaderValue = string | readonly string[]\n\n/** Options of {@link HttpException}. */\nexport interface HttpExceptionOptions extends ErrorOptions {\n /** Headers added to the error response (`www-authenticate`, `retry-after`, `allow`...). */\n readonly headers?: Readonly<Record<string, HeaderValue>>\n}\n\n/** JSON body of an error response. */\nexport interface HttpErrorBody {\n readonly statusCode: number\n /** Reason phrase of the status (`Not Found`). */\n readonly error: string\n readonly message: string\n /** Structured details (validation issues...), omitted when absent. */\n readonly details?: unknown\n}\n\n/** One entry of the `details` of a validation error. */\nexport interface ValidationIssueDetail {\n /** Dotted path of the invalid value inside the validated input (`user.email`, `items.0`), `''` for the root. */\n readonly path: string\n readonly message: string\n}\n\nconst NO_HEADERS: Readonly<Record<string, HeaderValue>> = Object.freeze({})\n\n/**\n * An error carrying an HTTP status. Thrown from handlers, guards, interceptors or services, it is\n * rendered as `{ statusCode, error, message, details? }` with its status and headers.\n *\n * ```ts\n * throw new HttpException(409, 'Email already used', { field: 'email' })\n * throw new NotFoundException(`User ${id} not found`)\n * throw new UnauthorizedException('Token expired', undefined, { headers: { 'www-authenticate': 'Bearer' } })\n * ```\n *\n * Invalid statuses (not an integer in 100–599) become `500`.\n */\nexport class HttpException extends Error {\n /** HTTP status of the response. */\n readonly status: number\n /** Structured details rendered in the body (omitted when `undefined`). */\n readonly details: unknown\n /** Headers added to the response. */\n readonly headers: Readonly<Record<string, HeaderValue>>\n\n constructor(status: number, message?: string, details?: unknown, options: HttpExceptionOptions = {}) {\n const code = isValidStatus(status) ? status : 500\n super(message ?? statusText(code), options.cause === undefined ? undefined : { cause: options.cause })\n this.name = 'HttpException'\n this.status = code\n this.details = details\n this.headers = options.headers ?? NO_HEADERS\n }\n\n /** The `statusCode` field of the body (alias of {@link status}). */\n get statusCode(): number {\n return this.status\n }\n\n /** Body of the error response. Override it in a subclass to change the shape. */\n toBody(): HttpErrorBody {\n const body: { statusCode: number; error: string; message: string; details?: unknown } = {\n statusCode: this.status,\n error: statusText(this.status),\n message: this.message,\n }\n if (this.details !== undefined) body.details = this.details\n return body\n }\n}\n\n/** Whether `value` is an {@link HttpException} (also across duplicated package copies). */\nexport function isHttpException(value: unknown): value is HttpException {\n return (\n value instanceof HttpException ||\n (value instanceof Error &&\n typeof (value as { status?: unknown }).status === 'number' &&\n typeof (value as { toBody?: unknown }).toBody === 'function')\n )\n}\n\n/** 400 Bad Request. */\nexport class BadRequestException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(400, message, details, options)\n this.name = 'BadRequestException'\n }\n}\n\n/**\n * 400 Bad Request raised when an input fails its schema (`@Body(schema)`, `@Query(schema)`...).\n * `details` lists the issues as `{ path, message }`; the raw Standard Schema issues are kept in\n * {@link issues} for exception mappers.\n */\nexport class ValidationException extends BadRequestException {\n /** What was validated: `body`, `query`, `query \"page\"`, `param \"id\"`... */\n readonly location: string\n readonly issues: readonly StandardSchemaV1Issue[]\n\n constructor(location: string, issues: readonly StandardSchemaV1Issue[], options?: HttpExceptionOptions) {\n super(`Invalid ${location}`, issues.map(toIssueDetail), options)\n this.name = 'ValidationException'\n this.location = location\n this.issues = issues\n }\n}\n\n/**\n * The `details` of a 400 raised by the framework for one invalid input (a multipart field...): the\n * shape of the issues of {@link ValidationException}, documented by `@znight/openapi`.\n */\nexport function issue(path: string, message: string): readonly ValidationIssueDetail[] {\n return [{ path, message }]\n}\n\n/** Converts a Standard Schema issue to `{ path, message }` (`path` dotted, `''` for the root). */\nexport function toIssueDetail(issue: StandardSchemaV1Issue): ValidationIssueDetail {\n return { path: formatIssuePath(issue.path), message: issue.message }\n}\n\nfunction formatIssuePath(path: StandardSchemaV1Issue['path']): string {\n if (path === undefined || path.length === 0) return ''\n let result = ''\n for (const segment of path) {\n const key = typeof segment === 'object' && segment !== null ? segment.key : segment\n const text = typeof key === 'symbol' ? (key.description ?? 'symbol') : String(key)\n result = result === '' ? text : `${result}.${text}`\n }\n return result\n}\n\n/** 401 Unauthorized. */\nexport class UnauthorizedException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(401, message, details, options)\n this.name = 'UnauthorizedException'\n }\n}\n\n/** 403 Forbidden (also the response of a guard returning `false`). */\nexport class ForbiddenException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(403, message, details, options)\n this.name = 'ForbiddenException'\n }\n}\n\n/** 404 Not Found. */\nexport class NotFoundException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(404, message, details, options)\n this.name = 'NotFoundException'\n }\n}\n\n/** 405 Method Not Allowed (pass the `allow` header in `options.headers`). */\nexport class MethodNotAllowedException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(405, message, details, options)\n this.name = 'MethodNotAllowedException'\n }\n}\n\n/** 409 Conflict. */\nexport class ConflictException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(409, message, details, options)\n this.name = 'ConflictException'\n }\n}\n\n/** 410 Gone. */\nexport class GoneException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(410, message, details, options)\n this.name = 'GoneException'\n }\n}\n\n/** 413 Payload Too Large (request body above `bodyLimit`). */\nexport class PayloadTooLargeException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(413, message, details, options)\n this.name = 'PayloadTooLargeException'\n }\n}\n\n/** 415 Unsupported Media Type. */\nexport class UnsupportedMediaTypeException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(415, message, details, options)\n this.name = 'UnsupportedMediaTypeException'\n }\n}\n\n/** 422 Unprocessable Entity. */\nexport class UnprocessableEntityException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(422, message, details, options)\n this.name = 'UnprocessableEntityException'\n }\n}\n\n/** 429 Too Many Requests (pass `retry-after` in `options.headers`). */\nexport class TooManyRequestsException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(429, message, details, options)\n this.name = 'TooManyRequestsException'\n }\n}\n\n/** 500 Internal Server Error (its message is always sent, unlike unexpected errors). */\nexport class InternalServerErrorException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(500, message, details, options)\n this.name = 'InternalServerErrorException'\n }\n}\n\n/** 501 Not Implemented. */\nexport class NotImplementedException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(501, message, details, options)\n this.name = 'NotImplementedException'\n }\n}\n\n/** 502 Bad Gateway. */\nexport class BadGatewayException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(502, message, details, options)\n this.name = 'BadGatewayException'\n }\n}\n\n/** 503 Service Unavailable. */\nexport class ServiceUnavailableException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(503, message, details, options)\n this.name = 'ServiceUnavailableException'\n }\n}\n\n/** 504 Gateway Timeout. */\nexport class GatewayTimeoutException extends HttpException {\n constructor(message?: string, details?: unknown, options?: HttpExceptionOptions) {\n super(504, message, details, options)\n this.name = 'GatewayTimeoutException'\n }\n}\n","/**\n * Web stream helpers shared by the pipeline and the adapters (internal): conversion of handler\n * stream sources (`ReadableStream`, Node.js `Readable`, async iterables) to byte streams, tracking of\n * response streams (request scope lifetime) and small constructors.\n */\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\n/**\n * A stream source accepted by `HttpResponse.stream()`: a Web `ReadableStream`, a Node.js `Readable`\n * or any async iterable (async generator...) of `Uint8Array` / `string` chunks (strings are encoded\n * as UTF-8).\n */\nexport type StreamSource = ReadableStream<Uint8Array | string> | AsyncIterable<Uint8Array | string>\n\n/** Runs a function in a captured async context (`AsyncLocalStorage.snapshot()`). */\nexport type ContextRunner = <R>(fn: () => R) => R\n\nconst ENCODER = new TextEncoder()\n\n/** The current async context, to run stream reads in it later (the request scope of a response). */\nexport function captureContext(): ContextRunner {\n const snapshot = (AsyncLocalStorage as { snapshot?: () => ContextRunner }).snapshot\n return typeof snapshot === 'function' ? snapshot() : run => run()\n}\n\n/** Whether `value` is a stream source (Web stream, Node.js readable or async iterable). */\nexport function isStreamSource(value: unknown): value is StreamSource {\n return (\n value instanceof ReadableStream ||\n (value !== null &&\n typeof value === 'object' &&\n typeof (value as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === 'function')\n )\n}\n\n/** Byte streams created by {@link toByteStream} (already normalised: not wrapped again). */\nconst BYTE_STREAMS = new WeakSet<ReadableStream<Uint8Array>>()\n\n/** Whether `stream` was created by {@link toByteStream}. */\nexport function isByteStream(stream: ReadableStream<unknown>): boolean {\n return BYTE_STREAMS.has(stream as ReadableStream<Uint8Array>)\n}\n\n/**\n * Converts a stream source to a pull-based byte stream: the source is read only when the consumer\n * reads (backpressure), strings are encoded as UTF-8, `ArrayBuffer`s and views are converted, empty\n * chunks are skipped and cancelling the stream cancels the source (`iterator.return()`, which\n * destroys a Node.js `Readable`; a `Readable` that was never read is destroyed directly).\n *\n * @throws TypeError (as a stream error) for chunks that are neither bytes nor strings.\n */\nexport function toByteStream(source: StreamSource): ReadableStream<Uint8Array> {\n let iterator: AsyncIterator<unknown> | undefined\n let reader: ChunkReader | undefined\n const next = (): Promise<IteratorResult<unknown>> => {\n if (source instanceof ReadableStream) {\n const current: ChunkReader = reader ?? source.getReader()\n reader = current\n return current.read() as Promise<IteratorResult<unknown>>\n }\n iterator ??= source[Symbol.asyncIterator]()\n return iterator.next()\n }\n const stream = new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n for (;;) {\n const result = await next()\n if (result.done === true) {\n controller.close()\n return\n }\n const chunk = toChunk(result.value)\n if (chunk.byteLength > 0) {\n controller.enqueue(chunk)\n return\n }\n }\n },\n async cancel(reason) {\n if (reader !== undefined) await reader.cancel(reason)\n else if (source instanceof ReadableStream) await source.cancel(reason)\n else if (iterator === undefined) {\n // never read: an async generator has nothing to clean up, a Node.js `Readable` holds its resource\n const destroyable = source as { destroy?: unknown }\n if (typeof destroyable.destroy === 'function') destroyable.destroy()\n } else await iterator.return?.(reason)\n },\n },\n { highWaterMark: 0 },\n )\n BYTE_STREAMS.add(stream)\n return stream\n}\n\n/** The part of a stream reader used here (Node.js and Bun declare different reader types). */\ninterface ChunkReader {\n read(): Promise<{ readonly done?: boolean; readonly value?: unknown }>\n cancel(reason?: unknown): Promise<void>\n}\n\nfunction toChunk(value: unknown): Uint8Array {\n if (value instanceof Uint8Array) return value\n if (typeof value === 'string') return ENCODER.encode(value)\n if (value instanceof ArrayBuffer) return new Uint8Array(value)\n if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength)\n throw new TypeError(\n `Invalid stream chunk: expected a Uint8Array or a string, received ${value === null ? 'null' : typeof value}`,\n )\n}\n\n/** The part of a byte stream reader used by {@link trackStream}. */\ninterface ByteReader {\n read(): Promise<{ readonly done?: boolean; readonly value?: Uint8Array | undefined }>\n cancel(reason?: unknown): Promise<void>\n}\n\n/** A response stream whose completion is observed. */\nexport interface TrackedStream {\n readonly stream: ReadableStream<Uint8Array>\n /**\n * Resolves once the source was fully read (`undefined`), cancelled by the consumer (`undefined`:\n * client disconnected, HEAD...) or failed (the error). Never rejects.\n */\n readonly done: Promise<unknown>\n}\n\n/**\n * Wraps a response body so that the pipeline knows when it has been fully sent (or abandoned) and\n * reads the source in `run` (the async context of the request scope, so that stream producers can\n * use request-scoped providers). The wrapper is pull-based (no read-ahead): backpressure is the\n * consumer's. A `Blob` is read through `blob.stream()`, opened on the first read only. `onCancel`\n * runs when the consumer cancels the stream (the client left), before the source is cancelled.\n */\nexport function trackStream(\n body: ReadableStream<Uint8Array> | Blob,\n run: ContextRunner,\n onCancel?: () => void,\n): TrackedStream {\n let reader: ByteReader | undefined = body instanceof Blob ? undefined : body.getReader()\n let settle: (error: unknown) => void = () => undefined\n const done = new Promise<unknown>(resolve => {\n settle = resolve\n })\n let finished = false\n const finish = (error?: unknown): void => {\n if (finished) return\n finished = true\n settle(error)\n }\n const stream = new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n let result: Awaited<ReturnType<ByteReader['read']>>\n try {\n result = await run(() => {\n reader ??= (body as Blob).stream().getReader()\n return reader.read()\n })\n } catch (error) {\n finish(error)\n throw error\n }\n if (result.done === true) {\n controller.close()\n finish()\n return\n }\n controller.enqueue(result.value as Uint8Array)\n },\n async cancel(reason) {\n onCancel?.()\n try {\n const current = reader\n if (current !== undefined) await run(() => current.cancel(reason))\n } catch {\n // the source failed while being cancelled: nothing left to send anyway\n } finally {\n finish()\n }\n },\n },\n { highWaterMark: 0 },\n )\n return { stream, done }\n}\n\n/** A stream failing with `error` on first read. */\nexport function failedStream(error: unknown): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.error(error)\n },\n })\n}\n\n/** Cancels a stream, ignoring failures (unconsumed response bodies). */\nexport function discardStream(stream: ReadableStream<Uint8Array> | null | undefined): void {\n if (stream instanceof ReadableStream && !stream.locked) stream.cancel().catch(() => undefined)\n}\n","/**\n * Cookies (RFC 0006): parsing of the `cookie` request header, canonical value encoding, strict\n * `Set-Cookie` serialisation (RFC 6265bis: attribute validation, name prefixes, size limits),\n * `Set-Cookie` parsing (tests) and the response cookie jar.\n *\n * This module is import-free (pure functions): safe to import from anywhere, the compiler excepted\n * (it has its own token grammar).\n */\n\n/** Options of a cookie set on a response (`ctx.setCookie()`, `HttpResponse.withCookie()`). */\nexport interface CookieOptions {\n /** Lifetime in seconds (integer). `0` or less expires the cookie now. Default: session cookie. */\n readonly maxAge?: number\n /**\n * Absolute expiry (sent as an IMF-fixdate), in the years 1601 to 9999 (browsers ignore other\n * years). Browsers cap lifetimes at 400 days: prefer `maxAge` for long-lived cookies.\n */\n readonly expires?: Date\n /**\n * Domain (sub-domains included). Default: none, a host-only cookie. `null`: host-only even when\n * `cookies.defaults` sets a domain. `__Host-` cookies never take the default domain.\n */\n readonly domain?: string | null\n /** Default: `'/'`. */\n readonly path?: string\n /** Default: `true` (browsers only send it over HTTPS, `http://localhost` excepted). */\n readonly secure?: boolean\n /** Default: `true` (not readable from JavaScript). */\n readonly httpOnly?: boolean\n /** Default: `'lax'`. `'none'` requires `secure`. */\n readonly sameSite?: 'strict' | 'lax' | 'none'\n /** CHIPS partitioned cookie. Requires `secure`. Default: `false`. */\n readonly partitioned?: boolean\n /** Chromium `Priority`. Default: none. */\n readonly priority?: 'low' | 'medium' | 'high'\n /** Signs the value with the first secret of the plugin option `cookies.secrets`. Default: `false`. */\n readonly signed?: boolean\n}\n\n/** Plugin-wide defaults (`cookies.defaults`). Lifetime and signing are per cookie. */\nexport type CookieDefaults = Omit<CookieOptions, 'maxAge' | 'expires' | 'signed'>\n\n/** What identifies a cookie to clear (and keeps prefixed names valid). */\nexport type ClearCookieOptions = Pick<\n CookieOptions,\n 'domain' | 'path' | 'secure' | 'httpOnly' | 'sameSite' | 'partitioned'\n>\n\n/** A cookie to send, as given (defaults and signing are applied when the response is serialised). */\nexport interface ResponseCookie {\n readonly name: string\n /** `undefined`: a clearing cookie. */\n readonly value: string | undefined\n readonly options: CookieOptions\n}\n\n/** A parsed `Set-Cookie` line (see {@link parseSetCookie}). */\nexport interface SetCookieInfo {\n readonly name: string\n /** Decoded value (a signed cookie: `\"<value>.<signature>\"`, decoded). */\n readonly value: string\n /** The header line. */\n readonly raw: string\n readonly expires?: Date\n readonly maxAge?: number\n readonly domain?: string\n readonly path?: string\n readonly secure: boolean\n readonly httpOnly: boolean\n readonly sameSite?: 'strict' | 'lax' | 'none'\n readonly partitioned: boolean\n readonly priority?: 'low' | 'medium' | 'high'\n}\n\n/** The secure defaults: `Path=/; Secure; HttpOnly; SameSite=Lax`, host-only. */\nexport const DEFAULT_COOKIE_OPTIONS: Readonly<{\n path: string\n secure: boolean\n httpOnly: boolean\n sameSite: 'strict' | 'lax' | 'none'\n}> = Object.freeze({ path: '/', secure: true, httpOnly: true, sameSite: 'lax' })\n\n/** Largest `name=value` (bytes on the wire, after encoding and signing). */\nexport const MAX_COOKIE_SIZE = 4096\n/** Largest `Domain` / `Path` attribute value (bytes). */\nexport const MAX_COOKIE_ATTRIBUTE_SIZE = 1024\nconst MAX_DOMAIN_LENGTH = 253\nconst EPOCH = 'Thu, 01 Jan 1970 00:00:00 GMT'\n/** Years a cookie-date can carry (RFC 6265 §5.1.1; four digits in an IMF-fixdate). */\nconst MIN_EXPIRES_YEAR = 1601\nconst MAX_EXPIRES_YEAR = 9999\n\nconst OPTION_KEYS: ReadonlySet<string> = new Set([\n 'maxAge',\n 'expires',\n 'domain',\n 'path',\n 'secure',\n 'httpOnly',\n 'sameSite',\n 'partitioned',\n 'priority',\n 'signed',\n])\nconst SAME_SITE: Readonly<Record<string, string>> = { strict: 'Strict', lax: 'Lax', none: 'None' }\nconst PRIORITY: Readonly<Record<string, string>> = { low: 'Low', medium: 'Medium', high: 'High' }\n\n// -------------------------------------------------------------------------------------------------\n// Request cookies\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Parses a `cookie` request header into a prototype-less, frozen record (`__proto__` is just a\n * name). Pairs are split on `;` only (never `,`) and trimmed; a pair without `=` or with an empty\n * name is ignored; names are kept as sent (case-sensitive); a value wrapped in double quotes is\n * unquoted, and percent-decoded when it contains `%` (a malformed sequence keeps the raw value).\n * When a name repeats, the first occurrence wins (browsers send the most specific path first).\n * Linear time, never throws.\n */\nexport function parseCookieHeader(header: string | undefined): Readonly<Record<string, string>> {\n const result = Object.create(null) as Record<string, string>\n if (typeof header === 'string') {\n let start = 0\n const length = header.length\n // the next `=` at or after `start`, searched again only once passed: every character is scanned\n // at most twice, even for a header made of `;` without `=` (linear time)\n let equals = -1\n while (start < length) {\n let end = header.indexOf(';', start)\n if (end === -1) end = length\n if (equals < start) {\n equals = header.indexOf('=', start)\n if (equals === -1) equals = length\n }\n if (equals < end) {\n const name = trim(header, start, equals)\n if (name !== '' && !Object.hasOwn(result, name)) {\n result[name] = decodeCookieValue(unquote(trim(header, equals + 1, end)))\n }\n }\n start = end + 1\n }\n }\n return Object.freeze(result)\n}\n\n/** `text.slice(start, end)` without leading and trailing SP / HTAB. */\nfunction trim(text: string, start: number, end: number): string {\n let from = start\n let to = end\n while (from < to && isBlank(text.charCodeAt(from))) from++\n while (to > from && isBlank(text.charCodeAt(to - 1))) to--\n return text.slice(from, to)\n}\n\nfunction isBlank(code: number): boolean {\n return code === 0x20 || code === 0x09\n}\n\nfunction unquote(value: string): string {\n return value.length >= 2 && value.charCodeAt(0) === 0x22 && value.charCodeAt(value.length - 1) === 0x22\n ? value.slice(1, -1)\n : value\n}\n\n/**\n * Decodes a cookie value produced by {@link encodeCookieValue} (`decodeURIComponent` when it\n * contains `%`; a malformed sequence keeps the raw value). Never throws.\n */\nexport function decodeCookieValue(value: string): string {\n if (!value.includes('%')) return value\n try {\n return decodeURIComponent(value)\n } catch {\n return value\n }\n}\n\n/**\n * Encodes a cookie value canonically: the UTF-8 bytes outside RFC 6265 `cookie-octet` (space, `\"`,\n * `,`, `;`, `\\`, controls, non-ASCII) and `%` are percent-encoded (upper-case hex), so that\n * {@link decodeCookieValue} restores the value exactly (`a b;c` → `a%20b%3Bc`), and\n * `encode(decode(w)) === w` for every encoded `w`. Quotes are never emitted.\n *\n * @throws TypeError for a non-string or a string with lone surrogates (they cannot round-trip).\n */\nexport function encodeCookieValue(value: string): string {\n if (typeof value !== 'string') {\n throw new TypeError(`A cookie value must be a string (received ${describe(value)})`)\n }\n if (!value.isWellFormed()) {\n throw new TypeError('A cookie value must be a well-formed string (it contains a lone surrogate)')\n }\n let encoded = ''\n let plain = 0\n for (let index = 0; index < value.length; index++) {\n const code = value.charCodeAt(index)\n if (isCookieOctet(code)) continue\n encoded += value.slice(plain, index)\n if (code < 0x80) {\n encoded += `%${HEX[code] as string}`\n plain = index + 1\n } else {\n // a whole code point (a surrogate pair is two UTF-16 units): `encodeURIComponent` gives its UTF-8 bytes\n const point = value.codePointAt(index) as number\n const width = point > 0xffff ? 2 : 1\n encoded += encodeURIComponent(value.slice(index, index + width))\n index += width - 1\n plain = index + 1\n }\n }\n return plain === 0 ? value : encoded + value.slice(plain)\n}\n\nconst HEX: readonly string[] = Array.from({ length: 128 }, (_, code) =>\n code.toString(16).toUpperCase().padStart(2, '0'),\n)\n\n/** RFC 6265 `cookie-octet`, `%` excluded (the escape character). */\nfunction isCookieOctet(code: number): boolean {\n return (\n code === 0x21 ||\n (code >= 0x23 && code <= 0x2b && code !== 0x25) ||\n (code >= 0x2d && code <= 0x3a) ||\n (code >= 0x3c && code <= 0x5b) ||\n (code >= 0x5d && code <= 0x7e)\n )\n}\n\n/** Whether `name` is an RFC 9110 token (a cookie name Znight can set). */\nexport function isCookieName(name: unknown): name is string {\n if (typeof name !== 'string' || name === '') return false\n for (let index = 0; index < name.length; index++) {\n if (!isTokenChar(name.charCodeAt(index))) return false\n }\n return true\n}\n\nfunction isTokenChar(code: number): boolean {\n // ! # $ % & ' * + - . ^ _ ` | ~ DIGIT ALPHA\n return (\n (code >= 0x30 && code <= 0x39) ||\n (code >= 0x41 && code <= 0x5a) ||\n (code >= 0x61 && code <= 0x7a) ||\n code === 0x21 ||\n (code >= 0x23 && code <= 0x27) ||\n code === 0x2a ||\n code === 0x2b ||\n code === 0x2d ||\n code === 0x2e ||\n code === 0x5e ||\n code === 0x5f ||\n code === 0x60 ||\n code === 0x7c ||\n code === 0x7e\n )\n}\n\n// -------------------------------------------------------------------------------------------------\n// Response cookies\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Checks what a cookie says about itself, without plugin defaults: the name, the value type, the\n * options (types, `maxAge`, `expires`, `domain`, `path`) and the size before signing. Run by\n * `HttpResponse.withCookie()` / `withoutCookie()` at call time; the rules depending on the defaults\n * (prefixes, `SameSite=None` and `partitioned` with `secure`), signing and the final size are checked\n * when the response is serialised.\n *\n * @throws TypeError / RangeError naming the cookie.\n */\nexport function checkCookie(name: string, value: string | undefined, options: CookieOptions | undefined): void {\n checkName(name)\n const checked = checkOptions(name, options)\n if (value !== undefined) {\n const encoded = encodeValue(name, value)\n checkSize(name, encoded)\n }\n if (typeof checked.domain === 'string') normalizeDomain(name, checked.domain)\n if (checked.path !== undefined) checkPath(name, checked.path)\n}\n\n/** A cookie resolved with the defaults: its `Set-Cookie` line and its jar key. */\nexport interface SerializedCookie {\n /** `name` + domain + path: a later cookie with the same key replaces an earlier one. */\n readonly key: string\n readonly line: string\n}\n\n/**\n * Serialises a response cookie with `defaults` (merged under the options): every rule of RFC 0006\n * §4.3 is checked. `sign` turns the encoded value into its signed wire form (`signed: true`).\n *\n * @throws TypeError / RangeError naming the cookie.\n */\nexport function serializeResponseCookie(\n cookie: ResponseCookie,\n defaults: CookieDefaults,\n sign?: (name: string, encoded: string) => string,\n): SerializedCookie {\n const { name, value } = cookie\n checkName(name)\n const options = checkOptions(name, cookie.options)\n checkOptions(name, defaults, true)\n const attributes = resolveAttributes(name, { ...applicableDefaults(name, defaults), ...definedOnly(options) })\n let wire: string\n let maxAge: number | undefined\n let expires: string | undefined\n if (value === undefined) {\n wire = ''\n maxAge = 0\n expires = EPOCH\n } else {\n wire = encodeValue(name, value)\n if (options.signed === true) {\n if (sign === undefined) throw new TypeError(`Cannot sign the cookie \"${name}\": no signing key`)\n wire = sign(name, wire)\n }\n if (options.maxAge !== undefined) maxAge = Math.max(options.maxAge, 0)\n if (options.expires !== undefined) expires = options.expires.toUTCString()\n }\n checkSize(name, wire)\n let line = `${name}=${wire}`\n if (maxAge !== undefined) line += `; Max-Age=${maxAge}`\n if (expires !== undefined) line += `; Expires=${expires}`\n if (attributes.domain !== undefined) line += `; Domain=${attributes.domain}`\n line += `; Path=${attributes.path}`\n if (attributes.secure) line += '; Secure'\n if (attributes.httpOnly) line += '; HttpOnly'\n if (attributes.sameSite !== undefined) line += `; SameSite=${SAME_SITE[attributes.sameSite] as string}`\n if (attributes.partitioned) line += '; Partitioned'\n if (attributes.priority !== undefined && value !== undefined) {\n line += `; Priority=${PRIORITY[attributes.priority] as string}`\n }\n return { key: cookieKey(name, attributes.domain, attributes.path), line }\n}\n\n/**\n * The `Set-Cookie` line of a cookie with the secure defaults\n * (`Path=/; Secure; HttpOnly; SameSite=Lax`, overridable per cookie), in the order\n * `name=value; Max-Age; Expires; Domain; Path; Secure; HttpOnly; SameSite; Partitioned; Priority`.\n * The value is percent-encoded (see {@link encodeCookieValue}). Signing (`signed: true`) needs the\n * secrets of the plugin: use `ctx.setCookie()` or `HttpPlugin.signCookie()`.\n *\n * ```ts\n * serializeCookie('theme', 'dark', { maxAge: 86_400, httpOnly: false })\n * // theme=dark; Max-Age=86400; Path=/; Secure; SameSite=Lax\n * ```\n *\n * @throws TypeError for an invalid name, value or attribute, a `SameSite=None` or partitioned cookie\n * without `Secure`, a broken `__Secure-` / `__Host-` / `__Http-` / `__Host-Http-` prefix rule.\n * @throws RangeError when `name=value` exceeds 4096 bytes, or `Domain` / `Path` 1024 bytes.\n */\nexport function serializeCookie(name: string, value: string, options: CookieOptions = {}): string {\n return serializeResponseCookie({ name, value, options }, DEFAULT_COOKIE_OPTIONS).line\n}\n\n/**\n * The `Set-Cookie` line clearing a cookie: `name=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT`\n * plus `Domain`, `Path`, `Secure`, `HttpOnly`, `SameSite` and `Partitioned` (secure defaults merged\n * with `options`), so that a prefixed cookie is cleared with valid attributes.\n */\nexport function serializeClearCookie(name: string, options: ClearCookieOptions = {}): string {\n return serializeResponseCookie({ name, value: undefined, options }, DEFAULT_COOKIE_OPTIONS).line\n}\n\n/** The jar key of a cookie (RFC 6265: a cookie is identified by its name, domain and path). */\nexport function cookieKey(name: string, domain: string | undefined, path: string): string {\n return `${name}\\u0000${domain ?? ''}\\u0000${path}`\n}\n\ninterface Attributes {\n readonly domain: string | undefined\n readonly path: string\n readonly secure: boolean\n readonly httpOnly: boolean\n readonly sameSite: 'strict' | 'lax' | 'none' | undefined\n readonly partitioned: boolean\n readonly priority: 'low' | 'medium' | 'high' | undefined\n}\n\n/**\n * The defaults a cookie takes: all of them, but a `__Host-` cookie (host-only, `Path=/` by\n * definition) never takes a default domain or path. Its own options are still checked.\n */\nfunction applicableDefaults(name: string, defaults: CookieDefaults): CookieDefaults {\n if (!name.toLowerCase().startsWith('__host-')) return defaults\n const { domain: _domain, path: _path, ...rest } = defaults\n return rest\n}\n\n/** Attributes after the defaults, checked against the cross-attribute and prefix rules. */\nfunction resolveAttributes(name: string, options: CookieOptions): Attributes {\n // `null`: host-only, whatever the defaults\n const domain = typeof options.domain === 'string' ? normalizeDomain(name, options.domain) : undefined\n const path = options.path ?? '/'\n checkPath(name, path)\n const attributes: Attributes = {\n domain,\n path,\n secure: options.secure === true,\n httpOnly: options.httpOnly === true,\n sameSite: options.sameSite,\n partitioned: options.partitioned === true,\n priority: options.priority,\n }\n if (attributes.sameSite === 'none' && !attributes.secure) {\n throw invalid(name, 'SameSite=None requires secure: true (browsers reject it otherwise)')\n }\n if (attributes.partitioned && !attributes.secure) {\n throw invalid(name, 'partitioned cookies require secure: true')\n }\n checkPrefix(name, attributes)\n return attributes\n}\n\n/** `__Secure-`, `__Host-`, `__Http-`, `__Host-Http-` (case-insensitive, like browsers). */\nfunction checkPrefix(name: string, attributes: Attributes): void {\n const lower = name.toLowerCase()\n const host = lower.startsWith('__host-')\n const http = lower.startsWith('__http-') || lower.startsWith('__host-http-')\n if (!host && !http && !lower.startsWith('__secure-')) return\n const prefix = prefixName(host, http)\n if (!attributes.secure) throw invalid(name, `the ${prefix} prefix requires secure: true`)\n if (http && !attributes.httpOnly) throw invalid(name, `the ${prefix} prefix requires httpOnly: true`)\n if (host) {\n if (attributes.domain !== undefined) throw invalid(name, `the ${prefix} prefix forbids a domain`)\n if (attributes.path !== '/') throw invalid(name, `the ${prefix} prefix requires path: '/'`)\n }\n}\n\nfunction checkName(name: string): void {\n if (!isCookieName(name)) {\n throw new TypeError(\n `Invalid cookie name ${describe(name)}: expected a token (letters, digits and ! # $ % & ' * + - . ^ _ \\` | ~)`,\n )\n }\n}\n\nfunction encodeValue(name: string, value: string): string {\n if (typeof value !== 'string') throw invalid(name, `the value must be a string (received ${describe(value)})`)\n if (!value.isWellFormed()) throw invalid(name, 'the value contains a lone surrogate')\n return encodeCookieValue(value)\n}\n\nfunction checkSize(name: string, wire: string): void {\n const size = byteLength(name) + 1 + wire.length // the wire value is ASCII\n if (size > MAX_COOKIE_SIZE) {\n throw new RangeError(\n `Invalid cookie \"${name}\": name=value is ${size} bytes on the wire, above the limit of ${MAX_COOKIE_SIZE} (browsers drop it)`,\n )\n }\n}\n\n/** Checks the type of every option (and rejects unknown keys); returns the options. */\nfunction checkOptions(name: string, options: CookieOptions | undefined, defaults = false): CookieOptions {\n if (options === undefined) return {}\n const what = defaults ? 'cookies.defaults' : 'options'\n if (options === null || typeof options !== 'object' || Array.isArray(options)) {\n throw invalid(name, `${what} must be an object (received ${describe(options)})`)\n }\n for (const key of Object.keys(options)) {\n if (!OPTION_KEYS.has(key)) throw invalid(name, `unknown option \"${key}\"`)\n }\n const { maxAge, expires, domain, path, secure, httpOnly, sameSite, partitioned, priority, signed } = options\n if (maxAge !== undefined && !(typeof maxAge === 'number' && Number.isSafeInteger(maxAge))) {\n throw invalid(name, `maxAge must be an integer number of seconds (received ${describe(maxAge)})`)\n }\n if (expires !== undefined && !(expires instanceof Date && !Number.isNaN(expires.getTime()))) {\n throw invalid(name, `expires must be a valid Date (received ${describe(expires)})`)\n }\n if (expires !== undefined) {\n const year = expires.getUTCFullYear()\n if (year < MIN_EXPIRES_YEAR || year > MAX_EXPIRES_YEAR) {\n throw invalid(\n name,\n `expires must be in the years ${MIN_EXPIRES_YEAR} to ${MAX_EXPIRES_YEAR} (received ${expires.toISOString()}): browsers ignore other dates; use maxAge for a long lifetime (browsers cap it at 400 days)`,\n )\n }\n }\n if (domain !== undefined && domain !== null && typeof domain !== 'string') {\n throw invalid(name, `domain must be a string or null (received ${describe(domain)})`)\n }\n if (path !== undefined && typeof path !== 'string') {\n throw invalid(name, `path must be a string (received ${describe(path)})`)\n }\n for (const [key, flag] of [\n ['secure', secure],\n ['httpOnly', httpOnly],\n ['partitioned', partitioned],\n ['signed', signed],\n ] as const) {\n if (flag !== undefined && typeof flag !== 'boolean') {\n throw invalid(name, `${key} must be a boolean (received ${describe(flag)})`)\n }\n }\n if (sameSite !== undefined && !Object.hasOwn(SAME_SITE, sameSite)) {\n throw invalid(name, `sameSite must be 'strict', 'lax' or 'none' (received ${describe(sameSite)})`)\n }\n if (priority !== undefined && !Object.hasOwn(PRIORITY, priority)) {\n throw invalid(name, `priority must be 'low', 'medium' or 'high' (received ${describe(priority)})`)\n }\n return options\n}\n\n/** Lower-cased, one leading `.` removed; an ASCII host name of at most 253 characters. */\nfunction normalizeDomain(name: string, domain: string): string {\n const normalized = (domain.startsWith('.') ? domain.slice(1) : domain).toLowerCase()\n if (normalized.length > MAX_COOKIE_ATTRIBUTE_SIZE) {\n throw new RangeError(`Invalid cookie \"${name}\": the domain exceeds ${MAX_COOKIE_ATTRIBUTE_SIZE} bytes`)\n }\n if (!isHostName(normalized)) {\n throw invalid(\n name,\n `invalid domain ${describe(domain)}: expected an ASCII host name (letters, digits, -, dot-separated labels; IDNs in punycode)`,\n )\n }\n return normalized\n}\n\nfunction isHostName(domain: string): boolean {\n if (domain === '' || domain.length > MAX_DOMAIN_LENGTH) return false\n let label = 0\n for (let index = 0; index < domain.length; index++) {\n const code = domain.charCodeAt(index)\n if (code === 0x2e) {\n if (label === 0) return false\n label = 0\n continue\n }\n const valid = (code >= 0x30 && code <= 0x39) || (code >= 0x61 && code <= 0x7a) || code === 0x2d\n if (!valid) return false\n label++\n }\n return label > 0\n}\n\n/** Starts with `/`, `%x20-7E` except `;`, at most 1024 bytes. */\nfunction checkPath(name: string, path: string): void {\n if (path.length > MAX_COOKIE_ATTRIBUTE_SIZE) {\n throw new RangeError(`Invalid cookie \"${name}\": the path exceeds ${MAX_COOKIE_ATTRIBUTE_SIZE} bytes`)\n }\n let valid = path.startsWith('/')\n for (let index = 0; valid && index < path.length; index++) {\n const code = path.charCodeAt(index)\n valid = code >= 0x20 && code <= 0x7e && code !== 0x3b\n }\n if (!valid) {\n throw invalid(name, `invalid path ${describe(path)}: expected \"/...\" made of visible ASCII characters without \";\"`)\n }\n}\n\n/** The options without `undefined` values (they would erase defaults when spread). */\nfunction definedOnly(options: CookieOptions): CookieOptions {\n const result: Record<string, unknown> = {}\n for (const key of Object.keys(options)) {\n const value = (options as Record<string, unknown>)[key]\n if (value !== undefined) result[key] = value\n }\n return result as CookieOptions\n}\n\n// -------------------------------------------------------------------------------------------------\n// Set-Cookie parsing\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Parses a `Set-Cookie` line (attribute names are case-insensitive; the value is decoded like a\n * request cookie). Used by `inject()` to fill `response.cookies`.\n *\n * @throws TypeError when the line has no `name=value` pair.\n */\nexport function parseSetCookie(line: string): SetCookieInfo {\n const parts = String(line).split(';')\n const pair = parts[0] as string\n const equals = pair.indexOf('=')\n const name = equals === -1 ? '' : trim(pair, 0, equals)\n if (name === '') throw new TypeError(`Invalid Set-Cookie line ${describe(line)}: missing name=value`)\n const info: {\n -readonly [K in keyof SetCookieInfo]: SetCookieInfo[K]\n } = {\n name,\n value: decodeCookieValue(unquote(trim(pair, equals + 1, pair.length))),\n raw: line,\n secure: false,\n httpOnly: false,\n partitioned: false,\n }\n for (const part of parts.slice(1)) {\n const separator = part.indexOf('=')\n const key = trim(part, 0, separator === -1 ? part.length : separator).toLowerCase()\n const value = separator === -1 ? '' : trim(part, separator + 1, part.length)\n switch (key) {\n case 'max-age': {\n const seconds = /^-?\\d+$/.test(value) ? Number(value) : Number.NaN\n if (Number.isSafeInteger(seconds)) info.maxAge = seconds\n break\n }\n case 'expires': {\n const date = new Date(value)\n if (!Number.isNaN(date.getTime())) info.expires = date\n break\n }\n case 'domain':\n if (value !== '') info.domain = (value.startsWith('.') ? value.slice(1) : value).toLowerCase()\n break\n case 'path':\n if (value.startsWith('/')) info.path = value\n break\n case 'secure':\n info.secure = true\n break\n case 'httponly':\n info.httpOnly = true\n break\n case 'partitioned':\n info.partitioned = true\n break\n case 'samesite': {\n const sameSite = value.toLowerCase()\n if (sameSite === 'strict' || sameSite === 'lax' || sameSite === 'none') info.sameSite = sameSite\n break\n }\n case 'priority': {\n const priority = value.toLowerCase()\n if (priority === 'low' || priority === 'medium' || priority === 'high') info.priority = priority\n break\n }\n default:\n break\n }\n }\n return Object.freeze(info)\n}\n\n/** The `set-cookie` lines of a response parsed by name (the last one wins), prototype-less and frozen. */\nexport function parseSetCookies(\n lines: readonly string[] | string | undefined,\n): Readonly<Record<string, SetCookieInfo>> {\n const result = Object.create(null) as Record<string, SetCookieInfo>\n const list = typeof lines === 'string' ? [lines] : (lines ?? [])\n for (const line of list) {\n try {\n const info = parseSetCookie(line)\n result[info.name] = info\n } catch {\n // not a cookie line: ignored\n }\n }\n return Object.freeze(result)\n}\n\n// -------------------------------------------------------------------------------------------------\n// Jar\n// -------------------------------------------------------------------------------------------------\n\n/**\n * Cookies of a response in insertion order, keyed by name, domain and path: a later cookie with\n * the same key replaces the earlier one in place (set then clear gives one clearing cookie).\n */\nexport class CookieJar<T> {\n readonly #entries = new Map<string, T>()\n\n /** Adds or replaces (in place) the entry of `key`. */\n set(key: string, entry: T): void {\n this.#entries.set(key, entry)\n }\n\n get size(): number {\n return this.#entries.size\n }\n\n values(): T[] {\n return [...this.#entries.values()]\n }\n\n entries(): [string, T][] {\n return [...this.#entries.entries()]\n }\n}\n\n/**\n * The jar key of a cookie as given (`HttpResponse.withCookie()`, before the defaults are known):\n * an absent domain or path is keyed as \"default\", a `null` domain as host-only.\n */\nexport function givenCookieKey(name: string, options: CookieOptions): string {\n const given = options.domain\n let domain: string\n if (given === undefined) domain = '\\u0001'\n else if (given === null) domain = ''\n else domain = (given.startsWith('.') ? given.slice(1) : given).toLowerCase()\n return `${name}\\u0000${domain}\\u0000${options.path ?? '\\u0001'}`\n}\n\n// -------------------------------------------------------------------------------------------------\n// Helpers\n// -------------------------------------------------------------------------------------------------\n\nfunction prefixName(host: boolean, http: boolean): string {\n if (host) return http ? '__Host-Http-' : '__Host-'\n return http ? '__Http-' : '__Secure-'\n}\n\nfunction invalid(name: string, reason: string): TypeError {\n return new TypeError(`Invalid cookie \"${name}\": ${reason}`)\n}\n\nfunction byteLength(text: string): number {\n let size = 0\n for (let index = 0; index < text.length; index++) {\n const code = text.charCodeAt(index)\n if (code < 0x80) size += 1\n else if (code < 0x800 || (code >= 0xd800 && code <= 0xdfff))\n size += 2 // a surrogate pair: 4 bytes\n else size += 3\n }\n return size\n}\n\nfunction describe(value: unknown): string {\n if (typeof value === 'string') return JSON.stringify(value.length > 64 ? `${value.slice(0, 64)}…` : value)\n if (value instanceof Date) return 'an invalid Date'\n if (value === null) return 'null'\n if (typeof value === 'object') return 'an object'\n return typeof value === 'bigint' ? `${value}n` : String(value)\n}\n","/** Helpers shared by the adapters (internal). */\nimport type { Readable } from 'node:stream'\nimport type {\n HttpServerAddress,\n InjectRequest,\n InjectResponse,\n InjectStreamRequest,\n InjectStreamResponse,\n} from '../adapter.ts'\n\nimport { encodeCookieValue, parseSetCookies } from '../cookies.ts'\nimport { BadRequestException, PayloadTooLargeException } from '../exceptions.ts'\nimport { failedStream } from '../stream.ts'\n\n/** An inject request normalised for the underlying tools. */\nexport interface NormalizedInject {\n readonly method: string\n readonly url: string\n readonly headers: Record<string, string>\n readonly payload: string | Uint8Array | undefined\n}\n\n/**\n * Applies the defaults of {@link InjectRequest}: query merged in the URL, cookies appended to the\n * `cookie` header (encoded values joined with `; `), body encoding and content type (`FormData` →\n * `multipart/form-data`, `Blob` → its type).\n */\nexport async function normalizeInject(request: InjectRequest): Promise<NormalizedInject> {\n if (request === null || typeof request !== 'object') throw new TypeError('inject() expects a request object')\n if (typeof request.url !== 'string' || !request.url.startsWith('/')) {\n throw new TypeError(`inject() expects a url starting with \"/\" (received ${JSON.stringify(request.url)})`)\n }\n const method = (request.method ?? 'GET').toUpperCase()\n let url = request.url\n if (request.query !== undefined) {\n const search = new URLSearchParams()\n for (const [key, value] of Object.entries(request.query)) {\n if (typeof value === 'string') search.append(key, value)\n else for (const item of value) search.append(key, item)\n }\n const query = search.toString()\n if (query !== '') url += `${url.includes('?') ? '&' : '?'}${query}`\n }\n const headers: Record<string, string> = {}\n for (const [name, value] of Object.entries(request.headers ?? {})) headers[name.toLowerCase()] = value\n if (request.signedCookies !== undefined) {\n throw new TypeError('inject(): signedCookies are signed by HttpPlugin.inject() (adapters only accept cookies)')\n }\n const cookie = cookieHeader(request.cookies)\n if (cookie !== '') headers['cookie'] = headers['cookie'] === undefined ? cookie : `${headers['cookie']}; ${cookie}`\n const body = request.body\n let payload: string | Uint8Array | undefined\n if (body === undefined) {\n payload = undefined\n } else if (typeof body === 'string') {\n payload = body\n headers['content-type'] ??= 'text/plain; charset=utf-8'\n } else if (body instanceof Uint8Array || body instanceof ArrayBuffer) {\n payload = body instanceof Uint8Array ? body : new Uint8Array(body)\n headers['content-type'] ??= 'application/octet-stream'\n } else if (body instanceof FormData) {\n // the Fetch API encodes forms (the boundary of the generated content type must be used)\n const encoded = new Response(body)\n // read the generated content type (with its boundary) before consuming the body (Bun sets it lazily)\n const type = encoded.headers.get('content-type')\n payload = new Uint8Array(await encoded.arrayBuffer())\n headers['content-type'] = type ?? encoded.headers.get('content-type') ?? 'multipart/form-data'\n } else if (body instanceof Blob) {\n payload = new Uint8Array(await body.arrayBuffer())\n headers['content-type'] ??= body.type === '' ? 'application/octet-stream' : body.type\n } else {\n payload = JSON.stringify(body)\n headers['content-type'] ??= 'application/json'\n }\n return { method, url, headers, payload }\n}\n\n/** The `cookie` header of inject cookies: `name=encoded` pairs joined with `; `. */\nfunction cookieHeader(cookies: Readonly<Record<string, string>> | undefined): string {\n if (cookies === undefined) return ''\n if (cookies === null || typeof cookies !== 'object') throw new TypeError('inject(): cookies must be an object')\n const pairs: string[] = []\n for (const name of Object.keys(cookies)) {\n if (!isRequestCookieName(name)) {\n throw new TypeError(\n `inject(): invalid cookie name ${JSON.stringify(name)} (empty, or with \";\", \"=\", spaces or controls)`,\n )\n }\n const value = cookies[name]\n if (typeof value !== 'string') throw new TypeError(`inject(): the value of the cookie \"${name}\" must be a string`)\n pairs.push(`${name}=${encodeCookieValue(value)}`)\n }\n return pairs.join('; ')\n}\n\n/** A name a `cookie` header can carry: no `;`, `=`, whitespace or controls, Latin-1. */\nfunction isRequestCookieName(name: string): boolean {\n if (name === '') return false\n for (let index = 0; index < name.length; index++) {\n const code = name.charCodeAt(index)\n if (code <= 0x20 || code === 0x3b || code === 0x3d || code === 0x7f || code > 0xff) return false\n }\n return true\n}\n\nconst DECODER = new TextDecoder()\n\n/**\n * Normalises response headers: lower-case names, repeated values joined with `, `, except\n * `set-cookie` (one entry per cookie: an `Expires` attribute contains `, `).\n */\nexport function injectHeaders(\n headers: Readonly<Record<string, string | number | readonly string[] | undefined>>,\n): Record<string, string | string[]> {\n const normalized: Record<string, string | string[]> = {}\n for (const [name, value] of Object.entries(headers)) {\n if (value === undefined) continue\n const key = name.toLowerCase()\n if (key === 'set-cookie') normalized[key] = typeof value === 'object' ? [...value] : [String(value)]\n else normalized[key] = typeof value === 'object' ? value.join(', ') : String(value)\n }\n return normalized\n}\n\n/** Builds an {@link InjectResponse} (headers normalised by {@link injectHeaders}, cookies parsed). */\nexport function injectResponse(\n status: number,\n headers: Readonly<Record<string, string | number | readonly string[] | undefined>>,\n bytes: Uint8Array,\n): InjectResponse {\n const normalized = injectHeaders(headers)\n const body = DECODER.decode(bytes)\n return {\n status,\n headers: normalized,\n body,\n bytes,\n cookies: parseSetCookies(normalized['set-cookie']),\n json: <T = unknown>(): T => JSON.parse(body) as T,\n }\n}\n\n/** Whether a `content-type` is `text/event-stream`. */\nexport function isEventStreamType(contentType: string | readonly string[] | undefined): boolean {\n if (typeof contentType !== 'string') return false\n const semicolon = contentType.indexOf(';')\n return (semicolon === -1 ? contentType : contentType.slice(0, semicolon)).trim().toLowerCase() === 'text/event-stream'\n}\n\n/**\n * `inject()` on top of `injectStream()`: reads the body to its end, except for an event stream\n * (which would never end): its body is cancelled (the server sees a disconnect) and the call\n * rejects with a hint.\n */\nexport async function bufferInjectStream(\n injectStream: (request: InjectStreamRequest) => Promise<InjectStreamResponse>,\n request: InjectRequest,\n): Promise<InjectResponse> {\n const response = await injectStream(request)\n const method = (request.method ?? 'GET').toUpperCase()\n if (method !== 'HEAD' && isEventStreamType(response.headers['content-type'])) {\n await response.body.cancel().catch(() => undefined)\n throw new TypeError(\n `inject(): ${method} ${request.url} answered an event stream (text/event-stream): use injectSse() or injectStream()`,\n )\n }\n const reader = response.body.getReader()\n const chunks: Uint8Array[] = []\n let size = 0\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n size += value.byteLength\n chunks.push(value)\n }\n const bytes = concat(chunks, size)\n const body = DECODER.decode(bytes)\n return {\n status: response.status,\n headers: response.headers,\n body,\n bytes,\n cookies: response.cookies,\n json: <T = unknown>(): T => JSON.parse(body) as T,\n }\n}\n\n/** Builds an {@link InjectStreamResponse}. */\nexport function injectStreamResponse(\n status: number,\n headers: Readonly<Record<string, string | number | readonly string[] | undefined>>,\n body: ReadableStream<Uint8Array>,\n): InjectStreamResponse {\n const normalized = injectHeaders(headers)\n return { status, headers: normalized, cookies: parseSetCookies(normalized['set-cookie']), body }\n}\n\n/** Builds an {@link HttpServerAddress} from a bound address. */\nexport function serverAddress(address: string, port: number, family?: string | number): HttpServerAddress {\n const ipv6 = family === 'IPv6' || family === 6 || address.includes(':')\n let client = address\n if (address === '0.0.0.0') client = '127.0.0.1'\n else if (address === '::') client = '::1'\n const url = `http://${client.includes(':') ? `[${client}]` : client}:${port}`\n return Object.freeze({\n host: address,\n port,\n family: ipv6 ? 'IPv6' : 'IPv4',\n url,\n toString: () => url,\n })\n}\n\n/** The 413 error of a body above `limit` bytes. */\nexport function payloadTooLarge(limit: number): PayloadTooLargeException {\n return new PayloadTooLargeException(`Request body exceeds the limit of ${limit} bytes`, undefined, {\n headers: { connection: 'close' },\n })\n}\n\n/** Rejects early when `content-length` announces more than `limit` bytes. */\nexport function exceedsDeclaredLength(contentLength: string | undefined, limit: number): boolean {\n if (contentLength === undefined) return false\n const length = Number(contentLength)\n return Number.isFinite(length) && length > limit\n}\n\n/** Bytes read (and discarded) from an abandoned Web request body before it is cancelled. */\nconst MAX_DISCARD_BYTES = 64 * 1024 * 1024\n\n/**\n * The body of a Web request as a pull-based stream enforcing `limit` (see\n * `AdapterRequest.streamBody`). `body` is only read when needed (a Node.js-backed request body\n * starts buffering once accessed). On overflow or cancellation the rest of the body is read and\n * discarded in the background (up to 64 MiB, then cancelled), so the server can write the response\n * and keep the connection usable instead of resetting it.\n */\nexport function webBodyStream(\n body: () => ReadableStream<Uint8Array> | null,\n limit: number,\n contentLength: string | undefined,\n): ReadableStream<Uint8Array> {\n if (exceedsDeclaredLength(contentLength, limit)) return failedStream(payloadTooLarge(limit))\n const source = body()\n if (source === null) return new ReadableStream<Uint8Array>({ start: controller => controller.close() })\n const reader = source.getReader()\n let size = 0\n let abandoned = false\n const abandon = (): void => {\n if (abandoned) return\n abandoned = true\n discardReader(reader)\n }\n return new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n let result: Awaited<ReturnType<typeof reader.read>>\n try {\n result = await reader.read()\n } catch (error) {\n abandoned = true\n throw new BadRequestException('Failed to read the request body', undefined, { cause: error })\n }\n if (result.done) {\n abandoned = true\n controller.close()\n return\n }\n size += result.value.byteLength\n if (size > limit) {\n abandon()\n throw payloadTooLarge(limit)\n }\n controller.enqueue(result.value)\n },\n cancel: abandon,\n },\n { highWaterMark: 0 },\n )\n}\n\n/** The part of a stream reader used to discard a body. */\ninterface BodyReader {\n read(): Promise<{ readonly done: boolean; readonly value?: Uint8Array | undefined }>\n cancel(): Promise<void>\n}\n\n/** Reads and drops the rest of a request body in the background, cancelling it past 64 MiB. */\nfunction discardReader(reader: BodyReader): void {\n let discarded = 0\n const next = (): void => {\n reader.read().then(\n result => {\n if (result.done) return\n discarded += result.value?.byteLength ?? 0\n if (discarded > MAX_DISCARD_BYTES) reader.cancel().catch(() => undefined)\n else next()\n },\n () => undefined,\n )\n }\n next()\n}\n\n/** Reads a Web request body fully, enforcing `limit` (see {@link webBodyStream}). */\nexport async function readWebStream(\n body: () => ReadableStream<Uint8Array> | null,\n limit: number,\n contentLength: string | undefined,\n): Promise<Uint8Array> {\n const reader = webBodyStream(body, limit, contentLength).getReader()\n const chunks: Uint8Array[] = []\n let size = 0\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n size += value.byteLength\n chunks.push(value)\n }\n return concat(chunks, size)\n}\n\n/** Concatenates chunks (no copy for a single chunk). */\nexport function concat(chunks: readonly Uint8Array[], size: number): Uint8Array {\n if (chunks.length === 0) return new Uint8Array(0)\n if (chunks.length === 1) return chunks[0] as Uint8Array\n const result = new Uint8Array(size)\n let offset = 0\n for (const chunk of chunks) {\n result.set(chunk, offset)\n offset += chunk.byteLength\n }\n return result\n}\n\n/** The light-my-request response of a streaming inject (`payloadAsStream: true`). */\ninterface LightStreamResponse {\n readonly statusCode: number\n readonly headers: Record<string, string | number | string[] | undefined>\n stream(): Readable\n readonly raw: { readonly res: { destroy(error?: Error): void } }\n}\n\n/** Minimal typing of `light-my-request` (optional peer dependency). */\nexport interface LightMyRequest {\n inject(dispatch: (req: never, res: never) => void, options: LightInjectOptions): PromiseLike<LightStreamResponse>\n}\n\n/** Options of a streaming light-my-request inject (also `fastify.inject()`). */\nexport interface LightInjectOptions {\n method: string\n url: string\n headers: Record<string, string>\n payload?: string | Buffer\n remoteAddress?: string\n payloadAsStream: true\n}\n\nlet lightMyRequest: Promise<LightMyRequest> | undefined\n\n/** Loads `light-my-request`, with an actionable error when it is not installed. */\nexport function loadLightMyRequest(adapter: string): Promise<LightMyRequest> {\n lightMyRequest ??= import('light-my-request').then(\n module => {\n const loaded = module as unknown as { default?: LightMyRequest } & LightMyRequest\n return loaded.default ?? loaded\n },\n (error: unknown) => {\n lightMyRequest = undefined\n throw new Error(\n `inject() with the ${adapter} adapter requires the optional peer dependency \"light-my-request\" ` +\n '(bun add -d light-my-request / npm i -D light-my-request)',\n { cause: error },\n )\n },\n )\n return lightMyRequest\n}\n\n/**\n * The light-my-request options of a normalised inject request (streaming mode). The signal is\n * handled by {@link lightStreamResponse} (light-my-request would destroy its fake request with an\n * unhandled error); an already aborted signal rejects at once, like `fetch()`.\n */\nexport async function lightInjectOptions(request: InjectStreamRequest): Promise<LightInjectOptions> {\n request.signal?.throwIfAborted()\n const normalized = await normalizeInject(request)\n return {\n method: normalized.method,\n url: normalized.url,\n headers: normalized.headers,\n remoteAddress: '127.0.0.1',\n payloadAsStream: true,\n ...(normalized.payload === undefined ? {} : { payload: toBuffer(normalized.payload) }),\n }\n}\n\n/** Runs a request through a Node.js request listener with `light-my-request`, streaming the body. */\nexport async function injectNodeStream(\n adapter: string,\n dispatch: (req: never, res: never) => void,\n request: InjectStreamRequest,\n): Promise<InjectStreamResponse> {\n const options = await lightInjectOptions(request)\n const { inject } = await loadLightMyRequest(adapter)\n return lightStreamResponse(await inject(dispatch, options), request.signal)\n}\n\n/**\n * An {@link InjectStreamResponse} of a light-my-request streaming response. Cancelling the body\n * (or aborting `signal`) destroys the server response: the server sees a client disconnect.\n */\nexport function lightStreamResponse(response: LightStreamResponse, signal?: AbortSignal): InjectStreamResponse {\n const readable = response.stream()\n const disconnect = (): void => {\n response.raw.res.destroy()\n readable.destroy()\n }\n let finished = false\n const body = new ReadableStream<Uint8Array>(\n {\n start(controller) {\n readable.on('data', (chunk: Buffer) => {\n if (finished) return\n controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength))\n if ((controller.desiredSize ?? 0) <= 0) readable.pause()\n })\n readable.once('end', () => {\n if (finished) return\n finished = true\n controller.close()\n })\n readable.once('error', error => {\n if (finished) return\n finished = true\n controller.error(error)\n })\n },\n pull() {\n if (readable.isPaused()) readable.resume()\n },\n cancel() {\n finished = true\n disconnect()\n },\n },\n { highWaterMark: 0 },\n )\n if (signal !== undefined) {\n if (signal.aborted) disconnect()\n else signal.addEventListener('abort', disconnect, { once: true })\n }\n return injectStreamResponse(response.statusCode, response.headers, body)\n}\n\n/** A `Buffer` view of bytes (tools such as light-my-request JSON-encode other objects). */\nexport function toBuffer(payload: string | Uint8Array): string | Buffer {\n return typeof payload === 'string' ? payload : Buffer.from(payload.buffer, payload.byteOffset, payload.byteLength)\n}\n\n/**\n * Runs a request through a Fetch handler (`(request: Request) => Promise<Response>`), streaming\n * the body. Cancelling the body (or aborting `signal`) aborts the request signal and cancels the\n * response body.\n */\nexport async function injectFetchStream(\n fetch: (request: Request) => Response | Promise<Response>,\n request: InjectStreamRequest,\n): Promise<InjectStreamResponse> {\n const signal = request.signal\n signal?.throwIfAborted()\n const normalized = await normalizeInject(request)\n const abort = new AbortController()\n signal?.addEventListener('abort', () => abort.abort(signal.reason), { once: true })\n const init: RequestInit = { method: normalized.method, headers: normalized.headers, signal: abort.signal }\n if (normalized.payload !== undefined && normalized.method !== 'GET' && normalized.method !== 'HEAD') {\n init.body = normalized.payload\n }\n const response = await fetch(new Request(`http://localhost${normalized.url}`, init))\n const headers: Record<string, string | readonly string[]> = {}\n for (const [name, value] of response.headers) if (name !== 'set-cookie') headers[name] = value\n const cookies = response.headers.getSetCookie()\n if (cookies.length > 0) headers['set-cookie'] = cookies\n const source = response.body\n const reader = source?.getReader()\n const body = new ReadableStream<Uint8Array>(\n {\n async pull(controller) {\n if (reader === undefined) {\n controller.close()\n return\n }\n const result = await reader.read()\n if (result.done) controller.close()\n else controller.enqueue(result.value)\n },\n async cancel(reason) {\n abort.abort(reason)\n await reader?.cancel(reason).catch(() => undefined)\n },\n },\n { highWaterMark: 0 },\n )\n abort.signal.addEventListener('abort', () => reader?.cancel(abort.signal.reason).catch(() => undefined), {\n once: true,\n })\n return injectStreamResponse(response.status, headers, body)\n}\n","/** Node.js `IncomingMessage` / `ServerResponse` helpers shared by the Node and Express adapters (internal). */\nimport type { IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders, Server, ServerResponse } from 'node:http'\nimport type { Socket } from 'node:net'\nimport type { AdapterReply, AdapterRequest } from '../adapter.ts'\nimport type { HeaderValue } from '../exceptions.ts'\n\nimport { Readable } from 'node:stream'\nimport { pipeline } from 'node:stream/promises'\n\nimport { BadRequestException } from '../exceptions.ts'\nimport { discardStream, failedStream } from '../stream.ts'\nimport { concat, exceedsDeclaredLength, payloadTooLarge } from './shared.ts'\n\n/** Bytes buffered by a request body stream before the request is paused. */\nconst BODY_HIGH_WATER_MARK = 64 * 1024\n\n/** Request headers with array values (only `set-cookie` in Node.js) joined with `, `. */\nexport function normalizeNodeHeaders(headers: IncomingHttpHeaders): Record<string, string | undefined> {\n for (const name in headers) {\n if (typeof headers[name] !== 'string') return copyHeaders(headers)\n }\n return headers as Record<string, string | undefined>\n}\n\nfunction copyHeaders(headers: IncomingHttpHeaders): Record<string, string | undefined> {\n const result: Record<string, string | undefined> = {}\n for (const name in headers) {\n const value = headers[name]\n result[name] = Array.isArray(value) ? value.join(', ') : value\n }\n return result\n}\n\n/**\n * Whether the body was already read by someone else: an Express body parser (`express.json()`...)\n * marks the request with `_body`; otherwise a declared body that already ended.\n */\nfunction consumedElsewhere(request: IncomingMessage): boolean {\n if ((request as { _body?: unknown })._body === true) return true\n if (!request.readableEnded) return false\n const length = request.headers['content-length']\n return request.headers['transfer-encoding'] !== undefined || (length !== undefined && length.trim() !== '0')\n}\n\n/** The error of a body consumed before Znight read it (an empty body would be silently wrong). */\nfunction consumedError(): Error {\n return new Error(\n 'The request body was already read by a middleware (an Express body parser such as express.json()?): ' +\n 'Znight reads the bodies of its routes itself, do not register body parsers for them',\n )\n}\n\n/** Reads a Node.js request body, enforcing `limit` (on `content-length`, then while streaming). */\nexport function readNodeBody(request: IncomingMessage, limit: number): Promise<Uint8Array> {\n if (exceedsDeclaredLength(request.headers['content-length'], limit)) {\n request.resume()\n return Promise.reject(payloadTooLarge(limit))\n }\n // a read in progress (the adapters read a body once: not expected)\n const reading = (request as ReadingRequest)[BODY_READ]\n if (reading != null) return reading.promise\n if (consumedElsewhere(request)) return Promise.reject(consumedError())\n if (request.readableEnded) return Promise.resolve(new Uint8Array(0))\n if (request.destroyed) return Promise.reject(new BadRequestException('The request was aborted'))\n let resolve!: (bytes: Uint8Array) => void\n let reject!: (error: unknown) => void\n const promise = new Promise<Uint8Array>((onRead, onError) => {\n resolve = onRead\n reject = onError\n })\n ;(request as ReadingRequest)[BODY_READ] = { limit, chunks: [], size: 0, resolve, reject, promise }\n if (reading === undefined) {\n request.on('data', onBodyData)\n request.on('end', onBodyEnd)\n request.on('error', onBodyError)\n request.on('close', onBodyClose)\n }\n return promise\n}\n\n/**\n * The state of the body read by {@link readNodeBody}, on its request: `null` once it is over (the\n * listeners stay), `undefined` before.\n */\nconst BODY_READ = Symbol('znight.bodyRead')\n\ninterface BodyRead {\n readonly limit: number\n readonly chunks: Uint8Array[]\n size: number\n readonly resolve: (bytes: Uint8Array) => void\n readonly reject: (error: unknown) => void\n readonly promise: Promise<Uint8Array>\n}\n\ntype ReadingRequest = IncomingMessage & { [BODY_READ]?: BodyRead | null }\n\n// The listeners of readNodeBody: shared functions (`this` is the request), no closure per request.\n// They stay attached once the read is over (removing them costs a lot more than leaving them): they\n// then do nothing. Node.js emits `error` on a destroyed request only when it has listeners, so the\n// `error` listener left behind changes nothing either.\n\n/** Stops reading: returns the state of the read (`undefined` when it is already over). */\nfunction stopBodyRead(request: ReadingRequest): BodyRead | undefined {\n const read = request[BODY_READ]\n if (read == null) return undefined\n request[BODY_READ] = null\n return read\n}\n\nfunction onBodyData(this: ReadingRequest, chunk: Uint8Array | string): void {\n const read = this[BODY_READ]\n if (read == null) return\n const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk\n read.size += bytes.byteLength\n if (read.size > read.limit) {\n stopBodyRead(this)\n this.resume() // discard the rest; the 413 response closes the connection\n read.reject(payloadTooLarge(read.limit))\n return\n }\n read.chunks.push(bytes)\n}\n\nfunction onBodyEnd(this: ReadingRequest): void {\n const read = stopBodyRead(this)\n read?.resolve(concat(read.chunks, read.size))\n}\n\nfunction onBodyError(this: ReadingRequest, error: Error): void {\n stopBodyRead(this)?.reject(new BadRequestException('Failed to read the request body', undefined, { cause: error }))\n}\n\nfunction onBodyClose(this: ReadingRequest): void {\n if (this.complete) return\n stopBodyRead(this)?.reject(new BadRequestException('The request was aborted'))\n}\n\n/**\n * A Node.js request body as a Web stream (see `AdapterRequest.streamBody`): the request is paused\n * while the consumer does not read (backpressure); past `limit` bytes the stream errors with 413 and\n * the rest of the body is discarded (`request.resume()`), like when the consumer cancels the stream,\n * so the response can still be written (it carries `connection: close`).\n */\nexport function nodeBodyStream(request: IncomingMessage, limit: number): ReadableStream<Uint8Array> {\n if (exceedsDeclaredLength(request.headers['content-length'], limit)) {\n request.resume()\n return failedStream(payloadTooLarge(limit))\n }\n if (consumedElsewhere(request)) return failedStream(consumedError())\n if (request.readableEnded) return new ReadableStream<Uint8Array>({ start: controller => controller.close() })\n if (request.destroyed) return failedStream(new BadRequestException('The request was aborted'))\n let size = 0\n let cleanup = (): void => undefined\n return new ReadableStream<Uint8Array>(\n {\n start(controller) {\n const onData = (chunk: Uint8Array | string): void => {\n const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk\n size += bytes.byteLength\n if (size > limit) {\n cleanup()\n request.resume() // discard the rest; the 413 response closes the connection\n controller.error(payloadTooLarge(limit))\n return\n }\n controller.enqueue(bytes)\n if ((controller.desiredSize ?? 0) <= 0) request.pause()\n }\n const onEnd = (): void => {\n cleanup()\n controller.close()\n }\n const onError = (error: Error): void => {\n cleanup()\n controller.error(new BadRequestException('Failed to read the request body', undefined, { cause: error }))\n }\n const onClose = (): void => {\n if (request.complete) return\n cleanup()\n controller.error(new BadRequestException('The request was aborted'))\n }\n cleanup = (): void => {\n request.off('data', onData)\n request.off('end', onEnd)\n request.off('error', onError)\n request.off('close', onClose)\n }\n request.on('data', onData)\n request.on('end', onEnd)\n request.on('error', onError)\n request.on('close', onClose)\n },\n pull() {\n if (request.isPaused()) request.resume()\n },\n cancel() {\n cleanup()\n request.resume() // discard the rest of the body\n },\n },\n { highWaterMark: BODY_HIGH_WATER_MARK, size: (chunk: Uint8Array | undefined) => chunk?.byteLength ?? 0 },\n )\n}\n\n/** Options of {@link nodeAdapterRequest}. */\nexport interface NodeRequestOptions {\n /** Request target (default: `request.url`). */\n readonly url?: string\n /** `@Req()` value (default: the `IncomingMessage`). */\n readonly raw?: unknown\n /** `@Res()` value (default: the `ServerResponse`). */\n readonly rawResponse?: unknown\n readonly ip?: string | undefined\n}\n\n/** Wraps a Node.js request/response pair as an {@link AdapterRequest}. */\nexport function nodeAdapterRequest(\n request: IncomingMessage,\n response: ServerResponse,\n options: NodeRequestOptions = NO_OPTIONS,\n): AdapterRequest {\n return new NodeAdapterRequest(request, response, options)\n}\n\nconst NO_OPTIONS: NodeRequestOptions = Object.freeze({})\n\n/** A Node.js request/response pair as an {@link AdapterRequest} (a class: no closure per request). */\nclass NodeAdapterRequest implements AdapterRequest {\n readonly method: string\n readonly url: string\n readonly headers: Readonly<Record<string, string | undefined>>\n readonly ip: string | undefined\n readonly remoteAddress: string | undefined\n readonly encrypted: boolean\n readonly raw: unknown\n readonly rawResponse: unknown\n readonly #request: IncomingMessage\n readonly #response: ServerResponse\n #body: Promise<Uint8Array> | undefined\n\n constructor(request: IncomingMessage, response: ServerResponse, options: NodeRequestOptions) {\n const remoteAddress = request.socket?.remoteAddress\n this.method = request.method ?? 'GET'\n this.url = options.url ?? request.url ?? '/'\n this.headers = normalizeNodeHeaders(request.headers)\n this.ip = options.ip ?? remoteAddress\n this.remoteAddress = remoteAddress\n this.encrypted = isEncrypted(request)\n this.raw = options.raw ?? request\n this.rawResponse = options.rawResponse ?? response\n this.#request = request\n this.#response = response\n }\n\n readBody(limit: number): Promise<Uint8Array> {\n this.#body ??= readNodeBody(this.#request, limit)\n return this.#body\n }\n\n streamBody(limit: number): ReadableStream<Uint8Array> {\n return nodeBodyStream(this.#request, limit)\n }\n\n rawStatus(): number {\n return this.#response.statusCode\n }\n\n onAbort(listener: () => void): void {\n onResponseAbort(this.#response, listener)\n }\n}\n\n/**\n * Calls `listener` once when `response` closes before it was fully written (the client left): on\n * the next microtask when it is already destroyed, never after a complete response.\n */\nexport function onResponseAbort(response: ServerResponse, listener: () => void): void {\n if (response.writableFinished) return\n if (response.destroyed) {\n queueMicrotask(listener)\n return\n }\n response.once('close', () => {\n if (!response.writableFinished) listener()\n })\n}\n\n/** Whether the request came over TLS (`node:https`, `node:http2` secure servers). */\nexport function isEncrypted(request: IncomingMessage): boolean {\n return (request.socket as { readonly encrypted?: unknown } | undefined)?.encrypted === true\n}\n\n/**\n * Writes a reply to a `ServerResponse`, piping a stream body (a failing stream destroys the\n * response). Never throws.\n */\nexport function writeNodeReply(response: ServerResponse, reply: AdapterReply): void {\n if (reply.raw === true) {\n discardStream(reply.body instanceof ReadableStream ? reply.body : null)\n return\n }\n if (response.headersSent || response.destroyed) {\n discardStream(reply.body instanceof ReadableStream ? reply.body : null)\n if (!response.writableEnded && !response.destroyed) response.end()\n return\n }\n try {\n // one call (merged over headers set earlier with setHeader(), e.g. by Express middleware); the\n // cookies set earlier are kept before the reply's own (writeHead would replace them)\n const headers =\n reply.headers['set-cookie'] === undefined\n ? reply.headers\n : withNativeCookies(response.getHeader('set-cookie'), reply.headers)\n response.writeHead(reply.status, headers as OutgoingHttpHeaders)\n } catch {\n // invalid header name or value set by user code\n discardStream(reply.body instanceof ReadableStream ? reply.body : null)\n if (!response.headersSent) {\n for (const name of response.getHeaderNames()) response.removeHeader(name)\n response.statusCode = 500\n response.setHeader('content-type', 'application/json; charset=utf-8')\n response.end('{\"statusCode\":500,\"error\":\"Internal Server Error\"}')\n }\n return\n }\n const body = reply.body\n if (body === null) {\n response.end()\n return\n }\n // an event stream may stay quiet longer than a socket timeout (`server.timeout`, Bun's emulation)\n if (reply.eventStream === true && (response as { isLightMyRequest?: boolean }).isLightMyRequest !== true) {\n response.setTimeout(0)\n }\n if (body instanceof Uint8Array) {\n // a string is written with the headers at once (bytes take a second write)\n response.end(reply.text ?? body)\n return\n }\n const fail = (): void => {\n if (!response.destroyed) response.destroy()\n }\n try {\n const stream = body instanceof Blob ? body.stream() : body\n pipeline(Readable.fromWeb(stream as import('node:stream/web').ReadableStream), response).catch(fail)\n } catch {\n fail()\n }\n}\n\n/**\n * `headers` with the `set-cookie` lines already set on the native response (Express middleware\n * `res.cookie()`, Fastify hooks `reply.header('set-cookie', ...)`) before its own: `headers`\n * unchanged when either side has none.\n */\nexport function withNativeCookies(\n native: number | string | readonly string[] | undefined,\n headers: Readonly<Record<string, HeaderValue>>,\n): Readonly<Record<string, HeaderValue>> {\n const own = headers['set-cookie']\n if (own === undefined || native === undefined || typeof native === 'number') return headers\n const before = typeof native === 'string' ? [native] : native\n if (before.length === 0) return headers\n return { ...headers, 'set-cookie': [...before, ...(typeof own === 'string' ? [own] : own)] }\n}\n\n/** Last-resort 500 when a handler promise rejected (should not happen: the pipeline maps errors). */\nexport function writeNodeFailure(response: ServerResponse): void {\n if (response.headersSent) {\n if (!response.writableEnded) response.destroy()\n return\n }\n response.statusCode = 500\n response.setHeader('content-type', 'application/json; charset=utf-8')\n response.end('{\"statusCode\":500,\"error\":\"Internal Server Error\"}')\n}\n\n/** The tracker of a socket (see {@link ConnectionTracker}). */\nconst TRACKER = Symbol('znight.tracker')\n/** The number of requests in progress on a tracked socket. */\nconst ACTIVE = Symbol('znight.active')\n\ninterface TrackedSocket extends Socket {\n [TRACKER]?: ConnectionTracker\n [ACTIVE]?: number\n}\n\n/**\n * Tracks the connections of a `node:http` server to close them on shutdown: idle keep-alive\n * connections first (graceful), every connection when forced. `server.closeIdleConnections()` /\n * `closeAllConnections()` are not reliable on every runtime (Bun), so sockets are tracked here. The\n * count of requests in progress lives on the socket, and one shared `close` listener per response\n * decrements it (no closure, no map lookup per request).\n */\nexport class ConnectionTracker {\n readonly #sockets = new Set<TrackedSocket>()\n #closing = false\n\n /**\n * `requests: false` when the caller's own `request` listener calls {@link track} for every request\n * of the server (one listener less to call per request).\n */\n constructor(server: Server, options: { readonly requests?: boolean } = {}) {\n server.on('connection', (socket: TrackedSocket) => {\n socket[TRACKER] = this\n socket[ACTIVE] = 0\n this.#sockets.add(socket)\n socket.once('close', () => this.#sockets.delete(socket))\n })\n if (options.requests !== false) {\n server.on('request', (request: IncomingMessage, response: ServerResponse) => this.track(request, response))\n }\n }\n\n /** Counts a request in progress on its connection, until its response closes (other servers' requests are ignored). */\n track(request: IncomingMessage, response: ServerResponse): void {\n const socket = request.socket as TrackedSocket | null\n if (socket?.[TRACKER] !== this) return\n socket[ACTIVE] = (socket[ACTIVE] ?? 0) + 1\n response.on('close', ConnectionTracker.#onResponseClose)\n }\n\n /** A response closed (`this`): one request less on its socket, ended when idle while closing. */\n static readonly #onResponseClose = function (this: ServerResponse): void {\n // the socket of a finished response is detached: reach it through its request\n const socket = (this.req as IncomingMessage | undefined)?.socket as TrackedSocket | null | undefined\n const tracker = socket?.[TRACKER]\n if (socket == null || tracker === undefined) return\n const active = (socket[ACTIVE] ?? 1) - 1\n socket[ACTIVE] = active\n if (active === 0 && tracker.#closing) socket.end()\n }\n\n /** Ends idle connections now and the others once their requests completed. */\n closeIdle(): void {\n this.#closing = true\n for (const socket of this.#sockets) if (socket[ACTIVE] === 0) socket.end()\n }\n\n /** Destroys every connection. */\n destroyAll(): void {\n this.#closing = true\n for (const socket of this.#sockets) socket.destroy()\n }\n}\n\n/** Closes a `node:http` server: graceful (idle connections ended), then forced when asked. */\nexport function closeServer(\n server: Server,\n tracker: ConnectionTracker,\n closing: Promise<void> | undefined,\n force: boolean,\n): Promise<void> {\n const promise =\n closing ??\n new Promise<void>(resolve => {\n if (!server.listening) {\n resolve()\n return\n }\n server.close(() => resolve())\n server.closeIdleConnections?.()\n tracker.closeIdle()\n })\n if (force) {\n server.closeAllConnections?.()\n tracker.destroyAll()\n }\n return promise\n}\n"],"mappings":";;;;;AACA,MAAM,UAA4C;CAChD,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;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"}
package/dist/node.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as HttpAdapter } from "./adapter-CGSceVEN.mjs";
1
+ import { s as HttpAdapter } from "./adapter-J0UXFnNM.mjs";
2
2
  import { IncomingMessage, Server, ServerOptions, ServerResponse } from "node:http";
3
3
  /** Options of {@link nodeAdapter}. */
4
4
  export interface NodeAdapterOptions {
package/dist/node.mjs CHANGED
@@ -1 +1 @@
1
- export { t as nodeAdapter } from "./node-BUnkdSsa.mjs";
1
+ export { t as nodeAdapter } from "./node-DnYv_AMI.mjs";