hzl-core 1.18.0 → 1.18.1
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/dist/events/types.d.ts +8 -8
- package/package.json +1 -1
- package/dist/db/connection.d.ts +0 -13
- package/dist/db/connection.d.ts.map +0 -1
- package/dist/db/connection.js +0 -54
- package/dist/db/connection.js.map +0 -1
- package/dist/db/connection.test.d.ts +0 -2
- package/dist/db/connection.test.d.ts.map +0 -1
- package/dist/db/connection.test.js +0 -63
- package/dist/db/connection.test.js.map +0 -1
package/dist/events/types.d.ts
CHANGED
|
@@ -63,27 +63,27 @@ declare const TaskCreatedSchema: z.ZodObject<{
|
|
|
63
63
|
}, "strip", z.ZodTypeAny, {
|
|
64
64
|
title: string;
|
|
65
65
|
project: string;
|
|
66
|
+
parent_id?: string | undefined;
|
|
66
67
|
description?: string | undefined;
|
|
67
68
|
links?: string[] | undefined;
|
|
69
|
+
depends_on?: string[] | undefined;
|
|
68
70
|
tags?: string[] | undefined;
|
|
69
71
|
priority?: number | undefined;
|
|
70
72
|
due_at?: string | undefined;
|
|
71
73
|
metadata?: Record<string, unknown> | undefined;
|
|
72
|
-
parent_id?: string | undefined;
|
|
73
74
|
assignee?: string | undefined;
|
|
74
|
-
depends_on?: string[] | undefined;
|
|
75
75
|
}, {
|
|
76
76
|
title: string;
|
|
77
77
|
project: string;
|
|
78
|
+
parent_id?: string | undefined;
|
|
78
79
|
description?: string | undefined;
|
|
79
80
|
links?: string[] | undefined;
|
|
81
|
+
depends_on?: string[] | undefined;
|
|
80
82
|
tags?: string[] | undefined;
|
|
81
83
|
priority?: number | undefined;
|
|
82
84
|
due_at?: string | undefined;
|
|
83
85
|
metadata?: Record<string, unknown> | undefined;
|
|
84
|
-
parent_id?: string | undefined;
|
|
85
86
|
assignee?: string | undefined;
|
|
86
|
-
depends_on?: string[] | undefined;
|
|
87
87
|
}>;
|
|
88
88
|
declare const StatusChangedSchema: z.ZodObject<{
|
|
89
89
|
from: z.ZodNativeEnum<typeof TaskStatus>;
|
|
@@ -125,19 +125,19 @@ declare const TaskUpdatedSchema: z.ZodEffects<z.ZodObject<{
|
|
|
125
125
|
old_value: z.ZodOptional<z.ZodUnknown>;
|
|
126
126
|
new_value: z.ZodUnknown;
|
|
127
127
|
}, "strip", z.ZodTypeAny, {
|
|
128
|
-
field: "title" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "
|
|
128
|
+
field: "title" | "parent_id" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "assignee";
|
|
129
129
|
old_value?: unknown;
|
|
130
130
|
new_value?: unknown;
|
|
131
131
|
}, {
|
|
132
|
-
field: "title" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "
|
|
132
|
+
field: "title" | "parent_id" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "assignee";
|
|
133
133
|
old_value?: unknown;
|
|
134
134
|
new_value?: unknown;
|
|
135
135
|
}>, {
|
|
136
|
-
field: "title" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "
|
|
136
|
+
field: "title" | "parent_id" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "assignee";
|
|
137
137
|
old_value?: unknown;
|
|
138
138
|
new_value?: unknown;
|
|
139
139
|
}, {
|
|
140
|
-
field: "title" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "
|
|
140
|
+
field: "title" | "parent_id" | "description" | "links" | "tags" | "priority" | "due_at" | "metadata" | "assignee";
|
|
141
141
|
old_value?: unknown;
|
|
142
142
|
new_value?: unknown;
|
|
143
143
|
}>;
|
package/package.json
CHANGED
package/dist/db/connection.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Database from 'libsql';
|
|
2
|
-
export declare function getDefaultDbPath(): string;
|
|
3
|
-
export declare function createConnection(dbPath?: string): Database.Database;
|
|
4
|
-
/**
|
|
5
|
-
* Execute a function within a write transaction using BEGIN IMMEDIATE.
|
|
6
|
-
* This ensures proper locking for concurrent access from multiple agents.
|
|
7
|
-
* Includes retry logic for SQLITE_BUSY errors.
|
|
8
|
-
*/
|
|
9
|
-
export declare function withWriteTransaction<T>(db: Database.Database, fn: () => T, opts?: {
|
|
10
|
-
retries?: number;
|
|
11
|
-
busySleepMs?: number;
|
|
12
|
-
}): T;
|
|
13
|
-
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/db/connection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,QAAQ,CAAC;AAM9B,wBAAgB,gBAAgB,IAAI,MAAM,CAGzC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAcnE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,EAAE,EAAE,MAAM,CAAC,EACX,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAChD,CAAC,CA0BH"}
|
package/dist/db/connection.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import Database from 'libsql';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import os from 'os';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { runMigrations } from './migrations.js';
|
|
6
|
-
export function getDefaultDbPath() {
|
|
7
|
-
const hzlDir = path.join(os.homedir(), '.hzl');
|
|
8
|
-
return path.join(hzlDir, 'data.db');
|
|
9
|
-
}
|
|
10
|
-
export function createConnection(dbPath) {
|
|
11
|
-
const resolvedPath = dbPath ?? process.env.HZL_DB ?? getDefaultDbPath();
|
|
12
|
-
// Handle in-memory databases
|
|
13
|
-
if (resolvedPath !== ':memory:') {
|
|
14
|
-
const dir = path.dirname(resolvedPath);
|
|
15
|
-
if (!fs.existsSync(dir)) {
|
|
16
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const db = new Database(resolvedPath);
|
|
20
|
-
runMigrations(db);
|
|
21
|
-
return db;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Execute a function within a write transaction using BEGIN IMMEDIATE.
|
|
25
|
-
* This ensures proper locking for concurrent access from multiple agents.
|
|
26
|
-
* Includes retry logic for SQLITE_BUSY errors.
|
|
27
|
-
*/
|
|
28
|
-
export function withWriteTransaction(db, fn, opts) {
|
|
29
|
-
const retries = opts?.retries ?? 5;
|
|
30
|
-
const busySleepMs = opts?.busySleepMs ?? 25;
|
|
31
|
-
let attempt = 0;
|
|
32
|
-
while (true) {
|
|
33
|
-
try {
|
|
34
|
-
// Use immediate transaction for write lock
|
|
35
|
-
return db.transaction(fn).immediate();
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
const error = err;
|
|
39
|
-
const isBusy = error?.code === 'SQLITE_BUSY' ||
|
|
40
|
-
(typeof error?.message === 'string' && error.message.includes('SQLITE_BUSY'));
|
|
41
|
-
if (!isBusy || attempt >= retries) {
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
attempt += 1;
|
|
45
|
-
// Simple sleep with exponential backoff
|
|
46
|
-
const sleepTime = busySleepMs * attempt;
|
|
47
|
-
const start = Date.now();
|
|
48
|
-
while (Date.now() - start < sleepTime) {
|
|
49
|
-
// Busy wait (synchronous sleep for better-sqlite3)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/db/connection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,QAAQ,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,E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S,EAAE,CAAC;QACxC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,GAAiD,CAAC;YAChE,MAAM,MAAM,GACV,KAAK,EAAE,IAAI,KAAK,aAAa;gBAC7B,CAAC,OAAO,KAAK,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;YAChF,IAAI,CAAC,MAAM,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;gBAClC,MAAM,GAAG,CAAC;YACZ,CAAC;YACD,OAAO,IAAI,CAAC,CAAC;YACb,wCAAwC;YACxC,MAAM,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;YACxC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,SAAS,EAAE,CAAC;gBACtC,mDAAmD;YACrD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.test.d.ts","sourceRoot":"","sources":["../../src/db/connection.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
-
import { createConnection, getDefaultDbPath, withWriteTransaction } from './connection.js';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
describe('connection', () => {
|
|
7
|
-
const testDbPath = path.join(os.tmpdir(), 'hzl-test-' + Date.now() + '.db');
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
try {
|
|
10
|
-
if (fs.existsSync(testDbPath))
|
|
11
|
-
fs.unlinkSync(testDbPath);
|
|
12
|
-
if (fs.existsSync(testDbPath + '-wal'))
|
|
13
|
-
fs.unlinkSync(testDbPath + '-wal');
|
|
14
|
-
if (fs.existsSync(testDbPath + '-shm'))
|
|
15
|
-
fs.unlinkSync(testDbPath + '-shm');
|
|
16
|
-
}
|
|
17
|
-
catch { }
|
|
18
|
-
});
|
|
19
|
-
it('creates database file at specified path', () => {
|
|
20
|
-
const db = createConnection(testDbPath);
|
|
21
|
-
expect(fs.existsSync(testDbPath)).toBe(true);
|
|
22
|
-
db.close();
|
|
23
|
-
});
|
|
24
|
-
it('runs migrations on new database', () => {
|
|
25
|
-
const db = createConnection(testDbPath);
|
|
26
|
-
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
|
|
27
|
-
const tableNames = tables.map((t) => t.name);
|
|
28
|
-
expect(tableNames).toContain('events');
|
|
29
|
-
expect(tableNames).toContain('tasks_current');
|
|
30
|
-
expect(tableNames).toContain('projection_state');
|
|
31
|
-
db.close();
|
|
32
|
-
});
|
|
33
|
-
it('returns default path in ~/.hzl/', () => {
|
|
34
|
-
const defaultPath = getDefaultDbPath();
|
|
35
|
-
expect(defaultPath).toContain('.hzl');
|
|
36
|
-
expect(defaultPath).toContain('data.db');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe('withWriteTransaction', () => {
|
|
40
|
-
it('commits on success', () => {
|
|
41
|
-
const db = createConnection(':memory:');
|
|
42
|
-
withWriteTransaction(db, () => {
|
|
43
|
-
db.prepare('INSERT INTO projection_state (name, last_event_id, updated_at) VALUES (?, ?, ?)').run('test', 0, new Date().toISOString());
|
|
44
|
-
});
|
|
45
|
-
const row = db.prepare('SELECT * FROM projection_state WHERE name = ?').get('test');
|
|
46
|
-
expect(row).toBeDefined();
|
|
47
|
-
db.close();
|
|
48
|
-
});
|
|
49
|
-
it('rolls back on error', () => {
|
|
50
|
-
const db = createConnection(':memory:');
|
|
51
|
-
try {
|
|
52
|
-
withWriteTransaction(db, () => {
|
|
53
|
-
db.prepare('INSERT INTO projection_state (name, last_event_id, updated_at) VALUES (?, ?, ?)').run('test', 0, new Date().toISOString());
|
|
54
|
-
throw new Error('Intentional failure');
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch { }
|
|
58
|
-
const row = db.prepare('SELECT * FROM projection_state WHERE name = ?').get('test');
|
|
59
|
-
expect(row).toBeUndefined();
|
|
60
|
-
db.close();
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
//# sourceMappingURL=connection.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.test.js","sourceRoot":"","sources":["../../src/db/connection.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IAE5E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC;YACH,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YACzD,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC;YAC3E,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC;gBAAE,EAAE,CAAC,UAAU,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC;QAC7E,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC,CAAC,CAAC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