-
-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ParseOptions argument to standardSchemaV1 #4567
Add ParseOptions argument to standardSchemaV1 #4567
Conversation
🦋 Changeset detectedLatest commit: 6295bb7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 36 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should make { errors: "all" }
the default. AFAIK, the spec doesn't specify how many issues should be raised by default.
I would prefer the default with export const standardSchemaV1 = <A, I>(
schema: Schema<A, I, never>,
overrideOptions?: AST.ParseOptions // Changed
): StandardSchemaV1<I, A> => {
const decodeUnknown = ParseResult.decodeUnknown(schema, { errors: "all" }) // Changed
return {
"~standard": {
version: 1,
vendor: "effect",
validate(value) {
const scheduler = new scheduler_.SyncScheduler()
const fiber = Effect.runFork(
Effect.matchEffect(decodeUnknown(value, overrideOptions), { // Changed
onFailure: makeStandardFailureFromParseIssue,
onSuccess: (value) => Effect.succeed({ value })
}),
{ scheduler }
)
scheduler.flush()
const exit = fiber.unsafePoll()
if (exit) {
return makeStandardResult(exit)
}
return new Promise((resolve) => {
fiber.addObserver((exit) => {
resolve(makeStandardResult(exit))
})
})
}
}
}
} |
Yes 👍 |
@gcanti I have changed the default to all errors with the possibility override the parse options. Also added an extra test for the override use case with |
Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Thanks @rehos |
Thank you @gcanti for your quick response and feedback. |
Type
Description
Add optional ParseOptions argument to standardSchemaV1. This will make form validation in form libraries like @tanstack/form more usable (i.e. display all errors to the user instead of just the first)