/// <reference types="node" />

import { Blob as Blob_2 } from 'buffer';
import { ConnectionOptions } from 'tls';
import { Duplex } from 'stream';
import { EventEmitter } from 'events';
import { IpcNetConnectOpts } from 'net';
import type { Json } from 'miniflare';
import { Readable } from 'stream';
import { ReadableStream as ReadableStream_2 } from 'stream/web';
import { Socket as Socket_2 } from 'net';
import { TcpNetConnectOpts } from 'net';
import { TlsOptions as TlsOptions_2 } from 'tls';
import { TLSSocket } from 'tls';
import { URL as URL_2 } from 'url';
import { URLSearchParams as URLSearchParams_2 } from 'url';
import { Writable } from 'stream';

declare type AbortSignal_2 = unknown;

declare interface BlobPropertyBag {
    type?: string
    endings?: 'native' | 'transparent'
}

declare type BodyInit_2 =
| ArrayBuffer
| AsyncIterable<Uint8Array>
| Blob_2
| FormData_2
| Iterable<Uint8Array>
| NodeJS.ArrayBufferView
| URLSearchParams_2
| null
| string

declare interface BodyMixin {
    readonly body: ReadableStream_2 | null
    readonly bodyUsed: boolean

    readonly arrayBuffer: () => Promise<ArrayBuffer>
    readonly blob: () => Promise<Blob_2>
    readonly formData: () => Promise<FormData_2>
    readonly json: () => Promise<unknown>
    readonly text: () => Promise<string>
}

declare class BodyReadable extends Readable {
    constructor(
    resume?: (this: Readable, size: number) => void | null,
    abort?: () => void | null,
    contentType?: string
    )

    /** Consumes and returns the body as a string
     *  https://fetch.spec.whatwg.org/#dom-body-text
     */
    text(): Promise<string>

    /** Consumes and returns the body as a JavaScript Object
     *  https://fetch.spec.whatwg.org/#dom-body-json
     */
    json(): Promise<any>

    /** Consumes and returns the body as a Blob
     *  https://fetch.spec.whatwg.org/#dom-body-blob
     */
    blob(): Promise<Blob_2>

    /** Consumes and returns the body as an ArrayBuffer
     *  https://fetch.spec.whatwg.org/#dom-body-arraybuffer
     */
    arrayBuffer(): Promise<ArrayBuffer>

    /** Not implemented
     *
     *  https://fetch.spec.whatwg.org/#dom-body-formdata
     */
    formData(): Promise<never>

    /** Returns true if the body is not null and the body has been consumed
     *
     *  Otherwise, returns false
     *
     * https://fetch.spec.whatwg.org/#dom-body-bodyused
     */
    readonly bodyUsed: boolean

    /** Throws on node 16.6.0
     *
     *  If body is null, it should return null as the body
     *
     *  If body is not null, should return the body as a ReadableStream
     *
     *  https://fetch.spec.whatwg.org/#dom-body-body
     */
    readonly body: never | undefined

    /** Dumps the response body by reading `limit` number of bytes.
     * @param opts.limit Number of bytes to read (optional) - Default: 262144
     */
    dump(opts?: { limit: number }): Promise<void>
}

declare function buildConnector (options?: buildConnector.BuildOptions): buildConnector.connector

declare namespace buildConnector {
    type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts) & {
        maxCachedSessions?: number | null;
        socketPath?: string | null;
        timeout?: number | null;
        port?: number;
        keepAlive?: boolean | null;
        keepAliveInitialDelay?: number | null;
    }

    interface Options {
        hostname: string
        host?: string
        protocol: string
        port: string
        servername?: string
        localAddress?: string | null
        httpSocket?: Socket_2
    }

    type Callback = (...args: CallbackArgs) => void
    type CallbackArgs = [null, Socket_2 | TLSSocket] | [Error, null]

    type connector = connectorAsync | connectorSync

    interface connectorSync {
        (options: buildConnector.Options): Socket_2 | TLSSocket
    }

    interface connectorAsync {
        (options: buildConnector.Options, callback: buildConnector.Callback): void
    }
}

/**
 * An imported module.
 */
declare interface CfModule {
    /**
     * The module name.
     *
     * @example
     * './src/index.js'
     */
    name: string;
    /**
     * The absolute path of the module on disk, or `undefined` if this is a
     * virtual module. Used as the source URL for this module, so source maps are
     * correctly resolved.
     *
     * @example
     * '/path/to/src/index.js'
     */
    filePath: string | undefined;
    /**
     * The module content, usually JavaScript or WASM code.
     *
     * @example
     * export default {
     *   async fetch(request) {
     *     return new Response('Ok')
     *   }
     * }
     */
    content: string | Buffer;
    /**
     * The module type.
     *
     * If absent, will default to the main module's type.
     */
    type?: CfModuleType;
}

/**
 * A module type.
 */
declare type CfModuleType = "esm" | "commonjs" | "compiled-wasm" | "text" | "buffer";

/** A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default. */
declare class Client extends Dispatcher {
    constructor(url: string | URL_2, options?: Client.Options);
    /** Property to get and set the pipelining factor. */
    pipelining: number;
    /** `true` after `client.close()` has been called. */
    closed: boolean;
    /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
    destroyed: boolean;
}

declare namespace Client {
    interface Options {
        /** the timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. Default: `4e3` milliseconds (4s). */
        keepAliveTimeout?: number | null;
        /** the maximum allowed `idleTimeout` when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
        keepAliveMaxTimeout?: number | null;
        /** A number subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */
        keepAliveTimeoutThreshold?: number | null;
        /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */
        pipelining?: number | null;
        /** **/
        connect?: buildConnector.BuildOptions | buildConnector.connector | null;
        /** The maximum length of request headers in bytes. Default: `16384` (16KiB). */
        maxHeaderSize?: number | null;
        /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */
        bodyTimeout?: number | null;
        /** The amount of time the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
        headersTimeout?: number | null;
        /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
        strictContentLength?: boolean;
        /** @deprecated use the connect option instead */
        tls?: TlsOptions_2 | null;
        /** */
        maxRequestsPerClient?: number;
        /** Max response body size in bytes, -1 is disabled */
        maxResponseSize?: number | null;
        /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
        autoSelectFamily?: boolean;
        /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
        autoSelectFamilyAttemptTimeout?: number;

