lib.deno.d.ts18249 lines · main
| 1 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 2 | |
| 3 | /// <reference no-default-lib="true" /> |
| 4 | /// <reference lib="esnext" /> |
| 5 | /// <reference lib="deno.net" /> |
| 6 | |
| 7 | /** Deno provides extra properties on `import.meta`. These are included here |
| 8 | * to ensure that these are still available when using the Deno namespace in |
| 9 | * conjunction with other type libs, like `dom`. |
| 10 | * |
| 11 | * @category Platform |
| 12 | */ |
| 13 | declare interface ImportMeta { |
| 14 | /** A string representation of the fully qualified module URL. When the |
| 15 | * module is loaded locally, the value will be a file URL (e.g. |
| 16 | * `file:///path/module.ts`). |
| 17 | * |
| 18 | * You can also parse the string as a URL to determine more information about |
| 19 | * how the current module was loaded. For example to determine if a module was |
| 20 | * local or not: |
| 21 | * |
| 22 | * ```ts |
| 23 | * const url = new URL(import.meta.url); |
| 24 | * if (url.protocol === "file:") { |
| 25 | * console.log("this module was loaded locally"); |
| 26 | * } |
| 27 | * ``` |
| 28 | */ |
| 29 | url: string; |
| 30 | |
| 31 | /** The absolute path of the current module. |
| 32 | * |
| 33 | * This property is only provided for local modules (ie. using `file://` URLs). |
| 34 | * |
| 35 | * Example: |
| 36 | * ``` |
| 37 | * // Unix |
| 38 | * console.log(import.meta.filename); // /home/alice/my_module.ts |
| 39 | * |
| 40 | * // Windows |
| 41 | * console.log(import.meta.filename); // C:\alice\my_module.ts |
| 42 | * ``` |
| 43 | */ |
| 44 | filename?: string; |
| 45 | |
| 46 | /** The absolute path of the directory containing the current module. |
| 47 | * |
| 48 | * This property is only provided for local modules (ie. using `file://` URLs). |
| 49 | * |
| 50 | * * Example: |
| 51 | * ``` |
| 52 | * // Unix |
| 53 | * console.log(import.meta.dirname); // /home/alice |
| 54 | * |
| 55 | * // Windows |
| 56 | * console.log(import.meta.dirname); // C:\alice |
| 57 | * ``` |
| 58 | */ |
| 59 | dirname?: string; |
| 60 | |
| 61 | /** A flag that indicates if the current module is the main module that was |
| 62 | * called when starting the program under Deno. |
| 63 | * |
| 64 | * ```ts |
| 65 | * if (import.meta.main) { |
| 66 | * // this was loaded as the main module, maybe do some bootstrapping |
| 67 | * } |
| 68 | * ``` |
| 69 | */ |
| 70 | main: boolean; |
| 71 | |
| 72 | /** A function that returns resolved specifier as if it would be imported |
| 73 | * using `import(specifier)`. |
| 74 | * |
| 75 | * ```ts |
| 76 | * console.log(import.meta.resolve("./foo.js")); |
| 77 | * // file:///dev/foo.js |
| 78 | * ``` |
| 79 | */ |
| 80 | resolve(specifier: string): string; |
| 81 | } |
| 82 | |
| 83 | /** Deno supports [User Timing Level 3](https://w3c.github.io/user-timing) |
| 84 | * which is not widely supported yet in other runtimes. |
| 85 | * |
| 86 | * Check out the |
| 87 | * [Performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance) |
| 88 | * documentation on MDN for further information about how to use the API. |
| 89 | * |
| 90 | * @category Performance |
| 91 | */ |
| 92 | declare interface Performance { |
| 93 | /** Stores a timestamp with the associated name (a "mark"). */ |
| 94 | mark(markName: string, options?: PerformanceMarkOptions): PerformanceMark; |
| 95 | |
| 96 | /** Stores the `DOMHighResTimeStamp` duration between two marks along with the |
| 97 | * associated name (a "measure"). */ |
| 98 | measure( |
| 99 | measureName: string, |
| 100 | options?: PerformanceMeasureOptions, |
| 101 | ): PerformanceMeasure; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Options which are used in conjunction with `performance.mark`. Check out the |
| 106 | * MDN |
| 107 | * [`performance.mark()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark#markoptions) |
| 108 | * documentation for more details. |
| 109 | * |
| 110 | * @category Performance |
| 111 | */ |
| 112 | declare interface PerformanceMarkOptions { |
| 113 | /** Metadata to be included in the mark. */ |
| 114 | // deno-lint-ignore no-explicit-any |
| 115 | detail?: any; |
| 116 | |
| 117 | /** Timestamp to be used as the mark time. */ |
| 118 | startTime?: number; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Options which are used in conjunction with `performance.measure`. Check out the |
| 123 | * MDN |
| 124 | * [`performance.mark()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure#measureoptions) |
| 125 | * documentation for more details. |
| 126 | * |
| 127 | * @category Performance |
| 128 | */ |
| 129 | declare interface PerformanceMeasureOptions { |
| 130 | /** Metadata to be included in the measure. */ |
| 131 | // deno-lint-ignore no-explicit-any |
| 132 | detail?: any; |
| 133 | |
| 134 | /** Timestamp to be used as the start time or string to be used as start |
| 135 | * mark. */ |
| 136 | start?: string | number; |
| 137 | |
| 138 | /** Duration between the start and end times. */ |
| 139 | duration?: number; |
| 140 | |
| 141 | /** Timestamp to be used as the end time or string to be used as end mark. */ |
| 142 | end?: string | number; |
| 143 | } |
| 144 | |
| 145 | /** The global namespace where Deno specific, non-standard APIs are located. */ |
| 146 | declare namespace Deno { |
| 147 | /** A set of error constructors that are raised by Deno APIs. |
| 148 | * |
| 149 | * Can be used to provide more specific handling of failures within code |
| 150 | * which is using Deno APIs. For example, handling attempting to open a file |
| 151 | * which does not exist: |
| 152 | * |
| 153 | * ```ts |
| 154 | * try { |
| 155 | * const file = await Deno.open("./some/file.txt"); |
| 156 | * } catch (error) { |
| 157 | * if (error instanceof Deno.errors.NotFound) { |
| 158 | * console.error("the file was not found"); |
| 159 | * } else { |
| 160 | * // otherwise re-throw |
| 161 | * throw error; |
| 162 | * } |
| 163 | * } |
| 164 | * ``` |
| 165 | * |
| 166 | * @category Errors |
| 167 | */ |
| 168 | export namespace errors { |
| 169 | /** |
| 170 | * Raised when the underlying operating system indicates that the file |
| 171 | * was not found. |
| 172 | * |
| 173 | * @category Errors */ |
| 174 | export class NotFound extends Error {} |
| 175 | /** |
| 176 | * Raised when the underlying operating system indicates the current user |
| 177 | * which the Deno process is running under does not have the appropriate |
| 178 | * permissions to a file or resource, or the user _did not_ provide required |
| 179 | * `--allow-*` flag. |
| 180 | * |
| 181 | * @category Errors */ |
| 182 | export class PermissionDenied extends Error {} |
| 183 | /** |
| 184 | * Raised when the underlying operating system reports that a connection to |
| 185 | * a resource is refused. |
| 186 | * |
| 187 | * @category Errors */ |
| 188 | export class ConnectionRefused extends Error {} |
| 189 | /** |
| 190 | * Raised when the underlying operating system reports that a connection has |
| 191 | * been reset. With network servers, it can be a _normal_ occurrence where a |
| 192 | * client will abort a connection instead of properly shutting it down. |
| 193 | * |
| 194 | * @category Errors */ |
| 195 | export class ConnectionReset extends Error {} |
| 196 | /** |
| 197 | * Raised when the underlying operating system reports an `ECONNABORTED` |
| 198 | * error. |
| 199 | * |
| 200 | * @category Errors */ |
| 201 | export class ConnectionAborted extends Error {} |
| 202 | /** |
| 203 | * Raised when the underlying operating system reports an `ENOTCONN` error. |
| 204 | * |
| 205 | * @category Errors */ |
| 206 | export class NotConnected extends Error {} |
| 207 | /** |
| 208 | * Raised when attempting to open a server listener on an address and port |
| 209 | * that already has a listener. |
| 210 | * |
| 211 | * @category Errors */ |
| 212 | export class AddrInUse extends Error {} |
| 213 | /** |
| 214 | * Raised when the underlying operating system reports an `EADDRNOTAVAIL` |
| 215 | * error. |
| 216 | * |
| 217 | * @category Errors */ |
| 218 | export class AddrNotAvailable extends Error {} |
| 219 | /** |
| 220 | * Raised when trying to write to a resource and a broken pipe error occurs. |
| 221 | * This can happen when trying to write directly to `stdout` or `stderr` |
| 222 | * and the operating system is unable to pipe the output for a reason |
| 223 | * external to the Deno runtime. |
| 224 | * |
| 225 | * @category Errors */ |
| 226 | export class BrokenPipe extends Error {} |
| 227 | /** |
| 228 | * Raised when trying to create a resource, like a file, that already |
| 229 | * exits. |
| 230 | * |
| 231 | * @category Errors */ |
| 232 | export class AlreadyExists extends Error {} |
| 233 | /** |
| 234 | * Raised when an operation to returns data that is invalid for the |
| 235 | * operation being performed. |
| 236 | * |
| 237 | * @category Errors */ |
| 238 | export class InvalidData extends Error {} |
| 239 | /** |
| 240 | * Raised when the underlying operating system reports that an I/O operation |
| 241 | * has timed out (`ETIMEDOUT`). |
| 242 | * |
| 243 | * @category Errors */ |
| 244 | export class TimedOut extends Error {} |
| 245 | /** |
| 246 | * Raised when the underlying operating system reports an `EINTR` error. In |
| 247 | * many cases, this underlying IO error will be handled internally within |
| 248 | * Deno, or result in an @{link BadResource} error instead. |
| 249 | * |
| 250 | * @category Errors */ |
| 251 | export class Interrupted extends Error {} |
| 252 | /** |
| 253 | * Raised when the underlying operating system would need to block to |
| 254 | * complete but an asynchronous (non-blocking) API is used. |
| 255 | * |
| 256 | * @category Errors */ |
| 257 | export class WouldBlock extends Error {} |
| 258 | /** |
| 259 | * Raised when expecting to write to a IO buffer resulted in zero bytes |
| 260 | * being written. |
| 261 | * |
| 262 | * @category Errors */ |
| 263 | export class WriteZero extends Error {} |
| 264 | /** |
| 265 | * Raised when attempting to read bytes from a resource, but the EOF was |
| 266 | * unexpectedly encountered. |
| 267 | * |
| 268 | * @category Errors */ |
| 269 | export class UnexpectedEof extends Error {} |
| 270 | /** |
| 271 | * The underlying IO resource is invalid or closed, and so the operation |
| 272 | * could not be performed. |
| 273 | * |
| 274 | * @category Errors */ |
| 275 | export class BadResource extends Error {} |
| 276 | /** |
| 277 | * Raised in situations where when attempting to load a dynamic import, |
| 278 | * too many redirects were encountered. |
| 279 | * |
| 280 | * @category Errors */ |
| 281 | export class Http extends Error {} |
| 282 | /** |
| 283 | * Raised when the underlying IO resource is not available because it is |
| 284 | * being awaited on in another block of code. |
| 285 | * |
| 286 | * @category Errors */ |
| 287 | export class Busy extends Error {} |
| 288 | /** |
| 289 | * Raised when the underlying Deno API is asked to perform a function that |
| 290 | * is not currently supported. |
| 291 | * |
| 292 | * @category Errors */ |
| 293 | export class NotSupported extends Error {} |
| 294 | /** |
| 295 | * Raised when too many symbolic links were encountered when resolving the |
| 296 | * filename. |
| 297 | * |
| 298 | * @category Errors */ |
| 299 | export class FilesystemLoop extends Error {} |
| 300 | /** |
| 301 | * Raised when trying to open, create or write to a directory. |
| 302 | * |
| 303 | * @category Errors */ |
| 304 | export class IsADirectory extends Error {} |
| 305 | /** |
| 306 | * Raised when performing a socket operation but the remote host is |
| 307 | * not reachable. |
| 308 | * |
| 309 | * @category Errors */ |
| 310 | export class NetworkUnreachable extends Error {} |
| 311 | /** |
| 312 | * Raised when trying to perform an operation on a path that is not a |
| 313 | * directory, when directory is required. |
| 314 | * |
| 315 | * @category Errors */ |
| 316 | export class NotADirectory extends Error {} |
| 317 | } |
| 318 | |
| 319 | /** The current process ID of this instance of the Deno CLI. |
| 320 | * |
| 321 | * ```ts |
| 322 | * console.log(Deno.pid); |
| 323 | * ``` |
| 324 | * |
| 325 | * @category Runtime |
| 326 | */ |
| 327 | export const pid: number; |
| 328 | |
| 329 | /** |
| 330 | * The process ID of parent process of this instance of the Deno CLI. |
| 331 | * |
| 332 | * ```ts |
| 333 | * console.log(Deno.ppid); |
| 334 | * ``` |
| 335 | * |
| 336 | * @category Runtime |
| 337 | */ |
| 338 | export const ppid: number; |
| 339 | |
| 340 | /** @category Runtime */ |
| 341 | export interface MemoryUsage { |
| 342 | /** The number of bytes of the current Deno's process resident set size, |
| 343 | * which is the amount of memory occupied in main memory (RAM). */ |
| 344 | rss: number; |
| 345 | /** The total size of the heap for V8, in bytes. */ |
| 346 | heapTotal: number; |
| 347 | /** The amount of the heap used for V8, in bytes. */ |
| 348 | heapUsed: number; |
| 349 | /** Memory, in bytes, associated with JavaScript objects outside of the |
| 350 | * JavaScript isolate. */ |
| 351 | external: number; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Returns an object describing the memory usage of the Deno process and the |
| 356 | * V8 subsystem measured in bytes. |
| 357 | * |
| 358 | * @category Runtime |
| 359 | */ |
| 360 | export function memoryUsage(): MemoryUsage; |
| 361 | |
| 362 | /** |
| 363 | * Get the `hostname` of the machine the Deno process is running on. |
| 364 | * |
| 365 | * ```ts |
| 366 | * console.log(Deno.hostname()); |
| 367 | * ``` |
| 368 | * |
| 369 | * Requires `allow-sys` permission. |
| 370 | * |
| 371 | * @tags allow-sys |
| 372 | * @category Runtime |
| 373 | */ |
| 374 | export function hostname(): string; |
| 375 | |
| 376 | /** |
| 377 | * Returns an array containing the 1, 5, and 15 minute load averages. The |
| 378 | * load average is a measure of CPU and IO utilization of the last one, five, |
| 379 | * and 15 minute periods expressed as a fractional number. Zero means there |
| 380 | * is no load. On Windows, the three values are always the same and represent |
| 381 | * the current load, not the 1, 5 and 15 minute load averages. |
| 382 | * |
| 383 | * ```ts |
| 384 | * console.log(Deno.loadavg()); // e.g. [ 0.71, 0.44, 0.44 ] |
| 385 | * ``` |
| 386 | * |
| 387 | * Requires `allow-sys` permission. |
| 388 | * |
| 389 | * On Windows there is no API available to retrieve this information and this method returns `[ 0, 0, 0 ]`. |
| 390 | * |
| 391 | * @tags allow-sys |
| 392 | * @category Runtime |
| 393 | */ |
| 394 | export function loadavg(): number[]; |
| 395 | |
| 396 | /** |
| 397 | * The information for a network interface returned from a call to |
| 398 | * {@linkcode Deno.networkInterfaces}. |
| 399 | * |
| 400 | * @category Network |
| 401 | */ |
| 402 | export interface NetworkInterfaceInfo { |
| 403 | /** The network interface name. */ |
| 404 | name: string; |
| 405 | /** The IP protocol version. */ |
| 406 | family: "IPv4" | "IPv6"; |
| 407 | /** The IP address bound to the interface. */ |
| 408 | address: string; |
| 409 | /** The netmask applied to the interface. */ |
| 410 | netmask: string; |
| 411 | /** The IPv6 scope id or `null`. */ |
| 412 | scopeid: number | null; |
| 413 | /** The CIDR range. */ |
| 414 | cidr: string; |
| 415 | /** The MAC address. */ |
| 416 | mac: string; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Returns an array of the network interface information. |
| 421 | * |
| 422 | * ```ts |
| 423 | * console.log(Deno.networkInterfaces()); |
| 424 | * ``` |
| 425 | * |
| 426 | * Requires `allow-sys` permission. |
| 427 | * |
| 428 | * @tags allow-sys |
| 429 | * @category Network |
| 430 | */ |
| 431 | export function networkInterfaces(): NetworkInterfaceInfo[]; |
| 432 | |
| 433 | /** |
| 434 | * Displays the total amount of free and used physical and swap memory in the |
| 435 | * system, as well as the buffers and caches used by the kernel. |
| 436 | * |
| 437 | * This is similar to the `free` command in Linux |
| 438 | * |
| 439 | * ```ts |
| 440 | * console.log(Deno.systemMemoryInfo()); |
| 441 | * ``` |
| 442 | * |
| 443 | * Requires `allow-sys` permission. |
| 444 | * |
| 445 | * @tags allow-sys |
| 446 | * @category Runtime |
| 447 | */ |
| 448 | export function systemMemoryInfo(): SystemMemoryInfo; |
| 449 | |
| 450 | /** |
| 451 | * Information returned from a call to {@linkcode Deno.systemMemoryInfo}. |
| 452 | * |
| 453 | * @category Runtime |
| 454 | */ |
| 455 | export interface SystemMemoryInfo { |
| 456 | /** Total installed memory in bytes. */ |
| 457 | total: number; |
| 458 | /** Unused memory in bytes. */ |
| 459 | free: number; |
| 460 | /** Estimation of how much memory, in bytes, is available for starting new |
| 461 | * applications, without swapping. Unlike the data provided by the cache or |
| 462 | * free fields, this field takes into account page cache and also that not |
| 463 | * all reclaimable memory will be reclaimed due to items being in use. |
| 464 | */ |
| 465 | available: number; |
| 466 | /** Memory used by kernel buffers. */ |
| 467 | buffers: number; |
| 468 | /** Memory used by the page cache and slabs. */ |
| 469 | cached: number; |
| 470 | /** Total swap memory. */ |
| 471 | swapTotal: number; |
| 472 | /** Unused swap memory. */ |
| 473 | swapFree: number; |
| 474 | } |
| 475 | |
| 476 | /** Reflects the `NO_COLOR` environment variable at program start. |
| 477 | * |
| 478 | * When the value is `true`, the Deno CLI will attempt to not send color codes |
| 479 | * to `stderr` or `stdout` and other command line programs should also attempt |
| 480 | * to respect this value. |
| 481 | * |
| 482 | * See: https://no-color.org/ |
| 483 | * |
| 484 | * @category Runtime |
| 485 | */ |
| 486 | export const noColor: boolean; |
| 487 | |
| 488 | /** |
| 489 | * Returns the release version of the Operating System. |
| 490 | * |
| 491 | * ```ts |
| 492 | * console.log(Deno.osRelease()); |
| 493 | * ``` |
| 494 | * |
| 495 | * Requires `allow-sys` permission. |
| 496 | * Under consideration to possibly move to Deno.build or Deno.versions and if |
| 497 | * it should depend sys-info, which may not be desirable. |
| 498 | * |
| 499 | * @tags allow-sys |
| 500 | * @category Runtime |
| 501 | */ |
| 502 | export function osRelease(): string; |
| 503 | |
| 504 | /** |
| 505 | * Returns the Operating System uptime in number of seconds. |
| 506 | * |
| 507 | * ```ts |
| 508 | * console.log(Deno.osUptime()); |
| 509 | * ``` |
| 510 | * |
| 511 | * Requires `allow-sys` permission. |
| 512 | * |
| 513 | * @tags allow-sys |
| 514 | * @category Runtime |
| 515 | */ |
| 516 | export function osUptime(): number; |
| 517 | |
| 518 | /** |
| 519 | * Options which define the permissions within a test or worker context. |
| 520 | * |
| 521 | * `"inherit"` ensures that all permissions of the parent process will be |
| 522 | * applied to the test context. `"none"` ensures the test context has no |
| 523 | * permissions. A `PermissionOptionsObject` provides a more specific |
| 524 | * set of permissions to the test context. |
| 525 | * |
| 526 | * @category Permissions */ |
| 527 | export type PermissionOptions = |
| 528 | | "inherit" |
| 529 | | "none" |
| 530 | | PermissionOptionsObject; |
| 531 | |
| 532 | /** |
| 533 | * A set of options which can define the permissions within a test or worker |
| 534 | * context at a highly specific level. |
| 535 | * |
| 536 | * @category Permissions */ |
| 537 | export interface PermissionOptionsObject { |
| 538 | /** Specifies if the `env` permission should be requested or revoked. |
| 539 | * If set to `"inherit"`, the current `env` permission will be inherited. |
| 540 | * If set to `true`, the global `env` permission will be requested. |
| 541 | * If set to `false`, the global `env` permission will be revoked. |
| 542 | * |
| 543 | * @default {false} |
| 544 | */ |
| 545 | env?: "inherit" | boolean | string[]; |
| 546 | |
| 547 | /** Specifies if the `sys` permission should be requested or revoked. |
| 548 | * If set to `"inherit"`, the current `sys` permission will be inherited. |
| 549 | * If set to `true`, the global `sys` permission will be requested. |
| 550 | * If set to `false`, the global `sys` permission will be revoked. |
| 551 | * |
| 552 | * @default {false} |
| 553 | */ |
| 554 | sys?: "inherit" | boolean | string[]; |
| 555 | |
| 556 | /** Specifies if the `hrtime` permission should be requested or revoked. |
| 557 | * If set to `"inherit"`, the current `hrtime` permission will be inherited. |
| 558 | * If set to `true`, the global `hrtime` permission will be requested. |
| 559 | * If set to `false`, the global `hrtime` permission will be revoked. |
| 560 | * |
| 561 | * @default {false} |
| 562 | */ |
| 563 | hrtime?: "inherit" | boolean; |
| 564 | |
| 565 | /** Specifies if the `net` permission should be requested or revoked. |
| 566 | * if set to `"inherit"`, the current `net` permission will be inherited. |
| 567 | * if set to `true`, the global `net` permission will be requested. |
| 568 | * if set to `false`, the global `net` permission will be revoked. |
| 569 | * if set to `string[]`, the `net` permission will be requested with the |
| 570 | * specified host strings with the format `"<host>[:<port>]`. |
| 571 | * |
| 572 | * @default {false} |
| 573 | * |
| 574 | * Examples: |
| 575 | * |
| 576 | * ```ts |
| 577 | * import { assertEquals } from "jsr:@std/assert"; |
| 578 | * |
| 579 | * Deno.test({ |
| 580 | * name: "inherit", |
| 581 | * permissions: { |
| 582 | * net: "inherit", |
| 583 | * }, |
| 584 | * async fn() { |
| 585 | * const status = await Deno.permissions.query({ name: "net" }) |
| 586 | * assertEquals(status.state, "granted"); |
| 587 | * }, |
| 588 | * }); |
| 589 | * ``` |
| 590 | * |
| 591 | * ```ts |
| 592 | * import { assertEquals } from "jsr:@std/assert"; |
| 593 | * |
| 594 | * Deno.test({ |
| 595 | * name: "true", |
| 596 | * permissions: { |
| 597 | * net: true, |
| 598 | * }, |
| 599 | * async fn() { |
| 600 | * const status = await Deno.permissions.query({ name: "net" }); |
| 601 | * assertEquals(status.state, "granted"); |
| 602 | * }, |
| 603 | * }); |
| 604 | * ``` |
| 605 | * |
| 606 | * ```ts |
| 607 | * import { assertEquals } from "jsr:@std/assert"; |
| 608 | * |
| 609 | * Deno.test({ |
| 610 | * name: "false", |
| 611 | * permissions: { |
| 612 | * net: false, |
| 613 | * }, |
| 614 | * async fn() { |
| 615 | * const status = await Deno.permissions.query({ name: "net" }); |
| 616 | * assertEquals(status.state, "denied"); |
| 617 | * }, |
| 618 | * }); |
| 619 | * ``` |
| 620 | * |
| 621 | * ```ts |
| 622 | * import { assertEquals } from "jsr:@std/assert"; |
| 623 | * |
| 624 | * Deno.test({ |
| 625 | * name: "localhost:8080", |
| 626 | * permissions: { |
| 627 | * net: ["localhost:8080"], |
| 628 | * }, |
| 629 | * async fn() { |
| 630 | * const status = await Deno.permissions.query({ name: "net", host: "localhost:8080" }); |
| 631 | * assertEquals(status.state, "granted"); |
| 632 | * }, |
| 633 | * }); |
| 634 | * ``` |
| 635 | */ |
| 636 | net?: "inherit" | boolean | string[]; |
| 637 | |
| 638 | /** Specifies if the `ffi` permission should be requested or revoked. |
| 639 | * If set to `"inherit"`, the current `ffi` permission will be inherited. |
| 640 | * If set to `true`, the global `ffi` permission will be requested. |
| 641 | * If set to `false`, the global `ffi` permission will be revoked. |
| 642 | * |
| 643 | * @default {false} |
| 644 | */ |
| 645 | ffi?: "inherit" | boolean | Array<string | URL>; |
| 646 | |
| 647 | /** Specifies if the `read` permission should be requested or revoked. |
| 648 | * If set to `"inherit"`, the current `read` permission will be inherited. |
| 649 | * If set to `true`, the global `read` permission will be requested. |
| 650 | * If set to `false`, the global `read` permission will be revoked. |
| 651 | * If set to `Array<string | URL>`, the `read` permission will be requested with the |
| 652 | * specified file paths. |
| 653 | * |
| 654 | * @default {false} |
| 655 | */ |
| 656 | read?: "inherit" | boolean | Array<string | URL>; |
| 657 | |
| 658 | /** Specifies if the `run` permission should be requested or revoked. |
| 659 | * If set to `"inherit"`, the current `run` permission will be inherited. |
| 660 | * If set to `true`, the global `run` permission will be requested. |
| 661 | * If set to `false`, the global `run` permission will be revoked. |
| 662 | * |
| 663 | * @default {false} |
| 664 | */ |
| 665 | run?: "inherit" | boolean | Array<string | URL>; |
| 666 | |
| 667 | /** Specifies if the `write` permission should be requested or revoked. |
| 668 | * If set to `"inherit"`, the current `write` permission will be inherited. |
| 669 | * If set to `true`, the global `write` permission will be requested. |
| 670 | * If set to `false`, the global `write` permission will be revoked. |
| 671 | * If set to `Array<string | URL>`, the `write` permission will be requested with the |
| 672 | * specified file paths. |
| 673 | * |
| 674 | * @default {false} |
| 675 | */ |
| 676 | write?: "inherit" | boolean | Array<string | URL>; |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Context that is passed to a testing function, which can be used to either |
| 681 | * gain information about the current test, or register additional test |
| 682 | * steps within the current test. |
| 683 | * |
| 684 | * @category Testing */ |
| 685 | export interface TestContext { |
| 686 | /** The current test name. */ |
| 687 | name: string; |
| 688 | /** The string URL of the current test. */ |
| 689 | origin: string; |
| 690 | /** If the current test is a step of another test, the parent test context |
| 691 | * will be set here. */ |
| 692 | parent?: TestContext; |
| 693 | |
| 694 | /** Run a sub step of the parent test or step. Returns a promise |
| 695 | * that resolves to a boolean signifying if the step completed successfully. |
| 696 | * |
| 697 | * The returned promise never rejects unless the arguments are invalid. |
| 698 | * |
| 699 | * If the test was ignored the promise returns `false`. |
| 700 | * |
| 701 | * ```ts |
| 702 | * Deno.test({ |
| 703 | * name: "a parent test", |
| 704 | * async fn(t) { |
| 705 | * console.log("before the step"); |
| 706 | * await t.step({ |
| 707 | * name: "step 1", |
| 708 | * fn(t) { |
| 709 | * console.log("current step:", t.name); |
| 710 | * } |
| 711 | * }); |
| 712 | * console.log("after the step"); |
| 713 | * } |
| 714 | * }); |
| 715 | * ``` |
| 716 | */ |
| 717 | step(definition: TestStepDefinition): Promise<boolean>; |
| 718 | |
| 719 | /** Run a sub step of the parent test or step. Returns a promise |
| 720 | * that resolves to a boolean signifying if the step completed successfully. |
| 721 | * |
| 722 | * The returned promise never rejects unless the arguments are invalid. |
| 723 | * |
| 724 | * If the test was ignored the promise returns `false`. |
| 725 | * |
| 726 | * ```ts |
| 727 | * Deno.test( |
| 728 | * "a parent test", |
| 729 | * async (t) => { |
| 730 | * console.log("before the step"); |
| 731 | * await t.step( |
| 732 | * "step 1", |
| 733 | * (t) => { |
| 734 | * console.log("current step:", t.name); |
| 735 | * } |
| 736 | * ); |
| 737 | * console.log("after the step"); |
| 738 | * } |
| 739 | * ); |
| 740 | * ``` |
| 741 | */ |
| 742 | step( |
| 743 | name: string, |
| 744 | fn: (t: TestContext) => void | Promise<void>, |
| 745 | ): Promise<boolean>; |
| 746 | |
| 747 | /** Run a sub step of the parent test or step. Returns a promise |
| 748 | * that resolves to a boolean signifying if the step completed successfully. |
| 749 | * |
| 750 | * The returned promise never rejects unless the arguments are invalid. |
| 751 | * |
| 752 | * If the test was ignored the promise returns `false`. |
| 753 | * |
| 754 | * ```ts |
| 755 | * Deno.test(async function aParentTest(t) { |
| 756 | * console.log("before the step"); |
| 757 | * await t.step(function step1(t) { |
| 758 | * console.log("current step:", t.name); |
| 759 | * }); |
| 760 | * console.log("after the step"); |
| 761 | * }); |
| 762 | * ``` |
| 763 | */ |
| 764 | step(fn: (t: TestContext) => void | Promise<void>): Promise<boolean>; |
| 765 | } |
| 766 | |
| 767 | /** @category Testing */ |
| 768 | export interface TestStepDefinition { |
| 769 | /** The test function that will be tested when this step is executed. The |
| 770 | * function can take an argument which will provide information about the |
| 771 | * current step's context. */ |
| 772 | fn: (t: TestContext) => void | Promise<void>; |
| 773 | /** The name of the step. */ |
| 774 | name: string; |
| 775 | /** If truthy the current test step will be ignored. |
| 776 | * |
| 777 | * This is a quick way to skip over a step, but also can be used for |
| 778 | * conditional logic, like determining if an environment feature is present. |
| 779 | */ |
| 780 | ignore?: boolean; |
| 781 | /** Check that the number of async completed operations after the test step |
| 782 | * is the same as number of dispatched operations. This ensures that the |
| 783 | * code tested does not start async operations which it then does |
| 784 | * not await. This helps in preventing logic errors and memory leaks |
| 785 | * in the application code. |
| 786 | * |
| 787 | * Defaults to the parent test or step's value. */ |
| 788 | sanitizeOps?: boolean; |
| 789 | /** Ensure the test step does not "leak" resources - like open files or |
| 790 | * network connections - by ensuring the open resources at the start of the |
| 791 | * step match the open resources at the end of the step. |
| 792 | * |
| 793 | * Defaults to the parent test or step's value. */ |
| 794 | sanitizeResources?: boolean; |
| 795 | /** Ensure the test step does not prematurely cause the process to exit, |
| 796 | * for example via a call to {@linkcode Deno.exit}. |
| 797 | * |
| 798 | * Defaults to the parent test or step's value. */ |
| 799 | sanitizeExit?: boolean; |
| 800 | } |
| 801 | |
| 802 | /** @category Testing */ |
| 803 | export interface TestDefinition { |
| 804 | fn: (t: TestContext) => void | Promise<void>; |
| 805 | /** The name of the test. */ |
| 806 | name: string; |
| 807 | /** If truthy the current test step will be ignored. |
| 808 | * |
| 809 | * It is a quick way to skip over a step, but also can be used for |
| 810 | * conditional logic, like determining if an environment feature is present. |
| 811 | */ |
| 812 | ignore?: boolean; |
| 813 | /** If at least one test has `only` set to `true`, only run tests that have |
| 814 | * `only` set to `true` and fail the test suite. */ |
| 815 | only?: boolean; |
| 816 | /** Check that the number of async completed operations after the test step |
| 817 | * is the same as number of dispatched operations. This ensures that the |
| 818 | * code tested does not start async operations which it then does |
| 819 | * not await. This helps in preventing logic errors and memory leaks |
| 820 | * in the application code. |
| 821 | * |
| 822 | * @default {true} */ |
| 823 | sanitizeOps?: boolean; |
| 824 | /** Ensure the test step does not "leak" resources - like open files or |
| 825 | * network connections - by ensuring the open resources at the start of the |
| 826 | * test match the open resources at the end of the test. |
| 827 | * |
| 828 | * @default {true} */ |
| 829 | sanitizeResources?: boolean; |
| 830 | /** Ensure the test case does not prematurely cause the process to exit, |
| 831 | * for example via a call to {@linkcode Deno.exit}. |
| 832 | * |
| 833 | * @default {true} */ |
| 834 | sanitizeExit?: boolean; |
| 835 | /** Specifies the permissions that should be used to run the test. |
| 836 | * |
| 837 | * Set this to "inherit" to keep the calling runtime permissions, set this |
| 838 | * to "none" to revoke all permissions, or set a more specific set of |
| 839 | * permissions using a {@linkcode PermissionOptionsObject}. |
| 840 | * |
| 841 | * @default {"inherit"} */ |
| 842 | permissions?: PermissionOptions; |
| 843 | } |
| 844 | |
| 845 | /** Register a test which will be run when `deno test` is used on the command |
| 846 | * line and the containing module looks like a test module. |
| 847 | * |
| 848 | * `fn` can be async if required. |
| 849 | * |
| 850 | * ```ts |
| 851 | * import { assertEquals } from "jsr:@std/assert"; |
| 852 | * |
| 853 | * Deno.test({ |
| 854 | * name: "example test", |
| 855 | * fn() { |
| 856 | * assertEquals("world", "world"); |
| 857 | * }, |
| 858 | * }); |
| 859 | * |
| 860 | * Deno.test({ |
| 861 | * name: "example ignored test", |
| 862 | * ignore: Deno.build.os === "windows", |
| 863 | * fn() { |
| 864 | * // This test is ignored only on Windows machines |
| 865 | * }, |
| 866 | * }); |
| 867 | * |
| 868 | * Deno.test({ |
| 869 | * name: "example async test", |
| 870 | * async fn() { |
| 871 | * const decoder = new TextDecoder("utf-8"); |
| 872 | * const data = await Deno.readFile("hello_world.txt"); |
| 873 | * assertEquals(decoder.decode(data), "Hello world"); |
| 874 | * } |
| 875 | * }); |
| 876 | * ``` |
| 877 | * |
| 878 | * @category Testing |
| 879 | */ |
| 880 | export const test: DenoTest; |
| 881 | |
| 882 | /** |
| 883 | * @category Testing |
| 884 | */ |
| 885 | export interface DenoTest { |
| 886 | /** Register a test which will be run when `deno test` is used on the command |
| 887 | * line and the containing module looks like a test module. |
| 888 | * |
| 889 | * `fn` can be async if required. |
| 890 | * |
| 891 | * ```ts |
| 892 | * import { assertEquals } from "jsr:@std/assert"; |
| 893 | * |
| 894 | * Deno.test({ |
| 895 | * name: "example test", |
| 896 | * fn() { |
| 897 | * assertEquals("world", "world"); |
| 898 | * }, |
| 899 | * }); |
| 900 | * |
| 901 | * Deno.test({ |
| 902 | * name: "example ignored test", |
| 903 | * ignore: Deno.build.os === "windows", |
| 904 | * fn() { |
| 905 | * // This test is ignored only on Windows machines |
| 906 | * }, |
| 907 | * }); |
| 908 | * |
| 909 | * Deno.test({ |
| 910 | * name: "example async test", |
| 911 | * async fn() { |
| 912 | * const decoder = new TextDecoder("utf-8"); |
| 913 | * const data = await Deno.readFile("hello_world.txt"); |
| 914 | * assertEquals(decoder.decode(data), "Hello world"); |
| 915 | * } |
| 916 | * }); |
| 917 | * ``` |
| 918 | * |
| 919 | * @category Testing |
| 920 | */ |
| 921 | (t: TestDefinition): void; |
| 922 | |
| 923 | /** Register a test which will be run when `deno test` is used on the command |
| 924 | * line and the containing module looks like a test module. |
| 925 | * |
| 926 | * `fn` can be async if required. |
| 927 | * |
| 928 | * ```ts |
| 929 | * import { assertEquals } from "jsr:@std/assert"; |
| 930 | * |
| 931 | * Deno.test("My test description", () => { |
| 932 | * assertEquals("hello", "hello"); |
| 933 | * }); |
| 934 | * |
| 935 | * Deno.test("My async test description", async () => { |
| 936 | * const decoder = new TextDecoder("utf-8"); |
| 937 | * const data = await Deno.readFile("hello_world.txt"); |
| 938 | * assertEquals(decoder.decode(data), "Hello world"); |
| 939 | * }); |
| 940 | * ``` |
| 941 | * |
| 942 | * @category Testing |
| 943 | */ |
| 944 | ( |
| 945 | name: string, |
| 946 | fn: (t: TestContext) => void | Promise<void>, |
| 947 | ): void; |
| 948 | |
| 949 | /** Register a test which will be run when `deno test` is used on the command |
| 950 | * line and the containing module looks like a test module. |
| 951 | * |
| 952 | * `fn` can be async if required. Declared function must have a name. |
| 953 | * |
| 954 | * ```ts |
| 955 | * import { assertEquals } from "jsr:@std/assert"; |
| 956 | * |
| 957 | * Deno.test(function myTestName() { |
| 958 | * assertEquals("hello", "hello"); |
| 959 | * }); |
| 960 | * |
| 961 | * Deno.test(async function myOtherTestName() { |
| 962 | * const decoder = new TextDecoder("utf-8"); |
| 963 | * const data = await Deno.readFile("hello_world.txt"); |
| 964 | * assertEquals(decoder.decode(data), "Hello world"); |
| 965 | * }); |
| 966 | * ``` |
| 967 | * |
| 968 | * @category Testing |
| 969 | */ |
| 970 | (fn: (t: TestContext) => void | Promise<void>): void; |
| 971 | |
| 972 | /** Register a test which will be run when `deno test` is used on the command |
| 973 | * line and the containing module looks like a test module. |
| 974 | * |
| 975 | * `fn` can be async if required. |
| 976 | * |
| 977 | * ```ts |
| 978 | * import { assert, fail, assertEquals } from "jsr:@std/assert"; |
| 979 | * |
| 980 | * Deno.test("My test description", { permissions: { read: true } }, (): void => { |
| 981 | * assertEquals("hello", "hello"); |
| 982 | * }); |
| 983 | * |
| 984 | * Deno.test("My async test description", { permissions: { read: false } }, async (): Promise<void> => { |
| 985 | * const decoder = new TextDecoder("utf-8"); |
| 986 | * const data = await Deno.readFile("hello_world.txt"); |
| 987 | * assertEquals(decoder.decode(data), "Hello world"); |
| 988 | * }); |
| 989 | * ``` |
| 990 | * |
| 991 | * @category Testing |
| 992 | */ |
| 993 | ( |
| 994 | name: string, |
| 995 | options: Omit<TestDefinition, "fn" | "name">, |
| 996 | fn: (t: TestContext) => void | Promise<void>, |
| 997 | ): void; |
| 998 | |
| 999 | /** Register a test which will be run when `deno test` is used on the command |
| 1000 | * line and the containing module looks like a test module. |
| 1001 | * |
| 1002 | * `fn` can be async if required. |
| 1003 | * |
| 1004 | * ```ts |
| 1005 | * import { assertEquals } from "jsr:@std/assert"; |
| 1006 | * |
| 1007 | * Deno.test( |
| 1008 | * { |
| 1009 | * name: "My test description", |
| 1010 | * permissions: { read: true }, |
| 1011 | * }, |
| 1012 | * () => { |
| 1013 | * assertEquals("hello", "hello"); |
| 1014 | * }, |
| 1015 | * ); |
| 1016 | * |
| 1017 | * Deno.test( |
| 1018 | * { |
| 1019 | * name: "My async test description", |
| 1020 | * permissions: { read: false }, |
| 1021 | * }, |
| 1022 | * async () => { |
| 1023 | * const decoder = new TextDecoder("utf-8"); |
| 1024 | * const data = await Deno.readFile("hello_world.txt"); |
| 1025 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1026 | * }, |
| 1027 | * ); |
| 1028 | * ``` |
| 1029 | * |
| 1030 | * @category Testing |
| 1031 | */ |
| 1032 | ( |
| 1033 | options: Omit<TestDefinition, "fn" | "name">, |
| 1034 | fn: (t: TestContext) => void | Promise<void>, |
| 1035 | ): void; |
| 1036 | |
| 1037 | /** Register a test which will be run when `deno test` is used on the command |
| 1038 | * line and the containing module looks like a test module. |
| 1039 | * |
| 1040 | * `fn` can be async if required. Declared function must have a name. |
| 1041 | * |
| 1042 | * ```ts |
| 1043 | * import { assertEquals } from "jsr:@std/assert"; |
| 1044 | * |
| 1045 | * Deno.test( |
| 1046 | * { permissions: { read: true } }, |
| 1047 | * function myTestName() { |
| 1048 | * assertEquals("hello", "hello"); |
| 1049 | * }, |
| 1050 | * ); |
| 1051 | * |
| 1052 | * Deno.test( |
| 1053 | * { permissions: { read: false } }, |
| 1054 | * async function myOtherTestName() { |
| 1055 | * const decoder = new TextDecoder("utf-8"); |
| 1056 | * const data = await Deno.readFile("hello_world.txt"); |
| 1057 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1058 | * }, |
| 1059 | * ); |
| 1060 | * ``` |
| 1061 | * |
| 1062 | * @category Testing |
| 1063 | */ |
| 1064 | ( |
| 1065 | options: Omit<TestDefinition, "fn">, |
| 1066 | fn: (t: TestContext) => void | Promise<void>, |
| 1067 | ): void; |
| 1068 | |
| 1069 | /** Shorthand property for ignoring a particular test case. |
| 1070 | * |
| 1071 | * @category Testing |
| 1072 | */ |
| 1073 | ignore(t: Omit<TestDefinition, "ignore">): void; |
| 1074 | |
| 1075 | /** Shorthand property for ignoring a particular test case. |
| 1076 | * |
| 1077 | * @category Testing |
| 1078 | */ |
| 1079 | ignore( |
| 1080 | name: string, |
| 1081 | fn: (t: TestContext) => void | Promise<void>, |
| 1082 | ): void; |
| 1083 | |
| 1084 | /** Shorthand property for ignoring a particular test case. |
| 1085 | * |
| 1086 | * @category Testing |
| 1087 | */ |
| 1088 | ignore(fn: (t: TestContext) => void | Promise<void>): void; |
| 1089 | |
| 1090 | /** Shorthand property for ignoring a particular test case. |
| 1091 | * |
| 1092 | * @category Testing |
| 1093 | */ |
| 1094 | ignore( |
| 1095 | name: string, |
| 1096 | options: Omit<TestDefinition, "fn" | "name" | "ignore">, |
| 1097 | fn: (t: TestContext) => void | Promise<void>, |
| 1098 | ): void; |
| 1099 | |
| 1100 | /** Shorthand property for ignoring a particular test case. |
| 1101 | * |
| 1102 | * @category Testing |
| 1103 | */ |
| 1104 | ignore( |
| 1105 | options: Omit<TestDefinition, "fn" | "name" | "ignore">, |
| 1106 | fn: (t: TestContext) => void | Promise<void>, |
| 1107 | ): void; |
| 1108 | |
| 1109 | /** Shorthand property for ignoring a particular test case. |
| 1110 | * |
| 1111 | * @category Testing |
| 1112 | */ |
| 1113 | ignore( |
| 1114 | options: Omit<TestDefinition, "fn" | "ignore">, |
| 1115 | fn: (t: TestContext) => void | Promise<void>, |
| 1116 | ): void; |
| 1117 | |
| 1118 | /** Shorthand property for focusing a particular test case. |
| 1119 | * |
| 1120 | * @category Testing |
| 1121 | */ |
| 1122 | only(t: Omit<TestDefinition, "only">): void; |
| 1123 | |
| 1124 | /** Shorthand property for focusing a particular test case. |
| 1125 | * |
| 1126 | * @category Testing |
| 1127 | */ |
| 1128 | only( |
| 1129 | name: string, |
| 1130 | fn: (t: TestContext) => void | Promise<void>, |
| 1131 | ): void; |
| 1132 | |
| 1133 | /** Shorthand property for focusing a particular test case. |
| 1134 | * |
| 1135 | * @category Testing |
| 1136 | */ |
| 1137 | only(fn: (t: TestContext) => void | Promise<void>): void; |
| 1138 | |
| 1139 | /** Shorthand property for focusing a particular test case. |
| 1140 | * |
| 1141 | * @category Testing |
| 1142 | */ |
| 1143 | only( |
| 1144 | name: string, |
| 1145 | options: Omit<TestDefinition, "fn" | "name" | "only">, |
| 1146 | fn: (t: TestContext) => void | Promise<void>, |
| 1147 | ): void; |
| 1148 | |
| 1149 | /** Shorthand property for focusing a particular test case. |
| 1150 | * |
| 1151 | * @category Testing |
| 1152 | */ |
| 1153 | only( |
| 1154 | options: Omit<TestDefinition, "fn" | "name" | "only">, |
| 1155 | fn: (t: TestContext) => void | Promise<void>, |
| 1156 | ): void; |
| 1157 | |
| 1158 | /** Shorthand property for focusing a particular test case. |
| 1159 | * |
| 1160 | * @category Testing |
| 1161 | */ |
| 1162 | only( |
| 1163 | options: Omit<TestDefinition, "fn" | "only">, |
| 1164 | fn: (t: TestContext) => void | Promise<void>, |
| 1165 | ): void; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Context that is passed to a benchmarked function. The instance is shared |
| 1170 | * between iterations of the benchmark. Its methods can be used for example |
| 1171 | * to override of the measured portion of the function. |
| 1172 | * |
| 1173 | * @category Testing |
| 1174 | */ |
| 1175 | export interface BenchContext { |
| 1176 | /** The current benchmark name. */ |
| 1177 | name: string; |
| 1178 | /** The string URL of the current benchmark. */ |
| 1179 | origin: string; |
| 1180 | |
| 1181 | /** Restarts the timer for the bench measurement. This should be called |
| 1182 | * after doing setup work which should not be measured. |
| 1183 | * |
| 1184 | * Warning: This method should not be used for benchmarks averaging less |
| 1185 | * than 10μs per iteration. In such cases it will be disabled but the call |
| 1186 | * will still have noticeable overhead, resulting in a warning. |
| 1187 | * |
| 1188 | * ```ts |
| 1189 | * Deno.bench("foo", async (t) => { |
| 1190 | * const data = await Deno.readFile("data.txt"); |
| 1191 | * t.start(); |
| 1192 | * // some operation on `data`... |
| 1193 | * }); |
| 1194 | * ``` |
| 1195 | */ |
| 1196 | start(): void; |
| 1197 | |
| 1198 | /** End the timer early for the bench measurement. This should be called |
| 1199 | * before doing teardown work which should not be measured. |
| 1200 | * |
| 1201 | * Warning: This method should not be used for benchmarks averaging less |
| 1202 | * than 10μs per iteration. In such cases it will be disabled but the call |
| 1203 | * will still have noticeable overhead, resulting in a warning. |
| 1204 | * |
| 1205 | * ```ts |
| 1206 | * Deno.bench("foo", async (t) => { |
| 1207 | * using file = await Deno.open("data.txt"); |
| 1208 | * t.start(); |
| 1209 | * // some operation on `file`... |
| 1210 | * t.end(); |
| 1211 | * }); |
| 1212 | * ``` |
| 1213 | */ |
| 1214 | end(): void; |
| 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * The interface for defining a benchmark test using {@linkcode Deno.bench}. |
| 1219 | * |
| 1220 | * @category Testing |
| 1221 | */ |
| 1222 | export interface BenchDefinition { |
| 1223 | /** The test function which will be benchmarked. */ |
| 1224 | fn: (b: BenchContext) => void | Promise<void>; |
| 1225 | /** The name of the test, which will be used in displaying the results. */ |
| 1226 | name: string; |
| 1227 | /** If truthy, the benchmark test will be ignored/skipped. */ |
| 1228 | ignore?: boolean; |
| 1229 | /** Group name for the benchmark. |
| 1230 | * |
| 1231 | * Grouped benchmarks produce a group time summary, where the difference |
| 1232 | * in performance between each test of the group is compared. */ |
| 1233 | group?: string; |
| 1234 | /** Benchmark should be used as the baseline for other benchmarks. |
| 1235 | * |
| 1236 | * If there are multiple baselines in a group, the first one is used as the |
| 1237 | * baseline. */ |
| 1238 | baseline?: boolean; |
| 1239 | /** If at least one bench has `only` set to true, only run benches that have |
| 1240 | * `only` set to `true` and fail the bench suite. */ |
| 1241 | only?: boolean; |
| 1242 | /** Ensure the bench case does not prematurely cause the process to exit, |
| 1243 | * for example via a call to {@linkcode Deno.exit}. |
| 1244 | * |
| 1245 | * @default {true} */ |
| 1246 | sanitizeExit?: boolean; |
| 1247 | /** Specifies the permissions that should be used to run the bench. |
| 1248 | * |
| 1249 | * Set this to `"inherit"` to keep the calling thread's permissions. |
| 1250 | * |
| 1251 | * Set this to `"none"` to revoke all permissions. |
| 1252 | * |
| 1253 | * @default {"inherit"} |
| 1254 | */ |
| 1255 | permissions?: PermissionOptions; |
| 1256 | } |
| 1257 | |
| 1258 | /** |
| 1259 | * Register a benchmark test which will be run when `deno bench` is used on |
| 1260 | * the command line and the containing module looks like a bench module. |
| 1261 | * |
| 1262 | * If the test function (`fn`) returns a promise or is async, the test runner |
| 1263 | * will await resolution to consider the test complete. |
| 1264 | * |
| 1265 | * ```ts |
| 1266 | * import { assertEquals } from "jsr:@std/assert"; |
| 1267 | * |
| 1268 | * Deno.bench({ |
| 1269 | * name: "example test", |
| 1270 | * fn() { |
| 1271 | * assertEquals("world", "world"); |
| 1272 | * }, |
| 1273 | * }); |
| 1274 | * |
| 1275 | * Deno.bench({ |
| 1276 | * name: "example ignored test", |
| 1277 | * ignore: Deno.build.os === "windows", |
| 1278 | * fn() { |
| 1279 | * // This test is ignored only on Windows machines |
| 1280 | * }, |
| 1281 | * }); |
| 1282 | * |
| 1283 | * Deno.bench({ |
| 1284 | * name: "example async test", |
| 1285 | * async fn() { |
| 1286 | * const decoder = new TextDecoder("utf-8"); |
| 1287 | * const data = await Deno.readFile("hello_world.txt"); |
| 1288 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1289 | * } |
| 1290 | * }); |
| 1291 | * ``` |
| 1292 | * |
| 1293 | * @category Testing |
| 1294 | */ |
| 1295 | export function bench(b: BenchDefinition): void; |
| 1296 | |
| 1297 | /** |
| 1298 | * Register a benchmark test which will be run when `deno bench` is used on |
| 1299 | * the command line and the containing module looks like a bench module. |
| 1300 | * |
| 1301 | * If the test function (`fn`) returns a promise or is async, the test runner |
| 1302 | * will await resolution to consider the test complete. |
| 1303 | * |
| 1304 | * ```ts |
| 1305 | * import { assertEquals } from "jsr:@std/assert"; |
| 1306 | * |
| 1307 | * Deno.bench("My test description", () => { |
| 1308 | * assertEquals("hello", "hello"); |
| 1309 | * }); |
| 1310 | * |
| 1311 | * Deno.bench("My async test description", async () => { |
| 1312 | * const decoder = new TextDecoder("utf-8"); |
| 1313 | * const data = await Deno.readFile("hello_world.txt"); |
| 1314 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1315 | * }); |
| 1316 | * ``` |
| 1317 | * |
| 1318 | * @category Testing |
| 1319 | */ |
| 1320 | export function bench( |
| 1321 | name: string, |
| 1322 | fn: (b: BenchContext) => void | Promise<void>, |
| 1323 | ): void; |
| 1324 | |
| 1325 | /** |
| 1326 | * Register a benchmark test which will be run when `deno bench` is used on |
| 1327 | * the command line and the containing module looks like a bench module. |
| 1328 | * |
| 1329 | * If the test function (`fn`) returns a promise or is async, the test runner |
| 1330 | * will await resolution to consider the test complete. |
| 1331 | * |
| 1332 | * ```ts |
| 1333 | * import { assertEquals } from "jsr:@std/assert"; |
| 1334 | * |
| 1335 | * Deno.bench(function myTestName() { |
| 1336 | * assertEquals("hello", "hello"); |
| 1337 | * }); |
| 1338 | * |
| 1339 | * Deno.bench(async function myOtherTestName() { |
| 1340 | * const decoder = new TextDecoder("utf-8"); |
| 1341 | * const data = await Deno.readFile("hello_world.txt"); |
| 1342 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1343 | * }); |
| 1344 | * ``` |
| 1345 | * |
| 1346 | * @category Testing |
| 1347 | */ |
| 1348 | export function bench(fn: (b: BenchContext) => void | Promise<void>): void; |
| 1349 | |
| 1350 | /** |
| 1351 | * Register a benchmark test which will be run when `deno bench` is used on |
| 1352 | * the command line and the containing module looks like a bench module. |
| 1353 | * |
| 1354 | * If the test function (`fn`) returns a promise or is async, the test runner |
| 1355 | * will await resolution to consider the test complete. |
| 1356 | * |
| 1357 | * ```ts |
| 1358 | * import { assertEquals } from "jsr:@std/assert"; |
| 1359 | * |
| 1360 | * Deno.bench( |
| 1361 | * "My test description", |
| 1362 | * { permissions: { read: true } }, |
| 1363 | * () => { |
| 1364 | * assertEquals("hello", "hello"); |
| 1365 | * } |
| 1366 | * ); |
| 1367 | * |
| 1368 | * Deno.bench( |
| 1369 | * "My async test description", |
| 1370 | * { permissions: { read: false } }, |
| 1371 | * async () => { |
| 1372 | * const decoder = new TextDecoder("utf-8"); |
| 1373 | * const data = await Deno.readFile("hello_world.txt"); |
| 1374 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1375 | * } |
| 1376 | * ); |
| 1377 | * ``` |
| 1378 | * |
| 1379 | * @category Testing |
| 1380 | */ |
| 1381 | export function bench( |
| 1382 | name: string, |
| 1383 | options: Omit<BenchDefinition, "fn" | "name">, |
| 1384 | fn: (b: BenchContext) => void | Promise<void>, |
| 1385 | ): void; |
| 1386 | |
| 1387 | /** |
| 1388 | * Register a benchmark test which will be run when `deno bench` is used on |
| 1389 | * the command line and the containing module looks like a bench module. |
| 1390 | * |
| 1391 | * If the test function (`fn`) returns a promise or is async, the test runner |
| 1392 | * will await resolution to consider the test complete. |
| 1393 | * |
| 1394 | * ```ts |
| 1395 | * import { assertEquals } from "jsr:@std/assert"; |
| 1396 | * |
| 1397 | * Deno.bench( |
| 1398 | * { name: "My test description", permissions: { read: true } }, |
| 1399 | * () => { |
| 1400 | * assertEquals("hello", "hello"); |
| 1401 | * } |
| 1402 | * ); |
| 1403 | * |
| 1404 | * Deno.bench( |
| 1405 | * { name: "My async test description", permissions: { read: false } }, |
| 1406 | * async () => { |
| 1407 | * const decoder = new TextDecoder("utf-8"); |
| 1408 | * const data = await Deno.readFile("hello_world.txt"); |
| 1409 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1410 | * } |
| 1411 | * ); |
| 1412 | * ``` |
| 1413 | * |
| 1414 | * @category Testing |
| 1415 | */ |
| 1416 | export function bench( |
| 1417 | options: Omit<BenchDefinition, "fn">, |
| 1418 | fn: (b: BenchContext) => void | Promise<void>, |
| 1419 | ): void; |
| 1420 | |
| 1421 | /** |
| 1422 | * Register a benchmark test which will be run when `deno bench` is used on |
| 1423 | * the command line and the containing module looks like a bench module. |
| 1424 | * |
| 1425 | * If the test function (`fn`) returns a promise or is async, the test runner |
| 1426 | * will await resolution to consider the test complete. |
| 1427 | * |
| 1428 | * ```ts |
| 1429 | * import { assertEquals } from "jsr:@std/assert"; |
| 1430 | * |
| 1431 | * Deno.bench( |
| 1432 | * { permissions: { read: true } }, |
| 1433 | * function myTestName() { |
| 1434 | * assertEquals("hello", "hello"); |
| 1435 | * } |
| 1436 | * ); |
| 1437 | * |
| 1438 | * Deno.bench( |
| 1439 | * { permissions: { read: false } }, |
| 1440 | * async function myOtherTestName() { |
| 1441 | * const decoder = new TextDecoder("utf-8"); |
| 1442 | * const data = await Deno.readFile("hello_world.txt"); |
| 1443 | * assertEquals(decoder.decode(data), "Hello world"); |
| 1444 | * } |
| 1445 | * ); |
| 1446 | * ``` |
| 1447 | * |
| 1448 | * @category Testing |
| 1449 | */ |
| 1450 | export function bench( |
| 1451 | options: Omit<BenchDefinition, "fn" | "name">, |
| 1452 | fn: (b: BenchContext) => void | Promise<void>, |
| 1453 | ): void; |
| 1454 | |
| 1455 | /** Exit the Deno process with optional exit code. |
| 1456 | * |
| 1457 | * If no exit code is supplied then Deno will exit with return code of `0`. |
| 1458 | * |
| 1459 | * In worker contexts this is an alias to `self.close();`. |
| 1460 | * |
| 1461 | * ```ts |
| 1462 | * Deno.exit(5); |
| 1463 | * ``` |
| 1464 | * |
| 1465 | * @category Runtime |
| 1466 | */ |
| 1467 | export function exit(code?: number): never; |
| 1468 | |
| 1469 | /** The exit code for the Deno process. |
| 1470 | * |
| 1471 | * If no exit code has been supplied, then Deno will assume a return code of `0`. |
| 1472 | * |
| 1473 | * When setting an exit code value, a number or non-NaN string must be provided, |
| 1474 | * otherwise a TypeError will be thrown. |
| 1475 | * |
| 1476 | * ```ts |
| 1477 | * console.log(Deno.exitCode); //-> 0 |
| 1478 | * Deno.exitCode = 1; |
| 1479 | * console.log(Deno.exitCode); //-> 1 |
| 1480 | * ``` |
| 1481 | * |
| 1482 | * @category Runtime |
| 1483 | */ |
| 1484 | export var exitCode: number; |
| 1485 | |
| 1486 | /** An interface containing methods to interact with the process environment |
| 1487 | * variables. |
| 1488 | * |
| 1489 | * @tags allow-env |
| 1490 | * @category Runtime |
| 1491 | */ |
| 1492 | export interface Env { |
| 1493 | /** Retrieve the value of an environment variable. |
| 1494 | * |
| 1495 | * Returns `undefined` if the supplied environment variable is not defined. |
| 1496 | * |
| 1497 | * ```ts |
| 1498 | * console.log(Deno.env.get("HOME")); // e.g. outputs "/home/alice" |
| 1499 | * console.log(Deno.env.get("MADE_UP_VAR")); // outputs "undefined" |
| 1500 | * ``` |
| 1501 | * |
| 1502 | * Requires `allow-env` permission. |
| 1503 | * |
| 1504 | * @tags allow-env |
| 1505 | */ |
| 1506 | get(key: string): string | undefined; |
| 1507 | |
| 1508 | /** Set the value of an environment variable. |
| 1509 | * |
| 1510 | * ```ts |
| 1511 | * Deno.env.set("SOME_VAR", "Value"); |
| 1512 | * Deno.env.get("SOME_VAR"); // outputs "Value" |
| 1513 | * ``` |
| 1514 | * |
| 1515 | * Requires `allow-env` permission. |
| 1516 | * |
| 1517 | * @tags allow-env |
| 1518 | */ |
| 1519 | set(key: string, value: string): void; |
| 1520 | |
| 1521 | /** Delete the value of an environment variable. |
| 1522 | * |
| 1523 | * ```ts |
| 1524 | * Deno.env.set("SOME_VAR", "Value"); |
| 1525 | * Deno.env.delete("SOME_VAR"); // outputs "undefined" |
| 1526 | * ``` |
| 1527 | * |
| 1528 | * Requires `allow-env` permission. |
| 1529 | * |
| 1530 | * @tags allow-env |
| 1531 | */ |
| 1532 | delete(key: string): void; |
| 1533 | |
| 1534 | /** Check whether an environment variable is present or not. |
| 1535 | * |
| 1536 | * ```ts |
| 1537 | * Deno.env.set("SOME_VAR", "Value"); |
| 1538 | * Deno.env.has("SOME_VAR"); // outputs true |
| 1539 | * ``` |
| 1540 | * |
| 1541 | * Requires `allow-env` permission. |
| 1542 | * |
| 1543 | * @tags allow-env |
| 1544 | */ |
| 1545 | has(key: string): boolean; |
| 1546 | |
| 1547 | /** Returns a snapshot of the environment variables at invocation as a |
| 1548 | * simple object of keys and values. |
| 1549 | * |
| 1550 | * ```ts |
| 1551 | * Deno.env.set("TEST_VAR", "A"); |
| 1552 | * const myEnv = Deno.env.toObject(); |
| 1553 | * console.log(myEnv.SHELL); |
| 1554 | * Deno.env.set("TEST_VAR", "B"); |
| 1555 | * console.log(myEnv.TEST_VAR); // outputs "A" |
| 1556 | * ``` |
| 1557 | * |
| 1558 | * Requires `allow-env` permission. |
| 1559 | * |
| 1560 | * @tags allow-env |
| 1561 | */ |
| 1562 | toObject(): { [index: string]: string }; |
| 1563 | } |
| 1564 | |
| 1565 | /** An interface containing methods to interact with the process environment |
| 1566 | * variables. |
| 1567 | * |
| 1568 | * @tags allow-env |
| 1569 | * @category Runtime |
| 1570 | */ |
| 1571 | export const env: Env; |
| 1572 | |
| 1573 | /** |
| 1574 | * Returns the path to the current deno executable. |
| 1575 | * |
| 1576 | * ```ts |
| 1577 | * console.log(Deno.execPath()); // e.g. "/home/alice/.local/bin/deno" |
| 1578 | * ``` |
| 1579 | * |
| 1580 | * Requires `allow-read` permission. |
| 1581 | * |
| 1582 | * @tags allow-read |
| 1583 | * @category Runtime |
| 1584 | */ |
| 1585 | export function execPath(): string; |
| 1586 | |
| 1587 | /** |
| 1588 | * Change the current working directory to the specified path. |
| 1589 | * |
| 1590 | * ```ts |
| 1591 | * Deno.chdir("/home/userA"); |
| 1592 | * Deno.chdir("../userB"); |
| 1593 | * Deno.chdir("C:\\Program Files (x86)\\Java"); |
| 1594 | * ``` |
| 1595 | * |
| 1596 | * Throws {@linkcode Deno.errors.NotFound} if directory not found. |
| 1597 | * |
| 1598 | * Throws {@linkcode Deno.errors.PermissionDenied} if the user does not have |
| 1599 | * operating system file access rights. |
| 1600 | * |
| 1601 | * Requires `allow-read` permission. |
| 1602 | * |
| 1603 | * @tags allow-read |
| 1604 | * @category Runtime |
| 1605 | */ |
| 1606 | export function chdir(directory: string | URL): void; |
| 1607 | |
| 1608 | /** |
| 1609 | * Return a string representing the current working directory. |
| 1610 | * |
| 1611 | * If the current directory can be reached via multiple paths (due to symbolic |
| 1612 | * links), `cwd()` may return any one of them. |
| 1613 | * |
| 1614 | * ```ts |
| 1615 | * const currentWorkingDirectory = Deno.cwd(); |
| 1616 | * ``` |
| 1617 | * |
| 1618 | * Throws {@linkcode Deno.errors.NotFound} if directory not available. |
| 1619 | * |
| 1620 | * Requires `allow-read` permission. |
| 1621 | * |
| 1622 | * @tags allow-read |
| 1623 | * @category Runtime |
| 1624 | */ |
| 1625 | export function cwd(): string; |
| 1626 | |
| 1627 | /** |
| 1628 | * Creates `newpath` as a hard link to `oldpath`. |
| 1629 | * |
| 1630 | * ```ts |
| 1631 | * await Deno.link("old/name", "new/name"); |
| 1632 | * ``` |
| 1633 | * |
| 1634 | * Requires `allow-read` and `allow-write` permissions. |
| 1635 | * |
| 1636 | * @tags allow-read, allow-write |
| 1637 | * @category File System |
| 1638 | */ |
| 1639 | export function link(oldpath: string, newpath: string): Promise<void>; |
| 1640 | |
| 1641 | /** |
| 1642 | * Synchronously creates `newpath` as a hard link to `oldpath`. |
| 1643 | * |
| 1644 | * ```ts |
| 1645 | * Deno.linkSync("old/name", "new/name"); |
| 1646 | * ``` |
| 1647 | * |
| 1648 | * Requires `allow-read` and `allow-write` permissions. |
| 1649 | * |
| 1650 | * @tags allow-read, allow-write |
| 1651 | * @category File System |
| 1652 | */ |
| 1653 | export function linkSync(oldpath: string, newpath: string): void; |
| 1654 | |
| 1655 | /** |
| 1656 | * A enum which defines the seek mode for IO related APIs that support |
| 1657 | * seeking. |
| 1658 | * |
| 1659 | * @category I/O */ |
| 1660 | export enum SeekMode { |
| 1661 | /* Seek from the start of the file/resource. */ |
| 1662 | Start = 0, |
| 1663 | /* Seek from the current position within the file/resource. */ |
| 1664 | Current = 1, |
| 1665 | /* Seek from the end of the current file/resource. */ |
| 1666 | End = 2, |
| 1667 | } |
| 1668 | |
| 1669 | /** |
| 1670 | * An abstract interface which when implemented provides an interface to read |
| 1671 | * bytes into an array buffer asynchronously. |
| 1672 | * |
| 1673 | * @deprecated This will be removed in Deno 2.0. See the |
| 1674 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1675 | * for migration instructions. |
| 1676 | * |
| 1677 | * @category I/O */ |
| 1678 | export interface Reader { |
| 1679 | /** Reads up to `p.byteLength` bytes into `p`. It resolves to the number of |
| 1680 | * bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error |
| 1681 | * encountered. Even if `read()` resolves to `n` < `p.byteLength`, it may |
| 1682 | * use all of `p` as scratch space during the call. If some data is |
| 1683 | * available but not `p.byteLength` bytes, `read()` conventionally resolves |
| 1684 | * to what is available instead of waiting for more. |
| 1685 | * |
| 1686 | * When `read()` encounters end-of-file condition, it resolves to EOF |
| 1687 | * (`null`). |
| 1688 | * |
| 1689 | * When `read()` encounters an error, it rejects with an error. |
| 1690 | * |
| 1691 | * Callers should always process the `n` > `0` bytes returned before |
| 1692 | * considering the EOF (`null`). Doing so correctly handles I/O errors that |
| 1693 | * happen after reading some bytes and also both of the allowed EOF |
| 1694 | * behaviors. |
| 1695 | * |
| 1696 | * Implementations should not retain a reference to `p`. |
| 1697 | * |
| 1698 | * Use |
| 1699 | * {@linkcode https://jsr.io/@std/io/doc/iterate-reader/~/iterateReader | iterateReader} |
| 1700 | * to turn {@linkcode Reader} into an {@linkcode AsyncIterator}. |
| 1701 | */ |
| 1702 | read(p: Uint8Array): Promise<number | null>; |
| 1703 | } |
| 1704 | |
| 1705 | /** |
| 1706 | * An abstract interface which when implemented provides an interface to read |
| 1707 | * bytes into an array buffer synchronously. |
| 1708 | * |
| 1709 | * @deprecated This will be removed in Deno 2.0. See the |
| 1710 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1711 | * for migration instructions. |
| 1712 | * |
| 1713 | * @category I/O */ |
| 1714 | export interface ReaderSync { |
| 1715 | /** Reads up to `p.byteLength` bytes into `p`. It resolves to the number |
| 1716 | * of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error |
| 1717 | * encountered. Even if `readSync()` returns `n` < `p.byteLength`, it may use |
| 1718 | * all of `p` as scratch space during the call. If some data is available |
| 1719 | * but not `p.byteLength` bytes, `readSync()` conventionally returns what is |
| 1720 | * available instead of waiting for more. |
| 1721 | * |
| 1722 | * When `readSync()` encounters end-of-file condition, it returns EOF |
| 1723 | * (`null`). |
| 1724 | * |
| 1725 | * When `readSync()` encounters an error, it throws with an error. |
| 1726 | * |
| 1727 | * Callers should always process the `n` > `0` bytes returned before |
| 1728 | * considering the EOF (`null`). Doing so correctly handles I/O errors that |
| 1729 | * happen after reading some bytes and also both of the allowed EOF |
| 1730 | * behaviors. |
| 1731 | * |
| 1732 | * Implementations should not retain a reference to `p`. |
| 1733 | * |
| 1734 | * Use |
| 1735 | * {@linkcode https://jsr.io/@std/io/doc/iterate-reader/~/iterateReaderSync | iterateReaderSync} |
| 1736 | * to turn {@linkcode ReaderSync} into an {@linkcode Iterator}. |
| 1737 | */ |
| 1738 | readSync(p: Uint8Array): number | null; |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * An abstract interface which when implemented provides an interface to write |
| 1743 | * bytes from an array buffer to a file/resource asynchronously. |
| 1744 | * |
| 1745 | * @deprecated This will be removed in Deno 2.0. See the |
| 1746 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1747 | * for migration instructions. |
| 1748 | * |
| 1749 | * @category I/O */ |
| 1750 | export interface Writer { |
| 1751 | /** Writes `p.byteLength` bytes from `p` to the underlying data stream. It |
| 1752 | * resolves to the number of bytes written from `p` (`0` <= `n` <= |
| 1753 | * `p.byteLength`) or reject with the error encountered that caused the |
| 1754 | * write to stop early. `write()` must reject with a non-null error if |
| 1755 | * would resolve to `n` < `p.byteLength`. `write()` must not modify the |
| 1756 | * slice data, even temporarily. |
| 1757 | * |
| 1758 | * This function is one of the lowest |
| 1759 | * level APIs and most users should not work with this directly, but rather |
| 1760 | * use {@linkcode https://jsr.io/@std/io/doc/write-all/~/writeAll | writeAll} |
| 1761 | * instead. |
| 1762 | * |
| 1763 | * Implementations should not retain a reference to `p`. |
| 1764 | */ |
| 1765 | write(p: Uint8Array): Promise<number>; |
| 1766 | } |
| 1767 | |
| 1768 | /** |
| 1769 | * An abstract interface which when implemented provides an interface to write |
| 1770 | * bytes from an array buffer to a file/resource synchronously. |
| 1771 | * |
| 1772 | * @deprecated This will be removed in Deno 2.0. See the |
| 1773 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1774 | * for migration instructions. |
| 1775 | * |
| 1776 | * @category I/O */ |
| 1777 | export interface WriterSync { |
| 1778 | /** Writes `p.byteLength` bytes from `p` to the underlying data |
| 1779 | * stream. It returns the number of bytes written from `p` (`0` <= `n` |
| 1780 | * <= `p.byteLength`) and any error encountered that caused the write to |
| 1781 | * stop early. `writeSync()` must throw a non-null error if it returns `n` < |
| 1782 | * `p.byteLength`. `writeSync()` must not modify the slice data, even |
| 1783 | * temporarily. |
| 1784 | * |
| 1785 | * Implementations should not retain a reference to `p`. |
| 1786 | */ |
| 1787 | writeSync(p: Uint8Array): number; |
| 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * An abstract interface which when implemented provides an interface to close |
| 1792 | * files/resources that were previously opened. |
| 1793 | * |
| 1794 | * @deprecated This will be removed in Deno 2.0. See the |
| 1795 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1796 | * for migration instructions. |
| 1797 | * |
| 1798 | * @category I/O */ |
| 1799 | export interface Closer { |
| 1800 | /** Closes the resource, "freeing" the backing file/resource. */ |
| 1801 | close(): void; |
| 1802 | } |
| 1803 | |
| 1804 | /** |
| 1805 | * An abstract interface which when implemented provides an interface to seek |
| 1806 | * within an open file/resource asynchronously. |
| 1807 | * |
| 1808 | * @category I/O */ |
| 1809 | export interface Seeker { |
| 1810 | /** Seek sets the offset for the next `read()` or `write()` to offset, |
| 1811 | * interpreted according to `whence`: `Start` means relative to the |
| 1812 | * start of the file, `Current` means relative to the current offset, |
| 1813 | * and `End` means relative to the end. Seek resolves to the new offset |
| 1814 | * relative to the start of the file. |
| 1815 | * |
| 1816 | * Seeking to an offset before the start of the file is an error. Seeking to |
| 1817 | * any positive offset is legal, but the behavior of subsequent I/O |
| 1818 | * operations on the underlying object is implementation-dependent. |
| 1819 | * |
| 1820 | * It resolves with the updated offset. |
| 1821 | */ |
| 1822 | seek(offset: number | bigint, whence: SeekMode): Promise<number>; |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * An abstract interface which when implemented provides an interface to seek |
| 1827 | * within an open file/resource synchronously. |
| 1828 | * |
| 1829 | * @category I/O */ |
| 1830 | export interface SeekerSync { |
| 1831 | /** Seek sets the offset for the next `readSync()` or `writeSync()` to |
| 1832 | * offset, interpreted according to `whence`: `Start` means relative |
| 1833 | * to the start of the file, `Current` means relative to the current |
| 1834 | * offset, and `End` means relative to the end. |
| 1835 | * |
| 1836 | * Seeking to an offset before the start of the file is an error. Seeking to |
| 1837 | * any positive offset is legal, but the behavior of subsequent I/O |
| 1838 | * operations on the underlying object is implementation-dependent. |
| 1839 | * |
| 1840 | * It returns the updated offset. |
| 1841 | */ |
| 1842 | seekSync(offset: number | bigint, whence: SeekMode): number; |
| 1843 | } |
| 1844 | |
| 1845 | /** |
| 1846 | * Copies from `src` to `dst` until either EOF (`null`) is read from `src` or |
| 1847 | * an error occurs. It resolves to the number of bytes copied or rejects with |
| 1848 | * the first error encountered while copying. |
| 1849 | * |
| 1850 | * @deprecated This will be removed in Deno 2.0. See the |
| 1851 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1852 | * for migration instructions. |
| 1853 | * |
| 1854 | * @category I/O |
| 1855 | * |
| 1856 | * @param src The source to copy from |
| 1857 | * @param dst The destination to copy to |
| 1858 | * @param options Can be used to tune size of the buffer. Default size is 32kB |
| 1859 | */ |
| 1860 | export function copy( |
| 1861 | src: Reader, |
| 1862 | dst: Writer, |
| 1863 | options?: { bufSize?: number }, |
| 1864 | ): Promise<number>; |
| 1865 | |
| 1866 | /** |
| 1867 | * Turns a Reader, `r`, into an async iterator. |
| 1868 | * |
| 1869 | * @deprecated This will be removed in Deno 2.0. See the |
| 1870 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1871 | * for migration instructions. |
| 1872 | * |
| 1873 | * @category I/O |
| 1874 | */ |
| 1875 | export function iter( |
| 1876 | r: Reader, |
| 1877 | options?: { bufSize?: number }, |
| 1878 | ): AsyncIterableIterator<Uint8Array>; |
| 1879 | |
| 1880 | /** |
| 1881 | * Turns a ReaderSync, `r`, into an iterator. |
| 1882 | * |
| 1883 | * @deprecated This will be removed in Deno 2.0. See the |
| 1884 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 1885 | * for migration instructions. |
| 1886 | * |
| 1887 | * @category I/O |
| 1888 | */ |
| 1889 | export function iterSync( |
| 1890 | r: ReaderSync, |
| 1891 | options?: { |
| 1892 | bufSize?: number; |
| 1893 | }, |
| 1894 | ): IterableIterator<Uint8Array>; |
| 1895 | |
| 1896 | /** Open a file and resolve to an instance of {@linkcode Deno.FsFile}. The |
| 1897 | * file does not need to previously exist if using the `create` or `createNew` |
| 1898 | * open options. The caller may have the resulting file automatically closed |
| 1899 | * by the runtime once it's out of scope by declaring the file variable with |
| 1900 | * the `using` keyword. |
| 1901 | * |
| 1902 | * ```ts |
| 1903 | * using file = await Deno.open("/foo/bar.txt", { read: true, write: true }); |
| 1904 | * // Do work with file |
| 1905 | * ``` |
| 1906 | * |
| 1907 | * Alternatively, the caller may manually close the resource when finished with |
| 1908 | * it. |
| 1909 | * |
| 1910 | * ```ts |
| 1911 | * const file = await Deno.open("/foo/bar.txt", { read: true, write: true }); |
| 1912 | * // Do work with file |
| 1913 | * file.close(); |
| 1914 | * ``` |
| 1915 | * |
| 1916 | * Requires `allow-read` and/or `allow-write` permissions depending on |
| 1917 | * options. |
| 1918 | * |
| 1919 | * @tags allow-read, allow-write |
| 1920 | * @category File System |
| 1921 | */ |
| 1922 | export function open( |
| 1923 | path: string | URL, |
| 1924 | options?: OpenOptions, |
| 1925 | ): Promise<FsFile>; |
| 1926 | |
| 1927 | /** Synchronously open a file and return an instance of |
| 1928 | * {@linkcode Deno.FsFile}. The file does not need to previously exist if |
| 1929 | * using the `create` or `createNew` open options. The caller may have the |
| 1930 | * resulting file automatically closed by the runtime once it's out of scope |
| 1931 | * by declaring the file variable with the `using` keyword. |
| 1932 | * |
| 1933 | * ```ts |
| 1934 | * using file = Deno.openSync("/foo/bar.txt", { read: true, write: true }); |
| 1935 | * // Do work with file |
| 1936 | * ``` |
| 1937 | * |
| 1938 | * Alternatively, the caller may manually close the resource when finished with |
| 1939 | * it. |
| 1940 | * |
| 1941 | * ```ts |
| 1942 | * const file = Deno.openSync("/foo/bar.txt", { read: true, write: true }); |
| 1943 | * // Do work with file |
| 1944 | * file.close(); |
| 1945 | * ``` |
| 1946 | * |
| 1947 | * Requires `allow-read` and/or `allow-write` permissions depending on |
| 1948 | * options. |
| 1949 | * |
| 1950 | * @tags allow-read, allow-write |
| 1951 | * @category File System |
| 1952 | */ |
| 1953 | export function openSync(path: string | URL, options?: OpenOptions): FsFile; |
| 1954 | |
| 1955 | /** Creates a file if none exists or truncates an existing file and resolves to |
| 1956 | * an instance of {@linkcode Deno.FsFile}. |
| 1957 | * |
| 1958 | * ```ts |
| 1959 | * const file = await Deno.create("/foo/bar.txt"); |
| 1960 | * ``` |
| 1961 | * |
| 1962 | * Requires `allow-read` and `allow-write` permissions. |
| 1963 | * |
| 1964 | * @tags allow-read, allow-write |
| 1965 | * @category File System |
| 1966 | */ |
| 1967 | export function create(path: string | URL): Promise<FsFile>; |
| 1968 | |
| 1969 | /** Creates a file if none exists or truncates an existing file and returns |
| 1970 | * an instance of {@linkcode Deno.FsFile}. |
| 1971 | * |
| 1972 | * ```ts |
| 1973 | * const file = Deno.createSync("/foo/bar.txt"); |
| 1974 | * ``` |
| 1975 | * |
| 1976 | * Requires `allow-read` and `allow-write` permissions. |
| 1977 | * |
| 1978 | * @tags allow-read, allow-write |
| 1979 | * @category File System |
| 1980 | */ |
| 1981 | export function createSync(path: string | URL): FsFile; |
| 1982 | |
| 1983 | /** Read from a resource ID (`rid`) into an array buffer (`buffer`). |
| 1984 | * |
| 1985 | * Resolves to either the number of bytes read during the operation or EOF |
| 1986 | * (`null`) if there was nothing more to read. |
| 1987 | * |
| 1988 | * It is possible for a read to successfully return with `0` bytes. This does |
| 1989 | * not indicate EOF. |
| 1990 | * |
| 1991 | * This function is one of the lowest level APIs and most users should not |
| 1992 | * work with this directly, but rather use {@linkcode ReadableStream} and |
| 1993 | * {@linkcode https://jsr.io/@std/streams/doc/to-array-buffer/~/toArrayBuffer | toArrayBuffer} |
| 1994 | * instead. |
| 1995 | * |
| 1996 | * **It is not guaranteed that the full buffer will be read in a single call.** |
| 1997 | * |
| 1998 | * ```ts |
| 1999 | * // if "/foo/bar.txt" contains the text "hello world": |
| 2000 | * using file = await Deno.open("/foo/bar.txt"); |
| 2001 | * const buf = new Uint8Array(100); |
| 2002 | * const numberOfBytesRead = await Deno.read(file.rid, buf); // 11 bytes |
| 2003 | * const text = new TextDecoder().decode(buf); // "hello world" |
| 2004 | * ``` |
| 2005 | * |
| 2006 | * @deprecated This will be removed in Deno 2.0. See the |
| 2007 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2008 | * for migration instructions. |
| 2009 | * |
| 2010 | * @category I/O |
| 2011 | */ |
| 2012 | export function read(rid: number, buffer: Uint8Array): Promise<number | null>; |
| 2013 | |
| 2014 | /** Synchronously read from a resource ID (`rid`) into an array buffer |
| 2015 | * (`buffer`). |
| 2016 | * |
| 2017 | * Returns either the number of bytes read during the operation or EOF |
| 2018 | * (`null`) if there was nothing more to read. |
| 2019 | * |
| 2020 | * It is possible for a read to successfully return with `0` bytes. This does |
| 2021 | * not indicate EOF. |
| 2022 | * |
| 2023 | * This function is one of the lowest level APIs and most users should not |
| 2024 | * work with this directly, but rather use {@linkcode ReadableStream} and |
| 2025 | * {@linkcode https://jsr.io/@std/streams/doc/to-array-buffer/~/toArrayBuffer | toArrayBuffer} |
| 2026 | * instead. |
| 2027 | * |
| 2028 | * **It is not guaranteed that the full buffer will be read in a single |
| 2029 | * call.** |
| 2030 | * |
| 2031 | * ```ts |
| 2032 | * // if "/foo/bar.txt" contains the text "hello world": |
| 2033 | * using file = Deno.openSync("/foo/bar.txt"); |
| 2034 | * const buf = new Uint8Array(100); |
| 2035 | * const numberOfBytesRead = Deno.readSync(file.rid, buf); // 11 bytes |
| 2036 | * const text = new TextDecoder().decode(buf); // "hello world" |
| 2037 | * ``` |
| 2038 | * |
| 2039 | * @deprecated This will be removed in Deno 2.0. See the |
| 2040 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2041 | * for migration instructions. |
| 2042 | * |
| 2043 | * @category I/O |
| 2044 | */ |
| 2045 | export function readSync(rid: number, buffer: Uint8Array): number | null; |
| 2046 | |
| 2047 | /** Write to the resource ID (`rid`) the contents of the array buffer (`data`). |
| 2048 | * |
| 2049 | * Resolves to the number of bytes written. This function is one of the lowest |
| 2050 | * level APIs and most users should not work with this directly, but rather |
| 2051 | * use {@linkcode WritableStream}, {@linkcode ReadableStream.from} and |
| 2052 | * {@linkcode ReadableStream.pipeTo}. |
| 2053 | * |
| 2054 | * **It is not guaranteed that the full buffer will be written in a single |
| 2055 | * call.** |
| 2056 | * |
| 2057 | * ```ts |
| 2058 | * const encoder = new TextEncoder(); |
| 2059 | * const data = encoder.encode("Hello world"); |
| 2060 | * using file = await Deno.open("/foo/bar.txt", { write: true }); |
| 2061 | * const bytesWritten = await Deno.write(file.rid, data); // 11 |
| 2062 | * ``` |
| 2063 | * |
| 2064 | * @deprecated This will be removed in Deno 2.0. See the |
| 2065 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2066 | * for migration instructions. |
| 2067 | * |
| 2068 | * @category I/O |
| 2069 | */ |
| 2070 | export function write(rid: number, data: Uint8Array): Promise<number>; |
| 2071 | |
| 2072 | /** Synchronously write to the resource ID (`rid`) the contents of the array |
| 2073 | * buffer (`data`). |
| 2074 | * |
| 2075 | * Returns the number of bytes written. This function is one of the lowest |
| 2076 | * level APIs and most users should not work with this directly, but rather |
| 2077 | * use {@linkcode WritableStream}, {@linkcode ReadableStream.from} and |
| 2078 | * {@linkcode ReadableStream.pipeTo}. |
| 2079 | * |
| 2080 | * **It is not guaranteed that the full buffer will be written in a single |
| 2081 | * call.** |
| 2082 | * |
| 2083 | * ```ts |
| 2084 | * const encoder = new TextEncoder(); |
| 2085 | * const data = encoder.encode("Hello world"); |
| 2086 | * using file = Deno.openSync("/foo/bar.txt", { write: true }); |
| 2087 | * const bytesWritten = Deno.writeSync(file.rid, data); // 11 |
| 2088 | * ``` |
| 2089 | * |
| 2090 | * @deprecated This will be removed in Deno 2.0. See the |
| 2091 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2092 | * for migration instructions. |
| 2093 | * |
| 2094 | * @category I/O |
| 2095 | */ |
| 2096 | export function writeSync(rid: number, data: Uint8Array): number; |
| 2097 | |
| 2098 | /** Seek a resource ID (`rid`) to the given `offset` under mode given by `whence`. |
| 2099 | * The call resolves to the new position within the resource (bytes from the start). |
| 2100 | * |
| 2101 | * ```ts |
| 2102 | * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: |
| 2103 | * using file = await Deno.open( |
| 2104 | * "hello.txt", |
| 2105 | * { read: true, write: true, truncate: true, create: true }, |
| 2106 | * ); |
| 2107 | * await file.write(new TextEncoder().encode("Hello world")); |
| 2108 | * |
| 2109 | * // advance cursor 6 bytes |
| 2110 | * const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.Start); |
| 2111 | * console.log(cursorPosition); // 6 |
| 2112 | * const buf = new Uint8Array(100); |
| 2113 | * await file.read(buf); |
| 2114 | * console.log(new TextDecoder().decode(buf)); // "world" |
| 2115 | * ``` |
| 2116 | * |
| 2117 | * The seek modes work as follows: |
| 2118 | * |
| 2119 | * ```ts |
| 2120 | * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: |
| 2121 | * using file = await Deno.open( |
| 2122 | * "hello.txt", |
| 2123 | * { read: true, write: true, truncate: true, create: true }, |
| 2124 | * ); |
| 2125 | * await file.write(new TextEncoder().encode("Hello world")); |
| 2126 | * |
| 2127 | * // Seek 6 bytes from the start of the file |
| 2128 | * console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.Start)); // "6" |
| 2129 | * // Seek 2 more bytes from the current position |
| 2130 | * console.log(await Deno.seek(file.rid, 2, Deno.SeekMode.Current)); // "8" |
| 2131 | * // Seek backwards 2 bytes from the end of the file |
| 2132 | * console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.End)); // "9" (i.e. 11-2) |
| 2133 | * ``` |
| 2134 | * |
| 2135 | * @deprecated This will be removed in Deno 2.0. See the |
| 2136 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2137 | * for migration instructions. |
| 2138 | * |
| 2139 | * @category I/O |
| 2140 | */ |
| 2141 | export function seek( |
| 2142 | rid: number, |
| 2143 | offset: number | bigint, |
| 2144 | whence: SeekMode, |
| 2145 | ): Promise<number>; |
| 2146 | |
| 2147 | /** Synchronously seek a resource ID (`rid`) to the given `offset` under mode |
| 2148 | * given by `whence`. The new position within the resource (bytes from the |
| 2149 | * start) is returned. |
| 2150 | * |
| 2151 | * ```ts |
| 2152 | * using file = Deno.openSync( |
| 2153 | * "hello.txt", |
| 2154 | * { read: true, write: true, truncate: true, create: true }, |
| 2155 | * ); |
| 2156 | * file.writeSync(new TextEncoder().encode("Hello world")); |
| 2157 | * |
| 2158 | * // advance cursor 6 bytes |
| 2159 | * const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.Start); |
| 2160 | * console.log(cursorPosition); // 6 |
| 2161 | * const buf = new Uint8Array(100); |
| 2162 | * file.readSync(buf); |
| 2163 | * console.log(new TextDecoder().decode(buf)); // "world" |
| 2164 | * ``` |
| 2165 | * |
| 2166 | * The seek modes work as follows: |
| 2167 | * |
| 2168 | * ```ts |
| 2169 | * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: |
| 2170 | * using file = Deno.openSync( |
| 2171 | * "hello.txt", |
| 2172 | * { read: true, write: true, truncate: true, create: true }, |
| 2173 | * ); |
| 2174 | * file.writeSync(new TextEncoder().encode("Hello world")); |
| 2175 | * |
| 2176 | * // Seek 6 bytes from the start of the file |
| 2177 | * console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.Start)); // "6" |
| 2178 | * // Seek 2 more bytes from the current position |
| 2179 | * console.log(Deno.seekSync(file.rid, 2, Deno.SeekMode.Current)); // "8" |
| 2180 | * // Seek backwards 2 bytes from the end of the file |
| 2181 | * console.log(Deno.seekSync(file.rid, -2, Deno.SeekMode.End)); // "9" (i.e. 11-2) |
| 2182 | * ``` |
| 2183 | * |
| 2184 | * @deprecated This will be removed in Deno 2.0. See the |
| 2185 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2186 | * for migration instructions. |
| 2187 | * |
| 2188 | * @category I/O |
| 2189 | */ |
| 2190 | export function seekSync( |
| 2191 | rid: number, |
| 2192 | offset: number | bigint, |
| 2193 | whence: SeekMode, |
| 2194 | ): number; |
| 2195 | |
| 2196 | /** |
| 2197 | * Flushes any pending data and metadata operations of the given file stream |
| 2198 | * to disk. |
| 2199 | * |
| 2200 | * ```ts |
| 2201 | * const file = await Deno.open( |
| 2202 | * "my_file.txt", |
| 2203 | * { read: true, write: true, create: true }, |
| 2204 | * ); |
| 2205 | * await file.write(new TextEncoder().encode("Hello World")); |
| 2206 | * await file.truncate(1); |
| 2207 | * await Deno.fsync(file.rid); |
| 2208 | * console.log(await Deno.readTextFile("my_file.txt")); // H |
| 2209 | * ``` |
| 2210 | * |
| 2211 | * @category File System |
| 2212 | */ |
| 2213 | export function fsync(rid: number): Promise<void>; |
| 2214 | |
| 2215 | /** |
| 2216 | * Synchronously flushes any pending data and metadata operations of the given |
| 2217 | * file stream to disk. |
| 2218 | * |
| 2219 | * ```ts |
| 2220 | * const file = Deno.openSync( |
| 2221 | * "my_file.txt", |
| 2222 | * { read: true, write: true, create: true }, |
| 2223 | * ); |
| 2224 | * file.writeSync(new TextEncoder().encode("Hello World")); |
| 2225 | * file.truncateSync(1); |
| 2226 | * Deno.fsyncSync(file.rid); |
| 2227 | * console.log(Deno.readTextFileSync("my_file.txt")); // H |
| 2228 | * ``` |
| 2229 | * |
| 2230 | * @category File System |
| 2231 | */ |
| 2232 | export function fsyncSync(rid: number): void; |
| 2233 | |
| 2234 | /** |
| 2235 | * Flushes any pending data operations of the given file stream to disk. |
| 2236 | * ```ts |
| 2237 | * const file = await Deno.open( |
| 2238 | * "my_file.txt", |
| 2239 | * { read: true, write: true, create: true }, |
| 2240 | * ); |
| 2241 | * await file.write(new TextEncoder().encode("Hello World")); |
| 2242 | * await Deno.fdatasync(file.rid); |
| 2243 | * console.log(await Deno.readTextFile("my_file.txt")); // Hello World |
| 2244 | * ``` |
| 2245 | * |
| 2246 | * @category File System |
| 2247 | */ |
| 2248 | export function fdatasync(rid: number): Promise<void>; |
| 2249 | |
| 2250 | /** |
| 2251 | * Synchronously flushes any pending data operations of the given file stream |
| 2252 | * to disk. |
| 2253 | * |
| 2254 | * ```ts |
| 2255 | * const file = Deno.openSync( |
| 2256 | * "my_file.txt", |
| 2257 | * { read: true, write: true, create: true }, |
| 2258 | * ); |
| 2259 | * file.writeSync(new TextEncoder().encode("Hello World")); |
| 2260 | * Deno.fdatasyncSync(file.rid); |
| 2261 | * console.log(Deno.readTextFileSync("my_file.txt")); // Hello World |
| 2262 | * ``` |
| 2263 | * |
| 2264 | * @category File System |
| 2265 | */ |
| 2266 | export function fdatasyncSync(rid: number): void; |
| 2267 | |
| 2268 | /** Close the given resource ID (`rid`) which has been previously opened, such |
| 2269 | * as via opening or creating a file. Closing a file when you are finished |
| 2270 | * with it is important to avoid leaking resources. |
| 2271 | * |
| 2272 | * ```ts |
| 2273 | * const file = await Deno.open("my_file.txt"); |
| 2274 | * // do work with "file" object |
| 2275 | * Deno.close(file.rid); |
| 2276 | * ``` |
| 2277 | * |
| 2278 | * It is recommended to define the variable with the `using` keyword so the |
| 2279 | * runtime will automatically close the resource when it goes out of scope. |
| 2280 | * Doing so negates the need to manually close the resource. |
| 2281 | * |
| 2282 | * ```ts |
| 2283 | * using file = await Deno.open("my_file.txt"); |
| 2284 | * // do work with "file" object |
| 2285 | * ``` |
| 2286 | * |
| 2287 | * @deprecated This will be removed in Deno 2.0. See the |
| 2288 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2289 | * for migration instructions. |
| 2290 | * |
| 2291 | * @category I/O |
| 2292 | */ |
| 2293 | export function close(rid: number): void; |
| 2294 | |
| 2295 | /** The Deno abstraction for reading and writing files. |
| 2296 | * |
| 2297 | * This is the most straight forward way of handling files within Deno and is |
| 2298 | * recommended over using the discrete functions within the `Deno` namespace. |
| 2299 | * |
| 2300 | * ```ts |
| 2301 | * using file = await Deno.open("/foo/bar.txt", { read: true }); |
| 2302 | * const fileInfo = await file.stat(); |
| 2303 | * if (fileInfo.isFile) { |
| 2304 | * const buf = new Uint8Array(100); |
| 2305 | * const numberOfBytesRead = await file.read(buf); // 11 bytes |
| 2306 | * const text = new TextDecoder().decode(buf); // "hello world" |
| 2307 | * } |
| 2308 | * ``` |
| 2309 | * |
| 2310 | * @category File System |
| 2311 | */ |
| 2312 | export class FsFile |
| 2313 | implements |
| 2314 | Reader, |
| 2315 | ReaderSync, |
| 2316 | Writer, |
| 2317 | WriterSync, |
| 2318 | Seeker, |
| 2319 | SeekerSync, |
| 2320 | Closer, |
| 2321 | Disposable { |
| 2322 | /** |
| 2323 | * The resource ID associated with the file instance. The resource ID |
| 2324 | * should be considered an opaque reference to resource. |
| 2325 | * |
| 2326 | * @deprecated This will be removed in Deno 2.0. See the |
| 2327 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2328 | * for migration instructions. |
| 2329 | */ |
| 2330 | readonly rid: number; |
| 2331 | /** A {@linkcode ReadableStream} instance representing to the byte contents |
| 2332 | * of the file. This makes it easy to interoperate with other web streams |
| 2333 | * based APIs. |
| 2334 | * |
| 2335 | * ```ts |
| 2336 | * using file = await Deno.open("my_file.txt", { read: true }); |
| 2337 | * const decoder = new TextDecoder(); |
| 2338 | * for await (const chunk of file.readable) { |
| 2339 | * console.log(decoder.decode(chunk)); |
| 2340 | * } |
| 2341 | * ``` |
| 2342 | */ |
| 2343 | readonly readable: ReadableStream<Uint8Array>; |
| 2344 | /** A {@linkcode WritableStream} instance to write the contents of the |
| 2345 | * file. This makes it easy to interoperate with other web streams based |
| 2346 | * APIs. |
| 2347 | * |
| 2348 | * ```ts |
| 2349 | * const items = ["hello", "world"]; |
| 2350 | * using file = await Deno.open("my_file.txt", { write: true }); |
| 2351 | * const encoder = new TextEncoder(); |
| 2352 | * const writer = file.writable.getWriter(); |
| 2353 | * for (const item of items) { |
| 2354 | * await writer.write(encoder.encode(item)); |
| 2355 | * } |
| 2356 | * ``` |
| 2357 | */ |
| 2358 | readonly writable: WritableStream<Uint8Array>; |
| 2359 | /** |
| 2360 | * The constructor which takes a resource ID. Generally `FsFile` should |
| 2361 | * not be constructed directly. Instead use {@linkcode Deno.open} or |
| 2362 | * {@linkcode Deno.openSync} to create a new instance of `FsFile`. |
| 2363 | * |
| 2364 | * @deprecated This will be removed in Deno 2.0. See the |
| 2365 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2366 | * for migration instructions. |
| 2367 | */ |
| 2368 | constructor(rid: number); |
| 2369 | /** Write the contents of the array buffer (`p`) to the file. |
| 2370 | * |
| 2371 | * Resolves to the number of bytes written. |
| 2372 | * |
| 2373 | * **It is not guaranteed that the full buffer will be written in a single |
| 2374 | * call.** |
| 2375 | * |
| 2376 | * ```ts |
| 2377 | * const encoder = new TextEncoder(); |
| 2378 | * const data = encoder.encode("Hello world"); |
| 2379 | * using file = await Deno.open("/foo/bar.txt", { write: true }); |
| 2380 | * const bytesWritten = await file.write(data); // 11 |
| 2381 | * ``` |
| 2382 | * |
| 2383 | * @category I/O |
| 2384 | */ |
| 2385 | write(p: Uint8Array): Promise<number>; |
| 2386 | /** Synchronously write the contents of the array buffer (`p`) to the file. |
| 2387 | * |
| 2388 | * Returns the number of bytes written. |
| 2389 | * |
| 2390 | * **It is not guaranteed that the full buffer will be written in a single |
| 2391 | * call.** |
| 2392 | * |
| 2393 | * ```ts |
| 2394 | * const encoder = new TextEncoder(); |
| 2395 | * const data = encoder.encode("Hello world"); |
| 2396 | * using file = Deno.openSync("/foo/bar.txt", { write: true }); |
| 2397 | * const bytesWritten = file.writeSync(data); // 11 |
| 2398 | * ``` |
| 2399 | */ |
| 2400 | writeSync(p: Uint8Array): number; |
| 2401 | /** Truncates (or extends) the file to reach the specified `len`. If `len` |
| 2402 | * is not specified, then the entire file contents are truncated. |
| 2403 | * |
| 2404 | * ### Truncate the entire file |
| 2405 | * |
| 2406 | * ```ts |
| 2407 | * using file = await Deno.open("my_file.txt", { write: true }); |
| 2408 | * await file.truncate(); |
| 2409 | * ``` |
| 2410 | * |
| 2411 | * ### Truncate part of the file |
| 2412 | * |
| 2413 | * ```ts |
| 2414 | * // if "my_file.txt" contains the text "hello world": |
| 2415 | * using file = await Deno.open("my_file.txt", { write: true }); |
| 2416 | * await file.truncate(7); |
| 2417 | * const buf = new Uint8Array(100); |
| 2418 | * await file.read(buf); |
| 2419 | * const text = new TextDecoder().decode(buf); // "hello w" |
| 2420 | * ``` |
| 2421 | */ |
| 2422 | truncate(len?: number): Promise<void>; |
| 2423 | /** Synchronously truncates (or extends) the file to reach the specified |
| 2424 | * `len`. If `len` is not specified, then the entire file contents are |
| 2425 | * truncated. |
| 2426 | * |
| 2427 | * ### Truncate the entire file |
| 2428 | * |
| 2429 | * ```ts |
| 2430 | * using file = Deno.openSync("my_file.txt", { write: true }); |
| 2431 | * file.truncateSync(); |
| 2432 | * ``` |
| 2433 | * |
| 2434 | * ### Truncate part of the file |
| 2435 | * |
| 2436 | * ```ts |
| 2437 | * // if "my_file.txt" contains the text "hello world": |
| 2438 | * using file = Deno.openSync("my_file.txt", { write: true }); |
| 2439 | * file.truncateSync(7); |
| 2440 | * const buf = new Uint8Array(100); |
| 2441 | * file.readSync(buf); |
| 2442 | * const text = new TextDecoder().decode(buf); // "hello w" |
| 2443 | * ``` |
| 2444 | */ |
| 2445 | truncateSync(len?: number): void; |
| 2446 | /** Read the file into an array buffer (`p`). |
| 2447 | * |
| 2448 | * Resolves to either the number of bytes read during the operation or EOF |
| 2449 | * (`null`) if there was nothing more to read. |
| 2450 | * |
| 2451 | * It is possible for a read to successfully return with `0` bytes. This |
| 2452 | * does not indicate EOF. |
| 2453 | * |
| 2454 | * **It is not guaranteed that the full buffer will be read in a single |
| 2455 | * call.** |
| 2456 | * |
| 2457 | * ```ts |
| 2458 | * // if "/foo/bar.txt" contains the text "hello world": |
| 2459 | * using file = await Deno.open("/foo/bar.txt"); |
| 2460 | * const buf = new Uint8Array(100); |
| 2461 | * const numberOfBytesRead = await file.read(buf); // 11 bytes |
| 2462 | * const text = new TextDecoder().decode(buf); // "hello world" |
| 2463 | * ``` |
| 2464 | */ |
| 2465 | read(p: Uint8Array): Promise<number | null>; |
| 2466 | /** Synchronously read from the file into an array buffer (`p`). |
| 2467 | * |
| 2468 | * Returns either the number of bytes read during the operation or EOF |
| 2469 | * (`null`) if there was nothing more to read. |
| 2470 | * |
| 2471 | * It is possible for a read to successfully return with `0` bytes. This |
| 2472 | * does not indicate EOF. |
| 2473 | * |
| 2474 | * **It is not guaranteed that the full buffer will be read in a single |
| 2475 | * call.** |
| 2476 | * |
| 2477 | * ```ts |
| 2478 | * // if "/foo/bar.txt" contains the text "hello world": |
| 2479 | * using file = Deno.openSync("/foo/bar.txt"); |
| 2480 | * const buf = new Uint8Array(100); |
| 2481 | * const numberOfBytesRead = file.readSync(buf); // 11 bytes |
| 2482 | * const text = new TextDecoder().decode(buf); // "hello world" |
| 2483 | * ``` |
| 2484 | */ |
| 2485 | readSync(p: Uint8Array): number | null; |
| 2486 | /** Seek to the given `offset` under mode given by `whence`. The call |
| 2487 | * resolves to the new position within the resource (bytes from the start). |
| 2488 | * |
| 2489 | * ```ts |
| 2490 | * // Given file pointing to file with "Hello world", which is 11 bytes long: |
| 2491 | * using file = await Deno.open( |
| 2492 | * "hello.txt", |
| 2493 | * { read: true, write: true, truncate: true, create: true }, |
| 2494 | * ); |
| 2495 | * await file.write(new TextEncoder().encode("Hello world")); |
| 2496 | * |
| 2497 | * // advance cursor 6 bytes |
| 2498 | * const cursorPosition = await file.seek(6, Deno.SeekMode.Start); |
| 2499 | * console.log(cursorPosition); // 6 |
| 2500 | * const buf = new Uint8Array(100); |
| 2501 | * await file.read(buf); |
| 2502 | * console.log(new TextDecoder().decode(buf)); // "world" |
| 2503 | * ``` |
| 2504 | * |
| 2505 | * The seek modes work as follows: |
| 2506 | * |
| 2507 | * ```ts |
| 2508 | * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: |
| 2509 | * const file = await Deno.open( |
| 2510 | * "hello.txt", |
| 2511 | * { read: true, write: true, truncate: true, create: true }, |
| 2512 | * ); |
| 2513 | * await file.write(new TextEncoder().encode("Hello world")); |
| 2514 | * |
| 2515 | * // Seek 6 bytes from the start of the file |
| 2516 | * console.log(await file.seek(6, Deno.SeekMode.Start)); // "6" |
| 2517 | * // Seek 2 more bytes from the current position |
| 2518 | * console.log(await file.seek(2, Deno.SeekMode.Current)); // "8" |
| 2519 | * // Seek backwards 2 bytes from the end of the file |
| 2520 | * console.log(await file.seek(-2, Deno.SeekMode.End)); // "9" (i.e. 11-2) |
| 2521 | * ``` |
| 2522 | */ |
| 2523 | seek(offset: number | bigint, whence: SeekMode): Promise<number>; |
| 2524 | /** Synchronously seek to the given `offset` under mode given by `whence`. |
| 2525 | * The new position within the resource (bytes from the start) is returned. |
| 2526 | * |
| 2527 | * ```ts |
| 2528 | * using file = Deno.openSync( |
| 2529 | * "hello.txt", |
| 2530 | * { read: true, write: true, truncate: true, create: true }, |
| 2531 | * ); |
| 2532 | * file.writeSync(new TextEncoder().encode("Hello world")); |
| 2533 | * |
| 2534 | * // advance cursor 6 bytes |
| 2535 | * const cursorPosition = file.seekSync(6, Deno.SeekMode.Start); |
| 2536 | * console.log(cursorPosition); // 6 |
| 2537 | * const buf = new Uint8Array(100); |
| 2538 | * file.readSync(buf); |
| 2539 | * console.log(new TextDecoder().decode(buf)); // "world" |
| 2540 | * ``` |
| 2541 | * |
| 2542 | * The seek modes work as follows: |
| 2543 | * |
| 2544 | * ```ts |
| 2545 | * // Given file.rid pointing to file with "Hello world", which is 11 bytes long: |
| 2546 | * using file = Deno.openSync( |
| 2547 | * "hello.txt", |
| 2548 | * { read: true, write: true, truncate: true, create: true }, |
| 2549 | * ); |
| 2550 | * file.writeSync(new TextEncoder().encode("Hello world")); |
| 2551 | * |
| 2552 | * // Seek 6 bytes from the start of the file |
| 2553 | * console.log(file.seekSync(6, Deno.SeekMode.Start)); // "6" |
| 2554 | * // Seek 2 more bytes from the current position |
| 2555 | * console.log(file.seekSync(2, Deno.SeekMode.Current)); // "8" |
| 2556 | * // Seek backwards 2 bytes from the end of the file |
| 2557 | * console.log(file.seekSync(-2, Deno.SeekMode.End)); // "9" (i.e. 11-2) |
| 2558 | * ``` |
| 2559 | */ |
| 2560 | seekSync(offset: number | bigint, whence: SeekMode): number; |
| 2561 | /** Resolves to a {@linkcode Deno.FileInfo} for the file. |
| 2562 | * |
| 2563 | * ```ts |
| 2564 | * import { assert } from "jsr:@std/assert"; |
| 2565 | * |
| 2566 | * using file = await Deno.open("hello.txt"); |
| 2567 | * const fileInfo = await file.stat(); |
| 2568 | * assert(fileInfo.isFile); |
| 2569 | * ``` |
| 2570 | */ |
| 2571 | stat(): Promise<FileInfo>; |
| 2572 | /** Synchronously returns a {@linkcode Deno.FileInfo} for the file. |
| 2573 | * |
| 2574 | * ```ts |
| 2575 | * import { assert } from "jsr:@std/assert"; |
| 2576 | * |
| 2577 | * using file = Deno.openSync("hello.txt") |
| 2578 | * const fileInfo = file.statSync(); |
| 2579 | * assert(fileInfo.isFile); |
| 2580 | * ``` |
| 2581 | */ |
| 2582 | statSync(): FileInfo; |
| 2583 | /** |
| 2584 | * Flushes any pending data and metadata operations of the given file |
| 2585 | * stream to disk. |
| 2586 | * |
| 2587 | * ```ts |
| 2588 | * const file = await Deno.open( |
| 2589 | * "my_file.txt", |
| 2590 | * { read: true, write: true, create: true }, |
| 2591 | * ); |
| 2592 | * await file.write(new TextEncoder().encode("Hello World")); |
| 2593 | * await file.truncate(1); |
| 2594 | * await file.sync(); |
| 2595 | * console.log(await Deno.readTextFile("my_file.txt")); // H |
| 2596 | * ``` |
| 2597 | * |
| 2598 | * @category I/O |
| 2599 | */ |
| 2600 | sync(): Promise<void>; |
| 2601 | /** |
| 2602 | * Synchronously flushes any pending data and metadata operations of the given |
| 2603 | * file stream to disk. |
| 2604 | * |
| 2605 | * ```ts |
| 2606 | * const file = Deno.openSync( |
| 2607 | * "my_file.txt", |
| 2608 | * { read: true, write: true, create: true }, |
| 2609 | * ); |
| 2610 | * file.writeSync(new TextEncoder().encode("Hello World")); |
| 2611 | * file.truncateSync(1); |
| 2612 | * file.syncSync(); |
| 2613 | * console.log(Deno.readTextFileSync("my_file.txt")); // H |
| 2614 | * ``` |
| 2615 | * |
| 2616 | * @category I/O |
| 2617 | */ |
| 2618 | syncSync(): void; |
| 2619 | /** |
| 2620 | * Flushes any pending data operations of the given file stream to disk. |
| 2621 | * ```ts |
| 2622 | * using file = await Deno.open( |
| 2623 | * "my_file.txt", |
| 2624 | * { read: true, write: true, create: true }, |
| 2625 | * ); |
| 2626 | * await file.write(new TextEncoder().encode("Hello World")); |
| 2627 | * await file.syncData(); |
| 2628 | * console.log(await Deno.readTextFile("my_file.txt")); // Hello World |
| 2629 | * ``` |
| 2630 | * |
| 2631 | * @category I/O |
| 2632 | */ |
| 2633 | syncData(): Promise<void>; |
| 2634 | /** |
| 2635 | * Synchronously flushes any pending data operations of the given file stream |
| 2636 | * to disk. |
| 2637 | * |
| 2638 | * ```ts |
| 2639 | * using file = Deno.openSync( |
| 2640 | * "my_file.txt", |
| 2641 | * { read: true, write: true, create: true }, |
| 2642 | * ); |
| 2643 | * file.writeSync(new TextEncoder().encode("Hello World")); |
| 2644 | * file.syncDataSync(); |
| 2645 | * console.log(Deno.readTextFileSync("my_file.txt")); // Hello World |
| 2646 | * ``` |
| 2647 | * |
| 2648 | * @category I/O |
| 2649 | */ |
| 2650 | syncDataSync(): void; |
| 2651 | /** |
| 2652 | * Changes the access (`atime`) and modification (`mtime`) times of the |
| 2653 | * file stream resource. Given times are either in seconds (UNIX epoch |
| 2654 | * time) or as `Date` objects. |
| 2655 | * |
| 2656 | * ```ts |
| 2657 | * using file = await Deno.open("file.txt", { create: true, write: true }); |
| 2658 | * await file.utime(1556495550, new Date()); |
| 2659 | * ``` |
| 2660 | * |
| 2661 | * @category File System |
| 2662 | */ |
| 2663 | utime(atime: number | Date, mtime: number | Date): Promise<void>; |
| 2664 | /** |
| 2665 | * Synchronously changes the access (`atime`) and modification (`mtime`) |
| 2666 | * times of the file stream resource. Given times are either in seconds |
| 2667 | * (UNIX epoch time) or as `Date` objects. |
| 2668 | * |
| 2669 | * ```ts |
| 2670 | * using file = Deno.openSync("file.txt", { create: true, write: true }); |
| 2671 | * file.utime(1556495550, new Date()); |
| 2672 | * ``` |
| 2673 | * |
| 2674 | * @category File System |
| 2675 | */ |
| 2676 | utimeSync(atime: number | Date, mtime: number | Date): void; |
| 2677 | /** **UNSTABLE**: New API, yet to be vetted. |
| 2678 | * |
| 2679 | * Checks if the file resource is a TTY (terminal). |
| 2680 | * |
| 2681 | * ```ts |
| 2682 | * // This example is system and context specific |
| 2683 | * using file = await Deno.open("/dev/tty6"); |
| 2684 | * file.isTerminal(); // true |
| 2685 | * ``` |
| 2686 | */ |
| 2687 | isTerminal(): boolean; |
| 2688 | /** **UNSTABLE**: New API, yet to be vetted. |
| 2689 | * |
| 2690 | * Set TTY to be under raw mode or not. In raw mode, characters are read and |
| 2691 | * returned as is, without being processed. All special processing of |
| 2692 | * characters by the terminal is disabled, including echoing input |
| 2693 | * characters. Reading from a TTY device in raw mode is faster than reading |
| 2694 | * from a TTY device in canonical mode. |
| 2695 | * |
| 2696 | * ```ts |
| 2697 | * using file = await Deno.open("/dev/tty6"); |
| 2698 | * file.setRaw(true, { cbreak: true }); |
| 2699 | * ``` |
| 2700 | */ |
| 2701 | setRaw(mode: boolean, options?: SetRawOptions): void; |
| 2702 | /** |
| 2703 | * Acquire an advisory file-system lock for the file. |
| 2704 | * |
| 2705 | * @param [exclusive=false] |
| 2706 | */ |
| 2707 | lock(exclusive?: boolean): Promise<void>; |
| 2708 | /** |
| 2709 | * Synchronously acquire an advisory file-system lock synchronously for the file. |
| 2710 | * |
| 2711 | * @param [exclusive=false] |
| 2712 | */ |
| 2713 | lockSync(exclusive?: boolean): void; |
| 2714 | /** |
| 2715 | * Release an advisory file-system lock for the file. |
| 2716 | */ |
| 2717 | unlock(): Promise<void>; |
| 2718 | /** |
| 2719 | * Synchronously release an advisory file-system lock for the file. |
| 2720 | */ |
| 2721 | unlockSync(): void; |
| 2722 | /** Close the file. Closing a file when you are finished with it is |
| 2723 | * important to avoid leaking resources. |
| 2724 | * |
| 2725 | * ```ts |
| 2726 | * using file = await Deno.open("my_file.txt"); |
| 2727 | * // do work with "file" object |
| 2728 | * ``` |
| 2729 | */ |
| 2730 | close(): void; |
| 2731 | |
| 2732 | [Symbol.dispose](): void; |
| 2733 | } |
| 2734 | |
| 2735 | /** |
| 2736 | * The Deno abstraction for reading and writing files. |
| 2737 | * |
| 2738 | * @deprecated This will be removed in Deno 2.0. See the |
| 2739 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2740 | * for migration instructions. |
| 2741 | * |
| 2742 | * @category File System |
| 2743 | */ |
| 2744 | export const File: typeof FsFile; |
| 2745 | |
| 2746 | /** Gets the size of the console as columns/rows. |
| 2747 | * |
| 2748 | * ```ts |
| 2749 | * const { columns, rows } = Deno.consoleSize(); |
| 2750 | * ``` |
| 2751 | * |
| 2752 | * This returns the size of the console window as reported by the operating |
| 2753 | * system. It's not a reflection of how many characters will fit within the |
| 2754 | * console window, but can be used as part of that calculation. |
| 2755 | * |
| 2756 | * @category I/O |
| 2757 | */ |
| 2758 | export function consoleSize(): { |
| 2759 | columns: number; |
| 2760 | rows: number; |
| 2761 | }; |
| 2762 | |
| 2763 | /** @category I/O */ |
| 2764 | export interface SetRawOptions { |
| 2765 | /** |
| 2766 | * The `cbreak` option can be used to indicate that characters that |
| 2767 | * correspond to a signal should still be generated. When disabling raw |
| 2768 | * mode, this option is ignored. This functionality currently only works on |
| 2769 | * Linux and Mac OS. |
| 2770 | */ |
| 2771 | cbreak: boolean; |
| 2772 | } |
| 2773 | |
| 2774 | /** A reference to `stdin` which can be used to read directly from `stdin`. |
| 2775 | * It implements the Deno specific {@linkcode Reader}, {@linkcode ReaderSync}, |
| 2776 | * and {@linkcode Closer} interfaces as well as provides a |
| 2777 | * {@linkcode ReadableStream} interface. |
| 2778 | * |
| 2779 | * ### Reading chunks from the readable stream |
| 2780 | * |
| 2781 | * ```ts |
| 2782 | * const decoder = new TextDecoder(); |
| 2783 | * for await (const chunk of Deno.stdin.readable) { |
| 2784 | * const text = decoder.decode(chunk); |
| 2785 | * // do something with the text |
| 2786 | * } |
| 2787 | * ``` |
| 2788 | * |
| 2789 | * @category I/O |
| 2790 | */ |
| 2791 | export const stdin: Reader & ReaderSync & Closer & { |
| 2792 | /** |
| 2793 | * The resource ID assigned to `stdin`. This can be used with the discrete |
| 2794 | * I/O functions in the `Deno` namespace. |
| 2795 | * |
| 2796 | * @deprecated This will be soft-removed in Deno 2.0. See the |
| 2797 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2798 | * for migration instructions. |
| 2799 | */ |
| 2800 | readonly rid: number; |
| 2801 | /** A readable stream interface to `stdin`. */ |
| 2802 | readonly readable: ReadableStream<Uint8Array>; |
| 2803 | /** |
| 2804 | * Set TTY to be under raw mode or not. In raw mode, characters are read and |
| 2805 | * returned as is, without being processed. All special processing of |
| 2806 | * characters by the terminal is disabled, including echoing input |
| 2807 | * characters. Reading from a TTY device in raw mode is faster than reading |
| 2808 | * from a TTY device in canonical mode. |
| 2809 | * |
| 2810 | * ```ts |
| 2811 | * Deno.stdin.setRaw(true, { cbreak: true }); |
| 2812 | * ``` |
| 2813 | * |
| 2814 | * @category I/O |
| 2815 | */ |
| 2816 | setRaw(mode: boolean, options?: SetRawOptions): void; |
| 2817 | /** |
| 2818 | * Checks if `stdin` is a TTY (terminal). |
| 2819 | * |
| 2820 | * ```ts |
| 2821 | * // This example is system and context specific |
| 2822 | * Deno.stdin.isTerminal(); // true |
| 2823 | * ``` |
| 2824 | * |
| 2825 | * @category I/O |
| 2826 | */ |
| 2827 | isTerminal(): boolean; |
| 2828 | }; |
| 2829 | /** A reference to `stdout` which can be used to write directly to `stdout`. |
| 2830 | * It implements the Deno specific {@linkcode Writer}, {@linkcode WriterSync}, |
| 2831 | * and {@linkcode Closer} interfaces as well as provides a |
| 2832 | * {@linkcode WritableStream} interface. |
| 2833 | * |
| 2834 | * These are low level constructs, and the {@linkcode console} interface is a |
| 2835 | * more straight forward way to interact with `stdout` and `stderr`. |
| 2836 | * |
| 2837 | * @category I/O |
| 2838 | */ |
| 2839 | export const stdout: Writer & WriterSync & Closer & { |
| 2840 | /** |
| 2841 | * The resource ID assigned to `stdout`. This can be used with the discrete |
| 2842 | * I/O functions in the `Deno` namespace. |
| 2843 | * |
| 2844 | * @deprecated This will be soft-removed in Deno 2.0. See the |
| 2845 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2846 | * for migration instructions. |
| 2847 | */ |
| 2848 | readonly rid: number; |
| 2849 | /** A writable stream interface to `stdout`. */ |
| 2850 | readonly writable: WritableStream<Uint8Array>; |
| 2851 | /** |
| 2852 | * Checks if `stdout` is a TTY (terminal). |
| 2853 | * |
| 2854 | * ```ts |
| 2855 | * // This example is system and context specific |
| 2856 | * Deno.stdout.isTerminal(); // true |
| 2857 | * ``` |
| 2858 | * |
| 2859 | * @category I/O |
| 2860 | */ |
| 2861 | isTerminal(): boolean; |
| 2862 | }; |
| 2863 | /** A reference to `stderr` which can be used to write directly to `stderr`. |
| 2864 | * It implements the Deno specific {@linkcode Writer}, {@linkcode WriterSync}, |
| 2865 | * and {@linkcode Closer} interfaces as well as provides a |
| 2866 | * {@linkcode WritableStream} interface. |
| 2867 | * |
| 2868 | * These are low level constructs, and the {@linkcode console} interface is a |
| 2869 | * more straight forward way to interact with `stdout` and `stderr`. |
| 2870 | * |
| 2871 | * @category I/O |
| 2872 | */ |
| 2873 | export const stderr: Writer & WriterSync & Closer & { |
| 2874 | /** |
| 2875 | * The resource ID assigned to `stderr`. This can be used with the discrete |
| 2876 | * I/O functions in the `Deno` namespace. |
| 2877 | * |
| 2878 | * @deprecated This will be soft-removed in Deno 2.0. See the |
| 2879 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2880 | * for migration instructions. |
| 2881 | */ |
| 2882 | readonly rid: number; |
| 2883 | /** A writable stream interface to `stderr`. */ |
| 2884 | readonly writable: WritableStream<Uint8Array>; |
| 2885 | /** |
| 2886 | * Checks if `stderr` is a TTY (terminal). |
| 2887 | * |
| 2888 | * ```ts |
| 2889 | * // This example is system and context specific |
| 2890 | * Deno.stderr.isTerminal(); // true |
| 2891 | * ``` |
| 2892 | * |
| 2893 | * @category I/O |
| 2894 | */ |
| 2895 | isTerminal(): boolean; |
| 2896 | }; |
| 2897 | |
| 2898 | /** |
| 2899 | * Options which can be set when doing {@linkcode Deno.open} and |
| 2900 | * {@linkcode Deno.openSync}. |
| 2901 | * |
| 2902 | * @category File System */ |
| 2903 | export interface OpenOptions { |
| 2904 | /** Sets the option for read access. This option, when `true`, means that |
| 2905 | * the file should be read-able if opened. |
| 2906 | * |
| 2907 | * @default {true} */ |
| 2908 | read?: boolean; |
| 2909 | /** Sets the option for write access. This option, when `true`, means that |
| 2910 | * the file should be write-able if opened. If the file already exists, |
| 2911 | * any write calls on it will overwrite its contents, by default without |
| 2912 | * truncating it. |
| 2913 | * |
| 2914 | * @default {false} */ |
| 2915 | write?: boolean; |
| 2916 | /** Sets the option for the append mode. This option, when `true`, means |
| 2917 | * that writes will append to a file instead of overwriting previous |
| 2918 | * contents. |
| 2919 | * |
| 2920 | * Note that setting `{ write: true, append: true }` has the same effect as |
| 2921 | * setting only `{ append: true }`. |
| 2922 | * |
| 2923 | * @default {false} */ |
| 2924 | append?: boolean; |
| 2925 | /** Sets the option for truncating a previous file. If a file is |
| 2926 | * successfully opened with this option set it will truncate the file to `0` |
| 2927 | * size if it already exists. The file must be opened with write access |
| 2928 | * for truncate to work. |
| 2929 | * |
| 2930 | * @default {false} */ |
| 2931 | truncate?: boolean; |
| 2932 | /** Sets the option to allow creating a new file, if one doesn't already |
| 2933 | * exist at the specified path. Requires write or append access to be |
| 2934 | * used. |
| 2935 | * |
| 2936 | * @default {false} */ |
| 2937 | create?: boolean; |
| 2938 | /** If set to `true`, no file, directory, or symlink is allowed to exist at |
| 2939 | * the target location. Requires write or append access to be used. When |
| 2940 | * createNew is set to `true`, create and truncate are ignored. |
| 2941 | * |
| 2942 | * @default {false} */ |
| 2943 | createNew?: boolean; |
| 2944 | /** Permissions to use if creating the file (defaults to `0o666`, before |
| 2945 | * the process's umask). |
| 2946 | * |
| 2947 | * Ignored on Windows. */ |
| 2948 | mode?: number; |
| 2949 | } |
| 2950 | |
| 2951 | /** |
| 2952 | * Options which can be set when using {@linkcode Deno.readFile} or |
| 2953 | * {@linkcode Deno.readFileSync}. |
| 2954 | * |
| 2955 | * @category File System */ |
| 2956 | export interface ReadFileOptions { |
| 2957 | /** |
| 2958 | * An abort signal to allow cancellation of the file read operation. |
| 2959 | * If the signal becomes aborted the readFile operation will be stopped |
| 2960 | * and the promise returned will be rejected with an AbortError. |
| 2961 | */ |
| 2962 | signal?: AbortSignal; |
| 2963 | } |
| 2964 | |
| 2965 | /** |
| 2966 | * Check if a given resource id (`rid`) is a TTY (a terminal). |
| 2967 | * |
| 2968 | * ```ts |
| 2969 | * // This example is system and context specific |
| 2970 | * const nonTTYRid = Deno.openSync("my_file.txt").rid; |
| 2971 | * const ttyRid = Deno.openSync("/dev/tty6").rid; |
| 2972 | * console.log(Deno.isatty(nonTTYRid)); // false |
| 2973 | * console.log(Deno.isatty(ttyRid)); // true |
| 2974 | * ``` |
| 2975 | * |
| 2976 | * @deprecated This will be soft-removed in Deno 2.0. See the |
| 2977 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2978 | * for migration instructions. |
| 2979 | * |
| 2980 | * @category I/O |
| 2981 | */ |
| 2982 | export function isatty(rid: number): boolean; |
| 2983 | |
| 2984 | /** |
| 2985 | * A variable-sized buffer of bytes with `read()` and `write()` methods. |
| 2986 | * |
| 2987 | * @deprecated This will be removed in Deno 2.0. See the |
| 2988 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 2989 | * for migration instructions. |
| 2990 | * |
| 2991 | * @category I/O |
| 2992 | */ |
| 2993 | export class Buffer implements Reader, ReaderSync, Writer, WriterSync { |
| 2994 | constructor(ab?: ArrayBuffer); |
| 2995 | /** Returns a slice holding the unread portion of the buffer. |
| 2996 | * |
| 2997 | * The slice is valid for use only until the next buffer modification (that |
| 2998 | * is, only until the next call to a method like `read()`, `write()`, |
| 2999 | * `reset()`, or `truncate()`). If `options.copy` is false the slice aliases the buffer content at |
| 3000 | * least until the next buffer modification, so immediate changes to the |
| 3001 | * slice will affect the result of future reads. |
| 3002 | * @param options Defaults to `{ copy: true }` |
| 3003 | */ |
| 3004 | bytes(options?: { copy?: boolean }): Uint8Array; |
| 3005 | /** Returns whether the unread portion of the buffer is empty. */ |
| 3006 | empty(): boolean; |
| 3007 | /** A read only number of bytes of the unread portion of the buffer. */ |
| 3008 | readonly length: number; |
| 3009 | /** The read only capacity of the buffer's underlying byte slice, that is, |
| 3010 | * the total space allocated for the buffer's data. */ |
| 3011 | readonly capacity: number; |
| 3012 | /** Discards all but the first `n` unread bytes from the buffer but |
| 3013 | * continues to use the same allocated storage. It throws if `n` is |
| 3014 | * negative or greater than the length of the buffer. */ |
| 3015 | truncate(n: number): void; |
| 3016 | /** Resets the buffer to be empty, but it retains the underlying storage for |
| 3017 | * use by future writes. `.reset()` is the same as `.truncate(0)`. */ |
| 3018 | reset(): void; |
| 3019 | /** Reads the next `p.length` bytes from the buffer or until the buffer is |
| 3020 | * drained. Returns the number of bytes read. If the buffer has no data to |
| 3021 | * return, the return is EOF (`null`). */ |
| 3022 | readSync(p: Uint8Array): number | null; |
| 3023 | /** Reads the next `p.length` bytes from the buffer or until the buffer is |
| 3024 | * drained. Resolves to the number of bytes read. If the buffer has no |
| 3025 | * data to return, resolves to EOF (`null`). |
| 3026 | * |
| 3027 | * NOTE: This methods reads bytes synchronously; it's provided for |
| 3028 | * compatibility with `Reader` interfaces. |
| 3029 | */ |
| 3030 | read(p: Uint8Array): Promise<number | null>; |
| 3031 | writeSync(p: Uint8Array): number; |
| 3032 | /** NOTE: This methods writes bytes synchronously; it's provided for |
| 3033 | * compatibility with `Writer` interface. */ |
| 3034 | write(p: Uint8Array): Promise<number>; |
| 3035 | /** Grows the buffer's capacity, if necessary, to guarantee space for |
| 3036 | * another `n` bytes. After `.grow(n)`, at least `n` bytes can be written to |
| 3037 | * the buffer without another allocation. If `n` is negative, `.grow()` will |
| 3038 | * throw. If the buffer can't grow it will throw an error. |
| 3039 | * |
| 3040 | * Based on Go Lang's |
| 3041 | * [Buffer.Grow](https://golang.org/pkg/bytes/#Buffer.Grow). */ |
| 3042 | grow(n: number): void; |
| 3043 | /** Reads data from `r` until EOF (`null`) and appends it to the buffer, |
| 3044 | * growing the buffer as needed. It resolves to the number of bytes read. |
| 3045 | * If the buffer becomes too large, `.readFrom()` will reject with an error. |
| 3046 | * |
| 3047 | * Based on Go Lang's |
| 3048 | * [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */ |
| 3049 | readFrom(r: Reader): Promise<number>; |
| 3050 | /** Reads data from `r` until EOF (`null`) and appends it to the buffer, |
| 3051 | * growing the buffer as needed. It returns the number of bytes read. If the |
| 3052 | * buffer becomes too large, `.readFromSync()` will throw an error. |
| 3053 | * |
| 3054 | * Based on Go Lang's |
| 3055 | * [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */ |
| 3056 | readFromSync(r: ReaderSync): number; |
| 3057 | } |
| 3058 | |
| 3059 | /** |
| 3060 | * Read Reader `r` until EOF (`null`) and resolve to the content as |
| 3061 | * Uint8Array`. |
| 3062 | * |
| 3063 | * @deprecated This will be removed in Deno 2.0. See the |
| 3064 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 3065 | * for migration instructions. |
| 3066 | * |
| 3067 | * @category I/O |
| 3068 | */ |
| 3069 | export function readAll(r: Reader): Promise<Uint8Array>; |
| 3070 | |
| 3071 | /** |
| 3072 | * Synchronously reads Reader `r` until EOF (`null`) and returns the content |
| 3073 | * as `Uint8Array`. |
| 3074 | * |
| 3075 | * @deprecated This will be removed in Deno 2.0. See the |
| 3076 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 3077 | * for migration instructions. |
| 3078 | * |
| 3079 | * @category I/O |
| 3080 | */ |
| 3081 | export function readAllSync(r: ReaderSync): Uint8Array; |
| 3082 | |
| 3083 | /** |
| 3084 | * Write all the content of the array buffer (`arr`) to the writer (`w`). |
| 3085 | * |
| 3086 | * @deprecated This will be removed in Deno 2.0. See the |
| 3087 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 3088 | * for migration instructions. |
| 3089 | * |
| 3090 | * @category I/O |
| 3091 | */ |
| 3092 | export function writeAll(w: Writer, arr: Uint8Array): Promise<void>; |
| 3093 | |
| 3094 | /** |
| 3095 | * Synchronously write all the content of the array buffer (`arr`) to the |
| 3096 | * writer (`w`). |
| 3097 | * |
| 3098 | * @deprecated This will be removed in Deno 2.0. See the |
| 3099 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 3100 | * for migration instructions. |
| 3101 | * |
| 3102 | * @category I/O |
| 3103 | */ |
| 3104 | export function writeAllSync(w: WriterSync, arr: Uint8Array): void; |
| 3105 | |
| 3106 | /** |
| 3107 | * Options which can be set when using {@linkcode Deno.mkdir} and |
| 3108 | * {@linkcode Deno.mkdirSync}. |
| 3109 | * |
| 3110 | * @category File System */ |
| 3111 | export interface MkdirOptions { |
| 3112 | /** If set to `true`, means that any intermediate directories will also be |
| 3113 | * created (as with the shell command `mkdir -p`). |
| 3114 | * |
| 3115 | * Intermediate directories are created with the same permissions. |
| 3116 | * |
| 3117 | * When recursive is set to `true`, succeeds silently (without changing any |
| 3118 | * permissions) if a directory already exists at the path, or if the path |
| 3119 | * is a symlink to an existing directory. |
| 3120 | * |
| 3121 | * @default {false} */ |
| 3122 | recursive?: boolean; |
| 3123 | /** Permissions to use when creating the directory (defaults to `0o777`, |
| 3124 | * before the process's umask). |
| 3125 | * |
| 3126 | * Ignored on Windows. */ |
| 3127 | mode?: number; |
| 3128 | } |
| 3129 | |
| 3130 | /** Creates a new directory with the specified path. |
| 3131 | * |
| 3132 | * ```ts |
| 3133 | * await Deno.mkdir("new_dir"); |
| 3134 | * await Deno.mkdir("nested/directories", { recursive: true }); |
| 3135 | * await Deno.mkdir("restricted_access_dir", { mode: 0o700 }); |
| 3136 | * ``` |
| 3137 | * |
| 3138 | * Defaults to throwing error if the directory already exists. |
| 3139 | * |
| 3140 | * Requires `allow-write` permission. |
| 3141 | * |
| 3142 | * @tags allow-write |
| 3143 | * @category File System |
| 3144 | */ |
| 3145 | export function mkdir( |
| 3146 | path: string | URL, |
| 3147 | options?: MkdirOptions, |
| 3148 | ): Promise<void>; |
| 3149 | |
| 3150 | /** Synchronously creates a new directory with the specified path. |
| 3151 | * |
| 3152 | * ```ts |
| 3153 | * Deno.mkdirSync("new_dir"); |
| 3154 | * Deno.mkdirSync("nested/directories", { recursive: true }); |
| 3155 | * Deno.mkdirSync("restricted_access_dir", { mode: 0o700 }); |
| 3156 | * ``` |
| 3157 | * |
| 3158 | * Defaults to throwing error if the directory already exists. |
| 3159 | * |
| 3160 | * Requires `allow-write` permission. |
| 3161 | * |
| 3162 | * @tags allow-write |
| 3163 | * @category File System |
| 3164 | */ |
| 3165 | export function mkdirSync(path: string | URL, options?: MkdirOptions): void; |
| 3166 | |
| 3167 | /** |
| 3168 | * Options which can be set when using {@linkcode Deno.makeTempDir}, |
| 3169 | * {@linkcode Deno.makeTempDirSync}, {@linkcode Deno.makeTempFile}, and |
| 3170 | * {@linkcode Deno.makeTempFileSync}. |
| 3171 | * |
| 3172 | * @category File System */ |
| 3173 | export interface MakeTempOptions { |
| 3174 | /** Directory where the temporary directory should be created (defaults to |
| 3175 | * the env variable `TMPDIR`, or the system's default, usually `/tmp`). |
| 3176 | * |
| 3177 | * Note that if the passed `dir` is relative, the path returned by |
| 3178 | * `makeTempFile()` and `makeTempDir()` will also be relative. Be mindful of |
| 3179 | * this when changing working directory. */ |
| 3180 | dir?: string; |
| 3181 | /** String that should precede the random portion of the temporary |
| 3182 | * directory's name. */ |
| 3183 | prefix?: string; |
| 3184 | /** String that should follow the random portion of the temporary |
| 3185 | * directory's name. */ |
| 3186 | suffix?: string; |
| 3187 | } |
| 3188 | |
| 3189 | /** Creates a new temporary directory in the default directory for temporary |
| 3190 | * files, unless `dir` is specified. Other optional options include |
| 3191 | * prefixing and suffixing the directory name with `prefix` and `suffix` |
| 3192 | * respectively. |
| 3193 | * |
| 3194 | * This call resolves to the full path to the newly created directory. |
| 3195 | * |
| 3196 | * Multiple programs calling this function simultaneously will create different |
| 3197 | * directories. It is the caller's responsibility to remove the directory when |
| 3198 | * no longer needed. |
| 3199 | * |
| 3200 | * ```ts |
| 3201 | * const tempDirName0 = await Deno.makeTempDir(); // e.g. /tmp/2894ea76 |
| 3202 | * const tempDirName1 = await Deno.makeTempDir({ prefix: 'my_temp' }); // e.g. /tmp/my_temp339c944d |
| 3203 | * ``` |
| 3204 | * |
| 3205 | * Requires `allow-write` permission. |
| 3206 | * |
| 3207 | * @tags allow-write |
| 3208 | * @category File System |
| 3209 | */ |
| 3210 | // TODO(ry) Doesn't check permissions. |
| 3211 | export function makeTempDir(options?: MakeTempOptions): Promise<string>; |
| 3212 | |
| 3213 | /** Synchronously creates a new temporary directory in the default directory |
| 3214 | * for temporary files, unless `dir` is specified. Other optional options |
| 3215 | * include prefixing and suffixing the directory name with `prefix` and |
| 3216 | * `suffix` respectively. |
| 3217 | * |
| 3218 | * The full path to the newly created directory is returned. |
| 3219 | * |
| 3220 | * Multiple programs calling this function simultaneously will create different |
| 3221 | * directories. It is the caller's responsibility to remove the directory when |
| 3222 | * no longer needed. |
| 3223 | * |
| 3224 | * ```ts |
| 3225 | * const tempDirName0 = Deno.makeTempDirSync(); // e.g. /tmp/2894ea76 |
| 3226 | * const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' }); // e.g. /tmp/my_temp339c944d |
| 3227 | * ``` |
| 3228 | * |
| 3229 | * Requires `allow-write` permission. |
| 3230 | * |
| 3231 | * @tags allow-write |
| 3232 | * @category File System |
| 3233 | */ |
| 3234 | // TODO(ry) Doesn't check permissions. |
| 3235 | export function makeTempDirSync(options?: MakeTempOptions): string; |
| 3236 | |
| 3237 | /** Creates a new temporary file in the default directory for temporary |
| 3238 | * files, unless `dir` is specified. |
| 3239 | * |
| 3240 | * Other options include prefixing and suffixing the directory name with |
| 3241 | * `prefix` and `suffix` respectively. |
| 3242 | * |
| 3243 | * This call resolves to the full path to the newly created file. |
| 3244 | * |
| 3245 | * Multiple programs calling this function simultaneously will create |
| 3246 | * different files. It is the caller's responsibility to remove the file when |
| 3247 | * no longer needed. |
| 3248 | * |
| 3249 | * ```ts |
| 3250 | * const tmpFileName0 = await Deno.makeTempFile(); // e.g. /tmp/419e0bf2 |
| 3251 | * const tmpFileName1 = await Deno.makeTempFile({ prefix: 'my_temp' }); // e.g. /tmp/my_temp754d3098 |
| 3252 | * ``` |
| 3253 | * |
| 3254 | * Requires `allow-write` permission. |
| 3255 | * |
| 3256 | * @tags allow-write |
| 3257 | * @category File System |
| 3258 | */ |
| 3259 | export function makeTempFile(options?: MakeTempOptions): Promise<string>; |
| 3260 | |
| 3261 | /** Synchronously creates a new temporary file in the default directory for |
| 3262 | * temporary files, unless `dir` is specified. |
| 3263 | * |
| 3264 | * Other options include prefixing and suffixing the directory name with |
| 3265 | * `prefix` and `suffix` respectively. |
| 3266 | * |
| 3267 | * The full path to the newly created file is returned. |
| 3268 | * |
| 3269 | * Multiple programs calling this function simultaneously will create |
| 3270 | * different files. It is the caller's responsibility to remove the file when |
| 3271 | * no longer needed. |
| 3272 | * |
| 3273 | * ```ts |
| 3274 | * const tempFileName0 = Deno.makeTempFileSync(); // e.g. /tmp/419e0bf2 |
| 3275 | * const tempFileName1 = Deno.makeTempFileSync({ prefix: 'my_temp' }); // e.g. /tmp/my_temp754d3098 |
| 3276 | * ``` |
| 3277 | * |
| 3278 | * Requires `allow-write` permission. |
| 3279 | * |
| 3280 | * @tags allow-write |
| 3281 | * @category File System |
| 3282 | */ |
| 3283 | export function makeTempFileSync(options?: MakeTempOptions): string; |
| 3284 | |
| 3285 | /** Changes the permission of a specific file/directory of specified path. |
| 3286 | * Ignores the process's umask. |
| 3287 | * |
| 3288 | * ```ts |
| 3289 | * await Deno.chmod("/path/to/file", 0o666); |
| 3290 | * ``` |
| 3291 | * |
| 3292 | * The mode is a sequence of 3 octal numbers. The first/left-most number |
| 3293 | * specifies the permissions for the owner. The second number specifies the |
| 3294 | * permissions for the group. The last/right-most number specifies the |
| 3295 | * permissions for others. For example, with a mode of 0o764, the owner (7) |
| 3296 | * can read/write/execute, the group (6) can read/write and everyone else (4) |
| 3297 | * can read only. |
| 3298 | * |
| 3299 | * | Number | Description | |
| 3300 | * | ------ | ----------- | |
| 3301 | * | 7 | read, write, and execute | |
| 3302 | * | 6 | read and write | |
| 3303 | * | 5 | read and execute | |
| 3304 | * | 4 | read only | |
| 3305 | * | 3 | write and execute | |
| 3306 | * | 2 | write only | |
| 3307 | * | 1 | execute only | |
| 3308 | * | 0 | no permission | |
| 3309 | * |
| 3310 | * NOTE: This API currently throws on Windows |
| 3311 | * |
| 3312 | * Requires `allow-write` permission. |
| 3313 | * |
| 3314 | * @tags allow-write |
| 3315 | * @category File System |
| 3316 | */ |
| 3317 | export function chmod(path: string | URL, mode: number): Promise<void>; |
| 3318 | |
| 3319 | /** Synchronously changes the permission of a specific file/directory of |
| 3320 | * specified path. Ignores the process's umask. |
| 3321 | * |
| 3322 | * ```ts |
| 3323 | * Deno.chmodSync("/path/to/file", 0o666); |
| 3324 | * ``` |
| 3325 | * |
| 3326 | * For a full description, see {@linkcode Deno.chmod}. |
| 3327 | * |
| 3328 | * NOTE: This API currently throws on Windows |
| 3329 | * |
| 3330 | * Requires `allow-write` permission. |
| 3331 | * |
| 3332 | * @tags allow-write |
| 3333 | * @category File System |
| 3334 | */ |
| 3335 | export function chmodSync(path: string | URL, mode: number): void; |
| 3336 | |
| 3337 | /** Change owner of a regular file or directory. |
| 3338 | * |
| 3339 | * This functionality is not available on Windows. |
| 3340 | * |
| 3341 | * ```ts |
| 3342 | * await Deno.chown("myFile.txt", 1000, 1002); |
| 3343 | * ``` |
| 3344 | * |
| 3345 | * Requires `allow-write` permission. |
| 3346 | * |
| 3347 | * Throws Error (not implemented) if executed on Windows. |
| 3348 | * |
| 3349 | * @tags allow-write |
| 3350 | * @category File System |
| 3351 | * |
| 3352 | * @param path path to the file |
| 3353 | * @param uid user id (UID) of the new owner, or `null` for no change |
| 3354 | * @param gid group id (GID) of the new owner, or `null` for no change |
| 3355 | */ |
| 3356 | export function chown( |
| 3357 | path: string | URL, |
| 3358 | uid: number | null, |
| 3359 | gid: number | null, |
| 3360 | ): Promise<void>; |
| 3361 | |
| 3362 | /** Synchronously change owner of a regular file or directory. |
| 3363 | * |
| 3364 | * This functionality is not available on Windows. |
| 3365 | * |
| 3366 | * ```ts |
| 3367 | * Deno.chownSync("myFile.txt", 1000, 1002); |
| 3368 | * ``` |
| 3369 | * |
| 3370 | * Requires `allow-write` permission. |
| 3371 | * |
| 3372 | * Throws Error (not implemented) if executed on Windows. |
| 3373 | * |
| 3374 | * @tags allow-write |
| 3375 | * @category File System |
| 3376 | * |
| 3377 | * @param path path to the file |
| 3378 | * @param uid user id (UID) of the new owner, or `null` for no change |
| 3379 | * @param gid group id (GID) of the new owner, or `null` for no change |
| 3380 | */ |
| 3381 | export function chownSync( |
| 3382 | path: string | URL, |
| 3383 | uid: number | null, |
| 3384 | gid: number | null, |
| 3385 | ): void; |
| 3386 | |
| 3387 | /** |
| 3388 | * Options which can be set when using {@linkcode Deno.remove} and |
| 3389 | * {@linkcode Deno.removeSync}. |
| 3390 | * |
| 3391 | * @category File System */ |
| 3392 | export interface RemoveOptions { |
| 3393 | /** If set to `true`, path will be removed even if it's a non-empty directory. |
| 3394 | * |
| 3395 | * @default {false} */ |
| 3396 | recursive?: boolean; |
| 3397 | } |
| 3398 | |
| 3399 | /** Removes the named file or directory. |
| 3400 | * |
| 3401 | * ```ts |
| 3402 | * await Deno.remove("/path/to/empty_dir/or/file"); |
| 3403 | * await Deno.remove("/path/to/populated_dir/or/file", { recursive: true }); |
| 3404 | * ``` |
| 3405 | * |
| 3406 | * Throws error if permission denied, path not found, or path is a non-empty |
| 3407 | * directory and the `recursive` option isn't set to `true`. |
| 3408 | * |
| 3409 | * Requires `allow-write` permission. |
| 3410 | * |
| 3411 | * @tags allow-write |
| 3412 | * @category File System |
| 3413 | */ |
| 3414 | export function remove( |
| 3415 | path: string | URL, |
| 3416 | options?: RemoveOptions, |
| 3417 | ): Promise<void>; |
| 3418 | |
| 3419 | /** Synchronously removes the named file or directory. |
| 3420 | * |
| 3421 | * ```ts |
| 3422 | * Deno.removeSync("/path/to/empty_dir/or/file"); |
| 3423 | * Deno.removeSync("/path/to/populated_dir/or/file", { recursive: true }); |
| 3424 | * ``` |
| 3425 | * |
| 3426 | * Throws error if permission denied, path not found, or path is a non-empty |
| 3427 | * directory and the `recursive` option isn't set to `true`. |
| 3428 | * |
| 3429 | * Requires `allow-write` permission. |
| 3430 | * |
| 3431 | * @tags allow-write |
| 3432 | * @category File System |
| 3433 | */ |
| 3434 | export function removeSync(path: string | URL, options?: RemoveOptions): void; |
| 3435 | |
| 3436 | /** Synchronously renames (moves) `oldpath` to `newpath`. Paths may be files or |
| 3437 | * directories. If `newpath` already exists and is not a directory, |
| 3438 | * `renameSync()` replaces it. OS-specific restrictions may apply when |
| 3439 | * `oldpath` and `newpath` are in different directories. |
| 3440 | * |
| 3441 | * ```ts |
| 3442 | * Deno.renameSync("old/path", "new/path"); |
| 3443 | * ``` |
| 3444 | * |
| 3445 | * On Unix-like OSes, this operation does not follow symlinks at either path. |
| 3446 | * |
| 3447 | * It varies between platforms when the operation throws errors, and if so what |
| 3448 | * they are. It's always an error to rename anything to a non-empty directory. |
| 3449 | * |
| 3450 | * Requires `allow-read` and `allow-write` permissions. |
| 3451 | * |
| 3452 | * @tags allow-read, allow-write |
| 3453 | * @category File System |
| 3454 | */ |
| 3455 | export function renameSync( |
| 3456 | oldpath: string | URL, |
| 3457 | newpath: string | URL, |
| 3458 | ): void; |
| 3459 | |
| 3460 | /** Renames (moves) `oldpath` to `newpath`. Paths may be files or directories. |
| 3461 | * If `newpath` already exists and is not a directory, `rename()` replaces it. |
| 3462 | * OS-specific restrictions may apply when `oldpath` and `newpath` are in |
| 3463 | * different directories. |
| 3464 | * |
| 3465 | * ```ts |
| 3466 | * await Deno.rename("old/path", "new/path"); |
| 3467 | * ``` |
| 3468 | * |
| 3469 | * On Unix-like OSes, this operation does not follow symlinks at either path. |
| 3470 | * |
| 3471 | * It varies between platforms when the operation throws errors, and if so |
| 3472 | * what they are. It's always an error to rename anything to a non-empty |
| 3473 | * directory. |
| 3474 | * |
| 3475 | * Requires `allow-read` and `allow-write` permissions. |
| 3476 | * |
| 3477 | * @tags allow-read, allow-write |
| 3478 | * @category File System |
| 3479 | */ |
| 3480 | export function rename( |
| 3481 | oldpath: string | URL, |
| 3482 | newpath: string | URL, |
| 3483 | ): Promise<void>; |
| 3484 | |
| 3485 | /** Asynchronously reads and returns the entire contents of a file as an UTF-8 |
| 3486 | * decoded string. Reading a directory throws an error. |
| 3487 | * |
| 3488 | * ```ts |
| 3489 | * const data = await Deno.readTextFile("hello.txt"); |
| 3490 | * console.log(data); |
| 3491 | * ``` |
| 3492 | * |
| 3493 | * Requires `allow-read` permission. |
| 3494 | * |
| 3495 | * @tags allow-read |
| 3496 | * @category File System |
| 3497 | */ |
| 3498 | export function readTextFile( |
| 3499 | path: string | URL, |
| 3500 | options?: ReadFileOptions, |
| 3501 | ): Promise<string>; |
| 3502 | |
| 3503 | /** Synchronously reads and returns the entire contents of a file as an UTF-8 |
| 3504 | * decoded string. Reading a directory throws an error. |
| 3505 | * |
| 3506 | * ```ts |
| 3507 | * const data = Deno.readTextFileSync("hello.txt"); |
| 3508 | * console.log(data); |
| 3509 | * ``` |
| 3510 | * |
| 3511 | * Requires `allow-read` permission. |
| 3512 | * |
| 3513 | * @tags allow-read |
| 3514 | * @category File System |
| 3515 | */ |
| 3516 | export function readTextFileSync(path: string | URL): string; |
| 3517 | |
| 3518 | /** Reads and resolves to the entire contents of a file as an array of bytes. |
| 3519 | * `TextDecoder` can be used to transform the bytes to string if required. |
| 3520 | * Reading a directory returns an empty data array. |
| 3521 | * |
| 3522 | * ```ts |
| 3523 | * const decoder = new TextDecoder("utf-8"); |
| 3524 | * const data = await Deno.readFile("hello.txt"); |
| 3525 | * console.log(decoder.decode(data)); |
| 3526 | * ``` |
| 3527 | * |
| 3528 | * Requires `allow-read` permission. |
| 3529 | * |
| 3530 | * @tags allow-read |
| 3531 | * @category File System |
| 3532 | */ |
| 3533 | export function readFile( |
| 3534 | path: string | URL, |
| 3535 | options?: ReadFileOptions, |
| 3536 | ): Promise<Uint8Array>; |
| 3537 | |
| 3538 | /** Synchronously reads and returns the entire contents of a file as an array |
| 3539 | * of bytes. `TextDecoder` can be used to transform the bytes to string if |
| 3540 | * required. Reading a directory returns an empty data array. |
| 3541 | * |
| 3542 | * ```ts |
| 3543 | * const decoder = new TextDecoder("utf-8"); |
| 3544 | * const data = Deno.readFileSync("hello.txt"); |
| 3545 | * console.log(decoder.decode(data)); |
| 3546 | * ``` |
| 3547 | * |
| 3548 | * Requires `allow-read` permission. |
| 3549 | * |
| 3550 | * @tags allow-read |
| 3551 | * @category File System |
| 3552 | */ |
| 3553 | export function readFileSync(path: string | URL): Uint8Array; |
| 3554 | |
| 3555 | /** Provides information about a file and is returned by |
| 3556 | * {@linkcode Deno.stat}, {@linkcode Deno.lstat}, {@linkcode Deno.statSync}, |
| 3557 | * and {@linkcode Deno.lstatSync} or from calling `stat()` and `statSync()` |
| 3558 | * on an {@linkcode Deno.FsFile} instance. |
| 3559 | * |
| 3560 | * @category File System |
| 3561 | */ |
| 3562 | export interface FileInfo { |
| 3563 | /** True if this is info for a regular file. Mutually exclusive to |
| 3564 | * `FileInfo.isDirectory` and `FileInfo.isSymlink`. */ |
| 3565 | isFile: boolean; |
| 3566 | /** True if this is info for a regular directory. Mutually exclusive to |
| 3567 | * `FileInfo.isFile` and `FileInfo.isSymlink`. */ |
| 3568 | isDirectory: boolean; |
| 3569 | /** True if this is info for a symlink. Mutually exclusive to |
| 3570 | * `FileInfo.isFile` and `FileInfo.isDirectory`. */ |
| 3571 | isSymlink: boolean; |
| 3572 | /** The size of the file, in bytes. */ |
| 3573 | size: number; |
| 3574 | /** The last modification time of the file. This corresponds to the `mtime` |
| 3575 | * field from `stat` on Linux/Mac OS and `ftLastWriteTime` on Windows. This |
| 3576 | * may not be available on all platforms. */ |
| 3577 | mtime: Date | null; |
| 3578 | /** The last access time of the file. This corresponds to the `atime` |
| 3579 | * field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not |
| 3580 | * be available on all platforms. */ |
| 3581 | atime: Date | null; |
| 3582 | /** The creation time of the file. This corresponds to the `birthtime` |
| 3583 | * field from `stat` on Mac/BSD and `ftCreationTime` on Windows. This may |
| 3584 | * not be available on all platforms. */ |
| 3585 | birthtime: Date | null; |
| 3586 | /** ID of the device containing the file. */ |
| 3587 | dev: number; |
| 3588 | /** Inode number. |
| 3589 | * |
| 3590 | * _Linux/Mac OS only._ */ |
| 3591 | ino: number | null; |
| 3592 | /** The underlying raw `st_mode` bits that contain the standard Unix |
| 3593 | * permissions for this file/directory. |
| 3594 | * |
| 3595 | * _Linux/Mac OS only._ */ |
| 3596 | mode: number | null; |
| 3597 | /** Number of hard links pointing to this file. |
| 3598 | * |
| 3599 | * _Linux/Mac OS only._ */ |
| 3600 | nlink: number | null; |
| 3601 | /** User ID of the owner of this file. |
| 3602 | * |
| 3603 | * _Linux/Mac OS only._ */ |
| 3604 | uid: number | null; |
| 3605 | /** Group ID of the owner of this file. |
| 3606 | * |
| 3607 | * _Linux/Mac OS only._ */ |
| 3608 | gid: number | null; |
| 3609 | /** Device ID of this file. |
| 3610 | * |
| 3611 | * _Linux/Mac OS only._ */ |
| 3612 | rdev: number | null; |
| 3613 | /** Blocksize for filesystem I/O. |
| 3614 | * |
| 3615 | * _Linux/Mac OS only._ */ |
| 3616 | blksize: number | null; |
| 3617 | /** Number of blocks allocated to the file, in 512-byte units. |
| 3618 | * |
| 3619 | * _Linux/Mac OS only._ */ |
| 3620 | blocks: number | null; |
| 3621 | /** True if this is info for a block device. |
| 3622 | * |
| 3623 | * _Linux/Mac OS only._ */ |
| 3624 | isBlockDevice: boolean | null; |
| 3625 | /** True if this is info for a char device. |
| 3626 | * |
| 3627 | * _Linux/Mac OS only._ */ |
| 3628 | isCharDevice: boolean | null; |
| 3629 | /** True if this is info for a fifo. |
| 3630 | * |
| 3631 | * _Linux/Mac OS only._ */ |
| 3632 | isFifo: boolean | null; |
| 3633 | /** True if this is info for a socket. |
| 3634 | * |
| 3635 | * _Linux/Mac OS only._ */ |
| 3636 | isSocket: boolean | null; |
| 3637 | } |
| 3638 | |
| 3639 | /** Resolves to the absolute normalized path, with symbolic links resolved. |
| 3640 | * |
| 3641 | * ```ts |
| 3642 | * // e.g. given /home/alice/file.txt and current directory /home/alice |
| 3643 | * await Deno.symlink("file.txt", "symlink_file.txt"); |
| 3644 | * const realPath = await Deno.realPath("./file.txt"); |
| 3645 | * const realSymLinkPath = await Deno.realPath("./symlink_file.txt"); |
| 3646 | * console.log(realPath); // outputs "/home/alice/file.txt" |
| 3647 | * console.log(realSymLinkPath); // outputs "/home/alice/file.txt" |
| 3648 | * ``` |
| 3649 | * |
| 3650 | * Requires `allow-read` permission for the target path. |
| 3651 | * |
| 3652 | * Also requires `allow-read` permission for the `CWD` if the target path is |
| 3653 | * relative. |
| 3654 | * |
| 3655 | * @tags allow-read |
| 3656 | * @category File System |
| 3657 | */ |
| 3658 | export function realPath(path: string | URL): Promise<string>; |
| 3659 | |
| 3660 | /** Synchronously returns absolute normalized path, with symbolic links |
| 3661 | * resolved. |
| 3662 | * |
| 3663 | * ```ts |
| 3664 | * // e.g. given /home/alice/file.txt and current directory /home/alice |
| 3665 | * Deno.symlinkSync("file.txt", "symlink_file.txt"); |
| 3666 | * const realPath = Deno.realPathSync("./file.txt"); |
| 3667 | * const realSymLinkPath = Deno.realPathSync("./symlink_file.txt"); |
| 3668 | * console.log(realPath); // outputs "/home/alice/file.txt" |
| 3669 | * console.log(realSymLinkPath); // outputs "/home/alice/file.txt" |
| 3670 | * ``` |
| 3671 | * |
| 3672 | * Requires `allow-read` permission for the target path. |
| 3673 | * |
| 3674 | * Also requires `allow-read` permission for the `CWD` if the target path is |
| 3675 | * relative. |
| 3676 | * |
| 3677 | * @tags allow-read |
| 3678 | * @category File System |
| 3679 | */ |
| 3680 | export function realPathSync(path: string | URL): string; |
| 3681 | |
| 3682 | /** |
| 3683 | * Information about a directory entry returned from {@linkcode Deno.readDir} |
| 3684 | * and {@linkcode Deno.readDirSync}. |
| 3685 | * |
| 3686 | * @category File System */ |
| 3687 | export interface DirEntry { |
| 3688 | /** The file name of the entry. It is just the entity name and does not |
| 3689 | * include the full path. */ |
| 3690 | name: string; |
| 3691 | /** True if this is info for a regular file. Mutually exclusive to |
| 3692 | * `DirEntry.isDirectory` and `DirEntry.isSymlink`. */ |
| 3693 | isFile: boolean; |
| 3694 | /** True if this is info for a regular directory. Mutually exclusive to |
| 3695 | * `DirEntry.isFile` and `DirEntry.isSymlink`. */ |
| 3696 | isDirectory: boolean; |
| 3697 | /** True if this is info for a symlink. Mutually exclusive to |
| 3698 | * `DirEntry.isFile` and `DirEntry.isDirectory`. */ |
| 3699 | isSymlink: boolean; |
| 3700 | } |
| 3701 | |
| 3702 | /** Reads the directory given by `path` and returns an async iterable of |
| 3703 | * {@linkcode Deno.DirEntry}. The order of entries is not guaranteed. |
| 3704 | * |
| 3705 | * ```ts |
| 3706 | * for await (const dirEntry of Deno.readDir("/")) { |
| 3707 | * console.log(dirEntry.name); |
| 3708 | * } |
| 3709 | * ``` |
| 3710 | * |
| 3711 | * Throws error if `path` is not a directory. |
| 3712 | * |
| 3713 | * Requires `allow-read` permission. |
| 3714 | * |
| 3715 | * @tags allow-read |
| 3716 | * @category File System |
| 3717 | */ |
| 3718 | export function readDir(path: string | URL): AsyncIterable<DirEntry>; |
| 3719 | |
| 3720 | /** Synchronously reads the directory given by `path` and returns an iterable |
| 3721 | * of {@linkcode Deno.DirEntry}. The order of entries is not guaranteed. |
| 3722 | * |
| 3723 | * ```ts |
| 3724 | * for (const dirEntry of Deno.readDirSync("/")) { |
| 3725 | * console.log(dirEntry.name); |
| 3726 | * } |
| 3727 | * ``` |
| 3728 | * |
| 3729 | * Throws error if `path` is not a directory. |
| 3730 | * |
| 3731 | * Requires `allow-read` permission. |
| 3732 | * |
| 3733 | * @tags allow-read |
| 3734 | * @category File System |
| 3735 | */ |
| 3736 | export function readDirSync(path: string | URL): Iterable<DirEntry>; |
| 3737 | |
| 3738 | /** Copies the contents and permissions of one file to another specified path, |
| 3739 | * by default creating a new file if needed, else overwriting. Fails if target |
| 3740 | * path is a directory or is unwritable. |
| 3741 | * |
| 3742 | * ```ts |
| 3743 | * await Deno.copyFile("from.txt", "to.txt"); |
| 3744 | * ``` |
| 3745 | * |
| 3746 | * Requires `allow-read` permission on `fromPath`. |
| 3747 | * |
| 3748 | * Requires `allow-write` permission on `toPath`. |
| 3749 | * |
| 3750 | * @tags allow-read, allow-write |
| 3751 | * @category File System |
| 3752 | */ |
| 3753 | export function copyFile( |
| 3754 | fromPath: string | URL, |
| 3755 | toPath: string | URL, |
| 3756 | ): Promise<void>; |
| 3757 | |
| 3758 | /** Synchronously copies the contents and permissions of one file to another |
| 3759 | * specified path, by default creating a new file if needed, else overwriting. |
| 3760 | * Fails if target path is a directory or is unwritable. |
| 3761 | * |
| 3762 | * ```ts |
| 3763 | * Deno.copyFileSync("from.txt", "to.txt"); |
| 3764 | * ``` |
| 3765 | * |
| 3766 | * Requires `allow-read` permission on `fromPath`. |
| 3767 | * |
| 3768 | * Requires `allow-write` permission on `toPath`. |
| 3769 | * |
| 3770 | * @tags allow-read, allow-write |
| 3771 | * @category File System |
| 3772 | */ |
| 3773 | export function copyFileSync( |
| 3774 | fromPath: string | URL, |
| 3775 | toPath: string | URL, |
| 3776 | ): void; |
| 3777 | |
| 3778 | /** Resolves to the full path destination of the named symbolic link. |
| 3779 | * |
| 3780 | * ```ts |
| 3781 | * await Deno.symlink("./test.txt", "./test_link.txt"); |
| 3782 | * const target = await Deno.readLink("./test_link.txt"); // full path of ./test.txt |
| 3783 | * ``` |
| 3784 | * |
| 3785 | * Throws TypeError if called with a hard link. |
| 3786 | * |
| 3787 | * Requires `allow-read` permission. |
| 3788 | * |
| 3789 | * @tags allow-read |
| 3790 | * @category File System |
| 3791 | */ |
| 3792 | export function readLink(path: string | URL): Promise<string>; |
| 3793 | |
| 3794 | /** Synchronously returns the full path destination of the named symbolic |
| 3795 | * link. |
| 3796 | * |
| 3797 | * ```ts |
| 3798 | * Deno.symlinkSync("./test.txt", "./test_link.txt"); |
| 3799 | * const target = Deno.readLinkSync("./test_link.txt"); // full path of ./test.txt |
| 3800 | * ``` |
| 3801 | * |
| 3802 | * Throws TypeError if called with a hard link. |
| 3803 | * |
| 3804 | * Requires `allow-read` permission. |
| 3805 | * |
| 3806 | * @tags allow-read |
| 3807 | * @category File System |
| 3808 | */ |
| 3809 | export function readLinkSync(path: string | URL): string; |
| 3810 | |
| 3811 | /** Resolves to a {@linkcode Deno.FileInfo} for the specified `path`. If |
| 3812 | * `path` is a symlink, information for the symlink will be returned instead |
| 3813 | * of what it points to. |
| 3814 | * |
| 3815 | * ```ts |
| 3816 | * import { assert } from "jsr:@std/assert"; |
| 3817 | * const fileInfo = await Deno.lstat("hello.txt"); |
| 3818 | * assert(fileInfo.isFile); |
| 3819 | * ``` |
| 3820 | * |
| 3821 | * Requires `allow-read` permission. |
| 3822 | * |
| 3823 | * @tags allow-read |
| 3824 | * @category File System |
| 3825 | */ |
| 3826 | export function lstat(path: string | URL): Promise<FileInfo>; |
| 3827 | |
| 3828 | /** Synchronously returns a {@linkcode Deno.FileInfo} for the specified |
| 3829 | * `path`. If `path` is a symlink, information for the symlink will be |
| 3830 | * returned instead of what it points to. |
| 3831 | * |
| 3832 | * ```ts |
| 3833 | * import { assert } from "jsr:@std/assert"; |
| 3834 | * const fileInfo = Deno.lstatSync("hello.txt"); |
| 3835 | * assert(fileInfo.isFile); |
| 3836 | * ``` |
| 3837 | * |
| 3838 | * Requires `allow-read` permission. |
| 3839 | * |
| 3840 | * @tags allow-read |
| 3841 | * @category File System |
| 3842 | */ |
| 3843 | export function lstatSync(path: string | URL): FileInfo; |
| 3844 | |
| 3845 | /** Resolves to a {@linkcode Deno.FileInfo} for the specified `path`. Will |
| 3846 | * always follow symlinks. |
| 3847 | * |
| 3848 | * ```ts |
| 3849 | * import { assert } from "jsr:@std/assert"; |
| 3850 | * const fileInfo = await Deno.stat("hello.txt"); |
| 3851 | * assert(fileInfo.isFile); |
| 3852 | * ``` |
| 3853 | * |
| 3854 | * Requires `allow-read` permission. |
| 3855 | * |
| 3856 | * @tags allow-read |
| 3857 | * @category File System |
| 3858 | */ |
| 3859 | export function stat(path: string | URL): Promise<FileInfo>; |
| 3860 | |
| 3861 | /** Synchronously returns a {@linkcode Deno.FileInfo} for the specified |
| 3862 | * `path`. Will always follow symlinks. |
| 3863 | * |
| 3864 | * ```ts |
| 3865 | * import { assert } from "jsr:@std/assert"; |
| 3866 | * const fileInfo = Deno.statSync("hello.txt"); |
| 3867 | * assert(fileInfo.isFile); |
| 3868 | * ``` |
| 3869 | * |
| 3870 | * Requires `allow-read` permission. |
| 3871 | * |
| 3872 | * @tags allow-read |
| 3873 | * @category File System |
| 3874 | */ |
| 3875 | export function statSync(path: string | URL): FileInfo; |
| 3876 | |
| 3877 | /** Options for writing to a file. |
| 3878 | * |
| 3879 | * @category File System |
| 3880 | */ |
| 3881 | export interface WriteFileOptions { |
| 3882 | /** If set to `true`, will append to a file instead of overwriting previous |
| 3883 | * contents. |
| 3884 | * |
| 3885 | * @default {false} */ |
| 3886 | append?: boolean; |
| 3887 | /** Sets the option to allow creating a new file, if one doesn't already |
| 3888 | * exist at the specified path. |
| 3889 | * |
| 3890 | * @default {true} */ |
| 3891 | create?: boolean; |
| 3892 | /** If set to `true`, no file, directory, or symlink is allowed to exist at |
| 3893 | * the target location. When createNew is set to `true`, `create` is ignored. |
| 3894 | * |
| 3895 | * @default {false} */ |
| 3896 | createNew?: boolean; |
| 3897 | /** Permissions always applied to file. */ |
| 3898 | mode?: number; |
| 3899 | /** An abort signal to allow cancellation of the file write operation. |
| 3900 | * |
| 3901 | * If the signal becomes aborted the write file operation will be stopped |
| 3902 | * and the promise returned will be rejected with an {@linkcode AbortError}. |
| 3903 | */ |
| 3904 | signal?: AbortSignal; |
| 3905 | } |
| 3906 | |
| 3907 | /** Write `data` to the given `path`, by default creating a new file if |
| 3908 | * needed, else overwriting. |
| 3909 | * |
| 3910 | * ```ts |
| 3911 | * const encoder = new TextEncoder(); |
| 3912 | * const data = encoder.encode("Hello world\n"); |
| 3913 | * await Deno.writeFile("hello1.txt", data); // overwrite "hello1.txt" or create it |
| 3914 | * await Deno.writeFile("hello2.txt", data, { create: false }); // only works if "hello2.txt" exists |
| 3915 | * await Deno.writeFile("hello3.txt", data, { mode: 0o777 }); // set permissions on new file |
| 3916 | * await Deno.writeFile("hello4.txt", data, { append: true }); // add data to the end of the file |
| 3917 | * ``` |
| 3918 | * |
| 3919 | * Requires `allow-write` permission, and `allow-read` if `options.create` is |
| 3920 | * `false`. |
| 3921 | * |
| 3922 | * @tags allow-read, allow-write |
| 3923 | * @category File System |
| 3924 | */ |
| 3925 | export function writeFile( |
| 3926 | path: string | URL, |
| 3927 | data: Uint8Array | ReadableStream<Uint8Array>, |
| 3928 | options?: WriteFileOptions, |
| 3929 | ): Promise<void>; |
| 3930 | |
| 3931 | /** Synchronously write `data` to the given `path`, by default creating a new |
| 3932 | * file if needed, else overwriting. |
| 3933 | * |
| 3934 | * ```ts |
| 3935 | * const encoder = new TextEncoder(); |
| 3936 | * const data = encoder.encode("Hello world\n"); |
| 3937 | * Deno.writeFileSync("hello1.txt", data); // overwrite "hello1.txt" or create it |
| 3938 | * Deno.writeFileSync("hello2.txt", data, { create: false }); // only works if "hello2.txt" exists |
| 3939 | * Deno.writeFileSync("hello3.txt", data, { mode: 0o777 }); // set permissions on new file |
| 3940 | * Deno.writeFileSync("hello4.txt", data, { append: true }); // add data to the end of the file |
| 3941 | * ``` |
| 3942 | * |
| 3943 | * Requires `allow-write` permission, and `allow-read` if `options.create` is |
| 3944 | * `false`. |
| 3945 | * |
| 3946 | * @tags allow-read, allow-write |
| 3947 | * @category File System |
| 3948 | */ |
| 3949 | export function writeFileSync( |
| 3950 | path: string | URL, |
| 3951 | data: Uint8Array, |
| 3952 | options?: WriteFileOptions, |
| 3953 | ): void; |
| 3954 | |
| 3955 | /** Write string `data` to the given `path`, by default creating a new file if |
| 3956 | * needed, else overwriting. |
| 3957 | * |
| 3958 | * ```ts |
| 3959 | * await Deno.writeTextFile("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it |
| 3960 | * ``` |
| 3961 | * |
| 3962 | * Requires `allow-write` permission, and `allow-read` if `options.create` is |
| 3963 | * `false`. |
| 3964 | * |
| 3965 | * @tags allow-read, allow-write |
| 3966 | * @category File System |
| 3967 | */ |
| 3968 | export function writeTextFile( |
| 3969 | path: string | URL, |
| 3970 | data: string | ReadableStream<string>, |
| 3971 | options?: WriteFileOptions, |
| 3972 | ): Promise<void>; |
| 3973 | |
| 3974 | /** Synchronously write string `data` to the given `path`, by default creating |
| 3975 | * a new file if needed, else overwriting. |
| 3976 | * |
| 3977 | * ```ts |
| 3978 | * Deno.writeTextFileSync("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it |
| 3979 | * ``` |
| 3980 | * |
| 3981 | * Requires `allow-write` permission, and `allow-read` if `options.create` is |
| 3982 | * `false`. |
| 3983 | * |
| 3984 | * @tags allow-read, allow-write |
| 3985 | * @category File System |
| 3986 | */ |
| 3987 | export function writeTextFileSync( |
| 3988 | path: string | URL, |
| 3989 | data: string, |
| 3990 | options?: WriteFileOptions, |
| 3991 | ): void; |
| 3992 | |
| 3993 | /** Truncates (or extends) the specified file, to reach the specified `len`. |
| 3994 | * If `len` is not specified then the entire file contents are truncated. |
| 3995 | * |
| 3996 | * ### Truncate the entire file |
| 3997 | * ```ts |
| 3998 | * await Deno.truncate("my_file.txt"); |
| 3999 | * ``` |
| 4000 | * |
| 4001 | * ### Truncate part of the file |
| 4002 | * |
| 4003 | * ```ts |
| 4004 | * const file = await Deno.makeTempFile(); |
| 4005 | * await Deno.writeTextFile(file, "Hello World"); |
| 4006 | * await Deno.truncate(file, 7); |
| 4007 | * const data = await Deno.readFile(file); |
| 4008 | * console.log(new TextDecoder().decode(data)); // "Hello W" |
| 4009 | * ``` |
| 4010 | * |
| 4011 | * Requires `allow-write` permission. |
| 4012 | * |
| 4013 | * @tags allow-write |
| 4014 | * @category File System |
| 4015 | */ |
| 4016 | export function truncate(name: string, len?: number): Promise<void>; |
| 4017 | |
| 4018 | /** Synchronously truncates (or extends) the specified file, to reach the |
| 4019 | * specified `len`. If `len` is not specified then the entire file contents |
| 4020 | * are truncated. |
| 4021 | * |
| 4022 | * ### Truncate the entire file |
| 4023 | * |
| 4024 | * ```ts |
| 4025 | * Deno.truncateSync("my_file.txt"); |
| 4026 | * ``` |
| 4027 | * |
| 4028 | * ### Truncate part of the file |
| 4029 | * |
| 4030 | * ```ts |
| 4031 | * const file = Deno.makeTempFileSync(); |
| 4032 | * Deno.writeFileSync(file, new TextEncoder().encode("Hello World")); |
| 4033 | * Deno.truncateSync(file, 7); |
| 4034 | * const data = Deno.readFileSync(file); |
| 4035 | * console.log(new TextDecoder().decode(data)); |
| 4036 | * ``` |
| 4037 | * |
| 4038 | * Requires `allow-write` permission. |
| 4039 | * |
| 4040 | * @tags allow-write |
| 4041 | * @category File System |
| 4042 | */ |
| 4043 | export function truncateSync(name: string, len?: number): void; |
| 4044 | |
| 4045 | /** @category Runtime |
| 4046 | * |
| 4047 | * @deprecated This will be removed in Deno 2.0. |
| 4048 | */ |
| 4049 | export interface OpMetrics { |
| 4050 | opsDispatched: number; |
| 4051 | opsDispatchedSync: number; |
| 4052 | opsDispatchedAsync: number; |
| 4053 | opsDispatchedAsyncUnref: number; |
| 4054 | opsCompleted: number; |
| 4055 | opsCompletedSync: number; |
| 4056 | opsCompletedAsync: number; |
| 4057 | opsCompletedAsyncUnref: number; |
| 4058 | bytesSentControl: number; |
| 4059 | bytesSentData: number; |
| 4060 | bytesReceived: number; |
| 4061 | } |
| 4062 | |
| 4063 | /** @category Runtime |
| 4064 | * |
| 4065 | * @deprecated This will be removed in Deno 2.0. |
| 4066 | */ |
| 4067 | export interface Metrics extends OpMetrics { |
| 4068 | ops: Record<string, OpMetrics>; |
| 4069 | } |
| 4070 | |
| 4071 | /** Receive metrics from the privileged side of Deno. This is primarily used |
| 4072 | * in the development of Deno. _Ops_, also called _bindings_, are the |
| 4073 | * go-between between Deno JavaScript sandbox and the rest of Deno. |
| 4074 | * |
| 4075 | * ```shell |
| 4076 | * > console.table(Deno.metrics()) |
| 4077 | * ┌─────────────────────────┬────────┐ |
| 4078 | * │ (index) │ Values │ |
| 4079 | * ├─────────────────────────┼────────┤ |
| 4080 | * │ opsDispatched │ 3 │ |
| 4081 | * │ opsDispatchedSync │ 2 │ |
| 4082 | * │ opsDispatchedAsync │ 1 │ |
| 4083 | * │ opsDispatchedAsyncUnref │ 0 │ |
| 4084 | * │ opsCompleted │ 3 │ |
| 4085 | * │ opsCompletedSync │ 2 │ |
| 4086 | * │ opsCompletedAsync │ 1 │ |
| 4087 | * │ opsCompletedAsyncUnref │ 0 │ |
| 4088 | * │ bytesSentControl │ 73 │ |
| 4089 | * │ bytesSentData │ 0 │ |
| 4090 | * │ bytesReceived │ 375 │ |
| 4091 | * └─────────────────────────┴────────┘ |
| 4092 | * ``` |
| 4093 | * |
| 4094 | * @category Runtime |
| 4095 | * |
| 4096 | * @deprecated This will be removed in Deno 2.0. |
| 4097 | */ |
| 4098 | export function metrics(): Metrics; |
| 4099 | |
| 4100 | /** |
| 4101 | * A map of open resources that Deno is tracking. The key is the resource ID |
| 4102 | * (_rid_) and the value is its representation. |
| 4103 | * |
| 4104 | * @deprecated This will be removed in Deno 2.0. |
| 4105 | * |
| 4106 | * @category Runtime */ |
| 4107 | export interface ResourceMap { |
| 4108 | [rid: number]: unknown; |
| 4109 | } |
| 4110 | |
| 4111 | /** Returns a map of open resource IDs (_rid_) along with their string |
| 4112 | * representations. This is an internal API and as such resource |
| 4113 | * representation has `unknown` type; that means it can change any time and |
| 4114 | * should not be depended upon. |
| 4115 | * |
| 4116 | * ```ts |
| 4117 | * console.log(Deno.resources()); |
| 4118 | * // { 0: "stdin", 1: "stdout", 2: "stderr" } |
| 4119 | * Deno.openSync('../test.file'); |
| 4120 | * console.log(Deno.resources()); |
| 4121 | * // { 0: "stdin", 1: "stdout", 2: "stderr", 3: "fsFile" } |
| 4122 | * ``` |
| 4123 | * |
| 4124 | * @deprecated This will be removed in Deno 2.0. |
| 4125 | * |
| 4126 | * @category Runtime |
| 4127 | */ |
| 4128 | export function resources(): ResourceMap; |
| 4129 | |
| 4130 | /** |
| 4131 | * Additional information for FsEvent objects with the "other" kind. |
| 4132 | * |
| 4133 | * - `"rescan"`: rescan notices indicate either a lapse in the events or a |
| 4134 | * change in the filesystem such that events received so far can no longer |
| 4135 | * be relied on to represent the state of the filesystem now. An |
| 4136 | * application that simply reacts to file changes may not care about this. |
| 4137 | * An application that keeps an in-memory representation of the filesystem |
| 4138 | * will need to care, and will need to refresh that representation directly |
| 4139 | * from the filesystem. |
| 4140 | * |
| 4141 | * @category File System |
| 4142 | */ |
| 4143 | export type FsEventFlag = "rescan"; |
| 4144 | |
| 4145 | /** |
| 4146 | * Represents a unique file system event yielded by a |
| 4147 | * {@linkcode Deno.FsWatcher}. |
| 4148 | * |
| 4149 | * @category File System */ |
| 4150 | export interface FsEvent { |
| 4151 | /** The kind/type of the file system event. */ |
| 4152 | kind: "any" | "access" | "create" | "modify" | "remove" | "other"; |
| 4153 | /** An array of paths that are associated with the file system event. */ |
| 4154 | paths: string[]; |
| 4155 | /** Any additional flags associated with the event. */ |
| 4156 | flag?: FsEventFlag; |
| 4157 | } |
| 4158 | |
| 4159 | /** |
| 4160 | * Returned by {@linkcode Deno.watchFs}. It is an async iterator yielding up |
| 4161 | * system events. To stop watching the file system by calling `.close()` |
| 4162 | * method. |
| 4163 | * |
| 4164 | * @category File System |
| 4165 | */ |
| 4166 | export interface FsWatcher extends AsyncIterable<FsEvent>, Disposable { |
| 4167 | /** |
| 4168 | * The resource id. |
| 4169 | * |
| 4170 | * @deprecated This will be removed in Deno 2.0. See the |
| 4171 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 4172 | * for migration instructions. |
| 4173 | */ |
| 4174 | readonly rid: number; |
| 4175 | /** Stops watching the file system and closes the watcher resource. */ |
| 4176 | close(): void; |
| 4177 | /** |
| 4178 | * Stops watching the file system and closes the watcher resource. |
| 4179 | * |
| 4180 | * @deprecated This will be removed in Deno 2.0. See the |
| 4181 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 4182 | * for migration instructions. |
| 4183 | */ |
| 4184 | return?(value?: any): Promise<IteratorResult<FsEvent>>; |
| 4185 | [Symbol.asyncIterator](): AsyncIterableIterator<FsEvent>; |
| 4186 | } |
| 4187 | |
| 4188 | /** Watch for file system events against one or more `paths`, which can be |
| 4189 | * files or directories. These paths must exist already. One user action (e.g. |
| 4190 | * `touch test.file`) can generate multiple file system events. Likewise, |
| 4191 | * one user action can result in multiple file paths in one event (e.g. `mv |
| 4192 | * old_name.txt new_name.txt`). |
| 4193 | * |
| 4194 | * The recursive option is `true` by default and, for directories, will watch |
| 4195 | * the specified directory and all sub directories. |
| 4196 | * |
| 4197 | * Note that the exact ordering of the events can vary between operating |
| 4198 | * systems. |
| 4199 | * |
| 4200 | * ```ts |
| 4201 | * const watcher = Deno.watchFs("/"); |
| 4202 | * for await (const event of watcher) { |
| 4203 | * console.log(">>>> event", event); |
| 4204 | * // { kind: "create", paths: [ "/foo.txt" ] } |
| 4205 | * } |
| 4206 | * ``` |
| 4207 | * |
| 4208 | * Call `watcher.close()` to stop watching. |
| 4209 | * |
| 4210 | * ```ts |
| 4211 | * const watcher = Deno.watchFs("/"); |
| 4212 | * |
| 4213 | * setTimeout(() => { |
| 4214 | * watcher.close(); |
| 4215 | * }, 5000); |
| 4216 | * |
| 4217 | * for await (const event of watcher) { |
| 4218 | * console.log(">>>> event", event); |
| 4219 | * } |
| 4220 | * ``` |
| 4221 | * |
| 4222 | * Requires `allow-read` permission. |
| 4223 | * |
| 4224 | * @tags allow-read |
| 4225 | * @category File System |
| 4226 | */ |
| 4227 | export function watchFs( |
| 4228 | paths: string | string[], |
| 4229 | options?: { recursive: boolean }, |
| 4230 | ): FsWatcher; |
| 4231 | |
| 4232 | /** |
| 4233 | * Options which can be used with {@linkcode Deno.run}. |
| 4234 | * |
| 4235 | * @deprecated This will be removed in Deno 2.0. See the |
| 4236 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 4237 | * for migration instructions. |
| 4238 | * |
| 4239 | * @category Sub Process */ |
| 4240 | export interface RunOptions { |
| 4241 | /** Arguments to pass. |
| 4242 | * |
| 4243 | * _Note_: the first element needs to be a path to the executable that is |
| 4244 | * being run. */ |
| 4245 | cmd: readonly string[] | [string | URL, ...string[]]; |
| 4246 | /** The current working directory that should be used when running the |
| 4247 | * sub-process. */ |
| 4248 | cwd?: string; |
| 4249 | /** Any environment variables to be set when running the sub-process. */ |
| 4250 | env?: Record<string, string>; |
| 4251 | /** By default subprocess inherits `stdout` of parent process. To change |
| 4252 | * this this option can be set to a resource ID (_rid_) of an open file, |
| 4253 | * `"inherit"`, `"piped"`, or `"null"`: |
| 4254 | * |
| 4255 | * - _number_: the resource ID of an open file/resource. This allows you to |
| 4256 | * write to a file. |
| 4257 | * - `"inherit"`: The default if unspecified. The subprocess inherits from the |
| 4258 | * parent. |
| 4259 | * - `"piped"`: A new pipe should be arranged to connect the parent and child |
| 4260 | * sub-process. |
| 4261 | * - `"null"`: This stream will be ignored. This is the equivalent of attaching |
| 4262 | * the stream to `/dev/null`. |
| 4263 | */ |
| 4264 | stdout?: "inherit" | "piped" | "null" | number; |
| 4265 | /** By default subprocess inherits `stderr` of parent process. To change |
| 4266 | * this this option can be set to a resource ID (_rid_) of an open file, |
| 4267 | * `"inherit"`, `"piped"`, or `"null"`: |
| 4268 | * |
| 4269 | * - _number_: the resource ID of an open file/resource. This allows you to |
| 4270 | * write to a file. |
| 4271 | * - `"inherit"`: The default if unspecified. The subprocess inherits from the |
| 4272 | * parent. |
| 4273 | * - `"piped"`: A new pipe should be arranged to connect the parent and child |
| 4274 | * sub-process. |
| 4275 | * - `"null"`: This stream will be ignored. This is the equivalent of attaching |
| 4276 | * the stream to `/dev/null`. |
| 4277 | */ |
| 4278 | stderr?: "inherit" | "piped" | "null" | number; |
| 4279 | /** By default subprocess inherits `stdin` of parent process. To change |
| 4280 | * this this option can be set to a resource ID (_rid_) of an open file, |
| 4281 | * `"inherit"`, `"piped"`, or `"null"`: |
| 4282 | * |
| 4283 | * - _number_: the resource ID of an open file/resource. This allows you to |
| 4284 | * read from a file. |
| 4285 | * - `"inherit"`: The default if unspecified. The subprocess inherits from the |
| 4286 | * parent. |
| 4287 | * - `"piped"`: A new pipe should be arranged to connect the parent and child |
| 4288 | * sub-process. |
| 4289 | * - `"null"`: This stream will be ignored. This is the equivalent of attaching |
| 4290 | * the stream to `/dev/null`. |
| 4291 | */ |
| 4292 | stdin?: "inherit" | "piped" | "null" | number; |
| 4293 | } |
| 4294 | |
| 4295 | /** |
| 4296 | * The status resolved from the `.status()` method of a |
| 4297 | * {@linkcode Deno.Process} instance. |
| 4298 | * |
| 4299 | * If `success` is `true`, then `code` will be `0`, but if `success` is |
| 4300 | * `false`, the sub-process exit code will be set in `code`. |
| 4301 | * |
| 4302 | * @deprecated This will be removed in Deno 2.0. See the |
| 4303 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 4304 | * for migration instructions. |
| 4305 | * |
| 4306 | * @category Sub Process */ |
| 4307 | export type ProcessStatus = |
| 4308 | | { |
| 4309 | success: true; |
| 4310 | code: 0; |
| 4311 | signal?: undefined; |
| 4312 | } |
| 4313 | | { |
| 4314 | success: false; |
| 4315 | code: number; |
| 4316 | signal?: number; |
| 4317 | }; |
| 4318 | |
| 4319 | /** |
| 4320 | * Represents an instance of a sub process that is returned from |
| 4321 | * {@linkcode Deno.run} which can be used to manage the sub-process. |
| 4322 | * |
| 4323 | * @deprecated This will be removed in Deno 2.0. See the |
| 4324 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 4325 | * for migration instructions. |
| 4326 | * |
| 4327 | * @category Sub Process */ |
| 4328 | export class Process<T extends RunOptions = RunOptions> { |
| 4329 | /** The resource ID of the sub-process. */ |
| 4330 | readonly rid: number; |
| 4331 | /** The operating system's process ID for the sub-process. */ |
| 4332 | readonly pid: number; |
| 4333 | /** A reference to the sub-processes `stdin`, which allows interacting with |
| 4334 | * the sub-process at a low level. */ |
| 4335 | readonly stdin: T["stdin"] extends "piped" ? Writer & Closer & { |
| 4336 | writable: WritableStream<Uint8Array>; |
| 4337 | } |
| 4338 | : (Writer & Closer & { writable: WritableStream<Uint8Array> }) | null; |
| 4339 | /** A reference to the sub-processes `stdout`, which allows interacting with |
| 4340 | * the sub-process at a low level. */ |
| 4341 | readonly stdout: T["stdout"] extends "piped" ? Reader & Closer & { |
| 4342 | readable: ReadableStream<Uint8Array>; |
| 4343 | } |
| 4344 | : (Reader & Closer & { readable: ReadableStream<Uint8Array> }) | null; |
| 4345 | /** A reference to the sub-processes `stderr`, which allows interacting with |
| 4346 | * the sub-process at a low level. */ |
| 4347 | readonly stderr: T["stderr"] extends "piped" ? Reader & Closer & { |
| 4348 | readable: ReadableStream<Uint8Array>; |
| 4349 | } |
| 4350 | : (Reader & Closer & { readable: ReadableStream<Uint8Array> }) | null; |
| 4351 | /** Wait for the process to exit and return its exit status. |
| 4352 | * |
| 4353 | * Calling this function multiple times will return the same status. |
| 4354 | * |
| 4355 | * The `stdin` reference to the process will be closed before waiting to |
| 4356 | * avoid a deadlock. |
| 4357 | * |
| 4358 | * If `stdout` and/or `stderr` were set to `"piped"`, they must be closed |
| 4359 | * manually before the process can exit. |
| 4360 | * |
| 4361 | * To run process to completion and collect output from both `stdout` and |
| 4362 | * `stderr` use: |
| 4363 | * |
| 4364 | * ```ts |
| 4365 | * const p = Deno.run({ cmd: [ "echo", "hello world" ], stderr: 'piped', stdout: 'piped' }); |
| 4366 | * const [status, stdout, stderr] = await Promise.all([ |
| 4367 | * p.status(), |
| 4368 | * p.output(), |
| 4369 | * p.stderrOutput() |
| 4370 | * ]); |
| 4371 | * p.close(); |
| 4372 | * ``` |
| 4373 | */ |
| 4374 | status(): Promise<ProcessStatus>; |
| 4375 | /** Buffer the stdout until EOF and return it as `Uint8Array`. |
| 4376 | * |
| 4377 | * You must set `stdout` to `"piped"` when creating the process. |
| 4378 | * |
| 4379 | * This calls `close()` on stdout after its done. */ |
| 4380 | output(): Promise<Uint8Array>; |
| 4381 | /** Buffer the stderr until EOF and return it as `Uint8Array`. |
| 4382 | * |
| 4383 | * You must set `stderr` to `"piped"` when creating the process. |
| 4384 | * |
| 4385 | * This calls `close()` on stderr after its done. */ |
| 4386 | stderrOutput(): Promise<Uint8Array>; |
| 4387 | /** Clean up resources associated with the sub-process instance. */ |
| 4388 | close(): void; |
| 4389 | /** Send a signal to process. |
| 4390 | * Default signal is `"SIGTERM"`. |
| 4391 | * |
| 4392 | * ```ts |
| 4393 | * const p = Deno.run({ cmd: [ "sleep", "20" ]}); |
| 4394 | * p.kill("SIGTERM"); |
| 4395 | * p.close(); |
| 4396 | * ``` |
| 4397 | */ |
| 4398 | kill(signo?: Signal): void; |
| 4399 | } |
| 4400 | |
| 4401 | /** Operating signals which can be listened for or sent to sub-processes. What |
| 4402 | * signals and what their standard behaviors are OS dependent. |
| 4403 | * |
| 4404 | * @category Runtime */ |
| 4405 | export type Signal = |
| 4406 | | "SIGABRT" |
| 4407 | | "SIGALRM" |
| 4408 | | "SIGBREAK" |
| 4409 | | "SIGBUS" |
| 4410 | | "SIGCHLD" |
| 4411 | | "SIGCONT" |
| 4412 | | "SIGEMT" |
| 4413 | | "SIGFPE" |
| 4414 | | "SIGHUP" |
| 4415 | | "SIGILL" |
| 4416 | | "SIGINFO" |
| 4417 | | "SIGINT" |
| 4418 | | "SIGIO" |
| 4419 | | "SIGPOLL" |
| 4420 | | "SIGUNUSED" |
| 4421 | | "SIGKILL" |
| 4422 | | "SIGPIPE" |
| 4423 | | "SIGPROF" |
| 4424 | | "SIGPWR" |
| 4425 | | "SIGQUIT" |
| 4426 | | "SIGSEGV" |
| 4427 | | "SIGSTKFLT" |
| 4428 | | "SIGSTOP" |
| 4429 | | "SIGSYS" |
| 4430 | | "SIGTERM" |
| 4431 | | "SIGTRAP" |
| 4432 | | "SIGTSTP" |
| 4433 | | "SIGTTIN" |
| 4434 | | "SIGTTOU" |
| 4435 | | "SIGURG" |
| 4436 | | "SIGUSR1" |
| 4437 | | "SIGUSR2" |
| 4438 | | "SIGVTALRM" |
| 4439 | | "SIGWINCH" |
| 4440 | | "SIGXCPU" |
| 4441 | | "SIGXFSZ"; |
| 4442 | |
| 4443 | /** Registers the given function as a listener of the given signal event. |
| 4444 | * |
| 4445 | * ```ts |
| 4446 | * Deno.addSignalListener( |
| 4447 | * "SIGTERM", |
| 4448 | * () => { |
| 4449 | * console.log("SIGTERM!") |
| 4450 | * } |
| 4451 | * ); |
| 4452 | * ``` |
| 4453 | * |
| 4454 | * _Note_: On Windows only `"SIGINT"` (CTRL+C) and `"SIGBREAK"` (CTRL+Break) |
| 4455 | * are supported. |
| 4456 | * |
| 4457 | * @category Runtime |
| 4458 | */ |
| 4459 | export function addSignalListener(signal: Signal, handler: () => void): void; |
| 4460 | |
| 4461 | /** Removes the given signal listener that has been registered with |
| 4462 | * {@linkcode Deno.addSignalListener}. |
| 4463 | * |
| 4464 | * ```ts |
| 4465 | * const listener = () => { |
| 4466 | * console.log("SIGTERM!") |
| 4467 | * }; |
| 4468 | * Deno.addSignalListener("SIGTERM", listener); |
| 4469 | * Deno.removeSignalListener("SIGTERM", listener); |
| 4470 | * ``` |
| 4471 | * |
| 4472 | * _Note_: On Windows only `"SIGINT"` (CTRL+C) and `"SIGBREAK"` (CTRL+Break) |
| 4473 | * are supported. |
| 4474 | * |
| 4475 | * @category Runtime |
| 4476 | */ |
| 4477 | export function removeSignalListener( |
| 4478 | signal: Signal, |
| 4479 | handler: () => void, |
| 4480 | ): void; |
| 4481 | |
| 4482 | /** |
| 4483 | * Spawns new subprocess. RunOptions must contain at a minimum the `opt.cmd`, |
| 4484 | * an array of program arguments, the first of which is the binary. |
| 4485 | * |
| 4486 | * ```ts |
| 4487 | * const p = Deno.run({ |
| 4488 | * cmd: ["curl", "https://example.com"], |
| 4489 | * }); |
| 4490 | * const status = await p.status(); |
| 4491 | * ``` |
| 4492 | * |
| 4493 | * Subprocess uses same working directory as parent process unless `opt.cwd` |
| 4494 | * is specified. |
| 4495 | * |
| 4496 | * Environmental variables from parent process can be cleared using `opt.clearEnv`. |
| 4497 | * Doesn't guarantee that only `opt.env` variables are present, |
| 4498 | * as the OS may set environmental variables for processes. |
| 4499 | * |
| 4500 | * Environmental variables for subprocess can be specified using `opt.env` |
| 4501 | * mapping. |
| 4502 | * |
| 4503 | * `opt.uid` sets the child process’s user ID. This translates to a setuid call |
| 4504 | * in the child process. Failure in the setuid call will cause the spawn to fail. |
| 4505 | * |
| 4506 | * `opt.gid` is similar to `opt.uid`, but sets the group ID of the child process. |
| 4507 | * This has the same semantics as the uid field. |
| 4508 | * |
| 4509 | * By default subprocess inherits stdio of parent process. To change |
| 4510 | * this this, `opt.stdin`, `opt.stdout`, and `opt.stderr` can be set |
| 4511 | * independently to a resource ID (_rid_) of an open file, `"inherit"`, |
| 4512 | * `"piped"`, or `"null"`: |
| 4513 | * |
| 4514 | * - _number_: the resource ID of an open file/resource. This allows you to |
| 4515 | * read or write to a file. |
| 4516 | * - `"inherit"`: The default if unspecified. The subprocess inherits from the |
| 4517 | * parent. |
| 4518 | * - `"piped"`: A new pipe should be arranged to connect the parent and child |
| 4519 | * sub-process. |
| 4520 | * - `"null"`: This stream will be ignored. This is the equivalent of attaching |
| 4521 | * the stream to `/dev/null`. |
| 4522 | * |
| 4523 | * Details of the spawned process are returned as an instance of |
| 4524 | * {@linkcode Deno.Process}. |
| 4525 | * |
| 4526 | * Requires `allow-run` permission. |
| 4527 | * |
| 4528 | * @deprecated This will be soft-removed in Deno 2.0. See the |
| 4529 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 4530 | * for migration instructions. |
| 4531 | * |
| 4532 | * @tags allow-run |
| 4533 | * @category Sub Process |
| 4534 | */ |
| 4535 | export function run<T extends RunOptions = RunOptions>(opt: T): Process<T>; |
| 4536 | |
| 4537 | /** Create a child process. |
| 4538 | * |
| 4539 | * If any stdio options are not set to `"piped"`, accessing the corresponding |
| 4540 | * field on the `Command` or its `CommandOutput` will throw a `TypeError`. |
| 4541 | * |
| 4542 | * If `stdin` is set to `"piped"`, the `stdin` {@linkcode WritableStream} |
| 4543 | * needs to be closed manually. |
| 4544 | * |
| 4545 | * `Command` acts as a builder. Each call to {@linkcode Command.spawn} or |
| 4546 | * {@linkcode Command.output} will spawn a new subprocess. |
| 4547 | * |
| 4548 | * @example Spawn a subprocess and pipe the output to a file |
| 4549 | * |
| 4550 | * ```ts |
| 4551 | * const command = new Deno.Command(Deno.execPath(), { |
| 4552 | * args: [ |
| 4553 | * "eval", |
| 4554 | * "console.log('Hello World')", |
| 4555 | * ], |
| 4556 | * stdin: "piped", |
| 4557 | * stdout: "piped", |
| 4558 | * }); |
| 4559 | * const child = command.spawn(); |
| 4560 | * |
| 4561 | * // open a file and pipe the subprocess output to it. |
| 4562 | * child.stdout.pipeTo( |
| 4563 | * Deno.openSync("output", { write: true, create: true }).writable, |
| 4564 | * ); |
| 4565 | * |
| 4566 | * // manually close stdin |
| 4567 | * child.stdin.close(); |
| 4568 | * const status = await child.status; |
| 4569 | * ``` |
| 4570 | * |
| 4571 | * @example Spawn a subprocess and collect its output |
| 4572 | * |
| 4573 | * ```ts |
| 4574 | * const command = new Deno.Command(Deno.execPath(), { |
| 4575 | * args: [ |
| 4576 | * "eval", |
| 4577 | * "console.log('hello'); console.error('world')", |
| 4578 | * ], |
| 4579 | * }); |
| 4580 | * const { code, stdout, stderr } = await command.output(); |
| 4581 | * console.assert(code === 0); |
| 4582 | * console.assert("hello\n" === new TextDecoder().decode(stdout)); |
| 4583 | * console.assert("world\n" === new TextDecoder().decode(stderr)); |
| 4584 | * ``` |
| 4585 | * |
| 4586 | * @example Spawn a subprocess and collect its output synchronously |
| 4587 | * |
| 4588 | * ```ts |
| 4589 | * const command = new Deno.Command(Deno.execPath(), { |
| 4590 | * args: [ |
| 4591 | * "eval", |
| 4592 | * "console.log('hello'); console.error('world')", |
| 4593 | * ], |
| 4594 | * }); |
| 4595 | * const { code, stdout, stderr } = command.outputSync(); |
| 4596 | * console.assert(code === 0); |
| 4597 | * console.assert("hello\n" === new TextDecoder().decode(stdout)); |
| 4598 | * console.assert("world\n" === new TextDecoder().decode(stderr)); |
| 4599 | * ``` |
| 4600 | * |
| 4601 | * @tags allow-run |
| 4602 | * @category Sub Process |
| 4603 | */ |
| 4604 | export class Command { |
| 4605 | constructor(command: string | URL, options?: CommandOptions); |
| 4606 | /** |
| 4607 | * Executes the {@linkcode Deno.Command}, waiting for it to finish and |
| 4608 | * collecting all of its output. |
| 4609 | * |
| 4610 | * Will throw an error if `stdin: "piped"` is set. |
| 4611 | * |
| 4612 | * If options `stdout` or `stderr` are not set to `"piped"`, accessing the |
| 4613 | * corresponding field on {@linkcode Deno.CommandOutput} will throw a `TypeError`. |
| 4614 | */ |
| 4615 | output(): Promise<CommandOutput>; |
| 4616 | /** |
| 4617 | * Synchronously executes the {@linkcode Deno.Command}, waiting for it to |
| 4618 | * finish and collecting all of its output. |
| 4619 | * |
| 4620 | * Will throw an error if `stdin: "piped"` is set. |
| 4621 | * |
| 4622 | * If options `stdout` or `stderr` are not set to `"piped"`, accessing the |
| 4623 | * corresponding field on {@linkcode Deno.CommandOutput} will throw a `TypeError`. |
| 4624 | */ |
| 4625 | outputSync(): CommandOutput; |
| 4626 | /** |
| 4627 | * Spawns a streamable subprocess, allowing to use the other methods. |
| 4628 | */ |
| 4629 | spawn(): ChildProcess; |
| 4630 | } |
| 4631 | |
| 4632 | /** |
| 4633 | * The interface for handling a child process returned from |
| 4634 | * {@linkcode Deno.Command.spawn}. |
| 4635 | * |
| 4636 | * @category Sub Process |
| 4637 | */ |
| 4638 | export class ChildProcess implements AsyncDisposable { |
| 4639 | get stdin(): WritableStream<Uint8Array>; |
| 4640 | get stdout(): ReadableStream<Uint8Array>; |
| 4641 | get stderr(): ReadableStream<Uint8Array>; |
| 4642 | readonly pid: number; |
| 4643 | /** Get the status of the child. */ |
| 4644 | readonly status: Promise<CommandStatus>; |
| 4645 | |
| 4646 | /** Waits for the child to exit completely, returning all its output and |
| 4647 | * status. */ |
| 4648 | output(): Promise<CommandOutput>; |
| 4649 | /** Kills the process with given {@linkcode Deno.Signal}. |
| 4650 | * |
| 4651 | * Defaults to `SIGTERM` if no signal is provided. |
| 4652 | * |
| 4653 | * @param [signo="SIGTERM"] |
| 4654 | */ |
| 4655 | kill(signo?: Signal): void; |
| 4656 | |
| 4657 | /** Ensure that the status of the child process prevents the Deno process |
| 4658 | * from exiting. */ |
| 4659 | ref(): void; |
| 4660 | /** Ensure that the status of the child process does not block the Deno |
| 4661 | * process from exiting. */ |
| 4662 | unref(): void; |
| 4663 | |
| 4664 | [Symbol.asyncDispose](): Promise<void>; |
| 4665 | } |
| 4666 | |
| 4667 | /** |
| 4668 | * Options which can be set when calling {@linkcode Deno.Command}. |
| 4669 | * |
| 4670 | * @category Sub Process |
| 4671 | */ |
| 4672 | export interface CommandOptions { |
| 4673 | /** Arguments to pass to the process. */ |
| 4674 | args?: string[]; |
| 4675 | /** |
| 4676 | * The working directory of the process. |
| 4677 | * |
| 4678 | * If not specified, the `cwd` of the parent process is used. |
| 4679 | */ |
| 4680 | cwd?: string | URL; |
| 4681 | /** |
| 4682 | * Clear environmental variables from parent process. |
| 4683 | * |
| 4684 | * Doesn't guarantee that only `env` variables are present, as the OS may |
| 4685 | * set environmental variables for processes. |
| 4686 | * |
| 4687 | * @default {false} |
| 4688 | */ |
| 4689 | clearEnv?: boolean; |
| 4690 | /** Environmental variables to pass to the subprocess. */ |
| 4691 | env?: Record<string, string>; |
| 4692 | /** |
| 4693 | * Sets the child process’s user ID. This translates to a setuid call in the |
| 4694 | * child process. Failure in the set uid call will cause the spawn to fail. |
| 4695 | */ |
| 4696 | uid?: number; |
| 4697 | /** Similar to `uid`, but sets the group ID of the child process. */ |
| 4698 | gid?: number; |
| 4699 | /** |
| 4700 | * An {@linkcode AbortSignal} that allows closing the process using the |
| 4701 | * corresponding {@linkcode AbortController} by sending the process a |
| 4702 | * SIGTERM signal. |
| 4703 | * |
| 4704 | * Not supported in {@linkcode Deno.Command.outputSync}. |
| 4705 | */ |
| 4706 | signal?: AbortSignal; |
| 4707 | |
| 4708 | /** How `stdin` of the spawned process should be handled. |
| 4709 | * |
| 4710 | * Defaults to `"inherit"` for `output` & `outputSync`, |
| 4711 | * and `"inherit"` for `spawn`. */ |
| 4712 | stdin?: "piped" | "inherit" | "null"; |
| 4713 | /** How `stdout` of the spawned process should be handled. |
| 4714 | * |
| 4715 | * Defaults to `"piped"` for `output` & `outputSync`, |
| 4716 | * and `"inherit"` for `spawn`. */ |
| 4717 | stdout?: "piped" | "inherit" | "null"; |
| 4718 | /** How `stderr` of the spawned process should be handled. |
| 4719 | * |
| 4720 | * Defaults to `"piped"` for `output` & `outputSync`, |
| 4721 | * and `"inherit"` for `spawn`. */ |
| 4722 | stderr?: "piped" | "inherit" | "null"; |
| 4723 | |
| 4724 | /** Skips quoting and escaping of the arguments on windows. This option |
| 4725 | * is ignored on non-windows platforms. |
| 4726 | * |
| 4727 | * @default {false} */ |
| 4728 | windowsRawArguments?: boolean; |
| 4729 | } |
| 4730 | |
| 4731 | /** |
| 4732 | * @category Sub Process |
| 4733 | */ |
| 4734 | export interface CommandStatus { |
| 4735 | /** If the child process exits with a 0 status code, `success` will be set |
| 4736 | * to `true`, otherwise `false`. */ |
| 4737 | success: boolean; |
| 4738 | /** The exit code of the child process. */ |
| 4739 | code: number; |
| 4740 | /** The signal associated with the child process. */ |
| 4741 | signal: Signal | null; |
| 4742 | } |
| 4743 | |
| 4744 | /** |
| 4745 | * The interface returned from calling {@linkcode Deno.Command.output} or |
| 4746 | * {@linkcode Deno.Command.outputSync} which represents the result of spawning the |
| 4747 | * child process. |
| 4748 | * |
| 4749 | * @category Sub Process |
| 4750 | */ |
| 4751 | export interface CommandOutput extends CommandStatus { |
| 4752 | /** The buffered output from the child process' `stdout`. */ |
| 4753 | readonly stdout: Uint8Array; |
| 4754 | /** The buffered output from the child process' `stderr`. */ |
| 4755 | readonly stderr: Uint8Array; |
| 4756 | } |
| 4757 | |
| 4758 | /** Option which can be specified when performing {@linkcode Deno.inspect}. |
| 4759 | * |
| 4760 | * @category I/O */ |
| 4761 | export interface InspectOptions { |
| 4762 | /** Stylize output with ANSI colors. |
| 4763 | * |
| 4764 | * @default {false} */ |
| 4765 | colors?: boolean; |
| 4766 | /** Try to fit more than one entry of a collection on the same line. |
| 4767 | * |
| 4768 | * @default {true} */ |
| 4769 | compact?: boolean; |
| 4770 | /** Traversal depth for nested objects. |
| 4771 | * |
| 4772 | * @default {4} */ |
| 4773 | depth?: number; |
| 4774 | /** The maximum length for an inspection to take up a single line. |
| 4775 | * |
| 4776 | * @default {80} */ |
| 4777 | breakLength?: number; |
| 4778 | /** Whether or not to escape sequences. |
| 4779 | * |
| 4780 | * @default {true} */ |
| 4781 | escapeSequences?: boolean; |
| 4782 | /** The maximum number of iterable entries to print. |
| 4783 | * |
| 4784 | * @default {100} */ |
| 4785 | iterableLimit?: number; |
| 4786 | /** Show a Proxy's target and handler. |
| 4787 | * |
| 4788 | * @default {false} */ |
| 4789 | showProxy?: boolean; |
| 4790 | /** Sort Object, Set and Map entries by key. |
| 4791 | * |
| 4792 | * @default {false} */ |
| 4793 | sorted?: boolean; |
| 4794 | /** Add a trailing comma for multiline collections. |
| 4795 | * |
| 4796 | * @default {false} */ |
| 4797 | trailingComma?: boolean; |
| 4798 | /** Evaluate the result of calling getters. |
| 4799 | * |
| 4800 | * @default {false} */ |
| 4801 | getters?: boolean; |
| 4802 | /** Show an object's non-enumerable properties. |
| 4803 | * |
| 4804 | * @default {false} */ |
| 4805 | showHidden?: boolean; |
| 4806 | /** The maximum length of a string before it is truncated with an |
| 4807 | * ellipsis. */ |
| 4808 | strAbbreviateSize?: number; |
| 4809 | } |
| 4810 | |
| 4811 | /** Converts the input into a string that has the same format as printed by |
| 4812 | * `console.log()`. |
| 4813 | * |
| 4814 | * ```ts |
| 4815 | * const obj = { |
| 4816 | * a: 10, |
| 4817 | * b: "hello", |
| 4818 | * }; |
| 4819 | * const objAsString = Deno.inspect(obj); // { a: 10, b: "hello" } |
| 4820 | * console.log(obj); // prints same value as objAsString, e.g. { a: 10, b: "hello" } |
| 4821 | * ``` |
| 4822 | * |
| 4823 | * A custom inspect functions can be registered on objects, via the symbol |
| 4824 | * `Symbol.for("Deno.customInspect")`, to control and customize the output |
| 4825 | * of `inspect()` or when using `console` logging: |
| 4826 | * |
| 4827 | * ```ts |
| 4828 | * class A { |
| 4829 | * x = 10; |
| 4830 | * y = "hello"; |
| 4831 | * [Symbol.for("Deno.customInspect")]() { |
| 4832 | * return `x=${this.x}, y=${this.y}`; |
| 4833 | * } |
| 4834 | * } |
| 4835 | * |
| 4836 | * const inStringFormat = Deno.inspect(new A()); // "x=10, y=hello" |
| 4837 | * console.log(inStringFormat); // prints "x=10, y=hello" |
| 4838 | * ``` |
| 4839 | * |
| 4840 | * A depth can be specified by using the `depth` option: |
| 4841 | * |
| 4842 | * ```ts |
| 4843 | * Deno.inspect({a: {b: {c: {d: 'hello'}}}}, {depth: 2}); // { a: { b: [Object] } } |
| 4844 | * ``` |
| 4845 | * |
| 4846 | * @category I/O |
| 4847 | */ |
| 4848 | export function inspect(value: unknown, options?: InspectOptions): string; |
| 4849 | |
| 4850 | /** The name of a privileged feature which needs permission. |
| 4851 | * |
| 4852 | * @category Permissions |
| 4853 | */ |
| 4854 | export type PermissionName = |
| 4855 | | "run" |
| 4856 | | "read" |
| 4857 | | "write" |
| 4858 | | "net" |
| 4859 | | "env" |
| 4860 | | "sys" |
| 4861 | | "ffi" |
| 4862 | | "hrtime"; |
| 4863 | |
| 4864 | /** The current status of the permission: |
| 4865 | * |
| 4866 | * - `"granted"` - the permission has been granted. |
| 4867 | * - `"denied"` - the permission has been explicitly denied. |
| 4868 | * - `"prompt"` - the permission has not explicitly granted nor denied. |
| 4869 | * |
| 4870 | * @category Permissions |
| 4871 | */ |
| 4872 | export type PermissionState = |
| 4873 | | "granted" |
| 4874 | | "denied" |
| 4875 | | "prompt"; |
| 4876 | |
| 4877 | /** The permission descriptor for the `allow-run` and `deny-run` permissions, which controls |
| 4878 | * access to what sub-processes can be executed by Deno. The option `command` |
| 4879 | * allows scoping the permission to a specific executable. |
| 4880 | * |
| 4881 | * **Warning, in practice, `allow-run` is effectively the same as `allow-all` |
| 4882 | * in the sense that malicious code could execute any arbitrary code on the |
| 4883 | * host.** |
| 4884 | * |
| 4885 | * @category Permissions */ |
| 4886 | export interface RunPermissionDescriptor { |
| 4887 | name: "run"; |
| 4888 | /** An `allow-run` or `deny-run` permission can be scoped to a specific executable, |
| 4889 | * which would be relative to the start-up CWD of the Deno CLI. */ |
| 4890 | command?: string | URL; |
| 4891 | } |
| 4892 | |
| 4893 | /** The permission descriptor for the `allow-read` and `deny-read` permissions, which controls |
| 4894 | * access to reading resources from the local host. The option `path` allows |
| 4895 | * scoping the permission to a specific path (and if the path is a directory |
| 4896 | * any sub paths). |
| 4897 | * |
| 4898 | * Permission granted under `allow-read` only allows runtime code to attempt |
| 4899 | * to read, the underlying operating system may apply additional permissions. |
| 4900 | * |
| 4901 | * @category Permissions */ |
| 4902 | export interface ReadPermissionDescriptor { |
| 4903 | name: "read"; |
| 4904 | /** An `allow-read` or `deny-read` permission can be scoped to a specific path (and if |
| 4905 | * the path is a directory, any sub paths). */ |
| 4906 | path?: string | URL; |
| 4907 | } |
| 4908 | |
| 4909 | /** The permission descriptor for the `allow-write` and `deny-write` permissions, which |
| 4910 | * controls access to writing to resources from the local host. The option |
| 4911 | * `path` allow scoping the permission to a specific path (and if the path is |
| 4912 | * a directory any sub paths). |
| 4913 | * |
| 4914 | * Permission granted under `allow-write` only allows runtime code to attempt |
| 4915 | * to write, the underlying operating system may apply additional permissions. |
| 4916 | * |
| 4917 | * @category Permissions */ |
| 4918 | export interface WritePermissionDescriptor { |
| 4919 | name: "write"; |
| 4920 | /** An `allow-write` or `deny-write` permission can be scoped to a specific path (and if |
| 4921 | * the path is a directory, any sub paths). */ |
| 4922 | path?: string | URL; |
| 4923 | } |
| 4924 | |
| 4925 | /** The permission descriptor for the `allow-net` and `deny-net` permissions, which controls |
| 4926 | * access to opening network ports and connecting to remote hosts via the |
| 4927 | * network. The option `host` allows scoping the permission for outbound |
| 4928 | * connection to a specific host and port. |
| 4929 | * |
| 4930 | * @category Permissions */ |
| 4931 | export interface NetPermissionDescriptor { |
| 4932 | name: "net"; |
| 4933 | /** Optional host string of the form `"<hostname>[:<port>]"`. Examples: |
| 4934 | * |
| 4935 | * "github.com" |
| 4936 | * "deno.land:8080" |
| 4937 | */ |
| 4938 | host?: string; |
| 4939 | } |
| 4940 | |
| 4941 | /** The permission descriptor for the `allow-env` and `deny-env` permissions, which controls |
| 4942 | * access to being able to read and write to the process environment variables |
| 4943 | * as well as access other information about the environment. The option |
| 4944 | * `variable` allows scoping the permission to a specific environment |
| 4945 | * variable. |
| 4946 | * |
| 4947 | * @category Permissions */ |
| 4948 | export interface EnvPermissionDescriptor { |
| 4949 | name: "env"; |
| 4950 | /** Optional environment variable name (e.g. `PATH`). */ |
| 4951 | variable?: string; |
| 4952 | } |
| 4953 | |
| 4954 | /** The permission descriptor for the `allow-sys` and `deny-sys` permissions, which controls |
| 4955 | * access to sensitive host system information, which malicious code might |
| 4956 | * attempt to exploit. The option `kind` allows scoping the permission to a |
| 4957 | * specific piece of information. |
| 4958 | * |
| 4959 | * @category Permissions */ |
| 4960 | export interface SysPermissionDescriptor { |
| 4961 | name: "sys"; |
| 4962 | /** The specific information to scope the permission to. */ |
| 4963 | kind?: |
| 4964 | | "loadavg" |
| 4965 | | "hostname" |
| 4966 | | "systemMemoryInfo" |
| 4967 | | "networkInterfaces" |
| 4968 | | "osRelease" |
| 4969 | | "osUptime" |
| 4970 | | "uid" |
| 4971 | | "gid" |
| 4972 | | "username" |
| 4973 | | "cpus" |
| 4974 | | "homedir" |
| 4975 | | "statfs" |
| 4976 | | "getPriority" |
| 4977 | | "setPriority"; |
| 4978 | } |
| 4979 | |
| 4980 | /** The permission descriptor for the `allow-ffi` and `deny-ffi` permissions, which controls |
| 4981 | * access to loading _foreign_ code and interfacing with it via the |
| 4982 | * [Foreign Function Interface API](https://deno.land/manual/runtime/ffi_api) |
| 4983 | * available in Deno. The option `path` allows scoping the permission to a |
| 4984 | * specific path on the host. |
| 4985 | * |
| 4986 | * @category Permissions */ |
| 4987 | export interface FfiPermissionDescriptor { |
| 4988 | name: "ffi"; |
| 4989 | /** Optional path on the local host to scope the permission to. */ |
| 4990 | path?: string | URL; |
| 4991 | } |
| 4992 | |
| 4993 | /** The permission descriptor for the `allow-hrtime` and `deny-hrtime` permissions, which |
| 4994 | * controls if the runtime code has access to high resolution time. High |
| 4995 | * resolution time is considered sensitive information, because it can be used |
| 4996 | * by malicious code to gain information about the host that it might not |
| 4997 | * otherwise have access to. |
| 4998 | * |
| 4999 | * @category Permissions */ |
| 5000 | export interface HrtimePermissionDescriptor { |
| 5001 | name: "hrtime"; |
| 5002 | } |
| 5003 | |
| 5004 | /** Permission descriptors which define a permission and can be queried, |
| 5005 | * requested, or revoked. |
| 5006 | * |
| 5007 | * View the specifics of the individual descriptors for more information about |
| 5008 | * each permission kind. |
| 5009 | * |
| 5010 | * @category Permissions |
| 5011 | */ |
| 5012 | export type PermissionDescriptor = |
| 5013 | | RunPermissionDescriptor |
| 5014 | | ReadPermissionDescriptor |
| 5015 | | WritePermissionDescriptor |
| 5016 | | NetPermissionDescriptor |
| 5017 | | EnvPermissionDescriptor |
| 5018 | | SysPermissionDescriptor |
| 5019 | | FfiPermissionDescriptor |
| 5020 | | HrtimePermissionDescriptor; |
| 5021 | |
| 5022 | /** The interface which defines what event types are supported by |
| 5023 | * {@linkcode PermissionStatus} instances. |
| 5024 | * |
| 5025 | * @category Permissions */ |
| 5026 | export interface PermissionStatusEventMap { |
| 5027 | "change": Event; |
| 5028 | } |
| 5029 | |
| 5030 | /** An {@linkcode EventTarget} returned from the {@linkcode Deno.permissions} |
| 5031 | * API which can provide updates to any state changes of the permission. |
| 5032 | * |
| 5033 | * @category Permissions */ |
| 5034 | export class PermissionStatus extends EventTarget { |
| 5035 | // deno-lint-ignore no-explicit-any |
| 5036 | onchange: ((this: PermissionStatus, ev: Event) => any) | null; |
| 5037 | readonly state: PermissionState; |
| 5038 | /** |
| 5039 | * Describes if permission is only granted partially, eg. an access |
| 5040 | * might be granted to "/foo" directory, but denied for "/foo/bar". |
| 5041 | * In such case this field will be set to `true` when querying for |
| 5042 | * read permissions of "/foo" directory. |
| 5043 | */ |
| 5044 | readonly partial: boolean; |
| 5045 | addEventListener<K extends keyof PermissionStatusEventMap>( |
| 5046 | type: K, |
| 5047 | listener: ( |
| 5048 | this: PermissionStatus, |
| 5049 | ev: PermissionStatusEventMap[K], |
| 5050 | ) => any, |
| 5051 | options?: boolean | AddEventListenerOptions, |
| 5052 | ): void; |
| 5053 | addEventListener( |
| 5054 | type: string, |
| 5055 | listener: EventListenerOrEventListenerObject, |
| 5056 | options?: boolean | AddEventListenerOptions, |
| 5057 | ): void; |
| 5058 | removeEventListener<K extends keyof PermissionStatusEventMap>( |
| 5059 | type: K, |
| 5060 | listener: ( |
| 5061 | this: PermissionStatus, |
| 5062 | ev: PermissionStatusEventMap[K], |
| 5063 | ) => any, |
| 5064 | options?: boolean | EventListenerOptions, |
| 5065 | ): void; |
| 5066 | removeEventListener( |
| 5067 | type: string, |
| 5068 | listener: EventListenerOrEventListenerObject, |
| 5069 | options?: boolean | EventListenerOptions, |
| 5070 | ): void; |
| 5071 | } |
| 5072 | |
| 5073 | /** |
| 5074 | * Deno's permission management API. |
| 5075 | * |
| 5076 | * The class which provides the interface for the {@linkcode Deno.permissions} |
| 5077 | * global instance and is based on the web platform |
| 5078 | * [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API), |
| 5079 | * though some proposed parts of the API which are useful in a server side |
| 5080 | * runtime context were removed or abandoned in the web platform specification |
| 5081 | * which is why it was chosen to locate it in the {@linkcode Deno} namespace |
| 5082 | * instead. |
| 5083 | * |
| 5084 | * By default, if the `stdin`/`stdout` is TTY for the Deno CLI (meaning it can |
| 5085 | * send and receive text), then the CLI will prompt the user to grant |
| 5086 | * permission when an un-granted permission is requested. This behavior can |
| 5087 | * be changed by using the `--no-prompt` command at startup. When prompting |
| 5088 | * the CLI will request the narrowest permission possible, potentially making |
| 5089 | * it annoying to the user. The permissions APIs allow the code author to |
| 5090 | * request a wider set of permissions at one time in order to provide a better |
| 5091 | * user experience. |
| 5092 | * |
| 5093 | * @category Permissions */ |
| 5094 | export class Permissions { |
| 5095 | /** Resolves to the current status of a permission. |
| 5096 | * |
| 5097 | * Note, if the permission is already granted, `request()` will not prompt |
| 5098 | * the user again, therefore `query()` is only necessary if you are going |
| 5099 | * to react differently existing permissions without wanting to modify them |
| 5100 | * or prompt the user to modify them. |
| 5101 | * |
| 5102 | * ```ts |
| 5103 | * const status = await Deno.permissions.query({ name: "read", path: "/etc" }); |
| 5104 | * console.log(status.state); |
| 5105 | * ``` |
| 5106 | */ |
| 5107 | query(desc: PermissionDescriptor): Promise<PermissionStatus>; |
| 5108 | |
| 5109 | /** Returns the current status of a permission. |
| 5110 | * |
| 5111 | * Note, if the permission is already granted, `request()` will not prompt |
| 5112 | * the user again, therefore `querySync()` is only necessary if you are going |
| 5113 | * to react differently existing permissions without wanting to modify them |
| 5114 | * or prompt the user to modify them. |
| 5115 | * |
| 5116 | * ```ts |
| 5117 | * const status = Deno.permissions.querySync({ name: "read", path: "/etc" }); |
| 5118 | * console.log(status.state); |
| 5119 | * ``` |
| 5120 | */ |
| 5121 | querySync(desc: PermissionDescriptor): PermissionStatus; |
| 5122 | |
| 5123 | /** Revokes a permission, and resolves to the state of the permission. |
| 5124 | * |
| 5125 | * ```ts |
| 5126 | * import { assert } from "jsr:@std/assert"; |
| 5127 | * |
| 5128 | * const status = await Deno.permissions.revoke({ name: "run" }); |
| 5129 | * assert(status.state !== "granted") |
| 5130 | * ``` |
| 5131 | */ |
| 5132 | revoke(desc: PermissionDescriptor): Promise<PermissionStatus>; |
| 5133 | |
| 5134 | /** Revokes a permission, and returns the state of the permission. |
| 5135 | * |
| 5136 | * ```ts |
| 5137 | * import { assert } from "jsr:@std/assert"; |
| 5138 | * |
| 5139 | * const status = Deno.permissions.revokeSync({ name: "run" }); |
| 5140 | * assert(status.state !== "granted") |
| 5141 | * ``` |
| 5142 | */ |
| 5143 | revokeSync(desc: PermissionDescriptor): PermissionStatus; |
| 5144 | |
| 5145 | /** Requests the permission, and resolves to the state of the permission. |
| 5146 | * |
| 5147 | * If the permission is already granted, the user will not be prompted to |
| 5148 | * grant the permission again. |
| 5149 | * |
| 5150 | * ```ts |
| 5151 | * const status = await Deno.permissions.request({ name: "env" }); |
| 5152 | * if (status.state === "granted") { |
| 5153 | * console.log("'env' permission is granted."); |
| 5154 | * } else { |
| 5155 | * console.log("'env' permission is denied."); |
| 5156 | * } |
| 5157 | * ``` |
| 5158 | */ |
| 5159 | request(desc: PermissionDescriptor): Promise<PermissionStatus>; |
| 5160 | |
| 5161 | /** Requests the permission, and returns the state of the permission. |
| 5162 | * |
| 5163 | * If the permission is already granted, the user will not be prompted to |
| 5164 | * grant the permission again. |
| 5165 | * |
| 5166 | * ```ts |
| 5167 | * const status = Deno.permissions.requestSync({ name: "env" }); |
| 5168 | * if (status.state === "granted") { |
| 5169 | * console.log("'env' permission is granted."); |
| 5170 | * } else { |
| 5171 | * console.log("'env' permission is denied."); |
| 5172 | * } |
| 5173 | * ``` |
| 5174 | */ |
| 5175 | requestSync(desc: PermissionDescriptor): PermissionStatus; |
| 5176 | } |
| 5177 | |
| 5178 | /** Deno's permission management API. |
| 5179 | * |
| 5180 | * It is a singleton instance of the {@linkcode Permissions} object and is |
| 5181 | * based on the web platform |
| 5182 | * [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API), |
| 5183 | * though some proposed parts of the API which are useful in a server side |
| 5184 | * runtime context were removed or abandoned in the web platform specification |
| 5185 | * which is why it was chosen to locate it in the {@linkcode Deno} namespace |
| 5186 | * instead. |
| 5187 | * |
| 5188 | * By default, if the `stdin`/`stdout` is TTY for the Deno CLI (meaning it can |
| 5189 | * send and receive text), then the CLI will prompt the user to grant |
| 5190 | * permission when an un-granted permission is requested. This behavior can |
| 5191 | * be changed by using the `--no-prompt` command at startup. When prompting |
| 5192 | * the CLI will request the narrowest permission possible, potentially making |
| 5193 | * it annoying to the user. The permissions APIs allow the code author to |
| 5194 | * request a wider set of permissions at one time in order to provide a better |
| 5195 | * user experience. |
| 5196 | * |
| 5197 | * Requesting already granted permissions will not prompt the user and will |
| 5198 | * return that the permission was granted. |
| 5199 | * |
| 5200 | * ### Querying |
| 5201 | * |
| 5202 | * ```ts |
| 5203 | * const status = await Deno.permissions.query({ name: "read", path: "/etc" }); |
| 5204 | * console.log(status.state); |
| 5205 | * ``` |
| 5206 | * |
| 5207 | * ```ts |
| 5208 | * const status = Deno.permissions.querySync({ name: "read", path: "/etc" }); |
| 5209 | * console.log(status.state); |
| 5210 | * ``` |
| 5211 | * |
| 5212 | * ### Revoking |
| 5213 | * |
| 5214 | * ```ts |
| 5215 | * import { assert } from "jsr:@std/assert"; |
| 5216 | * |
| 5217 | * const status = await Deno.permissions.revoke({ name: "run" }); |
| 5218 | * assert(status.state !== "granted") |
| 5219 | * ``` |
| 5220 | * |
| 5221 | * ```ts |
| 5222 | * import { assert } from "jsr:@std/assert"; |
| 5223 | * |
| 5224 | * const status = Deno.permissions.revokeSync({ name: "run" }); |
| 5225 | * assert(status.state !== "granted") |
| 5226 | * ``` |
| 5227 | * |
| 5228 | * ### Requesting |
| 5229 | * |
| 5230 | * ```ts |
| 5231 | * const status = await Deno.permissions.request({ name: "env" }); |
| 5232 | * if (status.state === "granted") { |
| 5233 | * console.log("'env' permission is granted."); |
| 5234 | * } else { |
| 5235 | * console.log("'env' permission is denied."); |
| 5236 | * } |
| 5237 | * ``` |
| 5238 | * |
| 5239 | * ```ts |
| 5240 | * const status = Deno.permissions.requestSync({ name: "env" }); |
| 5241 | * if (status.state === "granted") { |
| 5242 | * console.log("'env' permission is granted."); |
| 5243 | * } else { |
| 5244 | * console.log("'env' permission is denied."); |
| 5245 | * } |
| 5246 | * ``` |
| 5247 | * |
| 5248 | * @category Permissions |
| 5249 | */ |
| 5250 | export const permissions: Permissions; |
| 5251 | |
| 5252 | /** Information related to the build of the current Deno runtime. |
| 5253 | * |
| 5254 | * Users are discouraged from code branching based on this information, as |
| 5255 | * assumptions about what is available in what build environment might change |
| 5256 | * over time. Developers should specifically sniff out the features they |
| 5257 | * intend to use. |
| 5258 | * |
| 5259 | * The intended use for the information is for logging and debugging purposes. |
| 5260 | * |
| 5261 | * @category Runtime |
| 5262 | */ |
| 5263 | export const build: { |
| 5264 | /** The [LLVM](https://llvm.org/) target triple, which is the combination |
| 5265 | * of `${arch}-${vendor}-${os}` and represent the specific build target that |
| 5266 | * the current runtime was built for. */ |
| 5267 | target: string; |
| 5268 | /** Instruction set architecture that the Deno CLI was built for. */ |
| 5269 | arch: "x86_64" | "aarch64"; |
| 5270 | /** The operating system that the Deno CLI was built for. `"darwin"` is |
| 5271 | * also known as OSX or MacOS. */ |
| 5272 | os: |
| 5273 | | "darwin" |
| 5274 | | "linux" |
| 5275 | | "android" |
| 5276 | | "windows" |
| 5277 | | "freebsd" |
| 5278 | | "netbsd" |
| 5279 | | "aix" |
| 5280 | | "solaris" |
| 5281 | | "illumos"; |
| 5282 | /** The computer vendor that the Deno CLI was built for. */ |
| 5283 | vendor: string; |
| 5284 | /** Optional environment flags that were set for this build of Deno CLI. */ |
| 5285 | env?: string; |
| 5286 | }; |
| 5287 | |
| 5288 | /** Version information related to the current Deno CLI runtime environment. |
| 5289 | * |
| 5290 | * Users are discouraged from code branching based on this information, as |
| 5291 | * assumptions about what is available in what build environment might change |
| 5292 | * over time. Developers should specifically sniff out the features they |
| 5293 | * intend to use. |
| 5294 | * |
| 5295 | * The intended use for the information is for logging and debugging purposes. |
| 5296 | * |
| 5297 | * @category Runtime |
| 5298 | */ |
| 5299 | export const version: { |
| 5300 | /** Deno CLI's version. For example: `"1.26.0"`. */ |
| 5301 | deno: string; |
| 5302 | /** The V8 version used by Deno. For example: `"10.7.100.0"`. |
| 5303 | * |
| 5304 | * V8 is the underlying JavaScript runtime platform that Deno is built on |
| 5305 | * top of. */ |
| 5306 | v8: string; |
| 5307 | /** The TypeScript version used by Deno. For example: `"4.8.3"`. |
| 5308 | * |
| 5309 | * A version of the TypeScript type checker and language server is built-in |
| 5310 | * to the Deno CLI. */ |
| 5311 | typescript: string; |
| 5312 | }; |
| 5313 | |
| 5314 | /** Returns the script arguments to the program. |
| 5315 | * |
| 5316 | * Give the following command line invocation of Deno: |
| 5317 | * |
| 5318 | * ```sh |
| 5319 | * deno run --allow-read https://examples.deno.land/command-line-arguments.ts Sushi |
| 5320 | * ``` |
| 5321 | * |
| 5322 | * Then `Deno.args` will contain: |
| 5323 | * |
| 5324 | * ```ts |
| 5325 | * [ "Sushi" ] |
| 5326 | * ``` |
| 5327 | * |
| 5328 | * If you are looking for a structured way to parse arguments, there is |
| 5329 | * [`parseArgs()`](https://jsr.io/@std/cli/doc/parse-args/~/parseArgs) from |
| 5330 | * the Deno Standard Library. |
| 5331 | * |
| 5332 | * @category Runtime |
| 5333 | */ |
| 5334 | export const args: string[]; |
| 5335 | |
| 5336 | /** |
| 5337 | * A symbol which can be used as a key for a custom method which will be |
| 5338 | * called when `Deno.inspect()` is called, or when the object is logged to |
| 5339 | * the console. |
| 5340 | * |
| 5341 | * @deprecated This will be removed in Deno 2.0. See the |
| 5342 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5343 | * for migration instructions. |
| 5344 | * |
| 5345 | * @category I/O |
| 5346 | */ |
| 5347 | export const customInspect: unique symbol; |
| 5348 | |
| 5349 | /** The URL of the entrypoint module entered from the command-line. It |
| 5350 | * requires read permission to the CWD. |
| 5351 | * |
| 5352 | * Also see {@linkcode ImportMeta} for other related information. |
| 5353 | * |
| 5354 | * @tags allow-read |
| 5355 | * @category Runtime |
| 5356 | */ |
| 5357 | export const mainModule: string; |
| 5358 | |
| 5359 | /** Options that can be used with {@linkcode symlink} and |
| 5360 | * {@linkcode symlinkSync}. |
| 5361 | * |
| 5362 | * @category File System */ |
| 5363 | export interface SymlinkOptions { |
| 5364 | /** Specify the symbolic link type as file, directory or NTFS junction. This |
| 5365 | * option only applies to Windows and is ignored on other operating systems. */ |
| 5366 | type: "file" | "dir" | "junction"; |
| 5367 | } |
| 5368 | |
| 5369 | /** |
| 5370 | * Creates `newpath` as a symbolic link to `oldpath`. |
| 5371 | * |
| 5372 | * The `options.type` parameter can be set to `"file"`, `"dir"` or `"junction"`. |
| 5373 | * This argument is only available on Windows and ignored on other platforms. |
| 5374 | * |
| 5375 | * ```ts |
| 5376 | * await Deno.symlink("old/name", "new/name"); |
| 5377 | * ``` |
| 5378 | * |
| 5379 | * Requires full `allow-read` and `allow-write` permissions. |
| 5380 | * |
| 5381 | * @tags allow-read, allow-write |
| 5382 | * @category File System |
| 5383 | */ |
| 5384 | export function symlink( |
| 5385 | oldpath: string | URL, |
| 5386 | newpath: string | URL, |
| 5387 | options?: SymlinkOptions, |
| 5388 | ): Promise<void>; |
| 5389 | |
| 5390 | /** |
| 5391 | * Creates `newpath` as a symbolic link to `oldpath`. |
| 5392 | * |
| 5393 | * The `options.type` parameter can be set to `"file"`, `"dir"` or `"junction"`. |
| 5394 | * This argument is only available on Windows and ignored on other platforms. |
| 5395 | * |
| 5396 | * ```ts |
| 5397 | * Deno.symlinkSync("old/name", "new/name"); |
| 5398 | * ``` |
| 5399 | * |
| 5400 | * Requires full `allow-read` and `allow-write` permissions. |
| 5401 | * |
| 5402 | * @tags allow-read, allow-write |
| 5403 | * @category File System |
| 5404 | */ |
| 5405 | export function symlinkSync( |
| 5406 | oldpath: string | URL, |
| 5407 | newpath: string | URL, |
| 5408 | options?: SymlinkOptions, |
| 5409 | ): void; |
| 5410 | |
| 5411 | /** |
| 5412 | * Truncates or extends the specified file stream, to reach the specified |
| 5413 | * `len`. |
| 5414 | * |
| 5415 | * If `len` is not specified then the entire file contents are truncated as if |
| 5416 | * `len` was set to `0`. |
| 5417 | * |
| 5418 | * If the file previously was larger than this new length, the extra data is |
| 5419 | * lost. |
| 5420 | * |
| 5421 | * If the file previously was shorter, it is extended, and the extended part |
| 5422 | * reads as null bytes ('\0'). |
| 5423 | * |
| 5424 | * ### Truncate the entire file |
| 5425 | * |
| 5426 | * ```ts |
| 5427 | * const file = await Deno.open( |
| 5428 | * "my_file.txt", |
| 5429 | * { read: true, write: true, create: true } |
| 5430 | * ); |
| 5431 | * await Deno.ftruncate(file.rid); |
| 5432 | * ``` |
| 5433 | * |
| 5434 | * ### Truncate part of the file |
| 5435 | * |
| 5436 | * ```ts |
| 5437 | * const file = await Deno.open( |
| 5438 | * "my_file.txt", |
| 5439 | * { read: true, write: true, create: true } |
| 5440 | * ); |
| 5441 | * await file.write(new TextEncoder().encode("Hello World")); |
| 5442 | * await Deno.ftruncate(file.rid, 7); |
| 5443 | * const data = new Uint8Array(32); |
| 5444 | * await Deno.read(file.rid, data); |
| 5445 | * console.log(new TextDecoder().decode(data)); // Hello W |
| 5446 | * ``` |
| 5447 | * |
| 5448 | * @deprecated This will be removed in Deno 2.0. See the |
| 5449 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5450 | * for migration instructions. |
| 5451 | * |
| 5452 | * @category File System |
| 5453 | */ |
| 5454 | export function ftruncate(rid: number, len?: number): Promise<void>; |
| 5455 | |
| 5456 | /** |
| 5457 | * Synchronously truncates or extends the specified file stream, to reach the |
| 5458 | * specified `len`. |
| 5459 | * |
| 5460 | * If `len` is not specified then the entire file contents are truncated as if |
| 5461 | * `len` was set to `0`. |
| 5462 | * |
| 5463 | * If the file previously was larger than this new length, the extra data is |
| 5464 | * lost. |
| 5465 | * |
| 5466 | * If the file previously was shorter, it is extended, and the extended part |
| 5467 | * reads as null bytes ('\0'). |
| 5468 | * |
| 5469 | * ### Truncate the entire file |
| 5470 | * |
| 5471 | * ```ts |
| 5472 | * const file = Deno.openSync( |
| 5473 | * "my_file.txt", |
| 5474 | * { read: true, write: true, truncate: true, create: true } |
| 5475 | * ); |
| 5476 | * Deno.ftruncateSync(file.rid); |
| 5477 | * ``` |
| 5478 | * |
| 5479 | * ### Truncate part of the file |
| 5480 | * |
| 5481 | * ```ts |
| 5482 | * const file = Deno.openSync( |
| 5483 | * "my_file.txt", |
| 5484 | * { read: true, write: true, create: true } |
| 5485 | * ); |
| 5486 | * file.writeSync(new TextEncoder().encode("Hello World")); |
| 5487 | * Deno.ftruncateSync(file.rid, 7); |
| 5488 | * Deno.seekSync(file.rid, 0, Deno.SeekMode.Start); |
| 5489 | * const data = new Uint8Array(32); |
| 5490 | * Deno.readSync(file.rid, data); |
| 5491 | * console.log(new TextDecoder().decode(data)); // Hello W |
| 5492 | * ``` |
| 5493 | * |
| 5494 | * @deprecated This will be removed in Deno 2.0. See the |
| 5495 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5496 | * for migration instructions. |
| 5497 | * |
| 5498 | * @category File System |
| 5499 | */ |
| 5500 | export function ftruncateSync(rid: number, len?: number): void; |
| 5501 | |
| 5502 | /** |
| 5503 | * Synchronously changes the access (`atime`) and modification (`mtime`) times |
| 5504 | * of a file stream resource referenced by `rid`. Given times are either in |
| 5505 | * seconds (UNIX epoch time) or as `Date` objects. |
| 5506 | * |
| 5507 | * ```ts |
| 5508 | * const file = Deno.openSync("file.txt", { create: true, write: true }); |
| 5509 | * Deno.futimeSync(file.rid, 1556495550, new Date()); |
| 5510 | * ``` |
| 5511 | * |
| 5512 | * @deprecated This will be removed in Deno 2.0. See the |
| 5513 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5514 | * for migration instructions. |
| 5515 | * |
| 5516 | * @category File System |
| 5517 | */ |
| 5518 | export function futimeSync( |
| 5519 | rid: number, |
| 5520 | atime: number | Date, |
| 5521 | mtime: number | Date, |
| 5522 | ): void; |
| 5523 | |
| 5524 | /** |
| 5525 | * Changes the access (`atime`) and modification (`mtime`) times of a file |
| 5526 | * stream resource referenced by `rid`. Given times are either in seconds |
| 5527 | * (UNIX epoch time) or as `Date` objects. |
| 5528 | * |
| 5529 | * ```ts |
| 5530 | * const file = await Deno.open("file.txt", { create: true, write: true }); |
| 5531 | * await Deno.futime(file.rid, 1556495550, new Date()); |
| 5532 | * ``` |
| 5533 | * |
| 5534 | * @deprecated This will be removed in Deno 2.0. See the |
| 5535 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5536 | * for migration instructions. |
| 5537 | * |
| 5538 | * @category File System |
| 5539 | */ |
| 5540 | export function futime( |
| 5541 | rid: number, |
| 5542 | atime: number | Date, |
| 5543 | mtime: number | Date, |
| 5544 | ): Promise<void>; |
| 5545 | |
| 5546 | /** |
| 5547 | * Returns a `Deno.FileInfo` for the given file stream. |
| 5548 | * |
| 5549 | * ```ts |
| 5550 | * import { assert } from "jsr:@std/assert"; |
| 5551 | * |
| 5552 | * const file = await Deno.open("file.txt", { read: true }); |
| 5553 | * const fileInfo = await Deno.fstat(file.rid); |
| 5554 | * assert(fileInfo.isFile); |
| 5555 | * ``` |
| 5556 | * |
| 5557 | * @deprecated This will be removed in Deno 2.0. See the |
| 5558 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5559 | * for migration instructions. |
| 5560 | * |
| 5561 | * @category File System |
| 5562 | */ |
| 5563 | export function fstat(rid: number): Promise<FileInfo>; |
| 5564 | |
| 5565 | /** |
| 5566 | * Synchronously returns a {@linkcode Deno.FileInfo} for the given file |
| 5567 | * stream. |
| 5568 | * |
| 5569 | * ```ts |
| 5570 | * import { assert } from "jsr:@std/assert"; |
| 5571 | * |
| 5572 | * const file = Deno.openSync("file.txt", { read: true }); |
| 5573 | * const fileInfo = Deno.fstatSync(file.rid); |
| 5574 | * assert(fileInfo.isFile); |
| 5575 | * ``` |
| 5576 | * |
| 5577 | * @deprecated This will be removed in Deno 2.0. See the |
| 5578 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5579 | * for migration instructions. |
| 5580 | * |
| 5581 | * @category File System |
| 5582 | */ |
| 5583 | export function fstatSync(rid: number): FileInfo; |
| 5584 | |
| 5585 | /** |
| 5586 | * Synchronously changes the access (`atime`) and modification (`mtime`) times |
| 5587 | * of a file system object referenced by `path`. Given times are either in |
| 5588 | * seconds (UNIX epoch time) or as `Date` objects. |
| 5589 | * |
| 5590 | * ```ts |
| 5591 | * Deno.utimeSync("myfile.txt", 1556495550, new Date()); |
| 5592 | * ``` |
| 5593 | * |
| 5594 | * Requires `allow-write` permission. |
| 5595 | * |
| 5596 | * @tags allow-write |
| 5597 | * @category File System |
| 5598 | */ |
| 5599 | export function utimeSync( |
| 5600 | path: string | URL, |
| 5601 | atime: number | Date, |
| 5602 | mtime: number | Date, |
| 5603 | ): void; |
| 5604 | |
| 5605 | /** |
| 5606 | * Changes the access (`atime`) and modification (`mtime`) times of a file |
| 5607 | * system object referenced by `path`. Given times are either in seconds |
| 5608 | * (UNIX epoch time) or as `Date` objects. |
| 5609 | * |
| 5610 | * ```ts |
| 5611 | * await Deno.utime("myfile.txt", 1556495550, new Date()); |
| 5612 | * ``` |
| 5613 | * |
| 5614 | * Requires `allow-write` permission. |
| 5615 | * |
| 5616 | * @tags allow-write |
| 5617 | * @category File System |
| 5618 | */ |
| 5619 | export function utime( |
| 5620 | path: string | URL, |
| 5621 | atime: number | Date, |
| 5622 | mtime: number | Date, |
| 5623 | ): Promise<void>; |
| 5624 | |
| 5625 | /** The event yielded from an {@linkcode HttpConn} which represents an HTTP |
| 5626 | * request from a remote client. |
| 5627 | * |
| 5628 | * @category HTTP Server |
| 5629 | * |
| 5630 | * @deprecated This will be removed in Deno 2.0. See the |
| 5631 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5632 | * for migration instructions. |
| 5633 | */ |
| 5634 | export interface RequestEvent { |
| 5635 | /** The request from the client in the form of the web platform |
| 5636 | * {@linkcode Request}. */ |
| 5637 | readonly request: Request; |
| 5638 | /** The method to be used to respond to the event. The response needs to |
| 5639 | * either be an instance of {@linkcode Response} or a promise that resolves |
| 5640 | * with an instance of `Response`. |
| 5641 | * |
| 5642 | * When the response is successfully processed then the promise returned |
| 5643 | * will be resolved. If there are any issues with sending the response, |
| 5644 | * the promise will be rejected. */ |
| 5645 | respondWith(r: Response | PromiseLike<Response>): Promise<void>; |
| 5646 | } |
| 5647 | |
| 5648 | /** |
| 5649 | * The async iterable that is returned from {@linkcode serveHttp} which |
| 5650 | * yields up {@linkcode RequestEvent} events, representing individual |
| 5651 | * requests on the HTTP server connection. |
| 5652 | * |
| 5653 | * @category HTTP Server |
| 5654 | * |
| 5655 | * @deprecated This will be removed in Deno 2.0. See the |
| 5656 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5657 | * for migration instructions. |
| 5658 | */ |
| 5659 | export interface HttpConn extends AsyncIterable<RequestEvent>, Disposable { |
| 5660 | /** The resource ID associated with this connection. Generally users do not |
| 5661 | * need to be aware of this identifier. */ |
| 5662 | readonly rid: number; |
| 5663 | |
| 5664 | /** An alternative to the async iterable interface which provides promises |
| 5665 | * which resolve with either a {@linkcode RequestEvent} when there is |
| 5666 | * another request or `null` when the client has closed the connection. */ |
| 5667 | nextRequest(): Promise<RequestEvent | null>; |
| 5668 | /** Initiate a server side closure of the connection, indicating to the |
| 5669 | * client that you refuse to accept any more requests on this connection. |
| 5670 | * |
| 5671 | * Typically the client closes the connection, which will result in the |
| 5672 | * async iterable terminating or the `nextRequest()` method returning |
| 5673 | * `null`. */ |
| 5674 | close(): void; |
| 5675 | } |
| 5676 | |
| 5677 | /** |
| 5678 | * Provides an interface to handle HTTP request and responses over TCP or TLS |
| 5679 | * connections. The method returns an {@linkcode HttpConn} which yields up |
| 5680 | * {@linkcode RequestEvent} events, which utilize the web platform standard |
| 5681 | * {@linkcode Request} and {@linkcode Response} objects to handle the request. |
| 5682 | * |
| 5683 | * ```ts |
| 5684 | * const conn = Deno.listen({ port: 80 }); |
| 5685 | * const httpConn = Deno.serveHttp(await conn.accept()); |
| 5686 | * const e = await httpConn.nextRequest(); |
| 5687 | * if (e) { |
| 5688 | * e.respondWith(new Response("Hello World")); |
| 5689 | * } |
| 5690 | * ``` |
| 5691 | * |
| 5692 | * Alternatively, you can also use the async iterator approach: |
| 5693 | * |
| 5694 | * ```ts |
| 5695 | * async function handleHttp(conn: Deno.Conn) { |
| 5696 | * for await (const e of Deno.serveHttp(conn)) { |
| 5697 | * e.respondWith(new Response("Hello World")); |
| 5698 | * } |
| 5699 | * } |
| 5700 | * |
| 5701 | * for await (const conn of Deno.listen({ port: 80 })) { |
| 5702 | * handleHttp(conn); |
| 5703 | * } |
| 5704 | * ``` |
| 5705 | * |
| 5706 | * If `httpConn.nextRequest()` encounters an error or returns `null` then the |
| 5707 | * underlying {@linkcode HttpConn} resource is closed automatically. |
| 5708 | * |
| 5709 | * Also see the experimental Flash HTTP server {@linkcode Deno.serve} which |
| 5710 | * provides a ground up rewrite of handling of HTTP requests and responses |
| 5711 | * within the Deno CLI. |
| 5712 | * |
| 5713 | * Note that this function *consumes* the given connection passed to it, thus |
| 5714 | * the original connection will be unusable after calling this. Additionally, |
| 5715 | * you need to ensure that the connection is not being used elsewhere when |
| 5716 | * calling this function in order for the connection to be consumed properly. |
| 5717 | * |
| 5718 | * For instance, if there is a `Promise` that is waiting for read operation on |
| 5719 | * the connection to complete, it is considered that the connection is being |
| 5720 | * used elsewhere. In such a case, this function will fail. |
| 5721 | * |
| 5722 | * @category HTTP Server |
| 5723 | * @deprecated This will be soft-removed in Deno 2.0. See the |
| 5724 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 5725 | * for migration instructions. |
| 5726 | */ |
| 5727 | export function serveHttp(conn: Conn): HttpConn; |
| 5728 | |
| 5729 | /** The object that is returned from a {@linkcode Deno.upgradeWebSocket} |
| 5730 | * request. |
| 5731 | * |
| 5732 | * @category Web Sockets */ |
| 5733 | export interface WebSocketUpgrade { |
| 5734 | /** The response object that represents the HTTP response to the client, |
| 5735 | * which should be used to the {@linkcode RequestEvent} `.respondWith()` for |
| 5736 | * the upgrade to be successful. */ |
| 5737 | response: Response; |
| 5738 | /** The {@linkcode WebSocket} interface to communicate to the client via a |
| 5739 | * web socket. */ |
| 5740 | socket: WebSocket; |
| 5741 | } |
| 5742 | |
| 5743 | /** Options which can be set when performing a |
| 5744 | * {@linkcode Deno.upgradeWebSocket} upgrade of a {@linkcode Request} |
| 5745 | * |
| 5746 | * @category Web Sockets */ |
| 5747 | export interface UpgradeWebSocketOptions { |
| 5748 | /** Sets the `.protocol` property on the client side web socket to the |
| 5749 | * value provided here, which should be one of the strings specified in the |
| 5750 | * `protocols` parameter when requesting the web socket. This is intended |
| 5751 | * for clients and servers to specify sub-protocols to use to communicate to |
| 5752 | * each other. */ |
| 5753 | protocol?: string; |
| 5754 | /** If the client does not respond to this frame with a |
| 5755 | * `pong` within the timeout specified, the connection is deemed |
| 5756 | * unhealthy and is closed. The `close` and `error` event will be emitted. |
| 5757 | * |
| 5758 | * The unit is seconds, with a default of 30. |
| 5759 | * Set to `0` to disable timeouts. */ |
| 5760 | idleTimeout?: number; |
| 5761 | } |
| 5762 | |
| 5763 | /** |
| 5764 | * Upgrade an incoming HTTP request to a WebSocket. |
| 5765 | * |
| 5766 | * Given a {@linkcode Request}, returns a pair of {@linkcode WebSocket} and |
| 5767 | * {@linkcode Response} instances. The original request must be responded to |
| 5768 | * with the returned response for the websocket upgrade to be successful. |
| 5769 | * |
| 5770 | * ```ts |
| 5771 | * const conn = Deno.listen({ port: 80 }); |
| 5772 | * const httpConn = Deno.serveHttp(await conn.accept()); |
| 5773 | * const e = await httpConn.nextRequest(); |
| 5774 | * if (e) { |
| 5775 | * const { socket, response } = Deno.upgradeWebSocket(e.request); |
| 5776 | * socket.onopen = () => { |
| 5777 | * socket.send("Hello World!"); |
| 5778 | * }; |
| 5779 | * socket.onmessage = (e) => { |
| 5780 | * console.log(e.data); |
| 5781 | * socket.close(); |
| 5782 | * }; |
| 5783 | * socket.onclose = () => console.log("WebSocket has been closed."); |
| 5784 | * socket.onerror = (e) => console.error("WebSocket error:", e); |
| 5785 | * e.respondWith(response); |
| 5786 | * } |
| 5787 | * ``` |
| 5788 | * |
| 5789 | * If the request body is disturbed (read from) before the upgrade is |
| 5790 | * completed, upgrading fails. |
| 5791 | * |
| 5792 | * This operation does not yet consume the request or open the websocket. This |
| 5793 | * only happens once the returned response has been passed to `respondWith()`. |
| 5794 | * |
| 5795 | * @category Web Sockets |
| 5796 | */ |
| 5797 | export function upgradeWebSocket( |
| 5798 | request: Request, |
| 5799 | options?: UpgradeWebSocketOptions, |
| 5800 | ): WebSocketUpgrade; |
| 5801 | |
| 5802 | /** Send a signal to process under given `pid`. The value and meaning of the |
| 5803 | * `signal` to the process is operating system and process dependant. |
| 5804 | * {@linkcode Signal} provides the most common signals. Default signal |
| 5805 | * is `"SIGTERM"`. |
| 5806 | * |
| 5807 | * The term `kill` is adopted from the UNIX-like command line command `kill` |
| 5808 | * which also signals processes. |
| 5809 | * |
| 5810 | * If `pid` is negative, the signal will be sent to the process group |
| 5811 | * identified by `pid`. An error will be thrown if a negative `pid` is used on |
| 5812 | * Windows. |
| 5813 | * |
| 5814 | * ```ts |
| 5815 | * const p = Deno.run({ |
| 5816 | * cmd: ["sleep", "10000"] |
| 5817 | * }); |
| 5818 | * |
| 5819 | * Deno.kill(p.pid, "SIGINT"); |
| 5820 | * ``` |
| 5821 | * |
| 5822 | * Requires `allow-run` permission. |
| 5823 | * |
| 5824 | * @tags allow-run |
| 5825 | * @category Sub Process |
| 5826 | */ |
| 5827 | export function kill(pid: number, signo?: Signal): void; |
| 5828 | |
| 5829 | /** The type of the resource record to resolve via DNS using |
| 5830 | * {@linkcode Deno.resolveDns}. |
| 5831 | * |
| 5832 | * Only the listed types are supported currently. |
| 5833 | * |
| 5834 | * @category Network |
| 5835 | */ |
| 5836 | export type RecordType = |
| 5837 | | "A" |
| 5838 | | "AAAA" |
| 5839 | | "ANAME" |
| 5840 | | "CAA" |
| 5841 | | "CNAME" |
| 5842 | | "MX" |
| 5843 | | "NAPTR" |
| 5844 | | "NS" |
| 5845 | | "PTR" |
| 5846 | | "SOA" |
| 5847 | | "SRV" |
| 5848 | | "TXT"; |
| 5849 | |
| 5850 | /** |
| 5851 | * Options which can be set when using {@linkcode Deno.resolveDns}. |
| 5852 | * |
| 5853 | * @category Network */ |
| 5854 | export interface ResolveDnsOptions { |
| 5855 | /** The name server to be used for lookups. |
| 5856 | * |
| 5857 | * If not specified, defaults to the system configuration. For example |
| 5858 | * `/etc/resolv.conf` on Unix-like systems. */ |
| 5859 | nameServer?: { |
| 5860 | /** The IP address of the name server. */ |
| 5861 | ipAddr: string; |
| 5862 | /** The port number the query will be sent to. |
| 5863 | * |
| 5864 | * @default {53} */ |
| 5865 | port?: number; |
| 5866 | }; |
| 5867 | /** |
| 5868 | * An abort signal to allow cancellation of the DNS resolution operation. |
| 5869 | * If the signal becomes aborted the resolveDns operation will be stopped |
| 5870 | * and the promise returned will be rejected with an AbortError. |
| 5871 | */ |
| 5872 | signal?: AbortSignal; |
| 5873 | } |
| 5874 | |
| 5875 | /** If {@linkcode Deno.resolveDns} is called with `"CAA"` record type |
| 5876 | * specified, it will resolve with an array of objects with this interface. |
| 5877 | * |
| 5878 | * @category Network |
| 5879 | */ |
| 5880 | export interface CAARecord { |
| 5881 | /** If `true`, indicates that the corresponding property tag **must** be |
| 5882 | * understood if the semantics of the CAA record are to be correctly |
| 5883 | * interpreted by an issuer. |
| 5884 | * |
| 5885 | * Issuers **must not** issue certificates for a domain if the relevant CAA |
| 5886 | * Resource Record set contains unknown property tags that have `critical` |
| 5887 | * set. */ |
| 5888 | critical: boolean; |
| 5889 | /** An string that represents the identifier of the property represented by |
| 5890 | * the record. */ |
| 5891 | tag: string; |
| 5892 | /** The value associated with the tag. */ |
| 5893 | value: string; |
| 5894 | } |
| 5895 | |
| 5896 | /** If {@linkcode Deno.resolveDns} is called with `"MX"` record type |
| 5897 | * specified, it will return an array of objects with this interface. |
| 5898 | * |
| 5899 | * @category Network */ |
| 5900 | export interface MXRecord { |
| 5901 | /** A priority value, which is a relative value compared to the other |
| 5902 | * preferences of MX records for the domain. */ |
| 5903 | preference: number; |
| 5904 | /** The server that mail should be delivered to. */ |
| 5905 | exchange: string; |
| 5906 | } |
| 5907 | |
| 5908 | /** If {@linkcode Deno.resolveDns} is called with `"NAPTR"` record type |
| 5909 | * specified, it will return an array of objects with this interface. |
| 5910 | * |
| 5911 | * @category Network */ |
| 5912 | export interface NAPTRRecord { |
| 5913 | order: number; |
| 5914 | preference: number; |
| 5915 | flags: string; |
| 5916 | services: string; |
| 5917 | regexp: string; |
| 5918 | replacement: string; |
| 5919 | } |
| 5920 | |
| 5921 | /** If {@linkcode Deno.resolveDns} is called with `"SOA"` record type |
| 5922 | * specified, it will return an array of objects with this interface. |
| 5923 | * |
| 5924 | * @category Network */ |
| 5925 | export interface SOARecord { |
| 5926 | mname: string; |
| 5927 | rname: string; |
| 5928 | serial: number; |
| 5929 | refresh: number; |
| 5930 | retry: number; |
| 5931 | expire: number; |
| 5932 | minimum: number; |
| 5933 | } |
| 5934 | |
| 5935 | /** If {@linkcode Deno.resolveDns} is called with `"SRV"` record type |
| 5936 | * specified, it will return an array of objects with this interface. |
| 5937 | * |
| 5938 | * @category Network |
| 5939 | */ |
| 5940 | export interface SRVRecord { |
| 5941 | priority: number; |
| 5942 | weight: number; |
| 5943 | port: number; |
| 5944 | target: string; |
| 5945 | } |
| 5946 | |
| 5947 | /** |
| 5948 | * Performs DNS resolution against the given query, returning resolved |
| 5949 | * records. |
| 5950 | * |
| 5951 | * Fails in the cases such as: |
| 5952 | * |
| 5953 | * - the query is in invalid format. |
| 5954 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 5955 | * beyond the range of 16-bit unsigned integer. |
| 5956 | * - the request timed out. |
| 5957 | * |
| 5958 | * ```ts |
| 5959 | * const a = await Deno.resolveDns("example.com", "A"); |
| 5960 | * |
| 5961 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 5962 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 5963 | * }); |
| 5964 | * ``` |
| 5965 | * |
| 5966 | * Requires `allow-net` permission. |
| 5967 | * |
| 5968 | * @tags allow-net |
| 5969 | * @category Network |
| 5970 | */ |
| 5971 | export function resolveDns( |
| 5972 | query: string, |
| 5973 | recordType: "A" | "AAAA" | "ANAME" | "CNAME" | "NS" | "PTR", |
| 5974 | options?: ResolveDnsOptions, |
| 5975 | ): Promise<string[]>; |
| 5976 | |
| 5977 | /** |
| 5978 | * Performs DNS resolution against the given query, returning resolved |
| 5979 | * records. |
| 5980 | * |
| 5981 | * Fails in the cases such as: |
| 5982 | * |
| 5983 | * - the query is in invalid format. |
| 5984 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 5985 | * beyond the range of 16-bit unsigned integer. |
| 5986 | * - the request timed out. |
| 5987 | * |
| 5988 | * ```ts |
| 5989 | * const a = await Deno.resolveDns("example.com", "A"); |
| 5990 | * |
| 5991 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 5992 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 5993 | * }); |
| 5994 | * ``` |
| 5995 | * |
| 5996 | * Requires `allow-net` permission. |
| 5997 | * |
| 5998 | * @tags allow-net |
| 5999 | * @category Network |
| 6000 | */ |
| 6001 | export function resolveDns( |
| 6002 | query: string, |
| 6003 | recordType: "CAA", |
| 6004 | options?: ResolveDnsOptions, |
| 6005 | ): Promise<CAARecord[]>; |
| 6006 | |
| 6007 | /** |
| 6008 | * Performs DNS resolution against the given query, returning resolved |
| 6009 | * records. |
| 6010 | * |
| 6011 | * Fails in the cases such as: |
| 6012 | * |
| 6013 | * - the query is in invalid format. |
| 6014 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 6015 | * beyond the range of 16-bit unsigned integer. |
| 6016 | * - the request timed out. |
| 6017 | * |
| 6018 | * ```ts |
| 6019 | * const a = await Deno.resolveDns("example.com", "A"); |
| 6020 | * |
| 6021 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 6022 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 6023 | * }); |
| 6024 | * ``` |
| 6025 | * |
| 6026 | * Requires `allow-net` permission. |
| 6027 | * |
| 6028 | * @tags allow-net |
| 6029 | * @category Network |
| 6030 | */ |
| 6031 | export function resolveDns( |
| 6032 | query: string, |
| 6033 | recordType: "MX", |
| 6034 | options?: ResolveDnsOptions, |
| 6035 | ): Promise<MXRecord[]>; |
| 6036 | |
| 6037 | /** |
| 6038 | * Performs DNS resolution against the given query, returning resolved |
| 6039 | * records. |
| 6040 | * |
| 6041 | * Fails in the cases such as: |
| 6042 | * |
| 6043 | * - the query is in invalid format. |
| 6044 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 6045 | * beyond the range of 16-bit unsigned integer. |
| 6046 | * - the request timed out. |
| 6047 | * |
| 6048 | * ```ts |
| 6049 | * const a = await Deno.resolveDns("example.com", "A"); |
| 6050 | * |
| 6051 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 6052 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 6053 | * }); |
| 6054 | * ``` |
| 6055 | * |
| 6056 | * Requires `allow-net` permission. |
| 6057 | * |
| 6058 | * @tags allow-net |
| 6059 | * @category Network |
| 6060 | */ |
| 6061 | export function resolveDns( |
| 6062 | query: string, |
| 6063 | recordType: "NAPTR", |
| 6064 | options?: ResolveDnsOptions, |
| 6065 | ): Promise<NAPTRRecord[]>; |
| 6066 | |
| 6067 | /** |
| 6068 | * Performs DNS resolution against the given query, returning resolved |
| 6069 | * records. |
| 6070 | * |
| 6071 | * Fails in the cases such as: |
| 6072 | * |
| 6073 | * - the query is in invalid format. |
| 6074 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 6075 | * beyond the range of 16-bit unsigned integer. |
| 6076 | * - the request timed out. |
| 6077 | * |
| 6078 | * ```ts |
| 6079 | * const a = await Deno.resolveDns("example.com", "A"); |
| 6080 | * |
| 6081 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 6082 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 6083 | * }); |
| 6084 | * ``` |
| 6085 | * |
| 6086 | * Requires `allow-net` permission. |
| 6087 | * |
| 6088 | * @tags allow-net |
| 6089 | * @category Network |
| 6090 | */ |
| 6091 | export function resolveDns( |
| 6092 | query: string, |
| 6093 | recordType: "SOA", |
| 6094 | options?: ResolveDnsOptions, |
| 6095 | ): Promise<SOARecord[]>; |
| 6096 | |
| 6097 | /** |
| 6098 | * Performs DNS resolution against the given query, returning resolved |
| 6099 | * records. |
| 6100 | * |
| 6101 | * Fails in the cases such as: |
| 6102 | * |
| 6103 | * - the query is in invalid format. |
| 6104 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 6105 | * beyond the range of 16-bit unsigned integer. |
| 6106 | * - the request timed out. |
| 6107 | * |
| 6108 | * ```ts |
| 6109 | * const a = await Deno.resolveDns("example.com", "A"); |
| 6110 | * |
| 6111 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 6112 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 6113 | * }); |
| 6114 | * ``` |
| 6115 | * |
| 6116 | * Requires `allow-net` permission. |
| 6117 | * |
| 6118 | * @tags allow-net |
| 6119 | * @category Network |
| 6120 | */ |
| 6121 | export function resolveDns( |
| 6122 | query: string, |
| 6123 | recordType: "SRV", |
| 6124 | options?: ResolveDnsOptions, |
| 6125 | ): Promise<SRVRecord[]>; |
| 6126 | |
| 6127 | /** |
| 6128 | * Performs DNS resolution against the given query, returning resolved |
| 6129 | * records. |
| 6130 | * |
| 6131 | * Fails in the cases such as: |
| 6132 | * |
| 6133 | * - the query is in invalid format. |
| 6134 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 6135 | * beyond the range of 16-bit unsigned integer. |
| 6136 | * - the request timed out. |
| 6137 | * |
| 6138 | * ```ts |
| 6139 | * const a = await Deno.resolveDns("example.com", "A"); |
| 6140 | * |
| 6141 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 6142 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 6143 | * }); |
| 6144 | * ``` |
| 6145 | * |
| 6146 | * Requires `allow-net` permission. |
| 6147 | * |
| 6148 | * @tags allow-net |
| 6149 | * @category Network |
| 6150 | */ |
| 6151 | export function resolveDns( |
| 6152 | query: string, |
| 6153 | recordType: "TXT", |
| 6154 | options?: ResolveDnsOptions, |
| 6155 | ): Promise<string[][]>; |
| 6156 | |
| 6157 | /** |
| 6158 | * Performs DNS resolution against the given query, returning resolved |
| 6159 | * records. |
| 6160 | * |
| 6161 | * Fails in the cases such as: |
| 6162 | * |
| 6163 | * - the query is in invalid format. |
| 6164 | * - the options have an invalid parameter. For example `nameServer.port` is |
| 6165 | * beyond the range of 16-bit unsigned integer. |
| 6166 | * - the request timed out. |
| 6167 | * |
| 6168 | * ```ts |
| 6169 | * const a = await Deno.resolveDns("example.com", "A"); |
| 6170 | * |
| 6171 | * const aaaa = await Deno.resolveDns("example.com", "AAAA", { |
| 6172 | * nameServer: { ipAddr: "8.8.8.8", port: 53 }, |
| 6173 | * }); |
| 6174 | * ``` |
| 6175 | * |
| 6176 | * Requires `allow-net` permission. |
| 6177 | * |
| 6178 | * @tags allow-net |
| 6179 | * @category Network |
| 6180 | */ |
| 6181 | export function resolveDns( |
| 6182 | query: string, |
| 6183 | recordType: RecordType, |
| 6184 | options?: ResolveDnsOptions, |
| 6185 | ): Promise< |
| 6186 | | string[] |
| 6187 | | CAARecord[] |
| 6188 | | MXRecord[] |
| 6189 | | NAPTRRecord[] |
| 6190 | | SOARecord[] |
| 6191 | | SRVRecord[] |
| 6192 | | string[][] |
| 6193 | >; |
| 6194 | |
| 6195 | /** |
| 6196 | * Make the timer of the given `id` block the event loop from finishing. |
| 6197 | * |
| 6198 | * @category Runtime |
| 6199 | */ |
| 6200 | export function refTimer(id: number): void; |
| 6201 | |
| 6202 | /** |
| 6203 | * Make the timer of the given `id` not block the event loop from finishing. |
| 6204 | * |
| 6205 | * @category Runtime |
| 6206 | */ |
| 6207 | export function unrefTimer(id: number): void; |
| 6208 | |
| 6209 | /** |
| 6210 | * Returns the user id of the process on POSIX platforms. Returns null on Windows. |
| 6211 | * |
| 6212 | * ```ts |
| 6213 | * console.log(Deno.uid()); |
| 6214 | * ``` |
| 6215 | * |
| 6216 | * Requires `allow-sys` permission. |
| 6217 | * |
| 6218 | * @tags allow-sys |
| 6219 | * @category Runtime |
| 6220 | */ |
| 6221 | export function uid(): number | null; |
| 6222 | |
| 6223 | /** |
| 6224 | * Returns the group id of the process on POSIX platforms. Returns null on windows. |
| 6225 | * |
| 6226 | * ```ts |
| 6227 | * console.log(Deno.gid()); |
| 6228 | * ``` |
| 6229 | * |
| 6230 | * Requires `allow-sys` permission. |
| 6231 | * |
| 6232 | * @tags allow-sys |
| 6233 | * @category Runtime |
| 6234 | */ |
| 6235 | export function gid(): number | null; |
| 6236 | |
| 6237 | /** Additional information for an HTTP request and its connection. |
| 6238 | * |
| 6239 | * @category HTTP Server |
| 6240 | */ |
| 6241 | export interface ServeHandlerInfo { |
| 6242 | /** The remote address of the connection. */ |
| 6243 | remoteAddr: Deno.NetAddr; |
| 6244 | } |
| 6245 | |
| 6246 | /** A handler for HTTP requests. Consumes a request and returns a response. |
| 6247 | * |
| 6248 | * If a handler throws, the server calling the handler will assume the impact |
| 6249 | * of the error is isolated to the individual request. It will catch the error |
| 6250 | * and if necessary will close the underlying connection. |
| 6251 | * |
| 6252 | * @category HTTP Server |
| 6253 | */ |
| 6254 | export type ServeHandler = ( |
| 6255 | request: Request, |
| 6256 | info: ServeHandlerInfo, |
| 6257 | ) => Response | Promise<Response>; |
| 6258 | |
| 6259 | /** Options which can be set when calling {@linkcode Deno.serve}. |
| 6260 | * |
| 6261 | * @category HTTP Server |
| 6262 | */ |
| 6263 | export interface ServeOptions { |
| 6264 | /** The port to listen on. |
| 6265 | * |
| 6266 | * Set to `0` to listen on any available port. |
| 6267 | * |
| 6268 | * @default {8000} */ |
| 6269 | port?: number; |
| 6270 | |
| 6271 | /** A literal IP address or host name that can be resolved to an IP address. |
| 6272 | * |
| 6273 | * __Note about `0.0.0.0`__ While listening `0.0.0.0` works on all platforms, |
| 6274 | * the browsers on Windows don't work with the address `0.0.0.0`. |
| 6275 | * You should show the message like `server running on localhost:8080` instead of |
| 6276 | * `server running on 0.0.0.0:8080` if your program supports Windows. |
| 6277 | * |
| 6278 | * @default {"0.0.0.0"} */ |
| 6279 | hostname?: string; |
| 6280 | |
| 6281 | /** An {@linkcode AbortSignal} to close the server and all connections. */ |
| 6282 | signal?: AbortSignal; |
| 6283 | |
| 6284 | /** Sets `SO_REUSEPORT` on POSIX systems. */ |
| 6285 | reusePort?: boolean; |
| 6286 | |
| 6287 | /** The handler to invoke when route handlers throw an error. */ |
| 6288 | onError?: (error: unknown) => Response | Promise<Response>; |
| 6289 | |
| 6290 | /** The callback which is called when the server starts listening. */ |
| 6291 | onListen?: (localAddr: Deno.NetAddr) => void; |
| 6292 | } |
| 6293 | |
| 6294 | /** Additional options which are used when opening a TLS (HTTPS) server. |
| 6295 | * |
| 6296 | * @category HTTP Server |
| 6297 | */ |
| 6298 | export interface ServeTlsOptions extends ServeOptions { |
| 6299 | /** |
| 6300 | * Server private key in PEM format. Use {@linkcode TlsCertifiedKeyOptions} instead. |
| 6301 | * |
| 6302 | * @deprecated This will be removed in Deno 2.0. See the |
| 6303 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 6304 | * for migration instructions. |
| 6305 | */ |
| 6306 | cert?: string; |
| 6307 | |
| 6308 | /** |
| 6309 | * Cert chain in PEM format. Use {@linkcode TlsCertifiedKeyOptions} instead. |
| 6310 | * |
| 6311 | * @deprecated This will be removed in Deno 2.0. See the |
| 6312 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 6313 | * for migration instructions. |
| 6314 | */ |
| 6315 | key?: string; |
| 6316 | } |
| 6317 | |
| 6318 | /** |
| 6319 | * @category HTTP Server |
| 6320 | */ |
| 6321 | export interface ServeInit { |
| 6322 | /** The handler to invoke to process each incoming request. */ |
| 6323 | handler: ServeHandler; |
| 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * @category HTTP Server |
| 6328 | */ |
| 6329 | export interface ServeTlsInit { |
| 6330 | /** The handler to invoke to process each incoming request. */ |
| 6331 | handler: ServeHandler; |
| 6332 | } |
| 6333 | |
| 6334 | /** @category HTTP Server */ |
| 6335 | export interface ServeUnixOptions { |
| 6336 | /** The unix domain socket path to listen on. */ |
| 6337 | path: string; |
| 6338 | |
| 6339 | /** An {@linkcode AbortSignal} to close the server and all connections. */ |
| 6340 | signal?: AbortSignal; |
| 6341 | |
| 6342 | /** The handler to invoke when route handlers throw an error. */ |
| 6343 | onError?: (error: unknown) => Response | Promise<Response>; |
| 6344 | |
| 6345 | /** The callback which is called when the server starts listening. */ |
| 6346 | onListen?: (localAddr: Deno.UnixAddr) => void; |
| 6347 | } |
| 6348 | |
| 6349 | /** Information for a unix domain socket HTTP request. |
| 6350 | * |
| 6351 | * @category HTTP Server |
| 6352 | */ |
| 6353 | export interface ServeUnixHandlerInfo { |
| 6354 | /** The remote address of the connection. */ |
| 6355 | remoteAddr: Deno.UnixAddr; |
| 6356 | } |
| 6357 | |
| 6358 | /** A handler for unix domain socket HTTP requests. Consumes a request and returns a response. |
| 6359 | * |
| 6360 | * If a handler throws, the server calling the handler will assume the impact |
| 6361 | * of the error is isolated to the individual request. It will catch the error |
| 6362 | * and if necessary will close the underlying connection. |
| 6363 | * |
| 6364 | * @category HTTP Server |
| 6365 | */ |
| 6366 | export type ServeUnixHandler = ( |
| 6367 | request: Request, |
| 6368 | info: ServeUnixHandlerInfo, |
| 6369 | ) => Response | Promise<Response>; |
| 6370 | |
| 6371 | /** |
| 6372 | * @category HTTP Server |
| 6373 | */ |
| 6374 | export interface ServeUnixInit { |
| 6375 | /** The handler to invoke to process each incoming request. */ |
| 6376 | handler: ServeUnixHandler; |
| 6377 | } |
| 6378 | |
| 6379 | /** An instance of the server created using `Deno.serve()` API. |
| 6380 | * |
| 6381 | * @category HTTP Server |
| 6382 | */ |
| 6383 | export interface HttpServer<A extends Deno.Addr = Deno.Addr> |
| 6384 | extends AsyncDisposable { |
| 6385 | /** A promise that resolves once server finishes - eg. when aborted using |
| 6386 | * the signal passed to {@linkcode ServeOptions.signal}. |
| 6387 | */ |
| 6388 | finished: Promise<void>; |
| 6389 | |
| 6390 | /** The local address this server is listening on. */ |
| 6391 | addr: A; |
| 6392 | |
| 6393 | /** |
| 6394 | * Make the server block the event loop from finishing. |
| 6395 | * |
| 6396 | * Note: the server blocks the event loop from finishing by default. |
| 6397 | * This method is only meaningful after `.unref()` is called. |
| 6398 | */ |
| 6399 | ref(): void; |
| 6400 | |
| 6401 | /** Make the server not block the event loop from finishing. */ |
| 6402 | unref(): void; |
| 6403 | |
| 6404 | /** Gracefully close the server. No more new connections will be accepted, |
| 6405 | * while pending requests will be allowed to finish. |
| 6406 | */ |
| 6407 | shutdown(): Promise<void>; |
| 6408 | } |
| 6409 | |
| 6410 | /** |
| 6411 | * @category HTTP Server |
| 6412 | * |
| 6413 | * @deprecated This will be removed in Deno 2.0. See the |
| 6414 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 6415 | * for migration instructions. |
| 6416 | */ |
| 6417 | export type Server = HttpServer; |
| 6418 | |
| 6419 | /** Serves HTTP requests with the given handler. |
| 6420 | * |
| 6421 | * The below example serves with the port `8000` on hostname `"127.0.0.1"`. |
| 6422 | * |
| 6423 | * ```ts |
| 6424 | * Deno.serve((_req) => new Response("Hello, world")); |
| 6425 | * ``` |
| 6426 | * |
| 6427 | * @category HTTP Server |
| 6428 | */ |
| 6429 | export function serve(handler: ServeHandler): HttpServer<Deno.NetAddr>; |
| 6430 | /** Serves HTTP requests with the given option bag and handler. |
| 6431 | * |
| 6432 | * You can specify the socket path with `path` option. |
| 6433 | * |
| 6434 | * ```ts |
| 6435 | * Deno.serve( |
| 6436 | * { path: "path/to/socket" }, |
| 6437 | * (_req) => new Response("Hello, world") |
| 6438 | * ); |
| 6439 | * ``` |
| 6440 | * |
| 6441 | * You can stop the server with an {@linkcode AbortSignal}. The abort signal |
| 6442 | * needs to be passed as the `signal` option in the options bag. The server |
| 6443 | * aborts when the abort signal is aborted. To wait for the server to close, |
| 6444 | * await the promise returned from the `Deno.serve` API. |
| 6445 | * |
| 6446 | * ```ts |
| 6447 | * const ac = new AbortController(); |
| 6448 | * |
| 6449 | * const server = Deno.serve( |
| 6450 | * { signal: ac.signal, path: "path/to/socket" }, |
| 6451 | * (_req) => new Response("Hello, world") |
| 6452 | * ); |
| 6453 | * server.finished.then(() => console.log("Server closed")); |
| 6454 | * |
| 6455 | * console.log("Closing server..."); |
| 6456 | * ac.abort(); |
| 6457 | * ``` |
| 6458 | * |
| 6459 | * By default `Deno.serve` prints the message |
| 6460 | * `Listening on path/to/socket` on listening. If you like to |
| 6461 | * change this behavior, you can specify a custom `onListen` callback. |
| 6462 | * |
| 6463 | * ```ts |
| 6464 | * Deno.serve({ |
| 6465 | * onListen({ path }) { |
| 6466 | * console.log(`Server started at ${path}`); |
| 6467 | * // ... more info specific to your server .. |
| 6468 | * }, |
| 6469 | * path: "path/to/socket", |
| 6470 | * }, (_req) => new Response("Hello, world")); |
| 6471 | * ``` |
| 6472 | * |
| 6473 | * @category HTTP Server |
| 6474 | */ |
| 6475 | export function serve( |
| 6476 | options: ServeUnixOptions, |
| 6477 | handler: ServeUnixHandler, |
| 6478 | ): HttpServer<Deno.UnixAddr>; |
| 6479 | /** Serves HTTP requests with the given option bag and handler. |
| 6480 | * |
| 6481 | * You can specify an object with a port and hostname option, which is the |
| 6482 | * address to listen on. The default is port `8000` on hostname `"127.0.0.1"`. |
| 6483 | * |
| 6484 | * You can change the address to listen on using the `hostname` and `port` |
| 6485 | * options. The below example serves on port `3000` and hostname `"0.0.0.0"`. |
| 6486 | * |
| 6487 | * ```ts |
| 6488 | * Deno.serve( |
| 6489 | * { port: 3000, hostname: "0.0.0.0" }, |
| 6490 | * (_req) => new Response("Hello, world") |
| 6491 | * ); |
| 6492 | * ``` |
| 6493 | * |
| 6494 | * You can stop the server with an {@linkcode AbortSignal}. The abort signal |
| 6495 | * needs to be passed as the `signal` option in the options bag. The server |
| 6496 | * aborts when the abort signal is aborted. To wait for the server to close, |
| 6497 | * await the promise returned from the `Deno.serve` API. |
| 6498 | * |
| 6499 | * ```ts |
| 6500 | * const ac = new AbortController(); |
| 6501 | * |
| 6502 | * const server = Deno.serve( |
| 6503 | * { signal: ac.signal }, |
| 6504 | * (_req) => new Response("Hello, world") |
| 6505 | * ); |
| 6506 | * server.finished.then(() => console.log("Server closed")); |
| 6507 | * |
| 6508 | * console.log("Closing server..."); |
| 6509 | * ac.abort(); |
| 6510 | * ``` |
| 6511 | * |
| 6512 | * By default `Deno.serve` prints the message |
| 6513 | * `Listening on http://<hostname>:<port>/` on listening. If you like to |
| 6514 | * change this behavior, you can specify a custom `onListen` callback. |
| 6515 | * |
| 6516 | * ```ts |
| 6517 | * Deno.serve({ |
| 6518 | * onListen({ port, hostname }) { |
| 6519 | * console.log(`Server started at http://${hostname}:${port}`); |
| 6520 | * // ... more info specific to your server .. |
| 6521 | * }, |
| 6522 | * }, (_req) => new Response("Hello, world")); |
| 6523 | * ``` |
| 6524 | * |
| 6525 | * To enable TLS you must specify the `key` and `cert` options. |
| 6526 | * |
| 6527 | * ```ts |
| 6528 | * const cert = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n"; |
| 6529 | * const key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"; |
| 6530 | * Deno.serve({ cert, key }, (_req) => new Response("Hello, world")); |
| 6531 | * ``` |
| 6532 | * |
| 6533 | * @category HTTP Server |
| 6534 | */ |
| 6535 | export function serve( |
| 6536 | options: ServeOptions, |
| 6537 | handler: ServeHandler, |
| 6538 | ): HttpServer<Deno.NetAddr>; |
| 6539 | /** Serves HTTP requests with the given option bag and handler. |
| 6540 | * |
| 6541 | * You can specify an object with a port and hostname option, which is the |
| 6542 | * address to listen on. The default is port `8000` on hostname `"127.0.0.1"`. |
| 6543 | * |
| 6544 | * You can change the address to listen on using the `hostname` and `port` |
| 6545 | * options. The below example serves on port `3000` and hostname `"0.0.0.0"`. |
| 6546 | * |
| 6547 | * ```ts |
| 6548 | * Deno.serve( |
| 6549 | * { port: 3000, hostname: "0.0.0.0" }, |
| 6550 | * (_req) => new Response("Hello, world") |
| 6551 | * ); |
| 6552 | * ``` |
| 6553 | * |
| 6554 | * You can stop the server with an {@linkcode AbortSignal}. The abort signal |
| 6555 | * needs to be passed as the `signal` option in the options bag. The server |
| 6556 | * aborts when the abort signal is aborted. To wait for the server to close, |
| 6557 | * await the promise returned from the `Deno.serve` API. |
| 6558 | * |
| 6559 | * ```ts |
| 6560 | * const ac = new AbortController(); |
| 6561 | * |
| 6562 | * const server = Deno.serve( |
| 6563 | * { signal: ac.signal }, |
| 6564 | * (_req) => new Response("Hello, world") |
| 6565 | * ); |
| 6566 | * server.finished.then(() => console.log("Server closed")); |
| 6567 | * |
| 6568 | * console.log("Closing server..."); |
| 6569 | * ac.abort(); |
| 6570 | * ``` |
| 6571 | * |
| 6572 | * By default `Deno.serve` prints the message |
| 6573 | * `Listening on http://<hostname>:<port>/` on listening. If you like to |
| 6574 | * change this behavior, you can specify a custom `onListen` callback. |
| 6575 | * |
| 6576 | * ```ts |
| 6577 | * Deno.serve({ |
| 6578 | * onListen({ port, hostname }) { |
| 6579 | * console.log(`Server started at http://${hostname}:${port}`); |
| 6580 | * // ... more info specific to your server .. |
| 6581 | * }, |
| 6582 | * }, (_req) => new Response("Hello, world")); |
| 6583 | * ``` |
| 6584 | * |
| 6585 | * To enable TLS you must specify the `key` and `cert` options. |
| 6586 | * |
| 6587 | * ```ts |
| 6588 | * const cert = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n"; |
| 6589 | * const key = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"; |
| 6590 | * Deno.serve({ cert, key }, (_req) => new Response("Hello, world")); |
| 6591 | * ``` |
| 6592 | * |
| 6593 | * @category HTTP Server |
| 6594 | */ |
| 6595 | export function serve( |
| 6596 | options: |
| 6597 | | ServeTlsOptions |
| 6598 | | (ServeTlsOptions & TlsCertifiedKeyOptions), |
| 6599 | handler: ServeHandler, |
| 6600 | ): HttpServer<Deno.NetAddr>; |
| 6601 | /** Serves HTTP requests with the given option bag. |
| 6602 | * |
| 6603 | * You can specify an object with the path option, which is the |
| 6604 | * unix domain socket to listen on. |
| 6605 | * |
| 6606 | * ```ts |
| 6607 | * const ac = new AbortController(); |
| 6608 | * |
| 6609 | * const server = Deno.serve({ |
| 6610 | * path: "path/to/socket", |
| 6611 | * handler: (_req) => new Response("Hello, world"), |
| 6612 | * signal: ac.signal, |
| 6613 | * onListen({ path }) { |
| 6614 | * console.log(`Server started at ${path}`); |
| 6615 | * }, |
| 6616 | * }); |
| 6617 | * server.finished.then(() => console.log("Server closed")); |
| 6618 | * |
| 6619 | * console.log("Closing server..."); |
| 6620 | * ac.abort(); |
| 6621 | * ``` |
| 6622 | * |
| 6623 | * @category HTTP Server |
| 6624 | */ |
| 6625 | export function serve( |
| 6626 | options: ServeUnixInit & ServeUnixOptions, |
| 6627 | ): HttpServer<Deno.UnixAddr>; |
| 6628 | /** Serves HTTP requests with the given option bag. |
| 6629 | * |
| 6630 | * You can specify an object with a port and hostname option, which is the |
| 6631 | * address to listen on. The default is port `8000` on hostname `"127.0.0.1"`. |
| 6632 | * |
| 6633 | * ```ts |
| 6634 | * const ac = new AbortController(); |
| 6635 | * |
| 6636 | * const server = Deno.serve({ |
| 6637 | * port: 3000, |
| 6638 | * hostname: "0.0.0.0", |
| 6639 | * handler: (_req) => new Response("Hello, world"), |
| 6640 | * signal: ac.signal, |
| 6641 | * onListen({ port, hostname }) { |
| 6642 | * console.log(`Server started at http://${hostname}:${port}`); |
| 6643 | * }, |
| 6644 | * }); |
| 6645 | * server.finished.then(() => console.log("Server closed")); |
| 6646 | * |
| 6647 | * console.log("Closing server..."); |
| 6648 | * ac.abort(); |
| 6649 | * ``` |
| 6650 | * |
| 6651 | * @category HTTP Server |
| 6652 | */ |
| 6653 | export function serve( |
| 6654 | options: |
| 6655 | & ServeInit |
| 6656 | & ServeOptions, |
| 6657 | ): HttpServer<Deno.NetAddr>; |
| 6658 | /** Serves HTTP requests with the given option bag. |
| 6659 | * |
| 6660 | * You can specify an object with a port and hostname option, which is the |
| 6661 | * address to listen on. The default is port `8000` on hostname `"127.0.0.1"`. |
| 6662 | * |
| 6663 | * ```ts |
| 6664 | * const ac = new AbortController(); |
| 6665 | * |
| 6666 | * const server = Deno.serve({ |
| 6667 | * port: 3000, |
| 6668 | * hostname: "0.0.0.0", |
| 6669 | * handler: (_req) => new Response("Hello, world"), |
| 6670 | * signal: ac.signal, |
| 6671 | * onListen({ port, hostname }) { |
| 6672 | * console.log(`Server started at http://${hostname}:${port}`); |
| 6673 | * }, |
| 6674 | * }); |
| 6675 | * server.finished.then(() => console.log("Server closed")); |
| 6676 | * |
| 6677 | * console.log("Closing server..."); |
| 6678 | * ac.abort(); |
| 6679 | * ``` |
| 6680 | * |
| 6681 | * @category HTTP Server |
| 6682 | */ |
| 6683 | export function serve( |
| 6684 | options: |
| 6685 | & ServeTlsInit |
| 6686 | & ( |
| 6687 | | ServeTlsOptions |
| 6688 | | (ServeTlsOptions & TlsCertifiedKeyOptions) |
| 6689 | ), |
| 6690 | ): HttpServer<Deno.NetAddr>; |
| 6691 | } |
| 6692 | |
| 6693 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 6694 | |
| 6695 | // deno-lint-ignore-file no-explicit-any |
| 6696 | |
| 6697 | /// <reference no-default-lib="true" /> |
| 6698 | /// <reference lib="esnext" /> |
| 6699 | |
| 6700 | /** @category I/O */ |
| 6701 | declare interface Console { |
| 6702 | assert(condition?: boolean, ...data: any[]): void; |
| 6703 | clear(): void; |
| 6704 | count(label?: string): void; |
| 6705 | countReset(label?: string): void; |
| 6706 | debug(...data: any[]): void; |
| 6707 | dir(item?: any, options?: any): void; |
| 6708 | dirxml(...data: any[]): void; |
| 6709 | error(...data: any[]): void; |
| 6710 | group(...data: any[]): void; |
| 6711 | groupCollapsed(...data: any[]): void; |
| 6712 | groupEnd(): void; |
| 6713 | info(...data: any[]): void; |
| 6714 | log(...data: any[]): void; |
| 6715 | table(tabularData?: any, properties?: string[]): void; |
| 6716 | time(label?: string): void; |
| 6717 | timeEnd(label?: string): void; |
| 6718 | timeLog(label?: string, ...data: any[]): void; |
| 6719 | trace(...data: any[]): void; |
| 6720 | warn(...data: any[]): void; |
| 6721 | |
| 6722 | /** This method is a noop, unless used in inspector */ |
| 6723 | timeStamp(label?: string): void; |
| 6724 | |
| 6725 | /** This method is a noop, unless used in inspector */ |
| 6726 | profile(label?: string): void; |
| 6727 | |
| 6728 | /** This method is a noop, unless used in inspector */ |
| 6729 | profileEnd(label?: string): void; |
| 6730 | } |
| 6731 | |
| 6732 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 6733 | |
| 6734 | // deno-lint-ignore-file no-explicit-any no-var |
| 6735 | |
| 6736 | /// <reference no-default-lib="true" /> |
| 6737 | /// <reference lib="esnext" /> |
| 6738 | |
| 6739 | /** @category URL */ |
| 6740 | declare interface URLSearchParams { |
| 6741 | /** Appends a specified key/value pair as a new search parameter. |
| 6742 | * |
| 6743 | * ```ts |
| 6744 | * let searchParams = new URLSearchParams(); |
| 6745 | * searchParams.append('name', 'first'); |
| 6746 | * searchParams.append('name', 'second'); |
| 6747 | * ``` |
| 6748 | */ |
| 6749 | append(name: string, value: string): void; |
| 6750 | |
| 6751 | /** Deletes search parameters that match a name, and optional value, |
| 6752 | * from the list of all search parameters. |
| 6753 | * |
| 6754 | * ```ts |
| 6755 | * let searchParams = new URLSearchParams([['name', 'value']]); |
| 6756 | * searchParams.delete('name'); |
| 6757 | * searchParams.delete('name', 'value'); |
| 6758 | * ``` |
| 6759 | */ |
| 6760 | delete(name: string, value?: string): void; |
| 6761 | |
| 6762 | /** Returns all the values associated with a given search parameter |
| 6763 | * as an array. |
| 6764 | * |
| 6765 | * ```ts |
| 6766 | * searchParams.getAll('name'); |
| 6767 | * ``` |
| 6768 | */ |
| 6769 | getAll(name: string): string[]; |
| 6770 | |
| 6771 | /** Returns the first value associated to the given search parameter. |
| 6772 | * |
| 6773 | * ```ts |
| 6774 | * searchParams.get('name'); |
| 6775 | * ``` |
| 6776 | */ |
| 6777 | get(name: string): string | null; |
| 6778 | |
| 6779 | /** Returns a boolean value indicating if a given parameter, |
| 6780 | * or parameter and value pair, exists. |
| 6781 | * |
| 6782 | * ```ts |
| 6783 | * searchParams.has('name'); |
| 6784 | * searchParams.has('name', 'value'); |
| 6785 | * ``` |
| 6786 | */ |
| 6787 | has(name: string, value?: string): boolean; |
| 6788 | |
| 6789 | /** Sets the value associated with a given search parameter to the |
| 6790 | * given value. If there were several matching values, this method |
| 6791 | * deletes the others. If the search parameter doesn't exist, this |
| 6792 | * method creates it. |
| 6793 | * |
| 6794 | * ```ts |
| 6795 | * searchParams.set('name', 'value'); |
| 6796 | * ``` |
| 6797 | */ |
| 6798 | set(name: string, value: string): void; |
| 6799 | |
| 6800 | /** Sort all key/value pairs contained in this object in place and |
| 6801 | * return undefined. The sort order is according to Unicode code |
| 6802 | * points of the keys. |
| 6803 | * |
| 6804 | * ```ts |
| 6805 | * searchParams.sort(); |
| 6806 | * ``` |
| 6807 | */ |
| 6808 | sort(): void; |
| 6809 | |
| 6810 | /** Calls a function for each element contained in this object in |
| 6811 | * place and return undefined. Optionally accepts an object to use |
| 6812 | * as this when executing callback as second argument. |
| 6813 | * |
| 6814 | * ```ts |
| 6815 | * const params = new URLSearchParams([["a", "b"], ["c", "d"]]); |
| 6816 | * params.forEach((value, key, parent) => { |
| 6817 | * console.log(value, key, parent); |
| 6818 | * }); |
| 6819 | * ``` |
| 6820 | */ |
| 6821 | forEach( |
| 6822 | callbackfn: (value: string, key: string, parent: this) => void, |
| 6823 | thisArg?: any, |
| 6824 | ): void; |
| 6825 | |
| 6826 | /** Returns an iterator allowing to go through all keys contained |
| 6827 | * in this object. |
| 6828 | * |
| 6829 | * ```ts |
| 6830 | * const params = new URLSearchParams([["a", "b"], ["c", "d"]]); |
| 6831 | * for (const key of params.keys()) { |
| 6832 | * console.log(key); |
| 6833 | * } |
| 6834 | * ``` |
| 6835 | */ |
| 6836 | keys(): IterableIterator<string>; |
| 6837 | |
| 6838 | /** Returns an iterator allowing to go through all values contained |
| 6839 | * in this object. |
| 6840 | * |
| 6841 | * ```ts |
| 6842 | * const params = new URLSearchParams([["a", "b"], ["c", "d"]]); |
| 6843 | * for (const value of params.values()) { |
| 6844 | * console.log(value); |
| 6845 | * } |
| 6846 | * ``` |
| 6847 | */ |
| 6848 | values(): IterableIterator<string>; |
| 6849 | |
| 6850 | /** Returns an iterator allowing to go through all key/value |
| 6851 | * pairs contained in this object. |
| 6852 | * |
| 6853 | * ```ts |
| 6854 | * const params = new URLSearchParams([["a", "b"], ["c", "d"]]); |
| 6855 | * for (const [key, value] of params.entries()) { |
| 6856 | * console.log(key, value); |
| 6857 | * } |
| 6858 | * ``` |
| 6859 | */ |
| 6860 | entries(): IterableIterator<[string, string]>; |
| 6861 | |
| 6862 | /** Returns an iterator allowing to go through all key/value |
| 6863 | * pairs contained in this object. |
| 6864 | * |
| 6865 | * ```ts |
| 6866 | * const params = new URLSearchParams([["a", "b"], ["c", "d"]]); |
| 6867 | * for (const [key, value] of params) { |
| 6868 | * console.log(key, value); |
| 6869 | * } |
| 6870 | * ``` |
| 6871 | */ |
| 6872 | [Symbol.iterator](): IterableIterator<[string, string]>; |
| 6873 | |
| 6874 | /** Returns a query string suitable for use in a URL. |
| 6875 | * |
| 6876 | * ```ts |
| 6877 | * searchParams.toString(); |
| 6878 | * ``` |
| 6879 | */ |
| 6880 | toString(): string; |
| 6881 | |
| 6882 | /** Contains the number of search parameters |
| 6883 | * |
| 6884 | * ```ts |
| 6885 | * searchParams.size |
| 6886 | * ``` |
| 6887 | */ |
| 6888 | size: number; |
| 6889 | } |
| 6890 | |
| 6891 | /** @category URL */ |
| 6892 | declare var URLSearchParams: { |
| 6893 | readonly prototype: URLSearchParams; |
| 6894 | new ( |
| 6895 | init?: Iterable<string[]> | Record<string, string> | string, |
| 6896 | ): URLSearchParams; |
| 6897 | }; |
| 6898 | |
| 6899 | /** The URL interface represents an object providing static methods used for |
| 6900 | * creating object URLs. |
| 6901 | * |
| 6902 | * @category URL |
| 6903 | */ |
| 6904 | declare interface URL { |
| 6905 | hash: string; |
| 6906 | host: string; |
| 6907 | hostname: string; |
| 6908 | href: string; |
| 6909 | toString(): string; |
| 6910 | readonly origin: string; |
| 6911 | password: string; |
| 6912 | pathname: string; |
| 6913 | port: string; |
| 6914 | protocol: string; |
| 6915 | search: string; |
| 6916 | readonly searchParams: URLSearchParams; |
| 6917 | username: string; |
| 6918 | toJSON(): string; |
| 6919 | } |
| 6920 | |
| 6921 | /** The URL interface represents an object providing static methods used for |
| 6922 | * creating object URLs. |
| 6923 | * |
| 6924 | * @category URL |
| 6925 | */ |
| 6926 | declare var URL: { |
| 6927 | readonly prototype: URL; |
| 6928 | new (url: string | URL, base?: string | URL): URL; |
| 6929 | parse(url: string | URL, base?: string | URL): URL | null; |
| 6930 | canParse(url: string | URL, base?: string | URL): boolean; |
| 6931 | createObjectURL(blob: Blob): string; |
| 6932 | revokeObjectURL(url: string): void; |
| 6933 | }; |
| 6934 | |
| 6935 | /** @category URL */ |
| 6936 | declare interface URLPatternInit { |
| 6937 | protocol?: string; |
| 6938 | username?: string; |
| 6939 | password?: string; |
| 6940 | hostname?: string; |
| 6941 | port?: string; |
| 6942 | pathname?: string; |
| 6943 | search?: string; |
| 6944 | hash?: string; |
| 6945 | baseURL?: string; |
| 6946 | } |
| 6947 | |
| 6948 | /** @category URL */ |
| 6949 | declare type URLPatternInput = string | URLPatternInit; |
| 6950 | |
| 6951 | /** @category URL */ |
| 6952 | declare interface URLPatternComponentResult { |
| 6953 | input: string; |
| 6954 | groups: Record<string, string | undefined>; |
| 6955 | } |
| 6956 | |
| 6957 | /** `URLPatternResult` is the object returned from `URLPattern.exec`. |
| 6958 | * |
| 6959 | * @category URL |
| 6960 | */ |
| 6961 | declare interface URLPatternResult { |
| 6962 | /** The inputs provided when matching. */ |
| 6963 | inputs: [URLPatternInit] | [URLPatternInit, string]; |
| 6964 | |
| 6965 | /** The matched result for the `protocol` matcher. */ |
| 6966 | protocol: URLPatternComponentResult; |
| 6967 | /** The matched result for the `username` matcher. */ |
| 6968 | username: URLPatternComponentResult; |
| 6969 | /** The matched result for the `password` matcher. */ |
| 6970 | password: URLPatternComponentResult; |
| 6971 | /** The matched result for the `hostname` matcher. */ |
| 6972 | hostname: URLPatternComponentResult; |
| 6973 | /** The matched result for the `port` matcher. */ |
| 6974 | port: URLPatternComponentResult; |
| 6975 | /** The matched result for the `pathname` matcher. */ |
| 6976 | pathname: URLPatternComponentResult; |
| 6977 | /** The matched result for the `search` matcher. */ |
| 6978 | search: URLPatternComponentResult; |
| 6979 | /** The matched result for the `hash` matcher. */ |
| 6980 | hash: URLPatternComponentResult; |
| 6981 | } |
| 6982 | |
| 6983 | /** |
| 6984 | * The URLPattern API provides a web platform primitive for matching URLs based |
| 6985 | * on a convenient pattern syntax. |
| 6986 | * |
| 6987 | * The syntax is based on path-to-regexp. Wildcards, named capture groups, |
| 6988 | * regular groups, and group modifiers are all supported. |
| 6989 | * |
| 6990 | * ```ts |
| 6991 | * // Specify the pattern as structured data. |
| 6992 | * const pattern = new URLPattern({ pathname: "/users/:user" }); |
| 6993 | * const match = pattern.exec("https://blog.example.com/users/joe"); |
| 6994 | * console.log(match.pathname.groups.user); // joe |
| 6995 | * ``` |
| 6996 | * |
| 6997 | * ```ts |
| 6998 | * // Specify a fully qualified string pattern. |
| 6999 | * const pattern = new URLPattern("https://example.com/books/:id"); |
| 7000 | * console.log(pattern.test("https://example.com/books/123")); // true |
| 7001 | * console.log(pattern.test("https://deno.land/books/123")); // false |
| 7002 | * ``` |
| 7003 | * |
| 7004 | * ```ts |
| 7005 | * // Specify a relative string pattern with a base URL. |
| 7006 | * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); |
| 7007 | * console.log(pattern.test("https://blog.example.com/article")); // false |
| 7008 | * console.log(pattern.test("https://blog.example.com/article/123")); // true |
| 7009 | * ``` |
| 7010 | * |
| 7011 | * @category URL |
| 7012 | */ |
| 7013 | declare interface URLPattern { |
| 7014 | /** |
| 7015 | * Test if the given input matches the stored pattern. |
| 7016 | * |
| 7017 | * The input can either be provided as an absolute URL string with an optional base, |
| 7018 | * relative URL string with a required base, or as individual components |
| 7019 | * in the form of an `URLPatternInit` object. |
| 7020 | * |
| 7021 | * ```ts |
| 7022 | * const pattern = new URLPattern("https://example.com/books/:id"); |
| 7023 | * |
| 7024 | * // Test an absolute url string. |
| 7025 | * console.log(pattern.test("https://example.com/books/123")); // true |
| 7026 | * |
| 7027 | * // Test a relative url with a base. |
| 7028 | * console.log(pattern.test("/books/123", "https://example.com")); // true |
| 7029 | * |
| 7030 | * // Test an object of url components. |
| 7031 | * console.log(pattern.test({ pathname: "/books/123" })); // true |
| 7032 | * ``` |
| 7033 | */ |
| 7034 | test(input: URLPatternInput, baseURL?: string): boolean; |
| 7035 | |
| 7036 | /** |
| 7037 | * Match the given input against the stored pattern. |
| 7038 | * |
| 7039 | * The input can either be provided as an absolute URL string with an optional base, |
| 7040 | * relative URL string with a required base, or as individual components |
| 7041 | * in the form of an `URLPatternInit` object. |
| 7042 | * |
| 7043 | * ```ts |
| 7044 | * const pattern = new URLPattern("https://example.com/books/:id"); |
| 7045 | * |
| 7046 | * // Match an absolute url string. |
| 7047 | * let match = pattern.exec("https://example.com/books/123"); |
| 7048 | * console.log(match.pathname.groups.id); // 123 |
| 7049 | * |
| 7050 | * // Match a relative url with a base. |
| 7051 | * match = pattern.exec("/books/123", "https://example.com"); |
| 7052 | * console.log(match.pathname.groups.id); // 123 |
| 7053 | * |
| 7054 | * // Match an object of url components. |
| 7055 | * match = pattern.exec({ pathname: "/books/123" }); |
| 7056 | * console.log(match.pathname.groups.id); // 123 |
| 7057 | * ``` |
| 7058 | */ |
| 7059 | exec(input: URLPatternInput, baseURL?: string): URLPatternResult | null; |
| 7060 | |
| 7061 | /** The pattern string for the `protocol`. */ |
| 7062 | readonly protocol: string; |
| 7063 | /** The pattern string for the `username`. */ |
| 7064 | readonly username: string; |
| 7065 | /** The pattern string for the `password`. */ |
| 7066 | readonly password: string; |
| 7067 | /** The pattern string for the `hostname`. */ |
| 7068 | readonly hostname: string; |
| 7069 | /** The pattern string for the `port`. */ |
| 7070 | readonly port: string; |
| 7071 | /** The pattern string for the `pathname`. */ |
| 7072 | readonly pathname: string; |
| 7073 | /** The pattern string for the `search`. */ |
| 7074 | readonly search: string; |
| 7075 | /** The pattern string for the `hash`. */ |
| 7076 | readonly hash: string; |
| 7077 | } |
| 7078 | |
| 7079 | /** |
| 7080 | * The URLPattern API provides a web platform primitive for matching URLs based |
| 7081 | * on a convenient pattern syntax. |
| 7082 | * |
| 7083 | * The syntax is based on path-to-regexp. Wildcards, named capture groups, |
| 7084 | * regular groups, and group modifiers are all supported. |
| 7085 | * |
| 7086 | * ```ts |
| 7087 | * // Specify the pattern as structured data. |
| 7088 | * const pattern = new URLPattern({ pathname: "/users/:user" }); |
| 7089 | * const match = pattern.exec("https://blog.example.com/users/joe"); |
| 7090 | * console.log(match.pathname.groups.user); // joe |
| 7091 | * ``` |
| 7092 | * |
| 7093 | * ```ts |
| 7094 | * // Specify a fully qualified string pattern. |
| 7095 | * const pattern = new URLPattern("https://example.com/books/:id"); |
| 7096 | * console.log(pattern.test("https://example.com/books/123")); // true |
| 7097 | * console.log(pattern.test("https://deno.land/books/123")); // false |
| 7098 | * ``` |
| 7099 | * |
| 7100 | * ```ts |
| 7101 | * // Specify a relative string pattern with a base URL. |
| 7102 | * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); |
| 7103 | * console.log(pattern.test("https://blog.example.com/article")); // false |
| 7104 | * console.log(pattern.test("https://blog.example.com/article/123")); // true |
| 7105 | * ``` |
| 7106 | * |
| 7107 | * @category URL |
| 7108 | */ |
| 7109 | declare var URLPattern: { |
| 7110 | readonly prototype: URLPattern; |
| 7111 | new (input: URLPatternInput, baseURL?: string): URLPattern; |
| 7112 | }; |
| 7113 | |
| 7114 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 7115 | |
| 7116 | // deno-lint-ignore-file no-explicit-any no-var |
| 7117 | |
| 7118 | /// <reference no-default-lib="true" /> |
| 7119 | /// <reference lib="esnext" /> |
| 7120 | |
| 7121 | /** @category Platform */ |
| 7122 | declare interface DOMException extends Error { |
| 7123 | readonly name: string; |
| 7124 | readonly message: string; |
| 7125 | readonly code: number; |
| 7126 | readonly INDEX_SIZE_ERR: 1; |
| 7127 | readonly DOMSTRING_SIZE_ERR: 2; |
| 7128 | readonly HIERARCHY_REQUEST_ERR: 3; |
| 7129 | readonly WRONG_DOCUMENT_ERR: 4; |
| 7130 | readonly INVALID_CHARACTER_ERR: 5; |
| 7131 | readonly NO_DATA_ALLOWED_ERR: 6; |
| 7132 | readonly NO_MODIFICATION_ALLOWED_ERR: 7; |
| 7133 | readonly NOT_FOUND_ERR: 8; |
| 7134 | readonly NOT_SUPPORTED_ERR: 9; |
| 7135 | readonly INUSE_ATTRIBUTE_ERR: 10; |
| 7136 | readonly INVALID_STATE_ERR: 11; |
| 7137 | readonly SYNTAX_ERR: 12; |
| 7138 | readonly INVALID_MODIFICATION_ERR: 13; |
| 7139 | readonly NAMESPACE_ERR: 14; |
| 7140 | readonly INVALID_ACCESS_ERR: 15; |
| 7141 | readonly VALIDATION_ERR: 16; |
| 7142 | readonly TYPE_MISMATCH_ERR: 17; |
| 7143 | readonly SECURITY_ERR: 18; |
| 7144 | readonly NETWORK_ERR: 19; |
| 7145 | readonly ABORT_ERR: 20; |
| 7146 | readonly URL_MISMATCH_ERR: 21; |
| 7147 | readonly QUOTA_EXCEEDED_ERR: 22; |
| 7148 | readonly TIMEOUT_ERR: 23; |
| 7149 | readonly INVALID_NODE_TYPE_ERR: 24; |
| 7150 | readonly DATA_CLONE_ERR: 25; |
| 7151 | } |
| 7152 | |
| 7153 | /** @category Platform */ |
| 7154 | declare var DOMException: { |
| 7155 | readonly prototype: DOMException; |
| 7156 | new (message?: string, name?: string): DOMException; |
| 7157 | readonly INDEX_SIZE_ERR: 1; |
| 7158 | readonly DOMSTRING_SIZE_ERR: 2; |
| 7159 | readonly HIERARCHY_REQUEST_ERR: 3; |
| 7160 | readonly WRONG_DOCUMENT_ERR: 4; |
| 7161 | readonly INVALID_CHARACTER_ERR: 5; |
| 7162 | readonly NO_DATA_ALLOWED_ERR: 6; |
| 7163 | readonly NO_MODIFICATION_ALLOWED_ERR: 7; |
| 7164 | readonly NOT_FOUND_ERR: 8; |
| 7165 | readonly NOT_SUPPORTED_ERR: 9; |
| 7166 | readonly INUSE_ATTRIBUTE_ERR: 10; |
| 7167 | readonly INVALID_STATE_ERR: 11; |
| 7168 | readonly SYNTAX_ERR: 12; |
| 7169 | readonly INVALID_MODIFICATION_ERR: 13; |
| 7170 | readonly NAMESPACE_ERR: 14; |
| 7171 | readonly INVALID_ACCESS_ERR: 15; |
| 7172 | readonly VALIDATION_ERR: 16; |
| 7173 | readonly TYPE_MISMATCH_ERR: 17; |
| 7174 | readonly SECURITY_ERR: 18; |
| 7175 | readonly NETWORK_ERR: 19; |
| 7176 | readonly ABORT_ERR: 20; |
| 7177 | readonly URL_MISMATCH_ERR: 21; |
| 7178 | readonly QUOTA_EXCEEDED_ERR: 22; |
| 7179 | readonly TIMEOUT_ERR: 23; |
| 7180 | readonly INVALID_NODE_TYPE_ERR: 24; |
| 7181 | readonly DATA_CLONE_ERR: 25; |
| 7182 | }; |
| 7183 | |
| 7184 | /** @category Events */ |
| 7185 | declare interface EventInit { |
| 7186 | bubbles?: boolean; |
| 7187 | cancelable?: boolean; |
| 7188 | composed?: boolean; |
| 7189 | } |
| 7190 | |
| 7191 | /** An event which takes place in the DOM. |
| 7192 | * |
| 7193 | * @category Events |
| 7194 | */ |
| 7195 | declare interface Event { |
| 7196 | /** Returns true or false depending on how event was initialized. True if |
| 7197 | * event goes through its target's ancestors in reverse tree order, and |
| 7198 | * false otherwise. */ |
| 7199 | readonly bubbles: boolean; |
| 7200 | cancelBubble: boolean; |
| 7201 | /** Returns true or false depending on how event was initialized. Its return |
| 7202 | * value does not always carry meaning, but true can indicate that part of the |
| 7203 | * operation during which event was dispatched, can be canceled by invoking |
| 7204 | * the preventDefault() method. */ |
| 7205 | readonly cancelable: boolean; |
| 7206 | /** Returns true or false depending on how event was initialized. True if |
| 7207 | * event invokes listeners past a ShadowRoot node that is the root of its |
| 7208 | * target, and false otherwise. */ |
| 7209 | readonly composed: boolean; |
| 7210 | /** Returns the object whose event listener's callback is currently being |
| 7211 | * invoked. */ |
| 7212 | readonly currentTarget: EventTarget | null; |
| 7213 | /** Returns true if preventDefault() was invoked successfully to indicate |
| 7214 | * cancellation, and false otherwise. */ |
| 7215 | readonly defaultPrevented: boolean; |
| 7216 | /** Returns the event's phase, which is one of NONE, CAPTURING_PHASE, |
| 7217 | * AT_TARGET, and BUBBLING_PHASE. */ |
| 7218 | readonly eventPhase: number; |
| 7219 | /** Returns true if event was dispatched by the user agent, and false |
| 7220 | * otherwise. */ |
| 7221 | readonly isTrusted: boolean; |
| 7222 | /** Returns the object to which event is dispatched (its target). */ |
| 7223 | readonly target: EventTarget | null; |
| 7224 | /** Returns the event's timestamp as the number of milliseconds measured |
| 7225 | * relative to the time origin. */ |
| 7226 | readonly timeStamp: number; |
| 7227 | /** Returns the type of event, e.g. "click", "hashchange", or "submit". */ |
| 7228 | readonly type: string; |
| 7229 | /** Returns the invocation target objects of event's path (objects on which |
| 7230 | * listeners will be invoked), except for any nodes in shadow trees of which |
| 7231 | * the shadow root's mode is "closed" that are not reachable from event's |
| 7232 | * currentTarget. */ |
| 7233 | composedPath(): EventTarget[]; |
| 7234 | /** If invoked when the cancelable attribute value is true, and while |
| 7235 | * executing a listener for the event with passive set to false, signals to |
| 7236 | * the operation that caused event to be dispatched that it needs to be |
| 7237 | * canceled. */ |
| 7238 | preventDefault(): void; |
| 7239 | /** Invoking this method prevents event from reaching any registered event |
| 7240 | * listeners after the current one finishes running and, when dispatched in a |
| 7241 | * tree, also prevents event from reaching any other objects. */ |
| 7242 | stopImmediatePropagation(): void; |
| 7243 | /** When dispatched in a tree, invoking this method prevents event from |
| 7244 | * reaching any objects other than the current object. */ |
| 7245 | stopPropagation(): void; |
| 7246 | readonly AT_TARGET: number; |
| 7247 | readonly BUBBLING_PHASE: number; |
| 7248 | readonly CAPTURING_PHASE: number; |
| 7249 | readonly NONE: number; |
| 7250 | } |
| 7251 | |
| 7252 | /** An event which takes place in the DOM. |
| 7253 | * |
| 7254 | * @category Events |
| 7255 | */ |
| 7256 | declare var Event: { |
| 7257 | readonly prototype: Event; |
| 7258 | new (type: string, eventInitDict?: EventInit): Event; |
| 7259 | readonly AT_TARGET: number; |
| 7260 | readonly BUBBLING_PHASE: number; |
| 7261 | readonly CAPTURING_PHASE: number; |
| 7262 | readonly NONE: number; |
| 7263 | }; |
| 7264 | |
| 7265 | /** |
| 7266 | * EventTarget is a DOM interface implemented by objects that can receive events |
| 7267 | * and may have listeners for them. |
| 7268 | * |
| 7269 | * @category Events |
| 7270 | */ |
| 7271 | declare interface EventTarget { |
| 7272 | /** Appends an event listener for events whose type attribute value is type. |
| 7273 | * The callback argument sets the callback that will be invoked when the event |
| 7274 | * is dispatched. |
| 7275 | * |
| 7276 | * The options argument sets listener-specific options. For compatibility this |
| 7277 | * can be a boolean, in which case the method behaves exactly as if the value |
| 7278 | * was specified as options's capture. |
| 7279 | * |
| 7280 | * When set to true, options's capture prevents callback from being invoked |
| 7281 | * when the event's eventPhase attribute value is BUBBLING_PHASE. When false |
| 7282 | * (or not present), callback will not be invoked when event's eventPhase |
| 7283 | * attribute value is CAPTURING_PHASE. Either way, callback will be invoked if |
| 7284 | * event's eventPhase attribute value is AT_TARGET. |
| 7285 | * |
| 7286 | * When set to true, options's passive indicates that the callback will not |
| 7287 | * cancel the event by invoking preventDefault(). This is used to enable |
| 7288 | * performance optimizations described in § 2.8 Observing event listeners. |
| 7289 | * |
| 7290 | * When set to true, options's once indicates that the callback will only be |
| 7291 | * invoked once after which the event listener will be removed. |
| 7292 | * |
| 7293 | * The event listener is appended to target's event listener list and is not |
| 7294 | * appended if it has the same type, callback, and capture. */ |
| 7295 | addEventListener( |
| 7296 | type: string, |
| 7297 | listener: EventListenerOrEventListenerObject | null, |
| 7298 | options?: boolean | AddEventListenerOptions, |
| 7299 | ): void; |
| 7300 | /** Dispatches a synthetic event to event target and returns true if either |
| 7301 | * event's cancelable attribute value is false or its preventDefault() method |
| 7302 | * was not invoked, and false otherwise. */ |
| 7303 | dispatchEvent(event: Event): boolean; |
| 7304 | /** Removes the event listener in target's event listener list with the same |
| 7305 | * type, callback, and options. */ |
| 7306 | removeEventListener( |
| 7307 | type: string, |
| 7308 | callback: EventListenerOrEventListenerObject | null, |
| 7309 | options?: EventListenerOptions | boolean, |
| 7310 | ): void; |
| 7311 | } |
| 7312 | |
| 7313 | /** |
| 7314 | * EventTarget is a DOM interface implemented by objects that can receive events |
| 7315 | * and may have listeners for them. |
| 7316 | * |
| 7317 | * @category Events |
| 7318 | */ |
| 7319 | declare var EventTarget: { |
| 7320 | readonly prototype: EventTarget; |
| 7321 | new (): EventTarget; |
| 7322 | }; |
| 7323 | |
| 7324 | /** @category Events */ |
| 7325 | declare interface EventListener { |
| 7326 | (evt: Event): void | Promise<void>; |
| 7327 | } |
| 7328 | |
| 7329 | /** @category Events */ |
| 7330 | declare interface EventListenerObject { |
| 7331 | handleEvent(evt: Event): void | Promise<void>; |
| 7332 | } |
| 7333 | |
| 7334 | /** @category Events */ |
| 7335 | declare type EventListenerOrEventListenerObject = |
| 7336 | | EventListener |
| 7337 | | EventListenerObject; |
| 7338 | |
| 7339 | /** @category Events */ |
| 7340 | declare interface AddEventListenerOptions extends EventListenerOptions { |
| 7341 | once?: boolean; |
| 7342 | passive?: boolean; |
| 7343 | signal?: AbortSignal; |
| 7344 | } |
| 7345 | |
| 7346 | /** @category Events */ |
| 7347 | declare interface EventListenerOptions { |
| 7348 | capture?: boolean; |
| 7349 | } |
| 7350 | |
| 7351 | /** @category Events */ |
| 7352 | declare interface ProgressEventInit extends EventInit { |
| 7353 | lengthComputable?: boolean; |
| 7354 | loaded?: number; |
| 7355 | total?: number; |
| 7356 | } |
| 7357 | |
| 7358 | /** Events measuring progress of an underlying process, like an HTTP request |
| 7359 | * (for an XMLHttpRequest, or the loading of the underlying resource of an |
| 7360 | * <img>, <audio>, <video>, <style> or <link>). |
| 7361 | * |
| 7362 | * @category Events |
| 7363 | */ |
| 7364 | declare interface ProgressEvent<T extends EventTarget = EventTarget> |
| 7365 | extends Event { |
| 7366 | readonly lengthComputable: boolean; |
| 7367 | readonly loaded: number; |
| 7368 | readonly target: T | null; |
| 7369 | readonly total: number; |
| 7370 | } |
| 7371 | |
| 7372 | /** Events measuring progress of an underlying process, like an HTTP request |
| 7373 | * (for an XMLHttpRequest, or the loading of the underlying resource of an |
| 7374 | * <img>, <audio>, <video>, <style> or <link>). |
| 7375 | * |
| 7376 | * @category Events |
| 7377 | */ |
| 7378 | declare var ProgressEvent: { |
| 7379 | readonly prototype: ProgressEvent; |
| 7380 | new (type: string, eventInitDict?: ProgressEventInit): ProgressEvent; |
| 7381 | }; |
| 7382 | |
| 7383 | /** Decodes a string of data which has been encoded using base-64 encoding. |
| 7384 | * |
| 7385 | * ``` |
| 7386 | * console.log(atob("aGVsbG8gd29ybGQ=")); // outputs 'hello world' |
| 7387 | * ``` |
| 7388 | * |
| 7389 | * @category Encoding |
| 7390 | */ |
| 7391 | declare function atob(s: string): string; |
| 7392 | |
| 7393 | /** Creates a base-64 ASCII encoded string from the input string. |
| 7394 | * |
| 7395 | * ``` |
| 7396 | * console.log(btoa("hello world")); // outputs "aGVsbG8gd29ybGQ=" |
| 7397 | * ``` |
| 7398 | * |
| 7399 | * @category Encoding |
| 7400 | */ |
| 7401 | declare function btoa(s: string): string; |
| 7402 | |
| 7403 | /** @category Encoding */ |
| 7404 | declare interface TextDecoderOptions { |
| 7405 | fatal?: boolean; |
| 7406 | ignoreBOM?: boolean; |
| 7407 | } |
| 7408 | |
| 7409 | /** @category Encoding */ |
| 7410 | declare interface TextDecodeOptions { |
| 7411 | stream?: boolean; |
| 7412 | } |
| 7413 | |
| 7414 | /** @category Encoding */ |
| 7415 | declare interface TextDecoder { |
| 7416 | /** Returns encoding's name, lowercased. */ |
| 7417 | readonly encoding: string; |
| 7418 | /** Returns `true` if error mode is "fatal", and `false` otherwise. */ |
| 7419 | readonly fatal: boolean; |
| 7420 | /** Returns `true` if ignore BOM flag is set, and `false` otherwise. */ |
| 7421 | readonly ignoreBOM: boolean; |
| 7422 | |
| 7423 | /** Returns the result of running encoding's decoder. */ |
| 7424 | decode(input?: BufferSource, options?: TextDecodeOptions): string; |
| 7425 | } |
| 7426 | |
| 7427 | /** @category Encoding */ |
| 7428 | declare var TextDecoder: { |
| 7429 | readonly prototype: TextDecoder; |
| 7430 | new (label?: string, options?: TextDecoderOptions): TextDecoder; |
| 7431 | }; |
| 7432 | |
| 7433 | /** @category Encoding */ |
| 7434 | declare interface TextEncoderEncodeIntoResult { |
| 7435 | read: number; |
| 7436 | written: number; |
| 7437 | } |
| 7438 | |
| 7439 | /** @category Encoding */ |
| 7440 | declare interface TextEncoder { |
| 7441 | /** Returns "utf-8". */ |
| 7442 | readonly encoding: "utf-8"; |
| 7443 | /** Returns the result of running UTF-8's encoder. */ |
| 7444 | encode(input?: string): Uint8Array; |
| 7445 | encodeInto(input: string, dest: Uint8Array): TextEncoderEncodeIntoResult; |
| 7446 | } |
| 7447 | |
| 7448 | /** @category Encoding */ |
| 7449 | declare var TextEncoder: { |
| 7450 | readonly prototype: TextEncoder; |
| 7451 | new (): TextEncoder; |
| 7452 | }; |
| 7453 | |
| 7454 | /** @category Encoding */ |
| 7455 | declare interface TextDecoderStream { |
| 7456 | /** Returns encoding's name, lowercased. */ |
| 7457 | readonly encoding: string; |
| 7458 | /** Returns `true` if error mode is "fatal", and `false` otherwise. */ |
| 7459 | readonly fatal: boolean; |
| 7460 | /** Returns `true` if ignore BOM flag is set, and `false` otherwise. */ |
| 7461 | readonly ignoreBOM: boolean; |
| 7462 | readonly readable: ReadableStream<string>; |
| 7463 | readonly writable: WritableStream<BufferSource>; |
| 7464 | readonly [Symbol.toStringTag]: string; |
| 7465 | } |
| 7466 | |
| 7467 | /** @category Encoding */ |
| 7468 | declare var TextDecoderStream: { |
| 7469 | readonly prototype: TextDecoderStream; |
| 7470 | new (label?: string, options?: TextDecoderOptions): TextDecoderStream; |
| 7471 | }; |
| 7472 | |
| 7473 | /** @category Encoding */ |
| 7474 | declare interface TextEncoderStream { |
| 7475 | /** Returns "utf-8". */ |
| 7476 | readonly encoding: "utf-8"; |
| 7477 | readonly readable: ReadableStream<Uint8Array>; |
| 7478 | readonly writable: WritableStream<string>; |
| 7479 | readonly [Symbol.toStringTag]: string; |
| 7480 | } |
| 7481 | |
| 7482 | /** @category Encoding */ |
| 7483 | declare var TextEncoderStream: { |
| 7484 | readonly prototype: TextEncoderStream; |
| 7485 | new (): TextEncoderStream; |
| 7486 | }; |
| 7487 | |
| 7488 | /** A controller object that allows you to abort one or more DOM requests as and |
| 7489 | * when desired. |
| 7490 | * |
| 7491 | * @category Platform |
| 7492 | */ |
| 7493 | declare interface AbortController { |
| 7494 | /** Returns the AbortSignal object associated with this object. */ |
| 7495 | readonly signal: AbortSignal; |
| 7496 | /** Invoking this method will set this object's AbortSignal's aborted flag and |
| 7497 | * signal to any observers that the associated activity is to be aborted. */ |
| 7498 | abort(reason?: any): void; |
| 7499 | } |
| 7500 | |
| 7501 | /** A controller object that allows you to abort one or more DOM requests as and |
| 7502 | * when desired. |
| 7503 | * |
| 7504 | * @category Platform |
| 7505 | */ |
| 7506 | declare var AbortController: { |
| 7507 | readonly prototype: AbortController; |
| 7508 | new (): AbortController; |
| 7509 | }; |
| 7510 | |
| 7511 | /** @category Platform */ |
| 7512 | declare interface AbortSignalEventMap { |
| 7513 | abort: Event; |
| 7514 | } |
| 7515 | |
| 7516 | /** A signal object that allows you to communicate with a DOM request (such as a |
| 7517 | * Fetch) and abort it if required via an AbortController object. |
| 7518 | * |
| 7519 | * @category Platform |
| 7520 | */ |
| 7521 | declare interface AbortSignal extends EventTarget { |
| 7522 | /** Returns true if this AbortSignal's AbortController has signaled to abort, |
| 7523 | * and false otherwise. */ |
| 7524 | readonly aborted: boolean; |
| 7525 | readonly reason: any; |
| 7526 | onabort: ((this: AbortSignal, ev: Event) => any) | null; |
| 7527 | addEventListener<K extends keyof AbortSignalEventMap>( |
| 7528 | type: K, |
| 7529 | listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, |
| 7530 | options?: boolean | AddEventListenerOptions, |
| 7531 | ): void; |
| 7532 | addEventListener( |
| 7533 | type: string, |
| 7534 | listener: EventListenerOrEventListenerObject, |
| 7535 | options?: boolean | AddEventListenerOptions, |
| 7536 | ): void; |
| 7537 | removeEventListener<K extends keyof AbortSignalEventMap>( |
| 7538 | type: K, |
| 7539 | listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, |
| 7540 | options?: boolean | EventListenerOptions, |
| 7541 | ): void; |
| 7542 | removeEventListener( |
| 7543 | type: string, |
| 7544 | listener: EventListenerOrEventListenerObject, |
| 7545 | options?: boolean | EventListenerOptions, |
| 7546 | ): void; |
| 7547 | |
| 7548 | /** Throws this AbortSignal's abort reason, if its AbortController has |
| 7549 | * signaled to abort; otherwise, does nothing. */ |
| 7550 | throwIfAborted(): void; |
| 7551 | } |
| 7552 | |
| 7553 | /** @category Platform */ |
| 7554 | declare var AbortSignal: { |
| 7555 | readonly prototype: AbortSignal; |
| 7556 | new (): never; |
| 7557 | abort(reason?: any): AbortSignal; |
| 7558 | any(signals: AbortSignal[]): AbortSignal; |
| 7559 | timeout(milliseconds: number): AbortSignal; |
| 7560 | }; |
| 7561 | |
| 7562 | /** @category File */ |
| 7563 | declare interface FileReaderEventMap { |
| 7564 | "abort": ProgressEvent<FileReader>; |
| 7565 | "error": ProgressEvent<FileReader>; |
| 7566 | "load": ProgressEvent<FileReader>; |
| 7567 | "loadend": ProgressEvent<FileReader>; |
| 7568 | "loadstart": ProgressEvent<FileReader>; |
| 7569 | "progress": ProgressEvent<FileReader>; |
| 7570 | } |
| 7571 | |
| 7572 | /** Lets web applications asynchronously read the contents of files (or raw data |
| 7573 | * buffers) stored on the user's computer, using File or Blob objects to specify |
| 7574 | * the file or data to read. |
| 7575 | * |
| 7576 | * @category File |
| 7577 | */ |
| 7578 | declare interface FileReader extends EventTarget { |
| 7579 | readonly error: DOMException | null; |
| 7580 | onabort: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null; |
| 7581 | onerror: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null; |
| 7582 | onload: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null; |
| 7583 | onloadend: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null; |
| 7584 | onloadstart: |
| 7585 | | ((this: FileReader, ev: ProgressEvent<FileReader>) => any) |
| 7586 | | null; |
| 7587 | onprogress: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null; |
| 7588 | readonly readyState: number; |
| 7589 | readonly result: string | ArrayBuffer | null; |
| 7590 | abort(): void; |
| 7591 | readAsArrayBuffer(blob: Blob): void; |
| 7592 | readAsBinaryString(blob: Blob): void; |
| 7593 | readAsDataURL(blob: Blob): void; |
| 7594 | readAsText(blob: Blob, encoding?: string): void; |
| 7595 | readonly DONE: number; |
| 7596 | readonly EMPTY: number; |
| 7597 | readonly LOADING: number; |
| 7598 | addEventListener<K extends keyof FileReaderEventMap>( |
| 7599 | type: K, |
| 7600 | listener: (this: FileReader, ev: FileReaderEventMap[K]) => any, |
| 7601 | options?: boolean | AddEventListenerOptions, |
| 7602 | ): void; |
| 7603 | addEventListener( |
| 7604 | type: string, |
| 7605 | listener: EventListenerOrEventListenerObject, |
| 7606 | options?: boolean | AddEventListenerOptions, |
| 7607 | ): void; |
| 7608 | removeEventListener<K extends keyof FileReaderEventMap>( |
| 7609 | type: K, |
| 7610 | listener: (this: FileReader, ev: FileReaderEventMap[K]) => any, |
| 7611 | options?: boolean | EventListenerOptions, |
| 7612 | ): void; |
| 7613 | removeEventListener( |
| 7614 | type: string, |
| 7615 | listener: EventListenerOrEventListenerObject, |
| 7616 | options?: boolean | EventListenerOptions, |
| 7617 | ): void; |
| 7618 | } |
| 7619 | |
| 7620 | /** @category File */ |
| 7621 | declare var FileReader: { |
| 7622 | readonly prototype: FileReader; |
| 7623 | new (): FileReader; |
| 7624 | readonly DONE: number; |
| 7625 | readonly EMPTY: number; |
| 7626 | readonly LOADING: number; |
| 7627 | }; |
| 7628 | |
| 7629 | /** @category File */ |
| 7630 | declare type BlobPart = BufferSource | Blob | string; |
| 7631 | |
| 7632 | /** @category File */ |
| 7633 | declare interface BlobPropertyBag { |
| 7634 | type?: string; |
| 7635 | endings?: "transparent" | "native"; |
| 7636 | } |
| 7637 | |
| 7638 | /** A file-like object of immutable, raw data. Blobs represent data that isn't |
| 7639 | * necessarily in a JavaScript-native format. The File interface is based on |
| 7640 | * Blob, inheriting blob functionality and expanding it to support files on the |
| 7641 | * user's system. |
| 7642 | * |
| 7643 | * @category File |
| 7644 | */ |
| 7645 | declare interface Blob { |
| 7646 | readonly size: number; |
| 7647 | readonly type: string; |
| 7648 | arrayBuffer(): Promise<ArrayBuffer>; |
| 7649 | bytes(): Promise<Uint8Array>; |
| 7650 | slice(start?: number, end?: number, contentType?: string): Blob; |
| 7651 | stream(): ReadableStream<Uint8Array>; |
| 7652 | text(): Promise<string>; |
| 7653 | } |
| 7654 | |
| 7655 | /** A file-like object of immutable, raw data. Blobs represent data that isn't |
| 7656 | * necessarily in a JavaScript-native format. The File interface is based on |
| 7657 | * Blob, inheriting blob functionality and expanding it to support files on the |
| 7658 | * user's system. |
| 7659 | * |
| 7660 | * @category File |
| 7661 | */ |
| 7662 | declare var Blob: { |
| 7663 | readonly prototype: Blob; |
| 7664 | new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob; |
| 7665 | }; |
| 7666 | |
| 7667 | /** @category File */ |
| 7668 | declare interface FilePropertyBag extends BlobPropertyBag { |
| 7669 | lastModified?: number; |
| 7670 | } |
| 7671 | |
| 7672 | /** Provides information about files and allows JavaScript in a web page to |
| 7673 | * access their content. |
| 7674 | * |
| 7675 | * @category File |
| 7676 | */ |
| 7677 | declare interface File extends Blob { |
| 7678 | readonly lastModified: number; |
| 7679 | readonly name: string; |
| 7680 | } |
| 7681 | |
| 7682 | /** Provides information about files and allows JavaScript in a web page to |
| 7683 | * access their content. |
| 7684 | * |
| 7685 | * @category File |
| 7686 | */ |
| 7687 | declare var File: { |
| 7688 | readonly prototype: File; |
| 7689 | new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File; |
| 7690 | }; |
| 7691 | |
| 7692 | /** @category Streams */ |
| 7693 | declare interface ReadableStreamDefaultReadDoneResult { |
| 7694 | done: true; |
| 7695 | value?: undefined; |
| 7696 | } |
| 7697 | |
| 7698 | /** @category Streams */ |
| 7699 | declare interface ReadableStreamDefaultReadValueResult<T> { |
| 7700 | done: false; |
| 7701 | value: T; |
| 7702 | } |
| 7703 | |
| 7704 | /** @category Streams */ |
| 7705 | declare type ReadableStreamDefaultReadResult<T> = |
| 7706 | | ReadableStreamDefaultReadValueResult<T> |
| 7707 | | ReadableStreamDefaultReadDoneResult; |
| 7708 | |
| 7709 | /** @category Streams */ |
| 7710 | declare interface ReadableStreamDefaultReader<R = any> { |
| 7711 | readonly closed: Promise<void>; |
| 7712 | cancel(reason?: any): Promise<void>; |
| 7713 | read(): Promise<ReadableStreamDefaultReadResult<R>>; |
| 7714 | releaseLock(): void; |
| 7715 | } |
| 7716 | |
| 7717 | /** @category Streams */ |
| 7718 | declare var ReadableStreamDefaultReader: { |
| 7719 | readonly prototype: ReadableStreamDefaultReader; |
| 7720 | new <R>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>; |
| 7721 | }; |
| 7722 | |
| 7723 | /** @category Streams */ |
| 7724 | declare interface ReadableStreamBYOBReadDoneResult<V extends ArrayBufferView> { |
| 7725 | done: true; |
| 7726 | value?: V; |
| 7727 | } |
| 7728 | |
| 7729 | /** @category Streams */ |
| 7730 | declare interface ReadableStreamBYOBReadValueResult<V extends ArrayBufferView> { |
| 7731 | done: false; |
| 7732 | value: V; |
| 7733 | } |
| 7734 | |
| 7735 | /** @category Streams */ |
| 7736 | declare type ReadableStreamBYOBReadResult<V extends ArrayBufferView> = |
| 7737 | | ReadableStreamBYOBReadDoneResult<V> |
| 7738 | | ReadableStreamBYOBReadValueResult<V>; |
| 7739 | |
| 7740 | /** @category Streams */ |
| 7741 | declare interface ReadableStreamBYOBReaderReadOptions { |
| 7742 | min?: number; |
| 7743 | } |
| 7744 | |
| 7745 | /** @category Streams */ |
| 7746 | declare interface ReadableStreamBYOBReader { |
| 7747 | readonly closed: Promise<void>; |
| 7748 | cancel(reason?: any): Promise<void>; |
| 7749 | read<V extends ArrayBufferView>( |
| 7750 | view: V, |
| 7751 | options?: ReadableStreamBYOBReaderReadOptions, |
| 7752 | ): Promise<ReadableStreamBYOBReadResult<V>>; |
| 7753 | releaseLock(): void; |
| 7754 | } |
| 7755 | |
| 7756 | /** @category Streams */ |
| 7757 | declare var ReadableStreamBYOBReader: { |
| 7758 | readonly prototype: ReadableStreamBYOBReader; |
| 7759 | new (stream: ReadableStream<Uint8Array>): ReadableStreamBYOBReader; |
| 7760 | }; |
| 7761 | |
| 7762 | /** @category Streams */ |
| 7763 | declare interface ReadableStreamBYOBRequest { |
| 7764 | readonly view: ArrayBufferView | null; |
| 7765 | respond(bytesWritten: number): void; |
| 7766 | respondWithNewView(view: ArrayBufferView): void; |
| 7767 | } |
| 7768 | |
| 7769 | /** @category Streams */ |
| 7770 | declare var ReadableStreamBYOBRequest: { |
| 7771 | readonly prototype: ReadableStreamBYOBRequest; |
| 7772 | new (): never; |
| 7773 | }; |
| 7774 | |
| 7775 | /** @category Streams */ |
| 7776 | declare interface ReadableByteStreamControllerCallback { |
| 7777 | (controller: ReadableByteStreamController): void | PromiseLike<void>; |
| 7778 | } |
| 7779 | |
| 7780 | /** @category Streams */ |
| 7781 | declare interface UnderlyingByteSource { |
| 7782 | autoAllocateChunkSize?: number; |
| 7783 | cancel?: ReadableStreamErrorCallback; |
| 7784 | pull?: ReadableByteStreamControllerCallback; |
| 7785 | start?: ReadableByteStreamControllerCallback; |
| 7786 | type: "bytes"; |
| 7787 | } |
| 7788 | |
| 7789 | /** @category Streams */ |
| 7790 | declare interface UnderlyingSink<W = any> { |
| 7791 | abort?: WritableStreamErrorCallback; |
| 7792 | close?: WritableStreamDefaultControllerCloseCallback; |
| 7793 | start?: WritableStreamDefaultControllerStartCallback; |
| 7794 | type?: undefined; |
| 7795 | write?: WritableStreamDefaultControllerWriteCallback<W>; |
| 7796 | } |
| 7797 | |
| 7798 | /** @category Streams */ |
| 7799 | declare interface UnderlyingSource<R = any> { |
| 7800 | cancel?: ReadableStreamErrorCallback; |
| 7801 | pull?: ReadableStreamDefaultControllerCallback<R>; |
| 7802 | start?: ReadableStreamDefaultControllerCallback<R>; |
| 7803 | type?: undefined; |
| 7804 | } |
| 7805 | |
| 7806 | /** @category Streams */ |
| 7807 | declare interface ReadableStreamErrorCallback { |
| 7808 | (reason: any): void | PromiseLike<void>; |
| 7809 | } |
| 7810 | |
| 7811 | /** @category Streams */ |
| 7812 | declare interface ReadableStreamDefaultControllerCallback<R> { |
| 7813 | (controller: ReadableStreamDefaultController<R>): void | PromiseLike<void>; |
| 7814 | } |
| 7815 | |
| 7816 | /** @category Streams */ |
| 7817 | declare interface ReadableStreamDefaultController<R = any> { |
| 7818 | readonly desiredSize: number | null; |
| 7819 | close(): void; |
| 7820 | enqueue(chunk: R): void; |
| 7821 | error(error?: any): void; |
| 7822 | } |
| 7823 | |
| 7824 | /** @category Streams */ |
| 7825 | declare var ReadableStreamDefaultController: { |
| 7826 | readonly prototype: ReadableStreamDefaultController; |
| 7827 | new (): never; |
| 7828 | }; |
| 7829 | |
| 7830 | /** @category Streams */ |
| 7831 | declare interface ReadableByteStreamController { |
| 7832 | readonly byobRequest: ReadableStreamBYOBRequest | null; |
| 7833 | readonly desiredSize: number | null; |
| 7834 | close(): void; |
| 7835 | enqueue(chunk: ArrayBufferView): void; |
| 7836 | error(error?: any): void; |
| 7837 | } |
| 7838 | |
| 7839 | /** @category Streams */ |
| 7840 | declare var ReadableByteStreamController: { |
| 7841 | readonly prototype: ReadableByteStreamController; |
| 7842 | new (): never; |
| 7843 | }; |
| 7844 | |
| 7845 | /** @category Streams */ |
| 7846 | declare interface PipeOptions { |
| 7847 | preventAbort?: boolean; |
| 7848 | preventCancel?: boolean; |
| 7849 | preventClose?: boolean; |
| 7850 | signal?: AbortSignal; |
| 7851 | } |
| 7852 | |
| 7853 | /** @category Streams */ |
| 7854 | declare interface QueuingStrategySizeCallback<T = any> { |
| 7855 | (chunk: T): number; |
| 7856 | } |
| 7857 | |
| 7858 | /** @category Streams */ |
| 7859 | declare interface QueuingStrategy<T = any> { |
| 7860 | highWaterMark?: number; |
| 7861 | size?: QueuingStrategySizeCallback<T>; |
| 7862 | } |
| 7863 | |
| 7864 | /** This Streams API interface provides a built-in byte length queuing strategy |
| 7865 | * that can be used when constructing streams. |
| 7866 | * |
| 7867 | * @category Streams |
| 7868 | */ |
| 7869 | declare interface CountQueuingStrategy extends QueuingStrategy { |
| 7870 | highWaterMark: number; |
| 7871 | size(chunk: any): 1; |
| 7872 | } |
| 7873 | |
| 7874 | /** @category Streams */ |
| 7875 | declare var CountQueuingStrategy: { |
| 7876 | readonly prototype: CountQueuingStrategy; |
| 7877 | new (options: { highWaterMark: number }): CountQueuingStrategy; |
| 7878 | }; |
| 7879 | |
| 7880 | /** @category Streams */ |
| 7881 | declare interface ByteLengthQueuingStrategy |
| 7882 | extends QueuingStrategy<ArrayBufferView> { |
| 7883 | highWaterMark: number; |
| 7884 | size(chunk: ArrayBufferView): number; |
| 7885 | } |
| 7886 | |
| 7887 | /** @category Streams */ |
| 7888 | declare var ByteLengthQueuingStrategy: { |
| 7889 | readonly prototype: ByteLengthQueuingStrategy; |
| 7890 | new (options: { highWaterMark: number }): ByteLengthQueuingStrategy; |
| 7891 | }; |
| 7892 | |
| 7893 | /** This Streams API interface represents a readable stream of byte data. The |
| 7894 | * Fetch API offers a concrete instance of a ReadableStream through the body |
| 7895 | * property of a Response object. |
| 7896 | * |
| 7897 | * @category Streams |
| 7898 | */ |
| 7899 | declare interface ReadableStream<R = any> { |
| 7900 | readonly locked: boolean; |
| 7901 | cancel(reason?: any): Promise<void>; |
| 7902 | getReader(options: { mode: "byob" }): ReadableStreamBYOBReader; |
| 7903 | getReader(options?: { mode?: undefined }): ReadableStreamDefaultReader<R>; |
| 7904 | pipeThrough<T>(transform: { |
| 7905 | writable: WritableStream<R>; |
| 7906 | readable: ReadableStream<T>; |
| 7907 | }, options?: PipeOptions): ReadableStream<T>; |
| 7908 | pipeTo(dest: WritableStream<R>, options?: PipeOptions): Promise<void>; |
| 7909 | tee(): [ReadableStream<R>, ReadableStream<R>]; |
| 7910 | values(options?: { |
| 7911 | preventCancel?: boolean; |
| 7912 | }): AsyncIterableIterator<R>; |
| 7913 | [Symbol.asyncIterator](options?: { |
| 7914 | preventCancel?: boolean; |
| 7915 | }): AsyncIterableIterator<R>; |
| 7916 | } |
| 7917 | |
| 7918 | /** @category Streams */ |
| 7919 | declare var ReadableStream: { |
| 7920 | readonly prototype: ReadableStream; |
| 7921 | new ( |
| 7922 | underlyingSource: UnderlyingByteSource, |
| 7923 | strategy?: { highWaterMark?: number; size?: undefined }, |
| 7924 | ): ReadableStream<Uint8Array>; |
| 7925 | new <R = any>( |
| 7926 | underlyingSource?: UnderlyingSource<R>, |
| 7927 | strategy?: QueuingStrategy<R>, |
| 7928 | ): ReadableStream<R>; |
| 7929 | from<R>( |
| 7930 | asyncIterable: AsyncIterable<R> | Iterable<R | PromiseLike<R>>, |
| 7931 | ): ReadableStream<R>; |
| 7932 | }; |
| 7933 | |
| 7934 | /** @category Streams */ |
| 7935 | declare interface WritableStreamDefaultControllerCloseCallback { |
| 7936 | (): void | PromiseLike<void>; |
| 7937 | } |
| 7938 | |
| 7939 | /** @category Streams */ |
| 7940 | declare interface WritableStreamDefaultControllerStartCallback { |
| 7941 | (controller: WritableStreamDefaultController): void | PromiseLike<void>; |
| 7942 | } |
| 7943 | |
| 7944 | /** @category Streams */ |
| 7945 | declare interface WritableStreamDefaultControllerWriteCallback<W> { |
| 7946 | (chunk: W, controller: WritableStreamDefaultController): |
| 7947 | | void |
| 7948 | | PromiseLike< |
| 7949 | void |
| 7950 | >; |
| 7951 | } |
| 7952 | |
| 7953 | /** @category Streams */ |
| 7954 | declare interface WritableStreamErrorCallback { |
| 7955 | (reason: any): void | PromiseLike<void>; |
| 7956 | } |
| 7957 | |
| 7958 | /** This Streams API interface provides a standard abstraction for writing |
| 7959 | * streaming data to a destination, known as a sink. This object comes with |
| 7960 | * built-in backpressure and queuing. |
| 7961 | * |
| 7962 | * @category Streams |
| 7963 | */ |
| 7964 | declare interface WritableStream<W = any> { |
| 7965 | readonly locked: boolean; |
| 7966 | abort(reason?: any): Promise<void>; |
| 7967 | close(): Promise<void>; |
| 7968 | getWriter(): WritableStreamDefaultWriter<W>; |
| 7969 | } |
| 7970 | |
| 7971 | /** @category Streams */ |
| 7972 | declare var WritableStream: { |
| 7973 | readonly prototype: WritableStream; |
| 7974 | new <W = any>( |
| 7975 | underlyingSink?: UnderlyingSink<W>, |
| 7976 | strategy?: QueuingStrategy<W>, |
| 7977 | ): WritableStream<W>; |
| 7978 | }; |
| 7979 | |
| 7980 | /** This Streams API interface represents a controller allowing control of a |
| 7981 | * WritableStream's state. When constructing a WritableStream, the underlying |
| 7982 | * sink is given a corresponding WritableStreamDefaultController instance to |
| 7983 | * manipulate. |
| 7984 | * |
| 7985 | * @category Streams |
| 7986 | */ |
| 7987 | declare interface WritableStreamDefaultController { |
| 7988 | signal: AbortSignal; |
| 7989 | error(error?: any): void; |
| 7990 | } |
| 7991 | |
| 7992 | /** @category Streams */ |
| 7993 | declare var WritableStreamDefaultController: { |
| 7994 | readonly prototype: WritableStreamDefaultController; |
| 7995 | new (): never; |
| 7996 | }; |
| 7997 | |
| 7998 | /** This Streams API interface is the object returned by |
| 7999 | * WritableStream.getWriter() and once created locks the < writer to the |
| 8000 | * WritableStream ensuring that no other streams can write to the underlying |
| 8001 | * sink. |
| 8002 | * |
| 8003 | * @category Streams |
| 8004 | */ |
| 8005 | declare interface WritableStreamDefaultWriter<W = any> { |
| 8006 | readonly closed: Promise<void>; |
| 8007 | readonly desiredSize: number | null; |
| 8008 | readonly ready: Promise<void>; |
| 8009 | abort(reason?: any): Promise<void>; |
| 8010 | close(): Promise<void>; |
| 8011 | releaseLock(): void; |
| 8012 | write(chunk: W): Promise<void>; |
| 8013 | } |
| 8014 | |
| 8015 | /** @category Streams */ |
| 8016 | declare var WritableStreamDefaultWriter: { |
| 8017 | readonly prototype: WritableStreamDefaultWriter; |
| 8018 | new <W>(stream: WritableStream<W>): WritableStreamDefaultWriter<W>; |
| 8019 | }; |
| 8020 | |
| 8021 | /** @category Streams */ |
| 8022 | declare interface TransformStream<I = any, O = any> { |
| 8023 | readonly readable: ReadableStream<O>; |
| 8024 | readonly writable: WritableStream<I>; |
| 8025 | } |
| 8026 | |
| 8027 | /** @category Streams */ |
| 8028 | declare var TransformStream: { |
| 8029 | readonly prototype: TransformStream; |
| 8030 | new <I = any, O = any>( |
| 8031 | transformer?: Transformer<I, O>, |
| 8032 | writableStrategy?: QueuingStrategy<I>, |
| 8033 | readableStrategy?: QueuingStrategy<O>, |
| 8034 | ): TransformStream<I, O>; |
| 8035 | }; |
| 8036 | |
| 8037 | /** @category Streams */ |
| 8038 | declare interface TransformStreamDefaultController<O = any> { |
| 8039 | readonly desiredSize: number | null; |
| 8040 | enqueue(chunk: O): void; |
| 8041 | error(reason?: any): void; |
| 8042 | terminate(): void; |
| 8043 | } |
| 8044 | |
| 8045 | /** @category Streams */ |
| 8046 | declare var TransformStreamDefaultController: { |
| 8047 | readonly prototype: TransformStreamDefaultController; |
| 8048 | new (): never; |
| 8049 | }; |
| 8050 | |
| 8051 | /** @category Streams */ |
| 8052 | declare interface Transformer<I = any, O = any> { |
| 8053 | flush?: TransformStreamDefaultControllerCallback<O>; |
| 8054 | readableType?: undefined; |
| 8055 | start?: TransformStreamDefaultControllerCallback<O>; |
| 8056 | transform?: TransformStreamDefaultControllerTransformCallback<I, O>; |
| 8057 | cancel?: (reason: any) => Promise<void>; |
| 8058 | writableType?: undefined; |
| 8059 | } |
| 8060 | |
| 8061 | /** @category Streams */ |
| 8062 | declare interface TransformStreamDefaultControllerCallback<O> { |
| 8063 | (controller: TransformStreamDefaultController<O>): void | PromiseLike<void>; |
| 8064 | } |
| 8065 | |
| 8066 | /** @category Streams */ |
| 8067 | declare interface TransformStreamDefaultControllerTransformCallback<I, O> { |
| 8068 | ( |
| 8069 | chunk: I, |
| 8070 | controller: TransformStreamDefaultController<O>, |
| 8071 | ): void | PromiseLike<void>; |
| 8072 | } |
| 8073 | |
| 8074 | /** @category Events */ |
| 8075 | declare interface MessageEventInit<T = any> extends EventInit { |
| 8076 | data?: T; |
| 8077 | origin?: string; |
| 8078 | lastEventId?: string; |
| 8079 | } |
| 8080 | |
| 8081 | /** @category Events */ |
| 8082 | declare interface MessageEvent<T = any> extends Event { |
| 8083 | /** |
| 8084 | * Returns the data of the message. |
| 8085 | */ |
| 8086 | readonly data: T; |
| 8087 | /** |
| 8088 | * Returns the origin of the message, for server-sent events. |
| 8089 | */ |
| 8090 | readonly origin: string; |
| 8091 | /** |
| 8092 | * Returns the last event ID string, for server-sent events. |
| 8093 | */ |
| 8094 | readonly lastEventId: string; |
| 8095 | readonly source: null; |
| 8096 | /** |
| 8097 | * Returns transferred ports. |
| 8098 | */ |
| 8099 | readonly ports: ReadonlyArray<MessagePort>; |
| 8100 | } |
| 8101 | |
| 8102 | /** @category Events */ |
| 8103 | declare var MessageEvent: { |
| 8104 | readonly prototype: MessageEvent; |
| 8105 | new <T>(type: string, eventInitDict?: MessageEventInit<T>): MessageEvent<T>; |
| 8106 | }; |
| 8107 | |
| 8108 | /** @category Events */ |
| 8109 | declare type Transferable = ArrayBuffer | MessagePort; |
| 8110 | |
| 8111 | /** |
| 8112 | * This type has been renamed to StructuredSerializeOptions. Use that type for |
| 8113 | * new code. |
| 8114 | * |
| 8115 | * @deprecated use `StructuredSerializeOptions` instead. |
| 8116 | * @category Events |
| 8117 | */ |
| 8118 | declare type PostMessageOptions = StructuredSerializeOptions; |
| 8119 | |
| 8120 | /** @category Platform */ |
| 8121 | declare interface StructuredSerializeOptions { |
| 8122 | transfer?: Transferable[]; |
| 8123 | } |
| 8124 | |
| 8125 | /** The MessageChannel interface of the Channel Messaging API allows us to |
| 8126 | * create a new message channel and send data through it via its two MessagePort |
| 8127 | * properties. |
| 8128 | * |
| 8129 | * @category Messaging |
| 8130 | */ |
| 8131 | declare interface MessageChannel { |
| 8132 | readonly port1: MessagePort; |
| 8133 | readonly port2: MessagePort; |
| 8134 | } |
| 8135 | |
| 8136 | /** The MessageChannel interface of the Channel Messaging API allows us to |
| 8137 | * create a new message channel and send data through it via its two MessagePort |
| 8138 | * properties. |
| 8139 | * |
| 8140 | * @category Messaging |
| 8141 | */ |
| 8142 | declare var MessageChannel: { |
| 8143 | readonly prototype: MessageChannel; |
| 8144 | new (): MessageChannel; |
| 8145 | }; |
| 8146 | |
| 8147 | /** @category Messaging */ |
| 8148 | declare interface MessagePortEventMap { |
| 8149 | "message": MessageEvent; |
| 8150 | "messageerror": MessageEvent; |
| 8151 | } |
| 8152 | |
| 8153 | /** The MessagePort interface of the Channel Messaging API represents one of the |
| 8154 | * two ports of a MessageChannel, allowing messages to be sent from one port and |
| 8155 | * listening out for them arriving at the other. |
| 8156 | * |
| 8157 | * @category Messaging |
| 8158 | */ |
| 8159 | declare interface MessagePort extends EventTarget { |
| 8160 | onmessage: ((this: MessagePort, ev: MessageEvent) => any) | null; |
| 8161 | onmessageerror: ((this: MessagePort, ev: MessageEvent) => any) | null; |
| 8162 | /** |
| 8163 | * Disconnects the port, so that it is no longer active. |
| 8164 | */ |
| 8165 | close(): void; |
| 8166 | /** |
| 8167 | * Posts a message through the channel. Objects listed in transfer are |
| 8168 | * transferred, not just cloned, meaning that they are no longer usable on the |
| 8169 | * sending side. |
| 8170 | * |
| 8171 | * Throws a "DataCloneError" DOMException if transfer contains duplicate |
| 8172 | * objects or port, or if message could not be cloned. |
| 8173 | */ |
| 8174 | postMessage(message: any, transfer: Transferable[]): void; |
| 8175 | postMessage(message: any, options?: StructuredSerializeOptions): void; |
| 8176 | /** |
| 8177 | * Begins dispatching messages received on the port. This is implicitly called |
| 8178 | * when assigning a value to `this.onmessage`. |
| 8179 | */ |
| 8180 | start(): void; |
| 8181 | addEventListener<K extends keyof MessagePortEventMap>( |
| 8182 | type: K, |
| 8183 | listener: (this: MessagePort, ev: MessagePortEventMap[K]) => any, |
| 8184 | options?: boolean | AddEventListenerOptions, |
| 8185 | ): void; |
| 8186 | addEventListener( |
| 8187 | type: string, |
| 8188 | listener: EventListenerOrEventListenerObject, |
| 8189 | options?: boolean | AddEventListenerOptions, |
| 8190 | ): void; |
| 8191 | removeEventListener<K extends keyof MessagePortEventMap>( |
| 8192 | type: K, |
| 8193 | listener: (this: MessagePort, ev: MessagePortEventMap[K]) => any, |
| 8194 | options?: boolean | EventListenerOptions, |
| 8195 | ): void; |
| 8196 | removeEventListener( |
| 8197 | type: string, |
| 8198 | listener: EventListenerOrEventListenerObject, |
| 8199 | options?: boolean | EventListenerOptions, |
| 8200 | ): void; |
| 8201 | } |
| 8202 | |
| 8203 | /** The MessagePort interface of the Channel Messaging API represents one of the |
| 8204 | * two ports of a MessageChannel, allowing messages to be sent from one port and |
| 8205 | * listening out for them arriving at the other. |
| 8206 | * |
| 8207 | * @category Messaging |
| 8208 | */ |
| 8209 | declare var MessagePort: { |
| 8210 | readonly prototype: MessagePort; |
| 8211 | new (): never; |
| 8212 | }; |
| 8213 | |
| 8214 | /** |
| 8215 | * Creates a deep copy of a given value using the structured clone algorithm. |
| 8216 | * |
| 8217 | * Unlike a shallow copy, a deep copy does not hold the same references as the |
| 8218 | * source object, meaning its properties can be changed without affecting the |
| 8219 | * source. For more details, see |
| 8220 | * [MDN](https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy). |
| 8221 | * |
| 8222 | * Throws a `DataCloneError` if any part of the input value is not |
| 8223 | * serializable. |
| 8224 | * |
| 8225 | * @example |
| 8226 | * ```ts |
| 8227 | * const object = { x: 0, y: 1 }; |
| 8228 | * |
| 8229 | * const deepCopy = structuredClone(object); |
| 8230 | * deepCopy.x = 1; |
| 8231 | * console.log(deepCopy.x, object.x); // 1 0 |
| 8232 | * |
| 8233 | * const shallowCopy = object; |
| 8234 | * shallowCopy.x = 1; |
| 8235 | * // shallowCopy.x is pointing to the same location in memory as object.x |
| 8236 | * console.log(shallowCopy.x, object.x); // 1 1 |
| 8237 | * ``` |
| 8238 | * |
| 8239 | * @category Platform |
| 8240 | */ |
| 8241 | declare function structuredClone<T = any>( |
| 8242 | value: T, |
| 8243 | options?: StructuredSerializeOptions, |
| 8244 | ): T; |
| 8245 | |
| 8246 | /** |
| 8247 | * An API for compressing a stream of data. |
| 8248 | * |
| 8249 | * @example |
| 8250 | * ```ts |
| 8251 | * await Deno.stdin.readable |
| 8252 | * .pipeThrough(new CompressionStream("gzip")) |
| 8253 | * .pipeTo(Deno.stdout.writable); |
| 8254 | * ``` |
| 8255 | * |
| 8256 | * @category Streams |
| 8257 | */ |
| 8258 | declare interface CompressionStream { |
| 8259 | readonly readable: ReadableStream<Uint8Array>; |
| 8260 | readonly writable: WritableStream<Uint8Array>; |
| 8261 | } |
| 8262 | |
| 8263 | /** |
| 8264 | * An API for compressing a stream of data. |
| 8265 | * |
| 8266 | * @example |
| 8267 | * ```ts |
| 8268 | * await Deno.stdin.readable |
| 8269 | * .pipeThrough(new CompressionStream("gzip")) |
| 8270 | * .pipeTo(Deno.stdout.writable); |
| 8271 | * ``` |
| 8272 | * |
| 8273 | * @category Streams |
| 8274 | */ |
| 8275 | declare var CompressionStream: { |
| 8276 | readonly prototype: CompressionStream; |
| 8277 | /** |
| 8278 | * Creates a new `CompressionStream` object which compresses a stream of |
| 8279 | * data. |
| 8280 | * |
| 8281 | * Throws a `TypeError` if the format passed to the constructor is not |
| 8282 | * supported. |
| 8283 | */ |
| 8284 | new (format: string): CompressionStream; |
| 8285 | }; |
| 8286 | |
| 8287 | /** |
| 8288 | * An API for decompressing a stream of data. |
| 8289 | * |
| 8290 | * @example |
| 8291 | * ```ts |
| 8292 | * const input = await Deno.open("./file.txt.gz"); |
| 8293 | * const output = await Deno.create("./file.txt"); |
| 8294 | * |
| 8295 | * await input.readable |
| 8296 | * .pipeThrough(new DecompressionStream("gzip")) |
| 8297 | * .pipeTo(output.writable); |
| 8298 | * ``` |
| 8299 | * |
| 8300 | * @category Streams |
| 8301 | */ |
| 8302 | declare interface DecompressionStream { |
| 8303 | readonly readable: ReadableStream<Uint8Array>; |
| 8304 | readonly writable: WritableStream<Uint8Array>; |
| 8305 | } |
| 8306 | |
| 8307 | /** |
| 8308 | * An API for decompressing a stream of data. |
| 8309 | * |
| 8310 | * @example |
| 8311 | * ```ts |
| 8312 | * const input = await Deno.open("./file.txt.gz"); |
| 8313 | * const output = await Deno.create("./file.txt"); |
| 8314 | * |
| 8315 | * await input.readable |
| 8316 | * .pipeThrough(new DecompressionStream("gzip")) |
| 8317 | * .pipeTo(output.writable); |
| 8318 | * ``` |
| 8319 | * |
| 8320 | * @category Streams |
| 8321 | */ |
| 8322 | declare var DecompressionStream: { |
| 8323 | readonly prototype: DecompressionStream; |
| 8324 | /** |
| 8325 | * Creates a new `DecompressionStream` object which decompresses a stream of |
| 8326 | * data. |
| 8327 | * |
| 8328 | * Throws a `TypeError` if the format passed to the constructor is not |
| 8329 | * supported. |
| 8330 | */ |
| 8331 | new (format: string): DecompressionStream; |
| 8332 | }; |
| 8333 | |
| 8334 | /** Dispatch an uncaught exception. Similar to a synchronous version of: |
| 8335 | * ```ts |
| 8336 | * setTimeout(() => { throw error; }, 0); |
| 8337 | * ``` |
| 8338 | * The error can not be caught with a `try/catch` block. An error event will |
| 8339 | * be dispatched to the global scope. You can prevent the error from being |
| 8340 | * reported to the console with `Event.prototype.preventDefault()`: |
| 8341 | * ```ts |
| 8342 | * addEventListener("error", (event) => { |
| 8343 | * event.preventDefault(); |
| 8344 | * }); |
| 8345 | * reportError(new Error("foo")); // Will not be reported. |
| 8346 | * ``` |
| 8347 | * In Deno, this error will terminate the process if not intercepted like above. |
| 8348 | * |
| 8349 | * @category Platform |
| 8350 | */ |
| 8351 | declare function reportError( |
| 8352 | error: any, |
| 8353 | ): void; |
| 8354 | |
| 8355 | /** @category Platform */ |
| 8356 | declare type PredefinedColorSpace = "srgb" | "display-p3"; |
| 8357 | |
| 8358 | /** @category Platform */ |
| 8359 | declare interface ImageDataSettings { |
| 8360 | readonly colorSpace?: PredefinedColorSpace; |
| 8361 | } |
| 8362 | |
| 8363 | /** @category Platform */ |
| 8364 | declare interface ImageData { |
| 8365 | readonly colorSpace: PredefinedColorSpace; |
| 8366 | readonly data: Uint8ClampedArray; |
| 8367 | readonly height: number; |
| 8368 | readonly width: number; |
| 8369 | } |
| 8370 | |
| 8371 | /** @category Platform */ |
| 8372 | declare var ImageData: { |
| 8373 | prototype: ImageData; |
| 8374 | new (sw: number, sh: number, settings?: ImageDataSettings): ImageData; |
| 8375 | new ( |
| 8376 | data: Uint8ClampedArray, |
| 8377 | sw: number, |
| 8378 | sh?: number, |
| 8379 | settings?: ImageDataSettings, |
| 8380 | ): ImageData; |
| 8381 | }; |
| 8382 | |
| 8383 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 8384 | |
| 8385 | // deno-lint-ignore-file no-explicit-any no-var |
| 8386 | |
| 8387 | /// <reference no-default-lib="true" /> |
| 8388 | /// <reference lib="esnext" /> |
| 8389 | |
| 8390 | /** @category Platform */ |
| 8391 | declare interface DomIterable<K, V> { |
| 8392 | keys(): IterableIterator<K>; |
| 8393 | values(): IterableIterator<V>; |
| 8394 | entries(): IterableIterator<[K, V]>; |
| 8395 | [Symbol.iterator](): IterableIterator<[K, V]>; |
| 8396 | forEach( |
| 8397 | callback: (value: V, key: K, parent: this) => void, |
| 8398 | thisArg?: any, |
| 8399 | ): void; |
| 8400 | } |
| 8401 | |
| 8402 | /** @category Fetch */ |
| 8403 | declare type FormDataEntryValue = File | string; |
| 8404 | |
| 8405 | /** Provides a way to easily construct a set of key/value pairs representing |
| 8406 | * form fields and their values, which can then be easily sent using the |
| 8407 | * XMLHttpRequest.send() method. It uses the same format a form would use if the |
| 8408 | * encoding type were set to "multipart/form-data". |
| 8409 | * |
| 8410 | * @category Fetch |
| 8411 | */ |
| 8412 | declare interface FormData extends DomIterable<string, FormDataEntryValue> { |
| 8413 | append(name: string, value: string | Blob, fileName?: string): void; |
| 8414 | delete(name: string): void; |
| 8415 | get(name: string): FormDataEntryValue | null; |
| 8416 | getAll(name: string): FormDataEntryValue[]; |
| 8417 | has(name: string): boolean; |
| 8418 | set(name: string, value: string | Blob, fileName?: string): void; |
| 8419 | } |
| 8420 | |
| 8421 | /** @category Fetch */ |
| 8422 | declare var FormData: { |
| 8423 | readonly prototype: FormData; |
| 8424 | new (): FormData; |
| 8425 | }; |
| 8426 | |
| 8427 | /** @category Fetch */ |
| 8428 | declare interface Body { |
| 8429 | /** A simple getter used to expose a `ReadableStream` of the body contents. */ |
| 8430 | readonly body: ReadableStream<Uint8Array> | null; |
| 8431 | /** Stores a `Boolean` that declares whether the body has been used in a |
| 8432 | * response yet. |
| 8433 | */ |
| 8434 | readonly bodyUsed: boolean; |
| 8435 | /** Takes a `Response` stream and reads it to completion. It returns a promise |
| 8436 | * that resolves with an `ArrayBuffer`. |
| 8437 | */ |
| 8438 | arrayBuffer(): Promise<ArrayBuffer>; |
| 8439 | /** Takes a `Response` stream and reads it to completion. It returns a promise |
| 8440 | * that resolves with a `Blob`. |
| 8441 | */ |
| 8442 | blob(): Promise<Blob>; |
| 8443 | /** Takes a `Response` stream and reads it to completion. It returns a promise |
| 8444 | * that resolves with a `Uint8Array`. |
| 8445 | */ |
| 8446 | bytes(): Promise<Uint8Array>; |
| 8447 | /** Takes a `Response` stream and reads it to completion. It returns a promise |
| 8448 | * that resolves with a `FormData` object. |
| 8449 | */ |
| 8450 | formData(): Promise<FormData>; |
| 8451 | /** Takes a `Response` stream and reads it to completion. It returns a promise |
| 8452 | * that resolves with the result of parsing the body text as JSON. |
| 8453 | */ |
| 8454 | json(): Promise<any>; |
| 8455 | /** Takes a `Response` stream and reads it to completion. It returns a promise |
| 8456 | * that resolves with a `USVString` (text). |
| 8457 | */ |
| 8458 | text(): Promise<string>; |
| 8459 | } |
| 8460 | |
| 8461 | /** @category Fetch */ |
| 8462 | declare type HeadersInit = Iterable<string[]> | Record<string, string>; |
| 8463 | |
| 8464 | /** This Fetch API interface allows you to perform various actions on HTTP |
| 8465 | * request and response headers. These actions include retrieving, setting, |
| 8466 | * adding to, and removing. A Headers object has an associated header list, |
| 8467 | * which is initially empty and consists of zero or more name and value pairs. |
| 8468 | * You can add to this using methods like append() (see Examples). In all |
| 8469 | * methods of this interface, header names are matched by case-insensitive byte |
| 8470 | * sequence. |
| 8471 | * |
| 8472 | * @category Fetch |
| 8473 | */ |
| 8474 | declare interface Headers extends DomIterable<string, string> { |
| 8475 | /** Appends a new value onto an existing header inside a `Headers` object, or |
| 8476 | * adds the header if it does not already exist. |
| 8477 | */ |
| 8478 | append(name: string, value: string): void; |
| 8479 | /** Deletes a header from a `Headers` object. */ |
| 8480 | delete(name: string): void; |
| 8481 | /** Returns a `ByteString` sequence of all the values of a header within a |
| 8482 | * `Headers` object with a given name. |
| 8483 | */ |
| 8484 | get(name: string): string | null; |
| 8485 | /** Returns a boolean stating whether a `Headers` object contains a certain |
| 8486 | * header. |
| 8487 | */ |
| 8488 | has(name: string): boolean; |
| 8489 | /** Sets a new value for an existing header inside a Headers object, or adds |
| 8490 | * the header if it does not already exist. |
| 8491 | */ |
| 8492 | set(name: string, value: string): void; |
| 8493 | /** Returns an array containing the values of all `Set-Cookie` headers |
| 8494 | * associated with a response. |
| 8495 | */ |
| 8496 | getSetCookie(): string[]; |
| 8497 | } |
| 8498 | |
| 8499 | /** This Fetch API interface allows you to perform various actions on HTTP |
| 8500 | * request and response headers. These actions include retrieving, setting, |
| 8501 | * adding to, and removing. A Headers object has an associated header list, |
| 8502 | * which is initially empty and consists of zero or more name and value pairs. |
| 8503 | * You can add to this using methods like append() (see Examples). In all |
| 8504 | * methods of this interface, header names are matched by case-insensitive byte |
| 8505 | * sequence. |
| 8506 | * |
| 8507 | * @category Fetch |
| 8508 | */ |
| 8509 | declare var Headers: { |
| 8510 | readonly prototype: Headers; |
| 8511 | new (init?: HeadersInit): Headers; |
| 8512 | }; |
| 8513 | |
| 8514 | /** @category Fetch */ |
| 8515 | declare type RequestInfo = Request | string; |
| 8516 | /** @category Fetch */ |
| 8517 | declare type RequestCache = |
| 8518 | | "default" |
| 8519 | | "force-cache" |
| 8520 | | "no-cache" |
| 8521 | | "no-store" |
| 8522 | | "only-if-cached" |
| 8523 | | "reload"; |
| 8524 | /** @category Fetch */ |
| 8525 | declare type RequestCredentials = "include" | "omit" | "same-origin"; |
| 8526 | /** @category Fetch */ |
| 8527 | declare type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin"; |
| 8528 | /** @category Fetch */ |
| 8529 | declare type RequestRedirect = "error" | "follow" | "manual"; |
| 8530 | /** @category Fetch */ |
| 8531 | declare type ReferrerPolicy = |
| 8532 | | "" |
| 8533 | | "no-referrer" |
| 8534 | | "no-referrer-when-downgrade" |
| 8535 | | "origin" |
| 8536 | | "origin-when-cross-origin" |
| 8537 | | "same-origin" |
| 8538 | | "strict-origin" |
| 8539 | | "strict-origin-when-cross-origin" |
| 8540 | | "unsafe-url"; |
| 8541 | /** @category Fetch */ |
| 8542 | declare type BodyInit = |
| 8543 | | Blob |
| 8544 | | BufferSource |
| 8545 | | FormData |
| 8546 | | URLSearchParams |
| 8547 | | ReadableStream<Uint8Array> |
| 8548 | | string; |
| 8549 | /** @category Fetch */ |
| 8550 | declare type RequestDestination = |
| 8551 | | "" |
| 8552 | | "audio" |
| 8553 | | "audioworklet" |
| 8554 | | "document" |
| 8555 | | "embed" |
| 8556 | | "font" |
| 8557 | | "image" |
| 8558 | | "manifest" |
| 8559 | | "object" |
| 8560 | | "paintworklet" |
| 8561 | | "report" |
| 8562 | | "script" |
| 8563 | | "sharedworker" |
| 8564 | | "style" |
| 8565 | | "track" |
| 8566 | | "video" |
| 8567 | | "worker" |
| 8568 | | "xslt"; |
| 8569 | |
| 8570 | /** @category Fetch */ |
| 8571 | declare interface RequestInit { |
| 8572 | /** |
| 8573 | * A BodyInit object or null to set request's body. |
| 8574 | */ |
| 8575 | body?: BodyInit | null; |
| 8576 | /** |
| 8577 | * A string indicating how the request will interact with the browser's cache |
| 8578 | * to set request's cache. |
| 8579 | */ |
| 8580 | cache?: RequestCache; |
| 8581 | /** |
| 8582 | * A string indicating whether credentials will be sent with the request |
| 8583 | * always, never, or only when sent to a same-origin URL. Sets request's |
| 8584 | * credentials. |
| 8585 | */ |
| 8586 | credentials?: RequestCredentials; |
| 8587 | /** |
| 8588 | * A Headers object, an object literal, or an array of two-item arrays to set |
| 8589 | * request's headers. |
| 8590 | */ |
| 8591 | headers?: HeadersInit; |
| 8592 | /** |
| 8593 | * A cryptographic hash of the resource to be fetched by request. Sets |
| 8594 | * request's integrity. |
| 8595 | */ |
| 8596 | integrity?: string; |
| 8597 | /** |
| 8598 | * A boolean to set request's keepalive. |
| 8599 | */ |
| 8600 | keepalive?: boolean; |
| 8601 | /** |
| 8602 | * A string to set request's method. |
| 8603 | */ |
| 8604 | method?: string; |
| 8605 | /** |
| 8606 | * A string to indicate whether the request will use CORS, or will be |
| 8607 | * restricted to same-origin URLs. Sets request's mode. |
| 8608 | */ |
| 8609 | mode?: RequestMode; |
| 8610 | /** |
| 8611 | * A string indicating whether request follows redirects, results in an error |
| 8612 | * upon encountering a redirect, or returns the redirect (in an opaque |
| 8613 | * fashion). Sets request's redirect. |
| 8614 | */ |
| 8615 | redirect?: RequestRedirect; |
| 8616 | /** |
| 8617 | * A string whose value is a same-origin URL, "about:client", or the empty |
| 8618 | * string, to set request's referrer. |
| 8619 | */ |
| 8620 | referrer?: string; |
| 8621 | /** |
| 8622 | * A referrer policy to set request's referrerPolicy. |
| 8623 | */ |
| 8624 | referrerPolicy?: ReferrerPolicy; |
| 8625 | /** |
| 8626 | * An AbortSignal to set request's signal. |
| 8627 | */ |
| 8628 | signal?: AbortSignal | null; |
| 8629 | /** |
| 8630 | * Can only be null. Used to disassociate request from any Window. |
| 8631 | */ |
| 8632 | window?: any; |
| 8633 | } |
| 8634 | |
| 8635 | /** This Fetch API interface represents a resource request. |
| 8636 | * |
| 8637 | * @category Fetch |
| 8638 | */ |
| 8639 | declare interface Request extends Body { |
| 8640 | /** |
| 8641 | * Returns the cache mode associated with request, which is a string |
| 8642 | * indicating how the request will interact with the browser's cache when |
| 8643 | * fetching. |
| 8644 | */ |
| 8645 | readonly cache: RequestCache; |
| 8646 | /** |
| 8647 | * Returns the credentials mode associated with request, which is a string |
| 8648 | * indicating whether credentials will be sent with the request always, never, |
| 8649 | * or only when sent to a same-origin URL. |
| 8650 | */ |
| 8651 | readonly credentials: RequestCredentials; |
| 8652 | /** |
| 8653 | * Returns the kind of resource requested by request, e.g., "document" or "script". |
| 8654 | */ |
| 8655 | readonly destination: RequestDestination; |
| 8656 | /** |
| 8657 | * Returns a Headers object consisting of the headers associated with request. |
| 8658 | * Note that headers added in the network layer by the user agent will not be |
| 8659 | * accounted for in this object, e.g., the "Host" header. |
| 8660 | */ |
| 8661 | readonly headers: Headers; |
| 8662 | /** |
| 8663 | * Returns request's subresource integrity metadata, which is a cryptographic |
| 8664 | * hash of the resource being fetched. Its value consists of multiple hashes |
| 8665 | * separated by whitespace. [SRI] |
| 8666 | */ |
| 8667 | readonly integrity: string; |
| 8668 | /** |
| 8669 | * Returns a boolean indicating whether or not request is for a history |
| 8670 | * navigation (a.k.a. back-forward navigation). |
| 8671 | */ |
| 8672 | readonly isHistoryNavigation: boolean; |
| 8673 | /** |
| 8674 | * Returns a boolean indicating whether or not request is for a reload |
| 8675 | * navigation. |
| 8676 | */ |
| 8677 | readonly isReloadNavigation: boolean; |
| 8678 | /** |
| 8679 | * Returns a boolean indicating whether or not request can outlive the global |
| 8680 | * in which it was created. |
| 8681 | */ |
| 8682 | readonly keepalive: boolean; |
| 8683 | /** |
| 8684 | * Returns request's HTTP method, which is "GET" by default. |
| 8685 | */ |
| 8686 | readonly method: string; |
| 8687 | /** |
| 8688 | * Returns the mode associated with request, which is a string indicating |
| 8689 | * whether the request will use CORS, or will be restricted to same-origin |
| 8690 | * URLs. |
| 8691 | */ |
| 8692 | readonly mode: RequestMode; |
| 8693 | /** |
| 8694 | * Returns the redirect mode associated with request, which is a string |
| 8695 | * indicating how redirects for the request will be handled during fetching. A |
| 8696 | * request will follow redirects by default. |
| 8697 | */ |
| 8698 | readonly redirect: RequestRedirect; |
| 8699 | /** |
| 8700 | * Returns the referrer of request. Its value can be a same-origin URL if |
| 8701 | * explicitly set in init, the empty string to indicate no referrer, and |
| 8702 | * "about:client" when defaulting to the global's default. This is used during |
| 8703 | * fetching to determine the value of the `Referer` header of the request |
| 8704 | * being made. |
| 8705 | */ |
| 8706 | readonly referrer: string; |
| 8707 | /** |
| 8708 | * Returns the referrer policy associated with request. This is used during |
| 8709 | * fetching to compute the value of the request's referrer. |
| 8710 | */ |
| 8711 | readonly referrerPolicy: ReferrerPolicy; |
| 8712 | /** |
| 8713 | * Returns the signal associated with request, which is an AbortSignal object |
| 8714 | * indicating whether or not request has been aborted, and its abort event |
| 8715 | * handler. |
| 8716 | */ |
| 8717 | readonly signal: AbortSignal; |
| 8718 | /** |
| 8719 | * Returns the URL of request as a string. |
| 8720 | */ |
| 8721 | readonly url: string; |
| 8722 | clone(): Request; |
| 8723 | } |
| 8724 | |
| 8725 | /** This Fetch API interface represents a resource request. |
| 8726 | * |
| 8727 | * @category Fetch |
| 8728 | */ |
| 8729 | declare var Request: { |
| 8730 | readonly prototype: Request; |
| 8731 | new (input: RequestInfo | URL, init?: RequestInit): Request; |
| 8732 | }; |
| 8733 | |
| 8734 | /** @category Fetch */ |
| 8735 | declare interface ResponseInit { |
| 8736 | headers?: HeadersInit; |
| 8737 | status?: number; |
| 8738 | statusText?: string; |
| 8739 | } |
| 8740 | |
| 8741 | /** @category Fetch */ |
| 8742 | declare type ResponseType = |
| 8743 | | "basic" |
| 8744 | | "cors" |
| 8745 | | "default" |
| 8746 | | "error" |
| 8747 | | "opaque" |
| 8748 | | "opaqueredirect"; |
| 8749 | |
| 8750 | /** This Fetch API interface represents the response to a request. |
| 8751 | * |
| 8752 | * @category Fetch |
| 8753 | */ |
| 8754 | declare interface Response extends Body { |
| 8755 | readonly headers: Headers; |
| 8756 | readonly ok: boolean; |
| 8757 | readonly redirected: boolean; |
| 8758 | readonly status: number; |
| 8759 | readonly statusText: string; |
| 8760 | readonly type: ResponseType; |
| 8761 | readonly url: string; |
| 8762 | clone(): Response; |
| 8763 | } |
| 8764 | |
| 8765 | /** This Fetch API interface represents the response to a request. |
| 8766 | * |
| 8767 | * @category Fetch |
| 8768 | */ |
| 8769 | declare var Response: { |
| 8770 | readonly prototype: Response; |
| 8771 | new (body?: BodyInit | null, init?: ResponseInit): Response; |
| 8772 | json(data: unknown, init?: ResponseInit): Response; |
| 8773 | error(): Response; |
| 8774 | redirect(url: string | URL, status?: number): Response; |
| 8775 | }; |
| 8776 | |
| 8777 | /** Fetch a resource from the network. It returns a `Promise` that resolves to the |
| 8778 | * `Response` to that `Request`, whether it is successful or not. |
| 8779 | * |
| 8780 | * ```ts |
| 8781 | * const response = await fetch("http://my.json.host/data.json"); |
| 8782 | * console.log(response.status); // e.g. 200 |
| 8783 | * console.log(response.statusText); // e.g. "OK" |
| 8784 | * const jsonData = await response.json(); |
| 8785 | * ``` |
| 8786 | * |
| 8787 | * @tags allow-net, allow-read |
| 8788 | * @category Fetch |
| 8789 | */ |
| 8790 | declare function fetch( |
| 8791 | input: URL | Request | string, |
| 8792 | init?: RequestInit, |
| 8793 | ): Promise<Response>; |
| 8794 | |
| 8795 | /** |
| 8796 | * @category Fetch |
| 8797 | */ |
| 8798 | declare interface EventSourceInit { |
| 8799 | withCredentials?: boolean; |
| 8800 | } |
| 8801 | |
| 8802 | /** |
| 8803 | * @category Fetch |
| 8804 | */ |
| 8805 | declare interface EventSourceEventMap { |
| 8806 | "error": Event; |
| 8807 | "message": MessageEvent; |
| 8808 | "open": Event; |
| 8809 | } |
| 8810 | |
| 8811 | /** |
| 8812 | * @category Fetch |
| 8813 | */ |
| 8814 | declare interface EventSource extends EventTarget { |
| 8815 | onerror: ((this: EventSource, ev: Event) => any) | null; |
| 8816 | onmessage: ((this: EventSource, ev: MessageEvent) => any) | null; |
| 8817 | onopen: ((this: EventSource, ev: Event) => any) | null; |
| 8818 | /** |
| 8819 | * Returns the state of this EventSource object's connection. It can have the values described below. |
| 8820 | */ |
| 8821 | readonly readyState: number; |
| 8822 | /** |
| 8823 | * Returns the URL providing the event stream. |
| 8824 | */ |
| 8825 | readonly url: string; |
| 8826 | /** |
| 8827 | * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise. |
| 8828 | */ |
| 8829 | readonly withCredentials: boolean; |
| 8830 | /** |
| 8831 | * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED. |
| 8832 | */ |
| 8833 | close(): void; |
| 8834 | readonly CONNECTING: 0; |
| 8835 | readonly OPEN: 1; |
| 8836 | readonly CLOSED: 2; |
| 8837 | addEventListener<K extends keyof EventSourceEventMap>( |
| 8838 | type: K, |
| 8839 | listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, |
| 8840 | options?: boolean | AddEventListenerOptions, |
| 8841 | ): void; |
| 8842 | addEventListener( |
| 8843 | type: string, |
| 8844 | listener: (this: EventSource, event: MessageEvent) => any, |
| 8845 | options?: boolean | AddEventListenerOptions, |
| 8846 | ): void; |
| 8847 | addEventListener( |
| 8848 | type: string, |
| 8849 | listener: EventListenerOrEventListenerObject, |
| 8850 | options?: boolean | AddEventListenerOptions, |
| 8851 | ): void; |
| 8852 | removeEventListener<K extends keyof EventSourceEventMap>( |
| 8853 | type: K, |
| 8854 | listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, |
| 8855 | options?: boolean | EventListenerOptions, |
| 8856 | ): void; |
| 8857 | removeEventListener( |
| 8858 | type: string, |
| 8859 | listener: (this: EventSource, event: MessageEvent) => any, |
| 8860 | options?: boolean | EventListenerOptions, |
| 8861 | ): void; |
| 8862 | removeEventListener( |
| 8863 | type: string, |
| 8864 | listener: EventListenerOrEventListenerObject, |
| 8865 | options?: boolean | EventListenerOptions, |
| 8866 | ): void; |
| 8867 | } |
| 8868 | |
| 8869 | /** |
| 8870 | * @category Fetch |
| 8871 | */ |
| 8872 | declare var EventSource: { |
| 8873 | prototype: EventSource; |
| 8874 | new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource; |
| 8875 | readonly CONNECTING: 0; |
| 8876 | readonly OPEN: 1; |
| 8877 | readonly CLOSED: 2; |
| 8878 | }; |
| 8879 | |
| 8880 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 8881 | |
| 8882 | // deno-lint-ignore-file no-explicit-any no-empty-interface |
| 8883 | |
| 8884 | /// <reference no-default-lib="true" /> |
| 8885 | /// <reference lib="esnext" /> |
| 8886 | |
| 8887 | /** |
| 8888 | * @category GPU |
| 8889 | * @experimental |
| 8890 | */ |
| 8891 | declare interface GPUObjectBase { |
| 8892 | label: string; |
| 8893 | } |
| 8894 | |
| 8895 | /** |
| 8896 | * @category GPU |
| 8897 | * @experimental |
| 8898 | */ |
| 8899 | declare interface GPUObjectDescriptorBase { |
| 8900 | label?: string; |
| 8901 | } |
| 8902 | |
| 8903 | /** |
| 8904 | * @category GPU |
| 8905 | * @experimental |
| 8906 | */ |
| 8907 | declare class GPUSupportedLimits { |
| 8908 | maxTextureDimension1D?: number; |
| 8909 | maxTextureDimension2D?: number; |
| 8910 | maxTextureDimension3D?: number; |
| 8911 | maxTextureArrayLayers?: number; |
| 8912 | maxBindGroups?: number; |
| 8913 | maxBindingsPerBindGroup?: number; |
| 8914 | maxDynamicUniformBuffersPerPipelineLayout?: number; |
| 8915 | maxDynamicStorageBuffersPerPipelineLayout?: number; |
| 8916 | maxSampledTexturesPerShaderStage?: number; |
| 8917 | maxSamplersPerShaderStage?: number; |
| 8918 | maxStorageBuffersPerShaderStage?: number; |
| 8919 | maxStorageTexturesPerShaderStage?: number; |
| 8920 | maxUniformBuffersPerShaderStage?: number; |
| 8921 | maxUniformBufferBindingSize?: number; |
| 8922 | maxStorageBufferBindingSize?: number; |
| 8923 | minUniformBufferOffsetAlignment?: number; |
| 8924 | minStorageBufferOffsetAlignment?: number; |
| 8925 | maxVertexBuffers?: number; |
| 8926 | maxBufferSize?: number; |
| 8927 | maxVertexAttributes?: number; |
| 8928 | maxVertexBufferArrayStride?: number; |
| 8929 | maxInterStageShaderComponents?: number; |
| 8930 | maxColorAttachments?: number; |
| 8931 | maxColorAttachmentBytesPerSample?: number; |
| 8932 | maxComputeWorkgroupStorageSize?: number; |
| 8933 | maxComputeInvocationsPerWorkgroup?: number; |
| 8934 | maxComputeWorkgroupSizeX?: number; |
| 8935 | maxComputeWorkgroupSizeY?: number; |
| 8936 | maxComputeWorkgroupSizeZ?: number; |
| 8937 | maxComputeWorkgroupsPerDimension?: number; |
| 8938 | } |
| 8939 | |
| 8940 | /** |
| 8941 | * @category GPU |
| 8942 | * @experimental |
| 8943 | */ |
| 8944 | declare class GPUSupportedFeatures { |
| 8945 | forEach( |
| 8946 | callbackfn: ( |
| 8947 | value: GPUFeatureName, |
| 8948 | value2: GPUFeatureName, |
| 8949 | set: Set<GPUFeatureName>, |
| 8950 | ) => void, |
| 8951 | thisArg?: any, |
| 8952 | ): void; |
| 8953 | has(value: GPUFeatureName): boolean; |
| 8954 | size: number; |
| 8955 | [Symbol.iterator](): IterableIterator<GPUFeatureName>; |
| 8956 | entries(): IterableIterator<[GPUFeatureName, GPUFeatureName]>; |
| 8957 | keys(): IterableIterator<GPUFeatureName>; |
| 8958 | values(): IterableIterator<GPUFeatureName>; |
| 8959 | } |
| 8960 | |
| 8961 | /** |
| 8962 | * @category GPU |
| 8963 | * @experimental |
| 8964 | */ |
| 8965 | declare class GPUAdapterInfo { |
| 8966 | readonly vendor: string; |
| 8967 | readonly architecture: string; |
| 8968 | readonly device: string; |
| 8969 | readonly description: string; |
| 8970 | } |
| 8971 | |
| 8972 | /** |
| 8973 | * @category GPU |
| 8974 | * @experimental |
| 8975 | */ |
| 8976 | declare class GPU { |
| 8977 | requestAdapter( |
| 8978 | options?: GPURequestAdapterOptions, |
| 8979 | ): Promise<GPUAdapter | null>; |
| 8980 | getPreferredCanvasFormat(): GPUTextureFormat; |
| 8981 | } |
| 8982 | |
| 8983 | /** |
| 8984 | * @category GPU |
| 8985 | * @experimental |
| 8986 | */ |
| 8987 | declare interface GPURequestAdapterOptions { |
| 8988 | powerPreference?: GPUPowerPreference; |
| 8989 | forceFallbackAdapter?: boolean; |
| 8990 | } |
| 8991 | |
| 8992 | /** |
| 8993 | * @category GPU |
| 8994 | * @experimental |
| 8995 | */ |
| 8996 | declare type GPUPowerPreference = "low-power" | "high-performance"; |
| 8997 | |
| 8998 | /** |
| 8999 | * @category GPU |
| 9000 | * @experimental |
| 9001 | */ |
| 9002 | declare class GPUAdapter { |
| 9003 | readonly features: GPUSupportedFeatures; |
| 9004 | readonly limits: GPUSupportedLimits; |
| 9005 | readonly isFallbackAdapter: boolean; |
| 9006 | |
| 9007 | requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>; |
| 9008 | requestAdapterInfo(): Promise<GPUAdapterInfo>; |
| 9009 | } |
| 9010 | |
| 9011 | /** |
| 9012 | * @category GPU |
| 9013 | * @experimental |
| 9014 | */ |
| 9015 | declare interface GPUDeviceDescriptor extends GPUObjectDescriptorBase { |
| 9016 | requiredFeatures?: GPUFeatureName[]; |
| 9017 | requiredLimits?: Record<string, number>; |
| 9018 | } |
| 9019 | |
| 9020 | /** |
| 9021 | * @category GPU |
| 9022 | * @experimental |
| 9023 | */ |
| 9024 | declare type GPUFeatureName = |
| 9025 | | "depth-clip-control" |
| 9026 | | "depth32float-stencil8" |
| 9027 | | "pipeline-statistics-query" |
| 9028 | | "texture-compression-bc" |
| 9029 | | "texture-compression-etc2" |
| 9030 | | "texture-compression-astc" |
| 9031 | | "timestamp-query" |
| 9032 | | "indirect-first-instance" |
| 9033 | | "shader-f16" |
| 9034 | | "rg11b10ufloat-renderable" |
| 9035 | | "bgra8unorm-storage" |
| 9036 | | "float32-filterable" |
| 9037 | // extended from spec |
| 9038 | | "mappable-primary-buffers" |
| 9039 | | "sampled-texture-binding-array" |
| 9040 | | "sampled-texture-array-dynamic-indexing" |
| 9041 | | "sampled-texture-array-non-uniform-indexing" |
| 9042 | | "unsized-binding-array" |
| 9043 | | "multi-draw-indirect" |
| 9044 | | "multi-draw-indirect-count" |
| 9045 | | "push-constants" |
| 9046 | | "address-mode-clamp-to-border" |
| 9047 | | "texture-adapter-specific-format-features" |
| 9048 | | "shader-float64" |
| 9049 | | "vertex-attribute-64bit"; |
| 9050 | |
| 9051 | /** |
| 9052 | * @category GPU |
| 9053 | * @experimental |
| 9054 | */ |
| 9055 | declare class GPUDevice extends EventTarget implements GPUObjectBase { |
| 9056 | label: string; |
| 9057 | |
| 9058 | readonly lost: Promise<GPUDeviceLostInfo>; |
| 9059 | pushErrorScope(filter: GPUErrorFilter): undefined; |
| 9060 | popErrorScope(): Promise<GPUError | null>; |
| 9061 | |
| 9062 | readonly features: GPUSupportedFeatures; |
| 9063 | readonly limits: GPUSupportedLimits; |
| 9064 | readonly queue: GPUQueue; |
| 9065 | |
| 9066 | destroy(): undefined; |
| 9067 | |
| 9068 | createBuffer(descriptor: GPUBufferDescriptor): GPUBuffer; |
| 9069 | createTexture(descriptor: GPUTextureDescriptor): GPUTexture; |
| 9070 | createSampler(descriptor?: GPUSamplerDescriptor): GPUSampler; |
| 9071 | |
| 9072 | createBindGroupLayout( |
| 9073 | descriptor: GPUBindGroupLayoutDescriptor, |
| 9074 | ): GPUBindGroupLayout; |
| 9075 | createPipelineLayout( |
| 9076 | descriptor: GPUPipelineLayoutDescriptor, |
| 9077 | ): GPUPipelineLayout; |
| 9078 | createBindGroup(descriptor: GPUBindGroupDescriptor): GPUBindGroup; |
| 9079 | |
| 9080 | createShaderModule(descriptor: GPUShaderModuleDescriptor): GPUShaderModule; |
| 9081 | createComputePipeline( |
| 9082 | descriptor: GPUComputePipelineDescriptor, |
| 9083 | ): GPUComputePipeline; |
| 9084 | createRenderPipeline( |
| 9085 | descriptor: GPURenderPipelineDescriptor, |
| 9086 | ): GPURenderPipeline; |
| 9087 | createComputePipelineAsync( |
| 9088 | descriptor: GPUComputePipelineDescriptor, |
| 9089 | ): Promise<GPUComputePipeline>; |
| 9090 | createRenderPipelineAsync( |
| 9091 | descriptor: GPURenderPipelineDescriptor, |
| 9092 | ): Promise<GPURenderPipeline>; |
| 9093 | |
| 9094 | createCommandEncoder( |
| 9095 | descriptor?: GPUCommandEncoderDescriptor, |
| 9096 | ): GPUCommandEncoder; |
| 9097 | createRenderBundleEncoder( |
| 9098 | descriptor: GPURenderBundleEncoderDescriptor, |
| 9099 | ): GPURenderBundleEncoder; |
| 9100 | |
| 9101 | createQuerySet(descriptor: GPUQuerySetDescriptor): GPUQuerySet; |
| 9102 | } |
| 9103 | |
| 9104 | /** |
| 9105 | * @category GPU |
| 9106 | * @experimental |
| 9107 | */ |
| 9108 | declare class GPUBuffer implements GPUObjectBase { |
| 9109 | label: string; |
| 9110 | |
| 9111 | readonly size: number; |
| 9112 | readonly usage: GPUFlagsConstant; |
| 9113 | readonly mapState: GPUBufferMapState; |
| 9114 | |
| 9115 | mapAsync( |
| 9116 | mode: GPUMapModeFlags, |
| 9117 | offset?: number, |
| 9118 | size?: number, |
| 9119 | ): Promise<undefined>; |
| 9120 | getMappedRange(offset?: number, size?: number): ArrayBuffer; |
| 9121 | unmap(): undefined; |
| 9122 | |
| 9123 | destroy(): undefined; |
| 9124 | } |
| 9125 | |
| 9126 | /** |
| 9127 | * @category GPU |
| 9128 | * @experimental |
| 9129 | */ |
| 9130 | declare type GPUBufferMapState = "unmapped" | "pending" | "mapped"; |
| 9131 | |
| 9132 | /** |
| 9133 | * @category GPU |
| 9134 | * @experimental |
| 9135 | */ |
| 9136 | declare interface GPUBufferDescriptor extends GPUObjectDescriptorBase { |
| 9137 | size: number; |
| 9138 | usage: GPUBufferUsageFlags; |
| 9139 | mappedAtCreation?: boolean; |
| 9140 | } |
| 9141 | |
| 9142 | /** |
| 9143 | * @category GPU |
| 9144 | * @experimental |
| 9145 | */ |
| 9146 | declare type GPUBufferUsageFlags = number; |
| 9147 | |
| 9148 | /** |
| 9149 | * @category GPU |
| 9150 | * @experimental |
| 9151 | */ |
| 9152 | declare type GPUFlagsConstant = number; |
| 9153 | |
| 9154 | /** |
| 9155 | * @category GPU |
| 9156 | * @experimental |
| 9157 | */ |
| 9158 | declare class GPUBufferUsage { |
| 9159 | static MAP_READ: 0x0001; |
| 9160 | static MAP_WRITE: 0x0002; |
| 9161 | static COPY_SRC: 0x0004; |
| 9162 | static COPY_DST: 0x0008; |
| 9163 | static INDEX: 0x0010; |
| 9164 | static VERTEX: 0x0020; |
| 9165 | static UNIFORM: 0x0040; |
| 9166 | static STORAGE: 0x0080; |
| 9167 | static INDIRECT: 0x0100; |
| 9168 | static QUERY_RESOLVE: 0x0200; |
| 9169 | } |
| 9170 | |
| 9171 | /** |
| 9172 | * @category GPU |
| 9173 | * @experimental |
| 9174 | */ |
| 9175 | declare type GPUMapModeFlags = number; |
| 9176 | |
| 9177 | /** |
| 9178 | * @category GPU |
| 9179 | * @experimental |
| 9180 | */ |
| 9181 | declare class GPUMapMode { |
| 9182 | static READ: 0x0001; |
| 9183 | static WRITE: 0x0002; |
| 9184 | } |
| 9185 | |
| 9186 | /** |
| 9187 | * @category GPU |
| 9188 | * @experimental |
| 9189 | */ |
| 9190 | declare class GPUTexture implements GPUObjectBase { |
| 9191 | label: string; |
| 9192 | |
| 9193 | createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView; |
| 9194 | destroy(): undefined; |
| 9195 | |
| 9196 | readonly width: number; |
| 9197 | readonly height: number; |
| 9198 | readonly depthOrArrayLayers: number; |
| 9199 | readonly mipLevelCount: number; |
| 9200 | readonly sampleCount: number; |
| 9201 | readonly dimension: GPUTextureDimension; |
| 9202 | readonly format: GPUTextureFormat; |
| 9203 | readonly usage: GPUFlagsConstant; |
| 9204 | } |
| 9205 | |
| 9206 | /** |
| 9207 | * @category GPU |
| 9208 | * @experimental |
| 9209 | */ |
| 9210 | declare interface GPUTextureDescriptor extends GPUObjectDescriptorBase { |
| 9211 | size: GPUExtent3D; |
| 9212 | mipLevelCount?: number; |
| 9213 | sampleCount?: number; |
| 9214 | dimension?: GPUTextureDimension; |
| 9215 | format: GPUTextureFormat; |
| 9216 | usage: GPUTextureUsageFlags; |
| 9217 | viewFormats?: GPUTextureFormat[]; |
| 9218 | } |
| 9219 | |
| 9220 | /** |
| 9221 | * @category GPU |
| 9222 | * @experimental |
| 9223 | */ |
| 9224 | declare type GPUTextureDimension = "1d" | "2d" | "3d"; |
| 9225 | |
| 9226 | /** |
| 9227 | * @category GPU |
| 9228 | * @experimental |
| 9229 | */ |
| 9230 | declare type GPUTextureUsageFlags = number; |
| 9231 | |
| 9232 | /** |
| 9233 | * @category GPU |
| 9234 | * @experimental |
| 9235 | */ |
| 9236 | declare class GPUTextureUsage { |
| 9237 | static COPY_SRC: 0x01; |
| 9238 | static COPY_DST: 0x02; |
| 9239 | static TEXTURE_BINDING: 0x04; |
| 9240 | static STORAGE_BINDING: 0x08; |
| 9241 | static RENDER_ATTACHMENT: 0x10; |
| 9242 | } |
| 9243 | |
| 9244 | /** |
| 9245 | * @category GPU |
| 9246 | * @experimental |
| 9247 | */ |
| 9248 | declare class GPUTextureView implements GPUObjectBase { |
| 9249 | label: string; |
| 9250 | } |
| 9251 | |
| 9252 | /** |
| 9253 | * @category GPU |
| 9254 | * @experimental |
| 9255 | */ |
| 9256 | declare interface GPUTextureViewDescriptor extends GPUObjectDescriptorBase { |
| 9257 | format?: GPUTextureFormat; |
| 9258 | dimension?: GPUTextureViewDimension; |
| 9259 | aspect?: GPUTextureAspect; |
| 9260 | baseMipLevel?: number; |
| 9261 | mipLevelCount?: number; |
| 9262 | baseArrayLayer?: number; |
| 9263 | arrayLayerCount?: number; |
| 9264 | } |
| 9265 | |
| 9266 | /** |
| 9267 | * @category GPU |
| 9268 | * @experimental |
| 9269 | */ |
| 9270 | declare type GPUTextureViewDimension = |
| 9271 | | "1d" |
| 9272 | | "2d" |
| 9273 | | "2d-array" |
| 9274 | | "cube" |
| 9275 | | "cube-array" |
| 9276 | | "3d"; |
| 9277 | |
| 9278 | /** |
| 9279 | * @category GPU |
| 9280 | * @experimental |
| 9281 | */ |
| 9282 | declare type GPUTextureAspect = "all" | "stencil-only" | "depth-only"; |
| 9283 | |
| 9284 | /** |
| 9285 | * @category GPU |
| 9286 | * @experimental |
| 9287 | */ |
| 9288 | declare type GPUTextureFormat = |
| 9289 | | "r8unorm" |
| 9290 | | "r8snorm" |
| 9291 | | "r8uint" |
| 9292 | | "r8sint" |
| 9293 | | "r16uint" |
| 9294 | | "r16sint" |
| 9295 | | "r16float" |
| 9296 | | "rg8unorm" |
| 9297 | | "rg8snorm" |
| 9298 | | "rg8uint" |
| 9299 | | "rg8sint" |
| 9300 | | "r32uint" |
| 9301 | | "r32sint" |
| 9302 | | "r32float" |
| 9303 | | "rg16uint" |
| 9304 | | "rg16sint" |
| 9305 | | "rg16float" |
| 9306 | | "rgba8unorm" |
| 9307 | | "rgba8unorm-srgb" |
| 9308 | | "rgba8snorm" |
| 9309 | | "rgba8uint" |
| 9310 | | "rgba8sint" |
| 9311 | | "bgra8unorm" |
| 9312 | | "bgra8unorm-srgb" |
| 9313 | | "rgb9e5ufloat" |
| 9314 | | "rgb10a2uint" |
| 9315 | | "rgb10a2unorm" |
| 9316 | | "rg11b10ufloat" |
| 9317 | | "rg32uint" |
| 9318 | | "rg32sint" |
| 9319 | | "rg32float" |
| 9320 | | "rgba16uint" |
| 9321 | | "rgba16sint" |
| 9322 | | "rgba16float" |
| 9323 | | "rgba32uint" |
| 9324 | | "rgba32sint" |
| 9325 | | "rgba32float" |
| 9326 | | "stencil8" |
| 9327 | | "depth16unorm" |
| 9328 | | "depth24plus" |
| 9329 | | "depth24plus-stencil8" |
| 9330 | | "depth32float" |
| 9331 | | "depth32float-stencil8" |
| 9332 | | "bc1-rgba-unorm" |
| 9333 | | "bc1-rgba-unorm-srgb" |
| 9334 | | "bc2-rgba-unorm" |
| 9335 | | "bc2-rgba-unorm-srgb" |
| 9336 | | "bc3-rgba-unorm" |
| 9337 | | "bc3-rgba-unorm-srgb" |
| 9338 | | "bc4-r-unorm" |
| 9339 | | "bc4-r-snorm" |
| 9340 | | "bc5-rg-unorm" |
| 9341 | | "bc5-rg-snorm" |
| 9342 | | "bc6h-rgb-ufloat" |
| 9343 | | "bc6h-rgb-float" |
| 9344 | | "bc7-rgba-unorm" |
| 9345 | | "bc7-rgba-unorm-srgb" |
| 9346 | | "etc2-rgb8unorm" |
| 9347 | | "etc2-rgb8unorm-srgb" |
| 9348 | | "etc2-rgb8a1unorm" |
| 9349 | | "etc2-rgb8a1unorm-srgb" |
| 9350 | | "etc2-rgba8unorm" |
| 9351 | | "etc2-rgba8unorm-srgb" |
| 9352 | | "eac-r11unorm" |
| 9353 | | "eac-r11snorm" |
| 9354 | | "eac-rg11unorm" |
| 9355 | | "eac-rg11snorm" |
| 9356 | | "astc-4x4-unorm" |
| 9357 | | "astc-4x4-unorm-srgb" |
| 9358 | | "astc-5x4-unorm" |
| 9359 | | "astc-5x4-unorm-srgb" |
| 9360 | | "astc-5x5-unorm" |
| 9361 | | "astc-5x5-unorm-srgb" |
| 9362 | | "astc-6x5-unorm" |
| 9363 | | "astc-6x5-unorm-srgb" |
| 9364 | | "astc-6x6-unorm" |
| 9365 | | "astc-6x6-unorm-srgb" |
| 9366 | | "astc-8x5-unorm" |
| 9367 | | "astc-8x5-unorm-srgb" |
| 9368 | | "astc-8x6-unorm" |
| 9369 | | "astc-8x6-unorm-srgb" |
| 9370 | | "astc-8x8-unorm" |
| 9371 | | "astc-8x8-unorm-srgb" |
| 9372 | | "astc-10x5-unorm" |
| 9373 | | "astc-10x5-unorm-srgb" |
| 9374 | | "astc-10x6-unorm" |
| 9375 | | "astc-10x6-unorm-srgb" |
| 9376 | | "astc-10x8-unorm" |
| 9377 | | "astc-10x8-unorm-srgb" |
| 9378 | | "astc-10x10-unorm" |
| 9379 | | "astc-10x10-unorm-srgb" |
| 9380 | | "astc-12x10-unorm" |
| 9381 | | "astc-12x10-unorm-srgb" |
| 9382 | | "astc-12x12-unorm" |
| 9383 | | "astc-12x12-unorm-srgb"; |
| 9384 | |
| 9385 | /** |
| 9386 | * @category GPU |
| 9387 | * @experimental |
| 9388 | */ |
| 9389 | declare class GPUSampler implements GPUObjectBase { |
| 9390 | label: string; |
| 9391 | } |
| 9392 | |
| 9393 | /** |
| 9394 | * @category GPU |
| 9395 | * @experimental |
| 9396 | */ |
| 9397 | declare interface GPUSamplerDescriptor extends GPUObjectDescriptorBase { |
| 9398 | addressModeU?: GPUAddressMode; |
| 9399 | addressModeV?: GPUAddressMode; |
| 9400 | addressModeW?: GPUAddressMode; |
| 9401 | magFilter?: GPUFilterMode; |
| 9402 | minFilter?: GPUFilterMode; |
| 9403 | mipmapFilter?: GPUMipmapFilterMode; |
| 9404 | lodMinClamp?: number; |
| 9405 | lodMaxClamp?: number; |
| 9406 | compare?: GPUCompareFunction; |
| 9407 | maxAnisotropy?: number; |
| 9408 | } |
| 9409 | |
| 9410 | /** |
| 9411 | * @category GPU |
| 9412 | * @experimental |
| 9413 | */ |
| 9414 | declare type GPUAddressMode = "clamp-to-edge" | "repeat" | "mirror-repeat"; |
| 9415 | |
| 9416 | /** |
| 9417 | * @category GPU |
| 9418 | * @experimental |
| 9419 | */ |
| 9420 | declare type GPUFilterMode = "nearest" | "linear"; |
| 9421 | |
| 9422 | /** |
| 9423 | * @category GPU |
| 9424 | * @experimental |
| 9425 | */ |
| 9426 | declare type GPUMipmapFilterMode = "nearest" | "linear"; |
| 9427 | |
| 9428 | /** |
| 9429 | * @category GPU |
| 9430 | * @experimental |
| 9431 | */ |
| 9432 | declare type GPUCompareFunction = |
| 9433 | | "never" |
| 9434 | | "less" |
| 9435 | | "equal" |
| 9436 | | "less-equal" |
| 9437 | | "greater" |
| 9438 | | "not-equal" |
| 9439 | | "greater-equal" |
| 9440 | | "always"; |
| 9441 | |
| 9442 | /** |
| 9443 | * @category GPU |
| 9444 | * @experimental |
| 9445 | */ |
| 9446 | declare class GPUBindGroupLayout implements GPUObjectBase { |
| 9447 | label: string; |
| 9448 | } |
| 9449 | |
| 9450 | /** |
| 9451 | * @category GPU |
| 9452 | * @experimental |
| 9453 | */ |
| 9454 | declare interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase { |
| 9455 | entries: GPUBindGroupLayoutEntry[]; |
| 9456 | } |
| 9457 | |
| 9458 | /** |
| 9459 | * @category GPU |
| 9460 | * @experimental |
| 9461 | */ |
| 9462 | declare interface GPUBindGroupLayoutEntry { |
| 9463 | binding: number; |
| 9464 | visibility: GPUShaderStageFlags; |
| 9465 | |
| 9466 | buffer?: GPUBufferBindingLayout; |
| 9467 | sampler?: GPUSamplerBindingLayout; |
| 9468 | texture?: GPUTextureBindingLayout; |
| 9469 | storageTexture?: GPUStorageTextureBindingLayout; |
| 9470 | } |
| 9471 | |
| 9472 | /** |
| 9473 | * @category GPU |
| 9474 | * @experimental |
| 9475 | */ |
| 9476 | declare type GPUShaderStageFlags = number; |
| 9477 | |
| 9478 | /** |
| 9479 | * @category GPU |
| 9480 | * @experimental |
| 9481 | */ |
| 9482 | declare class GPUShaderStage { |
| 9483 | static VERTEX: 0x1; |
| 9484 | static FRAGMENT: 0x2; |
| 9485 | static COMPUTE: 0x4; |
| 9486 | } |
| 9487 | |
| 9488 | /** |
| 9489 | * @category GPU |
| 9490 | * @experimental |
| 9491 | */ |
| 9492 | declare interface GPUBufferBindingLayout { |
| 9493 | type?: GPUBufferBindingType; |
| 9494 | hasDynamicOffset?: boolean; |
| 9495 | minBindingSize?: number; |
| 9496 | } |
| 9497 | |
| 9498 | /** |
| 9499 | * @category GPU |
| 9500 | * @experimental |
| 9501 | */ |
| 9502 | declare type GPUBufferBindingType = "uniform" | "storage" | "read-only-storage"; |
| 9503 | |
| 9504 | /** |
| 9505 | * @category GPU |
| 9506 | * @experimental |
| 9507 | */ |
| 9508 | declare interface GPUSamplerBindingLayout { |
| 9509 | type?: GPUSamplerBindingType; |
| 9510 | } |
| 9511 | |
| 9512 | /** |
| 9513 | * @category GPU |
| 9514 | * @experimental |
| 9515 | */ |
| 9516 | declare type GPUSamplerBindingType = |
| 9517 | | "filtering" |
| 9518 | | "non-filtering" |
| 9519 | | "comparison"; |
| 9520 | |
| 9521 | /** |
| 9522 | * @category GPU |
| 9523 | * @experimental |
| 9524 | */ |
| 9525 | declare interface GPUTextureBindingLayout { |
| 9526 | sampleType?: GPUTextureSampleType; |
| 9527 | viewDimension?: GPUTextureViewDimension; |
| 9528 | multisampled?: boolean; |
| 9529 | } |
| 9530 | |
| 9531 | /** |
| 9532 | * @category GPU |
| 9533 | * @experimental |
| 9534 | */ |
| 9535 | declare type GPUTextureSampleType = |
| 9536 | | "float" |
| 9537 | | "unfilterable-float" |
| 9538 | | "depth" |
| 9539 | | "sint" |
| 9540 | | "uint"; |
| 9541 | |
| 9542 | /** |
| 9543 | * @category GPU |
| 9544 | * @experimental |
| 9545 | */ |
| 9546 | declare type GPUStorageTextureAccess = |
| 9547 | | "write-only" |
| 9548 | | "read-only" |
| 9549 | | "read-write"; |
| 9550 | |
| 9551 | /** |
| 9552 | * @category GPU |
| 9553 | * @experimental |
| 9554 | */ |
| 9555 | declare interface GPUStorageTextureBindingLayout { |
| 9556 | access: GPUStorageTextureAccess; |
| 9557 | format: GPUTextureFormat; |
| 9558 | viewDimension?: GPUTextureViewDimension; |
| 9559 | } |
| 9560 | |
| 9561 | /** |
| 9562 | * @category GPU |
| 9563 | * @experimental |
| 9564 | */ |
| 9565 | declare class GPUBindGroup implements GPUObjectBase { |
| 9566 | label: string; |
| 9567 | } |
| 9568 | |
| 9569 | /** |
| 9570 | * @category GPU |
| 9571 | * @experimental |
| 9572 | */ |
| 9573 | declare interface GPUBindGroupDescriptor extends GPUObjectDescriptorBase { |
| 9574 | layout: GPUBindGroupLayout; |
| 9575 | entries: GPUBindGroupEntry[]; |
| 9576 | } |
| 9577 | |
| 9578 | /** |
| 9579 | * @category GPU |
| 9580 | * @experimental |
| 9581 | */ |
| 9582 | declare type GPUBindingResource = |
| 9583 | | GPUSampler |
| 9584 | | GPUTextureView |
| 9585 | | GPUBufferBinding; |
| 9586 | |
| 9587 | /** |
| 9588 | * @category GPU |
| 9589 | * @experimental |
| 9590 | */ |
| 9591 | declare interface GPUBindGroupEntry { |
| 9592 | binding: number; |
| 9593 | resource: GPUBindingResource; |
| 9594 | } |
| 9595 | |
| 9596 | /** |
| 9597 | * @category GPU |
| 9598 | * @experimental |
| 9599 | */ |
| 9600 | declare interface GPUBufferBinding { |
| 9601 | buffer: GPUBuffer; |
| 9602 | offset?: number; |
| 9603 | size?: number; |
| 9604 | } |
| 9605 | |
| 9606 | /** |
| 9607 | * @category GPU |
| 9608 | * @experimental |
| 9609 | */ |
| 9610 | declare class GPUPipelineLayout implements GPUObjectBase { |
| 9611 | label: string; |
| 9612 | } |
| 9613 | |
| 9614 | /** |
| 9615 | * @category GPU |
| 9616 | * @experimental |
| 9617 | */ |
| 9618 | declare interface GPUPipelineLayoutDescriptor extends GPUObjectDescriptorBase { |
| 9619 | bindGroupLayouts: GPUBindGroupLayout[]; |
| 9620 | } |
| 9621 | |
| 9622 | /** |
| 9623 | * @category GPU |
| 9624 | * @experimental |
| 9625 | */ |
| 9626 | declare type GPUCompilationMessageType = "error" | "warning" | "info"; |
| 9627 | |
| 9628 | /** |
| 9629 | * @category GPU |
| 9630 | * @experimental |
| 9631 | */ |
| 9632 | declare interface GPUCompilationMessage { |
| 9633 | readonly message: string; |
| 9634 | readonly type: GPUCompilationMessageType; |
| 9635 | readonly lineNum: number; |
| 9636 | readonly linePos: number; |
| 9637 | } |
| 9638 | |
| 9639 | /** |
| 9640 | * @category GPU |
| 9641 | * @experimental |
| 9642 | */ |
| 9643 | declare interface GPUCompilationInfo { |
| 9644 | readonly messages: ReadonlyArray<GPUCompilationMessage>; |
| 9645 | } |
| 9646 | |
| 9647 | /** |
| 9648 | * @category GPU |
| 9649 | * @experimental |
| 9650 | */ |
| 9651 | declare class GPUPipelineError extends DOMException { |
| 9652 | constructor(message?: string, options?: GPUPipelineErrorInit); |
| 9653 | |
| 9654 | readonly reason: GPUPipelineErrorReason; |
| 9655 | } |
| 9656 | |
| 9657 | /** |
| 9658 | * @category GPU |
| 9659 | * @experimental |
| 9660 | */ |
| 9661 | declare interface GPUPipelineErrorInit { |
| 9662 | reason: GPUPipelineErrorReason; |
| 9663 | } |
| 9664 | |
| 9665 | /** |
| 9666 | * @category GPU |
| 9667 | * @experimental |
| 9668 | */ |
| 9669 | declare type GPUPipelineErrorReason = "validation" | "internal"; |
| 9670 | |
| 9671 | /** |
| 9672 | * @category GPU |
| 9673 | * @experimental |
| 9674 | */ |
| 9675 | declare class GPUShaderModule implements GPUObjectBase { |
| 9676 | label: string; |
| 9677 | } |
| 9678 | |
| 9679 | /** |
| 9680 | * @category GPU |
| 9681 | * @experimental |
| 9682 | */ |
| 9683 | declare interface GPUShaderModuleDescriptor extends GPUObjectDescriptorBase { |
| 9684 | code: string; |
| 9685 | sourceMap?: any; |
| 9686 | } |
| 9687 | |
| 9688 | /** |
| 9689 | * @category GPU |
| 9690 | * @experimental |
| 9691 | */ |
| 9692 | declare type GPUAutoLayoutMode = "auto"; |
| 9693 | |
| 9694 | /** |
| 9695 | * @category GPU |
| 9696 | * @experimental |
| 9697 | */ |
| 9698 | declare interface GPUPipelineDescriptorBase extends GPUObjectDescriptorBase { |
| 9699 | layout: GPUPipelineLayout | GPUAutoLayoutMode; |
| 9700 | } |
| 9701 | |
| 9702 | /** |
| 9703 | * @category GPU |
| 9704 | * @experimental |
| 9705 | */ |
| 9706 | declare interface GPUPipelineBase { |
| 9707 | getBindGroupLayout(index: number): GPUBindGroupLayout; |
| 9708 | } |
| 9709 | |
| 9710 | /** |
| 9711 | * @category GPU |
| 9712 | * @experimental |
| 9713 | */ |
| 9714 | declare interface GPUProgrammableStage { |
| 9715 | module: GPUShaderModule; |
| 9716 | entryPoint?: string; |
| 9717 | constants?: Record<string, number>; |
| 9718 | } |
| 9719 | |
| 9720 | /** |
| 9721 | * @category GPU |
| 9722 | * @experimental |
| 9723 | */ |
| 9724 | declare class GPUComputePipeline implements GPUObjectBase, GPUPipelineBase { |
| 9725 | label: string; |
| 9726 | |
| 9727 | getBindGroupLayout(index: number): GPUBindGroupLayout; |
| 9728 | } |
| 9729 | |
| 9730 | /** |
| 9731 | * @category GPU |
| 9732 | * @experimental |
| 9733 | */ |
| 9734 | declare interface GPUComputePipelineDescriptor |
| 9735 | extends GPUPipelineDescriptorBase { |
| 9736 | compute: GPUProgrammableStage; |
| 9737 | } |
| 9738 | |
| 9739 | /** |
| 9740 | * @category GPU |
| 9741 | * @experimental |
| 9742 | */ |
| 9743 | declare class GPURenderPipeline implements GPUObjectBase, GPUPipelineBase { |
| 9744 | label: string; |
| 9745 | |
| 9746 | getBindGroupLayout(index: number): GPUBindGroupLayout; |
| 9747 | } |
| 9748 | |
| 9749 | /** |
| 9750 | * @category GPU |
| 9751 | * @experimental |
| 9752 | */ |
| 9753 | declare interface GPURenderPipelineDescriptor |
| 9754 | extends GPUPipelineDescriptorBase { |
| 9755 | vertex: GPUVertexState; |
| 9756 | primitive?: GPUPrimitiveState; |
| 9757 | depthStencil?: GPUDepthStencilState; |
| 9758 | multisample?: GPUMultisampleState; |
| 9759 | fragment?: GPUFragmentState; |
| 9760 | } |
| 9761 | |
| 9762 | /** |
| 9763 | * @category GPU |
| 9764 | * @experimental |
| 9765 | */ |
| 9766 | declare interface GPUPrimitiveState { |
| 9767 | topology?: GPUPrimitiveTopology; |
| 9768 | stripIndexFormat?: GPUIndexFormat; |
| 9769 | frontFace?: GPUFrontFace; |
| 9770 | cullMode?: GPUCullMode; |
| 9771 | unclippedDepth?: boolean; |
| 9772 | } |
| 9773 | |
| 9774 | /** |
| 9775 | * @category GPU |
| 9776 | * @experimental |
| 9777 | */ |
| 9778 | declare type GPUPrimitiveTopology = |
| 9779 | | "point-list" |
| 9780 | | "line-list" |
| 9781 | | "line-strip" |
| 9782 | | "triangle-list" |
| 9783 | | "triangle-strip"; |
| 9784 | |
| 9785 | /** |
| 9786 | * @category GPU |
| 9787 | * @experimental |
| 9788 | */ |
| 9789 | declare type GPUFrontFace = "ccw" | "cw"; |
| 9790 | |
| 9791 | /** |
| 9792 | * @category GPU |
| 9793 | * @experimental |
| 9794 | */ |
| 9795 | declare type GPUCullMode = "none" | "front" | "back"; |
| 9796 | |
| 9797 | /** |
| 9798 | * @category GPU |
| 9799 | * @experimental |
| 9800 | */ |
| 9801 | declare interface GPUMultisampleState { |
| 9802 | count?: number; |
| 9803 | mask?: number; |
| 9804 | alphaToCoverageEnabled?: boolean; |
| 9805 | } |
| 9806 | |
| 9807 | /** |
| 9808 | * @category GPU |
| 9809 | * @experimental |
| 9810 | */ |
| 9811 | declare interface GPUFragmentState extends GPUProgrammableStage { |
| 9812 | targets: (GPUColorTargetState | null)[]; |
| 9813 | } |
| 9814 | |
| 9815 | /** |
| 9816 | * @category GPU |
| 9817 | * @experimental |
| 9818 | */ |
| 9819 | declare interface GPUColorTargetState { |
| 9820 | format: GPUTextureFormat; |
| 9821 | |
| 9822 | blend?: GPUBlendState; |
| 9823 | writeMask?: GPUColorWriteFlags; |
| 9824 | } |
| 9825 | |
| 9826 | /** |
| 9827 | * @category GPU |
| 9828 | * @experimental |
| 9829 | */ |
| 9830 | declare interface GPUBlendState { |
| 9831 | color: GPUBlendComponent; |
| 9832 | alpha: GPUBlendComponent; |
| 9833 | } |
| 9834 | |
| 9835 | /** |
| 9836 | * @category GPU |
| 9837 | * @experimental |
| 9838 | */ |
| 9839 | declare type GPUColorWriteFlags = number; |
| 9840 | |
| 9841 | /** |
| 9842 | * @category GPU |
| 9843 | * @experimental |
| 9844 | */ |
| 9845 | declare class GPUColorWrite { |
| 9846 | static RED: 0x1; |
| 9847 | static GREEN: 0x2; |
| 9848 | static BLUE: 0x4; |
| 9849 | static ALPHA: 0x8; |
| 9850 | static ALL: 0xF; |
| 9851 | } |
| 9852 | |
| 9853 | /** |
| 9854 | * @category GPU |
| 9855 | * @experimental |
| 9856 | */ |
| 9857 | declare interface GPUBlendComponent { |
| 9858 | operation?: GPUBlendOperation; |
| 9859 | srcFactor?: GPUBlendFactor; |
| 9860 | dstFactor?: GPUBlendFactor; |
| 9861 | } |
| 9862 | |
| 9863 | /** |
| 9864 | * @category GPU |
| 9865 | * @experimental |
| 9866 | */ |
| 9867 | declare type GPUBlendFactor = |
| 9868 | | "zero" |
| 9869 | | "one" |
| 9870 | | "src" |
| 9871 | | "one-minus-src" |
| 9872 | | "src-alpha" |
| 9873 | | "one-minus-src-alpha" |
| 9874 | | "dst" |
| 9875 | | "one-minus-dst" |
| 9876 | | "dst-alpha" |
| 9877 | | "one-minus-dst-alpha" |
| 9878 | | "src-alpha-saturated" |
| 9879 | | "constant" |
| 9880 | | "one-minus-constant"; |
| 9881 | |
| 9882 | /** |
| 9883 | * @category GPU |
| 9884 | * @experimental |
| 9885 | */ |
| 9886 | declare type GPUBlendOperation = |
| 9887 | | "add" |
| 9888 | | "subtract" |
| 9889 | | "reverse-subtract" |
| 9890 | | "min" |
| 9891 | | "max"; |
| 9892 | |
| 9893 | /** |
| 9894 | * @category GPU |
| 9895 | * @experimental |
| 9896 | */ |
| 9897 | declare interface GPUDepthStencilState { |
| 9898 | format: GPUTextureFormat; |
| 9899 | |
| 9900 | depthWriteEnabled: boolean; |
| 9901 | depthCompare: GPUCompareFunction; |
| 9902 | |
| 9903 | stencilFront?: GPUStencilFaceState; |
| 9904 | stencilBack?: GPUStencilFaceState; |
| 9905 | |
| 9906 | stencilReadMask?: number; |
| 9907 | stencilWriteMask?: number; |
| 9908 | |
| 9909 | depthBias?: number; |
| 9910 | depthBiasSlopeScale?: number; |
| 9911 | depthBiasClamp?: number; |
| 9912 | } |
| 9913 | |
| 9914 | /** |
| 9915 | * @category GPU |
| 9916 | * @experimental |
| 9917 | */ |
| 9918 | declare interface GPUStencilFaceState { |
| 9919 | compare?: GPUCompareFunction; |
| 9920 | failOp?: GPUStencilOperation; |
| 9921 | depthFailOp?: GPUStencilOperation; |
| 9922 | passOp?: GPUStencilOperation; |
| 9923 | } |
| 9924 | |
| 9925 | /** |
| 9926 | * @category GPU |
| 9927 | * @experimental |
| 9928 | */ |
| 9929 | declare type GPUStencilOperation = |
| 9930 | | "keep" |
| 9931 | | "zero" |
| 9932 | | "replace" |
| 9933 | | "invert" |
| 9934 | | "increment-clamp" |
| 9935 | | "decrement-clamp" |
| 9936 | | "increment-wrap" |
| 9937 | | "decrement-wrap"; |
| 9938 | |
| 9939 | /** |
| 9940 | * @category GPU |
| 9941 | * @experimental |
| 9942 | */ |
| 9943 | declare type GPUIndexFormat = "uint16" | "uint32"; |
| 9944 | |
| 9945 | /** |
| 9946 | * @category GPU |
| 9947 | * @experimental |
| 9948 | */ |
| 9949 | declare type GPUVertexFormat = |
| 9950 | | "uint8x2" |
| 9951 | | "uint8x4" |
| 9952 | | "sint8x2" |
| 9953 | | "sint8x4" |
| 9954 | | "unorm8x2" |
| 9955 | | "unorm8x4" |
| 9956 | | "snorm8x2" |
| 9957 | | "snorm8x4" |
| 9958 | | "uint16x2" |
| 9959 | | "uint16x4" |
| 9960 | | "sint16x2" |
| 9961 | | "sint16x4" |
| 9962 | | "unorm16x2" |
| 9963 | | "unorm16x4" |
| 9964 | | "snorm16x2" |
| 9965 | | "snorm16x4" |
| 9966 | | "float16x2" |
| 9967 | | "float16x4" |
| 9968 | | "float32" |
| 9969 | | "float32x2" |
| 9970 | | "float32x3" |
| 9971 | | "float32x4" |
| 9972 | | "uint32" |
| 9973 | | "uint32x2" |
| 9974 | | "uint32x3" |
| 9975 | | "uint32x4" |
| 9976 | | "sint32" |
| 9977 | | "sint32x2" |
| 9978 | | "sint32x3" |
| 9979 | | "sint32x4" |
| 9980 | | "unorm10-10-10-2"; |
| 9981 | |
| 9982 | /** |
| 9983 | * @category GPU |
| 9984 | * @experimental |
| 9985 | */ |
| 9986 | declare type GPUVertexStepMode = "vertex" | "instance"; |
| 9987 | |
| 9988 | /** |
| 9989 | * @category GPU |
| 9990 | * @experimental |
| 9991 | */ |
| 9992 | declare interface GPUVertexState extends GPUProgrammableStage { |
| 9993 | buffers?: (GPUVertexBufferLayout | null)[]; |
| 9994 | } |
| 9995 | |
| 9996 | /** |
| 9997 | * @category GPU |
| 9998 | * @experimental |
| 9999 | */ |
| 10000 | declare interface GPUVertexBufferLayout { |
| 10001 | arrayStride: number; |
| 10002 | stepMode?: GPUVertexStepMode; |
| 10003 | attributes: GPUVertexAttribute[]; |
| 10004 | } |
| 10005 | |
| 10006 | /** |
| 10007 | * @category GPU |
| 10008 | * @experimental |
| 10009 | */ |
| 10010 | declare interface GPUVertexAttribute { |
| 10011 | format: GPUVertexFormat; |
| 10012 | offset: number; |
| 10013 | |
| 10014 | shaderLocation: number; |
| 10015 | } |
| 10016 | |
| 10017 | /** |
| 10018 | * @category GPU |
| 10019 | * @experimental |
| 10020 | */ |
| 10021 | declare interface GPUImageDataLayout { |
| 10022 | offset?: number; |
| 10023 | bytesPerRow?: number; |
| 10024 | rowsPerImage?: number; |
| 10025 | } |
| 10026 | |
| 10027 | /** |
| 10028 | * @category GPU |
| 10029 | * @experimental |
| 10030 | */ |
| 10031 | declare class GPUCommandBuffer implements GPUObjectBase { |
| 10032 | label: string; |
| 10033 | } |
| 10034 | |
| 10035 | /** |
| 10036 | * @category GPU |
| 10037 | * @experimental |
| 10038 | */ |
| 10039 | declare interface GPUCommandBufferDescriptor extends GPUObjectDescriptorBase {} |
| 10040 | |
| 10041 | /** |
| 10042 | * @category GPU |
| 10043 | * @experimental |
| 10044 | */ |
| 10045 | declare class GPUCommandEncoder implements GPUObjectBase { |
| 10046 | label: string; |
| 10047 | |
| 10048 | beginRenderPass(descriptor: GPURenderPassDescriptor): GPURenderPassEncoder; |
| 10049 | beginComputePass( |
| 10050 | descriptor?: GPUComputePassDescriptor, |
| 10051 | ): GPUComputePassEncoder; |
| 10052 | |
| 10053 | copyBufferToBuffer( |
| 10054 | source: GPUBuffer, |
| 10055 | sourceOffset: number, |
| 10056 | destination: GPUBuffer, |
| 10057 | destinationOffset: number, |
| 10058 | size: number, |
| 10059 | ): undefined; |
| 10060 | |
| 10061 | copyBufferToTexture( |
| 10062 | source: GPUImageCopyBuffer, |
| 10063 | destination: GPUImageCopyTexture, |
| 10064 | copySize: GPUExtent3D, |
| 10065 | ): undefined; |
| 10066 | |
| 10067 | copyTextureToBuffer( |
| 10068 | source: GPUImageCopyTexture, |
| 10069 | destination: GPUImageCopyBuffer, |
| 10070 | copySize: GPUExtent3D, |
| 10071 | ): undefined; |
| 10072 | |
| 10073 | copyTextureToTexture( |
| 10074 | source: GPUImageCopyTexture, |
| 10075 | destination: GPUImageCopyTexture, |
| 10076 | copySize: GPUExtent3D, |
| 10077 | ): undefined; |
| 10078 | |
| 10079 | clearBuffer( |
| 10080 | destination: GPUBuffer, |
| 10081 | destinationOffset?: number, |
| 10082 | size?: number, |
| 10083 | ): undefined; |
| 10084 | |
| 10085 | pushDebugGroup(groupLabel: string): undefined; |
| 10086 | popDebugGroup(): undefined; |
| 10087 | insertDebugMarker(markerLabel: string): undefined; |
| 10088 | |
| 10089 | writeTimestamp(querySet: GPUQuerySet, queryIndex: number): undefined; |
| 10090 | |
| 10091 | resolveQuerySet( |
| 10092 | querySet: GPUQuerySet, |
| 10093 | firstQuery: number, |
| 10094 | queryCount: number, |
| 10095 | destination: GPUBuffer, |
| 10096 | destinationOffset: number, |
| 10097 | ): undefined; |
| 10098 | |
| 10099 | finish(descriptor?: GPUCommandBufferDescriptor): GPUCommandBuffer; |
| 10100 | } |
| 10101 | |
| 10102 | /** |
| 10103 | * @category GPU |
| 10104 | * @experimental |
| 10105 | */ |
| 10106 | declare interface GPUCommandEncoderDescriptor extends GPUObjectDescriptorBase {} |
| 10107 | |
| 10108 | /** |
| 10109 | * @category GPU |
| 10110 | * @experimental |
| 10111 | */ |
| 10112 | declare interface GPUImageCopyBuffer extends GPUImageDataLayout { |
| 10113 | buffer: GPUBuffer; |
| 10114 | } |
| 10115 | |
| 10116 | /** |
| 10117 | * @category GPU |
| 10118 | * @experimental |
| 10119 | */ |
| 10120 | declare interface GPUImageCopyTexture { |
| 10121 | texture: GPUTexture; |
| 10122 | mipLevel?: number; |
| 10123 | origin?: GPUOrigin3D; |
| 10124 | aspect?: GPUTextureAspect; |
| 10125 | } |
| 10126 | |
| 10127 | /** |
| 10128 | * @category GPU |
| 10129 | * @experimental |
| 10130 | */ |
| 10131 | declare interface GPUProgrammablePassEncoder { |
| 10132 | setBindGroup( |
| 10133 | index: number, |
| 10134 | bindGroup: GPUBindGroup, |
| 10135 | dynamicOffsets?: number[], |
| 10136 | ): undefined; |
| 10137 | |
| 10138 | setBindGroup( |
| 10139 | index: number, |
| 10140 | bindGroup: GPUBindGroup, |
| 10141 | dynamicOffsetsData: Uint32Array, |
| 10142 | dynamicOffsetsDataStart: number, |
| 10143 | dynamicOffsetsDataLength: number, |
| 10144 | ): undefined; |
| 10145 | |
| 10146 | pushDebugGroup(groupLabel: string): undefined; |
| 10147 | popDebugGroup(): undefined; |
| 10148 | insertDebugMarker(markerLabel: string): undefined; |
| 10149 | } |
| 10150 | |
| 10151 | /** |
| 10152 | * @category GPU |
| 10153 | * @experimental |
| 10154 | */ |
| 10155 | declare class GPUComputePassEncoder |
| 10156 | implements GPUObjectBase, GPUProgrammablePassEncoder { |
| 10157 | label: string; |
| 10158 | setBindGroup( |
| 10159 | index: number, |
| 10160 | bindGroup: GPUBindGroup, |
| 10161 | dynamicOffsets?: number[], |
| 10162 | ): undefined; |
| 10163 | setBindGroup( |
| 10164 | index: number, |
| 10165 | bindGroup: GPUBindGroup, |
| 10166 | dynamicOffsetsData: Uint32Array, |
| 10167 | dynamicOffsetsDataStart: number, |
| 10168 | dynamicOffsetsDataLength: number, |
| 10169 | ): undefined; |
| 10170 | pushDebugGroup(groupLabel: string): undefined; |
| 10171 | popDebugGroup(): undefined; |
| 10172 | insertDebugMarker(markerLabel: string): undefined; |
| 10173 | setPipeline(pipeline: GPUComputePipeline): undefined; |
| 10174 | dispatchWorkgroups(x: number, y?: number, z?: number): undefined; |
| 10175 | dispatchWorkgroupsIndirect( |
| 10176 | indirectBuffer: GPUBuffer, |
| 10177 | indirectOffset: number, |
| 10178 | ): undefined; |
| 10179 | |
| 10180 | end(): undefined; |
| 10181 | } |
| 10182 | |
| 10183 | /** |
| 10184 | * @category GPU |
| 10185 | * @experimental |
| 10186 | */ |
| 10187 | declare interface GPUComputePassTimestampWrites { |
| 10188 | querySet: GPUQuerySet; |
| 10189 | beginningOfPassWriteIndex?: number; |
| 10190 | endOfPassWriteIndex?: number; |
| 10191 | } |
| 10192 | |
| 10193 | /** |
| 10194 | * @category GPU |
| 10195 | * @experimental |
| 10196 | */ |
| 10197 | declare interface GPUComputePassDescriptor extends GPUObjectDescriptorBase { |
| 10198 | timestampWrites?: GPUComputePassTimestampWrites; |
| 10199 | } |
| 10200 | |
| 10201 | /** |
| 10202 | * @category GPU |
| 10203 | * @experimental |
| 10204 | */ |
| 10205 | declare interface GPURenderEncoderBase { |
| 10206 | setPipeline(pipeline: GPURenderPipeline): undefined; |
| 10207 | |
| 10208 | setIndexBuffer( |
| 10209 | buffer: GPUBuffer, |
| 10210 | indexFormat: GPUIndexFormat, |
| 10211 | offset?: number, |
| 10212 | size?: number, |
| 10213 | ): undefined; |
| 10214 | setVertexBuffer( |
| 10215 | slot: number, |
| 10216 | buffer: GPUBuffer, |
| 10217 | offset?: number, |
| 10218 | size?: number, |
| 10219 | ): undefined; |
| 10220 | |
| 10221 | draw( |
| 10222 | vertexCount: number, |
| 10223 | instanceCount?: number, |
| 10224 | firstVertex?: number, |
| 10225 | firstInstance?: number, |
| 10226 | ): undefined; |
| 10227 | drawIndexed( |
| 10228 | indexCount: number, |
| 10229 | instanceCount?: number, |
| 10230 | firstIndex?: number, |
| 10231 | baseVertex?: number, |
| 10232 | firstInstance?: number, |
| 10233 | ): undefined; |
| 10234 | |
| 10235 | drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): undefined; |
| 10236 | drawIndexedIndirect( |
| 10237 | indirectBuffer: GPUBuffer, |
| 10238 | indirectOffset: number, |
| 10239 | ): undefined; |
| 10240 | } |
| 10241 | |
| 10242 | /** |
| 10243 | * @category GPU |
| 10244 | * @experimental |
| 10245 | */ |
| 10246 | declare class GPURenderPassEncoder |
| 10247 | implements GPUObjectBase, GPUProgrammablePassEncoder, GPURenderEncoderBase { |
| 10248 | label: string; |
| 10249 | setBindGroup( |
| 10250 | index: number, |
| 10251 | bindGroup: GPUBindGroup, |
| 10252 | dynamicOffsets?: number[], |
| 10253 | ): undefined; |
| 10254 | setBindGroup( |
| 10255 | index: number, |
| 10256 | bindGroup: GPUBindGroup, |
| 10257 | dynamicOffsetsData: Uint32Array, |
| 10258 | dynamicOffsetsDataStart: number, |
| 10259 | dynamicOffsetsDataLength: number, |
| 10260 | ): undefined; |
| 10261 | pushDebugGroup(groupLabel: string): undefined; |
| 10262 | popDebugGroup(): undefined; |
| 10263 | insertDebugMarker(markerLabel: string): undefined; |
| 10264 | setPipeline(pipeline: GPURenderPipeline): undefined; |
| 10265 | setIndexBuffer( |
| 10266 | buffer: GPUBuffer, |
| 10267 | indexFormat: GPUIndexFormat, |
| 10268 | offset?: number, |
| 10269 | size?: number, |
| 10270 | ): undefined; |
| 10271 | setVertexBuffer( |
| 10272 | slot: number, |
| 10273 | buffer: GPUBuffer, |
| 10274 | offset?: number, |
| 10275 | size?: number, |
| 10276 | ): undefined; |
| 10277 | draw( |
| 10278 | vertexCount: number, |
| 10279 | instanceCount?: number, |
| 10280 | firstVertex?: number, |
| 10281 | firstInstance?: number, |
| 10282 | ): undefined; |
| 10283 | drawIndexed( |
| 10284 | indexCount: number, |
| 10285 | instanceCount?: number, |
| 10286 | firstIndex?: number, |
| 10287 | baseVertex?: number, |
| 10288 | firstInstance?: number, |
| 10289 | ): undefined; |
| 10290 | drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): undefined; |
| 10291 | drawIndexedIndirect( |
| 10292 | indirectBuffer: GPUBuffer, |
| 10293 | indirectOffset: number, |
| 10294 | ): undefined; |
| 10295 | |
| 10296 | setViewport( |
| 10297 | x: number, |
| 10298 | y: number, |
| 10299 | width: number, |
| 10300 | height: number, |
| 10301 | minDepth: number, |
| 10302 | maxDepth: number, |
| 10303 | ): undefined; |
| 10304 | |
| 10305 | setScissorRect( |
| 10306 | x: number, |
| 10307 | y: number, |
| 10308 | width: number, |
| 10309 | height: number, |
| 10310 | ): undefined; |
| 10311 | |
| 10312 | setBlendConstant(color: GPUColor): undefined; |
| 10313 | setStencilReference(reference: number): undefined; |
| 10314 | |
| 10315 | beginOcclusionQuery(queryIndex: number): undefined; |
| 10316 | endOcclusionQuery(): undefined; |
| 10317 | |
| 10318 | executeBundles(bundles: GPURenderBundle[]): undefined; |
| 10319 | end(): undefined; |
| 10320 | } |
| 10321 | |
| 10322 | /** |
| 10323 | * @category GPU |
| 10324 | * @experimental |
| 10325 | */ |
| 10326 | declare interface GPURenderPassTimestampWrites { |
| 10327 | querySet: GPUQuerySet; |
| 10328 | beginningOfPassWriteIndex?: number; |
| 10329 | endOfPassWriteIndex?: number; |
| 10330 | } |
| 10331 | |
| 10332 | /** |
| 10333 | * @category GPU |
| 10334 | * @experimental |
| 10335 | */ |
| 10336 | declare interface GPURenderPassDescriptor extends GPUObjectDescriptorBase { |
| 10337 | colorAttachments: (GPURenderPassColorAttachment | null)[]; |
| 10338 | depthStencilAttachment?: GPURenderPassDepthStencilAttachment; |
| 10339 | occlusionQuerySet?: GPUQuerySet; |
| 10340 | timestampWrites?: GPURenderPassTimestampWrites; |
| 10341 | } |
| 10342 | |
| 10343 | /** |
| 10344 | * @category GPU |
| 10345 | * @experimental |
| 10346 | */ |
| 10347 | declare interface GPURenderPassColorAttachment { |
| 10348 | view: GPUTextureView; |
| 10349 | resolveTarget?: GPUTextureView; |
| 10350 | |
| 10351 | clearValue?: GPUColor; |
| 10352 | loadOp: GPULoadOp; |
| 10353 | storeOp: GPUStoreOp; |
| 10354 | } |
| 10355 | |
| 10356 | /** |
| 10357 | * @category GPU |
| 10358 | * @experimental |
| 10359 | */ |
| 10360 | declare interface GPURenderPassDepthStencilAttachment { |
| 10361 | view: GPUTextureView; |
| 10362 | |
| 10363 | depthClearValue?: number; |
| 10364 | depthLoadOp?: GPULoadOp; |
| 10365 | depthStoreOp?: GPUStoreOp; |
| 10366 | depthReadOnly?: boolean; |
| 10367 | |
| 10368 | stencilClearValue?: number; |
| 10369 | stencilLoadOp?: GPULoadOp; |
| 10370 | stencilStoreOp?: GPUStoreOp; |
| 10371 | stencilReadOnly?: boolean; |
| 10372 | } |
| 10373 | |
| 10374 | /** |
| 10375 | * @category GPU |
| 10376 | * @experimental |
| 10377 | */ |
| 10378 | declare type GPULoadOp = "load" | "clear"; |
| 10379 | |
| 10380 | /** |
| 10381 | * @category GPU |
| 10382 | * @experimental |
| 10383 | */ |
| 10384 | declare type GPUStoreOp = "store" | "discard"; |
| 10385 | |
| 10386 | /** |
| 10387 | * @category GPU |
| 10388 | * @experimental |
| 10389 | */ |
| 10390 | declare class GPURenderBundle implements GPUObjectBase { |
| 10391 | label: string; |
| 10392 | } |
| 10393 | |
| 10394 | /** |
| 10395 | * @category GPU |
| 10396 | * @experimental |
| 10397 | */ |
| 10398 | declare interface GPURenderBundleDescriptor extends GPUObjectDescriptorBase {} |
| 10399 | |
| 10400 | /** |
| 10401 | * @category GPU |
| 10402 | * @experimental |
| 10403 | */ |
| 10404 | declare class GPURenderBundleEncoder |
| 10405 | implements GPUObjectBase, GPUProgrammablePassEncoder, GPURenderEncoderBase { |
| 10406 | label: string; |
| 10407 | draw( |
| 10408 | vertexCount: number, |
| 10409 | instanceCount?: number, |
| 10410 | firstVertex?: number, |
| 10411 | firstInstance?: number, |
| 10412 | ): undefined; |
| 10413 | drawIndexed( |
| 10414 | indexCount: number, |
| 10415 | instanceCount?: number, |
| 10416 | firstIndex?: number, |
| 10417 | baseVertex?: number, |
| 10418 | firstInstance?: number, |
| 10419 | ): undefined; |
| 10420 | drawIndexedIndirect( |
| 10421 | indirectBuffer: GPUBuffer, |
| 10422 | indirectOffset: number, |
| 10423 | ): undefined; |
| 10424 | drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): undefined; |
| 10425 | insertDebugMarker(markerLabel: string): undefined; |
| 10426 | popDebugGroup(): undefined; |
| 10427 | pushDebugGroup(groupLabel: string): undefined; |
| 10428 | setBindGroup( |
| 10429 | index: number, |
| 10430 | bindGroup: GPUBindGroup, |
| 10431 | dynamicOffsets?: number[], |
| 10432 | ): undefined; |
| 10433 | setBindGroup( |
| 10434 | index: number, |
| 10435 | bindGroup: GPUBindGroup, |
| 10436 | dynamicOffsetsData: Uint32Array, |
| 10437 | dynamicOffsetsDataStart: number, |
| 10438 | dynamicOffsetsDataLength: number, |
| 10439 | ): undefined; |
| 10440 | setIndexBuffer( |
| 10441 | buffer: GPUBuffer, |
| 10442 | indexFormat: GPUIndexFormat, |
| 10443 | offset?: number, |
| 10444 | size?: number, |
| 10445 | ): undefined; |
| 10446 | setPipeline(pipeline: GPURenderPipeline): undefined; |
| 10447 | setVertexBuffer( |
| 10448 | slot: number, |
| 10449 | buffer: GPUBuffer, |
| 10450 | offset?: number, |
| 10451 | size?: number, |
| 10452 | ): undefined; |
| 10453 | |
| 10454 | finish(descriptor?: GPURenderBundleDescriptor): GPURenderBundle; |
| 10455 | } |
| 10456 | |
| 10457 | /** |
| 10458 | * @category GPU |
| 10459 | * @experimental |
| 10460 | */ |
| 10461 | declare interface GPURenderPassLayout extends GPUObjectDescriptorBase { |
| 10462 | colorFormats: (GPUTextureFormat | null)[]; |
| 10463 | depthStencilFormat?: GPUTextureFormat; |
| 10464 | sampleCount?: number; |
| 10465 | } |
| 10466 | |
| 10467 | /** |
| 10468 | * @category GPU |
| 10469 | * @experimental |
| 10470 | */ |
| 10471 | declare interface GPURenderBundleEncoderDescriptor extends GPURenderPassLayout { |
| 10472 | depthReadOnly?: boolean; |
| 10473 | stencilReadOnly?: boolean; |
| 10474 | } |
| 10475 | |
| 10476 | /** |
| 10477 | * @category GPU |
| 10478 | * @experimental |
| 10479 | */ |
| 10480 | declare class GPUQueue implements GPUObjectBase { |
| 10481 | label: string; |
| 10482 | |
| 10483 | submit(commandBuffers: GPUCommandBuffer[]): undefined; |
| 10484 | |
| 10485 | onSubmittedWorkDone(): Promise<undefined>; |
| 10486 | |
| 10487 | writeBuffer( |
| 10488 | buffer: GPUBuffer, |
| 10489 | bufferOffset: number, |
| 10490 | data: BufferSource, |
| 10491 | dataOffset?: number, |
| 10492 | size?: number, |
| 10493 | ): undefined; |
| 10494 | |
| 10495 | writeTexture( |
| 10496 | destination: GPUImageCopyTexture, |
| 10497 | data: BufferSource, |
| 10498 | dataLayout: GPUImageDataLayout, |
| 10499 | size: GPUExtent3D, |
| 10500 | ): undefined; |
| 10501 | } |
| 10502 | |
| 10503 | /** |
| 10504 | * @category GPU |
| 10505 | * @experimental |
| 10506 | */ |
| 10507 | declare class GPUQuerySet implements GPUObjectBase { |
| 10508 | label: string; |
| 10509 | |
| 10510 | destroy(): undefined; |
| 10511 | |
| 10512 | readonly type: GPUQueryType; |
| 10513 | readonly count: number; |
| 10514 | } |
| 10515 | |
| 10516 | /** |
| 10517 | * @category GPU |
| 10518 | * @experimental |
| 10519 | */ |
| 10520 | declare interface GPUQuerySetDescriptor extends GPUObjectDescriptorBase { |
| 10521 | type: GPUQueryType; |
| 10522 | count: number; |
| 10523 | } |
| 10524 | |
| 10525 | /** |
| 10526 | * @category GPU |
| 10527 | * @experimental |
| 10528 | */ |
| 10529 | declare type GPUQueryType = "occlusion" | "timestamp"; |
| 10530 | |
| 10531 | /** |
| 10532 | * @category GPU |
| 10533 | * @experimental |
| 10534 | */ |
| 10535 | declare type GPUDeviceLostReason = "destroyed"; |
| 10536 | |
| 10537 | /** |
| 10538 | * @category GPU |
| 10539 | * @experimental |
| 10540 | */ |
| 10541 | declare interface GPUDeviceLostInfo { |
| 10542 | readonly reason: GPUDeviceLostReason; |
| 10543 | readonly message: string; |
| 10544 | } |
| 10545 | |
| 10546 | /** |
| 10547 | * @category GPU |
| 10548 | * @experimental |
| 10549 | */ |
| 10550 | declare class GPUError { |
| 10551 | readonly message: string; |
| 10552 | } |
| 10553 | |
| 10554 | /** |
| 10555 | * @category GPU |
| 10556 | * @experimental |
| 10557 | */ |
| 10558 | declare class GPUOutOfMemoryError extends GPUError { |
| 10559 | constructor(message: string); |
| 10560 | } |
| 10561 | |
| 10562 | /** |
| 10563 | * @category GPU |
| 10564 | * @experimental |
| 10565 | */ |
| 10566 | declare class GPUValidationError extends GPUError { |
| 10567 | constructor(message: string); |
| 10568 | } |
| 10569 | |
| 10570 | /** |
| 10571 | * @category GPU |
| 10572 | * @experimental |
| 10573 | */ |
| 10574 | declare class GPUInternalError extends GPUError { |
| 10575 | constructor(message: string); |
| 10576 | } |
| 10577 | |
| 10578 | /** |
| 10579 | * @category GPU |
| 10580 | * @experimental |
| 10581 | */ |
| 10582 | declare type GPUErrorFilter = "out-of-memory" | "validation" | "internal"; |
| 10583 | |
| 10584 | /** |
| 10585 | * @category GPU |
| 10586 | * @experimental |
| 10587 | */ |
| 10588 | declare class GPUUncapturedErrorEvent extends Event { |
| 10589 | constructor( |
| 10590 | type: string, |
| 10591 | gpuUncapturedErrorEventInitDict: GPUUncapturedErrorEventInit, |
| 10592 | ); |
| 10593 | |
| 10594 | readonly error: GPUError; |
| 10595 | } |
| 10596 | |
| 10597 | /** |
| 10598 | * @category GPU |
| 10599 | * @experimental |
| 10600 | */ |
| 10601 | declare interface GPUUncapturedErrorEventInit extends EventInit { |
| 10602 | error: GPUError; |
| 10603 | } |
| 10604 | |
| 10605 | /** |
| 10606 | * @category GPU |
| 10607 | * @experimental |
| 10608 | */ |
| 10609 | declare interface GPUColorDict { |
| 10610 | r: number; |
| 10611 | g: number; |
| 10612 | b: number; |
| 10613 | a: number; |
| 10614 | } |
| 10615 | |
| 10616 | /** |
| 10617 | * @category GPU |
| 10618 | * @experimental |
| 10619 | */ |
| 10620 | declare type GPUColor = number[] | GPUColorDict; |
| 10621 | |
| 10622 | /** |
| 10623 | * @category GPU |
| 10624 | * @experimental |
| 10625 | */ |
| 10626 | declare interface GPUOrigin3DDict { |
| 10627 | x?: number; |
| 10628 | y?: number; |
| 10629 | z?: number; |
| 10630 | } |
| 10631 | |
| 10632 | /** |
| 10633 | * @category GPU |
| 10634 | * @experimental |
| 10635 | */ |
| 10636 | declare type GPUOrigin3D = number[] | GPUOrigin3DDict; |
| 10637 | |
| 10638 | /** |
| 10639 | * @category GPU |
| 10640 | * @experimental |
| 10641 | */ |
| 10642 | declare interface GPUExtent3DDict { |
| 10643 | width: number; |
| 10644 | height?: number; |
| 10645 | depthOrArrayLayers?: number; |
| 10646 | } |
| 10647 | |
| 10648 | /** |
| 10649 | * @category GPU |
| 10650 | * @experimental |
| 10651 | */ |
| 10652 | declare type GPUExtent3D = number[] | GPUExtent3DDict; |
| 10653 | |
| 10654 | /** |
| 10655 | * @category GPU |
| 10656 | * @experimental |
| 10657 | */ |
| 10658 | declare type GPUCanvasAlphaMode = "opaque" | "premultiplied"; |
| 10659 | |
| 10660 | /** |
| 10661 | * @category GPU |
| 10662 | * @experimental |
| 10663 | */ |
| 10664 | declare interface GPUCanvasConfiguration { |
| 10665 | device: GPUDevice; |
| 10666 | format: GPUTextureFormat; |
| 10667 | usage?: GPUTextureUsageFlags; |
| 10668 | viewFormats?: GPUTextureFormat[]; |
| 10669 | colorSpace?: "srgb" | "display-p3"; |
| 10670 | alphaMode?: GPUCanvasAlphaMode; |
| 10671 | width: number; |
| 10672 | height: number; |
| 10673 | } |
| 10674 | /** |
| 10675 | * @category GPU |
| 10676 | * @experimental |
| 10677 | */ |
| 10678 | declare interface GPUCanvasContext { |
| 10679 | configure(configuration: GPUCanvasConfiguration): undefined; |
| 10680 | unconfigure(): undefined; |
| 10681 | getCurrentTexture(): GPUTexture; |
| 10682 | } |
| 10683 | |
| 10684 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 10685 | |
| 10686 | // deno-lint-ignore-file no-explicit-any no-var |
| 10687 | |
| 10688 | /// <reference no-default-lib="true" /> |
| 10689 | /// <reference lib="esnext" /> |
| 10690 | |
| 10691 | /** @category WebSockets */ |
| 10692 | declare interface CloseEventInit extends EventInit { |
| 10693 | code?: number; |
| 10694 | reason?: string; |
| 10695 | wasClean?: boolean; |
| 10696 | } |
| 10697 | |
| 10698 | /** @category WebSockets */ |
| 10699 | declare interface CloseEvent extends Event { |
| 10700 | /** |
| 10701 | * Returns the WebSocket connection close code provided by the server. |
| 10702 | */ |
| 10703 | readonly code: number; |
| 10704 | /** |
| 10705 | * Returns the WebSocket connection close reason provided by the server. |
| 10706 | */ |
| 10707 | readonly reason: string; |
| 10708 | /** |
| 10709 | * Returns true if the connection closed cleanly; false otherwise. |
| 10710 | */ |
| 10711 | readonly wasClean: boolean; |
| 10712 | } |
| 10713 | |
| 10714 | /** @category WebSockets */ |
| 10715 | declare var CloseEvent: { |
| 10716 | readonly prototype: CloseEvent; |
| 10717 | new (type: string, eventInitDict?: CloseEventInit): CloseEvent; |
| 10718 | }; |
| 10719 | |
| 10720 | /** @category WebSockets */ |
| 10721 | declare interface WebSocketEventMap { |
| 10722 | close: CloseEvent; |
| 10723 | error: Event; |
| 10724 | message: MessageEvent; |
| 10725 | open: Event; |
| 10726 | } |
| 10727 | |
| 10728 | /** |
| 10729 | * Provides the API for creating and managing a WebSocket connection to a |
| 10730 | * server, as well as for sending and receiving data on the connection. |
| 10731 | * |
| 10732 | * If you are looking to create a WebSocket server, please take a look at |
| 10733 | * `Deno.upgradeWebSocket()`. |
| 10734 | * |
| 10735 | * @tags allow-net |
| 10736 | * @category WebSockets |
| 10737 | */ |
| 10738 | declare interface WebSocket extends EventTarget { |
| 10739 | /** |
| 10740 | * Returns a string that indicates how binary data from the WebSocket object is exposed to scripts: |
| 10741 | * |
| 10742 | * Can be set, to change how binary data is returned. The default is "blob". |
| 10743 | */ |
| 10744 | binaryType: BinaryType; |
| 10745 | /** |
| 10746 | * Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network. |
| 10747 | * |
| 10748 | * If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.) |
| 10749 | */ |
| 10750 | readonly bufferedAmount: number; |
| 10751 | /** |
| 10752 | * Returns the extensions selected by the server, if any. |
| 10753 | */ |
| 10754 | readonly extensions: string; |
| 10755 | onclose: ((this: WebSocket, ev: CloseEvent) => any) | null; |
| 10756 | onerror: ((this: WebSocket, ev: Event | ErrorEvent) => any) | null; |
| 10757 | onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null; |
| 10758 | onopen: ((this: WebSocket, ev: Event) => any) | null; |
| 10759 | /** |
| 10760 | * Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation. |
| 10761 | */ |
| 10762 | readonly protocol: string; |
| 10763 | /** |
| 10764 | * Returns the state of the WebSocket object's connection. It can have the values described below. |
| 10765 | */ |
| 10766 | readonly readyState: number; |
| 10767 | /** |
| 10768 | * Returns the URL that was used to establish the WebSocket connection. |
| 10769 | */ |
| 10770 | readonly url: string; |
| 10771 | /** |
| 10772 | * Closes the WebSocket connection, optionally using code as the WebSocket connection close code and reason as the WebSocket connection close reason. |
| 10773 | */ |
| 10774 | close(code?: number, reason?: string): void; |
| 10775 | /** |
| 10776 | * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView. |
| 10777 | */ |
| 10778 | send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void; |
| 10779 | readonly CLOSED: number; |
| 10780 | readonly CLOSING: number; |
| 10781 | readonly CONNECTING: number; |
| 10782 | readonly OPEN: number; |
| 10783 | addEventListener<K extends keyof WebSocketEventMap>( |
| 10784 | type: K, |
| 10785 | listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, |
| 10786 | options?: boolean | AddEventListenerOptions, |
| 10787 | ): void; |
| 10788 | addEventListener( |
| 10789 | type: string, |
| 10790 | listener: EventListenerOrEventListenerObject, |
| 10791 | options?: boolean | AddEventListenerOptions, |
| 10792 | ): void; |
| 10793 | removeEventListener<K extends keyof WebSocketEventMap>( |
| 10794 | type: K, |
| 10795 | listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, |
| 10796 | options?: boolean | EventListenerOptions, |
| 10797 | ): void; |
| 10798 | removeEventListener( |
| 10799 | type: string, |
| 10800 | listener: EventListenerOrEventListenerObject, |
| 10801 | options?: boolean | EventListenerOptions, |
| 10802 | ): void; |
| 10803 | } |
| 10804 | |
| 10805 | /** @category WebSockets */ |
| 10806 | declare var WebSocket: { |
| 10807 | readonly prototype: WebSocket; |
| 10808 | new (url: string | URL, protocols?: string | string[]): WebSocket; |
| 10809 | readonly CLOSED: number; |
| 10810 | readonly CLOSING: number; |
| 10811 | readonly CONNECTING: number; |
| 10812 | readonly OPEN: number; |
| 10813 | }; |
| 10814 | |
| 10815 | /** @category WebSockets */ |
| 10816 | declare type BinaryType = "arraybuffer" | "blob"; |
| 10817 | |
| 10818 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 10819 | |
| 10820 | // deno-lint-ignore-file no-explicit-any no-var |
| 10821 | |
| 10822 | /// <reference no-default-lib="true" /> |
| 10823 | /// <reference lib="esnext" /> |
| 10824 | |
| 10825 | /** This Web Storage API interface provides access to a particular domain's |
| 10826 | * session or local storage. It allows, for example, the addition, modification, |
| 10827 | * or deletion of stored data items. |
| 10828 | * |
| 10829 | * @category Storage |
| 10830 | */ |
| 10831 | declare interface Storage { |
| 10832 | /** |
| 10833 | * Returns the number of key/value pairs currently present in the list associated with the object. |
| 10834 | */ |
| 10835 | readonly length: number; |
| 10836 | /** |
| 10837 | * Empties the list associated with the object of all key/value pairs, if there are any. |
| 10838 | */ |
| 10839 | clear(): void; |
| 10840 | /** |
| 10841 | * Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object. |
| 10842 | */ |
| 10843 | getItem(key: string): string | null; |
| 10844 | /** |
| 10845 | * Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object. |
| 10846 | */ |
| 10847 | key(index: number): string | null; |
| 10848 | /** |
| 10849 | * Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists. |
| 10850 | */ |
| 10851 | removeItem(key: string): void; |
| 10852 | /** |
| 10853 | * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously. |
| 10854 | * |
| 10855 | * Throws a "QuotaExceededError" DOMException exception if the new value couldn't be set. (Setting could fail if, e.g., the user has disabled storage for the site, or if the quota has been exceeded.) |
| 10856 | */ |
| 10857 | setItem(key: string, value: string): void; |
| 10858 | [name: string]: any; |
| 10859 | } |
| 10860 | |
| 10861 | /** @category Storage */ |
| 10862 | declare var Storage: { |
| 10863 | readonly prototype: Storage; |
| 10864 | new (): never; |
| 10865 | }; |
| 10866 | |
| 10867 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 10868 | |
| 10869 | // deno-lint-ignore-file no-var |
| 10870 | |
| 10871 | /// <reference no-default-lib="true" /> |
| 10872 | /// <reference lib="esnext" /> |
| 10873 | |
| 10874 | /** @category Canvas */ |
| 10875 | declare type ColorSpaceConversion = "default" | "none"; |
| 10876 | |
| 10877 | /** @category Canvas */ |
| 10878 | declare type ImageOrientation = "flipY" | "from-image" | "none"; |
| 10879 | |
| 10880 | /** @category Canvas */ |
| 10881 | declare type PremultiplyAlpha = "default" | "none" | "premultiply"; |
| 10882 | |
| 10883 | /** @category Canvas */ |
| 10884 | declare type ResizeQuality = "high" | "low" | "medium" | "pixelated"; |
| 10885 | |
| 10886 | /** @category Canvas */ |
| 10887 | declare type ImageBitmapSource = Blob | ImageData; |
| 10888 | |
| 10889 | /** @category Canvas */ |
| 10890 | declare interface ImageBitmapOptions { |
| 10891 | colorSpaceConversion?: ColorSpaceConversion; |
| 10892 | imageOrientation?: ImageOrientation; |
| 10893 | premultiplyAlpha?: PremultiplyAlpha; |
| 10894 | resizeHeight?: number; |
| 10895 | resizeQuality?: ResizeQuality; |
| 10896 | resizeWidth?: number; |
| 10897 | } |
| 10898 | |
| 10899 | /** @category Canvas */ |
| 10900 | declare function createImageBitmap( |
| 10901 | image: ImageBitmapSource, |
| 10902 | options?: ImageBitmapOptions, |
| 10903 | ): Promise<ImageBitmap>; |
| 10904 | /** @category Canvas */ |
| 10905 | declare function createImageBitmap( |
| 10906 | image: ImageBitmapSource, |
| 10907 | sx: number, |
| 10908 | sy: number, |
| 10909 | sw: number, |
| 10910 | sh: number, |
| 10911 | options?: ImageBitmapOptions, |
| 10912 | ): Promise<ImageBitmap>; |
| 10913 | |
| 10914 | /** @category Canvas */ |
| 10915 | declare interface ImageBitmap { |
| 10916 | readonly height: number; |
| 10917 | readonly width: number; |
| 10918 | close(): void; |
| 10919 | } |
| 10920 | |
| 10921 | /** @category Canvas */ |
| 10922 | declare var ImageBitmap: { |
| 10923 | prototype: ImageBitmap; |
| 10924 | new (): ImageBitmap; |
| 10925 | }; |
| 10926 | |
| 10927 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 10928 | |
| 10929 | // deno-lint-ignore-file no-var |
| 10930 | |
| 10931 | /// <reference no-default-lib="true" /> |
| 10932 | /// <reference lib="esnext" /> |
| 10933 | |
| 10934 | /** @category Crypto */ |
| 10935 | declare var crypto: Crypto; |
| 10936 | |
| 10937 | /** @category Crypto */ |
| 10938 | declare interface Algorithm { |
| 10939 | name: string; |
| 10940 | } |
| 10941 | |
| 10942 | /** @category Crypto */ |
| 10943 | declare interface KeyAlgorithm { |
| 10944 | name: string; |
| 10945 | } |
| 10946 | |
| 10947 | /** @category Crypto */ |
| 10948 | declare type AlgorithmIdentifier = string | Algorithm; |
| 10949 | /** @category Crypto */ |
| 10950 | declare type HashAlgorithmIdentifier = AlgorithmIdentifier; |
| 10951 | /** @category Crypto */ |
| 10952 | declare type KeyType = "private" | "public" | "secret"; |
| 10953 | /** @category Crypto */ |
| 10954 | declare type KeyUsage = |
| 10955 | | "decrypt" |
| 10956 | | "deriveBits" |
| 10957 | | "deriveKey" |
| 10958 | | "encrypt" |
| 10959 | | "sign" |
| 10960 | | "unwrapKey" |
| 10961 | | "verify" |
| 10962 | | "wrapKey"; |
| 10963 | /** @category Crypto */ |
| 10964 | declare type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki"; |
| 10965 | /** @category Crypto */ |
| 10966 | declare type NamedCurve = string; |
| 10967 | |
| 10968 | /** @category Crypto */ |
| 10969 | declare interface RsaOtherPrimesInfo { |
| 10970 | d?: string; |
| 10971 | r?: string; |
| 10972 | t?: string; |
| 10973 | } |
| 10974 | |
| 10975 | /** @category Crypto */ |
| 10976 | declare interface JsonWebKey { |
| 10977 | alg?: string; |
| 10978 | crv?: string; |
| 10979 | d?: string; |
| 10980 | dp?: string; |
| 10981 | dq?: string; |
| 10982 | e?: string; |
| 10983 | ext?: boolean; |
| 10984 | k?: string; |
| 10985 | key_ops?: string[]; |
| 10986 | kty?: string; |
| 10987 | n?: string; |
| 10988 | oth?: RsaOtherPrimesInfo[]; |
| 10989 | p?: string; |
| 10990 | q?: string; |
| 10991 | qi?: string; |
| 10992 | use?: string; |
| 10993 | x?: string; |
| 10994 | y?: string; |
| 10995 | } |
| 10996 | |
| 10997 | /** @category Crypto */ |
| 10998 | declare interface AesCbcParams extends Algorithm { |
| 10999 | iv: BufferSource; |
| 11000 | } |
| 11001 | |
| 11002 | /** @category Crypto */ |
| 11003 | declare interface AesGcmParams extends Algorithm { |
| 11004 | iv: BufferSource; |
| 11005 | additionalData?: BufferSource; |
| 11006 | tagLength?: number; |
| 11007 | } |
| 11008 | |
| 11009 | /** @category Crypto */ |
| 11010 | declare interface AesCtrParams extends Algorithm { |
| 11011 | counter: BufferSource; |
| 11012 | length: number; |
| 11013 | } |
| 11014 | |
| 11015 | /** @category Crypto */ |
| 11016 | declare interface HmacKeyGenParams extends Algorithm { |
| 11017 | hash: HashAlgorithmIdentifier; |
| 11018 | length?: number; |
| 11019 | } |
| 11020 | |
| 11021 | /** @category Crypto */ |
| 11022 | declare interface EcKeyGenParams extends Algorithm { |
| 11023 | namedCurve: NamedCurve; |
| 11024 | } |
| 11025 | |
| 11026 | /** @category Crypto */ |
| 11027 | declare interface EcKeyImportParams extends Algorithm { |
| 11028 | namedCurve: NamedCurve; |
| 11029 | } |
| 11030 | |
| 11031 | /** @category Crypto */ |
| 11032 | declare interface EcdsaParams extends Algorithm { |
| 11033 | hash: HashAlgorithmIdentifier; |
| 11034 | } |
| 11035 | |
| 11036 | /** @category Crypto */ |
| 11037 | declare interface RsaHashedImportParams extends Algorithm { |
| 11038 | hash: HashAlgorithmIdentifier; |
| 11039 | } |
| 11040 | |
| 11041 | /** @category Crypto */ |
| 11042 | declare interface RsaHashedKeyGenParams extends RsaKeyGenParams { |
| 11043 | hash: HashAlgorithmIdentifier; |
| 11044 | } |
| 11045 | |
| 11046 | /** @category Crypto */ |
| 11047 | declare interface RsaKeyGenParams extends Algorithm { |
| 11048 | modulusLength: number; |
| 11049 | publicExponent: Uint8Array; |
| 11050 | } |
| 11051 | |
| 11052 | /** @category Crypto */ |
| 11053 | declare interface RsaPssParams extends Algorithm { |
| 11054 | saltLength: number; |
| 11055 | } |
| 11056 | |
| 11057 | /** @category Crypto */ |
| 11058 | declare interface RsaOaepParams extends Algorithm { |
| 11059 | label?: Uint8Array; |
| 11060 | } |
| 11061 | |
| 11062 | /** @category Crypto */ |
| 11063 | declare interface HmacImportParams extends Algorithm { |
| 11064 | hash: HashAlgorithmIdentifier; |
| 11065 | length?: number; |
| 11066 | } |
| 11067 | |
| 11068 | /** @category Crypto */ |
| 11069 | declare interface EcKeyAlgorithm extends KeyAlgorithm { |
| 11070 | namedCurve: NamedCurve; |
| 11071 | } |
| 11072 | |
| 11073 | /** @category Crypto */ |
| 11074 | declare interface HmacKeyAlgorithm extends KeyAlgorithm { |
| 11075 | hash: KeyAlgorithm; |
| 11076 | length: number; |
| 11077 | } |
| 11078 | |
| 11079 | /** @category Crypto */ |
| 11080 | declare interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm { |
| 11081 | hash: KeyAlgorithm; |
| 11082 | } |
| 11083 | |
| 11084 | /** @category Crypto */ |
| 11085 | declare interface RsaKeyAlgorithm extends KeyAlgorithm { |
| 11086 | modulusLength: number; |
| 11087 | publicExponent: Uint8Array; |
| 11088 | } |
| 11089 | |
| 11090 | /** @category Crypto */ |
| 11091 | declare interface HkdfParams extends Algorithm { |
| 11092 | hash: HashAlgorithmIdentifier; |
| 11093 | info: BufferSource; |
| 11094 | salt: BufferSource; |
| 11095 | } |
| 11096 | |
| 11097 | /** @category Crypto */ |
| 11098 | declare interface Pbkdf2Params extends Algorithm { |
| 11099 | hash: HashAlgorithmIdentifier; |
| 11100 | iterations: number; |
| 11101 | salt: BufferSource; |
| 11102 | } |
| 11103 | |
| 11104 | /** @category Crypto */ |
| 11105 | declare interface AesDerivedKeyParams extends Algorithm { |
| 11106 | length: number; |
| 11107 | } |
| 11108 | |
| 11109 | /** @category Crypto */ |
| 11110 | declare interface EcdhKeyDeriveParams extends Algorithm { |
| 11111 | public: CryptoKey; |
| 11112 | } |
| 11113 | |
| 11114 | /** @category Crypto */ |
| 11115 | declare interface AesKeyGenParams extends Algorithm { |
| 11116 | length: number; |
| 11117 | } |
| 11118 | |
| 11119 | /** @category Crypto */ |
| 11120 | declare interface AesKeyAlgorithm extends KeyAlgorithm { |
| 11121 | length: number; |
| 11122 | } |
| 11123 | |
| 11124 | /** The CryptoKey dictionary of the Web Crypto API represents a cryptographic |
| 11125 | * key. |
| 11126 | * |
| 11127 | * @category Crypto |
| 11128 | */ |
| 11129 | declare interface CryptoKey { |
| 11130 | readonly algorithm: KeyAlgorithm; |
| 11131 | readonly extractable: boolean; |
| 11132 | readonly type: KeyType; |
| 11133 | readonly usages: KeyUsage[]; |
| 11134 | } |
| 11135 | |
| 11136 | /** @category Crypto */ |
| 11137 | declare var CryptoKey: { |
| 11138 | readonly prototype: CryptoKey; |
| 11139 | new (): never; |
| 11140 | }; |
| 11141 | |
| 11142 | /** The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for |
| 11143 | * an asymmetric cryptography algorithm, also known as a public-key algorithm. |
| 11144 | * |
| 11145 | * @category Crypto |
| 11146 | */ |
| 11147 | declare interface CryptoKeyPair { |
| 11148 | privateKey: CryptoKey; |
| 11149 | publicKey: CryptoKey; |
| 11150 | } |
| 11151 | |
| 11152 | /** @category Crypto */ |
| 11153 | declare var CryptoKeyPair: { |
| 11154 | readonly prototype: CryptoKeyPair; |
| 11155 | new (): never; |
| 11156 | }; |
| 11157 | |
| 11158 | /** This Web Crypto API interface provides a number of low-level cryptographic |
| 11159 | * functions. It is accessed via the Crypto.subtle properties available in a |
| 11160 | * window context (via Window.crypto). |
| 11161 | * |
| 11162 | * @category Crypto |
| 11163 | */ |
| 11164 | declare interface SubtleCrypto { |
| 11165 | generateKey( |
| 11166 | algorithm: RsaHashedKeyGenParams | EcKeyGenParams, |
| 11167 | extractable: boolean, |
| 11168 | keyUsages: KeyUsage[], |
| 11169 | ): Promise<CryptoKeyPair>; |
| 11170 | generateKey( |
| 11171 | algorithm: AesKeyGenParams | HmacKeyGenParams, |
| 11172 | extractable: boolean, |
| 11173 | keyUsages: KeyUsage[], |
| 11174 | ): Promise<CryptoKey>; |
| 11175 | generateKey( |
| 11176 | algorithm: AlgorithmIdentifier, |
| 11177 | extractable: boolean, |
| 11178 | keyUsages: KeyUsage[], |
| 11179 | ): Promise<CryptoKeyPair | CryptoKey>; |
| 11180 | importKey( |
| 11181 | format: "jwk", |
| 11182 | keyData: JsonWebKey, |
| 11183 | algorithm: |
| 11184 | | AlgorithmIdentifier |
| 11185 | | HmacImportParams |
| 11186 | | RsaHashedImportParams |
| 11187 | | EcKeyImportParams, |
| 11188 | extractable: boolean, |
| 11189 | keyUsages: KeyUsage[], |
| 11190 | ): Promise<CryptoKey>; |
| 11191 | importKey( |
| 11192 | format: Exclude<KeyFormat, "jwk">, |
| 11193 | keyData: BufferSource, |
| 11194 | algorithm: |
| 11195 | | AlgorithmIdentifier |
| 11196 | | HmacImportParams |
| 11197 | | RsaHashedImportParams |
| 11198 | | EcKeyImportParams, |
| 11199 | extractable: boolean, |
| 11200 | keyUsages: KeyUsage[], |
| 11201 | ): Promise<CryptoKey>; |
| 11202 | exportKey(format: "jwk", key: CryptoKey): Promise<JsonWebKey>; |
| 11203 | exportKey( |
| 11204 | format: Exclude<KeyFormat, "jwk">, |
| 11205 | key: CryptoKey, |
| 11206 | ): Promise<ArrayBuffer>; |
| 11207 | sign( |
| 11208 | algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams, |
| 11209 | key: CryptoKey, |
| 11210 | data: BufferSource, |
| 11211 | ): Promise<ArrayBuffer>; |
| 11212 | verify( |
| 11213 | algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams, |
| 11214 | key: CryptoKey, |
| 11215 | signature: BufferSource, |
| 11216 | data: BufferSource, |
| 11217 | ): Promise<boolean>; |
| 11218 | digest( |
| 11219 | algorithm: AlgorithmIdentifier, |
| 11220 | data: BufferSource, |
| 11221 | ): Promise<ArrayBuffer>; |
| 11222 | encrypt( |
| 11223 | algorithm: |
| 11224 | | AlgorithmIdentifier |
| 11225 | | RsaOaepParams |
| 11226 | | AesCbcParams |
| 11227 | | AesGcmParams |
| 11228 | | AesCtrParams, |
| 11229 | key: CryptoKey, |
| 11230 | data: BufferSource, |
| 11231 | ): Promise<ArrayBuffer>; |
| 11232 | decrypt( |
| 11233 | algorithm: |
| 11234 | | AlgorithmIdentifier |
| 11235 | | RsaOaepParams |
| 11236 | | AesCbcParams |
| 11237 | | AesGcmParams |
| 11238 | | AesCtrParams, |
| 11239 | key: CryptoKey, |
| 11240 | data: BufferSource, |
| 11241 | ): Promise<ArrayBuffer>; |
| 11242 | deriveBits( |
| 11243 | algorithm: |
| 11244 | | AlgorithmIdentifier |
| 11245 | | HkdfParams |
| 11246 | | Pbkdf2Params |
| 11247 | | EcdhKeyDeriveParams, |
| 11248 | baseKey: CryptoKey, |
| 11249 | length: number, |
| 11250 | ): Promise<ArrayBuffer>; |
| 11251 | deriveKey( |
| 11252 | algorithm: |
| 11253 | | AlgorithmIdentifier |
| 11254 | | HkdfParams |
| 11255 | | Pbkdf2Params |
| 11256 | | EcdhKeyDeriveParams, |
| 11257 | baseKey: CryptoKey, |
| 11258 | derivedKeyType: |
| 11259 | | AlgorithmIdentifier |
| 11260 | | AesDerivedKeyParams |
| 11261 | | HmacImportParams |
| 11262 | | HkdfParams |
| 11263 | | Pbkdf2Params, |
| 11264 | extractable: boolean, |
| 11265 | keyUsages: KeyUsage[], |
| 11266 | ): Promise<CryptoKey>; |
| 11267 | wrapKey( |
| 11268 | format: KeyFormat, |
| 11269 | key: CryptoKey, |
| 11270 | wrappingKey: CryptoKey, |
| 11271 | wrapAlgorithm: |
| 11272 | | AlgorithmIdentifier |
| 11273 | | RsaOaepParams |
| 11274 | | AesCbcParams |
| 11275 | | AesCtrParams, |
| 11276 | ): Promise<ArrayBuffer>; |
| 11277 | unwrapKey( |
| 11278 | format: KeyFormat, |
| 11279 | wrappedKey: BufferSource, |
| 11280 | unwrappingKey: CryptoKey, |
| 11281 | unwrapAlgorithm: |
| 11282 | | AlgorithmIdentifier |
| 11283 | | RsaOaepParams |
| 11284 | | AesCbcParams |
| 11285 | | AesCtrParams, |
| 11286 | unwrappedKeyAlgorithm: |
| 11287 | | AlgorithmIdentifier |
| 11288 | | HmacImportParams |
| 11289 | | RsaHashedImportParams |
| 11290 | | EcKeyImportParams, |
| 11291 | extractable: boolean, |
| 11292 | keyUsages: KeyUsage[], |
| 11293 | ): Promise<CryptoKey>; |
| 11294 | } |
| 11295 | |
| 11296 | /** @category Crypto */ |
| 11297 | declare var SubtleCrypto: { |
| 11298 | readonly prototype: SubtleCrypto; |
| 11299 | new (): never; |
| 11300 | }; |
| 11301 | |
| 11302 | /** @category Crypto */ |
| 11303 | declare interface Crypto { |
| 11304 | readonly subtle: SubtleCrypto; |
| 11305 | getRandomValues< |
| 11306 | T extends |
| 11307 | | Int8Array |
| 11308 | | Int16Array |
| 11309 | | Int32Array |
| 11310 | | Uint8Array |
| 11311 | | Uint16Array |
| 11312 | | Uint32Array |
| 11313 | | Uint8ClampedArray |
| 11314 | | BigInt64Array |
| 11315 | | BigUint64Array, |
| 11316 | >( |
| 11317 | array: T, |
| 11318 | ): T; |
| 11319 | randomUUID(): `${string}-${string}-${string}-${string}-${string}`; |
| 11320 | } |
| 11321 | |
| 11322 | /** @category Crypto */ |
| 11323 | declare var Crypto: { |
| 11324 | readonly prototype: Crypto; |
| 11325 | new (): never; |
| 11326 | }; |
| 11327 | |
| 11328 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 11329 | |
| 11330 | // deno-lint-ignore-file no-explicit-any no-var |
| 11331 | |
| 11332 | /// <reference no-default-lib="true" /> |
| 11333 | /// <reference lib="esnext" /> |
| 11334 | |
| 11335 | /** |
| 11336 | * @category Messaging |
| 11337 | * @experimental |
| 11338 | */ |
| 11339 | declare interface BroadcastChannelEventMap { |
| 11340 | "message": MessageEvent; |
| 11341 | "messageerror": MessageEvent; |
| 11342 | } |
| 11343 | |
| 11344 | /** |
| 11345 | * @category Messaging |
| 11346 | * @experimental |
| 11347 | */ |
| 11348 | declare interface BroadcastChannel extends EventTarget { |
| 11349 | /** |
| 11350 | * Returns the channel name (as passed to the constructor). |
| 11351 | */ |
| 11352 | readonly name: string; |
| 11353 | onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; |
| 11354 | onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; |
| 11355 | /** |
| 11356 | * Closes the BroadcastChannel object, opening it up to garbage collection. |
| 11357 | */ |
| 11358 | close(): void; |
| 11359 | /** |
| 11360 | * Sends the given message to other BroadcastChannel objects set up for |
| 11361 | * this channel. Messages can be structured objects, e.g. nested objects |
| 11362 | * and arrays. |
| 11363 | */ |
| 11364 | postMessage(message: any): void; |
| 11365 | addEventListener<K extends keyof BroadcastChannelEventMap>( |
| 11366 | type: K, |
| 11367 | listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, |
| 11368 | options?: boolean | AddEventListenerOptions, |
| 11369 | ): void; |
| 11370 | addEventListener( |
| 11371 | type: string, |
| 11372 | listener: EventListenerOrEventListenerObject, |
| 11373 | options?: boolean | AddEventListenerOptions, |
| 11374 | ): void; |
| 11375 | removeEventListener<K extends keyof BroadcastChannelEventMap>( |
| 11376 | type: K, |
| 11377 | listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, |
| 11378 | options?: boolean | EventListenerOptions, |
| 11379 | ): void; |
| 11380 | removeEventListener( |
| 11381 | type: string, |
| 11382 | listener: EventListenerOrEventListenerObject, |
| 11383 | options?: boolean | EventListenerOptions, |
| 11384 | ): void; |
| 11385 | } |
| 11386 | |
| 11387 | /** |
| 11388 | * @category Messaging |
| 11389 | * @experimental |
| 11390 | */ |
| 11391 | declare var BroadcastChannel: { |
| 11392 | readonly prototype: BroadcastChannel; |
| 11393 | new (name: string): BroadcastChannel; |
| 11394 | }; |
| 11395 | |
| 11396 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 11397 | |
| 11398 | /// <reference no-default-lib="true" /> |
| 11399 | /// <reference lib="esnext" /> |
| 11400 | /// <reference lib="esnext.disposable" /> |
| 11401 | |
| 11402 | declare namespace Deno { |
| 11403 | /** @category Network */ |
| 11404 | export interface NetAddr { |
| 11405 | transport: "tcp" | "udp"; |
| 11406 | hostname: string; |
| 11407 | port: number; |
| 11408 | } |
| 11409 | |
| 11410 | /** @category Network */ |
| 11411 | export interface UnixAddr { |
| 11412 | transport: "unix" | "unixpacket"; |
| 11413 | path: string; |
| 11414 | } |
| 11415 | |
| 11416 | /** @category Network */ |
| 11417 | export type Addr = NetAddr | UnixAddr; |
| 11418 | |
| 11419 | /** A generic network listener for stream-oriented protocols. |
| 11420 | * |
| 11421 | * @category Network |
| 11422 | */ |
| 11423 | export interface Listener<T extends Conn = Conn, A extends Addr = Addr> |
| 11424 | extends AsyncIterable<T>, Disposable { |
| 11425 | /** Waits for and resolves to the next connection to the `Listener`. */ |
| 11426 | accept(): Promise<T>; |
| 11427 | /** Close closes the listener. Any pending accept promises will be rejected |
| 11428 | * with errors. */ |
| 11429 | close(): void; |
| 11430 | /** Return the address of the `Listener`. */ |
| 11431 | readonly addr: A; |
| 11432 | |
| 11433 | /** |
| 11434 | * Return the rid of the `Listener`. |
| 11435 | * |
| 11436 | * @deprecated This will be removed in Deno 2.0. See the |
| 11437 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11438 | * for migration instructions. |
| 11439 | */ |
| 11440 | readonly rid: number; |
| 11441 | |
| 11442 | [Symbol.asyncIterator](): AsyncIterableIterator<T>; |
| 11443 | |
| 11444 | /** |
| 11445 | * Make the listener block the event loop from finishing. |
| 11446 | * |
| 11447 | * Note: the listener blocks the event loop from finishing by default. |
| 11448 | * This method is only meaningful after `.unref()` is called. |
| 11449 | */ |
| 11450 | ref(): void; |
| 11451 | |
| 11452 | /** Make the listener not block the event loop from finishing. */ |
| 11453 | unref(): void; |
| 11454 | } |
| 11455 | |
| 11456 | /** Specialized listener that accepts TLS connections. |
| 11457 | * |
| 11458 | * @category Network |
| 11459 | */ |
| 11460 | export type TlsListener = Listener<TlsConn, NetAddr>; |
| 11461 | |
| 11462 | /** Specialized listener that accepts TCP connections. |
| 11463 | * |
| 11464 | * @category Network |
| 11465 | */ |
| 11466 | export type TcpListener = Listener<TcpConn, NetAddr>; |
| 11467 | |
| 11468 | /** Specialized listener that accepts Unix connections. |
| 11469 | * |
| 11470 | * @category Network |
| 11471 | */ |
| 11472 | export type UnixListener = Listener<UnixConn, UnixAddr>; |
| 11473 | |
| 11474 | /** @category Network */ |
| 11475 | export interface Conn<A extends Addr = Addr> |
| 11476 | extends Reader, Writer, Closer, Disposable { |
| 11477 | /** The local address of the connection. */ |
| 11478 | readonly localAddr: A; |
| 11479 | /** The remote address of the connection. */ |
| 11480 | readonly remoteAddr: A; |
| 11481 | /** |
| 11482 | * The resource ID of the connection. |
| 11483 | * |
| 11484 | * @deprecated This will be removed in Deno 2.0. See the |
| 11485 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11486 | * for migration instructions. |
| 11487 | */ |
| 11488 | readonly rid: number; |
| 11489 | /** Shuts down (`shutdown(2)`) the write side of the connection. Most |
| 11490 | * callers should just use `close()`. */ |
| 11491 | closeWrite(): Promise<void>; |
| 11492 | |
| 11493 | /** Make the connection block the event loop from finishing. |
| 11494 | * |
| 11495 | * Note: the connection blocks the event loop from finishing by default. |
| 11496 | * This method is only meaningful after `.unref()` is called. |
| 11497 | */ |
| 11498 | ref(): void; |
| 11499 | /** Make the connection not block the event loop from finishing. */ |
| 11500 | unref(): void; |
| 11501 | |
| 11502 | readonly readable: ReadableStream<Uint8Array>; |
| 11503 | readonly writable: WritableStream<Uint8Array>; |
| 11504 | } |
| 11505 | |
| 11506 | /** @category Network */ |
| 11507 | export interface TlsHandshakeInfo { |
| 11508 | /** |
| 11509 | * Contains the ALPN protocol selected during negotiation with the server. |
| 11510 | * If no ALPN protocol selected, returns `null`. |
| 11511 | */ |
| 11512 | alpnProtocol: string | null; |
| 11513 | } |
| 11514 | |
| 11515 | /** @category Network */ |
| 11516 | export interface TlsConn extends Conn<NetAddr> { |
| 11517 | /** Runs the client or server handshake protocol to completion if that has |
| 11518 | * not happened yet. Calling this method is optional; the TLS handshake |
| 11519 | * will be completed automatically as soon as data is sent or received. */ |
| 11520 | handshake(): Promise<TlsHandshakeInfo>; |
| 11521 | /** |
| 11522 | * The resource ID of the connection. |
| 11523 | * |
| 11524 | * @deprecated This will be removed in Deno 2.0. See the |
| 11525 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11526 | * for migration instructions. |
| 11527 | */ |
| 11528 | readonly rid: number; |
| 11529 | } |
| 11530 | |
| 11531 | /** @category Network */ |
| 11532 | export interface ListenOptions { |
| 11533 | /** The port to listen on. |
| 11534 | * |
| 11535 | * Set to `0` to listen on any available port. |
| 11536 | */ |
| 11537 | port: number; |
| 11538 | /** A literal IP address or host name that can be resolved to an IP address. |
| 11539 | * |
| 11540 | * __Note about `0.0.0.0`__ While listening `0.0.0.0` works on all platforms, |
| 11541 | * the browsers on Windows don't work with the address `0.0.0.0`. |
| 11542 | * You should show the message like `server running on localhost:8080` instead of |
| 11543 | * `server running on 0.0.0.0:8080` if your program supports Windows. |
| 11544 | * |
| 11545 | * @default {"0.0.0.0"} */ |
| 11546 | hostname?: string; |
| 11547 | } |
| 11548 | |
| 11549 | /** @category Network */ |
| 11550 | export interface TcpListenOptions extends ListenOptions { |
| 11551 | } |
| 11552 | |
| 11553 | /** Listen announces on the local transport address. |
| 11554 | * |
| 11555 | * ```ts |
| 11556 | * const listener1 = Deno.listen({ port: 80 }) |
| 11557 | * const listener2 = Deno.listen({ hostname: "192.0.2.1", port: 80 }) |
| 11558 | * const listener3 = Deno.listen({ hostname: "[2001:db8::1]", port: 80 }); |
| 11559 | * const listener4 = Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" }); |
| 11560 | * ``` |
| 11561 | * |
| 11562 | * Requires `allow-net` permission. |
| 11563 | * |
| 11564 | * @tags allow-net |
| 11565 | * @category Network |
| 11566 | */ |
| 11567 | export function listen( |
| 11568 | options: TcpListenOptions & { transport?: "tcp" }, |
| 11569 | ): TcpListener; |
| 11570 | |
| 11571 | /** Options which can be set when opening a Unix listener via |
| 11572 | * {@linkcode Deno.listen} or {@linkcode Deno.listenDatagram}. |
| 11573 | * |
| 11574 | * @category Network |
| 11575 | */ |
| 11576 | export interface UnixListenOptions { |
| 11577 | /** A path to the Unix Socket. */ |
| 11578 | path: string; |
| 11579 | } |
| 11580 | |
| 11581 | /** Listen announces on the local transport address. |
| 11582 | * |
| 11583 | * ```ts |
| 11584 | * const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" }) |
| 11585 | * ``` |
| 11586 | * |
| 11587 | * Requires `allow-read` and `allow-write` permission. |
| 11588 | * |
| 11589 | * @tags allow-read, allow-write |
| 11590 | * @category Network |
| 11591 | */ |
| 11592 | // deno-lint-ignore adjacent-overload-signatures |
| 11593 | export function listen( |
| 11594 | options: UnixListenOptions & { transport: "unix" }, |
| 11595 | ): UnixListener; |
| 11596 | |
| 11597 | /** Provides TLS certified keys, ie: a key that has been certified by a trusted certificate authority. |
| 11598 | * A certified key generally consists of a private key and certificate part. |
| 11599 | * |
| 11600 | * @category Network |
| 11601 | */ |
| 11602 | export type TlsCertifiedKeyOptions = |
| 11603 | | TlsCertifiedKeyPem |
| 11604 | | TlsCertifiedKeyFromFile |
| 11605 | | TlsCertifiedKeyConnectTls; |
| 11606 | |
| 11607 | /** |
| 11608 | * Provides certified key material from strings. The key material is provided in |
| 11609 | * `PEM`-format (Privacy Enhanced Mail, https://www.rfc-editor.org/rfc/rfc1422) which can be identified by having |
| 11610 | * `-----BEGIN-----` and `-----END-----` markers at the beginning and end of the strings. This type of key is not compatible |
| 11611 | * with `DER`-format keys which are binary. |
| 11612 | * |
| 11613 | * Deno supports RSA, EC, and PKCS8-format keys. |
| 11614 | * |
| 11615 | * ```ts |
| 11616 | * const key = { |
| 11617 | * key: "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n", |
| 11618 | * cert: "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n" } |
| 11619 | * }; |
| 11620 | * ``` |
| 11621 | * |
| 11622 | * @category Network |
| 11623 | */ |
| 11624 | export interface TlsCertifiedKeyPem { |
| 11625 | /** The format of this key material, which must be PEM. */ |
| 11626 | keyFormat?: "pem"; |
| 11627 | /** Private key in `PEM` format. RSA, EC, and PKCS8-format keys are supported. */ |
| 11628 | key: string; |
| 11629 | /** Certificate chain in `PEM` format. */ |
| 11630 | cert: string; |
| 11631 | } |
| 11632 | |
| 11633 | /** |
| 11634 | * @deprecated This will be removed in Deno 2.0. See the |
| 11635 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11636 | * for migration instructions. |
| 11637 | * |
| 11638 | * @category Network |
| 11639 | */ |
| 11640 | export interface TlsCertifiedKeyFromFile { |
| 11641 | /** Path to a file containing a PEM formatted CA certificate. Requires |
| 11642 | * `--allow-read`. |
| 11643 | * |
| 11644 | * @tags allow-read |
| 11645 | * @deprecated This will be removed in Deno 2.0. See the |
| 11646 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11647 | * for migration instructions. |
| 11648 | */ |
| 11649 | certFile: string; |
| 11650 | /** Path to a file containing a private key file. Requires `--allow-read`. |
| 11651 | * |
| 11652 | * @tags allow-read |
| 11653 | * @deprecated This will be removed in Deno 2.0. See the |
| 11654 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11655 | * for migration instructions. |
| 11656 | */ |
| 11657 | keyFile: string; |
| 11658 | } |
| 11659 | |
| 11660 | /** |
| 11661 | * @deprecated This will be removed in Deno 2.0. See the |
| 11662 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11663 | * for migration instructions. |
| 11664 | * |
| 11665 | * @category Network |
| 11666 | */ |
| 11667 | export interface TlsCertifiedKeyConnectTls { |
| 11668 | /** |
| 11669 | * Certificate chain in `PEM` format. |
| 11670 | * |
| 11671 | * @deprecated This will be removed in Deno 2.0. See the |
| 11672 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11673 | * for migration instructions. |
| 11674 | */ |
| 11675 | certChain: string; |
| 11676 | /** |
| 11677 | * Private key in `PEM` format. RSA, EC, and PKCS8-format keys are supported. |
| 11678 | * |
| 11679 | * @deprecated This will be removed in Deno 2.0. See the |
| 11680 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11681 | * for migration instructions. |
| 11682 | */ |
| 11683 | privateKey: string; |
| 11684 | } |
| 11685 | |
| 11686 | /** @category Network */ |
| 11687 | export interface ListenTlsOptions extends TcpListenOptions { |
| 11688 | transport?: "tcp"; |
| 11689 | |
| 11690 | /** Application-Layer Protocol Negotiation (ALPN) protocols to announce to |
| 11691 | * the client. If not specified, no ALPN extension will be included in the |
| 11692 | * TLS handshake. |
| 11693 | */ |
| 11694 | alpnProtocols?: string[]; |
| 11695 | } |
| 11696 | |
| 11697 | /** Listen announces on the local transport address over TLS (transport layer |
| 11698 | * security). |
| 11699 | * |
| 11700 | * ```ts |
| 11701 | * using listener = Deno.listenTls({ |
| 11702 | * port: 443, |
| 11703 | * cert: Deno.readTextFileSync("./server.crt"), |
| 11704 | * key: Deno.readTextFileSync("./server.key"), |
| 11705 | * }); |
| 11706 | * ``` |
| 11707 | * |
| 11708 | * Requires `allow-net` permission. |
| 11709 | * |
| 11710 | * @tags allow-net |
| 11711 | * @category Network |
| 11712 | */ |
| 11713 | export function listenTls( |
| 11714 | options: ListenTlsOptions & TlsCertifiedKeyOptions, |
| 11715 | ): TlsListener; |
| 11716 | |
| 11717 | /** @category Network */ |
| 11718 | export interface ConnectOptions { |
| 11719 | /** The port to connect to. */ |
| 11720 | port: number; |
| 11721 | /** A literal IP address or host name that can be resolved to an IP address. |
| 11722 | * If not specified, |
| 11723 | * |
| 11724 | * @default {"127.0.0.1"} */ |
| 11725 | hostname?: string; |
| 11726 | transport?: "tcp"; |
| 11727 | } |
| 11728 | |
| 11729 | /** |
| 11730 | * Connects to the hostname (default is "127.0.0.1") and port on the named |
| 11731 | * transport (default is "tcp"), and resolves to the connection (`Conn`). |
| 11732 | * |
| 11733 | * ```ts |
| 11734 | * const conn1 = await Deno.connect({ port: 80 }); |
| 11735 | * const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 }); |
| 11736 | * const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 }); |
| 11737 | * const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" }); |
| 11738 | * ``` |
| 11739 | * |
| 11740 | * Requires `allow-net` permission for "tcp". |
| 11741 | * |
| 11742 | * @tags allow-net |
| 11743 | * @category Network |
| 11744 | */ |
| 11745 | export function connect(options: ConnectOptions): Promise<TcpConn>; |
| 11746 | |
| 11747 | /** @category Network */ |
| 11748 | export interface TcpConn extends Conn<NetAddr> { |
| 11749 | /** |
| 11750 | * Enable/disable the use of Nagle's algorithm. |
| 11751 | * |
| 11752 | * @param [noDelay=true] |
| 11753 | */ |
| 11754 | setNoDelay(noDelay?: boolean): void; |
| 11755 | /** Enable/disable keep-alive functionality. */ |
| 11756 | setKeepAlive(keepAlive?: boolean): void; |
| 11757 | /** |
| 11758 | * The resource ID of the connection. |
| 11759 | * |
| 11760 | * @deprecated This will be removed in Deno 2.0. See the |
| 11761 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11762 | * for migration instructions. |
| 11763 | */ |
| 11764 | readonly rid: number; |
| 11765 | } |
| 11766 | |
| 11767 | /** @category Network */ |
| 11768 | export interface UnixConnectOptions { |
| 11769 | transport: "unix"; |
| 11770 | path: string; |
| 11771 | } |
| 11772 | |
| 11773 | /** @category Network */ |
| 11774 | export interface UnixConn extends Conn<UnixAddr> { |
| 11775 | /** |
| 11776 | * The resource ID of the connection. |
| 11777 | * |
| 11778 | * @deprecated This will be removed in Deno 2.0. See the |
| 11779 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11780 | * for migration instructions. |
| 11781 | */ |
| 11782 | readonly rid: number; |
| 11783 | } |
| 11784 | |
| 11785 | /** Connects to the hostname (default is "127.0.0.1") and port on the named |
| 11786 | * transport (default is "tcp"), and resolves to the connection (`Conn`). |
| 11787 | * |
| 11788 | * ```ts |
| 11789 | * const conn1 = await Deno.connect({ port: 80 }); |
| 11790 | * const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 }); |
| 11791 | * const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 }); |
| 11792 | * const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" }); |
| 11793 | * const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" }); |
| 11794 | * ``` |
| 11795 | * |
| 11796 | * Requires `allow-net` permission for "tcp" and `allow-read` for "unix". |
| 11797 | * |
| 11798 | * @tags allow-net, allow-read |
| 11799 | * @category Network |
| 11800 | */ |
| 11801 | // deno-lint-ignore adjacent-overload-signatures |
| 11802 | export function connect(options: UnixConnectOptions): Promise<UnixConn>; |
| 11803 | |
| 11804 | /** @category Network */ |
| 11805 | export interface ConnectTlsOptions { |
| 11806 | /** The port to connect to. */ |
| 11807 | port: number; |
| 11808 | /** A literal IP address or host name that can be resolved to an IP address. |
| 11809 | * |
| 11810 | * @default {"127.0.0.1"} */ |
| 11811 | hostname?: string; |
| 11812 | /** Path to a file containing a PEM formatted list of root certificates that will |
| 11813 | * be used in addition to the default root certificates to verify the peer's certificate. Requires |
| 11814 | * `--allow-read`. |
| 11815 | * |
| 11816 | * @tags allow-read |
| 11817 | * @deprecated This will be removed in Deno 2.0. See the |
| 11818 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11819 | * for migration instructions. |
| 11820 | */ |
| 11821 | certFile?: string; |
| 11822 | /** A list of root certificates that will be used in addition to the |
| 11823 | * default root certificates to verify the peer's certificate. |
| 11824 | * |
| 11825 | * Must be in PEM format. */ |
| 11826 | caCerts?: string[]; |
| 11827 | /** Application-Layer Protocol Negotiation (ALPN) protocols supported by |
| 11828 | * the client. If not specified, no ALPN extension will be included in the |
| 11829 | * TLS handshake. |
| 11830 | */ |
| 11831 | alpnProtocols?: string[]; |
| 11832 | } |
| 11833 | |
| 11834 | /** Establishes a secure connection over TLS (transport layer security) using |
| 11835 | * an optional cert file, hostname (default is "127.0.0.1") and port. The |
| 11836 | * cert file is optional and if not included Mozilla's root certificates will |
| 11837 | * be used (see also https://github.com/ctz/webpki-roots for specifics) |
| 11838 | * |
| 11839 | * ```ts |
| 11840 | * const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem"); |
| 11841 | * const conn1 = await Deno.connectTls({ port: 80 }); |
| 11842 | * const conn2 = await Deno.connectTls({ caCerts: [caCert], hostname: "192.0.2.1", port: 80 }); |
| 11843 | * const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 }); |
| 11844 | * const conn4 = await Deno.connectTls({ caCerts: [caCert], hostname: "golang.org", port: 80}); |
| 11845 | * ``` |
| 11846 | * |
| 11847 | * Requires `allow-net` permission. |
| 11848 | * |
| 11849 | * @tags allow-net |
| 11850 | * @category Network |
| 11851 | */ |
| 11852 | export function connectTls(options: ConnectTlsOptions): Promise<TlsConn>; |
| 11853 | |
| 11854 | /** Establishes a secure connection over TLS (transport layer security) using |
| 11855 | * an optional cert file, client certificate, hostname (default is "127.0.0.1") and |
| 11856 | * port. The cert file is optional and if not included Mozilla's root certificates will |
| 11857 | * be used (see also https://github.com/ctz/webpki-roots for specifics) |
| 11858 | * |
| 11859 | * ```ts |
| 11860 | * const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem"); |
| 11861 | * const key = "----BEGIN PRIVATE KEY----..."; |
| 11862 | * const cert = "----BEGIN CERTIFICATE----..."; |
| 11863 | * const conn1 = await Deno.connectTls({ port: 80, key, cert }); |
| 11864 | * const conn2 = await Deno.connectTls({ caCerts: [caCert], hostname: "192.0.2.1", port: 80, key, cert }); |
| 11865 | * const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80, key, cert }); |
| 11866 | * const conn4 = await Deno.connectTls({ caCerts: [caCert], hostname: "golang.org", port: 80, key, cert }); |
| 11867 | * ``` |
| 11868 | * |
| 11869 | * Requires `allow-net` permission. |
| 11870 | * |
| 11871 | * @tags allow-net |
| 11872 | * @category Network |
| 11873 | */ |
| 11874 | export function connectTls( |
| 11875 | options: ConnectTlsOptions & TlsCertifiedKeyOptions, |
| 11876 | ): Promise<TlsConn>; |
| 11877 | |
| 11878 | /** @category Network */ |
| 11879 | export interface StartTlsOptions { |
| 11880 | /** A literal IP address or host name that can be resolved to an IP address. |
| 11881 | * |
| 11882 | * @default {"127.0.0.1"} */ |
| 11883 | hostname?: string; |
| 11884 | /** A list of root certificates that will be used in addition to the |
| 11885 | * default root certificates to verify the peer's certificate. |
| 11886 | * |
| 11887 | * Must be in PEM format. */ |
| 11888 | caCerts?: string[]; |
| 11889 | /** Application-Layer Protocol Negotiation (ALPN) protocols to announce to |
| 11890 | * the client. If not specified, no ALPN extension will be included in the |
| 11891 | * TLS handshake. |
| 11892 | */ |
| 11893 | alpnProtocols?: string[]; |
| 11894 | } |
| 11895 | |
| 11896 | /** Start TLS handshake from an existing connection using an optional list of |
| 11897 | * CA certificates, and hostname (default is "127.0.0.1"). Specifying CA certs |
| 11898 | * is optional. By default the configured root certificates are used. Using |
| 11899 | * this function requires that the other end of the connection is prepared for |
| 11900 | * a TLS handshake. |
| 11901 | * |
| 11902 | * Note that this function *consumes* the TCP connection passed to it, thus the |
| 11903 | * original TCP connection will be unusable after calling this. Additionally, |
| 11904 | * you need to ensure that the TCP connection is not being used elsewhere when |
| 11905 | * calling this function in order for the TCP connection to be consumed properly. |
| 11906 | * For instance, if there is a `Promise` that is waiting for read operation on |
| 11907 | * the TCP connection to complete, it is considered that the TCP connection is |
| 11908 | * being used elsewhere. In such a case, this function will fail. |
| 11909 | * |
| 11910 | * ```ts |
| 11911 | * const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" }); |
| 11912 | * const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem"); |
| 11913 | * // `conn` becomes unusable after calling `Deno.startTls` |
| 11914 | * const tlsConn = await Deno.startTls(conn, { caCerts: [caCert], hostname: "localhost" }); |
| 11915 | * ``` |
| 11916 | * |
| 11917 | * Requires `allow-net` permission. |
| 11918 | * |
| 11919 | * @tags allow-net |
| 11920 | * @category Network |
| 11921 | */ |
| 11922 | export function startTls( |
| 11923 | conn: TcpConn, |
| 11924 | options?: StartTlsOptions, |
| 11925 | ): Promise<TlsConn>; |
| 11926 | |
| 11927 | /** Shutdown socket send operations. |
| 11928 | * |
| 11929 | * Matches behavior of POSIX shutdown(3). |
| 11930 | * |
| 11931 | * ```ts |
| 11932 | * const listener = Deno.listen({ port: 80 }); |
| 11933 | * const conn = await listener.accept(); |
| 11934 | * Deno.shutdown(conn.rid); |
| 11935 | * ``` |
| 11936 | * |
| 11937 | * @deprecated This will be removed in Deno 2.0. See the |
| 11938 | * {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide} |
| 11939 | * for migration instructions. |
| 11940 | * |
| 11941 | * @category Network |
| 11942 | */ |
| 11943 | export function shutdown(rid: number): Promise<void>; |
| 11944 | } |
| 11945 | |
| 11946 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 11947 | |
| 11948 | // Documentation partially adapted from [MDN](https://developer.mozilla.org/), |
| 11949 | // by Mozilla Contributors, which is licensed under CC-BY-SA 2.5. |
| 11950 | |
| 11951 | /// <reference no-default-lib="true" /> |
| 11952 | /// <reference lib="esnext" /> |
| 11953 | /// <reference lib="deno.console" /> |
| 11954 | /// <reference lib="deno.url" /> |
| 11955 | /// <reference lib="deno.web" /> |
| 11956 | /// <reference lib="deno.webgpu" /> |
| 11957 | /// <reference lib="deno.canvas" /> |
| 11958 | /// <reference lib="deno.fetch" /> |
| 11959 | /// <reference lib="deno.websocket" /> |
| 11960 | /// <reference lib="deno.crypto" /> |
| 11961 | |
| 11962 | /** @category WASM */ |
| 11963 | declare namespace WebAssembly { |
| 11964 | /** |
| 11965 | * The `WebAssembly.CompileError` object indicates an error during WebAssembly decoding or validation. |
| 11966 | * |
| 11967 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError) |
| 11968 | * |
| 11969 | * @category WASM |
| 11970 | */ |
| 11971 | export class CompileError extends Error { |
| 11972 | /** Creates a new `WebAssembly.CompileError` object. */ |
| 11973 | constructor(message?: string, options?: ErrorOptions); |
| 11974 | } |
| 11975 | |
| 11976 | /** |
| 11977 | * A `WebAssembly.Global` object represents a global variable instance, accessible from |
| 11978 | * both JavaScript and importable/exportable across one or more `WebAssembly.Module` |
| 11979 | * instances. This allows dynamic linking of multiple modules. |
| 11980 | * |
| 11981 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) |
| 11982 | * |
| 11983 | * @category WASM |
| 11984 | */ |
| 11985 | export class Global { |
| 11986 | /** Creates a new `Global` object. */ |
| 11987 | constructor(descriptor: GlobalDescriptor, v?: any); |
| 11988 | |
| 11989 | /** |
| 11990 | * The value contained inside the global variable — this can be used to directly set |
| 11991 | * and get the global's value. |
| 11992 | */ |
| 11993 | value: any; |
| 11994 | |
| 11995 | /** Old-style method that returns the value contained inside the global variable. */ |
| 11996 | valueOf(): any; |
| 11997 | } |
| 11998 | |
| 11999 | /** |
| 12000 | * A `WebAssembly.Instance` object is a stateful, executable instance of a `WebAssembly.Module`. |
| 12001 | * Instance objects contain all the Exported WebAssembly functions that allow calling into |
| 12002 | * WebAssembly code from JavaScript. |
| 12003 | * |
| 12004 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) |
| 12005 | * |
| 12006 | * @category WASM |
| 12007 | */ |
| 12008 | export class Instance { |
| 12009 | /** Creates a new Instance object. */ |
| 12010 | constructor(module: Module, importObject?: Imports); |
| 12011 | |
| 12012 | /** |
| 12013 | * Returns an object containing as its members all the functions exported from the |
| 12014 | * WebAssembly module instance, to allow them to be accessed and used by JavaScript. |
| 12015 | * Read-only. |
| 12016 | */ |
| 12017 | readonly exports: Exports; |
| 12018 | } |
| 12019 | |
| 12020 | /** |
| 12021 | * The `WebAssembly.LinkError` object indicates an error during module instantiation |
| 12022 | * (besides traps from the start function). |
| 12023 | * |
| 12024 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError) |
| 12025 | * |
| 12026 | * @category WASM |
| 12027 | */ |
| 12028 | export class LinkError extends Error { |
| 12029 | /** Creates a new WebAssembly.LinkError object. */ |
| 12030 | constructor(message?: string, options?: ErrorOptions); |
| 12031 | } |
| 12032 | |
| 12033 | /** |
| 12034 | * The `WebAssembly.Memory` object is a resizable `ArrayBuffer` or `SharedArrayBuffer` that |
| 12035 | * holds the raw bytes of memory accessed by a WebAssembly Instance. |
| 12036 | * |
| 12037 | * A memory created by JavaScript or in WebAssembly code will be accessible and mutable |
| 12038 | * from both JavaScript and WebAssembly. |
| 12039 | * |
| 12040 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) |
| 12041 | * |
| 12042 | * @category WASM |
| 12043 | */ |
| 12044 | export class Memory { |
| 12045 | /** Creates a new `Memory` object. */ |
| 12046 | constructor(descriptor: MemoryDescriptor); |
| 12047 | |
| 12048 | /** An accessor property that returns the buffer contained in the memory. */ |
| 12049 | readonly buffer: ArrayBuffer | SharedArrayBuffer; |
| 12050 | |
| 12051 | /** |
| 12052 | * Increases the size of the memory instance by a specified number of WebAssembly |
| 12053 | * pages (each one is 64KB in size). |
| 12054 | */ |
| 12055 | grow(delta: number): number; |
| 12056 | } |
| 12057 | |
| 12058 | /** |
| 12059 | * A `WebAssembly.Module` object contains stateless WebAssembly code that has already been compiled |
| 12060 | * by the browser — this can be efficiently shared with Workers, and instantiated multiple times. |
| 12061 | * |
| 12062 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) |
| 12063 | * |
| 12064 | * @category WASM |
| 12065 | */ |
| 12066 | export class Module { |
| 12067 | /** Creates a new `Module` object. */ |
| 12068 | constructor(bytes: BufferSource); |
| 12069 | |
| 12070 | /** |
| 12071 | * Given a `Module` and string, returns a copy of the contents of all custom sections in the |
| 12072 | * module with the given string name. |
| 12073 | */ |
| 12074 | static customSections( |
| 12075 | moduleObject: Module, |
| 12076 | sectionName: string, |
| 12077 | ): ArrayBuffer[]; |
| 12078 | |
| 12079 | /** Given a `Module`, returns an array containing descriptions of all the declared exports. */ |
| 12080 | static exports(moduleObject: Module): ModuleExportDescriptor[]; |
| 12081 | |
| 12082 | /** Given a `Module`, returns an array containing descriptions of all the declared imports. */ |
| 12083 | static imports(moduleObject: Module): ModuleImportDescriptor[]; |
| 12084 | } |
| 12085 | |
| 12086 | /** |
| 12087 | * The `WebAssembly.RuntimeError` object is the error type that is thrown whenever WebAssembly |
| 12088 | * specifies a trap. |
| 12089 | * |
| 12090 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError) |
| 12091 | * |
| 12092 | * @category WASM |
| 12093 | */ |
| 12094 | export class RuntimeError extends Error { |
| 12095 | /** Creates a new `WebAssembly.RuntimeError` object. */ |
| 12096 | constructor(message?: string, options?: ErrorOptions); |
| 12097 | } |
| 12098 | |
| 12099 | /** |
| 12100 | * The `WebAssembly.Table()` object is a JavaScript wrapper object — an array-like structure |
| 12101 | * representing a WebAssembly Table, which stores function references. A table created by |
| 12102 | * JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript |
| 12103 | * and WebAssembly. |
| 12104 | * |
| 12105 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) |
| 12106 | * |
| 12107 | * @category WASM |
| 12108 | */ |
| 12109 | export class Table { |
| 12110 | /** Creates a new `Table` object. */ |
| 12111 | constructor(descriptor: TableDescriptor); |
| 12112 | |
| 12113 | /** Returns the length of the table, i.e. the number of elements. */ |
| 12114 | readonly length: number; |
| 12115 | |
| 12116 | /** Accessor function — gets the element stored at a given index. */ |
| 12117 | get(index: number): Function | null; |
| 12118 | |
| 12119 | /** Increases the size of the `Table` instance by a specified number of elements. */ |
| 12120 | grow(delta: number): number; |
| 12121 | |
| 12122 | /** Sets an element stored at a given index to a given value. */ |
| 12123 | set(index: number, value: Function | null): void; |
| 12124 | } |
| 12125 | |
| 12126 | /** The `GlobalDescriptor` describes the options you can pass to |
| 12127 | * `new WebAssembly.Global()`. |
| 12128 | * |
| 12129 | * @category WASM |
| 12130 | */ |
| 12131 | export interface GlobalDescriptor { |
| 12132 | mutable?: boolean; |
| 12133 | value: ValueType; |
| 12134 | } |
| 12135 | |
| 12136 | /** The `MemoryDescriptor` describes the options you can pass to |
| 12137 | * `new WebAssembly.Memory()`. |
| 12138 | * |
| 12139 | * @category WASM |
| 12140 | */ |
| 12141 | export interface MemoryDescriptor { |
| 12142 | initial: number; |
| 12143 | maximum?: number; |
| 12144 | shared?: boolean; |
| 12145 | } |
| 12146 | |
| 12147 | /** A `ModuleExportDescriptor` is the description of a declared export in a |
| 12148 | * `WebAssembly.Module`. |
| 12149 | * |
| 12150 | * @category WASM |
| 12151 | */ |
| 12152 | export interface ModuleExportDescriptor { |
| 12153 | kind: ImportExportKind; |
| 12154 | name: string; |
| 12155 | } |
| 12156 | |
| 12157 | /** A `ModuleImportDescriptor` is the description of a declared import in a |
| 12158 | * `WebAssembly.Module`. |
| 12159 | * |
| 12160 | * @category WASM |
| 12161 | */ |
| 12162 | export interface ModuleImportDescriptor { |
| 12163 | kind: ImportExportKind; |
| 12164 | module: string; |
| 12165 | name: string; |
| 12166 | } |
| 12167 | |
| 12168 | /** The `TableDescriptor` describes the options you can pass to |
| 12169 | * `new WebAssembly.Table()`. |
| 12170 | * |
| 12171 | * @category WASM |
| 12172 | */ |
| 12173 | export interface TableDescriptor { |
| 12174 | element: TableKind; |
| 12175 | initial: number; |
| 12176 | maximum?: number; |
| 12177 | } |
| 12178 | |
| 12179 | /** The value returned from `WebAssembly.instantiate`. |
| 12180 | * |
| 12181 | * @category WASM |
| 12182 | */ |
| 12183 | export interface WebAssemblyInstantiatedSource { |
| 12184 | /* A `WebAssembly.Instance` object that contains all the exported WebAssembly functions. */ |
| 12185 | instance: Instance; |
| 12186 | |
| 12187 | /** |
| 12188 | * A `WebAssembly.Module` object representing the compiled WebAssembly module. |
| 12189 | * This `Module` can be instantiated again, or shared via postMessage(). |
| 12190 | */ |
| 12191 | module: Module; |
| 12192 | } |
| 12193 | |
| 12194 | /** @category WASM */ |
| 12195 | export type ImportExportKind = "function" | "global" | "memory" | "table"; |
| 12196 | /** @category WASM */ |
| 12197 | export type TableKind = "anyfunc"; |
| 12198 | /** @category WASM */ |
| 12199 | export type ValueType = "f32" | "f64" | "i32" | "i64"; |
| 12200 | /** @category WASM */ |
| 12201 | export type ExportValue = Function | Global | Memory | Table; |
| 12202 | /** @category WASM */ |
| 12203 | export type Exports = Record<string, ExportValue>; |
| 12204 | /** @category WASM */ |
| 12205 | export type ImportValue = ExportValue | number; |
| 12206 | /** @category WASM */ |
| 12207 | export type ModuleImports = Record<string, ImportValue>; |
| 12208 | /** @category WASM */ |
| 12209 | export type Imports = Record<string, ModuleImports>; |
| 12210 | |
| 12211 | /** |
| 12212 | * The `WebAssembly.compile()` function compiles WebAssembly binary code into a |
| 12213 | * `WebAssembly.Module` object. This function is useful if it is necessary to compile |
| 12214 | * a module before it can be instantiated (otherwise, the `WebAssembly.instantiate()` |
| 12215 | * function should be used). |
| 12216 | * |
| 12217 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) |
| 12218 | * |
| 12219 | * @category WASM |
| 12220 | */ |
| 12221 | export function compile(bytes: BufferSource): Promise<Module>; |
| 12222 | |
| 12223 | /** |
| 12224 | * The `WebAssembly.compileStreaming()` function compiles a `WebAssembly.Module` |
| 12225 | * directly from a streamed underlying source. This function is useful if it is |
| 12226 | * necessary to a compile a module before it can be instantiated (otherwise, the |
| 12227 | * `WebAssembly.instantiateStreaming()` function should be used). |
| 12228 | * |
| 12229 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) |
| 12230 | * |
| 12231 | * @category WASM |
| 12232 | */ |
| 12233 | export function compileStreaming( |
| 12234 | source: Response | Promise<Response>, |
| 12235 | ): Promise<Module>; |
| 12236 | |
| 12237 | /** |
| 12238 | * The WebAssembly.instantiate() function allows you to compile and instantiate |
| 12239 | * WebAssembly code. |
| 12240 | * |
| 12241 | * This overload takes the WebAssembly binary code, in the form of a typed |
| 12242 | * array or ArrayBuffer, and performs both compilation and instantiation in one step. |
| 12243 | * The returned Promise resolves to both a compiled WebAssembly.Module and its first |
| 12244 | * WebAssembly.Instance. |
| 12245 | * |
| 12246 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) |
| 12247 | * |
| 12248 | * @category WASM |
| 12249 | */ |
| 12250 | export function instantiate( |
| 12251 | bytes: BufferSource, |
| 12252 | importObject?: Imports, |
| 12253 | ): Promise<WebAssemblyInstantiatedSource>; |
| 12254 | |
| 12255 | /** |
| 12256 | * The WebAssembly.instantiate() function allows you to compile and instantiate |
| 12257 | * WebAssembly code. |
| 12258 | * |
| 12259 | * This overload takes an already-compiled WebAssembly.Module and returns |
| 12260 | * a Promise that resolves to an Instance of that Module. This overload is useful |
| 12261 | * if the Module has already been compiled. |
| 12262 | * |
| 12263 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) |
| 12264 | * |
| 12265 | * @category WASM |
| 12266 | */ |
| 12267 | export function instantiate( |
| 12268 | moduleObject: Module, |
| 12269 | importObject?: Imports, |
| 12270 | ): Promise<Instance>; |
| 12271 | |
| 12272 | /** |
| 12273 | * The `WebAssembly.instantiateStreaming()` function compiles and instantiates a |
| 12274 | * WebAssembly module directly from a streamed underlying source. This is the most |
| 12275 | * efficient, optimized way to load wasm code. |
| 12276 | * |
| 12277 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming) |
| 12278 | * |
| 12279 | * @category WASM |
| 12280 | */ |
| 12281 | export function instantiateStreaming( |
| 12282 | response: Response | PromiseLike<Response>, |
| 12283 | importObject?: Imports, |
| 12284 | ): Promise<WebAssemblyInstantiatedSource>; |
| 12285 | |
| 12286 | /** |
| 12287 | * The `WebAssembly.validate()` function validates a given typed array of |
| 12288 | * WebAssembly binary code, returning whether the bytes form a valid wasm |
| 12289 | * module (`true`) or not (`false`). |
| 12290 | * |
| 12291 | * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate) |
| 12292 | * |
| 12293 | * @category WASM |
| 12294 | */ |
| 12295 | export function validate(bytes: BufferSource): boolean; |
| 12296 | } |
| 12297 | |
| 12298 | /** Sets a timer which executes a function once after the delay (in milliseconds) elapses. Returns |
| 12299 | * an id which may be used to cancel the timeout. |
| 12300 | * |
| 12301 | * ```ts |
| 12302 | * setTimeout(() => { console.log('hello'); }, 500); |
| 12303 | * ``` |
| 12304 | * |
| 12305 | * @category Platform |
| 12306 | */ |
| 12307 | declare function setTimeout( |
| 12308 | /** callback function to execute when timer expires */ |
| 12309 | cb: (...args: any[]) => void, |
| 12310 | /** delay in ms */ |
| 12311 | delay?: number, |
| 12312 | /** arguments passed to callback function */ |
| 12313 | ...args: any[] |
| 12314 | ): number; |
| 12315 | |
| 12316 | /** Repeatedly calls a function , with a fixed time delay between each call. |
| 12317 | * |
| 12318 | * ```ts |
| 12319 | * // Outputs 'hello' to the console every 500ms |
| 12320 | * setInterval(() => { console.log('hello'); }, 500); |
| 12321 | * ``` |
| 12322 | * |
| 12323 | * @category Platform |
| 12324 | */ |
| 12325 | declare function setInterval( |
| 12326 | /** callback function to execute when timer expires */ |
| 12327 | cb: (...args: any[]) => void, |
| 12328 | /** delay in ms */ |
| 12329 | delay?: number, |
| 12330 | /** arguments passed to callback function */ |
| 12331 | ...args: any[] |
| 12332 | ): number; |
| 12333 | |
| 12334 | /** Cancels a timed, repeating action which was previously started by a call |
| 12335 | * to `setInterval()` |
| 12336 | * |
| 12337 | * ```ts |
| 12338 | * const id = setInterval(() => {console.log('hello');}, 500); |
| 12339 | * // ... |
| 12340 | * clearInterval(id); |
| 12341 | * ``` |
| 12342 | * |
| 12343 | * @category Platform |
| 12344 | */ |
| 12345 | declare function clearInterval(id?: number): void; |
| 12346 | |
| 12347 | /** Cancels a scheduled action initiated by `setTimeout()` |
| 12348 | * |
| 12349 | * ```ts |
| 12350 | * const id = setTimeout(() => {console.log('hello');}, 500); |
| 12351 | * // ... |
| 12352 | * clearTimeout(id); |
| 12353 | * ``` |
| 12354 | * |
| 12355 | * @category Platform |
| 12356 | */ |
| 12357 | declare function clearTimeout(id?: number): void; |
| 12358 | |
| 12359 | /** @category Platform */ |
| 12360 | declare interface VoidFunction { |
| 12361 | (): void; |
| 12362 | } |
| 12363 | |
| 12364 | /** A microtask is a short function which is executed after the function or |
| 12365 | * module which created it exits and only if the JavaScript execution stack is |
| 12366 | * empty, but before returning control to the event loop being used to drive the |
| 12367 | * script's execution environment. This event loop may be either the main event |
| 12368 | * loop or the event loop driving a web worker. |
| 12369 | * |
| 12370 | * ```ts |
| 12371 | * queueMicrotask(() => { console.log('This event loop stack is complete'); }); |
| 12372 | * ``` |
| 12373 | * |
| 12374 | * @category Platform |
| 12375 | */ |
| 12376 | declare function queueMicrotask(func: VoidFunction): void; |
| 12377 | |
| 12378 | /** Dispatches an event in the global scope, synchronously invoking any |
| 12379 | * registered event listeners for this event in the appropriate order. Returns |
| 12380 | * false if event is cancelable and at least one of the event handlers which |
| 12381 | * handled this event called Event.preventDefault(). Otherwise it returns true. |
| 12382 | * |
| 12383 | * ```ts |
| 12384 | * dispatchEvent(new Event('unload')); |
| 12385 | * ``` |
| 12386 | * |
| 12387 | * @category Events |
| 12388 | */ |
| 12389 | declare function dispatchEvent(event: Event): boolean; |
| 12390 | |
| 12391 | /** @category Platform */ |
| 12392 | declare interface DOMStringList { |
| 12393 | /** Returns the number of strings in strings. */ |
| 12394 | readonly length: number; |
| 12395 | /** Returns true if strings contains string, and false otherwise. */ |
| 12396 | contains(string: string): boolean; |
| 12397 | /** Returns the string with index index from strings. */ |
| 12398 | item(index: number): string | null; |
| 12399 | [index: number]: string; |
| 12400 | } |
| 12401 | |
| 12402 | /** @category Platform */ |
| 12403 | declare type BufferSource = ArrayBufferView | ArrayBuffer; |
| 12404 | |
| 12405 | /** @category I/O */ |
| 12406 | declare var console: Console; |
| 12407 | |
| 12408 | /** @category Events */ |
| 12409 | declare interface ErrorEventInit extends EventInit { |
| 12410 | message?: string; |
| 12411 | filename?: string; |
| 12412 | lineno?: number; |
| 12413 | colno?: number; |
| 12414 | error?: any; |
| 12415 | } |
| 12416 | |
| 12417 | /** @category Events */ |
| 12418 | declare interface ErrorEvent extends Event { |
| 12419 | readonly message: string; |
| 12420 | readonly filename: string; |
| 12421 | readonly lineno: number; |
| 12422 | readonly colno: number; |
| 12423 | readonly error: any; |
| 12424 | } |
| 12425 | |
| 12426 | /** @category Events */ |
| 12427 | declare var ErrorEvent: { |
| 12428 | readonly prototype: ErrorEvent; |
| 12429 | new (type: string, eventInitDict?: ErrorEventInit): ErrorEvent; |
| 12430 | }; |
| 12431 | |
| 12432 | /** @category Events */ |
| 12433 | declare interface PromiseRejectionEventInit extends EventInit { |
| 12434 | promise: Promise<any>; |
| 12435 | reason?: any; |
| 12436 | } |
| 12437 | |
| 12438 | /** @category Events */ |
| 12439 | declare interface PromiseRejectionEvent extends Event { |
| 12440 | readonly promise: Promise<any>; |
| 12441 | readonly reason: any; |
| 12442 | } |
| 12443 | |
| 12444 | /** @category Events */ |
| 12445 | declare var PromiseRejectionEvent: { |
| 12446 | readonly prototype: PromiseRejectionEvent; |
| 12447 | new ( |
| 12448 | type: string, |
| 12449 | eventInitDict?: PromiseRejectionEventInit, |
| 12450 | ): PromiseRejectionEvent; |
| 12451 | }; |
| 12452 | |
| 12453 | /** @category Workers */ |
| 12454 | declare interface AbstractWorkerEventMap { |
| 12455 | "error": ErrorEvent; |
| 12456 | } |
| 12457 | |
| 12458 | /** @category Workers */ |
| 12459 | declare interface WorkerEventMap extends AbstractWorkerEventMap { |
| 12460 | "message": MessageEvent; |
| 12461 | "messageerror": MessageEvent; |
| 12462 | } |
| 12463 | |
| 12464 | /** @category Workers */ |
| 12465 | declare interface WorkerOptions { |
| 12466 | type?: "classic" | "module"; |
| 12467 | name?: string; |
| 12468 | } |
| 12469 | |
| 12470 | /** @category Workers */ |
| 12471 | declare interface Worker extends EventTarget { |
| 12472 | onerror: (this: Worker, e: ErrorEvent) => any | null; |
| 12473 | onmessage: (this: Worker, e: MessageEvent) => any | null; |
| 12474 | onmessageerror: (this: Worker, e: MessageEvent) => any | null; |
| 12475 | postMessage(message: any, transfer: Transferable[]): void; |
| 12476 | postMessage(message: any, options?: StructuredSerializeOptions): void; |
| 12477 | addEventListener<K extends keyof WorkerEventMap>( |
| 12478 | type: K, |
| 12479 | listener: (this: Worker, ev: WorkerEventMap[K]) => any, |
| 12480 | options?: boolean | AddEventListenerOptions, |
| 12481 | ): void; |
| 12482 | addEventListener( |
| 12483 | type: string, |
| 12484 | listener: EventListenerOrEventListenerObject, |
| 12485 | options?: boolean | AddEventListenerOptions, |
| 12486 | ): void; |
| 12487 | removeEventListener<K extends keyof WorkerEventMap>( |
| 12488 | type: K, |
| 12489 | listener: (this: Worker, ev: WorkerEventMap[K]) => any, |
| 12490 | options?: boolean | EventListenerOptions, |
| 12491 | ): void; |
| 12492 | removeEventListener( |
| 12493 | type: string, |
| 12494 | listener: EventListenerOrEventListenerObject, |
| 12495 | options?: boolean | EventListenerOptions, |
| 12496 | ): void; |
| 12497 | terminate(): void; |
| 12498 | } |
| 12499 | |
| 12500 | /** @category Workers */ |
| 12501 | declare var Worker: { |
| 12502 | readonly prototype: Worker; |
| 12503 | new (specifier: string | URL, options?: WorkerOptions): Worker; |
| 12504 | }; |
| 12505 | |
| 12506 | /** @category Performance */ |
| 12507 | declare type PerformanceEntryList = PerformanceEntry[]; |
| 12508 | |
| 12509 | /** @category Performance */ |
| 12510 | declare interface Performance extends EventTarget { |
| 12511 | /** Returns a timestamp representing the start of the performance measurement. */ |
| 12512 | readonly timeOrigin: number; |
| 12513 | |
| 12514 | /** Removes the stored timestamp with the associated name. */ |
| 12515 | clearMarks(markName?: string): void; |
| 12516 | |
| 12517 | /** Removes stored timestamp with the associated name. */ |
| 12518 | clearMeasures(measureName?: string): void; |
| 12519 | |
| 12520 | getEntries(): PerformanceEntryList; |
| 12521 | getEntriesByName(name: string, type?: string): PerformanceEntryList; |
| 12522 | getEntriesByType(type: string): PerformanceEntryList; |
| 12523 | |
| 12524 | /** Stores a timestamp with the associated name (a "mark"). */ |
| 12525 | mark(markName: string, options?: PerformanceMarkOptions): PerformanceMark; |
| 12526 | |
| 12527 | /** Stores the `DOMHighResTimeStamp` duration between two marks along with the |
| 12528 | * associated name (a "measure"). */ |
| 12529 | measure( |
| 12530 | measureName: string, |
| 12531 | options?: PerformanceMeasureOptions, |
| 12532 | ): PerformanceMeasure; |
| 12533 | /** Stores the `DOMHighResTimeStamp` duration between two marks along with the |
| 12534 | * associated name (a "measure"). */ |
| 12535 | measure( |
| 12536 | measureName: string, |
| 12537 | startMark?: string, |
| 12538 | endMark?: string, |
| 12539 | ): PerformanceMeasure; |
| 12540 | |
| 12541 | /** Returns a current time from Deno's start in milliseconds. |
| 12542 | * |
| 12543 | * Use the permission flag `--allow-hrtime` to return a precise value. |
| 12544 | * |
| 12545 | * ```ts |
| 12546 | * const t = performance.now(); |
| 12547 | * console.log(`${t} ms since start!`); |
| 12548 | * ``` |
| 12549 | * |
| 12550 | * @tags allow-hrtime |
| 12551 | */ |
| 12552 | now(): number; |
| 12553 | |
| 12554 | /** Returns a JSON representation of the performance object. */ |
| 12555 | toJSON(): any; |
| 12556 | } |
| 12557 | |
| 12558 | /** @category Performance */ |
| 12559 | declare var Performance: { |
| 12560 | readonly prototype: Performance; |
| 12561 | new (): never; |
| 12562 | }; |
| 12563 | |
| 12564 | /** @category Performance */ |
| 12565 | declare var performance: Performance; |
| 12566 | |
| 12567 | /** @category Performance */ |
| 12568 | declare interface PerformanceMarkOptions { |
| 12569 | /** Metadata to be included in the mark. */ |
| 12570 | detail?: any; |
| 12571 | |
| 12572 | /** Timestamp to be used as the mark time. */ |
| 12573 | startTime?: number; |
| 12574 | } |
| 12575 | |
| 12576 | /** @category Performance */ |
| 12577 | declare interface PerformanceMeasureOptions { |
| 12578 | /** Metadata to be included in the measure. */ |
| 12579 | detail?: any; |
| 12580 | |
| 12581 | /** Timestamp to be used as the start time or string to be used as start |
| 12582 | * mark. */ |
| 12583 | start?: string | number; |
| 12584 | |
| 12585 | /** Duration between the start and end times. */ |
| 12586 | duration?: number; |
| 12587 | |
| 12588 | /** Timestamp to be used as the end time or string to be used as end mark. */ |
| 12589 | end?: string | number; |
| 12590 | } |
| 12591 | |
| 12592 | /** Encapsulates a single performance metric that is part of the performance |
| 12593 | * timeline. A performance entry can be directly created by making a performance |
| 12594 | * mark or measure (for example by calling the `.mark()` method) at an explicit |
| 12595 | * point in an application. |
| 12596 | * |
| 12597 | * @category Performance |
| 12598 | */ |
| 12599 | declare interface PerformanceEntry { |
| 12600 | readonly duration: number; |
| 12601 | readonly entryType: string; |
| 12602 | readonly name: string; |
| 12603 | readonly startTime: number; |
| 12604 | toJSON(): any; |
| 12605 | } |
| 12606 | |
| 12607 | /** Encapsulates a single performance metric that is part of the performance |
| 12608 | * timeline. A performance entry can be directly created by making a performance |
| 12609 | * mark or measure (for example by calling the `.mark()` method) at an explicit |
| 12610 | * point in an application. |
| 12611 | * |
| 12612 | * @category Performance |
| 12613 | */ |
| 12614 | declare var PerformanceEntry: { |
| 12615 | readonly prototype: PerformanceEntry; |
| 12616 | new (): never; |
| 12617 | }; |
| 12618 | |
| 12619 | /** `PerformanceMark` is an abstract interface for `PerformanceEntry` objects |
| 12620 | * with an entryType of `"mark"`. Entries of this type are created by calling |
| 12621 | * `performance.mark()` to add a named `DOMHighResTimeStamp` (the mark) to the |
| 12622 | * performance timeline. |
| 12623 | * |
| 12624 | * @category Performance |
| 12625 | */ |
| 12626 | declare interface PerformanceMark extends PerformanceEntry { |
| 12627 | readonly detail: any; |
| 12628 | readonly entryType: "mark"; |
| 12629 | } |
| 12630 | |
| 12631 | /** `PerformanceMark` is an abstract interface for `PerformanceEntry` objects |
| 12632 | * with an entryType of `"mark"`. Entries of this type are created by calling |
| 12633 | * `performance.mark()` to add a named `DOMHighResTimeStamp` (the mark) to the |
| 12634 | * performance timeline. |
| 12635 | * |
| 12636 | * @category Performance |
| 12637 | */ |
| 12638 | declare var PerformanceMark: { |
| 12639 | readonly prototype: PerformanceMark; |
| 12640 | new (name: string, options?: PerformanceMarkOptions): PerformanceMark; |
| 12641 | }; |
| 12642 | |
| 12643 | /** `PerformanceMeasure` is an abstract interface for `PerformanceEntry` objects |
| 12644 | * with an entryType of `"measure"`. Entries of this type are created by calling |
| 12645 | * `performance.measure()` to add a named `DOMHighResTimeStamp` (the measure) |
| 12646 | * between two marks to the performance timeline. |
| 12647 | * |
| 12648 | * @category Performance |
| 12649 | */ |
| 12650 | declare interface PerformanceMeasure extends PerformanceEntry { |
| 12651 | readonly detail: any; |
| 12652 | readonly entryType: "measure"; |
| 12653 | } |
| 12654 | |
| 12655 | /** `PerformanceMeasure` is an abstract interface for `PerformanceEntry` objects |
| 12656 | * with an entryType of `"measure"`. Entries of this type are created by calling |
| 12657 | * `performance.measure()` to add a named `DOMHighResTimeStamp` (the measure) |
| 12658 | * between two marks to the performance timeline. |
| 12659 | * |
| 12660 | * @category Performance |
| 12661 | */ |
| 12662 | declare var PerformanceMeasure: { |
| 12663 | readonly prototype: PerformanceMeasure; |
| 12664 | new (): never; |
| 12665 | }; |
| 12666 | |
| 12667 | /** @category Events */ |
| 12668 | declare interface CustomEventInit<T = any> extends EventInit { |
| 12669 | detail?: T; |
| 12670 | } |
| 12671 | |
| 12672 | /** @category Events */ |
| 12673 | declare interface CustomEvent<T = any> extends Event { |
| 12674 | /** Returns any custom data event was created with. Typically used for |
| 12675 | * synthetic events. */ |
| 12676 | readonly detail: T; |
| 12677 | } |
| 12678 | |
| 12679 | /** @category Events */ |
| 12680 | declare var CustomEvent: { |
| 12681 | readonly prototype: CustomEvent; |
| 12682 | new <T>(typeArg: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>; |
| 12683 | }; |
| 12684 | |
| 12685 | /** @category Platform */ |
| 12686 | declare interface ErrorConstructor { |
| 12687 | /** See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions. */ |
| 12688 | captureStackTrace(error: Object, constructor?: Function): void; |
| 12689 | // TODO(nayeemrmn): Support `Error.prepareStackTrace()`. We currently use this |
| 12690 | // internally in a way that makes it unavailable for users. |
| 12691 | } |
| 12692 | |
| 12693 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 12694 | |
| 12695 | // deno-lint-ignore-file no-var |
| 12696 | |
| 12697 | /// <reference no-default-lib="true" /> |
| 12698 | /// <reference lib="esnext" /> |
| 12699 | |
| 12700 | /** @category Cache */ |
| 12701 | declare var caches: CacheStorage; |
| 12702 | |
| 12703 | /** @category Cache */ |
| 12704 | declare interface CacheStorage { |
| 12705 | /** Open a cache storage for the provided name. */ |
| 12706 | open(cacheName: string): Promise<Cache>; |
| 12707 | /** Check if cache already exists for the provided name. */ |
| 12708 | has(cacheName: string): Promise<boolean>; |
| 12709 | /** Delete cache storage for the provided name. */ |
| 12710 | delete(cacheName: string): Promise<boolean>; |
| 12711 | } |
| 12712 | |
| 12713 | /** @category Cache */ |
| 12714 | declare interface Cache { |
| 12715 | /** |
| 12716 | * Put the provided request/response into the cache. |
| 12717 | * |
| 12718 | * How is the API different from browsers? |
| 12719 | * 1. You cannot match cache objects using by relative paths. |
| 12720 | * 2. You cannot pass options like `ignoreVary`, `ignoreMethod`, `ignoreSearch`. |
| 12721 | */ |
| 12722 | put(request: RequestInfo | URL, response: Response): Promise<void>; |
| 12723 | /** |
| 12724 | * Return cache object matching the provided request. |
| 12725 | * |
| 12726 | * How is the API different from browsers? |
| 12727 | * 1. You cannot match cache objects using by relative paths. |
| 12728 | * 2. You cannot pass options like `ignoreVary`, `ignoreMethod`, `ignoreSearch`. |
| 12729 | */ |
| 12730 | match( |
| 12731 | request: RequestInfo | URL, |
| 12732 | options?: CacheQueryOptions, |
| 12733 | ): Promise<Response | undefined>; |
| 12734 | /** |
| 12735 | * Delete cache object matching the provided request. |
| 12736 | * |
| 12737 | * How is the API different from browsers? |
| 12738 | * 1. You cannot delete cache objects using by relative paths. |
| 12739 | * 2. You cannot pass options like `ignoreVary`, `ignoreMethod`, `ignoreSearch`. |
| 12740 | */ |
| 12741 | delete( |
| 12742 | request: RequestInfo | URL, |
| 12743 | options?: CacheQueryOptions, |
| 12744 | ): Promise<boolean>; |
| 12745 | } |
| 12746 | |
| 12747 | /** @category Cache */ |
| 12748 | declare var Cache: { |
| 12749 | readonly prototype: Cache; |
| 12750 | new (): never; |
| 12751 | }; |
| 12752 | |
| 12753 | /** @category Cache */ |
| 12754 | declare var CacheStorage: { |
| 12755 | readonly prototype: CacheStorage; |
| 12756 | new (): never; |
| 12757 | }; |
| 12758 | |
| 12759 | /** @category Cache */ |
| 12760 | declare interface CacheQueryOptions { |
| 12761 | ignoreMethod?: boolean; |
| 12762 | ignoreSearch?: boolean; |
| 12763 | ignoreVary?: boolean; |
| 12764 | } |
| 12765 | |
| 12766 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 12767 | |
| 12768 | /// <reference no-default-lib="true" /> |
| 12769 | /// <reference lib="deno.ns" /> |
| 12770 | /// <reference lib="deno.shared_globals" /> |
| 12771 | /// <reference lib="deno.webstorage" /> |
| 12772 | /// <reference lib="esnext" /> |
| 12773 | /// <reference lib="deno.cache" /> |
| 12774 | |
| 12775 | /** @category Platform */ |
| 12776 | declare interface WindowEventMap { |
| 12777 | "error": ErrorEvent; |
| 12778 | "unhandledrejection": PromiseRejectionEvent; |
| 12779 | "rejectionhandled": PromiseRejectionEvent; |
| 12780 | } |
| 12781 | |
| 12782 | /** @category Platform */ |
| 12783 | declare interface Window extends EventTarget { |
| 12784 | readonly window: Window & typeof globalThis; |
| 12785 | readonly self: Window & typeof globalThis; |
| 12786 | onerror: ((this: Window, ev: ErrorEvent) => any) | null; |
| 12787 | onload: ((this: Window, ev: Event) => any) | null; |
| 12788 | onbeforeunload: ((this: Window, ev: Event) => any) | null; |
| 12789 | onunload: ((this: Window, ev: Event) => any) | null; |
| 12790 | onunhandledrejection: |
| 12791 | | ((this: Window, ev: PromiseRejectionEvent) => any) |
| 12792 | | null; |
| 12793 | onrejectionhandled: |
| 12794 | | ((this: Window, ev: PromiseRejectionEvent) => any) |
| 12795 | | null; |
| 12796 | close: () => void; |
| 12797 | readonly closed: boolean; |
| 12798 | alert: (message?: string) => void; |
| 12799 | confirm: (message?: string) => boolean; |
| 12800 | prompt: (message?: string, defaultValue?: string) => string | null; |
| 12801 | Deno: typeof Deno; |
| 12802 | Navigator: typeof Navigator; |
| 12803 | navigator: Navigator; |
| 12804 | Location: typeof Location; |
| 12805 | location: Location; |
| 12806 | localStorage: Storage; |
| 12807 | sessionStorage: Storage; |
| 12808 | caches: CacheStorage; |
| 12809 | name: string; |
| 12810 | |
| 12811 | addEventListener<K extends keyof WindowEventMap>( |
| 12812 | type: K, |
| 12813 | listener: ( |
| 12814 | this: Window, |
| 12815 | ev: WindowEventMap[K], |
| 12816 | ) => any, |
| 12817 | options?: boolean | AddEventListenerOptions, |
| 12818 | ): void; |
| 12819 | addEventListener( |
| 12820 | type: string, |
| 12821 | listener: EventListenerOrEventListenerObject, |
| 12822 | options?: boolean | AddEventListenerOptions, |
| 12823 | ): void; |
| 12824 | removeEventListener<K extends keyof WindowEventMap>( |
| 12825 | type: K, |
| 12826 | listener: ( |
| 12827 | this: Window, |
| 12828 | ev: WindowEventMap[K], |
| 12829 | ) => any, |
| 12830 | options?: boolean | EventListenerOptions, |
| 12831 | ): void; |
| 12832 | removeEventListener( |
| 12833 | type: string, |
| 12834 | listener: EventListenerOrEventListenerObject, |
| 12835 | options?: boolean | EventListenerOptions, |
| 12836 | ): void; |
| 12837 | } |
| 12838 | |
| 12839 | /** @category Platform */ |
| 12840 | declare var Window: { |
| 12841 | readonly prototype: Window; |
| 12842 | new (): never; |
| 12843 | }; |
| 12844 | |
| 12845 | /** @category Platform */ |
| 12846 | declare var window: Window & typeof globalThis; |
| 12847 | /** @category Platform */ |
| 12848 | declare var self: Window & typeof globalThis; |
| 12849 | /** @category Platform */ |
| 12850 | declare var closed: boolean; |
| 12851 | /** @category Platform */ |
| 12852 | declare function close(): void; |
| 12853 | /** @category Events */ |
| 12854 | declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null; |
| 12855 | /** @category Events */ |
| 12856 | declare var onload: ((this: Window, ev: Event) => any) | null; |
| 12857 | /** @category Events */ |
| 12858 | declare var onbeforeunload: ((this: Window, ev: Event) => any) | null; |
| 12859 | /** @category Events */ |
| 12860 | declare var onunload: ((this: Window, ev: Event) => any) | null; |
| 12861 | /** @category Events */ |
| 12862 | declare var onunhandledrejection: |
| 12863 | | ((this: Window, ev: PromiseRejectionEvent) => any) |
| 12864 | | null; |
| 12865 | /** @category Storage */ |
| 12866 | declare var localStorage: Storage; |
| 12867 | /** @category Storage */ |
| 12868 | declare var sessionStorage: Storage; |
| 12869 | /** @category Cache */ |
| 12870 | declare var caches: CacheStorage; |
| 12871 | |
| 12872 | /** @category Platform */ |
| 12873 | declare interface Navigator { |
| 12874 | readonly gpu: GPU; |
| 12875 | readonly hardwareConcurrency: number; |
| 12876 | readonly userAgent: string; |
| 12877 | readonly language: string; |
| 12878 | readonly languages: string[]; |
| 12879 | } |
| 12880 | |
| 12881 | /** @category Platform */ |
| 12882 | declare var Navigator: { |
| 12883 | readonly prototype: Navigator; |
| 12884 | new (): never; |
| 12885 | }; |
| 12886 | |
| 12887 | /** @category Platform */ |
| 12888 | declare var navigator: Navigator; |
| 12889 | |
| 12890 | /** |
| 12891 | * Shows the given message and waits for the enter key pressed. |
| 12892 | * |
| 12893 | * If the stdin is not interactive, it does nothing. |
| 12894 | * |
| 12895 | * @category Platform |
| 12896 | * |
| 12897 | * @param message |
| 12898 | */ |
| 12899 | declare function alert(message?: string): void; |
| 12900 | |
| 12901 | /** |
| 12902 | * Shows the given message and waits for the answer. Returns the user's answer as boolean. |
| 12903 | * |
| 12904 | * Only `y` and `Y` are considered as true. |
| 12905 | * |
| 12906 | * If the stdin is not interactive, it returns false. |
| 12907 | * |
| 12908 | * @category Platform |
| 12909 | * |
| 12910 | * @param message |
| 12911 | */ |
| 12912 | declare function confirm(message?: string): boolean; |
| 12913 | |
| 12914 | /** |
| 12915 | * Shows the given message and waits for the user's input. Returns the user's input as string. |
| 12916 | * |
| 12917 | * If the default value is given and the user inputs the empty string, then it returns the given |
| 12918 | * default value. |
| 12919 | * |
| 12920 | * If the default value is not given and the user inputs the empty string, it returns the empty |
| 12921 | * string. |
| 12922 | * |
| 12923 | * If the stdin is not interactive, it returns null. |
| 12924 | * |
| 12925 | * @category Platform |
| 12926 | * |
| 12927 | * @param message |
| 12928 | * @param defaultValue |
| 12929 | */ |
| 12930 | declare function prompt(message?: string, defaultValue?: string): string | null; |
| 12931 | |
| 12932 | /** Registers an event listener in the global scope, which will be called |
| 12933 | * synchronously whenever the event `type` is dispatched. |
| 12934 | * |
| 12935 | * ```ts |
| 12936 | * addEventListener('unload', () => { console.log('All finished!'); }); |
| 12937 | * ... |
| 12938 | * dispatchEvent(new Event('unload')); |
| 12939 | * ``` |
| 12940 | * |
| 12941 | * @category Events |
| 12942 | */ |
| 12943 | declare function addEventListener< |
| 12944 | K extends keyof WindowEventMap, |
| 12945 | >( |
| 12946 | type: K, |
| 12947 | listener: (this: Window, ev: WindowEventMap[K]) => any, |
| 12948 | options?: boolean | AddEventListenerOptions, |
| 12949 | ): void; |
| 12950 | /** @category Events */ |
| 12951 | declare function addEventListener( |
| 12952 | type: string, |
| 12953 | listener: EventListenerOrEventListenerObject, |
| 12954 | options?: boolean | AddEventListenerOptions, |
| 12955 | ): void; |
| 12956 | |
| 12957 | /** Remove a previously registered event listener from the global scope |
| 12958 | * |
| 12959 | * ```ts |
| 12960 | * const listener = () => { console.log('hello'); }; |
| 12961 | * addEventListener('load', listener); |
| 12962 | * removeEventListener('load', listener); |
| 12963 | * ``` |
| 12964 | * |
| 12965 | * @category Events |
| 12966 | */ |
| 12967 | declare function removeEventListener< |
| 12968 | K extends keyof WindowEventMap, |
| 12969 | >( |
| 12970 | type: K, |
| 12971 | listener: (this: Window, ev: WindowEventMap[K]) => any, |
| 12972 | options?: boolean | EventListenerOptions, |
| 12973 | ): void; |
| 12974 | /** @category Events */ |
| 12975 | declare function removeEventListener( |
| 12976 | type: string, |
| 12977 | listener: EventListenerOrEventListenerObject, |
| 12978 | options?: boolean | EventListenerOptions, |
| 12979 | ): void; |
| 12980 | |
| 12981 | // TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. |
| 12982 | // The types there must first be split into window, worker and global types. |
| 12983 | /** The location (URL) of the object it is linked to. Changes done on it are |
| 12984 | * reflected on the object it relates to. Accessible via |
| 12985 | * `globalThis.location`. |
| 12986 | * |
| 12987 | * @category Platform |
| 12988 | */ |
| 12989 | declare interface Location { |
| 12990 | /** Returns a DOMStringList object listing the origins of the ancestor |
| 12991 | * browsing contexts, from the parent browsing context to the top-level |
| 12992 | * browsing context. |
| 12993 | * |
| 12994 | * Always empty in Deno. */ |
| 12995 | readonly ancestorOrigins: DOMStringList; |
| 12996 | /** Returns the Location object's URL's fragment (includes leading "#" if |
| 12997 | * non-empty). |
| 12998 | * |
| 12999 | * Cannot be set in Deno. */ |
| 13000 | hash: string; |
| 13001 | /** Returns the Location object's URL's host and port (if different from the |
| 13002 | * default port for the scheme). |
| 13003 | * |
| 13004 | * Cannot be set in Deno. */ |
| 13005 | host: string; |
| 13006 | /** Returns the Location object's URL's host. |
| 13007 | * |
| 13008 | * Cannot be set in Deno. */ |
| 13009 | hostname: string; |
| 13010 | /** Returns the Location object's URL. |
| 13011 | * |
| 13012 | * Cannot be set in Deno. */ |
| 13013 | href: string; |
| 13014 | toString(): string; |
| 13015 | /** Returns the Location object's URL's origin. */ |
| 13016 | readonly origin: string; |
| 13017 | /** Returns the Location object's URL's path. |
| 13018 | * |
| 13019 | * Cannot be set in Deno. */ |
| 13020 | pathname: string; |
| 13021 | /** Returns the Location object's URL's port. |
| 13022 | * |
| 13023 | * Cannot be set in Deno. */ |
| 13024 | port: string; |
| 13025 | /** Returns the Location object's URL's scheme. |
| 13026 | * |
| 13027 | * Cannot be set in Deno. */ |
| 13028 | protocol: string; |
| 13029 | /** Returns the Location object's URL's query (includes leading "?" if |
| 13030 | * non-empty). |
| 13031 | * |
| 13032 | * Cannot be set in Deno. */ |
| 13033 | search: string; |
| 13034 | /** Navigates to the given URL. |
| 13035 | * |
| 13036 | * Cannot be set in Deno. */ |
| 13037 | assign(url: string): void; |
| 13038 | /** Reloads the current page. |
| 13039 | * |
| 13040 | * Disabled in Deno. */ |
| 13041 | reload(): void; |
| 13042 | /** @deprecated */ |
| 13043 | reload(forcedReload: boolean): void; |
| 13044 | /** Removes the current page from the session history and navigates to the |
| 13045 | * given URL. |
| 13046 | * |
| 13047 | * Disabled in Deno. */ |
| 13048 | replace(url: string): void; |
| 13049 | } |
| 13050 | |
| 13051 | // TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. |
| 13052 | // The types there must first be split into window, worker and global types. |
| 13053 | /** The location (URL) of the object it is linked to. Changes done on it are |
| 13054 | * reflected on the object it relates to. Accessible via |
| 13055 | * `globalThis.location`. |
| 13056 | * |
| 13057 | * @category Platform |
| 13058 | */ |
| 13059 | declare var Location: { |
| 13060 | readonly prototype: Location; |
| 13061 | new (): never; |
| 13062 | }; |
| 13063 | |
| 13064 | // TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. |
| 13065 | // The types there must first be split into window, worker and global types. |
| 13066 | /** @category Platform */ |
| 13067 | declare var location: Location; |
| 13068 | |
| 13069 | /** @category Platform */ |
| 13070 | declare var name: string; |
| 13071 | |
| 13072 | // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. |
| 13073 | |
| 13074 | /// <reference no-default-lib="true" /> |
| 13075 | /// <reference lib="deno.ns" /> |
| 13076 | /// <reference lib="deno.broadcast_channel" /> |
| 13077 | /// <reference lib="deno.webgpu" /> |
| 13078 | /// <reference lib="esnext" /> |
| 13079 | /// <reference lib="es2022.intl" /> |
| 13080 | |
| 13081 | declare namespace Deno { |
| 13082 | export {}; // stop default export type behavior |
| 13083 | |
| 13084 | /** Information for a HTTP request. |
| 13085 | * |
| 13086 | * @category HTTP Server |
| 13087 | * @experimental |
| 13088 | */ |
| 13089 | export interface ServeHandlerInfo { |
| 13090 | /** The remote address of the connection. */ |
| 13091 | remoteAddr: Deno.NetAddr; |
| 13092 | /** The completion promise */ |
| 13093 | completed: Promise<void>; |
| 13094 | } |
| 13095 | |
| 13096 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13097 | * |
| 13098 | * Retrieve the process umask. If `mask` is provided, sets the process umask. |
| 13099 | * This call always returns what the umask was before the call. |
| 13100 | * |
| 13101 | * ```ts |
| 13102 | * console.log(Deno.umask()); // e.g. 18 (0o022) |
| 13103 | * const prevUmaskValue = Deno.umask(0o077); // e.g. 18 (0o022) |
| 13104 | * console.log(Deno.umask()); // e.g. 63 (0o077) |
| 13105 | * ``` |
| 13106 | * |
| 13107 | * This API is under consideration to determine if permissions are required to |
| 13108 | * call it. |
| 13109 | * |
| 13110 | * *Note*: This API is not implemented on Windows |
| 13111 | * |
| 13112 | * @category File System |
| 13113 | * @experimental |
| 13114 | */ |
| 13115 | export function umask(mask?: number): number; |
| 13116 | |
| 13117 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13118 | * |
| 13119 | * All plain number types for interfacing with foreign functions. |
| 13120 | * |
| 13121 | * @category FFI |
| 13122 | * @experimental |
| 13123 | */ |
| 13124 | export type NativeNumberType = |
| 13125 | | "u8" |
| 13126 | | "i8" |
| 13127 | | "u16" |
| 13128 | | "i16" |
| 13129 | | "u32" |
| 13130 | | "i32" |
| 13131 | | "f32" |
| 13132 | | "f64"; |
| 13133 | |
| 13134 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13135 | * |
| 13136 | * All BigInt number types for interfacing with foreign functions. |
| 13137 | * |
| 13138 | * @category FFI |
| 13139 | * @experimental |
| 13140 | */ |
| 13141 | export type NativeBigIntType = |
| 13142 | | "u64" |
| 13143 | | "i64" |
| 13144 | | "usize" |
| 13145 | | "isize"; |
| 13146 | |
| 13147 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13148 | * |
| 13149 | * The native boolean type for interfacing to foreign functions. |
| 13150 | * |
| 13151 | * @category FFI |
| 13152 | * @experimental |
| 13153 | */ |
| 13154 | export type NativeBooleanType = "bool"; |
| 13155 | |
| 13156 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13157 | * |
| 13158 | * The native pointer type for interfacing to foreign functions. |
| 13159 | * |
| 13160 | * @category FFI |
| 13161 | * @experimental |
| 13162 | */ |
| 13163 | export type NativePointerType = "pointer"; |
| 13164 | |
| 13165 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13166 | * |
| 13167 | * The native buffer type for interfacing to foreign functions. |
| 13168 | * |
| 13169 | * @category FFI |
| 13170 | * @experimental |
| 13171 | */ |
| 13172 | export type NativeBufferType = "buffer"; |
| 13173 | |
| 13174 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13175 | * |
| 13176 | * The native function type for interfacing with foreign functions. |
| 13177 | * |
| 13178 | * @category FFI |
| 13179 | * @experimental |
| 13180 | */ |
| 13181 | export type NativeFunctionType = "function"; |
| 13182 | |
| 13183 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13184 | * |
| 13185 | * The native void type for interfacing with foreign functions. |
| 13186 | * |
| 13187 | * @category FFI |
| 13188 | * @experimental |
| 13189 | */ |
| 13190 | export type NativeVoidType = "void"; |
| 13191 | |
| 13192 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13193 | * |
| 13194 | * The native struct type for interfacing with foreign functions. |
| 13195 | * |
| 13196 | * @category FFI |
| 13197 | * @experimental |
| 13198 | */ |
| 13199 | export type NativeStructType = { readonly struct: readonly NativeType[] }; |
| 13200 | |
| 13201 | /** |
| 13202 | * @category FFI |
| 13203 | * @experimental |
| 13204 | */ |
| 13205 | export const brand: unique symbol; |
| 13206 | |
| 13207 | /** |
| 13208 | * @category FFI |
| 13209 | * @experimental |
| 13210 | */ |
| 13211 | export type NativeU8Enum<T extends number> = "u8" & { [brand]: T }; |
| 13212 | /** |
| 13213 | * @category FFI |
| 13214 | * @experimental |
| 13215 | */ |
| 13216 | export type NativeI8Enum<T extends number> = "i8" & { [brand]: T }; |
| 13217 | /** |
| 13218 | * @category FFI |
| 13219 | * @experimental |
| 13220 | */ |
| 13221 | export type NativeU16Enum<T extends number> = "u16" & { [brand]: T }; |
| 13222 | /** |
| 13223 | * @category FFI |
| 13224 | * @experimental |
| 13225 | */ |
| 13226 | export type NativeI16Enum<T extends number> = "i16" & { [brand]: T }; |
| 13227 | /** |
| 13228 | * @category FFI |
| 13229 | * @experimental |
| 13230 | */ |
| 13231 | export type NativeU32Enum<T extends number> = "u32" & { [brand]: T }; |
| 13232 | /** |
| 13233 | * @category FFI |
| 13234 | * @experimental |
| 13235 | */ |
| 13236 | export type NativeI32Enum<T extends number> = "i32" & { [brand]: T }; |
| 13237 | /** |
| 13238 | * @category FFI |
| 13239 | * @experimental |
| 13240 | */ |
| 13241 | export type NativeTypedPointer<T extends PointerObject> = "pointer" & { |
| 13242 | [brand]: T; |
| 13243 | }; |
| 13244 | /** |
| 13245 | * @category FFI |
| 13246 | * @experimental |
| 13247 | */ |
| 13248 | export type NativeTypedFunction<T extends UnsafeCallbackDefinition> = |
| 13249 | & "function" |
| 13250 | & { |
| 13251 | [brand]: T; |
| 13252 | }; |
| 13253 | |
| 13254 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13255 | * |
| 13256 | * All supported types for interfacing with foreign functions. |
| 13257 | * |
| 13258 | * @category FFI |
| 13259 | * @experimental |
| 13260 | */ |
| 13261 | export type NativeType = |
| 13262 | | NativeNumberType |
| 13263 | | NativeBigIntType |
| 13264 | | NativeBooleanType |
| 13265 | | NativePointerType |
| 13266 | | NativeBufferType |
| 13267 | | NativeFunctionType |
| 13268 | | NativeStructType; |
| 13269 | |
| 13270 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13271 | * |
| 13272 | * @category FFI |
| 13273 | * @experimental |
| 13274 | */ |
| 13275 | export type NativeResultType = NativeType | NativeVoidType; |
| 13276 | |
| 13277 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13278 | * |
| 13279 | * Type conversion for foreign symbol parameters and unsafe callback return |
| 13280 | * types. |
| 13281 | * |
| 13282 | * @category FFI |
| 13283 | * @experimental |
| 13284 | */ |
| 13285 | export type ToNativeType<T extends NativeType = NativeType> = T extends |
| 13286 | NativeStructType ? BufferSource |
| 13287 | : T extends NativeNumberType ? T extends NativeU8Enum<infer U> ? U |
| 13288 | : T extends NativeI8Enum<infer U> ? U |
| 13289 | : T extends NativeU16Enum<infer U> ? U |
| 13290 | : T extends NativeI16Enum<infer U> ? U |
| 13291 | : T extends NativeU32Enum<infer U> ? U |
| 13292 | : T extends NativeI32Enum<infer U> ? U |
| 13293 | : number |
| 13294 | : T extends NativeBigIntType ? bigint |
| 13295 | : T extends NativeBooleanType ? boolean |
| 13296 | : T extends NativePointerType |
| 13297 | ? T extends NativeTypedPointer<infer U> ? U | null : PointerValue |
| 13298 | : T extends NativeFunctionType |
| 13299 | ? T extends NativeTypedFunction<infer U> ? PointerValue<U> | null |
| 13300 | : PointerValue |
| 13301 | : T extends NativeBufferType ? BufferSource | null |
| 13302 | : never; |
| 13303 | |
| 13304 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13305 | * |
| 13306 | * Type conversion for unsafe callback return types. |
| 13307 | * |
| 13308 | * @category FFI |
| 13309 | * @experimental |
| 13310 | */ |
| 13311 | export type ToNativeResultType< |
| 13312 | T extends NativeResultType = NativeResultType, |
| 13313 | > = T extends NativeStructType ? BufferSource |
| 13314 | : T extends NativeNumberType ? T extends NativeU8Enum<infer U> ? U |
| 13315 | : T extends NativeI8Enum<infer U> ? U |
| 13316 | : T extends NativeU16Enum<infer U> ? U |
| 13317 | : T extends NativeI16Enum<infer U> ? U |
| 13318 | : T extends NativeU32Enum<infer U> ? U |
| 13319 | : T extends NativeI32Enum<infer U> ? U |
| 13320 | : number |
| 13321 | : T extends NativeBigIntType ? bigint |
| 13322 | : T extends NativeBooleanType ? boolean |
| 13323 | : T extends NativePointerType |
| 13324 | ? T extends NativeTypedPointer<infer U> ? U | null : PointerValue |
| 13325 | : T extends NativeFunctionType |
| 13326 | ? T extends NativeTypedFunction<infer U> ? PointerObject<U> | null |
| 13327 | : PointerValue |
| 13328 | : T extends NativeBufferType ? BufferSource | null |
| 13329 | : T extends NativeVoidType ? void |
| 13330 | : never; |
| 13331 | |
| 13332 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13333 | * |
| 13334 | * A utility type for conversion of parameter types of foreign functions. |
| 13335 | * |
| 13336 | * @category FFI |
| 13337 | * @experimental |
| 13338 | */ |
| 13339 | export type ToNativeParameterTypes<T extends readonly NativeType[]> = |
| 13340 | // |
| 13341 | [(T[number])[]] extends [T] ? ToNativeType<T[number]>[] |
| 13342 | : [readonly (T[number])[]] extends [T] |
| 13343 | ? readonly ToNativeType<T[number]>[] |
| 13344 | : T extends readonly [...NativeType[]] ? { |
| 13345 | [K in keyof T]: ToNativeType<T[K]>; |
| 13346 | } |
| 13347 | : never; |
| 13348 | |
| 13349 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13350 | * |
| 13351 | * Type conversion for foreign symbol return types and unsafe callback |
| 13352 | * parameters. |
| 13353 | * |
| 13354 | * @category FFI |
| 13355 | * @experimental |
| 13356 | */ |
| 13357 | export type FromNativeType<T extends NativeType = NativeType> = T extends |
| 13358 | NativeStructType ? Uint8Array |
| 13359 | : T extends NativeNumberType ? T extends NativeU8Enum<infer U> ? U |
| 13360 | : T extends NativeI8Enum<infer U> ? U |
| 13361 | : T extends NativeU16Enum<infer U> ? U |
| 13362 | : T extends NativeI16Enum<infer U> ? U |
| 13363 | : T extends NativeU32Enum<infer U> ? U |
| 13364 | : T extends NativeI32Enum<infer U> ? U |
| 13365 | : number |
| 13366 | : T extends NativeBigIntType ? bigint |
| 13367 | : T extends NativeBooleanType ? boolean |
| 13368 | : T extends NativePointerType |
| 13369 | ? T extends NativeTypedPointer<infer U> ? U | null : PointerValue |
| 13370 | : T extends NativeBufferType ? PointerValue |
| 13371 | : T extends NativeFunctionType |
| 13372 | ? T extends NativeTypedFunction<infer U> ? PointerObject<U> | null |
| 13373 | : PointerValue |
| 13374 | : never; |
| 13375 | |
| 13376 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13377 | * |
| 13378 | * Type conversion for foreign symbol return types. |
| 13379 | * |
| 13380 | * @category FFI |
| 13381 | * @experimental |
| 13382 | */ |
| 13383 | export type FromNativeResultType< |
| 13384 | T extends NativeResultType = NativeResultType, |
| 13385 | > = T extends NativeStructType ? Uint8Array |
| 13386 | : T extends NativeNumberType ? T extends NativeU8Enum<infer U> ? U |
| 13387 | : T extends NativeI8Enum<infer U> ? U |
| 13388 | : T extends NativeU16Enum<infer U> ? U |
| 13389 | : T extends NativeI16Enum<infer U> ? U |
| 13390 | : T extends NativeU32Enum<infer U> ? U |
| 13391 | : T extends NativeI32Enum<infer U> ? U |
| 13392 | : number |
| 13393 | : T extends NativeBigIntType ? bigint |
| 13394 | : T extends NativeBooleanType ? boolean |
| 13395 | : T extends NativePointerType |
| 13396 | ? T extends NativeTypedPointer<infer U> ? U | null : PointerValue |
| 13397 | : T extends NativeBufferType ? PointerValue |
| 13398 | : T extends NativeFunctionType |
| 13399 | ? T extends NativeTypedFunction<infer U> ? PointerObject<U> | null |
| 13400 | : PointerValue |
| 13401 | : T extends NativeVoidType ? void |
| 13402 | : never; |
| 13403 | |
| 13404 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13405 | * |
| 13406 | * @category FFI |
| 13407 | * @experimental |
| 13408 | */ |
| 13409 | export type FromNativeParameterTypes< |
| 13410 | T extends readonly NativeType[], |
| 13411 | > = |
| 13412 | // |
| 13413 | [(T[number])[]] extends [T] ? FromNativeType<T[number]>[] |
| 13414 | : [readonly (T[number])[]] extends [T] |
| 13415 | ? readonly FromNativeType<T[number]>[] |
| 13416 | : T extends readonly [...NativeType[]] ? { |
| 13417 | [K in keyof T]: FromNativeType<T[K]>; |
| 13418 | } |
| 13419 | : never; |
| 13420 | |
| 13421 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13422 | * |
| 13423 | * The interface for a foreign function as defined by its parameter and result |
| 13424 | * types. |
| 13425 | * |
| 13426 | * @category FFI |
| 13427 | * @experimental |
| 13428 | */ |
| 13429 | export interface ForeignFunction< |
| 13430 | Parameters extends readonly NativeType[] = readonly NativeType[], |
| 13431 | Result extends NativeResultType = NativeResultType, |
| 13432 | NonBlocking extends boolean = boolean, |
| 13433 | > { |
| 13434 | /** Name of the symbol. |
| 13435 | * |
| 13436 | * Defaults to the key name in symbols object. */ |
| 13437 | name?: string; |
| 13438 | /** The parameters of the foreign function. */ |
| 13439 | parameters: Parameters; |
| 13440 | /** The result (return value) of the foreign function. */ |
| 13441 | result: Result; |
| 13442 | /** When `true`, function calls will run on a dedicated blocking thread and |
| 13443 | * will return a `Promise` resolving to the `result`. */ |
| 13444 | nonblocking?: NonBlocking; |
| 13445 | /** When `true`, dlopen will not fail if the symbol is not found. |
| 13446 | * Instead, the symbol will be set to `null`. |
| 13447 | * |
| 13448 | * @default {false} */ |
| 13449 | optional?: boolean; |
| 13450 | } |
| 13451 | |
| 13452 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13453 | * |
| 13454 | * @category FFI |
| 13455 | * @experimental |
| 13456 | */ |
| 13457 | export interface ForeignStatic<Type extends NativeType = NativeType> { |
| 13458 | /** Name of the symbol, defaults to the key name in symbols object. */ |
| 13459 | name?: string; |
| 13460 | /** The type of the foreign static value. */ |
| 13461 | type: Type; |
| 13462 | /** When `true`, dlopen will not fail if the symbol is not found. |
| 13463 | * Instead, the symbol will be set to `null`. |
| 13464 | * |
| 13465 | * @default {false} */ |
| 13466 | optional?: boolean; |
| 13467 | } |
| 13468 | |
| 13469 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13470 | * |
| 13471 | * A foreign library interface descriptor. |
| 13472 | * |
| 13473 | * @category FFI |
| 13474 | * @experimental |
| 13475 | */ |
| 13476 | export interface ForeignLibraryInterface { |
| 13477 | [name: string]: ForeignFunction | ForeignStatic; |
| 13478 | } |
| 13479 | |
| 13480 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13481 | * |
| 13482 | * A utility type that infers a foreign symbol. |
| 13483 | * |
| 13484 | * @category FFI |
| 13485 | * @experimental |
| 13486 | */ |
| 13487 | export type StaticForeignSymbol<T extends ForeignFunction | ForeignStatic> = |
| 13488 | T extends ForeignFunction ? FromForeignFunction<T> |
| 13489 | : T extends ForeignStatic ? FromNativeType<T["type"]> |
| 13490 | : never; |
| 13491 | |
| 13492 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13493 | * |
| 13494 | * @category FFI |
| 13495 | * @experimental |
| 13496 | */ |
| 13497 | export type FromForeignFunction<T extends ForeignFunction> = |
| 13498 | T["parameters"] extends readonly [] ? () => StaticForeignSymbolReturnType<T> |
| 13499 | : ( |
| 13500 | ...args: ToNativeParameterTypes<T["parameters"]> |
| 13501 | ) => StaticForeignSymbolReturnType<T>; |
| 13502 | |
| 13503 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13504 | * |
| 13505 | * @category FFI |
| 13506 | * @experimental |
| 13507 | */ |
| 13508 | export type StaticForeignSymbolReturnType<T extends ForeignFunction> = |
| 13509 | ConditionalAsync<T["nonblocking"], FromNativeResultType<T["result"]>>; |
| 13510 | |
| 13511 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13512 | * |
| 13513 | * @category FFI |
| 13514 | * @experimental |
| 13515 | */ |
| 13516 | export type ConditionalAsync<IsAsync extends boolean | undefined, T> = |
| 13517 | IsAsync extends true ? Promise<T> : T; |
| 13518 | |
| 13519 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13520 | * |
| 13521 | * A utility type that infers a foreign library interface. |
| 13522 | * |
| 13523 | * @category FFI |
| 13524 | * @experimental |
| 13525 | */ |
| 13526 | export type StaticForeignLibraryInterface<T extends ForeignLibraryInterface> = |
| 13527 | { |
| 13528 | [K in keyof T]: T[K]["optional"] extends true |
| 13529 | ? StaticForeignSymbol<T[K]> | null |
| 13530 | : StaticForeignSymbol<T[K]>; |
| 13531 | }; |
| 13532 | |
| 13533 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13534 | * |
| 13535 | * A non-null pointer, represented as an object |
| 13536 | * at runtime. The object's prototype is `null` |
| 13537 | * and cannot be changed. The object cannot be |
| 13538 | * assigned to either and is thus entirely read-only. |
| 13539 | * |
| 13540 | * To interact with memory through a pointer use the |
| 13541 | * {@linkcode UnsafePointerView} class. To create a |
| 13542 | * pointer from an address or the get the address of |
| 13543 | * a pointer use the static methods of the |
| 13544 | * {@linkcode UnsafePointer} class. |
| 13545 | * |
| 13546 | * @category FFI |
| 13547 | * @experimental |
| 13548 | */ |
| 13549 | export type PointerObject<T = unknown> = { [brand]: T }; |
| 13550 | |
| 13551 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13552 | * |
| 13553 | * Pointers are represented either with a {@linkcode PointerObject} |
| 13554 | * object or a `null` if the pointer is null. |
| 13555 | * |
| 13556 | * @category FFI |
| 13557 | * @experimental |
| 13558 | */ |
| 13559 | export type PointerValue<T = unknown> = null | PointerObject<T>; |
| 13560 | |
| 13561 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13562 | * |
| 13563 | * A collection of static functions for interacting with pointer objects. |
| 13564 | * |
| 13565 | * @category FFI |
| 13566 | * @experimental |
| 13567 | */ |
| 13568 | export class UnsafePointer { |
| 13569 | /** Create a pointer from a numeric value. This one is <i>really</i> dangerous! */ |
| 13570 | static create<T = unknown>(value: bigint): PointerValue<T>; |
| 13571 | /** Returns `true` if the two pointers point to the same address. */ |
| 13572 | static equals<T = unknown>(a: PointerValue<T>, b: PointerValue<T>): boolean; |
| 13573 | /** Return the direct memory pointer to the typed array in memory. */ |
| 13574 | static of<T = unknown>( |
| 13575 | value: Deno.UnsafeCallback | BufferSource, |
| 13576 | ): PointerValue<T>; |
| 13577 | /** Return a new pointer offset from the original by `offset` bytes. */ |
| 13578 | static offset<T = unknown>( |
| 13579 | value: PointerObject, |
| 13580 | offset: number, |
| 13581 | ): PointerValue<T>; |
| 13582 | /** Get the numeric value of a pointer */ |
| 13583 | static value(value: PointerValue): bigint; |
| 13584 | } |
| 13585 | |
| 13586 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13587 | * |
| 13588 | * An unsafe pointer view to a memory location as specified by the `pointer` |
| 13589 | * value. The `UnsafePointerView` API follows the standard built in interface |
| 13590 | * {@linkcode DataView} for accessing the underlying types at an memory |
| 13591 | * location (numbers, strings and raw bytes). |
| 13592 | * |
| 13593 | * @category FFI |
| 13594 | * @experimental |
| 13595 | */ |
| 13596 | export class UnsafePointerView { |
| 13597 | constructor(pointer: PointerObject); |
| 13598 | |
| 13599 | pointer: PointerObject; |
| 13600 | |
| 13601 | /** Gets a boolean at the specified byte offset from the pointer. */ |
| 13602 | getBool(offset?: number): boolean; |
| 13603 | /** Gets an unsigned 8-bit integer at the specified byte offset from the |
| 13604 | * pointer. */ |
| 13605 | getUint8(offset?: number): number; |
| 13606 | /** Gets a signed 8-bit integer at the specified byte offset from the |
| 13607 | * pointer. */ |
| 13608 | getInt8(offset?: number): number; |
| 13609 | /** Gets an unsigned 16-bit integer at the specified byte offset from the |
| 13610 | * pointer. */ |
| 13611 | getUint16(offset?: number): number; |
| 13612 | /** Gets a signed 16-bit integer at the specified byte offset from the |
| 13613 | * pointer. */ |
| 13614 | getInt16(offset?: number): number; |
| 13615 | /** Gets an unsigned 32-bit integer at the specified byte offset from the |
| 13616 | * pointer. */ |
| 13617 | getUint32(offset?: number): number; |
| 13618 | /** Gets a signed 32-bit integer at the specified byte offset from the |
| 13619 | * pointer. */ |
| 13620 | getInt32(offset?: number): number; |
| 13621 | /** Gets an unsigned 64-bit integer at the specified byte offset from the |
| 13622 | * pointer. */ |
| 13623 | getBigUint64(offset?: number): bigint; |
| 13624 | /** Gets a signed 64-bit integer at the specified byte offset from the |
| 13625 | * pointer. */ |
| 13626 | getBigInt64(offset?: number): bigint; |
| 13627 | /** Gets a signed 32-bit float at the specified byte offset from the |
| 13628 | * pointer. */ |
| 13629 | getFloat32(offset?: number): number; |
| 13630 | /** Gets a signed 64-bit float at the specified byte offset from the |
| 13631 | * pointer. */ |
| 13632 | getFloat64(offset?: number): number; |
| 13633 | /** Gets a pointer at the specified byte offset from the pointer */ |
| 13634 | getPointer<T = unknown>(offset?: number): PointerValue<T>; |
| 13635 | /** Gets a C string (`null` terminated string) at the specified byte offset |
| 13636 | * from the pointer. */ |
| 13637 | getCString(offset?: number): string; |
| 13638 | /** Gets a C string (`null` terminated string) at the specified byte offset |
| 13639 | * from the specified pointer. */ |
| 13640 | static getCString( |
| 13641 | pointer: PointerObject, |
| 13642 | offset?: number, |
| 13643 | ): string; |
| 13644 | /** Gets an `ArrayBuffer` of length `byteLength` at the specified byte |
| 13645 | * offset from the pointer. */ |
| 13646 | getArrayBuffer(byteLength: number, offset?: number): ArrayBuffer; |
| 13647 | /** Gets an `ArrayBuffer` of length `byteLength` at the specified byte |
| 13648 | * offset from the specified pointer. */ |
| 13649 | static getArrayBuffer( |
| 13650 | pointer: PointerObject, |
| 13651 | byteLength: number, |
| 13652 | offset?: number, |
| 13653 | ): ArrayBuffer; |
| 13654 | /** Copies the memory of the pointer into a typed array. |
| 13655 | * |
| 13656 | * Length is determined from the typed array's `byteLength`. |
| 13657 | * |
| 13658 | * Also takes optional byte offset from the pointer. */ |
| 13659 | copyInto(destination: BufferSource, offset?: number): void; |
| 13660 | /** Copies the memory of the specified pointer into a typed array. |
| 13661 | * |
| 13662 | * Length is determined from the typed array's `byteLength`. |
| 13663 | * |
| 13664 | * Also takes optional byte offset from the pointer. */ |
| 13665 | static copyInto( |
| 13666 | pointer: PointerObject, |
| 13667 | destination: BufferSource, |
| 13668 | offset?: number, |
| 13669 | ): void; |
| 13670 | } |
| 13671 | |
| 13672 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13673 | * |
| 13674 | * An unsafe pointer to a function, for calling functions that are not present |
| 13675 | * as symbols. |
| 13676 | * |
| 13677 | * @category FFI |
| 13678 | * @experimental |
| 13679 | */ |
| 13680 | export class UnsafeFnPointer<const Fn extends ForeignFunction> { |
| 13681 | /** The pointer to the function. */ |
| 13682 | pointer: PointerObject<Fn>; |
| 13683 | /** The definition of the function. */ |
| 13684 | definition: Fn; |
| 13685 | |
| 13686 | constructor(pointer: PointerObject<NoInfer<Fn>>, definition: Fn); |
| 13687 | /** @deprecated Properly type {@linkcode pointer} using {@linkcode NativeTypedFunction} or {@linkcode UnsafeCallbackDefinition} types. */ |
| 13688 | constructor(pointer: PointerObject, definition: Fn); |
| 13689 | |
| 13690 | /** Call the foreign function. */ |
| 13691 | call: FromForeignFunction<Fn>; |
| 13692 | } |
| 13693 | |
| 13694 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13695 | * |
| 13696 | * Definition of a unsafe callback function. |
| 13697 | * |
| 13698 | * @category FFI |
| 13699 | * @experimental |
| 13700 | */ |
| 13701 | export interface UnsafeCallbackDefinition< |
| 13702 | Parameters extends readonly NativeType[] = readonly NativeType[], |
| 13703 | Result extends NativeResultType = NativeResultType, |
| 13704 | > { |
| 13705 | /** The parameters of the callbacks. */ |
| 13706 | parameters: Parameters; |
| 13707 | /** The current result of the callback. */ |
| 13708 | result: Result; |
| 13709 | } |
| 13710 | |
| 13711 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13712 | * |
| 13713 | * An unsafe callback function. |
| 13714 | * |
| 13715 | * @category FFI |
| 13716 | * @experimental |
| 13717 | */ |
| 13718 | export type UnsafeCallbackFunction< |
| 13719 | Parameters extends readonly NativeType[] = readonly NativeType[], |
| 13720 | Result extends NativeResultType = NativeResultType, |
| 13721 | > = Parameters extends readonly [] ? () => ToNativeResultType<Result> : ( |
| 13722 | ...args: FromNativeParameterTypes<Parameters> |
| 13723 | ) => ToNativeResultType<Result>; |
| 13724 | |
| 13725 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13726 | * |
| 13727 | * An unsafe function pointer for passing JavaScript functions as C function |
| 13728 | * pointers to foreign function calls. |
| 13729 | * |
| 13730 | * The function pointer remains valid until the `close()` method is called. |
| 13731 | * |
| 13732 | * All `UnsafeCallback` are always thread safe in that they can be called from |
| 13733 | * foreign threads without crashing. However, they do not wake up the Deno event |
| 13734 | * loop by default. |
| 13735 | * |
| 13736 | * If a callback is to be called from foreign threads, use the `threadSafe()` |
| 13737 | * static constructor or explicitly call `ref()` to have the callback wake up |
| 13738 | * the Deno event loop when called from foreign threads. This also stops |
| 13739 | * Deno's process from exiting while the callback still exists and is not |
| 13740 | * unref'ed. |
| 13741 | * |
| 13742 | * Use `deref()` to then allow Deno's process to exit. Calling `deref()` on |
| 13743 | * a ref'ed callback does not stop it from waking up the Deno event loop when |
| 13744 | * called from foreign threads. |
| 13745 | * |
| 13746 | * @category FFI |
| 13747 | * @experimental |
| 13748 | */ |
| 13749 | export class UnsafeCallback< |
| 13750 | const Definition extends UnsafeCallbackDefinition = |
| 13751 | UnsafeCallbackDefinition, |
| 13752 | > { |
| 13753 | constructor( |
| 13754 | definition: Definition, |
| 13755 | callback: UnsafeCallbackFunction< |
| 13756 | Definition["parameters"], |
| 13757 | Definition["result"] |
| 13758 | >, |
| 13759 | ); |
| 13760 | |
| 13761 | /** The pointer to the unsafe callback. */ |
| 13762 | readonly pointer: PointerObject<Definition>; |
| 13763 | /** The definition of the unsafe callback. */ |
| 13764 | readonly definition: Definition; |
| 13765 | /** The callback function. */ |
| 13766 | readonly callback: UnsafeCallbackFunction< |
| 13767 | Definition["parameters"], |
| 13768 | Definition["result"] |
| 13769 | >; |
| 13770 | |
| 13771 | /** |
| 13772 | * Creates an {@linkcode UnsafeCallback} and calls `ref()` once to allow it to |
| 13773 | * wake up the Deno event loop when called from foreign threads. |
| 13774 | * |
| 13775 | * This also stops Deno's process from exiting while the callback still |
| 13776 | * exists and is not unref'ed. |
| 13777 | */ |
| 13778 | static threadSafe< |
| 13779 | Definition extends UnsafeCallbackDefinition = UnsafeCallbackDefinition, |
| 13780 | >( |
| 13781 | definition: Definition, |
| 13782 | callback: UnsafeCallbackFunction< |
| 13783 | Definition["parameters"], |
| 13784 | Definition["result"] |
| 13785 | >, |
| 13786 | ): UnsafeCallback<Definition>; |
| 13787 | |
| 13788 | /** |
| 13789 | * Increments the callback's reference counting and returns the new |
| 13790 | * reference count. |
| 13791 | * |
| 13792 | * After `ref()` has been called, the callback always wakes up the |
| 13793 | * Deno event loop when called from foreign threads. |
| 13794 | * |
| 13795 | * If the callback's reference count is non-zero, it keeps Deno's |
| 13796 | * process from exiting. |
| 13797 | */ |
| 13798 | ref(): number; |
| 13799 | |
| 13800 | /** |
| 13801 | * Decrements the callback's reference counting and returns the new |
| 13802 | * reference count. |
| 13803 | * |
| 13804 | * Calling `unref()` does not stop a callback from waking up the Deno |
| 13805 | * event loop when called from foreign threads. |
| 13806 | * |
| 13807 | * If the callback's reference counter is zero, it no longer keeps |
| 13808 | * Deno's process from exiting. |
| 13809 | */ |
| 13810 | unref(): number; |
| 13811 | |
| 13812 | /** |
| 13813 | * Removes the C function pointer associated with this instance. |
| 13814 | * |
| 13815 | * Continuing to use the instance or the C function pointer after closing |
| 13816 | * the `UnsafeCallback` will lead to errors and crashes. |
| 13817 | * |
| 13818 | * Calling this method sets the callback's reference counting to zero, |
| 13819 | * stops the callback from waking up the Deno event loop when called from |
| 13820 | * foreign threads and no longer keeps Deno's process from exiting. |
| 13821 | */ |
| 13822 | close(): void; |
| 13823 | } |
| 13824 | |
| 13825 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13826 | * |
| 13827 | * A dynamic library resource. Use {@linkcode Deno.dlopen} to load a dynamic |
| 13828 | * library and return this interface. |
| 13829 | * |
| 13830 | * @category FFI |
| 13831 | * @experimental |
| 13832 | */ |
| 13833 | export interface DynamicLibrary<S extends ForeignLibraryInterface> { |
| 13834 | /** All of the registered library along with functions for calling them. */ |
| 13835 | symbols: StaticForeignLibraryInterface<S>; |
| 13836 | /** Removes the pointers associated with the library symbols. |
| 13837 | * |
| 13838 | * Continuing to use symbols that are part of the library will lead to |
| 13839 | * errors and crashes. |
| 13840 | * |
| 13841 | * Calling this method will also immediately set any references to zero and |
| 13842 | * will no longer keep Deno's process from exiting. |
| 13843 | */ |
| 13844 | close(): void; |
| 13845 | } |
| 13846 | |
| 13847 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13848 | * |
| 13849 | * Opens an external dynamic library and registers symbols, making foreign |
| 13850 | * functions available to be called. |
| 13851 | * |
| 13852 | * Requires `allow-ffi` permission. Loading foreign dynamic libraries can in |
| 13853 | * theory bypass all of the sandbox permissions. While it is a separate |
| 13854 | * permission users should acknowledge in practice that is effectively the |
| 13855 | * same as running with the `allow-all` permission. |
| 13856 | * |
| 13857 | * @example Given a C library which exports a foreign function named `add()` |
| 13858 | * |
| 13859 | * ```ts |
| 13860 | * // Determine library extension based on |
| 13861 | * // your OS. |
| 13862 | * let libSuffix = ""; |
| 13863 | * switch (Deno.build.os) { |
| 13864 | * case "windows": |
| 13865 | * libSuffix = "dll"; |
| 13866 | * break; |
| 13867 | * case "darwin": |
| 13868 | * libSuffix = "dylib"; |
| 13869 | * break; |
| 13870 | * default: |
| 13871 | * libSuffix = "so"; |
| 13872 | * break; |
| 13873 | * } |
| 13874 | * |
| 13875 | * const libName = `./libadd.${libSuffix}`; |
| 13876 | * // Open library and define exported symbols |
| 13877 | * const dylib = Deno.dlopen( |
| 13878 | * libName, |
| 13879 | * { |
| 13880 | * "add": { parameters: ["isize", "isize"], result: "isize" }, |
| 13881 | * } as const, |
| 13882 | * ); |
| 13883 | * |
| 13884 | * // Call the symbol `add` |
| 13885 | * const result = dylib.symbols.add(35n, 34n); // 69n |
| 13886 | * |
| 13887 | * console.log(`Result from external addition of 35 and 34: ${result}`); |
| 13888 | * ``` |
| 13889 | * |
| 13890 | * @tags allow-ffi |
| 13891 | * @category FFI |
| 13892 | * @experimental |
| 13893 | */ |
| 13894 | export function dlopen<const S extends ForeignLibraryInterface>( |
| 13895 | filename: string | URL, |
| 13896 | symbols: S, |
| 13897 | ): DynamicLibrary<S>; |
| 13898 | |
| 13899 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13900 | * |
| 13901 | * Creates a presentable WebGPU surface from given window and |
| 13902 | * display handles. |
| 13903 | * |
| 13904 | * The parameters correspond to the table below: |
| 13905 | * |
| 13906 | * | system | winHandle | displayHandle | |
| 13907 | * | ----------------- | ------------- | --------------- | |
| 13908 | * | "cocoa" (macOS) | `NSView*` | - | |
| 13909 | * | "win32" (Windows) | `HWND` | `HINSTANCE` | |
| 13910 | * | "x11" (Linux) | Xlib `Window` | Xlib `Display*` | |
| 13911 | * | "wayland" (Linux) | `wl_surface*` | `wl_display*` | |
| 13912 | * |
| 13913 | * @category GPU |
| 13914 | * @experimental |
| 13915 | */ |
| 13916 | export class UnsafeWindowSurface { |
| 13917 | constructor( |
| 13918 | system: "cocoa" | "win32" | "x11" | "wayland", |
| 13919 | windowHandle: Deno.PointerValue<unknown>, |
| 13920 | displayHandle: Deno.PointerValue<unknown>, |
| 13921 | ); |
| 13922 | getContext(context: "webgpu"): GPUCanvasContext; |
| 13923 | present(): void; |
| 13924 | } |
| 13925 | |
| 13926 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13927 | * |
| 13928 | * These are unstable options which can be used with {@linkcode Deno.run}. |
| 13929 | * |
| 13930 | * @category Sub Process |
| 13931 | * @experimental |
| 13932 | */ |
| 13933 | export interface UnstableRunOptions extends RunOptions { |
| 13934 | /** If `true`, clears the environment variables before executing the |
| 13935 | * sub-process. |
| 13936 | * |
| 13937 | * @default {false} */ |
| 13938 | clearEnv?: boolean; |
| 13939 | /** For POSIX systems, sets the group ID for the sub process. */ |
| 13940 | gid?: number; |
| 13941 | /** For POSIX systems, sets the user ID for the sub process. */ |
| 13942 | uid?: number; |
| 13943 | } |
| 13944 | |
| 13945 | /** **UNSTABLE**: New API, yet to be vetted. |
| 13946 | * |
| 13947 | * Spawns new subprocess. RunOptions must contain at a minimum the `opt.cmd`, |
| 13948 | * an array of program arguments, the first of which is the binary. |
| 13949 | * |
| 13950 | * ```ts |
| 13951 | * const p = Deno.run({ |
| 13952 | * cmd: ["curl", "https://example.com"], |
| 13953 | * }); |
| 13954 | * const status = await p.status(); |
| 13955 | * ``` |
| 13956 | * |
| 13957 | * Subprocess uses same working directory as parent process unless `opt.cwd` |
| 13958 | * is specified. |
| 13959 | * |
| 13960 | * Environmental variables from parent process can be cleared using `opt.clearEnv`. |
| 13961 | * Doesn't guarantee that only `opt.env` variables are present, |
| 13962 | * as the OS may set environmental variables for processes. |
| 13963 | * |
| 13964 | * Environmental variables for subprocess can be specified using `opt.env` |
| 13965 | * mapping. |
| 13966 | * |
| 13967 | * `opt.uid` sets the child process’s user ID. This translates to a setuid call |
| 13968 | * in the child process. Failure in the setuid call will cause the spawn to fail. |
| 13969 | * |
| 13970 | * `opt.gid` is similar to `opt.uid`, but sets the group ID of the child process. |
| 13971 | * This has the same semantics as the uid field. |
| 13972 | * |
| 13973 | * By default subprocess inherits stdio of parent process. To change |
| 13974 | * this this, `opt.stdin`, `opt.stdout`, and `opt.stderr` can be set |
| 13975 | * independently to a resource ID (_rid_) of an open file, `"inherit"`, |
| 13976 | * `"piped"`, or `"null"`: |
| 13977 | * |
| 13978 | * - _number_: the resource ID of an open file/resource. This allows you to |
| 13979 | * read or write to a file. |
| 13980 | * - `"inherit"`: The default if unspecified. The subprocess inherits from the |
| 13981 | * parent. |
| 13982 | * - `"piped"`: A new pipe should be arranged to connect the parent and child |
| 13983 | * sub-process. |
| 13984 | * - `"null"`: This stream will be ignored. This is the equivalent of attaching |
| 13985 | * the stream to `/dev/null`. |
| 13986 | * |
| 13987 | * Details of the spawned process are returned as an instance of |
| 13988 | * {@linkcode Deno.Process}. |
| 13989 | * |
| 13990 | * Requires `allow-run` permission. |
| 13991 | * |
| 13992 | * @tags allow-run |
| 13993 | * @category Sub Process |
| 13994 | * @experimental |
| 13995 | */ |
| 13996 | export function run<T extends UnstableRunOptions = UnstableRunOptions>( |
| 13997 | opt: T, |
| 13998 | ): Process<T>; |
| 13999 | |
| 14000 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14001 | * |
| 14002 | * A custom `HttpClient` for use with {@linkcode fetch} function. This is |
| 14003 | * designed to allow custom certificates or proxies to be used with `fetch()`. |
| 14004 | * |
| 14005 | * @example ```ts |
| 14006 | * const caCert = await Deno.readTextFile("./ca.pem"); |
| 14007 | * const client = Deno.createHttpClient({ caCerts: [ caCert ] }); |
| 14008 | * const req = await fetch("https://myserver.com", { client }); |
| 14009 | * ``` |
| 14010 | * |
| 14011 | * @category Fetch |
| 14012 | * @experimental |
| 14013 | */ |
| 14014 | export interface HttpClient extends Disposable { |
| 14015 | /** Close the HTTP client. */ |
| 14016 | close(): void; |
| 14017 | } |
| 14018 | |
| 14019 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14020 | * |
| 14021 | * The options used when creating a {@linkcode Deno.HttpClient}. |
| 14022 | * |
| 14023 | * @category Fetch |
| 14024 | * @experimental |
| 14025 | */ |
| 14026 | export interface CreateHttpClientOptions { |
| 14027 | /** A list of root certificates that will be used in addition to the |
| 14028 | * default root certificates to verify the peer's certificate. |
| 14029 | * |
| 14030 | * Must be in PEM format. */ |
| 14031 | caCerts?: string[]; |
| 14032 | /** A HTTP proxy to use for new connections. */ |
| 14033 | proxy?: Proxy; |
| 14034 | /** Sets the maximum numer of idle connections per host allowed in the pool. */ |
| 14035 | poolMaxIdlePerHost?: number; |
| 14036 | /** Set an optional timeout for idle sockets being kept-alive. |
| 14037 | * Set to false to disable the timeout. */ |
| 14038 | poolIdleTimeout?: number | false; |
| 14039 | /** |
| 14040 | * Whether HTTP/1.1 is allowed or not. |
| 14041 | * |
| 14042 | * @default {true} |
| 14043 | */ |
| 14044 | http1?: boolean; |
| 14045 | /** Whether HTTP/2 is allowed or not. |
| 14046 | * |
| 14047 | * @default {true} |
| 14048 | */ |
| 14049 | http2?: boolean; |
| 14050 | /** Whether setting the host header is allowed or not. |
| 14051 | * |
| 14052 | * @default {false} |
| 14053 | */ |
| 14054 | allowHost?: boolean; |
| 14055 | } |
| 14056 | |
| 14057 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14058 | * |
| 14059 | * The definition of a proxy when specifying |
| 14060 | * {@linkcode Deno.CreateHttpClientOptions}. |
| 14061 | * |
| 14062 | * @category Fetch |
| 14063 | * @experimental |
| 14064 | */ |
| 14065 | export interface Proxy { |
| 14066 | /** The string URL of the proxy server to use. */ |
| 14067 | url: string; |
| 14068 | /** The basic auth credentials to be used against the proxy server. */ |
| 14069 | basicAuth?: BasicAuth; |
| 14070 | } |
| 14071 | |
| 14072 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14073 | * |
| 14074 | * Basic authentication credentials to be used with a {@linkcode Deno.Proxy} |
| 14075 | * server when specifying {@linkcode Deno.CreateHttpClientOptions}. |
| 14076 | * |
| 14077 | * @category Fetch |
| 14078 | * @experimental |
| 14079 | */ |
| 14080 | export interface BasicAuth { |
| 14081 | /** The username to be used against the proxy server. */ |
| 14082 | username: string; |
| 14083 | /** The password to be used against the proxy server. */ |
| 14084 | password: string; |
| 14085 | } |
| 14086 | |
| 14087 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14088 | * |
| 14089 | * Create a custom HttpClient to use with {@linkcode fetch}. This is an |
| 14090 | * extension of the web platform Fetch API which allows Deno to use custom |
| 14091 | * TLS certificates and connect via a proxy while using `fetch()`. |
| 14092 | * |
| 14093 | * @example ```ts |
| 14094 | * const caCert = await Deno.readTextFile("./ca.pem"); |
| 14095 | * const client = Deno.createHttpClient({ caCerts: [ caCert ] }); |
| 14096 | * const response = await fetch("https://myserver.com", { client }); |
| 14097 | * ``` |
| 14098 | * |
| 14099 | * @example ```ts |
| 14100 | * const client = Deno.createHttpClient({ |
| 14101 | * proxy: { url: "http://myproxy.com:8080" } |
| 14102 | * }); |
| 14103 | * const response = await fetch("https://myserver.com", { client }); |
| 14104 | * ``` |
| 14105 | * |
| 14106 | * @category Fetch |
| 14107 | * @experimental |
| 14108 | */ |
| 14109 | export function createHttpClient( |
| 14110 | options: CreateHttpClientOptions, |
| 14111 | ): HttpClient; |
| 14112 | |
| 14113 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14114 | * |
| 14115 | * Create a custom HttpClient to use with {@linkcode fetch}. This is an |
| 14116 | * extension of the web platform Fetch API which allows Deno to use custom |
| 14117 | * TLS certificates and connect via a proxy while using `fetch()`. |
| 14118 | * |
| 14119 | * @example ```ts |
| 14120 | * const caCert = await Deno.readTextFile("./ca.pem"); |
| 14121 | * // Load a client key and certificate that we'll use to connect |
| 14122 | * const key = await Deno.readTextFile("./key.key"); |
| 14123 | * const cert = await Deno.readTextFile("./cert.crt"); |
| 14124 | * const client = Deno.createHttpClient({ caCerts: [ caCert ], key, cert }); |
| 14125 | * const response = await fetch("https://myserver.com", { client }); |
| 14126 | * ``` |
| 14127 | * |
| 14128 | * @category Fetch |
| 14129 | * @experimental |
| 14130 | */ |
| 14131 | export function createHttpClient( |
| 14132 | options: CreateHttpClientOptions & TlsCertifiedKeyOptions, |
| 14133 | ): HttpClient; |
| 14134 | |
| 14135 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14136 | * |
| 14137 | * Represents membership of a IPv4 multicast group. |
| 14138 | * |
| 14139 | * @category Network |
| 14140 | * @experimental |
| 14141 | */ |
| 14142 | export interface MulticastV4Membership { |
| 14143 | /** Leaves the multicast group. */ |
| 14144 | leave: () => Promise<void>; |
| 14145 | /** Sets the multicast loopback option. If enabled, multicast packets will be looped back to the local socket. */ |
| 14146 | setLoopback: (loopback: boolean) => Promise<void>; |
| 14147 | /** Sets the time-to-live of outgoing multicast packets for this socket. */ |
| 14148 | setTTL: (ttl: number) => Promise<void>; |
| 14149 | } |
| 14150 | |
| 14151 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14152 | * |
| 14153 | * Represents membership of a IPv6 multicast group. |
| 14154 | * |
| 14155 | * @category Network |
| 14156 | * @experimental |
| 14157 | */ |
| 14158 | export interface MulticastV6Membership { |
| 14159 | /** Leaves the multicast group. */ |
| 14160 | leave: () => Promise<void>; |
| 14161 | /** Sets the multicast loopback option. If enabled, multicast packets will be looped back to the local socket. */ |
| 14162 | setLoopback: (loopback: boolean) => Promise<void>; |
| 14163 | } |
| 14164 | |
| 14165 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14166 | * |
| 14167 | * A generic transport listener for message-oriented protocols. |
| 14168 | * |
| 14169 | * @category Network |
| 14170 | * @experimental |
| 14171 | */ |
| 14172 | export interface DatagramConn extends AsyncIterable<[Uint8Array, Addr]> { |
| 14173 | /** Joins an IPv4 multicast group. */ |
| 14174 | joinMulticastV4( |
| 14175 | address: string, |
| 14176 | networkInterface: string, |
| 14177 | ): Promise<MulticastV4Membership>; |
| 14178 | |
| 14179 | /** Joins an IPv6 multicast group. */ |
| 14180 | joinMulticastV6( |
| 14181 | address: string, |
| 14182 | networkInterface: number, |
| 14183 | ): Promise<MulticastV6Membership>; |
| 14184 | |
| 14185 | /** Waits for and resolves to the next message to the instance. |
| 14186 | * |
| 14187 | * Messages are received in the format of a tuple containing the data array |
| 14188 | * and the address information. |
| 14189 | */ |
| 14190 | receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>; |
| 14191 | /** Sends a message to the target via the connection. The method resolves |
| 14192 | * with the number of bytes sent. */ |
| 14193 | send(p: Uint8Array, addr: Addr): Promise<number>; |
| 14194 | /** Close closes the socket. Any pending message promises will be rejected |
| 14195 | * with errors. */ |
| 14196 | close(): void; |
| 14197 | /** Return the address of the instance. */ |
| 14198 | readonly addr: Addr; |
| 14199 | [Symbol.asyncIterator](): AsyncIterableIterator<[Uint8Array, Addr]>; |
| 14200 | } |
| 14201 | |
| 14202 | /** |
| 14203 | * @category Network |
| 14204 | * @experimental |
| 14205 | */ |
| 14206 | export interface TcpListenOptions extends ListenOptions { |
| 14207 | /** When `true` the SO_REUSEPORT flag will be set on the listener. This |
| 14208 | * allows multiple processes to listen on the same address and port. |
| 14209 | * |
| 14210 | * On Linux this will cause the kernel to distribute incoming connections |
| 14211 | * across the different processes that are listening on the same address and |
| 14212 | * port. |
| 14213 | * |
| 14214 | * This flag is only supported on Linux. It is silently ignored on other |
| 14215 | * platforms. |
| 14216 | * |
| 14217 | * @default {false} */ |
| 14218 | reusePort?: boolean; |
| 14219 | } |
| 14220 | |
| 14221 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14222 | * |
| 14223 | * Unstable options which can be set when opening a datagram listener via |
| 14224 | * {@linkcode Deno.listenDatagram}. |
| 14225 | * |
| 14226 | * @category Network |
| 14227 | * @experimental |
| 14228 | */ |
| 14229 | export interface UdpListenOptions extends ListenOptions { |
| 14230 | /** When `true` the specified address will be reused, even if another |
| 14231 | * process has already bound a socket on it. This effectively steals the |
| 14232 | * socket from the listener. |
| 14233 | * |
| 14234 | * @default {false} */ |
| 14235 | reuseAddress?: boolean; |
| 14236 | |
| 14237 | /** When `true`, sent multicast packets will be looped back to the local socket. |
| 14238 | * |
| 14239 | * @default {false} */ |
| 14240 | loopback?: boolean; |
| 14241 | } |
| 14242 | |
| 14243 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14244 | * |
| 14245 | * Listen announces on the local transport address. |
| 14246 | * |
| 14247 | * ```ts |
| 14248 | * const listener1 = Deno.listenDatagram({ |
| 14249 | * port: 80, |
| 14250 | * transport: "udp" |
| 14251 | * }); |
| 14252 | * const listener2 = Deno.listenDatagram({ |
| 14253 | * hostname: "golang.org", |
| 14254 | * port: 80, |
| 14255 | * transport: "udp" |
| 14256 | * }); |
| 14257 | * ``` |
| 14258 | * |
| 14259 | * Requires `allow-net` permission. |
| 14260 | * |
| 14261 | * @tags allow-net |
| 14262 | * @category Network |
| 14263 | * @experimental |
| 14264 | */ |
| 14265 | export function listenDatagram( |
| 14266 | options: UdpListenOptions & { transport: "udp" }, |
| 14267 | ): DatagramConn; |
| 14268 | |
| 14269 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14270 | * |
| 14271 | * Listen announces on the local transport address. |
| 14272 | * |
| 14273 | * ```ts |
| 14274 | * const listener = Deno.listenDatagram({ |
| 14275 | * path: "/foo/bar.sock", |
| 14276 | * transport: "unixpacket" |
| 14277 | * }); |
| 14278 | * ``` |
| 14279 | * |
| 14280 | * Requires `allow-read` and `allow-write` permission. |
| 14281 | * |
| 14282 | * @tags allow-read, allow-write |
| 14283 | * @category Network |
| 14284 | * @experimental |
| 14285 | */ |
| 14286 | export function listenDatagram( |
| 14287 | options: UnixListenOptions & { transport: "unixpacket" }, |
| 14288 | ): DatagramConn; |
| 14289 | |
| 14290 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14291 | * |
| 14292 | * Acquire an advisory file-system lock for the provided file. |
| 14293 | * |
| 14294 | * @param [exclusive=false] |
| 14295 | * @category File System |
| 14296 | * @experimental |
| 14297 | */ |
| 14298 | export function flock(rid: number, exclusive?: boolean): Promise<void>; |
| 14299 | |
| 14300 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14301 | * |
| 14302 | * Acquire an advisory file-system lock synchronously for the provided file. |
| 14303 | * |
| 14304 | * @param [exclusive=false] |
| 14305 | * @category File System |
| 14306 | * @experimental |
| 14307 | */ |
| 14308 | export function flockSync(rid: number, exclusive?: boolean): void; |
| 14309 | |
| 14310 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14311 | * |
| 14312 | * Release an advisory file-system lock for the provided file. |
| 14313 | * |
| 14314 | * @category File System |
| 14315 | * @experimental |
| 14316 | */ |
| 14317 | export function funlock(rid: number): Promise<void>; |
| 14318 | |
| 14319 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14320 | * |
| 14321 | * Release an advisory file-system lock for the provided file synchronously. |
| 14322 | * |
| 14323 | * @category File System |
| 14324 | * @experimental |
| 14325 | */ |
| 14326 | export function funlockSync(rid: number): void; |
| 14327 | |
| 14328 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14329 | * |
| 14330 | * Open a new {@linkcode Deno.Kv} connection to persist data. |
| 14331 | * |
| 14332 | * When a path is provided, the database will be persisted to disk at that |
| 14333 | * path. Read and write access to the file is required. |
| 14334 | * |
| 14335 | * When no path is provided, the database will be opened in a default path for |
| 14336 | * the current script. This location is persistent across script runs and is |
| 14337 | * keyed on the origin storage key (the same key that is used to determine |
| 14338 | * `localStorage` persistence). More information about the origin storage key |
| 14339 | * can be found in the Deno Manual. |
| 14340 | * |
| 14341 | * @tags allow-read, allow-write |
| 14342 | * @category Cloud |
| 14343 | * @experimental |
| 14344 | */ |
| 14345 | export function openKv(path?: string): Promise<Deno.Kv>; |
| 14346 | |
| 14347 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14348 | * |
| 14349 | * CronScheduleExpression is used as the type of `minute`, `hour`, |
| 14350 | * `dayOfMonth`, `month`, and `dayOfWeek` in {@linkcode CronSchedule}. |
| 14351 | * @category Cloud |
| 14352 | * @experimental |
| 14353 | */ |
| 14354 | export type CronScheduleExpression = number | { exact: number | number[] } | { |
| 14355 | start?: number; |
| 14356 | end?: number; |
| 14357 | every?: number; |
| 14358 | }; |
| 14359 | |
| 14360 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14361 | * |
| 14362 | * CronSchedule is the interface used for JSON format |
| 14363 | * cron `schedule`. |
| 14364 | * @category Cloud |
| 14365 | * @experimental |
| 14366 | */ |
| 14367 | export interface CronSchedule { |
| 14368 | minute?: CronScheduleExpression; |
| 14369 | hour?: CronScheduleExpression; |
| 14370 | dayOfMonth?: CronScheduleExpression; |
| 14371 | month?: CronScheduleExpression; |
| 14372 | dayOfWeek?: CronScheduleExpression; |
| 14373 | } |
| 14374 | |
| 14375 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14376 | * |
| 14377 | * Create a cron job that will periodically execute the provided handler |
| 14378 | * callback based on the specified schedule. |
| 14379 | * |
| 14380 | * ```ts |
| 14381 | * Deno.cron("sample cron", "20 * * * *", () => { |
| 14382 | * console.log("cron job executed"); |
| 14383 | * }); |
| 14384 | * ``` |
| 14385 | * |
| 14386 | * ```ts |
| 14387 | * Deno.cron("sample cron", { hour: { every: 6 } }, () => { |
| 14388 | * console.log("cron job executed"); |
| 14389 | * }); |
| 14390 | * ``` |
| 14391 | * |
| 14392 | * `schedule` can be a string in the Unix cron format or in JSON format |
| 14393 | * as specified by interface {@linkcode CronSchedule}, where time is specified |
| 14394 | * using UTC time zone. |
| 14395 | * |
| 14396 | * @category Cloud |
| 14397 | * @experimental |
| 14398 | */ |
| 14399 | export function cron( |
| 14400 | name: string, |
| 14401 | schedule: string | CronSchedule, |
| 14402 | handler: () => Promise<void> | void, |
| 14403 | ): Promise<void>; |
| 14404 | |
| 14405 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14406 | * |
| 14407 | * Create a cron job that will periodically execute the provided handler |
| 14408 | * callback based on the specified schedule. |
| 14409 | * |
| 14410 | * ```ts |
| 14411 | * Deno.cron("sample cron", "20 * * * *", { |
| 14412 | * backoffSchedule: [10, 20] |
| 14413 | * }, () => { |
| 14414 | * console.log("cron job executed"); |
| 14415 | * }); |
| 14416 | * ``` |
| 14417 | * |
| 14418 | * `schedule` can be a string in the Unix cron format or in JSON format |
| 14419 | * as specified by interface {@linkcode CronSchedule}, where time is specified |
| 14420 | * using UTC time zone. |
| 14421 | * |
| 14422 | * `backoffSchedule` option can be used to specify the retry policy for failed |
| 14423 | * executions. Each element in the array represents the number of milliseconds |
| 14424 | * to wait before retrying the execution. For example, `[1000, 5000, 10000]` |
| 14425 | * means that a failed execution will be retried at most 3 times, with 1 |
| 14426 | * second, 5 seconds, and 10 seconds delay between each retry. |
| 14427 | * |
| 14428 | * @category Cloud |
| 14429 | * @experimental |
| 14430 | */ |
| 14431 | export function cron( |
| 14432 | name: string, |
| 14433 | schedule: string | CronSchedule, |
| 14434 | options: { backoffSchedule?: number[]; signal?: AbortSignal }, |
| 14435 | handler: () => Promise<void> | void, |
| 14436 | ): Promise<void>; |
| 14437 | |
| 14438 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14439 | * |
| 14440 | * A key to be persisted in a {@linkcode Deno.Kv}. A key is a sequence |
| 14441 | * of {@linkcode Deno.KvKeyPart}s. |
| 14442 | * |
| 14443 | * Keys are ordered lexicographically by their parts. The first part is the |
| 14444 | * most significant, and the last part is the least significant. The order of |
| 14445 | * the parts is determined by both the type and the value of the part. The |
| 14446 | * relative significance of the types can be found in documentation for the |
| 14447 | * {@linkcode Deno.KvKeyPart} type. |
| 14448 | * |
| 14449 | * Keys have a maximum size of 2048 bytes serialized. If the size of the key |
| 14450 | * exceeds this limit, an error will be thrown on the operation that this key |
| 14451 | * was passed to. |
| 14452 | * |
| 14453 | * @category Cloud |
| 14454 | * @experimental |
| 14455 | */ |
| 14456 | export type KvKey = readonly KvKeyPart[]; |
| 14457 | |
| 14458 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14459 | * |
| 14460 | * A single part of a {@linkcode Deno.KvKey}. Parts are ordered |
| 14461 | * lexicographically, first by their type, and within a given type by their |
| 14462 | * value. |
| 14463 | * |
| 14464 | * The ordering of types is as follows: |
| 14465 | * |
| 14466 | * 1. `Uint8Array` |
| 14467 | * 2. `string` |
| 14468 | * 3. `number` |
| 14469 | * 4. `bigint` |
| 14470 | * 5. `boolean` |
| 14471 | * |
| 14472 | * Within a given type, the ordering is as follows: |
| 14473 | * |
| 14474 | * - `Uint8Array` is ordered by the byte ordering of the array |
| 14475 | * - `string` is ordered by the byte ordering of the UTF-8 encoding of the |
| 14476 | * string |
| 14477 | * - `number` is ordered following this pattern: `-NaN` |
| 14478 | * < `-Infinity` < `-100.0` < `-1.0` < -`0.5` < `-0.0` < `0.0` < `0.5` |
| 14479 | * < `1.0` < `100.0` < `Infinity` < `NaN` |
| 14480 | * - `bigint` is ordered by mathematical ordering, with the largest negative |
| 14481 | * number being the least first value, and the largest positive number |
| 14482 | * being the last value |
| 14483 | * - `boolean` is ordered by `false` < `true` |
| 14484 | * |
| 14485 | * This means that the part `1.0` (a number) is ordered before the part `2.0` |
| 14486 | * (also a number), but is greater than the part `0n` (a bigint), because |
| 14487 | * `1.0` is a number and `0n` is a bigint, and type ordering has precedence |
| 14488 | * over the ordering of values within a type. |
| 14489 | * |
| 14490 | * @category Cloud |
| 14491 | * @experimental |
| 14492 | */ |
| 14493 | export type KvKeyPart = |
| 14494 | | Uint8Array |
| 14495 | | string |
| 14496 | | number |
| 14497 | | bigint |
| 14498 | | boolean |
| 14499 | | symbol; |
| 14500 | |
| 14501 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14502 | * |
| 14503 | * Consistency level of a KV operation. |
| 14504 | * |
| 14505 | * - `strong` - This operation must be strongly-consistent. |
| 14506 | * - `eventual` - Eventually-consistent behavior is allowed. |
| 14507 | * |
| 14508 | * @category Cloud |
| 14509 | * @experimental |
| 14510 | */ |
| 14511 | export type KvConsistencyLevel = "strong" | "eventual"; |
| 14512 | |
| 14513 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14514 | * |
| 14515 | * A selector that selects the range of data returned by a list operation on a |
| 14516 | * {@linkcode Deno.Kv}. |
| 14517 | * |
| 14518 | * The selector can either be a prefix selector or a range selector. A prefix |
| 14519 | * selector selects all keys that start with the given prefix (optionally |
| 14520 | * starting at a given key). A range selector selects all keys that are |
| 14521 | * lexicographically between the given start and end keys. |
| 14522 | * |
| 14523 | * @category Cloud |
| 14524 | * @experimental |
| 14525 | */ |
| 14526 | export type KvListSelector = |
| 14527 | | { prefix: KvKey } |
| 14528 | | { prefix: KvKey; start: KvKey } |
| 14529 | | { prefix: KvKey; end: KvKey } |
| 14530 | | { start: KvKey; end: KvKey }; |
| 14531 | |
| 14532 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14533 | * |
| 14534 | * A mutation to a key in a {@linkcode Deno.Kv}. A mutation is a |
| 14535 | * combination of a key, a value, and a type. The type determines how the |
| 14536 | * mutation is applied to the key. |
| 14537 | * |
| 14538 | * - `set` - Sets the value of the key to the given value, overwriting any |
| 14539 | * existing value. Optionally an `expireIn` option can be specified to |
| 14540 | * set a time-to-live (TTL) for the key. The TTL is specified in |
| 14541 | * milliseconds, and the key will be deleted from the database at earliest |
| 14542 | * after the specified number of milliseconds have elapsed. Once the |
| 14543 | * specified duration has passed, the key may still be visible for some |
| 14544 | * additional time. If the `expireIn` option is not specified, the key will |
| 14545 | * not expire. |
| 14546 | * - `delete` - Deletes the key from the database. The mutation is a no-op if |
| 14547 | * the key does not exist. |
| 14548 | * - `sum` - Adds the given value to the existing value of the key. Both the |
| 14549 | * value specified in the mutation, and any existing value must be of type |
| 14550 | * `Deno.KvU64`. If the key does not exist, the value is set to the given |
| 14551 | * value (summed with 0). If the result of the sum overflows an unsigned |
| 14552 | * 64-bit integer, the result is wrapped around. |
| 14553 | * - `max` - Sets the value of the key to the maximum of the existing value |
| 14554 | * and the given value. Both the value specified in the mutation, and any |
| 14555 | * existing value must be of type `Deno.KvU64`. If the key does not exist, |
| 14556 | * the value is set to the given value. |
| 14557 | * - `min` - Sets the value of the key to the minimum of the existing value |
| 14558 | * and the given value. Both the value specified in the mutation, and any |
| 14559 | * existing value must be of type `Deno.KvU64`. If the key does not exist, |
| 14560 | * the value is set to the given value. |
| 14561 | * |
| 14562 | * @category Cloud |
| 14563 | * @experimental |
| 14564 | */ |
| 14565 | export type KvMutation = |
| 14566 | & { key: KvKey } |
| 14567 | & ( |
| 14568 | | { type: "set"; value: unknown; expireIn?: number } |
| 14569 | | { type: "delete" } |
| 14570 | | { type: "sum"; value: KvU64 } |
| 14571 | | { type: "max"; value: KvU64 } |
| 14572 | | { type: "min"; value: KvU64 } |
| 14573 | ); |
| 14574 | |
| 14575 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14576 | * |
| 14577 | * An iterator over a range of data entries in a {@linkcode Deno.Kv}. |
| 14578 | * |
| 14579 | * The cursor getter returns the cursor that can be used to resume the |
| 14580 | * iteration from the current position in the future. |
| 14581 | * |
| 14582 | * @category Cloud |
| 14583 | * @experimental |
| 14584 | */ |
| 14585 | export class KvListIterator<T> implements AsyncIterableIterator<KvEntry<T>> { |
| 14586 | /** |
| 14587 | * Returns the cursor of the current position in the iteration. This cursor |
| 14588 | * can be used to resume the iteration from the current position in the |
| 14589 | * future by passing it to the `cursor` option of the `list` method. |
| 14590 | */ |
| 14591 | get cursor(): string; |
| 14592 | |
| 14593 | next(): Promise<IteratorResult<KvEntry<T>, undefined>>; |
| 14594 | [Symbol.asyncIterator](): AsyncIterableIterator<KvEntry<T>>; |
| 14595 | } |
| 14596 | |
| 14597 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14598 | * |
| 14599 | * A versioned pair of key and value in a {@linkcode Deno.Kv}. |
| 14600 | * |
| 14601 | * The `versionstamp` is a string that represents the current version of the |
| 14602 | * key-value pair. It can be used to perform atomic operations on the KV store |
| 14603 | * by passing it to the `check` method of a {@linkcode Deno.AtomicOperation}. |
| 14604 | * |
| 14605 | * @category Cloud |
| 14606 | * @experimental |
| 14607 | */ |
| 14608 | export type KvEntry<T> = { key: KvKey; value: T; versionstamp: string }; |
| 14609 | |
| 14610 | /** |
| 14611 | * **UNSTABLE**: New API, yet to be vetted. |
| 14612 | * |
| 14613 | * An optional versioned pair of key and value in a {@linkcode Deno.Kv}. |
| 14614 | * |
| 14615 | * This is the same as a {@linkcode KvEntry}, but the `value` and `versionstamp` |
| 14616 | * fields may be `null` if no value exists for the given key in the KV store. |
| 14617 | * |
| 14618 | * @category Cloud |
| 14619 | * @experimental |
| 14620 | */ |
| 14621 | export type KvEntryMaybe<T> = KvEntry<T> | { |
| 14622 | key: KvKey; |
| 14623 | value: null; |
| 14624 | versionstamp: null; |
| 14625 | }; |
| 14626 | |
| 14627 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14628 | * |
| 14629 | * Options for listing key-value pairs in a {@linkcode Deno.Kv}. |
| 14630 | * |
| 14631 | * @category Cloud |
| 14632 | * @experimental |
| 14633 | */ |
| 14634 | export interface KvListOptions { |
| 14635 | /** |
| 14636 | * The maximum number of key-value pairs to return. If not specified, all |
| 14637 | * matching key-value pairs will be returned. |
| 14638 | */ |
| 14639 | limit?: number; |
| 14640 | /** |
| 14641 | * The cursor to resume the iteration from. If not specified, the iteration |
| 14642 | * will start from the beginning. |
| 14643 | */ |
| 14644 | cursor?: string; |
| 14645 | /** |
| 14646 | * Whether to reverse the order of the returned key-value pairs. If not |
| 14647 | * specified, the order will be ascending from the start of the range as per |
| 14648 | * the lexicographical ordering of the keys. If `true`, the order will be |
| 14649 | * descending from the end of the range. |
| 14650 | * |
| 14651 | * The default value is `false`. |
| 14652 | */ |
| 14653 | reverse?: boolean; |
| 14654 | /** |
| 14655 | * The consistency level of the list operation. The default consistency |
| 14656 | * level is "strong". Some use cases can benefit from using a weaker |
| 14657 | * consistency level. For more information on consistency levels, see the |
| 14658 | * documentation for {@linkcode Deno.KvConsistencyLevel}. |
| 14659 | * |
| 14660 | * List operations are performed in batches (in sizes specified by the |
| 14661 | * `batchSize` option). The consistency level of the list operation is |
| 14662 | * applied to each batch individually. This means that while each batch is |
| 14663 | * guaranteed to be consistent within itself, the entire list operation may |
| 14664 | * not be consistent across batches because a mutation may be applied to a |
| 14665 | * key-value pair between batches, in a batch that has already been returned |
| 14666 | * by the list operation. |
| 14667 | */ |
| 14668 | consistency?: KvConsistencyLevel; |
| 14669 | /** |
| 14670 | * The size of the batches in which the list operation is performed. Larger |
| 14671 | * or smaller batch sizes may positively or negatively affect the |
| 14672 | * performance of a list operation depending on the specific use case and |
| 14673 | * iteration behavior. Slow iterating queries may benefit from using a |
| 14674 | * smaller batch size for increased overall consistency, while fast |
| 14675 | * iterating queries may benefit from using a larger batch size for better |
| 14676 | * performance. |
| 14677 | * |
| 14678 | * The default batch size is equal to the `limit` option, or 100 if this is |
| 14679 | * unset. The maximum value for this option is 500. Larger values will be |
| 14680 | * clamped. |
| 14681 | */ |
| 14682 | batchSize?: number; |
| 14683 | } |
| 14684 | |
| 14685 | /** |
| 14686 | * @category Cloud |
| 14687 | * @experimental |
| 14688 | */ |
| 14689 | export interface KvCommitResult { |
| 14690 | ok: true; |
| 14691 | /** The versionstamp of the value committed to KV. */ |
| 14692 | versionstamp: string; |
| 14693 | } |
| 14694 | |
| 14695 | /** |
| 14696 | * @category Cloud |
| 14697 | * @experimental |
| 14698 | */ |
| 14699 | export interface KvCommitError { |
| 14700 | ok: false; |
| 14701 | } |
| 14702 | |
| 14703 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14704 | * |
| 14705 | * A check to perform as part of a {@linkcode Deno.AtomicOperation}. The check |
| 14706 | * will fail if the versionstamp for the key-value pair in the KV store does |
| 14707 | * not match the given versionstamp. A check with a `null` versionstamp checks |
| 14708 | * that the key-value pair does not currently exist in the KV store. |
| 14709 | * |
| 14710 | * @category Cloud |
| 14711 | * @experimental |
| 14712 | */ |
| 14713 | export interface AtomicCheck { |
| 14714 | key: KvKey; |
| 14715 | versionstamp: string | null; |
| 14716 | } |
| 14717 | |
| 14718 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14719 | * |
| 14720 | * An operation on a {@linkcode Deno.Kv} that can be performed |
| 14721 | * atomically. Atomic operations do not auto-commit, and must be committed |
| 14722 | * explicitly by calling the `commit` method. |
| 14723 | * |
| 14724 | * Atomic operations can be used to perform multiple mutations on the KV store |
| 14725 | * in a single atomic transaction. They can also be used to perform |
| 14726 | * conditional mutations by specifying one or more |
| 14727 | * {@linkcode Deno.AtomicCheck}s that ensure that a mutation is only performed |
| 14728 | * if the key-value pair in the KV has a specific versionstamp. If any of the |
| 14729 | * checks fail, the entire operation will fail and no mutations will be made. |
| 14730 | * |
| 14731 | * The ordering of mutations is guaranteed to be the same as the ordering of |
| 14732 | * the mutations specified in the operation. Checks are performed before any |
| 14733 | * mutations are performed. The ordering of checks is unobservable. |
| 14734 | * |
| 14735 | * Atomic operations can be used to implement optimistic locking, where a |
| 14736 | * mutation is only performed if the key-value pair in the KV store has not |
| 14737 | * been modified since the last read. This can be done by specifying a check |
| 14738 | * that ensures that the versionstamp of the key-value pair matches the |
| 14739 | * versionstamp that was read. If the check fails, the mutation will not be |
| 14740 | * performed and the operation will fail. One can then retry the read-modify- |
| 14741 | * write operation in a loop until it succeeds. |
| 14742 | * |
| 14743 | * The `commit` method of an atomic operation returns a value indicating |
| 14744 | * whether checks passed and mutations were performed. If the operation failed |
| 14745 | * because of a failed check, the return value will be a |
| 14746 | * {@linkcode Deno.KvCommitError} with an `ok: false` property. If the |
| 14747 | * operation failed for any other reason (storage error, invalid value, etc.), |
| 14748 | * an exception will be thrown. If the operation succeeded, the return value |
| 14749 | * will be a {@linkcode Deno.KvCommitResult} object with a `ok: true` property |
| 14750 | * and the versionstamp of the value committed to KV. |
| 14751 | * |
| 14752 | * @category Cloud |
| 14753 | * @experimental |
| 14754 | */ |
| 14755 | export class AtomicOperation { |
| 14756 | /** |
| 14757 | * Add to the operation a check that ensures that the versionstamp of the |
| 14758 | * key-value pair in the KV store matches the given versionstamp. If the |
| 14759 | * check fails, the entire operation will fail and no mutations will be |
| 14760 | * performed during the commit. |
| 14761 | */ |
| 14762 | check(...checks: AtomicCheck[]): this; |
| 14763 | /** |
| 14764 | * Add to the operation a mutation that performs the specified mutation on |
| 14765 | * the specified key if all checks pass during the commit. The types and |
| 14766 | * semantics of all available mutations are described in the documentation |
| 14767 | * for {@linkcode Deno.KvMutation}. |
| 14768 | */ |
| 14769 | mutate(...mutations: KvMutation[]): this; |
| 14770 | /** |
| 14771 | * Shortcut for creating a `sum` mutation. This method wraps `n` in a |
| 14772 | * {@linkcode Deno.KvU64}, so the value of `n` must be in the range |
| 14773 | * `[0, 2^64-1]`. |
| 14774 | */ |
| 14775 | sum(key: KvKey, n: bigint): this; |
| 14776 | /** |
| 14777 | * Shortcut for creating a `min` mutation. This method wraps `n` in a |
| 14778 | * {@linkcode Deno.KvU64}, so the value of `n` must be in the range |
| 14779 | * `[0, 2^64-1]`. |
| 14780 | */ |
| 14781 | min(key: KvKey, n: bigint): this; |
| 14782 | /** |
| 14783 | * Shortcut for creating a `max` mutation. This method wraps `n` in a |
| 14784 | * {@linkcode Deno.KvU64}, so the value of `n` must be in the range |
| 14785 | * `[0, 2^64-1]`. |
| 14786 | */ |
| 14787 | max(key: KvKey, n: bigint): this; |
| 14788 | /** |
| 14789 | * Add to the operation a mutation that sets the value of the specified key |
| 14790 | * to the specified value if all checks pass during the commit. |
| 14791 | * |
| 14792 | * Optionally an `expireIn` option can be specified to set a time-to-live |
| 14793 | * (TTL) for the key. The TTL is specified in milliseconds, and the key will |
| 14794 | * be deleted from the database at earliest after the specified number of |
| 14795 | * milliseconds have elapsed. Once the specified duration has passed, the |
| 14796 | * key may still be visible for some additional time. If the `expireIn` |
| 14797 | * option is not specified, the key will not expire. |
| 14798 | */ |
| 14799 | set(key: KvKey, value: unknown, options?: { expireIn?: number }): this; |
| 14800 | /** |
| 14801 | * Add to the operation a mutation that deletes the specified key if all |
| 14802 | * checks pass during the commit. |
| 14803 | */ |
| 14804 | delete(key: KvKey): this; |
| 14805 | /** |
| 14806 | * Add to the operation a mutation that enqueues a value into the queue |
| 14807 | * if all checks pass during the commit. |
| 14808 | */ |
| 14809 | enqueue( |
| 14810 | value: unknown, |
| 14811 | options?: { |
| 14812 | delay?: number; |
| 14813 | keysIfUndelivered?: Deno.KvKey[]; |
| 14814 | backoffSchedule?: number[]; |
| 14815 | }, |
| 14816 | ): this; |
| 14817 | /** |
| 14818 | * Commit the operation to the KV store. Returns a value indicating whether |
| 14819 | * checks passed and mutations were performed. If the operation failed |
| 14820 | * because of a failed check, the return value will be a {@linkcode |
| 14821 | * Deno.KvCommitError} with an `ok: false` property. If the operation failed |
| 14822 | * for any other reason (storage error, invalid value, etc.), an exception |
| 14823 | * will be thrown. If the operation succeeded, the return value will be a |
| 14824 | * {@linkcode Deno.KvCommitResult} object with a `ok: true` property and the |
| 14825 | * versionstamp of the value committed to KV. |
| 14826 | * |
| 14827 | * If the commit returns `ok: false`, one may create a new atomic operation |
| 14828 | * with updated checks and mutations and attempt to commit it again. See the |
| 14829 | * note on optimistic locking in the documentation for |
| 14830 | * {@linkcode Deno.AtomicOperation}. |
| 14831 | */ |
| 14832 | commit(): Promise<KvCommitResult | KvCommitError>; |
| 14833 | } |
| 14834 | |
| 14835 | /** **UNSTABLE**: New API, yet to be vetted. |
| 14836 | * |
| 14837 | * A key-value database that can be used to store and retrieve data. |
| 14838 | * |
| 14839 | * Data is stored as key-value pairs, where the key is a {@linkcode Deno.KvKey} |
| 14840 | * and the value is an arbitrary structured-serializable JavaScript value. |
| 14841 | * Keys are ordered lexicographically as described in the documentation for |
| 14842 | * {@linkcode Deno.KvKey}. Keys are unique within a database, and the last |
| 14843 | * value set for a given key is the one that is returned when reading the |
| 14844 | * key. Keys can be deleted from the database, in which case they will no |
| 14845 | * longer be returned when reading keys. |
| 14846 | * |
| 14847 | * Values can be any structured-serializable JavaScript value (objects, |
| 14848 | * arrays, strings, numbers, etc.). The special value {@linkcode Deno.KvU64} |
| 14849 | * can be used to store 64-bit unsigned integers in the database. This special |
| 14850 | * value can not be nested within other objects or arrays. In addition to the |
| 14851 | * regular database mutation operations, the unsigned 64-bit integer value |
| 14852 | * also supports `sum`, `max`, and `min` mutations. |
| 14853 | * |
| 14854 | * Keys are versioned on write by assigning the key an ever-increasing |
| 14855 | * "versionstamp". The versionstamp represents the version of a key-value pair |
| 14856 | * in the database at some point in time, and can be used to perform |
| 14857 | * transactional operations on the database without requiring any locking. |
| 14858 | * This is enabled by atomic operations, which can have conditions that ensure |
| 14859 | * that the operation only succeeds if the versionstamp of the key-value pair |
| 14860 | * matches an expected versionstamp. |
| 14861 | * |
| 14862 | * Keys have a maximum length of 2048 bytes after serialization. Values have a |
| 14863 | * maximum length of 64 KiB after serialization. Serialization of both keys |
| 14864 | * and values is somewhat opaque, but one can usually assume that the |
| 14865 | * serialization of any value is about the same length as the resulting string |
| 14866 | * of a JSON serialization of that same value. If theses limits are exceeded, |
| 14867 | * an exception will be thrown. |
| 14868 | * |
| 14869 | * @category Cloud |
| 14870 | * @experimental |
| 14871 | */ |
| 14872 | export class Kv implements Disposable { |
| 14873 | /** |
| 14874 | * Retrieve the value and versionstamp for the given key from the database |
| 14875 | * in the form of a {@linkcode Deno.KvEntryMaybe}. If no value exists for |
| 14876 | * the key, the returned entry will have a `null` value and versionstamp. |
| 14877 | * |
| 14878 | * ```ts |
| 14879 | * const db = await Deno.openKv(); |
| 14880 | * const result = await db.get(["foo"]); |
| 14881 | * result.key; // ["foo"] |
| 14882 | * result.value; // "bar" |
| 14883 | * result.versionstamp; // "00000000000000010000" |
| 14884 | * ``` |
| 14885 | * |
| 14886 | * The `consistency` option can be used to specify the consistency level |
| 14887 | * for the read operation. The default consistency level is "strong". Some |
| 14888 | * use cases can benefit from using a weaker consistency level. For more |
| 14889 | * information on consistency levels, see the documentation for |
| 14890 | * {@linkcode Deno.KvConsistencyLevel}. |
| 14891 | */ |
| 14892 | get<T = unknown>( |
| 14893 | key: KvKey, |
| 14894 | options?: { consistency?: KvConsistencyLevel }, |
| 14895 | ): Promise<KvEntryMaybe<T>>; |
| 14896 | |
| 14897 | /** |
| 14898 | * Retrieve multiple values and versionstamps from the database in the form |
| 14899 | * of an array of {@linkcode Deno.KvEntryMaybe} objects. The returned array |
| 14900 | * will have the same length as the `keys` array, and the entries will be in |
| 14901 | * the same order as the keys. If no value exists for a given key, the |
| 14902 | * returned entry will have a `null` value and versionstamp. |
| 14903 | * |
| 14904 | * ```ts |
| 14905 | * const db = await Deno.openKv(); |
| 14906 | * const result = await db.getMany([["foo"], ["baz"]]); |
| 14907 | * result[0].key; // ["foo"] |
| 14908 | * result[0].value; // "bar" |
| 14909 | * result[0].versionstamp; // "00000000000000010000" |
| 14910 | * result[1].key; // ["baz"] |
| 14911 | * result[1].value; // null |
| 14912 | * result[1].versionstamp; // null |
| 14913 | * ``` |
| 14914 | * |
| 14915 | * The `consistency` option can be used to specify the consistency level |
| 14916 | * for the read operation. The default consistency level is "strong". Some |
| 14917 | * use cases can benefit from using a weaker consistency level. For more |
| 14918 | * information on consistency levels, see the documentation for |
| 14919 | * {@linkcode Deno.KvConsistencyLevel}. |
| 14920 | */ |
| 14921 | getMany<T extends readonly unknown[]>( |
| 14922 | keys: readonly [...{ [K in keyof T]: KvKey }], |
| 14923 | options?: { consistency?: KvConsistencyLevel }, |
| 14924 | ): Promise<{ [K in keyof T]: KvEntryMaybe<T[K]> }>; |
| 14925 | /** |
| 14926 | * Set the value for the given key in the database. If a value already |
| 14927 | * exists for the key, it will be overwritten. |
| 14928 | * |
| 14929 | * ```ts |
| 14930 | * const db = await Deno.openKv(); |
| 14931 | * await db.set(["foo"], "bar"); |
| 14932 | * ``` |
| 14933 | * |
| 14934 | * Optionally an `expireIn` option can be specified to set a time-to-live |
| 14935 | * (TTL) for the key. The TTL is specified in milliseconds, and the key will |
| 14936 | * be deleted from the database at earliest after the specified number of |
| 14937 | * milliseconds have elapsed. Once the specified duration has passed, the |
| 14938 | * key may still be visible for some additional time. If the `expireIn` |
| 14939 | * option is not specified, the key will not expire. |
| 14940 | */ |
| 14941 | set( |
| 14942 | key: KvKey, |
| 14943 | value: unknown, |
| 14944 | options?: { expireIn?: number }, |
| 14945 | ): Promise<KvCommitResult>; |
| 14946 | |
| 14947 | /** |
| 14948 | * Delete the value for the given key from the database. If no value exists |
| 14949 | * for the key, this operation is a no-op. |
| 14950 | * |
| 14951 | * ```ts |
| 14952 | * const db = await Deno.openKv(); |
| 14953 | * await db.delete(["foo"]); |
| 14954 | * ``` |
| 14955 | */ |
| 14956 | delete(key: KvKey): Promise<void>; |
| 14957 | |
| 14958 | /** |
| 14959 | * Retrieve a list of keys in the database. The returned list is an |
| 14960 | * {@linkcode Deno.KvListIterator} which can be used to iterate over the |
| 14961 | * entries in the database. |
| 14962 | * |
| 14963 | * Each list operation must specify a selector which is used to specify the |
| 14964 | * range of keys to return. The selector can either be a prefix selector, or |
| 14965 | * a range selector: |
| 14966 | * |
| 14967 | * - A prefix selector selects all keys that start with the given prefix of |
| 14968 | * key parts. For example, the selector `["users"]` will select all keys |
| 14969 | * that start with the prefix `["users"]`, such as `["users", "alice"]` |
| 14970 | * and `["users", "bob"]`. Note that you can not partially match a key |
| 14971 | * part, so the selector `["users", "a"]` will not match the key |
| 14972 | * `["users", "alice"]`. A prefix selector may specify a `start` key that |
| 14973 | * is used to skip over keys that are lexicographically less than the |
| 14974 | * start key. |
| 14975 | * - A range selector selects all keys that are lexicographically between |
| 14976 | * the given start and end keys (including the start, and excluding the |
| 14977 | * end). For example, the selector `["users", "a"], ["users", "n"]` will |
| 14978 | * select all keys that start with the prefix `["users"]` and have a |
| 14979 | * second key part that is lexicographically between `a` and `n`, such as |
| 14980 | * `["users", "alice"]`, `["users", "bob"]`, and `["users", "mike"]`, but |
| 14981 | * not `["users", "noa"]` or `["users", "zoe"]`. |
| 14982 | * |
| 14983 | * ```ts |
| 14984 | * const db = await Deno.openKv(); |
| 14985 | * const entries = db.list({ prefix: ["users"] }); |
| 14986 | * for await (const entry of entries) { |
| 14987 | * entry.key; // ["users", "alice"] |
| 14988 | * entry.value; // { name: "Alice" } |
| 14989 | * entry.versionstamp; // "00000000000000010000" |
| 14990 | * } |
| 14991 | * ``` |
| 14992 | * |
| 14993 | * The `options` argument can be used to specify additional options for the |
| 14994 | * list operation. See the documentation for {@linkcode Deno.KvListOptions} |
| 14995 | * for more information. |
| 14996 | */ |
| 14997 | list<T = unknown>( |
| 14998 | selector: KvListSelector, |
| 14999 | options?: KvListOptions, |
| 15000 | ): KvListIterator<T>; |
| 15001 | |
| 15002 | /** |
| 15003 | * Add a value into the database queue to be delivered to the queue |
| 15004 | * listener via {@linkcode Deno.Kv.listenQueue}. |
| 15005 | * |
| 15006 | * ```ts |
| 15007 | * const db = await Deno.openKv(); |
| 15008 | * await db.enqueue("bar"); |
| 15009 | * ``` |
| 15010 | * |
| 15011 | * The `delay` option can be used to specify the delay (in milliseconds) |
| 15012 | * of the value delivery. The default delay is 0, which means immediate |
| 15013 | * delivery. |
| 15014 | * |
| 15015 | * ```ts |
| 15016 | * const db = await Deno.openKv(); |
| 15017 | * await db.enqueue("bar", { delay: 60000 }); |
| 15018 | * ``` |
| 15019 | * |
| 15020 | * The `keysIfUndelivered` option can be used to specify the keys to |
| 15021 | * be set if the value is not successfully delivered to the queue |
| 15022 | * listener after several attempts. The values are set to the value of |
| 15023 | * the queued message. |
| 15024 | * |
| 15025 | * The `backoffSchedule` option can be used to specify the retry policy for |
| 15026 | * failed message delivery. Each element in the array represents the number of |
| 15027 | * milliseconds to wait before retrying the delivery. For example, |
| 15028 | * `[1000, 5000, 10000]` means that a failed delivery will be retried |
| 15029 | * at most 3 times, with 1 second, 5 seconds, and 10 seconds delay |
| 15030 | * between each retry. |
| 15031 | * |
| 15032 | * ```ts |
| 15033 | * const db = await Deno.openKv(); |
| 15034 | * await db.enqueue("bar", { |
| 15035 | * keysIfUndelivered: [["foo", "bar"]], |
| 15036 | * backoffSchedule: [1000, 5000, 10000], |
| 15037 | * }); |
| 15038 | * ``` |
| 15039 | */ |
| 15040 | enqueue( |
| 15041 | value: unknown, |
| 15042 | options?: { |
| 15043 | delay?: number; |
| 15044 | keysIfUndelivered?: Deno.KvKey[]; |
| 15045 | backoffSchedule?: number[]; |
| 15046 | }, |
| 15047 | ): Promise<KvCommitResult>; |
| 15048 | |
| 15049 | /** |
| 15050 | * Listen for queue values to be delivered from the database queue, which |
| 15051 | * were enqueued with {@linkcode Deno.Kv.enqueue}. The provided handler |
| 15052 | * callback is invoked on every dequeued value. A failed callback |
| 15053 | * invocation is automatically retried multiple times until it succeeds |
| 15054 | * or until the maximum number of retries is reached. |
| 15055 | * |
| 15056 | * ```ts |
| 15057 | * const db = await Deno.openKv(); |
| 15058 | * db.listenQueue(async (msg: unknown) => { |
| 15059 | * await db.set(["foo"], msg); |
| 15060 | * }); |
| 15061 | * ``` |
| 15062 | */ |
| 15063 | // deno-lint-ignore no-explicit-any |
| 15064 | listenQueue(handler: (value: any) => Promise<void> | void): Promise<void>; |
| 15065 | |
| 15066 | /** |
| 15067 | * Create a new {@linkcode Deno.AtomicOperation} object which can be used to |
| 15068 | * perform an atomic transaction on the database. This does not perform any |
| 15069 | * operations on the database - the atomic transaction must be committed |
| 15070 | * explicitly using the {@linkcode Deno.AtomicOperation.commit} method once |
| 15071 | * all checks and mutations have been added to the operation. |
| 15072 | */ |
| 15073 | atomic(): AtomicOperation; |
| 15074 | |
| 15075 | /** |
| 15076 | * Watch for changes to the given keys in the database. The returned stream |
| 15077 | * is a {@linkcode ReadableStream} that emits a new value whenever any of |
| 15078 | * the watched keys change their versionstamp. The emitted value is an array |
| 15079 | * of {@linkcode Deno.KvEntryMaybe} objects, with the same length and order |
| 15080 | * as the `keys` array. If no value exists for a given key, the returned |
| 15081 | * entry will have a `null` value and versionstamp. |
| 15082 | * |
| 15083 | * The returned stream does not return every single intermediate state of |
| 15084 | * the watched keys, but rather only keeps you up to date with the latest |
| 15085 | * state of the keys. This means that if a key is modified multiple times |
| 15086 | * quickly, you may not receive a notification for every single change, but |
| 15087 | * rather only the latest state of the key. |
| 15088 | * |
| 15089 | * ```ts |
| 15090 | * const db = await Deno.openKv(); |
| 15091 | * |
| 15092 | * const stream = db.watch([["foo"], ["bar"]]); |
| 15093 | * for await (const entries of stream) { |
| 15094 | * entries[0].key; // ["foo"] |
| 15095 | * entries[0].value; // "bar" |
| 15096 | * entries[0].versionstamp; // "00000000000000010000" |
| 15097 | * entries[1].key; // ["bar"] |
| 15098 | * entries[1].value; // null |
| 15099 | * entries[1].versionstamp; // null |
| 15100 | * } |
| 15101 | * ``` |
| 15102 | * |
| 15103 | * The `options` argument can be used to specify additional options for the |
| 15104 | * watch operation. The `raw` option can be used to specify whether a new |
| 15105 | * value should be emitted whenever a mutation occurs on any of the watched |
| 15106 | * keys (even if the value of the key does not change, such as deleting a |
| 15107 | * deleted key), or only when entries have observably changed in some way. |
| 15108 | * When `raw: true` is used, it is possible for the stream to occasionally |
| 15109 | * emit values even if no mutations have occurred on any of the watched |
| 15110 | * keys. The default value for this option is `false`. |
| 15111 | */ |
| 15112 | watch<T extends readonly unknown[]>( |
| 15113 | keys: readonly [...{ [K in keyof T]: KvKey }], |
| 15114 | options?: { raw?: boolean }, |
| 15115 | ): ReadableStream<{ [K in keyof T]: KvEntryMaybe<T[K]> }>; |
| 15116 | |
| 15117 | /** |
| 15118 | * Close the database connection. This will prevent any further operations |
| 15119 | * from being performed on the database, and interrupt any in-flight |
| 15120 | * operations immediately. |
| 15121 | */ |
| 15122 | close(): void; |
| 15123 | |
| 15124 | /** |
| 15125 | * Get a symbol that represents the versionstamp of the current atomic |
| 15126 | * operation. This symbol can be used as the last part of a key in |
| 15127 | * `.set()`, both directly on the `Kv` object and on an `AtomicOperation` |
| 15128 | * object created from this `Kv` instance. |
| 15129 | */ |
| 15130 | commitVersionstamp(): symbol; |
| 15131 | |
| 15132 | [Symbol.dispose](): void; |
| 15133 | } |
| 15134 | |
| 15135 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15136 | * |
| 15137 | * Wrapper type for 64-bit unsigned integers for use as values in a |
| 15138 | * {@linkcode Deno.Kv}. |
| 15139 | * |
| 15140 | * @category Cloud |
| 15141 | * @experimental |
| 15142 | */ |
| 15143 | export class KvU64 { |
| 15144 | /** Create a new `KvU64` instance from the given bigint value. If the value |
| 15145 | * is signed or greater than 64-bits, an error will be thrown. */ |
| 15146 | constructor(value: bigint); |
| 15147 | /** The value of this unsigned 64-bit integer, represented as a bigint. */ |
| 15148 | readonly value: bigint; |
| 15149 | } |
| 15150 | |
| 15151 | /** |
| 15152 | * A namespace containing runtime APIs available in Jupyter notebooks. |
| 15153 | * |
| 15154 | * When accessed outside of Jupyter notebook context an error will be thrown. |
| 15155 | * |
| 15156 | * @category Jupyter |
| 15157 | * @experimental |
| 15158 | */ |
| 15159 | export namespace jupyter { |
| 15160 | /** |
| 15161 | * @category Jupyter |
| 15162 | * @experimental |
| 15163 | */ |
| 15164 | export interface DisplayOptions { |
| 15165 | raw?: boolean; |
| 15166 | update?: boolean; |
| 15167 | display_id?: string; |
| 15168 | } |
| 15169 | |
| 15170 | /** |
| 15171 | * @category Jupyter |
| 15172 | * @experimental |
| 15173 | */ |
| 15174 | export type VegaObject = { |
| 15175 | $schema: string; |
| 15176 | [key: string]: unknown; |
| 15177 | }; |
| 15178 | |
| 15179 | /** |
| 15180 | * A collection of supported media types and data for Jupyter frontends. |
| 15181 | * |
| 15182 | * @category Jupyter |
| 15183 | * @experimental |
| 15184 | */ |
| 15185 | export type MediaBundle = { |
| 15186 | "text/plain"?: string; |
| 15187 | "text/html"?: string; |
| 15188 | "image/svg+xml"?: string; |
| 15189 | "text/markdown"?: string; |
| 15190 | "application/javascript"?: string; |
| 15191 | |
| 15192 | // Images (per Jupyter spec) must be base64 encoded. We could _allow_ |
| 15193 | // accepting Uint8Array or ArrayBuffer within `display` calls, however we still |
| 15194 | // must encode them for jupyter. |
| 15195 | "image/png"?: string; // WISH: Uint8Array | ArrayBuffer |
| 15196 | "image/jpeg"?: string; // WISH: Uint8Array | ArrayBuffer |
| 15197 | "image/gif"?: string; // WISH: Uint8Array | ArrayBuffer |
| 15198 | "application/pdf"?: string; // WISH: Uint8Array | ArrayBuffer |
| 15199 | |
| 15200 | // NOTE: all JSON types must be objects at the top level (no arrays, strings, or other primitives) |
| 15201 | "application/json"?: object; |
| 15202 | "application/geo+json"?: object; |
| 15203 | "application/vdom.v1+json"?: object; |
| 15204 | "application/vnd.plotly.v1+json"?: object; |
| 15205 | "application/vnd.vega.v5+json"?: VegaObject; |
| 15206 | "application/vnd.vegalite.v4+json"?: VegaObject; |
| 15207 | "application/vnd.vegalite.v5+json"?: VegaObject; |
| 15208 | |
| 15209 | // Must support a catch all for custom media types / mimetypes |
| 15210 | [key: string]: string | object | undefined; |
| 15211 | }; |
| 15212 | |
| 15213 | /** |
| 15214 | * @category Jupyter |
| 15215 | * @experimental |
| 15216 | */ |
| 15217 | export const $display: unique symbol; |
| 15218 | |
| 15219 | /** |
| 15220 | * @category Jupyter |
| 15221 | * @experimental |
| 15222 | */ |
| 15223 | export type Displayable = { |
| 15224 | [$display]: () => MediaBundle | Promise<MediaBundle>; |
| 15225 | }; |
| 15226 | |
| 15227 | /** |
| 15228 | * Display function for Jupyter Deno Kernel. |
| 15229 | * Mimics the behavior of IPython's `display(obj, raw=True)` function to allow |
| 15230 | * asynchronous displaying of objects in Jupyter. |
| 15231 | * |
| 15232 | * @param obj - The object to be displayed |
| 15233 | * @param options - Display options with a default { raw: true } |
| 15234 | * @category Jupyter |
| 15235 | * @experimental |
| 15236 | */ |
| 15237 | export function display(obj: unknown, options?: DisplayOptions): void; |
| 15238 | |
| 15239 | /** |
| 15240 | * Show Markdown in Jupyter frontends with a tagged template function. |
| 15241 | * |
| 15242 | * Takes a template string and returns a displayable object for Jupyter frontends. |
| 15243 | * |
| 15244 | * @example |
| 15245 | * Create a Markdown view. |
| 15246 | * |
| 15247 | * ```typescript |
| 15248 | * const { md } = Deno.jupyter; |
| 15249 | * md`# Notebooks in TypeScript via Deno  |
| 15250 | * |
| 15251 | * * TypeScript ${Deno.version.typescript} |
| 15252 | * * V8 ${Deno.version.v8} |
| 15253 | * * Deno ${Deno.version.deno} |
| 15254 | * |
| 15255 | * Interactive compute with Jupyter _built into Deno_! |
| 15256 | * ` |
| 15257 | * ``` |
| 15258 | * |
| 15259 | * @category Jupyter |
| 15260 | * @experimental |
| 15261 | */ |
| 15262 | export function md( |
| 15263 | strings: TemplateStringsArray, |
| 15264 | ...values: unknown[] |
| 15265 | ): Displayable; |
| 15266 | |
| 15267 | /** |
| 15268 | * Show HTML in Jupyter frontends with a tagged template function. |
| 15269 | * |
| 15270 | * Takes a template string and returns a displayable object for Jupyter frontends. |
| 15271 | * |
| 15272 | * @example |
| 15273 | * Create an HTML view. |
| 15274 | * ```typescript |
| 15275 | * const { html } = Deno.jupyter; |
| 15276 | * html`<h1>Hello, world!</h1>` |
| 15277 | * ``` |
| 15278 | * |
| 15279 | * @category Jupyter |
| 15280 | * @experimental |
| 15281 | */ |
| 15282 | export function html( |
| 15283 | strings: TemplateStringsArray, |
| 15284 | ...values: unknown[] |
| 15285 | ): Displayable; |
| 15286 | |
| 15287 | /** |
| 15288 | * SVG Tagged Template Function. |
| 15289 | * |
| 15290 | * Takes a template string and returns a displayable object for Jupyter frontends. |
| 15291 | * |
| 15292 | * Example usage: |
| 15293 | * |
| 15294 | * svg`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"> |
| 15295 | * <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" /> |
| 15296 | * </svg>` |
| 15297 | * |
| 15298 | * @category Jupyter |
| 15299 | * @experimental |
| 15300 | */ |
| 15301 | export function svg( |
| 15302 | strings: TemplateStringsArray, |
| 15303 | ...values: unknown[] |
| 15304 | ): Displayable; |
| 15305 | |
| 15306 | /** |
| 15307 | * Format an object for displaying in Deno |
| 15308 | * |
| 15309 | * @param obj - The object to be displayed |
| 15310 | * @returns MediaBundle |
| 15311 | * |
| 15312 | * @category Jupyter |
| 15313 | * @experimental |
| 15314 | */ |
| 15315 | export function format(obj: unknown): MediaBundle; |
| 15316 | |
| 15317 | /** |
| 15318 | * Broadcast a message on IO pub channel. |
| 15319 | * |
| 15320 | * ``` |
| 15321 | * await Deno.jupyter.broadcast("display_data", { |
| 15322 | * data: { "text/html": "<b>Processing.</b>" }, |
| 15323 | * metadata: {}, |
| 15324 | * transient: { display_id: "progress" } |
| 15325 | * }); |
| 15326 | * |
| 15327 | * await new Promise((resolve) => setTimeout(resolve, 500)); |
| 15328 | * |
| 15329 | * await Deno.jupyter.broadcast("update_display_data", { |
| 15330 | * data: { "text/html": "<b>Processing..</b>" }, |
| 15331 | * metadata: {}, |
| 15332 | * transient: { display_id: "progress" } |
| 15333 | * }); |
| 15334 | * ``` |
| 15335 | * |
| 15336 | * @category Jupyter |
| 15337 | * @experimental |
| 15338 | */ |
| 15339 | export function broadcast( |
| 15340 | msgType: string, |
| 15341 | content: Record<string, unknown>, |
| 15342 | extra?: { |
| 15343 | metadata?: Record<string, unknown>; |
| 15344 | buffers?: Uint8Array[]; |
| 15345 | }, |
| 15346 | ): Promise<void>; |
| 15347 | } |
| 15348 | } |
| 15349 | |
| 15350 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15351 | * |
| 15352 | * The [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) |
| 15353 | * which also supports setting a {@linkcode Deno.HttpClient} which provides a |
| 15354 | * way to connect via proxies and use custom TLS certificates. |
| 15355 | * |
| 15356 | * @tags allow-net, allow-read |
| 15357 | * @category Fetch |
| 15358 | * @experimental |
| 15359 | */ |
| 15360 | declare function fetch( |
| 15361 | input: Request | URL | string, |
| 15362 | init?: RequestInit & { client: Deno.HttpClient }, |
| 15363 | ): Promise<Response>; |
| 15364 | |
| 15365 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15366 | * |
| 15367 | * @category Workers |
| 15368 | * @experimental |
| 15369 | */ |
| 15370 | declare interface WorkerOptions { |
| 15371 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15372 | * |
| 15373 | * Configure permissions options to change the level of access the worker will |
| 15374 | * have. By default it will have no permissions. Note that the permissions |
| 15375 | * of a worker can't be extended beyond its parent's permissions reach. |
| 15376 | * |
| 15377 | * - `"inherit"` will take the permissions of the thread the worker is created |
| 15378 | * in. |
| 15379 | * - `"none"` will use the default behavior and have no permission |
| 15380 | * - A list of routes can be provided that are relative to the file the worker |
| 15381 | * is created in to limit the access of the worker (read/write permissions |
| 15382 | * only) |
| 15383 | * |
| 15384 | * Example: |
| 15385 | * |
| 15386 | * ```ts |
| 15387 | * // mod.ts |
| 15388 | * const worker = new Worker( |
| 15389 | * new URL("deno_worker.ts", import.meta.url).href, { |
| 15390 | * type: "module", |
| 15391 | * deno: { |
| 15392 | * permissions: { |
| 15393 | * read: true, |
| 15394 | * }, |
| 15395 | * }, |
| 15396 | * } |
| 15397 | * ); |
| 15398 | * ``` |
| 15399 | */ |
| 15400 | deno?: { |
| 15401 | /** Set to `"none"` to disable all the permissions in the worker. */ |
| 15402 | permissions?: Deno.PermissionOptions; |
| 15403 | }; |
| 15404 | } |
| 15405 | |
| 15406 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15407 | * |
| 15408 | * @category WebSockets |
| 15409 | * @experimental |
| 15410 | */ |
| 15411 | declare interface WebSocketStreamOptions { |
| 15412 | protocols?: string[]; |
| 15413 | signal?: AbortSignal; |
| 15414 | headers?: HeadersInit; |
| 15415 | } |
| 15416 | |
| 15417 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15418 | * |
| 15419 | * @category WebSockets |
| 15420 | * @experimental |
| 15421 | */ |
| 15422 | declare interface WebSocketConnection { |
| 15423 | readable: ReadableStream<string | Uint8Array>; |
| 15424 | writable: WritableStream<string | Uint8Array>; |
| 15425 | extensions: string; |
| 15426 | protocol: string; |
| 15427 | } |
| 15428 | |
| 15429 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15430 | * |
| 15431 | * @category WebSockets |
| 15432 | * @experimental |
| 15433 | */ |
| 15434 | declare interface WebSocketCloseInfo { |
| 15435 | code?: number; |
| 15436 | reason?: string; |
| 15437 | } |
| 15438 | |
| 15439 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15440 | * |
| 15441 | * @tags allow-net |
| 15442 | * @category WebSockets |
| 15443 | * @experimental |
| 15444 | */ |
| 15445 | declare interface WebSocketStream { |
| 15446 | url: string; |
| 15447 | opened: Promise<WebSocketConnection>; |
| 15448 | closed: Promise<WebSocketCloseInfo>; |
| 15449 | close(closeInfo?: WebSocketCloseInfo): void; |
| 15450 | } |
| 15451 | |
| 15452 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15453 | * |
| 15454 | * @tags allow-net |
| 15455 | * @category WebSockets |
| 15456 | * @experimental |
| 15457 | */ |
| 15458 | declare var WebSocketStream: { |
| 15459 | readonly prototype: WebSocketStream; |
| 15460 | new (url: string, options?: WebSocketStreamOptions): WebSocketStream; |
| 15461 | }; |
| 15462 | |
| 15463 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15464 | * |
| 15465 | * @tags allow-net |
| 15466 | * @category WebSockets |
| 15467 | * @experimental |
| 15468 | */ |
| 15469 | declare interface WebSocketError extends DOMException { |
| 15470 | readonly closeCode: number; |
| 15471 | readonly reason: string; |
| 15472 | } |
| 15473 | |
| 15474 | /** **UNSTABLE**: New API, yet to be vetted. |
| 15475 | * |
| 15476 | * @tags allow-net |
| 15477 | * @category WebSockets |
| 15478 | * @experimental |
| 15479 | */ |
| 15480 | declare var WebSocketError: { |
| 15481 | readonly prototype: WebSocketError; |
| 15482 | new (message?: string, init?: WebSocketCloseInfo): WebSocketError; |
| 15483 | }; |
| 15484 | |
| 15485 | // Adapted from `tc39/proposal-temporal`: https://github.com/tc39/proposal-temporal/blob/main/polyfill/index.d.ts |
| 15486 | |
| 15487 | /** |
| 15488 | * [Specification](https://tc39.es/proposal-temporal/docs/index.html) |
| 15489 | * |
| 15490 | * @category Temporal |
| 15491 | * @experimental |
| 15492 | */ |
| 15493 | declare namespace Temporal { |
| 15494 | /** |
| 15495 | * @category Temporal |
| 15496 | * @experimental |
| 15497 | */ |
| 15498 | export type ComparisonResult = -1 | 0 | 1; |
| 15499 | /** |
| 15500 | * @category Temporal |
| 15501 | * @experimental |
| 15502 | */ |
| 15503 | export type RoundingMode = |
| 15504 | | "ceil" |
| 15505 | | "floor" |
| 15506 | | "expand" |
| 15507 | | "trunc" |
| 15508 | | "halfCeil" |
| 15509 | | "halfFloor" |
| 15510 | | "halfExpand" |
| 15511 | | "halfTrunc" |
| 15512 | | "halfEven"; |
| 15513 | |
| 15514 | /** |
| 15515 | * Options for assigning fields using `with()` or entire objects with |
| 15516 | * `from()`. |
| 15517 | * |
| 15518 | * @category Temporal |
| 15519 | * @experimental |
| 15520 | */ |
| 15521 | export type AssignmentOptions = { |
| 15522 | /** |
| 15523 | * How to deal with out-of-range values |
| 15524 | * |
| 15525 | * - In `'constrain'` mode, out-of-range values are clamped to the nearest |
| 15526 | * in-range value. |
| 15527 | * - In `'reject'` mode, out-of-range values will cause the function to |
| 15528 | * throw a RangeError. |
| 15529 | * |
| 15530 | * The default is `'constrain'`. |
| 15531 | */ |
| 15532 | overflow?: "constrain" | "reject"; |
| 15533 | }; |
| 15534 | |
| 15535 | /** |
| 15536 | * Options for assigning fields using `Duration.prototype.with()` or entire |
| 15537 | * objects with `Duration.from()`, and for arithmetic with |
| 15538 | * `Duration.prototype.add()` and `Duration.prototype.subtract()`. |
| 15539 | * |
| 15540 | * @category Temporal |
| 15541 | * @experimental |
| 15542 | */ |
| 15543 | export type DurationOptions = { |
| 15544 | /** |
| 15545 | * How to deal with out-of-range values |
| 15546 | * |
| 15547 | * - In `'constrain'` mode, out-of-range values are clamped to the nearest |
| 15548 | * in-range value. |
| 15549 | * - In `'balance'` mode, out-of-range values are resolved by balancing them |
| 15550 | * with the next highest unit. |
| 15551 | * |
| 15552 | * The default is `'constrain'`. |
| 15553 | */ |
| 15554 | overflow?: "constrain" | "balance"; |
| 15555 | }; |
| 15556 | |
| 15557 | /** |
| 15558 | * Options for conversions of `Temporal.PlainDateTime` to `Temporal.Instant` |
| 15559 | * |
| 15560 | * @category Temporal |
| 15561 | * @experimental |
| 15562 | */ |
| 15563 | export type ToInstantOptions = { |
| 15564 | /** |
| 15565 | * Controls handling of invalid or ambiguous times caused by time zone |
| 15566 | * offset changes like Daylight Saving time (DST) transitions. |
| 15567 | * |
| 15568 | * This option is only relevant if a `DateTime` value does not exist in the |
| 15569 | * destination time zone (e.g. near "Spring Forward" DST transitions), or |
| 15570 | * exists more than once (e.g. near "Fall Back" DST transitions). |
| 15571 | * |
| 15572 | * In case of ambiguous or nonexistent times, this option controls what |
| 15573 | * exact time to return: |
| 15574 | * - `'compatible'`: Equivalent to `'earlier'` for backward transitions like |
| 15575 | * the start of DST in the Spring, and `'later'` for forward transitions |
| 15576 | * like the end of DST in the Fall. This matches the behavior of legacy |
| 15577 | * `Date`, of libraries like moment.js, Luxon, or date-fns, and of |
| 15578 | * cross-platform standards like [RFC 5545 |
| 15579 | * (iCalendar)](https://tools.ietf.org/html/rfc5545). |
| 15580 | * - `'earlier'`: The earlier time of two possible times |
| 15581 | * - `'later'`: The later of two possible times |
| 15582 | * - `'reject'`: Throw a RangeError instead |
| 15583 | * |
| 15584 | * The default is `'compatible'`. |
| 15585 | */ |
| 15586 | disambiguation?: "compatible" | "earlier" | "later" | "reject"; |
| 15587 | }; |
| 15588 | |
| 15589 | /** |
| 15590 | * @category Temporal |
| 15591 | * @experimental |
| 15592 | */ |
| 15593 | export type OffsetDisambiguationOptions = { |
| 15594 | /** |
| 15595 | * Time zone definitions can change. If an application stores data about |
| 15596 | * events in the future, then stored data about future events may become |
| 15597 | * ambiguous, for example if a country permanently abolishes DST. The |
| 15598 | * `offset` option controls this unusual case. |
| 15599 | * |
| 15600 | * - `'use'` always uses the offset (if it's provided) to calculate the |
| 15601 | * instant. This ensures that the result will match the instant that was |
| 15602 | * originally stored, even if local clock time is different. |
| 15603 | * - `'prefer'` uses the offset if it's valid for the date/time in this time |
| 15604 | * zone, but if it's not valid then the time zone will be used as a |
| 15605 | * fallback to calculate the instant. |
| 15606 | * - `'ignore'` will disregard any provided offset. Instead, the time zone |
| 15607 | * and date/time value are used to calculate the instant. This will keep |
| 15608 | * local clock time unchanged but may result in a different real-world |
| 15609 | * instant. |
| 15610 | * - `'reject'` acts like `'prefer'`, except it will throw a RangeError if |
| 15611 | * the offset is not valid for the given time zone identifier and |
| 15612 | * date/time value. |
| 15613 | * |
| 15614 | * If the ISO string ends in 'Z' then this option is ignored because there |
| 15615 | * is no possibility of ambiguity. |
| 15616 | * |
| 15617 | * If a time zone offset is not present in the input, then this option is |
| 15618 | * ignored because the time zone will always be used to calculate the |
| 15619 | * offset. |
| 15620 | * |
| 15621 | * If the offset is not used, and if the date/time and time zone don't |
| 15622 | * uniquely identify a single instant, then the `disambiguation` option will |
| 15623 | * be used to choose the correct instant. However, if the offset is used |
| 15624 | * then the `disambiguation` option will be ignored. |
| 15625 | */ |
| 15626 | offset?: "use" | "prefer" | "ignore" | "reject"; |
| 15627 | }; |
| 15628 | |
| 15629 | /** |
| 15630 | * @category Temporal |
| 15631 | * @experimental |
| 15632 | */ |
| 15633 | export type ZonedDateTimeAssignmentOptions = Partial< |
| 15634 | AssignmentOptions & ToInstantOptions & OffsetDisambiguationOptions |
| 15635 | >; |
| 15636 | |
| 15637 | /** |
| 15638 | * Options for arithmetic operations like `add()` and `subtract()` |
| 15639 | * |
| 15640 | * @category Temporal |
| 15641 | * @experimental |
| 15642 | */ |
| 15643 | export type ArithmeticOptions = { |
| 15644 | /** |
| 15645 | * Controls handling of out-of-range arithmetic results. |
| 15646 | * |
| 15647 | * If a result is out of range, then `'constrain'` will clamp the result to |
| 15648 | * the allowed range, while `'reject'` will throw a RangeError. |
| 15649 | * |
| 15650 | * The default is `'constrain'`. |
| 15651 | */ |
| 15652 | overflow?: "constrain" | "reject"; |
| 15653 | }; |
| 15654 | |
| 15655 | /** |
| 15656 | * @category Temporal |
| 15657 | * @experimental |
| 15658 | */ |
| 15659 | export type DateUnit = "year" | "month" | "week" | "day"; |
| 15660 | /** |
| 15661 | * @category Temporal |
| 15662 | * @experimental |
| 15663 | */ |
| 15664 | export type TimeUnit = |
| 15665 | | "hour" |
| 15666 | | "minute" |
| 15667 | | "second" |
| 15668 | | "millisecond" |
| 15669 | | "microsecond" |
| 15670 | | "nanosecond"; |
| 15671 | /** |
| 15672 | * @category Temporal |
| 15673 | * @experimental |
| 15674 | */ |
| 15675 | export type DateTimeUnit = DateUnit | TimeUnit; |
| 15676 | |
| 15677 | /** |
| 15678 | * When the name of a unit is provided to a Temporal API as a string, it is |
| 15679 | * usually singular, e.g. 'day' or 'hour'. But plural unit names like 'days' |
| 15680 | * or 'hours' are aso accepted too. |
| 15681 | * |
| 15682 | * @category Temporal |
| 15683 | * @experimental |
| 15684 | */ |
| 15685 | export type PluralUnit<T extends DateTimeUnit> = { |
| 15686 | year: "years"; |
| 15687 | month: "months"; |
| 15688 | week: "weeks"; |
| 15689 | day: "days"; |
| 15690 | hour: "hours"; |
| 15691 | minute: "minutes"; |
| 15692 | second: "seconds"; |
| 15693 | millisecond: "milliseconds"; |
| 15694 | microsecond: "microseconds"; |
| 15695 | nanosecond: "nanoseconds"; |
| 15696 | }[T]; |
| 15697 | |
| 15698 | /** |
| 15699 | * @category Temporal |
| 15700 | * @experimental |
| 15701 | */ |
| 15702 | export type LargestUnit<T extends DateTimeUnit> = "auto" | T | PluralUnit<T>; |
| 15703 | /** |
| 15704 | * @category Temporal |
| 15705 | * @experimental |
| 15706 | */ |
| 15707 | export type SmallestUnit<T extends DateTimeUnit> = T | PluralUnit<T>; |
| 15708 | /** |
| 15709 | * @category Temporal |
| 15710 | * @experimental |
| 15711 | */ |
| 15712 | export type TotalUnit<T extends DateTimeUnit> = T | PluralUnit<T>; |
| 15713 | |
| 15714 | /** |
| 15715 | * Options for outputting precision in toString() on types with seconds |
| 15716 | * |
| 15717 | * @category Temporal |
| 15718 | * @experimental |
| 15719 | */ |
| 15720 | export type ToStringPrecisionOptions = { |
| 15721 | fractionalSecondDigits?: "auto" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; |
| 15722 | smallestUnit?: SmallestUnit< |
| 15723 | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond" |
| 15724 | >; |
| 15725 | |
| 15726 | /** |
| 15727 | * Controls how rounding is performed: |
| 15728 | * - `halfExpand`: Round to the nearest of the values allowed by |
| 15729 | * `roundingIncrement` and `smallestUnit`. When there is a tie, round up. |
| 15730 | * This mode is the default. |
| 15731 | * - `ceil`: Always round up, towards the end of time. |
| 15732 | * - `trunc`: Always round down, towards the beginning of time. |
| 15733 | * - `floor`: Also round down, towards the beginning of time. This mode acts |
| 15734 | * the same as `trunc`, but it's included for consistency with |
| 15735 | * `Temporal.Duration.round()` where negative values are allowed and |
| 15736 | * `trunc` rounds towards zero, unlike `floor` which rounds towards |
| 15737 | * negative infinity which is usually unexpected. For this reason, `trunc` |
| 15738 | * is recommended for most use cases. |
| 15739 | */ |
| 15740 | roundingMode?: RoundingMode; |
| 15741 | }; |
| 15742 | |
| 15743 | /** |
| 15744 | * @category Temporal |
| 15745 | * @experimental |
| 15746 | */ |
| 15747 | export type ShowCalendarOption = { |
| 15748 | calendarName?: "auto" | "always" | "never" | "critical"; |
| 15749 | }; |
| 15750 | |
| 15751 | /** |
| 15752 | * @category Temporal |
| 15753 | * @experimental |
| 15754 | */ |
| 15755 | export type CalendarTypeToStringOptions = Partial< |
| 15756 | ToStringPrecisionOptions & ShowCalendarOption |
| 15757 | >; |
| 15758 | |
| 15759 | /** |
| 15760 | * @category Temporal |
| 15761 | * @experimental |
| 15762 | */ |
| 15763 | export type ZonedDateTimeToStringOptions = Partial< |
| 15764 | CalendarTypeToStringOptions & { |
| 15765 | timeZoneName?: "auto" | "never" | "critical"; |
| 15766 | offset?: "auto" | "never"; |
| 15767 | } |
| 15768 | >; |
| 15769 | |
| 15770 | /** |
| 15771 | * @category Temporal |
| 15772 | * @experimental |
| 15773 | */ |
| 15774 | export type InstantToStringOptions = Partial< |
| 15775 | ToStringPrecisionOptions & { |
| 15776 | timeZone: TimeZoneLike; |
| 15777 | } |
| 15778 | >; |
| 15779 | |
| 15780 | /** |
| 15781 | * Options to control the result of `until()` and `since()` methods in |
| 15782 | * `Temporal` types. |
| 15783 | * |
| 15784 | * @category Temporal |
| 15785 | * @experimental |
| 15786 | */ |
| 15787 | export interface DifferenceOptions<T extends DateTimeUnit> { |
| 15788 | /** |
| 15789 | * The unit to round to. For example, to round to the nearest minute, use |
| 15790 | * `smallestUnit: 'minute'`. This property is optional for `until()` and |
| 15791 | * `since()`, because those methods default behavior is not to round. |
| 15792 | * However, the same property is required for `round()`. |
| 15793 | */ |
| 15794 | smallestUnit?: SmallestUnit<T>; |
| 15795 | |
| 15796 | /** |
| 15797 | * The largest unit to allow in the resulting `Temporal.Duration` object. |
| 15798 | * |
| 15799 | * Larger units will be "balanced" into smaller units. For example, if |
| 15800 | * `largestUnit` is `'minute'` then a two-hour duration will be output as a |
| 15801 | * 120-minute duration. |
| 15802 | * |
| 15803 | * Valid values may include `'year'`, `'month'`, `'week'`, `'day'`, |
| 15804 | * `'hour'`, `'minute'`, `'second'`, `'millisecond'`, `'microsecond'`, |
| 15805 | * `'nanosecond'` and `'auto'`, although some types may throw an exception |
| 15806 | * if a value is used that would produce an invalid result. For example, |
| 15807 | * `hours` is not accepted by `Temporal.PlainDate.prototype.since()`. |
| 15808 | * |
| 15809 | * The default is always `'auto'`, though the meaning of this depends on the |
| 15810 | * type being used. |
| 15811 | */ |
| 15812 | largestUnit?: LargestUnit<T>; |
| 15813 | |
| 15814 | /** |
| 15815 | * Allows rounding to an integer number of units. For example, to round to |
| 15816 | * increments of a half hour, use `{ smallestUnit: 'minute', |
| 15817 | * roundingIncrement: 30 }`. |
| 15818 | */ |
| 15819 | roundingIncrement?: number; |
| 15820 | |
| 15821 | /** |
| 15822 | * Controls how rounding is performed: |
| 15823 | * - `halfExpand`: Round to the nearest of the values allowed by |
| 15824 | * `roundingIncrement` and `smallestUnit`. When there is a tie, round away |
| 15825 | * from zero like `ceil` for positive durations and like `floor` for |
| 15826 | * negative durations. |
| 15827 | * - `ceil`: Always round up, towards the end of time. |
| 15828 | * - `trunc`: Always round down, towards the beginning of time. This mode is |
| 15829 | * the default. |
| 15830 | * - `floor`: Also round down, towards the beginning of time. This mode acts |
| 15831 | * the same as `trunc`, but it's included for consistency with |
| 15832 | * `Temporal.Duration.round()` where negative values are allowed and |
| 15833 | * `trunc` rounds towards zero, unlike `floor` which rounds towards |
| 15834 | * negative infinity which is usually unexpected. For this reason, `trunc` |
| 15835 | * is recommended for most use cases. |
| 15836 | */ |
| 15837 | roundingMode?: RoundingMode; |
| 15838 | } |
| 15839 | |
| 15840 | /** |
| 15841 | * `round` methods take one required parameter. If a string is provided, the |
| 15842 | * resulting `Temporal.Duration` object will be rounded to that unit. If an |
| 15843 | * object is provided, its `smallestUnit` property is required while other |
| 15844 | * properties are optional. A string is treated the same as an object whose |
| 15845 | * `smallestUnit` property value is that string. |
| 15846 | * |
| 15847 | * @category Temporal |
| 15848 | * @experimental |
| 15849 | */ |
| 15850 | export type RoundTo<T extends DateTimeUnit> = |
| 15851 | | SmallestUnit<T> |
| 15852 | | { |
| 15853 | /** |
| 15854 | * The unit to round to. For example, to round to the nearest minute, |
| 15855 | * use `smallestUnit: 'minute'`. This option is required. Note that the |
| 15856 | * same-named property is optional when passed to `until` or `since` |
| 15857 | * methods, because those methods do no rounding by default. |
| 15858 | */ |
| 15859 | smallestUnit: SmallestUnit<T>; |
| 15860 | |
| 15861 | /** |
| 15862 | * Allows rounding to an integer number of units. For example, to round to |
| 15863 | * increments of a half hour, use `{ smallestUnit: 'minute', |
| 15864 | * roundingIncrement: 30 }`. |
| 15865 | */ |
| 15866 | roundingIncrement?: number; |
| 15867 | |
| 15868 | /** |
| 15869 | * Controls how rounding is performed: |
| 15870 | * - `halfExpand`: Round to the nearest of the values allowed by |
| 15871 | * `roundingIncrement` and `smallestUnit`. When there is a tie, round up. |
| 15872 | * This mode is the default. |
| 15873 | * - `ceil`: Always round up, towards the end of time. |
| 15874 | * - `trunc`: Always round down, towards the beginning of time. |
| 15875 | * - `floor`: Also round down, towards the beginning of time. This mode acts |
| 15876 | * the same as `trunc`, but it's included for consistency with |
| 15877 | * `Temporal.Duration.round()` where negative values are allowed and |
| 15878 | * `trunc` rounds towards zero, unlike `floor` which rounds towards |
| 15879 | * negative infinity which is usually unexpected. For this reason, `trunc` |
| 15880 | * is recommended for most use cases. |
| 15881 | */ |
| 15882 | roundingMode?: RoundingMode; |
| 15883 | }; |
| 15884 | |
| 15885 | /** |
| 15886 | * The `round` method of the `Temporal.Duration` accepts one required |
| 15887 | * parameter. If a string is provided, the resulting `Temporal.Duration` |
| 15888 | * object will be rounded to that unit. If an object is provided, the |
| 15889 | * `smallestUnit` and/or `largestUnit` property is required, while other |
| 15890 | * properties are optional. A string parameter is treated the same as an |
| 15891 | * object whose `smallestUnit` property value is that string. |
| 15892 | * |
| 15893 | * @category Temporal |
| 15894 | * @experimental |
| 15895 | */ |
| 15896 | export type DurationRoundTo = |
| 15897 | | SmallestUnit<DateTimeUnit> |
| 15898 | | ( |
| 15899 | & ( |
| 15900 | | { |
| 15901 | /** |
| 15902 | * The unit to round to. For example, to round to the nearest |
| 15903 | * minute, use `smallestUnit: 'minute'`. This property is normally |
| 15904 | * required, but is optional if `largestUnit` is provided and not |
| 15905 | * undefined. |
| 15906 | */ |
| 15907 | smallestUnit: SmallestUnit<DateTimeUnit>; |
| 15908 | |
| 15909 | /** |
| 15910 | * The largest unit to allow in the resulting `Temporal.Duration` |
| 15911 | * object. |
| 15912 | * |
| 15913 | * Larger units will be "balanced" into smaller units. For example, |
| 15914 | * if `largestUnit` is `'minute'` then a two-hour duration will be |
| 15915 | * output as a 120-minute duration. |
| 15916 | * |
| 15917 | * Valid values include `'year'`, `'month'`, `'week'`, `'day'`, |
| 15918 | * `'hour'`, `'minute'`, `'second'`, `'millisecond'`, |
| 15919 | * `'microsecond'`, `'nanosecond'` and `'auto'`. |
| 15920 | * |
| 15921 | * The default is `'auto'`, which means "the largest nonzero unit in |
| 15922 | * the input duration". This default prevents expanding durations to |
| 15923 | * larger units unless the caller opts into this behavior. |
| 15924 | * |
| 15925 | * If `smallestUnit` is larger, then `smallestUnit` will be used as |
| 15926 | * `largestUnit`, superseding a caller-supplied or default value. |
| 15927 | */ |
| 15928 | largestUnit?: LargestUnit<DateTimeUnit>; |
| 15929 | } |
| 15930 | | { |
| 15931 | /** |
| 15932 | * The unit to round to. For example, to round to the nearest |
| 15933 | * minute, use `smallestUnit: 'minute'`. This property is normally |
| 15934 | * required, but is optional if `largestUnit` is provided and not |
| 15935 | * undefined. |
| 15936 | */ |
| 15937 | smallestUnit?: SmallestUnit<DateTimeUnit>; |
| 15938 | |
| 15939 | /** |
| 15940 | * The largest unit to allow in the resulting `Temporal.Duration` |
| 15941 | * object. |
| 15942 | * |
| 15943 | * Larger units will be "balanced" into smaller units. For example, |
| 15944 | * if `largestUnit` is `'minute'` then a two-hour duration will be |
| 15945 | * output as a 120-minute duration. |
| 15946 | * |
| 15947 | * Valid values include `'year'`, `'month'`, `'week'`, `'day'`, |
| 15948 | * `'hour'`, `'minute'`, `'second'`, `'millisecond'`, |
| 15949 | * `'microsecond'`, `'nanosecond'` and `'auto'`. |
| 15950 | * |
| 15951 | * The default is `'auto'`, which means "the largest nonzero unit in |
| 15952 | * the input duration". This default prevents expanding durations to |
| 15953 | * larger units unless the caller opts into this behavior. |
| 15954 | * |
| 15955 | * If `smallestUnit` is larger, then `smallestUnit` will be used as |
| 15956 | * `largestUnit`, superseding a caller-supplied or default value. |
| 15957 | */ |
| 15958 | largestUnit: LargestUnit<DateTimeUnit>; |
| 15959 | } |
| 15960 | ) |
| 15961 | & { |
| 15962 | /** |
| 15963 | * Allows rounding to an integer number of units. For example, to round |
| 15964 | * to increments of a half hour, use `{ smallestUnit: 'minute', |
| 15965 | * roundingIncrement: 30 }`. |
| 15966 | */ |
| 15967 | roundingIncrement?: number; |
| 15968 | |
| 15969 | /** |
| 15970 | * Controls how rounding is performed: |
| 15971 | * - `halfExpand`: Round to the nearest of the values allowed by |
| 15972 | * `roundingIncrement` and `smallestUnit`. When there is a tie, round |
| 15973 | * away from zero like `ceil` for positive durations and like `floor` |
| 15974 | * for negative durations. This mode is the default. |
| 15975 | * - `ceil`: Always round towards positive infinity. For negative |
| 15976 | * durations this option will decrease the absolute value of the |
| 15977 | * duration which may be unexpected. To round away from zero, use |
| 15978 | * `ceil` for positive durations and `floor` for negative durations. |
| 15979 | * - `trunc`: Always round down towards zero. |
| 15980 | * - `floor`: Always round towards negative infinity. This mode acts the |
| 15981 | * same as `trunc` for positive durations but for negative durations |
| 15982 | * it will increase the absolute value of the result which may be |
| 15983 | * unexpected. For this reason, `trunc` is recommended for most "round |
| 15984 | * down" use cases. |
| 15985 | */ |
| 15986 | roundingMode?: RoundingMode; |
| 15987 | |
| 15988 | /** |
| 15989 | * The starting point to use for rounding and conversions when |
| 15990 | * variable-length units (years, months, weeks depending on the |
| 15991 | * calendar) are involved. This option is required if any of the |
| 15992 | * following are true: |
| 15993 | * - `unit` is `'week'` or larger units |
| 15994 | * - `this` has a nonzero value for `weeks` or larger units |
| 15995 | * |
| 15996 | * This value must be either a `Temporal.PlainDateTime`, a |
| 15997 | * `Temporal.ZonedDateTime`, or a string or object value that can be |
| 15998 | * passed to `from()` of those types. Examples: |
| 15999 | * - `'2020-01'01T00:00-08:00[America/Los_Angeles]'` |
| 16000 | * - `'2020-01'01'` |
| 16001 | * - `Temporal.PlainDate.from('2020-01-01')` |
| 16002 | * |
| 16003 | * `Temporal.ZonedDateTime` will be tried first because it's more |
| 16004 | * specific, with `Temporal.PlainDateTime` as a fallback. |
| 16005 | * |
| 16006 | * If the value resolves to a `Temporal.ZonedDateTime`, then operation |
| 16007 | * will adjust for DST and other time zone transitions. Otherwise |
| 16008 | * (including if this option is omitted), then the operation will ignore |
| 16009 | * time zone transitions and all days will be assumed to be 24 hours |
| 16010 | * long. |
| 16011 | */ |
| 16012 | relativeTo?: |
| 16013 | | Temporal.PlainDateTime |
| 16014 | | Temporal.ZonedDateTime |
| 16015 | | PlainDateTimeLike |
| 16016 | | ZonedDateTimeLike |
| 16017 | | string; |
| 16018 | } |
| 16019 | ); |
| 16020 | |
| 16021 | /** |
| 16022 | * Options to control behavior of `Duration.prototype.total()` |
| 16023 | * |
| 16024 | * @category Temporal |
| 16025 | * @experimental |
| 16026 | */ |
| 16027 | export type DurationTotalOf = |
| 16028 | | TotalUnit<DateTimeUnit> |
| 16029 | | { |
| 16030 | /** |
| 16031 | * The unit to convert the duration to. This option is required. |
| 16032 | */ |
| 16033 | unit: TotalUnit<DateTimeUnit>; |
| 16034 | |
| 16035 | /** |
| 16036 | * The starting point to use when variable-length units (years, months, |
| 16037 | * weeks depending on the calendar) are involved. This option is required if |
| 16038 | * any of the following are true: |
| 16039 | * - `unit` is `'week'` or larger units |
| 16040 | * - `this` has a nonzero value for `weeks` or larger units |
| 16041 | * |
| 16042 | * This value must be either a `Temporal.PlainDateTime`, a |
| 16043 | * `Temporal.ZonedDateTime`, or a string or object value that can be passed |
| 16044 | * to `from()` of those types. Examples: |
| 16045 | * - `'2020-01'01T00:00-08:00[America/Los_Angeles]'` |
| 16046 | * - `'2020-01'01'` |
| 16047 | * - `Temporal.PlainDate.from('2020-01-01')` |
| 16048 | * |
| 16049 | * `Temporal.ZonedDateTime` will be tried first because it's more |
| 16050 | * specific, with `Temporal.PlainDateTime` as a fallback. |
| 16051 | * |
| 16052 | * If the value resolves to a `Temporal.ZonedDateTime`, then operation will |
| 16053 | * adjust for DST and other time zone transitions. Otherwise (including if |
| 16054 | * this option is omitted), then the operation will ignore time zone |
| 16055 | * transitions and all days will be assumed to be 24 hours long. |
| 16056 | */ |
| 16057 | relativeTo?: |
| 16058 | | Temporal.ZonedDateTime |
| 16059 | | Temporal.PlainDateTime |
| 16060 | | ZonedDateTimeLike |
| 16061 | | PlainDateTimeLike |
| 16062 | | string; |
| 16063 | }; |
| 16064 | |
| 16065 | /** |
| 16066 | * Options to control behavior of `Duration.compare()`, `Duration.add()`, and |
| 16067 | * `Duration.subtract()` |
| 16068 | * |
| 16069 | * @category Temporal |
| 16070 | * @experimental |
| 16071 | */ |
| 16072 | export interface DurationArithmeticOptions { |
| 16073 | /** |
| 16074 | * The starting point to use when variable-length units (years, months, |
| 16075 | * weeks depending on the calendar) are involved. This option is required if |
| 16076 | * either of the durations has a nonzero value for `weeks` or larger units. |
| 16077 | * |
| 16078 | * This value must be either a `Temporal.PlainDateTime`, a |
| 16079 | * `Temporal.ZonedDateTime`, or a string or object value that can be passed |
| 16080 | * to `from()` of those types. Examples: |
| 16081 | * - `'2020-01'01T00:00-08:00[America/Los_Angeles]'` |
| 16082 | * - `'2020-01'01'` |
| 16083 | * - `Temporal.PlainDate.from('2020-01-01')` |
| 16084 | * |
| 16085 | * `Temporal.ZonedDateTime` will be tried first because it's more |
| 16086 | * specific, with `Temporal.PlainDateTime` as a fallback. |
| 16087 | * |
| 16088 | * If the value resolves to a `Temporal.ZonedDateTime`, then operation will |
| 16089 | * adjust for DST and other time zone transitions. Otherwise (including if |
| 16090 | * this option is omitted), then the operation will ignore time zone |
| 16091 | * transitions and all days will be assumed to be 24 hours long. |
| 16092 | */ |
| 16093 | relativeTo?: |
| 16094 | | Temporal.ZonedDateTime |
| 16095 | | Temporal.PlainDateTime |
| 16096 | | ZonedDateTimeLike |
| 16097 | | PlainDateTimeLike |
| 16098 | | string; |
| 16099 | } |
| 16100 | |
| 16101 | /** |
| 16102 | * @category Temporal |
| 16103 | * @experimental |
| 16104 | */ |
| 16105 | export type DurationLike = { |
| 16106 | years?: number; |
| 16107 | months?: number; |
| 16108 | weeks?: number; |
| 16109 | days?: number; |
| 16110 | hours?: number; |
| 16111 | minutes?: number; |
| 16112 | seconds?: number; |
| 16113 | milliseconds?: number; |
| 16114 | microseconds?: number; |
| 16115 | nanoseconds?: number; |
| 16116 | }; |
| 16117 | |
| 16118 | /** |
| 16119 | * A `Temporal.Duration` represents an immutable duration of time which can be |
| 16120 | * used in date/time arithmetic. |
| 16121 | * |
| 16122 | * See https://tc39.es/proposal-temporal/docs/duration.html for more details. |
| 16123 | * |
| 16124 | * @category Temporal |
| 16125 | * @experimental |
| 16126 | */ |
| 16127 | export class Duration { |
| 16128 | static from( |
| 16129 | item: Temporal.Duration | DurationLike | string, |
| 16130 | ): Temporal.Duration; |
| 16131 | static compare( |
| 16132 | one: Temporal.Duration | DurationLike | string, |
| 16133 | two: Temporal.Duration | DurationLike | string, |
| 16134 | options?: DurationArithmeticOptions, |
| 16135 | ): ComparisonResult; |
| 16136 | constructor( |
| 16137 | years?: number, |
| 16138 | months?: number, |
| 16139 | weeks?: number, |
| 16140 | days?: number, |
| 16141 | hours?: number, |
| 16142 | minutes?: number, |
| 16143 | seconds?: number, |
| 16144 | milliseconds?: number, |
| 16145 | microseconds?: number, |
| 16146 | nanoseconds?: number, |
| 16147 | ); |
| 16148 | readonly sign: -1 | 0 | 1; |
| 16149 | readonly blank: boolean; |
| 16150 | readonly years: number; |
| 16151 | readonly months: number; |
| 16152 | readonly weeks: number; |
| 16153 | readonly days: number; |
| 16154 | readonly hours: number; |
| 16155 | readonly minutes: number; |
| 16156 | readonly seconds: number; |
| 16157 | readonly milliseconds: number; |
| 16158 | readonly microseconds: number; |
| 16159 | readonly nanoseconds: number; |
| 16160 | negated(): Temporal.Duration; |
| 16161 | abs(): Temporal.Duration; |
| 16162 | with(durationLike: DurationLike): Temporal.Duration; |
| 16163 | add( |
| 16164 | other: Temporal.Duration | DurationLike | string, |
| 16165 | options?: DurationArithmeticOptions, |
| 16166 | ): Temporal.Duration; |
| 16167 | subtract( |
| 16168 | other: Temporal.Duration | DurationLike | string, |
| 16169 | options?: DurationArithmeticOptions, |
| 16170 | ): Temporal.Duration; |
| 16171 | round(roundTo: DurationRoundTo): Temporal.Duration; |
| 16172 | total(totalOf: DurationTotalOf): number; |
| 16173 | toLocaleString( |
| 16174 | locales?: string | string[], |
| 16175 | options?: Intl.DateTimeFormatOptions, |
| 16176 | ): string; |
| 16177 | toJSON(): string; |
| 16178 | toString(options?: ToStringPrecisionOptions): string; |
| 16179 | valueOf(): never; |
| 16180 | readonly [Symbol.toStringTag]: "Temporal.Duration"; |
| 16181 | } |
| 16182 | |
| 16183 | /** |
| 16184 | * A `Temporal.Instant` is an exact point in time, with a precision in |
| 16185 | * nanoseconds. No time zone or calendar information is present. Therefore, |
| 16186 | * `Temporal.Instant` has no concept of days, months, or even hours. |
| 16187 | * |
| 16188 | * For convenience of interoperability, it internally uses nanoseconds since |
| 16189 | * the {@link https://en.wikipedia.org/wiki/Unix_time|Unix epoch} (midnight |
| 16190 | * UTC on January 1, 1970). However, a `Temporal.Instant` can be created from |
| 16191 | * any of several expressions that refer to a single point in time, including |
| 16192 | * an {@link https://en.wikipedia.org/wiki/ISO_8601|ISO 8601 string} with a |
| 16193 | * time zone offset such as '2020-01-23T17:04:36.491865121-08:00'. |
| 16194 | * |
| 16195 | * See https://tc39.es/proposal-temporal/docs/instant.html for more details. |
| 16196 | * |
| 16197 | * @category Temporal |
| 16198 | * @experimental |
| 16199 | */ |
| 16200 | export class Instant { |
| 16201 | static fromEpochSeconds(epochSeconds: number): Temporal.Instant; |
| 16202 | static fromEpochMilliseconds(epochMilliseconds: number): Temporal.Instant; |
| 16203 | static fromEpochMicroseconds(epochMicroseconds: bigint): Temporal.Instant; |
| 16204 | static fromEpochNanoseconds(epochNanoseconds: bigint): Temporal.Instant; |
| 16205 | static from(item: Temporal.Instant | string): Temporal.Instant; |
| 16206 | static compare( |
| 16207 | one: Temporal.Instant | string, |
| 16208 | two: Temporal.Instant | string, |
| 16209 | ): ComparisonResult; |
| 16210 | constructor(epochNanoseconds: bigint); |
| 16211 | readonly epochSeconds: number; |
| 16212 | readonly epochMilliseconds: number; |
| 16213 | readonly epochMicroseconds: bigint; |
| 16214 | readonly epochNanoseconds: bigint; |
| 16215 | equals(other: Temporal.Instant | string): boolean; |
| 16216 | add( |
| 16217 | durationLike: |
| 16218 | | Omit< |
| 16219 | Temporal.Duration | DurationLike, |
| 16220 | "years" | "months" | "weeks" | "days" |
| 16221 | > |
| 16222 | | string, |
| 16223 | ): Temporal.Instant; |
| 16224 | subtract( |
| 16225 | durationLike: |
| 16226 | | Omit< |
| 16227 | Temporal.Duration | DurationLike, |
| 16228 | "years" | "months" | "weeks" | "days" |
| 16229 | > |
| 16230 | | string, |
| 16231 | ): Temporal.Instant; |
| 16232 | until( |
| 16233 | other: Temporal.Instant | string, |
| 16234 | options?: DifferenceOptions< |
| 16235 | | "hour" |
| 16236 | | "minute" |
| 16237 | | "second" |
| 16238 | | "millisecond" |
| 16239 | | "microsecond" |
| 16240 | | "nanosecond" |
| 16241 | >, |
| 16242 | ): Temporal.Duration; |
| 16243 | since( |
| 16244 | other: Temporal.Instant | string, |
| 16245 | options?: DifferenceOptions< |
| 16246 | | "hour" |
| 16247 | | "minute" |
| 16248 | | "second" |
| 16249 | | "millisecond" |
| 16250 | | "microsecond" |
| 16251 | | "nanosecond" |
| 16252 | >, |
| 16253 | ): Temporal.Duration; |
| 16254 | round( |
| 16255 | roundTo: RoundTo< |
| 16256 | | "hour" |
| 16257 | | "minute" |
| 16258 | | "second" |
| 16259 | | "millisecond" |
| 16260 | | "microsecond" |
| 16261 | | "nanosecond" |
| 16262 | >, |
| 16263 | ): Temporal.Instant; |
| 16264 | toZonedDateTime( |
| 16265 | calendarAndTimeZone: { timeZone: TimeZoneLike; calendar: CalendarLike }, |
| 16266 | ): Temporal.ZonedDateTime; |
| 16267 | toZonedDateTimeISO(tzLike: TimeZoneLike): Temporal.ZonedDateTime; |
| 16268 | toLocaleString( |
| 16269 | locales?: string | string[], |
| 16270 | options?: Intl.DateTimeFormatOptions, |
| 16271 | ): string; |
| 16272 | toJSON(): string; |
| 16273 | toString(options?: InstantToStringOptions): string; |
| 16274 | valueOf(): never; |
| 16275 | readonly [Symbol.toStringTag]: "Temporal.Instant"; |
| 16276 | } |
| 16277 | |
| 16278 | /** |
| 16279 | * @category Temporal |
| 16280 | * @experimental |
| 16281 | */ |
| 16282 | export type YearOrEraAndEraYear = { era: string; eraYear: number } | { |
| 16283 | year: number; |
| 16284 | }; |
| 16285 | /** |
| 16286 | * @category Temporal |
| 16287 | * @experimental |
| 16288 | */ |
| 16289 | export type MonthCodeOrMonthAndYear = |
| 16290 | | (YearOrEraAndEraYear & { month: number }) |
| 16291 | | { |
| 16292 | monthCode: string; |
| 16293 | }; |
| 16294 | /** |
| 16295 | * @category Temporal |
| 16296 | * @experimental |
| 16297 | */ |
| 16298 | export type MonthOrMonthCode = { month: number } | { monthCode: string }; |
| 16299 | |
| 16300 | /** |
| 16301 | * @category Temporal |
| 16302 | * @experimental |
| 16303 | */ |
| 16304 | export interface CalendarProtocol { |
| 16305 | id: string; |
| 16306 | year( |
| 16307 | date: |
| 16308 | | Temporal.PlainDate |
| 16309 | | Temporal.PlainDateTime |
| 16310 | | Temporal.PlainYearMonth |
| 16311 | | PlainDateLike |
| 16312 | | string, |
| 16313 | ): number; |
| 16314 | month( |
| 16315 | date: |
| 16316 | | Temporal.PlainDate |
| 16317 | | Temporal.PlainDateTime |
| 16318 | | Temporal.PlainYearMonth |
| 16319 | | Temporal.PlainMonthDay |
| 16320 | | PlainDateLike |
| 16321 | | string, |
| 16322 | ): number; |
| 16323 | monthCode( |
| 16324 | date: |
| 16325 | | Temporal.PlainDate |
| 16326 | | Temporal.PlainDateTime |
| 16327 | | Temporal.PlainYearMonth |
| 16328 | | Temporal.PlainMonthDay |
| 16329 | | PlainDateLike |
| 16330 | | string, |
| 16331 | ): string; |
| 16332 | day( |
| 16333 | date: |
| 16334 | | Temporal.PlainDate |
| 16335 | | Temporal.PlainDateTime |
| 16336 | | Temporal.PlainMonthDay |
| 16337 | | PlainDateLike |
| 16338 | | string, |
| 16339 | ): number; |
| 16340 | era( |
| 16341 | date: |
| 16342 | | Temporal.PlainDate |
| 16343 | | Temporal.PlainDateTime |
| 16344 | | PlainDateLike |
| 16345 | | string, |
| 16346 | ): string | undefined; |
| 16347 | eraYear( |
| 16348 | date: |
| 16349 | | Temporal.PlainDate |
| 16350 | | Temporal.PlainDateTime |
| 16351 | | PlainDateLike |
| 16352 | | string, |
| 16353 | ): number | undefined; |
| 16354 | dayOfWeek( |
| 16355 | date: |
| 16356 | | Temporal.PlainDate |
| 16357 | | Temporal.PlainDateTime |
| 16358 | | PlainDateLike |
| 16359 | | string, |
| 16360 | ): number; |
| 16361 | dayOfYear( |
| 16362 | date: |
| 16363 | | Temporal.PlainDate |
| 16364 | | Temporal.PlainDateTime |
| 16365 | | PlainDateLike |
| 16366 | | string, |
| 16367 | ): number; |
| 16368 | weekOfYear( |
| 16369 | date: |
| 16370 | | Temporal.PlainDate |
| 16371 | | Temporal.PlainDateTime |
| 16372 | | PlainDateLike |
| 16373 | | string, |
| 16374 | ): number; |
| 16375 | yearOfWeek( |
| 16376 | date: |
| 16377 | | Temporal.PlainDate |
| 16378 | | Temporal.PlainDateTime |
| 16379 | | PlainDateLike |
| 16380 | | string, |
| 16381 | ): number; |
| 16382 | daysInWeek( |
| 16383 | date: |
| 16384 | | Temporal.PlainDate |
| 16385 | | Temporal.PlainDateTime |
| 16386 | | PlainDateLike |
| 16387 | | string, |
| 16388 | ): number; |
| 16389 | daysInMonth( |
| 16390 | date: |
| 16391 | | Temporal.PlainDate |
| 16392 | | Temporal.PlainDateTime |
| 16393 | | Temporal.PlainYearMonth |
| 16394 | | PlainDateLike |
| 16395 | | string, |
| 16396 | ): number; |
| 16397 | daysInYear( |
| 16398 | date: |
| 16399 | | Temporal.PlainDate |
| 16400 | | Temporal.PlainDateTime |
| 16401 | | Temporal.PlainYearMonth |
| 16402 | | PlainDateLike |
| 16403 | | string, |
| 16404 | ): number; |
| 16405 | monthsInYear( |
| 16406 | date: |
| 16407 | | Temporal.PlainDate |
| 16408 | | Temporal.PlainDateTime |
| 16409 | | Temporal.PlainYearMonth |
| 16410 | | PlainDateLike |
| 16411 | | string, |
| 16412 | ): number; |
| 16413 | inLeapYear( |
| 16414 | date: |
| 16415 | | Temporal.PlainDate |
| 16416 | | Temporal.PlainDateTime |
| 16417 | | Temporal.PlainYearMonth |
| 16418 | | PlainDateLike |
| 16419 | | string, |
| 16420 | ): boolean; |
| 16421 | dateFromFields( |
| 16422 | fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number }, |
| 16423 | options?: AssignmentOptions, |
| 16424 | ): Temporal.PlainDate; |
| 16425 | yearMonthFromFields( |
| 16426 | fields: YearOrEraAndEraYear & MonthOrMonthCode, |
| 16427 | options?: AssignmentOptions, |
| 16428 | ): Temporal.PlainYearMonth; |
| 16429 | monthDayFromFields( |
| 16430 | fields: MonthCodeOrMonthAndYear & { day: number }, |
| 16431 | options?: AssignmentOptions, |
| 16432 | ): Temporal.PlainMonthDay; |
| 16433 | dateAdd( |
| 16434 | date: Temporal.PlainDate | PlainDateLike | string, |
| 16435 | duration: Temporal.Duration | DurationLike | string, |
| 16436 | options?: ArithmeticOptions, |
| 16437 | ): Temporal.PlainDate; |
| 16438 | dateUntil( |
| 16439 | one: Temporal.PlainDate | PlainDateLike | string, |
| 16440 | two: Temporal.PlainDate | PlainDateLike | string, |
| 16441 | options?: DifferenceOptions<"year" | "month" | "week" | "day">, |
| 16442 | ): Temporal.Duration; |
| 16443 | fields(fields: Iterable<string>): Iterable<string>; |
| 16444 | mergeFields( |
| 16445 | fields: Record<string, unknown>, |
| 16446 | additionalFields: Record<string, unknown>, |
| 16447 | ): Record<string, unknown>; |
| 16448 | toString?(): string; |
| 16449 | toJSON?(): string; |
| 16450 | } |
| 16451 | |
| 16452 | /** |
| 16453 | * Any of these types can be passed to Temporal methods instead of a Temporal.Calendar. |
| 16454 | * |
| 16455 | * @category Temporal |
| 16456 | * @experimental |
| 16457 | */ |
| 16458 | export type CalendarLike = |
| 16459 | | string |
| 16460 | | CalendarProtocol |
| 16461 | | ZonedDateTime |
| 16462 | | PlainDateTime |
| 16463 | | PlainDate |
| 16464 | | PlainYearMonth |
| 16465 | | PlainMonthDay; |
| 16466 | |
| 16467 | /** |
| 16468 | * A `Temporal.Calendar` is a representation of a calendar system. It includes |
| 16469 | * information about how many days are in each year, how many months are in |
| 16470 | * each year, how many days are in each month, and how to do arithmetic in |
| 16471 | * that calendar system. |
| 16472 | * |
| 16473 | * See https://tc39.es/proposal-temporal/docs/calendar.html for more details. |
| 16474 | * |
| 16475 | * @category Temporal |
| 16476 | * @experimental |
| 16477 | */ |
| 16478 | export class Calendar implements CalendarProtocol { |
| 16479 | static from(item: CalendarLike): Temporal.Calendar | CalendarProtocol; |
| 16480 | constructor(calendarIdentifier: string); |
| 16481 | readonly id: string; |
| 16482 | year( |
| 16483 | date: |
| 16484 | | Temporal.PlainDate |
| 16485 | | Temporal.PlainDateTime |
| 16486 | | Temporal.PlainYearMonth |
| 16487 | | PlainDateLike |
| 16488 | | string, |
| 16489 | ): number; |
| 16490 | month( |
| 16491 | date: |
| 16492 | | Temporal.PlainDate |
| 16493 | | Temporal.PlainDateTime |
| 16494 | | Temporal.PlainYearMonth |
| 16495 | | Temporal.PlainMonthDay |
| 16496 | | PlainDateLike |
| 16497 | | string, |
| 16498 | ): number; |
| 16499 | monthCode( |
| 16500 | date: |
| 16501 | | Temporal.PlainDate |
| 16502 | | Temporal.PlainDateTime |
| 16503 | | Temporal.PlainYearMonth |
| 16504 | | Temporal.PlainMonthDay |
| 16505 | | PlainDateLike |
| 16506 | | string, |
| 16507 | ): string; |
| 16508 | day( |
| 16509 | date: |
| 16510 | | Temporal.PlainDate |
| 16511 | | Temporal.PlainDateTime |
| 16512 | | Temporal.PlainMonthDay |
| 16513 | | PlainDateLike |
| 16514 | | string, |
| 16515 | ): number; |
| 16516 | era( |
| 16517 | date: |
| 16518 | | Temporal.PlainDate |
| 16519 | | Temporal.PlainDateTime |
| 16520 | | PlainDateLike |
| 16521 | | string, |
| 16522 | ): string | undefined; |
| 16523 | eraYear( |
| 16524 | date: |
| 16525 | | Temporal.PlainDate |
| 16526 | | Temporal.PlainDateTime |
| 16527 | | PlainDateLike |
| 16528 | | string, |
| 16529 | ): number | undefined; |
| 16530 | dayOfWeek( |
| 16531 | date: |
| 16532 | | Temporal.PlainDate |
| 16533 | | Temporal.PlainDateTime |
| 16534 | | PlainDateLike |
| 16535 | | string, |
| 16536 | ): number; |
| 16537 | dayOfYear( |
| 16538 | date: |
| 16539 | | Temporal.PlainDate |
| 16540 | | Temporal.PlainDateTime |
| 16541 | | PlainDateLike |
| 16542 | | string, |
| 16543 | ): number; |
| 16544 | weekOfYear( |
| 16545 | date: |
| 16546 | | Temporal.PlainDate |
| 16547 | | Temporal.PlainDateTime |
| 16548 | | PlainDateLike |
| 16549 | | string, |
| 16550 | ): number; |
| 16551 | yearOfWeek( |
| 16552 | date: |
| 16553 | | Temporal.PlainDate |
| 16554 | | Temporal.PlainDateTime |
| 16555 | | PlainDateLike |
| 16556 | | string, |
| 16557 | ): number; |
| 16558 | daysInWeek( |
| 16559 | date: |
| 16560 | | Temporal.PlainDate |
| 16561 | | Temporal.PlainDateTime |
| 16562 | | PlainDateLike |
| 16563 | | string, |
| 16564 | ): number; |
| 16565 | daysInMonth( |
| 16566 | date: |
| 16567 | | Temporal.PlainDate |
| 16568 | | Temporal.PlainDateTime |
| 16569 | | Temporal.PlainYearMonth |
| 16570 | | PlainDateLike |
| 16571 | | string, |
| 16572 | ): number; |
| 16573 | daysInYear( |
| 16574 | date: |
| 16575 | | Temporal.PlainDate |
| 16576 | | Temporal.PlainDateTime |
| 16577 | | Temporal.PlainYearMonth |
| 16578 | | PlainDateLike |
| 16579 | | string, |
| 16580 | ): number; |
| 16581 | monthsInYear( |
| 16582 | date: |
| 16583 | | Temporal.PlainDate |
| 16584 | | Temporal.PlainDateTime |
| 16585 | | Temporal.PlainYearMonth |
| 16586 | | PlainDateLike |
| 16587 | | string, |
| 16588 | ): number; |
| 16589 | inLeapYear( |
| 16590 | date: |
| 16591 | | Temporal.PlainDate |
| 16592 | | Temporal.PlainDateTime |
| 16593 | | Temporal.PlainYearMonth |
| 16594 | | PlainDateLike |
| 16595 | | string, |
| 16596 | ): boolean; |
| 16597 | dateFromFields( |
| 16598 | fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number }, |
| 16599 | options?: AssignmentOptions, |
| 16600 | ): Temporal.PlainDate; |
| 16601 | yearMonthFromFields( |
| 16602 | fields: YearOrEraAndEraYear & MonthOrMonthCode, |
| 16603 | options?: AssignmentOptions, |
| 16604 | ): Temporal.PlainYearMonth; |
| 16605 | monthDayFromFields( |
| 16606 | fields: MonthCodeOrMonthAndYear & { day: number }, |
| 16607 | options?: AssignmentOptions, |
| 16608 | ): Temporal.PlainMonthDay; |
| 16609 | dateAdd( |
| 16610 | date: Temporal.PlainDate | PlainDateLike | string, |
| 16611 | duration: Temporal.Duration | DurationLike | string, |
| 16612 | options?: ArithmeticOptions, |
| 16613 | ): Temporal.PlainDate; |
| 16614 | dateUntil( |
| 16615 | one: Temporal.PlainDate | PlainDateLike | string, |
| 16616 | two: Temporal.PlainDate | PlainDateLike | string, |
| 16617 | options?: DifferenceOptions<"year" | "month" | "week" | "day">, |
| 16618 | ): Temporal.Duration; |
| 16619 | fields(fields: Iterable<string>): string[]; |
| 16620 | mergeFields( |
| 16621 | fields: Record<string, unknown>, |
| 16622 | additionalFields: Record<string, unknown>, |
| 16623 | ): Record<string, unknown>; |
| 16624 | toString(): string; |
| 16625 | toJSON(): string; |
| 16626 | readonly [Symbol.toStringTag]: "Temporal.Calendar"; |
| 16627 | } |
| 16628 | |
| 16629 | /** |
| 16630 | * @category Temporal |
| 16631 | * @experimental |
| 16632 | */ |
| 16633 | export type PlainDateLike = { |
| 16634 | era?: string | undefined; |
| 16635 | eraYear?: number | undefined; |
| 16636 | year?: number; |
| 16637 | month?: number; |
| 16638 | monthCode?: string; |
| 16639 | day?: number; |
| 16640 | calendar?: CalendarLike; |
| 16641 | }; |
| 16642 | |
| 16643 | /** |
| 16644 | * @category Temporal |
| 16645 | * @experimental |
| 16646 | */ |
| 16647 | export type PlainDateISOFields = { |
| 16648 | isoYear: number; |
| 16649 | isoMonth: number; |
| 16650 | isoDay: number; |
| 16651 | calendar: string | CalendarProtocol; |
| 16652 | }; |
| 16653 | |
| 16654 | /** |
| 16655 | * A `Temporal.PlainDate` represents a calendar date. "Calendar date" refers to the |
| 16656 | * concept of a date as expressed in everyday usage, independent of any time |
| 16657 | * zone. For example, it could be used to represent an event on a calendar |
| 16658 | * which happens during the whole day no matter which time zone it's happening |
| 16659 | * in. |
| 16660 | * |
| 16661 | * See https://tc39.es/proposal-temporal/docs/date.html for more details. |
| 16662 | * |
| 16663 | * @category Temporal |
| 16664 | * @experimental |
| 16665 | */ |
| 16666 | export class PlainDate { |
| 16667 | static from( |
| 16668 | item: Temporal.PlainDate | PlainDateLike | string, |
| 16669 | options?: AssignmentOptions, |
| 16670 | ): Temporal.PlainDate; |
| 16671 | static compare( |
| 16672 | one: Temporal.PlainDate | PlainDateLike | string, |
| 16673 | two: Temporal.PlainDate | PlainDateLike | string, |
| 16674 | ): ComparisonResult; |
| 16675 | constructor( |
| 16676 | isoYear: number, |
| 16677 | isoMonth: number, |
| 16678 | isoDay: number, |
| 16679 | calendar?: CalendarLike, |
| 16680 | ); |
| 16681 | readonly era: string | undefined; |
| 16682 | readonly eraYear: number | undefined; |
| 16683 | readonly year: number; |
| 16684 | readonly month: number; |
| 16685 | readonly monthCode: string; |
| 16686 | readonly day: number; |
| 16687 | readonly calendarId: string; |
| 16688 | getCalendar(): CalendarProtocol; |
| 16689 | readonly dayOfWeek: number; |
| 16690 | readonly dayOfYear: number; |
| 16691 | readonly weekOfYear: number; |
| 16692 | readonly yearOfWeek: number; |
| 16693 | readonly daysInWeek: number; |
| 16694 | readonly daysInYear: number; |
| 16695 | readonly daysInMonth: number; |
| 16696 | readonly monthsInYear: number; |
| 16697 | readonly inLeapYear: boolean; |
| 16698 | equals(other: Temporal.PlainDate | PlainDateLike | string): boolean; |
| 16699 | with( |
| 16700 | dateLike: PlainDateLike, |
| 16701 | options?: AssignmentOptions, |
| 16702 | ): Temporal.PlainDate; |
| 16703 | withCalendar(calendar: CalendarLike): Temporal.PlainDate; |
| 16704 | add( |
| 16705 | durationLike: Temporal.Duration | DurationLike | string, |
| 16706 | options?: ArithmeticOptions, |
| 16707 | ): Temporal.PlainDate; |
| 16708 | subtract( |
| 16709 | durationLike: Temporal.Duration | DurationLike | string, |
| 16710 | options?: ArithmeticOptions, |
| 16711 | ): Temporal.PlainDate; |
| 16712 | until( |
| 16713 | other: Temporal.PlainDate | PlainDateLike | string, |
| 16714 | options?: DifferenceOptions<"year" | "month" | "week" | "day">, |
| 16715 | ): Temporal.Duration; |
| 16716 | since( |
| 16717 | other: Temporal.PlainDate | PlainDateLike | string, |
| 16718 | options?: DifferenceOptions<"year" | "month" | "week" | "day">, |
| 16719 | ): Temporal.Duration; |
| 16720 | toPlainDateTime( |
| 16721 | temporalTime?: Temporal.PlainTime | PlainTimeLike | string, |
| 16722 | ): Temporal.PlainDateTime; |
| 16723 | toZonedDateTime( |
| 16724 | timeZoneAndTime: |
| 16725 | | TimeZoneProtocol |
| 16726 | | string |
| 16727 | | { |
| 16728 | timeZone: TimeZoneLike; |
| 16729 | plainTime?: Temporal.PlainTime | PlainTimeLike | string; |
| 16730 | }, |
| 16731 | ): Temporal.ZonedDateTime; |
| 16732 | toPlainYearMonth(): Temporal.PlainYearMonth; |
| 16733 | toPlainMonthDay(): Temporal.PlainMonthDay; |
| 16734 | getISOFields(): PlainDateISOFields; |
| 16735 | toLocaleString( |
| 16736 | locales?: string | string[], |
| 16737 | options?: Intl.DateTimeFormatOptions, |
| 16738 | ): string; |
| 16739 | toJSON(): string; |
| 16740 | toString(options?: ShowCalendarOption): string; |
| 16741 | valueOf(): never; |
| 16742 | readonly [Symbol.toStringTag]: "Temporal.PlainDate"; |
| 16743 | } |
| 16744 | |
| 16745 | /** |
| 16746 | * @category Temporal |
| 16747 | * @experimental |
| 16748 | */ |
| 16749 | export type PlainDateTimeLike = { |
| 16750 | era?: string | undefined; |
| 16751 | eraYear?: number | undefined; |
| 16752 | year?: number; |
| 16753 | month?: number; |
| 16754 | monthCode?: string; |
| 16755 | day?: number; |
| 16756 | hour?: number; |
| 16757 | minute?: number; |
| 16758 | second?: number; |
| 16759 | millisecond?: number; |
| 16760 | microsecond?: number; |
| 16761 | nanosecond?: number; |
| 16762 | calendar?: CalendarLike; |
| 16763 | }; |
| 16764 | |
| 16765 | /** |
| 16766 | * @category Temporal |
| 16767 | * @experimental |
| 16768 | */ |
| 16769 | export type PlainDateTimeISOFields = { |
| 16770 | isoYear: number; |
| 16771 | isoMonth: number; |
| 16772 | isoDay: number; |
| 16773 | isoHour: number; |
| 16774 | isoMinute: number; |
| 16775 | isoSecond: number; |
| 16776 | isoMillisecond: number; |
| 16777 | isoMicrosecond: number; |
| 16778 | isoNanosecond: number; |
| 16779 | calendar: string | CalendarProtocol; |
| 16780 | }; |
| 16781 | |
| 16782 | /** |
| 16783 | * A `Temporal.PlainDateTime` represents a calendar date and wall-clock time, with |
| 16784 | * a precision in nanoseconds, and without any time zone. Of the Temporal |
| 16785 | * classes carrying human-readable time information, it is the most general |
| 16786 | * and complete one. `Temporal.PlainDate`, `Temporal.PlainTime`, `Temporal.PlainYearMonth`, |
| 16787 | * and `Temporal.PlainMonthDay` all carry less information and should be used when |
| 16788 | * complete information is not required. |
| 16789 | * |
| 16790 | * See https://tc39.es/proposal-temporal/docs/datetime.html for more details. |
| 16791 | * |
| 16792 | * @category Temporal |
| 16793 | * @experimental |
| 16794 | */ |
| 16795 | export class PlainDateTime { |
| 16796 | static from( |
| 16797 | item: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 16798 | options?: AssignmentOptions, |
| 16799 | ): Temporal.PlainDateTime; |
| 16800 | static compare( |
| 16801 | one: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 16802 | two: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 16803 | ): ComparisonResult; |
| 16804 | constructor( |
| 16805 | isoYear: number, |
| 16806 | isoMonth: number, |
| 16807 | isoDay: number, |
| 16808 | hour?: number, |
| 16809 | minute?: number, |
| 16810 | second?: number, |
| 16811 | millisecond?: number, |
| 16812 | microsecond?: number, |
| 16813 | nanosecond?: number, |
| 16814 | calendar?: CalendarLike, |
| 16815 | ); |
| 16816 | readonly era: string | undefined; |
| 16817 | readonly eraYear: number | undefined; |
| 16818 | readonly year: number; |
| 16819 | readonly month: number; |
| 16820 | readonly monthCode: string; |
| 16821 | readonly day: number; |
| 16822 | readonly hour: number; |
| 16823 | readonly minute: number; |
| 16824 | readonly second: number; |
| 16825 | readonly millisecond: number; |
| 16826 | readonly microsecond: number; |
| 16827 | readonly nanosecond: number; |
| 16828 | readonly calendarId: string; |
| 16829 | getCalendar(): CalendarProtocol; |
| 16830 | readonly dayOfWeek: number; |
| 16831 | readonly dayOfYear: number; |
| 16832 | readonly weekOfYear: number; |
| 16833 | readonly yearOfWeek: number; |
| 16834 | readonly daysInWeek: number; |
| 16835 | readonly daysInYear: number; |
| 16836 | readonly daysInMonth: number; |
| 16837 | readonly monthsInYear: number; |
| 16838 | readonly inLeapYear: boolean; |
| 16839 | equals(other: Temporal.PlainDateTime | PlainDateTimeLike | string): boolean; |
| 16840 | with( |
| 16841 | dateTimeLike: PlainDateTimeLike, |
| 16842 | options?: AssignmentOptions, |
| 16843 | ): Temporal.PlainDateTime; |
| 16844 | withPlainTime( |
| 16845 | timeLike?: Temporal.PlainTime | PlainTimeLike | string, |
| 16846 | ): Temporal.PlainDateTime; |
| 16847 | withPlainDate( |
| 16848 | dateLike: Temporal.PlainDate | PlainDateLike | string, |
| 16849 | ): Temporal.PlainDateTime; |
| 16850 | withCalendar(calendar: CalendarLike): Temporal.PlainDateTime; |
| 16851 | add( |
| 16852 | durationLike: Temporal.Duration | DurationLike | string, |
| 16853 | options?: ArithmeticOptions, |
| 16854 | ): Temporal.PlainDateTime; |
| 16855 | subtract( |
| 16856 | durationLike: Temporal.Duration | DurationLike | string, |
| 16857 | options?: ArithmeticOptions, |
| 16858 | ): Temporal.PlainDateTime; |
| 16859 | until( |
| 16860 | other: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 16861 | options?: DifferenceOptions< |
| 16862 | | "year" |
| 16863 | | "month" |
| 16864 | | "week" |
| 16865 | | "day" |
| 16866 | | "hour" |
| 16867 | | "minute" |
| 16868 | | "second" |
| 16869 | | "millisecond" |
| 16870 | | "microsecond" |
| 16871 | | "nanosecond" |
| 16872 | >, |
| 16873 | ): Temporal.Duration; |
| 16874 | since( |
| 16875 | other: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 16876 | options?: DifferenceOptions< |
| 16877 | | "year" |
| 16878 | | "month" |
| 16879 | | "week" |
| 16880 | | "day" |
| 16881 | | "hour" |
| 16882 | | "minute" |
| 16883 | | "second" |
| 16884 | | "millisecond" |
| 16885 | | "microsecond" |
| 16886 | | "nanosecond" |
| 16887 | >, |
| 16888 | ): Temporal.Duration; |
| 16889 | round( |
| 16890 | roundTo: RoundTo< |
| 16891 | | "day" |
| 16892 | | "hour" |
| 16893 | | "minute" |
| 16894 | | "second" |
| 16895 | | "millisecond" |
| 16896 | | "microsecond" |
| 16897 | | "nanosecond" |
| 16898 | >, |
| 16899 | ): Temporal.PlainDateTime; |
| 16900 | toZonedDateTime( |
| 16901 | tzLike: TimeZoneLike, |
| 16902 | options?: ToInstantOptions, |
| 16903 | ): Temporal.ZonedDateTime; |
| 16904 | toPlainDate(): Temporal.PlainDate; |
| 16905 | toPlainYearMonth(): Temporal.PlainYearMonth; |
| 16906 | toPlainMonthDay(): Temporal.PlainMonthDay; |
| 16907 | toPlainTime(): Temporal.PlainTime; |
| 16908 | getISOFields(): PlainDateTimeISOFields; |
| 16909 | toLocaleString( |
| 16910 | locales?: string | string[], |
| 16911 | options?: Intl.DateTimeFormatOptions, |
| 16912 | ): string; |
| 16913 | toJSON(): string; |
| 16914 | toString(options?: CalendarTypeToStringOptions): string; |
| 16915 | valueOf(): never; |
| 16916 | readonly [Symbol.toStringTag]: "Temporal.PlainDateTime"; |
| 16917 | } |
| 16918 | |
| 16919 | /** |
| 16920 | * @category Temporal |
| 16921 | * @experimental |
| 16922 | */ |
| 16923 | export type PlainMonthDayLike = { |
| 16924 | era?: string | undefined; |
| 16925 | eraYear?: number | undefined; |
| 16926 | year?: number; |
| 16927 | month?: number; |
| 16928 | monthCode?: string; |
| 16929 | day?: number; |
| 16930 | calendar?: CalendarLike; |
| 16931 | }; |
| 16932 | |
| 16933 | /** |
| 16934 | * A `Temporal.PlainMonthDay` represents a particular day on the calendar, but |
| 16935 | * without a year. For example, it could be used to represent a yearly |
| 16936 | * recurring event, like "Bastille Day is on the 14th of July." |
| 16937 | * |
| 16938 | * See https://tc39.es/proposal-temporal/docs/monthday.html for more details. |
| 16939 | * |
| 16940 | * @category Temporal |
| 16941 | * @experimental |
| 16942 | */ |
| 16943 | export class PlainMonthDay { |
| 16944 | static from( |
| 16945 | item: Temporal.PlainMonthDay | PlainMonthDayLike | string, |
| 16946 | options?: AssignmentOptions, |
| 16947 | ): Temporal.PlainMonthDay; |
| 16948 | constructor( |
| 16949 | isoMonth: number, |
| 16950 | isoDay: number, |
| 16951 | calendar?: CalendarLike, |
| 16952 | referenceISOYear?: number, |
| 16953 | ); |
| 16954 | readonly monthCode: string; |
| 16955 | readonly day: number; |
| 16956 | readonly calendarId: string; |
| 16957 | getCalendar(): CalendarProtocol; |
| 16958 | equals(other: Temporal.PlainMonthDay | PlainMonthDayLike | string): boolean; |
| 16959 | with( |
| 16960 | monthDayLike: PlainMonthDayLike, |
| 16961 | options?: AssignmentOptions, |
| 16962 | ): Temporal.PlainMonthDay; |
| 16963 | toPlainDate(year: { year: number }): Temporal.PlainDate; |
| 16964 | getISOFields(): PlainDateISOFields; |
| 16965 | toLocaleString( |
| 16966 | locales?: string | string[], |
| 16967 | options?: Intl.DateTimeFormatOptions, |
| 16968 | ): string; |
| 16969 | toJSON(): string; |
| 16970 | toString(options?: ShowCalendarOption): string; |
| 16971 | valueOf(): never; |
| 16972 | readonly [Symbol.toStringTag]: "Temporal.PlainMonthDay"; |
| 16973 | } |
| 16974 | |
| 16975 | /** |
| 16976 | * @category Temporal |
| 16977 | * @experimental |
| 16978 | */ |
| 16979 | export type PlainTimeLike = { |
| 16980 | hour?: number; |
| 16981 | minute?: number; |
| 16982 | second?: number; |
| 16983 | millisecond?: number; |
| 16984 | microsecond?: number; |
| 16985 | nanosecond?: number; |
| 16986 | }; |
| 16987 | |
| 16988 | /** |
| 16989 | * @category Temporal |
| 16990 | * @experimental |
| 16991 | */ |
| 16992 | export type PlainTimeISOFields = { |
| 16993 | isoHour: number; |
| 16994 | isoMinute: number; |
| 16995 | isoSecond: number; |
| 16996 | isoMillisecond: number; |
| 16997 | isoMicrosecond: number; |
| 16998 | isoNanosecond: number; |
| 16999 | }; |
| 17000 | |
| 17001 | /** |
| 17002 | * A `Temporal.PlainTime` represents a wall-clock time, with a precision in |
| 17003 | * nanoseconds, and without any time zone. "Wall-clock time" refers to the |
| 17004 | * concept of a time as expressed in everyday usage — the time that you read |
| 17005 | * off the clock on the wall. For example, it could be used to represent an |
| 17006 | * event that happens daily at a certain time, no matter what time zone. |
| 17007 | * |
| 17008 | * `Temporal.PlainTime` refers to a time with no associated calendar date; if you |
| 17009 | * need to refer to a specific time on a specific day, use |
| 17010 | * `Temporal.PlainDateTime`. A `Temporal.PlainTime` can be converted into a |
| 17011 | * `Temporal.PlainDateTime` by combining it with a `Temporal.PlainDate` using the |
| 17012 | * `toPlainDateTime()` method. |
| 17013 | * |
| 17014 | * See https://tc39.es/proposal-temporal/docs/time.html for more details. |
| 17015 | * |
| 17016 | * @category Temporal |
| 17017 | * @experimental |
| 17018 | */ |
| 17019 | export class PlainTime { |
| 17020 | static from( |
| 17021 | item: Temporal.PlainTime | PlainTimeLike | string, |
| 17022 | options?: AssignmentOptions, |
| 17023 | ): Temporal.PlainTime; |
| 17024 | static compare( |
| 17025 | one: Temporal.PlainTime | PlainTimeLike | string, |
| 17026 | two: Temporal.PlainTime | PlainTimeLike | string, |
| 17027 | ): ComparisonResult; |
| 17028 | constructor( |
| 17029 | hour?: number, |
| 17030 | minute?: number, |
| 17031 | second?: number, |
| 17032 | millisecond?: number, |
| 17033 | microsecond?: number, |
| 17034 | nanosecond?: number, |
| 17035 | ); |
| 17036 | readonly hour: number; |
| 17037 | readonly minute: number; |
| 17038 | readonly second: number; |
| 17039 | readonly millisecond: number; |
| 17040 | readonly microsecond: number; |
| 17041 | readonly nanosecond: number; |
| 17042 | equals(other: Temporal.PlainTime | PlainTimeLike | string): boolean; |
| 17043 | with( |
| 17044 | timeLike: Temporal.PlainTime | PlainTimeLike, |
| 17045 | options?: AssignmentOptions, |
| 17046 | ): Temporal.PlainTime; |
| 17047 | add( |
| 17048 | durationLike: Temporal.Duration | DurationLike | string, |
| 17049 | options?: ArithmeticOptions, |
| 17050 | ): Temporal.PlainTime; |
| 17051 | subtract( |
| 17052 | durationLike: Temporal.Duration | DurationLike | string, |
| 17053 | options?: ArithmeticOptions, |
| 17054 | ): Temporal.PlainTime; |
| 17055 | until( |
| 17056 | other: Temporal.PlainTime | PlainTimeLike | string, |
| 17057 | options?: DifferenceOptions< |
| 17058 | | "hour" |
| 17059 | | "minute" |
| 17060 | | "second" |
| 17061 | | "millisecond" |
| 17062 | | "microsecond" |
| 17063 | | "nanosecond" |
| 17064 | >, |
| 17065 | ): Temporal.Duration; |
| 17066 | since( |
| 17067 | other: Temporal.PlainTime | PlainTimeLike | string, |
| 17068 | options?: DifferenceOptions< |
| 17069 | | "hour" |
| 17070 | | "minute" |
| 17071 | | "second" |
| 17072 | | "millisecond" |
| 17073 | | "microsecond" |
| 17074 | | "nanosecond" |
| 17075 | >, |
| 17076 | ): Temporal.Duration; |
| 17077 | round( |
| 17078 | roundTo: RoundTo< |
| 17079 | | "hour" |
| 17080 | | "minute" |
| 17081 | | "second" |
| 17082 | | "millisecond" |
| 17083 | | "microsecond" |
| 17084 | | "nanosecond" |
| 17085 | >, |
| 17086 | ): Temporal.PlainTime; |
| 17087 | toPlainDateTime( |
| 17088 | temporalDate: Temporal.PlainDate | PlainDateLike | string, |
| 17089 | ): Temporal.PlainDateTime; |
| 17090 | toZonedDateTime(timeZoneAndDate: { |
| 17091 | timeZone: TimeZoneLike; |
| 17092 | plainDate: Temporal.PlainDate | PlainDateLike | string; |
| 17093 | }): Temporal.ZonedDateTime; |
| 17094 | getISOFields(): PlainTimeISOFields; |
| 17095 | toLocaleString( |
| 17096 | locales?: string | string[], |
| 17097 | options?: Intl.DateTimeFormatOptions, |
| 17098 | ): string; |
| 17099 | toJSON(): string; |
| 17100 | toString(options?: ToStringPrecisionOptions): string; |
| 17101 | valueOf(): never; |
| 17102 | readonly [Symbol.toStringTag]: "Temporal.PlainTime"; |
| 17103 | } |
| 17104 | |
| 17105 | /** |
| 17106 | * A plain object implementing the protocol for a custom time zone. |
| 17107 | * |
| 17108 | * @category Temporal |
| 17109 | * @experimental |
| 17110 | */ |
| 17111 | export interface TimeZoneProtocol { |
| 17112 | id: string; |
| 17113 | getOffsetNanosecondsFor(instant: Temporal.Instant | string): number; |
| 17114 | getOffsetStringFor?(instant: Temporal.Instant | string): string; |
| 17115 | getPlainDateTimeFor?( |
| 17116 | instant: Temporal.Instant | string, |
| 17117 | calendar?: CalendarLike, |
| 17118 | ): Temporal.PlainDateTime; |
| 17119 | getInstantFor?( |
| 17120 | dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 17121 | options?: ToInstantOptions, |
| 17122 | ): Temporal.Instant; |
| 17123 | getNextTransition?( |
| 17124 | startingPoint: Temporal.Instant | string, |
| 17125 | ): Temporal.Instant | null; |
| 17126 | getPreviousTransition?( |
| 17127 | startingPoint: Temporal.Instant | string, |
| 17128 | ): Temporal.Instant | null; |
| 17129 | getPossibleInstantsFor( |
| 17130 | dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 17131 | ): Temporal.Instant[]; |
| 17132 | toString?(): string; |
| 17133 | toJSON?(): string; |
| 17134 | } |
| 17135 | |
| 17136 | /** |
| 17137 | * Any of these types can be passed to Temporal methods instead of a Temporal.TimeZone. |
| 17138 | * |
| 17139 | * @category Temporal |
| 17140 | * @experimental |
| 17141 | */ |
| 17142 | export type TimeZoneLike = string | TimeZoneProtocol | ZonedDateTime; |
| 17143 | |
| 17144 | /** |
| 17145 | * A `Temporal.TimeZone` is a representation of a time zone: either an |
| 17146 | * {@link https://www.iana.org/time-zones|IANA time zone}, including |
| 17147 | * information about the time zone such as the offset between the local time |
| 17148 | * and UTC at a particular time, and daylight saving time (DST) changes; or |
| 17149 | * simply a particular UTC offset with no DST. |
| 17150 | * |
| 17151 | * `Temporal.ZonedDateTime` is the only Temporal type to contain a time zone. |
| 17152 | * Other types, like `Temporal.Instant` and `Temporal.PlainDateTime`, do not |
| 17153 | * contain any time zone information, and a `Temporal.TimeZone` object is |
| 17154 | * required to convert between them. |
| 17155 | * |
| 17156 | * See https://tc39.es/proposal-temporal/docs/timezone.html for more details. |
| 17157 | * |
| 17158 | * @category Temporal |
| 17159 | * @experimental |
| 17160 | */ |
| 17161 | export class TimeZone implements TimeZoneProtocol { |
| 17162 | static from(timeZone: TimeZoneLike): Temporal.TimeZone | TimeZoneProtocol; |
| 17163 | constructor(timeZoneIdentifier: string); |
| 17164 | readonly id: string; |
| 17165 | equals(timeZone: TimeZoneLike): boolean; |
| 17166 | getOffsetNanosecondsFor(instant: Temporal.Instant | string): number; |
| 17167 | getOffsetStringFor(instant: Temporal.Instant | string): string; |
| 17168 | getPlainDateTimeFor( |
| 17169 | instant: Temporal.Instant | string, |
| 17170 | calendar?: CalendarLike, |
| 17171 | ): Temporal.PlainDateTime; |
| 17172 | getInstantFor( |
| 17173 | dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 17174 | options?: ToInstantOptions, |
| 17175 | ): Temporal.Instant; |
| 17176 | getNextTransition( |
| 17177 | startingPoint: Temporal.Instant | string, |
| 17178 | ): Temporal.Instant | null; |
| 17179 | getPreviousTransition( |
| 17180 | startingPoint: Temporal.Instant | string, |
| 17181 | ): Temporal.Instant | null; |
| 17182 | getPossibleInstantsFor( |
| 17183 | dateTime: Temporal.PlainDateTime | PlainDateTimeLike | string, |
| 17184 | ): Temporal.Instant[]; |
| 17185 | toString(): string; |
| 17186 | toJSON(): string; |
| 17187 | readonly [Symbol.toStringTag]: "Temporal.TimeZone"; |
| 17188 | } |
| 17189 | |
| 17190 | /** |
| 17191 | * @category Temporal |
| 17192 | * @experimental |
| 17193 | */ |
| 17194 | export type PlainYearMonthLike = { |
| 17195 | era?: string | undefined; |
| 17196 | eraYear?: number | undefined; |
| 17197 | year?: number; |
| 17198 | month?: number; |
| 17199 | monthCode?: string; |
| 17200 | calendar?: CalendarLike; |
| 17201 | }; |
| 17202 | |
| 17203 | /** |
| 17204 | * A `Temporal.PlainYearMonth` represents a particular month on the calendar. For |
| 17205 | * example, it could be used to represent a particular instance of a monthly |
| 17206 | * recurring event, like "the June 2019 meeting". |
| 17207 | * |
| 17208 | * See https://tc39.es/proposal-temporal/docs/yearmonth.html for more details. |
| 17209 | * |
| 17210 | * @category Temporal |
| 17211 | * @experimental |
| 17212 | */ |
| 17213 | export class PlainYearMonth { |
| 17214 | static from( |
| 17215 | item: Temporal.PlainYearMonth | PlainYearMonthLike | string, |
| 17216 | options?: AssignmentOptions, |
| 17217 | ): Temporal.PlainYearMonth; |
| 17218 | static compare( |
| 17219 | one: Temporal.PlainYearMonth | PlainYearMonthLike | string, |
| 17220 | two: Temporal.PlainYearMonth | PlainYearMonthLike | string, |
| 17221 | ): ComparisonResult; |
| 17222 | constructor( |
| 17223 | isoYear: number, |
| 17224 | isoMonth: number, |
| 17225 | calendar?: CalendarLike, |
| 17226 | referenceISODay?: number, |
| 17227 | ); |
| 17228 | readonly era: string | undefined; |
| 17229 | readonly eraYear: number | undefined; |
| 17230 | readonly year: number; |
| 17231 | readonly month: number; |
| 17232 | readonly monthCode: string; |
| 17233 | readonly calendarId: string; |
| 17234 | getCalendar(): CalendarProtocol; |
| 17235 | readonly daysInMonth: number; |
| 17236 | readonly daysInYear: number; |
| 17237 | readonly monthsInYear: number; |
| 17238 | readonly inLeapYear: boolean; |
| 17239 | equals( |
| 17240 | other: Temporal.PlainYearMonth | PlainYearMonthLike | string, |
| 17241 | ): boolean; |
| 17242 | with( |
| 17243 | yearMonthLike: PlainYearMonthLike, |
| 17244 | options?: AssignmentOptions, |
| 17245 | ): Temporal.PlainYearMonth; |
| 17246 | add( |
| 17247 | durationLike: Temporal.Duration | DurationLike | string, |
| 17248 | options?: ArithmeticOptions, |
| 17249 | ): Temporal.PlainYearMonth; |
| 17250 | subtract( |
| 17251 | durationLike: Temporal.Duration | DurationLike | string, |
| 17252 | options?: ArithmeticOptions, |
| 17253 | ): Temporal.PlainYearMonth; |
| 17254 | until( |
| 17255 | other: Temporal.PlainYearMonth | PlainYearMonthLike | string, |
| 17256 | options?: DifferenceOptions<"year" | "month">, |
| 17257 | ): Temporal.Duration; |
| 17258 | since( |
| 17259 | other: Temporal.PlainYearMonth | PlainYearMonthLike | string, |
| 17260 | options?: DifferenceOptions<"year" | "month">, |
| 17261 | ): Temporal.Duration; |
| 17262 | toPlainDate(day: { day: number }): Temporal.PlainDate; |
| 17263 | getISOFields(): PlainDateISOFields; |
| 17264 | toLocaleString( |
| 17265 | locales?: string | string[], |
| 17266 | options?: Intl.DateTimeFormatOptions, |
| 17267 | ): string; |
| 17268 | toJSON(): string; |
| 17269 | toString(options?: ShowCalendarOption): string; |
| 17270 | valueOf(): never; |
| 17271 | readonly [Symbol.toStringTag]: "Temporal.PlainYearMonth"; |
| 17272 | } |
| 17273 | |
| 17274 | /** |
| 17275 | * @category Temporal |
| 17276 | * @experimental |
| 17277 | */ |
| 17278 | export type ZonedDateTimeLike = { |
| 17279 | era?: string | undefined; |
| 17280 | eraYear?: number | undefined; |
| 17281 | year?: number; |
| 17282 | month?: number; |
| 17283 | monthCode?: string; |
| 17284 | day?: number; |
| 17285 | hour?: number; |
| 17286 | minute?: number; |
| 17287 | second?: number; |
| 17288 | millisecond?: number; |
| 17289 | microsecond?: number; |
| 17290 | nanosecond?: number; |
| 17291 | offset?: string; |
| 17292 | timeZone?: TimeZoneLike; |
| 17293 | calendar?: CalendarLike; |
| 17294 | }; |
| 17295 | |
| 17296 | /** |
| 17297 | * @category Temporal |
| 17298 | * @experimental |
| 17299 | */ |
| 17300 | export type ZonedDateTimeISOFields = { |
| 17301 | isoYear: number; |
| 17302 | isoMonth: number; |
| 17303 | isoDay: number; |
| 17304 | isoHour: number; |
| 17305 | isoMinute: number; |
| 17306 | isoSecond: number; |
| 17307 | isoMillisecond: number; |
| 17308 | isoMicrosecond: number; |
| 17309 | isoNanosecond: number; |
| 17310 | offset: string; |
| 17311 | timeZone: string | TimeZoneProtocol; |
| 17312 | calendar: string | CalendarProtocol; |
| 17313 | }; |
| 17314 | |
| 17315 | /** |
| 17316 | * @category Temporal |
| 17317 | * @experimental |
| 17318 | */ |
| 17319 | export class ZonedDateTime { |
| 17320 | static from( |
| 17321 | item: Temporal.ZonedDateTime | ZonedDateTimeLike | string, |
| 17322 | options?: ZonedDateTimeAssignmentOptions, |
| 17323 | ): ZonedDateTime; |
| 17324 | static compare( |
| 17325 | one: Temporal.ZonedDateTime | ZonedDateTimeLike | string, |
| 17326 | two: Temporal.ZonedDateTime | ZonedDateTimeLike | string, |
| 17327 | ): ComparisonResult; |
| 17328 | constructor( |
| 17329 | epochNanoseconds: bigint, |
| 17330 | timeZone: TimeZoneLike, |
| 17331 | calendar?: CalendarLike, |
| 17332 | ); |
| 17333 | readonly era: string | undefined; |
| 17334 | readonly eraYear: number | undefined; |
| 17335 | readonly year: number; |
| 17336 | readonly month: number; |
| 17337 | readonly monthCode: string; |
| 17338 | readonly day: number; |
| 17339 | readonly hour: number; |
| 17340 | readonly minute: number; |
| 17341 | readonly second: number; |
| 17342 | readonly millisecond: number; |
| 17343 | readonly microsecond: number; |
| 17344 | readonly nanosecond: number; |
| 17345 | readonly timeZoneId: string; |
| 17346 | getTimeZone(): TimeZoneProtocol; |
| 17347 | readonly calendarId: string; |
| 17348 | getCalendar(): CalendarProtocol; |
| 17349 | readonly dayOfWeek: number; |
| 17350 | readonly dayOfYear: number; |
| 17351 | readonly weekOfYear: number; |
| 17352 | readonly yearOfWeek: number; |
| 17353 | readonly hoursInDay: number; |
| 17354 | readonly daysInWeek: number; |
| 17355 | readonly daysInMonth: number; |
| 17356 | readonly daysInYear: number; |
| 17357 | readonly monthsInYear: number; |
| 17358 | readonly inLeapYear: boolean; |
| 17359 | readonly offsetNanoseconds: number; |
| 17360 | readonly offset: string; |
| 17361 | readonly epochSeconds: number; |
| 17362 | readonly epochMilliseconds: number; |
| 17363 | readonly epochMicroseconds: bigint; |
| 17364 | readonly epochNanoseconds: bigint; |
| 17365 | equals(other: Temporal.ZonedDateTime | ZonedDateTimeLike | string): boolean; |
| 17366 | with( |
| 17367 | zonedDateTimeLike: ZonedDateTimeLike, |
| 17368 | options?: ZonedDateTimeAssignmentOptions, |
| 17369 | ): Temporal.ZonedDateTime; |
| 17370 | withPlainTime( |
| 17371 | timeLike?: Temporal.PlainTime | PlainTimeLike | string, |
| 17372 | ): Temporal.ZonedDateTime; |
| 17373 | withPlainDate( |
| 17374 | dateLike: Temporal.PlainDate | PlainDateLike | string, |
| 17375 | ): Temporal.ZonedDateTime; |
| 17376 | withCalendar(calendar: CalendarLike): Temporal.ZonedDateTime; |
| 17377 | withTimeZone(timeZone: TimeZoneLike): Temporal.ZonedDateTime; |
| 17378 | add( |
| 17379 | durationLike: Temporal.Duration | DurationLike | string, |
| 17380 | options?: ArithmeticOptions, |
| 17381 | ): Temporal.ZonedDateTime; |
| 17382 | subtract( |
| 17383 | durationLike: Temporal.Duration | DurationLike | string, |
| 17384 | options?: ArithmeticOptions, |
| 17385 | ): Temporal.ZonedDateTime; |
| 17386 | until( |
| 17387 | other: Temporal.ZonedDateTime | ZonedDateTimeLike | string, |
| 17388 | options?: Temporal.DifferenceOptions< |
| 17389 | | "year" |
| 17390 | | "month" |
| 17391 | | "week" |
| 17392 | | "day" |
| 17393 | | "hour" |
| 17394 | | "minute" |
| 17395 | | "second" |
| 17396 | | "millisecond" |
| 17397 | | "microsecond" |
| 17398 | | "nanosecond" |
| 17399 | >, |
| 17400 | ): Temporal.Duration; |
| 17401 | since( |
| 17402 | other: Temporal.ZonedDateTime | ZonedDateTimeLike | string, |
| 17403 | options?: Temporal.DifferenceOptions< |
| 17404 | | "year" |
| 17405 | | "month" |
| 17406 | | "week" |
| 17407 | | "day" |
| 17408 | | "hour" |
| 17409 | | "minute" |
| 17410 | | "second" |
| 17411 | | "millisecond" |
| 17412 | | "microsecond" |
| 17413 | | "nanosecond" |
| 17414 | >, |
| 17415 | ): Temporal.Duration; |
| 17416 | round( |
| 17417 | roundTo: RoundTo< |
| 17418 | | "day" |
| 17419 | | "hour" |
| 17420 | | "minute" |
| 17421 | | "second" |
| 17422 | | "millisecond" |
| 17423 | | "microsecond" |
| 17424 | | "nanosecond" |
| 17425 | >, |
| 17426 | ): Temporal.ZonedDateTime; |
| 17427 | startOfDay(): Temporal.ZonedDateTime; |
| 17428 | toInstant(): Temporal.Instant; |
| 17429 | toPlainDateTime(): Temporal.PlainDateTime; |
| 17430 | toPlainDate(): Temporal.PlainDate; |
| 17431 | toPlainYearMonth(): Temporal.PlainYearMonth; |
| 17432 | toPlainMonthDay(): Temporal.PlainMonthDay; |
| 17433 | toPlainTime(): Temporal.PlainTime; |
| 17434 | getISOFields(): ZonedDateTimeISOFields; |
| 17435 | toLocaleString( |
| 17436 | locales?: string | string[], |
| 17437 | options?: Intl.DateTimeFormatOptions, |
| 17438 | ): string; |
| 17439 | toJSON(): string; |
| 17440 | toString(options?: ZonedDateTimeToStringOptions): string; |
| 17441 | valueOf(): never; |
| 17442 | readonly [Symbol.toStringTag]: "Temporal.ZonedDateTime"; |
| 17443 | } |
| 17444 | |
| 17445 | /** |
| 17446 | * The `Temporal.Now` object has several methods which give information about |
| 17447 | * the current date, time, and time zone. |
| 17448 | * |
| 17449 | * See https://tc39.es/proposal-temporal/docs/now.html for more details. |
| 17450 | * |
| 17451 | * @category Temporal |
| 17452 | * @experimental |
| 17453 | */ |
| 17454 | export const Now: { |
| 17455 | /** |
| 17456 | * Get the exact system date and time as a `Temporal.Instant`. |
| 17457 | * |
| 17458 | * This method gets the current exact system time, without regard to |
| 17459 | * calendar or time zone. This is a good way to get a timestamp for an |
| 17460 | * event, for example. It works like the old-style JavaScript `Date.now()`, |
| 17461 | * but with nanosecond precision instead of milliseconds. |
| 17462 | * |
| 17463 | * Note that a `Temporal.Instant` doesn't know about time zones. For the |
| 17464 | * exact time in a specific time zone, use `Temporal.Now.zonedDateTimeISO` |
| 17465 | * or `Temporal.Now.zonedDateTime`. |
| 17466 | */ |
| 17467 | instant: () => Temporal.Instant; |
| 17468 | |
| 17469 | /** |
| 17470 | * Get the current calendar date and clock time in a specific calendar and |
| 17471 | * time zone. |
| 17472 | * |
| 17473 | * The `calendar` parameter is required. When using the ISO 8601 calendar or |
| 17474 | * if you don't understand the need for or implications of a calendar, then |
| 17475 | * a more ergonomic alternative to this method is |
| 17476 | * `Temporal.Now.zonedDateTimeISO()`. |
| 17477 | * |
| 17478 | * @param {CalendarLike} [calendar] - calendar identifier, or |
| 17479 | * a `Temporal.Calendar` instance, or an object implementing the calendar |
| 17480 | * protocol. |
| 17481 | * @param {TimeZoneLike} [tzLike] - |
| 17482 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17483 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17484 | * object implementing the time zone protocol. If omitted, the environment's |
| 17485 | * current time zone will be used. |
| 17486 | */ |
| 17487 | zonedDateTime: ( |
| 17488 | calendar: CalendarLike, |
| 17489 | tzLike?: TimeZoneLike, |
| 17490 | ) => Temporal.ZonedDateTime; |
| 17491 | |
| 17492 | /** |
| 17493 | * Get the current calendar date and clock time in a specific time zone, |
| 17494 | * using the ISO 8601 calendar. |
| 17495 | * |
| 17496 | * @param {TimeZoneLike} [tzLike] - |
| 17497 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17498 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17499 | * object implementing the time zone protocol. If omitted, the environment's |
| 17500 | * current time zone will be used. |
| 17501 | */ |
| 17502 | zonedDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.ZonedDateTime; |
| 17503 | |
| 17504 | /** |
| 17505 | * Get the current calendar date and clock time in a specific calendar and |
| 17506 | * time zone. |
| 17507 | * |
| 17508 | * The calendar is required. When using the ISO 8601 calendar or if you |
| 17509 | * don't understand the need for or implications of a calendar, then a more |
| 17510 | * ergonomic alternative to this method is `Temporal.Now.plainDateTimeISO`. |
| 17511 | * |
| 17512 | * Note that the `Temporal.PlainDateTime` type does not persist the time zone, |
| 17513 | * but retaining the time zone is required for most time-zone-related use |
| 17514 | * cases. Therefore, it's usually recommended to use |
| 17515 | * `Temporal.Now.zonedDateTimeISO` or `Temporal.Now.zonedDateTime` instead |
| 17516 | * of this function. |
| 17517 | * |
| 17518 | * @param {CalendarLike} [calendar] - calendar identifier, or |
| 17519 | * a `Temporal.Calendar` instance, or an object implementing the calendar |
| 17520 | * protocol. |
| 17521 | * @param {TimeZoneLike} [tzLike] - |
| 17522 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17523 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17524 | * object implementing the time zone protocol. If omitted, |
| 17525 | * the environment's current time zone will be used. |
| 17526 | */ |
| 17527 | plainDateTime: ( |
| 17528 | calendar: CalendarLike, |
| 17529 | tzLike?: TimeZoneLike, |
| 17530 | ) => Temporal.PlainDateTime; |
| 17531 | |
| 17532 | /** |
| 17533 | * Get the current date and clock time in a specific time zone, using the |
| 17534 | * ISO 8601 calendar. |
| 17535 | * |
| 17536 | * Note that the `Temporal.PlainDateTime` type does not persist the time zone, |
| 17537 | * but retaining the time zone is required for most time-zone-related use |
| 17538 | * cases. Therefore, it's usually recommended to use |
| 17539 | * `Temporal.Now.zonedDateTimeISO` instead of this function. |
| 17540 | * |
| 17541 | * @param {TimeZoneLike} [tzLike] - |
| 17542 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17543 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17544 | * object implementing the time zone protocol. If omitted, the environment's |
| 17545 | * current time zone will be used. |
| 17546 | */ |
| 17547 | plainDateTimeISO: (tzLike?: TimeZoneLike) => Temporal.PlainDateTime; |
| 17548 | |
| 17549 | /** |
| 17550 | * Get the current calendar date in a specific calendar and time zone. |
| 17551 | * |
| 17552 | * The calendar is required. When using the ISO 8601 calendar or if you |
| 17553 | * don't understand the need for or implications of a calendar, then a more |
| 17554 | * ergonomic alternative to this method is `Temporal.Now.plainDateISO`. |
| 17555 | * |
| 17556 | * @param {CalendarLike} [calendar] - calendar identifier, or |
| 17557 | * a `Temporal.Calendar` instance, or an object implementing the calendar |
| 17558 | * protocol. |
| 17559 | * @param {TimeZoneLike} [tzLike] - |
| 17560 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17561 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17562 | * object implementing the time zone protocol. If omitted, |
| 17563 | * the environment's current time zone will be used. |
| 17564 | */ |
| 17565 | plainDate: ( |
| 17566 | calendar: CalendarLike, |
| 17567 | tzLike?: TimeZoneLike, |
| 17568 | ) => Temporal.PlainDate; |
| 17569 | |
| 17570 | /** |
| 17571 | * Get the current date in a specific time zone, using the ISO 8601 |
| 17572 | * calendar. |
| 17573 | * |
| 17574 | * @param {TimeZoneLike} [tzLike] - |
| 17575 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17576 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17577 | * object implementing the time zone protocol. If omitted, the environment's |
| 17578 | * current time zone will be used. |
| 17579 | */ |
| 17580 | plainDateISO: (tzLike?: TimeZoneLike) => Temporal.PlainDate; |
| 17581 | |
| 17582 | /** |
| 17583 | * Get the current clock time in a specific time zone, using the ISO 8601 calendar. |
| 17584 | * |
| 17585 | * @param {TimeZoneLike} [tzLike] - |
| 17586 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone identifier} |
| 17587 | * string (e.g. `'Europe/London'`), `Temporal.TimeZone` instance, or an |
| 17588 | * object implementing the time zone protocol. If omitted, the environment's |
| 17589 | * current time zone will be used. |
| 17590 | */ |
| 17591 | plainTimeISO: (tzLike?: TimeZoneLike) => Temporal.PlainTime; |
| 17592 | |
| 17593 | /** |
| 17594 | * Get the identifier of the environment's current time zone. |
| 17595 | * |
| 17596 | * This method gets the identifier of the current system time zone. This |
| 17597 | * will usually be a named |
| 17598 | * {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones|IANA time zone}. |
| 17599 | */ |
| 17600 | timeZoneId: () => string; |
| 17601 | |
| 17602 | readonly [Symbol.toStringTag]: "Temporal.Now"; |
| 17603 | }; |
| 17604 | } |
| 17605 | |
| 17606 | /** |
| 17607 | * @category Temporal |
| 17608 | * @experimental |
| 17609 | */ |
| 17610 | declare interface Date { |
| 17611 | toTemporalInstant(): Temporal.Instant; |
| 17612 | } |
| 17613 | |
| 17614 | /** |
| 17615 | * @category Intl |
| 17616 | * @experimental |
| 17617 | */ |
| 17618 | declare namespace Intl { |
| 17619 | /** |
| 17620 | * @category Intl |
| 17621 | * @experimental |
| 17622 | */ |
| 17623 | export type Formattable = |
| 17624 | | Date |
| 17625 | | Temporal.Instant |
| 17626 | | Temporal.ZonedDateTime |
| 17627 | | Temporal.PlainDate |
| 17628 | | Temporal.PlainTime |
| 17629 | | Temporal.PlainDateTime |
| 17630 | | Temporal.PlainYearMonth |
| 17631 | | Temporal.PlainMonthDay; |
| 17632 | |
| 17633 | /** |
| 17634 | * @category Intl |
| 17635 | * @experimental |
| 17636 | */ |
| 17637 | export interface DateTimeFormatRangePart { |
| 17638 | source: "shared" | "startRange" | "endRange"; |
| 17639 | } |
| 17640 | |
| 17641 | /** |
| 17642 | * @category Intl |
| 17643 | * @experimental |
| 17644 | */ |
| 17645 | export interface DateTimeFormat { |
| 17646 | /** |
| 17647 | * Format a date into a string according to the locale and formatting |
| 17648 | * options of this `Intl.DateTimeFormat` object. |
| 17649 | * |
| 17650 | * @param date The date to format. |
| 17651 | */ |
| 17652 | format(date?: Formattable | number): string; |
| 17653 | |
| 17654 | /** |
| 17655 | * Allow locale-aware formatting of strings produced by |
| 17656 | * `Intl.DateTimeFormat` formatters. |
| 17657 | * |
| 17658 | * @param date The date to format. |
| 17659 | */ |
| 17660 | formatToParts( |
| 17661 | date?: Formattable | number, |
| 17662 | ): globalThis.Intl.DateTimeFormatPart[]; |
| 17663 | |
| 17664 | /** |
| 17665 | * Format a date range in the most concise way based on the locale and |
| 17666 | * options provided when instantiating this `Intl.DateTimeFormat` object. |
| 17667 | * |
| 17668 | * @param startDate The start date of the range to format. |
| 17669 | * @param endDate The start date of the range to format. Must be the same |
| 17670 | * type as `startRange`. |
| 17671 | */ |
| 17672 | formatRange<T extends Formattable>(startDate: T, endDate: T): string; |
| 17673 | formatRange(startDate: Date | number, endDate: Date | number): string; |
| 17674 | |
| 17675 | /** |
| 17676 | * Allow locale-aware formatting of tokens representing each part of the |
| 17677 | * formatted date range produced by `Intl.DateTimeFormat` formatters. |
| 17678 | * |
| 17679 | * @param startDate The start date of the range to format. |
| 17680 | * @param endDate The start date of the range to format. Must be the same |
| 17681 | * type as `startRange`. |
| 17682 | */ |
| 17683 | formatRangeToParts<T extends Formattable>( |
| 17684 | startDate: T, |
| 17685 | endDate: T, |
| 17686 | ): DateTimeFormatRangePart[]; |
| 17687 | formatRangeToParts( |
| 17688 | startDate: Date | number, |
| 17689 | endDate: Date | number, |
| 17690 | ): DateTimeFormatRangePart[]; |
| 17691 | } |
| 17692 | |
| 17693 | /** |
| 17694 | * @category Intl |
| 17695 | * @experimental |
| 17696 | */ |
| 17697 | export interface DateTimeFormatOptions { |
| 17698 | // TODO: remove the props below after TS lib declarations are updated |
| 17699 | dayPeriod?: "narrow" | "short" | "long"; |
| 17700 | dateStyle?: "full" | "long" | "medium" | "short"; |
| 17701 | timeStyle?: "full" | "long" | "medium" | "short"; |
| 17702 | } |
| 17703 | } |
| 17704 | |
| 17705 | /** |
| 17706 | * A typed array of 16-bit float values. The contents are initialized to 0. If the requested number |
| 17707 | * of bytes could not be allocated an exception is raised. |
| 17708 | * |
| 17709 | * @category Platform |
| 17710 | * @experimental |
| 17711 | */ |
| 17712 | declare interface Float16Array { |
| 17713 | /** |
| 17714 | * The size in bytes of each element in the array. |
| 17715 | */ |
| 17716 | readonly BYTES_PER_ELEMENT: number; |
| 17717 | |
| 17718 | /** |
| 17719 | * The ArrayBuffer instance referenced by the array. |
| 17720 | */ |
| 17721 | readonly buffer: ArrayBufferLike; |
| 17722 | |
| 17723 | /** |
| 17724 | * The length in bytes of the array. |
| 17725 | */ |
| 17726 | readonly byteLength: number; |
| 17727 | |
| 17728 | /** |
| 17729 | * The offset in bytes of the array. |
| 17730 | */ |
| 17731 | readonly byteOffset: number; |
| 17732 | |
| 17733 | /** |
| 17734 | * Returns the this object after copying a section of the array identified by start and end |
| 17735 | * to the same array starting at position target |
| 17736 | * @param target If target is negative, it is treated as length+target where length is the |
| 17737 | * length of the array. |
| 17738 | * @param start If start is negative, it is treated as length+start. If end is negative, it |
| 17739 | * is treated as length+end. |
| 17740 | * @param end If not specified, length of the this object is used as its default value. |
| 17741 | */ |
| 17742 | copyWithin(target: number, start: number, end?: number): this; |
| 17743 | |
| 17744 | /** |
| 17745 | * Determines whether all the members of an array satisfy the specified test. |
| 17746 | * @param predicate A function that accepts up to three arguments. The every method calls |
| 17747 | * the predicate function for each element in the array until the predicate returns a value |
| 17748 | * which is coercible to the Boolean value false, or until the end of the array. |
| 17749 | * @param thisArg An object to which the this keyword can refer in the predicate function. |
| 17750 | * If thisArg is omitted, undefined is used as the this value. |
| 17751 | */ |
| 17752 | every( |
| 17753 | predicate: (value: number, index: number, array: Float16Array) => unknown, |
| 17754 | thisArg?: any, |
| 17755 | ): boolean; |
| 17756 | |
| 17757 | /** |
| 17758 | * Changes all array elements from `start` to `end` index to a static `value` and returns the modified array |
| 17759 | * @param value value to fill array section with |
| 17760 | * @param start index to start filling the array at. If start is negative, it is treated as |
| 17761 | * length+start where length is the length of the array. |
| 17762 | * @param end index to stop filling the array at. If end is negative, it is treated as |
| 17763 | * length+end. |
| 17764 | */ |
| 17765 | fill(value: number, start?: number, end?: number): this; |
| 17766 | |
| 17767 | /** |
| 17768 | * Returns the elements of an array that meet the condition specified in a callback function. |
| 17769 | * @param predicate A function that accepts up to three arguments. The filter method calls |
| 17770 | * the predicate function one time for each element in the array. |
| 17771 | * @param thisArg An object to which the this keyword can refer in the predicate function. |
| 17772 | * If thisArg is omitted, undefined is used as the this value. |
| 17773 | */ |
| 17774 | filter( |
| 17775 | predicate: (value: number, index: number, array: Float16Array) => any, |
| 17776 | thisArg?: any, |
| 17777 | ): Float16Array; |
| 17778 | |
| 17779 | /** |
| 17780 | * Returns the value of the first element in the array where predicate is true, and undefined |
| 17781 | * otherwise. |
| 17782 | * @param predicate find calls predicate once for each element of the array, in ascending |
| 17783 | * order, until it finds one where predicate returns true. If such an element is found, find |
| 17784 | * immediately returns that element value. Otherwise, find returns undefined. |
| 17785 | * @param thisArg If provided, it will be used as the this value for each invocation of |
| 17786 | * predicate. If it is not provided, undefined is used instead. |
| 17787 | */ |
| 17788 | find( |
| 17789 | predicate: (value: number, index: number, obj: Float16Array) => boolean, |
| 17790 | thisArg?: any, |
| 17791 | ): number | undefined; |
| 17792 | |
| 17793 | /** |
| 17794 | * Returns the index of the first element in the array where predicate is true, and -1 |
| 17795 | * otherwise. |
| 17796 | * @param predicate find calls predicate once for each element of the array, in ascending |
| 17797 | * order, until it finds one where predicate returns true. If such an element is found, |
| 17798 | * findIndex immediately returns that element index. Otherwise, findIndex returns -1. |
| 17799 | * @param thisArg If provided, it will be used as the this value for each invocation of |
| 17800 | * predicate. If it is not provided, undefined is used instead. |
| 17801 | */ |
| 17802 | findIndex( |
| 17803 | predicate: (value: number, index: number, obj: Float16Array) => boolean, |
| 17804 | thisArg?: any, |
| 17805 | ): number; |
| 17806 | |
| 17807 | /** |
| 17808 | * Performs the specified action for each element in an array. |
| 17809 | * @param callbackfn A function that accepts up to three arguments. forEach calls the |
| 17810 | * callbackfn function one time for each element in the array. |
| 17811 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. |
| 17812 | * If thisArg is omitted, undefined is used as the this value. |
| 17813 | */ |
| 17814 | forEach( |
| 17815 | callbackfn: (value: number, index: number, array: Float16Array) => void, |
| 17816 | thisArg?: any, |
| 17817 | ): void; |
| 17818 | |
| 17819 | /** |
| 17820 | * Returns the index of the first occurrence of a value in an array. |
| 17821 | * @param searchElement The value to locate in the array. |
| 17822 | * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the |
| 17823 | * search starts at index 0. |
| 17824 | */ |
| 17825 | indexOf(searchElement: number, fromIndex?: number): number; |
| 17826 | |
| 17827 | /** |
| 17828 | * Adds all the elements of an array separated by the specified separator string. |
| 17829 | * @param separator A string used to separate one element of an array from the next in the |
| 17830 | * resulting String. If omitted, the array elements are separated with a comma. |
| 17831 | */ |
| 17832 | join(separator?: string): string; |
| 17833 | |
| 17834 | /** |
| 17835 | * Returns the index of the last occurrence of a value in an array. |
| 17836 | * @param searchElement The value to locate in the array. |
| 17837 | * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the |
| 17838 | * search starts at index 0. |
| 17839 | */ |
| 17840 | lastIndexOf(searchElement: number, fromIndex?: number): number; |
| 17841 | |
| 17842 | /** |
| 17843 | * The length of the array. |
| 17844 | */ |
| 17845 | readonly length: number; |
| 17846 | |
| 17847 | /** |
| 17848 | * Calls a defined callback function on each element of an array, and returns an array that |
| 17849 | * contains the results. |
| 17850 | * @param callbackfn A function that accepts up to three arguments. The map method calls the |
| 17851 | * callbackfn function one time for each element in the array. |
| 17852 | * @param thisArg An object to which the this keyword can refer in the callbackfn function. |
| 17853 | * If thisArg is omitted, undefined is used as the this value. |
| 17854 | */ |
| 17855 | map( |
| 17856 | callbackfn: (value: number, index: number, array: Float16Array) => number, |
| 17857 | thisArg?: any, |
| 17858 | ): Float16Array; |
| 17859 | |
| 17860 | /** |
| 17861 | * Calls the specified callback function for all the elements in an array. The return value of |
| 17862 | * the callback function is the accumulated result, and is provided as an argument in the next |
| 17863 | * call to the callback function. |
| 17864 | * @param callbackfn A function that accepts up to four arguments. The reduce method calls the |
| 17865 | * callbackfn function one time for each element in the array. |
| 17866 | * @param initialValue If initialValue is specified, it is used as the initial value to start |
| 17867 | * the accumulation. The first call to the callbackfn function provides this value as an argument |
| 17868 | * instead of an array value. |
| 17869 | */ |
| 17870 | reduce( |
| 17871 | callbackfn: ( |
| 17872 | previousValue: number, |
| 17873 | currentValue: number, |
| 17874 | currentIndex: number, |
| 17875 | array: Float16Array, |
| 17876 | ) => number, |
| 17877 | ): number; |
| 17878 | reduce( |
| 17879 | callbackfn: ( |
| 17880 | previousValue: number, |
| 17881 | currentValue: number, |
| 17882 | currentIndex: number, |
| 17883 | array: Float16Array, |
| 17884 | ) => number, |
| 17885 | initialValue: number, |
| 17886 | ): number; |
| 17887 | |
| 17888 | /** |
| 17889 | * Calls the specified callback function for all the elements in an array. The return value of |
| 17890 | * the callback function is the accumulated result, and is provided as an argument in the next |
| 17891 | * call to the callback function. |
| 17892 | * @param callbackfn A function that accepts up to four arguments. The reduce method calls the |
| 17893 | * callbackfn function one time for each element in the array. |
| 17894 | * @param initialValue If initialValue is specified, it is used as the initial value to start |
| 17895 | * the accumulation. The first call to the callbackfn function provides this value as an argument |
| 17896 | * instead of an array value. |
| 17897 | */ |
| 17898 | reduce<U>( |
| 17899 | callbackfn: ( |
| 17900 | previousValue: U, |
| 17901 | currentValue: number, |
| 17902 | currentIndex: number, |
| 17903 | array: Float16Array, |
| 17904 | ) => U, |
| 17905 | initialValue: U, |
| 17906 | ): U; |
| 17907 | |
| 17908 | /** |
| 17909 | * Calls the specified callback function for all the elements in an array, in descending order. |
| 17910 | * The return value of the callback function is the accumulated result, and is provided as an |
| 17911 | * argument in the next call to the callback function. |
| 17912 | * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls |
| 17913 | * the callbackfn function one time for each element in the array. |
| 17914 | * @param initialValue If initialValue is specified, it is used as the initial value to start |
| 17915 | * the accumulation. The first call to the callbackfn function provides this value as an |
| 17916 | * argument instead of an array value. |
| 17917 | */ |
| 17918 | reduceRight( |
| 17919 | callbackfn: ( |
| 17920 | previousValue: number, |
| 17921 | currentValue: number, |
| 17922 | currentIndex: number, |
| 17923 | array: Float16Array, |
| 17924 | ) => number, |
| 17925 | ): number; |
| 17926 | reduceRight( |
| 17927 | callbackfn: ( |
| 17928 | previousValue: number, |
| 17929 | currentValue: number, |
| 17930 | currentIndex: number, |
| 17931 | array: Float16Array, |
| 17932 | ) => number, |
| 17933 | initialValue: number, |
| 17934 | ): number; |
| 17935 | |
| 17936 | /** |
| 17937 | * Calls the specified callback function for all the elements in an array, in descending order. |
| 17938 | * The return value of the callback function is the accumulated result, and is provided as an |
| 17939 | * argument in the next call to the callback function. |
| 17940 | * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls |
| 17941 | * the callbackfn function one time for each element in the array. |
| 17942 | * @param initialValue If initialValue is specified, it is used as the initial value to start |
| 17943 | * the accumulation. The first call to the callbackfn function provides this value as an argument |
| 17944 | * instead of an array value. |
| 17945 | */ |
| 17946 | reduceRight<U>( |
| 17947 | callbackfn: ( |
| 17948 | previousValue: U, |
| 17949 | currentValue: number, |
| 17950 | currentIndex: number, |
| 17951 | array: Float16Array, |
| 17952 | ) => U, |
| 17953 | initialValue: U, |
| 17954 | ): U; |
| 17955 | |
| 17956 | /** |
| 17957 | * Reverses the elements in an Array. |
| 17958 | */ |
| 17959 | reverse(): Float16Array; |
| 17960 | |
| 17961 | /** |
| 17962 | * Sets a value or an array of values. |
| 17963 | * @param array A typed or untyped array of values to set. |
| 17964 | * @param offset The index in the current array at which the values are to be written. |
| 17965 | */ |
| 17966 | set(array: ArrayLike<number>, offset?: number): void; |
| 17967 | |
| 17968 | /** |
| 17969 | * Returns a section of an array. |
| 17970 | * @param start The beginning of the specified portion of the array. |
| 17971 | * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'. |
| 17972 | */ |
| 17973 | slice(start?: number, end?: number): Float16Array; |
| 17974 | |
| 17975 | /** |
| 17976 | * Determines whether the specified callback function returns true for any element of an array. |
| 17977 | * @param predicate A function that accepts up to three arguments. The some method calls |
| 17978 | * the predicate function for each element in the array until the predicate returns a value |
| 17979 | * which is coercible to the Boolean value true, or until the end of the array. |
| 17980 | * @param thisArg An object to which the this keyword can refer in the predicate function. |
| 17981 | * If thisArg is omitted, undefined is used as the this value. |
| 17982 | */ |
| 17983 | some( |
| 17984 | predicate: (value: number, index: number, array: Float16Array) => unknown, |
| 17985 | thisArg?: any, |
| 17986 | ): boolean; |
| 17987 | |
| 17988 | /** |
| 17989 | * Sorts an array. |
| 17990 | * @param compareFn Function used to determine the order of the elements. It is expected to return |
| 17991 | * a negative value if first argument is less than second argument, zero if they're equal and a positive |
| 17992 | * value otherwise. If omitted, the elements are sorted in ascending order. |
| 17993 | * ```ts |
| 17994 | * [11,2,22,1].sort((a, b) => a - b) |
| 17995 | * ``` |
| 17996 | */ |
| 17997 | sort(compareFn?: (a: number, b: number) => number): this; |
| 17998 | |
| 17999 | /** |
| 18000 | * Gets a new Float16Array view of the ArrayBuffer store for this array, referencing the elements |
| 18001 | * at begin, inclusive, up to end, exclusive. |
| 18002 | * @param begin The index of the beginning of the array. |
| 18003 | * @param end The index of the end of the array. |
| 18004 | */ |
| 18005 | subarray(begin?: number, end?: number): Float16Array; |
| 18006 | |
| 18007 | /** |
| 18008 | * Converts a number to a string by using the current locale. |
| 18009 | */ |
| 18010 | toLocaleString(): string; |
| 18011 | |
| 18012 | /** |
| 18013 | * Returns a string representation of an array. |
| 18014 | */ |
| 18015 | toString(): string; |
| 18016 | |
| 18017 | /** Returns the primitive value of the specified object. */ |
| 18018 | valueOf(): Float16Array; |
| 18019 | |
| 18020 | [index: number]: number; |
| 18021 | } |
| 18022 | |
| 18023 | /** |
| 18024 | * @category Platform |
| 18025 | * @experimental |
| 18026 | */ |
| 18027 | declare interface Float16ArrayConstructor { |
| 18028 | readonly prototype: Float16Array; |
| 18029 | new (length: number): Float16Array; |
| 18030 | new (array: ArrayLike<number> | ArrayBufferLike): Float16Array; |
| 18031 | new ( |
| 18032 | buffer: ArrayBufferLike, |
| 18033 | byteOffset?: number, |
| 18034 | length?: number, |
| 18035 | ): Float16Array; |
| 18036 | |
| 18037 | /** |
| 18038 | * The size in bytes of each element in the array. |
| 18039 | */ |
| 18040 | readonly BYTES_PER_ELEMENT: number; |
| 18041 | |
| 18042 | /** |
| 18043 | * Returns a new array from a set of elements. |
| 18044 | * @param items A set of elements to include in the new array object. |
| 18045 | */ |
| 18046 | of(...items: number[]): Float16Array; |
| 18047 | |
| 18048 | /** |
| 18049 | * Creates an array from an array-like or iterable object. |
| 18050 | * @param arrayLike An array-like or iterable object to convert to an array. |
| 18051 | */ |
| 18052 | from(arrayLike: ArrayLike<number>): Float16Array; |
| 18053 | |
| 18054 | /** |
| 18055 | * Creates an array from an array-like or iterable object. |
| 18056 | * @param arrayLike An array-like or iterable object to convert to an array. |
| 18057 | * @param mapfn A mapping function to call on every element of the array. |
| 18058 | * @param thisArg Value of 'this' used to invoke the mapfn. |
| 18059 | */ |
| 18060 | from<T>( |
| 18061 | arrayLike: ArrayLike<T>, |
| 18062 | mapfn: (v: T, k: number) => number, |
| 18063 | thisArg?: any, |
| 18064 | ): Float16Array; |
| 18065 | } |
| 18066 | /** |
| 18067 | * @category Platform |
| 18068 | * @experimental |
| 18069 | */ |
| 18070 | declare var Float16Array: Float16ArrayConstructor; |
| 18071 | |
| 18072 | /** |
| 18073 | * @category Platform |
| 18074 | * @experimental |
| 18075 | */ |
| 18076 | declare interface Float16 { |
| 18077 | [Symbol.iterator](): IterableIterator<number>; |
| 18078 | /** |
| 18079 | * Returns an array of key, value pairs for every entry in the array |
| 18080 | */ |
| 18081 | entries(): IterableIterator<[number, number]>; |
| 18082 | /** |
| 18083 | * Returns an list of keys in the array |
| 18084 | */ |
| 18085 | keys(): IterableIterator<number>; |
| 18086 | /** |
| 18087 | * Returns an list of values in the array |
| 18088 | */ |
| 18089 | values(): IterableIterator<number>; |
| 18090 | } |
| 18091 | |
| 18092 | /** |
| 18093 | * @category Platform |
| 18094 | * @experimental |
| 18095 | */ |
| 18096 | declare interface Float16Constructor { |
| 18097 | new (elements: Iterable<number>): Float16; |
| 18098 | |
| 18099 | /** |
| 18100 | * Creates an array from an array-like or iterable object. |
| 18101 | * @param arrayLike An array-like or iterable object to convert to an array. |
| 18102 | * @param mapfn A mapping function to call on every element of the array. |
| 18103 | * @param thisArg Value of 'this' used to invoke the mapfn. |
| 18104 | */ |
| 18105 | from( |
| 18106 | arrayLike: Iterable<number>, |
| 18107 | mapfn?: (v: number, k: number) => number, |
| 18108 | thisArg?: any, |
| 18109 | ): Float16; |
| 18110 | } |
| 18111 | |
| 18112 | /** |
| 18113 | * @category Platform |
| 18114 | * @experimental |
| 18115 | */ |
| 18116 | declare interface Float16Array { |
| 18117 | readonly [Symbol.toStringTag]: "Float16Array"; |
| 18118 | } |
| 18119 | |
| 18120 | /** |
| 18121 | * @category Platform |
| 18122 | * @experimental |
| 18123 | */ |
| 18124 | declare interface Float16Array { |
| 18125 | /** |
| 18126 | * Determines whether an array includes a certain element, returning true or false as appropriate. |
| 18127 | * @param searchElement The element to search for. |
| 18128 | * @param fromIndex The position in this array at which to begin searching for searchElement. |
| 18129 | */ |
| 18130 | includes(searchElement: number, fromIndex?: number): boolean; |
| 18131 | } |
| 18132 | |
| 18133 | /** |
| 18134 | * @category Platform |
| 18135 | * @experimental |
| 18136 | */ |
| 18137 | declare interface Float16ArrayConstructor { |
| 18138 | new (): Float16Array; |
| 18139 | } |
| 18140 | |
| 18141 | /** |
| 18142 | * @category Platform |
| 18143 | * @experimental |
| 18144 | */ |
| 18145 | declare interface Float16Array { |
| 18146 | /** |
| 18147 | * Returns the item located at the specified index. |
| 18148 | * @param index The zero-based index of the desired code unit. A negative index will count back from the last item. |
| 18149 | */ |
| 18150 | at(index: number): number | undefined; |
| 18151 | } |
| 18152 | |
| 18153 | /** |
| 18154 | * @category Platform |
| 18155 | * @experimental |
| 18156 | */ |
| 18157 | declare interface Float16Array { |
| 18158 | /** |
| 18159 | * Returns the value of the last element in the array where predicate is true, and undefined |
| 18160 | * otherwise. |
| 18161 | * @param predicate findLast calls predicate once for each element of the array, in descending |
| 18162 | * order, until it finds one where predicate returns true. If such an element is found, findLast |
| 18163 | * immediately returns that element value. Otherwise, findLast returns undefined. |
| 18164 | * @param thisArg If provided, it will be used as the this value for each invocation of |
| 18165 | * predicate. If it is not provided, undefined is used instead. |
| 18166 | */ |
| 18167 | findLast<S extends number>( |
| 18168 | predicate: ( |
| 18169 | value: number, |
| 18170 | index: number, |
| 18171 | array: Float16Array, |
| 18172 | ) => value is S, |
| 18173 | thisArg?: any, |
| 18174 | ): S | undefined; |
| 18175 | findLast( |
| 18176 | predicate: ( |
| 18177 | value: number, |
| 18178 | index: number, |
| 18179 | array: Float16Array, |
| 18180 | ) => unknown, |
| 18181 | thisArg?: any, |
| 18182 | ): number | undefined; |
| 18183 | |
| 18184 | /** |
| 18185 | * Returns the index of the last element in the array where predicate is true, and -1 |
| 18186 | * otherwise. |
| 18187 | * @param predicate findLastIndex calls predicate once for each element of the array, in descending |
| 18188 | * order, until it finds one where predicate returns true. If such an element is found, |
| 18189 | * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. |
| 18190 | * @param thisArg If provided, it will be used as the this value for each invocation of |
| 18191 | * predicate. If it is not provided, undefined is used instead. |
| 18192 | */ |
| 18193 | findLastIndex( |
| 18194 | predicate: ( |
| 18195 | value: number, |
| 18196 | index: number, |
| 18197 | array: Float16Array, |
| 18198 | ) => unknown, |
| 18199 | thisArg?: any, |
| 18200 | ): number; |
| 18201 | |
| 18202 | /** |
| 18203 | * Copies the array and returns the copy with the elements in reverse order. |
| 18204 | */ |
| 18205 | toReversed(): Float16Array; |
| 18206 | |
| 18207 | /** |
| 18208 | * Copies and sorts the array. |
| 18209 | * @param compareFn Function used to determine the order of the elements. It is expected to return |
| 18210 | * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive |
| 18211 | * value otherwise. If omitted, the elements are sorted in ascending order. |
| 18212 | * ```ts |
| 18213 | * const myNums = Float16Array.from([11.25, 2, -22.5, 1]); |
| 18214 | * myNums.toSorted((a, b) => a - b) // Float16Array(4) [-22.5, 1, 2, 11.5] |
| 18215 | * ``` |
| 18216 | */ |
| 18217 | toSorted(compareFn?: (a: number, b: number) => number): Float16Array; |
| 18218 | |
| 18219 | /** |
| 18220 | * Copies the array and inserts the given number at the provided index. |
| 18221 | * @param index The index of the value to overwrite. If the index is |
| 18222 | * negative, then it replaces from the end of the array. |
| 18223 | * @param value The value to insert into the copied array. |
| 18224 | * @returns A copy of the original array with the inserted value. |
| 18225 | */ |
| 18226 | with(index: number, value: number): Float16Array; |
| 18227 | } |
| 18228 | |
| 18229 | /** |
| 18230 | * @category Platform |
| 18231 | * @experimental |
| 18232 | */ |
| 18233 | declare interface DataView { |
| 18234 | /** |
| 18235 | * Gets the Float16 value at the specified byte offset from the start of the view. There is |
| 18236 | * no alignment constraint; multi-byte values may be fetched from any offset. |
| 18237 | * @param byteOffset The place in the buffer at which the value should be retrieved. |
| 18238 | * @param littleEndian If false or undefined, a big-endian value should be read. |
| 18239 | */ |
| 18240 | getFloat16(byteOffset: number, littleEndian?: boolean): number; |
| 18241 | |
| 18242 | /** |
| 18243 | * Stores an Float16 value at the specified byte offset from the start of the view. |
| 18244 | * @param byteOffset The place in the buffer at which the value should be set. |
| 18245 | * @param value The value to set. |
| 18246 | * @param littleEndian If false or undefined, a big-endian value should be written. |
| 18247 | */ |
| 18248 | setFloat16(byteOffset: number, value: number, littleEndian?: boolean): void; |
| 18249 | } |