@toiroakr/lines-db 0.4.0 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @toiroakr/lines-db
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1d60d66: feat: support directory for migration
8
+
9
+ ## 0.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - b281dc8: Fix constraint validation in validator to properly detect primary key and unique index violations
14
+
15
+ Previously, the validator was not creating indexes from schema metadata and was missing the default primaryKey behavior, causing constraint violations to go undetected. This fix ensures:
16
+ - Indexes (both unique and non-unique) are now properly created from schema metadata in the validation database
17
+ - Primary key defaults to 'id' column when not explicitly specified, matching database.ts behavior
18
+ - Constraint violations are properly detected by inserting rows into an in-memory database and catching SQLite exceptions
19
+ - Detailed error information is extracted from SQLite error messages for better diagnostics
20
+
21
+ Added comprehensive regression tests to prevent this issue from recurring.
22
+
3
23
  ## 0.4.0
4
24
 
5
25
  ### Minor Changes
package/bin/cli.js CHANGED
@@ -1041,37 +1041,48 @@ var Validator = class {
1041
1041
  };
1042
1042
  }
1043
1043
  /**
1044
- * Validate by loading data into an actual database
1045
- * This catches constraint violations (unique, primary key, foreign key, etc.)
1044
+ * Validate by loading data into database one row at a time
1045
+ * This catches constraint violations and extracts detailed error information
1046
1046
  */
1047
1047
  async validateWithDatabase(dirPath, jsonlFiles) {
1048
1048
  const errors = [];
1049
- const warnMessages = [];
1050
- const originalWarn = console.warn;
1051
- console.warn = (...args) => {
1052
- const message = args.map((arg) => String(arg)).join(" ");
1053
- warnMessages.push(message);
1054
- originalWarn(...args);
1055
- };
1056
1049
  try {
1057
- const db = LinesDB.create({ dataDir: dirPath });
1058
- await db.initialize();
1059
- await db.close();
1060
- for (const message of warnMessages) if (message.includes("Failed to load table")) {
1061
- const tableNameMatch = message.match(/Failed to load table '([^']+)'/);
1062
- const tableName = tableNameMatch ? tableNameMatch[1] : "unknown";
1063
- const file = jsonlFiles.find((f) => basename(f, ".jsonl") === tableName);
1064
- errors.push({
1065
- file: file || `${dirPath}/${tableName}.jsonl`,
1066
- tableName,
1067
- rowIndex: 0,
1068
- issues: [{
1069
- message: message.replace(/^Warning:\s*/, ""),
1070
- path: []
1071
- }],
1072
- type: "schema"
1073
- });
1050
+ const db = LinesDB.create({ dataDir: ":memory:" });
1051
+ for (const file of jsonlFiles) {
1052
+ const tableName = basename(file, ".jsonl");
1053
+ const data = await JsonlReader.read(file);
1054
+ let schema;
1055
+ let foreignKeys = [];
1056
+ let indexes = [];
1057
+ let primaryKey;
1058
+ try {
1059
+ schema = await SchemaLoader.loadSchema(file);
1060
+ const { pathToFileURL: pathToFileURL$1 } = await import("node:url");
1061
+ const schemaModule = await import(`${pathToFileURL$1(file.replace(".jsonl", ".schema.ts")).href}?t=${Date.now()}`);
1062
+ const schemaExport = schemaModule.schema || schemaModule.default;
1063
+ if (schemaExport?.foreignKeys) foreignKeys = schemaExport.foreignKeys;
1064
+ if (schemaExport?.indexes) indexes = schemaExport.indexes;
1065
+ if (schemaExport?.primaryKey) primaryKey = schemaExport.primaryKey;
1066
+ } catch (_error) {
1067
+ continue;
1068
+ }
1069
+ try {
1070
+ const tableSchema = this.createTableSchema(tableName, data, schema, foreignKeys, indexes, primaryKey);
1071
+ this.createTableInDb(db, tableSchema);
1072
+ for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
1073
+ const row = data[rowIndex];
1074
+ try {
1075
+ this.insertRowIntoDb(db, tableName, tableSchema, row);
1076
+ } catch (error) {
1077
+ const constraintError = this.analyzeConstraintError(error, file, tableName, rowIndex, row, foreignKeys, db);
1078
+ if (constraintError) errors.push(constraintError);
1079
+ }
1080
+ }
1081
+ } catch (_error) {
1082
+ continue;
1083
+ }
1074
1084
  }
1085
+ await db.close();
1075
1086
  } catch (error) {
1076
1087
  errors.push({
1077
1088
  file: dirPath,
@@ -1083,12 +1094,106 @@ var Validator = class {
1083
1094
  }],
1084
1095
  type: "schema"
1085
1096
  });
1086
- } finally {
1087
- console.warn = originalWarn;
1088
1097
  }
1089
1098
  return errors;
1090
1099
  }
1091
1100
  /**
1101
+ * Create table schema from data and validation schema
1102
+ */
1103
+ createTableSchema(tableName, data, validationSchema, foreignKeys, indexes, primaryKey) {
1104
+ if (data.length === 0) throw new Error(`No data found in ${tableName}`);
1105
+ const schema = JsonlReader.inferSchema(tableName, data);
1106
+ if (primaryKey) {
1107
+ const pkColumn = schema.columns.find((col) => col.name === primaryKey);
1108
+ if (pkColumn) pkColumn.primaryKey = true;
1109
+ } else if (!schema.columns.some((col) => col.primaryKey)) {
1110
+ const idColumn = schema.columns.find((c) => c.name === "id");
1111
+ if (idColumn) idColumn.primaryKey = true;
1112
+ }
1113
+ if (foreignKeys && foreignKeys.length > 0) schema.foreignKeys = foreignKeys;
1114
+ if (indexes && indexes.length > 0) schema.indexes = indexes;
1115
+ return schema;
1116
+ }
1117
+ /**
1118
+ * Create table in database
1119
+ */
1120
+ createTableInDb(db, schema) {
1121
+ const columns = schema.columns.map((col) => {
1122
+ let colDef = `${this.quoteIdentifier(col.name)} ${col.type.toUpperCase()}`;
1123
+ if (col.primaryKey) colDef += " PRIMARY KEY";
1124
+ return colDef;
1125
+ });
1126
+ if (schema.foreignKeys && schema.foreignKeys.length > 0) for (const fk of schema.foreignKeys) columns.push(`FOREIGN KEY (${this.quoteIdentifier(fk.column)}) REFERENCES ${this.quoteIdentifier(fk.references.table)}(${this.quoteIdentifier(fk.references.column)})`);
1127
+ const sql = `CREATE TABLE IF NOT EXISTS ${this.quoteIdentifier(schema.name)} (${columns.join(", ")})`;
1128
+ db.execute(sql);
1129
+ if (schema.indexes && schema.indexes.length > 0) for (const index of schema.indexes) {
1130
+ const indexName = index.name || `idx_${schema.name}_${index.columns.join("_")}`;
1131
+ const uniqueKeyword = index.unique ? "UNIQUE" : "";
1132
+ const indexColumns = index.columns.map((col) => this.quoteIdentifier(col)).join(", ");
1133
+ const indexSql = `CREATE ${uniqueKeyword} INDEX IF NOT EXISTS ${this.quoteIdentifier(indexName)} ON ${this.quoteIdentifier(schema.name)} (${indexColumns})`;
1134
+ db.execute(indexSql);
1135
+ }
1136
+ }
1137
+ /**
1138
+ * Insert a row into database
1139
+ */
1140
+ insertRowIntoDb(db, tableName, schema, row) {
1141
+ const columnNames = schema.columns.map((col) => col.name);
1142
+ const quotedColumns = columnNames.map((name) => this.quoteIdentifier(name));
1143
+ const placeholders = columnNames.map(() => "?").join(", ");
1144
+ const sql = `INSERT INTO ${this.quoteIdentifier(tableName)} (${quotedColumns.join(", ")}) VALUES (${placeholders})`;
1145
+ const values = columnNames.map((col) => {
1146
+ const value = row[col];
1147
+ if (value === null || value === void 0) return null;
1148
+ if (typeof value === "object") return JSON.stringify(value);
1149
+ if (typeof value === "boolean") return value ? 1 : 0;
1150
+ return value;
1151
+ });
1152
+ db.execute(sql, values);
1153
+ }
1154
+ /**
1155
+ * Analyze constraint error and extract detailed information
1156
+ */
1157
+ analyzeConstraintError(error, file, tableName, rowIndex, row, foreignKeys, db) {
1158
+ const errorMessage = error instanceof Error ? error.message : String(error);
1159
+ if (errorMessage.includes("FOREIGN KEY constraint failed")) for (const fk of foreignKeys) {
1160
+ const fkValue = row[fk.column];
1161
+ if (fkValue === null || fkValue === void 0) continue;
1162
+ try {
1163
+ const result = db.query(`SELECT COUNT(*) as count FROM ${this.quoteIdentifier(fk.references.table)} WHERE ${this.quoteIdentifier(fk.references.column)} = ?`, [fkValue]);
1164
+ if (result.length > 0 && result[0].count === 0) return {
1165
+ file,
1166
+ tableName,
1167
+ rowIndex,
1168
+ issues: [],
1169
+ type: "foreignKey",
1170
+ foreignKeyError: {
1171
+ column: fk.column,
1172
+ value: fkValue,
1173
+ referencedTable: fk.references.table,
1174
+ referencedColumn: fk.references.column
1175
+ }
1176
+ };
1177
+ } catch (_) {}
1178
+ }
1179
+ return {
1180
+ file,
1181
+ tableName,
1182
+ rowIndex,
1183
+ issues: [{
1184
+ message: errorMessage,
1185
+ path: []
1186
+ }],
1187
+ type: "schema"
1188
+ };
1189
+ }
1190
+ /**
1191
+ * Quote SQL identifier
1192
+ */
1193
+ quoteIdentifier(name) {
1194
+ return `"${name.replace(/"/g, "\"\"")}"`;
1195
+ }
1196
+ /**
1092
1197
  * Validate a single JSONL file
1093
1198
  */
1094
1199
  async validateFile(filePath) {
@@ -1110,8 +1215,9 @@ var Validator = class {
1110
1215
  }
1111
1216
  if (errors.length === 0) {
1112
1217
  const dirPath = dirname(filePath);
1113
- const dbErrors = await this.validateWithDatabase(dirPath, [filePath]);
1114
- errors.push(...dbErrors);
1218
+ const allJsonlFiles = (await readdir(dirPath, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => join(dirPath, entry.name));
1219
+ const dbErrors = await this.validateWithDatabase(dirPath, allJsonlFiles);
1220
+ errors.push(...dbErrors.filter((e) => e.file === filePath));
1115
1221
  }
1116
1222
  return {
1117
1223
  valid: errors.length === 0,
@@ -1317,7 +1423,110 @@ program.command("validate").description("Validate JSONL file(s) against schema")
1317
1423
  process.exit(1);
1318
1424
  }
1319
1425
  });
1320
- program.command("migrate").description("Migrate data with transformation function").argument("<file>", "JSONL file to migrate").argument("<transform>", "Transform function (e.g., \"(row) => ({ ...row, age: row.age + 1 })\")").option("-f, --filter <expr>", "Filter expression").option("-e, --errorOutput <path>", "Output file path for transformed data when migration fails").option("-v, --verbose", "Show verbose error output", false).action(async (filePath, transformStr, options) => {
1426
+ program.command("migrate").description("Migrate data with transformation function").argument("<path>", "File or directory path to migrate").argument("<transform>", "Transform function (e.g., \"(row) => ({ ...row, age: row.age + 1 })\")").option("-f, --filter <expr>", "Filter expression").option("-e, --errorOutput <path>", "Output file path for transformed data when migration fails").option("-v, --verbose", "Show verbose error output", false).action(async (path, transformStr, options) => {
1427
+ try {
1428
+ const stats = await stat(path);
1429
+ if (stats.isDirectory()) await migrateDirectory(path, transformStr, options);
1430
+ else if (stats.isFile() && path.endsWith(".jsonl")) await migrateFile(path, transformStr, options);
1431
+ else {
1432
+ console.error(`Error: Invalid path: ${path}. Must be a directory or .jsonl file.`);
1433
+ process.exit(1);
1434
+ }
1435
+ } catch (error) {
1436
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") console.error(`Error: Path not found: ${path}`);
1437
+ else console.error(`Error: ${String(error)}`);
1438
+ process.exit(1);
1439
+ }
1440
+ });
1441
+ /**
1442
+ * Migrate all JSONL files in a directory
1443
+ */
1444
+ async function migrateDirectory(dirPath, transformStr, options) {
1445
+ const jsonlFiles = (await readdir(dirPath, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => entry.name);
1446
+ if (jsonlFiles.length === 0) {
1447
+ console.error(`Error: No JSONL files found in directory: ${dirPath}`);
1448
+ process.exit(1);
1449
+ }
1450
+ console.log(`Found ${jsonlFiles.length} JSONL file(s) in directory`);
1451
+ const db = LinesDB.create({ dataDir: dirPath });
1452
+ await db.initialize();
1453
+ const tableNames = db.getTableNames();
1454
+ if (tableNames.length === 0) {
1455
+ console.error(`Error: No tables could be loaded from directory: ${dirPath}`);
1456
+ await db.close();
1457
+ process.exit(1);
1458
+ }
1459
+ console.log(`Loaded ${tableNames.length} table(s): ${tableNames.join(", ")}\n`);
1460
+ try {
1461
+ const transform = runInSandbox(`(${transformStr})`);
1462
+ if (typeof transform !== "function") {
1463
+ console.error("Error: Transform must be a function");
1464
+ await db.close();
1465
+ process.exit(1);
1466
+ }
1467
+ let filter = void 0;
1468
+ if (options.filter) try {
1469
+ filter = JSON.parse(options.filter);
1470
+ } catch {
1471
+ filter = runInSandbox(`(${options.filter})`);
1472
+ }
1473
+ let totalRowsMigrated = 0;
1474
+ let hasErrors = false;
1475
+ for (const tableName of tableNames) try {
1476
+ console.log(`Processing table '${tableName}'...`);
1477
+ const rowsToMigrate = filter ? db.find(tableName, filter) : db.find(tableName);
1478
+ if (rowsToMigrate.length === 0) {
1479
+ console.log(` No rows to migrate`);
1480
+ continue;
1481
+ }
1482
+ console.log(` Found ${rowsToMigrate.length} row(s) to migrate`);
1483
+ const transformedRows = rowsToMigrate.map((row) => transform(row));
1484
+ await db.transaction(async () => {
1485
+ db.batchUpdate(tableName, transformedRows, { validate: true });
1486
+ });
1487
+ console.log(` ✓ ${rowsToMigrate.length} row(s) updated\n`);
1488
+ totalRowsMigrated += rowsToMigrate.length;
1489
+ } catch (error) {
1490
+ hasErrors = true;
1491
+ console.error(styleText("red", ` ✗ Failed to migrate table '${tableName}'`));
1492
+ const formatter = new ErrorFormatter({ verbose: options.verbose });
1493
+ if (error instanceof Error && error.name === "ValidationError") {
1494
+ const validationError = error;
1495
+ if (validationError.validationErrors) {
1496
+ console.error(` Found ${validationError.validationErrors.length} validation error(s):\n`);
1497
+ const rowsToMigrate = filter ? db.find(tableName, filter) : db.find(tableName);
1498
+ const errorInfos = validationError.validationErrors.map(({ rowIndex, rowData, error: rowError }) => ({
1499
+ file: `${dirPath}/${tableName}.jsonl`,
1500
+ rowIndex,
1501
+ issues: rowError.issues,
1502
+ data: rowData,
1503
+ originalData: rowsToMigrate[rowIndex]
1504
+ }));
1505
+ const formatted = formatter.formatValidationErrors(errorInfos);
1506
+ console.error(formatted);
1507
+ }
1508
+ } else if (error instanceof Error) console.error(` ${error.message}`);
1509
+ console.error("");
1510
+ }
1511
+ await db.close();
1512
+ if (hasErrors) {
1513
+ console.error(styleText("red", `\n✗ Migration completed with errors for some tables`));
1514
+ console.log(`Total rows migrated: ${totalRowsMigrated}`);
1515
+ process.exit(1);
1516
+ } else {
1517
+ console.log(styleText("green", `\n✓ Migration completed successfully for all tables`));
1518
+ console.log(`Total rows migrated: ${totalRowsMigrated}`);
1519
+ process.exit(0);
1520
+ }
1521
+ } catch (error) {
1522
+ await db.close();
1523
+ throw error;
1524
+ }
1525
+ }
1526
+ /**
1527
+ * Migrate a single JSONL file
1528
+ */
1529
+ async function migrateFile(filePath, transformStr, options) {
1321
1530
  const tableName = (filePath.split("/").pop() || "").replace(".jsonl", "");
1322
1531
  if (!tableName) {
1323
1532
  console.error("Error: Invalid file path. Must be a .jsonl file");
@@ -1414,7 +1623,7 @@ program.command("migrate").description("Migrate data with transformation functio
1414
1623
  await db.close();
1415
1624
  throw error;
1416
1625
  }
1417
- });
1626
+ }
1418
1627
  program.parse();
1419
1628
 
1420
1629
  //#endregion
package/dist/index.cjs CHANGED
@@ -1106,37 +1106,48 @@ var Validator = class {
1106
1106
  };
1107
1107
  }
1108
1108
  /**
1109
- * Validate by loading data into an actual database
1110
- * This catches constraint violations (unique, primary key, foreign key, etc.)
1109
+ * Validate by loading data into database one row at a time
1110
+ * This catches constraint violations and extracts detailed error information
1111
1111
  */
1112
1112
  async validateWithDatabase(dirPath, jsonlFiles) {
1113
1113
  const errors = [];
1114
- const warnMessages = [];
1115
- const originalWarn = console.warn;
1116
- console.warn = (...args) => {
1117
- const message = args.map((arg) => String(arg)).join(" ");
1118
- warnMessages.push(message);
1119
- originalWarn(...args);
1120
- };
1121
1114
  try {
1122
- const db = LinesDB.create({ dataDir: dirPath });
1123
- await db.initialize();
1124
- await db.close();
1125
- for (const message of warnMessages) if (message.includes("Failed to load table")) {
1126
- const tableNameMatch = message.match(/Failed to load table '([^']+)'/);
1127
- const tableName = tableNameMatch ? tableNameMatch[1] : "unknown";
1128
- const file = jsonlFiles.find((f) => (0, node_path.basename)(f, ".jsonl") === tableName);
1129
- errors.push({
1130
- file: file || `${dirPath}/${tableName}.jsonl`,
1131
- tableName,
1132
- rowIndex: 0,
1133
- issues: [{
1134
- message: message.replace(/^Warning:\s*/, ""),
1135
- path: []
1136
- }],
1137
- type: "schema"
1138
- });
1115
+ const db = LinesDB.create({ dataDir: ":memory:" });
1116
+ for (const file of jsonlFiles) {
1117
+ const tableName = (0, node_path.basename)(file, ".jsonl");
1118
+ const data = await JsonlReader.read(file);
1119
+ let schema;
1120
+ let foreignKeys = [];
1121
+ let indexes = [];
1122
+ let primaryKey;
1123
+ try {
1124
+ schema = await SchemaLoader.loadSchema(file);
1125
+ const { pathToFileURL: pathToFileURL$1 } = await import("node:url");
1126
+ const schemaModule = await import(`${pathToFileURL$1(file.replace(".jsonl", ".schema.ts")).href}?t=${Date.now()}`);
1127
+ const schemaExport = schemaModule.schema || schemaModule.default;
1128
+ if (schemaExport?.foreignKeys) foreignKeys = schemaExport.foreignKeys;
1129
+ if (schemaExport?.indexes) indexes = schemaExport.indexes;
1130
+ if (schemaExport?.primaryKey) primaryKey = schemaExport.primaryKey;
1131
+ } catch (_error) {
1132
+ continue;
1133
+ }
1134
+ try {
1135
+ const tableSchema = this.createTableSchema(tableName, data, schema, foreignKeys, indexes, primaryKey);
1136
+ this.createTableInDb(db, tableSchema);
1137
+ for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
1138
+ const row = data[rowIndex];
1139
+ try {
1140
+ this.insertRowIntoDb(db, tableName, tableSchema, row);
1141
+ } catch (error) {
1142
+ const constraintError = this.analyzeConstraintError(error, file, tableName, rowIndex, row, foreignKeys, db);
1143
+ if (constraintError) errors.push(constraintError);
1144
+ }
1145
+ }
1146
+ } catch (_error) {
1147
+ continue;
1148
+ }
1139
1149
  }
1150
+ await db.close();
1140
1151
  } catch (error) {
1141
1152
  errors.push({
1142
1153
  file: dirPath,
@@ -1148,12 +1159,106 @@ var Validator = class {
1148
1159
  }],
1149
1160
  type: "schema"
1150
1161
  });
1151
- } finally {
1152
- console.warn = originalWarn;
1153
1162
  }
