@trpc/server 11.0.0-alpha-tmp-subscription-connection-state.489 → 11.0.0-alpha-tmp-12-06-react.665
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/@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.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.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/index.mjs +2 -0
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +27 -7
- package/dist/adapters/express.mjs +27 -7
- package/dist/adapters/fastify/fastifyRequestHandler.js +3 -1
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +3 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +9 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +10 -3
- package/dist/adapters/fetch/fetchRequestHandler.js +9 -8
- package/dist/adapters/fetch/fetchRequestHandler.mjs +9 -8
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.js +10 -5
- package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +10 -5
- 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 +16 -1
- package/dist/adapters/next-app-dir/redirect.mjs +16 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/rethrowNextErrors.js +4 -3
- package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +4 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +23 -30
- package/dist/adapters/next.mjs +24 -31
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +2 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.js +83 -40
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +83 -41
- package/dist/adapters/node-http/index.js +2 -0
- package/dist/adapters/node-http/index.mjs +2 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +7 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +70 -58
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +70 -59
- 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 +82 -0
- package/dist/adapters/node-http/writeResponse.mjs +79 -0
- package/dist/adapters/standalone.d.ts +5 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +25 -13
- package/dist/adapters/standalone.mjs +26 -14
- package/dist/adapters/ws.d.ts +14 -4
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +217 -101
- package/dist/adapters/ws.mjs +217 -102
- package/dist/bundle-analysis.json +412 -310
- package/dist/http.js +2 -4
- package/dist/http.mjs +2 -2
- package/dist/index.js +3 -0
- package/dist/index.mjs +3 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.1_rollup@4.27.4_tslib@2.8.1_typescript@5.7.2/node_modules/tslib/tslib.es6.js +73 -0
- package/dist/observable/behaviorSubject.d.ts +15 -0
- package/dist/observable/behaviorSubject.d.ts.map +1 -0
- package/dist/observable/behaviorSubject.js +40 -0
- package/dist/observable/behaviorSubject.mjs +38 -0
- package/dist/observable/index.d.ts +3 -3
- package/dist/observable/index.d.ts.map +1 -1
- package/dist/observable/index.js +5 -0
- package/dist/observable/index.mjs +3 -2
- package/dist/observable/observable.d.ts +2 -1
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/observable/observable.js +31 -8
- package/dist/observable/observable.mjs +31 -8
- package/dist/observable/operators.d.ts +2 -0
- package/dist/observable/operators.d.ts.map +1 -1
- package/dist/observable/operators.js +35 -0
- package/dist/observable/operators.mjs +34 -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/clientish/inference.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/clientish/inferrable.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/clientish/serialize.d.ts +2 -2
- package/dist/unstable-core-do-not-import/clientish/serialize.d.ts.map +1 -1
- 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.d.ts +1 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.js +16 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +16 -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/getHTTPStatusCode.d.ts +6 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +28 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +25 -1
- 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.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveResponse.js +180 -96
- package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +182 -98
- package/dist/unstable-core-do-not-import/http/types.d.ts +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +11 -11
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.js +11 -11
- package/dist/unstable-core-do-not-import/initTRPC.mjs +11 -11
- package/dist/unstable-core-do-not-import/middleware.d.ts +2 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/middleware.js +2 -2
- package/dist/unstable-core-do-not-import/middleware.mjs +2 -2
- package/dist/unstable-core-do-not-import/parser.d.ts +5 -1
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/parser.js +4 -0
- package/dist/unstable-core-do-not-import/parser.mjs +4 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +8 -2
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +31 -12
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +33 -39
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +33 -39
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +17 -17
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +4 -3
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +6 -5
- package/dist/unstable-core-do-not-import/router.mjs +6 -5
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +2 -9
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +7 -10
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- 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 +25 -14
- package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/jsonl.js +439 -318
- package/dist/unstable-core-do-not-import/stream/jsonl.mjs +439 -318
- package/dist/unstable-core-do-not-import/stream/sse.d.ts +58 -18
- package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/sse.js +297 -122
- package/dist/unstable-core-do-not-import/stream/sse.mjs +298 -123
- package/dist/unstable-core-do-not-import/stream/sse.types.d.ts +31 -0
- package/dist/unstable-core-do-not-import/stream/sse.types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/tracked.d.ts +2 -2
- package/dist/unstable-core-do-not-import/stream/tracked.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/tracked.js +1 -1
- package/dist/unstable-core-do-not-import/stream/tracked.mjs +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +171 -0
- package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +167 -0
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts +0 -11
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.js +0 -29
- package/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +1 -29
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts +17 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.js +44 -0
- package/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.d.ts +8 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.js +25 -0
- package/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.mjs +23 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts +5 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.js +26 -0
- package/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +23 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts +7 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.js +130 -0
- package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +127 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +2 -5
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/transformer.js +1 -1
- package/dist/unstable-core-do-not-import/transformer.mjs +1 -1
- package/dist/unstable-core-do-not-import/types.d.ts +26 -3
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +15 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +49 -1
- package/dist/unstable-core-do-not-import/utils.mjs +45 -2
- package/dist/unstable-core-do-not-import.d.ts +3 -2
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +14 -7
- package/dist/unstable-core-do-not-import.mjs +5 -6
- package/dist/vendor/unpromise/index.d.ts +3 -0
- package/dist/vendor/unpromise/index.d.ts.map +1 -0
- package/dist/vendor/unpromise/types.d.ts +28 -0
- package/dist/vendor/unpromise/types.d.ts.map +1 -0
- package/dist/vendor/unpromise/unpromise.d.ts +121 -0
- package/dist/vendor/unpromise/unpromise.d.ts.map +1 -0
- package/dist/vendor/unpromise/unpromise.js +292 -0
- package/dist/vendor/unpromise/unpromise.mjs +289 -0
- package/package.json +20 -17
- package/src/@trpc/server/http.ts +0 -2
- package/src/@trpc/server/index.ts +2 -0
- package/src/adapters/aws-lambda/getPlanner.ts +2 -2
- package/src/adapters/aws-lambda/index.ts +5 -6
- package/src/adapters/express.ts +21 -9
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +16 -5
- package/src/adapters/fetch/fetchRequestHandler.ts +2 -2
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +3 -0
- package/src/adapters/next-app-dir/rethrowNextErrors.ts +3 -2
- package/src/adapters/next.ts +29 -34
- package/src/adapters/node-http/incomingMessageToRequest.ts +110 -40
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +85 -63
- package/src/adapters/node-http/writeResponse.ts +94 -0
- package/src/adapters/standalone.ts +35 -18
- package/src/adapters/ws.ts +111 -57
- package/src/observable/behaviorSubject.ts +55 -0
- package/src/observable/index.ts +22 -3
- package/src/observable/observable.ts +32 -14
- package/src/observable/operators.ts +47 -0
- package/src/unstable-core-do-not-import/clientish/inference.ts +4 -4
- package/src/unstable-core-do-not-import/clientish/inferrable.ts +6 -6
- package/src/unstable-core-do-not-import/clientish/serialize.ts +5 -5
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +37 -4
- package/src/unstable-core-do-not-import/http/isAbortError.ts +7 -0
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +185 -90
- package/src/unstable-core-do-not-import/http/types.ts +1 -1
- package/src/unstable-core-do-not-import/initTRPC.ts +14 -20
- package/src/unstable-core-do-not-import/middleware.ts +5 -4
- package/src/unstable-core-do-not-import/parser.ts +17 -6
- package/src/unstable-core-do-not-import/procedure.ts +17 -2
- package/src/unstable-core-do-not-import/procedureBuilder.ts +137 -122
- package/src/unstable-core-do-not-import/rootConfig.ts +20 -20
- package/src/unstable-core-do-not-import/router.ts +15 -16
- package/src/unstable-core-do-not-import/rpc/codes.ts +2 -10
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +7 -12
- package/src/unstable-core-do-not-import/stream/jsonl.ts +287 -296
- package/src/unstable-core-do-not-import/stream/sse.ts +338 -171
- package/src/unstable-core-do-not-import/stream/sse.types.ts +44 -0
- package/src/unstable-core-do-not-import/stream/tracked.ts +5 -11
- package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +89 -0
- package/src/unstable-core-do-not-import/stream/utils/createDeferred.ts +0 -36
- package/src/unstable-core-do-not-import/stream/utils/disposable.ts +52 -0
- package/src/unstable-core-do-not-import/stream/utils/readableStreamFrom.ts +28 -0
- package/src/unstable-core-do-not-import/stream/utils/timerResource.ts +29 -0
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +47 -0
- package/src/unstable-core-do-not-import/transformer.ts +1 -1
- package/src/unstable-core-do-not-import/types.ts +35 -10
- package/src/unstable-core-do-not-import/utils.ts +56 -1
- package/src/unstable-core-do-not-import.ts +3 -2
- package/src/vendor/unpromise/ATTRIBUTION.txt +1 -0
- package/src/vendor/unpromise/LICENSE +20 -0
- package/src/vendor/unpromise/index.ts +7 -0
- package/src/vendor/unpromise/types.ts +55 -0
- package/src/vendor/unpromise/unpromise.ts +380 -0
- 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/http/toURL.d.ts +0 -2
- package/dist/unstable-core-do-not-import/http/toURL.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/toURL.js +0 -8
- package/dist/unstable-core-do-not-import/http/toURL.mjs +0 -6
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +0 -10
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +0 -31
- package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +0 -29
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts +0 -7
- package/dist/unstable-core-do-not-import/stream/utils/createServer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/types.js +0 -11
- package/dist/unstable-core-do-not-import/types.mjs +0 -9
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/http/toURL.ts +0 -7
- package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +0 -31
- package/src/unstable-core-do-not-import/stream/utils/createServer.ts +0 -44
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var getErrorShape = require('../../unstable-core-do-not-import/error/getErrorShape.js');
|
|
3
4
|
var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
|
|
5
|
+
var utils = require('../../unstable-core-do-not-import/utils.js');
|
|
4
6
|
var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
|
|
5
7
|
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
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/disposable.js');
|
|
6
11
|
var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
12
|
+
var writeResponse = require('./writeResponse.js');
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
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`
|
|
@@ -14,70 +20,76 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
|
|
|
14
20
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
15
21
|
* ```
|
|
16
22
|
*/ // @trpc/server
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/ function internal_exceptionHandler(opts) {
|
|
26
|
+
return (cause)=>{
|
|
27
|
+
const { res, req } = opts;
|
|
28
|
+
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
29
|
+
const shape = getErrorShape.getErrorShape({
|
|
30
|
+
config: opts.router._def._config,
|
|
31
|
+
error,
|
|
32
|
+
type: 'unknown',
|
|
33
|
+
path: undefined,
|
|
34
|
+
input: undefined,
|
|
35
|
+
ctx: undefined
|
|
22
36
|
});
|
|
23
|
-
|
|
24
|
-
const createContext = async (innerOpts)=>{
|
|
25
|
-
return await opts.createContext?.({
|
|
26
|
-
...opts,
|
|
27
|
-
...innerOpts
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
const response = await resolveResponse.resolveResponse({
|
|
31
|
-
...opts,
|
|
37
|
+
opts.onError?.({
|
|
32
38
|
req,
|
|
33
|
-
error
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
error,
|
|
40
|
+
type: 'unknown',
|
|
41
|
+
path: undefined,
|
|
42
|
+
input: undefined,
|
|
43
|
+
ctx: undefined
|
|
44
|
+
});
|
|
45
|
+
const transformed = transformer.transformTRPCResponse(opts.router._def._config, {
|
|
46
|
+
error: shape
|
|
41
47
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
res.statusCode = shape.data.httpStatus;
|
|
49
|
+
res.end(JSON.stringify(transformed));
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @remark the promise never rejects
|
|
54
|
+
*/ async function nodeHTTPRequestHandler(opts) {
|
|
55
|
+
return new Promise((resolve)=>{
|
|
56
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
|
|
57
|
+
opts.res.once('finish', ()=>{
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
return handleViaMiddleware(opts.req, opts.res, (err)=>{
|
|
61
|
+
utils.run(async ()=>{
|
|
62
|
+
const request = incomingMessageToRequest.incomingMessageToRequest(opts.req, opts.res, {
|
|
63
|
+
maxBodySize: opts.maxBodySize ?? null
|
|
56
64
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const { done , value: value1 } = await reader.read();
|
|
63
|
-
if (done) {
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
if (!res.writable) {
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
if (res.write(value1) === false) {
|
|
70
|
-
await new Promise((resolve)=>{
|
|
71
|
-
res.once('drain', resolve);
|
|
65
|
+
// Build tRPC dependencies
|
|
66
|
+
const createContext = async (innerOpts)=>{
|
|
67
|
+
return await opts.createContext?.({
|
|
68
|
+
...opts,
|
|
69
|
+
...innerOpts
|
|
72
70
|
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
};
|
|
72
|
+
const response = await resolveResponse.resolveResponse({
|
|
73
|
+
...opts,
|
|
74
|
+
req: request,
|
|
75
|
+
error: err ? TRPCError.getTRPCErrorFromUnknown(err) : null,
|
|
76
|
+
createContext,
|
|
77
|
+
onError (o) {
|
|
78
|
+
opts?.onError?.({
|
|
79
|
+
...o,
|
|
80
|
+
req: opts.req
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
await writeResponse.writeResponse({
|
|
85
|
+
request,
|
|
86
|
+
response,
|
|
87
|
+
rawResponse: opts.res
|
|
88
|
+
});
|
|
89
|
+
}).catch(internal_exceptionHandler(opts));
|
|
90
|
+
});
|
|
80
91
|
});
|
|
81
92
|
}
|
|
82
93
|
|
|
94
|
+
exports.internal_exceptionHandler = internal_exceptionHandler;
|
|
83
95
|
exports.nodeHTTPRequestHandler = nodeHTTPRequestHandler;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { getErrorShape } from '../../unstable-core-do-not-import/error/getErrorShape.mjs';
|
|
1
2
|
import { getTRPCErrorFromUnknown } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
|
|
3
|
+
import { run } from '../../unstable-core-do-not-import/utils.mjs';
|
|
2
4
|
import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
|
|
3
5
|
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
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/disposable.mjs';
|
|
4
9
|
import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
10
|
+
import { writeResponse } from './writeResponse.mjs';
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
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`
|
|
@@ -12,70 +18,75 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
|
|
|
12
18
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
19
|
* ```
|
|
14
20
|
*/ // @trpc/server
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/ function internal_exceptionHandler(opts) {
|
|
24
|
+
return (cause)=>{
|
|
25
|
+
const { res, req } = opts;
|
|
26
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
27
|
+
const shape = getErrorShape({
|
|
28
|
+
config: opts.router._def._config,
|
|
29
|
+
error,
|
|
30
|
+
type: 'unknown',
|
|
31
|
+
path: undefined,
|
|
32
|
+
input: undefined,
|
|
33
|
+
ctx: undefined
|
|
20
34
|
});
|
|
21
|
-
|
|
22
|
-
const createContext = async (innerOpts)=>{
|
|
23
|
-
return await opts.createContext?.({
|
|
24
|
-
...opts,
|
|
25
|
-
...innerOpts
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
const response = await resolveResponse({
|
|
29
|
-
...opts,
|
|
35
|
+
opts.onError?.({
|
|
30
36
|
req,
|
|
31
|
-
error
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
error,
|
|
38
|
+
type: 'unknown',
|
|
39
|
+
path: undefined,
|
|
40
|
+
input: undefined,
|
|
41
|
+
ctx: undefined
|
|
42
|
+
});
|
|
43
|
+
const transformed = transformTRPCResponse(opts.router._def._config, {
|
|
44
|
+
error: shape
|
|
39
45
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
res.statusCode = shape.data.httpStatus;
|
|
47
|
+
res.end(JSON.stringify(transformed));
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @remark the promise never rejects
|
|
52
|
+
*/ async function nodeHTTPRequestHandler(opts) {
|
|
53
|
+
return new Promise((resolve)=>{
|
|
54
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
|
|
55
|
+
opts.res.once('finish', ()=>{
|
|
56
|
+
resolve();
|
|
57
|
+
});
|
|
58
|
+
return handleViaMiddleware(opts.req, opts.res, (err)=>{
|
|
59
|
+
run(async ()=>{
|
|
60
|
+
const request = incomingMessageToRequest(opts.req, opts.res, {
|
|
61
|
+
maxBodySize: opts.maxBodySize ?? null
|
|
54
62
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const { done , value: value1 } = await reader.read();
|
|
61
|
-
if (done) {
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
if (!res.writable) {
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
if (res.write(value1) === false) {
|
|
68
|
-
await new Promise((resolve)=>{
|
|
69
|
-
res.once('drain', resolve);
|
|
63
|
+
// Build tRPC dependencies
|
|
64
|
+
const createContext = async (innerOpts)=>{
|
|
65
|
+
return await opts.createContext?.({
|
|
66
|
+
...opts,
|
|
67
|
+
...innerOpts
|
|
70
68
|
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
};
|
|
70
|
+
const response = await resolveResponse({
|
|
71
|
+
...opts,
|
|
72
|
+
req: request,
|
|
73
|
+
error: err ? getTRPCErrorFromUnknown(err) : null,
|
|
74
|
+
createContext,
|
|
75
|
+
onError (o) {
|
|
76
|
+
opts?.onError?.({
|
|
77
|
+
...o,
|
|
78
|
+
req: opts.req
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
await writeResponse({
|
|
83
|
+
request,
|
|
84
|
+
response,
|
|
85
|
+
rawResponse: opts.res
|
|
86
|
+
});
|
|
87
|
+
}).catch(internal_exceptionHandler(opts));
|
|
88
|
+
});
|
|
78
89
|
});
|
|
79
90
|
}
|
|
80
91
|
|
|
81
|
-
export { nodeHTTPRequestHandler };
|
|
92
|
+
export { internal_exceptionHandler, nodeHTTPRequestHandler };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { NodeHTTPResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function writeResponseBody(opts: {
|
|
6
|
+
res: NodeHTTPResponse;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
body: NonNullable<Response['body']>;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function writeResponse(opts: {
|
|
14
|
+
request: Request;
|
|
15
|
+
response: Response;
|
|
16
|
+
rawResponse: NodeHTTPResponse;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=writeResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeResponse.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/writeResponse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA4BhD;;GAEG;AAEH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,gBAAgB,CAAC;IACtB,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;CACrC,iBAoBA;AACD;;GAEG;AAEH,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,gBAAgB,CAAC;CAC/B,iBA0BA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isAbortError = require('../../unstable-core-do-not-import/http/isAbortError.js');
|
|
4
|
+
require('../../vendor/unpromise/unpromise.js');
|
|
5
|
+
require('../../unstable-core-do-not-import/stream/utils/disposable.js');
|
|
6
|
+
require('../../unstable-core-do-not-import/rootConfig.js');
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line no-restricted-imports
|
|
9
|
+
async function writeResponseBodyChunk(res, chunk) {
|
|
10
|
+
// useful for debugging 🙃
|
|
11
|
+
// console.debug('writing', new TextDecoder().decode(chunk));
|
|
12
|
+
if (res.write(chunk) === false) {
|
|
13
|
+
await new Promise((resolve, reject)=>{
|
|
14
|
+
const onError = (err)=>{
|
|
15
|
+
reject(err);
|
|
16
|
+
cleanup();
|
|
17
|
+
};
|
|
18
|
+
const onDrain = ()=>{
|
|
19
|
+
resolve();
|
|
20
|
+
cleanup();
|
|
21
|
+
};
|
|
22
|
+
const cleanup = ()=>{
|
|
23
|
+
res.off('error', onError);
|
|
24
|
+
res.off('drain', onDrain);
|
|
25
|
+
};
|
|
26
|
+
res.once('error', onError);
|
|
27
|
+
res.once('drain', onDrain);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/ async function writeResponseBody(opts) {
|
|
34
|
+
const { res } = opts;
|
|
35
|
+
try {
|
|
36
|
+
const writableStream = new WritableStream({
|
|
37
|
+
async write (chunk) {
|
|
38
|
+
await writeResponseBodyChunk(res, chunk);
|
|
39
|
+
res.flush?.();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
await opts.body.pipeTo(writableStream, {
|
|
43
|
+
signal: opts.signal
|
|
44
|
+
});
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (isAbortError.isAbortError(err)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/ async function writeResponse(opts) {
|
|
55
|
+
const { response, rawResponse } = opts;
|
|
56
|
+
// Only override status code if it hasn't been explicitly set in a procedure etc
|
|
57
|
+
if (rawResponse.statusCode === 200) {
|
|
58
|
+
rawResponse.statusCode = response.status;
|
|
59
|
+
}
|
|
60
|
+
for (const [key, value] of response.headers){
|
|
61
|
+
rawResponse.setHeader(key, value);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
if (response.body) {
|
|
65
|
+
await writeResponseBody({
|
|
66
|
+
res: rawResponse,
|
|
67
|
+
signal: opts.request.signal,
|
|
68
|
+
body: response.body
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (!rawResponse.headersSent) {
|
|
73
|
+
rawResponse.statusCode = 500;
|
|
74
|
+
}
|
|
75
|
+
throw err;
|
|
76
|
+
} finally{
|
|
77
|
+
rawResponse.end();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
exports.writeResponse = writeResponse;
|
|
82
|
+
exports.writeResponseBody = writeResponseBody;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isAbortError } from '../../unstable-core-do-not-import/http/isAbortError.mjs';
|
|
2
|
+
import '../../vendor/unpromise/unpromise.mjs';
|
|
3
|
+
import '../../unstable-core-do-not-import/stream/utils/disposable.mjs';
|
|
4
|
+
import '../../unstable-core-do-not-import/rootConfig.mjs';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line no-restricted-imports
|
|
7
|
+
async function writeResponseBodyChunk(res, chunk) {
|
|
8
|
+
// useful for debugging 🙃
|
|
9
|
+
// console.debug('writing', new TextDecoder().decode(chunk));
|
|
10
|
+
if (res.write(chunk) === false) {
|
|
11
|
+
await new Promise((resolve, reject)=>{
|
|
12
|
+
const onError = (err)=>{
|
|
13
|
+
reject(err);
|
|
14
|
+
cleanup();
|
|
15
|
+
};
|
|
16
|
+
const onDrain = ()=>{
|
|
17
|
+
resolve();
|
|
18
|
+
cleanup();
|
|
19
|
+
};
|
|
20
|
+
const cleanup = ()=>{
|
|
21
|
+
res.off('error', onError);
|
|
22
|
+
res.off('drain', onDrain);
|
|
23
|
+
};
|
|
24
|
+
res.once('error', onError);
|
|
25
|
+
res.once('drain', onDrain);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/ async function writeResponseBody(opts) {
|
|
32
|
+
const { res } = opts;
|
|
33
|
+
try {
|
|
34
|
+
const writableStream = new WritableStream({
|
|
35
|
+
async write (chunk) {
|
|
36
|
+
await writeResponseBodyChunk(res, chunk);
|
|
37
|
+
res.flush?.();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await opts.body.pipeTo(writableStream, {
|
|
41
|
+
signal: opts.signal
|
|
42
|
+
});
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (isAbortError(err)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/ async function writeResponse(opts) {
|
|
53
|
+
const { response, rawResponse } = opts;
|
|
54
|
+
// Only override status code if it hasn't been explicitly set in a procedure etc
|
|
55
|
+
if (rawResponse.statusCode === 200) {
|
|
56
|
+
rawResponse.statusCode = response.status;
|
|
57
|
+
}
|
|
58
|
+
for (const [key, value] of response.headers){
|
|
59
|
+
rawResponse.setHeader(key, value);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
if (response.body) {
|
|
63
|
+
await writeResponseBody({
|
|
64
|
+
res: rawResponse,
|
|
65
|
+
signal: opts.request.signal,
|
|
66
|
+
body: response.body
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (!rawResponse.headersSent) {
|
|
71
|
+
rawResponse.statusCode = 500;
|
|
72
|
+
}
|
|
73
|
+
throw err;
|
|
74
|
+
} finally{
|
|
75
|
+
rawResponse.end();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { writeResponse, writeResponseBody };
|
|
@@ -8,10 +8,13 @@
|
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
10
|
import http from 'http';
|
|
11
|
-
import type
|
|
11
|
+
import { type AnyRouter } from '../@trpc/server';
|
|
12
12
|
import type { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from './node-http';
|
|
13
13
|
export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
|
|
14
14
|
export type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function createHTTPHandler<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.RequestListener;
|
|
16
19
|
export declare function createHTTPServer<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
17
20
|
//# sourceMappingURL=standalone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAOrB,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,IAAI,CAAC,eAAe,CAyBtB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,wEAGxC"}
|
|
@@ -1,27 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var http = require('node:http');
|
|
4
|
-
var
|
|
4
|
+
var utils = require('../unstable-core-do-not-import/utils.js');
|
|
5
|
+
require('../vendor/unpromise/unpromise.js');
|
|
6
|
+
require('../unstable-core-do-not-import/stream/utils/disposable.js');
|
|
5
7
|
require('../unstable-core-do-not-import/rootConfig.js');
|
|
6
8
|
var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
|
|
9
|
+
var incomingMessageToRequest = require('./node-http/incomingMessageToRequest.js');
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/ function createHTTPHandler(opts) {
|
|
14
|
+
return (req, res)=>{
|
|
15
|
+
let path = '';
|
|
16
|
+
utils.run(async ()=>{
|
|
17
|
+
const url = incomingMessageToRequest.createURL(req);
|
|
18
|
+
// get procedure path and remove the leading slash
|
|
19
|
+
// /procedure -> procedure
|
|
20
|
+
path = url.pathname.slice(1);
|
|
21
|
+
await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
|
|
22
|
+
...opts,
|
|
23
|
+
req,
|
|
24
|
+
res,
|
|
25
|
+
path
|
|
26
|
+
});
|
|
27
|
+
}).catch(nodeHTTPRequestHandler.internal_exceptionHandler({
|
|
16
28
|
req,
|
|
17
29
|
res,
|
|
18
|
-
path
|
|
19
|
-
|
|
30
|
+
path,
|
|
31
|
+
...opts
|
|
32
|
+
}));
|
|
20
33
|
};
|
|
21
34
|
}
|
|
22
35
|
function createHTTPServer(opts) {
|
|
23
|
-
|
|
24
|
-
return http.createServer(handler);
|
|
36
|
+
return http.createServer(createHTTPHandler(opts));
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
exports.createHTTPHandler = createHTTPHandler;
|
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { run } from '../unstable-core-do-not-import/utils.mjs';
|
|
3
|
+
import '../vendor/unpromise/unpromise.mjs';
|
|
4
|
+
import '../unstable-core-do-not-import/stream/utils/disposable.mjs';
|
|
3
5
|
import '../unstable-core-do-not-import/rootConfig.mjs';
|
|
4
|
-
import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
|
|
6
|
+
import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
|
|
7
|
+
import { createURL } from './node-http/incomingMessageToRequest.mjs';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/ function createHTTPHandler(opts) {
|
|
12
|
+
return (req, res)=>{
|
|
13
|
+
let path = '';
|
|
14
|
+
run(async ()=>{
|
|
15
|
+
const url = createURL(req);
|
|
16
|
+
// get procedure path and remove the leading slash
|
|
17
|
+
// /procedure -> procedure
|
|
18
|
+
path = url.pathname.slice(1);
|
|
19
|
+
await nodeHTTPRequestHandler({
|
|
20
|
+
...opts,
|
|
21
|
+
req,
|
|
22
|
+
res,
|
|
23
|
+
path
|
|
24
|
+
});
|
|
25
|
+
}).catch(internal_exceptionHandler({
|
|
14
26
|
req,
|
|
15
27
|
res,
|
|
16
|
-
path
|
|
17
|
-
|
|
28
|
+
path,
|
|
29
|
+
...opts
|
|
30
|
+
}));
|
|
18
31
|
};
|
|
19
32
|
}
|
|
20
33
|
function createHTTPServer(opts) {
|
|
21
|
-
|
|
22
|
-
return http.createServer(handler);
|
|
34
|
+
return http.createServer(createHTTPHandler(opts));
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
export { createHTTPHandler, createHTTPServer };
|
package/dist/adapters/ws.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type ws from 'ws';
|
|
|
3
3
|
import type { AnyRouter, CreateContextCallback, inferRouterContext } from '../@trpc/server';
|
|
4
4
|
import { type BaseHandlerOptions } from '../@trpc/server/http';
|
|
5
5
|
import { type MaybePromise } from '../unstable-core-do-not-import';
|
|
6
|
-
import type
|
|
6
|
+
import { type NodeHTTPCreateContextFnOptions } from './node-http';
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
@@ -27,17 +27,27 @@ export type WSSHandlerOptions<TRouter extends AnyRouter> = WSConnectionHandlerOp
|
|
|
27
27
|
enabled: boolean;
|
|
28
28
|
/**
|
|
29
29
|
* Heartbeat interval in milliseconds
|
|
30
|
-
* @default
|
|
30
|
+
* @default 30_000
|
|
31
31
|
*/
|
|
32
32
|
pingMs?: number;
|
|
33
33
|
/**
|
|
34
34
|
* Terminate the WebSocket if no pong is received after this many milliseconds
|
|
35
|
-
* @default
|
|
35
|
+
* @default 5_000
|
|
36
36
|
*/
|
|
37
37
|
pongWaitMs?: number;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Disable responding to ping messages from the client
|
|
41
|
+
* **Not recommended** - this is mainly used for testing
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
dangerouslyDisablePong?: boolean;
|
|
39
45
|
};
|
|
40
|
-
export declare function getWSConnectionHandler<TRouter extends AnyRouter>(opts:
|
|
46
|
+
export declare function getWSConnectionHandler<TRouter extends AnyRouter>(opts: WSSHandlerOptions<TRouter>): (client: ws.WebSocket, req: IncomingMessage) => Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Handle WebSocket keep-alive messages
|
|
49
|
+
*/
|
|
50
|
+
export declare function handleKeepAlive(client: ws.WebSocket, pingMs?: number, pongWaitMs?: number): void;
|
|
41
51
|
export declare function applyWSSHandler<TRouter extends AnyRouter>(opts: WSSHandlerOptions<TRouter>): {
|
|
42
52
|
broadcastReconnectNotification: () => void;
|
|
43
53
|
};
|