import type { Json, ModuleFilePath } from "@valbuild/core"; import { result } from "@valbuild/core/fp"; import { ValSourceFileHandler } from "./ValSourceFileHandler.js"; /** * The two files an extraction touches, as text — nothing written yet. * * Both paths are project-relative in the `ModuleFilePath` style (a leading * slash), because that is what the callers already hold and what * {@link getNewJsonEntryPaths} derives. Join them onto the project root to get * somewhere to write. */ export type JsonValuesEntryExtraction = { /** The `*.val.json` to CREATE. It must not already exist — see the note below. */ jsonPath: string; jsonContent: string; /** The `.val.ts` to rewrite, and its complete new text. */ valTsPath: string; valTsContent: string; }; /** * Works out what moving ONE inline `.jsonValues()` entry into its own * `*.val.json` would change, without changing anything. * * This is the whole fix for `jsonValues:extract-entry`, minus the writing. It * is split out because the two callers cannot share a way of applying it: the * CLI writes both files ({@link extractJsonValuesEntry}), while the editor has * to hand the same two changes back as a `WorkspaceEdit` so they go through the * undo stack and respect an unsaved buffer. Anything that lived in only one of * those would be a fix that behaves differently depending on where it was * invoked from, which is exactly the drift `codeActions.ts` exists to prevent. * * It does NOT check whether `jsonPath` already exists: that needs a filesystem, * and the editor's answer ("is there a buffer or a file here?") is not the * CLI's. Every caller must check before writing — overwriting an unrelated file * is not a fix. * * Root-only, like the rest of the `.jsonValues()` machinery: the entry is looked * up in the module's root record/router object literal. */ export declare function planJsonValuesEntryExtraction({ moduleFilePath, entryKey, content, valTsPath, valTsText, }: { moduleFilePath: ModuleFilePath; entryKey: string; /** The entry's value, as it is written inline in the `.val.ts`. */ content: Json; /** Where the `.val.ts` lives, for error messages. */ valTsPath: string; /** Its text — the editor's version of it, where there is an editor. */ valTsText: string; }): result.Result; /** * Moves ONE `.jsonValues()` entry that was written inline in the `.val.ts` into * its own `*.val.json`, replacing the inline value with * `c.json(() => import("./.val.json"))`. * * The `val validate --fix` half of {@link planJsonValuesEntryExtraction}. It is * not expressible as a patch (a patch edits one `.val.ts` and cannot create the * backing JSON file), so it writes both files directly — JSON first, so a * failure part-way through never leaves the module pointing at a file that does * not exist. */ export declare function extractJsonValuesEntry(moduleFilePath: ModuleFilePath, rootDir: string, entryKey: string, content: Json, sourceFileHandler: ValSourceFileHandler): void;