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

level-commit

v0.1.0

Published

track the change history of a leveldb instance

Downloads

3

Readme

level-commit build status

Track the change history of a leveldb instance.

testling badge

Example

var level = require('level-test')()
var concat = require('concat-stream')
var db = level('db1', {valueEncoding: 'json'})
var committer = require('level-commit')(db)

committer.commit({a: 1}, {user: 'sam'}, function(err){
  if (err) return
  // success!
})

// later
committer.history(function (err, history) {
  if (err) return
  // commits are tracked in the history
  // history = [
  //   {
  //     patch: {a: 1},
  //     user: 'sam',
  //     ts: '1914-05-16T05:44:36.155Z' // when the commit was added
  //   }
  // ]
})

db.readStream({start: 'a', end: 'a'}).pipe(concat(function(body){
  // commits alter the database contents
  // body = [
  //   {key: 'a', value: 1}
  // ]
}))

Methods

var committer = commit(db, opts={})

db is a levelup instance.

options

  • opts.depth = 0 the depth of key that should be used as a prefix for each property. This is passed to level-objectify
  • opts.separator = '\xff' the string to use to separate sections of the prefix.
  • opts.timestamp = 'ts' the key to store the timestamp on.
  • opts.prefix = 'commit' + opts.separator the string to prefix the commit document's key with. To store commits in a sublevel, prefix with '\xffpath\xff\xffto\xff\xffsublevel\xffcommit'

committer.current( fn(err, obj) )

The callback function will be passed any error and an object that is the result of combining the patches of all commits in order with .applyPatch() from patcher.

committer.commit( patch={}, meta={}, fn(err) )

patch
The patch to commit. Create one with .computePatch() from patcher.

meta
Key-value pairs to include with the commit. Use any valid object key except patch and opts.timestamp, which will be overwritten by the patch provided in the first argument and the provided setting respectively.

fn(err)
A callback function for when the commit is complete. All writes are completed in a single batch operation in leveldb. A failure here means the commit and all side-effects failed.

committer.history( fn(err, history) )

The callback function will receive any error and the commit history for this instance in the order it was committed (oldest first).

committer.batch( fn(meta, batch, callback(err, batch)) )

Pass a function that will receive the meta information about a commit and the batch of operations that are about to occur as well as a callback to invoke with any error and the batch of operations to trigger.

// this batch function splits documents into sublevels
var committer = require('level-commit')(db, {depth: 1})

// note: you must augment your db with `level-sublevel` for this to work!
committer.batch(function(meta, batch, cb){
  admin = db.sublevel(meta.ship).sublevel('pegasus.admin')
  open = db.sublevel(meta.ship).sublevel('pegasus.public')

  batch.forEach(function (op) {
    op.prefix = op.key.slice(0,1) === 'u' ? admin : open
  })

  cb(null, batch)
})

data = {
  user: {
    lee: {name: 'Lee Adama'}
  }
  gear: {
    viper1: {serial: 15513}
  }
}

committer.commit(data, {user: 'sam', ship: 'battlestar'}, function (err) {
  if (err) return

  // db.sublevel('battlestar').sublevel('pegasis.admin') now contains:
  // [{key: 'user\xfflee', value: {name: 'Lee Adama'}}]

  // db.sublevel('battlestar').sublevel('pegasis.public') now contains:
  // [{key: 'gear\xffviper1', value: {serial: 15513}}]
})

License

MIT