diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-04-16 22:34:29 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-16 22:34:29 +1000 |
commit | 9c7c9a35c12625bd4793c21539391d6b08d17e73 (patch) | |
tree | dfe6ae0d0a9dcb93b215f51cf0f562a4ed68929d | |
parent | fe9cee620a4c0d8923bdf99882f95275b69abcb4 (diff) |
fix(#10200): weaken types so non-breaking (#10205)
Fixes #10200
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 10 | ||||
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 19 | ||||
-rw-r--r-- | runtime/js/40_tls.js | 6 |
3 files changed, 23 insertions, 12 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 8b0d8d7d9..9c47cb879 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -1726,19 +1726,21 @@ declare namespace Deno { * Requires `allow-write` permission. */ export function truncate(name: string, len?: number): Promise<void>; - export interface NetAddr { + export interface Addr { + transport: string; + } + + export interface NetAddr extends Addr { transport: "tcp" | "udp"; hostname: string; port: number; } - export interface UnixAddr { + export interface UnixAddr extends Addr { transport: "unix" | "unixpacket"; path: string; } - export type Addr = NetAddr | UnixAddr; - /** A generic network listener for stream-oriented protocols. */ export interface Listener<Address extends Addr = Addr> extends AsyncIterable<Conn<Address>> { diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index f7ed18780..96280af8f 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -874,23 +874,26 @@ declare namespace Deno { /** **UNSTABLE**: new API, yet to be vetted. * * A generic transport listener for message-oriented protocols. */ - export interface DatagramConn extends AsyncIterable<[Uint8Array, Addr]> { + export interface DatagramConn<Address extends Addr = Addr> + extends AsyncIterable<[Uint8Array, Address]> { /** **UNSTABLE**: new API, yet to be vetted. * * Waits for and resolves to the next message to the `UDPConn`. */ - receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>; + receive(p?: Uint8Array): Promise<[Uint8Array, Address]>; /** UNSTABLE: new API, yet to be vetted. * * Sends a message to the target. */ - send(p: Uint8Array, addr: Addr): Promise<number>; + send(p: Uint8Array, addr: Address): Promise<number>; /** UNSTABLE: new API, yet to be vetted. * * Close closes the socket. Any pending message promises will be rejected * with errors. */ close(): void; /** Return the address of the `UDPConn`. */ - readonly addr: Addr; - [Symbol.asyncIterator](): AsyncIterableIterator<[Uint8Array, Addr]>; + readonly addr: Address; + [Symbol.asyncIterator](): AsyncIterableIterator< + [Uint8Array, Address] + >; } export interface UnixListenOptions { @@ -930,7 +933,7 @@ declare namespace Deno { * Requires `allow-net` permission. */ export function listenDatagram( options: ListenOptions & { transport: "udp" }, - ): DatagramConn; + ): DatagramConn<NetAddr>; /** **UNSTABLE**: new API, yet to be vetted * @@ -946,7 +949,7 @@ declare namespace Deno { * Requires `allow-read` and `allow-write` permission. */ export function listenDatagram( options: UnixListenOptions & { transport: "unixpacket" }, - ): DatagramConn; + ): DatagramConn<UnixAddr>; export interface UnixConnectOptions { transport: "unix"; @@ -1000,7 +1003,7 @@ declare namespace Deno { * Requires `allow-net` permission. */ export function startTls( - conn: Conn<NetAddr>, + conn: Conn, options?: StartTlsOptions, ): Promise<Conn<NetAddr>>; diff --git a/runtime/js/40_tls.js b/runtime/js/40_tls.js index 4fafe9079..ea094b6a7 100644 --- a/runtime/js/40_tls.js +++ b/runtime/js/40_tls.js @@ -68,6 +68,12 @@ conn, { hostname = "127.0.0.1", certFile } = {}, ) { + if ( + !(conn.localAddr.transport === "tcp" || + conn.localAddr.transport === "udp") + ) { + throw new TypeError(`conn is not a valid network connection`); + } const res = await opStartTls({ rid: conn.rid, hostname, |