-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(idempotency): create initial class structure for function idempotency #1086
Changes from all commits
effbf64
12b1d03
8bc66e3
ea5548d
238d6fe
11d5633
b0f70c7
83aae62
fe5547e
dc2382e
1218fab
a8371eb
ff331d7
608adac
7d82aff
a25e11b
4309713
916a252
d90909e
2d9d377
c300988
09eff54
a2922e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# AWS Lambda Powertools for TypeScript | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintainers ( @flochaz @dreamorosi) I propose having just a link to our documentation page for now. Then we can use this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, Until we publish the package we can use the README like you suggest since it won't be published anywhere. It's good to have design, class diagrams, etc. near the code & version controlled. Once we start publishing the package on NPM however I would be inclined to follow the same structure we have for all the others since it's the "landing page" of the package on NPM and customers might arrive to that page without having seen our repo or our docs. |
||
|
||
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. |
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' | ||
] | ||
}; |
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" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PersistenceLayer } from './persistence/PersistenceLayer'; | ||
|
||
type IdempotencyOptions = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Note for reviewers): The term "Options" is consistent with other utilities (logger, metrics, tracer). However, Python's idempotency uses the term "Config" instead (code). Still, I prefer "Options" as used here. It's more consistent. Let me know if you disagree. |
||
dataKeywordArgument: string | ||
persistenceStore: PersistenceLayer | ||
}; | ||
|
||
export { IdempotencyOptions }; |
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 }; |
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 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from
@aws-lambda-powertools/commons
, @types/aws-lambdaand
lodash`, let's remove the other libraries we are not sure if we will be using yet.