@hozon/store-log 0.2.0 → 0.2.2

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Adapter } from '@hozon/adapter';
2
- import type { Kysely } from 'kysely';
2
+ import type { Kysely } from '@hozon/db';
3
3
  import type { LogTables } from './tables.js';
4
4
  import type { LogStore } from './types.js';
5
5
  export declare function createLogStoreAPI(db: Kysely<LogTables>, adapter: Adapter): LogStore;
package/lib/api.js CHANGED
@@ -1,14 +1,19 @@
1
1
  import { chunk, withKeepSet, withStoreTransaction } from '@hozon/db';
2
+ import { b64uFromUTF, b64uToUTF } from '@sozai/codec';
2
3
  import { categoryRange, encodeCategory } from './category.js';
4
+ function decodeLog(data) {
5
+ // Decode only the JSON column; nested JSON-looking strings are payload values.
6
+ return typeof data === 'string' ? JSON.parse(data) : data;
7
+ }
3
8
  function encodeCursor(timestamp, seq) {
4
- return btoa(JSON.stringify([
9
+ return b64uFromUTF(JSON.stringify([
5
10
  timestamp,
6
11
  seq
7
- ])).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
12
+ ]));
8
13
  }
9
14
  function decodeCursor(cursor) {
10
15
  try {
11
- const value = JSON.parse(atob(cursor.replaceAll('-', '+').replaceAll('_', '/')));
16
+ const value = JSON.parse(b64uToUTF(cursor));
12
17
  if (!Array.isArray(value) || value.length !== 2 || !value.every((item)=>typeof item === 'number' && Number.isFinite(item)) || !Number.isInteger(value[1])) {
13
18
  throw new TypeError('Invalid log cursor');
14
19
  }
@@ -80,7 +85,7 @@ export function createLogStoreAPI(db, adapter) {
80
85
  const page = rows.slice(0, limit);
81
86
  const last = page.at(-1);
82
87
  return {
83
- logs: page.map((row)=>row.data),
88
+ logs: page.map((row)=>decodeLog(row.data)),
84
89
  ...rows.length > limit && last !== undefined ? {
85
90
  cursor: encodeCursor(last.timestamp, last.seq)
86
91
  } : {}
@@ -89,7 +94,7 @@ export function createLogStoreAPI(db, adapter) {
89
94
  async getTraceLogs (traceID) {
90
95
  const rows = await db.selectFrom('logs').select('data').where('trace_id', '=', traceID).orderBy('timestamp').orderBy('seq').execute();
91
96
  // addLogs enforces paired IDs for every traced row.
92
- return rows.map((row)=>row.data);
97
+ return rows.map((row)=>decodeLog(row.data));
93
98
  },
94
99
  async deleteByTrace (traceIDs) {
95
100
  if (traceIDs.length === 0) return 0;
@@ -1,3 +1,2 @@
1
- import type { MigrationContext } from '@hozon/db';
2
- import type { Migration } from 'kysely/migration';
1
+ import type { Migration, MigrationContext } from '@hozon/db';
3
2
  export declare function logStoreMigrations(ctx: MigrationContext): Record<string, Migration>;
package/lib/migrations.js CHANGED
@@ -1,4 +1,4 @@
1
- import { sql } from 'kysely';
1
+ import { sql } from '@hozon/db';
2
2
  export function logStoreMigrations(ctx) {
3
3
  return {
4
4
  '0-init': {
package/lib/tables.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ColumnType, Generated } from 'kysely';
1
+ import type { ColumnType, Generated } from '@hozon/db';
2
2
  import type { LogLevel, StoredLog } from './types.js';
3
3
  export type LogTables = {
4
4
  logs: {
@@ -8,6 +8,6 @@ export type LogTables = {
8
8
  category: string;
9
9
  trace_id: string | null;
10
10
  span_id: string | null;
11
- data: ColumnType<StoredLog, unknown, unknown>;
11
+ data: ColumnType<StoredLog | string, unknown, unknown>;
12
12
  };
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hozon/store-log",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Portable structured log store for Hozon",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,14 +18,15 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@hozon/adapter": "^0.1.0",
21
- "@hozon/db": "^0.2.0",
22
- "@sozai/json": "^0.3.0",
23
- "kysely": "^0.29.6"
21
+ "@hozon/db": "^0.2.3",
22
+ "@sozai/codec": "^0.4.3",
23
+ "@sozai/json": "^0.3.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@hozon/node-sqlite": "^0.1.0",
27
27
  "@types/node": "^26.6.4",
28
28
  "del-cli": "^7.0.0",
29
+ "kysely": "^0.29.6",
29
30
  "vitest": "5.0.3"
30
31
  },
31
32
  "publishConfig": {