@trpc/server 11.0.0-rc.621 → 11.0.0-rc.632
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/@trpc/server/http.d.ts +1 -1
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.js +2 -2
- package/dist/adapters/aws-lambda/getPlanner.mjs +2 -2
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/index.mjs +2 -0
- package/dist/adapters/express.js +2 -0
- package/dist/adapters/express.mjs +2 -0
- package/dist/adapters/fastify/fastifyRequestHandler.js +3 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +3 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +8 -6
- package/dist/adapters/fetch/fetchRequestHandler.mjs +8 -6
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +6 -4
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +6 -4
- package/dist/adapters/next-app-dir/notFound.js +2 -0
- package/dist/adapters/next-app-dir/notFound.mjs +2 -0
- package/dist/adapters/next-app-dir/redirect.js +4 -1
- package/dist/adapters/next-app-dir/redirect.mjs +4 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +1 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +1 -1
- package/dist/adapters/next.js +2 -0
- package/dist/adapters/next.mjs +2 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +8 -5
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +8 -5
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +11 -43
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +11 -43
- package/dist/adapters/node-http/writeResponse.d.ts +18 -0
- package/dist/adapters/node-http/writeResponse.d.ts.map +1 -0
- package/dist/adapters/node-http/writeResponse.js +85 -0
- package/dist/adapters/node-http/writeResponse.mjs +82 -0
- package/dist/adapters/standalone.js +2 -0
- package/dist/adapters/standalone.mjs +2 -0
- package/dist/adapters/ws.js +11 -10
- package/dist/adapters/ws.mjs +11 -10
- package/dist/bundle-analysis.json +230 -186
- package/dist/http.js +2 -2
- package/dist/http.mjs +2 -1
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +11 -0
- package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +9 -0
- package/dist/observable/observable.js +1 -1
- package/dist/observable/observable.mjs +1 -1
- package/dist/rpc.js +2 -0
- package/dist/rpc.mjs +2 -0
- package/dist/shared.js +2 -0
- package/dist/shared.mjs +2 -0
- package/dist/unstable-core-do-not-import/createProxy.js +1 -1
- package/dist/unstable-core-do-not-import/createProxy.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +4 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +4 -1
- package/dist/unstable-core-do-not-import/error/formatter.js +1 -1
- package/dist/unstable-core-do-not-import/error/formatter.mjs +1 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +2 -2
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +2 -2
- package/dist/unstable-core-do-not-import/http/contentType.js +3 -3
- package/dist/unstable-core-do-not-import/http/contentType.mjs +3 -3
- package/dist/unstable-core-do-not-import/http/isAbortError.d.ts +4 -0
- package/dist/unstable-core-do-not-import/http/isAbortError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/isAbortError.js +9 -0
- package/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +24 -24
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +24 -24
- package/dist/unstable-core-do-not-import/middleware.js +1 -1
- package/dist/unstable-core-do-not-import/middleware.mjs +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -1
- package/dist/unstable-core-do-not-import/router.js +2 -2
- package/dist/unstable-core-do-not-import/router.mjs +2 -2
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +2 -2
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +2 -2
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +6 -9
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +86 -136
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +87 -137
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +27 -23
- package/dist/unstable-core-do-not-import/stream/sse.mjs +28 -24
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +10 -10
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +47 -34
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +47 -34
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +0 -4
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +0 -11
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +1 -11
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts +6 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js +28 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs +25 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +17 -17
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +17 -17
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.js +59 -0
- package/dist/unstable-core-do-not-import/stream/utils/withRefCount.mjs +57 -0
- package/dist/unstable-core-do-not-import.d.ts +2 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +2 -2
- package/dist/unstable-core-do-not-import.mjs +1 -1
- package/dist/vendor/unpromise/unpromise.js +21 -16
- package/dist/vendor/unpromise/unpromise.mjs +21 -16
- package/package.json +12 -5
- package/src/@trpc/server/http.ts +0 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +8 -4
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +8 -46
- package/src/adapters/node-http/writeResponse.ts +96 -0
- package/src/unstable-core-do-not-import/http/isAbortError.ts +7 -0
- package/src/unstable-core-do-not-import/stream/jsonl.ts +85 -154
- package/src/unstable-core-do-not-import/stream/sse.ts +24 -25
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +58 -37
- package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +0 -13
- package/src/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.ts +27 -0
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +31 -19
- package/src/unstable-core-do-not-import/stream/utils/withRefCount.ts +93 -0
- package/src/unstable-core-do-not-import.ts +2 -2
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +0 -32
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts +0 -8
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.js +0 -38
- package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.mjs +0 -36
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/stream/utils/promiseTimer.ts +0 -40
|
@@ -4,5 +4,5 @@ export type { BaseHandlerOptions, HTTPBaseHandlerOptions, HTTPErrorHandler,
|
|
|
4
4
|
* @deprecated Use `HTTPErrorHandler` instead
|
|
5
5
|
*/
|
|
6
6
|
HTTPErrorHandler as OnErrorFunction, ResolveHTTPRequestOptionsContextFn, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, } from '../../unstable-core-do-not-import';
|
|
7
|
-
export {
|
|
7
|
+
export { octetInputParser, parseConnectionParamsFromUnknown, parseConnectionParamsFromString, } from '../../unstable-core-do-not-import';
|
|
8
8
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB;AAChB;;GAEG;AACH,gBAAgB,IAAI,eAAe,EACnC,kCAAkC,EAClC,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAC3C,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB;AAChB;;GAEG;AACH,gBAAgB,IAAI,eAAe,EACnC,kCAAkC,EAClC,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,gBAAgB,EAChB,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,mCAAmC,CAAC"}
|
|
@@ -68,7 +68,7 @@ const v1Processor = {
|
|
|
68
68
|
},
|
|
69
69
|
getMethod: (event)=>event.httpMethod,
|
|
70
70
|
toResult: async (response)=>{
|
|
71
|
-
const { headers
|
|
71
|
+
const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
|
|
72
72
|
const result = {
|
|
73
73
|
...cookies.length && {
|
|
74
74
|
multiValueHeaders: {
|
|
@@ -115,7 +115,7 @@ const v2Processor = {
|
|
|
115
115
|
},
|
|
116
116
|
getMethod: (event)=>event.requestContext.http.method,
|
|
117
117
|
toResult: async (response)=>{
|
|
118
|
-
const { headers
|
|
118
|
+
const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
|
|
119
119
|
const result = {
|
|
120
120
|
cookies,
|
|
121
121
|
statusCode: response.status,
|
|
@@ -66,7 +66,7 @@ const v1Processor = {
|
|
|
66
66
|
},
|
|
67
67
|
getMethod: (event)=>event.httpMethod,
|
|
68
68
|
toResult: async (response)=>{
|
|
69
|
-
const { headers
|
|
69
|
+
const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
|
|
70
70
|
const result = {
|
|
71
71
|
...cookies.length && {
|
|
72
72
|
multiValueHeaders: {
|
|
@@ -113,7 +113,7 @@ const v2Processor = {
|
|
|
113
113
|
},
|
|
114
114
|
getMethod: (event)=>event.requestContext.http.method,
|
|
115
115
|
toResult: async (response)=>{
|
|
116
|
-
const { headers
|
|
116
|
+
const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
|
|
117
117
|
const result = {
|
|
118
118
|
cookies,
|
|
119
119
|
statusCode: response.status,
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
|
|
4
4
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
5
7
|
var getPlanner = require('./getPlanner.js');
|
|
6
8
|
|
|
7
9
|
function awsLambdaRequestHandler(opts) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
|
|
2
2
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
3
5
|
import { getPlanner } from './getPlanner.mjs';
|
|
4
6
|
|
|
5
7
|
function awsLambdaRequestHandler(opts) {
|
package/dist/adapters/express.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var utils = require('../unstable-core-do-not-import/utils.js');
|
|
4
|
+
require('../vendor/unpromise/unpromise.js');
|
|
5
|
+
require('../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
4
6
|
require('../unstable-core-do-not-import/rootConfig.js');
|
|
5
7
|
var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
|
|
6
8
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { run } from '../unstable-core-do-not-import/utils.mjs';
|
|
2
|
+
import '../vendor/unpromise/unpromise.mjs';
|
|
3
|
+
import '../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
2
4
|
import '../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
5
|
import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
|
|
4
6
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
|
|
4
4
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
5
7
|
var incomingMessageToRequest = require('../node-http/incomingMessageToRequest.js');
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -25,7 +27,7 @@ async function fastifyRequestHandler(opts) {
|
|
|
25
27
|
if ('body' in opts.req) {
|
|
26
28
|
incomingMessage.body = opts.req.body;
|
|
27
29
|
}
|
|
28
|
-
const req = incomingMessageToRequest.incomingMessageToRequest(incomingMessage, {
|
|
30
|
+
const req = incomingMessageToRequest.incomingMessageToRequest(incomingMessage, opts.res.raw, {
|
|
29
31
|
maxBodySize: null
|
|
30
32
|
});
|
|
31
33
|
const res = await resolveResponse.resolveResponse({
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
|
|
2
2
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
3
5
|
import { incomingMessageToRequest } from '../node-http/incomingMessageToRequest.mjs';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -23,7 +25,7 @@ async function fastifyRequestHandler(opts) {
|
|
|
23
25
|
if ('body' in opts.req) {
|
|
24
26
|
incomingMessage.body = opts.req.body;
|
|
25
27
|
}
|
|
26
|
-
const req = incomingMessageToRequest(incomingMessage, {
|
|
28
|
+
const req = incomingMessageToRequest(incomingMessage, opts.res.raw, {
|
|
27
29
|
maxBodySize: null
|
|
28
30
|
});
|
|
29
31
|
const res = await resolveResponse({
|
|
@@ -45,7 +45,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
45
45
|
}, async (socket, req)=>{
|
|
46
46
|
await onConnection(socket, req.raw);
|
|
47
47
|
if (trpcOptions?.keepAlive?.enabled) {
|
|
48
|
-
const { pingMs
|
|
48
|
+
const { pingMs, pongWaitMs } = trpcOptions.keepAlive;
|
|
49
49
|
ws.handleKeepAlive(socket, pingMs, pongWaitMs);
|
|
50
50
|
}
|
|
51
51
|
});
|
|
@@ -43,7 +43,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
43
43
|
}, async (socket, req)=>{
|
|
44
44
|
await onConnection(socket, req.raw);
|
|
45
45
|
if (trpcOptions?.keepAlive?.enabled) {
|
|
46
|
-
const { pingMs
|
|
46
|
+
const { pingMs, pongWaitMs } = trpcOptions.keepAlive;
|
|
47
47
|
handleKeepAlive(socket, pingMs, pongWaitMs);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
|
|
4
4
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* 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`
|
|
@@ -52,13 +54,13 @@ async function fetchRequestHandler(opts) {
|
|
|
52
54
|
} else {
|
|
53
55
|
/**
|
|
54
56
|
* @deprecated, delete in v12
|
|
55
|
-
*/ for (const [
|
|
56
|
-
if (Array.isArray(
|
|
57
|
-
for (const v of
|
|
58
|
-
resHeaders.append(
|
|
57
|
+
*/ for (const [key, value] of Object.entries(meta.headers)){
|
|
58
|
+
if (Array.isArray(value)) {
|
|
59
|
+
for (const v of value){
|
|
60
|
+
resHeaders.append(key, v);
|
|
59
61
|
}
|
|
60
|
-
} else if (typeof
|
|
61
|
-
resHeaders.set(
|
|
62
|
+
} else if (typeof value === 'string') {
|
|
63
|
+
resHeaders.set(key, value);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
|
|
2
2
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* 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`
|
|
@@ -50,13 +52,13 @@ async function fetchRequestHandler(opts) {
|
|
|
50
52
|
} else {
|
|
51
53
|
/**
|
|
52
54
|
* @deprecated, delete in v12
|
|
53
|
-
*/ for (const [
|
|
54
|
-
if (Array.isArray(
|
|
55
|
-
for (const v of
|
|
56
|
-
resHeaders.append(
|
|
55
|
+
*/ for (const [key, value] of Object.entries(meta.headers)){
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
for (const v of value){
|
|
58
|
+
resHeaders.append(key, v);
|
|
57
59
|
}
|
|
58
|
-
} else if (typeof
|
|
59
|
-
resHeaders.set(
|
|
60
|
+
} else if (typeof value === 'string') {
|
|
61
|
+
resHeaders.set(key, value);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
4
|
var formDataToObject = require('../../unstable-core-do-not-import/http/formDataToObject.js');
|
|
5
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
5
7
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
6
8
|
var redirect = require('./redirect.js');
|
|
7
9
|
var rethrowNextErrors = require('./rethrowNextErrors.js');
|
|
@@ -9,7 +11,7 @@ var rethrowNextErrors = require('./rethrowNextErrors.js');
|
|
|
9
11
|
/**
|
|
10
12
|
* Create a caller that works with Next.js React Server Components & Server Actions
|
|
11
13
|
*/ function nextAppDirCaller(config) {
|
|
12
|
-
const { normalizeFormData =true
|
|
14
|
+
const { normalizeFormData = true } = config;
|
|
13
15
|
const createContext = async ()=>{
|
|
14
16
|
return config?.createContext?.() ?? {};
|
|
15
17
|
};
|
|
@@ -63,13 +65,13 @@ var rethrowNextErrors = require('./rethrowNextErrors.js');
|
|
|
63
65
|
}
|
|
64
66
|
case 'query':
|
|
65
67
|
{
|
|
66
|
-
const
|
|
68
|
+
const input = opts.args[0];
|
|
67
69
|
return await opts.invoke({
|
|
68
70
|
type: opts._def.type,
|
|
69
71
|
ctx,
|
|
70
|
-
getRawInput: async ()=>
|
|
72
|
+
getRawInput: async ()=>input,
|
|
71
73
|
path,
|
|
72
|
-
input
|
|
74
|
+
input,
|
|
73
75
|
signal: undefined
|
|
74
76
|
}).then((data)=>{
|
|
75
77
|
if (data instanceof redirect.TRPCRedirectError) throw data;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { TRPCError, getTRPCErrorFromUnknown } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
2
|
import { formDataToObject } from '../../unstable-core-do-not-import/http/formDataToObject.mjs';
|
|
3
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
3
5
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
4
6
|
import { TRPCRedirectError } from './redirect.mjs';
|
|
5
7
|
import { rethrowNextErrors } from './rethrowNextErrors.mjs';
|
|
@@ -7,7 +9,7 @@ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
|
|
|
7
9
|
/**
|
|
8
10
|
* Create a caller that works with Next.js React Server Components & Server Actions
|
|
9
11
|
*/ function nextAppDirCaller(config) {
|
|
10
|
-
const { normalizeFormData =true
|
|
12
|
+
const { normalizeFormData = true } = config;
|
|
11
13
|
const createContext = async ()=>{
|
|
12
14
|
return config?.createContext?.() ?? {};
|
|
13
15
|
};
|
|
@@ -61,13 +63,13 @@ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
|
|
|
61
63
|
}
|
|
62
64
|
case 'query':
|
|
63
65
|
{
|
|
64
|
-
const
|
|
66
|
+
const input = opts.args[0];
|
|
65
67
|
return await opts.invoke({
|
|
66
68
|
type: opts._def.type,
|
|
67
69
|
ctx,
|
|
68
|
-
getRawInput: async ()=>
|
|
70
|
+
getRawInput: async ()=>input,
|
|
69
71
|
path,
|
|
70
|
-
input
|
|
72
|
+
input,
|
|
71
73
|
signal: undefined
|
|
72
74
|
}).then((data)=>{
|
|
73
75
|
if (data instanceof TRPCRedirectError) throw data;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
5
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
4
6
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
3
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
2
4
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _define_property = require('../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js');
|
|
3
4
|
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
5
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
4
7
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
8
|
|
|
6
9
|
/**
|
|
@@ -11,7 +14,7 @@ require('../../unstable-core-do-not-import/rootConfig.js');
|
|
|
11
14
|
// TODO(?): This should maybe a custom error code
|
|
12
15
|
code: 'UNPROCESSABLE_CONTENT',
|
|
13
16
|
message: `Redirect error to "${url}" that will be handled by Next.js`
|
|
14
|
-
});
|
|
17
|
+
}), _define_property._(this, "args", void 0);
|
|
15
18
|
this.args = [
|
|
16
19
|
url.toString(),
|
|
17
20
|
redirectType
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { _ as _define_property } from '../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs';
|
|
1
2
|
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
3
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
2
5
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -9,7 +12,7 @@ import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
|
9
12
|
// TODO(?): This should maybe a custom error code
|
|
10
13
|
code: 'UNPROCESSABLE_CONTENT',
|
|
11
14
|
message: `Redirect error to "${url}" that will be handled by Next.js`
|
|
12
|
-
});
|
|
15
|
+
}), _define_property(this, "args", void 0);
|
|
13
16
|
this.args = [
|
|
14
17
|
url.toString(),
|
|
15
18
|
redirectType
|
|
@@ -55,7 +55,7 @@ function isNotFoundError(error) {
|
|
|
55
55
|
if (error instanceof redirect.TRPCRedirectError) {
|
|
56
56
|
nextNavigation__namespace.redirect(...error.args);
|
|
57
57
|
}
|
|
58
|
-
const { cause
|
|
58
|
+
const { cause } = error;
|
|
59
59
|
// Next.js 15 has `unstable_rethrow`. Use that if it exists.
|
|
60
60
|
if ('unstable_rethrow' in nextNavigation__namespace && typeof nextNavigation__namespace.unstable_rethrow === 'function') {
|
|
61
61
|
nextNavigation__namespace.unstable_rethrow(cause);
|
|
@@ -34,7 +34,7 @@ function isNotFoundError(error) {
|
|
|
34
34
|
if (error instanceof TRPCRedirectError) {
|
|
35
35
|
nextNavigation.redirect(...error.args);
|
|
36
36
|
}
|
|
37
|
-
const { cause
|
|
37
|
+
const { cause } = error;
|
|
38
38
|
// Next.js 15 has `unstable_rethrow`. Use that if it exists.
|
|
39
39
|
if ('unstable_rethrow' in nextNavigation && typeof nextNavigation.unstable_rethrow === 'function') {
|
|
40
40
|
nextNavigation.unstable_rethrow(cause);
|
package/dist/adapters/next.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var utils = require('../unstable-core-do-not-import/utils.js');
|
|
4
4
|
var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
|
|
5
|
+
require('../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
5
7
|
require('../unstable-core-do-not-import/rootConfig.js');
|
|
6
8
|
var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
|
|
7
9
|
|
package/dist/adapters/next.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { run } from '../unstable-core-do-not-import/utils.mjs';
|
|
2
2
|
import { TRPCError } from '../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
3
|
+
import '../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
3
5
|
import '../unstable-core-do-not-import/rootConfig.mjs';
|
|
4
6
|
import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
|
|
5
7
|
|
|
@@ -9,7 +9,7 @@ export declare function createURL(req: http.IncomingMessage): URL;
|
|
|
9
9
|
/**
|
|
10
10
|
* Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
11
11
|
*/
|
|
12
|
-
export declare function incomingMessageToRequest(req: http.IncomingMessage, opts: {
|
|
12
|
+
export declare function incomingMessageToRequest(req: http.IncomingMessage, res: http.ServerResponse, opts: {
|
|
13
13
|
/**
|
|
14
14
|
* Max body size in bytes. If the body is larger than this, the request will be aborted
|
|
15
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,eAAe;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,GAAG,CAkBxD;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,
|
|
1
|
+
{"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,eAAe;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,GAAG,CAkBxD;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CAqCT"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
4
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
5
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
4
6
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
5
7
|
|
|
6
8
|
function createBody(req, opts) {
|
|
@@ -82,15 +84,16 @@ function createHeaders(incoming) {
|
|
|
82
84
|
}
|
|
83
85
|
/**
|
|
84
86
|
* Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
85
|
-
*/ function incomingMessageToRequest(req, opts) {
|
|
87
|
+
*/ function incomingMessageToRequest(req, res, opts) {
|
|
86
88
|
const ac = new AbortController();
|
|
87
89
|
const onAbort = ()=>{
|
|
90
|
+
res.off('close', onAbort);
|
|
91
|
+
req.socket.off('end', onAbort);
|
|
92
|
+
// abort the request
|
|
88
93
|
ac.abort();
|
|
89
|
-
req.off('aborted', onAbort);
|
|
90
|
-
req.off('close', onAbort);
|
|
91
94
|
};
|
|
92
|
-
|
|
93
|
-
req.socket
|
|
95
|
+
res.once('close', onAbort);
|
|
96
|
+
req.socket.once('end', onAbort);
|
|
94
97
|
// Get host from either regular header or HTTP/2 pseudo-header
|
|
95
98
|
const url = createURL(req);
|
|
96
99
|
const init = {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
3
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
2
4
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
3
5
|
|
|
4
6
|
function createBody(req, opts) {
|
|
@@ -80,15 +82,16 @@ function createHeaders(incoming) {
|
|
|
80
82
|
}
|
|
81
83
|
/**
|
|
82
84
|
* Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
83
|
-
*/ function incomingMessageToRequest(req, opts) {
|
|
85
|
+
*/ function incomingMessageToRequest(req, res, opts) {
|
|
84
86
|
const ac = new AbortController();
|
|
85
87
|
const onAbort = ()=>{
|
|
88
|
+
res.off('close', onAbort);
|
|
89
|
+
req.socket.off('end', onAbort);
|
|
90
|
+
// abort the request
|
|
86
91
|
ac.abort();
|
|
87
|
-
req.off('aborted', onAbort);
|
|
88
|
-
req.off('close', onAbort);
|
|
89
92
|
};
|
|
90
|
-
|
|
91
|
-
req.socket
|
|
93
|
+
res.once('close', onAbort);
|
|
94
|
+
req.socket.once('end', onAbort);
|
|
92
95
|
// Get host from either regular header or HTTP/2 pseudo-header
|
|
93
96
|
const url = createURL(req);
|
|
94
97
|
const init = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAM5B,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAM5B,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,WAClD,OAAO,UA6BvB;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBA6ClE"}
|
|
@@ -6,7 +6,10 @@ var utils = require('../../unstable-core-do-not-import/utils.js');
|
|
|
6
6
|
var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
|
|
7
7
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
8
8
|
var transformer = require('../../unstable-core-do-not-import/transformer.js');
|
|
9
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
10
|
+
require('../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js');
|
|
9
11
|
var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
12
|
+
var writeResponse = require('./writeResponse.js');
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* 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`
|
|
@@ -21,7 +24,7 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
|
21
24
|
* @internal
|
|
22
25
|
*/ function internal_exceptionHandler(opts) {
|
|
23
26
|
return (cause)=>{
|
|
24
|
-
const { res
|
|
27
|
+
const { res, req } = opts;
|
|
25
28
|
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
26
29
|
const shape = getErrorShape.getErrorShape({
|
|
27
30
|
config: opts.router._def._config,
|
|
@@ -56,7 +59,7 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
|
56
59
|
});
|
|
57
60
|
return handleViaMiddleware(opts.req, opts.res, (err)=>{
|
|
58
61
|
utils.run(async ()=>{
|
|
59
|
-
const
|
|
62
|
+
const request = incomingMessageToRequest.incomingMessageToRequest(opts.req, opts.res, {
|
|
60
63
|
maxBodySize: opts.maxBodySize ?? null
|
|
61
64
|
});
|
|
62
65
|
// Build tRPC dependencies
|
|
@@ -68,7 +71,7 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
|
68
71
|
};
|
|
69
72
|
const response = await resolveResponse.resolveResponse({
|
|
70
73
|
...opts,
|
|
71
|
-
req,
|
|
74
|
+
req: request,
|
|
72
75
|
error: err ? TRPCError.getTRPCErrorFromUnknown(err) : null,
|
|
73
76
|
createContext,
|
|
74
77
|
onError (o) {
|
|
@@ -78,46 +81,11 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
|
78
81
|
});
|
|
79
82
|
}
|
|
80
83
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
for (const [key, value] of response.headers){
|
|
87
|
-
res.setHeader(key, value);
|
|
88
|
-
}
|
|
89
|
-
if (response.body) {
|
|
90
|
-
const reader = response.body.getReader();
|
|
91
|
-
const onAbort = ()=>{
|
|
92
|
-
// cancelling the reader will cause the whole stream to be cancelled
|
|
93
|
-
reader.cancel().catch(()=>{
|
|
94
|
-
// console.error('reader.cancel() error', err);
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
req.signal.addEventListener('abort', onAbort, {
|
|
98
|
-
once: true
|
|
99
|
-
});
|
|
100
|
-
while(true){
|
|
101
|
-
const { done , value: value1 } = await reader.read();
|
|
102
|
-
if (done) {
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
if (!res.writable) {
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (res.write(value1) === false) {
|
|
109
|
-
await new Promise((resolve)=>{
|
|
110
|
-
res.once('drain', resolve);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
// useful for debugging chunked responses:
|
|
114
|
-
// console.log('wrote', Buffer.from(value).toString());
|
|
115
|
-
// IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
|
|
116
|
-
res.flush?.();
|
|
117
|
-
}
|
|
118
|
-
req.signal.removeEventListener('abort', onAbort);
|
|
119
|
-
}
|
|
120
|
-
res.end();
|
|
84
|
+
await writeResponse.writeResponse({
|
|
85
|
+
request,
|
|
86
|
+
response,
|
|
87
|
+
rawResponse: opts.res
|
|
88
|
+
});
|
|
121
89
|
}).catch(internal_exceptionHandler(opts));
|
|
122
90
|
});
|
|
123
91
|
});
|
|
@@ -4,7 +4,10 @@ import { run } from '../../unstable-core-do-not-import/utils.mjs';
|
|
|
4
4
|
import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
|
|
5
5
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
6
6
|
import { transformTRPCResponse } from '../../unstable-core-do-not-import/transformer.mjs';
|
|
7
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
8
|
+
import '../../unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs';
|
|
7
9
|
import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
10
|
+
import { writeResponse } from './writeResponse.mjs';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* 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`
|
|
@@ -19,7 +22,7 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
|
19
22
|
* @internal
|
|
20
23
|
*/ function internal_exceptionHandler(opts) {
|
|
21
24
|
return (cause)=>{
|
|
22
|
-
const { res
|
|
25
|
+
const { res, req } = opts;
|
|
23
26
|
const error = getTRPCErrorFromUnknown(cause);
|
|
24
27
|
const shape = getErrorShape({
|
|
25
28
|
config: opts.router._def._config,
|
|
@@ -54,7 +57,7 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
|
54
57
|
});
|
|
55
58
|
return handleViaMiddleware(opts.req, opts.res, (err)=>{
|
|
56
59
|
run(async ()=>{
|
|
57
|
-
const
|
|
60
|
+
const request = incomingMessageToRequest(opts.req, opts.res, {
|
|
58
61
|
maxBodySize: opts.maxBodySize ?? null
|
|
59
62
|
});
|
|
60
63
|
// Build tRPC dependencies
|
|
@@ -66,7 +69,7 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
|
66
69
|
};
|
|
67
70
|
const response = await resolveResponse({
|
|
68
71
|
...opts,
|
|
69
|
-
req,
|
|
72
|
+
req: request,
|
|
70
73
|
error: err ? getTRPCErrorFromUnknown(err) : null,
|
|
71
74
|
createContext,
|
|
72
75
|
onError (o) {
|
|
@@ -76,46 +79,11 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
81
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
for (const [key, value] of response.headers){
|
|
85
|
-
res.setHeader(key, value);
|
|
86
|
-
}
|
|
87
|
-
if (response.body) {
|
|
88
|
-
const reader = response.body.getReader();
|
|
89
|
-
const onAbort = ()=>{
|
|
90
|
-
// cancelling the reader will cause the whole stream to be cancelled
|
|
91
|
-
reader.cancel().catch(()=>{
|
|
92
|
-
// console.error('reader.cancel() error', err);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
req.signal.addEventListener('abort', onAbort, {
|
|
96
|
-
once: true
|
|
97
|
-
});
|
|
98
|
-
while(true){
|
|
99
|
-
const { done , value: value1 } = await reader.read();
|
|
100
|
-
if (done) {
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (!res.writable) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
if (res.write(value1) === false) {
|
|
107
|
-
await new Promise((resolve)=>{
|
|
108
|
-
res.once('drain', resolve);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
// useful for debugging chunked responses:
|
|
112
|
-
// console.log('wrote', Buffer.from(value).toString());
|
|
113
|
-
// IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
|
|
114
|
-
res.flush?.();
|
|
115
|
-
}
|
|
116
|
-
req.signal.removeEventListener('abort', onAbort);
|
|
117
|
-
}
|
|
118
|
-
res.end();
|
|
82
|
+
await writeResponse({
|
|
83
|
+
request,
|
|
84
|
+
response,
|
|
85
|
+
rawResponse: opts.res
|
|
86
|
+
});
|
|
119
87
|
}).catch(internal_exceptionHandler(opts));
|
|
120
88
|
});
|
|
121
89
|
});
|