import type { Patch } from "immer"; import type { KEYED_BRAND, SKIP } from "../constants.js"; export type Keyed = { value: T; key: string; readonly [KEYED_BRAND]: true; }; export type Args = TArgs | Keyed; export type ArgsOrVoid = TArgs extends void ? void : Args; export type ArgsOrVoidOrSkip = TArgs extends void ? void | typeof SKIP : Args | typeof SKIP; export type TMachineStatus = "pending" | "success" | "error" | "refreshing" | "refresh-error"; export interface TPendingState { status: "pending"; args: TArgs; data: null; error: unknown; updatedAt: null; isRetrying: boolean; } export interface TSuccessState { status: "success"; args: TArgs; data: TData; error: null; updatedAt: number; patchState: TPatchState | null; } export interface TErrorState { status: "error"; args: TArgs; data: null; error: unknown; updatedAt: null; } export interface TRefreshingState { status: "refreshing"; args: TArgs; data: TData; error: unknown; updatedAt: number; patchState: TPatchState | null; isRetrying: boolean; } export interface TRefreshErrorState { status: "refresh-error"; args: TArgs; data: TData; error: unknown; updatedAt: number; patchState: TPatchState | null; } export type TMachineState = TPendingState | TSuccessState | TErrorState | TRefreshingState | TRefreshErrorState; export interface TPatchEntry { forward: Patch[]; inverse: Patch[]; status: "pending" | "committed" | "aborted"; } export interface TPatchState { originalData: TData; patches: TPatchEntry[]; isConsistencyViolation: boolean; } export interface IPatchHandle { commit(): void; abort(): void; } export type TAgentStatus = TMachineStatus | "idle";