import type * as runtime from "@cloudflare/workers-types"; import * as Predicate from "effect/Predicate"; import * as Stream from "effect/Stream"; type ReplaceEffectStream = T extends Stream.Stream ? runtime.ReadableStream : T; /** * If the value is an Effect stream, converts it to a ReadableStream. * Otherwise, returns the value unchanged. */ export function replaceEffectStream(value: T): ReplaceEffectStream { if (isEffectStream(value)) { return Stream.toReadableStream(value) as ReplaceEffectStream; } return value as ReplaceEffectStream; } const isEffectStream = (value: unknown): value is Stream.Stream => Predicate.hasProperty(value, "~effect/Stream");