@forinda/kickjs-cli 5.11.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/agent-docs-Dmku65k2.mjs +12 -0
  2. package/dist/agent-docs-Dmku65k2.mjs.map +1 -0
  3. package/dist/{builtins-BL1BhYEv.mjs → builtins-G49e_Qsj.mjs} +2 -2
  4. package/dist/cli.mjs +151 -1376
  5. package/dist/config-DdtRfl33.mjs +13 -0
  6. package/dist/config-DdtRfl33.mjs.map +1 -0
  7. package/dist/doctor-SUUDEI1J.mjs +1221 -0
  8. package/dist/doctor-SUUDEI1J.mjs.map +1 -0
  9. package/dist/index.d.mts +663 -853
  10. package/dist/index.d.mts.map +1 -1
  11. package/dist/index.mjs +2 -2
  12. package/dist/{plugin-C4hfxiPw.mjs → plugin-Dg0Lk2Lp.mjs} +3 -3
  13. package/dist/{plugin-C4hfxiPw.mjs.map → plugin-Dg0Lk2Lp.mjs.map} +1 -1
  14. package/dist/{project-docs-CfB-KVN5.mjs → project-docs-C-dA6-TO.mjs} +6 -36
  15. package/dist/project-docs-C-dA6-TO.mjs.map +1 -0
  16. package/dist/{project-root-CDYKLnfG.mjs → project-root-so4F5DRN.mjs} +3 -3
  17. package/dist/{project-root-CDYKLnfG.mjs.map → project-root-so4F5DRN.mjs.map} +1 -1
  18. package/dist/{rolldown-runtime-CeWwRE8g.mjs → rolldown-runtime-DrKbExWn.mjs} +1 -1
  19. package/dist/run-plugins-B2_AT35s.mjs +636 -0
  20. package/dist/run-plugins-B2_AT35s.mjs.map +1 -0
  21. package/dist/typegen-5MX2F5iL.mjs +114 -0
  22. package/dist/typegen-5MX2F5iL.mjs.map +1 -0
  23. package/dist/types-C5PH0h7Z.mjs +11 -0
  24. package/package.json +13 -13
  25. package/dist/agent-docs-CXqrGZLl.mjs +0 -12
  26. package/dist/agent-docs-CXqrGZLl.mjs.map +0 -1
  27. package/dist/config-Cf8GU8CG.mjs +0 -13
  28. package/dist/config-Cf8GU8CG.mjs.map +0 -1
  29. package/dist/doctor-Dl709LzL.mjs +0 -2076
  30. package/dist/doctor-Dl709LzL.mjs.map +0 -1
  31. package/dist/project-docs-CfB-KVN5.mjs.map +0 -1
  32. package/dist/run-plugins-M_WVt-7a.mjs +0 -976
  33. package/dist/run-plugins-M_WVt-7a.mjs.map +0 -1
  34. package/dist/typegen-CezcLjMb.mjs +0 -114
  35. package/dist/typegen-CezcLjMb.mjs.map +0 -1
  36. package/dist/types-DvYczI2m.mjs +0 -12
  37. package/dist/types-DvYczI2m.mjs.map +0 -1
