import {
  a as createFileSystemSnapshot,
  i as InMemoryFileSystem,
  n as DurableObjectRawFileSystem,
  r as FileSystem,
  t as DurableObjectKVFileSystem
} from "./file-system-PsI0bi2L.js";

//#region src/types.d.ts
/**
 * Input files for the bundler
 * Keys are file paths, values are file contents
 */
type Files = Record<string, string>;
/**
 * Module format for Worker Loader binding
 */
interface Module {
  js?: string;
  cjs?: string;
  text?: string;
  data?: ArrayBuffer;
  json?: object;
}
/**
 * Output modules for Worker Loader binding
 */
type Modules = Record<string, string | Module>;
/**
 * Loader names supported for the `loader` option.
 *
 * Deliberately narrowed to the portable subset that every bundler in the
 * ecosystem (esbuild, rolldown, rspack, vite, webpack) can express:
 *
 *   - script flavours: `js`, `jsx`, `ts`, `tsx`, `json`, `css`
 *   - file content embedding: `text`, `binary`, `base64`, `dataurl`
 *
 * esbuild's `file` and `copy` loaders are intentionally NOT exposed: they
 * emit secondary output files that the bundler currently discards (only the
 * first output file is read). esbuild's `default` / `empty` / `local-css` /
 * `global-css` are also omitted because they are esbuild-internal control
 * flow, not portable concepts.
 *
 * Anything outside this set should go through
 * `__dangerouslyUseEsBuildPluginsDoNotUseOrYouWillBeFired` instead.
 */
type BundlerLoader =
  | "js"
  | "jsx"
  | "ts"
  | "tsx"
  | "json"
  | "css"
  | "text"
  | "binary"
  | "base64"
  | "dataurl";
/**
 * JSX transform mode passed to esbuild.
 */
type JsxMode = "transform" | "preserve" | "automatic";
/**
 * Options for createWorker
 */
interface CreateWorkerOptions {
  /**
   * Input files - keys are paths relative to project root, values are file contents
   */
  files: Files | FileSystem;
  /**
   * Entry point file path (relative to project root)
   * If not specified, will try to determine from wrangler.toml main field,
   * then package.json, then default paths (src/index.ts, etc.)
   */
  entryPoint?: string;
  /**
   * Whether to bundle all dependencies into a single file
   * @default true
   */
  bundle?: boolean;
  /**
   * External modules that should not be bundled.
   * Note: `cloudflare:*` modules are always treated as external.
   */
  externals?: string[];
  /**
   * Target environment
   * @default 'es2022'
   */
  target?: string;
  /**
   * Whether to minify the output
   * @default false
   */
  minify?: boolean;
  /**
   * Generate inline source maps for better debugging and error stack traces.
   * Only applies when `bundle: true`. Has no effect in transform-only mode
   * since the output closely mirrors the input structure.
   * @default false
   */
  sourcemap?: boolean;
  /**
   * npm registry URL for fetching packages.
   * @default 'https://registry.npmjs.org'
   */
  registry?: string;
  /**
   * JSX transform mode passed to esbuild.
   * `"automatic"` enables the new JSX runtime (no need to import React).
   *
   * Only applies when `bundle: true` (the default). In transform-only mode this
   * option is ignored and a warning is added to the result's `warnings` array.
   */
  jsx?: JsxMode;
  /**
   * Module to import the JSX runtime from when `jsx: "automatic"`.
   * @example "react", "preact", "@emotion/react"
   *
   * Only applies when `bundle: true`.
   */
  jsxImportSource?: string;
  /**
   * Constant replacements applied at bundle time. Each key is replaced with the
   * corresponding value (which must be a JSON-serialisable JavaScript expression).
   * @example { "process.env.NODE_ENV": '"production"', "__DEV__": "false" }
   *
   * Only applies when `bundle: true`. In transform-only mode this option is
   * ignored and a warning is added to the result's `warnings` array.
   */
  define?: Record<string, string>;
  /**
   * Per-extension loader overrides. Extensions are matched on file paths
   * (including the leading dot, e.g. `".svg"`). Built-in handling for
   * `.ts`/`.tsx`/`.js`/`.jsx`/`.json`/`.css` is preserved unless overridden here.
   *
   * Only applies when `bundle: true`.
   */
  loader?: Record<string, BundlerLoader>;
  /**
   * Package export conditions to honour during resolution
   * (e.g. `["workerd", "worker", "browser"]`).
   * Order matters — earlier conditions take precedence.
   *
   * Only applies when `bundle: true`.
   */
  conditions?: string[];
  /**
   * Exact virtual module aliases available during bundling. Each key is an
   * import specifier (for example `"node:fs"` or `"virtual:app/config"`) and
   * each value is JavaScript module source loaded by the bundler.
   *
   * Only applies when `bundle: true`. In transform-only mode this option is
   * ignored and a warning is added to the result's `warnings` array.
   */
  virtualModules?: Record<string, string>;
  /**
   * Escape hatch for advanced users: extra esbuild plugins to run **before**
   * the bundler's internal virtual-filesystem plugin.
   *
   * The deliberately unwieldy name is the API contract:
   *
   *   - This option is **not** covered by semver. It can change shape, be
   *     renamed, or be removed in any release.
   *   - The runtime ties you to esbuild. If this package switches bundlers
   *     (e.g. to rolldown), plugins authored against this API will break.
   *
   * Typed as `unknown[]` at the public boundary to keep `esbuild-wasm` types
   * out of the published `.d.ts`. Cast your plugin array to `unknown[]` when
   * passing it in. Each element is validated at runtime: it must be an object
   * with `name: string` and `setup: (build) => void`.
   *
   * Only applies when `bundle: true`. In transform-only mode this option is
   * ignored and a warning is added to the result's `warnings` array.
   */
  __dangerouslyUseEsBuildPluginsDoNotUseOrYouWillBeFired?: unknown[];
}
/**
 * Parsed wrangler configuration relevant to Worker Loader
 */
