@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.239 → 11.0.0-alpha-tmp-export-from-main.219
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/http.d.ts +2 -0
- package/dist/@trpc-server/http.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +2 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +4 -6
- package/dist/adapters/aws-lambda/index.mjs +2 -4
- package/dist/adapters/aws-lambda/utils.d.ts +3 -2
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +4 -5
- package/dist/adapters/aws-lambda/utils.mjs +2 -3
- package/dist/adapters/express.d.ts +2 -1
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +3 -6
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -4
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +2 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -0
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +2 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +4 -6
- package/dist/adapters/fetch/fetchRequestHandler.mjs +2 -4
- package/dist/adapters/fetch/types.d.ts +3 -2
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +3 -1
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +4 -6
- package/dist/adapters/next.mjs +2 -4
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +2 -4
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +1 -3
- package/dist/adapters/node-http/content-type/json/index.js +2 -4
- package/dist/adapters/node-http/content-type/json/index.mjs +1 -3
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +2 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +4 -6
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +2 -4
- package/dist/adapters/node-http/types.d.ts +4 -3
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +2 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +0 -1
- package/dist/adapters/standalone.mjs +0 -1
- package/dist/adapters/ws.d.ts +2 -3
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +26 -33
- package/dist/adapters/ws.mjs +1 -8
- package/dist/http.d.ts +6 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +21 -11
- package/dist/http.mjs +1 -6
- package/dist/index.d.ts +68 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -18
- package/dist/index.mjs +1 -8
- package/dist/observable.d.ts +3 -0
- package/dist/observable.d.ts.map +1 -0
- package/dist/observable.js +30 -0
- package/dist/observable.mjs +1 -0
- package/dist/rpc.d.ts +2 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +13 -6
- package/dist/rpc.mjs +1 -3
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +9 -6
- package/dist/shared.mjs +1 -4
- package/dist/unstableDontImportMe.d.ts +10 -0
- package/dist/unstableDontImportMe.d.ts.map +1 -0
- package/dist/unstableDontImportMe.js +142 -0
- package/dist/unstableDontImportMe.mjs +1 -0
- package/package.json +135 -52
- package/src/@trpc-server/http.ts +2 -0
- package/src/adapters/aws-lambda/index.ts +5 -4
- package/src/adapters/aws-lambda/utils.ts +4 -3
- package/src/adapters/express.ts +3 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +4 -6
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +2 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +4 -6
- package/src/adapters/fetch/types.ts +3 -2
- package/src/adapters/next.ts +4 -2
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +4 -6
- package/src/adapters/node-http/types.ts +5 -4
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +13 -14
- package/src/http.ts +26 -1
- package/src/index.ts +105 -1
- package/src/observable.ts +16 -0
- package/src/rpc.ts +26 -1
- package/src/shared.ts +1 -1
- package/src/unstableDontImportMe.ts +146 -0
- package/unstableDontImportMe/index.d.ts +1 -0
- package/unstableDontImportMe/index.js +1 -0
- package/dist/@trpc/server/http.d.ts +0 -7
- package/dist/@trpc/server/http.d.ts.map +0 -1
- package/dist/@trpc/server/index.d.ts +0 -69
- package/dist/@trpc/server/index.d.ts.map +0 -1
- package/dist/@trpc/server/rpc.d.ts +0 -3
- package/dist/@trpc/server/rpc.d.ts.map +0 -1
- package/dist/bundle-analysis.json +0 -757
- package/dist/observable/index.d.ts +0 -5
- package/dist/observable/index.d.ts.map +0 -1
- package/dist/observable/index.js +0 -13
- package/dist/observable/index.mjs +0 -2
- package/dist/observable/observable.d.ts +0 -13
- package/dist/observable/observable.d.ts.map +0 -1
- package/dist/observable/observable.js +0 -126
- package/dist/observable/observable.mjs +0 -122
- package/dist/observable/operators.d.ts +0 -8
- package/dist/observable/operators.d.ts.map +0 -1
- package/dist/observable/operators.js +0 -103
- package/dist/observable/operators.mjs +0 -99
- package/dist/observable/types.d.ts +0 -26
- package/dist/observable/types.d.ts.map +0 -1
- 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/createProxy.js +0 -52
- package/dist/unstable-core-do-not-import/createProxy.mjs +0 -49
- 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/TRPCError.js +0 -67
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +0 -63
- 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/formatter.js +0 -7
- package/dist/unstable-core-do-not-import/error/formatter.mjs +0 -5
- 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/error/getErrorShape.js +0 -31
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +0 -29
- 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/batchStreamFormatter.js +0 -32
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
- 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/contentType.js +0 -54
- package/dist/unstable-core-do-not-import/http/contentType.mjs +0 -52
- 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/getHTTPStatusCode.js +0 -51
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +0 -48
- 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/resolveHTTPResponse.js +0 -295
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +0 -293
- 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 -37
- package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.js +0 -48
- package/dist/unstable-core-do-not-import/index.mjs +0 -16
- 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/initTRPC.js +0 -95
- package/dist/unstable-core-do-not-import/initTRPC.mjs +0 -93
- 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/middleware.js +0 -95
- package/dist/unstable-core-do-not-import/middleware.mjs +0 -89
- 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/parser.js +0 -37
- package/dist/unstable-core-do-not-import/parser.mjs +0 -35
- 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/procedure.js +0 -9
- package/dist/unstable-core-do-not-import/procedure.mjs +0 -7
- 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/procedureBuilder.js +0 -176
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +0 -173
- 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/rootConfig.js +0 -8
- package/dist/unstable-core-do-not-import/rootConfig.mjs +0 -6
- 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/router.js +0 -156
- package/dist/unstable-core-do-not-import/router.mjs +0 -151
- 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/codes.js +0 -38
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +0 -35
- 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/rpc/parseTRPCMessage.js +0 -59
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +0 -57
- 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/transformer.js +0 -107
- package/dist/unstable-core-do-not-import/transformer.mjs +0 -102
- 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 -27
- package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/utils.js +0 -44
- package/dist/unstable-core-do-not-import/utils.mjs +0 -39
- package/src/@trpc/server/http.ts +0 -26
- package/src/@trpc/server/index.ts +0 -105
- package/src/@trpc/server/rpc.ts +0 -26
- package/src/observable/index.ts +0 -10
- package/src/observable/observable.ts +0 -158
- package/src/observable/operators.ts +0 -119
- package/src/observable/types.ts +0 -76
- 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 -110
- 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/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 -59
- package/unstable-core-do-not-import/index.d.ts +0 -1
- package/unstable-core-do-not-import/index.js +0 -1
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const noop = ()=>{
|
|
2
|
-
// noop
|
|
3
|
-
};
|
|
4
|
-
function createInnerProxy(callback, path) {
|
|
5
|
-
const proxy = new Proxy(noop, {
|
|
6
|
-
get (_obj, key) {
|
|
7
|
-
if (typeof key !== 'string' || key === 'then') {
|
|
8
|
-
// special case for if the proxy is accidentally treated
|
|
9
|
-
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return createInnerProxy(callback, [
|
|
13
|
-
...path,
|
|
14
|
-
key
|
|
15
|
-
]);
|
|
16
|
-
},
|
|
17
|
-
apply (_1, _2, args) {
|
|
18
|
-
const isApply = path[path.length - 1] === 'apply';
|
|
19
|
-
return callback({
|
|
20
|
-
args: isApply ? args.length >= 2 ? args[1] : [] : args,
|
|
21
|
-
path: isApply ? path.slice(0, -1) : path
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return proxy;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Creates a proxy that calls the callback with the path and arguments
|
|
29
|
-
*
|
|
30
|
-
* @internal
|
|
31
|
-
*/ const createRecursiveProxy = (callback)=>createInnerProxy(callback, []);
|
|
32
|
-
/**
|
|
33
|
-
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
34
|
-
*
|
|
35
|
-
* @internal
|
|
36
|
-
*/ const createFlatProxy = (callback)=>{
|
|
37
|
-
return new Proxy(noop, {
|
|
38
|
-
get (_obj, name) {
|
|
39
|
-
if (typeof name !== 'string' || name === 'then') {
|
|
40
|
-
// special case for if the proxy is accidentally treated
|
|
41
|
-
// like a PromiseLike (like in `Promise.resolve(proxy)`)
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
return callback(name);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { createFlatProxy, createRecursiveProxy };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
|
|
2
|
-
export declare function getCauseFromUnknown(cause: unknown): Error | undefined;
|
|
3
|
-
export declare function getTRPCErrorFromUnknown(cause: unknown): TRPCError;
|
|
4
|
-
export declare class TRPCError extends Error {
|
|
5
|
-
readonly cause?: Error;
|
|
6
|
-
readonly code: "INTERNAL_SERVER_ERROR" | "PARSE_ERROR" | "BAD_REQUEST" | "NOT_IMPLEMENTED" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
|
|
7
|
-
constructor(opts: {
|
|
8
|
-
message?: string;
|
|
9
|
-
code: TRPC_ERROR_CODE_KEY;
|
|
10
|
-
cause?: unknown;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=TRPCError.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCError.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/TRPCError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAMxD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAyBrE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAoBjE;AAED,qBAAa,SAAU,SAAQ,KAAK;IAGlC,SAAyB,KAAK,CAAC,EAAE,KAAK,CAAC;IACvC,SAAgB,IAAI,qSAAC;gBAET,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,mBAAmB,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAgBF"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var utils = require('../utils.js');
|
|
4
|
-
|
|
5
|
-
class UnknownCauseError extends Error {
|
|
6
|
-
}
|
|
7
|
-
function getCauseFromUnknown(cause) {
|
|
8
|
-
if (cause instanceof Error) {
|
|
9
|
-
return cause;
|
|
10
|
-
}
|
|
11
|
-
const type = typeof cause;
|
|
12
|
-
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
// Primitive types just get wrapped in an error
|
|
16
|
-
if (type !== 'object') {
|
|
17
|
-
return new Error(String(cause));
|
|
18
|
-
}
|
|
19
|
-
// If it's an object, we'll create a synthetic error
|
|
20
|
-
if (utils.isObject(cause)) {
|
|
21
|
-
const err = new UnknownCauseError();
|
|
22
|
-
for(const key in cause){
|
|
23
|
-
err[key] = cause[key];
|
|
24
|
-
}
|
|
25
|
-
return err;
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
function getTRPCErrorFromUnknown(cause) {
|
|
30
|
-
if (cause instanceof TRPCError) {
|
|
31
|
-
return cause;
|
|
32
|
-
}
|
|
33
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
34
|
-
// https://github.com/trpc/trpc/pull/4848
|
|
35
|
-
return cause;
|
|
36
|
-
}
|
|
37
|
-
const trpcError = new TRPCError({
|
|
38
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
39
|
-
cause
|
|
40
|
-
});
|
|
41
|
-
// Inherit stack from error
|
|
42
|
-
if (cause instanceof Error && cause.stack) {
|
|
43
|
-
trpcError.stack = cause.stack;
|
|
44
|
-
}
|
|
45
|
-
return trpcError;
|
|
46
|
-
}
|
|
47
|
-
class TRPCError extends Error {
|
|
48
|
-
constructor(opts){
|
|
49
|
-
const cause = getCauseFromUnknown(opts.cause);
|
|
50
|
-
const message = opts.message ?? cause?.message ?? opts.code;
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
52
|
-
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
53
|
-
super(message, {
|
|
54
|
-
cause
|
|
55
|
-
});
|
|
56
|
-
this.code = opts.code;
|
|
57
|
-
this.name = 'TRPCError';
|
|
58
|
-
if (!this.cause) {
|
|
59
|
-
// < ES2022 / < Node 16.9.0 compatability
|
|
60
|
-
this.cause = cause;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
exports.TRPCError = TRPCError;
|
|
66
|
-
exports.getCauseFromUnknown = getCauseFromUnknown;
|
|
67
|
-
exports.getTRPCErrorFromUnknown = getTRPCErrorFromUnknown;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../utils.mjs';
|
|
2
|
-
|
|
3
|
-
class UnknownCauseError extends Error {
|
|
4
|
-
}
|
|
5
|
-
function getCauseFromUnknown(cause) {
|
|
6
|
-
if (cause instanceof Error) {
|
|
7
|
-
return cause;
|
|
8
|
-
}
|
|
9
|
-
const type = typeof cause;
|
|
10
|
-
if (type === 'undefined' || type === 'function' || cause === null) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
// Primitive types just get wrapped in an error
|
|
14
|
-
if (type !== 'object') {
|
|
15
|
-
return new Error(String(cause));
|
|
16
|
-
}
|
|
17
|
-
// If it's an object, we'll create a synthetic error
|
|
18
|
-
if (isObject(cause)) {
|
|
19
|
-
const err = new UnknownCauseError();
|
|
20
|
-
for(const key in cause){
|
|
21
|
-
err[key] = cause[key];
|
|
22
|
-
}
|
|
23
|
-
return err;
|
|
24
|
-
}
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
function getTRPCErrorFromUnknown(cause) {
|
|
28
|
-
if (cause instanceof TRPCError) {
|
|
29
|
-
return cause;
|
|
30
|
-
}
|
|
31
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
32
|
-
// https://github.com/trpc/trpc/pull/4848
|
|
33
|
-
return cause;
|
|
34
|
-
}
|
|
35
|
-
const trpcError = new TRPCError({
|
|
36
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
37
|
-
cause
|
|
38
|
-
});
|
|
39
|
-
// Inherit stack from error
|
|
40
|
-
if (cause instanceof Error && cause.stack) {
|
|
41
|
-
trpcError.stack = cause.stack;
|
|
42
|
-
}
|
|
43
|
-
return trpcError;
|
|
44
|
-
}
|
|
45
|
-
class TRPCError extends Error {
|
|
46
|
-
constructor(opts){
|
|
47
|
-
const cause = getCauseFromUnknown(opts.cause);
|
|
48
|
-
const message = opts.message ?? cause?.message ?? opts.code;
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
50
|
-
// @ts-ignore https://github.com/tc39/proposal-error-cause
|
|
51
|
-
super(message, {
|
|
52
|
-
cause
|
|
53
|
-
});
|
|
54
|
-
this.code = opts.code;
|
|
55
|
-
this.name = 'TRPCError';
|
|
56
|
-
if (!this.cause) {
|
|
57
|
-
// < ES2022 / < Node 16.9.0 compatability
|
|
58
|
-
this.cause = cause;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { TRPCError, getCauseFromUnknown, getTRPCErrorFromUnknown };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ProcedureType } from '../procedure';
|
|
2
|
-
import type { TRPC_ERROR_CODE_KEY, TRPC_ERROR_CODE_NUMBER, TRPCErrorShape } from '../rpc';
|
|
3
|
-
import type { TRPCError } from './TRPCError';
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape<number>> = (args: {
|
|
8
|
-
error: TRPCError;
|
|
9
|
-
type: ProcedureType | 'unknown';
|
|
10
|
-
path: string | undefined;
|
|
11
|
-
input: unknown;
|
|
12
|
-
ctx: TContext | undefined;
|
|
13
|
-
shape: DefaultErrorShape;
|
|
14
|
-
}) => TShape;
|
|
15
|
-
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<any, infer TShape> ? TShape : DefaultErrorShape;
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export type DefaultErrorData = {
|
|
20
|
-
code: TRPC_ERROR_CODE_KEY;
|
|
21
|
-
httpStatus: number;
|
|
22
|
-
path?: string;
|
|
23
|
-
stack?: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export interface DefaultErrorShape extends TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, DefaultErrorData> {
|
|
29
|
-
message: string;
|
|
30
|
-
code: TRPC_ERROR_CODE_NUMBER;
|
|
31
|
-
}
|
|
32
|
-
export declare const defaultFormatter: ErrorFormatter<any, any>;
|
|
33
|
-
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACf,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,cAAc,CACxB,QAAQ,EACR,MAAM,SAAS,cAAc,CAAC,MAAM,CAAC,IACnC,CAAC,IAAI,EAAE;IACT,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,iBAAiB,CAAC;CAC1B,KAAK,MAAM,CAAC;AAEb,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,KAAK,SAAS,cAAc,CACnE,GAAG,EACH,MAAM,MAAM,CACb,GACG,MAAM,GACN,iBAAiB,CAAC;AACtB;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,iBACf,SAAQ,cAAc,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAErD,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ProcedureType } from '../procedure';
|
|
2
|
-
import type { AnyRootConfig } from '../rootConfig';
|
|
3
|
-
import type { TRPCError } from './TRPCError';
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare function getErrorShape<TConfig extends AnyRootConfig>(opts: {
|
|
8
|
-
config: TConfig;
|
|
9
|
-
error: TRPCError;
|
|
10
|
-
type: ProcedureType | 'unknown';
|
|
11
|
-
path: string | undefined;
|
|
12
|
-
input: unknown;
|
|
13
|
-
ctx: TConfig['$types']['ctx'] | undefined;
|
|
14
|
-
}): TConfig['$types']['errorShape'];
|
|
15
|
-
//# sourceMappingURL=getErrorShape.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getErrorShape.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/getErrorShape.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,aAAa,EAAE,IAAI,EAAE;IACjE,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAkBlC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var getHTTPStatusCode = require('../http/getHTTPStatusCode.js');
|
|
4
|
-
var codes = require('../rpc/codes.js');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/ function getErrorShape(opts) {
|
|
9
|
-
const { path , error , config } = opts;
|
|
10
|
-
const { code } = opts.error;
|
|
11
|
-
const shape = {
|
|
12
|
-
message: error.message,
|
|
13
|
-
code: codes.TRPC_ERROR_CODES_BY_KEY[code],
|
|
14
|
-
data: {
|
|
15
|
-
code,
|
|
16
|
-
httpStatus: getHTTPStatusCode.getHTTPStatusCodeFromError(error)
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
20
|
-
shape.data.stack = opts.error.stack;
|
|
21
|
-
}
|
|
22
|
-
if (typeof path === 'string') {
|
|
23
|
-
shape.data.path = path;
|
|
24
|
-
}
|
|
25
|
-
return config.errorFormatter({
|
|
26
|
-
...opts,
|
|
27
|
-
shape
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
exports.getErrorShape = getErrorShape;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getHTTPStatusCodeFromError } from '../http/getHTTPStatusCode.mjs';
|
|
2
|
-
import { TRPC_ERROR_CODES_BY_KEY } from '../rpc/codes.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/ function getErrorShape(opts) {
|
|
7
|
-
const { path , error , config } = opts;
|
|
8
|
-
const { code } = opts.error;
|
|
9
|
-
const shape = {
|
|
10
|
-
message: error.message,
|
|
11
|
-
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
12
|
-
data: {
|
|
13
|
-
code,
|
|
14
|
-
httpStatus: getHTTPStatusCodeFromError(error)
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
if (config.isDev && typeof opts.error.stack === 'string') {
|
|
18
|
-
shape.data.stack = opts.error.stack;
|
|
19
|
-
}
|
|
20
|
-
if (typeof path === 'string') {
|
|
21
|
-
shape.data.path = path;
|
|
22
|
-
}
|
|
23
|
-
return config.errorFormatter({
|
|
24
|
-
...opts,
|
|
25
|
-
shape
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { getErrorShape };
|
|
@@ -1,24 +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 declare function getBatchStreamFormatter(): {
|
|
21
|
-
(index: number, string: string): string;
|
|
22
|
-
end(): string;
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=batchStreamFormatter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batchStreamFormatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/batchStreamFormatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB;YAEd,MAAM,UAAU,MAAM;;EAO9C"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Format a batch response as a line-delimited JSON stream
|
|
5
|
-
* that the `unstable_httpBatchStreamLink` can parse:
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const formatter = getBatchStreamFormatter();
|
|
10
|
-
* res.send(formatter(1, 'response #2'));
|
|
11
|
-
* res.send(formatter(0, 'response #1'));
|
|
12
|
-
* res.send(formatter.end());
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* Expected format:
|
|
16
|
-
* ```json
|
|
17
|
-
* {"1":"response #2"
|
|
18
|
-
* ,"0":"response #1"
|
|
19
|
-
* }
|
|
20
|
-
* ```
|
|
21
|
-
*/ function getBatchStreamFormatter() {
|
|
22
|
-
let first = true;
|
|
23
|
-
function format(index, string) {
|
|
24
|
-
const prefix = first ? '{' : ',';
|
|
25
|
-
first = false;
|
|
26
|
-
return `${prefix}"${index}":${string}\n`;
|
|
27
|
-
}
|
|
28
|
-
format.end = ()=>'}';
|
|
29
|
-
return format;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
exports.getBatchStreamFormatter = getBatchStreamFormatter;
|
|
@@ -1,30 +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
|
-
*/ function getBatchStreamFormatter() {
|
|
20
|
-
let first = true;
|
|
21
|
-
function format(index, string) {
|
|
22
|
-
const prefix = first ? '{' : ',';
|
|
23
|
-
first = false;
|
|
24
|
-
return `${prefix}"${index}":${string}\n`;
|
|
25
|
-
}
|
|
26
|
-
format.end = ()=>'}';
|
|
27
|
-
return format;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { getBatchStreamFormatter };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '../error/TRPCError';
|
|
2
|
-
import type { AnyRouter } from '../router';
|
|
3
|
-
import type { MaybePromise } from '../types';
|
|
4
|
-
import type { HTTPRequest } from './types';
|
|
5
|
-
type GetInputs = (opts: {
|
|
6
|
-
req: HTTPRequest;
|
|
7
|
-
isBatchCall: boolean;
|
|
8
|
-
router: AnyRouter;
|
|
9
|
-
preprocessedBody: boolean;
|
|
10
|
-
}) => MaybePromise<Record<number, unknown>>;
|
|
11
|
-
export type BodyResult = {
|
|
12
|
-
ok: true;
|
|
13
|
-
data: unknown;
|
|
14
|
-
/**
|
|
15
|
-
* If the HTTP handler has already parsed the body
|
|
16
|
-
*/
|
|
17
|
-
preprocessed: boolean;
|
|
18
|
-
} | {
|
|
19
|
-
ok: false;
|
|
20
|
-
error: TRPCError;
|
|
21
|
-
};
|
|
22
|
-
export type BaseContentTypeHandler<TOptions> = {
|
|
23
|
-
isMatch(opts: TOptions): boolean;
|
|
24
|
-
getBody: (opts: TOptions) => MaybePromise<BodyResult>;
|
|
25
|
-
getInputs: GetInputs;
|
|
26
|
-
};
|
|
27
|
-
export declare const getJsonContentTypeInputs: GetInputs;
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=contentType.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,SAAS,GAAG,CAAC,IAAI,EAAE;IACtB,GAAG,EAAE,WAAW,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;IAClB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,KAAK,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5C,MAAM,MAAM,UAAU,GAClB;IACE,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;CACvB,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,sBAAsB,CAAC,QAAQ,IAAI;IAC7C,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,YAAY,CAAC,UAAU,CAAC,CAAC;IACtD,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,wBAAwB,EAAE,SAgCtC,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var TRPCError = require('../error/TRPCError.js');
|
|
4
|
-
|
|
5
|
-
function getRawProcedureInputOrThrow(opts) {
|
|
6
|
-
const { req } = opts;
|
|
7
|
-
try {
|
|
8
|
-
if (req.method === 'GET') {
|
|
9
|
-
if (!req.query.has('input')) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
const raw = req.query.get('input');
|
|
13
|
-
return JSON.parse(raw);
|
|
14
|
-
}
|
|
15
|
-
if (!opts.preprocessedBody && typeof req.body === 'string') {
|
|
16
|
-
// A mutation with no inputs will have req.body === ''
|
|
17
|
-
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
18
|
-
}
|
|
19
|
-
return req.body;
|
|
20
|
-
} catch (cause) {
|
|
21
|
-
throw new TRPCError.TRPCError({
|
|
22
|
-
code: 'PARSE_ERROR',
|
|
23
|
-
cause
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
28
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
29
|
-
};
|
|
30
|
-
const getJsonContentTypeInputs = (opts)=>{
|
|
31
|
-
const rawInput = getRawProcedureInputOrThrow(opts);
|
|
32
|
-
const transformer = opts.router._def._config.transformer;
|
|
33
|
-
if (!opts.isBatchCall) {
|
|
34
|
-
return {
|
|
35
|
-
0: deserializeInputValue(rawInput, transformer)
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
39
|
-
throw new TRPCError.TRPCError({
|
|
40
|
-
code: 'BAD_REQUEST',
|
|
41
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const input = {};
|
|
45
|
-
for(const key in rawInput){
|
|
46
|
-
const k = key;
|
|
47
|
-
const rawValue = rawInput[k];
|
|
48
|
-
const value = deserializeInputValue(rawValue, transformer);
|
|
49
|
-
input[k] = value;
|
|
50
|
-
}
|
|
51
|
-
return input;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
exports.getJsonContentTypeInputs = getJsonContentTypeInputs;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { TRPCError } from '../error/TRPCError.mjs';
|
|
2
|
-
|
|
3
|
-
function getRawProcedureInputOrThrow(opts) {
|
|
4
|
-
const { req } = opts;
|
|
5
|
-
try {
|
|
6
|
-
if (req.method === 'GET') {
|
|
7
|
-
if (!req.query.has('input')) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
const raw = req.query.get('input');
|
|
11
|
-
return JSON.parse(raw);
|
|
12
|
-
}
|
|
13
|
-
if (!opts.preprocessedBody && typeof req.body === 'string') {
|
|
14
|
-
// A mutation with no inputs will have req.body === ''
|
|
15
|
-
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
16
|
-
}
|
|
17
|
-
return req.body;
|
|
18
|
-
} catch (cause) {
|
|
19
|
-
throw new TRPCError({
|
|
20
|
-
code: 'PARSE_ERROR',
|
|
21
|
-
cause
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
26
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
27
|
-
};
|
|
28
|
-
const getJsonContentTypeInputs = (opts)=>{
|
|
29
|
-
const rawInput = getRawProcedureInputOrThrow(opts);
|
|
30
|
-
const transformer = opts.router._def._config.transformer;
|
|
31
|
-
if (!opts.isBatchCall) {
|
|
32
|
-
return {
|
|
33
|
-
0: deserializeInputValue(rawInput, transformer)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
37
|
-
throw new TRPCError({
|
|
38
|
-
code: 'BAD_REQUEST',
|
|
39
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const input = {};
|
|
43
|
-
for(const key in rawInput){
|
|
44
|
-
const k = key;
|
|
45
|
-
const rawValue = rawInput[k];
|
|
46
|
-
const value = deserializeInputValue(rawValue, transformer);
|
|
47
|
-
input[k] = value;
|
|
48
|
-
}
|
|
49
|
-
return input;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export { getJsonContentTypeInputs };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { TRPCError } from '../error/TRPCError';
|
|
2
|
-
import type { TRPCResponse } from '../rpc';
|
|
3
|
-
export declare function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): any;
|
|
4
|
-
export declare function getHTTPStatusCodeFromError(error: TRPCError): number;
|
|
5
|
-
//# sourceMappingURL=getHTTPStatusCode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AA4BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,OAuBpE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codes = require('../rpc/codes.js');
|
|
4
|
-
|
|
5
|
-
const JSONRPC2_TO_HTTP_CODE = {
|
|
6
|
-
PARSE_ERROR: 400,
|
|
7
|
-
BAD_REQUEST: 400,
|
|
8
|
-
UNAUTHORIZED: 401,
|
|
9
|
-
NOT_FOUND: 404,
|
|
10
|
-
FORBIDDEN: 403,
|
|
11
|
-
METHOD_NOT_SUPPORTED: 405,
|
|
12
|
-
TIMEOUT: 408,
|
|
13
|
-
CONFLICT: 409,
|
|
14
|
-
PRECONDITION_FAILED: 412,
|
|
15
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
16
|
-
UNPROCESSABLE_CONTENT: 422,
|
|
17
|
-
TOO_MANY_REQUESTS: 429,
|
|
18
|
-
CLIENT_CLOSED_REQUEST: 499,
|
|
19
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
20
|
-
NOT_IMPLEMENTED: 501
|
|
21
|
-
};
|
|
22
|
-
function getStatusCodeFromKey(code) {
|
|
23
|
-
return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
|
|
24
|
-
}
|
|
25
|
-
function getHTTPStatusCode(json) {
|
|
26
|
-
const arr = Array.isArray(json) ? json : [
|
|
27
|
-
json
|
|
28
|
-
];
|
|
29
|
-
const httpStatuses = new Set(arr.map((res)=>{
|
|
30
|
-
if ('error' in res) {
|
|
31
|
-
const data = res.error.data;
|
|
32
|
-
if (typeof data['httpStatus'] === 'number') {
|
|
33
|
-
return data['httpStatus'];
|
|
34
|
-
}
|
|
35
|
-
const code = codes.TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
36
|
-
return getStatusCodeFromKey(code);
|
|
37
|
-
}
|
|
38
|
-
return 200;
|
|
39
|
-
}));
|
|
40
|
-
if (httpStatuses.size !== 1) {
|
|
41
|
-
return 207;
|
|
42
|
-
}
|
|
43
|
-
const httpStatus = httpStatuses.values().next().value;
|
|
44
|
-
return httpStatus;
|
|
45
|
-
}
|
|
46
|
-
function getHTTPStatusCodeFromError(error) {
|
|
47
|
-
return getStatusCodeFromKey(error.code);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
exports.getHTTPStatusCode = getHTTPStatusCode;
|
|
51
|
-
exports.getHTTPStatusCodeFromError = getHTTPStatusCodeFromError;
|