@tndhuy/create-app 1.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 (176) hide show
  1. package/README.md +53 -0
  2. package/dist/cli.js +534 -0
  3. package/package.json +37 -0
  4. package/templates/mongo/.env.example +32 -0
  5. package/templates/mongo/Dockerfile +64 -0
  6. package/templates/mongo/docker-compose.yml +35 -0
  7. package/templates/mongo/eslint.config.mjs +35 -0
  8. package/templates/mongo/nest-cli.json +8 -0
  9. package/templates/mongo/package.json +105 -0
  10. package/templates/mongo/src/app.module.ts +59 -0
  11. package/templates/mongo/src/common/decorators/public-api.decorator.ts +9 -0
  12. package/templates/mongo/src/common/decorators/raw-response.decorator.ts +4 -0
  13. package/templates/mongo/src/common/filters/http-exception.filter.spec.ts +95 -0
  14. package/templates/mongo/src/common/filters/http-exception.filter.ts +43 -0
  15. package/templates/mongo/src/common/filters/rpc-exception.filter.ts +18 -0
  16. package/templates/mongo/src/common/index.ts +5 -0
  17. package/templates/mongo/src/common/interceptors/timeout.interceptor.ts +32 -0
  18. package/templates/mongo/src/common/interceptors/transform.interceptor.spec.ts +52 -0
  19. package/templates/mongo/src/common/interceptors/transform.interceptor.ts +25 -0
  20. package/templates/mongo/src/common/middleware/correlation-id.middleware.spec.ts +69 -0
  21. package/templates/mongo/src/common/middleware/correlation-id.middleware.ts +26 -0
  22. package/templates/mongo/src/infrastructure/cache/inject-redis.decorator.ts +4 -0
  23. package/templates/mongo/src/infrastructure/cache/redis.module.ts +9 -0
  24. package/templates/mongo/src/infrastructure/cache/redis.service.spec.ts +174 -0
  25. package/templates/mongo/src/infrastructure/cache/redis.service.ts +121 -0
  26. package/templates/mongo/src/infrastructure/config/config.module.ts +36 -0
  27. package/templates/mongo/src/infrastructure/config/environment.validation.spec.ts +100 -0
  28. package/templates/mongo/src/infrastructure/config/environment.validation.ts +21 -0
  29. package/templates/mongo/src/infrastructure/database/mongodb.module.ts +17 -0
  30. package/templates/mongo/src/infrastructure/health/health.controller.ts +46 -0
  31. package/templates/mongo/src/infrastructure/health/health.module.ts +12 -0
  32. package/templates/mongo/src/infrastructure/health/redis.health-indicator.ts +20 -0
  33. package/templates/mongo/src/instrumentation.spec.ts +24 -0
  34. package/templates/mongo/src/instrumentation.ts +44 -0
  35. package/templates/mongo/src/main.ts +102 -0
  36. package/templates/mongo/src/modules/example/application/commands/create-item.command.ts +3 -0
  37. package/templates/mongo/src/modules/example/application/commands/create-item.handler.spec.ts +49 -0
  38. package/templates/mongo/src/modules/example/application/commands/create-item.handler.ts +20 -0
  39. package/templates/mongo/src/modules/example/application/commands/delete-item.command.ts +3 -0
  40. package/templates/mongo/src/modules/example/application/commands/delete-item.handler.ts +15 -0
  41. package/templates/mongo/src/modules/example/application/dtos/create-item.dto.ts +9 -0
  42. package/templates/mongo/src/modules/example/application/dtos/item.response.dto.ts +9 -0
  43. package/templates/mongo/src/modules/example/application/queries/get-item.handler.spec.ts +49 -0
  44. package/templates/mongo/src/modules/example/application/queries/get-item.handler.ts +16 -0
  45. package/templates/mongo/src/modules/example/application/queries/get-item.query.ts +3 -0
  46. package/templates/mongo/src/modules/example/application/queries/list-items.handler.ts +16 -0
  47. package/templates/mongo/src/modules/example/application/queries/list-items.query.ts +3 -0
  48. package/templates/mongo/src/modules/example/domain/item-name.value-object.spec.ts +49 -0
  49. package/templates/mongo/src/modules/example/domain/item-name.value-object.ts +18 -0
  50. package/templates/mongo/src/modules/example/domain/item.entity.spec.ts +48 -0
  51. package/templates/mongo/src/modules/example/domain/item.entity.ts +19 -0
  52. package/templates/mongo/src/modules/example/domain/item.repository.interface.ts +10 -0
  53. package/templates/mongo/src/modules/example/example.module.ts +31 -0
  54. package/templates/mongo/src/modules/example/infrastructure/.gitkeep +0 -0
  55. package/templates/mongo/src/modules/example/infrastructure/persistence/mongoose-item.repository.ts +42 -0
  56. package/templates/mongo/src/modules/example/infrastructure/persistence/schemas/item.schema.ts +15 -0
  57. package/templates/mongo/src/modules/example/presenter/item.controller.ts +52 -0
  58. package/templates/mongo/src/shared/base/aggregate-root.spec.ts +44 -0
  59. package/templates/mongo/src/shared/base/aggregate-root.ts +20 -0
  60. package/templates/mongo/src/shared/base/domain-event.ts +6 -0
  61. package/templates/mongo/src/shared/base/entity.spec.ts +36 -0
  62. package/templates/mongo/src/shared/base/entity.ts +13 -0
  63. package/templates/mongo/src/shared/base/index.ts +5 -0
  64. package/templates/mongo/src/shared/base/repository.interface.ts +6 -0
  65. package/templates/mongo/src/shared/base/value-object.spec.ts +39 -0
  66. package/templates/mongo/src/shared/base/value-object.ts +13 -0
  67. package/templates/mongo/src/shared/dto/pagination.dto.spec.ts +49 -0
  68. package/templates/mongo/src/shared/dto/pagination.dto.ts +37 -0
  69. package/templates/mongo/src/shared/dto/response.dto.ts +13 -0
  70. package/templates/mongo/src/shared/exceptions/app.exception.spec.ts +59 -0
  71. package/templates/mongo/src/shared/exceptions/app.exception.ts +19 -0
  72. package/templates/mongo/src/shared/exceptions/error-codes.ts +9 -0
  73. package/templates/mongo/src/shared/index.ts +7 -0
  74. package/templates/mongo/src/shared/logger/logger.module.ts +12 -0
  75. package/templates/mongo/src/shared/logger/logger.service.ts +48 -0
  76. package/templates/mongo/src/shared/logger/pino.config.ts +86 -0
  77. package/templates/mongo/src/shared/validation-options.ts +38 -0
  78. package/templates/mongo/src/shared/valueobjects/date.valueobject.spec.ts +40 -0
  79. package/templates/mongo/src/shared/valueobjects/date.valueobject.ts +14 -0
  80. package/templates/mongo/src/shared/valueobjects/id.valueobject.spec.ts +28 -0
  81. package/templates/mongo/src/shared/valueobjects/id.valueobject.ts +14 -0
  82. package/templates/mongo/src/shared/valueobjects/index.ts +4 -0
  83. package/templates/mongo/src/shared/valueobjects/number.valueobject.spec.ts +48 -0
  84. package/templates/mongo/src/shared/valueobjects/number.valueobject.ts +14 -0
  85. package/templates/mongo/src/shared/valueobjects/string.valueobject.spec.ts +37 -0
  86. package/templates/mongo/src/shared/valueobjects/string.valueobject.ts +14 -0
  87. package/templates/mongo/tsconfig.build.json +4 -0
  88. package/templates/mongo/tsconfig.json +23 -0
  89. package/templates/postgres/.env.example +32 -0
  90. package/templates/postgres/Dockerfile +64 -0
  91. package/templates/postgres/eslint.config.mjs +35 -0
  92. package/templates/postgres/nest-cli.json +8 -0
  93. package/templates/postgres/package.json +103 -0
  94. package/templates/postgres/prisma/schema.prisma +14 -0
  95. package/templates/postgres/prisma.config.ts +11 -0
  96. package/templates/postgres/src/app.module.ts +34 -0
  97. package/templates/postgres/src/common/decorators/public-api.decorator.ts +9 -0
  98. package/templates/postgres/src/common/decorators/raw-response.decorator.ts +4 -0
  99. package/templates/postgres/src/common/filters/http-exception.filter.spec.ts +95 -0
  100. package/templates/postgres/src/common/filters/http-exception.filter.ts +43 -0
  101. package/templates/postgres/src/common/filters/rpc-exception.filter.ts +18 -0
  102. package/templates/postgres/src/common/index.ts +5 -0
  103. package/templates/postgres/src/common/interceptors/timeout.interceptor.ts +32 -0
  104. package/templates/postgres/src/common/interceptors/transform.interceptor.spec.ts +52 -0
  105. package/templates/postgres/src/common/interceptors/transform.interceptor.ts +25 -0
  106. package/templates/postgres/src/common/middleware/correlation-id.middleware.spec.ts +69 -0
  107. package/templates/postgres/src/common/middleware/correlation-id.middleware.ts +26 -0
  108. package/templates/postgres/src/infrastructure/cache/inject-redis.decorator.ts +4 -0
  109. package/templates/postgres/src/infrastructure/cache/redis.module.ts +9 -0
  110. package/templates/postgres/src/infrastructure/cache/redis.service.spec.ts +174 -0
  111. package/templates/postgres/src/infrastructure/cache/redis.service.ts +121 -0
  112. package/templates/postgres/src/infrastructure/config/config.module.ts +36 -0
  113. package/templates/postgres/src/infrastructure/config/environment.validation.spec.ts +100 -0
  114. package/templates/postgres/src/infrastructure/config/environment.validation.ts +21 -0
  115. package/templates/postgres/src/infrastructure/database/inject-prisma.decorator.ts +4 -0
  116. package/templates/postgres/src/infrastructure/database/prisma.module.ts +9 -0
  117. package/templates/postgres/src/infrastructure/database/prisma.service.ts +21 -0
  118. package/templates/postgres/src/infrastructure/health/health.controller.ts +46 -0
  119. package/templates/postgres/src/infrastructure/health/health.module.ts +12 -0
  120. package/templates/postgres/src/infrastructure/health/prisma.health-indicator.ts +19 -0
  121. package/templates/postgres/src/infrastructure/health/redis.health-indicator.ts +20 -0
  122. package/templates/postgres/src/instrumentation.spec.ts +24 -0
  123. package/templates/postgres/src/instrumentation.ts +44 -0
  124. package/templates/postgres/src/main.ts +102 -0
  125. package/templates/postgres/src/modules/example/application/commands/create-item.command.ts +3 -0
  126. package/templates/postgres/src/modules/example/application/commands/create-item.handler.spec.ts +49 -0
  127. package/templates/postgres/src/modules/example/application/commands/create-item.handler.ts +20 -0
  128. package/templates/postgres/src/modules/example/application/commands/delete-item.command.ts +3 -0
  129. package/templates/postgres/src/modules/example/application/commands/delete-item.handler.ts +15 -0
  130. package/templates/postgres/src/modules/example/application/dtos/create-item.dto.ts +9 -0
  131. package/templates/postgres/src/modules/example/application/dtos/item.response.dto.ts +9 -0
  132. package/templates/postgres/src/modules/example/application/queries/get-item.handler.spec.ts +49 -0
  133. package/templates/postgres/src/modules/example/application/queries/get-item.handler.ts +16 -0
  134. package/templates/postgres/src/modules/example/application/queries/get-item.query.ts +3 -0
  135. package/templates/postgres/src/modules/example/application/queries/list-items.handler.ts +16 -0
  136. package/templates/postgres/src/modules/example/application/queries/list-items.query.ts +3 -0
  137. package/templates/postgres/src/modules/example/domain/item-name.value-object.spec.ts +49 -0
  138. package/templates/postgres/src/modules/example/domain/item-name.value-object.ts +18 -0
  139. package/templates/postgres/src/modules/example/domain/item.entity.spec.ts +48 -0
  140. package/templates/postgres/src/modules/example/domain/item.entity.ts +19 -0
  141. package/templates/postgres/src/modules/example/domain/item.repository.interface.ts +10 -0
  142. package/templates/postgres/src/modules/example/example.module.ts +26 -0
  143. package/templates/postgres/src/modules/example/infrastructure/.gitkeep +0 -0
  144. package/templates/postgres/src/modules/example/infrastructure/persistence/prisma-item.repository.ts +34 -0
  145. package/templates/postgres/src/modules/example/presenter/item.controller.ts +52 -0
  146. package/templates/postgres/src/shared/base/aggregate-root.spec.ts +44 -0
  147. package/templates/postgres/src/shared/base/aggregate-root.ts +20 -0
  148. package/templates/postgres/src/shared/base/domain-event.ts +6 -0
  149. package/templates/postgres/src/shared/base/entity.spec.ts +36 -0
  150. package/templates/postgres/src/shared/base/entity.ts +13 -0
  151. package/templates/postgres/src/shared/base/index.ts +5 -0
  152. package/templates/postgres/src/shared/base/repository.interface.ts +6 -0
  153. package/templates/postgres/src/shared/base/value-object.spec.ts +39 -0
  154. package/templates/postgres/src/shared/base/value-object.ts +13 -0
  155. package/templates/postgres/src/shared/dto/pagination.dto.spec.ts +49 -0
  156. package/templates/postgres/src/shared/dto/pagination.dto.ts +37 -0
  157. package/templates/postgres/src/shared/dto/response.dto.ts +13 -0
  158. package/templates/postgres/src/shared/exceptions/app.exception.spec.ts +59 -0
  159. package/templates/postgres/src/shared/exceptions/app.exception.ts +19 -0
  160. package/templates/postgres/src/shared/exceptions/error-codes.ts +9 -0
  161. package/templates/postgres/src/shared/index.ts +7 -0
  162. package/templates/postgres/src/shared/logger/logger.module.ts +12 -0
  163. package/templates/postgres/src/shared/logger/logger.service.ts +48 -0
  164. package/templates/postgres/src/shared/logger/pino.config.ts +86 -0
  165. package/templates/postgres/src/shared/validation-options.ts +38 -0
  166. package/templates/postgres/src/shared/valueobjects/date.valueobject.spec.ts +40 -0
  167. package/templates/postgres/src/shared/valueobjects/date.valueobject.ts +14 -0
  168. package/templates/postgres/src/shared/valueobjects/id.valueobject.spec.ts +28 -0
  169. package/templates/postgres/src/shared/valueobjects/id.valueobject.ts +14 -0
  170. package/templates/postgres/src/shared/valueobjects/index.ts +4 -0
  171. package/templates/postgres/src/shared/valueobjects/number.valueobject.spec.ts +48 -0
  172. package/templates/postgres/src/shared/valueobjects/number.valueobject.ts +14 -0
  173. package/templates/postgres/src/shared/valueobjects/string.valueobject.spec.ts +37 -0
  174. package/templates/postgres/src/shared/valueobjects/string.valueobject.ts +14 -0
  175. package/templates/postgres/tsconfig.build.json +4 -0
  176. package/templates/postgres/tsconfig.json +23 -0