interface WranglerConfig {
  main?: string;
  compatibilityDate?: string;
  compatibilityFlags?: string[];
}
/**
 * Result from createWorker
 */
interface CreateWorkerResult {
  /**
   * The main module entry point path
   */
  mainModule: string;
  /**
   * All modules in the bundle
   */
  modules: Modules;
  /**
   * Parsed wrangler configuration (from wrangler.toml/json/jsonc).
   */
  wranglerConfig?: WranglerConfig;
  /**
   * Any warnings generated during bundling
   */
  warnings?: string[];
}
//#endregion
//#region src/asset-handler.d.ts
/**
 * Asset request handler for serving static assets.
 *
 * Key design: the manifest (routing metadata) is separated from the
 * storage (content retrieval). This lets you plug in any backend —
 * in-memory, KV, R2, Workspace, etc.
 *
 * Inspired by Cloudflare's Workers Static Assets behavior and
 * cloudflare-asset-worker by Timo Wilhelm.
 */
/**
 * Pluggable storage backend for asset content.
 * Implement this to serve assets from KV, R2, Workspace, or any other source.
 */
interface AssetStorage {
  get(pathname: string): Promise<ReadableStream | ArrayBuffer | string | null>;
}
/**
 * Metadata for a single asset (no content — that comes from storage).
 */
interface AssetMetadata {
  contentType: string | undefined;
  etag: string;
}
/**
 * The manifest maps pathnames to metadata. Used for routing decisions,
 * ETag checks, and content-type headers — all without touching storage.
 */
type AssetManifest = Map<string, AssetMetadata>;
/**
 * Create an in-memory storage backend from a pathname->content map.
 * This is the zero-config default for small asset sets.
 */
declare function createMemoryStorage(
  assets: Record<string, string | ArrayBuffer>
): AssetStorage;
/**
 * Configuration for asset serving behavior.
 */
interface AssetConfig {
  /**
   * How to handle HTML file resolution and trailing slashes.
   * @default 'auto-trailing-slash'
   */
  html_handling?:
    | "auto-trailing-slash"
    | "force-trailing-slash"
    | "drop-trailing-slash"
    | "none";
  /**
   * How to handle requests that don't match any asset.
   * - 'single-page-application': Serve /index.html for 404s
   * - '404-page': Serve nearest 404.html walking up the directory tree
   * - 'none': Return null (fall through)
   * @default 'none'
   */
  not_found_handling?: "single-page-application" | "404-page" | "none";
  /**
   * Static redirect rules. Keys are URL pathnames (or https://host/path for cross-host).
   * Supports * glob and :placeholder tokens.
   */
  redirects?: {
    static?: Record<
      string,
      {
        status: number;
        to: string;
      }
    >;
    dynamic?: Record<
      string,
      {
        status: number;
        to: string;
      }
    >;
  };
  /**
   * Custom response headers per pathname pattern (glob syntax).
   */
  headers?: Record<
    string,
    {
      set?: Record<string, string>;
      unset?: string[];
    }
  >;
}
/**
 * Build an AssetManifest from a pathname->content mapping.
 * Only computes metadata (content types, ETags) — doesn't store content.
 */
