UNPKG

ontime-pm

Version:
2 lines 26.7 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("dexie")):"function"==typeof define&&define.amd?define("ontime-pm",["dexie"],e):"object"==typeof exports?exports["ontime-pm"]=e(require("dexie")):t["ontime-pm"]=e(t.dexie)}(this,(function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=10)}([function(t,e,r){"use strict";var n;r.d(e,"a",(function(){return n})),function(t){t.START="start",t.IN_PROGRESS="in-progress",t.PAUSE="pause",t.CANCEL="cancel",t.ERROR="error",t.DONE="done"}(n||(n={}))},function(t,e,r){"use strict";r.d(e,"a",(function(){return o}));var n=function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),o=0;for(e=0;e<r;e++)for(var s=arguments[e],i=0,u=s.length;i<u;i++,o++)n[o]=s[i];return n},o=function(){function t(){this._listeners=new Map,this._onceListeners=new Map}return t.prototype.on=function(t,e){var r=this._listeners.get(t)||new Set;if("function"!=typeof e)throw new Error("Second argument must be a function");r.add(e),this._listeners.set(t,r)},t.prototype.once=function(t,e){var r=this._onceListeners.get(t)||new Set;if("function"!=typeof e)throw new Error("Second argument must be a function");r.add(e),this._onceListeners.set(t,r)},t.prototype.off=function(t,e){var r=this._listeners.get(t),n=this._onceListeners.get(t);if("function"!=typeof e)throw new Error("Second argument must be a function");r&&r.delete(e),n&&n.delete(e)},t.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];var o=this._onceListeners.get(t),s=this._listeners.get(t),i=this._listeners.get("*");o&&(o.forEach((function(t){return t.apply(void 0,e)})),this._onceListeners.delete(t)),s&&s.forEach((function(t){return t.apply(void 0,e)})),i&&i.forEach((function(r){return r.apply(void 0,n([t],e))}))},t.prototype.stopListening=function(){this._listeners.clear(),this._onceListeners.clear()},t}()},function(t,e,r){"use strict";var n,o,s=r(5),i=r.n(s),u=r(6),a=r.n(u),c=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),f=function(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,u)}a((n=n.apply(t,e||[])).next())}))},l=function(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},h=function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),o=0;for(e=0;e<r;e++)for(var s=arguments[e],i=0,u=s.length;i<u;i++,o++)n[o]=s[i];return n};!function(t){t.LOCAL="local",t.INDEX_DB="index_db"}(o||(o={}));var p=function(t){function e(){var e=t.call(this,"processes")||this;return e.version(1).stores({processes:"&id,userId,process,prevTask,task,state,vars"}),e}return c(e,t),e}(a.a),d=function(){this.storage=[]},y=function(){function t(t){if(this._type=t,this._type===o.LOCAL)this._local=new d;else{if(this._type!==o.INDEX_DB)throw new Error("DB: wrong type of database");this._db=new p}}return t.prototype.genId=function(){return i()()},t.prototype.create=function(t){return f(this,void 0,void 0,(function(){var e,r;return l(this,(function(n){switch(n.label){case 0:if(t.id||(e=this.genId(),t.id=e),this._type!==o.INDEX_DB||!this._db||!this._db.processes)return[3,5];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._db.processes.add(t)];case 2:return n.sent(),[3,4];case 3:throw r=n.sent(),console.error(r),r;case 4:return[3,6];case 5:if(!this._local||this._type!==o.LOCAL)throw new Error("DB: wrong type of database");this._local.storage.push(t),n.label=6;case 6:return[4,this.get(t.id)];case 7:return[2,n.sent()]}}))}))},t.prototype.list=function(t,e){return f(this,void 0,void 0,(function(){var r,n;return l(this,(function(s){switch(s.label){case 0:if(this._type!==o.INDEX_DB||!this._db||!this._db.processes)return[3,8];n=void 0,s.label=1;case 1:return s.trys.push([1,6,,7]),e?[4,this._db.processes.toCollection().filter((function(r){return t?r.userId===t&&e(r):e(r)})).toArray()]:[3,3];case 2:return n=s.sent(),[3,5];case 3:return[4,this._db.processes.toCollection().toArray()];case 4:n=s.sent(),s.label=5;case 5:return[3,7];case 6:throw r=s.sent(),console.error(r),r;case 7:return[2,n];case 8:if(this._local&&this._type===o.LOCAL)return n=void 0,[2,n=e?this._local.storage.filter((function(r){return t?r.userId===t&&e(r):e(r)})):h(this._local.storage)];throw new Error("DB: wrong type of database");case 9:return[2]}}))}))},t.prototype.get=function(t){return f(this,void 0,void 0,(function(){var e,r;return l(this,(function(n){switch(n.label){case 0:if(this._type!==o.INDEX_DB||!this._db||!this._db.processes)return[3,5];r=void 0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this._db.processes.where("id").equals(t).toArray()];case 2:return r=n.sent(),[3,4];case 3:throw e=n.sent(),console.error(e),e;case 4:if(!r[0])throw new Error("ProcessDTO not found");return[2,r[0]];case 5:if(this._local&&this._type===o.LOCAL){if(!(r=this._local.storage.find((function(e){return e.id===t}))))throw new Error("ProcessDTO not found");return[2,r]}throw new Error("DB: wrong type of database");case 6:return[2]}}))}))},t.prototype.update=function(t,e){return f(this,void 0,void 0,(function(){var r,n,s;return l(this,(function(i){switch(i.label){case 0:return[4,this.get(t)];case 1:if(r=i.sent(),(r=Object.assign(r,e)).vars&&(r.vars=Object.assign(r.vars,e.vars)),this._type!==o.INDEX_DB||!this._db||!this._db.processes)return[3,6];i.label=2;case 2:return i.trys.push([2,4,,5]),[4,this._db.processes.update(t,r)];case 3:return i.sent(),[3,5];case 4:throw n=i.sent(),console.error(n),n;case 5:return[3,7];case 6:if(!this._local||this._type!==o.LOCAL)throw new Error("DB: wrong type of database");(s=this._local.storage.findIndex((function(e){return e.id===t})))>=0&&(this._local.storage.splice(s,1),this._local.storage.push(r)),i.label=7;case 7:return[4,this.get(t)];case 8:return[2,i.sent()]}}))}))},t.prototype.remove=function(t){return f(this,void 0,void 0,(function(){var e,r,n;return l(this,(function(s){switch(s.label){case 0:return[4,this.get(t)];case 1:if(e=s.sent(),this._type!==o.INDEX_DB||!this._db||!this._db.processes)return[3,6];s.label=2;case 2:return s.trys.push([2,4,,5]),[4,this._db.processes.delete(t)];case 3:return s.sent(),[3,5];case 4:throw r=s.sent(),console.error(r),r;case 5:return[3,7];case 6:if(!this._local||this._type!==o.LOCAL)throw new Error("DB: wrong type of database");(n=this._local.storage.findIndex((function(e){return e.id===t})))>=0&&this._local.storage.splice(n,1),s.label=7;case 7:return[2,e]}}))}))},t.prototype.updateVars=function(t,e){return f(this,void 0,void 0,(function(){var r;return l(this,(function(n){switch(n.label){case 0:return[4,this.get(t)];case 1:return(r=n.sent()).vars=Object.assign(r.vars,e),[4,this.update(t,r)];case 2:return[2,n.sent()]}}))}))},t}();r.d(e,"a",(function(){return y})),r.d(e,"b",(function(){return o}))},function(t,e,r){"use strict";r.d(e,"a",(function(){return a}));var n,o=r(1),s=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=function(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,u)}a((n=n.apply(t,e||[])).next())}))},u=function(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},a=function(t){function e(e){var r=t.call(this)||this;return r._db=e,r}return s(e,t),e.prototype.run=function(){return i(this,void 0,void 0,(function(){return u(this,(function(t){throw new Error('Method "run" is not implemented')}))}))},e.prototype.destroy=function(){delete this._db,this.stopListening()},e.prototype.pause=function(){return i(this,void 0,void 0,(function(){return u(this,(function(t){throw new Error('Method "pause" is not implemented')}))}))},e.prototype.resume=function(){return i(this,void 0,void 0,(function(){return u(this,(function(t){throw new Error('Method "resume" is not implemented')}))}))},e.prototype.cancel=function(){return i(this,void 0,void 0,(function(){return u(this,(function(t){throw new Error('Method "cancel" is not implemented')}))}))},e}(o.a)},function(t,e,r){"use strict";(function(t){r.d(e,"a",(function(){return d}));var n,o=r(1),s=r(2),i=r(0),u=r(3),a=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),c=function(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,u)}a((n=n.apply(t,e||[])).next())}))},f=function(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},l=function(t){return this instanceof l?(this.v=t,this):new l(t)},h=function(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(t,e||[]),s=[];return n={},i("next"),i("throw"),i("return"),n[Symbol.asyncIterator]=function(){return this},n;function i(t){o[t]&&(n[t]=function(e){return new Promise((function(r,n){s.push([t,e,r,n])>1||u(t,e)}))})}function u(t,e){try{(r=o[t](e)).value instanceof l?Promise.resolve(r.value.v).then(a,c):f(s[0][2],r)}catch(t){f(s[0][3],t)}var r}function a(t){u("next",t)}function c(t){u("throw",t)}function f(t,e){t(e),s.shift(),s.length&&u(s[0][0],s[0][1])}},p=function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;var n=Array(t),o=0;for(e=0;e<r;e++)for(var s=arguments[e],i=0,u=s.length;i<u;i++,o++)n[o]=s[i];return n},d=function(e){function r(r,n,o){void 0===r&&(r=""),void 0===n&&(n={});var u=e.call(this)||this;if(u._currentStep=null,u.id="",u._currentStep=null,u._db="object"==typeof t?new s.a(s.b.LOCAL):new s.a(s.b.INDEX_DB),o)u.id=o;else{var a=u._db.genId(),c={id:a,userId:r,process:u.name,step:0,state:i.a.START,vars:n||{}};u.id=a,u._db.create(c)}return u}return a(r,e),Object.defineProperty(r.prototype,"name",{get:function(){throw new Error('Getter property "name" is not implemented')},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"tasks",{get:function(){throw new Error('Getter property "tasks" is not implemented')},enumerable:!0,configurable:!0}),r.prototype._getDTO=function(){return c(this,void 0,void 0,(function(){return f(this,(function(t){switch(t.label){case 0:return[4,this._db.get(this.id)];case 1:return[2,t.sent()]}}))}))},r.prototype._setState=function(t){return c(this,void 0,void 0,(function(){var e;return f(this,(function(r){switch(r.label){case 0:return[4,this._getDTO()];case 1:return(e=r.sent()).state=t,[4,this._db.update(this.id,e)];case 2:return[2,r.sent()]}}))}))},r.prototype._setStep=function(t){return c(this,void 0,void 0,(function(){var e;return f(this,(function(r){switch(r.label){case 0:return[4,this._getDTO()];case 1:return(e=r.sent()).step=t,[4,this._db.update(this.id,e)];case 2:return[2,r.sent()]}}))}))},r.prototype._runTask=function(t,e,r,n,o){return c(this,void 0,void 0,(function(){var s,a,c,l,h,d,y=this;return f(this,(function(f){switch(f.label){case 0:return[4,this._getDTO()];case 1:return(s=f.sent()).state===i.a.PAUSE?(setTimeout((function(){return y._runTask(t,e,r,n,o)}),1e3),[2]):s.state===i.a.DONE||s.state===i.a.CANCEL||s.state===i.a.ERROR?[2]:e===r?[2]:0!==e||s.state!==i.a.START?[3,3]:[4,this._setState(i.a.IN_PROGRESS)];case 2:s=f.sent(),this.emit(i.a.START,s),f.label=3;case 3:return s.state!==i.a.IN_PROGRESS?[3,25]:[4,this._setStep(e)];case 4:return s=f.sent(),[4,this.gateway(t,e,s)];case 5:if(t=f.sent(),this.emit("task/before",s),!(t.prototype instanceof u.a))return[3,14];a=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return y.emit.apply(y,p(["task/"+t],e))},c=new t(this._db),d=void 0,this._currentStep=c,c.on("*",a),f.label=6;case 6:return f.trys.push([6,8,,9]),[4,c.run()];case 7:return f.sent(),[3,9];case 8:return l=f.sent(),d=l,[3,9];case 9:return d?[4,this._setState(i.a.ERROR)]:[3,11];case 10:return s=f.sent(),this.emit(i.a.ERROR,d,s),o(d),[3,13];case 11:return[4,this._getDTO()];case 12:s=f.sent(),this.emit("task",s,e),n(),f.label=13;case 13:return c.off("*",a),c.destroy(),[3,25];case 14:if("function"!=typeof t)return[3,23];d=void 0,this._currentStep=t,f.label=15;case 15:return f.trys.push([15,17,,18]),[4,t(this._db)];case 16:return f.sent(),[3,18];case 17:return h=f.sent(),d=h,[3,18];case 18:return d?[4,this._setState(i.a.ERROR)]:[3,20];case 19:return s=f.sent(),this.emit(i.a.ERROR,d,s),o(d),[3,22];case 20:return[4,this._getDTO()];case 21:s=f.sent(),this.emit("task",s),n(),f.label=22;case 22:return[3,25];case 23:return d=new Error("Process: unknown task"),[4,this._setState(i.a.ERROR)];case 24:s=f.sent(),this.emit(i.a.ERROR,d,s),o(d),f.label=25;case 25:return[2]}}))}))},r.prototype._delayRunTask=function(t,e,r){var n=this;return new Promise((function(o,s){return n._runTask(t,e,r,o,s)}))},r.prototype.runTasks=function(){return h(this,arguments,(function(){var t,e,r,n;return f(this,(function(o){switch(o.label){case 0:return[4,l(this._getDTO())];case 1:t=o.sent(),e=t.step,r=this.tasks.length,n=e,o.label=2;case 2:if(!(n<r))return[3,10];o.label=3;case 3:return o.trys.push([3,5,,6]),[4,l(this._delayRunTask(this.tasks[n],n,r))];case 4:return o.sent(),[3,6];case 5:throw o.sent();case 6:return[4,l(void 0)];case 7:return[4,o.sent()];case 8:o.sent(),o.label=9;case 9:return n++,[3,2];case 10:return[4,l(!0)];case 11:return[2,o.sent()]}}))}))},r.prototype._run=function(){return c(this,void 0,void 0,(function(){var t;return f(this,(function(e){switch(e.label){case 0:t=this.runTasks(),e.label=1;case 1:return[4,t.next()];case 2:return e.sent().done?(this.emit(i.a.DONE),[3,3]):[3,1];case 3:return[2,!0]}}))}))},r.prototype.run=function(){var t=this;return new Promise((function(e,r){setTimeout((function(){return c(t,void 0,void 0,(function(){var t;return f(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this._run()];case 1:return n.sent(),e(),[3,3];case 2:return t=n.sent(),r(t),[3,3];case 3:return[2]}}))}))}),0)}))},r.prototype.gateway=function(t,e,r){return c(this,void 0,void 0,(function(){return f(this,(function(e){return[2,t]}))}))},r.prototype.pause=function(){return c(this,void 0,void 0,(function(){var t;return f(this,(function(e){switch(e.label){case 0:return[4,this._getDTO()];case 1:return(t=e.sent()).state!==i.a.IN_PROGRESS?[3,5]:[4,this._setState(i.a.PAUSE)];case 2:return t=e.sent(),this._currentStep&&this._currentStep.pause?[4,this._currentStep.pause()]:[3,4];case 3:e.sent(),this.emit(i.a.PAUSE,t),e.label=4;case 4:return[3,6];case 5:throw new Error('Process: you can pause process only with status "in progress"');case 6:return[2]}}))}))},r.prototype.resume=function(){return c(this,void 0,void 0,(function(){var t;return f(this,(function(e){switch(e.label){case 0:return[4,this._getDTO()];case 1:return(t=e.sent()).state!==i.a.PAUSE?[3,5]:[4,this._setState(i.a.IN_PROGRESS)];case 2:return t=e.sent(),this._currentStep&&this._currentStep.resume?[4,this._currentStep.resume()]:[3,4];case 3:e.sent(),this.emit("resume",t),e.label=4;case 4:return[3,6];case 5:throw new Error('Process: you can resume process only with status "pause"');case 6:return[2]}}))}))},r.prototype.cancel=function(){return c(this,void 0,void 0,(function(){var t,e;return f(this,(function(r){switch(r.label){case 0:return[4,this._getDTO()];case 1:return t=r.sent(),(e=t.state)!==i.a.START&&e!==i.a.IN_PROGRESS&&e!==i.a.PAUSE?[3,5]:[4,this._setState(i.a.CANCEL)];case 2:return t=r.sent(),this._currentStep&&this._currentStep.cancel?[4,this._currentStep.cancel()]:[3,4];case 3:r.sent(),this.emit(i.a.CANCEL,t),r.label=4;case 4:return[3,6];case 5:throw new Error('Process: you can cancel process only with statused "start | in progress | pause"');case 6:return[2]}}))}))},r.prototype.status=function(){return c(this,void 0,void 0,(function(){var t;return f(this,(function(e){switch(e.label){case 0:return[4,this._getDTO()];case 1:return t=e.sent(),[2,{process:t.process,step:t.step,state:t.state}]}}))}))},r.prototype.getVars=function(){return c(this,void 0,void 0,(function(){return f(this,(function(t){switch(t.label){case 0:return[4,this._getDTO()];case 1:return[2,t.sent().vars]}}))}))},r.prototype.getCurrentStep=function(){return this._currentStep},r}(o.a)}).call(this,r(7))},function(t,e,r){var n=r(8),o=r(9);t.exports=function(t,e,r){var s=e&&r||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var i=(t=t||{}).random||(t.rng||n)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,e)for(var u=0;u<16;++u)e[s+u]=i[u];return e||o(i)}},function(e,r){e.exports=t},function(t,e){var r,n,o=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function u(t){if(r===setTimeout)return setTimeout(t,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(t){r=s}try{n="function"==typeof clearTimeout?clearTimeout:i}catch(t){n=i}}();var a,c=[],f=!1,l=-1;function h(){f&&a&&(f=!1,a.length?c=a.concat(c):l=-1,c.length&&p())}function p(){if(!f){var t=u(h);f=!0;for(var e=c.length;e;){for(a=c,c=[];++l<e;)a&&a[l].run();l=-1,e=c.length}a=null,f=!1,function(t){if(n===clearTimeout)return clearTimeout(t);if((n===i||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(t);try{n(t)}catch(e){try{return n.call(null,t)}catch(e){return n.call(this,t)}}}(t)}}function d(t,e){this.fun=t,this.array=e}function y(){}o.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];c.push(new d(t,e)),1!==c.length||f||u(p)},d.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(t){return[]},o.binding=function(t){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(t){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(t,e){var r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(r){var n=new Uint8Array(16);t.exports=function(){return r(n),n}}else{var o=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),o[e]=t>>>((3&e)<<3)&255;return o}}},function(t,e){for(var r=[],n=0;n<256;++n)r[n]=(n+256).toString(16).substr(1);t.exports=function(t,e){var n=e||0,o=r;return[o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]]].join("")}},function(t,e,r){"use strict";r.r(e);var n,o=r(1),s=r(0),i=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),u=function(t,e,r,n){return new(r||(r=Promise))((function(o,s){function i(t){try{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,u)}a((n=n.apply(t,e||[])).next())}))},a=function(t,e){var r,n,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function u(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},c=function(t){function e(e){void 0===e&&(e="");var r=t.call(this)||this;return r._registeredProcesses=new Map,r._activeProcesses=new Map,r.userId="",r.userId=e,r}return i(e,t),e.prototype.register=function(t,e){this._registeredProcesses.set(t,e)},e.prototype.create=function(t,e,r){return u(this,void 0,void 0,(function(){var n,o,i,u=this;return a(this,(function(a){return n=this._registeredProcesses.get(t),o=r?new n(this.userId,e,r):new n(this.userId,e),this._activeProcesses.set(o.id,o),i=function(){o.off(s.a.CANCEL,i),o.off(s.a.ERROR,i),o.off(s.a.DONE,i),u._activeProcesses.delete(o.id)},o.on(s.a.CANCEL,i),o.on(s.a.ERROR,i),o.on(s.a.DONE,i),[2,o]}))}))},e.prototype.status=function(t){return u(this,void 0,void 0,(function(){var e;return a(this,(function(r){switch(r.label){case 0:return(e=this._activeProcesses.get(t))?[4,e.status()]:[3,2];case 1:return[2,r.sent()];case 2:throw new Error('Process ID: "'+t+'" not found')}}))}))},e.prototype.get=function(t){var e=this._activeProcesses.get(t);if(e)return e;throw new Error('Process ID: "'+t+'" not found')},e.prototype.list=function(t){var e=Array.from(this._activeProcesses.values());return t?e.filter(t):e},e}(o.a),f=r(4),l=r(3);r.d(e,"EventEmitter",(function(){return o.a})),r.d(e,"ProcessManager",(function(){return c})),r.d(e,"Process",(function(){return f.a})),r.d(e,"Task",(function(){return l.a}))}])})); //# sourceMappingURL=index.js.map