Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-batching

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-batching - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

21

dist/index.js
'use strict';
var chalk = require('chalk');
// const chalk = require('chalk');

@@ -28,7 +28,7 @@ var mapRouteToString = function mapRouteToString(req) {

var key = url + '|' + hashFunc(req);
console.log(chalk.bold(chalk.green('Hash Key:', key)));
// console.log(chalk.bold(chalk.green('Hash Key:', key)));
var cached = cache[key];
if (cached) {
console.log('Resolving from cache!');
// console.log('Resolving from cache!');
return process.nextTick(function () {

@@ -40,7 +40,7 @@ return res.send(cached);

if (queues[key]) {
console.log(chalk.yellow('queueing a request into ' + key));
// console.log(chalk.yellow(`queueing a request into ${key}`));
return queues[key].push(res);
}
console.log('creating a queue', key);
// console.log('creating a queue', key);
queues[key] = [res];

@@ -55,3 +55,3 @@

status: function status(num) {
console.log('res.status called with ' + num + '. Applying to queue...');
// console.log(`res.status called with ${num}. Applying to queue...`);
applyToQueue(key, function (responseObj) {

@@ -62,7 +62,7 @@ responseObj.status(num);

send: function send(result) {
console.log('Resolving Das Queue! and caching!');
console.log(chalk.yellow('Caching ' + key));
// console.log('Resolving Das Queue! and caching!');
// console.log(chalk.yellow(`Caching ${key}`));
cache[key] = result;
setTimeout(function () {
console.log(chalk.yellow('Clearing cache for ' + key + '...'));
// console.log(chalk.yellow(`Clearing cache for ${key}...`));
delete cache[key];

@@ -72,4 +72,3 @@ }, 5 * 1000); // 30 seconds

queue.forEach(function (responseObj) {
console.log('Resolving from queue!');
// responseObj.status(200);
// console.log('Resolving from queue!');
responseObj.send(result);

@@ -76,0 +75,0 @@ });

@@ -66,3 +66,3 @@

request.get('http://localhost:3000/foo').end(function (err, res) {
console.log('APi Returning: ', res.body);
// console.log('APi Returning: ', res.body);
expect(res.body.name).toBe('foo');

@@ -76,3 +76,3 @@ done();

request.get('http://localhost:3000/baz').end(function (err, res) {
console.log('APi Returning: ', res.body);
// console.log('APi Returning: ', res.body);
expect(mock.noop.calledOnce).toBe(true);

@@ -87,5 +87,5 @@ expect(res.body.name).toBe('baz');

var createReq = function createReq(num) {
console.log('Req #' + num + ' created.');
// console.log(`Req #${num} created.`);
request.get('http://localhost:3000/baz').end(function (err, res) {
console.log('Req #' + num + ' returned.', res.body);
// console.log(`Req #${num} returned.`, res.body);
expect(res.status).toEqual(203);

@@ -101,7 +101,7 @@ expect(res.body.name).toBe('baz');

request.get('http://localhost:3000/baz').end(function (err, res) {
console.log('Api Returning: ', res.body);
// console.log('Api Returning: ', res.body);
// expect(mock.noop.calledOnce).toBe(true);
expect(res.body.name).toBe('baz');
request.get('http://localhost:3000/baz').end(function (err, res) {
console.log('Cache Return: ', res.body);
// console.log('Cache Return: ', res.body);
expect(mock.noop.calledOnce).toBe(true);

@@ -118,3 +118,3 @@ expect(res.body.name).toBe('baz');

request.post('http://localhost:3000/barry/foo').end(function (err, res) {
console.log('Api Returning: ', res.body);
// console.log('Api Returning: ', res.body);
expect(mock.noop.calledOnce).toBe(true);

@@ -121,0 +121,0 @@ expect(res.body.name).toBe('barry');

{
"name": "express-batching",
"version": "0.0.1",
"version": "0.0.2",
"description": "A small higher order component for in-process batching and caching of API requests",

@@ -5,0 +5,0 @@ "homepage": "",

@@ -1,2 +0,2 @@

# express-batching [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status](https://coveralls.io/repos/github/blugavere/express-batching/badge.svg?branch=master)](https://coveralls.io/github/blugavere/express-batching?branch=master)[![NPM Downloads](https://img.shields.io/npm/dm/repositories.svg?style=flat)](https://www.npmjs.com/package/express-batching)
# express-batching [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status](https://coveralls.io/repos/github/blugavere/express-batching/badge.svg?branch=master)](https://coveralls.io/github/blugavere/express-batching?branch=master)[![NPM Downloads](https://img.shields.io/npm/dm/express-batching.svg?style=flat)](https://www.npmjs.com/package/express-batching)

@@ -3,0 +3,0 @@ > A small higher order component for in-process batching and caching of API requests

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc