MCPcopy Create free account
hub / github.com/Effect-TS/effect / encodeString

Function encodeString

packages/effect/src/encoding/Ndjson.ts:104–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102 * @since 4.0.0
103 */
104export const encodeString = <IE = never, Done = unknown>(): Channel.Channel<
105 Arr.NonEmptyReadonlyArray<string>,
106 IE | NdjsonError,
107 Done,
108 Arr.NonEmptyReadonlyArray<unknown>,
109 IE,
110 Done
111> =>
112 Channel.fromTransform((upstream, _scope) =>
113 Effect.succeed(Effect.flatMap(upstream, (input) => {
114 try {
115 return Effect.succeed(Arr.of(
116 input.map((item) => {
117 const output = JSON.stringify(item)
118 if (output === undefined) {
119 throw new TypeError("Value cannot be represented as JSON")
120 }
121 return output
122 }).join("\n") + "\n"
123 ))
124 } catch (cause) {
125 return Effect.fail(new NdjsonError({ kind: "Pack", cause }))
126 }
127 }))
128 )
129
130/**
131 * Creates a channel that encodes chunks of values as UTF-8 NDJSON bytes.

Callers 3

encodeFunction · 0.70
encodeSchemaStringFunction · 0.70
Ndjson.tsFile · 0.70

Calls 5

ofMethod · 0.65
failMethod · 0.65
succeedMethod · 0.45
joinMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected