import { ConfigGetScope, QueryConfig } from "./query-config"; import type { ConditionalPick, IsLiteral, LiteralUnion } from "type-fest"; import { StringKeys, ValueOf, Variable } from "./utils"; import { ProjectionPathEntries, ProjectionPathEntriesByType, ProjectionPaths, ProjectionPathsByType, ProjectionPathValue } from "./projection-paths"; export declare namespace Expressions { /** * Represents valid expressions for selecting a value. * This includes: * - fields of the current item (e.g. `"_type"`) * - parameters (e.g. `"$id"`) * - parent selectors (e.g. `"^._id"`) * - self (e.g. `"@"`) */ export type Field = ProjectionPaths>; /** * Retrieves the value of the */ export type FieldValue> = ProjectionPathValue, TFieldPath>; /** * This type allows any string, but provides * TypeScript suggestions for common expressions, * like '_type == "product"' or 'slug.current == $slug'. */ export type AnyConditional = LiteralUnion, string>; /** * This type allows any string, but provides * TypeScript suggestions for common expressions, * like '_type == "product"' or 'slug.current == $slug' * and 'title match (string)' for the score command */ export type Score = Conditional | MatchExpression; /** * Same as Score, but allows any valid string */ export type ScoreRaw = LiteralUnion, string>; /** * A strongly-typed conditional Groq conditional expression. * Currently, this only supports various simple expressions, * like '_type == "product"' or 'slug.current == $slug'. * */ export type Conditional = Variable> extends infer $PathEntries ? Equality<$PathEntries, TQueryConfig> | Inequality<$PathEntries, TQueryConfig> | NumberComparisons<$PathEntries, TQueryConfig> | BooleanSuggestions<$PathEntries> | References : never; type Comparison = ValueOf<{ [Key in StringKeys]: `${Key} ${ComparisonOperator} ${SuggestedKeysByType}`; }>; type Equality = Comparison; type Inequality = Comparison, TQueryConfig, "!=">; type MatchExpression = Comparison, string>, TQueryConfig, "match">; type References = `references(${IgnorePaths, string | string[]>, "_type" | "_createdAt" | "_updatedAt" | "_rev" | "_key">})`; type IgnorePaths = Exclude; export type NumberComparisons = Comparison, TQueryConfig, ">" | ">=" | "<" | "<=">; type BooleanSuggestions = ValueOf<{ [Key in StringKeys>]: Key | `!${Key}`; }>; /** * Suggest literal values: */ type LiteralValue = TValue extends string ? `"${TValue}"` : TValue extends number | null ? TValue : TValue extends undefined ? null : never; /** * Make some literal suggestions, * like (string) or (number) */ type LiteralSuggestion = IsLiteral extends true ? never : TValue extends string ? "(string)" : TValue extends number ? "(number)" : never; type SuggestedKeysByType = ProjectionPathsByType, TValue> | LiteralSuggestion | LiteralValue; /** * Finds all (string) keys of TObject where the value matches the given TType */ export type KeysByType = StringKeys>; /** * Returns suggestions for ordering the results. * * @example * Order == * | "name" | "name asc" | "name desc" * | "price" | "price asc" | "price desc" * | "slug.current" | "slug.current asc" | "slug.current desc" */ export type Order = `${ProjectionPathsByType}${"" | " asc" | " desc"}`; type SortableTypes = string | number | boolean | null; export type CountableEntries = PickByKey>, `${string}[]`>; type PickByKey = { [P in Extract]: T[P]; }; export {}; }