Skip to content

Commit

Permalink
fix(start): fix server function handling of standard schemas
Browse files Browse the repository at this point in the history
Some implementations (namely Valibot) still include the value key for failure results, which is technically still correct in structural typing (since an object type is a *minimum* requirement). What can actually be relied on is that result.issues is undefined if the result is valid, as this is in the spec.

Currently failure results from Valibot are still treated as success.
  • Loading branch information
EskiMojo14 authored Nov 24, 2024
1 parent 64e3b3c commit 73ded2e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/start/src/client/createServerFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import type {
ResolveAllValidators,
} from './createMiddleware'

//

export interface JsonResponse<TData> extends Response {
json: () => Promise<TData>
}
Expand Down Expand Up @@ -353,12 +351,13 @@ function execValidator(validator: AnyValidator, input: unknown): unknown {
if ('~standard' in validator) {
const result = validator['~standard'].validate(input)

if ('value' in result) return result.value

if (result instanceof Promise)
throw new Error('Async validation not supported')

throw new Error(JSON.stringify(result.issues, undefined, 2))
if (result.issues)
throw new Error(JSON.stringify(result.issues, undefined, 2))

return result.value
}

if ('parse' in validator) {
Expand Down

0 comments on commit 73ded2e

Please sign in to comment.