import { Parser, ParserFunction } from "../types/parser-types"; import type { QueryConfig } from "../types/query-config"; import type { Empty } from "../types/utils"; import { Constructor } from "type-fest"; import { GroqBuilderConfigType, GroqBuilderResultType, IGroqBuilder } from "./groq-builder-types"; export * from "./groq-builder-types"; export type RootResult = Empty; export type GroqBuilderOptions = { /** * Enables "pretty printing" for the compiled GROQ string. Useful for debugging. * @default "" (disabled) */ indent?: string; /** * If enabled, then runtime validation is always required for all fields. * If missing, an error will be thrown when the query is created. * * This affects the following 3 APIs where validation is normally optional: * * q.project({ * example: true, // ⛔️ use a validation function instead * example: z.string(), // ✅ * * example: "example.current", // ⛔️ use a tuple instead * example: ["example.current", z.string()], // ✅ * * example: q.field("example.current"), // ⛔️ ensure you pass the 2nd validation parameter * example: q.field("example.current", z.string()), // ✅ * }) * * @default false */ validationRequired?: boolean; }; /** * This class contains the base functionality * needed by all GroqBuilder classes. */ export declare class GroqBuilderBase { protected readonly internal: { readonly query: string; readonly parser: null | ParserFunction; readonly options: GroqBuilderOptions; }; constructor(internal: { readonly query: string; readonly parser: null | ParserFunction; readonly options: GroqBuilderOptions; }); /** * Returns a new GroqBuilder, appending the query. * * @internal * @param query - This raw GROQ query gets appended to the current query * @param parser - A function that validates the incoming data. * Use "passthrough" to indicate that it's OK for * the previous parser to be used with this new data * (i.e. the raw query doesn't change the result type). */ protected chain(query: string, parser?: Parser | null | "passthrough"): GroqBuilder; /** * Returns a new GroqBuilder, extending the current one with the given parameters. * @internal */ protected extend(overrides: Partial): GroqBuilder; /** * Returns an empty "child" GroqBuilder, * used for subqueries in a projection. * * @internal */ protected get subquery(): GroqBuilderSubquery; /** * This utility returns whitespace, if 'indent' is enabled. */ protected get indentation(): { newLine: string; space: string; }; /** * Extends this GroqBuilder class by implementing methods. * This allows the class to be split across multiple files in the `../commands/` folder. */ static implement(this: Constructor, methods: Partial>): void; /** * Extends this GroqBuilder class by implementing properties. * This allows the class to be split across multiple files in the `../commands/` folder. */ static implementProperties(this: Constructor, properties: { [P in keyof TGroqBuilder]?: PropertyDescriptor; }): void; } /** * This GroqBuilder only contains the methods * that can be used at the top-level of a query, * like `star` and `project`. * * It also contains certain utilities, like `fragment` and `value`. */ export declare class GroqBuilderRoot extends GroqBuilderBase { } /** * This GroqBuilder only contains the methods * that can be used inside a subquery of a projection, * like `field` and `project`. * Unlike `q`, it is strongly-typed according to the * context of the current projection. * * It also contains certain utilities that can be used * inside a projection, like `conditional` and `select`. */ export declare class GroqBuilderSubquery extends GroqBuilderBase { } /** * This GroqBuilder is a chainable query builder. * * All instances are immutable. */ export declare class GroqBuilder< /** * The result type of the query */ TResult = any, /** * Contains extra type info, * like the Sanity schema, parameters, and scope */ TQueryConfig extends QueryConfig = QueryConfig> extends GroqBuilderBase implements IGroqBuilder { readonly [GroqBuilderResultType]: TResult; readonly [GroqBuilderConfigType]: TQueryConfig; /** * The GROQ query as a string */ get query(): string; /** * The parser function that should be used to parse result data */ get parser(): null | ParserFunction; /** * Parses and validates the query results, * passing all data through the parsers. */ parse(data: unknown): TResult; }