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**.

30 lines (29 loc) 1.45 kB
import { ResultItem } from "../types/result-types"; import { ConditionalConfig, ConditionalProjectionMap, ExtractConditionalProjectionResults } from "./conditional-types"; declare module "../groq-builder" { interface GroqBuilder<TResult, TQueryConfig> { /** * Creates an inline conditional projection. * * The Condition strings are NOT strongly-typed. You can put any valid GROQ statement into these keys. See `conditionalByType` for a strongly-typed option. * * @example * q.star.filterByType("product").project(sub => ({ * name: q.string(), * ...sub.conditional({ * "price == msrp": { * onSale: q.value(false), * }, * "price < msrp": { * onSale: q.value(true), * price: q.number(), * msrp: q.number(), * }, * }), * })) */ conditional<TConditionalProjections extends ConditionalProjectionMap<ResultItem.Infer<TResult>, TQueryConfig>, TKey extends string = typeof DEFAULT_KEY, TIsExhaustive extends boolean = false>(conditionalProjections: TConditionalProjections, config?: Partial<ConditionalConfig<TKey, TIsExhaustive>>): ExtractConditionalProjectionResults<ResultItem.Infer<TResult>, TConditionalProjections, ConditionalConfig<TKey, TIsExhaustive>>; } } declare const DEFAULT_KEY: "[KEY]"; export {};