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.

view source

Declarations
#

17 declarations

CommandDeps
#

runtime/deps.ts view source

CommandDeps import type {CommandDeps} from '@fuzdev/fuz_app/runtime/deps.js';

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: string[], options?: RunCommandOptions | undefined): Promise<CommandResult>

cmd

type string

args

type string[]

options?

optional
returns Promise<CommandResult>

CommandResult
#

runtime/deps.ts view source

CommandResult import type {CommandResult} from '@fuzdev/fuz_app/runtime/deps.js';

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 import type {EnvDeps} from '@fuzdev/fuz_app/runtime/deps.js';

Environment variable access.

env_get

Get an environment variable value.

type (name: string): string | undefined

name

type string
returns string | undefined

env_set

Set an environment variable.

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

name

type string

value

type string
returns void

FetchDeps
#

runtime/deps.ts view source

FetchDeps import type {FetchDeps} from '@fuzdev/fuz_app/runtime/deps.js';

HTTP fetch capability.

fetch

Fetch a URL. Same signature as the global fetch.

type { (input: URL | RequestInfo, init?: RequestInit | undefined): Promise<Response>; (input: string | URL | Request, init?: RequestInit | undefined): Promise<...>; }

FsReadDeps
#

runtime/deps.ts view source

FsReadDeps import type {FsReadDeps} from '@fuzdev/fuz_app/runtime/deps.js';

File system read operations.

stat

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

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

path

type string
returns Promise<StatResult | null>

read_text_file

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

type (path: string): Promise<string>

path

type string
returns Promise<string>

read_file

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

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

path

type string
returns Promise<Uint8Array<ArrayBufferLike>>

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>

path

type string

offset

type number
returns Promise<ReadTextFromOffsetResult>

readdir

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

type (path: string): Promise<string[]>

path

type string
returns Promise<string[]>

FsRemoveDeps
#

runtime/deps.ts view source

FsRemoveDeps import type {FsRemoveDeps} from '@fuzdev/fuz_app/runtime/deps.js';

File system remove operations.

remove

Remove a file or directory.

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

path

type string

options?

type { recursive?: boolean | undefined; }
optional
returns Promise<void>

FsSecureReadDeps
#

runtime/deps.ts view source

FsSecureReadDeps import type {FsSecureReadDeps} from '@fuzdev/fuz_app/runtime/deps.js';

Hardened read for secret files (bootstrap tokens, keys) — the TS twin of the Rust spine's fuz_sys::secure_file::load_secure_file.

read_secure_file

