Socket
Socket
Sign inDemoInstall

couchdb-dispatcher

Package Overview
Dependencies
80
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    couchdb-dispatcher

> Massive getter by ID for CouchDB, with multiple collections


Version published
Weekly downloads
14
increased by1300%
Maintainers
1
Install size
4.12 MB
Created
Weekly downloads
 

Readme

Source

couchdb-dispatcher

Massive getter by ID for CouchDB, with multiple collections

Getting started

In order to install, simply use npm.

npm i couchdb-dispatcher

Then, import it in you file.

import { Routes, Route } from 'couchdb-dispatcher';

Usage

Dispatcher can hold two differents use cases: Dispatch into differents collection according to IDs, or serve access to a collection with a specific URL.

Dispatch into collections

According to some ID patterns, you can choose in which collection you want to fetch from.

import { EndpointAccepters, Routes } from 'couchdb-dispatcher';


// Set accepters
const accepters: EndpointAccepters = {
    'crispr_1': function(id: string) {
        return id.match(/arbitary_pattern/i);
    },
    'crispr_2': /test/i,
    'crispr_3': (id: string) => id.includes('cc')
};

// Set URL
const database_url = "http://localhost:5984";

// Create object
const routes = new Routes(accepters, database_url);

// Create a route that listen to request
routes.set({
    method: 'POST',
    route: '/bulk',
    get_keys: function (request, response) {
        if (request.body.keys && Array.isArray(request.body.keys)) {
            // If ok, return an array of ID string
            return request.body.keys;
        }

        // Otherwise, return nothing
        response.status(400).json({ error: "Request is invalid" });
    },
    post_data: function (_, response, data) {
        // Return database response as HTTP response
        response.json(data);
    }
})

FAQs

Last updated on 19 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc