aiex-cli 0.0.1-beta.31 → 0.0.1-beta.32

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/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as doctorDiagnosticsTableRows, _ as seedConfig, a as parseJsonSchema, b as package_default, c as getDefaultAIConfig, d as DEFAULT_MINERU_CONFIG, f as DEFAULT_PROMPT_CONFIG, g as createConfig, h as AIConfigSchema, i as JsonSchemaDefinitionSchema, l as readAIConfig, m as PLACEHOLDER_TEXT, n as createMigrationConfig, o as toSnakeCase, p as PLACEHOLDER_SCHEMA, s as generateDrizzleSchema, t as collectDoctorDiagnostics, u as writeAIConfig, v as description, w as formatDoctorDiagnosticsJson, x as version, y as name } from "./doctor-collector-DV8HNWO6.mjs";
1
+ import { C as doctorDiagnosticsTableRows, _ as seedConfig, a as parseJsonSchema, b as package_default, c as getDefaultAIConfig, d as DEFAULT_MINERU_CONFIG, f as DEFAULT_PROMPT_CONFIG, g as createConfig, h as AIConfigSchema, i as JsonSchemaDefinitionSchema, l as readAIConfig, m as PLACEHOLDER_TEXT, n as createMigrationConfig, o as toSnakeCase, p as PLACEHOLDER_SCHEMA, s as generateDrizzleSchema, t as collectDoctorDiagnostics, u as writeAIConfig, v as description, w as formatDoctorDiagnosticsJson, x as version, y as name } from "./doctor-collector-Dspt9g6R.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import fs from "node:fs/promises";
4
4
  import os from "node:os";
@@ -34,6 +34,7 @@ import { serveStatic } from "@hono/node-server/serve-static";
34
34
  import { Hono } from "hono";
35
35
  import { cors } from "hono/cors";
36
36
  import { zValidator } from "@hono/zod-validator";
37
+ import { Kysely, SqliteDialect, sql } from "kysely";
37
38
 
38
39
  //#region src/core/schema-sqlite/helpers.ts
39
40
  const __filename = fileURLToPath(import.meta.url);
