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

qvc

v1.1.0

Published

Handle commands and queries from the client with validation

Downloads

4

Readme

QVC

for node.js

This is an implementation of the QVC protocol for node. It supports commands and queries, and simple constraints, but not validation (yet).

Installation

Install it from npm using npm install qvc. This will install all needed dependencies

About QVC

QVC is an alternative to REST which adds validation and error handling to ajax requests. It is a protocol on top of the HTTP layer using JSON to encode data in both directions. QVC is short for Query Validation Command, describing the three parts of the protocol. A request to the server can either be a query, where the server should return a result, or a command, where the server should do some action. In both cases the client can send parameters to the server in the form of a JSON object. This JSON object is validated on the server, and the result of the validation is sent to the client in a standardized format. The protocol also provides a way to send validation constraints to the client, for client-side validation of parameters.

Usage

There are two parts to using QVC; creating a command/query handler and routing to it. The command/query handler is a function which takes a command/query as its first parameter, and calls the second parameter with the result (standard node.js callback style). For example:

var qvc = require('qvc');

module.exports = [
  qvc.query('load', function(query, done){
    console.log("load", query.name);

    loadDataAsync(function(err, result){
      //transform the result somehow
      done(err, result);
    });
  }),
  qvc.command('save', function(command, done){
    console.log("save", command.name);
    
    saveDataAsync(command.name, command.content, function(err, success){
      done(err, success);
    });
  })
];

This file contains both a command and a query handler, and can be expanded in the future with additional commands and queries. A project can consist of several files like this, with multiple handlers for both commands and queries.

A single routing file is needed for all this to work. An example is presented here:

var qvc = require('qvc');
var express = require('express');
var bodyParser = require('body-parser');

var app = express();

app.use(bodyParser.urlencoded());

app.use('/qvc', qvc(
  require('./handlers'),
  //add other handlers here...
));

app.listen(80);