@trpc/server 11.18.1-canary.9 → 11.19.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.cjs +16 -26
- package/dist/adapters/aws-lambda/index.d.cts +6 -16
- package/dist/adapters/aws-lambda/index.d.cts.map +1 -1
- package/dist/adapters/aws-lambda/index.d.mts +6 -16
- package/dist/adapters/aws-lambda/index.d.mts.map +1 -1
- package/dist/adapters/aws-lambda/index.mjs +13 -23
- package/dist/adapters/aws-lambda/index.mjs.map +1 -1
- package/dist/adapters/express.cjs +7 -16
- package/dist/adapters/express.d.cts +4 -11
- package/dist/adapters/express.d.cts.map +1 -1
- package/dist/adapters/express.d.mts +4 -11
- package/dist/adapters/express.d.mts.map +1 -1
- package/dist/adapters/express.mjs +6 -15
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/fastify/index.cjs +11 -24
- package/dist/adapters/fastify/index.d.cts +7 -14
- package/dist/adapters/fastify/index.d.cts.map +1 -1
- package/dist/adapters/fastify/index.d.mts +7 -14
- package/dist/adapters/fastify/index.d.mts.map +1 -1
- package/dist/adapters/fastify/index.mjs +10 -23
- package/dist/adapters/fastify/index.mjs.map +1 -1
- package/dist/adapters/fetch/index.cjs +7 -12
- package/dist/adapters/fetch/index.d.cts +7 -15
- package/dist/adapters/fetch/index.d.cts.map +1 -1
- package/dist/adapters/fetch/index.d.mts +7 -15
- package/dist/adapters/fetch/index.d.mts.map +1 -1
- package/dist/adapters/fetch/index.mjs +6 -11
- package/dist/adapters/fetch/index.mjs.map +1 -1
- package/dist/adapters/next-app-dir.cjs +13 -3145
- package/dist/adapters/next-app-dir.d.cts +3 -12
- package/dist/adapters/next-app-dir.d.cts.map +1 -1
- package/dist/adapters/next-app-dir.d.mts +3 -12
- package/dist/adapters/next-app-dir.d.mts.map +1 -1
- package/dist/adapters/next-app-dir.mjs +31 -3165
- package/dist/adapters/next-app-dir.mjs.map +1 -1
- package/dist/adapters/next.cjs +8 -16
- package/dist/adapters/next.d.cts +5 -15
- package/dist/adapters/next.d.cts.map +1 -1
- package/dist/adapters/next.d.mts +5 -15
- package/dist/adapters/next.d.mts.map +1 -1
- package/dist/adapters/next.mjs +7 -15
- package/dist/adapters/next.mjs.map +1 -1
- package/dist/adapters/node-http/index.cjs +3 -12
- package/dist/adapters/node-http/index.d.cts +1 -4
- package/dist/adapters/node-http/index.d.mts +1 -4
- package/dist/adapters/node-http/index.mjs +2 -12
- package/dist/adapters/standalone.cjs +21 -21
- package/dist/adapters/standalone.d.cts +9 -14
- package/dist/adapters/standalone.d.cts.map +1 -1
- package/dist/adapters/standalone.d.mts +9 -14
- package/dist/adapters/standalone.d.mts.map +1 -1
- package/dist/adapters/standalone.mjs +17 -19
- package/dist/adapters/standalone.mjs.map +1 -1
- package/dist/adapters/ws.cjs +3 -15
- package/dist/adapters/ws.d.cts +12 -17
- package/dist/adapters/ws.d.cts.map +1 -1
- package/dist/adapters/ws.d.mts +12 -17
- package/dist/adapters/ws.d.mts.map +1 -1
- package/dist/adapters/ws.mjs +2 -15
- package/dist/{codes-BfZsPdy-.cjs → codes-C6ZIq69A.cjs} +78 -74
- package/dist/{codes-DagpWZLc.mjs → codes-D5Ya6_Bi.mjs} +10 -4
- package/dist/codes-D5Ya6_Bi.mjs.map +1 -0
- package/dist/{contentTypeParsers-iAFF_pJG.cjs → contentTypeParsers-DUzXRHT1.cjs} +6 -8
- package/dist/{contentTypeParsers-SN4WL9ze.mjs → contentTypeParsers-KFMy_fwz.mjs} +3 -3
- package/dist/contentTypeParsers-KFMy_fwz.mjs.map +1 -0
- package/dist/getErrorShape-B0JBUs-i.mjs +209 -0
- package/dist/getErrorShape-B0JBUs-i.mjs.map +1 -0
- package/dist/getErrorShape-DeIapApr.cjs +272 -0
- package/dist/http.cjs +5 -9
- package/dist/http.d.cts +2 -3
- package/dist/http.d.mts +2 -3
- package/dist/http.mjs +4 -9
- package/dist/{index.d-DhhodpGb.d.mts → index-BHatz_Pu.d.cts} +3 -8
- package/dist/index-BHatz_Pu.d.cts.map +1 -0
- package/dist/{index.d-BiUz7kM_.d.cts → index-BMimGNYb.d.cts} +2 -5
- package/dist/index-BMimGNYb.d.cts.map +1 -0
- package/dist/{index.d-D4qZxQJh.d.mts → index-BMimGNYb.d.mts} +2 -5
- package/dist/index-BMimGNYb.d.mts.map +1 -0
- package/dist/{index.d-fBAdSX6g.d.cts → index-_jAhoJQ7.d.mts} +3 -8
- package/dist/index-_jAhoJQ7.d.mts.map +1 -0
- package/dist/index.cjs +5 -6
- package/dist/index.d.cts +10 -4
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +10 -4
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -6
- package/dist/{initTRPC-BRf4imah.mjs → initTRPC-B259os3T.mjs} +85 -83
- package/dist/initTRPC-B259os3T.mjs.map +1 -0
- package/dist/{initTRPC-_cqIfGlH.cjs → initTRPC-B7UdX-c3.cjs} +133 -132
- package/dist/{node-http-n0vBVXjb.mjs → node-http-BUlb5EdB.mjs} +29 -26
- package/dist/node-http-BUlb5EdB.mjs.map +1 -0
- package/dist/{node-http-CSXWJkwC.cjs → node-http-CikCqjt6.cjs} +48 -46
- package/dist/observable/index.cjs +4 -4
- package/dist/observable/index.d.cts +2 -2
- package/dist/observable/index.d.mts +2 -2
- package/dist/observable/index.mjs +3 -4
- package/dist/{observable-B1Nk6r1H.cjs → observable-CIyO2eSm.cjs} +28 -32
- package/dist/{observable-CUiPknO-.mjs → observable-CSprJVOf.mjs} +6 -10
- package/dist/observable-CSprJVOf.mjs.map +1 -0
- package/dist/{observable-BVzLuBs6.cjs → observable-D8mqXlHG.cjs} +34 -39
- package/dist/{observable-UMO3vUa_.mjs → observable-DwUFSuKv.mjs} +10 -12
- package/dist/observable-DwUFSuKv.mjs.map +1 -0
- package/dist/{parseTRPCMessage-D1ZZaDox.cjs → parseTRPCMessage-BxAIUx49.cjs} +13 -17
- package/dist/{parseTRPCMessage-CPM1-44n.mjs → parseTRPCMessage-MJWDg1vX.mjs} +5 -8
- package/dist/parseTRPCMessage-MJWDg1vX.mjs.map +1 -0
- package/dist/{resolveResponse-Djb7nJqb.cjs → resolveResponse-DLpzHrPG.cjs} +505 -583
- package/dist/{resolveResponse-C7cFScHo.mjs → resolveResponse-JtMyT9TQ.mjs} +412 -489
- package/dist/resolveResponse-JtMyT9TQ.mjs.map +1 -0
- package/dist/rolldown-runtime-VH7oDXx4.cjs +28 -0
- package/dist/rpc.cjs +4 -4
- package/dist/rpc.d.cts +2 -3
- package/dist/rpc.d.mts +2 -3
- package/dist/rpc.mjs +3 -4
- package/dist/shared.cjs +3 -4
- package/dist/shared.d.cts +2 -4
- package/dist/shared.d.mts +2 -4
- package/dist/shared.mjs +2 -4
- package/dist/{tracked-DFxm8M2u.cjs → tracked-BQJb0ANk.cjs} +125 -142
- package/dist/{tracked-DWInO6EQ.mjs → tracked-D4jU_Hb3.mjs} +42 -58
- package/dist/tracked-D4jU_Hb3.mjs.map +1 -0
- package/dist/{unstable-core-do-not-import.d-BdVSvUCr.d.mts → unstable-core-do-not-import-B9ZnrQAU.d.cts} +37 -69
- package/dist/unstable-core-do-not-import-B9ZnrQAU.d.cts.map +1 -0
- package/dist/{unstable-core-do-not-import.d-Dh9CT5RO.d.cts → unstable-core-do-not-import-BK_OKrtM.d.mts} +37 -69
- package/dist/unstable-core-do-not-import-BK_OKrtM.d.mts.map +1 -0
- package/dist/unstable-core-do-not-import.cjs +33 -12
- package/dist/unstable-core-do-not-import.d.cts +2 -3
- package/dist/unstable-core-do-not-import.d.mts +2 -3
- package/dist/unstable-core-do-not-import.mjs +32 -10
- package/dist/unstable-core-do-not-import.mjs.map +1 -0
- package/dist/{ws-DCe9kEo_.cjs → ws-BMSSVFiW.cjs} +59 -65
- package/dist/{ws-Bme8aJNK.mjs → ws-C7ZOJJeA.mjs} +41 -46
- package/dist/ws-C7ZOJJeA.mjs.map +1 -0
- package/package.json +13 -13
- package/src/adapters/aws-lambda/getPlanner.ts +1 -2
- package/src/adapters/aws-lambda/index.ts +1 -2
- package/src/adapters/ws.ts +3 -2
- package/src/adapters/wsEncoder.ts +1 -1
- package/src/observable/behaviorSubject.ts +4 -2
- package/src/observable/types.ts +4 -2
- package/src/unstable-core-do-not-import/clientish/inferrable.ts +1 -4
- package/src/unstable-core-do-not-import/http/contentType.ts +1 -1
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +4 -9
- package/src/unstable-core-do-not-import/http/types.ts +8 -4
- package/src/unstable-core-do-not-import/initTRPC.ts +10 -10
- package/src/unstable-core-do-not-import/middleware.ts +3 -2
- package/src/unstable-core-do-not-import/procedure.ts +11 -11
- package/src/unstable-core-do-not-import/router.ts +4 -5
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +33 -34
- package/src/unstable-core-do-not-import/stream/jsonl.ts +1 -2
- package/src/unstable-core-do-not-import/stream/sse.ts +18 -12
- package/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts +5 -2
- package/src/unstable-core-do-not-import/stream/utils/withPing.ts +1 -3
- package/src/unstable-core-do-not-import/transformer.ts +1 -4
- package/src/unstable-core-do-not-import/types.ts +9 -10
- package/dist/codes-DagpWZLc.mjs.map +0 -1
- package/dist/contentTypeParsers-SN4WL9ze.mjs.map +0 -1
- package/dist/getErrorShape-BPSzUA7W.mjs +0 -269
- package/dist/getErrorShape-BPSzUA7W.mjs.map +0 -1
- package/dist/getErrorShape-Ed1OwssN.cjs +0 -345
- package/dist/http-CWyjOa1l.mjs +0 -0
- package/dist/http-DXy3XyhL.cjs +0 -0
- package/dist/index.d-BiUz7kM_.d.cts.map +0 -1
- package/dist/index.d-CvZXeEyR.d.cts +0 -11
- package/dist/index.d-CvZXeEyR.d.cts.map +0 -1
- package/dist/index.d-D4qZxQJh.d.mts.map +0 -1
- package/dist/index.d-DhhodpGb.d.mts.map +0 -1
- package/dist/index.d-fBAdSX6g.d.cts.map +0 -1
- package/dist/index.d-vq_QHko2.d.mts +0 -11
- package/dist/index.d-vq_QHko2.d.mts.map +0 -1
- package/dist/initTRPC-BRf4imah.mjs.map +0 -1
- package/dist/node-http-n0vBVXjb.mjs.map +0 -1
- package/dist/observable-CUiPknO-.mjs.map +0 -1
- package/dist/observable-UMO3vUa_.mjs.map +0 -1
- package/dist/parseTRPCMessage-CPM1-44n.mjs.map +0 -1
- package/dist/resolveResponse-C7cFScHo.mjs.map +0 -1
- package/dist/tracked-DWInO6EQ.mjs.map +0 -1
- package/dist/unstable-core-do-not-import-9NNw8uQM.mjs +0 -31
- package/dist/unstable-core-do-not-import-9NNw8uQM.mjs.map +0 -1
- package/dist/unstable-core-do-not-import-fsjhEhgh.cjs +0 -35
- package/dist/unstable-core-do-not-import.d-BdVSvUCr.d.mts.map +0 -1
- package/dist/unstable-core-do-not-import.d-Dh9CT5RO.d.cts.map +0 -1
- package/dist/ws-Bme8aJNK.mjs.map +0 -1
|
@@ -1,42 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
require(
|
|
4
|
-
require(
|
|
5
|
-
const
|
|
6
|
-
require('../../contentTypeParsers-iAFF_pJG.cjs');
|
|
7
|
-
require('../../unstable-core-do-not-import-fsjhEhgh.cjs');
|
|
8
|
-
require('../../observable-B1Nk6r1H.cjs');
|
|
9
|
-
require('../../initTRPC-_cqIfGlH.cjs');
|
|
10
|
-
require('../../http-DXy3XyhL.cjs');
|
|
11
|
-
const require_node_http = require('../../node-http-CSXWJkwC.cjs');
|
|
12
|
-
require('../../observable-BVzLuBs6.cjs');
|
|
13
|
-
const require_ws = require('../../ws-DCe9kEo_.cjs');
|
|
14
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_getErrorShape = require("../../getErrorShape-DeIapApr.cjs");
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-DLpzHrPG.cjs");
|
|
4
|
+
const require_node_http = require("../../node-http-CikCqjt6.cjs");
|
|
5
|
+
const require_ws = require("../../ws-BMSSVFiW.cjs");
|
|
15
6
|
//#region src/adapters/fastify/fastifyRequestHandler.ts
|
|
16
|
-
var import_objectSpread2$1 = require_getErrorShape.__toESM(require_getErrorShape.require_objectSpread2(), 1);
|
|
17
7
|
async function fastifyRequestHandler(opts) {
|
|
18
8
|
const createContext = async (innerOpts) => {
|
|
19
9
|
var _opts$createContext;
|
|
20
|
-
return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts,
|
|
10
|
+
return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, opts), innerOpts)));
|
|
21
11
|
};
|
|
22
12
|
const incomingMessage = opts.req.raw;
|
|
23
13
|
if ("body" in opts.req) incomingMessage.body = opts.req.body;
|
|
24
14
|
const req = require_node_http.incomingMessageToRequest(incomingMessage, opts.res.raw, { maxBodySize: null });
|
|
25
|
-
const res = await require_resolveResponse.resolveResponse(
|
|
15
|
+
const res = await require_resolveResponse.resolveResponse(require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, opts), {}, {
|
|
26
16
|
req,
|
|
27
17
|
error: null,
|
|
28
18
|
createContext,
|
|
29
19
|
onError(o) {
|
|
30
20
|
var _opts$onError;
|
|
31
|
-
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts,
|
|
21
|
+
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, o), {}, { req: opts.req }));
|
|
32
22
|
}
|
|
33
23
|
}));
|
|
34
24
|
await opts.res.send(res);
|
|
35
25
|
}
|
|
36
|
-
|
|
37
26
|
//#endregion
|
|
38
27
|
//#region src/adapters/fastify/fastifyTRPCPlugin.ts
|
|
39
|
-
var import_objectSpread2 = require_getErrorShape.__toESM(require_getErrorShape.require_objectSpread2(), 1);
|
|
40
28
|
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
41
29
|
var _opts$prefix;
|
|
42
30
|
fastify.removeContentTypeParser("application/json");
|
|
@@ -51,7 +39,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
51
39
|
if (typeof fastifyTRPCPlugin.default !== "function") prefix = "";
|
|
52
40
|
fastify.all(`${prefix}/:path`, async (req, res) => {
|
|
53
41
|
const path = req.params.path;
|
|
54
|
-
await fastifyRequestHandler(
|
|
42
|
+
await fastifyRequestHandler(require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, opts.trpcOptions), {}, {
|
|
55
43
|
req,
|
|
56
44
|
res,
|
|
57
45
|
path
|
|
@@ -60,7 +48,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
60
48
|
if (opts.useWSS) {
|
|
61
49
|
var _prefix;
|
|
62
50
|
const trpcOptions = opts.trpcOptions;
|
|
63
|
-
const onConnection = require_ws.getWSConnectionHandler(
|
|
51
|
+
const onConnection = require_ws.getWSConnectionHandler(require_getErrorShape._objectSpread2({}, trpcOptions));
|
|
64
52
|
fastify.get((_prefix = prefix) !== null && _prefix !== void 0 ? _prefix : "/", { websocket: true }, (socket, req) => {
|
|
65
53
|
var _trpcOptions$keepAliv;
|
|
66
54
|
onConnection(socket, req.raw);
|
|
@@ -72,7 +60,6 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
72
60
|
}
|
|
73
61
|
done();
|
|
74
62
|
}
|
|
75
|
-
|
|
76
63
|
//#endregion
|
|
77
64
|
exports.fastifyRequestHandler = fastifyRequestHandler;
|
|
78
|
-
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
65
|
+
exports.fastifyTRPCPlugin = fastifyTRPCPlugin;
|
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import {
|
|
3
|
-
import "../../index.d-CvZXeEyR.cjs";
|
|
4
|
-
import { NodeHTTPCreateContextFnOptions, NodeHTTPCreateContextOption } from "../../index.d-fBAdSX6g.cjs";
|
|
1
|
+
import { J as AnyRouter, _n as HTTPBaseHandlerOptions } from "../../unstable-core-do-not-import-B9ZnrQAU.cjs";
|
|
2
|
+
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-BHatz_Pu.cjs";
|
|
5
3
|
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
6
|
-
|
|
7
4
|
//#region src/adapters/fastify/fastifyRequestHandler.d.ts
|
|
8
|
-
|
|
9
|
-
type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
5
|
+
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
10
6
|
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
11
7
|
req: TRequest;
|
|
12
8
|
res: TResponse;
|
|
13
9
|
path: string;
|
|
14
10
|
};
|
|
15
|
-
declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
11
|
+
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
16
12
|
//#endregion
|
|
17
13
|
//#region src/adapters/fastify/fastifyTRPCPlugin.d.ts
|
|
18
|
-
interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
14
|
+
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
19
15
|
prefix?: string;
|
|
20
16
|
useWSS?: boolean;
|
|
21
17
|
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;
|
|
22
18
|
}
|
|
23
|
-
type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
24
|
-
declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
25
|
-
//# sourceMappingURL=fastifyTRPCPlugin.d.ts.map
|
|
26
|
-
|
|
19
|
+
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
20
|
+
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
27
21
|
//#endregion
|
|
28
|
-
export { CreateFastifyContextOptions, FastifyHandlerOptions, FastifyTRPCPluginOptions, fastifyRequestHandler, fastifyTRPCPlugin };
|
|
29
22
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"mappings":";;;;YAyBY,sBACV,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,gBAChB,uBAAuB,SAAS,YAClC,4BAA4B,SAAS,UAAU;KAE5C,6BACH,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,gBAChB,sBAAsB,SAAS,UAAU;EAC3C,KAAK;EACL,KAAK;EACL;;wBAGoB,sBACpB,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,cAClB,MAAM,6BAA6B,SAAS,UAAU,aAAU;;;iBCtBjD,yBAAyB,gBAAgB;EACxD;EACA;EACA,aAAa,sBAAsB,SAAS,gBAAgB;;YAGlD,8BAA8B,+BACxC,gBACA;wBAGc,kBAAkB,gBAAgB,WAChD,SAAS,iBACT,MAAM,yBAAyB,UAC/B,OAAO,MAAM"}
|
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import {
|
|
3
|
-
import "../../index.d-vq_QHko2.mjs";
|
|
4
|
-
import { NodeHTTPCreateContextFnOptions, NodeHTTPCreateContextOption } from "../../index.d-DhhodpGb.mjs";
|
|
1
|
+
import { J as AnyRouter, _n as HTTPBaseHandlerOptions } from "../../unstable-core-do-not-import-BK_OKrtM.mjs";
|
|
2
|
+
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-_jAhoJQ7.mjs";
|
|
5
3
|
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
6
|
-
|
|
7
4
|
//#region src/adapters/fastify/fastifyRequestHandler.d.ts
|
|
8
|
-
|
|
9
|
-
type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
5
|
+
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
10
6
|
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
11
7
|
req: TRequest;
|
|
12
8
|
res: TResponse;
|
|
13
9
|
path: string;
|
|
14
10
|
};
|
|
15
|
-
declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
11
|
+
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
16
12
|
//#endregion
|
|
17
13
|
//#region src/adapters/fastify/fastifyTRPCPlugin.d.ts
|
|
18
|
-
interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
14
|
+
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
19
15
|
prefix?: string;
|
|
20
16
|
useWSS?: boolean;
|
|
21
17
|
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;
|
|
22
18
|
}
|
|
23
|
-
type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
24
|
-
declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
25
|
-
//# sourceMappingURL=fastifyTRPCPlugin.d.ts.map
|
|
26
|
-
|
|
19
|
+
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
20
|
+
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
27
21
|
//#endregion
|
|
28
|
-
export { CreateFastifyContextOptions, FastifyHandlerOptions, FastifyTRPCPluginOptions, fastifyRequestHandler, fastifyTRPCPlugin };
|
|
29
22
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"mappings":";;;;YAyBY,sBACV,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,gBAChB,uBAAuB,SAAS,YAClC,4BAA4B,SAAS,UAAU;KAE5C,6BACH,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,gBAChB,sBAAsB,SAAS,UAAU;EAC3C,KAAK;EACL,KAAK;EACL;;wBAGoB,sBACpB,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,cAClB,MAAM,6BAA6B,SAAS,UAAU,aAAU;;;iBCtBjD,yBAAyB,gBAAgB;EACxD;EACA;EACA,aAAa,sBAAsB,SAAS,gBAAgB;;YAGlD,8BAA8B,+BACxC,gBACA;wBAGc,kBAAkB,gBAAgB,WAChD,SAAS,iBACT,MAAM,yBAAyB,UAC/B,OAAO,MAAM"}
|
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../../
|
|
3
|
-
import "../../
|
|
4
|
-
import "../../
|
|
5
|
-
import { resolveResponse } from "../../resolveResponse-C7cFScHo.mjs";
|
|
6
|
-
import "../../contentTypeParsers-SN4WL9ze.mjs";
|
|
7
|
-
import "../../unstable-core-do-not-import-9NNw8uQM.mjs";
|
|
8
|
-
import "../../observable-UMO3vUa_.mjs";
|
|
9
|
-
import "../../initTRPC-BRf4imah.mjs";
|
|
10
|
-
import "../../http-CWyjOa1l.mjs";
|
|
11
|
-
import { incomingMessageToRequest } from "../../node-http-n0vBVXjb.mjs";
|
|
12
|
-
import "../../observable-CUiPknO-.mjs";
|
|
13
|
-
import { getWSConnectionHandler, handleKeepAlive } from "../../ws-Bme8aJNK.mjs";
|
|
14
|
-
|
|
1
|
+
import { n as _objectSpread2 } from "../../getErrorShape-B0JBUs-i.mjs";
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-JtMyT9TQ.mjs";
|
|
3
|
+
import { i as incomingMessageToRequest } from "../../node-http-BUlb5EdB.mjs";
|
|
4
|
+
import { n as getWSConnectionHandler, r as handleKeepAlive } from "../../ws-C7ZOJJeA.mjs";
|
|
15
5
|
//#region src/adapters/fastify/fastifyRequestHandler.ts
|
|
16
|
-
var import_objectSpread2$1 = __toESM(require_objectSpread2(), 1);
|
|
17
6
|
async function fastifyRequestHandler(opts) {
|
|
18
7
|
const createContext = async (innerOpts) => {
|
|
19
8
|
var _opts$createContext;
|
|
20
|
-
return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, (
|
|
9
|
+
return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, _objectSpread2(_objectSpread2({}, opts), innerOpts)));
|
|
21
10
|
};
|
|
22
11
|
const incomingMessage = opts.req.raw;
|
|
23
12
|
if ("body" in opts.req) incomingMessage.body = opts.req.body;
|
|
24
13
|
const req = incomingMessageToRequest(incomingMessage, opts.res.raw, { maxBodySize: null });
|
|
25
|
-
const res = await resolveResponse((
|
|
14
|
+
const res = await resolveResponse(_objectSpread2(_objectSpread2({}, opts), {}, {
|
|
26
15
|
req,
|
|
27
16
|
error: null,
|
|
28
17
|
createContext,
|
|
29
18
|
onError(o) {
|
|
30
19
|
var _opts$onError;
|
|
31
|
-
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, (
|
|
20
|
+
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, _objectSpread2(_objectSpread2({}, o), {}, { req: opts.req }));
|
|
32
21
|
}
|
|
33
22
|
}));
|
|
34
23
|
await opts.res.send(res);
|
|
35
24
|
}
|
|
36
|
-
|
|
37
25
|
//#endregion
|
|
38
26
|
//#region src/adapters/fastify/fastifyTRPCPlugin.ts
|
|
39
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
40
27
|
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
41
28
|
var _opts$prefix;
|
|
42
29
|
fastify.removeContentTypeParser("application/json");
|
|
@@ -51,7 +38,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
51
38
|
if (typeof fastifyTRPCPlugin.default !== "function") prefix = "";
|
|
52
39
|
fastify.all(`${prefix}/:path`, async (req, res) => {
|
|
53
40
|
const path = req.params.path;
|
|
54
|
-
await fastifyRequestHandler((
|
|
41
|
+
await fastifyRequestHandler(_objectSpread2(_objectSpread2({}, opts.trpcOptions), {}, {
|
|
55
42
|
req,
|
|
56
43
|
res,
|
|
57
44
|
path
|
|
@@ -60,7 +47,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
60
47
|
if (opts.useWSS) {
|
|
61
48
|
var _prefix;
|
|
62
49
|
const trpcOptions = opts.trpcOptions;
|
|
63
|
-
const onConnection = getWSConnectionHandler((
|
|
50
|
+
const onConnection = getWSConnectionHandler(_objectSpread2({}, trpcOptions));
|
|
64
51
|
fastify.get((_prefix = prefix) !== null && _prefix !== void 0 ? _prefix : "/", { websocket: true }, (socket, req) => {
|
|
65
52
|
var _trpcOptions$keepAliv;
|
|
66
53
|
onConnection(socket, req.raw);
|
|
@@ -72,7 +59,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
|
|
|
72
59
|
}
|
|
73
60
|
done();
|
|
74
61
|
}
|
|
75
|
-
|
|
76
62
|
//#endregion
|
|
77
63
|
export { fastifyRequestHandler, fastifyTRPCPlugin };
|
|
64
|
+
|
|
78
65
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"sourcesContent":["/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\nimport type { FastifyReply, FastifyRequest } from 'fastify';\n// @trpc/server\nimport type { AnyRouter } from '../../@trpc/server';\n// @trpc/server/http\nimport {\n resolveResponse,\n type HTTPBaseHandlerOptions,\n type ResolveHTTPRequestOptionsContextFn,\n} from '../../@trpc/server/http';\n// @trpc/server/node-http\nimport type { NodeHTTPRequest } from '../node-http';\nimport {\n incomingMessageToRequest,\n type NodeHTTPCreateContextOption,\n} from '../node-http';\n\nexport type FastifyHandlerOptions<\n TRouter extends AnyRouter,\n TRequest extends FastifyRequest,\n TResponse extends FastifyReply,\n> = HTTPBaseHandlerOptions<TRouter, TRequest> &\n NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;\n\ntype FastifyRequestHandlerOptions<\n TRouter extends AnyRouter,\n TRequest extends FastifyRequest,\n TResponse extends FastifyReply,\n> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {\n req: TRequest;\n res: TResponse;\n path: string;\n};\n\nexport async function fastifyRequestHandler<\n TRouter extends AnyRouter,\n TRequest extends FastifyRequest,\n TResponse extends FastifyReply,\n>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>) {\n const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (\n innerOpts,\n ) => {\n return await opts.createContext?.({\n ...opts,\n ...innerOpts,\n });\n };\n\n const incomingMessage: NodeHTTPRequest = opts.req.raw;\n\n // monkey-path body to the IncomingMessage\n if ('body' in opts.req) {\n incomingMessage.body = opts.req.body;\n }\n const req = incomingMessageToRequest(incomingMessage, opts.res.raw, {\n maxBodySize: null,\n });\n\n const res = await resolveResponse({\n ...opts,\n req,\n error: null,\n createContext,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: opts.req,\n });\n },\n });\n\n await opts.res.send(res);\n}\n","/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\n/// <reference types=\"@fastify/websocket\" />\nimport type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';\n// @trpc/server\nimport type { AnyRouter } from '../../@trpc/server';\n// @trpc/server/http\nimport type { NodeHTTPCreateContextFnOptions } from '../node-http';\n// @trpc/server/ws\nimport {\n getWSConnectionHandler,\n handleKeepAlive,\n type WSSHandlerOptions,\n} from '../ws';\nimport type { FastifyHandlerOptions } from './fastifyRequestHandler';\nimport { fastifyRequestHandler } from './fastifyRequestHandler';\n\nexport interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {\n prefix?: string;\n useWSS?: boolean;\n trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;\n}\n\nexport type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<\n FastifyRequest,\n FastifyReply\n>;\n\nexport function fastifyTRPCPlugin<TRouter extends AnyRouter>(\n fastify: FastifyInstance,\n opts: FastifyTRPCPluginOptions<TRouter>,\n done: (err?: Error) => void,\n) {\n fastify.removeContentTypeParser('application/json');\n fastify.addContentTypeParser(\n 'application/json',\n { parseAs: 'string' },\n function (_, body, _done) {\n _done(null, body);\n },\n );\n fastify.removeContentTypeParser('multipart/form-data');\n fastify.addContentTypeParser(\n 'multipart/form-data',\n {},\n function (_, body, _done) {\n _done(null, body);\n },\n );\n\n let prefix = opts.prefix ?? '';\n\n // https://github.com/fastify/fastify-plugin/blob/fe079bef6557a83794bf437e14b9b9edb8a74104/plugin.js#L11\n // @ts-expect-error property 'default' does not exists on type ...\n if (typeof fastifyTRPCPlugin.default !== 'function') {\n prefix = ''; // handled by fastify internally\n }\n\n fastify.all(`${prefix}/:path`, async (req, res) => {\n const path = (req.params as any).path;\n await fastifyRequestHandler({ ...opts.trpcOptions, req, res, path });\n });\n\n if (opts.useWSS) {\n const trpcOptions =\n opts.trpcOptions as unknown as WSSHandlerOptions<TRouter>;\n\n const onConnection = getWSConnectionHandler<TRouter>({\n ...trpcOptions,\n });\n\n fastify.get(prefix ?? '/', { websocket: true }, (socket, req) => {\n onConnection(socket, req.raw);\n if (trpcOptions?.keepAlive?.enabled) {\n const { pingMs, pongWaitMs } = trpcOptions.keepAlive;\n handleKeepAlive(socket, pingMs, pongWaitMs);\n }\n });\n }\n\n done();\n}\n"],"mappings":";;;;;AA0CA,eAAsB,sBAIpB,MAAkE;CAClE,MAAM,gBAA6D,OACjE,cACG;;EACH,OAAO,QAAA,sBAAM,KAAK,mBAAA,QAAA,wBAAA,KAAA,IAAA,KAAA,IAAA,oBAAA,KAAA,MAAA,eAAA,eAAA,CAAA,GACb,IAAA,GACA,SACL,CAAC;CACH;CAEA,MAAM,kBAAmC,KAAK,IAAI;CAGlD,IAAI,UAAU,KAAK,KACjB,gBAAgB,OAAO,KAAK,IAAI;CAElC,MAAM,MAAM,yBAAyB,iBAAiB,KAAK,IAAI,KAAK,EAClE,aAAa,KACf,CAAC;CAED,MAAM,MAAM,MAAM,gBAAA,eAAA,eAAA,CAAA,GACb,IAAA,GAAA,CAAA,GAAA;EACH;EACA,OAAO;EACP;EACA,QAAQ,GAAG;;GACT,SAAA,QAAA,SAAA,KAAA,MAAA,gBAAA,KAAM,aAAA,QAAA,kBAAA,KAAA,KAAA,cAAA,KAAA,MAAA,eAAA,eAAA,CAAA,GACD,CAAA,GAAA,CAAA,GAAA,EACH,KAAK,KAAK,IAAA,CACZ,CAAC;EACH;CACF,CAAA,CAAC;CAED,MAAM,KAAK,IAAI,KAAK,GAAG;AACzB;;;AC7CA,SAAgB,kBACd,SACA,MACA,MACA;;CACA,QAAQ,wBAAwB,kBAAkB;CAClD,QAAQ,qBACN,oBACA,EAAE,SAAS,SAAS,GACpB,SAAU,GAAG,MAAM,OAAO;EACxB,MAAM,MAAM,IAAI;CAClB,CACF;CACA,QAAQ,wBAAwB,qBAAqB;CACrD,QAAQ,qBACN,uBACA,CAAC,GACD,SAAU,GAAG,MAAM,OAAO;EACxB,MAAM,MAAM,IAAI;CAClB,CACF;CAEA,IAAI,UAAA,eAAS,KAAK,YAAA,QAAA,iBAAA,KAAA,IAAA,eAAU;CAI5B,IAAI,OAAO,kBAAkB,YAAY,YACvC,SAAS;CAGX,QAAQ,IAAI,GAAG,OAAO,SAAS,OAAO,KAAK,QAAQ;EACjD,MAAM,OAAQ,IAAI,OAAe;EACjC,MAAM,sBAAA,eAAA,eAAA,CAAA,GAA2B,KAAK,WAAA,GAAA,CAAA,GAAA;GAAa;GAAK;GAAK;EAAK,CAAA,CAAC;CACrE,CAAC;CAED,IAAI,KAAK,QAAQ;;EACf,MAAM,cACJ,KAAK;EAEP,MAAM,eAAe,uBAAA,eAAA,CAAA,GAChB,WACL,CAAC;EAED,QAAQ,KAAA,UAAI,YAAA,QAAA,YAAA,KAAA,IAAA,UAAU,KAAK,EAAE,WAAW,KAAK,IAAI,QAAQ,QAAQ;;GAC/D,aAAa,QAAQ,IAAI,GAAG;GAC5B,IAAA,gBAAA,QAAA,gBAAA,KAAA,MAAA,wBAAI,YAAa,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAW,SAAS;IACnC,MAAM,EAAE,QAAQ,eAAe,YAAY;IAC3C,gBAAgB,QAAQ,QAAQ,UAAU;GAC5C;EACF,CAAC;CACH;CAEA,KAAK;AACP"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
require(
|
|
3
|
-
require(
|
|
4
|
-
const require_resolveResponse = require('../../resolveResponse-Djb7nJqb.cjs');
|
|
5
|
-
require('../../observable-B1Nk6r1H.cjs');
|
|
6
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_getErrorShape = require("../../getErrorShape-DeIapApr.cjs");
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-DLpzHrPG.cjs");
|
|
7
4
|
//#region src/adapters/fetch/fetchRequestHandler.ts
|
|
8
|
-
var import_objectSpread2 = require_getErrorShape.__toESM(require_getErrorShape.require_objectSpread2(), 1);
|
|
9
5
|
const trimSlashes = (path) => {
|
|
10
6
|
path = path.startsWith("/") ? path.slice(1) : path;
|
|
11
7
|
path = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
@@ -15,7 +11,7 @@ async function fetchRequestHandler(opts) {
|
|
|
15
11
|
const resHeaders = new Headers();
|
|
16
12
|
const createContext = async (innerOpts) => {
|
|
17
13
|
var _opts$createContext;
|
|
18
|
-
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts,
|
|
14
|
+
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, require_getErrorShape._objectSpread2({
|
|
19
15
|
req: opts.req,
|
|
20
16
|
resHeaders
|
|
21
17
|
}, innerOpts));
|
|
@@ -24,14 +20,14 @@ async function fetchRequestHandler(opts) {
|
|
|
24
20
|
const pathname = trimSlashes(url.pathname);
|
|
25
21
|
const endpoint = trimSlashes(opts.endpoint);
|
|
26
22
|
const path = trimSlashes(pathname.slice(endpoint.length));
|
|
27
|
-
return await require_resolveResponse.resolveResponse(
|
|
23
|
+
return await require_resolveResponse.resolveResponse(require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, opts), {}, {
|
|
28
24
|
req: opts.req,
|
|
29
25
|
createContext,
|
|
30
26
|
path,
|
|
31
27
|
error: null,
|
|
32
28
|
onError(o) {
|
|
33
29
|
var _opts$onError;
|
|
34
|
-
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts,
|
|
30
|
+
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, o), {}, { req: opts.req }));
|
|
35
31
|
},
|
|
36
32
|
responseMeta(data) {
|
|
37
33
|
var _opts$responseMeta;
|
|
@@ -52,6 +48,5 @@ async function fetchRequestHandler(opts) {
|
|
|
52
48
|
}
|
|
53
49
|
}));
|
|
54
50
|
}
|
|
55
|
-
|
|
56
51
|
//#endregion
|
|
57
|
-
exports.fetchRequestHandler = fetchRequestHandler;
|
|
52
|
+
exports.fetchRequestHandler = fetchRequestHandler;
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import { AnyRouter, CreateContextCallback, HTTPBaseHandlerOptions, TRPCRequestInfo, inferRouterContext } from "../../unstable-core-do-not-import.d-Dh9CT5RO.cjs";
|
|
3
|
-
import "../../index.d-CvZXeEyR.cjs";
|
|
4
|
-
|
|
1
|
+
import { Cn as TRPCRequestInfo, J as AnyRouter, _n as HTTPBaseHandlerOptions, ft as inferRouterContext, yt as CreateContextCallback } from "../../unstable-core-do-not-import-B9ZnrQAU.cjs";
|
|
5
2
|
//#region src/adapters/fetch/types.d.ts
|
|
6
|
-
|
|
7
|
-
type FetchCreateContextFnOptions = {
|
|
3
|
+
export type FetchCreateContextFnOptions = {
|
|
8
4
|
req: Request;
|
|
9
5
|
resHeaders: Headers;
|
|
10
6
|
info: TRPCRequestInfo;
|
|
11
7
|
};
|
|
12
|
-
type FetchCreateContextFn<TRouter extends AnyRouter> = (opts: FetchCreateContextFnOptions) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
13
|
-
type FetchCreateContextOption<TRouter extends AnyRouter> = CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>>;
|
|
14
|
-
type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request> & {
|
|
8
|
+
export type FetchCreateContextFn<TRouter extends AnyRouter> = (opts: FetchCreateContextFnOptions) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
9
|
+
export type FetchCreateContextOption<TRouter extends AnyRouter> = CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>>;
|
|
10
|
+
export type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request> & {
|
|
15
11
|
req: Request;
|
|
16
12
|
endpoint: string;
|
|
17
13
|
};
|
|
18
|
-
type FetchHandlerRequestOptions<TRouter extends AnyRouter> = HTTPBaseHandlerOptions<TRouter, Request> & CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>> & {
|
|
14
|
+
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> = HTTPBaseHandlerOptions<TRouter, Request> & CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>> & {
|
|
19
15
|
req: Request;
|
|
20
16
|
endpoint: string;
|
|
21
17
|
};
|
|
22
|
-
//# sourceMappingURL=types.d.ts.map
|
|
23
18
|
//#endregion
|
|
24
19
|
//#region src/adapters/fetch/fetchRequestHandler.d.ts
|
|
25
|
-
declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
26
|
-
//# sourceMappingURL=fetchRequestHandler.d.ts.map
|
|
27
|
-
|
|
20
|
+
export declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
28
21
|
//#endregion
|
|
29
|
-
export { FetchCreateContextFn, FetchCreateContextFnOptions, FetchCreateContextOption, FetchHandlerOptions, FetchHandlerRequestOptions, fetchRequestHandler };
|
|
30
22
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/fetch/types.ts","../../../src/adapters/fetch/fetchRequestHandler.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/fetch/types.ts","../../../src/adapters/fetch/fetchRequestHandler.ts"],"mappings":";;YAqBY;EACV,KAAK;EACL,YAAY;EACZ,MAAM;;YAGI,qBAAqB,gBAAgB,cAC/C,MAAM,gCACH,mBAAmB,WAAW,QAAQ,mBAAmB;YAElD,yBAAyB,gBAAgB,aACnD,sBACE,mBAAmB,UACnB,qBAAqB;YAGb,oBAAoB,gBAAgB,aAC9C,yBAAyB,WACvB,uBAAuB,SAAS;EAC9B,KAAK;EACL;;YAGM,2BAA2B,gBAAgB,aACrD,uBAAuB,SAAS,WAC9B,sBACE,mBAAmB,UACnB,qBAAqB;EAErB,KAAK;EACL;;;;wBC5BgB,oBAAoB,gBAAgB,WACxD,MAAM,2BAA2B,WAChC,QAAQ"}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import { AnyRouter, CreateContextCallback, HTTPBaseHandlerOptions, TRPCRequestInfo, inferRouterContext } from "../../unstable-core-do-not-import.d-BdVSvUCr.mjs";
|
|
3
|
-
import "../../index.d-vq_QHko2.mjs";
|
|
4
|
-
|
|
1
|
+
import { Cn as TRPCRequestInfo, J as AnyRouter, _n as HTTPBaseHandlerOptions, ft as inferRouterContext, yt as CreateContextCallback } from "../../unstable-core-do-not-import-BK_OKrtM.mjs";
|
|
5
2
|
//#region src/adapters/fetch/types.d.ts
|
|
6
|
-
|
|
7
|
-
type FetchCreateContextFnOptions = {
|
|
3
|
+
export type FetchCreateContextFnOptions = {
|
|
8
4
|
req: Request;
|
|
9
5
|
resHeaders: Headers;
|
|
10
6
|
info: TRPCRequestInfo;
|
|
11
7
|
};
|
|
12
|
-
type FetchCreateContextFn<TRouter extends AnyRouter> = (opts: FetchCreateContextFnOptions) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
13
|
-
type FetchCreateContextOption<TRouter extends AnyRouter> = CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>>;
|
|
14
|
-
type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request> & {
|
|
8
|
+
export type FetchCreateContextFn<TRouter extends AnyRouter> = (opts: FetchCreateContextFnOptions) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
9
|
+
export type FetchCreateContextOption<TRouter extends AnyRouter> = CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>>;
|
|
10
|
+
export type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request> & {
|
|
15
11
|
req: Request;
|
|
16
12
|
endpoint: string;
|
|
17
13
|
};
|
|
18
|
-
type FetchHandlerRequestOptions<TRouter extends AnyRouter> = HTTPBaseHandlerOptions<TRouter, Request> & CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>> & {
|
|
14
|
+
export type FetchHandlerRequestOptions<TRouter extends AnyRouter> = HTTPBaseHandlerOptions<TRouter, Request> & CreateContextCallback<inferRouterContext<TRouter>, FetchCreateContextFn<TRouter>> & {
|
|
19
15
|
req: Request;
|
|
20
16
|
endpoint: string;
|
|
21
17
|
};
|
|
22
|
-
//# sourceMappingURL=types.d.ts.map
|
|
23
18
|
//#endregion
|
|
24
19
|
//#region src/adapters/fetch/fetchRequestHandler.d.ts
|
|
25
|
-
declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
26
|
-
//# sourceMappingURL=fetchRequestHandler.d.ts.map
|
|
27
|
-
|
|
20
|
+
export declare function fetchRequestHandler<TRouter extends AnyRouter>(opts: FetchHandlerRequestOptions<TRouter>): Promise<Response>;
|
|
28
21
|
//#endregion
|
|
29
|
-
export { FetchCreateContextFn, FetchCreateContextFnOptions, FetchCreateContextOption, FetchHandlerOptions, FetchHandlerRequestOptions, fetchRequestHandler };
|
|
30
22
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/fetch/types.ts","../../../src/adapters/fetch/fetchRequestHandler.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/fetch/types.ts","../../../src/adapters/fetch/fetchRequestHandler.ts"],"mappings":";;YAqBY;EACV,KAAK;EACL,YAAY;EACZ,MAAM;;YAGI,qBAAqB,gBAAgB,cAC/C,MAAM,gCACH,mBAAmB,WAAW,QAAQ,mBAAmB;YAElD,yBAAyB,gBAAgB,aACnD,sBACE,mBAAmB,UACnB,qBAAqB;YAGb,oBAAoB,gBAAgB,aAC9C,yBAAyB,WACvB,uBAAuB,SAAS;EAC9B,KAAK;EACL;;YAGM,2BAA2B,gBAAgB,aACrD,uBAAuB,SAAS,WAC9B,sBACE,mBAAmB,UACnB,qBAAqB;EAErB,KAAK;EACL;;;;wBC5BgB,oBAAoB,gBAAgB,WACxD,MAAM,2BAA2B,WAChC,QAAQ"}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../../
|
|
3
|
-
import "../../tracked-DWInO6EQ.mjs";
|
|
4
|
-
import { resolveResponse } from "../../resolveResponse-C7cFScHo.mjs";
|
|
5
|
-
import "../../observable-UMO3vUa_.mjs";
|
|
6
|
-
|
|
1
|
+
import { n as _objectSpread2 } from "../../getErrorShape-B0JBUs-i.mjs";
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-JtMyT9TQ.mjs";
|
|
7
3
|
//#region src/adapters/fetch/fetchRequestHandler.ts
|
|
8
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
9
4
|
const trimSlashes = (path) => {
|
|
10
5
|
path = path.startsWith("/") ? path.slice(1) : path;
|
|
11
6
|
path = path.endsWith("/") ? path.slice(0, -1) : path;
|
|
@@ -15,7 +10,7 @@ async function fetchRequestHandler(opts) {
|
|
|
15
10
|
const resHeaders = new Headers();
|
|
16
11
|
const createContext = async (innerOpts) => {
|
|
17
12
|
var _opts$createContext;
|
|
18
|
-
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, (
|
|
13
|
+
return (_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, _objectSpread2({
|
|
19
14
|
req: opts.req,
|
|
20
15
|
resHeaders
|
|
21
16
|
}, innerOpts));
|
|
@@ -24,14 +19,14 @@ async function fetchRequestHandler(opts) {
|
|
|
24
19
|
const pathname = trimSlashes(url.pathname);
|
|
25
20
|
const endpoint = trimSlashes(opts.endpoint);
|
|
26
21
|
const path = trimSlashes(pathname.slice(endpoint.length));
|
|
27
|
-
return await resolveResponse((
|
|
22
|
+
return await resolveResponse(_objectSpread2(_objectSpread2({}, opts), {}, {
|
|
28
23
|
req: opts.req,
|
|
29
24
|
createContext,
|
|
30
25
|
path,
|
|
31
26
|
error: null,
|
|
32
27
|
onError(o) {
|
|
33
28
|
var _opts$onError;
|
|
34
|
-
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, (
|
|
29
|
+
opts === null || opts === void 0 || (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, _objectSpread2(_objectSpread2({}, o), {}, { req: opts.req }));
|
|
35
30
|
},
|
|
36
31
|
responseMeta(data) {
|
|
37
32
|
var _opts$responseMeta;
|
|
@@ -52,7 +47,7 @@ async function fetchRequestHandler(opts) {
|
|
|
52
47
|
}
|
|
53
48
|
}));
|
|
54
49
|
}
|
|
55
|
-
|
|
56
50
|
//#endregion
|
|
57
51
|
export { fetchRequestHandler };
|
|
52
|
+
|
|
58
53
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"sourcesContent":["/**\n * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`\n *\n * @example\n * ```ts\n * import type { AnyTRPCRouter } from '@trpc/server'\n * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'\n * ```\n */\n// @trpc/server\n\nimport type { AnyRouter } from '../../@trpc/server';\nimport type { ResolveHTTPRequestOptionsContextFn } from '../../@trpc/server/http';\nimport { resolveResponse } from '../../@trpc/server/http';\nimport type { FetchHandlerRequestOptions } from './types';\n\nconst trimSlashes = (path: string): string => {\n path = path.startsWith('/') ? path.slice(1) : path;\n path = path.endsWith('/') ? path.slice(0, -1) : path;\n\n return path;\n};\n\nexport async function fetchRequestHandler<TRouter extends AnyRouter>(\n opts: FetchHandlerRequestOptions<TRouter>,\n): Promise<Response> {\n const resHeaders = new Headers();\n\n const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (\n innerOpts,\n ) => {\n return opts.createContext?.({ req: opts.req, resHeaders, ...innerOpts });\n };\n\n const url = new URL(opts.req.url);\n\n const pathname = trimSlashes(url.pathname);\n const endpoint = trimSlashes(opts.endpoint);\n const path = trimSlashes(pathname.slice(endpoint.length));\n\n return await resolveResponse({\n ...opts,\n req: opts.req,\n createContext,\n path,\n error: null,\n onError(o) {\n opts?.onError?.({ ...o, req: opts.req });\n },\n responseMeta(data) {\n const meta = opts.responseMeta?.(data);\n\n if (meta?.headers) {\n if (meta.headers instanceof Headers) {\n for (const [key, value] of meta.headers.entries()) {\n resHeaders.append(key, value);\n }\n } else {\n /**\n * @deprecated, delete in v12\n */\n for (const [key, value] of Object.entries(meta.headers)) {\n if (Array.isArray(value)) {\n for (const v of value) {\n resHeaders.append(key, v);\n }\n } else if (typeof value === 'string') {\n resHeaders.set(key, value);\n }\n }\n }\n }\n\n return {\n headers: resHeaders,\n status: meta?.status,\n };\n },\n });\n}\n"],"mappings":";;;AAgBA,MAAM,eAAe,SAAyB;CAC5C,OAAO,KAAK,WAAW,GAAG,IAAI,KAAK,MAAM,CAAC,IAAI;CAC9C,OAAO,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI;CAEhD,OAAO;AACT;AAEA,eAAsB,oBACpB,MACmB;CACnB,MAAM,aAAa,IAAI,QAAQ;CAE/B,MAAM,gBAA6D,OACjE,cACG;;EACH,QAAA,sBAAO,KAAK,mBAAA,QAAA,wBAAA,KAAA,IAAA,KAAA,IAAA,oBAAA,KAAA,MAAA,eAAA;GAAkB,KAAK,KAAK;GAAK;EAAe,GAAA,SAAU,CAAC;CACzE;CAEA,MAAM,MAAM,IAAI,IAAI,KAAK,IAAI,GAAG;CAEhC,MAAM,WAAW,YAAY,IAAI,QAAQ;CACzC,MAAM,WAAW,YAAY,KAAK,QAAQ;CAC1C,MAAM,OAAO,YAAY,SAAS,MAAM,SAAS,MAAM,CAAC;CAExD,OAAO,MAAM,gBAAA,eAAA,eAAA,CAAA,GACR,IAAA,GAAA,CAAA,GAAA;EACH,KAAK,KAAK;EACV;EACA;EACA,OAAO;EACP,QAAQ,GAAG;;GACT,SAAA,QAAA,SAAA,KAAA,MAAA,gBAAA,KAAM,aAAA,QAAA,kBAAA,KAAA,KAAA,cAAA,KAAA,MAAA,eAAA,eAAA,CAAA,GAAe,CAAA,GAAA,CAAA,GAAA,EAAG,KAAK,KAAK,IAAA,CAAI,CAAC;EACzC;EACA,aAAa,MAAM;;GACjB,MAAM,QAAA,qBAAO,KAAK,kBAAA,QAAA,uBAAA,KAAA,IAAA,KAAA,IAAA,mBAAA,KAAA,MAAe,IAAI;GAErC,IAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAI,KAAM,SAAS;IACjB,IAAI,KAAK,mBAAmB,SAC1B,KAAK,MAAM,CAAC,KAAK,UAAU,KAAK,QAAQ,QAAQ,GAC9C,WAAW,OAAO,KAAK,KAAK;;;;;IAM9B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,OAAO,GACpD,IAAI,MAAM,QAAQ,KAAK,GACrB,KAAK,MAAM,KAAK,OACd,WAAW,OAAO,KAAK,CAAC;SAErB,IAAI,OAAO,UAAU,UAC1B,WAAW,IAAI,KAAK,KAAK;GAIjC;GAEA,OAAO;IACL,SAAS;IACT,QAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAQ,KAAM;GAChB;EACF;CACF,CAAA,CAAC;AACH"}
|