@trpc/server 10.13.2 → 10.14.1
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/LICENSE +2 -2
- package/adapters/zodFileSchema/index.d.ts +1 -0
- package/adapters/zodFileSchema/index.js +1 -0
- package/dist/{TRPCError-e7333eae.mjs → TRPCError-226f5343.mjs} +5 -10
- package/dist/{TRPCError-ed16b3b7.js → TRPCError-92d93cfd.js} +5 -10
- package/dist/{TRPCError-4cbab0d0.js → TRPCError-98f26ad6.js} +5 -10
- package/dist/adapters/aws-lambda/index.js +7 -3
- package/dist/adapters/aws-lambda/index.mjs +7 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/express.js +4 -4
- package/dist/adapters/express.mjs +4 -4
- package/dist/adapters/fastify/index.js +3 -3
- package/dist/adapters/fastify/index.mjs +3 -3
- package/dist/adapters/fetch/index.js +3 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/next.js +4 -4
- package/dist/adapters/next.mjs +4 -4
- package/dist/adapters/node-http/index.js +4 -4
- package/dist/adapters/node-http/index.mjs +4 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/types.d.ts +23 -0
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.js +4 -4
- package/dist/adapters/standalone.mjs +4 -4
- package/dist/adapters/ws.js +2 -2
- package/dist/adapters/ws.mjs +2 -2
- package/dist/{config-bd759464.js → config-046e82fc.js} +1 -1
- package/dist/{config-fb5f49a1.mjs → config-61d48858.mjs} +1 -1
- package/dist/{config-69ee2314.js → config-cac4535e.js} +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/error/TRPCError.d.ts +1 -1
- package/dist/error/TRPCError.d.ts.map +1 -1
- package/dist/http/index.js +3 -3
- package/dist/http/index.mjs +3 -3
- package/dist/index.js +2 -2
- package/dist/index.mjs +4 -4
- package/dist/nodeHTTPRequestHandler-0f439ec3.js +90 -0
- package/dist/nodeHTTPRequestHandler-41accae1.mjs +92 -0
- package/dist/nodeHTTPRequestHandler-4f981ca6.js +94 -0
- package/dist/{resolveHTTPResponse-cbfdc43d.js → resolveHTTPResponse-4798ae79.js} +2 -2
- package/dist/{resolveHTTPResponse-8e9dd846.mjs → resolveHTTPResponse-5c43d189.mjs} +2 -2
- package/dist/{resolveHTTPResponse-39258d19.js → resolveHTTPResponse-ef105097.js} +2 -2
- package/dist/subscription.js +1 -1
- package/dist/subscription.mjs +1 -1
- package/package.json +3 -2
- package/src/adapters/aws-lambda/utils.ts +4 -0
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +64 -41
- package/src/adapters/node-http/types.ts +27 -0
- package/src/core/index.ts +1 -0
- package/src/error/TRPCError.ts +8 -13
- package/dist/nodeHTTPRequestHandler-40bc6a18.js +0 -81
- package/dist/nodeHTTPRequestHandler-4314fa32.mjs +0 -79
- package/dist/nodeHTTPRequestHandler-93528c16.js +0 -76
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { r as resolveHTTPResponse } from './resolveHTTPResponse-39258d19.js';
|
|
2
|
-
import { T as TRPCError } from './TRPCError-ed16b3b7.js';
|
|
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 });
|
|
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
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function nodeHTTPRequestHandler(opts) {
|
|
34
|
-
const createContext = async function _createContext() {
|
|
35
|
-
return await opts.createContext?.(opts);
|
|
36
|
-
};
|
|
37
|
-
const { path, router } = opts;
|
|
38
|
-
const bodyResult = await getPostBody(opts);
|
|
39
|
-
const query = opts.req.query
|
|
40
|
-
? new URLSearchParams(opts.req.query)
|
|
41
|
-
: new URLSearchParams(opts.req.url.split('?')[1]);
|
|
42
|
-
const req = {
|
|
43
|
-
method: opts.req.method,
|
|
44
|
-
headers: opts.req.headers,
|
|
45
|
-
query,
|
|
46
|
-
body: bodyResult.ok ? bodyResult.data : undefined,
|
|
47
|
-
};
|
|
48
|
-
const result = await resolveHTTPResponse({
|
|
49
|
-
batching: opts.batching,
|
|
50
|
-
responseMeta: opts.responseMeta,
|
|
51
|
-
path,
|
|
52
|
-
createContext,
|
|
53
|
-
router,
|
|
54
|
-
req,
|
|
55
|
-
error: bodyResult.ok ? null : bodyResult.error,
|
|
56
|
-
onError(o) {
|
|
57
|
-
opts?.onError?.({
|
|
58
|
-
...o,
|
|
59
|
-
req: opts.req,
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
const { res } = opts;
|
|
64
|
-
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
65
|
-
res.statusCode = result.status;
|
|
66
|
-
}
|
|
67
|
-
for (const [key, value] of Object.entries(result.headers ?? {})) {
|
|
68
|
-
if (typeof value === 'undefined') {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
res.setHeader(key, value);
|
|
72
|
-
}
|
|
73
|
-
res.end(result.body);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export { nodeHTTPRequestHandler as n };
|