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

digger-supplier

v0.1.10

Published

A database warehouse for digger.io.

Downloads

19

Readme

digger-supplier

A functional approach to REST api's.

A digger supplier is just a function - it accepts req and reply arguments.

req is a plain javascript object representing a HTTP request:

// a request represent a load of item 1234
{
	method:'get',
	url:'/1234',
	headers:{

	},
	body:null
}

reply is a standard node.js callback.

installation

$ npm install digger-supplier --save

usage

A supplier has 4 distinct roles to play.

  • select
  • append
  • save
  • remove

These are conceptually mapped onto the REST methods: GET, POST, PUT, DELETE

A supplier is a digger-warehouse - which means you can mount middleware onto a supplier like any other warehouse.

var Supplier = require('digger-supplier');
var supplier = Supplier();

// mount a custom middleware onto the supplier
// this is called before the database methods
supplier.use(function(req, res, next){
	
})

The point of a supplier is to connect to a data source on the back and interpret our container queries upon that data.

routing

It is useful to have the same supplier object deal with different backend resources (like files or databases) based upon the route that is used.

Imagine we have a supplier mounted on '/csv' - it is a csv file supplier that has access to a directory '/tmp/mycsvsupplier'.

var folder = '/tmp/mycsvsupplier';
var Supplier = require('digger-supplier');

// we create the supplier with an factory function
var supplier = Supplier(function(ready){
	
	/*
	
		connect to a database or prepare a filesystem or prepare API client etc
		
	*/
	ready();
})

// we run the provision function for every request - it decides what specific database table/collection/file to use
// based upon the route
//
// it is basically a renamed .use
supplier.provision(function(route, ready){
	
	
})

Database Methods

You specify what happens in your supplier when a container is:

  • searched for (select)
  • added (append)
  • updated (save)
  • deleted (remove)
var Supplier = require('digger-supplier');
var supplier = Supplier();

/*

	search the database with a selector and context array
	
*/
supplier.on('select', function(select_query, reply){
	
	/*
	
		a parsed selector string

		{
			tag:'product',
			class:["onsale"],
			attr:[{
				name:"price",
				operator:"<=",
				value:100
			}],
			modifier:{
				tree:true,
				sort:"name",
				limit:"6,10"
			}
		}
		
	*/
	var selector = select_query.selector;

	/*
	
		an array of skeletons from the previous step
		this is the context (i.e. to search within)


		[{
			_digger:{
				id:123
			}
		},{
			_digger:{
				id:456
			}
		}]
		
	*/
	var context = select_query.context;
})

/*

	add an item to the database
	
*/
supplier.on('append', function(append_query, reply){
	/*
	
		a skeleton of the container we are posting to

		{
			_digger:{
				id:123
			}
		}
		
	*/
	var target = append_query.target;

	/*
	
		an array of container data to add to the target

		[{
			name:"test1",
			_digger:{
				tag:"thing",
				id:"hello"
			}
		},{
			name:"test2",
			_digger:{
				tag:"otherthing",
				id:"goodbye"
			}
		}]
		
	*/
	var append_data = append_query.data;
})

supplier.on('save', function(save_query, reply){
	/*
	
		a skeleton of the container we are saving

		{
			_digger:{
				id:123
			}
		}
		
	*/
	var target = save_query.target;

	/*
	
		the update for the container

		{
			this:"that"
		}
		
	*/
	var save_data = save_query.data;
})

supplier.on('remove', function(remove_query, reply){
	/*
	
		a skeleton of the container we are removing

		{
			_digger:{
				id:123
			}
		}
		
	*/
	var target = remove_query.target;
})