simple-json-db
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -39,3 +39,3 @@ 'use strict'; | ||
if (!filePath || !filePath.length) { | ||
throw new Error('Missing filePath argument.'); | ||
throw new Error('Missing file path argument.'); | ||
} else { | ||
@@ -66,5 +66,7 @@ this.filePath = filePath; | ||
return; | ||
} else if (err.code === 'EACCES') { | ||
throw new Error('Cannot access path "' + filePath + '".'); | ||
} else { | ||
// Other error | ||
throw err; // TODO: Check perm | ||
throw new Error('Error while checking for existence of path "' + filePath + '": ' + err); | ||
} | ||
@@ -76,3 +78,3 @@ } | ||
} catch (err) { | ||
throw new Error('Cannot read & write on path "' + filePath + '"'); | ||
throw new Error('Cannot read & write on path "' + filePath + '". Check permissions!'); | ||
} | ||
@@ -153,3 +155,7 @@ if (stats.size > 0) { | ||
} catch (err) { | ||
throw err; // TODO: Do something meaningful | ||
if (err.code === 'EACCES') { | ||
throw new Error('Cannot access path "' + this.filePath + '".'); | ||
} else { | ||
throw new Error('Error while writing to path "' + this.filePath + '": ' + err); | ||
} | ||
} | ||
@@ -156,0 +162,0 @@ } |
var semver = require('semver'); | ||
var nodeVersion = semver.clean(process.version); | ||
if (semver.satisfies(nodeVersion, '>=6.2.2')) { | ||
if (semver.satisfies(nodeVersion, '>=6.0')) { | ||
module.exports = require('./jsondb.js'); // ES6 | ||
@@ -6,0 +6,0 @@ } else { |
@@ -36,4 +36,4 @@ const fs = require("fs"); | ||
// Mandatory arguments check | ||
if ( !filePath || !filePath.length) { | ||
throw new Error('Missing filePath argument.'); | ||
if (!filePath || !filePath.length) { | ||
throw new Error('Missing file path argument.'); | ||
} else { | ||
@@ -65,5 +65,7 @@ this.filePath = filePath; | ||
return; | ||
} else if (err.code === 'EACCES') { | ||
throw new Error(`Cannot access path "${filePath}".`); | ||
} else { | ||
// Other error | ||
throw err; // TODO: Check perm | ||
throw new Error(`Error while checking for existence of path "${filePath}": ${err}`); | ||
} | ||
@@ -75,3 +77,3 @@ } | ||
} catch (err) { | ||
throw new Error(`Cannot read & write on path "${filePath}"`); | ||
throw new Error(`Cannot read & write on path "${filePath}". Check permissions!`); | ||
} | ||
@@ -152,3 +154,7 @@ if (stats.size > 0) { | ||
} catch (err) { | ||
throw err; // TODO: Do something meaningful | ||
if (err.code === 'EACCES') { | ||
throw new Error(`Cannot access path "${this.filePath}".`); | ||
} else { | ||
throw new Error(`Error while writing to path "${this.filePath}": ${err}`); | ||
} | ||
} | ||
@@ -155,0 +161,0 @@ } |
{ | ||
"name": "simple-json-db", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A simple, no-frills, JSON storage engine for Node.JS", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --reporter spec" | ||
"test": "./node_modules/.bin/mocha --bail --reporter spec" | ||
}, | ||
@@ -30,10 +30,10 @@ "repository": { | ||
"devDependencies": { | ||
"babel-cli": "^6.10.1", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-cli": "^6.14.0", | ||
"babel-preset-es2015": "^6.14.0", | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3" | ||
"mocha": "^3.0.2" | ||
}, | ||
"dependencies": { | ||
"semver": "^5.2.0" | ||
"semver": "^5.3.0" | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
# Simple JSONdb | ||
A simple, no-frills, JSON storage engine for Node.JS. | ||
# Simple JSONdb [![dependencies Status](https://david-dm.org/nmaggioni/simple-jsondb/status.svg)](https://david-dm.org/nmaggioni/simple-jsondb) [![devDependencies Status](https://david-dm.org/nmaggioni/simple-jsondb/dev-status.svg)](https://david-dm.org/nmaggioni/simple-jsondb?type=dev) | ||
A simple, no-frills, JSON storage engine for Node.JS with **100% test coverage**. | ||
@@ -15,6 +15,14 @@ [![NPM](https://nodei.co/npm/simple-json-db.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/simple-json-db/) | ||
```javascript | ||
var JSONdb = require('simple-json-db'); | ||
var db = new JSONdb('/path/to/your/database.json', { options }); | ||
const JSONdb = require('simple-json-db'); | ||
const db = new JSONdb('/path/to/your/database.json'); | ||
``` | ||
The prototype of the constructor is `new JSONdb(string, [object])`, and you can supply the optional `options` object by giving it as second parameter: | ||
``` | ||
const db = new JSONdb('/path/to/your/database.json', { ... }); | ||
``` | ||
See the [Options](#options) section for more details. | ||
#### Options | ||
@@ -21,0 +29,0 @@ |
47
test.js
@@ -35,3 +35,13 @@ var JSONdb = require('./jsondb'); | ||
describe("Consistency", function() { | ||
describe('Privilege', function() { | ||
it('Tests are not being run as root', function() { | ||
var isRoot = process.getuid && process.getuid() === 0; | ||
//assert.isFalse(isRoot, 'Please do not run tests with root privileges!'); | ||
if (isRoot) { | ||
assert.fail(false, isRoot, 'Please do not run tests with root privileges!'); | ||
} | ||
}); | ||
}); | ||
describe('Consistency', function() { | ||
beforeEach('Database cleanup', function() { | ||
@@ -41,3 +51,3 @@ createInstance().deleteAll(); | ||
it("Create a new JSONdb instance and test `instanceOf`", function() { | ||
it('Create a new JSONdb instance and test `instanceOf`', function() { | ||
var db = createInstance(); | ||
@@ -47,3 +57,10 @@ assert.instanceOf(db, JSONdb); | ||
it("Check that a non-exhistent key returns `undefined`", function() { | ||
it('Check error handling for paths with no access', function() { | ||
assert.throws(function() { | ||
var db = new JSONdb('/' + Date.now().toString() + '.json', { syncOnWrite: true }); | ||
db.set('foo', 'bar'); | ||
}); | ||
}); | ||
it('Check that a non-exhistent key returns `undefined`', function() { | ||
var db = createInstance(); | ||
@@ -54,3 +71,3 @@ assert.typeOf(db.get(Date.now()), 'undefined', 'Unexpected type of initial read'); | ||
describe("Mechanics", function() { | ||
describe('Mechanics', function() { | ||
beforeEach('Database cleanup', function() { | ||
@@ -60,3 +77,3 @@ createInstance().deleteAll(); | ||
it("Check that values can change", function() { | ||
it('Check that values can change', function() { | ||
var db = createInstance(); | ||
@@ -71,3 +88,3 @@ var change = { testVal: db.get('foo') }; | ||
it("Check that values can change (deterministic)", function() { | ||
it('Check that values can change (deterministic)', function() { | ||
var db = createInstance(); | ||
@@ -81,3 +98,3 @@ db.set('foo', new Date().toISOString()); | ||
it("Check that keys can be deleted", function() { | ||
it('Check that keys can be deleted', function() { | ||
var db = createInstance(); | ||
@@ -92,3 +109,3 @@ db.set('foo', Date.now()); | ||
it("Check that keys existence can be verified (existent key)", function() { | ||
it('Check that keys existence can be verified (existent key)', function() { | ||
var db = createInstance(); | ||
@@ -99,3 +116,3 @@ db.set('foo', Date.now()); | ||
it("Check that keys existence can be verified (non-existent key)", function() { | ||
it('Check that keys existence can be verified (non-existent key)', function() { | ||
var db = createInstance(); | ||
@@ -105,3 +122,3 @@ assert.isFalse(db.has('foo'), 'Key existence is erroneous'); | ||
it("Verify sync to disk", function() { | ||
it('Verify sync to disk', function() { | ||
var db = createInstance(); | ||
@@ -113,3 +130,3 @@ db.set('foo', Date.now()); | ||
describe("Persistency", function() { | ||
describe('Persistency', function() { | ||
var db = createInstance(); | ||
@@ -122,6 +139,8 @@ db.set('foo', Date.now()); | ||
describe("Cleanup", function() { | ||
it("Temporary file removal", function() { | ||
assert.doesNotThrow(function() { fs.unlinkSync(global.filePath); }, Error, 'Unable to cleanup'); | ||
describe('Cleanup', function() { | ||
it('Temporary file removal', function() { | ||
assert.doesNotThrow(function() { | ||
fs.unlinkSync(global.filePath); | ||
}, Error, 'Unable to cleanup'); | ||
}) | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20233
449
72
Updatedsemver@^5.3.0