diff options
author | João Souto <joao.jpgs@hotmail.com> | 2020-03-23 22:02:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-23 18:02:51 -0400 |
commit | 70a50344315a4c3361fc321e78e076fb09a502b3 (patch) | |
tree | 1079d325ec898afb7829ac1888ed395ed2ac35d2 /cli/js/lib.deno.ns.d.ts | |
parent | b924e5ab7e69eab4d3b6d9a863a8fc2974f33b5d (diff) |
feat: Support Unix Domain Sockets (#4176)
Diffstat (limited to 'cli/js/lib.deno.ns.d.ts')
-rw-r--r-- | cli/js/lib.deno.ns.d.ts | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 99e40014c..72794e3bf 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -1546,21 +1546,18 @@ declare namespace Deno { * * Requires `allow-plugin` permission. */ export function openPlugin(filename: string): Plugin; - - export type Transport = "tcp" | "udp"; - - export interface Addr { - transport: Transport; + export interface NetAddr { + transport: "tcp" | "udp"; hostname: string; port: number; } - export interface UDPAddr { - port: number; - transport?: Transport; - hostname?: string; + export interface UnixAddr { + transport: "unix" | "unixpacket"; + address: string; } + export type Addr = NetAddr | UnixAddr; /** **UNSTABLE**: Maybe remove `ShutdownMode` entirely. * * Corresponds to `SHUT_RD`, `SHUT_WR`, `SHUT_RDWR` on POSIX-like systems. @@ -1587,16 +1584,8 @@ declare namespace Deno { /** **UNSTABLE**: new API, yet to be vetted. * - * Waits for the next message to the passed `rid` and writes it on the passed - * `Uint8Array`. - * - * Resolves to the number of bytes written and the remote address. */ - export function recvfrom(rid: number, p: Uint8Array): Promise<[number, Addr]>; - - /** **UNSTABLE**: new API, yet to be vetted. - * * A generic transport listener for message-oriented protocols. */ - export interface UDPConn extends AsyncIterable<[Uint8Array, Addr]> { + 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`. */ @@ -1604,7 +1593,7 @@ declare namespace Deno { /** UNSTABLE: new API, yet to be vetted. * * Sends a message to the target. */ - send(p: Uint8Array, addr: UDPAddr): Promise<void>; + send(p: Uint8Array, addr: Addr): Promise<void>; /** UNSTABLE: new API, yet to be vetted. * * Close closes the socket. Any pending message promises will be rejected @@ -1624,6 +1613,7 @@ declare namespace Deno { close(): void; /** Return the address of the `Listener`. */ readonly addr: Addr; + [Symbol.asyncIterator](): AsyncIterator<Conn>; } @@ -1648,13 +1638,12 @@ declare namespace Deno { /** A literal IP address or host name that can be resolved to an IP address. * If not specified, defaults to `0.0.0.0`. */ hostname?: string; - /** Either `"tcp"` or `"udp"`. Defaults to `"tcp"`. - * - * In the future: `"tcp4"`, `"tcp6"`, `"udp4"`, `"udp6"`, `"ip"`, `"ip4"`, - * `"ip6"`, `"unix"`, `"unixgram"`, and `"unixpacket"`. */ - transport?: Transport; } + export interface UnixListenOptions { + /** A Path to the Unix Socket. */ + address: string; + } /** **UNSTABLE**: new API * * Listen announces on the local transport address. @@ -1672,32 +1661,41 @@ declare namespace Deno { * * Listen announces on the local transport address. * - * Deno.listen({ port: 80 }) - * Deno.listen({ hostname: "192.0.2.1", port: 80 }) - * Deno.listen({ hostname: "[2001:db8::1]", port: 80 }); - * Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" }); + * Deno.listen({ address: "/foo/bar.sock", transport: "unix" }) + * + * Requires `allow-read` permission. */ + export function listen( + options: UnixListenOptions & { transport: "unix" } + ): Listener; + /** **UNSTABLE**: new API + * + * Listen announces on the local transport address. + * + * Deno.listen({ port: 80, transport: "udp" }) + * Deno.listen({ hostname: "golang.org", port: 80, transport: "udp" }); * * Requires `allow-net` permission. */ export function listen( options: ListenOptions & { transport: "udp" } - ): UDPConn; + ): DatagramConn; /** **UNSTABLE**: new API * * Listen announces on the local transport address. * - * Deno.listen({ port: 80 }) - * Deno.listen({ hostname: "192.0.2.1", port: 80 }) - * Deno.listen({ hostname: "[2001:db8::1]", port: 80 }); - * Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" }); + * Deno.listen({ address: "/foo/bar.sock", transport: "unixpacket" }) * - * Requires `allow-net` permission. */ - export function listen(options: ListenOptions): Listener | UDPConn; + * Requires `allow-read` permission. */ + export function listen( + options: UnixListenOptions & { transport: "unixpacket" } + ): DatagramConn; export interface ListenTLSOptions extends ListenOptions { /** Server certificate file. */ certFile: string; /** Server public key file. */ keyFile: string; + + transport?: "tcp"; } /** Listen announces on the local transport address over TLS (transport layer @@ -1714,11 +1712,12 @@ declare namespace Deno { /** A literal IP address or host name that can be resolved to an IP address. * If not specified, defaults to `127.0.0.1`. */ hostname?: string; - /** Either `"tcp"` or `"udp"`. Defaults to `"tcp"`. - * - * In the future: `"tcp4"`, `"tcp6"`, `"udp4"`, `"udp6"`, `"ip"`, `"ip4"`, - * `"ip6"`, `"unix"`, `"unixgram"`, and `"unixpacket"`. */ - transport?: Transport; + transport?: "tcp"; + } + + export interface UnixConnectOptions { + transport: "unix"; + address: string; } /** @@ -1728,10 +1727,13 @@ declare namespace Deno { * const conn1 = await Deno.connect({ port: 80 }) * const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 }) * const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 }); - * const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" }) + * const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" }); + * const conn5 = await Deno.connect({ address: "/foo/bar.sock", transport: "unix" }); * - * Requires `allow-net` permission. */ - export function connect(options: ConnectOptions): Promise<Conn>; + * Requires `allow-net` permission for "tcp" and `allow-read` for unix. */ + export function connect( + options: ConnectOptions | UnixConnectOptions + ): Promise<Conn>; export interface ConnectTLSOptions { /** The port to connect to. */ |