@hozon/store-log 0.2.2 → 0.2.4

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/lib/api.js CHANGED
@@ -50,6 +50,9 @@ export function createLogStoreAPI(db, adapter) {
50
50
  },
51
51
  async queryLogs (params) {
52
52
  if (!Number.isInteger(params.limit) || params.limit <= 0) throw new RangeError('Log limit must be a positive integer');
53
+ if (params.spanID !== undefined && params.traceID === undefined) throw new TypeError('Log spanID filter requires traceID');
54
+ const order = params.order ?? 'asc';
55
+ const after = order === 'asc' ? '>' : '<';
53
56
  const limit = Math.min(params.limit, 1000);
54
57
  let query = db.selectFrom('logs').select([
55
58
  'timestamp',
@@ -71,17 +74,18 @@ export function createLogStoreAPI(db, adapter) {
71
74
  query = query.where('category', '>=', gte).where('category', '<', lt);
72
75
  }
73
76
  if (params.traceID !== undefined) query = query.where('trace_id', '=', params.traceID);
77
+ if (params.spanID !== undefined) query = query.where('span_id', '=', params.spanID);
74
78
  if (params.cursor !== undefined) {
75
79
  const [timestamp, seq] = decodeCursor(params.cursor);
76
80
  query = query.where((eb)=>eb.or([
77
- eb('timestamp', '>', timestamp),
81
+ eb('timestamp', after, timestamp),
78
82
  eb.and([
79
83
  eb('timestamp', '=', timestamp),
80
- eb('seq', '>', seq)
84
+ eb('seq', after, seq)
81
85
  ])
82
86
  ]));
83
87
  }
84
- const rows = await query.orderBy('timestamp').orderBy('seq').limit(limit + 1).execute();
88
+ const rows = await query.orderBy('timestamp', order).orderBy('seq', order).limit(limit + 1).execute();
85
89
  const page = rows.slice(0, limit);
86
90
  const last = page.at(-1);
87
91
  return {
package/lib/migrations.js CHANGED
@@ -16,6 +16,12 @@ export function logStoreMigrations(ctx) {
16
16
  'timestamp',
17
17
  'seq'
18
18
  ]).execute();
19
+ await db.schema.createIndex(`${ctx.tablePrefix}_logs_trace_span_timestamp_seq`).on('logs').columns([
20
+ 'trace_id',
21
+ 'span_id',
22
+ 'timestamp',
23
+ 'seq'
24
+ ]).execute();
19
25
  await db.schema.createIndex(`${ctx.tablePrefix}_logs_level_timestamp`).on('logs').columns([
20
26
  'level',
21
27
  'timestamp'
package/lib/types.d.ts CHANGED
@@ -20,6 +20,10 @@ export type QueryLogsParams = {
20
20
  levels?: Array<LogLevel>;
21
21
  categoryPrefix?: Array<string>;
22
22
  traceID?: string;
23
+ /** Requires traceID. */
24
+ spanID?: string;
25
+ /** Defaults to 'asc'. */
26
+ order?: 'asc' | 'desc';
23
27
  limit: number;
24
28
  cursor?: string;
25
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hozon/store-log",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Portable structured log store for Hozon",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,16 +18,16 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@hozon/adapter": "^0.1.0",
21
- "@hozon/db": "^0.2.3",
21
+ "@hozon/db": "^0.3.0",
22
22
  "@sozai/codec": "^0.4.3",
23
23
  "@sozai/json": "^0.3.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@hozon/node-sqlite": "^0.1.0",
27
- "@types/node": "^26.6.4",
28
- "del-cli": "^7.0.0",
29
- "kysely": "^0.29.6",
30
- "vitest": "5.0.3"
27
+ "@types/node": "^26.6.5",
28
+ "del-cli": "^8.0.1",
29
+ "kysely": "^0.29.7",
30
+ "vitest": "5.0.5"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"