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

storage-based-queue

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storage-based-queue - npm Package Compare versions

Comparing version 0.0.5-alpha2.5 to 0.0.5-alpha2.6

2

dist/queue.min.js

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

!function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var c="function"==typeof require&&require;if(!u&&c)return c(a,!0);if(o)return o(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var l=n[a]={exports:{}};e[a][0].call(l.exports,function(t){var n=e[a][1][t];return i(n||t)},l,l.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(t,e,n){var r=/\b(Array|Date|Object|Math|JSON)\b/g;e.exports=function(t,e){var n,i=function(t){for(var e=[],n=0;n<t.length;n++)~e.indexOf(t[n])||e.push(t[n]);return e}((n=t,n.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g,"").replace(r,"").match(/[a-zA-Z_]\w*/g)||[]));e&&"string"==typeof e&&(o=e,e=function(t){return o+t});var o;if(e)return a=t,u=i,c=e,a.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g,function(t){return"("==t[t.length-1]?c(t):~u.indexOf(t)?c(t):t});var a,u,c;return i}},{}],2:[function(t,e,n){var r=t("to-function");e.exports=function(t,e){var n,i={};e=r(e);for(var o=0;o<t.length;++o)i[n=e(t[o],o)]=i[n]||[],i[n].push(t[o]);return i}},{"to-function":3}],3:[function(t,e,n){var r;try{r=t("props")}catch(e){r=t("component-props")}e.exports=i;function i(t){switch({}.toString.call(t)){case"[object Object]":return function(t){var e={};for(var n in t)e[n]="string"==typeof t[n]?o(t[n]):i(t[n]);return function(t){if("object"!=typeof t)return!1;for(var n in e){if(!(n in t))return!1;if(!e[n](t[n]))return!1}return!0}}(t);case"[object Function]":return t;case"[object String]":return/^ *\W+/.test(n=t)?new Function("_","return _ "+n):new Function("_","return "+function(t){var e=r(t);if(!e.length)return"_."+t;var n,i,o;for(i=0;i<e.length;i++)o=e[i],t=a(o,t,n="('function' == typeof "+(n="_."+o)+" ? "+n+"() : "+n+")");return t}(n));case"[object RegExp]":return e=t,function(t){return e.test(t)};default:return o(t)}var e,n}function o(t){return function(e){return t===e}}function a(t,e,n){return e.replace(new RegExp("(\\.)?"+t,"g"),function(t,e){return e?t:n})}},{"component-props":1,props:1}],4:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default={storage:"localstorage",prefix:"sq_jobs",timeout:1e3,limit:-1,principle:"fifo"}},{}],5:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,i=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}}(),o=t("./config.data"),a=(r=o,r&&r.__esModule?r:{default:r});var u=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=a.default,this.merge(e)}return i(t,[{key:"set",value:function(t,e){this.config[t]=e}},{key:"get",value:function(t){return this.config[t]}},{key:"has",value:function(t){return Object.prototype.hasOwnProperty.call(this.config,t)}},{key:"merge",value:function(t){this.config=Object.assign({},this.config,t)}},{key:"remove",value:function(t){return delete this.config[t]}},{key:"all",value:function(){return this.config}}]),t}();n.default=u},{"./config.data":4}],6:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}();var i=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._container={}}return r(t,[{key:"has",value:function(t){return Object.prototype.hasOwnProperty.call(this._container,t)}},{key:"get",value:function(t){return this._container[t]}},{key:"all",value:function(){return this._container}},{key:"bind",value:function(t,e){this._container[t]=e}},{key:"remove",value:function(t){return!!Object.prototype.hasOwnProperty.call(this._container,t)&&delete this._container[t]}},{key:"removeAll",value:function(){this._container={}}}]),t}();n.default=i},{}],7:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}();var i=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.store={},this.verifierPattern=/^[a-z0-9\-\_]+\:before$|after$|retry$|\*$/,this.wildcards=["*","error"],this.emptyFunc=function(){},this.store.before={},this.store.after={},this.store.retry={},this.store.wildcard={},this.store.error=this.emptyFunc,this.store["*"]=this.emptyFunc}return r(t,[{key:"on",value:function(t,e){if("function"!=typeof e)throw new Error("Event should be an function");this.isValid(t)&&this.add(t,e)}},{key:"emit",value:function(t,e){if(this.wildcards.indexOf(t)>-1)this.wildcard.apply(this,[t].concat(Array.prototype.slice.call(arguments)));else{var n=this.getType(t),r=this.getName(t);if(this.store[n]){(this.store[n][r]||this.emptyFunc).call(null,e)}}this.wildcard("*",t,e)}},{key:"wildcard",value:function(t,e,n){this.store.wildcard[t]&&this.store.wildcard[t].call(null,e,n)}},{key:"add",value:function(t,e){if(this.wildcards.indexOf(t)>-1)this.store.wildcard[t]=e;else{var n=this.getType(t),r=this.getName(t);this.store[n][r]=e}}},{key:"has",value:function(t){try{var e=t.split(":");return e.length>1?!!this.store[e[1]][e[0]]:!!this.store.wildcard[e[0]]}catch(t){return!1}}},{key:"getName",value:function(t){return t.match(/(.*)\:.*/)[1]}},{key:"getType",value:function(t){return t.match(/^[a-z0-9\-\_]+\:(.*)/)[1]}},{key:"isValid",value:function(t){return this.verifierPattern.test(t)||this.wildcards.indexOf(t)>-1}}]),t}();n.default=i},{}],8:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,i=t("./queue"),o=(r=i,r&&r.__esModule?r:{default:r});window.Queue=o.default,n.default=o.default},{"./queue":9}],9:[function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};Object.defineProperty(n,"__esModule",{value:!0});var i=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,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&u.return&&u.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),o="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return void 0===t?"undefined":r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":r(t)},a=h(t("./container")),u=h(t("./storage-capsule")),c=h(t("./config")),s=h(t("./event")),l=t("./utils"),f=h(t("./storage/localstorage"));function h(t){return t&&t.__esModule?t:{default:t}}var d=function(){t.FIFO="fifo",t.LIFO="lifo";function t(t){(function(t){this.currentChannel,this.currentTimeout,this.stopped=!0,this.running=!1,this.channels={},this.config=new c.default(t),this.storage=new u.default(this.config,new f.default(this.config)),this.event=new s.default,this.container=new a.default,this.timeout=this.config.get("timeout")}).call(this,t)}t.prototype.add=function(t){if(!function(t){return"object"!==(void 0===t?"undefined":o(t))||!0!==t.unique||this.hasByTag(t.tag)<1}.call(this,t))return!1;var e=h.call(this,t);return e&&this.stopped&&!0===this.running&&this.start(),e},t.prototype.next=function(){if(this.stopped)return console.log("[stopped]-> next"),function(){this.running=!1}.call(this),y.call(this);console.log("[next]->"),this.start()},t.prototype.start=function(){return this.stopped=!1,function(){if(t.isRegistered)return;var e=t.jobs||[],n=!0,r=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=c.handler.toString(),l=s.match(/function\s([a-zA-Z_]+).*?/),f=i(l,2),h=(f[0],f[1]);h&&this.container.bind(h,c)}}catch(t){r=!0,o=t}finally{try{!n&&u.return&&u.return()}finally{if(r)throw o}}t.isRegistered=!0}.call(this),this.running=function(){var t=this.config.get("timeout");return this.currentTimeout=setTimeout(function(){var t,e=r.call(this).fetch().shift();if(void 0===e)return console.log("-> "+this.currentChannel+" channel is empty..."),void y.call(this);this.container.has(e.handler)||console.warn(e.handler+"-> job not found");var i=this.container.get(e.handler),o=new i.handler;(function(t){return r.call(this).update(t._id,{locked:!0})}).call(this,e),p.call(this,"before",o,e.args),n.call(this,e,"before");var a=Object.values(i.deps||{});(t=o.handle).call.apply(t,[o,e.args].concat(function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}(a))).then(function(t,e){var i=this;return function(o){o?function(t,e){d.call(this,t._id)}.call(i,t,e):function(t,e){n.call(this,t,"retry");var i=function(t,e){"retry"in e||(e.retry=1);"tried"in t||(t.tried=0,t.retry=e.retry);++t.tried,t.tried>=e.retry&&(t.freezed=!0);return t}.call(this,t,e);return i.locked=!1,r.call(this).update(t._id,i)}.call(i,t,e),p.call(this,"after",e,t.args),n.call(this,t,"after"),i.next()}}.call(this,e,o).bind(this)).catch(function(t,e){var n=this;return function(e){d.call(n,t._id),n.event.emit("error",t),n.next()}}.call(this,e,o).bind(this))}.bind(this),t)}.call(this)>0,console.log("[started]->",this.running),this.running},t.prototype.stop=function(){console.log("[stopping]->"),this.stopped=!0},t.prototype.forceStop=function(){console.log("[forceStopped]->"),y.call(this)},t.prototype.create=function(t){return t in this.channels||(this.currentChannel=t,this.channels[t]=(0,l.clone)(this)),this.channels[t]},t.prototype.channel=function(t){if(!this.channels[t])throw new Error('Channel of "'+t+'" not found');return this.channels[t]},t.prototype.isEmpty=function(){return this.count()<1},t.prototype.count=function(){return e.call(this).length},t.prototype.countByTag=function(t){return e.call(this).filter(function(e){return e.tag===t}).length},t.prototype.clear=function(){this.currentChannel&&this.storage.clear(this.currentChannel)},t.prototype.clearByTag=function(t){var e=this;r.call(this).all().filter(l.utilClearByTag.bind(t)).forEach(function(t){return r.call(e).delete(t._id)})},t.prototype.has=function(t){return e.call(this).findIndex(function(e){return e._id===t})>-1},t.prototype.hasByTag=function(t){return e.call(this).findIndex(function(e){return e.tag===t})>-1},t.prototype.setTimeout=function(t){this.timeout=t,this.config.set("timeout",t)},t.prototype.setLimit=function(t){this.config.set("limit",t)},t.prototype.setPrefix=function(t){this.config.set("prefix",t)},t.prototype.setPrinciple=function(t){this.config.set("principle",t)},t.prototype.on=function(t,e){var n;(n=this.event).on.apply(n,arguments)},t.prototype.error=function(t){this.event.on("error",t)},t.register=function(e){if(!(e instanceof Array))throw new Error("Queue jobs should be objects within an array");t.isRegistered=!1,t.jobs=e};function e(){return r.call(this).all().filter(l.excludeSpecificTasks.bind(["freezed"]))}function n(t,e){"tag"in t&&(this.event.emit(t.tag+":"+e,t),this.event.emit(t.tag+":*",t))}function r(){return this.storage.channel(this.currentChannel)}function h(t){return r.call(this).save(t)}function h(t){return r.call(this).save(function(t){t.priority=t.priority||0,isNaN(t.priority)&&(t.priority=0);return t}(t))}function d(t){return r.call(this).delete(t)}function p(t,e,n){(0,l.hasMethod)(e,t)&&("before"==t&&(0,l.isFunction)(e.before)?e.before.call(e,n):"after"==t&&(0,l.isFunction)(e.after)&&e.after.call(e,n))}function y(){this.stop(),this.currentTimeout&&(this.currentTimeout=clearTimeout(this.currentTimeout))}return t}();n.default=d},{"./config":5,"./container":6,"./event":7,"./storage-capsule":10,"./storage/localstorage":11,"./utils":12}],10:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}(),i=a(t("group-by")),o=(a(t("./storage/localstorage")),a(t("./config")),t("./utils"));function a(t){return t&&t.__esModule?t:{default:t}}var u=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.storage=n,this.config=e}return r(t,[{key:"channel",value:function(t){return this.storageChannel=t,this}},{key:"fetch",value:function(){var t=this.all().filter(o.excludeSpecificTasks),e=(0,i.default)(t,"priority");return Object.keys(e).map(function(t){return parseInt(t)}).sort(function(t,e){return e-t}).reduce(this.reduceTasks(e),[])}},{key:"save",value:function(t){var e=this.storage.get(this.storageChannel);return this.isExceeded()?(console.warn("Task limit exceeded: The '"+this.storageChannel+"' channel limit is "+this.config.get("limit")),!1):(t=this.prepareTask(t),e.push(t),this.storage.set(this.storageChannel,JSON.stringify(e)),t._id)}},{key:"update",value:function(t,e){var n=this.all(),r=n.findIndex(function(e){return e._id==t});return!(r<0)&&(n[r]=Object.assign({},n[r],e),this.storage.set(this.storageChannel,JSON.stringify(n)),!0)}},{key:"delete",value:function(t){var e=this.all(),n=e.findIndex(function(e){return e._id===t});return!(n<0)&&(delete e[n],this.storage.set(this.storageChannel,JSON.stringify(e.filter(function(t){return t}))),!0)}},{key:"all",value:function(){return this.storage.get(this.storageChannel)}},{key:"generateId",value:function(){return(65536*(1+Math.random())).toString(16)}},{key:"prepareTask",value:function(t){return t.createdAt=Date.now(),t._id=this.generateId(),t}},{key:"reduceTasks",value:function(t){var e=this;return function(n,r){return"lifo"===e.config.get("principle")?n.concat(t[r].sort(o.lifo)):n.concat(t[r].sort(o.fifo))}.bind(this)}},{key:"isExceeded",value:function(){var t=this.config.get("limit"),e=this.all().filter(o.excludeSpecificTasks);return!(-1===t||t>e.length)}},{key:"clear",value:function(t){this.storage.clear(t)}}]),t}();n.default=u},{"./config":5,"./storage/localstorage":11,"./utils":12,"group-by":2}],11:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}();var i=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.storage=localStorage,this.config=e}return r(t,[{key:"get",value:function(t){try{var e=this.storageName(t);return this.has(e)?JSON.parse(this.storage.getItem(e)):[]}catch(t){return[]}}},{key:"set",value:function(t,e){this.storage.setItem(this.storageName(t),e)}},{key:"has",value:function(t){return t in this.storage}},{key:"clear",value:function(t){this.storage.removeItem(this.storageName(t))}},{key:"clearAll",value:function(){this.storage.clear()}},{key:"storageName",value:function(t){return this.getPrefix()+"_"+t}},{key:"getPrefix",value:function(){return this.config.get("prefix")}}]),t}();n.default=i},{}],12:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.clone=function(t){var e=Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyNames(t).reduce(function(e,n){return e[n]=Object.getOwnPropertyDescriptor(t,n),e},{}));Object.isExtensible(t)||Object.preventExtensions(e);Object.isSealed(t)&&Object.seal(e);Object.isFrozen(t)&&Object.freeze(e);return e},n.hasProperty=r,n.hasMethod=function(t,e){return t instanceof Object&&e in t},n.isFunction=function(t){return t instanceof Function},n.excludeSpecificTasks=i,n.utilClearByTag=function(t){if(!i.call(["locked"],t))return!1;return t.tag===this},n.fifo=function(t,e){return t.createdAt-e.createdAt},n.lifo=function(t,e){return e.createdAt-t.createdAt};function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function i(t){var e=Array.isArray(this)?this:["freezed","locked"],n=[],i=!0,o=!1,a=void 0;try{for(var u,c=e[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var s=u.value;n.push(!1===r(t,s)||!1===t[s])}}catch(t){o=!0,a=t}finally{try{!i&&c.return&&c.return()}finally{if(o)throw a}}return!(n.indexOf(!1)>-1)}},{}]},{},[8]);
!function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var c="function"==typeof require&&require;if(!u&&c)return c(a,!0);if(o)return o(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var l=n[a]={exports:{}};e[a][0].call(l.exports,function(t){var n=e[a][1][t];return i(n||t)},l,l.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(t,e,n){var r=/\b(Array|Date|Object|Math|JSON)\b/g;e.exports=function(t,e){var n,i=function(t){for(var e=[],n=0;n<t.length;n++)~e.indexOf(t[n])||e.push(t[n]);return e}((n=t,n.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g,"").replace(r,"").match(/[a-zA-Z_]\w*/g)||[]));e&&"string"==typeof e&&(o=e,e=function(t){return o+t});var o;if(e)return a=t,u=i,c=e,a.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g,function(t){return"("==t[t.length-1]?c(t):~u.indexOf(t)?c(t):t});var a,u,c;return i}},{}],2:[function(t,e,n){var r=t("to-function");e.exports=function(t,e){var n,i={};e=r(e);for(var o=0;o<t.length;++o)i[n=e(t[o],o)]=i[n]||[],i[n].push(t[o]);return i}},{"to-function":3}],3:[function(t,e,n){var r;try{r=t("props")}catch(e){r=t("component-props")}e.exports=i;function i(t){switch({}.toString.call(t)){case"[object Object]":return function(t){var e={};for(var n in t)e[n]="string"==typeof t[n]?o(t[n]):i(t[n]);return function(t){if("object"!=typeof t)return!1;for(var n in e){if(!(n in t))return!1;if(!e[n](t[n]))return!1}return!0}}(t);case"[object Function]":return t;case"[object String]":return/^ *\W+/.test(n=t)?new Function("_","return _ "+n):new Function("_","return "+function(t){var e=r(t);if(!e.length)return"_."+t;var n,i,o;for(i=0;i<e.length;i++)o=e[i],t=a(o,t,n="('function' == typeof "+(n="_."+o)+" ? "+n+"() : "+n+")");return t}(n));case"[object RegExp]":return e=t,function(t){return e.test(t)};default:return o(t)}var e,n}function o(t){return function(e){return t===e}}function a(t,e,n){return e.replace(new RegExp("(\\.)?"+t,"g"),function(t,e){return e?t:n})}},{"component-props":1,props:1}],4:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default={storage:"localstorage",prefix:"sq_jobs",timeout:1e3,limit:-1,principle:"fifo"}},{}],5:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,i=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}}(),o=t("./config.data"),a=(r=o,r&&r.__esModule?r:{default:r});var u=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config=a.default,this.merge(e)}return i(t,[{key:"set",value:function(t,e){this.config[t]=e}},{key:"get",value:function(t){return this.config[t]}},{key:"has",value:function(t){return Object.prototype.hasOwnProperty.call(this.config,t)}},{key:"merge",value:function(t){this.config=Object.assign({},this.config,t)}},{key:"remove",value:function(t){return delete this.config[t]}},{key:"all",value:function(){return this.config}}]),t}();n.default=u},{"./config.data":4}],6:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}();var i=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._container={}}return r(t,[{key:"has",value:function(t){return Object.prototype.hasOwnProperty.call(this._container,t)}},{key:"get",value:function(t){return this._container[t]}},{key:"all",value:function(){return this._container}},{key:"bind",value:function(t,e){this._container[t]=e}},{key:"remove",value:function(t){return!!Object.prototype.hasOwnProperty.call(this._container,t)&&delete this._container[t]}},{key:"removeAll",value:function(){this._container={}}}]),t}();n.default=i},{}],7:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}();var i=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.store={},this.verifierPattern=/^[a-z0-9\-\_]+\:before$|after$|retry$|\*$/,this.wildcards=["*","error"],this.emptyFunc=function(){},this.store.before={},this.store.after={},this.store.retry={},this.store.wildcard={},this.store.error=this.emptyFunc,this.store["*"]=this.emptyFunc}return r(t,[{key:"on",value:function(t,e){if("function"!=typeof e)throw new Error("Event should be an function");this.isValid(t)&&this.add(t,e)}},{key:"emit",value:function(t,e){if(this.wildcards.indexOf(t)>-1)this.wildcard.apply(this,[t].concat(Array.prototype.slice.call(arguments)));else{var n=this.getType(t),r=this.getName(t);if(this.store[n]){(this.store[n][r]||this.emptyFunc).call(null,e)}}this.wildcard("*",t,e)}},{key:"wildcard",value:function(t,e,n){this.store.wildcard[t]&&this.store.wildcard[t].call(null,e,n)}},{key:"add",value:function(t,e){if(this.wildcards.indexOf(t)>-1)this.store.wildcard[t]=e;else{var n=this.getType(t),r=this.getName(t);this.store[n][r]=e}}},{key:"has",value:function(t){try{var e=t.split(":");return e.length>1?!!this.store[e[1]][e[0]]:!!this.store.wildcard[e[0]]}catch(t){return!1}}},{key:"getName",value:function(t){return t.match(/(.*)\:.*/)[1]}},{key:"getType",value:function(t){return t.match(/^[a-z0-9\-\_]+\:(.*)/)[1]}},{key:"isValid",value:function(t){return this.verifierPattern.test(t)||this.wildcards.indexOf(t)>-1}}]),t}();n.default=i},{}],8:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,i=t("./queue"),o=(r=i,r&&r.__esModule?r:{default:r});window.Queue=o.default,n.default=o.default},{"./queue":9}],9:[function(t,e,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};Object.defineProperty(n,"__esModule",{value:!0});var i=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,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&u.return&&u.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),o="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return void 0===t?"undefined":r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":r(t)},a=h(t("./container")),u=h(t("./storage-capsule")),c=h(t("./config")),s=h(t("./event")),l=t("./utils"),f=h(t("./storage/localstorage"));function h(t){return t&&t.__esModule?t:{default:t}}var d=function(){t.FIFO="fifo",t.LIFO="lifo";function t(t){(function(t){this.currentChannel,this.currentTimeout,this.stopped=!0,this.running=!1,this.channels={},this.config=new c.default(t),this.storage=new u.default(this.config,new f.default(this.config)),this.event=new s.default,this.container=new a.default,this.timeout=this.config.get("timeout")}).call(this,t)}t.prototype.add=function(t){if(!function(t){return"object"!==(void 0===t?"undefined":o(t))||!0!==t.unique||this.hasByTag(t.tag)<1}.call(this,t))return!1;var e=h.call(this,t);return e&&this.stopped&&!0===this.running&&this.start(),e},t.prototype.next=function(){if(this.stopped)return console.log("[stopped]-> next"),function(){this.running=!1}.call(this),y.call(this);console.log("[next]->"),this.start()},t.prototype.start=function(){return this.stopped=!1,function(){if(t.isRegistered)return;var e=t.jobs||[],n=!0,r=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=c.handler.toString(),l=s.match(/function\s([a-zA-Z_]+).*?/),f=i(l,2),h=(f[0],f[1]);h&&this.container.bind(h,c)}}catch(t){r=!0,o=t}finally{try{!n&&u.return&&u.return()}finally{if(r)throw o}}t.isRegistered=!0}.call(this),this.running=function(){var t=this.config.get("timeout");return this.currentTimeout=setTimeout(function(){var t,e=r.call(this).fetch().shift();if(void 0===e)return console.log("-> "+this.currentChannel+" channel is empty..."),void y.call(this);this.container.has(e.handler)||console.warn(e.handler+"-> job not found");var i=this.container.get(e.handler),o=new i.handler;(function(t){return r.call(this).update(t._id,{locked:!0})}).call(this,e),p.call(this,"before",o,e.args),n.call(this,e,"before");var a=Object.values(i.deps||{});(t=o.handle).call.apply(t,[o,e.args].concat(function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}(a))).then(function(t,e){var i=this;return function(o){o?function(t,e){d.call(this,t._id)}.call(i,t,e):function(t,e){n.call(this,t,"retry");var i=function(t,e){"retry"in e||(e.retry=1);"tried"in t||(t.tried=0,t.retry=e.retry);++t.tried,t.tried>=e.retry&&(t.freezed=!0);return t}.call(this,t,e);return i.locked=!1,r.call(this).update(t._id,i)}.call(i,t,e),p.call(this,"after",e,t.args),n.call(this,t,"after"),i.next()}}.call(this,e,o).bind(this)).catch(function(t,e){var n=this;return function(e){d.call(n,t._id),n.event.emit("error",t),n.next()}}.call(this,e,o).bind(this))}.bind(this),t)}.call(this)>0,console.log("[started]->",this.running),this.running},t.prototype.stop=function(){console.log("[stopping]->"),this.stopped=!0},t.prototype.forceStop=function(){console.log("[forceStopped]->"),y.call(this)},t.prototype.create=function(t){return t in this.channels||(this.currentChannel=t,this.channels[t]=(0,l.clone)(this)),this.channels[t]},t.prototype.channel=function(t){if(!this.channels[t])throw new Error('Channel of "'+t+'" not found');return this.channels[t]},t.prototype.isEmpty=function(){return this.count()<1},t.prototype.count=function(){return e.call(this).length},t.prototype.countByTag=function(t){return e.call(this).filter(function(e){return e.tag===t}).length},t.prototype.clear=function(){return!!this.currentChannel&&(this.storage.clear(this.currentChannel),!0)},t.prototype.clearByTag=function(t){var e=this;r.call(this).all().filter(l.utilClearByTag.bind(t)).forEach(function(t){return r.call(e).delete(t._id)})},t.prototype.has=function(t){return e.call(this).findIndex(function(e){return e._id===t})>-1},t.prototype.hasByTag=function(t){return e.call(this).findIndex(function(e){return e.tag===t})>-1},t.prototype.setTimeout=function(t){this.timeout=t,this.config.set("timeout",t)},t.prototype.setLimit=function(t){this.config.set("limit",t)},t.prototype.setPrefix=function(t){this.config.set("prefix",t)},t.prototype.setPrinciple=function(t){this.config.set("principle",t)},t.prototype.on=function(t,e){var n;(n=this.event).on.apply(n,arguments)},t.prototype.error=function(t){this.event.on("error",t)},t.register=function(e){if(!(e instanceof Array))throw new Error("Queue jobs should be objects within an array");t.isRegistered=!1,t.jobs=e};function e(){return r.call(this).all().filter(l.excludeSpecificTasks.bind(["freezed"]))}function n(t,e){"tag"in t&&(this.event.emit(t.tag+":"+e,t),this.event.emit(t.tag+":*",t))}function r(){return this.storage.channel(this.currentChannel)}function h(t){return r.call(this).save(t)}function h(t){return r.call(this).save(function(t){t.priority=t.priority||0,isNaN(t.priority)&&(t.priority=0);return t}(t))}function d(t){return r.call(this).delete(t)}function p(t,e,n){(0,l.hasMethod)(e,t)&&("before"==t&&(0,l.isFunction)(e.before)?e.before.call(e,n):"after"==t&&(0,l.isFunction)(e.after)&&e.after.call(e,n))}function y(){this.stop(),this.currentTimeout&&(this.currentTimeout=clearTimeout(this.currentTimeout))}return t}();n.default=d},{"./config":5,"./container":6,"./event":7,"./storage-capsule":10,"./storage/localstorage":11,"./utils":12}],10:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}(),i=a(t("group-by")),o=(a(t("./storage/localstorage")),a(t("./config")),t("./utils"));function a(t){return t&&t.__esModule?t:{default:t}}var u=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.storage=n,this.config=e}return r(t,[{key:"channel",value:function(t){return this.storageChannel=t,this}},{key:"fetch",value:function(){var t=this.all().filter(o.excludeSpecificTasks),e=(0,i.default)(t,"priority");return Object.keys(e).map(function(t){return parseInt(t)}).sort(function(t,e){return e-t}).reduce(this.reduceTasks(e),[])}},{key:"save",value:function(t){var e=this.storage.get(this.storageChannel);return this.isExceeded()?(console.warn("Task limit exceeded: The '"+this.storageChannel+"' channel limit is "+this.config.get("limit")),!1):(t=this.prepareTask(t),e.push(t),this.storage.set(this.storageChannel,JSON.stringify(e)),t._id)}},{key:"update",value:function(t,e){var n=this.all(),r=n.findIndex(function(e){return e._id==t});return!(r<0)&&(n[r]=Object.assign({},n[r],e),this.storage.set(this.storageChannel,JSON.stringify(n)),!0)}},{key:"delete",value:function(t){var e=this.all(),n=e.findIndex(function(e){return e._id===t});return!(n<0)&&(delete e[n],this.storage.set(this.storageChannel,JSON.stringify(e.filter(function(t){return t}))),!0)}},{key:"all",value:function(){return this.storage.get(this.storageChannel)}},{key:"generateId",value:function(){return(65536*(1+Math.random())).toString(16)}},{key:"prepareTask",value:function(t){return t.createdAt=Date.now(),t._id=this.generateId(),t}},{key:"reduceTasks",value:function(t){var e=this;return function(n,r){return"lifo"===e.config.get("principle")?n.concat(t[r].sort(o.lifo)):n.concat(t[r].sort(o.fifo))}.bind(this)}},{key:"isExceeded",value:function(){var t=this.config.get("limit"),e=this.all().filter(o.excludeSpecificTasks);return!(-1===t||t>e.length)}},{key:"clear",value:function(t){this.storage.clear(t)}}]),t}();n.default=u},{"./config":5,"./storage/localstorage":11,"./utils":12,"group-by":2}],11:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=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}}();var i=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.storage=localStorage,this.config=e}return r(t,[{key:"get",value:function(t){try{var e=this.storageName(t);return this.has(e)?JSON.parse(this.storage.getItem(e)):[]}catch(t){return[]}}},{key:"set",value:function(t,e){this.storage.setItem(this.storageName(t),e)}},{key:"has",value:function(t){return t in this.storage}},{key:"clear",value:function(t){this.storage.removeItem(this.storageName(t))}},{key:"clearAll",value:function(){this.storage.clear()}},{key:"storageName",value:function(t){return this.getPrefix()+"_"+t}},{key:"getPrefix",value:function(){return this.config.get("prefix")}}]),t}();n.default=i},{}],12:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.clone=function(t){var e=Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyNames(t).reduce(function(e,n){return e[n]=Object.getOwnPropertyDescriptor(t,n),e},{}));Object.isExtensible(t)||Object.preventExtensions(e);Object.isSealed(t)&&Object.seal(e);Object.isFrozen(t)&&Object.freeze(e);return e},n.hasProperty=r,n.hasMethod=function(t,e){return t instanceof Object&&e in t},n.isFunction=function(t){return t instanceof Function},n.excludeSpecificTasks=i,n.utilClearByTag=function(t){if(!i.call(["locked"],t))return!1;return t.tag===this},n.fifo=function(t,e){return t.createdAt-e.createdAt},n.lifo=function(t,e){return e.createdAt-t.createdAt};function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function i(t){var e=Array.isArray(this)?this:["freezed","locked"],n=[],i=!0,o=!1,a=void 0;try{for(var u,c=e[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var s=u.value;n.push(!1===r(t,s)||!1===t[s])}}catch(t){o=!0,a=t}finally{try{!i&&c.return&&c.return()}finally{if(o)throw a}}return!(n.indexOf(!1)>-1)}},{}]},{},[8]);

