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**.
37 lines (36 loc) • 1.35 kB
TypeScript
import { z } from "zod";
import { ParserFunction } from "../types/public-types";
declare const zodPrimitives: Pick<typeof z, "string" | "number" | "boolean" | "object" | "array" | "null" | "date" | "literal" | "union">;
declare const zodExtras: {
/**
* Zod's `.default()` method doesn't work well with GROQ,
* since GROQ only returns `null` and never `undefined`.
*
* So instead of chaining Zod's `default` method,
* use this `default` method instead.
*
* @example
* // Before:
* q.number().default(0)
* // After:
* q.default(q.number(), 0)
*/
default<TZodSchema extends z.ZodType<any, any, any>>(schema: TZodSchema, defaultValue: z.output<TZodSchema>): ParserFunction<z.input<TZodSchema> | null, z.output<TZodSchema>>;
/**
* Shorthand for accessing the current value for a slug.
*
* @example
* // Before:
* q.star.filterByType("product").project({
* slug: ["slug.current", z.string()],
* })
* // After:
* q.star.filterByType("product").project({
* slug: q.slug("slug"),
* })
*/
slug<TFieldName extends string>(fieldName: TFieldName): readonly [`${TFieldName}.current`, z.ZodString];
};
export declare const zodMethods: ZodMethods;
export type ZodMethods = typeof zodPrimitives & typeof zodExtras;
export {};