jsonotron-express v0.1.9
An ExpressJS RESTful host for Jsonotron
An ExpressJS RESTful host for Jsonotron.
This package is part of the Jsonotron system.
Jsonotron is...
- a small set of components for building a NodeJS microservice
- for storing, patching and querying JSON documents
- stored in a schemaless/NoSQL database
- that have known, enforceable, and evolving schemas.
Visit https://karlhulme.github.io/jsonotron/ for details on how to get started.
Installation
npm install jsonotron-express --save
Usage
To instantiate a jsonotron-express server you have to provide 4 parameters:
docStore - A document store implementation such as jsonotron-memdocstore or jsonotron-cosmosdb.
docTypes - An array of document type definitions.
roleTypes - An array of role type definitions.
config - A configuration object that consists of the following optional properties:
additionalComponentsCount The number of additional components to be expected between the /data and /docTypeName component parts of the request url.
getRequestRoles A function that will be given an HTTP request and returns the roles held by the requesting user.
createDocStoreOptions A function that will be given a document type and an array of additional path components and should return an object that will be passed to the document store.
jsonotronConfig An object that will be passed to configure the underlying jsonotron engine, such as customFieldTypes. See the documentation for karlhulme/jsonotron for values that can be supplied here.
uuid A function that generates a unique identifier, used for ensuring uniqueness of operations and patches. If not supplied then the uuid/v4 package is used by default.
logger A function that is passed an object with status, text, internalText, json and header properties that will be used to compose the response. If not supplied, then responses with a status of 500 or higher will be logged to stdout.
handler A function that overrides the handler used to process the response. This is used by the testing framework.
const { createMemDocStore } = require('jsonotron-memdocstore')
const { createJsonotronExpress } = require('jsonotron-express')
const uuid = require('uuid/v4')
const docTypes = []
const roleTypes = []
const memDocStore = createMemDocStore(docs, uuid)
const jsonotronExpress = createJsonotronExpress(memDocStore, docTypes, roleTypes, { uuid })
const app = express()
app.use(bodyParser.json())
app.use('/root', jsonotronExpress)
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