( effect: Effect.Effect<A, ParseIssue, R>, ast: AST.AST, actual: unknown, options: InternalOptions | undefined )
| 1607 | const dropRightRefinement = (ast: AST.AST): AST.AST => AST.isRefinement(ast) ? dropRightRefinement(ast.from) : ast |
| 1608 | |
| 1609 | const handleForbidden = <A, R>( |
| 1610 | effect: Effect.Effect<A, ParseIssue, R>, |
| 1611 | ast: AST.AST, |
| 1612 | actual: unknown, |
| 1613 | options: InternalOptions | undefined |
| 1614 | ): Effect.Effect<A, ParseIssue, R> => { |
| 1615 | // If effects are allowed, return the original effect |
| 1616 | if (options?.isEffectAllowed === true) { |
| 1617 | return effect |
| 1618 | } |
| 1619 | |
| 1620 | // If the effect is already an Either, return it directly |
| 1621 | if (isEither(effect)) { |
| 1622 | return effect |
| 1623 | } |
| 1624 | |
| 1625 | // Otherwise, attempt to execute the effect synchronously |
| 1626 | const scheduler = new Scheduler.SyncScheduler() |
| 1627 | const fiber = Effect.runFork(effect as Effect.Effect<A, ParseIssue>, { scheduler }) |
| 1628 | scheduler.flush() |
| 1629 | const exit = fiber.unsafePoll() |
| 1630 | |
| 1631 | if (exit) { |
| 1632 | if (Exit.isSuccess(exit)) { |
| 1633 | // If the effect successfully resolves, wrap the value in a Right |
| 1634 | return Either.right(exit.value) |
| 1635 | } |
| 1636 | const cause = exit.cause |
| 1637 | if (Cause.isFailType(cause)) { |
| 1638 | // The effect executed synchronously but failed due to a ParseIssue |
| 1639 | return Either.left(cause.error) |
| 1640 | } |
| 1641 | // The effect executed synchronously but failed due to a defect (e.g., a missing dependency) |
| 1642 | return Either.left(new Forbidden(ast, actual, Cause.pretty(cause))) |
| 1643 | } |
| 1644 | |
| 1645 | // The effect could not be resolved synchronously, meaning it performs async work |
| 1646 | return Either.left( |
| 1647 | new Forbidden( |
| 1648 | ast, |
| 1649 | actual, |
| 1650 | "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work" |
| 1651 | ) |
| 1652 | ) |
| 1653 | } |
| 1654 | |
| 1655 | const compare = ([a]: [number, ...Array<unknown>], [b]: [number, ...Array<unknown>]) => a > b ? 1 : a < b ? -1 : 0 |
| 1656 |
no test coverage detected