@trpc/server 10.0.0-proxy-beta.0 → 10.0.0-proxy-beta.2
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/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +3 -3
- package/dist/adapters/aws-lambda/index.mjs +3 -3
- package/dist/adapters/aws-lambda/utils.d.ts +2 -2
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +3 -3
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/index.mjs +2 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/lambda/index.d.ts +1 -1
- package/dist/adapters/lambda/index.d.ts.map +1 -1
- package/dist/adapters/next.js +3 -3
- package/dist/adapters/next.mjs +3 -3
- package/dist/adapters/node-http/index.js +3 -3
- package/dist/adapters/node-http/index.mjs +3 -3
- package/dist/adapters/standalone.js +3 -3
- package/dist/adapters/standalone.mjs +3 -3
- package/dist/{codes-1c24d919.js → codes-731f0a7c.js} +2 -5
- package/dist/{codes-aaa7d554.mjs → codes-f164ac85.mjs} +2 -6
- package/dist/core/initTRPC.d.ts +6 -6
- package/dist/core/initTRPC.d.ts.map +1 -1
- package/dist/core/internals/config.d.ts +4 -4
- package/dist/core/internals/config.d.ts.map +1 -1
- package/dist/core/internals/getParseFn.d.ts +3 -3
- package/dist/core/internals/getParseFn.d.ts.map +1 -1
- package/dist/core/internals/mergeWithoutOverrides.d.ts +1 -1
- package/dist/core/internals/mergeWithoutOverrides.d.ts.map +1 -1
- package/dist/core/internals/omitPrototype.d.ts +1 -1
- package/dist/core/internals/omitPrototype.d.ts.map +1 -1
- package/dist/core/internals/procedureBuilder.d.ts +19 -19
- package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
- package/dist/core/internals/utils.d.ts +5 -5
- package/dist/core/internals/utils.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +8 -8
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/deprecated/internals/middlewares.d.ts +3 -3
- package/dist/deprecated/internals/middlewares.d.ts.map +1 -1
- package/dist/deprecated/internals/procedure.d.ts +8 -8
- package/dist/deprecated/internals/procedure.d.ts.map +1 -1
- package/dist/deprecated/interop.d.ts +2 -2
- package/dist/deprecated/interop.d.ts.map +1 -1
- package/dist/deprecated/router.d.ts +1 -1
- package/dist/deprecated/router.d.ts.map +1 -1
- package/dist/error/formatter.d.ts +1 -1
- package/dist/error/formatter.d.ts.map +1 -1
- package/dist/http/internals/getHTTPStatusCode.d.ts +1 -1
- package/dist/http/internals/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +4 -4
- package/dist/internals/invert.d.ts +6 -6
- package/dist/internals/invert.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-7295e689.js → nodeHTTPRequestHandler-e4b36284.js} +1 -1
- package/dist/{nodeHTTPRequestHandler-e4a030ab.mjs → nodeHTTPRequestHandler-f84d898b.mjs} +1 -1
- package/dist/observable/internals/identity.d.ts +1 -1
- package/dist/observable/internals/identity.d.ts.map +1 -1
- package/dist/observable/internals/pipe.d.ts +1 -1
- package/dist/observable/internals/pipe.d.ts.map +1 -1
- package/dist/observable/types.d.ts +6 -6
- package/dist/observable/types.d.ts.map +1 -1
- package/dist/{resolveHTTPResponse-9a70b9b2.js → resolveHTTPResponse-f80439bb.js} +4 -13
- package/dist/{resolveHTTPResponse-3955937e.mjs → resolveHTTPResponse-fa4e77dd.mjs} +3 -12
- package/dist/{router-fee6849a.js → router-244a949f.js} +3 -2
- package/dist/{router-4f222389.mjs → router-b5b89d55.mjs} +3 -2
- package/dist/rpc/codes.d.ts +1 -1
- package/dist/rpc/codes.d.ts.map +1 -1
- package/dist/rpc/index.js +1 -1
- package/dist/rpc/index.mjs +1 -1
- package/dist/types.d.ts +15 -15
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/adapters/aws-lambda/index.ts +2 -2
- package/src/adapters/aws-lambda/utils.ts +2 -2
- package/src/adapters/lambda/index.ts +2 -2
- package/src/core/initTRPC.ts +3 -3
- package/src/core/internals/config.ts +4 -4
- package/src/core/internals/getParseFn.ts +5 -5
- package/src/core/internals/mergeWithoutOverrides.ts +6 -6
- package/src/core/internals/omitPrototype.ts +4 -4
- package/src/core/internals/procedureBuilder.ts +32 -30
- package/src/core/internals/utils.ts +9 -9
- package/src/core/middleware.ts +6 -6
- package/src/core/types.ts +2 -2
- package/src/deprecated/internals/middlewares.ts +3 -1
- package/src/deprecated/internals/procedure.ts +18 -15
- package/src/deprecated/interop.ts +6 -2
- package/src/deprecated/router.ts +5 -2
- package/src/error/formatter.ts +4 -1
- package/src/http/internals/getHTTPStatusCode.ts +1 -1
- package/src/internals/invert.ts +8 -8
- package/src/observable/internals/identity.ts +1 -1
- package/src/observable/internals/pipe.ts +5 -5
- package/src/observable/types.ts +37 -26
- package/src/rpc/codes.ts +2 -2
- package/src/types.ts +23 -16
- package/dist/rpc/internals/invert.d.ts +0 -18
- package/dist/rpc/internals/invert.d.ts.map +0 -1
- package/src/rpc/internals/invert.ts +0 -27
package/dist/types.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
|
-
export declare type identity<
|
|
4
|
+
export declare type identity<TType> = TType;
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export declare type FlatOverwrite<
|
|
9
|
-
[TKey in keyof
|
|
8
|
+
export declare type FlatOverwrite<TType, TWith> = identity<{
|
|
9
|
+
[TKey in keyof TWith | keyof TType]: TKey extends keyof TWith ? TWith[TKey] : TKey extends keyof TType ? TType[TKey] : never;
|
|
10
10
|
}>;
|
|
11
11
|
/**
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
export declare type Maybe<
|
|
14
|
+
export declare type Maybe<TType> = TType | undefined | null;
|
|
15
15
|
/**
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
export declare type ThenArg<
|
|
18
|
+
export declare type ThenArg<TType> = TType extends PromiseLike<infer U> ? ThenArg<U> : TType;
|
|
19
19
|
/**
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
export declare type Simplify<
|
|
23
|
-
[KeyType in keyof
|
|
22
|
+
export declare type Simplify<TType> = {
|
|
23
|
+
[KeyType in keyof TType]: TType[KeyType];
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
|
-
export declare type Dict<
|
|
28
|
+
export declare type Dict<TType> = Record<string, TType | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
|
-
export declare type MaybePromise<
|
|
32
|
+
export declare type MaybePromise<TType> = TType | Promise<TType>;
|
|
33
33
|
/**
|
|
34
34
|
* @internal
|
|
35
35
|
*
|
|
36
36
|
* Creates a "lower-priority" type inference.
|
|
37
37
|
* https://github.com/microsoft/TypeScript/issues/14829#issuecomment-322267089
|
|
38
38
|
*/
|
|
39
|
-
export declare type InferLast<
|
|
40
|
-
[
|
|
39
|
+
export declare type InferLast<TType> = TType & {
|
|
40
|
+
[KeyType in keyof TType]: TType[KeyType];
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
45
|
export declare type inferAsyncReturnType<TFunction extends (...args: any) => any> = ThenArg<ReturnType<TFunction>>;
|
|
46
|
-
declare type FilterKeys<
|
|
47
|
-
[TKey in keyof
|
|
48
|
-
}[keyof
|
|
46
|
+
declare type FilterKeys<TObj extends object, TFilter> = {
|
|
47
|
+
[TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never;
|
|
48
|
+
}[keyof TObj];
|
|
49
49
|
/**
|
|
50
50
|
* @internal
|
|
51
51
|
*/
|
|
52
|
-
export declare type Filter<
|
|
52
|
+
export declare type Filter<TObj extends object, TFilter> = Pick<TObj, FilterKeys<TObj, TFilter>>;
|
|
53
53
|
export {};
|
|
54
54
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,oBAAY,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAC;AAEpC;;GAEG;AACH,oBAAY,aAAa,CAAC,KAAK,EAAE,KAAK,IAAI,QAAQ,CAAC;KAChD,IAAI,IAAI,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,IAAI,SAAS,MAAM,KAAK,GACzD,KAAK,CAAC,IAAI,CAAC,GACX,IAAI,SAAS,MAAM,KAAK,GACxB,KAAK,CAAC,IAAI,CAAC,GACX,KAAK;CACV,CAAC,CAAC;AAEH;;GAEG;AACH,oBAAY,KAAK,CAAC,KAAK,IAAI,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC;AAEpD;;GAEG;AACH,oBAAY,OAAO,CAAC,KAAK,IAAI,KAAK,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAC3D,OAAO,CAAC,CAAC,CAAC,GACV,KAAK,CAAC;AAEV;;GAEG;AACH,oBAAY,QAAQ,CAAC,KAAK,IAAI;KAAG,OAAO,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;CAAE,CAAC;AAE3E;;GAEG;AACH,oBAAY,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;AAE5D;;GAEG;AACH,oBAAY,YAAY,CAAC,KAAK,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAEzD;;;;;GAKG;AACH,oBAAY,SAAS,CAAC,KAAK,IAAI,KAAK,GAAG;KACpC,OAAO,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,oBAAY,oBAAoB,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,IACtE,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAEjC,aAAK,UAAU,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,IAAI;KAC7C,IAAI,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,IAAI,GAAG,KAAK;CAChE,CAAC,MAAM,IAAI,CAAC,CAAC;AAEd;;GAEG;AACH,oBAAY,MAAM,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,IAAI,IAAI,CACrD,IAAI,EACJ,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "10.0.0-proxy-beta.
|
|
3
|
+
"version": "10.0.0-proxy-beta.2",
|
|
4
4
|
"description": "tRPC Server",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"@cloudflare/workers-types": "^3.14.1",
|
|
111
111
|
"@fastify/websocket": "^5.0.0",
|
|
112
112
|
"@miniflare/core": "^2.4.0",
|
|
113
|
-
"@tanstack/react-query": "^4.0
|
|
113
|
+
"@tanstack/react-query": "^4.3.0",
|
|
114
114
|
"@types/aws-lambda": "^8.10.97",
|
|
115
115
|
"@types/express": "^4.17.12",
|
|
116
116
|
"@types/hash-sum": "^1.0.0",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"konn": "^0.7.0",
|
|
129
129
|
"miniflare": "^2.4.0",
|
|
130
130
|
"myzod": "^1.3.1",
|
|
131
|
-
"next": "^12.1
|
|
131
|
+
"next": "^12.3.1",
|
|
132
132
|
"node-fetch": "^2.6.1",
|
|
133
133
|
"superstruct": "^0.15.2",
|
|
134
134
|
"typescript": "4.7.4",
|
|
@@ -136,5 +136,5 @@
|
|
|
136
136
|
"yup": "^0.32.8",
|
|
137
137
|
"zod": "^3.0.0"
|
|
138
138
|
},
|
|
139
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "1345f6b3947b0ee11d621747648e163e124b8977"
|
|
140
140
|
}
|
|
@@ -131,9 +131,9 @@ type inferAPIGWEvent<
|
|
|
131
131
|
/** 1:1 mapping of v1 or v2 input events, deduces which is which.
|
|
132
132
|
* @internal
|
|
133
133
|
**/
|
|
134
|
-
type inferAPIGWReturn<
|
|
134
|
+
type inferAPIGWReturn<TType> = TType extends APIGatewayProxyEvent
|
|
135
135
|
? APIGatewayProxyResult
|
|
136
|
-
:
|
|
136
|
+
: TType extends APIGatewayProxyEventV2
|
|
137
137
|
? APIGatewayProxyStructuredResultV2
|
|
138
138
|
: never;
|
|
139
139
|
export function awsLambdaRequestHandler<
|
|
@@ -14,8 +14,8 @@ export type APIGatewayResult =
|
|
|
14
14
|
| APIGatewayProxyResult
|
|
15
15
|
| APIGatewayProxyStructuredResultV2;
|
|
16
16
|
|
|
17
|
-
export type CreateAWSLambdaContextOptions<
|
|
18
|
-
event:
|
|
17
|
+
export type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
|
|
18
|
+
event: TEvent;
|
|
19
19
|
context: APIGWContext;
|
|
20
20
|
};
|
|
21
21
|
export type AWSLambdaCreateContextFn<
|
|
@@ -9,8 +9,8 @@ export * from '../aws-lambda';
|
|
|
9
9
|
/**
|
|
10
10
|
* @deprecated use `aws-lambda` instead
|
|
11
11
|
*/
|
|
12
|
-
export type CreateLambdaContextOptions<
|
|
13
|
-
CreateAWSLambdaContextOptions<
|
|
12
|
+
export type CreateLambdaContextOptions<TEvent extends APIGatewayEvent> =
|
|
13
|
+
CreateAWSLambdaContextOptions<TEvent>;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @deprecated use `aws-lambda` instead
|
package/src/core/initTRPC.ts
CHANGED
|
@@ -26,10 +26,10 @@ import { createRouterFactory } from './router';
|
|
|
26
26
|
|
|
27
27
|
type PartialInitGenerics = Partial<InitGenerics>;
|
|
28
28
|
|
|
29
|
-
type CreateInitGenericsFromPartial<
|
|
29
|
+
type CreateInitGenericsFromPartial<TType extends PartialInitGenerics> =
|
|
30
30
|
CreateInitGenerics<{
|
|
31
|
-
ctx:
|
|
32
|
-
meta:
|
|
31
|
+
ctx: TType['ctx'] extends InitGenerics['ctx'] ? TType['ctx'] : {};
|
|
32
|
+
meta: TType['meta'] extends InitGenerics['meta'] ? TType['meta'] : {};
|
|
33
33
|
}>;
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -16,15 +16,15 @@ export interface InitGenerics {
|
|
|
16
16
|
* The initial params that are used and actually represents real values underneath
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
export interface InitOptions<
|
|
19
|
+
export interface InitOptions<TType extends InitGenerics> {
|
|
20
20
|
transformer: DataTransformerOptions;
|
|
21
|
-
errorFormatter: ErrorFormatter<
|
|
21
|
+
errorFormatter: ErrorFormatter<TType['ctx'], any>;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @internal
|
|
26
26
|
*/
|
|
27
|
-
export type CreateInitGenerics<
|
|
27
|
+
export type CreateInitGenerics<TType extends InitGenerics> = TType;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* The config that is resolved after `initTRPC.create()` has been called
|
|
@@ -40,4 +40,4 @@ export interface RootConfig extends InitGenerics {
|
|
|
40
40
|
/**
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
|
-
export type CreateRootConfig<
|
|
43
|
+
export type CreateRootConfig<TConfig extends RootConfig> = TConfig;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Parser } from '../parser';
|
|
2
2
|
|
|
3
|
-
export type ParseFn<
|
|
3
|
+
export type ParseFn<TType> = (value: unknown) => TType | Promise<TType>;
|
|
4
4
|
|
|
5
|
-
export function getParseFn<
|
|
5
|
+
export function getParseFn<TType>(procedureParser: Parser): ParseFn<TType> {
|
|
6
6
|
const parser = procedureParser as any;
|
|
7
7
|
|
|
8
8
|
if (typeof parser === 'function') {
|
|
@@ -37,11 +37,11 @@ export function getParseFn<T>(procedureParser: Parser): ParseFn<T> {
|
|
|
37
37
|
* @deprecated only for backwards compat
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
|
40
|
-
export function getParseFnOrPassThrough<
|
|
40
|
+
export function getParseFnOrPassThrough<TType>(
|
|
41
41
|
procedureParser: Parser | undefined,
|
|
42
|
-
): ParseFn<
|
|
42
|
+
): ParseFn<TType> {
|
|
43
43
|
if (!procedureParser) {
|
|
44
|
-
return (v) => v as
|
|
44
|
+
return (v) => v as TType;
|
|
45
45
|
}
|
|
46
46
|
return getParseFn(procedureParser);
|
|
47
47
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ensures there are no duplicate keys when building a procedure.
|
|
3
3
|
*/
|
|
4
|
-
export function mergeWithoutOverrides<
|
|
5
|
-
obj1:
|
|
6
|
-
...objs: Partial<
|
|
7
|
-
):
|
|
8
|
-
const newObj:
|
|
4
|
+
export function mergeWithoutOverrides<TType extends Record<string, unknown>>(
|
|
5
|
+
obj1: TType,
|
|
6
|
+
...objs: Partial<TType>[]
|
|
7
|
+
): TType {
|
|
8
|
+
const newObj: TType = Object.assign(Object.create(null), obj1);
|
|
9
9
|
|
|
10
10
|
for (const overrides of objs) {
|
|
11
11
|
for (const key in overrides) {
|
|
12
12
|
if (key in newObj && newObj[key] !== overrides[key]) {
|
|
13
13
|
throw new Error(`Duplicate key ${key}`);
|
|
14
14
|
}
|
|
15
|
-
newObj[key as keyof
|
|
15
|
+
newObj[key as keyof TType] = overrides[key] as TType[keyof TType];
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
return newObj;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Create an object without inheriting anything from `Object.prototype`
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
|
-
export function omitPrototype<
|
|
6
|
-
|
|
7
|
-
):
|
|
8
|
-
return Object.assign(Object.create(null),
|
|
5
|
+
export function omitPrototype<TObj extends Record<string, unknown>>(
|
|
6
|
+
obj: TObj,
|
|
7
|
+
): TObj {
|
|
8
|
+
return Object.assign(Object.create(null), obj);
|
|
9
9
|
}
|
|
@@ -44,20 +44,22 @@ type CreateProcedureReturnInput<
|
|
|
44
44
|
_output_out: FallbackValue<TNext['_output_out'], TPrev['_output_out']>;
|
|
45
45
|
}>;
|
|
46
46
|
|
|
47
|
-
type OverwriteIfDefined<
|
|
47
|
+
type OverwriteIfDefined<TType, TWith> = UnsetMarker extends TType
|
|
48
|
+
? TWith
|
|
49
|
+
: FlatOverwrite<TType, TWith>;
|
|
48
50
|
|
|
49
|
-
type ErrorMessage<
|
|
51
|
+
type ErrorMessage<TMessage extends string> = TMessage;
|
|
50
52
|
|
|
51
53
|
export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
52
54
|
/**
|
|
53
55
|
* Add an input parser to the procedure.
|
|
54
56
|
*/
|
|
55
|
-
input
|
|
57
|
+
input<TParser extends Parser>(
|
|
56
58
|
schema: TParams['_input_out'] extends UnsetMarker
|
|
57
|
-
?
|
|
58
|
-
: inferParser
|
|
59
|
+
? TParser
|
|
60
|
+
: inferParser<TParser>['out'] extends Record<string, unknown>
|
|
59
61
|
? TParams['_input_out'] extends Record<string, unknown>
|
|
60
|
-
?
|
|
62
|
+
? TParser
|
|
61
63
|
: ErrorMessage<'All input parsers did not resolve to an object'>
|
|
62
64
|
: ErrorMessage<'All input parsers did not resolve to an object'>,
|
|
63
65
|
): ProcedureBuilder<{
|
|
@@ -67,11 +69,11 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
|
67
69
|
_ctx_out: TParams['_ctx_out'];
|
|
68
70
|
_input_in: OverwriteIfDefined<
|
|
69
71
|
TParams['_input_in'],
|
|
70
|
-
inferParser
|
|
72
|
+
inferParser<TParser>['in']
|
|
71
73
|
>;
|
|
72
74
|
_input_out: OverwriteIfDefined<
|
|
73
75
|
TParams['_input_out'],
|
|
74
|
-
inferParser
|
|
76
|
+
inferParser<TParser>['out']
|
|
75
77
|
>;
|
|
76
78
|
_output_in: TParams['_output_in'];
|
|
77
79
|
_output_out: TParams['_output_out'];
|
|
@@ -79,8 +81,8 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
|
79
81
|
/**
|
|
80
82
|
* Add an output parser to the procedure.
|
|
81
83
|
*/
|
|
82
|
-
output
|
|
83
|
-
schema:
|
|
84
|
+
output<TParser extends Parser>(
|
|
85
|
+
schema: TParser,
|
|
84
86
|
): ProcedureBuilder<{
|
|
85
87
|
_config: TParams['_config'];
|
|
86
88
|
_meta: TParams['_meta'];
|
|
@@ -88,8 +90,8 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
|
88
90
|
_ctx_out: TParams['_ctx_out'];
|
|
89
91
|
_input_in: TParams['_input_in'];
|
|
90
92
|
_input_out: TParams['_input_out'];
|
|
91
|
-
_output_in: inferParser
|
|
92
|
-
_output_out: inferParser
|
|
93
|
+
_output_in: inferParser<TParser>['in'];
|
|
94
|
+
_output_out: inferParser<TParser>['out'];
|
|
93
95
|
}>;
|
|
94
96
|
/**
|
|
95
97
|
* Add a meta data to the procedure.
|
|
@@ -98,32 +100,32 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
|
98
100
|
/**
|
|
99
101
|
* Add a middleware to the procedure.
|
|
100
102
|
*/
|
|
101
|
-
use
|
|
102
|
-
fn: MiddlewareFunction<TParams,
|
|
103
|
-
): CreateProcedureReturnInput<TParams,
|
|
103
|
+
use<TNewParams extends ProcedureParams>(
|
|
104
|
+
fn: MiddlewareFunction<TParams, TNewParams>,
|
|
105
|
+
): CreateProcedureReturnInput<TParams, TNewParams>;
|
|
104
106
|
/**
|
|
105
107
|
* Extend the procedure with another procedure.
|
|
106
108
|
* @warning The TypeScript inference fails when chaining concatenated procedures.
|
|
107
109
|
*/
|
|
108
|
-
unstable_concat
|
|
109
|
-
proc:
|
|
110
|
-
):
|
|
110
|
+
unstable_concat<TProcedureReturnType extends AnyProcedureBuilder>(
|
|
111
|
+
proc: TProcedureReturnType,
|
|
112
|
+
): TProcedureReturnType extends ProcedureBuilder<infer $TParams>
|
|
111
113
|
? CreateProcedureReturnInput<TParams, $TParams>
|
|
112
114
|
: never;
|
|
113
115
|
/**
|
|
114
116
|
* Query procedure
|
|
115
117
|
*/
|
|
116
|
-
query
|
|
118
|
+
query<TOutput>(
|
|
117
119
|
resolver: (
|
|
118
120
|
opts: ResolveOptions<TParams>,
|
|
119
|
-
) => MaybePromise<FallbackValue<TParams['_output_in'],
|
|
121
|
+
) => MaybePromise<FallbackValue<TParams['_output_in'], TOutput>>,
|
|
120
122
|
): UnsetMarker extends TParams['_output_out']
|
|
121
123
|
? QueryProcedure<
|
|
122
124
|
OverwriteKnown<
|
|
123
125
|
TParams,
|
|
124
126
|
{
|
|
125
|
-
_output_in:
|
|
126
|
-
_output_out:
|
|
127
|
+
_output_in: TOutput;
|
|
128
|
+
_output_out: TOutput;
|
|
127
129
|
}
|
|
128
130
|
>
|
|
129
131
|
>
|
|
@@ -132,17 +134,17 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
|
132
134
|
/**
|
|
133
135
|
* Mutation procedure
|
|
134
136
|
*/
|
|
135
|
-
mutation
|
|
137
|
+
mutation<TOutput>(
|
|
136
138
|
resolver: (
|
|
137
139
|
opts: ResolveOptions<TParams>,
|
|
138
|
-
) => MaybePromise<FallbackValue<TParams['_output_in'],
|
|
140
|
+
) => MaybePromise<FallbackValue<TParams['_output_in'], TOutput>>,
|
|
139
141
|
): UnsetMarker extends TParams['_output_out']
|
|
140
142
|
? MutationProcedure<
|
|
141
143
|
OverwriteKnown<
|
|
142
144
|
TParams,
|
|
143
145
|
{
|
|
144
|
-
_output_in:
|
|
145
|
-
_output_out:
|
|
146
|
+
_output_in: TOutput;
|
|
147
|
+
_output_out: TOutput;
|
|
146
148
|
}
|
|
147
149
|
>
|
|
148
150
|
>
|
|
@@ -151,17 +153,17 @@ export interface ProcedureBuilder<TParams extends ProcedureParams> {
|
|
|
151
153
|
/**
|
|
152
154
|
* Mutation procedure
|
|
153
155
|
*/
|
|
154
|
-
subscription
|
|
156
|
+
subscription<TOutput>(
|
|
155
157
|
resolver: (
|
|
156
158
|
opts: ResolveOptions<TParams>,
|
|
157
|
-
) => MaybePromise<FallbackValue<TParams['_output_in'],
|
|
159
|
+
) => MaybePromise<FallbackValue<TParams['_output_in'], TOutput>>,
|
|
158
160
|
): UnsetMarker extends TParams['_output_out']
|
|
159
161
|
? SubscriptionProcedure<
|
|
160
162
|
OverwriteKnown<
|
|
161
163
|
TParams,
|
|
162
164
|
{
|
|
163
|
-
_output_in:
|
|
164
|
-
_output_out:
|
|
165
|
+
_output_in: TOutput;
|
|
166
|
+
_output_out: TOutput;
|
|
165
167
|
}
|
|
166
168
|
>
|
|
167
169
|
>
|
|
@@ -3,12 +3,12 @@ import { ProcedureParams } from '../procedure';
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
|
-
export type Overwrite<
|
|
6
|
+
export type Overwrite<TType, TWith> = Omit<TType, keyof TWith> & TWith;
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export type OverwriteKnown<
|
|
11
|
-
[K in keyof
|
|
10
|
+
export type OverwriteKnown<TType, TWith> = {
|
|
11
|
+
[K in keyof TType]: K extends keyof TWith ? TWith[K] : TType[K];
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* @internal
|
|
@@ -59,12 +59,12 @@ export type ValidateShape<TActualShape, TExpectedShape> =
|
|
|
59
59
|
/**
|
|
60
60
|
* @internal
|
|
61
61
|
*/
|
|
62
|
-
export type PickFirstDefined<
|
|
63
|
-
? undefined extends
|
|
62
|
+
export type PickFirstDefined<TType, TPick> = undefined extends TType
|
|
63
|
+
? undefined extends TPick
|
|
64
64
|
? never
|
|
65
|
-
:
|
|
66
|
-
:
|
|
65
|
+
: TPick
|
|
66
|
+
: TType;
|
|
67
67
|
|
|
68
|
-
export type EnsureRecord<
|
|
69
|
-
?
|
|
68
|
+
export type EnsureRecord<TRecord> = TRecord extends Record<string, any>
|
|
69
|
+
? TRecord
|
|
70
70
|
: Record<string, never>;
|
package/src/core/middleware.ts
CHANGED
|
@@ -61,11 +61,11 @@ export type MiddlewareFunction<
|
|
|
61
61
|
meta: TParams['_meta'];
|
|
62
62
|
next: {
|
|
63
63
|
(): Promise<MiddlewareResult<TParams>>;
|
|
64
|
-
|
|
64
|
+
<TContext>(opts: { ctx: TContext }): Promise<
|
|
65
65
|
MiddlewareResult<{
|
|
66
66
|
_config: any;
|
|
67
67
|
_ctx_in: TParams['_ctx_in'];
|
|
68
|
-
_ctx_out:
|
|
68
|
+
_ctx_out: TContext;
|
|
69
69
|
_input_in: TParams['_input_in'];
|
|
70
70
|
_input_out: TParams['_input_out'];
|
|
71
71
|
_output_in: TParams['_output_in'];
|
|
@@ -83,7 +83,7 @@ export type MiddlewareFunction<
|
|
|
83
83
|
*/
|
|
84
84
|
// FIXME this should use RootConfig
|
|
85
85
|
export function createMiddlewareFactory<TConfig extends RootConfig>() {
|
|
86
|
-
return function createMiddleware
|
|
86
|
+
return function createMiddleware<TNewParams extends ProcedureParams>(
|
|
87
87
|
fn: MiddlewareFunction<
|
|
88
88
|
{
|
|
89
89
|
_config: TConfig;
|
|
@@ -95,7 +95,7 @@ export function createMiddlewareFactory<TConfig extends RootConfig>() {
|
|
|
95
95
|
_output_out: unknown;
|
|
96
96
|
_meta: TConfig['meta'];
|
|
97
97
|
},
|
|
98
|
-
|
|
98
|
+
TNewParams
|
|
99
99
|
>,
|
|
100
100
|
) {
|
|
101
101
|
return fn;
|
|
@@ -110,7 +110,7 @@ function isPlainObject(obj: unknown) {
|
|
|
110
110
|
* @internal
|
|
111
111
|
* Please note, `trpc-openapi` uses this function.
|
|
112
112
|
*/
|
|
113
|
-
export function createInputMiddleware<
|
|
113
|
+
export function createInputMiddleware<TInput>(parse: ParseFn<TInput>) {
|
|
114
114
|
const inputMiddleware: ProcedureBuilderMiddleware = async ({
|
|
115
115
|
next,
|
|
116
116
|
rawInput,
|
|
@@ -145,7 +145,7 @@ export function createInputMiddleware<T>(parse: ParseFn<T>) {
|
|
|
145
145
|
/**
|
|
146
146
|
* @internal
|
|
147
147
|
*/
|
|
148
|
-
export function createOutputMiddleware<
|
|
148
|
+
export function createOutputMiddleware<TOutput>(parse: ParseFn<TOutput>) {
|
|
149
149
|
const outputMiddleware: ProcedureBuilderMiddleware = async ({ next }) => {
|
|
150
150
|
const result = await next();
|
|
151
151
|
if (!result.ok) {
|
package/src/core/types.ts
CHANGED
|
@@ -43,5 +43,5 @@ export type inferSubscriptionOutput<
|
|
|
43
43
|
inferProcedureOutput<TRouter['_def']['subscriptions'][TPath]>
|
|
44
44
|
>;
|
|
45
45
|
|
|
46
|
-
export type inferProcedureClientError<
|
|
47
|
-
inferProcedureParams<
|
|
46
|
+
export type inferProcedureClientError<TProcedure extends AnyProcedure> =
|
|
47
|
+
inferProcedureParams<TProcedure>['_config']['errorShape'];
|
|
@@ -54,6 +54,8 @@ export type MiddlewareFunction<TInputContext, TContext, TMeta> = (opts: {
|
|
|
54
54
|
meta?: TMeta;
|
|
55
55
|
next: {
|
|
56
56
|
(): Promise<MiddlewareResult<TInputContext>>;
|
|
57
|
-
<
|
|
57
|
+
<TNewContext>(opts: { ctx: TNewContext }): Promise<
|
|
58
|
+
MiddlewareResult<TNewContext>
|
|
59
|
+
>;
|
|
58
60
|
};
|
|
59
61
|
}) => Promise<MiddlewareResult<TContext>>;
|
|
@@ -20,30 +20,30 @@ export type ProcedureParserZodEsque<TInput, TOutput> = {
|
|
|
20
20
|
_output: TOutput;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export type ProcedureParserMyZodEsque<
|
|
24
|
-
parse: (input: any) =>
|
|
23
|
+
export type ProcedureParserMyZodEsque<TType> = {
|
|
24
|
+
parse: (input: any) => TType;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export type ProcedureParserSuperstructEsque<
|
|
28
|
-
create: (input: unknown) =>
|
|
27
|
+
export type ProcedureParserSuperstructEsque<TType> = {
|
|
28
|
+
create: (input: unknown) => TType;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export type ProcedureParserCustomValidatorEsque<
|
|
31
|
+
export type ProcedureParserCustomValidatorEsque<TType> = (
|
|
32
32
|
input: unknown,
|
|
33
|
-
) =>
|
|
33
|
+
) => TType | Promise<TType>;
|
|
34
34
|
|
|
35
|
-
export type ProcedureParserYupEsque<
|
|
36
|
-
validateSync: (input: unknown) =>
|
|
35
|
+
export type ProcedureParserYupEsque<TType> = {
|
|
36
|
+
validateSync: (input: unknown) => TType;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export type ProcedureParserWithInputOutput<TInput, TOutput> =
|
|
40
40
|
ProcedureParserZodEsque<TInput, TOutput>;
|
|
41
41
|
|
|
42
|
-
export type ProcedureParser<
|
|
43
|
-
| ProcedureParserYupEsque<
|
|
44
|
-
| ProcedureParserSuperstructEsque<
|
|
45
|
-
| ProcedureParserCustomValidatorEsque<
|
|
46
|
-
| ProcedureParserMyZodEsque<
|
|
42
|
+
export type ProcedureParser<TType> =
|
|
43
|
+
| ProcedureParserYupEsque<TType>
|
|
44
|
+
| ProcedureParserSuperstructEsque<TType>
|
|
45
|
+
| ProcedureParserCustomValidatorEsque<TType>
|
|
46
|
+
| ProcedureParserMyZodEsque<TType>;
|
|
47
47
|
|
|
48
48
|
export type ProcedureResolver<TContext, TInput, TOutput> = (opts: {
|
|
49
49
|
ctx: TContext;
|
|
@@ -70,9 +70,11 @@ export interface ProcedureCallOptions<TContext> {
|
|
|
70
70
|
type: ProcedureType;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
type ParseFn<
|
|
73
|
+
type ParseFn<TType> = (value: unknown) => TType | Promise<TType>;
|
|
74
74
|
|
|
75
|
-
function getParseFn<
|
|
75
|
+
function getParseFn<TType>(
|
|
76
|
+
procedureParser: ProcedureParser<TType>,
|
|
77
|
+
): ParseFn<TType> {
|
|
76
78
|
const parser = procedureParser as any;
|
|
77
79
|
|
|
78
80
|
if (typeof parser === 'function') {
|
|
@@ -210,6 +212,7 @@ export class Procedure<
|
|
|
210
212
|
},
|
|
211
213
|
): Promise<MiddlewareResult<any>> => {
|
|
212
214
|
try {
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
213
216
|
const result = await middlewaresWithResolver[callOpts.index]!({
|
|
214
217
|
ctx: callOpts.ctx,
|
|
215
218
|
type: opts.type,
|
|
@@ -67,10 +67,14 @@ type MigrateProcedure<
|
|
|
67
67
|
|
|
68
68
|
export type MigrateProcedureRecord<
|
|
69
69
|
TConfig extends RootConfig,
|
|
70
|
-
|
|
70
|
+
TProcedureRecord extends ProcedureRecord<any>,
|
|
71
71
|
TType extends ProcedureType,
|
|
72
72
|
> = {
|
|
73
|
-
[K in keyof
|
|
73
|
+
[K in keyof TProcedureRecord]: MigrateProcedure<
|
|
74
|
+
TConfig,
|
|
75
|
+
TProcedureRecord[K],
|
|
76
|
+
TType
|
|
77
|
+
>;
|
|
74
78
|
};
|
|
75
79
|
|
|
76
80
|
export type MigrateRouter<
|
package/src/deprecated/router.ts
CHANGED
|
@@ -36,7 +36,10 @@ export type { Procedure } from './internals/procedure';
|
|
|
36
36
|
/**
|
|
37
37
|
* @internal
|
|
38
38
|
*/
|
|
39
|
-
type Prefix<
|
|
39
|
+
type Prefix<
|
|
40
|
+
TPrefix extends string,
|
|
41
|
+
TSuffix extends string,
|
|
42
|
+
> = `${TPrefix}${TSuffix}`;
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
45
|
* @internal
|
|
@@ -239,7 +242,7 @@ function safeObject(): {};
|
|
|
239
242
|
/**
|
|
240
243
|
* Create an object without inheriting anything from `Object.prototype`
|
|
241
244
|
*/
|
|
242
|
-
function safeObject<
|
|
245
|
+
function safeObject<TObj>(obj: TObj): TObj;
|
|
243
246
|
/**
|
|
244
247
|
* Merge two objects without inheritance from `Object.prototype`
|
|
245
248
|
*/
|
package/src/error/formatter.ts
CHANGED
|
@@ -20,7 +20,10 @@ export type ErrorFormatter<TContext, TShape extends TRPCErrorShape<number>> = ({
|
|
|
20
20
|
shape: DefaultErrorShape;
|
|
21
21
|
}) => TShape;
|
|
22
22
|
|
|
23
|
-
export type ErrorFormatterShape<
|
|
23
|
+
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<
|
|
24
|
+
any,
|
|
25
|
+
infer TShape
|
|
26
|
+
>
|
|
24
27
|
? TShape
|
|
25
28
|
: DefaultErrorShape;
|
|
26
29
|
/**
|
|
@@ -3,7 +3,7 @@ import { invert } from '../../internals/invert';
|
|
|
3
3
|
import { TRPCResponse, TRPC_ERROR_CODES_BY_KEY } from '../../rpc';
|
|
4
4
|
|
|
5
5
|
export const TRPC_ERROR_CODES_BY_NUMBER = invert(TRPC_ERROR_CODES_BY_KEY);
|
|
6
|
-
type ValueOf<
|
|
6
|
+
type ValueOf<TType> = TType[keyof TType];
|
|
7
7
|
|
|
8
8
|
export type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
|
|
9
9
|
const JSONRPC2_TO_HTTP_CODE: Record<
|