        interceptors?: {Client: readonly Dispatcher[] | undefined}
    }

    interface SocketInfo {
        localAddress?: string
        localPort?: number
        remoteAddress?: string
        remotePort?: number
        remoteFamily?: string
        timeout?: number
        bytesWritten?: number
        bytesRead?: number
    }


}

/**
 * The possible types for a `Rule`.
 */
declare type ConfigModuleRuleType = "ESModule" | "CommonJS" | "CompiledWasm" | "Text" | "Data";

declare type CustomDomainRoute = {
    pattern: string;
    custom_domain: boolean;
};

/**
 * Publish a directory to an account/project.
 * NOTE: You will need the `CLOUDFLARE_API_KEY` environment
 * variable set
 */
declare function deploy({ directory, accountId, projectName, branch, skipCaching, commitMessage, commitHash, commitDirty, functionsDirectory: customFunctionsDirectory, bundle, }: PagesDeployOptions): Promise<{
    url: string;
    environment: "production" | "preview";
    id: string;
    project_id: string;
    project_name: string;
    build_config: {
        build_command: string;
        destination_dir: string;
        root_dir: string;
        web_analytics_tag?: string | undefined;
        web_analytics_token?: string | undefined;
        fast_builds?: boolean | undefined;
    };
    created_on: string;
    production_branch: string;
    deployment_trigger: {
        type: string;
        metadata: {
            branch: string;
            commit_hash: string;
            commit_message: string;
        };
    };
    latest_stage: {
        name: "build" | "deploy" | "queued" | "initialize" | "clone_repo";
        status: "active" | "idle" | "canceled" | "success" | "failure" | "skipped";
        started_on: string | null;
        ended_on: string | null;
    };
    stages: {
        name: "build" | "deploy" | "queued" | "initialize" | "clone_repo";
        status: "active" | "idle" | "canceled" | "success" | "failure" | "skipped";
        started_on: string | null;
        ended_on: string | null;
    }[];
    aliases: string[];
    modified_on: string;
    short_id: string;
    build_image_major_version: number;
    kv_namespaces?: any;
    source?: {
        type: "github" | "gitlab";
        config: {
            owner: string;
            repo_name: string;
            production_branch?: string | undefined;
            pr_comments_enabled?: boolean | undefined;
            deployments_enabled?: boolean | undefined;
            production_deployments_enabled?: boolean | undefined;
            preview_deployment_setting?: "none" | "all" | "custom" | undefined;
            preview_branch_includes?: string[] | undefined;
            preview_branch_excludes?: string[] | undefined;
        };
    } | undefined;
    env_vars?: any;
    durable_object_namespaces?: any;
    is_skipped?: boolean | undefined;
    files?: {
        [x: string]: string | undefined;
    } | undefined;
}>;

/**
 * Deprecated upload configuration.
 */
declare interface DeprecatedUpload {
    /**
     * The format of the Worker script.
     *
     * @deprecated We infer the format automatically now.
     */
    format?: "modules" | "service-worker";
    /**
     * The directory you wish to upload your worker from,
     * relative to the wrangler.toml file.
     *
     * Defaults to the directory containing the wrangler.toml file.
     *
     * @deprecated
     */
    dir?: string;
    /**
     * The path to the Worker script, relative to `upload.dir`.
     *
     * @deprecated This will be replaced by a command line argument.
     */
    main?: string;
    /**
     * @deprecated This is now defined at the top level `rules` field.
     */
    rules?: Environment["rules"];
}

