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

Function Cause

packages/effect/src/Schema.ts:11358–11390  ·  view source on GitHub ↗
(error: E, defect: D)

Source from the content-addressed store, hash-verified

11356 * @since 3.10.0
11357 */
11358export function Cause<E extends Constraint, D extends Constraint>(error: E, defect: D): Cause<E, D> {
11359 const schema = declareConstructor<Cause_.Cause<E["Type"]>, Cause_.Cause<E["Encoded"]>, CauseIso<E, D>>()(
11360 [error, defect],
11361 ([error, defect]) => {
11362 const failures = ArraySchema(CauseReason(error, defect))
11363 return (input, ast, options) => {
11364 if (!Cause_.isCause(input)) {
11365 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11366 }
11367 return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
11368 onSuccess: Cause_.fromReasons,
11369 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "reasons", issue, input, options)
11370 })
11371 }
11372 },
11373 {
11374 representation: {
11375 id: "effect/schema/Cause",
11376 payload: null
11377 },
11378 expected: "Cause",
11379 toCodec: ([error, defect]) =>
11380 link<Cause_.Cause<E["Encoded"]>>()(
11381 ArraySchema(CauseReason(error, defect)),
11382 SchemaTransformation.transform({
11383 decode: Cause_.fromReasons,
11384 encode: ({ reasons: failures }) => failures
11385 })
11386 )
11387 }
11388 )
11389 return make(schema.ast, { error, defect })
11390}
11391
11392// -----------------------------------------------------------------------------
11393// Chunk schemas

Callers 1

ExitFunction · 0.70

Calls 6

declareConstructorFunction · 0.70
CauseReasonFunction · 0.70
linkFunction · 0.70
makeFunction · 0.70
failMethod · 0.65
transformMethod · 0.65

Tested by

no test coverage detected