Skip to content

Commit

Permalink
Merge pull request #9 from antoinewg/antoinewg/node-20
Browse files Browse the repository at this point in the history
Migrate to node 20
  • Loading branch information
antoinewg authored Feb 13, 2024
2 parents 5b8f6a7 + e453d9c commit b049700
Show file tree
Hide file tree
Showing 20 changed files with 2,545 additions and 2,004 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
with:
fetch-depth: 2

- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v3
with:
version: 8.0.0
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: "pnpm"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ See [Remote Caching (Beta)](https://turborepo.org/docs/core-concepts/remote-cach
- clone this repo, or use it as template.
- install [pnpm](https://pnpm.io/installation) for package management.
- install the dependencies: `pnpm i`.
- build and run the services: `pnpm run build && pnpm run dev`.
- build and run the services: `pnpm build && pnpm dev`.
- send first request:

```bash
Expand Down
37 changes: 18 additions & 19 deletions package.json
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/*",
Expand All @@ -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]"
}
6 changes: 1 addition & 5 deletions packages/eslint-config-custom/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
module.exports = {
"root": true,
"extends": [
"plugin:you-dont-need-lodash-underscore/compatible",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:vitest/recommended",
"plugin:security/recommended"
"plugin:vitest/recommended"
],
"plugins": [
"@typescript-eslint",
"vitest",
"security",
"node"
],
"rules": {
Expand All @@ -29,7 +26,6 @@ module.exports = {
"@typescript-eslint/semi": "warn",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-namespace": "warn",
"security/detect-object-injection": "warn",
"no-var": "error",
"no-console": "warn",
"camelcase": "off",
Expand Down
14 changes: 6 additions & 8 deletions packages/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
"check:updates:u": "npx npm-check-updates -u && pnpm i"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-vitest": "^0.0.54",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vitest": "^0.3.22",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
"typescript": "^4.9.5"
"typescript": "^5.3.3"
},
"publishConfig": {
"access": "public"
Expand Down
67 changes: 63 additions & 4 deletions packages/helpers/middify.ts
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({}));
};
13 changes: 9 additions & 4 deletions packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
"test:watch": "vitest"
},
"dependencies": {
"@middy/core": "^4.2.6",
"@middy/http-json-body-parser": "^4.2.6"
"@middy/core": "^5.2.4",
"@middy/http-cors": "^5.2.4",
"@middy/http-error-handler": "^5.2.4",
"@middy/http-event-normalizer": "^5.2.4",
"@middy/http-json-body-parser": "^5.2.4",
"@middy/util": "^5.2.4",
"@middy/validator": "^5.2.4"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.111",
"json-schema-to-ts": "^2.7.2"
"@types/aws-lambda": "^8.10.133",
"json-schema-to-ts": "^3.0.0"
}
}
16 changes: 0 additions & 16 deletions packages/helpers/response.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
import type {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Handler,
} from "aws-lambda";
import type { FromSchema } from "json-schema-to-ts";

export type ValidatedAPIGatewayProxyEvent<S extends object> = Omit<
APIGatewayProxyEvent,
"body"
> & { body: FromSchema<S> };
export type ValidatedEventAPIGatewayProxyEvent<S extends object> = Handler<
ValidatedAPIGatewayProxyEvent<S>,
APIGatewayProxyResult
>;

export const formatJSONResponse = (response: Record<string, unknown>) => {
return {
statusCode: 200,
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"check:updates:u": "npx npm-check-updates -u && pnpm i"
},
"devDependencies": {
"tsconfig-paths": "^4.1.2"
"tsconfig-paths": "^4.2.0"
}
}
Loading

0 comments on commit b049700

Please sign in to comment.