| 63 | * @since 4.0.0 |
| 64 | */ |
| 65 | export const encodeString = <IE = never, Done = unknown>(): Channel.Channel< |
| 66 | Arr.NonEmptyReadonlyArray<string>, |
| 67 | IE | NdjsonError, |
| 68 | Done, |
| 69 | Arr.NonEmptyReadonlyArray<unknown>, |
| 70 | IE, |
| 71 | Done |
| 72 | > => |
| 73 | Channel.fromTransform((upstream, _scope) => |
| 74 | Effect.succeed(Effect.flatMap(upstream, (input) => { |
| 75 | try { |
| 76 | return Effect.succeed(Arr.of( |
| 77 | input.map((item) => { |
| 78 | const output = JSON.stringify(item) |
| 79 | if (output === undefined) { |
| 80 | throw new TypeError("Value cannot be represented as JSON") |
| 81 | } |
| 82 | return output |
| 83 | }).join("\n") + "\n" |
| 84 | )) |
| 85 | } catch (cause) { |
| 86 | return Effect.fail(new NdjsonError({ kind: "Pack", cause })) |
| 87 | } |
| 88 | })) |
| 89 | ) |
| 90 | |
| 91 | /** |
| 92 | * Creates a channel that encodes chunks of values as UTF-8 NDJSON bytes. |