/**
 * Creates a change proposal that tracks an isolated source version
 * against a target version. Rows live in the global scope.
 *
 * @param source - the source version ref
 * @param target - the target version ref (usually Main)
 */
export async function createChangeProposal(args) {
    const { lix } = args;
    const exec = async (trx) => {
        const values = {
            source_version_id: args.source.id,
            target_version_id: args.target.id,
        };
        if (args.id)
            values.id = args.id;
        if (args.status)
            values.status = args.status;
        await trx
            .insertInto("change_proposal")
            .values(values)
            .execute();
        const created = await trx
            .selectFrom("change_proposal")
            .where("source_version_id", "=", args.source.id)
            .where("target_version_id", "=", args.target.id)
            .selectAll()
            .orderBy("lixcol_created_at", "desc")
            .limit(1)
            .executeTakeFirstOrThrow();
        return created;
    };
    if (lix.db.isTransaction)
        return exec(lix.db);
    return lix.db.transaction().execute(exec);
}
//# sourceMappingURL=create-change-proposal.js.map