@hasna/logs 0.3.21 → 0.3.22
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.
- package/LICENSE +2 -1
- package/README.md +15 -0
- package/bun.lock +375 -0
- package/dist/cli/index.js +4 -3
- package/dist/count-x3n7qg3c.js +9 -0
- package/dist/diagnose-e0w5rwbc.js +9 -0
- package/dist/export-c3eqjste.js +10 -0
- package/dist/health-3f6ezg5c.js +8 -0
- package/dist/http-1r4r23qf.js +1236 -0
- package/dist/index-2tg9psrh.js +1241 -0
- package/dist/index-3dr7d80h.js +57 -0
- package/dist/index-5cj74qka.js +10803 -0
- package/dist/index-7w7v7hnr.js +76 -0
- package/dist/index-8pwbytc6.js +1241 -0
- package/dist/index-997bkzr2.js +15 -0
- package/dist/index-9n6bpjxf.js +10787 -0
- package/dist/index-cpvq9np9.js +39 -0
- package/dist/index-edn08m6f.js +51 -0
- package/dist/index-eh9bkbpa.js +70 -0
- package/dist/index-hjzbctgt.js +5868 -0
- package/dist/index-hwabsrfh.js +10742 -0
- package/dist/index-re3ntm60.js +48 -0
- package/dist/index-sgg59p1t.js +1241 -0
- package/dist/index-ssqkc6nh.js +1241 -0
- package/dist/index-ww5ggfv3.js +90 -0
- package/dist/index.js +156 -0
- package/dist/jobs-ypmmc2ma.js +22 -0
- package/dist/mcp/index.js +1207 -7021
- package/dist/query-7jwj05er.js +15 -0
- package/dist/server/index.js +15 -7
- package/package.json +3 -3
- package/sdk/package.json +8 -3
- package/src/cli/entrypoints.test.ts +1 -1
- package/src/index.ts +1 -0
- package/src/mcp/http.test.ts +92 -0
- package/src/mcp/http.ts +128 -0
- package/src/mcp/index.ts +36 -6
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/lib/jobs.ts
|
|
3
|
+
function createJob(db, data) {
|
|
4
|
+
return db.prepare(`
|
|
5
|
+
INSERT INTO scan_jobs (project_id, page_id, schedule)
|
|
6
|
+
VALUES ($project_id, $page_id, $schedule)
|
|
7
|
+
RETURNING *
|
|
8
|
+
`).get({
|
|
9
|
+
$project_id: data.project_id,
|
|
10
|
+
$page_id: data.page_id ?? null,
|
|
11
|
+
$schedule: data.schedule
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function listJobs(db, projectId) {
|
|
15
|
+
if (projectId) {
|
|
16
|
+
return db.prepare("SELECT * FROM scan_jobs WHERE project_id = $p ORDER BY created_at DESC").all({ $p: projectId });
|
|
17
|
+
}
|
|
18
|
+
return db.prepare("SELECT * FROM scan_jobs ORDER BY created_at DESC").all();
|
|
19
|
+
}
|
|
20
|
+
function getJob(db, id) {
|
|
21
|
+
return db.prepare("SELECT * FROM scan_jobs WHERE id = $id").get({ $id: id });
|
|
22
|
+
}
|
|
23
|
+
function updateJob(db, id, data) {
|
|
24
|
+
const fields = Object.keys(data).map((k) => `${k} = $${k}`).join(", ");
|
|
25
|
+
if (!fields)
|
|
26
|
+
return getJob(db, id);
|
|
27
|
+
const params = Object.fromEntries(Object.entries(data).map(([k, v]) => [`$${k}`, v]));
|
|
28
|
+
params.$id = id;
|
|
29
|
+
return db.prepare(`UPDATE scan_jobs SET ${fields} WHERE id = $id RETURNING *`).get(params);
|
|
30
|
+
}
|
|
31
|
+
function deleteJob(db, id) {
|
|
32
|
+
db.run("DELETE FROM scan_jobs WHERE id = $id", { $id: id });
|
|
33
|
+
}
|
|
34
|
+
function createScanRun(db, data) {
|
|
35
|
+
return db.prepare(`
|
|
36
|
+
INSERT INTO scan_runs (job_id, page_id) VALUES ($job_id, $page_id) RETURNING *
|
|
37
|
+
`).get({ $job_id: data.job_id, $page_id: data.page_id ?? null });
|
|
38
|
+
}
|
|
39
|
+
function finishScanRun(db, id, data) {
|
|
40
|
+
return db.prepare(`
|
|
41
|
+
UPDATE scan_runs SET finished_at = strftime('%Y-%m-%dT%H:%M:%fZ','now'),
|
|
42
|
+
status = $status, logs_collected = $logs_collected,
|
|
43
|
+
errors_found = $errors_found, perf_score = $perf_score
|
|
44
|
+
WHERE id = $id RETURNING *
|
|
45
|
+
`).get({
|
|
46
|
+
$id: id,
|
|
47
|
+
$status: data.status,
|
|
48
|
+
$logs_collected: data.logs_collected,
|
|
49
|
+
$errors_found: data.errors_found,
|
|
50
|
+
$perf_score: data.perf_score ?? null
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function listScanRuns(db, jobId, limit = 20) {
|
|
54
|
+
return db.prepare("SELECT * FROM scan_runs WHERE job_id = $j ORDER BY started_at DESC LIMIT $l").all({ $j: jobId, $l: limit });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { createJob, listJobs, getJob, updateJob, deleteJob, createScanRun, finishScanRun, listScanRuns };
|