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-patch-data

v0.3.0

Published

Store and read object patches (with metadata) in insert order

Downloads

3

Readme

level-patch-data build status

Store and read object patches (with metadata) in insert order

testling badge

Example

var concat = require('concat-stream')
var assert = require('assert')
var level = require('level-test')()
var Patch = require('level-patch-data')

var db = level('patch-test', {valueEncoding: 'json'})
var patch = Patch(db)

patch.add('doc', {a: 'a'}, {user: 'lee'}, function (err, commit) {
  patch.add('doc', {b: 'c'}, {user: 'kara'}, function (err, commit) {

    patch.readStream('doc').pipe(concat(function (body) {
      // body is
      [ { ts: '2014-06-28T06:05:53.100Z', // timestamp
          patch: { a: 'a' },
          key: 'docÿ2014-06-28T06:05:53.100Z' }, // namespaced and sorted by ts
        { user: 'lee',
          ts: '2014-06-28T06:05:53.113Z',
          patch: { b: 'c' },
          key: 'docÿ2014-06-28T06:05:53.113Z' } ]
    }))
  })
})

See tests for more examples.

Methods

var patch = Patch(db, opts)

  • db: an instance of levelup or a sublevel to store patches and data.

  • opts.separator: the string to use as a separator for key fields. default: '\xff'

  • opts.timestampField: the field to use to store the timestamp. default: ts

  • opts.keyField: the field to use to store the key. default: key

  • opts.patchField: the field to use to store the patch. default: patch

  • opts.key: the function to use to generate each patch's key. Use a custom key to add some entropy if there is a chance you'll have two commits in the same millisecond.

    // default
    opts.key = function (meta, namespace, opts) {
      return [namespace, meta[opts.timestampField]].join(opts.separator)
    }

patch.add(namespace, patch, meta, callback)

alias: addPatch

  • namespace: the string to identify this collections of patches. This module is designed for use with patcher patches for a single object per unique namespace
  • patch: the object to store as the patch
  • meta: key/value pairs to store with this patch. Note: the keys opts.timestampField, opts.keyField, and opts.patchField will be overwritten if set.
  • callback: receives two arguments, err which is only set if an error occurs and commit, which is the patch and its metadata exactly as it was saved.

patch.readStream(namespace, since)

aliases: createReadStream, read

Returns a readable stream that emits patches for namespace in insert order.

  • namespace: the collection of patches to read. patches will be streamed in the order inserted.
  • since: optional. pass the key of the commit to read commits since. The commit with key === since will not be returned, only all commits after it.

License

MIT