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

kuss

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kuss - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

55

lib/couchdb/index.js
const R = require('ramda')
const Bluebird = require('bluebird')
const CouchWrapper = require('./wrapper.js')
const ID = require('../identifier.js')
const Err = require('../error.js')
const R = require('ramda')
const Bluebird = require('bluebird')
const CouchWrapper = require('./wrapper.js')
const ID = require('../identifier.js')
const Err = require('../error.js')
const Util = require('../util')

@@ -87,2 +88,35 @@ const STORE = 'couchdb'

const _findOneByIdWhereEq = R.curry((couch, bucket, id, predicates) =>
getById(couch, bucket, id)
.then(R.unless(
R.allPass([Util.notNil, R.whereEq(ID.couchify(predicates))])
, R.always(null)
))
)
const _findOneWhereEq = R.curry((couch, bucket, predicates) =>
findWhereEq(
couch
, bucket
, R.objOf('predicates', ID.couchify(predicates))
)
.then(R.ifElse(
hasOnlyOne
, R.head
, R.compose(Err.TooManyRecords.throw(STORE, bucket, predicates), R.length)
))
)
const findOneWhereEq = R.curry((couch, bucket, predicates) =>
Bluebird.resolve(predicates)
.then(R.ifElse(
R.has('id')
, _findOneByIdWhereEq(couch, bucket, predicates.id)
, _findOneWhereEq(couch, bucket)
))
)
const bulk_upsert = R.curry((couch, bucket, keys, docs) =>

@@ -95,12 +129,8 @@ Bluebird.map(docs, (doc) =>

, R.always(doc)
, (predicates) => findWhereEq(
couch
, bucket
, R.objOf('predicates', ID.couchify(predicates))
)
, findOneWhereEq(couch, bucket)
))
.then(R.ifElse(
R.isEmpty
Util.isEmptyOrNil
, R.always(ID.couchify(doc))
, R.compose(ID.couchify, R.merge(R.__, doc), R.head)
, R.merge(R.__, ID.couchify(doc))
))

@@ -175,1 +205,2 @@ )

}))

@@ -47,2 +47,8 @@ /* eslint no-magic-numbers: 0 */

const notNil = R.compose(R.not, R.isNil)
const isEmptyOrNil = R.either(R.isEmpty, R.isNil)
module.exports = {

@@ -54,2 +60,4 @@ ascend

, replaceElement
, notNil
, isEmptyOrNil
}
{
"name": "kuss",
"version": "0.9.1",
"version": "0.9.2",
"description": "Combined Universal Storage Service",

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

@@ -198,3 +198,3 @@ /*eslint-env node, mocha*/

it(`should update a list of documents in the given bucket based on the
_id and _rev keys. if these two keys don't exist, create the document
_id and _rev keys. If these two keys don't exist, create the document
in the bucket`, function() {

@@ -222,2 +222,27 @@

it(`should update a list of documents in the given bucket based on the
_id and _rev keys. If these two keys don't exist, create the document
in the bucket`, function() {
return couchdb.insert(DB_NAME, { id: '1', first: 'mat', last: 'chuang' })
.then(() => couchdb.bulk_upsert(DB_NAME, ['last'], [
{ first: 'matt', last: 'chuang' }
, { first: 'jon', last: 'lee' }
]))
.then(() => couchdb.getAll(DB_NAME))
.then((res) => {
const map = R.compose(
R.mergeAll
, R.map((row) => ({ [row.doc.last] : row.doc }))
)(res.rows)
demand(res.rows).have.length(2)
demand(map['chuang'].first).equal('matt')
demand(map['lee'].first).equal('jon')
})
})
})

@@ -224,0 +249,0 @@

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