state-transducer
Version:
Extended Hierarchical State Transducer library
3 lines (2 loc) • 40.3 kB
JavaScript
const CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE="Model update function must return valid update operations!",SEP=".",TRANSITION_SYMBOL="--\x3e",TRANSITION_LABEL_START_SYMBOL=":",HISTORY_STATE_NAME="H",HISTORY_PREFIX="history.",INIT_STATE="nok",INIT_EVENT="init",AUTO_EVENT="auto",STATE_PROTOTYPE_NAME="State",NO_STATE_UPDATE=[],NO_OUTPUT=null,ACTION_IDENTITY=function(){return{outputs:NO_OUTPUT,updates:NO_STATE_UPDATE}},history_symbol={},SHALLOW="shallow",DEEP="deep",WRONG_EVENT_FORMAT_ERROR="The machine received an event which does not have the proper format. Expecting an object whose unique key is the event name, and value is the event data.",FUNCTION_THREW_ERROR=(t,e)=>`Exception thrown when executing ${e} ${t||""}`,INVALID_ACTION_FACTORY_EXECUTED=(t,e)=>`${FUNCTION_THREW_ERROR(t,e)}\nThe ${e} returned a value which is not an action.`,INVALID_PREDICATE_EXECUTED=(t,e)=>`${FUNCTION_THREW_ERROR(t,e)}\nThe ${e} returned a value which is not a boolean.`,ACTION_FACTORY_DESC="action factory",ENTRY_ACTION_FACTORY_DESC="(decorating) entry action",UPDATE_STATE_FN_DESC="update state function",PREDICATE_DESC="predicate",PATH_ROOT=[0],PRE_ORDER="PRE_ORDER";function clone(t){return void 0===t?void 0:JSON.parse(JSON.stringify(t))}function merge(t,e){return Object.assign({},t,e)}function updatePathInTraversalState(t,e,n){n.forEach((n,s)=>{const i=t.get(e),a=t.get(n),o=a&&a.path;t.set(n,merge(a,{isAdded:!0,isVisited:!1,path:o||i.path.concat(s)}))})}function updateVisitInTraversalState(t,e){t.set(e,merge(t.get(e),{isVisited:!0}))}function visitTree(t,e){const{store:n,lenses:s,traverse:i}=t,{empty:a,add:o,takeAndRemoveOne:r,isEmpty:c}=n,{getChildren:u}=s,{visit:l,seed:d}=i,f=new Map,T="function"==typeof d?new(d()):clone(d);let p="function"==typeof a?new(a()):clone(a),m=T;for(o([e],p),f.set(e,{isAdded:!0,isVisited:!1,path:PATH_ROOT});!c(p);){const t=r(p),e=u(f,t);o(e,p),updatePathInTraversalState(f,t,e),m=l(m,f,t),updateVisitInTraversalState(f,t)}return f.clear(),m}function breadthFirstTraverseTree(t,e,n){const{getChildren:s}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.push.apply(e,t)},lenses:{getChildren:(t,e)=>s(e)},traverse:e},n)}function preorderTraverseTree(t,e,n){const{getChildren:s}=t;return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>s(e)},traverse:e},n)}function postOrderTraverseTree(t,e,n){const{getChildren:s}=t,{seed:i,visit:a}=e,o=(t,e)=>e.get(t).isVisited||((t,e)=>0===s(t,e).length)(t,e);return visitTree({store:{empty:[],takeAndRemoveOne:t=>t.shift(),isEmpty:t=>0===t.length,add:(t,e)=>e.unshift(...t)},lenses:{getChildren:(t,e)=>o(e,t)?[]:s(e,t).concat([e])},traverse:{seed:i,visit:(t,e,n)=>o(n,e)?a(t,e,n):t}},n)}function isLeafLabel(t){return 0===objectTreeLenses.getChildren(t).length}const objectTreeLenses={isLeafLabel:isLeafLabel,getLabel:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getLabel > unexpected object tree value";return t},getChildren:t=>{if("object"!=typeof t||Array.isArray(t)||1!==Object.keys(t).length)throw"getChildren > unexpected value";{let e=Object.values(t)[0];return e&&"object"==typeof e&&!Array.isArray(e)?Object.keys(e).map(t=>({[t]:e[t]})):[]}},constructTree:(t,e)=>{const n=t&&Object.keys(t)&&Object.keys(t)[0];return 0===e.length?t:{[n]:Object.assign.apply(null,e)}}};function traverseObj(t,e){const n={root:e},{strategy:s,seed:i,visit:a}=t;return({BFS:breadthFirstTraverseTree,PRE_ORDER:preorderTraverseTree,POST_ORDER:postOrderTraverseTree}[s]||preorderTraverseTree)(objectTreeLenses,{seed:i,visit:function(t,e,n){const{path:s}=e.get(n);return JSON.stringify(s)===JSON.stringify(PATH_ROOT)?t:a(t,e,n)}},n)}const arrayTreeLenses={getLabel:t=>Array.isArray(t)?t[0]:t,getChildren:t=>Array.isArray(t)?t[1]:[],constructTree:(t,e)=>e&&Array.isArray(e)&&e.length>0?[t,e]:t},noop=()=>{},emptyConsole={log:noop,warn:noop,info:noop,debug:noop,error:noop,trace:noop};function isBoolean(t){return"boolean"==typeof t}function isFunction(t){return"function"==typeof t}function isControlState(t){return t&&"string"==typeof t||isHistoryControlState(t)}function isEvent(t){return t&&"string"==typeof t}function isActionFactory(t){return t&&"function"==typeof t}function make_states(t){return t.reduce((t,e)=>(t[e]="",t),{})}function make_events(t){return t}function get_fn_name(t){return/^[\s\r\n]*function[\s\r\n]*([^\(\s\r\n]*?)[\s\r\n]*\([^\)\s\r\n]*\)[\s\r\n]*\{((?:[^}]*\}?)+)\}\s*$/.exec(t.toString())[1]}function wrap(t){return["-",t,"-"].join("")}function times$1(t,e){return Array.apply(null,{length:e}).map(Number.call,Number).map(t)}function always(t){return t}function keys(t){return Object.keys(t)}function merge$1(t,e){return Object.assign({},t,e)}function is_history_transition(t){return t.to.startsWith(HISTORY_PREFIX)}function is_entry_transition(t){return t.event===INIT_EVENT}function is_from_control_state(t){return function(e){return e.from===t}}function is_to_history_control_state_of(t){return function(e){return is_history_control_state_of(t,e.to)}}function is_history_control_state_of(t,e){return e.substring(HISTORY_PREFIX.length)===t}function format_transition_label(t,e,n){const s=t||"";return e&&n?`${s} [${e.name}] / ${n.name}`:e?`${s} [${e.name}]}`:n?`${s} / ${n.name}`:`${s}`}function format_history_transition_state_name({from:t,to:e}){return`${t}.${e.substring(HISTORY_PREFIX.length)}.${HISTORY_STATE_NAME}`}function get_all_transitions(t){const{from:e,event:n,guards:s}=t;return s?s.map(({predicate:t,to:s,action:i})=>({from:e,event:n,predicate:t,to:s,action:i})):[t]}function getDisplayName(t){return t.replace(/_/g," ")}function mergeModelUpdates(t){return function(e,n,s){return{updates:t.reduce((t,i)=>{const a=i(e,n,s).updates;return a?t.concat(a):t},[]),outputs:NO_OUTPUT}}}function chainModelUpdates(t){return function(e,n,s){const{updateState:i}=s;return{updates:t.reduce((t,e)=>{const{extendedState:a,updates:o}=t,r=e(a,n,s).updates;return{extendedState:i(a,o),updates:r}},{extendedState:e,updates:[]}).updates||[],outputs:NO_OUTPUT}}}function mergeActionFactories(t,e){return function(n,s,i){const a=e.map(t=>t(n,s,i)),o=a.map(t=>t.updates||[]),r=a.map(t=>t.outputs||{});return{updates:[].concat(...o),outputs:t(r)}}}function identity(t,e,n){return{updates:[],outputs:NO_OUTPUT}}function lastOf(t){return t[t.length-1]}function formatActionName(t,e,n,s,i){const a=i?i.name:"",o=a?`[${a}]`:"",r=t?t.name:"identity";return`${r||"unnamed action"}:${e}-${n}->${s} ${o}`}function getFsmStateList(t){const{getLabel:e}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,n,s)=>{const i=e(s);return t[Object.keys(i)[0]]="",t}},t)}function getStatesType(t){const{getLabel:e,isLeafLabel:n}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,s,i)=>{const a=e(i),o=Object.keys(a)[0];return n(a)?(t[o]=!1,t):(t[o]=!0,t)}},t)}function getStatesPath(t){const{getLabel:e}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,n,s)=>{const i=n.get(s).path.join("."),a=e(s);return t[Object.keys(a)[0]]=i,t}},t)}function getStatesTransitionsMap(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][s]=e,t)},{})||{}}function getStatesTransitionsMaps(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return isHistoryControlState(n)?t:(t[n]=t[n]||{},t[n][s]=t[n][s]?t[n][s].concat(e):[e],t)},{})||{}}function getEventTransitionsMaps(t){return t.reduce((t,e)=>{const{from:n,event:s}=e;return isHistoryControlState(n)?t:(t[s]=t[s]||{},t[s][n]=t[s][n]?t[s][n].concat(e):[e],t)},{})||{}}function getHistoryStatesMap(t){return reduceTransitions((t,e,n,s)=>{const{from:i,event:a,to:o,action:r,predicate:c,gen:u}=e;if(isHistoryControlState(i)){const n=getHistoryUnderlyingState(i);t.set(n,(t.get(n)||[]).concat([e]))}else if(isHistoryControlState(o)){const n=getHistoryUnderlyingState(o);t.set(n,(t.get(n)||[]).concat([e]))}return t},new Map,t)||{}}function getTargetStatesMap(t){return reduceTransitions((t,e,n,s)=>{const{to:i}=e;return t.set(i,(t.get(i)||[]).concat([e])),t},new Map,t)||{}}function getAncestorMap(t){const{getLabel:e,getChildren:n}=objectTreeLenses;return traverseObj({strategy:PRE_ORDER,seed:{},visit:(t,s,i)=>{const a=e(i),o=Object.keys(a)[0];return n(i).map(t=>Object.keys(e(t))[0]).forEach(e=>{t[e]=t[e]||[],t[e]=t[e].concat(o)}),t}},t)}function computeHistoryMaps(t){if(0===Object.keys(t).length)throw"computeHistoryMaps : passed empty control states parameter?";const{getLabel:e,isLeafLabel:n}=objectTreeLenses,s={strategy:PRE_ORDER,seed:{stateList:[],stateAncestors:{[DEEP]:{},[SHALLOW]:{}}},visit:(t,n,s)=>{const i=e(s),a=Object.keys(i)[0];t.stateList=t.stateList.concat(a);const{path:o}=n.get(s);n.set(JSON.stringify(o),a);const r=o.slice(0,-1);if(1===r.length)n.set(JSON.stringify(r),INIT_STATE);else{const e=n.get(JSON.stringify(r));t.stateAncestors[SHALLOW][a]=[e];const{ancestors:s}=o.reduce((t,e)=>{const s=t.path.slice(0,-1);if(t.path=s,s.length>1){const e=n.get(JSON.stringify(s));t.ancestors=t.ancestors.concat(e)}return t},{ancestors:[],path:o});t.stateAncestors[DEEP][a]=s}return t}},{stateList:i,stateAncestors:a}=traverseObj(s,t);return{stateList:i,stateAncestors:a}}function mapOverTransitionsActions(t,e){return reduceTransitions(function(e,n,s,i){const{from:a,event:o,to:r,action:c,predicate:u}=n,l=t(c,n,s,i);return l.displayName=l.displayName||c&&(c.name||c.displayName||formatActionName(c,a,o,r,u)),void 0===u?e.push({from:a,event:o,to:r,action:l}):0===s?e.push({from:a,event:o,guards:[{to:r,predicate:u,action:l}]}):e[e.length-1].guards.push({to:r,predicate:u,action:l}),e},[],e)}function reduceTransitions(t,e,n){return n.reduce((e,n,s)=>{let{from:i,event:a,to:o,gen:r,action:c,guards:u}=n;return u||(u=r?[{to:o,action:c,gen:r,predicate:void 0}]:[{to:o,action:c,predicate:void 0}]),u.reduce((e,n,o)=>{const{to:r,action:c,gen:u,predicate:l}=n;return t(e,u?{from:i,event:a,to:r,action:c,predicate:l,gen:u}:{from:i,event:a,to:r,action:c,predicate:l},o,s)},e)},e)}function everyTransition(t,e){return reduceTransitions((e,n)=>e&&t(n),!0,[e])}function computeTimesCircledOn(t,e){return t.reduce((t,n)=>n===e?t+1:t,0)}function isInitState(t){return t===INIT_STATE}function isInitEvent(t){return t===INIT_EVENT}function isEventless(t){return void 0===t}function arrayizeOutput(t){return t===NO_OUTPUT?NO_OUTPUT:Array.isArray(t)?t:[t]}function isHistoryControlState(t){return"object"==typeof t&&(DEEP in t||SHALLOW in t)}function getHistoryParentState(t){return t[SHALLOW]||t[DEEP]}function isShallowHistory(t){return t[SHALLOW]}function isDeepHistory(t){return t[DEEP]}function getHistoryType(t){return t[DEEP]?DEEP:SHALLOW}function getHistoryUnderlyingState(t){return t[getHistoryType(t)]}function isHistoryStateEdge(t){return void 0!==t.history}function initHistoryDataStructure(t){const e=()=>t.reduce((t,e)=>(t[e]="",t),{});return{[DEEP]:e(),[SHALLOW]:e()}}function isCompoundState(t,e){const{statesAdjacencyList:n}=t;return n[e]&&0!==n[e].length}function isAtomicState(t,e){return!isCompoundState(t,e)}function updateHistory(t,e,n){return n===INIT_STATE?t:([SHALLOW,DEEP].forEach(s=>{(e[s][n]||[]).forEach(e=>{t[s][e]=n})}),t)}function computeHistoryState(t,e,n,s){const{stateList:i,stateAncestors:a}=computeHistoryMaps(t);let o=initHistoryDataStructure(i);return(o=e.reduce((t,e)=>updateHistory(t,a,e),o))[n][s]}function findInitTransition(t){return t.find(t=>t.from===INIT_STATE&&t.event===INIT_EVENT)}function tryCatch(t,e){return function(...n){try{return t.apply(t,n)}catch(t){return e(t,n)}}}function tryCatchMachineFn(t,e,n=[]){return tryCatch(e,(s,i)=>{const a=new Error(s),o=getFunctionName(e),r=FUNCTION_THREW_ERROR(o,t);a.probableCause=s.probableCause?[s.probableCause,r].join("\n"):r;const c={fnName:o,params:n.reduce((t,e,n)=>(t[e]=i[n],t),{})};return a.info=s.info?[].concat([s.info]).concat([c]):c,a})}function getFunctionName(t){return t.name||t.displayName||"anonymous"}function assert(t,e){const n=t.apply(null,e);if(!0!==n){const e=n.info;throw console.error(`ERROR: failed contract ${t.name||""}. ${e?"Error info:":""}`,n.info),n}}function notifyThrows(t,e){t.error(e),e.probableCause&&t.error(`Probable cause: ${e.probableCause}`),e.info&&t.error("ERROR: additional info",e.info)}function handleFnExecError(t,e,n,s,i,a){const{debug:o,console:r}=t;return o&&n instanceof Error?(i({debug:o,console:r},n,e),!0):!(!o||s(n))&&(a({debug:o,console:r},n,e),!0)}function notifyAndRethrow({debug:t,console:e},n){throw notifyThrows(e,n),n}function throwIfInvalidActionResult({debug:t,console:e},n,s){const{action:i,extendedState:a,eventData:o,settings:r}=s,c=getFunctionName(i),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(i),params:{updatedExtendedState:a,eventData:o,settings:r},returned:n},notifyThrows(e,u),u}function throwIfInvalidGuardResult({debug:t,console:e},n,s){const i=getFunctionName(s.predicate),a=new Error(INVALID_PREDICATE_EXECUTED(i,PREDICATE_DESC));throw a.info={predicateName:i,params:s,returned:n},notifyThrows(e,a),a}function throwIfInvalidEntryActionResult({debug:t,console:e},n,s){const{action:i,extendedState:a,eventData:o,settings:r}=s,c=getFunctionName(i),u=new Error(INVALID_ACTION_FACTORY_EXECUTED(c,ENTRY_ACTION_FACTORY_DESC));throw u.info={fnName:getFunctionName(i),params:{updatedExtendedState:a,eventData:o,settings:r},returned:n},notifyThrows(e,u),u}function isActions(t){return t&&"updates"in t&&"outputs"in t&&(t.outputs===NO_OUTPUT||Array.isArray(t.outputs))&&Array.isArray(t.updates)}function isEventStruct(t){let e;return t&&"object"==typeof t?Object.keys(t).length>1?(e=new Error(WRONG_EVENT_FORMAT_ERROR)).info={event:t,cause:"Event objects must have only one key which is the event name!"}:e=!0:(e=new Error(WRONG_EVENT_FORMAT_ERROR)).info={event:t,cause:"not an object!"},e}const noDuplicatedStates={name:"noDuplicatedStates",shouldThrow:!1,predicate:(t,e)=>{const{getLabel:n}=objectTreeLenses,s={strategy:PRE_ORDER,seed:{duplicatedStates:[],statesHashMap:{}},visit:(t,e,s)=>{const{duplicatedStates:i,statesHashMap:a}=t,o=n(s),r=Object.keys(o)[0];return r in a?{duplicatedStates:i.concat(r),statesHashMap:a}:{duplicatedStates:i,statesHashMap:(a[r]="",a)}}},{duplicatedStates:i}=traverseObj(s,t.states);return{isFulfilled:0===i.length,blame:{message:"State names must be unique! Found duplicated state names. Cf. log",info:{duplicatedStates:i}}}}},noReservedStates={name:"noReservedStates",shouldThrow:!1,predicate:(t,e,{statesType:n})=>({isFulfilled:-1===Object.keys(n).indexOf(INIT_STATE),blame:{message:"You cannot use a reserved control state name for any of the configured control states for the machine! Cf. log",info:{reservedStates:[INIT_STATE],statesType:n}}})},atLeastOneState={name:"atLeastOneState",shouldThrow:!1,predicate:(t,e,{statesType:n})=>({isFulfilled:Object.keys(n).length>0,blame:{message:"Machine configuration must define at least one control state! Cf. log",info:{statesType:n}}})},isInitialControlStateDeclared={name:"isInitialControlStateDeclared",shouldThrow:!1,predicate:(t,e,{initTransition:n,statesType:s})=>{const{initialControlState:i,transitions:a}=t,o=Object.keys(s);return i?{isFulfilled:o.indexOf(i)>-1,blame:{message:"Configured initial control state must be a declared state. Cf. log",info:{initialControlState:i,declaredStates:o}}}:{isFulfilled:!0,blame:void 0}}},eventsAreStrings={name:"eventsAreStrings",shouldThrow:!1,predicate:(t,e)=>({isFulfilled:t.events.every(t=>"string"==typeof t),blame:{message:"Events must be an array of strings!",info:{events:t.events}}})},validInitialConfig={name:"validInitialConfig",shouldThrow:!1,predicate:(t,e,{initTransition:n})=>{const{initialControlState:s}=t;return n&&s?{isFulfilled:!1,blame:{message:"Invalid machine configuration : defining an initial control state and an initial transition at the same time may lead to ambiguity and is forbidden!",info:{initialControlState:s,initTransition:n}}}:n||s?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Invalid machine configuration : you must define EITHER an initial control state OR an initial transition! Else in which state is the machine supposed to start?",info:{initialControlState:s,initTransition:n}}}}},validInitialTransition={name:"validInitialTransition",shouldThrow:!1,predicate:(t,e,{initTransition:n})=>{const{initialControlState:s,transitions:i}=t,a=i.reduce((t,e)=>(e.from===INIT_STATE&&t.push(e),t),[]);return{isFulfilled:s&&!n||!s&&n&&1===a.length&&n.event===INIT_EVENT&&(isInconditionalTransition(n)||areCconditionalTransitions(n)),blame:{message:"Invalid configuration for initial transition! Cf. log",info:{initTransition:n,initTransitions:a,initialControlState:s}}}}},initEventOnlyInCompoundStates={name:"initEventOnlyInCompoundStates",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:i})=>{const a=Object.keys(s).filter(t=>!s[t]).map(t=>({[t]:n[t]&&n[t][INIT_EVENT]})).filter(t=>Object.values(t)[0]);return{isFulfilled:0===a.length,blame:{message:"Found at least one atomic state with an entry transition! That is forbidden! Cf. log",info:{initTransitions:a}}}}},validInitialTransitionForCompoundState={name:"validInitialTransitionForCompoundState",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:i})=>{const a=Object.keys(s).filter(t=>s[t]),o=a.map(t=>n[t]&&n[t][INIT_EVENT]),r=o.every(Boolean);if(!r)return{isFulfilled:!1,blame:{message:"Found at least one compound state without an entry transition! Cf. log",info:{hasEntryTransitions:a.map(t=>({[t]:!(!n[t]||!n[t][INIT_EVENT])}))}}};const c=r&&o.every(t=>{const{guards:e,to:n}=t;return!e&&"string"==typeof n});return c?c&&o.every(t=>{const{from:e,to:n}=t;return e!==n&&i[n]&&i[n].startsWith(i[e])})?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must have a target state which is strictly below the compound state in the state hierarchy! ",info:{states:t.states,statesPath:i,entryTransitions:o}}}:{isFulfilled:!1,blame:{message:"Found at least one compound state with an invalid entry transition! Entry transitions for compound states must be inconditional and the associated target control state cannot be a history pseudo-state. Cf. log",info:{entryTransitions:o}}}}},validEventLessTransitions={name:"validEventLessTransitions",shouldThrow:!1,predicate:(t,e,{statesTransitionsMap:n,statesType:s,statesPath:i})=>{const a=Object.keys(s).map(t=>({[t]:n[t]&&"undefined"in n[t]&&1!==Object.keys(n[t]).length})).filter(t=>void 0!==Object.values(t)[0]&&Object.values(t)[0]);return{isFulfilled:0===a.length,blame:{message:"Found at least one control state without both an eventless transition and a competing transition! Cf. log",info:{failingOriginControlStates:a}}}}},allStateTransitionsOnOneSingleRow={name:"allStateTransitionsOnOneSingleRow",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n})=>{const s=Object.keys(n).reduce((t,e)=>{const s=Object.keys(n[e]).filter(t=>n[e][t].length>1);return s.length>0&&(t[e]=s),t},{});return{isFulfilled:0===Object.keys(s).length,blame:{message:"Found at least one control state and one event for which the associated transition are not condensated under a unique row! Cf. log",info:{statesTransitionsInfo:s}}}}},noConflictingTransitionsWithAncestorState={name:"noConflictingTransitionsWithAncestorState",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,eventTransitionsMaps:s,ancestorMap:i})=>{const a=Object.keys(s).reduce((t,e)=>{const n=Object.keys(s[e]),a=n.filter(t=>t!==INIT_STATE).map(t=>i[t]&&{[t]:i[t].find(t=>n.indexOf(t)>-1)}).filter(t=>t&&Object.values(t).filter(Boolean).length>0);return a.length>0&&(t[e]=a),t},{});return{isFulfilled:0===Object.keys(a).length,blame:{message:"Found two conflicting transitions! A -ev-> X, and B -ev-> Y leads to ambiguity if A < B or B < A. Cf. log",info:{eventTransitionsInfo:a}}}}},isHistoryStatesTargetStates={name:"isHistoryStatesTargetStates",shouldThrow:!1,predicate:(t,e,{})=>{const n=t.transitions.reduce((t,e)=>isHistoryControlState(e.from)?t.concat(e):t,[]);return{isFulfilled:0===Object.keys(n).length,blame:{message:"Found a history pseudo state configured as the origin control state for a transition. History pseudo states should only be target control states. Cf. log",info:{wrongHistoryStates:n}}}}},isHistoryStatesCompoundStates={name:"isHistoryStatesCompoundStates",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,statesType:s})=>{const i=Object.keys(n).map(t=>{if(t===INIT_STATE)return[];return Object.keys(n[t]).reduce((e,i)=>{const a=n[t][i][0],{guards:o,to:r}=a;return o?o.reduce((t,e)=>{const{to:n}=e;return isHistoryControlState(n)&&!s[getHistoryUnderlyingState(n)]?t.concat(a):t},e):isHistoryControlState(r)&&!s[getHistoryUnderlyingState(r)]?e.concat(a):e},[])}).reduce((t,e)=>t.concat(e),[]);return{isFulfilled:0===Object.keys(i).length,blame:{message:"Found a history pseudo state connected to an atomic state! History pseudo states only refer to compound states. Cf. log",info:{wrongHistoryStates:i,states:t.states}}}}},isHistoryStatesExisting={name:"isHistoryStatesExisting",shouldThrow:!1,predicate:(t,e,{historyStatesMap:n,statesType:s})=>{const i=Array.from(n.entries()).map(([t,e])=>!(t in s)&&{historyState:t,flatTransitions:e}).filter(Boolean),a=Object.keys(i).length;return{isFulfilled:0===a,blame:{message:`Found ${a} history pseudo state referring to a control state that is not declared! Check the states property of the state machine definition.`,info:{invalidTransitions:i,states:t.states}}}}};function isInconditionalTransition(t){const{from:e,event:n,guards:s,to:i,action:a}=t;return void 0===s&&i&&isControlState(e)&&isEvent(n)&&isControlState(i)&&isActionFactory(a)}function isValidGuard(t){const{to:e,predicate:n,action:s}=t;return e&&isControlState(e)&&isFunction(n)&&isActionFactory(s)}function areCconditionalTransitions(t){const{from:e,event:n,guards:s,to:i}=t;return s&&Array.isArray(s)&&s.length>0&&!i&&isControlState(e)&&isEvent(n)&&s.every(isValidGuard)}const isValidFsmDef={name:"isValidFsmDef",shouldThrow:!1,predicate:(t,e)=>{const{transitions:n,states:s,events:i,initialExtendedState:a}=t,o=n&&Array.isArray(n),r=s&&"object"==typeof s,c=i&&Array.isArray(i);return o?r?c?{isFulfilled:!0,blame:void 0}:{isFulfilled:!1,blame:{message:"The events property for a machine definition must be an array!",info:{events:i}}}:{isFulfilled:!1,blame:{message:"The states property for a machine definition must be an object!",info:{states:s}}}:{isFulfilled:!1,blame:{message:"The transitions property for a machine definition must be an array!",info:{transitions:n}}}}},haveTransitionsValidTypes={name:"haveTransitionsValidTypes",shouldThrow:!1,predicate:(t,e)=>{const{transitions:n}=t,s=n.map((t,e)=>!isInconditionalTransition(t)&&!areCconditionalTransitions(t)&&{transition:t,index:e}).filter(Boolean),i=Object.keys(s).length;return{isFulfilled:0===i,blame:{message:`Found ${i} transitions with invalid format! Check logs for more details.`,info:{wrongTransitions:s,transitions:n}}}}},areEventsDeclared={name:"areEventsDeclared",shouldThrow:!1,predicate:(t,e,{eventTransitionsMaps:n})=>{const s=Object.keys(n),i=t.events,a=i.map(t=>-1===s.indexOf(t)&&t).filter(Boolean),o=s.map(t=>-1===i.indexOf(t)&&t).filter(Boolean).filter(t=>t!==INIT_EVENT);return{isFulfilled:0===a.length&&0===o.length,blame:{message:"All declared events must be used in transitions. All events used in transition must be declared! Cf. log",info:{eventsDeclaredButNotTriggeringTransitions:a,eventsNotDeclaredButTriggeringTransitions:o}}}}},areStatesDeclared={name:"areStatesDeclared",shouldThrow:!1,predicate:(t,e,{statesTransitionsMaps:n,targetStatesMap:s,statesType:i})=>{const a=Object.keys(n),o=Array.from(s.keys()),r=Object.keys([a,o].reduce((t,e)=>(e.forEach(e=>t[e]=!0),t),{})),c=Object.keys(i),u=c.map(t=>-1===r.indexOf(t)&&t).filter(Boolean),l=r.map(t=>t!==INIT_STATE&&-1===c.indexOf(t)&&t).filter(Boolean);return{isFulfilled:0===u.length&&0===u.length,blame:{message:"All declared states must be used in transitions. All states used in transition must be declared! Cf. log",info:{statesDeclaredButNotTriggeringTransitions:u,statesNotDeclaredButTriggeringTransitions:l}}}}},isValidSettings={name:"isValidSettings",shouldThrow:!1,predicate:t=>({isFulfilled:!0,blame:void 0})},isInitialStateOriginState={name:"isInitialStateOriginState",shouldThrow:!1,predicate:(t,e,{targetStatesMap:n})=>Array.from(n.keys()).indexOf(INIT_STATE)>-1?{isFulfilled:!1,blame:{message:"Found at least one transition with the initial state as target state! CF. log",info:{targetStates:Array.from(n.keys()),transitions:t.transitions}}}:{isFulfilled:!0,blame:void 0}},isValidSelfTransition={name:"isValidSelfTransition",shouldThrow:!1,predicate:(t,e,{targetStatesMap:n,statesType:s})=>{const i=Array.from(n.keys()).map(t=>{return n.get(t).map(e=>{const{from:n,event:i}=e;if(t in s&&!s[t]&&n&&n===t&&!i)return{state:t,flatTransition:e}}).filter(Boolean)}).filter(t=>t.length>0);return{isFulfilled:0===i.length,blame:{message:"Found at least one eventless self-transition involving an atomic state! This is forbidden to avoid infinity loop! Cf. log",info:{wrongSelfTransitions:i}}}}},fsmContracts={computed:(t,e)=>({statesType:getStatesType(t.states),initTransition:findInitTransition(t.transitions),statesTransitionsMap:getStatesTransitionsMap(t.transitions),statesTransitionsMaps:getStatesTransitionsMaps(t.transitions),eventTransitionsMaps:getEventTransitionsMaps(t.transitions),ancestorMap:getAncestorMap(t.states),statesPath:getStatesPath(t.states),historyStatesMap:getHistoryStatesMap(t.transitions),targetStatesMap:getTargetStatesMap(t.transitions)}),description:"FSM structure",contracts:[isValidFsmDef,isValidSettings,isInitialControlStateDeclared,isInitialStateOriginState,eventsAreStrings,haveTransitionsValidTypes,noDuplicatedStates,noReservedStates,atLeastOneState,areEventsDeclared,areStatesDeclared,validInitialConfig,validInitialTransition,initEventOnlyInCompoundStates,validInitialTransitionForCompoundState,validEventLessTransitions,isValidSelfTransition,allStateTransitionsOnOneSingleRow,noConflictingTransitionsWithAncestorState,isHistoryStatesExisting,isHistoryStatesTargetStates,isHistoryStatesCompoundStates]};function makeContractHandler(t){const e=t.description;return function(...n){const s=[],i=t.computed.apply(null,n);return{isFulfilled:t.contracts.reduce((t,a)=>{const{name:o,predicate:r,shouldThrow:c}=a,u=n.concat(i),{isFulfilled:l,blame:d}=r.apply(null,u),f=`${e} FAILS ${o}!`,{message:T,info:p}=d||{};if(l)return t;if(s.push({name:o,message:T,info:p}),console.error(f),console.error([o,T].join(": ")),console.debug("Supporting error data:",p),c)throw new Error([f,"check console for information!"].join("\n"));return!1},!0),failingContracts:s}}}const fsmContractChecker=(t,e,n)=>makeContractHandler(n)(t,e),alwaysTrue=()=>!0;function build_event_enum(t){return(t=t.reduce?t:Array.prototype.slice.call(arguments)).push(INIT_EVENT),t.reduce(function(t,e){return t[e]=e,t},{})}function build_nested_state_structure(t){const e="State";let n={},s={};function i(){}return t={nok:t},i.prototype={current_state_name:INIT_STATE},n[INIT_STATE]=new i,n[STATE_PROTOTYPE_NAME]=new i,function t(i,a){keys(i).forEach(function(o){const r=i[o];if(n[o]=new a,n[o].name=o,n[o].parent_name=get_fn_name(a),n[o].root_name=e,"object"==typeof r){s[o]=!0;const e=function(){};e.displayName=o,e.prototype=n[o],t(r,e)}})}(t,i),{hash_states:n,is_group_state:s}}function build_state_enum(t){let e={history:{}};return e.NOK=INIT_STATE,function t(n){keys(n).forEach(function(s){const i=n[s];e[s]=s,"object"==typeof i&&t(i)})}(t),e}function normalizeTransitions(t){const{initialControlState:e,transitions:n}=t,s=findInitTransition(n);return e?n.concat([{from:INIT_STATE,event:INIT_EVENT,to:e,action:ACTION_IDENTITY}]):s?n:void 0}function normalizeFsmDef(t){return Object.assign({},t,{transitions:normalizeTransitions(t)})}function create_state_machine(t,e){return createStateMachine(t,e)}function createStateMachine(t,e){const{states:n,events:s,initialExtendedState:i,updateState:a}=t,{debug:o}=e||{},r=o&&o.checkContracts||void 0;let c=o&&o.console?o.console:emptyConsole;if(r){const{failingContracts:n}=fsmContractChecker(t,e,r);if(n.length>0)throw new Error("createStateMachine: called with wrong parameters! Cf. logs for failing contracts.")}const u=tryCatchMachineFn(UPDATE_STATE_FN_DESC,a,["extendedState, updates"]),l=build_event_enum(s),d=normalizeTransitions(t),f=build_nested_state_structure(n);let T=i;const{stateList:p,stateAncestors:m}=computeHistoryMaps(n);let h=initHistoryDataStructure(p),g={},y={};const _=f.is_group_state;let E=f.hash_states;function S(t,e){var n,s;c.debug("send event",t),n=isEventStruct,s=[t],r&&assert(n,s);const i=keys(t)[0],a=t[i],u=E[INIT_STATE].current_state_name;return e&&i===INIT_EVENT&&u!==INIT_STATE?(c.warn("The external event INIT_EVENT can only be sent when starting the machine!"),NO_OUTPUT):function(t,e,n,s){const i=t[INIT_STATE].current_state_name,a=t[i][e];if(a){c.log("found event handler!"),c.info("WHEN EVENT ",e);const{stop:r,outputs:u}=a(s,n,i);o&&!r&&c.warn("No guards have been fulfilled! We recommend to configure guards explicitly to cover the full state space!");const l=arrayizeOutput(u),d=t[INIT_STATE].current_state_name;if(y[d]&&d!==i){const t=g[d]?INIT_EVENT:AUTO_EVENT;return[].concat(l).concat(S({[t]:n},!1))}return l}return c.warn(`There is no transition associated to the event |${e}| in state |${i}|!`),NO_OUTPUT}(f.hash_states,i,a,T)}return d.forEach(function(t){let{from:n,to:s,action:i,event:r,guards:d}=t;d||(d=[{predicate:alwaysTrue,to:s,action:i}]),r===INIT_EVENT&&(g[n]=!0);let f=E[n];if(r&&!(r in l))throw`unknown event ${r} found in state machine definition!`;r||(r=AUTO_EVENT,y[n]=!0),_[n]&&g[n]&&(y[n]=!0),f[r]=d.reduce((t,s,i)=>{const r=s.action||ACTION_IDENTITY,l=r.name||r.displayName,d=function(t,e){let s="";const d=function(d,f,p){n=p||n;const g=t.predicate,y=g||alwaysTrue,_=!g||tryCatchMachineFn(PREDICATE_DESC,y,["extendedState","eventData","settings"])(d,f,e),S=t.to;if(s=y?"_checking_condition_"+i:"",handleFnExecError({debug:o,console:c},{predicate:t.predicate,extendedState:d,eventData:f,settings:e},_,isBoolean,notifyAndRethrow,throwIfInvalidGuardResult),_){c.info("IN STATE ",n),g&&c.info(`CASE: guard ${y.name} for transition is fulfilled`),!g&&c.info("CASE: unguarded transition"),c.info("THEN : we execute the action "+l);const t=tryCatchMachineFn(ACTION_FACTORY_DESC,r,["extendedState","eventData","settings"])(d,f,e);handleFnExecError({debug:o,console:c},{action:r,extendedState:d,eventData:f,settings:e},t,isActions,notifyAndRethrow,throwIfInvalidActionResult);const{updates:s,outputs:i}=t;!function(t,e,n){const s=n[t].name;h=updateHistory(h,m,s),c.info("left state",wrap(t))}(n,0,E);const p=u(d,s);handleFnExecError({debug:o,console:c},{updateStateFn:a,extendedState:d,updates:s},p,alwaysTrue,notifyAndRethrow,noop),T=p;const _=function(t,e,n){let s,i;if(isHistoryControlState(t)){const e=t.deep?DEEP:t.shallow?SHALLOW:void 0,a=t[e];i=h[e][a]||a,s=n[i]}else{if(!t)throw"enter_state : unknown case! Not a state name, and not a history state to enter!";s=n[t],i=s.name}return n[INIT_STATE].current_state_name=i,o&&c.info("AND TRANSITION TO STATE",i),i}(S,0,E);return c.info("ENTERING NEXT STATE : ",_),{stop:!0,outputs:i}}return{stop:!1,outputs:NO_OUTPUT}};return d.displayName=n+s,d}(s,e);return function(e,n,s){const i=t(e,n,s);return i.stop?i:d(e,n,s)}},function(){return{stop:!1,outputs:NO_OUTPUT}})}),S({[INIT_EVENT]:i},!0),function(t){return S(t,!0)}}function makeWebComponentFromFsm({name:t,eventHandler:e,fsm:n,commandHandlers:s,effectHandlers:i,options:a}){return customElements.define(t,class extends HTMLElement{constructor(){if(t.split("-").length<=1)throw"makeWebComponentFromFsm : web component's name MUST include a dash! Please review the name property passed as parameter to the function!";super();const o=this,{subjectFactory:r}=e;this.eventSubject=r(),this.options=Object.assign({},a);const c=this.options.NO_ACTION||NO_OUTPUT;this.eventSubject.subscribe({next:t=>{const e=n(t);e!==c&&e.forEach(t=>{if(t===c)return;const{command:e,params:n}=t;s[e](this.eventSubject.next,n,i,o)})}})}static get observedAttributes(){return[]}connectedCallback(){this.options.initialEvent&&this.eventSubject.next(this.options.initialEvent)}disconnectedCallback(){this.options.terminalEvent&&this.eventSubject.next(this.options.terminalEvent),this.eventSubject.complete()}attributeChangedCallback(t,e,n){this.constructor(),this.connectedCallback()}})}function makeNamedActionsFactory(t){return Object.keys(t).reduce((e,n)=>{const s=t[n];return s.displayName=n,e[n]=s,e},{})}function mergeOutputsFn(t){return t.reduce((t,e)=>t.concat(e),[])}function decorateWithEntryActions(t,e,n){if(!e)return t;const{transitions:s,states:i,initialExtendedState:a,initialControlState:o,events:r,updateState:c,settings:u}=t,l=getFsmStateList(i),d=Object.keys(e).every(t=>null!=l[t]),f=n||mergeOutputsFn;if(d){return{initialExtendedState:a,initialControlState:o,states:i,events:r,transitions:mapOverTransitionsActions((t,n,s,i)=>{const{to:a}=n,o=e[a];return o?decorateWithExitAction(t,o,f,c):t},s),updateState:c,settings:u}}throw"decorateWithEntryActions : found control states for which entry actions are defined, and yet do not exist in the state machine!"}function decorateWithExitAction(t,e,n,s){const i=function(i,a,o){const{debug:r}=o,c=tryCatchMachineFn(ENTRY_ACTION_FACTORY_DESC,e,["extendedState","eventData","settings"]),u=t(i,a,o),l=u.updates,d=tryCatchMachineFn(UPDATE_STATE_FN_DESC,s,["extendedState, updates"])(i,l);handleFnExecError({debug:r,console:console},{updateStateFn:s,extendedState:i,actionUpdate:l},d,alwaysTrue,notifyAndRethrow,noop);const f=d,T=c(f,a,o);if(!handleFnExecError({debug:r,console:console},{action:e,extendedState:f,eventData:a,settings:o},T,isActions,notifyAndRethrow,throwIfInvalidEntryActionResult))return{updates:[].concat(l,T.updates),outputs:n([u.outputs,T.outputs])}};return i.displayName=`Entry_Action_After_${getFunctionName(t)}`,i}function traceFSM(t,e){const{initialExtendedState:n,initialControlState:s,events:i,states:a,transitions:o,updateState:r}=e;return{initialExtendedState:n,initialControlState:s,events:i,states:a,updateState:r,transitions:mapOverTransitionsActions((t,e,n,s)=>(function(i,a,o){const{from:c,event:u,to:l,predicate:d}=e,f=tryCatchMachineFn(ACTION_FACTORY_DESC,t,["extendedState","eventData","settings"])(i,a,o),{outputs:T,updates:p}=f;return{updates:p,outputs:[{outputs:T,updates:p,extendedState:i,newExtendedState:tryCatchMachineFn(UPDATE_STATE_FN_DESC,r,["extendedState, updates"])(i,p||[]),controlState:c,event:{eventLabel:u,eventData:a},settings:o,targetControlState:l,predicate:d,actionFactory:t,guardIndex:n,transitionIndex:s}]}}),o)}}function makeHistoryStates(t){const e=Object.keys(getFsmStateList(t));return(t,n)=>{if(!e.includes(n))throw"makeHistoryStates: the state for which a history state must be constructed is not a configured state for the state machine under implementation!!";return{[t]:n,type:history_symbol}}}function historyState(t,e){return{[t]:e}}function generateStatePlantUmlHeader(t,e){return e?`state "${e}" as ${t} <<NoContent>>`:`state "${getDisplayName(t)}" as ${t} <<NoContent>>`}function toPlantUml(t,e){const{states:n,transitions:s}=t,{getChildren:i,constructTree:a,getLabel:o}=objectTreeLenses,r=t=>t.join(SEP),c=postOrderTraverseTree(objectTreeLenses,{seed:()=>Map,visit:(t,e,n)=>{const{path:a}=e.get(n),c=o(n),u=stateToPlantUML(Object.keys(c)[0],times$1(e=>t.get(r(a.concat(e))),((t,e)=>i(t,e).length)(n,e)),s);return t.set(r(a),u),t}},{[INIT_STATE]:n}),u=c.get("0");return c.clear(),u}function stateToPlantUML(t,e,n){return[`${generateStatePlantUmlHeader(t,"")} {`,e.join("\n"),format_history_states(t,n),format_entry_transitions(t,n),"}",translate_transitions(t,n)].filter(t=>"\n"!==t&&""!==t).join("\n")}function format_history_states(t,e){const n=e.reduce((e,n)=>{return get_all_transitions(n).filter(is_history_transition).filter(is_to_history_control_state_of(t)).reduce((t,e)=>(t[format_history_transition_state_name(e)]=void 0,t),e)},{});return Object.keys(n).map(t=>`${generateStatePlantUmlHeader(t,HISTORY_STATE_NAME)}`).join("\n")}function translate_transitions(t,e){return[format_history_transitions(t,e),format_standard_transitions(t,e)].filter(Boolean).join("\n")}function format_standard_transitions(t,e){return t===INIT_STATE?"":e.map(e=>{return get_all_transitions(e).filter(is_from_control_state(t)).filter(t=>!is_entry_transition(t)).filter(t=>!is_history_transition(t)).map(({from:t,event:e,predicate:n,to:s,action:i})=>[t,TRANSITION_SYMBOL,s,TRANSITION_LABEL_START_SYMBOL,format_transition_label(e,n,i)].join(" ")).join("\n")}).filter(Boolean).join("\n")}function format_entry_transitions(t,e){return e.reduce((e,n)=>{return get_all_transitions(n).filter(is_entry_transition).filter(is_from_control_state(t)).reduce((t,e)=>{const{from:n,to:s,predicate:i,action:a}=e;return t.push(`[*] ${TRANSITION_SYMBOL} ${s} ${TRANSITION_LABEL_START_SYMBOL} ${format_transition_label("",i,a)}`),t},e)},[]).join("\n")}function format_history_transitions(t,e){return e.map(e=>{return get_all_transitions(e).filter(is_from_control_state(t)).filter(is_history_transition).map(({from:t,event:e,predicate:n,to:s,action:i})=>[t,TRANSITION_SYMBOL,format_history_transition_state_name({from:t,to:s}),TRANSITION_LABEL_START_SYMBOL,format_transition_label(e,n,i)].join(" ")).join("\n")}).filter(Boolean).join("\n")}function toDagreVisualizerFormat(t){const{states:e,transitions:n}=t,{getLabel:s,getChildren:i}=objectTreeLenses,{constructTree:a}=arrayTreeLenses,o=t=>t.join(SEP),r=postOrderTraverseTree(objectTreeLenses,{seed:()=>Map,visit:(t,e,n)=>{const{path:r}=e.get(n),c=s(n),u=Object.keys(c)[0],l=times$1(e=>t.get(o(r.concat(e))),((t,e)=>i(t,e).length)(n,e));return t.set(o(r),a(u,l)),t}},{[INIT_STATE]:e}).get("0"),c=n.map(t=>{const{from:e,to:n,event:s,guards:i,action:a}=t;if(i){return{from:e,event:s,guards:i.map(t=>{const{predicate:e,to:n,action:s}=t;return{predicate:e.name,to:n,action:s.name}})}}return{from:e,to:n,event:s,action:a.name||"no action name?"}});return JSON.stringify({states:r,transitions:c})}export{fsmContracts,build_state_enum,normalizeTransitions,normalizeFsmDef,create_state_machine,createStateMachine,makeWebComponentFromFsm,makeNamedActionsFactory,mergeOutputsFn,decorateWithEntryActions,traceFSM,makeHistoryStates,historyState,toPlantUml,toDagreVisualizerFormat,CONTRACT_MODEL_UPDATE_FN_RETURN_VALUE,SEP,TRANSITION_SYMBOL,TRANSITION_LABEL_START_SYMBOL,HISTORY_STATE_NAME,HISTORY_PREFIX,INIT_STATE,INIT_EVENT,AUTO_EVENT,STATE_PROTOTYPE_NAME,NO_STATE_UPDATE,NO_OUTPUT,ACTION_IDENTITY,history_symbol,SHALLOW,DEEP,WRONG_EVENT_FORMAT_ERROR,FUNCTION_THREW_ERROR,INVALID_ACTION_FACTORY_EXECUTED,INVALID_PREDICATE_EXECUTED,ACTION_FACTORY_DESC,ENTRY_ACTION_FACTORY_DESC,UPDATE_STATE_FN_DESC,PREDICATE_DESC,noop,emptyConsole,isBoolean,isFunction,isControlState,isEvent,isActionFactory,make_states,make_events,get_fn_name,wrap,times$1 as times,always,keys,merge$1 as merge,is_history_transition,is_entry_transition,is_from_control_state,is_to_history_control_state_of,is_history_control_state_of,format_transition_label,format_history_transition_state_name,get_all_transitions,getDisplayName,mergeModelUpdates,chainModelUpdates,mergeActionFactories,identity,lastOf,getFsmStateList,getStatesType,getStatesPath,getStatesTransitionsMap,getStatesTransitionsMaps,getEventTransitionsMaps,getHistoryStatesMap,getTargetStatesMap,getAncestorMap,computeHistoryMaps,mapOverTransitionsActions,reduceTransitions,everyTransition,computeTimesCircledOn,isInitState,isInitEvent,isEventless,arrayizeOutput,isHistoryControlState,getHistoryParentState,isShallowHistory,isDeepHistory,getHistoryType,getHistoryUnderlyingState,isHistoryStateEdge,initHistoryDataStructure,isCompoundState,isAtomicState,updateHistory,computeHistoryState,findInitTransition,tryCatch,tryCatchMachineFn,getFunctionName,assert,notifyThrows,handleFnExecError,notifyAndRethrow,throwIfInvalidActionResult,throwIfInvalidGuardResult,throwIfInvalidEntryActionResult,isActions,isEventStruct};
//# sourceMappingURL=transducer.es.min.js.map