aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-01-11 14:56:41 -0800
committerGravatar GitHub <noreply@github.com> 2023-01-11 14:56:41 -0800
commit4969f068f63e68a19aacc67cc094421fa7297c07 (patch)
tree32943736fa378773c6eccd6967fa3dfc0c3f201d
parent4a1470d26c9d303ad9de93185e1e877d144d5592 (diff)
downloadbun-4969f068f63e68a19aacc67cc094421fa7297c07.tar.gz
bun-4969f068f63e68a19aacc67cc094421fa7297c07.tar.zst
bun-4969f068f63e68a19aacc67cc094421fa7297c07.zip
Types update (#1761)
* Fix type tests * Add dns types * Add node:net types * Make process.exit return never * Make ArrayBufferView tighter * Add types for node:dns * Remove docs * Use latest * Fix CI * Fix CI * Stop double trigger Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
-rw-r--r--.github/workflows/bun-types-tests.yml3
-rw-r--r--packages/bun-types/buffer.d.ts3
-rw-r--r--packages/bun-types/bun.d.ts7
-rw-r--r--packages/bun-types/child_process.d.ts2
-rw-r--r--packages/bun-types/crypto.d.ts1
-rw-r--r--packages/bun-types/dns.d.ts895
-rw-r--r--packages/bun-types/dns/promises.d.ts402
-rw-r--r--packages/bun-types/fs.d.ts2
-rw-r--r--packages/bun-types/fs/promises.d.ts1
-rw-r--r--packages/bun-types/globals.d.ts4
-rw-r--r--packages/bun-types/net.d.ts1007
-rw-r--r--packages/bun-types/package.json2
-rw-r--r--packages/bun-types/string_decoder.d.ts5
-rw-r--r--packages/bun-types/tsconfig.json1
-rw-r--r--packages/bun-types/zlib.d.ts1
15 files changed, 2323 insertions, 13 deletions
diff --git a/.github/workflows/bun-types-tests.yml b/.github/workflows/bun-types-tests.yml
index 152a89197..a0aca829f 100644
--- a/.github/workflows/bun-types-tests.yml
+++ b/.github/workflows/bun-types-tests.yml
@@ -3,6 +3,7 @@ on:
push:
paths:
- packages/bun-types/**/*
+ branches: [main]
pull_request:
paths:
- packages/bun-types/**/*
@@ -22,7 +23,7 @@ jobs:
- name: Install bun
uses: xhyrom/setup-bun@v0.1.8
with:
- bun-version: canary
+ bun-version: latest
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install node
diff --git a/packages/bun-types/buffer.d.ts b/packages/bun-types/buffer.d.ts
index a7de0cfe4..5a0dd071a 100644
--- a/packages/bun-types/buffer.d.ts
+++ b/packages/bun-types/buffer.d.ts
@@ -44,6 +44,7 @@
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/buffer.js)
*/
declare module "buffer" {
+ import { ArrayBufferView } from "bun";
export const INSPECT_MAX_BYTES: number;
export const kMaxLength: number;
export type TranscodeEncoding =
@@ -244,7 +245,7 @@ declare module "buffer" {
* @return The number of bytes contained within `string`.
*/
byteLength(
- string: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
+ string: string | ArrayBufferView | ArrayBufferLike,
encoding?: BufferEncoding,
): number;
/**
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts
index 8eb664ce1..1b5ec60ba 100644
--- a/packages/bun-types/bun.d.ts
+++ b/packages/bun-types/bun.d.ts
@@ -1,5 +1,3 @@
-import { Encoding } from "crypto";
-
interface VoidFunction {
(): void;
}
@@ -28,6 +26,8 @@ declare namespace Bun {
*
*/
declare module "bun" {
+ type ArrayBufferView = TypedArray | DataView;
+ import { Encoding as CryptoEncoding } from "crypto";
/**
* The environment variables of the process
*
@@ -2085,7 +2085,7 @@ declare module "bun" {
*
* @param input
*/
- update(input: StringOrBuffer, inputEncoding?: Encoding): CryptoHasher;
+ update(input: StringOrBuffer, inputEncoding?: CryptoEncoding): CryptoHasher;
/**
* Finalize the hash
@@ -3225,6 +3225,7 @@ type TypedArray =
| Uint32Array
| Float32Array
| Float64Array;
+
type TimeLike = string | number | Date;
type StringOrBuffer = string | TypedArray | ArrayBufferLike;
type PathLike = string | TypedArray | ArrayBufferLike | URL;
diff --git a/packages/bun-types/child_process.d.ts b/packages/bun-types/child_process.d.ts
index c36a7dd0d..04389986f 100644
--- a/packages/bun-types/child_process.d.ts
+++ b/packages/bun-types/child_process.d.ts
@@ -66,7 +66,7 @@
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/child_process.js)
*/
declare module "child_process" {
- import { SpawnOptions } from "bun";
+ import { SpawnOptions, ArrayBufferView } from "bun";
import { ObjectEncodingOptions } from "node:fs";
import { EventEmitter, Abortable } from "node:events";
diff --git a/packages/bun-types/crypto.d.ts b/packages/bun-types/crypto.d.ts
index 288bfe916..411deebd5 100644
--- a/packages/bun-types/crypto.d.ts
+++ b/packages/bun-types/crypto.d.ts
@@ -16,6 +16,7 @@
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/crypto.js)
*/
declare module "crypto" {
+ import { ArrayBufferView } from "bun";
import * as stream from "node:stream";
/**
* SPKAC is a Certificate Signing Request mechanism originally implemented by
diff --git a/packages/bun-types/dns.d.ts b/packages/bun-types/dns.d.ts
new file mode 100644
index 000000000..b5c9a777b
--- /dev/null
+++ b/packages/bun-types/dns.d.ts
@@ -0,0 +1,895 @@
+/**
+ * The `dns` module enables name resolution. For example, use it to look up IP
+ * addresses of host names.
+ *
+ * Although named for the [Domain Name System (DNS)](https://en.wikipedia.org/wiki/Domain_Name_System), it does not always use the
+ * DNS protocol for lookups. {@link lookup} uses the operating system
+ * facilities to perform name resolution. It may not need to perform any network
+ * communication. To perform name resolution the way other applications on the same
+ * system do, use {@link lookup}.
+ *
+ * ```js
+ * const dns = require('dns');
+ *
+ * dns.lookup('example.org', (err, address, family) => {
+ * console.log('address: %j family: IPv%s', address, family);
+ * });
+ * // address: "93.184.216.34" family: IPv4
+ * ```
+ *
+ * All other functions in the `dns` module connect to an actual DNS server to
+ * perform name resolution. They will always use the network to perform DNS
+ * queries. These functions do not use the same set of configuration files used by {@link lookup} (e.g. `/etc/hosts`). Use these functions to always perform
+ * DNS queries, bypassing other name-resolution facilities.
+ *
+ * ```js
+ * const dns = require('dns');
+ *
+ * dns.resolve4('archive.org', (err, addresses) => {
+ * if (err) throw err;
+ *
+ * console.log(`addresses: ${JSON.stringify(addresses)}`);
+ *
+ * addresses.forEach((a) => {
+ * dns.reverse(a, (err, hostnames) => {
+ * if (err) {
+ * throw err;
+ * }
+ * console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
+ * });
+ * });
+ * });
+ * ```
+ *
+ * See the `Implementation considerations section` for more information.
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/dns.js)
+ */
+declare module "dns" {
+ import * as dnsPromises from "node:dns/promises";
+ // Supported getaddrinfo flags.
+ export const ADDRCONFIG: number;
+ export const V4MAPPED: number;
+ /**
+ * If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
+ * well as IPv4 mapped IPv6 addresses.
+ */
+ export const ALL: number;
+ export interface LookupOptions {
+ family?: number | undefined;
+ // hints?: number | undefined;
+ // all?: boolean | undefined;
+ /**
+ * @default true
+ */
+ // verbatim?: boolean | undefined;
+ }
+ export interface LookupOneOptions extends LookupOptions {
+ // all?: false | undefined;
+ }
+ export interface LookupAllOptions extends LookupOptions {
+ // all: true;
+ }
+ export interface LookupAddress {
+ address: string;
+ family: number;
+ }
+ /**
+ * Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
+ * AAAA (IPv6) record. All `option` properties are optional. If `options` is an
+ * integer, then it must be `4` or `6` – if `options` is not provided, then IPv4
+ * and IPv6 addresses are both returned if found.
+ *
+ * With the `all` option set to `true`, the arguments for `callback` change to`(err, addresses)`, with `addresses` being an array of objects with the
+ * properties `address` and `family`.
+ *
+ * On error, `err` is an `Error` object, where `err.code` is the error code.
+ * Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
+ * the host name does not exist but also when the lookup fails in other ways
+ * such as no available file descriptors.
+ *
+ * `dns.lookup()` does not necessarily have anything to do with the DNS protocol.
+ * The implementation uses an operating system facility that can associate names
+ * with addresses, and vice versa. This implementation can have subtle but
+ * important consequences on the behavior of any Node.js program. Please take some
+ * time to consult the `Implementation considerations section` before using`dns.lookup()`.
+ *
+ * Example usage:
+ *
+ * ```js
+ * const dns = require('dns');
+ * const options = {
+ * family: 6,
+ * hints: dns.ADDRCONFIG | dns.V4MAPPED,
+ * };
+ * dns.lookup('example.com', options, (err, address, family) =>
+ * console.log('address: %j family: IPv%s', address, family));
+ * // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
+ *
+ * // When options.all is true, the result will be an Array.
+ * options.all = true;
+ * dns.lookup('example.com', options, (err, addresses) =>
+ * console.log('addresses: %j', addresses));
+ * // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
+ * ```
+ *
+ * If this method is invoked as its `util.promisify()` ed version, and `all`is not set to `true`, it returns a `Promise` for an `Object` with `address` and`family` properties.
+ * @since v0.1.90
+ */
+ export function lookup(
+ hostname: string,
+ family: number,
+ callback: (
+ err: ErrnoException | null,
+ address: string,
+ family: number,
+ ) => void,
+ ): void;
+ // export function lookup(
+ // hostname: string,
+ // options: LookupOneOptions,
+ // callback: (
+ // err: ErrnoException | null,
+ // address: string,
+ // family: number,
+ // ) => void,
+ // ): void;
+ // export function lookup(
+ // hostname: string,
+ // options: LookupAllOptions,
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses: LookupAddress[],
+ // ) => void,
+ // ): void;
+ export function lookup(
+ hostname: string,
+ options: LookupOptions,
+ callback: (
+ err: ErrnoException | null,
+ address: string | LookupAddress[],
+ family: number,
+ ) => void,
+ ): void;
+ export function lookup(
+ hostname: string,
+ callback: (
+ err: ErrnoException | null,
+ address: string,
+ family: number,
+ ) => void,
+ ): void;
+ // export namespace lookup {
+ // function __promisify__(
+ // hostname: string,
+ // options: LookupAllOptions,
+ // ): Promise<LookupAddress[]>;
+ // function __promisify__(
+ // hostname: string,
+ // options?: LookupOneOptions | number,
+ // ): Promise<LookupAddress>;
+ // function __promisify__(
+ // hostname: string,
+ // options: LookupOptions,
+ // ): Promise<LookupAddress | LookupAddress[]>;
+ // }
+ /**
+ * Resolves the given `address` and `port` into a host name and service using
+ * the operating system's underlying `getnameinfo` implementation.
+ *
+ * If `address` is not a valid IP address, a `TypeError` will be thrown.
+ * The `port` will be coerced to a number. If it is not a legal port, a `TypeError`will be thrown.
+ *
+ * On an error, `err` is an `Error` object, where `err.code` is the error code.
+ *
+ * ```js
+ * const dns = require('dns');
+ * dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
+ * console.log(hostname, service);
+ * // Prints: localhost ssh
+ * });
+ * ```
+ *
+ * If this method is invoked as its `util.promisify()` ed version, it returns a`Promise` for an `Object` with `hostname` and `service` properties.
+ * @since v0.11.14
+ */
+ export function lookupService(
+ address: string,
+ port: number,
+ callback: (
+ err: ErrnoException | null,
+ hostname: string,
+ service: string,
+ ) => void,
+ ): void;
+ // export namespace lookupService {
+ // function __promisify__(
+ // address: string,
+ // port: number,
+ // ): Promise<{
+ // hostname: string;
+ // service: string;
+ // }>;
+ // }
+ export interface ResolveOptions {
+ ttl: boolean;
+ }
+ export interface ResolveWithTtlOptions extends ResolveOptions {
+ ttl: true;
+ }
+ export interface RecordWithTtl {
+ address: string;
+ ttl: number;
+ }
+ /** @deprecated Use `AnyARecord` or `AnyAaaaRecord` instead. */
+ export type AnyRecordWithTtl = AnyARecord | AnyAaaaRecord;
+ export interface AnyARecord extends RecordWithTtl {
+ type: "A";
+ }
+ export interface AnyAaaaRecord extends RecordWithTtl {
+ type: "AAAA";
+ }
+ export interface CaaRecord {
+ critial: number;
+ issue?: string | undefined;
+ issuewild?: string | undefined;
+ iodef?: string | undefined;
+ contactemail?: string | undefined;
+ contactphone?: string | undefined;
+ }
+ export interface MxRecord {
+ priority: number;
+ exchange: string;
+ }
+ export interface AnyMxRecord extends MxRecord {
+ type: "MX";
+ }
+ export interface NaptrRecord {
+ flags: string;
+ service: string;
+ regexp: string;
+ replacement: string;
+ order: number;
+ preference: number;
+ }
+ export interface AnyNaptrRecord extends NaptrRecord {
+ type: "NAPTR";
+ }
+ export interface SoaRecord {
+ nsname: string;
+ hostmaster: string;
+ serial: number;
+ refresh: number;
+ retry: number;
+ expire: number;
+ minttl: number;
+ }
+ export interface AnySoaRecord extends SoaRecord {
+ type: "SOA";
+ }
+ export interface SrvRecord {
+ priority: number;
+ weight: number;
+ port: number;
+ name: string;
+ }
+ export interface AnySrvRecord extends SrvRecord {
+ type: "SRV";
+ }
+ export interface AnyTxtRecord {
+ type: "TXT";
+ entries: string[];
+ }
+ export interface AnyNsRecord {
+ type: "NS";
+ value: string;
+ }
+ export interface AnyPtrRecord {
+ type: "PTR";
+ value: string;
+ }
+ export interface AnyCnameRecord {
+ type: "CNAME";
+ value: string;
+ }
+ export type AnyRecord =
+ | AnyARecord
+ | AnyAaaaRecord
+ | AnyCnameRecord
+ | AnyMxRecord
+ | AnyNaptrRecord
+ | AnyNsRecord
+ | AnyPtrRecord
+ | AnySoaRecord
+ | AnySrvRecord
+ | AnyTxtRecord;
+ /**
+ * Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
+ * of the resource records. The `callback` function has arguments`(err, records)`. When successful, `records` will be an array of resource
+ * records. The type and structure of individual results varies based on `rrtype`:
+ *
+ * <omitted>
+ *
+ * On error, `err` is an `Error` object, where `err.code` is one of the `DNS error codes`.
+ * @since v0.1.27
+ * @param hostname Host name to resolve.
+ * @param [rrtype='A'] Resource record type.
+ */
+ export function resolve(
+ hostname: string,
+ callback: (err: ErrnoException | null, addresses: string[]) => void,
+ ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "A",
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "AAAA",
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "ANY",
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses: AnyRecord[],
+ // ) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "CNAME",
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "MX",
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses: MxRecord[],
+ // ) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "NAPTR",
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses: NaptrRecord[],
+ // ) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "NS",
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "PTR",
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "SOA",
+ // callback: (err: ErrnoException | null, addresses: SoaRecord) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "SRV",
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses: SrvRecord[],
+ // ) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: "TXT",
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses: string[][],
+ // ) => void,
+ // ): void;
+ // export function resolve(
+ // hostname: string,
+ // rrtype: string,
+ // callback: (
+ // err: ErrnoException | null,
+ // addresses:
+ // | string[]
+ // | MxRecord[]
+ // | NaptrRecord[]
+ // | SoaRecord
+ // | SrvRecord[]
+ // | string[][]
+ // | AnyRecord[],
+ // ) => void,
+ // ): void;
+ // export namespace resolve {
+ // function __promisify__(
+ // hostname: string,
+ // rrtype?: "A" | "AAAA" | "CNAME" | "NS" | "PTR",
+ // ): Promise<string[]>;
+ // function __promisify__(
+ // hostname: string,
+ // rrtype: "ANY",
+ // ): Promise<AnyRecord[]>;
+ // function __promisify__(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
+ // function __promisify__(
+ // hostname: string,
+ // rrtype: "NAPTR",
+ // ): Promise<NaptrRecord[]>;
+ // function __promisify__(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
+ // function __promisify__(
+ // hostname: string,
+ // rrtype: "SRV",
+ // ): Promise<SrvRecord[]>;
+ // function __promisify__(
+ // hostname: string,
+ // rrtype: "TXT",
+ // ): Promise<string[][]>;
+ // function __promisify__(
+ // hostname: string,
+ // rrtype: string,
+ // ): Promise<
+ // | string[]
+ // | MxRecord[]
+ // | NaptrRecord[]
+ // | SoaRecord
+ // | SrvRecord[]
+ // | string[][]
+ // | AnyRecord[]
+ // >;
+ // }
+ /**
+ * Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the`hostname`. The `addresses` argument passed to the `callback` function
+ * will contain an array of IPv4 addresses (e.g.`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
+ * @since v0.1.16
+ * @param hostname Host name to resolve.
+ */
+ export function resolve4(
+ hostname: string,
+ callback: (err: ErrnoException | null, addresses: string[]) => void,
+ ): void;
+ export function resolve4(
+ hostname: string,
+ options: ResolveWithTtlOptions,
+ callback: (err: ErrnoException | null, addresses: RecordWithTtl[]) => void,
+ ): void;
+ export function resolve4(
+ hostname: string,
+ options: ResolveOptions,
+ callback: (
+ err: ErrnoException | null,
+ addresses: string[] | RecordWithTtl[],
+ ) => void,
+ ): void;
+ // export namespace resolve4 {
+ // function __promisify__(hostname: string): Promise<string[]>;
+ // function __promisify__(
+ // hostname: string,
+ // options: ResolveWithTtlOptions,
+ // ): Promise<RecordWithTtl[]>;
+ // function __promisify__(
+ // hostname: string,
+ // options?: ResolveOptions,
+ // ): Promise<string[] | RecordWithTtl[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve a IPv6 addresses (`AAAA` records) for the`hostname`. The `addresses` argument passed to the `callback` function
+ * will contain an array of IPv6 addresses.
+ * @since v0.1.16
+ * @param hostname Host name to resolve.
+ */
+ export function resolve6(
+ hostname: string,
+ callback: (err: ErrnoException | null, addresses: string[]) => void,
+ ): void;
+ export function resolve6(
+ hostname: string,
+ options: ResolveWithTtlOptions,
+ callback: (err: ErrnoException | null, addresses: RecordWithTtl[]) => void,
+ ): void;
+ export function resolve6(
+ hostname: string,
+ options: ResolveOptions,
+ callback: (
+ err: ErrnoException | null,
+ addresses: string[] | RecordWithTtl[],
+ ) => void,
+ ): void;
+ // export namespace resolve6 {
+ // function __promisify__(hostname: string): Promise<string[]>;
+ // function __promisify__(
+ // hostname: string,
+ // options: ResolveWithTtlOptions,
+ // ): Promise<RecordWithTtl[]>;
+ // function __promisify__(
+ // hostname: string,
+ // options?: ResolveOptions,
+ // ): Promise<string[] | RecordWithTtl[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The`addresses` argument passed to the `callback` function
+ * will contain an array of canonical name records available for the `hostname`(e.g. `['bar.example.com']`).
+ * @since v0.3.2
+ */
+ // export function resolveCname(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export namespace resolveCname {
+ // function __promisify__(hostname: string): Promise<string[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve `CAA` records for the `hostname`. The`addresses` argument passed to the `callback` function
+ * will contain an array of certification authority authorization records
+ * available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]`).
+ * @since v15.0.0, v14.17.0
+ */
+ // export function resolveCaa(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, records: CaaRecord[]) => void,
+ // ): void;
+ // export namespace resolveCaa {
+ // function __promisify__(hostname: string): Promise<CaaRecord[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve mail exchange records (`MX` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
+ * contain an array of objects containing both a `priority` and `exchange`property (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`).
+ * @since v0.1.27
+ */
+ // export function resolveMx(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: MxRecord[]) => void,
+ // ): void;
+ // export namespace resolveMx {
+ // function __promisify__(hostname: string): Promise<MxRecord[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve regular expression based records (`NAPTR`records) for the `hostname`. The `addresses` argument passed to the `callback`function will contain an array of
+ * objects with the following properties:
+ *
+ * * `flags`
+ * * `service`
+ * * `regexp`
+ * * `replacement`
+ * * `order`
+ * * `preference`
+ *
+ * ```js
+ * {
+ * flags: 's',
+ * service: 'SIP+D2U',
+ * regexp: '',
+ * replacement: '_sip._udp.example.com',
+ * order: 30,
+ * preference: 100
+ * }
+ * ```
+ * @since v0.9.12
+ */
+ // export function resolveNaptr(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: NaptrRecord[]) => void,
+ // ): void;
+ // export namespace resolveNaptr {
+ // function __promisify__(hostname: string): Promise<NaptrRecord[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve name server records (`NS` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
+ * contain an array of name server records available for `hostname`(e.g. `['ns1.example.com', 'ns2.example.com']`).
+ * @since v0.1.90
+ */
+ // export function resolveNs(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export namespace resolveNs {
+ // function __promisify__(hostname: string): Promise<string[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve pointer records (`PTR` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
+ * be an array of strings containing the reply records.
+ * @since v6.0.0
+ */
+ // export function resolvePtr(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: string[]) => void,
+ // ): void;
+ // export namespace resolvePtr {
+ // function __promisify__(hostname: string): Promise<string[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
+ * the `hostname`. The `address` argument passed to the `callback` function will
+ * be an object with the following properties:
+ *
+ * * `nsname`
+ * * `hostmaster`
+ * * `serial`
+ * * `refresh`
+ * * `retry`
+ * * `expire`
+ * * `minttl`
+ *
+ * ```js
+ * {
+ * nsname: 'ns.example.com',
+ * hostmaster: 'root.example.com',
+ * serial: 2013101809,
+ * refresh: 10000,
+ * retry: 2400,
+ * expire: 604800,
+ * minttl: 3600
+ * }
+ * ```
+ * @since v0.11.10
+ */
+ // export function resolveSoa(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, address: SoaRecord) => void,
+ // ): void;
+ // export namespace resolveSoa {
+ // function __promisify__(hostname: string): Promise<SoaRecord>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve service records (`SRV` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
+ * be an array of objects with the following properties:
+ *
+ * * `priority`
+ * * `weight`
+ * * `port`
+ * * `name`
+ *
+ * ```js
+ * {
+ * priority: 10,
+ * weight: 5,
+ * port: 21223,
+ * name: 'service.example.com'
+ * }
+ * ```
+ * @since v0.1.27
+ */
+ // export function resolveSrv(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: SrvRecord[]) => void,
+ // ): void;
+ // export namespace resolveSrv {
+ // function __promisify__(hostname: string): Promise<SrvRecord[]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve text queries (`TXT` records) for the`hostname`. The `records` argument passed to the `callback` function is a
+ * two-dimensional array of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
+ * one record. Depending on the use case, these could be either joined together or
+ * treated separately.
+ * @since v0.1.27
+ */
+ // export function resolveTxt(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: string[][]) => void,
+ // ): void;
+ // export namespace resolveTxt {
+ // function __promisify__(hostname: string): Promise<string[][]>;
+ // }
+ /**
+ * Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
+ * The `ret` argument passed to the `callback` function will be an array containing
+ * various types of records. Each object has a property `type` that indicates the
+ * type of the current record. And depending on the `type`, additional properties
+ * will be present on the object:
+ *
+ * <omitted>
+ *
+ * Here is an example of the `ret` object passed to the callback:
+ *
+ * ```js
+ * [ { type: 'A', address: '127.0.0.1', ttl: 299 },
+ * { type: 'CNAME', value: 'example.com' },
+ * { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
+ * { type: 'NS', value: 'ns1.example.com' },
+ * { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
+ * { type: 'SOA',
+ * nsname: 'ns1.example.com',
+ * hostmaster: 'admin.example.com',
+ * serial: 156696742,
+ * refresh: 900,
+ * retry: 900,
+ * expire: 1800,
+ * minttl: 60 } ]
+ * ```
+ *
+ * DNS server operators may choose not to respond to `ANY`queries. It may be better to call individual methods like {@link resolve4},{@link resolveMx}, and so on. For more details, see [RFC
+ * 8482](https://tools.ietf.org/html/rfc8482).
+ */
+ // export function resolveAny(
+ // hostname: string,
+ // callback: (err: ErrnoException | null, addresses: AnyRecord[]) => void,
+ // ): void;
+ // export namespace resolveAny {
+ // function __promisify__(hostname: string): Promise<AnyRecord[]>;
+ // }
+ /**
+ * Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
+ * array of host names.
+ *
+ * On error, `err` is an `Error` object, where `err.code` is
+ * one of the `DNS error codes`.
+ * @since v0.1.16
+ */
+ // export function reverse(
+ // ip: string,
+ // callback: (err: ErrnoException | null, hostnames: string[]) => void,
+ // ): void;
+ /**
+ * Sets the IP address and port of servers to be used when performing DNS
+ * resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
+ * addresses. If the port is the IANA default DNS port (53) it can be omitted.
+ *
+ * ```js
+ * dns.setServers([
+ * '4.4.4.4',
+ * '[2001:4860:4860::8888]',
+ * '4.4.4.4:1053',
+ * '[2001:4860:4860::8888]:1053',
+ * ]);
+ * ```
+ *
+ * An error will be thrown if an invalid address is provided.
+ *
+ * The `dns.setServers()` method must not be called while a DNS query is in
+ * progress.
+ *
+ * The {@link setServers} method affects only {@link resolve},`dns.resolve*()` and {@link reverse} (and specifically _not_ {@link lookup}).
+ *
+ * This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
+ * That is, if attempting to resolve with the first server provided results in a`NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
+ * subsequent servers provided. Fallback DNS servers will only be used if the
+ * earlier ones time out or result in some other error.
+ * @since v0.11.3
+ * @param servers array of `RFC 5952` formatted addresses
+ */
+ // export function setServers(servers: ReadonlyArray<string>): void;
+ /**
+ * Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
+ * that are currently configured for DNS resolution. A string will include a port
+ * section if a custom port is used.
+ *
+ * ```js
+ * [
+ * '4.4.4.4',
+ * '2001:4860:4860::8888',
+ * '4.4.4.4:1053',
+ * '[2001:4860:4860::8888]:1053',
+ * ]
+ * ```
+ * @since v0.11.3
+ */
+ // export function getServers(): string[];
+ /**
+ * Set the default value of `verbatim` in {@link lookup} and `dnsPromises.lookup()`. The value could be:
+ *
+ * * `ipv4first`: sets default `verbatim` `false`.
+ * * `verbatim`: sets default `verbatim` `true`.
+ *
+ * The default is `ipv4first` and {@link setDefaultResultOrder} have higher
+ * priority than `--dns-result-order`. When using `worker threads`,{@link setDefaultResultOrder} from the main thread won't affect the default
+ * dns orders in workers.
+ * @since v16.4.0, v14.18.0
+ * @param order must be `'ipv4first'` or `'verbatim'`.
+ */
+ // export function setDefaultResultOrder(order: "ipv4first" | "verbatim"): void;
+ // Error codes
+ export const NODATA: string;
+ export const FORMERR: string;
+ export const SERVFAIL: string;
+ export const NOTFOUND: string;
+ export const NOTIMP: string;
+ export const REFUSED: string;
+ export const BADQUERY: string;
+ export const BADNAME: string;
+ export const BADFAMILY: string;
+ export const BADRESP: string;
+ export const CONNREFUSED: string;
+ export const TIMEOUT: string;
+ export const EOF: string;
+ export const FILE: string;
+ export const NOMEM: string;
+ export const DESTRUCTION: string;
+ export const BADSTR: string;
+ export const BADFLAGS: string;
+ export const NONAME: string;
+ export const BADHINTS: string;
+ export const NOTINITIALIZED: string;
+ export const LOADIPHLPAPI: string;
+ export const ADDRGETNETWORKPARAMS: string;
+ export const CANCELLED: string;
+ export interface ResolverOptions {
+ timeout?: number | undefined;
+ /**
+ * @default 4
+ */
+ tries?: number;
+ }
+ /**
+ * An independent resolver for DNS requests.
+ *
+ * Creating a new resolver uses the default server settings. Setting
+ * the servers used for a resolver using `resolver.setServers()` does not affect
+ * other resolvers:
+ *
+ * ```js
+ * const { Resolver } = require('dns');
+ * const resolver = new Resolver();
+ * resolver.setServers(['4.4.4.4']);
+ *
+ * // This request will use the server at 4.4.4.4, independent of global settings.
+ * resolver.resolve4('example.org', (err, addresses) => {
+ * // ...
+ * });
+ * ```
+ *
+ * The following methods from the `dns` module are available:
+ *
+ * * `resolver.getServers()`
+ * * `resolver.resolve()`
+ * * `resolver.resolve4()`
+ * * `resolver.resolve6()`
+ * * `resolver.resolveAny()`
+ * * `resolver.resolveCaa()`
+ * * `resolver.resolveCname()`
+ * * `resolver.resolveMx()`
+ * * `resolver.resolveNaptr()`
+ * * `resolver.resolveNs()`
+ * * `resolver.resolvePtr()`
+ * * `resolver.resolveSoa()`
+ * * `resolver.resolveSrv()`
+ * * `resolver.resolveTxt()`
+ * * `resolver.reverse()`
+ * * `resolver.setServers()`
+ * @since v8.3.0
+ */
+ export class Resolver {
+ constructor(options?: ResolverOptions);
+ /**
+ * Cancel all outstanding DNS queries made by this resolver. The corresponding
+ * callbacks will be called with an error with code `ECANCELLED`.
+ * @since v8.3.0
+ */
+ cancel(): void;
+ // getServers: typeof getServers;
+ resolve: typeof resolve;
+ resolve4: typeof resolve4;
+ resolve6: typeof resolve6;
+ // resolveAny: typeof resolveAny;
+ // resolveCname: typeof resolveCname;
+ // resolveMx: typeof resolveMx;
+ // resolveNaptr: typeof resolveNaptr;
+ // resolveNs: typeof resolveNs;
+ // resolvePtr: typeof resolvePtr;
+ // resolveSoa: typeof resolveSoa;
+ // resolveSrv: typeof resolveSrv;
+ // resolveTxt: typeof resolveTxt;
+ // reverse: typeof reverse;
+ /**
+ * The resolver instance will send its requests from the specified IP address.
+ * This allows programs to specify outbound interfaces when used on multi-homed
+ * systems.
+ *
+ * If a v4 or v6 address is not specified, it is set to the default, and the
+ * operating system will choose a local address automatically.
+ *
+ * The resolver will use the v4 local address when making requests to IPv4 DNS
+ * servers, and the v6 local address when making requests to IPv6 DNS servers.
+ * The `rrtype` of resolution requests has no impact on the local address used.
+ * @since v15.1.0, v14.17.0
+ * @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
+ * @param [ipv6='::0'] A string representation of an IPv6 address.
+ */
+ // setLocalAddress(ipv4?: string, ipv6?: string): void;
+ // setServers: typeof setServers;
+ }
+ export { dnsPromises as promises };
+}
+declare module "node:dns" {
+ export * from "dns";
+}
diff --git a/packages/bun-types/dns/promises.d.ts b/packages/bun-types/dns/promises.d.ts
new file mode 100644
index 000000000..6460128b2
--- /dev/null
+++ b/packages/bun-types/dns/promises.d.ts
@@ -0,0 +1,402 @@
+/**
+ * The `dns.promises` API provides an alternative set of asynchronous DNS methods
+ * that return `Promise` objects rather than using callbacks. The API is accessible
+ * via `require('dns').promises` or `require('dns/promises')`.
+ * @since v10.6.0
+ */
+declare module "dns/promises" {
+ import {
+ LookupAddress,
+ LookupOneOptions,
+ LookupAllOptions,
+ LookupOptions,
+ // AnyRecord,
+ // CaaRecord,
+ // MxRecord,
+ // NaptrRecord,
+ // SoaRecord,
+ // SrvRecord,
+ ResolveWithTtlOptions,
+ RecordWithTtl,
+ ResolveOptions,
+ ResolverOptions,
+ } from "node:dns";
+ /**
+ * Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
+ * that are currently configured for DNS resolution. A string will include a port
+ * section if a custom port is used.
+ *
+ * ```js
+ * [
+ * '4.4.4.4',
+ * '2001:4860:4860::8888',
+ * '4.4.4.4:1053',
+ * '[2001:4860:4860::8888]:1053',
+ * ]
+ * ```
+ * @since v10.6.0
+ */
+ // function getServers(): string[];
+ /**
+ * Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
+ * AAAA (IPv6) record. All `option` properties are optional. If `options` is an
+ * integer, then it must be `4` or `6` – if `options` is not provided, then IPv4
+ * and IPv6 addresses are both returned if found.
+ *
+ * With the `all` option set to `true`, the `Promise` is resolved with `addresses`being an array of objects with the properties `address` and `family`.
+ *
+ * On error, the `Promise` is rejected with an `Error` object, where `err.code`is the error code.
+ * Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
+ * the host name does not exist but also when the lookup fails in other ways
+ * such as no available file descriptors.
+ *
+ * `dnsPromises.lookup()` does not necessarily have anything to do with the DNS
+ * protocol. The implementation uses an operating system facility that can
+ * associate names with addresses, and vice versa. This implementation can have
+ * subtle but important consequences on the behavior of any Node.js program. Please
+ * take some time to consult the `Implementation considerations section` before
+ * using `dnsPromises.lookup()`.
+ *
+ * Example usage:
+ *
+ * ```js
+ * const dns = require('dns');
+ * const dnsPromises = dns.promises;
+ * const options = {
+ * family: 6,
+ * hints: dns.ADDRCONFIG | dns.V4MAPPED,
+ * };
+ *
+ * dnsPromises.lookup('example.com', options).then((result) => {
+ * console.log('address: %j family: IPv%s', result.address, result.family);
+ * // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
+ * });
+ *
+ * // When options.all is true, the result will be an Array.
+ * options.all = true;
+ * dnsPromises.lookup('example.com', options).then((result) => {
+ * console.log('addresses: %j', result);
+ * // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
+ * });
+ * ```
+ * @since v10.6.0
+ */
+ function lookup(hostname: string, family: number): Promise<LookupAddress>;
+ function lookup(
+ hostname: string,
+ options: LookupOneOptions,
+ ): Promise<LookupAddress>;
+ function lookup(
+ hostname: string,
+ options: LookupAllOptions,
+ ): Promise<LookupAddress[]>;
+ function lookup(
+ hostname: string,
+ options: LookupOptions,
+ ): Promise<LookupAddress | LookupAddress[]>;
+ function lookup(hostname: string): Promise<LookupAddress>;
+ /**
+ * Resolves the given `address` and `port` into a host name and service using
+ * the operating system's underlying `getnameinfo` implementation.
+ *
+ * If `address` is not a valid IP address, a `TypeError` will be thrown.
+ * The `port` will be coerced to a number. If it is not a legal port, a `TypeError`will be thrown.
+ *
+ * On error, the `Promise` is rejected with an `Error` object, where `err.code`is the error code.
+ *
+ * ```js
+ * const dnsPromises = require('dns').promises;
+ * dnsPromises.lookupService('127.0.0.1', 22).then((result) => {
+ * console.log(result.hostname, result.service);
+ * // Prints: localhost ssh
+ * });
+ * ```
+ * @since v10.6.0
+ */
+ function lookupService(
+ address: string,
+ port: number,
+ ): Promise<{
+ hostname: string;
+ service: string;
+ }>;
+ /**
+ * Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
+ * of the resource records. When successful, the `Promise` is resolved with an
+ * array of resource records. The type and structure of individual results vary
+ * based on `rrtype`:
+ *
+ * <omitted>
+ *
+ * On error, the `Promise` is rejected with an `Error` object, where `err.code`is one of the `DNS error codes`.
+ * @since v10.6.0
+ * @param hostname Host name to resolve.
+ * @param [rrtype='A'] Resource record type.
+ */
+ function resolve(hostname: string): Promise<string[]>;
+ // function resolve(hostname: string, rrtype: "A"): Promise<string[]>;
+ // function resolve(hostname: string, rrtype: "AAAA"): Promise<string[]>;
+ // function resolve(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
+ // function resolve(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>;
+ // function resolve(hostname: string, rrtype: "CNAME"): Promise<string[]>;
+ // function resolve(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
+ // function resolve(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
+ // function resolve(hostname: string, rrtype: "NS"): Promise<string[]>;
+ // function resolve(hostname: string, rrtype: "PTR"): Promise<string[]>;
+ // function resolve(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
+ // function resolve(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>;
+ // function resolve(hostname: string, rrtype: "TXT"): Promise<string[][]>;
+ // function resolve(
+ // hostname: string,
+ // rrtype: string,
+ // ): Promise<
+ // | string[]
+ // | MxRecord[]
+ // | NaptrRecord[]
+ // | SoaRecord
+ // | SrvRecord[]
+ // | string[][]
+ // | AnyRecord[]
+ // >;
+ /**
+ * Uses the DNS protocol to resolve IPv4 addresses (`A` records) for the`hostname`. On success, the `Promise` is resolved with an array of IPv4
+ * addresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
+ * @since v10.6.0
+ * @param hostname Host name to resolve.
+ */
+ function resolve4(hostname: string): Promise<string[]>;
+ function resolve4(
+ hostname: string,
+ options: ResolveWithTtlOptions,
+ ): Promise<RecordWithTtl[]>;
+ function resolve4(
+ hostname: string,
+ options: ResolveOptions,
+ ): Promise<string[] | RecordWithTtl[]>;
+ /**
+ * Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the`hostname`. On success, the `Promise` is resolved with an array of IPv6
+ * addresses.
+ * @since v10.6.0
+ * @param hostname Host name to resolve.
+ */
+ function resolve6(hostname: string): Promise<string[]>;
+ function resolve6(
+ hostname: string,
+ options: ResolveWithTtlOptions,
+ ): Promise<RecordWithTtl[]>;
+ function resolve6(
+ hostname: string,
+ options: ResolveOptions,
+ ): Promise<string[] | RecordWithTtl[]>;
+ /**
+ * Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
+ * On success, the `Promise` is resolved with an array containing various types of
+ * records. Each object has a property `type` that indicates the type of the
+ * current record. And depending on the `type`, additional properties will be
+ * present on the object:
+ *
+ * <omitted>
+ *
+ * Here is an example of the result object:
+ *
+ * ```js
+ * [ { type: 'A', address: '127.0.0.1', ttl: 299 },
+ * { type: 'CNAME', value: 'example.com' },
+ * { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
+ * { type: 'NS', value: 'ns1.example.com' },
+ * { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
+ * { type: 'SOA',
+ * nsname: 'ns1.example.com',
+ * hostmaster: 'admin.example.com',
+ * serial: 156696742,
+ * refresh: 900,
+ * retry: 900,
+ * expire: 1800,
+ * minttl: 60 } ]
+ * ```
+ * @since v10.6.0
+ */
+ // function resolveAny(hostname: string): Promise<AnyRecord[]>;
+ /**
+ * Uses the DNS protocol to resolve `CAA` records for the `hostname`. On success,
+ * the `Promise` is resolved with an array of objects containing available
+ * certification authority authorization records available for the `hostname`(e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]`).
+ * @since v15.0.0, v14.17.0
+ */
+ // function resolveCaa(hostname: string): Promise<CaaRecord[]>;
+ /**
+ * Uses the DNS protocol to resolve `CNAME` records for the `hostname`. On success,
+ * the `Promise` is resolved with an array of canonical name records available for
+ * the `hostname` (e.g. `['bar.example.com']`).
+ * @since v10.6.0
+ */
+ // function resolveCname(hostname: string): Promise<string[]>;
+ /**
+ * Uses the DNS protocol to resolve mail exchange records (`MX` records) for the`hostname`. On success, the `Promise` is resolved with an array of objects
+ * containing both a `priority` and `exchange` property (e.g.`[{priority: 10, exchange: 'mx.example.com'}, ...]`).
+ * @since v10.6.0
+ */
+ // function resolveMx(hostname: string): Promise<MxRecord[]>;
+ /**
+ * Uses the DNS protocol to resolve regular expression based records (`NAPTR`records) for the `hostname`. On success, the `Promise` is resolved with an array
+ * of objects with the following properties:
+ *
+ * * `flags`
+ * * `service`
+ * * `regexp`
+ * * `replacement`
+ * * `order`
+ * * `preference`
+ *
+ * ```js
+ * {
+ * flags: 's',
+ * service: 'SIP+D2U',
+ * regexp: '',
+ * replacement: '_sip._udp.example.com',
+ * order: 30,
+ * preference: 100
+ * }
+ * ```
+ * @since v10.6.0
+ */
+ // function resolveNaptr(hostname: string): Promise<NaptrRecord[]>;
+ /**
+ * Uses the DNS protocol to resolve name server records (`NS` records) for the`hostname`. On success, the `Promise` is resolved with an array of name server
+ * records available for `hostname` (e.g.`['ns1.example.com', 'ns2.example.com']`).
+ * @since v10.6.0
+ */
+ // function resolveNs(hostname: string): Promise<string[]>;
+ /**
+ * Uses the DNS protocol to resolve pointer records (`PTR` records) for the`hostname`. On success, the `Promise` is resolved with an array of strings
+ * containing the reply records.
+ * @since v10.6.0
+ */
+ // function resolvePtr(hostname: string): Promise<string[]>;
+ /**
+ * Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
+ * the `hostname`. On success, the `Promise` is resolved with an object with the
+ * following properties:
+ *
+ * * `nsname`
+ * * `hostmaster`
+ * * `serial`
+ * * `refresh`
+ * * `retry`
+ * * `expire`
+ * * `minttl`
+ *
+ * ```js
+ * {
+ * nsname: 'ns.example.com',
+ * hostmaster: 'root.example.com',
+ * serial: 2013101809,
+ * refresh: 10000,
+ * retry: 2400,
+ * expire: 604800,
+ * minttl: 3600
+ * }
+ * ```
+ * @since v10.6.0
+ */
+ // function resolveSoa(hostname: string): Promise<SoaRecord>;
+ /**
+ * Uses the DNS protocol to resolve service records (`SRV` records) for the`hostname`. On success, the `Promise` is resolved with an array of objects with
+ * the following properties:
+ *
+ * * `priority`
+ * * `weight`
+ * * `port`
+ * * `name`
+ *
+ * ```js
+ * {
+ * priority: 10,
+ * weight: 5,
+ * port: 21223,
+ * name: 'service.example.com'
+ * }
+ * ```
+ * @since v10.6.0
+ */
+ // function resolveSrv(hostname: string): Promise<SrvRecord[]>;
+ /**
+ * Uses the DNS protocol to resolve text queries (`TXT` records) for the`hostname`. On success, the `Promise` is resolved with a two-dimensional array
+ * of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
+ * one record. Depending on the use case, these could be either joined together or
+ * treated separately.
+ * @since v10.6.0
+ */
+ // function resolveTxt(hostname: string): Promise<string[][]>;
+ /**
+ * Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
+ * array of host names.
+ *
+ * On error, the `Promise` is rejected with an `Error` object, where `err.code`is one of the `DNS error codes`.
+ * @since v10.6.0
+ */
+ // function reverse(ip: string): Promise<string[]>;
+ /**
+ * Sets the IP address and port of servers to be used when performing DNS
+ * resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
+ * addresses. If the port is the IANA default DNS port (53) it can be omitted.
+ *
+ * ```js
+ * dnsPromises.setServers([
+ * '4.4.4.4',
+ * '[2001:4860:4860::8888]',
+ * '4.4.4.4:1053',
+ * '[2001:4860:4860::8888]:1053',
+ * ]);
+ * ```
+ *
+ * An error will be thrown if an invalid address is provided.
+ *
+ * The `dnsPromises.setServers()` method must not be called while a DNS query is in
+ * progress.
+ *
+ * This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
+ * That is, if attempting to resolve with the first server provided results in a`NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
+ * subsequent servers provided. Fallback DNS servers will only be used if the
+ * earlier ones time out or result in some other error.
+ * @since v10.6.0
+ * @param servers array of `RFC 5952` formatted addresses
+ */
+ // function setServers(servers: ReadonlyArray<string>): void;
+ /**
+ * Set the default value of `verbatim` in `dns.lookup()` and `dnsPromises.lookup()`. The value could be:
+ *
+ * * `ipv4first`: sets default `verbatim` `false`.
+ * * `verbatim`: sets default `verbatim` `true`.
+ *
+ * The default is `ipv4first` and `dnsPromises.setDefaultResultOrder()` have
+ * higher priority than `--dns-result-order`. When using `worker threads`,`dnsPromises.setDefaultResultOrder()` from the main thread won't affect the
+ * default dns orders in workers.
+ * @since v16.4.0, v14.18.0
+ * @param order must be `'ipv4first'` or `'verbatim'`.
+ */
+ // function setDefaultResultOrder(order: "ipv4first" | "verbatim"): void;
+ class Resolver {
+ constructor(options?: ResolverOptions);
+ cancel(): void;
+ // getServers: typeof getServers;
+ resolve: typeof resolve;
+ resolve4: typeof resolve4;
+ resolve6: typeof resolve6;
+ // resolveAny: typeof resolveAny;
+ // resolveCname: typeof resolveCname;
+ // resolveMx: typeof resolveMx;
+ // resolveNaptr: typeof resolveNaptr;
+ // resolveNs: typeof resolveNs;
+ // resolvePtr: typeof resolvePtr;
+ // resolveSoa: typeof resolveSoa;
+ // resolveSrv: typeof resolveSrv;
+ // resolveTxt: typeof resolveTxt;
+ // reverse: typeof reverse;
+ // setLocalAddress(ipv4?: string, ipv6?: string): void;
+ // setServers: typeof setServers;
+ }
+}
+declare module "node:dns/promises" {
+ export * from "dns/promises";
+}
diff --git a/packages/bun-types/fs.d.ts b/packages/bun-types/fs.d.ts
index c4fc1f99c..7e34d5873 100644
--- a/packages/bun-types/fs.d.ts
+++ b/packages/bun-types/fs.d.ts
@@ -19,7 +19,7 @@
*/
declare module "fs" {
import * as stream from "stream";
- import type { SystemError } from "bun";
+ import type { SystemError, ArrayBufferView } from "bun";
interface ObjectEncodingOptions {
encoding?: BufferEncoding | null | undefined;
diff --git a/packages/bun-types/fs/promises.d.ts b/packages/bun-types/fs/promises.d.ts
index 3749ca058..c4356da5c 100644
--- a/packages/bun-types/fs/promises.d.ts
+++ b/packages/bun-types/fs/promises.d.ts
@@ -8,6 +8,7 @@
* concurrent modifications on the same file or data corruption may occur.
*/
declare module "fs/promises" {
+ import { ArrayBufferView } from "bun";
import {
Stats,
BigIntStats,
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts
index a27ee2b92..8cf57b05a 100644
--- a/packages/bun-types/globals.d.ts
+++ b/packages/bun-types/globals.d.ts
@@ -351,7 +351,7 @@ interface Process {
revision: string;
chdir(directory: string): void;
cwd(): string;
- exit(code?: number): void;
+ exit(code?: number): never;
getgid(): number;
setgid(id: number | string): void;
getuid(): number;
@@ -1854,7 +1854,7 @@ declare var AbortSignal: {
// type AlgorithmIdentifier = Algorithm | string;
// type BodyInit = ReadableStream | XMLHttpRequestBodyInit;
-type BufferSource = ArrayBufferView | ArrayBuffer | SharedArrayBuffer;
+type BufferSource = TypedArray | DataView | ArrayBufferLike;
// type COSEAlgorithmIdentifier = number;
// type CSSNumberish = number;
// type CanvasImageSource =
diff --git a/packages/bun-types/net.d.ts b/packages/bun-types/net.d.ts
new file mode 100644
index 000000000..1e373f4ba
--- /dev/null
+++ b/packages/bun-types/net.d.ts
@@ -0,0 +1,1007 @@
+/**
+ * > Stability: 2 - Stable
+ *
+ * The `net` module provides an asynchronous network API for creating stream-based
+ * TCP or `IPC` servers ({@link createServer}) and clients
+ * ({@link createConnection}).
+ *
+ * It can be accessed using:
+ *
+ * ```js
+ * const net = require('net');
+ * ```
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/net.js)
+ */
+declare module "net" {
+ import * as stream from "node:stream";
+ import {
+ Abortable,
+ // EventEmitter
+ } from "node:events";
+ // import * as dns from "node:dns";
+ // type LookupFunction = (
+ // hostname: string,
+ // options: dns.LookupOneOptions,
+ // callback: (
+ // err: NodeJS.ErrnoException | null,
+ // address: string,
+ // family: number,
+ // ) => void,
+ // ) => void;
+ interface AddressInfo {
+ address: string;
+ family: string;
+ port: number;
+ }
+ interface SocketConstructorOpts {
+ // fd?: number | undefined;
+ allowHalfOpen?: boolean | undefined;
+ readable?: boolean | undefined;
+ writable?: boolean | undefined;
+ signal?: AbortSignal;
+ }
+ interface OnReadOpts {
+ buffer: Uint8Array | (() => Uint8Array);
+ /**
+ * This function is called for every chunk of incoming data.
+ * Two arguments are passed to it: the number of bytes written to buffer and a reference to buffer.
+ * Return false from this function to implicitly pause() the socket.
+ */
+ callback(bytesWritten: number, buf: Uint8Array): boolean;
+ }
+ interface ConnectOpts {
+ /**
+ * If specified, incoming data is stored in a single buffer and passed to the supplied callback when data arrives on the socket.
+ * Note: this will cause the streaming functionality to not provide any data, however events like 'error', 'end', and 'close' will
+ * still be emitted as normal and methods like pause() and resume() will also behave as expected.
+ */
+ onread?: OnReadOpts | undefined;
+ }
+ interface TcpSocketConnectOpts extends ConnectOpts {
+ port: number;
+ host?: string | undefined;
+ // localAddress?: string | undefined;
+ // localPort?: number | undefined;
+ // hints?: number | undefined;
+ // family?: number | undefined;
+ // lookup?: LookupFunction | undefined;
+ // noDelay?: boolean | undefined;
+ // keepAlive?: boolean | undefined;
+ // keepAliveInitialDelay?: number | undefined;
+ }
+ // interface IpcSocketConnectOpts extends ConnectOpts {
+ // path: string;
+ // }
+ type SocketConnectOpts = TcpSocketConnectOpts; // | IpcSocketConnectOpts;
+ type SocketReadyState =
+ | "opening"
+ | "open"
+ | "readOnly"
+ | "writeOnly"
+ | "closed";
+ /**
+ * This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
+ * (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
+ * an `EventEmitter`.
+ *
+ * A `net.Socket` can be created by the user and used directly to interact with
+ * a server. For example, it is returned by {@link createConnection},
+ * so the user can use it to talk to the server.
+ *
+ * It can also be created by Node.js and passed to the user when a connection
+ * is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
+ * it to interact with the client.
+ * @since v0.3.4
+ */
+ class Socket extends stream.Duplex {
+ constructor(options?: SocketConstructorOpts);
+ /**
+ * Sends data on the socket. The second parameter specifies the encoding in the
+ * case of a string. It defaults to UTF8 encoding.
+ *
+ * Returns `true` if the entire data was flushed successfully to the kernel
+ * buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is again free.
+ *
+ * The optional `callback` parameter will be executed when the data is finally
+ * written out, which may not be immediately.
+ *
+ * See `Writable` stream `write()` method for more
+ * information.
+ * @since v0.1.90
+ * @param [encoding='utf8'] Only used when data is `string`.
+ */
+ write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
+ write(
+ str: Uint8Array | string,
+ encoding?: BufferEncoding,
+ cb?: (err?: Error) => void,
+ ): boolean;
+ /**
+ * Initiate a connection on a given socket.
+ *
+ * Possible signatures:
+ *
+ * * `socket.connect(options[, connectListener])`
+ * * `socket.connect(path[, connectListener])` for `IPC` connections.
+ * * `socket.connect(port[, host][, connectListener])` for TCP connections.
+ * * Returns: `net.Socket` The socket itself.
+ *
+ * This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
+ * instead of a `'connect'` event, an `'error'` event will be emitted with
+ * the error passed to the `'error'` listener.
+ * The last parameter `connectListener`, if supplied, will be added as a listener
+ * for the `'connect'` event **once**.
+ *
+ * This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
+ * behavior.
+ */
+ connect(options: SocketConnectOpts, connectionListener?: () => void): this;
+ connect(port: number, host: string, connectionListener?: () => void): this;
+ connect(port: number, connectionListener?: () => void): this;
+ connect(path: string, connectionListener?: () => void): this;
+ /**
+ * Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
+ * @since v0.1.90
+ * @return The socket itself.
+ */
+ setEncoding(encoding?: BufferEncoding): this;
+ /**
+ * Pauses the reading of data. That is, `'data'` events will not be emitted.
+ * Useful to throttle back an upload.
+ * @return The socket itself.
+ */
+ pause(): this;
+ /**
+ * Close the TCP connection by sending an RST packet and destroy the stream.
+ * If this TCP socket is in connecting status, it will send an RST packet
+ * and destroy this TCP socket once it is connected. Otherwise, it will call
+ * `socket.destroy` with an `ERR_SOCKET_CLOSED` Error. If this is not a TCP socket
+ * (for example, a pipe), calling this method will immediately throw
+ * an `ERR_INVALID_HANDLE_TYPE` Error.
+ * @since v18.3.0
+ * @return The socket itself.
+ */
+ resetAndDestroy(): this;
+ /**
+ * Resumes reading after a call to `socket.pause()`.
+ * @return The socket itself.
+ */
+ resume(): this;
+ /**
+ * Sets the socket to timeout after `timeout` milliseconds of inactivity on
+ * the socket. By default `net.Socket` do not have a timeout.
+ *
+ * When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed. The user must manually call `socket.end()` or `socket.destroy()` to
+ * end the connection.
+ *
+ * ```js
+ * socket.setTimeout(3000);
+ * socket.on('timeout', () => {
+ * console.log('socket timeout');
+ * socket.end();
+ * });
+ * ```
+ *
+ * If `timeout` is 0, then the existing idle timeout is disabled.
+ *
+ * The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
+ * @since v0.1.90
+ * @return The socket itself.
+ */
+ setTimeout(timeout: number, callback?: () => void): this;
+ /**
+ * Enable/disable the use of Nagle's algorithm.
+ *
+ * When a TCP connection is created, it will have Nagle's algorithm enabled.
+ *
+ * Nagle's algorithm delays data before it is sent via the network. It attempts
+ * to optimize throughput at the expense of latency.
+ *
+ * Passing `true` for `noDelay` or not passing an argument will disable Nagle's
+ * algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
+ * algorithm.
+ * @since v0.1.90
+ * @param [noDelay=true]
+ * @return The socket itself.
+ */
+ setNoDelay(noDelay?: boolean): this;
+ /**
+ * Enable/disable keep-alive functionality, and optionally set the initial
+ * delay before the first keepalive probe is sent on an idle socket.
+ *
+ * Set `initialDelay` (in milliseconds) to set the delay between the last
+ * data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default
+ * (or previous) setting.
+ *
+ * Enabling the keep-alive functionality will set the following socket options:
+ *
+ * * `SO_KEEPALIVE=1`
+ * * `TCP_KEEPIDLE=initialDelay`
+ * * `TCP_KEEPCNT=10`
+ * * `TCP_KEEPINTVL=1`
+ * @since v0.1.92
+ * @param [enable=false]
+ * @param [initialDelay=0]
+ * @return The socket itself.
+ */
+ setKeepAlive(enable?: boolean, initialDelay?: number): this;
+ /**
+ * Returns the bound `address`, the address `family` name and `port` of the
+ * socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
+ * @since v0.1.90
+ */
+ address(): AddressInfo | {};
+ /**
+ * Calling `unref()` on a socket will allow the program to exit if this is the only
+ * active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
+ * @since v0.9.1
+ * @return The socket itself.
+ */
+ unref(): this;
+ /**
+ * Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will _not_ let the program exit if it's the only socket left (the default behavior).
+ * If the socket is `ref`ed calling `ref` again will have no effect.
+ * @since v0.9.1
+ * @return The socket itself.
+ */
+ ref(): this;
+ /**
+ * This property shows the number of characters buffered for writing. The buffer
+ * may contain strings whose length after encoding is not yet known. So this number
+ * is only an approximation of the number of bytes in the buffer.
+ *
+ * `net.Socket` has the property that `socket.write()` always works. This is to
+ * help users get up and running quickly. The computer cannot always keep up
+ * with the amount of data that is written to a socket. The network connection
+ * simply might be too slow. Node.js will internally queue up the data written to a
+ * socket and send it out over the wire when it is possible.
+ *
+ * The consequence of this internal buffering is that memory may grow.
+ * Users who experience large or growing `bufferSize` should attempt to
+ * "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
+ * @since v0.3.8
+ * @deprecated Since v14.6.0 - Use `writableLength` instead.
+ */
+ readonly bufferSize: number;
+ /**
+ * The amount of received bytes.
+ * @since v0.5.3
+ */
+ readonly bytesRead: number;
+ /**
+ * The amount of bytes sent.
+ * @since v0.5.3
+ */
+ readonly bytesWritten: number;
+ /**
+ * If `true`,`socket.connect(options[, connectListener])` was
+ * called and has not yet finished. It will stay `true` until the socket becomes
+ * connected, then it is set to `false` and the `'connect'` event is emitted. Note
+ * that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
+ * @since v6.1.0
+ */
+ readonly connecting: boolean;
+ /**
+ * See `writable.destroyed` for further details.
+ */
+ // readonly destroyed: boolean;
+ /**
+ * The string representation of the local IP address the remote client is
+ * connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
+ * connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
+ * @since v0.9.6
+ */
+ readonly localAddress?: string;
+ /**
+ * The numeric representation of the local port. For example, `80` or `21`.
+ * @since v0.9.6
+ */
+ readonly localPort?: number;
+ /**
+ * The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
+ * @since v18.8.0
+ */
+ readonly localFamily?: string;
+ /**
+ * This property represents the state of the connection as a string.
+ * @see {https://nodejs.org/api/net.html#socketreadystate}
+ * @since v0.5.0
+ */
+ readonly readyState: SocketReadyState;
+ /**
+ * The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
+ * the socket is destroyed (for example, if the client disconnected).
+ * @since v0.5.10
+ */
+ readonly remoteAddress?: string | undefined;
+ /**
+ * The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
+ * @since v0.11.14
+ */
+ readonly remoteFamily?: string | undefined;
+ /**
+ * The numeric representation of the remote port. For example, `80` or `21`.
+ * @since v0.5.10
+ */
+ readonly remotePort?: number | undefined;
+ /**
+ * The socket timeout in milliseconds as set by socket.setTimeout(). It is undefined if a timeout has not been set.
+ * @since v10.7.0
+ */
+ readonly timeout?: number | undefined;
+ /**
+ * Half-closes the socket. i.e., it sends a FIN packet. It is possible the
+ * server will still send some data.
+ *
+ * See `writable.end()` for further details.
+ * @since v0.1.90
+ * @param [encoding='utf8'] Only used when data is `string`.
+ * @param callback Optional callback for when the socket is finished.
+ * @return The socket itself.
+ */
+ end(callback?: () => void): this;
+ end(buffer: Uint8Array | string, callback?: () => void): this;
+ end(
+ str: Uint8Array | string,
+ encoding?: BufferEncoding,
+ callback?: () => void,
+ ): this;
+ /**
+ * events.EventEmitter
+ * 1. close
+ * 2. connect
+ * 3. data
+ * 4. drain
+ * 5. end
+ * 6. error
+ * 7. lookup
+ * 8. ready
+ * 9. timeout
+ */
+ addListener(event: string, listener: (...args: any[]) => void): this;
+ addListener(event: "close", listener: (hadError: boolean) => void): this;
+ addListener(event: "connect", listener: () => void): this;
+ addListener(event: "data", listener: (data: Buffer) => void): this;
+ addListener(event: "drain", listener: () => void): this;
+ addListener(event: "end", listener: () => void): this;
+ addListener(event: "error", listener: (err: Error) => void): this;
+ addListener(
+ event: "lookup",
+ listener: (
+ err: Error,
+ address: string,
+ family: string | number,
+ host: string,
+ ) => void,
+ ): this;
+ addListener(event: "ready", listener: () => void): this;
+ addListener(event: "timeout", listener: () => void): this;
+ emit(event: string | symbol, ...args: any[]): boolean;
+ emit(event: "close", hadError: boolean): boolean;
+ emit(event: "connect"): boolean;
+ emit(event: "data", data: Buffer): boolean;
+ emit(event: "drain"): boolean;
+ emit(event: "end"): boolean;
+ emit(event: "error", err: Error): boolean;
+ emit(
+ event: "lookup",
+ err: Error,
+ address: string,
+ family: string | number,
+ host: string,
+ ): boolean;
+ emit(event: "ready"): boolean;
+ emit(event: "timeout"): boolean;
+ on(event: string, listener: (...args: any[]) => void): this;
+ on(event: "close", listener: (hadError: boolean) => void): this;
+ on(event: "connect", listener: () => void): this;
+ on(event: "data", listener: (data: Buffer) => void): this;
+ on(event: "drain", listener: () => void): this;
+ on(event: "end", listener: () => void): this;
+ on(event: "error", listener: (err: Error) => void): this;
+ on(
+ event: "lookup",
+ listener: (
+ err: Error,
+ address: string,
+ family: string | number,
+ host: string,
+ ) => void,
+ ): this;
+ on(event: "ready", listener: () => void): this;
+ on(event: "timeout", listener: () => void): this;
+ once(event: string, listener: (...args: any[]) => void): this;
+ once(event: "close", listener: (hadError: boolean) => void): this;
+ once(event: "connect", listener: () => void): this;
+ once(event: "data", listener: (data: Buffer) => void): this;
+ once(event: "drain", listener: () => void): this;
+ once(event: "end", listener: () => void): this;
+ once(event: "error", listener: (err: Error) => void): this;
+ once(
+ event: "lookup",
+ listener: (
+ err: Error,
+ address: string,
+ family: string | number,
+ host: string,
+ ) => void,
+ ): this;
+ once(event: "ready", listener: () => void): this;
+ once(event: "timeout", listener: () => void): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
+ prependListener(
+ event: "close",
+ listener: (hadError: boolean) => void,
+ ): this;
+ prependListener(event: "connect", listener: () => void): this;
+ prependListener(event: "data", listener: (data: Buffer) => void): this;
+ prependListener(event: "drain", listener: () => void): this;
+ prependListener(event: "end", listener: () => void): this;
+ prependListener(event: "error", listener: (err: Error) => void): this;
+ prependListener(
+ event: "lookup",
+ listener: (
+ err: Error,
+ address: string,
+ family: string | number,
+ host: string,
+ ) => void,
+ ): this;
+ prependListener(event: "ready", listener: () => void): this;
+ prependListener(event: "timeout", listener: () => void): this;
+ prependOnceListener(
+ event: string,
+ listener: (...args: any[]) => void,
+ ): this;
+ prependOnceListener(
+ event: "close",
+ listener: (hadError: boolean) => void,
+ ): this;
+ prependOnceListener(event: "connect", listener: () => void): this;
+ prependOnceListener(event: "data", listener: (data: Buffer) => void): this;
+ prependOnceListener(event: "drain", listener: () => void): this;
+ prependOnceListener(event: "end", listener: () => void): this;
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
+ prependOnceListener(
+ event: "lookup",
+ listener: (
+ err: Error,
+ address: string,
+ family: string | number,
+ host: string,
+ ) => void,
+ ): this;
+ prependOnceListener(event: "ready", listener: () => void): this;
+ prependOnceListener(event: "timeout", listener: () => void): this;
+ }
+ interface ListenOptions extends Abortable {
+ port?: number | undefined;
+ host?: string | undefined;
+ backlog?: number | undefined;
+ path?: string | undefined;
+ exclusive?: boolean | undefined;
+ readableAll?: boolean | undefined;
+ writableAll?: boolean | undefined;
+ /**
+ * @default false
+ */
+ ipv6Only?: boolean | undefined;
+ }
+ interface ServerOpts {
+ /**
+ * Indicates whether half-opened TCP connections are allowed.
+ * @default false
+ */
+ allowHalfOpen?: boolean | undefined;
+ /**
+ * Indicates whether the socket should be paused on incoming connections.
+ * @default false
+ */
+ pauseOnConnect?: boolean | undefined;
+ /**
+ * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
+ * @default false
+ * @since v16.5.0
+ */
+ noDelay?: boolean | undefined;
+ /**
+ * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
+ * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
+ * @default false
+ * @since v16.5.0
+ */
+ keepAlive?: boolean | undefined;
+ /**
+ * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
+ * @default 0
+ * @since v16.5.0
+ */
+ keepAliveInitialDelay?: number | undefined;
+ }
+ interface DropArgument {
+ localAddress?: string;
+ localPort?: number;
+ localFamily?: string;
+ remoteAddress?: string;
+ remotePort?: number;
+ remoteFamily?: string;
+ }
+ /**
+ * This class is used to create a TCP or `IPC` server.
+ * @since v0.1.90
+ */
+ // class Server extends EventEmitter {
+ // constructor(connectionListener?: (socket: Socket) => void);
+ // constructor(
+ // options?: ServerOpts,
+ // connectionListener?: (socket: Socket) => void,
+ // );
+ // /**
+ // * Start a server listening for connections. A `net.Server` can be a TCP or
+ // * an `IPC` server depending on what it listens to.
+ // *
+ // * Possible signatures:
+ // *
+ // * * `server.listen(handle[, backlog][, callback])`
+ // * * `server.listen(options[, callback])`
+ // * * `server.listen(path[, backlog][, callback])` for `IPC` servers
+ // * * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
+ // *
+ // * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted. The last parameter `callback`will be added as a listener for the `'listening'`
+ // * event.
+ // *
+ // * All `listen()` methods can take a `backlog` parameter to specify the maximum
+ // * length of the queue of pending connections. The actual length will be determined
+ // * by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn`on Linux. The default value of this parameter is 511 (not 512).
+ // *
+ // * All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for
+ // * details).
+ // *
+ // * The `server.listen()` method can be called again if and only if there was an
+ // * error during the first `server.listen()` call or `server.close()` has been
+ // * called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
+ // *
+ // * One of the most common errors raised when listening is `EADDRINUSE`.
+ // * This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
+ // * after a certain amount of time:
+ // *
+ // * ```js
+ // * server.on('error', (e) => {
+ // * if (e.code === 'EADDRINUSE') {
+ // * console.log('Address in use, retrying...');
+ // * setTimeout(() => {
+ // * server.close();
+ // * server.listen(PORT, HOST);
+ // * }, 1000);
+ // * }
+ // * });
+ // * ```
+ // */
+ // listen(
+ // port?: number,
+ // hostname?: string,
+ // backlog?: number,
+ // listeningListener?: () => void,
+ // ): this;
+ // listen(
+ // port?: number,
+ // hostname?: string,
+ // listeningListener?: () => void,
+ // ): this;
+ // listen(
+ // port?: number,
+ // backlog?: number,
+ // listeningListener?: () => void,
+ // ): this;
+ // listen(port?: number, listeningListener?: () => void): this;
+ // listen(
+ // path: string,
+ // backlog?: number,
+ // listeningListener?: () => void,
+ // ): this;
+ // listen(path: string, listeningListener?: () => void): this;
+ // listen(options: ListenOptions, listeningListener?: () => void): this;
+ // listen(handle: any, backlog?: number, listeningListener?: () => void): this;
+ // listen(handle: any, listeningListener?: () => void): this;
+ // /**
+ // * Stops the server from accepting new connections and keeps existing
+ // * connections. This function is asynchronous, the server is finally closed
+ // * when all connections are ended and the server emits a `'close'` event.
+ // * The optional `callback` will be called once the `'close'` event occurs. Unlike
+ // * that event, it will be called with an `Error` as its only argument if the server
+ // * was not open when it was closed.
+ // * @since v0.1.90
+ // * @param callback Called when the server is closed.
+ // */
+ // close(callback?: (err?: Error) => void): this;
+ // /**
+ // * Returns the bound `address`, the address `family` name, and `port` of the server
+ // * as reported by the operating system if listening on an IP socket
+ // * (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
+ // *
+ // * For a server listening on a pipe or Unix domain socket, the name is returned
+ // * as a string.
+ // *
+ // * ```js
+ // * const server = net.createServer((socket) => {
+ // * socket.end('goodbye\n');
+ // * }).on('error', (err) => {
+ // * // Handle errors here.
+ // * throw err;
+ // * });
+ // *
+ // * // Grab an arbitrary unused port.
+ // * server.listen(() => {
+ // * console.log('opened server on', server.address());
+ // * });
+ // * ```
+ // *
+ // * `server.address()` returns `null` before the `'listening'` event has been
+ // * emitted or after calling `server.close()`.
+ // * @since v0.1.90
+ // */
+ // address(): AddressInfo | string | null;
+ // /**
+ // * Asynchronously get the number of concurrent connections on the server. Works
+ // * when sockets were sent to forks.
+ // *
+ // * Callback should take two arguments `err` and `count`.
+ // * @since v0.9.7
+ // */
+ // getConnections(cb: (error: Error | null, count: number) => void): void;
+ // /**
+ // * Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will _not_ let the program exit if it's the only server left (the default behavior).
+ // * If the server is `ref`ed calling `ref()` again will have no effect.
+ // * @since v0.9.1
+ // */
+ // ref(): this;
+ // /**
+ // * Calling `unref()` on a server will allow the program to exit if this is the only
+ // * active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.
+ // * @since v0.9.1
+ // */
+ // unref(): this;
+ // /**
+ // * Set this property to reject connections when the server's connection count gets
+ // * high.
+ // *
+ // * It is not recommended to use this option once a socket has been sent to a child
+ // * with `child_process.fork()`.
+ // * @since v0.2.0
+ // */
+ // maxConnections: number;
+ // connections: number;
+ // /**
+ // * Indicates whether or not the server is listening for connections.
+ // * @since v5.7.0
+ // */
+ // listening: boolean;
+ // /**
+ // * events.EventEmitter
+ // * 1. close
+ // * 2. connection
+ // * 3. error
+ // * 4. listening
+ // * 5. drop
+ // */
+ // addListener(event: string, listener: (...args: any[]) => void): this;
+ // addListener(event: "close", listener: () => void): this;
+ // addListener(event: "connection", listener: (socket: Socket) => void): this;
+ // addListener(event: "error", listener: (err: Error) => void): this;
+ // addListener(event: "listening", listener: () => void): this;
+ // addListener(event: "drop", listener: (data?: DropArgument) => void): this;
+ // emit(event: string | symbol, ...args: any[]): boolean;
+ // emit(event: "close"): boolean;
+ // emit(event: "connection", socket: Socket): boolean;
+ // emit(event: "error", err: Error): boolean;
+ // emit(event: "listening"): boolean;
+ // emit(event: "drop", data?: DropArgument): boolean;
+ // on(event: string, listener: (...args: any[]) => void): this;
+ // on(event: "close", listener: () => void): this;
+ // on(event: "connection", listener: (socket: Socket) => void): this;
+ // on(event: "error", listener: (err: Error) => void): this;
+ // on(event: "listening", listener: () => void): this;
+ // on(event: "drop", listener: (data?: DropArgument) => void): this;
+ // once(event: string, listener: (...args: any[]) => void): this;
+ // once(event: "close", listener: () => void): this;
+ // once(event: "connection", listener: (socket: Socket) => void): this;
+ // once(event: "error", listener: (err: Error) => void): this;
+ // once(event: "listening", listener: () => void): this;
+ // once(event: "drop", listener: (data?: DropArgument) => void): this;
+ // prependListener(event: string, listener: (...args: any[]) => void): this;
+ // prependListener(event: "close", listener: () => void): this;
+ // prependListener(
+ // event: "connection",
+ // listener: (socket: Socket) => void,
+ // ): this;
+ // prependListener(event: "error", listener: (err: Error) => void): this;
+ // prependListener(event: "listening", listener: () => void): this;
+ // prependListener(
+ // event: "drop",
+ // listener: (data?: DropArgument) => void,
+ // ): this;
+ // prependOnceListener(
+ // event: string,
+ // listener: (...args: any[]) => void,
+ // ): this;
+ // prependOnceListener(event: "close", listener: () => void): this;
+ // prependOnceListener(
+ // event: "connection",
+ // listener: (socket: Socket) => void,
+ // ): this;
+ // prependOnceListener(event: "error", listener: (err: Error) => void): this;
+ // prependOnceListener(event: "listening", listener: () => void): this;
+ // prependOnceListener(
+ // event: "drop",
+ // listener: (data?: DropArgument) => void,
+ // ): this;
+ // }
+ type IPVersion = "ipv4" | "ipv6";
+ /**
+ * The `BlockList` object can be used with some network APIs to specify rules for
+ * disabling inbound or outbound access to specific IP addresses, IP ranges, or
+ * IP subnets.
+ * @since v15.0.0, v14.18.0
+ */
+ // class BlockList {
+ // /**
+ // * Adds a rule to block the given IP address.
+ // * @since v15.0.0, v14.18.0
+ // * @param address An IPv4 or IPv6 address.
+ // * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
+ // */
+ // addAddress(address: string, type?: IPVersion): void;
+ // addAddress(address: SocketAddress): void;
+ // /**
+ // * Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).
+ // * @since v15.0.0, v14.18.0
+ // * @param start The starting IPv4 or IPv6 address in the range.
+ // * @param end The ending IPv4 or IPv6 address in the range.
+ // * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
+ // */
+ // addRange(start: string, end: string, type?: IPVersion): void;
+ // addRange(start: SocketAddress, end: SocketAddress): void;
+ // /**
+ // * Adds a rule to block a range of IP addresses specified as a subnet mask.
+ // * @since v15.0.0, v14.18.0
+ // * @param net The network IPv4 or IPv6 address.
+ // * @param prefix The number of CIDR prefix bits. For IPv4, this must be a value between `0` and `32`. For IPv6, this must be between `0` and `128`.
+ // * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
+ // */
+ // addSubnet(net: SocketAddress, prefix: number): void;
+ // addSubnet(net: string, prefix: number, type?: IPVersion): void;
+ // /**
+ // * Returns `true` if the given IP address matches any of the rules added to the`BlockList`.
+ // *
+ // * ```js
+ // * const blockList = new net.BlockList();
+ // * blockList.addAddress('123.123.123.123');
+ // * blockList.addRange('10.0.0.1', '10.0.0.10');
+ // * blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
+ // *
+ // * console.log(blockList.check('123.123.123.123')); // Prints: true
+ // * console.log(blockList.check('10.0.0.3')); // Prints: true
+ // * console.log(blockList.check('222.111.111.222')); // Prints: false
+ // *
+ // * // IPv6 notation for IPv4 addresses works:
+ // * console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
+ // * console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
+ // * ```
+ // * @since v15.0.0, v14.18.0
+ // * @param address The IP address to check
+ // * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
+ // */
+ // check(address: SocketAddress): boolean;
+ // check(address: string, type?: IPVersion): boolean;
+ // }
+ interface TcpNetConnectOpts
+ extends TcpSocketConnectOpts,
+ SocketConstructorOpts {
+ timeout?: number | undefined;
+ }
+ // interface IpcNetConnectOpts
+ // extends IpcSocketConnectOpts,
+ // SocketConstructorOpts {
+ // timeout?: number | undefined;
+ // }
+ type NetConnectOpts = TcpNetConnectOpts; //| IpcNetConnectOpts;
+ /**
+ * Creates a new TCP or `IPC` server.
+ *
+ * If `allowHalfOpen` is set to `true`, when the other end of the socket
+ * signals the end of transmission, the server will only send back the end of
+ * transmission when `socket.end()` is explicitly called. For example, in the
+ * context of TCP, when a FIN packed is received, a FIN packed is sent
+ * back only when `socket.end()` is explicitly called. Until then the
+ * connection is half-closed (non-readable but still writable). See `'end'` event and [RFC 1122](https://tools.ietf.org/html/rfc1122) (section 4.2.2.13) for more information.
+ *
+ * If `pauseOnConnect` is set to `true`, then the socket associated with each
+ * incoming connection will be paused, and no data will be read from its handle.
+ * This allows connections to be passed between processes without any data being
+ * read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
+ *
+ * The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
+ *
+ * Here is an example of a TCP echo server which listens for connections
+ * on port 8124:
+ *
+ * ```js
+ * const net = require('net');
+ * const server = net.createServer((c) => {
+ * // 'connection' listener.
+ * console.log('client connected');
+ * c.on('end', () => {
+ * console.log('client disconnected');
+ * });
+ * c.write('hello\r\n');
+ * c.pipe(c);
+ * });
+ * server.on('error', (err) => {
+ * throw err;
+ * });
+ * server.listen(8124, () => {
+ * console.log('server bound');
+ * });
+ * ```
+ *
+ * Test this by using `telnet`:
+ *
+ * ```console
+ * $ telnet localhost 8124
+ * ```
+ *
+ * To listen on the socket `/tmp/echo.sock`:
+ *
+ * ```js
+ * server.listen('/tmp/echo.sock', () => {
+ * console.log('server bound');
+ * });
+ * ```
+ *
+ * Use `nc` to connect to a Unix domain socket server:
+ *
+ * ```console
+ * $ nc -U /tmp/echo.sock
+ * ```
+ * @since v0.5.0
+ * @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
+ */
+ // function createServer(connectionListener?: (socket: Socket) => void): Server;
+ // function createServer(
+ // options?: ServerOpts,
+ // connectionListener?: (socket: Socket) => void,
+ // ): Server;
+ /**
+ * Aliases to {@link createConnection}.
+ *
+ * Possible signatures:
+ *
+ * * {@link connect}
+ * * {@link connect} for `IPC` connections.
+ * * {@link connect} for TCP connections.
+ */
+ function connect(
+ options: NetConnectOpts,
+ connectionListener?: () => void,
+ ): Socket;
+ function connect(
+ port: number,
+ host?: string,
+ connectionListener?: () => void,
+ ): Socket;
+ function connect(path: string, connectionListener?: () => void): Socket;
+ /**
+ * A factory function, which creates a new {@link Socket},
+ * immediately initiates connection with `socket.connect()`,
+ * then returns the `net.Socket` that starts the connection.
+ *
+ * When the connection is established, a `'connect'` event will be emitted
+ * on the returned socket. The last parameter `connectListener`, if supplied,
+ * will be added as a listener for the `'connect'` event **once**.
+ *
+ * Possible signatures:
+ *
+ * * {@link createConnection}
+ * * {@link createConnection} for `IPC` connections.
+ * * {@link createConnection} for TCP connections.
+ *
+ * The {@link connect} function is an alias to this function.
+ */
+ function createConnection(
+ options: NetConnectOpts,
+ connectionListener?: () => void,
+ ): Socket;
+ function createConnection(
+ port: number,
+ host?: string,
+ connectionListener?: () => void,
+ ): Socket;
+ function createConnection(
+ path: string,
+ connectionListener?: () => void,
+ ): Socket;
+ /**
+ * Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
+ * address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.
+ *
+ * ```js
+ * net.isIP('::1'); // returns 6
+ * net.isIP('127.0.0.1'); // returns 4
+ * net.isIP('127.000.000.001'); // returns 0
+ * net.isIP('127.0.0.1/24'); // returns 0
+ * net.isIP('fhqwhgads'); // returns 0
+ * ```
+ * @since v0.3.0
+ */
+ function isIP(input: string): number;
+ /**
+ * Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no
+ * leading zeroes. Otherwise, returns `false`.
+ *
+ * ```js
+ * net.isIPv4('127.0.0.1'); // returns true
+ * net.isIPv4('127.000.000.001'); // returns false
+ * net.isIPv4('127.0.0.1/24'); // returns false
+ * net.isIPv4('fhqwhgads'); // returns false
+ * ```
+ * @since v0.3.0
+ */
+ function isIPv4(input: string): boolean;
+ /**
+ * Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
+ *
+ * ```js
+ * net.isIPv6('::1'); // returns true
+ * net.isIPv6('fhqwhgads'); // returns false
+ * ```
+ * @since v0.3.0
+ */
+ function isIPv6(input: string): boolean;
+ // interface SocketAddressInitOptions {
+ // /**
+ // * The network address as either an IPv4 or IPv6 string.
+ // * @default 127.0.0.1
+ // */
+ // address?: string | undefined;
+ // /**
+ // * @default `'ipv4'`
+ // */
+ // family?: IPVersion | undefined;
+ // /**
+ // * An IPv6 flow-label used only if `family` is `'ipv6'`.
+ // * @default 0
+ // */
+ // flowlabel?: number | undefined;
+ // /**
+ // * An IP port.
+ // * @default 0
+ // */
+ // port?: number | undefined;
+ // }
+ /**
+ * @since v15.14.0, v14.18.0
+ */
+ // class SocketAddress {
+ // constructor(options: SocketAddressInitOptions);
+ // /**
+ // * @since v15.14.0, v14.18.0
+ // */
+ // readonly address: string;
+ // /**
+ // * Either \`'ipv4'\` or \`'ipv6'\`.
+ // * @since v15.14.0, v14.18.0
+ // */
+ // readonly family: IPVersion;
+ // /**
+ // * @since v15.14.0, v14.18.0
+ // */
+ // readonly port: number;
+ // /**
+ // * @since v15.14.0, v14.18.0
+ // */
+ // readonly flowlabel: number;
+ // }
+}
+declare module "node:net" {
+ export * from "net";
+}
diff --git a/packages/bun-types/package.json b/packages/bun-types/package.json
index b8c8a2e2a..b7eea6ea5 100644
--- a/packages/bun-types/package.json
+++ b/packages/bun-types/package.json
@@ -6,13 +6,11 @@
"scripts": {
"build": "rm -rf ./dist && bun run bundle && bun run fmt",
"bundle": "bun scripts/bundle.ts ./dist",
- "docs": "bun run build && typedoc",
"test": "tsd",
"fmt": "prettier --write './**/*.{ts,tsx,js,jsx}'"
},
"devDependencies": {
"tsd": "^0.22.0",
- "typedoc": "^0.23.9",
"prettier": "^2.4.1"
},
"tsd": {
diff --git a/packages/bun-types/string_decoder.d.ts b/packages/bun-types/string_decoder.d.ts
index aee1680dc..b4d507fac 100644
--- a/packages/bun-types/string_decoder.d.ts
+++ b/packages/bun-types/string_decoder.d.ts
@@ -39,6 +39,7 @@
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/string_decoder.js)
*/
declare module "string_decoder" {
+ import { ArrayBufferView } from "bun";
class StringDecoder {
constructor(encoding?: BufferEncoding);
/**
@@ -47,7 +48,7 @@ declare module "string_decoder" {
* returned string and stored in an internal buffer for the next call to`stringDecoder.write()` or `stringDecoder.end()`.
* @param buffer A `Buffer`, or `TypedArray`, or `DataView` containing the bytes to decode.
*/
- write(buffer: Buffer | ArrayBufferView): string;
+ write(buffer: ArrayBufferView): string;
/**
* Returns any remaining input stored in the internal buffer as a string. Bytes
* representing incomplete UTF-8 and UTF-16 characters will be replaced with
@@ -57,7 +58,7 @@ declare module "string_decoder" {
* After `end()` is called, the `stringDecoder` object can be reused for new input.
* @param buffer A `Buffer`, or `TypedArray`, or `DataView` containing the bytes to decode.
*/
- end(buffer?: Buffer | ArrayBufferView): string;
+ end(buffer?: ArrayBufferView): string;
}
}
declare module "node:string_decoder" {
diff --git a/packages/bun-types/tsconfig.json b/packages/bun-types/tsconfig.json
index 709470196..644fb4587 100644
--- a/packages/bun-types/tsconfig.json
+++ b/packages/bun-types/tsconfig.json
@@ -10,6 +10,7 @@
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"disableSolutionSearching": true,
+ "noUnusedLocals": true
},
"exclude": [
"dist",
diff --git a/packages/bun-types/zlib.d.ts b/packages/bun-types/zlib.d.ts
index 877350b93..ce1e581b0 100644
--- a/packages/bun-types/zlib.d.ts
+++ b/packages/bun-types/zlib.d.ts
@@ -90,6 +90,7 @@
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/zlib.js)
*/
declare module "zlib" {
+ import { ArrayBufferView } from "bun";
import * as stream from "node:stream";
interface ZlibOptions {
/**