/** * Profile patch-row editing for the gateway host half. The npm web loader * honors `disabled` on rows and applies the profile patch as the user layer, * so next-start enablement is a bare `{ id, name, disabled }` override row — * the same id-targeted, later-wins semantics the official desktop writer * uses. Editing goes through the `yaml` document round-trip, which preserves * comments and unrelated rows byte-for-byte in spirit; the !!js expression * tag keeps loader expressions literal so profiles carrying them stay * parseable. * @module @linxin666/dsh-client-ui-plugin-manager/host */ import { type Document, type ScalarTag, type YAMLMap, type YAMLSeq } from 'yaml'; /** * Persist one patch file conservatively: a timestamped-free single backup, * then a tmp write and an atomic-ish rename over the target. * @param patchPath - absolute cordis.patch.yml path. * @param text - the new file text. */ export declare function writePatchAtomic(patchPath: string, text: string): Promise; /** YAML `!!js` expression tag: expressions stay literal until the Loader evaluates them. */ export declare const JS_EXPRESSION_TAG: ScalarTag; /** A parsed patch file: the yaml document and its top-level sequence. */ export interface PatchDocumentView { readonly document: Document; readonly root: YAMLSeq; } /** * Parse a patch file, failing loud on invalid YAML and non-array roots. * @param text - file content. * @param filename - absolute cordis.patch.yml path (diagnostics only). * @returns the parsed document and root sequence. */ export declare function parsePatch(text: string, filename: string): PatchDocumentView; /** The string id of a bare row, when it carries one. */ export declare function bareRowId(item: unknown): string | undefined; /** The string name of a bare row, when it carries one. */ export declare function bareRowName(item: unknown): string | undefined; /** * The next-start enablement a bare row declares: a row is enabled unless it * carries an explicit `disabled: true` (mirrors the official reader). Non-row * items (insert wrappers, config rows) count as enabled. * @param item - one top-level patch item. * @returns whether the item leaves its entry enabled. */ export declare function bareRowEnabled(item: unknown): boolean; /** * The enablement a bundle patch itself declares for the ids it mentions: an * insert entry's own `disabled` key, then later top-level bare * `{ id, disabled }` rows applied in file order (the loader's later-wins * semantics). Ids the patch never mentions stay absent, which means "this * layer has no opinion" — not "enabled". The aggregate package ships its * inactive-by-default family rows exactly this way. * @param patchText - the package's own bundle patch text (`[]` for none). * @returns declared enablement by entry id, absent when undeclared. */ export declare function rowDefaultEnabledOf(patchText: string): Map; /** * Find the bare override row for one id. * @param root - the top-level sequence. * @param id - the entry id to match. * @returns the row and its index, or undefined. */ export declare function findBareRow(root: YAMLSeq, id: string): { row: YAMLMap; index: number; } | undefined; /** * The ids an installed package's own bundle patch claims, read from its * cordis.patch.yml (each insert entry carries an id). An empty result means * the package is a plain plugin whose row id is its package name. * @param patchText - the package's own bundle patch text (`[]` for none). * @returns the claimed insert ids, in order. */ export declare function claimedIdsOf(patchText: string): string[]; /** One insert entry of a bundle patch: the claimed id and the plugin package name. */ export interface InsertRow { id?: string; name?: string; /** * The real plugin package the row mounts, read from the aggregate shell * row's config.plugin. Present on shell-wrapped family rows; the display * name of a child row prefers it over the per-family subpath name. */ plugin?: string; } /** * The insert entries of an installed package's own bundle patch, with both * the claimed id and the entry's own name. The name matters twice: the * loader imports the plugin by it (an unresolvable name is a boot failure), * and a bare override row whose name mismatches it is skipped by the include * patch semantics, so enablement rows must carry this exact name. * @param patchText - the package's own bundle patch text (`[]` for none). * @returns the insert rows, in order. */ export declare function insertRowsOf(patchText: string): InsertRow[]; /** * The inner entry of an insert-format item whose id matches, when one exists * (the official desktop writer manages rows in this shape). * @param root - the top-level sequence. * @param id - the entry id to match. * @returns the inner row, or undefined. */ export declare function findInsertRow(root: YAMLSeq, id: string): YAMLMap | undefined; /** * Persist the next-start enablement of one entry. Bare override rows are this * package's own shape: enabling removes the override (or writes * `disabled: false` when the bundle itself ships the row disabled), disabling * creates or updates `{ id, name, disabled: true }`. When a newer desktop tool already * manages the entry as an insert-format row, the inner row's `disabled` flag * is edited instead (the official writer's shape). The returned text * preserves every other row and comment. * @param text - current patch file text. * @param filename - absolute path (diagnostics only). * @param id - the entry id to override. * @param name - the display name recorded on the row. * @param enabled - desired next-start enablement. * @param baseEnabled - whether the bundle layer leaves the id enabled; a bundle * that ships the row disabled needs an explicit `disabled: false` override, * because removing the user row only restores "no user opinion". * @returns the new file text. */ export declare function setRowEnabled(text: string, filename: string, id: string, name: string, enabled: boolean, baseEnabled?: boolean): string;