@@ -0,0 +1,1221 @@
1
+ /**
2
+ * @forinda/kickjs-cli v6.0.0
3
+ *
4
+ * Copyright (c) Felix Orinda
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import{b as e,c as t,d as n,g as r,l as i,o as a,s as o,v as s}from"./project-docs-C-dA6-TO.mjs";import{i as c}from"./config-DdtRfl33.mjs";import{t as l}from"./project-root-so4F5DRN.mjs";import{createRequire as u}from"node:module";import{dirname as d,join as f,relative as p,resolve as m}from"node:path";import{existsSync as h,readFileSync as g,readdirSync as _,statSync as v}from"node:fs";import{readFile as y,writeFile as b}from"node:fs/promises";import x from"pluralize";import{execFileSync as S,execSync as C}from"node:child_process";import{fileURLToPath as ee,pathToFileURL as te}from"node:url";import{defineGenerator as ne}from"@forinda/kickjs-cli-kit";function w(e){return e.replace(/[-_\s]+(.)?/g,(e,t)=>t?t.toUpperCase():``).replace(/^(.)/,e=>e.toUpperCase())}function T(e){let t=w(e);return t.charAt(0).toLowerCase()+t.slice(1)}function E(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/[\s_]+/g,`-`).toLowerCase()}function D(e){return x.plural(e)}function O(e){return x.plural(e)}function k(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function re(e){return e.charAt(0).toUpperCase()+e.slice(1).replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function ie(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).toLowerCase()}function ae(e,t,n){let r={inmemory:`InMemory${e}Repository`,drizzle:`Drizzle${e}Repository`,prisma:`Prisma${e}Repository`},i={inmemory:`in-memory-${t}`,drizzle:`drizzle-${t}`,prisma:`prisma-${t}`};return{repoClass:r[n]??`${re(n)}${e}Repository`,repoFile:i[n]??`${ie(n)}-${t}`}}function A(e){return e??`define`}function j(e){let{pascal:t,kebab:n,plural:r=``,repo:i,style:a}=e,{repoClass:o,repoFile:s}=ae(t,n,i),c=A(a),l=`/**
12
+ * ${t} Module
13
+ *
14
+ * REST module with a flat folder structure.
15
+ * Controller delegates to service, service wraps the repository.
16
+ *
17
+ * Structure:
18
+ * ${n}.controller.ts — HTTP routes (CRUD)
19
+ * ${n}.service.ts — Business logic
20
+ * ${n}.repository.ts — Repository interface
21
+ * ${s}.repository.ts — Repository implementation
22
+ * dtos/ — Request/response schemas
23
+ */`,u=`import { ${t.toUpperCase()}_REPOSITORY } from './${n}.repository'
24
+ import { ${o} } from './${s}.repository'
25
+ import { ${t}Controller } from './${n}.controller'
26
+
27
+ // Eagerly load decorated classes so @Service()/@Repository() decorators register in the DI container
28
+ import.meta.glob(['./**/*.service.ts', './**/*.repository.ts', '!./**/*.test.ts'], { eager: true })`,d=` /**
29
+ * Declare HTTP routes for this module. Return value shape:
30
+ *
31
+ * - \`path\` — URL prefix for this route set.
32
+ * - \`controller\` — Controller class (also drives OpenAPI).
33
+ * - \`version\` — Optional. Overrides the app-wide API version.
34
+ *
35
+ * Return an **array** to mount multiple route sets — admin
36
+ * surfaces, side-by-side v1 + v2 controllers, etc:
37
+ *
38
+ * return [
39
+ * { path: '/${r}', version: 1, controller: ${t}V1Controller },
40
+ * { path: '/${r}', version: 2, controller: ${t}V2Controller },
41
+ * ]
42
+ */`;return c===`class`?`${l}
43
+ import { Container, type AppModule, type ModuleRoutes } from '@forinda/kickjs'
44
+ ${u}
45
+
46
+ export class ${t}Module implements AppModule {
47
+ register(container: Container): void {
48
+ container.registerFactory(${t.toUpperCase()}_REPOSITORY, () =>
49
+ container.resolve(${o}),
50
+ )
51
+ }
52
+
53
+ ${d.replace(/^ {4}/gm,` `).replace(/^ {6}/gm,` `)}
54
+ routes(): ModuleRoutes {
55
+ return {
56
+ path: '/${r}',
57
+ controller: ${t}Controller,
58
+ }
59
+ }
60
+ }
61
+ `:`${l}
62
+ import { defineModule } from '@forinda/kickjs'
63
+ ${u}
64
+
65
+ export const ${t}Module = defineModule({
66
+ name: '${t}Module',
67
+ build: () => ({
68
+ register(container) {
69
+ container.registerFactory(${t.toUpperCase()}_REPOSITORY, () =>
70
+ container.resolve(${o}),
71
+ )
72
+ },
73
+
74
+ ${d}
75
+ routes() {
76
+ return {
77
+ path: '/${r}',
78
+ controller: ${t}Controller,
79
+ }
80
+ },
81
+ }),
82
+ })
83
+ `}function oe(e){let{pascal:t,kebab:n,plural:r=``,style:i}=e,a=A(i),o=` /**
84
+ * Declare HTTP routes. Return value shape:
85
+ *
86
+ * - \`path\` — URL prefix for this route set.
87
+ * - \`controller\` — Controller class (also drives OpenAPI).
88
+ * - \`version\` — Optional. Overrides the app-wide API version.
89
+ *
90
+ * Return an array to mount multiple route sets:
91
+ *
92
+ * return [
93
+ * { path: '/${r}', version: 1, controller: ${t}V1Controller },
94
+ * { path: '/${r}', version: 2, controller: ${t}V2Controller },
95
+ * ]
96
+ */`;return a===`class`?`import { type AppModule, type ModuleRoutes } from '@forinda/kickjs'
97
+ import { ${t}Controller } from './${n}.controller'
98
+
99
+ export class ${t}Module implements AppModule {
100
+ ${o.replace(/^ {4}/gm,` `).replace(/^ {6}/gm,` `)}
101
+ routes(): ModuleRoutes {
102
+ return {
103
+ path: '/${r}',
104
+ controller: ${t}Controller,
105
+ }
106
+ }
107
+ }
108
+ `:`import { defineModule } from '@forinda/kickjs'
109
+ import { ${t}Controller } from './${n}.controller'
110
+
111
+ export const ${t}Module = defineModule({
112
+ name: '${t}Module',
113
+ build: () => ({
114
+ ${o}
115
+ routes() {
116
+ return {
117
+ path: '/${r}',
118
+ controller: ${t}Controller,
119
+ }
120
+ },
121
+ }),
122
+ })
123
+ `}function M(e){let{pascal:t,kebab:n}=e,r=t.charAt(0).toLowerCase()+t.slice(1);return`import { Controller, Get, Post, Put, Delete, Autowired, ApiQueryParams, type Ctx } from '@forinda/kickjs'
124
+ import { ApiTags } from '@forinda/kickjs-swagger'
125
+ import { ${t}Service } from './${n}.service'
126
+ import { create${t}Schema } from './dtos/create-${n}.dto'
127
+ import { update${t}Schema } from './dtos/update-${n}.dto'
128
+ import { ${t.toUpperCase()}_QUERY_CONFIG } from './${n}.constants'
129
+
130
+ // Each handler annotates its \`ctx\` with \`Ctx<KickRoutes.${t}Controller['<method>']>\`
131
+ // so \`ctx.params\`, \`ctx.body\`, and \`ctx.query\` are typed end-to-end.
132
+ // The \`KickRoutes\` namespace is generated by \`kick typegen\` (auto-run on
133
+ // \`kick dev\`) — see https://forinda.github.io/kick-js/guide/typegen.
134
+
135
+ @Controller()
136
+ export class ${t}Controller {
137
+ @Autowired() private readonly ${r}Service!: ${t}Service
138
+
139
+ @Get('/')
140
+ @ApiTags('${t}')
141
+ @ApiQueryParams(${t.toUpperCase()}_QUERY_CONFIG)
142
+ async list(ctx: Ctx<KickRoutes.${t}Controller['list']>) {
143
+ return ctx.paginate(
144
+ (parsed) => this.${r}Service.findPaginated(parsed),
145
+ ${t.toUpperCase()}_QUERY_CONFIG,
146
+ )
147
+ }
148
+
149
+ @Get('/:id')
150
+ @ApiTags('${t}')
151
+ async getById(ctx: Ctx<KickRoutes.${t}Controller['getById']>) {
152
+ const result = await this.${r}Service.findById(ctx.params.id)
153
+ if (!result) return ctx.notFound('${t} not found')
154
+ ctx.json(result)
155
+ }
156
+
157
+ @Post('/', { body: create${t}Schema, name: 'Create${t}' })
158
+ @ApiTags('${t}')
159
+ async create(ctx: Ctx<KickRoutes.${t}Controller['create']>) {
160
+ const result = await this.${r}Service.create(ctx.body)
161
+ ctx.created(result)
162
+ }
163
+
164
+ @Put('/:id', { body: update${t}Schema, name: 'Update${t}' })
165
+ @ApiTags('${t}')
166
+ async update(ctx: Ctx<KickRoutes.${t}Controller['update']>) {
167
+ const result = await this.${r}Service.update(ctx.params.id, ctx.body)
168
+ ctx.json(result)
169
+ }
170
+
171
+ @Delete('/:id')
172
+ @ApiTags('${t}')
173
+ async remove(ctx: Ctx<KickRoutes.${t}Controller['remove']>) {
174
+ await this.${r}Service.delete(ctx.params.id)
175
+ ctx.noContent()
176
+ }
177
+ }
178
+ `}function se(e){let{pascal:t}=e;return`import { z } from 'zod'
179
+
180
+ /**
181
+ * Create ${t} DTO — Zod schema for validating POST request bodies.
182
+ * This schema is passed to @Post('/', { body: create${t}Schema }) for automatic validation.
183
+ * It also generates OpenAPI request body docs when SwaggerAdapter is used.
184
+ *
185
+ * Add more fields as needed. Supported Zod types:
186
+ * z.string(), z.number(), z.boolean(), z.enum([...]),
187
+ * z.array(), z.object(), .optional(), .default(), .transform()
188
+ */
189
+ export const create${t}Schema = z.object({
190
+ name: z.string().min(1, 'Name is required').max(200),
191
+ })
192
+
193
+ export type Create${t}DTO = z.infer<typeof create${t}Schema>
194
+ `}function ce(e){let{pascal:t}=e;return`import { z } from 'zod'
195
+
196
+ export const update${t}Schema = z.object({
197
+ name: z.string().min(1).max(200).optional(),
198
+ })
199
+
200
+ export type Update${t}DTO = z.infer<typeof update${t}Schema>
201
+ `}function le(e){let{pascal:t}=e;return`export interface ${t}ResponseDTO {
202
+ id: string
203
+ name: string
204
+ createdAt: string
205
+ updatedAt: string
206
+ }
207
+ `}function N(e){let{pascal:t,kebab:n,dtoPrefix:r=`../../application/dtos`,tokenScope:i=`app`}=e;return`/**
208
+ * ${t} Repository Interface
209
+ *
210
+ * Defines the contract for data access.
211
+ * The interface declares what operations are available;
212
+ * implementations (in-memory, Drizzle, Prisma) fulfill the contract.
213
+ *
214
+ * To swap implementations, change the factory in the module's register() method.
215
+ */
216
+ import { createToken } from '@forinda/kickjs'
217
+ import type { ${t}ResponseDTO } from '${r}/${n}-response.dto'
218
+ import type { Create${t}DTO } from '${r}/create-${n}.dto'
219
+ import type { Update${t}DTO } from '${r}/update-${n}.dto'
220
+ import type { ParsedQuery } from '@forinda/kickjs'
221
+
222
+ export interface I${t}Repository {
223
+ findById(id: string): Promise<${t}ResponseDTO | null>
224
+ findAll(): Promise<${t}ResponseDTO[]>
225
+ findPaginated(parsed: ParsedQuery): Promise<{ data: ${t}ResponseDTO[]; total: number }>
226
+ create(dto: Create${t}DTO): Promise<${t}ResponseDTO>
227
+ update(id: string, dto: Update${t}DTO): Promise<${t}ResponseDTO>
228
+ delete(id: string): Promise<void>
229
+ }
230
+
231
+ /**
232
+ * Collision-safe DI token bound to \`I${t}Repository\`.
233
+ * \`container.resolve(${t.toUpperCase()}_REPOSITORY)\` and
234
+ * \`@Inject(${t.toUpperCase()}_REPOSITORY)\` both return the typed
235
+ * interface — no manual generic, no \`any\` cast.
236
+ *
237
+ * The \`'${i}/'\` prefix matches the project scope so
238
+ * \`kick-lint\`'s \`token-reserved-prefix\` rule never fires —
239
+ * adopters must NOT use the reserved \`'kick/'\` namespace.
240
+ */
241
+ export const ${t.toUpperCase()}_REPOSITORY = createToken<I${t}Repository>('${i}/${t}/repository')
242
+ `}function P(e){let{pascal:t,kebab:n,repoPrefix:r=`../../domain/repositories`,dtoPrefix:i=`../../application/dtos`}=e;return`/**
243
+ * In-Memory ${t} Repository
244
+ *
245
+ * Implements the repository interface using a Map.
246
+ * Useful for prototyping and testing. Replace with a database implementation
247
+ * (Drizzle, Prisma, etc.) for production use.
248
+ *
249
+ * @Repository() registers this class in the DI container as a singleton.
250
+ */
251
+ import { randomUUID } from 'node:crypto'
252
+ import { Repository, HttpException } from '@forinda/kickjs'
253
+ import type { ParsedQuery } from '@forinda/kickjs'
254
+ import type { I${t}Repository } from '${r}/${n}.repository'
255
+ import type { ${t}ResponseDTO } from '${i}/${n}-response.dto'
256
+ import type { Create${t}DTO } from '${i}/create-${n}.dto'
257
+ import type { Update${t}DTO } from '${i}/update-${n}.dto'
258
+
259
+ @Repository()
260
+ export class InMemory${t}Repository implements I${t}Repository {
261
+ private store = new Map<string, ${t}ResponseDTO>()
262
+
263
+ async findById(id: string): Promise<${t}ResponseDTO | null> {
264
+ return this.store.get(id) ?? null
265
+ }
266
+
267
+ async findAll(): Promise<${t}ResponseDTO[]> {
268
+ return Array.from(this.store.values())
269
+ }
270
+
271
+ async findPaginated(parsed: ParsedQuery): Promise<{ data: ${t}ResponseDTO[]; total: number }> {
272
+ const all = Array.from(this.store.values())
273
+ const data = all.slice(parsed.pagination.offset, parsed.pagination.offset + parsed.pagination.limit)
274
+ return { data, total: all.length }
275
+ }
276
+
277
+ async create(dto: Create${t}DTO): Promise<${t}ResponseDTO> {
278
+ const now = new Date().toISOString()
279
+ const entity: ${t}ResponseDTO = {
280
+ id: randomUUID(),
281
+ ...dto,
282
+ createdAt: now,
283
+ updatedAt: now,
284
+ }
285
+ this.store.set(entity.id, entity)
286
+ return entity
287
+ }
288
+
289
+ async update(id: string, dto: Update${t}DTO): Promise<${t}ResponseDTO> {
290
+ const existing = this.store.get(id)
291
+ if (!existing) throw HttpException.notFound('${t} not found')
292
+ const updated = { ...existing, ...dto, updatedAt: new Date().toISOString() }
293
+ this.store.set(id, updated)
294
+ return updated
295
+ }
296
+
297
+ async delete(id: string): Promise<void> {
298
+ if (!this.store.has(id)) throw HttpException.notFound('${t} not found')
299
+ this.store.delete(id)
300
+ }
301
+ }
302
+ `}function F(e){let{pascal:t,kebab:n,repoType:r=``,repoPrefix:i=`../../domain/repositories`,dtoPrefix:a=`../../application/dtos`}=e,o=r.charAt(0).toUpperCase()+r.slice(1).replace(/-([a-z])/g,(e,t)=>t.toUpperCase());return`/**
303
+ * ${o} ${t} Repository
304
+ *
305
+ * Stub implementation for a custom '${r}' repository.
306
+ * Implements the repository interface using an in-memory Map as a placeholder.
307
+ *
308
+ * TODO: Replace the in-memory Map with your ${r} data-access logic.
309
+ * See I${t}Repository for the interface contract.
310
+ *
311
+ * @Repository() registers this class in the DI container as a singleton.
312
+ */
313
+ import { randomUUID } from 'node:crypto'
314
+ import { Repository, HttpException } from '@forinda/kickjs'
315
+ import type { ParsedQuery } from '@forinda/kickjs'
316
+ import type { I${t}Repository } from '${i}/${n}.repository'
317
+ import type { ${t}ResponseDTO } from '${a}/${n}-response.dto'
318
+ import type { Create${t}DTO } from '${a}/create-${n}.dto'
319
+ import type { Update${t}DTO } from '${a}/update-${n}.dto'
320
+
321
+ @Repository()
322
+ export class ${o}${t}Repository implements I${t}Repository {
323
+ // TODO: Replace with your ${r} client/connection
324
+ private store = new Map<string, ${t}ResponseDTO>()
325
+
326
+ async findById(id: string): Promise<${t}ResponseDTO | null> {
327
+ // TODO: Implement with ${r}
328
+ return this.store.get(id) ?? null
329
+ }
330
+
331
+ async findAll(): Promise<${t}ResponseDTO[]> {
332
+ // TODO: Implement with ${r}
333
+ return Array.from(this.store.values())
334
+ }
335
+
336
+ async findPaginated(parsed: ParsedQuery): Promise<{ data: ${t}ResponseDTO[]; total: number }> {
337
+ // TODO: Implement with ${r}
338
+ const all = Array.from(this.store.values())
339
+ const data = all.slice(parsed.pagination.offset, parsed.pagination.offset + parsed.pagination.limit)
340
+ return { data, total: all.length }
341
+ }
342
+
343
+ async create(dto: Create${t}DTO): Promise<${t}ResponseDTO> {
344
+ // TODO: Implement with ${r}
345
+ const now = new Date().toISOString()
346
+ const entity: ${t}ResponseDTO = {
347
+ id: randomUUID(),
348
+ ...dto,
349
+ createdAt: now,
350
+ updatedAt: now,
351
+ }
352
+ this.store.set(entity.id, entity)
353
+ return entity
354
+ }
355
+
356
+ async update(id: string, dto: Update${t}DTO): Promise<${t}ResponseDTO> {
357
+ // TODO: Implement with ${r}
358
+ const existing = this.store.get(id)
359
+ if (!existing) throw HttpException.notFound('${t} not found')
360
+ const updated = { ...existing, ...dto, updatedAt: new Date().toISOString() }
361
+ this.store.set(id, updated)
362
+ return updated
363
+ }
364
+
365
+ async delete(id: string): Promise<void> {
366
+ // TODO: Implement with ${r}
367
+ if (!this.store.has(id)) throw HttpException.notFound('${t} not found')
368
+ this.store.delete(id)
369
+ }
370
+ }
371
+ `}function ue(e){let{pascal:t,kebab:n,plural:r=``}=e;return`import { describe, it, expect, beforeEach } from 'vitest'
372
+ import { Container } from '@forinda/kickjs'
373
+
374
+ describe('${t}Controller', () => {
375
+ beforeEach(() => {
376
+ Container.reset()
377
+ })
378
+
379
+ it('should be defined', () => {
380
+ expect(true).toBe(true)
381
+ })
382
+
383
+ describe('POST /${r}', () => {
384
+ it('should create a new ${n}', async () => {
385
+ // TODO: Set up test module, call create endpoint, assert 201
386
+ expect(true).toBe(true)
387
+ })
388
+ })
389
+
390
+ describe('GET /${r}', () => {
391
+ it('should return paginated ${r}', async () => {
392
+ // TODO: Set up test module, call list endpoint, assert { data, meta }
393
+ expect(true).toBe(true)
394
+ })
395
+ })
396
+
397
+ describe('GET /${r}/:id', () => {
398
+ it('should return a ${n} by id', async () => {
399
+ // TODO: Create a ${n}, then fetch by id, assert match
400
+ expect(true).toBe(true)
401
+ })
402
+
403
+ it('should return 404 for non-existent ${n}', async () => {
404
+ // TODO: Fetch non-existent id, assert 404
405
+ expect(true).toBe(true)
406
+ })
407
+ })
408
+
409
+ describe('PUT /${r}/:id', () => {
410
+ it('should update an existing ${n}', async () => {
411
+ // TODO: Create, update, assert changes
412
+ expect(true).toBe(true)
413
+ })
414
+ })
415
+
416
+ describe('DELETE /${r}/:id', () => {
417
+ it('should delete a ${n}', async () => {
418
+ // TODO: Create, delete, assert gone
419
+ expect(true).toBe(true)
420
+ })
421
+ })
422
+ })
423
+ `}function de(e){let{pascal:t,kebab:n,plural:r=``,repoPrefix:i=`../infrastructure/repositories/in-memory-${n}.repository`}=e;return`import { describe, it, expect, beforeEach } from 'vitest'
424
+ import { InMemory${t}Repository } from '${i}'
425
+
426
+ describe('InMemory${t}Repository', () => {
427
+ let repo: InMemory${t}Repository
428
+
429
+ beforeEach(() => {
430
+ repo = new InMemory${t}Repository()
431
+ })
432
+
433
+ it('should create and retrieve a ${n}', async () => {
434
+ const created = await repo.create({ name: 'Test ${t}' })
435
+ expect(created).toBeDefined()
436
+ expect(created.name).toBe('Test ${t}')
437
+ expect(created.id).toBeDefined()
438
+
439
+ const found = await repo.findById(created.id)
440
+ expect(found).toEqual(created)
441
+ })
442
+
443
+ it('should return null for non-existent id', async () => {
444
+ const found = await repo.findById('non-existent')
445
+ expect(found).toBeNull()
446
+ })
447
+
448
+ it('should list all ${r}', async () => {
449
+ await repo.create({ name: '${t} 1' })
450
+ await repo.create({ name: '${t} 2' })
451
+
452
+ const all = await repo.findAll()
453
+ expect(all).toHaveLength(2)
454
+ })
455
+
456
+ it('should return paginated results', async () => {
457
+ await repo.create({ name: '${t} 1' })
458
+ await repo.create({ name: '${t} 2' })
459
+ await repo.create({ name: '${t} 3' })
460
+
461
+ const result = await repo.findPaginated({
462
+ filters: [],
463
+ sort: [],
464
+ search: '',
465
+ pagination: { page: 1, limit: 2, offset: 0 },
466
+ })
467
+
468
+ expect(result.data).toHaveLength(2)
469
+ expect(result.total).toBe(3)
470
+ })
471
+
472
+ it('should update a ${n}', async () => {
473
+ const created = await repo.create({ name: 'Original' })
474
+ const updated = await repo.update(created.id, { name: 'Updated' })
475
+ expect(updated.name).toBe('Updated')
476
+ })
477
+
478
+ it('should delete a ${n}', async () => {
479
+ const created = await repo.create({ name: 'To Delete' })
480
+ await repo.delete(created.id)
481
+ const found = await repo.findById(created.id)
482
+ expect(found).toBeNull()
483
+ })
484
+ })
485
+ `}function I(e){let{pascal:t,kebab:n}=e;return`import { Service, Inject, HttpException } from '@forinda/kickjs'
486
+ import type { ParsedQuery } from '@forinda/kickjs'
487
+ import { ${t.toUpperCase()}_REPOSITORY, type I${t}Repository } from './${n}.repository'
488
+ import type { ${t}ResponseDTO } from './dtos/${n}-response.dto'
489
+ import type { Create${t}DTO } from './dtos/create-${n}.dto'
490
+ import type { Update${t}DTO } from './dtos/update-${n}.dto'
491
+
492
+ @Service()
493
+ export class ${t}Service {
494
+ constructor(
495
+ @Inject(${t.toUpperCase()}_REPOSITORY) private readonly repo: I${t}Repository,
496
+ ) {}
497
+
498
+ async findById(id: string): Promise<${t}ResponseDTO | null> {
499
+ return this.repo.findById(id)
500
+ }
501
+
502
+ async findAll(): Promise<${t}ResponseDTO[]> {
503
+ return this.repo.findAll()
504
+ }
505
+
506
+ async findPaginated(parsed: ParsedQuery) {
507
+ return this.repo.findPaginated(parsed)
508
+ }
509
+
510
+ async create(dto: Create${t}DTO): Promise<${t}ResponseDTO> {
511
+ return this.repo.create(dto)
512
+ }
513
+
514
+ async update(id: string, dto: Update${t}DTO): Promise<${t}ResponseDTO> {
515
+ return this.repo.update(id, dto)
516
+ }
517
+
518
+ async delete(id: string): Promise<void> {
519
+ await this.repo.delete(id)
520
+ }
521
+ }
522
+ `}function L(e){let{pascal:t}=e;return`import type { QueryFieldConfig } from '@forinda/kickjs'
523
+
524
+ export const ${t.toUpperCase()}_QUERY_CONFIG: QueryFieldConfig = {
525
+ filterable: ['name'],
526
+ sortable: ['name', 'createdAt'],
527
+ searchable: ['name'],
528
+ }
529
+ `}function fe(e,t,n,r=[]){switch(t){case`minimal`:{let t=[],i=[];return r.includes(`swagger`)&&(t.push(`import { SwaggerAdapter } from '@forinda/kickjs-swagger'`),i.push(` SwaggerAdapter({ info: { title: '${e}', version: '${n}' } }),`)),r.includes(`devtools`)&&(t.push(`import { DevToolsAdapter } from '@forinda/kickjs-devtools'`),i.push(` DevToolsAdapter(),`)),`import 'reflect-metadata'
530
+ // Side-effect import — registers the extended env schema with kickjs
531
+ // **before** any controller / service / @Value gets resolved. Without
532
+ // this line ConfigService.get('YOUR_KEY') returns undefined because the
533
+ // cached schema would still be the base shape. See guide/configuration.
534
+ import './config'
535
+ import { bootstrap } from '@forinda/kickjs'
536
+ ${t.length?t.join(`
537
+ `)+`
538
+ `:``}import { modules } from './modules'
539
+
540
+ // Export the app for the Vite plugin (dev mode)
541
+ export const app = await bootstrap({ modules${i.length?`,\n adapters: [\n${i.join(`
542
+ `)}\n ]`:``} })
543
+ `}default:{let t=[],i=[];return r.includes(`devtools`)&&(t.push(`import { DevToolsAdapter } from '@forinda/kickjs-devtools'`),i.push(` DevToolsAdapter(),`)),r.includes(`swagger`)&&(t.push(`import { SwaggerAdapter } from '@forinda/kickjs-swagger'`),i.push(` SwaggerAdapter({\n info: { title: '${e}', version: '${n}' },\n }),`)),`import 'reflect-metadata'
544
+ // Side-effect import — registers the extended env schema with kickjs
545
+ // **before** any controller / service / @Value gets resolved. Without
546
+ // this line ConfigService.get('YOUR_KEY') returns undefined because the
547
+ // cached schema would still be the base shape. See guide/configuration.
548
+ import './config'
549
+ import express from 'express'
550
+ import {
551
+ bootstrap,
552
+ requestId,
553
+ requestLogger,
554
+ helmet,
555
+ cors,
556
+ } from '@forinda/kickjs'
557
+ ${t.length?t.join(`
558
+ `)+`
559
+ `:``}import { modules } from './modules'
560
+
561
+ // Export the app for the Vite plugin (dev mode)
562
+ export const app = await bootstrap({
563
+ modules,${i.length?`\n adapters: [\n${i.join(`
564
+ `)}\n ],`:``}
565
+ middleware: [
566
+ helmet(),
567
+ cors({ origin: '*' }),
568
+ requestId(),
569
+ requestLogger(),
570
+ express.json(),
571
+ ],
572
+ })
573
+ `}}}function pe(){return`import { defineModules } from '@forinda/kickjs'
574
+ import { HelloModule } from './hello/hello.module'
575
+
576
+ // Remove HelloModule and run: kick g module <name>
577
+ // \`defineModules()\` returns a chainable list — \`kick g module\` appends
578
+ // \`.mount(NewModule())\` to the chain on every generation.
579
+ export const modules = defineModules().mount(HelloModule())
580
+ `}function me(e=`zod`){return e===`valibot`?`import { loadEnvFromSchema } from '@forinda/kickjs/config'
581
+ import { fromValibot } from '@forinda/kickjs-schema/valibot'
582
+ import * as v from 'valibot'
583
+
584
+ /**
585
+ * Project environment schema (Valibot).
586
+ *
587
+ * \`fromValibot\` wraps the Valibot schema as a \`KickSchema\` so the
588
+ * env loader, validate middleware, and swagger spec generator all see
589
+ * the same shape. The default export is the contract \`kick typegen\`
590
+ * reads to populate \`KickEnv\` via \`InferSchemaOutput<typeof _envSchema>\`
591
+ * — that's what makes \`@Value('FOO')\` autocomplete and
592
+ * \`process.env.FOO\` typed.
593
+ *
594
+ * @example
595
+ * DATABASE_URL: v.pipe(v.string(), v.url()),
596
+ * JWT_SECRET: v.pipe(v.string(), v.minLength(32)),
597
+ * REDIS_URL: v.optional(v.pipe(v.string(), v.url())),
598
+ */
599
+ const envSchema = fromValibot(
600
+ v.object({
601
+ PORT: v.optional(v.pipe(v.string(), v.transform(Number)), '3000'),
602
+ NODE_ENV: v.optional(v.picklist(['development', 'production', 'test']), 'development'),
603
+ LOG_LEVEL: v.optional(v.string(), 'info'),
604
+ // DATABASE_URL: v.pipe(v.string(), v.url()),
605
+ }),
606
+ )
607
+
608
+ /**
609
+ * IMPORTANT — side effect: register the schema with kickjs's env cache
610
+ * **at module-load time**. \`ConfigService\` and \`@Value()\` both consume
611
+ * this cache, and they will fall back to the base schema (or undefined)
612
+ * if no extended schema has been registered before they're resolved.
613
+ *
614
+ * As long as \`src/index.ts\` imports this file (\`import './config'\`) at
615
+ * the top — before \`bootstrap()\` runs — every controller and service
616
+ * in the app sees the typed extended values.
617
+ */
618
+ export const env = loadEnvFromSchema(envSchema)
619
+
620
+ export default envSchema
621
+ `:e===`yup`?`import { loadEnvFromSchema } from '@forinda/kickjs/config'
622
+ import { fromYup } from '@forinda/kickjs-schema/yup'
623
+ import * as yup from 'yup'
624
+
625
+ /**
626
+ * Project environment schema (Yup).
627
+ *
628
+ * \`fromYup\` wraps the Yup schema as a \`KickSchema\` so the env loader,
629
+ * validate middleware, and swagger spec generator all see the same
630
+ * shape. The default export is the contract \`kick typegen\` reads to
631
+ * populate \`KickEnv\` via \`InferSchemaOutput<typeof _envSchema>\`.
632
+ *
633
+ * Note: Yup's \`.url()\` defaults to http/https; database connection
634
+ * strings like \`postgres://\` use \`.matches(/^[a-z]+:\\/\\/.+/i)\` or
635
+ * a plain \`.string().required()\`.
636
+ *
637
+ * @example
638
+ * DATABASE_URL: yup.string().required(),
639
+ * JWT_SECRET: yup.string().min(32).required(),
640
+ * REDIS_URL: yup.string().url().optional(),
641
+ */
642
+ const envSchema = fromYup(
643
+ yup.object({
644
+ PORT: yup.number().default(3000),
645
+ NODE_ENV: yup
646
+ .string()
647
+ .oneOf(['development', 'production', 'test'])
648
+ .default('development'),
649
+ LOG_LEVEL: yup.string().default('info'),
650
+ // DATABASE_URL: yup.string().required(),
651
+ }),
652
+ )
653
+
654
+ /**
655
+ * IMPORTANT — side effect: register the schema with kickjs's env cache
656
+ * **at module-load time**. \`ConfigService\` and \`@Value()\` both consume
657
+ * this cache, and they will fall back to the base schema (or undefined)
658
+ * if no extended schema has been registered before they're resolved.
659
+ *
660
+ * As long as \`src/index.ts\` imports this file (\`import './config'\`) at
661
+ * the top — before \`bootstrap()\` runs — every controller and service
662
+ * in the app sees the typed extended values.
663
+ */
664
+ export const env = loadEnvFromSchema(envSchema)
665
+
666
+ export default envSchema
667
+ `:`import { loadEnvFromSchema } from '@forinda/kickjs/config'
668
+ import { fromZod } from '@forinda/kickjs-schema/zod'
669
+ import { z } from 'zod'
670
+
671
+ /**
672
+ * Project environment schema (Zod).
673
+ *
674
+ * \`fromZod\` wraps the Zod schema as a \`KickSchema\` so the env loader,
675
+ * validate middleware, and swagger spec generator all see the same
676
+ * shape. The default export is the contract \`kick typegen\` reads to
677
+ * populate \`KickEnv\` via \`InferSchemaOutput<typeof _envSchema>\` —
678
+ * that's what makes \`@Value('FOO')\` autocomplete and
679
+ * \`process.env.FOO\` typed.
680
+ *
681
+ * @example
682
+ * DATABASE_URL: z.string().url(),
683
+ * JWT_SECRET: z.string().min(32),
684
+ * REDIS_URL: z.string().url().optional(),
685
+ */
686
+ const envSchema = fromZod(
687
+ z.object({
688
+ PORT: z.coerce.number().default(3000),
689
+ NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
690
+ LOG_LEVEL: z.string().default('info'),
691
+ // DATABASE_URL: z.string().url(),
692
+ }),
693
+ )
694
+
695
+ /**
696
+ * IMPORTANT — side effect: register the schema with kickjs's env cache
697
+ * **at module-load time**. \`ConfigService\` and \`@Value()\` both consume
698
+ * this cache, and they will fall back to the base schema (or undefined)
699
+ * if no extended schema has been registered before they're resolved.
700
+ *
701
+ * As long as \`src/index.ts\` imports this file (\`import './config'\`) at
702
+ * the top — before \`bootstrap()\` runs — every controller and service
703
+ * in the app sees the typed extended values.
704
+ */
705
+ export const env = loadEnvFromSchema(envSchema)
706
+
707
+ export default envSchema
708
+ `}function he(){return`import { Service } from '@forinda/kickjs'
709
+
710
+ @Service()
711
+ export class HelloService {
712
+ greet(name: string) {
713
+ return { message: \`Hello \${name} from KickJS!\`, timestamp: new Date().toISOString() }
714
+ }
715
+
716
+ healthCheck() {
717
+ return { status: 'ok', uptime: process.uptime() }
718
+ }
719
+ }
720
+ `}function R(){return`import { Controller, Get, Autowired, type Ctx } from '@forinda/kickjs'
721
+ import { HelloService } from './hello.service'
722
+
723
+ // \`Ctx<KickRoutes.HelloController['<method>']>\` is generated by
724
+ // \`kick typegen\` (auto-run on \`kick dev\`). The first run after a fresh
725
+ // scaffold creates \`.kickjs/types/routes.ts\` so this file typechecks.
726
+ // See https://forinda.github.io/kick-js/guide/typegen.
727
+
728
+ @Controller()
729
+ export class HelloController {
730
+ @Autowired() private readonly helloService!: HelloService
731
+
732
+ @Get('/')
733
+ index(ctx: Ctx<KickRoutes.HelloController['index']>) {
734
+ ctx.json(this.helloService.greet('World'))
735
+ }
736
+
737
+ @Get('/health')
738
+ health(ctx: Ctx<KickRoutes.HelloController['health']>) {
739
+ ctx.json(this.helloService.healthCheck())
740
+ }
741
+ }
742
+ `}function ge(){return`import { defineModule } from '@forinda/kickjs'
743
+ import { HelloController } from './hello.controller'
744
+
745
+ export const HelloModule = defineModule({
746
+ name: 'HelloModule',
747
+ build: () => ({
748
+ // \`register(container)\` is optional — only implement it when you need
749
+ // to bind a token to a concrete implementation, e.g.
750
+ // register(container) {
751
+ // container.registerFactory(USER_REPOSITORY, () => container.resolve(InMemoryUserRepository))
752
+ // }
753
+ // The HelloService uses @Service() so the decorator handles registration.
754
+
755
+ routes() {
756
+ return {
757
+ path: '/hello',
758
+ controller: HelloController,
759
+ }
760
+ },
761
+ }),
762
+ })
763
+ `}function _e(e,t=`inmemory`,n=`pnpm`){return`import { defineConfig } from '@forinda/kickjs-cli'
764
+
765
+ export default defineConfig({
766
+ pattern: '${e}',
767
+ // Pinned so \`kick add\` and other dep-installing commands always use the
768
+ // project's intended package manager, regardless of which lockfile exists.
769
+ packageManager: '${n}',
770
+ modules: {
771
+ dir: 'src/modules',
772
+ repo: ${t===`inmemory`?`'inmemory'`:`{ name: '${t}' }`},
773
+ pluralize: true,
774
+ },
775
+
776
+ // \`kick typegen\` populates \`.kickjs/types/\` so \`Ctx<KickRoutes.X['method']>\`
777
+ // resolves to fully-typed params/body/query. Auto-runs on \`kick dev\`.
778
+ // \`'kickjs-schema'\` routes inference through \`InferSchemaOutput\` so the
779
+ // typegen works for any wrapped schema (Zod / Valibot / Yup). Switch
780
+ // to \`'zod'\` if you ship Zod schemas without \`fromZod()\` wrapping, or
781
+ // set \`schemaValidator: false\` to skip schema-driven body typing.
782
+ typegen: {
783
+ schemaValidator: 'kickjs-schema',
784
+ },
785
+
786
+ commands: [
787
+ {
788
+ name: 'test',
789
+ description: 'Run tests with Vitest',
790
+ steps: 'npx vitest run',
791
+ },
792
+ {
793
+ name: 'format',
794
+ description: 'Format code with Prettier',
795
+ steps: 'npx prettier --write src/',
796
+ },
797
+ {
798
+ name: 'format:check',
799
+ description: 'Check formatting without writing',
800
+ steps: 'npx prettier --check src/',
801
+ },
802
+ {
803
+ name: 'ci:check',
804
+ description: 'Run typecheck + format check',
805
+ steps: ['npx tsc --noEmit', 'npx prettier --check src/'],
806
+ aliases: ['verify'],
807
+ },
808
+ ],
809
+ })
810
+ `}async function ve(e){let{pascal:t,kebab:n,plural:r,style:i,write:a}=e;await a(`${n}.module.ts`,oe({pascal:t,kebab:n,plural:r,style:i})),await a(`${n}.controller.ts`,`import { Controller, Get, type Ctx } from '@forinda/kickjs'
811
+
812
+ // \`Ctx<KickRoutes.${t}Controller['<method>']>\` is generated by
813
+ // \`kick typegen\` (auto-run on \`kick dev\`).
814
+
815
+ @Controller()
816
+ export class ${t}Controller {
817
+ @Get('/')
818
+ async list(ctx: Ctx<KickRoutes.${t}Controller['list']>) {
819
+ ctx.json({ message: '${t} list' })
820
+ }
821
+ }
822
+ `)}async function ye(e){let{pascal:t,kebab:n,plural:r,pluralPascal:i,repo:a,noTests:o,tokenScope:s,style:c,write:l}=e;await l(`${n}.module.ts`,j({pascal:t,kebab:n,plural:r,repo:a,style:c})),await l(`${n}.constants.ts`,L({pascal:t,kebab:n})),await l(`${n}.controller.ts`,M({pascal:t,kebab:n,plural:r,pluralPascal:i})),await l(`${n}.service.ts`,I({pascal:t,kebab:n})),await l(`dtos/create-${n}.dto.ts`,se({pascal:t,kebab:n})),await l(`dtos/update-${n}.dto.ts`,ce({pascal:t,kebab:n})),await l(`dtos/${n}-response.dto.ts`,le({pascal:t,kebab:n})),await l(`${n}.repository.ts`,N({pascal:t,kebab:n,dtoPrefix:`./dtos`,tokenScope:s}));let u=a===`inmemory`,d=u?`in-memory-${n}`:`${E(a)}-${n}`,f=u?P({pascal:t,kebab:n,repoPrefix:`.`,dtoPrefix:`./dtos`}):F({pascal:t,kebab:n,repoType:a,repoPrefix:`.`,dtoPrefix:`./dtos`});await l(`${d}.repository.ts`,f),o||(a!==`inmemory`&&await l(`in-memory-${n}.repository.ts`,P({pascal:t,kebab:n,repoPrefix:`.`,dtoPrefix:`./dtos`})),await l(`__tests__/${n}.controller.test.ts`,ue({pascal:t,kebab:n,plural:r})),await l(`__tests__/${n}.repository.test.ts`,de({pascal:t,kebab:n,plural:r,repoPrefix:`../in-memory-${n}.repository`})))}function be(e){return e?typeof e==`string`?e:e.name:`inmemory`}async function xe(t){let{name:n,modulesDir:a,noEntity:c,noTests:l,repo:u=`inmemory`,force:d,dryRun:p}=t,m=t.pluralize!==!1,h=t.pattern??`rest`;t.minimal&&(h=`minimal`);let g=E(n),_=w(n),v=m?D(g):g,y=m?O(_):_,b=f(a,v),x=[],S=d??!1,C={kebab:g,pascal:_,plural:v,pluralPascal:y,moduleDir:b,repo:u,noEntity:c??!1,noTests:l??!1,prismaClientPath:t.prismaClientPath??`@prisma/client`,tokenScope:t.tokenScope??`app`,style:t.style??`define`,write:async(t,n)=>{let a=f(b,t);if(p){x.push(a);return}if(!S&&await s(a)&&!await o({message:`File exists: ${r.dim(t)}. Overwrite?`,initialValue:!1})){i.warn(`Skipped: ${t}`);return}await e(a,n),x.push(a)},files:x};switch(h){case`minimal`:await ve(C);break;default:await ye(C);break}return p||await z(a,_,v,g,C.style),x}async function z(t,n,r,i,a=`define`){let o=f(t,`index.ts`),c=await s(o),l=`./${r}/${i}.module`,u=a===`class`?`${n}Module`:`${n}Module()`;if(!c){await e(o,a===`class`?`import type { AppModuleEntry } from '@forinda/kickjs'
823
+ import { ${n}Module } from '${l}'
824
+
825
+ export const modules: AppModuleEntry[] = [${u}]
826
+ `:`import { defineModules } from '@forinda/kickjs'
827
+ import { ${n}Module } from '${l}'
828
+
829
+ export const modules = defineModules().mount(${u})
830
+ `);return}let d=await y(o,`utf-8`),p=`import { ${n}Module } from '${l}'`,m=k(l);if(!RegExp(`^import\\s*\\{[^}]*\\b${k(n)}Module\\b[^}]*\\}\\s*from\\s*['"]${m}['"]`,`m`).test(d)){let e=d.lastIndexOf(`import `);if(e!==-1){let t=d.indexOf(`
831
+ `,e);d=d.slice(0,t+1)+p+`
832
+ `+d.slice(t+1)}else d=p+`
833
+ `+d}let h=V(d);if(h){let e=d.slice(h.rhsStart,h.rhsEnd+1);RegExp(`\\b${k(n)}Module\\b`).test(e)||(d=B(d,u))}else d=B(d,u);await b(o,d,`utf-8`)}function B(e,t){let n=V(e);if(!n)return e;if(n.shape===`array`){let r=e.slice(n.rhsStart+1,n.rhsEnd),i=r.trim(),a;if(!i)a=`[${t}]`;else{let e=i.endsWith(`,`)?``:`,`;a=`[${r.trimEnd()}${e} ${t}]`}return e.slice(0,n.rhsStart)+a+e.slice(n.rhsEnd+1)}return`${e.slice(0,n.chainEnd)}\n .mount(${t})${e.slice(n.chainEnd)}`}function V(e){let t=/export\s+const\s+modules\b[^=]*=/.exec(e);if(!t)return null;let n=t.index+t[0].length;for(;n<e.length&&/\s/.test(e[n]??``);)n++;if(e[n]===`[`){let t=Ce(e,n);return t===-1?null:{shape:`array`,rhsStart:n,rhsEnd:t}}if(e.slice(n,n+13)===`defineModules`){let t=Se(e,n);return t===-1?null:{shape:`chain`,rhsStart:n,rhsEnd:t-1,chainEnd:t}}return null}function Se(e,t=0){let n=/defineModules\s*\(/g;n.lastIndex=t;let r=n.exec(e);if(!r)return-1;let i=r.index+r[0].length-1;if(e[i]!==`(`||(i=U(e,i),i===-1))return-1;for(i++;;){let t=i;for(;t<e.length&&/\s/.test(e[t]??``);)t++;if(e[t]!==`.`||e.slice(t,t+6)!==`.mount`)break;for(t+=6;t<e.length&&/\s/.test(e[t]??``);)t++;if(e[t]!==`(`)break;let n=U(e,t);if(n===-1)break;i=n+1}return i}function H(e,t){let n=e.slice(t,t+2);if(n===`//`){for(t+=2;t<e.length&&e[t]!==`
834
+ `;)t++;return t}if(n===`/*`){for(t+=2;t+1<e.length&&!(e[t]===`*`&&e[t+1]===`/`);)t++;return t+2}return t}function Ce(e,t){if(e[t]!==`[`)return-1;let n=1,r=t+1;for(;r<e.length;){let t=e.slice(r,r+2);if(t===`//`||t===`/*`){r=H(e,r);continue}let i=e[r]??``;if(i===`'`||i===`"`||i==="`"){let t=i;for(r++;r<e.length&&e[r]!==t;)e[r]===`\\`&&r++,r++;r<e.length&&r++;continue}if(i===`[`)n++;else if(i===`]`&&(n--,n===0))return r;r++}return-1}function U(e,t){if(e[t]!==`(`)return-1;let n=1,r=t+1;for(;r<e.length;){let t=e.slice(r,r+2);if(t===`//`||t===`/*`){r=H(e,r);continue}let i=e[r]??``;if(i===`'`||i===`"`||i==="`"){let t=i;for(r++;r<e.length&&e[r]!==t;)e[r]===`\\`&&r++,r++;r<e.length&&r++;continue}if(i===`(`)n++;else if(i===`)`&&(n--,n===0))return r;r++}return-1}async function we(t){let{name:n,outDir:r}=t,i=E(n),a=w(n),o=[],s=f(r,`${i}.adapter.ts`);return await e(s,`import {
835
+ defineAdapter,
836
+ type AdapterContext,
837
+ type AdapterMiddleware,
838
+ type ContributorRegistrations,
839
+ type Constructor,
840
+ } from '@forinda/kickjs'
841
+
842
+ /**
843
+ * Configuration for the ${a} adapter.
844
+ *
845
+ * Adapters typically take a small config object so callers can tune
846
+ * behaviour at bootstrap time. Keep the shape narrow — anything
847
+ * derived from the environment should be read inside the build
848
+ * function via getEnv(), not forced onto the caller.
849
+ */
850
+ export interface ${a}AdapterConfig {
851
+ // Add your adapter configuration here, e.g.:
852
+ // enabled?: boolean
853
+ // apiKey?: string
854
+ }
855
+
856
+ /**
857
+ * ${a} adapter — built via \`defineAdapter()\` so callers get the
858
+ * factory's call / \`.scoped()\` / \`.async()\` surfaces for free.
859
+ *
860
+ * Hooks into the Application lifecycle to add middleware, routes,
861
+ * Context Contributors, or external service connections.
862
+ *
863
+ * Every lifecycle hook below is OPTIONAL. The scaffold emits all of
864
+ * them so adopters can browse what's available and delete what they
865
+ * don't need — \`build()\` returning \`{}\` is also valid for an adapter
866
+ * that only contributes config defaults.
867
+ *
868
+ * @example
869
+ * \`\`\`ts
870
+ * import { bootstrap } from '@forinda/kickjs'
871
+ * import { ${a}Adapter } from './adapters/${i}.adapter'
872
+ *
873
+ * bootstrap({
874
+ * modules,
875
+ * adapters: [${a}Adapter({ /* config overrides *\\/ })],
876
+ * })
877
+ * \`\`\`
878
+ */
879
+ export const ${a}Adapter = defineAdapter<${a}AdapterConfig>({
880
+ name: '${a}Adapter',
881
+ defaults: {
882
+ // Default config values go here. The adopter's overrides shallow-merge
883
+ // on top of these before \`build()\` runs.
884
+ },
885
+ build: (_config, { name: _name }) => {
886
+ // Closures inside \`build()\` are how each adapter instance owns its
887
+ // own state (database client, Map, timer handle, …). The same
888
+ // \`_config\` is visible to every hook below.
889
+
890
+ return {
891
+ /**
892
+ * Express middleware entries the Application mounts at named phases.
893
+ *
894
+ * \`phase\` controls where each handler sits in the pipeline:
895
+ * 'beforeGlobal' | 'afterGlobal' | 'beforeRoutes' | 'afterRoutes'.
896
+ *
897
+ * \`path\` (optional) scopes the entry to a path prefix.
898
+ *
899
+ * Delete this hook entirely if you don't add middleware.
900
+ */
901
+ middleware(): AdapterMiddleware[] {
902
+ return [
903
+ // Example: add a custom header to all responses
904
+ // {
905
+ // phase: 'beforeGlobal',
906
+ // handler: (_req, res, next) => {
907
+ // res.setHeader('X-${a}', 'true')
908
+ // next()
909
+ // },
910
+ // },
911
+ // Example: scope a rate limiter to one path prefix
912
+ // {
913
+ // phase: 'beforeRoutes',
914
+ // path: '/api/v1/auth',
915
+ // handler: rateLimit({ max: 10 }),
916
+ // },
917
+ ]
918
+ },
919
+
920
+ /**
921
+ * Runs BEFORE global middleware. Mount routes that should bypass the
922
+ * middleware stack — health checks, docs UI, static assets, OAuth
923
+ * callbacks. Anything you want reachable even if a global middleware
924
+ * later in the chain rejects requests.
925
+ *
926
+ * Delete this hook if you have no early routes.
927
+ */
928
+ beforeMount(_ctx: AdapterContext): void {
929
+ // Example:
930
+ // _ctx.app.get('/${i}/status', (_req, res) => res.json({ status: 'ok' }))
931
+ },
932
+
933
+ /**
934
+ * Fires once per controller class as the router mounts. Use this to
935
+ * collect route metadata for OpenAPI specs, dependency graphs, route
936
+ * inventories, devtools dashboards.
937
+ *
938
+ * Delete this hook unless your adapter introspects the route registry.
939
+ */
940
+ onRouteMount(_controllerClass: Constructor, _mountPath: string): void {
941
+ // Example (Swagger-style): collect routes for the spec.
942
+ // openApiSpec.addController(_controllerClass, _mountPath)
943
+ },
944
+
945
+ /**
946
+ * Runs AFTER modules + routes are wired, BEFORE the server starts.
947
+ * Right place for late-stage DI registrations or final config validation.
948
+ *
949
+ * Delete this hook if there's nothing to wire post-modules.
950
+ */
951
+ beforeStart(_ctx: AdapterContext): void {
952
+ // Example: _ctx.container.registerInstance(MY_TOKEN, new MyService(_config))
953
+ },
954
+
955
+ /**
956
+ * Runs AFTER the HTTP server is listening. The raw \`http.Server\` is
957
+ * available on \`ctx.server\` — attach upgrade handlers (Socket.IO,
958
+ * gRPC, GraphQL subscriptions), warm caches, log a banner.
959
+ *
960
+ * Delete this hook if you don't need the running server reference.
961
+ */
962
+ afterStart(_ctx: AdapterContext): void {
963
+ // Example: const io = new Server(_ctx.server)
964
+ },
965
+
966
+ /**
967
+ * Returns Context Contributors to merge into every route's pipeline
968
+ * at the \`'adapter'\` precedence level. Per-route handlers can
969
+ * override the value at the method / class / module level.
970
+ *
971
+ * Delete this hook unless your adapter ships typed per-request values
972
+ * (auth user, tenant, locale, feature flags, geo, etc).
973
+ */
974
+ contributors(): ContributorRegistrations {
975
+ return [
976
+ // Example:
977
+ // import { defineHttpContextDecorator } from '@forinda/kickjs'
978
+ // declare module '@forinda/kickjs' { interface ContextMeta { ${i}: { id: string } } }
979
+ // const Load${a} = defineHttpContextDecorator({
980
+ // key: '${i}',
981
+ // resolve: (ctx) => ({ id: ctx.req.headers['x-${i}-id'] as string }),
982
+ // })
983
+ // return [Load${a}.registration]
984
+ ]
985
+ },
986
+
987
+ /**
988
+ * Runs on graceful shutdown (SIGINT/SIGTERM). Clean up long-lived
989
+ * resources the adapter owns: close connections, flush buffers,
990
+ * cancel timers. The framework runs every adapter's \`shutdown\`
991
+ * concurrently via \`Promise.allSettled\` — one failure won't block
992
+ * sibling adapters.
993
+ *
994
+ * Delete this hook if your adapter holds no resources.
995
+ */
996
+ async shutdown(): Promise<void> {
997
+ // Example: await this.pool.end()
998
+ // Example: clearInterval(this.heartbeatTimer)
999
+ },
1000
+ }
1001
+ },
1002
+ })
1003
+ `),o.push(s),o}const Te={controller:``,service:``,dto:`dtos`,guard:`guards`,middleware:`middleware`,contributor:`contributors`};function W(e){let{type:t,outDir:n,moduleName:r,modulesDir:i=`src/modules`,defaultDir:a,shouldPluralize:o=!0}=e;if(n)return m(n);if(r){let e=Te,n=E(r),a=o?D(n):n,s=e[t]??``,c=f(i,a);return m(s?f(c,s):c)}return m(a)}async function Ee(t){let{name:n,moduleName:r,modulesDir:i,pattern:a}=t,o=W({type:`middleware`,outDir:t.outDir,moduleName:r,modulesDir:i,defaultDir:`src/middleware`,pattern:a,shouldPluralize:t.pluralize??!0}),s=E(n),c=T(n),l=[],u=f(o,`${s}.middleware.ts`);return await e(u,`import type { Request, Response, NextFunction } from 'express'
1004
+
1005
+ export interface ${w(n)}Options {
1006
+ // Add configuration options here. The factory below closes over the
1007
+ // resolved options object; pass them at the call site —
1008
+ // \`${c}({ foo: 'bar' })\` — and the closure preserves them across
1009
+ // every request.
1010
+ }
1011
+
1012
+ /**
1013
+ * ${w(n)} middleware.
1014
+ *
1015
+ * Usage in bootstrap (fires on every request):
1016
+ * middleware: [${c}()]
1017
+ *
1018
+ * Usage with adapter — phase controls *when* the handler runs:
1019
+ *
1020
+ * middleware() {
1021
+ * return [{ handler: ${c}(), phase: 'afterGlobal' }]
1022
+ * }
1023
+ *
1024
+ * Phase semantics (see \`MiddlewarePhase\` JSDoc for the full contract):
1025
+ * - 'beforeGlobal' / 'afterGlobal' / 'beforeRoutes' — fire on every
1026
+ * request, before module routes run.
1027
+ * - 'afterRoutes' — fires ONLY when no route matched (404 fall-through)
1028
+ * OR a route handler called \`next()\` without ending the response.
1029
+ * Controllers that call \`ctx.json(…)\` end the chain and skip this
1030
+ * phase. For per-response work (logging, metrics) attach to
1031
+ * \`res.on('finish', …)\` from an earlier-phase middleware instead.
1032
+ *
1033
+ * Optional path scope — string, RegExp, or array of either:
1034
+ * middleware() {
1035
+ * return [{
1036
+ * handler: ${c}({ region: 'eu' }),
1037
+ * phase: 'afterGlobal',
1038
+ * path: ['/api', /^\\/admin/],
1039
+ * }]
1040
+ * }
1041
+ *
1042
+ * Usage with @Middleware decorator:
1043
+ * @Middleware(${c}())
1044
+ */
1045
+ export function ${c}(options: ${w(n)}Options = {}) {
1046
+ return (req: Request, res: Response, next: NextFunction) => {
1047
+ // Implement your middleware logic here. \`options\` is captured by
1048
+ // closure — log or read it anywhere in this handler body.
1049
+ void options
1050
+ next()
1051
+ }
1052
+ }
1053
+ `),l.push(u),l}async function De(t){let{name:n,moduleName:r,modulesDir:i,pattern:a}=t,o=W({type:`guard`,outDir:t.outDir,moduleName:r,modulesDir:i,defaultDir:`src/guards`,pattern:a,shouldPluralize:t.pluralize??!0}),s=E(n),c=T(n),l=w(n),u=[],d=f(o,`${s}.guard.ts`);return await e(d,`import { Container, HttpException } from '@forinda/kickjs'
1054
+ import type { RequestContext } from '@forinda/kickjs'
1055
+
1056
+ /**
1057
+ * ${l} guard.
1058
+ *
1059
+ * Guards protect routes by checking conditions before the handler runs.
1060
+ * Return early with an error response to block access.
1061
+ *
1062
+ * Usage:
1063
+ * @Middleware(${c}Guard)
1064
+ * @Get('/protected')
1065
+ * async handler(ctx: RequestContext) { ... }
1066
+ */
1067
+ export async function ${c}Guard(ctx: RequestContext, next: () => void): Promise<void> {
1068
+ // Example: check for an authorization header
1069
+ const header = ctx.headers.authorization
1070
+ if (!header?.startsWith('Bearer ')) {
1071
+ ctx.res.status(401).json({ message: 'Missing or invalid authorization header' })
1072
+ return
1073
+ }
1074
+
1075
+ const token = header.slice(7)
1076
+
1077
+ try {
1078
+ // Verify the token using a service from the DI container
1079
+ // const container = Container.getInstance()
1080
+ // const authService = container.resolve(AuthService)
1081
+ // const payload = authService.verifyToken(token)
1082
+ // ctx.set('auth', payload)
1083
+
1084
+ next()
1085
+ } catch {
1086
+ ctx.res.status(401).json({ message: 'Invalid or expired token' })
1087
+ }
1088
+ }
1089
+ `),u.push(d),u}async function Oe(t){let{name:n,moduleName:r,modulesDir:i,pattern:a}=t,o=W({type:`service`,outDir:t.outDir,moduleName:r,modulesDir:i,defaultDir:`src/services`,pattern:a,shouldPluralize:t.pluralize??!0}),s=E(n),c=w(n),l=[],u=f(o,`${s}.service.ts`);return await e(u,`import { Service } from '@forinda/kickjs'
1090
+
1091
+ @Service()
1092
+ export class ${c}Service {
1093
+ // Inject dependencies via constructor
1094
+ // constructor(
1095
+ // @Inject(MY_REPO) private readonly repo: IMyRepository,
1096
+ // ) {}
1097
+ }
1098
+ `),l.push(u),l}async function ke(t){let{name:n,moduleName:r,modulesDir:i,pattern:a}=t,o=W({type:`controller`,outDir:t.outDir,moduleName:r,modulesDir:i,defaultDir:`src/controllers`,pattern:a,shouldPluralize:t.pluralize??!0}),s=E(n),c=w(n),l=[],u=f(o,`${s}.controller.ts`);return await e(u,`import { Controller, Get, Post, type Ctx } from '@forinda/kickjs'
1099
+
1100
+ // \`Ctx<KickRoutes.${c}Controller['<method>']>\` is generated by
1101
+ // \`kick typegen\` (auto-run on \`kick dev\`). After the first run, your IDE
1102
+ // will autocomplete \`ctx.params\`, \`ctx.body\`, and \`ctx.query\`.
1103
+ // See https://forinda.github.io/kick-js/guide/typegen for details.
1104
+
1105
+ @Controller()
1106
+ export class ${c}Controller {
1107
+ // @Autowired() private readonly myService!: MyService
1108
+
1109
+ @Get('/')
1110
+ async list(ctx: Ctx<KickRoutes.${c}Controller['list']>) {
1111
+ ctx.json({ message: '${c} list' })
1112
+ }
1113
+
1114
+ @Post('/')
1115
+ async create(ctx: Ctx<KickRoutes.${c}Controller['create']>) {
1116
+ ctx.created({ message: '${c} created', data: ctx.body })
1117
+ }
1118
+ }
1119
+ `),l.push(u),l}async function Ae(t){let{name:n,moduleName:r,modulesDir:i,pattern:a}=t,o=W({type:`dto`,outDir:t.outDir,moduleName:r,modulesDir:i,defaultDir:`src/dtos`,pattern:a,shouldPluralize:t.pluralize??!0}),s=E(n),c=w(n),l=T(n),u=[],d=f(o,`${s}.dto.ts`);return await e(d,`import { z } from 'zod'
1120
+
1121
+ export const ${l}Schema = z.object({
1122
+ // Define your schema fields here
1123
+ name: z.string().min(1).max(200),
1124
+ })
1125
+
1126
+ export type ${c}DTO = z.infer<typeof ${l}Schema>
1127
+ `),u.push(d),u}const je={swagger:`@forinda/kickjs-swagger`,ws:`@forinda/kickjs-ws`,queue:`@forinda/kickjs-queue`,devtools:`@forinda/kickjs-devtools`},Me={zod:{name:`zod`,range:`^4.3.6`},valibot:{name:`valibot`,range:`^1.4.1`},yup:{name:`yup`,range:`^1.7.1`}};function G(e,t){let n=e[t];if(!n)throw Error(`generatePackageJson: missing resolved version for ${t}. Add it to SIBLING_PACKAGES in generators/project.ts.`);return n}function Ne(e,t,n,r=[],i=`zod`){let a=Me[i],o={"@forinda/kickjs":G(n,`@forinda/kickjs`),"@forinda/kickjs-schema":G(n,`@forinda/kickjs-schema`),dotenv:`^17.3.1`,express:`^5.1.0`,"reflect-metadata":`^0.2.2`,[a.name]:a.range};for(let e of r){let t=je[e];t&&!o[t]&&(o[t]=G(n,t))}return JSON.stringify({name:e,version:`0.0.0`,type:`module`,scripts:{dev:`vite`,"dev:debug":`kick dev:debug`,build:`kick build`,start:`kick start`,test:`vitest run`,"test:watch":`vitest`,typecheck:`tsc --noEmit`,typegen:`kick typegen`,lint:`eslint src/`,format:`prettier --write src/`},dependencies:o,devDependencies:{"@forinda/kickjs-cli":G(n,`@forinda/kickjs-cli`),"@forinda/kickjs-vite":G(n,`@forinda/kickjs-vite`),"@swc/core":`^1.15.21`,"@types/express":`^5.0.6`,"@types/node":`^25.0.0`,"unplugin-swc":`^1.5.9`,vite:`^8.0.3`,vitest:`^4.1.2`,typescript:`^6.0.3`,prettier:`^3.8.1`}},null,2)}function Pe(){return`import { defineConfig } from 'vite'
1128
+ import { resolve } from 'node:path'
1129
+ import swc from 'unplugin-swc'
1130
+ import { kickjsVitePlugin, envWatchPlugin } from '@forinda/kickjs-vite'
1131
+
1132
+ export default defineConfig({
1133
+ oxc: false,
1134
+ plugins: [
1135
+ swc.vite(),
1136
+ kickjsVitePlugin({ entry: 'src/index.ts' }),
1137
+ // Watches .env files and triggers a full reload on change so the
1138
+ // dev server picks up env tweaks without a manual restart.
1139
+ envWatchPlugin(),
1140
+ ],
1141
+ resolve: {
1142
+ alias: {
1143
+ '@': resolve(__dirname, 'src'),
1144
+ },
1145
+ },
1146
+ build: {
1147
+ target: 'node20',
1148
+ ssr: true,
1149
+ outDir: 'dist',
1150
+ sourcemap: true,
1151
+ rollupOptions: {
1152
+ input: resolve(__dirname, 'src/index.ts'),
1153
+ output: { format: 'esm' },
1154
+ },
1155
+ },
1156
+ })
1157
+ `}function Fe(){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`,paths:{"@/*":[`./src/*`]}},include:[`src`,`.kickjs/types/**/*.d.ts`,`.kickjs/types/**/*.ts`]},null,2)}function Ie(){return JSON.stringify({semi:!1,singleQuote:!0,trailingComma:`all`,printWidth:100,tabWidth:2},null,2)}function Le(){return`# https://editorconfig.org
1158
+ root = true
1159
+
1160
+ [*]
1161
+ indent_style = space
1162
+ indent_size = 2
1163
+ end_of_line = lf
1164
+ charset = utf-8
1165
+ trim_trailing_whitespace = true
1166
+ insert_final_newline = true
1167
+
1168
+ [*.md]
1169
+ trim_trailing_whitespace = false
1170
+ `}function Re(){return`node_modules/
1171
+ dist/
1172
+ .env
1173
+ coverage/
1174
+ .DS_Store
1175
+ *.tsbuildinfo
1176
+ .kickjs/
1177
+ `}function ze(){return`# Auto-detect text files and normalise line endings to LF
1178
+ * text=auto eol=lf
1179
+
1180
+ # Explicitly mark generated / binary files
1181
+ *.png binary
1182
+ *.jpg binary
1183
+ *.jpeg binary
1184
+ *.gif binary
1185
+ *.ico binary
1186
+ *.woff binary
1187
+ *.woff2 binary
1188
+ *.ttf binary
1189
+ *.eot binary
1190
+
1191
+ # Lock files — treat as generated
1192
+ pnpm-lock.yaml -diff linguist-generated
1193
+ yarn.lock -diff linguist-generated
1194
+ package-lock.json -diff linguist-generated
1195
+ `}function Be(){return`PORT=3000
1196
+ NODE_ENV=development
1197
+ `}function Ve(){return`PORT=3000
1198
+ NODE_ENV=development
1199
+ `}function He(){return`import { defineConfig } from 'vitest/config'
1200
+ import swc from 'unplugin-swc'
1201
+
1202
+ export default defineConfig({
1203
+ plugins: [swc.vite()],
1204
+ test: {
1205
+ globals: true,
1206
+ environment: 'node',
1207
+ include: ['src/**/*.test.ts'],
1208
+ },
1209
+ })
1210
+ `}const Ue=d(ee(import.meta.url)),K=JSON.parse(g(f(Ue,`..`,`package.json`),`utf-8`)),We=`^${K.version}`,Ge=[`@forinda/kickjs`,`@forinda/kickjs-cli`,`@forinda/kickjs-schema`,`@forinda/kickjs-vite`,`@forinda/kickjs-swagger`,`@forinda/kickjs-ws`,`@forinda/kickjs-queue`,`@forinda/kickjs-devtools`,`@forinda/kickjs-testing`];async function Ke(){let e=await Promise.all(Ge.map(async e=>{try{let t=S(`npm`,[`view`,e,`version`],{encoding:`utf-8`,timeout:5e3,stdio:[`ignore`,`pipe`,`ignore`]}).toString().trim();if(t&&/^\d+\.\d+\.\d+/.test(t))return[e,`^${t}`]}catch{}return[e,We]}));return Object.fromEntries(e)}async function qe(t){let{name:n,directory:r,packageManager:i=`pnpm`,template:o=`rest`,defaultRepo:s=`inmemory`,packages:c=[],schemaLib:l=`zod`}=t,u=r,d=e=>console.log(` ${e}`);console.log(`\n Creating KickJS project: ${n}\n`),d(`Resolving package versions...`);let p=await Ke();await e(f(u,`package.json`),Ne(n,o,p,c,l)),await e(f(u,`vite.config.ts`),Pe()),await e(f(u,`tsconfig.json`),Fe()),await e(f(u,`.prettierrc`),Ie()),await e(f(u,`.editorconfig`),Le()),await e(f(u,`.gitignore`),Re()),await e(f(u,`.gitattributes`),ze()),await e(f(u,`.env`),Be()),await e(f(u,`.env.example`),Ve()),await e(f(u,`src/config/index.ts`),me(l)),await e(f(u,`src/index.ts`),fe(n,o,K.version,c)),await e(f(u,`src/modules/index.ts`),pe()),await e(f(u,`src/modules/hello/hello.service.ts`),he()),await e(f(u,`src/modules/hello/hello.controller.ts`),R()),await e(f(u,`src/modules/hello/hello.module.ts`),ge()),await e(f(u,`kick.config.ts`),_e(o,s,i)),await e(f(u,`vitest.config.ts`),He()),await e(f(u,`README.md`),a(n,o,i));let{generateAgentDocs:m}=await import(`./agent-docs-Dmku65k2.mjs`).then(e=>e.t);if(await m({outDir:u,name:n,pm:i,template:o,only:`all`,force:!0}),t.installDeps){console.log(`\n Installing dependencies with ${i}...\n`);try{C(`${i} install`,{cwd:u,stdio:`inherit`}),console.log(`
1211
+ Dependencies installed successfully!`)}catch{console.log(`\n Warning: ${i} install failed. Run it manually.`)}}try{let{runTypegen:e}=await import(`./typegen-5MX2F5iL.mjs`).then(e=>e.n);await e({cwd:u,allowDuplicates:!0,silent:!0})}catch{}if(t.initGit)try{C(`git init`,{cwd:u,stdio:`pipe`}),C(`git branch -M main`,{cwd:u,stdio:`pipe`}),C(`git add -A`,{cwd:u,stdio:`pipe`}),C(`git commit -m "chore: initial commit from kick new"`,{cwd:u,stdio:`pipe`}),d(`Git repository initialized`)}catch{d(`Warning: git init failed (git may not be installed)`)}console.log(`
1212
+ Project scaffolded successfully!`),console.log();let h=u!==process.cwd();d(`Next steps:`),h&&d(` cd ${n}`),t.installDeps||d(` ${i} install`);let g={rest:`kick g module user`,ddd:`kick g module user --repo drizzle`,cqrs:`kick g module user --pattern cqrs`,minimal:`# add your routes to src/index.ts`};d(` ${g[o]??g.rest}`),d(` kick dev`),d(``),d(`Commands:`),d(` kick dev Start dev server with Vite HMR`),d(` kick build Production build via Vite`),d(` kick start Run production build`),d(``),d(`Generators:`),d(` kick g module <name> Full DDD module (controller, DTOs, use-cases, repo)`),d(` kick g scaffold <n> <f..> CRUD module from field definitions`),d(` kick g controller <name> Standalone controller`),d(` kick g service <name> @Service() class`),d(` kick g middleware <name> Express middleware`),d(` kick g guard <name> Route guard (auth, roles, etc.)`),d(` kick g adapter <name> AppAdapter with lifecycle hooks`),d(` kick g dto <name> Zod DTO schema`),d(` kick g config Generate kick.config.ts`),d(``),d(`Add packages:`),d(` kick add <pkg> Install a KickJS package + peers`),d(` kick add --list Show all available packages`),d(``),d(`Available: auth, swagger, drizzle, prisma, ws, queue, devtools, mcp, testing`),d(``)}function Je(e){return E(e).replace(/-/g,`_`)}function q(e){let t=e.cwd??process.cwd(),n=e.projectRoot??l(t),r=e.pluralize??!0,i=w(e.name),a=T(e.name),o=E(e.name),s=Je(e.name),c={name:e.name,pascal:i,camel:a,kebab:o,snake:s,modulesDir:e.modulesDir??`src/modules`,cwd:t,projectRoot:n,args:e.args??[],flags:e.flags??{}};if(r){let e=D(o);c.pluralKebab=e,c.pluralPascal=w(e),c.pluralCamel=T(e)}return c}function Ye(e,t){return m(e.cwd,t)}async function Xe(e){return import(te(e).href)}const J=new Map;async function Y(e){let t=J.get(e);if(t)return t;let n=Ze(e);return J.set(e,n),n}async function Ze(e){let t=m(e,`package.json`);if(!h(t))return{generators:[],loaded:[],failed:[]};let n=Qe(JSON.parse(await y(t,`utf-8`))),r=u(m(e,`package.json`)),i=[],a=[],o=[];for(let e of n){let t;try{t=r.resolve(`${e}/package.json`)}catch{continue}let n;try{n=JSON.parse(await y(t,`utf-8`))}catch(t){o.push({source:e,reason:`failed to parse package.json: ${t}`});continue}if(!n.kickjs?.generators)continue;let s=n.kickjs.generators,c=m(d(t),s);if(!h(c)){o.push({source:e,reason:`kickjs.generators points to missing file: ${s}`});continue}let l;try{l=await Xe(c)}catch(t){o.push({source:e,reason:`failed to import manifest: ${t}`});continue}let u=l.default;if(!Array.isArray(u)){o.push({source:e,reason:`manifest's default export is not an array of GeneratorSpec`});continue}for(let t of u){if(!$e(t)){o.push({source:e,reason:`manifest entry is not a valid GeneratorSpec (missing name/files)`});continue}i.push({source:e,spec:t})}a.push(e)}return{generators:i,loaded:a,failed:o}}function Qe(e){let t=new Set;for(let n of[e.dependencies,e.devDependencies,e.peerDependencies])if(n)for(let e of Object.keys(n))t.add(e);return Array.from(t)}function $e(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.name==`string`&&typeof t.files==`function`}async function et(e,t=[]){let n=e.cwd??process.cwd(),r=t.find(t=>t.spec.name===e.generatorName);if(r)return X(r.spec,r.source,e,n);let i=nt(await Y(n),e.generatorName);return i?X(i.spec,i.source,e,n):null}async function tt(e,t=[]){let n=await Y(e),r=new Set(t.map(e=>e.spec.name)),i=n.generators.filter(e=>!r.has(e.spec.name));return{generators:[...t,...i],loaded:n.loaded,failed:n.failed}}function nt(e,t){return e.generators.find(e=>e.spec.name===t)}async function X(t,n,r,i){let a=q({name:r.itemName,args:r.args,flags:r.flags,modulesDir:r.modulesDir,pluralize:r.pluralize,cwd:i,projectRoot:r.projectRoot}),o=await t.files(a),s=[];for(let t of o){let n=Ye(a,t.path);await e(n,t.content),s.push(n)}return{files:s,source:n}}function rt(e){return e}function it(e){return e}function Z(e){try{return JSON.parse(g(e,`utf-8`))}catch{return null}}function Q(e){try{return g(e,`utf-8`)}catch{return null}}function at(e){let t=Q(f(e,`tsconfig.json`));if(!t)return null;let n=t.replace(/\/\*[\s\S]*?\*\//g,``).replace(/\/\/.*$/gm,``),r;try{r=JSON.parse(n)}catch{return null}if(typeof r?.extends==`string`){let t=ot(e,r.extends);if(t){let e=Z(t)??{};r.compilerOptions={...e.compilerOptions,...r.compilerOptions}}}return r}function ot(e,t){if(t.startsWith(`.`)){let n=m(e,t);return h(n)?n:null}let n=f(e,`node_modules`,t);return h(n)?n:null}function st(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function ct(){let e=process.version,t=Number.parseInt(e.replace(/^v/,``).split(`.`)[0],10);return Number.isNaN(t)||t<20?{name:`Node version`,status:`fail`,message:e,fix:`KickJS requires Node 20 or newer.
1213
+ Install a supported version via nvm / fnm / volta.`}:{name:`Node version`,status:`pass`,message:e}}function lt(e){if(!e.pkg)return{name:`@forinda/kickjs installed`,status:`warn`,message:`no package.json`};let t={...e.pkg.dependencies,...e.pkg.peerDependencies};return t[`@forinda/kickjs`]?{name:`@forinda/kickjs installed`,status:`pass`,message:t[`@forinda/kickjs`]}:{name:`@forinda/kickjs installed`,status:`fail`,fix:"This directory does not look like a KickJS project — `@forinda/kickjs` is not in your package.json. Run `kick doctor` from the project root, or scaffold a fresh project with `kick new <name>`."}}function ut(e){if(!e.pkg)return null;let t={...e.pkg.dependencies,...e.pkg.peerDependencies};return t[`@forinda/kickjs`]&&!t.express?{name:`express installed`,status:`fail`,fix:"`@forinda/kickjs` declares `express` as a required peer dependency, but your package.json does not include it. Install: pnpm add express"}:t.express?{name:`express installed`,status:`pass`,message:t.express}:null}function dt(e){if(!e.pkg)return{name:`reflect-metadata installed`,status:`warn`,message:`no package.json`};let t={...e.pkg.dependencies,...e.pkg.peerDependencies,...e.pkg.devDependencies};return t[`reflect-metadata`]?{name:`reflect-metadata installed`,status:`pass`,message:t[`reflect-metadata`]}:{name:`reflect-metadata installed`,status:`fail`,fix:`KickJS decorators require the reflect-metadata polyfill.
1214
+ Install it: pnpm add reflect-metadata
1215
+ Then import it at the top of src/index.ts:
1216
+
1217
+ import 'reflect-metadata'
1218
+ // ... rest of bootstrap`}}function ft(e){if(!e.tsconfig)return[{name:`tsconfig.json present`,status:`fail`,fix:"Create a tsconfig.json with `experimentalDecorators: true` and `emitDecoratorMetadata: true`. `kick new` scaffolds one automatically."}];let t=e.tsconfig.compilerOptions??{},n=[];return n.push(t.experimentalDecorators===!0?{name:`tsconfig: experimentalDecorators`,status:`pass`}:{name:`tsconfig: experimentalDecorators`,status:`fail`,fix:'Add `"experimentalDecorators": true` to compilerOptions in tsconfig.json. Without it, @Service / @Controller / @Get etc. don\'t register any metadata at compile time.'}),n.push(t.emitDecoratorMetadata===!0?{name:`tsconfig: emitDecoratorMetadata`,status:`pass`}:{name:`tsconfig: emitDecoratorMetadata`,status:`fail`,fix:'Add `"emitDecoratorMetadata": true` to compilerOptions in tsconfig.json. The DI container uses this metadata for constructor-parameter injection.'}),n}function $(e){let t=[`src/env.ts`,`src/env/index.ts`,`src/config/env.ts`,`src/config/index.ts`].map(t=>f(e.cwd,t)).filter(e=>h(e)).filter(e=>/\bloadEnv\s*\(/.test(Q(e)??``));if(t.length===0)return null;let n=[`src/index.ts`,`src/main.ts`].map(t=>f(e.cwd,t)).find(e=>h(e));if(!n)return{name:`env wiring`,status:`warn`,message:`env-init file exists but no src/index.ts or src/main.ts found`};let r=Q(n)??``,i=d(n),a=[];for(let e of t){let t=p(i,e).replace(/\\/g,`/`).replace(/\.ts$/,``),n=t.startsWith(`.`)?t:`./`+t,r=n.replace(/\/index$/,``);a.push(n,r);let o=e.replace(/\\/g,`/`).match(/\/src\/(.+?)(?:\.ts)?$/);if(o){let e=`@/`+o[1],t=e.replace(/\/index$/,``);a.push(e,t)}}let o=-1;for(let e of new Set(a)){let t=RegExp(`^import\\s+(?:.*?from\\s+)?['"]${st(e)}['"]`,`m`),n=r.match(t);n&&n.index!==void 0&&(o===-1||n.index<o)&&(o=n.index)}let s=r.search(/\bbootstrap\s*\(/),c=t.map(t=>p(e.cwd,t).replace(/\\/g,`/`)).join(`, `);return o===-1?{name:`env wiring`,status:`fail`,message:c,fix:`An env-init file (${c}) calls \`loadEnv(...)\` but \`${p(e.cwd,n).replace(/\\/g,`/`)}\` doesn't import it.\nWithout this, ConfigService.get('X') returns undefined while @Value('X') works via process.env fallback — a half-broken config you won't notice until something is missing.\n\nFix: add a side-effect import at the top of ${p(e.cwd,n).replace(/\\/g,`/`)} (above bootstrap()), pointing at one of the detected files. For example:\n\n import './env'\n // or\n import './config'\n // or, with the @/ alias:\n import '@/config/env'`}:s!==-1&&o>s?{name:`env wiring`,status:`warn`,message:`env-init imported AFTER bootstrap() — should be before`,fix:`Move the env import above the bootstrap() call so the schema runs before any service reads from ConfigService.`}:{name:`env wiring`,status:`pass`}}function pt(e,t=mt){let n=0,r=0,i=[e];for(;i.length>0&&r<t;){let e=i.pop(),a;try{a=_(e,{withFileTypes:!0})}catch{continue}for(let o of a){if(r>=t)break;r++;let a=f(e,o.name);if(o.isDirectory()){i.push(a);continue}try{let e=v(a).mtimeMs;e>n&&(n=e)}catch{}}}return n}const mt=2e3;function ht(e){let t=f(e.cwd,`.kickjs`,`types`);if(!h(t))return null;let n=pt(t);if(n===0)return null;let r=Date.now()-n,i=Math.floor(r/6e4);return i>60?{name:`typegen freshness`,status:`warn`,message:`last updated ${i} minutes ago`,fix:"Re-run `kick typegen` (or `kick dev`, which runs it on every reload) so generated types match the current code."}:{name:`typegen freshness`,status:`pass`,message:i===0?`just now`:`${i}m ago`}}const gt=[()=>ct(),lt,ut,dt,ft,$,ht];async function _t(e,t={}){let n={cwd:e,pkg:Z(f(e,`package.json`)),tsconfig:at(e)},r=[...gt,...t.extraChecks??[]],i=[];for(let e of r){let t;try{t=await e(n)}catch(t){i.push({name:e.name||`doctor check`,status:`fail`,message:t instanceof Error?t.message:String(t)});continue}t!=null&&(Array.isArray(t)?i.push(...t):i.push(t))}return i}function vt(e){switch(e){case`pass`:return r.green(`✔`);case`warn`:return r.yellow(`⚠`);case`fail`:return r.red(`✖`)}}function yt(e){let t=vt(e.status),n=e.message?` ${r.dim(`(${e.message})`)}`:``;return`${t} ${e.name}${n}`}function bt(e){return e.split(`
1219
+ `).map(e=>` ${r.dim(`→`)} ${e}`).join(`
1220
+ `)}function xt(e){return e?.doctor?.checks??[]}function St(e){e.command(`doctor`).description(`Pre-flight checks for your KickJS project (dev environment health)`).action(async()=>{let e=process.cwd(),a=xt(await c(e));t(`KickJS Doctor`);let o=await _t(e,{extraChecks:a});for(let e of o)i.message(yt(e)),e.fix&&e.status!==`pass`&&i.message(bt(e.fix));let s=o.filter(e=>e.status===`pass`).length,l=o.filter(e=>e.status===`warn`).length,u=o.filter(e=>e.status===`fail`).length,d=[r.green(`${s} passed`),l>0?r.yellow(`${l} warning${l===1?``:`s`}`):`${l} warnings`,u>0?r.red(`${u} error${u===1?``:`s`}`):`${u} errors`].join(`, `);u>0?(n(`${d} — fix the errors above before running the app`),process.exit(1)):n(l>0?`${d} — review the warnings`:r.green(`${d} — your environment looks good`))})}export{T as A,P as C,k as D,j as E,w as M,D as O,F as S,M as T,V as _,et as a,L as b,qe as c,Oe as d,De as f,z as g,we as h,tt as i,E as j,O as k,Ae as l,W as m,rt as n,q as o,Ee as p,St as r,ne as s,it as t,ke as u,xe as v,N as w,I as x,be as y};
1221
+ //# sourceMappingURL=doctor-SUUDEI1J.mjs.map