litedbmodel-gen 0.3.3 → 0.4.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/README.md +185 -49
- package/cli-contract.yaml +420 -6
- package/dist/chunk-2H7UOFLK.js +11 -0
- package/dist/chunk-2H7UOFLK.js.map +1 -0
- package/dist/cli.js +559 -20
- package/dist/cli.js.map +1 -1
- package/dist/dsl-4DLYIQ4T.js +14842 -0
- package/dist/dsl-4DLYIQ4T.js.map +1 -0
- package/docs/cli-reference.md +171 -5
- package/package.json +30 -4
package/docs/cli-reference.md
CHANGED
|
@@ -8,6 +8,8 @@ embedoc-based model code generator for litedbmodel. Parses SQL DDL (PostgreSQL /
|
|
|
8
8
|
|
|
9
9
|
- [litedbmodel-gen](#litedbmodel-gen)
|
|
10
10
|
- [init](#litedbmodel-gen-init)
|
|
11
|
+
- [audit](#litedbmodel-gen-audit)
|
|
12
|
+
- [implement](#litedbmodel-gen-implement)
|
|
11
13
|
|
|
12
14
|
---
|
|
13
15
|
|
|
@@ -52,21 +54,185 @@ litedbmodel-gen init path/to/embedoc.config.yaml
|
|
|
52
54
|
- **Generated files:**
|
|
53
55
|
- `.embedoc/templates/model.hbs` (text/x-handlebars-template) *(optional)*
|
|
54
56
|
|
|
55
|
-
**Exit 1:** Setup failed
|
|
57
|
+
**Exit 1:** Setup failed due to an unexpected file operation error.
|
|
56
58
|
|
|
57
59
|
- **stderr:** format=`text`
|
|
58
60
|
|
|
61
|
+
**Exit 3:** Input validation failed. The specified embedoc.config.yaml path was not found. Run "npx embedoc init" first.
|
|
62
|
+
|
|
63
|
+
- **stderr:** format=`json`
|
|
64
|
+
|
|
59
65
|
#### Extensions
|
|
60
66
|
|
|
61
67
|
```yaml
|
|
62
68
|
x-agent:
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
riskLevel: low
|
|
70
|
+
requiresConfirmation: false
|
|
65
71
|
idempotent: true
|
|
66
|
-
|
|
72
|
+
sideEffects:
|
|
67
73
|
- file_write
|
|
68
|
-
|
|
74
|
+
recommendedBeforeUse:
|
|
69
75
|
- Run "npx embedoc init" first to create embedoc.config.yaml.
|
|
70
76
|
```
|
|
71
77
|
|
|
72
78
|
---
|
|
79
|
+
|
|
80
|
+
### audit
|
|
81
|
+
|
|
82
|
+
Audit litedbmodel usage code for common anti-patterns.
|
|
83
|
+
|
|
84
|
+
Scans TypeScript source files that import or use litedbmodel models, detecting anti-patterns such as loop-insert (use createMany), delete-then-reinsert (use upsert), N+1 queries, missing idempotency guards, missing UNIQUE constraints for onConflict, over-broad deletes, and missing forUpdate in concurrent-write paths. Returns structured findings with severity ratings and remediation guidance referencing the correct litedbmodel API.
|
|
85
|
+
|
|
86
|
+
**Usage:**
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
litedbmodel-gen audit
|
|
90
|
+
```
|
|
91
|
+
```
|
|
92
|
+
litedbmodel-gen audit src/
|
|
93
|
+
```
|
|
94
|
+
```
|
|
95
|
+
litedbmodel-gen audit src/services/user-service.ts --fail-on warning --report-format text
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Arguments
|
|
99
|
+
|
|
100
|
+
| Name | Required | Description |
|
|
101
|
+
|---|---|---|
|
|
102
|
+
| `target` | No | File or directory path to audit. Defaults to the current working directory. |
|
|
103
|
+
|
|
104
|
+
#### Options
|
|
105
|
+
|
|
106
|
+
| Option | Aliases | Required | Default | Description |
|
|
107
|
+
|---|---|---|---|---|
|
|
108
|
+
| `--adapter` | | No | `"mock"` | LLM adapter to use for the audit. |
|
|
109
|
+
| `--model` | | No | | Model name override for the selected adapter. |
|
|
110
|
+
| `--dry-run` | | No | `false` | Output the constructed prompt without calling the LLM. |
|
|
111
|
+
| `--fail-on` | | No | `"error"` | Minimum finding severity that causes exit code 10. Findings below this threshold are still reported. |
|
|
112
|
+
| `--output` | -o | No | | Write the report to a file instead of stdout. |
|
|
113
|
+
| `--report-format` | | No | `"json"` | Output format for the audit report. |
|
|
114
|
+
|
|
115
|
+
#### Exit Codes
|
|
116
|
+
|
|
117
|
+
**Exit 0:** Audit completed. No findings at or above the --fail-on threshold.
|
|
118
|
+
|
|
119
|
+
- **stdout:** format=`json`
|
|
120
|
+
|
|
121
|
+
**Exit 1:** General error (unexpected exception or I/O failure).
|
|
122
|
+
|
|
123
|
+
- **stderr:** format=`text`
|
|
124
|
+
|
|
125
|
+
**Exit 3:** Input validation failed (target path not found, no TypeScript files found at path).
|
|
126
|
+
|
|
127
|
+
- **stderr:** format=`json`
|
|
128
|
+
|
|
129
|
+
**Exit 10:** Blocking findings detected at or above the --fail-on threshold.
|
|
130
|
+
|
|
131
|
+
- **stdout:** format=`json`
|
|
132
|
+
|
|
133
|
+
**Exit 11:** agent-contracts-runtime package is not installed.
|
|
134
|
+
|
|
135
|
+
- **stderr:** format=`json`
|
|
136
|
+
|
|
137
|
+
**Exit 12:** Adapter initialization failed (missing API key or invalid configuration).
|
|
138
|
+
|
|
139
|
+
- **stderr:** format=`json`
|
|
140
|
+
|
|
141
|
+
#### Extensions
|
|
142
|
+
|
|
143
|
+
```yaml
|
|
144
|
+
x-agent:
|
|
145
|
+
riskLevel: low
|
|
146
|
+
requiresConfirmation: false
|
|
147
|
+
idempotent: true
|
|
148
|
+
sideEffects:
|
|
149
|
+
- network
|
|
150
|
+
sideEffectNote: Makes network calls to the configured LLM provider when adapter is not "mock". Writes to the filesystem only when --output is specified.
|
|
151
|
+
safeDryRunOption: dry-run
|
|
152
|
+
expectedDurationMs: 120000
|
|
153
|
+
retryableExitCodes:
|
|
154
|
+
- 1
|
|
155
|
+
- 12
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### implement
|
|
161
|
+
|
|
162
|
+
Implement a feature using litedbmodel best practices.
|
|
163
|
+
|
|
164
|
+
Reads the project's model definitions, then implements the described feature directly in the target source file(s), applying litedbmodel best-practice patterns: createMany for batch inserts, upsert with onConflict/onConflictUpdate for idempotent writes, forUpdate for concurrent-safe reads, and DBModel.transaction for multi-step operations. Avoids all eight common litedbmodel anti-patterns. Requires an agentic adapter (claude/cursor) that can read and write project files.
|
|
165
|
+
|
|
166
|
+
**Usage:**
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
litedbmodel-gen implement "Add syncNutrientSummary in src/services/meal.service.ts" --target src/services/meal.service.ts --models "src/models/**/*.ts" --adapter claude
|
|
170
|
+
```
|
|
171
|
+
```
|
|
172
|
+
litedbmodel-gen implement "Add bulk upsert for order items" --target src/services/order.service.ts --adapter claude
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### Arguments
|
|
176
|
+
|
|
177
|
+
| Name | Required | Description |
|
|
178
|
+
|---|---|---|
|
|
179
|
+
| `description` | Yes | Natural-language description of the feature to implement. Should specify the function name, target file, and business logic. |
|
|
180
|
+
|
|
181
|
+
#### Options
|
|
182
|
+
|
|
183
|
+
| Option | Aliases | Required | Default | Description |
|
|
184
|
+
|---|---|---|---|---|
|
|
185
|
+
| `--target` | -t | No | | Target source file(s) to create or edit. The agent reads these files to understand existing code and writes the implementation to them. |
|
|
186
|
+
| `--models` | | No | `"models/**/*.ts"` | Glob pattern for model definition files. The agent reads these to understand available models, columns, and relations. |
|
|
187
|
+
| `--adapter` | | No | `"mock"` | LLM adapter to use for code generation. |
|
|
188
|
+
| `--model` | | No | | Model name override for the selected adapter. |
|
|
189
|
+
| `--dry-run` | | No | `false` | Output the constructed prompt without calling the LLM. |
|
|
190
|
+
| `--fail-on` | | No | `"error"` | Minimum finding severity that causes exit code 10. Design concerns (info/warning) are still reported at exit 0. |
|
|
191
|
+
| `--output` | -o | No | | Write the report to a file instead of stdout. |
|
|
192
|
+
| `--report-format` | | No | `"json"` | Output format for the implementation report. |
|
|
193
|
+
|
|
194
|
+
#### Exit Codes
|
|
195
|
+
|
|
196
|
+
**Exit 0:** Implementation written to target files successfully with no design concerns at or above the --fail-on threshold.
|
|
197
|
+
|
|
198
|
+
- **stdout:** format=`json`
|
|
199
|
+
|
|
200
|
+
**Exit 1:** General error (unexpected exception or I/O failure).
|
|
201
|
+
|
|
202
|
+
- **stderr:** format=`text`
|
|
203
|
+
|
|
204
|
+
**Exit 3:** Input validation failed (missing description or unreadable model files).
|
|
205
|
+
|
|
206
|
+
- **stderr:** format=`json`
|
|
207
|
+
|
|
208
|
+
**Exit 10:** Implementation written but design concerns at or above the --fail-on threshold were detected.
|
|
209
|
+
|
|
210
|
+
- **stdout:** format=`json`
|
|
211
|
+
|
|
212
|
+
**Exit 11:** agent-contracts-runtime package is not installed.
|
|
213
|
+
|
|
214
|
+
- **stderr:** format=`json`
|
|
215
|
+
|
|
216
|
+
**Exit 12:** Adapter initialization failed (missing API key or invalid configuration).
|
|
217
|
+
|
|
218
|
+
- **stderr:** format=`json`
|
|
219
|
+
|
|
220
|
+
#### Extensions
|
|
221
|
+
|
|
222
|
+
```yaml
|
|
223
|
+
x-agent:
|
|
224
|
+
riskLevel: high
|
|
225
|
+
requiresConfirmation: true
|
|
226
|
+
idempotent: false
|
|
227
|
+
sideEffects:
|
|
228
|
+
- network
|
|
229
|
+
- filesystem_write
|
|
230
|
+
sideEffectNote: The agent reads project files and writes implementation code directly to the target source file(s). Uses an agentic adapter (claude/cursor) with file read/write tools.
|
|
231
|
+
safeDryRunOption: dry-run
|
|
232
|
+
expectedDurationMs: 120000
|
|
233
|
+
retryableExitCodes:
|
|
234
|
+
- 1
|
|
235
|
+
- 12
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litedbmodel-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "embedoc-based model code generator for litedbmodel — generates TypeScript column definitions from SQL DDL (PostgreSQL/MySQL/SQLite)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"test": "vitest run",
|
|
27
27
|
"test:watch": "vitest",
|
|
28
28
|
"typecheck": "tsc --noEmit",
|
|
29
|
-
"prepublishOnly": "npm run build"
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"cli:generate": "cli-contracts generate",
|
|
31
|
+
"dsl:generate": "agent-runtime generate --config dsl/agent-runtime.config.yaml"
|
|
30
32
|
},
|
|
31
33
|
"keywords": [
|
|
32
34
|
"litedbmodel",
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
],
|
|
42
44
|
"license": "MIT",
|
|
43
45
|
"dependencies": {
|
|
46
|
+
"better-sqlite3": "^12.10.0",
|
|
44
47
|
"commander": "^14.0.3",
|
|
45
48
|
"js-yaml": "^4.1.1",
|
|
46
49
|
"node-sql-parser": "^5.4.0"
|
|
@@ -48,13 +51,36 @@
|
|
|
48
51
|
"peerDependencies": {
|
|
49
52
|
"embedoc": ">=0.11.0"
|
|
50
53
|
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"@anthropic-ai/claude-agent-sdk": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@openai/agents": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"@google/genai": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@cursor/sdk": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"optionalDependencies": {
|
|
69
|
+
"@anthropic-ai/claude-agent-sdk": ">=0.2.0",
|
|
70
|
+
"@google/genai": ">=2.0.0",
|
|
71
|
+
"@openai/agents": ">=0.10.0"
|
|
72
|
+
},
|
|
51
73
|
"devDependencies": {
|
|
74
|
+
"@cursor/sdk": "^1.0.16",
|
|
52
75
|
"@types/js-yaml": "^4.0.9",
|
|
53
76
|
"@types/node": "^25.3.3",
|
|
54
|
-
"
|
|
77
|
+
"agent-contracts": "^0.32.0",
|
|
78
|
+
"agent-contracts-runtime": "^0.32.1",
|
|
79
|
+
"cli-contracts": "^0.31.6",
|
|
55
80
|
"embedoc": "^0.11.0",
|
|
56
81
|
"tsup": "^8.0.1",
|
|
57
82
|
"typescript": "^5.3.0",
|
|
58
|
-
"vitest": "^4.1.7"
|
|
83
|
+
"vitest": "^4.1.7",
|
|
84
|
+
"zod": "^4.0.0"
|
|
59
85
|
}
|
|
60
86
|
}
|