diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-01-25 08:12:10 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 22:12:10 +0100 |
commit | fc176c4dea7463d587a1e921780cce55552e0c86 (patch) | |
tree | 88e996655b20e796571db38896d4db27fcfe54b7 | |
parent | 176118a0468c5b4f2117d18271d814000d4752b2 (diff) |
feat: deprecate `Deno.{Conn,TcpConn,TlsConn,UnixConn}.rid` (#22077)
For removal in Deno v2.
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
-rw-r--r-- | cli/tests/integration/worker_tests.rs | 8 | ||||
-rw-r--r-- | ext/net/01_net.js | 55 | ||||
-rw-r--r-- | ext/net/02_tls.js | 18 | ||||
-rw-r--r-- | ext/net/lib.deno_net.d.ts | 32 |
4 files changed, 96 insertions, 17 deletions
diff --git a/cli/tests/integration/worker_tests.rs b/cli/tests/integration/worker_tests.rs index 573863d4f..cbd63d809 100644 --- a/cli/tests/integration/worker_tests.rs +++ b/cli/tests/integration/worker_tests.rs @@ -1,10 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. itest!(workers { - args: "test --reload --location http://127.0.0.1:4545/ -A --unstable workers/test.ts", - output: "workers/test.ts.out", - http_server: true, - }); + args: "test --reload --location http://127.0.0.1:4545/ -A --unstable-worker-options workers/test.ts", + output: "workers/test.ts.out", + http_server: true, +}); itest!(worker_error { args: "run -A workers/worker_error.ts", diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 73d8bad49..a2b04de76 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -106,6 +106,11 @@ class Conn { } get rid() { + internals.warnOnDeprecatedApi( + "Deno.Conn.rid", + new Error().stack, + "Use `Deno.Conn` instance methods instead.", + ); return this.#rid; } @@ -118,14 +123,14 @@ class Conn { } write(p) { - return write(this.rid, p); + return write(this.#rid, p); } async read(buffer) { if (buffer.length === 0) { return 0; } - const promise = core.read(this.rid, buffer); + const promise = core.read(this.#rid, buffer); if (this.#unref) core.unrefOpPromise(promise); SetPrototypeAdd(this.#pendingReadPromises, promise); let nread; @@ -140,16 +145,16 @@ class Conn { } close() { - core.close(this.rid); + core.close(this.#rid); } closeWrite() { - return shutdown(this.rid); + return shutdown(this.#rid); } get readable() { if (this.#readable === undefined) { - this.#readable = readableStreamForRidUnrefable(this.rid); + this.#readable = readableStreamForRidUnrefable(this.#rid); if (this.#unref) { readableStreamForRidUnrefableUnref(this.#readable); } @@ -159,7 +164,7 @@ class Conn { get writable() { if (this.#writable === undefined) { - this.#writable = writableStreamForRid(this.rid); + this.#writable = writableStreamForRid(this.#rid); } return this.#writable; } @@ -193,16 +198,48 @@ class Conn { } class TcpConn extends Conn { + #rid = 0; + + constructor(rid, remoteAddr, localAddr) { + super(rid, remoteAddr, localAddr); + this.#rid = rid; + } + + get rid() { + internals.warnOnDeprecatedApi( + "Deno.TcpConn.rid", + new Error().stack, + "Use `Deno.TcpConn` instance methods instead.", + ); + return this.#rid; + } + setNoDelay(noDelay = true) { - return op_set_nodelay(this.rid, noDelay); + return op_set_nodelay(this.#rid, noDelay); } setKeepAlive(keepAlive = true) { - return op_set_keepalive(this.rid, keepAlive); + return op_set_keepalive(this.#rid, keepAlive); } } -class UnixConn extends Conn {} +class UnixConn extends Conn { + #rid = 0; + + constructor(rid, remoteAddr, localAddr) { + super(rid, remoteAddr, localAddr); + this.#rid = rid; + } + + get rid() { + internals.warnOnDeprecatedApi( + "Deno.UnixConn.rid", + new Error().stack, + "Use `Deno.UnixConn` instance methods instead.", + ); + return this.#rid; + } +} class Listener { #rid = 0; diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index e71bd77f5..1411c6d74 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -24,8 +24,24 @@ function opTlsHandshake(rid) { } class TlsConn extends Conn { + #rid = 0; + + constructor(rid, remoteAddr, localAddr) { + super(rid, remoteAddr, localAddr); + this.#rid = rid; + } + + get rid() { + internals.warnOnDeprecatedApi( + "Deno.TlsConn.rid", + new Error().stack, + "Use `Deno.TlsConn` instance methods instead.", + ); + return this.#rid; + } + handshake() { - return opTlsHandshake(this.rid); + return opTlsHandshake(this.#rid); } } diff --git a/ext/net/lib.deno_net.d.ts b/ext/net/lib.deno_net.d.ts index a7ed95bae..c6a771bc0 100644 --- a/ext/net/lib.deno_net.d.ts +++ b/ext/net/lib.deno_net.d.ts @@ -69,7 +69,12 @@ declare namespace Deno { readonly localAddr: Addr; /** The remote address of the connection. */ readonly remoteAddr: Addr; - /** The resource ID of the connection. */ + /** + * The resource ID of the connection. + * + * @deprecated Use {@linkcode Deno.Conn} instance methods instead. + * {@linkcode Deno.Conn.rid} will be removed in Deno 2.0. + */ readonly rid: number; /** Shuts down (`shutdown(2)`) the write side of the connection. Most * callers should just use `close()`. */ @@ -103,6 +108,13 @@ declare namespace Deno { * not happened yet. Calling this method is optional; the TLS handshake * will be completed automatically as soon as data is sent or received. */ handshake(): Promise<TlsHandshakeInfo>; + /** + * The resource ID of the connection. + * + * @deprecated Use {@linkcode Deno.TlsConn} instance methods instead. + * {@linkcode Deno.TlsConn.rid} will be removed in Deno 2.0. + */ + readonly rid: number; } /** @category Network */ @@ -260,6 +272,13 @@ declare namespace Deno { setNoDelay(noDelay?: boolean): void; /** Enable/disable keep-alive functionality. */ setKeepAlive(keepAlive?: boolean): void; + /** + * The resource ID of the connection. + * + * @deprecated Use {@linkcode Deno.Conn} instance methods instead. + * {@linkcode Deno.Conn.rid} will be removed in Deno 2.0. + */ + readonly rid: number; } /** @category Network */ @@ -269,8 +288,15 @@ declare namespace Deno { } /** @category Network */ - // deno-lint-ignore no-empty-interface - export interface UnixConn extends Conn {} + export interface UnixConn extends Conn { + /** + * The resource ID of the connection. + * + * @deprecated Use {@linkcode Deno.UnixConn} instance methods instead. + * {@linkcode Deno.UnixConn.rid} will be removed in Deno 2.0. + */ + readonly rid: number; + } /** Connects to the hostname (default is "127.0.0.1") and port on the named * transport (default is "tcp"), and resolves to the connection (`Conn`). |