@@ -3,6 +3,7 @@ import { type ErrorDetails, HTTPError } from "../../error.ts";
33import type { ServerRequest } from "srvx" ;
44import type {
55 StandardSchemaV1 ,
6+ FailureResult ,
67 InferOutput ,
78 Issue ,
89} from "./standard-schema.ts" ;
@@ -19,7 +20,7 @@ export type ValidateFunction<
1920export type ValidateIssues = ReadonlyArray < Issue > ;
2021export type ValidateError =
2122 | ( ( ) => ErrorDetails )
22- | ( ( issues : ValidateIssues ) => ErrorDetails ) ;
23+ | ( ( result : FailureResult ) => ErrorDetails ) ;
2324
2425/**
2526 * Validates the given data using the provided validation function.
@@ -34,7 +35,7 @@ export async function validateData<Schema extends StandardSchemaV1>(
3435 data : unknown ,
3536 fn : Schema ,
3637 options ?: {
37- onError ?: ( issues : ValidateIssues ) => ErrorDetails ;
38+ onError ?: ( result : FailureResult ) => ErrorDetails ;
3839 } ,
3940) : Promise < InferOutput < Schema > > ;
4041export async function validateData < T > (
@@ -55,7 +56,7 @@ export async function validateData<T>(
5556 const result = await fn [ "~standard" ] . validate ( data ) ;
5657 if ( result . issues ) {
5758 const errorDetails = options ?. onError
58- ? options . onError ( result . issues )
59+ ? options . onError ( result )
5960 : {
6061 message : "Validation failed" ,
6162 issues : result . issues ,
@@ -98,7 +99,7 @@ export function validatedRequest<
9899 body ?: RequestBody ;
99100 headers ?: RequestHeaders ;
100101 onError ?: (
101- issues : ValidateIssues ,
102+ result : FailureResult ,
102103 source : "headers" | "body" ,
103104 ) => ErrorDetails ;
104105 } ,
@@ -132,7 +133,7 @@ export function validatedRequest<
132133 . then ( ( result ) => {
133134 if ( result . issues ) {
134135 const errorDetails = validate . onError
135- ? validate . onError ( result . issues , "body" )
136+ ? validate . onError ( result , "body" )
136137 : {
137138 message : "Validation failed" ,
138139 issues : result . issues ,
@@ -158,7 +159,7 @@ export function validatedURL(
158159 url : URL ,
159160 validate : {
160161 query ?: StandardSchemaV1 ;
161- onError ?: ( issues : ValidateIssues , source : "query" ) => ErrorDetails ;
162+ onError ?: ( result : FailureResult , source : "query" ) => ErrorDetails ;
162163 } ,
163164) : URL {
164165 if ( ! validate . query ) {
@@ -183,15 +184,15 @@ function syncValidate<Source extends "headers" | "query", T = unknown>(
183184 type : Source ,
184185 data : unknown ,
185186 fn : StandardSchemaV1 < T > ,
186- onError ?: ( issues : ValidateIssues , source : Source ) => ErrorDetails ,
187+ onError ?: ( result : FailureResult , source : Source ) => ErrorDetails ,
187188) : T {
188189 const result = fn [ "~standard" ] . validate ( data ) ;
189190 if ( result instanceof Promise ) {
190191 throw new TypeError ( `Asynchronous validation is not supported for ${ type } ` ) ;
191192 }
192193 if ( result . issues ) {
193194 const errorDetails = onError
194- ? onError ( result . issues , type )
195+ ? onError ( result , type )
195196 : {
196197 message : "Validation failed" ,
197198 issues : result . issues ,
0 commit comments