diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 1 | ||||
-rw-r--r-- | cli/build.rs | 11 | ||||
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 144 | ||||
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 257 | ||||
-rw-r--r-- | cli/main.rs | 2 | ||||
-rw-r--r-- | cli/tests/integration/mod.rs | 6 | ||||
-rw-r--r-- | cli/tsc.rs | 3 |
7 files changed, 22 insertions, 402 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8052f06a5..c46bfb17a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -25,6 +25,7 @@ deno_console = { version = "0.10.0", path = "../extensions/console" } deno_core = { version = "0.92.0", path = "../core" } deno_crypto = { version = "0.24.0", path = "../extensions/crypto" } deno_fetch = { version = "0.32.0", path = "../extensions/fetch" } +deno_net = { version = "0.1.0", path = "../extensions/net" } deno_timers = { version = "0.8.0", path = "../extensions/timers" } deno_url = { version = "0.10.0", path = "../extensions/url" } deno_web = { version = "0.41.0", path = "../extensions/web" } diff --git a/cli/build.rs b/cli/build.rs index 5e872ab2c..f932d5eff 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -68,6 +68,9 @@ fn create_compiler_snapshot( "deno.broadcast_channel", deno_broadcast_channel::get_declaration(), ); + op_crate_libs.insert("deno.net", deno_net::get_declaration()); + op_crate_libs + .insert("deno.net_unstable", deno_net::get_unstable_declaration()); // ensure we invalidate the build properly. for (_, path) in op_crate_libs.iter() { @@ -302,6 +305,14 @@ fn main() { "cargo:rustc-env=DENO_BROADCAST_CHANNEL_LIB_PATH={}", deno_broadcast_channel::get_declaration().display() ); + println!( + "cargo:rustc-env=DENO_NET_LIB_PATH={}", + deno_net::get_declaration().display() + ); + println!( + "cargo:rustc-env=DENO_NET_UNSTABLE_LIB_PATH={}", + deno_net::get_unstable_declaration().display() + ); println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap()); diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index e83858586..e1c558f37 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -2,6 +2,7 @@ /// <reference no-default-lib="true" /> /// <reference lib="esnext" /> +/// <reference lib="deno.net" /> /** Deno provides extra properties on `import.meta`. These are included here * to ensure that these are still available when using the Deno namespace in @@ -1784,149 +1785,6 @@ declare namespace Deno { * Requires `allow-write` permission. */ export function truncate(name: string, len?: number): Promise<void>; - export interface NetAddr { - transport: "tcp" | "udp"; - hostname: string; - port: number; - } - - 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<Conn> { - /** Waits for and resolves to the next connection to the `Listener`. */ - accept(): Promise<Conn>; - /** Close closes the listener. Any pending accept promises will be rejected - * with errors. */ - close(): void; - /** Return the address of the `Listener`. */ - readonly addr: Addr; - - /** Return the rid of the `Listener`. */ - readonly rid: number; - - [Symbol.asyncIterator](): AsyncIterableIterator<Conn>; - } - - export interface Conn extends Reader, Writer, Closer { - /** The local address of the connection. */ - readonly localAddr: Addr; - /** The remote address of the connection. */ - readonly remoteAddr: Addr; - /** The resource ID of the connection. */ - readonly rid: number; - /** Shuts down (`shutdown(2)`) the write side of the connection. Most - * callers should just use `close()`. */ - closeWrite(): Promise<void>; - } - - export interface ListenOptions { - /** The port to listen on. */ - port: number; - /** 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; - } - - /** Listen announces on the local transport address. - * - * ```ts - * const listener1 = Deno.listen({ port: 80 }) - * const listener2 = Deno.listen({ hostname: "192.0.2.1", port: 80 }) - * const listener3 = Deno.listen({ hostname: "[2001:db8::1]", port: 80 }); - * const listener4 = Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" }); - * ``` - * - * Requires `allow-net` permission. */ - export function listen( - options: ListenOptions & { transport?: "tcp" }, - ): Listener; - - 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 - * security). - * - * ```ts - * const lstnr = Deno.listenTls({ port: 443, certFile: "./server.crt", keyFile: "./server.key" }); - * ``` - * - * Requires `allow-net` permission. */ - export function listenTls(options: ListenTlsOptions): Listener; - - export interface ConnectOptions { - /** The port to connect to. */ - port: number; - /** 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; - transport?: "tcp"; - } - - /** - * 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`). - * - * ```ts - * 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" }); - * ``` - * - * Requires `allow-net` permission for "tcp". */ - export function connect(options: ConnectOptions): Promise<Conn>; - - export interface ConnectTlsOptions { - /** The port to connect to. */ - port: number; - /** 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; - /** Server certificate file. */ - certFile?: string; - } - - /** Establishes a secure connection over TLS (transport layer security) using - * an optional cert file, hostname (default is "127.0.0.1") and port. The - * cert file is optional and if not included Mozilla's root certificates will - * be used (see also https://github.com/ctz/webpki-roots for specifics) - * - * ```ts - * const conn1 = await Deno.connectTls({ port: 80 }); - * const conn2 = await Deno.connectTls({ certFile: "./certs/my_custom_root_CA.pem", hostname: "192.0.2.1", port: 80 }); - * const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 }); - * const conn4 = await Deno.connectTls({ certFile: "./certs/my_custom_root_CA.pem", hostname: "golang.org", port: 80}); - * ``` - * - * Requires `allow-net` permission. - */ - export function connectTls(options: ConnectTlsOptions): Promise<Conn>; - - /** Shutdown socket send operations. - * - * Matches behavior of POSIX shutdown(3). - * - * ```ts - * const listener = Deno.listen({ port: 80 }); - * const conn = await listener.accept(); - * Deno.shutdown(conn.rid); - * ``` - */ - export function shutdown(rid: number): Promise<void>; - export interface Metrics { opsDispatched: number; opsDispatchedSync: number; diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 1d01a748e..ac03e695c 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -2,6 +2,7 @@ /// <reference no-default-lib="true" /> /// <reference lib="deno.ns" /> +/// <reference lib="deno.net_unstable" /> declare namespace Deno { /** @@ -812,232 +813,6 @@ declare namespace Deno { mtime: number | Date, ): Promise<void>; - /** The type of the resource record. - * Only the listed types are supported currently. */ - export type RecordType = - | "A" - | "AAAA" - | "ANAME" - | "CNAME" - | "MX" - | "PTR" - | "SRV" - | "TXT"; - - export interface ResolveDnsOptions { - /** The name server to be used for lookups. - * If not specified, defaults to the system configuration e.g. `/etc/resolv.conf` on Unix. */ - nameServer?: { - /** The IP address of the name server */ - ipAddr: string; - /** The port number the query will be sent to. - * If not specified, defaults to 53. */ - port?: number; - }; - } - - /** If `resolveDns` is called with "MX" record type specified, it will return an array of this interface. */ - export interface MXRecord { - preference: number; - exchange: string; - } - - /** If `resolveDns` is called with "SRV" record type specified, it will return an array of this interface. */ - export interface SRVRecord { - priority: number; - weight: number; - port: number; - target: string; - } - - export function resolveDns( - query: string, - recordType: "A" | "AAAA" | "ANAME" | "CNAME" | "PTR", - options?: ResolveDnsOptions, - ): Promise<string[]>; - - export function resolveDns( - query: string, - recordType: "MX", - options?: ResolveDnsOptions, - ): Promise<MXRecord[]>; - - export function resolveDns( - query: string, - recordType: "SRV", - options?: ResolveDnsOptions, - ): Promise<SRVRecord[]>; - - export function resolveDns( - query: string, - recordType: "TXT", - options?: ResolveDnsOptions, - ): Promise<string[][]>; - - /** ** UNSTABLE**: new API, yet to be vetted. - * - * Performs DNS resolution against the given query, returning resolved records. - * Fails in the cases such as: - * - the query is in invalid format - * - the options have an invalid parameter, e.g. `nameServer.port` is beyond the range of 16-bit unsigned integer - * - timed out - * - * ```ts - * const a = await Deno.resolveDns("example.com", "A"); - * - * const aaaa = await Deno.resolveDns("example.com", "AAAA", { - * nameServer: { ipAddr: "8.8.8.8", port: 1234 }, - * }); - * ``` - * - * Requires `allow-net` permission. - */ - export function resolveDns( - query: string, - recordType: RecordType, - options?: ResolveDnsOptions, - ): Promise<string[] | MXRecord[] | SRVRecord[] | string[][]>; - - /** **UNSTABLE**: new API, yet to be vetted. - * - * A generic transport listener for message-oriented protocols. */ - 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, Addr]>; - /** UNSTABLE: new API, yet to be vetted. - * - * Sends a message to the target. */ - send(p: Uint8Array, addr: Addr): 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]>; - } - - export interface UnixListenOptions { - /** A Path to the Unix Socket. */ - path: string; - } - - /** **UNSTABLE**: new API, yet to be vetted. - * - * Listen announces on the local transport address. - * - * ```ts - * const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" }) - * ``` - * - * Requires `allow-read` and `allow-write` permission. */ - export function listen( - options: UnixListenOptions & { transport: "unix" }, - ): Listener; - - /** **UNSTABLE**: new API, yet to be vetted - * - * Listen announces on the local transport address. - * - * ```ts - * const listener1 = Deno.listenDatagram({ - * port: 80, - * transport: "udp" - * }); - * const listener2 = Deno.listenDatagram({ - * hostname: "golang.org", - * port: 80, - * transport: "udp" - * }); - * ``` - * - * Requires `allow-net` permission. */ - export function listenDatagram( - options: ListenOptions & { transport: "udp" }, - ): DatagramConn; - - /** **UNSTABLE**: new API, yet to be vetted - * - * Listen announces on the local transport address. - * - * ```ts - * const listener = Deno.listenDatagram({ - * path: "/foo/bar.sock", - * transport: "unixpacket" - * }); - * ``` - * - * Requires `allow-read` and `allow-write` permission. */ - export function listenDatagram( - options: UnixListenOptions & { transport: "unixpacket" }, - ): DatagramConn; - - export interface UnixConnectOptions { - transport: "unix"; - path: string; - } - - /** **UNSTABLE**: The unix socket transport is unstable as a new API yet to - * be vetted. The TCP transport is considered stable. - * - * 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`). - * - * ```ts - * 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 conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" }); - * ``` - * - * Requires `allow-net` permission for "tcp" and `allow-read` for "unix". */ - export function connect( - options: ConnectOptions | UnixConnectOptions, - ): Promise<Conn>; - - export interface StartTlsOptions { - /** 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; - /** Server certificate file. */ - certFile?: string; - } - - /** **UNSTABLE**: new API, yet to be vetted. - * - * Start TLS handshake from an existing connection using - * an optional cert file, hostname (default is "127.0.0.1"). The - * cert file is optional and if not included Mozilla's root certificates will - * be used (see also https://github.com/ctz/webpki-roots for specifics) - * Using this function requires that the other end of the connection is - * prepared for TLS handshake. - * - * ```ts - * const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" }); - * const tlsConn = await Deno.startTls(conn, { certFile: "./certs/my_custom_root_CA.pem", hostname: "localhost" }); - * ``` - * - * Requires `allow-net` permission. - */ - export function startTls( - conn: Conn, - options?: StartTlsOptions, - ): Promise<Conn>; - - export interface ListenTlsOptions { - /** **UNSTABLE**: new API, yet to be vetted. - * - * Application-Layer Protocol Negotiation (ALPN) protocols to announce to - * the client. If not specified, no ALPN extension will be included in the - * TLS handshake. - */ - alpnProtocols?: string[]; - } - /** **UNSTABLE**: The `signo` argument may change to require the Deno.Signal * enum. * @@ -1182,36 +957,6 @@ declare namespace Deno { bytesReceived: number; } - export interface RequestEvent { - readonly request: Request; - respondWith(r: Response | Promise<Response>): Promise<void>; - } - - export interface HttpConn extends AsyncIterable<RequestEvent> { - readonly rid: number; - - nextRequest(): Promise<RequestEvent | null>; - close(): void; - } - - /** **UNSTABLE**: new API, yet to be vetted. - * - * Services HTTP requests given a TCP or TLS socket. - * - * ```ts - * const conn = await Deno.connect({ port: 80, hostname: "127.0.0.1" }); - * const httpConn = Deno.serveHttp(conn); - * const e = await httpConn.nextRequest(); - * if (e) { - * e.respondWith(new Response("Hello World")); - * } - * ``` - * - * If `httpConn.nextRequest()` encounters an error or returns `null` - * then the underlying HttpConn resource is closed automatically. - */ - export function serveHttp(conn: Conn): HttpConn; - /** **UNSTABLE**: New option, yet to be vetted. */ export interface TestDefinition { /** Specifies the permissions that should be used to run the test. diff --git a/cli/main.rs b/cli/main.rs index 38db7d13f..f1cf67ac4 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -334,12 +334,14 @@ pub fn get_types(unstable: bool) -> String { crate::tsc::DENO_WEBSTORAGE_LIB, crate::tsc::DENO_CRYPTO_LIB, crate::tsc::DENO_BROADCAST_CHANNEL_LIB, + crate::tsc::DENO_NET_LIB, crate::tsc::SHARED_GLOBALS_LIB, crate::tsc::WINDOW_LIB, ]; if unstable { types.push(crate::tsc::UNSTABLE_NS_LIB); + types.push(crate::tsc::DENO_NET_UNSTABLE_LIB); } types.join("\n") diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index fab2f20a5..c11d26dc9 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -2,9 +2,9 @@ use crate::itest; use deno_core::url; -use deno_runtime::ops::tls::rustls; -use deno_runtime::ops::tls::webpki; -use deno_runtime::ops::tls::TlsStream; +use deno_runtime::deno_net::ops_tls::rustls; +use deno_runtime::deno_net::ops_tls::webpki; +use deno_runtime::deno_net::ops_tls::TlsStream; use std::fs; use std::io::BufReader; use std::io::Cursor; diff --git a/cli/tsc.rs b/cli/tsc.rs index 3e7974a97..59b4ac81a 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -44,6 +44,9 @@ pub static DENO_WEBSTORAGE_LIB: &str = pub static DENO_CRYPTO_LIB: &str = include_str!(env!("DENO_CRYPTO_LIB_PATH")); pub static DENO_BROADCAST_CHANNEL_LIB: &str = include_str!(env!("DENO_BROADCAST_CHANNEL_LIB_PATH")); +pub static DENO_NET_LIB: &str = include_str!(env!("DENO_NET_LIB_PATH")); +pub static DENO_NET_UNSTABLE_LIB: &str = + include_str!(env!("DENO_NET_UNSTABLE_LIB_PATH")); pub static SHARED_GLOBALS_LIB: &str = include_str!("dts/lib.deno.shared_globals.d.ts"); pub static WINDOW_LIB: &str = include_str!("dts/lib.deno.window.d.ts"); |