import { query, status, Synnax as Client } from '@synnaxlabs/client'; import { CrudeTimeSpan, destructor, state, verbs } from '@synnaxlabs/x'; import { default as z } from 'zod'; import { InitialStatusDetailsContainer, Result, ResultStatus } from './result'; /** What an update implementation receives. */ export interface UpdateParams { data: Input; client: Client; setStatus: (setter: state.SetArg>) => void; onOptimisticComplete: (data: Output) => Promise; } /** Params for {@link createUpdate}. */ export type CreateUpdateParams = { name: string; verbs: verbs.Verbs; update: (params: UpdateParams) => Promise; } & InitialStatusDetailsContainer; /** Return value for `useObservableUpdate`. */ export interface UseObservableUpdateReturn { /** Runs the update and reports a failure as an error status. */ update: (data: Input, opts?: query.FetchOptions) => void; /** Runs the update and resolves to whether it succeeded. */ updateAsync: (data: Input, opts?: query.FetchOptions) => Promise; } export interface UseObservableUpdateParams { debounce?: CrudeTimeSpan; onChange: state.Setter>; beforeUpdate?: (params: BeforeUpdateParams) => Promise | Input | boolean; afterOptimistic?: (params: AfterOptimisticParams) => Promise | void; afterSuccess?: (params: AfterSuccessParams) => Promise | void; afterFailure?: (params: AfterFailureParams) => Promise | void; } export interface BeforeUpdateParams { /** Side-effect undos run in reverse order when the update fails. */ rollbacks: destructor.Destructor[]; client: Client; data: Data; } export interface AfterOptimisticParams { /** Side-effect undos run in reverse order when the update fails. */ rollbacks: destructor.Destructor[]; client: Client; data: Output; } export interface AfterSuccessParams { client: Client; data: Output; } export interface AfterFailureParams { client: Client; status: status.Status>; data: Data; } export interface UseDirectUpdateParams extends Omit, "onChange"> { } /** Return value for `useUpdate`: the update callbacks plus its own result state. */ export type UseDirectUpdateReturn = Result & UseObservableUpdateReturn; export interface UseObservableUpdate { (params: UseObservableUpdateParams): UseObservableUpdateReturn; } export interface UseUpdate { (params?: UseDirectUpdateParams): UseDirectUpdateReturn; } /** The hooks {@link createUpdate} builds for one mutation. */ export interface CreateUpdateReturn { useObservableUpdate: UseObservableUpdate; useUpdate: UseUpdate; } /** * Builds the hooks that run one mutation against a Core, applying the change to the * cache before the request returns and rolling it back on failure. Call it once per * mutation, at module scope. */ export declare const createUpdate: (createParams: CreateUpdateParams) => CreateUpdateReturn; //# sourceMappingURL=update.d.ts.map