db-model-router 1.0.0 → 1.0.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.
- package/README.md +154 -203
- package/docker-compose.yml +13 -9
- package/docs/SKILL.md +196 -24
- package/docs/adapters/cockroachdb.md +1 -1
- package/docs/adapters/dynamodb.md +1 -1
- package/docs/adapters/mongodb.md +1 -1
- package/docs/adapters/mssql.md +1 -1
- package/docs/adapters/oracle.md +1 -1
- package/docs/adapters/postgres.md +1 -1
- package/docs/adapters/redis.md +1 -1
- package/docs/adapters/sqlite3.md +1 -1
- package/package.json +7 -12
- package/src/cli/commands/diff.js +114 -0
- package/src/cli/commands/doctor.js +181 -0
- package/src/cli/commands/generate-llm-docs.js +418 -0
- package/src/cli/commands/generate.js +240 -0
- package/src/cli/commands/init.js +153 -0
- package/src/cli/commands/inspect.js +205 -0
- package/src/cli/diff-engine.js +198 -0
- package/src/cli/flags.js +112 -0
- package/src/cli/generate-model.js +4 -4
- package/src/cli/generate-openapi.js +5 -1
- package/src/cli/generate-route.js +242 -7
- package/src/cli/init/dependencies.js +83 -0
- package/src/cli/init/generators.js +782 -0
- package/src/cli/init/prompt.js +159 -0
- package/src/cli/init.js +281 -0
- package/src/cli/main.js +95 -0
- package/src/commons/model.js +5 -6
- package/src/commons/route.js +24 -0
- package/src/schema/schema-parser.js +78 -0
- package/src/schema/schema-printer.js +81 -0
- package/src/schema/schema-to-meta.js +74 -0
- package/src/schema/schema-validator.js +253 -0
- package/src/serve.js +7 -10
- package/docs/README.md +0 -208
- package/src/cli/generate-app.js +0 -359
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { parseSchema } = require("../../schema/schema-parser");
|
|
6
|
+
const { SchemaValidationError } = require("../../schema/schema-validator");
|
|
7
|
+
const { schemaToModelMeta } = require("../../schema/schema-to-meta");
|
|
8
|
+
const { computeDiff } = require("../diff-engine");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Adapter-to-driver mapping.
|
|
12
|
+
* Maps each supported adapter to the npm package name required.
|
|
13
|
+
*/
|
|
14
|
+
const ADAPTER_DRIVER_MAP = {
|
|
15
|
+
mysql: "mysql2",
|
|
16
|
+
postgres: "pg",
|
|
17
|
+
sqlite3: "better-sqlite3",
|
|
18
|
+
mongodb: "mongodb",
|
|
19
|
+
mssql: "tedious",
|
|
20
|
+
cockroachdb: "pg",
|
|
21
|
+
oracle: "oracledb",
|
|
22
|
+
redis: "redis",
|
|
23
|
+
dynamodb: "@aws-sdk/client-dynamodb",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Doctor command handler for the unified CLI.
|
|
28
|
+
*
|
|
29
|
+
* Validates the schema, checks adapter driver dependencies in package.json,
|
|
30
|
+
* and verifies generated files are in sync with the schema.
|
|
31
|
+
*
|
|
32
|
+
* Supported flags:
|
|
33
|
+
* --from Path to schema file (default: dbmr.schema.json)
|
|
34
|
+
* --json Output JSON result via ctx
|
|
35
|
+
*
|
|
36
|
+
* @param {object} args - Parsed key-value args
|
|
37
|
+
* @param {object} flags - Universal flags: { yes, json, dryRun, noInstall, help }
|
|
38
|
+
* @param {import('../flags').OutputContext} ctx - Output context
|
|
39
|
+
*/
|
|
40
|
+
async function doctor(args, flags, ctx) {
|
|
41
|
+
const schemaFile = args.from || "dbmr.schema.json";
|
|
42
|
+
const schemaPath = path.resolve(schemaFile);
|
|
43
|
+
const baseDir = process.cwd();
|
|
44
|
+
|
|
45
|
+
// --- 1. Schema validation ---
|
|
46
|
+
const validation = { valid: true, errors: [] };
|
|
47
|
+
let schema = null;
|
|
48
|
+
|
|
49
|
+
if (!fs.existsSync(schemaPath)) {
|
|
50
|
+
validation.valid = false;
|
|
51
|
+
validation.errors.push({
|
|
52
|
+
path: "",
|
|
53
|
+
message: `Schema file not found: ${schemaFile}`,
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
try {
|
|
57
|
+
const raw = fs.readFileSync(schemaPath, "utf8");
|
|
58
|
+
schema = parseSchema(raw);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
validation.valid = false;
|
|
61
|
+
if (err instanceof SchemaValidationError) {
|
|
62
|
+
validation.errors = err.errors;
|
|
63
|
+
} else {
|
|
64
|
+
validation.errors.push({ path: "", message: err.message });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// --- 2. Dependency check ---
|
|
70
|
+
const dependencies = { ok: true, missing: [] };
|
|
71
|
+
|
|
72
|
+
if (schema) {
|
|
73
|
+
const driver = ADAPTER_DRIVER_MAP[schema.adapter];
|
|
74
|
+
if (driver) {
|
|
75
|
+
const pkgPath = path.join(baseDir, "package.json");
|
|
76
|
+
if (fs.existsSync(pkgPath)) {
|
|
77
|
+
try {
|
|
78
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
79
|
+
const allDeps = Object.assign(
|
|
80
|
+
{},
|
|
81
|
+
pkg.dependencies || {},
|
|
82
|
+
pkg.devDependencies || {},
|
|
83
|
+
);
|
|
84
|
+
if (!allDeps[driver]) {
|
|
85
|
+
dependencies.ok = false;
|
|
86
|
+
dependencies.missing.push({
|
|
87
|
+
adapter: schema.adapter,
|
|
88
|
+
driver,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
} catch (_) {
|
|
92
|
+
// If package.json is unreadable, report driver as missing
|
|
93
|
+
dependencies.ok = false;
|
|
94
|
+
dependencies.missing.push({
|
|
95
|
+
adapter: schema.adapter,
|
|
96
|
+
driver,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
dependencies.ok = false;
|
|
101
|
+
dependencies.missing.push({
|
|
102
|
+
adapter: schema.adapter,
|
|
103
|
+
driver,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- 3. Sync check ---
|
|
110
|
+
const sync = { ok: true, outOfSync: [] };
|
|
111
|
+
|
|
112
|
+
if (schema) {
|
|
113
|
+
const meta = schemaToModelMeta(schema);
|
|
114
|
+
const relationships = schema.relationships || [];
|
|
115
|
+
const diff = computeDiff(baseDir, meta, relationships);
|
|
116
|
+
|
|
117
|
+
if (
|
|
118
|
+
diff.added.length > 0 ||
|
|
119
|
+
diff.modified.length > 0 ||
|
|
120
|
+
diff.deleted.length > 0
|
|
121
|
+
) {
|
|
122
|
+
sync.ok = false;
|
|
123
|
+
for (const f of diff.added) {
|
|
124
|
+
sync.outOfSync.push({ file: f, status: "missing" });
|
|
125
|
+
}
|
|
126
|
+
for (const m of diff.modified) {
|
|
127
|
+
sync.outOfSync.push({ file: m.file, status: "modified" });
|
|
128
|
+
}
|
|
129
|
+
for (const f of diff.deleted) {
|
|
130
|
+
sync.outOfSync.push({ file: f, status: "extra" });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// --- 4. Report results ---
|
|
136
|
+
const allPass = validation.valid && dependencies.ok && sync.ok;
|
|
137
|
+
const report = { validation, dependencies, sync };
|
|
138
|
+
|
|
139
|
+
if (flags.json) {
|
|
140
|
+
ctx.result(report);
|
|
141
|
+
} else {
|
|
142
|
+
// Validation
|
|
143
|
+
if (validation.valid) {
|
|
144
|
+
ctx.log("✓ Schema validation passed");
|
|
145
|
+
} else {
|
|
146
|
+
ctx.log("✗ Schema validation failed:");
|
|
147
|
+
for (const e of validation.errors) {
|
|
148
|
+
const loc = e.path ? ` (${e.path})` : "";
|
|
149
|
+
ctx.log(` ${e.message}${loc}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Dependencies
|
|
154
|
+
if (dependencies.ok) {
|
|
155
|
+
ctx.log("✓ Dependencies OK");
|
|
156
|
+
} else {
|
|
157
|
+
ctx.log("✗ Missing dependencies:");
|
|
158
|
+
for (const m of dependencies.missing) {
|
|
159
|
+
ctx.log(` ${m.adapter} requires "${m.driver}" in package.json`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Sync
|
|
164
|
+
if (sync.ok) {
|
|
165
|
+
ctx.log("✓ Generated files in sync");
|
|
166
|
+
} else {
|
|
167
|
+
ctx.log("✗ Files out of sync:");
|
|
168
|
+
for (const s of sync.outOfSync) {
|
|
169
|
+
ctx.log(` ${s.file} (${s.status})`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// --- 5. Exit code ---
|
|
175
|
+
if (!allPass) {
|
|
176
|
+
process.exitCode = 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
module.exports = doctor;
|
|
181
|
+
module.exports.ADAPTER_DRIVER_MAP = ADAPTER_DRIVER_MAP;
|
|
@@ -0,0 +1,418 @@
|
|
|
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 };
|