-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from antoinewg/antoinewg/node-20
Migrate to node 20
- Loading branch information
Showing
20 changed files
with
2,545 additions
and
2,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "turboless", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*", | ||
|
@@ -21,27 +21,26 @@ | |
"package": "turbo run package" | ||
}, | ||
"devDependencies": { | ||
"@serverless/typescript": "^3.29.0", | ||
"@types/aws-lambda": "^8.10.114", | ||
"@types/node": "^18.15.11", | ||
"@vitest/coverage-c8": "^0.29.8", | ||
"esbuild": "^0.17.15", | ||
"@serverless/typescript": "^3.38.0", | ||
"@types/aws-lambda": "^8.10.133", | ||
"@types/node": "^20.11.17", | ||
"@vitest/coverage-v8": "^1.2.2", | ||
"esbuild": "^0.20.0", | ||
"eslint-config-custom": "workspace:*", | ||
"prettier": "latest", | ||
"serverless": "^3.29.0", | ||
"serverless-esbuild": "^1.43.0", | ||
"serverless-offline": "^12.0.4", | ||
"ts-node": "^10.9.1", | ||
"turbo": "latest", | ||
"typescript": "^5.0.3", | ||
"vitest": "^0.29.8" | ||
"serverless": "^3.38.0", | ||
"serverless-esbuild": "^1.51.0", | ||
"serverless-offline": "^13.3.3", | ||
"ts-node": "^10.9.2", | ||
"turbo": "^1.12.3", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.2.2" | ||
}, | ||
"engines": { | ||
"npm": ">=8.0.0", | ||
"node": ">=16.0.0" | ||
"node": ">=18", | ||
"pnpm": ">=8", | ||
"npm": "please-use-pnpm", | ||
"yarn": "please-use-pnpm" | ||
}, | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"aws-lambda": "^1.0.7" | ||
} | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,66 @@ | ||
import middy from "@middy/core"; | ||
import middy, { MiddyfiedHandler } from "@middy/core"; | ||
import middyJsonBodyParser from "@middy/http-json-body-parser"; | ||
import type { Handler } from "aws-lambda"; | ||
import cors from "@middy/http-cors"; | ||
import validator from "@middy/validator"; | ||
import { transpileSchema } from "@middy/validator/transpile"; | ||
import httpErrorHandler from "@middy/http-error-handler"; | ||
import httpEventNormalizer from "@middy/http-event-normalizer"; | ||
|
||
export const middyfy = <TEvent, TResult>(handler: Handler<TEvent, TResult>) => { | ||
return middy<TEvent, TResult>(handler).use(middyJsonBodyParser()); | ||
import type { | ||
APIGatewayProxyEvent as ProxyEvent, | ||
APIGatewayProxyResult, | ||
Context, | ||
Handler as AWSHandler, | ||
} from "aws-lambda"; | ||
import type { FromSchema } from "json-schema-to-ts"; | ||
|
||
// Taken from https://github.com/middyjs/middy/issues/316#issuecomment-1013351805 | ||
// Event is an APIGatewayProxyEvent with a typed body, pathParameters and queryStringParameters which depends on http-json-body-parser & json-schema-to-ts | ||
// queryStringParameters and multiValueQueryStringParameters is non-nullable as we use http-event-normalizer | ||
export interface Event< | ||
TBody extends Record<string, unknown> | null, | ||
TPathParameters extends Record<string, unknown> | null, | ||
TQueryStringParameters extends Record<string, unknown> | null | ||
> extends Omit< | ||
ProxyEvent, | ||
"body" | "pathParameters" | "queryStringParameters" | ||
> { | ||
body: TBody extends Record<string, unknown> ? FromSchema<TBody> : null; | ||
pathParameters: TPathParameters extends Record<string, unknown> | ||
? FromSchema<TPathParameters> | ||
: null; | ||
queryStringParameters: TQueryStringParameters extends Record<string, unknown> | ||
? FromSchema<TQueryStringParameters> | ||
: null; | ||
multiValueQueryStringParameters: NonNullable< | ||
ProxyEvent["multiValueQueryStringParameters"] | ||
>; | ||
} | ||
|
||
// We are making use of http-response-serializer | ||
interface Result extends Omit<APIGatewayProxyResult, "body"> { | ||
body: string | Record<string, unknown>; | ||
} | ||
|
||
// Handler type which gives us proper types on our event based on TBody and TPathParameters which are JSON schemas | ||
export type CustomHandler< | ||
TBody extends Record<string, unknown> | null = null, | ||
TPathParameters extends Record<string, unknown> | null = null, | ||
TQueryStringParameters extends Record<string, unknown> | null = null | ||
> = AWSHandler<Event<TBody, TPathParameters, TQueryStringParameters>, Result>; | ||
|
||
// TODO: find a way to remove the couple of `any` here. Validation and typing are still working though | ||
export const middyfy = ( | ||
handler: any, | ||
schema: Record<string, unknown> | null = null | ||
): MiddyfiedHandler<Event<never, never, never>, Result, Error, Context> => { | ||
const wrapper: any = middy(handler) | ||
.use(middyJsonBodyParser()) | ||
.use(httpEventNormalizer()); | ||
|
||
if (schema) { | ||
wrapper.use(validator({ eventSchema: transpileSchema(schema) })); | ||
} | ||
|
||
return wrapper.use(cors()).use(httpErrorHandler({})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.