New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dexie-batch

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dexie-batch - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

158

dist/dexie-batch.js

@@ -1,77 +0,79 @@

/*! dexie-batch v0.4.1 | github.com/raphinesse/dexie-batch | MIT License */
/*! dexie-batch v0.4.2 | github.com/raphinesse/dexie-batch | MIT License */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('dexie')) :
typeof define === 'function' && define.amd ? define(['dexie'], factory) :
(global.DexieBatch = factory(global.Dexie));
}(this, (function (dexie) { 'use strict';
(global = global || self, global.DexieBatch = factory(global.Dexie));
}(this, function (dexie) { 'use strict';
dexie = dexie && dexie.hasOwnProperty('default') ? dexie['default'] : dexie;
var classCallCheck = function (instance, Constructor) {
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
}
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);
}
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;
};
}();
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
if (!_n && _i["return"] != null) _i["return"]();
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
if (_d) throw _e;
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
return _arr;
}
var Promise$1 = dexie.Promise;
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
var dexieBatch = function () {
/* eslint-disable prefer-rest-params */
var Promise = dexie.Promise;
var dexieBatch =
/*#__PURE__*/
function () {
function DexieBatch(opts) {
classCallCheck(this, DexieBatch);
_classCallCheck(this, DexieBatch);

@@ -82,4 +84,4 @@ assertValidOptions(opts);

createClass(DexieBatch, [{
key: 'isParallel',
_createClass(DexieBatch, [{
key: "isParallel",
value: function isParallel() {

@@ -89,11 +91,10 @@ return Boolean(this.opts.limit);

}, {
key: 'each',
key: "each",
value: function each(collection, callback) {
var _this = this;
assertValidMethodArgs.apply(undefined, arguments);
assertValidMethodArgs.apply(void 0, arguments);
return this.eachBatch(collection, function (batch, batchIdx) {
var baseIdx = batchIdx * _this.opts.batchSize;
return Promise$1.all(batch.map(function (item, i) {
return Promise.all(batch.map(function (item, i) {
return callback(item, baseIdx + i);

@@ -104,6 +105,5 @@ }));

}, {
key: 'eachBatch',
key: "eachBatch",
value: function eachBatch(collection, callback) {
assertValidMethodArgs.apply(undefined, arguments);
assertValidMethodArgs.apply(void 0, arguments);
var delegate = this.isParallel() ? 'eachBatchParallel' : 'eachBatchSerial';

@@ -113,5 +113,6 @@ return this[delegate](collection, callback);

}, {
key: 'eachBatchParallel',
key: "eachBatchParallel",
value: function eachBatchParallel(collection, callback) {
assertValidMethodArgs.apply(undefined, arguments);
assertValidMethodArgs.apply(void 0, arguments);
if (!this.opts.limit) {

@@ -134,3 +135,4 @@ throw new Error('Option "limit" must be set for parallel operation');

}
return Promise$1.all(batchPromises).then(function (batches) {
return Promise.all(batchPromises).then(function (batches) {
return batches.length;

@@ -140,3 +142,3 @@ });

}, {
key: 'eachBatchSerial',
key: "eachBatchSerial",
value: function eachBatchSerial(collection, callback) {

@@ -146,14 +148,12 @@ var _this2 = this;

var batchIdx = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
assertValidMethodArgs.apply(undefined, arguments);
assertValidMethodArgs.apply(void 0, arguments);
var batchSize = this.opts.batchSize;
return collection.clone().limit(batchSize).toArray().then(function (batch) {
if (batch.length === 0) return 0;
var userPromise = callback(batch, batchIdx);
var userPromise = callback(batch, batchIdx);
var nextBatchesPromise = _this2.eachBatchSerial(collection.clone().offset(batchSize), callback, batchIdx + 1);
return Promise$1.all([userPromise, nextBatchesPromise]).then(function (_ref) {
var _ref2 = slicedToArray(_ref, 2),
return Promise.all([userPromise, nextBatchesPromise]).then(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
batchCount = _ref2[1];

@@ -166,2 +166,3 @@

}]);
return DexieBatch;

@@ -172,2 +173,3 @@ }();

var batchSize = opts && opts.batchSize;
if (!(batchSize && Number.isInteger(batchSize) && batchSize > 0)) {

@@ -186,13 +188,15 @@ throw new Error('Mandatory option "batchSize" must be a positive integer');

}
if (!isCollectionInstance(collection)) {
throw new Error('"collection" must be of type Collection');
}
if (!(typeof callback === 'function')) {
throw new TypeError('"callback" must be a function');
}
}
// We would need the Dexie instance that created the collection to get the
} // We would need the Dexie instance that created the collection to get the
// Collection constructor and do some proper type checking.
// So for now we resort to duck typing
function isCollectionInstance(obj) {

@@ -207,3 +211,3 @@ if (!obj) return false;

})));
}));
//# sourceMappingURL=dexie-batch.js.map

@@ -1,3 +0,3 @@

/*! dexie-batch v0.4.1 | github.com/raphinesse/dexie-batch | MIT License */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("dexie")):"function"==typeof define&&define.amd?define(["dexie"],e):t.DexieBatch=e(t.Dexie)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},n=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),r=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var a,l=t[Symbol.iterator]();!(r=(a=l.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&l.return&&l.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=t.Promise;function o(t,e){if(arguments.length<2)throw new Error('Arguments "collection" and "callback" are mandatory');if(!(n=t)||!["clone","offset","limit","toArray"].every(function(t){return"function"==typeof n[t]}))throw new Error('"collection" must be of type Collection');var n;if("function"!=typeof e)throw new TypeError('"callback" must be a function')}return function(){function t(n){e(this,t),function(t){var e=t&&t.batchSize;if(!(e&&Number.isInteger(e)&&e>0))throw new Error('Mandatory option "batchSize" must be a positive integer');if("limit"in t&&!(Number.isInteger(t.limit)&&t.limit>=0))throw new Error('Option "limit" must be a non-negative integer')}(n),this.opts=n}return n(t,[{key:"isParallel",value:function(){return Boolean(this.opts.limit)}},{key:"each",value:function(t,e){var n=this;return o.apply(void 0,arguments),this.eachBatch(t,function(t,r){var o=r*n.opts.batchSize;return i.all(t.map(function(t,n){return e(t,o+n)}))})}},{key:"eachBatch",value:function(t,e){return o.apply(void 0,arguments),this[this.isParallel()?"eachBatchParallel":"eachBatchSerial"](t,e)}},{key:"eachBatchParallel",value:function(t,e){if(o.apply(void 0,arguments),!this.opts.limit)throw new Error('Option "limit" must be set for parallel operation');for(var n=this.opts.batchSize,r=[],a=function(i){var o=t.clone().offset(i*n).limit(n).toArray().then(function(t){return e(t,i)});r.push(o)},l=0;l*n<this.opts.limit;l++)a(l);return i.all(r).then(function(t){return t.length})}},{key:"eachBatchSerial",value:function(t,e){var n=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;o.apply(void 0,arguments);var l=this.opts.batchSize;return t.clone().limit(l).toArray().then(function(o){if(0===o.length)return 0;var u=e(o,a),c=n.eachBatchSerial(t.clone().offset(l),e,a+1);return i.all([u,c]).then(function(t){return r(t,2)[1]+1})})}}]),t}()});
/*! dexie-batch v0.4.2 | github.com/raphinesse/dexie-batch | MIT License */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("dexie")):"function"==typeof define&&define.amd?define(["dexie"],e):(t=t||self).DexieBatch=e(t.Dexie)}(this,function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,i=!1,o=void 0;try{for(var a,l=t[Symbol.iterator]();!(r=(a=l.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==l.return||l.return()}finally{if(i)throw o}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=(t=t&&t.hasOwnProperty("default")?t.default:t).Promise;function i(t,e){if(arguments.length<2)throw new Error('Arguments "collection" and "callback" are mandatory');if(!(n=t)||!["clone","offset","limit","toArray"].every(function(t){return"function"==typeof n[t]}))throw new Error('"collection" must be of type Collection');var n;if("function"!=typeof e)throw new TypeError('"callback" must be a function')}return function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),function(t){var e=t&&t.batchSize;if(!(e&&Number.isInteger(e)&&e>0))throw new Error('Mandatory option "batchSize" must be a positive integer');if("limit"in t&&!(Number.isInteger(t.limit)&&t.limit>=0))throw new Error('Option "limit" must be a non-negative integer')}(e),this.opts=e}var o,a,l;return o=t,(a=[{key:"isParallel",value:function(){return Boolean(this.opts.limit)}},{key:"each",value:function(t,e){var n=this;return i.apply(void 0,arguments),this.eachBatch(t,function(t,i){var o=i*n.opts.batchSize;return r.all(t.map(function(t,n){return e(t,o+n)}))})}},{key:"eachBatch",value:function(t,e){return i.apply(void 0,arguments),this[this.isParallel()?"eachBatchParallel":"eachBatchSerial"](t,e)}},{key:"eachBatchParallel",value:function(t,e){if(i.apply(void 0,arguments),!this.opts.limit)throw new Error('Option "limit" must be set for parallel operation');for(var n=this.opts.batchSize,o=[],a=function(r){var i=t.clone().offset(r*n).limit(n).toArray().then(function(t){return e(t,r)});o.push(i)},l=0;l*n<this.opts.limit;l++)a(l);return r.all(o).then(function(t){return t.length})}},{key:"eachBatchSerial",value:function(t,e){var o=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;i.apply(void 0,arguments);var l=this.opts.batchSize;return t.clone().limit(l).toArray().then(function(i){if(0===i.length)return 0;var u=e(i,a),c=o.eachBatchSerial(t.clone().offset(l),e,a+1);return r.all([u,c]).then(function(t){return n(t,2)[1]+1})})}}])&&e(o.prototype,a),l&&e(o,l),t}()});
//# sourceMappingURL=dexie-batch.min.js.map
{
"name": "dexie-batch",
"version": "0.4.1",
"version": "0.4.2",
"description": "Fetch DB entries in batches to improve performance while respecting IPC size constraints",

@@ -35,16 +35,15 @@ "license": "MIT",

"devDependencies": {
"ava": "^0.25.0",
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",
"cujs": "^0.2.0",
"dexie": "^2.0.1",
"fake-indexeddb": "^2.0.3",
"nyc": "^11.6.0",
"rollup": "^0.57.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-node-resolve": "^3.3.0",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"ava": "^1.4.1",
"cujs": "^0.2.1",
"dexie": "^2.0.4",
"fake-indexeddb": "^2.1.0",
"nyc": "^13.3.0",
"rollup": "^1.7.4",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.2",
"rollup-plugin-node-resolve": "^4.0.1",
"uglify-es": "^3.3.9",
"xo": "^0.20.3"
"xo": "^0.24.0"
},

@@ -51,0 +50,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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