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.4 to 0.0.5-alpha2.5

.npmignore

2

dist/queue.min.js

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

!function t(e,n,r){function i(u,a){if(!n[u]){if(!e[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(o)return o(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var l=n[u]={exports:{}};e[u][0].call(l.exports,function(t){var n=e[u][1][t];return i(n||t)},l,l.exports,t,e,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(t,e,n){var r=/\b(Array|Date|Object|Math|JSON)\b/g;e.exports=function(t,e){var n=function(t){for(var e=[],n=0;n<t.length;n++)~e.indexOf(t[n])||e.push(t[n]);return e}(function(t){return t.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g,"").replace(r,"").match(/[a-zA-Z_]\w*/g)||[]}(t));return e&&"string"==typeof e&&(e=function(t){return function(e){return t+e}}(e)),e?function(t,e,n){return t.replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g,function(t){return"("==t[t.length-1]?n(t):~e.indexOf(t)?n(t):t})}(t,n,e):n}},{}],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){function r(t){switch({}.toString.call(t)){case"[object Object]":return function(t){var e={};for(var n in t)e[n]="string"==typeof t[n]?i(t[n]):r(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 function(t){return/^ *\W+/.test(t)?new Function("_","return _ "+t):new Function("_","return "+function(t){var e=o(t);if(!e.length)return"_."+t;var n,r,i;for(r=0;r<e.length;r++)i=e[r],t=function(t,e,n){return e.replace(new RegExp("(\\.)?"+t,"g"),function(t,e){return e?t:n})}(i,t,n="('function' == typeof "+(n="_."+i)+" ? "+n+"() : "+n+")");return t}(t))}(t);case"[object RegExp]":return function(t){return function(e){return t.test(e)}}(t);default:return i(t)}}function i(t){return function(e){return t===e}}var o;try{o=t("props")}catch(e){o=t("component-props")}e.exports=r},{"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=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=function(t){return t&&t.__esModule?t:{default:t}}(t("./config.data")),o=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=i.default,this.merge(e)}return r(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=o},{"./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}}(),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){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}}(),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=function(t){return t&&t.__esModule?t:{default:t}}(t("./queue"));window.Queue=r.default,n.default=r.default},{"./queue":9}],9:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}var i="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 o=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 u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{!r&&a.return&&a.return()}finally{if(i)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),u="function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?function(t){return void 0===t?"undefined":i(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":i(t)},a=r(t("./container")),c=r(t("./storage-capsule")),s=r(t("./config")),l=r(t("./event")),f=t("./utils"),h=r(t("./storage/localstorage")),d=function(){function t(t){(function(t){this.currentChannel,this.currentTimeout,this.stopped=!0,this.running=!1,this.channels={},this.config=new s.default(t),this.storage=new c.default(this.config,new h.default(this.config)),this.event=new l.default,this.container=new a.default,this.timeout=this.config.get("timeout")}).call(this,t)}function e(){return r.call(this).all().filter(f.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 i(t){return r.call(this).save(t)}function i(t){return r.call(this).save(function(t){t.priority=t.priority||0,isNaN(t.priority)&&(t.priority=0);return t}(t))}function d(){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 g.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),y.call(this,"before",o,e.args),n.call(this,e,"before");var u=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)}(u))).then(function(t,e){var i=this;return function(o){o?function(t,e){p.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),y.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){p.call(n,t._id),n.event.emit("error",t),n.next()}}.call(this,e,o).bind(this))}.bind(this),t)}function p(t){return r.call(this).delete(t)}function y(t,e,n){(0,f.hasMethod)(e,t)&&("before"==t&&(0,f.isFunction)(e.before)?e.before.call(e,n):"after"==t&&(0,f.isFunction)(e.after)&&e.after.call(e,n))}function g(){this.stop(),this.currentTimeout&&(this.currentTimeout=clearTimeout(this.currentTimeout))}return t.FIFO="fifo",t.LIFO="lifo",t.prototype.add=function(t){if(!function(t){return"object"!==(void 0===t?"undefined":u(t))||!0!==t.unique||this.hasByTag(t.tag)<1}.call(this,t))return!1;var e=i.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),g.call(this);console.log("[next]->"),this.start()},t.prototype.start=function(){return this.stopped=!1,function(){if(!t.isRegistered){var e=t.jobs||[],n=!0,r=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done);n=!0){var c=u.value,s=c.handler.toString().match(/function\s([a-zA-Z_]+).*?/),l=o(s,2),f=(l[0],l[1]);f&&this.container.bind(f,c)}}catch(t){r=!0,i=t}finally{try{!n&&a.return&&a.return()}finally{if(r)throw i}}t.isRegistered=!0}}.call(this),this.running=d.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]->"),g.call(this)},t.prototype.create=function(t){return t in this.channels||(this.currentChannel=t,this.channels[t]=(0,f.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(f.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},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";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(n,"__esModule",{value:!0});var 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=r(t("group-by")),u=(r(t("./storage/localstorage")),r(t("./config")),t("./utils")),a=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 i(t,[{key:"channel",value:function(t){return this.storageChannel=t,this}},{key:"fetch",value:function(){var t=this.all().filter(u.excludeSpecificTasks),e=(0,o.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){try{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)}catch(t){return!1}}},{key:"update",value:function(t,e){try{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)}catch(t){return!1}}},{key:"delete",value:function(t){try{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)}catch(t){return!1}}},{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(u.lifo)):n.concat(t[r].sort(u.fifo))}.bind(this)}},{key:"isExceeded",value:function(){var t=this.config.get("limit"),e=this.all().filter(u.excludeSpecificTasks);return!(-1===t||t>e.length)}},{key:"clear",value:function(t){this.storage.clear(t)}}]),t}();n.default=a},{"./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}}(),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";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,u=void 0;try{for(var a,c=e[Symbol.iterator]();!(i=(a=c.next()).done);i=!0){var s=a.value;n.push(!1===r(t,s)||!1===t[s])}}catch(t){o=!0,u=t}finally{try{!i&&c.return&&c.return()}finally{if(o)throw u}}return!(n.indexOf(!1)>-1)}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},{}));return Object.isExtensible(t)||Object.preventExtensions(e),Object.isSealed(t)&&Object.seal(e),Object.isFrozen(t)&&Object.freeze(e),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){return!!i.call(["locked"],t)&&t.tag===this},n.fifo=function(t,e){return t.createdAt-e.createdAt},n.lifo=function(t,e){return e.createdAt-t.createdAt}},{}]},{},[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(){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]);

@@ -27,5 +27,4 @@

remove(id) {
if (Object.prototype.hasOwnProperty.call(this._container, id)) {
delete this._container[id];
}
if (!Object.prototype.hasOwnProperty.call(this._container, id)) return false;
return delete this._container[id];
}

@@ -32,0 +31,0 @@

@@ -36,69 +36,57 @@

save(task) {
try {
// get all tasks current channel's
const tasks = this.storage.get(this.storageChannel);
// get all tasks current channel's
const tasks = this.storage.get(this.storageChannel);
// check channel limit.
// if limit is exceeded, does not insert new task
if (this.isExceeded()) {
console.warn(
`Task limit exceeded: The '${
this.storageChannel
}' channel limit is ${this.config.get("limit")}`);
// check channel limit.
// if limit is exceeded, does not insert new task
if (this.isExceeded()) {
console.warn(
`Task limit exceeded: The '${
this.storageChannel
}' channel limit is ${this.config.get("limit")}`);
return false;
}
return false;
}
// prepare all properties before save
// example: createdAt etc.
task = this.prepareTask(task);
// prepare all properties before save
// example: createdAt etc.
task = this.prepareTask(task);
// add task to storage
tasks.push(task);
// add task to storage
tasks.push(task);
// save tasks
this.storage.set(this.storageChannel, JSON.stringify(tasks));
// save tasks
this.storage.set(this.storageChannel, JSON.stringify(tasks));
return task._id;
} catch (e) {
return false;
}
return task._id;
}
update(id, update) {
try {
const data = this.all();
const index = data.findIndex(t => t._id == id);
const data = this.all();
const index = data.findIndex(t => t._id == id);
if (index < 0) return false;
if (index < 0) return false;
// merge existing object with given update object
data[index] = Object.assign({}, data[index], update);
// merge existing object with given update object
data[index] = Object.assign({}, data[index], update);
// save to the storage as string
this.storage.set(this.storageChannel, JSON.stringify(data));
// save to the storage as string
this.storage.set(this.storageChannel, JSON.stringify(data));
return true;
} catch (e) {
return false;
}
return true;
}
delete(id) {
try {
const data = this.all();
const index = data.findIndex(d => d._id === id);
const data = this.all();
const index = data.findIndex(d => d._id === id);
if (index < 0) return false;
if (index < 0) return false;
delete data[index];
delete data[index];
this.storage.set(
this.storageChannel,
JSON.stringify(data.filter(d => d)));
this.storage.set(
this.storageChannel,
JSON.stringify(data.filter(d => d)));
return true;
} catch (e) {
return false;
}
return true;
}

@@ -105,0 +93,0 @@

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

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

@@ -26,6 +26,5 @@ /* @flow */

remove(id: string): void {
if (Object.prototype.hasOwnProperty.call(this._container, id)) {
delete this._container[id];
}
remove(id: string): boolean {
if (! Object.prototype.hasOwnProperty.call(this._container, id)) return false;
return delete this._container[id];
}

@@ -32,0 +31,0 @@

@@ -36,69 +36,57 @@ /* @flow */

save(task: ITask): string | boolean {
try {
// get all tasks current channel's
const tasks: ITask[] = this.storage.get(this.storageChannel);
// get all tasks current channel's
const tasks: ITask[] = this.storage.get(this.storageChannel);
// check channel limit.
// if limit is exceeded, does not insert new task
if (this.isExceeded()) {
console.warn(
`Task limit exceeded: The '${
this.storageChannel
}' channel limit is ${this.config.get("limit")}`
);
return false;
}
// check channel limit.
// if limit is exceeded, does not insert new task
if (this.isExceeded()) {
console.warn(
`Task limit exceeded: The '${
this.storageChannel
}' channel limit is ${this.config.get("limit")}`
);
return false;
}
// prepare all properties before save
// example: createdAt etc.
task = this.prepareTask(task);
// prepare all properties before save
// example: createdAt etc.
task = this.prepareTask(task);
// add task to storage
tasks.push(task);
// add task to storage
tasks.push(task);
// save tasks
this.storage.set(this.storageChannel, JSON.stringify(tasks));
// save tasks
this.storage.set(this.storageChannel, JSON.stringify(tasks));
return task._id;
} catch (e) {
return false;
}
return task._id;
}
update(id: string, update: { [property: string]: any }): boolean {
try {
const data: any[] = this.all();
const index: number = data.findIndex(t => t._id == id);
const data: any[] = this.all();
const index: number = data.findIndex(t => t._id == id);
if (index < 0) return false;
if (index < 0) return false;
// merge existing object with given update object
data[index] = Object.assign({}, data[index], update);
// merge existing object with given update object
data[index] = Object.assign({}, data[index], update);
// save to the storage as string
this.storage.set(this.storageChannel, JSON.stringify(data));
// save to the storage as string
this.storage.set(this.storageChannel, JSON.stringify(data));
return true;
} catch (e) {
return false;
}
return true;
}
delete(id: string): boolean {
try {
const data: any[] = this.all();
const index: number = data.findIndex(d => d._id === id);
const data: any[] = this.all();
const index: number = data.findIndex(d => d._id === id);
if (index < 0) return false;
if (index < 0) return false;
delete data[index];
delete data[index];
this.storage.set(
this.storageChannel,
JSON.stringify(data.filter(d => d))
);
return true;
} catch (e) {
return false;
}
this.storage.set(
this.storageChannel,
JSON.stringify(data.filter(d => d))
);
return true;
}

@@ -105,0 +93,0 @@

@@ -39,2 +39,4 @@ import Container from "../lib/container";

expect('item1' in container._container).toBeFalsy();
expect(container.remove('item2')).toBeFalsy();
});

@@ -41,0 +43,0 @@

@@ -44,2 +44,4 @@ import StorageCapsule from "../lib/storage-capsule";

expect(task.createdAt).toBeDefined();
expect(() => storage.save(2)).toThrow();
});

@@ -93,2 +95,4 @@

expect(updatedTasks.findIndex(t => t._id === id)).toBeLessThan(0);
expect(storage.delete(423423)).toBeFalsy();
});

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

@@ -8,2 +8,3 @@ import * as utils from "../lib/utils";

}
exampleFunc.prototype.run = function() {

@@ -53,2 +54,13 @@ this.test2 = 'World';

});
it('should be check specific tags in object, -> utilClearByTag()', () => {
const task = {tag: 'test', freezed: true, locked: true, worker: 'SendEmail' };
expect(utils.utilClearByTag(task)).toBeFalsy();
task.locked = false;
expect(utils.utilClearByTag.call('test', task)).toBeTruthy();
expect(utils.utilClearByTag.call('test2', task)).toBeFalsy();
});
});

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