@trpc/server 11.22.2-canary.15.a81bba207 → 11.22.2-canary.16.ea96ec538
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aws-lambda/index.cjs +1 -1
- package/dist/adapters/aws-lambda/index.mjs +1 -1
- package/dist/adapters/express.cjs +1 -1
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/index.cjs +3 -3
- package/dist/adapters/fastify/index.mjs +3 -3
- package/dist/adapters/fetch/index.cjs +1 -1
- package/dist/adapters/fetch/index.mjs +1 -1
- package/dist/adapters/next.cjs +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/index.cjs +1 -1
- package/dist/adapters/node-http/index.mjs +1 -1
- package/dist/adapters/standalone.cjs +1 -1
- package/dist/adapters/standalone.mjs +1 -1
- package/dist/adapters/ws.cjs +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/http.cjs +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{node-http-B5jkpWn7.mjs → node-http-ChhZEv1k.mjs} +2 -2
- package/dist/{node-http-B5jkpWn7.mjs.map → node-http-ChhZEv1k.mjs.map} +1 -1
- package/dist/{node-http-BZ0HlzkC.cjs → node-http-X8RiQEuH.cjs} +1 -1
- package/dist/{resolveResponse-b9D_SrLs.cjs → resolveResponse-CoGjFxK0.cjs} +8 -4
- package/dist/{resolveResponse-DH5L33sC.mjs → resolveResponse-DksrxZ2k.mjs} +9 -5
- package/dist/{resolveResponse-DH5L33sC.mjs.map → resolveResponse-DksrxZ2k.mjs.map} +1 -1
- package/dist/unstable-core-do-not-import.cjs +1 -1
- package/dist/unstable-core-do-not-import.mjs +1 -1
- package/dist/{ws-83TNWW-W.cjs → ws-7qWW7Uec.cjs} +2 -2
- package/dist/{ws-DJ2SSChC.mjs → ws-BYfo-HED.mjs} +3 -3
- package/dist/{ws-DJ2SSChC.mjs.map → ws-BYfo-HED.mjs.map} +1 -1
- package/package.json +2 -2
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +5 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_getErrorShape = require("../../getErrorShape-hncV8cPE.cjs");
|
|
3
|
-
const require_resolveResponse = require("../../resolveResponse-
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-CoGjFxK0.cjs");
|
|
4
4
|
let node_stream = require("node:stream");
|
|
5
5
|
let node_stream_promises = require("node:stream/promises");
|
|
6
6
|
//#region src/vendor/cookie-es/set-cookie/split.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as _objectSpread2 } from "../../getErrorShape-zlj81BiC.mjs";
|
|
2
|
-
import { t as resolveResponse } from "../../resolveResponse-
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-DksrxZ2k.mjs";
|
|
3
3
|
import { Readable } from "node:stream";
|
|
4
4
|
import { pipeline } from "node:stream/promises";
|
|
5
5
|
//#region src/vendor/cookie-es/set-cookie/split.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_codes = require("../codes-HK4UsP07.cjs");
|
|
3
3
|
const require_getErrorShape = require("../getErrorShape-hncV8cPE.cjs");
|
|
4
|
-
const require_node_http = require("../node-http-
|
|
4
|
+
const require_node_http = require("../node-http-X8RiQEuH.cjs");
|
|
5
5
|
//#region src/adapters/express.ts
|
|
6
6
|
function createExpressMiddleware(opts) {
|
|
7
7
|
return (req, res) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { m as run } from "../codes-C9N0z0an.mjs";
|
|
2
2
|
import { n as _objectSpread2 } from "../getErrorShape-zlj81BiC.mjs";
|
|
3
|
-
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-
|
|
3
|
+
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-ChhZEv1k.mjs";
|
|
4
4
|
//#region src/adapters/express.ts
|
|
5
5
|
function createExpressMiddleware(opts) {
|
|
6
6
|
return (req, res) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_getErrorShape = require("../../getErrorShape-hncV8cPE.cjs");
|
|
3
|
-
const require_resolveResponse = require("../../resolveResponse-
|
|
4
|
-
const require_node_http = require("../../node-http-
|
|
5
|
-
const require_ws = require("../../ws-
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-CoGjFxK0.cjs");
|
|
4
|
+
const require_node_http = require("../../node-http-X8RiQEuH.cjs");
|
|
5
|
+
const require_ws = require("../../ws-7qWW7Uec.cjs");
|
|
6
6
|
//#region src/adapters/fastify/fastifyRequestHandler.ts
|
|
7
7
|
async function fastifyRequestHandler(opts) {
|
|
8
8
|
const createContext = async (innerOpts) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as _objectSpread2 } from "../../getErrorShape-zlj81BiC.mjs";
|
|
2
|
-
import { t as resolveResponse } from "../../resolveResponse-
|
|
3
|
-
import { i as incomingMessageToRequest } from "../../node-http-
|
|
4
|
-
import { n as getWSConnectionHandler } from "../../ws-
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-DksrxZ2k.mjs";
|
|
3
|
+
import { i as incomingMessageToRequest } from "../../node-http-ChhZEv1k.mjs";
|
|
4
|
+
import { n as getWSConnectionHandler } from "../../ws-BYfo-HED.mjs";
|
|
5
5
|
//#region src/adapters/fastify/fastifyRequestHandler.ts
|
|
6
6
|
async function fastifyRequestHandler(opts) {
|
|
7
7
|
const createContext = async (innerOpts) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_getErrorShape = require("../../getErrorShape-hncV8cPE.cjs");
|
|
3
|
-
const require_resolveResponse = require("../../resolveResponse-
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-CoGjFxK0.cjs");
|
|
4
4
|
//#region src/adapters/fetch/fetchRequestHandler.ts
|
|
5
5
|
const trimSlashes = (path) => {
|
|
6
6
|
path = path.startsWith("/") ? path.slice(1) : path;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as _objectSpread2 } from "../../getErrorShape-zlj81BiC.mjs";
|
|
2
|
-
import { t as resolveResponse } from "../../resolveResponse-
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-DksrxZ2k.mjs";
|
|
3
3
|
//#region src/adapters/fetch/fetchRequestHandler.ts
|
|
4
4
|
const trimSlashes = (path) => {
|
|
5
5
|
path = path.startsWith("/") ? path.slice(1) : path;
|
package/dist/adapters/next.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_codes = require("../codes-HK4UsP07.cjs");
|
|
3
3
|
const require_getErrorShape = require("../getErrorShape-hncV8cPE.cjs");
|
|
4
4
|
const require_asyncGeneratorDelegate = require("../asyncGeneratorDelegate-Dj-8tGhf.cjs");
|
|
5
|
-
const require_node_http = require("../node-http-
|
|
5
|
+
const require_node_http = require("../node-http-X8RiQEuH.cjs");
|
|
6
6
|
//#region src/adapters/next.ts
|
|
7
7
|
function createNextApiHandler(opts) {
|
|
8
8
|
return async (req, res) => {
|
package/dist/adapters/next.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { m as run } from "../codes-C9N0z0an.mjs";
|
|
2
2
|
import { n as _objectSpread2 } from "../getErrorShape-zlj81BiC.mjs";
|
|
3
3
|
import { v as TRPCError } from "../asyncGeneratorDelegate-FcEJT04i.mjs";
|
|
4
|
-
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-
|
|
4
|
+
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-ChhZEv1k.mjs";
|
|
5
5
|
//#region src/adapters/next.ts
|
|
6
6
|
function createNextApiHandler(opts) {
|
|
7
7
|
return async (req, res) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_node_http = require("../../node-http-
|
|
2
|
+
const require_node_http = require("../../node-http-X8RiQEuH.cjs");
|
|
3
3
|
exports.createURL = require_node_http.createURL;
|
|
4
4
|
exports.incomingMessageToRequest = require_node_http.incomingMessageToRequest;
|
|
5
5
|
exports.internal_exceptionHandler = require_node_http.internal_exceptionHandler;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as incomingMessageToRequest, n as nodeHTTPRequestHandler, r as createURL, t as internal_exceptionHandler } from "../../node-http-
|
|
1
|
+
import { i as incomingMessageToRequest, n as nodeHTTPRequestHandler, r as createURL, t as internal_exceptionHandler } from "../../node-http-ChhZEv1k.mjs";
|
|
2
2
|
export { createURL, incomingMessageToRequest, internal_exceptionHandler, nodeHTTPRequestHandler };
|
|
3
3
|
|
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_rolldown_runtime = require("../rolldown-runtime-CFW-PwTP.cjs");
|
|
3
3
|
const require_codes = require("../codes-HK4UsP07.cjs");
|
|
4
4
|
const require_getErrorShape = require("../getErrorShape-hncV8cPE.cjs");
|
|
5
|
-
const require_node_http = require("../node-http-
|
|
5
|
+
const require_node_http = require("../node-http-X8RiQEuH.cjs");
|
|
6
6
|
let http = require("http");
|
|
7
7
|
http = require_rolldown_runtime.__toESM(http, 1);
|
|
8
8
|
//#region src/adapters/standalone.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { m as run } from "../codes-C9N0z0an.mjs";
|
|
2
2
|
import { n as _objectSpread2 } from "../getErrorShape-zlj81BiC.mjs";
|
|
3
|
-
import { n as nodeHTTPRequestHandler, r as createURL, t as internal_exceptionHandler } from "../node-http-
|
|
3
|
+
import { n as nodeHTTPRequestHandler, r as createURL, t as internal_exceptionHandler } from "../node-http-ChhZEv1k.mjs";
|
|
4
4
|
import http from "http";
|
|
5
5
|
//#region src/adapters/standalone.ts
|
|
6
6
|
/**
|
package/dist/adapters/ws.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_ws = require("../ws-
|
|
2
|
+
const require_ws = require("../ws-7qWW7Uec.cjs");
|
|
3
3
|
exports.applyWSSHandler = require_ws.applyWSSHandler;
|
|
4
4
|
exports.getWSConnectionHandler = require_ws.getWSConnectionHandler;
|
|
5
5
|
exports.handleKeepAlive = require_ws.handleKeepAlive;
|
package/dist/adapters/ws.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as jsonEncoder, n as getWSConnectionHandler, r as handleKeepAlive, t as applyWSSHandler } from "../ws-
|
|
1
|
+
import { i as jsonEncoder, n as getWSConnectionHandler, r as handleKeepAlive, t as applyWSSHandler } from "../ws-BYfo-HED.mjs";
|
|
2
2
|
export { applyWSSHandler, getWSConnectionHandler, handleKeepAlive, jsonEncoder };
|
|
3
3
|
|
package/dist/http.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_getErrorShape = require("./getErrorShape-hncV8cPE.cjs");
|
|
3
|
-
const require_resolveResponse = require("./resolveResponse-
|
|
3
|
+
const require_resolveResponse = require("./resolveResponse-CoGjFxK0.cjs");
|
|
4
4
|
const require_contentTypeParsers = require("./contentTypeParsers-B1e2ZNvN.cjs");
|
|
5
5
|
exports.getHTTPStatusCode = require_getErrorShape.getHTTPStatusCode;
|
|
6
6
|
exports.getHTTPStatusCodeFromError = require_getErrorShape.getHTTPStatusCodeFromError;
|
package/dist/http.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { d as getHTTPStatusCode, f as getHTTPStatusCodeFromError } from "./getErrorShape-zlj81BiC.mjs";
|
|
2
|
-
import { b as parseConnectionParamsFromString, t as resolveResponse, x as parseConnectionParamsFromUnknown } from "./resolveResponse-
|
|
2
|
+
import { b as parseConnectionParamsFromString, t as resolveResponse, x as parseConnectionParamsFromUnknown } from "./resolveResponse-DksrxZ2k.mjs";
|
|
3
3
|
import { t as octetInputParser } from "./contentTypeParsers-Bb-9hUEf.mjs";
|
|
4
4
|
export { getHTTPStatusCode, getHTTPStatusCodeFromError, octetInputParser, parseConnectionParamsFromString, parseConnectionParamsFromUnknown, resolveResponse };
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { m as run } from "./codes-C9N0z0an.mjs";
|
|
2
2
|
import { n as _objectSpread2, t as getErrorShape } from "./getErrorShape-zlj81BiC.mjs";
|
|
3
3
|
import { _ as transformTRPCResponse, b as getTRPCErrorFromUnknown, v as TRPCError } from "./asyncGeneratorDelegate-FcEJT04i.mjs";
|
|
4
|
-
import { h as isAbortError, t as resolveResponse } from "./resolveResponse-
|
|
4
|
+
import { h as isAbortError, t as resolveResponse } from "./resolveResponse-DksrxZ2k.mjs";
|
|
5
5
|
import { IncomingMessage } from "node:http";
|
|
6
6
|
//#region src/adapters/node-http/incomingMessageToRequest.ts
|
|
7
7
|
function createBody(req, opts) {
|
|
@@ -246,4 +246,4 @@ async function nodeHTTPRequestHandler(opts) {
|
|
|
246
246
|
export { incomingMessageToRequest as i, nodeHTTPRequestHandler as n, createURL as r, internal_exceptionHandler as t };
|
|
247
247
|
|
|
248
248
|
|
|
249
|
-
//# sourceMappingURL=node-http-
|
|
249
|
+
//# sourceMappingURL=node-http-ChhZEv1k.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-http-B5jkpWn7.mjs","names":[],"sources":["../src/adapters/node-http/incomingMessageToRequest.ts","../src/adapters/node-http/writeResponse.ts","../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"sourcesContent":["import type * as http from 'http';\nimport { IncomingMessage } from 'node:http';\nimport { TRPCError } from '../../@trpc/server';\nimport type { NodeHTTPRequest, NodeHTTPResponse } from './types';\n\nfunction createBody(\n req: NodeHTTPRequest,\n opts: {\n /**\n * Max body size in bytes. If the body is larger than this, the request will be aborted\n */\n maxBodySize: number | null;\n },\n): RequestInit['body'] {\n // Some adapters will pre-parse the body and add it to the request object\n if ('body' in req) {\n if (req.body !== undefined) {\n // If the body is already a string, return it directly\n if (typeof req.body === 'string') {\n return req.body;\n }\n // formData use\n if (req.body instanceof IncomingMessage) {\n return req.body as any;\n }\n // If body exists but isn't a string, stringify it as JSON\n return JSON.stringify(req.body);\n }\n if (req.readableEnded) {\n // The stream was consumed without producing a parsed body — there is\n // nothing left to read\n return undefined;\n }\n // The property was defined without the stream being read — e.g. express\n // 5's body-parser assigns `req.body = undefined` on content types it\n // skips (such as multipart/form-data) — so stream it like an unparsed\n // request\n } else if (req.readableEnded) {\n // Another middleware drained the stream without handing over what it\n // read, so waiting for `data`/`end` would hang forever\n return new ReadableStream({\n start(controller) {\n controller.error(\n new TRPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message:\n 'The request body has already been read by another middleware. Assign the parsed body to `req.body` so tRPC can use it',\n }),\n );\n },\n });\n }\n let size = 0;\n let hasClosed = false;\n\n return new ReadableStream({\n start(controller) {\n const onData = (chunk: Buffer) => {\n size += chunk.length;\n if (!opts.maxBodySize || size <= opts.maxBodySize) {\n controller.enqueue(\n new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength),\n );\n return;\n }\n controller.error(\n new TRPCError({\n code: 'PAYLOAD_TOO_LARGE',\n }),\n );\n hasClosed = true;\n req.off('data', onData);\n req.off('end', onEnd);\n };\n\n const onEnd = () => {\n if (hasClosed) {\n return;\n }\n hasClosed = true;\n req.off('data', onData);\n req.off('end', onEnd);\n controller.close();\n };\n\n req.on('data', onData);\n req.on('end', onEnd);\n },\n cancel() {\n req.destroy();\n },\n });\n}\nexport function createURL(req: NodeHTTPRequest): URL {\n try {\n const protocol =\n // http2\n (req.headers[':scheme'] && req.headers[':scheme'] === 'https') ||\n // http1\n (req.socket && 'encrypted' in req.socket && req.socket.encrypted)\n ? 'https:'\n : 'http:';\n\n const host = req.headers.host ?? req.headers[':authority'] ?? 'localhost';\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n return new URL(req.url!, `${protocol}//${host}`);\n } catch (cause) {\n throw new TRPCError({\n code: 'BAD_REQUEST',\n message: 'Invalid URL',\n cause,\n });\n }\n}\n\nfunction createHeaders(incoming: http.IncomingHttpHeaders): Headers {\n const headers = new Headers();\n\n for (const key in incoming) {\n const value = incoming[key];\n if (typeof key === 'string' && key.startsWith(':')) {\n // Skip HTTP/2 pseudo-headers\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n headers.append(key, item);\n }\n } else if (value != null) {\n headers.append(key, value);\n }\n }\n\n return headers;\n}\n\n/**\n * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)\n */\nexport function incomingMessageToRequest(\n req: NodeHTTPRequest,\n res: NodeHTTPResponse,\n opts: {\n /**\n * Max body size in bytes. If the body is larger than this, the request will be aborted\n */\n maxBodySize: number | null;\n },\n): Request {\n const ac = new AbortController();\n\n const onAbort = () => {\n res.off('close', onClose);\n req.off('aborted', onAbort);\n\n // abort the request\n ac.abort();\n };\n\n const onClose = () => {\n // `close` is also emitted after a response that was sent completely,\n // so only abort if the connection closed before the response was ended\n if (res.writableEnded) {\n req.off('aborted', onAbort);\n return;\n }\n onAbort();\n };\n\n res.once('close', onClose);\n req.once('aborted', onAbort);\n\n // Get host from either regular header or HTTP/2 pseudo-header\n const url = createURL(req);\n\n const init: RequestInit = {\n headers: createHeaders(req.headers),\n method: req.method,\n signal: ac.signal,\n };\n\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n init.body = createBody(req, opts);\n\n // init.duplex = 'half' must be set when body is a ReadableStream, and Node follows the spec.\n // However, this property is not defined in the TypeScript types for RequestInit, so we have\n // to cast it here in order to set it without a type error.\n // See https://fetch.spec.whatwg.org/#dom-requestinit-duplex\n // @ts-expect-error this is fine\n init.duplex = 'half';\n }\n\n const request = new Request(url, init);\n\n return request;\n}\n","// oxlint-disable-next-line no-restricted-imports\nimport { isAbortError } from '../../unstable-core-do-not-import';\nimport type { NodeHTTPResponse } from './types';\n\nasync function writeResponseBodyChunk(\n res: NodeHTTPResponse,\n chunk: Uint8Array,\n) {\n // useful for debugging 🙃\n // console.debug('writing', new TextDecoder().decode(chunk));\n\n if (res.write(chunk) === false) {\n await new Promise<void>((resolve, reject) => {\n const onError = (err: unknown) => {\n reject(err);\n cleanup();\n };\n const onDrain = () => {\n resolve();\n cleanup();\n };\n const cleanup = () => {\n res.off('error', onError);\n res.off('drain', onDrain);\n res.off('close', onDrain);\n };\n res.once('error', onError);\n res.once('drain', onDrain);\n res.once('close', onDrain);\n });\n }\n}\n/**\n * @internal\n */\n\nexport async function writeResponseBody(opts: {\n res: NodeHTTPResponse;\n signal: AbortSignal;\n body: NonNullable<Response['body']>;\n}) {\n const { res } = opts;\n\n try {\n const writableStream = new WritableStream({\n async write(chunk) {\n await writeResponseBodyChunk(res, chunk);\n res.flush?.();\n },\n });\n\n await opts.body.pipeTo(writableStream, {\n signal: opts.signal,\n });\n } catch (err) {\n if (isAbortError(err)) {\n return;\n }\n throw err;\n }\n}\n/**\n * @internal\n */\n\nexport async function writeResponse(opts: {\n request: Request;\n response: Response;\n rawResponse: NodeHTTPResponse;\n}) {\n const { response, rawResponse } = opts;\n\n // Only override status code if it hasn't been explicitly set in a procedure etc\n if (rawResponse.statusCode === 200) {\n rawResponse.statusCode = response.status;\n }\n for (const [key, value] of response.headers) {\n if (key.toLowerCase() === 'set-cookie') continue;\n rawResponse.setHeader(key, value);\n }\n const cookies = response.headers.getSetCookie();\n if (cookies.length > 0) {\n rawResponse.setHeader('set-cookie', cookies);\n }\n try {\n if (response.body) {\n await writeResponseBody({\n res: rawResponse,\n signal: opts.request.signal,\n body: response.body,\n });\n }\n } catch (err) {\n if (!rawResponse.headersSent) {\n rawResponse.statusCode = 500;\n }\n throw err;\n } finally {\n rawResponse.end();\n }\n}\n","/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\n\n// @trpc/server\n\nimport {\n getTRPCErrorFromUnknown,\n transformTRPCResponse,\n type AnyRouter,\n} from '../../@trpc/server';\nimport type { ResolveHTTPRequestOptionsContextFn } from '../../@trpc/server/http';\nimport { resolveResponse } from '../../@trpc/server/http';\n// oxlint-disable-next-line no-restricted-imports\nimport { getErrorShape, run } from '../../unstable-core-do-not-import';\nimport { incomingMessageToRequest } from './incomingMessageToRequest';\nimport type {\n NodeHTTPRequest,\n NodeHTTPRequestHandlerOptions,\n NodeHTTPResponse,\n} from './types';\nimport { writeResponse } from './writeResponse';\n\n/**\n * @internal\n */\nexport function internal_exceptionHandler<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>) {\n return (cause: unknown) => {\n const { res, req } = opts;\n const error = getTRPCErrorFromUnknown(cause);\n\n const shape = getErrorShape({\n config: opts.router._def._config,\n error,\n type: 'unknown',\n path: undefined,\n input: undefined,\n ctx: undefined,\n });\n\n opts.onError?.({\n req,\n error,\n type: 'unknown',\n path: undefined,\n input: undefined,\n ctx: undefined,\n });\n\n const transformed = transformTRPCResponse(opts.router._def._config, {\n error: shape,\n });\n\n res.statusCode = shape.data.httpStatus;\n res.end(JSON.stringify(transformed));\n };\n}\n\n/**\n * @remark the promise never rejects\n */\nexport async function nodeHTTPRequestHandler<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>) {\n return new Promise<void>((resolve) => {\n const handleViaMiddleware =\n opts.middleware ?? ((_req, _res, next) => next());\n\n opts.res.once('finish', () => {\n resolve();\n });\n return handleViaMiddleware(opts.req, opts.res, (err: unknown) => {\n run(async () => {\n const request = incomingMessageToRequest(opts.req, opts.res, {\n maxBodySize: opts.maxBodySize ?? null,\n });\n\n // Build tRPC dependencies\n const createContext: ResolveHTTPRequestOptionsContextFn<\n TRouter\n > = async (innerOpts) => {\n return await opts.createContext?.({\n ...opts,\n ...innerOpts,\n });\n };\n\n const response = await resolveResponse({\n ...opts,\n req: request,\n error: err ? getTRPCErrorFromUnknown(err) : null,\n createContext,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: opts.req,\n });\n },\n });\n\n await writeResponse({\n request,\n response,\n rawResponse: opts.res,\n });\n }).catch(internal_exceptionHandler(opts));\n });\n });\n}\n"],"mappings":";;;;;;AAKA,SAAS,WACP,KACA,MAMqB;CAErB,IAAI,UAAU,KAAK;EACjB,IAAI,IAAI,SAAS,KAAA,GAAW;GAE1B,IAAI,OAAO,IAAI,SAAS,UACtB,OAAO,IAAI;GAGb,IAAI,IAAI,gBAAgB,iBACtB,OAAO,IAAI;GAGb,OAAO,KAAK,UAAU,IAAI,IAAI;EAChC;EACA,IAAI,IAAI,eAGN;CAMJ,OAAO,IAAI,IAAI,eAGb,OAAO,IAAI,eAAe,EACxB,MAAM,YAAY;EAChB,WAAW,MACT,IAAI,UAAU;GACZ,MAAM;GACN,SACE;EACJ,CAAC,CACH;CACF,EACF,CAAC;CAEH,IAAI,OAAO;CACX,IAAI,YAAY;CAEhB,OAAO,IAAI,eAAe;EACxB,MAAM,YAAY;GAChB,MAAM,UAAU,UAAkB;IAChC,QAAQ,MAAM;IACd,IAAI,CAAC,KAAK,eAAe,QAAQ,KAAK,aAAa;KACjD,WAAW,QACT,IAAI,WAA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/incomingMessageToRequest.ts","../src/adapters/node-http/writeResponse.ts","../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"sourcesContent":["import type * as http from 'http';\nimport { IncomingMessage } from 'node:http';\nimport { TRPCError } from '../../@trpc/server';\nimport type { NodeHTTPRequest, NodeHTTPResponse } from './types';\n\nfunction createBody(\n req: NodeHTTPRequest,\n opts: {\n /**\n * Max body size in bytes. If the body is larger than this, the request will be aborted\n */\n maxBodySize: number | null;\n },\n): RequestInit['body'] {\n // Some adapters will pre-parse the body and add it to the request object\n if ('body' in req) {\n if (req.body !== undefined) {\n // If the body is already a string, return it directly\n if (typeof req.body === 'string') {\n return req.body;\n }\n // formData use\n if (req.body instanceof IncomingMessage) {\n return req.body as any;\n }\n // If body exists but isn't a string, stringify it as JSON\n return JSON.stringify(req.body);\n }\n if (req.readableEnded) {\n // The stream was consumed without producing a parsed body — there is\n // nothing left to read\n return undefined;\n }\n // The property was defined without the stream being read — e.g. express\n // 5's body-parser assigns `req.body = undefined` on content types it\n // skips (such as multipart/form-data) — so stream it like an unparsed\n // request\n } else if (req.readableEnded) {\n // Another middleware drained the stream without handing over what it\n // read, so waiting for `data`/`end` would hang forever\n return new ReadableStream({\n start(controller) {\n controller.error(\n new TRPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message:\n 'The request body has already been read by another middleware. Assign the parsed body to `req.body` so tRPC can use it',\n }),\n );\n },\n });\n }\n let size = 0;\n let hasClosed = false;\n\n return new ReadableStream({\n start(controller) {\n const onData = (chunk: Buffer) => {\n size += chunk.length;\n if (!opts.maxBodySize || size <= opts.maxBodySize) {\n controller.enqueue(\n new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength),\n );\n return;\n }\n controller.error(\n new TRPCError({\n code: 'PAYLOAD_TOO_LARGE',\n }),\n );\n hasClosed = true;\n req.off('data', onData);\n req.off('end', onEnd);\n };\n\n const onEnd = () => {\n if (hasClosed) {\n return;\n }\n hasClosed = true;\n req.off('data', onData);\n req.off('end', onEnd);\n controller.close();\n };\n\n req.on('data', onData);\n req.on('end', onEnd);\n },\n cancel() {\n req.destroy();\n },\n });\n}\nexport function createURL(req: NodeHTTPRequest): URL {\n try {\n const protocol =\n // http2\n (req.headers[':scheme'] && req.headers[':scheme'] === 'https') ||\n // http1\n (req.socket && 'encrypted' in req.socket && req.socket.encrypted)\n ? 'https:'\n : 'http:';\n\n const host = req.headers.host ?? req.headers[':authority'] ?? 'localhost';\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n return new URL(req.url!, `${protocol}//${host}`);\n } catch (cause) {\n throw new TRPCError({\n code: 'BAD_REQUEST',\n message: 'Invalid URL',\n cause,\n });\n }\n}\n\nfunction createHeaders(incoming: http.IncomingHttpHeaders): Headers {\n const headers = new Headers();\n\n for (const key in incoming) {\n const value = incoming[key];\n if (typeof key === 'string' && key.startsWith(':')) {\n // Skip HTTP/2 pseudo-headers\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n headers.append(key, item);\n }\n } else if (value != null) {\n headers.append(key, value);\n }\n }\n\n return headers;\n}\n\n/**\n * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)\n */\nexport function incomingMessageToRequest(\n req: NodeHTTPRequest,\n res: NodeHTTPResponse,\n opts: {\n /**\n * Max body size in bytes. If the body is larger than this, the request will be aborted\n */\n maxBodySize: number | null;\n },\n): Request {\n const ac = new AbortController();\n\n const onAbort = () => {\n res.off('close', onClose);\n req.off('aborted', onAbort);\n\n // abort the request\n ac.abort();\n };\n\n const onClose = () => {\n // `close` is also emitted after a response that was sent completely,\n // so only abort if the connection closed before the response was ended\n if (res.writableEnded) {\n req.off('aborted', onAbort);\n return;\n }\n onAbort();\n };\n\n res.once('close', onClose);\n req.once('aborted', onAbort);\n\n // Get host from either regular header or HTTP/2 pseudo-header\n const url = createURL(req);\n\n const init: RequestInit = {\n headers: createHeaders(req.headers),\n method: req.method,\n signal: ac.signal,\n };\n\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n init.body = createBody(req, opts);\n\n // init.duplex = 'half' must be set when body is a ReadableStream, and Node follows the spec.\n // However, this property is not defined in the TypeScript types for RequestInit, so we have\n // to cast it here in order to set it without a type error.\n // See https://fetch.spec.whatwg.org/#dom-requestinit-duplex\n // @ts-expect-error this is fine\n init.duplex = 'half';\n }\n\n const request = new Request(url, init);\n\n return request;\n}\n","// oxlint-disable-next-line no-restricted-imports\nimport { isAbortError } from '../../unstable-core-do-not-import';\nimport type { NodeHTTPResponse } from './types';\n\nasync function writeResponseBodyChunk(\n res: NodeHTTPResponse,\n chunk: Uint8Array,\n) {\n // useful for debugging 🙃\n // console.debug('writing', new TextDecoder().decode(chunk));\n\n if (res.write(chunk) === false) {\n await new Promise<void>((resolve, reject) => {\n const onError = (err: unknown) => {\n reject(err);\n cleanup();\n };\n const onDrain = () => {\n resolve();\n cleanup();\n };\n const cleanup = () => {\n res.off('error', onError);\n res.off('drain', onDrain);\n res.off('close', onDrain);\n };\n res.once('error', onError);\n res.once('drain', onDrain);\n res.once('close', onDrain);\n });\n }\n}\n/**\n * @internal\n */\n\nexport async function writeResponseBody(opts: {\n res: NodeHTTPResponse;\n signal: AbortSignal;\n body: NonNullable<Response['body']>;\n}) {\n const { res } = opts;\n\n try {\n const writableStream = new WritableStream({\n async write(chunk) {\n await writeResponseBodyChunk(res, chunk);\n res.flush?.();\n },\n });\n\n await opts.body.pipeTo(writableStream, {\n signal: opts.signal,\n });\n } catch (err) {\n if (isAbortError(err)) {\n return;\n }\n throw err;\n }\n}\n/**\n * @internal\n */\n\nexport async function writeResponse(opts: {\n request: Request;\n response: Response;\n rawResponse: NodeHTTPResponse;\n}) {\n const { response, rawResponse } = opts;\n\n // Only override status code if it hasn't been explicitly set in a procedure etc\n if (rawResponse.statusCode === 200) {\n rawResponse.statusCode = response.status;\n }\n for (const [key, value] of response.headers) {\n if (key.toLowerCase() === 'set-cookie') continue;\n rawResponse.setHeader(key, value);\n }\n const cookies = response.headers.getSetCookie();\n if (cookies.length > 0) {\n rawResponse.setHeader('set-cookie', cookies);\n }\n try {\n if (response.body) {\n await writeResponseBody({\n res: rawResponse,\n signal: opts.request.signal,\n body: response.body,\n });\n }\n } catch (err) {\n if (!rawResponse.headersSent) {\n rawResponse.statusCode = 500;\n }\n throw err;\n } finally {\n rawResponse.end();\n }\n}\n","/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\n\n// @trpc/server\n\nimport {\n getTRPCErrorFromUnknown,\n transformTRPCResponse,\n type AnyRouter,\n} from '../../@trpc/server';\nimport type { ResolveHTTPRequestOptionsContextFn } from '../../@trpc/server/http';\nimport { resolveResponse } from '../../@trpc/server/http';\n// oxlint-disable-next-line no-restricted-imports\nimport { getErrorShape, run } from '../../unstable-core-do-not-import';\nimport { incomingMessageToRequest } from './incomingMessageToRequest';\nimport type {\n NodeHTTPRequest,\n NodeHTTPRequestHandlerOptions,\n NodeHTTPResponse,\n} from './types';\nimport { writeResponse } from './writeResponse';\n\n/**\n * @internal\n */\nexport function internal_exceptionHandler<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>) {\n return (cause: unknown) => {\n const { res, req } = opts;\n const error = getTRPCErrorFromUnknown(cause);\n\n const shape = getErrorShape({\n config: opts.router._def._config,\n error,\n type: 'unknown',\n path: undefined,\n input: undefined,\n ctx: undefined,\n });\n\n opts.onError?.({\n req,\n error,\n type: 'unknown',\n path: undefined,\n input: undefined,\n ctx: undefined,\n });\n\n const transformed = transformTRPCResponse(opts.router._def._config, {\n error: shape,\n });\n\n res.statusCode = shape.data.httpStatus;\n res.end(JSON.stringify(transformed));\n };\n}\n\n/**\n * @remark the promise never rejects\n */\nexport async function nodeHTTPRequestHandler<\n TRouter extends AnyRouter,\n TRequest extends NodeHTTPRequest,\n TResponse extends NodeHTTPResponse,\n>(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>) {\n return new Promise<void>((resolve) => {\n const handleViaMiddleware =\n opts.middleware ?? ((_req, _res, next) => next());\n\n opts.res.once('finish', () => {\n resolve();\n });\n return handleViaMiddleware(opts.req, opts.res, (err: unknown) => {\n run(async () => {\n const request = incomingMessageToRequest(opts.req, opts.res, {\n maxBodySize: opts.maxBodySize ?? null,\n });\n\n // Build tRPC dependencies\n const createContext: ResolveHTTPRequestOptionsContextFn<\n TRouter\n > = async (innerOpts) => {\n return await opts.createContext?.({\n ...opts,\n ...innerOpts,\n });\n };\n\n const response = await resolveResponse({\n ...opts,\n req: request,\n error: err ? getTRPCErrorFromUnknown(err) : null,\n createContext,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: opts.req,\n });\n },\n });\n\n await writeResponse({\n request,\n response,\n rawResponse: opts.res,\n });\n }).catch(internal_exceptionHandler(opts));\n });\n });\n}\n"],"mappings":";;;;;;AAKA,SAAS,WACP,KACA,MAMqB;CAErB,IAAI,UAAU,KAAK;EACjB,IAAI,IAAI,SAAS,KAAA,GAAW;GAE1B,IAAI,OAAO,IAAI,SAAS,UACtB,OAAO,IAAI;GAGb,IAAI,IAAI,gBAAgB,iBACtB,OAAO,IAAI;GAGb,OAAO,KAAK,UAAU,IAAI,IAAI;EAChC;EACA,IAAI,IAAI,eAGN;CAMJ,OAAO,IAAI,IAAI,eAGb,OAAO,IAAI,eAAe,EACxB,MAAM,YAAY;EAChB,WAAW,MACT,IAAI,UAAU;GACZ,MAAM;GACN,SACE;EACJ,CAAC,CACH;CACF,EACF,CAAC;CAEH,IAAI,OAAO;CACX,IAAI,YAAY;CAEhB,OAAO,IAAI,eAAe;EACxB,MAAM,YAAY;GAChB,MAAM,UAAU,UAAkB;IAChC,QAAQ,M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AAC;AACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_codes = require("./codes-HK4UsP07.cjs");
|
|
2
2
|
const require_getErrorShape = require("./getErrorShape-hncV8cPE.cjs");
|
|
3
3
|
const require_asyncGeneratorDelegate = require("./asyncGeneratorDelegate-Dj-8tGhf.cjs");
|
|
4
|
-
const require_resolveResponse = require("./resolveResponse-
|
|
4
|
+
const require_resolveResponse = require("./resolveResponse-CoGjFxK0.cjs");
|
|
5
5
|
let node_http = require("node:http");
|
|
6
6
|
//#region src/adapters/node-http/incomingMessageToRequest.ts
|
|
7
7
|
function createBody(req, opts) {
|
|
@@ -1782,10 +1782,14 @@ async function resolveResponse(opts) {
|
|
|
1782
1782
|
code: "NOT_FOUND",
|
|
1783
1783
|
message: `No procedure found on path "${call.path}"`
|
|
1784
1784
|
});
|
|
1785
|
-
if (!methodMapper[proc._def.type].includes(req.method))
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1785
|
+
if (!methodMapper[proc._def.type].includes(req.method)) {
|
|
1786
|
+
const accepted = opts.allowMethodOverride ? TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE : TYPE_ACCEPTED_METHOD_MAP;
|
|
1787
|
+
headers.set("allow", accepted[proc._def.type].join(", "));
|
|
1788
|
+
throw new require_asyncGeneratorDelegate.TRPCError({
|
|
1789
|
+
code: "METHOD_NOT_SUPPORTED",
|
|
1790
|
+
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1789
1793
|
if (proc._def.type === "subscription") {
|
|
1790
1794
|
/* istanbul ignore if -- @preserve */
|
|
1791
1795
|
if (info.isBatchCall) throw new require_asyncGeneratorDelegate.TRPCError({
|
|
@@ -1782,10 +1782,14 @@ async function resolveResponse(opts) {
|
|
|
1782
1782
|
code: "NOT_FOUND",
|
|
1783
1783
|
message: `No procedure found on path "${call.path}"`
|
|
1784
1784
|
});
|
|
1785
|
-
if (!methodMapper[proc._def.type].includes(req.method))
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1785
|
+
if (!methodMapper[proc._def.type].includes(req.method)) {
|
|
1786
|
+
const accepted = opts.allowMethodOverride ? TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE : TYPE_ACCEPTED_METHOD_MAP;
|
|
1787
|
+
headers.set("allow", accepted[proc._def.type].join(", "));
|
|
1788
|
+
throw new TRPCError({
|
|
1789
|
+
code: "METHOD_NOT_SUPPORTED",
|
|
1790
|
+
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1789
1793
|
if (proc._def.type === "subscription") {
|
|
1790
1794
|
/* istanbul ignore if -- @preserve */
|
|
1791
1795
|
if (info.isBatchCall) throw new TRPCError({
|
|
@@ -2099,4 +2103,4 @@ async function resolveResponse(opts) {
|
|
|
2099
2103
|
export { getAcceptHeader as _, isPromise as a, parseConnectionParamsFromString as b, createDeferred as c, _usingCtx as d, makeAsyncResource as f, throwAbortError as g, isAbortError as h, sseStreamProducer as i, iteratorResource as l, Unpromise as m, sseHeaders as n, jsonlStreamConsumer as o, makeResource as p, sseStreamConsumer as r, jsonlStreamProducer as s, resolveResponse as t, takeWithGrace as u, getLastEventId as v, parseConnectionParamsFromUnknown as x, getRequestInfo as y };
|
|
2100
2104
|
|
|
2101
2105
|
|
|
2102
|
-
//# sourceMappingURL=resolveResponse-
|
|
2106
|
+
//# sourceMappingURL=resolveResponse-DksrxZ2k.mjs.map
|