UNPKG

groq-builder

Version:

A **schema-aware**, strongly-typed GROQ query builder. It enables you to build GROQ queries using **auto-completion**, **type-checking**, and **runtime validation**.

24 lines (23 loc) 1.66 kB
import { ResultItem } from "../types/result-types"; import { ProjectionKey, ProjectionKeyValue, ValidateParserInput } from "./projection-types"; import { Parser, ParserWithWidenedInput } from "../types/public-types"; declare module "../groq-builder" { interface GroqBuilder<TResult, TQueryConfig> { /** * Performs a "naked projection", returning just the values of the field specified. * * This overload does NOT perform any runtime validation; the return type is inferred. */ field<TProjectionKey extends ProjectionKey<ResultItem.Infer<TResult>>>(fieldName: TProjectionKey): GroqBuilder<ResultItem.Override<TResult, ProjectionKeyValue<ResultItem.Infer<TResult>, TProjectionKey>>, TQueryConfig>; /** * Performs a "naked projection", returning just the values of the field specified. * * This overload allows a parser to be passed, for validating the results. */ field<TProjectionKey extends ProjectionKey<ResultItem.Infer<TResult>>, TParser extends ParserWithWidenedInput<ProjectionKeyValue<ResultItem.Infer<TResult>, TProjectionKey>>>(fieldName: TProjectionKey, parser: TParser): GroqBuilder<ResultItem.Override<TResult, TParser extends Parser<infer TParserInput, infer TParserOutput> ? ValidateParserInput<ProjectionKeyValue<ResultItem.Infer<TResult>, TProjectionKey>, TParserInput, TParserOutput> : never>, TQueryConfig>; /** @deprecated Please use the 'field' method for naked projections */ projectField: never; /** @deprecated Please use the 'field' method for naked projections */ projectNaked: never; } }