| 1 | import type * as runtime from "@cloudflare/workers-types"; |
| 2 | import * as Predicate from "effect/Predicate"; |
| 3 | import * as Stream from "effect/Stream"; |
| 4 | |
| 5 | type ReplaceEffectStream<T> = |
| 6 | T extends Stream.Stream<any> ? runtime.ReadableStream<any> : T; |
| 7 | |
| 8 | /** |
| 9 | * If the value is an Effect stream, converts it to a ReadableStream. |
| 10 | * Otherwise, returns the value unchanged. |
| 11 | */ |
| 12 | export function replaceEffectStream<T>(value: T): ReplaceEffectStream<T> { |
| 13 | if (isEffectStream(value)) { |
| 14 | return Stream.toReadableStream(value) as ReplaceEffectStream<T>; |
| 15 | } |
| 16 | return value as ReplaceEffectStream<T>; |
| 17 | } |
| 18 | |
| 19 | const isEffectStream = (value: unknown): value is Stream.Stream<any> => |
| 20 | Predicate.hasProperty(value, "~effect/Stream"); |