declare function buildAssetManifest(
  assets: Record<string, string | ArrayBuffer>
): Promise<AssetManifest>;
/**
 * Convenience: build both a manifest and an in-memory storage from assets.
 */
declare function buildAssets(
  assets: Record<string, string | ArrayBuffer>
): Promise<{
  manifest: AssetManifest;
  storage: AssetStorage;
}>;
/**
 * Handle an asset request. Returns a Response if an asset matches,
 * or null if the request should fall through to the user's Worker.
 *
 * @param request - The incoming HTTP request
 * @param manifest - Asset manifest (pathname -> metadata)
 * @param storage - Storage backend for fetching content
 * @param config - Asset serving configuration
 */
declare function handleAssetRequest(
  request: Request,
  manifest: AssetManifest,
  storage: AssetStorage,
  config?: AssetConfig
): Promise<Response | null>;
//#endregion
//#region src/app.d.ts
/**
 * Options for createApp
 */
interface CreateAppOptions {
  /**
   * Input files — keys are paths relative to project root, values are file contents.
   * Accepts a plain object (which is wrapped in an InMemoryFileSystem automatically)
   * or any FileSystem implementation for custom storage backends.
   */
  files: Files | FileSystem;
  /**
   * Server entry point (the Worker fetch handler).
   * If not specified, detected from wrangler config / package.json / defaults.
   */
  server?: string;
  /**
   * Client entry point(s) to bundle for the browser.
   * These are bundled with esbuild targeting the browser.
   */
  client?: string | string[];
  /**
   * Static assets to serve as-is (pathname -> content).
   * Keys should be URL pathnames (e.g., "/favicon.ico", "/robots.txt").
   * These are NOT processed by the bundler.
   */
  assets?: Record<string, string | ArrayBuffer>;
  /**
   * Asset serving configuration.
   */
  assetConfig?: AssetConfig;
  /**
   * Whether to bundle server dependencies.
   * @default true
   */
  bundle?: boolean;
  /**
   * External modules that should not be bundled.
   */
  externals?: string[];
  /**
   * Target environment for server bundle.
   * @default 'es2022'
   */
  target?: string;
  /**
   * Whether to minify the output.
   * @default false
   */
  minify?: boolean;
  /**
   * Generate source maps.
   * @default false
   */
  sourcemap?: boolean;
  /**
   * npm registry URL for fetching packages.
   */
  registry?: string;
  /**
   * JSX transform mode passed to esbuild. Applied to both server and client
   * bundles.
   */
  jsx?: JsxMode;
  /**
   * Module to import the JSX runtime from when `jsx: "automatic"`.
   */
  jsxImportSource?: string;
  /**
   * Constant replacements applied at bundle time. Applied to both server and
   * client bundles.
   */
  define?: Record<string, string>;
  /**
   * Per-extension loader overrides. Applied to both server and client bundles.
   */
  loader?: Record<string, BundlerLoader>;
  /**
   * Package export conditions to honour during resolution.
   * Applied to both server and client bundles (the host can pass e.g.
   * `["worker", "browser"]` for the client, but most users want a single
   * shared set).
   */
  conditions?: string[];
  /**
   * Escape hatch for advanced users: extra esbuild plugins to run **before**
   * the bundler's internal virtual-filesystem plugin. Applied to both server
   * and client bundles.
   *
   * The deliberately unwieldy name is the API contract:
   *
   *   - This option is **not** covered by semver. It can change shape, be
   *     renamed, or be removed in any release.
   *   - The runtime ties you to esbuild. If this package switches bundlers
   *     (e.g. to rolldown), plugins authored against this API will break.
   *
   * Typed as `unknown[]` at the public boundary to keep `esbuild-wasm` types
   * out of the published `.d.ts`. Cast your plugin array to `unknown[]` when
   * passing it in. Each element is validated at runtime: it must be an object
   * with `name: string` and `setup: (build) => void`.
   *
   * On the server side, only applies when `bundle: true`; transform-only mode
   * surfaces a warning instead. Always applies to client bundles.
   */
  __dangerouslyUseEsBuildPluginsDoNotUseOrYouWillBeFired?: unknown[];
}
/**
 * Result from createApp
 */
