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.
- package/TODO.md +1 -0
- package/dbmr.schema.json +1 -1
- package/package.json +1 -1
- package/src/cli/commands/generate.js +38 -15
- package/src/cli/commands/help.js +1 -1
- package/src/cli/diff-engine.js +2 -1
- package/src/cli/generate-db-manager.js +1573 -0
- package/src/cli/generate-model.js +9 -4
- package/src/cli/generate-openapi.js +40 -13
- package/src/cli/generate-route.js +7 -7
- package/src/cli/init/generators.js +36 -30
- package/src/cli/main.js +2 -2
- package/src/sqlite3/db.js +11 -0
- package/demo/.dockerignore +0 -7
- package/demo/.env.example +0 -13
- package/demo/Dockerfile +0 -20
- package/demo/app.js +0 -37
- package/demo/commons/add_migration.js +0 -43
- package/demo/commons/db.js +0 -17
- package/demo/commons/migrate.js +0 -65
- package/demo/commons/security.js +0 -30
- package/demo/commons/session.js +0 -13
- package/demo/dbmr.schema.json +0 -362
- package/demo/docs/llm.md +0 -197
- package/demo/llms.txt +0 -70
- package/demo/middleware/logger.js +0 -67
- package/demo/migrations/20260430155808_create_migrations_table.sql +0 -6
- package/demo/migrations/20260430155809_create_tables.sql +0 -207
- package/demo/models/addresses.js +0 -22
- package/demo/models/cart_items.js +0 -18
- package/demo/models/carts.js +0 -16
- package/demo/models/categories.js +0 -20
- package/demo/models/coupons.js +0 -23
- package/demo/models/order_items.js +0 -21
- package/demo/models/orders.js +0 -25
- package/demo/models/payments.js +0 -21
- package/demo/models/product_images.js +0 -18
- package/demo/models/product_reviews.js +0 -20
- package/demo/models/product_variants.js +0 -20
- package/demo/models/products.js +0 -30
- package/demo/models/shipments.js +0 -19
- package/demo/models/users.js +0 -19
- package/demo/models/wishlists.js +0 -15
- package/demo/openapi.json +0 -5872
- package/demo/package-lock.json +0 -2810
- package/demo/package.json +0 -34
- package/demo/routes/addresses.js +0 -6
- package/demo/routes/carts/cart_items.js +0 -7
- package/demo/routes/carts.js +0 -6
- package/demo/routes/categories.js +0 -6
- package/demo/routes/coupons.js +0 -6
- package/demo/routes/docs.js +0 -18
- package/demo/routes/health.js +0 -35
- package/demo/routes/index.js +0 -39
- package/demo/routes/orders/order_items.js +0 -7
- package/demo/routes/orders/payments.js +0 -7
- package/demo/routes/orders/shipments.js +0 -7
- package/demo/routes/orders.js +0 -6
- package/demo/routes/products/product_images.js +0 -7
- package/demo/routes/products/product_reviews.js +0 -7
- package/demo/routes/products/product_variants.js +0 -7
- package/demo/routes/products.js +0 -6
- package/demo/routes/users.js +0 -6
- package/demo/routes/wishlists.js +0 -6
- package/src/cli/commands/generate-llm-docs.js +0 -418
package/demo/package.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "demo",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"start": "node app.js",
|
|
9
|
-
"dev": "nodemon app.js",
|
|
10
|
-
"migrate": "node commons/migrate.js",
|
|
11
|
-
"add_migration": "node commons/add_migration.js",
|
|
12
|
-
"docker:build": "docker build -t app .",
|
|
13
|
-
"docker:up": "docker compose up -d",
|
|
14
|
-
"docker:down": "docker compose down"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [],
|
|
17
|
-
"author": "",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"type": "module",
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"db-model-router": "latest",
|
|
22
|
-
"dotenv": "latest",
|
|
23
|
-
"express": "latest",
|
|
24
|
-
"express-session": "latest",
|
|
25
|
-
"better-sqlite3": "latest",
|
|
26
|
-
"express-rate-limit": "latest",
|
|
27
|
-
"helmet": "latest",
|
|
28
|
-
"winston": "latest",
|
|
29
|
-
"swagger-ui-express": "latest"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"nodemon": "latest"
|
|
33
|
-
}
|
|
34
|
-
}
|
package/demo/routes/addresses.js
DELETED
package/demo/routes/carts.js
DELETED
package/demo/routes/coupons.js
DELETED
package/demo/routes/docs.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import swaggerUi from "swagger-ui-express";
|
|
3
|
-
import { readFileSync } from "fs";
|
|
4
|
-
import { dirname, join } from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
|
|
7
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const spec = JSON.parse(readFileSync(join(__dirname, "../openapi.json"), "utf8"));
|
|
9
|
-
|
|
10
|
-
const router = express.Router();
|
|
11
|
-
|
|
12
|
-
router.use("/", swaggerUi.serve);
|
|
13
|
-
router.get("/", swaggerUi.setup(spec, {
|
|
14
|
-
customSiteTitle: "API Documentation",
|
|
15
|
-
customCss: ".swagger-ui .topbar { display: none }",
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
export default router;
|
package/demo/routes/health.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
|
|
3
|
-
const router = express.Router();
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* GET /health
|
|
7
|
-
* Returns server health status, uptime, memory, and database connectivity.
|
|
8
|
-
*/
|
|
9
|
-
router.get("/", async (req, res) => {
|
|
10
|
-
const health = {
|
|
11
|
-
status: "ok",
|
|
12
|
-
timestamp: new Date().toISOString(),
|
|
13
|
-
uptime: process.uptime(),
|
|
14
|
-
memory: process.memoryUsage(),
|
|
15
|
-
db: { connected: false },
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
if (global.db && typeof global.db.query === "function") {
|
|
20
|
-
await global.db.query("SELECT NOW()");
|
|
21
|
-
health.db.connected = true;
|
|
22
|
-
} else if (global.db && typeof global.db.get === "function") {
|
|
23
|
-
// NoSQL adapters (mongodb, redis, dynamodb)
|
|
24
|
-
health.db.connected = true;
|
|
25
|
-
}
|
|
26
|
-
} catch (err) {
|
|
27
|
-
health.status = "degraded";
|
|
28
|
-
health.db.error = err.message;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const statusCode = health.status === "ok" ? 200 : 503;
|
|
32
|
-
res.status(statusCode).json(health);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export default router;
|
package/demo/routes/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
|
|
3
|
-
const router = express.Router();
|
|
4
|
-
|
|
5
|
-
import addressesRoute from "./addresses.js";
|
|
6
|
-
import cartsRoute from "./carts.js";
|
|
7
|
-
import categoriesRoute from "./categories.js";
|
|
8
|
-
import couponsRoute from "./coupons.js";
|
|
9
|
-
import ordersRoute from "./orders.js";
|
|
10
|
-
import productsRoute from "./products.js";
|
|
11
|
-
import usersRoute from "./users.js";
|
|
12
|
-
import wishlistsRoute from "./wishlists.js";
|
|
13
|
-
import product_imagesChildRoute from "./products/product_images.js";
|
|
14
|
-
import product_variantsChildRoute from "./products/product_variants.js";
|
|
15
|
-
import product_reviewsChildRoute from "./products/product_reviews.js";
|
|
16
|
-
import cart_itemsChildRoute from "./carts/cart_items.js";
|
|
17
|
-
import order_itemsChildRoute from "./orders/order_items.js";
|
|
18
|
-
import paymentsChildRoute from "./orders/payments.js";
|
|
19
|
-
import shipmentsChildRoute from "./orders/shipments.js";
|
|
20
|
-
import docsRoute from "./docs.js";
|
|
21
|
-
|
|
22
|
-
router.use("/docs", docsRoute);
|
|
23
|
-
router.use("/addresses", addressesRoute);
|
|
24
|
-
router.use("/carts", cartsRoute);
|
|
25
|
-
router.use("/categories", categoriesRoute);
|
|
26
|
-
router.use("/coupons", couponsRoute);
|
|
27
|
-
router.use("/orders", ordersRoute);
|
|
28
|
-
router.use("/products", productsRoute);
|
|
29
|
-
router.use("/users", usersRoute);
|
|
30
|
-
router.use("/wishlists", wishlistsRoute);
|
|
31
|
-
router.use("/products/:product_id/product_images", product_imagesChildRoute);
|
|
32
|
-
router.use("/products/:product_id/product_variants", product_variantsChildRoute);
|
|
33
|
-
router.use("/products/:product_id/product_reviews", product_reviewsChildRoute);
|
|
34
|
-
router.use("/carts/:cart_id/cart_items", cart_itemsChildRoute);
|
|
35
|
-
router.use("/orders/:order_id/order_items", order_itemsChildRoute);
|
|
36
|
-
router.use("/orders/:order_id/payments", paymentsChildRoute);
|
|
37
|
-
router.use("/orders/:order_id/shipments", shipmentsChildRoute);
|
|
38
|
-
|
|
39
|
-
export default router;
|
package/demo/routes/orders.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dbModelRouter from "db-model-router";
|
|
2
|
-
import product_images from "../../models/product_images.js";
|
|
3
|
-
|
|
4
|
-
const { route } = dbModelRouter;
|
|
5
|
-
|
|
6
|
-
// Child route: scoped by parent products via product_id
|
|
7
|
-
export default route(product_images, { product_id: "params.product_id" });
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dbModelRouter from "db-model-router";
|
|
2
|
-
import product_reviews from "../../models/product_reviews.js";
|
|
3
|
-
|
|
4
|
-
const { route } = dbModelRouter;
|
|
5
|
-
|
|
6
|
-
// Child route: scoped by parent products via product_id
|
|
7
|
-
export default route(product_reviews, { product_id: "params.product_id" });
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import dbModelRouter from "db-model-router";
|
|
2
|
-
import product_variants from "../../models/product_variants.js";
|
|
3
|
-
|
|
4
|
-
const { route } = dbModelRouter;
|
|
5
|
-
|
|
6
|
-
// Child route: scoped by parent products via product_id
|
|
7
|
-
export default route(product_variants, { product_id: "params.product_id" });
|
package/demo/routes/products.js
DELETED
package/demo/routes/users.js
DELETED
package/demo/routes/wishlists.js
DELETED
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* LLM Docs Generator
|
|
5
|
-
*
|
|
6
|
-
* Generates two documentation files optimized for LLM consumption:
|
|
7
|
-
* - llms.txt: ultra-compact CLI reference (≤200 lines)
|
|
8
|
-
* - docs/llm.md: full reference with examples, schema definition, route contract, etc.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const ADAPTERS = [
|
|
12
|
-
"mysql",
|
|
13
|
-
"postgres",
|
|
14
|
-
"sqlite3",
|
|
15
|
-
"mongodb",
|
|
16
|
-
"mssql",
|
|
17
|
-
"cockroachdb",
|
|
18
|
-
"oracle",
|
|
19
|
-
"redis",
|
|
20
|
-
"dynamodb",
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
const FRAMEWORKS = ["express", "ultimate-express"];
|
|
24
|
-
|
|
25
|
-
const SUBCOMMANDS = ["init", "inspect", "generate", "doctor", "diff"];
|
|
26
|
-
|
|
27
|
-
const UNIVERSAL_FLAGS = [
|
|
28
|
-
"--yes",
|
|
29
|
-
"--json",
|
|
30
|
-
"--dry-run",
|
|
31
|
-
"--no-install",
|
|
32
|
-
"--help",
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
const ADAPTER_CAPABILITIES = {
|
|
36
|
-
mysql: { sql: true, transactions: true, migrations: true, streaming: false },
|
|
37
|
-
postgres: {
|
|
38
|
-
sql: true,
|
|
39
|
-
transactions: true,
|
|
40
|
-
migrations: true,
|
|
41
|
-
streaming: false,
|
|
42
|
-
},
|
|
43
|
-
sqlite3: {
|
|
44
|
-
sql: true,
|
|
45
|
-
transactions: true,
|
|
46
|
-
migrations: true,
|
|
47
|
-
streaming: false,
|
|
48
|
-
},
|
|
49
|
-
mongodb: {
|
|
50
|
-
sql: false,
|
|
51
|
-
transactions: false,
|
|
52
|
-
migrations: false,
|
|
53
|
-
streaming: false,
|
|
54
|
-
},
|
|
55
|
-
mssql: { sql: true, transactions: true, migrations: true, streaming: false },
|
|
56
|
-
cockroachdb: {
|
|
57
|
-
sql: true,
|
|
58
|
-
transactions: true,
|
|
59
|
-
migrations: true,
|
|
60
|
-
streaming: false,
|
|
61
|
-
},
|
|
62
|
-
oracle: { sql: true, transactions: true, migrations: true, streaming: false },
|
|
63
|
-
redis: {
|
|
64
|
-
sql: false,
|
|
65
|
-
transactions: false,
|
|
66
|
-
migrations: false,
|
|
67
|
-
streaming: false,
|
|
68
|
-
},
|
|
69
|
-
dynamodb: {
|
|
70
|
-
sql: false,
|
|
71
|
-
transactions: false,
|
|
72
|
-
migrations: false,
|
|
73
|
-
streaming: false,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Generate the content for llms.txt — ultra-compact CLI reference (≤200 lines).
|
|
79
|
-
* @returns {string}
|
|
80
|
-
*/
|
|
81
|
-
function generateLlmsTxt() {
|
|
82
|
-
const lines = [
|
|
83
|
-
"# db-model-router — LLM Quick Reference",
|
|
84
|
-
"",
|
|
85
|
-
"## Schema File: dbmr.schema.json",
|
|
86
|
-
'{ "adapter": "<adapter>", "framework": "<framework>", "tables": { "<name>": { "columns": { "<col>": "<rule>" }, "pk": "<col>", "unique": ["<col>"], "softDelete": "<col>" } }, "relationships": [{ "parent": "<t>", "child": "<t>", "foreignKey": "<col>" }], "options": {} }',
|
|
87
|
-
"",
|
|
88
|
-
"Adapters: " + ADAPTERS.join(", "),
|
|
89
|
-
"Frameworks: " + FRAMEWORKS.join(", "),
|
|
90
|
-
'Column rules: (required|)?(string|integer|numeric|boolean|object) e.g. "required|string"',
|
|
91
|
-
"",
|
|
92
|
-
"## Universal Flags",
|
|
93
|
-
UNIVERSAL_FLAGS.join(" "),
|
|
94
|
-
"",
|
|
95
|
-
"## Commands",
|
|
96
|
-
"",
|
|
97
|
-
"### init",
|
|
98
|
-
"Scaffold a new project.",
|
|
99
|
-
" --from <schema> Read config from schema file",
|
|
100
|
-
" --framework <fw> Framework (express|ultimate-express)",
|
|
101
|
-
" --database <db> Adapter name",
|
|
102
|
-
"Example: db-model-router init --from dbmr.schema.json --yes --no-install",
|
|
103
|
-
"",
|
|
104
|
-
"### inspect",
|
|
105
|
-
"Introspect a live database and produce a schema file.",
|
|
106
|
-
" --type <adapter> Database adapter",
|
|
107
|
-
" --env <path> Path to .env file",
|
|
108
|
-
" --out <path> Output path (default: dbmr.schema.json)",
|
|
109
|
-
" --tables <list> Comma-separated table filter",
|
|
110
|
-
"Example: db-model-router inspect --type sqlite3 --env .env --out schema.json",
|
|
111
|
-
"",
|
|
112
|
-
"### generate",
|
|
113
|
-
"Generate code artifacts from schema.",
|
|
114
|
-
" --from <schema> Schema file (default: dbmr.schema.json)",
|
|
115
|
-
" --models Generate model files only",
|
|
116
|
-
" --routes Generate route files only",
|
|
117
|
-
" --openapi Generate OpenAPI spec only",
|
|
118
|
-
" --tests Generate test files only",
|
|
119
|
-
" --llm-docs Generate LLM documentation only",
|
|
120
|
-
"Example: db-model-router generate --from dbmr.schema.json",
|
|
121
|
-
"Example: db-model-router generate --models --dry-run",
|
|
122
|
-
"",
|
|
123
|
-
"### doctor",
|
|
124
|
-
"Validate schema, check dependencies, verify file sync.",
|
|
125
|
-
" --from <schema> Schema file (default: dbmr.schema.json)",
|
|
126
|
-
"Example: db-model-router doctor --from dbmr.schema.json --json",
|
|
127
|
-
"",
|
|
128
|
-
"### diff",
|
|
129
|
-
"Preview changes between schema and generated files.",
|
|
130
|
-
" --from <schema> Schema file (default: dbmr.schema.json)",
|
|
131
|
-
"Example: db-model-router diff --from dbmr.schema.json",
|
|
132
|
-
"",
|
|
133
|
-
"## Route Contract (per table)",
|
|
134
|
-
"GET /api/<table>/ List (page, size, sort, select_columns)",
|
|
135
|
-
"POST /api/<table>/ Bulk insert",
|
|
136
|
-
"PUT /api/<table>/ Bulk update",
|
|
137
|
-
"DELETE /api/<table>/ Bulk delete",
|
|
138
|
-
"GET /api/<table>/:id Get by ID",
|
|
139
|
-
"POST /api/<table>/:id Insert one",
|
|
140
|
-
"PUT /api/<table>/:id Update one",
|
|
141
|
-
"PATCH /api/<table>/:id Partial update one",
|
|
142
|
-
"DELETE /api/<table>/:id Delete one",
|
|
143
|
-
"",
|
|
144
|
-
"## Generated Files",
|
|
145
|
-
"models/<table>.js Model with CRUD operations",
|
|
146
|
-
"routes/<table>.js Express route handlers",
|
|
147
|
-
"routes/<child>_child_of_<parent>.js Child route",
|
|
148
|
-
"routes/index.js Route mounting index",
|
|
149
|
-
"test/<table>.test.js CRUD endpoint tests",
|
|
150
|
-
"openapi.json OpenAPI 3.0 spec",
|
|
151
|
-
"llms.txt This file",
|
|
152
|
-
"docs/llm.md Full LLM reference",
|
|
153
|
-
];
|
|
154
|
-
|
|
155
|
-
return lines.join("\n") + "\n";
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Generate the content for docs/llm.md — full LLM reference.
|
|
160
|
-
* @returns {string}
|
|
161
|
-
*/
|
|
162
|
-
function generateLlmMd() {
|
|
163
|
-
const sections = [];
|
|
164
|
-
|
|
165
|
-
// Title
|
|
166
|
-
sections.push("# db-model-router — LLM Reference");
|
|
167
|
-
sections.push("");
|
|
168
|
-
|
|
169
|
-
// Installation
|
|
170
|
-
sections.push("## Installation");
|
|
171
|
-
sections.push("");
|
|
172
|
-
sections.push("```bash");
|
|
173
|
-
sections.push("npm install db-model-router");
|
|
174
|
-
sections.push("```");
|
|
175
|
-
sections.push("");
|
|
176
|
-
|
|
177
|
-
// Workflow
|
|
178
|
-
sections.push("## Canonical Schema-Driven Workflow");
|
|
179
|
-
sections.push("");
|
|
180
|
-
sections.push("1. Create or inspect a `dbmr.schema.json` schema file");
|
|
181
|
-
sections.push(
|
|
182
|
-
"2. Run `db-model-router generate --from dbmr.schema.json` to generate all artifacts",
|
|
183
|
-
);
|
|
184
|
-
sections.push(
|
|
185
|
-
"3. Run `db-model-router doctor` to validate schema and check sync",
|
|
186
|
-
);
|
|
187
|
-
sections.push(
|
|
188
|
-
"4. Run `db-model-router diff` to preview changes before regenerating",
|
|
189
|
-
);
|
|
190
|
-
sections.push("5. Edit the schema file and repeat from step 2");
|
|
191
|
-
sections.push("");
|
|
192
|
-
|
|
193
|
-
// Schema Definition
|
|
194
|
-
sections.push("## Schema Definition");
|
|
195
|
-
sections.push("");
|
|
196
|
-
sections.push(
|
|
197
|
-
"The `dbmr.schema.json` file is the single source of truth for your project.",
|
|
198
|
-
);
|
|
199
|
-
sections.push("");
|
|
200
|
-
sections.push("```json");
|
|
201
|
-
sections.push(
|
|
202
|
-
JSON.stringify(
|
|
203
|
-
{
|
|
204
|
-
adapter: "<adapter>",
|
|
205
|
-
framework: "<framework>",
|
|
206
|
-
tables: {
|
|
207
|
-
"<table_name>": {
|
|
208
|
-
columns: {
|
|
209
|
-
"<column_name>": "<column_rule>",
|
|
210
|
-
},
|
|
211
|
-
pk: "<primary_key_column>",
|
|
212
|
-
unique: ["<column_name>"],
|
|
213
|
-
softDelete: "<column_name>",
|
|
214
|
-
timestamps: {
|
|
215
|
-
created_at: "<column_name>",
|
|
216
|
-
modified_at: "<column_name>",
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
relationships: [
|
|
221
|
-
{ parent: "<table>", child: "<table>", foreignKey: "<column>" },
|
|
222
|
-
],
|
|
223
|
-
options: {},
|
|
224
|
-
},
|
|
225
|
-
null,
|
|
226
|
-
2,
|
|
227
|
-
),
|
|
228
|
-
);
|
|
229
|
-
sections.push("```");
|
|
230
|
-
sections.push("");
|
|
231
|
-
sections.push("### Adapters");
|
|
232
|
-
sections.push("");
|
|
233
|
-
sections.push("| Adapter | Description |");
|
|
234
|
-
sections.push("|---------|-------------|");
|
|
235
|
-
for (const a of ADAPTERS) {
|
|
236
|
-
sections.push(`| ${a} | ${a} database adapter |`);
|
|
237
|
-
}
|
|
238
|
-
sections.push("");
|
|
239
|
-
sections.push("### Frameworks");
|
|
240
|
-
sections.push("");
|
|
241
|
-
sections.push("| Framework | Description |");
|
|
242
|
-
sections.push("|-----------|-------------|");
|
|
243
|
-
for (const f of FRAMEWORKS) {
|
|
244
|
-
sections.push(`| ${f} | ${f} HTTP framework |`);
|
|
245
|
-
}
|
|
246
|
-
sections.push("");
|
|
247
|
-
sections.push("### Column Rules");
|
|
248
|
-
sections.push("");
|
|
249
|
-
sections.push(
|
|
250
|
-
"Column rules use pipe-delimited tokens: `(required|)?(string|integer|numeric|boolean|object)`",
|
|
251
|
-
);
|
|
252
|
-
sections.push("");
|
|
253
|
-
sections.push(
|
|
254
|
-
'Examples: `"required|string"`, `"integer"`, `"required|boolean"`, `"object"`',
|
|
255
|
-
);
|
|
256
|
-
sections.push("");
|
|
257
|
-
|
|
258
|
-
// CLI Commands
|
|
259
|
-
sections.push("## CLI Commands");
|
|
260
|
-
sections.push("");
|
|
261
|
-
sections.push(
|
|
262
|
-
"All commands support universal flags: " +
|
|
263
|
-
UNIVERSAL_FLAGS.map((f) => "`" + f + "`").join(", "),
|
|
264
|
-
);
|
|
265
|
-
sections.push("");
|
|
266
|
-
|
|
267
|
-
// init
|
|
268
|
-
sections.push("### init");
|
|
269
|
-
sections.push("");
|
|
270
|
-
sections.push("Scaffold a new project from a schema file or interactively.");
|
|
271
|
-
sections.push("");
|
|
272
|
-
sections.push("```bash");
|
|
273
|
-
sections.push("# From schema file, non-interactive");
|
|
274
|
-
sections.push(
|
|
275
|
-
"db-model-router init --from dbmr.schema.json --yes --no-install",
|
|
276
|
-
);
|
|
277
|
-
sections.push("");
|
|
278
|
-
sections.push("# Interactive with defaults");
|
|
279
|
-
sections.push(
|
|
280
|
-
"db-model-router init --framework express --database sqlite3 --yes",
|
|
281
|
-
);
|
|
282
|
-
sections.push("");
|
|
283
|
-
sections.push("# Dry run to preview");
|
|
284
|
-
sections.push("db-model-router init --from dbmr.schema.json --dry-run");
|
|
285
|
-
sections.push("```");
|
|
286
|
-
sections.push("");
|
|
287
|
-
sections.push("| Flag | Description |");
|
|
288
|
-
sections.push("|------|-------------|");
|
|
289
|
-
sections.push("| `--from <path>` | Read config from schema file |");
|
|
290
|
-
sections.push(
|
|
291
|
-
"| `--framework <fw>` | Framework: express, ultimate-express |",
|
|
292
|
-
);
|
|
293
|
-
sections.push("| `--database <db>` | Adapter name |");
|
|
294
|
-
sections.push("");
|
|
295
|
-
|
|
296
|
-
// inspect
|
|
297
|
-
sections.push("### inspect");
|
|
298
|
-
sections.push("");
|
|
299
|
-
sections.push("Introspect a live database and produce a schema file.");
|
|
300
|
-
sections.push("");
|
|
301
|
-
sections.push("```bash");
|
|
302
|
-
sections.push(
|
|
303
|
-
"db-model-router inspect --type postgres --env .env --out dbmr.schema.json",
|
|
304
|
-
);
|
|
305
|
-
sections.push(
|
|
306
|
-
"db-model-router inspect --type sqlite3 --tables users,posts --json",
|
|
307
|
-
);
|
|
308
|
-
sections.push("```");
|
|
309
|
-
sections.push("");
|
|
310
|
-
sections.push("| Flag | Description |");
|
|
311
|
-
sections.push("|------|-------------|");
|
|
312
|
-
sections.push("| `--type <adapter>` | Database adapter to use |");
|
|
313
|
-
sections.push("| `--env <path>` | Path to .env file |");
|
|
314
|
-
sections.push("| `--out <path>` | Output file (default: dbmr.schema.json) |");
|
|
315
|
-
sections.push("| `--tables <list>` | Comma-separated table filter |");
|
|
316
|
-
sections.push("");
|
|
317
|
-
|
|
318
|
-
// generate
|
|
319
|
-
sections.push("### generate");
|
|
320
|
-
sections.push("");
|
|
321
|
-
sections.push("Generate code artifacts from the schema file.");
|
|
322
|
-
sections.push("");
|
|
323
|
-
sections.push("```bash");
|
|
324
|
-
sections.push("# Generate all artifacts");
|
|
325
|
-
sections.push("db-model-router generate --from dbmr.schema.json");
|
|
326
|
-
sections.push("");
|
|
327
|
-
sections.push("# Generate only models");
|
|
328
|
-
sections.push("db-model-router generate --models");
|
|
329
|
-
sections.push("");
|
|
330
|
-
sections.push("# Generate only routes");
|
|
331
|
-
sections.push("db-model-router generate --routes");
|
|
332
|
-
sections.push("");
|
|
333
|
-
sections.push("# Preview with dry-run");
|
|
334
|
-
sections.push("db-model-router generate --dry-run --json");
|
|
335
|
-
sections.push("");
|
|
336
|
-
sections.push("# Generate LLM docs only");
|
|
337
|
-
sections.push("db-model-router generate --llm-docs");
|
|
338
|
-
sections.push("```");
|
|
339
|
-
sections.push("");
|
|
340
|
-
sections.push("| Flag | Description |");
|
|
341
|
-
sections.push("|------|-------------|");
|
|
342
|
-
sections.push(
|
|
343
|
-
"| `--from <path>` | Schema file (default: dbmr.schema.json) |",
|
|
344
|
-
);
|
|
345
|
-
sections.push("| `--models` | Generate model files only |");
|
|
346
|
-
sections.push("| `--routes` | Generate route files only |");
|
|
347
|
-
sections.push("| `--openapi` | Generate OpenAPI spec only |");
|
|
348
|
-
sections.push("| `--tests` | Generate test files only |");
|
|
349
|
-
sections.push("| `--llm-docs` | Generate LLM documentation only |");
|
|
350
|
-
sections.push("");
|
|
351
|
-
|
|
352
|
-
// doctor
|
|
353
|
-
sections.push("### doctor");
|
|
354
|
-
sections.push("");
|
|
355
|
-
sections.push(
|
|
356
|
-
"Validate schema, check dependencies, and verify generated files are in sync.",
|
|
357
|
-
);
|
|
358
|
-
sections.push("");
|
|
359
|
-
sections.push("```bash");
|
|
360
|
-
sections.push("db-model-router doctor --from dbmr.schema.json");
|
|
361
|
-
sections.push("db-model-router doctor --json");
|
|
362
|
-
sections.push("```");
|
|
363
|
-
sections.push("");
|
|
364
|
-
|
|
365
|
-
// diff
|
|
366
|
-
sections.push("### diff");
|
|
367
|
-
sections.push("");
|
|
368
|
-
sections.push(
|
|
369
|
-
"Preview changes between the schema and currently generated files.",
|
|
370
|
-
);
|
|
371
|
-
sections.push("");
|
|
372
|
-
sections.push("```bash");
|
|
373
|
-
sections.push("db-model-router diff --from dbmr.schema.json");
|
|
374
|
-
sections.push("db-model-router diff --json");
|
|
375
|
-
sections.push("```");
|
|
376
|
-
sections.push("");
|
|
377
|
-
|
|
378
|
-
// Route Contract
|
|
379
|
-
sections.push("## Route Contract");
|
|
380
|
-
sections.push("");
|
|
381
|
-
sections.push("Each table generates 9 endpoints:");
|
|
382
|
-
sections.push("");
|
|
383
|
-
sections.push("| Method | Path | Description |");
|
|
384
|
-
sections.push("|--------|------|-------------|");
|
|
385
|
-
sections.push(
|
|
386
|
-
"| GET | `/api/<table>/` | List with pagination (page, size, sort, select_columns) |",
|
|
387
|
-
);
|
|
388
|
-
sections.push("| POST | `/api/<table>/` | Bulk insert |");
|
|
389
|
-
sections.push("| PUT | `/api/<table>/` | Bulk update |");
|
|
390
|
-
sections.push("| DELETE | `/api/<table>/` | Bulk delete |");
|
|
391
|
-
sections.push(
|
|
392
|
-
"| GET | `/api/<table>/:id` | Get single record by primary key |",
|
|
393
|
-
);
|
|
394
|
-
sections.push("| POST | `/api/<table>/:id` | Insert single record |");
|
|
395
|
-
sections.push("| PUT | `/api/<table>/:id` | Update single record |");
|
|
396
|
-
sections.push(
|
|
397
|
-
"| PATCH | `/api/<table>/:id` | Partial update single record |",
|
|
398
|
-
);
|
|
399
|
-
sections.push("| DELETE | `/api/<table>/:id` | Delete single record |");
|
|
400
|
-
sections.push("");
|
|
401
|
-
|
|
402
|
-
// Adapter Capability Matrix
|
|
403
|
-
sections.push("## Adapter Capability Matrix");
|
|
404
|
-
sections.push("");
|
|
405
|
-
sections.push("| Adapter | SQL | Transactions | Migrations | Streaming |");
|
|
406
|
-
sections.push("|---------|-----|--------------|------------|-----------|");
|
|
407
|
-
for (const [adapter, caps] of Object.entries(ADAPTER_CAPABILITIES)) {
|
|
408
|
-
const yn = (v) => (v ? "Yes" : "No");
|
|
409
|
-
sections.push(
|
|
410
|
-
`| ${adapter} | ${yn(caps.sql)} | ${yn(caps.transactions)} | ${yn(caps.migrations)} | ${yn(caps.streaming)} |`,
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
sections.push("");
|
|
414
|
-
|
|
415
|
-
return sections.join("\n") + "\n";
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
module.exports = { generateLlmsTxt, generateLlmMd };
|