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

monoxide-versioning

v0.0.0

Published

Versioning middleware for Monoxide GET requests

Downloads

2

Readme

Monoxide-Versioning

Versioning caching layer for the Monoxide ReST server.

This module is intended as a rapid-polling via ReST system where a serve record can be either the same version as before or mismatched. In the former case this module returns only a truncated version of the record (containing only _id + __v) rather than the whole record.

This module operates as a middleware layer which performs two actions:

  • Checks if an incoming request contains a version string (by default ?__v=<SOMETHING>). If it does it only returns a new version of the document if the version requested is older than the server one.
  • Inserts itself as a late-call middleware layer item which updates its own cache.
var app = express();
var port = 8181;
app.use(expressLogger);
app.use(bodyParser.json());
app.set('log.indent', '      ');

// Add middleware as an express chain
app.get('/api/users/:id', monoxideVersioning(), monoxide.express.get('users'));

Any request to /api/users/1234 can take an optional __v query parameter. If this matches a truncated version of the document is returned (containing only _id + __v). If the version mismatches the entire document is returned.

API

This module exposes a single function-factory which is designed to slot into the ExpressJS middleware chain. It accepts the following options:

| Option | Type | Description | |---------------------|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | idField | function | Function used to obtain the ID from the express req object. This defaults to using req.params.id | | versionField | function | Function used to obtain the requested version from the express req object. This defaults to using req.query.__v | assumeVersion | number | What value to assume when no version is explicitly passed. Set this to undefined to always return the full payload | hasher | function | Function that should return a string hash of what we need to hash against. This is usually the query + params of req | hashGet | function | Hash getting function to be called as (hash, cb). Defaults to the internal in-memory storage | hashSet | function | Hash setting function to be called as (hash, expire, cb). Defaults to the internal in-memory storage | hashRemove | function | Hash removal function to be called as (hash, cb). Defaults to the internal in-memory storage | hashClean | function | Hash cleaning function to be called as (cb). Defaults to the internal in-memory storage | hashExpire | number | The time in milliseconds a hash should expire. Defaults to 1 hour | versionedResponse | function | Function which should respond to Express if a hashed version is detected | model | string or function | The name of the current model to query against in options.invalidates. If this is a function it is run ONCE when the factory is invoked and its response used in all future calls. Defaults to a function which tries to match the model against /api/<MODEL>/:id | invalidates | function | Function which should determine if an incoming request invalidates the cache. Called as (req, res, id, version, cb). Defaults to pulling the record by its ID and checking its version if options.model is specified, otherwise uses req.method != 'GET'