import type { Action2, FromActionConfig } from '../actions/index.js'; import type { Equals, Keys, NotUndefined, PrimitiveObject } from '../libs/bemedev/globals/types'; import type { DelayFunction2 } from '../delays/index.js'; import type { EmitterDef, EmitterFunction2, EmitterReturn, EmittersMap } from '../emitters/index.js'; import type { ActorsConfigMap, EventObject, EventsMap, ToEventObject, ToEvents } from '../events/index.js'; import type { PredicateS, PredicateS2 } from '../guards/index.js'; import type { ActivityConfig, BaseConfig, ExtractActionsFromActivity, ExtractDelaysFromActivity, ExtractGuardsFromActivity, ExtractTagsFromFlat, FlatMapN, NodeConfig, NodeConfigCompound, NodeConfigParallel } from '../states/index.js'; import type { ExtractActionKeysFromTransitions, ExtractChildKeysFromTransitions, ExtractDelayKeysFromTransitions, ExtractEmitterSrcKeyFromTransitions, ExtractGuardKeysFromTransitions, Transition, TransitionsConfig } from '../transitions/index.js'; import type { Recompose } from '@bemedev/decompose'; import type { Observable } from 'rxjs'; import type { Describer, FnMap, FnMapR, FnR, KeyU, RecordS, ReduceArray } from '../types/index.js'; import { Identify } from '../libs/bemedev/globals/types'; /** * Type representing the main JSON config. * * @see {@linkcode NodeConfigCompound} for compound nodes. * @see {@linkcode NodeConfigParallel} for parallel nodes. */ export type ConfigNode = NodeConfigCompound | NodeConfigParallel; /** * Type representing a describer for a child service. * * @see {@linkcode Describer} for more details. */ export type MachineConfig = Describer | string; /** * Type representing the main JSON node config of a state machine. * * @see {@linkcode ConfigNode} for more details. * @see {@linkcode MachineConfig} * @see {@linkcode SingleOrArrayL} */ export type Config = NodeConfig & { readonly strict?: boolean; readonly __longRuns?: boolean; }; export type ChildEvents = NotUndefined[K] extends infer P ? P : never; export type ChildFunction = FnMap; export type ChildFunction2 = FnR; export type ChildrenMap = RecordS>; export type ExtractTagsFromConfig = ExtractTagsFromFlat>; export type NoExtraKeysConfigDef = T & { [K in Exclude]: never; } & { states?: { [K in keyof T['states']]: T['states'][K] extends infer TK extends ConfigDef ? NoExtraKeysConfigDef : never; }; }; export type ConfigDef = { readonly targets: string; readonly initial?: string; readonly states?: RecordS; }; export type NoExtraKeysConfigNode = T & { [K in Exclude]: never; } & { states?: { [K in keyof T['states']]: T['states'][K] extends infer TK extends NodeConfig ? NoExtraKeysConfigNode : never; }; }; export type NoExtraKeysConfig = T & { [K in Exclude]: never; } & { states?: Record>; }; export type TransformConfigDef = BaseConfig & TransitionsConfig & { readonly initial?: T['initial']; readonly states?: { [Key in keyof T['states']]: T['states'][Key] extends infer TK extends ConfigDef ? TransformConfigDef : never; }; }; /** * Type representing all action keys from a flat map of nodes. * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @returns A type representing all action keys from this flat map. * * @see {@linkcode TransitionsConfig} for the structure of transitions. * @see {@linkcode ActivityConfig} for the structure of activities. * @see {@linkcode FromActionConfig} for extracting action names from action configurations. * @see {@linkcode ExtractActionKeysFromTransitions} for extracting actions from transitions. * @see {@linkcode ExtractActionsFromActivity} for extracting actions from activities. * @see {@linkcode ReduceArray} for reducing arrays to a single type. */ type _GetKeyActionsFromFlat = { [key in keyof Flat]: ExtractActionKeysFromTransitions> | ExtractActionsFromActivity> | FromActionConfig['entry']>> | FromActionConfig['exit']>> extends infer V ? unknown extends V ? never : V : never; }[keyof Flat]; /** * Type representing all guard keys from a flat map of nodes. * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @returns A type representing all guard keys from this flat map. * * @see {@linkcode TransitionsConfig} for the structure of transitions. * @see {@linkcode ActivityConfig} for the structure of activities. * @see {@linkcode ExtractGuardKeysFromTransitions} for extracting guards from transitions. * @see {@linkcode ExtractGuardsFromActivity} for extracting guards from activities. */ type _GetKeyGuardsFromFlat = { [key in keyof Flat]: ExtractGuardKeysFromTransitions> | ExtractGuardsFromActivity> extends infer V ? unknown extends V ? never : V : never; }[keyof Flat]; type _GetEmitterSrcKeyFromFlat = { [key in keyof Flat]: ExtractEmitterSrcKeyFromTransitions> extends infer V ? unknown extends V ? never : V : never; }[keyof Flat]; type _GetChildKeysFromFlat = { [key in keyof Flat]: ExtractChildKeysFromTransitions>; }[keyof Flat]; /** * Type representing all event types from a flat map of nodes. * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @returns A type representing all event types from this flat map. * */ type _GetEventKeysFromFlat = { [key in keyof Flat]: Flat[key] extends { on: infer V; } ? keyof V : never; }[keyof Flat]; /** * Type representing all delay keys from a flat map of nodes. * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @returns A type representing all delay keys from this flat map. * * @see {@linkcode TransitionsConfig} for the structure of transitions. * @see {@linkcode ActivityConfig} for the structure of activities. * @see {@linkcode ExtractDelayKeysFromTransitions} for extracting delays from transitions. * @see {@linkcode ExtractDelaysFromActivity} for extracting delays from activities. */ type _GetDelayKeysFromFlat = { [key in keyof Flat]: ExtractDelayKeysFromTransitions> | ExtractDelaysFromActivity extends infer V ? unknown extends V ? never : V : never; }[keyof Flat]; /** * Provide a record of all actions by key and {@linkcode Action} function. * * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [P] - type of the promisees map * @template Pc - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * * @see {@linkcode _GetKeyActionsFromFlat} for extracting action keys from the flat map. */ export type GetActionsFromFlat = Record<_GetKeyActionsFromFlat, Action2>; /** * Provide a record of all guards by key and {@linkcode PredicateS} function. * * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [P] - type of the promisees map * @template Pc - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * * @see {@linkcode _GetKeyGuardsFromFlat} for extracting guard keys from the flat map. */ export type GetGuardsFromFlat = Record<_GetKeyGuardsFromFlat, PredicateS>; export type GetEmitterSrcsKeyFromFlat = { [key in _GetEmitterSrcKeyFromFlat]: Observable>; }; /** * Provide a record of all delays by key and {@linkcode DelayFunction} function. * * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [A] - type of the actors config map * @template Pc - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * * @see {@linkcode _GetDelayKeysFromFlat} for extracting delay keys from the flat map. */ export type GetDelaysFromFlat = Record<_GetDelayKeysFromFlat, DelayFunction2>; /** * Provide a record of all events by key and {@linkcode PrimitiveObject} payload. * * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes * * @see {@linkcode _GetEventKeysFromFlat} for extracting event keys from the flat map. */ export type GetEventsFromFlat = Record<_GetEventKeysFromFlat, PrimitiveObject>; /** * Get all events from a machine config. * * @template : {@linkcode Config} [C] - type of the machine config * @returns A type representing all events from the machine config. * * @see {@linkcode FlatMapN} for the flat map structure. * @see {@linkcode GetEventsFromFlat} for extracting events from the flat map. * @see {@linkcode ConfigFrom} for extracting the config from the config. */ export type GetEventsFromConfig = GetEventsFromFlat>; /** * Get all events from a machine. * * @template : {@linkcode KeyU}<'config'> [T] - type of the machine * * @returns A type representing all events from the machine. * * @see {@linkcode ConfigFrom} for extracting the config from the machine. * @see {@linkcode GetEventsFromConfig} for extracting events from the machine. */ export type GetEventsFromMachine> = GetEventsFromConfig>; export type GetEmittersSrcKeyFromFlat = Record<_GetEmitterSrcKeyFromFlat, EmitterDef>; export type GetEmittersSrcFromFlat = { [key in _GetEmitterSrcKeyFromFlat]: EmitterFunction2>; }; /** * Get all emitters from a machine config. * * @template : {@linkcode Config} [C] - type of the machine config * @returns A type representing all emitters from the machine config. * * @see {@linkcode FlatMapN} for the flat map structure. * @see {@linkcode GetEmittersSrcKeyFromFlat} for extracting promises from the flat map. * @see {@linkcode FlatMapN} for extracting the config from a machine config. */ export type GetEmittersSrcFromConfig = GetEmittersSrcKeyFromFlat>; /** * Get all emitters from a machine. * * @template : {@linkcode KeyU}<'config'> [T] - type of the machine * * @returns A type representing all emitters from the machine. * * @see {@linkcode ConfigFrom} for extracting the config from the machine. * @see {@linkcode GetEmittersSrcFromConfig} for extracting promises from the machine. */ export type GetEmittersSrcFromMachine> = GetEmittersSrcFromConfig>; export type GetChildrenSrcKeysFromFlat = _GetChildKeysFromFlat> = { [key in G['src']]: Record['on'], any>; }; export type GetChildrenSrcKeysFromFlat2 = _GetChildKeysFromFlat> = { [key in G['src']]: Extract extends infer E extends G ? { on: Record; context: keyof E['contexts']; parentPcontext: E['contexts'][keyof E['contexts']]; } : never; }; export type GetChildrenSrcFromFlat = _GetChildKeysFromFlat> = { [key in G['src']]: ChildFunction2; context: Recomposer['contexts']>; }>; }; /** * Get all child machines from a machine config. * * @template : {@linkcode Config} [C] - type of the machine config * @returns A type representing all child machines from the machine config. * * @see {@linkcode FlatMapN} for the flat map structure. * @see {@linkcode GetChildrenSrcKeysFromFlat} for extracting promises from the flat map. * @see {@linkcode FlatMapN} for extracting the config from a machine config. */ export type GetChildrenSrcFromConfig = GetChildrenSrcKeysFromFlat>; /** * Get all child machines from a machine. * * @template : {@linkcode KeyU}<'config'> [T] - type of the machine * * @returns A type representing all child machines from the machine. * * @see {@linkcode ConfigFrom} for extracting the config from the machine. * @see {@linkcode GetChildrenSrcFromConfig} for extracting child machines from the machine. */ export type GetChildrenSrcFromMachine> = GetChildrenSrcFromConfig>; export type GetActorsFromFlat = { children: Partial>; emitters: Partial>; }; export type GetActorsFromConfig = GetActorsFromFlat, E, A, Pc, Tc, T>; export type GetActorsFromMachine, E extends EventObject = EventObject, A extends ActorsConfigMap = ActorsConfigMap, Pc = any, Tc extends PrimitiveObject = PrimitiveObject, T extends string = string> = GetActorsFromConfig, E, A, Pc, Tc, T>; export type GetActorsSrcKeysFromFlat = { children: GetChildrenSrcKeysFromFlat; emitters: GetEmittersSrcKeyFromFlat; }; export type Recomposer