Read a small secret file with fail-loud checks: rejects symlinks, non-regular files (FIFO, device, directory — real runtimes only; the mock has no file types), any group/other-accessible mode (must be 0600/0400; skipped where POSIX modes don't apply), and files over a 4 KiB cap. Permission checks run on the open descriptor where the platform allows, so the file can't be swapped between check and read. Throws on any refusal — a refused secret must never degrade to an empty read.

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

path

type string
returns Promise<Uint8Array<ArrayBufferLike>>

FsStreamDeps
#

runtime/deps.ts view source

FsStreamDeps import type {FsStreamDeps} from '@fuzdev/fuz_app/runtime/deps.js';

Streaming file I/O — read a file as a byte stream, or write a byte stream to a file, both bounded in memory (peak ≈ one chunk, not the whole file).

Kept separate from FsReadDeps / FsWriteDeps so the whole-buffer read_file / write_file consumers and their partial test stubs are unaffected; only the full runtime factories implement these. Used for GB-scale artifact transfer (the fuzf file get / put path) where buffering the whole file would OOM the client.

read_file_stream

Open a file as a ReadableStream of its bytes — read incrementally, so peak memory is one chunk rather than the whole file. Throws if the file does not exist. Use as a streaming upload body or for an incremental hash pass over a large file.

type (path: string): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>

path

type string
returns Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>

write_file_stream

Write a ReadableStream of bytes to a file, consuming it with backpressure (peak memory is one chunk). Creates or truncates path. Throws on any I/O error; a partially-written file may remain, so callers needing atomicity write to a temp path then rename.

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

path

type string

data

type ReadableStream<Uint8Array<ArrayBufferLike>>
returns Promise<void>

FsWriteDeps
#

runtime/deps.ts view source

FsWriteDeps import type {FsWriteDeps} from '@fuzdev/fuz_app/runtime/deps.js';

File system write operations.

mkdir

Create a directory. mode applies at creation (no-op where modes don't apply).

type (path: string, options?: { recursive?: boolean | undefined; mode?: number | undefined; } | undefined): Promise<void>

path

type string

options?

type { recursive?: boolean | undefined; mode?: number | undefined; }
optional
returns Promise<void>

write_text_file

Write text to a file. See WriteFileOptions for mode / exclusive.

type (path: string, content: string, options?: WriteFileOptions | undefined): Promise<void>

path

type string

content

type string

options?

optional
returns Promise<void>

write_file

Write bytes to a file.

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

path

type string

data

type Uint8Array<ArrayBufferLike>
returns Promise<void>

rename

Rename (move) a file.

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

old_path

type string

new_path

type string
returns Promise<void>

fsync

Flush a file's data to stable storage (fsync). Call on a temp file after writing it and *before* rename-ing it into place when the renamed path is later served without re-verification — otherwise a host crash after the rename can surface a torn/zero file as authentic content. The fact disk CAS (db/fact_disk_storage.ts) is the one such path; it twins the Rust fuz_fact §fsync posture (data-sync before rename; the parent-dir fsync stays deliberately waived — a lost dirent is regenerable under content addressing). Real runtimes open the path, fsync, and close; create_mock_runtime no-ops (it models no durability).

type (path: string): Promise<void>

path

type string
returns Promise<void>

LogDeps
#

runtime/deps.ts view source

LogDeps import type {LogDeps} from '@fuzdev/fuz_app/runtime/deps.js';

Warning/diagnostic output.

warn

Log a warning message.

type (...args: unknown[]): void

args

type unknown[]
returns void

ProcessDeps
#

runtime/deps.ts view source

ProcessDeps import type {ProcessDeps} from '@fuzdev/fuz_app/runtime/deps.js';

Process lifecycle.

exit

Exit the process with a code.

type (code: number): never

code

type number
returns never

ReadTextFromOffsetResult
#

runtime/deps.ts view source

ReadTextFromOffsetResult import type {ReadTextFromOffsetResult} from '@fuzdev/fuz_app/runtime/deps.js';

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 import type {RunCommandOptions} from '@fuzdev/fuz_app/runtime/deps.js';

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 import type {RuntimeDeps} from '@fuzdev/fuz_app/runtime/deps.js';

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>

returns Record<string, string>

args

CLI arguments passed to the program.

type readonly string[]

readonly

cwd

Get current working directory.

type (): string

returns string

run_command_inherit

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

type (cmd: string, args: string[]): Promise<number>

cmd

type string

args

type string[]
returns Promise<number>

StatResult
#

runtime/deps.ts view source

StatResult import type {StatResult} from '@fuzdev/fuz_app/runtime/deps.js';

Result of a stat operation.

is_file

type boolean

is_directory

type boolean

size?

Byte length of a regular file. Meaningful only when is_file is true; for directories it is runtime-defined (real OS stat reports the directory entry's on-disk size, not 0 — only create_mock_runtime reports 0). Populated by every runtime factory (create_node_runtime / create_deno_runtime / create_mock_runtime); optional so loose test stubs that only assert is_file / is_directory don't have to supply it. Callers that need an exact size (e.g. a streaming upload's Content-Length) read it from a real runtime, where it is always present.

type number

mtime_ms?

Last-modification time in epoch milliseconds, when the runtime reports it. Populated by create_node_runtime / create_deno_runtime; create_mock_runtime omits it (so a mock-backed sweep treats every temp as unknown-age and never reaps). Optional so loose test stubs that only assert is_file / is_directory don't have to supply it. The orphan-temp sweep (db/fact_disk_storage.ts) reads it to age out stale .tmp spill files.

type number

TerminalDeps
#

runtime/deps.ts view source

TerminalDeps import type {TerminalDeps} from '@fuzdev/fuz_app/runtime/deps.js';

Terminal I/O operations.

stdout_write

Write bytes to stdout.

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

data

type Uint8Array<ArrayBufferLike>
returns Promise<number>

stdin_read

Read bytes from stdin, or null on EOF.

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

buffer

type Uint8Array<ArrayBufferLike>
returns Promise<number | null>

WriteFileOptions
#

runtime/deps.ts view source

WriteFileOptions import type {WriteFileOptions} from '@fuzdev/fuz_app/runtime/deps.js';

Options for FsWriteDeps.write_text_file.

mode?

POSIX mode applied at creation (e.g. 0o600). Creation-time only — an existing file keeps its mode (pair with exclusive when the mode must hold). No-op where modes don't apply (mock runtime, Windows).

type number

exclusive?

Fail if the path already exists (O_EXCL). Load-bearing for secret files: without it a crash-leftover temp file is reopened O_TRUNC and keeps its old (possibly permissive) mode, since mode only applies at creation.

type boolean

Imported by
#