New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gear

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gear - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

lib/blob.js

4

index.js

@@ -36,2 +36,4 @@ /*

}
});
});
exports.Blob = require('./lib/blob').Blob;

@@ -7,3 +7,4 @@ /*

var async = require('async'),
Gearbox = require('./gearbox').Gearbox;
Gearbox = require('./gearbox').Gearbox,
Blob = require('./blob').Blob;

@@ -33,7 +34,7 @@ /*

Queue.prototype._dispatch = function(name, options, messages, done) {
Queue.prototype._dispatch = function(name, options, blobs, done) {
var task = this._gearbox.task(name);
// Deep freeze messages
messages.forEach(function(o) {
// Deep freeze blobs
blobs.forEach(function(o) {
Object.freeze(o);

@@ -47,5 +48,5 @@ for (var prop in o) {

// task type determines how messages are processed
// Task type determines how blobs are processed
switch (task.type) {
case 'append': // add messages to queue
case 'append': // Add blobs to queue
if (options === undefined) {

@@ -60,12 +61,12 @@ options = [];

async.map(options, task.bind(this), function(err, results) {
done(err, messages.concat(results));
done(err, blobs.concat(results));
});
break;
case 'iterate': // task can look at all messages at once
task.call(this, options, messages, done);
case 'iterate': // Task can look at all blobs at once
task.call(this, options, blobs, done);
break;
case 'reduce': // reduce messages operating on a per task basis
async.reduce(messages, {meta: {}, body: ''}, task.bind(this, options), function(err, results) {
case 'reduce': // Reduce blobs operating on a per task basis
async.reduce(blobs, new Blob(), task.bind(this, options), function(err, results) {
done(err, [results]);

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

case 'slice': // select up to options.length messages
async.map(messages.slice(0, Array.isArray(options) ? options.length : 1), task.bind(this, options), done);
case 'slice': // Select up to options.length blobs
async.map(blobs.slice(0, Array.isArray(options) ? options.length : 1), task.bind(this, options), done);
break;
default: // transform message on a per task basis
async.map(messages, task.bind(this, options), done);
default: // Transform blob on a per task basis
async.map(blobs, task.bind(this, options), done);
break;

@@ -83,0 +84,0 @@ }

@@ -6,20 +6,15 @@ /*

*/
/**
* Concatenates messages.
* Concatenates blobs.
*
* @param options {Object} Concat options.
* @param options.callback {Function} Callback on each message.
* @param messages {Array} Incoming messages.
* @param options.callback {Function} Callback on each blob.
* @param blobs {Array} Incoming blobs.
* @param done {Function} Callback on task completion.
*/
var concat = exports.concat = function concat(options, prev, message, done) {
var concat = exports.concat = function concat(options, prev, blob, done) {
options = options || {};
var callback = options.callback || function(message) {
return message.body;
};
done(null, {
body: prev.body + callback(message)
});
done(null, blob.create([prev, options.callback ? options.callback(blob) : blob]));
};
concat.type = 'reduce';

@@ -7,10 +7,10 @@ /*

/**
* Gets a message.
* Gets a blob.
*
* @param index {Integer} Index of messages.
* @param messages {Array} Incoming messages.
* @param index {Integer} Index of blobs.
* @param blobs {Array} Incoming blobs.
* @param done {Function} Callback on task completion.
*/
var get = exports.get = function get(index, messages, done) {
done(null, messages.slice(index, index + 1));
var get = exports.get = function get(index, blobs, done) {
done(null, blobs.slice(index, index + 1));
};

@@ -23,8 +23,8 @@ get.type = 'iterate';

* @param string {String} String to log.
* @param message {Array} Incoming messages.
* @param blob {Array} Incoming blobs.
* @param done {Function} Callback on task completion.
*/
var log = exports.log = function log(string, messages, done) {
var log = exports.log = function log(string, blobs, done) {
this._log(string);
done(null, messages);
done(null, blobs);
};

@@ -34,18 +34,18 @@ log.type = 'iterate';

/**
* Inspects messages.
* Inspects blobs.
*
* @param options {Object} Ignored.
* @param message {Object} Incoming messages.
* @param blob {Object} Incoming blobs.
* @param done {Function} Callback on task completion.
*/
var inspect = exports.inspect = function inspect(options, messages, done) {
var inspect = exports.inspect = function inspect(options, blobs, done) {
var self = this;
this._log('INSPECT: ' + messages.length + (messages.length > 1 ? ' messages' : ' message'));
this._log('INSPECT: ' + blobs.length + (blobs.length > 1 ? ' blobs' : ' blob'));
messages.forEach(function(message, index) {
self._log(message);
blobs.forEach(function(blob, index) {
self._log(blob);
});
done(null, messages);
done(null, blobs);
};
inspect.type = 'iterate';

@@ -6,6 +6,7 @@ /*

*/
var fs = require('fs');
var fs = require('fs'),
Blob = require('../blob').Blob;
/**
* Loads message from different sources.
* Loads blobs from different sources.
* TODO: Add more sources i.e. (url).

@@ -22,8 +23,3 @@ *

fs.readFile(options.file, function(err, data) {
done(err, {
meta: {
name: options.file
},
body: data
});
done(err, new Blob([data], {name: options.file}));
});

@@ -30,0 +26,0 @@ }

@@ -12,6 +12,6 @@ /*

* @param workflow {String} TODO.
* @param message {Object} Incoming message.
* @param blob {Object} Incoming blob.
* @param done {Function} Callback on task completion.
*/
var tasks = exports.tasks = function tasks(workflow, messages, done) {
var tasks = exports.tasks = function tasks(workflow, blobs, done) {
var item,

@@ -25,11 +25,11 @@ requires,

return function(callback, result) {
var new_messages = requires.length ? [] : messages;
var new_blobs = requires.length ? [] : blobs;
result = result || [];
// Concat dependency messages in order of requires array
// Concat dependency blobs in order of requires array
requires.forEach(function(item) {
new_messages = new_messages.concat(result[item]);
new_blobs = new_blobs.concat(result[item]);
});
self._dispatch(name, options, new_messages, callback);
self._dispatch(name, options, new_blobs, callback);
};

@@ -36,0 +36,0 @@ }

@@ -12,10 +12,10 @@ /*

/**
* Write the message to disk with an optional checksum in the filename.
* Write the blob to disk with an optional checksum in the filename.
*
* @param options {Object} Write options or filename.
* @param options.file {String} Filename to write.
* @param message {Object} Incoming message.
* @param blob {Object} Incoming blob.
* @param done {Function} Callback on task completion.
*/
var write = exports.write = function write(options, message, done) {
var write = exports.write = function write(options, blob, done) {
options = (typeof options === 'string') ? {file: options} : options;

@@ -26,10 +26,5 @@

function writeFile(name, message) {
fs.writeFile(name, message.body, function(err) {
done(err, {
meta: {
name: name
},
body: message.body
});
function writeFile(name, b) {
fs.writeFile(name, blob.toString(), function(err) {
done(err, blob.create([blob], {name: name}));
});

@@ -40,3 +35,3 @@ }

checksum = Crypto.createHash('md5');
checksum.update(message.body);
checksum.update(blob.toString());
options.file = options.file.replace('{checksum}', checksum.digest('hex'));

@@ -51,3 +46,3 @@ }

} else {
writeFile(options.file, message);
writeFile(options.file, blob);
}

@@ -57,3 +52,3 @@ });

else {
writeFile(options.file, message);
writeFile(options.file, blob);
}

@@ -60,0 +55,0 @@ });

{
"name": "gear",
"version": "0.2.1",
"version": "0.3.0",
"description": "Gear.js - Task-based build system.",

@@ -5,0 +5,0 @@ "author": "Stephen Murphy <stephen@hypernaut.com>",

@@ -9,3 +9,3 @@ # Gear.js

* Basic building blocks that can be combined to perform complex builds.
* Tasks simply transform input to output without relying on system internals.
* Tasks are simply defined and keep system internals to a minimum.
* Asynchronous execution.

@@ -19,6 +19,6 @@ * Extensible task loading via NPM, file, or directory.

```bash
$ npm install gear
$ npm install gear-lib
```
npm install gear
npm install gear-lib
```

@@ -29,3 +29,3 @@ ## Quick Examples

```
```javascript
gear.queue()

@@ -41,3 +41,3 @@ .load('foo.js')

```
```javascript
gear.queue()

@@ -53,3 +53,3 @@ .load(['foo.js', {file: 'bar.js'}, 'baz.js'])

```
```javascript
gear.queue()

@@ -104,3 +104,3 @@ .load('foo.js')

```
```javascript
gear.queue()

@@ -124,3 +124,3 @@ .log('test')

```
```javascript
gear.queue()

@@ -144,3 +144,3 @@ .task('log', 'Hello, world!')

```
```javascript
gear.queue()

@@ -164,3 +164,3 @@ .log('test')

```
```javascript
gear.gearbox();

@@ -184,3 +184,3 @@ ```

```
```javascript
gear.gearbox().load({dirname: 'foo'});

@@ -197,3 +197,3 @@ ```

Loads messages from different sources.
Loads blobs from different sources.

@@ -206,3 +206,3 @@ __Arguments__

```
```javascript
// source - Filename or object to load.

@@ -221,9 +221,9 @@ // source.file - Filename of resource.

* options.file - File to write, will replace {checksum} with hash of message body.
* options.file - File to write, will replace {checksum} with hash of blob content.
Write the message to disk.
Write the blob to disk.
__Example__
```
```javascript
.write({file: 'foo'})

@@ -237,7 +237,7 @@ ```

Concatenates messages.
Concatenates blobs.
__Example__
```
```javascript
.concat()

@@ -251,7 +251,7 @@ ```

Inspects a message.
Inspects blobs.
__Example__
```
```javascript
.inspect()

@@ -273,3 +273,3 @@ ```

```
```javascript
.log('Finished')

@@ -291,3 +291,3 @@ ```

```
```javascript
// label - Task instance name.

@@ -314,5 +314,5 @@ // label.task - Task name.

```bash
$ npm install gear-lib
```
npm install gear-lib
```

@@ -322,3 +322,3 @@ <a name="Custom" />

Writing a task is especially easy compared to other Node build systems. There is no need to use Gear.js internals within a task. Tasks operate on immutable messages. Messages have a body property. The task returns transformed data via its callback.
Writing a task is especially easy compared to other Node build systems. There is no need to use Gear.js internals within a task. Tasks operate on immutable blobs. Blobs have a body property. The task returns transformed data via its callback.

@@ -328,4 +328,4 @@ __Arguments__

* options - Options for the task.
* messages - Immutable list of messages created by other tasks. Messages must each have a body property.
* done(err, results) - Callback executed when task is complete.
* blob - Immutable blob.
* done(err, result) - Callback executed when task is complete.

@@ -335,4 +335,4 @@ __Example__

// example.js
// Example task replaces each message body with a string.
exports.example = function(string, message, done) {
// Example task replaces each blob with a string.
exports.example = function(string, blob, done) {
done(null, {body: string});

@@ -344,3 +344,3 @@ };

```
```javascript
gear.queue({gearbox: gear.gearbox({filename: 'example.js'})})

@@ -361,2 +361,1 @@ .example('EXAMPLE')

* [grunt](/cowboy/grunt) created by [cowboy](/cowboy).
* [Thread Building Blocks](http://threadingbuildingblocks.org/) by Intel.
var should = require('should'),
Blob = require('../lib/blob').Blob,
concat = require('../lib/tasks/concat').concat,
fixtures = {
prev: {body: 'abc'},
cur: {body: 'def'}
prev: new Blob(['abc']),
cur: new Blob(['def'])
};
describe('concat()', function() {
it('should concat messages', function(done) {
concat(null, fixtures.prev, fixtures.cur, function(err, message) {
message.body.should.equal('abcdef');
it('should concat blobs', function(done) {
concat(null, fixtures.prev, fixtures.cur, function(err, blob) {
blob.toString().should.equal('abcdef');
done(err);

@@ -13,0 +14,0 @@ });

@@ -11,3 +11,3 @@ var should = require('should'),

it('should handle filenames instead of objects', function(done) {
load(fixtures.filename, function(err, message) {
load(fixtures.filename, function(err, blob) {
done(err);

@@ -18,3 +18,3 @@ });

it('should read files', function(done) {
load(fixtures.file, function(err, message) {
load(fixtures.file, function(err, blob) {
done(err);

@@ -25,3 +25,3 @@ });

it('should handle missing files', function(done) {
load(fixtures.missing_file, function(err, message) {
load(fixtures.missing_file, function(err, blob) {
should.exist(err);

@@ -28,0 +28,0 @@ done();

var path = require('path'),
fs = require('fs'),
Blob = require('../lib/blob').Blob,
write = require('../lib/tasks/write').write,

@@ -9,3 +10,3 @@ fixtures = {

checksum_replaced: 'testing/write_900150983cd24fb0d6963f7d28e17f72.txt',
message: {body: 'abc'}
blob: new Blob(['abc'])
};

@@ -22,3 +23,3 @@

remove(fixtures.filename);
write(fixtures.filename, fixtures.message, function(err, message) {
write(fixtures.filename, fixtures.blob, function(err, blob) {
path.existsSync(fixtures.filename).should.equal(true);

@@ -31,3 +32,3 @@ done(err);

remove(fixtures.filename);
write({file: fixtures.filename2}, fixtures.message, function(err, message) {
write({file: fixtures.filename2}, fixtures.blob, function(err, blob) {
path.existsSync(fixtures.filename2).should.equal(true);

@@ -40,3 +41,3 @@ done(err);

remove(fixtures.checksum_replaced);
write({file: fixtures.checksum}, fixtures.message, function(err, message) {
write({file: fixtures.checksum}, fixtures.blob, function(err, blob) {
path.existsSync(fixtures.checksum_replaced).should.equal(true);

@@ -43,0 +44,0 @@ done(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