@warlock.js/core 4.0.142 → 4.0.144

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.
Files changed (42) hide show
  1. package/esm/cli/commands/generate/generate.command.d.ts.map +1 -1
  2. package/esm/cli/commands/generate/generate.command.js +20 -0
  3. package/esm/cli/commands/generate/generate.command.js.map +1 -1
  4. package/esm/cli/commands/generate/generators/column-dsl-parser.d.ts +11 -0
  5. package/esm/cli/commands/generate/generators/column-dsl-parser.d.ts.map +1 -0
  6. package/esm/cli/commands/generate/generators/column-dsl-parser.js +47 -0
  7. package/esm/cli/commands/generate/generators/column-dsl-parser.js.map +1 -0
  8. package/esm/cli/commands/generate/generators/controller.generator.js +1 -1
  9. package/esm/cli/commands/generate/generators/controller.generator.js.map +1 -1
  10. package/esm/cli/commands/generate/generators/migration.generator.d.ts +1 -1
  11. package/esm/cli/commands/generate/generators/migration.generator.d.ts.map +1 -1
  12. package/esm/cli/commands/generate/generators/migration.generator.js +44 -4
  13. package/esm/cli/commands/generate/generators/migration.generator.js.map +1 -1
  14. package/esm/cli/commands/generate/generators/model.generator.d.ts.map +1 -1
  15. package/esm/cli/commands/generate/generators/model.generator.js +5 -3
  16. package/esm/cli/commands/generate/generators/model.generator.js.map +1 -1
  17. package/esm/cli/commands/generate/generators/module.generator.d.ts.map +1 -1
  18. package/esm/cli/commands/generate/generators/module.generator.js +19 -27
  19. package/esm/cli/commands/generate/generators/module.generator.js.map +1 -1
  20. package/esm/cli/commands/generate/generators/repository.generator.js +1 -1
  21. package/esm/cli/commands/generate/generators/repository.generator.js.map +1 -1
  22. package/esm/cli/commands/generate/generators/resource.generator.js +1 -1
  23. package/esm/cli/commands/generate/generators/resource.generator.js.map +1 -1
  24. package/esm/cli/commands/generate/generators/service.generator.js +1 -1
  25. package/esm/cli/commands/generate/generators/service.generator.js.map +1 -1
  26. package/esm/cli/commands/generate/generators/validation.generator.js +1 -1
  27. package/esm/cli/commands/generate/generators/validation.generator.js.map +1 -1
  28. package/esm/cli/commands/generate/templates/stubs.d.ts +42 -27
  29. package/esm/cli/commands/generate/templates/stubs.d.ts.map +1 -1
  30. package/esm/cli/commands/generate/templates/stubs.js +184 -237
  31. package/esm/cli/commands/generate/templates/stubs.js.map +1 -1
  32. package/esm/cli/commands/generate/utils/name-parser.d.ts +22 -27
  33. package/esm/cli/commands/generate/utils/name-parser.d.ts.map +1 -1
  34. package/esm/cli/commands/generate/utils/name-parser.js +41 -52
  35. package/esm/cli/commands/generate/utils/name-parser.js.map +1 -1
  36. package/esm/cli/commands/migrate.command.d.ts.map +1 -1
  37. package/esm/cli/commands/migrate.command.js +5 -0
  38. package/esm/cli/commands/migrate.command.js.map +1 -1
  39. package/esm/database/migrate-action.d.ts.map +1 -1
  40. package/esm/database/migrate-action.js +7 -2
  41. package/esm/database/migrate-action.js.map +1 -1
  42. package/package.json +8 -7
@@ -1,4 +1,4 @@
1
- import {parseName}from'../utils/name-parser.js';/**
1
+ /**
2
2
  * Controller template stub
3
3
  */
