@trpc/server 11.0.0-alpha-tmp-export-from-main.223 → 11.0.0-alpha-tmp-workflow-merge.250
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +9 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
- package/dist/@trpc-server/http.d.ts +2 -0
- package/dist/@trpc-server/http.d.ts.map +1 -0
- package/dist/@trpc-server.d.ts +69 -0
- package/dist/@trpc-server.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +6 -54
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.js +20 -109
- package/dist/adapters/aws-lambda/index.mjs +5 -94
- package/dist/adapters/aws-lambda/utils.d.ts +48 -0
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/utils.js +100 -0
- package/dist/adapters/aws-lambda/utils.mjs +93 -0
- package/dist/adapters/express.d.ts +6 -9
- package/dist/adapters/express.d.ts.map +1 -0
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +13 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.js +81 -0
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +79 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +22 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +51 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +49 -0
- package/dist/adapters/fastify/index.d.ts +3 -33
- package/dist/adapters/fastify/index.d.ts.map +1 -0
- package/dist/adapters/fastify/index.js +5 -124
- package/dist/adapters/fastify/index.mjs +2 -125
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +18 -0
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -0
- package/dist/adapters/fetch/fetchRequestHandler.js +118 -0
- package/dist/adapters/fetch/fetchRequestHandler.mjs +116 -0
- package/dist/adapters/fetch/index.d.ts +3 -51
- package/dist/adapters/fetch/index.d.ts.map +1 -0
- package/dist/adapters/fetch/index.js +4 -115
- package/dist/adapters/fetch/index.mjs +1 -116
- package/dist/adapters/fetch/types.d.ts +31 -0
- package/dist/adapters/fetch/types.d.ts.map +1 -0
- package/dist/adapters/next.d.ts +7 -11
- package/dist/adapters/next.d.ts.map +1 -0
- package/dist/adapters/next.js +6 -6
- package/dist/adapters/next.mjs +2 -2
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +70 -0
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +10 -201
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/index.js +23 -662
- package/dist/adapters/node-http/content-type/form-data/index.mjs +10 -646
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +31 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +16 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +45 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +7 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.js +42 -0
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +40 -0
- package/dist/adapters/node-http/content-type/json/index.d.ts +2 -89
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +1 -0
- package/dist/adapters/node-http/content-type/json/index.js +6 -47
- package/dist/adapters/node-http/content-type/json/index.mjs +3 -44
- package/dist/adapters/node-http/index.d.ts +3 -100
- package/dist/adapters/node-http/index.d.ts.map +1 -0
- package/dist/adapters/node-http/index.js +4 -106
- package/dist/adapters/node-http/index.mjs +1 -107
- package/dist/adapters/node-http/internals/contentType.d.ts +9 -0
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -0
- package/dist/adapters/node-http/internals/contentType.js +8 -0
- package/dist/adapters/node-http/internals/contentType.mjs +6 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +14 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +109 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +107 -0
- package/dist/adapters/node-http/{content-type/json/index.d.mts → types.d.ts} +15 -21
- package/dist/adapters/node-http/types.d.ts.map +1 -0
- package/dist/adapters/standalone.d.ts +9 -11
- package/dist/adapters/standalone.d.ts.map +1 -0
- package/dist/adapters/standalone.js +5 -9
- package/dist/adapters/standalone.mjs +2 -2
- package/dist/adapters/ws.d.ts +14 -12
- package/dist/adapters/ws.d.ts.map +1 -0
- package/dist/adapters/ws.js +27 -27
- package/dist/adapters/ws.mjs +12 -12
- package/dist/bundle-analysis.json +416 -0
- package/dist/http.d.ts +2 -1
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +7 -21
- package/dist/http.mjs +1 -1
- package/dist/index.d.ts +2 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -811
- package/dist/index.mjs +1 -799
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
- package/dist/observable.d.ts +2 -1
- package/dist/observable.d.ts.map +1 -0
- package/dist/observable.js +7 -25
- package/dist/observable.mjs +1 -1
- package/dist/rpc.d.ts +2 -1
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +7 -13
- package/dist/rpc.mjs +1 -1
- package/dist/shared.d.ts +26 -1
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +4 -4
- package/dist/shared.mjs +1 -1
- package/package.json +49 -137
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +9 -0
- package/src/@trpc-server/http.ts +1 -1
- package/src/@trpc-server.ts +105 -0
- package/src/adapters/aws-lambda/index.ts +2 -2
- package/src/adapters/aws-lambda/utils.ts +2 -2
- package/src/adapters/express.ts +1 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
- package/src/adapters/fetch/types.ts +1 -1
- package/src/adapters/next.ts +2 -2
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +1 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
- package/src/adapters/node-http/types.ts +1 -1
- package/src/adapters/standalone.ts +1 -1
- package/src/adapters/ws.ts +8 -8
- package/src/http.ts +1 -26
- package/src/index.ts +1 -107
- package/src/observable.ts +1 -16
- package/src/rpc.ts +1 -25
- package/src/shared.ts +1 -1
- package/dist/adapters/aws-lambda/index.d.mts +0 -68
- package/dist/adapters/express.d.mts +0 -19
- package/dist/adapters/fastify/index.d.mts +0 -33
- package/dist/adapters/fetch/index.d.mts +0 -51
- package/dist/adapters/next.d.mts +0 -21
- package/dist/adapters/node-http/content-type/form-data/index.d.mts +0 -219
- package/dist/adapters/node-http/index.d.mts +0 -100
- package/dist/adapters/standalone.d.mts +0 -21
- package/dist/adapters/ws.d.mts +0 -36
- package/dist/http.d.mts +0 -1
- package/dist/index.d.mts +0 -9
- package/dist/observable.d.mts +0 -1
- package/dist/rpc.d.mts +0 -1
- package/dist/shared.d.mts +0 -1
- package/dist/unstableDontImportMe.d.mts +0 -1
- package/dist/unstableDontImportMe.d.ts +0 -1
- package/dist/unstableDontImportMe.js +0 -1549
- package/dist/unstableDontImportMe.mjs +0 -1514
- package/src/unstableDontImportMe.ts +0 -146
- package/unstableDontImportMe/index.d.ts +0 -1
- package/unstableDontImportMe/index.js +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is here to make TypeScript happy and prevent _"The inferred type of 'createContext' cannot be named without a reference to [...]"_.
|
|
3
|
+
*
|
|
4
|
+
* We're basically just re-exporting everything from @trpc/core here.
|
|
5
|
+
*
|
|
6
|
+
* If you need to import anything from here, please open an issue at https://github.com/trpc/trpc/issues
|
|
7
|
+
*/
|
|
8
|
+
export * from '@trpc/core';
|
|
9
|
+
//# sourceMappingURL=@trpc-core-unstable-do-not-import-this-please.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"@trpc-core-unstable-do-not-import-this-please.d.ts","sourceRoot":"","sources":["../src/@trpc-core-unstable-do-not-import-this-please.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/@trpc-server/http.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export { TRPCError,
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use `experimental_trpcMiddleware` instead
|
|
4
|
+
*/
|
|
5
|
+
experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type ProcedureRouterRecord as TRPCProcedureRouterRecord, type ProcedureArgs as TRPCProcedureArgs, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, } from './@trpc-core-unstable-do-not-import-this-please';
|
|
6
|
+
export type {
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use `AnyTRPCProcedure` instead
|
|
9
|
+
*/
|
|
10
|
+
AnyProcedure,
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated use `AnyTRPCRouter` instead
|
|
13
|
+
*/
|
|
14
|
+
AnyRouter,
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use `AnyTRPCMiddlewareFunction` instead
|
|
17
|
+
*/
|
|
18
|
+
AnyMiddlewareFunction,
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use `TRPCCombinedDataTransformer` instead
|
|
21
|
+
*/
|
|
22
|
+
CombinedDataTransformer,
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated This is a utility type will be removed in v12
|
|
25
|
+
*/
|
|
26
|
+
Dict,
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated This is a utility type will be removed in v12
|
|
29
|
+
*/
|
|
30
|
+
DeepPartial,
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated use `TRPCProcedureType` instead
|
|
33
|
+
*/
|
|
34
|
+
ProcedureType,
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated use `AnyTRPCMutationProcedure` instead
|
|
37
|
+
*/
|
|
38
|
+
AnyMutationProcedure,
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated use `AnyTRPCQueryProcedure` instead
|
|
41
|
+
*/
|
|
42
|
+
AnyQueryProcedure,
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated use `TRPCProcedureRouterRecord` instead
|
|
45
|
+
*/
|
|
46
|
+
ProcedureRouterRecord,
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated use `TRPCProcedureArgs` instead
|
|
49
|
+
*/
|
|
50
|
+
ProcedureArgs,
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated use `AnyTRPCSubscriptionProcedure` instead
|
|
53
|
+
*/
|
|
54
|
+
AnySubscriptionProcedure, } from '@trpc/core';
|
|
55
|
+
export {
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated use `getTRPCErrorShape` instead
|
|
58
|
+
*/
|
|
59
|
+
getErrorShape,
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated use `callTRPCProcedure` instead
|
|
62
|
+
*/
|
|
63
|
+
callProcedure, } from '@trpc/core';
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated
|
|
66
|
+
* Use `Awaited<ReturnType<typeof myFunction>>` instead
|
|
67
|
+
*/
|
|
68
|
+
export type inferAsyncReturnType<TFunction extends (...args: any[]) => any> = Awaited<ReturnType<TFunction>>;
|
|
69
|
+
//# sourceMappingURL=@trpc-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"@trpc-server.d.ts","sourceRoot":"","sources":["../src/@trpc-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,aAAa,IAAI,iBAAiB,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,IAAI,mBAAmB,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,+BAA+B,EACpC,KAAK,kCAAkC,EACvC,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,SAAS,IAAI,aAAa,EAC/B,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,oBAAoB,IAAI,wBAAwB,EACrD,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,KAAK,qBAAqB,IAAI,yBAAyB,EACvD,KAAK,aAAa,IAAI,iBAAiB,EACvC,KAAK,wBAAwB,IAAI,4BAA4B,GAC9D,MAAM,iDAAiD,CAAC;AAEzD,YAAY;AACV;;GAEG;AACH,YAAY;AACZ;;GAEG;AACH,SAAS;AACT;;GAEG;AACH,qBAAqB;AACrB;;GAEG;AACH,uBAAuB;AAEvB;;GAEG;AACH,IAAI;AAEJ;;GAEG;AACH,WAAW;AACX;;GAEG;AACH,aAAa;AACb;;GAEG;AACH,oBAAoB;AAEpB;;GAEG;AACH,iBAAiB;AACjB;;GAEG;AACH,qBAAqB;AACrB;;GAEG;AACH,aAAa;AACb;;GAEG;AACH,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO;AACL;;GAEG;AACH,aAAa;AAEb;;GAEG;AACH,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACxE,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context } from 'aws-lambda';
|
|
2
|
-
import { AnyRouter, inferRouterContext } from '@trpc/server';
|
|
3
|
-
import { TRPCRequestInfo, OnErrorFunction, ResponseMetaFn, HTTPHeaders } from '@trpc/server/http';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* 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`
|
|
7
3
|
*
|
|
@@ -12,57 +8,13 @@ import { TRPCRequestInfo, OnErrorFunction, ResponseMetaFn, HTTPHeaders } from '@
|
|
|
12
8
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
9
|
* ```
|
|
14
10
|
*/
|
|
15
|
-
|
|
16
|
-
type
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
event: TEvent;
|
|
20
|
-
context: Context;
|
|
21
|
-
info: TRPCRequestInfo;
|
|
22
|
-
};
|
|
23
|
-
type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
24
|
-
type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = {
|
|
25
|
-
router: TRouter;
|
|
26
|
-
batching?: {
|
|
27
|
-
enabled: boolean;
|
|
28
|
-
};
|
|
29
|
-
onError?: OnErrorFunction<TRouter, TEvent>;
|
|
30
|
-
responseMeta?: ResponseMetaFn<TRouter>;
|
|
31
|
-
} & ({
|
|
32
|
-
/**
|
|
33
|
-
* @link https://trpc.io/docs/v11/context
|
|
34
|
-
**/
|
|
35
|
-
createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
36
|
-
} | {
|
|
37
|
-
/**
|
|
38
|
-
* @link https://trpc.io/docs/v11/context
|
|
39
|
-
**/
|
|
40
|
-
createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
41
|
-
});
|
|
42
|
-
declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
|
|
43
|
-
declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
|
|
44
|
-
declare function getHTTPMethod(event: APIGatewayEvent): string;
|
|
45
|
-
declare function getPath(event: APIGatewayEvent): string;
|
|
46
|
-
declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
|
|
47
|
-
type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
|
|
48
|
-
type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
|
|
49
|
-
declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 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`
|
|
53
|
-
*
|
|
54
|
-
* Do **not** import from `@trpc/core`
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
58
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
|
|
11
|
+
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
|
|
12
|
+
import type { AnyRouter } from '../../@trpc-server';
|
|
13
|
+
import type { APIGatewayEvent, AWSLambdaOptions } from './utils';
|
|
14
|
+
export * from './utils';
|
|
62
15
|
/** 1:1 mapping of v1 or v2 input events, deduces which is which.
|
|
63
16
|
* @internal
|
|
64
17
|
**/
|
|
65
18
|
type inferAPIGWReturn<TType> = TType extends APIGatewayProxyEvent ? APIGatewayProxyResult : TType extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
|
|
66
|
-
declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends APIGatewayEvent, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context:
|
|
67
|
-
|
|
68
|
-
export { type APIGatewayEvent, type APIGatewayPayloadFormatVersion, type APIGatewayResult, type AWSLambdaCreateContextFn, type AWSLambdaOptions, type CreateAWSLambdaContextOptions, type DefinedAPIGatewayPayloadFormats, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, awsLambdaRequestHandler, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
|
|
19
|
+
export declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends APIGatewayEvent, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: APIGWContext) => Promise<TResult>;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AASpD,OAAO,KAAK,EACV,eAAe,EAEf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,cAAc,SAAS,CAAC;AAqDxB;;IAEI;AACJ,KAAK,gBAAgB,CAAC,KAAK,IAAI,KAAK,SAAS,oBAAoB,GAC7D,qBAAqB,GACrB,KAAK,SAAS,sBAAsB,GACpC,iCAAiC,GACjC,KAAK,CAAC;AACV,wBAAgB,uBAAuB,CACrC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAExC,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACtC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,CA4B5D"}
|
|
@@ -1,97 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var http = require('@trpc/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 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`
|
|
8
|
-
*
|
|
9
|
-
* Do **not** import from `@trpc/core`
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
13
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
14
|
-
* ```
|
|
15
|
-
*/ // @trpc/server
|
|
16
|
-
function isPayloadV1(event) {
|
|
17
|
-
return determinePayloadFormat(event) == '1.0';
|
|
18
|
-
}
|
|
19
|
-
function isPayloadV2(event) {
|
|
20
|
-
return determinePayloadFormat(event) == '2.0';
|
|
21
|
-
}
|
|
22
|
-
function determinePayloadFormat(event) {
|
|
23
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
24
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
25
|
-
// If there is no version property, then the version is implied as 1.0
|
|
26
|
-
const unknownEvent = event;
|
|
27
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
28
|
-
return '1.0';
|
|
29
|
-
} else {
|
|
30
|
-
if ([
|
|
31
|
-
'1.0',
|
|
32
|
-
'2.0'
|
|
33
|
-
].includes(unknownEvent.version)) {
|
|
34
|
-
return unknownEvent.version;
|
|
35
|
-
} else {
|
|
36
|
-
return 'custom';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function getHTTPMethod(event) {
|
|
41
|
-
if (isPayloadV1(event)) {
|
|
42
|
-
return event.httpMethod;
|
|
43
|
-
}
|
|
44
|
-
if (isPayloadV2(event)) {
|
|
45
|
-
return event.requestContext.http.method;
|
|
46
|
-
}
|
|
47
|
-
throw new server.TRPCError({
|
|
48
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
49
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function getPath(event) {
|
|
53
|
-
if (isPayloadV1(event)) {
|
|
54
|
-
if (!event.pathParameters) {
|
|
55
|
-
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
56
|
-
return event.path.split('/').pop() ?? '';
|
|
57
|
-
}
|
|
58
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
59
|
-
for (const match of matches){
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
61
|
-
const group = match[1];
|
|
62
|
-
if (group.includes('+') && event.pathParameters) {
|
|
63
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return event.path.slice(1);
|
|
67
|
-
}
|
|
68
|
-
if (isPayloadV2(event)) {
|
|
69
|
-
const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
70
|
-
for (const match of matches){
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
72
|
-
const group = match[1];
|
|
73
|
-
if (group.includes('+') && event.pathParameters) {
|
|
74
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return event.rawPath.slice(1);
|
|
78
|
-
}
|
|
79
|
-
throw new server.TRPCError({
|
|
80
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
81
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function transformHeaders(headers) {
|
|
85
|
-
const obj = {};
|
|
86
|
-
for (const [key, value] of Object.entries(headers)){
|
|
87
|
-
if (typeof value === 'undefined') {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
91
|
-
}
|
|
92
|
-
return obj;
|
|
93
|
-
}
|
|
94
|
-
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
3
|
+
var core = require('@trpc/core');
|
|
4
|
+
var http = require('@trpc/core/http');
|
|
5
|
+
var utils = require('./utils.js');
|
|
95
6
|
|
|
96
7
|
/**
|
|
97
8
|
* 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`
|
|
@@ -117,38 +28,38 @@ function lambdaEventToHTTPRequest(event) {
|
|
|
117
28
|
body = event.body;
|
|
118
29
|
}
|
|
119
30
|
return {
|
|
120
|
-
method: getHTTPMethod(event),
|
|
31
|
+
method: utils.getHTTPMethod(event),
|
|
121
32
|
query: query,
|
|
122
33
|
headers: event.headers,
|
|
123
34
|
body: body
|
|
124
35
|
};
|
|
125
36
|
}
|
|
126
37
|
function tRPCOutputToAPIGatewayOutput(event, response) {
|
|
127
|
-
if (isPayloadV1(event)) {
|
|
38
|
+
if (utils.isPayloadV1(event)) {
|
|
128
39
|
const resp = {
|
|
129
40
|
statusCode: response.status,
|
|
130
41
|
body: response.body ?? '',
|
|
131
|
-
headers: transformHeaders(response.headers ?? {})
|
|
42
|
+
headers: utils.transformHeaders(response.headers ?? {})
|
|
132
43
|
};
|
|
133
44
|
return resp;
|
|
134
|
-
} else if (isPayloadV2(event)) {
|
|
135
|
-
const
|
|
45
|
+
} else if (utils.isPayloadV2(event)) {
|
|
46
|
+
const resp1 = {
|
|
136
47
|
statusCode: response.status,
|
|
137
48
|
body: response.body ?? undefined,
|
|
138
|
-
headers: transformHeaders(response.headers ?? {})
|
|
49
|
+
headers: utils.transformHeaders(response.headers ?? {})
|
|
139
50
|
};
|
|
140
|
-
return
|
|
51
|
+
return resp1;
|
|
141
52
|
} else {
|
|
142
|
-
throw new
|
|
53
|
+
throw new core.TRPCError({
|
|
143
54
|
code: 'INTERNAL_SERVER_ERROR',
|
|
144
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
55
|
+
message: utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
145
56
|
});
|
|
146
57
|
}
|
|
147
58
|
}
|
|
148
59
|
function awsLambdaRequestHandler(opts) {
|
|
149
60
|
return async (event, context)=>{
|
|
150
61
|
const req = lambdaEventToHTTPRequest(event);
|
|
151
|
-
const path = getPath(event);
|
|
62
|
+
const path = utils.getPath(event);
|
|
152
63
|
const createContext = async (innerOpts)=>{
|
|
153
64
|
return await opts.createContext?.({
|
|
154
65
|
event,
|
|
@@ -175,10 +86,10 @@ function awsLambdaRequestHandler(opts) {
|
|
|
175
86
|
};
|
|
176
87
|
}
|
|
177
88
|
|
|
178
|
-
exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
|
|
89
|
+
exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
|
|
90
|
+
exports.getHTTPMethod = utils.getHTTPMethod;
|
|
91
|
+
exports.getPath = utils.getPath;
|
|
92
|
+
exports.isPayloadV1 = utils.isPayloadV1;
|
|
93
|
+
exports.isPayloadV2 = utils.isPayloadV2;
|
|
94
|
+
exports.transformHeaders = utils.transformHeaders;
|
|
179
95
|
exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
|
|
180
|
-
exports.getHTTPMethod = getHTTPMethod;
|
|
181
|
-
exports.getPath = getPath;
|
|
182
|
-
exports.isPayloadV1 = isPayloadV1;
|
|
183
|
-
exports.isPayloadV2 = isPayloadV2;
|
|
184
|
-
exports.transformHeaders = transformHeaders;
|
|
@@ -1,95 +1,6 @@
|
|
|
1
|
-
import { TRPCError } from '@trpc/
|
|
2
|
-
import { resolveHTTPResponse } from '@trpc/
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 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`
|
|
6
|
-
*
|
|
7
|
-
* Do **not** import from `@trpc/core`
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
11
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
12
|
-
* ```
|
|
13
|
-
*/ // @trpc/server
|
|
14
|
-
function isPayloadV1(event) {
|
|
15
|
-
return determinePayloadFormat(event) == '1.0';
|
|
16
|
-
}
|
|
17
|
-
function isPayloadV2(event) {
|
|
18
|
-
return determinePayloadFormat(event) == '2.0';
|
|
19
|
-
}
|
|
20
|
-
function determinePayloadFormat(event) {
|
|
21
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
22
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
23
|
-
// If there is no version property, then the version is implied as 1.0
|
|
24
|
-
const unknownEvent = event;
|
|
25
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
26
|
-
return '1.0';
|
|
27
|
-
} else {
|
|
28
|
-
if ([
|
|
29
|
-
'1.0',
|
|
30
|
-
'2.0'
|
|
31
|
-
].includes(unknownEvent.version)) {
|
|
32
|
-
return unknownEvent.version;
|
|
33
|
-
} else {
|
|
34
|
-
return 'custom';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function getHTTPMethod(event) {
|
|
39
|
-
if (isPayloadV1(event)) {
|
|
40
|
-
return event.httpMethod;
|
|
41
|
-
}
|
|
42
|
-
if (isPayloadV2(event)) {
|
|
43
|
-
return event.requestContext.http.method;
|
|
44
|
-
}
|
|
45
|
-
throw new TRPCError({
|
|
46
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
47
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function getPath(event) {
|
|
51
|
-
if (isPayloadV1(event)) {
|
|
52
|
-
if (!event.pathParameters) {
|
|
53
|
-
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
54
|
-
return event.path.split('/').pop() ?? '';
|
|
55
|
-
}
|
|
56
|
-
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
57
|
-
for (const match of matches){
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
|
-
const group = match[1];
|
|
60
|
-
if (group.includes('+') && event.pathParameters) {
|
|
61
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return event.path.slice(1);
|
|
65
|
-
}
|
|
66
|
-
if (isPayloadV2(event)) {
|
|
67
|
-
const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
68
|
-
for (const match of matches){
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
-
const group = match[1];
|
|
71
|
-
if (group.includes('+') && event.pathParameters) {
|
|
72
|
-
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return event.rawPath.slice(1);
|
|
76
|
-
}
|
|
77
|
-
throw new TRPCError({
|
|
78
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
79
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function transformHeaders(headers) {
|
|
83
|
-
const obj = {};
|
|
84
|
-
for (const [key, value] of Object.entries(headers)){
|
|
85
|
-
if (typeof value === 'undefined') {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
89
|
-
}
|
|
90
|
-
return obj;
|
|
91
|
-
}
|
|
92
|
-
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
1
|
+
import { TRPCError } from '@trpc/core';
|
|
2
|
+
import { resolveHTTPResponse } from '@trpc/core/http';
|
|
3
|
+
import { getPath, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE } from './utils.mjs';
|
|
93
4
|
|
|
94
5
|
/**
|
|
95
6
|
* 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`
|
|
@@ -130,12 +41,12 @@ function tRPCOutputToAPIGatewayOutput(event, response) {
|
|
|
130
41
|
};
|
|
131
42
|
return resp;
|
|
132
43
|
} else if (isPayloadV2(event)) {
|
|
133
|
-
const
|
|
44
|
+
const resp1 = {
|
|
134
45
|
statusCode: response.status,
|
|
135
46
|
body: response.body ?? undefined,
|
|
136
47
|
headers: transformHeaders(response.headers ?? {})
|
|
137
48
|
};
|
|
138
|
-
return
|
|
49
|
+
return resp1;
|
|
139
50
|
} else {
|
|
140
51
|
throw new TRPCError({
|
|
141
52
|
code: 'INTERNAL_SERVER_ERROR',
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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`
|
|
3
|
+
*
|
|
4
|
+
* Do **not** import from `@trpc/core`
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
|
|
12
|
+
import type { AnyRouter, inferRouterContext } from '../../@trpc-server';
|
|
13
|
+
import type { HTTPHeaders, OnErrorFunction, ResponseMetaFn, TRPCRequestInfo } from '../../http';
|
|
14
|
+
export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
15
|
+
export type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
16
|
+
export type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
|
|
17
|
+
event: TEvent;
|
|
18
|
+
context: APIGWContext;
|
|
19
|
+
info: TRPCRequestInfo;
|
|
20
|
+
};
|
|
21
|
+
export type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
22
|
+
export type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = {
|
|
23
|
+
router: TRouter;
|
|
24
|
+
batching?: {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
};
|
|
27
|
+
onError?: OnErrorFunction<TRouter, TEvent>;
|
|
28
|
+
responseMeta?: ResponseMetaFn<TRouter>;
|
|
29
|
+
} & ({
|
|
30
|
+
/**
|
|
31
|
+
* @link https://trpc.io/docs/v11/context
|
|
32
|
+
**/
|
|
33
|
+
createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
34
|
+
} | {
|
|
35
|
+
/**
|
|
36
|
+
* @link https://trpc.io/docs/v11/context
|
|
37
|
+
**/
|
|
38
|
+
createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
39
|
+
});
|
|
40
|
+
export declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
|
|
41
|
+
export declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
|
|
42
|
+
export declare function getHTTPMethod(event: APIGatewayEvent): string;
|
|
43
|
+
export declare function getPath(event: APIGatewayEvent): string;
|
|
44
|
+
export declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
|
|
45
|
+
export type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
|
|
46
|
+
export type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
|
|
47
|
+
export declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
|
|
48
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAIxE,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;AAC5E,MAAM,MAAM,gBAAgB,GACxB,qBAAqB,GACrB,iCAAiC,CAAC;AAEtC,MAAM,MAAM,6BAA6B,CAAC,MAAM,SAAS,eAAe,IAAI;IAC1E,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,wBAAwB,CAClC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,IAC5B,CAAC,EACH,KAAK,EACL,OAAO,EACP,IAAI,GACL,EAAE,6BAA6B,CAAC,MAAM,CAAC,KACpC,kBAAkB,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzC,MAAM,MAAM,gBAAgB,CAC1B,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,IAE5B;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3C,YAAY,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACxC,GAAG,CACA;IACE;;QAEI;IACJ,aAAa,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC1D,GACD;IACE;;QAEI;IACJ,aAAa,CAAC,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC3D,CACJ,CAAC;AAEN,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,oBAAoB,CAE/B;AACD,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,sBAAsB,CAEjC;AAoBD,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,UAWnD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe,UA+B7C;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,WAAW,GACnB,gBAAgB,CAAC,SAAS,CAAC,CAU7B;AAED,MAAM,MAAM,+BAA+B,GAAG,KAAK,GAAG,KAAK,CAAC;AAC5D,MAAM,MAAM,8BAA8B,GACtC,+BAA+B,GAC/B,QAAQ,CAAC;AAEb,eAAO,MAAM,4CAA4C,QAEiD,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@trpc/core');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 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`
|
|
7
|
+
*
|
|
8
|
+
* Do **not** import from `@trpc/core`
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
|
+
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
|
+
* ```
|
|
14
|
+
*/ // @trpc/server
|
|
15
|
+
function isPayloadV1(event) {
|
|
16
|
+
return determinePayloadFormat(event) == '1.0';
|
|
17
|
+
}
|
|
18
|
+
function isPayloadV2(event) {
|
|
19
|
+
return determinePayloadFormat(event) == '2.0';
|
|
20
|
+
}
|
|
21
|
+
function determinePayloadFormat(event) {
|
|
22
|
+
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
23
|
+
// According to AWS support, version is is extracted from the version property in the event.
|
|
24
|
+
// If there is no version property, then the version is implied as 1.0
|
|
25
|
+
const unknownEvent = event;
|
|
26
|
+
if (typeof unknownEvent.version === 'undefined') {
|
|
27
|
+
return '1.0';
|
|
28
|
+
} else {
|
|
29
|
+
if ([
|
|
30
|
+
'1.0',
|
|
31
|
+
'2.0'
|
|
32
|
+
].includes(unknownEvent.version)) {
|
|
33
|
+
return unknownEvent.version;
|
|
34
|
+
} else {
|
|
35
|
+
return 'custom';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getHTTPMethod(event) {
|
|
40
|
+
if (isPayloadV1(event)) {
|
|
41
|
+
return event.httpMethod;
|
|
42
|
+
}
|
|
43
|
+
if (isPayloadV2(event)) {
|
|
44
|
+
return event.requestContext.http.method;
|
|
45
|
+
}
|
|
46
|
+
throw new core.TRPCError({
|
|
47
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
48
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function getPath(event) {
|
|
52
|
+
if (isPayloadV1(event)) {
|
|
53
|
+
if (!event.pathParameters) {
|
|
54
|
+
// Then this event was not triggered by a resource denoted with {proxy+}
|
|
55
|
+
return event.path.split('/').pop() ?? '';
|
|
56
|
+
}
|
|
57
|
+
const matches = event.resource.matchAll(/\{(.*?)\}/g);
|
|
58
|
+
for (const match of matches){
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
|
+
const group = match[1];
|
|
61
|
+
if (group.includes('+') && event.pathParameters) {
|
|
62
|
+
return event.pathParameters[group.replace('+', '')] ?? '';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return event.path.slice(1);
|
|
66
|
+
}
|
|
67
|
+
if (isPayloadV2(event)) {
|
|
68
|
+
const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
|
|
69
|
+
for (const match1 of matches1){
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
71
|
+
const group1 = match1[1];
|
|
72
|
+
if (group1.includes('+') && event.pathParameters) {
|
|
73
|
+
return event.pathParameters[group1.replace('+', '')] ?? '';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return event.rawPath.slice(1);
|
|
77
|
+
}
|
|
78
|
+
throw new core.TRPCError({
|
|
79
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
80
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function transformHeaders(headers) {
|
|
84
|
+
const obj = {};
|
|
85
|
+
for (const [key, value] of Object.entries(headers)){
|
|
86
|
+
if (typeof value === 'undefined') {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
94
|
+
|
|
95
|
+
exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
|
|
96
|
+
exports.getHTTPMethod = getHTTPMethod;
|
|
97
|
+
exports.getPath = getPath;
|
|
98
|
+
exports.isPayloadV1 = isPayloadV1;
|
|
99
|
+
exports.isPayloadV2 = isPayloadV2;
|
|
100
|
+
exports.transformHeaders = transformHeaders;
|