import type { SerializableValue } from './serializable'; /** Legend currently implements in-memory state only; unsupported persistence cannot be selected. */ export interface AppStateSpec { readonly provider: 'legend'; readonly persistence?: false; } export type StatePrimitive = string | number | boolean | null; export type StateValue = SerializableValue; export type StatePath = string | readonly string[]; export interface StateAdapterCapabilities { readonly subscriptions: boolean; readonly computed: boolean; readonly persistence: boolean; } export interface StateAdapterError { readonly code: string; readonly message: string; readonly cause?: unknown; } export type StateSuccess = [TValue] extends [void] ? { readonly ok: true; } : { readonly ok: true; readonly data: TValue; }; export type StateResult = | StateSuccess | { readonly ok: false; readonly error: StateAdapterError; }; export interface StateSnapshot { readonly path: StatePath; readonly value: TValue | undefined; } export type StateListener = ( snapshot: StateSnapshot, ) => void; export interface StateSubscription { unsubscribe(): Promise | void; } export interface StateAdapter { readonly capabilities: StateAdapterCapabilities; get(path: StatePath): StateResult; set(path: StatePath, value: TValue): StateResult; subscribe( path: StatePath, listener: StateListener, ): StateResult; delete?(path: StatePath): StateResult; }