Skip to content

Commit

Permalink
cool
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Apr 29, 2024
1 parent 328bcc4 commit ed9d992
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions packages/server/src/adapters/aws-lambda/getPlanner.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
/**
* 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`
*
* @example
* ```ts
* import type { AnyTRPCRouter } from '@trpc/server'
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
* ```
*/
import type {
APIGatewayProxyEvent,
APIGatewayProxyEventV2,
APIGatewayProxyResult,
APIGatewayProxyStructuredResultV2,
} from 'aws-lambda';

// import @trpc/server

// @trpc/server

export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;

export type APIGatewayResult =
Expand Down Expand Up @@ -53,20 +40,6 @@ interface Processor<TEvent extends LambdaEvent> {
toResult: (response: Response) => Promise<inferAPIGWReturn<TEvent>>;
}

function transformHeaders(
headers: Request['headers'],
): APIGatewayResult['headers'] {
const obj: APIGatewayResult['headers'] = {};

for (const [key, value] of headers) {
if (typeof value === 'undefined') {
continue;
}
obj[key] = value;
}
return obj;
}

const v1Processor: Processor<APIGatewayProxyEvent> = {
// same as getPath above
getTRPCPath: (event) => {
Expand Down Expand Up @@ -128,7 +101,7 @@ const v1Processor: Processor<APIGatewayProxyEvent> = {
const result: APIGatewayProxyResult = {
statusCode: response.status,
body: await response.text(),
headers: transformHeaders(response.headers),
headers: Object.fromEntries(response.headers.entries()),
};

return result;
Expand Down Expand Up @@ -172,7 +145,7 @@ const v2Processor: Processor<APIGatewayProxyEventV2> = {
const result: APIGatewayProxyStructuredResultV2 = {
statusCode: response.status,
body: await response.text(),
headers: transformHeaders(response.headers),
headers: Object.fromEntries(response.headers.entries()),
};

return result;
Expand Down

0 comments on commit ed9d992

Please sign in to comment.