/** * IR Diff Engine — Compare two versions of Manifest IR and produce a * structured diff report highlighting added/removed/changed entities, * properties, commands, constraints, policies, events, stores, and relationships. * * Can also generate database migration scripts (SQL and Prisma) from schema diffs. * * Design notes: * - Deterministic: same inputs always produce same output (sorted, no random IDs). * - IR is the authority — diffs are computed purely from IR, never from source. * - Migration generation is advisory: the consumer decides whether to apply. */ import type { IR, PropertyModifier } from './ir'; export type DiffChangeKind = 'added' | 'removed' | 'changed'; export interface PropertyDiff { name: string; change: DiffChangeKind; /** For 'changed': what changed */ details?: { type?: { from: string; to: string; }; modifiers?: { from: PropertyModifier[]; to: PropertyModifier[]; }; defaultValue?: { from: string; to: string; }; }; } export interface ComputedPropertyDiff { name: string; change: DiffChangeKind; details?: { type?: { from: string; to: string; }; expression?: { from: string; to: string; }; dependencies?: { from: string[]; to: string[]; }; }; } export interface RelationshipDiff { name: string; change: DiffChangeKind; details?: { kind?: { from: string; to: string; }; target?: { from: string; to: string; }; foreignKeyChanged?: boolean; through?: { from: string | undefined; to: string | undefined; }; onDelete?: { from: string | undefined; to: string | undefined; }; onUpdate?: { from: string | undefined; to: string | undefined; }; }; } export interface ConstraintDiff { name: string; change: DiffChangeKind; details?: { severity?: { from: string; to: string; }; message?: { from: string | undefined; to: string | undefined; }; }; } export interface CommandDiff { name: string; change: DiffChangeKind; details?: { entity?: { from: string | undefined; to: string | undefined; }; parametersAdded?: string[]; parametersRemoved?: string[]; guardsChanged?: boolean; actionsChanged?: boolean; emitsChanged?: boolean; returnsChanged?: boolean; }; } export interface PolicyDiff { name: string; change: DiffChangeKind; details?: { entity?: { from: string | undefined; to: string | undefined; }; action?: { from: string; to: string; }; expressionChanged?: boolean; }; } export interface StoreDiff { entity: string; change: DiffChangeKind; details?: { target?: { from: string; to: string; }; configChanged?: boolean; }; } export interface EventDiff { name: string; change: DiffChangeKind; details?: { channel?: { from: string; to: string; }; payloadChanged?: boolean; }; } export interface EntityDiff { name: string; change: DiffChangeKind; module?: { from: string | undefined; to: string | undefined; }; properties: PropertyDiff[]; computedProperties: ComputedPropertyDiff[]; relationships: RelationshipDiff[]; constraints: ConstraintDiff[]; commands: string[]; policies: string[]; versionProperty?: { from: string | undefined; to: string | undefined; }; } export interface ModuleDiff { name: string; change: DiffChangeKind; entities: { added: string[]; removed: string[]; }; commands: { added: string[]; removed: string[]; }; stores: { added: string[]; removed: string[]; }; events: { added: string[]; removed: string[]; }; policies: { added: string[]; removed: string[]; }; } export interface IRDiffReport { /** Top-level summary */ summary: { entitiesAdded: number; entitiesRemoved: number; entitiesChanged: number; commandsAdded: number; commandsRemoved: number; commandsChanged: number; policiesAdded: number; policiesRemoved: number; policiesChanged: number; eventsAdded: number; eventsRemoved: number; eventsChanged: number; storesAdded: number; storesRemoved: number; storesChanged: number; modulesAdded: number; modulesRemoved: number; hasChanges: boolean; }; modules: ModuleDiff[]; entities: EntityDiff[]; commands: CommandDiff[]; policies: PolicyDiff[]; stores: StoreDiff[]; events: EventDiff[]; } export interface MigrationColumnChange { columnName: string; change: DiffChangeKind; details?: { type?: { from: string; to: string; }; nullable?: { from: boolean; to: boolean; }; default?: { from: string | undefined; to: string | undefined; }; unique?: { from: boolean; to: boolean; }; }; } export interface MigrationTableChange { tableName: string; change: DiffChangeKind; columns: MigrationColumnChange[]; } export interface MigrationReport { /** SQL DDL statements (PostgreSQL) */ sql: string[]; /** Prisma schema migration steps */ prisma: string[]; /** Human-readable summary */ summary: string[]; /** Warnings about potentially destructive changes */ warnings: string[]; } /** * Compare two IR versions and produce a structured diff report. */ export declare function diffIR(oldIR: IR, newIR: IR): IRDiffReport; /** * Generate migration scripts (SQL and Prisma) from an IR diff report. * * The migration is advisory — the consumer decides whether to apply. * Generated SQL targets PostgreSQL. Prisma output provides the equivalent * Prisma schema steps. */ export declare function generateMigration(diff: IRDiffReport, _oldIR: IR, newIR: IR): MigrationReport; //# sourceMappingURL=ir-diff.d.ts.map