import type { Manifest, PlacementRecord, WidgetRecord } from './manifest.js'; /** * Three-way diff engine (spec 04 § 7.2) — the core of the upgrade path. * * Compares three states for a theme: * - S (snapshot): the manifest as of the last install. * - M (manifest): the manifest as it is now. * - D (live DB): the current `widget_instance` / `widget_placement` rows. * * It is a PURE function — the caller loads the live DB once and passes it in, * so the whole thing is trivially unit-testable. The result is an ordered op * list (the order IS the contract, § 7.4), a conflict list, and counts. */ export interface Conflict { widget_uuid: string; field_path: string; manifest_value: unknown; user_value: unknown; } export interface PlanOp { table: 'widget_instance' | 'widget_placement' | 'landing_page'; op: 'INSERT' | 'UPDATE' | 'DELETE'; uuid: string; payload?: Record; } /** * A placement as the diff sees it: the shared shape plus the entity scope a * nested landing-page placement carries. `entity_urn` is STRUCTURAL — like * `widget_instance_uuid` it is never merged, only set on INSERT. */ export type ScopedPlacement = PlacementRecord & { entity_urn?: string | null; }; /** Live landing-page row as the diff's `D` input (manifest-carried fields only). */ export interface LandingPageLiveRow { uuid: string; name: string; description: string | null; meta_title: string | null; meta_description: string | null; status: boolean; } export interface DiffResult { ops: PlanOp[]; conflicts: Conflict[]; counts: { widgets_added: number; widgets_updated: number; widgets_removed: number; placements_added: number; placements_updated: number; placements_removed: number; landing_pages_added: number; landing_pages_updated: number; /** * Pages the manifest stopped shipping. The `landing_page` row is NEVER * deleted (pages are not theme property) — only its theme-owned placements * go. Counted so the CLI can report them. */ landing_pages_released: number; }; /** Pages dropped from the manifest whose row was left in place, by uuid+name. */ releasedLandingPages: Array<{ uuid: string; name: string; }>; /** * Rows already in the DB that this version of the manifest newly declares — * present in M and D but not in S. The author's own store after * `theme:export-content`: they built content in the page builder, exported * it, and are now re-activating. Adopted (left exactly as they are) and * recorded in the new snapshot, never re-inserted. */ adopted: { widgets: number; placements: number; landingPages: number; }; } export interface LiveDbState { widgets: Map; placements: Map; /** Live rows for the landing pages this theme knows about (S ∪ M). */ landingPages?: Map; } export declare function diffManifest(snapshot: Manifest, manifest: Manifest, liveDb: LiveDbState): DiffResult;