@veloxts/cli 0.7.1 → 0.7.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/CHANGELOG.md +21 -0
- package/dist/commands/introspect.js +19 -30
- package/dist/commands/mcp.js +2 -3
- package/dist/commands/openapi.js +1 -10
- package/dist/commands/procedures.js +1 -12
- package/dist/dev/error-parser.js +0 -3
- package/dist/generators/fields/types.d.ts +7 -0
- package/dist/generators/fields/types.js +29 -0
- package/dist/generators/generators/namespace.js +7 -2
- package/dist/generators/templates/namespace.d.ts +3 -0
- package/dist/generators/templates/namespace.js +85 -1
- package/dist/generators/utils/prisma-schema.d.ts +18 -0
- package/dist/generators/utils/prisma-schema.js +53 -2
- package/dist/utils/paths.d.ts +4 -0
- package/dist/utils/paths.js +12 -4
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @veloxts/cli
|
|
2
2
|
|
|
3
|
+
## 0.7.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat(cli): auto-populate Zod schemas from Prisma model fields
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @veloxts/auth@0.7.3
|
|
10
|
+
- @veloxts/core@0.7.3
|
|
11
|
+
- @veloxts/orm@0.7.3
|
|
12
|
+
- @veloxts/router@0.7.3
|
|
13
|
+
- @veloxts/validation@0.7.3
|
|
14
|
+
|
|
15
|
+
## 0.7.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- fix(cli): replace require() with readFileSync in MCP tests
|
|
20
|
+
- simplify code for clarity and maintainability
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @veloxts/core@0.7.2
|
|
23
|
+
|
|
3
24
|
## 0.7.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -10,28 +10,33 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { existsSync } from 'node:fs';
|
|
12
12
|
import { readdir, readFile } from 'node:fs/promises';
|
|
13
|
-
import { join
|
|
13
|
+
import { join } from 'node:path';
|
|
14
14
|
import { discoverProceduresVerbose, getRouteSummary, isDiscoveryError, } from '@veloxts/router';
|
|
15
15
|
import { Command } from 'commander';
|
|
16
|
-
import { config as loadEnv } from 'dotenv';
|
|
17
16
|
import pc from 'picocolors';
|
|
18
17
|
import { getErrorsByCategory } from '../errors/index.js';
|
|
18
|
+
import { loadEnvironment } from '../utils/paths.js';
|
|
19
19
|
import { extractSchemaNames, extractSchemaTypes } from '../utils/schema-patterns.js';
|
|
20
20
|
// ============================================================================
|
|
21
21
|
// Constants
|
|
22
22
|
// ============================================================================
|
|
23
23
|
/** Default API prefix for REST routes */
|
|
24
24
|
const DEFAULT_API_PREFIX = '/api';
|
|
25
|
-
// ============================================================================
|
|
26
|
-
// Helper Functions
|
|
27
|
-
// ============================================================================
|
|
28
25
|
/**
|
|
29
|
-
*
|
|
26
|
+
* Get picocolors color function for an HTTP method
|
|
30
27
|
*/
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
function getMethodColor(method) {
|
|
29
|
+
switch (method) {
|
|
30
|
+
case 'GET':
|
|
31
|
+
return pc.green;
|
|
32
|
+
case 'POST':
|
|
33
|
+
return pc.yellow;
|
|
34
|
+
case 'PUT':
|
|
35
|
+
return pc.blue;
|
|
36
|
+
case 'PATCH':
|
|
37
|
+
return pc.cyan;
|
|
38
|
+
default:
|
|
39
|
+
return pc.red;
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
@@ -139,9 +144,9 @@ function getErrorIntrospection() {
|
|
|
139
144
|
for (const prefix of categories) {
|
|
140
145
|
const categoryErrors = getErrorsByCategory(prefix);
|
|
141
146
|
const categoryName = categoryNames[prefix] ?? 'Unknown';
|
|
142
|
-
for (const
|
|
147
|
+
for (const def of categoryErrors) {
|
|
143
148
|
errors.push({
|
|
144
|
-
code,
|
|
149
|
+
code: def.code,
|
|
145
150
|
name: def.name,
|
|
146
151
|
message: def.message,
|
|
147
152
|
fix: def.fix,
|
|
@@ -172,15 +177,7 @@ function printProcedures(procedures) {
|
|
|
172
177
|
console.log(pc.bold(pc.cyan(`/${currentNs}`)));
|
|
173
178
|
}
|
|
174
179
|
const method = proc.route?.method ?? (proc.type === 'query' ? 'GET' : 'POST');
|
|
175
|
-
const methodColor = method
|
|
176
|
-
? pc.green
|
|
177
|
-
: method === 'POST'
|
|
178
|
-
? pc.yellow
|
|
179
|
-
: method === 'PUT'
|
|
180
|
-
? pc.blue
|
|
181
|
-
: method === 'PATCH'
|
|
182
|
-
? pc.cyan
|
|
183
|
-
: pc.red;
|
|
180
|
+
const methodColor = getMethodColor(method);
|
|
184
181
|
const schemas = [];
|
|
185
182
|
if (proc.hasInput)
|
|
186
183
|
schemas.push('in');
|
|
@@ -226,15 +223,7 @@ function printRoutes(routes) {
|
|
|
226
223
|
console.log(pc.bold('REST Routes'));
|
|
227
224
|
console.log(pc.dim('─'.repeat(60)));
|
|
228
225
|
for (const route of routes) {
|
|
229
|
-
const methodColor = route.method
|
|
230
|
-
? pc.green
|
|
231
|
-
: route.method === 'POST'
|
|
232
|
-
? pc.yellow
|
|
233
|
-
: route.method === 'PUT'
|
|
234
|
-
? pc.blue
|
|
235
|
-
: route.method === 'PATCH'
|
|
236
|
-
? pc.cyan
|
|
237
|
-
: pc.red;
|
|
226
|
+
const methodColor = getMethodColor(route.method);
|
|
238
227
|
console.log(` ${methodColor(route.method.padEnd(7))} ${route.path}`);
|
|
239
228
|
console.log(pc.dim(` → ${route.namespace}.${route.procedure}`));
|
|
240
229
|
}
|
package/dist/commands/mcp.js
CHANGED
|
@@ -95,8 +95,7 @@ async function readClaudeConfig(configPath) {
|
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
97
|
try {
|
|
98
|
-
|
|
99
|
-
return config;
|
|
98
|
+
return await readJsonFile(configPath);
|
|
100
99
|
}
|
|
101
100
|
catch (err) {
|
|
102
101
|
throw new Error(`Failed to parse Claude Desktop configuration: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -301,7 +300,7 @@ async function runMcpInit(options) {
|
|
|
301
300
|
process.exit(1);
|
|
302
301
|
}
|
|
303
302
|
// Success!
|
|
304
|
-
const action =
|
|
303
|
+
const action = configExists ? 'updated' : 'created';
|
|
305
304
|
const result = {
|
|
306
305
|
success: true,
|
|
307
306
|
action,
|
package/dist/commands/openapi.js
CHANGED
|
@@ -11,18 +11,9 @@ import { createServer } from 'node:http';
|
|
|
11
11
|
import { dirname, extname, resolve } from 'node:path';
|
|
12
12
|
import { discoverProceduresVerbose, generateOpenApiSpec, generateSwaggerUIHtml, isDiscoveryError, validateOpenApiSpec, } from '@veloxts/router';
|
|
13
13
|
import { Command } from 'commander';
|
|
14
|
-
import { config as loadEnv } from 'dotenv';
|
|
15
14
|
import pc from 'picocolors';
|
|
16
15
|
import YAML from 'yaml';
|
|
17
|
-
|
|
18
|
-
* Load environment variables from .env file if present
|
|
19
|
-
*/
|
|
20
|
-
function loadEnvironment() {
|
|
21
|
-
const envPath = resolve(process.cwd(), '.env');
|
|
22
|
-
if (existsSync(envPath)) {
|
|
23
|
-
loadEnv({ path: envPath });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
16
|
+
import { loadEnvironment } from '../utils/paths.js';
|
|
26
17
|
// ============================================================================
|
|
27
18
|
// Helper Functions
|
|
28
19
|
// ============================================================================
|
|
@@ -4,21 +4,10 @@
|
|
|
4
4
|
* Provides subcommands for managing procedures:
|
|
5
5
|
* - procedures:list - List all discovered procedures
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync } from 'node:fs';
|
|
8
|
-
import { resolve } from 'node:path';
|
|
9
7
|
import { discoverProceduresVerbose, isDiscoveryError, } from '@veloxts/router';
|
|
10
8
|
import { Command } from 'commander';
|
|
11
|
-
import { config as loadEnv } from 'dotenv';
|
|
12
9
|
import pc from 'picocolors';
|
|
13
|
-
|
|
14
|
-
* Load environment variables from .env file if present
|
|
15
|
-
*/
|
|
16
|
-
function loadEnvironment() {
|
|
17
|
-
const envPath = resolve(process.cwd(), '.env');
|
|
18
|
-
if (existsSync(envPath)) {
|
|
19
|
-
loadEnv({ path: envPath });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
10
|
+
import { loadEnvironment } from '../utils/paths.js';
|
|
22
11
|
// ============================================================================
|
|
23
12
|
// Helper Functions
|
|
24
13
|
// ============================================================================
|
package/dist/dev/error-parser.js
CHANGED
|
@@ -264,9 +264,6 @@ function generateSuggestion(type, errorText) {
|
|
|
264
264
|
if (moduleName.startsWith('.') || moduleName.startsWith('/')) {
|
|
265
265
|
suggestion = `Check that the file '${moduleName}' exists and the path is correct relative to the importing file.`;
|
|
266
266
|
}
|
|
267
|
-
else if (moduleName.startsWith('@')) {
|
|
268
|
-
suggestion = `Install the package: pnpm add ${moduleName}`;
|
|
269
|
-
}
|
|
270
267
|
else {
|
|
271
268
|
suggestion = `Install the package: pnpm add ${moduleName}`;
|
|
272
269
|
}
|
|
@@ -88,6 +88,13 @@ export declare function validateEnumName(name: string): string | undefined;
|
|
|
88
88
|
* Validate enum values format (UPPER_CASE)
|
|
89
89
|
*/
|
|
90
90
|
export declare function validateEnumValues(values: string[]): string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Map a Prisma schema type string to a FieldType
|
|
93
|
+
*
|
|
94
|
+
* Used when reading fields from an existing Prisma model to convert them
|
|
95
|
+
* into FieldDefinition objects for code generation.
|
|
96
|
+
*/
|
|
97
|
+
export declare function prismaTypeToFieldType(prismaType: string): FieldType;
|
|
91
98
|
/**
|
|
92
99
|
* Parse comma-separated enum values
|
|
93
100
|
*/
|
|
@@ -138,6 +138,35 @@ export function validateEnumValues(values) {
|
|
|
138
138
|
}
|
|
139
139
|
return undefined;
|
|
140
140
|
}
|
|
141
|
+
// ============================================================================
|
|
142
|
+
// Prisma Type Mapping
|
|
143
|
+
// ============================================================================
|
|
144
|
+
/**
|
|
145
|
+
* Map a Prisma schema type string to a FieldType
|
|
146
|
+
*
|
|
147
|
+
* Used when reading fields from an existing Prisma model to convert them
|
|
148
|
+
* into FieldDefinition objects for code generation.
|
|
149
|
+
*/
|
|
150
|
+
export function prismaTypeToFieldType(prismaType) {
|
|
151
|
+
switch (prismaType) {
|
|
152
|
+
case 'String':
|
|
153
|
+
return 'string';
|
|
154
|
+
case 'Int':
|
|
155
|
+
return 'int';
|
|
156
|
+
case 'Float':
|
|
157
|
+
case 'Decimal':
|
|
158
|
+
case 'BigInt':
|
|
159
|
+
return 'float';
|
|
160
|
+
case 'Boolean':
|
|
161
|
+
return 'boolean';
|
|
162
|
+
case 'DateTime':
|
|
163
|
+
return 'datetime';
|
|
164
|
+
case 'Json':
|
|
165
|
+
return 'json';
|
|
166
|
+
default:
|
|
167
|
+
return 'string';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
141
170
|
/**
|
|
142
171
|
* Parse comma-separated enum values
|
|
143
172
|
*/
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { BaseGenerator } from '../base.js';
|
|
15
15
|
import { getNamespaceInstructions, getNamespaceProcedurePath, getNamespaceSchemaPath, getNamespaceTestPath, namespaceSchemaTemplate, namespaceTemplate, namespaceTestTemplate, } from '../templates/namespace.js';
|
|
16
16
|
import { deriveEntityNames } from '../utils/naming.js';
|
|
17
|
-
import { analyzePrismaSchema, findPrismaSchema, getModelRelations, hasModel, } from '../utils/prisma-schema.js';
|
|
17
|
+
import { analyzePrismaSchema, findPrismaSchema, getModelFields, getModelRelations, hasModel, } from '../utils/prisma-schema.js';
|
|
18
18
|
import { detectRouterPattern, isProcedureRegistered, registerProcedures, } from '../utils/router-integration.js';
|
|
19
19
|
// ============================================================================
|
|
20
20
|
// Generator Implementation
|
|
@@ -113,10 +113,15 @@ Examples:
|
|
|
113
113
|
hasMany: [...modelRelations.hasMany],
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
+
// Extract scalar fields for Zod schema generation
|
|
117
|
+
const scalarFields = getModelFields(schemaAnalysis, entity.pascal);
|
|
118
|
+
if (scalarFields.length > 0) {
|
|
119
|
+
enrichedOptions.fields = scalarFields;
|
|
120
|
+
}
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
catch {
|
|
119
|
-
// Schema parsing failed — proceed without relations
|
|
124
|
+
// Schema parsing failed — proceed without relations or fields
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
const enrichedConfig = { ...config, options: enrichedOptions };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Unlike the procedure generator, this creates a minimal scaffold ready for
|
|
6
6
|
* custom procedures rather than pre-defined CRUD operations.
|
|
7
7
|
*/
|
|
8
|
+
import type { FieldDefinition } from '../fields/types.js';
|
|
8
9
|
import type { TemplateContext, TemplateFunction } from '../types.js';
|
|
9
10
|
/**
|
|
10
11
|
* Relation info for code generation (shared with resource template)
|
|
@@ -24,6 +25,8 @@ export interface NamespaceOptions {
|
|
|
24
25
|
withTests: boolean;
|
|
25
26
|
/** Detected relations from Prisma schema */
|
|
26
27
|
relations?: RelationInfo;
|
|
28
|
+
/** Scalar fields extracted from Prisma model */
|
|
29
|
+
fields?: FieldDefinition[];
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Generate namespace procedure file
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* Unlike the procedure generator, this creates a minimal scaffold ready for
|
|
6
6
|
* custom procedures rather than pre-defined CRUD operations.
|
|
7
7
|
*/
|
|
8
|
+
import { FIELD_TYPES } from '../fields/types.js';
|
|
9
|
+
import { fieldToZod } from '../templates/resource.js';
|
|
8
10
|
// ============================================================================
|
|
9
11
|
// Relation Helpers
|
|
10
12
|
// ============================================================================
|
|
@@ -170,7 +172,89 @@ export const ${entity.camel}Procedures = procedures('${entity.plural}', {
|
|
|
170
172
|
* Generate schema file for the namespace
|
|
171
173
|
*/
|
|
172
174
|
export function namespaceSchemaTemplate(ctx) {
|
|
173
|
-
const { entity } = ctx;
|
|
175
|
+
const { entity, options } = ctx;
|
|
176
|
+
const fields = options.fields;
|
|
177
|
+
if (fields && fields.length > 0) {
|
|
178
|
+
return generateSchemaWithFields(entity, fields);
|
|
179
|
+
}
|
|
180
|
+
return generateSchemaPlaceholder(entity);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Generate schema with actual fields from Prisma model
|
|
184
|
+
*/
|
|
185
|
+
function generateSchemaWithFields(entity, fields) {
|
|
186
|
+
// Base schema: all fields
|
|
187
|
+
const baseFields = fields.map(fieldToZod).join('\n');
|
|
188
|
+
// Create input: non-auto-generated fields (those without @default or @updatedAt)
|
|
189
|
+
const createFields = fields.filter((f) => !f.attributes.hasDefault);
|
|
190
|
+
const createFieldLines = createFields.map((f) => {
|
|
191
|
+
// In create input, optional fields use .optional() instead of .nullable()
|
|
192
|
+
return fieldToZodForInput(f);
|
|
193
|
+
});
|
|
194
|
+
const createContent = createFieldLines.join('\n');
|
|
195
|
+
return `/**
|
|
196
|
+
* ${entity.pascal} Schemas
|
|
197
|
+
*
|
|
198
|
+
* Zod validation schemas for ${entity.humanReadable} entities.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
import { z } from 'zod';
|
|
202
|
+
|
|
203
|
+
// ============================================================================
|
|
204
|
+
// Base Schema
|
|
205
|
+
// ============================================================================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* ${entity.pascal} entity schema
|
|
209
|
+
*/
|
|
210
|
+
export const ${entity.pascal}Schema = z.object({
|
|
211
|
+
id: z.string().uuid(),
|
|
212
|
+
${baseFields}
|
|
213
|
+
createdAt: z.coerce.date(),
|
|
214
|
+
updatedAt: z.coerce.date(),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
export type ${entity.pascal} = z.infer<typeof ${entity.pascal}Schema>;
|
|
218
|
+
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// Input Schemas
|
|
221
|
+
// ============================================================================
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Create ${entity.pascal} input
|
|
225
|
+
*/
|
|
226
|
+
export const Create${entity.pascal}Input = z.object({
|
|
227
|
+
${createContent}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
export type Create${entity.pascal}InputType = z.infer<typeof Create${entity.pascal}Input>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Update ${entity.pascal} input
|
|
234
|
+
*/
|
|
235
|
+
export const Update${entity.pascal}Input = z.object({
|
|
236
|
+
${createContent}
|
|
237
|
+
}).partial();
|
|
238
|
+
|
|
239
|
+
export type Update${entity.pascal}InputType = z.infer<typeof Update${entity.pascal}Input>;
|
|
240
|
+
`;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Convert a field to Zod for input schemas (optional → .optional() instead of .nullable())
|
|
244
|
+
*/
|
|
245
|
+
function fieldToZodForInput(field) {
|
|
246
|
+
// Create a copy with optional mapped to .optional() suffix
|
|
247
|
+
const typeInfo = FIELD_TYPES.find((t) => t.type === field.type);
|
|
248
|
+
let zodType = typeInfo?.zodSchema ?? 'z.string()';
|
|
249
|
+
if (field.attributes.optional) {
|
|
250
|
+
zodType += '.optional()';
|
|
251
|
+
}
|
|
252
|
+
return ` ${field.name}: ${zodType},`;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Generate schema with TODO placeholders (no Prisma model found)
|
|
256
|
+
*/
|
|
257
|
+
function generateSchemaPlaceholder(entity) {
|
|
174
258
|
return `/**
|
|
175
259
|
* ${entity.pascal} Schemas
|
|
176
260
|
*
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Parses Prisma schema files to find models/enums and enables safe injection
|
|
5
5
|
* of new definitions without breaking existing code.
|
|
6
6
|
*/
|
|
7
|
+
import type { FieldDefinition } from '../fields/types.js';
|
|
7
8
|
/**
|
|
8
9
|
* Parsed information about a single field in a Prisma model
|
|
9
10
|
*/
|
|
@@ -18,6 +19,10 @@ export interface PrismaFieldInfo {
|
|
|
18
19
|
readonly isArray: boolean;
|
|
19
20
|
/** The related model name, if this is a relation field */
|
|
20
21
|
readonly relatedModel: string | undefined;
|
|
22
|
+
/** Whether this field has a `?` modifier (nullable/optional) */
|
|
23
|
+
readonly isOptional: boolean;
|
|
24
|
+
/** Whether this field has `@default(...)` or `@updatedAt` */
|
|
25
|
+
readonly hasDefault: boolean;
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* Detailed information about a Prisma model including its fields
|
|
@@ -129,6 +134,19 @@ export declare function injectIntoSchema(analysis: PrismaSchemaAnalysis, models:
|
|
|
129
134
|
* Throws if any model or enum already exists (prevents accidental overwrites)
|
|
130
135
|
*/
|
|
131
136
|
export declare function validateNoConflicts(analysis: PrismaSchemaAnalysis, models: PrismaModelDefinition[], enums?: PrismaEnumDefinition[]): void;
|
|
137
|
+
/**
|
|
138
|
+
* Convert a PrismaFieldInfo to a FieldDefinition for code generation
|
|
139
|
+
*
|
|
140
|
+
* Returns null for fields that should be skipped (relations, reserved names).
|
|
141
|
+
*/
|
|
142
|
+
export declare function prismaFieldToFieldDefinition(field: PrismaFieldInfo): FieldDefinition | null;
|
|
143
|
+
/**
|
|
144
|
+
* Get scalar, non-auto-generated fields from a Prisma model as FieldDefinitions
|
|
145
|
+
*
|
|
146
|
+
* Filters out relation fields, reserved fields (id, createdAt, updatedAt, deletedAt),
|
|
147
|
+
* and fields with @id annotation.
|
|
148
|
+
*/
|
|
149
|
+
export declare function getModelFields(analysis: PrismaSchemaAnalysis, modelName: string): FieldDefinition[];
|
|
132
150
|
/**
|
|
133
151
|
* Generate a minimal Prisma model string
|
|
134
152
|
*/
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* of new definitions without breaking existing code.
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { prismaTypeToFieldType, RESERVED_FIELD_NAMES } from '../fields/types.js';
|
|
8
9
|
import { GeneratorError, GeneratorErrorCode } from '../types.js';
|
|
9
10
|
// ============================================================================
|
|
10
11
|
// Schema Parsing
|
|
@@ -156,13 +157,15 @@ function parseModelFields(body, modelNames) {
|
|
|
156
157
|
continue;
|
|
157
158
|
}
|
|
158
159
|
// Parse field: name Type[?][] [@annotations...]
|
|
159
|
-
// Match: fieldName TypeName optional modifiers
|
|
160
|
-
const fieldMatch = trimmed.match(/^(\w+)\s+(\w+)(\[\])
|
|
160
|
+
// Match: fieldName TypeName optional array and optional modifiers
|
|
161
|
+
const fieldMatch = trimmed.match(/^(\w+)\s+(\w+)(\[\])?(\?)?/);
|
|
161
162
|
if (!fieldMatch)
|
|
162
163
|
continue;
|
|
163
164
|
const name = fieldMatch[1];
|
|
164
165
|
const baseType = fieldMatch[2];
|
|
165
166
|
const isArray = fieldMatch[3] === '[]';
|
|
167
|
+
const isOptional = fieldMatch[4] === '?';
|
|
168
|
+
const hasDefault = /@default\(/.test(trimmed) || /@updatedAt/.test(trimmed);
|
|
166
169
|
// Check if this is a relation field (type matches a known model)
|
|
167
170
|
const isRelation = modelNames.has(baseType);
|
|
168
171
|
if (!isRelation) {
|
|
@@ -172,6 +175,8 @@ function parseModelFields(body, modelNames) {
|
|
|
172
175
|
isRelation: false,
|
|
173
176
|
isArray: false,
|
|
174
177
|
relatedModel: undefined,
|
|
178
|
+
isOptional,
|
|
179
|
+
hasDefault,
|
|
175
180
|
});
|
|
176
181
|
continue;
|
|
177
182
|
}
|
|
@@ -188,6 +193,8 @@ function parseModelFields(body, modelNames) {
|
|
|
188
193
|
isRelation: true,
|
|
189
194
|
isArray,
|
|
190
195
|
relatedModel: baseType,
|
|
196
|
+
isOptional,
|
|
197
|
+
hasDefault,
|
|
191
198
|
});
|
|
192
199
|
}
|
|
193
200
|
return fields;
|
|
@@ -311,6 +318,50 @@ export function validateNoConflicts(analysis, models, enums = []) {
|
|
|
311
318
|
}
|
|
312
319
|
}
|
|
313
320
|
// ============================================================================
|
|
321
|
+
// Field Conversion
|
|
322
|
+
// ============================================================================
|
|
323
|
+
/**
|
|
324
|
+
* Convert a PrismaFieldInfo to a FieldDefinition for code generation
|
|
325
|
+
*
|
|
326
|
+
* Returns null for fields that should be skipped (relations, reserved names).
|
|
327
|
+
*/
|
|
328
|
+
export function prismaFieldToFieldDefinition(field) {
|
|
329
|
+
// Skip relation fields
|
|
330
|
+
if (field.isRelation)
|
|
331
|
+
return null;
|
|
332
|
+
// Skip reserved fields (id, createdAt, updatedAt, deletedAt)
|
|
333
|
+
if (RESERVED_FIELD_NAMES.includes(field.name))
|
|
334
|
+
return null;
|
|
335
|
+
return {
|
|
336
|
+
name: field.name,
|
|
337
|
+
type: prismaTypeToFieldType(field.type),
|
|
338
|
+
attributes: {
|
|
339
|
+
optional: field.isOptional,
|
|
340
|
+
unique: false, // Not tracked in PrismaFieldInfo
|
|
341
|
+
hasDefault: field.hasDefault,
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Get scalar, non-auto-generated fields from a Prisma model as FieldDefinitions
|
|
347
|
+
*
|
|
348
|
+
* Filters out relation fields, reserved fields (id, createdAt, updatedAt, deletedAt),
|
|
349
|
+
* and fields with @id annotation.
|
|
350
|
+
*/
|
|
351
|
+
export function getModelFields(analysis, modelName) {
|
|
352
|
+
const modelInfo = analysis.modelDetails.get(modelName);
|
|
353
|
+
if (!modelInfo)
|
|
354
|
+
return [];
|
|
355
|
+
const fields = [];
|
|
356
|
+
for (const field of modelInfo.fields) {
|
|
357
|
+
const converted = prismaFieldToFieldDefinition(field);
|
|
358
|
+
if (converted) {
|
|
359
|
+
fields.push(converted);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return fields;
|
|
363
|
+
}
|
|
364
|
+
// ============================================================================
|
|
314
365
|
// Helpers
|
|
315
366
|
// ============================================================================
|
|
316
367
|
/**
|
package/dist/utils/paths.d.ts
CHANGED
|
@@ -101,3 +101,7 @@ export declare function writeJsonFile(filePath: string, data: unknown): Promise<
|
|
|
101
101
|
* Create a directory recursively
|
|
102
102
|
*/
|
|
103
103
|
export declare function createDirectory(dirPath: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* Load environment variables from .env file if present
|
|
106
|
+
*/
|
|
107
|
+
export declare function loadEnvironment(cwd?: string): void;
|
package/dist/utils/paths.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
|
5
5
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import { config as loadEnv } from 'dotenv';
|
|
7
8
|
/** Common entry point file names, ordered by preference */
|
|
8
9
|
const ENTRY_POINT_PATTERNS = [
|
|
9
10
|
'src/index.ts',
|
|
@@ -252,8 +253,7 @@ export async function isVeloxProject(cwd = process.cwd()) {
|
|
|
252
253
|
return false;
|
|
253
254
|
}
|
|
254
255
|
try {
|
|
255
|
-
const
|
|
256
|
-
const content = await fs.readFile(packageJsonPath, 'utf-8');
|
|
256
|
+
const content = await readFile(packageJsonPath, 'utf-8');
|
|
257
257
|
const pkg = JSON.parse(content);
|
|
258
258
|
// Check if any @veloxts packages are in dependencies
|
|
259
259
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
@@ -289,8 +289,7 @@ export async function detectProjectType(cwd = process.cwd()) {
|
|
|
289
289
|
return result;
|
|
290
290
|
}
|
|
291
291
|
try {
|
|
292
|
-
const
|
|
293
|
-
const content = await fs.readFile(packageJsonPath, 'utf-8');
|
|
292
|
+
const content = await readFile(packageJsonPath, 'utf-8');
|
|
294
293
|
const pkg = JSON.parse(content);
|
|
295
294
|
// Collect all dependencies
|
|
296
295
|
result.dependencies = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
@@ -328,3 +327,12 @@ export async function writeJsonFile(filePath, data) {
|
|
|
328
327
|
export function createDirectory(dirPath) {
|
|
329
328
|
mkdirSync(dirPath, { recursive: true });
|
|
330
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Load environment variables from .env file if present
|
|
332
|
+
*/
|
|
333
|
+
export function loadEnvironment(cwd = process.cwd()) {
|
|
334
|
+
const envPath = path.resolve(cwd, '.env');
|
|
335
|
+
if (existsSync(envPath)) {
|
|
336
|
+
loadEnv({ path: envPath });
|
|
337
|
+
}
|
|
338
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Developer tooling and CLI commands for VeloxTS framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"pluralize": "8.0.0",
|
|
42
42
|
"tsx": "4.21.0",
|
|
43
43
|
"yaml": "2.8.2",
|
|
44
|
-
"@veloxts/
|
|
45
|
-
"@veloxts/
|
|
46
|
-
"@veloxts/
|
|
47
|
-
"@veloxts/
|
|
48
|
-
"@veloxts/
|
|
44
|
+
"@veloxts/auth": "0.7.3",
|
|
45
|
+
"@veloxts/orm": "0.7.3",
|
|
46
|
+
"@veloxts/core": "0.7.3",
|
|
47
|
+
"@veloxts/router": "0.7.3",
|
|
48
|
+
"@veloxts/validation": "0.7.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@prisma/client": ">=7.0.0"
|