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

chrobject

v0.5.4

Published

Stores chronicles of plain objects as diffs and snapshots

Downloads

42

Readme

NPM version NPM downloads

Installation

npm install --save chrobject
// Then include in a node.js file
var chrobject = require('chrobject');

Contributing

Clone the repo, then

npm install
node_modules/typings/dist/bin.js install

and here we go. Develop your new features or fixes, test it using npm test and create a pull request.

Usage

This is a working example:

var chrobject = require('chrobject');
var mongoose = require('mongoose');

// Configure a storage strategy
 // The only included strategy is mongoose which needs a mongoose connection
mongoose.connect('mongodb://localhost/testChrobject');
var loggerConfig = {
    baseDir: '/Users/chotz/Desktop/logs',
    console: {
        logLevel: 'debug'
    },
    file: {
        logLevel: 'debug',
        executionFile: 'server.log',
        exceptionsFile: 'error.log'
    }
};
var mongooseStorage = new chrobject.MongooseStorage(loggerConfig);

// instanciate Chrobject
var entity = new chrobject.Entity('testObj', 'a.id');
var config = chrobject.Configuration.SNAP_AND_DIFF;
var creator = new chrobject.Creator('username', 'sourceapp');
var options = {
    ignoreProperties: [
        'data.ignoredProp'
    ]
};
var history = new chrobject.Chrobject(entity, config, mongooseStorage);

// save a snapshot + diff entry
history.saveEntry({ a: { id: 'adsf' }, data: { test: 'val', ignoredProp: 'asdf' } }, creator, new Date(), function (err, result) {
    console.log('error:', err);
    console.log('result:', result);
    mongoose.disconnect();
    process.exit();
});

Features

Entity

This describes the entities to be stored. The name of it is something like car if you want to save the history of car objects. The idPath is the path in the object by which this object is identified, eg. exterior.plate.number with the car example.

Configuration

You can configure the Chrobject in three ways by using the Configuration enum:

  • SNAP_ONLY: Only snapshots of the objects will be saved with a timestamp so you can get the status of the object at any time in the past.
  • DIFF_ONLY: Only diffs of the object compared to the last status before will be saved, so you can see who changed what and when did he do so.
  • SNAP_AND_DIFF: In this case both snapshots and diffs are stored, so you can see which changes were made at what time and what was the status of the object after that change. Each diff is therefore connected to a snapshot by a link id.

ChrobjectOptions

You can set some options to Chrobject:

  • ignoreProperties: String array of properties to be ignored when diff-ing Objects, eg. [ 'my.path.to.prop1', 'my.other.path' ].

Storage Strategy

You can implement your own storage strategy, which hast to implement interface chrobject/src/storage/StorageStrategy.ts.

Currently implemented Strategies:

Creator

Each time you save an entry (snap, diff or snap + diff) you can assign a creator to the change to keep track of who is changing what. The creator consists of a user and a sourceapp to clarify through which application the user made the change.