@openqa/cli 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,123 +7,171 @@ import { Tracer } from "@orka-js/observability";
7
7
  import { EventEmitter as EventEmitter3 } from "events";
8
8
 
9
9
  // database/index.ts
10
- import Database from "better-sqlite3";
11
- import { readFileSync } from "fs";
12
- import { join, dirname } from "path";
10
+ import { Low } from "lowdb";
11
+ import { JSONFile } from "lowdb/node";
12
+ import { dirname } from "path";
13
13
  import { fileURLToPath } from "url";
14
14
  import { mkdirSync } from "fs";
15
15
  var __filename = fileURLToPath(import.meta.url);
16
16
  var __dirname = dirname(__filename);
17
17
  var OpenQADatabase = class {
18
- db;
19
- constructor(dbPath = "./data/openqa.db") {
20
- const dir = dirname(dbPath);
21
- mkdirSync(dir, { recursive: true });
22
- this.db = new Database(dbPath);
18
+ constructor(dbPath = "./data/openqa.json") {
19
+ this.dbPath = dbPath;
23
20
  this.initialize();
24
21
  }
22
+ db = null;
25
23
  initialize() {
26
- const schema = readFileSync(join(__dirname, "schema.sql"), "utf-8");
27
- this.db.exec(schema);
28
- }
29
- getConfig(key) {
30
- const row = this.db.prepare("SELECT value FROM config WHERE key = ?").get(key);
31
- return row?.value || null;
32
- }
33
- setConfig(key, value) {
34
- this.db.prepare("INSERT OR REPLACE INTO config (key, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP)").run(key, value);
35
- }
36
- getAllConfig() {
37
- const rows = this.db.prepare("SELECT key, value FROM config").all();
38
- return Object.fromEntries(rows.map((r) => [r.key, r.value]));
39
- }
40
- createSession(id, metadata) {
41
- this.db.prepare("INSERT INTO test_sessions (id, status, metadata) VALUES (?, ?, ?)").run(
42
- id,
43
- "running",
44
- metadata ? JSON.stringify(metadata) : null
45
- );
46
- return this.getSession(id);
47
- }
48
- getSession(id) {
49
- return this.db.prepare("SELECT * FROM test_sessions WHERE id = ?").get(id);
24
+ const dir = dirname(this.dbPath);
25
+ mkdirSync(dir, { recursive: true });
26
+ const adapter = new JSONFile(this.dbPath);
27
+ this.db = new Low(adapter, {
28
+ config: {},
29
+ test_sessions: [],
30
+ actions: [],
31
+ bugs: [],
32
+ kanban_tickets: []
33
+ });
34
+ this.db.read();
35
+ if (!this.db.data) {
36
+ this.db.data = {
37
+ config: {},
38
+ test_sessions: [],
39
+ actions: [],
40
+ bugs: [],
41
+ kanban_tickets: []
42
+ };
43
+ this.db.write();
44
+ }
50
45
  }
51
- updateSession(id, updates) {
52
- const fields = Object.keys(updates).map((k) => `${k} = ?`).join(", ");
53
- const values = [...Object.values(updates), id];
54
- this.db.prepare(`UPDATE test_sessions SET ${fields} WHERE id = ?`).run(...values);
46
+ async ensureInitialized() {
47
+ if (!this.db) {
48
+ this.initialize();
49
+ }
50
+ await this.db.read();
55
51
  }
56
- getRecentSessions(limit = 10) {
57
- return this.db.prepare("SELECT * FROM test_sessions ORDER BY started_at DESC LIMIT ?").all(limit);
52
+ async getConfig(key) {
53
+ await this.ensureInitialized();
54
+ return this.db.data.config[key] || null;
58
55
  }
59
- createAction(action) {
60
- const id = `action_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
61
- this.db.prepare("INSERT INTO actions (id, session_id, type, description, input, output, screenshot_path) VALUES (?, ?, ?, ?, ?, ?, ?)").run(
62
- id,
63
- action.session_id,
64
- action.type,
65
- action.description,
66
- action.input || null,
67
- action.output || null,
68
- action.screenshot_path || null
69
- );
70
- return this.db.prepare("SELECT * FROM actions WHERE id = ?").get(id);
56
+ async setConfig(key, value) {
57
+ await this.ensureInitialized();
58
+ this.db.data.config[key] = value;
59
+ await this.db.write();
71
60
  }
72
- getSessionActions(sessionId) {
73
- return this.db.prepare("SELECT * FROM actions WHERE session_id = ? ORDER BY timestamp DESC").all(sessionId);
61
+ async getAllConfig() {
62
+ await this.ensureInitialized();
63
+ return this.db.data.config;
74
64
  }
75
- createBug(bug) {
76
- const id = `bug_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
77
- this.db.prepare("INSERT INTO bugs (id, session_id, title, description, severity, status, github_issue_url, screenshot_path) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(
65
+ async createSession(id, metadata) {
66
+ await this.ensureInitialized();
67
+ const session = {
78
68
  id,
79
- bug.session_id,
80
- bug.title,
81
- bug.description,
82
- bug.severity,
83
- bug.status,
84
- bug.github_issue_url || null,
85
- bug.screenshot_path || null
86
- );
87
- return this.db.prepare("SELECT * FROM bugs WHERE id = ?").get(id);
88
- }
89
- updateBug(id, updates) {
90
- const fields = Object.keys(updates).map((k) => `${k} = ?`).join(", ");
91
- const values = [...Object.values(updates), id];
92
- this.db.prepare(`UPDATE bugs SET ${fields}, updated_at = CURRENT_TIMESTAMP WHERE id = ?`).run(...values);
93
- }
94
- getAllBugs() {
95
- return this.db.prepare("SELECT * FROM bugs ORDER BY created_at DESC").all();
69
+ started_at: (/* @__PURE__ */ new Date()).toISOString(),
70
+ status: "running",
71
+ total_actions: 0,
72
+ bugs_found: 0,
73
+ metadata: metadata ? JSON.stringify(metadata) : void 0
74
+ };
75
+ this.db.data.test_sessions.push(session);
76
+ await this.db.write();
77
+ return session;
78
+ }
79
+ async getSession(id) {
80
+ await this.ensureInitialized();
81
+ return this.db.data.test_sessions.find((s) => s.id === id) || null;
82
+ }
83
+ async updateSession(id, updates) {
84
+ await this.ensureInitialized();
85
+ const index = this.db.data.test_sessions.findIndex((s) => s.id === id);
86
+ if (index !== -1) {
87
+ this.db.data.test_sessions[index] = { ...this.db.data.test_sessions[index], ...updates };
88
+ await this.db.write();
89
+ }
96
90
  }
97
- getBugsByStatus(status) {
98
- return this.db.prepare("SELECT * FROM bugs WHERE status = ? ORDER BY created_at DESC").all(status);
91
+ async getRecentSessions(limit = 10) {
92
+ await this.ensureInitialized();
93
+ return this.db.data.test_sessions.sort((a, b) => new Date(b.started_at).getTime() - new Date(a.started_at).getTime()).slice(0, limit);
99
94
  }
100
- createKanbanTicket(ticket) {
101
- const id = `ticket_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
102
- this.db.prepare("INSERT INTO kanban_tickets (id, bug_id, title, description, priority, column, tags, screenshot_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(
103
- id,
104
- ticket.bug_id || null,
105
- ticket.title,
106
- ticket.description,
107
- ticket.priority,
108
- ticket.column,
109
- ticket.tags || null,
110
- ticket.screenshot_url || null
111
- );
112
- return this.db.prepare("SELECT * FROM kanban_tickets WHERE id = ?").get(id);
95
+ async createAction(action) {
96
+ await this.ensureInitialized();
97
+ const newAction = {
98
+ id: `action_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
99
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
100
+ ...action
101
+ };
102
+ this.db.data.actions.push(newAction);
103
+ await this.db.write();
104
+ return newAction;
105
+ }
106
+ async getSessionActions(sessionId) {
107
+ await this.ensureInitialized();
108
+ return this.db.data.actions.filter((a) => a.session_id === sessionId).sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
109
+ }
110
+ async createBug(bug) {
111
+ await this.ensureInitialized();
112
+ const newBug = {
113
+ id: `bug_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
114
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
115
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
116
+ ...bug
117
+ };
118
+ this.db.data.bugs.push(newBug);
119
+ await this.db.write();
120
+ return newBug;
121
+ }
122
+ async updateBug(id, updates) {
123
+ await this.ensureInitialized();
124
+ const index = this.db.data.bugs.findIndex((b) => b.id === id);
125
+ if (index !== -1) {
126
+ this.db.data.bugs[index] = {
127
+ ...this.db.data.bugs[index],
128
+ ...updates,
129
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
130
+ };
131
+ await this.db.write();
132
+ }
113
133
  }
114
- updateKanbanTicket(id, updates) {
115
- const fields = Object.keys(updates).map((k) => `${k} = ?`).join(", ");
116
- const values = [...Object.values(updates), id];
117
- this.db.prepare(`UPDATE kanban_tickets SET ${fields}, updated_at = CURRENT_TIMESTAMP WHERE id = ?`).run(...values);
134
+ async getAllBugs() {
135
+ await this.ensureInitialized();
136
+ return this.db.data.bugs.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
137
+ }
138
+ async getBugsByStatus(status) {
139
+ await this.ensureInitialized();
140
+ return this.db.data.bugs.filter((b) => b.status === status).sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
141
+ }
142
+ async createKanbanTicket(ticket) {
143
+ await this.ensureInitialized();
144
+ const newTicket = {
145
+ id: `ticket_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
146
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
147
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
148
+ ...ticket
149
+ };
150
+ this.db.data.kanban_tickets.push(newTicket);
151
+ await this.db.write();
152
+ return newTicket;
153
+ }
154
+ async updateKanbanTicket(id, updates) {
155
+ await this.ensureInitialized();
156
+ const index = this.db.data.kanban_tickets.findIndex((t) => t.id === id);
157
+ if (index !== -1) {
158
+ this.db.data.kanban_tickets[index] = {
159
+ ...this.db.data.kanban_tickets[index],
160
+ ...updates,
161
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
162
+ };
163
+ await this.db.write();
164
+ }
118
165
  }
119
- getKanbanTickets() {
120
- return this.db.prepare("SELECT * FROM kanban_tickets ORDER BY created_at DESC").all();
166
+ async getKanbanTickets() {
167
+ await this.ensureInitialized();
168
+ return this.db.data.kanban_tickets.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
121
169
  }
122
- getKanbanTicketsByColumn(column) {
123
- return this.db.prepare("SELECT * FROM kanban_tickets WHERE column = ? ORDER BY created_at DESC").all(column);
170
+ async getKanbanTicketsByColumn(column) {
171
+ await this.ensureInitialized();
172
+ return this.db.data.kanban_tickets.filter((t) => t.column === column).sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
124
173
  }
125
- close() {
126
- this.db.close();
174
+ async close() {
127
175
  }
128
176
  };
129
177