Open History to see the last commit
1import type { FileSnapshot } from '../fs/types'
2
3export interface SerializedRequest {
4 body?: ArrayBuffer
5 headers: [string, string][]
6 method: string
7 url: string
8}
9
10export type HostToRuntimeMessage =
11 | {
12 type: 'load'
13 id: number
14 code: string
15 env: Record<string, string>
16 files: FileSnapshot
17 }
18 | {
19 type: 'request'
20 id: number
21 request: SerializedRequest
22 }
23
24export type RuntimeToHostMessage =
25 | { type: 'loaded'; id: number }
26 | { type: 'response-start'; id: number; status: number; statusText: string; headers: [string, string][] }
27 | { type: 'response-chunk'; id: number; chunk: ArrayBuffer }
28 | { type: 'response-end'; id: number }
29 | { type: 'error'; id: number; message: string; stack?: string }
30
31export interface RuntimeHost {
32 asyncContext: {
33 beginRequest(): void
34 endRequest(): void
35 retain(storage: { _store: unknown }, previous: unknown): boolean
36 }
37 env: Record<string, string>
38 fs: {
39 readFile(path: string | URL, options?: string | { encoding?: string }): Promise<string | Uint8Array>
40 readdir(path: string | URL): Promise<string[]>
41 stat(path: string | URL): Promise<{kind:'file'|'directory';isDirectory(): boolean;isFile(): boolean;size: number}>
42 lstat(path: string | URL): Promise<{kind:'file'|'directory';isDirectory(): boolean;isFile(): boolean;size: number}>
43 writeFile(path: string | URL, contents: string | Uint8Array): Promise<void>
44 }
45}
46
47declare global {
48 var __webContainerHost: RuntimeHost
49}