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

stillframe

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stillframe - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

40

lib/index.js

@@ -11,3 +11,3 @@ 'use strict';

function Stillframe(config, store, generators) {
function Stillframe(config, store, engines) {

@@ -17,3 +17,3 @@ if(!this instanceof Stillframe)

if(!store || !generators || !config)
if(!store || !engines || !config)
throw new Error('Missing required arguments.');

@@ -29,10 +29,10 @@

// attach the generators
this.generators = generators;
// attach the engines
this.engines = engines;
}
// lookup an entry in the cache manifest
Stillframe.prototype.lookup = function lookup(generator, hash, timestamp, ttl, callback) {
Stillframe.prototype.lookup = function lookup(engineId, hash, timestamp, ttl, callback) {
return this.redis.eval(
lookupScript, 1, [this.config.prefix, generator, hash].join(':'),
lookupScript, 1, [this.config.prefix, engineId, hash].join(':'),
timestamp, // current request entry

@@ -47,5 +47,5 @@ timestamp - ttl, // oldest acceptable complete entry

// resolve a pending entry in the cache manifest
Stillframe.prototype.resolve = function resolve(generator, hash, timestamp, callback) {
Stillframe.prototype.resolve = function resolve(engineId, hash, timestamp, callback) {
return this.redis.eval(
resolveScript, 1, [this.config.prefix, generator, hash].join(':'),
resolveScript, 1, [this.config.prefix, engineId, hash].join(':'),
timestamp, // current request entry

@@ -58,3 +58,3 @@ timestamp + this.config.ttl, // entry expiration

Stillframe.prototype.take = function take(generator, request, options, ttl, callback) {
Stillframe.prototype.take = function take(engineId, request, options, ttl, callback) {
var self = this;

@@ -64,5 +64,5 @@ var switchboard = new stream.PassThrough();

// make sure the generator exists
if(!self.generators[generator])
return error(new Error('The generator "' + generator + '" does not exist.'));
// make sure the engine exists
if(!self.engines[engineId])
return error(new Error('The engine "' + engineId + '" does not exist.'));

@@ -93,5 +93,6 @@ // generate the hash

// lookup hash in cache manifest
return self.lookup(generator, hash, timestamp, ttl, function(err, entry){
return self.lookup(engineId, hash, timestamp, ttl, function(err, entry){
if(err) return error(err);
var engine = self.engines[engineId];

@@ -111,3 +112,3 @@

else if(entry[0] === 'complete')
self.store.fetch(generator, hash, parseInt(entry[1])).pipe(switchboard);
self.store.fetch(engineId, engine, hash, parseInt(entry[1])).pipe(switchboard);

@@ -125,6 +126,6 @@ // cache is pending; wait and try again...

var readStream = self.generators[generator].run(request, options);
var writeStream = self.store.save(generator, hash, timestamp, ttl);
var readStream = engine.run(request, options);
var writeStream = self.store.save(engineId, engine, hash, timestamp, ttl);
// read from generator
// read from engineId
readStream

@@ -144,5 +145,8 @@ .on('error', function(e){

// TODO: write any progress to redis
.on('progress', function(e){})
// resolve the cache manifest entry
.on('finish', function(){
if(!err) self.resolve(generator, hash, timestamp, function(err){
if(!err) self.resolve(engineId, hash, timestamp, function(err){
if(err) switchboard.emit('error', err);

@@ -149,0 +153,0 @@ });

{
"name": "stillframe",
"version": "0.0.2",
"version": "0.0.3",
"description": "A simple distributed url-to-whatever framework.",

@@ -20,3 +20,4 @@ "main": "./lib/index.js",

"istanbul": "^0.3.20",
"mocha": "^2.2.4"
"mocha": "^2.2.4",
"stillframe-store-file": "^1.0.0"
},

@@ -23,0 +24,0 @@ "dependencies": {

@@ -8,3 +8,3 @@ [![Build Status](https://travis-ci.org/the-control-group/stillframe.svg?branch=master)](https://travis-ci.org/the-control-group/stillframe)

Pluggable **generators** build stillframes from request objects, and pluggable **stores** persist the results.
Pluggable **engines** build stillframes from request objects, and pluggable **stores** persist the results.

@@ -11,0 +11,0 @@

@@ -5,2 +5,33 @@ 'use strict';

var stream = require('stream');
function EchoEngine(config) {
this.config = config || {};
};
// run the generator
// @return instance of stream.Readable
EchoEngine.prototype.run = function run(request, options) {
var s = new stream.PassThrough();
s.metadata = {
type: 'application/json',
extension: 'json'
};
// DIRTY: this timeout exists for testing purposes
setTimeout(function(){
s.end(JSON.stringify(request));
}, 50);
return s;
};
var config = require('../config.test.js');

@@ -11,4 +42,3 @@ var Stillframe = require('../lib/index.js');

var FileStore = require('../lib/stores/file.js');
var EchoGenerator = require('../lib/generators/echo.js');
var FileStore = require('stillframe-store-file');

@@ -25,3 +55,3 @@ var tmp = __dirname + '/../tmp';

timestamp = Date.now();
stillframe = new Stillframe(config, new FileStore({path: tmp}), {echo: new EchoGenerator()});
stillframe = new Stillframe(config, new FileStore({path: tmp}), {echo: new EchoEngine()});
});

@@ -114,3 +144,3 @@

ttl = 1000*60*60;
stillframe = new Stillframe(config, new FileStore({path: tmp}), {echo: new EchoGenerator()});
stillframe = new Stillframe(config, new FileStore({path: tmp}), {echo: new EchoEngine()});
});

@@ -367,7 +397,7 @@

ttl = 1000*60*60;
stillframe = new Stillframe(config, new FileStore({path: tmp}), {echo: new EchoGenerator()});
stillframe = new Stillframe(config, new FileStore({path: tmp}), {echo: new EchoEngine()});
});
describe('(callback)', function(done){
it('returns an error for a nonexistant generator', function(done){
it('returns an error for a nonexistant engine', function(done){
stillframe.take('nonexistant', {url: 'http://www.example.com/callback'}, {}, ttl, function(err, snapshot){

@@ -396,3 +426,3 @@ assert.instanceOf(err, Error);

it('should return an existing pending snapshot', function(done){
// DIRTY: the echo generator has a 5ms timeout
// DIRTY: the echo engine has a 5ms timeout
stillframe.take('echo', {url: 'http://www.example.com/callback'}, {}, ttl, function(err, snapshot){

@@ -406,3 +436,3 @@ assert.isNull(err);

it('should return an complete snapshot', function(done){
// DIRTY: the echo generator has a 5ms timeout
// DIRTY: the echo engine has a 5ms timeout
setTimeout(function(){

@@ -420,3 +450,3 @@ stillframe.take('echo', {url: 'http://www.example.com/callback'}, {}, ttl, function(err, snapshot){

describe('(stream)', function(done){
it('emits an error for a nonexistant generator', function(done){
it('emits an error for a nonexistant engine', function(done){
stillframe.take('nonexistant', {url: 'http://www.example.com/stream'}, {}, ttl)

@@ -423,0 +453,0 @@ .on('error', function(err){

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