Stdio.ts
Stdio.ts overview
Section titled “Stdio.ts overview”Service contract for command-line arguments and standard input, output, and error output. It lets programs depend on standard I/O through the Effect environment instead of reading from or writing to global process handles directly.
The service exposes arguments as an Effect, stdout and stderr as Sinks
that accept strings or bytes, and stdin as a byte Stream. This module also
provides a constructor for service values and a small test layer with
overridable defaults.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”Creates a Stdio service implementation from the provided fields and
attaches the Stdio type identifier.
When to use
Use when you need to assemble a concrete Stdio service from command-line
arguments and standard I/O implementations.
Details
The returned service reuses the supplied fields unchanged and only adds the
Stdio type identifier; it does not create a Layer or provide defaults.
See
layerTestfor a test layer with default fields that can be overridden
Signature
declare const make: (options: Omit<Stdio, TypeId>) => StdioSince v4.0.0
layers
Section titled “layers”layerTest
Section titled “layerTest”Creates a test layer for Stdio.
When to use
Use to provide deterministic standard I/O in tests while overriding only the command-line arguments, input stream, or output sinks relevant to the case.
Details
Any provided fields override defaults. By default, arguments are empty, standard output and error are draining sinks, and standard input is an empty stream.
See
makefor constructing aStdioservice directly without aLayeror defaults
Signature
declare const layerTest: (impl: Partial<Stdio>) => Layer.Layer<Stdio>Since v4.0.0
models
Section titled “models”Stdio (interface)
Section titled “Stdio (interface)”Defines the service interface for process standard I/O.
When to use
Use to depend on command-line arguments and standard I/O through the Effect environment.
Details
The service provides command-line arguments, sinks for standard output and
standard error, and a stream of standard input bytes. I/O operations can fail
with PlatformError.
Signature
export interface Stdio { readonly [TypeId]: TypeId readonly args: Effect.Effect<ReadonlyArray<string>> stdout(options?: { readonly endOnDone?: boolean | undefined }): Sink.Sink<void, string | Uint8Array, never, PlatformError> stderr(options?: { readonly endOnDone?: boolean | undefined }): Sink.Sink<void, string | Uint8Array, never, PlatformError> readonly stdin: Stream.Stream<Uint8Array, PlatformError>}Since v4.0.0
services
Section titled “services”Service tag for process standard I/O.
When to use
Use when you need command-line arguments or standard I/O streams supplied by an effect’s environment.
See
makefor constructing aStdioservice directlylayerTestfor a test layer with defaults and overrides
Signature
declare const Stdio: Context.Service<Stdio, Stdio>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Runtime identifier stored on Stdio service implementations.
Details
This marker is part of the runtime representation of Stdio service
implementations.
Signature
declare const TypeId: "~effect/Stdio"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”String literal type used as the unique brand for the Stdio service.
When to use
Use to type the runtime identifier stored on Stdio service implementations.
Signature
type TypeId = "~effect/Stdio"Since v4.0.0