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.2.0 to 0.2.1

lib/couchdb/driver.js

47

lib/couchdb/index.js
const R = require('ramda')
const R = require('ramda')
const assert = require('assert')
const Facade = require('./facade.js')
/**
* A configured nano connection is required to use this store.
*/
function Couch(nano) {
const requireField = R.curry((field, doc) =>
assert(doc.hasOwnProperty(field), `${field} is required`)
)
module.exports = function CouchStore(nano) {
const insert = R.curry((bucket, doc) => R.compose(
Facade.insert(nano, bucket)
, R.tap(requireField('id'))
)(doc))
const upsert = R.curry((bucket, keys, data) => R.compose(
insert(nano, bucket)
, R.tap(requireField('_rev')
)(data)))
const getById = Facade.get(nano)
const getAll = (bucket) => Facade.list(nano, bucket, {})
const projectAll = R.curry((bucket, projection) =>
getAll.map(R.pick(projection))
)
return {
insert
, upsert
, getById
, getAll
, projectAll
}
}

20

lib/error.js
//eslint-disable-next-line max-len
//@see http://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax
const STATUS_CODE_ERROR = 500
class CussError extends Error {
constructor(message, status=500) {
constructor(message, status=STATUS_CODE_ERROR) {
super(message)
this.name = this.constructor.name;
this.message = message;
this.status = status;
this.name = this.constructor.name
this.message = message
this.status = status
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
if ('function' === typeof Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor)
} else {
this.stack = (new Error(message)).stack;
this.stack = (new Error(message)).stack
}

@@ -29,3 +33,3 @@ }

super(message, 500);
super(message, STATUS_CODE_ERROR)
}

@@ -32,0 +36,0 @@ }

const R = require('ramda');
const Bluebird = require('bluebird');
const uuid = require('uuid');
const Err = require('../error.js');
const R = require('ramda')
const Bluebird = require('bluebird')
const uuid = require('uuid')
const Err = require('../error.js')
//const QueryRouter = require('../query-router.js')
const ONE = 1
const TWO = 2
const throwInvalidBucket = (bucket) => {
throw new Error(`Invalid Bucket: ${bucket}`);
};
throw new Error(`Invalid Bucket: ${bucket}`)
}
const throwItemNotFound = (bucket, id) => {
throw new Error(`Item ID#${id} Not Found in bucket: ${bucket}`);
};
throw new Error(`Item ID#${id} Not Found in bucket: ${bucket}`)
}
const missingBucket = R.curryN(2, R.compose(R.not, R.flip(R.has)));
const missingBucket = R.curryN(TWO, R.compose(R.not, R.flip(R.has)))
const assertBucket = R.curry((store, bucket) =>
const assertBucket = R.curry((store, bucket) =>
R.when(missingBucket(store), throwInvalidBucket)(bucket)
);
)

@@ -29,27 +32,27 @@

const store = R.defaultTo({}, data_set);
const store = R.defaultTo({}, data_set)
const getBucket = (bucket) => {
assertBucket(store, bucket);
assertBucket(store, bucket)
return R.prop(bucket, store);
};
return R.prop(bucket, store)
}
const getById = R.curry((bucket, id) => {
assertBucket(store, bucket);
assertBucket(store, bucket)
return Bluebird.resolve(store[bucket][id]);
});
return Bluebird.resolve(store[bucket][id])
})
const insert = R.curry((bucket, data) => {
data.id = uuid.v4();
data.id = uuid.v4()
if (!R.has(bucket, store)) store[bucket] = {};
if (!R.has(bucket, store)) store[bucket] = {}
store[bucket][data.id] = data;
store[bucket][data.id] = data
return Bluebird.resolve(data.id);
});
return Bluebird.resolve(data.id)
})

@@ -67,3 +70,3 @@

);
)

@@ -77,3 +80,3 @@

, R.compose(Bluebird.resolve, R.prop(R.__, store))
)(bucket));
)(bucket))

@@ -90,6 +93,6 @@

);
)
const getAll = R.compose(Bluebird.resolve, R.values, getBucket);
const getAll = R.compose(Bluebird.resolve, R.values, getBucket)

@@ -103,7 +106,7 @@

const projectAll = R.curry((bucket, projection) =>
getAll(bucket).map(R.pick(projection)));
getAll(bucket).map(R.pick(projection)))
const findBy = R.curry((bucket, projection, prop, value) =>
projectAll(bucket, projection).filter(R.propEq(prop, value)));
projectAll(bucket, projection).filter(R.propEq(prop, value)))

@@ -115,19 +118,16 @@

.tap((results) => {
if (results.length > 1)
if (ONE < results.length)
throw new Err.TooManyRecords(
bucket, prop, value, results.length
);
)
})
.then(R.head));
.then(R.head))
const findById = R.curry((bucket, projection, id) => {
return getById(bucket, id)
.then(R.pick(projection))
const findById = R.curry((bucket, projection, id) =>
getById(bucket, id).then(R.pick(projection))
)
});
return {

@@ -143,3 +143,3 @@ insert

, findWhere
};
}

@@ -146,0 +146,0 @@ }

@@ -39,3 +39,4 @@

const maxOneRecord = (table, field, value) => (results) => {
if (results.length > 1)
//eslint-disable-next-line no-magic-numbers
if (1 < results.length)
throw new Err.TooManyRecords(table, field, value, results.length)

@@ -68,3 +69,3 @@ }

+ `ON DUPLICATE KEY UPDATE ${updates}`
const update_params = withoutId(params);
const update_params = withoutId(params)

@@ -71,0 +72,0 @@ return Query.runNoCache(mysql, sql, update_params)

@@ -9,4 +9,6 @@

conn.createConfirmChannel()
Bluebird.resolve(conn)
.then(connection => connection.createConfirmChannel())
.then((channel) => new Bluebird( function(resolve, reject) {

@@ -13,0 +15,0 @@

{
"name": "kuss",
"version": "0.2.0",
"version": "0.2.1",
"description": "Combined Universal Storage Service",

@@ -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