docs: enterprise refactor plan with ralph specs
This commit is contained in:
77
dist/db/VisualBaselineRepository.js
vendored
Normal file
77
dist/db/VisualBaselineRepository.js
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
/**
|
||||
* VisualBaselineRepository — CRUD for visual_baselines and visual_comparisons tables.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VisualBaselineRepository = void 0;
|
||||
class VisualBaselineRepository {
|
||||
constructor(db) {
|
||||
this.db = db;
|
||||
}
|
||||
// ─── Baselines ────────────────────────────────────────────────────────────
|
||||
createBaseline(params) {
|
||||
this.db.prepare(`
|
||||
INSERT OR REPLACE INTO visual_baselines (id, state_id, url, screenshot_path, approved_at, approved_by, width, height)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(params.id, params.stateId, params.url, params.screenshotPath, Date.now(), params.approvedBy ?? 'user', params.width, params.height);
|
||||
}
|
||||
findBaselineByStateId(stateId) {
|
||||
return this.db
|
||||
.prepare('SELECT * FROM visual_baselines WHERE state_id = ? ORDER BY approved_at DESC LIMIT 1')
|
||||
.get(stateId);
|
||||
}
|
||||
findBaselineById(id) {
|
||||
return this.db
|
||||
.prepare('SELECT * FROM visual_baselines WHERE id = ?')
|
||||
.get(id);
|
||||
}
|
||||
// ─── Comparisons ──────────────────────────────────────────────────────────
|
||||
createComparison(params) {
|
||||
this.db.prepare(`
|
||||
INSERT INTO visual_comparisons
|
||||
(id, session_id, state_id, baseline_id, current_screenshot_path, diff_screenshot_path, diff_pixels, diff_percent, status, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(params.id, params.sessionId, params.stateId, params.baselineId ?? null, params.currentScreenshotPath, params.diffScreenshotPath ?? null, params.diffPixels ?? null, params.diffPercent ?? null, params.status, Date.now());
|
||||
}
|
||||
findComparisonById(id) {
|
||||
return this.db
|
||||
.prepare('SELECT * FROM visual_comparisons WHERE id = ?')
|
||||
.get(id);
|
||||
}
|
||||
findComparisons(filters) {
|
||||
const conditions = [];
|
||||
const values = [];
|
||||
if (filters?.sessionId) {
|
||||
conditions.push('session_id = ?');
|
||||
values.push(filters.sessionId);
|
||||
}
|
||||
if (filters?.status) {
|
||||
conditions.push('status = ?');
|
||||
values.push(filters.status);
|
||||
}
|
||||
const where = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
||||
return this.db
|
||||
.prepare(`SELECT * FROM visual_comparisons ${where} ORDER BY created_at DESC`)
|
||||
.all(...values);
|
||||
}
|
||||
updateComparisonStatus(id, status) {
|
||||
this.db.prepare('UPDATE visual_comparisons SET status = ? WHERE id = ?').run(status, id);
|
||||
}
|
||||
promoteToBaseline(comparisonId) {
|
||||
const comparison = this.findComparisonById(comparisonId);
|
||||
if (!comparison)
|
||||
return null;
|
||||
const baselineId = `baseline_${Date.now()}`;
|
||||
this.createBaseline({
|
||||
id: baselineId,
|
||||
stateId: comparison.state_id,
|
||||
url: comparison.session_id,
|
||||
screenshotPath: comparison.current_screenshot_path,
|
||||
width: 1280,
|
||||
height: 720,
|
||||
});
|
||||
this.updateComparisonStatus(comparisonId, 'passed');
|
||||
return baselineId;
|
||||
}
|
||||
}
|
||||
exports.VisualBaselineRepository = VisualBaselineRepository;
|
||||
Reference in New Issue
Block a user