@peter.naydenov/fsm-hub 2.1.3 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Chaingelog.md CHANGED
@@ -1,6 +1,17 @@
1
1
  ## Release History
2
2
 
3
3
 
4
+ ### 2.1.5 ( 2026-07-21)
5
+ - [x] Dependency update. ask-for-promise@3.2.0;
6
+ - [x] Dev dependency update. @peter.naydenov/fsm - v.5.2.6;
7
+
8
+
9
+
10
+ ### 2.1.4 ( 2026-05-11)
11
+ - [x] Dependency update. ask-for-promise@3.1.1;
12
+ - [x] Dev dependency update. @peter.naydenov/fsm - v.5.2.5;
13
+
14
+
4
15
 
5
16
  ### 2.1.2 ( 2024-11-13)
6
17
  - [x] Dependency update. Ask-for-promise@3.1.0;
package/dist/fsm-hub.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("ask-for-promise"),n=require("@peter.naydenov/stack");const r={_setTransitions:function(e,n){return function({reactivity:r,transformers:t},s={}){let a={},c={},o={},i={};return r.forEach(((r,t)=>{if(!(r instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,t+1);const s=r.length,[a,u,l,f]=r;if(!(4==s||3==s))return void e._debugger(n.WRONG_REACTIVITY_RECORD,t+1);const h=`${a}/${u}`;if(4==s){c[h]||(c[h]=[]),c[h].push(l);o[`${h}/${l}`]=f}3==s&&(i[h]||(i[h]=[]),i[h].push(l))})),t&&Object.keys(t).forEach((e=>{const n=t[e],r=s[n];r&&(a[e]=r)})),{transformers:a,subscribers:c,callbacks:i,actions:o}}},_debugger:function(e){return function(n,r){e.debug&&console.log(n,r)}},_callback:function(n,r){return function(t,s,a,c){const o=`${s}/${a}`,i=n.subscribers[o]||!1,u=n.callbacks[o]||!1,l=n.fnCallbacks,f=n.actions,h=[];let d;if(i||u){if(i&&i.forEach((e=>{if(!n.fsm[e])return void n._debugger(r.MISSING_FSM,i);const t=f[`${o}/${e}`],u=`${s}/${e}`,l=n.transformers[u];d="function"==typeof l?l(a,c):c,d||(d={},d.___internalFlag=!0);const _=n.fsm[e].update(t,d);h.push(_)})),u){let t=e();h.push(t.promise),u.forEach((e=>{const t=l[e],o=`${s}/${e}`,i=n.transformers[o];d="function"==typeof i?i(a,c):c,d.answer&&d.answer.hasOwnProperty("___internalFlag")&&(d.answer=void 0),"function"==typeof t?t(d):n._debugger(r.MISSING_FN,e)})),t.done()}Promise.all(h).then((()=>t.done()))}else t.done()}},addFsm:function(n,r){return function(t){Object.keys(t).forEach((s=>{function a(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let r=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&r)return void(n.lock=!1);let[t,s,a]=r?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),c(t,s,a)}function c(r,t,s){let c;if(!n.lock)return n.lock=!0,c=e(),c.onComplete((e=>a(!1))),void n._callback(c,r,t,s);if(s){if(n.haveInternalRequest)return void n.cacheInternal.push([[r,t,s]]);let c=e();return c.onComplete((e=>a(!0))),n.haveInternalRequest=!0,void n._callback(c,r,t,s)}n.cache.push([[r,t,s]])}n.fsm[s]?n._debugger(r.REGISTERED_FSM_NAME,s):(n.fsm[s]=t[s],n.fsm[s].on("update",((e,n)=>c(s,e,n))))}))}},addFunctions:function(e,n){return function(r){Object.keys(r).forEach((t=>{e.fnCallbacks[t]?e._debugger(n.REGISTERED_FUNCTION_NAME,t):e.fnCallbacks[t]=r[t]}))}}},t={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};module.exports=function(s,a){const c=this,o=Object.keys(r);c.fsm={},c.fnCallbacks={},c.debug=s.debug||!1,c.cache=n({type:"FIFO"}),c.cacheInternal=n({type:"FIFO"}),c.wait=[],c.lock=!1,c.haveInternalRequest=!1,c.reactivityTask=!1,c.askForPromise=e,o.forEach((e=>{c[e]=r[e](c,t)}));const{transformers:i,subscribers:u,actions:l,callbacks:f}=c._setTransitions(s,a);c.transformers=i,c.subscribers=u,c.actions=l,c.callbacks=f};
1
+ "use strict";var e=require("ask-for-promise"),n=require("@peter.naydenov/stack");const r={_setTransitions:function(e,n){return function({reactivity:r,transformers:t},s={}){let a={},c={},o={},i={};return r.forEach((r,t)=>{if(!(r instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,t+1);const s=r.length,[a,u,l,f]=r;if(!(4==s||3==s))return void e._debugger(n.WRONG_REACTIVITY_RECORD,t+1);const h=`${a}/${u}`;if(4==s){c[h]||(c[h]=[]),c[h].push(l);o[`${h}/${l}`]=f}3==s&&(i[h]||(i[h]=[]),i[h].push(l))}),t&&Object.keys(t).forEach(e=>{const n=t[e],r=s[n];r&&(a[e]=r)}),{transformers:a,subscribers:c,callbacks:i,actions:o}}},_debugger:function(e){return function(n,r){e.debug&&console.log(n,r)}},_callback:function(n,r){return function(t,s,a,c){const o=`${s}/${a}`,i=n.subscribers[o]||!1,u=n.callbacks[o]||!1,l=n.fnCallbacks,f=n.actions,h=[];let d;if(i||u){if(i&&i.forEach(e=>{if(!n.fsm[e])return void n._debugger(r.MISSING_FSM,i);const t=f[`${o}/${e}`],u=`${s}/${e}`,l=n.transformers[u];d="function"==typeof l?l(a,c):c,d||(d={},d.___internalFlag=!0);const _=n.fsm[e].update(t,d);h.push(_)}),u){let t=e();h.push(t.promise),u.forEach(e=>{const t=l[e],o=`${s}/${e}`,i=n.transformers[o];d="function"==typeof i?i(a,c):c,d.answer&&d.answer.hasOwnProperty("___internalFlag")&&(d.answer=void 0),"function"==typeof t?t(d):n._debugger(r.MISSING_FN,e)}),t.done()}Promise.all(h).then(()=>t.done())}else t.done()}},addFsm:function(n,r){return function(t){Object.keys(t).forEach(s=>{function a(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let r=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&r)return void(n.lock=!1);let[t,s,a]=r?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),c(t,s,a)}function c(r,t,s){let c;if(!n.lock)return n.lock=!0,c=e(),c.onComplete(e=>a(!1)),void n._callback(c,r,t,s);if(s){if(n.haveInternalRequest)return void n.cacheInternal.push([[r,t,s]]);let c=e();return c.onComplete(e=>a(!0)),n.haveInternalRequest=!0,void n._callback(c,r,t,s)}n.cache.push([[r,t,s]])}n.fsm[s]?n._debugger(r.REGISTERED_FSM_NAME,s):(n.fsm[s]=t[s],n.fsm[s].on("update",(e,n)=>c(s,e,n)))})}},addFunctions:function(e,n){return function(r){Object.keys(r).forEach(t=>{e.fnCallbacks[t]?e._debugger(n.REGISTERED_FUNCTION_NAME,t):e.fnCallbacks[t]=r[t]})}}},t={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};module.exports=function(s,a){const c=this,o=Object.keys(r);c.fsm={},c.fnCallbacks={},c.debug=s.debug||!1,c.cache=n({type:"FIFO"}),c.cacheInternal=n({type:"FIFO"}),c.wait=[],c.lock=!1,c.haveInternalRequest=!1,c.reactivityTask=!1,c.askForPromise=e,o.forEach(e=>{c[e]=r[e](c,t)});const{transformers:i,subscribers:u,actions:l,callbacks:f}=c._setTransitions(s,a);c.transformers=i,c.subscribers=u,c.actions=l,c.callbacks=f};
@@ -1 +1 @@
1
- import e from"ask-for-promise";import n from"@peter.naydenov/stack";const t={_setTransitions:function(e,n){return function({reactivity:t,transformers:r},s={}){let a={},c={},o={},i={};return t.forEach(((t,r)=>{if(!(t instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const s=t.length,[a,u,l,f]=t;if(!(4==s||3==s))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const h=`${a}/${u}`;if(4==s){c[h]||(c[h]=[]),c[h].push(l);o[`${h}/${l}`]=f}3==s&&(i[h]||(i[h]=[]),i[h].push(l))})),r&&Object.keys(r).forEach((e=>{const n=r[e],t=s[n];t&&(a[e]=t)})),{transformers:a,subscribers:c,callbacks:i,actions:o}}},_debugger:function(e){return function(n,t){e.debug&&console.log(n,t)}},_callback:function(n,t){return function(r,s,a,c){const o=`${s}/${a}`,i=n.subscribers[o]||!1,u=n.callbacks[o]||!1,l=n.fnCallbacks,f=n.actions,h=[];let d;if(i||u){if(i&&i.forEach((e=>{if(!n.fsm[e])return void n._debugger(t.MISSING_FSM,i);const r=f[`${o}/${e}`],u=`${s}/${e}`,l=n.transformers[u];d="function"==typeof l?l(a,c):c,d||(d={},d.___internalFlag=!0);const _=n.fsm[e].update(r,d);h.push(_)})),u){let r=e();h.push(r.promise),u.forEach((e=>{const r=l[e],o=`${s}/${e}`,i=n.transformers[o];d="function"==typeof i?i(a,c):c,d.answer&&d.answer.hasOwnProperty("___internalFlag")&&(d.answer=void 0),"function"==typeof r?r(d):n._debugger(t.MISSING_FN,e)})),r.done()}Promise.all(h).then((()=>r.done()))}else r.done()}},addFsm:function(n,t){return function(r){Object.keys(r).forEach((s=>{function a(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let t=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&t)return void(n.lock=!1);let[r,s,a]=t?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),c(r,s,a)}function c(t,r,s){let c;if(!n.lock)return n.lock=!0,c=e(),c.onComplete((e=>a(!1))),void n._callback(c,t,r,s);if(s){if(n.haveInternalRequest)return void n.cacheInternal.push([[t,r,s]]);let c=e();return c.onComplete((e=>a(!0))),n.haveInternalRequest=!0,void n._callback(c,t,r,s)}n.cache.push([[t,r,s]])}n.fsm[s]?n._debugger(t.REGISTERED_FSM_NAME,s):(n.fsm[s]=r[s],n.fsm[s].on("update",((e,n)=>c(s,e,n))))}))}},addFunctions:function(e,n){return function(t){Object.keys(t).forEach((r=>{e.fnCallbacks[r]?e._debugger(n.REGISTERED_FUNCTION_NAME,r):e.fnCallbacks[r]=t[r]}))}}},r={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};function s(s,a){const c=this,o=Object.keys(t);c.fsm={},c.fnCallbacks={},c.debug=s.debug||!1,c.cache=n({type:"FIFO"}),c.cacheInternal=n({type:"FIFO"}),c.wait=[],c.lock=!1,c.haveInternalRequest=!1,c.reactivityTask=!1,c.askForPromise=e,o.forEach((e=>{c[e]=t[e](c,r)}));const{transformers:i,subscribers:u,actions:l,callbacks:f}=c._setTransitions(s,a);c.transformers=i,c.subscribers=u,c.actions=l,c.callbacks=f}export{s as default};
1
+ import e from"ask-for-promise";import n from"@peter.naydenov/stack";const t={_setTransitions:function(e,n){return function({reactivity:t,transformers:r},s={}){let a={},c={},o={},i={};return t.forEach((t,r)=>{if(!(t instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const s=t.length,[a,u,l,f]=t;if(!(4==s||3==s))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const h=`${a}/${u}`;if(4==s){c[h]||(c[h]=[]),c[h].push(l);o[`${h}/${l}`]=f}3==s&&(i[h]||(i[h]=[]),i[h].push(l))}),r&&Object.keys(r).forEach(e=>{const n=r[e],t=s[n];t&&(a[e]=t)}),{transformers:a,subscribers:c,callbacks:i,actions:o}}},_debugger:function(e){return function(n,t){e.debug&&console.log(n,t)}},_callback:function(n,t){return function(r,s,a,c){const o=`${s}/${a}`,i=n.subscribers[o]||!1,u=n.callbacks[o]||!1,l=n.fnCallbacks,f=n.actions,h=[];let d;if(i||u){if(i&&i.forEach(e=>{if(!n.fsm[e])return void n._debugger(t.MISSING_FSM,i);const r=f[`${o}/${e}`],u=`${s}/${e}`,l=n.transformers[u];d="function"==typeof l?l(a,c):c,d||(d={},d.___internalFlag=!0);const _=n.fsm[e].update(r,d);h.push(_)}),u){let r=e();h.push(r.promise),u.forEach(e=>{const r=l[e],o=`${s}/${e}`,i=n.transformers[o];d="function"==typeof i?i(a,c):c,d.answer&&d.answer.hasOwnProperty("___internalFlag")&&(d.answer=void 0),"function"==typeof r?r(d):n._debugger(t.MISSING_FN,e)}),r.done()}Promise.all(h).then(()=>r.done())}else r.done()}},addFsm:function(n,t){return function(r){Object.keys(r).forEach(s=>{function a(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let t=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&t)return void(n.lock=!1);let[r,s,a]=t?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),c(r,s,a)}function c(t,r,s){let c;if(!n.lock)return n.lock=!0,c=e(),c.onComplete(e=>a(!1)),void n._callback(c,t,r,s);if(s){if(n.haveInternalRequest)return void n.cacheInternal.push([[t,r,s]]);let c=e();return c.onComplete(e=>a(!0)),n.haveInternalRequest=!0,void n._callback(c,t,r,s)}n.cache.push([[t,r,s]])}n.fsm[s]?n._debugger(t.REGISTERED_FSM_NAME,s):(n.fsm[s]=r[s],n.fsm[s].on("update",(e,n)=>c(s,e,n)))})}},addFunctions:function(e,n){return function(t){Object.keys(t).forEach(r=>{e.fnCallbacks[r]?e._debugger(n.REGISTERED_FUNCTION_NAME,r):e.fnCallbacks[r]=t[r]})}}},r={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};function s(s,a){const c=this,o=Object.keys(t);c.fsm={},c.fnCallbacks={},c.debug=s.debug||!1,c.cache=n({type:"FIFO"}),c.cacheInternal=n({type:"FIFO"}),c.wait=[],c.lock=!1,c.haveInternalRequest=!1,c.reactivityTask=!1,c.askForPromise=e,o.forEach(e=>{c[e]=t[e](c,r)});const{transformers:i,subscribers:u,actions:l,callbacks:f}=c._setTransitions(s,a);c.transformers=i,c.subscribers=u,c.actions=l,c.callbacks=f}export{s as default};
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).fsmHub=n()}(this,(function(){"use strict";function e(e){return e?function(e){let o=e.map((e=>n())),c=o.map((e=>e.promise));o.promises=o;let s=t(Promise.all(c));function i(e){let n="pending";return e.then((()=>n="fulfilled")).catch((()=>n="rejected")),n}function l(n,...t){o.forEach(((r,o)=>n({value:e[o],done:r.done,cancel:r.cancel,timeout:r.timeout,state:i(r.promise)},...t)))}const a={promise:Promise.all(c),promises:o,done:e=>{o.forEach((n=>n.done(e)))},cancel:e=>{o.forEach((n=>n.cancel(e)))},each:l,onComplete:s,timeout:()=>{}};return a.timeout=r(!0,a),a}(e):n()}function n(){let e,n;const o=new Promise(((t,r)=>{e=t,n=r})),c={promise:o,promises:null,done:e,cancel:n,each:()=>{},onComplete:t(o),timeout:()=>{}};return c.timeout=r(!1,c),c.each=(t,...r)=>{t({value:null,done:e,cancel:n,timeout:c.timeout},...r)},c}function t(e){return function(n,t=null){null===t?e.then((e=>n(e))):e.then((e=>n(e)),(e=>t(e)))}}function r(e,n){let r;return r=e?Promise.all(n.promises.map((e=>e.promise))):n.promise,function(e,o){let c,s=new Promise(((n,t)=>{c=setTimeout((()=>{n(o),Promise.resolve(r)}),e)}));return r.then((()=>clearTimeout(c))),n.onComplete=t(Promise.race([r,s])),n}}e.sequence=function(n,...t){const r=e(),o=[];const c=function*(e){for(const n of e)yield n}(n);return function e(n,...t){n.done?r.done(o):n.value(...t).then((n=>{o.push(n),e(c.next(),...t,n)}))}(c.next(),...t),r},e.all=function(n,...t){const r=e(),o=[],c=n.map(((e,n)=>"function"==typeof e?e(...t).then((e=>o[n]=e)):e.then((e=>o[n]=e))));return Promise.all(c).then((()=>r.done(o))),r};const o={_setTransitions:function(e,n){return function({reactivity:t,transformers:r},o={}){let c={},s={},i={},l={};return t.forEach(((t,r)=>{if(!(t instanceof Array))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const o=t.length,[c,a,u,f]=t;if(!(4==o||3==o))return void e._debugger(n.WRONG_REACTIVITY_RECORD,r+1);const p=`${c}/${a}`;if(4==o){s[p]||(s[p]=[]),s[p].push(u);i[`${p}/${u}`]=f}3==o&&(l[p]||(l[p]=[]),l[p].push(u))})),r&&Object.keys(r).forEach((e=>{const n=r[e],t=o[n];t&&(c[e]=t)})),{transformers:c,subscribers:s,callbacks:l,actions:i}}},_debugger:function(e){return function(n,t){e.debug&&console.log(n,t)}},_callback:function(n,t){return function(r,o,c,s){const i=`${o}/${c}`,l=n.subscribers[i]||!1,a=n.callbacks[i]||!1,u=n.fnCallbacks,f=n.actions,p=[];let h;if(l||a){if(l&&l.forEach((e=>{if(!n.fsm[e])return void n._debugger(t.MISSING_FSM,l);const r=f[`${i}/${e}`],a=`${o}/${e}`,u=n.transformers[a];h="function"==typeof u?u(c,s):s,h||(h={},h.___internalFlag=!0);const m=n.fsm[e].update(r,h);p.push(m)})),a){let r=e();p.push(r.promise),a.forEach((e=>{const r=u[e],i=`${o}/${e}`,l=n.transformers[i];h="function"==typeof l?l(c,s):s,h.answer&&h.answer.hasOwnProperty("___internalFlag")&&(h.answer=void 0),"function"==typeof r?r(h):n._debugger(t.MISSING_FN,e)})),r.done()}Promise.all(p).then((()=>r.done()))}else r.done()}},addFsm:function(n,t){return function(r){Object.keys(r).forEach((o=>{function c(e){if(e&&(n.haveInternalRequest=!1),n.haveInternalRequest)return;let t=n.cacheInternal.isEmpty();if(n.cache.isEmpty()&&t)return void(n.lock=!1);let[r,o,c]=t?n.cache.pull():n.cacheInternal.pull();n.cache.isEmpty()&&(n.lock=!1),n.cacheInternal.isEmpty()&&(n.haveInternalRequest=!1),s(r,o,c)}function s(t,r,o){let s;if(!n.lock)return n.lock=!0,s=e(),s.onComplete((e=>c(!1))),void n._callback(s,t,r,o);if(o){if(n.haveInternalRequest)return void n.cacheInternal.push([[t,r,o]]);let s=e();return s.onComplete((e=>c(!0))),n.haveInternalRequest=!0,void n._callback(s,t,r,o)}n.cache.push([[t,r,o]])}n.fsm[o]?n._debugger(t.REGISTERED_FSM_NAME,o):(n.fsm[o]=r[o],n.fsm[o].on("update",((e,n)=>s(o,e,n))))}))}},addFunctions:function(e,n){return function(t){Object.keys(t).forEach((r=>{e.fnCallbacks[r]?e._debugger(n.REGISTERED_FUNCTION_NAME,r):e.fnCallbacks[r]=t[r]}))}}},c={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};function s(e={}){let n=[],{type:t,limit:r,onLimit:o}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),c="LIFO"===t.toUpperCase(),s=!1;function i(e=1,t=0){let r=[];return t>0&&Array.from({length:t}).map((()=>n.pop())),1==e?n.pop():(Array.from({length:e}).map((()=>{let e=n.pop();null!=e&&r.push(e)})),r)}function l(e=1,t=0){let r=[],o=n.length-t;return e>1&&Array.from({length:e}).map((()=>{null!=n[o-1]&&r.push(n[o-1]),o--})),1==e?n[n.length-1]:r}function a(){}return a.prototype={pull:i,pullReverse:function(e=1,n=0){let t=i(e,n);return t instanceof Array?t.reverse():t},peek:l,peekReverse:function(e=1,n=0){const t=l(e,n);return t instanceof Array?t.reverse():t},getSize:()=>n.length,isEmpty:()=>0==n.length,reset:()=>(n=[],!0),debug:()=>[...n]},a.prototype.push=c?function(e){const t=e instanceof Array,c=t?e.length:1;let l=!1;if("full"!==o||!s){if(r&&t&&c>r&&(e=e.slice(0,-c+r)),r){const c=(t?e.length:1)+n.length;c>=r&&"full"===o&&(e=e.slice(0,-(c-r))),c>=r&&"update"===o&&(l=i(c-r))}return n=e instanceof Array?n.concat(e):n.concat([e]),s=!!r&&n.length===r,l||void 0}}:function(e){const t=e instanceof Array,c=t?e.length:1;let l=!1;if("full"!==o||!s){if(r&&t&&c>r&&(e=e.slice(c-r)),r){const c=(t?e.length:1)+n.length;c>=r&&"full"===o&&(e=e.slice(0,-(c-r))),c>=r&&"update"===o&&(l=i(c-r))}return n=t?e.reduce(((e,n)=>[n,...e]),n):[e].reduce(((e,n)=>[n,...e]),n),s=!!r&&n.length===r,l||void 0}},new a}return function(n,t){const r=this,i=Object.keys(o);r.fsm={},r.fnCallbacks={},r.debug=n.debug||!1,r.cache=s({type:"FIFO"}),r.cacheInternal=s({type:"FIFO"}),r.wait=[],r.lock=!1,r.haveInternalRequest=!1,r.reactivityTask=!1,r.askForPromise=e,i.forEach((e=>{r[e]=o[e](r,c)}));const{transformers:l,subscribers:a,actions:u,callbacks:f}=r._setTransitions(n,t);r.transformers=l,r.subscribers=a,r.actions=u,r.callbacks=f}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).fsmHub=t()}(this,function(){"use strict";function e(e){return e?function(e){let i=e.map(e=>t()),o=i.map(e=>e.promise);i.promises=i;let c=n(Promise.all(o));const s={promise:Promise.all(o),promises:i,_list:e,_activeTimer:null,each:()=>{},onComplete:c,timeout:()=>{},done:function(e){null!==this._activeTimer&&(clearTimeout(this._activeTimer),this._activeTimer=null),this.promises.forEach(t=>t.done(e))},cancel:function(e){null!==this._activeTimer&&(clearTimeout(this._activeTimer),this._activeTimer=null),this.promises.forEach(t=>t.cancel(e))}};return s.each=function(e,...t){this.promises.forEach((n,r)=>e({value:this._list[r],done:n.done,cancel:n.cancel,timeout:n.timeout},r,...t))},s.timeout=r(!0),s}(e):t()}function t(){let e,t;const i=new Promise((n,r)=>{e=n,t=r}),o={promise:i,promises:null,_activeTimer:null,each:()=>{},onComplete:n(i),timeout:()=>{}},c=new WeakRef(o);return o.done=function(t){const n=c.deref();void 0!==n&&null!==n._activeTimer&&(clearTimeout(n._activeTimer),n._activeTimer=null),e(t)},o.cancel=function(e){const n=c.deref();void 0!==n&&null!==n._activeTimer&&(clearTimeout(n._activeTimer),n._activeTimer=null),t(e)},o.timeout=r(!1),o.each=function(e,...t){e({value:null,done:o.done,cancel:o.cancel,timeout:this.timeout},...t)},o}function n(e){return function(t,n=null){null===n?e.then(e=>t(e)):e.then(e=>t(e),e=>n(e))}}function r(e){return function(t,r){const i=new WeakRef(this);let o,c;o=e?Promise.all(this.promises.map(e=>e.promise)):this.promise;const s=new Promise((e,n)=>{c=setTimeout(()=>{const t=i.deref();void 0!==t&&t.done(r),e(r)},t)});return this._activeTimer=c,o.then(()=>clearTimeout(c)),this.onComplete=n(Promise.race([o,s])),this}}e.sequence=function(t,...n){const r=e(),i=[];const o=function*(e){for(const t of e)yield t}(t);try{!function e(t,...n){t.done?r.done(i):Promise.resolve().then(()=>t.value(...n)).then(t=>{i.push(t),e(o.next(),...n,t)},e=>{r.cancel(e)})}(o.next(),...n)}catch(e){r.cancel(e)}return r},e.all=function(t,...n){const r=e(),i=[];let o;try{o=t.map((e,t)=>Promise.resolve().then(()=>"function"==typeof e?e(...n):e).then(e=>i[t]=e,e=>{throw e}))}catch(e){return r.cancel(e),r}return Promise.all(o).then(()=>r.done(i),e=>r.cancel(e)),r};const i={_setTransitions:function(e,t){return function({reactivity:n,transformers:r},i={}){let o={},c={},s={},l={};return n.forEach((n,r)=>{if(!(n instanceof Array))return void e._debugger(t.WRONG_REACTIVITY_RECORD,r+1);const i=n.length,[o,a,u,f]=n;if(!(4==i||3==i))return void e._debugger(t.WRONG_REACTIVITY_RECORD,r+1);const m=`${o}/${a}`;if(4==i){c[m]||(c[m]=[]),c[m].push(u);s[`${m}/${u}`]=f}3==i&&(l[m]||(l[m]=[]),l[m].push(u))}),r&&Object.keys(r).forEach(e=>{const t=r[e],n=i[t];n&&(o[e]=n)}),{transformers:o,subscribers:c,callbacks:l,actions:s}}},_debugger:function(e){return function(t,n){e.debug&&console.log(t,n)}},_callback:function(t,n){return function(r,i,o,c){const s=`${i}/${o}`,l=t.subscribers[s]||!1,a=t.callbacks[s]||!1,u=t.fnCallbacks,f=t.actions,m=[];let h;if(l||a){if(l&&l.forEach(e=>{if(!t.fsm[e])return void t._debugger(n.MISSING_FSM,l);const r=f[`${s}/${e}`],a=`${i}/${e}`,u=t.transformers[a];h="function"==typeof u?u(o,c):c,h||(h={},h.___internalFlag=!0);const p=t.fsm[e].update(r,h);m.push(p)}),a){let r=e();m.push(r.promise),a.forEach(e=>{const r=u[e],s=`${i}/${e}`,l=t.transformers[s];h="function"==typeof l?l(o,c):c,h.answer&&h.answer.hasOwnProperty("___internalFlag")&&(h.answer=void 0),"function"==typeof r?r(h):t._debugger(n.MISSING_FN,e)}),r.done()}Promise.all(m).then(()=>r.done())}else r.done()}},addFsm:function(t,n){return function(r){Object.keys(r).forEach(i=>{function o(e){if(e&&(t.haveInternalRequest=!1),t.haveInternalRequest)return;let n=t.cacheInternal.isEmpty();if(t.cache.isEmpty()&&n)return void(t.lock=!1);let[r,i,o]=n?t.cache.pull():t.cacheInternal.pull();t.cache.isEmpty()&&(t.lock=!1),t.cacheInternal.isEmpty()&&(t.haveInternalRequest=!1),c(r,i,o)}function c(n,r,i){let c;if(!t.lock)return t.lock=!0,c=e(),c.onComplete(e=>o(!1)),void t._callback(c,n,r,i);if(i){if(t.haveInternalRequest)return void t.cacheInternal.push([[n,r,i]]);let c=e();return c.onComplete(e=>o(!0)),t.haveInternalRequest=!0,void t._callback(c,n,r,i)}t.cache.push([[n,r,i]])}t.fsm[i]?t._debugger(n.REGISTERED_FSM_NAME,i):(t.fsm[i]=r[i],t.fsm[i].on("update",(e,t)=>c(i,e,t)))})}},addFunctions:function(e,t){return function(n){Object.keys(n).forEach(r=>{e.fnCallbacks[r]?e._debugger(t.REGISTERED_FUNCTION_NAME,r):e.fnCallbacks[r]=n[r]})}}},o={WRONG_REACTIVITY_RECORD:"Error: Wrong reactivity record on row %s.",REGISTERED_FSM_NAME:'Warning: FSM "%s" is already registered.',REGISTERED_FUNCTION_NAME:'Warning: Function "%s" is already registered.',MISSING_FSM:'Warning: Fsm "%s" is not registered to the hub.',MISSING_FN:'Warning: Function "%s" is not registered to the hub.'};function c(e={}){let t=[],{type:n,limit:r,onLimit:i}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),o="LIFO"===n.toUpperCase(),c=!1;function s(e=1,n=0){let r=[];return n>0&&Array.from({length:n}).map(()=>t.pop()),1==e?t.pop():(Array.from({length:e}).map(()=>{let e=t.pop();null!=e&&r.push(e)}),r)}function l(e=1,n=0){let r=[],i=t.length-n;return e>1&&Array.from({length:e}).map(()=>{null!=t[i-1]&&r.push(t[i-1]),i--}),1==e?t[t.length-1]:r}function a(){}return a.prototype={pull:s,pullReverse:function(e=1,t=0){let n=s(e,t);return n instanceof Array?n.reverse():n},peek:l,peekReverse:function(e=1,t=0){const n=l(e,t);return n instanceof Array?n.reverse():n},getSize:()=>t.length,isEmpty:()=>0==t.length,reset:()=>(t=[],!0),debug:()=>[...t]},a.prototype.push=o?function(e){const n=e instanceof Array,o=n?e.length:1;let l=!1;if("full"!==i||!c){if(r&&n&&o>r&&(e=e.slice(0,-o+r)),r){const o=(n?e.length:1)+t.length;o>=r&&"full"===i&&(e=e.slice(0,-(o-r))),o>=r&&"update"===i&&(l=s(o-r))}return t=e instanceof Array?t.concat(e):t.concat([e]),c=!!r&&t.length===r,l||void 0}}:function(e){const n=e instanceof Array,o=n?e.length:1;let l=!1;if("full"!==i||!c){if(r&&n&&o>r&&(e=e.slice(o-r)),r){const o=(n?e.length:1)+t.length;o>=r&&"full"===i&&(e=e.slice(0,-(o-r))),o>=r&&"update"===i&&(l=s(o-r))}return t=n?e.reduce((e,t)=>[t,...e],t):[e].reduce((e,t)=>[t,...e],t),c=!!r&&t.length===r,l||void 0}},new a}return function(t,n){const r=this,s=Object.keys(i);r.fsm={},r.fnCallbacks={},r.debug=t.debug||!1,r.cache=c({type:"FIFO"}),r.cacheInternal=c({type:"FIFO"}),r.wait=[],r.lock=!1,r.haveInternalRequest=!1,r.reactivityTask=!1,r.askForPromise=e,s.forEach(e=>{r[e]=i[e](r,o)});const{transformers:l,subscribers:a,actions:u,callbacks:f}=r._setTransitions(t,n);r.transformers=l,r.subscribers=a,r.actions=u,r.callbacks=f}});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peter.naydenov/fsm-hub",
3
3
  "description": "FSM orchestration and state-managment tool",
