@trpc/server 10.0.0-alpha.29 → 10.0.0-alpha.31
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/types.d.ts +2 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/initTRPC.d.ts +30 -25
- package/dist/core/initTRPC.d.ts.map +1 -1
- package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +121 -41
- package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +1 -1
- package/dist/core/internals/config.d.ts +3 -5
- package/dist/core/internals/config.d.ts.map +1 -1
- package/dist/core/internals/internalProcedure.d.ts +18 -1
- package/dist/core/internals/internalProcedure.d.ts.map +1 -1
- package/dist/core/internals/mergeRouters.d.ts.map +1 -1
- package/dist/core/internals/prefixObjectKeys.d.ts +2 -0
- package/dist/core/internals/prefixObjectKeys.d.ts.map +1 -0
- package/dist/core/internals/procedureBuilder.d.ts +39 -8
- package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +16 -7
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/procedure.d.ts +26 -3
- package/dist/core/procedure.d.ts.map +1 -1
- package/dist/core/router.d.ts +52 -60
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/types.d.ts +9 -9
- package/dist/core/types.d.ts.map +1 -1
- package/dist/deprecated/interop.d.ts +23 -23
- package/dist/deprecated/interop.d.ts.map +1 -1
- package/dist/http/internals/types.d.ts +3 -3
- package/dist/http/internals/types.d.ts.map +1 -1
- package/dist/index.js +100 -56
- package/dist/index.mjs +100 -56
- package/dist/internals/types.d.ts +2 -2
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/observable/observable.d.ts +1 -1
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +2 -2
- package/src/adapters/node-http/types.ts +2 -4
- package/src/core/index.ts +1 -1
- package/src/core/initTRPC.ts +14 -9
- package/src/core/internals/__generated__/mergeRoutersGeneric.ts +184 -104
- package/src/core/internals/config.ts +4 -5
- package/src/core/internals/internalProcedure.ts +52 -21
- package/src/core/internals/mergeRouters.ts +3 -15
- package/src/core/internals/prefixObjectKeys.ts +9 -0
- package/src/core/internals/procedureBuilder.ts +92 -9
- package/src/core/middleware.ts +7 -4
- package/src/core/procedure.ts +38 -2
- package/src/core/router.ts +143 -136
- package/src/core/types.ts +33 -16
- package/src/deprecated/interop.ts +110 -50
- package/src/http/internals/types.ts +3 -3
- package/src/internals/types.ts +2 -2
- package/src/observable/observable.ts +6 -3
- package/src/types.ts +9 -0
- package/dist/core/internals/mergeRoutersGeneric.d.ts +0 -21
- package/dist/core/internals/mergeRoutersGeneric.d.ts.map +0 -1
- package/src/core/internals/mergeRoutersGeneric.ts +0 -35
|
@@ -1,49 +1,80 @@
|
|
|
1
|
+
import { CombinedDataTransformer, ProcedureParams, ProcedureType } from '..';
|
|
2
|
+
import { CreateRootConfig, RootConfig } from '../core/internals/config';
|
|
1
3
|
import { getParseFnOrPassThrough } from '../core/internals/getParseFn';
|
|
2
4
|
import {
|
|
3
5
|
createInputMiddleware,
|
|
4
6
|
createInternalBuilder,
|
|
5
7
|
createOutputMiddleware,
|
|
6
8
|
} from '../core/internals/internalProcedure';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
+
import { mergeWithoutOverrides } from '../core/internals/mergeWithoutOverrides';
|
|
10
|
+
import {
|
|
11
|
+
MutationProcedure,
|
|
12
|
+
Procedure as NewProcedure,
|
|
13
|
+
QueryProcedure,
|
|
14
|
+
SubscriptionProcedure,
|
|
15
|
+
} from '../core/procedure';
|
|
16
|
+
import {
|
|
17
|
+
Router as NewRouter,
|
|
18
|
+
RouterDef,
|
|
19
|
+
createRouterFactory,
|
|
20
|
+
} from '../core/router';
|
|
9
21
|
import {
|
|
10
22
|
AnyRouter as AnyOldRouter,
|
|
11
23
|
Router as OldRouter,
|
|
12
24
|
} from '../deprecated/router';
|
|
13
25
|
import { TRPCErrorShape } from '../rpc';
|
|
14
|
-
import { CombinedDataTransformer } from '../transformer';
|
|
15
26
|
import { Procedure as OldProcedure } from './internals/procedure';
|
|
16
27
|
import { ProcedureRecord } from './router';
|
|
17
28
|
|
|
18
29
|
type AnyOldProcedure = OldProcedure<any, any, any, any, any, any, any, any>;
|
|
19
|
-
type MigrateProcedure<TProcedure extends AnyOldProcedure> =
|
|
20
|
-
TProcedure extends OldProcedure<
|
|
21
|
-
infer TInputContext,
|
|
22
|
-
infer TContext,
|
|
23
|
-
infer TMeta,
|
|
24
|
-
infer TInput,
|
|
25
|
-
infer TParsedInput,
|
|
26
|
-
infer TOutput,
|
|
27
|
-
infer _TParsedOutput,
|
|
28
|
-
infer TFinalInput
|
|
29
|
-
>
|
|
30
|
-
? NewProcedure<{
|
|
31
|
-
_ctx_in: TInputContext;
|
|
32
|
-
_ctx_out: TContext;
|
|
33
|
-
_meta: TMeta;
|
|
34
|
-
_input_in: TInput;
|
|
35
|
-
_input_out: TParsedInput;
|
|
36
|
-
_output_in: TOutput;
|
|
37
|
-
_output_out: TFinalInput;
|
|
38
|
-
}>
|
|
39
|
-
: never;
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
type convertProcedureParams<
|
|
32
|
+
TConfig extends RootConfig,
|
|
33
|
+
TProcedure extends AnyOldProcedure,
|
|
34
|
+
> = TProcedure extends OldProcedure<
|
|
35
|
+
infer TInputContext,
|
|
36
|
+
infer TContext,
|
|
37
|
+
infer TMeta,
|
|
38
|
+
infer TInput,
|
|
39
|
+
infer TParsedInput,
|
|
40
|
+
infer TOutput,
|
|
41
|
+
infer _TParsedOutput,
|
|
42
|
+
infer TFinalInput
|
|
43
|
+
>
|
|
44
|
+
? ProcedureParams<
|
|
45
|
+
TConfig,
|
|
46
|
+
TInputContext,
|
|
47
|
+
TContext,
|
|
48
|
+
TInput,
|
|
49
|
+
TParsedInput,
|
|
50
|
+
TOutput,
|
|
51
|
+
TFinalInput,
|
|
52
|
+
TMeta
|
|
53
|
+
>
|
|
54
|
+
: never;
|
|
55
|
+
|
|
56
|
+
type MigrateProcedure<
|
|
57
|
+
TConfig extends RootConfig,
|
|
58
|
+
TProcedure extends AnyOldProcedure,
|
|
59
|
+
TType extends ProcedureType,
|
|
60
|
+
> = TType extends 'query'
|
|
61
|
+
? QueryProcedure<convertProcedureParams<TConfig, TProcedure>>
|
|
62
|
+
: TType extends 'mutation'
|
|
63
|
+
? MutationProcedure<convertProcedureParams<TConfig, TProcedure>>
|
|
64
|
+
: TType extends 'subscription'
|
|
65
|
+
? SubscriptionProcedure<convertProcedureParams<TConfig, TProcedure>>
|
|
66
|
+
: never;
|
|
67
|
+
|
|
68
|
+
export type MigrateProcedureRecord<
|
|
69
|
+
TConfig extends RootConfig,
|
|
70
|
+
T extends ProcedureRecord<any>,
|
|
71
|
+
TType extends ProcedureType,
|
|
72
|
+
> = {
|
|
73
|
+
[K in keyof T]: MigrateProcedure<TConfig, T[K], TType>;
|
|
43
74
|
};
|
|
44
75
|
|
|
45
76
|
export type MigrateRouter<
|
|
46
|
-
TInputContext,
|
|
77
|
+
TInputContext extends Record<string, any>,
|
|
47
78
|
TContext,
|
|
48
79
|
TMeta extends Record<string, any>,
|
|
49
80
|
TQueries extends ProcedureRecord<
|
|
@@ -73,17 +104,44 @@ export type MigrateRouter<
|
|
|
73
104
|
unknown,
|
|
74
105
|
unknown
|
|
75
106
|
>,
|
|
76
|
-
TErrorShape extends TRPCErrorShape<
|
|
77
|
-
> = NewRouter<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
TErrorShape extends TRPCErrorShape<any>,
|
|
108
|
+
> = NewRouter<
|
|
109
|
+
RouterDef<
|
|
110
|
+
TInputContext,
|
|
111
|
+
TErrorShape,
|
|
112
|
+
TMeta,
|
|
113
|
+
MigrateProcedureRecord<
|
|
114
|
+
CreateRootConfig<{
|
|
115
|
+
ctx: TInputContext;
|
|
116
|
+
errorShape: TErrorShape;
|
|
117
|
+
meta: TMeta;
|
|
118
|
+
transformer: CombinedDataTransformer;
|
|
119
|
+
}>,
|
|
120
|
+
TQueries,
|
|
121
|
+
'query'
|
|
122
|
+
> &
|
|
123
|
+
MigrateProcedureRecord<
|
|
124
|
+
CreateRootConfig<{
|
|
125
|
+
ctx: TInputContext;
|
|
126
|
+
errorShape: TErrorShape;
|
|
127
|
+
meta: TMeta;
|
|
128
|
+
transformer: CombinedDataTransformer;
|
|
129
|
+
}>,
|
|
130
|
+
TMutations,
|
|
131
|
+
'mutation'
|
|
132
|
+
> &
|
|
133
|
+
MigrateProcedureRecord<
|
|
134
|
+
CreateRootConfig<{
|
|
135
|
+
ctx: TInputContext;
|
|
136
|
+
errorShape: TErrorShape;
|
|
137
|
+
meta: TMeta;
|
|
138
|
+
transformer: CombinedDataTransformer;
|
|
139
|
+
}>,
|
|
140
|
+
TSubscriptions,
|
|
141
|
+
'subscription'
|
|
142
|
+
>
|
|
143
|
+
>
|
|
144
|
+
>;
|
|
87
145
|
|
|
88
146
|
export type MigrateOldRouter<TRouter extends AnyOldRouter> =
|
|
89
147
|
TRouter extends OldRouter<
|
|
@@ -106,9 +164,10 @@ export type MigrateOldRouter<TRouter extends AnyOldRouter> =
|
|
|
106
164
|
>
|
|
107
165
|
: never;
|
|
108
166
|
|
|
109
|
-
function migrateProcedure<
|
|
110
|
-
|
|
111
|
-
|
|
167
|
+
function migrateProcedure<
|
|
168
|
+
TProcedure extends AnyOldProcedure,
|
|
169
|
+
TType extends ProcedureType,
|
|
170
|
+
>(oldProc: TProcedure, type: TType): MigrateProcedure<any, TProcedure, TType> {
|
|
112
171
|
const def = oldProc._def();
|
|
113
172
|
|
|
114
173
|
const inputParser = getParseFnOrPassThrough(def.inputParser);
|
|
@@ -125,9 +184,12 @@ function migrateProcedure<TProcedure extends AnyOldProcedure>(
|
|
|
125
184
|
],
|
|
126
185
|
meta: def.meta,
|
|
127
186
|
output: def.outputParser,
|
|
187
|
+
mutation: type === 'mutation',
|
|
188
|
+
query: type === 'query',
|
|
189
|
+
subscription: type === 'subscription',
|
|
128
190
|
});
|
|
129
191
|
|
|
130
|
-
const proc = builder
|
|
192
|
+
const proc = builder[type]((opts) => def.resolver(opts as any));
|
|
131
193
|
|
|
132
194
|
return proc as any;
|
|
133
195
|
}
|
|
@@ -143,27 +205,25 @@ export function migrateRouter<TOldRouter extends AnyOldRouter>(
|
|
|
143
205
|
const mutations: ProcRecord = {};
|
|
144
206
|
const subscriptions: ProcRecord = {};
|
|
145
207
|
for (const [name, procedure] of Object.entries(oldRouter._def.queries)) {
|
|
146
|
-
queries[name] = migrateProcedure(procedure as any);
|
|
208
|
+
queries[name] = migrateProcedure(procedure as any, 'query');
|
|
147
209
|
}
|
|
148
210
|
|
|
149
211
|
for (const [name, procedure] of Object.entries(oldRouter._def.mutations)) {
|
|
150
|
-
mutations[name] = migrateProcedure(procedure as any);
|
|
212
|
+
mutations[name] = migrateProcedure(procedure as any, 'mutation');
|
|
151
213
|
}
|
|
152
214
|
|
|
153
215
|
for (const [name, procedure] of Object.entries(
|
|
154
216
|
oldRouter._def.subscriptions,
|
|
155
217
|
)) {
|
|
156
|
-
subscriptions[name] = migrateProcedure(procedure as any);
|
|
218
|
+
subscriptions[name] = migrateProcedure(procedure as any, 'subscription');
|
|
157
219
|
}
|
|
158
220
|
|
|
221
|
+
const procedures = mergeWithoutOverrides(queries, mutations, subscriptions);
|
|
222
|
+
|
|
159
223
|
const newRouter = createRouterFactory<any>({
|
|
160
224
|
transformer,
|
|
161
225
|
errorFormatter,
|
|
162
|
-
})(
|
|
163
|
-
mutations,
|
|
164
|
-
queries,
|
|
165
|
-
subscriptions,
|
|
166
|
-
});
|
|
226
|
+
})(procedures);
|
|
167
227
|
|
|
168
228
|
return newRouter as any;
|
|
169
229
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRouter, ProcedureType,
|
|
1
|
+
import { AnyRouter, ProcedureType, inferRouterDef } from '../../core';
|
|
2
2
|
import { TRPCError } from '../../error/TRPCError';
|
|
3
3
|
import { BaseHandlerOptions } from '../../internals/types';
|
|
4
4
|
import { TRPCResponse } from '../../rpc';
|
|
@@ -24,8 +24,8 @@ export interface HTTPRequest {
|
|
|
24
24
|
* @internal
|
|
25
25
|
*/
|
|
26
26
|
export type ResponseMetaFn<TRouter extends AnyRouter> = (opts: {
|
|
27
|
-
data: TRPCResponse<unknown,
|
|
28
|
-
ctx?:
|
|
27
|
+
data: TRPCResponse<unknown, inferRouterDef<TRouter>['_error']>[];
|
|
28
|
+
ctx?: inferRouterDef<TRouter>['_ctx'];
|
|
29
29
|
/**
|
|
30
30
|
* The different tRPC paths requested
|
|
31
31
|
**/
|
package/src/internals/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { inferRouterDef } from '../core';
|
|
2
2
|
import { ProcedureType } from '../core';
|
|
3
3
|
import { AnyRouter } from '../core/router';
|
|
4
4
|
import { TRPCError } from '../error/TRPCError';
|
|
@@ -20,5 +20,5 @@ export type OnErrorFunction<TRouter extends AnyRouter, TRequest> = (opts: {
|
|
|
20
20
|
path: string | undefined;
|
|
21
21
|
req: TRequest;
|
|
22
22
|
input: unknown;
|
|
23
|
-
ctx: undefined |
|
|
23
|
+
ctx: undefined | inferRouterDef<TRouter>['_ctx'];
|
|
24
24
|
}) => void;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { pipeFromArray } from './internals/pipe';
|
|
2
2
|
import { Observable, Observer, OperatorFunction, TeardownLogic } from './types';
|
|
3
3
|
|
|
4
|
-
export type inferObservableValue<
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export type inferObservableValue<TObservable> = TObservable extends Observable<
|
|
5
|
+
infer TValue,
|
|
6
|
+
unknown
|
|
7
|
+
>
|
|
8
|
+
? TValue
|
|
9
|
+
: never;
|
|
7
10
|
|
|
8
11
|
export function isObservable(x: unknown): x is Observable<unknown, unknown> {
|
|
9
12
|
return typeof x === 'object' && x !== null && 'subscribe' in x;
|
package/src/types.ts
CHANGED
|
@@ -65,3 +65,12 @@ export type InferLast<T> = T & { [K in keyof T]: T[K] };
|
|
|
65
65
|
*/
|
|
66
66
|
export type inferAsyncReturnType<TFunction extends (...args: any) => any> =
|
|
67
67
|
ThenArg<ReturnType<TFunction>>;
|
|
68
|
+
|
|
69
|
+
type FilterKeys<T extends object, K> = {
|
|
70
|
+
[TKey in keyof T]: T[TKey] extends K ? TKey : never;
|
|
71
|
+
}[keyof T];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export type Filter<T extends object, K> = Pick<T, FilterKeys<T, K>>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thanks to @phryneas!
|
|
3
|
-
*
|
|
4
|
-
* @link https://twitter.com/phry/status/1538516854058242048
|
|
5
|
-
*/
|
|
6
|
-
import { AnyRouterParams, AnyRouter, Router } from "../router";
|
|
7
|
-
declare type TailIntersectProperty<Elements extends AnyRouterParams[], Property extends keyof AnyRouterParams, Acc = unknown> = Elements extends [infer Head extends AnyRouterParams, ...infer Tail extends AnyRouterParams[]] ? TailIntersectProperty<Tail, Property, Head[Property] & Acc> : Acc;
|
|
8
|
-
declare type RouterToParam<R extends Router<any>> = R extends Router<infer P> ? P : never;
|
|
9
|
-
declare type RoutersToParams<T, Acc extends unknown[] = []> = T extends [infer Head extends Router<any>, ...infer Tail] ? RoutersToParams<Tail, [...Acc, RouterToParam<Head>]> : Acc;
|
|
10
|
-
export declare function mergeRoutersGeneric<Routers extends [...AnyRouter[]]>(...routers: Routers): RoutersToParams<Routers> extends infer AllParams extends AnyRouterParams[] ? Router<{
|
|
11
|
-
_ctx: RouterToParam<Routers[0]>['_ctx'];
|
|
12
|
-
_errorShape: RouterToParam<Routers[0]>['_errorShape'];
|
|
13
|
-
_meta: RouterToParam<Routers[0]>['_meta'];
|
|
14
|
-
transformer: RouterToParam<Routers[0]>['transformer'];
|
|
15
|
-
errorFormatter: RouterToParam<Routers[0]>['errorFormatter'];
|
|
16
|
-
queries: TailIntersectProperty<AllParams, 'queries'>;
|
|
17
|
-
mutations: TailIntersectProperty<AllParams, 'mutations'>;
|
|
18
|
-
subscriptions: TailIntersectProperty<AllParams, 'subscriptions'>;
|
|
19
|
-
}> : never;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=mergeRoutersGeneric.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeRoutersGeneric.d.ts","sourceRoot":"","sources":["../../../src/core/internals/mergeRoutersGeneric.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAI/D,aAAK,qBAAqB,CAAC,QAAQ,SAAS,eAAe,EAAE,EAAE,QAAQ,SAAS,MAAM,eAAe,EAAE,GAAG,GAAG,OAAO,IAEhH,QAAQ,SAAS,CAAC,MAAM,IAAI,SAAS,eAAe,EAAE,GAAG,MAAM,IAAI,SAAS,eAAe,EAAE,CAAC,GAAG,qBAAqB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAGvK,aAAK,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAEjF,aAAK,eAAe,CAAC,CAAC,EAAE,GAAG,SAAS,OAAO,EAAE,GAAG,EAAE,IAC9C,CAAC,SAAS,CAAC,MAAM,IAAI,SAAS,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,eAAe,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAE3H,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,CAAC,GAAG,SAAS,EAAE,CAAC,EAChE,GAAG,OAAO,EAAE,OAAO,GAClB,eAAe,CAAC,OAAO,CAAC,SAAS,MAAM,SAAS,SAAS,eAAe,EAAE,GAC1E,MAAM,CAAC;IACJ,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IACtD,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1C,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IACtD,cAAc,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAC5D,OAAO,EAAE,qBAAqB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACrD,SAAS,EAAE,qBAAqB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACzD,aAAa,EAAE,qBAAqB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;CACpE,CAAC,GAAG,KAAK,CAEb"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thanks to @phryneas!
|
|
3
|
-
*
|
|
4
|
-
* @link https://twitter.com/phry/status/1538516854058242048
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { AnyRouterParams, AnyRouter, Router } from "../router";
|
|
8
|
-
import { mergeRouters } from "./mergeRouters";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type TailIntersectProperty<Elements extends AnyRouterParams[], Property extends keyof AnyRouterParams, Acc = unknown> =
|
|
12
|
-
// eslint-disable-next-line prettier/prettier
|
|
13
|
-
Elements extends [infer Head extends AnyRouterParams, ...infer Tail extends AnyRouterParams[]] ? TailIntersectProperty<Tail, Property, Head[Property] & Acc> : Acc;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type RouterToParam<R extends Router<any>> = R extends Router<infer P> ? P : never
|
|
17
|
-
|
|
18
|
-
type RoutersToParams<T, Acc extends unknown[] = []> =
|
|
19
|
-
T extends [infer Head extends Router<any>, ...infer Tail] ? RoutersToParams<Tail, [...Acc, RouterToParam<Head>]> : Acc;
|
|
20
|
-
|
|
21
|
-
export function mergeRoutersGeneric<Routers extends [...AnyRouter[]]>(
|
|
22
|
-
...routers: Routers
|
|
23
|
-
): RoutersToParams<Routers> extends infer AllParams extends AnyRouterParams[] ?
|
|
24
|
-
Router<{
|
|
25
|
-
_ctx: RouterToParam<Routers[0]>['_ctx'];
|
|
26
|
-
_errorShape: RouterToParam<Routers[0]>['_errorShape'];
|
|
27
|
-
_meta: RouterToParam<Routers[0]>['_meta'];
|
|
28
|
-
transformer: RouterToParam<Routers[0]>['transformer'];
|
|
29
|
-
errorFormatter: RouterToParam<Routers[0]>['errorFormatter'];
|
|
30
|
-
queries: TailIntersectProperty<AllParams, 'queries'>;
|
|
31
|
-
mutations: TailIntersectProperty<AllParams, 'mutations'>;
|
|
32
|
-
subscriptions: TailIntersectProperty<AllParams, 'subscriptions'>;
|
|
33
|
-
}> : never {
|
|
34
|
-
return mergeRouters(...routers) as any;
|
|
35
|
-
}
|