Coder Social home page Coder Social logo

mikaelvesavuori / triplecheck-repository-dynamodb Goto Github PK

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

Database utility for using DynamoDB with TripleCheck broker.

License: MIT License

Shell 4.73% JavaScript 21.98% TypeScript 73.29%
triplecheck contract-testing consumer-contracts pacts consumer-driven-contracts

triplecheck-repository-dynamodb's Introduction

triplecheck-repository-dynamodb

TripleCheck database repository

TripleCheck: DynamoDB database repository

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

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<any> {
  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
  ];
}

triplecheck-repository-dynamodb'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.