Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
908 B · 30 lines
TypeScript
12345678910111213141516171819202122232425262728293031import * 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<T> = { ok: true; value: T } | { ok: false; error: RegistryError };
export function registryResult<T>( program: Effect.Effect<T, RegistryFailure>,): Promise<RegistryResult<T>> { return Effect.runPromise( program.pipe( Effect.catchDefect((error) => isRegistryFailure(error) ? Effect.fail(error) : Effect.die(error), ), Effect.match({ onSuccess: (value): RegistryResult<T> => ({ ok: true, value }), onFailure: (error): RegistryResult<T> => ({ ok: false, error: error.code, }), }), ), );}