-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getDotPath, safeParseAsync, type GenericSchema, type GenericSchemaAsync } from "valibot"; | ||
import type { Infer, ValidationAdapter } from "./types"; | ||
|
||
class ValibotAdapter implements ValidationAdapter { | ||
async validate<S extends GenericSchema | GenericSchemaAsync>(schema: S, data: unknown) { | ||
const result = await safeParseAsync(schema, data); | ||
|
||
if (result.success) { | ||
return { | ||
success: true, | ||
data: result.output as Infer<S>, | ||
} as const; | ||
} | ||
|
||
return { | ||
success: false, | ||
issues: result.issues.map((issue) => ({ | ||
message: issue.message, | ||
path: getDotPath(issue)?.split("."), | ||
})), | ||
} as const; | ||
} | ||
} | ||
|
||
export function valibotAdapter() { | ||
return new ValibotAdapter(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.