import type { ZodType } from "zod"; import type { ResultItem } from "./result-types"; import type { Simplify } from "./utils"; import type { ExtractProjectionResult } from "../commands/projection-types"; import type { QueryConfig } from "./schema-types"; /** * A Parser is either a generic mapping function, or a Zod schema. * It's used for run-time validation and/or transformation * of the results of a field. */ export type Parser = ParserFunction | ZodType; /** * Same as `Parser`, except it allows for wider input types, * so that a value of `string` can be handled * by a parser that accepts `string | null` etc. */ export type ParserWithWidenedInput = ParserFunction | ZodType; export type InferParserInput = TParser extends Parser ? TInput : never; export type InferParserOutput = TParser extends Parser ? TOutput : never; /** * A generic "parser" object which can take any input and output a parsed type. */ export type ParserObject = { parse: ParserFunction; }; /** * A generic "parser" function which takes any input and outputs a parsed type. */ export type ParserFunction = (input: TInput) => TOutput; export type ParserFunctionMaybe = null | ParserFunction; export declare const GroqBuilderResultType: unique symbol; export declare const GroqBuilderConfigType: unique symbol; /** * IGroqBuilder is the bare minimum GroqBuilder, used to prevent circular references * @internal */ export type IGroqBuilder = { /** * Used to infer the Result types of a GroqBuilder. * This symbol is not used at runtime. * @internal */ readonly [GroqBuilderResultType]: TResult; /** * Used to infer the TQueryConfig types of a GroqBuilder. * This symbol is not used at runtime * @internal */ readonly [GroqBuilderConfigType]: TQueryConfig; /** * The GROQ query as a string */ readonly query: string; /** * The parser function that should be used to parse result data */ readonly parser: ParserFunction | null; /** * Parses and validates the query results, passing all data through the parsers. */ readonly parse: ParserFunction; }; /** * Extracts the Result type from a GroqBuilder query */ export type InferResultType> = TGroqBuilder extends IGroqBuilder ? TResultType : never; /** * Extracts the Result type for a single item from a GroqBuilder query */ export type InferResultItem> = ResultItem.Infer>; export type InferParametersType> = TGroqBuilder extends IGroqBuilder ? TQueryConfig["parameters"] : never; /** * Used to store the Result types of a Fragment. * This symbol is not used at runtime. */ export declare const FragmentInputTypeTag: unique symbol; export type Fragment = TProjectionMap & { readonly [FragmentInputTypeTag]?: TFragmentInput; }; /** * Infers the result types of a fragment. * @example * const productFragment = q.fragment().project({ * name: q.string(), * price: q.number(), * }); * * type ProductFragment = InferFragmentType; */ export type InferFragmentType> = TFragment extends Fragment ? Simplify> : never;