import type { QuestionnaireResponse } from 'fhir/r4'; /** * A single form update task, representing a `QuestionnaireResponse` that should be processed. */ export interface UpdateTask { /** The `QuestionnaireResponse` snapshot used to evaluate calculated expressions */ questionnaireResponse: QuestionnaireResponse; /** * Optional flag indicating this update is the first update upon pre-population and form build. * Useful for distinguishing initialization updates from subsequent user-triggered updates. * Defaults to `false`. */ isInitialUpdate?: boolean; } /** * Zustand store for managing queued, sequential updates to a FHIR form. */ export interface FormUpdateQueueStoreType { /** Queue of form update tasks (FIFO) */ queue: UpdateTask[]; /** Flag indicating if a task is currently being processed */ isProcessing: boolean; /** * Adds a new form update task to the end of the queue. * Triggers the queue processor if not already running. * * @param task - The form update task to enqueue */ enqueueFormUpdate: (task: UpdateTask) => void; /** * Internal processor that handles one task at a time, in order. * * - Applies the `updateExpressions` function to the `questionnaireResponse`. * - Applies the resulting computed updates. * - Updates the `QuestionnaireResponse` store in two phases: immediate and async. * - Automatically proceeds to the next task in the queue. */ _startProcessing: () => void; } /** * `formUpdateQueueStore` is a Zustand store that serializes asynchronous form update logic. * * It ensures that each form update task is processed sequentially, one at a time, * to avoid race conditions and inconsistent state during expression evaluation. * * - `enqueueFormUpdate` adds a new task to the end of the queue. * - `_startProcessing` handles processing each task and re-triggers itself as needed. */ export declare const formUpdateQueueStore: import("zustand/vanilla").StoreApi; export declare const useFormUpdateQueueStore: import("zustand/vanilla").StoreApi & { use: { queue: () => UpdateTask[]; isProcessing: () => boolean; enqueueFormUpdate: () => (task: UpdateTask) => void; _startProcessing: () => () => void; }; };