(error: E, defect: D)
| 11356 | * @since 3.10.0 |
| 11357 | */ |
| 11358 | export 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 |
no test coverage detected