https://github.com/mikaelvesavuori/triplecheck-repository-cloudflarekv
Database utility for using Cloudflare KV with TripleCheck broker.
https://github.com/mikaelvesavuori/triplecheck-repository-cloudflarekv
broker cloudflare cloudflare-kv consumer-contracts consumer-driven-contracts contract-testing pacts triplecheck
Last synced: about 2 months ago
JSON representation
Database utility for using Cloudflare KV with TripleCheck broker.
- Host: GitHub
- URL: https://github.com/mikaelvesavuori/triplecheck-repository-cloudflarekv
- Owner: mikaelvesavuori
- License: mit
- Created: 2021-04-24T13:42:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-18T13:41:30.000Z (almost 4 years ago)
- Last Synced: 2025-01-16T16:22:24.139Z (4 months ago)
- Topics: broker, cloudflare, cloudflare-kv, consumer-contracts, consumer-driven-contracts, contract-testing, pacts, triplecheck
- Language: TypeScript
- Homepage:
- Size: 994 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-cloudflarekv

## TripleCheck: Cloudflare KV database repository
Database utility for using Cloudflare KV with TripleCheck broker. It implements the repository base at [triplecheck-core](https://github.com/mikaelvesavuori/triplecheck-core).
## Basic implementation
In your `triplecheck-broker` implementation, do a regular import for `triplecheck-repository-cloudflarekv` and pass the repository to the broker. In a Cloudflare Workers context, an implementation could look like:
```TypeScript
import { CloudflareKvRepository } from 'triplecheck-repository-cloudflarekv';
import { TripleCheckBroker } from 'triplecheck-broker';async function handler(req: any) {
const repository = new CloudflareKvRepository();// We need to pass a cleaned request object, body/payload and repository to Triplecheck
const { body, method } = req;
const { pathname, search } = new URL(req.url);
const payload: any = body ? await req.json() : null;const request = {
method,
pathname,
search
};const { responseData, status, headers } = await TripleCheckBroker(
request,
payload,
repository
);return new Response(JSON.stringify(responseData), { status, headers });
}addEventListener('fetch', (event) => event.respondWith(handler(event.request)));
```