import type { HasRequiredKeys, IsUnknown } from "type-fest"; import type { QueryConfig } from "./types/schema-types"; import { IGroqBuilder } from "./types/public-types"; export type QueryRunnerOptions = IsUnknown extends true ? { /** * This query does not have any parameters defined. * Please use `q.parameters<...>()` to define the required input parameters. */ parameters?: never; } : { /** * This query requires the following input parameters. */ parameters: TQueryConfig["parameters"]; }; /** * Utility to create a "query runner" that consumes the result of the `q` chain. * * If you need to pass custom options to your `execute` function, * use the TCustomOptions to ensure they're strongly typed. * * @example * const runner = makeSafeQueryRunner( * async (query, { parameters }) => { * return await sanityClient.fetch(query, { params: parameters }); * } * ) * * @example * const runner = makeSafeQueryRunner<{ withAuth: boolean }>( * async (query, { parameters, withAuth }) => { * if (withAuth) ... * } * ) * */ export declare function makeSafeQueryRunner(execute: (query: string, options: QueryRunnerOptions & TCustomOptions) => Promise): (builder: IGroqBuilder, ..._options: MaybeRequired & TCustomOptions>) => Promise; /** * If all options are fully optional, * then this makes the entire options argument optional too. * * If the options argument has any required keys, * then the entire options argument is required too. */ type MaybeRequired = HasRequiredKeys extends true ? [TOptions] : [] | [TOptions]; export {};