|
| 1 | +/** |
| 2 | + * Import metadata for current module. |
| 3 | + * @description Exposes module path info and resolver. |
| 4 | + */ |
| 5 | +interface ImportMeta { |
| 6 | + /** Absolute directory path of module */ |
| 7 | + dirname: string |
| 8 | + /** Absolute file path of module */ |
| 9 | + filename: string |
| 10 | + /** |
| 11 | + * Resolve specifier against module URL. |
| 12 | + * @param specifier - Module specifier to resolve |
| 13 | + * @returns Absolute resolved URL string |
| 14 | + */ |
| 15 | + resolve(specifier: string): string |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | +/** |
| 20 | + * Deno global runtime namespace. |
| 21 | + * @description Ambient types for Deno runtime APIs. |
| 22 | + */ |
1 | 23 | declare namespace Deno { |
| 24 | + /** |
| 25 | + * Environment variable accessor. |
| 26 | + * @description Reads and mutates process environment. |
| 27 | + */ |
2 | 28 | interface Env { |
| 29 | + /** |
| 30 | + * Delete environment variable. |
| 31 | + * @param key - Variable name to remove |
| 32 | + */ |
| 33 | + delete(key: string): void |
| 34 | + /** |
| 35 | + * Get environment variable value. |
| 36 | + * @param key - Variable name to read |
| 37 | + * @returns Variable value or undefined |
| 38 | + */ |
3 | 39 | get(key: string): string | undefined |
4 | | - set(key: string, value: string): void |
| 40 | + /** |
| 41 | + * Check environment variable exists. |
| 42 | + * @param key - Variable name to check |
| 43 | + * @returns True when variable is set |
| 44 | + */ |
5 | 45 | has(key: string): boolean |
6 | | - delete(key: string): void |
| 46 | + /** |
| 47 | + * Set environment variable value. |
| 48 | + * @param key - Variable name to write |
| 49 | + * @param value - Value to assign |
| 50 | + */ |
| 51 | + set(key: string, value: string): void |
| 52 | + /** |
| 53 | + * Snapshot all environment variables. |
| 54 | + * @returns Record of all variable entries |
| 55 | + */ |
7 | 56 | toObject(): Record<string, string> |
8 | 57 | } |
9 | | - const env: Env |
10 | | - |
11 | | - function cwd(): string |
12 | | - function exit(code?: number): never |
13 | | - function kill(pid: number, signo?: string): void |
14 | | - function readTextFile(path: string | URL): Promise<string> |
15 | | - function readFile(path: string | URL): Promise<Uint8Array> |
16 | | - function writeFile( |
17 | | - path: string | URL, |
18 | | - data: Uint8Array | ReadableStream<Uint8Array> |
19 | | - ): Promise<void> |
20 | | - interface FsFile { |
21 | | - write(data: Uint8Array): Promise<number> |
22 | | - close(): void |
23 | | - } |
24 | | - function open( |
25 | | - path: string | URL, |
26 | | - options?: { read?: boolean; write?: boolean; create?: boolean; append?: boolean } |
27 | | - ): Promise<FsFile> |
28 | | - function watchFs( |
29 | | - paths: string | string[], |
30 | | - options?: { recursive?: boolean } |
31 | | - ): AsyncIterableIterator<{ kind: string; paths: string[] }> |
32 | | - |
33 | | - interface ServeInit { |
34 | | - port?: number |
35 | | - hostname?: string |
36 | | - signal?: AbortSignal |
37 | | - onListen?: (addr: { hostname: string; port: number }) => void |
38 | | - } |
39 | | - function serve( |
40 | | - options: ServeInit, |
41 | | - handler: (request: Request) => Response | Promise<Response> |
42 | | - ): { finished: Promise<void>; shutdown(): Promise<void> } |
43 | | - |
44 | | - function upgradeWebSocket(request: Request): { socket: WebSocket; response: Response } |
45 | 58 |
|
| 59 | + /** |
| 60 | + * Filesystem entry metadata. |
| 61 | + * @description Describes file type, size, and times. |
| 62 | + */ |
46 | 63 | interface FileInfo { |
47 | | - isFile: boolean |
| 64 | + /** Last access time */ |
| 65 | + atime: Date | null |
| 66 | + /** Creation time of entry */ |
| 67 | + birthtime: Date | null |
| 68 | + /** True when entry is a directory */ |
48 | 69 | isDirectory: boolean |
| 70 | + /** True when entry is a file */ |
| 71 | + isFile: boolean |
| 72 | + /** True when entry is a symlink */ |
49 | 73 | isSymlink: boolean |
50 | | - size: number |
| 74 | + /** Last modification time */ |
51 | 75 | mtime: Date | null |
52 | | - atime: Date | null |
53 | | - birthtime: Date | null |
| 76 | + /** Entry size in bytes */ |
| 77 | + size: number |
54 | 78 | } |
55 | | - function stat(path: string | URL): Promise<FileInfo> |
56 | 79 |
|
| 80 | + /** |
| 81 | + * Open file handle reference. |
| 82 | + * @description Wraps an open file descriptor. |
| 83 | + */ |
| 84 | + interface FsFile { |
| 85 | + /** Close the file handle */ |
| 86 | + close(): void |
| 87 | + /** |
| 88 | + * Write bytes to file handle. |
| 89 | + * @param data - Byte content to write |
| 90 | + * @returns Promise resolving to bytes written |
| 91 | + */ |
| 92 | + write(data: Uint8Array): Promise<number> |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Network address descriptor. |
| 97 | + * @description Transport, hostname, and port info. |
| 98 | + */ |
57 | 99 | interface NetAddr { |
58 | | - transport: 'tcp' | 'udp' |
| 100 | + /** Remote hostname or address */ |
59 | 101 | hostname: string |
| 102 | + /** Remote port number */ |
60 | 103 | port: number |
| 104 | + /** Transport protocol type */ |
| 105 | + transport: 'tcp' | 'udp' |
61 | 106 | } |
| 107 | + |
| 108 | + /** |
| 109 | + * Per-request serve handler info. |
| 110 | + * @description Remote address and completion signal. |
| 111 | + */ |
62 | 112 | interface ServeHandlerInfo { |
63 | | - remoteAddr: NetAddr |
| 113 | + /** Promise resolving when request completes */ |
64 | 114 | completed: Promise<void> |
| 115 | + /** Remote peer network address */ |
| 116 | + remoteAddr: NetAddr |
65 | 117 | } |
66 | 118 |
|
| 119 | + /** |
| 120 | + * HTTP server initialization options. |
| 121 | + * @description Configures listen address and lifecycle. |
| 122 | + */ |
| 123 | + interface ServeInit { |
| 124 | + /** Hostname to bind the server */ |
| 125 | + hostname?: string |
| 126 | + /** Callback fired when listening starts */ |
| 127 | + onListen?: (addr: { hostname: string; port: number }) => void |
| 128 | + /** Port number to listen on */ |
| 129 | + port?: number |
| 130 | + /** Abort signal to stop server */ |
| 131 | + signal?: AbortSignal |
| 132 | + } |
| 133 | + |
| 134 | + /** Global environment variable accessor */ |
| 135 | + const env: Env |
| 136 | + |
| 137 | + /** |
| 138 | + * Get current working directory. |
| 139 | + * @returns Absolute working directory path |
| 140 | + */ |
| 141 | + function cwd(): string |
| 142 | + /** |
| 143 | + * Exit process with status code. |
| 144 | + * @param code - Optional exit status code |
| 145 | + * @returns Never returns to caller |
| 146 | + */ |
| 147 | + function exit(code?: number): never |
| 148 | + /** |
| 149 | + * Send signal to a process. |
| 150 | + * @param pid - Target process identifier |
| 151 | + * @param signo - Optional signal name |
| 152 | + */ |
| 153 | + function kill(pid: number, signo?: string): void |
| 154 | + /** |
| 155 | + * Open file and return handle. |
| 156 | + * @param path - File path or URL |
| 157 | + * @param options - Read, write, create flags |
| 158 | + * @returns Promise resolving to file handle |
| 159 | + */ |
| 160 | + function open( |
| 161 | + path: string | URL, |
| 162 | + options?: { read?: boolean; write?: boolean; create?: boolean; append?: boolean } |
| 163 | + ): Promise<FsFile> |
| 164 | + /** |
| 165 | + * Read file contents as bytes. |
| 166 | + * @param path - File path or URL |
| 167 | + * @returns Promise resolving to byte array |
| 168 | + */ |
| 169 | + function readFile(path: string | URL): Promise<Uint8Array> |
| 170 | + /** |
| 171 | + * Read file contents as text. |
| 172 | + * @param path - File path or URL |
| 173 | + * @returns Promise resolving to file text |
| 174 | + */ |
| 175 | + function readTextFile(path: string | URL): Promise<string> |
| 176 | + /** |
| 177 | + * Start HTTP server with handler. |
| 178 | + * @param options - Server initialization options |
| 179 | + * @param handler - Request to response handler |
| 180 | + * @returns Server with finished and shutdown |
| 181 | + */ |
| 182 | + function serve( |
| 183 | + options: ServeInit, |
| 184 | + handler: (request: Request) => Response | Promise<Response> |
| 185 | + ): { finished: Promise<void>; shutdown(): Promise<void> } |
| 186 | + /** |
| 187 | + * Get filesystem entry metadata. |
| 188 | + * @param path - File path or URL |
| 189 | + * @returns Promise resolving to file info |
| 190 | + */ |
| 191 | + function stat(path: string | URL): Promise<FileInfo> |
| 192 | + /** |
| 193 | + * Upgrade request to WebSocket. |
| 194 | + * @param request - Incoming upgrade request |
| 195 | + * @returns Socket and upgrade response pair |
| 196 | + */ |
| 197 | + function upgradeWebSocket(request: Request): { socket: WebSocket; response: Response } |
| 198 | + /** |
| 199 | + * Watch filesystem paths for changes. |
| 200 | + * @param paths - Path or paths to watch |
| 201 | + * @param options - Recursive watch flag |
| 202 | + * @returns Async iterator of change events |
| 203 | + */ |
| 204 | + function watchFs( |
| 205 | + paths: string | string[], |
| 206 | + options?: { recursive?: boolean } |
| 207 | + ): AsyncIterableIterator<{ kind: string; paths: string[] }> |
| 208 | + /** |
| 209 | + * Write bytes to a file. |
| 210 | + * @param path - File path or URL |
| 211 | + * @param data - Byte content or stream |
| 212 | + * @returns Promise resolving when write completes |
| 213 | + */ |
| 214 | + function writeFile( |
| 215 | + path: string | URL, |
| 216 | + data: Uint8Array | ReadableStream<Uint8Array> |
| 217 | + ): Promise<void> |
| 218 | + /** |
| 219 | + * Write text to a file. |
| 220 | + * @param path - File path or URL |
| 221 | + * @param data - Text content to write |
| 222 | + * @param options - Append and create flags |
| 223 | + * @returns Promise resolving when write completes |
| 224 | + */ |
| 225 | + function writeTextFile( |
| 226 | + path: string | URL, |
| 227 | + data: string, |
| 228 | + options?: { append?: boolean; create?: boolean } |
| 229 | + ): Promise<void> |
| 230 | + |
| 231 | + /** |
| 232 | + * Deno runtime error classes. |
| 233 | + * @description Typed errors thrown by runtime APIs. |
| 234 | + */ |
67 | 235 | namespace errors { |
68 | | - class NotFound extends Error {} |
| 236 | + /** Resource handle is invalid */ |
| 237 | + class BadResource extends Error {} |
| 238 | + /** Data was invalid or corrupt */ |
69 | 239 | class InvalidData extends Error {} |
| 240 | + /** Resource was not found */ |
| 241 | + class NotFound extends Error {} |
| 242 | + /** Operation is not supported */ |
70 | 243 | class NotSupported extends Error {} |
71 | | - class BadResource extends Error {} |
| 244 | + /** Permission was denied for operation */ |
72 | 245 | class PermissionDenied extends Error {} |
73 | 246 | } |
74 | 247 | } |
0 commit comments