@@ -127,5 +127,5 @@

Queue.prototype.clear = function () {
if (this.currentChannel) {
this.storage.clear(this.currentChannel);
}
if (!this.currentChannel) return false;
this.storage.clear(this.currentChannel);
return true;
};

@@ -132,0 +132,0 @@

{
"name": "storage-based-queue",
"version": "0.0.5-alpha2.5",
"version": "0.0.5-alpha2.6",
"description": "Simply queue manager",

@@ -5,0 +5,0 @@ "main": "lib/queue.js",

@@ -126,6 +126,6 @@ /* @flow */

Queue.prototype.clear = function(): void {
if (this.currentChannel) {
this.storage.clear(this.currentChannel);
}
Queue.prototype.clear = function(): boolean {
if (! this.currentChannel) return false;
this.storage.clear(this.currentChannel);
return true;
};

@@ -132,0 +132,0 @@

@@ -7,3 +7,3 @@ import Config from "../lib/config";

beforeEach(() => {
config = new Config
config = new Config({})
config.set('test', true);

@@ -10,0 +10,0 @@ });

@@ -25,2 +25,13 @@ import Config from "../lib/config";

it('should be register queue worker', () => {
Queue.register([
{ handler: SendEmail},
{ handler: SendEmail}
]);
expect(Queue.jobs.length).toBeGreaterThan(1);
expect(() => Queue.register('worker')).toThrow();
});
it('should be add new task to queue, -> add()', () => {

@@ -211,2 +222,4 @@ expect(queue.running).toBeFalsy();

expect(channelA.count()).toEqual(0);
channelA.currentChannel = null;
channelA.clear();
});

@@ -213,0 +226,0 @@

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