UNPKG

agnostic-query

Version:

Type-safe fluent builder for portable query schemas. Runtime-agnostic, database-agnostic — the same QuerySchema drives Drizzle, Kysely, db0, or raw SQL.

32 lines (31 loc) 871 B
import { multiLogicalWhereOps, unaryComparisonOps } from "./core/where.js"; import * as v from "valibot"; //#region src/valibot.ts const createWhereSchema = () => { const fieldSchema = v.pipe(v.any(), v.transform((input) => typeof input === "string" ? [input] : input), v.array(v.union([v.string(), v.number()]))); const unaryComparisonSchema = v.object({ field: fieldSchema, op: v.picklist(unaryComparisonOps), value: v.any() }); const multiComparisonSchema = v.object({ field: fieldSchema, op: v.literal("in"), values: v.array(v.any()) }); const schema = v.lazy(() => v.union([ unaryComparisonSchema, multiComparisonSchema, v.object({ op: v.picklist(multiLogicalWhereOps), conditions: v.array(schema) }), v.object({ op: v.literal("not"), condition: schema }) ])); return schema; }; //#endregion export { createWhereSchema };