@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
|
@@ -13,6 +13,11 @@ export type ParserValibotEsque<TInput, TParsedInput> = {
|
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
export type ParserArkTypeEsque<TInput, TParsedInput> = {
|
|
17
|
+
inferIn: TInput;
|
|
18
|
+
infer: TParsedInput;
|
|
19
|
+
};
|
|
20
|
+
|
|
16
21
|
export type ParserMyZodEsque<TInput> = {
|
|
17
22
|
parse: (input: any) => TInput;
|
|
18
23
|
};
|
|
@@ -42,7 +47,8 @@ export type ParserWithoutInput<TInput> =
|
|
|
42
47
|
|
|
43
48
|
export type ParserWithInputOutput<TInput, TParsedInput> =
|
|
44
49
|
| ParserZodEsque<TInput, TParsedInput>
|
|
45
|
-
| ParserValibotEsque<TInput, TParsedInput
|
|
50
|
+
| ParserValibotEsque<TInput, TParsedInput>
|
|
51
|
+
| ParserArkTypeEsque<TInput, TParsedInput>;
|
|
46
52
|
|
|
47
53
|
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
48
54
|
|
|
@@ -53,17 +59,22 @@ export type inferParser<TParser extends Parser> =
|
|
|
53
59
|
out: $TOut;
|
|
54
60
|
}
|
|
55
61
|
: TParser extends ParserWithoutInput<infer $InOut>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
? {
|
|
63
|
+
in: $InOut;
|
|
64
|
+
out: $InOut;
|
|
65
|
+
}
|
|
66
|
+
: never;
|
|
61
67
|
|
|
62
68
|
export type ParseFn<TType> = (value: unknown) => Promise<TType> | TType;
|
|
63
69
|
|
|
64
70
|
export function getParseFn<TType>(procedureParser: Parser): ParseFn<TType> {
|
|
65
71
|
const parser = procedureParser as any;
|
|
66
72
|
|
|
73
|
+
if (typeof parser === 'function' && typeof parser.assert === 'function') {
|
|
74
|
+
// ParserArkTypeEsque - arktype schemas shouldn't be called as a function because they return a union type instead of throwing
|
|
75
|
+
return parser.assert.bind(parser);
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
if (typeof parser === 'function') {
|
|
68
79
|
// ParserValibotEsque (>= v0.31.0)
|
|
69
80
|
// ParserCustomValidatorEsque
|
|
@@ -66,10 +66,25 @@ export interface MutationProcedure<TDef extends BuiltProcedureDef>
|
|
|
66
66
|
export interface SubscriptionProcedure<TDef extends BuiltProcedureDef>
|
|
67
67
|
extends Procedure<'subscription', TDef> {}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated
|
|
71
|
+
*/
|
|
72
|
+
export interface LegacyObservableSubscriptionProcedure<
|
|
73
|
+
TDef extends BuiltProcedureDef,
|
|
74
|
+
> extends SubscriptionProcedure<TDef> {
|
|
75
|
+
_observable: true;
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
export type AnyQueryProcedure = QueryProcedure<any>;
|
|
70
79
|
export type AnyMutationProcedure = MutationProcedure<any>;
|
|
71
|
-
export type AnySubscriptionProcedure =
|
|
72
|
-
|
|
80
|
+
export type AnySubscriptionProcedure =
|
|
81
|
+
| SubscriptionProcedure<any>
|
|
82
|
+
| LegacyObservableSubscriptionProcedure<any>;
|
|
83
|
+
|
|
84
|
+
export type AnyProcedure =
|
|
85
|
+
| AnyQueryProcedure
|
|
86
|
+
| AnyMutationProcedure
|
|
87
|
+
| AnySubscriptionProcedure;
|
|
73
88
|
|
|
74
89
|
export type inferProcedureInput<TProcedure extends AnyProcedure> =
|
|
75
90
|
undefined extends inferProcedureParams<TProcedure>['$types']['input']
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { inferObservableValue } from '../observable';
|
|
1
|
+
import type { inferObservableValue, Observable } from '../observable';
|
|
2
2
|
import { getTRPCErrorFromUnknown, TRPCError } from './error/TRPCError';
|
|
3
3
|
import type {
|
|
4
4
|
AnyMiddlewareFunction,
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
AnyMutationProcedure,
|
|
18
18
|
AnyProcedure,
|
|
19
19
|
AnyQueryProcedure,
|
|
20
|
-
|
|
20
|
+
LegacyObservableSubscriptionProcedure,
|
|
21
21
|
MutationProcedure,
|
|
22
22
|
ProcedureType,
|
|
23
23
|
QueryProcedure,
|
|
@@ -37,18 +37,29 @@ import { mergeWithoutOverrides } from './utils';
|
|
|
37
37
|
type IntersectIfDefined<TType, TWith> = TType extends UnsetMarker
|
|
38
38
|
? TWith
|
|
39
39
|
: TWith extends UnsetMarker
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
? TType
|
|
41
|
+
: Simplify<TType & TWith>;
|
|
42
|
+
|
|
43
43
|
type DefaultValue<TValue, TFallback> = TValue extends UnsetMarker
|
|
44
44
|
? TFallback
|
|
45
45
|
: TValue;
|
|
46
46
|
|
|
47
|
-
type
|
|
48
|
-
infer $
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
type inferAsyncIterable<TOutput> =
|
|
48
|
+
TOutput extends AsyncIterable<infer $Yield, infer $Return, infer $Next>
|
|
49
|
+
? {
|
|
50
|
+
yield: $Yield;
|
|
51
|
+
return: $Return;
|
|
52
|
+
next: $Next;
|
|
53
|
+
}
|
|
54
|
+
: never;
|
|
55
|
+
type inferSubscriptionOutput<TOutput> =
|
|
56
|
+
TOutput extends AsyncIterable<any>
|
|
57
|
+
? AsyncIterable<
|
|
58
|
+
inferTrackedOutput<inferAsyncIterable<TOutput>['yield']>,
|
|
59
|
+
inferAsyncIterable<TOutput>['return'],
|
|
60
|
+
inferAsyncIterable<TOutput>['next']
|
|
61
|
+
>
|
|
62
|
+
: TypeError<'Subscription output could not be inferred'>;
|
|
52
63
|
|
|
53
64
|
export type CallerOverride<TContext> = (opts: {
|
|
54
65
|
args: unknown[];
|
|
@@ -92,6 +103,10 @@ export interface ProcedureResolverOptions<
|
|
|
92
103
|
> {
|
|
93
104
|
ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
|
|
94
105
|
input: TInputOut extends UnsetMarker ? undefined : TInputOut;
|
|
106
|
+
/**
|
|
107
|
+
* The AbortSignal of the request
|
|
108
|
+
*/
|
|
109
|
+
signal: AbortSignal | undefined;
|
|
95
110
|
}
|
|
96
111
|
|
|
97
112
|
/**
|
|
@@ -129,35 +144,36 @@ export type AnyProcedureBuilder = ProcedureBuilder<
|
|
|
129
144
|
*/
|
|
130
145
|
export type inferProcedureBuilderResolverOptions<
|
|
131
146
|
TProcedureBuilder extends AnyProcedureBuilder,
|
|
132
|
-
> =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
147
|
+
> =
|
|
148
|
+
TProcedureBuilder extends ProcedureBuilder<
|
|
149
|
+
infer TContext,
|
|
150
|
+
infer TMeta,
|
|
151
|
+
infer TContextOverrides,
|
|
152
|
+
infer _TInputIn,
|
|
153
|
+
infer TInputOut,
|
|
154
|
+
infer _TOutputIn,
|
|
155
|
+
infer _TOutputOut,
|
|
156
|
+
infer _TCaller
|
|
157
|
+
>
|
|
158
|
+
? ProcedureResolverOptions<
|
|
159
|
+
TContext,
|
|
160
|
+
TMeta,
|
|
161
|
+
TContextOverrides,
|
|
162
|
+
TInputOut extends UnsetMarker
|
|
163
|
+
? // if input is not set, we don't want to infer it as `undefined` since a procedure further down the chain might have set an input
|
|
164
|
+
unknown
|
|
165
|
+
: TInputOut extends object
|
|
166
|
+
? Simplify<
|
|
167
|
+
TInputOut & {
|
|
168
|
+
/**
|
|
169
|
+
* Extra input params might have been added by a `.input()` further down the chain
|
|
170
|
+
*/
|
|
171
|
+
[keyAddedByInputCallFurtherDown: string]: unknown;
|
|
172
|
+
}
|
|
173
|
+
>
|
|
174
|
+
: TInputOut
|
|
175
|
+
>
|
|
176
|
+
: never;
|
|
161
177
|
|
|
162
178
|
export interface ProcedureBuilder<
|
|
163
179
|
TContext,
|
|
@@ -171,20 +187,20 @@ export interface ProcedureBuilder<
|
|
|
171
187
|
> {
|
|
172
188
|
/**
|
|
173
189
|
* Add an input parser to the procedure.
|
|
174
|
-
* @
|
|
190
|
+
* @see https://trpc.io/docs/v11/server/validators
|
|
175
191
|
*/
|
|
176
192
|
input<$Parser extends Parser>(
|
|
177
193
|
schema: TInputOut extends UnsetMarker
|
|
178
194
|
? $Parser
|
|
179
195
|
: inferParser<$Parser>['out'] extends Record<string, unknown> | undefined
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
? TInputOut extends Record<string, unknown> | undefined
|
|
197
|
+
? undefined extends inferParser<$Parser>['out'] // if current is optional the previous must be too
|
|
198
|
+
? undefined extends TInputOut
|
|
199
|
+
? $Parser
|
|
200
|
+
: TypeError<'Cannot chain an optional parser to a required parser'>
|
|
201
|
+
: $Parser
|
|
202
|
+
: TypeError<'All input parsers did not resolve to an object'>
|
|
203
|
+
: TypeError<'All input parsers did not resolve to an object'>,
|
|
188
204
|
): ProcedureBuilder<
|
|
189
205
|
TContext,
|
|
190
206
|
TMeta,
|
|
@@ -197,7 +213,7 @@ export interface ProcedureBuilder<
|
|
|
197
213
|
>;
|
|
198
214
|
/**
|
|
199
215
|
* Add an output parser to the procedure.
|
|
200
|
-
* @
|
|
216
|
+
* @see https://trpc.io/docs/v11/server/validators
|
|
201
217
|
*/
|
|
202
218
|
output<$Parser extends Parser>(
|
|
203
219
|
schema: $Parser,
|
|
@@ -213,7 +229,7 @@ export interface ProcedureBuilder<
|
|
|
213
229
|
>;
|
|
214
230
|
/**
|
|
215
231
|
* Add a meta data to the procedure.
|
|
216
|
-
* @
|
|
232
|
+
* @see https://trpc.io/docs/v11/server/metadata
|
|
217
233
|
*/
|
|
218
234
|
meta(
|
|
219
235
|
meta: TMeta,
|
|
@@ -229,7 +245,7 @@ export interface ProcedureBuilder<
|
|
|
229
245
|
>;
|
|
230
246
|
/**
|
|
231
247
|
* Add a middleware to the procedure.
|
|
232
|
-
* @
|
|
248
|
+
* @see https://trpc.io/docs/v11/server/middlewares
|
|
233
249
|
*/
|
|
234
250
|
use<$ContextOverridesOut>(
|
|
235
251
|
fn:
|
|
@@ -295,7 +311,7 @@ export interface ProcedureBuilder<
|
|
|
295
311
|
>;
|
|
296
312
|
/**
|
|
297
313
|
* Query procedure
|
|
298
|
-
* @
|
|
314
|
+
* @see https://trpc.io/docs/v11/concepts#vocabulary
|
|
299
315
|
*/
|
|
300
316
|
query<$Output>(
|
|
301
317
|
resolver: ProcedureResolver<
|
|
@@ -317,7 +333,7 @@ export interface ProcedureBuilder<
|
|
|
317
333
|
|
|
318
334
|
/**
|
|
319
335
|
* Mutation procedure
|
|
320
|
-
* @
|
|
336
|
+
* @see https://trpc.io/docs/v11/concepts#vocabulary
|
|
321
337
|
*/
|
|
322
338
|
mutation<$Output>(
|
|
323
339
|
resolver: ProcedureResolver<
|
|
@@ -339,9 +355,9 @@ export interface ProcedureBuilder<
|
|
|
339
355
|
|
|
340
356
|
/**
|
|
341
357
|
* Subscription procedure
|
|
342
|
-
* @
|
|
358
|
+
* @see https://trpc.io/docs/v11/server/subscriptions
|
|
343
359
|
*/
|
|
344
|
-
subscription<$Output
|
|
360
|
+
subscription<$Output extends AsyncIterable<any, void, any>>(
|
|
345
361
|
resolver: ProcedureResolver<
|
|
346
362
|
TContext,
|
|
347
363
|
TMeta,
|
|
@@ -354,9 +370,28 @@ export interface ProcedureBuilder<
|
|
|
354
370
|
? TypeError<'Not implemented'>
|
|
355
371
|
: SubscriptionProcedure<{
|
|
356
372
|
input: DefaultValue<TInputIn, void>;
|
|
357
|
-
output: DefaultValue<TOutputOut,
|
|
373
|
+
output: inferSubscriptionOutput<DefaultValue<TOutputOut, $Output>>;
|
|
374
|
+
}>;
|
|
375
|
+
/**
|
|
376
|
+
* @deprecated Using subscriptions with an observable is deprecated. Use an async generator instead.
|
|
377
|
+
* This feature will be removed in v12 of tRPC.
|
|
378
|
+
* @see https://trpc.io/docs/v11/server/subscriptions
|
|
379
|
+
*/
|
|
380
|
+
subscription<$Output extends Observable<any, any>>(
|
|
381
|
+
resolver: ProcedureResolver<
|
|
382
|
+
TContext,
|
|
383
|
+
TMeta,
|
|
384
|
+
TContextOverrides,
|
|
385
|
+
TInputOut,
|
|
386
|
+
TOutputIn,
|
|
387
|
+
$Output
|
|
388
|
+
>,
|
|
389
|
+
): TCaller extends true
|
|
390
|
+
? TypeError<'Not implemented'>
|
|
391
|
+
: LegacyObservableSubscriptionProcedure<{
|
|
392
|
+
input: DefaultValue<TInputIn, void>;
|
|
393
|
+
output: inferObservableValue<DefaultValue<TOutputOut, $Output>>;
|
|
358
394
|
}>;
|
|
359
|
-
|
|
360
395
|
/**
|
|
361
396
|
* Overrides the way a procedure is invoked
|
|
362
397
|
* Do not use this unless you know what you're doing - this is an experimental API
|
|
@@ -394,7 +429,7 @@ function createNewBuilder(
|
|
|
394
429
|
...mergeWithoutOverrides(def1, rest),
|
|
395
430
|
inputs: [...def1.inputs, ...(inputs ?? [])],
|
|
396
431
|
middlewares: [...def1.middlewares, ...middlewares],
|
|
397
|
-
meta: def1.meta && meta ? { ...def1.meta, ...meta } : meta ?? def1.meta,
|
|
432
|
+
meta: def1.meta && meta ? { ...def1.meta, ...meta } : (meta ?? def1.meta),
|
|
398
433
|
});
|
|
399
434
|
}
|
|
400
435
|
|
|
@@ -464,11 +499,8 @@ export function createBuilder<TContext, TMeta>(
|
|
|
464
499
|
resolver,
|
|
465
500
|
) as AnyMutationProcedure;
|
|
466
501
|
},
|
|
467
|
-
subscription(resolver) {
|
|
468
|
-
return createResolver(
|
|
469
|
-
{ ..._def, type: 'subscription' },
|
|
470
|
-
resolver,
|
|
471
|
-
) as AnySubscriptionProcedure;
|
|
502
|
+
subscription(resolver: ProcedureResolver<any, any, any, any, any, any>) {
|
|
503
|
+
return createResolver({ ..._def, type: 'subscription' }, resolver) as any;
|
|
472
504
|
},
|
|
473
505
|
experimental_caller(caller) {
|
|
474
506
|
return createNewBuilder(_def, {
|
|
@@ -532,6 +564,7 @@ export interface ProcedureCallOptions<TContext> {
|
|
|
532
564
|
input?: unknown;
|
|
533
565
|
path: string;
|
|
534
566
|
type: ProcedureType;
|
|
567
|
+
signal: AbortSignal | undefined;
|
|
535
568
|
}
|
|
536
569
|
|
|
537
570
|
const codeblock = `
|
|
@@ -539,6 +572,46 @@ This is a client-only function.
|
|
|
539
572
|
If you want to call this function on the server, see https://trpc.io/docs/v11/server/server-side-calls
|
|
540
573
|
`.trim();
|
|
541
574
|
|
|
575
|
+
// run the middlewares recursively with the resolver as the last one
|
|
576
|
+
async function callRecursive(
|
|
577
|
+
index: number,
|
|
578
|
+
_def: AnyProcedureBuilderDef,
|
|
579
|
+
opts: ProcedureCallOptions<any>,
|
|
580
|
+
): Promise<MiddlewareResult<any>> {
|
|
581
|
+
try {
|
|
582
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
583
|
+
const middleware = _def.middlewares[index]!;
|
|
584
|
+
const result = await middleware({
|
|
585
|
+
...opts,
|
|
586
|
+
meta: _def.meta,
|
|
587
|
+
input: opts.input,
|
|
588
|
+
next(_nextOpts?: any) {
|
|
589
|
+
const nextOpts = _nextOpts as
|
|
590
|
+
| {
|
|
591
|
+
ctx?: Record<string, unknown>;
|
|
592
|
+
input?: unknown;
|
|
593
|
+
getRawInput?: GetRawInputFn;
|
|
594
|
+
}
|
|
595
|
+
| undefined;
|
|
596
|
+
|
|
597
|
+
return callRecursive(index + 1, _def, {
|
|
598
|
+
...opts,
|
|
599
|
+
ctx: nextOpts?.ctx ? { ...opts.ctx, ...nextOpts.ctx } : opts.ctx,
|
|
600
|
+
input: nextOpts && 'input' in nextOpts ? nextOpts.input : opts.input,
|
|
601
|
+
getRawInput: nextOpts?.getRawInput ?? opts.getRawInput,
|
|
602
|
+
});
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
return result;
|
|
606
|
+
} catch (cause) {
|
|
607
|
+
return {
|
|
608
|
+
ok: false,
|
|
609
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
610
|
+
marker: middlewareMarker,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
542
615
|
function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
543
616
|
async function procedure(opts: ProcedureCallOptions<unknown>) {
|
|
544
617
|
// is direct server-side call
|
|
@@ -546,66 +619,8 @@ function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
|
546
619
|
throw new Error(codeblock);
|
|
547
620
|
}
|
|
548
621
|
|
|
549
|
-
// run the middlewares recursively with the resolver as the last one
|
|
550
|
-
async function callRecursive(
|
|
551
|
-
callOpts: {
|
|
552
|
-
ctx: any;
|
|
553
|
-
index: number;
|
|
554
|
-
input?: unknown;
|
|
555
|
-
getRawInput?: GetRawInputFn;
|
|
556
|
-
} = {
|
|
557
|
-
index: 0,
|
|
558
|
-
ctx: opts.ctx,
|
|
559
|
-
},
|
|
560
|
-
): Promise<MiddlewareResult<any>> {
|
|
561
|
-
try {
|
|
562
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
563
|
-
const middleware = _def.middlewares[callOpts.index]!;
|
|
564
|
-
const result = await middleware({
|
|
565
|
-
ctx: callOpts.ctx,
|
|
566
|
-
type: opts.type,
|
|
567
|
-
path: opts.path,
|
|
568
|
-
getRawInput: callOpts.getRawInput ?? opts.getRawInput,
|
|
569
|
-
meta: _def.meta,
|
|
570
|
-
input: callOpts.input,
|
|
571
|
-
next(_nextOpts?: any) {
|
|
572
|
-
const nextOpts = _nextOpts as
|
|
573
|
-
| {
|
|
574
|
-
ctx?: Record<string, unknown>;
|
|
575
|
-
input?: unknown;
|
|
576
|
-
getRawInput?: GetRawInputFn;
|
|
577
|
-
}
|
|
578
|
-
| undefined;
|
|
579
|
-
|
|
580
|
-
return callRecursive({
|
|
581
|
-
index: callOpts.index + 1,
|
|
582
|
-
ctx:
|
|
583
|
-
nextOpts && 'ctx' in nextOpts
|
|
584
|
-
? { ...callOpts.ctx, ...nextOpts.ctx }
|
|
585
|
-
: callOpts.ctx,
|
|
586
|
-
input:
|
|
587
|
-
nextOpts && 'input' in nextOpts
|
|
588
|
-
? nextOpts.input
|
|
589
|
-
: callOpts.input,
|
|
590
|
-
getRawInput:
|
|
591
|
-
nextOpts && 'getRawInput' in nextOpts
|
|
592
|
-
? nextOpts.getRawInput
|
|
593
|
-
: callOpts.getRawInput,
|
|
594
|
-
});
|
|
595
|
-
},
|
|
596
|
-
});
|
|
597
|
-
return result;
|
|
598
|
-
} catch (cause) {
|
|
599
|
-
return {
|
|
600
|
-
ok: false,
|
|
601
|
-
error: getTRPCErrorFromUnknown(cause),
|
|
602
|
-
marker: middlewareMarker,
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
622
|
// there's always at least one "next" since we wrap this.resolver in a middleware
|
|
608
|
-
const result = await callRecursive();
|
|
623
|
+
const result = await callRecursive(0, _def, opts);
|
|
609
624
|
|
|
610
625
|
if (!result) {
|
|
611
626
|
throw new TRPCError({
|
|
@@ -36,12 +36,12 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
36
36
|
$types: TTypes;
|
|
37
37
|
/**
|
|
38
38
|
* Use a data transformer
|
|
39
|
-
* @
|
|
39
|
+
* @see https://trpc.io/docs/v11/data-transformers
|
|
40
40
|
*/
|
|
41
41
|
transformer: CombinedDataTransformer;
|
|
42
42
|
/**
|
|
43
43
|
* Use custom error formatting
|
|
44
|
-
* @
|
|
44
|
+
* @see https://trpc.io/docs/v11/error-formatting
|
|
45
45
|
*/
|
|
46
46
|
errorFormatter: ErrorFormatter<TTypes['ctx'], TTypes['errorShape']>;
|
|
47
47
|
/**
|
|
@@ -65,26 +65,26 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
65
65
|
|
|
66
66
|
defaultMeta?: TTypes['meta'] extends object ? TTypes['meta'] : never;
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Enable support for returning async iterables and returning deferred promises when using `httpBatchStreamLink`
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
iterablesAndDeferreds?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Options for server-sent events (SSE) subscriptions
|
|
75
|
+
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
76
|
+
*/
|
|
77
|
+
sse?: {
|
|
69
78
|
/**
|
|
70
|
-
* Enable
|
|
79
|
+
* Enable server-sent events (SSE) subscriptions
|
|
71
80
|
* @default true
|
|
72
81
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* Enable server-sent events (SSE) subscriptions
|
|
80
|
-
* @default true
|
|
81
|
-
*/
|
|
82
|
-
enabled?: boolean;
|
|
83
|
-
} & Pick<
|
|
84
|
-
SSEStreamProducerOptions,
|
|
85
|
-
'ping' | 'emitAndEndImmediately' | 'maxDurationMs'
|
|
86
|
-
>;
|
|
87
|
-
};
|
|
82
|
+
enabled?: boolean;
|
|
83
|
+
} & Pick<
|
|
84
|
+
SSEStreamProducerOptions,
|
|
85
|
+
'ping' | 'emitAndEndImmediately' | 'maxDurationMs' | 'client'
|
|
86
|
+
>;
|
|
87
|
+
experimental?: {};
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -114,7 +114,7 @@ export type CreateContextCallback<
|
|
|
114
114
|
object extends TContext ? true : false,
|
|
115
115
|
{
|
|
116
116
|
/**
|
|
117
|
-
* @
|
|
117
|
+
* @see https://trpc.io/docs/v11/context
|
|
118
118
|
**/
|
|
119
119
|
createContext: TFunction;
|
|
120
120
|
}
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
ErrorHandlerOptions,
|
|
8
8
|
inferProcedureInput,
|
|
9
9
|
inferProcedureOutput,
|
|
10
|
+
LegacyObservableSubscriptionProcedure,
|
|
10
11
|
} from './procedure';
|
|
11
12
|
import type { ProcedureCallOptions } from './procedureBuilder';
|
|
12
13
|
import type { AnyRootTypes, RootConfig } from './rootConfig';
|
|
@@ -22,7 +23,9 @@ type DecorateProcedure<TProcedure extends AnyProcedure> = (
|
|
|
22
23
|
input: inferProcedureInput<TProcedure>,
|
|
23
24
|
) => Promise<
|
|
24
25
|
TProcedure['_def']['type'] extends 'subscription'
|
|
25
|
-
?
|
|
26
|
+
? TProcedure extends LegacyObservableSubscriptionProcedure<any>
|
|
27
|
+
? Observable<inferProcedureOutput<TProcedure>, TRPCError>
|
|
28
|
+
: inferProcedureOutput<TProcedure>
|
|
26
29
|
: inferProcedureOutput<TProcedure>
|
|
27
30
|
>;
|
|
28
31
|
|
|
@@ -33,8 +36,8 @@ export type DecorateRouterRecord<TRecord extends RouterRecord> = {
|
|
|
33
36
|
[TKey in keyof TRecord]: TRecord[TKey] extends AnyProcedure
|
|
34
37
|
? DecorateProcedure<TRecord[TKey]>
|
|
35
38
|
: TRecord[TKey] extends RouterRecord
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
? DecorateRouterRecord<TRecord[TKey]>
|
|
40
|
+
: never;
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -60,6 +63,7 @@ export type RouterCaller<
|
|
|
60
63
|
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>),
|
|
61
64
|
options?: {
|
|
62
65
|
onError?: RouterCallerErrorHandler<TRoot['ctx']>;
|
|
66
|
+
signal?: AbortSignal;
|
|
63
67
|
},
|
|
64
68
|
) => DecorateRouterRecord<TRecord>;
|
|
65
69
|
|
|
@@ -76,7 +80,7 @@ export interface Router<
|
|
|
76
80
|
};
|
|
77
81
|
/**
|
|
78
82
|
* @deprecated use `t.createCallerFactory(router)` instead
|
|
79
|
-
* @
|
|
83
|
+
* @see https://trpc.io/docs/v11/server/server-side-calls
|
|
80
84
|
*/
|
|
81
85
|
createCaller: RouterCaller<TRoot, TRecord>;
|
|
82
86
|
}
|
|
@@ -142,10 +146,10 @@ export type DecorateCreateRouterOptions<
|
|
|
142
146
|
? $Value extends AnyProcedure
|
|
143
147
|
? $Value
|
|
144
148
|
: $Value extends Router<any, infer TRecord>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
? TRecord
|
|
150
|
+
: $Value extends CreateRouterOptions
|
|
151
|
+
? DecorateCreateRouterOptions<$Value>
|
|
152
|
+
: never
|
|
149
153
|
: never;
|
|
150
154
|
};
|
|
151
155
|
|
|
@@ -270,12 +274,7 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
270
274
|
const _def = router._def;
|
|
271
275
|
type Context = TRoot['ctx'];
|
|
272
276
|
|
|
273
|
-
return function createCaller(
|
|
274
|
-
ctxOrCallback,
|
|
275
|
-
options?: {
|
|
276
|
-
onError?: RouterCallerErrorHandler<Context>;
|
|
277
|
-
},
|
|
278
|
-
) {
|
|
277
|
+
return function createCaller(ctxOrCallback, opts) {
|
|
279
278
|
return createRecursiveProxy<ReturnType<RouterCaller<any, any>>>(
|
|
280
279
|
async ({ path, args }) => {
|
|
281
280
|
const fullPath = path.join('.');
|
|
@@ -297,9 +296,10 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
297
296
|
getRawInput: async () => args[0],
|
|
298
297
|
ctx,
|
|
299
298
|
type: procedure._def.type,
|
|
299
|
+
signal: opts?.signal,
|
|
300
300
|
});
|
|
301
301
|
} catch (cause) {
|
|
302
|
-
|
|
302
|
+
opts?.onError?.({
|
|
303
303
|
ctx,
|
|
304
304
|
error: getTRPCErrorFromUnknown(cause),
|
|
305
305
|
input: args[0],
|
|
@@ -318,7 +318,6 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
318
318
|
type MergeRouters<
|
|
319
319
|
TRouters extends AnyRouter[],
|
|
320
320
|
TRoot extends AnyRootTypes = TRouters[0]['_def']['_config']['$types'],
|
|
321
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
322
321
|
TRecord extends RouterRecord = {},
|
|
323
322
|
> = TRouters extends [
|
|
324
323
|
infer Head extends AnyRouter,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ValueOf } from '../types';
|
|
1
|
+
import type { InvertKeyValue, ValueOf } from '../types';
|
|
2
2
|
|
|
3
3
|
// reference: https://www.jsonrpc.org/specification
|
|
4
4
|
|
|
@@ -41,16 +41,8 @@ export const TRPC_ERROR_CODES_BY_KEY = {
|
|
|
41
41
|
CLIENT_CLOSED_REQUEST: -32099, // 499
|
|
42
42
|
} as const;
|
|
43
43
|
|
|
44
|
-
type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
|
|
45
|
-
[K in keyof TType]: TValue extends TType[K] ? K : never;
|
|
46
|
-
}[keyof TType];
|
|
47
|
-
|
|
48
|
-
type Invert<TType extends Record<PropertyKey, PropertyKey>> = {
|
|
49
|
-
[TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
44
|
// pure
|
|
53
|
-
export const TRPC_ERROR_CODES_BY_NUMBER:
|
|
45
|
+
export const TRPC_ERROR_CODES_BY_NUMBER: InvertKeyValue<
|
|
54
46
|
typeof TRPC_ERROR_CODES_BY_KEY
|
|
55
47
|
> = {
|
|
56
48
|
[-32700]: 'PARSE_ERROR',
|
|
@@ -63,14 +63,15 @@ export interface TRPCRequest
|
|
|
63
63
|
|
|
64
64
|
export interface TRPCResult<TData = unknown> {
|
|
65
65
|
data: TData;
|
|
66
|
+
type?: 'data';
|
|
67
|
+
/**
|
|
68
|
+
* The id of the message to keep track of in case of a reconnect
|
|
69
|
+
*/
|
|
70
|
+
id?: string;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
export interface TRPCSuccessResponse<TData>
|
|
69
|
-
extends JSONRPC2.ResultResponse<
|
|
70
|
-
TRPCResult<TData> & {
|
|
71
|
-
type?: 'data';
|
|
72
|
-
}
|
|
73
|
-
> {}
|
|
74
|
+
extends JSONRPC2.ResultResponse<TRPCResult<TData>> {}
|
|
74
75
|
|
|
75
76
|
export interface TRPCErrorResponse<
|
|
76
77
|
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
@@ -111,13 +112,7 @@ export interface TRPCResultMessage<TData>
|
|
|
111
112
|
extends JSONRPC2.ResultResponse<
|
|
112
113
|
| { type: 'started'; data?: never }
|
|
113
114
|
| { type: 'stopped'; data?: never }
|
|
114
|
-
|
|
|
115
|
-
type: 'data';
|
|
116
|
-
/**
|
|
117
|
-
* The id of the message to keep track of in case of a reconnect
|
|
118
|
-
*/
|
|
119
|
-
id?: string;
|
|
120
|
-
})
|
|
115
|
+
| TRPCResult<TData>
|
|
121
116
|
> {}
|
|
122
117
|
|
|
123
118
|
export type TRPCResponseMessage<
|