@lssm/app.cli-database 1.11.1 → 1.41.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lssm/app.cli-database",
3
- "version": "1.11.1",
3
+ "version": "1.41.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "database": "dist/cli.js"
@@ -13,23 +13,28 @@
13
13
  "lint": "bun run lint:fix",
14
14
  "lint:fix": "eslint src --fix",
15
15
  "lint:check": "eslint src",
16
- "prisma:import": "bun database import",
17
- "prisma:check": "bun database check",
18
- "dbs:generate": "bun database generate",
19
- "dbs:migrate": "bun database migrate:dev",
20
- "dbs:deploy": "bun database migrate:deploy",
21
- "dbs:status": "bun database migrate:status",
22
- "dbs:seed": "bun database seed"
16
+ "prisma:import": "database import",
17
+ "prisma:check": "database check",
18
+ "dbs:generate": "database generate",
19
+ "dbs:migrate": "database migrate:dev",
20
+ "dbs:deploy": "database migrate:deploy",
21
+ "dbs:status": "database migrate:status",
22
+ "dbs:seed": "database seed",
23
+ "schema:generate": "database schema:generate",
24
+ "schema:compose": "database schema:compose"
23
25
  },
24
26
  "dependencies": {
25
- "@prisma/adapter-pg": "^7.0.1",
26
- "@prisma/client": "^7.0.1",
27
- "prisma": "^7.0.1",
28
- "minimist": "^1.2.8"
27
+ "@lssm/lib.schema": "workspace:*",
28
+ "@prisma/adapter-pg": "^7.1.0",
29
+ "@prisma/client": "^7.1.0",
30
+ "prisma": "^7.1.0",
31
+ "minimist": "^1.2.8",
32
+ "execa": "^9.6.1"
29
33
  },
30
34
  "devDependencies": {
31
- "@lssm/tool.tsdown": "0.12.1",
32
- "tsdown": "^0.16.6"
35
+ "@lssm/tool.tsdown": "workspace:*",
36
+ "@types/minimist": "^1.2.5",
37
+ "tsdown": "^0.17.4"
33
38
  },
34
39
  "main": "./dist/index.mjs",
35
40
  "module": "./dist/index.mjs",
@@ -39,11 +44,16 @@
39
44
  "README.md"
40
45
  ],
41
46
  "exports": {
42
- ".": "./dist/index.mjs",
43
- "./cli": "./dist/cli.mjs",
47
+ ".": "./src/index.ts",
48
+ "./cli": "./src/cli.ts",
44
49
  "./*": "./*"
45
50
  },
46
51
  "publishConfig": {
47
- "access": "public"
52
+ "access": "public",
53
+ "exports": {
54
+ ".": "./dist/index.mjs",
55
+ "./cli": "./dist/cli.mjs",
56
+ "./*": "./*"
57
+ }
48
58
  }
49
59
  }
