db-model-router 1.0.5 → 1.0.6

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 (65) hide show
  1. package/TODO.md +1 -0
  2. package/dbmr.schema.json +1 -1
  3. package/package.json +1 -1
  4. package/src/cli/commands/generate.js +38 -15
  5. package/src/cli/commands/help.js +1 -1
  6. package/src/cli/diff-engine.js +2 -1
  7. package/src/cli/generate-db-manager.js +1573 -0
  8. package/src/cli/generate-model.js +9 -4
  9. package/src/cli/generate-openapi.js +40 -13
  10. package/src/cli/generate-route.js +7 -7
  11. package/src/cli/init/generators.js +36 -30
  12. package/src/cli/main.js +2 -2
  13. package/src/sqlite3/db.js +11 -0
  14. package/demo/.dockerignore +0 -7
  15. package/demo/.env.example +0 -13
  16. package/demo/Dockerfile +0 -20
  17. package/demo/app.js +0 -37
  18. package/demo/commons/add_migration.js +0 -43
  19. package/demo/commons/db.js +0 -17
  20. package/demo/commons/migrate.js +0 -65
  21. package/demo/commons/security.js +0 -30
  22. package/demo/commons/session.js +0 -13
  23. package/demo/dbmr.schema.json +0 -362
  24. package/demo/docs/llm.md +0 -197
  25. package/demo/llms.txt +0 -70
  26. package/demo/middleware/logger.js +0 -67
  27. package/demo/migrations/20260430155808_create_migrations_table.sql +0 -6
  28. package/demo/migrations/20260430155809_create_tables.sql +0 -207
  29. package/demo/models/addresses.js +0 -22
  30. package/demo/models/cart_items.js +0 -18
  31. package/demo/models/carts.js +0 -16
  32. package/demo/models/categories.js +0 -20
  33. package/demo/models/coupons.js +0 -23
  34. package/demo/models/order_items.js +0 -21
  35. package/demo/models/orders.js +0 -25
  36. package/demo/models/payments.js +0 -21
  37. package/demo/models/product_images.js +0 -18
  38. package/demo/models/product_reviews.js +0 -20
  39. package/demo/models/product_variants.js +0 -20
  40. package/demo/models/products.js +0 -30
  41. package/demo/models/shipments.js +0 -19
  42. package/demo/models/users.js +0 -19
  43. package/demo/models/wishlists.js +0 -15
  44. package/demo/openapi.json +0 -5872
  45. package/demo/package-lock.json +0 -2810
  46. package/demo/package.json +0 -34
  47. package/demo/routes/addresses.js +0 -6
  48. package/demo/routes/carts/cart_items.js +0 -7
  49. package/demo/routes/carts.js +0 -6
  50. package/demo/routes/categories.js +0 -6
  51. package/demo/routes/coupons.js +0 -6
  52. package/demo/routes/docs.js +0 -18
  53. package/demo/routes/health.js +0 -35
  54. package/demo/routes/index.js +0 -39
  55. package/demo/routes/orders/order_items.js +0 -7
  56. package/demo/routes/orders/payments.js +0 -7
  57. package/demo/routes/orders/shipments.js +0 -7
  58. package/demo/routes/orders.js +0 -6
  59. package/demo/routes/products/product_images.js +0 -7
  60. package/demo/routes/products/product_reviews.js +0 -7
  61. package/demo/routes/products/product_variants.js +0 -7
  62. package/demo/routes/products.js +0 -6
  63. package/demo/routes/users.js +0 -6
  64. package/demo/routes/wishlists.js +0 -6
  65. package/src/cli/commands/generate-llm-docs.js +0 -418
package/TODO.md CHANGED
@@ -12,3 +12,4 @@ Main page will have 3 tabs
12
12
  This needs to added in route like /database
13
13
 
14
14
  The api that this will use is POST /database/login, GET /database/tables, GET /database/tables/:table_name?sort=1&size=30&post_name=%title%
15
+ the UI should be able to filter,sort and move through the pages
package/dbmr.schema.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "adapter": "sqlite3",
3
3
  "framework": "express",
4
4
  "options": {
5
- "session": "redis",
5
+ "session": "memory",
6
6
  "rateLimiting": true,
7
7
  "helmet": true,
8
8
  "logger": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "db-model-router",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Generative API Creation using mysql2 and express libraries in node js",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -13,9 +13,9 @@ const {
13
13
  generateChildTestFile,
14
14
  } = require("../generate-route");
15
15
  const { generateOpenAPISpec } = require("../generate-openapi");
16
- const { generateLlmsTxt, generateLlmMd } = require("./generate-llm-docs");
17
16
  const { generateMigrationFiles } = require("../generate-migration");
18
17
  const { generateDocsRoute } = require("../generate-docs-route");
18
+ const { generateDbManager } = require("../generate-db-manager");
19
19
  const { migrationTimestamp } = require("../init/generators");
