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

node-kv-storage

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-kv-storage - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

42

index.js

@@ -0,1 +1,2 @@

const path = require('path');
const storage = require('node-persist');

@@ -62,3 +63,3 @@

// const _databaseName = new WeakMap();
const _databaseName = new WeakMap();
const _databasePromise = new WeakMap();

@@ -68,19 +69,29 @@

// const checkFileExists = (filePath) => fs.promises.access(filePath, fs.F_OK).then(() => true).catch(() => false);
function init(name) {
const baseDir = process.env.NODE_KV_STORAGE_DIR || global.NODE_KV_STORAGE_DIR || process.cwd();
const dirName = name === DEFAULT_STORAGE_AREA_NAME ? 'storage' : name;
const db = storage.create({
dir: '.node-persist/' + (name === DEFAULT_STORAGE_AREA_NAME ? 'storage' : name),
dir: path.resolve(baseDir, '.node-persist', dirName),
stringify: JSON.stringify,
parse: JSON.parse,
encoding: 'utf8',
logging: false,
logging: !!process.env.DEBUG,
ttl: false,
})
_databasePromise.set(this, db.init().then(() => db))
return db.init().then(() => db);
}
function getDatabasePromise(area) {
let promise = _databasePromise.get(area);
if (!promise) {
const name = _databaseName.get(area);
promise = init(name);
_databasePromise.set(area, promise);
}
return promise;
}
class StorageArea {
constructor (name) {
init.call(this, name);
_databaseName.set(this, name);
}

@@ -90,3 +101,3 @@

const coercedKey = coerceKey(key);
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);

@@ -102,4 +113,3 @@ if (value === undefined) {

const coercedKey = coerceKey(key);
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
return await store.getItem(coercedKey);

@@ -110,3 +120,3 @@ }

const coercedKey = coerceKey(key);
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
await store.removeItem(coercedKey);

@@ -116,3 +126,3 @@ }

async clear () {
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
await store.clear()

@@ -122,3 +132,3 @@ }

async *keys () {
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
// TODO: Do in true async iterative fashion

@@ -130,3 +140,3 @@ const keys = await store.keys()

async *values () {
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
// TODO: Do in true async iterative fashion

@@ -138,3 +148,3 @@ const keys = await store.keys()

async *entries () {
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
// TODO: Do in true async iterative fashion

@@ -146,3 +156,3 @@ const keys = await store.keys()

async *[Symbol.asyncIterator]() {
const store = await _databasePromise.get(this)
const store = await getDatabasePromise(this);
// TODO: Do in true async iterative fashion

@@ -149,0 +159,0 @@ const keys = await store.keys()

{
"name": "node-kv-storage",
"version": "1.0.1",
"version": "1.1.0",
"description": "Wrapper around node-persist that conforms to the std:kv-storage interface",

@@ -5,0 +5,0 @@ "main": "index.js",

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