char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
38d7f6c
main
1import { SymbolFor } from "ext:core/primordials" ; 2import * as subprocess from "ext:process/main.js" ; 3import * as net from "ext:net/main.js" ; 4import * as file from "ext:file/main.js" ; 5import * as environment from "./env.js" ; 6import * as consoleInspection from "ext:console/inspect.js" ; 7import * as authority from "./pledge.js" ; 8import * as host from "./host.js" ; 9import * as http from "ext:http/main.js" ; 10import * as httpFile from "ext:http/file.js" ; 11import * as stdio from "ext:stdio/main.js" ; 12 13// Non-constructible class values still expose ordinary function reflection. 14type ClassStatics = Omit < Function , "prototype" | typeof Symbol . hasInstance >; 15 16export const avril :unique symbol = SymbolFor ( "runtime:avril" ) as typeof avril ; 17 18export interface GrantRestriction < T > { 19readonly allow ?:readonly T []; 20readonly deny ?:readonly T []; 21} 22 23export interface Pledge { 24readonly net ?:false | GrantRestriction < string >; 25readonly env ?:false | GrantRestriction < string >; 26readonly sys ?:false | GrantRestriction < string >; 27readonly read ?:false | GrantRestriction < string | URL >; 28readonly write ?:false | GrantRestriction < string | URL >; 29readonly jsExec ?:false | GrantRestriction < string | URL >; 30readonly run ?:false | GrantRestriction < string | URL >; 31readonly ffi ?:false | GrantRestriction < string | URL >; 32} 33 34/** Irreversibly narrows authority; omitted categories are unchanged. */ 35export const pledge :( restrictions :Pledge ) => void = authority . pledge ; 36 37/** Runtime-local environment; named operations require authority for that variable. */ 38export const env :Readonly <{ 39get ( name :string ) :string | undefined ; 40has ( name :string ) :boolean ; 41set ( name :string , value :string ) :void ; 42delete ( name :string ) :void ; 43/** Returns an independent, null-prototype snapshot of permitted variables only. */ 44toObject () :Record < string , string >; 45}> = environment . env ; 46 47/** This process. `pid` and `runtime` need no authority; `cwd()` requires read authority for the working directory, and the other methods each require sys authority for their own name ("hostname", "osRelease", "uptime", "loadavg"). Denied calls throw PermissionDenied. */ 48export const process :Readonly <{ 49pid :number ; 50/** Frozen script arguments, excluding runtime options and entry modules; needs no authority. REPL and test sessions accept arguments after `--`. Workers inherit them. */ 51args :readonly string []; 52cwd () :string ; 53hostname () :string ; 54osRelease () :string ; 55/** Seconds since the system booted. */ 56uptime () :number ; 57/** 1, 5, and 15 minute load averages; [0, 0, 0] on Windows. */ 58loadavg () :[ number , number , number ]; 59}> = host . process ; 60 61/** The avril build running this process; needs no authority. */ 62export const runtime :Readonly <{ 63os :"linux" | "macos" | "windows" ; 64arch :"x86_64" | "aarch64" ; 65/** avril version. */ 66version :string ; 67/** V8 version. */ 68v8 :string ; 69}> = host . runtime ; 70 71export interface InspectOptions { 72/** Nesting levels to expand; `null` or `Infinity` expand as far as avril allows. Defaults to 3. */ 73depth ?:number | null ; 74/** Wrap values in ANSI color escapes. */ 75colors ?:boolean ; 76} 77 78/** 79* Formats a value the way `console.log` and the REPL show it, without invoking getters. 80* 81* An object customizes its format with a method keyed by 82* `Symbol.for("runtime.avril.inspect")`, called as `method(inspect, options)`. 83* A string result is used verbatim; any other result is inspected in its place. 84* Inspecting the object again from inside its own method uses the default format. 85*/ 86export const inspect :( value :unknown , options ?:InspectOptions ) => string = consoleInspection . inspect ; 87 88export interface TcpAddr { 89readonly transport :"tcp" ; 90readonly hostname :string ; 91readonly port :number ; 92} 93 94export interface UnixAddr { 95readonly transport :"unix" ; 96readonly path :string | null ; 97} 98 99export interface UdpAddr { 100readonly transport :"udp" ; 101readonly hostname :string ; 102readonly port :number ; 103} 104export type StreamAddr = TcpAddr | UnixAddr ; 105export type Addr = StreamAddr | UdpAddr ; 106 107export interface ServeInfo < A extends StreamAddr = StreamAddr > { 108readonly remoteAddr :A ; 109} 110 111export type ServeHandler < A extends StreamAddr = StreamAddr > = ( 112request :Request , 113info :ServeInfo < A >, 114) => Response | Promise < Response >; 115 116export interface ServeOptions { 117path ?:never ; 118/** Defaults to 127.0.0.1. */ 119hostname ?:string ; 120/** Defaults to 8000; 0 selects an available port. */ 121port ?:number ; 122/** Aborting stops the listener and closes active connections immediately. */ 123signal ?:AbortSignal ; 124onListen ?:( addr :TcpAddr ) => void ; 125/** Handler errors default to a 500 response. */ 126onError ?:( error :unknown ) => Response | Promise < Response >; 127} 128 129export interface UnixServeOptions extends Omit < ServeOptions , "hostname" | "port" | "path" | "onListen" > { 130path :string ; 131hostname ?:never ; 132port ?:never ; 133onListen ?:( addr :UnixAddr ) => void ; 134} 135 136export interface ServeModule { 137fetch :ServeHandler ; 138} 139 140export interface HttpServer < A extends StreamAddr = StreamAddr > { 141readonly addr :A ; 142readonly finished :Promise < void >; 143/** Stops accepting connections and waits for active responses. */ 144shutdown () :Promise < void >; 145} 146 147/** Serves HTTP/1.1; TCP requires net authority, Unix sockets require write authority. */ 148export const serve :{ 149( handler :ServeHandler < TcpAddr >) :HttpServer < TcpAddr >; 150( options :ServeOptions , handler :ServeHandler < TcpAddr >) :HttpServer < TcpAddr >; 151( options :UnixServeOptions , handler :ServeHandler < UnixAddr >) :HttpServer < UnixAddr >; 152} = http . serve ; 153 154export interface ServeFileOptions { 155/** Additional headers; Content-Type and ETag override the defaults. */ 156headers ?:HeadersInit ; 157/** Transfers ownership of a supplied FileHandle. Defaults to true; ignored for paths. */ 158consume ?:boolean ; 159} 160 161/** Streams a regular file with conditional and single-range support; requires read authority. */ 162export const serveFile :( 163request :Request , 164source :string | URL | FileHandle , 165options ?:ServeFileOptions , 166) => Promise < Response > = httpFile . serveFile ; 167 168export const upgradeWebSocket :( 169request :Request , 170options ?:{ protocol ?:string }, 171) => { socket :WebSocket ; response :Response } = http . upgradeWebSocket ; 172 173export interface TcpListenOptions { 174transport ?:"tcp" ; 175hostname ?:string ; 176port :number ; 177} 178export interface TcpConnectOptions extends TcpListenOptions { 179signal ?:AbortSignal ; 180} 181export interface UnixListenOptions { 182transport :"unix" ; 183path :string ; 184hostname ?:never ; 185port ?:never ; 186} 187export interface UnixConnectOptions extends UnixListenOptions { 188signal ?:AbortSignal ; 189} 190export interface Conn < A extends StreamAddr = TcpAddr > { 191readonly localAddr :A ; 192readonly remoteAddr :A ; 193read ( buffer :Uint8Array ) :Promise < number | null >; 194write ( buffer :Uint8Array ) :Promise < number >; 195/** Writes every view in order before resolving; unlike write, success means the whole vector was written. */ 196writev ( buffers :readonly Uint8Array []) :Promise < number >; 197closeWrite () :Promise < void >; 198close () :void ; 199[ Symbol . dispose ]() :void ; 200readonly readable :ReadableStream < Uint8Array >; 201readonly writable :WritableStream < Uint8Array >; 202} 203 204export const Conn :ClassStatics & { 205readonly prototype :Conn < StreamAddr >; 206[ Symbol . hasInstance ]( value :unknown ) :value isConn < StreamAddr >; 207} = net . Conn ; 208export interface Listener < A extends StreamAddr = TcpAddr > extends AsyncIterable < Conn < A >> { 209readonly addr :A ; 210accept () :Promise < Conn < A >>; 211close () :void ; 212[ Symbol . dispose ]() :void ; 213[ Symbol . asyncIterator ]() :AsyncIterator < Conn < A >>; 214} 215 216export const Listener :ClassStatics & { 217readonly prototype :Listener < StreamAddr >; 218[ Symbol . hasInstance ]( value :unknown ) :value isListener < StreamAddr >; 219} = net . Listener ; 220export const connect :{ 221( options :TcpConnectOptions ) :Promise < Conn < TcpAddr >>; 222( options :UnixConnectOptions ) :Promise < Conn < UnixAddr >>; 223} = net . connect ; 224export const listen :{ 225( options :TcpListenOptions ) :Listener < TcpAddr >; 226( options :UnixListenOptions ) :Listener < UnixAddr >; 227} = net . listen ; 228 229export interface UdpListenOptions { 230transport ?:"udp" ; 231hostname ?:string ; 232port :number ; 233} 234export interface UdpSendOptions { 235transport ?:"udp" ; 236hostname ?:string ; 237port :number ; 238} 239export interface DatagramConn extends AsyncIterable <[ Uint8Array , UdpAddr ]> { 240readonly addr :UdpAddr ; 241receive ( buffer ?:Uint8Array ) :Promise <[ Uint8Array , UdpAddr ]>; 242send ( buffer :Uint8Array , target :UdpSendOptions ) :Promise < number >; 243setBroadcast ( enabled ?:boolean ) :void ; 244close () :void ; 245[ Symbol . dispose ]() :void ; 246[ Symbol . asyncIterator ]() :AsyncIterator <[ Uint8Array , UdpAddr ]>; 247} 248 249export const DatagramConn :ClassStatics & { 250readonly prototype :DatagramConn ; 251[ Symbol . hasInstance ]( value :unknown ) :value isDatagramConn ; 252} = net . DatagramConn ; 253export const listenDatagram :( options :UdpListenOptions ) => DatagramConn = net . listenDatagram ; 254 255export interface OpenOptions { 256read ?:boolean ; 257write ?:boolean ; 258append ?:boolean ; 259truncate ?:boolean ; 260create ?:boolean ; 261createNew ?:boolean ; 262mode ?:number ; 263} 264 265export interface FileInfo { 266isFile :boolean ; 267isDirectory :boolean ; 268isSymlink :boolean ; 269size :number ; 270mtime :Date | null ; 271atime :Date | null ; 272birthtime :Date | null ; 273mode :number | null ; 274uid :number | null ; 275gid :number | null ; 276} 277 278export const SeekMode :Readonly <{ Start :0 ; Current :1 ; End :2 }> = file . SeekMode ; 279export interface FileHandle { 280read ( buffer :Uint8Array ) :Promise < number | null >; 281write ( buffer :Uint8Array ) :Promise < number >; 282/** Writes every view in order before resolving; unlike write, success means the whole vector was written. */ 283writev ( buffers :readonly Uint8Array []) :Promise < number >; 284seek ( offset :number , whence :0 | 1 | 2 ) :Promise < number >; 285stat () :Promise < FileInfo >; 286truncate ( length ?:number ) :Promise < void >; 287sync () :Promise < void >; 288syncData () :Promise < void >; 289fchmod ( mode :number ) :Promise < void >; 290fchown ( uid :number | null , gid :number | null ) :Promise < void >; 291/** Times are seconds since the Unix epoch, like Deno and Node; Dates are accepted. */ 292futime ( atime :number | Date , mtime :number | Date ) :Promise < void >; 293/** Acquires an advisory lock, exclusive by default (unlike Deno's shared default). Waiting releases the handle queue, so a lock does not serialize with reads and writes. */ 294flock ( exclusive ?:boolean ) :Promise < void >; 295funlock () :Promise < void >; 296/** Synchronous operations share the native queue with async calls; they do not run JS callbacks while waiting. */ 297readSync ( buffer :Uint8Array ) :number | null ; 298writeSync ( buffer :Uint8Array ) :number ; 299/** Writes every view in order before returning; unlike writeSync, a normal return means the whole vector was written. */ 300writevSync ( buffers :readonly Uint8Array []) :number ; 301seekSync ( offset :number , whence :0 | 1 | 2 ) :number ; 302statSync () :FileInfo ; 303truncateSync ( length ?:number ) :void ; 304syncSync () :void ; 305syncDataSync () :void ; 306fchmodSync ( mode :number ) :void ; 307fchownSync ( uid :number | null , gid :number | null ) :void ; 308futimeSync ( atime :number | Date , mtime :number | Date ) :void ; 309/** Like flock(), waiting releases the handle queue, but blocks this isolate. */ 310flockSync ( exclusive ?:boolean ) :void ; 311funlockSync () :void ; 312close () :void ; 313[ Symbol . dispose ]() :void ; 314readonly readable :ReadableStream < Uint8Array >; 315readonly writable :WritableStream < Uint8Array >; 316} 317 318export const FileHandle :ClassStatics & { 319readonly prototype :FileHandle ; 320[ Symbol . hasInstance ]( value :unknown ) :value isFileHandle ; 321} = file . FileHandle ; 322export const open :( 323path :string | URL , 324options ?:OpenOptions , 325) => Promise < FileHandle > = file . open ; 326export const create :( path :string | URL ) => Promise < FileHandle > = file . create ; 327export const stat :( path :string | URL ) => Promise < FileInfo > = file . stat ; 328export const lstat :( path :string | URL ) => Promise < FileInfo > = file . lstat ; 329export interface DirEntry { 330name :string ; 331isFile :boolean ; 332isDirectory :boolean ; 333isSymlink :boolean ; 334} 335export const readDir :( path :string | URL ) => AsyncIterable < DirEntry > = file . readDir ; 336export type FsEventKind = 337| "create" 338| "modify" 339| "remove" 340| "rename" 341| "rescan" ; 342export interface FsEvent { 343readonly kind :FsEventKind ; 344/** Absolute paths under the canonicalized watched root. A rename has the source first and destination second; a rescan names each root whose contents should be read again. Events may be coalesced, and access events are not reported. */ 345readonly paths :readonly string []; 346} 347export interface WatchOptions { 348/** Watch subdirectories, including ones created later; defaults to true. Ignored for file roots. */ 349recursive ?:boolean ; 350/** Aborting closes the watcher and ends iteration without throwing the abort reason. */ 351signal ?:AbortSignal ; 352} 353export interface FsWatcher extends AsyncIterable < FsEvent > { 354close () :void ; 355/** Keeps the process alive while the watcher is open, including between iterations; this is the default. */ 356ref () :void ; 357/** Allows the process to exit even while the watcher is open. */ 358unref () :void ; 359[ Symbol . dispose ]() :void ; 360[ Symbol . asyncIterator ]() :AsyncIterator < FsEvent >; 361} 362 363export const FsWatcher :ClassStatics & { 364readonly prototype :FsWatcher ; 365[ Symbol . hasInstance ]( value :unknown ) :value isFsWatcher ; 366} = file . FsWatcher ; 367/** Watches existing files or directories; requires read authority for each root and, for recursive directories, its whole tree. Events are rechecked against live read authority when delivered. A file root stays attached to its path across replacement and recreation; removing or renaming away a directory root ends its watch once every root is gone. */ 368export const watchFs :( 369paths :string | URL | Iterable < string | URL >, 370options ?:WatchOptions , 371) => FsWatcher = file . watchFs ; 372export const mkdir :( 373path :string | URL , 374options ?:{ mode ?:number }, 375) => Promise < void > = file . mkdir ; 376export const remove :( 377path :string | URL , 378options ?:{ recursive ?:boolean }, 379) => Promise < void > = file . remove ; 380/** Requires directory-shaped authority over the source (read/write) and destination (write). Scoped directory renames containing symlinks are not yet implemented. */ 381export const rename :( 382source :string | URL , 383destination :string | URL , 384) => Promise < void > = file . rename ; 385export const copyFile :( 386source :string | URL , 387destination :string | URL , 388) => Promise < void > = file . copyFile ; 389/** Stores target text unchanged; requires write at the link and read/write tree authority over its target. Creation on Windows is not yet implemented. */ 390export const symlink :( 391target :string | URL , 392linkPath :string | URL , 393options ?:{ type ?:"file" | "dir" }, 394) => Promise < void > = file . symlink ; 395/** Reads the link's stored text, not its referent. */ 396export const readLink :( path :string | URL ) => Promise < string > = file . readLink ; 397export const realPath :( path :string | URL ) => Promise < string > = file . realPath ; 398/** Changes the file mode bits. Follows links. */ 399export const chmod :( path :string | URL , mode :number ) => Promise < void > = file . chmod ; 400/** Null keeps that id; 4294967295 is rejected. Follows links. */ 401export const chown :( 402path :string | URL , 403uid :number | null , 404gid :number | null , 405) => Promise < void > = file . chown ; 406/** Like chown but acts on the link itself. */ 407export const lchown :( 408path :string | URL , 409uid :number | null , 410gid :number | null , 411) => Promise < void > = file . lchown ; 412/** Times are seconds since the Unix epoch, like Deno and Node; Dates are accepted. Follows links. */ 413export const utime :( 414path :string | URL , 415atime :number | Date , 416mtime :number | Date , 417) => Promise < void > = file . utime ; 418/** Like utime but acts on the link itself; a trailing slash follows instead. */ 419export const lutime :( 420path :string | URL , 421atime :number | Date , 422mtime :number | Date , 423) => Promise < void > = file . lutime ; 424/** Requires read and write authority over the source and write over the destination; symlink sources are refused. */ 425export const link :( 426oldpath :string | URL , 427newpath :string | URL , 428) => Promise < void > = file . link ; 429/** Sets the file size, zero-filling growth. Follows links. */ 430export const truncate :( path :string | URL , length ?:number ) => Promise < void > = file . truncate ; 431export const errors :Readonly < 432Record < 433| "NotFound" 434| "PermissionDenied" 435| "AlreadyExists" 436| "NotEmpty" 437| "CrossDevice" 438| "NotADirectory" 439| "IsADirectory" 440| "InvalidInput" 441| "BadResource" 442| "Busy" 443| "BrokenPipe" 444| "NotSupported" 445| "IoError" , 446new ( message ?:string ) => Error 447> 448> = file . errors ; 449 450export type ProcessReason = 451| "abort" 452| "timeout" 453| "output-limit" 454| "terminated" 455| "dispose" 456| "owner" 457| "io-error" 458| "drain-timeout" ; 459export interface ProcessStatus { 460readonly code :number | null ; 461readonly signal :string | null ; 462readonly success :boolean ; 463readonly reason :ProcessReason | null ; 464readonly error :string | null ; 465} 466export interface ProcessOutput < T = Uint8Array > extends ProcessStatus { 467readonly stdout :T | null ; 468readonly stderr :T | null ; 469} 470/** File redirections resolve against the child working directory. The file mode is output-only; stdin files accept no mode. */ 471export type ProcessStdio = "piped" | "inherit" | "null" | { 472file :string | URL ; 473mode ?:"truncate" | "append" | "create-new" ; 474} | { handle :FileHandle }; 475export type ExtraProcessStdio = { 476pipe :"parent-to-child" | "child-to-parent" ; 477} | { 478file :string | URL ; 479mode ?:"truncate" | "append" | "create-new" ; 480direction :"parent-to-child" | "child-to-parent" ; 481} | { handle :FileHandle ; direction :"parent-to-child" | "child-to-parent" }; 482export interface ProcessOptions { 483args ?:Iterable < string >; 484cwd ?:string | URL ; 485/** Bare names search only the effective child environment's PATH. False uses a pathname relative to child cwd. */ 486searchPath ?:boolean ; 487clearEnv ?:boolean ; 488env ?:Record < string , string >; 489stdin ?:ProcessStdio ; 490stdout ?:ProcessStdio ; 491stderr ?:ProcessStdio | "stdout" ; 492input ?:string | Uint8Array | ReadableStream < Uint8Array >; 493encoding ?:string ; 494/** False returns nonzero exits instead of throwing; timeout, abort, output-limit, and IO failures still throw. */ 495check ?:boolean ; 496signal ?:AbortSignal ; 497timeoutMs ?:number ; 498/** Combined limit on output kept in memory for a result: stdout and stderr when collected, and stderr alone while lines() streams stdout. Defaults to 128 MiB; exceeding it terminates the child. */ 499maxCollectedBytes ?:number ; 500/** Maximum unread native queue per stream; defaults to 1 MiB. For spawn's streams, overflow terminates the child; there is no backpressure. run() and runSync() always drain their output, so they block the child instead. */ 501maxBufferedBytes ?:number ; 502termination ?:{ 503/** Group termination covers the child's process group. With a terminal attached, children that inherit standard streams instead join the parent's group so terminal IO (including /dev/tty) keeps working; kill() then targets only the child. Unowned SIGINT/SIGTERM stop children gracefully before exiting; a repeat signal shortens that wait. Serve owns its shutdown signals and drains in-flight subprocess work. REPL interruption stops only the session's blocking runSync. On Windows the group is the child's job object, and SIGTERM, SIGINT, SIGQUIT, and SIGKILL all terminate at once with exit code 1 and no signal, so graceMs has no effect; other signals reject with NotSupported. Console Ctrl-C also reaches Windows children directly, as a shared terminal's interrupt does on Unix. */ 504scope ?:"group" | "child" ; 505signal ?:string ; 506graceMs ?:number ; 507}; 508drainTimeoutMs ?:number ; 509} 510export interface SpawnOptions extends ProcessOptions { 511/** On Windows, descriptors up to 254 reach children through the C runtime's inherited descriptor table, so only CRT-based programs see them. */ 512extraStdio ?:Record < number , ExtraProcessStdio >; 513/** Not yet supported on Windows. */ 514terminal ?:{ columns ?:number ; rows ?:number }; 515} 516export interface ProcessTerminal { 517readonly readable :ReadableStream < Uint8Array >; 518readonly writable :WritableStream < Uint8Array >; 519resize ( columns :number , rows :number ) :void ; 520} 521/** One native invocation, owned by this isolate. Native execution is not sandboxed. On Linux, shebang scripts observe /dev/fd/N as their path while the executable stays pinned. */ 522export interface ChildProcess < T = Uint8Array > extends AsyncDisposable { 523readonly pid :number ; 524/** Null when automatic input owns stdin. */ 525readonly stdin :WritableStream < Uint8Array > | null ; 526readonly stdout :ReadableStream < Uint8Array > | null ; 527readonly stderr :ReadableStream < Uint8Array > | null ; 528readonly stdio :Readonly < 529Record < number , ReadableStream < Uint8Array > | WritableStream < Uint8Array >> 530>; 531readonly terminal :ProcessTerminal | null ; 532readonly status :Promise < ProcessStatus >; 533readonly completed :Promise < ProcessStatus >; 534/** Collects once, never respawns; rejects previously read or locked output. */ 535output () :Promise < ProcessOutput < T >>; 536/** Sends one signal to the termination scope (the whole process group by default, or just the child when it shares the parent's group). */ 537kill ( signal ?:string ) :boolean ; 538terminate () :Promise < ProcessStatus >; 539ref () :void ; 540unref () :void ; 541[ Symbol . asyncDispose ]() :Promise < void >; 542} 543 544export const ChildProcess :ClassStatics & { 545readonly prototype :ChildProcess < Uint8Array | string >; 546[ Symbol . hasInstance ]( value :unknown ) :value isChildProcess < Uint8Array | string >; 547} = subprocess . ChildProcess ; 548export interface ProcessError extends Error { 549readonly result :ProcessOutput < Uint8Array | string > | null ; 550} 551 552export const ProcessError :Omit < ErrorConstructor , "prototype" > & { 553readonly prototype :ProcessError ; 554new ( 555message :string , 556result ?:ProcessOutput < Uint8Array | string > | null , 557cause ?:unknown , 558) :ProcessError ; 559[ Symbol . hasInstance ]( value :unknown ) :value isProcessError ; 560} = subprocess . ProcessError ; 561export interface OutputLimitError extends ProcessError { 562} 563 564export const OutputLimitError :Omit < ErrorConstructor , "prototype" > & { 565readonly prototype :OutputLimitError ; 566new ( result :ProcessOutput < Uint8Array | string >) :OutputLimitError ; 567[ Symbol . hasInstance ]( value :unknown ) :value isOutputLimitError ; 568} = subprocess . OutputLimitError ; 569export interface ProcessTimeoutError extends ProcessError { 570} 571 572export const ProcessTimeoutError :Omit < ErrorConstructor , "prototype" > & { 573readonly prototype :ProcessTimeoutError ; 574new ( result :ProcessOutput < Uint8Array | string >) :ProcessTimeoutError ; 575[ Symbol . hasInstance ]( value :unknown ) :value isProcessTimeoutError ; 576} = subprocess . ProcessTimeoutError ; 577export interface ProcessAbortError extends ProcessError { 578} 579 580export const ProcessAbortError :Omit < ErrorConstructor , "prototype" > & { 581readonly prototype :ProcessAbortError ; 582new ( 583result :ProcessOutput < Uint8Array | string > | null , 584cause ?:unknown , 585) :ProcessAbortError ; 586[ Symbol . hasInstance ]( value :unknown ) :value isProcessAbortError ; 587} = subprocess . ProcessAbortError ; 588/** Authorizes native execution through run capabilities, independently of read and jsExec; the child is not sandboxed by avril's capabilities. Supported on Linux, macOS, and Windows 10 1607 or later; other platforms reject launch with NotSupported. On Linux, when close_range is unavailable, descriptor isolation requires /proc/self/fd. Linux pins the executable through exec; macOS launches the authorized path, and Windows holds it open against replacement until launch. Abruptly killed owners take their direct children with them on Linux and the child's job on Windows; on macOS only orderly exits clean up. Windows rejects batch files (run cmd.exe explicitly), and names without a .com or .exe extension also try both. Grants and denials name executable entries, not programs: aliases and hard links to the same binary need their own entries. On case-insensitive filesystems they match an entry by its stored spelling. Relative grants resolve against the grant-time working directory, not PATH. Unref'd children are terminated when their owner exits; only direct children are pinned to the owner's lifetime, so group grandchildren rely on group termination. Unix supervision preserves inherited ignored signal dispositions. No implicit shell. */ 589export const run :{ 590( 591command :string | URL , 592options ?:ProcessOptions & { encoding ?:undefined }, 593) :ProcessPromise ; 594( 595command :string | URL , 596options :ProcessOptions & { encoding :string }, 597) :ProcessPromise < string >; 598( 599command :string | URL , 600args :Iterable < string > | undefined , 601options ?:ProcessOptions & { args ?:undefined ; encoding ?:undefined }, 602) :ProcessPromise ; 603( 604command :string | URL , 605args :Iterable < string > | undefined , 606options :ProcessOptions & { args ?:undefined ; encoding :string }, 607) :ProcessPromise < string >; 608} = subprocess . run ; 609/** The run() result, with shortcuts to its stdout. Each shortcut fails like the run itself; stdout decodes with the encoding option, or UTF-8. */ 610export interface ProcessPromise < T = Uint8Array > 611extends Promise < ProcessOutput < T >> { 612bytes () :Promise < Uint8Array >; 613text () :Promise < string >; 614json () :Promise < unknown >; 615/** Stdout lines without their \n or \r\n. Called in the same turn as run(), it streams as the child writes, and the run's failures surface after the last line; a stopped run (timeout, abort, termination) ends iteration without the lines still queued, and ending iteration early terminates the child, so the run rejects as terminated. Past maxBufferedBytes unread, the child blocks until the loop catches up, so iterate rather than only awaiting the run. Streamed stdout is not collected and does not count toward maxCollectedBytes. Called later, it splits the collected output. */ 616lines () :AsyncIterableIterator < string >; 617} 618export type RunSyncOptions = Omit < ProcessOptions , "input" | "signal" > & { 619input ?:string | Uint8Array ; 620}; 621export const runSync :{ 622( 623command :string | URL , 624options ?:RunSyncOptions & { encoding ?:undefined }, 625) :ProcessOutput ; 626( 627command :string | URL , 628options :RunSyncOptions & { encoding :string }, 629) :ProcessOutput < string >; 630( 631command :string | URL , 632args :Iterable < string > | undefined , 633options ?:RunSyncOptions & { args ?:undefined ; encoding ?:undefined }, 634) :ProcessOutput ; 635( 636command :string | URL , 637args :Iterable < string > | undefined , 638options :RunSyncOptions & { args ?:undefined ; encoding :string }, 639) :ProcessOutput < string >; 640} = subprocess . runSync ; 641export const spawn :{ 642( 643command :string | URL , 644options ?:SpawnOptions & { encoding ?:undefined }, 645) :ChildProcess ; 646( 647command :string | URL , 648options :SpawnOptions & { encoding :string }, 649) :ChildProcess < string >; 650( 651command :string | URL , 652args :Iterable < string > | undefined , 653options ?:SpawnOptions & { args ?:undefined ; encoding ?:undefined }, 654) :ChildProcess ; 655( 656command :string | URL , 657args :Iterable < string > | undefined , 658options :SpawnOptions & { args ?:undefined ; encoding :string }, 659) :ChildProcess < string >; 660} = subprocess . spawn ; 661 662/** 663* Listens for a process signal, Deno-style. Supported on Linux and 664* macOS for SIGINT, SIGTERM, SIGHUP, SIGUSR1, SIGUSR2, and SIGWINCH; 665* other platforms and other signals throw NotSupported, while 666* unknown names and the uncatchable SIGKILL/SIGSTOP throw 667* InvalidInput. Listening needs no pledge. 668* 669* Signals are process-wide: each delivery reaches every live isolate 670* that binds it (entry, REPL, workers), with one isolate's listeners 671* firing in binding order. But only the entry isolate (and the REPL's 672* main isolate) suppress the default death: worker listeners observe 673* every delivery but never count, so with no entry listener a lethal 674* delivery still kills the process and worker delivery is best-effort. 675* A worker that must finish cleanup cannot rely on its own listener; 676* the entry module must listen instead and coordinate, the same shape 677* as serve's shutdown: entry listens, notifies workers, waits for 678* their acks, then exits. Once the last entry listener goes away the 679* prior fate returns. An active listener keeps the event loop alive, 680* like a referenced handle. 681* 682* Reserved owners still run alongside listeners: serve owns SIGINT and 683* SIGTERM for shutdown, and the REPL owns SIGINT for eval interrupt, so 684* listening to those observes the shutdown or interrupt rather than 685* replacing it. 686*/ 687export const addSignalListener :( 688signal :string , 689listener :() => void , 690) => void = subprocess . addSignalListener ; 691/** Stops a listener added with addSignalListener; unknown pairs are a no-op. */ 692export const removeSignalListener :( 693signal :string , 694listener :() => void , 695) => void = subprocess . removeSignalListener ; 696 697export const stdin :ReadableStream < Uint8Array > = stdio . stdin ; 698export const stdout :WritableStream < Uint8Array > = stdio . stdout ; 699export const stderr :WritableStream < Uint8Array > = stdio . stderr ;