@mikemajesty/microservice-crud 6.1.20 → 7.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 (41) hide show
  1. package/bin/microservice-crud +3 -2
  2. package/package.json +10 -6
  3. package/src/{cli.js → cli.mjs} +52 -46
  4. package/src/templates/core/entity/entity.mjs +35 -0
  5. package/src/templates/core/repository/{repository.js → repository.mjs} +2 -2
  6. package/src/templates/core/use-cases/__tests__/{create.spec.js → create.spec.mjs} +2 -2
  7. package/src/templates/core/use-cases/__tests__/{delete.spec.js → delete.spec.mjs} +2 -2
  8. package/src/templates/core/use-cases/__tests__/{get-by-id.spec.js → get-by-id.spec.mjs} +2 -2
  9. package/src/templates/core/use-cases/__tests__/{list.spec.js → list.spec.mjs} +3 -3
  10. package/src/templates/core/use-cases/__tests__/{update.spec.js → update.spec.mjs} +2 -2
  11. package/src/templates/core/use-cases/{create.js → create.mjs} +5 -5
  12. package/src/templates/core/use-cases/{delete.js → delete.mjs} +5 -5
  13. package/src/templates/core/use-cases/{get-by-id.js → get-by-id.mjs} +5 -5
  14. package/src/templates/core/use-cases/{list.js → list.mjs} +5 -5
  15. package/src/templates/core/use-cases/{update.js → update.mjs} +5 -5
  16. package/src/templates/core-sigle/entity/entity.mjs +35 -0
  17. package/src/templates/core-sigle/repository/{repository.js → repository.mjs} +2 -2
  18. package/src/templates/core-sigle/use-cases/{usecase.js → usecase.mjs} +6 -6
  19. package/src/templates/infra/{adapter.js → adapter.mjs} +2 -2
  20. package/src/templates/infra/{index.js → index.mjs} +1 -2
  21. package/src/templates/infra/{module.js → module.mjs} +2 -2
  22. package/src/templates/infra/{service.js → service.mjs} +5 -5
  23. package/src/templates/libs/{adapter.js → adapter.mjs} +2 -4
  24. package/src/templates/libs/{index.js → index.mjs} +1 -1
  25. package/src/templates/libs/{module.js → module.mjs} +2 -2
  26. package/src/templates/libs/{service.js → service.mjs} +5 -5
  27. package/src/templates/module/{controller.js → controller.mjs} +3 -3
  28. package/src/templates/module/{module.js → module.mjs} +2 -2
  29. package/src/templates/mongo/modules/{adapter.js → adapter.mjs} +2 -2
  30. package/src/templates/mongo/modules/{controller.js → controller.mjs} +3 -3
  31. package/src/templates/mongo/modules/{module.js → module.mjs} +2 -2
  32. package/src/templates/mongo/modules/{repository.js → repository.mjs} +3 -3
  33. package/src/templates/mongo/schemas/{schema.js → schema.mjs} +3 -3
  34. package/src/templates/postgres/modules/{adapter.js → adapter.mjs} +2 -2
  35. package/src/templates/postgres/modules/{controller.js → controller.mjs} +3 -3
  36. package/src/templates/postgres/modules/{module.js → module.mjs} +2 -2
  37. package/src/templates/postgres/modules/{repository.js → repository.mjs} +2 -2
  38. package/src/templates/postgres/schemas/{schema.js → schema.mjs} +3 -3
  39. package/src/templates/core/entity/entity.js +0 -35
  40. package/src/templates/core-sigle/entity/entity.js +0 -35
  41. /package/src/{textUtils.js → textUtils.mjs} +0 -0
@@ -1,3 +1,4 @@
1
1
  #! /usr/bin/env node
2
- require = require('esm')(module /*, options */)
3
- require('../src/cli').cli(process.argv);
2
+ import { cli } from '../src/cli.mjs';
3
+
4
+ cli(process.argv);
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@mikemajesty/microservice-crud",
3
- "version": "6.1.20",
3
+ "version": "7.0.0",
4
4
  "description": "Monorepo CLI",
5
5
  "main": "src/cli.js",
6
+ "type": "module",
6
7
  "scripts": {
7
8
  "permission": "chmod -R 777 ./bin/*",
8
- "crud": "ENV=local node ./bin/microservice-crud"
9
+ "crud": "ENV=local node ./bin/microservice-crud",
10
+ "check-newest:deps": "npx npm-check-updates"
9
11
  },
10
12
  "bin": {
11
13
  "@mikemajesty/microservice-crud": "bin/microservice-crud",
@@ -25,10 +27,12 @@
25
27
  "cli-select": "^1.1.2",
26
28
  "colorette": "^2.0.20",
27
29
  "esm": "^3.2.25",
28
- "fs": "^0.0.1-security",
29
- "fs-extra": "^11.2.0",
30
+ "fs-extra": "^11.3.0",
30
31
  "pluralize": "^8.0.0",
31
32
  "prompt-sync": "^4.2.0",
32
- "rimraf": "^5.0.10"
33
+ "rimraf": "^6.0.1"
34
+ },
35
+ "devDependencies": {
36
+ "npm-check-updates": "^17.1.15"
33
37
  }
