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 🙏

© 2026 – Pkg Stats / Ryan Hefner

highlander

v0.0.6

Published

highlander

Downloads

12

Readme

Build Status NPM version

node-highlander

Prevalence layer for node.

Installation

npm i highlander

Designed for simplicity

node-highlander is a simple implementation of System Prevalence. As such it can be used as

  • a database (persistent, transactional)
  • a building block for simplified CQRS or Event Sourcing (since Prevalence, when not picky about theory or full set of features, can be seen a a special case where there is exactly one aggregate)

Use it if you appreciate that

  • data schema is in your code
  • performance is through the roof since all data is in main memory
  • its easily maintable/readable/hackable since all history (of data modifications) are kept in a journal
    • typically a plain text file in production
    • typically a copy of the production file in development
    • in-memory in testing scenarios

Dont use it

  • for distributed, clustered, or otherwise non-monolithic systems
  • without proper TDD
  • without a basic understanding of the Prevalence pattern

Ok, show me the code!

Setup a repository that is backed to disk with

var highlander = require('highlander');
var repo = highlander.repository({
	journal: highlander.fileJournal({path: 'data.log'}),
	model: {todos: []} 
});

Define a command (add todo):

repo.registerCommand('add todo',function (ctx, cb){ ctx.model.todos.push(ctx.args); cb(); });

Add a todo by executing a command:

repo.execute('add todo',{text: 'buy milk'}, function (err, data) {
	if (err) { 
		console.error(err); 
	}
});

List all todos:

repo.query(
	function (model, cb) { cb(null, model.todos); },
	function (err, todos) {
		if (err){
			return console.error(err);
		}
		for (var i = 0; i < todos.length; ++i){
			console.log(todos[i].text);
		}
	});

API

repository(options)

Create a new repository instance. All members of options are optional with reasonable defaults:

  • model - the application state, defaults to {}
  • commandRegistry - registered commands
  • synchronizer - reader/writer locks
  • marshaller - marshalling of data between model/repository and application
  • journal - persistent history of commands, defaults to in-memory journal.

repository.execute(name, args, callback)

Invoke asynchronously a named command with specified arguments. The callback (optional) should be have the form function (err, result) {...}.

repository.query(fn, callback)

Invoke a query asynchronously.

The query predicate (fn) should have the form function (model, cb) {...}, and is assumed to have no side effects on the model. fn must report result with a call to cb(<err>,<result>). The callback callback (optional) should be have the form function (err, result) {...}.

repository.query(
    function (model, cb) {
        var result = calculateResult(model);
        cb(null, result);
    },
    function (err, result) {
        console.log(result);
    });

repository.registerCommand(name, handler)

Register a command. Handler must be on the form

  • function (context, cb) {...}
  • {execute: function (context, cb) {...}}
  • {execute: function (context, cb) {...}, validate: function (context, cb) {...}}

Context is setup to

{
	model: <the model>,
	command: <name of invoked command>,
	args: <supplied command arguments>
}  

validators - validate(ctx,cb)

Validators are called before executors.

function (ctx, cb){
    if (argumentsAreInconsistentWithModel(ctx.args, ctx.model){
        return cb('Validation error');
    }
    cb();
}

Also, validators may throw in case of failed validation.

function (ctx, cb){
    if (argumentsAreInconsistentWithModel(ctx.args, ctx.model){
        throw 'Validation error';
    }
}

executors - execute(ctx, cb)

Executors may freely inspect the context parameter. In particular, they are assumed to modify context.model in a meaningful way.

function (ctx, cb) {
    ctx.model.gizmo = ctx.args.gizmo;
    cb(null,ctx.model.gizmo);
}

Why asynchronous when all state is in main memory anyways?

  • Execution of a command involves writing a log entry, possibily to disk or other external storage. This is in node an inherently asynchronoius operation
  • Execution of commands and queries are serialized using reader/writer locks. Thus the actual execution might be deferred due to synchronization.

To avoid nasty race conditions, results from commands and queries are marshalled (ie deep copied).

Why no snapshots?

node-highlander does not support snapshots, since

  • snapshotting a live in memory representation to Json would restrict the model to NOT contain any cycles.
  • anything related to runtime behaviour of the model (classes, prototypes etc) would be lost in a restore from snapshot.