MCPcopy Create free account
hub / github.com/Effect-TS/effect / asserts

Function asserts

packages/effect/src/SchemaParser.ts:203–213  ·  view source on GitHub ↗
(schema: S, input: I)

Source from the content-addressed store, hash-verified

201 * @since 4.0.0
202 */
203export 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.

Callers

nothing calls this directly

Calls 2

asExitFunction · 0.85
runFunction · 0.70

Tested by

no test coverage detected