valibot 1.1.0
const schema = v.object({
first: v.string(),
second: v.pipe(v.string(), v.nonEmpty()),
});
console.log(schema["~standard"].validate({ first: "", second: "" }))
This code gives such output:
{
"value": {
"first": "",
"second": ""
},
"typed": true,
"issues": [
{
"kind": "validation",
"type": "non_empty",
"input": "",
"expected": "!0",
"received": "0",
"message": "Invalid length: Expected !0 but received 0",
"path": [
{
"type": "object",
"origin": "value",
"input": {
"first": "",
"second": ""
},
"key": "second",
"value": ""
}
]
}
]
}
But actually such output is violating standard schema contract because value and issues cannot exists at a time
export type Result<Output> = SuccessResult<Output> | FailureResult;
/** The result interface if validation succeeds. */
export interface SuccessResult<Output> {
/** The typed output value. */
readonly value: Output;
/** The non-existent issues. */
readonly issues?: undefined; // <--- we should have `issues: undefined` when `value` is defined
}
/** The result interface if validation fails. */
export interface FailureResult {
/** The issues of failed validation. */
readonly issues: ReadonlyArray<Issue>;
}
Such mismatch can lead (and has already led to in my case) to errors in the code that checks for errors based on the absence of value as a result of validation.
valibot
1.1.0This code gives such output:
But actually such output is violating standard schema contract because
valueandissuescannot exists at a timeSuch mismatch can lead (and has already led to in my case) to errors in the code that checks for errors based on the absence of
valueas a result of validation.