= Equals extends true ? any : Equals extends true ? any : Recompose, unknown>>; export type GetActorsSrcKeysFromFlat2 = _GetChildKeysFromFlat> = { children: { [key in G['src']]: Record['on'], any>; }; emitters: GetEmittersSrcKeyFromFlat; pContext: Recomposer; }; export type GetActorKeysFromConfig = GetActorsSrcKeysFromFlat>; export type GetActorKeysFromConfig2 = GetActorsSrcKeysFromFlat2>; export type GetActorKeysFromMachine> = GetActorKeysFromConfig>; export type ChildConfigDef = EventsMap; export type ChildConfigMap = RecordS; export type Child = { src: ChildFunction2; description?: string; id: string; on: Identify>>[]; contexts: string[]; }; /** * Not used in the codebase, but provided for completeness. */ export type FnMapFrom, R = any, Ex extends string = never> = FnMapR, ContextFrom, Extract, R, Ex>; /** * The big one ! * * Type representing the options for a machine configuration. * * @template : {@linkcode Config} [C] - type of the machine config * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [A] - type of the actors config map * @template Pc - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * @template : {@linkcode FlatMapN} [Flat] - type of the flat map of nodes inside {@linkcode C} * * @returns A type representing the options for the machine configuration. * All options can be : * * `initials` - a record of initial states. * * `actions` - a partial record of actions, where keys are action names and values are action functions. * * `predicates` - a partial record of predicates, where keys are predicate names and values are predicate functions. * * `promises` - a partial record of promises, where keys are promise names and values are promise functions. * * `delays` - a partial record of delays, where keys are delay names and values are delay functions. * * `machines` - a partial record of child services, where keys are machine names and values are child services. * * @see {@linkcode GetInititalsFromFlat} for extracting initials from the flat map. * @see {@linkcode GetActionsFromFlat} for extracting actions from the flat map. * @see {@linkcode GetGuardsFromFlat} for extracting guards from the flat map. * @see {@linkcode GetPromiseSrcsFromFlat} for extracting promise sources from the flat map. * @see {@linkcode GetDelaysFromFlat} for extracting delays from the flat map. * @see {@linkcode GetMachinesFromConfig} for extracting child services from the machine config * @see {@linkcode Partial} - intern type to make all properties optional. */ export type MachineOptions> = ToEventObject>, Flat extends FlatMapN = FlatMapN> = Partial<{ actions: Partial>; predicates: Partial>; delays: Partial>; actors: Partial>; }>; /** * Getting the options from a machine. * * @template : {@linkcode KeyU}<'options'> [T] - type of the machine options * * @see {@linkcode SimpleMachineOptions2} for the structure of the machine options. */ export type MachineOptionsFrom> = Extract; /** * Alias of {@linkcode MachineOptionsFrom}. */ export type MoF> = MachineOptionsFrom; /** * Getting config from a machine. * * @template : {@linkcode KeyU}<'config'> [T] - type of the machine pre-config * * @see {@linkcode Config} for the structure of the machine config. */ export type ConfigFrom> = Extract; /** * Getting private context from a machine. * * @template : {@linkcode KeyU}<'pContext'> [T] - type of the machine events map */ export type PrivateContextFrom> = T['pContext']; /** * Getting context from a machine. * * @template : {@linkcode KeyU}<'context'> [T] - type of the machine context * * @see {@linkcode PrimitiveObject} for the structure of the context. */ export type ContextFrom> = Extract; /** * Getting events map from a machine. * * @template : {@linkcode KeyU}<'eventsMap'> [T] - type of the machine events map * * @see {@linkcode EventsMap} for the structure of the events map. */ export type EventsMapFrom> = Extract; /** * Getting state from a machine. * * @template : {@linkcode KeyU}<'__state'> [T] - type of the machine state * * @see {@linkcode StateFrom} for extracting the state from the machine. */ export type StateFrom> = T['__state']; export type DecomposedStateFrom> = T['__decomposedState']; /** * Getting extended state from a machine. * * @template : {@linkcode KeyU}<'__stateExtended'> [T] - type of the machine extended state * * @see {@linkcode StateExtendedFrom} for extracting the extended state from the machine. */ export type StateExtendedFrom> = T['__stateExtended']; /** * Getting stateP from a machine. * @template : {@linkcode KeyU}<'__stateP'> [T] - type of the machine stateP * @see {@linkcode StatePFrom} for extracting the stateP from the machine. */ export type StatePFrom> = T['__stateP']; /** * Getting statePextended from a machine. * * @template : {@linkcode KeyU}<'__statePextended'> [T] - type of the machine statePextended * * @see {@linkcode StatePextendedFrom} for extracting the statePextended from the machine. */ export type StatePextendedFrom> = T['__statePextended']; /** * Getting promisees map from a machine. * * @template : {@linkcode KeyU}<'promiseesMap'> [T] - type of the machine promisees map * * @see {@linkcode ActorsConfigMap} for the structure of the promisees map. */ export type ActorsMapFrom> = Extract; /** * Getting all events from a machine. * * @template : {@linkcode KeyU}<'__events'> [T] - type of the machine events * */ export type EventsFrom> = T['__events']; /** * Get all actions map from a machine. * * @template : {@linkcode KeyU}<'actions'> [T] - type of the machine actions * * @see {@linkcode ActionsMapFrom} for extracting actions from the machine. * @see {@linkcode NotUndefined} * @see {@linkcode ActionFnFrom} for extracting action functions from the machine. * @see {@linkcode ActionParamsFrom} for extracting action parameters from the machine. * @see {@linkcode ActionKeysFrom} for extracting action keys from the machine. */ export type ActionsMapFrom> = NotUndefined; export type AddOptionsFrom> = NotUndefined; /** * Get the action function from a machine. * * @template : {@linkcode KeyU}<'__actionFn'> [T] - type of the machine action function * * @see {@linkcode NotUndefined} for ensuring the action function is not undefined. */ export type ActionFnFrom> = NotUndefined; /** * Get the action function parameters from a machine. * * @template : {@linkcode KeyU}<'__actionParams'> [T] - type of the machine action parameters * * @see {@linkcode NotUndefined} for ensuring the action parameters are not undefined. */ export type ActionParamsFrom> = NotUndefined; /** * Get the action keys from a machine. * * @template : {@linkcode KeyU}<'actions'> [T] - type of the machine actions * * @see {@linkcode ActionsMapFrom} for extracting actions from the machine. */ export type ActionKeysFrom> = T['__actionKey']; /** * Get all predicates map from a machine. * * @template : {@linkcode KeyU}<'predicates'> [T] - type of the machine predicates map. * * @see {@linkcode NotUndefined} */ export type PredicatesMapFrom> = NotUndefined; /** * Get the predicate function from a machine. * * @template : {@linkcode KeyU}<'__predicate'> [T] - type of the machine predicate function * * @see {@linkcode NotUndefined} for ensuring the predicate function is not undefined. */ export type PredicateSFrom> = NotUndefined; /** * Get the guard keys from a machine. * * @template : {@linkcode KeyU}<'predicates'> [T] - type of the machine machine predicates map. * * @see {@linkcode NotUndefined} for ensuring the predicates map is not undefined. * @see {@linkcode PredicatesMapFrom} for extracting guards from the machine. */ export type GuardKeysFrom> = T['__guardKey']; /** * Get all delays map from a machine. * * @template : {@linkcode KeyU}<'delays'> [T] - type of the machine delays map. * * @see {@linkcode NotUndefined} for ensuring the delays map is not undefined. */ export type DelaysMapFrom> = NotUndefined; /** * Get the delay keys from a machine. * * @template : {@linkcode KeyU}<'delays'> [T] - type of the machine delays map. * * @see {@linkcode NotUndefined} for ensuring the delays map is not undefined. * @see {@linkcode DelaysMapFrom} for extracting delays from the machine. */ export type DelayKeysFrom> = T['__delayKey']; /** * Get the delay function from a machine. * * @template : {@linkcode KeyU}<'__delay'> [T] - type of the machine delay function. * * @see {@linkcode NotUndefined} for ensuring the delay function is not undefined. */ export type DelayFnFrom> = NotUndefined; /** * Get the machines map from a machine. * * @template : {@linkcode KeyU}<'machines'> [T] - type of the machine machines map. * * @see {@linkcode NotUndefined} for ensuring the machines map is not undefined. */ export type MachinesMapFrom> = NotUndefined; /** * Get the childrend keys from a machine. * * @template : {@linkcode KeyU}<'__childKey'> [T] - type of the machine child keys. */ export type ChildrenKeysFrom> = T['__childKey']; /** * Simple representation machine options * * @template : {@linkcode EventsMap} [E] - type of the events map * @template : {@linkcode ActorsConfigMap} [A] - type of the actors config map * @template Pc - type of the private context * @template : {@linkcode PrimitiveObject} [Tc] - type of the context * */ export type SimpleMachineOptions> = ToEventObject>> = Partial<{ actions: Partial>>; predicates: Partial>>; delays: Partial>>; actors: Partial<{ children: RecordS>; emitters: EmittersMap; }>; }>; /** * Second version of simple machine options. * * @see {@linkcode Partial} * @see {@linkcode Record} * * @remarks * This type is more flexible than {@linkcode SimpleMachineOptions} */ export type SimpleMachineOptions2 = Partial & Record<'actors', { children?: RecordS; emitters?: RecordS; }>>; export type ExtractContextsKeyFromChild; }> = keyof T['contexts']; export type ExtractEventsKeyFromChild; }> = keyof T['on']; export {}; //# sourceMappingURL=types.d.ts.map