| 201 | * @since 4.0.0 |
| 202 | */ |
| 203 | export function asserts<S extends Schema.Constraint, I>(schema: S, input: I): asserts input is I & S["Type"] { |
| 204 | const parser = asExit(run<S["Type"], never>(SchemaAST.toType(schema.ast))) |
| 205 | const exit = parser(input, SchemaAST.defaultParseOptions) |
| 206 | if (Exit.isFailure(exit)) { |
| 207 | const issue = InternalSchemaCause.getSchemaIssueOrThrow( |
| 208 | exit.cause, |
| 209 | "Assertion adapter can only throw schema issues" |
| 210 | ) |
| 211 | throw new Error("Schema validation failed", { cause: issue }) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Creates an effectful decoder for `unknown` input. |