mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
feat(cli/dts): stricter typings for Listener & Conn (#10012)
This commit is contained in:
parent
8b59d9f7bc
commit
a8057e3e06
3 changed files with 29 additions and 16 deletions
26
cli/dts/lib.deno.ns.d.ts
vendored
26
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -1740,26 +1740,28 @@ declare namespace Deno {
|
|||
export type Addr = NetAddr | UnixAddr;
|
||||
|
||||
/** A generic network listener for stream-oriented protocols. */
|
||||
export interface Listener extends AsyncIterable<Conn> {
|
||||
export interface Listener<Address extends Addr = Addr>
|
||||
extends AsyncIterable<Conn<Address>> {
|
||||
/** Waits for and resolves to the next connection to the `Listener`. */
|
||||
accept(): Promise<Conn>;
|
||||
accept(): Promise<Conn<Address>>;
|
||||
/** Close closes the listener. Any pending accept promises will be rejected
|
||||
* with errors. */
|
||||
close(): void;
|
||||
/** Return the address of the `Listener`. */
|
||||
readonly addr: Addr;
|
||||
readonly addr: Address;
|
||||
|
||||
/** Return the rid of the `Listener`. */
|
||||
readonly rid: number;
|
||||
|
||||
[Symbol.asyncIterator](): AsyncIterableIterator<Conn>;
|
||||
[Symbol.asyncIterator](): AsyncIterableIterator<Conn<Address>>;
|
||||
}
|
||||
|
||||
export interface Conn extends Reader, Writer, Closer {
|
||||
export interface Conn<Address extends Addr = Addr>
|
||||
extends Reader, Writer, Closer {
|
||||
/** The local address of the connection. */
|
||||
readonly localAddr: Addr;
|
||||
readonly localAddr: Address;
|
||||
/** The remote address of the connection. */
|
||||
readonly remoteAddr: Addr;
|
||||
readonly remoteAddr: Address;
|
||||
/** The resource ID of the connection. */
|
||||
readonly rid: number;
|
||||
/** Shuts down (`shutdown(2)`) the write side of the connection. Most
|
||||
|
@ -1787,7 +1789,7 @@ declare namespace Deno {
|
|||
* Requires `allow-net` permission. */
|
||||
export function listen(
|
||||
options: ListenOptions & { transport?: "tcp" },
|
||||
): Listener;
|
||||
): Listener<NetAddr>;
|
||||
|
||||
export interface ListenTlsOptions extends ListenOptions {
|
||||
/** Server certificate file. */
|
||||
|
@ -1806,7 +1808,7 @@ declare namespace Deno {
|
|||
* ```
|
||||
*
|
||||
* Requires `allow-net` permission. */
|
||||
export function listenTls(options: ListenTlsOptions): Listener;
|
||||
export function listenTls(options: ListenTlsOptions): Listener<NetAddr>;
|
||||
|
||||
export interface ConnectOptions {
|
||||
/** The port to connect to. */
|
||||
|
@ -1829,7 +1831,7 @@ declare namespace Deno {
|
|||
* ```
|
||||
*
|
||||
* Requires `allow-net` permission for "tcp". */
|
||||
export function connect(options: ConnectOptions): Promise<Conn>;
|
||||
export function connect(options: ConnectOptions): Promise<Conn<NetAddr>>;
|
||||
|
||||
export interface ConnectTlsOptions {
|
||||
/** The port to connect to. */
|
||||
|
@ -1855,7 +1857,9 @@ declare namespace Deno {
|
|||
*
|
||||
* Requires `allow-net` permission.
|
||||
*/
|
||||
export function connectTls(options: ConnectTlsOptions): Promise<Conn>;
|
||||
export function connectTls(
|
||||
options: ConnectTlsOptions,
|
||||
): Promise<Conn<NetAddr>>;
|
||||
|
||||
/** Shutdown socket send operations.
|
||||
*
|
||||
|
|
13
cli/dts/lib.deno.unstable.d.ts
vendored
13
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -909,7 +909,7 @@ declare namespace Deno {
|
|||
* Requires `allow-read` and `allow-write` permission. */
|
||||
export function listen(
|
||||
options: UnixListenOptions & { transport: "unix" },
|
||||
): Listener;
|
||||
): Listener<UnixAddr>;
|
||||
|
||||
/** **UNSTABLE**: new API, yet to be vetted
|
||||
*
|
||||
|
@ -969,8 +969,11 @@ declare namespace Deno {
|
|||
*
|
||||
* Requires `allow-net` permission for "tcp" and `allow-read` for "unix". */
|
||||
export function connect(
|
||||
options: ConnectOptions | UnixConnectOptions,
|
||||
): Promise<Conn>;
|
||||
options: ConnectOptions,
|
||||
): Promise<Conn<NetAddr>>;
|
||||
export function connect(
|
||||
options: UnixConnectOptions,
|
||||
): Promise<Conn<UnixAddr>>;
|
||||
|
||||
export interface StartTlsOptions {
|
||||
/** A literal IP address or host name that can be resolved to an IP address.
|
||||
|
@ -997,9 +1000,9 @@ declare namespace Deno {
|
|||
* Requires `allow-net` permission.
|
||||
*/
|
||||
export function startTls(
|
||||
conn: Conn,
|
||||
conn: Conn<NetAddr>,
|
||||
options?: StartTlsOptions,
|
||||
): Promise<Conn>;
|
||||
): Promise<Conn<NetAddr>>;
|
||||
|
||||
export interface ListenTlsOptions {
|
||||
/** **UNSTABLE**: new API, yet to be vetted.
|
||||
|
|
|
@ -18,6 +18,12 @@ 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 },
|
||||
|
|
Loading…
Add table
Reference in a new issue