{"version":3,"sources":["../src/index.ts","../src/mixins/BaseClass.ts","../src/mixins/DictionaryContainer.ts","../src/mixins/BasicActionContainer.ts","../src/mixins/ExtendedActionContainer.ts","../src/ActionDictionary.ts","../src/Automata.ts","../src/mixins/BasicEventContainer.ts","../src/mixins/BasicStateContainer.ts","../src/mixins/BasicValidatorContainer.ts","../src/EventAdapter.ts","../src/mixins/ExtendedEventContainer.ts","../src/mixins/ExtendedStateContainer.ts","../src/mixins/ExtendedValidatorContainer.ts","../src/EventBus.ts","../src/CoreLoop.ts","../src/DataSource.ts","../src/EventDictionary.ts","../src/FunctionDictionary.ts","../src/IOPromiseAdapter.ts","../src/types/index.ts","../src/DataDestination.ts","../src/StateDictionary.ts"],"sourcesContent":["/**\n * @packageDocumentation\n *\n * The `@yantrix/automata` package is a foundational component of the Yantrix framework,\n * designed to create and manage finite state machines (FSMs) with type-safe transitions and event handling in TypeScript.\n *\n * Its core purpose is to:\n * - Provide the core building blocks for Yantrix FSMs\n * - Enable the creation of complex state machines with minimal boilerplate\n * - Ensure that all state transitions and event handling are type-safe\n *\n */\n\nexport * from './ActionDictionary.js';\nexport * from './Automata.js';\nexport * from './CoreLoop.js';\nexport * from './DataSource.js';\nexport * from './EventAdapter.js';\nexport * from './EventBus.js';\nexport * from './EventDictionary.js';\nexport * from './FunctionDictionary.js';\nexport * from './IOPromiseAdapter.js';\nexport * from './StateDictionary.js';\nexport * from './types/dictionaries.js';\nexport * from './types/index.js';\nexport * from './types/interfaces.js';\n","import { uniqId } from '@yantrix/utils';\nimport { IBaseClass } from '../types/index.js';\n\nexport class AbstractBaseClass implements IBaseClass {\n\treadonly correlationId: string;\n\tstatic readonly BASE_ID_LENGTH = 12;\n\n\tconstructor(...args: any[]) {\n\t\tthis.correlationId = uniqId(AbstractBaseClass.BASE_ID_LENGTH + (args || []).length);\n\t}\n\n\tnext(): this {\n\t\treturn this;\n\t}\n}\n","/**\n * @module AbstractDictionaryContainer\n * @description A common parent for all Dictionaries which implements numeric hash for any incoming values, possibly\n * split by namespaces\n */\nimport { TAbstractConstructor } from '../types/index.js';\n\nexport default function DictionaryContainer<ItemType>() {\n\treturn <TBase extends TAbstractConstructor = TAbstractConstructor>(base: TBase) =>\n\t\tclass AbstractDictionaryContainer extends base {\n\t\t\t_dictionary: Record<string, ItemType> = {};\n\t\t\t_dictionaryIndex = new Map<\n\t\t\t\tItemType,\n\t\t\t\t{\n\t\t\t\t\tkey: string;\n\t\t\t\t\tnamespace: string | undefined;\n\t\t\t\t}\n\t\t\t>();\n\n\t\t\t_namespaceIndex: Record<string, string[]> = {};\n\n\t\t\tgetDictionary(namespace?: string): Record<string, ItemType> {\n\t\t\t\tif (namespace == null)\n\t\t\t\t\treturn this._dictionary;\n\t\t\t\treturn (this._namespaceIndex[namespace] ?? []).reduce(\n\t\t\t\t\t(dict, itemKey) =>\n\t\t\t\t\t\tObject.assign(dict, {\n\t\t\t\t\t\t\t[itemKey]: this._dictionary[itemKey],\n\t\t\t\t\t\t}),\n\t\t\t\t\t{} as Record<string, ItemType>,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t_stringHash(str: string): number {\n\t\t\t\tlet hash = 0;\n\t\t\t\tif (!str?.length)\n\t\t\t\t\treturn hash;\n\t\t\t\tfor (let i = 0; i < str.length; i++) {\n\t\t\t\t\tconst chr = str.charCodeAt(i);\n\t\t\t\t\thash = (hash << 5) - hash + chr;\n\t\t\t\t\thash |= 0;\n\t\t\t\t}\n\t\t\t\treturn Math.abs(hash);\n\t\t\t}\n\n\t\t\t_findItem(itemKey: string, namespace?: string): NonNullable<ItemType> | null {\n\t\t\t\tconst k = this._getItemKey(itemKey, namespace);\n\t\t\t\tconst v = this._dictionary[k];\n\n\t\t\t\tif (v && this._dictionaryIndex.has(v))\n\t\t\t\t\treturn v;\n\t\t\t\tdelete this._dictionary[k];\n\n\t\t\t\tif (!namespace)\n\t\t\t\t\treturn null;\n\t\t\t\tif (this._namespaceIndex[namespace])\n\t\t\t\t\tthis._namespaceIndex[namespace] = this._namespaceIndex[namespace].filter(v => v !== k);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t_getItemKey(itemKey: string, namespace = ''): string {\n\t\t\t\tif (!itemKey?.length)\n\t\t\t\t\tthrow new Error(`item key is empty`);\n\t\t\t\tconst prefix = namespace?.length ? `${namespace}__` : '';\n\t\t\t\treturn `${prefix}${itemKey}`;\n\t\t\t}\n\n\t\t\t_getItemValue(itemKey: string, namespace?: string): ItemType {\n\t\t\t\tif (!itemKey?.length)\n\t\t\t\t\tthrow new Error(`item key is empty`);\n\t\t\t\tlet value = this._stringHash(this._getItemKey(itemKey, namespace));\n\t\t\t\tif (Object.values(this._dictionary).includes(value as ItemType))\n\t\t\t\t\tvalue = value + this._stringHash(JSON.stringify(this._dictionary));\n\t\t\t\treturn value as ItemType;\n\t\t\t}\n\n\t\t\t_deleteItemKey(itemKey: string): this {\n\t\t\t\tconst item = this?._dictionary[itemKey];\n\t\t\t\tif (!item)\n\t\t\t\t\treturn this;\n\t\t\t\tconst meta = this._dictionaryIndex.get(item);\n\t\t\t\tdelete this._dictionary[itemKey];\n\t\t\t\tif (meta?.namespace) {\n\t\t\t\t\tthis._namespaceIndex[meta.namespace] = this._namespaceIndex[meta.namespace]?.filter(\n\t\t\t\t\t\tv => v !== itemKey,\n\t\t\t\t\t) as string[];\n\t\t\t\t}\n\t\t\t\tthis._dictionaryIndex.delete(item);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t_getValueData(value: ItemType): {\n\t\t\t\tkey: string;\n\t\t\t\tnamespace: string | undefined;\n\t\t\t} | null {\n\t\t\t\treturn this._dictionaryIndex.get(value) ?? null;\n\t\t\t}\n\n\t\t\t_addItemKey(itemKey: string, namespace?: string): ItemType {\n\t\t\t\tconst k = this._getItemKey(itemKey, namespace);\n\t\t\t\tif (this._dictionary[k]) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Item key ${itemKey} is taken within ${\n\t\t\t\t\t\t\tnamespace == null ? 'default namespace' : `namespace \"${namespace}\"`\n\t\t\t\t\t\t}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst value = this._getItemValue(itemKey, namespace);\n\t\t\t\tthis._dictionary[k] = value;\n\t\t\t\tif (namespace) {\n\t\t\t\t\tif (!this._namespaceIndex[namespace])\n\t\t\t\t\t\tthis._namespaceIndex[namespace] = [];\n\t\t\t\t\tthis._namespaceIndex[namespace].push(k);\n\t\t\t\t}\n\t\t\t\tthis._dictionaryIndex.set(value, { key: k, namespace });\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\t_clearItems(namespace?: string): this {\n\t\t\t\tif (namespace != null) {\n\t\t\t\t\tfor (const itemKey of this._namespaceIndex[namespace] ?? []) {\n\t\t\t\t\t\tthis._deleteItemKey(itemKey);\n\t\t\t\t\t}\n\t\t\t\t\tdelete this._namespaceIndex[namespace];\n\t\t\t\t} else {\n\t\t\t\t\tthis._namespaceIndex = {};\n\t\t\t\t\tthis._dictionaryIndex.clear();\n\t\t\t\t\tthis._dictionary = {};\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\t\t};\n}\n","import { isPositiveInteger } from '@yantrix/utils';\nimport { TAbstractConstructor, TAutomataBaseActionType, TValidator } from '../types/index.js';\n\nexport default function BasicActionContainer<ActionType extends TAutomataBaseActionType>() {\n\treturn <T extends TAbstractConstructor>(Base: T) =>\n\t\tclass AbstractBasicActionContainer extends Base {\n\t\t\t#_defaultActionValidator = isPositiveInteger as TValidator<ActionType>;\n\n\t\t\t#_actionValidator: TValidator<ActionType> | undefined;\n\n\t\t\tget validateAction(): TValidator<ActionType> {\n\t\t\t\treturn this.#_actionValidator ?? this.#_defaultActionValidator;\n\t\t\t}\n\n\t\t\tsetActionValidator(actionValidator: TValidator<ActionType> | null = null): this {\n\t\t\t\tif (actionValidator === null) {\n\t\t\t\t\tthis.#_actionValidator = undefined;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tif (typeof actionValidator !== 'function')\n\t\t\t\t\tthrow new Error(`passed Action Validator is not a function`);\n\t\t\t\tthis.#_actionValidator = actionValidator.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\t\t};\n}\n","import {\n\tTAbstractConstructor,\n\tTAutomataActionPayload,\n\tTAutomataBaseActionType,\n\tTDefinedValues,\n\tTValidator,\n} from '../types/index.js';\nimport BasicActionContainer from './BasicActionContainer.js';\n\nexport default function ExtendedActionContainer<\n\tActionType extends TAutomataBaseActionType,\n\tPayloadType extends { [K in ActionType]: any },\n>() {\n\treturn <TBase extends TAbstractConstructor>(Proto: TBase) =>\n\t\tclass AbstractExtendedActionContainer extends BasicActionContainer<ActionType>()(Proto) {\n\t\t\t_payloadValidator: TValidator<TAutomataActionPayload<ActionType, PayloadType>> | undefined;\n\n\t\t\tget validateActionPayload(): TValidator<TAutomataActionPayload<ActionType, PayloadType>> {\n\t\t\t\treturn this._payloadValidator ?? this._defaultPayloadValidator;\n\t\t\t}\n\n\t\t\tsetActionPayloadValidator(\n\t\t\t\tpayloadValidator?: TValidator<TAutomataActionPayload<ActionType, PayloadType>>,\n\t\t\t): this {\n\t\t\t\tif (payloadValidator === null) {\n\t\t\t\t\tthis._payloadValidator = undefined;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tif (typeof payloadValidator !== 'function')\n\t\t\t\t\tthrow new Error(`passed Payload Validator is not a function`);\n\t\t\t\tthis._payloadValidator = payloadValidator.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t_defaultPayloadValidator = (p: any): p is TDefinedValues<TAutomataActionPayload<ActionType, PayloadType>> =>\n\t\t\t\t!!this.validateAction\n\t\t\t\t&& this.validateAction(p?.action)\n\t\t\t\t&& (p?.payload === null || typeof p.payload === 'object');\n\t\t};\n}\n","import { AbstractBaseClass } from './mixins/BaseClass.js';\nimport DictionaryContainer from './mixins/DictionaryContainer.js';\nimport ExtendedActionContainer from './mixins/ExtendedActionContainer.js';\nimport { TActionKeysCollection, TActionLookupParams, TActionValuesCollection } from './types/dictionaries.js';\nimport { TAbstractConstructor, TAutomataBaseActionType } from './types/index.js';\nimport { IActionDictionary } from './types/interfaces.js';\n\nexport function createActionDictionary<\n\tActionType extends TAutomataBaseActionType,\n\tPayloadType extends { [K in ActionType]: any },\n>() {\n\treturn <BaseType extends TAbstractConstructor = TAbstractConstructor>(Base: BaseType) =>\n\t\tclass AbstractActionDictionary extends DictionaryContainer<ActionType>()(\n\t\t\tExtendedActionContainer<ActionType, PayloadType>()(Base),\n\t\t) {\n\t\t\tgetActionKeys({\n\t\t\t\tactions = [],\n\t\t\t\tnamespace = undefined,\n\t\t\t}: TActionValuesCollection<ActionType>): Array<string | null> {\n\t\t\t\treturn (actions ?? []).map((action) => {\n\t\t\t\t\tif (!this.validateAction(action))\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tconst data = this._getValueData(action);\n\t\t\t\t\tif (!data)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tif (namespace !== null && namespace !== data.namespace)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\treturn data.key;\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tclearActions(namespace?: string): this {\n\t\t\t\treturn this._clearItems(namespace);\n\t\t\t}\n\n\t\t\tremoveActions({ namespace, actions = [], keys = [] }: TActionLookupParams<ActionType>): this {\n\t\t\t\tconst actionsToDelete: ActionType[] = [\n\t\t\t\t\t...actions.filter(this.validateAction),\n\t\t\t\t\t...keys.flatMap(k => (k ? [this._findItem(k, namespace)] : [])),\n\t\t\t\t].filter(v => v !== null);\n\n\t\t\t\tconst actionKeys = actionsToDelete\n\t\t\t\t\t.map(action => this._getValueData(action))\n\t\t\t\t\t.filter(data => !!data && (namespace === null || namespace === data?.namespace));\n\n\t\t\t\tfor (const actionKey of actionKeys) {\n\t\t\t\t\tif (actionKey)\n\t\t\t\t\t\tthis._deleteItemKey(actionKey.key);\n\t\t\t\t}\n\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tgetActionValues({\n\t\t\t\tnamespace = undefined,\n\t\t\t\tkeys = [],\n\t\t\t}: TActionKeysCollection<ActionType>): Array<ActionType | null> {\n\t\t\t\treturn (keys ?? []).flatMap(k => (k ? [this._findItem(k, namespace)] : []));\n\t\t\t}\n\n\t\t\taddActions({ namespace = undefined, keys }: TActionKeysCollection<ActionType>): ActionType[] {\n\t\t\t\treturn (keys || []).flatMap(k => (k ? [this._addItemKey(k, namespace)] : []));\n\t\t\t}\n\t\t};\n}\n\n/**\n * Basic action dictionary class that is used in Yantrix automatas.\n */\nexport class BasicActionDictionary\n\textends createActionDictionary<TAutomataBaseActionType, Record<TAutomataBaseActionType, any>>()(AbstractBaseClass)\n\timplements IActionDictionary<TAutomataBaseActionType, Record<TAutomataBaseActionType, any>> {\n\tconstructor() {\n\t\tsuper();\n\t}\n}\n\nexport default BasicActionDictionary;\n","import { isPositiveInteger } from '@yantrix/utils';\nimport { AbstractBaseClass } from './mixins/BaseClass.js';\nimport BasicValidatorContainer from './mixins/BasicValidatorContainer.js';\nimport {\n\tTAbstractConstructor,\n\tTAutomataActionPayload,\n\tTAutomataBaseActionType,\n\tTAutomataBaseEventType,\n\tTAutomataBaseStateType,\n\tTAutomataParams,\n\tTAutomataQueue,\n\tTAutomataReducer,\n\tTAutomataStateContext,\n} from './types/index.js';\n\nimport { IAutomata, IAutomataEventAdapter, IAutomataFunctionRegistry } from './types/interfaces.js';\n\nexport function createAutomata<\n\tStateType extends TAutomataBaseStateType = TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType = TAutomataBaseActionType,\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n>() {\n\treturn <BaseType extends TAbstractConstructor = TAbstractConstructor>(Base: BaseType) =>\n\t\tclass AbstractGenericAutomata extends BasicValidatorContainer<StateType, ActionType, EventType>()(Base) {\n\t\t\tpublic eventAdapter: IAutomataEventAdapter<\n\t\t\t\tStateType,\n\t\t\t\tActionType,\n\t\t\t\tEventType,\n\t\t\t\tContextType,\n\t\t\t\tPayloadType,\n\t\t\t\tEventMetaType\n\t\t\t> | null = null;\n\n\t\t\t#state: StateType | null = null;\n\t\t\t#context: ContextType[StateType] | null = null;\n\t\t\t#lastAction: ActionType | null = null;\n\t\t\t#actionQueue: TAutomataQueue<ActionType, PayloadType> = [];\n\t\t\t#enabled = true;\n\t\t\t#paused = false;\n\t\t\t#rootReducer: TAutomataReducer<StateType, ActionType, ContextType, PayloadType> | null = null;\n\t\t\t#functionRegistry: IAutomataFunctionRegistry | null = null;\n\n\t\t\t#currentCycle: number = 1;\n\n\t\t\tconstructor(\n\t\t\t\teventAdapter: IAutomataEventAdapter<\n\t\t\t\t\tStateType,\n\t\t\t\t\tActionType,\n\t\t\t\t\tEventType,\n\t\t\t\t\tContextType,\n\t\t\t\t\tPayloadType,\n\t\t\t\t\tEventMetaType\n\t\t\t\t> | null = null,\n\t\t\t\t...args: any[]\n\t\t\t) {\n\t\t\t\tsuper(args);\n\t\t\t\tif (eventAdapter)\n\t\t\t\t\tthis.eventAdapter = eventAdapter;\n\t\t\t}\n\n\t\t\tget state(): StateType | null {\n\t\t\t\treturn this.#state;\n\t\t\t}\n\n\t\t\tget context(): ContextType[StateType] | null {\n\t\t\t\treturn this.#context;\n\t\t\t}\n\n\t\t\tget lastAction(): ActionType | null {\n\t\t\t\treturn this.#lastAction;\n\t\t\t}\n\n\t\t\tset lastAction(action: ActionType | null) {\n\t\t\t\tthis.#lastAction = action;\n\t\t\t}\n\n\t\t\tget currentCycle(): number {\n\t\t\t\treturn this.#currentCycle;\n\t\t\t}\n\n\t\t\tincrementCycle(): this {\n\t\t\t\tthis.#currentCycle++;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tclearActionQueue(): this {\n\t\t\t\tthis.#actionQueue = [];\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tcollapseActionQueue(): {\n\t\t\t\tactions: TAutomataQueue<ActionType, PayloadType> | null;\n\t\t\t\tnewState: TAutomataStateContext<StateType, ContextType>;\n\t\t\t} {\n\t\t\t\tconst actions = (this.#actionQueue ?? []).slice();\n\t\t\t\tconst newState = this.reduceQueue();\n\t\t\t\tif (this.isEnabled()) {\n\t\t\t\t\tthis.setContext(newState);\n\t\t\t\t\tthis.clearActionQueue();\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tactions,\n\t\t\t\t\tnewState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tenable(): this {\n\t\t\t\tthis.#enabled = true;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tdisable(clearQueue = false): this {\n\t\t\t\tthis.#enabled = false;\n\t\t\t\tif (clearQueue)\n\t\t\t\t\tthis.clearActionQueue();\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tisEnabled(): boolean {\n\t\t\t\treturn this.#enabled ?? true;\n\t\t\t}\n\n\t\t\tisPaused(): boolean {\n\t\t\t\treturn this.#paused ?? false;\n\t\t\t}\n\n\t\t\tpause(): this {\n\t\t\t\tthis.#paused = true;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tresume(): this {\n\t\t\t\tthis.#paused = false;\n\t\t\t\tif (this.isEnabled())\n\t\t\t\t\tthis.collapseActionQueue();\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tinit(params: TAutomataParams<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType>): this {\n\t\t\t\tconst {\n\t\t\t\t\tstate = null,\n\t\t\t\t\tcontext,\n\t\t\t\t\tpaused = false,\n\t\t\t\t\tenabled = true,\n\t\t\t\t\trootReducer = null,\n\t\t\t\t\tstateValidator,\n\t\t\t\t\tactionValidator,\n\t\t\t\t\teventValidator,\n\t\t\t\t\tfunctionRegistry,\n\t\t\t\t} = params;\n\t\t\t\tif (rootReducer == null)\n\t\t\t\t\tthis.#rootReducer = null;\n\t\t\t\telse if (rootReducer instanceof Function)\n\t\t\t\t\tthis.#rootReducer = rootReducer;\n\t\t\t\telse throw new Error(`Invalid Root Reducer supplied: ${rootReducer}`);\n\t\t\t\tif (!this.validateState(state))\n\t\t\t\t\tthrow new Error(`Invalid initial State: ${state}`);\n\t\t\t\tif (functionRegistry == null) {\n\t\t\t\t\tthis.#functionRegistry = null;\n\t\t\t\t} else {\n\t\t\t\t\tthis.#functionRegistry = functionRegistry;\n\t\t\t\t}\n\t\t\t\tthis.#actionQueue = [];\n\t\t\t\tthis.#enabled = enabled;\n\t\t\t\tthis.#paused = paused;\n\t\t\t\tthis.setContext({ state, context });\n\t\t\t\tif (stateValidator)\n\t\t\t\t\tthis.setStateValidator(stateValidator);\n\t\t\t\tif (actionValidator)\n\t\t\t\t\tthis.setActionValidator(actionValidator);\n\t\t\t\tif (eventValidator)\n\t\t\t\t\tthis.setEventValidator(eventValidator);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tdispatch(\n\t\t\t\taction: TAutomataActionPayload<ActionType, PayloadType>,\n\t\t\t): TAutomataStateContext<StateType, ContextType> {\n\t\t\t\tif (!this.validateAction(action?.action))\n\t\t\t\t\tthrow new Error(`Invalid Action: ${JSON.stringify(action)}`);\n\t\t\t\tif (!this.#rootReducer) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Root Reducer is not defined. Please init the Instance with a rootReducer. Dispatched Action: ${JSON.stringify(\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst reducedValue = this.#rootReducer({\n\t\t\t\t\t...action,\n\t\t\t\t\t...this.reduceQueue(),\n\t\t\t\t});\n\t\t\t\tif (!reducedValue || !this.validateState(reducedValue.state))\n\t\t\t\t\tthrow new Error(`Invalid Reduced State: ${reducedValue}`);\n\t\t\t\tif (this.isPaused()) {\n\t\t\t\t\tthis.#actionQueue = this.getActionQueue().concat(action);\n\t\t\t\t} else if (this.isEnabled()) {\n\t\t\t\t\tthis.clearActionQueue();\n\t\t\t\t\tthis.setContext(reducedValue);\n\n\t\t\t\t\tif (this.eventAdapter) {\n\t\t\t\t\t\tthis.eventAdapter.handleTransition(this.getContext());\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn reducedValue;\n\t\t\t}\n\n\t\t\tgetContext<K extends StateType = StateType>(): TAutomataStateContext<K, ContextType> {\n\t\t\t\treturn {\n\t\t\t\t\tstate: this.state as K,\n\t\t\t\t\tcontext: this.context,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tgetActionQueue(): TAutomataActionPayload<ActionType, PayloadType>[] {\n\t\t\t\treturn (this.#actionQueue ?? []).slice(0);\n\t\t\t}\n\n\t\t\tgetReducer(): TAutomataReducer<StateType, ActionType, ContextType, PayloadType> | null {\n\t\t\t\treturn this.#rootReducer;\n\t\t\t}\n\n\t\t\tconsumeAction(count = 1): {\n\t\t\t\taction: TAutomataActionPayload<ActionType, PayloadType> | null;\n\t\t\t\tnewState: TAutomataStateContext<StateType, ContextType>;\n\t\t\t} {\n\t\t\t\tif (!isPositiveInteger(count))\n\t\t\t\t\tthrow new Error(`Invalid Action Count: ${count}`);\n\t\t\t\tlet currentResponse: ReturnType<\n\t\t\t\t\tIAutomata<\n\t\t\t\t\t\tStateType,\n\t\t\t\t\t\tActionType,\n\t\t\t\t\t\tEventType,\n\t\t\t\t\t\tContextType,\n\t\t\t\t\t\tPayloadType,\n\t\t\t\t\t\tEventMetaType\n\t\t\t\t\t>['consumeAction']\n\t\t\t\t> = {\n\t\t\t\t\taction: null,\n\t\t\t\t\tnewState: this.getContext(),\n\t\t\t\t};\n\t\t\t\tconst queue = this.getActionQueue().slice(0, count);\n\t\t\t\twhile (queue.length) {\n\t\t\t\t\tcurrentResponse = this.reduceQueueItem(queue, currentResponse.newState);\n\t\t\t\t}\n\t\t\t\tif (this.isEnabled()) {\n\t\t\t\t\tthis.setActionQueue(this.getActionQueue().slice(count)).setContext(currentResponse.newState);\n\t\t\t\t}\n\t\t\t\treturn currentResponse;\n\t\t\t}\n\n\t\t\treduceQueueItem(queue = this.getActionQueue(), newState = this.getContext()): {\n\t\t\t\taction: TAutomataActionPayload<ActionType, PayloadType> | null;\n\t\t\t\tnewState: TAutomataStateContext<StateType, ContextType>;\n\t\t\t} {\n\t\t\t\tif (!this.#rootReducer)\n\t\t\t\t\tthrow new Error(`Root Reducer is not defined. Please init the Instance with a rootReducer.`);\n\t\t\t\tconst currentResponse: ReturnType<\n\t\t\t\t\tIAutomata<\n\t\t\t\t\t\tStateType,\n\t\t\t\t\t\tActionType,\n\t\t\t\t\t\tEventType,\n\t\t\t\t\t\tContextType,\n\t\t\t\t\t\tPayloadType,\n\t\t\t\t\t\tEventMetaType\n\t\t\t\t\t>['consumeAction']\n\t\t\t\t> = {\n\t\t\t\t\taction: null,\n\t\t\t\t\tnewState: newState || this.getContext(),\n\t\t\t\t};\n\t\t\t\tif (!queue?.length)\n\t\t\t\t\treturn currentResponse;\n\t\t\t\tconst currentAction = queue.shift();\n\t\t\t\tif (!currentAction)\n\t\t\t\t\treturn currentResponse;\n\t\t\t\tif (!this.validateAction(currentAction?.action))\n\t\t\t\t\tthrow new Error(`Invalid Action: ${currentAction}`);\n\t\t\t\tcurrentResponse.newState = this.#rootReducer({\n\t\t\t\t\t...currentResponse.newState,\n\t\t\t\t\t...currentAction,\n\t\t\t\t});\n\t\t\t\tcurrentResponse.action = currentAction;\n\t\t\t\treturn currentResponse;\n\t\t\t}\n\n\t\t\treduceQueue: () => TAutomataStateContext<StateType, ContextType> = () => {\n\t\t\t\tlet reducedValue = this.getContext();\n\t\t\t\tif (!this.#rootReducer)\n\t\t\t\t\tthrow new Error(`Root Reducer is not defined. Please init the Instance with a rootReducer`);\n\t\t\t\tconst queue = this.getActionQueue();\n\t\t\t\twhile (queue?.length) reducedValue = this.reduceQueueItem(queue, reducedValue).newState;\n\t\t\t\treturn reducedValue;\n\t\t\t};\n\n\t\t\tsetContext: (context?: TAutomataStateContext<StateType, ContextType> | null) => this = (context = null) => {\n\t\t\t\tif (!context || !this.validateState(context?.state))\n\t\t\t\t\tthrow new Error(`Invalid Context: ${context}`);\n\t\t\t\tthis.#state = context.state;\n\t\t\t\tthis.#context = context.context ?? null;\n\t\t\t\treturn this;\n\t\t\t};\n\n\t\t\tsetActionQueue: (queue?: TAutomataQueue<ActionType, PayloadType> | null) => this = (queue) => {\n\t\t\t\tif (!Array.isArray(queue))\n\t\t\t\t\tthrow new Error(`Invalid Action Queue: ${queue}`);\n\t\t\t\tthis.#actionQueue = queue;\n\t\t\t\treturn this;\n\t\t\t};\n\n\t\t\tgetFunctionRegistry(): IAutomataFunctionRegistry | null {\n\t\t\t\treturn this.#functionRegistry;\n\t\t\t}\n\n\t\t\tsetFunctionRegistry: (registry: IAutomataFunctionRegistry | null) => this = (registry = null) => {\n\t\t\t\tthis.#functionRegistry = registry;\n\t\t\t\treturn this;\n\t\t\t};\n\n\t\t\tgetEventAdapter(): IAutomataEventAdapter<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType> | null {\n\t\t\t\treturn this.eventAdapter;\n\t\t\t}\n\n\t\t\tsetEventAdapter: (adapter: IAutomataEventAdapter<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType> | null) => this = (adapter = null) => {\n\t\t\t\tthis.eventAdapter = adapter;\n\t\t\t\treturn this;\n\t\t\t};\n\t\t};\n}\n\n/**\n * Class that represents a basic Yantrix Automata instance.\n */\nexport class GenericAutomata\n\textends createAutomata<\n\t\tTAutomataBaseStateType,\n\t\tTAutomataBaseActionType,\n\t\tTAutomataBaseEventType,\n\t\tRecord<TAutomataBaseStateType, any>,\n\t\tRecord<TAutomataBaseActionType, any>,\n\t\tRecord<TAutomataBaseEventType, any>\n\t>()(AbstractBaseClass)\n\timplements\n\t\tIAutomata<\n\t\t\tTAutomataBaseStateType,\n\t\t\tTAutomataBaseActionType,\n\t\t\tTAutomataBaseEventType,\n\t\t\tRecord<TAutomataBaseStateType, any>,\n\t\t\tRecord<TAutomataBaseActionType, any>,\n\t\t\tRecord<TAutomataBaseEventType, any>\n\t\t> {}\n\nexport default GenericAutomata;\n","import { isPositiveInteger } from '@yantrix/utils';\nimport { TAbstractConstructor, TAutomataBaseEventType, TValidator } from '../types/index.js';\n\nexport default function BasicEventContainer<EventType extends TAutomataBaseEventType>() {\n\treturn <T extends TAbstractConstructor>(Base: T) =>\n\t\tclass AbstractBasicEventContainer extends Base {\n\t\t\t#_defaultEventValidator = isPositiveInteger as TValidator<EventType>;\n\t\t\t#_eventValidator: TValidator<EventType> | undefined;\n\n\t\t\tpublic get validateEvent(): TValidator<EventType> {\n\t\t\t\treturn this.#_eventValidator ?? this.#_defaultEventValidator;\n\t\t\t}\n\n\t\t\tsetEventValidator(eventValidator: TValidator<EventType> | null = null): this {\n\t\t\t\tif (eventValidator === null) {\n\t\t\t\t\tthis.#_eventValidator = undefined;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tif (typeof eventValidator !== 'function')\n\t\t\t\t\tthrow new Error(`passed Event Validator is not a function`);\n\t\t\t\tthis.#_eventValidator = eventValidator.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\t\t};\n}\n","import { isPositiveInteger } from '@yantrix/utils';\nimport { TAbstractConstructor, TAutomataBaseStateType, TValidator } from '../types/index.js';\n\nexport default function BasicStateContainer<StateType extends TAutomataBaseStateType>() {\n\treturn <T extends TAbstractConstructor>(Base: T) =>\n\t\tclass AbstractBasicStateContainer extends Base {\n\t\t\t#_defaultStateValidator = isPositiveInteger as TValidator<StateType>;\n\n\t\t\t#_stateValidator: TValidator<StateType> | undefined;\n\n\t\t\tpublic get validateState(): TValidator<StateType> {\n\t\t\t\treturn this.#_stateValidator ?? this.#_defaultStateValidator;\n\t\t\t}\n\n\t\t\tsetStateValidator(stateValidator: TValidator<StateType> | null = null): this {\n\t\t\t\tif (stateValidator === null) {\n\t\t\t\t\tthis.#_stateValidator = undefined;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tif (typeof stateValidator !== 'function')\n\t\t\t\t\tthrow new Error(`passed State Validator is not a function`);\n\t\t\t\tthis.#_stateValidator = stateValidator.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\t\t};\n}\n","import {\n\tTAbstractConstructor,\n\tTAutomataBaseActionType,\n\tTAutomataBaseEventType,\n\tTAutomataBaseStateType,\n} from '../types/index.js';\nimport BasicActionContainer from './BasicActionContainer.js';\nimport BasicEventContainer from './BasicEventContainer.js';\nimport BasicStateContainer from './BasicStateContainer.js';\n\nexport default function BasicValidatorContainer<\n\tStateType extends TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType,\n\tEventType extends TAutomataBaseEventType,\n>() {\n\treturn <TBase extends TAbstractConstructor>(Proto: TBase) =>\n\t\tclass AbstractBasicValidatorContainer extends BasicStateContainer<StateType>()(\n\t\t\tBasicEventContainer<EventType>()(BasicActionContainer<ActionType>()(Proto)),\n\t\t) {};\n}\n","import { unifyObjectKey } from '@yantrix/utils';\nimport { AbstractBaseClass } from './mixins/BaseClass.js';\nimport ExtendedValidatorContainer from './mixins/ExtendedValidatorContainer.js';\nimport {\n\tTAbstractConstructor,\n\tTAutomataBaseActionType,\n\tTAutomataBaseEventType,\n\tTAutomataBaseStateType,\n\tTAutomataEventEmitter,\n\tTAutomataEventHandler,\n\tTAutomataEventMetaType,\n\tTAutomataStateContext,\n\tTDefinedValues,\n} from './types/index.js';\nimport { IAutomataEventAdapter } from './types/interfaces.js';\n\nexport function createEventAdapter<\n\tStateType extends TAutomataBaseStateType = TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType = TAutomataBaseActionType,\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n>() {\n\treturn <BaseType extends TAbstractConstructor = TAbstractConstructor>(Base: BaseType) =>\n\t\tclass AbstractAutomataEventAdapter extends ExtendedValidatorContainer<\n\t\t\tStateType,\n\t\t\tActionType,\n\t\t\tEventType,\n\t\t\tContextType,\n\t\t\tPayloadType,\n\t\t\tEventMetaType\n\t\t>()(Base) {\n\t\t\t#eventListeners: {\n\t\t\t\t[T in EventType]?: Array<TAutomataEventHandler<T, ActionType, EventMetaType, PayloadType>>;\n\t\t\t};\n\n\t\t\t#eventEmitters: {\n\t\t\t\t[T in StateType]?: Array<TAutomataEventEmitter<EventType, T, EventMetaType, ContextType>>;\n\t\t\t};\n\n\t\t\tpublic constructor() {\n\t\t\t\tsuper();\n\t\t\t\tthis.#eventListeners = {};\n\t\t\t\tthis.#eventEmitters = {};\n\t\t\t}\n\n\t\t\tpublic addEventEmitter<T extends StateType>(\n\t\t\t\ton: T,\n\t\t\t\temitter: TAutomataEventEmitter<EventType, T, EventMetaType, ContextType>,\n\t\t\t): (() => void) | null {\n\t\t\t\tif (on === null || on === undefined || !(emitter instanceof Function) || !this.validateState(on))\n\t\t\t\t\treturn null;\n\t\t\t\tthis.#eventEmitters = Object.assign(this.#eventEmitters ?? {}, {\n\t\t\t\t\t[on]: (this.#eventEmitters[on] ?? []).concat(emitter),\n\t\t\t\t});\n\t\t\t\treturn () => {\n\t\t\t\t\tif (this.#eventEmitters?.[on]) {\n\t\t\t\t\t\tconst newEmitters = (this.#eventEmitters[on] || []).filter(v => v !== emitter);\n\t\t\t\t\t\tif (!newEmitters.length)\n\t\t\t\t\t\t\tdelete this.#eventEmitters[on];\n\t\t\t\t\t\telse this.#eventEmitters[on] = newEmitters;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tpublic addEventListener<T extends EventType>(\n\t\t\t\ttype: T,\n\t\t\t\thandler: TAutomataEventHandler<T, ActionType, EventMetaType, PayloadType>,\n\t\t\t): (() => void) | null {\n\t\t\t\tif (type === null || type === undefined || !(handler instanceof Function) || !this.validateEvent(type))\n\t\t\t\t\treturn null;\n\t\t\t\tthis.#eventListeners = Object.assign(this.#eventListeners ?? {}, {\n\t\t\t\t\t[type]: [...(this.#eventListeners?.[type] ?? []), handler],\n\t\t\t\t});\n\t\t\t\treturn () => {\n\t\t\t\t\tif (this.#eventListeners?.[type]) {\n\t\t\t\t\t\tconst newHandlers = (this.#eventListeners[type] || []).filter(v => v !== handler);\n\t\t\t\t\t\tif (!newHandlers.length)\n\t\t\t\t\t\t\tdelete this.#eventListeners[type];\n\t\t\t\t\t\telse this.#eventListeners[type] = newHandlers;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tpublic handleEvent<T extends EventType>(\n\t\t\t\tevent: TAutomataEventMetaType<T, EventMetaType>,\n\t\t\t): Array<ReturnType<TAutomataEventHandler<T, ActionType, EventMetaType, PayloadType>>> {\n\t\t\t\tif (!this.validateEventMeta(event))\n\t\t\t\t\treturn [];\n\t\t\t\treturn (this.#eventListeners?.[event.event] || [])\n\t\t\t\t\t.map(handler => handler(event))\n\t\t\t\t\t.filter(action => this.validateAction(action.action));\n\t\t\t}\n\n\t\t\tpublic handleTransition<T extends StateType>(\n\t\t\t\tnewState: TAutomataStateContext<T, ContextType>,\n\t\t\t): Array<ReturnType<TAutomataEventEmitter<EventType, T, EventMetaType, ContextType>>> {\n\t\t\t\tif (!this.validateContext(newState))\n\t\t\t\t\treturn [];\n\t\t\t\treturn (this.#eventEmitters?.[newState.state] || [])\n\t\t\t\t\t.map(emitter => emitter(newState))\n\t\t\t\t\t.filter(event => this.validateEvent(event.event));\n\t\t\t}\n\n\t\t\tpublic removeAllListeners<T extends EventType>(type: T | null = null): this {\n\t\t\t\tswitch (true) {\n\t\t\t\t\tcase type === null:\n\t\t\t\t\t\tthis.#eventListeners = {};\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tif (this.validateEvent(type) && this.#eventListeners?.[type])\n\t\t\t\t\t\t\tdelete this.#eventListeners[type];\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic removeAllEmitters<T extends StateType>(type: T | null = null): this {\n\t\t\t\tswitch (true) {\n\t\t\t\t\tcase type === null:\n\t\t\t\t\t\tthis.#eventEmitters = {};\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tif (this.validateState(type) && this.#eventEmitters?.[type])\n\t\t\t\t\t\t\tdelete this.#eventEmitters[type];\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic getObservedEvents(): TDefinedValues<EventType>[] {\n\t\t\t\treturn Object\n\t\t\t\t\t.keys(this.#eventListeners)\n\t\t\t\t\t.map(unifyObjectKey<EventType>)\n\t\t\t\t\t.filter(k => this.#eventListeners[k]?.length)\n\t\t\t\t\t.filter(this.validateEvent);\n\t\t\t}\n\n\t\t\tpublic getObservedStates(): TDefinedValues<StateType>[] {\n\t\t\t\treturn Object\n\t\t\t\t\t.keys(this.#eventEmitters)\n\t\t\t\t\t.map(unifyObjectKey<StateType>)\n\t\t\t\t\t.filter(k => this.#eventEmitters[k]?.length)\n\t\t\t\t\t.filter(this.validateState);\n\t\t\t}\n\t\t};\n}\n\n/**\n * Basic event adapter class that is used in Yantrix automatas.\n */\nexport class AutomataEventAdapter\n\textends createEventAdapter()(AbstractBaseClass)\n\timplements\n\t\tIAutomataEventAdapter<\n\t\t\tTAutomataBaseStateType,\n\t\t\tTAutomataBaseActionType,\n\t\t\tTAutomataBaseEventType,\n\t\t\tRecord<TAutomataBaseStateType, any>,\n\t\t\tRecord<TAutomataBaseActionType, any>,\n\t\t\tRecord<TAutomataBaseEventType, any>\n\t\t> {\n\tpublic constructor() {\n\t\tsuper();\n\t}\n}\n\nexport default AutomataEventAdapter;\n","import {\n\tTAbstractConstructor,\n\tTAutomataBaseEventType,\n\tTAutomataEventMetaType,\n\tTDefinedValues,\n\tTValidator,\n} from '../types/index.js';\nimport BasicEventContainer from './BasicEventContainer.js';\n\nexport default function ExtendedEventContainer<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any },\n>() {\n\treturn <TBase extends TAbstractConstructor>(Proto: TBase) =>\n\t\tclass AbstractExtendedEventContainer extends BasicEventContainer<EventType>()(Proto) {\n\t\t\t#__eventMetaValidator: TValidator<TAutomataEventMetaType<EventType, EventMetaType>> | undefined;\n\n\t\t\tpublic get validateEventMeta(): TValidator<TAutomataEventMetaType<EventType, EventMetaType>> {\n\t\t\t\treturn this.#__eventMetaValidator ?? this.#__defaultEventMetaValidator;\n\t\t\t}\n\n\t\t\tsetEventMetaValidator(\n\t\t\t\teventMetaValidator?: TValidator<TAutomataEventMetaType<EventType, EventMetaType>>,\n\t\t\t): this {\n\t\t\t\tif (eventMetaValidator === null) {\n\t\t\t\t\tthis.#__eventMetaValidator = undefined;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tif (typeof eventMetaValidator !== 'function')\n\t\t\t\t\tthrow new Error(`passed Event Meta Validator is not a function`);\n\t\t\t\tthis.#__eventMetaValidator = eventMetaValidator.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t#__defaultEventMetaValidator = (\n\t\t\t\tp: any,\n\t\t\t): p is TDefinedValues<TAutomataEventMetaType<EventType, EventMetaType>> =>\n\t\t\t\tthis.validateEvent(p?.event) && (p?.meta === null || typeof p.meta === 'object');\n\t\t};\n}\n","import {\n\tTAbstractConstructor,\n\tTAutomataBaseStateType,\n\tTAutomataStateContext,\n\tTDefinedValues,\n\tTValidator,\n} from '../types/index.js';\nimport BasicStateContainer from './BasicStateContainer.js';\n\nexport default function ExtendedStateContainer<\n\tStateType extends TAutomataBaseStateType,\n\tContextType extends { [K in StateType]: any },\n>() {\n\treturn <TBase extends TAbstractConstructor>(Proto: TBase) =>\n\t\tclass AbstractExtendedStateContainer extends BasicStateContainer<StateType>()(Proto) {\n\t\t\t#__contextValidator: TValidator<TAutomataStateContext<StateType, ContextType>> | undefined;\n\n\t\t\tpublic get validateContext(): TValidator<TAutomataStateContext<StateType, ContextType>> {\n\t\t\t\treturn this.#__contextValidator ?? this.#__defaultContextValidator;\n\t\t\t}\n\n\t\t\tsetContextValidator(contextValidator?: TValidator<TAutomataStateContext<StateType, ContextType>>): this {\n\t\t\t\tif (contextValidator === null) {\n\t\t\t\t\tthis.#__contextValidator = undefined;\n\t\t\t\t\treturn this;\n\t\t\t\t}\n\t\t\t\tif (typeof contextValidator !== 'function')\n\t\t\t\t\tthrow new Error(`passed Context Validator is not a function`);\n\t\t\t\tthis.#__contextValidator = contextValidator.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t#__defaultContextValidator = (p: any): p is TDefinedValues<TAutomataStateContext<StateType, ContextType>> =>\n\t\t\t\tthis.validateState(p?.state) && (p?.context === null || typeof p.context === 'object');\n\t\t};\n}\n","import {\n\tTAbstractConstructor,\n\tTAutomataBaseActionType,\n\tTAutomataBaseEventType,\n\tTAutomataBaseStateType,\n} from '../types/index.js';\nimport ExtendedActionContainer from './ExtendedActionContainer.js';\nimport ExtendedEventContainer from './ExtendedEventContainer.js';\nimport ExtendedStateContainer from './ExtendedStateContainer.js';\n\nexport default function ExtendedValidatorContainer<\n\tStateType extends TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType,\n\tEventType extends TAutomataBaseEventType,\n\tContextType extends { [K in StateType]: any },\n\tPayloadType extends { [K in ActionType]: any },\n\tEventMetaType extends { [K in EventType]: any },\n>() {\n\treturn <TBase extends TAbstractConstructor>(Proto: TBase) =>\n\t\tclass AbstractExtendedValidatorContainer extends ExtendedStateContainer<StateType, ContextType>()(\n\t\t\tExtendedEventContainer<EventType, EventMetaType>()(\n\t\t\t\tExtendedActionContainer<ActionType, PayloadType>()(Proto),\n\t\t\t),\n\t\t) {};\n}\n","import { AbstractBaseClass } from './mixins/BaseClass.js';\nimport ExtendedEventContainer from './mixins/ExtendedEventContainer.js';\nimport { TAbstractConstructor, TAutomataBaseEventType, TAutomataEventStack, TEventBusHandler } from './types/index.js';\nimport { IAutomataEventBus } from './types/interfaces.js';\n\nexport const STACK_RECURSION_LIMIT_RATIO = 2;\nexport const STACK_PROCESSING_BATCH_SIZE = 32;\nexport function createEventBus<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n>() {\n\treturn <TBase extends TAbstractConstructor>(Proto: TBase) =>\n\t\tclass AbstractAutomataEventBus\n\t\t\textends ExtendedEventContainer<EventType, EventMetaType>()(Proto)\n\t\t\timplements IAutomataEventBus<EventType, EventMetaType> {\n\t\t\t#isProcessing: boolean;\n\t\t\t#isPaused: boolean;\n\t\t\t#eventStack: TAutomataEventStack<EventType, EventMetaType>;\n\t\t\t#eventSubscriptions: Map<EventType, Set<TEventBusHandler<EventType, EventMetaType>>>;\n\n\t\t\tconstructor() {\n\t\t\t\tsuper();\n\t\t\t\tthis.#eventStack = [];\n\t\t\t\tthis.#eventSubscriptions = new Map();\n\t\t\t\tthis.#isProcessing = false;\n\t\t\t\tthis.#isPaused = false;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Subscribes to the given event. When the event is received, the callback will be called with the event as an argument.\n\t\t\t * The callback should return a task with incoming event, task ID and a result, which is\n\t\t\t * - either null (if the event was processed synchronously)\n\t\t\t * - or a promise that resolves with an array of new events to be dispatched to the bus.\n\t\t\t * @param event - The event to subscribe to\n\t\t\t * @param callback - The callback to call when the event is received\n\t\t\t * @returns This event bus instance\n\t\t\t */\n\t\t\tpublic subscribe(event: EventType, callback: TEventBusHandler<EventType, EventMetaType>): this {\n\t\t\t\tif (!this.validateEvent(event))\n\t\t\t\t\tthrow new TypeError(`Invalid event passed for subscription}`);\n\n\t\t\t\tif (typeof (callback) !== 'function')\n\t\t\t\t\tthrow new TypeError('Invalid callback passed for subscription');\n\n\t\t\t\tlet eventCallbacks = this.#eventSubscriptions.get(event);\n\n\t\t\t\tif (!eventCallbacks) {\n\t\t\t\t\teventCallbacks = new Set();\n\t\t\t\t\tthis.#eventSubscriptions.set(event, eventCallbacks);\n\t\t\t\t}\n\n\t\t\t\teventCallbacks.add(callback);\n\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic unsubscribe(event: EventType, callback: null | TEventBusHandler<EventType, EventMetaType>): this {\n\t\t\t\tif (!this.validateEvent(event))\n\t\t\t\t\tthrow new TypeError(`Invalid event passed for subscription}`);\n\n\t\t\t\tconst eventCallbacks = this.#eventSubscriptions.get(event);\n\t\t\t\tif (eventCallbacks && callback) {\n\t\t\t\t\teventCallbacks.delete(callback);\n\t\t\t\t} else if (!callback) {\n\t\t\t\t\tthis.#eventSubscriptions.delete(event);\n\t\t\t\t}\n\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Dispatches events to the event bus. If the event bus is not paused, the events will be immediately processed.\n\t\t\t * If the event bus is paused, the events will be buffered and processed when the event bus is resumed.\n\t\t\t * @param events - The events to dispatch\n\t\t\t * @returns This event bus instance\n\t\t\t */\n\t\t\tpublic dispatch(...events: TAutomataEventStack<EventType, EventMetaType>): this {\n\t\t\t\tthis.#eventStack.push(...events);\n\t\t\t\tthis._processEvents();\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic getEventStack(): TAutomataEventStack<EventType, EventMetaType> {\n\t\t\t\treturn this.#eventStack.slice();\n\t\t\t}\n\n\t\t\t/** ***********  ✨ Windsurf Command ⭐  */\n\t\t\t/**\n\t\t\t * Clears the event stack of all events. This method does not prevent new events from being dispatched.\n\t\t\t * @returns This event bus instance\n\t\t\t */\n\t\t\t/** *****  12c97ac8-1158-4225-8ad9-1724f95adea2  */\n\t\t\tpublic clearEventStack(): this {\n\t\t\t\tthis.#eventStack = [];\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic pause(): this {\n\t\t\t\tthis.#isPaused = true;\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic resume(): this {\n\t\t\t\tthis.#isPaused = false;\n\t\t\t\tthis._processEvents();\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tpublic isRunning(): boolean {\n\t\t\t\treturn !this.#isPaused;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Processes events in the event stack and handles them using subscribed callbacks.\n\t\t\t *\n\t\t\t * This method iterates over the event stack, invoking the corresponding callbacks for each valid event,\n\t\t\t * and processes a batch of events limited by `STACK_PROCESSING_BATCH_SIZE`. It checks for recursive event\n\t\t\t * emissions and ensures that the recursion limit does not exceed the defined\n\t\t\t * `STACK_RECURSION_LIMIT_RATIO` relative to the current stack length.\n\t\t\t *\n\t\t\t * @returns {TAutomataEventStack<EventType, EventMetaType>} new events acquired from processing the queue.\n\t\t\t *\n\t\t\t * @throws {Error} If the recursion limit, calculated as a ratio of the stack length, is exceeded for any event.\n\t\t\t *\n\t\t\t */\n\n\t\t\t_processEvents(): Promise<TAutomataEventStack<EventType, EventMetaType>> {\n\t\t\t\tif (this.#isProcessing || this.#isPaused) {\n\t\t\t\t\treturn Promise.resolve([]);\n\t\t\t\t}\n\t\t\t\tconst promiseStack: Array<Promise<TAutomataEventStack<EventType, EventMetaType>>> = [];\n\t\t\t\tlet counter = 0;\n\t\t\t\tthis.#isProcessing = true;\n\t\t\t\twhile (\n\t\t\t\t\tthis.#eventStack.length > 0\n\t\t\t\t\t&& counter++ < STACK_PROCESSING_BATCH_SIZE\n\t\t\t\t) {\n\t\t\t\t\tconst eventObject = this.#eventStack.shift();\n\t\t\t\t\tif (!eventObject)\n\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\tif (!this.validateEventMeta(eventObject)) throw new TypeError('Invalid Event in the queue');\n\n\t\t\t\t\tconst eventCallbacks = this.#eventSubscriptions.get(eventObject.event);\n\n\t\t\t\t\tif (!eventCallbacks?.size) continue;\n\n\t\t\t\t\teventCallbacks.forEach((callback) => {\n\t\t\t\t\t\tconst eventResult = callback(eventObject);\n\n\t\t\t\t\t\tif (!eventResult?.result) return;\n\n\t\t\t\t\t\tpromiseStack.push(eventResult.result);\n\t\t\t\t\t});\n\t\t\t\t\tif (\n\t\t\t\t\t\tpromiseStack.length > STACK_RECURSION_LIMIT_RATIO * this.#eventStack.length\n\t\t\t\t\t\t&& (this.#eventStack.length > 1)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Stack is growing too fast: ${eventObject}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!promiseStack.length) {\n\t\t\t\t\tthis.#isProcessing = false;\n\t\t\t\t\treturn Promise.resolve([]);\n\t\t\t\t}\n\n\t\t\t\tconst returnValue = Promise.all(promiseStack).then(events => events.flat());\n\n\t\t\t\treturnValue.then((events) => {\n\t\t\t\t\tif (events.some(event => !this.validateEventMeta(event)))\n\t\t\t\t\t\tthrow new TypeError('Invalid event received from promise');\n\n\t\t\t\t\tthis.#eventStack.push(...events);\n\t\t\t\t\tthis.#isProcessing = false;\n\n\t\t\t\t\tif (this.#eventStack.length)\n\t\t\t\t\t\tthis._processEvents();\n\t\t\t\t});\n\n\t\t\t\treturn returnValue;\n\t\t\t}\n\t\t};\n}\n\n/**\n * Basic event bus class that is used in Yantrix automatas.\n */\nexport class BasicEventBus\n\textends createEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass)\n\timplements IAutomataEventBus<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>> {\n\tconstructor() {\n\t\tsuper();\n\t}\n}\n\nexport default BasicEventBus;\n","import AutomataEventAdapter from './EventAdapter';\nimport BasicEventBus from './EventBus';\nimport {\n\tIEventDestination,\n\tIEventSource,\n\tTAutomataBaseActionType,\n\tTAutomataBaseEventType,\n\tTAutomataBaseStateType,\n\tTAutomataEventMetaType,\n\tTAutomataEventStack,\n} from './types';\nimport { IAutomata, IAutomataEventAdapter, IAutomataEventBus } from './types/interfaces';\n\ntype TUnsub = () => void;\n\ntype TRegisteredAutomata = {\n\tid: string;\n\tunsubs: TUnsub[];\n};\n\ntype TRegisteredDestination = {\n\tid: string;\n\tunsub: TUnsub;\n};\n\ntype TRegisteredSource = {\n\tid: string;\n\tstop: () => void;\n};\n/**\n * CoreLoop is a minimal main-loop that connects:\n * - an Event Bus (pub/sub for Events),\n * - one or more FSMs (IAutomata) through an Event Adapter,\n * - Sources (producers of Events),\n * - Destinations (consumers of Events).\n *\n * Responsibilities:\n * - Subscribe the adapter to observed Events and dispatch mapped Actions to the FSM.\n * - After each FSM transition, translate emitted Events via the adapter and re-dispatch them to the Event Bus.\n * - Manage lifecycle (start/stop) of Sources and Destinations.\n *\n * Generics:\n * - EventType: enum/number of Events\n * - EventMetaType: a map EventType -> meta payload shape\n */\nexport class CoreLoop<\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> {\n\tprivate readonly bus: IAutomataEventBus<EventType, EventMetaType>;\n\tprivate readonly automata: Map<string, TRegisteredAutomata> = new Map();\n\tprivate readonly destinations: Map<string, TRegisteredDestination> = new Map();\n\tprivate readonly sources: Map<string, TRegisteredSource> = new Map();\n\tprivate started = false;\n\n\tprotected readonly publishToBus = (\n\t\tevent: TAutomataEventMetaType<EventType, EventMetaType>,\n\t): void => {\n\t\tthis.bus.dispatch(event);\n\t};\n\n\tconstructor(bus?: IAutomataEventBus<EventType, EventMetaType>) {\n\t\tthis.bus = (bus ?? (new BasicEventBus() as unknown as IAutomataEventBus<EventType, EventMetaType>));\n\t}\n\n\tpublic getBus(): IAutomataEventBus<EventType, EventMetaType> {\n\t\treturn this.bus;\n\t}\n\n\t/**\n\t * Registers an automata and wires data flow:\n\t * - Event Bus -> Event Adapter -> Actions -> dispatch to the Automata\n\t * - FSM transitions -> Event Adapter -> Events -> Event Bus (via EventBus-aware adapter)\n\t *\n\t * Assumptions:\n\t * - The adapter is already configured with addEventListener(...) and addEventEmitter(...) mappings.\n\t *\n\t * @template StateType Automata state enum (number)\n\t * @template ActionType Automata action enum (number)\n\t * @template ContextType State -> Context mapping\n\t * @template PayloadType Action -> Payload mapping\n\t * @param id Unique identifier for the automata within this CoreLoop\n\t * @param machine Automata instance to register\n\t * @param adapter Optional AutomataEventAdapter; created if not provided\n\t * @throws Error when an automata with the same id is already registered\n\t * @returns This CoreLoop instance (for chaining)\n\t */\n\tpublic registerAutomata<\n\t\tStateType extends TAutomataBaseStateType,\n\t\tActionType extends TAutomataBaseActionType,\n\t\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n\t\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n\t>(\n\t\tid: string,\n\t\tmachine: IAutomata<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType>,\n\t\tadapter?: AutomataEventAdapter,\n\t): this {\n\t\tif (this.automata.has(id)) throw new Error(`Automata with id \"${id}\" already registered`);\n\n\t\tconst bridge\n\t\t\t= adapter\n\t\t\t?? new AutomataEventAdapter();\n\n\t\t// Attach adapter to the automata:\n\t\tmachine.eventAdapter = bridge as unknown as IAutomataEventAdapter<\n\t\t\tStateType,\n\t\t\tActionType,\n\t\t\tEventType,\n\t\t\tContextType,\n\t\t\tPayloadType,\n\t\t\tEventMetaType\n\t\t>;\n\n\t\t// Subscribe to the Event Bus for events observed by the adapter\n\t\tconst observed = bridge.getObservedEvents();\n\t\tconst unsubs: TUnsub[] = [];\n\n\t\tfor (const evt of observed) {\n\t\t\tconst handler = ({ event, meta }: TAutomataEventMetaType<EventType, EventMetaType>) => {\n\t\t\t\tconst nextEventsToProcess: TAutomataEventStack<EventType, EventMetaType> = [];\n\n\t\t\t\t// 1) Event -> Actions\n\t\t\t\tconst actions = bridge.handleEvent({ event, meta } as any);\n\n\t\t\t\t// 2) Actions -> FSM -> Transition -> Emitted Events\n\t\t\t\tfor (const a of actions) {\n\t\t\t\t\tmachine.dispatch(a as any);\n\t\t\t\t\tconst emitted = bridge.handleTransition(machine.getContext()) ?? [];\n\t\t\t\t\tif (emitted?.length) {\n\t\t\t\t\t\tnextEventsToProcess.push(...(emitted as TAutomataEventStack<EventType, EventMetaType>));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tevent,\n\t\t\t\t\tmeta,\n\t\t\t\t\ttask_id: `event_${String(event)}`,\n\t\t\t\t\tresult: Promise.resolve(nextEventsToProcess),\n\t\t\t\t};\n\t\t\t};\n\n\t\t\tthis.bus.subscribe(evt as EventType, handler as any);\n\t\t\tunsubs.push(() => this.bus.unsubscribe(evt as EventType, handler as any));\n\t\t}\n\n\t\tthis.automata.set(id, { id, unsubs });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Unregisters a previously registered automata by id.\n\t *\n\t * Behavior:\n\t * - Safely unsubscribes all event bus subscriptions created during registration.\n\t * - Removes automata entry from the registry. No-op if not found.\n\t *\n\t * @param id Automata identifier passed during registration.\n\t * @returns This CoreLoop instance for chaining.\n\t */\n\tpublic unregisterAutomata(id: string): this {\n\t\tconst reg = this.automata.get(id);\n\t\tif (reg) {\n\t\t\treg.unsubs.forEach(u => u());\n\t\t\tthis.automata.delete(id);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Registers a Source. The Source is started immediately if the loop is already running.\n\t * Note: This method treats the passed-in object as immutable and does NOT mutate src.id.\n\t * Non-empty src. Id is required.\n\t */\n\tpublic registerSource(src: IEventSource<EventType, EventMetaType>): this {\n\t\tif (!src.id || src.id.length === 0) {\n\t\t\tthrow new Error('Source must provide a non-empty string id');\n\t\t}\n\t\tconst id = src.id;\n\n\t\tif (this.sources.has(id)) {\n\t\t\tthrow new Error(`Source with id \"${id}\" already registered`);\n\t\t}\n\n\t\tif (this.started) {\n\t\t\tsrc.start(this.publishToBus);\n\t\t}\n\n\t\tthis.sources.set(id, {\n\t\t\tid,\n\t\t\tstop: () => src.stop(),\n\t\t});\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Unregisters a previously registered Source by id.\n\t *\n\t * Behavior:\n\t * - Calls Source.stop() if present.\n\t * - Removes the source from the registry. No-op if not found.\n\t *\n\t * @param id Source identifier assigned on registration.\n\t * @returns This CoreLoop instance for chaining.\n\t */\n\tpublic unregisterSource(id: string): this {\n\t\tconst reg = this.sources.get(id);\n\t\tif (reg) {\n\t\t\treg.stop();\n\t\t\tthis.sources.delete(id);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Registers a Destination. Destination is responsible for its own subscriptions via bind().\n\t *\n\t * @param dst Destination to register\n\t * @throws Error if a Destination with the same id is already registered\n\t * @returns This CoreLoop instance for chaining.\n\t */\n\tpublic registerDestination(dst: IEventDestination<EventType, EventMetaType>): this {\n\t\tif (!dst.id || dst.id.length === 0) {\n\t\t\tthrow new Error('Destination must provide a non-empty string id');\n\t\t}\n\t\tconst id = dst.id;\n\n\t\tif (this.destinations.has(id)) throw new Error(`Destination with id \"${id}\" already registered`);\n\n\t\tconst unsub = dst.bind(this.bus);\n\t\tthis.destinations.set(id, { id, unsub });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Unregisters a previously registered Destination by id.\n\t *\n\t * Behavior:\n\t * - Invokes the unsubscription function returned by Destination.bind().\n\t * - Removes the destination from the registry. No-op if not found.\n\t *\n\t * @param id Destination identifier assigned on registration.\n\t * @returns This CoreLoop instance for chaining.\n\t */\n\tpublic unregisterDestination(id: string): this {\n\t\tconst reg = this.destinations.get(id);\n\t\tif (reg) {\n\t\t\treg.unsub();\n\t\t\tthis.destinations.delete(id);\n\t\t}\n\t\treturn this;\n\t}\n\n\tpublic start(): this {\n\t\tif (this.started) return this;\n\t\tthis.started = true;\n\t\tthis.bus.resume();\n\n\t\treturn this;\n\t}\n\n\tpublic stop(): this {\n\t\tif (!this.started) return this;\n\t\tthis.started = false;\n\t\tthis.bus.pause();\n\n\t\t// Stop all sources\n\t\tthis.sources.forEach(s => s.stop());\n\n\t\t// Unsubscribe all destinations\n\t\tthis.destinations.forEach(d => d.unsub());\n\n\t\treturn this;\n\t}\n}\n","import { AbstractBaseClass } from './mixins/BaseClass';\nimport ExtendedEventContainer from './mixins/ExtendedEventContainer';\nimport { TAbstractConstructor, TAutomataBaseEventType, TAutomataEventStack, TCycleIteratorInfo, TDataSourceConstructorOpts } from './types';\nimport { IAgnosticDataSource, IDataSource } from './types/interfaces';\n\nexport abstract class AbstractAgnosticDataSource<T> extends AbstractBaseClass implements IAgnosticDataSource<T> {\n\t#_dataPacketQueue: T[] = [];\n\t#active = false;\n\t#currentCycle = 0;\n\t#totalCycles = 0;\n\t#epoch = 1;\n\t#id: string;\n\n\tpublic get currentCycle(): number {\n\t\treturn this.#currentCycle;\n\t}\n\n\tpublic get totalCycles(): number {\n\t\treturn this.#totalCycles;\n\t}\n\n\tpublic get currentEpoch(): number {\n\t\treturn this.#epoch;\n\t}\n\n\tpublic get id(): string {\n\t\treturn this.#id;\n\t}\n\n\t_getCycleIteratorInfo(): TCycleIteratorInfo {\n\t\treturn {\n\t\t\tcurrentCycle: this.currentCycle,\n\t\t\ttotalCycles: this.totalCycles,\n\t\t\tcurrentEpoch: this.currentEpoch,\n\t\t};\n\t}\n\n\t_isValidId(id: any): id is string {\n\t\treturn id === undefined || id === null || (typeof id === 'string' && id?.length > 0);\n\t}\n\n\tclearQueue() {\n\t\tconst d = this.#_dataPacketQueue.slice();\n\t\tthis.#_dataPacketQueue = [];\n\t\tthis.#currentCycle = 0;\n\t\tthis.#epoch++;\n\t\treturn d;\n\t}\n\n\tpublic constructor(opts: TDataSourceConstructorOpts<T>) {\n\t\tsuper();\n\t\tif (!this._isValidId(opts?.id))\n\t\t\tthrow new TypeError('Invalid ID');\n\t\tthis.#id = opts.id || this.correlationId;\n\t\tif (typeof opts?.afterInit === 'function') {\n\t\t\topts.afterInit(\n\t\t\t\tthis.id,\n\t\t\t\t(data: T) => this._addDataPacket(data),\n\t\t\t\tthis.clearQueue.bind(this),\n\t\t\t);\n\t\t} else if (opts?.afterInit) {\n\t\t\tthrow new TypeError(`Invalid afterInit function for Data Source #${this.id}`);\n\t\t}\n\t}\n\n\tpublic start(): this {\n\t\tthis.#currentCycle = 0;\n\t\tthis.#epoch++;\n\t\tthis.#active = true;\n\t\treturn this;\n\t}\n\n\tpublic stop(): this {\n\t\tthis.#active = false;\n\t\treturn this;\n\t}\n\n\tpublic isActive(): boolean {\n\t\treturn this.#active;\n\t}\n\n\t_addDataPacket(dataPacket: T): void {\n\t\tthis.#currentCycle++;\n\t\tthis.#totalCycles++;\n\t\tthis.#_dataPacketQueue.push(dataPacket);\n\t}\n\n\t_getDataPacket(): T | null {\n\t\tconst t = this.#_dataPacketQueue.shift();\n\t\tif (t === undefined) return null;\n\t\treturn t;\n\t}\n\n\tpublic *dataEmitter() {\n\t\twhile (true) {\n\t\t\tif (this.isActive() && this.#_dataPacketQueue.length) {\n\t\t\t\tyield this._getDataPacket();\n\t\t\t} else {\n\t\t\t\tyield null;\n\t\t\t}\n\t\t}\n\t}\n}\n\ntype TIntervalTimerDataSourceDataPacket = {\n\tid: string;\n\ttimestamp: number;\n\tstartTimestamp: number;\n} & TCycleIteratorInfo;\nexport class IntervalTimerDataSource extends AbstractAgnosticDataSource<TIntervalTimerDataSourceDataPacket> {\n\t#intervalLink: any = null;\n\t#interval: number = 0;\n\t#startTimestamp = 0;\n\n\t_isValidInterval(interval: any): interval is number {\n\t\treturn Number.isFinite(interval) && Number.isInteger(interval) && interval > 0;\n\t}\n\n\tpublic constructor(opts: TDataSourceConstructorOpts<TIntervalTimerDataSourceDataPacket> & { interval: number }) {\n\t\tsuper(opts);\n\t\tif (!this._isValidInterval(opts.interval))\n\t\t\tthrow new RangeError(`Invalid timer interval for Data Source #${this.id}`);\n\t\tthis.#interval = opts.interval;\n\t}\n\n\toverride start(): this {\n\t\tsuper.start();\n\t\tthis.#startTimestamp = Date.now();\n\t\tif (this.#intervalLink != null)\n\t\t\tclearInterval(this.#intervalLink);\n\t\tthis.#intervalLink = setInterval(() => this._addDataPacket({\n\t\t\tid: this.id,\n\t\t\tstartTimestamp: this.#startTimestamp,\n\t\t\ttimestamp: Date.now(),\n\t\t\t...this._getCycleIteratorInfo(),\n\t\t}), this.#interval);\n\t\treturn this;\n\t}\n\n\toverride stop(): this {\n\t\tsuper.stop();\n\t\tif (this.#intervalLink != null) {\n\t\t\tclearInterval(this.#intervalLink);\n\t\t\tthis.#intervalLink = null;\n\t\t}\n\t\treturn this;\n\t}\n}\n\nexport class NamedDataSource<T> extends AbstractAgnosticDataSource<T> {\n\toverride _addDataPacket(dataPacket: T): void {\n\t\tsuper._addDataPacket(Object.assign({}, dataPacket, { id: this.id }));\n\t}\n}\n\nexport function createDataSourceAdapter<\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n\tDataPacketType = any,\n>() {\n\treturn <BaseType extends TAbstractConstructor<\n\t\tAbstractAgnosticDataSource<DataPacketType>\n\t> = TAbstractConstructor<\n\t\tAbstractAgnosticDataSource<DataPacketType>\n\t>>(Base: BaseType) =>\n\t\tclass AbstractAutomataDataSource extends ExtendedEventContainer<\n\t\t\tEventType,\n\t\t\tEventMetaType\n\t\t>()(Base) implements IDataSource<EventType, EventMetaType, DataPacketType> {\n\t\t\t#eventListeners: Partial<{\n\t\t\t\t[id: string]: [\n\t\t\t\t\t(data: DataPacketType) => TAutomataEventStack<EventType, EventMetaType>,\n                    null | ((...events: TAutomataEventStack<EventType, EventMetaType>) => any),\n\t\t\t\t];\n\t\t\t}> = {};\n\n\t\t\taddListener(\n\t\t\t\tid: string,\n\t\t\t\ttransform: (data: DataPacketType) => TAutomataEventStack<EventType, EventMetaType>,\n\t\t\t\tdispatch?: (...events: TAutomataEventStack<EventType, EventMetaType>) => any,\n\t\t\t): this {\n\t\t\t\tif (typeof transform !== 'function')\n\t\t\t\t\tthrow new TypeError(`Invalid transformer provided in event listener for Data Source #${this.id}`);\n\n\t\t\t\tif (dispatch && typeof dispatch !== 'function')\n\t\t\t\t\tthrow new TypeError(`Invalid dispatcher provided in event listener for Data Source #${this.id}`);\n\n\t\t\t\tthis.#eventListeners[id] = [transform, dispatch || null];\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tremoveListener(id: string): this {\n\t\t\t\tif (!this.#eventListeners[id])\n\t\t\t\t\tthrow new TypeError(`Invalid event listener id for Data Source #${this.id}`);\n\t\t\t\tdelete this.#eventListeners[id];\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tgetEventListeners() {\n\t\t\t\treturn this.#eventListeners;\n\t\t\t}\n\n\t\t\tgetListenerKeys() {\n\t\t\t\treturn Object.keys(this.#eventListeners);\n\t\t\t}\n\n\t\t\toverride *dataEmitter() {\n\t\t\t\tconst dataEmitter = super.dataEmitter();\n\t\t\t\twhile (this.isActive()) {\n\t\t\t\t\tconst dataPacket = dataEmitter.next();\n\t\t\t\t\tif (dataPacket.value) {\n\t\t\t\t\t\tfor (const id of this.getListenerKeys()) {\n\t\t\t\t\t\t\tconst [transform, dispatch] = this.#eventListeners[id]!;\n\t\t\t\t\t\t\tconst events = transform(dataPacket.value) || [];\n\n\t\t\t\t\t\t\tif (!events.length)\n\t\t\t\t\t\t\t\tcontinue;\n\n\t\t\t\t\t\t\tif (!events.some(this.validateEventMeta))\n\t\t\t\t\t\t\t\tthrow new Error(`Got invalid event stack from transformer: ${JSON.stringify(events)}`);\n\n\t\t\t\t\t\t\tif (dispatch) {\n\t\t\t\t\t\t\t\tdispatch(...events);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tyield dataPacket.value;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tyield null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tyield null;\n\t\t\t}\n\n\t\t\t*eventEmitter() {\n\t\t\t\tconst dataEmitter = super.dataEmitter();\n\t\t\t\tlet allEvents: TAutomataEventStack<EventType, EventMetaType> = [];\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst dataPacket = dataEmitter.next();\n\t\t\t\t\tallEvents = [];\n\t\t\t\t\tif (dataPacket.value) {\n\t\t\t\t\t\tfor (const id of this.getListenerKeys()) {\n\t\t\t\t\t\t\tconst [transform, dispatch] = this.#eventListeners[id]!;\n\t\t\t\t\t\t\tconst events = transform(dataPacket.value) || [];\n\t\t\t\t\t\t\tif (!events.length)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tif (!events.some(this.validateEventMeta))\n\t\t\t\t\t\t\t\tthrow new Error(`Got invalid event stack from transformer: ${events}`);\n\t\t\t\t\t\t\tallEvents = allEvents.concat(events);\n\t\t\t\t\t\t\tif (dispatch) {\n\t\t\t\t\t\t\t\tdispatch(...events);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tyield allEvents;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n}\n\nexport class BasicDataSource extends createDataSourceAdapter<\n\tTAutomataBaseEventType,\n\tRecord<TAutomataBaseEventType, any>,\nobject\n>()(NamedDataSource<object>) { }\nexport default BasicDataSource;\n","import { TAutomataBaseEventType } from './index.js';\nimport { AbstractBaseClass } from './mixins/BaseClass.js';\nimport DictionaryContainer from './mixins/DictionaryContainer.js';\nimport ExtendedEventContainer from './mixins/ExtendedEventContainer.js';\nimport { TEventKeysCollection, TEventLookupParams, TEventValuesCollection } from './types/dictionaries.js';\nimport { TAbstractConstructor } from './types/index.js';\nimport { IEventDictionary } from './types/interfaces.js';\n\nexport function createEventDictionary<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any },\n>() {\n\treturn <BaseType extends TAbstractConstructor = TAbstractConstructor>(Base: BaseType) =>\n\t\tclass AbstractEventDictionary extends DictionaryContainer<EventType>()(\n\t\t\tExtendedEventContainer<EventType, EventMetaType>()(Base),\n\t\t) {\n\t\t\t/**\n\t\t\t * Retrieves event keys bound to the namespace\n\t\t\t * @param obj - object with list of events to get keys for and associated namespace\n\t\t\t * @param obj.events - list of events to get keys for\n\t\t\t * @param obj.namespace - associated namespace\n\t\t\t * @returns Array of event keys\n\t\t\t */\n\t\t\tgetEventKeys({\n\t\t\t\tevents = [],\n\t\t\t\tnamespace = undefined,\n\t\t\t}: TEventValuesCollection<EventType>): Array<string | null> {\n\t\t\t\treturn (events ?? []).map((event) => {\n\t\t\t\t\tif (!this.validateEvent(event))\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tconst data = this._getValueData(event);\n\t\t\t\t\tif (!data)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tif (namespace !== null && namespace !== data.namespace)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\treturn data?.key;\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Clears all events bound to the namespace\n\t\t\t * @param namespace\n\t\t\t * @returns dictionary\n\t\t\t */\n\t\t\tclearEvents(namespace?: string): this {\n\t\t\t\treturn this._clearItems(namespace);\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Removes specified events from the dictionary\n\t\t\t * @param obj - object with namespace, list of events/keys to delete\n\t\t\t * @returns dictionary\n\t\t\t */\n\t\t\tremoveEvents({ namespace, events = [], keys = [] }: TEventLookupParams<EventType>): this {\n\t\t\t\tconst eventsToDelete = [\n\t\t\t\t\t...events.filter(this.validateEvent),\n\t\t\t\t\t...keys.flatMap(k => (k ? [this._findItem(k, namespace)] : [])),\n\t\t\t\t].filter(v => v !== null);\n\t\t\t\tconst eventKeys = eventsToDelete\n\t\t\t\t\t.map(event => this._getValueData(event))\n\t\t\t\t\t.filter(data => !!data && (namespace == null || namespace === data?.namespace));\n\t\t\t\tfor (const eventKey of eventKeys) {\n\t\t\t\t\tif (eventKey)\n\t\t\t\t\t\tthis._deleteItemKey(eventKey.key);\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Retrieves event values bound to the namespace\n\t\t\t * @param obj - object with list of keys to get events from and associated namespace\n\t\t\t * @returns Array of event values\n\t\t\t */\n\t\t\tgetEventValues({\n\t\t\t\tnamespace = undefined,\n\t\t\t\tkeys = [],\n\t\t\t}: TEventKeysCollection<EventType>): Array<EventType | null> {\n\t\t\t\treturn (keys ?? []).flatMap(k => (k ? [this._findItem(k, namespace)] : []));\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Add events to the namespace\n\t\t\t * @param obj - object with list of keys to get events from and associated namespace\n\t\t\t * @returns Array of added events\n\t\t\t */\n\t\t\taddEvents({ namespace = undefined, keys }: TEventKeysCollection<EventType>): EventType[] {\n\t\t\t\treturn (keys || []).flatMap(k => (k ? [this._addItemKey(k, namespace)] : []));\n\t\t\t}\n\t\t};\n}\n\n/**\n * Basic event dictionary class that's used in Yantrix automatas.\n */\nexport class BasicEventDictionary\n\textends createEventDictionary<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>>()(AbstractBaseClass)\n\timplements IEventDictionary<TAutomataBaseEventType, Record<TAutomataBaseEventType, any>> {\n\tconstructor() {\n\t\tsuper();\n\t}\n}\n\nexport const EventDictionary = new BasicEventDictionary();\nexport default BasicEventDictionary;\n","import { TAutomataFunction } from './types';\nimport { IAutomataFunctionRegistry } from './types/interfaces';\n\n/**\n * Implementation of {@link IAutomataFunctionRegistry}, where functions are stored in a map.\n *\n * Has strict requirements for registering new functions, overwrites are not possible.\n */\nexport class FunctionDictionary implements IAutomataFunctionRegistry {\n\tprivate functions: Record<string, TAutomataFunction>;\n\n\tconstructor(functions?: Record<string, TAutomataFunction>) {\n\t\tthis.functions = functions ?? {};\n\t}\n\n\tregister(\n\t\tf: string | Record<string, TAutomataFunction>,\n\t\tcallback?: TAutomataFunction,\n\t): Record<string, TAutomataFunction> {\n\t\tif (typeof f === 'string' && callback != null) {\n\t\t\treturn this.registerSingleFunction(f, callback);\n\t\t} else if (typeof f === 'object') {\n\t\t\treturn this.registerMultipleFunctions(f);\n\t\t} else {\n\t\t\tthrow new TypeError('Incorrect arguments');\n\t\t}\n\t}\n\n\tprivate registerSingleFunction(\n\t\tfunctionKey: string,\n\t\tcallback: TAutomataFunction,\n\t): Record<string, TAutomataFunction> {\n\t\tif (functionKey.length < 1 || functionKey.length > 255) {\n\t\t\tthrow new Error(`Function key length must be between 1-255 symbols!`);\n\t\t}\n\t\tif (!functionKey.match(/^[a-z]\\w+$/i)) {\n\t\t\tthrow new Error('Incorrect function key format!');\n\t\t}\n\t\tif (this.functions[functionKey] !== undefined) {\n\t\t\tthrow new Error(`Function with the key ${functionKey} already exists, overwrite not permitted!`);\n\t\t}\n\n\t\tthis.functions[functionKey] = callback;\n\t\treturn { [functionKey]: callback };\n\t}\n\n\tprivate registerMultipleFunctions(\n\t\tfunctionMap: Record<string, TAutomataFunction>,\n\t): Record<string, TAutomataFunction> {\n\t\tObject.entries(functionMap).forEach(([name, callback]) => this.registerSingleFunction(name, callback));\n\t\treturn functionMap;\n\t}\n\n\thas(functionKey: string) {\n\t\tconst func = this.functions[functionKey];\n\t\treturn func !== undefined;\n\t}\n\n\tget(functionKey: string): TAutomataFunction {\n\t\tconst func = this.functions[functionKey];\n\t\tif (func)\n\t\t\treturn func;\n\t\telse throw new Error(`Function with the key ${functionKey} not found!`);\n\t}\n\n\tcall(functionKey: string, ...args: any[]) {\n\t\tconst func = this.get(functionKey)!;\n\t\treturn func(...args);\n\t}\n\n\tclear() {\n\t\tthis.functions = {};\n\t}\n}\n","import { uniqId } from '@yantrix/utils';\nimport { createDataDestinationAdapter, NamedDataDestination } from './DataDestination';\nimport { createDataSourceAdapter, NamedDataSource } from './DataSource';\nimport { TAutomataBaseEventType, TAutomataEventMetaType, TAutomataEventStack } from './types';\nimport { IDataDestination, IDataSource } from './types/interfaces';\n\n/**\n * Creates a Data Source and a Data Destination that are connected by a\n * function that resolves a Promise with input data and returns the result\n * as an event.\n *\n * @param {object} opts\n * @param {string} [opts.id] - An optional id for the Data Source and Data Destination\n * @param {Function} opts.resolver - A function that resolves a Promise with input data\n * @param {Function} opts.requestMapper - A function that maps an event to input data\n * @param {Function} opts.responseMapper - A function that maps the result of the resolver to an event\n * @param {EventType[]} [opts.requestEvents]- An array of event names that should trigger the request\n * @param {EventType[]} opts.responseEvents - An array of event names that should be emitted by the Data Source\n * @returns {[IDataSource, IDataDestination]} - An array with the Data Source and the Data Destination\n */\nfunction createPromiseDataAdapter<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends Record<EventType, any>,\n\tInputData extends object,\n\tOutputData = any,\n>(opts: {\n\tid?: string;\n\tresolver: (data: InputData) => Promise<OutputData>;\n\trequestMapper: (event: TAutomataEventMetaType<EventType, EventMetaType>) => InputData | null;\n\tresponseMapper: (data: OutputData) => TAutomataEventStack<EventType, EventMetaType>;\n\trequestEvents: EventType[] | null;\n},\n): [\n\t\tIDataSource<EventType, EventMetaType, OutputData>,\n\t\tIDataDestination<EventType, EventMetaType, null, InputData, OutputData>,\n\t] {\n\tconst { id, resolver, requestEvents, requestMapper, responseMapper } = opts;\n\n\tlet setterFunction: (data: OutputData) => any;\n\n\tconst SourceConstructor = createDataSourceAdapter<\n\t\tEventType,\n\t\tEventMetaType,\n\t\tOutputData\n\t>()(NamedDataSource<OutputData>);\n\n\tconst dataSource = new SourceConstructor({\n\t\tid,\n\t\tafterInit: (_id, setter) => {\n\t\t\tif (setter)\n\t\t\t\tsetterFunction = setter;\n\t\t},\n\t});\n\n\tconst DestinationConstructor = createDataDestinationAdapter<\n\t\tEventType,\n\t\tEventMetaType,\n\t\tnull,\n\t\tInputData,\n\t\tOutputData\n\t>()(NamedDataDestination<InputData, OutputData>);\n\n\tconst dataDestination = new DestinationConstructor({\n\t\tid,\n\t\tresolver: (data: InputData) => resolver(data).then((result: OutputData) => {\n\t\t\tsetterFunction(result);\n\t\t\treturn result;\n\t\t}),\n\t});\n\tdataDestination.createTrigger(requestEvents, requestMapper);\n\tdataSource.addListener(uniqId(), responseMapper);\n\n\treturn [dataSource, dataDestination];\n}\n\nexport type THTTPRequestAdapterInput = {\n\trequest: RequestInit;\n\tevent_id: TAutomataBaseEventType;\n};\n\nexport type THTTPRequestAdapterOutput = {\n\tresponse: Response;\n\tevent_id: TAutomataBaseEventType;\n};\n/**\n * Creates a Data Source and a Data Destination that are connected by a list of HTTP Requests, each initiated by a certain event\n *\n * @param {object} opts\n * @param {string} [opts.id] - An optional id for the Data Source and Data Destination\n * @param {object} opts.routes - An object with event names as keys and an array with the request options and the response mapper as values\n * @returns {[IDataSource, IDataDestination]} - An array with the Data Source and the Data Destination\n */\nexport function createHTTPRequestAdapter<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends Record<EventType, any>,\n>(opts: {\n\tid?: string;\n\troutes: Partial<{ [K in EventType]: [\n\t\t(event: TAutomataEventMetaType<K, EventMetaType>) => RequestInit | null,\n\t\t(data: Response) => TAutomataEventStack<EventType, EventMetaType>,\n\t] }>;\n},\n): [\n\t\tIDataSource<EventType, EventMetaType, THTTPRequestAdapterOutput>,\n\t\tIDataDestination<EventType, EventMetaType, null, THTTPRequestAdapterInput, THTTPRequestAdapterOutput>,\n\t] {\n\tconst { id = uniqId(), routes } = opts;\n\n\tconst requestEvents = Object.keys(routes).map(x => Number.parseInt(x)) as EventType[];\n\n\tconst reqHandler = (event: TAutomataEventMetaType<EventType, EventMetaType>): THTTPRequestAdapterInput | null => {\n\t\tif (!event?.event)\n\t\t\treturn null;\n\t\tconst opts = routes[event.event];\n\t\tif (!opts)\n\t\t\treturn null;\n\t\tconst request = opts[0](event);\n\t\tif (!request) return null;\n\t\treturn {\n\t\t\trequest,\n\t\t\tevent_id: event.event,\n\t\t};\n\t};\n\n\tconst rspHandler = (data: THTTPRequestAdapterOutput): TAutomataEventStack<EventType, EventMetaType> => {\n\t\tconst eId = data?.event_id as EventType;\n\t\tif (!eId)\n\t\t\treturn [];\n\t\tconst opts = routes[eId];\n\t\tif (!opts || !opts[1])\n\t\t\treturn [];\n\t\treturn opts[1](data.response);\n\t};\n\n\treturn createPromiseDataAdapter<EventType, EventMetaType, THTTPRequestAdapterInput, THTTPRequestAdapterOutput>({\n\t\tid,\n\t\tresolver: async (data: THTTPRequestAdapterInput) => {\n\t\t\tconst req = data.request as RequestInit & { url: string };\n\t\t\tconst request = new Request(req.url, {\n\t\t\t\tmethod: data.request.method,\n\t\t\t});\n\t\t\tconst response = await fetch(request);\n\t\t\treturn { response, event_id: data.event_id };\n\t\t},\n\t\trequestEvents,\n\t\trequestMapper: reqHandler,\n\t\tresponseMapper: rspHandler,\n\t});\n}\n","import { IAutomataEventBus, IAutomataFunctionRegistry } from './interfaces';\n\n/**\n * Represents the base state type for the automata.\n */\nexport type TAutomataBaseStateType = number;\n\n/**\n * Represents the base action type for the automata.\n */\nexport type TAutomataBaseActionType = number;\n\n/**\n * Represents the base event type for the automata.\n */\nexport type TAutomataBaseEventType = number;\n\nexport interface IBaseClass {\n\tnext?: () => this;\n\tcorrelationId: string;\n}\n\nexport type TAbstractConstructor<T = object> = new (...args: any[]) => T;\n\nexport type TAbstractFunction<T = any> = (...args: any[]) => T;\n\nexport type TMixin<T extends TAbstractFunction> = InstanceType<ReturnType<T>>;\n\nexport type TMergeClassTrait<TTrait extends TAbstractConstructor, TTarget extends TAbstractConstructor> = (new (\n\t...a: ConstructorParameters<TTarget>\n) => InstanceType<TTrait> & InstanceType<TTarget>) &\nPick<TTarget, keyof TTarget> &\nPick<TTrait, keyof TTrait>;\n\n/**\n * Container for automata state.\n */\nexport type TAutomataStateContainer<StateType extends TAutomataBaseStateType> = {\n\tstate: StateType | null;\n};\n\n/**\n * Container for automata action.\n */\nexport type TAutomataActionContainer<ActionType extends TAutomataBaseActionType> = {\n\taction: ActionType | null;\n};\n\n/**\n * Container for automata event.\n */\nexport type TAutomataEventContainer<EventType extends TAutomataBaseEventType> = {\n\tevent: EventType | null;\n};\n\n/**\n * Represents the current state & associated context of the automata.\n *\n * @template StateType - The type of the automata state.\n * @template ContextType - The type of the context associated with each state.\n */\nexport type TAutomataStateContext<\n\tStateType extends TAutomataBaseStateType,\n\tContextType extends { [K in StateType]: any },\n> = TAutomataStateContainer<StateType> & {\n\tcontext: ContextType[StateType] | null;\n};\n\n/**\n * Represents the action for an automata, together with its payload.\n *\n * @template ActionType - The type of the automata action.\n * @template PayloadType - The type of the payload associated with each action.\n */\nexport type TAutomataActionPayload<\n\tActionType extends TAutomataBaseActionType,\n\tPayloadType extends { [K in ActionType]: any },\n> = TAutomataActionContainer<ActionType> & {\n\tpayload: PayloadType[ActionType] | null;\n};\n\n/**\n * Represents the event that can be emitted or received by an automata.\n *\n * @template EventType - The type of the automata event.\n * @template EventMetaType - The type of the metadata associated with each event.\n */\nexport type TAutomataEventMetaType<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> = TAutomataEventContainer<EventType> & {\n\tmeta: EventMetaType[EventType] | null;\n};\n\n/**\n * Represents an event handler function for an automata.\n *\n * @template EventType - The type of the automata event.\n * @template ActionType - The type of the automata action.\n * @template EventMetaType - The type of the metadata associated with each event.\n * @template PayloadType - The type of the payload associated with each action.\n * @param event - The event metadata.\n * @returns The action(and its payload) that needs to be dispatched to the automata upon processing the event.\n */\nexport type TAutomataEventHandler<\n\tEventType extends TAutomataBaseEventType,\n\tActionType extends TAutomataBaseActionType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n> = (event: TAutomataEventMetaType<EventType, EventMetaType>) => TAutomataActionPayload<ActionType, PayloadType>;\n\n/**\n * Represents an event emitter function for an automata.\n *\n * @template EventType - The type of the automata event.\n * @template StateType - The type of the automata state.\n * @template EventMetaType - The type of the metadata associated with each event.\n * @template ContextType - The type of the context associated with each state.\n * @param state - The current state of the automata.\n * @returns The event that needs to be emitted by the automata after executing a certain `Action`.\n */\nexport type TAutomataEventEmitter<\n\tEventType extends TAutomataBaseEventType,\n\tStateType extends TAutomataBaseStateType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n> = (state: TAutomataStateContext<StateType, ContextType>) => TAutomataEventMetaType<EventType, EventMetaType>;\n\nexport type TAutomataEvent<\n\tStateType extends TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n> = TAutomataStateContext<StateType, ContextType> & TAutomataActionPayload<ActionType, PayloadType>;\n\n/**\n * Represents a reducer function for an automata,\n * used for changing the state upon the dispatch of a certain `Action`.\n *\n * @template StateType - The type of the current automata state.\n * @template ActionType - The type of the automata action.\n * @template ContextType - The type of the context associated with each state.\n * @template PayloadType - The type of the payload associated with each action.\n * @template NewStateType - The type of the new state for the automata.\n * @param params - The event parameters.\n * @returns The new state that the automata should enter and its updated context.\n */\nexport type TAutomataReducer<\n\tStateType extends TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n\tNewStateType extends StateType = StateType,\n> = (\n\tparams: TAutomataEvent<StateType, ActionType, ContextType, PayloadType>,\n) => TAutomataStateContext<NewStateType, ContextType>;\n\n/**\n * Represents a dispatch function for an automata,\n * used for dispatching certain `Actions` to the automata to change its state.\n *\n * @template StateType - The type of the automata state.\n * @template ActionType - The type of the automata action.\n * @template ContextType - The type of the context associated with each state.\n * @template PayloadType - The type of the payload associated with each action.\n * @template NewStateType - The type of the new state after the dispatch.\n * @param action - The action payload.\n * @returns The new state of the automata and the updated context.\n */\nexport type TAutomataDispatch<\n\tStateType extends TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n\tNewStateType extends StateType = StateType,\n> = (\n\taction: TAutomataActionPayload<ActionType, PayloadType>,\n) => ReturnType<TAutomataReducer<StateType, ActionType, ContextType, PayloadType, NewStateType>>;\n\nexport type TSubscriptionCancelFunction = () => void;\n\n/**\n * Represents a type with all properties defined and non-nullable.\n *\n * @template T - The type to transform.\n */\nexport type TDefinedValues<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]: NonNullable<T[P]>;\n\t\t}\n\t: NonNullable<T>;\n\n/**\n * Represents a validator function of the automata.\n * Used as a template for validating the automata state, action, event, or event metadata.\n *\n * @example\n * ```typescript\n * // Create an action validator for the automata:\n * const testValidator = ((a: number) => a % 15 === 0) as TValidator<TTestAction>;\n * sampleAutomataInstance.setActionValidator(testValidator);\n * ```\n *\n * @template T - The type of the validator.\n * @param x - The value to validate.\n */\nexport type TValidator<T> = (x: any) => x is TDefinedValues<T>;\n\n/**\n * Parameters for automata configuration.\n */\nexport type TAutomataParams<\n\tStateType extends TAutomataBaseStateType,\n\tActionType extends TAutomataBaseActionType,\n\tEventType extends TAutomataBaseEventType,\n\tContextType extends {\n\t\t[K in StateType]: any;\n\t} = Record<StateType, any>,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> = TAutomataStateContext<StateType, ContextType> & {\n\trootReducer: TAutomataReducer<StateType, ActionType, ContextType, PayloadType> | null;\n\tstateValidator?: TValidator<StateType>;\n\tactionValidator?: TValidator<ActionType>;\n\teventValidator?: TValidator<EventType>;\n\teventMetaValidator?: TValidator<EventMetaType>;\n\tfunctionRegistry?: IAutomataFunctionRegistry;\n\tenabled?: boolean;\n\tpaused?: boolean;\n};\n\n/**\n * Queue for automata actions.\n */\nexport type TAutomataQueue<\n\tActionType extends TAutomataBaseActionType,\n\tPayloadType extends { [K in ActionType]: any } = Record<ActionType, any>,\n> = Array<TAutomataActionPayload<ActionType, PayloadType>>;\n\n/**\n * Stack for automata events.\n */\nexport type TAutomataEventStack<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> = Array<TAutomataEventMetaType<EventType, EventMetaType>>;\n\n/**\n * Effect function for automata model.\n */\nexport type TAutomataEffect<\n\tModelType extends object,\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> = (event: EventMetaType, model: ModelType) => ModelType;\n\nexport type TGenericTransformer<DataType> = (data: DataType) => DataType;\n\n/**\n * Represents a transformer function for the context of an automata state.\n * This transformer can be added to the `State Dictionary` of the automata.\n *\n * @template StateType - The type of the automata state.\n * @template ContextType - The type of the context associated with each state.\n * @param context - The current state (and context) of the automata.\n * @returns The transformed state (and context) of the automata.\n */\nexport type TContextTransformer<\n\tStateType extends TAutomataBaseStateType,\n\tContextType extends {\n\t\t[K in StateType]: any;\n\t} = Record<StateType, any>,\n> = (context: TAutomataStateContext<StateType, ContextType>) => TAutomataStateContext<StateType, ContextType>;\n\nexport type TContextPredicate<\n\tStateType extends TAutomataBaseStateType,\n\tContextType extends {\n\t\t[K in StateType]: any;\n\t} = Record<StateType, any>,\n> = (context: TAutomataStateContext<StateType, ContextType>) => THighOrderPredicate;\n\nexport type TModelPredicate<ModelType extends object = Record<string, any>> = (model: ModelType) => THighOrderPredicate;\n\nexport type THighOrderPredicate = (...predicates: Array<(...args: any[]) => boolean>) => boolean;\n\n/**\n * Represents a task that will be processed by the event bus after emitting a certain `Event`.\n * Contains the ID of this task, as well as Promise for next events to be processed.\n * Returning null as a result of handler makes it synchronous.\n *\n * @template EventType - The type of the automata event.\n * @template EventMetaType - The type of the metadata associated with each event.\n */\nexport type TEventBusTask<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> = TAutomataEventMetaType<EventType, EventMetaType> & {\n\ttask_id: string;\n\tresult: Promise<TAutomataEventStack<EventType, EventMetaType>> | null;\n};\n\n/**\n * Handler function for the event bus that transforms emitted events to event bus tasks.\n * Contains the ID of this task, as well as Promise for next events to be processed.\n * Returning null as a result of handler makes it synchronous.\n *\n * @template EventType - The type of the automata event.\n * @template EventMetaType - The type of the metadata associated with each event.\n * @param event - The event metadata.\n * @returns The event bus task.\n */\nexport type TEventBusHandler<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> = (event: TAutomataEventMetaType<EventType, EventMetaType>) => TEventBusTask<EventType, EventMetaType>;\n\n/**\n * Represents a function that can be used in the automata.\n */\nexport type TAutomataFunction = ((...args: any) => any) | null;\n\nexport type TCycleIteratorInfo = {\n\tcurrentCycle: number;\n\ttotalCycles: number;\n\tcurrentEpoch: number;\n};\n\nexport type TDataSourceConstructorOpts<T> = {\n\tid?: string;\n\tafterInit?: (\n\t\tid: string,\n\t\tpublishMethod?: (data: T) => any,\n\t\tresetMethod?: () => T[]\n\t) => void;\n};\n\nexport type TDataDestinationResolver<\n\tDataPacketType,\n\tResolveResultType,\n\tObjectType,\n> = (data: DataPacketType, self?: ObjectType) => Promise<ResolveResultType>;\n\nexport type TDataDestinationConstructorOpts<DataPacketType, ResolveResultType, ObjectType> = {\n\tid?: string;\n\tresolver?: TDataDestinationResolver<DataPacketType, ResolveResultType, ObjectType> | null;\n\tafterInit?: (\n\t\tid?: string,\n\t\tsetResolver?: (resolver: TDataDestinationResolver<DataPacketType, ResolveResultType, ObjectType>) => any\n\t) => void;\n};\n\nexport type TDataDestinationOutput<DataPacketType, ResolveResultType, ErrorType> =\n\t{\n\t\tdata: DataPacketType;\n\t\tresult: ResolveResultType | null;\n\t\terror?: ErrorType;\n\t};\n\nexport const WILDCARD_EVENT = Symbol('wildcard_event');\n\nexport type TDataBoundSelector<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends Record<EventType, any>,\n\tDataPacketType,\n\tDataModel,\n> = (event: TAutomataEventMetaType<EventType, EventMetaType>, model?: DataModel) => DataPacketType | null;\nexport type TDataBoundEventDictionary<\n\tEventType extends TAutomataBaseEventType,\n\tEventMetaType extends Record<EventType, any>,\n\tDataPacketType,\n\tDataModel,\n> = {\n\t[T in EventType]?: Array<TDataBoundSelector<T, EventMetaType, DataPacketType, DataModel>>\n} & {\n\t[WILDCARD_EVENT]?: Array<TDataBoundSelector<EventType, EventMetaType, DataPacketType, DataModel>>;\n};\n\nexport interface IEventSource<\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> {\n\tid: string;\n\t/**\n\t * Starts the source. Use the provided publish callback to push ready-to-dispatch events into the EventBus.\n\t */\n\tstart: (publish: (event: TAutomataEventMetaType<EventType, EventMetaType>) => void) => void;\n\t/**\n\t * Stops the source and releases its resources.\n\t */\n\tstop: () => void;\n\t/**\n\t * (Optional) A set of event types that this source may publish.\n\t */\n\tgetObservedEvents?: () => EventType[];\n}\n\nexport interface IEventDestination<\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n> {\n\tid: string;\n\t/**\n\t * Binds the destination to the event bus. Must return an unsubscribe function.\n\t * Inside, subscribe to the required events via bus.subscribe(...).\n\t */\n\tbind: (bus: IAutomataEventBus<EventType, EventMetaType>) => TSubscriptionCancelFunction;\n}\n","import { AbstractBaseClass } from './mixins/BaseClass';\nimport ExtendedEventContainer from './mixins/ExtendedEventContainer';\nimport { TAbstractConstructor, TAutomataBaseEventType, TAutomataEventMetaType, TDataBoundEventDictionary, TDataBoundSelector, TDataDestinationConstructorOpts, TDataDestinationOutput, TDataDestinationResolver, WILDCARD_EVENT } from './types';\nimport { IAgnosticDataDestination, IDataDestination } from './types/interfaces';\n\nexport abstract class AbstractAgnosticDataDestination<\n\tDataPacketType,\n\tResolveResultType,\n\tErrorType = Error,\n> extends AbstractBaseClass implements IAgnosticDataDestination<\n\tDataPacketType,\n\tResolveResultType,\n\tErrorType\n> {\n\t#_dataPacketQueue: Array<TDataDestinationOutput<DataPacketType, ResolveResultType, ErrorType>> = [];\n\t#_requestQueue: Array<DataPacketType> = [];\n\t#active = false;\n\t#currentCycle = 0;\n\t#totalCycles = 0;\n\t#epoch = 0;\n\t#id: string;\n\t_resolver: null | TDataDestinationResolver<DataPacketType, ResolveResultType, IAgnosticDataDestination<\n\t\tDataPacketType,\n\t\tResolveResultType,\n\t\tErrorType\n\t>> = null;\n\n\tpublic get currentCycle(): number {\n\t\treturn this.#currentCycle;\n\t}\n\n\tpublic get totalCycles(): number {\n\t\treturn this.#totalCycles;\n\t}\n\n\tpublic get currentEpoch(): number {\n\t\treturn this.#epoch;\n\t}\n\n\tpublic get id(): string {\n\t\treturn this.#id;\n\t}\n\n\t/**\n\t * Constructs an instance of `AbstractAgnosticDataDestination`.\n\t *\n\t * @param opts - The options for the data destination.\n\t * @param opts.id - A unique identifier for the data destination. Generated if not provided.\n\t * @param opts.resolver - An optional function to resolve data packets.\n\t * @param opts.afterInit - An optional callback invoked after initialization.\n\t * @throws {TypeError} Throws if the ID is invalid.\n\t * @throws {TypeError} Throws if the resolver is not a function.\n\t */\n\n\tpublic constructor(opts: TDataDestinationConstructorOpts<\n\t\tDataPacketType,\n\t\tResolveResultType,\n\t\tIAgnosticDataDestination<\n\t\t\tDataPacketType,\n\t\t\tResolveResultType,\n\t\t\tErrorType\n\t\t>\n\t>) {\n\t\tsuper();\n\t\tif (!this._isValidId(opts?.id))\n\t\t\tthrow new TypeError('Invalid ID');\n\t\tif (opts?.resolver && typeof opts.resolver != 'function') {\n\t\t\tthrow new TypeError(`Invalid resolver function for ID #${opts.id}`);\n\t\t}\n\t\tif (opts.resolver)\n\t\t\tthis._resolver = opts.resolver;\n\t\tthis.#id = opts.id ?? this.correlationId;\n\t\tif (typeof opts?.afterInit === 'function') {\n\t\t\topts.afterInit(this.#id, (resolver: typeof opts.resolver) => {\n\t\t\t\tif (typeof resolver !== 'function') {\n\t\t\t\t\tthrow new TypeError(`Invalid resolver function for Destination #${this.#id}`);\n\t\t\t\t}\n\t\t\t\tthis._resolver = resolver;\n\t\t\t\treturn this;\n\t\t\t});\n\t\t}\n\t}\n\n\t_addDataPacket(dataPacket: DataPacketType) {\n\t\tif (!this._resolver)\n\t\t\treturn Promise.resolve(null);\n\t\tthis.#_requestQueue.push(dataPacket);\n\t\tif (!this.#active)\n\t\t\treturn Promise.resolve(null);\n\t\treturn this._sendDataPacket();\n\t}\n\n\t_sendDataPacket(): Promise<null | ResolveResultType> {\n\t\tif (!this._resolver || !this.#_requestQueue.length)\n\t\t\treturn Promise.resolve(null);\n\t\tconst dataPacket = this.#_requestQueue.shift()!;\n\t\treturn this._resolver(dataPacket, this)\n\t\t\t.then(\n\t\t\t\t(result) => {\n\t\t\t\t\tthis.#_dataPacketQueue.push({ data: dataPacket, result });\n\t\t\t\t\treturn result;\n\t\t\t\t},\n\t\t\t)\n\t\t\t.catch(\n\t\t\t\t(error) => {\n\t\t\t\t\tthis.#_dataPacketQueue.push({ data: dataPacket, result: null, error });\n\t\t\t\t\treturn null;\n\t\t\t\t},\n\t\t\t)\n\t\t\t.finally(() => {\n\t\t\t\tthis.#currentCycle++;\n\t\t\t\tthis.#totalCycles++;\n\t\t\t});\n\t}\n\n\t_isValidId(id: any): id is string {\n\t\treturn typeof id === 'string' && id?.length > 0;\n\t}\n\n\t/**\n\t * Consumes the next request in the queue when the current cycle completes\n\t * @returns This destination instance\n\t */\n\tasync _consumeNextRequest() {\n\t\tif (this.#_requestQueue.length && this.isActive()) {\n\t\t\tawait this._sendDataPacket();\n\t\t\tthis._consumeNextRequest();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Start/resume data processing\n\t * @returns This destination instance\n\t */\n\tpublic start(): this {\n\t\tthis.#active = true;\n\t\tthis.#currentCycle = 0;\n\t\tthis.#epoch++;\n\t\tthis._consumeNextRequest();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Stop/pause data processing\n\t * @returns This destination instance\n\t */\n\tpublic stop(): this {\n\t\tthis.#active = false;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Check if data processing is active\n\t * @returns True if actively processing data\n\t */\n\tpublic isActive(): boolean {\n\t\treturn this.#active;\n\t}\n\n\tpublic send(data: DataPacketType): Promise<null | ResolveResultType> {\n\t\tif (!this._resolver)\n\t\t\tthrow new EvalError(`Resolver not set for Destination #${this.#id}`);\n\t\treturn this._addDataPacket(data);\n\t}\n\n\tpublic *requestEmitter() {\n\t\twhile (true) {\n\t\t\tif (this.#_dataPacketQueue.length) {\n\t\t\t\tconst c = this.#_dataPacketQueue.shift();\n\t\t\t\tyield (c === undefined) ? null : c;\n\t\t\t} else {\n\t\t\t\tyield null;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class NamedDataDestination<\n\tDataPacketType,\n\tResolveResultType,\n> extends AbstractAgnosticDataDestination<\n\t\tDataPacketType,\n\t\tResolveResultType\n\t> {\n\toverride _addDataPacket(dataPacket: DataPacketType): Promise<null | ResolveResultType> {\n\t\treturn super._addDataPacket(Object.assign({}, dataPacket, { id: this.id }));\n\t}\n}\n\nexport function createDataDestinationAdapter<\n\tEventType extends TAutomataBaseEventType = TAutomataBaseEventType,\n\tEventMetaType extends { [K in EventType]: any } = Record<EventType, any>,\n\tDataModel extends object | null = object | null,\n\tDataPacketType extends Record<string, any> = Record<string, any>,\n\tResolveResultType = any,\n\tErrorType = Error,\n>() {\n\treturn <BaseType extends TAbstractConstructor<\n\t\tAbstractAgnosticDataDestination<DataPacketType, ResolveResultType, ErrorType>\n\t> = TAbstractConstructor<\n\t\tAbstractAgnosticDataDestination<DataPacketType, ResolveResultType, ErrorType>\n\t>>(Base: BaseType) =>\n\t\tclass AbstractAutomataDataDestination extends ExtendedEventContainer<\n\t\t\tEventType,\n\t\t\tEventMetaType\n\t\t>()(Base) implements IDataDestination<\n\t\t\tEventType,\n\t\t\tEventMetaType,\n\t\t\tDataModel,\n\t\t\tDataPacketType,\n\t\t\tResolveResultType,\n\t\t\tErrorType\n\t\t> {\n\t\t\t#eventTriggers: TDataBoundEventDictionary<EventType, EventMetaType, DataPacketType, DataModel> = {};\n\n\t\t\tgetBoundEvents() {\n\t\t\t\tconst keys = Object\n\t\t\t\t\t.keys(this.#eventTriggers)\n\t\t\t\t\t.map(t => Number.parseInt(t)) as unknown as Array<null | EventType>;\n\t\t\t\tif (this.#eventTriggers[WILDCARD_EVENT]?.length)\n\t\t\t\t\tkeys.push(null);\n\t\t\t\treturn keys;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Creates a trigger by associating a set of events with a selector function.\n\t\t\t * The selector function is called when the specified events occur, and it\n\t\t\t * determines the data packet that should be sent for those events.\n\t\t\t *\n\t\t\t * @param events - An array of event types that should trigger the selector.\n\t\t\t *                 If null, the selector applies to all events.\n\t\t\t * @param selector - A function that selects a data packet based on the event\n\t\t\t *                   metadata and optional model. Must be a pure function.\n\t\t\t *\n\t\t\t * @returns The current instance, allowing for method chaining.\n\t\t\t *\n\t\t\t * @throws {TypeError} Throws if the selector is not a function.\n\t\t\t * @throws {TypeError} Throws if events is not an array or null.\n\t\t\t * @throws {TypeError} Throws if any event name is invalid.\n\t\t\t */\n\n\t\t\tcreateTrigger(\n\t\t\t\tevents: EventType[] | null,\n\t\t\t\tselector: TDataBoundSelector<EventType, EventMetaType, DataPacketType, DataModel>,\n\t\t\t): this {\n\t\t\t\tif (typeof selector !== 'function')\n\t\t\t\t\tthrow new TypeError(`Invalid selector function provided in trigger for Data Destination #${this.id}`);\n\n\t\t\t\tif (events && !Array.isArray(events))\n\t\t\t\t\tthrow new TypeError(`Invalid event types provided in trigger for Data Destination #${this.id}`);\n\n\t\t\t\tif (events) {\n\t\t\t\t\tfor (const eventName of events) {\n\t\t\t\t\t\tif (!this.validateEvent(eventName))\n\t\t\t\t\t\t\tthrow new TypeError(`Invalid event name in createTrigger ofData Destination #${this.id}`);\n\n\t\t\t\t\t\tthis.#eventTriggers = Object.assign({}, this.#eventTriggers, {\n\t\t\t\t\t\t\t[eventName]: [selector].concat(this.#eventTriggers[eventName] || []),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthis.#eventTriggers[WILDCARD_EVENT] = [selector].concat(this.#eventTriggers[WILDCARD_EVENT] || []);\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tremoveTrigger(\n\t\t\t\tevents: EventType[] | null,\n\t\t\t\tselector?: TDataBoundSelector<EventType, EventMetaType, DataPacketType, DataModel>,\n\t\t\t): this {\n\t\t\t\tif (events && !Array.isArray(events))\n\t\t\t\t\tthrow new TypeError(`Invalid event types provided in trigger for Data Destination #${this.id}`);\n\t\t\t\tif (events) {\n\t\t\t\t\tfor (const eventName of events) {\n\t\t\t\t\t\tif (!this.validateEvent(eventName))\n\t\t\t\t\t\t\tthrow new TypeError(`Invalid event name in removeTrigger of Data Destination #${this.id}`);\n\t\t\t\t\t\tif (!this.#eventTriggers[eventName])\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tif (!selector) {\n\t\t\t\t\t\t\tdelete this.#eventTriggers[eventName];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst triggers = this.#eventTriggers[eventName].filter(t => t !== selector);\n\t\t\t\t\t\t\tthis.#eventTriggers = Object.assign({}, this.#eventTriggers, { [eventName]: triggers });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tdelete this.#eventTriggers[WILDCARD_EVENT];\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tgetTriggers() {\n\t\t\t\treturn this.#eventTriggers;\n\t\t\t}\n\n\t\t\tupdate(event: TAutomataEventMetaType<EventType, EventMetaType>, model?: DataModel) {\n\t\t\t\tif (!this.validateEventMeta(event))\n\t\t\t\t\tthrow new TypeError(`Invalid event passed to Data Destination #${this.id}`);\n\n\t\t\t\tconst selectors = (this.#eventTriggers[WILDCARD_EVENT] || [])\n\t\t\t\t\t.concat(this.#eventTriggers[event.event] || []);\n\n\t\t\t\tconst packets: DataPacketType[] = [];\n\t\t\t\tif (!selectors?.length || !this.isActive())\n\t\t\t\t\treturn null;\n\n\t\t\t\tfor (const selector of selectors) {\n\t\t\t\t\tconst packet = selector(event, model);\n\t\t\t\t\tif (packet) {\n\t\t\t\t\t\tthis.send(packet);\n\t\t\t\t\t\tpackets.push(packet);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\treturn packets;\n\t\t\t}\n\t\t};\n}\n\nexport class BasicDataDestination extends createDataDestinationAdapter<\n\tTAutomataBaseEventType,\n\tRecord<TAutomataBaseEventType, any>,\nobject,\nRecord<string, any>\n>()(NamedDataDestination<Record<string, any>, any>) { }\nexport default BasicDataDestination;\n","import { uniqId } from '@yantrix/utils';\nimport { AbstractBaseClass } from './mixins/BaseClass.js';\nimport DictionaryContainer from './mixins/DictionaryContainer.js';\nimport ExtendedStateContainer from './mixins/ExtendedStateContainer.js';\nimport { TStateKeysCollection, TStateLookupParams, TStateValuesCollection } from './types/dictionaries.js';\nimport {\n\tTAbstractConstructor,\n\tTAutomataBaseStateType,\n\tTAutomataStateContext,\n\tTContextTransformer,\n} from './types/index.js';\nimport { IStateDictionary } from './types/interfaces.js';\n\n// type TTransformerDictionaryItem<\n// \tStateType extends TAutomataBaseStateType = TAutomataBaseStateType,\n// \tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n// > = {\n// \tstate: StateType;\n// \ttransformer: TContextTransformer<StateType, ContextType>;\n// };\n\nexport function createStateDictionary<\n\tStateType extends TAutomataBaseStateType = TAutomataBaseStateType,\n\tContextType extends { [K in StateType]: any } = Record<StateType, any>,\n>() {\n\treturn <BaseType extends TAbstractConstructor = TAbstractConstructor>(Base: BaseType) =>\n\t\tclass AbstractStateDictionary extends DictionaryContainer<StateType>()(\n\t\t\tExtendedStateContainer<StateType, ContextType>()(Base),\n\t\t) {\n\t\t\t#transformers: {\n\t\t\t\t[K in StateType]?: Record<\n\t\t\t\t\tstring,\n\t\t\t\t\t{\n\t\t\t\t\t\tnamespace?: string;\n\t\t\t\t\t\ttransformer: TContextTransformer<K, ContextType>;\n\t\t\t\t\t}\n\t\t\t\t>;\n\t\t\t} = {};\n\n\t\t\t#transformersIndex: Record<string, StateType> = {};\n\n\t\t\tgetStateKeys({\n\t\t\t\tstates = [],\n\t\t\t\tnamespace = undefined,\n\t\t\t}: TStateValuesCollection<StateType>): Array<string | null> {\n\t\t\t\treturn (states ?? []).map((state) => {\n\t\t\t\t\tif (!this.validateState(state))\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tconst data = this._getValueData(state);\n\t\t\t\t\tif (!data)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tif (namespace !== null && namespace !== data.namespace)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\treturn data.key;\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tclearStates(namespace?: string): this {\n\t\t\t\treturn this._clearItems(namespace);\n\t\t\t}\n\n\t\t\tremoveStates(\n\t\t\t\t{ namespace, states = [], keys = [] }: TStateLookupParams<StateType>,\n\t\t\t\tremoveContextTransformers?: boolean,\n\t\t\t): this {\n\t\t\t\tconst statesToDelete = [\n\t\t\t\t\t...states.filter(this.validateState),\n\t\t\t\t\t...keys.flatMap(k => (k ? [this._findItem(k, namespace)] : [])),\n\t\t\t\t].filter(v => v != null);\n\n\t\t\t\tconst stateKeys = statesToDelete\n\t\t\t\t\t.map(State => this._getValueData(State))\n\t\t\t\t\t.filter(data => !!data && (namespace == null || namespace === data?.namespace));\n\n\t\t\t\tfor (const stateKey of stateKeys) {\n\t\t\t\t\tif (stateKey)\n\t\t\t\t\t\tthis._deleteItemKey(stateKey.key);\n\t\t\t\t}\n\n\t\t\t\tif (removeContextTransformers) {\n\t\t\t\t\tstatesToDelete\n\t\t\t\t\t\t.flatMap(State => Object.keys(this.#transformers[State] ?? {}))\n\t\t\t\t\t\t.forEach(id => this.removeContextTransformerById(id));\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tgetStateValues({\n\t\t\t\tnamespace = undefined,\n\t\t\t\tkeys = [],\n\t\t\t}: TStateKeysCollection<StateType>): Array<StateType | null> {\n\t\t\t\treturn (keys ?? []).map(k => this._findItem(k, namespace));\n\t\t\t}\n\n\t\t\taddStates({ namespace = undefined, keys }: TStateKeysCollection<StateType>): StateType[] {\n\t\t\t\treturn (keys || []).map(k => this._addItemKey(k, namespace));\n\t\t\t}\n\n\t\t\taddContextTransformer<T extends StateType>(\n\t\t\t\tstate: T,\n\t\t\t\ttransformer: TContextTransformer<T, ContextType>,\n\t\t\t\tnamespace?: string,\n\t\t\t): string {\n\t\t\t\tconst id = this.#getTransformerKey(state, namespace);\n\t\t\t\tif (Object.values(this.#transformers[state] ?? {}).map(t => t.transformer).includes(transformer)) {\n\t\t\t\t\tthrow new EvalError('Context transformer already was added to State Dictionary');\n\t\t\t\t}\n\t\t\t\tthis.#transformersIndex[id] = state;\n\n\t\t\t\tthis.#transformers[state] = Object.assign(this.#transformers[state] ?? {}, {\n\t\t\t\t\t[id]: { namespace, transformer },\n\t\t\t\t});\n\t\t\t\treturn id;\n\t\t\t}\n\n\t\t\tremoveContextTransformerById(id: string): this {\n\t\t\t\tif (this.#transformersIndex[id]) {\n\t\t\t\t\tconst state = this.#transformersIndex[id];\n\t\t\t\t\tif (state && this.#transformers?.[state]?.[id]) {\n\t\t\t\t\t\tthis.#transformers[state] = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.#transformers[state] ?? {}).filter(([key]) => key !== id),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tdelete this.#transformersIndex[id];\n\t\t\t\t}\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tremoveContextTransformer<T extends StateType>(\n\t\t\t\tstate: T,\n\t\t\t\ttransformer: TContextTransformer<T, ContextType>,\n\t\t\t\tnamespace?: string,\n\t\t\t): this {\n\t\t\t\tObject.keys(this.#transformers[state] ?? {}).find((id) => {\n\t\t\t\t\tconst item = this.#transformers[state]?.[id];\n\t\t\t\t\tif (!item)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tif (item.transformer === transformer && (item?.namespace || null) === (namespace || null))\n\t\t\t\t\t\tthis.removeContextTransformerById(id);\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\t\t\t\treturn this;\n\t\t\t}\n\n\t\t\tgetContextTransformers(namespace?: string): Record<\n\t\t\t\tstring,\n\t\t\t\tRecord<string, TContextTransformer<StateType, ContextType>>\n\t\t\t> {\n\t\t\t\treturn Object.keys(this.#transformers).reduce(\n\t\t\t\t\t(obj, state) => ({\n\t\t\t\t\t\t...obj,\n\t\t\t\t\t\t[state]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.#transformers[state as unknown as StateType] ?? {}).filter(\n\t\t\t\t\t\t\t\t([, value]) => (value.namespace || null) === (namespace || null),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\t\t{},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\trunContextTransformers<T extends StateType>(\n\t\t\t\tid: string,\n\t\t\t\tcontext: TAutomataStateContext<T, ContextType>,\n\t\t\t): TAutomataStateContext<StateType, ContextType> {\n\t\t\t\tconst stateType = this.#transformersIndex[id];\n\t\t\t\tif (stateType !== context?.state)\n\t\t\t\t\treturn context;\n\t\t\t\tconst transformers = this.#transformers[stateType]?.[id]?.transformer;\n\t\t\t\tif (!transformers)\n\t\t\t\t\treturn context;\n\t\t\t\treturn transformers(context);\n\t\t\t}\n\n\t\t\t#getTransformerKey(state: StateType, namespace?: string): string {\n\t\t\t\treturn this._getItemKey(`${state}/${uniqId()}`, namespace);\n\t\t\t}\n\t\t};\n}\n\n/**\n * Basic state dictionary class that's used in Yantrix automatas.\n */\nexport class BasicStateDictionary\n\textends createStateDictionary<TAutomataBaseStateType, Record<TAutomataBaseStateType, any>>()(AbstractBaseClass)\n\timplements IStateDictionary<TAutomataBaseStateType, Record<TAutomataBaseStateType, any>> {\n\tconstructor() {\n\t\tsuper();\n\t}\n}\n\nexport default BasicStateDictionary;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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C,KAAK,GAAG,OAAO;AAAA,YACf,OAAO,QAAQ,KAAK,cAAc,KAA6B,KAAK,CAAC,CAAC,EAAE;AAAA,cACvE,CAAC,CAAC,EAAE,KAAK,OAAO,MAAM,aAAa,WAAW,aAAa;AAAA,YAC5D;AAAA,UACD;AAAA,QACD;AAAA,QACA,CAAC;AAAA,MACF;AAAA,IACD;AAAA,IAEA,uBACC,IACA,SACgD;AAChD,YAAM,YAAY,KAAK,mBAAmB,EAAE;AAC5C,UAAI,cAAc,SAAS;AAC1B,eAAO;AACR,YAAM,eAAe,KAAK,cAAc,SAAS,IAAI,EAAE,GAAG;AAC1D,UAAI,CAAC;AACJ,eAAO;AACR,aAAO,aAAa,OAAO;AAAA,IAC5B;AAAA,IAEA,mBAAmB,OAAkB,WAA4B;AAChE,aAAO,KAAK,YAAY,GAAG,KAAK,QAAI,sBAAO,CAAC,IAAI,SAAS;AAAA,IAC1D;AAAA,EACD;AACF;AA7JgB;AAkKT,IAAM,uBAAN,cACE,sBAAmF,EAAE,iBAAiB,EACrB;AAAA,EAzL1F,OAyL0F;AAAA;AAAA;AAAA,EACzF,cAAc;AACb,UAAM;AAAA,EACP;AACD;","names":["v","import_utils","import_utils","import_utils","import_utils","import_utils","import_utils","opts","import_utils"]}