https://github.com/mikaelvesavuori/triplecheck-repository-dynamodb
Database utility for using DynamoDB with TripleCheck broker.
https://github.com/mikaelvesavuori/triplecheck-repository-dynamodb
consumer-contracts consumer-driven-contracts contract-testing pacts triplecheck
Last synced: 4 months ago
JSON representation
Database utility for using DynamoDB with TripleCheck broker.
- Host: GitHub
- URL: https://github.com/mikaelvesavuori/triplecheck-repository-dynamodb
- Owner: mikaelvesavuori
- License: mit
- Created: 2021-05-14T17:23:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-18T14:49:00.000Z (about 4 years ago)
- Last Synced: 2025-01-16T16:22:23.591Z (5 months ago)
- Topics: consumer-contracts, consumer-driven-contracts, contract-testing, pacts, triplecheck
- Language: TypeScript
- Homepage:
- Size: 853 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# triplecheck-repository-dynamodb

## TripleCheck: DynamoDB database repository
Database utility for using DynamoDB with TripleCheck broker. It implements the repository base at [triplecheck-core](https://github.com/mikaelvesavuori/triplecheck-core).
## Instructions
You will need to have a pre-existing DynamoDB table. Use `id` (String type) as the primary partition key.
## Basic implementation
In your `triplecheck-broker` implementation, do a regular import for `triplecheck-repository-dynamodb` and pass the repository to the broker. In a Lambda context, an implementation could look like:
```TypeScript
import { TripleCheckBroker } from 'triplecheck-broker';
import { DynamoRepository } from 'triplecheck-repository-dynamodb';export async function handler(event: any) {
const repository = DynamoRepository();const [request, payload] = await getRequestData(event);
const { responseData, status, headers } = await TripleCheckBroker(request, payload, repository);
const response = {
statusCode: status,
body: JSON.stringify(responseData),
headers
};return response;
}/**
* @description Utility function to get the data we need to run the TripleCheck broker.
* Expects the full AWS Lambda event object.
*/
async function getRequestData(event: any): Promise {
const { body, httpMethod, path, queryStringParameters } = event;const payload = body && typeof body === 'string' ? JSON.parse(body) : body;
const search = (() => {
let _search = '';
if (queryStringParameters && JSON.stringify(queryStringParameters) !== '{}') {
_search += Object.keys(queryStringParameters)[0];
_search += Object.values(queryStringParameters)[0];
}
return _search;
})();return [
{
method: httpMethod,
pathname: path || '/',
search
},
payload
];
}```