aiex-cli 0.0.2-beta.9 → 0.0.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/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { S as version, T as formatDoctorDiagnosticsJson, _ as createConfig, a as parseJsonSchema, b as name, c as getDefaultAIConfig, d as DEFAULT_MARKITDOWN_CONFIG, f as DEFAULT_MINERU_CONFIG, g as AIConfigSchema, h as PLACEHOLDER_TEXT, i as JsonSchemaDefinitionSchema, l as readAIConfig, m as PLACEHOLDER_SCHEMA, n as createMigrationConfig, o as toSnakeCase, p as DEFAULT_PROMPT_CONFIG, s as generateDrizzleSchema, t as collectDoctorDiagnostics, u as writeAIConfig, v as seedConfig, w as doctorDiagnosticsTableRows, x as package_default, y as description } from "./doctor-collector-Cb9X2mxU.mjs";
1
+ import { S as version, T as formatDoctorDiagnosticsJson, _ as createConfig, a as parseJsonSchema, b as name, c as getDefaultAIConfig, d as DEFAULT_MARKITDOWN_CONFIG, f as DEFAULT_MINERU_CONFIG, g as AIConfigSchema, h as PLACEHOLDER_TEXT, i as JsonSchemaDefinitionSchema, l as readAIConfig, m as PLACEHOLDER_SCHEMA, n as createMigrationConfig, o as toSnakeCase, p as DEFAULT_PROMPT_CONFIG, s as generateDrizzleSchema, t as collectDoctorDiagnostics, u as writeAIConfig, v as seedConfig, w as doctorDiagnosticsTableRows, x as package_default, y as description } from "./doctor-collector-DR7s0UUh.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import fs from "node:fs/promises";
4
4
  import os from "node:os";
@@ -14964,6 +14964,7 @@ function aiRoutes(config) {
14964
14964
  //#region src/server/routes/data.ts
14965
14965
  const FILE_REGEX = /\.json$/;
14966
14966
  const EXTRACTION_TIMESTAMP_RE = /-\d{4}-\d{2}-\d{2}T/;
14967
+ const INTERNAL_ROWID_COLUMN = "__aiex_rowid";
14967
14968
  const TIMESTAMP_CLEANUP = /(\d{2})-(\d{2})-(\d{2})/;
14968
14969
  const TIMESTAMP_TZ = /(\d{3})Z/;
14969
14970
  const tableParamSchema = z.object({ name: z.string().regex(/^[a-z][a-z0-9_]*$/) });
@@ -14980,6 +14981,31 @@ function invalidParamResponse$1(message) {
14980
14981
  if (!result.success) return c.json({ error: message }, 400);
14981
14982
  };
14982
14983
  }
