@veloxts/cli 0.3.6 → 0.4.1
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/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/generate.d.ts +17 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +219 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/migrate.d.ts +8 -3
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +17 -123
- package/dist/commands/migrate.js.map +1 -1
- package/dist/generators/base.d.ts +76 -0
- package/dist/generators/base.d.ts.map +1 -0
- package/dist/generators/base.js +271 -0
- package/dist/generators/base.js.map +1 -0
- package/dist/generators/generators/index.d.ts +17 -0
- package/dist/generators/generators/index.d.ts.map +1 -0
- package/dist/generators/generators/index.js +43 -0
- package/dist/generators/generators/index.js.map +1 -0
- package/dist/generators/generators/migration.d.ts +43 -0
- package/dist/generators/generators/migration.d.ts.map +1 -0
- package/dist/generators/generators/migration.js +121 -0
- package/dist/generators/generators/migration.js.map +1 -0
- package/dist/generators/generators/model.d.ts +38 -0
- package/dist/generators/generators/model.d.ts.map +1 -0
- package/dist/generators/generators/model.js +108 -0
- package/dist/generators/generators/model.js.map +1 -0
- package/dist/generators/generators/procedure.d.ts +37 -0
- package/dist/generators/generators/procedure.d.ts.map +1 -0
- package/dist/generators/generators/procedure.js +99 -0
- package/dist/generators/generators/procedure.js.map +1 -0
- package/dist/generators/generators/resource.d.ts +29 -0
- package/dist/generators/generators/resource.d.ts.map +1 -0
- package/dist/generators/generators/resource.js +124 -0
- package/dist/generators/generators/resource.js.map +1 -0
- package/dist/generators/generators/schema.d.ts +28 -0
- package/dist/generators/generators/schema.d.ts.map +1 -0
- package/dist/generators/generators/schema.js +83 -0
- package/dist/generators/generators/schema.js.map +1 -0
- package/dist/generators/generators/test.d.ts +28 -0
- package/dist/generators/generators/test.d.ts.map +1 -0
- package/dist/generators/generators/test.js +96 -0
- package/dist/generators/generators/test.js.map +1 -0
- package/dist/generators/index.d.ts +16 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +16 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/registry.d.ts +97 -0
- package/dist/generators/registry.d.ts.map +1 -0
- package/dist/generators/registry.js +253 -0
- package/dist/generators/registry.js.map +1 -0
- package/dist/generators/templates/migration.d.ts +23 -0
- package/dist/generators/templates/migration.d.ts.map +1 -0
- package/dist/generators/templates/migration.js +389 -0
- package/dist/generators/templates/migration.js.map +1 -0
- package/dist/generators/templates/model.d.ts +37 -0
- package/dist/generators/templates/model.d.ts.map +1 -0
- package/dist/generators/templates/model.js +374 -0
- package/dist/generators/templates/model.js.map +1 -0
- package/dist/generators/templates/procedure.d.ts +25 -0
- package/dist/generators/templates/procedure.d.ts.map +1 -0
- package/dist/generators/templates/procedure.js +274 -0
- package/dist/generators/templates/procedure.js.map +1 -0
- package/dist/generators/templates/resource.d.ts +34 -0
- package/dist/generators/templates/resource.d.ts.map +1 -0
- package/dist/generators/templates/resource.js +550 -0
- package/dist/generators/templates/resource.js.map +1 -0
- package/dist/generators/templates/schema.d.ts +33 -0
- package/dist/generators/templates/schema.d.ts.map +1 -0
- package/dist/generators/templates/schema.js +248 -0
- package/dist/generators/templates/schema.js.map +1 -0
- package/dist/generators/templates/test.d.ts +31 -0
- package/dist/generators/templates/test.d.ts.map +1 -0
- package/dist/generators/templates/test.js +882 -0
- package/dist/generators/templates/test.js.map +1 -0
- package/dist/generators/types.d.ts +211 -0
- package/dist/generators/types.d.ts.map +1 -0
- package/dist/generators/types.js +54 -0
- package/dist/generators/types.js.map +1 -0
- package/dist/generators/utils/filesystem.d.ts +68 -0
- package/dist/generators/utils/filesystem.d.ts.map +1 -0
- package/dist/generators/utils/filesystem.js +217 -0
- package/dist/generators/utils/filesystem.js.map +1 -0
- package/dist/generators/utils/naming.d.ts +122 -0
- package/dist/generators/utils/naming.d.ts.map +1 -0
- package/dist/generators/utils/naming.js +198 -0
- package/dist/generators/utils/naming.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/migrations/commands/fresh.d.ts +11 -0
- package/dist/migrations/commands/fresh.d.ts.map +1 -0
- package/dist/migrations/commands/fresh.js +164 -0
- package/dist/migrations/commands/fresh.js.map +1 -0
- package/dist/migrations/commands/index.d.ts +11 -0
- package/dist/migrations/commands/index.d.ts.map +1 -0
- package/dist/migrations/commands/index.js +11 -0
- package/dist/migrations/commands/index.js.map +1 -0
- package/dist/migrations/commands/reset.d.ts +11 -0
- package/dist/migrations/commands/reset.d.ts.map +1 -0
- package/dist/migrations/commands/reset.js +258 -0
- package/dist/migrations/commands/reset.js.map +1 -0
- package/dist/migrations/commands/rollback.d.ts +11 -0
- package/dist/migrations/commands/rollback.d.ts.map +1 -0
- package/dist/migrations/commands/rollback.js +241 -0
- package/dist/migrations/commands/rollback.js.map +1 -0
- package/dist/migrations/commands/run.d.ts +11 -0
- package/dist/migrations/commands/run.d.ts.map +1 -0
- package/dist/migrations/commands/run.js +183 -0
- package/dist/migrations/commands/run.js.map +1 -0
- package/dist/migrations/commands/status.d.ts +11 -0
- package/dist/migrations/commands/status.d.ts.map +1 -0
- package/dist/migrations/commands/status.js +154 -0
- package/dist/migrations/commands/status.js.map +1 -0
- package/dist/migrations/errors.d.ts +74 -0
- package/dist/migrations/errors.d.ts.map +1 -0
- package/dist/migrations/errors.js +155 -0
- package/dist/migrations/errors.js.map +1 -0
- package/dist/migrations/index.d.ts +13 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +17 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/loader.d.ts +44 -0
- package/dist/migrations/loader.d.ts.map +1 -0
- package/dist/migrations/loader.js +181 -0
- package/dist/migrations/loader.js.map +1 -0
- package/dist/migrations/prisma-wrapper.d.ts +60 -0
- package/dist/migrations/prisma-wrapper.d.ts.map +1 -0
- package/dist/migrations/prisma-wrapper.js +184 -0
- package/dist/migrations/prisma-wrapper.js.map +1 -0
- package/dist/migrations/rollback-runner.d.ts +40 -0
- package/dist/migrations/rollback-runner.d.ts.map +1 -0
- package/dist/migrations/rollback-runner.js +191 -0
- package/dist/migrations/rollback-runner.js.map +1 -0
- package/dist/migrations/types.d.ts +214 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations/types.js +19 -0
- package/dist/migrations/types.js.map +1 -0
- package/package.json +29 -8
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Template
|
|
3
|
+
*
|
|
4
|
+
* Generates Prisma model, Zod schema, and optionally procedures.
|
|
5
|
+
*/
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Prisma Model Template
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Generate Prisma model definition
|
|
11
|
+
*/
|
|
12
|
+
function generatePrismaModel(ctx) {
|
|
13
|
+
const { entity, options } = ctx;
|
|
14
|
+
const fields = [' id String @id @default(uuid())'];
|
|
15
|
+
// Add timestamps if enabled
|
|
16
|
+
if (options.timestamps) {
|
|
17
|
+
fields.push(' createdAt DateTime @default(now())');
|
|
18
|
+
fields.push(' updatedAt DateTime @updatedAt');
|
|
19
|
+
}
|
|
20
|
+
// Add soft delete if enabled
|
|
21
|
+
if (options.softDelete) {
|
|
22
|
+
fields.push(' deletedAt DateTime?');
|
|
23
|
+
}
|
|
24
|
+
return `/// ${entity.humanReadable} model
|
|
25
|
+
/// Add your fields below the id field
|
|
26
|
+
model ${entity.pascal} {
|
|
27
|
+
${fields.join('\n')}
|
|
28
|
+
|
|
29
|
+
// TODO: Add your ${entity.humanReadable} fields here
|
|
30
|
+
// name String
|
|
31
|
+
// email String @unique
|
|
32
|
+
|
|
33
|
+
@@map("${entity.snake}")
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Zod Schema Template
|
|
39
|
+
// ============================================================================
|
|
40
|
+
/**
|
|
41
|
+
* Generate Zod schema file
|
|
42
|
+
*/
|
|
43
|
+
function generateZodSchema(ctx) {
|
|
44
|
+
const { entity, options } = ctx;
|
|
45
|
+
const schemaFields = [' id: z.string().uuid(),'];
|
|
46
|
+
// Add timestamps if enabled
|
|
47
|
+
if (options.timestamps) {
|
|
48
|
+
schemaFields.push(' createdAt: z.string().datetime(),');
|
|
49
|
+
schemaFields.push(' updatedAt: z.string().datetime(),');
|
|
50
|
+
}
|
|
51
|
+
// Add soft delete if enabled
|
|
52
|
+
if (options.softDelete) {
|
|
53
|
+
schemaFields.push(' deletedAt: z.string().datetime().nullable(),');
|
|
54
|
+
}
|
|
55
|
+
return `/**
|
|
56
|
+
* ${entity.pascal} Schemas
|
|
57
|
+
*
|
|
58
|
+
* Zod validation schemas for ${entity.humanReadable} model.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
import { z } from '@veloxts/velox';
|
|
62
|
+
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// Response Schema
|
|
65
|
+
// ============================================================================
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* ${entity.pascal} response schema
|
|
69
|
+
*/
|
|
70
|
+
export const ${entity.pascal}Schema = z.object({
|
|
71
|
+
${schemaFields.join('\n')}
|
|
72
|
+
// TODO: Add your ${entity.humanReadable} fields here
|
|
73
|
+
// name: z.string().min(1).max(100),
|
|
74
|
+
// email: z.string().email(),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export type ${entity.pascal} = z.infer<typeof ${entity.pascal}Schema>;
|
|
78
|
+
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Input Schemas
|
|
81
|
+
// ============================================================================
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Create ${entity.pascal} input schema
|
|
85
|
+
*/
|
|
86
|
+
export const Create${entity.pascal}Input = z.object({
|
|
87
|
+
// TODO: Add required fields for creating a ${entity.humanReadable}
|
|
88
|
+
// name: z.string().min(1).max(100),
|
|
89
|
+
// email: z.string().email(),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export type Create${entity.pascal}Data = z.infer<typeof Create${entity.pascal}Input>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Update ${entity.pascal} input schema
|
|
96
|
+
*/
|
|
97
|
+
export const Update${entity.pascal}Input = z.object({
|
|
98
|
+
// TODO: Add optional fields for updating a ${entity.humanReadable}
|
|
99
|
+
// name: z.string().min(1).max(100).optional(),
|
|
100
|
+
// email: z.string().email().optional(),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export type Update${entity.pascal}Data = z.infer<typeof Update${entity.pascal}Input>;
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
// ============================================================================
|
|
107
|
+
// Procedures Template
|
|
108
|
+
// ============================================================================
|
|
109
|
+
/**
|
|
110
|
+
* Generate procedures file
|
|
111
|
+
*/
|
|
112
|
+
function generateProcedures(ctx) {
|
|
113
|
+
const { entity, options } = ctx;
|
|
114
|
+
const paginationImport = options.paginated ? ', paginationInputSchema' : '';
|
|
115
|
+
const listOutput = options.paginated
|
|
116
|
+
? `z.object({
|
|
117
|
+
data: z.array(${entity.pascal}Schema),
|
|
118
|
+
meta: z.object({
|
|
119
|
+
page: z.number(),
|
|
120
|
+
limit: z.number(),
|
|
121
|
+
total: z.number(),
|
|
122
|
+
}),
|
|
123
|
+
})`
|
|
124
|
+
: `z.array(${entity.pascal}Schema)`;
|
|
125
|
+
const listInput = options.paginated ? `.input(paginationInputSchema.optional())` : '';
|
|
126
|
+
const listLogic = options.paginated
|
|
127
|
+
? `const page = input?.page ?? 1;
|
|
128
|
+
const limit = input?.limit ?? 10;
|
|
129
|
+
const skip = (page - 1) * limit;
|
|
130
|
+
${options.softDelete ? 'const where = { deletedAt: null };' : ''}
|
|
131
|
+
|
|
132
|
+
const [items, total] = await Promise.all([
|
|
133
|
+
ctx.db.${entity.camel}.findMany({ ${options.softDelete ? 'where, ' : ''}skip, take: limit }),
|
|
134
|
+
ctx.db.${entity.camel}.count(${options.softDelete ? '{ where }' : ''}),
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
data: items.map(toResponse),
|
|
139
|
+
meta: { page, limit, total },
|
|
140
|
+
};`
|
|
141
|
+
: `${options.softDelete ? 'const where = { deletedAt: null };' : ''}
|
|
142
|
+
const items = await ctx.db.${entity.camel}.findMany(${options.softDelete ? '{ where }' : ''});
|
|
143
|
+
return items.map(toResponse);`;
|
|
144
|
+
const deleteLogic = options.softDelete
|
|
145
|
+
? `await ctx.db.${entity.camel}.update({
|
|
146
|
+
where: { id: input.id },
|
|
147
|
+
data: { deletedAt: new Date() },
|
|
148
|
+
});`
|
|
149
|
+
: `await ctx.db.${entity.camel}.delete({
|
|
150
|
+
where: { id: input.id },
|
|
151
|
+
});`;
|
|
152
|
+
const findWhereClause = options.softDelete
|
|
153
|
+
? `{ id: input.id, deletedAt: null }`
|
|
154
|
+
: `{ id: input.id }`;
|
|
155
|
+
const responseFields = ['id: item.id,'];
|
|
156
|
+
if (options.timestamps) {
|
|
157
|
+
responseFields.push('createdAt: item.createdAt.toISOString(),');
|
|
158
|
+
responseFields.push('updatedAt: item.updatedAt.toISOString(),');
|
|
159
|
+
}
|
|
160
|
+
if (options.softDelete) {
|
|
161
|
+
responseFields.push('deletedAt: item.deletedAt?.toISOString() ?? null,');
|
|
162
|
+
}
|
|
163
|
+
const dbInterfaceFields = ['id: string;'];
|
|
164
|
+
if (options.timestamps) {
|
|
165
|
+
dbInterfaceFields.push('createdAt: Date;');
|
|
166
|
+
dbInterfaceFields.push('updatedAt: Date;');
|
|
167
|
+
}
|
|
168
|
+
if (options.softDelete) {
|
|
169
|
+
dbInterfaceFields.push('deletedAt: Date | null;');
|
|
170
|
+
}
|
|
171
|
+
return `/**
|
|
172
|
+
* ${entity.pascal} Procedures
|
|
173
|
+
*
|
|
174
|
+
* CRUD operations for ${entity.humanReadablePlural}.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
import { defineProcedures, procedure${paginationImport}, z } from '@veloxts/velox';
|
|
178
|
+
|
|
179
|
+
import {
|
|
180
|
+
${entity.pascal}Schema,
|
|
181
|
+
Create${entity.pascal}Input,
|
|
182
|
+
Update${entity.pascal}Input,
|
|
183
|
+
} from '../schemas/${entity.kebab}.js';
|
|
184
|
+
|
|
185
|
+
// ============================================================================
|
|
186
|
+
// Type Definitions
|
|
187
|
+
// ============================================================================
|
|
188
|
+
|
|
189
|
+
// Database model type - should match your Prisma schema
|
|
190
|
+
interface Db${entity.pascal} {
|
|
191
|
+
${dbInterfaceFields.join('\n ')}
|
|
192
|
+
// TODO: Add your ${entity.humanReadable} fields here
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Helper to convert database model to response
|
|
196
|
+
function toResponse(item: Db${entity.pascal}) {
|
|
197
|
+
return {
|
|
198
|
+
${responseFields.join('\n ')}
|
|
199
|
+
// TODO: Map your ${entity.humanReadable} fields here
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ============================================================================
|
|
204
|
+
// Procedures
|
|
205
|
+
// ============================================================================
|
|
206
|
+
|
|
207
|
+
export const ${entity.camel}Procedures = defineProcedures('${entity.plural}', {
|
|
208
|
+
/**
|
|
209
|
+
* Get a single ${entity.humanReadable} by ID
|
|
210
|
+
* GET /${entity.plural}/:id
|
|
211
|
+
*/
|
|
212
|
+
get${entity.pascal}: procedure()
|
|
213
|
+
.input(z.object({ id: z.string().uuid() }))
|
|
214
|
+
.output(${entity.pascal}Schema.nullable())
|
|
215
|
+
.query(async ({ input, ctx }) => {
|
|
216
|
+
const item = await ctx.db.${entity.camel}.findUnique({
|
|
217
|
+
where: ${findWhereClause},
|
|
218
|
+
});
|
|
219
|
+
return item ? toResponse(item) : null;
|
|
220
|
+
}),
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* List all ${entity.humanReadablePlural}
|
|
224
|
+
* GET /${entity.plural}
|
|
225
|
+
*/
|
|
226
|
+
list${entity.pascalPlural}: procedure()
|
|
227
|
+
${listInput}
|
|
228
|
+
.output(${listOutput})
|
|
229
|
+
.query(async ({ input, ctx }) => {
|
|
230
|
+
${listLogic}
|
|
231
|
+
}),
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Create a new ${entity.humanReadable}
|
|
235
|
+
* POST /${entity.plural}
|
|
236
|
+
*/
|
|
237
|
+
create${entity.pascal}: procedure()
|
|
238
|
+
.input(Create${entity.pascal}Input)
|
|
239
|
+
.output(${entity.pascal}Schema)
|
|
240
|
+
.mutation(async ({ input, ctx }) => {
|
|
241
|
+
const item = await ctx.db.${entity.camel}.create({
|
|
242
|
+
data: input,
|
|
243
|
+
});
|
|
244
|
+
return toResponse(item);
|
|
245
|
+
}),
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Update an existing ${entity.humanReadable} (full update)
|
|
249
|
+
* PUT /${entity.plural}/:id
|
|
250
|
+
*/
|
|
251
|
+
update${entity.pascal}: procedure()
|
|
252
|
+
.input(z.object({ id: z.string().uuid() }).merge(Update${entity.pascal}Input))
|
|
253
|
+
.output(${entity.pascal}Schema)
|
|
254
|
+
.mutation(async ({ input, ctx }) => {
|
|
255
|
+
const { id, ...data } = input;
|
|
256
|
+
const item = await ctx.db.${entity.camel}.update({
|
|
257
|
+
where: { id },
|
|
258
|
+
data,
|
|
259
|
+
});
|
|
260
|
+
return toResponse(item);
|
|
261
|
+
}),
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Partially update an existing ${entity.humanReadable}
|
|
265
|
+
* PATCH /${entity.plural}/:id
|
|
266
|
+
*/
|
|
267
|
+
patch${entity.pascal}: procedure()
|
|
268
|
+
.input(z.object({ id: z.string().uuid() }).merge(Update${entity.pascal}Input))
|
|
269
|
+
.output(${entity.pascal}Schema)
|
|
270
|
+
.mutation(async ({ input, ctx }) => {
|
|
271
|
+
const { id, ...data } = input;
|
|
272
|
+
const item = await ctx.db.${entity.camel}.update({
|
|
273
|
+
where: { id },
|
|
274
|
+
data,
|
|
275
|
+
});
|
|
276
|
+
return toResponse(item);
|
|
277
|
+
}),
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Delete a ${entity.humanReadable}
|
|
281
|
+
* DELETE /${entity.plural}/:id
|
|
282
|
+
*/
|
|
283
|
+
delete${entity.pascal}: procedure()
|
|
284
|
+
.input(z.object({ id: z.string().uuid() }))
|
|
285
|
+
.output(z.object({ success: z.boolean() }))
|
|
286
|
+
.mutation(async ({ input, ctx }) => {
|
|
287
|
+
${deleteLogic}
|
|
288
|
+
return { success: true };
|
|
289
|
+
}),
|
|
290
|
+
});
|
|
291
|
+
`;
|
|
292
|
+
}
|
|
293
|
+
// ============================================================================
|
|
294
|
+
// Template Exports
|
|
295
|
+
// ============================================================================
|
|
296
|
+
/**
|
|
297
|
+
* Model template - generates Prisma model definition
|
|
298
|
+
*/
|
|
299
|
+
export const prismaModelTemplate = (ctx) => {
|
|
300
|
+
return generatePrismaModel(ctx);
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Schema template - generates Zod schema file
|
|
304
|
+
*/
|
|
305
|
+
export const schemaTemplate = (ctx) => {
|
|
306
|
+
return generateZodSchema(ctx);
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Procedures template - generates procedure file
|
|
310
|
+
*/
|
|
311
|
+
export const proceduresTemplate = (ctx) => {
|
|
312
|
+
return generateProcedures(ctx);
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Generate all files for a model
|
|
316
|
+
*/
|
|
317
|
+
export function generateModelFiles(ctx) {
|
|
318
|
+
const { entity, options } = ctx;
|
|
319
|
+
const files = [];
|
|
320
|
+
// Always generate Prisma model snippet
|
|
321
|
+
files.push({
|
|
322
|
+
path: `prisma/models/${entity.kebab}.prisma`,
|
|
323
|
+
content: generatePrismaModel(ctx),
|
|
324
|
+
});
|
|
325
|
+
// Always generate Zod schema
|
|
326
|
+
files.push({
|
|
327
|
+
path: `src/schemas/${entity.kebab}.ts`,
|
|
328
|
+
content: generateZodSchema(ctx),
|
|
329
|
+
});
|
|
330
|
+
// Generate procedures if --crud flag is set
|
|
331
|
+
if (options.crud) {
|
|
332
|
+
files.push({
|
|
333
|
+
path: `src/procedures/${entity.plural}.ts`,
|
|
334
|
+
content: generateProcedures(ctx),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return files;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Generate post-generation instructions
|
|
341
|
+
*/
|
|
342
|
+
export function getModelInstructions(ctx) {
|
|
343
|
+
const { entity, options } = ctx;
|
|
344
|
+
let instructions = `
|
|
345
|
+
1. Copy the Prisma model to your schema:
|
|
346
|
+
|
|
347
|
+
cat prisma/models/${entity.kebab}.prisma >> prisma/schema.prisma
|
|
348
|
+
|
|
349
|
+
Then customize the fields and run:
|
|
350
|
+
pnpm db:push && pnpm db:generate
|
|
351
|
+
|
|
352
|
+
2. Export the schema:
|
|
353
|
+
|
|
354
|
+
// src/schemas/index.ts
|
|
355
|
+
export * from './${entity.kebab}.js';
|
|
356
|
+
`;
|
|
357
|
+
if (options.crud) {
|
|
358
|
+
instructions += `
|
|
359
|
+
3. Export the procedures:
|
|
360
|
+
|
|
361
|
+
// src/procedures/index.ts
|
|
362
|
+
export * from './${entity.plural}.js';
|
|
363
|
+
|
|
364
|
+
4. Register the procedures in your app:
|
|
365
|
+
|
|
366
|
+
// src/index.ts
|
|
367
|
+
import { ${entity.camel}Procedures } from './procedures/index.js';
|
|
368
|
+
|
|
369
|
+
const collections = [..., ${entity.camel}Procedures];
|
|
370
|
+
`;
|
|
371
|
+
}
|
|
372
|
+
return instructions;
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sour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AAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAkC;IACrE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAEhC,IAAI,YAAY,GAAG;;;yBAGI,MAAM,CAAC,KAAK;;;;;;;;wBAQb,MAAM,CAAC,KAAK;CACnC,CAAC;IAEA,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,YAAY,IAAI;;;;wBAII,MAAM,CAAC,MAAM;;;;;gBAKrB,MAAM,CAAC,KAAK;;iCAEK,MAAM,CAAC,KAAK;CAC5C,CAAC;IACA,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure Template
|
|
3
|
+
*
|
|
4
|
+
* Generates procedure files for VeloxTS applications.
|
|
5
|
+
*/
|
|
6
|
+
import type { TemplateFunction } from '../types.js';
|
|
7
|
+
export interface ProcedureOptions {
|
|
8
|
+
/** Generate full CRUD operations */
|
|
9
|
+
crud: boolean;
|
|
10
|
+
/** Include pagination for list operation */
|
|
11
|
+
paginated: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate procedure file content
|
|
15
|
+
*/
|
|
16
|
+
export declare const procedureTemplate: TemplateFunction<ProcedureOptions>;
|
|
17
|
+
/**
|
|
18
|
+
* Generate the file path for a procedure
|
|
19
|
+
*/
|
|
20
|
+
export declare function getProcedurePath(entityPlural: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Generate post-generation instructions
|
|
23
|
+
*/
|
|
24
|
+
export declare function getProcedureInstructions(entityPlural: string, entityPascal: string): string;
|
|
25
|
+
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../../../src/generators/templates/procedure.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMrE,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,4CAA4C;IAC5C,SAAS,EAAE,OAAO,CAAC;CACpB;AA4OD;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,CAAC,gBAAgB,CAKhE,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAyB3F"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure Template
|
|
3
|
+
*
|
|
4
|
+
* Generates procedure files for VeloxTS applications.
|
|
5
|
+
*/
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Helper Functions
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Generate a simple procedure with just a get operation
|
|
11
|
+
*/
|
|
12
|
+
function generateSimpleProcedure(ctx) {
|
|
13
|
+
const { entity } = ctx;
|
|
14
|
+
return `/**
|
|
15
|
+
* ${entity.pascal} Procedures
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { defineProcedures, procedure, z } from '@veloxts/velox';
|
|
19
|
+
|
|
20
|
+
export const ${entity.camel}Procedures = defineProcedures('${entity.plural}', {
|
|
21
|
+
/**
|
|
22
|
+
* Get a single ${entity.humanReadable} by ID
|
|
23
|
+
* GET /${entity.plural}/:id
|
|
24
|
+
*/
|
|
25
|
+
get${entity.pascal}: procedure()
|
|
26
|
+
.input(z.object({ id: z.string().uuid() }))
|
|
27
|
+
.output(
|
|
28
|
+
z.object({
|
|
29
|
+
id: z.string().uuid(),
|
|
30
|
+
// TODO: Add ${entity.humanReadable} fields
|
|
31
|
+
createdAt: z.string().datetime(),
|
|
32
|
+
updatedAt: z.string().datetime(),
|
|
33
|
+
}).nullable()
|
|
34
|
+
)
|
|
35
|
+
.query(async ({ input, ctx }) => {
|
|
36
|
+
// TODO: Implement get${entity.pascal} logic
|
|
37
|
+
// Example: return ctx.db.${entity.camel}.findUnique({ where: { id: input.id } });
|
|
38
|
+
throw new Error('Not implemented');
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Generate CRUD procedures
|
|
45
|
+
*/
|
|
46
|
+
function generateCrudProcedures(ctx) {
|
|
47
|
+
const { entity, options } = ctx;
|
|
48
|
+
const listOutput = options.paginated
|
|
49
|
+
? `z.object({
|
|
50
|
+
data: z.array(${entity.pascal}Schema),
|
|
51
|
+
meta: z.object({
|
|
52
|
+
page: z.number(),
|
|
53
|
+
limit: z.number(),
|
|
54
|
+
total: z.number(),
|
|
55
|
+
totalPages: z.number(),
|
|
56
|
+
}),
|
|
57
|
+
})`
|
|
58
|
+
: `z.array(${entity.pascal}Schema)`;
|
|
59
|
+
const listInput = options.paginated ? `.input(paginationInputSchema.optional())` : '';
|
|
60
|
+
const listLogic = options.paginated
|
|
61
|
+
? `const page = input?.page ?? 1;
|
|
62
|
+
const limit = input?.limit ?? 10;
|
|
63
|
+
const skip = (page - 1) * limit;
|
|
64
|
+
|
|
65
|
+
const [items, total] = await Promise.all([
|
|
66
|
+
ctx.db.${entity.camel}.findMany({ skip, take: limit }),
|
|
67
|
+
ctx.db.${entity.camel}.count(),
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
const totalPages = Math.ceil(total / limit);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
data: items.map(toResponse),
|
|
74
|
+
meta: { page, limit, total, totalPages },
|
|
75
|
+
};`
|
|
76
|
+
: `const items = await ctx.db.${entity.camel}.findMany();
|
|
77
|
+
return items.map(toResponse);`;
|
|
78
|
+
const paginationImport = options.paginated ? ', paginationInputSchema' : '';
|
|
79
|
+
return `/**
|
|
80
|
+
* ${entity.pascal} Procedures
|
|
81
|
+
*
|
|
82
|
+
* CRUD operations for ${entity.humanReadablePlural}.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
import { defineProcedures, procedure${paginationImport}, z } from '@veloxts/velox';
|
|
86
|
+
|
|
87
|
+
// ============================================================================
|
|
88
|
+
// Schemas
|
|
89
|
+
// ============================================================================
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* ${entity.pascal} response schema
|
|
93
|
+
*/
|
|
94
|
+
const ${entity.pascal}Schema = z.object({
|
|
95
|
+
id: z.string().uuid(),
|
|
96
|
+
// TODO: Add ${entity.humanReadable} fields here
|
|
97
|
+
createdAt: z.string().datetime(),
|
|
98
|
+
updatedAt: z.string().datetime(),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Create ${entity.pascal} input schema
|
|
103
|
+
*/
|
|
104
|
+
const Create${entity.pascal}Input = z.object({
|
|
105
|
+
// TODO: Add required fields for creating a ${entity.humanReadable}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Update ${entity.pascal} input schema
|
|
110
|
+
*/
|
|
111
|
+
const Update${entity.pascal}Input = z.object({
|
|
112
|
+
// TODO: Add optional fields for updating a ${entity.humanReadable}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ============================================================================
|
|
116
|
+
// Type Definitions
|
|
117
|
+
// ============================================================================
|
|
118
|
+
|
|
119
|
+
// Database model type - adjust to match your Prisma schema
|
|
120
|
+
interface Db${entity.pascal} {
|
|
121
|
+
id: string;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
updatedAt: Date;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Helper to convert database model to response
|
|
127
|
+
function toResponse(db${entity.pascal}: Db${entity.pascal}) {
|
|
128
|
+
return {
|
|
129
|
+
id: db${entity.pascal}.id,
|
|
130
|
+
createdAt: db${entity.pascal}.createdAt.toISOString(),
|
|
131
|
+
updatedAt: db${entity.pascal}.updatedAt.toISOString(),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Procedures
|
|
137
|
+
// ============================================================================
|
|
138
|
+
|
|
139
|
+
export const ${entity.camel}Procedures = defineProcedures('${entity.plural}', {
|
|
140
|
+
/**
|
|
141
|
+
* Get a single ${entity.humanReadable} by ID
|
|
142
|
+
* GET /${entity.plural}/:id
|
|
143
|
+
*/
|
|
144
|
+
get${entity.pascal}: procedure()
|
|
145
|
+
.input(z.object({ id: z.string().uuid() }))
|
|
146
|
+
.output(${entity.pascal}Schema.nullable())
|
|
147
|
+
.query(async ({ input, ctx }) => {
|
|
148
|
+
const item = await ctx.db.${entity.camel}.findUnique({
|
|
149
|
+
where: { id: input.id },
|
|
150
|
+
});
|
|
151
|
+
return item ? toResponse(item) : null;
|
|
152
|
+
}),
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* List all ${entity.humanReadablePlural}
|
|
156
|
+
* GET /${entity.plural}
|
|
157
|
+
*/
|
|
158
|
+
list${entity.pascalPlural}: procedure()
|
|
159
|
+
${listInput}
|
|
160
|
+
.output(${listOutput})
|
|
161
|
+
.query(async ({ input, ctx }) => {
|
|
162
|
+
${listLogic}
|
|
163
|
+
}),
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create a new ${entity.humanReadable}
|
|
167
|
+
* POST /${entity.plural}
|
|
168
|
+
*/
|
|
169
|
+
create${entity.pascal}: procedure()
|
|
170
|
+
.input(Create${entity.pascal}Input)
|
|
171
|
+
.output(${entity.pascal}Schema)
|
|
172
|
+
.mutation(async ({ input, ctx }) => {
|
|
173
|
+
const item = await ctx.db.${entity.camel}.create({
|
|
174
|
+
data: input,
|
|
175
|
+
});
|
|
176
|
+
return toResponse(item);
|
|
177
|
+
}),
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Update an existing ${entity.humanReadable} (full update)
|
|
181
|
+
* PUT /${entity.plural}/:id
|
|
182
|
+
*/
|
|
183
|
+
update${entity.pascal}: procedure()
|
|
184
|
+
.input(z.object({ id: z.string().uuid() }).merge(Update${entity.pascal}Input))
|
|
185
|
+
.output(${entity.pascal}Schema)
|
|
186
|
+
.mutation(async ({ input, ctx }) => {
|
|
187
|
+
const { id, ...data } = input;
|
|
188
|
+
const item = await ctx.db.${entity.camel}.update({
|
|
189
|
+
where: { id },
|
|
190
|
+
data,
|
|
191
|
+
});
|
|
192
|
+
return toResponse(item);
|
|
193
|
+
}),
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Partially update an existing ${entity.humanReadable}
|
|
197
|
+
* PATCH /${entity.plural}/:id
|
|
198
|
+
*/
|
|
199
|
+
patch${entity.pascal}: procedure()
|
|
200
|
+
.input(z.object({ id: z.string().uuid() }).merge(Update${entity.pascal}Input))
|
|
201
|
+
.output(${entity.pascal}Schema)
|
|
202
|
+
.mutation(async ({ input, ctx }) => {
|
|
203
|
+
const { id, ...data } = input;
|
|
204
|
+
const item = await ctx.db.${entity.camel}.update({
|
|
205
|
+
where: { id },
|
|
206
|
+
data,
|
|
207
|
+
});
|
|
208
|
+
return toResponse(item);
|
|
209
|
+
}),
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Delete a ${entity.humanReadable}
|
|
213
|
+
* DELETE /${entity.plural}/:id
|
|
214
|
+
*/
|
|
215
|
+
delete${entity.pascal}: procedure()
|
|
216
|
+
.input(z.object({ id: z.string().uuid() }))
|
|
217
|
+
.output(z.object({ success: z.boolean() }))
|
|
218
|
+
.mutation(async ({ input, ctx }) => {
|
|
219
|
+
await ctx.db.${entity.camel}.delete({
|
|
220
|
+
where: { id: input.id },
|
|
221
|
+
});
|
|
222
|
+
return { success: true };
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
`;
|
|
226
|
+
}
|
|
227
|
+
// ============================================================================
|
|
228
|
+
// Template Export
|
|
229
|
+
// ============================================================================
|
|
230
|
+
/**
|
|
231
|
+
* Generate procedure file content
|
|
232
|
+
*/
|
|
233
|
+
export const procedureTemplate = (ctx) => {
|
|
234
|
+
if (ctx.options.crud) {
|
|
235
|
+
return generateCrudProcedures(ctx);
|
|
236
|
+
}
|
|
237
|
+
return generateSimpleProcedure(ctx);
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Generate the file path for a procedure
|
|
241
|
+
*/
|
|
242
|
+
export function getProcedurePath(entityPlural) {
|
|
243
|
+
return `src/procedures/${entityPlural}.ts`;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Generate post-generation instructions
|
|
247
|
+
*/
|
|
248
|
+
export function getProcedureInstructions(entityPlural, entityPascal) {
|
|
249
|
+
return `
|
|
250
|
+
1. Add the procedure to your exports:
|
|
251
|
+
|
|
252
|
+
// src/procedures/index.ts
|
|
253
|
+
export * from './${entityPlural}.js';
|
|
254
|
+
|
|
255
|
+
2. Register the procedure collection in your app:
|
|
256
|
+
|
|
257
|
+
// src/index.ts
|
|
258
|
+
import { ${entityPlural.replace(/-/g, '')}Procedures } from './procedures/index.js';
|
|
259
|
+
|
|
260
|
+
const collections = [..., ${entityPlural.replace(/-/g, '')}Procedures];
|
|
261
|
+
|
|
262
|
+
3. If using CRUD, add the ${entityPascal} model to your Prisma schema:
|
|
263
|
+
|
|
264
|
+
// prisma/schema.prisma
|
|
265
|
+
model ${entityPascal} {
|
|
266
|
+
id String @id @default(uuid())
|
|
267
|
+
createdAt DateTime @default(now())
|
|
268
|
+
updatedAt DateTime @updatedAt
|
|
269
|
+
|
|
270
|
+
@@map("${entityPlural.replace(/-/g, '_')}")
|
|
271
|
+
}
|
|
272
|
+
`;
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=procedure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../../src/generators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