4
- "version": "2.1.3",
4
+ "version": "2.1.5",
5
5
  "license": "MIT",
6
6
  "author": "Peter Naydenov",
7
7
  "main": "./dist/fsm-hub.umd.js",
@@ -22,18 +22,22 @@
22
22
  "build": "rollup -c"
23
23
  },
24
24
  "dependencies": {
25
- "@peter.naydenov/stack": "3.0.0",
26
- "ask-for-promise": "3.1.0"
25
+ "@peter.naydenov/stack": "^3.0.0",
26
+ "ask-for-promise": "^3.2.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@peter.naydenov/fsm": "5.2.4",
30
- "@rollup/plugin-commonjs": "^29.0.0",
29
+ "@peter.naydenov/fsm": "5.2.6",
30
+ "@rollup/plugin-commonjs": "^29.0.3",
31
31
  "@rollup/plugin-node-resolve": "^16.0.3",
32
- "@rollup/plugin-terser": "^0.4.4",
33
- "c8": "^10.1.3",
34
- "chai": "6.2.1",
35
- "mocha": "11.7.5",
36
- "rollup": "^4.53.2"
32
+ "@rollup/plugin-terser": "^1.0.0",
33
+ "c8": "^12.0.0",
34
+ "chai": "6.2.2",
35
+ "mocha": "11.7.6",
36
+ "rollup": "^4.62.2"
37
+ },
38
+ "overrides": {
39
+ "diff": "^8.0.4",
40
+ "serialize-javascript": "^7.0.5"
37
41
  },
38
42
  "repository": {
39
43
  "type": "git",
@@ -56,5 +60,8 @@
56
60
  "fsm",
57
61
  "state-managment",
58
62
  "orchestration"
59
- ]
63
+ ],
64
+ "allowScripts": {
65
+ "fsevents@2.3.3": true
66
+ }
60
67
  }