@forinda/kickjs-cli 1.2.8 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +51 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.js +51 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -326,6 +326,28 @@ export const ${pascal.toUpperCase()}_QUERY_CONFIG: QueryParamsConfig = {
|
|
|
326
326
|
`;
|
|
327
327
|
}
|
|
328
328
|
__name(generateConstants, "generateConstants");
|
|
329
|
+
function generateDrizzleConstants(pascal, kebab) {
|
|
330
|
+
return `import type { DrizzleQueryParamsConfig } from '@forinda/kickjs-drizzle'
|
|
331
|
+
// TODO: Import your schema table and reference actual columns for type safety
|
|
332
|
+
// import { ${kebab}s } from '@/db/schema'
|
|
333
|
+
|
|
334
|
+
export const ${pascal.toUpperCase()}_QUERY_CONFIG: DrizzleQueryParamsConfig = {
|
|
335
|
+
columns: {
|
|
336
|
+
// Replace with actual Drizzle Column references for type-safe filtering:
|
|
337
|
+
// name: ${kebab}s.name,
|
|
338
|
+
// status: ${kebab}s.status,
|
|
339
|
+
},
|
|
340
|
+
sortable: {
|
|
341
|
+
// name: ${kebab}s.name,
|
|
342
|
+
// createdAt: ${kebab}s.createdAt,
|
|
343
|
+
},
|
|
344
|
+
searchColumns: [
|
|
345
|
+
// ${kebab}s.name,
|
|
346
|
+
],
|
|
347
|
+
}
|
|
348
|
+
`;
|
|
349
|
+
}
|
|
350
|
+
__name(generateDrizzleConstants, "generateDrizzleConstants");
|
|
329
351
|
|
|
330
352
|
// src/generators/templates/dtos.ts
|
|
331
353
|
function generateCreateDTO(pascal, kebab) {
|
|
@@ -573,65 +595,73 @@ function generateDrizzleRepository(pascal, kebab, repoPrefix = "../../domain/rep
|
|
|
573
595
|
* Drizzle ${pascal} Repository
|
|
574
596
|
*
|
|
575
597
|
* Implements the repository interface using Drizzle ORM.
|
|
576
|
-
*
|
|
598
|
+
* Uses buildFromColumns() with Column objects for type-safe query building.
|
|
577
599
|
*
|
|
578
600
|
* TODO: Update the schema import to match your Drizzle schema file.
|
|
579
|
-
* TODO: Replace
|
|
601
|
+
* TODO: Replace DRIZZLE_DB injection token with your actual database token.
|
|
580
602
|
*
|
|
581
603
|
* @Repository() registers this class in the DI container as a singleton.
|
|
582
604
|
*/
|
|
583
|
-
import { eq, sql } from 'drizzle-orm'
|
|
584
|
-
import { Repository, HttpException,
|
|
605
|
+
import { eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc, count, sql } from 'drizzle-orm'
|
|
606
|
+
import { Repository, HttpException, Inject } from '@forinda/kickjs-core'
|
|
607
|
+
import { DRIZZLE_DB, DrizzleQueryAdapter } from '@forinda/kickjs-drizzle'
|
|
585
608
|
import type { ParsedQuery } from '@forinda/kickjs-http'
|
|
586
609
|
import type { I${pascal}Repository } from '${repoPrefix}/${kebab}.repository'
|
|
587
610
|
import type { ${pascal}ResponseDTO } from '${dtoPrefix}/${kebab}-response.dto'
|
|
588
611
|
import type { Create${pascal}DTO } from '${dtoPrefix}/create-${kebab}.dto'
|
|
589
612
|
import type { Update${pascal}DTO } from '${dtoPrefix}/update-${kebab}.dto'
|
|
613
|
+
import { ${pascal.toUpperCase()}_QUERY_CONFIG } from '../../constants'
|
|
590
614
|
|
|
591
615
|
// TODO: Import your Drizzle schema table \u2014 e.g.:
|
|
592
616
|
// import { ${kebab}s } from '@/db/schema'
|
|
593
617
|
|
|
594
|
-
|
|
595
|
-
|
|
618
|
+
const queryAdapter = new DrizzleQueryAdapter({
|
|
619
|
+
eq, ne, gt, gte, lt, lte, ilike, inArray, between, and, or, asc, desc,
|
|
620
|
+
})
|
|
596
621
|
|
|
597
622
|
@Repository()
|
|
598
623
|
export class Drizzle${pascal}Repository implements I${pascal}Repository {
|
|
599
|
-
|
|
600
|
-
// @Autowired(DRIZZLE_DB) private db!: DrizzleDB
|
|
624
|
+
constructor(@Inject(DRIZZLE_DB) private db: any) {}
|
|
601
625
|
|
|
602
626
|
async findById(id: string): Promise<${pascal}ResponseDTO | null> {
|
|
603
627
|
// TODO: Implement with Drizzle
|
|
604
|
-
// const
|
|
628
|
+
// const row = this.db.select().from(${kebab}s).where(eq(${kebab}s.id, id)).get()
|
|
605
629
|
// return row ?? null
|
|
606
630
|
throw new Error('Drizzle ${pascal} repository not yet implemented \u2014 update schema imports and queries')
|
|
607
631
|
}
|
|
608
632
|
|
|
609
633
|
async findAll(): Promise<${pascal}ResponseDTO[]> {
|
|
610
634
|
// TODO: Implement with Drizzle
|
|
611
|
-
// return this.db.select().from(${kebab}s)
|
|
635
|
+
// return this.db.select().from(${kebab}s).all()
|
|
612
636
|
throw new Error('Drizzle ${pascal} repository not yet implemented')
|
|
613
637
|
}
|
|
614
638
|
|
|
615
639
|
async findPaginated(parsed: ParsedQuery): Promise<{ data: ${pascal}ResponseDTO[]; total: number }> {
|
|
616
|
-
// TODO:
|
|
617
|
-
// const
|
|
618
|
-
//
|
|
619
|
-
//
|
|
620
|
-
//
|
|
621
|
-
//
|
|
640
|
+
// TODO: Use buildFromColumns() with your query config for type-safe filtering
|
|
641
|
+
// const query = queryAdapter.buildFromColumns(parsed, ${pascal.toUpperCase()}_QUERY_CONFIG)
|
|
642
|
+
//
|
|
643
|
+
// const data = this.db
|
|
644
|
+
// .select().from(${kebab}s).$dynamic()
|
|
645
|
+
// .where(query.where).orderBy(...query.orderBy)
|
|
646
|
+
// .limit(query.limit).offset(query.offset).all()
|
|
647
|
+
//
|
|
648
|
+
// const totalResult = this.db
|
|
649
|
+
// .select({ count: count() }).from(${kebab}s)
|
|
650
|
+
// .$dynamic().where(query.where).get()
|
|
651
|
+
//
|
|
652
|
+
// return { data, total: totalResult?.count ?? 0 }
|
|
622
653
|
throw new Error('Drizzle ${pascal} repository not yet implemented')
|
|
623
654
|
}
|
|
624
655
|
|
|
625
656
|
async create(dto: Create${pascal}DTO): Promise<${pascal}ResponseDTO> {
|
|
626
657
|
// TODO: Implement with Drizzle
|
|
627
|
-
//
|
|
628
|
-
// return row
|
|
658
|
+
// return this.db.insert(${kebab}s).values(dto).returning().get()
|
|
629
659
|
throw new Error('Drizzle ${pascal} repository not yet implemented')
|
|
630
660
|
}
|
|
631
661
|
|
|
632
662
|
async update(id: string, dto: Update${pascal}DTO): Promise<${pascal}ResponseDTO> {
|
|
633
663
|
// TODO: Implement with Drizzle
|
|
634
|
-
// const
|
|
664
|
+
// const row = this.db.update(${kebab}s).set(dto).where(eq(${kebab}s.id, id)).returning().get()
|
|
635
665
|
// if (!row) throw HttpException.notFound('${pascal} not found')
|
|
636
666
|
// return row
|
|
637
667
|
throw new Error('Drizzle ${pascal} repository not yet implemented')
|
|
@@ -639,8 +669,7 @@ export class Drizzle${pascal}Repository implements I${pascal}Repository {
|
|
|
639
669
|
|
|
640
670
|
async delete(id: string): Promise<void> {
|
|
641
671
|
// TODO: Implement with Drizzle
|
|
642
|
-
//
|
|
643
|
-
// if (!result.rowCount) throw HttpException.notFound('${pascal} not found')
|
|
672
|
+
// this.db.delete(${kebab}s).where(eq(${kebab}s.id, id)).run()
|
|
644
673
|
throw new Error('Drizzle ${pascal} repository not yet implemented')
|
|
645
674
|
}
|
|
646
675
|
}
|
|
@@ -1543,7 +1572,7 @@ __name(generateCqrsFiles, "generateCqrsFiles");
|
|
|
1543
1572
|
async function generateDddFiles(ctx) {
|
|
1544
1573
|
const { pascal, kebab, plural, pluralPascal, repo, noEntity, noTests, write } = ctx;
|
|
1545
1574
|
await write("index.ts", generateModuleIndex(pascal, kebab, plural, repo));
|
|
1546
|
-
await write("constants.ts", generateConstants(pascal));
|
|
1575
|
+
await write("constants.ts", repo === "drizzle" ? generateDrizzleConstants(pascal, kebab) : generateConstants(pascal));
|
|
1547
1576
|
await write(`presentation/${kebab}.controller.ts`, generateController(pascal, kebab, plural, pluralPascal));
|
|
1548
1577
|
await write(`application/dtos/create-${kebab}.dto.ts`, generateCreateDTO(pascal, kebab));
|
|
1549
1578
|
await write(`application/dtos/update-${kebab}.dto.ts`, generateUpdateDTO(pascal, kebab));
|