@@ -0,0 +1,40 @@
1
+ import { DateValueObject } from './date.valueobject';
2
+
3
+ describe('DateValueObject', () => {
4
+ it('should store and return a valid Date', () => {
5
+ const date = new Date('2024-01-15T10:00:00Z');
6
+ const vo = new DateValueObject(date);
7
+ expect(vo.value).toEqual(date);
8
+ });
9
+
10
+ it('should throw when constructed with an invalid Date (NaN time)', () => {
11
+ expect(() => new DateValueObject(new Date('invalid'))).toThrow(
12
+ 'Date value must be a valid Date',
13
+ );
14
+ });
15
+
16
+ it('should throw when constructed with a non-Date value', () => {
17
+ expect(() => new DateValueObject('2024-01-01' as any)).toThrow(
18
+ 'Date value must be a valid Date',
19
+ );
20
+ });
21
+
22
+ it('should throw when constructed with null', () => {
23
+ expect(() => new DateValueObject(null as any)).toThrow(
24
+ 'Date value must be a valid Date',
25
+ );
26
+ });
27
+
28
+ it('should be equal to another DateValueObject with the same date value', () => {
29
+ const date = new Date('2024-06-01T00:00:00Z');
30
+ const vo1 = new DateValueObject(date);
31
+ const vo2 = new DateValueObject(new Date('2024-06-01T00:00:00Z'));
32
+ expect(vo1.equals(vo2)).toBe(true);
33
+ });
34
+
35
+ it('should not be equal to a DateValueObject with a different date', () => {
36
+ const vo1 = new DateValueObject(new Date('2024-01-01'));
37
+ const vo2 = new DateValueObject(new Date('2024-12-31'));
38
+ expect(vo1.equals(vo2)).toBe(false);
39
+ });
40
+ });
@@ -0,0 +1,14 @@
1
+ import { ValueObject } from '../base/value-object';
2
+
3
+ export class DateValueObject extends ValueObject<{ value: Date }> {
4
+ constructor(value: Date) {
5
+ if (!(value instanceof Date) || isNaN(value.getTime())) {
6
+ throw new Error('Date value must be a valid Date');
7
+ }
8
+ super({ value });
9
+ }
10
+
11
+ get value(): Date {
12
+ return this.props.value;
13
+ }
14
+ }
@@ -0,0 +1,28 @@
1
+ import { IdValueObject } from './id.valueobject';
2
+
3
+ describe('IdValueObject', () => {
4
+ it('should store and return the id value', () => {
5
+ const id = new IdValueObject('abc-123');
6
+ expect(id.value).toBe('abc-123');
7
+ });
8
+
9
+ it('should throw when constructed with an empty string', () => {
10
+ expect(() => new IdValueObject('')).toThrow('ID must not be empty');
11
+ });
12
+
13
+ it('should throw when constructed with whitespace-only string', () => {
14
+ expect(() => new IdValueObject(' ')).toThrow('ID must not be empty');
15
+ });
16
+
17
+ it('should be equal to another IdValueObject with the same value', () => {
18
+ const id1 = new IdValueObject('abc-123');
19
+ const id2 = new IdValueObject('abc-123');
20
+ expect(id1.equals(id2)).toBe(true);
21
+ });
22
+
23
+ it('should not be equal to another IdValueObject with a different value', () => {
24
+ const id1 = new IdValueObject('abc-123');
25
+ const id2 = new IdValueObject('xyz-456');
26
+ expect(id1.equals(id2)).toBe(false);
27
+ });
28
+ });
@@ -0,0 +1,14 @@
1
+ import { ValueObject } from '../base/value-object';
2
+
3
+ export class IdValueObject extends ValueObject<{ value: string }> {
4
+ constructor(value: string) {
5
+ if (!value || value.trim().length === 0) {
6
+ throw new Error('ID must not be empty');
7
+ }
8
+ super({ value });
9
+ }
10
+
11
+ get value(): string {
12
+ return this.props.value;
13
+ }
14
+ }
@@ -0,0 +1,4 @@
1
+ export { IdValueObject } from './id.valueobject';
2
+ export { StringValueObject } from './string.valueobject';
3
+ export { NumberValueObject } from './number.valueobject';
4
+ export { DateValueObject } from './date.valueobject';
@@ -0,0 +1,48 @@
1
+ import { NumberValueObject } from './number.valueobject';
2
+
3
+ describe('NumberValueObject', () => {
4
+ it('should store and return the numeric value', () => {
5
+ const vo = new NumberValueObject(42);
6
+ expect(vo.value).toBe(42);
7
+ });
8
+
9
+ it('should store zero as a valid value', () => {
10
+ const vo = new NumberValueObject(0);
11
+ expect(vo.value).toBe(0);
12
+ });
13
+
14
+ it('should store negative numbers', () => {
15
+ const vo = new NumberValueObject(-7);
16
+ expect(vo.value).toBe(-7);
17
+ });
18
+
19
+ it('should throw when constructed with NaN', () => {
20
+ expect(() => new NumberValueObject(NaN)).toThrow(
21
+ 'Number value must be a finite number',
22
+ );
23
+ });
24
+
25
+ it('should throw when constructed with Infinity', () => {
26
+ expect(() => new NumberValueObject(Infinity)).toThrow(
27
+ 'Number value must be a finite number',
28
+ );
29
+ });
30
+
31
+ it('should throw when constructed with negative Infinity', () => {
32
+ expect(() => new NumberValueObject(-Infinity)).toThrow(
33
+ 'Number value must be a finite number',
34
+ );
35
+ });
36
+
37
+ it('should be equal to another NumberValueObject with the same value', () => {
38
+ const vo1 = new NumberValueObject(99);
39
+ const vo2 = new NumberValueObject(99);
40
+ expect(vo1.equals(vo2)).toBe(true);
41
+ });
42
+
43
+ it('should not be equal to a NumberValueObject with a different value', () => {
44
+ const vo1 = new NumberValueObject(1);
45
+ const vo2 = new NumberValueObject(2);
46
+ expect(vo1.equals(vo2)).toBe(false);
47
+ });
48
+ });
@@ -0,0 +1,14 @@
1
+ import { ValueObject } from '../base/value-object';
2
+
3
+ export class NumberValueObject extends ValueObject<{ value: number }> {
4
+ constructor(value: number) {
5
+ if (!Number.isFinite(value)) {
6
+ throw new Error('Number value must be a finite number');
7
+ }
8
+ super({ value });
9
+ }
10
+
11
+ get value(): number {
12
+ return this.props.value;
13
+ }
14
+ }
@@ -0,0 +1,37 @@
1
+ import { StringValueObject } from './string.valueobject';
2
+
3
+ describe('StringValueObject', () => {
4
+ it('should store and return the string value', () => {
5
+ const vo = new StringValueObject('hello');
6
+ expect(vo.value).toBe('hello');
7
+ });
8
+
9
+ it('should throw when constructed with null', () => {
10
+ expect(() => new StringValueObject(null as any)).toThrow(
11
+ 'String value must not be null or undefined',
12
+ );
13
+ });
14
+
15
+ it('should throw when constructed with undefined', () => {
16
+ expect(() => new StringValueObject(undefined as any)).toThrow(
17
+ 'String value must not be null or undefined',
18
+ );
19
+ });
20
+
21
+ it('should be equal to another StringValueObject with the same value', () => {
22
+ const vo1 = new StringValueObject('hello');
23
+ const vo2 = new StringValueObject('hello');
24
+ expect(vo1.equals(vo2)).toBe(true);
25
+ });
26
+
27
+ it('should not be equal to a StringValueObject with a different value', () => {
28
+ const vo1 = new StringValueObject('hello');
29
+ const vo2 = new StringValueObject('world');
30
+ expect(vo1.equals(vo2)).toBe(false);
31
+ });
32
+
33
+ it('should allow empty strings (only null/undefined are rejected)', () => {
34
+ const vo = new StringValueObject('');
35
+ expect(vo.value).toBe('');
36
+ });
37
+ });
@@ -0,0 +1,14 @@
1
+ import { ValueObject } from '../base/value-object';
2
+
3
+ export class StringValueObject extends ValueObject<{ value: string }> {
4
+ constructor(value: string) {
5
+ if (value === null || value === undefined) {
6
+ throw new Error('String value must not be null or undefined');
7
+ }
8
+ super({ value });
9
+ }
10
+
11
+ get value(): string {
12
+ return this.props.value;
13
+ }
14
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
4
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "declaration": true,
5
+ "removeComments": true,
6
+ "emitDecoratorMetadata": true,
7
+ "experimentalDecorators": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "esModuleInterop": true,
10
+ "target": "ES2023",
11
+ "sourceMap": true,
12
+ "outDir": "./dist",
13
+ "baseUrl": "./",
14
+ "paths": {
15
+ "@shared/*": ["src/shared/*"]
16
+ },
17
+ "incremental": true,
18
+ "skipLibCheck": true,
19
+ "strictNullChecks": true,
20
+ "noImplicitAny": false
21
+ },
22
+ "exclude": ["node_modules", "dist", "test", "packages"]
23
+ }