@effect/platform 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import * as Brand from "@effect/data/Brand";
2
+ import * as Chunk from "@effect/data/Chunk";
3
+ import { Tag } from "@effect/data/Context";
4
+ import * as Effect from "@effect/io/Effect";
5
+ import * as Sink from "@effect/stream/Sink";
6
+ import * as Stream from "@effect/stream/Stream";
7
+ /** @internal */
8
+ export const ProcessTypeId = /*#__PURE__*/Symbol.for("@effect/platform/Process");
9
+ /** @internal */
10
+ export const ExitCode = /*#__PURE__*/Brand.nominal();
11
+ /** @internal */
12
+ export const ProcessId = /*#__PURE__*/Brand.nominal();
13
+ /** @internal */
14
+ export const CommandExecutor = /*#__PURE__*/Tag();
15
+ /** @internal */
16
+ export const makeExecutor = start => {
17
+ const stream = command => Stream.flatMap(process => process.stdout)(Stream.fromEffect(start(command)));
18
+ const streamLines = (command, encoding) => {
19
+ const decoder = new TextDecoder(encoding);
20
+ return Stream.splitLines(Stream.mapChunks(stream(command), Chunk.map(bytes => decoder.decode(bytes))));
21
+ };
22
+ return {
23
+ start,
24
+ exitCode: command => Effect.flatMap(start(command), process => process.exitCode),
25
+ stream,
26
+ string: (command, encoding = "utf-8") => {
27
+ const decoder = new TextDecoder(encoding);
28
+ return Effect.map(bytes => decoder.decode(bytes))(Effect.flatMap(process => Stream.run(process.stdout, collectUint8Array))(start(command)));
29
+ },
30
+ lines: (command, encoding = "utf-8") => {
31
+ return Effect.map(Chunk.toReadonlyArray)(Stream.runCollect(streamLines(command, encoding)));
32
+ },
33
+ streamLines
34
+ };
35
+ };
36
+ const collectUint8Array = /*#__PURE__*/Sink.foldLeftChunks( /*#__PURE__*/new Uint8Array(), (bytes, chunk) => Chunk.reduce(chunk, bytes, (acc, curr) => {
37
+ const newArray = new Uint8Array(acc.length + curr.length);
38
+ newArray.set(acc);
39
+ newArray.set(curr, acc.length);
40
+ return newArray;
41
+ }));
42
+ //# sourceMappingURL=commandExecutor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commandExecutor.mjs","names":["Brand","Chunk","Tag","Effect","Sink","Stream","ProcessTypeId","Symbol","for","ExitCode","nominal","ProcessId","CommandExecutor","makeExecutor","start","stream","command","flatMap","process","stdout","fromEffect","streamLines","encoding","decoder","TextDecoder","splitLines","mapChunks","map","bytes","decode","exitCode","string","run","collectUint8Array","lines","toReadonlyArray","runCollect","foldLeftChunks","Uint8Array","chunk","reduce","acc","curr","newArray","length","set"],"sources":["../../src/internal/commandExecutor.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,oBAAoB;AAC3C,OAAO,KAAKC,KAAK,MAAM,oBAAoB;AAC3C,SAASC,GAAG,QAAQ,sBAAsB;AAE1C,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAE3C,OAAO,KAAKC,IAAI,MAAM,qBAAqB;AAC3C,OAAO,KAAKC,MAAM,MAAM,uBAAuB;AAE/C;AACA,OAAO,MAAMC,aAAa,gBAAmCC,MAAM,CAACC,GAAG,CACrE,0BAA0B,CACO;AAEnC;AACA,OAAO,MAAMC,QAAQ,gBAAGT,KAAK,CAACU,OAAO,EAA6B;AAElE;AACA,OAAO,MAAMC,SAAS,gBAAGX,KAAK,CAACU,OAAO,EAA+B;AAErE;AACA,OAAO,MAAME,eAAe,gBAAGV,GAAG,EAAoC;AAEtE;AACA,OAAO,MAAMW,YAAY,GAAIC,KAAgD,IAAsC;EACjH,MAAMC,MAAM,GAAgDC,OAAO,IAG/DX,MAAM,CAACY,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACC,MAAM,CAAC,CAD3Cd,MAAM,CAACe,UAAU,CAACN,KAAK,CAACE,OAAO,CAAC,CAAC,CAElC;EACH,MAAMK,WAAW,GAAoDA,CAACL,OAAO,EAAEM,QAAQ,KAAI;IACzF,MAAMC,OAAO,GAAG,IAAIC,WAAW,CAACF,QAAQ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,IAAIL,UAAU,CAACG,GAAG,CAACG,MAAM,GAAGF,IAAI,CAACE,MAAM,CAAC;EACzDD,QAAQ,CAACE,GAAG,CAACJ,GAAG,CAAC;EACjBE,QAAQ,CAACE,GAAG,CAACH,IAAI,EAAED,GAAG,CAACG,MAAM,CAAC;EAC9B,OAAOD,QAAQ;AACjB,CAAC,CAAC,CACL"}
@@ -28,7 +28,7 @@ const stream = (file, {
28
28
  offset = Size(0)
29
29
  } = {}) => Stream.bufferChunks(Stream.unfoldEffect(offset, position => {
30
30
  if (bytesToRead !== undefined && bytesToRead <= position - offset) {
31
- return Effect.succeedNone();
31
+ return Effect.succeed(Option.none());
32
32
  }
33
33
  const toRead = bytesToRead !== undefined && bytesToRead - (position - offset) < chunkSize ? bytesToRead - (position - offset) : chunkSize;
34
34
  return Effect.map(Option.map(buf => [buf, Size(position + BigInt(buf.length))]))(file.readAlloc(toRead, {
@@ -1 +1 @@
1
- {"version":3,"file":"fileSystem.mjs","names":["Tag","Option","Effect","Sink","Stream","tag","Size","bytes","BigInt","make","impl","of","stream","path","options","unwrapScoped","map","file","open","flag","sink","forEach","_","writeAll","bufferSize","bytesToRead","chunkSize","offset","bufferChunks","unfoldEffect","position","undefined","succeedNone","toRead","buf","length","readAlloc"],"sources":["../../src/internal/fileSystem.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAG,QAAQ,sBAAsB;AAE1C,OAAO,KAAKC,MAAM,MAAM,qBAAqB;AAC7C,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAE3C,OAAO,KAAKC,IAAI,MAAM,qBAAqB;AAC3C,OAAO,KAAKC,MAAM,MAAM,uBAAuB;AAE/C;AACA,OAAO,MAAMC,GAAG,gBAAGL,GAAG,EAAc;AAEpC;AACA,OAAO,MAAMM,IAAI,GAAIC,KAAsB,IAAK,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAc,GAAGC,MAAM,CAACD,KAAK,CAAU;AAEnH;AACA,OAAO,MAAME,IAAI,GA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,SAAS;EAEb,OAEExB,MAAM,CAACc,GAAG,CACRf,MAAM,CAACe,GAAG,CAAEkB,GAAG,IAAK,CAACA,GAAG,EAAE5B,IAAI,CAACwB,QAAQ,GAAGtB,MAAM,CAAC0B,GAAG,CAACC,MAAM,CAAC,CAAC,CAAU,CAAC,CACzE,CAHDlB,IAAI,CAACmB,SAAS,CAACH,MAAe,EAAE;IAAEN,MAAM,EAAEG;EAAQ,CAAE,CAAC;AAKzD,CAAC,CAAC,EACFN,UAAU,CACX"}
1
+ {"version":3,"file":"fileSystem.mjs","names":["Tag","Option","Effect","Sink","Stream","tag","Size","bytes","BigInt","make","impl","of","stream","path","options","unwrapScoped","map","file","open","flag","sink","forEach","_","writeAll","bufferSize","bytesToRead","chunkSize","offset","bufferChunks","unfoldEffect","position","undefined","succeed","none","toRead","buf","length","readAlloc"],"sources":["../../src/internal/fileSystem.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAG,QAAQ,sBAAsB;AAE1C,OAAO,KAAKC,MAAM,MAAM,qBAAqB;AAC7C,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAE3C,OAAO,KAAKC,IAAI,MAAM,qBAAqB;AAC3C,OAAO,KAAKC,MAAM,MAAM,uBAAuB;AAE/C;AACA,OAAO,MAAMC,GAAG,gBAAGL,GAAG,EAAc;AAEpC;AACA,OAAO,MAAMM,IAAI,GAAIC,KAAsB,IAAK,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAc,GAAGC,MAAM,CAACD,KAAK,CAAU;AAEnH;AACA,OAAO,MAAME,IAAI,GAAIC,IAAyC,IAAgB;EAC5E,OAAOL,GAAG,CAACM,EAAE,CAAC;IACZ,GAAGD,IAAI;IACPE,MAAM,EAAEA,CAACC,IAAI,EAAEC,OAAO,KAIlBV,MAAM,CAACW,YAAY,CADnBb,MAAM,CAACc,GAAG,CAAEC,IAAI,IAAKL,MAAM,CAACK,IAAI,EAAEH,OAAO,CAAC,CAAC,CAD3CJ,IAAI,CAAC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CAACH,MAAe,EAAE;IAAEP,MAAM,EAAEG;EAAQ,CAAE,CAAC;AAKzD,CAAC,CAAC,EACFN,UAAU,CACX"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@effect/platform",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/effect-ts/platform.git"
8
8
  },
9
9
  "dependencies": {
10
- "@effect/data": "^0.12.8",
11
- "@effect/io": "^0.26.1",
12
- "@effect/stream": "^0.22.1",
10
+ "@effect/data": "^0.14.1",
11
+ "@effect/io": "^0.32.1",
12
+ "@effect/stream": "^0.26.0",
13
13
  "path-browserify": "^1.0.1"
14
14
  },
15
15
  "publishConfig": {
package/src/Command.ts ADDED
@@ -0,0 +1,278 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { HashMap } from "@effect/data/HashMap"
5
+ import type { Option } from "@effect/data/Option"
6
+ import type { NonEmptyReadonlyArray } from "@effect/data/ReadonlyArray"
7
+ import type { Effect } from "@effect/io/Effect"
8
+ import type { CommandExecutor, ExitCode, Process } from "@effect/platform/CommandExecutor"
9
+ import type { PlatformError } from "@effect/platform/Error"
10
+ import * as internal from "@effect/platform/internal/command"
11
+ import type { Sink } from "@effect/stream/Sink"
12
+ import type { Stream } from "@effect/stream/Stream"
13
+
14
+ /**
15
+ * @since 1.0.0
16
+ */
17
+ export const CommandTypeId: unique symbol = internal.CommandTypeId
18
+
19
+ /**
20
+ * @since 1.0.0
21
+ */
22
+ export type CommandTypeId = typeof CommandTypeId
23
+
24
+ /**
25
+ * @since 1.0.0
26
+ * @category models
27
+ */
28
+ export type Command = StandardCommand | PipedCommand
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ */
33
+ export declare namespace Command {
34
+ /**
35
+ * @since 1.0.0
36
+ * @category models
37
+ */
38
+ export interface Proto {
39
+ readonly [CommandTypeId]: CommandTypeId
40
+ }
41
+ /**
42
+ * Configures the pipe that is established between the parent and child
43
+ * processes' `stdin` stream.
44
+ *
45
+ * @since 1.0.0
46
+ * @category models
47
+ */
48
+ export type Input = CommandInput
49
+ /**
50
+ * Configures the pipes that are established between the parent and child
51
+ * processes `stderr` and `stdout` streams.
52
+ *
53
+ * @since 1.0.0
54
+ * @category models
55
+ */
56
+ export type Output = CommandOutput
57
+ }
58
+
59
+ /**
60
+ * Configures the pipe that is established between the parent and child
61
+ * processes' `stdin` stream.
62
+ *
63
+ * @since 1.0.0
64
+ * @category models
65
+ */
66
+ export type CommandInput = Stream<never, PlatformError, Uint8Array>
67
+
68
+ /**
69
+ * Configures the pipes that are established between the parent and child
70
+ * processes `stderr` and `stdout` streams.
71
+ *
72
+ * @since 1.0.0
73
+ * @category models
74
+ */
75
+ export type CommandOutput = "inherit" | "pipe" | Sink<never, never, Uint8Array, never, Uint8Array>
76
+
77
+ /**
78
+ * @since 1.0.0
79
+ * @category models
80
+ */
81
+ export interface StandardCommand extends Command.Proto {
82
+ readonly _tag: "StandardCommand"
83
+ readonly command: string
84
+ readonly args: ReadonlyArray<string>
85
+ readonly env: HashMap<string, string>
86
+ readonly cwd: Option<string>
87
+ readonly stdin: Option<Command.Input>
88
+ readonly stdout: Command.Output
89
+ readonly stderr: Command.Output
90
+ readonly gid: Option<number>
91
+ readonly uid: Option<number>
92
+ }
93
+
94
+ /**
95
+ * @since 1.0.0
96
+ * @category models
97
+ */
98
+ export interface PipedCommand extends Command.Proto {
99
+ readonly _tag: "PipedCommand"
100
+ readonly left: Command
101
+ readonly right: Command
102
+ }
103
+
104
+ /**
105
+ * Returns `true` if the specified value is a `Command`, otherwise returns
106
+ * `false`.
107
+ *
108
+ * @since 1.0.0
109
+ * @category refinements
110
+ */
111
+ export const isCommand: (u: unknown) => u is Command = internal.isCommand
112
+
113
+ /**
114
+ * Specify the environment variables that will be used when running this command.
115
+ *
116
+ * @since 1.0.0
117
+ * @category combinators
118
+ */
119
+ export const env: {
120
+ (environment: Record<string, string>): (self: Command) => Command
121
+ (self: Command, environment: Record<string, string>): Command
122
+ } = internal.env
123
+
124
+ /**
125
+ * Returns the exit code of the command after the process has completed
126
+ * execution.
127
+ *
128
+ * @since 1.0.0
129
+ * @category execution
130
+ */
131
+ export const exitCode: (self: Command) => Effect<CommandExecutor, PlatformError, ExitCode> = internal.exitCode
132
+
133
+ /**
134
+ * Feed a string to standard input (default encoding of UTF-8).
135
+ *
136
+ * @since 1.0.0
137
+ * @category combinators
138
+ */
139
+ export const feed: {
140
+ (input: string): (self: Command) => Command
141
+ (self: Command, input: string): Command
142
+ } = internal.feed
143
+
144
+ /**
145
+ * Flatten this command to a non-empty array of standard commands.
146
+ *
147
+ * * For a `StandardCommand`, this simply returns a `1` element array
148
+ * * For a `PipedCommand`, all commands in the pipe will be extracted out into
149
+ * a array from left to right
150
+ *
151
+ * @since 1.0.0
152
+ * @category combinators
153
+ */
154
+ export const flatten: (self: Command) => NonEmptyReadonlyArray<StandardCommand> = internal.flatten
155
+
156
+ /**
157
+ * Runs the command returning the output as an array of lines with the specified
158
+ * encoding.
159
+ *
160
+ * @since 1.0.0
161
+ * @category execution
162
+ */
163
+ export const lines: (
164
+ command: Command,
165
+ encoding?: string
166
+ ) => Effect<CommandExecutor, PlatformError, ReadonlyArray<string>> = internal.lines
167
+
168
+ /**
169
+ * Create a command with the specified process name and an optional list of
170
+ * arguments.
171
+ *
172
+ * @since 1.0.0
173
+ * @category constructors
174
+ */
175
+ export const make: (command: string, ...args: Array<string>) => Command = internal.make
176
+
177
+ /**
178
+ * Pipe one command to another command from left to right.
179
+ *
180
+ * Conceptually, the equivalent of piping one shell command to another:
181
+ *
182
+ * ```sh
183
+ * command1 | command2
184
+ * ```
185
+ *
186
+ * @since 1.0.0
187
+ * @category combinators
188
+ */
189
+ export const pipeTo: {
190
+ (into: Command): (self: Command) => Command
191
+ (self: Command, into: Command): Command
192
+ } = internal.pipeTo
193
+
194
+ /**
195
+ * Start running the command and return a handle to the running process.
196
+ *
197
+ * @since 1.0.0
198
+ * @category execution
199
+ */
200
+ export const start: (command: Command) => Effect<CommandExecutor, PlatformError, Process> = internal.start
201
+
202
+ /**
203
+ * Start running the command and return the output as a `Stream`.
204
+ *
205
+ * @since 1.0.0
206
+ * @category execution
207
+ */
208
+ export const stream: (command: Command) => Stream<CommandExecutor, PlatformError, Uint8Array> = internal.stream
209
+
210
+ /**
211
+ * Runs the command returning the output as an stream of lines with the
212
+ * specified encoding.
213
+ *
214
+ * @since 1.0.0
215
+ * @category execution
216
+ */
217
+ export const streamLines: (command: Command) => Stream<CommandExecutor, PlatformError, string> = internal.streamLines
218
+
219
+ /**
220
+ * Runs the command returning the entire output as a string with the
221
+ * specified encoding.
222
+ *
223
+ * If an encoding is not specified, the encoding will default to `utf-8`.
224
+ *
225
+ * @since 1.0.0
226
+ * @category execution
227
+ */
228
+ export const string: {
229
+ (encoding?: string): (command: Command) => Effect<CommandExecutor, PlatformError, string>
230
+ (command: Command, encoding?: string): Effect<CommandExecutor, PlatformError, string>
231
+ } = internal.string
232
+
233
+ /**
234
+ * Specify the standard error stream for a command.
235
+ *
236
+ * @since 1.0.0
237
+ * @category combinators
238
+ */
239
+ export const stderr: {
240
+ (stderr: Command.Output): (self: Command) => Command
241
+ (self: Command, stderr: Command.Output): Command
242
+ } = internal.stderr
243
+
244
+ /**
245
+ * Specify the standard input stream for a command.
246
+ *
247
+ * @since 1.0.0
248
+ * @category combinators
249
+ */
250
+ export const stdin: {
251
+ (stdin: Command.Input): (self: Command) => Command
252
+ (self: Command, stdin: Command.Input): Command
253
+ } = internal.stdin
254
+
255
+ /**
256
+ * Specify the standard output stream for a command.
257
+ *
258
+ * @since 1.0.0
259
+ * @category combinators
260
+ */
261
+ export const stdout: {
262
+ (stdout: Command.Output): (self: Command) => Command
263
+ (self: Command, stdout: Command.Output): Command
264
+ } = internal.stdout
265
+
266
+ /**
267
+ * Set the working directory that will be used when this command will be run.
268
+ *
269
+ * For piped commands, the working directory of each command will be set to the
270
+ * specified working directory.
271
+ *
272
+ * @since 1.0.0
273
+ * @category combinators
274
+ */
275
+ export const workingDirectory: {
276
+ (cwd: string): (self: Command) => Command
277
+ (self: Command, cwd: string): Command
278
+ } = internal.workingDirectory
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type * as Brand from "@effect/data/Brand"
5
+ import type { Tag } from "@effect/data/Context"
6
+ import type { Effect } from "@effect/io/Effect"
7
+ import type { Command } from "@effect/platform/Command"
8
+ import type { PlatformError } from "@effect/platform/Error"
9
+ import * as internal from "@effect/platform/internal/commandExecutor"
10
+ import type { Sink } from "@effect/stream/Sink"
11
+ import type { Stream } from "@effect/stream/Stream"
12
+
13
+ /**
14
+ * @since 1.0.0
15
+ * @category models
16
+ */
17
+ export interface CommandExecutor {
18
+ /**
19
+ * Returns the exit code of the command after the process has completed
20
+ * execution.
21
+ */
22
+ readonly exitCode: (command: Command) => Effect<never, PlatformError, ExitCode>
23
+ /**
24
+ * Start running the command and return a handle to the running process.
25
+ */
26
+ readonly start: (command: Command) => Effect<never, PlatformError, Process>
27
+ /**
28
+ * Runs the command returning the entire output as a string with the
29
+ * specified encoding.
30
+ *
31
+ * If an encoding is not specified, the encoding will default to `utf-8`.
32
+ */
33
+ readonly string: (command: Command, encoding?: string) => Effect<never, PlatformError, string>
34
+ /**
35
+ * Runs the command returning the entire output as an array of lines.
36
+ *
37
+ * If an encoding is not specified, the encoding will default to `utf-8`.
38
+ */
39
+ readonly lines: (command: Command, encoding?: string) => Effect<never, PlatformError, ReadonlyArray<string>>
40
+ /**
41
+ * Runs the command returning the output as a `Stream`.
42
+ */
43
+ readonly stream: (command: Command) => Stream<never, PlatformError, Uint8Array>
44
+ /**
45
+ * Runs the command returning the output as a `Stream` of lines.
46
+ */
47
+ readonly streamLines: (command: Command, encoding?: string) => Stream<never, PlatformError, string>
48
+ }
49
+
50
+ /**
51
+ * @since 1.0.0
52
+ * @category tags
53
+ */
54
+ export const CommandExecutor: Tag<CommandExecutor, CommandExecutor> = internal.CommandExecutor
55
+
56
+ /**
57
+ * @since 1.0.0
58
+ * @category symbols
59
+ */
60
+ export const ProcessTypeId: unique symbol = internal.ProcessTypeId
61
+
62
+ /**
63
+ * @since 1.0.0
64
+ * @category symbols
65
+ */
66
+ export type ProcessTypeId = typeof ProcessTypeId
67
+
68
+ /**
69
+ * @since 1.0.0
70
+ * @category models
71
+ */
72
+ export interface Process {
73
+ readonly [ProcessTypeId]: ProcessTypeId
74
+ /**
75
+ * The process identifier.
76
+ */
77
+ readonly pid: ProcessId
78
+ /**
79
+ * Waits for the process to exit and returns the `ExitCode` of the command
80
+ * that was run.
81
+ */
82
+ readonly exitCode: Effect<never, PlatformError, ExitCode>
83
+ /**
84
+ * Returns `true` if the process is still running, otherwise returns `false`.
85
+ */
86
+ readonly isRunning: Effect<never, PlatformError, boolean>
87
+ /**
88
+ * Kills the running process with the provided signal.
89
+ *
90
+ * If no signal is provided, the signal will defaults to `SIGTERM`.
91
+ */
92
+ readonly kill: (signal?: Signal) => Effect<never, PlatformError, void>
93
+ /**
94
+ * The standard error stream of the process.
95
+ */
96
+ readonly stderr: Stream<never, PlatformError, Uint8Array>
97
+ /**
98
+ * The standard input sink of the process.
99
+ */
100
+ readonly stdin: Sink<never, PlatformError, Uint8Array, never, void>
101
+ /**
102
+ * The standard output stream of the process.
103
+ */
104
+ readonly stdout: Stream<never, PlatformError, Uint8Array>
105
+ }
106
+
107
+ /**
108
+ * @since 1.0.0
109
+ * @category models
110
+ */
111
+ export type ProcessId = Brand.Branded<number, "ProcessId">
112
+
113
+ /**
114
+ * @since 1.0.0
115
+ */
116
+ export namespace Process {
117
+ /**
118
+ * @since 1.0.0
119
+ * @category models
120
+ */
121
+ export type Id = ProcessId
122
+ }
123
+
124
+ /**
125
+ * @since 1.0.0
126
+ * @category models
127
+ */
128
+ export type Signal =
129
+ | "SIGABRT"
130
+ | "SIGALRM"
131
+ | "SIGBUS"
132
+ | "SIGCHLD"
133
+ | "SIGCONT"
134
+ | "SIGFPE"
135
+ | "SIGHUP"
136
+ | "SIGILL"
137
+ | "SIGINT"
138
+ | "SIGIO"
139
+ | "SIGIOT"
140
+ | "SIGKILL"
141
+ | "SIGPIPE"
142
+ | "SIGPOLL"
143
+ | "SIGPROF"
144
+ | "SIGPWR"
145
+ | "SIGQUIT"
146
+ | "SIGSEGV"
147
+ | "SIGSTKFLT"
148
+ | "SIGSTOP"
149
+ | "SIGSYS"
150
+ | "SIGTERM"
151
+ | "SIGTRAP"
152
+ | "SIGTSTP"
153
+ | "SIGTTIN"
154
+ | "SIGTTOU"
155
+ | "SIGUNUSED"
156
+ | "SIGURG"
157
+ | "SIGUSR1"
158
+ | "SIGUSR2"
159
+ | "SIGVTALRM"
160
+ | "SIGWINCH"
161
+ | "SIGXCPU"
162
+ | "SIGXFSZ"
163
+ | "SIGBREAK"
164
+ | "SIGLOST"
165
+ | "SIGINFO"
166
+
167
+ /**
168
+ * @since 1.0.0
169
+ * @category models
170
+ */
171
+ export type ExitCode = Brand.Branded<number, "ExitCode">
172
+
173
+ /**
174
+ * @since 1.0.0
175
+ * @category constructors
176
+ */
177
+ export const ExitCode: Brand.Brand.Constructor<ExitCode> = internal.ExitCode
178
+
179
+ /**
180
+ * @since 1.0.0
181
+ * @category constructors
182
+ */
183
+ export const ProcessId: Brand.Brand.Constructor<Process.Id> = internal.ProcessId
184
+
185
+ /**
186
+ * @since 1.0.0
187
+ * @category constructors
188
+ */
189
+ export const makeExecutor: (
190
+ start: (command: Command) => Effect<never, PlatformError, Process>
191
+ ) => CommandExecutor = internal.makeExecutor
package/src/Error.ts CHANGED
@@ -33,7 +33,7 @@ export namespace PlatformError {
33
33
  export interface Base extends Data.Case {
34
34
  readonly [PlatformErrorTypeId]: typeof PlatformErrorTypeId
35
35
  readonly _tag: string
36
- readonly module: "FileSystem" | "Path"
36
+ readonly module: "Command" | "FileSystem" | "Path"
37
37
  readonly method: string
38
38
  readonly message: string
39
39
  }