Permalink
Browse files

jshintified.

  • Loading branch information...
mcollina committed Nov 18, 2013
1 parent 8f1eab9 commit ec5a1cb92cbc6886fa152430362e9dce59a96c06
View
@@ -1,7 +1,6 @@
{
"node": true,
"browser": true,
"es5": true,
"curly": true,
"eqeqeq": true,
"immed": true,
@@ -1 +1 @@
module.exports = require("readable-stream");
module.exports = require('readable-stream');
View
@@ -1,3 +1,3 @@
Leveljs = require("level-js");
var Leveljs = require("level-js");
module.exports = function(l) { return new Leveljs(l); };
View
@@ -1 +1 @@
module.exports = require("leveldown");
module.exports = require('leveldown');
View
@@ -1,15 +1,15 @@
var keyfilter = require("./keyfilterstream")
, materializer = require("./materializerstream")
, Variable = require("./variable")
, Navigator = require("./navigator")
, extend = require("xtend")
, utilities = require("./utilities")
, queryplanner = require("./queryplanner")
, PassThrough = require("./streamwrapper").PassThrough
, WriteStream = require("./writestream")
, levelup = require("levelup")
, LevelWriteStream = require("level-writestream")
var keyfilter = require('./keyfilterstream')
, materializer = require('./materializerstream')
, Variable = require('./variable')
, Navigator = require('./navigator')
, extend = require('xtend')
, utilities = require('./utilities')
, queryplanner = require('./queryplanner')
, PassThrough = require('./streamwrapper').PassThrough
, WriteStream = require('./writestream')
, levelup = require('levelup')
, levelWriteStream = require('level-writestream')
, Leveljs
, joinStream
, doAction
@@ -26,31 +26,31 @@ module.exports = function levelgraph(leveldb, options) {
var name = leveldb
, db;
if (typeof leveldb === "string") {
if (typeof leveldb === 'string') {
// we are using LevelDown on node or level-js in the Browser
if (!options.db) {
options.db = require("./getdb");
options.db = require('./getdb');
}
leveldb = levelup(name, options);
}
LevelWriteStream(leveldb);
levelWriteStream(leveldb);
db = {
getStream: function(pattern, options) {
var query = utilities.createQuery(pattern, options);
return leveldb.createReadStream(query).
pipe(keyfilter(query));
}
, get: utilities.wrapCallback("getStream")
, put: doAction("put", leveldb)
, del: doAction("del", leveldb)
, get: utilities.wrapCallback('getStream')
, put: doAction('put', leveldb)
, del: doAction('del', leveldb)
, putStream: doActionStream('put', leveldb)
, delStream: doActionStream('del', leveldb)
, close: leveldb.close.bind(leveldb)
, v: Variable
, joinStream: joinStream(leveldb, options)
, join: utilities.wrapCallback("joinStream")
, join: utilities.wrapCallback('joinStream')
, nav: function(start) {
return new Navigator({ start: start, db: this });
}
@@ -60,7 +60,7 @@ module.exports = function levelgraph(leveldb, options) {
};
joinStream = function(db, options) {
options = extend({ joinAlgorithm: "sort" }, options);
options = extend({ joinAlgorithm: 'sort' }, options);
var planner = queryplanner(db, options);
@@ -78,13 +78,14 @@ joinStream = function(db, options) {
planner(query, function(err, newquery) {
if (err) {
result.emit("error", err);
result.emit('error', err);
return;
}
var streams = newquery.map(function(triple) {
var stream = triple.stream
, index = triple.index
, index = triple.index;
delete triple.stream;
delete triple.index;
return stream({ triple: triple, db: that, index: index });
@@ -127,12 +128,12 @@ doActionStream = function(type, leveldb) {
var levelStream = leveldb.createWriteStream({ type: type });
var writeStream = new WriteStream();
writeStream.pipe(levelStream);
levelStream.on("error", function(err) {
writeStream.emit("error", err);
levelStream.on('error', function(err) {
writeStream.emit('error', err);
});
levelStream.on("close", function() {
writeStream.emit("close");
levelStream.on('close', function() {
writeStream.emit('close');
});
return writeStream;
};
}
};
View
@@ -1,7 +1,7 @@
var Variable = require("./variable")
, Transform = require("./streamwrapper").Transform
, CallbackStream = require("callback-stream")
, wrapCallback = require("./utilities").wrapCallback;
var Variable = require('./variable')
, Transform = require('./streamwrapper').Transform
, CallbackStream = require('callback-stream')
, wrapCallback = require('./utilities').wrapCallback;
function NavigatorStream(options) {
if (!(this instanceof NavigatorStream)) {
@@ -37,7 +37,7 @@ function Navigator(options) {
var count = 0;
this._nextVar = function() {
return this.db.v("x" + count++);
return this.db.v('x' + count++);
};
this.go(options.start);
@@ -60,8 +60,8 @@ function arch(varKey, lastKey) {
};
}
Navigator.prototype.archOut = arch("object", "subject");
Navigator.prototype.archIn = arch("subject", "object");
Navigator.prototype.archOut = arch('object', 'subject');
Navigator.prototype.archIn = arch('subject', 'object');
Navigator.prototype.bind = function (value) {
this._initialContext[this._lastElement.name] = value;
@@ -81,7 +81,7 @@ Navigator.prototype.go = function (vertex) {
return this;
};
Navigator.prototype.triples = wrapCallback("triplesStream");
Navigator.prototype.triples = wrapCallback('triplesStream');
Navigator.prototype.triplesStream = function (pattern) {
View
@@ -7,6 +7,14 @@ var utilities = require("./utilities")
, doSortQueryPlan
, async = require("async");
function orderedPossibleIndex(keys) {
return Object.keys(utilities.defs).filter(function(index) {
return keys.every(function(key, pos) {
return utilities.defs[index][pos] === key;
});
});
}
function queryplanner(db, options) {
return function planner(query, callback) {
// dupes!
@@ -130,14 +138,6 @@ doSortQueryPlan = function(first, second) {
second.stream = SortJoinStream;
return second;
}
function orderedPossibleIndex(keys) {
return Object.keys(utilities.defs).filter(function(index) {
return keys.every(function(key, pos) {
return utilities.defs[index][pos] === key;
});
});
}
};
module.exports = queryplanner;
View
@@ -1,14 +1,14 @@
var Transform = require("./streamwrapper").Transform
, Variable = require("./variable")
, queryMask = require("./utilities").queryMask
, variablesMask = require("./utilities").variablesMask
var Transform = require('./streamwrapper').Transform
, Variable = require('./variable')
, queryMask = require('./utilities').queryMask
, variablesMask = require('./utilities').variablesMask
, maskUpdater
, matcher
, materializer = require("./utilities").materializer
, createQuery = require("./utilities").createQuery
, genKey = require("./utilities").genKey
, genKeys = require("./utilities").genKeys;
, materializer = require('./utilities').materializer
, createQuery = require('./utilities').createQuery
, genKey = require('./utilities').genKey
, genKeys = require('./utilities').genKeys;
var counter = 0;
@@ -26,9 +26,9 @@ function SortJoinStream(options) {
this.db = options.db;
var that = this;
this.once("pipe", function(source) {
source.on("error", function(err) {
that.emit("error", err);
this.once('pipe', function(source) {
source.on('error', function(err) {
that.emit('error', err);
});
});
@@ -51,16 +51,16 @@ SortJoinStream.prototype._restart = function() {
this._readStream = this.db.getStream(this._queryMask, { index: this.index });
this._readStream.on("error", function(err) {
that.emit("error", err);
this._readStream.on('error', function(err) {
that.emit('error', err);
});
this._readStream.on("end", function() {
this._readStream.on('end', function() {
that._readStream = null;
that._execLastDone();
});
this._readStream.on("readable", function() {
this._readStream.on('readable', function() {
if (that._toNextTriple) {
that._toNextTriple();
}
@@ -134,15 +134,15 @@ SortJoinStream.prototype._transform = function(context, encoding, done) {
, key
, otherKey;
key = genKey(that.index, materializer(that.triple, context)) + "::\xff";
key = genKey(that.index, materializer(that.triple, context)) + '::\xff';
if (newContext) {
that.push(newContext);
that._nextTriple(doRead, true);
return;
}
key = genKey(that.index, materializer(that.triple, context)) + "::\xff";
key = genKey(that.index, materializer(that.triple, context)) + '::\xff';
otherKey = genKey(that.index, triple);
if (key >= otherKey) {
View
@@ -1 +1 @@
module.exports = require("stream");
module.exports = require('stream');
View
@@ -1,13 +1,13 @@
var CallbackStream = require("callback-stream")
, Variable = require("./variable")
var CallbackStream = require('callback-stream')
, Variable = require('./variable')
, defs = {
spo: ["subject", "predicate", "object"],
sop: ["subject", "object", "predicate"],
pos: ["predicate", "object", "subject"],
pso: ["predicate", "subject", "object"],
ops: ["object", "predicate", "subject"],
osp: ["object", "subject", "predicate"]
spo: ['subject', 'predicate', 'object'],
sop: ['subject', 'object', 'predicate'],
pos: ['predicate', 'object', 'subject'],
pso: ['predicate', 'subject', 'object'],
ops: ['object', 'predicate', 'subject'],
osp: ['object', 'subject', 'predicate']
};
module.exports.defs = defs;
@@ -40,10 +40,10 @@ function genKey(key, triple) {
}
if (result.length < 4) {
result.push("");
result.push('');
}
return result.join("::");
return result.join('::');
}
module.exports.genKey = genKey;
@@ -110,7 +110,7 @@ function createQuery(pattern, options) {
, key = genKey(index, pattern)
, query = {
start: key,
end: key + "\xff",
end: key + '\xff',
fillCache: true
};
@@ -149,15 +149,15 @@ module.exports.materializer = materializer;
a = function(key) {
return defs.spo.indexOf(key) >= 0;
}
};
b = function(triple, key) {
return typeof triple[key] !== "object";
}
return typeof triple[key] !== 'object';
};
c = function(triple, key) {
return triple[key] instanceof Variable;
}
};
var objectMask = function objectMask(criteria, object) {
return Object.keys(object).
View
@@ -1,9 +1,22 @@
var Transform = require("./streamwrapper").Transform;
var Transform = require('./streamwrapper').Transform;
var genKey = require('./utilities').genKey;
var genKeys = require('./utilities').genKeys;
var defs = require('./utilities').defs;
function genActions(triple) {
var json = JSON.stringify(triple)
, keys = genKeys(triple)
, i
, result = [];
for (i = 0; i < keys.length; i++) {
result.push({ key: keys[i], value: json });
}
return result;
}
function WriteStream(options) {
if (!(this instanceof WriteStream)) {
return new WriteStream(options);
@@ -31,16 +44,3 @@ WriteStream.prototype._transform = function(data, encoding, done) {
};
module.exports = WriteStream;
function genActions(triple) {
var json = JSON.stringify(triple)
, keys = genKeys(triple)
, i
, result = [];
for (i = 0; i < keys.length; i++) {
result.push({ key: keys[i], value: json });
};
return result;
}
Oops, something went wrong.

0 comments on commit ec5a1cb

Please sign in to comment.