import { NuxtErrorDetails } from "../app/error.js"; import { RequestEvent } from "nuxt/schema"; //#region src/server/validate.d.ts /** A validation failure, as a Standard Schema reports it. */ interface ValidationIssue { readonly message: string; readonly path?: ReadonlyArray | undefined; } type StandardResult = { readonly value: Output; readonly issues?: undefined; } | { readonly issues: ReadonlyArray; }; /** A schema implementing [Standard Schema](https://standardschema.dev), as Zod, Valibot and ArkType do. */ interface StandardSchema { readonly '~standard': { readonly version: 1; readonly vendor: string; readonly validate: (value: unknown) => StandardResult | Promise>; readonly types?: { readonly input: unknown; readonly output: Output; } | undefined; }; } type SchemaOutput = NonNullable['output']; /** * What a validator function returns: the validated value, `true` to accept * the input as it is, or `false` to reject it. Returning nothing accepts the * input, and throwing rejects it with the error thrown. * * @since 4.6.0 */ export type ValidateResult = T | true | false | void; interface ValidateOptions { /** The error to reject invalid input with, in place of a `400` carrying the issues as `data.issues`. */ onError?: (result: { issues: ReadonlyArray; }) => NuxtErrorDetails; } /** * Read the query string of the request, validated with a Standard Schema or a * validator function. Invalid input is rejected with a `400` whose `data` * carries the issues, unless `onError` returns a different error. * * @example * ```ts * import { z } from 'zod' * * export default defineEventHandler(async (event) => { * const { page } = await getValidatedQuery(event, z.object({ page: z.coerce.number() })) * return { page } * }) * ``` * * @since 4.6.0 */ export declare function getValidatedQuery(event: Pick & { url?: URL; }, validate: S, options?: ValidateOptions): Promise>; export declare function getValidatedQuery(event: Pick & { url?: URL; }, validate: (data: Record) => ValidateResult | Promise>, options?: ValidateOptions): Promise; /** * Read and parse the request body as {@link readBody} does, validated with a * Standard Schema or a validator function. Invalid input is rejected with a * `400` whose `data` carries the issues, unless `onError` returns a different * error. * * @since 4.6.0 */ export declare function readValidatedBody(event: Pick, validate: S, options?: ValidateOptions): Promise>; export declare function readValidatedBody(event: Pick, validate: (data: unknown) => ValidateResult | Promise>, options?: ValidateOptions): Promise; //#endregion export {};