@forinda/kickjs-cli 1.2.13 → 1.3.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/README.md +51 -9
- package/dist/cli.js +1095 -484
- package/dist/index.d.ts +70 -5
- package/dist/index.js +980 -377
- package/package.json +15 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Ue=Object.defineProperty;var s=(r,e)=>Ue(r,"name",{value:e,configurable:!0});import{join as ce}from"path";import{createInterface as Le}from"readline";import{writeFile as Me,mkdir as qe,access as ze,readFile as Rt}from"fs/promises";import{dirname as _e}from"path";var Fe=!1;async function l(r,e){Fe||(await qe(_e(r),{recursive:!0}),await Me(r,e,"utf-8"))}s(l,"writeFileSafe");async function F(r){try{return await ze(r),!0}catch{return!1}}s(F,"fileExists");function f(r){return r.replace(/[-_\s]+(.)?/g,(e,t)=>t?t.toUpperCase():"").replace(/^(.)/,e=>e.toUpperCase())}s(f,"toPascalCase");function w(r){let e=f(r);return e.charAt(0).toLowerCase()+e.slice(1)}s(w,"toCamelCase");function u(r){return r.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}s(u,"toKebabCase");function E(r){return r.endsWith("s")?r:r.endsWith("x")||r.endsWith("z")||r.endsWith("sh")||r.endsWith("ch")?r+"es":r.endsWith("y")&&!/[aeiou]y$/.test(r)?r.slice(0,-1)+"ies":r+"s"}s(E,"pluralize");function le(r){return r.endsWith("s")?r:r.endsWith("x")||r.endsWith("z")||r.endsWith("sh")||r.endsWith("ch")?r+"es":r.endsWith("y")&&!/[aeiou]y$/i.test(r)?r.slice(0,-1)+"ies":r+"s"}s(le,"pluralizePascal");import{readFile as Ne,writeFile as We}from"fs/promises";var Ge={inmemory:"in-memory",drizzle:"Drizzle",prisma:"Prisma"};function ue(r){return r.charAt(0).toUpperCase()+r.slice(1).replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}s(ue,"toPascalRepoType");function Qe(r){return r.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}s(Qe,"toKebabRepoType");function me(r){return Ge[r]??ue(r)}s(me,"repoLabel");function fe(r,e,t){let o={inmemory:`InMemory${r}Repository`,drizzle:`Drizzle${r}Repository`,prisma:`Prisma${r}Repository`},i={inmemory:`in-memory-${e}`,drizzle:`drizzle-${e}`,prisma:`prisma-${e}`};return{repoClass:o[t]??`${ue(t)}${r}Repository`,repoFile:i[t]??`${Qe(t)}-${e}`}}s(fe,"repoMaps");function G(r){let{pascal:e,kebab:t,plural:o="",repo:i}=r,{repoClass:a,repoFile:c}=fe(e,t,i);return`/**
|
|
2
2
|
* ${e} Module
|
|
3
3
|
*
|
|
4
4
|
* Self-contained feature module following Domain-Driven Design (DDD).
|
|
@@ -8,12 +8,12 @@ var me=Object.defineProperty;var i=(e,t)=>me(e,"name",{value:t,configurable:!0})
|
|
|
8
8
|
* presentation/ \u2014 HTTP controllers (entry points)
|
|
9
9
|
* application/ \u2014 Use cases (orchestration) and DTOs (validation)
|
|
10
10
|
* domain/ \u2014 Entities, value objects, repository interfaces, domain services
|
|
11
|
-
* infrastructure/ \u2014 Repository implementations (
|
|
11
|
+
* infrastructure/ \u2014 Repository implementations (currently ${me(i)})
|
|
12
12
|
*/
|
|
13
13
|
import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
|
|
14
14
|
import { buildRoutes } from '@forinda/kickjs-http'
|
|
15
15
|
import { ${e.toUpperCase()}_REPOSITORY } from './domain/repositories/${t}.repository'
|
|
16
|
-
import { ${
|
|
16
|
+
import { ${a} } from './infrastructure/repositories/${c}.repository'
|
|
17
17
|
import { ${e}Controller } from './presentation/${t}.controller'
|
|
18
18
|
|
|
19
19
|
// Eagerly load decorated classes so @Service()/@Repository() decorators register in the DI container
|
|
@@ -26,28 +26,28 @@ export class ${e}Module implements AppModule {
|
|
|
26
26
|
/**
|
|
27
27
|
* Register module dependencies in the DI container.
|
|
28
28
|
* Bind repository interface tokens to their implementations here.
|
|
29
|
-
*
|
|
29
|
+
* Currently wired to ${me(i)}. To swap implementations, change the factory target.
|
|
30
30
|
*/
|
|
31
31
|
register(container: Container): void {
|
|
32
32
|
container.registerFactory(${e.toUpperCase()}_REPOSITORY, () =>
|
|
33
|
-
container.resolve(${
|
|
33
|
+
container.resolve(${a}),
|
|
34
34
|
)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Declare HTTP routes for this module.
|
|
39
|
-
* The path is prefixed with the global apiPrefix and version (e.g. /api/v1/${
|
|
39
|
+
* The path is prefixed with the global apiPrefix and version (e.g. /api/v1/${o}).
|
|
40
40
|
* Passing 'controller' enables automatic OpenAPI spec generation via SwaggerAdapter.
|
|
41
41
|
*/
|
|
42
42
|
routes(): ModuleRoutes {
|
|
43
43
|
return {
|
|
44
|
-
path: '/${
|
|
44
|
+
path: '/${o}',
|
|
45
45
|
router: buildRoutes(${e}Controller),
|
|
46
46
|
controller: ${e}Controller,
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
`}
|
|
50
|
+
`}s(G,"generateModuleIndex");function Q(r){let{pascal:e,kebab:t,plural:o="",repo:i}=r,{repoClass:a,repoFile:c}=fe(e,t,i);return`/**
|
|
51
51
|
* ${e} Module
|
|
52
52
|
*
|
|
53
53
|
* REST module with a flat folder structure.
|
|
@@ -57,13 +57,13 @@ export class ${e}Module implements AppModule {
|
|
|
57
57
|
* ${t}.controller.ts \u2014 HTTP routes (CRUD)
|
|
58
58
|
* ${t}.service.ts \u2014 Business logic
|
|
59
59
|
* ${t}.repository.ts \u2014 Repository interface
|
|
60
|
-
* ${
|
|
60
|
+
* ${c}.repository.ts \u2014 Repository implementation
|
|
61
61
|
* dtos/ \u2014 Request/response schemas
|
|
62
62
|
*/
|
|
63
63
|
import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
|
|
64
64
|
import { buildRoutes } from '@forinda/kickjs-http'
|
|
65
65
|
import { ${e.toUpperCase()}_REPOSITORY } from './${t}.repository'
|
|
66
|
-
import { ${
|
|
66
|
+
import { ${a} } from './${c}.repository'
|
|
67
67
|
import { ${e}Controller } from './${t}.controller'
|
|
68
68
|
|
|
69
69
|
// Eagerly load decorated classes so @Service()/@Repository() decorators register in the DI container
|
|
@@ -72,37 +72,37 @@ import.meta.glob(['./**/*.service.ts', './**/*.repository.ts', '!./**/*.test.ts'
|
|
|
72
72
|
export class ${e}Module implements AppModule {
|
|
73
73
|
register(container: Container): void {
|
|
74
74
|
container.registerFactory(${e.toUpperCase()}_REPOSITORY, () =>
|
|
75
|
-
container.resolve(${
|
|
75
|
+
container.resolve(${a}),
|
|
76
76
|
)
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
routes(): ModuleRoutes {
|
|
80
80
|
return {
|
|
81
|
-
path: '/${
|
|
81
|
+
path: '/${o}',
|
|
82
82
|
router: buildRoutes(${e}Controller),
|
|
83
83
|
controller: ${e}Controller,
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
`}
|
|
87
|
+
`}s(Q,"generateRestModuleIndex");function L(r){let{pascal:e,kebab:t,plural:o=""}=r;return`import { type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
|
|
88
88
|
import { buildRoutes } from '@forinda/kickjs-http'
|
|
89
89
|
import { ${e}Controller } from './${t}.controller'
|
|
90
90
|
|
|
91
91
|
export class ${e}Module implements AppModule {
|
|
92
92
|
routes(): ModuleRoutes {
|
|
93
93
|
return {
|
|
94
|
-
path: '/${
|
|
94
|
+
path: '/${o}',
|
|
95
95
|
router: buildRoutes(${e}Controller),
|
|
96
96
|
controller: ${e}Controller,
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
`}
|
|
100
|
+
`}s(L,"generateMinimalModuleIndex");function N(r){let{pascal:e,kebab:t,plural:o="",pluralPascal:i=""}=r;return`import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams } from '@forinda/kickjs-core'
|
|
101
101
|
import type { RequestContext } from '@forinda/kickjs-http'
|
|
102
102
|
import { ApiTags } from '@forinda/kickjs-swagger'
|
|
103
103
|
import { Create${e}UseCase } from '../application/use-cases/create-${t}.use-case'
|
|
104
104
|
import { Get${e}UseCase } from '../application/use-cases/get-${t}.use-case'
|
|
105
|
-
import { List${
|
|
105
|
+
import { List${i}UseCase } from '../application/use-cases/list-${o}.use-case'
|
|
106
106
|
import { Update${e}UseCase } from '../application/use-cases/update-${t}.use-case'
|
|
107
107
|
import { Delete${e}UseCase } from '../application/use-cases/delete-${t}.use-case'
|
|
108
108
|
import { create${e}Schema } from '../application/dtos/create-${t}.dto'
|
|
@@ -113,7 +113,7 @@ import { ${e.toUpperCase()}_QUERY_CONFIG } from '../constants'
|
|
|
113
113
|
export class ${e}Controller {
|
|
114
114
|
@Autowired() private create${e}UseCase!: Create${e}UseCase
|
|
115
115
|
@Autowired() private get${e}UseCase!: Get${e}UseCase
|
|
116
|
-
@Autowired() private list${
|
|
116
|
+
@Autowired() private list${i}UseCase!: List${i}UseCase
|
|
117
117
|
@Autowired() private update${e}UseCase!: Update${e}UseCase
|
|
118
118
|
@Autowired() private delete${e}UseCase!: Delete${e}UseCase
|
|
119
119
|
|
|
@@ -122,7 +122,7 @@ export class ${e}Controller {
|
|
|
122
122
|
@ApiQueryParams(${e.toUpperCase()}_QUERY_CONFIG)
|
|
123
123
|
async list(ctx: RequestContext) {
|
|
124
124
|
return ctx.paginate(
|
|
125
|
-
(parsed) => this.list${
|
|
125
|
+
(parsed) => this.list${i}UseCase.execute(parsed),
|
|
126
126
|
${e.toUpperCase()}_QUERY_CONFIG,
|
|
127
127
|
)
|
|
128
128
|
}
|
|
@@ -156,7 +156,7 @@ export class ${e}Controller {
|
|
|
156
156
|
ctx.noContent()
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
`}
|
|
159
|
+
`}s(N,"generateController");function W(r){let{pascal:e,kebab:t,plural:o="",pluralPascal:i=""}=r,a=e.charAt(0).toLowerCase()+e.slice(1);return`import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams } from '@forinda/kickjs-core'
|
|
160
160
|
import type { RequestContext } from '@forinda/kickjs-http'
|
|
161
161
|
import { ApiTags } from '@forinda/kickjs-swagger'
|
|
162
162
|
import { ${e}Service } from './${t}.service'
|
|
@@ -166,14 +166,14 @@ import { ${e.toUpperCase()}_QUERY_CONFIG } from './${t}.constants'
|
|
|
166
166
|
|
|
167
167
|
@Controller()
|
|
168
168
|
export class ${e}Controller {
|
|
169
|
-
@Autowired() private ${
|
|
169
|
+
@Autowired() private ${a}Service!: ${e}Service
|
|
170
170
|
|
|
171
171
|
@Get('/')
|
|
172
172
|
@ApiTags('${e}')
|
|
173
173
|
@ApiQueryParams(${e.toUpperCase()}_QUERY_CONFIG)
|
|
174
174
|
async list(ctx: RequestContext) {
|
|
175
175
|
return ctx.paginate(
|
|
176
|
-
(parsed) => this.${
|
|
176
|
+
(parsed) => this.${a}Service.findPaginated(parsed),
|
|
177
177
|
${e.toUpperCase()}_QUERY_CONFIG,
|
|
178
178
|
)
|
|
179
179
|
}
|
|
@@ -181,7 +181,7 @@ export class ${e}Controller {
|
|
|
181
181
|
@Get('/:id')
|
|
182
182
|
@ApiTags('${e}')
|
|
183
183
|
async getById(ctx: RequestContext) {
|
|
184
|
-
const result = await this.${
|
|
184
|
+
const result = await this.${a}Service.findById(ctx.params.id)
|
|
185
185
|
if (!result) return ctx.notFound('${e} not found')
|
|
186
186
|
ctx.json(result)
|
|
187
187
|
}
|
|
@@ -189,50 +189,32 @@ export class ${e}Controller {
|
|
|
189
189
|
@Post('/', { body: create${e}Schema, name: 'Create${e}' })
|
|
190
190
|
@ApiTags('${e}')
|
|
191
191
|
async create(ctx: RequestContext) {
|
|
192
|
-
const result = await this.${
|
|
192
|
+
const result = await this.${a}Service.create(ctx.body)
|
|
193
193
|
ctx.created(result)
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
@Put('/:id', { body: update${e}Schema, name: 'Update${e}' })
|
|
197
197
|
@ApiTags('${e}')
|
|
198
198
|
async update(ctx: RequestContext) {
|
|
199
|
-
const result = await this.${
|
|
199
|
+
const result = await this.${a}Service.update(ctx.params.id, ctx.body)
|
|
200
200
|
ctx.json(result)
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
@Delete('/:id')
|
|
204
204
|
@ApiTags('${e}')
|
|
205
205
|
async remove(ctx: RequestContext) {
|
|
206
|
-
await this.${
|
|
206
|
+
await this.${a}Service.delete(ctx.params.id)
|
|
207
207
|
ctx.noContent()
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
`}
|
|
210
|
+
`}s(W,"generateRestController");function B(r){let{pascal:e}=r;return`import type { QueryParamsConfig } from '@forinda/kickjs-core'
|
|
211
211
|
|
|
212
212
|
export const ${e.toUpperCase()}_QUERY_CONFIG: QueryParamsConfig = {
|
|
213
213
|
filterable: ['name'],
|
|
214
214
|
sortable: ['name', 'createdAt'],
|
|
215
215
|
searchable: ['name'],
|
|
216
216
|
}
|
|
217
|
-
`}
|
|
218
|
-
// TODO: Import your schema table and reference actual columns for type safety
|
|
219
|
-
// import { ${t}s } from '@/db/schema'
|
|
220
|
-
|
|
221
|
-
export const ${e.toUpperCase()}_QUERY_CONFIG: DrizzleQueryParamsConfig = {
|
|
222
|
-
columns: {
|
|
223
|
-
// Replace with actual Drizzle Column references for type-safe filtering:
|
|
224
|
-
// name: ${t}s.name,
|
|
225
|
-
// status: ${t}s.status,
|
|
226
|
-
},
|
|
227
|
-
sortable: {
|
|
228
|
-
// name: ${t}s.name,
|
|
229
|
-
// createdAt: ${t}s.createdAt,
|
|
230
|
-
},
|
|
231
|
-
searchColumns: [
|
|
232
|
-
// ${t}s.name,
|
|
233
|
-
],
|
|
234
|
-
}
|
|
235
|
-
`}i(W,"generateDrizzleConstants");function R(e,t){return`import { z } from 'zod'
|
|
217
|
+
`}s(B,"generateConstants");function C(r){let{pascal:e,kebab:t}=r;return`import { z } from 'zod'
|
|
236
218
|
|
|
237
219
|
/**
|
|
238
220
|
* Create ${e} DTO \u2014 Zod schema for validating POST request bodies.
|
|
@@ -248,20 +230,20 @@ export const create${e}Schema = z.object({
|
|
|
248
230
|
})
|
|
249
231
|
|
|
250
232
|
export type Create${e}DTO = z.infer<typeof create${e}Schema>
|
|
251
|
-
`}
|
|
233
|
+
`}s(C,"generateCreateDTO");function R(r){let{pascal:e,kebab:t}=r;return`import { z } from 'zod'
|
|
252
234
|
|
|
253
235
|
export const update${e}Schema = z.object({
|
|
254
236
|
name: z.string().min(1).max(200).optional(),
|
|
255
237
|
})
|
|
256
238
|
|
|
257
239
|
export type Update${e}DTO = z.infer<typeof update${e}Schema>
|
|
258
|
-
`}
|
|
240
|
+
`}s(R,"generateUpdateDTO");function b(r){let{pascal:e,kebab:t}=r;return`export interface ${e}ResponseDTO {
|
|
259
241
|
id: string
|
|
260
242
|
name: string
|
|
261
243
|
createdAt: string
|
|
262
244
|
updatedAt: string
|
|
263
245
|
}
|
|
264
|
-
`}
|
|
246
|
+
`}s(b,"generateResponseDTO");function K(r){let{pascal:e,kebab:t,plural:o="",pluralPascal:i=""}=r;return[{file:`create-${t}.use-case.ts`,content:`/**
|
|
265
247
|
* Create ${e} Use Case
|
|
266
248
|
*
|
|
267
249
|
* Application layer \u2014 orchestrates a single business operation.
|
|
@@ -297,12 +279,12 @@ export class Get${e}UseCase {
|
|
|
297
279
|
return this.repo.findById(id)
|
|
298
280
|
}
|
|
299
281
|
}
|
|
300
|
-
`},{file:`list-${
|
|
282
|
+
`},{file:`list-${o}.use-case.ts`,content:`import { Service, Inject } from '@forinda/kickjs-core'
|
|
301
283
|
import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../../domain/repositories/${t}.repository'
|
|
302
284
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
303
285
|
|
|
304
286
|
@Service()
|
|
305
|
-
export class List${
|
|
287
|
+
export class List${i}UseCase {
|
|
306
288
|
constructor(
|
|
307
289
|
@Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
|
|
308
290
|
) {}
|
|
@@ -339,7 +321,7 @@ export class Delete${e}UseCase {
|
|
|
339
321
|
await this.repo.delete(id)
|
|
340
322
|
}
|
|
341
323
|
}
|
|
342
|
-
`}]}
|
|
324
|
+
`}]}s(K,"generateUseCases");function D(r){let{pascal:e,kebab:t,dtoPrefix:o="../../application/dtos"}=r;return`/**
|
|
343
325
|
* ${e} Repository Interface
|
|
344
326
|
*
|
|
345
327
|
* Defines the contract for data access.
|
|
@@ -348,9 +330,9 @@ export class Delete${e}UseCase {
|
|
|
348
330
|
*
|
|
349
331
|
* To swap implementations, change the factory in the module's register() method.
|
|
350
332
|
*/
|
|
351
|
-
import type { ${e}ResponseDTO } from '${
|
|
352
|
-
import type { Create${e}DTO } from '${
|
|
353
|
-
import type { Update${e}DTO } from '${
|
|
333
|
+
import type { ${e}ResponseDTO } from '${o}/${t}-response.dto'
|
|
334
|
+
import type { Create${e}DTO } from '${o}/create-${t}.dto'
|
|
335
|
+
import type { Update${e}DTO } from '${o}/update-${t}.dto'
|
|
354
336
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
355
337
|
|
|
356
338
|
export interface I${e}Repository {
|
|
@@ -363,7 +345,7 @@ export interface I${e}Repository {
|
|
|
363
345
|
}
|
|
364
346
|
|
|
365
347
|
export const ${e.toUpperCase()}_REPOSITORY = Symbol('I${e}Repository')
|
|
366
|
-
`}
|
|
348
|
+
`}s(D,"generateRepositoryInterface");function T(r){let{pascal:e,kebab:t,repoPrefix:o="../../domain/repositories",dtoPrefix:i="../../application/dtos"}=r;return`/**
|
|
367
349
|
* In-Memory ${e} Repository
|
|
368
350
|
*
|
|
369
351
|
* Implements the repository interface using a Map.
|
|
@@ -375,10 +357,10 @@ export const ${e.toUpperCase()}_REPOSITORY = Symbol('I${e}Repository')
|
|
|
375
357
|
import { randomUUID } from 'node:crypto'
|
|
376
358
|
import { Repository, HttpException } from '@forinda/kickjs-core'
|
|
377
359
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
378
|
-
import type { I${e}Repository } from '${
|
|
379
|
-
import type { ${e}ResponseDTO } from '${
|
|
380
|
-
import type { Create${e}DTO } from '${
|
|
381
|
-
import type { Update${e}DTO } from '${
|
|
360
|
+
import type { I${e}Repository } from '${o}/${t}.repository'
|
|
361
|
+
import type { ${e}ResponseDTO } from '${i}/${t}-response.dto'
|
|
362
|
+
import type { Create${e}DTO } from '${i}/create-${t}.dto'
|
|
363
|
+
import type { Update${e}DTO } from '${i}/update-${t}.dto'
|
|
382
364
|
|
|
383
365
|
@Repository()
|
|
384
366
|
export class InMemory${e}Repository implements I${e}Repository {
|
|
@@ -423,161 +405,76 @@ export class InMemory${e}Repository implements I${e}Repository {
|
|
|
423
405
|
this.store.delete(id)
|
|
424
406
|
}
|
|
425
407
|
}
|
|
426
|
-
`}
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* Implements the repository interface using Drizzle ORM.
|
|
430
|
-
* Uses buildFromColumns() with Column objects for type-safe query building.
|
|
431
|
-
*
|
|
432
|
-
* TODO: Update the schema import to match your Drizzle schema file.
|
|
433
|
-
* TODO: Replace DRIZZLE_DB injection token with your actual database token.
|
|
434
|
-
*
|
|
435
|
-
* @Repository() registers this class in the DI container as a singleton.
|
|
436
|
-
*/
|
|
437
|
-
import { eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc, count, sql } from 'drizzle-orm'
|
|
438
|
-
import { Repository, HttpException, Inject } from '@forinda/kickjs-core'
|
|
439
|
-
import { DRIZZLE_DB, DrizzleQueryAdapter } from '@forinda/kickjs-drizzle'
|
|
440
|
-
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
441
|
-
import type { I${e}Repository } from '${r}/${t}.repository'
|
|
442
|
-
import type { ${e}ResponseDTO } from '${o}/${t}-response.dto'
|
|
443
|
-
import type { Create${e}DTO } from '${o}/create-${t}.dto'
|
|
444
|
-
import type { Update${e}DTO } from '${o}/update-${t}.dto'
|
|
445
|
-
import { ${e.toUpperCase()}_QUERY_CONFIG } from '../../constants'
|
|
446
|
-
|
|
447
|
-
// TODO: Import your Drizzle schema table \u2014 e.g.:
|
|
448
|
-
// import { ${t}s } from '@/db/schema'
|
|
449
|
-
|
|
450
|
-
const queryAdapter = new DrizzleQueryAdapter({
|
|
451
|
-
eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc,
|
|
452
|
-
})
|
|
453
|
-
|
|
454
|
-
@Repository()
|
|
455
|
-
export class Drizzle${e}Repository implements I${e}Repository {
|
|
456
|
-
constructor(@Inject(DRIZZLE_DB) private db: any) {}
|
|
457
|
-
|
|
458
|
-
async findById(id: string): Promise<${e}ResponseDTO | null> {
|
|
459
|
-
// TODO: Implement with Drizzle
|
|
460
|
-
// const row = this.db.select().from(${t}s).where(eq(${t}s.id, id)).get()
|
|
461
|
-
// return row ?? null
|
|
462
|
-
throw new Error('Drizzle ${e} repository not yet implemented \u2014 update schema imports and queries')
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
async findAll(): Promise<${e}ResponseDTO[]> {
|
|
466
|
-
// TODO: Implement with Drizzle
|
|
467
|
-
// return this.db.select().from(${t}s).all()
|
|
468
|
-
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
|
|
472
|
-
// TODO: Use buildFromColumns() with your query config for type-safe filtering
|
|
473
|
-
// const query = queryAdapter.buildFromColumns(parsed, ${e.toUpperCase()}_QUERY_CONFIG)
|
|
474
|
-
//
|
|
475
|
-
// const data = this.db
|
|
476
|
-
// .select().from(${t}s).$dynamic()
|
|
477
|
-
// .where(query.where).orderBy(...query.orderBy)
|
|
478
|
-
// .limit(query.limit).offset(query.offset).all()
|
|
479
|
-
//
|
|
480
|
-
// const totalResult = this.db
|
|
481
|
-
// .select({ count: count() }).from(${t}s)
|
|
482
|
-
// .$dynamic().where(query.where).get()
|
|
483
|
-
//
|
|
484
|
-
// return { data, total: totalResult?.count ?? 0 }
|
|
485
|
-
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
|
|
489
|
-
// TODO: Implement with Drizzle
|
|
490
|
-
// return this.db.insert(${t}s).values(dto).returning().get()
|
|
491
|
-
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
|
|
495
|
-
// TODO: Implement with Drizzle
|
|
496
|
-
// const row = this.db.update(${t}s).set(dto).where(eq(${t}s.id, id)).returning().get()
|
|
497
|
-
// if (!row) throw HttpException.notFound('${e} not found')
|
|
498
|
-
// return row
|
|
499
|
-
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
async delete(id: string): Promise<void> {
|
|
503
|
-
// TODO: Implement with Drizzle
|
|
504
|
-
// this.db.delete(${t}s).where(eq(${t}s.id, id)).run()
|
|
505
|
-
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
`}i(T,"generateDrizzleRepository");function P(e,t,r="../../domain/repositories",o="../../application/dtos"){let n=t.replace(/-([a-z])/g,(s,p)=>p.toUpperCase());return`/**
|
|
509
|
-
* Prisma ${e} Repository
|
|
408
|
+
`}s(T,"generateInMemoryRepository");function P(r){let{pascal:e,kebab:t,repoType:o="",repoPrefix:i="../../domain/repositories",dtoPrefix:a="../../application/dtos"}=r,c=o.charAt(0).toUpperCase()+o.slice(1).replace(/-([a-z])/g,(n,p)=>p.toUpperCase());return`/**
|
|
409
|
+
* ${c} ${e} Repository
|
|
510
410
|
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
411
|
+
* Stub implementation for a custom '${o}' repository.
|
|
412
|
+
* Implements the repository interface using an in-memory Map as a placeholder.
|
|
513
413
|
*
|
|
514
|
-
* TODO:
|
|
515
|
-
*
|
|
414
|
+
* TODO: Replace the in-memory Map with your ${o} data-access logic.
|
|
415
|
+
* See I${e}Repository for the interface contract.
|
|
516
416
|
*
|
|
517
417
|
* @Repository() registers this class in the DI container as a singleton.
|
|
518
418
|
*/
|
|
519
|
-
import {
|
|
419
|
+
import { randomUUID } from 'node:crypto'
|
|
420
|
+
import { Repository, HttpException } from '@forinda/kickjs-core'
|
|
520
421
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
521
|
-
import type { I${e}Repository } from '${
|
|
522
|
-
import type { ${e}ResponseDTO } from '${
|
|
523
|
-
import type { Create${e}DTO } from '${
|
|
524
|
-
import type { Update${e}DTO } from '${
|
|
525
|
-
|
|
526
|
-
// TODO: Import your Prisma injection token \u2014 e.g.:
|
|
527
|
-
// import { PRISMA_CLIENT } from '@/db/prisma.provider'
|
|
528
|
-
// import type { PrismaClient } from '@prisma/client'
|
|
422
|
+
import type { I${e}Repository } from '${i}/${t}.repository'
|
|
423
|
+
import type { ${e}ResponseDTO } from '${a}/${t}-response.dto'
|
|
424
|
+
import type { Create${e}DTO } from '${a}/create-${t}.dto'
|
|
425
|
+
import type { Update${e}DTO } from '${a}/update-${t}.dto'
|
|
529
426
|
|
|
530
427
|
@Repository()
|
|
531
|
-
export class
|
|
532
|
-
// TODO:
|
|
533
|
-
|
|
428
|
+
export class ${c}${e}Repository implements I${e}Repository {
|
|
429
|
+
// TODO: Replace with your ${o} client/connection
|
|
430
|
+
private store = new Map<string, ${e}ResponseDTO>()
|
|
534
431
|
|
|
535
432
|
async findById(id: string): Promise<${e}ResponseDTO | null> {
|
|
536
|
-
// TODO: Implement with
|
|
537
|
-
|
|
538
|
-
throw new Error('Prisma ${e} repository not yet implemented \u2014 update Prisma imports and queries')
|
|
433
|
+
// TODO: Implement with ${o}
|
|
434
|
+
return this.store.get(id) ?? null
|
|
539
435
|
}
|
|
540
436
|
|
|
541
437
|
async findAll(): Promise<${e}ResponseDTO[]> {
|
|
542
|
-
// TODO: Implement with
|
|
543
|
-
|
|
544
|
-
throw new Error('Prisma ${e} repository not yet implemented')
|
|
438
|
+
// TODO: Implement with ${o}
|
|
439
|
+
return Array.from(this.store.values())
|
|
545
440
|
}
|
|
546
441
|
|
|
547
442
|
async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
|
|
548
|
-
// TODO: Implement with
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
// take: parsed.pagination.limit,
|
|
553
|
-
// }),
|
|
554
|
-
// this.prisma.${n}.count(),
|
|
555
|
-
// ])
|
|
556
|
-
// return { data, total }
|
|
557
|
-
throw new Error('Prisma ${e} repository not yet implemented')
|
|
443
|
+
// TODO: Implement with ${o}
|
|
444
|
+
const all = Array.from(this.store.values())
|
|
445
|
+
const data = all.slice(parsed.pagination.offset, parsed.pagination.offset + parsed.pagination.limit)
|
|
446
|
+
return { data, total: all.length }
|
|
558
447
|
}
|
|
559
448
|
|
|
560
449
|
async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
|
|
561
|
-
// TODO: Implement with
|
|
562
|
-
|
|
563
|
-
|
|
450
|
+
// TODO: Implement with ${o}
|
|
451
|
+
const now = new Date().toISOString()
|
|
452
|
+
const entity: ${e}ResponseDTO = {
|
|
453
|
+
id: randomUUID(),
|
|
454
|
+
name: dto.name,
|
|
455
|
+
createdAt: now,
|
|
456
|
+
updatedAt: now,
|
|
457
|
+
}
|
|
458
|
+
this.store.set(entity.id, entity)
|
|
459
|
+
return entity
|
|
564
460
|
}
|
|
565
461
|
|
|
566
462
|
async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
|
|
567
|
-
// TODO: Implement with
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
463
|
+
// TODO: Implement with ${o}
|
|
464
|
+
const existing = this.store.get(id)
|
|
465
|
+
if (!existing) throw HttpException.notFound('${e} not found')
|
|
466
|
+
const updated = { ...existing, ...dto, updatedAt: new Date().toISOString() }
|
|
467
|
+
this.store.set(id, updated)
|
|
468
|
+
return updated
|
|
572
469
|
}
|
|
573
470
|
|
|
574
471
|
async delete(id: string): Promise<void> {
|
|
575
|
-
// TODO: Implement with
|
|
576
|
-
|
|
577
|
-
|
|
472
|
+
// TODO: Implement with ${o}
|
|
473
|
+
if (!this.store.has(id)) throw HttpException.notFound('${e} not found')
|
|
474
|
+
this.store.delete(id)
|
|
578
475
|
}
|
|
579
476
|
}
|
|
580
|
-
`}
|
|
477
|
+
`}s(P,"generateCustomRepository");function Y(r){let{pascal:e,kebab:t}=r;return`/**
|
|
581
478
|
* ${e} Domain Service
|
|
582
479
|
*
|
|
583
480
|
* Domain layer \u2014 contains business rules that don't belong to a single entity.
|
|
@@ -600,7 +497,7 @@ export class ${e}DomainService {
|
|
|
600
497
|
}
|
|
601
498
|
}
|
|
602
499
|
}
|
|
603
|
-
`}
|
|
500
|
+
`}s(Y,"generateDomainService");function H(r){let{pascal:e,kebab:t}=r;return`/**
|
|
604
501
|
* ${e} Entity
|
|
605
502
|
*
|
|
606
503
|
* Domain layer \u2014 the core business object.
|
|
@@ -669,7 +566,7 @@ export class ${e} {
|
|
|
669
566
|
}
|
|
670
567
|
}
|
|
671
568
|
}
|
|
672
|
-
`}
|
|
569
|
+
`}s(H,"generateEntity");function J(r){let{pascal:e,kebab:t}=r;return`/**
|
|
673
570
|
* ${e} ID Value Object
|
|
674
571
|
*
|
|
675
572
|
* Domain layer \u2014 wraps a primitive ID with type safety and validation.
|
|
@@ -703,7 +600,7 @@ export class ${e}Id {
|
|
|
703
600
|
return this.value === other.value
|
|
704
601
|
}
|
|
705
602
|
}
|
|
706
|
-
`}
|
|
603
|
+
`}s(J,"generateValueObject");function O(r){let{pascal:e,kebab:t,plural:o=""}=r;return`import { describe, it, expect, beforeEach } from 'vitest'
|
|
707
604
|
import { Container } from '@forinda/kickjs-core'
|
|
708
605
|
|
|
709
606
|
describe('${e}Controller', () => {
|
|
@@ -715,21 +612,21 @@ describe('${e}Controller', () => {
|
|
|
715
612
|
expect(true).toBe(true)
|
|
716
613
|
})
|
|
717
614
|
|
|
718
|
-
describe('POST /${
|
|
615
|
+
describe('POST /${o}', () => {
|
|
719
616
|
it('should create a new ${t}', async () => {
|
|
720
617
|
// TODO: Set up test module, call create endpoint, assert 201
|
|
721
618
|
expect(true).toBe(true)
|
|
722
619
|
})
|
|
723
620
|
})
|
|
724
621
|
|
|
725
|
-
describe('GET /${
|
|
726
|
-
it('should return paginated ${
|
|
622
|
+
describe('GET /${o}', () => {
|
|
623
|
+
it('should return paginated ${o}', async () => {
|
|
727
624
|
// TODO: Set up test module, call list endpoint, assert { data, meta }
|
|
728
625
|
expect(true).toBe(true)
|
|
729
626
|
})
|
|
730
627
|
})
|
|
731
628
|
|
|
732
|
-
describe('GET /${
|
|
629
|
+
describe('GET /${o}/:id', () => {
|
|
733
630
|
it('should return a ${t} by id', async () => {
|
|
734
631
|
// TODO: Create a ${t}, then fetch by id, assert match
|
|
735
632
|
expect(true).toBe(true)
|
|
@@ -741,22 +638,22 @@ describe('${e}Controller', () => {
|
|
|
741
638
|
})
|
|
742
639
|
})
|
|
743
640
|
|
|
744
|
-
describe('PUT /${
|
|
641
|
+
describe('PUT /${o}/:id', () => {
|
|
745
642
|
it('should update an existing ${t}', async () => {
|
|
746
643
|
// TODO: Create, update, assert changes
|
|
747
644
|
expect(true).toBe(true)
|
|
748
645
|
})
|
|
749
646
|
})
|
|
750
647
|
|
|
751
|
-
describe('DELETE /${
|
|
648
|
+
describe('DELETE /${o}/:id', () => {
|
|
752
649
|
it('should delete a ${t}', async () => {
|
|
753
650
|
// TODO: Create, delete, assert gone
|
|
754
651
|
expect(true).toBe(true)
|
|
755
652
|
})
|
|
756
653
|
})
|
|
757
654
|
})
|
|
758
|
-
`}
|
|
759
|
-
import { InMemory${e}Repository } from '${
|
|
655
|
+
`}s(O,"generateControllerTest");function I(r){let{pascal:e,kebab:t,plural:o="",repoPrefix:i=`../infrastructure/repositories/in-memory-${t}.repository`}=r;return`import { describe, it, expect, beforeEach } from 'vitest'
|
|
656
|
+
import { InMemory${e}Repository } from '${i}'
|
|
760
657
|
|
|
761
658
|
describe('InMemory${e}Repository', () => {
|
|
762
659
|
let repo: InMemory${e}Repository
|
|
@@ -780,7 +677,7 @@ describe('InMemory${e}Repository', () => {
|
|
|
780
677
|
expect(found).toBeNull()
|
|
781
678
|
})
|
|
782
679
|
|
|
783
|
-
it('should list all ${
|
|
680
|
+
it('should list all ${o}', async () => {
|
|
784
681
|
await repo.create({ name: '${e} 1' })
|
|
785
682
|
await repo.create({ name: '${e} 2' })
|
|
786
683
|
|
|
@@ -817,7 +714,7 @@ describe('InMemory${e}Repository', () => {
|
|
|
817
714
|
expect(found).toBeNull()
|
|
818
715
|
})
|
|
819
716
|
})
|
|
820
|
-
`}
|
|
717
|
+
`}s(I,"generateRepositoryTest");function V(r){let{pascal:e,kebab:t}=r;return`import { Service, Inject, HttpException } from '@forinda/kickjs-core'
|
|
821
718
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
822
719
|
import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from './${t}.repository'
|
|
823
720
|
import type { ${e}ResponseDTO } from './dtos/${t}-response.dto'
|
|
@@ -854,14 +751,14 @@ export class ${e}Service {
|
|
|
854
751
|
await this.repo.delete(id)
|
|
855
752
|
}
|
|
856
753
|
}
|
|
857
|
-
`}
|
|
754
|
+
`}s(V,"generateRestService");function U(r){let{pascal:e}=r;return`import type { QueryFieldConfig } from '@forinda/kickjs-http'
|
|
858
755
|
|
|
859
756
|
export const ${e.toUpperCase()}_QUERY_CONFIG: QueryFieldConfig = {
|
|
860
757
|
filterable: ['name'],
|
|
861
758
|
sortable: ['name', 'createdAt'],
|
|
862
759
|
searchable: ['name'],
|
|
863
760
|
}
|
|
864
|
-
`}
|
|
761
|
+
`}s(U,"generateRestConstants");function Z(r){let{pascal:e,kebab:t,plural:o="",repo:i}=r,a={inmemory:`InMemory${e}Repository`,drizzle:`Drizzle${e}Repository`,prisma:`Prisma${e}Repository`},c={inmemory:`in-memory-${t}`,drizzle:`drizzle-${t}`,prisma:`prisma-${t}`},n=a[i]??a.inmemory,p=c[i]??c.inmemory;return`/**
|
|
865
762
|
* ${e} Module \u2014 CQRS Pattern
|
|
866
763
|
*
|
|
867
764
|
* Separates read (queries) and write (commands) operations.
|
|
@@ -877,7 +774,7 @@ export const ${e.toUpperCase()}_QUERY_CONFIG: QueryFieldConfig = {
|
|
|
877
774
|
import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs-core'
|
|
878
775
|
import { buildRoutes } from '@forinda/kickjs-http'
|
|
879
776
|
import { ${e.toUpperCase()}_REPOSITORY } from './${t}.repository'
|
|
880
|
-
import { ${
|
|
777
|
+
import { ${n} } from './${p}.repository'
|
|
881
778
|
import { ${e}Controller } from './${t}.controller'
|
|
882
779
|
|
|
883
780
|
// Eagerly load decorated classes
|
|
@@ -894,26 +791,26 @@ import.meta.glob(
|
|
|
894
791
|
export class ${e}Module implements AppModule {
|
|
895
792
|
register(container: Container): void {
|
|
896
793
|
container.registerFactory(${e.toUpperCase()}_REPOSITORY, () =>
|
|
897
|
-
container.resolve(${
|
|
794
|
+
container.resolve(${n}),
|
|
898
795
|
)
|
|
899
796
|
}
|
|
900
797
|
|
|
901
798
|
routes(): ModuleRoutes {
|
|
902
799
|
return {
|
|
903
|
-
path: '/${
|
|
800
|
+
path: '/${o}',
|
|
904
801
|
router: buildRoutes(${e}Controller),
|
|
905
802
|
controller: ${e}Controller,
|
|
906
803
|
}
|
|
907
804
|
}
|
|
908
805
|
}
|
|
909
|
-
`}
|
|
806
|
+
`}s(Z,"generateCqrsModuleIndex");function X(r){let{pascal:e,kebab:t,plural:o="",pluralPascal:i=""}=r;return`import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams } from '@forinda/kickjs-core'
|
|
910
807
|
import type { RequestContext } from '@forinda/kickjs-http'
|
|
911
808
|
import { ApiTags } from '@forinda/kickjs-swagger'
|
|
912
809
|
import { Create${e}Command } from './commands/create-${t}.command'
|
|
913
810
|
import { Update${e}Command } from './commands/update-${t}.command'
|
|
914
811
|
import { Delete${e}Command } from './commands/delete-${t}.command'
|
|
915
812
|
import { Get${e}Query } from './queries/get-${t}.query'
|
|
916
|
-
import { List${
|
|
813
|
+
import { List${i}Query } from './queries/list-${o}.query'
|
|
917
814
|
import { create${e}Schema } from './dtos/create-${t}.dto'
|
|
918
815
|
import { update${e}Schema } from './dtos/update-${t}.dto'
|
|
919
816
|
import { ${e.toUpperCase()}_QUERY_CONFIG } from './${t}.constants'
|
|
@@ -924,14 +821,14 @@ export class ${e}Controller {
|
|
|
924
821
|
@Autowired() private update${e}Command!: Update${e}Command
|
|
925
822
|
@Autowired() private delete${e}Command!: Delete${e}Command
|
|
926
823
|
@Autowired() private get${e}Query!: Get${e}Query
|
|
927
|
-
@Autowired() private list${
|
|
824
|
+
@Autowired() private list${i}Query!: List${i}Query
|
|
928
825
|
|
|
929
826
|
@Get('/')
|
|
930
827
|
@ApiTags('${e}')
|
|
931
828
|
@ApiQueryParams(${e.toUpperCase()}_QUERY_CONFIG)
|
|
932
829
|
async list(ctx: RequestContext) {
|
|
933
830
|
return ctx.paginate(
|
|
934
|
-
(parsed) => this.list${
|
|
831
|
+
(parsed) => this.list${i}Query.execute(parsed),
|
|
935
832
|
${e.toUpperCase()}_QUERY_CONFIG,
|
|
936
833
|
)
|
|
937
834
|
}
|
|
@@ -965,7 +862,7 @@ export class ${e}Controller {
|
|
|
965
862
|
ctx.noContent()
|
|
966
863
|
}
|
|
967
864
|
}
|
|
968
|
-
`}
|
|
865
|
+
`}s(X,"generateCqrsController");function ee(r){let{pascal:e,kebab:t}=r;return[{file:`create-${t}.command.ts`,content:`import { Service, Inject } from '@forinda/kickjs-core'
|
|
969
866
|
import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
|
|
970
867
|
import type { Create${e}DTO } from '../dtos/create-${t}.dto'
|
|
971
868
|
import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
|
|
@@ -1019,7 +916,7 @@ export class Delete${e}Command {
|
|
|
1019
916
|
this.events.emit('${t}.deleted', { id })
|
|
1020
917
|
}
|
|
1021
918
|
}
|
|
1022
|
-
`}]}
|
|
919
|
+
`}]}s(ee,"generateCqrsCommands");function te(r){let{pascal:e,kebab:t,plural:o="",pluralPascal:i=""}=r;return[{file:`get-${t}.query.ts`,content:`import { Service, Inject } from '@forinda/kickjs-core'
|
|
1023
920
|
import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
|
|
1024
921
|
import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
|
|
1025
922
|
|
|
@@ -1033,12 +930,12 @@ export class Get${e}Query {
|
|
|
1033
930
|
return this.repo.findById(id)
|
|
1034
931
|
}
|
|
1035
932
|
}
|
|
1036
|
-
`},{file:`list-${
|
|
933
|
+
`},{file:`list-${o}.query.ts`,content:`import { Service, Inject } from '@forinda/kickjs-core'
|
|
1037
934
|
import { ${e.toUpperCase()}_REPOSITORY, type I${e}Repository } from '../${t}.repository'
|
|
1038
935
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
1039
936
|
|
|
1040
937
|
@Service()
|
|
1041
|
-
export class List${
|
|
938
|
+
export class List${i}Query {
|
|
1042
939
|
constructor(
|
|
1043
940
|
@Inject(${e.toUpperCase()}_REPOSITORY) private readonly repo: I${e}Repository,
|
|
1044
941
|
) {}
|
|
@@ -1047,7 +944,7 @@ export class List${o}Query {
|
|
|
1047
944
|
return this.repo.findPaginated(parsed)
|
|
1048
945
|
}
|
|
1049
946
|
}
|
|
1050
|
-
`}]}
|
|
947
|
+
`}]}s(te,"generateCqrsQueries");function re(r){let{pascal:e,kebab:t}=r;return[{file:`${t}.events.ts`,content:`import { Service } from '@forinda/kickjs-core'
|
|
1051
948
|
import { EventEmitter } from 'node:events'
|
|
1052
949
|
import type { ${e}ResponseDTO } from '../dtos/${t}-response.dto'
|
|
1053
950
|
|
|
@@ -1133,149 +1030,307 @@ export class On${e}ChangeHandler {
|
|
|
1133
1030
|
})
|
|
1134
1031
|
}
|
|
1135
1032
|
}
|
|
1136
|
-
`}]}
|
|
1137
|
-
|
|
1138
|
-
import type { RequestContext } from '@forinda/kickjs-http'
|
|
1139
|
-
|
|
1140
|
-
@Controller()
|
|
1141
|
-
export class ${t}Controller {
|
|
1142
|
-
@Get('/')
|
|
1143
|
-
async list(ctx: RequestContext) {
|
|
1144
|
-
ctx.json({ message: '${t} list' })
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
`)}i(xe,"generateMinimalFiles");async function Re(e){let{pascal:t,kebab:r,plural:o,pluralPascal:n,repo:s,noTests:p,write:a}=e;await a("index.ts",G(t,r,o,s)),await a(`${r}.constants.ts`,z(t)),await a(`${r}.controller.ts`,B(t,r,o,n)),await a(`${r}.service.ts`,J(t,r)),await a(`dtos/create-${r}.dto.ts`,R(t,r)),await a(`dtos/update-${r}.dto.ts`,D(t,r)),await a(`dtos/${r}-response.dto.ts`,O(t,r)),await a(`${r}.repository.ts`,k(t,r,"./dtos"));let d={inmemory:`in-memory-${r}`,drizzle:`drizzle-${r}`,prisma:`prisma-${r}`},m={inmemory:i(()=>I(t,r,".","./dtos"),"inmemory"),drizzle:i(()=>T(t,r,".","./dtos"),"drizzle"),prisma:i(()=>P(t,r,".","./dtos"),"prisma")};await a(`${d[s]}.repository.ts`,m[s]()),p||(await a(`__tests__/${r}.controller.test.ts`,S(t,r,o)),await a(`__tests__/${r}.repository.test.ts`,j(t,r,o,`../${d.inmemory}.repository`)))}i(Re,"generateRestFiles");async function De(e){let{pascal:t,kebab:r,plural:o,pluralPascal:n,repo:s,noTests:p,write:a}=e;await a("index.ts",Z(t,r,o,s)),await a(`${r}.constants.ts`,z(t)),await a(`${r}.controller.ts`,X(t,r,o,n)),await a(`dtos/create-${r}.dto.ts`,R(t,r)),await a(`dtos/update-${r}.dto.ts`,D(t,r)),await a(`dtos/${r}-response.dto.ts`,O(t,r));let d=ee(t,r);for(let g of d)await a(`commands/${g.file}`,g.content);let m=te(t,r,o,n);for(let g of m)await a(`queries/${g.file}`,g.content);let u=re(t,r);for(let g of u)await a(`events/${g.file}`,g.content);await a(`${r}.repository.ts`,k(t,r,"./dtos"));let y={inmemory:`in-memory-${r}`,drizzle:`drizzle-${r}`,prisma:`prisma-${r}`},v={inmemory:i(()=>I(t,r,".","./dtos"),"inmemory"),drizzle:i(()=>T(t,r,".","./dtos"),"drizzle"),prisma:i(()=>P(t,r,".","./dtos"),"prisma")};await a(`${y[s]}.repository.ts`,v[s]()),p||(await a(`__tests__/${r}.controller.test.ts`,S(t,r,o)),await a(`__tests__/${r}.repository.test.ts`,j(t,r,o,`../${y.inmemory}.repository`)))}i(De,"generateCqrsFiles");async function Oe(e){let{pascal:t,kebab:r,plural:o,pluralPascal:n,repo:s,noEntity:p,noTests:a,write:d}=e;await d("index.ts",Q(t,r,o,s)),await d("constants.ts",s==="drizzle"?W(t,r):L(t)),await d(`presentation/${r}.controller.ts`,Y(t,r,o,n)),await d(`application/dtos/create-${r}.dto.ts`,R(t,r)),await d(`application/dtos/update-${r}.dto.ts`,D(t,r)),await d(`application/dtos/${r}-response.dto.ts`,O(t,r));let m=b(t,r,o,n);for(let v of m)await d(`application/use-cases/${v.file}`,v.content);await d(`domain/repositories/${r}.repository.ts`,k(t,r)),await d(`domain/services/${r}-domain.service.ts`,K(t,r));let u={inmemory:`in-memory-${r}`,drizzle:`drizzle-${r}`,prisma:`prisma-${r}`},y={inmemory:i(()=>I(t,r),"inmemory"),drizzle:i(()=>T(t,r),"drizzle"),prisma:i(()=>P(t,r),"prisma")};await d(`infrastructure/repositories/${u[s]}.repository.ts`,y[s]()),p||(await d(`domain/entities/${r}.entity.ts`,H(t,r)),await d(`domain/value-objects/${r}-id.vo.ts`,V(t,r))),a||(await d(`__tests__/${r}.controller.test.ts`,S(t,r,o)),await d(`__tests__/${r}.repository.test.ts`,j(t,r,o)))}i(Oe,"generateDddFiles");async function ke(e,t,r){let o=oe(e,"index.ts");if(!await F(o)){await c(o,`import type { AppModuleClass } from '@forinda/kickjs-core'
|
|
1148
|
-
import { ${t}Module } from './${r}'
|
|
1149
|
-
|
|
1150
|
-
export const modules: AppModuleClass[] = [${t}Module]
|
|
1151
|
-
`);return}let s=await he(o,"utf-8"),p=`import { ${t}Module } from './${r}'`;if(!s.includes(`${t}Module`)){let a=s.lastIndexOf("import ");if(a!==-1){let d=s.indexOf(`
|
|
1152
|
-
`,a);s=s.slice(0,d+1)+p+`
|
|
1153
|
-
`+s.slice(d+1)}else s=p+`
|
|
1154
|
-
`+s;s=s.replace(/(=\s*\[)([\s\S]*?)(])/,(d,m,u,y)=>{let v=u.trim();if(!v)return`${m}${t}Module${y}`;let g=v.endsWith(",")?"":",";return`${m}${u.trimEnd()}${g} ${t}Module${y}`})}await we(o,s,"utf-8")}i(ke,"autoRegisterModule");import{join as Ie}from"path";async function Te(e){let{name:t,outDir:r}=e,o=f(t),n=l(t),s=[],p=Ie(r,`${o}.adapter.ts`);return await c(p,`import type { Express } from 'express'
|
|
1155
|
-
import type { AppAdapter, AdapterMiddleware, Container } from '@forinda/kickjs-core'
|
|
1156
|
-
|
|
1157
|
-
export interface ${n}AdapterOptions {
|
|
1158
|
-
// Add your adapter configuration here
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
/**
|
|
1162
|
-
* ${n} adapter.
|
|
1033
|
+
`}]}s(re,"generateCqrsEvents");function S(r){let{pascal:e,kebab:t,repoPrefix:o="../../domain/repositories",dtoPrefix:i="../../application/dtos"}=r;return`/**
|
|
1034
|
+
* Drizzle ${e} Repository
|
|
1163
1035
|
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1036
|
+
* Implements the repository interface using Drizzle ORM.
|
|
1037
|
+
* Uses buildFromColumns() with Column objects for type-safe query building.
|
|
1166
1038
|
*
|
|
1167
|
-
*
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1039
|
+
* TODO: Update the schema import to match your Drizzle schema file.
|
|
1040
|
+
* TODO: Replace DRIZZLE_DB injection token with your actual database token.
|
|
1041
|
+
*
|
|
1042
|
+
* @Repository() registers this class in the DI container as a singleton.
|
|
1171
1043
|
*/
|
|
1172
|
-
|
|
1173
|
-
|
|
1044
|
+
import { eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc, count, sql } from 'drizzle-orm'
|
|
1045
|
+
import { Repository, HttpException, Inject } from '@forinda/kickjs-core'
|
|
1046
|
+
import { DRIZZLE_DB, DrizzleQueryAdapter } from '@forinda/kickjs-drizzle'
|
|
1047
|
+
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
1048
|
+
import type { I${e}Repository } from '${o}/${t}.repository'
|
|
1049
|
+
import type { ${e}ResponseDTO } from '${i}/${t}-response.dto'
|
|
1050
|
+
import type { Create${e}DTO } from '${i}/create-${t}.dto'
|
|
1051
|
+
import type { Update${e}DTO } from '${i}/update-${t}.dto'
|
|
1052
|
+
import { ${e.toUpperCase()}_QUERY_CONFIG } from '../../constants'
|
|
1174
1053
|
|
|
1175
|
-
|
|
1054
|
+
// TODO: Import your Drizzle schema table \u2014 e.g.:
|
|
1055
|
+
// import { ${t}s } from '@/db/schema'
|
|
1176
1056
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
// },
|
|
1191
|
-
// },
|
|
1192
|
-
// Example: scope middleware to a specific path
|
|
1193
|
-
// {
|
|
1194
|
-
// phase: 'beforeRoutes',
|
|
1195
|
-
// path: '/api/v1/admin',
|
|
1196
|
-
// handler: myAdminMiddleware(),
|
|
1197
|
-
// },
|
|
1198
|
-
]
|
|
1057
|
+
const queryAdapter = new DrizzleQueryAdapter({
|
|
1058
|
+
eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc,
|
|
1059
|
+
})
|
|
1060
|
+
|
|
1061
|
+
@Repository()
|
|
1062
|
+
export class Drizzle${e}Repository implements I${e}Repository {
|
|
1063
|
+
constructor(@Inject(DRIZZLE_DB) private db: any) {}
|
|
1064
|
+
|
|
1065
|
+
async findById(id: string): Promise<${e}ResponseDTO | null> {
|
|
1066
|
+
// TODO: Implement with Drizzle
|
|
1067
|
+
// const row = this.db.select().from(${t}s).where(eq(${t}s.id, id)).get()
|
|
1068
|
+
// return row ?? null
|
|
1069
|
+
throw new Error('Drizzle ${e} repository not yet implemented \u2014 update schema imports and queries')
|
|
1199
1070
|
}
|
|
1200
1071
|
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
*/
|
|
1206
|
-
beforeMount(app: Express, container: Container): void {
|
|
1207
|
-
// Example: mount a status route
|
|
1208
|
-
// app.get('/${o}/status', (_req, res) => {
|
|
1209
|
-
// res.json({ status: 'ok' })
|
|
1210
|
-
// })
|
|
1072
|
+
async findAll(): Promise<${e}ResponseDTO[]> {
|
|
1073
|
+
// TODO: Implement with Drizzle
|
|
1074
|
+
// return this.db.select().from(${t}s).all()
|
|
1075
|
+
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
1211
1076
|
}
|
|
1212
1077
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
//
|
|
1219
|
-
//
|
|
1078
|
+
async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
|
|
1079
|
+
// TODO: Use buildFromColumns() with your query config for type-safe filtering
|
|
1080
|
+
// const query = queryAdapter.buildFromColumns(parsed, ${e.toUpperCase()}_QUERY_CONFIG)
|
|
1081
|
+
//
|
|
1082
|
+
// const data = this.db
|
|
1083
|
+
// .select().from(${t}s).$dynamic()
|
|
1084
|
+
// .where(query.where).orderBy(...query.orderBy)
|
|
1085
|
+
// .limit(query.limit).offset(query.offset).all()
|
|
1086
|
+
//
|
|
1087
|
+
// const totalResult = this.db
|
|
1088
|
+
// .select({ count: count() }).from(${t}s)
|
|
1089
|
+
// .$dynamic().where(query.where).get()
|
|
1090
|
+
//
|
|
1091
|
+
// return { data, total: totalResult?.count ?? 0 }
|
|
1092
|
+
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
1220
1093
|
}
|
|
1221
1094
|
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
afterStart(server: any, container: Container): void {
|
|
1227
|
-
// Example: attach Socket.IO
|
|
1228
|
-
// const io = new Server(server)
|
|
1229
|
-
// container.registerInstance(SOCKET_IO, io)
|
|
1095
|
+
async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
|
|
1096
|
+
// TODO: Implement with Drizzle
|
|
1097
|
+
// return this.db.insert(${t}s).values(dto).returning().get()
|
|
1098
|
+
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
1230
1099
|
}
|
|
1231
1100
|
|
|
1232
|
-
|
|
1233
|
-
|
|
1101
|
+
async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
|
|
1102
|
+
// TODO: Implement with Drizzle
|
|
1103
|
+
// const row = this.db.update(${t}s).set(dto).where(eq(${t}s.id, id)).returning().get()
|
|
1104
|
+
// if (!row) throw HttpException.notFound('${e} not found')
|
|
1105
|
+
// return row
|
|
1106
|
+
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
async delete(id: string): Promise<void> {
|
|
1110
|
+
// TODO: Implement with Drizzle
|
|
1111
|
+
// this.db.delete(${t}s).where(eq(${t}s.id, id)).run()
|
|
1112
|
+
throw new Error('Drizzle ${e} repository not yet implemented')
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
`}s(S,"generateDrizzleRepository");function oe(r){let{pascal:e,kebab:t}=r;return`import type { DrizzleQueryParamsConfig } from '@forinda/kickjs-drizzle'
|
|
1116
|
+
// TODO: Import your schema table and reference actual columns for type safety
|
|
1117
|
+
// import { ${t}s } from '@/db/schema'
|
|
1118
|
+
|
|
1119
|
+
export const ${e.toUpperCase()}_QUERY_CONFIG: DrizzleQueryParamsConfig = {
|
|
1120
|
+
columns: {
|
|
1121
|
+
// Replace with actual Drizzle Column references for type-safe filtering:
|
|
1122
|
+
// name: ${t}s.name,
|
|
1123
|
+
// status: ${t}s.status,
|
|
1124
|
+
},
|
|
1125
|
+
sortable: {
|
|
1126
|
+
// name: ${t}s.name,
|
|
1127
|
+
// createdAt: ${t}s.createdAt,
|
|
1128
|
+
},
|
|
1129
|
+
searchColumns: [
|
|
1130
|
+
// ${t}s.name,
|
|
1131
|
+
],
|
|
1132
|
+
}
|
|
1133
|
+
`}s(oe,"generateDrizzleConstants");function A(r){let{pascal:e,kebab:t,repoPrefix:o="../../domain/repositories",dtoPrefix:i="../../application/dtos"}=r,a=t.replace(/-([a-z])/g,(c,n)=>n.toUpperCase());return`/**
|
|
1134
|
+
* Prisma ${e} Repository
|
|
1135
|
+
*
|
|
1136
|
+
* Implements the repository interface using Prisma Client.
|
|
1137
|
+
* Requires a PrismaClient instance injected via the DI container.
|
|
1138
|
+
*
|
|
1139
|
+
* Ensure your Prisma schema has a '${e}' model defined.
|
|
1140
|
+
*
|
|
1141
|
+
* For full Prisma field-level type safety, replace PrismaModelDelegate with your PrismaClient:
|
|
1142
|
+
* @Inject(PRISMA_CLIENT) private prisma!: PrismaClient
|
|
1143
|
+
*
|
|
1144
|
+
* @Repository() registers this class in the DI container as a singleton.
|
|
1145
|
+
*/
|
|
1146
|
+
import { Repository, HttpException, Inject } from '@forinda/kickjs-core'
|
|
1147
|
+
import { PRISMA_CLIENT, type PrismaModelDelegate } from '@forinda/kickjs-prisma'
|
|
1148
|
+
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
1149
|
+
import type { I${e}Repository } from '${o}/${t}.repository'
|
|
1150
|
+
import type { ${e}ResponseDTO } from '${i}/${t}-response.dto'
|
|
1151
|
+
import type { Create${e}DTO } from '${i}/create-${t}.dto'
|
|
1152
|
+
import type { Update${e}DTO } from '${i}/update-${t}.dto'
|
|
1153
|
+
|
|
1154
|
+
@Repository()
|
|
1155
|
+
export class Prisma${e}Repository implements I${e}Repository {
|
|
1156
|
+
@Inject(PRISMA_CLIENT) private prisma!: { ${a}: PrismaModelDelegate }
|
|
1157
|
+
|
|
1158
|
+
async findById(id: string): Promise<${e}ResponseDTO | null> {
|
|
1159
|
+
return this.prisma.${a}.findUnique({ where: { id } }) as Promise<${e}ResponseDTO | null>
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
async findAll(): Promise<${e}ResponseDTO[]> {
|
|
1163
|
+
return this.prisma.${a}.findMany() as Promise<${e}ResponseDTO[]>
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
async findPaginated(parsed: ParsedQuery): Promise<{ data: ${e}ResponseDTO[]; total: number }> {
|
|
1167
|
+
const [data, total] = await Promise.all([
|
|
1168
|
+
this.prisma.${a}.findMany({
|
|
1169
|
+
skip: parsed.pagination.offset,
|
|
1170
|
+
take: parsed.pagination.limit,
|
|
1171
|
+
}) as Promise<${e}ResponseDTO[]>,
|
|
1172
|
+
this.prisma.${a}.count(),
|
|
1173
|
+
])
|
|
1174
|
+
return { data, total }
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
async create(dto: Create${e}DTO): Promise<${e}ResponseDTO> {
|
|
1178
|
+
return this.prisma.${a}.create({ data: dto as Record<string, unknown> }) as Promise<${e}ResponseDTO>
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
async update(id: string, dto: Update${e}DTO): Promise<${e}ResponseDTO> {
|
|
1182
|
+
const existing = await this.prisma.${a}.findUnique({ where: { id } })
|
|
1183
|
+
if (!existing) throw HttpException.notFound('${e} not found')
|
|
1184
|
+
return this.prisma.${a}.update({ where: { id }, data: dto as Record<string, unknown> }) as Promise<${e}ResponseDTO>
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
async delete(id: string): Promise<void> {
|
|
1188
|
+
await this.prisma.${a}.deleteMany({ where: { id } })
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
`}s(A,"generatePrismaRepository");async function se(r){let{pascal:e,kebab:t,plural:o,write:i}=r;await i("index.ts",L({pascal:e,kebab:t,plural:o})),await i(`${t}.controller.ts`,`import { Controller, Get } from '@forinda/kickjs-core'
|
|
1192
|
+
import type { RequestContext } from '@forinda/kickjs-http'
|
|
1193
|
+
|
|
1194
|
+
@Controller()
|
|
1195
|
+
export class ${e}Controller {
|
|
1196
|
+
@Get('/')
|
|
1197
|
+
async list(ctx: RequestContext) {
|
|
1198
|
+
ctx.json({ message: '${e} list' })
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
`)}s(se,"generateMinimalFiles");async function ie(r){let{pascal:e,kebab:t,plural:o,pluralPascal:i,repo:a,noTests:c,prismaClientPath:n,write:p}=r;await p("index.ts",Q({pascal:e,kebab:t,plural:o,repo:a})),await p(`${t}.constants.ts`,U({pascal:e,kebab:t})),await p(`${t}.controller.ts`,W({pascal:e,kebab:t,plural:o,pluralPascal:i})),await p(`${t}.service.ts`,V({pascal:e,kebab:t})),await p(`dtos/create-${t}.dto.ts`,C({pascal:e,kebab:t})),await p(`dtos/update-${t}.dto.ts`,R({pascal:e,kebab:t})),await p(`dtos/${t}-response.dto.ts`,b({pascal:e,kebab:t})),await p(`${t}.repository.ts`,D({pascal:e,kebab:t,dtoPrefix:"./dtos"}));let d={inmemory:`in-memory-${t}`,drizzle:`drizzle-${t}`,prisma:`prisma-${t}`},m={inmemory:s(()=>T({pascal:e,kebab:t,repoPrefix:".",dtoPrefix:"./dtos"}),"inmemory"),drizzle:s(()=>S({pascal:e,kebab:t,repoPrefix:".",dtoPrefix:"./dtos"}),"drizzle"),prisma:s(()=>A({pascal:e,kebab:t,repoPrefix:".",dtoPrefix:"./dtos",prismaClientPath:n}),"prisma")},y=d[a]??`${u(a)}-${t}`,$=m[a]??(()=>P({pascal:e,kebab:t,repoType:a,repoPrefix:".",dtoPrefix:"./dtos"}));await p(`${y}.repository.ts`,$()),c||(await p(`__tests__/${t}.controller.test.ts`,O({pascal:e,kebab:t,plural:o})),await p(`__tests__/${t}.repository.test.ts`,I({pascal:e,kebab:t,plural:o,repoPrefix:`../${d.inmemory??`in-memory-${t}`}.repository`})))}s(ie,"generateRestFiles");async function ae(r){let{pascal:e,kebab:t,plural:o,pluralPascal:i,repo:a,noTests:c,prismaClientPath:n,write:p}=r;await p("index.ts",Z({pascal:e,kebab:t,plural:o,repo:a})),await p(`${t}.constants.ts`,U({pascal:e,kebab:t})),await p(`${t}.controller.ts`,X({pascal:e,kebab:t,plural:o,pluralPascal:i})),await p(`dtos/create-${t}.dto.ts`,C({pascal:e,kebab:t})),await p(`dtos/update-${t}.dto.ts`,R({pascal:e,kebab:t})),await p(`dtos/${t}-response.dto.ts`,b({pascal:e,kebab:t}));let d=ee({pascal:e,kebab:t});for(let h of d)await p(`commands/${h.file}`,h.content);let m=te({pascal:e,kebab:t,plural:o,pluralPascal:i});for(let h of m)await p(`queries/${h.file}`,h.content);let y=re({pascal:e,kebab:t});for(let h of y)await p(`events/${h.file}`,h.content);await p(`${t}.repository.ts`,D({pascal:e,kebab:t,dtoPrefix:"./dtos"}));let $={inmemory:`in-memory-${t}`,drizzle:`drizzle-${t}`,prisma:`prisma-${t}`},x={inmemory:s(()=>T({pascal:e,kebab:t,repoPrefix:".",dtoPrefix:"./dtos"}),"inmemory"),drizzle:s(()=>S({pascal:e,kebab:t,repoPrefix:".",dtoPrefix:"./dtos"}),"drizzle"),prisma:s(()=>A({pascal:e,kebab:t,repoPrefix:".",dtoPrefix:"./dtos",prismaClientPath:n}),"prisma")},j=$[a]??`${u(a)}-${t}`,v=x[a]??(()=>P({pascal:e,kebab:t,repoType:a,repoPrefix:".",dtoPrefix:"./dtos"}));await p(`${j}.repository.ts`,v()),c||(await p(`__tests__/${t}.controller.test.ts`,O({pascal:e,kebab:t,plural:o})),await p(`__tests__/${t}.repository.test.ts`,I({pascal:e,kebab:t,plural:o,repoPrefix:`../${$.inmemory??`in-memory-${t}`}.repository`})))}s(ae,"generateCqrsFiles");async function ne(r){let{pascal:e,kebab:t,plural:o,pluralPascal:i,repo:a,noEntity:c,noTests:n,prismaClientPath:p,write:d}=r;await d("index.ts",G({pascal:e,kebab:t,plural:o,repo:a})),await d("constants.ts",a==="drizzle"?oe({pascal:e,kebab:t}):B({pascal:e,kebab:t})),await d(`presentation/${t}.controller.ts`,N({pascal:e,kebab:t,plural:o,pluralPascal:i})),await d(`application/dtos/create-${t}.dto.ts`,C({pascal:e,kebab:t})),await d(`application/dtos/update-${t}.dto.ts`,R({pascal:e,kebab:t})),await d(`application/dtos/${t}-response.dto.ts`,b({pascal:e,kebab:t}));let m=K({pascal:e,kebab:t,plural:o,pluralPascal:i});for(let v of m)await d(`application/use-cases/${v.file}`,v.content);await d(`domain/repositories/${t}.repository.ts`,D({pascal:e,kebab:t})),await d(`domain/services/${t}-domain.service.ts`,Y({pascal:e,kebab:t}));let y={inmemory:`in-memory-${t}`,drizzle:`drizzle-${t}`,prisma:`prisma-${t}`},$={inmemory:s(()=>T({pascal:e,kebab:t}),"inmemory"),drizzle:s(()=>S({pascal:e,kebab:t}),"drizzle"),prisma:s(()=>A({pascal:e,kebab:t,prismaClientPath:p}),"prisma")},x=y[a]??`${u(a)}-${t}`,j=$[a]??(()=>P({pascal:e,kebab:t,repoType:a}));await d(`infrastructure/repositories/${x}.repository.ts`,j()),c||(await d(`domain/entities/${t}.entity.ts`,H({pascal:e,kebab:t})),await d(`domain/value-objects/${t}-id.vo.ts`,J({pascal:e,kebab:t}))),n||(await d(`__tests__/${t}.controller.test.ts`,O({pascal:e,kebab:t,plural:o})),await d(`__tests__/${t}.repository.test.ts`,I({pascal:e,kebab:t,plural:o})))}s(ne,"generateDddFiles");function Be(r){let e=Le({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question(r,o=>{e.close(),t(o.trim().toLowerCase())})})}s(Be,"promptUser");async function Ke(r){let{name:e,modulesDir:t,noEntity:o,noTests:i,repo:a="inmemory",force:c,dryRun:n}=r,p=r.pluralize!==!1,d=r.pattern??"ddd";r.minimal&&(d="minimal");let m=u(e),y=f(e),$=p?E(m):m,x=p?le(y):y,j=ce(t,$),v=[],h=c??!1,je=s(async(_,Ee)=>{let z=ce(j,_);if(n){v.push(z);return}if(!h&&await F(z)){let de=await Be(` File already exists: ${_}
|
|
1202
|
+
Overwrite? (y/n/a = yes/no/all) `);if(de==="a")h=!0;else if(de!=="y"){console.log(` Skipped: ${_}`);return}}await l(z,Ee),v.push(z)},"write"),q={kebab:m,pascal:y,plural:$,pluralPascal:x,moduleDir:j,repo:a,noEntity:o??!1,noTests:i??!1,prismaClientPath:r.prismaClientPath??"@prisma/client",write:je,files:v};switch(d){case"minimal":await se(q);break;case"rest":await ie(q);break;case"cqrs":await ae(q);break;default:await ne(q);break}return n||await Ye(t,y,$),v}s(Ke,"generateModule");async function Ye(r,e,t){let o=ce(r,"index.ts");if(!await F(o)){await l(o,`import type { AppModuleClass } from '@forinda/kickjs-core'
|
|
1203
|
+
import { ${e}Module } from './${t}'
|
|
1204
|
+
|
|
1205
|
+
export const modules: AppModuleClass[] = [${e}Module]
|
|
1206
|
+
`);return}let a=await Ne(o,"utf-8"),c=`import { ${e}Module } from './${t}'`;if(!a.includes(`${e}Module`)){let n=a.lastIndexOf("import ");if(n!==-1){let p=a.indexOf(`
|
|
1207
|
+
`,n);a=a.slice(0,p+1)+c+`
|
|
1208
|
+
`+a.slice(p+1)}else a=c+`
|
|
1209
|
+
`+a;a=a.replace(/(=\s*\[)([\s\S]*?)(])/,(p,d,m,y)=>{let $=m.trim();if(!$)return`${d}${e}Module${y}`;let x=$.endsWith(",")?"":",";return`${d}${m.trimEnd()}${x} ${e}Module${y}`})}await We(o,a,"utf-8")}s(Ye,"autoRegisterModule");import{join as He}from"path";async function Je(r){let{name:e,outDir:t}=r,o=u(e),i=f(e),a=[],c=He(t,`${o}.adapter.ts`);return await l(c,`import type { Express } from 'express'
|
|
1210
|
+
import type { AppAdapter, AdapterMiddleware, Container } from '@forinda/kickjs-core'
|
|
1211
|
+
|
|
1212
|
+
export interface ${i}AdapterOptions {
|
|
1213
|
+
// Add your adapter configuration here
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* ${i} adapter.
|
|
1218
|
+
*
|
|
1219
|
+
* Hooks into the Application lifecycle to add middleware, routes,
|
|
1220
|
+
* or external service connections.
|
|
1221
|
+
*
|
|
1222
|
+
* Usage:
|
|
1223
|
+
* bootstrap({
|
|
1224
|
+
* adapters: [new ${i}Adapter({ ... })],
|
|
1225
|
+
* })
|
|
1226
|
+
*/
|
|
1227
|
+
export class ${i}Adapter implements AppAdapter {
|
|
1228
|
+
name = '${i}Adapter'
|
|
1229
|
+
|
|
1230
|
+
constructor(private options: ${i}AdapterOptions = {}) {}
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* Return middleware entries that the Application will mount.
|
|
1234
|
+
* Use \`phase\` to control where in the pipeline they run:
|
|
1235
|
+
* 'beforeGlobal' | 'afterGlobal' | 'beforeRoutes' | 'afterRoutes'
|
|
1236
|
+
*/
|
|
1237
|
+
middleware(): AdapterMiddleware[] {
|
|
1238
|
+
return [
|
|
1239
|
+
// Example: add a custom header to all responses
|
|
1240
|
+
// {
|
|
1241
|
+
// phase: 'beforeGlobal',
|
|
1242
|
+
// handler: (_req: any, res: any, next: any) => {
|
|
1243
|
+
// res.setHeader('X-${i}', 'true')
|
|
1244
|
+
// next()
|
|
1245
|
+
// },
|
|
1246
|
+
// },
|
|
1247
|
+
// Example: scope middleware to a specific path
|
|
1248
|
+
// {
|
|
1249
|
+
// phase: 'beforeRoutes',
|
|
1250
|
+
// path: '/api/v1/admin',
|
|
1251
|
+
// handler: myAdminMiddleware(),
|
|
1252
|
+
// },
|
|
1253
|
+
]
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Called before global middleware.
|
|
1258
|
+
* Use this to mount routes that bypass the middleware stack
|
|
1259
|
+
* (health checks, docs UI, static assets).
|
|
1260
|
+
*/
|
|
1261
|
+
beforeMount(app: Express, container: Container): void {
|
|
1262
|
+
// Example: mount a status route
|
|
1263
|
+
// app.get('/${o}/status', (_req, res) => {
|
|
1264
|
+
// res.json({ status: 'ok' })
|
|
1265
|
+
// })
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Called after modules and routes are registered, before the server starts.
|
|
1270
|
+
* Use this for late-stage DI registrations or config validation.
|
|
1271
|
+
*/
|
|
1272
|
+
beforeStart(app: Express, container: Container): void {
|
|
1273
|
+
// Example: register a service in the DI container
|
|
1274
|
+
// container.registerInstance(MY_TOKEN, new MyService(this.options))
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Called after the HTTP server is listening.
|
|
1279
|
+
* Use this to attach to the raw http.Server (Socket.IO, gRPC, etc).
|
|
1280
|
+
*/
|
|
1281
|
+
afterStart(server: any, container: Container): void {
|
|
1282
|
+
// Example: attach Socket.IO
|
|
1283
|
+
// const io = new Server(server)
|
|
1284
|
+
// container.registerInstance(SOCKET_IO, io)
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Called on graceful shutdown. Clean up connections.
|
|
1234
1289
|
*/
|
|
1235
1290
|
async shutdown(): Promise<void> {
|
|
1236
1291
|
// Example: close a connection pool
|
|
1237
1292
|
// await this.pool.end()
|
|
1238
1293
|
}
|
|
1239
1294
|
}
|
|
1240
|
-
`),
|
|
1295
|
+
`),a.push(c),a}s(Je,"generateAdapter");import{join as et}from"path";import{resolve as pe,join as ge}from"path";var Ve={controller:"presentation",service:"domain/services",dto:"application/dtos",guard:"presentation/guards",middleware:"middleware"},Ze={controller:"",service:"",dto:"dtos",guard:"guards",middleware:"middleware"},Xe={controller:"",service:"",dto:"dtos",guard:"guards",middleware:"middleware",command:"commands",query:"queries",event:"events"};function k(r){let{type:e,outDir:t,moduleName:o,modulesDir:i="src/modules",defaultDir:a,pattern:c="ddd"}=r;if(t)return pe(t);if(o){let n=c==="ddd"?Ve:c==="cqrs"?Xe:Ze,p=u(o),d=E(p),m=n[e]??"",y=ge(i,d);return pe(m?ge(y,m):y)}return pe(a)}s(k,"resolveOutDir");async function tt(r){let{name:e,moduleName:t,modulesDir:o,pattern:i}=r,a=k({type:"middleware",outDir:r.outDir,moduleName:t,modulesDir:o,defaultDir:"src/middleware",pattern:i}),c=u(e),n=w(e),p=[],d=et(a,`${c}.middleware.ts`);return await l(d,`import type { Request, Response, NextFunction } from 'express'
|
|
1241
1296
|
|
|
1242
|
-
export interface ${
|
|
1297
|
+
export interface ${f(e)}Options {
|
|
1243
1298
|
// Add configuration options here
|
|
1244
1299
|
}
|
|
1245
1300
|
|
|
1246
1301
|
/**
|
|
1247
|
-
* ${
|
|
1302
|
+
* ${f(e)} middleware.
|
|
1248
1303
|
*
|
|
1249
1304
|
* Usage in bootstrap:
|
|
1250
|
-
* middleware: [${
|
|
1305
|
+
* middleware: [${n}()]
|
|
1251
1306
|
*
|
|
1252
1307
|
* Usage with adapter:
|
|
1253
|
-
* middleware() { return [{ handler: ${
|
|
1308
|
+
* middleware() { return [{ handler: ${n}(), phase: 'afterGlobal' }] }
|
|
1254
1309
|
*
|
|
1255
1310
|
* Usage with @Middleware decorator:
|
|
1256
|
-
* @Middleware(${
|
|
1311
|
+
* @Middleware(${n}())
|
|
1257
1312
|
*/
|
|
1258
|
-
export function ${
|
|
1313
|
+
export function ${n}(options: ${f(e)}Options = {}) {
|
|
1259
1314
|
return (req: Request, res: Response, next: NextFunction) => {
|
|
1260
1315
|
// Implement your middleware logic here
|
|
1261
1316
|
next()
|
|
1262
1317
|
}
|
|
1263
1318
|
}
|
|
1264
|
-
`),
|
|
1319
|
+
`),p.push(d),p}s(tt,"generateMiddleware");import{join as rt}from"path";async function ot(r){let{name:e,moduleName:t,modulesDir:o,pattern:i}=r,a=k({type:"guard",outDir:r.outDir,moduleName:t,modulesDir:o,defaultDir:"src/guards",pattern:i}),c=u(e),n=w(e),p=f(e),d=[],m=rt(a,`${c}.guard.ts`);return await l(m,`import { Container, HttpException } from '@forinda/kickjs-core'
|
|
1265
1320
|
import type { RequestContext } from '@forinda/kickjs-http'
|
|
1266
1321
|
|
|
1267
1322
|
/**
|
|
1268
|
-
* ${
|
|
1323
|
+
* ${p} guard.
|
|
1269
1324
|
*
|
|
1270
1325
|
* Guards protect routes by checking conditions before the handler runs.
|
|
1271
1326
|
* Return early with an error response to block access.
|
|
1272
1327
|
*
|
|
1273
1328
|
* Usage:
|
|
1274
|
-
* @Middleware(${
|
|
1329
|
+
* @Middleware(${n}Guard)
|
|
1275
1330
|
* @Get('/protected')
|
|
1276
1331
|
* async handler(ctx: RequestContext) { ... }
|
|
1277
1332
|
*/
|
|
1278
|
-
export async function ${
|
|
1333
|
+
export async function ${n}Guard(ctx: RequestContext, next: () => void): Promise<void> {
|
|
1279
1334
|
// Example: check for an authorization header
|
|
1280
1335
|
const header = ctx.headers.authorization
|
|
1281
1336
|
if (!header?.startsWith('Bearer ')) {
|
|
@@ -1297,43 +1352,41 @@ export async function ${a}Guard(ctx: RequestContext, next: () => void): Promise<
|
|
|
1297
1352
|
ctx.res.status(401).json({ message: 'Invalid or expired token' })
|
|
1298
1353
|
}
|
|
1299
1354
|
}
|
|
1300
|
-
`),
|
|
1355
|
+
`),d.push(m),d}s(ot,"generateGuard");import{join as st}from"path";async function it(r){let{name:e,moduleName:t,modulesDir:o,pattern:i}=r,a=k({type:"service",outDir:r.outDir,moduleName:t,modulesDir:o,defaultDir:"src/services",pattern:i}),c=u(e),n=f(e),p=[],d=st(a,`${c}.service.ts`);return await l(d,`import { Service } from '@forinda/kickjs-core'
|
|
1301
1356
|
|
|
1302
1357
|
@Service()
|
|
1303
|
-
export class ${
|
|
1358
|
+
export class ${n}Service {
|
|
1304
1359
|
// Inject dependencies via constructor
|
|
1305
1360
|
// constructor(
|
|
1306
1361
|
// @Inject(MY_REPO) private readonly repo: IMyRepository,
|
|
1307
1362
|
// ) {}
|
|
1308
1363
|
}
|
|
1309
|
-
`),
|
|
1364
|
+
`),p.push(d),p}s(it,"generateService");import{join as at}from"path";async function nt(r){let{name:e,moduleName:t,modulesDir:o,pattern:i}=r,a=k({type:"controller",outDir:r.outDir,moduleName:t,modulesDir:o,defaultDir:"src/controllers",pattern:i}),c=u(e),n=f(e),p=[],d=at(a,`${c}.controller.ts`);return await l(d,`import { Controller, Get, Post, Autowired } from '@forinda/kickjs-core'
|
|
1310
1365
|
import type { RequestContext } from '@forinda/kickjs-http'
|
|
1311
1366
|
|
|
1312
1367
|
@Controller()
|
|
1313
|
-
export class ${
|
|
1368
|
+
export class ${n}Controller {
|
|
1314
1369
|
// @Autowired() private myService!: MyService
|
|
1315
1370
|
|
|
1316
1371
|
@Get('/')
|
|
1317
1372
|
async list(ctx: RequestContext) {
|
|
1318
|
-
ctx.json({ message: '${
|
|
1373
|
+
ctx.json({ message: '${n} list' })
|
|
1319
1374
|
}
|
|
1320
1375
|
|
|
1321
1376
|
@Post('/')
|
|
1322
1377
|
async create(ctx: RequestContext) {
|
|
1323
|
-
ctx.created({ message: '${
|
|
1378
|
+
ctx.created({ message: '${n} created', data: ctx.body })
|
|
1324
1379
|
}
|
|
1325
1380
|
}
|
|
1326
|
-
`),
|
|
1381
|
+
`),p.push(d),p}s(nt,"generateController");import{join as ct}from"path";async function pt(r){let{name:e,moduleName:t,modulesDir:o,pattern:i}=r,a=k({type:"dto",outDir:r.outDir,moduleName:t,modulesDir:o,defaultDir:"src/dtos",pattern:i}),c=u(e),n=f(e),p=w(e),d=[],m=ct(a,`${c}.dto.ts`);return await l(m,`import { z } from 'zod'
|
|
1327
1382
|
|
|
1328
|
-
export const ${
|
|
1383
|
+
export const ${p}Schema = z.object({
|
|
1329
1384
|
// Define your schema fields here
|
|
1330
1385
|
name: z.string().min(1).max(200),
|
|
1331
1386
|
})
|
|
1332
1387
|
|
|
1333
|
-
export type ${
|
|
1334
|
-
`),
|
|
1335
|
-
Creating KickJS project: ${t}
|
|
1336
|
-
`);let p={"@forinda/kickjs-core":h,"@forinda/kickjs-http":h,"@forinda/kickjs-config":h,express:"^5.1.0","reflect-metadata":"^0.2.2",zod:"^4.3.6",pino:"^10.3.1","pino-pretty":"^13.1.3"};if(n!=="minimal"&&(p["@forinda/kickjs-swagger"]=h,p["@forinda/kickjs-devtools"]=h),n==="graphql"&&(p["@forinda/kickjs-graphql"]=h,p.graphql="^16.11.0"),n==="cqrs"&&(p["@forinda/kickjs-queue"]=h,p["@forinda/kickjs-ws"]=h,p["@forinda/kickjs-otel"]=h),n==="ddd"&&(p["@forinda/kickjs-swagger"]=h),await c($(s,"package.json"),JSON.stringify({name:t,version:q.version,type:"module",scripts:{dev:"kick dev","dev:debug":"kick dev:debug",build:"kick build",start:"kick start",test:"vitest run","test:watch":"vitest",typecheck:"tsc --noEmit",lint:"eslint src/",format:"prettier --write src/"},dependencies:p,devDependencies:{"@forinda/kickjs-cli":h,"@swc/core":"^1.7.28","@types/express":"^5.0.6","@types/node":"^24.5.2","unplugin-swc":"^1.5.9",vite:"^7.3.1","vite-node":"^5.3.0",vitest:"^3.2.4",typescript:"^5.9.2",prettier:"^3.8.1"}},null,2)),await c($(s,"vite.config.ts"),`import { defineConfig } from 'vite'
|
|
1388
|
+
export type ${n}DTO = z.infer<typeof ${p}Schema>
|
|
1389
|
+
`),d.push(m),d}s(pt,"generateDto");import{join as g,dirname as dt}from"path";import{execSync as M}from"child_process";import{readFileSync as lt}from"fs";import{fileURLToPath as mt}from"url";function ye(r,e,t){let o={"@forinda/kickjs-core":t,"@forinda/kickjs-http":t,"@forinda/kickjs-config":t,express:"^5.1.0","reflect-metadata":"^0.2.2",zod:"^4.3.6",pino:"^10.3.1","pino-pretty":"^13.1.3"};return e!=="minimal"&&(o["@forinda/kickjs-swagger"]=t,o["@forinda/kickjs-devtools"]=t),e==="graphql"&&(o["@forinda/kickjs-graphql"]=t,o.graphql="^16.11.0"),e==="cqrs"&&(o["@forinda/kickjs-queue"]=t,o["@forinda/kickjs-ws"]=t,o["@forinda/kickjs-otel"]=t),e==="ddd"&&(o["@forinda/kickjs-swagger"]=t),JSON.stringify({name:r,version:t.replace("^",""),type:"module",scripts:{dev:"kick dev","dev:debug":"kick dev:debug",build:"kick build",start:"kick start",test:"vitest run","test:watch":"vitest",typecheck:"tsc --noEmit",lint:"eslint src/",format:"prettier --write src/"},dependencies:o,devDependencies:{"@forinda/kickjs-cli":t,"@swc/core":"^1.7.28","@types/express":"^5.0.6","@types/node":"^24.5.2","unplugin-swc":"^1.5.9",vite:"^7.3.1","vite-node":"^5.3.0",vitest:"^3.2.4",typescript:"^5.9.2",prettier:"^3.8.1"}},null,2)}s(ye,"generatePackageJson");function $e(){return`import { defineConfig } from 'vite'
|
|
1337
1390
|
import { resolve } from 'path'
|
|
1338
1391
|
import swc from 'unplugin-swc'
|
|
1339
1392
|
|
|
@@ -1359,7 +1412,7 @@ export default defineConfig({
|
|
|
1359
1412
|
},
|
|
1360
1413
|
},
|
|
1361
1414
|
})
|
|
1362
|
-
`
|
|
1415
|
+
`}s($e,"generateViteConfig");function he(){return JSON.stringify({compilerOptions:{target:"ES2022",module:"ESNext",moduleResolution:"bundler",lib:["ES2022"],types:["node","vite/client"],strict:!0,esModuleInterop:!0,skipLibCheck:!0,sourceMap:!0,declaration:!0,experimentalDecorators:!0,emitDecoratorMetadata:!0,outDir:"dist",rootDir:"src",paths:{"@/*":["./src/*"]}},include:["src"]},null,2)}s(he,"generateTsConfig");function ke(){return JSON.stringify({semi:!1,singleQuote:!0,trailingComma:"all",printWidth:100,tabWidth:2},null,2)}s(ke,"generatePrettierConfig");function ve(){return`# https://editorconfig.org
|
|
1363
1416
|
root = true
|
|
1364
1417
|
|
|
1365
1418
|
[*]
|
|
@@ -1372,13 +1425,13 @@ insert_final_newline = true
|
|
|
1372
1425
|
|
|
1373
1426
|
[*.md]
|
|
1374
1427
|
trim_trailing_whitespace = false
|
|
1375
|
-
`
|
|
1428
|
+
`}s(ve,"generateEditorConfig");function xe(){return`node_modules/
|
|
1376
1429
|
dist/
|
|
1377
1430
|
.env
|
|
1378
1431
|
coverage/
|
|
1379
1432
|
.DS_Store
|
|
1380
1433
|
*.tsbuildinfo
|
|
1381
|
-
`
|
|
1434
|
+
`}s(xe,"generateGitIgnore");function we(){return`# Auto-detect text files and normalise line endings to LF
|
|
1382
1435
|
* text=auto eol=lf
|
|
1383
1436
|
|
|
1384
1437
|
# Explicitly mark generated / binary files
|
|
@@ -1396,45 +1449,11 @@ coverage/
|
|
|
1396
1449
|
pnpm-lock.yaml -diff linguist-generated
|
|
1397
1450
|
yarn.lock -diff linguist-generated
|
|
1398
1451
|
package-lock.json -diff linguist-generated
|
|
1399
|
-
`
|
|
1452
|
+
`}s(we,"generateGitAttributes");function Ce(){return`PORT=3000
|
|
1400
1453
|
NODE_ENV=development
|
|
1401
|
-
`
|
|
1454
|
+
`}s(Ce,"generateEnv");function Re(){return`PORT=3000
|
|
1402
1455
|
NODE_ENV=development
|
|
1403
|
-
`
|
|
1404
|
-
|
|
1405
|
-
export const modules: AppModuleClass[] = []
|
|
1406
|
-
`),n==="graphql"&&await c($(s,"src/resolvers/.gitkeep"),""),await c($(s,"kick.config.ts"),`import { defineConfig } from '@forinda/kickjs-cli'
|
|
1407
|
-
|
|
1408
|
-
export default defineConfig({
|
|
1409
|
-
pattern: '${n}',
|
|
1410
|
-
modulesDir: 'src/modules',
|
|
1411
|
-
defaultRepo: 'inmemory',
|
|
1412
|
-
|
|
1413
|
-
commands: [
|
|
1414
|
-
{
|
|
1415
|
-
name: 'test',
|
|
1416
|
-
description: 'Run tests with Vitest',
|
|
1417
|
-
steps: 'npx vitest run',
|
|
1418
|
-
},
|
|
1419
|
-
{
|
|
1420
|
-
name: 'format',
|
|
1421
|
-
description: 'Format code with Prettier',
|
|
1422
|
-
steps: 'npx prettier --write src/',
|
|
1423
|
-
},
|
|
1424
|
-
{
|
|
1425
|
-
name: 'format:check',
|
|
1426
|
-
description: 'Check formatting without writing',
|
|
1427
|
-
steps: 'npx prettier --check src/',
|
|
1428
|
-
},
|
|
1429
|
-
{
|
|
1430
|
-
name: 'check',
|
|
1431
|
-
description: 'Run typecheck + format check',
|
|
1432
|
-
steps: ['npx tsc --noEmit', 'npx prettier --check src/'],
|
|
1433
|
-
aliases: ['verify', 'ci'],
|
|
1434
|
-
},
|
|
1435
|
-
],
|
|
1436
|
-
})
|
|
1437
|
-
`),await c($(s,"vitest.config.ts"),`import { defineConfig } from 'vitest/config'
|
|
1456
|
+
`}s(Re,"generateEnvExample");function be(){return`import { defineConfig } from 'vitest/config'
|
|
1438
1457
|
import swc from 'unplugin-swc'
|
|
1439
1458
|
|
|
1440
1459
|
export default defineConfig({
|
|
@@ -1445,12 +1464,7 @@ export default defineConfig({
|
|
|
1445
1464
|
include: ['src/**/*.test.ts'],
|
|
1446
1465
|
},
|
|
1447
1466
|
})
|
|
1448
|
-
`
|
|
1449
|
-
Installing dependencies with ${o}...
|
|
1450
|
-
`);try{_(`${o} install`,{cwd:s,stdio:"inherit"}),console.log(`
|
|
1451
|
-
Dependencies installed successfully!`)}catch{console.log(`
|
|
1452
|
-
Warning: ${o} install failed. Run it manually.`)}}console.log(`
|
|
1453
|
-
Project scaffolded successfully!`),console.log();let a=s!==process.cwd();console.log(" Next steps:"),a&&console.log(` cd ${t}`),e.installDeps||console.log(` ${o} install`);let d={rest:"kick g module user",graphql:"kick g resolver user",ddd:"kick g module user --repo drizzle",cqrs:"kick g module user --pattern cqrs",minimal:"# add your routes to src/index.ts"};console.log(` ${d[n]??d.rest}`),console.log(" kick dev"),console.log(),console.log(" Commands:"),console.log(" kick dev Start dev server with Vite HMR"),console.log(" kick build Production build via Vite"),console.log(" kick start Run production build"),console.log(),console.log(" Generators:"),console.log(" kick g module <name> Full DDD module (controller, DTOs, use-cases, repo)"),console.log(" kick g scaffold <n> <f..> CRUD module from field definitions"),console.log(" kick g controller <name> Standalone controller"),console.log(" kick g service <name> @Service() class"),console.log(" kick g middleware <name> Express middleware"),console.log(" kick g guard <name> Route guard (auth, roles, etc.)"),console.log(" kick g adapter <name> AppAdapter with lifecycle hooks"),console.log(" kick g dto <name> Zod DTO schema"),n==="graphql"&&console.log(" kick g resolver <name> GraphQL resolver"),n==="cqrs"&&console.log(" kick g job <name> Queue job processor"),console.log(" kick g config Generate kick.config.ts"),console.log(),console.log(" Add packages:"),console.log(" kick add <pkg> Install a KickJS package + peers"),console.log(" kick add --list Show all available packages"),console.log(),console.log(" Available: auth, swagger, graphql, drizzle, prisma, ws,"),console.log(" cron, queue, mailer, otel, multi-tenant, notifications, testing"),console.log()}i(We,"initProject");function be(e,t){switch(t){case"graphql":return`import 'reflect-metadata'
|
|
1467
|
+
`}s(be,"generateVitestConfig");function De(r,e,t){switch(e){case"graphql":return`import 'reflect-metadata'
|
|
1454
1468
|
import { bootstrap } from '@forinda/kickjs-http'
|
|
1455
1469
|
import { DevToolsAdapter } from '@forinda/kickjs-devtools'
|
|
1456
1470
|
import { GraphQLAdapter } from '@forinda/kickjs-graphql'
|
|
@@ -1482,10 +1496,10 @@ import { modules } from './modules'
|
|
|
1482
1496
|
bootstrap({
|
|
1483
1497
|
modules,
|
|
1484
1498
|
adapters: [
|
|
1485
|
-
new OtelAdapter({ serviceName: '${
|
|
1499
|
+
new OtelAdapter({ serviceName: '${r}' }),
|
|
1486
1500
|
new DevToolsAdapter(),
|
|
1487
1501
|
new SwaggerAdapter({
|
|
1488
|
-
info: { title: '${
|
|
1502
|
+
info: { title: '${r}', version: '${t}' },
|
|
1489
1503
|
}),
|
|
1490
1504
|
// Uncomment for WebSocket support:
|
|
1491
1505
|
// new WsAdapter(),
|
|
@@ -1511,18 +1525,55 @@ bootstrap({
|
|
|
1511
1525
|
adapters: [
|
|
1512
1526
|
new DevToolsAdapter(),
|
|
1513
1527
|
new SwaggerAdapter({
|
|
1514
|
-
info: { title: '${
|
|
1528
|
+
info: { title: '${r}', version: '${t}' },
|
|
1515
1529
|
}),
|
|
1516
1530
|
],
|
|
1517
1531
|
})
|
|
1518
|
-
`}}
|
|
1532
|
+
`}}s(De,"generateEntryFile");function Te(){return`import type { AppModuleClass } from '@forinda/kickjs-core'
|
|
1533
|
+
|
|
1534
|
+
export const modules: AppModuleClass[] = []
|
|
1535
|
+
`}s(Te,"generateModulesIndex");function Pe(r,e="inmemory"){return`import { defineConfig } from '@forinda/kickjs-cli'
|
|
1536
|
+
|
|
1537
|
+
export default defineConfig({
|
|
1538
|
+
pattern: '${r}',
|
|
1539
|
+
modules: {
|
|
1540
|
+
dir: 'src/modules',
|
|
1541
|
+
repo: '${e}',
|
|
1542
|
+
pluralize: true,
|
|
1543
|
+
},
|
|
1544
|
+
|
|
1545
|
+
commands: [
|
|
1546
|
+
{
|
|
1547
|
+
name: 'test',
|
|
1548
|
+
description: 'Run tests with Vitest',
|
|
1549
|
+
steps: 'npx vitest run',
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
name: 'format',
|
|
1553
|
+
description: 'Format code with Prettier',
|
|
1554
|
+
steps: 'npx prettier --write src/',
|
|
1555
|
+
},
|
|
1556
|
+
{
|
|
1557
|
+
name: 'format:check',
|
|
1558
|
+
description: 'Check formatting without writing',
|
|
1559
|
+
steps: 'npx prettier --check src/',
|
|
1560
|
+
},
|
|
1561
|
+
{
|
|
1562
|
+
name: 'check',
|
|
1563
|
+
description: 'Run typecheck + format check',
|
|
1564
|
+
steps: ['npx tsc --noEmit', 'npx prettier --check src/'],
|
|
1565
|
+
aliases: ['verify', 'ci'],
|
|
1566
|
+
},
|
|
1567
|
+
],
|
|
1568
|
+
})
|
|
1569
|
+
`}s(Pe,"generateKickConfig");function Oe(r,e,t){let o={rest:"REST API",graphql:"GraphQL API",ddd:"Domain-Driven Design",cqrs:"CQRS + Event-Driven",minimal:"Minimal"},i=["@forinda/kickjs-core","@forinda/kickjs-http","@forinda/kickjs-config"];return e!=="minimal"&&i.push("@forinda/kickjs-swagger","@forinda/kickjs-devtools"),e==="graphql"&&i.push("@forinda/kickjs-graphql"),e==="cqrs"&&i.push("@forinda/kickjs-queue","@forinda/kickjs-ws","@forinda/kickjs-otel"),`# ${r}
|
|
1519
1570
|
|
|
1520
|
-
A **${o[
|
|
1571
|
+
A **${o[e]??"REST API"}** built with [KickJS](https://forinda.github.io/kick-js/) \u2014 a decorator-driven Node.js framework on Express 5 and TypeScript.
|
|
1521
1572
|
|
|
1522
1573
|
## Getting Started
|
|
1523
1574
|
|
|
1524
1575
|
\`\`\`bash
|
|
1525
|
-
${
|
|
1576
|
+
${t} install
|
|
1526
1577
|
kick dev
|
|
1527
1578
|
\`\`\`
|
|
1528
1579
|
|
|
@@ -1533,7 +1584,7 @@ kick dev
|
|
|
1533
1584
|
| \`kick dev\` | Start dev server with Vite HMR |
|
|
1534
1585
|
| \`kick build\` | Production build |
|
|
1535
1586
|
| \`kick start\` | Run production build |
|
|
1536
|
-
| \`${
|
|
1587
|
+
| \`${t} run test\` | Run tests with Vitest |
|
|
1537
1588
|
| \`kick g module <name>\` | Generate a DDD module |
|
|
1538
1589
|
| \`kick g scaffold <name> <fields...>\` | Generate CRUD from field definitions |
|
|
1539
1590
|
| \`kick add <package>\` | Add a KickJS package |
|
|
@@ -1550,7 +1601,7 @@ src/
|
|
|
1550
1601
|
|
|
1551
1602
|
## Packages
|
|
1552
1603
|
|
|
1553
|
-
${
|
|
1604
|
+
${i.map(a=>`- \`${a}\``).join(`
|
|
1554
1605
|
`)}
|
|
1555
1606
|
|
|
1556
1607
|
## Adding Features
|
|
@@ -1578,4 +1629,556 @@ Copy \`.env.example\` to \`.env\` and configure:
|
|
|
1578
1629
|
|
|
1579
1630
|
- [KickJS Documentation](https://forinda.github.io/kick-js/)
|
|
1580
1631
|
- [CLI Reference](https://forinda.github.io/kick-js/api/cli.html)
|
|
1581
|
-
`}
|
|
1632
|
+
`}s(Oe,"generateReadme");function Ie(r,e,t){return`# CLAUDE.md \u2014 ${r} Development Guide
|
|
1633
|
+
|
|
1634
|
+
## Project Overview
|
|
1635
|
+
|
|
1636
|
+
This is a **${{rest:"REST API",graphql:"GraphQL API",ddd:"Domain-Driven Design",cqrs:"CQRS + Event-Driven",minimal:"Minimal Express"}[e]??"REST API"}** application built with [KickJS](https://forinda.github.io/kick-js/) \u2014 a decorator-driven Node.js framework on Express 5 and TypeScript.
|
|
1637
|
+
|
|
1638
|
+
## Quick Commands
|
|
1639
|
+
|
|
1640
|
+
\`\`\`bash
|
|
1641
|
+
${t} install # Install dependencies
|
|
1642
|
+
kick dev # Start dev server with HMR
|
|
1643
|
+
kick build # Production build via Vite
|
|
1644
|
+
kick start # Run production build
|
|
1645
|
+
${t} run test # Run tests with Vitest
|
|
1646
|
+
${t} run typecheck # TypeScript type checking
|
|
1647
|
+
${t} run format # Format code with Prettier
|
|
1648
|
+
\`\`\`
|
|
1649
|
+
|
|
1650
|
+
## Project Structure
|
|
1651
|
+
|
|
1652
|
+
\`\`\`
|
|
1653
|
+
src/
|
|
1654
|
+
\u251C\u2500\u2500 index.ts # Application bootstrap
|
|
1655
|
+
\u251C\u2500\u2500 modules/ # Feature modules (DDD/CQRS pattern)
|
|
1656
|
+
\u2502 \u2514\u2500\u2500 index.ts # Module registry
|
|
1657
|
+
${e==="graphql"?`\u251C\u2500\u2500 resolvers/ # GraphQL resolvers
|
|
1658
|
+
`:""}\u2514\u2500\u2500 ...
|
|
1659
|
+
\`\`\`
|
|
1660
|
+
|
|
1661
|
+
## Package Manager
|
|
1662
|
+
|
|
1663
|
+
- Always use **${t}** for this project
|
|
1664
|
+
- Run \`${t} install\` to sync dependencies
|
|
1665
|
+
- Never mix package managers (npm/yarn/pnpm)
|
|
1666
|
+
|
|
1667
|
+
## Code Style
|
|
1668
|
+
|
|
1669
|
+
- **Prettier** \u2014 no semicolons, single quotes, trailing commas, 100 char width
|
|
1670
|
+
- **TypeScript strict mode** \u2014 all types required
|
|
1671
|
+
- Format before committing: \`${t} run format\`
|
|
1672
|
+
- Type check with: \`${t} run typecheck\`
|
|
1673
|
+
|
|
1674
|
+
## Key Patterns
|
|
1675
|
+
|
|
1676
|
+
### Controllers
|
|
1677
|
+
|
|
1678
|
+
Use decorators to define routes:
|
|
1679
|
+
|
|
1680
|
+
\`\`\`ts
|
|
1681
|
+
import { Controller, Get, Post, RequestContext } from '@forinda/kickjs-http'
|
|
1682
|
+
|
|
1683
|
+
@Controller('/users')
|
|
1684
|
+
export class UserController {
|
|
1685
|
+
@Get('/')
|
|
1686
|
+
async findAll(ctx: RequestContext) {
|
|
1687
|
+
return ctx.json({ users: [] })
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
@Post('/')
|
|
1691
|
+
async create(ctx: RequestContext) {
|
|
1692
|
+
const data = ctx.body
|
|
1693
|
+
return ctx.created({ user: data })
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
\`\`\`
|
|
1697
|
+
|
|
1698
|
+
### Services
|
|
1699
|
+
|
|
1700
|
+
Inject dependencies with \`@Service()\` and \`@Autowired()\`:
|
|
1701
|
+
|
|
1702
|
+
\`\`\`ts
|
|
1703
|
+
import { Service, Autowired } from '@forinda/kickjs-core'
|
|
1704
|
+
|
|
1705
|
+
@Service()
|
|
1706
|
+
export class UserService {
|
|
1707
|
+
@Autowired()
|
|
1708
|
+
private userRepository!: UserRepository
|
|
1709
|
+
|
|
1710
|
+
async findAll() {
|
|
1711
|
+
return this.userRepository.findAll()
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
\`\`\`
|
|
1715
|
+
|
|
1716
|
+
### Modules
|
|
1717
|
+
|
|
1718
|
+
Register controllers and providers in modules:
|
|
1719
|
+
|
|
1720
|
+
\`\`\`ts
|
|
1721
|
+
import { Module } from '@forinda/kickjs-core'
|
|
1722
|
+
import { UserController } from './user.controller'
|
|
1723
|
+
import { UserService } from './user.service'
|
|
1724
|
+
|
|
1725
|
+
@Module({
|
|
1726
|
+
controllers: [UserController],
|
|
1727
|
+
providers: [UserService],
|
|
1728
|
+
})
|
|
1729
|
+
export class UserModule {}
|
|
1730
|
+
\`\`\`
|
|
1731
|
+
|
|
1732
|
+
### RequestContext
|
|
1733
|
+
|
|
1734
|
+
Every controller method receives \`ctx: RequestContext\`:
|
|
1735
|
+
|
|
1736
|
+
\`\`\`ts
|
|
1737
|
+
ctx.body // Request body (parsed JSON)
|
|
1738
|
+
ctx.params // Route params
|
|
1739
|
+
ctx.query // Query string
|
|
1740
|
+
ctx.headers // Request headers
|
|
1741
|
+
ctx.requestId // Auto-generated request ID
|
|
1742
|
+
ctx.session // Session data (if session middleware enabled)
|
|
1743
|
+
ctx.file // Uploaded file (single)
|
|
1744
|
+
ctx.files // Uploaded files (multiple)
|
|
1745
|
+
|
|
1746
|
+
// Pagination helpers
|
|
1747
|
+
ctx.qs(config) // Parse query with filters/sort/pagination
|
|
1748
|
+
ctx.paginate(handler) // Auto-paginated response
|
|
1749
|
+
|
|
1750
|
+
// Response helpers
|
|
1751
|
+
ctx.json(data) // 200 OK with JSON
|
|
1752
|
+
ctx.created(data) // 201 Created
|
|
1753
|
+
ctx.noContent() // 204 No Content
|
|
1754
|
+
ctx.notFound() // 404 Not Found
|
|
1755
|
+
ctx.badRequest(msg) // 400 Bad Request
|
|
1756
|
+
\`\`\`
|
|
1757
|
+
|
|
1758
|
+
## CLI Generators
|
|
1759
|
+
|
|
1760
|
+
Generate code with the \`kick\` CLI:
|
|
1761
|
+
|
|
1762
|
+
\`\`\`bash
|
|
1763
|
+
kick g module <name> # Full module (controller, service, DTOs, repo)
|
|
1764
|
+
kick g scaffold <name> <fields> # CRUD module from field definitions
|
|
1765
|
+
kick g controller <name> # Standalone controller
|
|
1766
|
+
kick g service <name> # Service class
|
|
1767
|
+
kick g middleware <name> # Express middleware
|
|
1768
|
+
kick g guard <name> # Route guard (auth, roles)
|
|
1769
|
+
kick g adapter <name> # AppAdapter with lifecycle hooks
|
|
1770
|
+
kick g dto <name> # Zod DTO schema
|
|
1771
|
+
${e==="graphql"?`kick g resolver <name> # GraphQL resolver
|
|
1772
|
+
`:""}${e==="cqrs"?`kick g job <name> # Queue job processor
|
|
1773
|
+
`:""}\`\`\`
|
|
1774
|
+
|
|
1775
|
+
## Adding Packages
|
|
1776
|
+
|
|
1777
|
+
\`\`\`bash
|
|
1778
|
+
kick add auth # JWT, API key, OAuth strategies
|
|
1779
|
+
kick add swagger # OpenAPI docs from decorators
|
|
1780
|
+
kick add ws # WebSocket support
|
|
1781
|
+
kick add queue # Background jobs (BullMQ/RabbitMQ/Kafka)
|
|
1782
|
+
kick add mailer # Email (SMTP, Resend, SES)
|
|
1783
|
+
kick add cron # Scheduled tasks
|
|
1784
|
+
kick add prisma # Prisma ORM adapter
|
|
1785
|
+
kick add drizzle # Drizzle ORM adapter
|
|
1786
|
+
kick add otel # OpenTelemetry tracing
|
|
1787
|
+
kick add --list # Show all available packages
|
|
1788
|
+
\`\`\`
|
|
1789
|
+
|
|
1790
|
+
## Environment Configuration
|
|
1791
|
+
|
|
1792
|
+
Edit \`.env\` for environment variables. Access them with \`@Value()\` decorator:
|
|
1793
|
+
|
|
1794
|
+
\`\`\`ts
|
|
1795
|
+
import { Value } from '@forinda/kickjs-config'
|
|
1796
|
+
|
|
1797
|
+
@Service()
|
|
1798
|
+
export class ApiService {
|
|
1799
|
+
@Value('API_KEY')
|
|
1800
|
+
private apiKey!: string
|
|
1801
|
+
|
|
1802
|
+
@Value('PORT', 3000) // With default
|
|
1803
|
+
private port!: number
|
|
1804
|
+
}
|
|
1805
|
+
\`\`\`
|
|
1806
|
+
|
|
1807
|
+
Or use \`ConfigService\`:
|
|
1808
|
+
|
|
1809
|
+
\`\`\`ts
|
|
1810
|
+
import { ConfigService } from '@forinda/kickjs-config'
|
|
1811
|
+
|
|
1812
|
+
@Service()
|
|
1813
|
+
export class AppService {
|
|
1814
|
+
@Autowired()
|
|
1815
|
+
private config!: ConfigService
|
|
1816
|
+
|
|
1817
|
+
getPort() {
|
|
1818
|
+
return this.config.get('PORT', 3000)
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
\`\`\`
|
|
1822
|
+
|
|
1823
|
+
## Testing
|
|
1824
|
+
|
|
1825
|
+
Tests live in \`src/**/*.test.ts\`:
|
|
1826
|
+
|
|
1827
|
+
\`\`\`ts
|
|
1828
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
1829
|
+
import { Container } from '@forinda/kickjs-core'
|
|
1830
|
+
import { createTestApp } from '@forinda/kickjs-testing'
|
|
1831
|
+
|
|
1832
|
+
describe('UserController', () => {
|
|
1833
|
+
beforeEach(() => Container.reset())
|
|
1834
|
+
|
|
1835
|
+
it('should return users', async () => {
|
|
1836
|
+
const app = await createTestApp([UserModule])
|
|
1837
|
+
const res = await app.get('/users')
|
|
1838
|
+
expect(res.status).toBe(200)
|
|
1839
|
+
})
|
|
1840
|
+
})
|
|
1841
|
+
\`\`\`
|
|
1842
|
+
|
|
1843
|
+
Run tests:
|
|
1844
|
+
- \`${t} run test\` \u2014 run all tests
|
|
1845
|
+
- \`${t} run test:watch\` \u2014 watch mode
|
|
1846
|
+
|
|
1847
|
+
## Decorators Reference
|
|
1848
|
+
|
|
1849
|
+
### Route Decorators
|
|
1850
|
+
- \`@Controller('/path')\` \u2014 define controller prefix
|
|
1851
|
+
- \`@Get('/'), @Post('/'), @Put('/'), @Delete('/'), @Patch('/')\` \u2014 HTTP methods
|
|
1852
|
+
- \`@Middleware(fn)\` \u2014 attach middleware
|
|
1853
|
+
- \`@Public()\` \u2014 skip authentication (requires @forinda/kickjs-auth)
|
|
1854
|
+
- \`@Roles('admin', 'user')\` \u2014 role-based access control
|
|
1855
|
+
|
|
1856
|
+
### DI Decorators
|
|
1857
|
+
- \`@Module({ controllers, providers, imports })\` \u2014 define module
|
|
1858
|
+
- \`@Service()\` \u2014 singleton service (DI-registered)
|
|
1859
|
+
- \`@Repository()\` \u2014 repository (semantic alias for @Service)
|
|
1860
|
+
- \`@Autowired()\` \u2014 property injection
|
|
1861
|
+
- \`@Inject('token')\` \u2014 token-based injection
|
|
1862
|
+
- \`@Value('ENV_VAR')\` \u2014 inject config value
|
|
1863
|
+
|
|
1864
|
+
${e==="cqrs"?"### CQRS/Event Decorators\n- `@Job('job-name')` \u2014 queue job handler\n- `@Process('queue-name')` \u2014 queue processor\n- `@Cron('0 * * * *')` \u2014 cron schedule\n- `@WsController('/path')` \u2014 WebSocket controller\n- `@Subscribe('event')` \u2014 WebSocket event handler\n\n":""}${e==="graphql"?"### GraphQL Decorators\n- `@Resolver()` \u2014 GraphQL resolver\n- `@Query()` \u2014 GraphQL query\n- `@Mutation()` \u2014 GraphQL mutation\n- `@Arg('name')` \u2014 resolver argument\n\n":""}## Common Pitfalls
|
|
1865
|
+
|
|
1866
|
+
1. **Decorators fire at import time** \u2014 make sure to import module classes in \`src/modules/index.ts\`
|
|
1867
|
+
2. **Tests need \`Container.reset()\`** \u2014 call in \`beforeEach\` to isolate DI state
|
|
1868
|
+
3. **Always use \`ctx.body\`** \u2014 never \`req.body\` directly
|
|
1869
|
+
4. **DI requires \`reflect-metadata\`** \u2014 already imported in \`src/index.ts\`
|
|
1870
|
+
5. **Vite HMR requires proper cleanup** \u2014 adapters should implement \`shutdown()\`
|
|
1871
|
+
|
|
1872
|
+
## Learn More
|
|
1873
|
+
|
|
1874
|
+
- [KickJS Documentation](https://forinda.github.io/kick-js/)
|
|
1875
|
+
- [API Reference](https://forinda.github.io/kick-js/api/)
|
|
1876
|
+
- [CLI Commands](https://forinda.github.io/kick-js/guide/cli-commands.html)
|
|
1877
|
+
- [Decorators Guide](https://forinda.github.io/kick-js/guide/decorators.html)
|
|
1878
|
+
`}s(Ie,"generateClaude");function Se(r,e,t){return`# AGENTS.md \u2014 AI Agent Guide for ${r}
|
|
1879
|
+
|
|
1880
|
+
This guide helps AI agents (Claude, Copilot, etc.) work effectively on this KickJS application.
|
|
1881
|
+
|
|
1882
|
+
## Before You Start
|
|
1883
|
+
|
|
1884
|
+
1. Read \`CLAUDE.md\` for project conventions and commands
|
|
1885
|
+
2. Run \`${t} install\` to install dependencies
|
|
1886
|
+
3. Run \`kick dev\` to verify the app starts
|
|
1887
|
+
4. Read the [KickJS documentation](https://forinda.github.io/kick-js/) for framework details
|
|
1888
|
+
|
|
1889
|
+
## Where to Find Things
|
|
1890
|
+
|
|
1891
|
+
### Application Structure
|
|
1892
|
+
|
|
1893
|
+
| What | Where |
|
|
1894
|
+
|------|-------|
|
|
1895
|
+
| Entry point | \`src/index.ts\` |
|
|
1896
|
+
| Module registry | \`src/modules/index.ts\` |
|
|
1897
|
+
| Feature modules | \`src/modules/<module-name>/\` |
|
|
1898
|
+
${e==="graphql"?"| GraphQL resolvers | `src/resolvers/` |\n":""}| Environment config | \`.env\` |
|
|
1899
|
+
| TypeScript config | \`tsconfig.json\` |
|
|
1900
|
+
| Vite config (HMR) | \`vite.config.ts\` |
|
|
1901
|
+
| Vitest config | \`vitest.config.ts\` |
|
|
1902
|
+
| Prettier config | \`.prettierrc\` |
|
|
1903
|
+
| CLI config | \`kick.config.ts\` |
|
|
1904
|
+
|
|
1905
|
+
### Module Pattern (${e.toUpperCase()})
|
|
1906
|
+
|
|
1907
|
+
Each module in \`src/modules/<name>/\` typically contains:
|
|
1908
|
+
|
|
1909
|
+
${e==="ddd"?`\`\`\`
|
|
1910
|
+
<name>/
|
|
1911
|
+
\u251C\u2500\u2500 <name>.controller.ts # HTTP routes (@Controller)
|
|
1912
|
+
\u251C\u2500\u2500 <name>.service.ts # Business logic (@Service)
|
|
1913
|
+
\u251C\u2500\u2500 <name>.repository.ts # Data access (@Repository)
|
|
1914
|
+
\u251C\u2500\u2500 <name>.dto.ts # Request/response schemas (Zod)
|
|
1915
|
+
\u251C\u2500\u2500 <name>.entity.ts # Domain entity (optional)
|
|
1916
|
+
\u2514\u2500\u2500 <name>.module.ts # Module definition (@Module)
|
|
1917
|
+
\`\`\`
|
|
1918
|
+
`:e==="cqrs"?`\`\`\`
|
|
1919
|
+
<name>/
|
|
1920
|
+
\u251C\u2500\u2500 commands/ # Write operations
|
|
1921
|
+
\u2502 \u251C\u2500\u2500 create-<name>.command.ts
|
|
1922
|
+
\u2502 \u2514\u2500\u2500 create-<name>.handler.ts
|
|
1923
|
+
\u251C\u2500\u2500 queries/ # Read operations
|
|
1924
|
+
\u2502 \u251C\u2500\u2500 get-<name>.query.ts
|
|
1925
|
+
\u2502 \u2514\u2500\u2500 get-<name>.handler.ts
|
|
1926
|
+
\u251C\u2500\u2500 events/ # Domain events
|
|
1927
|
+
\u2502 \u2514\u2500\u2500 <name>-created.event.ts
|
|
1928
|
+
\u251C\u2500\u2500 <name>.controller.ts # HTTP routes
|
|
1929
|
+
\u251C\u2500\u2500 <name>.repository.ts # Data access
|
|
1930
|
+
\u2514\u2500\u2500 <name>.module.ts # Module definition
|
|
1931
|
+
\`\`\`
|
|
1932
|
+
`:e==="graphql"?"```\nresolvers/\n\u251C\u2500\u2500 <name>.resolver.ts # @Resolver, @Query, @Mutation\n\u251C\u2500\u2500 <name>.types.ts # GraphQL type definitions\n\u2514\u2500\u2500 <name>.service.ts # Business logic\n```\n":e==="rest"?`\`\`\`
|
|
1933
|
+
<name>/
|
|
1934
|
+
\u251C\u2500\u2500 <name>.controller.ts # HTTP routes (@Controller)
|
|
1935
|
+
\u251C\u2500\u2500 <name>.service.ts # Business logic (@Service)
|
|
1936
|
+
\u251C\u2500\u2500 <name>.dto.ts # Request/response schemas (Zod)
|
|
1937
|
+
\u2514\u2500\u2500 <name>.module.ts # Module definition (@Module)
|
|
1938
|
+
\`\`\`
|
|
1939
|
+
`:"```\nsrc/\n\u251C\u2500\u2500 index.ts # Add routes here\n\u2514\u2500\u2500 ... # Custom structure\n```\n"}
|
|
1940
|
+
|
|
1941
|
+
## Checklist: Adding a Feature
|
|
1942
|
+
|
|
1943
|
+
### New Module (Recommended)
|
|
1944
|
+
|
|
1945
|
+
Use the CLI generator for consistency:
|
|
1946
|
+
|
|
1947
|
+
\`\`\`bash
|
|
1948
|
+
kick g module <name> # Generate full module
|
|
1949
|
+
# or
|
|
1950
|
+
kick g scaffold <name> <fields> # Generate CRUD from fields
|
|
1951
|
+
\`\`\`
|
|
1952
|
+
|
|
1953
|
+
Then:
|
|
1954
|
+
- [ ] Review generated files in \`src/modules/<name>/\`
|
|
1955
|
+
- [ ] Verify module is registered in \`src/modules/index.ts\`
|
|
1956
|
+
- [ ] Update DTOs in \`<name>.dto.ts\` if needed
|
|
1957
|
+
- [ ] Implement business logic in \`<name>.service.ts\`
|
|
1958
|
+
- [ ] Run \`kick dev\` to test with HMR
|
|
1959
|
+
- [ ] Write tests in \`<name>.test.ts\`
|
|
1960
|
+
|
|
1961
|
+
### Manual Controller
|
|
1962
|
+
|
|
1963
|
+
If not using generators:
|
|
1964
|
+
|
|
1965
|
+
- [ ] Create \`src/modules/<name>/<name>.controller.ts\`
|
|
1966
|
+
- [ ] Add \`@Controller('/path')\` decorator
|
|
1967
|
+
- [ ] Add route handlers with \`@Get()\`, \`@Post()\`, etc.
|
|
1968
|
+
- [ ] Create module file with \`@Module({ controllers: [NameController] })\`
|
|
1969
|
+
- [ ] Register module in \`src/modules/index.ts\`
|
|
1970
|
+
- [ ] Test with \`kick dev\`
|
|
1971
|
+
|
|
1972
|
+
### Manual Service
|
|
1973
|
+
|
|
1974
|
+
- [ ] Create \`src/modules/<name>/<name>.service.ts\`
|
|
1975
|
+
- [ ] Add \`@Service()\` decorator
|
|
1976
|
+
- [ ] Inject dependencies with \`@Autowired()\`
|
|
1977
|
+
- [ ] Register in module \`providers\` array
|
|
1978
|
+
- [ ] Write unit tests
|
|
1979
|
+
|
|
1980
|
+
### New Middleware
|
|
1981
|
+
|
|
1982
|
+
- [ ] Create \`src/middleware/<name>.middleware.ts\`
|
|
1983
|
+
- [ ] Export middleware function (Express format)
|
|
1984
|
+
- [ ] Register in \`src/index.ts\` or attach to routes with \`@Middleware()\`
|
|
1985
|
+
- [ ] Test with sample requests
|
|
1986
|
+
|
|
1987
|
+
### Adding a Package
|
|
1988
|
+
|
|
1989
|
+
Use \`kick add\` to install KickJS packages with correct peer dependencies:
|
|
1990
|
+
|
|
1991
|
+
- [ ] Run \`kick add <package>\` (e.g., \`kick add auth\`)
|
|
1992
|
+
- [ ] Follow package-specific setup in terminal output
|
|
1993
|
+
- [ ] Update \`src/index.ts\` to register adapter (if needed)
|
|
1994
|
+
- [ ] Configure environment variables in \`.env\`
|
|
1995
|
+
- [ ] Test integration with \`kick dev\`
|
|
1996
|
+
|
|
1997
|
+
## Common Tasks
|
|
1998
|
+
|
|
1999
|
+
### Generate CRUD Module
|
|
2000
|
+
|
|
2001
|
+
\`\`\`bash
|
|
2002
|
+
kick g scaffold user name:string email:string age:number
|
|
2003
|
+
\`\`\`
|
|
2004
|
+
|
|
2005
|
+
This creates a full CRUD module with:
|
|
2006
|
+
- Controller with GET, POST, PUT, DELETE routes
|
|
2007
|
+
- Service with business logic
|
|
2008
|
+
- Repository with data access
|
|
2009
|
+
- DTOs with Zod validation
|
|
2010
|
+
|
|
2011
|
+
### Add Authentication
|
|
2012
|
+
|
|
2013
|
+
\`\`\`bash
|
|
2014
|
+
kick add auth
|
|
2015
|
+
\`\`\`
|
|
2016
|
+
|
|
2017
|
+
Then configure in \`src/index.ts\`:
|
|
2018
|
+
|
|
2019
|
+
\`\`\`ts
|
|
2020
|
+
import { AuthAdapter, JwtStrategy } from '@forinda/kickjs-auth'
|
|
2021
|
+
|
|
2022
|
+
bootstrap({
|
|
2023
|
+
modules,
|
|
2024
|
+
adapters: [
|
|
2025
|
+
new AuthAdapter({
|
|
2026
|
+
strategies: [new JwtStrategy({ secret: process.env.JWT_SECRET! })],
|
|
2027
|
+
}),
|
|
2028
|
+
],
|
|
2029
|
+
})
|
|
2030
|
+
\`\`\`
|
|
2031
|
+
|
|
2032
|
+
### Add Database (Prisma)
|
|
2033
|
+
|
|
2034
|
+
\`\`\`bash
|
|
2035
|
+
kick add prisma
|
|
2036
|
+
${t} install prisma @prisma/client
|
|
2037
|
+
npx prisma init
|
|
2038
|
+
# Edit prisma/schema.prisma
|
|
2039
|
+
npx prisma migrate dev --name init
|
|
2040
|
+
kick g module user --repo prisma
|
|
2041
|
+
\`\`\`
|
|
2042
|
+
|
|
2043
|
+
### Add WebSocket Support
|
|
2044
|
+
|
|
2045
|
+
\`\`\`bash
|
|
2046
|
+
kick add ws
|
|
2047
|
+
\`\`\`
|
|
2048
|
+
|
|
2049
|
+
Then add adapter in \`src/index.ts\`:
|
|
2050
|
+
|
|
2051
|
+
\`\`\`ts
|
|
2052
|
+
import { WsAdapter } from '@forinda/kickjs-ws'
|
|
2053
|
+
|
|
2054
|
+
bootstrap({
|
|
2055
|
+
modules,
|
|
2056
|
+
adapters: [new WsAdapter()],
|
|
2057
|
+
})
|
|
2058
|
+
\`\`\`
|
|
2059
|
+
|
|
2060
|
+
Create WebSocket controller:
|
|
2061
|
+
|
|
2062
|
+
\`\`\`bash
|
|
2063
|
+
kick g controller chat --ws
|
|
2064
|
+
\`\`\`
|
|
2065
|
+
|
|
2066
|
+
## Testing Guidelines
|
|
2067
|
+
|
|
2068
|
+
All tests use Vitest:
|
|
2069
|
+
|
|
2070
|
+
\`\`\`ts
|
|
2071
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2072
|
+
import { Container } from '@forinda/kickjs-core'
|
|
2073
|
+
import { createTestApp } from '@forinda/kickjs-testing'
|
|
2074
|
+
|
|
2075
|
+
describe('UserController', () => {
|
|
2076
|
+
beforeEach(() => {
|
|
2077
|
+
Container.reset() // Important: isolate DI state
|
|
2078
|
+
})
|
|
2079
|
+
|
|
2080
|
+
it('should return users', async () => {
|
|
2081
|
+
const app = await createTestApp([UserModule])
|
|
2082
|
+
const res = await app.get('/users')
|
|
2083
|
+
|
|
2084
|
+
expect(res.status).toBe(200)
|
|
2085
|
+
expect(res.body).toHaveProperty('users')
|
|
2086
|
+
})
|
|
2087
|
+
})
|
|
2088
|
+
\`\`\`
|
|
2089
|
+
|
|
2090
|
+
Run tests:
|
|
2091
|
+
- \`${t} run test\` \u2014 run all tests once
|
|
2092
|
+
- \`${t} run test:watch\` \u2014 watch mode
|
|
2093
|
+
- Individual file: \`${t} run test src/modules/user/user.test.ts\`
|
|
2094
|
+
|
|
2095
|
+
## Environment Variables
|
|
2096
|
+
|
|
2097
|
+
Managed via \`.env\` file. Access with:
|
|
2098
|
+
|
|
2099
|
+
1. **@Value() decorator** (recommended):
|
|
2100
|
+
\`\`\`ts
|
|
2101
|
+
@Value('DATABASE_URL')
|
|
2102
|
+
private dbUrl!: string
|
|
2103
|
+
\`\`\`
|
|
2104
|
+
|
|
2105
|
+
2. **ConfigService** (for dynamic access):
|
|
2106
|
+
\`\`\`ts
|
|
2107
|
+
@Autowired()
|
|
2108
|
+
private config!: ConfigService
|
|
2109
|
+
|
|
2110
|
+
const port = this.config.get('PORT', 3000)
|
|
2111
|
+
\`\`\`
|
|
2112
|
+
|
|
2113
|
+
3. **Direct access** (avoid in app code):
|
|
2114
|
+
\`\`\`ts
|
|
2115
|
+
process.env.PORT
|
|
2116
|
+
\`\`\`
|
|
2117
|
+
|
|
2118
|
+
## Key Decorators
|
|
2119
|
+
|
|
2120
|
+
### HTTP Routes
|
|
2121
|
+
| Decorator | Purpose |
|
|
2122
|
+
|-----------|---------|
|
|
2123
|
+
| \`@Controller('/path')\` | Define route prefix |
|
|
2124
|
+
| \`@Get('/'), @Post('/')\` | HTTP method handlers |
|
|
2125
|
+
| \`@Middleware(fn)\` | Attach middleware |
|
|
2126
|
+
| \`@Public()\` | Skip auth (requires auth adapter) |
|
|
2127
|
+
| \`@Roles('admin')\` | Role-based access |
|
|
2128
|
+
|
|
2129
|
+
### Dependency Injection
|
|
2130
|
+
| Decorator | Purpose |
|
|
2131
|
+
|-----------|---------|
|
|
2132
|
+
| \`@Module({})\` | Define feature module |
|
|
2133
|
+
| \`@Service()\` | Register singleton service |
|
|
2134
|
+
| \`@Repository()\` | Register repository |
|
|
2135
|
+
| \`@Autowired()\` | Property injection |
|
|
2136
|
+
| \`@Inject('token')\` | Token-based injection |
|
|
2137
|
+
| \`@Value('VAR')\` | Inject env variable |
|
|
2138
|
+
|
|
2139
|
+
${e==="graphql"?"### GraphQL\n| Decorator | Purpose |\n|-----------|---------|\n| `@Resolver()` | GraphQL resolver class |\n| `@Query()` | Query handler |\n| `@Mutation()` | Mutation handler |\n| `@Arg('name')` | Resolver argument |\n\n":""}${e==="cqrs"?"### Background Jobs\n| Decorator | Purpose |\n|-----------|---------|\n| `@Job('name')` | Queue job handler |\n| `@Process('queue')` | Queue processor |\n| `@Cron('0 * * * *')` | Cron schedule |\n| `@WsController()` | WebSocket controller |\n\n":""}## Common Pitfalls
|
|
2140
|
+
|
|
2141
|
+
1. **Forgot to register module** \u2014 Add to \`src/modules/index.ts\` exports array
|
|
2142
|
+
2. **DI not working** \u2014 Ensure \`reflect-metadata\` is imported in \`src/index.ts\`
|
|
2143
|
+
3. **Tests failing randomly** \u2014 Missing \`Container.reset()\` in \`beforeEach\`
|
|
2144
|
+
4. **Routes not found** \u2014 Check controller path and module registration
|
|
2145
|
+
5. **HMR not working** \u2014 Verify \`vite.config.ts\` has \`hmr: true\`
|
|
2146
|
+
6. **Decorators not working** \u2014 Check \`tsconfig.json\` has \`experimentalDecorators: true\`
|
|
2147
|
+
|
|
2148
|
+
## CLI Commands Reference
|
|
2149
|
+
|
|
2150
|
+
| Command | Description |
|
|
2151
|
+
|---------|-------------|
|
|
2152
|
+
| \`kick dev\` | Dev server with HMR |
|
|
2153
|
+
| \`kick dev:debug\` | Dev server with debugger |
|
|
2154
|
+
| \`kick build\` | Production build |
|
|
2155
|
+
| \`kick start\` | Run production build |
|
|
2156
|
+
| \`kick g module <names...>\` | Generate one or more modules |
|
|
2157
|
+
| \`kick g scaffold <name> <fields>\` | Generate CRUD |
|
|
2158
|
+
| \`kick g controller <name>\` | Generate controller |
|
|
2159
|
+
| \`kick g service <name>\` | Generate service |
|
|
2160
|
+
| \`kick g middleware <name>\` | Generate middleware |
|
|
2161
|
+
| \`kick add <package>\` | Add KickJS package |
|
|
2162
|
+
| \`kick add --list\` | List available packages |
|
|
2163
|
+
| \`kick rm module <names...>\` | Remove one or more modules |
|
|
2164
|
+
|
|
2165
|
+
> **Note:** When using \`kick new\` in scripts or CI, pass \`-t\` (or \`--template\`) and \`-r\` (or \`--repo\`) flags to bypass interactive prompts:
|
|
2166
|
+
> \`\`\`bash
|
|
2167
|
+
> kick new my-api -t ddd -r prisma --pm ${t} --no-git --no-install -f
|
|
2168
|
+
> \`\`\`
|
|
2169
|
+
|
|
2170
|
+
## Learn More
|
|
2171
|
+
|
|
2172
|
+
- [KickJS Docs](https://forinda.github.io/kick-js/)
|
|
2173
|
+
- [CLI Reference](https://forinda.github.io/kick-js/api/cli.html)
|
|
2174
|
+
- [Decorators Guide](https://forinda.github.io/kick-js/guide/decorators.html)
|
|
2175
|
+
- [DI System](https://forinda.github.io/kick-js/guide/dependency-injection.html)
|
|
2176
|
+
- [Testing](https://forinda.github.io/kick-js/api/testing.html)
|
|
2177
|
+
`}s(Se,"generateAgents");var ut=dt(mt(import.meta.url)),Ae=JSON.parse(lt(g(ut,"..","package.json"),"utf-8")),ft=`^${Ae.version}`;async function gt(r){let{name:e,directory:t,packageManager:o="pnpm",template:i="rest",defaultRepo:a="inmemory"}=r,c=t,n=s(m=>console.log(` ${m}`),"log");if(console.log(`
|
|
2178
|
+
Creating KickJS project: ${e}
|
|
2179
|
+
`),await l(g(c,"package.json"),ye(e,i,ft)),await l(g(c,"vite.config.ts"),$e()),await l(g(c,"tsconfig.json"),he()),await l(g(c,".prettierrc"),ke()),await l(g(c,".editorconfig"),ve()),await l(g(c,".gitignore"),xe()),await l(g(c,".gitattributes"),we()),await l(g(c,".env"),Ce()),await l(g(c,".env.example"),Re()),await l(g(c,"src/index.ts"),De(e,i,Ae.version)),await l(g(c,"src/modules/index.ts"),Te()),i==="graphql"&&await l(g(c,"src/resolvers/.gitkeep"),""),await l(g(c,"kick.config.ts"),Pe(i,a)),await l(g(c,"vitest.config.ts"),be()),await l(g(c,"README.md"),Oe(e,i,o)),await l(g(c,"CLAUDE.md"),Ie(e,i,o)),await l(g(c,"AGENTS.md"),Se(e,i,o)),r.initGit)try{M("git init",{cwd:c,stdio:"pipe"}),M("git branch -M main",{cwd:c,stdio:"pipe"}),M("git add -A",{cwd:c,stdio:"pipe"}),M('git commit -m "chore: initial commit from kick new"',{cwd:c,stdio:"pipe"}),n("Git repository initialized")}catch{n("Warning: git init failed (git may not be installed)")}if(r.installDeps){console.log(`
|
|
2180
|
+
Installing dependencies with ${o}...
|
|
2181
|
+
`);try{M(`${o} install`,{cwd:c,stdio:"inherit"}),console.log(`
|
|
2182
|
+
Dependencies installed successfully!`)}catch{console.log(`
|
|
2183
|
+
Warning: ${o} install failed. Run it manually.`)}}console.log(`
|
|
2184
|
+
Project scaffolded successfully!`),console.log();let p=c!==process.cwd();n("Next steps:"),p&&n(` cd ${e}`),r.installDeps||n(` ${o} install`);let d={rest:"kick g module user",graphql:"kick g resolver user",ddd:"kick g module user --repo drizzle",cqrs:"kick g module user --pattern cqrs",minimal:"# add your routes to src/index.ts"};n(` ${d[i]??d.rest}`),n(" kick dev"),n(""),n("Commands:"),n(" kick dev Start dev server with Vite HMR"),n(" kick build Production build via Vite"),n(" kick start Run production build"),n(""),n("Generators:"),n(" kick g module <name> Full DDD module (controller, DTOs, use-cases, repo)"),n(" kick g scaffold <n> <f..> CRUD module from field definitions"),n(" kick g controller <name> Standalone controller"),n(" kick g service <name> @Service() class"),n(" kick g middleware <name> Express middleware"),n(" kick g guard <name> Route guard (auth, roles, etc.)"),n(" kick g adapter <name> AppAdapter with lifecycle hooks"),n(" kick g dto <name> Zod DTO schema"),i==="graphql"&&n(" kick g resolver <name> GraphQL resolver"),i==="cqrs"&&n(" kick g job <name> Queue job processor"),n(" kick g config Generate kick.config.ts"),n(""),n("Add packages:"),n(" kick add <pkg> Install a KickJS package + peers"),n(" kick add --list Show all available packages"),n(""),n("Available: auth, swagger, graphql, drizzle, prisma, ws,"),n(" cron, queue, mailer, otel, multi-tenant, notifications, testing"),n("")}s(gt,"initProject");import{readFile as yt,access as $t}from"fs/promises";import{join as ht}from"path";function kt(r){return r}s(kt,"defineConfig");var vt=["kick.config.ts","kick.config.js","kick.config.mjs","kick.config.json"];async function xt(r){for(let e of vt){let t=ht(r,e);try{await $t(t)}catch{continue}if(e.endsWith(".json")){let o=await yt(t,"utf-8");return JSON.parse(o)}try{let{pathToFileURL:o}=await import("url"),i=await import(o(t).href);return i.default??i}catch{e.endsWith(".ts")&&console.warn(`Warning: Failed to load ${e}. TypeScript config files require a runtime loader (e.g. tsx, ts-node) or use kick.config.js/.mjs instead.`);continue}}return null}s(xt,"loadKickConfig");export{kt as defineConfig,Je as generateAdapter,nt as generateController,pt as generateDto,ot as generateGuard,tt as generateMiddleware,Ke as generateModule,it as generateService,gt as initProject,xt as loadKickConfig,E as pluralize,w as toCamelCase,u as toKebabCase,f as toPascalCase};
|