@trpc/server 11.0.0-rc.361 → 11.0.0-rc.363
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 -5
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -2
- 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 +8 -77
- package/dist/adapters/aws-lambda/index.mjs +9 -72
- package/dist/adapters/express.js +1 -0
- package/dist/adapters/express.mjs +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +19 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +22 -64
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +22 -64
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -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 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +29 -86
- package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -86
- package/dist/adapters/fetch/types.d.ts +2 -2
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- 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 +28 -71
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -71
- package/dist/adapters/node-http/types.d.ts +7 -8
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +174 -271
- package/dist/http.js +4 -2
- package/dist/http.mjs +2 -1
- package/dist/index.js +2 -4
- package/dist/index.mjs +1 -2
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -20
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +180 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +178 -0
- 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/resolveResponse.d.ts +15 -0
- package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/{resolveHTTPResponse.js → resolveResponse.js} +119 -134
- package/dist/unstable-core-do-not-import/http/{resolveHTTPResponse.mjs → resolveResponse.mjs} +119 -134
- package/dist/unstable-core-do-not-import/http/types.d.ts +25 -27
- 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 +0 -9
- 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 +12 -8
- package/dist/unstable-core-do-not-import.mjs +7 -5
- package/package.json +3 -13
- package/src/@trpc/server/http.ts +7 -12
- package/src/@trpc/server/index.ts +0 -3
- package/src/adapters/aws-lambda/getPlanner.ts +191 -0
- package/src/adapters/aws-lambda/index.ts +43 -107
- package/src/adapters/express.ts +1 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +43 -90
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +4 -3
- package/src/adapters/fetch/fetchRequestHandler.ts +35 -111
- package/src/adapters/fetch/types.ts +4 -2
- package/src/adapters/next.ts +1 -1
- 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 -97
- package/src/adapters/node-http/types.ts +27 -37
- package/src/adapters/standalone.ts +1 -1
- package/src/unstable-core-do-not-import/http/contentType.ts +214 -22
- 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/resolveResponse.ts +386 -0
- package/src/unstable-core-do-not-import/http/types.ts +25 -30
- package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -10
- 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/content-type/json/index.d.ts +0 -10
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/content-type/json/index.js +0 -62
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -60
- package/dist/adapters/aws-lambda/utils.d.ts +0 -31
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -111
- package/dist/adapters/aws-lambda/utils.mjs +0 -103
- package/dist/adapters/content-handlers/concurrentCache.d.ts +0 -7
- package/dist/adapters/content-handlers/concurrentCache.d.ts.map +0 -1
- package/dist/adapters/content-handlers/concurrentCache.js +0 -17
- package/dist/adapters/content-handlers/concurrentCache.mjs +0 -15
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
- package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
- package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/fastify/content-type/json/index.js +0 -62
- package/dist/adapters/fastify/content-type/json/index.mjs +0 -60
- package/dist/adapters/fastify/types.d.ts +0 -11
- package/dist/adapters/fastify/types.d.ts.map +0 -1
- package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
- package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/fetch/content-type/json/index.js +0 -55
- package/dist/adapters/fetch/content-type/json/index.mjs +0 -53
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -5
- 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 -32
- package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -30
- 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 -45
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -43
- package/dist/adapters/node-http/content-type/json/index.d.ts +0 -5
- 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 -68
- package/dist/adapters/node-http/content-type/json/index.mjs +0 -66
- package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/octet/index.js +0 -19
- package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
- package/dist/adapters/node-http/content-type/types.d.ts +0 -8
- package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
- package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -11
- 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/src/adapters/aws-lambda/content-type/json/index.ts +0 -108
- package/src/adapters/aws-lambda/utils.ts +0 -170
- package/src/adapters/content-handlers/concurrentCache.ts +0 -16
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
- package/src/adapters/fastify/content-type/json/index.ts +0 -106
- package/src/adapters/fastify/types.ts +0 -22
- package/src/adapters/fetch/content-type/json/index.ts +0 -90
- package/src/adapters/node-http/content-type/form-data/index.ts +0 -37
- package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -49
- package/src/adapters/node-http/content-type/json/index.ts +0 -100
- package/src/adapters/node-http/content-type/octet/index.ts +0 -27
- package/src/adapters/node-http/content-type/types.ts +0 -19
- package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
- package/src/unstable-core-do-not-import/http/index.ts +0 -28
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -461
package/dist/http.js
CHANGED
|
@@ -1,8 +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');
|
|
5
|
+
var contentTypeParsers = require('./unstable-core-do-not-import/http/contentTypeParsers.js');
|
|
6
|
+
var resolveResponse = require('./unstable-core-do-not-import/http/resolveResponse.js');
|
|
6
7
|
var toURL = require('./unstable-core-do-not-import/http/toURL.js');
|
|
7
8
|
require('./unstable-core-do-not-import/rootConfig.js');
|
|
8
9
|
|
|
@@ -10,6 +11,7 @@ require('./unstable-core-do-not-import/rootConfig.js');
|
|
|
10
11
|
|
|
11
12
|
exports.getHTTPStatusCode = getHTTPStatusCode.getHTTPStatusCode;
|
|
12
13
|
exports.getHTTPStatusCodeFromError = getHTTPStatusCode.getHTTPStatusCodeFromError;
|
|
13
|
-
exports.resolveHTTPResponse = resolveHTTPResponse.resolveHTTPResponse;
|
|
14
14
|
exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
|
|
15
|
+
exports.octetInputParser = contentTypeParsers.octetInputParser;
|
|
16
|
+
exports.resolveResponse = resolveResponse.resolveResponse;
|
|
15
17
|
exports.toURL = toURL.toURL;
|
package/dist/http.mjs
CHANGED
|
@@ -1,5 +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';
|
|
3
|
+
export { octetInputParser } from './unstable-core-do-not-import/http/contentTypeParsers.mjs';
|
|
4
|
+
export { resolveResponse } from './unstable-core-do-not-import/http/resolveResponse.mjs';
|
|
4
5
|
export { toURL } from './unstable-core-do-not-import/http/toURL.mjs';
|
|
5
6
|
import './unstable-core-do-not-import/rootConfig.mjs';
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
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');
|
|
9
9
|
var middleware = require('./unstable-core-do-not-import/middleware.js');
|
|
10
10
|
require('./unstable-core-do-not-import/rootConfig.js');
|
|
11
|
-
var contentTypeParsers = require('./unstable-core-do-not-import/contentTypeParsers.js');
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
exports.createTRPCFlatProxy = createProxy.createFlatProxy;
|
|
16
|
-
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
17
15
|
exports.TRPCError = TRPCError.TRPCError;
|
|
18
16
|
exports.getTRPCErrorFromUnknown = TRPCError.getTRPCErrorFromUnknown;
|
|
17
|
+
exports.getErrorShape = getErrorShape.getErrorShape;
|
|
19
18
|
exports.callProcedure = router.callProcedure;
|
|
20
19
|
exports.callTRPCProcedure = router.callProcedure;
|
|
21
20
|
exports.transformTRPCResponse = transformer.transformTRPCResponse;
|
|
22
21
|
exports.initTRPC = initTRPC.initTRPC;
|
|
23
22
|
exports.experimental_standaloneMiddleware = middleware.experimental_standaloneMiddleware;
|
|
24
23
|
exports.experimental_trpcMiddleware = middleware.experimental_standaloneMiddleware;
|
|
25
|
-
exports.parseOctetInput = contentTypeParsers.parseOctetInput;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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';
|
|
7
7
|
export { experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware } from './unstable-core-do-not-import/middleware.mjs';
|
|
8
8
|
import './unstable-core-do-not-import/rootConfig.mjs';
|
|
9
|
-
export { parseOctetInput } from './unstable-core-do-not-import/contentTypeParsers.mjs';
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} | {
|
|
10
|
-
ok: false;
|
|
11
|
-
error: TRPCError;
|
|
12
|
-
};
|
|
13
|
-
export type BaseContentTypeHandler<TOptions> = {
|
|
14
|
-
name: string;
|
|
15
|
-
isMatch(headers: Headers): boolean;
|
|
16
|
-
getInputs: (opts: TOptions, info: {
|
|
17
|
-
isBatchCall: boolean;
|
|
18
|
-
batch: number;
|
|
19
|
-
}) => Promise<unknown>;
|
|
20
|
-
};
|
|
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;
|
|
21
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":"
|
|
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"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var TRPCError = require('../error/TRPCError.js');
|
|
4
|
+
var utils = require('../utils.js');
|
|
5
|
+
|
|
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;
|
|
18
|
+
}
|
|
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;
|
|
40
|
+
}
|
|
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;
|
|
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
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
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
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
calls: [
|
|
119
|
+
{
|
|
120
|
+
path: opts.path,
|
|
121
|
+
getRawInput: getInputs.read,
|
|
122
|
+
result: getInputs.result
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
isBatchCall: false
|
|
126
|
+
};
|
|
127
|
+
}
|
|
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;
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
calls: [
|
|
146
|
+
{
|
|
147
|
+
path: opts.path,
|
|
148
|
+
getRawInput: getInputs.read,
|
|
149
|
+
result: getInputs.result
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
isBatchCall: false
|
|
153
|
+
};
|
|
154
|
+
}
|
|
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
|
+
}
|
|
179
|
+
|
|
180
|
+
exports.getRequestInfo = getRequestInfo;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { TRPCError } from '../error/TRPCError.mjs';
|
|
2
|
+
import { unsetMarker, isObject } from '../utils.mjs';
|
|
3
|
+
|
|
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;
|
|
16
|
+
}
|
|
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;
|
|
38
|
+
}
|
|
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;
|
|
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
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
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
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
calls: [
|
|
117
|
+
{
|
|
118
|
+
path: opts.path,
|
|
119
|
+
getRawInput: getInputs.read,
|
|
120
|
+
result: getInputs.result
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
isBatchCall: false
|
|
124
|
+
};
|
|
125
|
+
}
|
|
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;
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
calls: [
|
|
144
|
+
{
|
|
145
|
+
path: opts.path,
|
|
146
|
+
getRawInput: getInputs.read,
|
|
147
|
+
result: getInputs.result
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
isBatchCall: false
|
|
151
|
+
};
|
|
152
|
+
}
|
|
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
|
+
}
|
|
177
|
+
|
|
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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TRPCError } from '../error/TRPCError';
|
|
2
|
+
import { type AnyRouter } from '../router';
|
|
3
|
+
import type { HTTPBaseHandlerOptions, ResolveHTTPRequestOptionsContextFn } from './types';
|
|
4
|
+
interface ResolveHTTPRequestOptions<TRouter extends AnyRouter> extends HTTPBaseHandlerOptions<TRouter, Request> {
|
|
5
|
+
createContext: ResolveHTTPRequestOptionsContextFn<TRouter>;
|
|
6
|
+
req: Request;
|
|
7
|
+
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* If the request had an issue before reaching the handler
|
|
10
|
+
*/
|
|
11
|
+
error: TRPCError | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function resolveResponse<TRouter extends AnyRouter>(opts: ResolveHTTPRequestOptions<TRouter>): Promise<Response>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=resolveResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AAUjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAuHD,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAkOnB"}
|