From d632cce129cb7025a34cf0aa7262a38fb12f47c4 Mon Sep 17 00:00:00 2001 From: ud2 Date: Tue, 4 Jul 2023 02:36:55 +0800 Subject: fix(dts): make globals available on globalThis (#19438) This PR changes Web IDL interfaces to be declared with `var` instead of `class`, so that accessing them via `globalThis` does not raise type errors. Closes #13390. --- .../lib.deno_broadcast_channel.d.ts | 6 +- ext/cache/lib.deno_cache.d.ts | 10 +- ext/crypto/lib.deno_crypto.d.ts | 93 ++--- ext/fetch/lib.deno_fetch.d.ts | 183 +++------ ext/url/lib.deno_url.d.ts | 88 ++++- ext/web/lib.deno_web.d.ts | 426 +++++++++++++++------ ext/websocket/lib.deno_websocket.d.ts | 35 +- ext/webstorage/lib.deno_webstorage.d.ts | 6 +- 8 files changed, 516 insertions(+), 331 deletions(-) (limited to 'ext') diff --git a/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts b/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts index ea01bef36..1ffd6532d 100644 --- a/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts +++ b/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts @@ -6,13 +6,13 @@ /// /** @category Broadcast Channel */ -interface BroadcastChannelEventMap { +declare interface BroadcastChannelEventMap { "message": MessageEvent; "messageerror": MessageEvent; } /** @category Broadcast Channel */ -interface BroadcastChannel extends EventTarget { +declare interface BroadcastChannel extends EventTarget { /** * Returns the channel name (as passed to the constructor). */ @@ -53,6 +53,6 @@ interface BroadcastChannel extends EventTarget { /** @category Broadcast Channel */ declare var BroadcastChannel: { - prototype: BroadcastChannel; + readonly prototype: BroadcastChannel; new (name: string): BroadcastChannel; }; diff --git a/ext/cache/lib.deno_cache.d.ts b/ext/cache/lib.deno_cache.d.ts index 0834d7f20..ca0218bf5 100644 --- a/ext/cache/lib.deno_cache.d.ts +++ b/ext/cache/lib.deno_cache.d.ts @@ -54,18 +54,18 @@ declare interface Cache { /** @category Cache API */ declare var Cache: { - prototype: Cache; - new (name: string): Cache; + readonly prototype: Cache; + new (): never; }; /** @category Cache API */ declare var CacheStorage: { - prototype: CacheStorage; - new (): CacheStorage; + readonly prototype: CacheStorage; + new (): never; }; /** @category Cache API */ -interface CacheQueryOptions { +declare interface CacheQueryOptions { ignoreMethod?: boolean; ignoreSearch?: boolean; ignoreVary?: boolean; diff --git a/ext/crypto/lib.deno_crypto.d.ts b/ext/crypto/lib.deno_crypto.d.ts index 6ff7b72b0..2ad0c67f0 100644 --- a/ext/crypto/lib.deno_crypto.d.ts +++ b/ext/crypto/lib.deno_crypto.d.ts @@ -9,23 +9,23 @@ declare var crypto: Crypto; /** @category Web Crypto API */ -interface Algorithm { +declare interface Algorithm { name: string; } /** @category Web Crypto API */ -interface KeyAlgorithm { +declare interface KeyAlgorithm { name: string; } /** @category Web Crypto API */ -type AlgorithmIdentifier = string | Algorithm; +declare type AlgorithmIdentifier = string | Algorithm; /** @category Web Crypto API */ -type HashAlgorithmIdentifier = AlgorithmIdentifier; +declare type HashAlgorithmIdentifier = AlgorithmIdentifier; /** @category Web Crypto API */ -type KeyType = "private" | "public" | "secret"; +declare type KeyType = "private" | "public" | "secret"; /** @category Web Crypto API */ -type KeyUsage = +declare type KeyUsage = | "decrypt" | "deriveBits" | "deriveKey" @@ -35,19 +35,19 @@ type KeyUsage = | "verify" | "wrapKey"; /** @category Web Crypto API */ -type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki"; +declare type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki"; /** @category Web Crypto API */ -type NamedCurve = string; +declare type NamedCurve = string; /** @category Web Crypto API */ -interface RsaOtherPrimesInfo { +declare interface RsaOtherPrimesInfo { d?: string; r?: string; t?: string; } /** @category Web Crypto API */ -interface JsonWebKey { +declare interface JsonWebKey { alg?: string; crv?: string; d?: string; @@ -56,7 +56,6 @@ interface JsonWebKey { e?: string; ext?: boolean; k?: string; - // deno-lint-ignore camelcase key_ops?: string[]; kty?: string; n?: string; @@ -70,129 +69,129 @@ interface JsonWebKey { } /** @category Web Crypto API */ -interface AesCbcParams extends Algorithm { +declare interface AesCbcParams extends Algorithm { iv: BufferSource; } /** @category Web Crypto API */ -interface AesGcmParams extends Algorithm { +declare interface AesGcmParams extends Algorithm { iv: BufferSource; additionalData?: BufferSource; tagLength?: number; } /** @category Web Crypto API */ -interface AesCtrParams extends Algorithm { +declare interface AesCtrParams extends Algorithm { counter: BufferSource; length: number; } /** @category Web Crypto API */ -interface HmacKeyGenParams extends Algorithm { +declare interface HmacKeyGenParams extends Algorithm { hash: HashAlgorithmIdentifier; length?: number; } /** @category Web Crypto API */ -interface EcKeyGenParams extends Algorithm { +declare interface EcKeyGenParams extends Algorithm { namedCurve: NamedCurve; } /** @category Web Crypto API */ -interface EcKeyImportParams extends Algorithm { +declare interface EcKeyImportParams extends Algorithm { namedCurve: NamedCurve; } /** @category Web Crypto API */ -interface EcdsaParams extends Algorithm { +declare interface EcdsaParams extends Algorithm { hash: HashAlgorithmIdentifier; } /** @category Web Crypto API */ -interface RsaHashedImportParams extends Algorithm { +declare interface RsaHashedImportParams extends Algorithm { hash: HashAlgorithmIdentifier; } /** @category Web Crypto API */ -interface RsaHashedKeyGenParams extends RsaKeyGenParams { +declare interface RsaHashedKeyGenParams extends RsaKeyGenParams { hash: HashAlgorithmIdentifier; } /** @category Web Crypto API */ -interface RsaKeyGenParams extends Algorithm { +declare interface RsaKeyGenParams extends Algorithm { modulusLength: number; publicExponent: Uint8Array; } /** @category Web Crypto API */ -interface RsaPssParams extends Algorithm { +declare interface RsaPssParams extends Algorithm { saltLength: number; } /** @category Web Crypto API */ -interface RsaOaepParams extends Algorithm { +declare interface RsaOaepParams extends Algorithm { label?: Uint8Array; } /** @category Web Crypto API */ -interface HmacImportParams extends Algorithm { +declare interface HmacImportParams extends Algorithm { hash: HashAlgorithmIdentifier; length?: number; } /** @category Web Crypto API */ -interface EcKeyAlgorithm extends KeyAlgorithm { +declare interface EcKeyAlgorithm extends KeyAlgorithm { namedCurve: NamedCurve; } /** @category Web Crypto API */ -interface HmacKeyAlgorithm extends KeyAlgorithm { +declare interface HmacKeyAlgorithm extends KeyAlgorithm { hash: KeyAlgorithm; length: number; } /** @category Web Crypto API */ -interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm { +declare interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm { hash: KeyAlgorithm; } /** @category Web Crypto API */ -interface RsaKeyAlgorithm extends KeyAlgorithm { +declare interface RsaKeyAlgorithm extends KeyAlgorithm { modulusLength: number; publicExponent: Uint8Array; } /** @category Web Crypto API */ -interface HkdfParams extends Algorithm { +declare interface HkdfParams extends Algorithm { hash: HashAlgorithmIdentifier; info: BufferSource; salt: BufferSource; } /** @category Web Crypto API */ -interface Pbkdf2Params extends Algorithm { +declare interface Pbkdf2Params extends Algorithm { hash: HashAlgorithmIdentifier; iterations: number; salt: BufferSource; } /** @category Web Crypto API */ -interface AesDerivedKeyParams extends Algorithm { +declare interface AesDerivedKeyParams extends Algorithm { length: number; } /** @category Web Crypto API */ -interface EcdhKeyDeriveParams extends Algorithm { +declare interface EcdhKeyDeriveParams extends Algorithm { public: CryptoKey; } /** @category Web Crypto API */ -interface AesKeyGenParams extends Algorithm { +declare interface AesKeyGenParams extends Algorithm { length: number; } /** @category Web Crypto API */ -interface AesKeyAlgorithm extends KeyAlgorithm { +declare interface AesKeyAlgorithm extends KeyAlgorithm { length: number; } @@ -201,7 +200,7 @@ interface AesKeyAlgorithm extends KeyAlgorithm { * * @category Web Crypto API */ -interface CryptoKey { +declare interface CryptoKey { readonly algorithm: KeyAlgorithm; readonly extractable: boolean; readonly type: KeyType; @@ -210,8 +209,8 @@ interface CryptoKey { /** @category Web Crypto API */ declare var CryptoKey: { - prototype: CryptoKey; - new (): CryptoKey; + readonly prototype: CryptoKey; + new (): never; }; /** The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for @@ -219,15 +218,15 @@ declare var CryptoKey: { * * @category Web Crypto API */ -interface CryptoKeyPair { +declare interface CryptoKeyPair { privateKey: CryptoKey; publicKey: CryptoKey; } /** @category Web Crypto API */ declare var CryptoKeyPair: { - prototype: CryptoKeyPair; - new (): CryptoKeyPair; + readonly prototype: CryptoKeyPair; + new (): never; }; /** This Web Crypto API interface provides a number of low-level cryptographic @@ -236,7 +235,7 @@ declare var CryptoKeyPair: { * * @category Web Crypto API */ -interface SubtleCrypto { +declare interface SubtleCrypto { generateKey( algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, @@ -368,6 +367,12 @@ interface SubtleCrypto { ): Promise; } +/** @category Web Crypto API */ +declare var SubtleCrypto: { + readonly prototype: SubtleCrypto; + new (): never; +}; + /** @category Web Crypto API */ declare interface Crypto { readonly subtle: SubtleCrypto; @@ -389,7 +394,7 @@ declare interface Crypto { } /** @category Web Crypto API */ -declare var SubtleCrypto: { - prototype: SubtleCrypto; - new (): SubtleCrypto; +declare var Crypto: { + readonly prototype: Crypto; + new (): never; }; diff --git a/ext/fetch/lib.deno_fetch.d.ts b/ext/fetch/lib.deno_fetch.d.ts index 5031cc431..7f574b76e 100644 --- a/ext/fetch/lib.deno_fetch.d.ts +++ b/ext/fetch/lib.deno_fetch.d.ts @@ -6,7 +6,7 @@ /// /** @category DOM APIs */ -interface DomIterable { +declare interface DomIterable { keys(): IterableIterator; values(): IterableIterator; entries(): IterableIterator<[K, V]>; @@ -18,7 +18,7 @@ interface DomIterable { } /** @category Fetch API */ -type FormDataEntryValue = File | string; +declare type FormDataEntryValue = File | string; /** Provides a way to easily construct a set of key/value pairs representing * form fields and their values, which can then be easily sent using the @@ -27,31 +27,23 @@ type FormDataEntryValue = File | string; * * @category Fetch API */ -interface FormData { +declare 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; - keys(): IterableIterator; - values(): IterableIterator; - entries(): IterableIterator<[string, FormDataEntryValue]>; - [Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>; - forEach( - callback: (value: FormDataEntryValue, key: string, parent: this) => void, - thisArg?: any, - ): void; } /** @category Fetch API */ declare var FormData: { - prototype: FormData; + readonly prototype: FormData; new (): FormData; }; /** @category Fetch API */ -interface Body { +declare 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 @@ -81,7 +73,7 @@ interface Body { } /** @category Fetch API */ -type HeadersInit = Headers | string[][] | Record; +declare type HeadersInit = Iterable | Record; /** This Fetch API interface allows you to perform various actions on HTTP * request and response headers. These actions include retrieving, setting, @@ -93,33 +85,13 @@ type HeadersInit = Headers | string[][] | Record; * * @category Fetch API */ -interface Headers { - append(name: string, value: string): void; - delete(name: string): void; - get(name: string): string | null; - has(name: string): boolean; - set(name: string, value: string): void; - forEach( - callbackfn: (value: string, key: string, parent: Headers) => void, - thisArg?: any, - ): void; -} - -/** @category Fetch API */ -declare class Headers implements DomIterable { - constructor(init?: HeadersInit); - +declare 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. */ @@ -128,32 +100,35 @@ declare class Headers implements DomIterable { * 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 + /** Returns an array containing the values of all `Set-Cookie` headers + * associated with a response. */ - [Symbol.iterator](): IterableIterator<[string, string]>; + getSetCookie(): string[]; } +/** This Fetch API interface allows you to perform various actions on HTTP + * request and response headers. These actions include retrieving, setting, + * adding to, and removing. A Headers object has an associated header list, + * which is initially empty and consists of zero or more name and value pairs. + * You can add to this using methods like append() (see Examples). In all + * methods of this interface, header names are matched by case-insensitive byte + * sequence. + * + * @category Fetch API + */ +declare var Headers: { + readonly prototype: Headers; + new (init?: HeadersInit): Headers; +}; + /** @category Fetch API */ -type RequestInfo = Request | string; +declare type RequestInfo = Request | string; /** @category Fetch API */ -type RequestCache = +declare type RequestCache = | "default" | "force-cache" | "no-cache" @@ -161,13 +136,13 @@ type RequestCache = | "only-if-cached" | "reload"; /** @category Fetch API */ -type RequestCredentials = "include" | "omit" | "same-origin"; +declare type RequestCredentials = "include" | "omit" | "same-origin"; /** @category Fetch API */ -type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin"; +declare type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin"; /** @category Fetch API */ -type RequestRedirect = "error" | "follow" | "manual"; +declare type RequestRedirect = "error" | "follow" | "manual"; /** @category Fetch API */ -type ReferrerPolicy = +declare type ReferrerPolicy = | "" | "no-referrer" | "no-referrer-when-downgrade" @@ -178,7 +153,7 @@ type ReferrerPolicy = | "strict-origin-when-cross-origin" | "unsafe-url"; /** @category Fetch API */ -type BodyInit = +declare type BodyInit = | Blob | BufferSource | FormData @@ -186,7 +161,7 @@ type BodyInit = | ReadableStream | string; /** @category Fetch API */ -type RequestDestination = +declare type RequestDestination = | "" | "audio" | "audioworklet" @@ -207,7 +182,7 @@ type RequestDestination = | "xslt"; /** @category Fetch API */ -interface RequestInit { +declare interface RequestInit { /** * A BodyInit object or null to set request's body. */ @@ -275,9 +250,7 @@ interface RequestInit { * * @category Fetch API */ -declare class Request implements Body { - constructor(input: RequestInfo | URL, init?: RequestInit); - +declare interface Request extends Body { /** * Returns the cache mode associated with request, which is a string * indicating how the request will interact with the browser's cache when @@ -361,44 +334,26 @@ declare class Request implements Body { */ readonly url: string; clone(): Request; - - /** 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 - * request yet. - */ - readonly bodyUsed: boolean; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with an `ArrayBuffer`. - */ - arrayBuffer(): Promise; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with a `Blob`. - */ - blob(): Promise; - /** Takes a `Request` stream and reads it to completion. It returns a promise - * that resolves with a `FormData` object. - */ - formData(): Promise; - /** Takes a `Request` 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 `Request` stream and reads it to completion. It returns a promise - * that resolves with a `USVString` (text). - */ - text(): Promise; } +/** This Fetch API interface represents a resource request. + * + * @category Fetch API + */ +declare var Request: { + readonly prototype: Request; + new (input: RequestInfo | URL, init?: RequestInit): Request; +}; + /** @category Fetch API */ -interface ResponseInit { +declare interface ResponseInit { headers?: HeadersInit; status?: number; statusText?: string; } /** @category Fetch API */ -type ResponseType = +declare type ResponseType = | "basic" | "cors" | "default" @@ -410,12 +365,7 @@ type ResponseType = * * @category Fetch API */ -declare class Response implements Body { - constructor(body?: BodyInit | null, init?: ResponseInit); - static json(data: unknown, init?: ResponseInit): Response; - static error(): Response; - static redirect(url: string | URL, status?: number): Response; - +declare interface Response extends Body { readonly headers: Headers; readonly ok: boolean; readonly redirected: boolean; @@ -424,35 +374,20 @@ declare class Response implements Body { readonly type: ResponseType; readonly url: string; clone(): Response; - - /** 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; } +/** This Fetch API interface represents the response to a request. + * + * @category Fetch API + */ +declare var Response: { + readonly prototype: Response; + new (body?: BodyInit | null, init?: ResponseInit): Response; + json(data: unknown, init?: ResponseInit): Response; + error(): Response; + redirect(url: string | URL, status?: number): Response; +}; + /** Fetch a resource from the network. It returns a `Promise` that resolves to the * `Response` to that `Request`, whether it is successful or not. * diff --git a/ext/url/lib.deno_url.d.ts b/ext/url/lib.deno_url.d.ts index 9a8c155d9..6da1c5704 100644 --- a/ext/url/lib.deno_url.d.ts +++ b/ext/url/lib.deno_url.d.ts @@ -1,17 +1,12 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// deno-lint-ignore-file no-explicit-any +// deno-lint-ignore-file no-explicit-any no-var /// /// /** @category Web APIs */ -declare class URLSearchParams { - constructor( - init?: string[][] | Record | string | URLSearchParams, - ); - static toString(): string; - +declare interface URLSearchParams { /** Appends a specified key/value pair as a new search parameter. * * ```ts @@ -22,15 +17,16 @@ declare class URLSearchParams { */ append(name: string, value: string): void; - /** Deletes the given search parameter and its associated value, + /** Deletes search parameters that match a name, and optional value, * from the list of all search parameters. * * ```ts * let searchParams = new URLSearchParams([['name', 'value']]); * searchParams.delete('name'); + * searchParams.delete('name', 'value'); * ``` */ - delete(name: string): void; + delete(name: string, value?: string): void; /** Returns all the values associated with a given search parameter * as an array. @@ -49,14 +45,15 @@ declare class URLSearchParams { */ get(name: string): string | null; - /** Returns a Boolean that indicates whether a parameter with the - * specified name exists. + /** Returns a boolean value indicating if a given parameter, + * or parameter and value pair, exists. * * ```ts * searchParams.has('name'); + * searchParams.has('name', 'value'); * ``` */ - has(name: string): boolean; + has(name: string, value?: string): boolean; /** Sets the value associated with a given search parameter to the * given value. If there were several matching values, this method @@ -160,17 +157,20 @@ declare class URLSearchParams { size: number; } +/** @category Web APIs */ +declare var URLSearchParams: { + readonly prototype: URLSearchParams; + new ( + init?: Iterable | Record | string, + ): URLSearchParams; +}; + /** The URL interface represents an object providing static methods used for * creating object URLs. * * @category Web APIs */ -declare class URL { - constructor(url: string | URL, base?: string | URL); - static canParse(url: string | URL, base?: string | URL): boolean; - static createObjectURL(blob: Blob): string; - static revokeObjectURL(url: string): void; - +declare interface URL { hash: string; host: string; hostname: string; @@ -187,6 +187,19 @@ declare class URL { toJSON(): string; } +/** The URL interface represents an object providing static methods used for + * creating object URLs. + * + * @category Web APIs + */ +declare var URL: { + readonly prototype: URL; + new (url: string | URL, base?: string | URL): URL; + canParse(url: string | URL, base?: string | URL): boolean; + createObjectURL(blob: Blob): string; + revokeObjectURL(url: string): void; +}; + /** @category Web APIs */ declare interface URLPatternInit { protocol?: string; @@ -265,9 +278,7 @@ declare interface URLPatternResult { * * @category Web APIs */ -declare class URLPattern { - constructor(input: URLPatternInput, baseURL?: string); - +declare interface URLPattern { /** * Test if the given input matches the stored pattern. * @@ -332,3 +343,38 @@ declare class URLPattern { /** The pattern string for the `hash`. */ readonly hash: string; } + +/** + * The URLPattern API provides a web platform primitive for matching URLs based + * on a convenient pattern syntax. + * + * The syntax is based on path-to-regexp. Wildcards, named capture groups, + * regular groups, and group modifiers are all supported. + * + * ```ts + * // Specify the pattern as structured data. + * const pattern = new URLPattern({ pathname: "/users/:user" }); + * const match = pattern.exec("https://blog.example.com/users/joe"); + * console.log(match.pathname.groups.user); // joe + * ``` + * + * ```ts + * // Specify a fully qualified string pattern. + * const pattern = new URLPattern("https://example.com/books/:id"); + * console.log(pattern.test("https://example.com/books/123")); // true + * console.log(pattern.test("https://deno.land/books/123")); // false + * ``` + * + * ```ts + * // Specify a relative string pattern with a base URL. + * const pattern = new URLPattern("/article/:id", "https://blog.example.com"); + * console.log(pattern.test("https://blog.example.com/article")); // false + * console.log(pattern.test("https://blog.example.com/article/123")); // true + * ``` + * + * @category Web APIs + */ +declare var URLPattern: { + readonly prototype: URLPattern; + new (input: URLPatternInput, baseURL?: string): URLPattern; +}; diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index e1ffdc329..331c9536b 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -5,16 +5,71 @@ /// /// -/** @category DOM Events */ -declare class DOMException extends Error { - constructor(message?: string, name?: string); +/** @category Web APIs */ +declare interface DOMException extends Error { readonly name: string; readonly message: string; readonly code: number; + readonly INDEX_SIZE_ERR: 1; + readonly DOMSTRING_SIZE_ERR: 2; + readonly HIERARCHY_REQUEST_ERR: 3; + readonly WRONG_DOCUMENT_ERR: 4; + readonly INVALID_CHARACTER_ERR: 5; + readonly NO_DATA_ALLOWED_ERR: 6; + readonly NO_MODIFICATION_ALLOWED_ERR: 7; + readonly NOT_FOUND_ERR: 8; + readonly NOT_SUPPORTED_ERR: 9; + readonly INUSE_ATTRIBUTE_ERR: 10; + readonly INVALID_STATE_ERR: 11; + readonly SYNTAX_ERR: 12; + readonly INVALID_MODIFICATION_ERR: 13; + readonly NAMESPACE_ERR: 14; + readonly INVALID_ACCESS_ERR: 15; + readonly VALIDATION_ERR: 16; + readonly TYPE_MISMATCH_ERR: 17; + readonly SECURITY_ERR: 18; + readonly NETWORK_ERR: 19; + readonly ABORT_ERR: 20; + readonly URL_MISMATCH_ERR: 21; + readonly QUOTA_EXCEEDED_ERR: 22; + readonly TIMEOUT_ERR: 23; + readonly INVALID_NODE_TYPE_ERR: 24; + readonly DATA_CLONE_ERR: 25; } +/** @category Web APIs */ +declare var DOMException: { + readonly prototype: DOMException; + new (message?: string, name?: string): DOMException; + readonly INDEX_SIZE_ERR: 1; + readonly DOMSTRING_SIZE_ERR: 2; + readonly HIERARCHY_REQUEST_ERR: 3; + readonly WRONG_DOCUMENT_ERR: 4; + readonly INVALID_CHARACTER_ERR: 5; + readonly NO_DATA_ALLOWED_ERR: 6; + readonly NO_MODIFICATION_ALLOWED_ERR: 7; + readonly NOT_FOUND_ERR: 8; + readonly NOT_SUPPORTED_ERR: 9; + readonly INUSE_ATTRIBUTE_ERR: 10; + readonly INVALID_STATE_ERR: 11; + readonly SYNTAX_ERR: 12; + readonly INVALID_MODIFICATION_ERR: 13; + readonly NAMESPACE_ERR: 14; + readonly INVALID_ACCESS_ERR: 15; + readonly VALIDATION_ERR: 16; + readonly TYPE_MISMATCH_ERR: 17; + readonly SECURITY_ERR: 18; + readonly NETWORK_ERR: 19; + readonly ABORT_ERR: 20; + readonly URL_MISMATCH_ERR: 21; + readonly QUOTA_EXCEEDED_ERR: 22; + readonly TIMEOUT_ERR: 23; + readonly INVALID_NODE_TYPE_ERR: 24; + readonly DATA_CLONE_ERR: 25; +}; + /** @category DOM Events */ -interface EventInit { +declare interface EventInit { bubbles?: boolean; cancelable?: boolean; composed?: boolean; @@ -24,8 +79,7 @@ interface EventInit { * * @category DOM Events */ -declare class Event { - constructor(type: string, eventInitDict?: EventInit); +declare interface Event { /** Returns true or false depending on how event was initialized. True if * event goes through its target's ancestors in reverse tree order, and * false otherwise. */ @@ -80,19 +134,28 @@ declare class Event { readonly BUBBLING_PHASE: number; readonly CAPTURING_PHASE: number; readonly NONE: number; - static readonly AT_TARGET: number; - static readonly BUBBLING_PHASE: number; - static readonly CAPTURING_PHASE: number; - static readonly NONE: number; } +/** An event which takes place in the DOM. + * + * @category DOM Events + */ +declare var Event: { + readonly prototype: Event; + new (type: string, eventInitDict?: EventInit): Event; + readonly AT_TARGET: number; + readonly BUBBLING_PHASE: number; + readonly CAPTURING_PHASE: number; + readonly NONE: number; +}; + /** * EventTarget is a DOM interface implemented by objects that can receive events * and may have listeners for them. * * @category DOM Events */ -declare class EventTarget { +declare interface EventTarget { /** Appends an event listener for events whose type attribute value is type. * The callback argument sets the callback that will be invoked when the event * is dispatched. @@ -134,13 +197,24 @@ declare class EventTarget { ): void; } +/** + * EventTarget is a DOM interface implemented by objects that can receive events + * and may have listeners for them. + * + * @category DOM Events + */ +declare var EventTarget: { + readonly prototype: EventTarget; + new (): EventTarget; +}; + /** @category DOM Events */ -interface EventListener { +declare interface EventListener { (evt: Event): void | Promise; } /** @category DOM Events */ -interface EventListenerObject { +declare interface EventListenerObject { handleEvent(evt: Event): void | Promise; } @@ -150,19 +224,19 @@ declare type EventListenerOrEventListenerObject = | EventListenerObject; /** @category DOM Events */ -interface AddEventListenerOptions extends EventListenerOptions { +declare interface AddEventListenerOptions extends EventListenerOptions { once?: boolean; passive?: boolean; signal?: AbortSignal; } /** @category DOM Events */ -interface EventListenerOptions { +declare interface EventListenerOptions { capture?: boolean; } /** @category DOM Events */ -interface ProgressEventInit extends EventInit { +declare interface ProgressEventInit extends EventInit { lengthComputable?: boolean; loaded?: number; total?: number; @@ -174,14 +248,25 @@ interface ProgressEventInit extends EventInit { * * @category DOM Events */ -declare class ProgressEvent extends Event { - constructor(type: string, eventInitDict?: ProgressEventInit); +declare interface ProgressEvent + extends Event { readonly lengthComputable: boolean; readonly loaded: number; readonly target: T | null; readonly total: number; } +/** Events measuring progress of an underlying process, like an HTTP request + * (for an XMLHttpRequest, or the loading of the underlying resource of an + * ,