1154
1163
  return errors;
1155
1164
  }
1156
1165
  /**
1166
+ * Create table schema from data and validation schema
1167
+ */
1168
+ createTableSchema(tableName, data, validationSchema, foreignKeys, indexes, primaryKey) {
1169
+ if (data.length === 0) throw new Error(`No data found in ${tableName}`);
1170
+ const schema = JsonlReader.inferSchema(tableName, data);
1171
+ if (primaryKey) {
1172
+ const pkColumn = schema.columns.find((col) => col.name === primaryKey);
1173
+ if (pkColumn) pkColumn.primaryKey = true;
1174
+ } else if (!schema.columns.some((col) => col.primaryKey)) {
1175
+ const idColumn = schema.columns.find((c) => c.name === "id");
1176
+ if (idColumn) idColumn.primaryKey = true;
1177
+ }
1178
+ if (foreignKeys && foreignKeys.length > 0) schema.foreignKeys = foreignKeys;
1179
+ if (indexes && indexes.length > 0) schema.indexes = indexes;
1180
+ return schema;
1181
+ }
1182
+ /**
1183
+ * Create table in database
1184
+ */
1185
+ createTableInDb(db, schema) {
1186
+ const columns = schema.columns.map((col) => {
1187
+ let colDef = `${this.quoteIdentifier(col.name)} ${col.type.toUpperCase()}`;
1188
+ if (col.primaryKey) colDef += " PRIMARY KEY";
1189
+ return colDef;
1190
+ });
1191
+ if (schema.foreignKeys && schema.foreignKeys.length > 0) for (const fk of schema.foreignKeys) columns.push(`FOREIGN KEY (${this.quoteIdentifier(fk.column)}) REFERENCES ${this.quoteIdentifier(fk.references.table)}(${this.quoteIdentifier(fk.references.column)})`);
1192
+ const sql = `CREATE TABLE IF NOT EXISTS ${this.quoteIdentifier(schema.name)} (${columns.join(", ")})`;
1193
+ db.execute(sql);
1194
+ if (schema.indexes && schema.indexes.length > 0) for (const index of schema.indexes) {
1195
+ const indexName = index.name || `idx_${schema.name}_${index.columns.join("_")}`;
1196
+ const uniqueKeyword = index.unique ? "UNIQUE" : "";
1197
+ const indexColumns = index.columns.map((col) => this.quoteIdentifier(col)).join(", ");
1198
+ const indexSql = `CREATE ${uniqueKeyword} INDEX IF NOT EXISTS ${this.quoteIdentifier(indexName)} ON ${this.quoteIdentifier(schema.name)} (${indexColumns})`;
1199
+ db.execute(indexSql);
1200
+ }
1201
+ }
1202
+ /**
1203
+ * Insert a row into database
1204
+ */
1205
+ insertRowIntoDb(db, tableName, schema, row) {
1206
+ const columnNames = schema.columns.map((col) => col.name);
1207
+ const quotedColumns = columnNames.map((name) => this.quoteIdentifier(name));
1208
+ const placeholders = columnNames.map(() => "?").join(", ");
1209
+ const sql = `INSERT INTO ${this.quoteIdentifier(tableName)} (${quotedColumns.join(", ")}) VALUES (${placeholders})`;
1210
+ const values = columnNames.map((col) => {
1211
+ const value = row[col];
1212
+ if (value === null || value === void 0) return null;
1213
+ if (typeof value === "object") return JSON.stringify(value);
1214
+ if (typeof value === "boolean") return value ? 1 : 0;
1215
+ return value;
1216
+ });
1217
+ db.execute(sql, values);
1218
+ }
1219
+ /**
1220
+ * Analyze constraint error and extract detailed information
1221
+ */
1222
+ analyzeConstraintError(error, file, tableName, rowIndex, row, foreignKeys, db) {
1223
+ const errorMessage = error instanceof Error ? error.message : String(error);
1224
+ if (errorMessage.includes("FOREIGN KEY constraint failed")) for (const fk of foreignKeys) {
1225
+ const fkValue = row[fk.column];
1226
+ if (fkValue === null || fkValue === void 0) continue;
1227
+ try {
1228
+ const result = db.query(`SELECT COUNT(*) as count FROM ${this.quoteIdentifier(fk.references.table)} WHERE ${this.quoteIdentifier(fk.references.column)} = ?`, [fkValue]);
1229
+ if (result.length > 0 && result[0].count === 0) return {
1230
+ file,
1231
+ tableName,
1232
+ rowIndex,
1233
+ issues: [],
1234
+ type: "foreignKey",
1235
+ foreignKeyError: {
1236
+ column: fk.column,
1237
+ value: fkValue,
1238
+ referencedTable: fk.references.table,
1239
+ referencedColumn: fk.references.column
1240
+ }
1241
+ };
1242
+ } catch (_) {}
1243
+ }
1244
+ return {
1245
+ file,
1246
+ tableName,
1247
+ rowIndex,
1248
+ issues: [{
1249
+ message: errorMessage,
1250
+ path: []
1251
+ }],
1252
+ type: "schema"
1253
+ };
1254
+ }
1255
+ /**
1256
+ * Quote SQL identifier
1257
+ */
1258
+ quoteIdentifier(name) {
1259
+ return `"${name.replace(/"/g, "\"\"")}"`;
1260
+ }
1261
+ /**
1157
1262
  * Validate a single JSONL file
1158
1263
  */
