New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

changes

Package Overview
Dependencies
Maintainers
4
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

changes

A consistent, fault tolerant CouchDB _changes listener with pre-fetch support

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-72.22%
Maintainers
4
Weekly downloads
 
Created
Source

changes

A consistent, fault tolerant CouchDB _changes listener with pre-fetch support.

Usage

  var Changes = require('changes');
  
  var changes = new Changes({
    url: 'http://user:pass@127.0.0.1:5984/database',
    timeout: {
      max:  60000,
      step: 5000
    }
  });
  
  //
  // Dump changes as they come in.
  //
  changes.on('change', function (doc) {
    console.dir(doc);
  });
  
  //
  // The callback will be called once a _changes
  // connection has been established or with an
  // error if the first connection fails.
  //
  changes.listen(function (err) {
    if (err) {
      console.log('Did not connect to _changes on first attempt');
      console.dir(err);
      changes.retry.enabled = false;
      return process.exit(1);
    }
    
    console.log('Listening for _changes');
  });

Pre-fetching Views

Often when you establish a connection to _changes you also want to know about the other documents in a view before the current update_seq. This is supported like this:

  var Changes = require('changes');
  
  var changes = new Changes({
    url: 'http://user:pass@127.0.0.1:5984/database',
    views: {
      'important': {
        path: '_design/Some/_view/name',
        query: { include_docs: true }
      }
    },
    timeout: {
      max:  60000,
      step: 5000
    }
  });

  //
  // All rows from a queries view will be emitted
  // in the `views:<name>` event **before** the
  // `_changes` listener starts. 
  //
  changes.on('views:important', function (rows) {
    //
    // Dump any existing "important" rows.
    //
    console.dir(rows);
  });
  
  //
  // Dump changes as they come in.
  //
  changes.on('change', function (doc) {
    console.dir(doc);
  });
  
  //
  // The callback will be called once a _changes
  // connection has been established or with an
  // error if the first connection fails.
  //
  changes.listen(function (err) {
    if (err) {
      console.log('Did not connect to _changes on first attempt');
      console.dir(err);
      changes.retry.enabled = false;
      return process.exit(1);
    }
    
    console.log('Listening for _changes');
  });
License: MIT
Authors: Bradley Meck, Maciej Malecki, Charlie Robbins

Keywords

FAQs

Package last updated on 12 Apr 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc