1 | import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
|
2 | import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
|
3 | declare type SimplisticExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
|
4 | type: TEventType;
|
5 | } ? TEvent : never;
|
6 | export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
|
7 | initialContext: TContext;
|
8 | assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, SimplisticExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, SimplisticExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, SimplisticExtractEvent<TEvent, TEventType>, TEvent>;
|
9 | events: Prop<TModelCreators, 'events'>;
|
10 | actions: Prop<TModelCreators, 'actions'>;
|
11 | reset: () => AssignAction<TContext, any>;
|
12 | createMachine: {
|
13 | <TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
|
14 | value: any;
|
15 | context: TContext;
|
16 | }, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
|
17 | };
|
18 | }
|
19 | export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
|
20 | export declare type ModelEventsFrom<TModel extends Model<any, any, any, any> | undefined> = TModel extends Model<any, infer TEvent, any, any> ? TEvent : EventObject;
|
21 | export declare type ModelActionsFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<any, any, infer TAction, any> ? TAction : never;
|
22 | export declare type EventCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
23 | type: any;
|
24 | } ? "An event creator can't return an object with a type property" : Self : 'An event creator must return an object';
|
25 | export declare type EventCreators<Self> = {
|
26 | [K in keyof Self]: Self[K] extends AnyFunction ? EventCreator<Self[K]> : 'An event creator must be a function';
|
27 | };
|
28 | export declare type FinalEventCreators<Self> = {
|
29 | [K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
30 | type: K;
|
31 | }> : never;
|
32 | };
|
33 | export declare type ActionCreator<Self extends AnyFunction, Return = ReturnType<Self>> = Return extends object ? Return extends {
|
34 | type: any;
|
35 | } ? "An action creator can't return an object with a type property" : Self : 'An action creator must return an object';
|
36 | export declare type ActionCreators<Self> = {
|
37 | [K in keyof Self]: Self[K] extends AnyFunction ? ActionCreator<Self[K]> : 'An action creator must be a function';
|
38 | };
|
39 | export declare type FinalActionCreators<Self> = {
|
40 | [K in keyof Self]: Self[K] extends AnyFunction ? (...args: Parameters<Self[K]>) => Compute<ReturnType<Self[K]> & {
|
41 | type: K;
|
42 | }> : never;
|
43 | };
|
44 | export interface ModelCreators<Self> {
|
45 | events?: EventCreators<Prop<Self, 'events'>>;
|
46 | actions?: ActionCreators<Prop<Self, 'actions'>>;
|
47 | }
|
48 | export interface FinalModelCreators<Self> {
|
49 | events: FinalEventCreators<Prop<Self, 'events'>>;
|
50 | actions: FinalActionCreators<Prop<Self, 'actions'>>;
|
51 | }
|
52 | export declare type UnionFromCreatorsReturnTypes<TCreators> = {
|
53 | [K in keyof TCreators]: TCreators[K] extends AnyFunction ? ReturnType<TCreators[K]> : never;
|
54 | }[keyof TCreators];
|
55 | export {};
|
56 |
|
\ | No newline at end of file |