key-file-storage
Advanced tools
Comparing version 2.0.3 to 2.1.0
{ | ||
"name": "key-file-storage", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Simple key-value storage directly on file system, maps each key to a separate file.", | ||
@@ -25,3 +25,5 @@ "main": "main.js", | ||
"dependencies": { | ||
"fs-extra": "^0.30.0" | ||
"fs-extra": "^0.30.0", | ||
"is-valid-path": "^0.1.1", | ||
"recur-fs": "^2.2.4" | ||
}, | ||
@@ -28,0 +30,0 @@ "devDependencies": { |
184
README.md
@@ -15,2 +15,15 @@ # key-file-storage | ||
```javascript | ||
var kfs = require("key-file-storage")('my/storage/path'); | ||
// Write something to file 'my/storage/path/myfile' | ||
kfs.myfile = { mydata: 123 }; | ||
// Read contents of file 'my/storage/path/myfile' | ||
var mydata = kfs.myfile.mydata; | ||
// Delete file 'my/storage/path/myfile' | ||
delete kfs.myfile; | ||
``` | ||
Just give it a try, you'll like it! | ||
@@ -20,3 +33,3 @@ | ||
Installing package on Node.js (*Node.js 6.0.0 or higher is required*) : | ||
Installing package on Node.js (*Node.js **6.0.0** or higher is required*) : | ||
```sh | ||
@@ -28,20 +41,19 @@ $ npm install key-file-storage | ||
Initializing key-file storage : | ||
Initializing a key-file storage : | ||
```javascript | ||
var keyFileStorage = require("key-file-storage"); | ||
// Using an unlimited cache | ||
var kfs = keyFileStorage('/path/to/the/storage/directory'); | ||
var kfs = keyFileStorage('/storage/directory/path', caching); | ||
``` | ||
/* or */ | ||
The value of `caching` can be | ||
// Using a custom cache | ||
var kfs = keyFileStorage('/path/to/the/storage/directory', cacheConfig); | ||
``` | ||
1. `true` (_Default value, if not specified_) : | ||
Unlimited cache, anything will be cached on memory, good for small data volumes. | ||
The value of `cacheConfig` can be | ||
2. `false` : | ||
No cache, read the files from disk every time, good when other applications can modify the files' contents arbitrarily. | ||
1. `true` (_By default_) : Unlimited cache, anything will be cached on memory, good for small data volumes. | ||
2. `false` : No cache, read the files from disk every time, good when other applications can modify the files' contents arbitrarily. | ||
3. `n` (_An integer number_) : Limited cache, only the `n` latest referred key-values will be cached, good for large data volumes where only a fraction of data is being used frequently . | ||
3. `n` (_An integer number_) : | ||
Limited cache, only the `n` latest referred key-values will be cached, good for large data volumes where only a fraction of data is being used frequently . | ||
@@ -55,21 +67,21 @@ ## Usage | ||
```javascript | ||
// Set | ||
kfs['key'] = value | ||
// Get | ||
kfs['key'] | ||
// Delete | ||
delete kfs['key'] | ||
// Check for existence | ||
'key' in kfs // true or false | ||
// Clear all database | ||
delete kfs['*'] | ||
kfs['key'] = value // Write file | ||
``` | ||
```javascript | ||
kfs['key'] // Read file | ||
``` | ||
```javascript | ||
delete kfs['key'] // Delete file | ||
``` | ||
```javascript | ||
delete kfs['*'] // Delete all storage files | ||
``` | ||
```javascript | ||
'key' in kfs // Check for file existence | ||
//=> true or false | ||
``` | ||
- You can use `kfs.keyName` instead of `kfs['keyName']` anywhere if the key name allows. | ||
- `undefined` is not supported as a savable value, but `null` is. Saving a key with value `undefined` is equivalent to remove it. So, you can use `kfs['key'] = undefined` or even `kfs['*'] = undefined` to delete data. | ||
- `undefined` is not supported as a savable value, but `null` is. Saving a key with value `undefined` is equivalent to remove it. So, you can use `kfs['key'] = undefined` or even `kfs['*'] = undefined` to delete files. | ||
@@ -80,56 +92,92 @@ - Synchronous API will throw an exception if any errors happens, so you shall handle it your way. | ||
Every one of the following calls returns a promise : | ||
Every one of the following calls **returns a promise** : | ||
```javascript | ||
// Set | ||
kfs('key', value) | ||
kfs('key', value) // Write file | ||
``` | ||
```javascript | ||
kfs('key') // Read file | ||
``` | ||
```javascript | ||
new kfs('key') // Delete file | ||
``` | ||
```javascript | ||
new kfs('*') /* or */ | ||
new kfs() /* or */ | ||
new kfs // Delete all storage files | ||
``` | ||
```javascript | ||
('key' in kfs(), kfs()) // Check for file existence | ||
// Resolves to true or false | ||
``` | ||
// Get | ||
kfs('key') | ||
- Once again, `undefined` is not supported as a savable value, but `null` is. Saving a key with value `undefined` is equivalent to remove it. So, you can use `kfs('key', undefined)` or even `kfs('*', undefined)` to delete files. | ||
// Delete | ||
new kfs('key') | ||
### Asynchronous API with Callbacks | ||
// Check for existence | ||
('key' in kfs(), kfs()) // resolves to true or false | ||
The same as asynchronous with promises, but with callback function as the last input value of `kfs()` : | ||
// Clear all database | ||
new kfs('*') /* or */ new kfs() | ||
```javascript | ||
kfs('key', value, cb) // Write file | ||
``` | ||
```javascript | ||
kfs('key', cb) // Read file | ||
``` | ||
```javascript | ||
new kfs('key', cb) // Delete file | ||
``` | ||
```javascript | ||
new kfs('*', cb) /* or */ | ||
new kfs(cb) // Delete all storage files | ||
``` | ||
```javascript | ||
'key' in kfs(cb) // Check for file existence | ||
// without promise output | ||
/* or */ | ||
('key' in kfs(), kfs(cb)) | ||
// Check for file existence | ||
// with promise output | ||
``` | ||
- Once again, `undefined` is not supported as a savable value, but `null` is. Saving a key with value `undefined` is equivalent to remove it. So, you can use `kfs('key', undefined)` or even `kfs('*', undefined)` to delete data. | ||
- These calls *still* return a promise on their output (except for `'key' in kfs(callback)` form of existence check). | ||
### Asynchronous API with Callbacks | ||
- The first input parameter of all callback functions is `err`, so you shall handle it within the callback. *Reading* and *Existence checking* callbacks provide the return values as their second input parameter. | ||
The same as asynchronous with promises, but with callback function as the last input value of `kfs()` : | ||
### Folders as Collections | ||
```javascript | ||
// Set | ||
kfs('key', value, callback) | ||
Every folder in the storage can be treated as a *collection* of *key-values*. | ||
// Get | ||
kfs('key', callback) | ||
You can query the list of all containing keys (*filenames*) within a collection (*folder*) like this (_**Note** that a collection path must end with a **forward slash** `'/'`_) : | ||
// Delete | ||
new kfs('key', callback) | ||
#### Synchronous API | ||
// Check for existence | ||
'key' in kfs(callback) // No promise returns anymore | ||
/* or */ | ||
('key' in kfs(), kfs(callback)) // resolves to true or false | ||
```javascript | ||
var keys = kfs['col/path/'] | ||
// keys = ['col/path/key1', 'col/path/sub/key2', ... ] | ||
``` | ||
// Clear all database | ||
new kfs('*', callback) /* or */ new kfs(callback) | ||
#### Asynchronous API with Promises | ||
```javascript | ||
kfs('col/path/').then(function(keys) { | ||
// keys = ['col/path/key1', 'col/path/sub/key2', ... ] | ||
}); | ||
``` | ||
- These calls *still* return a promise on their output (except for `'key' in kfs(callback)` form of existence check). | ||
#### Asynchronous API with Callbacks | ||
- The first input parameter of all callback functions is `err`, so you shall handle it within the callback. *Set*, *Get* and *Existence check* callbacks provide the return values as their second input parameter. | ||
```javascript | ||
kfs('col/path/', function(error, keys) { | ||
// keys = ['col/path/key1', 'col/path/sub/key2', ... ] | ||
}); | ||
``` | ||
## Notes | ||
- **NOTE 1 :** Each key will map to a separate file (*using the key itself as its relative path*) so there is no need to load all the database file for any key access. Therefore, keys may be relative paths, e.g: `data.json`, `/my/key/01` or `any/other/relative/path/to/a/file`. The only exception is strings including `..` (*double dot*) which will not be accepted for security reasons. | ||
- **NOTE 1 :** Each key will map to a separate file (*using the key itself as its relative path*). Therefore, keys may be relative paths, e.g: `'data.json'`, `'/my/key/01'` or `'any/other/relative/path/to/a/file'`. The only exception is strings including `'..'` (*double dot*) which will not be accepted for security reasons. | ||
- **NOTE 2 :** There is a built-in implemented **cache**, so accessing a certain key more than once won't require file-system level operations (off course with some active cache). | ||
- **NOTE 2 :** If a key's relative path ends with a *forward slash* `'/'`, it will be considered to be a collection (*folder*) name. So, `'data/set/'` is a collection and `'data/set/key'` is a key in that collection. | ||
- **NOTE 3 :** This module has a built-in implemented **cache**, so, when activated, accessing a certain key more than once won't require file-system level operations again for that file. | ||
## Example | ||
@@ -147,12 +195,16 @@ | ||
name: "Hessam", | ||
age: 30 | ||
skills: { | ||
java: 10, | ||
csharp: 15 | ||
} | ||
}; | ||
// Read file './db/users/hessam/skills' as a JSON object asynchronously: | ||
kfs('users/hessam/skills').then(skills => { | ||
console.log("Hessam's java skill is ", skills.java); | ||
kfs('users/hessam').then(function(hessamData) { | ||
console.log("Hessam's java skill is ", | ||
hessamData.skills.java); | ||
}); | ||
// Check whether file './db/users/mahdiar' exists or not asynchronously: | ||
'users/mahdiar' in kfs(exists => { | ||
'users/mahdiar' in kfs(function(error, exists) { | ||
if(exists) { | ||
@@ -162,2 +214,6 @@ console.log("We have Mahdiar's data!"); | ||
}); | ||
// List the file names of all users in './db/users/' synchronously: | ||
var allUsers = kfs['users/']; | ||
//=> ['users/hessam', 'users/mahdiar', ... ] | ||
``` | ||
@@ -167,5 +223,5 @@ | ||
The code is simple and straightforward. It would be nice if you had any suggestions or contribution on it or detected any bug or issue. | ||
The code is simple and straightforward. It would be appreciated if you had any suggestions or contribution on it or detected any bug or issue. | ||
+ See the code on [GitHub.com](https://github.com/ahs502/key-file-storage) | ||
+ See the code on [GitHub.com (key-file-storage)](https://github.com/ahs502/key-file-storage) | ||
+ Contact me by [my gmail address](ahs502@gmail.com) *(Hessam A Shokravi)* |
var fs = require("fs-extra"); | ||
var path = require("path"); | ||
var isValidPath = require('is-valid-path'); | ||
var recurFs = require('recur-fs'); | ||
@@ -8,6 +10,5 @@ module.exports = keyFileBasic; | ||
if (kfsPath === undefined) { | ||
kfsPath = __dirname; // Current working folder by default. | ||
} | ||
else if (typeof kfsPath !== 'string') { | ||
kfsPath = kfsPath || __dirname; // Current working folder by default. | ||
kfsPath = String(kfsPath); | ||
if (!isValidPath(kfsPath)) { | ||
throw new Error('Invalid stroage path.'); | ||
@@ -30,4 +31,8 @@ } | ||
clearAsync, | ||
hasAsync | ||
hasAsync, | ||
// Iterate | ||
querySync, | ||
queryAsync | ||
}; | ||
@@ -204,5 +209,37 @@ | ||
function querySync(collection) { | ||
try { | ||
collection = path.join(kfsPath, validizeKey(collection)); | ||
var files = recurFs.readdir.sync(collection, function(resource, stat) { | ||
return stat.isFile(); | ||
}); | ||
files = files.map(file => path.relative(kfsPath, file)); | ||
return files || []; | ||
} | ||
catch (err) { | ||
return []; | ||
} | ||
} | ||
function queryAsync(collection) { | ||
return new Promise(function(resolve, reject) { | ||
collection = path.join(kfsPath, validizeKey(collection)); | ||
recurFs.readdir(collection, function(resource, stat, next) { | ||
next(stat.isFile()); | ||
}, function(err, resources) { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(resources.map(file => path.relative(kfsPath, file))); | ||
} | ||
}); | ||
}); | ||
} | ||
/////////////////////////////////////////////////// | ||
function validizeKey(key) { | ||
key = String(key); | ||
if (key.indexOf('..') >= 0) { | ||
if (key.indexOf('/..') >= 0 || key.indexOf('../') >= 0 || key === '..') { | ||
throw new Error('Invalid key name.'); | ||
@@ -209,0 +246,0 @@ } |
@@ -57,2 +57,6 @@ var keyFileBasic = require("./key-file-basic"); | ||
} | ||
else if (String(a1).slice(-1) === '/') { | ||
/* async query pr */ | ||
return kfb.queryAsync(a1); | ||
} | ||
else { | ||
@@ -66,4 +70,10 @@ /* async get pr */ | ||
if (typeof a2 === 'function') { | ||
/* async get cb */ | ||
return callbackizePromise(kfb.getAsync(a1), a2); | ||
if (String(a1).slice(-1) === '/') { | ||
/* async query cb */ | ||
return callbackizePromise(kfb.queryAsync(a1), a2); | ||
} | ||
else { | ||
/* async get cb */ | ||
return callbackizePromise(kfb.getAsync(a1), a2); | ||
} | ||
} | ||
@@ -94,5 +104,11 @@ else { | ||
/* sync get */ | ||
get: function(target, property, receiver) { | ||
return kfb.getSync(property); | ||
if (String(property).slice(-1) === '/') { | ||
/* sync query */ | ||
return kfb.querySync(property); | ||
} | ||
else { | ||
/* sync get */ | ||
return kfb.getSync(property); | ||
} | ||
}, | ||
@@ -123,3 +139,8 @@ | ||
case 1: | ||
return kfb.deleteAsync(a1); | ||
if (typeof a1 === 'function') { | ||
return callbackizePromise(kfb.clearAsync(), a1); | ||
} | ||
else { | ||
return kfb.deleteAsync(a1); | ||
} | ||
// break; | ||
@@ -126,0 +147,0 @@ |
258
test.js
@@ -0,15 +1,33 @@ | ||
///////////////////////////////////////////////////// | ||
require("colors"); | ||
var _ = require("lodash"); | ||
function e(x1, x2, method) { // expect to be equal | ||
if (!_.isEqual(x1, x2)) { | ||
console.log('ERROR. '.red.bold, (method || '').red); | ||
console.log((String(x1).bold + ' != ' + (String(x2).bold)).yellow); | ||
throw new Error(method); | ||
} | ||
else { | ||
console.log('Passed! '.green.bold, (method || '').green); | ||
} | ||
var e = expectedToBeEqual(_.isEqual); | ||
var a = expectedToBeEqual(setEqual); | ||
function expectedToBeEqual(isEqual) { | ||
return function(x1, x2, method) { | ||
if (!isEqual(x1, x2)) { | ||
console.log('ERROR. '.red.bold, (method || '').red); | ||
console.log((String(x1).bold + ' != ' + (String(x2).bold)).yellow); | ||
throw new Error(method); | ||
} | ||
else { | ||
console.log('Passed! '.green.bold, (method || '').green); | ||
} | ||
}; | ||
} | ||
function setEqual(s1, s2) { | ||
s1 = s1 || []; | ||
s2 = s2 || []; | ||
var i; | ||
for (i = 0; i < s1.length; i++) | ||
if (s2.indexOf(s1[i]) < 0) return false; | ||
for (i = 0; i < s2.length; i++) | ||
if (s1.indexOf(s2[i]) < 0) return false; | ||
return true; | ||
} | ||
function mock(obj, method, wrap) { | ||
@@ -49,100 +67,146 @@ var f = obj[method]; | ||
kfs = keyFileStorage('./db', 6); | ||
// testBasicAsyncPromise(); | ||
// testBasicSync(); | ||
testBasicQuery(); | ||
kfs('a') | ||
.then(a => e(a, null, '0001'), errorHandler) | ||
.then(() => kfs('a/b', 456), errorHandler) | ||
.then(ab => e(ab, 456, '0002'), errorHandler) | ||
.then(() => kfs('a/b'), errorHandler) | ||
.then(ab => e(ab, 456, '0003'), errorHandler) | ||
.then(() => new kfs('a/b'), errorHandler) | ||
.then(() => kfs('a/b'), errorHandler) | ||
.then(ab => e(ab, null, '0004'), errorHandler) | ||
.then(() => kfs('s', 67), errorHandler) | ||
.then(() => kfs('s'), errorHandler) | ||
.then(s => e(s, 67, '0005'), errorHandler) | ||
.then(() => kfs('s', undefined), errorHandler) | ||
.then(() => kfs('s'), errorHandler) | ||
.then(s => e(s, null, '0005ex'), errorHandler) | ||
.then(() => kfs('f/h/y', 'dfgafgsdfgsfdgfdsgsfdgsdf'), errorHandler) | ||
.then(() => kfs('w/4/e', null), errorHandler) | ||
.then(() => kfs('65', true), errorHandler) | ||
.then(() => kfs('_-_-_', 12345.67890), errorHandler) | ||
.then(() => kfs('f/h/y'), errorHandler) | ||
.then(x => e(x, 'dfgafgsdfgsfdgfdsgsfdgsdf', '0006'), errorHandler) | ||
.then(() => kfs('w/4/e'), errorHandler) | ||
.then(x => e(x, null, '0007'), errorHandler) | ||
.then(() => kfs(65), errorHandler) | ||
.then(x => e(x, true, '0008'), errorHandler) | ||
.then(() => kfs('_-_-_'), errorHandler) | ||
.then(x => e(x, 12345.67890, '0009'), errorHandler) | ||
.then(() => ('qwe' in kfs(), kfs()), errorHandler) | ||
.then(has => e(has, false, 'has001'), errorHandler) | ||
.then(() => ('_-_-_' in kfs(), kfs()), errorHandler) | ||
.then(has => e(has, true, 'has002'), errorHandler) | ||
.then(() => ('f/h/y' in kfs(), kfs()), errorHandler) | ||
.then(has => e(has, true, 'has003'), errorHandler) | ||
.then(() => new kfs(), errorHandler) | ||
.then(() => kfs('f/h/y'), errorHandler) | ||
.then(x => e(x, null, '0010'), errorHandler) | ||
.then(() => kfs('w/4/e'), errorHandler) | ||
.then(x => e(x, null, '0011'), errorHandler) | ||
.then(() => kfs(65), errorHandler) | ||
.then(x => e(x, null, '0012'), errorHandler) | ||
.then(() => kfs('_-_-_'), errorHandler) | ||
.then(x => e(x, null, '0013'), errorHandler) | ||
///////////////////////////////////////////////////// | ||
.then(() => terminateCondition = true, () => terminateCondition = true); | ||
function testBasicAsyncPromise() { | ||
kfs = keyFileStorage('./db', 6); | ||
function errorHandler(err) { | ||
console.log(String(err).res.inverse); | ||
return ''; | ||
kfs('a') | ||
.then(a => e(a, null, '0001'), errorHandler) | ||
.then(() => kfs('a/b', 456), errorHandler) | ||
.then(ab => e(ab, 456, '0002'), errorHandler) | ||
.then(() => kfs('a/b'), errorHandler) | ||
.then(ab => e(ab, 456, '0003'), errorHandler) | ||
.then(() => new kfs('a/b'), errorHandler) | ||
.then(() => kfs('a/b'), errorHandler) | ||
.then(ab => e(ab, null, '0004'), errorHandler) | ||
.then(() => kfs('s', 67), errorHandler) | ||
.then(() => kfs('s'), errorHandler) | ||
.then(s => e(s, 67, '0005'), errorHandler) | ||
.then(() => kfs('s', undefined), errorHandler) | ||
.then(() => kfs('s'), errorHandler) | ||
.then(s => e(s, null, '0005ex'), errorHandler) | ||
.then(() => kfs('f/h/y', 'dfgafgsdfgsfdgfdsgsfdgsdf'), errorHandler) | ||
.then(() => kfs('w/4/e', null), errorHandler) | ||
.then(() => kfs('65', true), errorHandler) | ||
.then(() => kfs('_-_-_', 12345.67890), errorHandler) | ||
.then(() => kfs('f/h/y'), errorHandler) | ||
.then(x => e(x, 'dfgafgsdfgsfdgfdsgsfdgsdf', '0006'), errorHandler) | ||
.then(() => kfs('w/4/e'), errorHandler) | ||
.then(x => e(x, null, '0007'), errorHandler) | ||
.then(() => kfs(65), errorHandler) | ||
.then(x => e(x, true, '0008'), errorHandler) | ||
.then(() => kfs('_-_-_'), errorHandler) | ||
.then(x => e(x, 12345.67890, '0009'), errorHandler) | ||
.then(() => ('qwe' in kfs(), kfs()), errorHandler) | ||
.then(has => e(has, false, 'has001'), errorHandler) | ||
.then(() => ('_-_-_' in kfs(), kfs()), errorHandler) | ||
.then(has => e(has, true, 'has002'), errorHandler) | ||
.then(() => ('f/h/y' in kfs(), kfs()), errorHandler) | ||
.then(has => e(has, true, 'has003'), errorHandler) | ||
.then(() => new kfs(), errorHandler) | ||
.then(() => kfs('f/h/y'), errorHandler) | ||
.then(x => e(x, null, '0010'), errorHandler) | ||
.then(() => kfs('w/4/e'), errorHandler) | ||
.then(x => e(x, null, '0011'), errorHandler) | ||
.then(() => kfs(65), errorHandler) | ||
.then(x => e(x, null, '0012'), errorHandler) | ||
.then(() => kfs('_-_-_'), errorHandler) | ||
.then(x => e(x, null, '0013'), errorHandler) | ||
.then(() => terminateCondition = true, () => terminateCondition = true); | ||
function errorHandler(err) { | ||
console.log(String(err).res.inverse); | ||
return ''; | ||
} | ||
} | ||
// kfs = keyFileStorage('./db'); | ||
///////////////////////////////////////////////////// | ||
// e(kfs.a = 65, kfs.a, '0001'); | ||
// e(kfs.a, 65, '0002'); | ||
// e(kfs.b, null, '0003'); | ||
// e(kfs['c/v/x'] = { | ||
// a: 4, | ||
// b: 'qwerty' | ||
// }, kfs['c/v/x'], '0004'); | ||
// e('c/v/x' in kfs, true, '0005'); | ||
// e('a' in kfs, true, '0006'); | ||
// e(delete kfs.a, true, '0007'); | ||
// e('a' in kfs, false, '0008'); | ||
// e(delete kfs['c/v/x'], true, '0009'); | ||
// e('c/v/x' in kfs, false, '0010'); | ||
// kfs.z1 = 1; | ||
// kfs.z2 = 2; | ||
// kfs.z3 = 3; | ||
// kfs.z4 = 4; | ||
// kfs.y1 = kfs.z1; | ||
// kfs.z5 = 5; | ||
// kfs.z6 = 6; | ||
// kfs.z7 = 7; | ||
// e(kfs.z1, 1, '0011'); | ||
// e(kfs.z2, 2, '0012'); | ||
// e(kfs.z3, 3, '0013'); | ||
// e(kfs.z4, 4, '0014'); | ||
// e(kfs.z5, 5, '0015'); | ||
// e(kfs.z6, 6, '0016'); | ||
// e(kfs.z7, 7, '0017'); | ||
// e(kfs.y1, kfs.z1, '0018'); | ||
// delete kfs['*']; | ||
// e(kfs.z1, null, '0019'); | ||
// e(kfs.z2, null, '0020'); | ||
// e(kfs.z3, null, '0021'); | ||
// e(kfs.z4, null, '0022'); | ||
// e(kfs.z5, null, '0023'); | ||
// e(kfs.z6, null, '0024'); | ||
// e(kfs.z7, null, '0025'); | ||
// e(kfs.y1, null, '0026'); | ||
function testBasicSync() { | ||
kfs = keyFileStorage('./db'); | ||
// terminateCondition = true; | ||
e(kfs.a = 65, kfs.a, '0001'); | ||
e(kfs.a, 65, '0002'); | ||
e(kfs.b, null, '0003'); | ||
e(kfs['c/v/x'] = { | ||
a: 4, | ||
b: 'qwerty' | ||
}, kfs['c/v/x'], '0004'); | ||
e('c/v/x' in kfs, true, '0005'); | ||
e('a' in kfs, true, '0006'); | ||
e(delete kfs.a, true, '0007'); | ||
e('a' in kfs, false, '0008'); | ||
e(delete kfs['c/v/x'], true, '0009'); | ||
e('c/v/x' in kfs, false, '0010'); | ||
kfs.z1 = 1; | ||
kfs.z2 = 2; | ||
kfs.z3 = 3; | ||
kfs.z4 = 4; | ||
kfs.y1 = kfs.z1; | ||
kfs.z5 = 5; | ||
kfs.z6 = 6; | ||
kfs.z7 = 7; | ||
e(kfs.z1, 1, '0011'); | ||
e(kfs.z2, 2, '0012'); | ||
e(kfs.z3, 3, '0013'); | ||
e(kfs.z4, 4, '0014'); | ||
e(kfs.z5, 5, '0015'); | ||
e(kfs.z6, 6, '0016'); | ||
e(kfs.z7, 7, '0017'); | ||
e(kfs.y1, kfs.z1, '0018'); | ||
delete kfs['*']; | ||
e(kfs.z1, null, '0019'); | ||
e(kfs.z2, null, '0020'); | ||
e(kfs.z3, null, '0021'); | ||
e(kfs.z4, null, '0022'); | ||
e(kfs.z5, null, '0023'); | ||
e(kfs.z6, null, '0024'); | ||
e(kfs.z7, null, '0025'); | ||
e(kfs.y1, null, '0026'); | ||
terminateCondition = true; | ||
} | ||
///////////////////////////////////////////////////// | ||
function testBasicQuery() { | ||
kfs = keyFileStorage('./db', false); | ||
kfs['asd0'] = kfs['adf'] = kfs['asdh'] = kfs['asd.zxc'] = | ||
kfs['qwe.zxc'] = kfs['asd.xcv'] = kfs['qwe.asd'] = | ||
kfs['asd/tyu'] = kfs['asd/tyu2'] = kfs['asd/wer/1'] = | ||
kfs['asd/wer/2'] = kfs['asd/wer5'] = kfs['asd/wer/5/1'] = | ||
kfs['z.z'] = kfs['z.'] = kfs['.z'] = kfs['z.z.z'] = kfs['z/.z'] = | ||
kfs['z/z.'] = kfs['z/z.z'] = kfs['z/z/.z'] = kfs['z/z/z.'] = kfs['z/z/z.z'] = | ||
true; | ||
a(kfs['/'], ['.z', 'adf', 'asd/tyu', 'asd/tyu2', 'asd/wer/1', 'asd/wer/2', 'asd/wer/5/1', 'asd/wer5', 'asd.xcv', 'asd.zxc', 'asd0', 'asdh', 'qwe.asd', 'qwe.zxc', 'z/.z', 'z/z/.z', 'z/z/z.', 'z/z/z.z', 'z/z.', 'z/z.z', 'z.', 'z.z', 'z.z.z'], '0001'); | ||
a(kfs['rfv/'], [], '0002'); | ||
a(kfs['z/'], ['z/.z', 'z/z.', 'z/z.z', 'z/z/.z', 'z/z/z.', 'z/z/z.z'], '0003'); | ||
a(kfs['asd/wer/5/'], ['asd/wer/5/1'], '0004'); | ||
kfs('/') | ||
.then(keys => a(keys, ['.z', 'adf', 'asd/tyu', 'asd/tyu2', 'asd/wer/1', 'asd/wer/2', 'asd/wer/5/1', 'asd/wer5', 'asd.xcv', 'asd.zxc', 'asd0', 'asdh', 'qwe.asd', 'qwe.zxc', 'z/.z', 'z/z/.z', 'z/z/z.', 'z/z/z.z', 'z/z.', 'z/z.z', 'z.', 'z.z', 'z.z.z'], '0010')) | ||
.then(() => kfs('rfv/' /*,keys=>a(keys,[],'0011')*/ )) | ||
.then(keys => a(keys, [], '0011')) | ||
.then(() => kfs('z/', function(err, keys) { | ||
if (err) return Promise.reject(err); | ||
a(keys, ['z/.z', 'z/z.', 'z/z.z', 'z/z/.z', 'z/z/z.', 'z/z/z.z'], '0012'); | ||
})) | ||
.then(() => kfs('asd/wer/5/', function(err, keys) { | ||
if (err) return Promise.reject(err); | ||
a(keys, ['asd/wer/5/1'], '0013'); | ||
})) | ||
.then(() => terminateCondition = true, () => terminateCondition = true); | ||
} | ||
///////////////////////////////////////////////////// | ||
///////////////////////////////////////////////////// | ||
///////////////////////////////////////////////////// | ||
@@ -153,1 +217,3 @@ var terminateCondition; | ||
})(); | ||
///////////////////////////////////////////////////// |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31148
33
644
220
0
3
+ Addedis-valid-path@^0.1.1
+ Addedrecur-fs@^2.2.4
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-invalid-path@0.1.0(transitive)
+ Addedis-valid-path@0.1.1(transitive)
+ Addedminimatch@3.0.3(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedmkdirp@0.5.1(transitive)
+ Addedrecur-fs@2.2.4(transitive)
+ Addedrimraf@2.5.4(transitive)