@orveth/validation
v0.1.1
Published
Discriminated validation results and adapter-friendly validators.
Maintainers
Readme
@orveth/validation
Package name
@orveth/validation
Purpose
Defines validation result types and a Validator interface that external schema libraries can adapt to without becoming a hard dependency of the ecosystem.
Installation
pnpm add @orveth/validationBasic usage
import { validationFailure, validationSuccess, type Validator } from "@orveth/validation";
const validator: Validator<unknown, string> = {
validate(input) {
if (typeof input !== "string" || input.trim().length === 0) {
return validationFailure([{ path: "", message: "Expected a non-empty string" }]);
}
return validationSuccess(input);
},
};API overview
Exports:
ValidationIssue,ValidationSuccess,ValidationFailure,ValidationResult<T>Validator<TInput, TOutput>- Constructors:
validationSuccess,validationFailure
Design notes
- A successful validation returns
{ ok: true, value: T }. - A failed validation returns
{ ok: false, issues: ValidationIssue[] }. - This package does not throw by itself; callers decide how failures map to HTTP responses or
ValidationError.
Error behavior
This package does not define transport-level errors. Higher layers may translate issues into @orveth/errors ValidationError when appropriate.
TypeScript notes
This package ships .d.ts declarations and is authored in TypeScript strict mode.
License
Released under the MIT License. See the repository LICENSE file.
