import * as Effect from "effect/Effect"; import { isRegistryFailure, type RegistryError, type RegistryFailure, } from "./installation-errors.ts"; // Only plain values cross Durable Object RPC; expected errors retain their // declared codes, and defects still abort native storage transactions. export type RegistryResult = { ok: true; value: T } | { ok: false; error: RegistryError }; export function registryResult( program: Effect.Effect, ): Promise> { return Effect.runPromise( program.pipe( Effect.catchDefect((error) => isRegistryFailure(error) ? Effect.fail(error) : Effect.die(error), ), Effect.match({ onSuccess: (value): RegistryResult => ({ ok: true, value }), onFailure: (error): RegistryResult => ({ ok: false, error: error.code, }), }), ), ); }