import { Tree } from '@nx/devkit'; import { type FormattingOptions, type JSONPath } from 'jsonc-parser'; /** * The wrangler config `$schema`, pointed at a workspace-root-relative path. In a * hoisted monorepo `wrangler` lives in the root `node_modules`, not the project's, * so an `offsetFromRoot`-relative path is what lets editors validate the config. */ export declare function wranglerSchemaPath(projectRoot: string): string; export declare const WRANGLER_CONFIG_FILES: readonly ["wrangler.jsonc", "wrangler.json", "wrangler.toml"]; export declare const JSONC_CONFIG_EXTENSIONS: string[]; export declare const FORMATTING: FormattingOptions; export declare function findWranglerConfig(tree: Tree, projectRoot: string): string | null; export declare function isJsoncConfig(configPath: string): boolean; export declare function assertJsoncConfig(configPath: string, caller?: string): void; /** * Read a wrangler config's raw text from the real filesystem, for the two * callers that operate outside the generator Tree (the inference plugin, and * post-flush provisioning). Throws the underlying fs error on a missing file — * callers decide how to handle that (the inference plugin warns and skips a * config; provisioning lets a missing config surface as a hard failure). */ export declare function readWranglerConfigTextFromFile(absConfigPath: string): string; /** * Best-effort parse: salvages a partial result even from a malformed config * (jsonc-parser's default, error-tolerant behavior). Used wherever the config * is assumed already valid — the generators and provisioning only ever edit a * config that a prior generator run (or the user) already wrote. */ export declare function parseWranglerConfig(text: string): Record; /** * Strict parse: throws a descriptive error when the text contains any parse * errors, instead of silently salvaging a partial result. Used by the * inference plugin's validity gate, which must distinguish a genuinely broken * config (skip inference, warn) from a merely unusual one. * * Most wrangler configs are plain JSON, so try the native parser first (as * @nx/devkit's own `parseJson` does) and only fall back to jsonc-parser for * comments/trailing commas or a real syntax error. */ export declare function parseWranglerConfigStrict(text: string): Record; export declare function readWranglerConfig(tree: Tree, configPath: string): Record; /** * Whether the array at `arrayPath` — top-level (`['kv_namespaces']`) or nested * (`['durable_objects', 'bindings']`) — has an entry whose `field` === `value`. */ export declare function findInArray(config: Record, arrayPath: JSONPath, field: string, value: string): boolean; /** * Index of the entry in the array at `arrayPath` whose `field` === `value`, or * -1 if the array is absent or no entry matches. */ export declare function findIndexInArray(config: Record, arrayPath: JSONPath, field: string, value: string): number; /** * Append `entry` to the array at `arrayPath` — top-level or nested (e.g. * `['queues', 'producers']`). `modify` creates any missing intermediate * objects/arrays, so this also handles "first binding of this kind" without a * separate branch. */ export declare function appendToArray(tree: Tree, configPath: string, arrayPath: JSONPath, entry: Record): void; export declare function getMigrationCount(config: Record): number; export declare function migrationDefinesClass(config: Record, className: string): boolean; export interface D1DatabaseBinding { binding: string; database_name: string; } /** * Extract `d1_databases` entries that carry a non-empty `binding` and * `database_name`. A malformed entry is dropped rather than thrown on; * `onInvalidEntry` lets the caller warn with its own context (e.g. the config * file path) instead of baking one message into this accessor. */ export declare function getD1Databases(config: Record, onInvalidEntry?: (entry: unknown) => void): D1DatabaseBinding[]; export interface ProductionToggles { observability?: boolean; smartPlacement?: boolean; } export declare function applyProductionToggles(tree: Tree, configPath: string, toggles: ProductionToggles): void; export declare function applyProductionTogglesToProject(tree: Tree, projectRoot: string, toggles: ProductionToggles, caller: string): boolean;