@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.215 → 11.0.0-alpha-tmp-export-from-main.211
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-core-unstable-do-not-import-this-please.d.ts +9 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
- package/dist/@trpc-server/http.d.ts +1 -1
- package/dist/@trpc-server/http.d.ts.map +1 -1
- package/dist/@trpc-server.d.ts +3 -3
- package/dist/@trpc-server.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.js +7 -12
- package/dist/adapters/aws-lambda/index.mjs +3 -8
- package/dist/adapters/aws-lambda/utils.d.ts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +2 -8
- package/dist/adapters/express.mjs +2 -8
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/index.js +4 -12
- package/dist/adapters/fastify/index.mjs +2 -10
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -1
- package/dist/adapters/fetch/index.js +4 -10
- package/dist/adapters/fetch/index.mjs +2 -8
- package/dist/adapters/fetch/types.d.ts +1 -1
- package/dist/adapters/next.d.ts +1 -1
- package/dist/adapters/next.js +5 -11
- package/dist/adapters/next.mjs +3 -9
- package/dist/adapters/node-http/content-type/json/index.js +3 -5
- package/dist/adapters/node-http/content-type/json/index.mjs +1 -3
- package/dist/adapters/node-http/index.js +2 -8
- package/dist/adapters/node-http/index.mjs +2 -8
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/types.d.ts +2 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -1
- package/dist/adapters/standalone.js +2 -8
- package/dist/adapters/standalone.mjs +2 -8
- package/dist/adapters/ws.d.ts +1 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +26 -31
- package/dist/adapters/ws.mjs +1 -6
- package/dist/http.d.ts +6 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +21 -12
- package/dist/http.mjs +1 -7
- package/dist/index.js +41 -15
- package/dist/index.mjs +1 -5
- package/dist/{nodeHTTPRequestHandler-257a3b5f.mjs → nodeHTTPRequestHandler-2d5c8791.mjs} +2 -4
- package/dist/{nodeHTTPRequestHandler-f4b7e374.js → nodeHTTPRequestHandler-55f05150.js} +4 -6
- package/dist/{nodeHTTPRequestHandler-29178135.js → nodeHTTPRequestHandler-7691fc79.js} +1 -3
- package/dist/observable.d.ts +2 -2
- package/dist/observable.d.ts.map +1 -1
- package/dist/observable.js +25 -9
- package/dist/observable.mjs +1 -3
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +13 -5
- package/dist/rpc.mjs +1 -2
- package/dist/shared.js +9 -4
- package/dist/shared.mjs +1 -2
- package/package.json +125 -53
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +9 -0
- package/src/@trpc-server/http.ts +1 -2
- package/src/@trpc-server.ts +3 -3
- package/src/adapters/aws-lambda/index.ts +1 -1
- package/src/adapters/aws-lambda/utils.ts +1 -1
- package/src/adapters/express.ts +2 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
- package/src/adapters/fetch/types.ts +1 -1
- package/src/adapters/next.ts +1 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
- package/src/adapters/node-http/types.ts +3 -2
- package/src/adapters/standalone.ts +1 -1
- package/src/adapters/ws.ts +10 -9
- package/src/http.ts +6 -6
- package/src/observable.ts +2 -2
- package/src/rpc.ts +2 -2
- package/dist/TRPCError-10da405a.js +0 -61
- package/dist/TRPCError-14edcf88.mjs +0 -63
- package/dist/TRPCError-e2c8eb77.js +0 -67
- package/dist/batchStreamFormatter-1971db27.js +0 -32
- package/dist/batchStreamFormatter-378277dc.mjs +0 -30
- package/dist/batchStreamFormatter-4375dc8b.js +0 -31
- package/dist/bundle-analysis.json +0 -767
- package/dist/contentType-2ed02bef.mjs +0 -52
- package/dist/contentType-3a829011.js +0 -54
- package/dist/contentType-e4a2373e.js +0 -59
- package/dist/createProxy-0306dcaa.mjs +0 -121
- package/dist/createProxy-7e413449.js +0 -127
- package/dist/createProxy-dce0c414.js +0 -116
- package/dist/initTRPC-2cef03ab.js +0 -384
- package/dist/initTRPC-38faa18f.js +0 -371
- package/dist/initTRPC-fa1b3d57.mjs +0 -376
- package/dist/observable-2a5a96d5.js +0 -125
- package/dist/observable-62674916.js +0 -125
- package/dist/observable-6d025a37.mjs +0 -121
- package/dist/operators-0cc4956a.js +0 -99
- package/dist/operators-b08617cb.js +0 -103
- package/dist/operators-d0c3e794.mjs +0 -99
- package/dist/parseTRPCMessage-6e6c204e.js +0 -65
- package/dist/parseTRPCMessage-8eb0bbe9.mjs +0 -62
- package/dist/parseTRPCMessage-ebdfe3ca.js +0 -67
- package/dist/resolveHTTPResponse-833ca2b8.js +0 -265
- package/dist/resolveHTTPResponse-9322334c.mjs +0 -291
- package/dist/resolveHTTPResponse-d64c48e1.js +0 -293
- package/dist/rootConfig-3371c473.js +0 -89
- package/dist/rootConfig-571c9267.js +0 -94
- package/dist/rootConfig-6b04a6b8.mjs +0 -81
- package/dist/router-3344b52a.js +0 -262
- package/dist/router-919c37eb.js +0 -259
- package/dist/router-d6789e4b.mjs +0 -252
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
- 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/contentType.d.ts +0 -29
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.d.ts +0 -35
- package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.js +0 -51
- package/dist/unstable-core-do-not-import/index.mjs +0 -11
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/observable/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/observable.d.ts +0 -13
- package/dist/unstable-core-do-not-import/observable/observable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/operators.d.ts +0 -8
- package/dist/unstable-core-do-not-import/observable/operators.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/types.d.ts +0 -26
- package/dist/unstable-core-do-not-import/observable/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
- package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/router.d.ts +0 -85
- package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/types.d.ts +0 -98
- package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +0 -31
- package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
- package/src/unstable-core-do-not-import/createProxy.ts +0 -59
- package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
- package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
- package/src/unstable-core-do-not-import/http/index.ts +0 -23
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
- package/src/unstable-core-do-not-import/http/types.ts +0 -111
- package/src/unstable-core-do-not-import/index.ts +0 -108
- package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
- package/src/unstable-core-do-not-import/middleware.ts +0 -233
- package/src/unstable-core-do-not-import/observable/index.ts +0 -10
- package/src/unstable-core-do-not-import/observable/observable.ts +0 -155
- package/src/unstable-core-do-not-import/observable/operators.ts +0 -119
- package/src/unstable-core-do-not-import/observable/types.ts +0 -76
- package/src/unstable-core-do-not-import/parser.ts +0 -94
- package/src/unstable-core-do-not-import/procedure.ts +0 -108
- package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
- package/src/unstable-core-do-not-import/router.ts +0 -370
- package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
- package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
- package/src/unstable-core-do-not-import/serialize.ts +0 -122
- package/src/unstable-core-do-not-import/transformer.ts +0 -202
- package/src/unstable-core-do-not-import/types.ts +0 -151
- package/src/unstable-core-do-not-import/utils.ts +0 -66
- package/unstable-core-do-not-import/index.d.ts +0 -1
- package/unstable-core-do-not-import/index.js +0 -1
|
@@ -1,370 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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;
|
|
@@ -1,136 +0,0 @@
|
|
|
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>;
|
|
@@ -1,21 +0,0 @@
|
|
|
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';
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { procedureTypes, type ProcedureType } from '../procedure';
|
|
2
|
-
import type { CombinedDataTransformer } from '../transformer';
|
|
3
|
-
import { isObject } from '../utils';
|
|
4
|
-
import type { TRPCClientOutgoingMessage } from './envelopes';
|
|
5
|
-
|
|
6
|
-
/* istanbul ignore next -- @preserve */
|
|
7
|
-
function assertIsObject(obj: unknown): asserts obj is Record<string, unknown> {
|
|
8
|
-
if (!isObject(obj)) {
|
|
9
|
-
throw new Error('Not an object');
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/* istanbul ignore next -- @preserve */
|
|
14
|
-
function assertIsProcedureType(obj: unknown): asserts obj is ProcedureType {
|
|
15
|
-
if (!procedureTypes.includes(obj as any)) {
|
|
16
|
-
throw new Error('Invalid procedure type');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/* istanbul ignore next -- @preserve */
|
|
21
|
-
function assertIsRequestId(
|
|
22
|
-
obj: unknown,
|
|
23
|
-
): asserts obj is number | string | null {
|
|
24
|
-
if (
|
|
25
|
-
obj !== null &&
|
|
26
|
-
typeof obj === 'number' &&
|
|
27
|
-
isNaN(obj) &&
|
|
28
|
-
typeof obj !== 'string'
|
|
29
|
-
) {
|
|
30
|
-
throw new Error('Invalid request id');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/* istanbul ignore next -- @preserve */
|
|
35
|
-
function assertIsString(obj: unknown): asserts obj is string {
|
|
36
|
-
if (typeof obj !== 'string') {
|
|
37
|
-
throw new Error('Invalid string');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/* istanbul ignore next -- @preserve */
|
|
42
|
-
function assertIsJSONRPC2OrUndefined(
|
|
43
|
-
obj: unknown,
|
|
44
|
-
): asserts obj is '2.0' | undefined {
|
|
45
|
-
if (typeof obj !== 'undefined' && obj !== '2.0') {
|
|
46
|
-
throw new Error('Must be JSONRPC 2.0');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @public */
|
|
51
|
-
export function parseTRPCMessage(
|
|
52
|
-
obj: unknown,
|
|
53
|
-
transformer: CombinedDataTransformer,
|
|
54
|
-
): TRPCClientOutgoingMessage {
|
|
55
|
-
assertIsObject(obj);
|
|
56
|
-
|
|
57
|
-
const { id, jsonrpc, method, params } = obj;
|
|
58
|
-
assertIsRequestId(id);
|
|
59
|
-
assertIsJSONRPC2OrUndefined(jsonrpc);
|
|
60
|
-
|
|
61
|
-
if (method === 'subscription.stop') {
|
|
62
|
-
return {
|
|
63
|
-
id,
|
|
64
|
-
jsonrpc,
|
|
65
|
-
method,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
assertIsProcedureType(method);
|
|
69
|
-
assertIsObject(params);
|
|
70
|
-
const { input: rawInput, path } = params;
|
|
71
|
-
|
|
72
|
-
assertIsString(path);
|
|
73
|
-
|
|
74
|
-
const input = transformer.input.deserialize(rawInput);
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
id,
|
|
78
|
-
jsonrpc,
|
|
79
|
-
method,
|
|
80
|
-
params: {
|
|
81
|
-
input,
|
|
82
|
-
path,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|