import { ExtractProjectionResult, ProjectionMap, ProjectionMapOrCallback } from "./projection-types"; import { Empty, IntersectionOfValues, Simplify, ValueOf } from "../types/utils"; import { ExtractDocumentTypes, QueryConfig } from "../types/schema-types"; import { GroqBuilder } from "../groq-builder"; import { IGroqBuilder, InferResultType } from "../types/public-types"; import { Expressions } from "../types/groq-expressions"; export type ConditionalProjectionMap = Partial, ProjectionMap | ((q: GroqBuilder) => ProjectionMap)>>; export type ExtractConditionalProjectionResults, TConfig extends ConditionalConfig> = SpreadableConditionals; }>>; export type ExtractConditionalProjectionTypes = Simplify>]: InferResultType>; }>>; export type ConditionalByTypeProjectionMap = { [_type in ExtractDocumentTypes]?: ProjectionMapOrCallback, TQueryConfig>; }; export type ExtractConditionalByTypeProjectionResults, TConfig extends ConditionalConfig> = SpreadableConditionals, keyof TConditionalByTypeProjectionMap>; }) | ValueOf<{ [_type in keyof TConditionalByTypeProjectionMap]: { /** * When using conditionalByType, * this _type is automatically added to the query. */ _type: _type; } & ExtractProjectionResult, TConditionalByTypeProjectionMap[_type] extends (q: any) => infer TProjectionMap ? TProjectionMap : TConditionalByTypeProjectionMap[_type]>; }>>; export type ConditionalKey = `[CONDITIONAL] ${TKey}`; export declare function isConditional(key: string): key is ConditionalKey; export type SpreadableConditionals = { [UniqueConditionalKey in ConditionalKey]: IGroqBuilder; }; export type ConditionalConfig = { /** * If using multiple conditions in a single projection, * each condition must have a unique key. * This key is not used in the resulting query, and can be anything. */ key: TKey; /** * If the conditional statements cover all possible scenarios, * then setting `isExhaustive` to `true` will ensure stronger types, * and will throw runtime errors if none of the conditions are satisfied. */ isExhaustive: TIsExhaustive; };