4
4
  function controllerStub(name, options = {}) {
@@ -29,29 +29,24 @@ ${name.camel}Controller.validation = {
29
29
  * Note: moduleName is the module (plural), we need singular entity name
30
30
  */
31
31
  function crudCreateControllerStub(moduleName) {
32
- // Get singular entity name (e.g., "products" -> "product")
33
- const entityKebab = moduleName.kebab.endsWith("s")
34
- ? moduleName.kebab.slice(0, -1)
35
- : moduleName.kebab;
36
- const entity = parseName(entityKebab);
37
32
  return `import { type RequestHandler } from "@warlock.js/core";
38
- import { type Create${entity.pascal}Request } from "../requests/create-${entity.kebab}.request";
39
- import { create${entity.pascal}Schema } from "../schema/create-${entity.kebab}.schema";
40
- import { create${entity.pascal}Service } from "../services/create-${entity.kebab}.service";
33
+ import { type Create${moduleName.pascal}Request } from "../requests/create-${moduleName.kebab}.request";
34
+ import { create${moduleName.pascal}Schema } from "../schema/create-${moduleName.kebab}.schema";
35
+ import { create${moduleName.pascal}Service } from "../services/create-${moduleName.kebab}.service";
41
36
 
42
- export const create${entity.pascal}Controller: RequestHandler = async (
43
- request: Create${entity.pascal}Request,
37
+ export const create${moduleName.pascal}Controller: RequestHandler = async (
38
+ request: Create${moduleName.pascal}Request,
44
39
  response,
45
40
  ) => {
46
- const ${entity.camel} = await create${entity.pascal}Service(request.validated());
41
+ const ${moduleName.camel} = await create${moduleName.pascal}Service(request.validated());
47
42
 
48
43
  return response.success({
49
- ${entity.camel},
44
+ ${moduleName.camel},
50
45
  });
51
46
  };
52
47
 
53
- create${entity.pascal}Controller.validation = {
54
- schema: create${entity.pascal}Schema,
48
+ create${moduleName.pascal}Controller.validation = {
49
+ schema: create${moduleName.pascal}Schema,
55
50
  };
56
51
  `;
57
52
  }
@@ -59,33 +54,24 @@ create${entity.pascal}Controller.validation = {
59
54
  * CRUD Update Controller template
60
55
  */
61
56
  function crudUpdateControllerStub(moduleName) {
62
- // Get singular entity name
63
- const entityKebab = moduleName.kebab.endsWith("s")
64
- ? moduleName.kebab.slice(0, -1)
65
- : moduleName.kebab;
66
- const entity = parseName(entityKebab);
67
57
  return `import { type RequestHandler } from "@warlock.js/core";
68
- import { type Update${entity.pascal}Request } from "../requests/update-${entity.kebab}.request";
69
- import { update${entity.pascal}Schema } from "../schema/update-${entity.kebab}.schema";
70
- import { update${entity.pascal}Service } from "../services/update-${entity.kebab}.service";
58
+ import { type Update${moduleName.pascal}Request } from "../requests/update-${moduleName.kebab}.request";
59
+ import { update${moduleName.pascal}Schema } from "../schema/update-${moduleName.kebab}.schema";
60
+ import { update${moduleName.pascal}Service } from "../services/update-${moduleName.kebab}.service";
71
61
 
72
- export const update${entity.pascal}Controller: RequestHandler = async (
73
- request: Update${entity.pascal}Request,
62
+ export const update${moduleName.pascal}Controller: RequestHandler = async (
63
+ request: Update${moduleName.pascal}Request,
74
64
  response,
75
65
  ) => {
76
- const ${entity.camel} = await update${entity.pascal}Service(request.int("id"), request.validated());
77
-
78
- if (!${entity.camel}) {
79
- return response.notFound();
80
- }
66
+ const ${moduleName.camel} = await update${moduleName.pascal}Service(request.input("id"), request.validated());
81
67
 
82
68
  return response.success({
83
- ${entity.camel},
69
+ ${moduleName.camel},
84
70
  });
85
71
  };
86
72
 
87
- update${entity.pascal}Controller.validation = {
88
- schema: update${entity.pascal}Schema,
73
+ update${moduleName.pascal}Controller.validation = {
74
+ schema: update${moduleName.pascal}Schema,
89
75
  };
90
76
  `;
91
77
  }
@@ -93,18 +79,15 @@ update${entity.pascal}Controller.validation = {
93
79
  * CRUD List Controller template
94
80
  */
95
81
  function crudListControllerStub(moduleName) {
96
- const entityKebab = moduleName.kebab.endsWith("s")
97
- ? moduleName.kebab.slice(0, -1)
98
- : moduleName.kebab;
99
- const entity = parseName(entityKebab);
82
+ const plural = moduleName.plural;
100
83
  return `import { type RequestHandler } from "@warlock.js/core";
101
- import { list${entity.pascal}sService } from "../services/list-${moduleName.kebab}.service";
84
+ import { list${plural.pascal}Service } from "../services/list-${plural.kebab}.service";
102
85
 
103
- export const list${entity.pascal}sController: RequestHandler = async (
86
+ export const list${plural.pascal}Controller: RequestHandler = async (
104
87
  request,
105
88
  response,
106
89
  ) => {
107
- const { data, pagination } = await list${entity.pascal}sService(request.all());
90
+ const { data, pagination } = await list${plural.pascal}Service(request.all());
108
91
 
109
92
  return response.success({
110
93
  data,
@@ -117,25 +100,21 @@ export const list${entity.pascal}sController: RequestHandler = async (
117
100
  * CRUD Show/Get Controller template
118
101
  */
119
102
  function crudShowControllerStub(moduleName) {
120
- const entityKebab = moduleName.kebab.endsWith("s")
121
- ? moduleName.kebab.slice(0, -1)
122
- : moduleName.kebab;
123
- const entity = parseName(entityKebab);
124
103
  return `import { type RequestHandler } from "@warlock.js/core";
125
- import { get${entity.pascal}Service } from "../services/get-${entity.kebab}.service";
104
+ import { get${moduleName.pascal}Service } from "../services/get-${moduleName.kebab}.service";
126
105
 
127
- export const get${entity.pascal}Controller: RequestHandler = async (
106
+ export const get${moduleName.pascal}Controller: RequestHandler = async (
128
107
  request,
129
108
  response,
130
109
  ) => {
131
- const ${entity.camel} = await get${entity.pascal}Service(request.int("id"));
110
+ const ${moduleName.camel} = await get${moduleName.pascal}Service(request.input("id"));
132
111
 
133
- if (!${entity.camel}) {
112
+ if (!${moduleName.camel}) {
134
113
  return response.notFound();
135
114
  }
136
115
 
137
116
  return response.success({
138
- ${entity.camel},
117
+ ${moduleName.camel},
139
118
  });
140
119
  };
141
120
  `;
@@ -144,21 +123,17 @@ export const get${entity.pascal}Controller: RequestHandler = async (
144
123
  * CRUD Delete Controller template
145
124
  */
146
125
  function crudDeleteControllerStub(moduleName) {
147
- const entityKebab = moduleName.kebab.endsWith("s")
148
- ? moduleName.kebab.slice(0, -1)
149
- : moduleName.kebab;
150
- const entity = parseName(entityKebab);
151
126
  return `import { type RequestHandler } from "@warlock.js/core";
152
- import { delete${entity.pascal}Service } from "../services/delete-${entity.kebab}.service";
127
+ import { delete${moduleName.pascal}Service } from "../services/delete-${moduleName.kebab}.service";
153
128
 
154
- export const delete${entity.pascal}Controller: RequestHandler = async (
129
+ export const delete${moduleName.pascal}Controller: RequestHandler = async (
155
130
  request,
156
131
  response,
157
132
  ) => {
158
- await delete${entity.pascal}Service(request.int("id"));
133
+ await delete${moduleName.pascal}Service(request.input("id"));
159
134
 
160
135
  return response.success({
161
- message: "${entity.pascal} deleted successfully",
136
+ message: "${moduleName.pascal} deleted successfully",
162
137
  });
163
138
  };
164
139
  `;
@@ -167,26 +142,24 @@ export const delete${entity.pascal}Controller: RequestHandler = async (
167
142
  * CRUD Routes template
168
143
  */
169
144
  function crudRoutesStub(moduleName) {
170
- const entityKebab = moduleName.kebab.endsWith("s")
171
- ? moduleName.kebab.slice(0, -1)
172
- : moduleName.kebab;
173
- const entity = parseName(entityKebab);
145
+ const singular = moduleName.singular;
146
+ const plural = moduleName.plural;
174
147
  return `import { router } from "@warlock.js/core";
175
148
  import { guarded } from "app/shared/utils/router";
176
- import { create${entity.pascal}Controller } from "./controllers/create-${entity.kebab}.controller";
177
- import { delete${entity.pascal}Controller } from "./controllers/delete-${entity.kebab}.controller";
178
- import { get${entity.pascal}Controller } from "./controllers/get-${entity.kebab}.controller";
179
- import { list${entity.pascal}sController } from "./controllers/list-${moduleName.kebab}.controller";
180
- import { update${entity.pascal}Controller } from "./controllers/update-${entity.kebab}.controller";
149
+ import { create${singular.pascal}Controller } from "./controllers/create-${singular.kebab}.controller";
150
+ import { delete${singular.pascal}Controller } from "./controllers/delete-${singular.kebab}.controller";
151
+ import { get${singular.pascal}Controller } from "./controllers/get-${singular.kebab}.controller";
152
+ import { list${plural.pascal}Controller } from "./controllers/list-${plural.kebab}.controller";
153
+ import { update${singular.pascal}Controller } from "./controllers/update-${singular.kebab}.controller";
181
154
 
182
155
  guarded(() => {
183
156
  router
184
- .route("/${moduleName.kebab}")
185
- .list(list${entity.pascal}sController)
186
- .show(get${entity.pascal}Controller)
187
- .create(create${entity.pascal}Controller)
188
- .update(update${entity.pascal}Controller)
189
- .destroy(delete${entity.pascal}Controller);
157
+ .route("/${plural.kebab}")
158
+ .list(list${plural.pascal}Controller)
159
+ .show(get${singular.pascal}Controller)
160
+ .create(create${singular.pascal}Controller)
161
+ .update(update${singular.pascal}Controller)
162
+ .destroy(delete${singular.pascal}Controller);
190
163
  });
191
164
  `;
192
165
  }
@@ -194,31 +167,27 @@ guarded(() => {
194
167
  * CRUD Model template
195
168
  */
196
169
  function crudModelStub(moduleName) {
197
- // Get singular entity name
198
- const entityKebab = moduleName.kebab.endsWith("s")
199
- ? moduleName.kebab.slice(0, -1)
200
- : moduleName.kebab;
201
- const entity = parseName(entityKebab);
170
+ const singular = moduleName.singular;
171
+ const plural = moduleName.plural;
202
172
  return `import { Model, RegisterModel } from "@warlock.js/cascade";
203
173
  import { type Infer, v } from "@warlock.js/core";
204
- import { ${entity.pascal}Resource } from "app/${moduleName.kebab}/resources/${entity.kebab}.resource";
174
+ import { ${singular.pascal}Resource } from "app/${plural.kebab}/resources/${singular.kebab}.resource";
205
175
 
206
- export const ${entity.camel}Schema = v.object({
207
- name: v.string().required(),
176
+ export const ${singular.camel}Schema = v.object({
208
177
  // TODO: Add more fields
209
178
  });
210
179
 
211
- type ${entity.pascal}Schema = Infer<typeof ${entity.camel}Schema>;
180
+ type ${singular.pascal}Schema = Infer<typeof ${singular.camel}Schema>;
212
181
 
213
182
  @RegisterModel()
214
- export class ${entity.pascal} extends Model<${entity.pascal}Schema> {
215
- public static table = "${moduleName.snake}";
183
+ export class ${singular.pascal} extends Model<${singular.pascal}Schema> {
184
+ public static table = "${plural.snake}";
216
185
 
217
- public static schema = ${entity.camel}Schema;
186
+ public static schema = ${singular.camel}Schema;
218
187
 
219
188
  public static relations = {};
220
189
 
221
- public static resource = ${entity.pascal}Resource;
190
+ public static resource = ${singular.pascal}Resource;
222
191
  }
223
192
  `;
224
193
  }
@@ -227,20 +196,13 @@ export class ${entity.pascal} extends Model<${entity.pascal}Schema> {
227
196
  */
228
197
  function crudResourceStub(moduleName) {
229
198
  // Get singular entity name
230
- const entityKebab = moduleName.kebab.endsWith("s")
231
- ? moduleName.kebab.slice(0, -1)
232
- : moduleName.kebab;
233
- const entity = parseName(entityKebab);
199
+ const entity = moduleName.singular;
234
200
  return `import { defineResource } from "@warlock.js/core";
235
201
 
236
202
  export const ${entity.pascal}Resource = defineResource({
237
203
  schema: {
238
204
  id: "number",
239
- name: "string",
240
- // TODO: Add more fields
241
- createdBy: "object",
242
- updatedBy: "object",
243
- isActive: "boolean",
205
+ // TODO: Add more resource fields
244
206
  },
245
207
  });
246
208
  `;
@@ -248,22 +210,26 @@ export const ${entity.pascal}Resource = defineResource({
248
210
  /**
249
211
  * CRUD Repository template
250
212
  */
251
- function crudRepositoryStub(moduleName) {
252
- const entityKebab = moduleName.kebab.endsWith("s")
253
- ? moduleName.kebab.slice(0, -1)
254
- : moduleName.kebab;
255
- const entity = parseName(entityKebab);
213
+ function crudRepositoryStub(entity) {
214
+ const moduleSingularName = entity.singular;
215
+ const modulePluralName = entity.plural;
256
216
  return `import type { FilterRules, RepositoryOptions } from "@warlock.js/core";
257
217
  import { RepositoryManager } from "@warlock.js/core";
258
- import { ${entity.pascal} } from "../models/${entity.kebab}";
218
+ import { ${moduleSingularName.pascal} } from "../models/${moduleSingularName.kebab}";
219
+
220
+ type ${moduleSingularName.pascal}ListFilter = {
221
+ // Repository list filters
222
+ };
259
223
 
260
- class ${entity.pascal}Repository extends RepositoryManager<${entity.pascal}> {
261
- public source = ${entity.pascal};
224
+ export type ${moduleSingularName.pascal}ListOptions = RepositoryOptions & ${moduleSingularName.pascal}ListFilter;
225
+
226
+ class ${modulePluralName.pascal}Repository extends RepositoryManager<${moduleSingularName.pascal}, ${moduleSingularName.pascal}ListOptions> {
227
+ public source = ${moduleSingularName.pascal};
262
228
 
263
229
  public simpleSelectColumns: string[] = ["id"];
264
230
 
265
231
  public filterBy: FilterRules = {
266
- id: "int",
232
+ id: "=",
267
233
  };
268
234
 
269
235
  public defaultOptions: RepositoryOptions = {
@@ -273,121 +239,104 @@ class ${entity.pascal}Repository extends RepositoryManager<${entity.pascal}> {
273
239
  };
274
240
  }
275
241
 
276
- export const ${moduleName.camel}Repository = new ${entity.pascal}Repository();
242
+ export const ${modulePluralName.camel}Repository = new ${modulePluralName.pascal}Repository();
277
243
  `;
278
244
  }
279
245
  /**
280
246
  * CRUD Create Service template
281
247
  */
282
- function crudCreateServiceStub(moduleName) {
283
- const entityKebab = moduleName.kebab.endsWith("s")
284
- ? moduleName.kebab.slice(0, -1)
285
- : moduleName.kebab;
286
- const entity = parseName(entityKebab);
287
- return `import { ${entity.pascal} } from "../models/${entity.kebab}";
288
- import type { Create${entity.pascal}Schema } from "../schema/create-${entity.kebab}.schema";
289
-
290
- export async function create${entity.pascal}Service(data: Create${entity.pascal}Schema) {
291
- const ${entity.camel} = await ${entity.pascal}.create(data);
292
- return ${entity.camel};
248
+ function crudCreateServiceStub(entity) {
249
+ const moduleSingularName = entity.singular;
250
+ return `import { ${moduleSingularName.pascal} } from "../models/${moduleSingularName.kebab}";
251
+ import type { Create${moduleSingularName.pascal}Schema } from "../schema/create-${moduleSingularName.kebab}.schema";
252
+
253
+ export async function create${moduleSingularName.pascal}Service(data: Create${moduleSingularName.pascal}Schema) {
254
+ const ${moduleSingularName.camel} = await ${moduleSingularName.pascal}.create(data);
255
+ return ${moduleSingularName.camel};
293
256
  }
294
257
  `;
295
258
  }
296
259
  /**
297
260
  * CRUD Update Service template
298
261
  */
299
- function crudUpdateServiceStub(moduleName) {
300
- const entityKebab = moduleName.kebab.endsWith("s")
301
- ? moduleName.kebab.slice(0, -1)
302
- : moduleName.kebab;
303
- const entity = parseName(entityKebab);
262
+ function crudUpdateServiceStub(entity) {
263
+ const moduleSingularName = entity.singular;
304
264
  return `import { ResourceNotFoundError } from "@warlock.js/core";
305
- import { ${entity.pascal} } from "../models/${entity.kebab}";
306
- import type { Update${entity.pascal}Schema } from "../schema/update-${entity.kebab}.schema";
265
+ import { get${moduleSingularName.pascal}Service } from "./get-${moduleSingularName.kebab}.service";
266
+ import type { Update${moduleSingularName.pascal}Schema } from "../schema/update-${moduleSingularName.kebab}.schema";
307
267
 
308
- export async function update${entity.pascal}Service(id: number, data: Update${entity.pascal}Schema) {
309
- const ${entity.camel} = await ${entity.pascal}.find(id);
310
- if (!${entity.camel}) {
311
- throw new ResourceNotFoundError("${entity.pascal} not found");
312
- }
313
- await ${entity.camel}.save({ merge: data });
314
- return ${entity.camel};
268
+ export async function update${moduleSingularName.pascal}Service(id: number | string, data: Update${moduleSingularName.pascal}Schema) {
269
+ const ${moduleSingularName.camel} = await get${moduleSingularName.pascal}Service(id);
270
+
271
+ await ${moduleSingularName.camel}.save({ merge: data });
272
+ return ${moduleSingularName.camel};
315
273
  }
316
274
  `;
317
275
  }
318
276
  /**
319
277
  * CRUD List Service template
320
278
  */
321
- function crudListServiceStub(moduleName) {
322
- const entityKebab = moduleName.kebab.endsWith("s")
323
- ? moduleName.kebab.slice(0, -1)
324
- : moduleName.kebab;
325
- const entity = parseName(entityKebab);
326
- return `import { ${moduleName.camel}Repository } from "../repositories/${moduleName.kebab}.repository";
279
+ function crudListServiceStub(entity) {
280
+ const modulePluralName = entity.plural;
281
+ return `import { ${modulePluralName.camel}Repository } from "../repositories/${modulePluralName.kebab}.repository";
327
282
 
328
- export async function list${entity.pascal}sService(filters: any) {
329
- return ${moduleName.camel}Repository.listCached(filters);
283
+ export async function list${modulePluralName.pascal}Service(filters: any) {
284
+ return ${modulePluralName.camel}Repository.listCached(filters);
330
285
  }
331
286
  `;
332
287
  }
333
288
  /**
334
289
  * CRUD Get Service template
335
290
  */
336
- function crudGetServiceStub(moduleName) {
337
- const entityKebab = moduleName.kebab.endsWith("s")
338
- ? moduleName.kebab.slice(0, -1)
339
- : moduleName.kebab;
340
- const entity = parseName(entityKebab);
341
- return `import { ${moduleName.camel}Repository } from "../repositories/${moduleName.kebab}.repository";
291
+ function crudGetServiceStub(entity) {
292
+ return `import { ${entity.plural.camel}Repository } from "../repositories/${entity.plural.kebab}.repository";
293
+ import { ResourceNotFoundError } from "@warlock.js/core";
294
+
295
+ export async function get${entity.singular.pascal}Service(id: number | string) {
296
+ const ${entity.singular.camel} = await ${entity.plural.camel}Repository.getCached(id);
342
297
 
343
- export async function get${entity.pascal}Service(id: number) {
344
- return ${moduleName.camel}Repository.getCached(id);
298
+ if (!${entity.singular.camel}) {
299
+ throw new ResourceNotFoundError("${entity.singular.pascal} resource not found!");
300
+ }
301
+
302
+ return ${entity.singular.camel};
345
303
  }
346
304
  `;
347
305
  }
348
306
  /**
349
307
  * CRUD Delete Service template
350
308
  */
351
- function crudDeleteServiceStub(moduleName) {
352
- const entityKebab = moduleName.kebab.endsWith("s")
353
- ? moduleName.kebab.slice(0, -1)
354
- : moduleName.kebab;
355
- const entity = parseName(entityKebab);
309
+ function crudDeleteServiceStub(entity) {
310
+ const singular = entity.singular;
356
311
  return `import { ResourceNotFoundError } from "@warlock.js/core";
357
- import { ${entity.pascal} } from "../models/${entity.kebab}";
312
+ import { get${singular.pascal}Service } from "./get-${singular.kebab}.service";
358
313
 
359
- export async function delete${entity.pascal}Service(id: number) {
360
- const ${entity.camel} = await ${entity.pascal}.find(id);
361
- if (!${entity.camel}) {
362
- throw new ResourceNotFoundError("${entity.pascal} not found");
314
+ export async function delete${singular.pascal}Service(id: number | string) {
315
+ const ${singular.camel} = await get${singular.pascal}Service(id);
316
+ if (!${singular.camel}) {
317
+ throw new ResourceNotFoundError("${singular.pascal} not found");
363
318
  }
364
- await ${entity.camel}.destroy();
319
+ await ${singular.camel}.destroy();
365
320
  }
366
321
  `;
367
322
  }
368
323
  /**
369
324
  * CRUD Seed template
370
325
  */
371
- function crudSeedStub(moduleName) {
372
- const entityKebab = moduleName.kebab.endsWith("s")
373
- ? moduleName.kebab.slice(0, -1)
374
- : moduleName.kebab;
375
- const entity = parseName(entityKebab);
376
- return `import { Random } from "@mongez/reinforcements";
377
- import { seeder } from "@warlock.js/core";
378
- import { ${entity.pascal} } from "../models/${entity.kebab}";
326
+ function crudSeedStub(entity) {
327
+ return `import { seeder } from "@warlock.js/core";
328
+ import { ${entity.singular.pascal} } from "../models/${entity.singular.kebab}";
379
329
 
380
330
  export default seeder({
381
- name: "Seed ${entity.pascal}s",
331
+ name: "Seed ${entity.plural.pascal}",
382
332
  once: true,
383
333
  enabled: true,
384
334
  run: async () => {
385
335
  const total = 10;
386
336
  for (let i = 0; i < total; i++) {
387
- // await ${entity.pascal}.create({
388
- // name: \`${entity.pascal} \${Random.int()}\`,
389
- // // TODO: Add more fields
390
- // });
337
+ await ${entity.singular.pascal}.create({
338
+ // TODO: Add more fields
339
+ });
391
340
  }
392
341
 
393
342
  return {
@@ -400,42 +349,47 @@ export default seeder({
400
349
  /**
401
350
  * Migration template
402
351
  */
403
- function migrationStub(entityName) {
404
- return `import { Migration } from "@warlock.js/cascade";
352
+ /**
353
+ * Migration Create template
354
+ */
355
+ function migrationStub(entityName, options = {}) {
356
+ const { columns = "", imports = [], timestamps = true } = options;
357
+ const allImports = ["Migration", ...imports].join(", ");
358
+ let optionsString = "";
359
+ if (timestamps === false) {
360
+ optionsString = `, { timestamps: false }`;
361
+ }
362
+ return `import { ${allImports} } from "@warlock.js/cascade";
405
363
  import { ${entityName.pascal} } from "../${entityName.kebab}.model";
406
364
 
407
- export default class ${entityName.pascal}Migration extends Migration.for(${entityName.pascal}) {
408
- /**
409
- * Migration metadata
410
- */
411
- public static createdAt = "${new Date().toISOString()}";
412
-
413
- /**
414
- * Set migration execution order (If it holds other migrations references)
415
- */
416
- public static order = 0;
417
-
418
- public up() {
419
- // Create table
420
- this.createTableIfNotExists();
421
-
422
- // Primary key
423
- this.id();
424
-
425
- // Add your schema fields here
426
- this.text("name").notNullable();
427
-
428
- // Status
429
- this.boolean("isActive").default(true);
430
-
431
- // Timestamps
432
- this.timestamps();
433
- }
434
-
435
- public down() {
436
- this.dropTableIfExists();
437
- }
365
+ export default Migration.create(${entityName.pascal}, {
366
+ ${columns ? columns : " // add your columns here, id is auto added to the list"}
367
+ }${optionsString});
368
+ `;
438
369
  }
370
+ /**
371
+ * Migration Alter template
372
+ */
373
+ function migrationAlterStub(entityName, options = {}) {
374
+ const { add = "", drop, rename, imports = [] } = options;
375
+ const allImports = ["Migration", ...imports].join(", ");
376
+ // Build the schema object dynamically
377
+ const schemaParts = [];
378
+ if (add) {
379
+ schemaParts.push(` add: {\n${add}\n },`);
380
+ }
381
+ if (drop) {
382
+ schemaParts.push(` drop: ${drop},`);
383
+ }
384
+ if (rename) {
385
+ schemaParts.push(` rename: ${rename},`);
386
+ }
387
+ return `import { ${allImports} } from "@warlock.js/cascade";
388
+ import { ${entityName.pascal} } from "../${entityName.kebab}.model";
389
+
390
+ export default Migration.alter(${entityName.pascal}, {
391
+ ${schemaParts.join("\n")}
392
+ });
439
393
  `;
440
394
  }
441
395
  /**
@@ -443,19 +397,13 @@ export default class ${entityName.pascal}Migration extends Migration.for(${entit
443
397
  * Outputs to: schema/create-{entity}.schema.ts
444
398
  */
445
399
  function crudCreateValidationStub(moduleName) {
446
- // Get singular entity name
447
- const entityKebab = moduleName.kebab.endsWith("s")
448
- ? moduleName.kebab.slice(0, -1)
449
- : moduleName.kebab;
450
- const entity = parseName(entityKebab);
451
400
  return `import { v, type Infer } from "@warlock.js/core";
452
401
 
453
- export const create${entity.pascal}Schema = v.object({
454
- name: v.string().required(),
402
+ export const create${moduleName.pascal}Schema = v.object({
455
403
  // TODO: Add validation rules
456
404
  });
457
405
 
458
- export type Create${entity.pascal}Schema = Infer<typeof create${entity.pascal}Schema>;
406
+ export type Create${moduleName.pascal}Schema = Infer<typeof create${moduleName.pascal}Schema>;
459
407
  `;
460
408
  }
461
409
  /**
@@ -463,19 +411,14 @@ export type Create${entity.pascal}Schema = Infer<typeof create${entity.pascal}Sc
463
411
  * Outputs to: schema/update-{entity}.schema.ts
464
412
  */
465
413
  function crudUpdateValidationStub(moduleName) {
466
- // Get singular entity name
467
- const entityKebab = moduleName.kebab.endsWith("s")
468
- ? moduleName.kebab.slice(0, -1)
469
- : moduleName.kebab;
470
- const entity = parseName(entityKebab);
471
- return `import { v, type Infer } from "@warlock.js/core";
414
+ return `import { v, type Infer } from "@warlock.js/seal";
472
415
 
473
- export const update${entity.pascal}Schema = v.object({
416
+ export const update${moduleName.pascal}Schema = v.object({
474
417
  name: v.string(),
475
418
  // TODO: Add validation rules
476
419
  });
477
420
 
478
- export type Update${entity.pascal}Schema = Infer<typeof update${entity.pascal}Schema>;
421
+ export type Update${moduleName.pascal}Schema = Infer<typeof update${moduleName.pascal}Schema>;
479
422
  `;
480
423
  }
481
424
  /**
@@ -493,7 +436,7 @@ function serviceStub(name) {
493
436
  * Outputs to: schema/{name}.schema.ts
494
437
  */
495
438
  function validationStub(name) {
496
- return `import { v, type Infer } from "@warlock.js/core";
439
+ return `import { v, type Infer } from "@warlock.js/seal";
497
440
 
498
441
  export const ${name.camel}Schema = v.object({
499
442
  // TODO: Define validation schema
@@ -516,27 +459,28 @@ export type ${name.pascal}Request = Request<${name.pascal}Schema>;
516
459
  * Model template stub
517
460
  */
518
461
  function modelStub(name, options = {}) {
519
- const { tableName = `${name.snake}s`, withResource } = options;
462
+ const { tableName = `${name.plural.snake}`, withResource } = options;
520
463
  return `import { Model } from "@warlock.js/core";
521
464
  import type { StrictMode } from "@warlock.js/cascade";
522
465
  import { v, type Infer } from "@warlock.js/core";
523
- ${withResource ? `import { ${name.pascal}Resource } from "../../resources/${name.kebab}.resource";` : ""}
466
+ ${withResource ? `import { ${name.singular.pascal}Resource } from "../../resources/${name.singular.kebab}.resource";` : ""}
524
467
 
525
- const ${name.camel}Schema = v.object({
468
+ const ${name.singular.camel}Schema = v.object({
526
469
  // TODO: Define model schema
527
- name: v.string().required(),
528
470
  });
529
471
 
530
- type ${name.pascal}Type = Infer<typeof ${name.camel}Schema>;
472
+ type ${name.singular.pascal}Type = Infer<typeof ${name.singular.camel}Schema>;
531
473
 
532
- export class ${name.pascal} extends Model<${name.pascal}Type> {
474
+ export class ${name.singular.pascal} extends Model<${name.singular.pascal}Type> {
533
475
  public static table = "${tableName}";
534
476
  public static strictMode: StrictMode = "fail";
535
- ${withResource ? ` public static resource = ${name.pascal}Resource;` : ""}
477
+ ${withResource ? ` public static resource = ${name.singular.pascal}Resource;` : ""}
536
478
 
537
- public static schema = ${name.camel}Schema;
479
+ public static schema = ${name.singular.camel}Schema;
538
480
 
539
- public embed = ["id", "name"];
481
+ public static relations = {
482
+ // TODO: Define relations
483
+ };
540
484
  }
541
485
  `;
542
486
  }
@@ -546,10 +490,16 @@ ${withResource ? ` public static resource = ${name.pascal}Resource;` : ""}
546
490
  function repositoryStub(name) {
547
491
  return `import type { FilterByOptions, RepositoryOptions } from "@warlock.js/core";
548
492
  import { RepositoryManager } from "@warlock.js/core";
549
- import { ${name.pascal} } from "../models/${name.kebab}";
493
+ import { ${name.singular.pascal} } from "../models/${name.singular.kebab}";
494
+
495
+ type ${name.singular.pascal}ListFilter = {
496
+ // Repository list filters
497
+ };
550
498
 
551
- export class ${name.pascal}Repository extends RepositoryManager<${name.pascal}> {
552
- public source = ${name.pascal};
499
+ export type ${name.singular.pascal}ListOptions = RepositoryOptions & ${name.singular.pascal}ListFilter;
500
+
501
+ export class ${name.plural.pascal}Repository extends RepositoryManager<${name.singular.pascal}, ${name.singular.pascal}ListFilter> {
502
+ public source = ${name.singular.pascal};
553
503
 
554
504
  protected defaultOptions: RepositoryOptions = this.withDefaultOptions({});
555
505
 
@@ -558,7 +508,7 @@ export class ${name.pascal}Repository extends RepositoryManager<${name.pascal}>
558
508
  });
559
509
  }
560
510
 
561
- export const ${name.camel}Repository = new ${name.pascal}Repository();
511
+ export const ${name.plural.camel}Repository = new ${name.plural.pascal}Repository();
562
512
  `;
563
513
  }
564
514
  /**
@@ -567,7 +517,7 @@ export const ${name.camel}Repository = new ${name.pascal}Repository();
567
517
  function resourceStub(name) {
568
518
  return `import { Resource } from "@warlock.js/core";
569
519
 
570
- export class ${name.pascal}Resource extends Resource {
520
+ export class ${name.singular.pascal}Resource extends Resource {
571
521
  public schema = {
572
522
  id: "int",
573
523
  name: "string",
@@ -575,7 +525,4 @@ export class ${name.pascal}Resource extends Resource {
575
525
  };
576
526
  }
577
527
  `;
578
- }
579
- /**
580
- * Migration template stub
581
- */export{controllerStub,crudCreateControllerStub,crudCreateServiceStub,crudCreateValidationStub,crudDeleteControllerStub,crudDeleteServiceStub,crudGetServiceStub,crudListControllerStub,crudListServiceStub,crudModelStub,crudRepositoryStub,crudResourceStub,crudRoutesStub,crudSeedStub,crudShowControllerStub,crudUpdateControllerStub,crudUpdateServiceStub,crudUpdateValidationStub,migrationStub,modelStub,repositoryStub,requestStub,resourceStub,serviceStub,validationStub};//# sourceMappingURL=stubs.js.map
528
+ }export{controllerStub,crudCreateControllerStub,crudCreateServiceStub,crudCreateValidationStub,crudDeleteControllerStub,crudDeleteServiceStub,crudGetServiceStub,crudListControllerStub,crudListServiceStub,crudModelStub,crudRepositoryStub,crudResourceStub,crudRoutesStub,crudSeedStub,crudShowControllerStub,crudUpdateControllerStub,crudUpdateServiceStub,crudUpdateValidationStub,migrationAlterStub,migrationStub,modelStub,repositoryStub,requestStub,resourceStub,serviceStub,validationStub};//# sourceMappingURL=stubs.js.map