Coder Social home page Coder Social logo

mikaelvesavuori / triplecheck-repository-cloudflarekv Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1018 KB

Database utility for using Cloudflare KV with TripleCheck broker.

License: MIT License

Shell 1.71% TypeScript 90.37% JavaScript 7.93%
triplecheck contract-testing consumer-contracts pacts cloudflare-kv broker consumer-driven-contracts cloudflare

triplecheck-repository-cloudflarekv's Introduction

triplecheck-repository-cloudflarekv

TripleCheck database repository

TripleCheck: Cloudflare KV database repository

Database utility for using Cloudflare KV with TripleCheck broker. It implements the repository base at 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:

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)));

triplecheck-repository-cloudflarekv's People

Contributors

mikaelvesavuori avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.