@@ -1,7 +0,0 @@
1
- import { createRequire } from "node:module";
2
-
3
- //#region rolldown:runtime
4
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
-
6
- //#endregion
7
- export { __require };
package/dist/cli.d.mts DELETED
@@ -1 +0,0 @@
1
- export { };
package/dist/cli.mjs DELETED
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env node
2
- import { runImport } from "./commands/import.mjs";
3
- import { runCheck } from "./commands/check.mjs";
4
- import { runGenerate } from "./commands/generate.mjs";
5
- import { runMigrate } from "./commands/migrate.mjs";
6
- import { runSeed } from "./commands/seed.mjs";
7
- import mri from "minimist";
8
-
9
- //#region src/cli.ts
10
- async function main() {
11
- const argv = mri(process.argv.slice(2));
12
- const [cmd] = argv._;
13
- switch (cmd) {
14
- case "import":
15
- await runImport(argv);
16
- break;
17
- case "check":
18
- await runCheck(argv);
19
- break;
20
- case "generate":
21
- await runGenerate(argv);
22
- break;
23
- case "migrate:dev":
24
- case "migrate:deploy":
25
- case "migrate:status":
26
- await runMigrate(cmd, argv);
27
- break;
28
- case "seed":
29
- await runSeed(argv);
30
- break;
31
- default:
32
- console.error("Usage: database <import|check|generate|migrate:dev|migrate:deploy|migrate:status|seed>");
33
- process.exit(1);
34
- }
35
- }
36
- main().catch((err) => {
37
- console.error(err);
38
- process.exit(1);
39
- });
40
-
41
- //#endregion
42
- export { };
@@ -1,34 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import crypto from "node:crypto";
4
-
5
- //#region src/commands/check.ts
6
- function sha256(content) {
7
- return crypto.createHash("sha256").update(content).digest("hex");
8
- }
9
- async function runCheck(argv) {
10
- const target = argv.target || process.cwd();
11
- const lockPath = path.join(target, "prisma", "schema", "imported", "imported.lock.json");
12
- if (!fs.existsSync(lockPath)) {
13
- console.error("No imported.lock.json found. Run: database import");
14
- process.exit(1);
15
- }
16
- const lock = JSON.parse(fs.readFileSync(lockPath, "utf8"));
17
- let ok = true;
18
- for (const e of lock.entries) {
19
- if (!fs.existsSync(e.sourcePath)) {
20
- console.error(`Missing source: ${e.sourcePath}`);
21
- ok = false;
22
- continue;
23
- }
24
- if (sha256(fs.readFileSync(e.sourcePath, "utf8")) !== e.sha256) {
25
- console.error(`Drift detected for ${e.moduleName} (${e.sourcePath})`);
26
- ok = false;
27
- }
28
- }
29
- if (!ok) process.exit(2);
30
- console.log("Imported schemas are in sync with lock.");
31
- }
32
-
33
- //#endregion
34
- export { runCheck };
@@ -1,9 +0,0 @@
1
- import { execa } from "execa";
2
-
3
- //#region src/commands/generate.ts
4
- async function runGenerate(argv) {
5
- await execa("prisma", ["generate"], { stdio: "inherit" });
6
- }
7
-
8
- //#endregion
9
- export { runGenerate };
@@ -1,95 +0,0 @@
1
- import { __require } from "../_virtual/rolldown_runtime.mjs";
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- import crypto from "node:crypto";
5
- import { pathToFileURL } from "node:url";
6
-
7
- //#region src/commands/import.ts
8
- function sha256(content) {
9
- return crypto.createHash("sha256").update(content).digest("hex");
10
- }
11
- function stripDatasourceAndGenerators(schema) {
12
- return schema.replace(/datasource\s+\w+\s*\{[\s\S]*?\}/g, "").replace(/generator\s+\w+\s*\{[\s\S]*?\}/g, "").trim();
13
- }
14
- async function runImport(argv) {
15
- const target = argv.target || process.cwd();
16
- const modulesArg = argv.modules || "";
17
- async function loadModulesFromMergerConfig() {
18
- const candidates = [
19
- path.join(target, "prisma-merger.config.ts"),
20
- path.join(target, "prisma-merger.config.mts"),
21
- path.join(target, "prisma-merger.config.js"),
22
- path.join(target, "prisma-merger.config.mjs"),
23
- path.join(target, "prisma-merger.config.cjs"),
24
- path.join(target, "prisma-merger.config.json")
25
- ];
26
- for (const file of candidates) {
27
- if (!fs.existsSync(file)) continue;
28
- if (file.endsWith(".json")) {
29
- const json = JSON.parse(fs.readFileSync(file, "utf8"));
30
- if (Array.isArray(json.modules) && json.modules.length > 0) return json.modules;
31
- } else if (file.endsWith(".ts") || file.endsWith(".mts")) {
32
- const match = fs.readFileSync(file, "utf8").match(/modules\s*:\s*\[([\s\S]*?)\]/m);
33
- if (Array.isArray(match) && typeof match[1] === "string") {
34
- const arr = match[1] || "";
35
- const mods = [];
36
- const re = /['\"]([^'\"]+)['\"]/g;
37
- let m;
38
- while (m = re.exec(arr)) {
39
- const val = m[1] ?? "";
40
- if (val) mods.push(val);
41
- }
42
- if (mods.length > 0) return mods;
43
- }
44
- } else {
45
- const mod = await import(pathToFileURL(file).href);
46
- const cfg = mod.default || mod;
47
- if (Array.isArray(cfg.modules) && cfg.modules.length > 0) return cfg.modules;
48
- }
49
- }
50
- return null;
51
- }
52
- let modules = modulesArg.split(",").map((s) => s.trim()).filter(Boolean);
53
- if (modules.length === 0) {
54
- const fromCfg = await loadModulesFromMergerConfig();
55
- if (fromCfg) modules = fromCfg;
56
- }
57
- if (modules.length === 0) {
58
- console.error("No modules specified. Provide --modules or define prisma-merger.config.ts { modules: [...] }");
59
- process.exit(1);
60
- }
61
- const importedDir = path.join(target, "prisma", "schema", "imported");
62
- fs.mkdirSync(importedDir, { recursive: true });
63
- const entries = [];
64
- for (const mod of modules) {
65
- const pkgPath = __require.resolve(path.join(mod, "package.json"));
66
- const modRoot = path.dirname(pkgPath);
67
- const schemaPath = path.join(modRoot, "prisma", "schema.prisma");
68
- if (!fs.existsSync(schemaPath)) {
69
- console.error(`Module ${mod} missing prisma/schema.prisma`);
70
- process.exit(1);
71
- }
72
- const raw = fs.readFileSync(schemaPath, "utf8");
73
- const stripped = stripDatasourceAndGenerators(raw);
74
- const outDir = path.join(importedDir, path.basename(mod).replace(/^@/, "").replace(/\//g, "_"));
75
- fs.mkdirSync(outDir, { recursive: true });
76
- const outFile = path.join(outDir, "models.prisma");
77
- fs.writeFileSync(outFile, stripped, "utf8");
78
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
79
- entries.push({
80
- moduleName: mod,
81
- version: pkg.version || "0.0.0",
82
- sourcePath: schemaPath,
83
- sha256: sha256(raw)
84
- });
85
- }
86
- const lock = {
87
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
88
- entries
89
- };
90
- fs.writeFileSync(path.join(importedDir, "imported.lock.json"), JSON.stringify(lock, null, 2));
91
- console.log(`Imported ${entries.length} modules into ${importedDir}`);
92
- }
93
-
94
- //#endregion
95
- export { runImport };
@@ -1,20 +0,0 @@
1
- import { execa } from "execa";
2
-
3
- //#region src/commands/migrate.ts
4
- async function runMigrate(cmd, argv) {
5
- if (cmd === "migrate:dev") {
6
- await execa("prisma", ["migrate", "dev"], { stdio: "inherit" });
7
- return;
8
- }
9
- if (cmd === "migrate:deploy") {
10
- await execa("prisma", ["migrate", "deploy"], { stdio: "inherit" });
11
- return;
12
- }
13
- if (cmd === "migrate:status") {
14
- await execa("prisma", ["migrate", "status"], { stdio: "inherit" });
15
- return;
16
- }
17
- }
18
-
19
- //#endregion
20
- export { runMigrate };
@@ -1,14 +0,0 @@
1
- import { execa } from "execa";
2
-
3
- //#region src/commands/seed.ts
4
- async function runSeed(argv) {
5
- try {
6
- await execa("prisma", ["db", "seed"], { stdio: "inherit" });
7
- } catch (e) {
8
- console.warn("No prisma seed configured or seed failed.");
9
- throw e;
10
- }
11
- }
12
-
13
- //#endregion
14
- export { runSeed };
package/dist/index.d.mts DELETED
@@ -1,4 +0,0 @@
1
- import { createPrismaClientFromEnv, getSingletonClient } from "./lib/client.mjs";
2
- import { ImportLock, ImportLockEntry } from "./lib/types.mjs";
3
- import { MergedPrismaConfig, defineMergedPrismaConfig } from "./lib/config.mjs";
4
- export { ImportLock, ImportLockEntry, MergedPrismaConfig, createPrismaClientFromEnv, defineMergedPrismaConfig, getSingletonClient };
package/dist/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- import { createPrismaClientFromEnv, getSingletonClient } from "./lib/client.mjs";
2
- import { defineMergedPrismaConfig } from "./lib/config.mjs";
3
-
4
- export { createPrismaClientFromEnv, defineMergedPrismaConfig, getSingletonClient };
@@ -1,7 +0,0 @@
1
- import { PrismaClient } from "@prisma/client";
2
-
3
- //#region src/lib/client.d.ts
4
- declare function createPrismaClientFromEnv(envVar: string, fallback?: string): PrismaClient;
5
- declare function getSingletonClient(envVar?: string): PrismaClient;
6
- //#endregion
7
- export { createPrismaClientFromEnv, getSingletonClient };
@@ -1,17 +0,0 @@
1
- import { PrismaClient } from "@prisma/client";
2
- import { PrismaPg } from "@prisma/adapter-pg";
3
-
4
- //#region src/lib/client.ts
5
- const g = global;
6
- function createPrismaClientFromEnv(envVar, fallback) {
7
- const raw = process.env[envVar] || (fallback ? process.env[fallback] : void 0);
8
- if (!raw) throw new Error(`Missing database URL env: ${envVar}${fallback ? ` (or ${fallback})` : ""}`);
9
- return new PrismaClient({ adapter: new PrismaPg({ connectionString: `${raw}`.replaceAll("sslmode=require", "sslmode=disable") }) });
10
- }
11
- function getSingletonClient(envVar = "DATABASE_URL") {
12
- if (!g.__lssm_db) g.__lssm_db = createPrismaClientFromEnv(envVar);
13
- return g.__lssm_db;
14
- }
15
-
16
- //#endregion
17
- export { createPrismaClientFromEnv, getSingletonClient };
@@ -1,7 +0,0 @@
1
- //#region src/lib/config.d.ts
2
- interface MergedPrismaConfig {
3
- modules: string[];
4
- }
5
- declare function defineMergedPrismaConfig(config: MergedPrismaConfig): MergedPrismaConfig;
6
- //#endregion
7
- export { MergedPrismaConfig, defineMergedPrismaConfig };
@@ -1,7 +0,0 @@
1
- //#region src/lib/config.ts
2
- function defineMergedPrismaConfig(config) {
3
- return config;
4
- }
5
-
6
- //#endregion
7
- export { defineMergedPrismaConfig };
@@ -1,13 +0,0 @@
1
- //#region src/lib/types.d.ts
2
- interface ImportLockEntry {
3
- moduleName: string;
4
- version: string;
5
- sourcePath: string;
6
- sha256: string;
7
- }
8
- interface ImportLock {
9
- updatedAt: string;
10
- entries: ImportLockEntry[];
11
- }
12
- //#endregion
13
- export { ImportLock, ImportLockEntry };