docs: add README and end-user guides for all modules
This commit is contained in:
53
docs/validation.md
Normal file
53
docs/validation.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Validation
|
||||
|
||||
TypeBox-based schema validation helpers for operation inputs and outputs.
|
||||
|
||||
## validateOrThrow
|
||||
|
||||
Validates a value against a TypeBox schema. Throws on failure with formatted error messages:
|
||||
|
||||
```ts
|
||||
import { validateOrThrow } from "@alkdev/operations";
|
||||
|
||||
validateOrThrow(schema, input, "Input validation failed for task.create");
|
||||
```
|
||||
|
||||
Used internally by `registry.execute()` to validate inputs before running handlers.
|
||||
|
||||
## collectErrors
|
||||
|
||||
Returns an array of errors without throwing:
|
||||
|
||||
```ts
|
||||
import { collectErrors } from "@alkdev/operations";
|
||||
|
||||
const errors = collectErrors(schema, value);
|
||||
// [{ path: "/title", message: "Expected string" }, ...]
|
||||
```
|
||||
|
||||
Used internally by `registry.execute()` to warn on output validation failures.
|
||||
|
||||
## assertIsSchema
|
||||
|
||||
Validates that a value is a TypeBox schema. Throws if not:
|
||||
|
||||
```ts
|
||||
import { assertIsSchema } from "@alkdev/operations";
|
||||
|
||||
assertIsSchema(maybeSchema, "task.create input");
|
||||
```
|
||||
|
||||
Useful when receiving schemas from external sources (JSON, OpenAPI) before passing them to the registry.
|
||||
|
||||
## formatValueErrors
|
||||
|
||||
Formats an iterable of `{ path, message }` errors into a human-readable string:
|
||||
|
||||
```ts
|
||||
import { formatValueErrors } from "@alkdev/operations";
|
||||
|
||||
const formatted = formatValueErrors(errors);
|
||||
// " - /title: Expected string\n - /priority: Expected union member"
|
||||
```
|
||||
|
||||
Accepts an optional indent prefix (default `" - "`).
|
||||
Reference in New Issue
Block a user