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

snapshot-reduce

v3.0.1

Published

Incrementally reduce an event-log into a snapshot view of those events

Downloads

27

Readme

snapshot-reduce

build status dependency status

Incrementally reduce an event-log into a snapshot view of those events

The idea is that you store all your raw data as a massive log of append only events, i.e. you never update or delete anything.

Then you use snapshot-reduce to reduce the event log into a coherent snapshot of a subset of current state.

Example

Snapshot reduce allows you to accumulate a subset of a event log into a snapshot representation of that data. The actual mapReduce is based on mongoDB and is incremental.

var snapshotReduce = require("snapshot-reduce")
var passback = require("callback-reduce/passback")

// Get a mongoDB instance however you want
var db = someMongoDb
var inputCollection = db.collection("event-log")
var outputCollection = db.collection("snapshot.my-thing")

var command = snapshotReduce("my-thing", {
    inputCollection: inputCollection
    , outputCollection: outputCollection
})

passback(command, function (err, res) {

})

For this to work you must adhere to some constraints of the event-log input. For example if your input is:

{
    "eventType" : "add"
    , "value" : {
        "title" : "some room"
        , "type" : "colingo-room"
        , "id" : "1"
        , "timestamp" : 1360877429848
    }
}

This is a message that says "a room was added". You may have another message like

{
    "eventType" : "add"
    , "value" : {
        "name" : "Jake"
        , "message" : "test"
        , "type" : "colingo-room~messages"
        , "parentId" : [ "1" ]
        , "id" : "3dedc0cc-917b-48ed-a3c9-6166011fb458"
        , "timestamp" : 1360878425642
    }
}

Which says a message was added to a room. The room it was added to was the room with id "1"

All inputs should have inline type, id and timestamp fields. The type is used to query a subset of the event-log to map reduce. The timestamp field is used to support incremental map reduce, i.e. it will only reduce values that have a timestamp higher then the last one from last time.

The two events above would be reduced to

{
    title: "some room"
    , id: "1"
    , type: "colingo-room"
    , timestamp: 1360877429848
    , messages: [{
        name: "Jake"
        , message: "test"
        , id: "3dedc0cc-917b-48ed-a3c9-6166011fb458"
        , timestamp: 1360878425642
        , type: "colingo-room~messages"
        , parentId: ["1"]
    }]
    , __lastTimestamp__: 1360878425642
}

The __lastTimestamp__ field is used to do an incremental map reduce and basically allows snapshot-reduce to reduce the entire history of the event log again.

Installation

npm install snapshot-reduce

Contributors

  • Raynos

MIT Licenced