@kaban-board/core 0.2.11 → 0.2.12
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/db/bun-adapter.d.ts +3 -0
- package/dist/db/bun-adapter.d.ts.map +1 -0
- package/dist/db/index.d.ts +0 -3
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/libsql-adapter.d.ts +3 -0
- package/dist/db/libsql-adapter.d.ts.map +1 -0
- package/dist/db/utils.d.ts +3 -0
- package/dist/db/utils.d.ts.map +1 -0
- package/dist/index.js +194 -152
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun-adapter.d.ts","sourceRoot":"","sources":["../../src/db/bun-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAsD/D"}
|
package/dist/db/index.d.ts
CHANGED
|
@@ -9,14 +9,12 @@ type LibsqlClient = import("@libsql/client").Client;
|
|
|
9
9
|
* Note: Uses libsql drizzle type for compatibility; bun:sqlite is API-compatible at runtime.
|
|
10
10
|
*/
|
|
11
11
|
export type DB = Omit<DrizzleDb, "$client"> & {
|
|
12
|
-
/** Raw database client. Type varies by backend. */
|
|
13
12
|
$client: BunDatabase | LibsqlClient;
|
|
14
13
|
/**
|
|
15
14
|
* Execute raw SQL statements.
|
|
16
15
|
* @internal For schema initialization only. Does not sanitize input.
|
|
17
16
|
*/
|
|
18
17
|
$runRaw: (sql: string) => Promise<void>;
|
|
19
|
-
/** Close the database connection and release resources. */
|
|
20
18
|
$close: () => Promise<void>;
|
|
21
19
|
};
|
|
22
20
|
export interface DbConfig {
|
|
@@ -24,7 +22,6 @@ export interface DbConfig {
|
|
|
24
22
|
authToken?: string;
|
|
25
23
|
}
|
|
26
24
|
export interface CreateDbOptions {
|
|
27
|
-
/** Run migrations on connect. Default: true */
|
|
28
25
|
migrate?: boolean;
|
|
29
26
|
}
|
|
30
27
|
export declare function createDb(config: DbConfig | string, options?: CreateDbOptions): Promise<DB>;
|
package/dist/db/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,KAAK,SAAS,GAAG,UAAU,CAAC,cAAc,oBAAoB,EAAE,OAAO,CAAC,CAAC;AAEzE,KAAK,WAAW,GAAG,YAAY,CAAC,cAAc,YAAY,EAAE,QAAQ,CAAC,CAAC;AACtE,KAAK,YAAY,GAAG,OAAO,gBAAgB,EAAE,MAAM,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG;IAC5C,OAAO,EAAE,WAAW,GAAG,YAAY,CAAC;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAID,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,QAAQ,GAAG,MAAM,EACzB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,EAAE,CAAC,CA4Cb;AAsDD,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,EAAE,iBAE5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libsql-adapter.d.ts","sourceRoot":"","sources":["../../src/db/libsql-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE/C,wBAAsB,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,EAAE,CAAC,CAkDlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/db/utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,QAM3C"}
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,118 @@ var __export = (target, all) => {
|
|
|
27
27
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
28
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
29
|
|
|
30
|
+
// src/types.ts
|
|
31
|
+
var DEFAULT_CONFIG, KabanError, ExitCode;
|
|
32
|
+
var init_types = __esm(() => {
|
|
33
|
+
DEFAULT_CONFIG = {
|
|
34
|
+
board: {
|
|
35
|
+
name: "Kaban Board"
|
|
36
|
+
},
|
|
37
|
+
columns: [
|
|
38
|
+
{ id: "backlog", name: "Backlog" },
|
|
39
|
+
{ id: "todo", name: "Todo" },
|
|
40
|
+
{ id: "in_progress", name: "In Progress", wipLimit: 3 },
|
|
41
|
+
{ id: "review", name: "Review", wipLimit: 2 },
|
|
42
|
+
{ id: "done", name: "Done", isTerminal: true }
|
|
43
|
+
],
|
|
44
|
+
defaults: {
|
|
45
|
+
column: "todo",
|
|
46
|
+
agent: "user"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
KabanError = class KabanError extends Error {
|
|
50
|
+
code;
|
|
51
|
+
constructor(message, code) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.code = code;
|
|
54
|
+
this.name = "KabanError";
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
ExitCode = {
|
|
58
|
+
SUCCESS: 0,
|
|
59
|
+
GENERAL_ERROR: 1,
|
|
60
|
+
NOT_FOUND: 2,
|
|
61
|
+
CONFLICT: 3,
|
|
62
|
+
VALIDATION: 4
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/db/utils.ts
|
|
67
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
68
|
+
import { dirname } from "node:path";
|
|
69
|
+
import { fileURLToPath } from "node:url";
|
|
70
|
+
function fileUrlToPath(urlOrPath) {
|
|
71
|
+
if (!urlOrPath.startsWith("file:"))
|
|
72
|
+
return urlOrPath;
|
|
73
|
+
if (urlOrPath.startsWith("file:///") || urlOrPath.startsWith("file://localhost/")) {
|
|
74
|
+
return fileURLToPath(urlOrPath);
|
|
75
|
+
}
|
|
76
|
+
return urlOrPath.replace(/^file:/, "");
|
|
77
|
+
}
|
|
78
|
+
function ensureDbDir(filePath) {
|
|
79
|
+
if (filePath === ":memory:" || filePath.trim() === "")
|
|
80
|
+
return;
|
|
81
|
+
const dir = dirname(filePath);
|
|
82
|
+
if (!existsSync(dir)) {
|
|
83
|
+
mkdirSync(dir, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
var init_utils = () => {};
|
|
87
|
+
|
|
88
|
+
// src/db/schema.ts
|
|
89
|
+
var exports_schema = {};
|
|
90
|
+
__export(exports_schema, {
|
|
91
|
+
undoLog: () => undoLog,
|
|
92
|
+
tasks: () => tasks,
|
|
93
|
+
columns: () => columns,
|
|
94
|
+
boards: () => boards
|
|
95
|
+
});
|
|
96
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
97
|
+
var boards, columns, tasks, undoLog;
|
|
98
|
+
var init_schema = __esm(() => {
|
|
99
|
+
boards = sqliteTable("boards", {
|
|
100
|
+
id: text("id").primaryKey(),
|
|
101
|
+
name: text("name").notNull(),
|
|
102
|
+
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
|
|
103
|
+
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull()
|
|
104
|
+
});
|
|
105
|
+
columns = sqliteTable("columns", {
|
|
106
|
+
id: text("id").primaryKey(),
|
|
107
|
+
boardId: text("board_id").notNull().references(() => boards.id),
|
|
108
|
+
name: text("name").notNull(),
|
|
109
|
+
position: integer("position").notNull(),
|
|
110
|
+
wipLimit: integer("wip_limit"),
|
|
111
|
+
isTerminal: integer("is_terminal", { mode: "boolean" }).notNull().default(false)
|
|
112
|
+
});
|
|
113
|
+
tasks = sqliteTable("tasks", {
|
|
114
|
+
id: text("id").primaryKey(),
|
|
115
|
+
title: text("title").notNull(),
|
|
116
|
+
description: text("description"),
|
|
117
|
+
columnId: text("column_id").notNull().references(() => columns.id),
|
|
118
|
+
position: integer("position").notNull(),
|
|
119
|
+
createdBy: text("created_by").notNull(),
|
|
120
|
+
assignedTo: text("assigned_to"),
|
|
121
|
+
parentId: text("parent_id").references(() => tasks.id),
|
|
122
|
+
dependsOn: text("depends_on", { mode: "json" }).$type().notNull().default([]),
|
|
123
|
+
files: text("files", { mode: "json" }).$type().notNull().default([]),
|
|
124
|
+
labels: text("labels", { mode: "json" }).$type().notNull().default([]),
|
|
125
|
+
blockedReason: text("blocked_reason"),
|
|
126
|
+
version: integer("version").notNull().default(1),
|
|
127
|
+
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
|
|
128
|
+
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
|
|
129
|
+
startedAt: integer("started_at", { mode: "timestamp" }),
|
|
130
|
+
completedAt: integer("completed_at", { mode: "timestamp" }),
|
|
131
|
+
archived: integer("archived", { mode: "boolean" }).notNull().default(false),
|
|
132
|
+
archivedAt: integer("archived_at", { mode: "timestamp" })
|
|
133
|
+
});
|
|
134
|
+
undoLog = sqliteTable("undo_log", {
|
|
135
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
136
|
+
operation: text("operation").notNull(),
|
|
137
|
+
data: text("data", { mode: "json" }).notNull(),
|
|
138
|
+
createdAt: integer("created_at", { mode: "timestamp" }).notNull()
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
30
142
|
// drizzle/meta/_journal.json
|
|
31
143
|
var _journal_default;
|
|
32
144
|
var init__journal = __esm(() => {
|
|
@@ -120,8 +232,8 @@ __export(exports_migrator, {
|
|
|
120
232
|
runMigrations: () => runMigrations
|
|
121
233
|
});
|
|
122
234
|
import { readFileSync } from "node:fs";
|
|
123
|
-
import { dirname, isAbsolute, join } from "node:path";
|
|
124
|
-
import { fileURLToPath } from "node:url";
|
|
235
|
+
import { dirname as dirname2, isAbsolute, join } from "node:path";
|
|
236
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
125
237
|
function resolveSqlContent(sqlOrPath) {
|
|
126
238
|
if (sqlOrPath.includes("CREATE") || sqlOrPath.includes("INSERT") || sqlOrPath.includes("--")) {
|
|
127
239
|
return sqlOrPath;
|
|
@@ -235,141 +347,32 @@ var init_migrator = __esm(() => {
|
|
|
235
347
|
"0001_add_archived": _0001_add_archived_default,
|
|
236
348
|
"0002_add_fts5": _0002_add_fts5_default
|
|
237
349
|
};
|
|
238
|
-
__dirname2 =
|
|
350
|
+
__dirname2 = dirname2(fileURLToPath2(import.meta.url));
|
|
239
351
|
drizzleDir = join(__dirname2, "..", "..", "drizzle");
|
|
240
352
|
});
|
|
241
353
|
|
|
242
|
-
// src/db/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// src/types.ts
|
|
248
|
-
var DEFAULT_CONFIG = {
|
|
249
|
-
board: {
|
|
250
|
-
name: "Kaban Board"
|
|
251
|
-
},
|
|
252
|
-
columns: [
|
|
253
|
-
{ id: "backlog", name: "Backlog" },
|
|
254
|
-
{ id: "todo", name: "Todo" },
|
|
255
|
-
{ id: "in_progress", name: "In Progress", wipLimit: 3 },
|
|
256
|
-
{ id: "review", name: "Review", wipLimit: 2 },
|
|
257
|
-
{ id: "done", name: "Done", isTerminal: true }
|
|
258
|
-
],
|
|
259
|
-
defaults: {
|
|
260
|
-
column: "todo",
|
|
261
|
-
agent: "user"
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
class KabanError extends Error {
|
|
266
|
-
code;
|
|
267
|
-
constructor(message, code) {
|
|
268
|
-
super(message);
|
|
269
|
-
this.code = code;
|
|
270
|
-
this.name = "KabanError";
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
var ExitCode = {
|
|
274
|
-
SUCCESS: 0,
|
|
275
|
-
GENERAL_ERROR: 1,
|
|
276
|
-
NOT_FOUND: 2,
|
|
277
|
-
CONFLICT: 3,
|
|
278
|
-
VALIDATION: 4
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
// src/db/schema.ts
|
|
282
|
-
var exports_schema = {};
|
|
283
|
-
__export(exports_schema, {
|
|
284
|
-
undoLog: () => undoLog,
|
|
285
|
-
tasks: () => tasks,
|
|
286
|
-
columns: () => columns,
|
|
287
|
-
boards: () => boards
|
|
288
|
-
});
|
|
289
|
-
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
290
|
-
var boards = sqliteTable("boards", {
|
|
291
|
-
id: text("id").primaryKey(),
|
|
292
|
-
name: text("name").notNull(),
|
|
293
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
|
|
294
|
-
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull()
|
|
295
|
-
});
|
|
296
|
-
var columns = sqliteTable("columns", {
|
|
297
|
-
id: text("id").primaryKey(),
|
|
298
|
-
boardId: text("board_id").notNull().references(() => boards.id),
|
|
299
|
-
name: text("name").notNull(),
|
|
300
|
-
position: integer("position").notNull(),
|
|
301
|
-
wipLimit: integer("wip_limit"),
|
|
302
|
-
isTerminal: integer("is_terminal", { mode: "boolean" }).notNull().default(false)
|
|
354
|
+
// src/db/libsql-adapter.ts
|
|
355
|
+
var exports_libsql_adapter = {};
|
|
356
|
+
__export(exports_libsql_adapter, {
|
|
357
|
+
createLibsqlDb: () => createLibsqlDb
|
|
303
358
|
});
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
title: text("title").notNull(),
|
|
307
|
-
description: text("description"),
|
|
308
|
-
columnId: text("column_id").notNull().references(() => columns.id),
|
|
309
|
-
position: integer("position").notNull(),
|
|
310
|
-
createdBy: text("created_by").notNull(),
|
|
311
|
-
assignedTo: text("assigned_to"),
|
|
312
|
-
parentId: text("parent_id").references(() => tasks.id),
|
|
313
|
-
dependsOn: text("depends_on", { mode: "json" }).$type().notNull().default([]),
|
|
314
|
-
files: text("files", { mode: "json" }).$type().notNull().default([]),
|
|
315
|
-
labels: text("labels", { mode: "json" }).$type().notNull().default([]),
|
|
316
|
-
blockedReason: text("blocked_reason"),
|
|
317
|
-
version: integer("version").notNull().default(1),
|
|
318
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull(),
|
|
319
|
-
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull(),
|
|
320
|
-
startedAt: integer("started_at", { mode: "timestamp" }),
|
|
321
|
-
completedAt: integer("completed_at", { mode: "timestamp" }),
|
|
322
|
-
archived: integer("archived", { mode: "boolean" }).notNull().default(false),
|
|
323
|
-
archivedAt: integer("archived_at", { mode: "timestamp" })
|
|
324
|
-
});
|
|
325
|
-
var undoLog = sqliteTable("undo_log", {
|
|
326
|
-
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
327
|
-
operation: text("operation").notNull(),
|
|
328
|
-
data: text("data", { mode: "json" }).notNull(),
|
|
329
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull()
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
// src/db/index.ts
|
|
333
|
-
init_migrator();
|
|
334
|
-
var isBun = typeof globalThis.Bun !== "undefined" && typeof globalThis.Bun.version === "string";
|
|
335
|
-
function fileUrlToPath(urlOrPath) {
|
|
336
|
-
if (!urlOrPath.startsWith("file:"))
|
|
337
|
-
return urlOrPath;
|
|
338
|
-
if (urlOrPath.startsWith("file:///") || urlOrPath.startsWith("file://localhost/")) {
|
|
339
|
-
return fileURLToPath2(urlOrPath);
|
|
340
|
-
}
|
|
341
|
-
return urlOrPath.replace(/^file:/, "");
|
|
342
|
-
}
|
|
343
|
-
function ensureDbDir(filePath) {
|
|
344
|
-
if (filePath === ":memory:" || filePath.trim() === "")
|
|
345
|
-
return;
|
|
346
|
-
const dir = dirname2(filePath);
|
|
347
|
-
if (!existsSync(dir)) {
|
|
348
|
-
mkdirSync(dir, { recursive: true });
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async function createBunDb(filePath) {
|
|
352
|
-
let sqlite;
|
|
359
|
+
async function createLibsqlDb(config) {
|
|
360
|
+
let client;
|
|
353
361
|
try {
|
|
354
|
-
const {
|
|
355
|
-
const { drizzle } = await import("drizzle-orm/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
362
|
+
const { createClient } = await import("@libsql/client");
|
|
363
|
+
const { drizzle } = await import("drizzle-orm/libsql");
|
|
364
|
+
if (config.url.startsWith("file:")) {
|
|
365
|
+
ensureDbDir(fileUrlToPath(config.url));
|
|
366
|
+
}
|
|
367
|
+
client = createClient(config);
|
|
368
|
+
const db = drizzle(client, { schema: exports_schema });
|
|
359
369
|
let closed = false;
|
|
360
|
-
const
|
|
370
|
+
const clientRef = client;
|
|
361
371
|
return Object.assign(db, {
|
|
362
|
-
$client:
|
|
372
|
+
$client: clientRef,
|
|
363
373
|
$runRaw: async (sql) => {
|
|
364
374
|
try {
|
|
365
|
-
|
|
366
|
-
sqliteRef.exec(sql);
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
const statements = sql.split(";").filter((s) => s.trim());
|
|
370
|
-
for (const stmt of statements) {
|
|
371
|
-
sqliteRef.run(stmt);
|
|
372
|
-
}
|
|
375
|
+
await clientRef.executeMultiple(sql);
|
|
373
376
|
} catch (error) {
|
|
374
377
|
throw new KabanError(`SQL execution failed: ${error instanceof Error ? error.message : String(error)}`, ExitCode.GENERAL_ERROR);
|
|
375
378
|
}
|
|
@@ -379,36 +382,52 @@ async function createBunDb(filePath) {
|
|
|
379
382
|
return;
|
|
380
383
|
closed = true;
|
|
381
384
|
try {
|
|
382
|
-
|
|
385
|
+
clientRef.close();
|
|
383
386
|
} catch {}
|
|
384
387
|
}
|
|
385
388
|
});
|
|
386
389
|
} catch (error) {
|
|
387
390
|
try {
|
|
388
|
-
|
|
391
|
+
client?.close?.();
|
|
389
392
|
} catch {}
|
|
390
393
|
if (error instanceof KabanError)
|
|
391
394
|
throw error;
|
|
392
|
-
throw new KabanError(`Failed to create
|
|
395
|
+
throw new KabanError(`Failed to create libsql database: ${error instanceof Error ? error.message : String(error)}`, ExitCode.GENERAL_ERROR);
|
|
393
396
|
}
|
|
394
397
|
}
|
|
395
|
-
|
|
396
|
-
|
|
398
|
+
var init_libsql_adapter = __esm(() => {
|
|
399
|
+
init_types();
|
|
400
|
+
init_schema();
|
|
401
|
+
init_utils();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// src/db/bun-adapter.ts
|
|
405
|
+
var exports_bun_adapter = {};
|
|
406
|
+
__export(exports_bun_adapter, {
|
|
407
|
+
createBunDb: () => createBunDb
|
|
408
|
+
});
|
|
409
|
+
async function createBunDb(filePath) {
|
|
410
|
+
let sqlite;
|
|
397
411
|
try {
|
|
398
|
-
const {
|
|
399
|
-
const { drizzle } = await import("drizzle-orm/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
client = createClient(config);
|
|
404
|
-
const db = drizzle(client, { schema: exports_schema });
|
|
412
|
+
const { Database } = await import("bun:sqlite");
|
|
413
|
+
const { drizzle } = await import("drizzle-orm/bun-sqlite");
|
|
414
|
+
ensureDbDir(filePath);
|
|
415
|
+
sqlite = new Database(filePath);
|
|
416
|
+
const db = drizzle({ client: sqlite, schema: exports_schema });
|
|
405
417
|
let closed = false;
|
|
406
|
-
const
|
|
418
|
+
const sqliteRef = sqlite;
|
|
407
419
|
return Object.assign(db, {
|
|
408
|
-
$client:
|
|
420
|
+
$client: sqliteRef,
|
|
409
421
|
$runRaw: async (sql) => {
|
|
410
422
|
try {
|
|
411
|
-
|
|
423
|
+
if (typeof sqliteRef.exec === "function") {
|
|
424
|
+
sqliteRef.exec(sql);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const statements = sql.split(";").filter((s) => s.trim());
|
|
428
|
+
for (const stmt of statements) {
|
|
429
|
+
sqliteRef.run(stmt);
|
|
430
|
+
}
|
|
412
431
|
} catch (error) {
|
|
413
432
|
throw new KabanError(`SQL execution failed: ${error instanceof Error ? error.message : String(error)}`, ExitCode.GENERAL_ERROR);
|
|
414
433
|
}
|
|
@@ -418,19 +437,31 @@ async function createLibsqlDb(config) {
|
|
|
418
437
|
return;
|
|
419
438
|
closed = true;
|
|
420
439
|
try {
|
|
421
|
-
|
|
440
|
+
sqliteRef.close();
|
|
422
441
|
} catch {}
|
|
423
442
|
}
|
|
424
443
|
});
|
|
425
444
|
} catch (error) {
|
|
426
445
|
try {
|
|
427
|
-
|
|
446
|
+
sqlite?.close?.();
|
|
428
447
|
} catch {}
|
|
429
448
|
if (error instanceof KabanError)
|
|
430
449
|
throw error;
|
|
431
|
-
throw new KabanError(`Failed to create
|
|
450
|
+
throw new KabanError(`Failed to create Bun database: ${error instanceof Error ? error.message : String(error)}`, ExitCode.GENERAL_ERROR);
|
|
432
451
|
}
|
|
433
452
|
}
|
|
453
|
+
var init_bun_adapter = __esm(() => {
|
|
454
|
+
init_types();
|
|
455
|
+
init_schema();
|
|
456
|
+
init_utils();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// src/db/index.ts
|
|
460
|
+
init_types();
|
|
461
|
+
init_utils();
|
|
462
|
+
init_migrator();
|
|
463
|
+
init_schema();
|
|
464
|
+
var isBun = typeof globalThis.Bun !== "undefined" && typeof globalThis.Bun.version === "string";
|
|
434
465
|
async function createDb(config, options = {}) {
|
|
435
466
|
const { migrate = true } = options;
|
|
436
467
|
try {
|
|
@@ -440,18 +471,24 @@ async function createDb(config, options = {}) {
|
|
|
440
471
|
const forceLibsql = driver === "libsql";
|
|
441
472
|
if (typeof config === "string") {
|
|
442
473
|
if (forceLibsql) {
|
|
443
|
-
|
|
474
|
+
const { createLibsqlDb: createLibsqlDb2 } = await Promise.resolve().then(() => (init_libsql_adapter(), exports_libsql_adapter));
|
|
475
|
+
db = await createLibsqlDb2({ url: `file:${config}` });
|
|
444
476
|
} else if (preferBun) {
|
|
445
|
-
|
|
477
|
+
const { createBunDb: createBunDb2 } = await Promise.resolve().then(() => (init_bun_adapter(), exports_bun_adapter));
|
|
478
|
+
db = await createBunDb2(config);
|
|
446
479
|
} else {
|
|
447
|
-
|
|
480
|
+
const { createLibsqlDb: createLibsqlDb2 } = await Promise.resolve().then(() => (init_libsql_adapter(), exports_libsql_adapter));
|
|
481
|
+
db = await createLibsqlDb2({ url: `file:${config}` });
|
|
448
482
|
}
|
|
449
483
|
} else if (forceLibsql) {
|
|
450
|
-
|
|
484
|
+
const { createLibsqlDb: createLibsqlDb2 } = await Promise.resolve().then(() => (init_libsql_adapter(), exports_libsql_adapter));
|
|
485
|
+
db = await createLibsqlDb2(config);
|
|
451
486
|
} else if (preferBun && config.url.startsWith("file:")) {
|
|
452
|
-
|
|
487
|
+
const { createBunDb: createBunDb2 } = await Promise.resolve().then(() => (init_bun_adapter(), exports_bun_adapter));
|
|
488
|
+
db = await createBunDb2(fileUrlToPath(config.url));
|
|
453
489
|
} else {
|
|
454
|
-
|
|
490
|
+
const { createLibsqlDb: createLibsqlDb2 } = await Promise.resolve().then(() => (init_libsql_adapter(), exports_libsql_adapter));
|
|
491
|
+
db = await createLibsqlDb2(config);
|
|
455
492
|
}
|
|
456
493
|
if (migrate) {
|
|
457
494
|
const { runMigrations: runMigrations2 } = await Promise.resolve().then(() => (init_migrator(), exports_migrator));
|
|
@@ -755,6 +792,7 @@ class BoardService {
|
|
|
755
792
|
// src/services/task.ts
|
|
756
793
|
import { and, eq as eq2, inArray, lt, sql } from "drizzle-orm";
|
|
757
794
|
import { ulid as ulid2 } from "ulid";
|
|
795
|
+
init_types();
|
|
758
796
|
|
|
759
797
|
// src/utils/similarity.ts
|
|
760
798
|
function tokenize(text2) {
|
|
@@ -774,6 +812,7 @@ function jaccardSimilarity(text1, text2) {
|
|
|
774
812
|
|
|
775
813
|
// src/validation.ts
|
|
776
814
|
import { ZodError } from "zod";
|
|
815
|
+
init_types();
|
|
777
816
|
function wrapZodError(fn, fieldName) {
|
|
778
817
|
try {
|
|
779
818
|
return fn();
|
|
@@ -1184,6 +1223,9 @@ class TaskService {
|
|
|
1184
1223
|
};
|
|
1185
1224
|
}
|
|
1186
1225
|
}
|
|
1226
|
+
|
|
1227
|
+
// src/index.ts
|
|
1228
|
+
init_types();
|
|
1187
1229
|
export {
|
|
1188
1230
|
validateTitle,
|
|
1189
1231
|
validateTaskId,
|