runtime/deps.ts

Shared dependency interfaces for runtime operations.

Small composable interfaces that functions accept for only the capabilities they need. Both Deno and Node implementations satisfy all these interfaces via RuntimeDeps.

Declarations
#

14 declarations

view source

CommandDeps
#

runtime/deps.ts view source

CommandDeps

Command execution.

run_command

Run a command and return the result. Never throws — failures surface as success: false.

options.cwd sets the child's working directory. options.signal aborts the child when the signal fires. options.timeout_ms kills the child after the given duration and returns timed_out: true on the result.

type ( cmd: string, args: Array<string>, options?: RunCommandOptions, ) => Promise<CommandResult>

CommandResult
#

runtime/deps.ts view source

CommandResult

Result of executing a command.

timed_out is present only when timeout_ms was passed in RunCommandOptions and the process was killed after exceeding the timeout. Callers that pass timeout_ms should check this flag to distinguish timeout from exit-code failure.

success

type boolean

code

type number

stdout

type string

stderr

type string

timed_out

type boolean

EnvDeps
#

runtime/deps.ts view source

EnvDeps

Environment variable access.

env_get

Get an environment variable value.

type (name: string) => string | undefined

env_set

Set an environment variable.

type (name: string, value: string) => void

FetchDeps
#

runtime/deps.ts view source

FetchDeps

HTTP fetch capability.

fetch

Fetch a URL. Same signature as the global fetch.

type typeof globalThis.fetch

FsReadDeps
#

runtime/deps.ts view source

FsReadDeps

File system read operations.

stat

Get file/directory stats, or null if path doesn't exist.

type (path: string) => Promise<StatResult | null>

read_text_file

Read a file as text. Throws if the file does not exist.

type (path: string) => Promise<string>

read_file

Read a file as bytes. Throws if the file does not exist.

type (path: string) => Promise<Uint8Array>

read_text_from_offset

Read text starting from a byte offset. Throws if the file does not exist.

Returns content, bytes_read, and file_size so callers can detect truncation (when file_size < offset) and tail incrementally without re-reading the whole file.

type (path: string, offset: number) => Promise<ReadTextFromOffsetResult>

readdir

List directory entries (names, not full paths). Throws if the directory does not exist.

type (path: string) => Promise<Array<string>>

FsRemoveDeps
#

runtime/deps.ts view source

FsRemoveDeps

File system remove operations.

remove

Remove a file or directory.

type (path: string, options?: {recursive?: boolean}) => Promise<void>

FsWriteDeps
#

runtime/deps.ts view source

FsWriteDeps

File system write operations.

mkdir

Create a directory.

type (path: string, options?: {recursive?: boolean}) => Promise<void>

write_text_file

Write text to a file.

type (path: string, content: string) => Promise<void>

write_file

Write bytes to a file.

type (path: string, data: Uint8Array) => Promise<void>

rename

Rename (move) a file.

type (old_path: string, new_path: string) => Promise<void>

LogDeps
#

runtime/deps.ts view source

LogDeps

Warning/diagnostic output.

warn

Log a warning message.

type (...args: Array<unknown>) => void

ProcessDeps
#

ReadTextFromOffsetResult
#

runtime/deps.ts view source

ReadTextFromOffsetResult

Result of reading text from a byte offset.

content

Decoded text content read from the offset.

type string

bytes_read

Number of bytes actually read.

type number

file_size

Total file size at the time of the read (for truncation detection).

type number

RunCommandOptions
#

runtime/deps.ts view source

RunCommandOptions

Options for run_command.

cwd

Working directory for the child process.

type string

signal

AbortSignal to terminate the child process.

type AbortSignal

timeout_ms

Kill the process and return timed_out: true after this many milliseconds.

type number

RuntimeDeps
#

runtime/deps.ts view source

RuntimeDeps

Full runtime capabilities returned by create_deno_runtime or create_node_runtime.

Extends all *Deps interfaces with additional app-level capabilities. Functions should accept narrow *Deps interfaces, not this full type — this type is for the wiring layer that creates and passes the runtime.

inheritance

env_all

Get all environment variables.

type () => Record<string, string>

args

CLI arguments passed to the program.

type ReadonlyArray<string>
readonly

cwd

Get current working directory.

type () => string

run_command_inherit

Run a command with inherited stdout/stderr (output goes directly to terminal).

type (cmd: string, args: Array<string>) => Promise<number>

StatResult
#

TerminalDeps
#

runtime/deps.ts view source

TerminalDeps

Terminal I/O operations.

stdout_write

Write bytes to stdout.

type (data: Uint8Array) => Promise<number>

stdin_read

Read bytes from stdin, or null on EOF.

type (buffer: Uint8Array) => Promise<number | null>