@trpc/server 11.0.0-next-beta.240 → 11.0.0-next-beta.242
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/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +2 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +2 -0
- package/dist/adapters/node-http/types.d.ts +3 -3
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/bundle-analysis.json +36 -36
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +7 -2
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -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 +2 -2
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +2 -2
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +43 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +39 -47
- package/dist/unstable-core-do-not-import/index.d.ts +1 -1
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +14 -8
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +23 -38
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +3 -3
- package/dist/unstable-core-do-not-import/router.mjs +3 -3
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +1 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/transformer.d.ts +1 -1
- package/package.json +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +4 -2
- package/src/adapters/node-http/types.ts +3 -3
- package/src/unstable-core-do-not-import/error/formatter.ts +7 -7
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +6 -3
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +45 -51
- package/src/unstable-core-do-not-import/index.ts +0 -2
- package/src/unstable-core-do-not-import/initTRPC.ts +10 -8
- package/src/unstable-core-do-not-import/router.ts +53 -78
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +1 -3
|
@@ -19,19 +19,6 @@ export interface ProcedureRouterRecord {
|
|
|
19
19
|
[key: string]: AnyProcedure | AnyRouter;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export interface RouterDef<
|
|
23
|
-
TRoot extends AnyRootTypes,
|
|
24
|
-
TRecord extends ProcedureRouterRecord,
|
|
25
|
-
> {
|
|
26
|
-
_config: RootConfig<TRoot>;
|
|
27
|
-
router: true;
|
|
28
|
-
procedure?: never;
|
|
29
|
-
procedures: TRecord;
|
|
30
|
-
record: TRecord;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type AnyRouterDef = RouterDef<any, any>;
|
|
34
|
-
|
|
35
22
|
type DecorateProcedure<TProcedure extends AnyProcedure> = (
|
|
36
23
|
input: inferProcedureInput<TProcedure>,
|
|
37
24
|
) => Promise<TProcedure['_def']['_output_out']>;
|
|
@@ -39,7 +26,9 @@ type DecorateProcedure<TProcedure extends AnyProcedure> = (
|
|
|
39
26
|
/**
|
|
40
27
|
* @internal
|
|
41
28
|
*/
|
|
42
|
-
type DecoratedProcedureRecord<
|
|
29
|
+
export type DecoratedProcedureRecord<
|
|
30
|
+
TProcedures extends ProcedureRouterRecord,
|
|
31
|
+
> = {
|
|
43
32
|
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
44
33
|
? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
|
|
45
34
|
: TProcedures[TKey] extends AnyProcedure
|
|
@@ -50,46 +39,54 @@ type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
|
50
39
|
/**
|
|
51
40
|
* @internal
|
|
52
41
|
*/
|
|
53
|
-
export type RouterCaller<
|
|
42
|
+
export type RouterCaller<
|
|
43
|
+
TRoot extends AnyRootTypes,
|
|
44
|
+
TRecord extends ProcedureRouterRecord,
|
|
45
|
+
> = (
|
|
54
46
|
/**
|
|
55
47
|
* @note
|
|
56
48
|
* If passing a function, we recommend it's a cached function
|
|
57
49
|
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
58
50
|
*/
|
|
59
|
-
ctx:
|
|
60
|
-
|
|
61
|
-
| (() => MaybePromise<TDef['_config']['$types']['ctx']>),
|
|
62
|
-
) => DecoratedProcedureRecord<TDef['record']>;
|
|
51
|
+
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>),
|
|
52
|
+
) => DecoratedProcedureRecord<TRecord>;
|
|
63
53
|
|
|
64
|
-
export interface Router<
|
|
65
|
-
|
|
54
|
+
export interface Router<
|
|
55
|
+
TRoot extends AnyRootTypes,
|
|
56
|
+
TRecord extends ProcedureRouterRecord,
|
|
57
|
+
> {
|
|
58
|
+
_def: {
|
|
59
|
+
_config: RootConfig<TRoot>;
|
|
60
|
+
router: true;
|
|
61
|
+
procedure?: never;
|
|
62
|
+
procedures: TRecord;
|
|
63
|
+
record: TRecord;
|
|
64
|
+
};
|
|
66
65
|
/**
|
|
67
66
|
* @deprecated use `t.createCallerFactory(router)` instead
|
|
68
67
|
* @link https://trpc.io/docs/v11/server/server-side-calls
|
|
69
68
|
*/
|
|
70
|
-
createCaller: RouterCaller<
|
|
69
|
+
createCaller: RouterCaller<TRoot, TRecord>;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
export type
|
|
72
|
+
export type BuiltRouter<
|
|
73
|
+
TRoot extends AnyRootTypes,
|
|
74
|
+
TRecord extends ProcedureRouterRecord,
|
|
75
|
+
> = Router<TRoot, TRecord> & TRecord;
|
|
74
76
|
|
|
75
|
-
type
|
|
76
|
-
|
|
77
|
-
>
|
|
78
|
-
|
|
79
|
-
? TParams
|
|
80
|
-
: never
|
|
81
|
-
: never;
|
|
82
|
-
type inferRouterConfig<TRouter extends AnyRouter> =
|
|
83
|
-
inferRouterDef<TRouter>['_config'];
|
|
77
|
+
export type AnyRouter = Router<any, any>;
|
|
78
|
+
|
|
79
|
+
export type inferRouterRootTypes<TRouter extends AnyRouter> =
|
|
80
|
+
TRouter['_def']['_config']['$types'];
|
|
84
81
|
|
|
85
82
|
export type inferRouterContext<TRouter extends AnyRouter> =
|
|
86
|
-
|
|
83
|
+
inferRouterRootTypes<TRouter>['ctx'];
|
|
87
84
|
export type inferRouterError<TRouter extends AnyRouter> =
|
|
88
|
-
|
|
85
|
+
inferRouterRootTypes<TRouter>['errorShape'];
|
|
89
86
|
export type inferRouterMeta<TRouter extends AnyRouter> =
|
|
90
|
-
|
|
87
|
+
inferRouterRootTypes<TRouter>['meta'];
|
|
91
88
|
|
|
92
|
-
type GetInferenceHelpers<
|
|
89
|
+
export type GetInferenceHelpers<
|
|
93
90
|
TType extends 'input' | 'output',
|
|
94
91
|
TRouter extends AnyRouter,
|
|
95
92
|
> = {
|
|
@@ -142,18 +139,6 @@ const reservedWords = [
|
|
|
142
139
|
'then',
|
|
143
140
|
];
|
|
144
141
|
|
|
145
|
-
/**
|
|
146
|
-
* @internal
|
|
147
|
-
*/
|
|
148
|
-
export type CreateRouterInner<
|
|
149
|
-
TRoot extends AnyRootTypes,
|
|
150
|
-
TProcRouterRecord extends ProcedureRouterRecord,
|
|
151
|
-
> = Router<RouterDef<TRoot, TProcRouterRecord>> &
|
|
152
|
-
/**
|
|
153
|
-
* This adds ability to call procedures directly but is primarily used for quick access in type inference
|
|
154
|
-
*/
|
|
155
|
-
TProcRouterRecord;
|
|
156
|
-
|
|
157
142
|
/**
|
|
158
143
|
* @internal
|
|
159
144
|
*/
|
|
@@ -162,9 +147,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
162
147
|
) {
|
|
163
148
|
return function createRouterInner<
|
|
164
149
|
TProcRouterRecord extends ProcedureRouterRecord,
|
|
165
|
-
>(
|
|
166
|
-
procedures: TProcRouterRecord,
|
|
167
|
-
): CreateRouterInner<TRoot, TProcRouterRecord> {
|
|
150
|
+
>(procedures: TProcRouterRecord): BuiltRouter<TRoot, TProcRouterRecord> {
|
|
168
151
|
const reservedWordsUsed = new Set(
|
|
169
152
|
Object.keys(procedures).filter((v) => reservedWords.includes(v)),
|
|
170
153
|
);
|
|
@@ -194,7 +177,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
194
177
|
}
|
|
195
178
|
recursiveGetPaths(procedures);
|
|
196
179
|
|
|
197
|
-
const _def:
|
|
180
|
+
const _def: AnyRouter['_def'] = {
|
|
198
181
|
_config: config,
|
|
199
182
|
router: true,
|
|
200
183
|
procedures: routerProcedures,
|
|
@@ -202,7 +185,7 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
202
185
|
record: procedures,
|
|
203
186
|
};
|
|
204
187
|
|
|
205
|
-
const router:
|
|
188
|
+
const router: BuiltRouter<TRoot, TProcRouterRecord> = {
|
|
206
189
|
...procedures,
|
|
207
190
|
_def,
|
|
208
191
|
createCaller(ctx) {
|
|
@@ -218,11 +201,11 @@ export function createRouterFactory<TRoot extends AnyRootTypes>(
|
|
|
218
201
|
});
|
|
219
202
|
});
|
|
220
203
|
|
|
221
|
-
return proxy as ReturnType<RouterCaller<any>>;
|
|
204
|
+
return proxy as ReturnType<RouterCaller<any, any>>;
|
|
222
205
|
},
|
|
223
206
|
};
|
|
224
207
|
|
|
225
|
-
return router
|
|
208
|
+
return router;
|
|
226
209
|
};
|
|
227
210
|
}
|
|
228
211
|
|
|
@@ -250,15 +233,16 @@ export function callProcedure(
|
|
|
250
233
|
}
|
|
251
234
|
|
|
252
235
|
export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
253
|
-
return function createCallerInner<
|
|
254
|
-
|
|
255
|
-
|
|
236
|
+
return function createCallerInner<TRecord extends ProcedureRouterRecord>(
|
|
237
|
+
router: Router<TRoot, TRecord>,
|
|
238
|
+
): RouterCaller<TRoot, TRecord> {
|
|
256
239
|
const _def = router._def;
|
|
257
240
|
type Context = TRoot['ctx'];
|
|
258
241
|
|
|
259
242
|
return function createCaller(maybeContext) {
|
|
260
243
|
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
261
244
|
const fullPath = path.join('.');
|
|
245
|
+
|
|
262
246
|
const procedure = _def.procedures[fullPath] as AnyProcedure;
|
|
263
247
|
|
|
264
248
|
const callProc = (ctx: Context) =>
|
|
@@ -280,7 +264,7 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
280
264
|
return callProc(maybeContext);
|
|
281
265
|
});
|
|
282
266
|
|
|
283
|
-
return proxy as ReturnType<RouterCaller<any>>;
|
|
267
|
+
return proxy as ReturnType<RouterCaller<any, any>>;
|
|
284
268
|
};
|
|
285
269
|
};
|
|
286
270
|
}
|
|
@@ -288,25 +272,15 @@ export function createCallerFactory<TRoot extends AnyRootTypes>() {
|
|
|
288
272
|
/** @internal */
|
|
289
273
|
type MergeRouters<
|
|
290
274
|
TRouters extends AnyRouter[],
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
{}
|
|
295
|
-
>,
|
|
275
|
+
TRoot extends AnyRootTypes = TRouters[0]['_def']['_config']['$types'],
|
|
276
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
277
|
+
TRecord extends ProcedureRouterRecord = {},
|
|
296
278
|
> = TRouters extends [
|
|
297
279
|
infer Head extends AnyRouter,
|
|
298
280
|
...infer Tail extends AnyRouter[],
|
|
299
281
|
]
|
|
300
|
-
? MergeRouters<
|
|
301
|
-
|
|
302
|
-
{
|
|
303
|
-
_config: TRouterDef['_config'];
|
|
304
|
-
router: true;
|
|
305
|
-
procedures: Head['_def']['procedures'] & TRouterDef['procedures'];
|
|
306
|
-
record: Head['_def']['record'] & TRouterDef['record'];
|
|
307
|
-
}
|
|
308
|
-
>
|
|
309
|
-
: Router<TRouterDef> & TRouterDef['record'];
|
|
282
|
+
? MergeRouters<Tail, TRoot, Head['_def']['record'] & TRecord>
|
|
283
|
+
: BuiltRouter<TRoot, TRecord>;
|
|
310
284
|
|
|
311
285
|
export function mergeRouters<TRouters extends AnyRouter[]>(
|
|
312
286
|
...routerList: [...TRouters]
|
|
@@ -353,12 +327,13 @@ export function mergeRouters<TRouters extends AnyRouter[]>(
|
|
|
353
327
|
const router = createRouterFactory({
|
|
354
328
|
errorFormatter,
|
|
355
329
|
transformer,
|
|
356
|
-
isDev: routerList.
|
|
357
|
-
allowOutsideOfServer: routerList.
|
|
330
|
+
isDev: routerList.every((r) => r._def._config.isDev),
|
|
331
|
+
allowOutsideOfServer: routerList.every(
|
|
358
332
|
(r) => r._def._config.allowOutsideOfServer,
|
|
359
333
|
),
|
|
360
|
-
isServer: routerList.
|
|
334
|
+
isServer: routerList.every((r) => r._def._config.isServer),
|
|
361
335
|
$types: routerList[0]?._def._config.$types,
|
|
362
336
|
})(record);
|
|
363
|
-
|
|
337
|
+
|
|
338
|
+
return router as MergeRouters<TRouters>;
|
|
364
339
|
}
|
|
@@ -5,9 +5,7 @@ import type { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
|
5
5
|
/**
|
|
6
6
|
* Error response
|
|
7
7
|
*/
|
|
8
|
-
export interface TRPCErrorShape<
|
|
9
|
-
TData extends Record<string, unknown> = Record<string, unknown>,
|
|
10
|
-
> {
|
|
8
|
+
export interface TRPCErrorShape<TData extends object = object> {
|
|
11
9
|
code: TRPC_ERROR_CODE_NUMBER;
|
|
12
10
|
message: string;
|
|
13
11
|
data: TData;
|