npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sengi-express

v14.0.0

Published

An express interface to the Sengi engine.

Downloads

4

Readme

Sengi Express

This package is part of the Sengi family.

npm

An ExpressJS RESTful host for a Sengi-based document service.

This modules provides a createSengiExpress function that returns an Express Request handler that you can mount using app.use.

Installation

npm install sengi-express

Usage

import { MemDocStore } from 'sengi-docstore-mem'
import { createSengiExpress } from 'sengi-express'
import { v4 } from 'uuid'

const docTypes = [] // import implementations of DocType interface
const clients = [] // import implementations of Client interface

const memDocStore = new MemDocStore({ docs, generateDocVersionFunc: v4 })
const sengiExpress = createSengiExpress({
  docStore: memDocStore,
  docTypes,
  clients
})

const app = express()
app.use(bodyParser.json())
app.use('/', sengiExpress)

Constructor

To instantiate a sengi-express server you pass the constructor parameters defined for a sengi-engine plus the following additional properties:

  • additionalComponentsCount - The number of additional components to be expected between the / and /docTypeName component parts of the request url. This can be used for capturing additional url parameters (e.g. tenant id).

  • getDocStoreOptions - A function that returns an object that will be provided to the DocStore and included in DocStore callbacks.

  • getRequestOptions - A functino that returns an object that will be provided to the Sengi Engine and included in Sengi Engine callbacks.

  • getUuid - 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.

The getDocStoreOptions and getRequestOptions callbacks will be passed a SengiExpressCallbackProps object. This contains the following properties:

  • headers - An object where each key name is a header name and each value is the corresponding header value sent with a request.

  • path - The path of the request.

  • matchedResourceType - The type of resource that was matched from the RestResourceType enum.

  • method - The method of the request, e.g. GET, POST, etc

  • urlParams - The parameters pulled from the url as a consequence of matching the resource type. Possible keys are adc, docTypePluralName, id and operationName.

Routes

A SengiExpress mounted at the / path would make a number of different routes accessible. If you want to divide your doc types into collections, then mount multiple handlers at different points, e.g. /cars and /bikes.

The examples below assume that Sengi is mounted at /sengi.

To retrieve all documents in a collection:

GET https://server.com/sengi/records/<docTypePluralName>?fields=a,b,c

(This route all supports the offset and limit query parameters, although this is not supported by all doc stores)

To retrieve a subset of documents from a collection using a filter:

GET https://server.com/sengi/records/<docTypePluralName>?fields=a,b,c&filterName=myFilter&filterParams={"foo":"bar"}

To retrieve a subset of documents from a collection by specifying id's:

GET https://server.com/sengi/records/<docTypePluralName>?fields=a,b,c&ids=1234,5678

To create a new document, post the new document to:

POST https://server.com/sengi/records/<docTypePluralName>

To create a new document using a constructor, post constructor parameters to:

POST https://server.com/sengi/records/<docTypePluralName>:<constructorName>

To access a single document:

GET https://server.com/sengi/records/<docTypePluralName>/<id>?fields=a,b,c

To update a document, send new field values:

PATCH https://server.com/sengi/records/<docTypePluralName>/<id>

To execute an operation, send operation parameters to:

POST https://server.com/sengi/records/<docTypePluralName>/<id>:<operationName>

To patch a document, send a merge patch object to:

PATCH https://server.com/sengi/records/<docTypePluralName>/<id>

To delete a document:

DELETE https://server.com/sengi/records/<docTypePluralName>/<id>

Development

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 family of libraries to be re-published.