@trpc/server 11.23.1-canary.3.ae3beada3 → 11.23.1-canary.30.70e1d688c
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 +12 -2
- package/dist/adapters/aws-lambda/index.d.cts +24 -1
- package/dist/adapters/aws-lambda/index.d.cts.map +1 -1
- package/dist/adapters/aws-lambda/index.d.mts +24 -1
- package/dist/adapters/aws-lambda/index.d.mts.map +1 -1
- package/dist/adapters/aws-lambda/index.mjs +12 -2
- package/dist/adapters/aws-lambda/index.mjs.map +1 -1
- package/dist/adapters/express.cjs +8 -3
- package/dist/adapters/express.d.cts +12 -2
- package/dist/adapters/express.d.cts.map +1 -1
- package/dist/adapters/express.d.mts +12 -2
- package/dist/adapters/express.d.mts.map +1 -1
- package/dist/adapters/express.mjs +8 -3
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/fastify/index.cjs +20 -4
- package/dist/adapters/fastify/index.d.cts +38 -4
- package/dist/adapters/fastify/index.d.cts.map +1 -1
- package/dist/adapters/fastify/index.d.mts +38 -4
- package/dist/adapters/fastify/index.d.mts.map +1 -1
- package/dist/adapters/fastify/index.mjs +20 -4
- package/dist/adapters/fastify/index.mjs.map +1 -1
- package/dist/adapters/fetch/index.cjs +13 -2
- package/dist/adapters/fetch/index.d.cts +26 -1
- package/dist/adapters/fetch/index.d.cts.map +1 -1
- package/dist/adapters/fetch/index.d.mts +26 -1
- package/dist/adapters/fetch/index.d.mts.map +1 -1
- package/dist/adapters/fetch/index.mjs +13 -2
- package/dist/adapters/fetch/index.mjs.map +1 -1
- package/dist/adapters/next-app-dir.cjs +19 -9
- package/dist/adapters/next-app-dir.d.cts +21 -11
- package/dist/adapters/next-app-dir.d.cts.map +1 -1
- package/dist/adapters/next-app-dir.d.mts +21 -11
- package/dist/adapters/next-app-dir.d.mts.map +1 -1
- package/dist/adapters/next-app-dir.mjs +19 -9
- package/dist/adapters/next-app-dir.mjs.map +1 -1
- package/dist/adapters/next.cjs +10 -4
- package/dist/adapters/next.d.cts +13 -2
- package/dist/adapters/next.d.cts.map +1 -1
- package/dist/adapters/next.d.mts +13 -2
- package/dist/adapters/next.d.mts.map +1 -1
- package/dist/adapters/next.mjs +10 -4
- package/dist/adapters/next.mjs.map +1 -1
- package/dist/adapters/node-http/index.cjs +1 -1
- package/dist/adapters/node-http/index.d.cts +1 -1
- package/dist/adapters/node-http/index.d.mts +1 -1
- package/dist/adapters/node-http/index.mjs +1 -1
- package/dist/adapters/standalone.cjs +19 -3
- package/dist/adapters/standalone.d.cts +32 -6
- package/dist/adapters/standalone.d.cts.map +1 -1
- package/dist/adapters/standalone.d.mts +32 -6
- package/dist/adapters/standalone.d.mts.map +1 -1
- package/dist/adapters/standalone.mjs +19 -3
- package/dist/adapters/standalone.mjs.map +1 -1
- package/dist/adapters/ws.cjs +1 -1
- package/dist/adapters/ws.d.cts +2 -2
- package/dist/adapters/ws.d.mts +2 -2
- package/dist/adapters/ws.mjs +1 -1
- package/dist/{asyncGeneratorDelegate-FcEJT04i.mjs → asyncGeneratorDelegate-0Kj4R1TB.mjs} +77 -9
- package/dist/asyncGeneratorDelegate-0Kj4R1TB.mjs.map +1 -0
- package/dist/{asyncGeneratorDelegate-Dj-8tGhf.cjs → asyncGeneratorDelegate-D6_6Ojyy.cjs} +93 -7
- package/dist/{codes-HK4UsP07.cjs → codes-Be-DrYMh.cjs} +8 -4
- package/dist/{codes-C9N0z0an.mjs → codes-nbrm_zWY.mjs} +9 -5
- package/dist/codes-nbrm_zWY.mjs.map +1 -0
- package/dist/{contentTypeParsers-B1e2ZNvN.cjs → contentTypeParsers-BTdoZrqN.cjs} +12 -0
- package/dist/contentTypeParsers-D1EBkFFY.mjs +26 -0
- package/dist/contentTypeParsers-D1EBkFFY.mjs.map +1 -0
- package/dist/{getErrorShape-hncV8cPE.cjs → getErrorShape-8t0oLscZ.cjs} +16 -5
- package/dist/{getErrorShape-zlj81BiC.mjs → getErrorShape-B6z8u8q0.mjs} +17 -6
- package/dist/getErrorShape-B6z8u8q0.mjs.map +1 -0
- package/dist/http.cjs +3 -3
- package/dist/http.d.cts +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +3 -3
- package/dist/{index-BI3Qi_F-.d.cts → index-BGYvuCEh.d.cts} +68 -8
- package/dist/index-BGYvuCEh.d.cts.map +1 -0
- package/dist/{index-BI3Qi_F-.d.mts → index-BGYvuCEh.d.mts} +68 -8
- package/dist/index-BGYvuCEh.d.mts.map +1 -0
- package/dist/{index-Tpw5OCTF.d.cts → index-BjG3DNaL.d.cts} +41 -29
- package/dist/index-BjG3DNaL.d.cts.map +1 -0
- package/dist/{index-CtkOmZzm.d.mts → index-vR2bVSvk.d.mts} +41 -29
- package/dist/index-vR2bVSvk.d.mts.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/{initTRPC-RMeQIy9H.mjs → initTRPC-AGcaZSsI.mjs} +47 -23
- package/dist/initTRPC-AGcaZSsI.mjs.map +1 -0
- package/dist/{initTRPC-DP-s8c4t.cjs → initTRPC-DDP2HNOa.cjs} +46 -22
- package/dist/{node-http-ChhZEv1k.mjs → node-http-CRKoQOwy.mjs} +14 -7
- package/dist/node-http-CRKoQOwy.mjs.map +1 -0
- package/dist/{node-http-X8RiQEuH.cjs → node-http-IgvbwDdQ.cjs} +13 -6
- package/dist/observable/index.cjs +2 -2
- package/dist/observable/index.d.cts +1 -1
- package/dist/observable/index.d.mts +1 -1
- package/dist/observable/index.mjs +2 -2
- package/dist/{observable-C-LvH26G.cjs → observable-B8nn0anr.cjs} +27 -4
- package/dist/{observable-yEyhfXUI.mjs → observable-CdPmrXKY.mjs} +28 -5
- package/dist/observable-CdPmrXKY.mjs.map +1 -0
- package/dist/{observable-CkXWrCsV.mjs → observable-F1Nt_3e4.mjs} +16 -4
- package/dist/observable-F1Nt_3e4.mjs.map +1 -0
- package/dist/{observable-xBsJ11Ns.cjs → observable-N4F1yT7s.cjs} +15 -3
- package/dist/{parseTRPCMessage-CJ4DJVBp.mjs → parseTRPCMessage-BO1-cCsX.mjs} +7 -3
- package/dist/parseTRPCMessage-BO1-cCsX.mjs.map +1 -0
- package/dist/{parseTRPCMessage-CPEfSSFx.cjs → parseTRPCMessage-BsPr5reh.cjs} +6 -2
- package/dist/{resolveResponse-CoGjFxK0.cjs → resolveResponse-D2d2y6BC.cjs} +17 -5
- package/dist/{resolveResponse-DksrxZ2k.mjs → resolveResponse-oG-tsWtT.mjs} +18 -6
- package/dist/resolveResponse-oG-tsWtT.mjs.map +1 -0
- package/dist/rpc.cjs +2 -2
- package/dist/rpc.d.cts +1 -1
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.mjs +2 -2
- package/dist/shared.cjs +1 -1
- package/dist/shared.d.cts +1 -1
- package/dist/shared.d.mts +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/{unstable-core-do-not-import-Dbo98mkh.d.mts → unstable-core-do-not-import-CLjKFqzt.d.mts} +558 -162
- package/dist/unstable-core-do-not-import-CLjKFqzt.d.mts.map +1 -0
- package/dist/{unstable-core-do-not-import-B8epiErP.d.cts → unstable-core-do-not-import-DrFOoxdW.d.cts} +558 -162
- package/dist/unstable-core-do-not-import-DrFOoxdW.d.cts.map +1 -0
- package/dist/unstable-core-do-not-import.cjs +10 -7
- package/dist/unstable-core-do-not-import.d.cts +2 -2
- package/dist/unstable-core-do-not-import.d.mts +2 -2
- package/dist/unstable-core-do-not-import.mjs +8 -8
- package/dist/{ws-BYfo-HED.mjs → ws-BuMgPk3g.mjs} +30 -11
- package/dist/ws-BuMgPk3g.mjs.map +1 -0
- package/dist/ws-CDC5vYSF.d.cts +95 -0
- package/dist/ws-CDC5vYSF.d.cts.map +1 -0
- package/dist/ws-CXuYC1QZ.d.mts +95 -0
- package/dist/ws-CXuYC1QZ.d.mts.map +1 -0
- package/dist/{ws-7qWW7Uec.cjs → ws-TUtpQwOX.cjs} +29 -10
- package/package.json +2 -2
- package/skills/adapter-aws-lambda/SKILL.md +1 -1
- package/skills/adapter-express/SKILL.md +1 -1
- package/skills/adapter-fastify/SKILL.md +1 -1
- package/skills/adapter-fetch/SKILL.md +1 -1
- package/skills/adapter-standalone/SKILL.md +1 -1
- package/skills/auth/SKILL.md +1 -1
- package/skills/caching/SKILL.md +2 -2
- package/skills/error-handling/SKILL.md +38 -1
- package/skills/middlewares/SKILL.md +1 -1
- package/skills/non-json-content-types/SKILL.md +13 -4
- package/skills/server-setup/SKILL.md +1 -1
- package/skills/server-side-calls/SKILL.md +1 -1
- package/skills/service-oriented-architecture/SKILL.md +1 -1
- package/skills/subscriptions/SKILL.md +1 -1
- package/skills/trpc-router/SKILL.md +1 -1
- package/skills/validators/SKILL.md +1 -1
- package/src/@trpc/server/index.ts +3 -2
- package/src/adapters/aws-lambda/index.ts +23 -0
- package/src/adapters/express.ts +10 -0
- package/src/adapters/fastify/fastifyRequestHandler.ts +5 -0
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +30 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +11 -0
- package/src/adapters/fetch/types.ts +14 -0
- package/src/adapters/next-app-dir/nextAppDirCaller.ts +8 -4
- package/src/adapters/next-app-dir/notFound.ts +3 -1
- package/src/adapters/next-app-dir/redirect.ts +6 -4
- package/src/adapters/next-app-dir/rethrowNextErrors.ts +5 -1
- package/src/adapters/next.ts +13 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +6 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +3 -1
- package/src/adapters/node-http/types.ts +30 -25
- package/src/adapters/standalone.ts +30 -4
- package/src/adapters/ws.ts +42 -8
- package/src/adapters/wsEncoder.ts +5 -6
- package/src/observable/behaviorSubject.ts +6 -2
- package/src/observable/observable.ts +31 -5
- package/src/observable/operators.ts +12 -0
- package/src/observable/types.ts +18 -0
- package/src/unstable-core-do-not-import/clientish/inference.ts +22 -1
- package/src/unstable-core-do-not-import/clientish/inferrable.ts +5 -2
- package/src/unstable-core-do-not-import/createProxy.ts +4 -4
- package/src/unstable-core-do-not-import/error/TRPCError.ts +19 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +15 -2
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +2 -0
- package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +15 -2
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +9 -0
- package/src/unstable-core-do-not-import/http/parseConnectionParams.ts +8 -0
- package/src/unstable-core-do-not-import/http/pathSeparator.ts +51 -0
- package/src/unstable-core-do-not-import/http/resolveResponse.ts +9 -1
- package/src/unstable-core-do-not-import/http/types.ts +55 -27
- package/src/unstable-core-do-not-import/initTRPC.ts +53 -27
- package/src/unstable-core-do-not-import/middleware.ts +25 -5
- package/src/unstable-core-do-not-import/parser.ts +21 -1
- package/src/unstable-core-do-not-import/procedure.ts +28 -2
- package/src/unstable-core-do-not-import/procedureBuilder.ts +56 -35
- package/src/unstable-core-do-not-import/rootConfig.ts +39 -19
- package/src/unstable-core-do-not-import/router.ts +92 -11
- package/src/unstable-core-do-not-import/rpc/codes.ts +13 -5
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +45 -9
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +5 -1
- package/src/unstable-core-do-not-import/stream/tracked.ts +17 -5
- package/src/unstable-core-do-not-import/transformer.ts +12 -1
- package/src/unstable-core-do-not-import/types.ts +2 -0
- package/src/unstable-core-do-not-import/utils.ts +4 -1
- package/src/unstable-core-do-not-import.ts +1 -0
- package/dist/asyncGeneratorDelegate-FcEJT04i.mjs.map +0 -1
- package/dist/codes-C9N0z0an.mjs.map +0 -1
- package/dist/contentTypeParsers-Bb-9hUEf.mjs +0 -14
- package/dist/contentTypeParsers-Bb-9hUEf.mjs.map +0 -1
- package/dist/getErrorShape-zlj81BiC.mjs.map +0 -1
- package/dist/index-BI3Qi_F-.d.cts.map +0 -1
- package/dist/index-BI3Qi_F-.d.mts.map +0 -1
- package/dist/index-CtkOmZzm.d.mts.map +0 -1
- package/dist/index-Tpw5OCTF.d.cts.map +0 -1
- package/dist/initTRPC-RMeQIy9H.mjs.map +0 -1
- package/dist/node-http-ChhZEv1k.mjs.map +0 -1
- package/dist/observable-CkXWrCsV.mjs.map +0 -1
- package/dist/observable-yEyhfXUI.mjs.map +0 -1
- package/dist/parseTRPCMessage-CJ4DJVBp.mjs.map +0 -1
- package/dist/resolveResponse-DksrxZ2k.mjs.map +0 -1
- package/dist/unstable-core-do-not-import-B8epiErP.d.cts.map +0 -1
- package/dist/unstable-core-do-not-import-Dbo98mkh.d.mts.map +0 -1
- package/dist/ws-BYfo-HED.mjs.map +0 -1
- package/dist/ws-DD1ukLuC.d.cts +0 -61
- package/dist/ws-DD1ukLuC.d.cts.map +0 -1
- package/dist/ws-DT37N43e.d.mts +0 -61
- package/dist/ws-DT37N43e.d.mts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_getErrorShape = require("../../getErrorShape-
|
|
3
|
-
const require_resolveResponse = require("../../resolveResponse-
|
|
2
|
+
const require_getErrorShape = require("../../getErrorShape-8t0oLscZ.cjs");
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-D2d2y6BC.cjs");
|
|
4
4
|
let node_stream = require("node:stream");
|
|
5
5
|
let node_stream_promises = require("node:stream/promises");
|
|
6
6
|
//#region src/vendor/cookie-es/set-cookie/split.ts
|
|
@@ -211,6 +211,11 @@ function getPlanner(event) {
|
|
|
211
211
|
}
|
|
212
212
|
//#endregion
|
|
213
213
|
//#region src/adapters/aws-lambda/index.ts
|
|
214
|
+
/**
|
|
215
|
+
* Creates a Lambda handler for a router, for API Gateway (REST and HTTP
|
|
216
|
+
* APIs) and Lambda function URLs.
|
|
217
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#3-use-the-amazon-api-gateway-adapter
|
|
218
|
+
*/
|
|
214
219
|
function awsLambdaRequestHandler(opts) {
|
|
215
220
|
return async (event, context) => {
|
|
216
221
|
const planner = getPlanner(event);
|
|
@@ -234,6 +239,11 @@ function awsLambdaRequestHandler(opts) {
|
|
|
234
239
|
return await planner.toResult(response);
|
|
235
240
|
};
|
|
236
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Creates a Lambda handler that streams its response, for use with
|
|
244
|
+
* `awslambda.streamifyResponse()`.
|
|
245
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#aws-lambda-response-streaming-adapter
|
|
246
|
+
*/
|
|
237
247
|
function awsLambdaStreamingRequestHandler(opts) {
|
|
238
248
|
return async (event, responseStream, context) => {
|
|
239
249
|
const planner = getPlanner(event);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ln as TRPCRequestInfo, jn as HTTPBaseHandlerOptions, rr as inferRouterContext, ur as CreateContextCallback, zn as AnyRouter } from "../../unstable-core-do-not-import-
|
|
1
|
+
import { Ln as TRPCRequestInfo, jn as HTTPBaseHandlerOptions, rr as inferRouterContext, ur as CreateContextCallback, zn as AnyRouter } from "../../unstable-core-do-not-import-DrFOoxdW.cjs";
|
|
2
2
|
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context, StreamifyHandler } from "aws-lambda";
|
|
3
3
|
//#region src/adapters/aws-lambda/getPlanner.d.ts
|
|
4
4
|
type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
@@ -8,14 +8,37 @@ type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
|
8
8
|
type inferAPIGWReturn<TEvent> = TEvent extends APIGatewayProxyEvent ? APIGatewayProxyResult : TEvent extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/adapters/aws-lambda/index.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* What `createContext` gets in the AWS Lambda adapter: the event, the
|
|
13
|
+
* Lambda context and the request's `info`.
|
|
14
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#2-create-a-trpc-router
|
|
15
|
+
*/
|
|
11
16
|
export type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {
|
|
17
|
+
/** The API Gateway or function URL event. */
|
|
12
18
|
event: TEvent;
|
|
19
|
+
/** The Lambda invocation's context. */
|
|
13
20
|
context: Context;
|
|
14
21
|
info: TRPCRequestInfo;
|
|
15
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The options of `awsLambdaRequestHandler` and
|
|
25
|
+
* `awsLambdaStreamingRequestHandler`.
|
|
26
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda
|
|
27
|
+
*/
|
|
16
28
|
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends LambdaEvent> = HTTPBaseHandlerOptions<TRouter, TEvent> & CreateContextCallback<inferRouterContext<AnyRouter>, AWSLambdaCreateContextFn<TRouter, TEvent>>;
|
|
29
|
+
/** The `createContext` function the AWS Lambda adapter takes. */
|
|
17
30
|
export type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends LambdaEvent> = ({ event, context, info }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Lambda handler for a router, for API Gateway (REST and HTTP
|
|
33
|
+
* APIs) and Lambda function URLs.
|
|
34
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#3-use-the-amazon-api-gateway-adapter
|
|
35
|
+
*/
|
|
18
36
|
export declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends LambdaEvent>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: Context) => Promise<inferAPIGWReturn<TEvent>>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a Lambda handler that streams its response, for use with
|
|
39
|
+
* `awslambda.streamifyResponse()`.
|
|
40
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#aws-lambda-response-streaming-adapter
|
|
41
|
+
*/
|
|
19
42
|
export declare function awsLambdaStreamingRequestHandler<TRouter extends AnyRouter, TEvent extends LambdaEvent>(opts: AWSLambdaOptions<TRouter, TEvent>): StreamifyHandler<TEvent>;
|
|
20
43
|
//#endregion
|
|
21
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/aws-lambda/getPlanner.ts","../../../src/adapters/aws-lambda/index.ts"],"mappings":";;;KAUY,cAAc,uBAAuB;;;;KAqBrC,iBAAiB,UAAU,eAAe,uBAClD,wBACA,eAAe,yBACb
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/aws-lambda/getPlanner.ts","../../../src/adapters/aws-lambda/index.ts"],"mappings":";;;KAUY,cAAc,uBAAuB;;;;KAqBrC,iBAAiB,UAAU,eAAe,uBAClD,wBACA,eAAe,yBACb;;;;;;;;YCHM,8BAA8B,eAAe;;EAEvD,OAAO;;EAEP,SAAS;EACT,MAAM;;;;;;;YAQI,iBACV,gBAAgB,WAChB,eAAe,eACb,uBAAuB,SAAS,UAClC,sBACE,mBAAmB,YACnB,yBAAyB,SAAS;;YAI1B,yBACV,gBAAgB,WAChB,eAAe,kBAEf,OACA,SACA,QACC,8BAA8B,YAC7B,mBAAmB,WACnB,QAAQ,mBAAmB;;;;;;wBAOf,wBACd,gBAAgB,WAChB,eAAe,aAEf,MAAM,iBAAiB,SAAS,WAC9B,OAAO,QAAQ,SAAS,YAAiB,QAAQ,iBAAiB;;;;;;wBAiCtD,iCACd,gBAAgB,WAChB,eAAe,aACf,MAAM,iBAAiB,SAAS,UAAU,iBAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ln as TRPCRequestInfo, jn as HTTPBaseHandlerOptions, rr as inferRouterContext, ur as CreateContextCallback, zn as AnyRouter } from "../../unstable-core-do-not-import-
|
|
1
|
+
import { Ln as TRPCRequestInfo, jn as HTTPBaseHandlerOptions, rr as inferRouterContext, ur as CreateContextCallback, zn as AnyRouter } from "../../unstable-core-do-not-import-CLjKFqzt.mjs";
|
|
2
2
|
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context, StreamifyHandler } from "aws-lambda";
|
|
3
3
|
//#region src/adapters/aws-lambda/getPlanner.d.ts
|
|
4
4
|
type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
@@ -8,14 +8,37 @@ type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
|
8
8
|
type inferAPIGWReturn<TEvent> = TEvent extends APIGatewayProxyEvent ? APIGatewayProxyResult : TEvent extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/adapters/aws-lambda/index.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* What `createContext` gets in the AWS Lambda adapter: the event, the
|
|
13
|
+
* Lambda context and the request's `info`.
|
|
14
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#2-create-a-trpc-router
|
|
15
|
+
*/
|
|
11
16
|
export type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {
|
|
17
|
+
/** The API Gateway or function URL event. */
|
|
12
18
|
event: TEvent;
|
|
19
|
+
/** The Lambda invocation's context. */
|
|
13
20
|
context: Context;
|
|
14
21
|
info: TRPCRequestInfo;
|
|
15
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The options of `awsLambdaRequestHandler` and
|
|
25
|
+
* `awsLambdaStreamingRequestHandler`.
|
|
26
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda
|
|
27
|
+
*/
|
|
16
28
|
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends LambdaEvent> = HTTPBaseHandlerOptions<TRouter, TEvent> & CreateContextCallback<inferRouterContext<AnyRouter>, AWSLambdaCreateContextFn<TRouter, TEvent>>;
|
|
29
|
+
/** The `createContext` function the AWS Lambda adapter takes. */
|
|
17
30
|
export type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends LambdaEvent> = ({ event, context, info }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Lambda handler for a router, for API Gateway (REST and HTTP
|
|
33
|
+
* APIs) and Lambda function URLs.
|
|
34
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#3-use-the-amazon-api-gateway-adapter
|
|
35
|
+
*/
|
|
18
36
|
export declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends LambdaEvent>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: Context) => Promise<inferAPIGWReturn<TEvent>>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a Lambda handler that streams its response, for use with
|
|
39
|
+
* `awslambda.streamifyResponse()`.
|
|
40
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#aws-lambda-response-streaming-adapter
|
|
41
|
+
*/
|
|
19
42
|
export declare function awsLambdaStreamingRequestHandler<TRouter extends AnyRouter, TEvent extends LambdaEvent>(opts: AWSLambdaOptions<TRouter, TEvent>): StreamifyHandler<TEvent>;
|
|
20
43
|
//#endregion
|
|
21
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/aws-lambda/getPlanner.ts","../../../src/adapters/aws-lambda/index.ts"],"mappings":";;;KAUY,cAAc,uBAAuB;;;;KAqBrC,iBAAiB,UAAU,eAAe,uBAClD,wBACA,eAAe,yBACb
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/aws-lambda/getPlanner.ts","../../../src/adapters/aws-lambda/index.ts"],"mappings":";;;KAUY,cAAc,uBAAuB;;;;KAqBrC,iBAAiB,UAAU,eAAe,uBAClD,wBACA,eAAe,yBACb;;;;;;;;YCHM,8BAA8B,eAAe;;EAEvD,OAAO;;EAEP,SAAS;EACT,MAAM;;;;;;;YAQI,iBACV,gBAAgB,WAChB,eAAe,eACb,uBAAuB,SAAS,UAClC,sBACE,mBAAmB,YACnB,yBAAyB,SAAS;;YAI1B,yBACV,gBAAgB,WAChB,eAAe,kBAEf,OACA,SACA,QACC,8BAA8B,YAC7B,mBAAmB,WACnB,QAAQ,mBAAmB;;;;;;wBAOf,wBACd,gBAAgB,WAChB,eAAe,aAEf,MAAM,iBAAiB,SAAS,WAC9B,OAAO,QAAQ,SAAS,YAAiB,QAAQ,iBAAiB;;;;;;wBAiCtD,iCACd,gBAAgB,WAChB,eAAe,aACf,MAAM,iBAAiB,SAAS,UAAU,iBAAiB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as _objectSpread2 } from "../../getErrorShape-
|
|
2
|
-
import { t as resolveResponse } from "../../resolveResponse-
|
|
1
|
+
import { n as _objectSpread2 } from "../../getErrorShape-B6z8u8q0.mjs";
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-oG-tsWtT.mjs";
|
|
3
3
|
import { Readable } from "node:stream";
|
|
4
4
|
import { pipeline } from "node:stream/promises";
|
|
5
5
|
//#region src/vendor/cookie-es/set-cookie/split.ts
|
|
@@ -210,6 +210,11 @@ function getPlanner(event) {
|
|
|
210
210
|
}
|
|
211
211
|
//#endregion
|
|
212
212
|
//#region src/adapters/aws-lambda/index.ts
|
|
213
|
+
/**
|
|
214
|
+
* Creates a Lambda handler for a router, for API Gateway (REST and HTTP
|
|
215
|
+
* APIs) and Lambda function URLs.
|
|
216
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#3-use-the-amazon-api-gateway-adapter
|
|
217
|
+
*/
|
|
213
218
|
function awsLambdaRequestHandler(opts) {
|
|
214
219
|
return async (event, context) => {
|
|
215
220
|
const planner = getPlanner(event);
|
|
@@ -233,6 +238,11 @@ function awsLambdaRequestHandler(opts) {
|
|
|
233
238
|
return await planner.toResult(response);
|
|
234
239
|
};
|
|
235
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Creates a Lambda handler that streams its response, for use with
|
|
243
|
+
* `awslambda.streamifyResponse()`.
|
|
244
|
+
* @see https://trpc.io/docs/server/adapters/aws-lambda#aws-lambda-response-streaming-adapter
|
|
245
|
+
*/
|
|
236
246
|
function awsLambdaStreamingRequestHandler(opts) {
|
|
237
247
|
return async (event, responseStream, context) => {
|
|
238
248
|
const planner = getPlanner(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/vendor/cookie-es/set-cookie/split.ts","../../../src/adapters/aws-lambda/getPlanner.ts","../../../src/adapters/aws-lambda/index.ts"],"sourcesContent":["/**\n * Based on https://github.com/unjs/cookie-es/tree/v1.2.2\n * MIT License\n * \n * Cookie-es copyright (c) Pooya Parsa <pooya@pi0.io>\n * Set-Cookie parsing based on https://github.com/nfriedly/set-cookie-parser\n * Copyright (c) 2015 Nathan Friedly <nathan@nfriedly.com> (http://nfriedly.com/)\n * \n * @see https://github.com/unjs/cookie-es/blob/main/src/set-cookie/split.ts\n */\n\n/**\n * Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas\n * that are within a single set-cookie field-value, such as in the Expires portion.\n *\n * See https://tools.ietf.org/html/rfc2616#section-4.2\n */\nexport function splitSetCookieString(\n cookiesString: string | string[],\n ): string[] {\n if (Array.isArray(cookiesString)) {\n return cookiesString.flatMap((c) => splitSetCookieString(c));\n }\n \n if (typeof cookiesString !== \"string\") {\n return [];\n }\n \n const cookiesStrings: string[] = [];\n let pos: number = 0;\n let start: number;\n let ch: string;\n let lastComma: number;\n let nextStart: number;\n let cookiesSeparatorFound: boolean;\n \n const skipWhitespace = () => {\n while (pos < cookiesString.length && /\\s/.test(cookiesString.charAt(pos))) {\n pos += 1;\n }\n return pos < cookiesString.length;\n };\n \n const notSpecialChar = () => {\n ch = cookiesString.charAt(pos);\n return ch !== \"=\" && ch !== \";\" && ch !== \",\";\n };\n \n while (pos < cookiesString.length) {\n start = pos;\n cookiesSeparatorFound = false;\n \n while (skipWhitespace()) {\n ch = cookiesString.charAt(pos);\n if (ch === \",\") {\n // ',' is a cookie separator if we have later first '=', not ';' or ','\n lastComma = pos;\n pos += 1;\n \n skipWhitespace();\n nextStart = pos;\n \n while (pos < cookiesString.length && notSpecialChar()) {\n pos += 1;\n }\n \n // currently special character\n if (pos < cookiesString.length && cookiesString.charAt(pos) === \"=\") {\n // we found cookies separator\n cookiesSeparatorFound = true;\n // pos is inside the next cookie, so back up and return it.\n pos = nextStart;\n cookiesStrings.push(cookiesString.slice(start, lastComma));\n start = pos;\n } else {\n // in param ',' or param separator ';',\n // we continue from that comma\n pos = lastComma + 1;\n }\n } else {\n pos += 1;\n }\n }\n \n if (!cookiesSeparatorFound || pos >= cookiesString.length) {\n cookiesStrings.push(cookiesString.slice(start));\n }\n }\n \n return cookiesStrings;\n }","import { Readable, type Writable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport type {\n APIGatewayProxyEvent,\n APIGatewayProxyEventV2,\n APIGatewayProxyResult,\n APIGatewayProxyStructuredResultV2,\n} from 'aws-lambda';\nimport { splitSetCookieString } from '../../vendor/cookie-es/set-cookie/split';\n\nexport type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;\n\nexport type APIGatewayResult =\n | APIGatewayProxyResult\n | APIGatewayProxyStructuredResultV2;\n\nfunction determinePayloadFormat(event: LambdaEvent): string {\n // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html\n // According to AWS support, version is extracted from the version property in the event.\n // If there is no version property, then the version is implied as 1.0\n const unknownEvent = event as { version?: string };\n if (typeof unknownEvent.version === 'undefined') {\n return '1.0';\n } else {\n return unknownEvent.version;\n }\n}\n\n/** 1:1 mapping of v1 or v2 input events, deduces which is which.\n * @internal\n **/\nexport type inferAPIGWReturn<TEvent> = TEvent extends APIGatewayProxyEvent\n ? APIGatewayProxyResult\n : TEvent extends APIGatewayProxyEventV2\n ? APIGatewayProxyStructuredResultV2\n : never;\n\ninterface Processor<TEvent extends LambdaEvent> {\n getTRPCPath: (event: TEvent) => string;\n url(event: TEvent): Pick<URL, 'hostname' | 'pathname' | 'search'>;\n getHeaders: (event: TEvent) => Headers;\n getMethod: (event: TEvent) => string;\n toResult: (response: Response) => Promise<inferAPIGWReturn<TEvent>>;\n toStream: (response: Response, stream: Writable) => Promise<void>;\n}\n\nfunction getHeadersAndCookiesFromResponse(response: Response) {\n const headers = Object.fromEntries(response.headers.entries());\n\n const cookies: string[] = splitSetCookieString(\n response.headers.getSetCookie(),\n ).map((cookie) => cookie.trim());\n\n delete headers['set-cookie'];\n\n return { headers, cookies };\n}\n\nconst v1Processor: Processor<APIGatewayProxyEvent> = {\n // same as getPath above\n getTRPCPath: (event) => {\n if (!event.pathParameters) {\n // Then this event was not triggered by a resource denoted with {proxy+}\n return event.path.split('/').pop() ?? '';\n }\n const matches = event.resource.matchAll(/\\{(.*?)\\}/g);\n for (const match of matches) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const group = match[1]!;\n if (group.includes('+') && event.pathParameters) {\n return event.pathParameters[group.replace('+', '')] ?? '';\n }\n }\n return event.path.slice(1);\n },\n url(event) {\n const hostname: string =\n event.requestContext.domainName ??\n event.headers['host'] ??\n event.multiValueHeaders?.['host']?.[0] ??\n 'localhost';\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(\n event.queryStringParameters ?? {},\n )) {\n if (value !== undefined) {\n searchParams.append(key, value);\n }\n }\n const qs = searchParams.toString();\n return {\n hostname,\n pathname: event.path,\n search: qs && `?${qs}`,\n };\n },\n getHeaders: (event) => {\n const headers = new Headers();\n\n // Process multiValueHeaders first (takes precedence per AWS docs)\n // This handles headers that can have multiple values\n for (const [k, values] of Object.entries(event.multiValueHeaders ?? {})) {\n if (values) {\n values.forEach((v) => headers.append(k, v));\n }\n }\n\n // Then process single-value headers, but skip any that were already\n // added from multiValueHeaders to avoid duplication\n for (const [key, value] of Object.entries(event.headers ?? {})) {\n if (value !== undefined && !headers.has(key)) {\n headers.append(key, value);\n }\n }\n\n return headers;\n },\n getMethod: (event) => event.httpMethod,\n toResult: async (response) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const result: APIGatewayProxyResult = {\n ...(cookies.length && { multiValueHeaders: { 'set-cookie': cookies } }),\n statusCode: response.status,\n body: await response.text(),\n headers,\n };\n\n return result;\n },\n toStream: async (response, stream) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const metadata = {\n statusCode: response.status,\n headers,\n cookies,\n };\n\n const responseStream = awslambda.HttpResponseStream.from(stream, metadata);\n\n if (response.body) {\n await pipeline(Readable.fromWeb(response.body as any), responseStream);\n } else {\n responseStream.end();\n }\n },\n};\n\nconst v2Processor: Processor<APIGatewayProxyEventV2> = {\n getTRPCPath: (event) => {\n const matches = event.routeKey.matchAll(/\\{(.*?)\\}/g);\n for (const match of matches) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const group = match[1]!;\n if (group.includes('+') && event.pathParameters) {\n return event.pathParameters[group.replace('+', '')] ?? '';\n }\n }\n return event.rawPath.slice(1);\n },\n url(event) {\n return {\n hostname: event.requestContext.domainName,\n pathname: event.rawPath,\n search: event.rawQueryString && `?${event.rawQueryString}`,\n };\n },\n getHeaders: (event) => {\n const headers = new Headers();\n for (const [key, value] of Object.entries(event.headers ?? {})) {\n if (value !== undefined) {\n headers.append(key, value);\n }\n }\n\n if (event.cookies) {\n headers.append('cookie', event.cookies.join('; '));\n }\n return headers;\n },\n getMethod: (event) => event.requestContext.http.method,\n toResult: async (response) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const result: APIGatewayProxyStructuredResultV2 = {\n cookies,\n statusCode: response.status,\n body: await response.text(),\n headers,\n };\n\n return result;\n },\n\n toStream: async (response, stream) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const metadata = {\n statusCode: response.status,\n headers,\n cookies,\n };\n\n const responseStream = awslambda.HttpResponseStream.from(stream, metadata);\n\n if (response.body) {\n await pipeline(Readable.fromWeb(response.body as any), responseStream);\n } else {\n responseStream.end();\n }\n },\n};\n\nexport function getPlanner<TEvent extends LambdaEvent>(event: TEvent) {\n const version = determinePayloadFormat(event);\n let processor: Processor<TEvent>;\n switch (version) {\n case '1.0':\n processor = v1Processor as Processor<TEvent>;\n break;\n case '2.0':\n processor = v2Processor as Processor<TEvent>;\n break;\n default:\n throw new Error(`Unsupported version: ${version}`);\n }\n\n const urlParts = processor.url(event);\n const url = `https://${urlParts.hostname}${urlParts.pathname}${urlParts.search}`;\n\n const init: RequestInit = {\n headers: processor.getHeaders(event),\n method: processor.getMethod(event),\n // @ts-expect-error this is fine\n duplex: 'half',\n };\n if (event.body) {\n init.body = event.isBase64Encoded\n ? Buffer.from(event.body, 'base64')\n : event.body;\n }\n\n const request = new Request(url, init);\n\n return {\n path: processor.getTRPCPath(event),\n request,\n toResult: processor.toResult,\n toStream: processor.toStream,\n };\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 */\nimport type { Context as APIGWContext, StreamifyHandler } from 'aws-lambda';\n// @trpc/server\nimport type {\n AnyRouter,\n CreateContextCallback,\n inferRouterContext,\n} from '../../@trpc/server';\n// @trpc/server\nimport type {\n HTTPBaseHandlerOptions,\n ResolveHTTPRequestOptionsContextFn,\n TRPCRequestInfo,\n} from '../../@trpc/server/http';\nimport { resolveResponse } from '../../@trpc/server/http';\nimport type { inferAPIGWReturn, LambdaEvent } from './getPlanner';\nimport { getPlanner } from './getPlanner';\n\nexport type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {\n event: TEvent;\n context: APIGWContext;\n info: TRPCRequestInfo;\n};\n\nexport type AWSLambdaOptions<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n> = HTTPBaseHandlerOptions<TRouter, TEvent> &\n CreateContextCallback<\n inferRouterContext<AnyRouter>,\n AWSLambdaCreateContextFn<TRouter, TEvent>\n >;\n\nexport type AWSLambdaCreateContextFn<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n> = ({\n event,\n context,\n info,\n}: CreateAWSLambdaContextOptions<TEvent>) =>\n | inferRouterContext<TRouter>\n | Promise<inferRouterContext<TRouter>>;\n\nexport function awsLambdaRequestHandler<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n>(\n opts: AWSLambdaOptions<TRouter, TEvent>,\n): (event: TEvent, context: APIGWContext) => Promise<inferAPIGWReturn<TEvent>> {\n return async (event, context) => {\n const planner = getPlanner(event);\n\n const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (\n innerOpts,\n ) => {\n return await opts.createContext?.({ event, context, ...innerOpts });\n };\n\n const response = await resolveResponse({\n ...opts,\n createContext,\n req: planner.request,\n path: planner.path,\n error: null,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: event,\n });\n },\n });\n\n return await planner.toResult(response);\n };\n}\n\nexport function awsLambdaStreamingRequestHandler<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n>(opts: AWSLambdaOptions<TRouter, TEvent>): StreamifyHandler<TEvent> {\n return async (event, responseStream, context) => {\n const planner = getPlanner(event);\n\n const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (\n innerOpts,\n ) => {\n return await opts.createContext?.({ event, context, ...innerOpts });\n };\n\n const response = await resolveResponse({\n ...opts,\n createContext,\n req: planner.request,\n path: planner.path,\n error: null,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: event,\n });\n },\n });\n\n await planner.toStream(response, respon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BAA6D,OACjE,cACG;;GACH,OAAO,QAAA,uBAAM,KAAK,mBAAA,QAAA,yBAAA,KAAA,IAAA,KAAA,IAAA,qBAAA,KAAA,MAAA,eAAA;IAAkB;IAAO;GAAY,GAAA,SAAU,CAAC;EACpE;EAEA,MAAM,WAAW,MAAM,gBAAA,eAAA,eAAA,CAAA,GAClB,IAAA,GAAA,CAAA,GAAA;GACH;GACA,KAAK,QAAQ;GACb,MAAM,QAAQ;GACd,OAAO;GACP,QAAQ,GAAG;;IACT,SAAA,QAAA,SAAA,KAAA,MAAA,iBAAA,KAAM,aAAA,QAAA,mBAAA,KAAA,KAAA,eAAA,KAAA,MAAA,eAAA,eAAA,CAAA,GACD,CAAA,GAAA,CAAA,GAAA,EACH,KAAK,MAAA,CACP,CAAC;GACH;EACF,CAAA,CAAC;EAED,MAAM,QAAQ,SAAS,UAAU,cAAc;CACjD;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/vendor/cookie-es/set-cookie/split.ts","../../../src/adapters/aws-lambda/getPlanner.ts","../../../src/adapters/aws-lambda/index.ts"],"sourcesContent":["/**\n * Based on https://github.com/unjs/cookie-es/tree/v1.2.2\n * MIT License\n * \n * Cookie-es copyright (c) Pooya Parsa <pooya@pi0.io>\n * Set-Cookie parsing based on https://github.com/nfriedly/set-cookie-parser\n * Copyright (c) 2015 Nathan Friedly <nathan@nfriedly.com> (http://nfriedly.com/)\n * \n * @see https://github.com/unjs/cookie-es/blob/main/src/set-cookie/split.ts\n */\n\n/**\n * Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas\n * that are within a single set-cookie field-value, such as in the Expires portion.\n *\n * See https://tools.ietf.org/html/rfc2616#section-4.2\n */\nexport function splitSetCookieString(\n cookiesString: string | string[],\n ): string[] {\n if (Array.isArray(cookiesString)) {\n return cookiesString.flatMap((c) => splitSetCookieString(c));\n }\n \n if (typeof cookiesString !== \"string\") {\n return [];\n }\n \n const cookiesStrings: string[] = [];\n let pos: number = 0;\n let start: number;\n let ch: string;\n let lastComma: number;\n let nextStart: number;\n let cookiesSeparatorFound: boolean;\n \n const skipWhitespace = () => {\n while (pos < cookiesString.length && /\\s/.test(cookiesString.charAt(pos))) {\n pos += 1;\n }\n return pos < cookiesString.length;\n };\n \n const notSpecialChar = () => {\n ch = cookiesString.charAt(pos);\n return ch !== \"=\" && ch !== \";\" && ch !== \",\";\n };\n \n while (pos < cookiesString.length) {\n start = pos;\n cookiesSeparatorFound = false;\n \n while (skipWhitespace()) {\n ch = cookiesString.charAt(pos);\n if (ch === \",\") {\n // ',' is a cookie separator if we have later first '=', not ';' or ','\n lastComma = pos;\n pos += 1;\n \n skipWhitespace();\n nextStart = pos;\n \n while (pos < cookiesString.length && notSpecialChar()) {\n pos += 1;\n }\n \n // currently special character\n if (pos < cookiesString.length && cookiesString.charAt(pos) === \"=\") {\n // we found cookies separator\n cookiesSeparatorFound = true;\n // pos is inside the next cookie, so back up and return it.\n pos = nextStart;\n cookiesStrings.push(cookiesString.slice(start, lastComma));\n start = pos;\n } else {\n // in param ',' or param separator ';',\n // we continue from that comma\n pos = lastComma + 1;\n }\n } else {\n pos += 1;\n }\n }\n \n if (!cookiesSeparatorFound || pos >= cookiesString.length) {\n cookiesStrings.push(cookiesString.slice(start));\n }\n }\n \n return cookiesStrings;\n }","import { Readable, type Writable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport type {\n APIGatewayProxyEvent,\n APIGatewayProxyEventV2,\n APIGatewayProxyResult,\n APIGatewayProxyStructuredResultV2,\n} from 'aws-lambda';\nimport { splitSetCookieString } from '../../vendor/cookie-es/set-cookie/split';\n\nexport type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;\n\nexport type APIGatewayResult =\n | APIGatewayProxyResult\n | APIGatewayProxyStructuredResultV2;\n\nfunction determinePayloadFormat(event: LambdaEvent): string {\n // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html\n // According to AWS support, version is extracted from the version property in the event.\n // If there is no version property, then the version is implied as 1.0\n const unknownEvent = event as { version?: string };\n if (typeof unknownEvent.version === 'undefined') {\n return '1.0';\n } else {\n return unknownEvent.version;\n }\n}\n\n/** 1:1 mapping of v1 or v2 input events, deduces which is which.\n * @internal\n **/\nexport type inferAPIGWReturn<TEvent> = TEvent extends APIGatewayProxyEvent\n ? APIGatewayProxyResult\n : TEvent extends APIGatewayProxyEventV2\n ? APIGatewayProxyStructuredResultV2\n : never;\n\ninterface Processor<TEvent extends LambdaEvent> {\n getTRPCPath: (event: TEvent) => string;\n url(event: TEvent): Pick<URL, 'hostname' | 'pathname' | 'search'>;\n getHeaders: (event: TEvent) => Headers;\n getMethod: (event: TEvent) => string;\n toResult: (response: Response) => Promise<inferAPIGWReturn<TEvent>>;\n toStream: (response: Response, stream: Writable) => Promise<void>;\n}\n\nfunction getHeadersAndCookiesFromResponse(response: Response) {\n const headers = Object.fromEntries(response.headers.entries());\n\n const cookies: string[] = splitSetCookieString(\n response.headers.getSetCookie(),\n ).map((cookie) => cookie.trim());\n\n delete headers['set-cookie'];\n\n return { headers, cookies };\n}\n\nconst v1Processor: Processor<APIGatewayProxyEvent> = {\n // same as getPath above\n getTRPCPath: (event) => {\n if (!event.pathParameters) {\n // Then this event was not triggered by a resource denoted with {proxy+}\n return event.path.split('/').pop() ?? '';\n }\n const matches = event.resource.matchAll(/\\{(.*?)\\}/g);\n for (const match of matches) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const group = match[1]!;\n if (group.includes('+') && event.pathParameters) {\n return event.pathParameters[group.replace('+', '')] ?? '';\n }\n }\n return event.path.slice(1);\n },\n url(event) {\n const hostname: string =\n event.requestContext.domainName ??\n event.headers['host'] ??\n event.multiValueHeaders?.['host']?.[0] ??\n 'localhost';\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(\n event.queryStringParameters ?? {},\n )) {\n if (value !== undefined) {\n searchParams.append(key, value);\n }\n }\n const qs = searchParams.toString();\n return {\n hostname,\n pathname: event.path,\n search: qs && `?${qs}`,\n };\n },\n getHeaders: (event) => {\n const headers = new Headers();\n\n // Process multiValueHeaders first (takes precedence per AWS docs)\n // This handles headers that can have multiple values\n for (const [k, values] of Object.entries(event.multiValueHeaders ?? {})) {\n if (values) {\n values.forEach((v) => headers.append(k, v));\n }\n }\n\n // Then process single-value headers, but skip any that were already\n // added from multiValueHeaders to avoid duplication\n for (const [key, value] of Object.entries(event.headers ?? {})) {\n if (value !== undefined && !headers.has(key)) {\n headers.append(key, value);\n }\n }\n\n return headers;\n },\n getMethod: (event) => event.httpMethod,\n toResult: async (response) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const result: APIGatewayProxyResult = {\n ...(cookies.length && { multiValueHeaders: { 'set-cookie': cookies } }),\n statusCode: response.status,\n body: await response.text(),\n headers,\n };\n\n return result;\n },\n toStream: async (response, stream) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const metadata = {\n statusCode: response.status,\n headers,\n cookies,\n };\n\n const responseStream = awslambda.HttpResponseStream.from(stream, metadata);\n\n if (response.body) {\n await pipeline(Readable.fromWeb(response.body as any), responseStream);\n } else {\n responseStream.end();\n }\n },\n};\n\nconst v2Processor: Processor<APIGatewayProxyEventV2> = {\n getTRPCPath: (event) => {\n const matches = event.routeKey.matchAll(/\\{(.*?)\\}/g);\n for (const match of matches) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const group = match[1]!;\n if (group.includes('+') && event.pathParameters) {\n return event.pathParameters[group.replace('+', '')] ?? '';\n }\n }\n return event.rawPath.slice(1);\n },\n url(event) {\n return {\n hostname: event.requestContext.domainName,\n pathname: event.rawPath,\n search: event.rawQueryString && `?${event.rawQueryString}`,\n };\n },\n getHeaders: (event) => {\n const headers = new Headers();\n for (const [key, value] of Object.entries(event.headers ?? {})) {\n if (value !== undefined) {\n headers.append(key, value);\n }\n }\n\n if (event.cookies) {\n headers.append('cookie', event.cookies.join('; '));\n }\n return headers;\n },\n getMethod: (event) => event.requestContext.http.method,\n toResult: async (response) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const result: APIGatewayProxyStructuredResultV2 = {\n cookies,\n statusCode: response.status,\n body: await response.text(),\n headers,\n };\n\n return result;\n },\n\n toStream: async (response, stream) => {\n const { headers, cookies } = getHeadersAndCookiesFromResponse(response);\n\n const metadata = {\n statusCode: response.status,\n headers,\n cookies,\n };\n\n const responseStream = awslambda.HttpResponseStream.from(stream, metadata);\n\n if (response.body) {\n await pipeline(Readable.fromWeb(response.body as any), responseStream);\n } else {\n responseStream.end();\n }\n },\n};\n\nexport function getPlanner<TEvent extends LambdaEvent>(event: TEvent) {\n const version = determinePayloadFormat(event);\n let processor: Processor<TEvent>;\n switch (version) {\n case '1.0':\n processor = v1Processor as Processor<TEvent>;\n break;\n case '2.0':\n processor = v2Processor as Processor<TEvent>;\n break;\n default:\n throw new Error(`Unsupported version: ${version}`);\n }\n\n const urlParts = processor.url(event);\n const url = `https://${urlParts.hostname}${urlParts.pathname}${urlParts.search}`;\n\n const init: RequestInit = {\n headers: processor.getHeaders(event),\n method: processor.getMethod(event),\n // @ts-expect-error this is fine\n duplex: 'half',\n };\n if (event.body) {\n init.body = event.isBase64Encoded\n ? Buffer.from(event.body, 'base64')\n : event.body;\n }\n\n const request = new Request(url, init);\n\n return {\n path: processor.getTRPCPath(event),\n request,\n toResult: processor.toResult,\n toStream: processor.toStream,\n };\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 */\nimport type { Context as APIGWContext, StreamifyHandler } from 'aws-lambda';\n// @trpc/server\nimport type {\n AnyRouter,\n CreateContextCallback,\n inferRouterContext,\n} from '../../@trpc/server';\n// @trpc/server\nimport type {\n HTTPBaseHandlerOptions,\n ResolveHTTPRequestOptionsContextFn,\n TRPCRequestInfo,\n} from '../../@trpc/server/http';\nimport { resolveResponse } from '../../@trpc/server/http';\nimport type { inferAPIGWReturn, LambdaEvent } from './getPlanner';\nimport { getPlanner } from './getPlanner';\n\n/**\n * What `createContext` gets in the AWS Lambda adapter: the event, the\n * Lambda context and the request's `info`.\n * @see https://trpc.io/docs/server/adapters/aws-lambda#2-create-a-trpc-router\n */\nexport type CreateAWSLambdaContextOptions<TEvent extends LambdaEvent> = {\n /** The API Gateway or function URL event. */\n event: TEvent;\n /** The Lambda invocation's context. */\n context: APIGWContext;\n info: TRPCRequestInfo;\n};\n\n/**\n * The options of `awsLambdaRequestHandler` and\n * `awsLambdaStreamingRequestHandler`.\n * @see https://trpc.io/docs/server/adapters/aws-lambda\n */\nexport type AWSLambdaOptions<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n> = HTTPBaseHandlerOptions<TRouter, TEvent> &\n CreateContextCallback<\n inferRouterContext<AnyRouter>,\n AWSLambdaCreateContextFn<TRouter, TEvent>\n >;\n\n/** The `createContext` function the AWS Lambda adapter takes. */\nexport type AWSLambdaCreateContextFn<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n> = ({\n event,\n context,\n info,\n}: CreateAWSLambdaContextOptions<TEvent>) =>\n | inferRouterContext<TRouter>\n | Promise<inferRouterContext<TRouter>>;\n\n/**\n * Creates a Lambda handler for a router, for API Gateway (REST and HTTP\n * APIs) and Lambda function URLs.\n * @see https://trpc.io/docs/server/adapters/aws-lambda#3-use-the-amazon-api-gateway-adapter\n */\nexport function awsLambdaRequestHandler<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n>(\n opts: AWSLambdaOptions<TRouter, TEvent>,\n): (event: TEvent, context: APIGWContext) => Promise<inferAPIGWReturn<TEvent>> {\n return async (event, context) => {\n const planner = getPlanner(event);\n\n const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (\n innerOpts,\n ) => {\n return await opts.createContext?.({ event, context, ...innerOpts });\n };\n\n const response = await resolveResponse({\n ...opts,\n createContext,\n req: planner.request,\n path: planner.path,\n error: null,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: event,\n });\n },\n });\n\n return await planner.toResult(response);\n };\n}\n\n/**\n * Creates a Lambda handler that streams its response, for use with\n * `awslambda.streamifyResponse()`.\n * @see https://trpc.io/docs/server/adapters/aws-lambda#aws-lambda-response-streaming-adapter\n */\nexport function awsLambdaStreamingRequestHandler<\n TRouter extends AnyRouter,\n TEvent extends LambdaEvent,\n>(opts: AWSLambdaOptions<TRouter, TEvent>): StreamifyHandler<TEvent> {\n return async (event, responseStream, context) => {\n const planner = getPlanner(event);\n\n const createContext: ResolveHTTPRequestOptionsContextFn<TRouter> = async (\n innerOpts,\n ) => {\n return await opts.createContext?.({ event, context, ...innerOpts });\n };\n\n const response = await resolveResponse({\n ...opts,\n createContext,\n req: planner.request,\n path: planner.path,\n error: null,\n onError(o) {\n opts?.onError?.({\n ...o,\n req: event,\n });\n },\n });\n\n await planner.toStream(response, responseStream);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,qBACZ,eACU;CACV,IAAI,MAAM,QAAQ,aAAa,GAC7B,OAAO,cAAc,SAAS,MAAM,qBAAqB,CAAC,CAAC;CAG7D,IAAI,OAAO,kBAAkB,UAC3B,OAAO,CAAC;CAGV,MAAM,iBAA2B,CAAC;CAClC,IAAI,MAAc;CAClB,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,MAAM,uBAAuB;EAC3B,OAAO,MAAM,cAAc,UAAU,KAAK,KAAK,cAAc,OAAO,GAAG,CAAC,GACtE,OAAO;EAET,OAAO,MAAM,cAAc;CAC7B;CAEA,MAAM,uBAAuB;EAC3B,KAAK,cAAc,OAAO,GAAG;EAC7B,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO;CAC5C;CAEA,OAAO,MAAM,cAAc,QAAQ;EACjC,QAAQ;EACR,wBAAwB;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1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_codes = require("../codes-
|
|
3
|
-
const require_getErrorShape = require("../getErrorShape-
|
|
4
|
-
const require_node_http = require("../node-http-
|
|
2
|
+
const require_codes = require("../codes-Be-DrYMh.cjs");
|
|
3
|
+
const require_getErrorShape = require("../getErrorShape-8t0oLscZ.cjs");
|
|
4
|
+
const require_node_http = require("../node-http-IgvbwDdQ.cjs");
|
|
5
5
|
//#region src/adapters/express.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates an Express middleware that serves a router. Mount it on a path,
|
|
8
|
+
* such as `/trpc`.
|
|
9
|
+
* @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter
|
|
10
|
+
*/
|
|
6
11
|
function createExpressMiddleware(opts) {
|
|
7
12
|
return (req, res) => {
|
|
8
13
|
let path = "";
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import { zn as AnyRouter } from "../unstable-core-do-not-import-
|
|
2
|
-
import { c as NodeHTTPHandlerOptions, o as NodeHTTPCreateContextFnOptions } from "../index-
|
|
1
|
+
import { zn as AnyRouter } from "../unstable-core-do-not-import-DrFOoxdW.cjs";
|
|
2
|
+
import { c as NodeHTTPHandlerOptions, o as NodeHTTPCreateContextFnOptions } from "../index-BjG3DNaL.cjs";
|
|
3
3
|
import * as express from "express";
|
|
4
4
|
//#region src/adapters/express.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* What `createContext` gets in the Express adapter: `req`, `res` and the
|
|
7
|
+
* request's `info`.
|
|
8
|
+
* @see https://trpc.io/docs/server/adapters/express#2-create-a-trpc-router
|
|
9
|
+
*/
|
|
5
10
|
export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<express.Request, express.Response>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an Express middleware that serves a router. Mount it on a path,
|
|
13
|
+
* such as `/trpc`.
|
|
14
|
+
* @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter
|
|
15
|
+
*/
|
|
6
16
|
export declare function createExpressMiddleware<TRouter extends AnyRouter>(opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>): express.Handler;
|
|
7
17
|
//#endregion
|
|
8
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.cts","names":[],"sources":["../../src/adapters/express.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.d.cts","names":[],"sources":["../../src/adapters/express.ts"],"mappings":";;;;;;;;;YAwBY,8BAA8B,+BACxC,QAAQ,SACR,QAAQ;;;;;;wBAQM,wBAAwB,gBAAgB,WACtD,MAAM,uBAAuB,SAAS,QAAQ,SAAS,QAAQ,YAC9D,QAAQ"}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import { zn as AnyRouter } from "../unstable-core-do-not-import-
|
|
2
|
-
import { c as NodeHTTPHandlerOptions, o as NodeHTTPCreateContextFnOptions } from "../index-
|
|
1
|
+
import { zn as AnyRouter } from "../unstable-core-do-not-import-CLjKFqzt.mjs";
|
|
2
|
+
import { c as NodeHTTPHandlerOptions, o as NodeHTTPCreateContextFnOptions } from "../index-vR2bVSvk.mjs";
|
|
3
3
|
import * as express from "express";
|
|
4
4
|
//#region src/adapters/express.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* What `createContext` gets in the Express adapter: `req`, `res` and the
|
|
7
|
+
* request's `info`.
|
|
8
|
+
* @see https://trpc.io/docs/server/adapters/express#2-create-a-trpc-router
|
|
9
|
+
*/
|
|
5
10
|
export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<express.Request, express.Response>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an Express middleware that serves a router. Mount it on a path,
|
|
13
|
+
* such as `/trpc`.
|
|
14
|
+
* @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter
|
|
15
|
+
*/
|
|
6
16
|
export declare function createExpressMiddleware<TRouter extends AnyRouter>(opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>): express.Handler;
|
|
7
17
|
//#endregion
|
|
8
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.mts","names":[],"sources":["../../src/adapters/express.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.d.mts","names":[],"sources":["../../src/adapters/express.ts"],"mappings":";;;;;;;;;YAwBY,8BAA8B,+BACxC,QAAQ,SACR,QAAQ;;;;;;wBAQM,wBAAwB,gBAAgB,WACtD,MAAM,uBAAuB,SAAS,QAAQ,SAAS,QAAQ,YAC9D,QAAQ"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { m as run } from "../codes-
|
|
2
|
-
import { n as _objectSpread2 } from "../getErrorShape-
|
|
3
|
-
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-
|
|
1
|
+
import { m as run } from "../codes-nbrm_zWY.mjs";
|
|
2
|
+
import { n as _objectSpread2 } from "../getErrorShape-B6z8u8q0.mjs";
|
|
3
|
+
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-CRKoQOwy.mjs";
|
|
4
4
|
//#region src/adapters/express.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates an Express middleware that serves a router. Mount it on a path,
|
|
7
|
+
* such as `/trpc`.
|
|
8
|
+
* @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter
|
|
9
|
+
*/
|
|
5
10
|
function createExpressMiddleware(opts) {
|
|
6
11
|
return (req, res) => {
|
|
7
12
|
let path = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.mjs","names":[],"sources":["../../src/adapters/express.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 * as express from 'express';\nimport type { AnyRouter } from '../@trpc/server';\n// oxlint-disable-next-line no-restricted-imports\nimport { run } from '../unstable-core-do-not-import';\nimport type {\n NodeHTTPCreateContextFnOptions,\n NodeHTTPHandlerOptions,\n} from './node-http';\nimport { internal_exceptionHandler, nodeHTTPRequestHandler } from './node-http';\n\nexport type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<\n express.Request,\n express.Response\n>;\n\nexport function createExpressMiddleware<TRouter extends AnyRouter>(\n opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>,\n): express.Handler {\n return (req, res) => {\n let path = '';\n run(async () => {\n path = req.path.slice(req.path.lastIndexOf('/') + 1);\n\n await nodeHTTPRequestHandler({\n ...opts,\n req,\n res,\n path,\n });\n }).catch(\n internal_exceptionHandler({\n req,\n res,\n path,\n ...opts,\n }),\n );\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"express.mjs","names":[],"sources":["../../src/adapters/express.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 * as express from 'express';\nimport type { AnyRouter } from '../@trpc/server';\n// oxlint-disable-next-line no-restricted-imports\nimport { run } from '../unstable-core-do-not-import';\nimport type {\n NodeHTTPCreateContextFnOptions,\n NodeHTTPHandlerOptions,\n} from './node-http';\nimport { internal_exceptionHandler, nodeHTTPRequestHandler } from './node-http';\n\n/**\n * What `createContext` gets in the Express adapter: `req`, `res` and the\n * request's `info`.\n * @see https://trpc.io/docs/server/adapters/express#2-create-a-trpc-router\n */\nexport type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<\n express.Request,\n express.Response\n>;\n\n/**\n * Creates an Express middleware that serves a router. Mount it on a path,\n * such as `/trpc`.\n * @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter\n */\nexport function createExpressMiddleware<TRouter extends AnyRouter>(\n opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>,\n): express.Handler {\n return (req, res) => {\n let path = '';\n run(async () => {\n path = req.path.slice(req.path.lastIndexOf('/') + 1);\n\n await nodeHTTPRequestHandler({\n ...opts,\n req,\n res,\n path,\n });\n }).catch(\n internal_exceptionHandler({\n req,\n res,\n path,\n ...opts,\n }),\n );\n };\n}\n"],"mappings":";;;;;;;;;AAkCA,SAAgB,wBACd,MACiB;CACjB,QAAQ,KAAK,QAAQ;EACnB,IAAI,OAAO;EACX,IAAI,YAAY;GACd,OAAO,IAAI,KAAK,MAAM,IAAI,KAAK,YAAY,GAAG,IAAI,CAAC;GAEnD,MAAM,uBAAA,eAAA,eAAA,CAAA,GACD,IAAA,GAAA,CAAA,GAAA;IACH;IACA;IACA;GACF,CAAA,CAAC;EACH,CAAC,CAAC,CAAC,MACD,0BAAA,eAAA;GACE;GACA;GACA;EACG,GAAA,IACL,CAAC,CACH;CACF;AACF"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_getErrorShape = require("../../getErrorShape-
|
|
3
|
-
const require_resolveResponse = require("../../resolveResponse-
|
|
4
|
-
const require_node_http = require("../../node-http-
|
|
5
|
-
const require_ws = require("../../ws-
|
|
2
|
+
const require_getErrorShape = require("../../getErrorShape-8t0oLscZ.cjs");
|
|
3
|
+
const require_resolveResponse = require("../../resolveResponse-D2d2y6BC.cjs");
|
|
4
|
+
const require_node_http = require("../../node-http-IgvbwDdQ.cjs");
|
|
5
|
+
const require_ws = require("../../ws-TUtpQwOX.cjs");
|
|
6
6
|
//#region src/adapters/fastify/fastifyRequestHandler.ts
|
|
7
|
+
/**
|
|
8
|
+
* Handles one Fastify request for a router. `fastifyTRPCPlugin` uses it;
|
|
9
|
+
* call it yourself to mount tRPC on your own route.
|
|
10
|
+
*/
|
|
7
11
|
async function fastifyRequestHandler(opts) {
|
|
8
12
|
const createContext = async (innerOpts) => {
|
|
9
13
|
var _opts$createContext;
|
|
@@ -25,6 +29,18 @@ async function fastifyRequestHandler(opts) {
|
|
|
25
29
|
}
|
|
26
30
|
//#endregion
|
|
27
31
|
//#region src/adapters/fastify/fastifyTRPCPlugin.ts
|
|
32
|
+
/**
|
|
33
|
+
* A Fastify plugin that serves a router over HTTP, and over WebSockets
|
|
34
|
+
* with `useWSS`.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* server.register(fastifyTRPCPlugin, {
|
|
38
|
+
* prefix: '/trpc',
|
|
39
|
+
* trpcOptions: { router: appRouter, createContext },
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
* @see https://trpc.io/docs/server/adapters/fastify#create-fastify-server
|
|
43
|
+
*/
|
|
28
44
|
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
29
45
|
var _opts$prefix;
|
|
30
46
|
fastify.removeContentTypeParser("application/json");
|
|
@@ -1,26 +1,60 @@
|
|
|
1
|
-
import { jn as HTTPBaseHandlerOptions, zn as AnyRouter } from "../../unstable-core-do-not-import-
|
|
2
|
-
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-
|
|
3
|
-
import { i as WSSHandlerOptions } from "../../ws-
|
|
1
|
+
import { jn as HTTPBaseHandlerOptions, zn as AnyRouter } from "../../unstable-core-do-not-import-DrFOoxdW.cjs";
|
|
2
|
+
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-BjG3DNaL.cjs";
|
|
3
|
+
import { i as WSSHandlerOptions } from "../../ws-CDC5vYSF.cjs";
|
|
4
4
|
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
5
5
|
//#region src/adapters/fastify/fastifyRequestHandler.d.ts
|
|
6
|
+
/** The options of the Fastify adapter's request handler. */
|
|
6
7
|
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
7
8
|
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
8
9
|
req: TRequest;
|
|
9
10
|
res: TResponse;
|
|
10
11
|
path: string;
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Handles one Fastify request for a router. `fastifyTRPCPlugin` uses it;
|
|
15
|
+
* call it yourself to mount tRPC on your own route.
|
|
16
|
+
*/
|
|
12
17
|
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
13
18
|
//#endregion
|
|
14
19
|
//#region src/adapters/fastify/fastifyTRPCPlugin.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* The options of `fastifyTRPCPlugin`.
|
|
22
|
+
* @see https://trpc.io/docs/server/adapters/fastify#fastify-plugin-options
|
|
23
|
+
*/
|
|
15
24
|
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
25
|
+
/** The path the router is served at, such as `/trpc`. */
|
|
16
26
|
prefix?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to serve WebSockets too. Needs `@fastify/websocket` to be
|
|
29
|
+
* registered first.
|
|
30
|
+
* @see https://trpc.io/docs/server/adapters/fastify#enable-websockets
|
|
31
|
+
*/
|
|
17
32
|
useWSS?: boolean;
|
|
18
33
|
/**
|
|
19
|
-
*
|
|
34
|
+
* The router and handler options. `keepAlive`, `dangerouslyDisablePong`
|
|
35
|
+
* and `experimental_encoder` only apply with `useWSS`.
|
|
20
36
|
*/
|
|
21
37
|
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply> & Pick<WSSHandlerOptions<TRouter>, 'keepAlive' | 'dangerouslyDisablePong' | 'experimental_encoder'>;
|
|
22
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* What `createContext` gets in the Fastify adapter: `req`, `res` and the
|
|
41
|
+
* request's `info`. With `useWSS`, WebSocket connections get the raw
|
|
42
|
+
* `IncomingMessage` as `req` and the `WebSocket` as `res` instead.
|
|
43
|
+
* @see https://trpc.io/docs/server/adapters/fastify#create-the-context
|
|
44
|
+
*/
|
|
23
45
|
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
46
|
+
/**
|
|
47
|
+
* A Fastify plugin that serves a router over HTTP, and over WebSockets
|
|
48
|
+
* with `useWSS`.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* server.register(fastifyTRPCPlugin, {
|
|
52
|
+
* prefix: '/trpc',
|
|
53
|
+
* trpcOptions: { router: appRouter, createContext },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
* @see https://trpc.io/docs/server/adapters/fastify#create-fastify-server
|
|
57
|
+
*/
|
|
24
58
|
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
25
59
|
//#endregion
|
|
26
60
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"mappings":";;;;;;YA0BY,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;;;;;;wBAOoB,sBACpB,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,cAClB,MAAM,6BAA6B,SAAS,UAAU,aAAU;;;;;;;iBC3BjD,yBAAyB,gBAAgB;;EAExD;;;;;;EAMA;;;;;EAKA,aAAa,sBAAsB,SAAS,gBAAgB,gBAC1D,KACE,kBAAkB;;;;;;;;YAWZ,8BAA8B,+BACxC,gBACA;;;;;;;;;;;;;wBAec,kBAAkB,gBAAgB,WAChD,SAAS,iBACT,MAAM,yBAAyB,UAC/B,OAAO,MAAM"}
|
|
@@ -1,26 +1,60 @@
|
|
|
1
|
-
import { jn as HTTPBaseHandlerOptions, zn as AnyRouter } from "../../unstable-core-do-not-import-
|
|
2
|
-
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-
|
|
3
|
-
import { i as WSSHandlerOptions } from "../../ws-
|
|
1
|
+
import { jn as HTTPBaseHandlerOptions, zn as AnyRouter } from "../../unstable-core-do-not-import-CLjKFqzt.mjs";
|
|
2
|
+
import { o as NodeHTTPCreateContextFnOptions, s as NodeHTTPCreateContextOption } from "../../index-vR2bVSvk.mjs";
|
|
3
|
+
import { i as WSSHandlerOptions } from "../../ws-CXuYC1QZ.mjs";
|
|
4
4
|
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
5
5
|
//#region src/adapters/fastify/fastifyRequestHandler.d.ts
|
|
6
|
+
/** The options of the Fastify adapter's request handler. */
|
|
6
7
|
export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
|
|
7
8
|
type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
|
|
8
9
|
req: TRequest;
|
|
9
10
|
res: TResponse;
|
|
10
11
|
path: string;
|
|
11
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Handles one Fastify request for a router. `fastifyTRPCPlugin` uses it;
|
|
15
|
+
* call it yourself to mount tRPC on your own route.
|
|
16
|
+
*/
|
|
12
17
|
export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
|
|
13
18
|
//#endregion
|
|
14
19
|
//#region src/adapters/fastify/fastifyTRPCPlugin.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* The options of `fastifyTRPCPlugin`.
|
|
22
|
+
* @see https://trpc.io/docs/server/adapters/fastify#fastify-plugin-options
|
|
23
|
+
*/
|
|
15
24
|
export interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
|
|
25
|
+
/** The path the router is served at, such as `/trpc`. */
|
|
16
26
|
prefix?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to serve WebSockets too. Needs `@fastify/websocket` to be
|
|
29
|
+
* registered first.
|
|
30
|
+
* @see https://trpc.io/docs/server/adapters/fastify#enable-websockets
|
|
31
|
+
*/
|
|
17
32
|
useWSS?: boolean;
|
|
18
33
|
/**
|
|
19
|
-
*
|
|
34
|
+
* The router and handler options. `keepAlive`, `dangerouslyDisablePong`
|
|
35
|
+
* and `experimental_encoder` only apply with `useWSS`.
|
|
20
36
|
*/
|
|
21
37
|
trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply> & Pick<WSSHandlerOptions<TRouter>, 'keepAlive' | 'dangerouslyDisablePong' | 'experimental_encoder'>;
|
|
22
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* What `createContext` gets in the Fastify adapter: `req`, `res` and the
|
|
41
|
+
* request's `info`. With `useWSS`, WebSocket connections get the raw
|
|
42
|
+
* `IncomingMessage` as `req` and the `WebSocket` as `res` instead.
|
|
43
|
+
* @see https://trpc.io/docs/server/adapters/fastify#create-the-context
|
|
44
|
+
*/
|
|
23
45
|
export type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
|
|
46
|
+
/**
|
|
47
|
+
* A Fastify plugin that serves a router over HTTP, and over WebSockets
|
|
48
|
+
* with `useWSS`.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* server.register(fastifyTRPCPlugin, {
|
|
52
|
+
* prefix: '/trpc',
|
|
53
|
+
* trpcOptions: { router: appRouter, createContext },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
* @see https://trpc.io/docs/server/adapters/fastify#create-fastify-server
|
|
57
|
+
*/
|
|
24
58
|
export declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
|
|
25
59
|
//#endregion
|
|
26
60
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts","../../../src/adapters/fastify/fastifyTRPCPlugin.ts"],"mappings":";;;;;;YA0BY,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;;;;;;wBAOoB,sBACpB,gBAAgB,WAChB,iBAAiB,gBACjB,kBAAkB,cAClB,MAAM,6BAA6B,SAAS,UAAU,aAAU;;;;;;;iBC3BjD,yBAAyB,gBAAgB;;EAExD;;;;;;EAMA;;;;;EAKA,aAAa,sBAAsB,SAAS,gBAAgB,gBAC1D,KACE,kBAAkB;;;;;;;;YAWZ,8BAA8B,+BACxC,gBACA;;;;;;;;;;;;;wBAec,kBAAkB,gBAAgB,WAChD,SAAS,iBACT,MAAM,yBAAyB,UAC/B,OAAO,MAAM"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { n as _objectSpread2 } from "../../getErrorShape-
|
|
2
|
-
import { t as resolveResponse } from "../../resolveResponse-
|
|
3
|
-
import { i as incomingMessageToRequest } from "../../node-http-
|
|
4
|
-
import { n as getWSConnectionHandler } from "../../ws-
|
|
1
|
+
import { n as _objectSpread2 } from "../../getErrorShape-B6z8u8q0.mjs";
|
|
2
|
+
import { t as resolveResponse } from "../../resolveResponse-oG-tsWtT.mjs";
|
|
3
|
+
import { i as incomingMessageToRequest } from "../../node-http-CRKoQOwy.mjs";
|
|
4
|
+
import { n as getWSConnectionHandler } from "../../ws-BuMgPk3g.mjs";
|
|
5
5
|
//#region src/adapters/fastify/fastifyRequestHandler.ts
|
|
6
|
+
/**
|
|
7
|
+
* Handles one Fastify request for a router. `fastifyTRPCPlugin` uses it;
|
|
8
|
+
* call it yourself to mount tRPC on your own route.
|
|
9
|
+
*/
|
|
6
10
|
async function fastifyRequestHandler(opts) {
|
|
7
11
|
const createContext = async (innerOpts) => {
|
|
8
12
|
var _opts$createContext;
|
|
@@ -24,6 +28,18 @@ async function fastifyRequestHandler(opts) {
|
|
|
24
28
|
}
|
|
25
29
|
//#endregion
|
|
26
30
|
//#region src/adapters/fastify/fastifyTRPCPlugin.ts
|
|
31
|
+
/**
|
|
32
|
+
* A Fastify plugin that serves a router over HTTP, and over WebSockets
|
|
33
|
+
* with `useWSS`.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* server.register(fastifyTRPCPlugin, {
|
|
37
|
+
* prefix: '/trpc',
|
|
38
|
+
* trpcOptions: { router: appRouter, createContext },
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
* @see https://trpc.io/docs/server/adapters/fastify#create-fastify-server
|
|
42
|
+
*/
|
|
27
43
|
function fastifyTRPCPlugin(fastify, opts, done) {
|
|
28
44
|
var _opts$prefix;
|
|
29
45
|
fastify.removeContentTypeParser("application/json");
|