34
- }
38
+ }
@@ -1,48 +1,55 @@
1
- import { getCoreSingleEntity } from './templates/core-sigle/entity/entity';
2
- import { getCoreSingleRepository } from './templates/core-sigle/repository/repository';
3
- import { getCoreSingleUsecaseCreate } from './templates/core-sigle/use-cases/usecase';
4
- import { getIndexInfra } from './templates/infra';
5
- import { getAdapterInfra } from './templates/infra/adapter';
6
- import { getModuleInfa } from './templates/infra/module';
7
- import { getServiceInfra } from './templates/infra/service';
8
- import { getIndexLib } from './templates/libs';
9
- import { getAdapterLib } from './templates/libs/adapter';
10
- import { getModuleLib } from './templates/libs/module';
11
- import { getServiceLib } from './templates/libs/service';
12
- import { getModuleControllerModule } from './templates/module/controller';
13
- import { getModuleModule } from './templates/module/module';
14
-
15
- const fs = require('fs');
16
- const { bold, green, red } = require('colorette');
17
- const fse = require('fs-extra');
18
- const path = require('path');
19
- const cliSelect = require('cli-select');
20
- const prompt = require('prompt-sync')();
21
-
22
- const { getCoreUsecaseCreateTest } = require('./templates/core/use-cases/__tests__/create.spec');
23
- const { getCoreUsecaseUpdateTest } = require('./templates/core/use-cases/__tests__/update.spec');
24
- const { getCoreUsecaseDeleteTest } = require('./templates/core/use-cases/__tests__/delete.spec');
25
- const { getCoreUsecaseListTest } = require('./templates/core/use-cases/__tests__/list.spec');
26
- const { getCoreUsecaseGetByIdTest } = require('./templates/core/use-cases/__tests__/get-by-id.spec');
27
- const { getCoreUsecaseGetById } = require('./templates/core/use-cases/get-by-id');
28
- const { getCoreUsecaseList } = require('./templates/core/use-cases/list');
29
- const { getCoreEntity } = require('./templates/core/entity/entity');
30
- const { getCoreRepository } = require('./templates/core/repository/repository');
31
- const { getCoreUsecaseCreate } = require('./templates/core/use-cases/create');
32
- const { getCoreUsecaseDelete } = require('./templates/core/use-cases/delete');
33
- const { getCoreUsecaseUpdate } = require('./templates/core/use-cases/update');
34
-
35
- const { getModuleAdapter } = require('./templates/postgres/modules/adapter');
36
- const { getModuleController } = require('./templates/postgres/modules/controller');
37
- const { getModule } = require('./templates/postgres/modules/module');
38
- const { getModuleRepository } = require('./templates/postgres/modules/repository');
39
- const { getModuleSchema } = require('./templates/postgres/schemas/schema');
40
-
41
- const { getModuleAdapter: getModuleAdapterMongo } = require('./templates/mongo/modules/adapter');
42
- const { getModuleController: getModuleControllerMongo } = require('./templates/mongo/modules/controller');
43
- const { getModule: getModuleMongo } = require('./templates/mongo/modules/module');
44
- const { getModuleRepository: getModuleRepositoryMongo } = require('./templates/mongo/modules/repository');
45
- const { getModuleSchema: getModuleSchemaMongo } = require('./templates/mongo/schemas/schema');
1
+ import { getCoreSingleUsecaseCreate } from './templates/core-sigle/use-cases/usecase.mjs';
2
+ import { getCoreSingleRepository } from './templates/core-sigle/repository/repository.mjs';
3
+ import { getCoreSingleEntity } from './templates/core-sigle/entity/entity.mjs';
4
+ import { getIndexInfra } from './templates/infra/index.mjs';
5
+ import getAdapterInfra from './templates/infra/adapter.mjs';
6
+ import { getModuleInfa } from './templates/infra/module.mjs';
7
+ import { getServiceInfra } from './templates/infra/service.mjs';
8
+ import { getIndexLib } from './templates/libs/index.mjs';
9
+ import { getAdapterLib } from './templates/libs/adapter.mjs';
10
+ import { getModuleLib } from './templates/libs/module.mjs';
11
+ import { getServiceLib } from './templates/libs/service.mjs';
12
+ import { getModuleControllerModule } from './templates/module/controller.mjs';
13
+ import { getModuleModule } from './templates/module/module.mjs';
14
+
15
+ import fs from 'fs';
16
+ import { bold, green, red } from 'colorette';
17
+ import fse from 'fs-extra';
18
+ import path from 'path';
19
+ import cliSelect from 'cli-select';
20
+ import promptSync from 'prompt-sync';
21
+ import { fileURLToPath } from 'url';
22
+ import { dirname } from 'path';
23
+
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const __dirname = dirname(__filename);
26
+
27
+ const prompt = promptSync();
28
+
29
+ import { getCoreUsecaseCreateTest } from './templates/core/use-cases/__tests__/create.spec.mjs';
30
+ import { getCoreUsecaseUpdateTest } from './templates/core/use-cases/__tests__/update.spec.mjs';
31
+ import { getCoreUsecaseDeleteTest } from './templates/core/use-cases/__tests__/delete.spec.mjs';
32
+ import { getCoreUsecaseListTest } from './templates/core/use-cases/__tests__/list.spec.mjs';
33
+ import { getCoreUsecaseGetByIdTest } from './templates/core/use-cases/__tests__/get-by-id.spec.mjs';
34
+ import { getCoreUsecaseGetById } from './templates/core/use-cases/get-by-id.mjs';
35
+ import { getCoreUsecaseList } from './templates/core/use-cases/list.mjs';
36
+ import { getCoreEntity } from './templates/core/entity/entity.mjs';
37
+ import { getCoreRepository } from './templates/core/repository/repository.mjs';
38
+ import { getCoreUsecaseCreate } from './templates/core/use-cases/create.mjs';
39
+ import { getCoreUsecaseDelete } from './templates/core/use-cases/delete.mjs';
40
+ import { getCoreUsecaseUpdate } from './templates/core/use-cases/update.mjs';
41
+
42
+ import { getModuleAdapter } from './templates/postgres/modules/adapter.mjs';
43
+ import { getModuleController } from './templates/postgres/modules/controller.mjs';
44
+ import { getModule } from './templates/postgres/modules/module.mjs';
45
+ import { getModuleRepository } from './templates/postgres/modules/repository.mjs';
46
+ import { getModuleSchema } from './templates/postgres/schemas/schema.mjs';
47
+
48
+ import { getModuleAdapter as getModuleAdapterMongo } from './templates/mongo/modules/adapter.mjs';
49
+ import { getModuleController as getModuleControllerMongo } from './templates/mongo/modules/controller.mjs';
50
+ import { getModule as getModuleMongo } from './templates/mongo/modules/module.mjs';
51
+ import { getModuleRepository as getModuleRepositoryMongo } from './templates/mongo/modules/repository.mjs';
52
+ import { getModuleSchema as getModuleSchemaMongo } from './templates/mongo/schemas/schema.mjs';
46
53
 
