@hasna/logs 0.3.20 → 0.3.21

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.
@@ -1,90 +0,0 @@
1
- // @bun
2
- import {
3
- parseTime
4
- } from "./index-997bkzr2.js";
5
-
6
- // src/lib/query.ts
7
- function searchLogs(db, q) {
8
- const conditions = [];
9
- const params = {};
10
- if (q.project_id) {
11
- conditions.push("l.project_id = $project_id");
12
- params.$project_id = q.project_id;
13
- }
14
- if (q.page_id) {
15
- conditions.push("l.page_id = $page_id");
16
- params.$page_id = q.page_id;
17
- }
18
- if (q.service) {
19
- conditions.push("l.service = $service");
20
- params.$service = q.service;
21
- }
22
- if (q.trace_id) {
23
- conditions.push("l.trace_id = $trace_id");
24
- params.$trace_id = q.trace_id;
25
- }
26
- if (q.since) {
27
- conditions.push("l.timestamp >= $since");
28
- params.$since = parseTime(q.since) ?? q.since;
29
- }
30
- if (q.until) {
31
- conditions.push("l.timestamp <= $until");
32
- params.$until = parseTime(q.until) ?? q.until;
33
- }
34
- if (q.level) {
35
- const levels = Array.isArray(q.level) ? q.level : [q.level];
36
- const placeholders = levels.map((_, i) => `$level${i}`).join(",");
37
- levels.forEach((lv, i) => {
38
- params[`$level${i}`] = lv;
39
- });
40
- conditions.push(`l.level IN (${placeholders})`);
41
- }
42
- const limit = q.limit ?? 100;
43
- const offset = q.offset ?? 0;
44
- params.$limit = limit;
45
- params.$offset = offset;
46
- if (q.text) {
47
- params.$text = q.text;
48
- const where2 = conditions.length ? `WHERE ${conditions.join(" AND ")} AND` : "WHERE";
49
- const sql2 = `
50
- SELECT l.* FROM logs l
51
- ${where2} l.rowid IN (SELECT rowid FROM logs_fts WHERE logs_fts MATCH $text)
52
- ORDER BY l.timestamp DESC
53
- LIMIT $limit OFFSET $offset
54
- `;
55
- return db.prepare(sql2).all(params);
56
- }
57
- const where = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
58
- const sql = `SELECT * FROM logs l ${where} ORDER BY l.timestamp DESC LIMIT $limit OFFSET $offset`;
59
- return db.prepare(sql).all(params);
60
- }
61
- function tailLogs(db, projectId, n = 50) {
62
- if (projectId) {
63
- return db.prepare("SELECT * FROM logs WHERE project_id = $p ORDER BY timestamp DESC LIMIT $n").all({ $p: projectId, $n: n });
64
- }
65
- return db.prepare("SELECT * FROM logs ORDER BY timestamp DESC LIMIT $n").all({ $n: n });
66
- }
67
- function getLogContext(db, traceId) {
68
- return db.prepare("SELECT * FROM logs WHERE trace_id = $t ORDER BY timestamp ASC").all({ $t: traceId });
69
- }
70
- function getLogContextFromId(db, logId, window = 0) {
71
- const log = db.prepare("SELECT * FROM logs WHERE id = $id").get({ $id: logId });
72
- if (!log)
73
- return [];
74
- const trace = log.trace_id ? getLogContext(db, log.trace_id) : [log];
75
- if (window <= 0)
76
- return trace;
77
- const before = db.prepare(`SELECT * FROM logs WHERE id != $id AND timestamp <= $ts ORDER BY timestamp DESC LIMIT $n`).all({ $id: logId, $ts: log.timestamp, $n: window });
78
- const after = db.prepare(`SELECT * FROM logs WHERE id != $id AND timestamp > $ts ORDER BY timestamp ASC LIMIT $n`).all({ $id: logId, $ts: log.timestamp, $n: window });
79
- const seen = new Set;
80
- const merged = [];
81
- for (const row of [...before.reverse(), ...trace, ...after]) {
82
- if (!seen.has(row.id)) {
83
- seen.add(row.id);
84
- merged.push(row);
85
- }
86
- }
87
- return merged.sort((a, b) => a.timestamp < b.timestamp ? -1 : a.timestamp > b.timestamp ? 1 : 0);
88
- }
89
-
90
- export { searchLogs, tailLogs, getLogContext, getLogContextFromId };
@@ -1,22 +0,0 @@
1
- // @bun
2
- import {
3
- createJob,
4
- createScanRun,
5
- deleteJob,
6
- finishScanRun,
7
- getJob,
8
- listJobs,
9
- listScanRuns,
10
- updateJob
11
- } from "./index-3dr7d80h.js";
12
- import"./index-re3ntm60.js";
13
- export {
14
- updateJob,
15
- listScanRuns,
16
- listJobs,
17
- getJob,
18
- finishScanRun,
19
- deleteJob,
20
- createScanRun,
21
- createJob
22
- };
@@ -1,15 +0,0 @@
1
- // @bun
2
- import {
3
- getLogContext,
4
- getLogContextFromId,
5
- searchLogs,
6
- tailLogs
7
- } from "./index-ww5ggfv3.js";
8
- import"./index-997bkzr2.js";
9
- import"./index-re3ntm60.js";
10
- export {
11
- tailLogs,
12
- searchLogs,
13
- getLogContextFromId,
14
- getLogContext
15
- };