import type { ArgsOrVoidOrSkip, IResourceAgent, TResourceAgentState } from "../../../query/types/index.js"; import type { Resource } from "./Resource.js"; /** * Reactive observer for a {@link Resource} with SWR behaviour. * * The agent tracks a single cache entry at a time, deriving a flat * {@link TResourceAgentState} signal. When arguments change via {@link set}, * the previous entry's data is preserved as stale fallback (SWR). * * @template TArgs - Query argument type. * @template TData - Query return data type. */ export declare class ResourceAgent implements IResourceAgent { private readonly _resource; private readonly _tracking$; readonly state$: import("../../../signals/index.js").DisposableSignal>; private _previous$; private _isStarted; private _isMarked; private _settledPromise; constructor(resource: Resource); get args(): TArgs | null; /** * Start observing with the args previously supplied to {@link set}, and * trigger the query for them. A no-op beyond flipping the started flag when * no args have been set yet (or after `SKIP`); the query then starts from * the next {@link set}. */ start(): void; /** * Set the observed args. Before {@link start} this only records them; once * the agent is started, changing the args also triggers the query for them. * `SKIP` clears the observation and drops the agent back to `idle`. * * `mark` (default `false`) makes an unstarted agent report `pending` (or * `refreshing` over adopted stale data) rather than `idle` while no cache * entry exists yet: the React hooks create an agent during render but only * start it in a layout effect, and marking hides that gap. */ set(args: ArgsOrVoidOrSkip, mark?: boolean): void; /** * Take over `source`'s data as this agent's SWR fallback, exactly as * {@link set} would keep the previous entry when the args change on a * single agent: `source`'s current entry if it holds settled data, else * whatever `source` itself was falling back on. * * For consumers that *replace* the agent instead of mutating it — the * React hooks create one agent per args so render stays pure, and hand the * stale data over from the last committed agent to its successor. */ adoptPrevious(source: IResourceAgent): void; /** Retry the last failed query. Only meaningful after an error state. */ retry: () => void; /** Force a background refresh of the current entry (SWR). */ refresh: () => void; /** * Promise resolving once the agent leaves the initial-loading phase (see * {@link IResourceAgent.whenSettled}). * * Consumed by `useSuspenseResource`: a suspended render aborts its effects, * so this promise — created during render — is the only thing that can wake * React once the query settles. It never rejects; the actual error is read * from the derived state on the next render, keeping error handling inside * the React tree (Error Boundary) and avoiding unhandled rejections. * * The instance is cached for the duration of one loading phase so repeated * renders throw the same promise (a fresh promise every render would loop), * and cleared on settle so a later argument change can suspend again. */ whenSettled(): Promise; /** Whether a derived state represents anything other than initial loading. */ private _isSettled; private _deriveState; private _promoteToPrevious; private _deriveNotIdleState; /** * Stale data of the previous entry (SWR fallback) together with the args it * was loaded for, or `null` when there is no previous entry or it holds no * data. Reads the previous machine signal, subscribing the deriving computed * to its changes. */ private _previous; /** * Initial-loading state for `args`: `refreshing` (with `isSwitching`) over * the stale data of the previous entry when there is any (SWR), plain * `pending` otherwise. `retrying` carries the retry bookkeeping of the * underlying machine state (a `retry()` of a failed initial load). */ private _createLoadingState; private _idleState; }