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

marsdb

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marsdb - npm Package Compare versions

Comparing version 0.5.18 to 0.5.19

.tern-project

6

dist/AsyncEventEmitter.js
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -28,3 +28,3 @@ Object.defineProperty(exports, "__esModule", {

var AsyncEventEmitter = function (_EventEmitter) {
var AsyncEventEmitter = (function (_EventEmitter) {
_inherits(AsyncEventEmitter, _EventEmitter);

@@ -118,4 +118,4 @@

return AsyncEventEmitter;
}(_eventemitter2.default);
})(_eventemitter2.default);
exports.default = AsyncEventEmitter;
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -38,3 +38,3 @@ Object.defineProperty(exports, "__esModule", {

var Base64 = exports.Base64 = function () {
var Base64 = exports.Base64 = (function () {
function Base64() {

@@ -170,4 +170,4 @@ _classCallCheck(this, Base64);

return Base64;
}();
})();
exports.default = new Base64();
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -77,3 +77,3 @@ Object.defineProperty(exports, "__esModule", {

var Collection = exports.Collection = function (_EventEmitter) {
var Collection = exports.Collection = (function (_EventEmitter) {
_inherits(Collection, _EventEmitter);

@@ -453,4 +453,4 @@

return Collection;
}(_eventemitter2.default);
})(_eventemitter2.default);
exports.default = Collection;
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Object.defineProperty(exports, "__esModule", {

@@ -33,3 +29,3 @@ value: true

var CollectionDelegate = exports.CollectionDelegate = function () {
var CollectionDelegate = exports.CollectionDelegate = (function () {
function CollectionDelegate(db) {

@@ -101,31 +97,15 @@ _classCallCheck(this, CollectionDelegate);

if (upsert && original.length && original[0] === null) {
var _ret = function () {
var newDoc = updated[0];
return {
v: _this3.db.insert(newDoc, { quiet: true }).then(function (docId) {
return {
modified: 0, original: [], updated: [],
inserted: _extends({ _id: docId }, newDoc)
};
})
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
} else {
var updateStorgePromises = (0, _map3.default)(updated, function (d) {
return _this3.db.storageManager.persist(d._id, d);
});
var updateIndexPromises = (0, _map3.default)(updated, function (d, i) {
return _this3.db.indexManager.reindexDocument(original[i], d);
});
return Promise.all([].concat(_toConsumableArray(updateStorgePromises), _toConsumableArray(updateIndexPromises))).then(function () {
return {
modified: updated.length,
original: original,
updated: updated
};
});
}
var updateStorgePromises = (0, _map3.default)(updated, function (d) {
return _this3.db.storageManager.persist(d._id, d);
});
var updateIndexPromises = (0, _map3.default)(updated, function (d, i) {
return _this3.db.indexManager.reindexDocument(original[i], d);
});
return Promise.all([].concat(_toConsumableArray(updateStorgePromises), _toConsumableArray(updateIndexPromises))).then(function () {
return {
modified: updated.length,
original: original,
updated: updated
};
});
});

@@ -173,4 +153,4 @@ }

return CollectionDelegate;
}();
})();
exports.default = CollectionDelegate;
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -18,3 +18,3 @@ Object.defineProperty(exports, "__esModule", {

var CollectionIndex = exports.CollectionIndex = function () {
var CollectionIndex = exports.CollectionIndex = (function () {
function CollectionIndex() {

@@ -73,4 +73,4 @@ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

return CollectionIndex;
}();
})();
exports.default = CollectionIndex;
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _PIPELINE_PROCESSORS;

@@ -76,2 +74,4 @@

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -162,3 +162,3 @@

var Cursor = function (_AsyncEventEmitter) {
var Cursor = (function (_AsyncEventEmitter) {
_inherits(Cursor, _AsyncEventEmitter);

@@ -448,5 +448,5 @@

return Cursor;
}(_AsyncEventEmitter3.default);
})(_AsyncEventEmitter3.default);
exports.Cursor = Cursor;
exports.default = Cursor;
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -61,3 +61,3 @@ var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };

var CursorObservable = function (_Cursor) {
var CursorObservable = (function (_Cursor) {
_inherits(CursorObservable, _Cursor);

@@ -366,5 +366,5 @@

return CursorObservable;
}(_Cursor3.default);
})(_Cursor3.default);
exports.CursorObservable = CursorObservable;
exports.default = CursorObservable;

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

var doNotResolve = true;
var _maybeResolve = null;
var maybeResolve = null;

@@ -31,5 +31,5 @@ var debouncer = function debouncer() {

promise = new Promise(function (resolve, reject) {
_maybeResolve = function maybeResolve() {
maybeResolve = function () {
if (doNotResolve) {
timeout = setTimeout(_maybeResolve, wait);
timeout = setTimeout(maybeResolve, wait);
doNotResolve = false;

@@ -42,6 +42,6 @@ } else {

doNotResolve = true;
_maybeResolve = null;
maybeResolve = null;
}
};
_maybeResolve();
maybeResolve();
});

@@ -52,7 +52,7 @@ } else {

if (callNow && _maybeResolve) {
if (callNow && maybeResolve) {
var returnPromise = promise;
returnPromise.debouncePassed = true;
clearTimeout(timeout);
_maybeResolve();
maybeResolve();
callsCount += 1;

@@ -59,0 +59,0 @@ return returnPromise;

@@ -12,3 +12,2 @@ 'use strict';

exports.isIndexable = isIndexable;
exports.removeDollarOperators = removeDollarOperators;
exports.isOperatorObject = isOperatorObject;

@@ -49,5 +48,2 @@ exports.isNumericKey = isNumericKey;

// Like _isArray, but doesn't regard polyfilled Uint8Arrays on old browsers as
// arrays.
// XXX maybe this should be EJSON.isArray
function isArray(x) {

@@ -57,5 +53,2 @@ return _checkTypes2.default.array(x) && !_EJSON2.default.isBinary(x);

// XXX maybe this should be EJSON.isObject, though EJSON doesn't know about
// RegExp
// XXX note that _type(undefined) === 3!!!!
function isPlainObject(x) {

@@ -69,13 +62,2 @@ return x && MongoTypeComp._type(x) === 3;

// Oddball function used by upsert.
function removeDollarOperators(selector) {
var selectorDoc = {};
for (var k in selector) {
if (k.substr(0, 1) !== '$') {
selectorDoc[k] = selector[k];
}
}
return selectorDoc;
}
// Returns true if this is an object with at least one key and all keys begin

@@ -82,0 +64,0 @@ // with $. Unless inconsistentOK is set, throws if some keys begin with $ and

'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Object.defineProperty(exports, "__esModule", {

@@ -56,2 +54,4 @@ value: true

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

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

var DocumentMatcher = exports.DocumentMatcher = function () {
var DocumentMatcher = exports.DocumentMatcher = (function () {
function DocumentMatcher(selector) {

@@ -189,3 +189,3 @@ _classCallCheck(this, DocumentMatcher);

return DocumentMatcher;
}();
})();

@@ -524,3 +524,3 @@ exports.default = DocumentMatcher;

point = operand.$geometry;
distance = function distance(value) {
distance = function (value) {
// XXX: for now, we don't calculate the actual distance between, say,

@@ -544,3 +544,3 @@ // polygon and circle. If people care about this use-case it will get

point = pointToArray(operand);
distance = function distance(value) {
distance = function (value) {
if (!(0, _Document.isArray)(value) && !(0, _Document.isPlainObject)(value)) {

@@ -547,0 +547,0 @@ return null;

'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Object.defineProperty(exports, "__esModule", {

@@ -32,2 +30,6 @@ value: true

var _Random = require('./Random');
var _Random2 = _interopRequireDefault(_Random);
var _DocumentMatcher = require('./DocumentMatcher');

@@ -45,5 +47,7 @@

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DocumentModifier = exports.DocumentModifier = function () {
var DocumentModifier = exports.DocumentModifier = (function () {
function DocumentModifier() {

@@ -60,5 +64,6 @@ var query = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

key: 'modify',
value: function modify(docs, mod) {
value: function modify(docs) {
var _this = this;
var mod = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

@@ -69,2 +74,3 @@

// Regular update
(0, _forEach2.default)(docs, function (d) {

@@ -80,4 +86,6 @@ var match = _this._matcher.documentMatches(d);

if (!docs.length && options.upsert) {
var newDoc = (0, _Document.removeDollarOperators)(this._query);
// Upsert update
if (!newResults.length && options.upsert) {
var newDoc = documentBySelector(this._query);
newDoc._id = newDoc._id || _Random2.default.default().id(17);
newDoc = this._modifyDocument(newDoc, mod, { isInsert: true });

@@ -122,3 +130,3 @@ newResults.push(newDoc);

if (!isModifier) {
if (mod._id && !_EJSON2.default.equals(doc._id, mod._id)) {
if (!options.isInsert && mod._id && !_EJSON2.default.equals(doc._id, mod._id)) {
throw new Error('Cannot change the _id of a document');

@@ -152,5 +160,4 @@ }

}
if (keypath === '_id') {
throw new Error('Mod on _id not allowed');
if (keypath === '_id' && !options.isInsert) {
throw new Error('Mod on _id not allowed for update.');
}

@@ -182,6 +189,23 @@

return DocumentModifier;
}();
})();
exports.default = DocumentModifier;
// by given selector returns an object that should
// be used for upsert operation
var documentBySelector = function documentBySelector(selector) {
var selectorDoc = {};
(0, _forEach2.default)(selector, function (v, k) {
if (k.substr(0, 1) !== '$' && !(0, _Document.isOperatorObject)(v, true)) {
var keyparts = k.split('.');
var modTarget = findModTarget(selectorDoc, keyparts);
if (modTarget) {
modTarget[keyparts[keyparts.length - 1]] = v;
}
}
});
return selectorDoc;
};
// for a.b.c.2.d.e, keyparts should be ['a', 'b', 'c', '2', 'd', 'e'],

@@ -204,3 +228,2 @@ // and then you would operate on the 'e' property of the returned

// the path.
var findModTarget = function findModTarget(doc, keyparts, options) {

@@ -207,0 +230,0 @@ options = options || {};

'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Object.defineProperty(exports, "__esModule", {

@@ -58,2 +56,4 @@ value: true

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

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

var DocumentProjector = function () {
var DocumentProjector = (function () {
function DocumentProjector(fields) {

@@ -95,3 +95,3 @@ _classCallCheck(this, DocumentProjector);

return DocumentProjector;
}();
})();

@@ -98,0 +98,0 @@ // Knows how to compile a fields projection to a predicate function.

'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -36,3 +36,3 @@ Object.defineProperty(exports, "__esModule", {

var DocumentRetriver = exports.DocumentRetriver = function () {
var DocumentRetriver = exports.DocumentRetriver = (function () {
function DocumentRetriver(db) {

@@ -148,4 +148,4 @@ _classCallCheck(this, DocumentRetriver);

return DocumentRetriver;
}();
})();
exports.default = DocumentRetriver;
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Object.defineProperty(exports, "__esModule", {

@@ -44,2 +42,4 @@ value: true

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -60,3 +60,3 @@

var DocumentSorter = exports.DocumentSorter = function () {
var DocumentSorter = exports.DocumentSorter = (function () {
function DocumentSorter(spec) {

@@ -475,3 +475,3 @@ var _this = this;

return DocumentSorter;
}();
})();

@@ -478,0 +478,0 @@ exports.default = DocumentSorter;

'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /**
* Based on Meteor's EJSON package.
* Rewrite with ES6 and better formated for passing
* linter
*/
Object.defineProperty(exports, "__esModule", {

@@ -40,2 +34,8 @@ value: true

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } /**
* Based on Meteor's EJSON package.
* Rewrite with ES6 and better formated for passing
* linter
*/
// Internal utils

@@ -55,3 +55,3 @@ function _isNaN(val) {

var EJSON = exports.EJSON = function () {
var EJSON = exports.EJSON = (function () {
// @ngInject

@@ -567,4 +567,4 @@

return EJSON;
}();
})();
exports.default = new EJSON();
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -54,3 +54,3 @@ Object.defineProperty(exports, "__esModule", {

var IndexManager = exports.IndexManager = function () {
var IndexManager = exports.IndexManager = (function () {
function IndexManager(db) {

@@ -273,4 +273,4 @@ var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

return IndexManager;
}();
})();
exports.default = IndexManager;
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -29,3 +29,3 @@ Object.defineProperty(exports, "__esModule", {

var PromiseQueue = function () {
var PromiseQueue = (function () {
function PromiseQueue() {

@@ -148,4 +148,4 @@ var maxPendingPromises = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0];

return PromiseQueue;
}();
})();
exports.default = PromiseQueue;
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Object.defineProperty(exports, "__esModule", {

@@ -22,2 +20,4 @@ value: true

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -60,3 +60,3 @@

return function (args) {
return (function (args) {
var s0 = 0;

@@ -106,3 +106,3 @@ var s1 = 0;

return random;
}(Array.prototype.slice.call(arguments));
})(Array.prototype.slice.call(arguments));
};

@@ -129,3 +129,3 @@

var Random = function () {
var Random = (function () {
function Random(type) {

@@ -166,3 +166,3 @@ var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

if (this.type === RANDOM_GENERATOR_TYPE.NODE_CRYPTO) {
var _ret = function () {
var _ret = (function () {
var nodeCrypto = require('crypto');

@@ -186,3 +186,3 @@ var numBytes = Math.ceil(digits / 2);

};
}();
})();

@@ -259,5 +259,5 @@ if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;

return Random;
}();
})();
exports.default = Random;
exports.default = Random;
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -37,3 +37,3 @@ Object.defineProperty(exports, "__esModule", {

var StorageManager = exports.StorageManager = function () {
var StorageManager = exports.StorageManager = (function () {
function StorageManager(db) {

@@ -129,4 +129,4 @@ var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

return StorageManager;
}();
})();
exports.default = StorageManager;

@@ -50,24 +50,16 @@ import _map from 'fast.js/map';

}).then(({original, updated}) => {
if (upsert && original.length && original[0] === null) {
const newDoc = updated[0];
return this.db.insert(newDoc, {quiet: true}).then((docId) => ({
modified: 0, original: [], updated: [],
inserted: {_id: docId, ...newDoc},
}));
} else {
const updateStorgePromises = _map(updated, d =>
this.db.storageManager.persist(d._id, d)
);
const updateIndexPromises = _map(updated, (d, i) =>
this.db.indexManager.reindexDocument(original[i], d)
);
return Promise.all([
...updateStorgePromises,
...updateIndexPromises,
]).then(() => ({
modified: updated.length,
original: original,
updated: updated,
}));
}
const updateStorgePromises = _map(updated, d =>
this.db.storageManager.persist(d._id, d)
);
const updateIndexPromises = _map(updated, (d, i) =>
this.db.indexManager.reindexDocument(original[i], d)
);
return Promise.all([
...updateStorgePromises,
...updateIndexPromises,
]).then(() => ({
modified: updated.length,
original: original,
updated: updated,
}));
});

@@ -74,0 +66,0 @@ }

@@ -29,5 +29,2 @@ import _check from 'check-types';

// Like _isArray, but doesn't regard polyfilled Uint8Arrays on old browsers as
// arrays.
// XXX maybe this should be EJSON.isArray
export function isArray(x) {

@@ -37,5 +34,2 @@ return _check.array(x) && !EJSON.isBinary(x);

// XXX maybe this should be EJSON.isObject, though EJSON doesn't know about
// RegExp
// XXX note that _type(undefined) === 3!!!!
export function isPlainObject(x) {

@@ -49,13 +43,2 @@ return x && MongoTypeComp._type(x) === 3;

// Oddball function used by upsert.
export function removeDollarOperators(selector) {
var selectorDoc = {};
for (var k in selector) {
if (k.substr(0, 1) !== '$') {
selectorDoc[k] = selector[k];
}
}
return selectorDoc;
}
// Returns true if this is an object with at least one key and all keys begin

@@ -62,0 +45,0 @@ // with $. Unless inconsistentOK is set, throws if some keys begin with $ and

@@ -6,6 +6,7 @@ import _check from 'check-types';

import EJSON from './EJSON';
import Random from './Random';
import DocumentMatcher from './DocumentMatcher';
import DocumentSorter from './DocumentSorter';
import {isPlainObject, isIndexable, isOperatorObject,
isNumericKey, MongoTypeComp, removeDollarOperators} from './Document';
isNumericKey, MongoTypeComp} from './Document';

@@ -19,6 +20,7 @@

modify(docs, mod, options = {}) {
modify(docs, mod = {}, options = {}) {
const oldResults = [];
const newResults = [];
// Regular update
_each(docs, (d) => {

@@ -37,4 +39,6 @@ const match = this._matcher.documentMatches(d);

if (!docs.length && options.upsert) {
let newDoc = removeDollarOperators(this._query);
// Upsert update
if (!newResults.length && options.upsert) {
let newDoc = documentBySelector(this._query);
newDoc._id = newDoc._id || Random.default().id(17);
newDoc = this._modifyDocument(newDoc, mod, {isInsert: true});

@@ -74,3 +78,3 @@ newResults.push(newDoc);

if (!isModifier) {
if (mod._id && !EJSON.equals(doc._id, mod._id)) {
if (!options.isInsert && mod._id && !EJSON.equals(doc._id, mod._id)) {
throw new Error('Cannot change the _id of a document');

@@ -105,5 +109,4 @@ }

}
if (keypath === '_id') {
throw new Error('Mod on _id not allowed');
if (keypath === '_id' && !options.isInsert) {
throw new Error('Mod on _id not allowed for update.');
}

@@ -136,2 +139,20 @@

// by given selector returns an object that should
// be used for upsert operation
var documentBySelector = function(selector) {
var selectorDoc = {};
_each(selector, (v, k) => {
if (k.substr(0, 1) !== '$' && !isOperatorObject(v, true)) {
const keyparts = k.split('.');
const modTarget = findModTarget(selectorDoc, keyparts);
if (modTarget) {
modTarget[keyparts[keyparts.length - 1]] = v;
}
}
});
return selectorDoc;
};
// for a.b.c.2.d.e, keyparts should be ['a', 'b', 'c', '2', 'd', 'e'],

@@ -138,0 +159,0 @@ // and then you would operate on the 'e' property of the returned

{
"name": "marsdb",
"version": "0.5.18",
"version": "0.5.19",
"author": {

@@ -5,0 +5,0 @@ "name": "Artem Artemev",

@@ -368,25 +368,2 @@ import {Document} from '../../lib/Document';

it('should insert document if it is not exists with updasert', function () {
const db = new Collection('test');
const testUpsert = (query, mod, expected) => {
return db.remove({}, {multi: true}).then(() => {
return db.update(query, mod, {upsert: true}).then((res) => {
res.modified.should.be.equals(0);
res.original.should.be.deep.equals([]);
res.updated.should.be.deep.equals([]);
expect(res.inserted._id).to.have.length(17);
delete res.inserted._id;
res.inserted.should.be.deep.equals(expected);
});
});
}
return Promise.all([
testUpsert({a: 2}, {$set: {b: 3}}, {a: 2, b: 3}),
testUpsert({a: 2}, {b: 3}, {b: 3}),
testUpsert({a: 2}, {$unset: {a: 1}}, {}),
testUpsert({a: 2}, {$setOnInsert: {a: 1}}, {a: 1}),
]);
});
it('should update by primitive id type', function () {

@@ -408,2 +385,32 @@ const db = new Collection('test');

describe('#update - upsert', function () {
const db = new Collection('test');
const testUpsert = (query, mod, expected, expectedId) => {
it(`should upsert with ${JSON.stringify(query)} ${JSON.stringify(mod)},\n\textected ${JSON.stringify(expected)}`, function() {
return db.remove({}, {multi: true}).then(() => {
return db.update(query, mod, {upsert: true}).then((res) => {
res.modified.should.be.equals(1);
res.original.should.be.deep.equals([null]);
res.updated.should.have.length(1);
if (expectedId) {
res.updated[0]._id.should.be.equal(expectedId);
} else {
expect(res.updated[0]._id).to.have.length(17);
}
delete res.updated[0]._id;
res.updated[0].should.be.deep.equals(expected);
});
});
});
};
testUpsert({a: 2}, {$set: {b: 3}}, {a: 2, b: 3})
testUpsert({'a.b.c': 2}, {$set: {b: 3}}, {a: {b: {c: 2}}, b: 3})
testUpsert({'a.b.c': 2, _id: {$in: [1,2,3]}}, {$set: {b: 3}}, {a: {b: {c: 2}}, b: 3})
testUpsert({'a.b.c': 2, _id: 123}, {$set: {b: 3}}, {a: {b: {c: 2}}, b: 3}, 123)
testUpsert({a: 2}, {b: 3}, {b: 3})
testUpsert({a: 2}, {$unset: {a: 1}}, {})
testUpsert({a: 2, _id: '123'}, {$setOnInsert: {a: 1, _id: '123'}}, {a: 1}, '123');
});
describe('#findOne', function () {

@@ -534,2 +541,2 @@ it('should find only one document', function () {

});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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