flint-orm 0.4.2 → 0.4.4
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/src/cli.js +146 -46
- package/package.json +17 -8
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -13593,48 +13666,74 @@ async function cmdMigrate(args, config) {
|
|
|
13593
13666
|
const isLocalDriver = config.driver === "bun-sqlite" || config.driver === "better-sqlite3";
|
|
13594
13667
|
const dbUrl = isLocalDriver ? resolve3(process.cwd(), config.database.url) : config.database.url;
|
|
13595
13668
|
let executor;
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13669
|
+
const DRIVER_PACKAGES = {
|
|
13670
|
+
"better-sqlite3": "better-sqlite3",
|
|
13671
|
+
libsql: "@libsql/client",
|
|
13672
|
+
"libsql-web": "@libsql/client",
|
|
13673
|
+
turso: "@tursodatabase/database",
|
|
13674
|
+
"turso-sync": "@tursodatabase/sync"
|
|
13675
|
+
};
|
|
13676
|
+
try {
|
|
13677
|
+
switch (config.driver) {
|
|
13678
|
+
case "bun-sqlite": {
|
|
13679
|
+
const { BunSqliteExecutor: BunSqliteExecutor2 } = await Promise.resolve().then(() => (init_bun_sqlite(), exports_bun_sqlite));
|
|
13680
|
+
const { Database: Database10 } = await import("bun:sqlite");
|
|
13681
|
+
executor = new BunSqliteExecutor2(new Database10(dbUrl));
|
|
13682
|
+
break;
|
|
13683
|
+
}
|
|
13684
|
+
case "better-sqlite3": {
|
|
13685
|
+
const { BetterSqlite3Executor: BetterSqlite3Executor2 } = await Promise.resolve().then(() => (init_better_sqlite3(), exports_better_sqlite3));
|
|
13686
|
+
const Database10 = (await Promise.resolve().then(() => __toESM(require_lib(), 1))).default;
|
|
13687
|
+
executor = new BetterSqlite3Executor2(new Database10(dbUrl));
|
|
13688
|
+
break;
|
|
13689
|
+
}
|
|
13690
|
+
case "libsql": {
|
|
13691
|
+
const { LibsqlExecutor: LibsqlExecutor2 } = await Promise.resolve().then(() => (init_libsql(), exports_libsql));
|
|
13692
|
+
const { createClient: createLibsqlClient } = await Promise.resolve().then(() => (init_node(), exports_node));
|
|
13693
|
+
executor = new LibsqlExecutor2(createLibsqlClient({ url: dbUrl, authToken: config.database.authToken }));
|
|
13694
|
+
break;
|
|
13695
|
+
}
|
|
13696
|
+
case "libsql-web": {
|
|
13697
|
+
const { LibsqlWebExecutor: LibsqlWebExecutor2 } = await Promise.resolve().then(() => (init_libsql_web(), exports_libsql_web));
|
|
13698
|
+
const { createClient: createLibsqlWebClient } = await Promise.resolve().then(() => (init_web2(), exports_web));
|
|
13699
|
+
executor = new LibsqlWebExecutor2(createLibsqlWebClient({ url: dbUrl, authToken: config.database.authToken }));
|
|
13700
|
+
break;
|
|
13701
|
+
}
|
|
13702
|
+
case "turso-sync": {
|
|
13703
|
+
const { TursoSyncExecutor: TursoSyncExecutor2 } = await Promise.resolve().then(() => (init_turso_sync(), exports_turso_sync));
|
|
13704
|
+
const { connect: connect4 } = await Promise.resolve().then(() => (init_promise2(), exports_promise));
|
|
13705
|
+
const db = await connect4({ path: dbUrl, authToken: config.database.authToken });
|
|
13706
|
+
executor = new TursoSyncExecutor2(db);
|
|
13707
|
+
break;
|
|
13708
|
+
}
|
|
13709
|
+
case "turso": {
|
|
13710
|
+
const { TursoExecutor: TursoExecutor2 } = await Promise.resolve().then(() => (init_turso(), exports_turso));
|
|
13711
|
+
const { connect: connect4 } = await Promise.resolve().then(() => (init_promise3(), exports_promise2));
|
|
13712
|
+
const db = await connect4(dbUrl);
|
|
13713
|
+
executor = new TursoExecutor2(db);
|
|
13714
|
+
break;
|
|
13715
|
+
}
|
|
13716
|
+
default:
|
|
13717
|
+
cancel(`Unsupported driver: ${config.driver}`);
|
|
13718
|
+
process.exit(1);
|
|
13627
13719
|
}
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13720
|
+
} catch (err) {
|
|
13721
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
13722
|
+
const pkg = DRIVER_PACKAGES[config.driver];
|
|
13723
|
+
if (pkg && (msg.includes("Cannot find module") || msg.includes("ERR_MODULE_NOT_FOUND") || msg.includes("not found"))) {
|
|
13724
|
+
const installCmd = pkg === "@libsql/client" ? "npm install @libsql/client" : `npm install ${pkg}`;
|
|
13725
|
+
note(`Driver "${config.driver}" is not installed.
|
|
13726
|
+
|
|
13727
|
+
Install it with:
|
|
13728
|
+
|
|
13729
|
+
${import_picocolors.default.dim(installCmd)}
|
|
13730
|
+
`, "Missing driver");
|
|
13731
|
+
} else {
|
|
13732
|
+
note(`Failed to load driver "${config.driver}":
|
|
13733
|
+
|
|
13734
|
+
${import_picocolors.default.dim(msg)}`, "Error");
|
|
13634
13735
|
}
|
|
13635
|
-
|
|
13636
|
-
cancel(`Unsupported driver: ${config.driver}`);
|
|
13637
|
-
process.exit(1);
|
|
13736
|
+
process.exit(1);
|
|
13638
13737
|
}
|
|
13639
13738
|
try {
|
|
13640
13739
|
if (statusOnly) {
|
|
@@ -13738,7 +13837,8 @@ main().catch((err) => {
|
|
|
13738
13837
|
if (isCancel(err) || err instanceof CancellationError) {
|
|
13739
13838
|
cancel("Operation cancelled.");
|
|
13740
13839
|
} else {
|
|
13741
|
-
|
|
13840
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
13841
|
+
note(msg || "An unexpected error occurred.", "Error");
|
|
13742
13842
|
}
|
|
13743
13843
|
process.exit(1);
|
|
13744
13844
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flint-orm",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"bin": {
|
|
5
5
|
"flint": "./dist/src/cli.js"
|
|
6
6
|
},
|
|
@@ -65,22 +65,31 @@
|
|
|
65
65
|
"format": "oxfmt --write",
|
|
66
66
|
"check": "oxlint && oxfmt"
|
|
67
67
|
},
|
|
68
|
-
"dependencies": {
|
|
68
|
+
"dependencies": {},
|
|
69
|
+
"devDependencies": {
|
|
69
70
|
"@clack/prompts": "1.7.0",
|
|
70
71
|
"@libsql/client": "0.17.4",
|
|
71
72
|
"@tursodatabase/database": "0.6.1",
|
|
72
73
|
"@tursodatabase/sync": "0.6.1",
|
|
73
|
-
"better-sqlite3": "12.11.1",
|
|
74
|
-
"picocolors": "1.1.1"
|
|
75
|
-
},
|
|
76
|
-
"devDependencies": {
|
|
77
74
|
"@types/better-sqlite3": "7.6.13",
|
|
78
75
|
"@types/bun": "1.3.14",
|
|
79
76
|
"@types/node": "26.1.1",
|
|
77
|
+
"better-sqlite3": "12.11.1",
|
|
80
78
|
"oxfmt": "0.57.0",
|
|
81
|
-
"oxlint": "1.72.0"
|
|
79
|
+
"oxlint": "1.72.0",
|
|
80
|
+
"picocolors": "1.1.1"
|
|
82
81
|
},
|
|
83
82
|
"peerDependencies": {
|
|
84
|
-
"
|
|
83
|
+
"@libsql/client": ">=0.17.4",
|
|
84
|
+
"@tursodatabase/database": ">=0.6.1",
|
|
85
|
+
"@tursodatabase/sync": ">=0.6.1",
|
|
86
|
+
"better-sqlite3": ">=12.11.1",
|
|
87
|
+
"typescript": ">=5.0.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"@libsql/client": { "optional": true },
|
|
91
|
+
"@tursodatabase/database": { "optional": true },
|
|
92
|
+
"@tursodatabase/sync": { "optional": true },
|
|
93
|
+
"better-sqlite3": { "optional": true }
|
|
85
94
|
}
|
|
86
95
|
}
|