/**
 * DerivedVariable resolution process:
 * 1. 'result-selector' (getOrRegisterDerivedVariableResult) - handle resolving dependencies, return a previous/cached result or signify that we need to refetch.
 * This one explicitly does not use 'nested' in its key to share results across different nested values.
 * 2. 'selector' (getOrRegisterDerivedVariableValue) - handle fetching if needed, waiting for task result if task response
 * This one also does NOT use 'nested', also shares results.
 * 3. 'nested-selector' (getOrRegisterDerivedVariable) - handle resolving to a nested value if 'nested' is set
 * This one DOES use 'nested' in its key to resolve the shared values to different nested values.
 */
import type { Params } from 'react-router';
import { type GetRecoilValue, type RecoilValue, type Snapshot } from 'recoil';
import { type WebSocketClientInterface } from '../../api';
import { type RequestExtras } from '../../api/http';
import { type DerivedVariable, type GlobalTaskContext, type ResolvedDerivedVariable, type ResolvedServerVariable, type ResolvedSwitchVariable } from '../../types';
import { type Deferred } from '../utils/deferred';
import { type TriggerIndexValue } from './store';
import { type TriggerInfo } from './triggers';
export interface DerivedVariableValueResponse<T> {
    cache_key: string;
    value: T;
}
type DerivedVariableResponse<T> = DerivedVariableTaskResponse | DerivedVariableValueResponse<T>;
export declare function isTaskResponse(dvResponse: DerivedVariableResponse<any>): dvResponse is DerivedVariableTaskResponse;
interface DerivedVariableTaskResponse {
    cache_key: string;
    task_id: string;
}
interface FetchDerivedVariableArgs {
    cache: DerivedVariable['cache'];
    extras: RequestExtras;
    force_key?: string | null;
    /**
     * selector instance key  - each selector's requests should be treated separately
     */
    selectorKey: string;
    values: Record<string | number, any>;
    /**
     * Variable uid
     */
    variableUid: string;
    wsClient: WebSocketClientInterface;
}
/**
 * Fetch the value of a derived variable from the backend
 *
 * @param input Function inputs
 * - `cache`, the cache option for the derived variable.
 * - `extras`, request extras to be merged into the options
 * - `uid`, the uid of the derived variable
 * - `values`, values to pass in the request
 * - `wsClient`, websocket client
 */
export declare function fetchDerivedVariable<T>({ cache, extras, force_key, variableUid, values, wsClient, }: FetchDerivedVariableArgs): Promise<DerivedVariableResponse<T>>;
/**
 * Resolve a value to a format understood by the backend, resolving atoms to values.
 *
 * @param value value to resolve
 * @param getter recoil getter function
 */
export declare function resolveValue(value: ResolvedDerivedVariable | ResolvedServerVariable | ResolvedSwitchVariable | RecoilValue<any>, getter: GetRecoilValue): any;
/**
 * Recursively build a deps array from a list of values
 * Values not in deps array are replaced with empty array
 *
 * @param values array of primitives and ResolvedDerivedVariable objects
 * @param deps array of indexes of dependencies to get values from
 */
export declare function getDeps(values: Array<ResolvedDerivedVariable | any>, deps?: number[]): any[];
/**
 * A helper hook that turns a DerivedVariable into its trigger index value.
 * Useful to subscribe a component to forced trigger updates.
 *
 * @param variable variable to use
 */
export declare function useTriggerIndex(variable: DerivedVariable): TriggerIndexValue;
/**
 * DerivedVariable resolution result meaning that the value did not change since last time
 * and should be returned from the previous entry.
 */
interface PreviousResult {
    /**
     * Previous entry in the depsRegistry found to not have been changed
     */
    entry: {
        args: any[];
        result: any;
    };
    type: 'previous';
    relevantValues: any[];
    /**
     * List of values to use in the refetch request (force_key is embedded directly in the values)
     */
    values: any[];
    /** Key to the deps cache */
    depsKey: string;
}
/**
 * DerivedVariable resolution result meaning that the value changed since last time
 * and should be refetched.
 */
interface CurrentResult {
    /**
     * List of new 'relevant' values which should be used to update the depsRegistry entry if refetch was successful
     */
    relevantValues: any[];
    /**
     * Force key for self-trigger (polling, manual trigger), null if triggered by nested variable
     */
    selfTriggerForceKey: string | null;
    type: 'current';
    /**
     * List of values to use in the refetch request (force_key is embedded directly in the values)
     */
    values: any[];
    /** Key to the deps cache */
    depsKey: string;
}
/**
 * Represents a cached result of a derived variable resolution.
 * This can happen when we prefetch a derived value, wraps the current result and the raw server response.
 */