1159
1264
  async validateFile(filePath) {
@@ -1175,8 +1280,9 @@ var Validator = class {
1175
1280
  }
1176
1281
  if (errors.length === 0) {
1177
1282
  const dirPath = (0, node_path.dirname)(filePath);
1178
- const dbErrors = await this.validateWithDatabase(dirPath, [filePath]);
1179
- errors.push(...dbErrors);
1283
+ const allJsonlFiles = (await (0, node_fs_promises.readdir)(dirPath, { withFileTypes: true })).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => (0, node_path.join)(dirPath, entry.name));
1284
+ const dbErrors = await this.validateWithDatabase(dirPath, allJsonlFiles);
1285
+ errors.push(...dbErrors.filter((e) => e.file === filePath));
1180
1286
  }
1181
1287
  return {
1182
1288
  valid: errors.length === 0,
package/dist/index.d.cts CHANGED
@@ -469,10 +469,30 @@ declare class Validator {
469
469
  */
470
470
  private validateDirectory;
471
471
  /**
472
- * Validate by loading data into an actual database
473
- * This catches constraint violations (unique, primary key, foreign key, etc.)
472
+ * Validate by loading data into database one row at a time
473
+ * This catches constraint violations and extracts detailed error information
474
474
  */
475
475
  private validateWithDatabase;
476
+ /**
477
+ * Create table schema from data and validation schema
478
+ */
479
+ private createTableSchema;
480
+ /**
481
+ * Create table in database
482
+ */
483
+ private createTableInDb;
484
+ /**
485
+ * Insert a row into database
486
+ */
487
+ private insertRowIntoDb;
488
+ /**
489
+ * Analyze constraint error and extract detailed information
490
+ */
491
+ private analyzeConstraintError;
492
+ /**
493
+ * Quote SQL identifier
494
+ */
495
+ private quoteIdentifier;
476
496
  /**
477
497
  * Validate a single JSONL file
478
498
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/sqlite-adapter.ts","../src/types.ts","../src/database.ts","../src/jsonl-reader.ts","../src/jsonl-writer.ts","../src/schema-loader.ts","../src/directory-scanner.ts","../src/schema.ts","../src/type-generator.ts","../src/validator.ts","../src/jsonl-migration.ts","../src/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;AASA;AAMA;;UANiB,cAAA;wBACO;ECPZ,IAAA,CAAA,GAAK,EAAA,MAAA,CAAA,EAAA,IAAG;EACR,KAAA,EAAA,EAAA,IAAA;;AACY,UDUP,eAAA,CCVO;EACP,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA;IAAQ,O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
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/sqlite-adapter.ts","../src/types.ts","../src/database.ts","../src/jsonl-reader.ts","../src/jsonl-writer.ts","../src/schema-loader.ts","../src/directory-scanner.ts","../src/schema.ts","../src/type-generator.ts","../src/validator.ts","../src/jsonl-migration.ts","../src/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;AASA;AAMA;;UANiB,cAAA;wBACO;ECPZ,IAAA,CAAA,GAAK,EAAA,MAAA,CAAA,EAAG,IAAA;EACR,KAAA,EAAA,EAAA,IAAA;;AACY,UDUP,eAAA,CCVO;EACP,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA;IAAQ,OAAA,EAAA,MAAA;IACJ,eAAA,EAAA,MAAA,GAAA,MAAA;EAAO,CAAA;EAAxB,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA,GAAA;EAAgB,GAAA,CAAA,GAAA,MAAA,EAAA,GAAA,EAAA,CAAA,EAAA,GAAA,EAAA;AACpB;;;KALY,KAAA,GAAQ;KACR,6BACI,QAAQ,sBACP,QAAQ,SACrB,iBAAiB,OAAO;ADEX,KCDL,oBDCmB,CACP,MAAA,CAAA,GCFmB,gBAAA,CAAiB,MDErB,CCF4B,MDE5B,CAAA;AAKtB,KCNL,mBAAA,GAAsB,gBAAA,CAAiB,KDMnB;KCCpB,kBAAgB,YAAU,qCAAqC;KAC/D,mBAAiB,YAAU,qCAAqC;AAdhE,UAgBK,oBAAA,CAhBS;EACd,MAAA,EAAA,MAAA;EACI,UAAA,EAAA;IAAQ,KAAA,EAAA,MAAA;IACP,MAAA,EAAA,MAAA;EAAQ,CAAA;EACJ,QAAA,CAAA,EAAA,SAAA,GAAA,UAAA,GAAA,UAAA,GAAA,WAAA;EAAO,QAAA,CAAA,EAAA,SAAA,GAAA,UAAA,GAAA,UAAA,GAAA,WAAA;;AAAR,UAsBH,eAAA,CAtBG;EACR,IAAA,CAAA,EAAA,MAAA;E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CAAA,EQyBG,ORzBH,CQyBW,gBRzBS,CAAA;EAUpB;AAMjB;;EAGgB,QAAA,iBAAA;EACJ;;AAGZ;AASA;EACqB,QAAA,oBAA2B;EAE/B;;;EAEW,QAAA,iBAAA;EAAhB;;AAaZ;EAOiB,QAAA,eAAgB;EAET;;;EAFsB,QAAA,eAAA;EAKlC;AACZ;AAGA;EAGY,QAAA,sBAAgB;EAEhB;;;EACkB,QAAA,eAAA;EAAE;;;EAGpB,QAAA,YAAc;;;;USzFT,sBAAA;;EVIA,SAAA,EAAA,MAAc;EAMd,IAAA,EUPT,UVOS,EAAe;;;;ACZhC;AACA;AACgB,iBSUM,oBAAA,CTVN,OAAA,ESUoC,sBTVpC,CAAA,ESU6D,OTV7D,CAAA,IAAA,CAAA;;;;;;ADIC,KWLL,kBAAA,GXMY,MAAA,GAAA,SAAe;AAKtB,iBWTD,aAAA,CAAA,CXSgB,EWTC,kBXSD;cWAnB,SAAO"}
package/dist/index.d.ts CHANGED
@@ -469,10 +469,30 @@ declare class Validator {
469
469
  */
470
470
  private validateDirectory;
471
471
  /**
472
- * Validate by loading data into an actual database
473
- * This catches constraint violations (unique, primary key, foreign key, etc.)
472
+ * Validate by loading data into database one row at a time
473
+ * This catches constraint violations and extracts detailed error information
474
474
  */
475
475
  private validateWithDatabase;
476
+ /**
477
+ * Create table schema from data and validation schema
478
+ */
479
+ private createTableSchema;
480
+ /**
481
+ * Create table in database
482
+ */
483
+ private createTableInDb;
484
+ /**
485
+ * Insert a row into database
486
+ */
487
+ private insertRowIntoDb;
488
+ /**
489
+ * Analyze constraint error and extract detailed information
490
+ */
491
+ private analyzeConstraintError;
492
+ /**
493
+ * Quote SQL identifier
494
+ */
495
+ private quoteIdentifier;
476
496
  /**
477
497
  * Validate a single JSONL file
478
498
  */