flint-orm 0.4.2 → 0.4.3

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.
Files changed (2) hide show
  1. package/dist/src/cli.js +80 -6
  2. package/package.json +1 -1
package/dist/src/cli.js CHANGED
@@ -13485,15 +13485,65 @@ var import_picocolors = __toESM(require_picocolors(), 1);
13485
13485
  init_diff();
13486
13486
  async function loadConfig() {
13487
13487
  const configPath = resolve3(process.cwd(), "flint.config.ts");
13488
+ if (!existsSync3(configPath)) {
13489
+ note(`Could not find ${import_picocolors.default.bold("flint.config.ts")} in the current directory.
13490
+
13491
+ ` + `Create one with:
13492
+
13493
+ ` + ` ${import_picocolors.default.dim("import { defineConfig } from 'flint-orm/config';")}
13494
+ ` + ` ${import_picocolors.default.dim("export default defineConfig({")}
13495
+ ` + ` ${import_picocolors.default.dim(" driver: 'bun-sqlite',")}
13496
+ ` + ` ${import_picocolors.default.dim(" database: { url: './app.db' },")}
13497
+ ` + ` ${import_picocolors.default.dim(" schema: './db',")}
13498
+ ` + ` ${import_picocolors.default.dim("});")}
13499
+ `, "Missing config");
13500
+ process.exit(1);
13501
+ }
13488
13502
  const configUrl = pathToFileURL2(configPath).href;
13489
13503
  const mod = await import(configUrl);
13490
- return mod.default;
13504
+ const config = mod.default;
13505
+ if (!config || typeof config !== "object") {
13506
+ note(`${import_picocolors.default.bold("flint.config.ts")} does not export a config object.
13507
+
13508
+ Make sure it has a default export:
13509
+
13510
+ ${import_picocolors.default.dim("export default defineConfig({ ... })")}
13511
+ `, "Invalid config");
13512
+ process.exit(1);
13513
+ }
13514
+ const missing = [];
13515
+ if (!config.driver)
13516
+ missing.push("driver");
13517
+ if (!config.database)
13518
+ missing.push("database");
13519
+ if (!config.schema)
13520
+ missing.push("schema");
13521
+ if (missing.length > 0) {
13522
+ note(`${import_picocolors.default.bold("flint.config.ts")} is missing required fields: ${import_picocolors.default.bold(missing.join(", "))}
13523
+
13524
+ A valid config looks like:
13525
+
13526
+ ${import_picocolors.default.dim("export default defineConfig({")}
13527
+ ${import_picocolors.default.dim(" driver: 'bun-sqlite',")}
13528
+ ${import_picocolors.default.dim(" database: { url: './app.db' },")}
13529
+ ${import_picocolors.default.dim(" schema: './db',")}
13530
+ ${import_picocolors.default.dim("});")}
13531
+ `, "Invalid config");
13532
+ process.exit(1);
13533
+ }
13534
+ return config;
13491
13535
  }
13492
13536
  function isTableDef(value) {
13493
13537
  return value !== null && typeof value === "object" && "_" in value && typeof value._ === "object" && typeof value._.name === "string";
13494
13538
  }
13495
13539
  async function discoverTables(schemaPath) {
13496
13540
  const abs = isAbsolute(schemaPath) ? schemaPath : resolve3(process.cwd(), schemaPath);
13541
+ if (!existsSync3(abs)) {
13542
+ note(`Schema path ${import_picocolors.default.bold(abs)} does not exist.
13543
+
13544
+ Check the ${import_picocolors.default.bold("schema")} field in your ${import_picocolors.default.bold("flint.config.ts")}.`, "Schema not found");
13545
+ process.exit(1);
13546
+ }
13497
13547
  const stat = statSync(abs);
13498
13548
  if (stat.isFile()) {
13499
13549
  return importTableFile(abs);
@@ -13501,11 +13551,23 @@ async function discoverTables(schemaPath) {
13501
13551
  if (stat.isDirectory()) {
13502
13552
  return importTableFolder(abs);
13503
13553
  }
13504
- throw new Error(`Schema path does not exist: ${abs}`);
13554
+ note(`Schema path ${import_picocolors.default.bold(abs)} is not a file or directory.`, "Invalid schema path");
13555
+ process.exit(1);
13505
13556
  }
13506
13557
  async function importTableFile(filePath) {
13507
13558
  const url = pathToFileURL2(filePath).href;
13508
- const mod = await import(url);
13559
+ let mod;
13560
+ try {
13561
+ mod = await import(url);
13562
+ } catch (err) {
13563
+ const msg = err instanceof Error ? err.message : String(err);
13564
+ note(`Could not load schema file ${import_picocolors.default.bold(filePath)}:
13565
+
13566
+ ${import_picocolors.default.dim(msg)}
13567
+
13568
+ Make sure the file exports table() definitions.`, "Schema import error");
13569
+ process.exit(1);
13570
+ }
13509
13571
  const tables = [];
13510
13572
  for (const exportValue of Object.values(mod)) {
13511
13573
  if (isTableDef(exportValue)) {
@@ -13546,7 +13608,14 @@ async function cmdGenerate(args, config) {
13546
13608
  for (const folder of folders) {
13547
13609
  const statePath = join3(migrationsDir, folder, "state.json");
13548
13610
  if (existsSync3(statePath)) {
13549
- previousState = JSON.parse(readFileSync4(statePath, "utf-8"));
13611
+ try {
13612
+ previousState = JSON.parse(readFileSync4(statePath, "utf-8"));
13613
+ } catch {
13614
+ note(`Could not parse ${import_picocolors.default.bold(statePath)}.
13615
+
13616
+ The file may be corrupted. Delete it and run ${import_picocolors.default.bold("flint generate")} again.`, "Invalid state file");
13617
+ process.exit(1);
13618
+ }
13550
13619
  break;
13551
13620
  }
13552
13621
  }
@@ -13581,7 +13650,11 @@ async function cmdGenerate(args, config) {
13581
13650
  if (err instanceof Error && err.message.includes("No changes detected")) {
13582
13651
  outro("Schema is already up to date.");
13583
13652
  } else {
13584
- throw err;
13653
+ const msg = err instanceof Error ? err.message : String(err);
13654
+ note(`Migration generation failed:
13655
+
13656
+ ${import_picocolors.default.dim(msg)}`, "Error");
13657
+ process.exit(1);
13585
13658
  }
13586
13659
  }
13587
13660
  }
@@ -13738,7 +13811,8 @@ main().catch((err) => {
13738
13811
  if (isCancel(err) || err instanceof CancellationError) {
13739
13812
  cancel("Operation cancelled.");
13740
13813
  } else {
13741
- cancel(err.message ?? "An error occurred");
13814
+ const msg = err instanceof Error ? err.message : String(err);
13815
+ note(msg || "An unexpected error occurred.", "Error");
13742
13816
  }
13743
13817
  process.exit(1);
13744
13818
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flint-orm",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "bin": {
5
5
  "flint": "./dist/src/cli.js"
6
6
  },