From e422e2c0a41e12cbc4432af60cdf175ccc88ad68 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Wed, 12 Feb 2025 09:20:07 +0100 Subject: [PATCH 1/2] chore(validation): add workspace pkg --- ...sable-run-linting-check-and-unit-tests.yml | 1 + package-lock.json | 70 +++++++++++++++++- package.json | 3 +- packages/validation/README.md | 74 +++++++++++++++++++ packages/validation/package.json | 69 +++++++++++++++++ packages/validation/src/index.ts | 1 + packages/validation/tests/tsconfig.json | 8 ++ packages/validation/tests/unit/index.test.ts | 16 ++++ packages/validation/tsconfig.esm.json | 10 +++ packages/validation/tsconfig.json | 9 +++ packages/validation/vitest.config.ts | 8 ++ 11 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 packages/validation/README.md create mode 100644 packages/validation/package.json create mode 100644 packages/validation/src/index.ts create mode 100644 packages/validation/tests/tsconfig.json create mode 100644 packages/validation/tests/unit/index.test.ts create mode 100644 packages/validation/tsconfig.esm.json create mode 100644 packages/validation/tsconfig.json create mode 100644 packages/validation/vitest.config.ts diff --git a/.github/workflows/reusable-run-linting-check-and-unit-tests.yml b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml index 91fcc711f4..5e4cab43a2 100644 --- a/.github/workflows/reusable-run-linting-check-and-unit-tests.yml +++ b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml @@ -50,6 +50,7 @@ jobs: "packages/tracer", "packages/parser", "packages/parameters", + "packages/validation", "packages/metrics" ] fail-fast: false diff --git a/package-lock.json b/package-lock.json index 632c7c57f7..970cc291cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,8 @@ "examples/snippets", "layers", "examples/app", - "packages/event-handler" + "packages/event-handler", + "packages/validation" ], "devDependencies": { "@biomejs/biome": "^1.9.4", @@ -354,6 +355,10 @@ "resolved": "packages/tracer", "link": true }, + "node_modules/@aws-lambda-powertools/validation": { + "resolved": "packages/validation", + "link": true + }, "node_modules/@aws-sdk/client-appconfigdata": { "version": "3.744.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-appconfigdata/-/client-appconfigdata-3.744.0.tgz", @@ -4639,6 +4644,22 @@ "node": ">=8" } }, + "node_modules/ajv": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -6736,6 +6757,12 @@ "node": ">=0.6.0" } }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -6752,6 +6779,22 @@ "node": ">=8.6.0" } }, + "node_modules/fast-uri": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.6.tgz", + "integrity": "sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/fast-xml-parser": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.4.1.tgz", @@ -8258,6 +8301,12 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -12519,6 +12568,15 @@ "node": ">=0.10.0" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -15709,6 +15767,16 @@ "optional": true } } + }, + "packages/validation": { + "name": "@aws-lambda-powertools/validation", + "version": "2.14.0", + "license": "MIT-0", + "dependencies": { + "@aws-lambda-powertools/commons": "^2.14.0", + "@aws-lambda-powertools/jmespath": "^2.14.0", + "ajv": "^8.17.1" + } } } } diff --git a/package.json b/package.json index 70726e0ebf..299b5ed4fb 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "examples/snippets", "layers", "examples/app", - "packages/event-handler" + "packages/event-handler", + "packages/validation" ], "scripts": { "test": "npm t -ws", diff --git a/packages/validation/README.md b/packages/validation/README.md new file mode 100644 index 0000000000..0c312ce069 --- /dev/null +++ b/packages/validation/README.md @@ -0,0 +1,74 @@ +# Powertools for AWS Lambda (TypeScript) - Validation Utility + +> [!Warning] +> This feature is currently under development. As such it's considered not stable and we might make significant breaking changes before going before its release. You are welcome to [provide feedback](https://github.com/aws-powertools/powertools-lambda-typescript/discussions/3519) and [contribute to the project](https://docs.powertools.aws.dev/lambda/typescript/latest/contributing/getting_started/). + +Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/typescript/latest/#features). + +You can use the library in both TypeScript and JavaScript code bases. + +## Intro + +This utility provides JSON Schema validation for events and responses, including JMESPath support to unwrap events before validation. + +## Usage + +To get started, install the library by running: + +```sh +npm i @aws-lambda-powertools/validation +``` + +> [!Note] +> This readme is a work in progress. + +## Contribute + +If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/CONTRIBUTING.md). + +## Roadmap + +The roadmap of Powertools for AWS Lambda (TypeScript) is driven by customers’ demand. +Help us prioritize upcoming functionalities or utilities by [upvoting existing RFCs and feature requests](https://github.com/aws-powertools/powertools-lambda-typescript/issues), or [creating new ones](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new/choose), in this GitHub repository. + +## Connect + +- **Powertools for AWS Lambda on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)** +- **Email**: + +## How to support Powertools for AWS Lambda (TypeScript)? + +### Becoming a reference customer + +Knowing which companies are using this library is important to help prioritize the project internally. If your company is using Powertools for AWS Lambda (TypeScript), you can request to have your name and logo added to the README file by raising a [Support Powertools for AWS Lambda (TypeScript) (become a reference)](https://s12d.com/become-reference-pt-ts) issue. + +The following companies, among others, use Powertools: + +- [Alma Media](https://www.almamedia.fi) +- [AppYourself](https://appyourself.net) +- [Bailey Nelson](https://www.baileynelson.com.au) +- [Banxware](https://www.banxware.com) +- [Caylent](https://caylent.com/) +- [Certible](https://www.certible.com/) +- [Elva](https://elva-group.com) +- [Flyweight](https://flyweight.io/) +- [globaldatanet](https://globaldatanet.com/) +- [Hashnode](https://hashnode.com/) +- [LocalStack](https://localstack.cloud/) +- [Perfect Post](https://www.perfectpost.fr) +- [Sennder](https://sennder.com/) +- [tecRacer GmbH & Co. KG](https://www.tecracer.com/) +- [Trek10](https://www.trek10.com/) +- [WeSchool](https://www.weschool.com) + +### Sharing your work + +Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog post, workshops, presentation, sample apps and others. Check out what the community has already shared about Powertools for AWS Lambda (TypeScript) [here](https://docs.powertools.aws.dev/lambda/typescript/latest/we_made_this). + +### Using Lambda Layer + +This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](https://docs.powertools.aws.dev/lambda/typescript/latest/#lambda-layer), you can add Powertools as a dev dependency to not impact the development process. + +## License + +This library is licensed under the MIT-0 License. See the LICENSE file. diff --git a/packages/validation/package.json b/packages/validation/package.json new file mode 100644 index 0000000000..9a604a2b73 --- /dev/null +++ b/packages/validation/package.json @@ -0,0 +1,69 @@ +{ + "name": "@aws-lambda-powertools/validation", + "version": "2.14.0", + "description": "An utility to validate events and responses using JSON Schemas", + "author": { + "name": "Amazon Web Services", + "url": "https://aws.amazon.com" + }, + "private": true, + "scripts": { + "test": "vitest --run", + "test:unit": "vitest --run", + "test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'", + "test:unit:types": "echo 'Not Implemented'", + "test:e2e:nodejs18x": "echo \"Not implemented\"", + "test:e2e:nodejs20x": "echo \"Not implemented\"", + "test:e2e:nodejs22x": "echo \"Not implemented\"", + "test:e2e": "echo \"Not implemented\"", + "build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", + "build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json", + "build": "echo \"Not implemented\"", + "lint": "biome lint .", + "lint:fix": "biome check --write .", + "prepack": "node ../../.github/scripts/release_patch_package_json.js ." + }, + "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme", + "license": "MIT-0", + "type": "module", + "exports": { + ".": { + "require": { + "types": "./lib/cjs/index.d.ts", + "default": "./lib/cjs/index.js" + }, + "import": { + "types": "./lib/esm/index.d.ts", + "default": "./lib/esm/index.js" + } + } + }, + "types": "./lib/cjs/index.d.ts", + "main": "./lib/cjs/index.js", + "files": [ + "lib" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git" + }, + "bugs": { + "url": "https://github.com/aws-powertools/powertools-lambda-typescript/issues" + }, + "dependencies": { + "@aws-lambda-powertools/commons": "^2.14.0", + "@aws-lambda-powertools/jmespath": "^2.14.0", + "ajv": "^8.17.1" + }, + "keywords": [ + "aws", + "lambda", + "powertools", + "json-schema", + "validation", + "event", + "handler", + "nodejs", + "serverless" + ] +} diff --git a/packages/validation/src/index.ts b/packages/validation/src/index.ts new file mode 100644 index 0000000000..9d87720cc5 --- /dev/null +++ b/packages/validation/src/index.ts @@ -0,0 +1 @@ +export const foo = () => true; diff --git a/packages/validation/tests/tsconfig.json b/packages/validation/tests/tsconfig.json new file mode 100644 index 0000000000..39f442212e --- /dev/null +++ b/packages/validation/tests/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../../", + "noEmit": true + }, + "include": ["../../testing/src/setupEnv.ts", "../src/**/*", "./**/*"] +} diff --git a/packages/validation/tests/unit/index.test.ts b/packages/validation/tests/unit/index.test.ts new file mode 100644 index 0000000000..096d56dbb9 --- /dev/null +++ b/packages/validation/tests/unit/index.test.ts @@ -0,0 +1,16 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { foo } from '../../src/index.js'; + +describe('Validation', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('should return true', () => { + // Act + const result = foo(); + + // Assess + expect(result).toBe(true); + }); +}); diff --git a/packages/validation/tsconfig.esm.json b/packages/validation/tsconfig.esm.json new file mode 100644 index 0000000000..82486b64fa --- /dev/null +++ b/packages/validation/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.esm.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "./lib/esm", + "rootDir": "./src", + "tsBuildInfoFile": ".tsbuildinfo/esm.json" + }, + "include": ["./src/**/*"] +} diff --git a/packages/validation/tsconfig.json b/packages/validation/tsconfig.json new file mode 100644 index 0000000000..4923c4f6f4 --- /dev/null +++ b/packages/validation/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./lib/cjs/", + "rootDir": "./src", + "tsBuildInfoFile": ".tsbuildinfo/cjs.json" + }, + "include": ["./src/**/*"] +} diff --git a/packages/validation/vitest.config.ts b/packages/validation/vitest.config.ts new file mode 100644 index 0000000000..9f1196ef1f --- /dev/null +++ b/packages/validation/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineProject } from 'vitest/config'; + +export default defineProject({ + test: { + environment: 'node', + setupFiles: ['../testing/src/setupEnv.ts'], + }, +}); From 45747b2b728263f39d7708261e09bb65a0399cbb Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Wed, 12 Feb 2025 10:53:08 +0100 Subject: [PATCH 2/2] chore: add pkg to lerna.json --- lerna.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lerna.json b/lerna.json index b294aaa8e1..ab5ffd1ff9 100644 --- a/lerna.json +++ b/lerna.json @@ -11,6 +11,7 @@ "packages/jmespath", "packages/parser", "packages/event-handler", + "packages/validation", "examples/app", "layers", "examples/snippets"