interface CreateAppResult extends CreateWorkerResult {
  /**
   * Combined assets (user-provided + client bundles) for host-side serving.
   * The host should use createMemoryStorage(assets) and handleAssetRequest()
   * to serve these before forwarding requests to the isolate.
   */
  assets: Record<string, string | ArrayBuffer>;
  /**
   * The asset manifest for runtime request handling.
   * Contains metadata (content types, ETags) for each asset.
   */
  assetManifest: AssetManifest;
  /**
   * The asset config for runtime request handling.
   */
  assetConfig?: AssetConfig;
  /**
   * Client bundle output paths (relative to asset root).
   */
  clientBundles?: string[];
}
/**
 * Creates a full-stack app bundle from source files.
 *
 * This function:
 * 1. Bundles client entry point(s) for the browser (if provided)
 * 2. Collects static assets and builds the asset manifest
 * 3. Bundles the server Worker
 * 4. Returns server modules (for the isolate) and assets (for host-side serving) separately
 *
 * How the output is mounted (module worker, DO class, facet) is the caller's concern.
 */
declare function createApp(options: CreateAppOptions): Promise<CreateAppResult>;
//#endregion
//#region src/mime.d.ts
/**
 * MIME type inference from file extensions.
 */
/**
 * Infer MIME type from a file path.
 * Returns undefined if the type is unknown.
 */
declare function inferContentType(path: string): string | undefined;
/**
 * Whether a content type represents a text-based format
 * (used to decide text vs binary module storage).
 */
declare function isTextContentType(contentType: string): boolean;
//#endregion
//#region src/installer.d.ts
interface InstallOptions {
  /**
   * Include devDependencies (default: false)
   */
  dev?: boolean;
  /**
   * Registry URL (default: https://registry.npmjs.org)
   */
  registry?: string;
}
interface InstallResult {
  /**
   * Packages that were freshly installed in this call.
   * Packages already present in the filesystem are skipped and not listed here.
   */
  installed: string[];
  /**
   * Warnings encountered during installation
   */
  warnings: string[];
}
/**
 * Install npm dependencies into a virtual file system.
 *
 * Reads the package.json from the files, resolves all dependencies,
 * and populates node_modules with the package contents.
 *
 * @param fileSystem - Virtual file system containing package.json
 * @param options - Installation options
 * @returns Metadata about the installation
 */
declare function installDependencies(
  fileSystem: FileSystem,
  options?: InstallOptions
): Promise<InstallResult>;
/**
 * Check if files contain a package.json with dependencies that need installing.
 */
declare function hasDependencies(files: FileSystem): boolean;
//#endregion
//#region src/index.d.ts
/**
 * Creates a worker bundle from source files.
 *
 * This function performs:
 * 1. Entry point detection (from package.json or defaults)
 * 2. Auto-installation of npm dependencies (if package.json has dependencies)
 * 3. TypeScript/JSX transformation (via Sucrase)
 * 4. Module resolution (handling imports/exports)
 * 5. Optional bundling (combining all modules into one)
 *
 * @param options - Configuration options
 * @returns The main module path and all modules
 */
declare function createWorker(
  options: CreateWorkerOptions
): Promise<CreateWorkerResult>;
//#endregion
export {
  type AssetConfig,
  type AssetManifest,
  type AssetMetadata,
  type AssetStorage,
  type BundlerLoader,
  type CreateAppOptions,
  type CreateAppResult,
  type CreateWorkerOptions,
  type CreateWorkerResult,
  DurableObjectKVFileSystem,
  DurableObjectRawFileSystem,
  type FileSystem,
  type Files,
  InMemoryFileSystem,
  type InstallResult,
  type JsxMode,
  type Modules,
  type WranglerConfig,
  buildAssetManifest,
  buildAssets,
  createApp,
  createFileSystemSnapshot,
  createMemoryStorage,
  createWorker,
  handleAssetRequest,
  hasDependencies,
  inferContentType,
  installDependencies,
  isTextContentType
};
//# sourceMappingURL=index.d.ts.map
