@trpc/server 11.0.0-rc.359 → 11.0.0-rc.362
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 -6
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -1
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.d.ts +13 -0
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/getPlanner.js +143 -0
- package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
- package/dist/adapters/aws-lambda/index.d.ts +12 -9
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -65
- package/dist/adapters/aws-lambda/index.mjs +8 -61
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +1 -1
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +10 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +12 -55
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +13 -56
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -5
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +28 -71
- package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -72
- package/dist/adapters/fetch/types.d.ts +9 -12
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +2 -7
- package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -2
- package/dist/adapters/next.mjs +1 -2
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
- package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
- package/dist/adapters/node-http/index.d.ts +1 -0
- package/dist/adapters/node-http/index.d.ts.map +1 -1
- package/dist/adapters/node-http/index.js +2 -0
- package/dist/adapters/node-http/index.mjs +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +27 -72
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -73
- package/dist/adapters/node-http/types.d.ts +2 -14
- package/dist/adapters/node-http/types.d.ts.map +1 -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 -12
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +173 -259
- package/dist/http.js +4 -4
- package/dist/http.mjs +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -28
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +164 -38
- package/dist/unstable-core-do-not-import/http/contentType.mjs +164 -38
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +7 -43
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +115 -124
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +116 -125
- package/dist/unstable-core-do-not-import/http/types.d.ts +25 -29
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +12 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +2 -0
- package/dist/unstable-core-do-not-import/utils.mjs +2 -1
- package/dist/unstable-core-do-not-import.d.ts +9 -3
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +11 -9
- package/dist/unstable-core-do-not-import.mjs +7 -6
- package/package.json +3 -14
- package/src/@trpc/server/http.ts +7 -13
- package/src/@trpc/server/index.ts +1 -0
- package/src/adapters/aws-lambda/getPlanner.ts +191 -0
- package/src/adapters/aws-lambda/index.ts +43 -92
- package/src/adapters/express.ts +1 -6
- package/src/adapters/fastify/fastifyRequestHandler.ts +22 -77
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +34 -98
- package/src/adapters/fetch/types.ts +24 -15
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +2 -9
- package/src/adapters/next.ts +1 -6
- package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
- package/src/adapters/node-http/index.ts +1 -0
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -110
- package/src/adapters/node-http/types.ts +9 -19
- package/src/adapters/standalone.ts +1 -2
- package/src/adapters/ws.ts +9 -14
- package/src/unstable-core-do-not-import/http/contentType.ts +199 -82
- package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +133 -205
- package/src/unstable-core-do-not-import/http/types.ts +25 -32
- package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
- package/src/unstable-core-do-not-import/rootConfig.ts +21 -0
- package/src/unstable-core-do-not-import/utils.ts +4 -0
- package/src/unstable-core-do-not-import.ts +9 -3
- package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
- package/adapters/node-http/content-type/form-data/index.js +0 -1
- package/adapters/node-http/content-type/json/index.d.ts +0 -1
- package/adapters/node-http/content-type/json/index.js +0 -1
- package/dist/adapters/aws-lambda/utils.d.ts +0 -40
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -100
- package/dist/adapters/aws-lambda/utils.mjs +0 -93
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -73
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -26
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +0 -135
- package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -108
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -53
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -51
- package/dist/adapters/node-http/content-type/json/index.d.ts +0 -2
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/index.js +0 -16
- package/dist/adapters/node-http/content-type/json/index.mjs +0 -14
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -12
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/src/adapters/aws-lambda/utils.ts +0 -164
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +0 -277
- package/src/adapters/node-http/content-type/form-data/index.ts +0 -163
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +0 -89
- package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -58
- package/src/adapters/node-http/content-type/json/index.ts +0 -11
- package/src/adapters/node-http/internals/contentType.ts +0 -31
- package/src/unstable-core-do-not-import/http/index.ts +0 -29
package/dist/http.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var getHTTPStatusCode = require('./unstable-core-do-not-import/http/getHTTPStatusCode.js');
|
|
4
|
-
var resolveHTTPResponse = require('./unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
5
4
|
var batchStreamFormatter = require('./unstable-core-do-not-import/http/batchStreamFormatter.js');
|
|
6
|
-
var
|
|
5
|
+
var contentTypeParsers = require('./unstable-core-do-not-import/http/contentTypeParsers.js');
|
|
6
|
+
var resolveHTTPResponse = require('./unstable-core-do-not-import/http/resolveHTTPResponse.js');
|
|
7
7
|
var toURL = require('./unstable-core-do-not-import/http/toURL.js');
|
|
8
8
|
require('./unstable-core-do-not-import/rootConfig.js');
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ require('./unstable-core-do-not-import/rootConfig.js');
|
|
|
11
11
|
|
|
12
12
|
exports.getHTTPStatusCode = getHTTPStatusCode.getHTTPStatusCode;
|
|
13
13
|
exports.getHTTPStatusCodeFromError = getHTTPStatusCode.getHTTPStatusCodeFromError;
|
|
14
|
-
exports.resolveHTTPResponse = resolveHTTPResponse.resolveHTTPResponse;
|
|
15
14
|
exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
|
|
16
|
-
exports.
|
|
15
|
+
exports.octetInputParser = contentTypeParsers.octetInputParser;
|
|
16
|
+
exports.resolveResponse = resolveHTTPResponse.resolveResponse;
|
|
17
17
|
exports.toURL = toURL.toURL;
|
package/dist/http.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getHTTPStatusCode, getHTTPStatusCodeFromError } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
|
|
2
|
-
export { resolveHTTPResponse } from './unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
3
2
|
export { getBatchStreamFormatter } from './unstable-core-do-not-import/http/batchStreamFormatter.mjs';
|
|
4
|
-
export {
|
|
3
|
+
export { octetInputParser } from './unstable-core-do-not-import/http/contentTypeParsers.mjs';
|
|
4
|
+
export { resolveResponse } from './unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
|
|
5
5
|
export { toURL } from './unstable-core-do-not-import/http/toURL.mjs';
|
|
6
6
|
import './unstable-core-do-not-import/rootConfig.mjs';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var createProxy = require('./unstable-core-do-not-import/createProxy.js');
|
|
4
|
-
var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
|
|
5
4
|
var TRPCError = require('./unstable-core-do-not-import/error/TRPCError.js');
|
|
5
|
+
var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
|
|
6
6
|
var router = require('./unstable-core-do-not-import/router.js');
|
|
7
7
|
var transformer = require('./unstable-core-do-not-import/transformer.js');
|
|
8
8
|
var initTRPC = require('./unstable-core-do-not-import/initTRPC.js');
|
|
@@ -12,9 +12,9 @@ require('./unstable-core-do-not-import/rootConfig.js');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
exports.createTRPCFlatProxy = createProxy.createFlatProxy;
|
|
15
|
-
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
16
15
|
exports.TRPCError = TRPCError.TRPCError;
|
|
17
16
|
exports.getTRPCErrorFromUnknown = TRPCError.getTRPCErrorFromUnknown;
|
|
17
|
+
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
18
18
|
exports.callProcedure = router.callProcedure;
|
|
19
19
|
exports.callTRPCProcedure = router.callProcedure;
|
|
20
20
|
exports.transformTRPCResponse = transformer.transformTRPCResponse;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createFlatProxy as createTRPCFlatProxy } from './unstable-core-do-not-import/createProxy.mjs';
|
|
2
|
-
export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
|
|
3
2
|
export { TRPCError, getTRPCErrorFromUnknown } from './unstable-core-do-not-import/error/TRPCError.mjs';
|
|
3
|
+
export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
|
|
4
4
|
export { callProcedure, callProcedure as callTRPCProcedure } from './unstable-core-do-not-import/router.mjs';
|
|
5
5
|
export { transformTRPCResponse } from './unstable-core-do-not-import/transformer.mjs';
|
|
6
6
|
export { initTRPC } from './unstable-core-do-not-import/initTRPC.mjs';
|
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {};
|
|
1
|
+
import type { RootConfig } from '../rootConfig';
|
|
2
|
+
import type { TRPCRequestInfo } from './types';
|
|
3
|
+
export declare function getRequestInfo(opts: {
|
|
4
|
+
path: string;
|
|
5
|
+
req: Request;
|
|
6
|
+
searchParams: URLSearchParams;
|
|
7
|
+
config: RootConfig<any>;
|
|
8
|
+
}): TRPCRequestInfo;
|
|
29
9
|
//# sourceMappingURL=contentType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA4M/C,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,eAAe,CAAC;IAC9B,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;CACzB,GAAG,eAAe,CAGlB"}
|
|
@@ -1,54 +1,180 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var TRPCError = require('../error/TRPCError.js');
|
|
4
|
+
var utils = require('../utils.js');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Memoize a function that takes no arguments
|
|
8
|
+
* @internal
|
|
9
|
+
*/ function memo(fn) {
|
|
10
|
+
let promise = null;
|
|
11
|
+
let value = utils.unsetMarker;
|
|
12
|
+
return {
|
|
13
|
+
/**
|
|
14
|
+
* Lazily read the value
|
|
15
|
+
*/ read: async ()=>{
|
|
16
|
+
if (value !== utils.unsetMarker) {
|
|
17
|
+
return value;
|
|
11
18
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
if (promise === null) {
|
|
20
|
+
// dedupes promises and catches errors
|
|
21
|
+
promise = fn().catch((cause)=>{
|
|
22
|
+
if (cause instanceof TRPCError.TRPCError) {
|
|
23
|
+
throw cause;
|
|
24
|
+
}
|
|
25
|
+
throw new TRPCError.TRPCError({
|
|
26
|
+
code: 'BAD_REQUEST',
|
|
27
|
+
message: cause instanceof Error ? cause.message : 'Invalid input',
|
|
28
|
+
cause
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
value = await promise;
|
|
33
|
+
promise = null;
|
|
34
|
+
return value;
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Get an already stored result
|
|
38
|
+
*/ result: ()=>{
|
|
39
|
+
return value !== utils.unsetMarker ? value : undefined;
|
|
18
40
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const jsonContentTypeHandler = {
|
|
44
|
+
isMatch (req) {
|
|
45
|
+
return !!req.headers.get('content-type')?.startsWith('application/json');
|
|
46
|
+
},
|
|
47
|
+
parse (opts) {
|
|
48
|
+
const { req } = opts;
|
|
49
|
+
const isBatchCall = opts.searchParams.get('batch') === '1';
|
|
50
|
+
const paths = isBatchCall ? opts.path.split(',') : [
|
|
51
|
+
opts.path
|
|
52
|
+
];
|
|
53
|
+
const getInputs = memo(async ()=>{
|
|
54
|
+
let inputs = undefined;
|
|
55
|
+
if (req.method === 'GET') {
|
|
56
|
+
const queryInput = opts.searchParams.get('input');
|
|
57
|
+
if (queryInput) {
|
|
58
|
+
inputs = JSON.parse(queryInput);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
inputs = await req.json();
|
|
62
|
+
}
|
|
63
|
+
if (inputs === undefined) {
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
if (!isBatchCall) {
|
|
67
|
+
return {
|
|
68
|
+
0: opts.config.transformer.input.deserialize(inputs)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (!utils.isObject(inputs)) {
|
|
72
|
+
throw new TRPCError.TRPCError({
|
|
73
|
+
code: 'BAD_REQUEST',
|
|
74
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const acc = {};
|
|
78
|
+
for (const index of paths.keys()){
|
|
79
|
+
const input = inputs[index];
|
|
80
|
+
if (input !== undefined) {
|
|
81
|
+
acc[index] = opts.config.transformer.input.deserialize(input);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return acc;
|
|
24
85
|
});
|
|
86
|
+
return {
|
|
87
|
+
isBatchCall,
|
|
88
|
+
calls: paths.map((path, index)=>({
|
|
89
|
+
path,
|
|
90
|
+
getRawInput: async ()=>{
|
|
91
|
+
const inputs = await getInputs.read();
|
|
92
|
+
return inputs[index];
|
|
93
|
+
},
|
|
94
|
+
result: ()=>{
|
|
95
|
+
return getInputs.result()?.[index];
|
|
96
|
+
}
|
|
97
|
+
}))
|
|
98
|
+
};
|
|
25
99
|
}
|
|
26
|
-
}
|
|
27
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
28
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
29
100
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
101
|
+
const formDataContentTypeHandler = {
|
|
102
|
+
isMatch (req) {
|
|
103
|
+
return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
|
|
104
|
+
},
|
|
105
|
+
parse (opts) {
|
|
106
|
+
const { req } = opts;
|
|
107
|
+
if (req.method !== 'POST') {
|
|
108
|
+
throw new TRPCError.TRPCError({
|
|
109
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
110
|
+
message: 'Only POST requests are supported for multipart/form-data requests'
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const getInputs = memo(async ()=>{
|
|
114
|
+
const fd = await req.formData();
|
|
115
|
+
return fd;
|
|
116
|
+
});
|
|
34
117
|
return {
|
|
35
|
-
|
|
118
|
+
calls: [
|
|
119
|
+
{
|
|
120
|
+
path: opts.path,
|
|
121
|
+
getRawInput: getInputs.read,
|
|
122
|
+
result: getInputs.result
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
isBatchCall: false
|
|
36
126
|
};
|
|
37
127
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
128
|
+
};
|
|
129
|
+
const octetStreamContentTypeHandler = {
|
|
130
|
+
isMatch (req) {
|
|
131
|
+
return !!req.headers.get('content-type')?.startsWith('application/octet-stream');
|
|
132
|
+
},
|
|
133
|
+
parse (opts) {
|
|
134
|
+
const { req } = opts;
|
|
135
|
+
if (req.method !== 'POST') {
|
|
136
|
+
throw new TRPCError.TRPCError({
|
|
137
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
138
|
+
message: 'Only POST requests are supported for application/octet-stream requests'
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const getInputs = memo(async ()=>{
|
|
142
|
+
return req.body;
|
|
42
143
|
});
|
|
144
|
+
return {
|
|
145
|
+
calls: [
|
|
146
|
+
{
|
|
147
|
+
path: opts.path,
|
|
148
|
+
getRawInput: getInputs.read,
|
|
149
|
+
result: getInputs.result
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
isBatchCall: false
|
|
153
|
+
};
|
|
43
154
|
}
|
|
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
155
|
};
|
|
156
|
+
const handlers = [
|
|
157
|
+
jsonContentTypeHandler,
|
|
158
|
+
formDataContentTypeHandler,
|
|
159
|
+
octetStreamContentTypeHandler
|
|
160
|
+
];
|
|
161
|
+
function getContentTypeHandler(req) {
|
|
162
|
+
const handler = handlers.find((handler)=>handler.isMatch(req));
|
|
163
|
+
if (handler) {
|
|
164
|
+
return handler;
|
|
165
|
+
}
|
|
166
|
+
if (!handler && req.method === 'GET') {
|
|
167
|
+
// fallback to JSON for get requests so GET-requests can be opened in browser easily
|
|
168
|
+
return jsonContentTypeHandler;
|
|
169
|
+
}
|
|
170
|
+
throw new TRPCError.TRPCError({
|
|
171
|
+
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
172
|
+
message: req.headers.has('content-type') ? `Unsupported content-type "${req.headers.get('content-type')}` : 'Missing content-type header'
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function getRequestInfo(opts) {
|
|
176
|
+
const handler = getContentTypeHandler(opts.req);
|
|
177
|
+
return handler.parse(opts);
|
|
178
|
+
}
|
|
53
179
|
|
|
54
|
-
exports.
|
|
180
|
+
exports.getRequestInfo = getRequestInfo;
|
|
@@ -1,52 +1,178 @@
|
|
|
1
1
|
import { TRPCError } from '../error/TRPCError.mjs';
|
|
2
|
+
import { unsetMarker, isObject } from '../utils.mjs';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Memoize a function that takes no arguments
|
|
6
|
+
* @internal
|
|
7
|
+
*/ function memo(fn) {
|
|
8
|
+
let promise = null;
|
|
9
|
+
let value = unsetMarker;
|
|
10
|
+
return {
|
|
11
|
+
/**
|
|
12
|
+
* Lazily read the value
|
|
13
|
+
*/ read: async ()=>{
|
|
14
|
+
if (value !== unsetMarker) {
|
|
15
|
+
return value;
|
|
9
16
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
if (promise === null) {
|
|
18
|
+
// dedupes promises and catches errors
|
|
19
|
+
promise = fn().catch((cause)=>{
|
|
20
|
+
if (cause instanceof TRPCError) {
|
|
21
|
+
throw cause;
|
|
22
|
+
}
|
|
23
|
+
throw new TRPCError({
|
|
24
|
+
code: 'BAD_REQUEST',
|
|
25
|
+
message: cause instanceof Error ? cause.message : 'Invalid input',
|
|
26
|
+
cause
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
value = await promise;
|
|
31
|
+
promise = null;
|
|
32
|
+
return value;
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Get an already stored result
|
|
36
|
+
*/ result: ()=>{
|
|
37
|
+
return value !== unsetMarker ? value : undefined;
|
|
16
38
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const jsonContentTypeHandler = {
|
|
42
|
+
isMatch (req) {
|
|
43
|
+
return !!req.headers.get('content-type')?.startsWith('application/json');
|
|
44
|
+
},
|
|
45
|
+
parse (opts) {
|
|
46
|
+
const { req } = opts;
|
|
47
|
+
const isBatchCall = opts.searchParams.get('batch') === '1';
|
|
48
|
+
const paths = isBatchCall ? opts.path.split(',') : [
|
|
49
|
+
opts.path
|
|
50
|
+
];
|
|
51
|
+
const getInputs = memo(async ()=>{
|
|
52
|
+
let inputs = undefined;
|
|
53
|
+
if (req.method === 'GET') {
|
|
54
|
+
const queryInput = opts.searchParams.get('input');
|
|
55
|
+
if (queryInput) {
|
|
56
|
+
inputs = JSON.parse(queryInput);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
inputs = await req.json();
|
|
60
|
+
}
|
|
61
|
+
if (inputs === undefined) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
if (!isBatchCall) {
|
|
65
|
+
return {
|
|
66
|
+
0: opts.config.transformer.input.deserialize(inputs)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (!isObject(inputs)) {
|
|
70
|
+
throw new TRPCError({
|
|
71
|
+
code: 'BAD_REQUEST',
|
|
72
|
+
message: '"input" needs to be an object when doing a batch call'
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const acc = {};
|
|
76
|
+
for (const index of paths.keys()){
|
|
77
|
+
const input = inputs[index];
|
|
78
|
+
if (input !== undefined) {
|
|
79
|
+
acc[index] = opts.config.transformer.input.deserialize(input);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
22
83
|
});
|
|
84
|
+
return {
|
|
85
|
+
isBatchCall,
|
|
86
|
+
calls: paths.map((path, index)=>({
|
|
87
|
+
path,
|
|
88
|
+
getRawInput: async ()=>{
|
|
89
|
+
const inputs = await getInputs.read();
|
|
90
|
+
return inputs[index];
|
|
91
|
+
},
|
|
92
|
+
result: ()=>{
|
|
93
|
+
return getInputs.result()?.[index];
|
|
94
|
+
}
|
|
95
|
+
}))
|
|
96
|
+
};
|
|
23
97
|
}
|
|
24
|
-
}
|
|
25
|
-
const deserializeInputValue = (rawValue, transformer)=>{
|
|
26
|
-
return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
|
|
27
98
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
99
|
+
const formDataContentTypeHandler = {
|
|
100
|
+
isMatch (req) {
|
|
101
|
+
return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
|
|
102
|
+
},
|
|
103
|
+
parse (opts) {
|
|
104
|
+
const { req } = opts;
|
|
105
|
+
if (req.method !== 'POST') {
|
|
106
|
+
throw new TRPCError({
|
|
107
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
108
|
+
message: 'Only POST requests are supported for multipart/form-data requests'
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const getInputs = memo(async ()=>{
|
|
112
|
+
const fd = await req.formData();
|
|
113
|
+
return fd;
|
|
114
|
+
});
|
|
32
115
|
return {
|
|
33
|
-
|
|
116
|
+
calls: [
|
|
117
|
+
{
|
|
118
|
+
path: opts.path,
|
|
119
|
+
getRawInput: getInputs.read,
|
|
120
|
+
result: getInputs.result
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
isBatchCall: false
|
|
34
124
|
};
|
|
35
125
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
126
|
+
};
|
|
127
|
+
const octetStreamContentTypeHandler = {
|
|
128
|
+
isMatch (req) {
|
|
129
|
+
return !!req.headers.get('content-type')?.startsWith('application/octet-stream');
|
|
130
|
+
},
|
|
131
|
+
parse (opts) {
|
|
132
|
+
const { req } = opts;
|
|
133
|
+
if (req.method !== 'POST') {
|
|
134
|
+
throw new TRPCError({
|
|
135
|
+
code: 'METHOD_NOT_SUPPORTED',
|
|
136
|
+
message: 'Only POST requests are supported for application/octet-stream requests'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const getInputs = memo(async ()=>{
|
|
140
|
+
return req.body;
|
|
40
141
|
});
|
|
142
|
+
return {
|
|
143
|
+
calls: [
|
|
144
|
+
{
|
|
145
|
+
path: opts.path,
|
|
146
|
+
getRawInput: getInputs.read,
|
|
147
|
+
result: getInputs.result
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
isBatchCall: false
|
|
151
|
+
};
|
|
41
152
|
}
|
|
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
153
|
};
|
|
154
|
+
const handlers = [
|
|
155
|
+
jsonContentTypeHandler,
|
|
156
|
+
formDataContentTypeHandler,
|
|
157
|
+
octetStreamContentTypeHandler
|
|
158
|
+
];
|
|
159
|
+
function getContentTypeHandler(req) {
|
|
160
|
+
const handler = handlers.find((handler)=>handler.isMatch(req));
|
|
161
|
+
if (handler) {
|
|
162
|
+
return handler;
|
|
163
|
+
}
|
|
164
|
+
if (!handler && req.method === 'GET') {
|
|
165
|
+
// fallback to JSON for get requests so GET-requests can be opened in browser easily
|
|
166
|
+
return jsonContentTypeHandler;
|
|
167
|
+
}
|
|
168
|
+
throw new TRPCError({
|
|
169
|
+
code: 'UNSUPPORTED_MEDIA_TYPE',
|
|
170
|
+
message: req.headers.has('content-type') ? `Unsupported content-type "${req.headers.get('content-type')}` : 'Missing content-type header'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function getRequestInfo(opts) {
|
|
174
|
+
const handler = getContentTypeHandler(opts.req);
|
|
175
|
+
return handler.parse(opts);
|
|
176
|
+
}
|
|
51
177
|
|
|
52
|
-
export {
|
|
178
|
+
export { getRequestInfo };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParserZodEsque } from '../parser';
|
|
2
|
+
type UtilityParser<TInput, TOutput> = ParserZodEsque<TInput, TOutput> & {
|
|
3
|
+
parse: (input: unknown) => TOutput;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* File is only available from Node19+ but it always extends Blob so we can use that as a type until we eventually drop Node18
|
|
7
|
+
*/
|
|
8
|
+
interface FileLike extends Blob {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
}
|
|
11
|
+
type OctetInput = Blob | Uint8Array | FileLike;
|
|
12
|
+
export declare const octetInputParser: UtilityParser<OctetInput, ReadableStream>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=contentTypeParsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentTypeParsers.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentTypeParsers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,KAAK,aAAa,CAAC,MAAM,EAAE,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACtE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACpC,CAAC;AAIF;;GAEG;AACH,UAAU,QAAS,SAAQ,IAAI;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,KAAK,UAAU,GAAG,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC/C,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,UAAU,EAAE,cAAc,CAYtE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const octetInputParser = {
|
|
4
|
+
_input: null,
|
|
5
|
+
_output: null,
|
|
6
|
+
parse (input) {
|
|
7
|
+
if (input instanceof ReadableStream) {
|
|
8
|
+
return input;
|
|
9
|
+
}
|
|
10
|
+
throw new Error(`Parsed input was expected to be a ReadableStream but was: ${typeof input}`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.octetInputParser = octetInputParser;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const octetInputParser = {
|
|
2
|
+
_input: null,
|
|
3
|
+
_output: null,
|
|
4
|
+
parse (input) {
|
|
5
|
+
if (input instanceof ReadableStream) {
|
|
6
|
+
return input;
|
|
7
|
+
}
|
|
8
|
+
throw new Error(`Parsed input was expected to be a ReadableStream but was: ${typeof input}`);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { octetInputParser };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TRPCError } from '../error/TRPCError';
|
|
2
2
|
import type { TRPCResponse } from '../rpc';
|
|
3
|
-
export declare function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]):
|
|
3
|
+
export declare function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): number;
|
|
4
4
|
export declare function getHTTPStatusCodeFromError(error: TRPCError): number;
|
|
5
5
|
//# sourceMappingURL=getHTTPStatusCode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AA6BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AA6BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,CAyB7E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
|