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

Function encodeString

packages/effect/src/unstable/encoding/Ndjson.ts:65–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63 * @since 4.0.0
64 */
65export 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.

Callers 3

encodeFunction · 0.70
encodeSchemaStringFunction · 0.70
Ndjson.tsFile · 0.70

Calls 5

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

Tested by

no test coverage detected