Skip to content
Browse files

Refactor for newer npm

Change-Id: If5336f868f4e04ec69820620c22fbcb545a68297
  • Loading branch information...
1 parent 620f179 commit c5f50ab3b849004e60a27705835461ea3f5f09d5 Tim Caswell committed Jul 8, 2011
Showing with 40 additions and 45 deletions.
  1. 0 {lib/nstore → }/cache.js
  2. +6 −6 {lib → }/nstore.js
  3. +5 −9 package.json
  4. +26 −27 {lib/nstore → }/query.js
  5. +3 −3 test/helper.js
View
0 lib/nstore/cache.js → cache.js
File renamed without changes.
View
12 lib/nstore.js → nstore.js
@@ -1,10 +1,10 @@
var Path = require('path'),
- fs = require('fs'),
+ Fs = require('fs'),
Step = require('step'),
Pattern = require('pattern'),
Hash = require('pattern/hash'),
Queue = require('pattern/queue'),
- File = require('./file');
+ File = require('./lib/file');
const CHUNK_LENGTH = 40 * 1024,
TAB = 9,
@@ -53,11 +53,11 @@ var nStore = module.exports = Pattern.extend({
var counter = 0;
this.busy = true;
- fs.open(this.filename, 'a+', 0666, function (err, fd) {
+ Fs.open(this.filename, 'a+', 0666, function (err, fd) {
if (err) { callback(err); return; }
var line = [0, null, null];
function readChunk(position) {
- fs.read(fd, buffer, 0, CHUNK_LENGTH, position, function (err, bytes) {
+ Fs.read(fd, buffer, 0, CHUNK_LENGTH, position, function (err, bytes) {
if (err) throw err;
if (!bytes) {
scanned = position;
@@ -283,11 +283,11 @@ var nStore = module.exports = Pattern.extend({
// },
// function closeOld(err) {
// if (err) throw err;
- // fs.close(self.fd, this);
+ // Fs.close(self.fd, this);
// },
// function moveNew(err) {
// if (err) throw err;
- // fs.rename(tmpFile, self.filename, this);
+ // Fs.rename(tmpFile, self.filename, this);
// },
// function transitionState(err) {
// if (err) throw err;
View
14 package.json
@@ -1,22 +1,18 @@
{
"name": "nstore",
- "version": "0.3.0",
+ "version": "0.5.0",
"description": "nStore is a simple, in-process key/value database for node.js.",
- "tags": ["nosql", "database"],
+ "tags": ["nosql", "database", "pattern"],
"author": "Tim Caswell <tim@creationix.com>",
"repository": {
"type": "git",
"url": "http://github.com/creationix/nstore.git"
},
"bugs": "http://github.com/creationix/nstore/issues",
- "engines": ["node >= 0.2.0"],
- "modules": {
- "index": "lib/nstore.js",
- "cache": "lib/nstore/cache.js",
- "query": "lib/nstore/query.js"
- },
+ "engines": ["node >= 0.4.0"],
+ "main": "nstore.js",
"dependencies": {
"step": ">=0.0.3",
- "pattern": ">=0.0.2"
+ "pattern": ">=0.2.0"
}
}
View
53 lib/nstore/query.js → query.js
@@ -17,33 +17,32 @@ module.exports = function QueryPlugin() {
}
var keys = Object.keys(this.index);
var counter = keys.length;
- if(keys.length === 0) {
- process.nextTick(function() {
- if (stream) stream.emit('end');
- if (callback) callback(null, results);
- });
- } else {
- keys.forEach(function (key) {
- this.get(key, function (err, doc, key) {
- if (err) {
- if (stream) stream.emit('error', err);
- if (callback) callback(err);
- return;
- }
- if (filter(doc, key)) {
- if (stream) stream.emit('document', doc, key);
- if (callback) results[key] = doc;
- };
- counter--;
- if (counter === 0) {
- if (stream) stream.emit('end');
- if (callback) callback(null, results);
- }
- });
- }, this);
- }
+ if(keys.length === 0) {
+ process.nextTick(function() {
+ if (stream) stream.emit('end');
+ if (callback) callback(null, results);
+ });
+ } else {
+ keys.forEach(function (key) {
+ this.get(key, function (err, doc, key) {
+ if (err) {
+ if (stream) stream.emit('error', err);
+ if (callback) callback(err);
+ return;
+ }
+ if (filter(doc, key)) {
+ if (stream) stream.emit('document', doc, key);
+ if (callback) results[key] = doc;
+ };
+ counter--;
+ if (counter === 0) {
+ if (stream) stream.emit('end');
+ if (callback) callback(null, results);
+ }
+ });
+ }, this);
+ }
}
-
};
}
@@ -78,6 +77,6 @@ function compileSection(obj) {
name = "doc." + name;
}
return "(" + name + " " + operator + " " + JSON.stringify(obj[key]) + ")";
- })
+ });
return "(" + parts.join(" && ") + ")";
}
View
6 test/helper.js
@@ -1,5 +1,5 @@
Object.freeze(Object.prototype);
-require.paths.unshift('../lib');
+require.paths.unshift("../../");
global.assert = require('assert');
global.fs = require('fs');
global.Step = require('step');
@@ -25,7 +25,7 @@ function clean() {
try {
fs.unlinkSync('fixtures/new.db');
} catch (err) {
- if (err.errno !== process.ENOENT) {
+ if (err.code !== 'ENOENT') {
throw err;
}
}
@@ -35,4 +35,4 @@ function clean() {
clean();
// Clean on exit too
-// process.addListener('exit', clean);
+// process.addListener('exit', clean);

0 comments on commit c5f50ab

Please sign in to comment.
Something went wrong with that request. Please try again.