@trpc/server 11.0.0-alpha-tmp-export-from-main.218 → 11.0.0-alpha-tmp-export-from-main-nuke-core.239
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 +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +69 -0
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -2
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +5 -4
- package/dist/adapters/aws-lambda/utils.mjs +3 -2
- package/dist/adapters/express.d.ts +1 -2
- 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 +6 -3
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +4 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +6 -4
- package/dist/adapters/fetch/fetchRequestHandler.mjs +4 -2
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +1 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +6 -4
- package/dist/adapters/next.mjs +4 -2
- 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 +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +3 -1
- package/dist/adapters/node-http/content-type/json/index.js +4 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +3 -1
- 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 +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +6 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +4 -2
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.d.ts +3 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -26
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -21
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -41
- package/dist/index.mjs +8 -1
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -13
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +6 -9
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +53 -125
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +2 -4
- 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 +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -26
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -30
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
|
@@ -0,0 +1,24 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 };
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 };
|
|
@@ -0,0 +1,5 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TRPC_ERROR_CODES_BY_NUMBER } from '../rpc/codes.mjs';
|
|
2
|
+
|
|
3
|
+
const JSONRPC2_TO_HTTP_CODE = {
|
|
4
|
+
PARSE_ERROR: 400,
|
|
5
|
+
BAD_REQUEST: 400,
|
|
6
|
+
UNAUTHORIZED: 401,
|
|
7
|
+
NOT_FOUND: 404,
|
|
8
|
+
FORBIDDEN: 403,
|
|
9
|
+
METHOD_NOT_SUPPORTED: 405,
|
|
10
|
+
TIMEOUT: 408,
|
|
11
|
+
CONFLICT: 409,
|
|
12
|
+
PRECONDITION_FAILED: 412,
|
|
13
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
14
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
15
|
+
TOO_MANY_REQUESTS: 429,
|
|
16
|
+
CLIENT_CLOSED_REQUEST: 499,
|
|
17
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
18
|
+
NOT_IMPLEMENTED: 501
|
|
19
|
+
};
|
|
20
|
+
function getStatusCodeFromKey(code) {
|
|
21
|
+
return JSONRPC2_TO_HTTP_CODE[code] ?? 500;
|
|
22
|
+
}
|
|
23
|
+
function getHTTPStatusCode(json) {
|
|
24
|
+
const arr = Array.isArray(json) ? json : [
|
|
25
|
+
json
|
|
26
|
+
];
|
|
27
|
+
const httpStatuses = new Set(arr.map((res)=>{
|
|
28
|
+
if ('error' in res) {
|
|
29
|
+
const data = res.error.data;
|
|
30
|
+
if (typeof data['httpStatus'] === 'number') {
|
|
31
|
+
return data['httpStatus'];
|
|
32
|
+
}
|
|
33
|
+
const code = TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
34
|
+
return getStatusCodeFromKey(code);
|
|
35
|
+
}
|
|
36
|
+
return 200;
|
|
37
|
+
}));
|
|
38
|
+
if (httpStatuses.size !== 1) {
|
|
39
|
+
return 207;
|
|
40
|
+
}
|
|
41
|
+
const httpStatus = httpStatuses.values().next().value;
|
|
42
|
+
return httpStatus;
|
|
43
|
+
}
|
|
44
|
+
function getHTTPStatusCodeFromError(error) {
|
|
45
|
+
return getStatusCodeFromKey(error.code);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { getHTTPStatusCode, getHTTPStatusCodeFromError };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { getHTTPStatusCode, getHTTPStatusCodeFromError, } from './getHTTPStatusCode';
|
|
2
|
+
export { resolveHTTPResponse } from './resolveHTTPResponse';
|
|
3
|
+
export type { BaseHandlerOptions, HTTPBaseHandlerOptions, HTTPHeaders, HTTPRequest, HTTPResponse, OnErrorFunction, ProcedureCall, ResolveHTTPRequestOptionsContextFn, ResponseChunk, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, } from './types';
|
|
4
|
+
export { getBatchStreamFormatter } from './batchStreamFormatter';
|
|
5
|
+
export type { BaseContentTypeHandler, BodyResult } from './contentType';
|
|
6
|
+
export { getJsonContentTypeInputs } from './contentType';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kCAAkC,EAClC,aAAa,EACb,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,YAAY,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TRPCError } from '../error/TRPCError';
|
|
2
|
+
import type { AnyRouter } from '../router';
|
|
3
|
+
import type { Maybe } from '../types';
|
|
4
|
+
import type { BaseContentTypeHandler } from './contentType';
|
|
5
|
+
import type { HTTPBaseHandlerOptions, HTTPRequest, HTTPResponse, ResolveHTTPRequestOptionsContextFn, ResponseChunk } from './types';
|
|
6
|
+
interface ResolveHTTPRequestOptions<TRouter extends AnyRouter, TRequest extends HTTPRequest> extends HTTPBaseHandlerOptions<TRouter, TRequest> {
|
|
7
|
+
createContext: ResolveHTTPRequestOptionsContextFn<TRouter>;
|
|
8
|
+
req: TRequest;
|
|
9
|
+
path: string;
|
|
10
|
+
error?: Maybe<TRPCError>;
|
|
11
|
+
contentTypeHandler?: BaseContentTypeHandler<any>;
|
|
12
|
+
preprocessedBody?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Called as soon as the response head is known.
|
|
15
|
+
* When streaming, headers will have been generated
|
|
16
|
+
* **without** knowing the response body.
|
|
17
|
+
*
|
|
18
|
+
* Without this callback, streaming is disabled.
|
|
19
|
+
*/
|
|
20
|
+
unstable_onHead: (headResponse: Omit<HTTPResponse, 'body'>, isStreaming: boolean) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Called for every procedure with `[index, result]`.
|
|
23
|
+
*
|
|
24
|
+
* Will be called a single time with `index = -1` if
|
|
25
|
+
* - response is an error
|
|
26
|
+
* - response is empty (HEAD request)
|
|
27
|
+
*
|
|
28
|
+
* Without this callback, streaming is disabled.
|
|
29
|
+
*/
|
|
30
|
+
unstable_onChunk: (chunk: ResponseChunk) => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Since `resolveHTTPResponse` is a public API (community adapters),
|
|
34
|
+
* let's give it a strong type signature to increase discoverability.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Non-streaming signature for `resolveHTTPResponse`:
|
|
38
|
+
* @param opts.unstable_onHead `undefined`
|
|
39
|
+
* @param opts.unstable_onChunk `undefined`
|
|
40
|
+
* @returns `Promise<HTTPResponse>`
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveHTTPResponse<TRouter extends AnyRouter, TRequest extends HTTPRequest>(opts: Omit<ResolveHTTPRequestOptions<TRouter, TRequest>, 'unstable_onChunk' | 'unstable_onHead'>): Promise<HTTPResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Streaming signature for `resolveHTTPResponse`:
|
|
45
|
+
* @param opts.unstable_onHead called as soon as the response head is known
|
|
46
|
+
* @param opts.unstable_onChunk called for every procedure with `[index, result]`
|
|
47
|
+
* @returns `Promise<void>` since the response is streamed
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveHTTPResponse<TRouter extends AnyRouter, TRequest extends HTTPRequest>(opts: ResolveHTTPRequestOptions<TRouter, TRequest>): Promise<void>;
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=resolveHTTPResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EACV,SAAS,EAGV,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,KAAK,EACV,sBAAsB,EAEtB,WAAW,EACX,YAAY,EACZ,kCAAkC,EAClC,aAAa,EAEd,MAAM,SAAS,CAAC;AAoBjB,UAAU,yBAAyB,CACjC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,CAC5B,SAAQ,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACjD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACzB,kBAAkB,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC,CAAC;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;OAMG;IACH,eAAe,EAAE,CACf,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,EACxC,WAAW,EAAE,OAAO,KACjB,IAAI,CAAC;IACV;;;;;;;;OAQG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAClD;AAyJD;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,EAE5B,IAAI,EAAE,IAAI,CACR,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC5C,kBAAkB,GAAG,iBAAiB,CACvC,GACA,OAAO,CAAC,YAAY,CAAC,CAAC;AACzB;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,EAC5B,IAAI,EAAE,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|