Skip to content
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

Merged
merged 23 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
effbf64
feat: initial configuration for idempotency package
vgphoenixcampos Sep 2, 2022
12b1d03
feat: initial idempotency classes
vgphoenixcampos Sep 2, 2022
8bc66e3
feat: inherit tsconfig from base
vgphoenixcampos Sep 8, 2022
ea5548d
feat: refactor persistence layer classes into their own folder
vgphoenixcampos Sep 8, 2022
238d6fe
feat: added async types to persistence layer
vgphoenixcampos Sep 8, 2022
11d5633
feat: rename idempotency config to differentiate from idempotency opt…
vgphoenixcampos Sep 8, 2022
b0f70c7
feat: added type for a generic function
vgphoenixcampos Sep 8, 2022
83aae62
feat: modified AnyFunction to accept void functions
vgphoenixcampos Sep 8, 2022
fe5547e
feat: defined member variables of record
vgphoenixcampos Sep 8, 2022
dc2382e
feat: remove idempotency configuration for this FR
vgphoenixcampos Sep 8, 2022
1218fab
feat: removing unused params from options
vgphoenixcampos Sep 8, 2022
a8371eb
feat: refactored type of function to accept any combo of parameters
vgphoenixcampos Sep 8, 2022
ff331d7
feat: add type for update and add functions for dynamo
Sep 9, 2022
608adac
feat: add table name for dynamo constructor
Sep 9, 2022
7d82aff
feat: add key attribute for dynamo record
KevenFuentes9 Sep 9, 2022
a25e11b
feat: add type for update and add functions for dynamo
KevenFuentes9 Sep 9, 2022
4309713
feat: add table name for dynamo constructor
KevenFuentes9 Sep 9, 2022
916a252
feat: add key attribute for dynamo record
KevenFuentes9 Sep 9, 2022
d90909e
Merge branch 'typescript-idempotency-initial-dev-branch' of https://g…
KevenFuentes9 Sep 9, 2022
2d9d377
feat: fixing linting issues
vgphoenixcampos Sep 9, 2022
c300988
Merge pull request #1 from jeffrey-baker-vg/typescript-idempotency-in…
vgphoenixcampos Sep 9, 2022
09eff54
feat: addressing comments in initial PR
jeffrey-baker-vg Sep 15, 2022
a2922e8
Merge pull request #2 from jeffrey-baker-vg/address-comments-initial-PR
jeffrey-baker-vg Sep 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions packages/idempotency/LICENSE-THIRD-PARTY
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
@aws-lambda-powertools/commons
Copy link
Contributor

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-lambdaandlodash`, let's remove the other libraries we are not sure if we will be using yet.

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.


******************************

lodash.clonedeep
4.5.0 <https://github.com/lodash/lodash>
Copyright jQuery Foundation and other contributors <https://jquery.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.


******************************

lodash.merge
4.6.2 <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.
83 changes: 83 additions & 0 deletions packages/idempotency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# AWS Lambda Powertools for TypeScript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintainers ( @flochaz @dreamorosi)
I know that this is all packages have the same copy. But this duplicates the top-level README.md and confuses readers that there is a new information here that is different from the top-level one.

I propose having just a link to our documentation page for now. Then we can use this README.md for any dev related items like design, class diagram, etc. The usages should always be the doc. Do you agree?

Copy link
Contributor

Choose a reason for hiding this comment

The 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**: [email protected]

## 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.
45 changes: 45 additions & 0 deletions packages/idempotency/jest.config.js
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'
]
};
57 changes: 57 additions & 0 deletions packages/idempotency/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@aws-lambda-powertools/idempotency",
"version": "0.0.11",
"description": "TBD",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"description": "TBD",
"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"
]
}
8 changes: 8 additions & 0 deletions packages/idempotency/src/IdempotencyOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PersistenceLayer } from './persistence/PersistenceLayer';

type IdempotencyOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 };
10 changes: 10 additions & 0 deletions packages/idempotency/src/makeFunctionIdempotent.ts
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 };
Loading