import { type ActionConfig } from '../actions/index.js'; import { type ActorsConfigMap, type EventArg, type EventArgT, type ToEventObject, type ToEvents } from '../events/index.js'; import { type GuardConfig } from '../guards/index.js'; import { type Config, type ConfigFrom, type ContextFrom, type EventsMapFrom, type GetEventsFromConfig, type PrivateContextFrom } from '../machine/index.js'; import { Node, type NodeConfig, type State, type StateValue } from '../states/index.js'; import { type Interval2 } from '@bemedev/interval2'; import type { _Send_F, AddSubscriber_F, AnyInterpreter, CollectedService, CreateInterval2_F, Interpreter_F, Mode, PerformTransitions_F, Selector_F, WorkingStatus } from './interpreter.types'; import type { PrimitiveObject } from '../libs/bemedev/globals/types'; import { type EmitterFunction2 } from '../emitters/index.js'; import type { Machine } from '../machine/machine.js'; import type { ActorsMapFrom, AnyMachine, ChildFunction2, ExtractTagsFromConfig, GetActorKeysFromConfig } from '../machine/index.js'; /** * The `Interpreter` class is responsible for interpreting and managing the state of a machine. * It provides methods to start, stop, pause, and resume the machine, as well as to send events * and subscribe to state changes. * * @template : type {@linkcode Config} [C] - The configuration type of the machine. * @template : [Pc] - The private context type, which can be any type. * @template : type {@linkcode types} [Tc] - The context type. * @template : type {@linkcode EventsMap} [E] - The events map type, which maps event names to their * @template : type {@linkcode PromiseeMap} [P] - The promisees map type, which maps promise names to their * @template Mo : type {@linkcode SimpleMachineOptions2} - The machine options type, which includes various configurations for the machine. Default to {@linkcode MachineOptions}. * * @implements : {@linkcode AnyInterpreter} * * @remarks * The `Interpreter` class is a core component of the state machine implementation, * allowing for the execution of state transitions, handling of events, and management of the machine's lifecycle. * It supports various modes of operation, including strict and normal modes, * and provides mechanisms for error and warning handling. * * It also allows for the execution of actions, predicates, and delays, * * as well as the management of child interpreters and scheduled tasks. * * @see {@linkcode GetEventsFromConfig} for extracting events from the machine configuration. */ export declare class Interpreter = GetEventsFromConfig, A extends ActorsConfigMap = GetActorKeysFromConfig, Ta extends ExtractTagsFromConfig = ExtractTagsFromConfig, Eo extends ToEventObject> = ToEventObject>> implements AnyInterpreter { #private; /** * Public getter of the service subscribers of this {@linkcode Interpreter} service. */ get children(): CollectedService[]; /** * Returns a service subscriber of this {@linkcode Interpreter} service with a specific id. * @param id - The id of the service subscriber to get. * @return The service subscriber {@linkcode AnyInterpreter} of this {@linkcode Interpreter} service with the specified id, or undefined if not found. * * @see {@linkcode children} for all children. */ getChildAt: (id: string) => CollectedService | undefined; /** * Allias of {@linkcode getChildAt} function. */ at: (id: string) => CollectedService | undefined; /** * The id of the current {@linkcode Interpreter} service. * Used for child machines identification. */ id?: string; from?: string; /** * The accessor of {@linkcode Mode} of this {@linkcode Interpreter} service */ get mode(): Mode; /** * @deprecated * * Used for typings only * The accessor of current {@linkcode ToEvents} of this {@linkcode Interpreter} service * * @remarks Usually for typings */ get event(): Eo; /** * The accessor of the map of events from the inner {@linkcode Machine}. */ get eventsMap(): E; get tags(): Ta[] | undefined; /** * Where everything is initialized * @param machine, the {@linkcode Machine} to interpret. * @param mode, the {@linkcode Mode} of the interpreter, default is 'strict'. * @param exact, whether to use exact intervals or not, default is false. */ constructor(machine: AnyMachine, mode?: Mode, exact?: boolean); /** * Checks if the current {@linkcode Mode} mode is 'strict'. */ get isStrict(): boolean; /** * Checks if the current {@linkcode Mode} mode is 'normal'. */ get isNormal(): boolean; /** * Performs computations, after transitioning to the next target, to update the current {@linkcode NodeConfigWithInitials} config state of this {@linkcode Interpreter} service */ protected _performConfig: () => void; protected _iterate: () => number; /** * The accessor of initial {@linkcode Node} of the inner {@linkcode Machine}. */ get initialNode(): Node; /** * The accessor of current {@linkcode Node} of this {@linkcode Interpreter} service. */ get node(): Node; /** * Set the current {@linkcode Mode} of this {@linkcode Interpreter} service to 'strict'. * In this mode, all errors are thrown and warnings are logged to the console. */ makeStrict: () => void; /** * Set the current {@linkcode Mode} of this {@linkcode Interpreter} service to 'normal'. * In this mode, errors are logged to the console, but not thrown. */ makeNormal: () => void; /** * The public accessor of initial {@linkcode WorkingStatus} status of the this {@linkcode Interpreter} service. */ get status(): WorkingStatus; /** * The public accessor of initial {@linkcode NodeConfigWithInitials} of the inner {@linkcode Machine}. */ get initialConfig(): NodeConfig; /** * The public accessor of initial {@linkcode StateValue} of the inner {@linkcode Machine}. */ get initialValue(): StateValue; /** * The public accessor of current {@linkcode NodeConfigWithInitials} config state of this {@linkcode Interpreter} service. */ get config(): NodeConfig; /** * Create a new {@linkcode Interpreter} instance with the same initial configuration as this instance. */ get renew(): Interpreter>>; /** * The public accessor of current {@linkcode StateValue}> of this {@linkcode Interpreter} service. */ get value(): StateValue; /** * The public accessor of current {@linkcode Tc} context of this {@linkcode Interpreter} service. */ get context(): Tc; /** * @deprecated * Just use for testing * @returns the current {@linkcode Pc} private context of this {@linkcode Interpreter} service. * @remarks returns nothing in prod * * @see {@linkcode context} to get the current context. */ get _pContext(): Pc | undefined; get isReady(): boolean; /** * Select a path from the current {@linkcode Tc} context of this {@linkcode Interpreter} service. * * @param path, the key to select from the current {@linkcode Tc} context of this {@linkcode Interpreter} service. * * @returns the value from the path from the current {@linkcode Tc} context of this {@linkcode Interpreter} service. * * @see {@linkcode getByKey} for retrieving values by key. */ get select(): Selector_F; /** * @deprecated * Select a path from the current {@linkcode Pc} private context of this {@linkcode Interpreter} service. * * @param path, the key to select from the current {@linkcode Pc} private context of this {@linkcode Interpreter} service. * * @returns the value from the path from the current {@linkcode Pc} private context of this {@linkcode Interpreter} service. * * @remarks returns nothing in prod * * @see {@linkcode getByKey} for retrieving values by key. */ get _pSelect(): Selector_F; /** * Start this {@linkcode Interpreter} service. */ start: () => Promise; /** * Performs all self transitions and activities of this {@linkcode Interpreter} service. * @remarks Throw if the number of self transitions exceeds {@linkcode DEFAULT_MAX_SELF_TRANSITIONS}. */ protected _next: () => Promise; protected createInterval: CreateInterval2_F; /** * Collection of all currents {@linkcode Interval2} intervals, related to current {@linkcode ActivityConfig}s of this {@linkcode Interpreter} service. */ protected _cachedIntervals: Interval2[]; protected __performTransitions: PerformTransitions_F; get longRuns(): boolean; pause: () => void; resume: () => void; stop: () => void; /** * @deprecated * Used internally */ _providePrivateContext: (pContext: Pc) => Machine, Eo, Pc, Tc, Ta>>; predicates: Partial, Eo, Pc, Tc, Ta>>; delays: Partial, Eo, Pc, Tc, Ta>>; actors: Partial, Eo, A, Pc, Tc, Ta>>; }>>; /** * @deprecated * Used internally * * Alias of {@linkcode _providePrivateContext} */ _ppC: (pContext: Pc) => Machine, Eo, Pc, Tc, Ta>>; predicates: Partial, Eo, Pc, Tc, Ta>>; delays: Partial, Eo, Pc, Tc, Ta>>; actors: Partial, Eo, A, Pc, Tc, Ta>>; }>>; /** * @deprecated * Used internally */ _provideContext: (context: Tc) => Machine, Eo, Pc, Tc, Ta>>; predicates: Partial, Eo, Pc, Tc, Ta>>; delays: Partial, Eo, Pc, Tc, Ta>>; actors: Partial, Eo, A, Pc, Tc, Ta>>; }>>; /** * Add options to the inner {@linkcode Machine} of this {@linkcode Interpreter} service. */ get addOptions(): import("../machine/index.js").AddOptions_F, Eo, Pc, Tc, Ta>>; predicates: Partial, Eo, Pc, Tc, Ta>>; delays: Partial, Eo, Pc, Tc, Ta>>; actors: Partial, Eo, A, Pc, Tc, Ta>>; }>>; /** * Provides options for the interpreter and returns a new interpreter instance. * * @param option a function that provides options for the machine. * Options can include actions, predicates, delays, promises, and child machines. * @returns a new interpreter instance with the provided options applied. */ provideOptions: (option: Parameters<(typeof this)["addOptions"]>[0]) => Interpreter>>; subscribe: AddSubscriber_F; private __subscribe; get state(): Readonly>; /** * @deprecated * Just use for testing * @remarks returns nothing in prod */ get _errorsCollector(): Set | undefined; /** * @deprecated * Just use for testing * @remarks returns nothing in prod */ get _warningsCollector(): Set | undefined; protected _addError: (...errors: string[]) => void; protected _addWarning: (...warnings: string[]) => void; protected _send: _Send_F; /** * Creates a sender function for the given event type. * @param type - the {@linkcode EventArgT} type of the event to send. * @returns a function with the payload as Parameter that sends the event with the given type and payload. * * @see {@linkcode send} for sending events directly. */ sender: >(type: T) => (...data: object extends (Extract, { type: T; }> | Extract> extends infer U extends import("../emitters/index.js").EmitterConfigMap ? U extends any ? { type: `${keyof U & string}::next`; payload: U[keyof U]["next"]; } | { type: `${keyof U & string}::error`; payload: U[keyof U]["error"]; } : never : never, { type: T; }> | Extract<{ [key in keyof Exclude & string]: import("../libs/bemedev/globals/types").Unionize[key]> extends infer U_1 ? U_1 extends any ? { type: `${key}::on::${keyof U_1 & string}`; payload: U_1[keyof U_1]; } : never : never; }[keyof Exclude & string], { type: T; }>)["payload"] ? [] : [(Extract, { type: T; }> | Extract> extends infer U extends import("../emitters/index.js").EmitterConfigMap ? U extends any ? { type: `${keyof U & string}::next`; payload: U[keyof U]["next"]; } | { type: `${keyof U & string}::error`; payload: U[keyof U]["error"]; } : never : never, { type: T; }> | Extract<{ [key in keyof Exclude & string]: import("../libs/bemedev/globals/types").Unionize[key]> extends infer U_1 ? U_1 extends any ? { type: `${key}::on::${keyof U_1 & string}`; payload: U_1[keyof U_1]; } : never : never; }[keyof Exclude & string], { type: T; }>)["payload"]]) => Promise; /** * Sends an event to the current {@linkcode Interpreter} service. * * @param _event - the {@linkcode EventArg} event to send. * * @remarks * If the event cannot be performed, it will not be sent. * If the event is sent, it will be processed and the state will be updated. */ send: (_event: EventArg) => Promise; /** * Proposes the next configuration based on the current state value and the target. * @param target - the target state to propose the next configuration. * @returns the proposed next {@linkcode NodeConfigWithInitials} based on the current state value and the target. * * @remarks * Only proposes next config, does not change the current config. * * // * // * @see {@linkcode Machine.valueToConfig} for more details. * * // */ protected proposedNextConfig: (target: string) => NodeConfig; toActionFn: (action: ActionConfig) => import("../actions/index.js").Action2 | undefined; toPredicateFn: (guard: GuardConfig) => import("../guards/index.js").PredicateS3 | undefined; toDelayFn: (delay: string) => import("../delays/index.js").DelayFunction3 | undefined; toChildFunction: (machine: string) => ChildFunction2>, Pc, Tc, Ta, { eventsMap: any; }> | undefined; toEmitterSrc: (emitter: string) => EmitterFunction2>, Pc, Tc, Ta, any> | undefined; protected interpretChild: Interpreter_F; dispose: () => void; [Symbol.dispose]: () => void; [Symbol.asyncDispose]: () => Promise; } export declare const TIME_TO_RINIT_SELF_COUNTER: number; /** * Retrieves the {@linkcode Interpreter} service from the given {@linkcode AnyMachine} machine. * * @template : type {@linkcode AnyMachine} [M] - The type of the machine from which to retrieve the interpreter. * * @see {@linkcode ConfigFrom} * @see {@linkcode PrivateContextFrom} * @see {@linkcode ContextFrom} * @see {@linkcode EventsMapFrom} * @see {@linkcode PromiseesMapFrom} * @see {@linkcode MachineOptionsFrom} */ export type InterpreterFrom = Interpreter, PrivateContextFrom, ContextFrom, EventsMapFrom, ActorsMapFrom>; /** * Creates an {@linkcode Interpreter} service from the given {@linkcode MachineConfig} machine. * * @param machine - The {@linkcode MachineConfig} machine to create the interpreter from. * @param options - The options for the interpreter, including context, private context, mode, and exact. * @returns an {@linkcode Interpreter} service. * * @see {@linkcode MachineConfig} */ export declare const interpret: Interpreter_F; //# sourceMappingURL=interpreter.d.ts.map