import type { Asset, Flow, FlowResult } from "@player-ui/types"; import type { BindingParser, BindingLike } from "./binding"; import type { SchemaController } from "./schema"; import type { ExpressionEvaluator } from "./expressions"; import type { Logger } from "./logger"; import type { ViewController, DataController, ValidationController, FlowController, ErrorController } from "./controllers"; import type { ReadOnlyDataController } from "./controllers/data/utils"; import { SyncBailHook, SyncHook, SyncWaterfallHook } from "tapable-ts"; import { ViewInstance } from "./view"; /** * Metadata describing the incoming content to `Player.start()`. Passed * alongside the raw payload through the `transformContent` hook so plugins * can decide whether to claim/convert it. */ export interface ContentMeta { /** * Content format identifier. `"player"` (default) means the input is * already a `Flow` and needs no conversion. Anything else is a free-form * string a plugin can recognize. */ format: string; /** * Optional format version (e.g., `"0.9"`). Free-form — plugins decide the * convention. Lets a single format plugin dispatch across major/minor * versions without the caller picking a different `format` string. */ version?: string; } /** * Options passed to `Player.start()` alongside the payload. */ export interface StartOptions { /** Identifier of the input content's format. Default: `"player"`. */ format?: string; /** Optional content-format version. See `ContentMeta.version`. */ version?: string; } /** * Public Player Hooks */ export interface PlayerHooks { /** The hook that fires every time we create a new flowController (a new Content blob is passed in) */ flowController: SyncHook<[FlowController], Record>; /** The hook that updates/handles views */ viewController: SyncHook<[ViewController], Record>; /** A hook called every-time there's a new view. This is equivalent to the view hook on the view-controller */ view: SyncHook<[ViewInstance], Record>; /** Called when an expression evaluator was created */ expressionEvaluator: SyncHook<[ExpressionEvaluator], Record>; /** The hook that creates and manages data */ dataController: SyncHook<[DataController], Record>; /** Called after the schema is created for a flow */ schema: SyncHook<[SchemaController], Record>; /** Manages validations (schema and x-field ) */ validationController: SyncHook<[ValidationController], Record>; /** Manages parsing binding */ bindingParser: SyncHook<[BindingParser], Record>; /** Manages error handling and captures errors from all subsystems */ errorController: SyncHook<[ErrorController], Record>; /** A that's called for state changes in the flow execution */ state: SyncHook<[PlayerFlowState], Record>; /** A hook to access the current flow */ onStart: SyncHook<[Flow>], Record>; /** A hook for when the flow ends either in success or failure */ onEnd: SyncHook<[], Record>; /** Mutate the Content flow before starting */ resolveFlowContent: SyncWaterfallHook<[ Flow> ], Record>; /** * Transform raw input content into a Player `Flow` before any state is set * up. Fires at the top of `Player.start()` — after plugins are applied, * before `resolveFlowContent`. Being a bail hook, taps inspect `meta.format` * (and optionally `meta.version`) and return a `Flow` to claim the content; * returning `undefined` passes to the next tap. Player registers a default * tap for the `"player"` format that returns the payload as-is, so the hook * is guaranteed to yield a `Flow` and `start()` needs no type-casting. */ transformContent: SyncBailHook<[unknown, ContentMeta], Flow>>; } /** The status for a flow's execution state */ export type PlayerFlowStatus = "not-started" | "in-progress" | "completed" | "error"; /** Common interface for the state of Player's flow execution */ export interface BaseFlowState { /** A unique reference for the life-cycle of a flow */ ref: symbol; /** The status of the given flow */ status: T; } /** The beginning state of Player, before it's seen a flow */ export type NotStartedState = BaseFlowState<"not-started">; export declare const NOT_STARTED_STATE: NotStartedState; /** Shared properties for a flow in any state of execution (in-progress, completed successfully, or errored out) */ export interface PlayerFlowExecutionData { /** The currently executing flow */ flow: Flow; } export interface ControllerState { /** The manager for data for a flow */ data: DataController; /** The view manager for a flow */ view: ViewController; /** The schema manager for a flow */ schema: SchemaController; /** The validation manager for a flow */ validation: ValidationController; /** The expression evaluator for a flow */ expression: ExpressionEvaluator; /** The manager for parsing and resolving bindings */ binding: BindingParser; /** the manager for the flow state machine */ flow: FlowController; /** The manager for error handling */ error: ErrorController; } /** A flow is currently executing */ export type InProgressState = BaseFlowState<"in-progress"> & PlayerFlowExecutionData & { /** A promise that resolves when the flow is completed */ flowResult: Promise; /** The underlying state controllers for the current flow */ controllers: ControllerState; /** Allow other platforms to abort the current flow with an error */ fail: (error: Error) => void; /** * The Logger for the current player instance */ logger: Logger; }; /** The flow completed properly */ export type CompletedState = BaseFlowState<"completed"> & PlayerFlowExecutionData & FlowResult & { /** Readonly Player controllers to provide Player functionality after the flow has ended */ controllers: { /** A read only instance of the Data Controller */ data: ReadOnlyDataController; }; }; /** The flow finished but not successfully */ export type ErrorState = BaseFlowState<"error"> & { /** The currently executing flow */ flow: Flow; /** The error associated with the failed flow */ error: Error; }; /** Any Player state */ export type PlayerFlowState = NotStartedState | InProgressState | CompletedState | ErrorState; export type RawSetType = [BindingLike, any]; export type RawSetTransaction = Record | RawSetType[]; //# sourceMappingURL=types.d.ts.map