import { MachineBase } from './index'; /** * Constructable class type used by the machine-mixin utilities. * * @typeParam T - Instance type produced by the constructor. */ export type Constructor = new (...args: any[]) => T; /** * Helper to convert a tuple of types into an intersection of those types. * e.g. [A, B] -> A & B * @typeParam U - Union to distribute and intersect. */ export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; /** * Extracts the instance type from a constructor. * @typeParam T - Constructor type to inspect. */ export type Instance = T extends new (...args: any[]) => infer R ? R : never; /** * Extracts the Context type from a MachineBase subclass. * @typeParam T - Machine instance type to inspect. */ export type ExtractContext = T extends MachineBase ? C : never; /** * Combined context type for a union of machines. * @typeParam T - Tuple of machine constructors whose contexts are intersected. */ export type CombinedContext = UnionToIntersection>> & object; /** * Combined instance type for a union of machines. * @typeParam T - Tuple of machine constructors whose instances are intersected. */ export type CombinedInstance = UnionToIntersection>; /** * The instance type of a MachineUnion, with methods remapped to return the union type. * @typeParam T - Tuple of machine constructors being combined. */ export type MachineUnionInstance = { [K in keyof CombinedInstance]: CombinedInstance[K] extends (...args: infer Args) => any ? (...args: Args) => MachineUnionInstance : CombinedInstance[K]; } & CombinedInstance; /** * The constructor type for a MachineUnion. * @typeParam T - Tuple of machine constructors being combined. */ export type MachineUnionConstructor = new (context: CombinedContext) => MachineUnionInstance; /** * Creates a new class that combines the functionality of multiple Machine classes. * * This utility effectively implements multiple inheritance for State Machines. * It merges the prototypes of all provided classes into a single new class, * preserving the type safety of contexts and methods. * * Crucially, it **wraps** inherited methods to ensure they return instances * of the *Combined* machine, enabling fluent method chaining across different * mixed-in capabilities. * * @param machines - A list of Machine classes to combine. * @returns A new class constructor that inherits from all input classes. * @typeParam T - Constructor tuple used to infer combined context and methods. * @throws {TypeError} At construction if no usable base constructor is supplied. * * @example * ```typescript * class A extends MachineBase<{ a: number }> { * incA() { return new A({ a: this.context.a + 1 }); } * } * class B extends MachineBase<{ b: number }> { * incB() { return new B({ b: this.context.b + 1 }); } * } * * class AB extends MachineUnion(A, B) {} * * const machine = new AB({ a: 0, b: 0 }); * machine.incA().incB(); // Type-safe chaining! * ``` */ export declare function MachineUnion(...machines: T): MachineUnionConstructor; /** * Creates a new class that extends a Source machine but excludes methods defined in one or more Excluded classes. * * This is useful for "subtracting" functionality from a combined machine or * creating a restricted view of a larger machine. * * @param Source - The class to extend and extract methods from. * @param Excluded - One or more classes defining methods to remove. * @returns A new class with the subset of methods. * @typeParam S - Source constructor type. * @typeParam E - Tuple of constructors whose methods are removed. * * @example * ```typescript * class Admin extends MachineUnion(Viewer, Editor, Moderator) {} * class Guest extends MachineExclude(Admin, Editor, Moderator) {} * ``` */ export declare function MachineExclude(Source: S, ...Excluded: E): new (context: ExtractContext>) => Omit, Exclude, "context">>; /** * Functional helper to combine multiple Machine instances into a single union instance. * * Automatically merges the contexts of all provided instances and creates a new * `MachineUnion` class on the fly. * * @param instances - Variadic list of machine instances to combine. * @returns A new instance of the combined machine. * @typeParam T - Machine-instance tuple to combine. * * @example * ```typescript * const counter = new Counter({ count: 0 }); * const toggler = new Toggler({ active: true }); * * const app = machineUnion(counter, toggler); * app.increment().toggle(); // Works! logic merged. * ``` */ export declare function machineUnion[]>(...instances: T): Instance ? Constructor : never; }>>; /** * Functional helper to create a restricted machine instance by excluding behaviors * defined in other machine instances. * * @param source - The source machine instance. * @param excluded - Variadic list of machine instances whose methods should be excluded from source. * @returns A new instance restricted to the source's capabilities minus excluded ones. * @typeParam S - Source machine instance type. * @typeParam E - Tuple of machine instances defining excluded methods. * * @example * ```typescript * const fullApp = new AppMachine({ count: 0, active: true }); * const guestApp = machineExclude(fullApp, new Toggler({ active: false })); * // guestApp.toggle(); // Error! * ``` */ export declare function machineExclude, E extends MachineBase[]>(source: S, ...excluded: E): Omit>; //# sourceMappingURL=mixins.d.ts.map