-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Pipe to emit a single issue #618
Comments
We could introduce an export function naturalNumber(message = "Natural value expected.") {
return v.abortPipeEarly(v.pipe(v.number(message), v.integer(message), v.minValue(1, message)));
} An alternative could be a general export function naturalNumber(message = "Natural value expected.") {
return v.config(v.pipe(v.number(message), v.integer(message), v.minValue(1, message)), { abortPipeEarly: true });
} What do you think is best? Until this functionality is part of the library, you can write this method yourself: export function abortPipeEarly<TSchema extends v.GenericSchema>(
schema: TSchema
): TSchema {
return {
...schema,
_run(dataset, config) {
return schema._run(dataset, { ...config, abortPipeEarly: true });
},
};
}
export function config<TSchema extends v.GenericSchema>(
schema: TSchema,
config: Omit<v.Config<v.InferIssue<TSchema>>, 'skipPipe'>
): TSchema {
return {
...schema,
_run(dataset, config_) {
return schema._run(dataset, { ...config_, ...config });
},
};
} |
Thanks for confirming that the use case is valid. I suppose between the two options you suggest, |
v0.31.0-rc.10 with |
As a developer, I would like to create reusable schemas, presumably with the new pipe function, that only emit a single issue to the parse result.
delivers:
I'd somehow like baz to have only 1 issue. Note that
parse(..., { abortPipeEarly: true })
is not really an option, as it's global to the whole parse and also it's controlled by the user (and not by the schema author).Of course I could always fallback to
custom()
but thenpipe()
kinda loses its value.Some ideas:
The text was updated successfully, but these errors were encountered: