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

keyv-pouchdb

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keyv-pouchdb - npm Package Compare versions

Comparing version 0.0.0-alpha.2 to 0.1.0-alpha.1

2

package.json
{
"name": "keyv-pouchdb",
"version": "0.0.0-alpha.2",
"version": "0.1.0-alpha.1",
"description": "PouchDB storage adapter for Keyv",

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

@@ -12,4 +12,6 @@ <p>

[![Build Status](https://travis-ci.com/wmik/keyv-pouchdb.svg?branch=master)](https://travis-ci.com/wmik/keyv-pouchdb)
[![Build Status](https://travis-ci.com/wmik/keyv-pouchdb.svg?branch=master)](https://travis-ci.com/wmik/keyv-pouchdb)
![npm](https://img.shields.io/npm/v/keyv-pouchdb.svg)
## Motivation

@@ -41,3 +43,3 @@ Leveraging [pouchdb-lru-cache](https://github.com/squarespace/pouchdb-lru-cache) as a [keyv-storage-adapter](https://github.com/topics/keyv-storage-adapter) that complies with the [api specs](https://github.com/lukechilds/keyv-test-suite).

database: "keyv-pouchdb-cache", // database (string | uri)
plugins: [] // plugin list
remoteConfig: {} // configuration options for remote database
}

@@ -52,11 +54,10 @@ });

*/
new Keyv("http://localhost:3000/keyv-pouchdb-cache"); // loads `pouchdb-adapter-http`
new KeyvPouchDB("http://localhost:3000/keyv-pouchdb-cache"); // loads `pouchdb-adapter-http`
/*
*
*
* or maybe even sqlite3
*
*/
new Keyv("database.db"); // loads `pouchdb-adapter-node-websql`
new KeyvPouchDB("database.db"); // loads `pouchdb-adapter-node-websql`

@@ -63,0 +64,0 @@ /****************************/

@@ -9,6 +9,2 @@ "use strict";

const loadPlugins = plugins => {
plugins.forEach(plug => PouchDB.plugin(require(plug)));
};
function dbFactory(opts) {

@@ -20,8 +16,13 @@ const adapters = {

};
const adapter = [adapters[opts.pouchDB.adapter]];
loadPlugins(adapter.concat(opts.pouchDB.plugins));
if (!Object.prototype.hasOwnProperty.call(adapters, opts.pouchDB.adapter)) {
throw new Error(`Unsupported pouchdb adapter ${opts.pouchDB.adapter}`);
}
PouchDB.plugin(require(adapters[opts.pouchDB.adapter]));
const db = new PouchDB(opts.pouchDB.database, {
[opts.pouchDB.adapter !== "http" && "adapter"]: opts.pouchDB.adapter
[opts.pouchDB.adapter !== "http" && "adapter"]: opts.pouchDB.adapter,
...(() =>
opts.pouchDB.adapter === "http" ? opts.pouchDB.remoteConfig : {})()
});

@@ -34,9 +35,15 @@ db.initLru(opts.maxCacheSize);

class KeyvPouchdb extends EventEmitter {
constructor(opts) {
constructor(opts, config = {}) {
super();
if (typeof opts === "string") {
if (opts.indexOf(".db") > -1) {
if (opts.endsWith(".db")) {
opts = { pouchDB: { database: opts, adapter: "websql" } };
} else {
opts = { pouchDB: { database: opts, adapter: "http" } };
opts = {
pouchDB: {
database: opts,
adapter: "http",
remoteConfig: { ...config }
}
};
}

@@ -49,3 +56,3 @@ }

database: "keyv-pouchdb-cache",
plugins: []
remoteConfig: {}
},

@@ -93,3 +100,4 @@ maxCacheSize: 5000000, // 5MB

const pouchdb = new PouchDB(this._opts.pouchDB.database, {
adapter: this._opts.pouchDB.adapter
[this._opts.pouchDB.adapter !== "http" && "adapter"]: this._opts.pouchDB
.adapter
});

@@ -96,0 +104,0 @@ return pouchdb.destroy().then(() => {

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