import * as SmolToml from "smol-toml"; import type { ConfigFormat } from "./config-format.ts"; /** * Format-preserving surgical editor for `supabase/config.{toml,json}`. Pure and synchronous: * callers own reading the current file text and writing the returned text back out atomically. * Every edited document is re-parsed and deep-compared against the original before being * returned; any mismatch refuses rather than shipping wrong bytes. An edit either replaces an * existing value's span in place or inserts a new line/table — nothing else is touched, so * untouched comments, spacing, and quoting survive byte-for-byte. See ADR 0023 for the design * rationale and rejected alternatives. */ export type ConfigEditValue = | string | number | boolean | ReadonlyArray | { readonly [key: string]: ConfigEditValue }; export interface ConfigEdit { readonly path: ReadonlyArray; readonly value: ConfigEditValue; } export type ConfigEditRefusalReason = | "duplicate_table_header" | "array_of_tables_on_path" | "inline_table_on_path" | "env_reference_target" | "verification_mismatch" | "parse_error"; export interface ConfigEditRefusal { readonly reason: ConfigEditRefusalReason; readonly path: ReadonlyArray; readonly detail: string; } export interface AppliedConfigEdit { readonly path: ReadonlyArray; readonly action: "replaced" | "inserted"; readonly createdTables: ReadonlyArray>; } export type ConfigEditOutcome = | { readonly kind: "applied"; readonly text: string; readonly applied: ReadonlyArray; } | { readonly kind: "refused"; readonly refusal: ConfigEditRefusal }; /** * The `[remotes.