Skip to content

Commit 06fbaae

Browse files
jeffrey-baker-vgvgphoenixcamposKeven“KevenFuentes9”KevenFuentes9
authored
feat(idempotency): create initial class structure for function idempotency (#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 <[email protected]> Co-authored-by: Keven <[email protected]> Co-authored-by: “KevenFuentes9” <“[email protected]”> Co-authored-by: KevenFuentes9 <[email protected]> Co-authored-by: Phoenix Campos <[email protected]>
1 parent bce3f2b commit 06fbaae

17 files changed

+12487
-12063
lines changed

Diff for: layer-publisher/package-lock.json

+12,051-12,051
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package-lock.json

+4-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/idempotency/LICENSE-THIRD-PARTY

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
@aws-lambda-powertools/commons
2+
0.0.2 <https://github.com/awslabs/aws-lambda-powertools-typescript>
3+
license: MIT*
4+
authors: Amazon Web Services <https://aws.amazon.com>
5+
6+
******************************
7+
8+
@types/aws-lambda
9+
8.10.87 <https://github.com/DefinitelyTyped/DefinitelyTyped>
10+
MIT License
11+
12+
Copyright (c) Microsoft Corporation.
13+
14+
Permission is hereby granted, free of charge, to any person obtaining a copy
15+
of this software and associated documentation files (the "Software"), to deal
16+
in the Software without restriction, including without limitation the rights
17+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
copies of the Software, and to permit persons to whom the Software is
19+
furnished to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in all
22+
copies or substantial portions of the Software.
23+
24+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
SOFTWARE
31+
32+
33+
******************************
34+
35+
lodash
36+
4.17.21 <https://github.com/lodash/lodash>
37+
Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
38+
39+
Based on Underscore.js, copyright Jeremy Ashkenas,
40+
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
41+
42+
This software consists of voluntary contributions made by many
43+
individuals. For exact contribution history, see the revision history
44+
available at https://github.com/lodash/lodash
45+
46+
The following license applies to all parts of this software except as
47+
documented below:
48+
49+
====
50+
51+
Permission is hereby granted, free of charge, to any person obtaining
52+
a copy of this software and associated documentation files (the
53+
"Software"), to deal in the Software without restriction, including
54+
without limitation the rights to use, copy, modify, merge, publish,
55+
distribute, sublicense, and/or sell copies of the Software, and to
56+
permit persons to whom the Software is furnished to do so, subject to
57+
the following conditions:
58+
59+
The above copyright notice and this permission notice shall be
60+
included in all copies or substantial portions of the Software.
61+
62+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
63+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
65+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
66+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
67+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
68+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69+
70+
====
71+
72+
Copyright and related rights for sample code are waived via CC0. Sample
73+
code is defined as all source code displayed within the prose of the
74+
documentation.
75+
76+
CC0: http://creativecommons.org/publicdomain/zero/1.0/
77+
78+
====
79+
80+
Files located in the node_modules and vendor directories are externally
81+
maintained libraries used by this software which have their own
82+
licenses; we recommend you read them, as their terms may differ from the
83+
terms above.

Diff for: packages/idempotency/README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# AWS Lambda Powertools for TypeScript
2+
3+
A suite of utilities for AWS Lambda functions to ease the adoption of best practices such as tracing, structured logging, custom metrics, and more.
4+
5+
You can use the library in both TypeScript and JavaScript code bases.
6+
7+
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.
8+
9+
**[📜 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)**
10+
11+
## Table of contents
12+
13+
- [Features](#features)
14+
- [Getting started](#getting-started)
15+
- [Installation](#installation)
16+
- [Examples](#examples)
17+
- [Serverless TypeScript Demo](#serverless-typescript-demo-application)
18+
- [Contribute](#contribute)
19+
- [Roadmap](#roadmap)
20+
- [Connect](#connect)
21+
- [Credits](#credits)
22+
- [License](#license)
23+
24+
## Features
25+
26+
* **[Tracer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
27+
* **[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
28+
* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
29+
30+
## Getting started
31+
32+
Find the complete project's [documentation here](https://awslabs.github.io/aws-lambda-powertools-typescript).
33+
34+
### Installation
35+
36+
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).
37+
Each TypeScript utility is installed as standalone NPM package.
38+
39+
Install all three core utilities at once with this single command:
40+
41+
```shell
42+
npm install @aws-lambda-powertools/logger @aws-lambda-powertools/tracer @aws-lambda-powertools/metrics
43+
```
44+
45+
Or refer to the installation guide of each utility:
46+
47+
👉 [Installation guide for the **Tracer** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer#getting-started)
48+
49+
👉 [Installation guide for the **Logger** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger#getting-started)
50+
51+
👉 [Installation guide for the **Metrics** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics#getting-started)
52+
53+
### Examples
54+
55+
* [CDK](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk)
56+
* [SAM](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/sam)
57+
58+
### Serverless TypeScript Demo application
59+
60+
The [Serverless TypeScript Demo](https://github.com/aws-samples/serverless-typescript-demo) shows how to use Lambda Powertools for TypeScript.
61+
You can find instructions on how to deploy and load test this application in the [repository](https://github.com/aws-samples/serverless-typescript-demo).
62+
63+
## Contribute
64+
65+
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).
66+
67+
## Roadmap
68+
69+
The roadmap of Powertools is driven by customers’ demand.
70+
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.
71+
72+
## Connect
73+
74+
* **AWS Lambda Powertools on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)**
75+
* **Email**: [email protected]
76+
77+
## Credits
78+
79+
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/).
80+
81+
## License
82+
83+
This library is licensed under the MIT-0 License. See the LICENSE file.

Diff for: packages/idempotency/jest.config.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module.exports = {
2+
displayName: {
3+
name: 'AWS Lambda Powertools utility: IDEMPOTENCY',
4+
color: 'cyan',
5+
},
6+
'runner': 'groups',
7+
'preset': 'ts-jest',
8+
'transform': {
9+
'^.+\\.ts?$': 'ts-jest',
10+
},
11+
moduleFileExtensions: [ 'js', 'ts' ],
12+
'collectCoverageFrom': [
13+
'**/src/**/*.ts',
14+
'!**/node_modules/**',
15+
],
16+
'testMatch': ['**/?(*.)+(spec|test).ts'],
17+
'roots': [
18+
'<rootDir>/src',
19+
'<rootDir>/tests',
20+
],
21+
'testPathIgnorePatterns': [
22+
'/node_modules/',
23+
],
24+
'testEnvironment': 'node',
25+
'coveragePathIgnorePatterns': [
26+
'/node_modules/',
27+
'/types/',
28+
],
29+
'coverageThreshold': {
30+
'global': {
31+
'statements': 100,
32+
'branches': 100,
33+
'functions': 100,
34+
'lines': 100,
35+
},
36+
},
37+
'coverageReporters': [
38+
'json-summary',
39+
'text',
40+
'lcov'
41+
],
42+
'setupFiles': [
43+
'<rootDir>/tests/helpers/populateEnvironmentVariables.ts'
44+
]
45+
};

Diff for: packages/idempotency/package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "@aws-lambda-powertools/idempotency",
3+
"version": "0.0.11",
4+
"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.",
5+
"author": {
6+
"name": "Amazon Web Services",
7+
"url": "https://aws.amazon.com"
8+
},
9+
"publishConfig": {
10+
"access": "public"
11+
},
12+
"scripts": {
13+
"commit": "commit",
14+
"test": "npm run test:unit",
15+
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose",
16+
"test:e2e:nodejs12x": "RUNTIME=nodejs12x jest --group=e2e",
17+
"test:e2e:nodejs14x": "RUNTIME=nodejs14x jest --group=e2e",
18+
"test:e2e:nodejs16x": "RUNTIME=nodejs16x jest --group=e2e",
19+
"test:e2e": "jest --group=e2e",
20+
"watch": "jest --watch --group=unit",
21+
"build": "tsc",
22+
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
23+
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
24+
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
25+
"package-bundle": "../../package-bundler.sh logger-bundle ./dist",
26+
"prepare": "npm run build",
27+
"prepublishOnly": "npm test && npm run lint",
28+
"preversion": "npm run lint",
29+
"version": "npm run format && git add -A src",
30+
"postversion": "git push && git push --tags"
31+
},
32+
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/idempotency#readme",
33+
"license": "MIT",
34+
"main": "./lib/index.js",
35+
"types": "./lib/index.d.ts",
36+
"typedocMain": "src/index.ts",
37+
"files": [
38+
"lib"
39+
],
40+
"repository": {
41+
"type": "git",
42+
"url": "git+https://github.com/awslabs/aws-lambda-powertools-typescript.git"
43+
},
44+
"bugs": {
45+
"url": "https://github.com/awslabs/aws-lambda-powertools-typescript/issues"
46+
},
47+
"dependencies": {
48+
"@aws-lambda-powertools/commons": "^1.2.1"
49+
},
50+
"keywords": [
51+
"aws",
52+
"lambda",
53+
"powertools",
54+
"serverless",
55+
"nodejs"
56+
]
57+
}

Diff for: packages/idempotency/src/IdempotencyOptions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { PersistenceLayer } from './persistence/PersistenceLayer';
2+
3+
type IdempotencyOptions = {
4+
dataKeywordArgument: string
5+
persistenceStore: PersistenceLayer
6+
};
7+
8+
export { IdempotencyOptions };

Diff for: packages/idempotency/src/makeFunctionIdempotent.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { AnyFunction } from './types/AnyFunction';
3+
import { IdempotencyOptions } from './IdempotencyOptions';
4+
5+
const makeFunctionIdempotent = <U>(
6+
fn: AnyFunction<U>,
7+
_options: IdempotencyOptions
8+
): (...args: Array<any>) => Promise<U | void> => (...args) => fn(...args);
9+
10+
export { makeFunctionIdempotent };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
2+
import { IdempotencyRecord, PersistenceLayer } from './PersistenceLayer';
3+
4+
class DynamoDBPersistenceLayer extends PersistenceLayer {
5+
public constructor(_tableName: string, _key_attr: string = 'id') {
6+
super();
7+
}
8+
protected async _deleteRecord(): Promise<void> {}
9+
protected async _getRecord(): Promise<IdempotencyRecord> {
10+
return Promise.resolve({} as IdempotencyRecord);
11+
}
12+
protected async _putRecord(_record: IdempotencyRecord): Promise<void> {}
13+
protected async _updateRecord(): Promise<void> {}
14+
}
15+
16+
export {
17+
DynamoDBPersistenceLayer
18+
};

0 commit comments

Comments
 (0)