@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,31 +0,0 @@
|
|
|
1
|
-
type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = {
|
|
2
|
-
[K in keyof TType]: TValue extends TType[K] ? K : never;
|
|
3
|
-
}[keyof TType];
|
|
4
|
-
type Invert<TType extends Record<PropertyKey, PropertyKey>> = {
|
|
5
|
-
[TValue in TType[keyof TType]]: KeyFromValue<TValue, TType>;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare function invert<TRecord extends Record<PropertyKey, PropertyKey>>(obj: TRecord): Invert<TRecord>;
|
|
11
|
-
/**
|
|
12
|
-
* Ensures there are no duplicate keys when building a procedure.
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export declare function mergeWithoutOverrides<TType extends Record<string, unknown>>(obj1: TType, ...objs: Partial<TType>[]): TType;
|
|
16
|
-
/**
|
|
17
|
-
* Check that value is object
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Create an object without inheriting anything from `Object.prototype`
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export declare function omitPrototype<TObj extends Record<string, unknown>>(obj: TObj): TObj;
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
export declare function identity<TType>(x: TType): TType;
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/utils.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,MAAM,EAAE,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KACzE,CAAC,IAAI,MAAM,KAAK,GAAG,MAAM,SAAS,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACxD,CAAC,MAAM,KAAK,CAAC,CAAC;AAEf,KAAK,MAAM,CAAC,KAAK,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI;KAC3D,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;CAC5D,CAAC;AACF;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,EACrE,GAAG,EAAE,OAAO,GACX,MAAM,CAAC,OAAO,CAAC,CAOjB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,GACxB,KAAK,CAYP;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,GAAG,EAAE,IAAI,GACR,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAE/C"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AnyRootConfig } from './rootConfig';
|
|
2
|
-
import type { AnyRouter } from './router';
|
|
3
|
-
|
|
4
|
-
export type TRPCInferrable = AnyRouter | AnyRootConfig;
|
|
5
|
-
export type inferConfig<TInferrable extends TRPCInferrable> =
|
|
6
|
-
TInferrable extends AnyRouter ? TInferrable['_def']['_config'] : TInferrable;
|
|
7
|
-
|
|
8
|
-
export type inferErrorShape<TInferrable extends TRPCInferrable> =
|
|
9
|
-
inferConfig<TInferrable>['$types']['errorShape'];
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
interface ProxyCallbackOptions {
|
|
2
|
-
path: string[];
|
|
3
|
-
args: unknown[];
|
|
4
|
-
}
|
|
5
|
-
type ProxyCallback = (opts: ProxyCallbackOptions) => unknown;
|
|
6
|
-
|
|
7
|
-
const noop = () => {
|
|
8
|
-
// noop
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function createInnerProxy(callback: ProxyCallback, path: string[]) {
|
|
12
|
-
const proxy: unknown = new Proxy(noop, {
|
|
13
|
-
get(_obj, key) {
|
|
14
|
-
if (typeof key !== 'string' || key === 'then') {
|
|
15
|
-
// special case for if the proxy is accidentally treated
|
|
16
|
-
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
return createInnerProxy(callback, [...path, key]);
|
|
20
|
-
},
|
|
21
|
-
apply(_1, _2, args) {
|
|
22
|
-
const isApply = path[path.length - 1] === 'apply';
|
|
23
|
-
return callback({
|
|
24
|
-
args: isApply ? (args.length >= 2 ? args[1] : []) : args,
|
|
25
|
-
path: isApply ? path.slice(0, -1) : path,
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return proxy;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Creates a proxy that calls the callback with the path and arguments
|
|
35
|
-
*
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
export const createRecursiveProxy = (callback: ProxyCallback) =>
|
|
39
|
-
createInnerProxy(callback, []);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export const createFlatProxy = <TFaux>(
|
|
47
|
-
callback: (path: string & keyof TFaux) => any,
|
|
48
|
-
): TFaux => {
|
|
49
|
-
return new Proxy(noop, {
|
|
50
|
-
get(_obj, name) {
|
|
51
|
-
if (typeof name !== 'string' || name === 'then') {
|
|
52
|
-
// special case for if the proxy is accidentally treated
|
|
53
|
-
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return callback(name as any);
|
|
57
|
-
},
|
|
58
|
-
}) as TFaux;
|
|
59
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
|
|
2
|
-
import { isObject } from '../utils';
|
|
3
|
-
|
|
4
|
-
class UnknownCauseError extends Error {
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
}
|
|
7
|
-
export function getCauseFromUnknown(cause: unknown): Error | undefined {
|
|
8
|
-
if (cause instanceof Error) {
|
|
9
|
-
return cause;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const type = typeof cause;
|
|
13
|
-
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Primitive types just get wrapped in an error
|
|
18
|
-
if (type !== 'object') {
|
|
19
|
-
return new Error(String(cause));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// If it's an object, we'll create a synthetic error
|
|
23
|
-
if (isObject(cause)) {
|
|
24
|
-
const err = new UnknownCauseError();
|
|
25
|
-
for (const key in cause) {
|
|
26
|
-
err[key] = cause[key];
|
|
27
|
-
}
|
|
28
|
-
return err;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
|
|
35
|
-
if (cause instanceof TRPCError) {
|
|
36
|
-
return cause;
|
|
37
|
-
}
|
|
38
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
39
|
-
// https://github.com/trpc/trpc/pull/4848
|
|
40
|
-
return cause as TRPCError;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const trpcError = new TRPCError({
|
|
44
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
45
|
-
cause,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Inherit stack from error
|
|
49
|
-
if (cause instanceof Error && cause.stack) {
|
|
50
|
-
trpcError.stack = cause.stack;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return trpcError;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class TRPCError extends Error {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
-
// @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
|
|
59
|
-
public override readonly cause?: Error;
|
|
60
|
-
public readonly code;
|
|
61
|
-
|
|
62
|
-
constructor(opts: {
|
|
63
|
-
message?: string;
|
|
64
|
-
code: TRPC_ERROR_CODE_KEY;
|
|
65
|
-
cause?: unknown;
|
|
66
|
-
}) {
|
|
67
|
-
const cause = getCauseFromUnknown(opts.cause);
|
|
68
|
-
const message = opts.message ?? cause?.message ?? opts.code;
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
71
|
-
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
72
|
-
super(message, { cause });
|
|
73
|
-
|
|
74
|
-
this.code = opts.code;
|
|
75
|
-
this.name = 'TRPCError';
|
|
76
|
-
|
|
77
|
-
if (!this.cause) {
|
|
78
|
-
// < ES2022 / < Node 16.9.0 compatability
|
|
79
|
-
this.cause = cause;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { ProcedureType } from '../procedure';
|
|
2
|
-
import type {
|
|
3
|
-
TRPC_ERROR_CODE_KEY,
|
|
4
|
-
TRPC_ERROR_CODE_NUMBER,
|
|
5
|
-
TRPCErrorShape,
|
|
6
|
-
} from '../rpc';
|
|
7
|
-
import type { TRPCError } from './TRPCError';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export type ErrorFormatter<
|
|
13
|
-
TContext,
|
|
14
|
-
TShape extends TRPCErrorShape<number>,
|
|
15
|
-
> = (args: {
|
|
16
|
-
error: TRPCError;
|
|
17
|
-
type: ProcedureType | 'unknown';
|
|
18
|
-
path: string | undefined;
|
|
19
|
-
input: unknown;
|
|
20
|
-
ctx: TContext | undefined;
|
|
21
|
-
shape: DefaultErrorShape;
|
|
22
|
-
}) => TShape;
|
|
23
|
-
|
|
24
|
-
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<
|
|
25
|
-
any,
|
|
26
|
-
infer TShape
|
|
27
|
-
>
|
|
28
|
-
? TShape
|
|
29
|
-
: DefaultErrorShape;
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export type DefaultErrorData = {
|
|
34
|
-
code: TRPC_ERROR_CODE_KEY;
|
|
35
|
-
httpStatus: number;
|
|
36
|
-
path?: string;
|
|
37
|
-
stack?: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
export interface DefaultErrorShape
|
|
44
|
-
extends TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, DefaultErrorData> {
|
|
45
|
-
message: string;
|
|
46
|
-
code: TRPC_ERROR_CODE_NUMBER;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const defaultFormatter: ErrorFormatter<any, any> = ({ shape }) => {
|
|
50
|
-
return shape;
|
|
51
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { getHTTPStatusCodeFromError } from '../http/getHTTPStatusCode';
|
|
2
|
-
import type { ProcedureType } from '../procedure';
|
|
3
|
-
import type { AnyRootConfig } from '../rootConfig';
|
|
4
|
-
import { TRPC_ERROR_CODES_BY_KEY } from '../rpc';
|
|
5
|
-
import type { DefaultErrorShape } from './formatter';
|
|
6
|
-
import type { TRPCError } from './TRPCError';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function getErrorShape<TConfig extends AnyRootConfig>(opts: {
|
|
12
|
-
config: TConfig;
|
|
13
|
-
error: TRPCError;
|
|
14
|
-
type: ProcedureType | 'unknown';
|
|
15
|
-
path: string | undefined;
|
|
16
|
-
input: unknown;
|
|
17
|
-
ctx: TConfig['$types']['ctx'] | undefined;
|
|
18
|
-
}): TConfig['$types']['errorShape'] {
|
|
19
|
-
const { path, error, config } = opts;
|
|
20
|
-
const { code } = opts.error;
|
|
21
|
-
const shape: DefaultErrorShape = {
|
|
22
|
-
message: error.message,
|
|
23
|
-
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
24
|
-
data: {
|
|
25
|
-
code,
|
|
26
|
-
httpStatus: getHTTPStatusCodeFromError(error),
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
30
|
-
shape.data.stack = opts.error.stack;
|
|
31
|
-
}
|
|
32
|
-
if (typeof path === 'string') {
|
|
33
|
-
shape.data.path = path;
|
|
34
|
-
}
|
|
35
|
-
return config.errorFormatter({ ...opts, shape });
|
|
36
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Format a batch response as a line-delimited JSON stream
|
|
3
|
-
* that the `unstable_httpBatchStreamLink` can parse:
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const formatter = getBatchStreamFormatter();
|
|
8
|
-
* res.send(formatter(1, 'response #2'));
|
|
9
|
-
* res.send(formatter(0, 'response #1'));
|
|
10
|
-
* res.send(formatter.end());
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Expected format:
|
|
14
|
-
* ```json
|
|
15
|
-
* {"1":"response #2"
|
|
16
|
-
* ,"0":"response #1"
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function getBatchStreamFormatter() {
|
|
21
|
-
let first = true;
|
|
22
|
-
function format(index: number, string: string) {
|
|
23
|
-
const prefix = first ? '{' : ',';
|
|
24
|
-
first = false;
|
|
25
|
-
return `${prefix}"${index}":${string}\n`;
|
|
26
|
-
}
|
|
27
|
-
format.end = () => '}';
|
|
28
|
-
return format;
|
|
29
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
import { TRPCError } from '../error/TRPCError';
|
|
3
|
-
import type { AnyRouter } from '../router';
|
|
4
|
-
import type { CombinedDataTransformer } from '../transformer';
|
|
5
|
-
import type { MaybePromise } from '../types';
|
|
6
|
-
import type { HTTPRequest } from './types';
|
|
7
|
-
|
|
8
|
-
type GetInputs = (opts: {
|
|
9
|
-
req: HTTPRequest;
|
|
10
|
-
isBatchCall: boolean;
|
|
11
|
-
router: AnyRouter;
|
|
12
|
-
preprocessedBody: boolean;
|
|
13
|
-
}) => MaybePromise<Record<number, unknown>>;
|
|
14
|
-
|
|
15
|
-
export type BodyResult =
|
|
16
|
-
| {
|
|
17
|
-
ok: true;
|
|
18
|
-
data: unknown;
|
|
19
|
-
/**
|
|
20
|
-
* If the HTTP handler has already parsed the body
|
|
21
|
-
*/
|
|
22
|
-
preprocessed: boolean;
|
|
23
|
-
}
|
|
24
|
-
| { ok: false; error: TRPCError };
|
|
25
|
-
|
|
26
|
-
export type BaseContentTypeHandler<TOptions> = {
|
|
27
|
-
isMatch(opts: TOptions): boolean;
|
|
28
|
-
getBody: (opts: TOptions) => MaybePromise<BodyResult>;
|
|
29
|
-
getInputs: GetInputs;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function getRawProcedureInputOrThrow(opts: {
|
|
33
|
-
req: HTTPRequest;
|
|
34
|
-
preprocessedBody: boolean;
|
|
35
|
-
}) {
|
|
36
|
-
const { req } = opts;
|
|
37
|
-
try {
|
|
38
|
-
if (req.method === 'GET') {
|
|
39
|
-
if (!req.query.has('input')) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
const raw = req.query.get('input');
|
|
43
|
-
return JSON.parse(raw!);
|
|
44
|
-
}
|
|
45
|
-
if (!opts.preprocessedBody && typeof req.body === 'string') {
|
|
46
|
-
// A mutation with no inputs will have req.body === ''
|
|
47
|
-
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
48
|
-
}
|
|
49
|
-
return req.body;
|
|
50
|
-
} catch (cause) {
|
|
51
|
-
throw new TRPCError({
|
|
52
|
-
code: 'PARSE_ERROR',
|
|
53
|
-
cause,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const deserializeInputValue = (
|
|
59
|
-
rawValue: unknown,
|
|
60
|
-
transformer: CombinedDataTransformer,
|
|
61
|
-
) => {
|
|
62
|
-
return typeof rawValue !== 'undefined'
|
|
63
|
-
? transformer.input.deserialize(rawValue)
|
|
64
|
-
: rawValue;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const getJsonContentTypeInputs: GetInputs = (opts) => {
|
|
68
|
-
const rawInput = getRawProcedureInputOrThrow(opts);
|
|
69
|
-
const transformer = opts.router._def._config.transformer;
|
|
70
|
-
|
|
71
|
-
if (!opts.isBatchCall) {
|
|
72
|
-
return {
|
|
73
|
-
0: deserializeInputValue(rawInput, transformer),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* istanbul ignore if */
|
|
78
|
-
if (
|
|
79
|
-
rawInput == null ||
|
|
80
|
-
typeof rawInput !== 'object' ||
|
|
81
|
-
Array.isArray(rawInput)
|
|
82
|
-
) {
|
|
83
|
-
throw new TRPCError({
|
|
84
|
-
code: 'BAD_REQUEST',
|
|
85
|
-
message: '"input" needs to be an object when doing a batch call',
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const input: Record<number, unknown> = {};
|
|
89
|
-
for (const key in rawInput) {
|
|
90
|
-
const k = key as any as number;
|
|
91
|
-
const rawValue = rawInput[k];
|
|
92
|
-
|
|
93
|
-
const value = deserializeInputValue(rawValue, transformer);
|
|
94
|
-
|
|
95
|
-
input[k] = value;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return input;
|
|
99
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { TRPCError } from '../error/TRPCError';
|
|
2
|
-
import type { TRPC_ERROR_CODES_BY_KEY, TRPCResponse } from '../rpc';
|
|
3
|
-
import { TRPC_ERROR_CODES_BY_NUMBER } from '../rpc';
|
|
4
|
-
|
|
5
|
-
const JSONRPC2_TO_HTTP_CODE: Record<
|
|
6
|
-
keyof typeof TRPC_ERROR_CODES_BY_KEY,
|
|
7
|
-
number
|
|
8
|
-
> = {
|
|
9
|
-
PARSE_ERROR: 400,
|
|
10
|
-
BAD_REQUEST: 400,
|
|
11
|
-
UNAUTHORIZED: 401,
|
|
12
|
-
NOT_FOUND: 404,
|
|
13
|
-
FORBIDDEN: 403,
|
|
14
|
-
METHOD_NOT_SUPPORTED: 405,
|
|
15
|
-
TIMEOUT: 408,
|
|
16
|
-
CONFLICT: 409,
|
|
17
|
-
PRECONDITION_FAILED: 412,
|
|
18
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
19
|
-
UNPROCESSABLE_CONTENT: 422,
|
|
20
|
-
TOO_MANY_REQUESTS: 429,
|
|
21
|
-
CLIENT_CLOSED_REQUEST: 499,
|
|
22
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
23
|
-
NOT_IMPLEMENTED: 501,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function getStatusCodeFromKey(code: keyof typeof TRPC_ERROR_CODES_BY_KEY) {
|
|
27
|
-
return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]) {
|
|
31
|
-
const arr = Array.isArray(json) ? json : [json];
|
|
32
|
-
const httpStatuses = new Set(
|
|
33
|
-
arr.map((res) => {
|
|
34
|
-
if ('error' in res) {
|
|
35
|
-
const data = res.error.data;
|
|
36
|
-
if (typeof data['httpStatus'] === 'number') {
|
|
37
|
-
return data['httpStatus'];
|
|
38
|
-
}
|
|
39
|
-
const code = TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
40
|
-
return getStatusCodeFromKey(code);
|
|
41
|
-
}
|
|
42
|
-
return 200;
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (httpStatuses.size !== 1) {
|
|
47
|
-
return 207;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const httpStatus = httpStatuses.values().next().value;
|
|
51
|
-
|
|
52
|
-
return httpStatus;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function getHTTPStatusCodeFromError(error: TRPCError) {
|
|
56
|
-
return getStatusCodeFromKey(error.code);
|
|
57
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
getHTTPStatusCode,
|
|
3
|
-
getHTTPStatusCodeFromError,
|
|
4
|
-
} from './getHTTPStatusCode';
|
|
5
|
-
export { resolveHTTPResponse } from './resolveHTTPResponse';
|
|
6
|
-
export type {
|
|
7
|
-
BaseHandlerOptions,
|
|
8
|
-
HTTPBaseHandlerOptions,
|
|
9
|
-
HTTPHeaders,
|
|
10
|
-
HTTPRequest,
|
|
11
|
-
HTTPResponse,
|
|
12
|
-
OnErrorFunction,
|
|
13
|
-
ProcedureCall,
|
|
14
|
-
ResolveHTTPRequestOptionsContextFn,
|
|
15
|
-
ResponseChunk,
|
|
16
|
-
ResponseMeta,
|
|
17
|
-
ResponseMetaFn,
|
|
18
|
-
TRPCRequestInfo,
|
|
19
|
-
} from './types';
|
|
20
|
-
|
|
21
|
-
export { getBatchStreamFormatter } from './batchStreamFormatter';
|
|
22
|
-
export type { BaseContentTypeHandler, BodyResult } from './contentType';
|
|
23
|
-
export { getJsonContentTypeInputs } from './contentType';
|