@trpc/server 11.0.0-rc.359 → 11.0.0-rc.362
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 +7 -6
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.d.ts +13 -0
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/getPlanner.js +143 -0
- package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
- package/dist/adapters/aws-lambda/index.d.ts +12 -9
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -65
- package/dist/adapters/aws-lambda/index.mjs +8 -61
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +1 -1
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +10 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +12 -55
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +13 -56
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -5
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +28 -71
- package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -72
- package/dist/adapters/fetch/types.d.ts +9 -12
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +2 -7
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -2
- package/dist/adapters/next.mjs +1 -2
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
- package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
- package/dist/adapters/node-http/index.d.ts +1 -0
- package/dist/adapters/node-http/index.d.ts.map +1 -1
- package/dist/adapters/node-http/index.js +2 -0
- package/dist/adapters/node-http/index.mjs +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +27 -72
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -73
- package/dist/adapters/node-http/types.d.ts +2 -14
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +0 -1
- package/dist/adapters/standalone.mjs +0 -1
- package/dist/adapters/ws.d.ts +2 -12
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +173 -259
- package/dist/http.js +4 -4
- package/dist/http.mjs +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -28
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +164 -38
- package/dist/unstable-core-do-not-import/http/contentType.mjs +164 -38
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +7 -43
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +115 -124
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +116 -125
- package/dist/unstable-core-do-not-import/http/types.d.ts +25 -29
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +12 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +2 -0
- package/dist/unstable-core-do-not-import/utils.mjs +2 -1
- package/dist/unstable-core-do-not-import.d.ts +9 -3
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +11 -9
- package/dist/unstable-core-do-not-import.mjs +7 -6
- package/package.json +3 -14
- package/src/@trpc/server/http.ts +7 -13
- package/src/@trpc/server/index.ts +1 -0
- package/src/adapters/aws-lambda/getPlanner.ts +191 -0
- package/src/adapters/aws-lambda/index.ts +43 -92
- package/src/adapters/express.ts +1 -6
- package/src/adapters/fastify/fastifyRequestHandler.ts +22 -77
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +34 -98
- package/src/adapters/fetch/types.ts +24 -15
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -9
- package/src/adapters/next.ts +1 -6
- package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
- package/src/adapters/node-http/index.ts +1 -0
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -110
- package/src/adapters/node-http/types.ts +9 -19
- package/src/adapters/standalone.ts +1 -2
- package/src/adapters/ws.ts +9 -14
- package/src/unstable-core-do-not-import/http/contentType.ts +199 -82
- package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +133 -205
- package/src/unstable-core-do-not-import/http/types.ts +25 -32
- package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
- package/src/unstable-core-do-not-import/rootConfig.ts +21 -0
- package/src/unstable-core-do-not-import/utils.ts +4 -0
- package/src/unstable-core-do-not-import.ts +9 -3
- package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
- package/adapters/node-http/content-type/form-data/index.js +0 -1
- package/adapters/node-http/content-type/json/index.d.ts +0 -1
- package/adapters/node-http/content-type/json/index.js +0 -1
- package/dist/adapters/aws-lambda/utils.d.ts +0 -40
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -100
- package/dist/adapters/aws-lambda/utils.mjs +0 -93
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -73
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -26
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +0 -135
- package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -108
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -53
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -51
- package/dist/adapters/node-http/content-type/json/index.d.ts +0 -2
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/index.js +0 -16
- package/dist/adapters/node-http/content-type/json/index.mjs +0 -14
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -12
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/src/adapters/aws-lambda/utils.ts +0 -164
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +0 -277
- package/src/adapters/node-http/content-type/form-data/index.ts +0 -163
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +0 -89
- package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -58
- package/src/adapters/node-http/content-type/json/index.ts +0 -11
- package/src/adapters/node-http/internals/contentType.ts +0 -31
- package/src/unstable-core-do-not-import/http/index.ts +0 -29
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createProxy = require('./unstable-core-do-not-import/createProxy.js');
|
|
4
|
+
var TRPCError = require('./unstable-core-do-not-import/error/TRPCError.js');
|
|
4
5
|
var formatter = require('./unstable-core-do-not-import/error/formatter.js');
|
|
5
6
|
var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
|
|
6
|
-
var TRPCError = require('./unstable-core-do-not-import/error/TRPCError.js');
|
|
7
|
-
var getHTTPStatusCode = require('./unstable-core-do-not-import/http/getHTTPStatusCode.js');
|
|
8
|
-
var resolveHTTPResponse = require('./unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
9
7
|
var batchStreamFormatter = require('./unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
10
8
|
var contentType = require('./unstable-core-do-not-import/http/contentType.js');
|
|
9
|
+
var contentTypeParsers = require('./unstable-core-do-not-import/http/contentTypeParsers.js');
|
|
10
|
+
var getHTTPStatusCode = require('./unstable-core-do-not-import/http/getHTTPStatusCode.js');
|
|
11
|
+
var resolveHTTPResponse = require('./unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
11
12
|
var toURL = require('./unstable-core-do-not-import/http/toURL.js');
|
|
12
13
|
var initTRPC = require('./unstable-core-do-not-import/initTRPC.js');
|
|
13
14
|
var middleware = require('./unstable-core-do-not-import/middleware.js');
|
|
@@ -26,16 +27,17 @@ var utils = require('./unstable-core-do-not-import/utils.js');
|
|
|
26
27
|
|
|
27
28
|
exports.createFlatProxy = createProxy.createFlatProxy;
|
|
28
29
|
exports.createRecursiveProxy = createProxy.createRecursiveProxy;
|
|
29
|
-
exports.defaultFormatter = formatter.defaultFormatter;
|
|
30
|
-
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
31
30
|
exports.TRPCError = TRPCError.TRPCError;
|
|
32
31
|
exports.getCauseFromUnknown = TRPCError.getCauseFromUnknown;
|
|
33
32
|
exports.getTRPCErrorFromUnknown = TRPCError.getTRPCErrorFromUnknown;
|
|
33
|
+
exports.defaultFormatter = formatter.defaultFormatter;
|
|
34
|
+
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
35
|
+
exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
|
|
36
|
+
exports.getRequestInfo = contentType.getRequestInfo;
|
|
37
|
+
exports.octetInputParser = contentTypeParsers.octetInputParser;
|
|
34
38
|
exports.getHTTPStatusCode = getHTTPStatusCode.getHTTPStatusCode;
|
|
35
39
|
exports.getHTTPStatusCodeFromError = getHTTPStatusCode.getHTTPStatusCodeFromError;
|
|
36
|
-
exports.
|
|
37
|
-
exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
|
|
38
|
-
exports.getJsonContentTypeInputs = contentType.getJsonContentTypeInputs;
|
|
40
|
+
exports.resolveResponse = resolveHTTPResponse.resolveResponse;
|
|
39
41
|
exports.toURL = toURL.toURL;
|
|
40
42
|
exports.initTRPC = initTRPC.initTRPC;
|
|
41
43
|
exports.createInputMiddleware = middleware.createInputMiddleware;
|
|
@@ -46,7 +48,6 @@ exports.middlewareMarker = middleware.middlewareMarker;
|
|
|
46
48
|
exports.getParseFn = parser.getParseFn;
|
|
47
49
|
exports.procedureTypes = procedure.procedureTypes;
|
|
48
50
|
exports.createBuilder = procedureBuilder.createBuilder;
|
|
49
|
-
exports.unsetMarker = procedureBuilder.unsetMarker;
|
|
50
51
|
exports.isServerDefault = rootConfig.isServerDefault;
|
|
51
52
|
exports.callProcedure = router.callProcedure;
|
|
52
53
|
exports.createCallerFactory = router.createCallerFactory;
|
|
@@ -64,3 +65,4 @@ exports.isFunction = utils.isFunction;
|
|
|
64
65
|
exports.isObject = utils.isObject;
|
|
65
66
|
exports.mergeWithoutOverrides = utils.mergeWithoutOverrides;
|
|
66
67
|
exports.omitPrototype = utils.omitPrototype;
|
|
68
|
+
exports.unsetMarker = utils.unsetMarker;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
export { createFlatProxy, createRecursiveProxy } from './unstable-core-do-not-import/createProxy.mjs';
|
|
2
|
+
export { TRPCError, getCauseFromUnknown, getTRPCErrorFromUnknown } from './unstable-core-do-not-import/error/TRPCError.mjs';
|
|
2
3
|
export { defaultFormatter } from './unstable-core-do-not-import/error/formatter.mjs';
|
|
3
4
|
export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
|
|
4
|
-
export { TRPCError, getCauseFromUnknown, getTRPCErrorFromUnknown } from './unstable-core-do-not-import/error/TRPCError.mjs';
|
|
5
|
-
export { getHTTPStatusCode, getHTTPStatusCodeFromError } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
|
|
6
|
-
export { resolveHTTPResponse } from './unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
7
5
|
export { getBatchStreamFormatter } from './unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
8
|
-
export {
|
|
6
|
+
export { getRequestInfo } from './unstable-core-do-not-import/http/contentType.mjs';
|
|
7
|
+
export { octetInputParser } from './unstable-core-do-not-import/http/contentTypeParsers.mjs';
|
|
8
|
+
export { getHTTPStatusCode, getHTTPStatusCodeFromError } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
|
|
9
|
+
export { resolveResponse } from './unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
9
10
|
export { toURL } from './unstable-core-do-not-import/http/toURL.mjs';
|
|
10
11
|
export { initTRPC } from './unstable-core-do-not-import/initTRPC.mjs';
|
|
11
12
|
export { createInputMiddleware, createMiddlewareFactory, createOutputMiddleware, experimental_standaloneMiddleware, middlewareMarker } from './unstable-core-do-not-import/middleware.mjs';
|
|
12
13
|
export { getParseFn } from './unstable-core-do-not-import/parser.mjs';
|
|
13
14
|
export { procedureTypes } from './unstable-core-do-not-import/procedure.mjs';
|
|
14
|
-
export { createBuilder
|
|
15
|
+
export { createBuilder } from './unstable-core-do-not-import/procedureBuilder.mjs';
|
|
15
16
|
export { isServerDefault } from './unstable-core-do-not-import/rootConfig.mjs';
|
|
16
17
|
export { callProcedure, createCallerFactory, createRouterFactory, mergeRouters } from './unstable-core-do-not-import/router.mjs';
|
|
17
18
|
export { TRPC_ERROR_CODES_BY_KEY, TRPC_ERROR_CODES_BY_NUMBER } from './unstable-core-do-not-import/rpc/codes.mjs';
|
|
18
19
|
export { parseTRPCMessage } from './unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
|
|
19
20
|
export { defaultTransformer, getDataTransformer, transformResult, transformTRPCResponse } from './unstable-core-do-not-import/transformer.mjs';
|
|
20
21
|
export { ERROR_SYMBOL } from './unstable-core-do-not-import/types.mjs';
|
|
21
|
-
export { isFunction, isObject, mergeWithoutOverrides, omitPrototype } from './unstable-core-do-not-import/utils.mjs';
|
|
22
|
+
export { isFunction, isObject, mergeWithoutOverrides, omitPrototype, unsetMarker } from './unstable-core-do-not-import/utils.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.362+01bb2eade",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,16 +58,6 @@
|
|
|
58
58
|
"require": "./dist/adapters/next.js",
|
|
59
59
|
"default": "./dist/adapters/next.js"
|
|
60
60
|
},
|
|
61
|
-
"./adapters/node-http/content-type/form-data": {
|
|
62
|
-
"import": "./dist/adapters/node-http/content-type/form-data/index.mjs",
|
|
63
|
-
"require": "./dist/adapters/node-http/content-type/form-data/index.js",
|
|
64
|
-
"default": "./dist/adapters/node-http/content-type/form-data/index.js"
|
|
65
|
-
},
|
|
66
|
-
"./adapters/node-http/content-type/json": {
|
|
67
|
-
"import": "./dist/adapters/node-http/content-type/json/index.mjs",
|
|
68
|
-
"require": "./dist/adapters/node-http/content-type/json/index.js",
|
|
69
|
-
"default": "./dist/adapters/node-http/content-type/json/index.js"
|
|
70
|
-
},
|
|
71
61
|
"./adapters/node-http": {
|
|
72
62
|
"import": "./dist/adapters/node-http/index.mjs",
|
|
73
63
|
"require": "./dist/adapters/node-http/index.js",
|
|
@@ -128,14 +118,13 @@
|
|
|
128
118
|
"devDependencies": {
|
|
129
119
|
"@fastify/websocket": "^10.0.1",
|
|
130
120
|
"@tanstack/react-query": "^5.25.0",
|
|
131
|
-
"@types/aws-lambda": "^8.10.
|
|
121
|
+
"@types/aws-lambda": "^8.10.137",
|
|
132
122
|
"@types/express": "^4.17.17",
|
|
133
123
|
"@types/hash-sum": "^1.0.0",
|
|
134
124
|
"@types/node": "^20.10.0",
|
|
135
125
|
"@types/react": "^18.3.0",
|
|
136
126
|
"@types/react-dom": "^18.3.0",
|
|
137
127
|
"@types/ws": "^8.2.0",
|
|
138
|
-
"@web3-storage/multipart-parser": "^1.0.0",
|
|
139
128
|
"devalue": "^5.0.0",
|
|
140
129
|
"eslint": "^8.56.0",
|
|
141
130
|
"express": "^4.17.1",
|
|
@@ -160,5 +149,5 @@
|
|
|
160
149
|
"funding": [
|
|
161
150
|
"https://trpc.io/sponsor"
|
|
162
151
|
],
|
|
163
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "01bb2eadebe880a91f31192b2d4e16bfd679d99a"
|
|
164
153
|
}
|
package/src/@trpc/server/http.ts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
export {
|
|
2
2
|
getHTTPStatusCode,
|
|
3
3
|
getHTTPStatusCodeFromError,
|
|
4
|
+
resolveResponse,
|
|
4
5
|
} from '../../unstable-core-do-not-import';
|
|
5
|
-
export { resolveHTTPResponse } from '../../unstable-core-do-not-import';
|
|
6
6
|
export type {
|
|
7
7
|
BaseHandlerOptions,
|
|
8
8
|
HTTPBaseHandlerOptions,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
HTTPErrorHandler,
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `HTTPErrorHandler` instead
|
|
12
|
+
*/
|
|
13
|
+
HTTPErrorHandler as OnErrorFunction,
|
|
14
14
|
ResolveHTTPRequestOptionsContextFn,
|
|
15
|
-
ResponseChunk,
|
|
16
15
|
ResponseMeta,
|
|
17
16
|
ResponseMetaFn,
|
|
18
17
|
TRPCRequestInfo,
|
|
19
18
|
} from '../../unstable-core-do-not-import';
|
|
20
19
|
|
|
21
20
|
export { getBatchStreamFormatter } from '../../unstable-core-do-not-import';
|
|
22
|
-
export
|
|
23
|
-
BaseContentTypeHandler,
|
|
24
|
-
BodyResult,
|
|
25
|
-
} from '../../unstable-core-do-not-import';
|
|
26
|
-
export { getJsonContentTypeInputs } from '../../unstable-core-do-not-import';
|
|
27
|
-
export { toURL } from '../../unstable-core-do-not-import';
|
|
21
|
+
export { octetInputParser, toURL } from '../../unstable-core-do-not-import';
|
|
@@ -32,6 +32,7 @@ export {
|
|
|
32
32
|
type RouterRecord as TRPCRouterRecord,
|
|
33
33
|
type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure,
|
|
34
34
|
type ProcedureOptions as TRPCProcedureOptions,
|
|
35
|
+
type CreateContextCallback,
|
|
35
36
|
type MutationProcedure as TRPCMutationProcedure,
|
|
36
37
|
type QueryProcedure as TRPCQueryProcedure,
|
|
37
38
|
type SubscriptionProcedure as TRPCSubscriptionProcedure,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
APIGatewayProxyEvent,
|
|
3
|
+
APIGatewayProxyEventV2,
|
|
4
|
+
APIGatewayProxyResult,
|
|
5
|
+
APIGatewayProxyStructuredResultV2,
|
|
6
|
+
} from 'aws-lambda';
|
|
7
|
+
|
|
8
|
+
export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
9
|
+
|
|
10
|
+
export type APIGatewayResult =
|
|
11
|
+
| APIGatewayProxyResult
|
|
12
|
+
| APIGatewayProxyStructuredResultV2;
|
|
13
|
+
|
|
14
|
+
function determinePayloadFormat(event: LambdaEvent): string {
|
|
15
|
+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
16
|
+
// According to AWS support, version is is extracted from the version property in the event.
|
|
17
|
+
// If there is no version property, then the version is implied as 1.0
|
|
18
|
+
const unknownEvent = event as { version?: string };
|
|
19
|
+
if (typeof unknownEvent.version === 'undefined') {
|
|
20
|
+
return '1.0';
|
|
21
|
+
} else {
|
|
22
|
+
return unknownEvent.version;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 1:1 mapping of v1 or v2 input events, deduces which is which.
|
|
27
|
+
* @internal
|
|
28
|
+
**/
|
|
29
|
+
export type inferAPIGWReturn<TEvent> = TEvent extends APIGatewayProxyEvent
|
|
30
|
+
? APIGatewayProxyResult
|
|
31
|
+
: TEvent extends APIGatewayProxyEventV2
|
|
32
|
+
? APIGatewayProxyStructuredResultV2
|
|
33
|
+
: never;
|
|
34
|
+
|
|
35
|
+
interface Processor<TEvent extends LambdaEvent> {
|
|
36
|
+
getTRPCPath: (event: TEvent) => string;
|
|
37
|
+
url(event: TEvent): Pick<URL, 'hostname' | 'pathname' | 'search'>;
|
|
38
|
+
getHeaders: (event: TEvent) => Headers;
|
|
39
|
+
getMethod: (event: TEvent) => string;
|
|
40
|
+
toResult: (response: Response) => Promise<inferAPIGWReturn<TEvent>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const v1Processor: Processor<APIGatewayProxyEvent> = {
|
|
44
|
+
// same as getPath above
|
|
45
|
+
getTRPCPath: (event) => {
|
|
46
|
+
if (!event.pathParameters) {
|
|
47
|
+
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
48
|
+
return event.path.split('/').pop() ?? '';
|
|
49
|
+
}
|
|
50
|
+
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
51
|
+
for (const match of matches) {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
|
+
const group = match[1]!;
|
|
54
|
+
if (group.includes('+') && event.pathParameters) {
|
|
55
|
+
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return event.path.slice(1);
|
|
59
|
+
},
|
|
60
|
+
url(event) {
|
|
61
|
+
const hostname: string =
|
|
62
|
+
event.requestContext.domainName ??
|
|
63
|
+
event.headers['host'] ??
|
|
64
|
+
event.multiValueHeaders?.['host']?.[0] ??
|
|
65
|
+
'localhost';
|
|
66
|
+
|
|
67
|
+
const searchParams = new URLSearchParams();
|
|
68
|
+
|
|
69
|
+
for (const [key, value] of Object.entries(
|
|
70
|
+
event.queryStringParameters ?? {},
|
|
71
|
+
)) {
|
|
72
|
+
if (value !== undefined) {
|
|
73
|
+
searchParams.append(key, value);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const qs = searchParams.toString();
|
|
77
|
+
return {
|
|
78
|
+
hostname,
|
|
79
|
+
pathname: event.path,
|
|
80
|
+
search: qs && `?${qs}`,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
getHeaders: (event) => {
|
|
84
|
+
const headers = new Headers();
|
|
85
|
+
for (const [key, value] of Object.entries(event.headers ?? {})) {
|
|
86
|
+
if (value !== undefined) {
|
|
87
|
+
headers.append(key, value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const [k, values] of Object.entries(event.multiValueHeaders ?? {})) {
|
|
92
|
+
if (values) {
|
|
93
|
+
values.forEach((v) => headers.append(k, v));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return headers;
|
|
98
|
+
},
|
|
99
|
+
getMethod: (event) => event.httpMethod,
|
|
100
|
+
toResult: async (response) => {
|
|
101
|
+
const result: APIGatewayProxyResult = {
|
|
102
|
+
statusCode: response.status,
|
|
103
|
+
body: await response.text(),
|
|
104
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const v2Processor: Processor<APIGatewayProxyEventV2> = {
|
|
112
|
+
getTRPCPath: (event) => {
|
|
113
|
+
const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
114
|
+
for (const match of matches) {
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
116
|
+
const group = match[1]!;
|
|
117
|
+
if (group.includes('+') && event.pathParameters) {
|
|
118
|
+
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return event.rawPath.slice(1);
|
|
122
|
+
},
|
|
123
|
+
url(event) {
|
|
124
|
+
return {
|
|
125
|
+
hostname: event.requestContext.domainName,
|
|
126
|
+
pathname: event.rawPath,
|
|
127
|
+
search: event.rawQueryString && `?${event.rawQueryString}`,
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
getHeaders: (event) => {
|
|
131
|
+
const headers = new Headers();
|
|
132
|
+
for (const [key, value] of Object.entries(event.headers ?? {})) {
|
|
133
|
+
if (value !== undefined) {
|
|
134
|
+
headers.append(key, value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (event.cookies) {
|
|
139
|
+
headers.append('cookie', event.cookies.join('; '));
|
|
140
|
+
}
|
|
141
|
+
return headers;
|
|
142
|
+
},
|
|
143
|
+
getMethod: (event) => event.requestContext.http.method,
|
|
144
|
+
toResult: async (response) => {
|
|
145
|
+
const result: APIGatewayProxyStructuredResultV2 = {
|
|
146
|
+
statusCode: response.status,
|
|
147
|
+
body: await response.text(),
|
|
148
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return result;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export function getPlanner<TEvent extends LambdaEvent>(event: TEvent) {
|
|
156
|
+
const version = determinePayloadFormat(event);
|
|
157
|
+
let processor: Processor<TEvent>;
|
|
158
|
+
switch (version) {
|
|
159
|
+
case '1.0':
|
|
160
|
+
processor = v1Processor as Processor<TEvent>;
|
|
161
|
+
break;
|
|
162
|
+
case '2.0':
|
|
163
|
+
processor = v2Processor as Processor<TEvent>;
|
|
164
|
+
break;
|
|
165
|
+
default:
|
|
166
|
+
throw new Error(`Unsupported version: ${version}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const urlParts = processor.url(event);
|
|
170
|
+
const url = `https://${urlParts.hostname}${urlParts.pathname}${urlParts.search}`;
|
|
171
|
+
|
|
172
|
+
const init: RequestInit = {
|
|
173
|
+
headers: processor.getHeaders(event),
|
|
174
|
+
method: processor.getMethod(event),
|
|
175
|
+
// @ts-expect-error this is fine
|
|
176
|
+
duplex: 'half',
|
|
177
|
+
};
|
|
178
|
+
if (event.body) {
|
|
179
|
+
init.body = event.isBase64Encoded
|
|
180
|
+
? Buffer.from(event.body, 'base64')
|
|
181
|
+
: event.body;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const request = new Request(url, init);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
path: processor.getTRPCPath(event),
|
|
188
|
+
request,
|
|
189
|
+
toResult: processor.toResult,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
@@ -7,119 +7,70 @@
|
|
|
7
7
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
import type {
|
|
11
|
-
APIGatewayProxyEvent,
|
|
12
|
-
APIGatewayProxyEventV2,
|
|
13
|
-
APIGatewayProxyResult,
|
|
14
|
-
APIGatewayProxyStructuredResultV2,
|
|
15
|
-
Context as APIGWContext,
|
|
16
|
-
} from 'aws-lambda';
|
|
10
|
+
import type { Context as APIGWContext } from 'aws-lambda';
|
|
17
11
|
// @trpc/server
|
|
18
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
AnyRouter,
|
|
14
|
+
CreateContextCallback,
|
|
15
|
+
inferRouterContext,
|
|
16
|
+
} from '../../@trpc/server';
|
|
19
17
|
// @trpc/server
|
|
20
|
-
import { TRPCError } from '../../@trpc/server';
|
|
21
18
|
import type {
|
|
22
|
-
|
|
23
|
-
HTTPResponse,
|
|
19
|
+
HTTPBaseHandlerOptions,
|
|
24
20
|
ResolveHTTPRequestOptionsContextFn,
|
|
21
|
+
TRPCRequestInfo,
|
|
25
22
|
} from '../../@trpc/server/http';
|
|
26
|
-
import {
|
|
27
|
-
import type {
|
|
28
|
-
|
|
29
|
-
APIGatewayResult,
|
|
30
|
-
AWSLambdaOptions,
|
|
31
|
-
} from './utils';
|
|
32
|
-
import {
|
|
33
|
-
getHTTPMethod,
|
|
34
|
-
getPath,
|
|
35
|
-
isPayloadV1,
|
|
36
|
-
isPayloadV2,
|
|
37
|
-
transformHeaders,
|
|
38
|
-
UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
39
|
-
} from './utils';
|
|
40
|
-
|
|
41
|
-
export * from './utils';
|
|
23
|
+
import { resolveResponse } from '../../@trpc/server/http';
|
|
24
|
+
import type { inferAPIGWReturn, LambdaEvent } from './getPlanner';
|
|
25
|
+
import { getPlanner } from './getPlanner';
|
|
42
26
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (typeof value !== 'undefined') {
|
|
49
|
-
query.append(key, value);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
27
|
+
export type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {
|
|
28
|
+
event: TEvent;
|
|
29
|
+
context: APIGWContext;
|
|
30
|
+
info: TRPCRequestInfo;
|
|
31
|
+
};
|
|
52
32
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
query: query,
|
|
63
|
-
headers: event.headers,
|
|
64
|
-
body: body,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
33
|
+
export type AWSLambdaOptions<
|
|
34
|
+
TRouter extends AnyRouter,
|
|
35
|
+
TEvent extends LambdaEvent,
|
|
36
|
+
> =
|
|
37
|
+
| HTTPBaseHandlerOptions<TRouter, TEvent> &
|
|
38
|
+
CreateContextCallback<
|
|
39
|
+
inferRouterContext<AnyRouter>,
|
|
40
|
+
AWSLambdaCreateContextFn<TRouter, TEvent>
|
|
41
|
+
>;
|
|
67
42
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return resp as TResult;
|
|
79
|
-
} else if (isPayloadV2(event)) {
|
|
80
|
-
const resp: APIGatewayProxyStructuredResultV2 = {
|
|
81
|
-
statusCode: response.status,
|
|
82
|
-
body: response.body ?? undefined,
|
|
83
|
-
headers: transformHeaders(response.headers ?? {}),
|
|
84
|
-
};
|
|
85
|
-
return resp as TResult;
|
|
86
|
-
} else {
|
|
87
|
-
throw new TRPCError({
|
|
88
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
89
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
43
|
+
export type AWSLambdaCreateContextFn<
|
|
44
|
+
TRouter extends AnyRouter,
|
|
45
|
+
TEvent extends LambdaEvent,
|
|
46
|
+
> = ({
|
|
47
|
+
event,
|
|
48
|
+
context,
|
|
49
|
+
info,
|
|
50
|
+
}: CreateAWSLambdaContextOptions<TEvent>) =>
|
|
51
|
+
| inferRouterContext<TRouter>
|
|
52
|
+
| Promise<inferRouterContext<TRouter>>;
|
|
93
53
|
|
|
94
|
-
/** 1:1 mapping of v1 or v2 input events, deduces which is which.
|
|
95
|
-
* @internal
|
|
96
|
-
**/
|
|
97
|
-
type inferAPIGWReturn<TType> = TType extends APIGatewayProxyEvent
|
|
98
|
-
? APIGatewayProxyResult
|
|
99
|
-
: TType extends APIGatewayProxyEventV2
|
|
100
|
-
? APIGatewayProxyStructuredResultV2
|
|
101
|
-
: never;
|
|
102
54
|
export function awsLambdaRequestHandler<
|
|
103
55
|
TRouter extends AnyRouter,
|
|
104
|
-
TEvent extends
|
|
105
|
-
TResult extends inferAPIGWReturn<TEvent>,
|
|
56
|
+
TEvent extends LambdaEvent,
|
|
106
57
|
>(
|
|
107
58
|
opts: AWSLambdaOptions<TRouter, TEvent>,
|
|
108
|
-
): (event: TEvent, context: APIGWContext) => Promise<
|
|
59
|
+
): (event: TEvent, context: APIGWContext) => Promise<inferAPIGWReturn<TEvent>> {
|
|
109
60
|
return async (event, context) => {
|
|
110
|
-
const
|
|
111
|
-
|
|
61
|
+
const planner = getPlanner(event);
|
|
62
|
+
|
|
112
63
|
const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (
|
|
113
64
|
innerOpts,
|
|
114
65
|
) => {
|
|
115
66
|
return await opts.createContext?.({ event, context, ...innerOpts });
|
|
116
67
|
};
|
|
117
68
|
|
|
118
|
-
const response = await
|
|
69
|
+
const response = await resolveResponse({
|
|
119
70
|
...opts,
|
|
120
71
|
createContext,
|
|
121
|
-
req,
|
|
122
|
-
path,
|
|
72
|
+
req: planner.request,
|
|
73
|
+
path: planner.path,
|
|
123
74
|
error: null,
|
|
124
75
|
onError(o) {
|
|
125
76
|
opts?.onError?.({
|
|
@@ -129,6 +80,6 @@ export function awsLambdaRequestHandler<
|
|
|
129
80
|
},
|
|
130
81
|
});
|
|
131
82
|
|
|
132
|
-
return
|
|
83
|
+
return await planner.toResult(response);
|
|
133
84
|
};
|
|
134
85
|
}
|
package/src/adapters/express.ts
CHANGED
|
@@ -27,12 +27,7 @@ export function createExpressMiddleware<TRouter extends AnyRouter>(
|
|
|
27
27
|
const endpoint = req.path.slice(1);
|
|
28
28
|
|
|
29
29
|
await nodeHTTPRequestHandler({
|
|
30
|
-
|
|
31
|
-
...(opts as NodeHTTPHandlerOptions<
|
|
32
|
-
AnyRouter,
|
|
33
|
-
express.Request,
|
|
34
|
-
express.Response
|
|
35
|
-
>),
|
|
30
|
+
...(opts as any),
|
|
36
31
|
req,
|
|
37
32
|
res,
|
|
38
33
|
path: endpoint,
|
|
@@ -7,22 +7,19 @@
|
|
|
7
7
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
import { Readable } from 'node:stream';
|
|
11
10
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
12
11
|
// @trpc/server
|
|
13
12
|
import type { AnyRouter } from '../../@trpc/server';
|
|
14
13
|
import type {
|
|
15
14
|
HTTPBaseHandlerOptions,
|
|
16
|
-
HTTPRequest,
|
|
17
|
-
HTTPResponse,
|
|
18
15
|
ResolveHTTPRequestOptionsContextFn,
|
|
19
|
-
ResponseChunk,
|
|
20
16
|
} from '../../@trpc/server/http';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
import { resolveResponse } from '../../@trpc/server/http';
|
|
18
|
+
import type {
|
|
19
|
+
IncomingMessageWithBody,
|
|
20
|
+
NodeHTTPCreateContextOption,
|
|
21
|
+
} from '../node-http';
|
|
22
|
+
import { incomingMessageToRequest } from '../node-http';
|
|
26
23
|
|
|
27
24
|
export type FastifyHandlerOptions<
|
|
28
25
|
TRouter extends AnyRouter,
|
|
@@ -55,80 +52,28 @@ export async function fastifyRequestHandler<
|
|
|
55
52
|
});
|
|
56
53
|
};
|
|
57
54
|
|
|
58
|
-
const
|
|
59
|
-
? new URLSearchParams(opts.req.query as any)
|
|
60
|
-
: new URLSearchParams(opts.req.url.split('?')[1]);
|
|
55
|
+
const incomingMessage = opts.req.raw as IncomingMessageWithBody;
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
// monkey-path body to the IncomingMessage
|
|
58
|
+
if ('body' in opts.req) {
|
|
59
|
+
incomingMessage.body = opts.req.body;
|
|
60
|
+
}
|
|
61
|
+
const req = incomingMessageToRequest(incomingMessage, {
|
|
62
|
+
maxBodySize: null,
|
|
63
|
+
});
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
const promise = new Promise<FastifyReply>((r) => (resolve = r));
|
|
71
|
-
|
|
72
|
-
let isStream = false;
|
|
73
|
-
let stream: Readable;
|
|
74
|
-
let formatter: ReturnType<typeof getBatchStreamFormatter>;
|
|
75
|
-
const unstable_onHead = (head: HTTPResponse, isStreaming: boolean) => {
|
|
76
|
-
if (!opts.res.statusCode || opts.res.statusCode === 200) {
|
|
77
|
-
opts.res.statusCode = head.status;
|
|
78
|
-
}
|
|
79
|
-
for (const [key, value] of Object.entries(head.headers ?? {})) {
|
|
80
|
-
/* istanbul ignore if -- @preserve */
|
|
81
|
-
if (typeof value === 'undefined') {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
void opts.res.header(key, value);
|
|
85
|
-
}
|
|
86
|
-
if (isStreaming) {
|
|
87
|
-
void opts.res.header('Transfer-Encoding', 'chunked');
|
|
88
|
-
void opts.res.header(
|
|
89
|
-
'Vary',
|
|
90
|
-
opts.res.hasHeader('Vary')
|
|
91
|
-
? 'trpc-batch-mode, ' + opts.res.getHeader('Vary')
|
|
92
|
-
: 'trpc-batch-mode',
|
|
93
|
-
);
|
|
94
|
-
stream = new Readable();
|
|
95
|
-
stream._read = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
96
|
-
resolve(opts.res.send(stream));
|
|
97
|
-
isStream = true;
|
|
98
|
-
formatter = getBatchStreamFormatter();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const unstable_onChunk = ([index, string]: ResponseChunk) => {
|
|
103
|
-
if (index === -1) {
|
|
104
|
-
// full response, no streaming
|
|
105
|
-
resolve(opts.res.send(string));
|
|
106
|
-
} else {
|
|
107
|
-
stream.push(formatter(index, string));
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
resolveHTTPResponse({
|
|
65
|
+
const res = await resolveResponse({
|
|
112
66
|
...opts,
|
|
113
67
|
req,
|
|
68
|
+
error: null,
|
|
114
69
|
createContext,
|
|
115
70
|
onError(o) {
|
|
116
|
-
opts?.onError?.({
|
|
71
|
+
opts?.onError?.({
|
|
72
|
+
...o,
|
|
73
|
+
req: opts.req,
|
|
74
|
+
});
|
|
117
75
|
},
|
|
118
|
-
|
|
119
|
-
unstable_onChunk,
|
|
120
|
-
})
|
|
121
|
-
.then(() => {
|
|
122
|
-
if (isStream) {
|
|
123
|
-
stream.push(formatter.end());
|
|
124
|
-
stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
.catch(() => {
|
|
128
|
-
if (isStream) {
|
|
129
|
-
stream.push(null);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
76
|
+
});
|
|
132
77
|
|
|
133
|
-
|
|
78
|
+
await opts.res.send(res);
|
|
134
79
|
}
|