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

jennings

v1.3.1

Published

Jennings

Downloads

12

Readme

Jennings

wercker status

Jennings is a simple, crazy-fast NodeJS library/router/service for processing inverted queries. What is an inverted query? It's kind of like the game show Jeopardy: you're using a clue in the form of a statement to narrow down a list of answers formed as questions. It's not a perfect metaphor, but it's a good starting point. In practice, inverted queries are part of any notification system, bidding system, etc.

Jennings is designed for extremely low latency and easy clustering; the entire answers database is replicated in-memory on each node.

Query Language

Criteria are inspired by the JSON Patch spec (RFC 6902). A criterion is an object that consists of an op property which specifies which operation to use; a path property which can be either a json-pointer or (preferred) an array of path parts; and a value property which is used by the operation. The following operations are currently supported:

exists ensures that the clue contains a property at the given path; value should be set to null

match ensures that the clue contains a property at the given path, and that its value is matched by the regular expression supplied in value

eq ensures that the clue contains a property at the given path, and that its value is strictly equal to value

ne ensures that the clue lacks a property at the given path, or that its value is not strictly equal to value

lt ensures that the clue contains a property at the given path, and that its value is less than value

le ensures that the clue contains a property at the given path, and that its value is less than or loosly equal to value

gt ensures that the clue contains a property at the given path, and that its value is greater than value

ge ensures that the clue contains a property at the given path, and that its value is greater than or loosly equal to value


Example:

// Clue
{
	"category": "let's have a ball",
	"question": "sink it and you've scratched"
}

// Answer - this is one answer that might be returned in response to the above clue
{
	"id": "3dd771a1-c9d1-4c42-8057-e44ed788bf52",
	"data": {
		"response": "cue ball"
	},
	"criteria": [
		{
			"op": "eq",
			"path": ["category"],
			"value": "let's have a ball"
		},
		{
			"op": "match",
			"path": ["question"],
			"value": "scratched"
		},
		{
			"op": "match",
			"path": ["question"],
			"value": "sink"
		}
	]
}

How To Use

Jennings is written for nodejs and uses RethinkDB for persistance and synchronization. You'll need to make sure both are installed and that RethinkDB is running. You can obtain Jennings from npm: npm install jennings --save, and use it as a standalone service or embed it in your node project.

as a library

All library methods return a promise object that resolves to the noted types.

var jennings = require('js');

// insert a new answer and auto-generate ID (resolves to the new answer)
jennings.create({criteria: [{op: 'eq', path: ['foo'], 'value': 'bar'}], data: {cool: 'beans'}});

// replace/insert an answer by ID (resolves to the new answer)
jennings.save('one', {id: 'one', criteria: [{op: 'eq', path: ['foo'], 'value': 'bar'}], data: {cool: 'beans'}});

// get an answer by ID (resolves to the requested answer or null)
jennings.get('one');

// delete an answer by ID (resolves to the deleted answer)
jennings.delete('one');

// get all answers (resolves to an array of answers)
jennings.query();

// get all answers with strong consistency (resolves to an array of answers)
jennings.query(null, null, true);

// query for answers by clue (resolves to an array of answers)
jennings.query({foo: 'bar'});

// query for by criteria (resolves to an array of answers)
jennings.query(null, [{op: 'eq', path: ['id'], value: 'one'}]);

as a router

var config = require('path/to/your/config.json');
var app = require('express')();

var jennings = require('jennings');

// add the router to your express app
app.use('/prefix', jennings.router);

// (create) POST   /prefix
// (save)   POST   /prefix/:id
// (get)    GET    /prefix/:id
// (delete) DELETE /prefix/:id
// (query)  GET    /prefix
// (query)  GET    /prefix?clue={"foo": "bar"}
// (query)  GET    /prefix?criteria=[{"op": "eq", "path": ["foo"], "value": "bar"}]

as a service

In production, it's recommended to use a process manager like forever or pm2 to restart your script in the event of a crash. However, it should be noted that the Jennings server already clusters operations across all available processor cores, so little is gained by using the cluster or fork features of PM2.

# in development
node server.js

# using forever in production
forever start server.js

# using pm2 in production
pm2 start server.js -n jennings -x 1

Performance Tips

Jennings is designed to very easily scale horizontally to acommodate an extremely large number of simultaneous requests. It is designed to hold thousands of answers, but not millions. To accomidate large numbers of answers and maintain awesome response times, you'll have to scale vertically.