Socket
Socket
Sign inDemoInstall

effects-as-data-mongo

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effects-as-data-mongo - npm Package Compare versions

Comparing version 1.2.2 to 1.3.2

15

package.json
{
"name": "effects-as-data-mongo",
"version": "1.2.2",
"version": "1.3.2",
"description": "Effects-as-data for mongo",

@@ -12,4 +12,4 @@ "main": "src/index.js",

"test": "jest",
"precommit": "standard; npm test && uver && git add -A",
"deploy": "standard && npm test",
"precommit": "npm test && uver && git add -A",
"deploy": "npm test",
"publish-please": "publish-please",

@@ -31,13 +31,4 @@ "prepublish": "publish-please guard"

"sinon": "^1.17.7",
"standard": "^8.6.0",
"uver-cli": "^1.1.0"
},
"standard": {
"globals": [
"describe",
"test",
"it",
"fail"
]
}
}

29

src/actions.js

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

function mongoInsert (collection, doc) {
function mongoInsert(collection, doc) {
return {

@@ -7,6 +7,6 @@ type: 'mongo',

doc
}
};
}
function mongoUpsert (collection, doc, query) {
function mongoUpsert(collection, doc, query) {
return {

@@ -18,6 +18,6 @@ type: 'mongo',

query
}
};
}
function mongoFindOne (collection, query) {
function mongoFindOne(collection, query) {
return {

@@ -28,6 +28,6 @@ type: 'mongo',

query
}
};
}
function mongoFind (collection, query, options = {}) {
function mongoFind(collection, query, options = {}) {
return {

@@ -40,5 +40,13 @@ type: 'mongo',

limit: options.perPage || 25
}
};
}
function mongoDropCollection(collection) {
return {
type: 'mongo',
fn: 'dropCollection',
collection
};
}
module.exports = {

@@ -48,3 +56,4 @@ mongoInsert,

mongoFindOne,
mongoFind
}
mongoFind,
mongoDropCollection
};

@@ -1,27 +0,30 @@

const { curry } = require('ramda')
const { safecb } = require('safe-errors')
const { isFailure, normalizeToSuccess } = require('simple-protocol-helpers')
const { curry } = require('ramda');
const { safecb } = require('safe-errors');
const { isFailure, normalizeToSuccess } = require('simple-protocol-helpers');
function mongoHandler (mongo, action) {
let collection
let update
function mongoHandler(mongo, action) {
let collection;
let update;
switch (action.fn) {
case 'insert':
collection = mongo.collection(action.collection)
return safecb(collection.insert, collection)(action.doc)
collection = mongo.collection(action.collection);
return safecb(collection.insert, collection)(action.doc);
case 'upsert':
collection = mongo.collection(action.collection)
update = safecb(collection.update, collection)
return update(action.query || { guid: action.doc.guid }, action.doc, { upsert: true, multi: false })
collection = mongo.collection(action.collection);
update = safecb(collection.update, collection);
return update(action.query || { guid: action.doc.guid }, action.doc, {
upsert: true,
multi: false
});
case 'findOne':
collection = mongo.collection(action.collection)
return safecb(collection.findOne, collection)(action.query)
collection = mongo.collection(action.collection);
return safecb(collection.findOne, collection)(action.query);
case 'find':
const limit = action.limit || 25
const skip = (action.page || 0) * limit
collection = mongo.collection(action.collection)
const limit = action.limit || 25;
const skip = (action.page || 0) * limit;
collection = mongo.collection(action.collection);

@@ -31,26 +34,35 @@ const resultsQuery = safecb(collection.find, collection)(action.query, {

skip
}).then((r) => r.payload.toArray())
.then(normalizeToSuccess)
})
.then(r => r.payload.toArray())
.then(normalizeToSuccess);
const totalQuery = safecb(collection.count, collection)(action.query)
const totalQuery = safecb(collection.count, collection)(action.query);
return Promise.all([resultsQuery, totalQuery])
.then(([results, total]) => {
if (isFailure(results)) return results
if (isFailure(total)) return total
return Promise.all([
resultsQuery,
totalQuery
]).then(([results, total]) => {
if (isFailure(results)) return results;
if (isFailure(total)) return total;
return {
results: results.payload,
total: total.payload
}
})
};
});
case 'dropCollection':
collection = mongo.collection(action.collection);
return safecb(collection.drop, collection)();
default:
return Promise.reject(`function "${action.fn}" not available for mongo handler.`)
return Promise.reject(
`function "${action.fn}" not available for mongo handler.`
);
}
}
module.exports = (mongo) => {
module.exports = mongo => {
return {
mongo: curry(mongoHandler)(mongo)
}
}
};
};
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