node package manager

pouch-stream-server

pouch-stream-server

By Build Status

PouchDB stream server. Serves generic PouchDB object streams.

Goes well with pouch-remote-stream on the client.

PouchDB version

Tested against PouchDB version 5.

Install

$ npm install pouch-server-stream --save

Use

var PouchDB = require('pouchdb');
 
// Create DB 
var db = new PouchDB('mydb');
 
var PouchStreamServer = require('pouch-stream-server');
 
 
// Create a server 
 
var server = PouchStreamServer();
 
// Add a database to it 
 
server.dbs.add('mydb', db);
 
// Connect the streams 
 
netServer.on('connection', function(conn) {
  var stream = server.stream();
  stream.pipe(conn).pipe(stream);
});

API

PouchStreamServer([options])

Creates a Pouch Stream server. Example:

var PouchStreamServer = require('pouch-stream-server');
var server = PouchStreamServer(options);

options is an optional object with any of the following keys:

  • highWaterMark: The maximum number of objects to store in the internal buffer before ceasing to read from the underlying resource (when reading) or inducing back-pressure (when writing). Defaults to 16.

server

server.dbs.add(dbName, db)

Adds a database that can be addressed by name from the remote stream. Example:

var db = new PouchDB('mydb');
server.dbs.add('myremotedb', db);

server.stream([options])

Returns a stream to be used to talk to a remote client.

options is an optional object with the following optional keys:

  • highWaterMark: The maximum number of objects to store in the internal buffer before ceasing to read from the underlying resource (when reading) or inducing back-pressure (when writing). Defaults to 16.
  • databases: Indication of which databases are allowed to use this stream. Defaults to any. Can be either:
    • a string containing the name of the one allowed database
    • an array of strings containing the names of the allowed databases
    • a filter function that accepts the database name and returns a truthy value if the database is allowed to be used in this stream.

License

ISC