{"version":3,"file":"machine.cjs","names":["_unknown","#decomposed","#eventsMap","#actorsMap","#typingsByKey","extract","byKey","commonT","keysOf","#config","#flat","flatMap","#initialConfig","initialConfig","#getInitialKeys","#elements","#actions","#predicates","#delays","#actors","#initialKeys","merge","#isValue","#isNotValue","#isDefined","#isNotDefined","#voidAction","#sendTo","_any","expandFnMap","fn","reduceFnMap","assignByKey","#cloneStateExtended","getByKey","#timeAction","#addActions","#addPredicates","#addDelays","#addChildren","#addEmitters","#pContext","#context","#renew","valueToNodeConfig","nodeToValue","isValue","isNotValue","isDefinedS","isNotDefinedS","toArray","isAtomic","isCompound","partialCall"],"sources":["../../src/machine/machine.ts"],"sourcesContent":["import _any from '#bemedev/features/common/castings/any';\nimport commonT from '#bemedev/features/common/typings';\nimport extract from '#bemedev/features/common/typings/extract';\nimport byKey from '#bemedev/features/objects/typings/byKey';\nimport keysOf from '#bemedev/features/objects/typings/keysOf';\nimport type {\n  AllowedNames,\n  NOmit,\n  NotUndefined,\n  PrimitiveObject,\n} from '#bemedev/globals/types';\nimport { DEFAULT_DELIMITER } from '#constants';\nimport { type EventsMap, type ToEvents } from '#events';\nimport {\n  isDefinedS,\n  isNotDefinedS,\n  isNotValue,\n  isValue,\n  type DefinedValue,\n} from '#guards';\nimport type {\n  State,\n  StateExtended,\n  StateP,\n  StatePextended,\n} from '#states';\nimport {\n  flatMap,\n  initialConfig,\n  isAtomic,\n  isCompound,\n  nodeToValue,\n  valueToNodeConfig,\n  type FlatMapN,\n  type NodeConfig,\n  type StateValue,\n} from '#states';\nimport { merge, reduceFnMap } from '#utils';\nimport toArray from '#bemedev/features/arrays/castings/toArray';\nimport { partialCall } from '#bemedev/features/functions/functions/partialCall';\nimport { decompose, getByKey, type Decompose } from '@bemedev/decompose';\n\nimport type { Action } from '#actions';\nimport type { DelayFunction } from '#delays';\nimport { EventsR, ActorsConfigMap, ToEventObject } from '#events';\n\nimport { _unknown } from '#bemedev/globals/utils/_unknown';\nimport type { PredicateS } from '#guards';\nimport cloneDeep from 'clone-deep';\nimport { withTimeout } from '@bemedev/better-promise';\nimport { assignByKey, expandFnMap } from './functions';\nimport type {\n  AddOptions_F,\n  AddOptionsParam_F,\n  AnyMachine,\n  Elements,\n  GetIO_F,\n  ScheduledData,\n  SendAction_F,\n  TimeAction_F,\n  VoidAction_F,\n} from './machine.types';\nimport type {\n  Config,\n  ConfigDef,\n  ExtractTagsFromConfig,\n  GetActorKeysFromConfig,\n  GetActorKeysFromConfig2,\n  GetEventsFromConfig,\n  MachineOptions,\n  NoExtraKeysConfig,\n  NoExtraKeysConfigDef,\n  TransformConfigDef,\n} from './types';\n\n/**\n * A class representing a state machine.\n * It provides methods to manage states, actions, predicates, delays, promises, and machines.\n *\n * @template : {@linkcode Config} [C] - The configuration type of the machine.\n * @template Pc : The private context type of the machine.\n * @template : {@linkcode PrimitiveObject} [Pc] - The context type of the machine.\n * @template : {@linkcode GetEventsFromConfig}<{@linkcode C}> [E] - The events map type derived from the configuration.\n * @template : {@linkcode PromiseeMap} [P] - The promisees map type derived from the configuration.\n * @template : {@linkcode SimpleMachineOptions2} [Mo] - The options type for the machine, which includes actions, predicates, delays, promises, and machines. Defaults to {@linkcode MachineOptions}<[{@linkcode C} , {@linkcode E} , {@linkcode A} , {@linkcode Pc} , {@linkcode Tc} ]>.\n *\n * @implements {@linkcode AnyMachine}<{@linkcode E} , {@linkcode A} , {@linkcode Pc} , {@linkcode Tc} >\n */\n\nclass Machine<\n  const C extends Config = Config,\n  const Pc = any,\n  const Tc extends PrimitiveObject = PrimitiveObject,\n  E extends GetEventsFromConfig<C> = GetEventsFromConfig<C>,\n  A extends ActorsConfigMap = GetActorKeysFromConfig<C>,\n  Ta extends ExtractTagsFromConfig<C> = ExtractTagsFromConfig<C>,\n  Eo extends ToEventObject<ToEvents<E, A>> = ToEventObject<ToEvents<E, A>>,\n  Mo extends MachineOptions<C, E, A, Pc, Tc, Ta, Eo> = MachineOptions<\n    C,\n    E,\n    A,\n    Pc,\n    Tc,\n    Ta,\n    Eo\n  >,\n> implements AnyMachine<E, A, Pc, Tc> {\n  /**\n   * The configuration of the machine for this {@linkcode Machine}.\n   *\n   * @see {@linkcode Config}\n   * @see {@linkcode C}\n   */\n  #config: C;\n\n  get __config() {\n    return _unknown<C>();\n  }\n\n  /**\n   * The flat map of the configuration for this {@linkcode Machine}.\n   *\n   * @see {@linkcode FlatMapN}\n   * @see {@linkcode Config}\n   * @see {@linkcode C}\n   */\n  #flat: FlatMapN<C, true>;\n\n  #decomposed: any;\n\n  get decomposed() {\n    return this.#decomposed as Decompose<\n      C,\n      { sep: '.'; start: false; object: 'both' }\n    >;\n  }\n\n  /**\n   * The map of events for this {@linkcode Machine}.\n   *\n   * @see {@linkcode EventsMap}\n   * @see {@linkcode E}\n   */\n  #eventsMap!: E;\n\n  /**\n   * The map of promisees for this {@linkcode Machine}.\n   *\n   * @see {@linkcode PromiseeMap}\n   * @see {@linkcode A}\n   */\n  #actorsMap!: A;\n\n  /**\n   * Public accessor for the events map for this {@linkcode Machine}.\n   *\n   * @see {@linkcode EventsMap}\n   * @see {@linkcode E}   */\n  get eventsMap() {\n    return this.#eventsMap;\n  }\n\n  /**\n   * Public accessor for the promisees map for this {@linkcode Machine}.\n   *\n   * @see {@linkcode PromiseeMap}\n   * @see {@linkcode A}\n   */\n  get actorsMap() {\n    return this.#actorsMap;\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the events map for this {@linkcode Machine} as a type.\n   *\n   * @see {@linkcode ToEvents}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __events() {\n    return _unknown<EventsR<E>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the events map for this {@linkcode Machine} as a type.\n   *\n   * @see {@linkcode ToEvents}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __eventsO() {\n    return _unknown<Eo>();\n  }\n\n  /**\n   * @deprecated\n   * This property provides the action function for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode E}\n   * @see {@linkcode PromiseeMap}\n   * @see {@linkcode A}\n   * @see {@linkcode Pc}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode Tc}\n   */\n  get __actionFn() {\n    return _unknown<Action<Eo, Pc, Tc, Ta>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides any action key for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __actionKey() {\n    return this.#typingsByKey('actions');\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the action parameters of action function for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode E}\n   * @see {@linkcode Pc}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode Tc}\n   */\n  get __actionParams() {\n    return _unknown<{ pContext: Pc; context: Tc; map: E }>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the state extended for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode StateExtended}\n   * @see {@linkcode ToEvents}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode ActorsConfigMap}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __stateExtended() {\n    return _unknown<StateExtended<Eo, Pc, Tc, Ta>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the state for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode State}\n   * @see {@linkcode ToEventsR2}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode ActorsConfigMap}\n   * @see {@linkcode E}\n   * @see {@linkcode A}   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __state() {\n    return _unknown<State<Eo, Tc, Ta>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the decomposed state for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode State}\n   * @see {@linkcode Decompose}\n   * @see {@linkcode Eo}\n   * @see {@linkcode Tc}\n   * @see {@linkcode Ta}\n   */\n  get __decomposedState() {\n    return _unknown<\n      Decompose<\n        State<Eo, Tc, Ta>,\n        { sep: '.'; start: false; object: 'both' }\n      >\n    >();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the state payload for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode StateP}\n   * @see {@linkcode ToEventsR2}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode ActorsConfigMap}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __stateP() {\n    return _unknown<StateP<Eo, Tc, Ta>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the extended state payload for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode StatePextended}\n   * @see {@linkcode ToEventsR2}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode ActorsConfigMap}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __statePextended() {\n    return _unknown<StatePextended<Eo, Pc, Tc, Ta>>();\n  }\n\n  #typingsByKey = <\n    K extends AllowedNames<AnyMachine<E, A, Pc, Tc>, object | undefined>,\n  >(\n    key: K,\n  ) => {\n    const _this = commonT.dynamic(this);\n    const out1 = byKey(_this, key);\n    const out2 = extract(out1, {} as object);\n    const out3 = keysOf.union(out2);\n\n    return out3;\n  };\n\n  /**\n   * @deprecated\n   *\n   * This property provides any guard key for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __guardKey() {\n    return this.#typingsByKey('predicates');\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the predicate function for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode PredicateS}\n   * @see {@linkcode ActorsConfigMap}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __predicate() {\n    return _unknown<PredicateS<Eo, Pc, Tc, Ta>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides any delay key for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __delayKey() {\n    return this.#typingsByKey('delays');\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides the delay function for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode DelayFunction}\n   * @see {@linkcode ActorsConfigMap}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode E}\n   * @see {@linkcode A}\n   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __delay() {\n    return _unknown<DelayFunction<Eo, Pc, Tc, Ta>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides any {@linkcode DefinedValue} for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   *\n   * @see {@linkcode DefinedValue}\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode Pc}\n   * @see {@linkcode Tc}\n   */\n  get __definedValue() {\n    return _unknown<DefinedValue<Pc, Tc>>();\n  }\n\n  /**\n   * @deprecated\n   *\n   * This property provides any child key for this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __childKey() {\n    return this.#typingsByKey('children');\n  }\n\n  /**\n   * @deprecated\n   *\n   * Return this {@linkcode Machine} as a type.\n   *\n   * @remarks Used for typing purposes only.\n   */\n  get __machine() {\n    return _unknown<this>();\n  }\n\n  get __tag() {\n    return _unknown<Ta>();\n  }\n  // #endregion\n\n  // #region private\n  #actions?: Mo['actions'];\n\n  #predicates?: Mo['predicates'];\n\n  #delays?: Mo['delays'];\n\n  #actors?: Mo['actors'];\n\n  /**\n   * Context for this {@linkcode Machine}.\n   *\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode Tc}\n   */\n  #context!: Tc;\n\n  /**\n   * Private context for this {@linkcode Machine}.\n   *\n   * @see {@linkcode Pc}\n   */\n  #pContext!: Pc;\n\n  #initialKeys: string[] = [];\n\n  /**\n   * The initial node config of this {@linkcode Machine}.\n   */\n  #initialConfig: NodeConfig;\n  // #endregion\n\n  /**\n   * Creates an instance of Machine.\n   *\n   * @param config : of type {@linkcode Config} [C] - The configuration for the machine.\n   *\n   * @remarks\n   * This constructor initializes the machine with the provided configuration.\n   * It flattens the configuration and prepares it for further operations ({@linkcode flat}).\n   */\n  constructor(config: C) {\n    this.#config = config;\n    this.#decomposed = decompose(config, {\n      start: false,\n      object: 'both',\n    });\n    this.#flat = flatMap(this.#config, true);\n    this.#initialConfig = initialConfig(this.#config);\n    this.#getInitialKeys();\n    this.longRuns = this.#config.__longRuns === true;\n  }\n\n  readonly longRuns: boolean;\n\n  /**\n   * The accessor configuration of the machine for this {@linkcode Machine}.\n   *\n   * @see {@linkcode Config}\n   * @see {@linkcode C}\n   */\n  get config() {\n    return this.#config;\n  }\n\n  /**\n   * The public accessor of the flat map of the configuration for this {@linkcode Machine}.\n   *\n   * @see {@linkcode FlatMapN}\n   * @see {@linkcode Config}\n   * @see {@linkcode C}\n   */\n  get flat() {\n    return this.#flat;\n  }\n\n  /**\n   * The accessor of context for this {@linkcode Machine}.\n   *\n   * @see {@linkcode PrimitiveObject}\n   * @see {@linkcode Tc}\n   */\n  get context() {\n    const out = this.#elements.context;\n    return out;\n  }\n\n  /**\n   * The accessor of private context for this {@linkcode Machine}.\n   *\n   * @see {@linkcode Pc}\n   */\n  get pContext() {\n    const out = this.#elements.pContext;\n    return out;\n  }\n\n  get actions() {\n    return this.#actions;\n  }\n\n  get predicates() {\n    return this.#predicates;\n  }\n\n  get delays() {\n    return this.#delays;\n  }\n\n  get children() {\n    return this.#actors?.children;\n  }\n\n  get emitters() {\n    return this.#actors?.emitters;\n  }\n\n  // #region Providers\n\n  #getInitialKeys = () => {\n    const entries = Object.entries(this.#flat);\n    entries.forEach(([key, { initial }]) => {\n      const check1 = initial !== undefined;\n      if (check1) {\n        const toPush = `${key}${DEFAULT_DELIMITER}${initial}`;\n        this.#initialKeys.push(toPush);\n      }\n    });\n  };\n\n  isInitial = (target: string) => {\n    return this.#initialKeys.includes(target);\n  };\n\n  retrieveParentFromInitial = (target: string): NodeConfig => {\n    const check1 = this.isInitial(target);\n    const flat: any = this.#flat;\n    if (check1) {\n      const parent = target.substring(\n        0,\n        target.lastIndexOf(DEFAULT_DELIMITER),\n      );\n      const check2 = this.isInitial(parent);\n\n      if (check2) return this.retrieveParentFromInitial.bind(this)(parent);\n      return flat[parent];\n    }\n    return flat[target];\n  };\n\n  #addActions = (actions?: Mo['actions']) =>\n    (this.#actions = merge(this.#actions, actions));\n\n  #addPredicates = (predicates?: Mo['predicates']) =>\n    (this.#predicates = merge(this.#predicates, predicates));\n\n  #addDelays = (delays?: Mo['delays']) =>\n    (this.#delays = merge(this.#delays, delays));\n\n  #addChildren = (children?: NotUndefined<Mo['actors']>['children']) =>\n    (this.#actors = merge(this.#actors, { children }));\n\n  #addEmitters = (emitters?: NotUndefined<Mo['actors']>['emitters']) =>\n    (this.#actors = merge(this.#actors, { emitters }));\n\n  /**\n   * Create options for the machine.\n   *\n   * @param option a function that provides options for the machine.\n   * Options can include actions, predicates, delays, promises, and child machines.\n   *\n   * Remark: Used for typings, when you're outside the Machine class.\n   */\n  createOptions: AddOptions_F<Eo, Pc, Tc, Ta, Mo> = helper => {\n    const isValue = this.#isValue;\n    const isNotValue = this.#isNotValue;\n    const isDefined = this.#isDefined;\n    const isNotDefined = this.#isNotDefined;\n    const voidAction = this.#voidAction;\n    const sendTo = this.#sendTo;\n\n    const _legacy = Object.freeze({\n      actions: cloneDeep(this.#actions),\n      predicates: cloneDeep(this.#predicates),\n      delays: cloneDeep(this.#delays),\n      actors: cloneDeep(this.#actors),\n    }) as any;\n\n    const out = helper(\n      {\n        isValue,\n        isNotValue,\n        isDefined,\n        isNotDefined,\n\n        assign: (key, fn, options?) => {\n          if (!options) {\n            return _any(expandFnMap)(\n              this.#eventsMap,\n              this.#actorsMap,\n              _any(key),\n              fn,\n            );\n          }\n\n          const { error: errorFn, max } = options;\n          const _fn = reduceFnMap(\n            this.#eventsMap,\n            this.#actorsMap,\n            fn as any,\n          );\n\n          return async ({ pContext, context, event, ...rest }) => {\n            const all = cloneDeep({ pContext, context });\n\n            const execute = async () => {\n              const rawResult = await _fn({\n                pContext,\n                context,\n                event,\n                ...rest,\n              });\n              return assignByKey(all, _any(key), rawResult);\n            };\n\n            try {\n              if (max !== undefined) {\n                const tp = withTimeout(\n                  execute,\n                  `assign-${String(key)}`,\n                  max,\n                );\n                return await tp();\n              }\n              return await execute();\n            } catch (e: any) {\n              const rawResult = errorFn({\n                context,\n                pContext,\n                payload: e,\n                ...rest,\n              });\n\n              return assignByKey(all, _any(key), rawResult);\n            }\n          };\n        },\n\n        batch: (...fns) => {\n          return async ({ context, pContext, ...rest }) => {\n            const state = this.#cloneStateExtended({\n              context,\n              pContext,\n              ...rest,\n            });\n\n            let out: any;\n            for (const fn of fns.filter(f => !!f)) {\n              if (!out) out = await fn(state);\n              else out = await fn({ ...out, ...rest });\n            }\n            return out;\n          };\n        },\n\n        filter: (key, fn) => {\n          return ({ context, pContext }) => {\n            const currentValue = getByKey.low({ context, pContext }, key);\n\n            const predicate = fn as any;\n\n            let filteredValue: any;\n\n            if (Array.isArray(currentValue)) {\n              // Filter array elements\n              filteredValue = currentValue.filter(predicate);\n            } else if (\n              currentValue !== null &&\n              typeof currentValue === 'object'\n            ) {\n              // Filter object properties\n              filteredValue = Object.entries(currentValue).reduce(\n                (acc, [objKey, value]) => {\n                  const check = predicate(value, currentValue);\n                  if (check) acc[objKey] = value;\n                  return acc;\n                },\n                {} as any,\n              );\n            }\n\n            return assignByKey({ context, pContext }, key, filteredValue);\n          };\n        },\n\n        erase: key => {\n          return ({ context, pContext }) => {\n            const state = cloneDeep({\n              context,\n              pContext,\n            });\n            return assignByKey(state, key, undefined);\n          };\n        },\n\n        voidAction,\n        sendTo,\n\n        debounce: (fn, { id, ms = 100 }) => {\n          return async ({ context, pContext, ...rest }) => {\n            const state = this.#cloneStateExtended({\n              context,\n              pContext,\n              ...rest,\n            });\n            const data = await fn(state);\n\n            const scheduled: ScheduledData<Pc, Tc> = { data, ms, id };\n\n            return _any({\n              context,\n              pContext,\n              scheduled,\n            });\n          };\n        },\n\n        resend: resend => {\n          return ({ context, pContext }) => {\n            return _any({\n              context,\n              pContext,\n              resend,\n            });\n          };\n        },\n\n        forceSend: forceSend => {\n          return ({ context, pContext }) => {\n            return _any({\n              context,\n              pContext,\n              forceSend,\n            });\n          };\n        },\n\n        pauseActivity: this.#timeAction('pauseActivity'),\n        resumeActivity: this.#timeAction('resumeActivity'),\n        stopActivity: this.#timeAction('stopActivity'),\n        pauseTimer: this.#timeAction('pauseTimer'),\n        resumeTimer: this.#timeAction('resumeTimer'),\n        stopTimer: this.#timeAction('stopTimer'),\n      },\n      { _legacy },\n    );\n\n    return out;\n  };\n\n  /**\n   * Provides options for the machine.\n   *\n   * @param option a function that provides options for the machine.\n   * Options can include actions, predicates, delays, promises, and child machines.\n   */\n  addOptions: AddOptions_F<Eo, Pc, Tc, Ta, Mo> = helper => {\n    const out = this.createOptions(helper as any);\n\n    this.#addActions(out?.actions);\n    this.#addPredicates(out?.predicates);\n    this.#addDelays(out?.delays);\n    this.#addChildren(out?.actors?.children);\n    this.#addEmitters(out?.actors?.emitters);\n\n    return out as any;\n  };\n\n  /**\n   * Provides options for the machine.\n   *\n   * @param helper a function that provides options for the machine.\n   * Options can include actions, predicates, delays, promises, and child machines.\n   * @returns a new instance of the machine with the provided options applied.\n   */\n  provideOptions = <T extends Mo>(\n    helper: AddOptionsParam_F<Eo, Pc, Tc, Ta, T>,\n  ) => {\n    const out = this.renew;\n    out.addOptions(helper);\n\n    return out;\n  };\n  // #endregion\n\n  /**\n   * Get all meaningful elements of the machine.\n   *\n   * @see {@linkcode Elements}\n   *\n   * @see type inferences :\n   *\n   * @see {@linkcode Config} , {@linkcode C} , {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc} , {@linkcode SimpleMachineOptions2} , {@linkcode MachineOptions} , {@linkcode Mo}\n   */\n  get #elements(): Elements<C, E, A, Pc, Tc, Mo> {\n    const config = structuredClone(this.#config);\n    const pContext = cloneDeep(this.#pContext);\n    const context = structuredClone(this.#context);\n    const actions = cloneDeep(this.#actions);\n    const predicates = cloneDeep(this.#predicates);\n    const delays = cloneDeep(this.#delays);\n    const actorsMap = cloneDeep(this.#actorsMap);\n    const events = cloneDeep(this.#eventsMap);\n    const actors = cloneDeep(this.#actors);\n\n    return {\n      config,\n      pContext,\n      context,\n      actions,\n      predicates,\n      delays,\n      actors,\n      events,\n      actorsMap,\n    };\n  }\n\n  /**\n   * Provides elements of the machine.\n   * @param key the key of the element to provide.\n   * @param value the value of the element to provide.\n   * If not provided, the current elements will be returned.\n   * @returns the elements of the machine with the provided key and value.\n   *\n   * @see {@linkcode Elements}\n   *\n   * @see type inferences :\n   *\n   *  {@linkcode Config} , {@linkcode C} , {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc} , {@linkcode SimpleMachineOptions2} , {@linkcode MachineOptions} , {@linkcode Mo}\n   */\n\n  /**\n   * Renews the machine with the provided key and value.\n   * @param key the key of the element to provide.\n   * @param value the value of the element to provide.\n   * If not provided, the current elements will be returned.\n   * @returns a new instance of this {@linkcode Machine} with the provided key and value.\n   *\n   * @see {@linkcode Elements}\n   *\n   * @see type inferences :\n   *\n   *  {@linkcode Config} , {@linkcode C} , {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode types} , {@linkcode Tc} , {@linkcode SimpleMachineOptions2} , {@linkcode MachineOptions} , {@linkcode Mo}\n   */\n  #renew = (): this => {\n    const {\n      config,\n      pContext,\n      context,\n      predicates,\n      actions,\n      delays,\n\n      events,\n      actors,\n      actorsMap,\n    } = this.#elements;\n\n    const out = new Machine<C, Pc, Tc, E, A, Ta, Eo, Mo>(config);\n\n    out.#pContext = pContext;\n    out.#context = context;\n    out.#eventsMap = events;\n    out.#actorsMap = actorsMap;\n\n    out.#addPredicates(predicates);\n    out.#addActions(actions);\n    out.#addDelays(delays);\n    out.#addChildren(actors?.children);\n    out.#addEmitters(actors?.emitters);\n\n    return out as any;\n  };\n\n  /**\n   * Returns a new instance from this {@linkcode Machine} with all its {@linkcode Elements}.\n   */\n  get renew() {\n    const out = this.#renew();\n\n    return out;\n  }\n\n  addPrivateContext = (pContext: Pc) => {\n    this.#pContext = pContext;\n  };\n\n  addContext = (context: Tc) => {\n    this.#context = context;\n  };\n\n  /**\n   * @deprecated\n   * @remarks used internally\n   */\n  _provideEvents = <T extends EventsMap>(map: T) => {\n    const { pContext, config, context, actorsMap } = this.#elements;\n\n    const out = new Machine<C, Pc, Tc, T, A>(config);\n\n    out.#pContext = pContext;\n    out.#context = context;\n    out.#eventsMap = map;\n    out.#actorsMap = actorsMap;\n\n    return out;\n  };\n\n  /**\n   * @deprecated\n   * @remarks used internally\n   */\n  _provideActors = <T extends ActorsConfigMap>(map: T) => {\n    const { pContext, config, context, events } = this.#elements;\n\n    const out = new Machine<C, Pc, Tc, E, T>(config);\n\n    out.#pContext = pContext;\n    out.#context = context;\n    out.#eventsMap = events;\n    out.#actorsMap = map;\n\n    return out;\n  };\n\n  /**\n   * Converts a {@linkcode StateValue} to a {@linkcode NodeConfigWithInitials} with the {@linkcode NodeConfigWithInitials} postConfig of this {@linkcode Machine}.\n   *\n   * @param from the {@linkcode StateValue} to convert.\n   * @returns the converted {@linkcode NodeConfigWithInitials}.\n   *\n   * @see {@linkcode valueToNodeConfig}\n   */\n  valueToConfig = (from: StateValue) => {\n    return valueToNodeConfig(this.#config, from);\n  };\n\n  /**\n   * The accessor of the initial node config of this {@linkcode Machine}.\n   */\n  get initialConfig() {\n    return this.#initialConfig;\n  }\n\n  /**\n   * The accessor of the initial {@linkcode StateValue} of this {@linkcode Machine}.\n   *\n   * @see {@linkcode nodeToValue}\n   */\n  get initialValue() {\n    return nodeToValue(this.#initialConfig as any);\n  }\n\n  /**\n   * Alias of {@linkcode valueToConfig} method.\n   */\n  toNode = this.valueToConfig;\n\n  get options() {\n    const predicates = this.#predicates;\n    const actions = this.#actions;\n    const delays = this.#delays;\n    const actors = this.#actors;\n\n    const out = _unknown<Mo>({\n      predicates,\n      actions,\n      delays,\n\n      actors,\n    });\n\n    return out;\n  }\n\n  // #region Options helper functions\n\n  /**\n   * Function helper to check if a value matches the provided values\n   *\n   * @see type inferences :\n   *\n   * {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc}\n   *\n   * @see {@linkcode isValue}\n   */\n  get #isValue() {\n    return isValue<Eo, Pc, Tc, Ta>;\n  }\n\n  /**\n   * Function helper to check if a value is not one of the provided values.\n   *\n   * @see type inferences :\n   *\n   *  {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc}\n   *\n   * @see {@linkcode isNotValue}\n   */\n  get #isNotValue() {\n    return isNotValue<Eo, Pc, Tc, Ta>;\n  }\n\n  /**\n   * Function helper to check if a value is defined\n   *\n   * @see type inferences :\n   *\n   * {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc}\n   *\n   * @see {@linkcode isDefinedS}\n   */\n  get #isDefined() {\n    return isDefinedS<Eo, Pc, Tc, Ta>;\n  }\n\n  /**\n   * Function helper to check if a value is undefined or null\n   * @see type inferences :\n   *\n   * {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc}\n   *\n   * @see {@linkcode isDefinedS}\n   */\n  get #isNotDefined() {\n    return isNotDefinedS<Eo, Pc, Tc, Ta>;\n  }\n\n  /**\n   * Function helper to send an event to a child service.\n   *\n   * @param _ an optional parameter of type {@linkcode AnyMachine} [{@linkcode T}] to specify the machine context. Only used for type inference.\n   *\n   * @see type inferences :\n   *\n   * {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc}\n   *\n   * @see {@linkcode reduceFnMap}\n   */\n  #sendTo: SendAction_F<Eo, Pc, Tc, Ta> = <T extends AnyMachine>(\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    _?: T,\n  ) => {\n    return (fn, options?) => {\n      if (!options) {\n        const fn2 = reduceFnMap(this.eventsMap, this.#actorsMap, fn);\n        return ({ context, pContext, ...rest }) => {\n          const state = this.#cloneStateExtended({\n            context,\n            pContext,\n            ...rest,\n          });\n          const { event, to } = fn2(state) as any;\n\n          const sentEvent = { to, event };\n\n          return _any({ context, pContext, sentEvent });\n        };\n      }\n\n      const { error: errorFn, max } = options;\n\n      return async ({ context, pContext, event, ...rest }) => {\n        const out = _any({ context, pContext });\n        const state = this.#cloneStateExtended({\n          context,\n          pContext,\n          event,\n          ...rest,\n        });\n\n        const execute = async () => {\n          const fn2 = reduceFnMap(this.eventsMap, this.#actorsMap, fn);\n          const { event, to } = (await fn2(state)) as any;\n          const sentEvent = { to, event };\n          return _any({ ...out, sentEvent });\n        };\n\n        try {\n          if (max !== undefined) {\n            const tp = withTimeout(execute, 'sendTo', max);\n            return await tp();\n          }\n          return await execute();\n        } catch (e: any) {\n          errorFn({\n            context,\n            pContext,\n            payload: e,\n            ...rest,\n          });\n\n          return out;\n        }\n      };\n    };\n  };\n\n  /**\n   * Function helper to perform a void action.\n   *\n   * @param fn the action function to perform.\n   *\n   * @see type inferences :\n   *\n   * {@linkcode GetEventsFromConfig} , {@linkcode E} , {@linkcode PromiseeMap} , {@linkcode GetPromiseesSrcFromConfig} , {@linkcode A} , {@linkcode Pc} , {@linkcode PrimitiveObject} , {@linkcode Tc}\n   *\n   * @see {@linkcode VoidAction_F}\n   */\n  #voidAction: VoidAction_F<Eo, Pc, Tc, Ta> = (fn, options?) => {\n    if (!options) {\n      return ({ context, pContext, ...rest }) => {\n        const _fn = reduceFnMap(this.#eventsMap, this.#actorsMap, fn);\n        const state = this.#cloneStateExtended({\n          context,\n          pContext,\n          ...rest,\n        });\n        _fn(state);\n\n        return _any({ context, pContext });\n      };\n    }\n\n    const { error: errorFn, max } = options;\n\n    return async ({ context, pContext, event, ...rest }) => {\n      const out = _any({ context, pContext });\n      const state = this.#cloneStateExtended({\n        context,\n        pContext,\n        event,\n        ...rest,\n      });\n\n      const execute = async () => {\n        const _fn = reduceFnMap(this.#eventsMap, this.#actorsMap, fn);\n        await _fn(state);\n        return out;\n      };\n\n      try {\n        if (max !== undefined) {\n          const tp = withTimeout(execute, 'voidAction', max);\n          return await tp();\n        }\n        return await execute();\n      } catch (e: any) {\n        errorFn({\n          context,\n          pContext,\n          payload: e,\n          ...rest,\n        });\n\n        return out;\n      }\n    };\n  };\n\n  #timeAction = (name: string): TimeAction_F<Eo, Pc, Tc, Ta> => {\n    return id =>\n      ({ context, pContext }) => {\n        return _any({ context, pContext, [name]: id });\n      };\n  };\n\n  #cloneStateExtended = (state: StateExtended<Eo, Pc, Tc, Ta>) => {\n    return structuredClone(state);\n  };\n}\n\n/**\n * Helper to retrieve entry or exit actions from a node.\n *\n * @see {@linkcode GetIO_F}\n * @see {@linkcode toArray.typed}\n * @see {@linkcode isAtomic}\n * @see {@linkcode isCompound}\n */\nconst getIO: GetIO_F = (key, node) => {\n  if (!node) return [];\n  const out = toArray.typed(node?.[key]);\n\n  if (isAtomic(node)) return out;\n  const states = node.states;\n\n  if (isCompound(node)) {\n    const initial = states[node.initial];\n\n    out.push(...getIO(key, initial));\n  }\n\n  return out;\n};\n\n/**\n * Retrieves all entry actions from a node.\n */\nexport const getEntries = partialCall.paramArray(getIO, 'entry');\n\n/**\n * Retrieves all exit actions from a node.\n */\nexport const getExits = partialCall.paramArray(getIO, 'exit');\n\nexport type { Machine };\n\nexport type CreateMachine_F = <\n  const C2 extends NoExtraKeysConfigDef<ConfigDef> =\n    NoExtraKeysConfigDef<ConfigDef>,\n  const C extends Config & TransformConfigDef<C2> = Config &\n    TransformConfigDef<C2>,\n  Tc extends PrimitiveObject = PrimitiveObject,\n  EventM extends GetEventsFromConfig<C> = GetEventsFromConfig<C>,\n  A0 extends GetActorKeysFromConfig2<C> = GetActorKeysFromConfig2<C>,\n  A extends NOmit<A0, 'pContext'> = NOmit<A0, 'pContext'>,\n  Pc extends A0['pContext'] = A0['pContext'],\n>(\n  config: NoExtraKeysConfig<C & { __tsSchema?: NoExtraKeysConfigDef<C2> }>,\n  types: { pContext: Pc; context: Tc; eventsMap: EventM; actorsMap: A },\n) => Machine<\n  C,\n  // No need to be instanciated, they will be instanciated inside\n  Pc,\n  Tc,\n  EventM,\n  A\n>;\n\n/**\n * Creates a new instance of {@linkcode Machine} with the provided configuration and\n *\n * @param config The configuration for the machine.\n * @param types An object containing the types for the machine:\n * - `pContext`: The private context type.\n * - `context`: The context type.\n * - `eventsMap`: The events map type derived from the configuration.\n * - `promiseesMap`: The promisees map type derived from the configuration.\n *\n * @param initials The initials {@linkcode StateValue} for all compound node configs for the {@linkcode Machine}, derived from the configuration.\n * @returns A new instance of {@linkcode Machine} with the provided configuration and\n *\n * @see {@linkcode CreateMachine_F}\n */\nexport const createMachine: CreateMachine_F = (\n  config,\n  { eventsMap, actorsMap },\n) => {\n  const out = new Machine(config as Config)\n    ._provideEvents(eventsMap)\n    ._provideActors(actorsMap);\n\n  return out as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,IAAM,UAAN,MAAM,QAiBgC;;;;;;;CAOpC;CAEA,IAAI,WAAW;AACb,SAAOA,4CAAAA,UAAa;;;;;;;;;CAUtB;CAEA;CAEA,IAAI,aAAa;AACf,SAAO,MAAA;;;;;;;;CAYT;;;;;;;CAQA;;;;;;CAOA,IAAI,YAAY;AACd,SAAO,MAAA;;;;;;;;CAST,IAAI,YAAY;AACd,SAAO,MAAA;;;;;;;;;;;;;CAcT,IAAI,WAAW;AACb,SAAOA,4CAAAA,UAAsB;;;;;;;;;;;;;CAc/B,IAAI,YAAY;AACd,SAAOA,4CAAAA,UAAc;;;;;;;;;;;;;;;CAgBvB,IAAI,aAAa;AACf,SAAOA,4CAAAA,UAAkC;;;;;;;;;CAU3C,IAAI,cAAc;AAChB,SAAO,MAAA,aAAmB,UAAU;;;;;;;;;;;;;;CAetC,IAAI,iBAAiB;AACnB,SAAOA,4CAAAA,UAAiD;;;;;;;;;;;;;;;;;;CAmB1D,IAAI,kBAAkB;AACpB,SAAOA,4CAAAA,UAAyC;;;;;;;;;;;;;;;;;CAkBlD,IAAI,UAAU;AACZ,SAAOA,4CAAAA,UAA6B;;;;;;;;;;;;;;;CAgBtC,IAAI,oBAAoB;AACtB,SAAOA,4CAAAA,UAKJ;;;;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