diff --git a/cli/build.rs b/cli/build.rs index 7fc4b718d5..f8e348f527 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -71,9 +71,14 @@ fn main() { let snapshot_path = o.join("COMPILER_SNAPSHOT.bin"); let mut custom_libs: HashMap = HashMap::new(); custom_libs.insert( - "lib.deno_runtime.d.ts".to_string(), - c.join("js/lib.deno_runtime.d.ts"), + "lib.deno_main.d.ts".to_string(), + c.join("js/lib.deno_main.d.ts"), ); + custom_libs.insert( + "lib.deno_worker.d.ts".to_string(), + c.join("js/lib.deno_worker.d.ts"), + ); + custom_libs.insert("lib.deno.d.ts".to_string(), c.join("js/lib.deno.d.ts")); let main_module_name = deno_typescript::compile_bundle(&bundle_path, root_names) diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 3adf924956..b95a811e76 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -165,6 +165,7 @@ fn req( let j = match (compiler_config.path, compiler_config.content) { (Some(config_path), Some(config_data)) => json!({ "type": request_type as i32, + "target": "main", "rootNames": root_names, "outFile": out_file, "bundle": bundle, @@ -173,6 +174,7 @@ fn req( }), _ => json!({ "type": request_type as i32, + "target": "main", "rootNames": root_names, "outFile": out_file, "bundle": bundle, @@ -617,6 +619,7 @@ pub fn runtime_compile_async( ) -> Pin> { let req_msg = json!({ "type": msg::CompilerRequestType::RuntimeCompile as i32, + "target": "runtime", "rootName": root_name, "sources": sources, "options": options, diff --git a/cli/js.rs b/cli/js.rs index 8f57adb4db..57516a239e 100644 --- a/cli/js.rs +++ b/cli/js.rs @@ -16,7 +16,8 @@ pub static COMPILER_SNAPSHOT_MAP: &[u8] = pub static COMPILER_SNAPSHOT_DTS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.d.ts")); -pub static DENO_RUNTIME: &str = include_str!("js/lib.deno_runtime.d.ts"); +pub static DENO_NS_LIB: &str = include_str!("js/lib.deno.d.ts"); +pub static DENO_MAIN_LIB: &str = include_str!("js/lib.deno_main.d.ts"); #[test] fn cli_snapshot() { diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 54861f7138..2807422e2f 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -9,6 +9,7 @@ import { TranspileOnlyResult } from "./compiler_api.ts"; import { oldProgram } from "./compiler_bootstrap.ts"; import { setRootExports } from "./compiler_bundler.ts"; import { + CompilerHostTarget, defaultBundlerOptions, defaultRuntimeCompileOptions, defaultTranspileOptions, @@ -42,6 +43,7 @@ const self = globalThis; interface CompilerRequestCompile { type: CompilerRequestType.Compile; + target: CompilerHostTarget; rootNames: string[]; // TODO(ry) add compiler config to this interface. // options: ts.CompilerOptions; @@ -53,6 +55,7 @@ interface CompilerRequestCompile { interface CompilerRequestRuntimeCompile { type: CompilerRequestType.RuntimeCompile; + target: CompilerHostTarget; rootName: string; sources?: Record; bundle?: boolean; @@ -100,7 +103,14 @@ self.bootstrapTsCompiler = function tsCompilerMain(): void { // `Compile` are requests from the internals to Deno, generated by both // the `run` and `bundle` sub command. case CompilerRequestType.Compile: { - const { bundle, config, configPath, outFile, rootNames } = request; + const { + bundle, + config, + configPath, + outFile, + rootNames, + target + } = request; util.log(">>> compile start", { rootNames, type: CompilerRequestType[request.type] @@ -129,7 +139,11 @@ self.bootstrapTsCompiler = function tsCompilerMain(): void { }; const writeFile = createWriteFile(state); - const host = (state.host = new Host({ bundle, writeFile })); + const host = (state.host = new Host({ + bundle, + target, + writeFile + })); let diagnostics: readonly ts.Diagnostic[] | undefined; // if there is a configuration supplied, we need to parse that @@ -189,7 +203,7 @@ self.bootstrapTsCompiler = function tsCompilerMain(): void { // `RuntimeCompile` are requests from a runtime user, both compiles and // bundles. The process is similar to a request from the privileged // side, but also returns the output to the on message. - const { rootName, sources, options, bundle } = request; + const { rootName, sources, options, bundle, target } = request; util.log(">>> runtime compile start", { rootName, @@ -216,7 +230,11 @@ self.bootstrapTsCompiler = function tsCompilerMain(): void { }; const writeFile = createWriteFile(state); - const host = (state.host = new Host({ bundle, writeFile })); + const host = (state.host = new Host({ + bundle, + target, + writeFile + })); const compilerOptions = [defaultRuntimeCompileOptions]; if (options) { compilerOptions.push(convertCompilerOptions(options)); diff --git a/cli/js/compiler_bootstrap.ts b/cli/js/compiler_bootstrap.ts index 31e5774bf6..a5c7eb029d 100644 --- a/cli/js/compiler_bootstrap.ts +++ b/cli/js/compiler_bootstrap.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { ASSETS, Host } from "./compiler_host.ts"; +import { ASSETS, CompilerHostTarget, Host } from "./compiler_host.ts"; import { core } from "./core.ts"; import * as dispatch from "./dispatch.ts"; import { getAsset } from "./compiler_util.ts"; @@ -15,9 +15,28 @@ for (const [name, opId] of Object.entries(ops)) { (dispatch as any)[opName] = opId; } -const host = new Host({ writeFile(): void {} }); +const host = new Host({ + target: CompilerHostTarget.Main, + writeFile(): void {} +}); const options = host.getCompilationSettings(); +// This is a hacky way of adding our libs to the libs available in TypeScript() +// as these are internal APIs of TypeScript which maintain valid libs +/* eslint-disable @typescript-eslint/no-explicit-any */ +(ts as any).libs.push("deno_main", "deno_worker", "deno"); +(ts as any).libMap.set("deno_main", "lib.deno_main.d.ts"); +(ts as any).libMap.set("deno_worker", "lib.deno_worker.d.ts"); +(ts as any).libMap.set("deno", "lib.deno.d.ts"); +/* eslint-enable @typescript-eslint/no-explicit-any */ + +// this pre-populates the cache at snapshot time of our library files, so they +// are available in the future when needed. +host.getSourceFile(`${ASSETS}/lib.deno_main.d.ts`, ts.ScriptTarget.ESNext); +host.getSourceFile(`${ASSETS}/lib.deno_worker.d.ts`, ts.ScriptTarget.ESNext); +host.getSourceFile(`${ASSETS}/lib.deno.d.ts`, ts.ScriptTarget.ESNext); +host.getSourceFile(`${ASSETS}/lib.webworker.d.ts`, ts.ScriptTarget.ESNext); + /** Used to generate the foundational AST for all other compilations, so it can * be cached as part of the snapshot and available to speed up startup */ export const oldProgram = ts.createProgram({ diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts index bff16757b2..619ce702a7 100644 --- a/cli/js/compiler_host.ts +++ b/cli/js/compiler_host.ts @@ -6,8 +6,20 @@ import { cwd } from "./dir.ts"; import { assert, notImplemented } from "./util.ts"; import * as util from "./util.ts"; +/** Specifies the target that the host should use to inform the TypeScript + * compiler of what types should be used to validate the program against. */ +export enum CompilerHostTarget { + /** The main isolate library, where the main program runs. */ + Main = "main", + /** The runtime API library. */ + Runtime = "runtime", + /** The worker isolate library, where worker programs run. */ + Worker = "worker" +} + export interface CompilerHostOptions { bundle?: boolean; + target: CompilerHostTarget; writeFile: WriteFileCallback; } @@ -124,6 +136,8 @@ const ignoredCompilerOptions: readonly string[] = [ export class Host implements ts.CompilerHost { private readonly _options = defaultCompileOptions; + private _target: CompilerHostTarget; + private _writeFile: WriteFileCallback; private _getAsset(filename: string): SourceFile { @@ -146,7 +160,8 @@ export class Host implements ts.CompilerHost { /** Provides the `ts.HostCompiler` interface for Deno. */ constructor(options: CompilerHostOptions) { - const { bundle = false, writeFile } = options; + const { bundle = false, target, writeFile } = options; + this._target = target; this._writeFile = writeFile; if (bundle) { // options we need to change when we are generating a bundle @@ -215,7 +230,13 @@ export class Host implements ts.CompilerHost { } getDefaultLibFileName(_options: ts.CompilerOptions): string { - return ASSETS + "/lib.deno_runtime.d.ts"; + switch (this._target) { + case CompilerHostTarget.Main: + case CompilerHostTarget.Runtime: + return `${ASSETS}/lib.deno_main.d.ts`; + case CompilerHostTarget.Worker: + return `${ASSETS}/lib.deno_worker.d.ts`; + } } getNewLine(): string { diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno.d.ts similarity index 59% rename from cli/js/lib.deno_runtime.d.ts rename to cli/js/lib.deno.d.ts index 31a6dbb3ef..0fa6f008c8 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno.d.ts @@ -1,8 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-empty-interface */ - /// /// @@ -2225,1572 +2222,3 @@ declare namespace Deno { // TODO(ry) move EOF here? }; } - -declare interface Window { - window: Window & typeof globalThis; - atob: typeof __textEncoding.atob; - btoa: typeof __textEncoding.btoa; - fetch: typeof __fetch.fetch; - clearTimeout: typeof __timers.clearTimeout; - clearInterval: typeof __timers.clearInterval; - console: __console.Console; - setTimeout: typeof __timers.setTimeout; - setInterval: typeof __timers.setInterval; - location: __domTypes.Location; - onload: Function | undefined; - onunload: Function | undefined; - crypto: Crypto; - Blob: typeof __blob.DenoBlob; - File: __domTypes.DomFileConstructor; - CustomEvent: typeof __customEvent.CustomEvent; - Event: typeof __event.Event; - EventTarget: typeof __eventTarget.EventTarget; - URL: typeof __url.URL; - URLSearchParams: typeof __urlSearchParams.URLSearchParams; - Headers: __domTypes.HeadersConstructor; - FormData: __domTypes.FormDataConstructor; - TextEncoder: typeof __textEncoding.TextEncoder; - TextDecoder: typeof __textEncoding.TextDecoder; - Request: __domTypes.RequestConstructor; - Response: typeof __fetch.Response; - performance: __performanceUtil.Performance; - onmessage: (e: { data: any }) => void; - onerror: undefined | typeof onerror; - bootstrapWorkerRuntime: typeof __workerMain.bootstrapWorkerRuntime; - workerClose: typeof __workerMain.workerClose; - postMessage: typeof __workerMain.postMessage; - Worker: typeof __workers.WorkerImpl; - addEventListener: ( - type: string, - callback: (event: __domTypes.Event) => void | null, - options?: boolean | __domTypes.AddEventListenerOptions | undefined - ) => void; - dispatchEvent: (event: __domTypes.Event) => boolean; - removeEventListener: ( - type: string, - callback: (event: __domTypes.Event) => void | null, - options?: boolean | __domTypes.EventListenerOptions | undefined - ) => void; - queueMicrotask: (task: () => void) => void; - Deno: typeof Deno; -} - -declare const window: Window & typeof globalThis; -declare const atob: typeof __textEncoding.atob; -declare const btoa: typeof __textEncoding.btoa; -declare const fetch: typeof __fetch.fetch; -declare const clearTimeout: typeof __timers.clearTimeout; -declare const clearInterval: typeof __timers.clearInterval; -declare const console: __console.Console; -declare const setTimeout: typeof __timers.setTimeout; -declare const setInterval: typeof __timers.setInterval; -declare const location: __domTypes.Location; -declare const onload: Function | undefined; -declare const onunload: Function | undefined; -declare const crypto: Crypto; -declare const Blob: typeof __blob.DenoBlob; -declare const File: __domTypes.DomFileConstructor; -declare const CustomEventInit: typeof __customEvent.CustomEventInit; -declare const CustomEvent: typeof __customEvent.CustomEvent; -declare const EventInit: typeof __event.EventInit; -declare const Event: typeof __event.Event; -declare const EventListener: typeof __eventTarget.EventListener; -declare const EventTarget: typeof __eventTarget.EventTarget; -declare const URL: typeof __url.URL; -declare const URLSearchParams: typeof __urlSearchParams.URLSearchParams; -declare const Headers: __domTypes.HeadersConstructor; -declare const FormData: __domTypes.FormDataConstructor; -declare const TextEncoder: typeof __textEncoding.TextEncoder; -declare const TextDecoder: typeof __textEncoding.TextDecoder; -declare const Request: __domTypes.RequestConstructor; -declare const Response: typeof __fetch.Response; -declare const performance: __performanceUtil.Performance; -declare let onmessage: ((e: { data: any }) => Promise | void) | undefined; -declare let onerror: - | (( - msg: string, - source: string, - lineno: number, - colno: number, - e: Event - ) => boolean | void) - | undefined; -declare const bootstrapWorkerRuntime: typeof __workerMain.bootstrapWorkerRuntime; -declare const workerClose: typeof __workerMain.workerClose; -declare const postMessage: typeof __workerMain.postMessage; -declare const Worker: typeof __workers.WorkerImpl; -declare const addEventListener: ( - type: string, - callback: (event: __domTypes.Event) => void | null, - options?: boolean | __domTypes.AddEventListenerOptions | undefined -) => void; -declare const dispatchEvent: (event: __domTypes.Event) => boolean; -declare const removeEventListener: ( - type: string, - callback: (event: __domTypes.Event) => void | null, - options?: boolean | __domTypes.EventListenerOptions | undefined -) => void; - -declare type Blob = __domTypes.Blob; -declare type Body = __domTypes.Body; -declare type File = __domTypes.DomFile; -declare type CustomEventInit = __domTypes.CustomEventInit; -declare type CustomEvent = __domTypes.CustomEvent; -declare type EventInit = __domTypes.EventInit; -declare type Event = __domTypes.Event; -declare type EventListener = __domTypes.EventListener; -declare type EventTarget = __domTypes.EventTarget; -declare type URL = __url.URL; -declare type URLSearchParams = __domTypes.URLSearchParams; -declare type Headers = __domTypes.Headers; -declare type FormData = __domTypes.FormData; -declare type TextEncoder = __textEncoding.TextEncoder; -declare type TextDecoder = __textEncoding.TextDecoder; -declare type Request = __domTypes.Request; -declare type Response = __domTypes.Response; -declare type Worker = __workers.Worker; - -declare interface ImportMeta { - url: string; - main: boolean; -} - -declare interface Crypto { - readonly subtle: null; - getRandomValues: < - T extends - | Int8Array - | Uint8Array - | Uint8ClampedArray - | Int16Array - | Uint16Array - | Int32Array - | Uint32Array - >( - typedArray: T - ) => T; -} - -declare namespace __domTypes { - // @url js/dom_types.d.ts - - export type BufferSource = ArrayBufferView | ArrayBuffer; - export type HeadersInit = - | Headers - | Array<[string, string]> - | Record; - export type URLSearchParamsInit = - | string - | string[][] - | Record; - type BodyInit = - | Blob - | BufferSource - | FormData - | URLSearchParams - | ReadableStream - | string; - export type RequestInfo = Request | string; - type ReferrerPolicy = - | "" - | "no-referrer" - | "no-referrer-when-downgrade" - | "origin-only" - | "origin-when-cross-origin" - | "unsafe-url"; - export type BlobPart = BufferSource | Blob | string; - export type FormDataEntryValue = DomFile | string; - export interface DomIterable { - keys(): IterableIterator; - values(): IterableIterator; - entries(): IterableIterator<[K, V]>; - [Symbol.iterator](): IterableIterator<[K, V]>; - forEach( - callback: (value: V, key: K, parent: this) => void, - thisArg?: any - ): void; - } - type EndingType = "transparent" | "native"; - export interface BlobPropertyBag { - type?: string; - ending?: EndingType; - } - interface AbortSignalEventMap { - abort: ProgressEvent; - } - export enum NodeType { - ELEMENT_NODE = 1, - TEXT_NODE = 3, - DOCUMENT_FRAGMENT_NODE = 11 - } - export const eventTargetHost: unique symbol; - export const eventTargetListeners: unique symbol; - export const eventTargetMode: unique symbol; - export const eventTargetNodeType: unique symbol; - export interface EventTarget { - [eventTargetHost]: EventTarget | null; - [eventTargetListeners]: { [type in string]: EventListener[] }; - [eventTargetMode]: string; - [eventTargetNodeType]: NodeType; - addEventListener( - type: string, - callback: (event: Event) => void | null, - options?: boolean | AddEventListenerOptions - ): void; - dispatchEvent(event: Event): boolean; - removeEventListener( - type: string, - callback?: (event: Event) => void | null, - options?: EventListenerOptions | boolean - ): void; - } - export interface ProgressEventInit extends EventInit { - lengthComputable?: boolean; - loaded?: number; - total?: number; - } - export interface URLSearchParams extends DomIterable { - /** - * Appends a specified key/value pair as a new search parameter. - */ - append(name: string, value: string): void; - /** - * Deletes the given search parameter, and its associated value, - * from the list of all search parameters. - */ - delete(name: string): void; - /** - * Returns the first value associated to the given search parameter. - */ - get(name: string): string | null; - /** - * Returns all the values association with a given search parameter. - */ - getAll(name: string): string[]; - /** - * Returns a Boolean indicating if such a search parameter exists. - */ - has(name: string): boolean; - /** - * Sets the value associated to a given search parameter to the given value. - * If there were several values, delete the others. - */ - set(name: string, value: string): void; - /** - * Sort all key/value pairs contained in this object in place - * and return undefined. The sort order is according to Unicode - * code points of the keys. - */ - sort(): void; - /** - * Returns a query string suitable for use in a URL. - */ - toString(): string; - /** - * Iterates over each name-value pair in the query - * and invokes the given function. - */ - forEach( - callbackfn: (value: string, key: string, parent: this) => void, - thisArg?: any - ): void; - } - export interface EventListener { - handleEvent(event: Event): void; - readonly callback: (event: Event) => void | null; - readonly options: boolean | AddEventListenerOptions; - } - export interface EventInit { - bubbles?: boolean; - cancelable?: boolean; - composed?: boolean; - } - export interface CustomEventInit extends EventInit { - detail?: any; - } - export enum EventPhase { - NONE = 0, - CAPTURING_PHASE = 1, - AT_TARGET = 2, - BUBBLING_PHASE = 3 - } - export interface EventPath { - item: EventTarget; - itemInShadowTree: boolean; - relatedTarget: EventTarget | null; - rootOfClosedTree: boolean; - slotInClosedTree: boolean; - target: EventTarget | null; - touchTargetList: EventTarget[]; - } - export interface Event { - readonly type: string; - target: EventTarget | null; - currentTarget: EventTarget | null; - composedPath(): EventPath[]; - eventPhase: number; - stopPropagation(): void; - stopImmediatePropagation(): void; - readonly bubbles: boolean; - readonly cancelable: boolean; - preventDefault(): void; - readonly defaultPrevented: boolean; - readonly composed: boolean; - isTrusted: boolean; - readonly timeStamp: Date; - dispatched: boolean; - readonly initialized: boolean; - inPassiveListener: boolean; - cancelBubble: boolean; - cancelBubbleImmediately: boolean; - path: EventPath[]; - relatedTarget: EventTarget | null; - } - export interface CustomEvent extends Event { - readonly detail: any; - initCustomEvent( - type: string, - bubbles?: boolean, - cancelable?: boolean, - detail?: any | null - ): void; - } - export interface DomFile extends Blob { - readonly lastModified: number; - readonly name: string; - } - export interface DomFileConstructor { - new ( - bits: BlobPart[], - filename: string, - options?: FilePropertyBag - ): DomFile; - prototype: DomFile; - } - export interface FilePropertyBag extends BlobPropertyBag { - lastModified?: number; - } - interface ProgressEvent extends Event { - readonly lengthComputable: boolean; - readonly loaded: number; - readonly total: number; - } - export interface EventListenerOptions { - capture: boolean; - } - export interface AddEventListenerOptions extends EventListenerOptions { - once: boolean; - passive: boolean; - } - interface AbortSignal extends EventTarget { - readonly aborted: boolean; - onabort: ((this: AbortSignal, ev: ProgressEvent) => any) | null; - addEventListener( - type: K, - listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, - options?: boolean | AddEventListenerOptions - ): void; - addEventListener( - type: string, - listener: EventListener, - options?: boolean | AddEventListenerOptions - ): void; - removeEventListener( - type: K, - listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, - options?: boolean | EventListenerOptions - ): void; - removeEventListener( - type: string, - listener: EventListener, - options?: boolean | EventListenerOptions - ): void; - } - export interface ReadableStream { - readonly locked: boolean; - cancel(): Promise; - getReader(): ReadableStreamReader; - tee(): [ReadableStream, ReadableStream]; - } - export interface ReadableStreamReader { - cancel(): Promise; - read(): Promise; - releaseLock(): void; - } - export interface FormData extends DomIterable { - append(name: string, value: string | Blob, fileName?: string): void; - delete(name: string): void; - get(name: string): FormDataEntryValue | null; - getAll(name: string): FormDataEntryValue[]; - has(name: string): boolean; - set(name: string, value: string | Blob, fileName?: string): void; - } - export interface FormDataConstructor { - new (): FormData; - prototype: FormData; - } - /** A blob object represents a file-like object of immutable, raw data. */ - export interface Blob { - /** The size, in bytes, of the data contained in the `Blob` object. */ - readonly size: number; - /** A string indicating the media type of the data contained in the `Blob`. - * If the type is unknown, this string is empty. - */ - readonly type: string; - /** Returns a new `Blob` object containing the data in the specified range of - * bytes of the source `Blob`. - */ - slice(start?: number, end?: number, contentType?: string): Blob; - } - export interface Body { - /** A simple getter used to expose a `ReadableStream` of the body contents. */ - readonly body: ReadableStream | null; - /** Stores a `Boolean` that declares whether the body has been used in a - * response yet. - */ - readonly bodyUsed: boolean; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with an `ArrayBuffer`. - */ - arrayBuffer(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with a `Blob`. - */ - blob(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with a `FormData` object. - */ - formData(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with the result of parsing the body text as JSON. - */ - json(): Promise; - /** Takes a `Response` stream and reads it to completion. It returns a promise - * that resolves with a `USVString` (text). - */ - text(): Promise; - } - export interface Headers extends DomIterable { - /** Appends a new value onto an existing header inside a `Headers` object, or - * adds the header if it does not already exist. - */ - append(name: string, value: string): void; - /** Deletes a header from a `Headers` object. */ - delete(name: string): void; - /** Returns an iterator allowing to go through all key/value pairs - * contained in this Headers object. The both the key and value of each pairs - * are ByteString objects. - */ - entries(): IterableIterator<[string, string]>; - /** Returns a `ByteString` sequence of all the values of a header within a - * `Headers` object with a given name. - */ - get(name: string): string | null; - /** Returns a boolean stating whether a `Headers` object contains a certain - * header. - */ - has(name: string): boolean; - /** Returns an iterator allowing to go through all keys contained in - * this Headers object. The keys are ByteString objects. - */ - keys(): IterableIterator; - /** Sets a new value for an existing header inside a Headers object, or adds - * the header if it does not already exist. - */ - set(name: string, value: string): void; - /** Returns an iterator allowing to go through all values contained in - * this Headers object. The values are ByteString objects. - */ - values(): IterableIterator; - forEach( - callbackfn: (value: string, key: string, parent: this) => void, - thisArg?: any - ): void; - /** The Symbol.iterator well-known symbol specifies the default - * iterator for this Headers object - */ - [Symbol.iterator](): IterableIterator<[string, string]>; - } - export interface HeadersConstructor { - new (init?: HeadersInit): Headers; - prototype: Headers; - } - type RequestCache = - | "default" - | "no-store" - | "reload" - | "no-cache" - | "force-cache" - | "only-if-cached"; - type RequestCredentials = "omit" | "same-origin" | "include"; - type RequestDestination = - | "" - | "audio" - | "audioworklet" - | "document" - | "embed" - | "font" - | "image" - | "manifest" - | "object" - | "paintworklet" - | "report" - | "script" - | "sharedworker" - | "style" - | "track" - | "video" - | "worker" - | "xslt"; - type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors"; - type RequestRedirect = "follow" | "error" | "manual"; - type ResponseType = - | "basic" - | "cors" - | "default" - | "error" - | "opaque" - | "opaqueredirect"; - export interface RequestInit { - body?: BodyInit | null; - cache?: RequestCache; - credentials?: RequestCredentials; - headers?: HeadersInit; - integrity?: string; - keepalive?: boolean; - method?: string; - mode?: RequestMode; - redirect?: RequestRedirect; - referrer?: string; - referrerPolicy?: ReferrerPolicy; - signal?: AbortSignal | null; - window?: any; - } - export interface ResponseInit { - headers?: HeadersInit; - status?: number; - statusText?: string; - } - export interface RequestConstructor { - new (input: RequestInfo, init?: RequestInit): Request; - prototype: Request; - } - export interface Request extends Body { - /** Returns the cache mode associated with request, which is a string - * indicating how the the request will interact with the browser's cache when - * fetching. - */ - readonly cache?: RequestCache; - /** Returns the credentials mode associated with request, which is a string - * indicating whether credentials will be sent with the request always, never, - * or only when sent to a same-origin URL. - */ - readonly credentials?: RequestCredentials; - /** Returns the kind of resource requested by request, (e.g., `document` or - * `script`). - */ - readonly destination?: RequestDestination; - /** Returns a Headers object consisting of the headers associated with - * request. - * - * Note that headers added in the network layer by the user agent - * will not be accounted for in this object, (e.g., the `Host` header). - */ - readonly headers: Headers; - /** Returns request's subresource integrity metadata, which is a cryptographic - * hash of the resource being fetched. Its value consists of multiple hashes - * separated by whitespace. [SRI] - */ - readonly integrity?: string; - /** Returns a boolean indicating whether or not request is for a history - * navigation (a.k.a. back-forward navigation). - */ - readonly isHistoryNavigation?: boolean; - /** Returns a boolean indicating whether or not request is for a reload - * navigation. - */ - readonly isReloadNavigation?: boolean; - /** Returns a boolean indicating whether or not request can outlive the global - * in which it was created. - */ - readonly keepalive?: boolean; - /** Returns request's HTTP method, which is `GET` by default. */ - readonly method: string; - /** Returns the mode associated with request, which is a string indicating - * whether the request will use CORS, or will be restricted to same-origin - * URLs. - */ - readonly mode?: RequestMode; - /** Returns the redirect mode associated with request, which is a string - * indicating how redirects for the request will be handled during fetching. - * - * A request will follow redirects by default. - */ - readonly redirect?: RequestRedirect; - /** Returns the referrer of request. Its value can be a same-origin URL if - * explicitly set in init, the empty string to indicate no referrer, and - * `about:client` when defaulting to the global's default. - * - * This is used during fetching to determine the value of the `Referer` - * header of the request being made. - */ - readonly referrer?: string; - /** Returns the referrer policy associated with request. This is used during - * fetching to compute the value of the request's referrer. - */ - readonly referrerPolicy?: ReferrerPolicy; - /** Returns the signal associated with request, which is an AbortSignal object - * indicating whether or not request has been aborted, and its abort event - * handler. - */ - readonly signal?: AbortSignal; - /** Returns the URL of request as a string. */ - readonly url: string; - clone(): Request; - } - export interface Response extends Body { - /** Contains the `Headers` object associated with the response. */ - readonly headers: Headers; - /** Contains a boolean stating whether the response was successful (status in - * the range 200-299) or not. - */ - readonly ok: boolean; - /** Indicates whether or not the response is the result of a redirect; that - * is, its URL list has more than one entry. - */ - readonly redirected: boolean; - /** Contains the status code of the response (e.g., `200` for a success). */ - readonly status: number; - /** Contains the status message corresponding to the status code (e.g., `OK` - * for `200`). - */ - readonly statusText: string; - readonly trailer: Promise; - /** Contains the type of the response (e.g., `basic`, `cors`). */ - readonly type: ResponseType; - /** Contains the URL of the response. */ - readonly url: string; - /** Creates a clone of a `Response` object. */ - clone(): Response; - } - export interface Location { - /** - * Returns a DOMStringList object listing the origins of the ancestor browsing - * contexts, from the parent browsing context to the top-level browsing - * context. - */ - readonly ancestorOrigins: string[]; - /** - * Returns the Location object's URL's fragment (includes leading "#" if - * non-empty). - * Can be set, to navigate to the same URL with a changed fragment (ignores - * leading "#"). - */ - hash: string; - /** - * Returns the Location object's URL's host and port (if different from the - * default port for the scheme). Can be set, to navigate to the same URL with - * a changed host and port. - */ - host: string; - /** - * Returns the Location object's URL's host. Can be set, to navigate to the - * same URL with a changed host. - */ - hostname: string; - /** - * Returns the Location object's URL. Can be set, to navigate to the given - * URL. - */ - href: string; - /** Returns the Location object's URL's origin. */ - readonly origin: string; - /** - * Returns the Location object's URL's path. - * Can be set, to navigate to the same URL with a changed path. - */ - pathname: string; - /** - * Returns the Location object's URL's port. - * Can be set, to navigate to the same URL with a changed port. - */ - port: string; - /** - * Returns the Location object's URL's scheme. - * Can be set, to navigate to the same URL with a changed scheme. - */ - protocol: string; - /** - * Returns the Location object's URL's query (includes leading "?" if - * non-empty). Can be set, to navigate to the same URL with a changed query - * (ignores leading "?"). - */ - search: string; - /** - * Navigates to the given URL. - */ - assign(url: string): void; - /** - * Reloads the current page. - */ - reload(): void; - /** @deprecated */ - reload(forcedReload: boolean): void; - /** - * Removes the current page from the session history and navigates to the - * given URL. - */ - replace(url: string): void; - } -} - -declare namespace __blob { - // @url js/blob.d.ts - - export const bytesSymbol: unique symbol; - export const blobBytesWeakMap: WeakMap<__domTypes.Blob, Uint8Array>; - export class DenoBlob implements __domTypes.Blob { - private readonly [bytesSymbol]; - readonly size: number; - readonly type: string; - /** A blob object represents a file-like object of immutable, raw data. */ - constructor( - blobParts?: __domTypes.BlobPart[], - options?: __domTypes.BlobPropertyBag - ); - slice(start?: number, end?: number, contentType?: string): DenoBlob; - } -} - -declare namespace __console { - // @url js/console.d.ts - - type ConsoleOptions = Partial<{ - showHidden: boolean; - depth: number; - colors: boolean; - indentLevel: number; - }>; - export class CSI { - static kClear: string; - static kClearScreenDown: string; - } - const isConsoleInstance: unique symbol; - export class Console { - private printFunc; - indentLevel: number; - [isConsoleInstance]: boolean; - /** Writes the arguments to stdout */ - log: (...args: unknown[]) => void; - /** Writes the arguments to stdout */ - debug: (...args: unknown[]) => void; - /** Writes the arguments to stdout */ - info: (...args: unknown[]) => void; - /** Writes the properties of the supplied `obj` to stdout */ - dir: ( - obj: unknown, - options?: Partial<{ - showHidden: boolean; - depth: number; - colors: boolean; - indentLevel: number; - }> - ) => void; - - /** From MDN: - * Displays an interactive tree of the descendant elements of - * the specified XML/HTML element. If it is not possible to display - * as an element the JavaScript Object view is shown instead. - * The output is presented as a hierarchical listing of expandable - * nodes that let you see the contents of child nodes. - * - * Since we write to stdout, we can't display anything interactive - * we just fall back to `console.dir`. - */ - dirxml: ( - obj: unknown, - options?: Partial<{ - showHidden: boolean; - depth: number; - colors: boolean; - indentLevel: number; - }> - ) => void; - - /** Writes the arguments to stdout */ - warn: (...args: unknown[]) => void; - /** Writes the arguments to stdout */ - error: (...args: unknown[]) => void; - /** Writes an error message to stdout if the assertion is `false`. If the - * assertion is `true`, nothing happens. - * - * ref: https://console.spec.whatwg.org/#assert - */ - assert: (condition?: boolean, ...args: unknown[]) => void; - count: (label?: string) => void; - countReset: (label?: string) => void; - table: (data: unknown, properties?: string[] | undefined) => void; - time: (label?: string) => void; - timeLog: (label?: string, ...args: unknown[]) => void; - timeEnd: (label?: string) => void; - group: (...label: unknown[]) => void; - groupCollapsed: (...label: unknown[]) => void; - groupEnd: () => void; - clear: () => void; - trace: (...args: unknown[]) => void; - static [Symbol.hasInstance](instance: Console): boolean; - } - /** A symbol which can be used as a key for a custom method which will be called - * when `Deno.inspect()` is called, or when the object is logged to the console. - */ - export const customInspect: unique symbol; - /** - * `inspect()` converts input into string that has the same format - * as printed by `console.log(...)`; - */ - export function inspect(value: unknown, options?: ConsoleOptions): string; -} - -declare namespace __event { - // @url js/event.d.ts - - export const eventAttributes: WeakMap; - export class EventInit implements __domTypes.EventInit { - bubbles: boolean; - cancelable: boolean; - composed: boolean; - constructor({ - bubbles, - cancelable, - composed - }?: { - bubbles?: boolean | undefined; - cancelable?: boolean | undefined; - composed?: boolean | undefined; - }); - } - export class Event implements __domTypes.Event { - isTrusted: boolean; - private _canceledFlag; - private _dispatchedFlag; - private _initializedFlag; - private _inPassiveListenerFlag; - private _stopImmediatePropagationFlag; - private _stopPropagationFlag; - private _path; - constructor(type: string, eventInitDict?: __domTypes.EventInit); - readonly bubbles: boolean; - cancelBubble: boolean; - cancelBubbleImmediately: boolean; - readonly cancelable: boolean; - readonly composed: boolean; - currentTarget: __domTypes.EventTarget; - readonly defaultPrevented: boolean; - dispatched: boolean; - eventPhase: number; - readonly initialized: boolean; - inPassiveListener: boolean; - path: __domTypes.EventPath[]; - relatedTarget: __domTypes.EventTarget; - target: __domTypes.EventTarget; - readonly timeStamp: Date; - readonly type: string; - /** Returns the event’s path (objects on which listeners will be - * invoked). This does not include nodes in shadow trees if the - * shadow root was created with its ShadowRoot.mode closed. - * - * event.composedPath(); - */ - composedPath(): __domTypes.EventPath[]; - /** Cancels the event (if it is cancelable). - * See https://dom.spec.whatwg.org/#set-the-canceled-flag - * - * event.preventDefault(); - */ - preventDefault(): void; - /** Stops the propagation of events further along in the DOM. - * - * event.stopPropagation(); - */ - stopPropagation(): void; - /** For this particular event, no other listener will be called. - * Neither those attached on the same element, nor those attached - * on elements which will be traversed later (in capture phase, - * for instance). - * - * event.stopImmediatePropagation(); - */ - stopImmediatePropagation(): void; - } -} - -declare namespace __customEvent { - // @url js/custom_event.d.ts - - export const customEventAttributes: WeakMap; - export class CustomEventInit extends __event.EventInit - implements __domTypes.CustomEventInit { - detail: any; - constructor({ - bubbles, - cancelable, - composed, - detail - }: __domTypes.CustomEventInit); - } - export class CustomEvent extends __event.Event - implements __domTypes.CustomEvent { - constructor(type: string, customEventInitDict?: __domTypes.CustomEventInit); - readonly detail: any; - initCustomEvent( - type: string, - bubbles?: boolean, - cancelable?: boolean, - detail?: any - ): void; - readonly [Symbol.toStringTag]: string; - } -} - -declare namespace __eventTarget { - // @url js/event_target.d.ts - - export class EventListenerOptions implements __domTypes.EventListenerOptions { - _capture: boolean; - constructor({ capture }?: { capture?: boolean | undefined }); - readonly capture: boolean; - } - export class AddEventListenerOptions extends EventListenerOptions - implements __domTypes.AddEventListenerOptions { - _passive: boolean; - _once: boolean; - constructor({ - capture, - passive, - once - }?: { - capture?: boolean | undefined; - passive?: boolean | undefined; - once?: boolean | undefined; - }); - readonly passive: boolean; - readonly once: boolean; - } - export class EventListener implements __domTypes.EventListener { - allEvents: __domTypes.Event[]; - atEvents: __domTypes.Event[]; - bubbledEvents: __domTypes.Event[]; - capturedEvents: __domTypes.Event[]; - private _callback; - private _options; - constructor( - callback: (event: __domTypes.Event) => void | null, - options: boolean | __domTypes.AddEventListenerOptions - ); - handleEvent(event: __domTypes.Event): void; - readonly callback: (event: __domTypes.Event) => void | null; - readonly options: __domTypes.AddEventListenerOptions | boolean; - } - export const eventTargetAssignedSlot: unique symbol; - export const eventTargetHasActivationBehavior: unique symbol; - export class EventTarget implements __domTypes.EventTarget { - [__domTypes.eventTargetHost]: __domTypes.EventTarget | null; - [__domTypes.eventTargetListeners]: { - [type in string]: __domTypes.EventListener[]; - }; - [__domTypes.eventTargetMode]: string; - [__domTypes.eventTargetNodeType]: __domTypes.NodeType; - private [eventTargetAssignedSlot]; - private [eventTargetHasActivationBehavior]; - addEventListener( - type: string, - callback: (event: __domTypes.Event) => void | null, - options?: __domTypes.AddEventListenerOptions | boolean - ): void; - removeEventListener( - type: string, - callback: (event: __domTypes.Event) => void | null, - options?: __domTypes.EventListenerOptions | boolean - ): void; - dispatchEvent(event: __domTypes.Event): boolean; - readonly [Symbol.toStringTag]: string; - } -} - -declare namespace __io { - /** UNSTABLE: maybe remove "SEEK_" prefix. Maybe capitalization wrong. */ - export enum SeekMode { - SEEK_START = 0, - SEEK_CURRENT = 1, - SEEK_END = 2 - } - export interface Reader { - /** Reads up to p.byteLength bytes into `p`. It resolves to the number - * of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error encountered. - * Even if `read()` returns `n` < `p.byteLength`, it may use all of `p` as - * scratch space during the call. If some data is available but not - * `p.byteLength` bytes, `read()` conventionally returns what is available - * instead of waiting for more. - * - * When `read()` encounters end-of-file condition, it returns EOF symbol. - * - * When `read()` encounters an error, it rejects with an error. - * - * Callers should always process the `n` > `0` bytes returned before - * considering the EOF. Doing so correctly handles I/O errors that happen - * after reading some bytes and also both of the allowed EOF behaviors. - * - * Implementations must not retain `p`. - */ - read(p: Uint8Array): Promise; - } - export interface SyncReader { - readSync(p: Uint8Array): number | Deno.EOF; - } - export interface Writer { - /** Writes `p.byteLength` bytes from `p` to the underlying data - * stream. It resolves to the number of bytes written from `p` (`0` <= `n` <= - * `p.byteLength`) and any error encountered that caused the write to stop - * early. `write()` must return a non-null error if it returns `n` < - * `p.byteLength`. write() must not modify the slice data, even temporarily. - * - * Implementations must not retain `p`. - */ - write(p: Uint8Array): Promise; - } - export interface SyncWriter { - writeSync(p: Uint8Array): number; - } - export interface Closer { - close(): void; - } - export interface Seeker { - /** Seek sets the offset for the next `read()` or `write()` to offset, - * interpreted according to `whence`: `SeekStart` means relative to the start - * of the file, `SeekCurrent` means relative to the current offset, and - * `SeekEnd` means relative to the end. Seek returns the new offset relative - * to the start of the file and an error, if any. - * - * Seeking to an offset before the start of the file is an error. Seeking to - * any positive offset is legal, but the behavior of subsequent I/O operations - * on the underlying object is implementation-dependent. - */ - seek(offset: number, whence: SeekMode): Promise; - } - export interface SyncSeeker { - seekSync(offset: number, whence: SeekMode): void; - } - export interface ReadCloser extends Reader, Closer {} - export interface WriteCloser extends Writer, Closer {} - export interface ReadSeeker extends Reader, Seeker {} - export interface WriteSeeker extends Writer, Seeker {} - export interface ReadWriteCloser extends Reader, Writer, Closer {} - export interface ReadWriteSeeker extends Reader, Writer, Seeker {} - - /** UNSTABLE: controversial. - * - * Copies from `src` to `dst` until either `EOF` is reached on `src` - * or an error occurs. It returns the number of bytes copied and the first - * error encountered while copying, if any. - * - * Because `copy()` is defined to read from `src` until `EOF`, it does not - * treat an `EOF` from `read()` as an error to be reported. - */ - export function copy(dst: Writer, src: Reader): Promise; - - /** UNSTABLE: Make Reader into AsyncIterable? Remove this? - * - * Turns `r` into async iterator. - * - * for await (const chunk of toAsyncIterator(reader)) { - * console.log(chunk) - * } - */ - export function toAsyncIterator(r: Reader): AsyncIterableIterator; -} - -declare namespace __fetch { - // @url js/fetch.d.ts - - class Body - implements __domTypes.Body, __domTypes.ReadableStream, __io.ReadCloser { - private rid; - readonly contentType: string; - bodyUsed: boolean; - private _bodyPromise; - private _data; - readonly locked: boolean; - readonly body: null | Body; - constructor(rid: number, contentType: string); - private _bodyBuffer; - arrayBuffer(): Promise; - blob(): Promise<__domTypes.Blob>; - formData(): Promise<__domTypes.FormData>; - json(): Promise; - text(): Promise; - read(p: Uint8Array): Promise; - close(): void; - cancel(): Promise; - getReader(): __domTypes.ReadableStreamReader; - tee(): [__domTypes.ReadableStream, __domTypes.ReadableStream]; - [Symbol.asyncIterator](): AsyncIterableIterator; - } - export class Response implements __domTypes.Response { - readonly url: string; - readonly status: number; - statusText: string; - readonly type = "basic"; - readonly redirected: boolean; - headers: __domTypes.Headers; - readonly trailer: Promise<__domTypes.Headers>; - bodyUsed: boolean; - readonly body: Body; - constructor( - url: string, - status: number, - headersList: Array<[string, string]>, - rid: number, - redirected_: boolean, - body_?: null | Body - ); - arrayBuffer(): Promise; - blob(): Promise<__domTypes.Blob>; - formData(): Promise<__domTypes.FormData>; - json(): Promise; - text(): Promise; - readonly ok: boolean; - clone(): __domTypes.Response; - } - /** Fetch a resource from the network. */ - export function fetch( - input: __domTypes.Request | __url.URL | string, - init?: __domTypes.RequestInit - ): Promise; -} - -declare namespace __textEncoding { - // @url js/text_encoding.d.ts - - export function atob(s: string): string; - /** Creates a base-64 ASCII string from the input string. */ - export function btoa(s: string): string; - export interface TextDecodeOptions { - stream?: false; - } - export interface TextDecoderOptions { - fatal?: boolean; - ignoreBOM?: boolean; - } - export class TextDecoder { - private _encoding; - /** Returns encoding's name, lowercased. */ - readonly encoding: string; - /** Returns `true` if error mode is "fatal", and `false` otherwise. */ - readonly fatal: boolean; - /** Returns `true` if ignore BOM flag is set, and `false` otherwise. */ - readonly ignoreBOM = false; - constructor(label?: string, options?: TextDecoderOptions); - /** Returns the result of running encoding's decoder. */ - decode( - input?: __domTypes.BufferSource, - options?: TextDecodeOptions - ): string; - readonly [Symbol.toStringTag]: string; - } - interface TextEncoderEncodeIntoResult { - read: number; - written: number; - } - export class TextEncoder { - /** Returns "utf-8". */ - readonly encoding = "utf-8"; - /** Returns the result of running UTF-8's encoder. */ - encode(input?: string): Uint8Array; - encodeInto(input: string, dest: Uint8Array): TextEncoderEncodeIntoResult; - readonly [Symbol.toStringTag]: string; - } -} - -declare namespace __timers { - // @url js/timers.d.ts - - export type Args = unknown[]; - /** Sets a timer which executes a function once after the timer expires. */ - export function setTimeout( - cb: (...args: Args) => void, - delay?: number, - ...args: Args - ): number; - /** Repeatedly calls a function , with a fixed time delay between each call. */ - export function setInterval( - cb: (...args: Args) => void, - delay?: number, - ...args: Args - ): number; - export function clearTimeout(id?: number): void; - export function clearInterval(id?: number): void; -} - -declare namespace __urlSearchParams { - // @url js/url_search_params.d.ts - - export class URLSearchParams { - private params; - private url; - constructor(init?: string | string[][] | Record); - private updateSteps; - /** Appends a specified key/value pair as a new search parameter. - * - * searchParams.append('name', 'first'); - * searchParams.append('name', 'second'); - */ - append(name: string, value: string): void; - /** Deletes the given search parameter and its associated value, - * from the list of all search parameters. - * - * searchParams.delete('name'); - */ - delete(name: string): void; - /** Returns all the values associated with a given search parameter - * as an array. - * - * searchParams.getAll('name'); - */ - getAll(name: string): string[]; - /** Returns the first value associated to the given search parameter. - * - * searchParams.get('name'); - */ - get(name: string): string | null; - /** Returns a Boolean that indicates whether a parameter with the - * specified name exists. - * - * searchParams.has('name'); - */ - has(name: string): boolean; - /** Sets the value associated with a given search parameter to the - * given value. If there were several matching values, this method - * deletes the others. If the search parameter doesn't exist, this - * method creates it. - * - * searchParams.set('name', 'value'); - */ - set(name: string, value: string): void; - /** Sort all key/value pairs contained in this object in place and - * return undefined. The sort order is according to Unicode code - * points of the keys. - * - * searchParams.sort(); - */ - sort(): void; - /** Calls a function for each element contained in this object in - * place and return undefined. Optionally accepts an object to use - * as this when executing callback as second argument. - * - * searchParams.forEach((value, key, parent) => { - * console.log(value, key, parent); - * }); - * - */ - forEach( - callbackfn: (value: string, key: string, parent: this) => void, - thisArg?: any - ): void; - /** Returns an iterator allowing to go through all keys contained - * in this object. - * - * for (const key of searchParams.keys()) { - * console.log(key); - * } - */ - keys(): IterableIterator; - /** Returns an iterator allowing to go through all values contained - * in this object. - * - * for (const value of searchParams.values()) { - * console.log(value); - * } - */ - values(): IterableIterator; - /** Returns an iterator allowing to go through all key/value - * pairs contained in this object. - * - * for (const [key, value] of searchParams.entries()) { - * console.log(key, value); - * } - */ - entries(): IterableIterator<[string, string]>; - /** Returns an iterator allowing to go through all key/value - * pairs contained in this object. - * - * for (const [key, value] of searchParams[Symbol.iterator]()) { - * console.log(key, value); - * } - */ - [Symbol.iterator](): IterableIterator<[string, string]>; - /** Returns a query string suitable for use in a URL. - * - * searchParams.toString(); - */ - toString(): string; - private _handleStringInitialization; - private _handleArrayInitialization; - } -} - -declare namespace __url { - // @url js/url.d.ts - export interface URL { - hash: string; - host: string; - hostname: string; - href: string; - readonly origin: string; - password: string; - pathname: string; - port: string; - protocol: string; - search: string; - readonly searchParams: __urlSearchParams.URLSearchParams; - username: string; - toString(): string; - toJSON(): string; - } - - export const URL: { - prototype: URL; - new (url: string, base?: string | URL): URL; - createObjectURL(object: __domTypes.Blob): string; - revokeObjectURL(url: string): void; - }; -} - -declare namespace __workerMain { - export let onmessage: (e: { data: any }) => void; - export function postMessage(data: any): void; - export function getMessage(): Promise; - export let isClosing: boolean; - export function workerClose(): void; - export function bootstrapWorkerRuntime(): Promise; -} - -declare namespace __workers { - // @url js/workers.d.ts - export interface Worker { - onerror?: (e: Event) => void; - onmessage?: (e: { data: any }) => void; - onmessageerror?: () => void; - postMessage(data: any): void; - } - export interface WorkerOptions { - type?: "classic" | "module"; - } - export class WorkerImpl implements Worker { - private readonly id; - private isClosing; - private readonly isClosedPromise; - onerror?: (e: Event) => void; - onmessage?: (data: any) => void; - onmessageerror?: () => void; - constructor(specifier: string, options?: WorkerOptions); - postMessage(data: any): void; - private run; - } -} - -declare namespace __performanceUtil { - // @url js/performance.d.ts - - export class Performance { - /** Returns a current time from Deno's start in milliseconds. - * - * Use the flag --allow-hrtime return a precise value. - * - * const t = performance.now(); - * console.log(`${t} ms since start!`); - */ - now(): number; - } -} - -// @url js/lib.web_assembly.d.ts - -// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/ -// And follow on WebIDL at: https://webassembly.github.io/spec/web-api/ - -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */ - -declare namespace WebAssembly { - interface WebAssemblyInstantiatedSource { - module: Module; - instance: Instance; - } - - /** Compiles a `WebAssembly.Module` from WebAssembly binary code. This - * function is useful if it is necessary to a compile a module before it can - * be instantiated (otherwise, the `WebAssembly.instantiate()` function - * should be used). */ - function compile(bufferSource: __domTypes.BufferSource): Promise; - - /** Compiles a `WebAssembly.Module` directly from a streamed underlying - * source. This function is useful if it is necessary to a compile a module - * before it can be instantiated (otherwise, the - * `WebAssembly.instantiateStreaming()` function should be used). */ - function compileStreaming( - source: Promise<__domTypes.Response> - ): Promise; - - /** Takes the WebAssembly binary code, in the form of a typed array or - * `ArrayBuffer`, and performs both compilation and instantiation in one step. - * The returned `Promise` resolves to both a compiled `WebAssembly.Module` and - * its first `WebAssembly.Instance`. */ - function instantiate( - bufferSource: __domTypes.BufferSource, - importObject?: object - ): Promise; - - /** Takes an already-compiled `WebAssembly.Module` and returns a `Promise` - * that resolves to an `Instance` of that `Module`. This overload is useful if - * the `Module` has already been compiled. */ - function instantiate( - module: Module, - importObject?: object - ): Promise; - - /** Compiles and instantiates a WebAssembly module directly from a streamed - * underlying source. This is the most efficient, optimized way to load wasm - * code. */ - function instantiateStreaming( - source: Promise<__domTypes.Response>, - importObject?: object - ): Promise; - - /** Validates a given typed array of WebAssembly binary code, returning - * whether the bytes form a valid wasm module (`true`) or not (`false`). */ - function validate(bufferSource: __domTypes.BufferSource): boolean; - - type ImportExportKind = "function" | "table" | "memory" | "global"; - - interface ModuleExportDescriptor { - name: string; - kind: ImportExportKind; - } - interface ModuleImportDescriptor { - module: string; - name: string; - kind: ImportExportKind; - } - - class Module { - constructor(bufferSource: __domTypes.BufferSource); - - /** Given a `Module` and string, returns a copy of the contents of all - * custom sections in the module with the given string name. */ - static customSections( - moduleObject: Module, - sectionName: string - ): ArrayBuffer; - - /** Given a `Module`, returns an array containing descriptions of all the - * declared exports. */ - static exports(moduleObject: Module): ModuleExportDescriptor[]; - - /** Given a `Module`, returns an array containing descriptions of all the - * declared imports. */ - static imports(moduleObject: Module): ModuleImportDescriptor[]; - } - - class Instance { - constructor(module: Module, importObject?: object); - - /** An object containing as its members all the functions exported from the - * WebAssembly module instance, to allow them to be accessed and used by - * JavaScript. */ - readonly exports: T; - } - - interface MemoryDescriptor { - initial: number; - maximum?: number; - } - - class Memory { - constructor(descriptor: MemoryDescriptor); - - /** An accessor property that returns the buffer contained in the memory. */ - readonly buffer: ArrayBuffer; - - /** Increases the size of the memory instance by a specified number of - * WebAssembly pages (each one is 64KB in size). */ - grow(delta: number): number; - } - - type TableKind = "anyfunc"; - - interface TableDescriptor { - element: TableKind; - initial: number; - maximum?: number; - } - - class Table { - constructor(descriptor: TableDescriptor); - - /** Returns the length of the table, i.e. the number of elements. */ - readonly length: number; - - /** Accessor function — gets the element stored at a given index. */ - get(index: number): (...args: any[]) => any; - - /** Increases the size of the Table instance by a specified number of - * elements. */ - grow(delta: number): number; - - /** Sets an element stored at a given index to a given value. */ - set(index: number, value: (...args: any[]) => any): void; - } - - interface GlobalDescriptor { - value: string; - mutable?: boolean; - } - - /** Represents a global variable instance, accessible from both JavaScript and - * importable/exportable across one or more `WebAssembly.Module` instances. - * This allows dynamic linking of multiple modules. */ - class Global { - constructor(descriptor: GlobalDescriptor, value?: any); - - /** Old-style method that returns the value contained inside the global - * variable. */ - valueOf(): any; - - /** The value contained inside the global variable — this can be used to - * directly set and get the global's value. */ - value: any; - } - - /** Indicates an error during WebAssembly decoding or validation */ - class CompileError extends Error { - constructor(message: string, fileName?: string, lineNumber?: string); - } - - /** Indicates an error during module instantiation (besides traps from the - * start function). */ - class LinkError extends Error { - constructor(message: string, fileName?: string, lineNumber?: string); - } - - /** Is thrown whenever WebAssembly specifies a trap. */ - class RuntimeError extends Error { - constructor(message: string, fileName?: string, lineNumber?: string); - } -} - -// Catch-all for JSX elements. -// See https://www.typescriptlang.org/docs/handbook/jsx.html#intrinsic-elements -declare namespace JSX { - interface IntrinsicElements { - [elemName: string]: any; - } -} diff --git a/cli/js/lib.deno_main.d.ts b/cli/js/lib.deno_main.d.ts new file mode 100644 index 0000000000..ec050fc1e3 --- /dev/null +++ b/cli/js/lib.deno_main.d.ts @@ -0,0 +1,1572 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */ + +/// +/// +/// + +declare interface Window { + window: Window & typeof globalThis; + atob: typeof __textEncoding.atob; + btoa: typeof __textEncoding.btoa; + fetch: typeof __fetch.fetch; + clearTimeout: typeof __timers.clearTimeout; + clearInterval: typeof __timers.clearInterval; + console: __console.Console; + setTimeout: typeof __timers.setTimeout; + setInterval: typeof __timers.setInterval; + location: __domTypes.Location; + onload: Function | undefined; + onunload: Function | undefined; + crypto: Crypto; + Blob: typeof __blob.DenoBlob; + File: __domTypes.DomFileConstructor; + CustomEvent: typeof __customEvent.CustomEvent; + Event: typeof __event.Event; + EventTarget: typeof __eventTarget.EventTarget; + URL: typeof __url.URL; + URLSearchParams: typeof __urlSearchParams.URLSearchParams; + Headers: __domTypes.HeadersConstructor; + FormData: __domTypes.FormDataConstructor; + TextEncoder: typeof __textEncoding.TextEncoder; + TextDecoder: typeof __textEncoding.TextDecoder; + Request: __domTypes.RequestConstructor; + Response: typeof __fetch.Response; + performance: __performanceUtil.Performance; + onmessage: (e: { data: any }) => void; + onerror: undefined | typeof onerror; + bootstrapWorkerRuntime: typeof __workerMain.bootstrapWorkerRuntime; + workerClose: typeof __workerMain.workerClose; + postMessage: typeof __workerMain.postMessage; + Worker: typeof __workers.WorkerImpl; + addEventListener: ( + type: string, + callback: (event: __domTypes.Event) => void | null, + options?: boolean | __domTypes.AddEventListenerOptions | undefined + ) => void; + dispatchEvent: (event: __domTypes.Event) => boolean; + removeEventListener: ( + type: string, + callback: (event: __domTypes.Event) => void | null, + options?: boolean | __domTypes.EventListenerOptions | undefined + ) => void; + queueMicrotask: (task: () => void) => void; + Deno: typeof Deno; +} + +declare const window: Window & typeof globalThis; +declare const atob: typeof __textEncoding.atob; +declare const btoa: typeof __textEncoding.btoa; +declare const fetch: typeof __fetch.fetch; +declare const clearTimeout: typeof __timers.clearTimeout; +declare const clearInterval: typeof __timers.clearInterval; +declare const console: __console.Console; +declare const setTimeout: typeof __timers.setTimeout; +declare const setInterval: typeof __timers.setInterval; +declare const location: __domTypes.Location; +declare const onload: Function | undefined; +declare const onunload: Function | undefined; +declare const crypto: Crypto; +declare const Blob: typeof __blob.DenoBlob; +declare const File: __domTypes.DomFileConstructor; +declare const CustomEventInit: typeof __customEvent.CustomEventInit; +declare const CustomEvent: typeof __customEvent.CustomEvent; +declare const EventInit: typeof __event.EventInit; +declare const Event: typeof __event.Event; +declare const EventListener: typeof __eventTarget.EventListener; +declare const EventTarget: typeof __eventTarget.EventTarget; +declare const URL: typeof __url.URL; +declare const URLSearchParams: typeof __urlSearchParams.URLSearchParams; +declare const Headers: __domTypes.HeadersConstructor; +declare const FormData: __domTypes.FormDataConstructor; +declare const TextEncoder: typeof __textEncoding.TextEncoder; +declare const TextDecoder: typeof __textEncoding.TextDecoder; +declare const Request: __domTypes.RequestConstructor; +declare const Response: typeof __fetch.Response; +declare const performance: __performanceUtil.Performance; +declare let onmessage: ((e: { data: any }) => Promise | void) | undefined; +declare let onerror: + | (( + msg: string, + source: string, + lineno: number, + colno: number, + e: Event + ) => boolean | void) + | undefined; +declare const bootstrapWorkerRuntime: typeof __workerMain.bootstrapWorkerRuntime; +declare const workerClose: typeof __workerMain.workerClose; +declare const postMessage: typeof __workerMain.postMessage; +declare const Worker: typeof __workers.WorkerImpl; +declare const addEventListener: ( + type: string, + callback: (event: __domTypes.Event) => void | null, + options?: boolean | __domTypes.AddEventListenerOptions | undefined +) => void; +declare const dispatchEvent: (event: __domTypes.Event) => boolean; +declare const removeEventListener: ( + type: string, + callback: (event: __domTypes.Event) => void | null, + options?: boolean | __domTypes.EventListenerOptions | undefined +) => void; + +declare type Blob = __domTypes.Blob; +declare type Body = __domTypes.Body; +declare type File = __domTypes.DomFile; +declare type CustomEventInit = __domTypes.CustomEventInit; +declare type CustomEvent = __domTypes.CustomEvent; +declare type EventInit = __domTypes.EventInit; +declare type Event = __domTypes.Event; +declare type EventListener = __domTypes.EventListener; +declare type EventTarget = __domTypes.EventTarget; +declare type URL = __url.URL; +declare type URLSearchParams = __domTypes.URLSearchParams; +declare type Headers = __domTypes.Headers; +declare type FormData = __domTypes.FormData; +declare type TextEncoder = __textEncoding.TextEncoder; +declare type TextDecoder = __textEncoding.TextDecoder; +declare type Request = __domTypes.Request; +declare type Response = __domTypes.Response; +declare type Worker = __workers.Worker; + +declare interface ImportMeta { + url: string; + main: boolean; +} + +declare interface Crypto { + readonly subtle: null; + getRandomValues< + T extends + | Int8Array + | Int16Array + | Int32Array + | Uint8Array + | Uint16Array + | Uint32Array + | Uint8ClampedArray + | Float32Array + | Float64Array + | DataView + | null + >( + array: T + ): T; +} + +// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/ +// and: https://webassembly.github.io/spec/web-api/ + +declare namespace WebAssembly { + interface WebAssemblyInstantiatedSource { + module: Module; + instance: Instance; + } + + /** Compiles a `WebAssembly.Module` from WebAssembly binary code. This + * function is useful if it is necessary to a compile a module before it can + * be instantiated (otherwise, the `WebAssembly.instantiate()` function + * should be used). */ + function compile(bufferSource: __domTypes.BufferSource): Promise; + + /** Compiles a `WebAssembly.Module` directly from a streamed underlying + * source. This function is useful if it is necessary to a compile a module + * before it can be instantiated (otherwise, the + * `WebAssembly.instantiateStreaming()` function should be used). */ + function compileStreaming( + source: Promise<__domTypes.Response> + ): Promise; + + /** Takes the WebAssembly binary code, in the form of a typed array or + * `ArrayBuffer`, and performs both compilation and instantiation in one step. + * The returned `Promise` resolves to both a compiled `WebAssembly.Module` and + * its first `WebAssembly.Instance`. */ + function instantiate( + bufferSource: __domTypes.BufferSource, + importObject?: object + ): Promise; + + /** Takes an already-compiled `WebAssembly.Module` and returns a `Promise` + * that resolves to an `Instance` of that `Module`. This overload is useful if + * the `Module` has already been compiled. */ + function instantiate( + module: Module, + importObject?: object + ): Promise; + + /** Compiles and instantiates a WebAssembly module directly from a streamed + * underlying source. This is the most efficient, optimized way to load wasm + * code. */ + function instantiateStreaming( + source: Promise<__domTypes.Response>, + importObject?: object + ): Promise; + + /** Validates a given typed array of WebAssembly binary code, returning + * whether the bytes form a valid wasm module (`true`) or not (`false`). */ + function validate(bufferSource: __domTypes.BufferSource): boolean; + + type ImportExportKind = "function" | "table" | "memory" | "global"; + + interface ModuleExportDescriptor { + name: string; + kind: ImportExportKind; + } + interface ModuleImportDescriptor { + module: string; + name: string; + kind: ImportExportKind; + } + + class Module { + constructor(bufferSource: __domTypes.BufferSource); + + /** Given a `Module` and string, returns a copy of the contents of all + * custom sections in the module with the given string name. */ + static customSections( + moduleObject: Module, + sectionName: string + ): ArrayBuffer; + + /** Given a `Module`, returns an array containing descriptions of all the + * declared exports. */ + static exports(moduleObject: Module): ModuleExportDescriptor[]; + + /** Given a `Module`, returns an array containing descriptions of all the + * declared imports. */ + static imports(moduleObject: Module): ModuleImportDescriptor[]; + } + + class Instance { + constructor(module: Module, importObject?: object); + + /** An object containing as its members all the functions exported from the + * WebAssembly module instance, to allow them to be accessed and used by + * JavaScript. */ + readonly exports: T; + } + + interface MemoryDescriptor { + initial: number; + maximum?: number; + } + + class Memory { + constructor(descriptor: MemoryDescriptor); + + /** An accessor property that returns the buffer contained in the memory. */ + readonly buffer: ArrayBuffer; + + /** Increases the size of the memory instance by a specified number of + * WebAssembly pages (each one is 64KB in size). */ + grow(delta: number): number; + } + + type TableKind = "anyfunc"; + + interface TableDescriptor { + element: TableKind; + initial: number; + maximum?: number; + } + + class Table { + constructor(descriptor: TableDescriptor); + + /** Returns the length of the table, i.e. the number of elements. */ + readonly length: number; + + /** Accessor function — gets the element stored at a given index. */ + get(index: number): (...args: any[]) => any; + + /** Increases the size of the Table instance by a specified number of + * elements. */ + grow(delta: number): number; + + /** Sets an element stored at a given index to a given value. */ + set(index: number, value: (...args: any[]) => any): void; + } + + type ValueType = "i32" | "i64" | "f32" | "f64"; + + interface GlobalDescriptor { + value: ValueType; + mutable?: boolean; + } + + /** Represents a global variable instance, accessible from both JavaScript and + * importable/exportable across one or more `WebAssembly.Module` instances. + * This allows dynamic linking of multiple modules. */ + class Global { + constructor(descriptor: GlobalDescriptor, value?: any); + + /** Old-style method that returns the value contained inside the global + * variable. */ + valueOf(): any; + + /** The value contained inside the global variable — this can be used to + * directly set and get the global's value. */ + value: any; + } + + /** Indicates an error during WebAssembly decoding or validation */ + class CompileError extends Error { + constructor(message: string, fileName?: string, lineNumber?: string); + } + + /** Indicates an error during module instantiation (besides traps from the + * start function). */ + class LinkError extends Error { + constructor(message: string, fileName?: string, lineNumber?: string); + } + + /** Is thrown whenever WebAssembly specifies a trap. */ + class RuntimeError extends Error { + constructor(message: string, fileName?: string, lineNumber?: string); + } +} + +declare namespace __domTypes { + // @url js/dom_types.d.ts + + export type BufferSource = ArrayBufferView | ArrayBuffer; + export type HeadersInit = + | Headers + | Array<[string, string]> + | Record; + export type URLSearchParamsInit = + | string + | string[][] + | Record; + type BodyInit = + | Blob + | BufferSource + | FormData + | URLSearchParams + | ReadableStream + | string; + export type RequestInfo = Request | string; + type ReferrerPolicy = + | "" + | "no-referrer" + | "no-referrer-when-downgrade" + | "origin-only" + | "origin-when-cross-origin" + | "unsafe-url"; + export type BlobPart = BufferSource | Blob | string; + export type FormDataEntryValue = DomFile | string; + export interface DomIterable { + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; + forEach( + callback: (value: V, key: K, parent: this) => void, + thisArg?: any + ): void; + } + type EndingType = "transparent" | "native"; + export interface BlobPropertyBag { + type?: string; + ending?: EndingType; + } + interface AbortSignalEventMap { + abort: ProgressEvent; + } + export enum NodeType { + ELEMENT_NODE = 1, + TEXT_NODE = 3, + DOCUMENT_FRAGMENT_NODE = 11 + } + export const eventTargetHost: unique symbol; + export const eventTargetListeners: unique symbol; + export const eventTargetMode: unique symbol; + export const eventTargetNodeType: unique symbol; + export interface EventTarget { + [eventTargetHost]: EventTarget | null; + [eventTargetListeners]: { [type in string]: EventListener[] }; + [eventTargetMode]: string; + [eventTargetNodeType]: NodeType; + addEventListener( + type: string, + callback: (event: Event) => void | null, + options?: boolean | AddEventListenerOptions + ): void; + dispatchEvent(event: Event): boolean; + removeEventListener( + type: string, + callback?: (event: Event) => void | null, + options?: EventListenerOptions | boolean + ): void; + } + export interface ProgressEventInit extends EventInit { + lengthComputable?: boolean; + loaded?: number; + total?: number; + } + export interface URLSearchParams extends DomIterable { + /** + * Appends a specified key/value pair as a new search parameter. + */ + append(name: string, value: string): void; + /** + * Deletes the given search parameter, and its associated value, + * from the list of all search parameters. + */ + delete(name: string): void; + /** + * Returns the first value associated to the given search parameter. + */ + get(name: string): string | null; + /** + * Returns all the values association with a given search parameter. + */ + getAll(name: string): string[]; + /** + * Returns a Boolean indicating if such a search parameter exists. + */ + has(name: string): boolean; + /** + * Sets the value associated to a given search parameter to the given value. + * If there were several values, delete the others. + */ + set(name: string, value: string): void; + /** + * Sort all key/value pairs contained in this object in place + * and return undefined. The sort order is according to Unicode + * code points of the keys. + */ + sort(): void; + /** + * Returns a query string suitable for use in a URL. + */ + toString(): string; + /** + * Iterates over each name-value pair in the query + * and invokes the given function. + */ + forEach( + callbackfn: (value: string, key: string, parent: this) => void, + thisArg?: any + ): void; + } + export interface EventListener { + handleEvent(event: Event): void; + readonly callback: (event: Event) => void | null; + readonly options: boolean | AddEventListenerOptions; + } + export interface EventInit { + bubbles?: boolean; + cancelable?: boolean; + composed?: boolean; + } + export interface CustomEventInit extends EventInit { + detail?: any; + } + export enum EventPhase { + NONE = 0, + CAPTURING_PHASE = 1, + AT_TARGET = 2, + BUBBLING_PHASE = 3 + } + export interface EventPath { + item: EventTarget; + itemInShadowTree: boolean; + relatedTarget: EventTarget | null; + rootOfClosedTree: boolean; + slotInClosedTree: boolean; + target: EventTarget | null; + touchTargetList: EventTarget[]; + } + export interface Event { + readonly type: string; + target: EventTarget | null; + currentTarget: EventTarget | null; + composedPath(): EventPath[]; + eventPhase: number; + stopPropagation(): void; + stopImmediatePropagation(): void; + readonly bubbles: boolean; + readonly cancelable: boolean; + preventDefault(): void; + readonly defaultPrevented: boolean; + readonly composed: boolean; + isTrusted: boolean; + readonly timeStamp: Date; + dispatched: boolean; + readonly initialized: boolean; + inPassiveListener: boolean; + cancelBubble: boolean; + cancelBubbleImmediately: boolean; + path: EventPath[]; + relatedTarget: EventTarget | null; + } + export interface CustomEvent extends Event { + readonly detail: any; + initCustomEvent( + type: string, + bubbles?: boolean, + cancelable?: boolean, + detail?: any | null + ): void; + } + export interface DomFile extends Blob { + readonly lastModified: number; + readonly name: string; + } + export interface DomFileConstructor { + new ( + bits: BlobPart[], + filename: string, + options?: FilePropertyBag + ): DomFile; + prototype: DomFile; + } + export interface FilePropertyBag extends BlobPropertyBag { + lastModified?: number; + } + interface ProgressEvent extends Event { + readonly lengthComputable: boolean; + readonly loaded: number; + readonly total: number; + } + export interface EventListenerOptions { + capture: boolean; + } + export interface AddEventListenerOptions extends EventListenerOptions { + once: boolean; + passive: boolean; + } + interface AbortSignal extends EventTarget { + readonly aborted: boolean; + onabort: ((this: AbortSignal, ev: ProgressEvent) => any) | null; + addEventListener( + type: K, + listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, + options?: boolean | AddEventListenerOptions + ): void; + addEventListener( + type: string, + listener: EventListener, + options?: boolean | AddEventListenerOptions + ): void; + removeEventListener( + type: K, + listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, + options?: boolean | EventListenerOptions + ): void; + removeEventListener( + type: string, + listener: EventListener, + options?: boolean | EventListenerOptions + ): void; + } + export interface ReadableStream { + readonly locked: boolean; + cancel(): Promise; + getReader(): ReadableStreamReader; + tee(): [ReadableStream, ReadableStream]; + } + export interface ReadableStreamReader { + cancel(): Promise; + read(): Promise; + releaseLock(): void; + } + export interface FormData extends DomIterable { + append(name: string, value: string | Blob, fileName?: string): void; + delete(name: string): void; + get(name: string): FormDataEntryValue | null; + getAll(name: string): FormDataEntryValue[]; + has(name: string): boolean; + set(name: string, value: string | Blob, fileName?: string): void; + } + export interface FormDataConstructor { + new (): FormData; + prototype: FormData; + } + /** A blob object represents a file-like object of immutable, raw data. */ + export interface Blob { + /** The size, in bytes, of the data contained in the `Blob` object. */ + readonly size: number; + /** A string indicating the media type of the data contained in the `Blob`. + * If the type is unknown, this string is empty. + */ + readonly type: string; + /** Returns a new `Blob` object containing the data in the specified range of + * bytes of the source `Blob`. + */ + slice(start?: number, end?: number, contentType?: string): Blob; + } + export interface Body { + /** A simple getter used to expose a `ReadableStream` of the body contents. */ + readonly body: ReadableStream | null; + /** Stores a `Boolean` that declares whether the body has been used in a + * response yet. + */ + readonly bodyUsed: boolean; + /** Takes a `Response` stream and reads it to completion. It returns a promise + * that resolves with an `ArrayBuffer`. + */ + arrayBuffer(): Promise; + /** Takes a `Response` stream and reads it to completion. It returns a promise + * that resolves with a `Blob`. + */ + blob(): Promise; + /** Takes a `Response` stream and reads it to completion. It returns a promise + * that resolves with a `FormData` object. + */ + formData(): Promise; + /** Takes a `Response` stream and reads it to completion. It returns a promise + * that resolves with the result of parsing the body text as JSON. + */ + json(): Promise; + /** Takes a `Response` stream and reads it to completion. It returns a promise + * that resolves with a `USVString` (text). + */ + text(): Promise; + } + export interface Headers extends DomIterable { + /** Appends a new value onto an existing header inside a `Headers` object, or + * adds the header if it does not already exist. + */ + append(name: string, value: string): void; + /** Deletes a header from a `Headers` object. */ + delete(name: string): void; + /** Returns an iterator allowing to go through all key/value pairs + * contained in this Headers object. The both the key and value of each pairs + * are ByteString objects. + */ + entries(): IterableIterator<[string, string]>; + /** Returns a `ByteString` sequence of all the values of a header within a + * `Headers` object with a given name. + */ + get(name: string): string | null; + /** Returns a boolean stating whether a `Headers` object contains a certain + * header. + */ + has(name: string): boolean; + /** Returns an iterator allowing to go through all keys contained in + * this Headers object. The keys are ByteString objects. + */ + keys(): IterableIterator; + /** Sets a new value for an existing header inside a Headers object, or adds + * the header if it does not already exist. + */ + set(name: string, value: string): void; + /** Returns an iterator allowing to go through all values contained in + * this Headers object. The values are ByteString objects. + */ + values(): IterableIterator; + forEach( + callbackfn: (value: string, key: string, parent: this) => void, + thisArg?: any + ): void; + /** The Symbol.iterator well-known symbol specifies the default + * iterator for this Headers object + */ + [Symbol.iterator](): IterableIterator<[string, string]>; + } + export interface HeadersConstructor { + new (init?: HeadersInit): Headers; + prototype: Headers; + } + type RequestCache = + | "default" + | "no-store" + | "reload" + | "no-cache" + | "force-cache" + | "only-if-cached"; + type RequestCredentials = "omit" | "same-origin" | "include"; + type RequestDestination = + | "" + | "audio" + | "audioworklet" + | "document" + | "embed" + | "font" + | "image" + | "manifest" + | "object" + | "paintworklet" + | "report" + | "script" + | "sharedworker" + | "style" + | "track" + | "video" + | "worker" + | "xslt"; + type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors"; + type RequestRedirect = "follow" | "error" | "manual"; + type ResponseType = + | "basic" + | "cors" + | "default" + | "error" + | "opaque" + | "opaqueredirect"; + export interface RequestInit { + body?: BodyInit | null; + cache?: RequestCache; + credentials?: RequestCredentials; + headers?: HeadersInit; + integrity?: string; + keepalive?: boolean; + method?: string; + mode?: RequestMode; + redirect?: RequestRedirect; + referrer?: string; + referrerPolicy?: ReferrerPolicy; + signal?: AbortSignal | null; + window?: any; + } + export interface ResponseInit { + headers?: HeadersInit; + status?: number; + statusText?: string; + } + export interface RequestConstructor { + new (input: RequestInfo, init?: RequestInit): Request; + prototype: Request; + } + export interface Request extends Body { + /** Returns the cache mode associated with request, which is a string + * indicating how the the request will interact with the browser's cache when + * fetching. + */ + readonly cache?: RequestCache; + /** Returns the credentials mode associated with request, which is a string + * indicating whether credentials will be sent with the request always, never, + * or only when sent to a same-origin URL. + */ + readonly credentials?: RequestCredentials; + /** Returns the kind of resource requested by request, (e.g., `document` or + * `script`). + */ + readonly destination?: RequestDestination; + /** Returns a Headers object consisting of the headers associated with + * request. + * + * Note that headers added in the network layer by the user agent + * will not be accounted for in this object, (e.g., the `Host` header). + */ + readonly headers: Headers; + /** Returns request's subresource integrity metadata, which is a cryptographic + * hash of the resource being fetched. Its value consists of multiple hashes + * separated by whitespace. [SRI] + */ + readonly integrity?: string; + /** Returns a boolean indicating whether or not request is for a history + * navigation (a.k.a. back-forward navigation). + */ + readonly isHistoryNavigation?: boolean; + /** Returns a boolean indicating whether or not request is for a reload + * navigation. + */ + readonly isReloadNavigation?: boolean; + /** Returns a boolean indicating whether or not request can outlive the global + * in which it was created. + */ + readonly keepalive?: boolean; + /** Returns request's HTTP method, which is `GET` by default. */ + readonly method: string; + /** Returns the mode associated with request, which is a string indicating + * whether the request will use CORS, or will be restricted to same-origin + * URLs. + */ + readonly mode?: RequestMode; + /** Returns the redirect mode associated with request, which is a string + * indicating how redirects for the request will be handled during fetching. + * + * A request will follow redirects by default. + */ + readonly redirect?: RequestRedirect; + /** Returns the referrer of request. Its value can be a same-origin URL if + * explicitly set in init, the empty string to indicate no referrer, and + * `about:client` when defaulting to the global's default. + * + * This is used during fetching to determine the value of the `Referer` + * header of the request being made. + */ + readonly referrer?: string; + /** Returns the referrer policy associated with request. This is used during + * fetching to compute the value of the request's referrer. + */ + readonly referrerPolicy?: ReferrerPolicy; + /** Returns the signal associated with request, which is an AbortSignal object + * indicating whether or not request has been aborted, and its abort event + * handler. + */ + readonly signal?: AbortSignal; + /** Returns the URL of request as a string. */ + readonly url: string; + clone(): Request; + } + export interface Response extends Body { + /** Contains the `Headers` object associated with the response. */ + readonly headers: Headers; + /** Contains a boolean stating whether the response was successful (status in + * the range 200-299) or not. + */ + readonly ok: boolean; + /** Indicates whether or not the response is the result of a redirect; that + * is, its URL list has more than one entry. + */ + readonly redirected: boolean; + /** Contains the status code of the response (e.g., `200` for a success). */ + readonly status: number; + /** Contains the status message corresponding to the status code (e.g., `OK` + * for `200`). + */ + readonly statusText: string; + readonly trailer: Promise; + /** Contains the type of the response (e.g., `basic`, `cors`). */ + readonly type: ResponseType; + /** Contains the URL of the response. */ + readonly url: string; + /** Creates a clone of a `Response` object. */ + clone(): Response; + } + export interface Location { + /** + * Returns a DOMStringList object listing the origins of the ancestor browsing + * contexts, from the parent browsing context to the top-level browsing + * context. + */ + readonly ancestorOrigins: string[]; + /** + * Returns the Location object's URL's fragment (includes leading "#" if + * non-empty). + * Can be set, to navigate to the same URL with a changed fragment (ignores + * leading "#"). + */ + hash: string; + /** + * Returns the Location object's URL's host and port (if different from the + * default port for the scheme). Can be set, to navigate to the same URL with + * a changed host and port. + */ + host: string; + /** + * Returns the Location object's URL's host. Can be set, to navigate to the + * same URL with a changed host. + */ + hostname: string; + /** + * Returns the Location object's URL. Can be set, to navigate to the given + * URL. + */ + href: string; + /** Returns the Location object's URL's origin. */ + readonly origin: string; + /** + * Returns the Location object's URL's path. + * Can be set, to navigate to the same URL with a changed path. + */ + pathname: string; + /** + * Returns the Location object's URL's port. + * Can be set, to navigate to the same URL with a changed port. + */ + port: string; + /** + * Returns the Location object's URL's scheme. + * Can be set, to navigate to the same URL with a changed scheme. + */ + protocol: string; + /** + * Returns the Location object's URL's query (includes leading "?" if + * non-empty). Can be set, to navigate to the same URL with a changed query + * (ignores leading "?"). + */ + search: string; + /** + * Navigates to the given URL. + */ + assign(url: string): void; + /** + * Reloads the current page. + */ + reload(): void; + /** @deprecated */ + reload(forcedReload: boolean): void; + /** + * Removes the current page from the session history and navigates to the + * given URL. + */ + replace(url: string): void; + } +} + +declare namespace __blob { + // @url js/blob.d.ts + + export const bytesSymbol: unique symbol; + export const blobBytesWeakMap: WeakMap<__domTypes.Blob, Uint8Array>; + export class DenoBlob implements __domTypes.Blob { + private readonly [bytesSymbol]; + readonly size: number; + readonly type: string; + /** A blob object represents a file-like object of immutable, raw data. */ + constructor( + blobParts?: __domTypes.BlobPart[], + options?: __domTypes.BlobPropertyBag + ); + slice(start?: number, end?: number, contentType?: string): DenoBlob; + } +} + +declare namespace __console { + // @url js/console.d.ts + + type ConsoleOptions = Partial<{ + showHidden: boolean; + depth: number; + colors: boolean; + indentLevel: number; + }>; + export class CSI { + static kClear: string; + static kClearScreenDown: string; + } + const isConsoleInstance: unique symbol; + export class Console { + private printFunc; + indentLevel: number; + [isConsoleInstance]: boolean; + /** Writes the arguments to stdout */ + log: (...args: unknown[]) => void; + /** Writes the arguments to stdout */ + debug: (...args: unknown[]) => void; + /** Writes the arguments to stdout */ + info: (...args: unknown[]) => void; + /** Writes the properties of the supplied `obj` to stdout */ + dir: ( + obj: unknown, + options?: Partial<{ + showHidden: boolean; + depth: number; + colors: boolean; + indentLevel: number; + }> + ) => void; + + /** From MDN: + * Displays an interactive tree of the descendant elements of + * the specified XML/HTML element. If it is not possible to display + * as an element the JavaScript Object view is shown instead. + * The output is presented as a hierarchical listing of expandable + * nodes that let you see the contents of child nodes. + * + * Since we write to stdout, we can't display anything interactive + * we just fall back to `console.dir`. + */ + dirxml: ( + obj: unknown, + options?: Partial<{ + showHidden: boolean; + depth: number; + colors: boolean; + indentLevel: number; + }> + ) => void; + + /** Writes the arguments to stdout */ + warn: (...args: unknown[]) => void; + /** Writes the arguments to stdout */ + error: (...args: unknown[]) => void; + /** Writes an error message to stdout if the assertion is `false`. If the + * assertion is `true`, nothing happens. + * + * ref: https://console.spec.whatwg.org/#assert + */ + assert: (condition?: boolean, ...args: unknown[]) => void; + count: (label?: string) => void; + countReset: (label?: string) => void; + table: (data: unknown, properties?: string[] | undefined) => void; + time: (label?: string) => void; + timeLog: (label?: string, ...args: unknown[]) => void; + timeEnd: (label?: string) => void; + group: (...label: unknown[]) => void; + groupCollapsed: (...label: unknown[]) => void; + groupEnd: () => void; + clear: () => void; + trace: (...args: unknown[]) => void; + static [Symbol.hasInstance](instance: Console): boolean; + } + /** A symbol which can be used as a key for a custom method which will be called + * when `Deno.inspect()` is called, or when the object is logged to the console. + */ + export const customInspect: unique symbol; + /** + * `inspect()` converts input into string that has the same format + * as printed by `console.log(...)`; + */ + export function inspect(value: unknown, options?: ConsoleOptions): string; +} + +declare namespace __event { + // @url js/event.d.ts + + export const eventAttributes: WeakMap; + export class EventInit implements __domTypes.EventInit { + bubbles: boolean; + cancelable: boolean; + composed: boolean; + constructor({ + bubbles, + cancelable, + composed + }?: { + bubbles?: boolean | undefined; + cancelable?: boolean | undefined; + composed?: boolean | undefined; + }); + } + export class Event implements __domTypes.Event { + isTrusted: boolean; + private _canceledFlag; + private _dispatchedFlag; + private _initializedFlag; + private _inPassiveListenerFlag; + private _stopImmediatePropagationFlag; + private _stopPropagationFlag; + private _path; + constructor(type: string, eventInitDict?: __domTypes.EventInit); + readonly bubbles: boolean; + cancelBubble: boolean; + cancelBubbleImmediately: boolean; + readonly cancelable: boolean; + readonly composed: boolean; + currentTarget: __domTypes.EventTarget; + readonly defaultPrevented: boolean; + dispatched: boolean; + eventPhase: number; + readonly initialized: boolean; + inPassiveListener: boolean; + path: __domTypes.EventPath[]; + relatedTarget: __domTypes.EventTarget; + target: __domTypes.EventTarget; + readonly timeStamp: Date; + readonly type: string; + /** Returns the event’s path (objects on which listeners will be + * invoked). This does not include nodes in shadow trees if the + * shadow root was created with its ShadowRoot.mode closed. + * + * event.composedPath(); + */ + composedPath(): __domTypes.EventPath[]; + /** Cancels the event (if it is cancelable). + * See https://dom.spec.whatwg.org/#set-the-canceled-flag + * + * event.preventDefault(); + */ + preventDefault(): void; + /** Stops the propagation of events further along in the DOM. + * + * event.stopPropagation(); + */ + stopPropagation(): void; + /** For this particular event, no other listener will be called. + * Neither those attached on the same element, nor those attached + * on elements which will be traversed later (in capture phase, + * for instance). + * + * event.stopImmediatePropagation(); + */ + stopImmediatePropagation(): void; + } +} + +declare namespace __customEvent { + // @url js/custom_event.d.ts + + export const customEventAttributes: WeakMap; + export class CustomEventInit extends __event.EventInit + implements __domTypes.CustomEventInit { + detail: any; + constructor({ + bubbles, + cancelable, + composed, + detail + }: __domTypes.CustomEventInit); + } + export class CustomEvent extends __event.Event + implements __domTypes.CustomEvent { + constructor(type: string, customEventInitDict?: __domTypes.CustomEventInit); + readonly detail: any; + initCustomEvent( + type: string, + bubbles?: boolean, + cancelable?: boolean, + detail?: any + ): void; + readonly [Symbol.toStringTag]: string; + } +} + +declare namespace __eventTarget { + // @url js/event_target.d.ts + + export class EventListenerOptions implements __domTypes.EventListenerOptions { + _capture: boolean; + constructor({ capture }?: { capture?: boolean | undefined }); + readonly capture: boolean; + } + export class AddEventListenerOptions extends EventListenerOptions + implements __domTypes.AddEventListenerOptions { + _passive: boolean; + _once: boolean; + constructor({ + capture, + passive, + once + }?: { + capture?: boolean | undefined; + passive?: boolean | undefined; + once?: boolean | undefined; + }); + readonly passive: boolean; + readonly once: boolean; + } + export class EventListener implements __domTypes.EventListener { + allEvents: __domTypes.Event[]; + atEvents: __domTypes.Event[]; + bubbledEvents: __domTypes.Event[]; + capturedEvents: __domTypes.Event[]; + private _callback; + private _options; + constructor( + callback: (event: __domTypes.Event) => void | null, + options: boolean | __domTypes.AddEventListenerOptions + ); + handleEvent(event: __domTypes.Event): void; + readonly callback: (event: __domTypes.Event) => void | null; + readonly options: __domTypes.AddEventListenerOptions | boolean; + } + export const eventTargetAssignedSlot: unique symbol; + export const eventTargetHasActivationBehavior: unique symbol; + export class EventTarget implements __domTypes.EventTarget { + [__domTypes.eventTargetHost]: __domTypes.EventTarget | null; + [__domTypes.eventTargetListeners]: { + [type in string]: __domTypes.EventListener[]; + }; + [__domTypes.eventTargetMode]: string; + [__domTypes.eventTargetNodeType]: __domTypes.NodeType; + private [eventTargetAssignedSlot]; + private [eventTargetHasActivationBehavior]; + addEventListener( + type: string, + callback: (event: __domTypes.Event) => void | null, + options?: __domTypes.AddEventListenerOptions | boolean + ): void; + removeEventListener( + type: string, + callback: (event: __domTypes.Event) => void | null, + options?: __domTypes.EventListenerOptions | boolean + ): void; + dispatchEvent(event: __domTypes.Event): boolean; + readonly [Symbol.toStringTag]: string; + } +} + +declare namespace __io { + /** UNSTABLE: maybe remove "SEEK_" prefix. Maybe capitalization wrong. */ + export enum SeekMode { + SEEK_START = 0, + SEEK_CURRENT = 1, + SEEK_END = 2 + } + export interface Reader { + /** Reads up to p.byteLength bytes into `p`. It resolves to the number + * of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error encountered. + * Even if `read()` returns `n` < `p.byteLength`, it may use all of `p` as + * scratch space during the call. If some data is available but not + * `p.byteLength` bytes, `read()` conventionally returns what is available + * instead of waiting for more. + * + * When `read()` encounters end-of-file condition, it returns EOF symbol. + * + * When `read()` encounters an error, it rejects with an error. + * + * Callers should always process the `n` > `0` bytes returned before + * considering the EOF. Doing so correctly handles I/O errors that happen + * after reading some bytes and also both of the allowed EOF behaviors. + * + * Implementations must not retain `p`. + */ + read(p: Uint8Array): Promise; + } + export interface SyncReader { + readSync(p: Uint8Array): number | Deno.EOF; + } + export interface Writer { + /** Writes `p.byteLength` bytes from `p` to the underlying data + * stream. It resolves to the number of bytes written from `p` (`0` <= `n` <= + * `p.byteLength`) and any error encountered that caused the write to stop + * early. `write()` must return a non-null error if it returns `n` < + * `p.byteLength`. write() must not modify the slice data, even temporarily. + * + * Implementations must not retain `p`. + */ + write(p: Uint8Array): Promise; + } + export interface SyncWriter { + writeSync(p: Uint8Array): number; + } + export interface Closer { + close(): void; + } + export interface Seeker { + /** Seek sets the offset for the next `read()` or `write()` to offset, + * interpreted according to `whence`: `SeekStart` means relative to the start + * of the file, `SeekCurrent` means relative to the current offset, and + * `SeekEnd` means relative to the end. Seek returns the new offset relative + * to the start of the file and an error, if any. + * + * Seeking to an offset before the start of the file is an error. Seeking to + * any positive offset is legal, but the behavior of subsequent I/O operations + * on the underlying object is implementation-dependent. + */ + seek(offset: number, whence: SeekMode): Promise; + } + export interface SyncSeeker { + seekSync(offset: number, whence: SeekMode): void; + } + export interface ReadCloser extends Reader, Closer {} + export interface WriteCloser extends Writer, Closer {} + export interface ReadSeeker extends Reader, Seeker {} + export interface WriteSeeker extends Writer, Seeker {} + export interface ReadWriteCloser extends Reader, Writer, Closer {} + export interface ReadWriteSeeker extends Reader, Writer, Seeker {} + + /** UNSTABLE: controversial. + * + * Copies from `src` to `dst` until either `EOF` is reached on `src` + * or an error occurs. It returns the number of bytes copied and the first + * error encountered while copying, if any. + * + * Because `copy()` is defined to read from `src` until `EOF`, it does not + * treat an `EOF` from `read()` as an error to be reported. + */ + export function copy(dst: Writer, src: Reader): Promise; + + /** UNSTABLE: Make Reader into AsyncIterable? Remove this? + * + * Turns `r` into async iterator. + * + * for await (const chunk of toAsyncIterator(reader)) { + * console.log(chunk) + * } + */ + export function toAsyncIterator(r: Reader): AsyncIterableIterator; +} + +declare namespace __fetch { + // @url js/fetch.d.ts + + class Body + implements __domTypes.Body, __domTypes.ReadableStream, __io.ReadCloser { + private rid; + readonly contentType: string; + bodyUsed: boolean; + private _bodyPromise; + private _data; + readonly locked: boolean; + readonly body: null | Body; + constructor(rid: number, contentType: string); + private _bodyBuffer; + arrayBuffer(): Promise; + blob(): Promise<__domTypes.Blob>; + formData(): Promise<__domTypes.FormData>; + json(): Promise; + text(): Promise; + read(p: Uint8Array): Promise; + close(): void; + cancel(): Promise; + getReader(): __domTypes.ReadableStreamReader; + tee(): [__domTypes.ReadableStream, __domTypes.ReadableStream]; + [Symbol.asyncIterator](): AsyncIterableIterator; + } + export class Response implements __domTypes.Response { + readonly url: string; + readonly status: number; + statusText: string; + readonly type = "basic"; + readonly redirected: boolean; + headers: __domTypes.Headers; + readonly trailer: Promise<__domTypes.Headers>; + bodyUsed: boolean; + readonly body: Body; + constructor( + url: string, + status: number, + headersList: Array<[string, string]>, + rid: number, + redirected_: boolean, + body_?: null | Body + ); + arrayBuffer(): Promise; + blob(): Promise<__domTypes.Blob>; + formData(): Promise<__domTypes.FormData>; + json(): Promise; + text(): Promise; + readonly ok: boolean; + clone(): __domTypes.Response; + } + /** Fetch a resource from the network. */ + export function fetch( + input: __domTypes.Request | __url.URL | string, + init?: __domTypes.RequestInit + ): Promise; +} + +declare namespace __textEncoding { + // @url js/text_encoding.d.ts + + export function atob(s: string): string; + /** Creates a base-64 ASCII string from the input string. */ + export function btoa(s: string): string; + export interface TextDecodeOptions { + stream?: false; + } + export interface TextDecoderOptions { + fatal?: boolean; + ignoreBOM?: boolean; + } + export class TextDecoder { + private _encoding; + /** Returns encoding's name, lowercased. */ + readonly encoding: string; + /** Returns `true` if error mode is "fatal", and `false` otherwise. */ + readonly fatal: boolean; + /** Returns `true` if ignore BOM flag is set, and `false` otherwise. */ + readonly ignoreBOM = false; + constructor(label?: string, options?: TextDecoderOptions); + /** Returns the result of running encoding's decoder. */ + decode( + input?: __domTypes.BufferSource, + options?: TextDecodeOptions + ): string; + readonly [Symbol.toStringTag]: string; + } + interface TextEncoderEncodeIntoResult { + read: number; + written: number; + } + export class TextEncoder { + /** Returns "utf-8". */ + readonly encoding = "utf-8"; + /** Returns the result of running UTF-8's encoder. */ + encode(input?: string): Uint8Array; + encodeInto(input: string, dest: Uint8Array): TextEncoderEncodeIntoResult; + readonly [Symbol.toStringTag]: string; + } +} + +declare namespace __timers { + // @url js/timers.d.ts + + export type Args = unknown[]; + /** Sets a timer which executes a function once after the timer expires. */ + export function setTimeout( + cb: (...args: Args) => void, + delay?: number, + ...args: Args + ): number; + /** Repeatedly calls a function , with a fixed time delay between each call. */ + export function setInterval( + cb: (...args: Args) => void, + delay?: number, + ...args: Args + ): number; + export function clearTimeout(id?: number): void; + export function clearInterval(id?: number): void; +} + +declare namespace __urlSearchParams { + // @url js/url_search_params.d.ts + + export class URLSearchParams { + private params; + private url; + constructor(init?: string | string[][] | Record); + private updateSteps; + /** Appends a specified key/value pair as a new search parameter. + * + * searchParams.append('name', 'first'); + * searchParams.append('name', 'second'); + */ + append(name: string, value: string): void; + /** Deletes the given search parameter and its associated value, + * from the list of all search parameters. + * + * searchParams.delete('name'); + */ + delete(name: string): void; + /** Returns all the values associated with a given search parameter + * as an array. + * + * searchParams.getAll('name'); + */ + getAll(name: string): string[]; + /** Returns the first value associated to the given search parameter. + * + * searchParams.get('name'); + */ + get(name: string): string | null; + /** Returns a Boolean that indicates whether a parameter with the + * specified name exists. + * + * searchParams.has('name'); + */ + has(name: string): boolean; + /** Sets the value associated with a given search parameter to the + * given value. If there were several matching values, this method + * deletes the others. If the search parameter doesn't exist, this + * method creates it. + * + * searchParams.set('name', 'value'); + */ + set(name: string, value: string): void; + /** Sort all key/value pairs contained in this object in place and + * return undefined. The sort order is according to Unicode code + * points of the keys. + * + * searchParams.sort(); + */ + sort(): void; + /** Calls a function for each element contained in this object in + * place and return undefined. Optionally accepts an object to use + * as this when executing callback as second argument. + * + * searchParams.forEach((value, key, parent) => { + * console.log(value, key, parent); + * }); + * + */ + forEach( + callbackfn: (value: string, key: string, parent: this) => void, + thisArg?: any + ): void; + /** Returns an iterator allowing to go through all keys contained + * in this object. + * + * for (const key of searchParams.keys()) { + * console.log(key); + * } + */ + keys(): IterableIterator; + /** Returns an iterator allowing to go through all values contained + * in this object. + * + * for (const value of searchParams.values()) { + * console.log(value); + * } + */ + values(): IterableIterator; + /** Returns an iterator allowing to go through all key/value + * pairs contained in this object. + * + * for (const [key, value] of searchParams.entries()) { + * console.log(key, value); + * } + */ + entries(): IterableIterator<[string, string]>; + /** Returns an iterator allowing to go through all key/value + * pairs contained in this object. + * + * for (const [key, value] of searchParams[Symbol.iterator]()) { + * console.log(key, value); + * } + */ + [Symbol.iterator](): IterableIterator<[string, string]>; + /** Returns a query string suitable for use in a URL. + * + * searchParams.toString(); + */ + toString(): string; + private _handleStringInitialization; + private _handleArrayInitialization; + } +} + +declare namespace __url { + // @url js/url.d.ts + export interface URL { + hash: string; + host: string; + hostname: string; + href: string; + readonly origin: string; + password: string; + pathname: string; + port: string; + protocol: string; + search: string; + readonly searchParams: __urlSearchParams.URLSearchParams; + username: string; + toString(): string; + toJSON(): string; + } + + export const URL: { + prototype: URL; + new (url: string, base?: string | URL): URL; + createObjectURL(object: __domTypes.Blob): string; + revokeObjectURL(url: string): void; + }; +} + +declare namespace __workerMain { + export let onmessage: (e: { data: any }) => void; + export function postMessage(data: any): void; + export function getMessage(): Promise; + export let isClosing: boolean; + export function workerClose(): void; + export function bootstrapWorkerRuntime(): Promise; +} + +declare namespace __workers { + // @url js/workers.d.ts + export interface Worker { + onerror?: (e: Event) => void; + onmessage?: (e: { data: any }) => void; + onmessageerror?: () => void; + postMessage(data: any): void; + } + export interface WorkerOptions { + type?: "classic" | "module"; + } + export class WorkerImpl implements Worker { + private readonly id; + private isClosing; + private readonly isClosedPromise; + onerror?: (e: Event) => void; + onmessage?: (data: any) => void; + onmessageerror?: () => void; + constructor(specifier: string, options?: WorkerOptions); + postMessage(data: any): void; + private run; + } +} + +declare namespace __performanceUtil { + // @url js/performance.d.ts + + export class Performance { + /** Returns a current time from Deno's start in milliseconds. + * + * Use the flag --allow-hrtime return a precise value. + * + * const t = performance.now(); + * console.log(`${t} ms since start!`); + */ + now(): number; + } +} + +/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-interface, @typescript-eslint/no-explicit-any */ diff --git a/cli/js/lib.deno_worker.d.ts b/cli/js/lib.deno_worker.d.ts new file mode 100644 index 0000000000..d7652807dc --- /dev/null +++ b/cli/js/lib.deno_worker.d.ts @@ -0,0 +1,5 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +/// +/// +/// diff --git a/cli/js/lib.web_assembly.d.ts b/cli/js/lib.web_assembly.d.ts deleted file mode 100644 index 8c357840a3..0000000000 --- a/cli/js/lib.web_assembly.d.ts +++ /dev/null @@ -1,173 +0,0 @@ -// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/ -// And follow on WebIDL at: https://webassembly.github.io/spec/web-api/ - -/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */ - -declare namespace WebAssembly { - interface WebAssemblyInstantiatedSource { - module: Module; - instance: Instance; - } - - /** Compiles a `WebAssembly.Module` from WebAssembly binary code. This - * function is useful if it is necessary to a compile a module before it can - * be instantiated (otherwise, the `WebAssembly.instantiate()` function - * should be used). */ - function compile(bufferSource: domTypes.BufferSource): Promise; - - /** Compiles a `WebAssembly.Module` directly from a streamed underlying - * source. This function is useful if it is necessary to a compile a module - * before it can be instantiated (otherwise, the - * `WebAssembly.instantiateStreaming()` function should be used). */ - function compileStreaming( - source: Promise - ): Promise; - - /** Takes the WebAssembly binary code, in the form of a typed array or - * `ArrayBuffer`, and performs both compilation and instantiation in one step. - * The returned `Promise` resolves to both a compiled `WebAssembly.Module` and - * its first `WebAssembly.Instance`. */ - function instantiate( - bufferSource: domTypes.BufferSource, - importObject?: object - ): Promise; - - /** Takes an already-compiled `WebAssembly.Module` and returns a `Promise` - * that resolves to an `Instance` of that `Module`. This overload is useful if - * the `Module` has already been compiled. */ - function instantiate( - module: Module, - importObject?: object - ): Promise; - - /** Compiles and instantiates a WebAssembly module directly from a streamed - * underlying source. This is the most efficient, optimized way to load wasm - * code. */ - function instantiateStreaming( - source: Promise, - importObject?: object - ): Promise; - - /** Validates a given typed array of WebAssembly binary code, returning - * whether the bytes form a valid wasm module (`true`) or not (`false`). */ - function validate(bufferSource: domTypes.BufferSource): boolean; - - type ImportExportKind = "function" | "table" | "memory" | "global"; - - interface ModuleExportDescriptor { - name: string; - kind: ImportExportKind; - } - interface ModuleImportDescriptor { - module: string; - name: string; - kind: ImportExportKind; - } - - class Module { - constructor(bufferSource: domTypes.BufferSource); - - /** Given a `Module` and string, returns a copy of the contents of all - * custom sections in the module with the given string name. */ - static customSections( - moduleObject: Module, - sectionName: string - ): ArrayBuffer; - - /** Given a `Module`, returns an array containing descriptions of all the - * declared exports. */ - static exports(moduleObject: Module): ModuleExportDescriptor[]; - - /** Given a `Module`, returns an array containing descriptions of all the - * declared imports. */ - static imports(moduleObject: Module): ModuleImportDescriptor[]; - } - - class Instance { - constructor(module: Module, importObject?: object); - - /** An object containing as its members all the functions exported from the - * WebAssembly module instance, to allow them to be accessed and used by - * JavaScript. */ - readonly exports: T; - } - - interface MemoryDescriptor { - initial: number; - maximum?: number; - } - - class Memory { - constructor(descriptor: MemoryDescriptor); - - /** An accessor property that returns the buffer contained in the memory. */ - readonly buffer: ArrayBuffer; - - /** Increases the size of the memory instance by a specified number of - * WebAssembly pages (each one is 64KB in size). */ - grow(delta: number): number; - } - - type TableKind = "anyfunc"; - - interface TableDescriptor { - element: TableKind; - initial: number; - maximum?: number; - } - - class Table { - constructor(descriptor: TableDescriptor); - - /** Returns the length of the table, i.e. the number of elements. */ - readonly length: number; - - /** Accessor function — gets the element stored at a given index. */ - get(index: number): (...args: any[]) => any; - - /** Increases the size of the Table instance by a specified number of - * elements. */ - grow(delta: number): number; - - /** Sets an element stored at a given index to a given value. */ - set(index: number, value: (...args: any[]) => any): void; - } - - interface GlobalDescriptor { - value: string; - mutable?: boolean; - } - - /** Represents a global variable instance, accessible from both JavaScript and - * importable/exportable across one or more `WebAssembly.Module` instances. - * This allows dynamic linking of multiple modules. */ - class Global { - constructor(descriptor: GlobalDescriptor, value?: any); - - /** Old-style method that returns the value contained inside the global - * variable. */ - valueOf(): any; - - /** The value contained inside the global variable — this can be used to - * directly set and get the global's value. */ - value: any; - } - - /** Indicates an error during WebAssembly decoding or validation */ - class CompileError extends Error { - constructor(message: string, fileName?: string, lineNumber?: string); - } - - /** Indicates an error during module instantiation (besides traps from the - * start function). */ - class LinkError extends Error { - constructor(message: string, fileName?: string, lineNumber?: string); - } - - /** Is thrown whenever WebAssembly specifies a trap. */ - class RuntimeError extends Error { - constructor(message: string, fileName?: string, lineNumber?: string); - } -} - -/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */ diff --git a/cli/lib.rs b/cli/lib.rs index 4a08f40c60..a650b4d448 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -146,7 +146,7 @@ fn create_worker_and_state( } fn types_command() { - println!("{}", crate::js::DENO_RUNTIME); + println!("{}\n{}", crate::js::DENO_NS_LIB, crate::js::DENO_MAIN_LIB); } fn print_cache_info(worker: MainWorker) { diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs index 2d908cf8b5..8133a2886f 100644 --- a/deno_typescript/lib.rs +++ b/deno_typescript/lib.rs @@ -280,6 +280,7 @@ pub fn get_asset(name: &str) -> Option<&'static str> { "lib.esnext.bigint.d.ts" => inc!("lib.esnext.bigint.d.ts"), "lib.esnext.intl.d.ts" => inc!("lib.esnext.intl.d.ts"), "lib.esnext.symbol.d.ts" => inc!("lib.esnext.symbol.d.ts"), + "lib.webworker.d.ts" => inc!("lib.webworker.d.ts"), _ => None, } }