@@ -13277,8 +13278,8 @@ function buildInsertSql(table, data) {
13277
13278
  function insertTableRow({ db, table, data, parentRowId, foreignKeyColumn }) {
13278
13279
  const rowData = { ...data };
13279
13280
  if (parentRowId !== void 0 && foreignKeyColumn) rowData[foreignKeyColumn] = parentRowId;
13280
- const { sql, values } = buildInsertSql(table, rowData);
13281
- const info = db.prepare(sql).run(...values);
13281
+ const { sql: sql$1, values } = buildInsertSql(table, rowData);
13282
+ const info = db.prepare(sql$1).run(...values);
13282
13283
  return Number(info.lastInsertRowid);
13283
13284
  }
13284
13285
  function parseDataByColumns(data, schema, table) {
@@ -14223,6 +14224,9 @@ function invalidParamResponse$1(message) {
14223
14224
  if (!result.success) return c.json({ error: message }, 400);
14224
14225
  };
14225
14226
  }
14227
+ function createReadonlyQueryDb(databasePath) {
14228
+ return new Kysely({ dialect: new SqliteDialect({ database: new Database(databasePath, { readonly: true }) }) });
14229
+ }
14226
14230
  function dataRoutes(config) {
14227
14231
  const app = new Hono();
14228
14232
  const aiexDir = path.dirname(config.schemaPath);
@@ -14270,10 +14274,15 @@ function dataRoutes(config) {
14270
14274
  let db = null;
14271
14275
  let dbTables = [];
14272
14276
  try {
14273
- db = new Database(config.databasePath, { readonly: true });
14274
- dbTables = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_%' ORDER BY name`).all().map((r) => r.name);
14277
+ db = createReadonlyQueryDb(config.databasePath);
14278
+ dbTables = (await sql`
14279
+ select name
14280
+ from sqlite_master
14281
+ where type = 'table' and name not like 'sqlite_%' and name not like '_%'
14282
+ order by name
14283
+ `.execute(db)).rows.map((row) => row.name);
14275
14284
  } catch {} finally {
14276
- db?.close();
14285
+ await db?.destroy();
14277
14286
  }
14278
14287
  const tables = [];
14279
14288
  for (const file of schemaFiles) try {
@@ -14298,36 +14307,46 @@ function dataRoutes(config) {
14298
14307
  const { page, pageSize, search, sortField, sortOrder } = c.req.valid("query");
14299
14308
  let db;
14300
14309
  try {
14301
- db = new Database(config.databasePath, { readonly: true });
14310
+ db = createReadonlyQueryDb(config.databasePath);
14302
14311
  } catch {
14303
14312
  return c.json({ error: "Database not found. Run `aiex schema` first." }, 400);
14304
14313
  }
14305
14314
  try {
14306
- if (!db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name=?`).get(tableName)) {
14307
- db.close();
14308
- return c.json({ error: `Table "${tableName}" not found in database` }, 404);
14309
- }
14310
- const columns = db.prepare(`PRAGMA table_info(\`${tableName}\`)`).all().map((col) => ({
14315
+ if ((await sql`
14316
+ select name
14317
+ from sqlite_master
14318
+ where type = 'table' and name = ${tableName}
14319
+ `.execute(db)).rows.length === 0) return c.json({ error: `Table "${tableName}" not found in database` }, 404);
14320
+ const columns = (await sql`
14321
+ pragma table_info(${sql.table(tableName)})
14322
+ `.execute(db)).rows.map((col) => ({
14311
14323
  name: col.name,
14312
14324
  type: col.type,
14313
14325
  notNull: !!col.notnull,
14314
14326
  pk: !!col.pk
14315
14327
  }));
14316
- let orderClause = "";
14317
- if (sortField && columns.some((c$1) => c$1.name === sortField)) orderClause = ` ORDER BY \`${sortField}\` ${sortOrder === "desc" ? "DESC" : "ASC"}`;
14318
- let whereClause = "";
14319
- const queryParams = [];
14320
- if (search) whereClause = ` WHERE ${columns.map((col) => {
14321
- queryParams.push(`%${search}%`);
14322
- return `\`${col.name}\` LIKE ?`;
14323
- }).join(" OR ")}`;
14324
- const total = db.prepare(`SELECT COUNT(*) as count FROM \`${tableName}\`${whereClause}`).get(...queryParams).count;
14328
+ const searchConditions = columns.map((col) => sql`${sql.ref(col.name)} like ${`%${search}%`}`);
14329
+ const searchCondition = search ? sql`where ${sql.join(searchConditions, sql` or `)}` : sql``;
14330
+ const sortColumn = columns.find((col) => col.name === sortField);
14331
+ const orderBy = sortColumn ? sql`order by ${sql.ref(sortColumn.name)} ${sql.raw(sortOrder === "desc" ? "desc" : "asc")}` : sql``;
14332
+ const total = (await sql`
14333
+ select count(*) as count
14334
+ from ${sql.table(tableName)}
14335
+ ${searchCondition}
14336
+ `.execute(db)).rows[0]?.count ?? 0;
14325
14337
  const offset = (page - 1) * pageSize;
14326
14338
  const totalPages = Math.max(1, Math.ceil(total / pageSize));
14327
- const rows = db.prepare(`SELECT * FROM \`${tableName}\`${whereClause}${orderClause} LIMIT ? OFFSET ?`).all(...queryParams, pageSize, offset);
14339
+ const result = await sql`
14340
+ select *
14341
+ from ${sql.table(tableName)}
14342
+ ${searchCondition}
14343
+ ${orderBy}
14344
+ limit ${pageSize}
14345
+ offset ${offset}
14346
+ `.execute(db);
14328
14347
  return c.json({
14329
14348
  columns,
14330
- rows,
14349
+ rows: result.rows,
14331
14350
  total,
14332
14351
  page,
14333
14352
  pageSize,
@@ -14336,7 +14355,7 @@ function dataRoutes(config) {
14336
14355
  } catch (error) {
14337
14356
  return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
14338
14357
  } finally {
14339
- db.close();
14358
+ await db.destroy();
14340
14359
  }
14341
14360
  });
14342
14361
  app.get("/data/:name", zValidator("param", extractionFileParamSchema, invalidParamResponse$1("Invalid extraction file name")), async (c) => {
@@ -65,7 +65,7 @@ function doctorDiagnosticsTableRows(d) {
65
65
  //#endregion
66
66
  //#region package.json
67
67
  var name = "aiex-cli";
68
- var version = "0.0.1-beta.31";
68
+ var version = "0.0.1-beta.32";
69
69
  var description = "JSON Schema → SQLite with AI-powered data extraction";
70
70
  var package_default = {
71
71
  name,
@@ -143,6 +143,7 @@ var package_default = {
143
143
  "hono": "catalog:",
144
144
  "jsonfile": "catalog:",
145
145
  "jsonrepair": "catalog:",
146
+ "kysely": "catalog:",
146
147
  "mime": "catalog:",
147
148
  "open": "catalog:",
148
149
  "p-retry": "catalog:",
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { C as doctorDiagnosticsTableRows, S as buildDoctorDiagnostics, a as parseJsonSchema, i as JsonSchemaDefinitionSchema, n as createMigrationConfig, r as generateDrizzleConfig, s as generateDrizzleSchema, t as collectDoctorDiagnostics, w as formatDoctorDiagnosticsJson } from "./doctor-collector-DV8HNWO6.mjs";
1
+ import { C as doctorDiagnosticsTableRows, S as buildDoctorDiagnostics, a as parseJsonSchema, i as JsonSchemaDefinitionSchema, n as createMigrationConfig, r as generateDrizzleConfig, s as generateDrizzleSchema, t as collectDoctorDiagnostics, w as formatDoctorDiagnosticsJson } from "./doctor-collector-Dspt9g6R.mjs";
2
2
 
3
3
  export { JsonSchemaDefinitionSchema, buildDoctorDiagnostics, collectDoctorDiagnostics, createMigrationConfig, doctorDiagnosticsTableRows, formatDoctorDiagnosticsJson, generateDrizzleConfig, generateDrizzleSchema, parseJsonSchema };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aiex-cli",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.31",
4
+ "version": "0.0.1-beta.32",
5
5
  "description": "JSON Schema → SQLite with AI-powered data extraction",
6
6
  "author": "OSpoon <zxin088@gmail.com>",
7
7
  "license": "MIT",
@@ -64,6 +64,7 @@
64
64
  "hono": "^4.0.0",
65
65
  "jsonfile": "^6.2.1",
66
66
  "jsonrepair": "^3.14.0",
67
+ "kysely": "^0.29.2",
67
68
  "mime": "^4.1.0",
68
69
  "open": "^11.0.0",
69
70
  "p-retry": "^7.1.0",