47
54
  const createModule = async (name) => {
48
55
  if (!name) throw new Error('--name is required')
@@ -378,7 +385,6 @@ export async function cli(args) {
378
385
  try {
379
386
 
380
387
  const dest = path.resolve(`${__dirname}/../../../../`)
381
-
382
388
  const src = paths[0]
383
389
 
384
390
  // VALIDATE
@@ -0,0 +1,35 @@
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
+
3
+ const getCoreEntity = (name) => `import { BaseEntity } from '@/utils/entity';;
4
+
5
+ import { Infer, InputValidator } from '@/utils/validator';
6
+
7
+ const ID = InputValidator.string().uuid();
8
+ const Name = InputValidator.string().min(1).max(200).trim();
9
+ const CreatedAt = InputValidator.date().nullish();
10
+ const UpdatedAt = InputValidator.date().nullish();
11
+ const DeletedAt = InputValidator.date().nullish();
12
+
13
+ export const ${dashToPascal(name)}EntitySchema = InputValidator.object({
14
+ id: ID,
15
+ name: Name,
16
+ createdAt: CreatedAt,
17
+ updatedAt: UpdatedAt,
18
+ deletedAt: DeletedAt
19
+ });
20
+
21
+ type ${dashToPascal(name)} = Infer<typeof ${dashToPascal(name)}EntitySchema>;
22
+
23
+ export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>() {
24
+ name!: string;
25
+
26
+ constructor(entity: ${dashToPascal(name)}) {
27
+ super(${dashToPascal(name)}EntitySchema);
28
+ Object.assign(this, this.validate(entity));
29
+ }
30
+ }
31
+ `
32
+
33
+ export {
34
+ getCoreEntity
35
+ }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
3
  const getCoreRepository = (name) => `import { IRepository } from '@/infra/repository';
4
4
 
@@ -10,6 +10,6 @@ export abstract class I${dashToPascal(name)}Repository extends IRepository<${das
10
10
  }
11
11
  `
12
12
 
13
- module.exports = {
13
+ export {
14
14
  getCoreRepository
15
15
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../../textUtils.mjs"
2
2
 
3
3
  const getCoreUsecaseCreateTest = (name) => `import { Test } from '@nestjs/testing';
4
4
  import { ZodIssue } from 'zod';
@@ -63,6 +63,6 @@ describe(${dashToPascal(name)}CreateUsecase.name, () => {
63
63
  });
64
64
  `
65
65
 
66
- module.exports = {
66
+ export {
67
67
  getCoreUsecaseCreateTest
68
68
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../../textUtils.mjs"
2
2
 
3
3
  const getCoreUsecaseDeleteTest = (name) => `import { Test } from '@nestjs/testing';
4
4
  import { ZodIssue } from 'zod';
@@ -73,6 +73,6 @@ describe(${dashToPascal(name)}DeleteUsecase.name, () => {
73
73
  });
74
74
  `
75
75
 
76
- module.exports = {
76
+ export {
77
77
  getCoreUsecaseDeleteTest
78
78
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../../textUtils.mjs"
2
2
 
3
3
  const getCoreUsecaseGetByIdTest = (name) => `import { Test } from '@nestjs/testing';
4
4
  import { ZodIssue } from 'zod';
@@ -68,6 +68,6 @@ describe(${dashToPascal(name)}GetByIdUsecase.name, () => {
68
68
  });
69
69
  `
70
70
 
71
- module.exports = {
71
+ export {
72
72
  getCoreUsecaseGetByIdTest
73
73
  }
@@ -1,6 +1,6 @@
1
1
 
2
- const pluralize = require('pluralize')
3
- const { dashToPascal, snakeToCamel } = require('../../../../textUtils')
2
+ import pluralize from 'pluralize'
3
+ import { dashToPascal, snakeToCamel } from '../../../../textUtils.mjs'
4
4
 
5
5
  const getCoreUsecaseListTest = (name) => `import { Test } from '@nestjs/testing';
6
6
  import { ZodIssue } from 'zod';
@@ -78,6 +78,6 @@ describe(${dashToPascal(name)}ListUsecase.name, () => {
78
78
  });
79
79
  `
80
80
 
81
- module.exports = {
81
+ export {
82
82
  getCoreUsecaseListTest
83
83
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../../textUtils.mjs"
2
2
 
3
3
  const getCoreUsecaseUpdateTest = (name) => `import { Test } from '@nestjs/testing';
4
4
  import { ZodIssue } from 'zod';
@@ -77,6 +77,6 @@ describe(${dashToPascal(name)}UpdateUsecase.name, () => {
77
77
  });
78
78
  `
79
79
 
80
- module.exports = {
80
+ export {
81
81
  getCoreUsecaseUpdateTest
82
82
  }
@@ -1,13 +1,13 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../textUtils.mjs"
2
2
 
3
- const getCoreUsecaseCreate = (name) => `import { z } from 'zod';
3
+ const getCoreUsecaseCreate = (name) => `import { ILoggerAdapter } from '@/infra/logger';
4
4
 
5
- import { ILoggerAdapter } from '@/infra/logger';
6
5
  import { CreatedModel } from '@/infra/repository';
7
6
  import { ValidateSchema } from '@/utils/decorators';
8
7
  import { IUsecase } from '@/utils/usecase';
9
8
  import { UUIDUtils } from '@/utils/uuid';
10
9
 
10
+ import { Infer } from '@/utils/validator';
11
11
  import { I${dashToPascal(name)}Repository } from '../repository/${name}';
12
12
  import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from './../entity/${name}';
13
13
 
@@ -33,10 +33,10 @@ export class ${dashToPascal(name)}CreateUsecase implements IUsecase {
33
33
  }
34
34
  }
35
35
 
36
- export type ${dashToPascal(name)}CreateInput = z.infer<typeof ${dashToPascal(name)}CreateSchema>;
36
+ export type ${dashToPascal(name)}CreateInput = Infer<typeof ${dashToPascal(name)}CreateSchema>;
37
37
  export type ${dashToPascal(name)}CreateOutput = CreatedModel;
38
38
  `
39
39
 
40
- module.exports = {
40
+ export {
41
41
  getCoreUsecaseCreate
42
42
  }
@@ -1,12 +1,12 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../textUtils.mjs"
2
2
 
3
- const getCoreUsecaseDelete = (name) => `import { z } from 'zod';
3
+ const getCoreUsecaseDelete = (name) => `import { I${dashToPascal(name)}Repository } from '@/core/${name}/repository/${name}';
4
4
 
5
- import { I${dashToPascal(name)}Repository } from '@/core/${name}/repository/${name}';
6
5
  import { ValidateSchema } from '@/utils/decorators';
7
6
  import { ApiNotFoundException } from '@/utils/exception';
8
7
  import { IUsecase } from '@/utils/usecase';
9
8
 
9
+ import { Infer } from '@/utils/validator';
10
10
  import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from '../entity/${name}';
11
11
 
12
12
  export const ${dashToPascal(name)}DeleteSchema = ${dashToPascal(name)}EntitySchema.pick({
@@ -34,10 +34,10 @@ export class ${dashToPascal(name)}DeleteUsecase implements IUsecase {
34
34
  }
35
35
  }
36
36
 
37
- export type ${dashToPascal(name)}DeleteInput = z.infer<typeof ${dashToPascal(name)}DeleteSchema>;
37
+ export type ${dashToPascal(name)}DeleteInput = Infer<typeof ${dashToPascal(name)}DeleteSchema>;
38
38
  export type ${dashToPascal(name)}DeleteOutput = ${dashToPascal(name)}Entity;
39
39
  `
40
40
 
41
- module.exports = {
41
+ export {
42
42
  getCoreUsecaseDelete
43
43
  }
@@ -1,12 +1,12 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../textUtils.mjs"
2
2
 
3
- const getCoreUsecaseGetById = (name) => `import { z } from 'zod';
3
+ const getCoreUsecaseGetById = (name) => `import { ${dashToPascal(name)}EntitySchema } from '@/core/${name}/entity/${name}';
4
4
 
5
- import { ${dashToPascal(name)}EntitySchema } from '@/core/${name}/entity/${name}';
6
5
  import { ValidateSchema } from '@/utils/decorators';
7
6
  import { ApiNotFoundException } from '@/utils/exception';
8
7
  import { IUsecase } from '@/utils/usecase';
9
8
 
9
+ import { Infer } from '@/utils/validator';
10
10
  import { ${dashToPascal(name)}Entity } from '../entity/${name}';
11
11
  import { I${dashToPascal(name)}Repository } from '../repository/${name}';
12
12
 
@@ -29,10 +29,10 @@ export class ${dashToPascal(name)}GetByIdUsecase implements IUsecase {
29
29
  }
30
30
  }
31
31
 
32
- export type ${dashToPascal(name)}GetByIdInput = z.infer<typeof ${dashToPascal(name)}GetByIdSchema>;
32
+ export type ${dashToPascal(name)}GetByIdInput = Infer<typeof ${dashToPascal(name)}GetByIdSchema>;
33
33
  export type ${dashToPascal(name)}GetByIdOutput = ${dashToPascal(name)}Entity;
34
34
  `
35
35
 
36
- module.exports = {
36
+ export {
37
37
  getCoreUsecaseGetById
38
38
  }
@@ -1,17 +1,17 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../textUtils.mjs"
2
2
 
3
- const getCoreUsecaseList = (name) => `import { z } from 'zod';
3
+ const getCoreUsecaseList = (name) => `import { ${dashToPascal(name)}Entity } from '@/core/${name}/entity/${name}';;
4
4
 
5
- import { ${dashToPascal(name)}Entity } from '@/core/${name}/entity/${name}';
6
5
  import { ValidateSchema } from '@/utils/decorators';
7
6
  import { PaginationInput, PaginationOutput, PaginationSchema } from '@/utils/pagination';
8
7
  import { SearchSchema } from '@/utils/search';
9
8
  import { SortSchema } from '@/utils/sort';
10
9
  import { IUsecase } from '@/utils/usecase';
11
10
 
11
+ import { InputValidator } from '@/utils/validator';
12
12
  import { I${dashToPascal(name)}Repository } from '../repository/${name}';
13
13
 
14
- export const ${dashToPascal(name)}ListSchema = z.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
14
+ export const ${dashToPascal(name)}ListSchema = InputValidator.intersection(PaginationSchema, SortSchema.merge(SearchSchema));
15
15
 
16
16
  export class ${dashToPascal(name)}ListUsecase implements IUsecase {
17
17
  constructor(private readonly ${snakeToCamel(name)}Repository: I${dashToPascal(name)}Repository) {}
@@ -26,6 +26,6 @@ export type ${dashToPascal(name)}ListInput = PaginationInput<${dashToPascal(name
26
26
  export type ${dashToPascal(name)}ListOutput = PaginationOutput<${dashToPascal(name)}Entity>;
27
27
  `
28
28
 
29
- module.exports = {
29
+ export {
30
30
  getCoreUsecaseList
31
31
  }
@@ -1,13 +1,13 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../textUtils.mjs"
2
2
 
3
- const getCoreUsecaseUpdate = (name) => `import { z } from 'zod';
3
+ const getCoreUsecaseUpdate = (name) => `import { I${dashToPascal(name)}Repository } from '@/core/${name}/repository/${name}';;
4
4
 
5
- import { I${dashToPascal(name)}Repository } from '@/core/${name}/repository/${name}';
6
5
  import { ILoggerAdapter } from '@/infra/logger';
7
6
  import { ValidateSchema } from '@/utils/decorators';
8
7
  import { ApiNotFoundException } from '@/utils/exception';
9
8
  import { IUsecase } from '@/utils/usecase';
10
9
 
10
+ import { Infer } from '@/utils/validator';
11
11
  import { ${dashToPascal(name)}Entity, ${dashToPascal(name)}EntitySchema } from './../entity/${name}';
12
12
 
13
13
  export const ${dashToPascal(name)}UpdateSchema = ${dashToPascal(name)}EntitySchema.pick({
@@ -42,10 +42,10 @@ export class ${dashToPascal(name)}UpdateUsecase implements IUsecase {
42
42
  }
43
43
  }
44
44
 
45
- export type ${dashToPascal(name)}UpdateInput = z.infer<typeof ${dashToPascal(name)}UpdateSchema>;
45
+ export type ${dashToPascal(name)}UpdateInput = Infer<typeof ${dashToPascal(name)}UpdateSchema>;
46
46
  export type ${dashToPascal(name)}UpdateOutput = ${dashToPascal(name)}Entity;
47
47
  `
48
48
 
49
- module.exports = {
49
+ export {
50
50
  getCoreUsecaseUpdate
51
51
  }
@@ -0,0 +1,35 @@
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
+
3
+ const getCoreSingleEntity = (name) => `import { BaseEntity } from '@/utils/entity';
4
+
5
+ import { Infer, InputValidator } from '@/utils/validator';
6
+
7
+ const ID = InputValidator.string().uuid();
8
+ const Name = InputValidator.string().min(1).max(200).trim();
9
+ const CreatedAt = InputValidator.date().nullish();
10
+ const UpdatedAt = InputValidator.date().nullish();
11
+ const DeletedAt = InputValidator.date().nullish();
12
+
13
+ export const ${dashToPascal(name)}EntitySchema = InputValidator.object({
14
+ id: ID,
15
+ name: Name,
16
+ createdAt: CreatedAt,
17
+ updatedAt: UpdatedAt,
18
+ deletedAt: DeletedAt
19
+ });
20
+
21
+ type ${dashToPascal(name)} = Infer<typeof ${dashToPascal(name)}EntitySchema>;
22
+
23
+ export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>() {
24
+ name!: string;
25
+
26
+ constructor(entity: ${dashToPascal(name)}) {
27
+ super(${dashToPascal(name)}EntitySchema);
28
+ Object.assign(this, this.validate(entity));
29
+ }
30
+ }
31
+ `
32
+
33
+ export {
34
+ getCoreSingleEntity
35
+ }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
3
  const getCoreSingleRepository = (name) => `import { IRepository } from '@/infra/repository';
4
4
 
@@ -7,6 +7,6 @@ import { ${dashToPascal(name)}Entity } from '../entity/${name}';
7
7
  export abstract class I${dashToPascal(name)}Repository extends IRepository<${dashToPascal(name)}Entity> {}
8
8
  `
9
9
 
10
- module.exports = {
10
+ export {
11
11
  getCoreSingleRepository
12
12
  }
@@ -1,11 +1,11 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
- const getCoreSingleUsecaseCreate = (name) => `import { z } from 'zod';
3
+ const getCoreSingleUsecaseCreate = (name) => `import { ValidateSchema } from '@/utils/decorators';;
4
4
 
5
- import { ValidateSchema } from '@/utils/decorators';
5
+ import { Infer, InputValidator } from '@/utils/validator';
6
6
  import { IUsecase } from '@/utils/usecase';
7
7
 
8
- export const ${dashToPascal(name)}RenameSchema = z.object({ id: z.string() });
8
+ export const ${dashToPascal(name)}RenameSchema = InputValidator.object({ id: InputValidator.string() });
9
9
 
10
10
  export class ${dashToPascal(name)}RenameUsecase implements IUsecase {
11
11
  @ValidateSchema(${dashToPascal(name)}RenameSchema)
@@ -14,10 +14,10 @@ export class ${dashToPascal(name)}RenameUsecase implements IUsecase {
14
14
  }
15
15
  }
16
16
 
17
- export type ${dashToPascal(name)}RenameUseCaseInput = z.infer<typeof ${dashToPascal(name)}RenameSchema>;
17
+ export type ${dashToPascal(name)}RenameUseCaseInput = Infer<typeof ${dashToPascal(name)}RenameSchema>;
18
18
  export type ${dashToPascal(name)}RenameUseCaseOutput = ${dashToPascal(name)}RenameUseCaseInput;
19
19
  `
20
20
 
21
- module.exports = {
21
+ export {
22
22
  getCoreSingleUsecaseCreate
23
23
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getAdapterInfra = (name) => `import { ${dashToPascal(name)}GetInput, ${dashToPascal(name)}GetOutput } from './service';
4
4
 
@@ -7,6 +7,6 @@ export abstract class I${dashToPascal(name)}Adapter {
7
7
  }
8
8
  `
9
9
 
10
- module.exports = {
10
+ export default {
11
11
  getAdapterInfra
12
12
  }
@@ -1,9 +1,8 @@
1
-
2
1
  const getIndexInfra = (name) => `export * from './adapter';
3
2
  export * from './module';
4
3
  export * from './service';
5
4
  `
6
5
 
7
- module.exports = {
6
+ export {
8
7
  getIndexInfra
9
8
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getModuleInfa = (name) => `import { Module } from '@nestjs/common';
4
4
 
@@ -18,6 +18,6 @@ import { ${dashToPascal(name)}Service } from './service';
18
18
  export class ${dashToPascal(name)}Module {}
19
19
  `
20
20
 
21
- module.exports = {
21
+ export {
22
22
  getModuleInfa
23
23
  }
@@ -1,13 +1,13 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getServiceInfra = (name) => `import { Injectable } from '@nestjs/common';
4
- import { z } from 'zod';
4
+ import { Infer, InputValidator } from '@/utils/validator';
5
5
 
6
6
  import { ValidateSchema } from '@/utils/decorators';
7
7
 
8
8
  import { I${dashToPascal(name)}Adapter } from './adapter';
9
9
 
10
- const ${dashToPascal(name)}Schema = z.object({ name: z.string().trim() });
10
+ const ${dashToPascal(name)}Schema = InputValidator.object({ name: InputValidator.string().trim() });
11
11
 
12
12
  @Injectable()
13
13
  export class ${dashToPascal(name)}Service implements I${dashToPascal(name)}Adapter {
@@ -17,10 +17,10 @@ export class ${dashToPascal(name)}Service implements I${dashToPascal(name)}Adapt
17
17
  }
18
18
  }
19
19
 
20
- export type ${dashToPascal(name)}GetInput = z.infer<typeof ${dashToPascal(name)}Schema>;
20
+ export type ${dashToPascal(name)}GetInput = Infer<typeof ${dashToPascal(name)}Schema>;
21
21
  export type ${dashToPascal(name)}GetOutput = ${dashToPascal(name)}GetInput;
22
22
  `
23
23
 
24
- module.exports = {
24
+ export {
25
25
  getServiceInfra
26
26
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getAdapterLib = (name) => `import { ${dashToPascal(name)}Input, ${dashToPascal(name)}Output } from './service';
4
4
 
@@ -7,6 +7,4 @@ export abstract class I${dashToPascal(name)}Adapter {
7
7
  }
8
8
  `
9
9
 
10
- module.exports = {
11
- getAdapterLib
12
- }
10
+ export { getAdapterLib }
@@ -4,6 +4,6 @@ export * from './module';
4
4
  export * from './service';
5
5
  `
6
6
 
7
- module.exports = {
7
+ export {
8
8
  getIndexLib
9
9
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getModuleLib = (name) => `import { Module } from '@nestjs/common';
4
4
 
@@ -18,6 +18,6 @@ import { ${dashToPascal(name)}Service } from './service';
18
18
  export class ${dashToPascal(name)}LibModule {}
19
19
  `
20
20
 
21
- module.exports = {
21
+ export {
22
22
  getModuleLib
23
23
  }
@@ -1,13 +1,13 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getServiceLib = (name) => `import { Injectable } from '@nestjs/common';
4
- import { z } from 'zod';
4
+ import { Infer, InputValidator } from '@/utils/validator';
5
5
 
6
6
  import { ValidateSchema } from '@/utils/decorators';
7
7
 
8
8
  import { I${dashToPascal(name)}Adapter } from './adapter';
9
9
 
10
- const ${dashToPascal(name)}Schema = z.object({ name: z.string().trim() });
10
+ const ${dashToPascal(name)}Schema = InputValidator.object({ name: InputValidator.string().trim() });
11
11
 
12
12
  @Injectable()
13
13
  export class ${dashToPascal(name)}Service implements I${dashToPascal(name)}Adapter {
@@ -17,10 +17,10 @@ export class ${dashToPascal(name)}Service implements I${dashToPascal(name)}Adapt
17
17
  }
18
18
  }
19
19
 
20
- export type ${dashToPascal(name)}Input = z.infer<typeof ${dashToPascal(name)}Schema>;
20
+ export type ${dashToPascal(name)}Input = Infer<typeof ${dashToPascal(name)}Schema>;
21
21
  export type ${dashToPascal(name)}Output = ${dashToPascal(name)}Input;
22
22
  `
23
23
 
24
- module.exports = {
24
+ export {
25
25
  getServiceLib
26
26
  }
@@ -1,6 +1,6 @@
1
1
 
2
- const pluralize = require('pluralize')
3
- const { dashToPascal } = require('../../textUtils')
2
+ import pluralize from 'pluralize'
3
+ import { dashToPascal } from '../../textUtils.mjs'
4
4
 
5
5
  const getModuleControllerModule = (name) => `import { Controller, Get, Req, Version } from '@nestjs/common';
6
6
 
@@ -16,6 +16,6 @@ export class ${dashToPascal(name)}Controller {
16
16
  }
17
17
  `
18
18
 
19
- module.exports = {
19
+ export {
20
20
  getModuleControllerModule
21
21
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../textUtils")
1
+ import { dashToPascal } from "../../textUtils.mjs"
2
2
 
3
3
  const getModuleModule = (name) => `import { Module } from '@nestjs/common';
4
4
 
@@ -11,6 +11,6 @@ import { ${dashToPascal(name)}Controller } from './controller';
11
11
  export class ${dashToPascal(name)}Module {}
12
12
  `
13
13
 
14
- module.exports = {
14
+ export {
15
15
  getModuleModule
16
16
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
3
  const getModuleAdapter = (name) => `import { ${dashToPascal(name)}CreateInput, ${dashToPascal(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
4
4
  import { ${dashToPascal(name)}DeleteInput, ${dashToPascal(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
@@ -28,6 +28,6 @@ export abstract class I${dashToPascal(name)}GetByIdAdapter implements IUsecase {
28
28
  }
29
29
  `
30
30
 
31
- module.exports = {
31
+ export {
32
32
  getModuleAdapter
33
33
  }
@@ -1,5 +1,5 @@
1
- const pluralize = require('pluralize')
2
- const { dashToPascal, snakeToCamel } = require('../../../textUtils')
1
+ import pluralize from 'pluralize'
2
+ import { dashToPascal, snakeToCamel } from '../../../textUtils.mjs'
3
3
 
4
4
  const getModuleController = (name) => `import { Controller, Delete, Get, HttpCode, Post, Put, Req, Version } from '@nestjs/common';
5
5
 
@@ -70,6 +70,6 @@ export class ${dashToPascal(name)}Controller {
70
70
  }
71
71
  `
72
72
 
73
- module.exports = {
73
+ export {
74
74
  getModuleController
75
75
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal, snakeToCamel } = require("../../../textUtils")
1
+ import { dashToPascal, snakeToCamel } from "../../../textUtils.mjs"
2
2
 
3
3
  const getModule = (name) => `import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
4
4
  import { getConnectionToken } from '@nestjs/mongoose';
@@ -105,6 +105,6 @@ export class ${dashToPascal(name)}Module implements NestModule {
105
105
  }
106
106
  `
107
107
 
108
- module.exports = {
108
+ export {
109
109
  getModule
110
110
  }
@@ -1,5 +1,5 @@
1
- const pluralize = require('pluralize')
2
- const { dashToPascal, snakeToCamel } = require('../../../textUtils')
1
+ import pluralize from 'pluralize'
2
+ import { dashToPascal, snakeToCamel } from '../../../textUtils.mjs'
3
3
 
4
4
  const getModuleRepository = (name) => `import { Injectable } from '@nestjs/common';
5
5
  import { InjectModel } from '@nestjs/mongoose';
@@ -34,6 +34,6 @@ export class ${dashToPascal(name)}Repository extends MongoRepository<${dashToPas
34
34
  }
35
35
  `
36
36
 
37
- module.exports = {
37
+ export {
38
38
  getModuleRepository
39
39
  }
@@ -1,6 +1,6 @@
1
1
 
2
- const pluralize = require('pluralize')
3
- const { dashToPascal } = require('../../../textUtils')
2
+ import pluralize from 'pluralize'
3
+ import { dashToPascal } from '../../../textUtils.mjs'
4
4
 
5
5
  const getModuleSchema = (name) => `import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
6
6
  import { Document } from 'mongoose';
@@ -39,6 +39,6 @@ ${dashToPascal(name)}Schema.virtual('id').get(function () {
39
39
  export { ${dashToPascal(name)}Schema };
40
40
  `
41
41
 
42
- module.exports = {
42
+ export {
43
43
  getModuleSchema
44
44
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
3
  const getModuleAdapter = (name) => `import { ${dashToPascal(name)}CreateInput, ${dashToPascal(name)}CreateOutput } from '@/core/${name}/use-cases/${name}-create';
4
4
  import { ${dashToPascal(name)}DeleteInput, ${dashToPascal(name)}DeleteOutput } from '@/core/${name}/use-cases/${name}-delete';
@@ -28,6 +28,6 @@ export abstract class I${dashToPascal(name)}DeleteAdapter implements IUsecase {
28
28
  }
29
29
  `
30
30
 
31
- module.exports = {
31
+ export {
32
32
  getModuleAdapter
33
33
  }
@@ -1,5 +1,5 @@
1
- const pluralize = require('pluralize')
2
- const { dashToPascal, snakeToCamel } = require('../../../textUtils')
1
+ import pluralize from 'pluralize'
2
+ import { dashToPascal, snakeToCamel } from '../../../textUtils.mjs'
3
3
 
4
4
  const getModuleController = (name) => `import { Controller, Delete, Get, HttpCode, Post, Put, Req, Version } from '@nestjs/common';
5
5
 
@@ -70,6 +70,6 @@ export class ${dashToPascal(name)}Controller {
70
70
  }
71
71
  `
72
72
 
73
- module.exports = {
73
+ export {
74
74
  getModuleController
75
75
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
3
  const getModule = (name) => `import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
4
4
  import { getRepositoryToken, TypeOrmModule } from '@nestjs/typeorm';
@@ -73,6 +73,6 @@ export class ${dashToPascal(name)}Module implements NestModule {
73
73
  }
74
74
  `
75
75
 
76
- module.exports = {
76
+ export {
77
77
  getModule
78
78
  }
@@ -1,4 +1,4 @@
1
- const { dashToPascal } = require("../../../textUtils")
1
+ import { dashToPascal } from "../../../textUtils.mjs"
2
2
 
3
3
  const getModuleRepository = (name) => `import { Injectable } from '@nestjs/common';
4
4
  import { FindOptionsOrder, FindOptionsWhere, Repository } from 'typeorm';
@@ -37,6 +37,6 @@ export class ${dashToPascal(name)}Repository extends TypeORMRepository<Model> im
37
37
  type Model = ${dashToPascal(name)}Schema & ${dashToPascal(name)}Entity;
38
38
  `
39
39
 
40
- module.exports = {
40
+ export {
41
41
  getModuleRepository
42
42
  }
@@ -1,6 +1,6 @@
1
1
 
2
- const pluralize = require('pluralize')
3
- const { dashToPascal } = require('../../../textUtils')
2
+ import pluralize from 'pluralize'
3
+ import { dashToPascal } from '../../../textUtils.mjs'
4
4
 
5
5
  const getModuleSchema = (name) => `import {
6
6
  BaseEntity,
@@ -31,6 +31,6 @@ export class ${dashToPascal(name)}Schema extends BaseEntity {
31
31
  }
32
32
  `
33
33
 
34
- module.exports = {
34
+ export {
35
35
  getModuleSchema
36
36
  }
@@ -1,35 +0,0 @@
1
- const { dashToPascal } = require("../../../textUtils")
2
-
3
- const getCoreEntity = (name) => `import { z } from 'zod';
4
-
5
- import { BaseEntity } from '@/utils/entity';
6
-
7
- const ID = z.string().uuid();
8
- const Name = z.string().min(1).max(200).trim();
9
- const CreatedAt = z.date().nullish();
10
- const UpdatedAt = z.date().nullish();
11
- const DeletedAt = z.date().nullish();
12
-
13
- export const ${dashToPascal(name)}EntitySchema = z.object({
14
- id: ID,
15
- name: Name,
16
- createdAt: CreatedAt,
17
- updatedAt: UpdatedAt,
18
- deletedAt: DeletedAt
19
- });
20
-
21
- type ${dashToPascal(name)} = z.infer<typeof ${dashToPascal(name)}EntitySchema>;
22
-
23
- export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>() {
24
- name!: string;
25
-
26
- constructor(entity: ${dashToPascal(name)}) {
27
- super(${dashToPascal(name)}EntitySchema);
28
- Object.assign(this, this.validate(entity));
29
- }
30
- }
31
- `
32
-
33
- module.exports = {
34
- getCoreEntity
35
- }
@@ -1,35 +0,0 @@
1
- const { dashToPascal } = require("../../../textUtils")
2
-
3
- const getCoreSingleEntity = (name) => `import { z } from 'zod';
4
-
5
- import { BaseEntity } from '@/utils/entity';
6
-
7
- const ID = z.string().uuid();
8
- const Name = z.string().min(1).max(200).trim();
9
- const CreatedAt = z.date().nullish();
10
- const UpdatedAt = z.date().nullish();
11
- const DeletedAt = z.date().nullish();
12
-
13
- export const ${dashToPascal(name)}EntitySchema = z.object({
14
- id: ID,
15
- name: Name,
16
- createdAt: CreatedAt,
17
- updatedAt: UpdatedAt,
18
- deletedAt: DeletedAt
19
- });
20
-
21
- type ${dashToPascal(name)} = z.infer<typeof ${dashToPascal(name)}EntitySchema>;
22
-
23
- export class ${dashToPascal(name)}Entity extends BaseEntity<${dashToPascal(name)}Entity>() {
24
- name!: string;
25
-
26
- constructor(entity: ${dashToPascal(name)}) {
27
- super(${dashToPascal(name)}EntitySchema);
28
- Object.assign(this, this.validate(entity));
29
- }
30
- }
31
- `
32
-
33
- module.exports = {
34
- getCoreSingleEntity
35
- }
File without changes