@trpc/server 10.22.0 → 10.23.0
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/adapters/aws-lambda/index.js +2 -1
- package/dist/adapters/aws-lambda/index.mjs +2 -1
- package/dist/adapters/express.js +5 -2
- package/dist/adapters/express.mjs +5 -2
- package/dist/adapters/fastify/index.js +2 -1
- package/dist/adapters/fastify/index.mjs +2 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/index.js +3 -2
- package/dist/adapters/fetch/index.mjs +3 -2
- package/dist/adapters/next.js +5 -2
- package/dist/adapters/next.mjs +5 -2
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +70 -0
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +24 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/index.js +723 -0
- package/dist/adapters/node-http/content-type/form-data/index.mjs +708 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +31 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +11 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +40 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +7 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/json/index.d.ts +2 -0
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/json/index.js +53 -0
- package/dist/adapters/node-http/content-type/json/index.mjs +49 -0
- package/dist/adapters/node-http/index.js +5 -2
- package/dist/adapters/node-http/index.mjs +5 -2
- package/dist/adapters/node-http/internals/contentType.d.ts +9 -0
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -7
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/types.d.ts +7 -0
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.js +5 -2
- package/dist/adapters/standalone.mjs +5 -2
- package/dist/contentType-3194ed5f.mjs +5 -0
- package/dist/contentType-8356d528.js +54 -0
- package/dist/contentType-8c16408e.js +7 -0
- package/dist/contentType-a75c990c.js +58 -0
- package/dist/contentType-acc3be52.mjs +52 -0
- package/dist/contentType-f27e4bfc.js +5 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +3 -0
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/http/contentType.d.ts +29 -0
- package/dist/http/contentType.d.ts.map +1 -0
- package/dist/http/index.js +2 -1
- package/dist/http/index.mjs +2 -1
- package/dist/http/resolveHTTPResponse.d.ts +2 -0
- package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.mjs +6 -4
- package/dist/{nodeHTTPRequestHandler-8bbfaa5c.js → nodeHTTPRequestHandler-953c8f9a.js} +22 -54
- package/dist/{nodeHTTPRequestHandler-9d8156da.js → nodeHTTPRequestHandler-c1dcd256.js} +22 -47
- package/dist/{nodeHTTPRequestHandler-4f6f12f6.mjs → nodeHTTPRequestHandler-fcbe1351.mjs} +22 -54
- package/dist/{resolveHTTPResponse-b413b925.js → resolveHTTPResponse-9a9f3436.js} +10 -56
- package/dist/{resolveHTTPResponse-a2e412ec.js → resolveHTTPResponse-a7abb046.js} +9 -49
- package/dist/{resolveHTTPResponse-24febe05.mjs → resolveHTTPResponse-e1286cb3.mjs} +10 -50
- package/package.json +14 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +4 -1
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +268 -0
- package/src/adapters/node-http/content-type/form-data/index.ts +105 -0
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +59 -0
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +51 -0
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +85 -0
- package/src/adapters/node-http/{internals → content-type/json}/getPostBody.test.ts +6 -2
- package/src/adapters/node-http/{internals → content-type/json}/getPostBody.ts +5 -7
- package/src/adapters/node-http/content-type/json/index.ts +11 -0
- package/src/adapters/node-http/internals/contentType.ts +29 -0
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +34 -35
- package/src/adapters/node-http/types.ts +15 -0
- package/src/core/index.ts +1 -1
- package/src/core/internals/procedureBuilder.ts +21 -4
- package/src/core/middleware.ts +1 -0
- package/src/http/contentType.ts +100 -0
- package/src/http/resolveHTTPResponse.ts +18 -65
- package/dist/adapters/node-http/internals/getPostBody.d.ts +0 -14
- package/dist/adapters/node-http/internals/getPostBody.d.ts.map +0 -1
package/dist/http/index.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var config = require('../config-e6e74385.js');
|
|
6
|
-
var resolveHTTPResponse = require('../resolveHTTPResponse-
|
|
6
|
+
var resolveHTTPResponse = require('../resolveHTTPResponse-a7abb046.js');
|
|
7
7
|
require('../TRPCError-16b2e52d.js');
|
|
8
8
|
require('../codes-0a561c20.js');
|
|
9
9
|
require('../index-4d2d31b6.js');
|
|
10
10
|
require('../transformTRPCResponse-8afb9a5c.js');
|
|
11
|
+
require('../contentType-8356d528.js');
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
package/dist/http/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { T as TRPC_ERROR_CODES_BY_NUMBER, f as getHTTPStatusCode, g as getHTTPStatusCodeFromError } from '../config-f0387de5.mjs';
|
|
2
|
-
export { r as resolveHTTPResponse } from '../resolveHTTPResponse-
|
|
2
|
+
export { r as resolveHTTPResponse } from '../resolveHTTPResponse-e1286cb3.mjs';
|
|
3
3
|
import '../TRPCError-2b10c8d2.mjs';
|
|
4
4
|
import '../codes-e5d244b6.mjs';
|
|
5
5
|
import '../index-972002da.mjs';
|
|
6
6
|
import '../transformTRPCResponse-0ea8c0ca.mjs';
|
|
7
|
+
import '../contentType-acc3be52.mjs';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnyRouter, inferRouterContext } from '../core';
|
|
2
2
|
import { TRPCError } from '../error/TRPCError';
|
|
3
3
|
import { Maybe } from '../types';
|
|
4
|
+
import { BaseContentTypeHandler } from './contentType';
|
|
4
5
|
import { HTTPResponse } from './internals/types';
|
|
5
6
|
import { HTTPBaseHandlerOptions, HTTPRequest } from './types';
|
|
6
7
|
interface ResolveHTTPRequestOptions<TRouter extends AnyRouter, TRequest extends HTTPRequest> extends HTTPBaseHandlerOptions<TRouter, TRequest> {
|
|
@@ -8,6 +9,7 @@ interface ResolveHTTPRequestOptions<TRouter extends AnyRouter, TRequest extends
|
|
|
8
9
|
req: TRequest;
|
|
9
10
|
path: string;
|
|
10
11
|
error?: Maybe<TRPCError>;
|
|
12
|
+
contentTypeHandler?: BaseContentTypeHandler<any>;
|
|
11
13
|
preprocessedBody?: boolean;
|
|
12
14
|
}
|
|
13
15
|
export declare function resolveHTTPResponse<TRouter extends AnyRouter, TRequest extends HTTPRequest>(opts: ResolveHTTPRequestOptions<TRouter, TRequest>): Promise<HTTPResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../src/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAGT,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAA2B,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../src/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAGT,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAA2B,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EACL,sBAAsB,EAEvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAe,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAc9D,UAAU,yBAAyB,CACjC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,CAC5B,SAAQ,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACjD,aAAa,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,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;CAC5B;AAED,wBAAsB,mBAAmB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,EAC5B,IAAI,EAAE,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CA8K3E"}
|
package/dist/index.js
CHANGED
|
@@ -455,17 +455,19 @@ function createProcedureCaller(_def) {
|
|
|
455
455
|
ctx: callOpts.ctx,
|
|
456
456
|
type: opts.type,
|
|
457
457
|
path: opts.path,
|
|
458
|
-
rawInput: opts.rawInput,
|
|
458
|
+
rawInput: callOpts.rawInput ?? opts.rawInput,
|
|
459
459
|
meta: _def.meta,
|
|
460
460
|
input: callOpts.input,
|
|
461
|
-
next
|
|
462
|
-
|
|
461
|
+
next (_nextOpts) {
|
|
462
|
+
const nextOpts = _nextOpts;
|
|
463
|
+
return callRecursive({
|
|
463
464
|
index: callOpts.index + 1,
|
|
464
465
|
ctx: nextOpts && 'ctx' in nextOpts ? {
|
|
465
466
|
...callOpts.ctx,
|
|
466
467
|
...nextOpts.ctx
|
|
467
468
|
} : callOpts.ctx,
|
|
468
|
-
input: nextOpts && 'input' in nextOpts ? nextOpts.input : callOpts.input
|
|
469
|
+
input: nextOpts && 'input' in nextOpts ? nextOpts.input : callOpts.input,
|
|
470
|
+
rawInput: nextOpts && 'rawInput' in nextOpts ? nextOpts.rawInput : callOpts.rawInput
|
|
469
471
|
});
|
|
470
472
|
}
|
|
471
473
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -453,17 +453,19 @@ function createProcedureCaller(_def) {
|
|
|
453
453
|
ctx: callOpts.ctx,
|
|
454
454
|
type: opts.type,
|
|
455
455
|
path: opts.path,
|
|
456
|
-
rawInput: opts.rawInput,
|
|
456
|
+
rawInput: callOpts.rawInput ?? opts.rawInput,
|
|
457
457
|
meta: _def.meta,
|
|
458
458
|
input: callOpts.input,
|
|
459
|
-
next
|
|
460
|
-
|
|
459
|
+
next (_nextOpts) {
|
|
460
|
+
const nextOpts = _nextOpts;
|
|
461
|
+
return callRecursive({
|
|
461
462
|
index: callOpts.index + 1,
|
|
462
463
|
ctx: nextOpts && 'ctx' in nextOpts ? {
|
|
463
464
|
...callOpts.ctx,
|
|
464
465
|
...nextOpts.ctx
|
|
465
466
|
} : callOpts.ctx,
|
|
466
|
-
input: nextOpts && 'input' in nextOpts ? nextOpts.input : callOpts.input
|
|
467
|
+
input: nextOpts && 'input' in nextOpts ? nextOpts.input : callOpts.input,
|
|
468
|
+
rawInput: nextOpts && 'rawInput' in nextOpts ? nextOpts.rawInput : callOpts.rawInput
|
|
467
469
|
});
|
|
468
470
|
}
|
|
469
471
|
});
|
|
@@ -1,67 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var resolveHTTPResponse = require('./resolveHTTPResponse-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
async function getPostBody(opts) {
|
|
7
|
-
const { req , maxBodySize =Infinity } = opts;
|
|
8
|
-
return new Promise((resolve)=>{
|
|
9
|
-
if ('body' in req) {
|
|
10
|
-
resolve({
|
|
11
|
-
ok: true,
|
|
12
|
-
data: req.body,
|
|
13
|
-
preprocessed: true
|
|
14
|
-
});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
let body = '';
|
|
18
|
-
let hasBody = false;
|
|
19
|
-
req.on('data', function(data) {
|
|
20
|
-
body += data;
|
|
21
|
-
hasBody = true;
|
|
22
|
-
if (body.length > maxBodySize) {
|
|
23
|
-
resolve({
|
|
24
|
-
ok: false,
|
|
25
|
-
error: new TRPCError.TRPCError({
|
|
26
|
-
code: 'PAYLOAD_TOO_LARGE'
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
req.socket.destroy();
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
req.on('end', ()=>{
|
|
33
|
-
resolve({
|
|
34
|
-
ok: true,
|
|
35
|
-
data: hasBody ? body : undefined,
|
|
36
|
-
preprocessed: false
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
3
|
+
var resolveHTTPResponse = require('./resolveHTTPResponse-a7abb046.js');
|
|
4
|
+
var adapters_nodeHttp_contentType_json_index = require('./adapters/node-http/content-type/json/index.js');
|
|
41
5
|
|
|
6
|
+
const defaultJSONContentTypeHandler = adapters_nodeHttp_contentType_json_index.nodeHTTPJSONContentTypeHandler();
|
|
42
7
|
async function nodeHTTPRequestHandler(opts) {
|
|
43
|
-
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>
|
|
44
|
-
return next();
|
|
45
|
-
});
|
|
8
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
|
|
46
9
|
return handleViaMiddleware(opts.req, opts.res, async (err)=>{
|
|
47
|
-
if (err)
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
//
|
|
51
|
-
// Build tRPC dependencies
|
|
52
|
-
async function createContext() {
|
|
10
|
+
if (err) throw err;
|
|
11
|
+
const createContext = async ()=>{
|
|
53
12
|
return await opts.createContext?.(opts);
|
|
54
|
-
}
|
|
55
|
-
const bodyResult = await getPostBody(opts);
|
|
13
|
+
};
|
|
56
14
|
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
15
|
+
const jsonContentTypeHandler = defaultJSONContentTypeHandler;
|
|
16
|
+
const contentTypeHandlers = opts.experimental_contentTypeHandlers ?? [
|
|
17
|
+
jsonContentTypeHandler
|
|
18
|
+
];
|
|
19
|
+
const contentTypeHandler = contentTypeHandlers.find((handler)=>handler.isMatch({
|
|
20
|
+
...opts,
|
|
21
|
+
query
|
|
22
|
+
})) ?? // fallback to json
|
|
23
|
+
jsonContentTypeHandler;
|
|
24
|
+
const bodyResult = await contentTypeHandler.getBody({
|
|
25
|
+
...opts,
|
|
26
|
+
query
|
|
27
|
+
});
|
|
57
28
|
const req = {
|
|
58
29
|
method: opts.req.method,
|
|
59
30
|
headers: opts.req.headers,
|
|
60
31
|
query,
|
|
61
32
|
body: bodyResult.ok ? bodyResult.data : undefined
|
|
62
33
|
};
|
|
63
|
-
//
|
|
64
|
-
// Invoke tRPC
|
|
65
34
|
const result = await resolveHTTPResponse.resolveHTTPResponse({
|
|
66
35
|
batching: opts.batching,
|
|
67
36
|
responseMeta: opts.responseMeta,
|
|
@@ -76,10 +45,9 @@ async function nodeHTTPRequestHandler(opts) {
|
|
|
76
45
|
...o,
|
|
77
46
|
req: opts.req
|
|
78
47
|
});
|
|
79
|
-
}
|
|
48
|
+
},
|
|
49
|
+
contentTypeHandler
|
|
80
50
|
});
|
|
81
|
-
//
|
|
82
|
-
// Handle result
|
|
83
51
|
const { res } = opts;
|
|
84
52
|
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
85
53
|
res.statusCode = result.status;
|
|
@@ -1,62 +1,38 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from './resolveHTTPResponse-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
async function getPostBody(opts) {
|
|
5
|
-
const { req, maxBodySize = Infinity } = opts;
|
|
6
|
-
return new Promise((resolve) => {
|
|
7
|
-
if ('body' in req) {
|
|
8
|
-
resolve({ ok: true, data: req.body, preprocessed: true });
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
let body = '';
|
|
12
|
-
let hasBody = false;
|
|
13
|
-
req.on('data', function (data) {
|
|
14
|
-
body += data;
|
|
15
|
-
hasBody = true;
|
|
16
|
-
if (body.length > maxBodySize) {
|
|
17
|
-
resolve({
|
|
18
|
-
ok: false,
|
|
19
|
-
error: new TRPCError({ code: 'PAYLOAD_TOO_LARGE' }),
|
|
20
|
-
});
|
|
21
|
-
req.socket.destroy();
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
req.on('end', () => {
|
|
25
|
-
resolve({
|
|
26
|
-
ok: true,
|
|
27
|
-
data: hasBody ? body : undefined,
|
|
28
|
-
preprocessed: false,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
1
|
+
import { r as resolveHTTPResponse } from './resolveHTTPResponse-9a9f3436.js';
|
|
2
|
+
import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.js';
|
|
33
3
|
|
|
4
|
+
const defaultJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler();
|
|
34
5
|
async function nodeHTTPRequestHandler(opts) {
|
|
35
|
-
const handleViaMiddleware = opts.middleware ??
|
|
36
|
-
((_req, _res, next) => {
|
|
37
|
-
return next();
|
|
38
|
-
});
|
|
6
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next) => next());
|
|
39
7
|
return handleViaMiddleware(opts.req, opts.res, async (err) => {
|
|
40
|
-
if (err)
|
|
8
|
+
if (err)
|
|
41
9
|
throw err;
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
// Build tRPC dependencies
|
|
45
|
-
async function createContext() {
|
|
10
|
+
const createContext = async () => {
|
|
46
11
|
return await opts.createContext?.(opts);
|
|
47
|
-
}
|
|
48
|
-
const bodyResult = await getPostBody(opts);
|
|
12
|
+
};
|
|
49
13
|
const query = opts.req.query
|
|
50
14
|
? new URLSearchParams(opts.req.query)
|
|
51
15
|
: new URLSearchParams(opts.req.url.split('?')[1]);
|
|
16
|
+
const jsonContentTypeHandler = defaultJSONContentTypeHandler;
|
|
17
|
+
const contentTypeHandlers = opts.experimental_contentTypeHandlers ?? [
|
|
18
|
+
jsonContentTypeHandler,
|
|
19
|
+
];
|
|
20
|
+
const contentTypeHandler = contentTypeHandlers.find((handler) => handler.isMatch({
|
|
21
|
+
...opts,
|
|
22
|
+
query,
|
|
23
|
+
})) ??
|
|
24
|
+
// fallback to json
|
|
25
|
+
jsonContentTypeHandler;
|
|
26
|
+
const bodyResult = await contentTypeHandler.getBody({
|
|
27
|
+
...opts,
|
|
28
|
+
query,
|
|
29
|
+
});
|
|
52
30
|
const req = {
|
|
53
31
|
method: opts.req.method,
|
|
54
32
|
headers: opts.req.headers,
|
|
55
33
|
query,
|
|
56
34
|
body: bodyResult.ok ? bodyResult.data : undefined,
|
|
57
35
|
};
|
|
58
|
-
//
|
|
59
|
-
// Invoke tRPC
|
|
60
36
|
const result = await resolveHTTPResponse({
|
|
61
37
|
batching: opts.batching,
|
|
62
38
|
responseMeta: opts.responseMeta,
|
|
@@ -72,9 +48,8 @@ async function nodeHTTPRequestHandler(opts) {
|
|
|
72
48
|
req: opts.req,
|
|
73
49
|
});
|
|
74
50
|
},
|
|
51
|
+
contentTypeHandler,
|
|
75
52
|
});
|
|
76
|
-
//
|
|
77
|
-
// Handle result
|
|
78
53
|
const { res } = opts;
|
|
79
54
|
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
80
55
|
res.statusCode = result.status;
|
|
@@ -1,65 +1,34 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from './resolveHTTPResponse-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
async function getPostBody(opts) {
|
|
5
|
-
const { req , maxBodySize =Infinity } = opts;
|
|
6
|
-
return new Promise((resolve)=>{
|
|
7
|
-
if ('body' in req) {
|
|
8
|
-
resolve({
|
|
9
|
-
ok: true,
|
|
10
|
-
data: req.body,
|
|
11
|
-
preprocessed: true
|
|
12
|
-
});
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
let body = '';
|
|
16
|
-
let hasBody = false;
|
|
17
|
-
req.on('data', function(data) {
|
|
18
|
-
body += data;
|
|
19
|
-
hasBody = true;
|
|
20
|
-
if (body.length > maxBodySize) {
|
|
21
|
-
resolve({
|
|
22
|
-
ok: false,
|
|
23
|
-
error: new TRPCError({
|
|
24
|
-
code: 'PAYLOAD_TOO_LARGE'
|
|
25
|
-
})
|
|
26
|
-
});
|
|
27
|
-
req.socket.destroy();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
req.on('end', ()=>{
|
|
31
|
-
resolve({
|
|
32
|
-
ok: true,
|
|
33
|
-
data: hasBody ? body : undefined,
|
|
34
|
-
preprocessed: false
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
1
|
+
import { r as resolveHTTPResponse } from './resolveHTTPResponse-e1286cb3.mjs';
|
|
2
|
+
import { nodeHTTPJSONContentTypeHandler } from './adapters/node-http/content-type/json/index.mjs';
|
|
39
3
|
|
|
4
|
+
const defaultJSONContentTypeHandler = nodeHTTPJSONContentTypeHandler();
|
|
40
5
|
async function nodeHTTPRequestHandler(opts) {
|
|
41
|
-
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>
|
|
42
|
-
return next();
|
|
43
|
-
});
|
|
6
|
+
const handleViaMiddleware = opts.middleware ?? ((_req, _res, next)=>next());
|
|
44
7
|
return handleViaMiddleware(opts.req, opts.res, async (err)=>{
|
|
45
|
-
if (err)
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
//
|
|
49
|
-
// Build tRPC dependencies
|
|
50
|
-
async function createContext() {
|
|
8
|
+
if (err) throw err;
|
|
9
|
+
const createContext = async ()=>{
|
|
51
10
|
return await opts.createContext?.(opts);
|
|
52
|
-
}
|
|
53
|
-
const bodyResult = await getPostBody(opts);
|
|
11
|
+
};
|
|
54
12
|
const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
|
|
13
|
+
const jsonContentTypeHandler = defaultJSONContentTypeHandler;
|
|
14
|
+
const contentTypeHandlers = opts.experimental_contentTypeHandlers ?? [
|
|
15
|
+
jsonContentTypeHandler
|
|
16
|
+
];
|
|
17
|
+
const contentTypeHandler = contentTypeHandlers.find((handler)=>handler.isMatch({
|
|
18
|
+
...opts,
|
|
19
|
+
query
|
|
20
|
+
})) ?? // fallback to json
|
|
21
|
+
jsonContentTypeHandler;
|
|
22
|
+
const bodyResult = await contentTypeHandler.getBody({
|
|
23
|
+
...opts,
|
|
24
|
+
query
|
|
25
|
+
});
|
|
55
26
|
const req = {
|
|
56
27
|
method: opts.req.method,
|
|
57
28
|
headers: opts.req.headers,
|
|
58
29
|
query,
|
|
59
30
|
body: bodyResult.ok ? bodyResult.data : undefined
|
|
60
31
|
};
|
|
61
|
-
//
|
|
62
|
-
// Invoke tRPC
|
|
63
32
|
const result = await resolveHTTPResponse({
|
|
64
33
|
batching: opts.batching,
|
|
65
34
|
responseMeta: opts.responseMeta,
|
|
@@ -74,10 +43,9 @@ async function nodeHTTPRequestHandler(opts) {
|
|
|
74
43
|
...o,
|
|
75
44
|
req: opts.req
|
|
76
45
|
});
|
|
77
|
-
}
|
|
46
|
+
},
|
|
47
|
+
contentTypeHandler
|
|
78
48
|
});
|
|
79
|
-
//
|
|
80
|
-
// Handle result
|
|
81
49
|
const { res } = opts;
|
|
82
50
|
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
83
51
|
res.statusCode = result.status;
|
|
@@ -1,37 +1,19 @@
|
|
|
1
1
|
import { e as callProcedure, f as getHTTPStatusCode } from './config-2d85b8f0.js';
|
|
2
|
-
import { T as TRPCError, a as getTRPCErrorFromUnknown
|
|
2
|
+
import { T as TRPCError, a as getTRPCErrorFromUnknown } from './TRPCError-61026c9a.js';
|
|
3
3
|
import { t as transformTRPCResponse } from './transformTRPCResponse-560a1eb1.js';
|
|
4
|
+
import { g as getJsonContentTypeInputs } from './contentType-a75c990c.js';
|
|
4
5
|
|
|
5
6
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
6
7
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
7
8
|
GET: 'query',
|
|
8
9
|
POST: 'mutation',
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (req.method === 'GET') {
|
|
14
|
-
if (!req.query.has('input')) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
const raw = req.query.get('input');
|
|
18
|
-
return JSON.parse(raw);
|
|
19
|
-
}
|
|
20
|
-
if (!opts.preprocessed && typeof req.body === 'string') {
|
|
21
|
-
// A mutation with no inputs will have req.body === ''
|
|
22
|
-
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
23
|
-
}
|
|
24
|
-
return req.body;
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
throw new TRPCError({
|
|
28
|
-
code: 'PARSE_ERROR',
|
|
29
|
-
cause: getCauseFromUnknown(err),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
11
|
+
const fallbackContentTypeHandler = {
|
|
12
|
+
getInputs: getJsonContentTypeInputs,
|
|
13
|
+
};
|
|
33
14
|
async function resolveHTTPResponse(opts) {
|
|
34
15
|
const { router, req } = opts;
|
|
16
|
+
const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
|
|
35
17
|
const batchingEnabled = opts.batching?.enabled ?? true;
|
|
36
18
|
if (req.method === 'HEAD') {
|
|
37
19
|
// can be used for lambda warmup
|
|
@@ -91,42 +73,14 @@ async function resolveHTTPResponse(opts) {
|
|
|
91
73
|
code: 'METHOD_NOT_SUPPORTED',
|
|
92
74
|
});
|
|
93
75
|
}
|
|
94
|
-
const
|
|
76
|
+
const inputs = await contentTypeHandler.getInputs({
|
|
77
|
+
isBatchCall,
|
|
95
78
|
req,
|
|
96
|
-
|
|
79
|
+
router,
|
|
80
|
+
preprocessedBody: opts.preprocessedBody ?? false,
|
|
97
81
|
});
|
|
98
82
|
paths = isBatchCall ? opts.path.split(',') : [opts.path];
|
|
99
83
|
ctx = await opts.createContext();
|
|
100
|
-
const deserializeInputValue = (rawValue) => {
|
|
101
|
-
return typeof rawValue !== 'undefined'
|
|
102
|
-
? router._def._config.transformer.input.deserialize(rawValue)
|
|
103
|
-
: rawValue;
|
|
104
|
-
};
|
|
105
|
-
const getInputs = () => {
|
|
106
|
-
if (!isBatchCall) {
|
|
107
|
-
return {
|
|
108
|
-
0: deserializeInputValue(rawInput),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
/* istanbul ignore if -- @preserve */
|
|
112
|
-
if (rawInput == null ||
|
|
113
|
-
typeof rawInput !== 'object' ||
|
|
114
|
-
Array.isArray(rawInput)) {
|
|
115
|
-
throw new TRPCError({
|
|
116
|
-
code: 'BAD_REQUEST',
|
|
117
|
-
message: '"input" needs to be an object when doing a batch call',
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const input = {};
|
|
121
|
-
for (const key in rawInput) {
|
|
122
|
-
const k = key;
|
|
123
|
-
const rawValue = rawInput[k];
|
|
124
|
-
const value = deserializeInputValue(rawValue);
|
|
125
|
-
input[k] = value;
|
|
126
|
-
}
|
|
127
|
-
return input;
|
|
128
|
-
};
|
|
129
|
-
const inputs = getInputs();
|
|
130
84
|
const rawResults = await Promise.all(paths.map(async (path, index) => {
|
|
131
85
|
const input = inputs[index];
|
|
132
86
|
try {
|
|
@@ -3,35 +3,18 @@
|
|
|
3
3
|
var config = require('./config-e6e74385.js');
|
|
4
4
|
var TRPCError = require('./TRPCError-16b2e52d.js');
|
|
5
5
|
var transformTRPCResponse = require('./transformTRPCResponse-8afb9a5c.js');
|
|
6
|
+
var contentType = require('./contentType-8356d528.js');
|
|
6
7
|
|
|
7
8
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
8
9
|
GET: 'query',
|
|
9
10
|
POST: 'mutation'
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (req.method === 'GET') {
|
|
15
|
-
if (!req.query.has('input')) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
const raw = req.query.get('input');
|
|
19
|
-
return JSON.parse(raw);
|
|
20
|
-
}
|
|
21
|
-
if (!opts.preprocessed && typeof req.body === 'string') {
|
|
22
|
-
// A mutation with no inputs will have req.body === ''
|
|
23
|
-
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
24
|
-
}
|
|
25
|
-
return req.body;
|
|
26
|
-
} catch (err) {
|
|
27
|
-
throw new TRPCError.TRPCError({
|
|
28
|
-
code: 'PARSE_ERROR',
|
|
29
|
-
cause: TRPCError.getCauseFromUnknown(err)
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
12
|
+
const fallbackContentTypeHandler = {
|
|
13
|
+
getInputs: contentType.getJsonContentTypeInputs
|
|
14
|
+
};
|
|
33
15
|
async function resolveHTTPResponse(opts) {
|
|
34
16
|
const { router , req } = opts;
|
|
17
|
+
const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
|
|
35
18
|
const batchingEnabled = opts.batching?.enabled ?? true;
|
|
36
19
|
if (req.method === 'HEAD') {
|
|
37
20
|
// can be used for lambda warmup
|
|
@@ -90,39 +73,16 @@ async function resolveHTTPResponse(opts) {
|
|
|
90
73
|
code: 'METHOD_NOT_SUPPORTED'
|
|
91
74
|
});
|
|
92
75
|
}
|
|
93
|
-
const
|
|
76
|
+
const inputs = await contentTypeHandler.getInputs({
|
|
77
|
+
isBatchCall,
|
|
94
78
|
req,
|
|
95
|
-
|
|
79
|
+
router,
|
|
80
|
+
preprocessedBody: opts.preprocessedBody ?? false
|
|
96
81
|
});
|
|
97
82
|
paths = isBatchCall ? opts.path.split(',') : [
|
|
98
83
|
opts.path
|
|
99
84
|
];
|
|
100
85
|
ctx = await opts.createContext();
|
|
101
|
-
const deserializeInputValue = (rawValue)=>{
|
|
102
|
-
return typeof rawValue !== 'undefined' ? router._def._config.transformer.input.deserialize(rawValue) : rawValue;
|
|
103
|
-
};
|
|
104
|
-
const getInputs = ()=>{
|
|
105
|
-
if (!isBatchCall) {
|
|
106
|
-
return {
|
|
107
|
-
0: deserializeInputValue(rawInput)
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/* istanbul ignore if -- @preserve */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
111
|
-
throw new TRPCError.TRPCError({
|
|
112
|
-
code: 'BAD_REQUEST',
|
|
113
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const input = {};
|
|
117
|
-
for(const key in rawInput){
|
|
118
|
-
const k = key;
|
|
119
|
-
const rawValue = rawInput[k];
|
|
120
|
-
const value = deserializeInputValue(rawValue);
|
|
121
|
-
input[k] = value;
|
|
122
|
-
}
|
|
123
|
-
return input;
|
|
124
|
-
};
|
|
125
|
-
const inputs = getInputs();
|
|
126
86
|
const rawResults = await Promise.all(paths.map(async (path, index)=>{
|
|
127
87
|
const input = inputs[index];
|
|
128
88
|
try {
|
|
@@ -1,35 +1,18 @@
|
|
|
1
1
|
import { e as callProcedure, f as getHTTPStatusCode } from './config-f0387de5.mjs';
|
|
2
|
-
import { T as TRPCError, a as getTRPCErrorFromUnknown
|
|
2
|
+
import { T as TRPCError, a as getTRPCErrorFromUnknown } from './TRPCError-2b10c8d2.mjs';
|
|
3
3
|
import { t as transformTRPCResponse } from './transformTRPCResponse-0ea8c0ca.mjs';
|
|
4
|
+
import { g as getJsonContentTypeInputs } from './contentType-acc3be52.mjs';
|
|
4
5
|
|
|
5
6
|
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
6
7
|
GET: 'query',
|
|
7
8
|
POST: 'mutation'
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (req.method === 'GET') {
|
|
13
|
-
if (!req.query.has('input')) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const raw = req.query.get('input');
|
|
17
|
-
return JSON.parse(raw);
|
|
18
|
-
}
|
|
19
|
-
if (!opts.preprocessed && typeof req.body === 'string') {
|
|
20
|
-
// A mutation with no inputs will have req.body === ''
|
|
21
|
-
return req.body.length === 0 ? undefined : JSON.parse(req.body);
|
|
22
|
-
}
|
|
23
|
-
return req.body;
|
|
24
|
-
} catch (err) {
|
|
25
|
-
throw new TRPCError({
|
|
26
|
-
code: 'PARSE_ERROR',
|
|
27
|
-
cause: getCauseFromUnknown(err)
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
10
|
+
const fallbackContentTypeHandler = {
|
|
11
|
+
getInputs: getJsonContentTypeInputs
|
|
12
|
+
};
|
|
31
13
|
async function resolveHTTPResponse(opts) {
|
|
32
14
|
const { router , req } = opts;
|
|
15
|
+
const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
|
|
33
16
|
const batchingEnabled = opts.batching?.enabled ?? true;
|
|
34
17
|
if (req.method === 'HEAD') {
|
|
35
18
|
// can be used for lambda warmup
|
|
@@ -88,39 +71,16 @@ async function resolveHTTPResponse(opts) {
|
|
|
88
71
|
code: 'METHOD_NOT_SUPPORTED'
|
|
89
72
|
});
|
|
90
73
|
}
|
|
91
|
-
const
|
|
74
|
+
const inputs = await contentTypeHandler.getInputs({
|
|
75
|
+
isBatchCall,
|
|
92
76
|
req,
|
|
93
|
-
|
|
77
|
+
router,
|
|
78
|
+
preprocessedBody: opts.preprocessedBody ?? false
|
|
94
79
|
});
|
|
95
80
|
paths = isBatchCall ? opts.path.split(',') : [
|
|
96
81
|
opts.path
|
|
97
82
|
];
|
|
98
83
|
ctx = await opts.createContext();
|
|
99
|
-
const deserializeInputValue = (rawValue)=>{
|
|
100
|
-
return typeof rawValue !== 'undefined' ? router._def._config.transformer.input.deserialize(rawValue) : rawValue;
|
|
101
|
-
};
|
|
102
|
-
const getInputs = ()=>{
|
|
103
|
-
if (!isBatchCall) {
|
|
104
|
-
return {
|
|
105
|
-
0: deserializeInputValue(rawInput)
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/* istanbul ignore if -- @preserve */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
|
|
109
|
-
throw new TRPCError({
|
|
110
|
-
code: 'BAD_REQUEST',
|
|
111
|
-
message: '"input" needs to be an object when doing a batch call'
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
const input = {};
|
|
115
|
-
for(const key in rawInput){
|
|
116
|
-
const k = key;
|
|
117
|
-
const rawValue = rawInput[k];
|
|
118
|
-
const value = deserializeInputValue(rawValue);
|
|
119
|
-
input[k] = value;
|
|
120
|
-
}
|
|
121
|
-
return input;
|
|
122
|
-
};
|
|
123
|
-
const inputs = getInputs();
|
|
124
84
|
const rawResults = await Promise.all(paths.map(async (path, index)=>{
|
|
125
85
|
const input = inputs[index];
|
|
126
86
|
try {
|