/** * Argument validators for function definitions. * * These serve double duty: * 1. Runtime validation — reject bad input before the handler runs. * 2. Type inference — TypeScript infers handler arg types from validators. * * @example * ```typescript * import { mutation, v } from "@pylonsync/functions"; * * export default mutation({ * args: { * name: v.string(), * age: v.optional(v.number()), * tags: v.array(v.string()), * }, * async handler(ctx, args) { * // args is typed as { name: string, age?: number, tags: string[] } * }, * }); * ``` */ import type { AnyValidator, InferArgs, InferValidator, Validator, ValidatorSchema } from "./types"; export declare const v: { /** String value. */ string: () => Validator; /** Number (float64). Same as `v.float()`. */ number: () => Validator; /** * 64-bit float. Alias for `v.number()` so the validator API matches the * schema DSL (which uses `field.float()`). Prefer this in new code. */ float: () => Validator; /** Integer. */ int: () => Validator; /** Boolean. Same as `v.bool()`. */ boolean: () => Validator; /** * Boolean. Alias for `v.boolean()` so the validator API matches the * schema DSL (which uses `field.bool()`). Prefer this in new code. */ bool: () => Validator; /** * ISO-8601 datetime string. Validates the shape of a string value; the * stored column type comes from the schema (`field.datetime()`). */ datetime: () => Validator; /** * Richtext string. Same runtime validation as `v.string()`; named * explicitly so server functions read as the matching schema type. */ richtext: () => Validator; /** ID reference to another entity. */ id: (table: string) => Validator; /** Null value. */ null: () => Validator; /** Array of values. */ array: (items: TValidator) => Validator[], false>; /** Object with typed fields. */ object: (fields: TSchema) => Validator, false>; /** Optional value (may be omitted). */ optional: (inner: TValidator) => Validator, true>; /** Union of multiple types. */ union: (...variants: TVariants) => Validator, false>; /** Exact literal value. */ literal: (value: TValue) => Validator; /** Any valid JSON value. */ any: () => Validator; /** * Arbitrary JSON value (object, array, or scalar). The validator-side * match for `field.json()` — accepts any JSON shape but types the arg * as `unknown`, so handlers narrow before use instead of getting `any`. */ json: () => Validator; }; export declare function validateArgs(args: unknown, schema: Record): { valid: boolean; errors: string[]; };