interface CachedResponse {
    type: 'cached';
    response: Deferred<{
        ok: boolean;
        value: any;
    }>;
    values: any[];
    depsKey: string;
    currentResult: CurrentResult;
    relevantValues: any[];
}
/**
 * Represents the result of a derived variable resolution.
 */
export type DerivedResult = PreviousResult | CurrentResult | CachedResponse;
/**
 * Resolve a derived value from a list of dependant variables and their resolved values.
 *
 * Handles a dependency array, where in case 'relevant' (i.e. present in deps) values did not change,
 * an earlier result from the `depsRegistry` is returned.
 *
 * This is the core of the derived variable resolution logic, extracted so that it can be used in both
 * DerivedVariable and py_component logic.
 *
 * @param key unique key to look up `depsRegistry` entry from
 * @param variables dependant variables
 * @param deps list of relevant dependant variables, akin to useEffect dependency array
 * @param resolvedVariables resolved values of dependant variables - turned into primitives and Resolved forms
 * @param get getter function to resolve atoms to values
 * @param triggerList list of trigger info objects
 * @param triggers list of triggers to register as dependencies; first one is expected to be the self-trigger
 */
export declare function resolveDerivedValue({ key, variables, deps, resolvedVariables, resolutionStrategy, triggerList, triggers, }: {
    key: string;
    variables: any[];
    deps: any[];
    resolvedVariables: any[];
    resolutionStrategy: {
        name: 'get';
        get: GetRecoilValue;
    } | {
        name: 'static';
        snapshot: Snapshot;
        params: Params<string>;
    };
    triggerList: Array<TriggerInfo>;
    triggers: TriggerIndexValue[];
}): DerivedResult;
/**
 * Get or register a recoil selector for a given derived variable result object.
 * Resolves the primitive values and returns either the previous cached result or an object
 * signifying that we need to refetch the value.
 *
 * First of the 3 stages of resolving a derived variable.
 */
export declare function getOrRegisterDerivedVariableResult(variable: DerivedVariable, wsClient: WebSocketClientInterface, taskContext: GlobalTaskContext, currentExtras: RequestExtras): RecoilValue<DerivedResult>;
/**
 * Get a derived variable from the selector registry, registering it if not already registered
 *  Handles the 'derived result' returned from the first stage selector, fetching the value
 *  if value is 'current', awaiting cached deferred values and waiting for task results if needed.
 *
 * Second of the 3 stages of resolving a derived variable.
 */
export declare function getOrRegisterDerivedVariableValue(variable: DerivedVariable, wsClient: WebSocketClientInterface, taskContext: GlobalTaskContext, currentExtras: RequestExtras): RecoilValue<any>;
/**
 * Resolve the nested value of a DerivedVariable if needed.
 * Unwraps the raw result of a DerivedVariable.
 *
 * Third of the 3 stages of resolving a derived variable. Unwraps the 'nested' value
 * if set on the variable.
 *
 * @param variable variable to register
 * @param wsClient WebSocket client from context
 * @param taskContext global task context
 * @param search search query from location
 * @param extras request extras to be merged into the options
 */
export declare function getOrRegisterDerivedVariable(variable: DerivedVariable, wsClient: WebSocketClientInterface, taskContext: GlobalTaskContext, currentExtras: RequestExtras): RecoilValue<any>;
/**
 * Preload a derived value.
 * Replicates the logic of normal resolution but resolving the values
 * from snapshot or falling back to the defaults.
 *
 * For details, see the original implementation comments.
 *
 * Returns null if there already is a cached value for the variable.
 * Otherwise, returns an object with values so be sent to the backend
 * and handles to resolve the cached promise to the result.
 */
export declare function preloadDerivedValue({ key, variables, deps, triggerList, triggers, snapshot, params, }: {
    key: string;
    variables: any[];
    deps: any[];
    triggerList: Array<TriggerInfo>;
    triggers: TriggerIndexValue[];
    snapshot: Snapshot;
    params: Params<string>;
}): {
    handle: Deferred<any>;
    result: DerivedResult;
} | null;
/**
 * Preload a derived variable value.
 */
export declare function preloadDerivedVariable(variable: DerivedVariable, snapshot: Snapshot, params: Params<string>): ReturnType<typeof preloadDerivedValue>;
/**
 * Helper hook to get the (data) derived variable selector, while correctly registering triggers and setting up polling interval.
 *
 * @param variable derived variable to use
 * @param WsClient websocket client instance
 * @param taskContext global task context
 * @param search search query
 * @param extras request extras to be merged into the options
 */
export declare function useDerivedVariable(variable: DerivedVariable, WsClient: WebSocketClientInterface, taskContext: GlobalTaskContext, extras: RequestExtras, pollingInterval?: number): RecoilValue<any>;
export {};
//# sourceMappingURL=derived-variable.d.ts.map