import { Expressions } from "./groq-expressions"; import { Empty, ExtractString, IsAny, LiteralUnion, Override, SimplifyDeep, StringKeys, UndefinedToNull } from "./utils"; import { TypeMismatchError } from "./type-mismatch-error"; import { Parser, ParserWithWidenedInput } from "./parser-types"; import { QueryConfig } from "./query-config"; import { ConditionalKey, ExtractConditionalProjectionTypes } from "../commands/subquery/conditional-types"; import { IGroqBuilder } from "../groq-builder"; import { FragmentMetadataKeys } from "./fragment-types"; export type ProjectionMap = { [P in LiteralUnion]?: ProjectionFieldConfig : any>; } & { "..."?: true | Parser; }; export type ProjectionFieldConfig = true | Expressions.Field | ParserWithWidenedInput | readonly [ Expressions.Field, ParserWithWidenedInput ] | IGroqBuilder; export type ExtractProjectionResult = Override, ExtractConditionalProjectionTypes & ExtractProjectionResultFields>>>; type ExtractSpreadOperator = TProjectionMap extends { "...": true; } ? TResultItem : TProjectionMap extends { "...": Parser; } ? TOutput : Empty; type ExtractProjectionResultFields = { [P in keyof TProjectionMap]: TProjectionMap[P] extends IGroqBuilder ? TValue : TProjectionMap[P] extends boolean ? P extends keyof TResultItem ? UndefinedToNull : TypeMismatchError<{ error: `⛔️ 'true' can only be used for known properties; '${StringKeys

}' is not known ⛔️`; actual: P; expected: keyof TResultItem; }> : TProjectionMap[P] extends string ? TProjectionMap[P] extends Expressions.Field ? Expressions.FieldValue : TypeMismatchError<{ error: `⛔️ Naked projections can only be used for known properties; '${TProjectionMap[P]}' is not known ⛔️`; actual: TProjectionMap[P]; expected: SimplifyDeep>; }> : TProjectionMap[P] extends readonly [infer TKey, infer TParser] ? TKey extends Expressions.Field & string ? TParser extends Parser ? ValidateParserInput, TParserInput, TParserOutput, TKey> : TypeMismatchError<{ error: `⛔️ Naked projections can only be used for known properties; '${TKey}' is not known ⛔️`; actual: TKey; expected: SimplifyDeep>; }> : TypeMismatchError<{ error: `⛔️ Naked projections can only be used for known properties; '${ExtractString}' is not known ⛔️`; actual: TKey; expected: SimplifyDeep>; }> : TProjectionMap[P] extends Parser ? P extends keyof TResultItem ? ValidateParserInput, TParserInput, TParserOutput, StringKeys

> : TypeMismatchError<{ error: `⛔️ A parser can only be used for known properties; '${StringKeys

}' is not known ⛔️`; actual: P; expected: keyof TResultItem; }> : never; }; export type ValidateParserInput = TIncomingValue extends TParserInput ? TParserOutput : IsAny extends true ? TParserOutput : TypeMismatchError<{ error: `⛔️ The '${TKey}' field has a data type that is not fully compatible with the specified parser ⛔️`; actual: TIncomingValue; expected: TParserInput; }>; export {};