@trpc/server 11.0.0-alpha-tmp-subscription-connection-state.489 → 11.0.0-alpha-tmp-12-06-react.667
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 +415 -313
- 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
|
@@ -15,7 +15,7 @@ import type { TRPCResponse } from '../rpc';
|
|
|
15
15
|
import { isPromise, jsonlStreamProducer } from '../stream/jsonl';
|
|
16
16
|
import { sseHeaders, sseStreamProducer } from '../stream/sse';
|
|
17
17
|
import { transformTRPCResponse } from '../transformer';
|
|
18
|
-
import { isAsyncIterable, isObject } from '../utils';
|
|
18
|
+
import { isAsyncIterable, isObject, run } from '../utils';
|
|
19
19
|
import { getRequestInfo } from './contentType';
|
|
20
20
|
import { getHTTPStatusCode } from './getHTTPStatusCode';
|
|
21
21
|
import type {
|
|
@@ -24,6 +24,11 @@ import type {
|
|
|
24
24
|
TRPCRequestInfo,
|
|
25
25
|
} from './types';
|
|
26
26
|
|
|
27
|
+
function errorToAsyncIterable(err: TRPCError): AsyncIterable<never> {
|
|
28
|
+
return run(async function* () {
|
|
29
|
+
throw err;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
27
32
|
type HTTPMethods =
|
|
28
33
|
| 'GET'
|
|
29
34
|
| 'POST'
|
|
@@ -85,8 +90,8 @@ function initResponse<TRouter extends AnyRouter, TRequest>(initOpts: {
|
|
|
85
90
|
const data = eagerGeneration
|
|
86
91
|
? []
|
|
87
92
|
: Array.isArray(untransformedJSON)
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
? untransformedJSON
|
|
94
|
+
: [untransformedJSON];
|
|
90
95
|
|
|
91
96
|
const meta =
|
|
92
97
|
responseMeta?.({
|
|
@@ -194,6 +199,8 @@ function isDataStream(v: unknown) {
|
|
|
194
199
|
);
|
|
195
200
|
}
|
|
196
201
|
|
|
202
|
+
type ResultTuple<T> = [undefined, T] | [TRPCError, undefined];
|
|
203
|
+
|
|
197
204
|
export async function resolveResponse<TRouter extends AnyRouter>(
|
|
198
205
|
opts: ResolveHTTPRequestOptions<TRouter>,
|
|
199
206
|
): Promise<Response> {
|
|
@@ -213,8 +220,64 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
213
220
|
const allowBatching = opts.allowBatching ?? opts.batching?.enabled ?? true;
|
|
214
221
|
const allowMethodOverride =
|
|
215
222
|
(opts.allowMethodOverride ?? false) && req.method === 'POST';
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
|
|
224
|
+
type $Context = inferRouterContext<TRouter>;
|
|
225
|
+
|
|
226
|
+
const infoTuple: ResultTuple<TRPCRequestInfo> = run(() => {
|
|
227
|
+
try {
|
|
228
|
+
return [
|
|
229
|
+
undefined,
|
|
230
|
+
getRequestInfo({
|
|
231
|
+
req,
|
|
232
|
+
path: decodeURIComponent(opts.path),
|
|
233
|
+
router,
|
|
234
|
+
searchParams: url.searchParams,
|
|
235
|
+
headers: opts.req.headers,
|
|
236
|
+
}),
|
|
237
|
+
];
|
|
238
|
+
} catch (cause) {
|
|
239
|
+
return [getTRPCErrorFromUnknown(cause), undefined];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
interface ContextManager {
|
|
244
|
+
valueOrUndefined: () => $Context | undefined;
|
|
245
|
+
value: () => $Context;
|
|
246
|
+
create: (info: TRPCRequestInfo) => Promise<void>;
|
|
247
|
+
}
|
|
248
|
+
const ctxManager: ContextManager = run(() => {
|
|
249
|
+
let result: ResultTuple<$Context> | undefined = undefined;
|
|
250
|
+
return {
|
|
251
|
+
valueOrUndefined: () => {
|
|
252
|
+
if (!result) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
return result[1];
|
|
256
|
+
},
|
|
257
|
+
value: () => {
|
|
258
|
+
const [err, ctx] = result!;
|
|
259
|
+
if (err) {
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
262
|
+
return ctx;
|
|
263
|
+
},
|
|
264
|
+
create: async (info) => {
|
|
265
|
+
if (result) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
'This should only be called once - report a bug in tRPC',
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
const ctx = await opts.createContext({
|
|
272
|
+
info,
|
|
273
|
+
});
|
|
274
|
+
result = [undefined, ctx];
|
|
275
|
+
} catch (cause) {
|
|
276
|
+
result = [getTRPCErrorFromUnknown(cause), undefined];
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
});
|
|
218
281
|
|
|
219
282
|
const methodMapper = allowMethodOverride
|
|
220
283
|
? TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE
|
|
@@ -226,25 +289,12 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
226
289
|
const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
|
|
227
290
|
|
|
228
291
|
const experimentalIterablesAndDeferreds =
|
|
229
|
-
|
|
230
|
-
const experimentalSSE =
|
|
231
|
-
router._def._config.experimental?.sseSubscriptions?.enabled ?? true;
|
|
292
|
+
config.iterablesAndDeferreds ?? true;
|
|
293
|
+
const experimentalSSE = config.sse?.enabled ?? true;
|
|
232
294
|
try {
|
|
233
|
-
info =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
router,
|
|
237
|
-
searchParams: url.searchParams,
|
|
238
|
-
headers: opts.req.headers,
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// we create context early so that error handlers may access context information
|
|
242
|
-
ctx = await opts.createContext({
|
|
243
|
-
info,
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
if (opts.error) {
|
|
247
|
-
throw opts.error;
|
|
295
|
+
const [infoError, info] = infoTuple;
|
|
296
|
+
if (infoError) {
|
|
297
|
+
throw infoError;
|
|
248
298
|
}
|
|
249
299
|
if (info.isBatchCall && !allowBatching) {
|
|
250
300
|
throw new TRPCError({
|
|
@@ -259,13 +309,19 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
259
309
|
code: 'BAD_REQUEST',
|
|
260
310
|
});
|
|
261
311
|
}
|
|
312
|
+
await ctxManager.create(info);
|
|
262
313
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
314
|
+
interface RPCResultOk {
|
|
315
|
+
data: unknown;
|
|
316
|
+
}
|
|
317
|
+
type RPCResult = ResultTuple<RPCResultOk>;
|
|
266
318
|
const rpcCalls = info.calls.map(async (call): Promise<RPCResult> => {
|
|
267
319
|
const proc = call.procedure;
|
|
268
320
|
try {
|
|
321
|
+
if (opts.error) {
|
|
322
|
+
throw opts.error;
|
|
323
|
+
}
|
|
324
|
+
|
|
269
325
|
if (!proc) {
|
|
270
326
|
throw new TRPCError({
|
|
271
327
|
code: 'NOT_FOUND',
|
|
@@ -279,20 +335,24 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
279
335
|
message: `Unsupported ${req.method}-request to ${proc._def.type} procedure at path "${call.path}"`,
|
|
280
336
|
});
|
|
281
337
|
}
|
|
282
|
-
|
|
283
|
-
if (proc._def.type === 'subscription'
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
338
|
+
|
|
339
|
+
if (proc._def.type === 'subscription') {
|
|
340
|
+
/* istanbul ignore if -- @preserve */
|
|
341
|
+
if (info.isBatchCall) {
|
|
342
|
+
throw new TRPCError({
|
|
343
|
+
code: 'BAD_REQUEST',
|
|
344
|
+
message: `Cannot batch subscription calls`,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
288
347
|
}
|
|
289
348
|
const data: unknown = await proc({
|
|
290
349
|
path: call.path,
|
|
291
350
|
getRawInput: call.getRawInput,
|
|
292
|
-
ctx,
|
|
351
|
+
ctx: ctxManager.value(),
|
|
293
352
|
type: proc._def.type,
|
|
353
|
+
signal: opts.req.signal,
|
|
294
354
|
});
|
|
295
|
-
return [data];
|
|
355
|
+
return [undefined, { data }];
|
|
296
356
|
} catch (cause) {
|
|
297
357
|
const error = getTRPCErrorFromUnknown(cause);
|
|
298
358
|
const input = call.result();
|
|
@@ -301,19 +361,19 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
301
361
|
error,
|
|
302
362
|
path: call.path,
|
|
303
363
|
input,
|
|
304
|
-
ctx,
|
|
364
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
305
365
|
type: call.procedure?._def.type ?? 'unknown',
|
|
306
366
|
req: opts.req,
|
|
307
367
|
});
|
|
308
368
|
|
|
309
|
-
return [
|
|
369
|
+
return [error, undefined];
|
|
310
370
|
}
|
|
311
371
|
});
|
|
312
372
|
|
|
313
373
|
// ----------- response handlers -----------
|
|
314
374
|
if (!info.isBatchCall) {
|
|
315
375
|
const [call] = info.calls;
|
|
316
|
-
const [
|
|
376
|
+
const [error, result] = await rpcCalls[0]!;
|
|
317
377
|
|
|
318
378
|
switch (info.type) {
|
|
319
379
|
case 'unknown':
|
|
@@ -322,7 +382,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
322
382
|
// httpLink
|
|
323
383
|
headers.set('content-type', 'application/json');
|
|
324
384
|
|
|
325
|
-
if (isDataStream(data)) {
|
|
385
|
+
if (isDataStream(result?.data)) {
|
|
326
386
|
throw new TRPCError({
|
|
327
387
|
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
328
388
|
message:
|
|
@@ -333,17 +393,17 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
333
393
|
? {
|
|
334
394
|
error: getErrorShape({
|
|
335
395
|
config,
|
|
336
|
-
ctx,
|
|
396
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
337
397
|
error,
|
|
338
398
|
input: call!.result(),
|
|
339
399
|
path: call!.path,
|
|
340
400
|
type: info.type,
|
|
341
401
|
}),
|
|
342
402
|
}
|
|
343
|
-
: { result: { data } };
|
|
403
|
+
: { result: { data: result.data } };
|
|
344
404
|
|
|
345
405
|
const headResponse = initResponse({
|
|
346
|
-
ctx,
|
|
406
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
347
407
|
info,
|
|
348
408
|
responseMeta: opts.responseMeta,
|
|
349
409
|
errors: error ? [error] : [],
|
|
@@ -361,36 +421,61 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
361
421
|
case 'subscription': {
|
|
362
422
|
// httpSubscriptionLink
|
|
363
423
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
424
|
+
const iterable: AsyncIterable<unknown> = run(() => {
|
|
425
|
+
if (error) {
|
|
426
|
+
return errorToAsyncIterable(error);
|
|
427
|
+
}
|
|
428
|
+
if (!experimentalSSE) {
|
|
429
|
+
return errorToAsyncIterable(
|
|
430
|
+
new TRPCError({
|
|
431
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
432
|
+
message: 'Missing experimental flag "sseSubscriptions"',
|
|
433
|
+
}),
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (!isObservable(result.data) && !isAsyncIterable(result.data)) {
|
|
438
|
+
return errorToAsyncIterable(
|
|
439
|
+
new TRPCError({
|
|
440
|
+
message: `Subscription ${
|
|
441
|
+
call!.path
|
|
442
|
+
} did not return an observable or a AsyncGenerator`,
|
|
443
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
444
|
+
}),
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
const dataAsIterable = isObservable(result.data)
|
|
448
|
+
? observableToAsyncIterable(result.data, opts.req.signal)
|
|
449
|
+
: result.data;
|
|
450
|
+
return dataAsIterable;
|
|
451
|
+
});
|
|
370
452
|
|
|
371
|
-
if (!isObservable(data) && !isAsyncIterable(data)) {
|
|
372
|
-
throw new TRPCError({
|
|
373
|
-
message: `Subscription ${
|
|
374
|
-
call!.path
|
|
375
|
-
} did not return an observable or a AsyncGenerator`,
|
|
376
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
const dataAsIterable = isObservable(data)
|
|
380
|
-
? observableToAsyncIterable(data)
|
|
381
|
-
: data;
|
|
382
453
|
const stream = sseStreamProducer({
|
|
383
|
-
...config.
|
|
384
|
-
data:
|
|
454
|
+
...config.sse,
|
|
455
|
+
data: iterable,
|
|
385
456
|
serialize: (v) => config.transformer.output.serialize(v),
|
|
386
457
|
formatError(errorOpts) {
|
|
458
|
+
const error = getTRPCErrorFromUnknown(errorOpts.error);
|
|
459
|
+
const input = call?.result();
|
|
460
|
+
const path = call?.path;
|
|
461
|
+
const type = call?.procedure?._def.type ?? 'unknown';
|
|
462
|
+
|
|
463
|
+
opts.onError?.({
|
|
464
|
+
error,
|
|
465
|
+
path,
|
|
466
|
+
input,
|
|
467
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
468
|
+
req: opts.req,
|
|
469
|
+
type,
|
|
470
|
+
});
|
|
471
|
+
|
|
387
472
|
const shape = getErrorShape({
|
|
388
473
|
config,
|
|
389
|
-
ctx,
|
|
390
|
-
error
|
|
391
|
-
input
|
|
392
|
-
path
|
|
393
|
-
type
|
|
474
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
475
|
+
error,
|
|
476
|
+
input,
|
|
477
|
+
path,
|
|
478
|
+
type,
|
|
394
479
|
});
|
|
395
480
|
|
|
396
481
|
return shape;
|
|
@@ -401,7 +486,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
401
486
|
}
|
|
402
487
|
|
|
403
488
|
const headResponse = initResponse({
|
|
404
|
-
ctx,
|
|
489
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
405
490
|
info,
|
|
406
491
|
responseMeta: opts.responseMeta,
|
|
407
492
|
errors: [],
|
|
@@ -423,7 +508,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
423
508
|
headers.set('content-type', 'application/json');
|
|
424
509
|
headers.set('transfer-encoding', 'chunked');
|
|
425
510
|
const headResponse = initResponse({
|
|
426
|
-
ctx,
|
|
511
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
427
512
|
info,
|
|
428
513
|
responseMeta: opts.responseMeta,
|
|
429
514
|
errors: [],
|
|
@@ -446,14 +531,15 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
446
531
|
*/
|
|
447
532
|
maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
|
|
448
533
|
data: rpcCalls.map(async (res) => {
|
|
449
|
-
const [
|
|
534
|
+
const [error, result] = await res;
|
|
535
|
+
|
|
536
|
+
const call = info.calls[0];
|
|
450
537
|
|
|
451
|
-
const call = info!.calls[0];
|
|
452
538
|
if (error) {
|
|
453
539
|
return {
|
|
454
540
|
error: getErrorShape({
|
|
455
541
|
config,
|
|
456
|
-
ctx,
|
|
542
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
457
543
|
error,
|
|
458
544
|
input: call!.result(),
|
|
459
545
|
path: call!.path,
|
|
@@ -466,12 +552,12 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
466
552
|
* Not very pretty, but we need to wrap nested data in promises
|
|
467
553
|
* Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
|
|
468
554
|
*/
|
|
469
|
-
const
|
|
470
|
-
? observableToAsyncIterable(result)
|
|
471
|
-
: Promise.resolve(result);
|
|
555
|
+
const iterable = isObservable(result.data)
|
|
556
|
+
? observableToAsyncIterable(result.data, opts.req.signal)
|
|
557
|
+
: Promise.resolve(result.data);
|
|
472
558
|
return {
|
|
473
559
|
result: Promise.resolve({
|
|
474
|
-
data,
|
|
560
|
+
data: iterable,
|
|
475
561
|
}),
|
|
476
562
|
};
|
|
477
563
|
}),
|
|
@@ -481,7 +567,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
481
567
|
error: getTRPCErrorFromUnknown(cause),
|
|
482
568
|
path: undefined,
|
|
483
569
|
input: undefined,
|
|
484
|
-
ctx,
|
|
570
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
485
571
|
req: opts.req,
|
|
486
572
|
type: info?.type ?? 'unknown',
|
|
487
573
|
});
|
|
@@ -490,13 +576,20 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
490
576
|
formatError(errorOpts) {
|
|
491
577
|
const call = info?.calls[errorOpts.path[0] as any];
|
|
492
578
|
|
|
579
|
+
const error = getTRPCErrorFromUnknown(errorOpts.error);
|
|
580
|
+
const input = call?.result();
|
|
581
|
+
const path = call?.path;
|
|
582
|
+
const type = call?.procedure?._def.type ?? 'unknown';
|
|
583
|
+
|
|
584
|
+
// no need to call `onError` here as it will be propagated through the stream itself
|
|
585
|
+
|
|
493
586
|
const shape = getErrorShape({
|
|
494
587
|
config,
|
|
495
|
-
ctx,
|
|
496
|
-
error
|
|
497
|
-
input
|
|
498
|
-
path
|
|
499
|
-
type
|
|
588
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
589
|
+
error,
|
|
590
|
+
input,
|
|
591
|
+
path,
|
|
592
|
+
type,
|
|
500
593
|
});
|
|
501
594
|
|
|
502
595
|
return shape;
|
|
@@ -519,19 +612,19 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
519
612
|
headers.set('content-type', 'application/json');
|
|
520
613
|
const results: RPCResult[] = (await Promise.all(rpcCalls)).map(
|
|
521
614
|
(res): RPCResult => {
|
|
522
|
-
const [
|
|
615
|
+
const [error, result] = res;
|
|
523
616
|
if (error) {
|
|
524
617
|
return res;
|
|
525
618
|
}
|
|
526
619
|
|
|
527
|
-
if (isDataStream(data)) {
|
|
620
|
+
if (isDataStream(result.data)) {
|
|
528
621
|
return [
|
|
529
|
-
null,
|
|
530
622
|
new TRPCError({
|
|
531
623
|
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
532
624
|
message:
|
|
533
625
|
'Cannot use stream-like response in non-streaming request - use httpBatchStreamLink',
|
|
534
626
|
}),
|
|
627
|
+
undefined,
|
|
535
628
|
];
|
|
536
629
|
}
|
|
537
630
|
return res;
|
|
@@ -539,15 +632,15 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
539
632
|
);
|
|
540
633
|
const resultAsRPCResponse = results.map(
|
|
541
634
|
(
|
|
542
|
-
[
|
|
635
|
+
[error, result],
|
|
543
636
|
index,
|
|
544
637
|
): TRPCResponse<unknown, inferRouterError<TRouter>> => {
|
|
545
|
-
const call = info
|
|
638
|
+
const call = info.calls[index]!;
|
|
546
639
|
if (error) {
|
|
547
640
|
return {
|
|
548
641
|
error: getErrorShape({
|
|
549
642
|
config,
|
|
550
|
-
ctx,
|
|
643
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
551
644
|
error,
|
|
552
645
|
input: call.result(),
|
|
553
646
|
path: call.path,
|
|
@@ -556,17 +649,17 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
556
649
|
};
|
|
557
650
|
}
|
|
558
651
|
return {
|
|
559
|
-
result: { data },
|
|
652
|
+
result: { data: result.data },
|
|
560
653
|
};
|
|
561
654
|
},
|
|
562
655
|
);
|
|
563
656
|
|
|
564
657
|
const errors = results
|
|
565
|
-
.map(([
|
|
658
|
+
.map(([error]) => error)
|
|
566
659
|
.filter(Boolean) as TRPCError[];
|
|
567
660
|
|
|
568
661
|
const headResponse = initResponse({
|
|
569
|
-
ctx,
|
|
662
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
570
663
|
info,
|
|
571
664
|
responseMeta: opts.responseMeta,
|
|
572
665
|
untransformedJSON: resultAsRPCResponse,
|
|
@@ -582,6 +675,8 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
582
675
|
},
|
|
583
676
|
);
|
|
584
677
|
} catch (cause) {
|
|
678
|
+
const [_infoError, info] = infoTuple;
|
|
679
|
+
const ctx = ctxManager.valueOrUndefined();
|
|
585
680
|
// we get here if
|
|
586
681
|
// - batching is called when it's not enabled
|
|
587
682
|
// - `createContext()` throws
|
|
@@ -591,7 +686,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
|
|
|
591
686
|
// - `errorFormatter` return value is malformed
|
|
592
687
|
const { error, untransformedJSON, body } = caughtErrorToData(cause, {
|
|
593
688
|
opts,
|
|
594
|
-
ctx,
|
|
689
|
+
ctx: ctxManager.valueOrUndefined(),
|
|
595
690
|
type: info?.type ?? 'unknown',
|
|
596
691
|
});
|
|
597
692
|
|
|
@@ -50,7 +50,7 @@ export interface HTTPBaseHandlerOptions<TRouter extends AnyRouter, TRequest>
|
|
|
50
50
|
/**
|
|
51
51
|
* Add handler to be called before response is sent to the user
|
|
52
52
|
* Useful for setting cache headers
|
|
53
|
-
* @
|
|
53
|
+
* @see https://trpc.io/docs/v11/caching
|
|
54
54
|
*/
|
|
55
55
|
responseMeta?: ResponseMetaFn<TRouter>;
|
|
56
56
|
}
|
|
@@ -16,12 +16,8 @@ import type { DataTransformerOptions } from './transformer';
|
|
|
16
16
|
import { defaultTransformer, getDataTransformer } from './transformer';
|
|
17
17
|
import type { Unwrap, ValidateShape } from './types';
|
|
18
18
|
|
|
19
|
-
type inferErrorFormatterShape<TType> =
|
|
20
|
-
any,
|
|
21
|
-
infer TShape
|
|
22
|
-
>
|
|
23
|
-
? TShape
|
|
24
|
-
: DefaultErrorShape;
|
|
19
|
+
type inferErrorFormatterShape<TType> =
|
|
20
|
+
TType extends ErrorFormatter<any, infer TShape> ? TShape : DefaultErrorShape;
|
|
25
21
|
interface RuntimeConfigOptions<TContext extends object, TMeta extends object>
|
|
26
22
|
extends Partial<
|
|
27
23
|
Omit<
|
|
@@ -36,7 +32,7 @@ interface RuntimeConfigOptions<TContext extends object, TMeta extends object>
|
|
|
36
32
|
> {
|
|
37
33
|
/**
|
|
38
34
|
* Use a data transformer
|
|
39
|
-
* @
|
|
35
|
+
* @see https://trpc.io/docs/v11/data-transformers
|
|
40
36
|
*/
|
|
41
37
|
transformer?: DataTransformerOptions;
|
|
42
38
|
}
|
|
@@ -46,7 +42,7 @@ type ContextCallback = (...args: any[]) => object | Promise<object>;
|
|
|
46
42
|
class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
47
43
|
/**
|
|
48
44
|
* Add a context shape as a generic to the root object
|
|
49
|
-
* @
|
|
45
|
+
* @see https://trpc.io/docs/v11/server/context
|
|
50
46
|
*/
|
|
51
47
|
context<TNewContext extends object | ContextCallback>() {
|
|
52
48
|
return new TRPCBuilder<
|
|
@@ -57,7 +53,7 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
57
53
|
|
|
58
54
|
/**
|
|
59
55
|
* Add a meta shape as a generic to the root object
|
|
60
|
-
* @
|
|
56
|
+
* @see https://trpc.io/docs/v11/quickstart
|
|
61
57
|
*/
|
|
62
58
|
meta<TNewMeta extends object>() {
|
|
63
59
|
return new TRPCBuilder<TContext, TNewMeta>();
|
|
@@ -65,12 +61,10 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
63
|
* Create the root object
|
|
68
|
-
* @
|
|
64
|
+
* @see https://trpc.io/docs/v11/server/routers#initialize-trpc
|
|
69
65
|
*/
|
|
70
66
|
create<TOptions extends RuntimeConfigOptions<TContext, TMeta>>(
|
|
71
|
-
opts?:
|
|
72
|
-
| ValidateShape<TOptions, RuntimeConfigOptions<TContext, TMeta>>
|
|
73
|
-
| undefined,
|
|
67
|
+
opts?: ValidateShape<TOptions, RuntimeConfigOptions<TContext, TMeta>>,
|
|
74
68
|
) {
|
|
75
69
|
type $Root = CreateRootTypes<{
|
|
76
70
|
ctx: TContext;
|
|
@@ -82,6 +76,7 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
82
76
|
}>;
|
|
83
77
|
|
|
84
78
|
const config: RootConfig<$Root> = {
|
|
79
|
+
...opts,
|
|
85
80
|
transformer: getDataTransformer(opts?.transformer ?? defaultTransformer),
|
|
86
81
|
isDev:
|
|
87
82
|
opts?.isDev ??
|
|
@@ -95,7 +90,6 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
95
90
|
* @internal
|
|
96
91
|
*/
|
|
97
92
|
$types: null as any,
|
|
98
|
-
experimental: opts?.experimental ?? {},
|
|
99
93
|
};
|
|
100
94
|
|
|
101
95
|
{
|
|
@@ -116,29 +110,29 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
116
110
|
_config: config,
|
|
117
111
|
/**
|
|
118
112
|
* Builder object for creating procedures
|
|
119
|
-
* @
|
|
113
|
+
* @see https://trpc.io/docs/v11/server/procedures
|
|
120
114
|
*/
|
|
121
115
|
procedure: createBuilder<$Root['ctx'], $Root['meta']>({
|
|
122
116
|
meta: opts?.defaultMeta,
|
|
123
117
|
}),
|
|
124
118
|
/**
|
|
125
119
|
* Create reusable middlewares
|
|
126
|
-
* @
|
|
120
|
+
* @see https://trpc.io/docs/v11/server/middlewares
|
|
127
121
|
*/
|
|
128
122
|
middleware: createMiddlewareFactory<$Root['ctx'], $Root['meta']>(),
|
|
129
123
|
/**
|
|
130
124
|
* Create a router
|
|
131
|
-
* @
|
|
125
|
+
* @see https://trpc.io/docs/v11/server/routers
|
|
132
126
|
*/
|
|
133
127
|
router: createRouterFactory<$Root>(config),
|
|
134
128
|
/**
|
|
135
129
|
* Merge Routers
|
|
136
|
-
* @
|
|
130
|
+
* @see https://trpc.io/docs/v11/server/merging-routers
|
|
137
131
|
*/
|
|
138
132
|
mergeRouters,
|
|
139
133
|
/**
|
|
140
134
|
* Create a server-side caller for a router
|
|
141
|
-
* @
|
|
135
|
+
* @see https://trpc.io/docs/v11/server/server-side-calls
|
|
142
136
|
*/
|
|
143
137
|
createCallerFactory: createCallerFactory<$Root>(),
|
|
144
138
|
};
|
|
@@ -147,7 +141,7 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
147
141
|
|
|
148
142
|
/**
|
|
149
143
|
* Builder to initialize the tRPC root object - use this exactly once per backend
|
|
150
|
-
* @
|
|
144
|
+
* @see https://trpc.io/docs/v11/quickstart
|
|
151
145
|
*/
|
|
152
146
|
export const initTRPC = new TRPCBuilder();
|
|
153
147
|
export type { TRPCBuilder };
|
|
@@ -100,15 +100,16 @@ export type MiddlewareFunction<
|
|
|
100
100
|
input: TInputOut;
|
|
101
101
|
getRawInput: GetRawInputFn;
|
|
102
102
|
meta: TMeta | undefined;
|
|
103
|
+
signal: AbortSignal | undefined;
|
|
103
104
|
next: {
|
|
104
105
|
(): Promise<MiddlewareResult<TContextOverridesIn>>;
|
|
105
106
|
<$ContextOverride>(opts: {
|
|
106
107
|
ctx?: $ContextOverride;
|
|
107
108
|
input?: unknown;
|
|
108
109
|
}): Promise<MiddlewareResult<$ContextOverride>>;
|
|
109
|
-
(opts: {
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
(opts: {
|
|
111
|
+
getRawInput: GetRawInputFn;
|
|
112
|
+
}): Promise<MiddlewareResult<TContextOverridesIn>>;
|
|
112
113
|
};
|
|
113
114
|
}): Promise<MiddlewareResult<$ContextOverridesOut>>;
|
|
114
115
|
_type?: string | undefined;
|
|
@@ -157,7 +158,7 @@ export function createMiddlewareFactory<
|
|
|
157
158
|
|
|
158
159
|
/**
|
|
159
160
|
* Create a standalone middleware
|
|
160
|
-
* @
|
|
161
|
+
* @see https://trpc.io/docs/v11/server/middlewares#experimental-standalone-middlewares
|
|
161
162
|
* @deprecated use `.unstable_concat()` instead
|
|
162
163
|
*/
|
|
163
164
|
export const experimental_standaloneMiddleware = <
|