import type { IsUnknown, HasRequiredKeys, EmptyObject } from "type-fest"; import type { QueryConfig } from "./types/query-config"; import type { IGroqBuilder } from "./groq-builder"; 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?: EmptyObject; } : { /** * This query requires the following input parameters. */ parameters: TQueryConfig["parameters"]; }; /** * Executes a query and returns strongly-typed results. */ export type QueryRunnerFunction = { (builder: IGroqBuilder, ..._options: MaybeRequired & TCustomOptions>): Promise; }; /** * 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): QueryRunnerFunction; /** * 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 {};