import { IModelDescriptor, IRelationDescriptor, OrphanPolicy } from './interfaces.js'; import type { ModelBase } from './model.js'; /** * What `save()` will do with one model instance. * * There is no `delete` member: every row `save()` removes is removed because it was detached * from a relation, and that is carried by `IOrphanDelta` keyed by primary key rather than by * a subject over a model instance the caller no longer holds. */ export declare enum SubjectOperation { Insert = "insert", Update = "update", None = "none" } /** * A foreign-key column whose value is another model's primary key — which may not exist yet * when the subject is built. Resolved by the executor immediately before the statement that * needs it. */ export interface IPendingForeignKey { /** Column on this subject's own row that receives the key. */ Column: string; /** Model the value is read from. */ Target: ModelBase; /** * Column on `Target` that holds the value — the relation's join column, `Relation.PrimaryKey`. * That is the target's own primary key unless the relation names another one, so this is read * instead of `Target.PrimaryKeyValue`: the two differ for `@BelongsTo(T, 'fk', 'Code')`, and * the join column is what every other persist path writes. */ JoinColumn: string; } /** * The membership change of one hasMany relation on one owner, as of the snapshot diff. * * `Added` are members with no snapshot ( never in the database ). `Kept` are members that * were already there or were re-parented in from elsewhere. `RemovedKeys` are primary keys * that were in the snapshot and are not in the array any more. */ export interface IRelationDelta { Descriptor: IRelationDescriptor; Added: ModelBase[]; Kept: ModelBase[]; RemovedKeys: unknown[]; } /** * Junction rows to create and destroy for one manyToMany relation on one owner. * `Added` holds target models because their keys may not exist yet; `RemovedKeys` holds * plain keys because those models are gone from the array. */ export interface IJunctionDelta { Descriptor: IRelationDescriptor; JunctionDescriptor: IModelDescriptor; Owner: ModelBase; Added: ModelBase[]; RemovedKeys: unknown[]; } /** * Rows detached from a relation and the policy that decides their fate. */ export interface IOrphanDelta { Descriptor: IRelationDescriptor; TargetDescriptor: IModelDescriptor; Policy: OrphanPolicy; PrimaryKeys: unknown[]; } /** * One model instance and everything `save()` needs to know about it. */ export declare class Subject { readonly Model: ModelBase; readonly Descriptor: IModelDescriptor; Operation: SubjectOperation; /** Columns that differ from the snapshot. Empty for an insert, which writes everything. */ ChangedColumns: string[]; /** Foreign keys resolved just before this subject's own statement runs. */ PendingForeignKeys: IPendingForeignKey[]; /** * Foreign keys that cannot be resolved before this subject's INSERT — a self-referencing * cycle — and are applied by a follow-up UPDATE in the update phase instead. */ DeferredForeignKeys: IPendingForeignKey[]; /** hasMany membership changes owned by this subject. Read by the orphan resolver. */ RelationDeltas: IRelationDelta[]; /** `Model#key`, or `Model#` before the key exists. Diagnostics only — never a map key. */ get Identity(): string; constructor(Model: ModelBase, Descriptor: IModelDescriptor, Operation: SubjectOperation); } /** * Everything one `save()` will do, before ordering. */ export declare class SubjectSet { readonly Subjects: Subject[]; readonly Junctions: IJunctionDelta[]; readonly Orphans: IOrphanDelta[]; private _byModel; /** * Registers `subject`, or returns the one already registered for the same model instance. * Instance identity is the key — canonicalizing two instances of one row is the identity * map's job, and it runs first. */ add(subject: Subject): Subject; find(model: ModelBase): Subject | undefined; /** True when this set would emit no statements at all. */ get IsEmpty(): boolean; } //# sourceMappingURL=subject.d.ts.map