14984
+ function getAuditNotionStatus(record) {
14985
+ if (record.notionPages?.length) return "synced";
14986
+ if (record.status === "failed") return "failed";
14987
+ return "not_synced";
14988
+ }
14989
+ async function getRowExtractionActions(aiexDir, tableName) {
14990
+ const actions = /* @__PURE__ */ new Map();
14991
+ const auditRecords = await listExtractionAuditRecords(aiexDir);
14992
+ for (const record of auditRecords) {
14993
+ if (!record.outputName) continue;
14994
+ for (const inserted of record.tablesInserted ?? []) {
14995
+ if (inserted.table !== tableName) continue;
14996
+ const key = String(inserted.rowId);
14997
+ if (actions.has(key)) continue;
14998
+ const notionPages = record.notionPages?.length ? record.notionPages : void 0;
14999
+ actions.set(key, {
15000
+ extractionName: record.outputName,
15001
+ notionStatus: getAuditNotionStatus(record),
15002
+ notionPages,
15003
+ notionError: !notionPages && record.status === "failed" ? record.error : void 0
15004
+ });
15005
+ }
15006
+ }
15007
+ return actions;
15008
+ }
14983
15009
  function schemaNameFromExtractionFile(name$1) {
14984
15010
  const stem = name$1.replace(FILE_REGEX, "");
14985
15011
  const match = stem.match(EXTRACTION_TIMESTAMP_RE);
@@ -14997,22 +15023,27 @@ function dataRoutes(config) {
14997
15023
  try {
14998
15024
  await fs.mkdir(extractedDir, { recursive: true });
14999
15025
  const jsonFiles = (await fs.readdir(extractedDir)).filter((f) => f.endsWith(".json") && !f.endsWith(".prompt.md"));
15026
+ const auditRecords = await listExtractionAuditRecords(aiexDir);
15027
+ const auditByOutputName = new Map(auditRecords.map((record) => [record.outputName, record]));
15000
15028
  const records = [];
15001
15029
  for (const file of jsonFiles) {
15002
- const name$1 = file.replace(FILE_REGEX, "");
15003
- const idx = name$1.lastIndexOf("-");
15004
- if (idx === -1) continue;
15005
- const schemaName = name$1.slice(0, idx);
15006
- const timestamp = name$1.slice(idx + 1).replace(/-/g, (d, i) => i === 4 || i === 7 ? "-" : d).replace(TIMESTAMP_CLEANUP, (_, h, m, s) => `${h}:${m}:${s}`).replace(TIMESTAMP_TZ, ".$1Z");
15030
+ const schemaName = schemaNameFromExtractionFile(file);
15031
+ if (!schemaName) continue;
15032
+ const timestamp = file.replace(FILE_REGEX, "").slice(schemaName.length + 1).replace(/-/g, (d, i) => i === 4 || i === 7 ? "-" : d).replace(TIMESTAMP_CLEANUP, (_, h, m, s) => `${h}:${m}:${s}`).replace(TIMESTAMP_TZ, ".$1Z");
15007
15033
  const filePath = path.join(extractedDir, file);
15008
15034
  try {
15009
15035
  const stat = await fs.stat(filePath);
15036
+ const audit = auditByOutputName.get(file);
15037
+ const notionPages = audit?.notionPages?.length ? audit.notionPages : void 0;
15010
15038
  records.push({
15011
15039
  name: file,
15012
15040
  schemaName,
15013
15041
  timestamp,
15014
15042
  fileSize: stat.size,
15015
- modifiedAt: stat.mtime.toISOString()
15043
+ modifiedAt: stat.mtime.toISOString(),
15044
+ notionStatus: notionPages ? "synced" : audit?.status === "failed" ? "failed" : "not_synced",
15045
+ notionPages,
15046
+ notionError: !notionPages && audit?.status === "failed" ? audit.error : void 0
15016
15047
  });
15017
15048
  } catch {
15018
15049
  continue;
@@ -15099,16 +15130,24 @@ function dataRoutes(config) {
15099
15130
  const offset = (page - 1) * pageSize;
15100
15131
  const totalPages = Math.max(1, Math.ceil(total / pageSize));
15101
15132
  const result = await sql`
15102
- select *
15133
+ select rowid as ${sql.raw(INTERNAL_ROWID_COLUMN)}, *
15103
15134
  from ${sql.table(tableName)}
15104
15135
  ${searchCondition}
15105
15136
  ${orderBy}
15106
15137
  limit ${pageSize}
15107
15138
  offset ${offset}
15108
15139
  `.execute(db);
15140
+ const actionsByRowId = await getRowExtractionActions(aiexDir, tableName);
15141
+ const rowActions = Object.fromEntries(result.rows.map((row, index) => {
15142
+ const rowId = row[INTERNAL_ROWID_COLUMN];
15143
+ const action = rowId === null || rowId === void 0 ? void 0 : actionsByRowId.get(String(rowId));
15144
+ return action ? [String(index), action] : null;
15145
+ }).filter((entry) => !!entry));
15146
+ const rows = result.rows.map(({ [INTERNAL_ROWID_COLUMN]: _rowid, ...row }) => row);
15109
15147
  return c.json({
15110
15148
  columns,
15111
- rows: result.rows,
15149
+ rows,
15150
+ rowActions,
15112
15151
  total,
15113
15152
  page,
15114
15153
  pageSize,
@@ -15162,9 +15201,19 @@ function dataRoutes(config) {
15162
15201
  databaseId: page.databaseId,
15163
15202
  pageId: page.pageId
15164
15203
  }];
15165
- const record = (await listExtractionAuditRecords(aiexDir)).find((record$1) => record$1.outputName === name$1);
15204
+ let record = (await listExtractionAuditRecords(aiexDir)).find((record$1) => record$1.outputName === name$1);
15205
+ if (!record) record = await createExtractionAuditRecord(aiexDir, {
15206
+ schemaName,
15207
+ source: {
15208
+ type: "file",
15209
+ filePath,
15210
+ fileName: name$1
15211
+ }
15212
+ });
15166
15213
  if (record) await updateExtractionAuditRecord(aiexDir, record.id, {
15167
15214
  status: "succeeded",
15215
+ outputPath: filePath,
15216
+ outputName: name$1,
15168
15217
  notionPages,
15169
15218
  error: void 0
15170
15219
  });
@@ -15173,9 +15222,17 @@ function dataRoutes(config) {
15173
15222
  notionPages
15174
15223
  });
15175
15224
  } catch (error) {
15225
+ const message = error instanceof Error ? error.message : String(error);
15226
+ const record = (await listExtractionAuditRecords(aiexDir)).find((record$1) => record$1.outputName === name$1);
15227
+ if (record) await updateExtractionAuditRecord(aiexDir, record.id, {
15228
+ status: "failed",
15229
+ outputPath: filePath,
15230
+ outputName: name$1,
15231
+ error: message
15232
+ });
15176
15233
  return c.json({
15177
15234
  success: false,
15178
- error: error instanceof Error ? error.message : String(error)
15235
+ error: message
15179
15236
  }, 500);
15180
15237
  }
15181
15238
  });
@@ -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.2-beta.9";
68
+ var version = "0.0.2";
69
69
  var description = "JSON Schema → SQLite with AI-powered data extraction";
70
70
  var package_default = {
71
71
  name,
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { C as buildDoctorDiagnostics, T as formatDoctorDiagnosticsJson, a as parseJsonSchema, i as JsonSchemaDefinitionSchema, n as createMigrationConfig, r as generateDrizzleConfig, s as generateDrizzleSchema, t as collectDoctorDiagnostics, w as doctorDiagnosticsTableRows } from "./doctor-collector-Cb9X2mxU.mjs";
1
+ import { C as buildDoctorDiagnostics, T as formatDoctorDiagnosticsJson, a as parseJsonSchema, i as JsonSchemaDefinitionSchema, n as createMigrationConfig, r as generateDrizzleConfig, s as generateDrizzleSchema, t as collectDoctorDiagnostics, w as doctorDiagnosticsTableRows } from "./doctor-collector-DR7s0UUh.mjs";
2
2
 
3
3
  export { JsonSchemaDefinitionSchema, buildDoctorDiagnostics, collectDoctorDiagnostics, createMigrationConfig, doctorDiagnosticsTableRows, formatDoctorDiagnosticsJson, generateDrizzleConfig, generateDrizzleSchema, parseJsonSchema };