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

Function asserts

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

Source from the content-addressed store, hash-verified

225 * @since 4.0.0
226 */
227export function asserts<S extends Schema.Constraint, I>(schema: S, input: I): asserts input is I & S["Type"] {
228 const ast = SchemaAST.toType(schema.ast)
229 const result = CompilerRegistry.resolve(ast).parser(input, SchemaAST.defaultParseOptions)
230 const exit = Effect.runSyncExit(parserResult<S["Type"], never>(result, input))
231 if (Exit.isFailure(exit)) {
232 const issue = InternalSchemaCause.getSchemaIssueOrThrow(
233 exit.cause,
234 "Assertion adapter can only throw schema issues"
235 )
236 throw new Error("Schema validation failed", { cause: issue })
237 }
238}
239
240/**
241 * Creates an effectful decoder for `unknown` input.

Callers

nothing calls this directly

Calls 3

parserResultFunction · 0.85
resolveMethod · 0.80
parserMethod · 0.45

Tested by

no test coverage detected