import type { NotUndefined, PrimitiveObject, Unionize } from '../libs/bemedev/globals/types'; import type { EmitterConfigMap } from '../emitters/index.js'; import type { ChildConfigMap } from '../machine/index.js'; import type { ALWAYS_EVENT, INIT_EVENT, MAX_EXCEEDED_EVENT_TYPE } from './constants'; import { EmptyObject } from '@bemedev/decompose'; /** * Represents an event object with a type and payload. * @template T - The type of the payload. * @returns An object with a type and payload. */ export type EventObject = { type: string; payload: T; }; /** * Represents a map of events where the keys are event names and the values are the payloads. * * @see {@linkcode PrimitiveObject} for the type of the payload. */ export type EventsMap = Record; export type InitEvent = typeof INIT_EVENT; export type MaxExceededEvent = typeof MAX_EXCEEDED_EVENT_TYPE; export type AlwaysEvent = typeof ALWAYS_EVENT; /** * Represents a union of all event strings. */ export type EventStrings = InitEvent | MaxExceededEvent | AlwaysEvent; export type AllEvent = EventObject | EventStrings; /** * Transforms a map of events into a union type of event objects. * Each event object has a type and payload. * @template : {@linkcode EventsMap} [T], the map to transform. * * @see {@linkcode Unionize} for the utility type that creates a union type from * the keys of the map. */ export type EventsR = Unionize extends infer U ? U extends any ? { type: keyof U & string; payload: U[keyof U]; } : never : never; type _EmitterConfigR = Unionize extends infer U extends 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 _ChildConfigR = { [key in keyof T & string]: Unionize extends infer U ? U extends any ? { type: `${key}::on::${keyof U & string}`; payload: U[keyof U]; } : never : never; }[keyof T & string]; export type ActorsConfigMap = { children?: ChildConfigMap; emitters?: EmitterConfigMap; }; /** * Represents a union type of all events, emitters, and child events. * It combines the transformed events, emitters, and child events into a single type. * @template : {@linkcode EventsMap} [E], the map of events. * @template : {@linkcode ActorsConfigMap} [A], the configuration map for actors which includes children and emitters. * @returns A union type of events, emitter-events, and child-events. */ export type ToEventsR = EventsR | _EmitterConfigR> | _ChildConfigR>; export type ToEvents = ToEventsR | EventStrings; export type EventArgObject = object extends E['payload'] ? E['type'] | E : E; export type EventArgAll = E extends string ? E : E extends EventObject ? EventArgObject : never; /** * Transforms an event map into arguments to send to the machine. * @template : {@linkcode EventsMap} [E], the map of events. * * @see {@linkcode EventsR} for the utility type that transforms the map into a union type. * @see {@linkcode EventObject} for the structure of the event object. */ export type EventArg = EventArgObject>; /** * Extracts the type of the event from the event map. * @template : {@linkcode EventsMap} [E], the map of events * * @see {@linkcode EventsR} for the utility type that transforms the map into a union type. * @see {@linkcode EventObject} for the structure of the event object. */ export type EventArgT = EventsR extends infer To extends EventObject ? To['type'] : never; export type ToEventObject = Exclude; export type EventToType = Exclude; export {}; //# sourceMappingURL=types.d.ts.map