-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(idempotency): create initial class structure for function idempo…
…tency (#1086) * feat: initial configuration for idempotency package * feat: initial idempotency classes * feat: inherit tsconfig from base * feat: refactor persistence layer classes into their own folder * feat: added async types to persistence layer * feat: rename idempotency config to differentiate from idempotency options * feat: added type for a generic function * feat: modified AnyFunction to accept void functions * feat: defined member variables of record * feat: remove idempotency configuration for this FR * feat: removing unused params from options * feat: refactored type of function to accept any combo of parameters * feat: add type for update and add functions for dynamo * feat: add table name for dynamo constructor * feat: add key attribute for dynamo record * feat: add type for update and add functions for dynamo * feat: add table name for dynamo constructor * feat: add key attribute for dynamo record * feat: fixing linting issues * feat: addressing comments in initial PR Co-authored-by: vgphoenixcampos <111440293+vgphoenixcampos@users.noreply.github.com> Co-authored-by: Keven <keven@Kevens-MacBook-Pro.local> Co-authored-by: “KevenFuentes9” <“keven_fuentes@vanguard.com”> Co-authored-by: KevenFuentes9 <keven_fuentes@vanguard.com> Co-authored-by: Phoenix Campos <phoenix_campos@vanguard.com>
- Loading branch information
1 parent
bce3f2b
commit 06fbaae
Showing
17 changed files
with
12,487 additions
and
12,063 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@aws-lambda-powertools/commons | ||
0.0.2 <https://github.com/awslabs/aws-lambda-powertools-typescript> | ||
license: MIT* | ||
authors: Amazon Web Services <https://aws.amazon.com> | ||
|
||
****************************** | ||
|
||
@types/aws-lambda | ||
8.10.87 <https://github.com/DefinitelyTyped/DefinitelyTyped> | ||
MIT License | ||
|
||
Copyright (c) Microsoft Corporation. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE | ||
|
||
|
||
****************************** | ||
|
||
lodash | ||
4.17.21 <https://github.com/lodash/lodash> | ||
Copyright OpenJS Foundation and other contributors <https://openjsf.org/> | ||
|
||
Based on Underscore.js, copyright Jeremy Ashkenas, | ||
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/> | ||
|
||
This software consists of voluntary contributions made by many | ||
individuals. For exact contribution history, see the revision history | ||
available at https://github.com/lodash/lodash | ||
|
||
The following license applies to all parts of this software except as | ||
documented below: | ||
|
||
==== | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
==== | ||
|
||
Copyright and related rights for sample code are waived via CC0. Sample | ||
code is defined as all source code displayed within the prose of the | ||
documentation. | ||
|
||
CC0: http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
==== | ||
|
||
Files located in the node_modules and vendor directories are externally | ||
maintained libraries used by this software which have their own | ||
licenses; we recommend you read them, as their terms may differ from the | ||
terms above. |
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# AWS Lambda Powertools for TypeScript | ||
|
||
A suite of utilities for AWS Lambda functions to ease the adoption of best practices such as tracing, structured logging, custom metrics, and more. | ||
|
||
You can use the library in both TypeScript and JavaScript code bases. | ||
|
||
AWS Lambda Powertools for [Python](https://github.com/awslabs/aws-lambda-powertools-python) and AWS Lambda Powertools for [Java](https://github.com/awslabs/aws-lambda-powertools-java) are also available. | ||
|
||
**[📜 Documentation](https://awslabs.github.io/aws-lambda-powertools-typescript/)** | **[NPM](https://www.npmjs.com/org/aws-lambda-powertools)** | **[Roadmap](https://github.com/awslabs/aws-lambda-powertools-roadmap/projects/1)** | **[Examples](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples)** | **[Serverless TypeScript Demo](https://github.com/aws-samples/serverless-typescript-demo)** | ||
|
||
## Table of contents | ||
|
||
- [Features](#features) | ||
- [Getting started](#getting-started) | ||
- [Installation](#installation) | ||
- [Examples](#examples) | ||
- [Serverless TypeScript Demo](#serverless-typescript-demo-application) | ||
- [Contribute](#contribute) | ||
- [Roadmap](#roadmap) | ||
- [Connect](#connect) | ||
- [Credits](#credits) | ||
- [License](#license) | ||
|
||
## Features | ||
|
||
* **[Tracer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions | ||
* **[Logger](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context | ||
* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) | ||
|
||
## Getting started | ||
|
||
Find the complete project's [documentation here](https://awslabs.github.io/aws-lambda-powertools-typescript). | ||
|
||
### Installation | ||
|
||
The AWS Lambda Powertools for TypeScript utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3). | ||
Each TypeScript utility is installed as standalone NPM package. | ||
|
||
Install all three core utilities at once with this single command: | ||
|
||
```shell | ||
npm install @aws-lambda-powertools/logger @aws-lambda-powertools/tracer @aws-lambda-powertools/metrics | ||
``` | ||
|
||
Or refer to the installation guide of each utility: | ||
|
||
👉 [Installation guide for the **Tracer** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer#getting-started) | ||
|
||
👉 [Installation guide for the **Logger** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger#getting-started) | ||
|
||
👉 [Installation guide for the **Metrics** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics#getting-started) | ||
|
||
### Examples | ||
|
||
* [CDK](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk) | ||
* [SAM](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/sam) | ||
|
||
### Serverless TypeScript Demo application | ||
|
||
The [Serverless TypeScript Demo](https://github.com/aws-samples/serverless-typescript-demo) shows how to use Lambda Powertools for TypeScript. | ||
You can find instructions on how to deploy and load test this application in the [repository](https://github.com/aws-samples/serverless-typescript-demo). | ||
|
||
## Contribute | ||
|
||
If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/awslabs/aws-lambda-powertools-typescript/blob/main/CONTRIBUTING.md). | ||
|
||
## Roadmap | ||
|
||
The roadmap of Powertools is driven by customers’ demand. | ||
Help us prioritize upcoming functionalities or utilities by [upvoting existing RFCs and feature requests](https://github.com/awslabs/aws-lambda-powertools-typescript/issues), or [creating new ones](https://github.com/awslabs/aws-lambda-powertools-typescript/issues/new/choose), in this GitHub repository. | ||
|
||
## Connect | ||
|
||
* **AWS Lambda Powertools on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)** | ||
* **Email**: aws-lambda-powertools-feedback@amazon.com | ||
|
||
## Credits | ||
|
||
Credits for the Lambda Powertools idea go to [DAZN](https://github.com/getndazn) and their [DAZN Lambda Powertools](https://github.com/getndazn/dazn-lambda-powertools/). | ||
|
||
## License | ||
|
||
This library is licensed under the MIT-0 License. See the LICENSE file. |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = { | ||
displayName: { | ||
name: 'AWS Lambda Powertools utility: IDEMPOTENCY', | ||
color: 'cyan', | ||
}, | ||
'runner': 'groups', | ||
'preset': 'ts-jest', | ||
'transform': { | ||
'^.+\\.ts?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: [ 'js', 'ts' ], | ||
'collectCoverageFrom': [ | ||
'**/src/**/*.ts', | ||
'!**/node_modules/**', | ||
], | ||
'testMatch': ['**/?(*.)+(spec|test).ts'], | ||
'roots': [ | ||
'<rootDir>/src', | ||
'<rootDir>/tests', | ||
], | ||
'testPathIgnorePatterns': [ | ||
'/node_modules/', | ||
], | ||
'testEnvironment': 'node', | ||
'coveragePathIgnorePatterns': [ | ||
'/node_modules/', | ||
'/types/', | ||
], | ||
'coverageThreshold': { | ||
'global': { | ||
'statements': 100, | ||
'branches': 100, | ||
'functions': 100, | ||
'lines': 100, | ||
}, | ||
}, | ||
'coverageReporters': [ | ||
'json-summary', | ||
'text', | ||
'lcov' | ||
], | ||
'setupFiles': [ | ||
'<rootDir>/tests/helpers/populateEnvironmentVariables.ts' | ||
] | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "@aws-lambda-powertools/idempotency", | ||
"version": "0.0.11", | ||
"description": "The idempotency package for the AWS Lambda Powertools for TypeScript library. It provides options to make your Lambda functions idempotent and safe to retry.", | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"commit": "commit", | ||
"test": "npm run test:unit", | ||
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose", | ||
"test:e2e:nodejs12x": "RUNTIME=nodejs12x jest --group=e2e", | ||
"test:e2e:nodejs14x": "RUNTIME=nodejs14x jest --group=e2e", | ||
"test:e2e:nodejs16x": "RUNTIME=nodejs16x jest --group=e2e", | ||
"test:e2e": "jest --group=e2e", | ||
"watch": "jest --watch --group=unit", | ||
"build": "tsc", | ||
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests", | ||
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests", | ||
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", | ||
"package-bundle": "../../package-bundler.sh logger-bundle ./dist", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/idempotency#readme", | ||
"license": "MIT", | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"typedocMain": "src/index.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/awslabs/aws-lambda-powertools-typescript.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/awslabs/aws-lambda-powertools-typescript/issues" | ||
}, | ||
"dependencies": { | ||
"@aws-lambda-powertools/commons": "^1.2.1" | ||
}, | ||
"keywords": [ | ||
"aws", | ||
"lambda", | ||
"powertools", | ||
"serverless", | ||
"nodejs" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PersistenceLayer } from './persistence/PersistenceLayer'; | ||
|
||
type IdempotencyOptions = { | ||
dataKeywordArgument: string | ||
persistenceStore: PersistenceLayer | ||
}; | ||
|
||
export { IdempotencyOptions }; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { AnyFunction } from './types/AnyFunction'; | ||
import { IdempotencyOptions } from './IdempotencyOptions'; | ||
|
||
const makeFunctionIdempotent = <U>( | ||
fn: AnyFunction<U>, | ||
_options: IdempotencyOptions | ||
): (...args: Array<any>) => Promise<U | void> => (...args) => fn(...args); | ||
|
||
export { makeFunctionIdempotent }; |
18 changes: 18 additions & 0 deletions
18
packages/idempotency/src/persistence/DynamoDbPersistenceLayer.ts
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { IdempotencyRecord, PersistenceLayer } from './PersistenceLayer'; | ||
|
||
class DynamoDBPersistenceLayer extends PersistenceLayer { | ||
public constructor(_tableName: string, _key_attr: string = 'id') { | ||
super(); | ||
} | ||
protected async _deleteRecord(): Promise<void> {} | ||
protected async _getRecord(): Promise<IdempotencyRecord> { | ||
return Promise.resolve({} as IdempotencyRecord); | ||
} | ||
protected async _putRecord(_record: IdempotencyRecord): Promise<void> {} | ||
protected async _updateRecord(): Promise<void> {} | ||
} | ||
|
||
export { | ||
DynamoDBPersistenceLayer | ||
}; |
Oops, something went wrong.