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

kappa-view

v3.1.0

Published

make views over kappa-core with leveldb

Downloads

155

Readme

kappa-view

Base for creating kappa-core views over LevelDB.

Materialized Views

A materialized view does two things:

  1. A map function, that maps a list of log entries to modifications to a view. In this case, a LevelDB database.
  2. An api object, which are functions and variables that the view exposes in order to retrieve data from the LevelDB that map writes to.

This module handles view lifecycle logic for you: normally a kappa view needs to manage storing and fetching the state of the indexer ("up to what log sequence numbers have I processed?"), as well as purging the view's LevelDB database when the version of the view gets bumped.

Example

This is a view for a very simple single-value key-value store, that maps log entries like { key: 'foo', value: 'bar' } to an API that allows get(key) queries.

var kappa = require('kappa-core')
var makeView = require('kappa-view')
var ram = require('random-access-memory')
var memdb = require('memdb')

var core = kappa(ram, { valueEncoding: 'json' })
var lvl = memdb()

var view = makeView(lvl, function (db) {
  return {
    map: function (entries, next) {
      var batch = entries.map(function (entry) {
        return {
          type: 'put',
          key: entry.value.key,
          value: entry.value.value
        }
      })
      db.batch(batch, next)
    },
    
    api: {
      get: function (core, key, cb) {
        core.ready(function () {
          db.get(key, cb)
        })
      }
    }
  }
})

core.use('kv', view)

core.writer(function (err, log) {
  log.append({key: 'foo', value: 'bar'})
  log.append({key: 'bax', value: 'baz'})

  core.api.kv.get('foo', console.log)
  core.api.kv.get('bax', console.log)
  core.api.kv.get('nix', console.log)
})

outputs

null 'bar'
null 'baz'
NotFoundError: Key not found in database [nix]

API

var makeView = require('kappa-view')

var view = makeView(level, setupFunction)

Create a new view, backed by LevelDB.

Expects a LevelUP or LevelDOWN instance level.

setupFunction is a function that is given parameters db (LevelDB instance) and core (kappa-core instance). It is called exactly once. A kappa view must be returned, which is an object with the keys

  • map: function (entries, next): receives an array of log entries. Once you've persisted whatever changes you'd like to db, call next() to signal the view is ready for the next batch of log entries.
  • api: {}: an object that defines API functions that the view exposes. These can have whatever names you want, be sync or async, and return whatever you'd like.

Install

With npm installed, run

$ npm install kappa-view

License

ISC