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

fawn

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fawn - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

12

CONTRIBUTING.md

@@ -1,4 +0,8 @@

Create a fork <br>
make your changes <br>
add tests where applicable<br>
open a pr on dev branch <br>
You might want to check out [this medium article](https://codeburst.io/fawn-transactions-in-mongodb-988d8646e564) before jumping in.
Once You're ready to go:
- Create a fork <br>
- make your changes <br>
- add tests where applicable<br>
- open a pr on dev branch <br>

@@ -25,3 +25,2 @@ "use strict";

var updateState = utils.updateState;
var getCollection = utils.getCollection;

@@ -33,2 +32,3 @@ // db utils

var getModel;
var getCollectionForStep;

@@ -49,2 +49,3 @@ /**

getModel = dbUtils.getModel;
getCollectionForStep = dbUtils.getCollectionForStep;

@@ -138,3 +139,3 @@ return Roller;

function rollbackSave(db, save, task) {
var collection = getCollection(db, save);
var collection = getCollectionForStep(db, save);
var _id = save.dataStore[0]._id;

@@ -157,3 +158,3 @@

function rollbackRemoveOrUpdate(db, step, task) {
var collection = getCollection(db, step);
var collection = getCollectionForStep(db, step);
var chain = Promise.resolve();

@@ -160,0 +161,0 @@

@@ -11,3 +11,2 @@ /**

var resolveFuture = utils.resolveFuture;
var storeOldData = utils.storeOldData;
var updateState = utils.updateState;

@@ -18,2 +17,3 @@ var xcode = utils.xcode;

var getModel;
var storeOldData;

@@ -27,2 +27,3 @@ // constants

getModel = dbUtils.getModel;
storeOldData = dbUtils.storeOldData;
};

@@ -88,3 +89,3 @@

doc._id = doc._id || utils.generateId();
doc._id = doc._id || dbUtils.generateId();
dataStore.push({_id: doc._id});

@@ -91,0 +92,0 @@

@@ -9,5 +9,11 @@ /**

var dbUtils;
var storeOldData;
exports.setDbUtils = function (_dbUtils) {
dbUtils = _dbUtils;
storeOldData = _dbUtils.storeOldData;
};
// utility functions
var resolveFuture = utils.resolveFuture;
var storeOldData = utils.storeOldData;
var updateState = utils.updateState;

@@ -74,3 +80,3 @@ var xcode = utils.xcode;

doc._id = doc._id || utils.generateId();
doc._id = doc._id || dbUtils.generateId();
step.dataStore = [{_id: doc._id}];

@@ -77,0 +83,0 @@

@@ -9,3 +9,3 @@ "use strict";

var utils = require("./utils/gen.utils");
var native = require("./task_core/native");
var native = require("./task_core/native"); //set db utils when we get them
var goose = require("./task_core/goose");

@@ -58,2 +58,3 @@

dbUtils = require("./utils/db.utils")(mongoose);
native.setDbUtils(dbUtils);
modelCache = dbUtils.modelCache;

@@ -411,3 +412,3 @@ setModel = dbUtils.setModel;

resolveFuture(options, results);
options._id = options._id || utils.generateId();
options._id = options._id || dbUtils.generateId();

@@ -494,3 +495,3 @@ step.options = options;

var collection = task.constructor.collection;
step.dataStore = [{removed: file._id, shadow: utils.generateId()}];
step.dataStore = [{removed: file._id, shadow: dbUtils.generateId()}];

@@ -497,0 +498,0 @@ collection.updateOne({_id: task._id}, task.toObject()).then(function(){

@@ -162,2 +162,47 @@ "use strict";

/**
* generates a MongoDB ObjectId
*/
function generateId(id) {
return new mongoose.Types.ObjectId(id);
}
/**
* Gets the collection for a step
*
* @param db native db
* @param step the step in question
*
* @returns native collection
*/
function getCollectionForStep(db, step){
return step.useMongoose
? mongoose.model(step.name).collection
: db.collection(step.name)
}
/**
* This function stores data that's about to be
* changed by a step, for rollback purposes
*
* @param db native db
* @param step the step
* @param condition literal obj rep of the step's condition
*
* @returns {Promise|*}
*/
function storeOldData(db, step, condition){
var Collection = getCollectionForStep(db, step);
var options = step.options
? utils.xcode(step.options)
: step.type === constants.REMOVE ? {multi: true} : null;
var query = Collection.find(condition);
var searchQuery = options && options.multi === true
? query
: query.limit(1);
return searchQuery.toArray().then(function(result){
step.dataStore = result;
});
}
return {

@@ -172,3 +217,7 @@ setModel: setModel

, makeRemoveChain: makeRemoveChain
, generateId: generateId
, getCollection: getCollection
, getCollectionForStep: getCollectionForStep
, storeOldData: storeOldData
};
};

@@ -8,3 +8,2 @@ /**

var Promise = require("bluebird");
var mongoose = require("mongoose");
var $ = constants.$PREFIX;

@@ -14,27 +13,2 @@ var DOT = constants.DOT_PREFIX;

/**
* This function stores data that's about to be
* changed by a step, for rollback purposes
*
* @param db native db
* @param step the step
* @param condition literal obj rep of the step's condition
*
* @returns {Promise|*}
*/
exports.storeOldData = function(db, step, condition){
var Collection = getCollection(db, step);
var options = step.options
? xcode(step.options)
: step.type === constants.REMOVE ? {multi: true} : null;
var query = Collection.find(condition);
var searchQuery = options && options.multi === true
? query
: query.limit(1);
return searchQuery.toArray().then(function(result){
step.dataStore = result;
});
};
/**
* Updates the state of a task's step.

@@ -254,23 +228,2 @@ *

/**
* generates a MongoDB ObjectId
*/
exports.generateId = function(id) {
return new mongoose.Types.ObjectId(id);
};
/**
* Gets the collection for a step
*
* @param db native db
* @param step the step in question
*
* @returns native collection
*/
var getCollection = exports.getCollection = function getCollection(db, step){
return step.useMongoose
? mongoose.model(step.name).collection
: db.collection(step.name)
};
{
"name": "fawn",
"version": "2.1.3",
"version": "2.1.4",
"description": "Promise based library for transactions in MongoDB",

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

@@ -31,3 +31,3 @@ "use strict";

global.TEST_FILE_NAME = "FAWN_TEST.oj";
global.TEST_FILE_ID = utils.generateId();
global.TEST_FILE_ID = global.dbUtils.generateId();

@@ -34,0 +34,0 @@ describe("ALL TESTS", function(){

@@ -82,3 +82,3 @@ /**

var gfs = Grid(mongoose.connection.db);
var id = utils.generateId();
var id = dbUtils.generateId();

@@ -96,3 +96,3 @@ return task.saveFile(TEST_FILE_PATH, {_id: id})

var gfs = Grid(mongoose.connection.db);
var id = utils.generateId();
var id = dbUtils.generateId();
var writeStream = gfs.createWriteStream({_id: id});

@@ -99,0 +99,0 @@

@@ -336,3 +336,3 @@ "use strict";

var gabe = new TestMdlB({name: "Gabe", age: 34});
var id = utils.generateId();
var id = dbUtils.generateId();

@@ -339,0 +339,0 @@ return expect(

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