From 2ba75527770aa7a4a49fdca50f1cbee5e5456a40 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Mon, 19 Apr 2021 20:25:20 +1000 Subject: [PATCH 1/2] Revert "fix(#10200): weaken types so non-breaking (#10205)" This reverts commit 9c7c9a35c12625bd4793c21539391d6b08d17e73. --- cli/dts/lib.deno.ns.d.ts | 10 ++++------ cli/dts/lib.deno.unstable.d.ts | 19 ++++++++----------- runtime/js/40_tls.js | 6 ------ 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 9c47cb87938483..8b0d8d7d91b266 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -1726,21 +1726,19 @@ declare namespace Deno { * Requires `allow-write` permission. */ export function truncate(name: string, len?: number): Promise; - export interface Addr { - transport: string; - } - - export interface NetAddr extends Addr { + export interface NetAddr { transport: "tcp" | "udp"; hostname: string; port: number; } - export interface UnixAddr extends Addr { + export interface UnixAddr { transport: "unix" | "unixpacket"; path: string; } + export type Addr = NetAddr | UnixAddr; + /** A generic network listener for stream-oriented protocols. */ export interface Listener
extends AsyncIterable> { diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 96280af8f1bc21..f7ed187807aaf1 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -874,26 +874,23 @@ declare namespace Deno { /** **UNSTABLE**: new API, yet to be vetted. * * A generic transport listener for message-oriented protocols. */ - export interface DatagramConn
- extends AsyncIterable<[Uint8Array, Address]> { + export interface DatagramConn extends AsyncIterable<[Uint8Array, Addr]> { /** **UNSTABLE**: new API, yet to be vetted. * * Waits for and resolves to the next message to the `UDPConn`. */ - receive(p?: Uint8Array): Promise<[Uint8Array, Address]>; + receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>; /** UNSTABLE: new API, yet to be vetted. * * Sends a message to the target. */ - send(p: Uint8Array, addr: Address): Promise; + send(p: Uint8Array, addr: Addr): Promise; /** 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: Address; - [Symbol.asyncIterator](): AsyncIterableIterator< - [Uint8Array, Address] - >; + readonly addr: Addr; + [Symbol.asyncIterator](): AsyncIterableIterator<[Uint8Array, Addr]>; } export interface UnixListenOptions { @@ -933,7 +930,7 @@ declare namespace Deno { * Requires `allow-net` permission. */ export function listenDatagram( options: ListenOptions & { transport: "udp" }, - ): DatagramConn; + ): DatagramConn; /** **UNSTABLE**: new API, yet to be vetted * @@ -949,7 +946,7 @@ declare namespace Deno { * Requires `allow-read` and `allow-write` permission. */ export function listenDatagram( options: UnixListenOptions & { transport: "unixpacket" }, - ): DatagramConn; + ): DatagramConn; export interface UnixConnectOptions { transport: "unix"; @@ -1003,7 +1000,7 @@ declare namespace Deno { * Requires `allow-net` permission. */ export function startTls( - conn: Conn, + conn: Conn, options?: StartTlsOptions, ): Promise>; diff --git a/runtime/js/40_tls.js b/runtime/js/40_tls.js index ea094b6a74a39a..4fafe90792c3f0 100644 --- a/runtime/js/40_tls.js +++ b/runtime/js/40_tls.js @@ -68,12 +68,6 @@ 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, From bf971bee28a0365c2de2d6e261ff648d606e13dc Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Mon, 19 Apr 2021 20:25:56 +1000 Subject: [PATCH 2/2] Revert "feat(cli/dts): stricter typings for Listener & Conn (#10012)" This reverts commit a8057e3e06962a8d7c6330a085704bb4493eed04. --- cli/dts/lib.deno.ns.d.ts | 26 +++++++++++--------------- cli/dts/lib.deno.unstable.d.ts | 13 +++++-------- cli/tests/unit/net_test.ts | 6 ------ 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 8b0d8d7d91b266..738d0ba54be218 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -1740,28 +1740,26 @@ declare namespace Deno { export type Addr = NetAddr | UnixAddr; /** A generic network listener for stream-oriented protocols. */ - export interface Listener
- extends AsyncIterable> { + export interface Listener extends AsyncIterable { /** Waits for and resolves to the next connection to the `Listener`. */ - accept(): Promise>; + accept(): Promise; /** Close closes the listener. Any pending accept promises will be rejected * with errors. */ close(): void; /** Return the address of the `Listener`. */ - readonly addr: Address; + readonly addr: Addr; /** Return the rid of the `Listener`. */ readonly rid: number; - [Symbol.asyncIterator](): AsyncIterableIterator>; + [Symbol.asyncIterator](): AsyncIterableIterator; } - export interface Conn
- extends Reader, Writer, Closer { + export interface Conn extends Reader, Writer, Closer { /** The local address of the connection. */ - readonly localAddr: Address; + readonly localAddr: Addr; /** The remote address of the connection. */ - readonly remoteAddr: Address; + readonly remoteAddr: Addr; /** The resource ID of the connection. */ readonly rid: number; /** Shuts down (`shutdown(2)`) the write side of the connection. Most @@ -1789,7 +1787,7 @@ declare namespace Deno { * Requires `allow-net` permission. */ export function listen( options: ListenOptions & { transport?: "tcp" }, - ): Listener; + ): Listener; export interface ListenTlsOptions extends ListenOptions { /** Server certificate file. */ @@ -1808,7 +1806,7 @@ declare namespace Deno { * ``` * * Requires `allow-net` permission. */ - export function listenTls(options: ListenTlsOptions): Listener; + export function listenTls(options: ListenTlsOptions): Listener; export interface ConnectOptions { /** The port to connect to. */ @@ -1831,7 +1829,7 @@ declare namespace Deno { * ``` * * Requires `allow-net` permission for "tcp". */ - export function connect(options: ConnectOptions): Promise>; + export function connect(options: ConnectOptions): Promise; export interface ConnectTlsOptions { /** The port to connect to. */ @@ -1857,9 +1855,7 @@ declare namespace Deno { * * Requires `allow-net` permission. */ - export function connectTls( - options: ConnectTlsOptions, - ): Promise>; + export function connectTls(options: ConnectTlsOptions): Promise; /** Shutdown socket send operations. * diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index f7ed187807aaf1..8d4c1f87d7f897 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -909,7 +909,7 @@ declare namespace Deno { * Requires `allow-read` and `allow-write` permission. */ export function listen( options: UnixListenOptions & { transport: "unix" }, - ): Listener; + ): Listener; /** **UNSTABLE**: new API, yet to be vetted * @@ -969,11 +969,8 @@ declare namespace Deno { * * Requires `allow-net` permission for "tcp" and `allow-read` for "unix". */ export function connect( - options: ConnectOptions, - ): Promise>; - export function connect( - options: UnixConnectOptions, - ): Promise>; + options: ConnectOptions | UnixConnectOptions, + ): Promise; export interface StartTlsOptions { /** A literal IP address or host name that can be resolved to an IP address. @@ -1000,9 +997,9 @@ declare namespace Deno { * Requires `allow-net` permission. */ export function startTls( - conn: Conn, + conn: Conn, options?: StartTlsOptions, - ): Promise>; + ): Promise; export interface ListenTlsOptions { /** **UNSTABLE**: new API, yet to be vetted. diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 5f9fc916afd109..725bb9684e4666 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -18,12 +18,6 @@ unitTest({ perms: { net: true } }, function netTcpListenClose(): void { listener.close(); }); -unitTest({ perms: { net: true } }, function netListenPortType(): void { - const listener = Deno.listen({ port: 0, transport: "tcp" }); - listener.addr.port; - listener.close(); -}); - unitTest( { perms: { net: true },