@trpc/server 11.0.0-next-beta.242 → 11.0.0-next-beta.285
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/index.d.ts +1 -5
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +2 -2
- package/dist/adapters/node-http/content-type/form-data/index.mjs +1 -1
- package/dist/bundle-analysis.json +56 -114
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +25 -4
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -1
- 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 +15 -7
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +25 -18
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +36 -19
- package/dist/unstable-core-do-not-import/router.mjs +37 -20
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +1 -2
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/types.d.ts +1 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/@trpc/server/index.ts +1 -5
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +35 -4
- package/src/unstable-core-do-not-import/index.ts +0 -2
- package/src/unstable-core-do-not-import/router.ts +84 -54
- package/src/unstable-core-do-not-import/rpc/codes.ts +1 -1
- package/src/unstable-core-do-not-import/types.ts +1 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
|
@@ -2,29 +2,27 @@ import type { AnyProcedure, inferProcedureInput, inferTransformedProcedureOutput
|
|
|
2
2
|
import type { ProcedureCallOptions } from './procedureBuilder';
|
|
3
3
|
import type { AnyRootTypes, RootConfig } from './rootConfig';
|
|
4
4
|
import type { MaybePromise } from './types';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export interface ProcedureRouterRecord {
|
|
8
|
-
[key: string]: AnyProcedure | AnyRouter;
|
|
5
|
+
export interface RouterRecord {
|
|
6
|
+
[key: string]: AnyProcedure | RouterRecord;
|
|
9
7
|
}
|
|
10
8
|
type DecorateProcedure<TProcedure extends AnyProcedure> = (input: inferProcedureInput<TProcedure>) => Promise<TProcedure['_def']['_output_out']>;
|
|
11
9
|
/**
|
|
12
10
|
* @internal
|
|
13
11
|
*/
|
|
14
|
-
export type
|
|
15
|
-
[TKey in keyof
|
|
12
|
+
export type DecorateRouterRecord<TRecord extends RouterRecord> = {
|
|
13
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends AnyProcedure ? DecorateProcedure<TRecord[TKey]> : TRecord[TKey] extends RouterRecord ? DecorateRouterRecord<TRecord[TKey]> : never;
|
|
16
14
|
};
|
|
17
15
|
/**
|
|
18
16
|
* @internal
|
|
19
17
|
*/
|
|
20
|
-
export type RouterCaller<TRoot extends AnyRootTypes, TRecord extends
|
|
18
|
+
export type RouterCaller<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = (
|
|
21
19
|
/**
|
|
22
20
|
* @note
|
|
23
21
|
* If passing a function, we recommend it's a cached function
|
|
24
22
|
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
25
23
|
*/
|
|
26
|
-
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>)) =>
|
|
27
|
-
export interface Router<TRoot extends AnyRootTypes, TRecord extends
|
|
24
|
+
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>)) => DecorateRouterRecord<TRecord>;
|
|
25
|
+
export interface Router<TRoot extends AnyRootTypes, TRecord extends RouterRecord> {
|
|
28
26
|
_def: {
|
|
29
27
|
_config: RootConfig<TRoot>;
|
|
30
28
|
router: true;
|
|
@@ -38,30 +36,39 @@ export interface Router<TRoot extends AnyRootTypes, TRecord extends ProcedureRou
|
|
|
38
36
|
*/
|
|
39
37
|
createCaller: RouterCaller<TRoot, TRecord>;
|
|
40
38
|
}
|
|
41
|
-
export type BuiltRouter<TRoot extends AnyRootTypes,
|
|
39
|
+
export type BuiltRouter<TRoot extends AnyRootTypes, TDef extends RouterRecord> = Router<TRoot, TDef> & TDef;
|
|
42
40
|
export type AnyRouter = Router<any, any>;
|
|
43
41
|
export type inferRouterRootTypes<TRouter extends AnyRouter> = TRouter['_def']['_config']['$types'];
|
|
44
42
|
export type inferRouterContext<TRouter extends AnyRouter> = inferRouterRootTypes<TRouter>['ctx'];
|
|
45
43
|
export type inferRouterError<TRouter extends AnyRouter> = inferRouterRootTypes<TRouter>['errorShape'];
|
|
46
44
|
export type inferRouterMeta<TRouter extends AnyRouter> = inferRouterRootTypes<TRouter>['meta'];
|
|
47
|
-
export type GetInferenceHelpers<TType extends 'input' | 'output',
|
|
48
|
-
[TKey in keyof
|
|
45
|
+
export type GetInferenceHelpers<TType extends 'input' | 'output', TRoot extends AnyRootTypes, TRecord extends RouterRecord> = {
|
|
46
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? GetInferenceHelpers<TType, TRoot, $Value> : $Value extends AnyProcedure ? TType extends 'input' ? inferProcedureInput<$Value> : inferTransformedProcedureOutput<TRoot, $Value> : never : never;
|
|
47
|
+
};
|
|
48
|
+
export type inferRouterInputs<TRouter extends AnyRouter> = GetInferenceHelpers<'input', TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
|
49
|
+
export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<'output', TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
|
50
|
+
export type CreateRouterOptions = {
|
|
51
|
+
[key: string]: AnyProcedure | AnyRouter | CreateRouterOptions;
|
|
52
|
+
};
|
|
53
|
+
export type DecorateCreateRouterOptions<TRouterOptions extends CreateRouterOptions> = {
|
|
54
|
+
[K in keyof TRouterOptions]: TRouterOptions[K] extends infer $Value ? $Value extends AnyProcedure ? $Value : $Value extends Router<any, infer TRecord> ? TRecord : $Value extends CreateRouterOptions ? DecorateCreateRouterOptions<$Value> : never : never;
|
|
49
55
|
};
|
|
50
|
-
export type inferRouterInputs<TRouter extends AnyRouter> = GetInferenceHelpers<'input', TRouter>;
|
|
51
|
-
export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<'output', TRouter>;
|
|
52
56
|
/**
|
|
53
57
|
* @internal
|
|
54
58
|
*/
|
|
55
|
-
export declare function createRouterFactory<TRoot extends AnyRootTypes>(config: RootConfig<TRoot>):
|
|
59
|
+
export declare function createRouterFactory<TRoot extends AnyRootTypes>(config: RootConfig<TRoot>): {
|
|
60
|
+
<TInput extends RouterRecord>(input: TInput): BuiltRouter<TRoot, TInput>;
|
|
61
|
+
<TInput_1 extends CreateRouterOptions>(input: TInput_1): BuiltRouter<TRoot, DecorateCreateRouterOptions<TInput_1>>;
|
|
62
|
+
};
|
|
56
63
|
/**
|
|
57
64
|
* @internal
|
|
58
65
|
*/
|
|
59
66
|
export declare function callProcedure(opts: ProcedureCallOptions & {
|
|
60
|
-
procedures:
|
|
67
|
+
procedures: RouterRecord;
|
|
61
68
|
}): Promise<unknown>;
|
|
62
|
-
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <TRecord extends
|
|
69
|
+
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <TRecord extends RouterRecord>(router: Router<TRoot, TRecord>) => RouterCaller<TRoot, TRecord>;
|
|
63
70
|
/** @internal */
|
|
64
|
-
type MergeRouters<TRouters extends AnyRouter[], TRoot extends AnyRootTypes = TRouters[0]['_def']['_config']['$types'], TRecord extends
|
|
71
|
+
type MergeRouters<TRouters extends AnyRouter[], TRoot extends AnyRootTypes = TRouters[0]['_def']['_config']['$types'], TRecord extends RouterRecord = {}> = TRouters extends [
|
|
65
72
|
infer Head extends AnyRouter,
|
|
66
73
|
...infer Tail extends AnyRouter[]
|
|
67
74
|
] ? MergeRouters<Tail, TRoot, Head['_def']['record'] & TRecord> : BuiltRouter<TRoot, TRecord>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/router.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,+BAA+B,EAChC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/router.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,+BAA+B,EAChC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EA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AAS,SAAS;IAC5B,GAAG,MAAM,IAAI,SAAS,SAAS,EAAE;CAClC,GACG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,GAC3D,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAEhC,wBAAgB,YAAY,CAAC,QAAQ,SAAS,SAAS,EAAE,EACvD,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,GAC3B,YAAY,CAAC,QAAQ,CAAC,CAoDxB"}
|
|
@@ -7,7 +7,7 @@ var transformer = require('./transformer.js');
|
|
|
7
7
|
var utils = require('./utils.js');
|
|
8
8
|
|
|
9
9
|
function isRouter(procedureOrRouter) {
|
|
10
|
-
return 'router' in procedureOrRouter._def;
|
|
10
|
+
return procedureOrRouter._def && 'router' in procedureOrRouter._def;
|
|
11
11
|
}
|
|
12
12
|
const emptyRouter = {
|
|
13
13
|
_ctx: null,
|
|
@@ -30,35 +30,52 @@ const emptyRouter = {
|
|
|
30
30
|
/**
|
|
31
31
|
* @internal
|
|
32
32
|
*/ function createRouterFactory(config) {
|
|
33
|
-
|
|
34
|
-
const reservedWordsUsed = new Set(Object.keys(
|
|
33
|
+
function createRouterInner(input) {
|
|
34
|
+
const reservedWordsUsed = new Set(Object.keys(input).filter((v)=>reservedWords.includes(v)));
|
|
35
35
|
if (reservedWordsUsed.size > 0) {
|
|
36
36
|
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
37
37
|
}
|
|
38
|
-
const
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (isRouter(
|
|
43
|
-
|
|
38
|
+
const procedures = utils.omitPrototype({});
|
|
39
|
+
function step(from, path = []) {
|
|
40
|
+
const aggregate = utils.omitPrototype({});
|
|
41
|
+
for (const [key, item] of Object.entries(from ?? {})){
|
|
42
|
+
if (isRouter(item)) {
|
|
43
|
+
aggregate[key] = step(item._def.record, [
|
|
44
|
+
...path,
|
|
45
|
+
key
|
|
46
|
+
]);
|
|
44
47
|
continue;
|
|
45
48
|
}
|
|
46
|
-
if (
|
|
49
|
+
if (!isProcedure(item)) {
|
|
50
|
+
// RouterRecord
|
|
51
|
+
aggregate[key] = step(item, [
|
|
52
|
+
...path,
|
|
53
|
+
key
|
|
54
|
+
]);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const newPath = [
|
|
58
|
+
...path,
|
|
59
|
+
key
|
|
60
|
+
].join('.');
|
|
61
|
+
if (procedures[newPath]) {
|
|
47
62
|
throw new Error(`Duplicate key: ${newPath}`);
|
|
48
63
|
}
|
|
49
|
-
|
|
64
|
+
procedures[newPath] = item;
|
|
65
|
+
aggregate[key] = item;
|
|
50
66
|
}
|
|
67
|
+
return aggregate;
|
|
51
68
|
}
|
|
52
|
-
|
|
69
|
+
const record = step(input);
|
|
53
70
|
const _def = {
|
|
54
71
|
_config: config,
|
|
55
72
|
router: true,
|
|
56
|
-
procedures
|
|
73
|
+
procedures,
|
|
57
74
|
...emptyRouter,
|
|
58
|
-
record
|
|
75
|
+
record
|
|
59
76
|
};
|
|
60
|
-
|
|
61
|
-
...
|
|
77
|
+
return {
|
|
78
|
+
...record,
|
|
62
79
|
_def,
|
|
63
80
|
createCaller (ctx) {
|
|
64
81
|
const proxy = createProxy.createRecursiveProxy(({ path , args })=>{
|
|
@@ -74,11 +91,11 @@ const emptyRouter = {
|
|
|
74
91
|
return proxy;
|
|
75
92
|
}
|
|
76
93
|
};
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
}
|
|
95
|
+
return createRouterInner;
|
|
79
96
|
}
|
|
80
97
|
function isProcedure(procedureOrRouter) {
|
|
81
|
-
return
|
|
98
|
+
return typeof procedureOrRouter === 'function';
|
|
82
99
|
}
|
|
83
100
|
/**
|
|
84
101
|
* @internal
|
|
@@ -2,10 +2,10 @@ import { createRecursiveProxy } from './createProxy.mjs';
|
|
|
2
2
|
import { defaultFormatter } from './error/formatter.mjs';
|
|
3
3
|
import { TRPCError } from './error/TRPCError.mjs';
|
|
4
4
|
import { defaultTransformer } from './transformer.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { mergeWithoutOverrides, omitPrototype } from './utils.mjs';
|
|
6
6
|
|
|
7
7
|
function isRouter(procedureOrRouter) {
|
|
8
|
-
return 'router' in procedureOrRouter._def;
|
|
8
|
+
return procedureOrRouter._def && 'router' in procedureOrRouter._def;
|
|
9
9
|
}
|
|
10
10
|
const emptyRouter = {
|
|
11
11
|
_ctx: null,
|
|
@@ -28,35 +28,52 @@ const emptyRouter = {
|
|
|
28
28
|
/**
|
|
29
29
|
* @internal
|
|
30
30
|
*/ function createRouterFactory(config) {
|
|
31
|
-
|
|
32
|
-
const reservedWordsUsed = new Set(Object.keys(
|
|
31
|
+
function createRouterInner(input) {
|
|
32
|
+
const reservedWordsUsed = new Set(Object.keys(input).filter((v)=>reservedWords.includes(v)));
|
|
33
33
|
if (reservedWordsUsed.size > 0) {
|
|
34
34
|
throw new Error('Reserved words used in `router({})` call: ' + Array.from(reservedWordsUsed).join(', '));
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (isRouter(
|
|
41
|
-
|
|
36
|
+
const procedures = omitPrototype({});
|
|
37
|
+
function step(from, path = []) {
|
|
38
|
+
const aggregate = omitPrototype({});
|
|
39
|
+
for (const [key, item] of Object.entries(from ?? {})){
|
|
40
|
+
if (isRouter(item)) {
|
|
41
|
+
aggregate[key] = step(item._def.record, [
|
|
42
|
+
...path,
|
|
43
|
+
key
|
|
44
|
+
]);
|
|
42
45
|
continue;
|
|
43
46
|
}
|
|
44
|
-
if (
|
|
47
|
+
if (!isProcedure(item)) {
|
|
48
|
+
// RouterRecord
|
|
49
|
+
aggregate[key] = step(item, [
|
|
50
|
+
...path,
|
|
51
|
+
key
|
|
52
|
+
]);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const newPath = [
|
|
56
|
+
...path,
|
|
57
|
+
key
|
|
58
|
+
].join('.');
|
|
59
|
+
if (procedures[newPath]) {
|
|
45
60
|
throw new Error(`Duplicate key: ${newPath}`);
|
|
46
61
|
}
|
|
47
|
-
|
|
62
|
+
procedures[newPath] = item;
|
|
63
|
+
aggregate[key] = item;
|
|
48
64
|
}
|
|
65
|
+
return aggregate;
|
|
49
66
|
}
|
|
50
|
-
|
|
67
|
+
const record = step(input);
|
|
51
68
|
const _def = {
|
|
52
69
|
_config: config,
|
|
53
70
|
router: true,
|
|
54
|
-
procedures
|
|
71
|
+
procedures,
|
|
55
72
|
...emptyRouter,
|
|
56
|
-
record
|
|
73
|
+
record
|
|
57
74
|
};
|
|
58
|
-
|
|
59
|
-
...
|
|
75
|
+
return {
|
|
76
|
+
...record,
|
|
60
77
|
_def,
|
|
61
78
|
createCaller (ctx) {
|
|
62
79
|
const proxy = createRecursiveProxy(({ path , args })=>{
|
|
@@ -72,11 +89,11 @@ const emptyRouter = {
|
|
|
72
89
|
return proxy;
|
|
73
90
|
}
|
|
74
91
|
};
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
}
|
|
93
|
+
return createRouterInner;
|
|
77
94
|
}
|
|
78
95
|
function isProcedure(procedureOrRouter) {
|
|
79
|
-
return
|
|
96
|
+
return typeof procedureOrRouter === 'function';
|
|
80
97
|
}
|
|
81
98
|
/**
|
|
82
99
|
* @internal
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ValueOf } from '../types';
|
|
1
2
|
/**
|
|
2
3
|
* JSON-RPC 2.0 Error codes
|
|
3
4
|
*
|
|
@@ -44,8 +45,6 @@ export declare const TRPC_ERROR_CODES_BY_NUMBER: {
|
|
|
44
45
|
[-32029]: "TOO_MANY_REQUESTS";
|
|
45
46
|
[-32099]: "CLIENT_CLOSED_REQUEST";
|
|
46
47
|
};
|
|
47
|
-
type ValueOf<TObj> = TObj[keyof TObj];
|
|
48
48
|
export type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
49
49
|
export type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
|
|
50
|
-
export {};
|
|
51
50
|
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/codes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/codes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAKxC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;OAGG;;IAEH;;OAEG;;;;;;;;;;;;;;;CAmBK,CAAC;AAEX,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;CAAkC,CAAC;AAE1E,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,KAAK,SAAS,GAAG,EAAE,GAAG,IAAI,GACpD,KAAK,GACL;KAAG,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAAE,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,KA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beta.285+e18d84950",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -157,5 +157,5 @@
|
|
|
157
157
|
"funding": [
|
|
158
158
|
"https://trpc.io/sponsor"
|
|
159
159
|
],
|
|
160
|
-
"gitHead": "
|
|
160
|
+
"gitHead": "e18d84950b13f4cfce437473dde62e39a27c4879"
|
|
161
161
|
}
|
|
@@ -26,7 +26,7 @@ export {
|
|
|
26
26
|
type ProcedureType as TRPCProcedureType,
|
|
27
27
|
type AnyMutationProcedure as AnyTRPCMutationProcedure,
|
|
28
28
|
type AnyQueryProcedure as AnyTRPCQueryProcedure,
|
|
29
|
-
type
|
|
29
|
+
type RouterRecord as TRPCRouterRecord,
|
|
30
30
|
type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure,
|
|
31
31
|
type ProcedureOptions as TRPCProcedureOptions,
|
|
32
32
|
} from '../../unstable-core-do-not-import';
|
|
@@ -71,10 +71,6 @@ export type {
|
|
|
71
71
|
* @deprecated use `AnyTRPCQueryProcedure` instead
|
|
72
72
|
*/
|
|
73
73
|
AnyQueryProcedure,
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated use `TRPCProcedureRouterRecord` instead
|
|
76
|
-
*/
|
|
77
|
-
ProcedureRouterRecord,
|
|
78
74
|
/**
|
|
79
75
|
* @deprecated use `AnyTRPCSubscriptionProcedure` instead
|
|
80
76
|
*/
|
|
@@ -1,11 +1,42 @@
|
|
|
1
|
-
import type { AnyRootTypes } from './rootConfig';
|
|
2
|
-
|
|
1
|
+
import type { AnyRootTypes, RootConfig } from './rootConfig';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result of `initTRPC.create()`
|
|
5
|
+
*/
|
|
6
|
+
type InitLike = {
|
|
7
|
+
_config: RootConfig<AnyRootTypes>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Result of `initTRPC.create().router()`
|
|
12
|
+
*/
|
|
13
|
+
type RouterLike = {
|
|
14
|
+
_def: InitLike;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Result of `initTRPC.create()._config`
|
|
19
|
+
*/
|
|
20
|
+
type RootConfigLike = {
|
|
21
|
+
$types: AnyRootTypes;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Anything that can be inferred to the root config types
|
|
25
|
+
*/
|
|
26
|
+
export type TRPCInferrable =
|
|
27
|
+
| RouterLike
|
|
28
|
+
| InitLike
|
|
29
|
+
| RootConfigLike
|
|
30
|
+
| AnyRootTypes;
|
|
3
31
|
|
|
4
|
-
export type TRPCInferrable = AnyRouter | AnyRootTypes;
|
|
5
32
|
export type inferRootTypes<TInferrable extends TRPCInferrable> =
|
|
6
33
|
TInferrable extends AnyRootTypes
|
|
7
34
|
? TInferrable
|
|
8
|
-
: TInferrable extends
|
|
35
|
+
: TInferrable extends RootConfigLike
|
|
36
|
+
? TInferrable['$types']
|
|
37
|
+
: TInferrable extends InitLike
|
|
38
|
+
? TInferrable['_config']['$types']
|
|
39
|
+
: TInferrable extends RouterLike
|
|
9
40
|
? TInferrable['_def']['_config']['$types']
|
|
10
41
|
: never;
|
|
11
42
|
|