/** Dispatcher is the core API used to dispatch requests. */
declare class Dispatcher extends EventEmitter {
    /** Dispatches a request. This API is expected to evolve through semver-major versions and is less stable than the preceding higher level APIs. It is primarily intended for library developers who implement higher level APIs on top of this. */
    dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean;
    /** Starts two-way communications with the requested resource. */
    connect(options: Dispatcher.ConnectOptions): Promise<Dispatcher.ConnectData>;
    connect(options: Dispatcher.ConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void;
    /** Performs an HTTP request. */
    request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>;
    request(options: Dispatcher.RequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
    /** For easy use with `stream.pipeline`. */
    pipeline(options: Dispatcher.PipelineOptions, handler: Dispatcher.PipelineHandler): Duplex;
    /** A faster version of `Dispatcher.request`. */
    stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory): Promise<Dispatcher.StreamData>;
    stream(options: Dispatcher.RequestOptions, factory: Dispatcher.StreamFactory, callback: (err: Error | null, data: Dispatcher.StreamData) => void): void;
    /** Upgrade to a different protocol. */
    upgrade(options: Dispatcher.UpgradeOptions): Promise<Dispatcher.UpgradeData>;
    upgrade(options: Dispatcher.UpgradeOptions, callback: (err: Error | null, data: Dispatcher.UpgradeData) => void): void;
    /** Closes the client and gracefully waits for enqueued requests to complete before invoking the callback (or returning a promise if no callback is provided). */
    close(): Promise<void>;
    close(callback: () => void): void;
    /** Destroy the client abruptly with the given err. All the pending and running requests will be asynchronously aborted and error. Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided). Since this operation is asynchronously dispatched there might still be some progress on dispatched requests. */
    destroy(): Promise<void>;
    destroy(err: Error | null): Promise<void>;
    destroy(callback: () => void): void;
    destroy(err: Error | null, callback: () => void): void;

    on(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    on(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    on(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    on(eventName: 'drain', callback: (origin: URL_2) => void): this;


    once(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    once(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    once(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    once(eventName: 'drain', callback: (origin: URL_2) => void): this;


    off(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    off(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    off(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    off(eventName: 'drain', callback: (origin: URL_2) => void): this;


    addListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    addListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    addListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    addListener(eventName: 'drain', callback: (origin: URL_2) => void): this;

    removeListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    removeListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    removeListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    removeListener(eventName: 'drain', callback: (origin: URL_2) => void): this;

    prependListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    prependListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    prependListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    prependListener(eventName: 'drain', callback: (origin: URL_2) => void): this;

    prependOnceListener(eventName: 'connect', callback: (origin: URL_2, targets: readonly Dispatcher[]) => void): this;
    prependOnceListener(eventName: 'disconnect', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    prependOnceListener(eventName: 'connectionError', callback: (origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
    prependOnceListener(eventName: 'drain', callback: (origin: URL_2) => void): this;

    listeners(eventName: 'connect'): ((origin: URL_2, targets: readonly Dispatcher[]) => void)[]
    listeners(eventName: 'disconnect'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
    listeners(eventName: 'connectionError'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
    listeners(eventName: 'drain'): ((origin: URL_2) => void)[];

    rawListeners(eventName: 'connect'): ((origin: URL_2, targets: readonly Dispatcher[]) => void)[]
    rawListeners(eventName: 'disconnect'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
    rawListeners(eventName: 'connectionError'): ((origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
    rawListeners(eventName: 'drain'): ((origin: URL_2) => void)[];

    emit(eventName: 'connect', origin: URL_2, targets: readonly Dispatcher[]): boolean;
    emit(eventName: 'disconnect', origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
    emit(eventName: 'connectionError', origin: URL_2, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
    emit(eventName: 'drain', origin: URL_2): boolean;
}

declare namespace Dispatcher {
    interface DispatchOptions {
        origin?: string | URL_2;
        path: string;
        method: HttpMethod;
        /** Default: `null` */
        body?: string | Buffer | Uint8Array | Readable | null | FormData_2;
        /** Default: `null` */
        headers?: IncomingHttpHeaders | string[] | null;
        /** Query string params to be embedded in the request URL. Default: `null` */
        query?: Record<string, any>;
        /** Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline have completed. Default: `true` if `method` is `HEAD` or `GET`. */
        idempotent?: boolean;
        /** Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received. */
        blocking?: boolean;
        /** Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`. Default: `method === 'CONNECT' || null`. */
        upgrade?: boolean | string | null;
        /** The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 300 seconds. */
        headersTimeout?: number | null;
        /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use 0 to disable it entirely. Defaults to 300 seconds. */
        bodyTimeout?: number | null;
        /** Whether the request should stablish a keep-alive or not. Default `false` */
        reset?: boolean;
        /** Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server. Defaults to false */
        throwOnError?: boolean;
    }
    interface ConnectOptions {
        path: string;
        /** Default: `null` */
        headers?: IncomingHttpHeaders | string[] | null;
        /** Default: `null` */
        signal?: AbortSignal_2 | EventEmitter | null;
        /** This argument parameter is passed through to `ConnectData` */
        opaque?: unknown;
        /** Default: 0 */
        maxRedirections?: number;
        /** Default: `null` */
        responseHeader?: 'raw' | null;
    }
    interface RequestOptions extends DispatchOptions {
        /** Default: `null` */
        opaque?: unknown;
        /** Default: `null` */
        signal?: AbortSignal_2 | EventEmitter | null;
        /** Default: 0 */
        maxRedirections?: number;
        /** Default: `null` */
        onInfo?: (info: { statusCode: number, headers: Record<string, string | string[]> }) => void;
        /** Default: `null` */
        responseHeader?: 'raw' | null;
    }
    interface PipelineOptions extends RequestOptions {
        /** `true` if the `handler` will return an object stream. Default: `false` */
        objectMode?: boolean;
    }
    interface UpgradeOptions {
        path: string;
        /** Default: `'GET'` */
        method?: string;
        /** Default: `null` */
        headers?: IncomingHttpHeaders | string[] | null;
        /** A string of comma separated protocols, in descending preference order. Default: `'Websocket'` */
        protocol?: string;
        /** Default: `null` */
        signal?: AbortSignal_2 | EventEmitter | null;
        /** Default: 0 */
        maxRedirections?: number;
        /** Default: `null` */
        responseHeader?: 'raw' | null;
    }
    interface ConnectData {
        statusCode: number;
        headers: IncomingHttpHeaders;
        socket: Duplex;
        opaque: unknown;
    }
    interface ResponseData {
        statusCode: number;
        headers: IncomingHttpHeaders;
        body: BodyReadable & BodyMixin;
        trailers: Record<string, string>;
        opaque: unknown;
        context: object;
    }
    interface PipelineHandlerData {
        statusCode: number;
        headers: IncomingHttpHeaders;
        opaque: unknown;
        body: BodyReadable;
        context: object;
    }
    interface StreamData {
        opaque: unknown;
        trailers: Record<string, string>;
    }
    interface UpgradeData {
        headers: IncomingHttpHeaders;
        socket: Duplex;
        opaque: unknown;
    }
    interface StreamFactoryData {
        statusCode: number;
        headers: IncomingHttpHeaders;
        opaque: unknown;
        context: object;
    }
    type StreamFactory = (data: StreamFactoryData) => Writable;
    interface DispatchHandlers {
        /** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
        onConnect?(abort: () => void): void;
        /** Invoked when an error has occurred. */
        onError?(err: Error): void;
        /** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */
        onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void;
        /** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */
        onHeaders?(statusCode: number, headers: Buffer[] | string[] | null, resume: () => void): boolean;
        /** Invoked when response payload data is received. */
        onData?(chunk: Buffer): boolean;
        /** Invoked when response payload and trailers have been received and the request has completed. */
        onComplete?(trailers: string[] | null): void;
        /** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */
        onBodySent?(chunkSize: number, totalBytesSent: number): void;
    }
    type PipelineHandler = (data: PipelineHandlerData) => Readable;
    type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';

    /**
     * @link https://fetch.spec.whatwg.org/#body-mixin
     */
    interface BodyMixin {
        readonly body?: never; // throws on node v16.6.0
        readonly bodyUsed: boolean;
        arrayBuffer(): Promise<ArrayBuffer>;
        blob(): Promise<Blob_2>;
        formData(): Promise<never>;
        json(): Promise<any>;
        text(): Promise<string>;
    }

    interface DispatchInterceptor {
        (dispatch: Dispatcher['dispatch']): Dispatcher['dispatch']
    }
}

declare interface DispatchNamespaceOutbound {
    /** Name of the service handling the outbound requests */
    service: string;
    /** (Optional) Name of the environment handling the outbound requests. */
    environment?: string;
    /** (Optional) List of parameter names, for sending context from your dispatch worker to the outbound handler */
    parameters?: string[];
}

declare type DurableObjectBindings = {
    /** The name of the binding used to refer to the Durable Object */
    name: string;
    /** The exported class name of the Durable Object */
    class_name: string;
    /** The script where the Durable Object is defined (if it's external to this worker) */
    script_name?: string;
    /** The service environment of the script_name to bind to */
    environment?: string;
}[];

declare interface EnablePagesAssetsServiceBindingOptions {
    proxyPort?: number;
    directory?: string;
}

/**
 * The `Environment` interface declares all the configuration fields that
 * can be specified for an environment.
 *
 * This could be the top-level default environment, or a specific named environment.
 */
declare interface Environment extends EnvironmentInheritable, EnvironmentNonInheritable {
}

/**
 * The `EnvironmentInheritable` interface declares all the configuration fields for an environment
 * that can be inherited (and overridden) from the top-level environment.
 */
declare interface EnvironmentInheritable {
    /**
     * The name of your worker. Alphanumeric + dashes only.
     *
     * @inheritable
     */
    name: string | undefined;
    /**
     * This is the ID of the account associated with your zone.
     * You might have more than one account, so make sure to use
     * the ID of the account associated with the zone/route you
     * provide, if you provide one. It can also be specified through
     * the CLOUDFLARE_ACCOUNT_ID environment variable.
     *
     * @inheritable
     */
    account_id: string | undefined;
    /**
     * A date in the form yyyy-mm-dd, which will be used to determine
     * which version of the Workers runtime is used.
     *
     * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
     *
     * @inheritable
     */
    compatibility_date: string | undefined;
    /**
     * A list of flags that enable features from upcoming features of
     * the Workers runtime, usually used together with compatibility_flags.
     *
     * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
     *
     * @inheritable
     */
    compatibility_flags: string[];
    /**
     * The entrypoint/path to the JavaScript file that will be executed.
     */
    main: string | undefined;
    /**
     * If true then Wrangler will traverse the file tree below `base_dir`;
     * Any files that match `rules` will be included in the deployed worker.
     * Defaults to true if `no_bundle` is true, otherwise false.
     *
     * @inheritable
     */
    find_additional_modules: boolean | undefined;
    /**
     * The directory in which module rules should be evaluated when including additional files into a worker deployment.
     * This defaults to the directory containing the `main` entry point of the worker if not specified.
     *
     * @inheritable
     */
    base_dir: string | undefined;
    /**
     * Whether we use <name>.<subdomain>.workers.dev to
     * test and deploy your worker.
     *
     * @default `true` (This is a breaking change from Wrangler v1)
     * @breaking
     * @inheritable
     */
    workers_dev: boolean | undefined;
    /**
     * A list of routes that your worker should be published to.
     * Only one of `routes` or `route` is required.
     *
     * Only required when workers_dev is false, and there's no scheduled worker (see `triggers`)
     *
     * @inheritable
     */
    routes: Route[] | undefined;
    /**
     * A route that your worker should be published to. Literally
     * the same as routes, but only one.
     * Only one of `routes` or `route` is required.
     *
     * Only required when workers_dev is false, and there's no scheduled worker
     *
     * @inheritable
     */
    route: Route | undefined;
    /**
     * Path to a custom tsconfig
     */
    tsconfig: string | undefined;
    /**
     * The function to use to replace jsx syntax.
     *
     * @default `"React.createElement"`
     * @inheritable
     */
    jsx_factory: string;
    /**
     * The function to use to replace jsx fragment syntax.
     *
     * @default `"React.Fragment"`
     * @inheritable
     */
    jsx_fragment: string;
    /**
     * "Cron" definitions to trigger a worker's "scheduled" function.
     *
     * Lets you call workers periodically, much like a cron job.
     *
     * More details here https://developers.cloudflare.com/workers/platform/cron-triggers
     *
     * @default `{crons:[]}`
     * @inheritable
     */
    triggers: {
        crons: string[];
    };
    /**
     * Specifies the Usage Model for your Worker. There are two options -
     * [bundled](https://developers.cloudflare.com/workers/platform/limits#bundled-usage-model) and
     * [unbound](https://developers.cloudflare.com/workers/platform/limits#unbound-usage-model).
     * For newly created Workers, if the Usage Model is omitted
     * it will be set to the [default Usage Model set on the account](https://dash.cloudflare.com/?account=workers/default-usage-model).
     * For existing Workers, if the Usage Model is omitted, it will be
     * set to the Usage Model configured in the dashboard for that Worker.
     *
     * @inheritable
     */
    usage_model: "bundled" | "unbound" | undefined;
    /**
     * Specify limits for runtime behavior.
     * Only supported for the "standard" Usage Model
     *
     * @inheritable
     */
    limits: UserLimits | undefined;
    /**
     * An ordered list of rules that define which modules to import,
     * and what type to import them as. You will need to specify rules
     * to use Text, Data, and CompiledWasm modules, or when you wish to
     * have a .js file be treated as an ESModule instead of CommonJS.
     *
     * @inheritable
     */
    rules: Rule[];
    /**
     * Configures a custom build step to be run by Wrangler when building your Worker.
     *
     * Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
     * for more details.
     *
     * @default {}
     */
    build: {
        /** The command used to build your Worker. On Linux and macOS, the command is executed in the `sh` shell and the `cmd` shell for Windows. The `&&` and `||` shell operators may be used. */
        command?: string;
        /** The directory in which the command is executed. */
        cwd?: string;
        /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
        watch_dir?: string | string[];
        /**
         * Deprecated field previously used to configure the build and upload of the script.
         * @deprecated
         */
        upload?: DeprecatedUpload;
    };
    /**
     * Skip internal build steps and directly deploy script
     * @inheritable
     */
    no_bundle: boolean | undefined;
    /**
     * Minify the script before uploading.
     * @inheritable
     */
    minify: boolean | undefined;
    /**
     * Add polyfills for node builtin modules and globals
     * @inheritable
     */
    node_compat: boolean | undefined;
    /**
     * Specifies namespace bindings that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    dispatch_namespaces: {
        /** The binding name used to refer to the bound service. */
        binding: string;
        /** The namespace to bind to. */
        namespace: string;
        /** Details about the outbound worker which will handle outbound requests from your namespace */
        outbound?: DispatchNamespaceOutbound;
    }[];
    /**
     *	Designates this worker as an internal-only "first-party" worker.
     */
    first_party_worker: boolean | undefined;
    /**
     * TODO: remove this as it has been deprecated.
     *
     * This is just here for now because the `route` commands use it.
     * So we need to include it in this type so it is available.
     */
    zone_id?: string;
    /**
     * List of bindings that you will send to logfwdr
     *
     * @default `{bindings:[]}`
     * @inheritable
     */
    logfwdr: {
        bindings: {
            /** The binding name used to refer to logfwdr */
            name: string;
            /** The destination for this logged message */
            destination: string;
        }[];
    };
    /**
     * Send Trace Events from this worker to Workers Logpush.
     *
     * This will not configure a corresponding Logpush job automatically.
     *
     * For more information about Workers Logpush, see:
     * https://blog.cloudflare.com/logpush-for-workers/
     *
     * @inheritable
     */
    logpush: boolean | undefined;
    /**
     * Specify how the worker should be located to minimize round-trip time.
     *
     * More details: https://developers.cloudflare.com/workers/platform/smart-placement/
     */
    placement: {
        mode: "off" | "smart";
    } | undefined;
}

/**
 * The `EnvironmentNonInheritable` interface declares all the configuration fields for an environment
 * that cannot be inherited from the top-level environment, and must be defined specifically.
 *
 * If any of these fields are defined at the top-level then they should also be specifically defined
 * for each named environment.
 */
declare interface EnvironmentNonInheritable {
    /**
     * A map of values to substitute when deploying your worker.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `{}`
     * @nonInheritable
     */
    define: Record<string, string>;
    /**
     * A map of environment variables to set when deploying your worker.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `{}`
     * @nonInheritable
     */
    vars: Record<string, string | Json>;
    /**
     * A list of durable objects that your worker should be bound to.
     *
     * For more information about Durable Objects, see the documentation at
     * https://developers.cloudflare.com/workers/learning/using-durable-objects
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `{bindings:[]}`
     * @nonInheritable
     */
    durable_objects: {
        bindings: DurableObjectBindings;
    };
    /**
     * These specify any Workers KV Namespaces you want to
     * access from inside your Worker.
     *
     * To learn more about KV Namespaces,
     * see the documentation at https://developers.cloudflare.com/workers/learning/how-kv-works
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    kv_namespaces: {
        /** The binding name used to refer to the KV Namespace */
        binding: string;
        /** The ID of the KV namespace */
        id: string;
        /** The ID of the KV namespace used during `wrangler dev` */
        preview_id?: string;
    }[];
    /**
     * These specify bindings to send email from inside your Worker.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    send_email: {
        /** The binding name used to refer to the this binding */
        name: string;
        /** If this binding should be restricted to a specific verified address */
        destination_address?: string;
        /** If this binding should be restricted to a set of verified addresses */
        allowed_destination_addresses?: string[];
    }[];
    /**
     * Specifies Queues that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `{}`
     * @nonInheritable
     */
    queues: {
        /** Producer bindings */
        producers?: {
            /** The binding name used to refer to the Queue in the worker. */
            binding: string;
            /** The name of this Queue. */
            queue: string;
        }[];
        /** Consumer configuration */
        consumers?: {
            /** The name of the queue from which this script should consume. */
            queue: string;
            /** The maximum number of messages per batch */
            max_batch_size?: number;
            /** The maximum number of seconds to wait to fill a batch with messages. */
            max_batch_timeout?: number;
            /** The maximum number of retries for each message. */
            max_retries?: number;
            /** The queue to send messages that failed to be consumed. */
            dead_letter_queue?: string;
            /** The maximum number of concurrent consumer Worker invocations. Leaving this unset will allow your consumer to scale to the maximum concurrency needed to keep up with the message backlog. */
            max_concurrency?: number | null;
        }[];
    };
    /**
     * Specifies R2 buckets that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    r2_buckets: {
        /** The binding name used to refer to the R2 bucket in the worker. */
        binding: string;
        /** The name of this R2 bucket at the edge. */
        bucket_name: string;
        /** The preview name of this R2 bucket at the edge. */
        preview_bucket_name?: string;
        /** The jurisdiction that the bucket exists in. Default if not present. */
        jurisdiction?: string;
    }[];
    /**
     * Specifies D1 databases that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    d1_databases: {
        /** The binding name used to refer to the D1 database in the worker. */
        binding: string;
        /** The name of this D1 database. */
        database_name: string;
        /** The UUID of this D1 database (not required). */
        database_id: string;
        /** The UUID of this D1 database for Wrangler Dev (if specified). */
        preview_database_id?: string;
        /** The name of the migrations table for this D1 database (defaults to 'd1_migrations'). */
        migrations_table?: string;
        /** The path to the directory of migrations for this D1 database (defaults to './migrations'). */
        migrations_dir?: string;
        /** Internal use only. */
        database_internal_env?: string;
    }[];
    /**
     * Specifies Vectorize indexes that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    vectorize: {
        /** The binding name used to refer to the Vectorize index in the worker. */
        binding: string;
        /** The name of the index. */
        index_name: string;
    }[];
    /**
     * Specifies Constellation projects that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    constellation: {
        /** The binding name used to refer to the project in the worker. */
        binding: string;
        /** The id of the project. */
        project_id: string;
    }[];
    /**
     * Specifies Hyperdrive configs that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    hyperdrive: {
        /** The binding name used to refer to the project in the worker. */
        binding: string;
        /** The id of the database. */
        id: string;
    }[];
    /**
     * Specifies service bindings (worker-to-worker) that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    services: {
        /** The binding name used to refer to the bound service. */
        binding: string;
        /** The name of the service. */
        service: string;
        /** The environment of the service (e.g. production, staging, etc). */
        environment?: string;
    }[] | undefined;
    /**
     * Specifies analytics engine datasets that are bound to this Worker environment.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @default `[]`
     * @nonInheritable
     */
    analytics_engine_datasets: {
        /** The binding name used to refer to the dataset in the worker. */
        binding: string;
        /** The name of this dataset to write to. */
        dataset?: string;
    }[];
    /**
     * A browser that will be usable from the worker.
     */
    browser: {
        binding: string;
    } | undefined;
    /**
     * Binding to the AI project.
     */
    ai: {
        binding: string;
    } | undefined;
    /**
     * "Unsafe" tables for features that aren't directly supported by wrangler.
     *
     * NOTE: This field is not automatically inherited from the top level environment,
     * and so must be specified in every named environment.
     *
     * @nonInheritable
     */
    unsafe: {
        /**
         * A set of bindings that should be put into a Worker's upload metadata without changes. These
         * can be used to implement bindings for features that haven't released and aren't supported
         * directly by wrangler or miniflare.
         */
        bindings?: {
            name: string;
            type: string;
            [key: string]: unknown;
        }[];
        /**
         * Arbitrary key/value pairs that will be included in the uploaded metadata.  Values specified
         * here will always be applied to metadata last, so can add new or override existing fields.
         */
        metadata?: {
            [key: string]: string;
        };
        /**
         * Used for internal capnp uploads for the Workers runtime
         */
        capnp?: {
            base_path: string;
            source_schemas: string[];
            compiled_schema?: never;
        } | {
            base_path?: never;
            source_schemas?: never;
            compiled_schema: string;
        };
    };
    mtls_certificates: {
        /** The binding name used to refer to the certificate in the worker */
        binding: string;
        /** The uuid of the uploaded mTLS certificate */
        certificate_id: string;
    }[];
    tail_consumers?: TailConsumer[];
}

declare namespace Errors {
    class UndiciError extends Error { }

    /** Connect timeout error. */
    class ConnectTimeoutError extends UndiciError {
        name: 'ConnectTimeoutError';
        code: 'UND_ERR_CONNECT_TIMEOUT';
    }

    /** A header exceeds the `headersTimeout` option. */
    class HeadersTimeoutError extends UndiciError {
        name: 'HeadersTimeoutError';
        code: 'UND_ERR_HEADERS_TIMEOUT';
    }

    /** Headers overflow error. */
    class HeadersOverflowError extends UndiciError {
        name: 'HeadersOverflowError'
        code: 'UND_ERR_HEADERS_OVERFLOW'
    }

    /** A body exceeds the `bodyTimeout` option. */
    class BodyTimeoutError extends UndiciError {
        name: 'BodyTimeoutError';
        code: 'UND_ERR_BODY_TIMEOUT';
    }

    class ResponseStatusCodeError extends UndiciError {
        name: 'ResponseStatusCodeError';
        code: 'UND_ERR_RESPONSE_STATUS_CODE';
        body: null | Record<string, any> | string
        status: number
        statusCode: number
        headers: IncomingHttpHeaders | string[] | null;
    }

    /** Passed an invalid argument. */
    class InvalidArgumentError extends UndiciError {
        name: 'InvalidArgumentError';
        code: 'UND_ERR_INVALID_ARG';
    }

    /** Returned an invalid value. */
    class InvalidReturnValueError extends UndiciError {
        name: 'InvalidReturnValueError';
        code: 'UND_ERR_INVALID_RETURN_VALUE';
    }

    /** The request has been aborted by the user. */
    class RequestAbortedError extends UndiciError {
        name: 'AbortError';
        code: 'UND_ERR_ABORTED';
    }

    /** Expected error with reason. */
    class InformationalError extends UndiciError {
        name: 'InformationalError';
        code: 'UND_ERR_INFO';
    }

    /** Request body length does not match content-length header. */
    class RequestContentLengthMismatchError extends UndiciError {
        name: 'RequestContentLengthMismatchError';
        code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH';
    }

    /** Response body length does not match content-length header. */
    class ResponseContentLengthMismatchError extends UndiciError {
        name: 'ResponseContentLengthMismatchError';
        code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH';
    }

    /** Trying to use a destroyed client. */
    class ClientDestroyedError extends UndiciError {
        name: 'ClientDestroyedError';
        code: 'UND_ERR_DESTROYED';
    }

    /** Trying to use a closed client. */
    class ClientClosedError extends UndiciError {
        name: 'ClientClosedError';
        code: 'UND_ERR_CLOSED';
    }

    /** There is an error with the socket. */
    class SocketError extends UndiciError {
        name: 'SocketError';
        code: 'UND_ERR_SOCKET';
        socket: Client.SocketInfo | null
    }

    /** Encountered unsupported functionality. */
    class NotSupportedError extends UndiciError {
        name: 'NotSupportedError';
        code: 'UND_ERR_NOT_SUPPORTED';
    }

    /** No upstream has been added to the BalancedPool. */
    class BalancedPoolMissingUpstreamError extends UndiciError {
        name: 'MissingUpstreamError';
        code: 'UND_ERR_BPL_MISSING_UPSTREAM';
    }

    class HTTPParserError extends UndiciError {
        name: 'HTTPParserError';
        code: string;
    }

    /** The response exceed the length allowed. */
    class ResponseExceededMaxSizeError extends UndiciError {
        name: 'ResponseExceededMaxSizeError';
        code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';
    }
}

declare class File_2 extends Blob_2 {
    /**
     * Creates a new File instance.
     *
     * @param fileBits An `Array` strings, or [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), [`ArrayBufferView`](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects, or a mix of any of such objects, that will be put inside the [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
     * @param fileName The name of the file.
     * @param options An options object containing optional attributes for the file.
     */
    constructor(fileBits: ReadonlyArray<string | NodeJS.ArrayBufferView | Blob_2>, fileName: string, options?: FilePropertyBag)

    /**
     * Name of the file referenced by the File object.
     */
    readonly name: string

    /**
     * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
     */
    readonly lastModified: number

    readonly [Symbol.toStringTag]: string
}

declare interface FilePropertyBag extends BlobPropertyBag {
    /**
     * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
     */
    lastModified?: number
}

/**
 * Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using fetch().
 */
declare class FormData_2 {
    /**
     * Appends a new value onto an existing key inside a FormData object,
     * or adds the key if it does not already exist.
     *
     * The difference between `set()` and `append()` is that if the specified key already exists, `set()` will overwrite all existing values with the new one, whereas `append()` will append the new value onto the end of the existing set of values.
     *
     * @param name The name of the field whose data is contained in `value`.
     * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
     or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
     * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
     */
    append(name: string, value: unknown, fileName?: string): void

    /**
     * Set a new value for an existing key inside FormData,
     * or add the new field if it does not already exist.
     *
     * @param name The name of the field whose data is contained in `value`.
     * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
     or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
     * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
     *
     */
    set(name: string, value: unknown, fileName?: string): void

    /**
     * Returns the first value associated with a given key from within a `FormData` object.
     * If you expect multiple values and want all of them, use the `getAll()` method instead.
     *
     * @param {string} name A name of the value you want to retrieve.
     *
     * @returns A `FormDataEntryValue` containing the value. If the key doesn't exist, the method returns null.
     */
    get(name: string): FormDataEntryValue | null

    /**
     * Returns all the values associated with a given key from within a `FormData` object.
     *
     * @param {string} name A name of the value you want to retrieve.
     *
     * @returns An array of `FormDataEntryValue` whose key matches the value passed in the `name` parameter. If the key doesn't exist, the method returns an empty list.
     */
    getAll(name: string): FormDataEntryValue[]

    /**
     * Returns a boolean stating whether a `FormData` object contains a certain key.
     *
     * @param name A string representing the name of the key you want to test for.
     *
     * @return A boolean value.
     */
    has(name: string): boolean

    /**
     * Deletes a key and its value(s) from a `FormData` object.
     *
     * @param name The name of the key you want to delete.
     */
    delete(name: string): void

    /**
     * Executes given callback function for each field of the FormData instance
     */
    forEach: (
    callbackfn: (value: FormDataEntryValue, key: string, iterable: FormData_2) => void,
    thisArg?: unknown
    ) => void

    /**
     * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all keys contained in this `FormData` object.
     * Each key is a `string`.
     */
    keys: () => SpecIterableIterator<string>

    /**
     * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all values contained in this object `FormData` object.
     * Each value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
     */
    values: () => SpecIterableIterator<FormDataEntryValue>

    /**
     * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through the `FormData` key/value pairs.
     * The key of each pair is a string; the value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
     */
    entries: () => SpecIterableIterator<[string, FormDataEntryValue]>

    /**
     * An alias for FormData#entries()
     */
    [Symbol.iterator]: () => SpecIterableIterator<[string, FormDataEntryValue]>

    readonly [Symbol.toStringTag]: string
}

/**
 * A `string` or `File` that represents a single value from a set of `FormData` key-value pairs.
 */
declare type FormDataEntryValue = string | File_2

declare class Headers_2 implements SpecIterable<[string, string]> {
    constructor (init?: HeadersInit_2)
    readonly append: (name: string, value: string) => void
    readonly delete: (name: string) => void
    readonly get: (name: string) => string | null
    readonly has: (name: string) => boolean
    readonly set: (name: string, value: string) => void
    readonly getSetCookie: () => string[]
    readonly forEach: (
    callbackfn: (value: string, key: string, iterable: Headers_2) => void,
    thisArg?: unknown
    ) => void

    readonly keys: () => SpecIterableIterator<string>
    readonly values: () => SpecIterableIterator<string>
    readonly entries: () => SpecIterableIterator<[string, string]>
    readonly [Symbol.iterator]: () => SpecIterator<[string, string]>
}

declare type HeadersInit_2 = string[][] | Record<string, string | ReadonlyArray<string>> | Headers_2

/**
 * The header type declaration of `undici`.
 */
declare type IncomingHttpHeaders = Record<string, string | string[] | undefined>;

declare interface PagesDeployOptions {
    /**
     * Path to static assets to deploy to Pages
     */
    directory: string;
    /**
     * The Cloudflare Account ID that owns the project that's
     * being published
     */
    accountId: string;
    /**
     * The name of the project to be published
     */
    projectName: string;
    /**
     * Branch name to use. Defaults to production branch
     */
    branch?: string;
    /**
     * Whether or not to skip local file upload result caching
     */
    skipCaching?: boolean;
    /**
     * Commit message associated to deployment
     */
    commitMessage?: string;
    /**
     * Commit hash associated to deployment
     */
    commitHash?: string;
    /**
     * Whether or not the deployment should be considered to be
     * in a dirty commit state
     */
    commitDirty?: boolean;
    /**
     * Path to the project's functions directory. Default uses
     * the current working directory + /functions since this is
     * typically called in a CLI
     */
    functionsDirectory?: string;
    /**
     * Whether to run bundling on `_worker.js` before deploying.
     * Default: true
     */
    bundle?: boolean;
}

declare type ReferrerPolicy =
| ''
| 'no-referrer'
| 'no-referrer-when-downgrade'
| 'origin'
| 'origin-when-cross-origin'
| 'same-origin'
| 'strict-origin'
| 'strict-origin-when-cross-origin'
| 'unsafe-url';

declare class Request_2 implements BodyMixin {
    constructor (input: RequestInfo_2, init?: RequestInit_2)

    readonly cache: RequestCache
    readonly credentials: RequestCredentials
    readonly destination: RequestDestination
    readonly headers: Headers_2
    readonly integrity: string
    readonly method: string
    readonly mode: RequestMode
    readonly redirect: RequestRedirect
    readonly referrerPolicy: string
    readonly url: string

    readonly keepalive: boolean
    readonly signal: AbortSignal
    readonly duplex: RequestDuplex

    readonly body: ReadableStream_2 | null
    readonly bodyUsed: boolean

    readonly arrayBuffer: () => Promise<ArrayBuffer>
    readonly blob: () => Promise<Blob_2>
    readonly formData: () => Promise<FormData_2>
    readonly json: () => Promise<unknown>
    readonly text: () => Promise<string>

    readonly clone: () => Request_2
}

declare type RequestCache =
| 'default'
| 'force-cache'
| 'no-cache'
| 'no-store'
| 'only-if-cached'
| 'reload'

declare type RequestCredentials = 'omit' | 'include' | 'same-origin'

declare type RequestDestination =
| ''
| 'audio'
| 'audioworklet'
| 'document'
| 'embed'
| 'font'
| 'image'
| 'manifest'
| 'object'
| 'paintworklet'
| 'report'
| 'script'
| 'sharedworker'
| 'style'
| 'track'
| 'video'
| 'worker'
| 'xslt'

declare type RequestDuplex = 'half'

declare type RequestInfo_2 = string | URL_2 | Request_2

declare interface RequestInit_2 {
    method?: string
    keepalive?: boolean
    headers?: HeadersInit_2
    body?: BodyInit_2
    redirect?: RequestRedirect
    integrity?: string
    signal?: AbortSignal
    credentials?: RequestCredentials
    mode?: RequestMode
    referrer?: string
    referrerPolicy?: ReferrerPolicy
    window?: null
    dispatcher?: Dispatcher
    duplex?: RequestDuplex
}

declare type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin'

declare type RequestRedirect = 'error' | 'follow' | 'manual'

declare class Response_2 implements BodyMixin {
    constructor (body?: BodyInit_2, init?: ResponseInit_2)

    readonly headers: Headers_2
    readonly ok: boolean
    readonly status: number
    readonly statusText: string
    readonly type: ResponseType
    readonly url: string
    readonly redirected: boolean

    readonly body: ReadableStream_2 | null
    readonly bodyUsed: boolean

    readonly arrayBuffer: () => Promise<ArrayBuffer>
    readonly blob: () => Promise<Blob_2>
    readonly formData: () => Promise<FormData_2>
    readonly json: () => Promise<unknown>
    readonly text: () => Promise<string>

    readonly clone: () => Response_2

    static error (): Response_2
    static json(data: any, init?: ResponseInit_2): Response_2
    static redirect (url: string | URL_2, status: ResponseRedirectStatus): Response_2
}

declare interface ResponseInit_2 {
    readonly status?: number
    readonly statusText?: string
    readonly headers?: HeadersInit_2
}

declare type ResponseRedirectStatus = 301 | 302 | 303 | 307 | 308

declare type ResponseType =
| 'basic'
| 'cors'
| 'default'
| 'error'
| 'opaque'
| 'opaqueredirect'

declare type Route = SimpleRoute | ZoneIdRoute | ZoneNameRoute | CustomDomainRoute;

/**
 * A bundling resolver rule, defining the modules type for paths that match the specified globs.
 */
declare type Rule = {
    type: ConfigModuleRuleType;
    globs: string[];
    fallthrough?: boolean;
};

declare type SimpleRoute = string;

declare interface SpecIterable<T> {
    [Symbol.iterator](): SpecIterator<T>;
}

declare interface SpecIterableIterator<T> extends SpecIterator<T> {
    [Symbol.iterator](): SpecIterableIterator<T>;
}

declare interface SpecIterator<T, TReturn = any, TNext = undefined> {
    next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
}

declare type TailConsumer = {
    /** The name of the service tail events will be forwarded to. */
    service: string;
    /** (Optional) The environment of the service. */
    environment?: string;
    /** (Optional) The dispatch namespace the Tail Worker script belongs to (if any). */
    namespace?: string;
};

/**
 *  unstable_dev starts a wrangler dev server, and returns a promise that resolves with utility functions to interact with it.
 */
export declare function unstable_dev(script: string, options?: UnstableDevOptions, apiOptions?: unknown): Promise<UnstableDevWorker>;

export declare const unstable_pages: {
    deploy: typeof deploy;
};

export declare interface UnstableDevOptions {
    config?: string;
    env?: string;
    ip?: string;
    port?: number;
    bundle?: boolean;
    inspectorPort?: number;
    localProtocol?: "http" | "https";
    assets?: string;
    site?: string;
    siteInclude?: string[];
    siteExclude?: string[];
    nodeCompat?: boolean;
    compatibilityDate?: string;
    compatibilityFlags?: string[];
    persist?: boolean;
    persistTo?: string;
    vars?: Record<string, string | Json>;
    kv?: {
        binding: string;
        id: string;
        preview_id?: string;
    }[];
    durableObjects?: {
        name: string;
        class_name: string;
        script_name?: string | undefined;
        environment?: string | undefined;
    }[];
    services?: {
        binding: string;
        service: string;
        environment?: string | undefined;
    }[];
    r2?: {
        binding: string;
        bucket_name: string;
        preview_bucket_name?: string;
    }[];
    moduleRoot?: string;
    rules?: Rule[];
    logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
    inspect?: boolean;
    local?: boolean;
    accountId?: string;
    experimental?: {
        processEntrypoint?: boolean;
        additionalModules?: CfModule[];
        d1Databases?: Environment["d1_databases"];
        disableExperimentalWarning?: boolean;
        disableDevRegistry?: boolean;
        enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
        forceLocal?: boolean;
        liveReload?: boolean;
        showInteractiveDevSession?: boolean;
        testMode?: boolean;
        testScheduled?: boolean;
        watch?: boolean;
    };
}

export declare interface UnstableDevWorker {
    port: number;
    address: string;
    stop: () => Promise<void>;
    fetch: (input?: RequestInfo_2, init?: RequestInit_2) => Promise<Response_2>;
    waitUntilExit: () => Promise<void>;
}

declare interface UserLimits {
    /** Maximum allowed CPU time for a worker's invocation in milliseconds */
    cpu_ms: number;
}

declare type ZoneIdRoute = {
    pattern: string;
    zone_id: string;
    custom_domain?: boolean;
};

declare type ZoneNameRoute = {
    pattern: string;
    zone_name: string;
    custom_domain?: boolean;
};

export { }
