/** * The protocol type definitions of @xmachines/play * * These types define the architectural contracts between the Actor layer and the * infrastructure layer. The two layers therefore stay loosely coupled, with no * direct dependency. RFC section 5.2 gives these protocols. They open the * communication channels, and they keep each concern separate. * * This package defines the base event contract only. This limit is deliberate. */ /** * The generic event type of the Play Architecture * * PlayEvent is the minimal event contract of the Actor communication: it is every * object with a `type` string property. The infrastructure sends each event to the * Actor, and the guards of the Actor state machine decide the validity. * * **The type parameter:** the generic `TPayload` gives the shape of the event fields * after `type`. Its default is `Record`, which accepts each shape. * * **Architectural context:** the type implements **Passive Infrastructure * (INV-04)**. The infrastructure converts each user action into an event, and it * makes no decision. The guards of the Actor state machine decide if each event is * valid in the current state. * * **Framework-agnostic:** this type is generic on purpose, and it is bound to no * state machine framework. It matches the common event shape of XState, of Robot, * and of the other state machine libraries. * * **The common event types:** * - A domain event: `{ type: 'auth.login', userId: '123' }` * - Your own event: `{ type: 'form.submit', data: {...} }` * * @typeParam TPayload - The fields after `type`. The default is `Record` * * @example * The use without the type parameter, which is flexible * ```typescript * import type { PlayEvent } from "@xmachines/play"; * * // It accepts every event with type: string * const loginEvent: PlayEvent = { * type: 'auth.login', * userId: 'user123', * timestamp: Date.now() * }; * actor.send(loginEvent); * ``` * * @example * The use with the type parameter, which is type-safe * ```typescript * import type { PlayEvent } from "@xmachines/play"; * * // A type-safe event with a known shape * type LoginEvent = PlayEvent<{ userId: string; timestamp: number }>; * * const loginEvent: LoginEvent = { * type: 'auth.login', * userId: 'user123', * timestamp: Date.now() * }; * * // A TypeScript error: a necessary field is absent * const invalid: LoginEvent = { type: 'auth.login' }; // Error! * ``` * * @see [Play RFC](../../docs/rfc/play.md) */ export type PlayEvent = Record> = { readonly type: string; } & TPayload; //# sourceMappingURL=types.d.ts.map