Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

key-file-storage

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-file-storage - npm Package Compare versions

Comparing version 2.2.9 to 2.2.10

0

dist/index.d.ts

@@ -0,0 +0,0 @@ import { KeyFileStorage } from './src/key-file-storage';

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ export interface KfsCache {

@@ -0,0 +0,0 @@ "use strict";

2

dist/src/key-file-basic.d.ts

@@ -7,2 +7,3 @@ export interface KeyFileBasic {

hasSync(key: string): boolean;
querySync(collection: string): string[];
setAsync(key: string, value: any): Promise<any>;

@@ -13,3 +14,2 @@ getAsync(key: string): Promise<any>;

hasAsync(key: string): Promise<boolean>;
querySync(collection: string): string[];
queryAsync(collection: string): Promise<string[]>;

@@ -16,0 +16,0 @@ }

@@ -20,2 +20,3 @@ "use strict";

hasSync: hasSync,
querySync: querySync,
// Asynchronous

@@ -27,4 +28,2 @@ setAsync: setAsync,

hasAsync: hasAsync,
// Iterate
querySync: querySync,
queryAsync: queryAsync,

@@ -82,2 +81,18 @@ };

}
function querySync(collection) {
collection = validizeKey(collection);
if (collection in cache)
return cache[collection];
try {
var collectionPath = path_1.join(kfsPath, collection);
var files = recurFs.readdir.sync(collectionPath, function (resource, status) {
return status.isFile();
});
files = files.map(function (file) { return validizeKey(path_1.relative(kfsPath, file)); });
return (cache[collection] = files || []);
}
catch (err) {
return [];
}
}
function setAsync(key, value) {

@@ -146,18 +161,2 @@ if (value === undefined)

}
function querySync(collection) {
collection = validizeKey(collection);
if (collection in cache)
return cache[collection];
try {
var collectionPath = path_1.join(kfsPath, collection);
var files = recurFs.readdir.sync(collectionPath, function (resource, status) {
return status.isFile();
});
files = files.map(function (file) { return validizeKey(path_1.relative(kfsPath, file)); });
return (cache[collection] = files || []);
}
catch (err) {
return [];
}
}
function queryAsync(collection) {

@@ -164,0 +163,0 @@ collection = validizeKey(collection);

@@ -0,0 +0,0 @@ export interface KeyFileStorage {

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

{
"name": "key-file-storage",
"version": "2.2.9",
"version": "2.2.10",
"description": "Simple key-value storage directly on file system, maps each key to a separate file.",

@@ -41,5 +41,5 @@ "main": "dist/index.js",

"dependencies": {
"@types/fs-extra": "^8.0.0",
"@types/fs-extra": "^9.0.11",
"@types/is-valid-path": "^0.1.0",
"fs-extra": "^8.1.0",
"fs-extra": "^10.0.0",
"is-valid-path": "^0.1.1",

@@ -49,9 +49,9 @@ "recur-fs": "^2.2.4"

"devDependencies": {
"colors": "^1.3.3",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"tslint": "^5.18.0",
"colors": "^1.4.0",
"prettier": "^2.3.0",
"rimraf": "^3.0.2",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.5.2"
"typescript": "^4.3.2"
}
}

@@ -23,3 +23,3 @@ 'use strict';

{
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
var propertyName = String(property);

@@ -32,6 +32,6 @@ if (propertyName.endsWith('/')) {

Object.keys(collectionCache)
.filter(function(collection) {
.filter(function (collection) {
return keyInCollection(propertyName, collection);
})
.forEach(function(collection) {
.forEach(function (collection) {
return (

@@ -43,3 +43,3 @@ collectionCache[collection].includes(propertyName) || collectionCache[collection].push(propertyName)

},
get: function(target, property, receiver) {
get: function (target, property, receiver) {
var propertyName = String(property);

@@ -49,7 +49,7 @@ if (propertyName.endsWith('/')) return collectionCache[propertyName];

},
deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
var propertyName = String(property);
if (propertyName === '*') {
collectionCache = {};
Object.keys(target).forEach(function(key) {
Object.keys(target).forEach(function (key) {
return delete target[key];

@@ -61,6 +61,6 @@ });

Object.keys(collectionCache)
.filter(function(collection) {
.filter(function (collection) {
return keyInCollection(propertyName, collection);
})
.forEach(function(collection) {
.forEach(function (collection) {
return (

@@ -73,3 +73,3 @@ collectionCache[collection].includes(propertyName) &&

},
has: function(target, property) {
has: function (target, property) {
var propertyName = String(property);

@@ -88,12 +88,12 @@ if (propertyName.endsWith('/')) return propertyName in collectionCache;

{
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
return true;
},
get: function(target, property, receiver) {
get: function (target, property, receiver) {
return undefined;
},
deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
return true;
},
has: function(target, property) {
has: function (target, property) {
return false;

@@ -115,3 +115,3 @@ },

{
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
var propertyName = String(property);

@@ -125,6 +125,6 @@ if (propertyName.endsWith('/')) {

Object.keys(collectionCache)
.filter(function(collection) {
.filter(function (collection) {
return keyInCollection(propertyName, collection);
})
.forEach(function(collection) {
.forEach(function (collection) {
return (

@@ -136,3 +136,3 @@ collectionCache[collection].includes(propertyName) || collectionCache[collection].push(propertyName)

},
get: function(target, property, receiver) {
get: function (target, property, receiver) {
var propertyName = String(property);

@@ -143,3 +143,3 @@ if (propertyName.endsWith('/')) return collectionCache[propertyName];

},
deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
var propertyName = String(property);

@@ -154,6 +154,6 @@ if (propertyName === '*') {

Object.keys(collectionCache)
.filter(function(collection) {
.filter(function (collection) {
return keyInCollection(propertyName, collection);
})
.forEach(function(collection) {
.forEach(function (collection) {
return (

@@ -167,3 +167,3 @@ collectionCache[collection].includes(propertyName) &&

},
has: function(target, property) {
has: function (target, property) {
var propertyName = String(property);

@@ -170,0 +170,0 @@ if (propertyName.endsWith('/')) return propertyName in collectionCache;

@@ -31,3 +31,3 @@ export interface KfsCache {

{
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
const propertyName = String(property);

@@ -40,5 +40,5 @@ if (propertyName.endsWith('/')) {

Object.keys(collectionCache)
.filter(collection => keyInCollection(propertyName, collection))
.filter((collection) => keyInCollection(propertyName, collection))
.forEach(
collection =>
(collection) =>
collectionCache[collection].includes(propertyName) || collectionCache[collection].push(propertyName),

@@ -49,3 +49,3 @@ );

get: function(target, property, receiver) {
get: function (target, property, receiver) {
const propertyName = String(property);

@@ -56,7 +56,7 @@ if (propertyName.endsWith('/')) return collectionCache[propertyName];

deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
const propertyName = String(property);
if (propertyName === '*') {
collectionCache = {};
Object.keys(target).forEach(key => delete target[key]);
Object.keys(target).forEach((key) => delete target[key]);
return true;

@@ -66,5 +66,5 @@ }

Object.keys(collectionCache)
.filter(collection => keyInCollection(propertyName, collection))
.filter((collection) => keyInCollection(propertyName, collection))
.forEach(
collection =>
(collection) =>
collectionCache[collection].includes(propertyName) &&

@@ -76,3 +76,3 @@ collectionCache[collection].splice(collectionCache[collection].indexOf(propertyName), 1),

has: function(target, property) {
has: function (target, property) {
const propertyName = String(property);

@@ -92,15 +92,15 @@ if (propertyName.endsWith('/')) return propertyName in collectionCache;

{
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
return true;
},
get: function(target, property, receiver) {
get: function (target, property, receiver) {
return undefined;
},
deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
return true;
},
has: function(target, property) {
has: function (target, property) {
return false;

@@ -124,3 +124,3 @@ },

{
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
const propertyName = String(property);

@@ -134,5 +134,5 @@ if (propertyName.endsWith('/')) {

Object.keys(collectionCache)
.filter(collection => keyInCollection(propertyName, collection))
.filter((collection) => keyInCollection(propertyName, collection))
.forEach(
collection =>
(collection) =>
collectionCache[collection].includes(propertyName) || collectionCache[collection].push(propertyName),

@@ -143,3 +143,3 @@ );

get: function(target, property, receiver) {
get: function (target, property, receiver) {
const propertyName = String(property);

@@ -151,3 +151,3 @@ if (propertyName.endsWith('/')) return collectionCache[propertyName];

deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
const propertyName = String(property);

@@ -162,5 +162,5 @@ if (propertyName === '*') {

Object.keys(collectionCache)
.filter(collection => keyInCollection(propertyName, collection))
.filter((collection) => keyInCollection(propertyName, collection))
.forEach(
collection =>
(collection) =>
collectionCache[collection].includes(propertyName) &&

@@ -173,3 +173,3 @@ collectionCache[collection].splice(collectionCache[collection].indexOf(propertyName), 1),

has: function(target, property) {
has: function (target, property) {
const propertyName = String(property);

@@ -176,0 +176,0 @@ if (propertyName.endsWith('/')) return propertyName in collectionCache;

@@ -76,4 +76,4 @@ 'use strict';

var file = path_1.join(kfsPath, key);
return new Promise(function(resolve, reject) {
fs_extra_1.outputJson(file, value, { spaces: 2 }, function(err) {
return new Promise(function (resolve, reject) {
fs_extra_1.outputJson(file, value, { spaces: 2 }, function (err) {
if (err) return reject(err);

@@ -88,6 +88,6 @@ resolve((cache[key] = value));

var file = path_1.join(kfsPath, key);
return new Promise(function(resolve, reject) {
fs_extra_1.stat(file, function(err, status) {
return new Promise(function (resolve, reject) {
fs_extra_1.stat(file, function (err, status) {
if (err || !status || !status.isFile()) return resolve((cache[key] = null));
fs_extra_1.readJson(file, function(err, value) {
fs_extra_1.readJson(file, function (err, value) {
if (err) return reject(err);

@@ -103,4 +103,4 @@ resolve((cache[key] = value));

var file = path_1.join(kfsPath, key);
return new Promise(function(resolve, reject) {
fs_extra_1.remove(file, function(err) {
return new Promise(function (resolve, reject) {
fs_extra_1.remove(file, function (err) {
if (err) return reject(err);

@@ -112,4 +112,4 @@ resolve(delete cache[key]);

function clearAsync() {
return new Promise(function(resolve, reject) {
fs_extra_1.remove(kfsPath, function(err) {
return new Promise(function (resolve, reject) {
fs_extra_1.remove(kfsPath, function (err) {
if (err) return reject(err);

@@ -124,4 +124,4 @@ resolve(delete cache['*']);

var file = path_1.join(kfsPath, key);
return new Promise(function(resolve, reject) {
fs_extra_1.stat(file, function(err, status) {
return new Promise(function (resolve, reject) {
fs_extra_1.stat(file, function (err, status) {
resolve(!!(!err && status && status.isFile()));

@@ -136,6 +136,6 @@ });

var collectionPath = path_1.join(kfsPath, collection);
var files = recurFs.readdir.sync(collectionPath, function(resource, status) {
var files = recurFs.readdir.sync(collectionPath, function (resource, status) {
return status.isFile();
});
files = files.map(function(file) {
files = files.map(function (file) {
return validizeKey(path_1.relative(kfsPath, file));

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

if (collection in cache) return Promise.resolve(cache[collection]);
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
//// This implementation does not work with empty folders:

@@ -168,3 +168,3 @@ // recurFs.readdir(collection, function(resource, status, next) {

var collectionPath = path_1.join(kfsPath, collection);
fs_extra_1.stat(collectionPath, function(err, status) {
fs_extra_1.stat(collectionPath, function (err, status) {
if (err) {

@@ -180,3 +180,3 @@ if (err.code === 'ENOENT') resolve((cache[collection] = []));

var folderPath = path_1.join(kfsPath, folder);
fs_extra_1.readdir(folderPath, function(err, files) {
fs_extra_1.readdir(folderPath, function (err, files) {
if (terminated) return;

@@ -192,6 +192,6 @@ jobNumber--;

}
files.forEach(function(file) {
files.forEach(function (file) {
if (terminated) return;
var filePath = path_1.join(folderPath, file);
fs_extra_1.stat(filePath, function(err, status) {
fs_extra_1.stat(filePath, function (err, status) {
if (terminated) return;

@@ -198,0 +198,0 @@ jobNumber--;

@@ -23,2 +23,3 @@ import {

hasSync(key: string): boolean;
querySync(collection: string): string[];

@@ -30,4 +31,2 @@ setAsync(key: string, value: any): Promise<any>;

hasAsync(key: string): Promise<boolean>;
querySync(collection: string): string[];
queryAsync(collection: string): Promise<string[]>;

@@ -50,2 +49,3 @@ }

hasSync,
querySync,

@@ -58,5 +58,2 @@ // Asynchronous

hasAsync,
// Iterate
querySync,
queryAsync,

@@ -112,2 +109,17 @@ };

function querySync(collection: string) {
collection = validizeKey(collection);
if (collection in cache) return cache[collection];
try {
const collectionPath = join(kfsPath, collection);
var files = recurFs.readdir.sync(collectionPath, function (resource: any, status: { isFile: () => void }) {
return status.isFile();
});
files = files.map((file: string) => validizeKey(relative(kfsPath, file)));
return (cache[collection] = files || []);
} catch (err) {
return [];
}
}
function setAsync(key: string, value: any) {

@@ -117,4 +129,4 @@ if (value === undefined) return deleteAsync(key);

var file = join(kfsPath, key);
return new Promise(function(resolve, reject) {
outputJson(file, value, { spaces: 2 }, function(err) {
return new Promise(function (resolve, reject) {
outputJson(file, value, { spaces: 2 }, function (err) {
if (err) return reject(err);

@@ -130,6 +142,6 @@ resolve((cache[key] = value));

var file = join(kfsPath, key);
return new Promise(function(resolve, reject) {
stat(file, function(err, status) {
return new Promise(function (resolve, reject) {
stat(file, function (err, status) {
if (err || !status || !status.isFile()) return resolve((cache[key] = null));
readJson(file, function(err, value) {
readJson(file, function (err, value) {
if (err) return reject(err);

@@ -146,4 +158,4 @@ resolve((cache[key] = value));

var file = join(kfsPath, key);
return new Promise(function(resolve, reject) {
remove(file, function(err) {
return new Promise(function (resolve, reject) {
remove(file, function (err) {
if (err) return reject(err);

@@ -156,4 +168,4 @@ resolve(delete cache[key]);

function clearAsync(): Promise<boolean> {
return new Promise(function(resolve, reject) {
remove(kfsPath, function(err) {
return new Promise(function (resolve, reject) {
remove(kfsPath, function (err) {
if (err) return reject(err);

@@ -169,4 +181,4 @@ resolve(delete cache['*']);

var file = join(kfsPath, key);
return new Promise(function(resolve, reject) {
stat(file, function(err, status) {
return new Promise(function (resolve, reject) {
stat(file, function (err, status) {
resolve(!!(!err && status && status.isFile()));

@@ -177,17 +189,2 @@ });

function querySync(collection: string) {
collection = validizeKey(collection);
if (collection in cache) return cache[collection];
try {
const collectionPath = join(kfsPath, collection);
var files = recurFs.readdir.sync(collectionPath, function(resource: any, status: { isFile: () => void }) {
return status.isFile();
});
files = files.map((file: string) => validizeKey(relative(kfsPath, file)));
return (cache[collection] = files || []);
} catch (err) {
return [];
}
}
function queryAsync(collection: string): Promise<string[]> {

@@ -197,3 +194,3 @@ collection = validizeKey(collection);

return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
//// This implementation does not work with empty folders:

@@ -216,3 +213,3 @@ // recurFs.readdir(collection, function(resource, status, next) {

const collectionPath = join(kfsPath, collection);
stat(collectionPath, function(err, status) {
stat(collectionPath, function (err, status) {
if (err) {

@@ -229,3 +226,3 @@ if (err.code === 'ENOENT') resolve((cache[collection] = []));

const folderPath = join(kfsPath, folder);
readdir(folderPath, function(err, files) {
readdir(folderPath, function (err, files) {
if (terminated) return;

@@ -241,6 +238,6 @@ jobNumber--;

}
files.forEach(function(file) {
files.forEach(function (file) {
if (terminated) return;
var filePath = join(folderPath, file);
stat(filePath, function(err, status) {
stat(filePath, function (err, status) {
if (terminated) return;

@@ -247,0 +244,0 @@ jobNumber--;

@@ -11,3 +11,3 @@ 'use strict';

var hasAsyncWrap = {
has: function(target, property) {
has: function (target, property) {
var promise = kfb.hasAsync(property);

@@ -24,3 +24,3 @@ if (hasAsyncHandler) {

var kfs = new Proxy(
function() {
function () {
var a1 = arguments[0],

@@ -82,7 +82,7 @@ a2 = arguments[1],

/* sync set */
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
kfb.setSync(String(property), value);
return true;
},
get: function(target, property, receiver) {
get: function (target, property, receiver) {
if (String(property).slice(-1) === '/') {

@@ -97,11 +97,11 @@ /* sync query */

/* sync delete */
deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
return kfb.deleteSync(String(property));
},
/* sync has */
has: function(target, property) {
has: function (target, property) {
return kfb.hasSync(String(property));
},
/* async delete */
construct: function(target, argumentsList, newTarget) {
construct: function (target, argumentsList, newTarget) {
var a1 = argumentsList[0],

@@ -131,3 +131,3 @@ a2 = argumentsList[1];

if (typeof callback === 'function') {
return promise.then(function(data) {
return promise.then(function (data) {
return callback(undefined, data);

@@ -134,0 +134,0 @@ }, callback);

@@ -23,3 +23,3 @@ import keyFileBasic from './key-file-basic';

var hasAsyncWrap = {
has: function(target: any, property: string) {
has: function (target: any, property: string) {
var promise = kfb.hasAsync(property);

@@ -37,3 +37,3 @@ if (hasAsyncHandler) {

var kfs = new Proxy(
function() {
function () {
var a1 = arguments[0],

@@ -100,3 +100,3 @@ a2 = arguments[1],

/* sync set */
set: function(target, property, value, receiver) {
set: function (target, property, value, receiver) {
kfb.setSync(String(property), value);

@@ -106,3 +106,3 @@ return true;

get: function(target, property, receiver) {
get: function (target, property, receiver) {
if (String(property).slice(-1) === '/') {

@@ -118,3 +118,3 @@ /* sync query */

/* sync delete */
deleteProperty: function(target, property) {
deleteProperty: function (target, property) {
return kfb.deleteSync(String(property));

@@ -124,3 +124,3 @@ },

/* sync has */
has: function(target, property) {
has: function (target, property) {
return kfb.hasSync(String(property));

@@ -130,3 +130,3 @@ },

/* async delete */
construct: function(target, argumentsList, newTarget) {
construct: function (target, argumentsList, newTarget) {
var a1 = argumentsList[0],

@@ -162,3 +162,3 @@ a2 = argumentsList[1];

if (typeof callback === 'function') {
return promise.then(function(data) {
return promise.then(function (data) {
return callback(undefined, data);

@@ -165,0 +165,0 @@ }, callback);

@@ -0,0 +0,0 @@ "use strict";

@@ -6,2 +6,4 @@ import keyFileStorage from './index';

console.log('..............................................');
console.log("(kfs.a = 'a') >> ", (kfs.a = 'a'));

@@ -34,5 +36,5 @@ console.log('kfs.a, kfs.b >> ', kfs.a, kfs.b);

Promise.resolve()
.then(x => kfs('qq/qqq', { data: 123 }))
.then(x => kfs('qq/www', { data: 456 }))
.then(x => kfs('qq/'))
.then(x => console.log(x))
.then(x => kfs('qq/qqq', { data: 123 }))
.then(x => kfs('qq/www', { data: 456 }))
.then(x => kfs('qq/'))
.then(x => console.log(x));
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