MCPcopy
hub / github.com/Effect-TS/effect / makeExecutor

Function makeExecutor

packages/platform/src/internal/commandExecutor.ts:28–60  ·  view source on GitHub ↗
(start: _CommandExecutor.CommandExecutor["start"])

Source from the content-addressed store, hash-verified

26
27/** @internal */
28export const makeExecutor = (start: _CommandExecutor.CommandExecutor["start"]): _CommandExecutor.CommandExecutor => {
29 const stream: _CommandExecutor.CommandExecutor["stream"] = (command) =>
30 Stream.unwrapScoped(Effect.map(start(command), (process) => process.stdout))
31 const streamLines: _CommandExecutor.CommandExecutor["streamLines"] = (command, encoding) => {
32 const decoder = new TextDecoder(encoding)
33 return Stream.splitLines(
34 Stream.mapChunks(stream(command), Chunk.map((bytes) => decoder.decode(bytes)))
35 )
36 }
37 return {
38 [TypeId]: TypeId,
39 start,
40 exitCode: (command) => Effect.scoped(Effect.flatMap(start(command), (process) => process.exitCode)),
41 stream,
42 string: (command, encoding = "utf-8") => {
43 const decoder = new TextDecoder(encoding)
44 return pipe(
45 start(command),
46 Effect.flatMap((process) => Stream.run(process.stdout, collectUint8Array)),
47 Effect.map((bytes) => decoder.decode(bytes)),
48 Effect.scoped
49 )
50 },
51 lines: (command, encoding = "utf-8") => {
52 return pipe(
53 streamLines(command, encoding),
54 Stream.runCollect,
55 Effect.map(Chunk.toArray)
56 )
57 },
58 streamLines
59 }
60}
61
62const collectUint8Array: Sink.Sink<Uint8Array, Uint8Array> = Sink.foldLeftChunks(
63 new Uint8Array(),

Callers

nothing calls this directly

Calls 6

decodeMethod · 0.80
startFunction · 0.70
pipeFunction · 0.70
streamLinesFunction · 0.70
mapMethod · 0.65
runMethod · 0.45

Tested by

no test coverage detected