@trpc/server 11.0.0-alpha-tmp-export-from-main.218 → 11.0.0-alpha-tmp-export-from-main-nuke-core.239
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@trpc/server/http.d.ts +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +69 -0
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -2
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +5 -4
- package/dist/adapters/aws-lambda/utils.mjs +3 -2
- package/dist/adapters/express.d.ts +1 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +6 -3
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +4 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +6 -4
- package/dist/adapters/fetch/fetchRequestHandler.mjs +4 -2
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +1 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +6 -4
- package/dist/adapters/next.mjs +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +3 -1
- package/dist/adapters/node-http/content-type/json/index.js +4 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +3 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +6 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +4 -2
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.d.ts +3 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -26
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -21
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -41
- package/dist/index.mjs +8 -1
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -13
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +6 -9
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +53 -125
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +2 -4
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -26
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -30
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ErrorFormatter } from './error/formatter';
|
|
2
|
+
import type { TRPCErrorShape } from './rpc';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The initial generics that are used in the init function
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface RootConfigTypes {
|
|
9
|
+
ctx: object;
|
|
10
|
+
meta: object;
|
|
11
|
+
errorShape: unknown;
|
|
12
|
+
transformer: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The default check to see if we're in a server
|
|
17
|
+
*/
|
|
18
|
+
export const isServerDefault: boolean =
|
|
19
|
+
typeof window === 'undefined' ||
|
|
20
|
+
'Deno' in window ||
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
22
|
+
globalThis.process?.env?.['NODE_ENV'] === 'test' ||
|
|
23
|
+
!!globalThis.process?.env?.['JEST_WORKER_ID'] ||
|
|
24
|
+
!!globalThis.process?.env?.['VITEST_WORKER_ID'];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The runtime config that are used and actually represents real values underneath
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export interface RuntimeConfig<TTypes extends RootConfigTypes> {
|
|
31
|
+
/**
|
|
32
|
+
* Use a data transformer
|
|
33
|
+
* @link https://trpc.io/docs/v11/data-transformers
|
|
34
|
+
*/
|
|
35
|
+
transformer: TTypes['transformer'];
|
|
36
|
+
/**
|
|
37
|
+
* Use custom error formatting
|
|
38
|
+
* @link https://trpc.io/docs/v11/error-formatting
|
|
39
|
+
*/
|
|
40
|
+
errorFormatter: ErrorFormatter<
|
|
41
|
+
TTypes['ctx'],
|
|
42
|
+
TRPCErrorShape<number> & { [key: string]: any }
|
|
43
|
+
>;
|
|
44
|
+
/**
|
|
45
|
+
* Allow `@trpc/server` to run in non-server environments
|
|
46
|
+
* @warning **Use with caution**, this should likely mainly be used within testing.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
allowOutsideOfServer: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Is this a server environment?
|
|
52
|
+
* @warning **Use with caution**, this should likely mainly be used within testing.
|
|
53
|
+
* @default typeof window === 'undefined' || 'Deno' in window || process.env.NODE_ENV === 'test'
|
|
54
|
+
*/
|
|
55
|
+
isServer: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Is this development?
|
|
58
|
+
* Will be used to decide if the API should return stack traces
|
|
59
|
+
* @default process.env.NODE_ENV !== 'production'
|
|
60
|
+
*/
|
|
61
|
+
isDev: boolean;
|
|
62
|
+
|
|
63
|
+
defaultMeta?: TTypes['meta'] extends object ? TTypes['meta'] : never;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export type CreateRootConfigTypes<TGenerics extends RootConfigTypes> =
|
|
70
|
+
TGenerics;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The config that is resolved after `initTRPC.create()` has been called
|
|
74
|
+
* Combination of `InitTOptions` + `InitGenerics`
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export interface RootConfig<TGenerics extends RootConfigTypes>
|
|
78
|
+
extends RuntimeConfig<TGenerics> {
|
|
79
|
+
$types: TGenerics;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export type AnyRootConfig = RootConfig<{
|
|
86
|
+
ctx: any;
|
|
87
|
+
meta: any;
|
|
88
|
+
errorShape: any;
|
|
89
|
+
transformer: any;
|
|
90
|
+
}>;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { createRecursiveProxy } from './createProxy';
|
|
2
|
+
import { defaultFormatter } from './error/formatter';
|
|
3
|
+
import { TRPCError } from './error/TRPCError';
|
|
4
|
+
import type {
|
|
5
|
+
AnyProcedure,
|
|
6
|
+
inferProcedureInput,
|
|
7
|
+
inferTransformedProcedureOutput,
|
|
8
|
+
ProcedureArgs,
|
|
9
|
+
} from './procedure';
|
|
10
|
+
import type { ProcedureCallOptions } from './procedureBuilder';
|
|
11
|
+
import type { AnyRootConfig } from './rootConfig';
|
|
12
|
+
import type { CombinedDataTransformer } from './transformer';
|
|
13
|
+
import { defaultTransformer } from './transformer';
|
|
14
|
+
import type { MaybePromise } from './types';
|
|
15
|
+
import { mergeWithoutOverrides, omitPrototype } from './utils';
|
|
16
|
+
|
|
17
|
+
/** @internal **/
|
|
18
|
+
export type ProcedureRecord = Record<string, AnyProcedure>;
|
|
19
|
+
|
|
20
|
+
export interface ProcedureRouterRecord {
|
|
21
|
+
[key: string]: AnyProcedure | AnyRouter;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RouterDef<
|
|
25
|
+
TConfig extends AnyRootConfig,
|
|
26
|
+
TRecord extends ProcedureRouterRecord,
|
|
27
|
+
> {
|
|
28
|
+
_config: TConfig;
|
|
29
|
+
router: true;
|
|
30
|
+
procedure?: never;
|
|
31
|
+
procedures: TRecord;
|
|
32
|
+
record: TRecord;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type AnyRouterDef<TConfig extends AnyRootConfig = AnyRootConfig> =
|
|
36
|
+
RouterDef<TConfig, any>;
|
|
37
|
+
|
|
38
|
+
type DecorateProcedure<TProcedure extends AnyProcedure> = (
|
|
39
|
+
input: ProcedureArgs<TProcedure['_def']>[0],
|
|
40
|
+
) => Promise<TProcedure['_def']['_output_out']>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
46
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
47
|
+
? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
|
|
48
|
+
: TProcedures[TKey] extends AnyProcedure
|
|
49
|
+
? DecorateProcedure<TProcedures[TKey]>
|
|
50
|
+
: never;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export type RouterCaller<TDef extends AnyRouterDef> = (
|
|
57
|
+
/**
|
|
58
|
+
* @note
|
|
59
|
+
* If passing a function, we recommend it's a cached function
|
|
60
|
+
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
61
|
+
*/
|
|
62
|
+
ctx:
|
|
63
|
+
| TDef['_config']['$types']['ctx']
|
|
64
|
+
| (() => MaybePromise<TDef['_config']['$types']['ctx']>),
|
|
65
|
+
) => DecoratedProcedureRecord<TDef['record']>;
|
|
66
|
+
|
|
67
|
+
export interface Router<TDef extends AnyRouterDef> {
|
|
68
|
+
_def: TDef;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated use `t.createCallerFactory(router)` instead
|
|
71
|
+
* @link https://trpc.io/docs/v11/server/server-side-calls
|
|
72
|
+
*/
|
|
73
|
+
createCaller: RouterCaller<TDef>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type AnyRouter = Router<AnyRouterDef>;
|
|
77
|
+
|
|
78
|
+
type inferRouterDef<TRouter extends AnyRouter> = TRouter extends Router<
|
|
79
|
+
infer TParams
|
|
80
|
+
>
|
|
81
|
+
? TParams extends AnyRouterDef<any>
|
|
82
|
+
? TParams
|
|
83
|
+
: never
|
|
84
|
+
: never;
|
|
85
|
+
type inferRouterConfig<TRouter extends AnyRouter> =
|
|
86
|
+
inferRouterDef<TRouter>['_config'];
|
|
87
|
+
|
|
88
|
+
export type inferRouterContext<TRouter extends AnyRouter> =
|
|
89
|
+
inferRouterConfig<TRouter>['$types']['ctx'];
|
|
90
|
+
export type inferRouterError<TRouter extends AnyRouter> =
|
|
91
|
+
inferRouterConfig<TRouter>['$types']['errorShape'];
|
|
92
|
+
export type inferRouterMeta<TRouter extends AnyRouter> =
|
|
93
|
+
inferRouterConfig<TRouter>['$types']['meta'];
|
|
94
|
+
|
|
95
|
+
type GetInferenceHelpers<
|
|
96
|
+
TType extends 'input' | 'output',
|
|
97
|
+
TRouter extends AnyRouter,
|
|
98
|
+
> = {
|
|
99
|
+
[TKey in keyof TRouter['_def']['record']]: TRouter['_def']['record'][TKey] extends infer TRouterOrProcedure
|
|
100
|
+
? TRouterOrProcedure extends AnyRouter
|
|
101
|
+
? GetInferenceHelpers<TType, TRouterOrProcedure>
|
|
102
|
+
: TRouterOrProcedure extends AnyProcedure
|
|
103
|
+
? TType extends 'input'
|
|
104
|
+
? inferProcedureInput<TRouterOrProcedure>
|
|
105
|
+
: inferTransformedProcedureOutput<
|
|
106
|
+
TRouter['_def']['_config'],
|
|
107
|
+
TRouterOrProcedure
|
|
108
|
+
>
|
|
109
|
+
: never
|
|
110
|
+
: never;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type inferRouterInputs<TRouter extends AnyRouter> = GetInferenceHelpers<
|
|
114
|
+
'input',
|
|
115
|
+
TRouter
|
|
116
|
+
>;
|
|
117
|
+
|
|
118
|
+
export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<
|
|
119
|
+
'output',
|
|
120
|
+
TRouter
|
|
121
|
+
>;
|
|
122
|
+
|
|
123
|
+
function isRouter(
|
|
124
|
+
procedureOrRouter: AnyProcedure | AnyRouter,
|
|
125
|
+
): procedureOrRouter is AnyRouter {
|
|
126
|
+
return 'router' in procedureOrRouter._def;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const emptyRouter = {
|
|
130
|
+
_ctx: null as any,
|
|
131
|
+
_errorShape: null as any,
|
|
132
|
+
_meta: null as any,
|
|
133
|
+
queries: {},
|
|
134
|
+
mutations: {},
|
|
135
|
+
subscriptions: {},
|
|
136
|
+
errorFormatter: defaultFormatter,
|
|
137
|
+
transformer: defaultTransformer,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Reserved words that can't be used as router or procedure names
|
|
142
|
+
*/
|
|
143
|
+
const reservedWords = [
|
|
144
|
+
/**
|
|
145
|
+
* Then is a reserved word because otherwise we can't return a promise that returns a Proxy
|
|
146
|
+
* since JS will think that `.then` is something that exists
|
|
147
|
+
*/
|
|
148
|
+
'then',
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
export type CreateRouterInner<
|
|
155
|
+
TConfig extends AnyRootConfig,
|
|
156
|
+
TProcRouterRecord extends ProcedureRouterRecord,
|
|
157
|
+
> = Router<RouterDef<TConfig, TProcRouterRecord>> &
|
|
158
|
+
/**
|
|
159
|
+
* This adds ability to call procedures directly but is primarily used for quick access in type inference
|
|
160
|
+
*/
|
|
161
|
+
TProcRouterRecord;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
export function createRouterFactory<TConfig extends AnyRootConfig>(
|
|
167
|
+
config: TConfig,
|
|
168
|
+
) {
|
|
169
|
+
return function createRouterInner<
|
|
170
|
+
TProcRouterRecord extends ProcedureRouterRecord,
|
|
171
|
+
>(
|
|
172
|
+
procedures: TProcRouterRecord,
|
|
173
|
+
): CreateRouterInner<TConfig, TProcRouterRecord> {
|
|
174
|
+
const reservedWordsUsed = new Set(
|
|
175
|
+
Object.keys(procedures).filter((v) => reservedWords.includes(v)),
|
|
176
|
+
);
|
|
177
|
+
if (reservedWordsUsed.size > 0) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
'Reserved words used in `router({})` call: ' +
|
|
180
|
+
Array.from(reservedWordsUsed).join(', '),
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const routerProcedures: ProcedureRecord = omitPrototype({});
|
|
185
|
+
function recursiveGetPaths(procedures: ProcedureRouterRecord, path = '') {
|
|
186
|
+
for (const [key, procedureOrRouter] of Object.entries(procedures ?? {})) {
|
|
187
|
+
const newPath = `${path}${key}`;
|
|
188
|
+
|
|
189
|
+
if (isRouter(procedureOrRouter)) {
|
|
190
|
+
recursiveGetPaths(procedureOrRouter._def.procedures, `${newPath}.`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (routerProcedures[newPath]) {
|
|
195
|
+
throw new Error(`Duplicate key: ${newPath}`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
routerProcedures[newPath] = procedureOrRouter;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
recursiveGetPaths(procedures);
|
|
202
|
+
|
|
203
|
+
const _def: AnyRouterDef<TConfig> = {
|
|
204
|
+
_config: config,
|
|
205
|
+
router: true,
|
|
206
|
+
procedures: routerProcedures,
|
|
207
|
+
...emptyRouter,
|
|
208
|
+
record: procedures,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const router: AnyRouter = {
|
|
212
|
+
...procedures,
|
|
213
|
+
_def,
|
|
214
|
+
createCaller(ctx) {
|
|
215
|
+
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
216
|
+
const fullPath = path.join('.');
|
|
217
|
+
const procedure = _def.procedures[fullPath] as AnyProcedure;
|
|
218
|
+
|
|
219
|
+
return procedure({
|
|
220
|
+
path: fullPath,
|
|
221
|
+
getRawInput: async () => args[0],
|
|
222
|
+
ctx,
|
|
223
|
+
type: procedure._def.type,
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return proxy as ReturnType<RouterCaller<any>>;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
return router as any;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function isProcedure(
|
|
236
|
+
procedureOrRouter: AnyProcedure | AnyRouter,
|
|
237
|
+
): procedureOrRouter is AnyProcedure {
|
|
238
|
+
return !!procedureOrRouter._def.procedure;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
243
|
+
export function callProcedure(
|
|
244
|
+
opts: ProcedureCallOptions & { procedures: ProcedureRouterRecord },
|
|
245
|
+
) {
|
|
246
|
+
const { type, path } = opts;
|
|
247
|
+
const proc = opts.procedures[path];
|
|
248
|
+
if (!proc || !isProcedure(proc) || proc._def.type !== type) {
|
|
249
|
+
throw new TRPCError({
|
|
250
|
+
code: 'NOT_FOUND',
|
|
251
|
+
message: `No "${type}"-procedure on path "${path}"`,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return proc(opts);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function createCallerFactory<TConfig extends AnyRootConfig>() {
|
|
259
|
+
return function createCallerInner<
|
|
260
|
+
TRouter extends Router<AnyRouterDef<TConfig>>,
|
|
261
|
+
>(router: TRouter): RouterCaller<TRouter['_def']> {
|
|
262
|
+
const _def = router._def;
|
|
263
|
+
type Context = TConfig['$types']['ctx'];
|
|
264
|
+
|
|
265
|
+
return function createCaller(maybeContext) {
|
|
266
|
+
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
267
|
+
const fullPath = path.join('.');
|
|
268
|
+
const procedure = _def.procedures[fullPath] as AnyProcedure;
|
|
269
|
+
|
|
270
|
+
const callProc = (ctx: Context) =>
|
|
271
|
+
procedure({
|
|
272
|
+
path: fullPath,
|
|
273
|
+
getRawInput: async () => args[0],
|
|
274
|
+
ctx,
|
|
275
|
+
type: procedure._def.type,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
if (typeof maybeContext === 'function') {
|
|
279
|
+
const context = (maybeContext as () => MaybePromise<Context>)();
|
|
280
|
+
if (context instanceof Promise) {
|
|
281
|
+
return context.then(callProc);
|
|
282
|
+
}
|
|
283
|
+
return callProc(context);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return callProc(maybeContext);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return proxy as ReturnType<RouterCaller<any>>;
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** @internal */
|
|
295
|
+
type MergeRouters<
|
|
296
|
+
TRouters extends AnyRouter[],
|
|
297
|
+
TRouterDef extends AnyRouterDef = RouterDef<
|
|
298
|
+
TRouters[0]['_def']['_config'],
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
300
|
+
{}
|
|
301
|
+
>,
|
|
302
|
+
> = TRouters extends [
|
|
303
|
+
infer Head extends AnyRouter,
|
|
304
|
+
...infer Tail extends AnyRouter[],
|
|
305
|
+
]
|
|
306
|
+
? MergeRouters<
|
|
307
|
+
Tail,
|
|
308
|
+
{
|
|
309
|
+
_config: TRouterDef['_config'];
|
|
310
|
+
router: true;
|
|
311
|
+
procedures: Head['_def']['procedures'] & TRouterDef['procedures'];
|
|
312
|
+
record: Head['_def']['record'] & TRouterDef['record'];
|
|
313
|
+
}
|
|
314
|
+
>
|
|
315
|
+
: Router<TRouterDef> & TRouterDef['record'];
|
|
316
|
+
|
|
317
|
+
export function mergeRouters<TRouters extends AnyRouter[]>(
|
|
318
|
+
...routerList: [...TRouters]
|
|
319
|
+
): MergeRouters<TRouters> {
|
|
320
|
+
const record = mergeWithoutOverrides(
|
|
321
|
+
{},
|
|
322
|
+
...routerList.map((r) => r._def.record),
|
|
323
|
+
);
|
|
324
|
+
const errorFormatter = routerList.reduce(
|
|
325
|
+
(currentErrorFormatter, nextRouter) => {
|
|
326
|
+
if (
|
|
327
|
+
nextRouter._def._config.errorFormatter &&
|
|
328
|
+
nextRouter._def._config.errorFormatter !== defaultFormatter
|
|
329
|
+
) {
|
|
330
|
+
if (
|
|
331
|
+
currentErrorFormatter !== defaultFormatter &&
|
|
332
|
+
currentErrorFormatter !== nextRouter._def._config.errorFormatter
|
|
333
|
+
) {
|
|
334
|
+
throw new Error('You seem to have several error formatters');
|
|
335
|
+
}
|
|
336
|
+
return nextRouter._def._config.errorFormatter;
|
|
337
|
+
}
|
|
338
|
+
return currentErrorFormatter;
|
|
339
|
+
},
|
|
340
|
+
defaultFormatter,
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
const transformer = routerList.reduce((prev, current) => {
|
|
344
|
+
if (
|
|
345
|
+
current._def._config.transformer &&
|
|
346
|
+
current._def._config.transformer !== defaultTransformer
|
|
347
|
+
) {
|
|
348
|
+
if (
|
|
349
|
+
prev !== defaultTransformer &&
|
|
350
|
+
prev !== current._def._config.transformer
|
|
351
|
+
) {
|
|
352
|
+
throw new Error('You seem to have several transformers');
|
|
353
|
+
}
|
|
354
|
+
return current._def._config.transformer;
|
|
355
|
+
}
|
|
356
|
+
return prev;
|
|
357
|
+
}, defaultTransformer as CombinedDataTransformer);
|
|
358
|
+
|
|
359
|
+
const router = createRouterFactory({
|
|
360
|
+
errorFormatter,
|
|
361
|
+
transformer,
|
|
362
|
+
isDev: routerList.some((r) => r._def._config.isDev),
|
|
363
|
+
allowOutsideOfServer: routerList.some(
|
|
364
|
+
(r) => r._def._config.allowOutsideOfServer,
|
|
365
|
+
),
|
|
366
|
+
isServer: routerList.some((r) => r._def._config.isServer),
|
|
367
|
+
$types: routerList[0]?._def._config.$types as any,
|
|
368
|
+
})(record);
|
|
369
|
+
return router as any;
|
|
370
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { invert } from '../utils';
|
|
2
|
+
|
|
3
|
+
// reference: https://www.jsonrpc.org/specification
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* JSON-RPC 2.0 Error codes
|
|
7
|
+
*
|
|
8
|
+
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
|
9
|
+
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
|
10
|
+
*/
|
|
11
|
+
export const TRPC_ERROR_CODES_BY_KEY = {
|
|
12
|
+
/**
|
|
13
|
+
* Invalid JSON was received by the server.
|
|
14
|
+
* An error occurred on the server while parsing the JSON text.
|
|
15
|
+
*/
|
|
16
|
+
PARSE_ERROR: -32700,
|
|
17
|
+
/**
|
|
18
|
+
* The JSON sent is not a valid Request object.
|
|
19
|
+
*/
|
|
20
|
+
BAD_REQUEST: -32600, // 400
|
|
21
|
+
|
|
22
|
+
// Internal JSON-RPC error
|
|
23
|
+
INTERNAL_SERVER_ERROR: -32603,
|
|
24
|
+
NOT_IMPLEMENTED: -32603,
|
|
25
|
+
|
|
26
|
+
// Implementation specific errors
|
|
27
|
+
UNAUTHORIZED: -32001, // 401
|
|
28
|
+
FORBIDDEN: -32003, // 403
|
|
29
|
+
NOT_FOUND: -32004, // 404
|
|
30
|
+
METHOD_NOT_SUPPORTED: -32005, // 405
|
|
31
|
+
TIMEOUT: -32008, // 408
|
|
32
|
+
CONFLICT: -32009, // 409
|
|
33
|
+
PRECONDITION_FAILED: -32012, // 412
|
|
34
|
+
PAYLOAD_TOO_LARGE: -32013, // 413
|
|
35
|
+
UNPROCESSABLE_CONTENT: -32022, // 422
|
|
36
|
+
TOO_MANY_REQUESTS: -32029, // 429
|
|
37
|
+
CLIENT_CLOSED_REQUEST: -32099, // 499
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
export const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
|
|
41
|
+
|
|
42
|
+
type ValueOf<TObj> = TObj[keyof TObj];
|
|
43
|
+
export type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
44
|
+
export type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import type { ProcedureType } from '../procedure';
|
|
3
|
+
import type { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Error response
|
|
7
|
+
*/
|
|
8
|
+
export interface TRPCErrorShape<
|
|
9
|
+
TCode extends number = TRPC_ERROR_CODE_NUMBER,
|
|
10
|
+
TData extends Record<string, unknown> = Record<string, unknown>,
|
|
11
|
+
> {
|
|
12
|
+
code: TCode;
|
|
13
|
+
message: string;
|
|
14
|
+
data: TData;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* JSON-RPC 2.0 Specification
|
|
19
|
+
*/
|
|
20
|
+
export namespace JSONRPC2 {
|
|
21
|
+
export type RequestId = number | string | null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* All requests/responses extends this shape
|
|
25
|
+
*/
|
|
26
|
+
export interface BaseEnvelope {
|
|
27
|
+
id?: RequestId;
|
|
28
|
+
jsonrpc?: '2.0';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface BaseRequest<TMethod extends string = string>
|
|
32
|
+
extends BaseEnvelope {
|
|
33
|
+
method: TMethod;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Request<TMethod extends string = string, TParams = unknown>
|
|
37
|
+
extends BaseRequest<TMethod> {
|
|
38
|
+
params: TParams;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ResultResponse<TResult = unknown> extends BaseEnvelope {
|
|
42
|
+
result: TResult;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ErrorResponse<TError extends TRPCErrorShape = TRPCErrorShape>
|
|
46
|
+
extends BaseEnvelope {
|
|
47
|
+
error: TError;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/////////////////////////// HTTP envelopes ///////////////////////
|
|
52
|
+
|
|
53
|
+
export interface TRPCRequest
|
|
54
|
+
extends JSONRPC2.Request<ProcedureType, { path: string; input: unknown }> {}
|
|
55
|
+
|
|
56
|
+
export interface TRPCResult<TData = unknown> {
|
|
57
|
+
data: TData;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface TRPCSuccessResponse<TData>
|
|
61
|
+
extends JSONRPC2.ResultResponse<
|
|
62
|
+
TRPCResult<TData> & {
|
|
63
|
+
type?: 'data';
|
|
64
|
+
}
|
|
65
|
+
> {}
|
|
66
|
+
|
|
67
|
+
export interface TRPCErrorResponse<
|
|
68
|
+
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
69
|
+
> extends JSONRPC2.ErrorResponse<TError> {}
|
|
70
|
+
|
|
71
|
+
export type TRPCResponse<
|
|
72
|
+
TData = unknown,
|
|
73
|
+
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
74
|
+
> = TRPCErrorResponse<TError> | TRPCSuccessResponse<TData>;
|
|
75
|
+
|
|
76
|
+
/////////////////////////// WebSocket envelopes ///////////////////////
|
|
77
|
+
|
|
78
|
+
export type TRPCRequestMessage = TRPCRequest & {
|
|
79
|
+
id: JSONRPC2.RequestId;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The client asked the server to unsubscribe
|
|
84
|
+
*/
|
|
85
|
+
export interface TRPCSubscriptionStopNotification
|
|
86
|
+
extends JSONRPC2.BaseRequest<'subscription.stop'> {
|
|
87
|
+
id: null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The client's outgoing request types
|
|
92
|
+
*/
|
|
93
|
+
export type TRPCClientOutgoingRequest = TRPCSubscriptionStopNotification;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The client's sent messages shape
|
|
97
|
+
*/
|
|
98
|
+
export type TRPCClientOutgoingMessage =
|
|
99
|
+
| TRPCRequestMessage
|
|
100
|
+
| (JSONRPC2.BaseRequest<'subscription.stop'> & { id: JSONRPC2.RequestId });
|
|
101
|
+
|
|
102
|
+
export interface TRPCResultMessage<TData>
|
|
103
|
+
extends JSONRPC2.ResultResponse<
|
|
104
|
+
| { type: 'started'; data?: never }
|
|
105
|
+
| { type: 'stopped'; data?: never }
|
|
106
|
+
| (TRPCResult<TData> & { type: 'data' })
|
|
107
|
+
> {}
|
|
108
|
+
|
|
109
|
+
export type TRPCResponseMessage<
|
|
110
|
+
TData = unknown,
|
|
111
|
+
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
112
|
+
> = { id: JSONRPC2.RequestId } & (
|
|
113
|
+
| TRPCErrorResponse<TError>
|
|
114
|
+
| TRPCResultMessage<TData>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The server asked the client to reconnect - useful when restarting/redeploying service
|
|
119
|
+
*/
|
|
120
|
+
export interface TRPCReconnectNotification
|
|
121
|
+
extends JSONRPC2.BaseRequest<'reconnect'> {
|
|
122
|
+
id: JSONRPC2.RequestId;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The client's incoming request types
|
|
127
|
+
*/
|
|
128
|
+
export type TRPCClientIncomingRequest = TRPCReconnectNotification;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The client's received messages shape
|
|
132
|
+
*/
|
|
133
|
+
export type TRPCClientIncomingMessage<
|
|
134
|
+
TResult = unknown,
|
|
135
|
+
TError extends TRPCErrorShape = TRPCErrorShape,
|
|
136
|
+
> = TRPCClientIncomingRequest | TRPCResponseMessage<TResult, TError>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { TRPC_ERROR_CODES_BY_KEY, TRPC_ERROR_CODES_BY_NUMBER } from './codes';
|
|
2
|
+
export type { TRPC_ERROR_CODE_KEY, TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
3
|
+
export type {
|
|
4
|
+
JSONRPC2,
|
|
5
|
+
TRPCClientIncomingMessage,
|
|
6
|
+
TRPCClientIncomingRequest,
|
|
7
|
+
TRPCClientOutgoingMessage,
|
|
8
|
+
TRPCClientOutgoingRequest,
|
|
9
|
+
TRPCErrorResponse,
|
|
10
|
+
TRPCErrorShape,
|
|
11
|
+
TRPCReconnectNotification,
|
|
12
|
+
TRPCRequest,
|
|
13
|
+
TRPCRequestMessage,
|
|
14
|
+
TRPCResponse,
|
|
15
|
+
TRPCResponseMessage,
|
|
16
|
+
TRPCResult,
|
|
17
|
+
TRPCResultMessage,
|
|
18
|
+
TRPCSubscriptionStopNotification,
|
|
19
|
+
TRPCSuccessResponse,
|
|
20
|
+
} from './envelopes';
|
|
21
|
+
export { parseTRPCMessage } from './parseTRPCMessage';
|