1.0.0 • Published 4 years ago

sengi-memdocstore v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

An in-memory document store for Sengi

npm.io npm JavaScript Style Guide

An in-memory JSON document store that implements the (Sengi)https://github.com/karlhulme/sengi document store interface.

This package is aimed at testing scenarios because the documents upserted and deleted from the collection are not stored permanently.

Installation

npm install sengi-memdocstore

Usage

To instantiate a MemDocStore you have to provide 2 parameters:

  • docs - An array of "documents". Each document is just a POJO.

  • docVersionGenerator - A function (doc) that returns a unique version number string given a document. This can be a hash based on the given document or just a unique number. Simplest method is to pass it the uuid/v4 library as this will generate a UUID.

const { createMemDocStore } = require('sengi-memdocstore')
const uuid = require('uuid/v4')

const docs = []
const memDocStore = createMemDocStore(docs, uuid)

memDocStore.upsert('test', {
  id: '0001',
  docType: 'test',
  hello: 'world'
})

Development

Code base adheres to the rules chosen by https://standardjs.com/. Code is formatted with 2 spaces.

Tests are written using Jest with 100% coverage.

npm test

Continuous Deployment

Any pushes or pull-requests on non-master branches will trigger the test runner.

Any pushes to master will cause the library to be re-published.