20
20
 
21
21
  /**
@@ -31,7 +31,7 @@ const { migrationTimestamp } = require("../init/generators");
31
31
  * --openapi Generate only OpenAPI spec + docs route
32
32
  * --tests Generate only test files
33
33
  * --migrations Generate only migration files
34
- * --llm-docs Generate only LLM documentation
34
+ * --db-manager Generate DB Manager UI (SQL adapters only)
35
35
  * --dry-run Report planned files without writing
36
36
  * --json Output JSON result via ctx
37
37
  *
@@ -86,14 +86,15 @@ async function generate(args, flags, ctx) {
86
86
  args.openapi === true ||
87
87
  args.tests === true ||
88
88
  args.migrations === true ||
89
- args["llm-docs"] === true;
89
+ args["db-manager"] === true;
90
90
 
91
91
  const genModels = !hasArtifactFlag || args.models === true;
92
92
  const genRoutes = !hasArtifactFlag || args.routes === true;
93
93
  const genOpenapi = !hasArtifactFlag || args.openapi === true;
94
94
  const genTests = !hasArtifactFlag || args.tests === true;
95
95
  const genMigrations = !hasArtifactFlag || args.migrations === true;
96
- const genLlmDocs = !hasArtifactFlag || args["llm-docs"] === true;
96
+ //const genDbManager = !hasArtifactFlag || args["db-manager"] === true;
97
+ const genDbManager = false;
97
98
 
98
99
  const modelsRelPath = "../models";
99
100
  const baseDir = process.cwd();
@@ -154,7 +155,9 @@ async function generate(args, flags, ctx) {
154
155
  if (genOpenapi) {
155
156
  planned.push({
156
157
  relPath: "openapi.json",
157
- content: JSON.stringify(generateOpenAPISpec(meta), null, 2) + "\n",
158
+ content:
159
+ JSON.stringify(generateOpenAPISpec(meta, { relationships }), null, 2) +
160
+ "\n",
158
161
  });
159
162
 
160
163
  // Generate Swagger UI docs route
@@ -208,16 +211,36 @@ async function generate(args, flags, ctx) {
208
211
  }
209
212
  }
210
213
 
211
- // --- LLM docs ---
212
- if (genLlmDocs) {
213
- planned.push({
214
- relPath: "llms.txt",
215
- content: generateLlmsTxt(),
216
- });
217
- planned.push({
218
- relPath: "docs/llm.md",
219
- content: generateLlmMd(),
220
- });
214
+ // --- DB Manager ---
215
+ if (genDbManager) {
216
+ const dbmOptions = {};
217
+ const envPath = path.join(baseDir, ".env");
218
+ const envExamplePath = path.join(baseDir, ".env.example");
219
+ const appJsPath = path.join(baseDir, "app.js");
220
+ const pkgJsonPath = path.join(baseDir, "package.json");
221
+
222
+ if (fs.existsSync(envPath)) {
223
+ dbmOptions.envContent = fs.readFileSync(envPath, "utf8");
224
+ }
225
+ if (fs.existsSync(envExamplePath)) {
226
+ dbmOptions.envExampleContent = fs.readFileSync(envExamplePath, "utf8");
227
+ }
228
+ if (fs.existsSync(appJsPath)) {
229
+ dbmOptions.appJsContent = fs.readFileSync(appJsPath, "utf8");
230
+ }
231
+ if (fs.existsSync(pkgJsonPath)) {
232
+ dbmOptions.packageJsonContent = fs.readFileSync(pkgJsonPath, "utf8");
233
+ }
234
+
235
+ const dbmResult = generateDbManager(schema, dbmOptions);
236
+
237
+ for (const f of dbmResult.files) {
238
+ planned.push(f);
239
+ }
240
+
241
+ for (const w of dbmResult.warnings) {
242
+ ctx.log(` warning: ${w}`);
243
+ }
221
244
  }
222
245
 
223
246
  // --- Process planned files ---
@@ -82,7 +82,7 @@ Options:
82
82
  --openapi Generate only OpenAPI spec + Swagger UI docs route
83
83
  --tests Generate only test files
84
84
  --migrations Generate only database migration files
85
- --llm-docs Generate only LLM documentation (llms.txt + docs/llm.md)
85
+ --db-manager Generate DB Manager UI (SQL adapters only)
86
86
  --yes Accept all defaults without prompting
87
87
  --json Output machine-readable JSON
88
88
  --dry-run Report planned files without writing
@@ -117,7 +117,8 @@ function buildExpectedFiles(meta, relationships) {
117
117
  // OpenAPI spec
118
118
  expected.set(
119
119
  "openapi.json",
120
- JSON.stringify(generateOpenAPISpec(meta), null, 2) + "\n",
120
+ JSON.stringify(generateOpenAPISpec(meta, { relationships }), null, 2) +
121
+ "\n",
121
122
  );
122
123
 
123
124
  return expected;