typescript-express-starter 6.0.0 → 6.3.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 (143) hide show
  1. package/README.kr.md +133 -52
  2. package/README.md +134 -54
  3. package/bin/cli.js +4 -3
  4. package/lib/default/.swcrc +41 -0
  5. package/lib/default/Dockerfile +1 -1
  6. package/lib/default/ecosystem.config.js +40 -24
  7. package/lib/default/nodemon.json +2 -2
  8. package/lib/default/package.json +15 -8
  9. package/lib/default/src/app.ts +1 -2
  10. package/lib/default/src/http/auth.http +12 -15
  11. package/lib/default/src/http/users.http +12 -16
  12. package/lib/default/src/index.ts +1 -0
  13. package/lib/default/src/middlewares/auth.middleware.ts +3 -3
  14. package/lib/default/src/models/users.model.ts +5 -5
  15. package/lib/default/src/server.ts +1 -2
  16. package/lib/default/src/services/auth.service.ts +5 -5
  17. package/lib/default/src/services/users.service.ts +3 -3
  18. package/lib/default/src/tests/auth.test.ts +4 -4
  19. package/lib/default/src/tests/users.test.ts +4 -4
  20. package/lib/default/src/utils/logger.ts +5 -5
  21. package/lib/default/src/utils/util.ts +1 -1
  22. package/lib/default/tsconfig.json +2 -2
  23. package/lib/knex/.swcrc +39 -0
  24. package/lib/knex/Dockerfile +1 -1
  25. package/lib/knex/ecosystem.config.js +57 -43
  26. package/lib/knex/knexfile.ts +6 -6
  27. package/lib/knex/nodemon.json +2 -2
  28. package/lib/knex/package.json +14 -8
  29. package/lib/knex/src/app.ts +2 -3
  30. package/lib/knex/src/databases/index.ts +6 -6
  31. package/lib/knex/src/http/auth.http +12 -15
  32. package/lib/knex/src/http/users.http +12 -16
  33. package/lib/knex/src/index.ts +1 -0
  34. package/lib/knex/src/middlewares/auth.middleware.ts +4 -4
  35. package/lib/knex/src/server.ts +1 -2
  36. package/lib/knex/src/services/auth.service.ts +5 -5
  37. package/lib/knex/src/services/users.service.ts +3 -3
  38. package/lib/knex/src/tests/auth.test.ts +2 -2
  39. package/lib/knex/src/tests/index.test.ts +1 -1
  40. package/lib/knex/src/tests/users.test.ts +2 -2
  41. package/lib/knex/src/utils/logger.ts +5 -5
  42. package/lib/knex/src/utils/util.ts +1 -1
  43. package/lib/knex/tsconfig.json +2 -2
  44. package/lib/mongoose/.swcrc +39 -0
  45. package/lib/mongoose/Dockerfile +1 -1
  46. package/lib/mongoose/docker-compose.yml +0 -4
  47. package/lib/mongoose/ecosystem.config.js +42 -27
  48. package/lib/mongoose/nodemon.json +2 -2
  49. package/lib/mongoose/package.json +15 -8
  50. package/lib/mongoose/src/app.ts +2 -3
  51. package/lib/mongoose/src/configs/development.json +1 -1
  52. package/lib/mongoose/src/configs/production.json +1 -1
  53. package/lib/mongoose/src/configs/test.json +1 -1
  54. package/lib/mongoose/src/http/auth.http +32 -0
  55. package/lib/mongoose/src/http/users.http +34 -0
  56. package/lib/mongoose/src/index.ts +1 -0
  57. package/lib/mongoose/src/middlewares/auth.middleware.ts +3 -3
  58. package/lib/mongoose/src/server.ts +1 -2
  59. package/lib/mongoose/src/services/auth.service.ts +5 -5
  60. package/lib/mongoose/src/services/users.service.ts +3 -3
  61. package/lib/mongoose/src/utils/logger.ts +5 -5
  62. package/lib/mongoose/src/utils/util.ts +1 -1
  63. package/lib/mongoose/tsconfig.json +2 -2
  64. package/lib/prisma/.env +1 -1
  65. package/lib/prisma/.swcrc +37 -0
  66. package/lib/prisma/Dockerfile +1 -1
  67. package/lib/prisma/docker-compose.yml +1 -6
  68. package/lib/prisma/ecosystem.config.js +40 -24
  69. package/lib/prisma/nodemon.json +2 -2
  70. package/lib/prisma/package.json +17 -10
  71. package/lib/prisma/src/app.ts +2 -3
  72. package/lib/prisma/src/http/auth.http +12 -15
  73. package/lib/prisma/src/http/users.http +12 -16
  74. package/lib/prisma/src/index.ts +1 -0
  75. package/lib/prisma/src/middlewares/auth.middleware.ts +4 -4
  76. package/lib/prisma/src/server.ts +1 -2
  77. package/lib/prisma/src/services/auth.service.ts +5 -5
  78. package/lib/prisma/src/services/users.service.ts +3 -3
  79. package/lib/prisma/src/utils/logger.ts +5 -5
  80. package/lib/prisma/src/utils/util.ts +1 -1
  81. package/lib/prisma/tsconfig.json +2 -2
  82. package/lib/routing-controllers/.swcrc +37 -0
  83. package/lib/routing-controllers/Dockerfile +1 -1
  84. package/lib/routing-controllers/ecosystem.config.js +40 -24
  85. package/lib/routing-controllers/nodemon.json +2 -2
  86. package/lib/routing-controllers/package.json +18 -11
  87. package/lib/routing-controllers/src/app.ts +33 -6
  88. package/lib/routing-controllers/src/http/auth.http +12 -15
  89. package/lib/routing-controllers/src/http/users.http +12 -16
  90. package/lib/routing-controllers/src/index.ts +1 -0
  91. package/lib/routing-controllers/src/middlewares/auth.middleware.ts +3 -3
  92. package/lib/routing-controllers/src/middlewares/validation.middleware.ts +10 -2
  93. package/lib/routing-controllers/src/models/users.model.ts +5 -5
  94. package/lib/routing-controllers/src/server.ts +1 -3
  95. package/lib/routing-controllers/src/services/auth.service.ts +5 -5
  96. package/lib/routing-controllers/src/services/users.service.ts +3 -3
  97. package/lib/routing-controllers/src/utils/logger.ts +5 -5
  98. package/lib/routing-controllers/src/utils/util.ts +1 -1
  99. package/lib/routing-controllers/tsconfig.json +2 -2
  100. package/lib/sequelize/.swcrc +39 -0
  101. package/lib/sequelize/Dockerfile +1 -1
  102. package/lib/sequelize/docker-compose.yml +1 -6
  103. package/lib/sequelize/ecosystem.config.js +42 -27
  104. package/lib/sequelize/nodemon.json +2 -2
  105. package/lib/sequelize/package.json +15 -8
  106. package/lib/sequelize/src/app.ts +1 -2
  107. package/lib/sequelize/src/configs/development.json +2 -2
  108. package/lib/sequelize/src/configs/production.json +1 -1
  109. package/lib/sequelize/src/configs/test.json +1 -1
  110. package/lib/sequelize/src/http/auth.http +32 -0
  111. package/lib/sequelize/src/http/users.http +34 -0
  112. package/lib/sequelize/src/index.ts +1 -0
  113. package/lib/sequelize/src/middlewares/auth.middleware.ts +4 -4
  114. package/lib/sequelize/src/server.ts +1 -2
  115. package/lib/sequelize/src/services/auth.service.ts +5 -5
  116. package/lib/sequelize/src/services/users.service.ts +3 -3
  117. package/lib/sequelize/src/utils/logger.ts +5 -5
  118. package/lib/sequelize/src/utils/util.ts +1 -1
  119. package/lib/sequelize/tsconfig.json +2 -2
  120. package/lib/starter.js +8 -12
  121. package/lib/typeorm/.swcrc +39 -0
  122. package/lib/typeorm/Dockerfile +1 -1
  123. package/lib/typeorm/docker-compose.yml +1 -1
  124. package/lib/typeorm/ecosystem.config.js +42 -27
  125. package/lib/typeorm/nodemon.json +2 -2
  126. package/lib/typeorm/package.json +15 -8
  127. package/lib/typeorm/src/app.ts +1 -2
  128. package/lib/typeorm/src/configs/development.json +1 -1
  129. package/lib/typeorm/src/configs/production.json +1 -1
  130. package/lib/typeorm/src/configs/test.json +1 -1
  131. package/lib/typeorm/src/databases/index.ts +5 -5
  132. package/lib/typeorm/src/{entity → entities}/users.entity.ts +3 -3
  133. package/lib/typeorm/src/http/auth.http +12 -15
  134. package/lib/typeorm/src/http/users.http +12 -16
  135. package/lib/typeorm/src/index.ts +1 -0
  136. package/lib/typeorm/src/middlewares/auth.middleware.ts +5 -9
  137. package/lib/typeorm/src/server.ts +1 -2
  138. package/lib/typeorm/src/services/auth.service.ts +13 -17
  139. package/lib/typeorm/src/services/users.service.ts +16 -22
  140. package/lib/typeorm/src/utils/logger.ts +5 -5
  141. package/lib/typeorm/src/utils/util.ts +1 -1
  142. package/lib/typeorm/tsconfig.json +3 -3
  143. package/package.json +12 -4
@@ -1,37 +1,34 @@
1
- import bcrypt from 'bcrypt';
1
+ import { compare, hash } from 'bcrypt';
2
2
  import config from 'config';
3
- import jwt from 'jsonwebtoken';
4
- import { getRepository } from 'typeorm';
3
+ import { sign } from 'jsonwebtoken';
4
+ import { EntityRepository, Repository } from 'typeorm';
5
5
  import { CreateUserDto } from '@dtos/users.dto';
6
- import { UserEntity } from '@entity/users.entity';
6
+ import { UserEntity } from '@entities/users.entity';
7
7
  import { HttpException } from '@exceptions/HttpException';
8
8
  import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
9
9
  import { User } from '@interfaces/users.interface';
10
10
  import { isEmpty } from '@utils/util';
11
11
 
12
- class AuthService {
13
- public users = UserEntity;
14
-
12
+ @EntityRepository()
13
+ class AuthService extends Repository<UserEntity> {
15
14
  public async signup(userData: CreateUserDto): Promise<User> {
16
15
  if (isEmpty(userData)) throw new HttpException(400, "You're not userData");
17
16
 
18
- const userRepository = getRepository(this.users);
19
- const findUser: User = await userRepository.findOne({ where: { email: userData.email } });
17
+ const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
20
18
  if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
21
19
 
22
- const hashedPassword = await bcrypt.hash(userData.password, 10);
23
- const createUserData: User = await userRepository.save({ ...userData, password: hashedPassword });
20
+ const hashedPassword = await hash(userData.password, 10);
21
+ const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
24
22
  return createUserData;
25
23
  }
26
24
 
27
25
  public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
28
26
  if (isEmpty(userData)) throw new HttpException(400, "You're not userData");
29
27
 
30
- const userRepository = getRepository(this.users);
31
- const findUser: User = await userRepository.findOne({ where: { email: userData.email } });
28
+ const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
32
29
  if (!findUser) throw new HttpException(409, `You're email ${userData.email} not found`);
33
30
 
34
- const isPasswordMatching: boolean = await bcrypt.compare(userData.password, findUser.password);
31
+ const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
35
32
  if (!isPasswordMatching) throw new HttpException(409, "You're password not matching");
36
33
 
37
34
  const tokenData = this.createToken(findUser);
@@ -43,8 +40,7 @@ class AuthService {
43
40
  public async logout(userData: User): Promise<User> {
44
41
  if (isEmpty(userData)) throw new HttpException(400, "You're not userData");
45
42
 
46
- const userRepository = getRepository(this.users);
47
- const findUser: User = await userRepository.findOne({ where: { email: userData.email, password: userData.password } });
43
+ const findUser: User = await UserEntity.findOne({ where: { email: userData.email, password: userData.password } });
48
44
  if (!findUser) throw new HttpException(409, "You're not user");
49
45
 
50
46
  return findUser;
@@ -55,7 +51,7 @@ class AuthService {
55
51
  const secretKey: string = config.get('secretKey');
56
52
  const expiresIn: number = 60 * 60;
57
53
 
58
- return { expiresIn, token: jwt.sign(dataStoredInToken, secretKey, { expiresIn }) };
54
+ return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
59
55
  }
60
56
 
61
57
  public createCookie(tokenData: TokenData): string {
@@ -1,25 +1,22 @@
1
- import bcrypt from 'bcrypt';
2
- import { getRepository } from 'typeorm';
1
+ import { hash } from 'bcrypt';
2
+ import { EntityRepository, Repository } from 'typeorm';
3
3
  import { CreateUserDto } from '@dtos/users.dto';
4
- import { UserEntity } from '@entity/users.entity';
4
+ import { UserEntity } from '@entities/users.entity';
5
5
  import { HttpException } from '@exceptions/HttpException';
6
6
  import { User } from '@interfaces/users.interface';
7
7
  import { isEmpty } from '@utils/util';
8
8
 
9
- class UserService {
10
- public users = UserEntity;
11
-
9
+ @EntityRepository()
10
+ class UserService extends Repository<UserEntity> {
12
11
  public async findAllUser(): Promise<User[]> {
13
- const userRepository = getRepository(this.users);
14
- const users: User[] = await userRepository.find();
12
+ const users: User[] = await UserEntity.find();
15
13
  return users;
16
14
  }
17
15
 
18
16
  public async findUserById(userId: number): Promise<User> {
19
17
  if (isEmpty(userId)) throw new HttpException(400, "You're not userId");
20
18
 
21
- const userRepository = getRepository(this.users);
22
- const findUser: User = await userRepository.findOne({ where: { id: userId } });
19
+ const findUser: User = await UserEntity.findOne({ where: { id: userId } });
23
20
  if (!findUser) throw new HttpException(409, "You're not user");
24
21
 
25
22
  return findUser;
@@ -28,12 +25,11 @@ class UserService {
28
25
  public async createUser(userData: CreateUserDto): Promise<User> {
29
26
  if (isEmpty(userData)) throw new HttpException(400, "You're not userData");
30
27
 
31
- const userRepository = getRepository(this.users);
32
- const findUser: User = await userRepository.findOne({ where: { email: userData.email } });
28
+ const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
33
29
  if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
34
30
 
35
- const hashedPassword = await bcrypt.hash(userData.password, 10);
36
- const createUserData: User = await userRepository.save({ ...userData, password: hashedPassword });
31
+ const hashedPassword = await hash(userData.password, 10);
32
+ const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
37
33
 
38
34
  return createUserData;
39
35
  }
@@ -41,25 +37,23 @@ class UserService {
41
37
  public async updateUser(userId: number, userData: CreateUserDto): Promise<User> {
42
38
  if (isEmpty(userData)) throw new HttpException(400, "You're not userData");
43
39
 
44
- const userRepository = getRepository(this.users);
45
- const findUser: User = await userRepository.findOne({ where: { id: userId } });
40
+ const findUser: User = await UserEntity.findOne({ where: { id: userId } });
46
41
  if (!findUser) throw new HttpException(409, "You're not user");
47
42
 
48
- const hashedPassword = await bcrypt.hash(userData.password, 10);
49
- await userRepository.update(userId, { ...userData, password: hashedPassword });
43
+ const hashedPassword = await hash(userData.password, 10);
44
+ await UserEntity.update(userId, { ...userData, password: hashedPassword });
50
45
 
51
- const updateUser: User = await userRepository.findOne({ where: { id: userId } });
46
+ const updateUser: User = await UserEntity.findOne({ where: { id: userId } });
52
47
  return updateUser;
53
48
  }
54
49
 
55
50
  public async deleteUser(userId: number): Promise<User> {
56
51
  if (isEmpty(userId)) throw new HttpException(400, "You're not userId");
57
52
 
58
- const userRepository = getRepository(this.users);
59
- const findUser: User = await userRepository.findOne({ where: { id: userId } });
53
+ const findUser: User = await UserEntity.findOne({ where: { id: userId } });
60
54
  if (!findUser) throw new HttpException(409, "You're not user");
61
55
 
62
- await userRepository.delete({ id: userId });
56
+ await UserEntity.delete({ id: userId });
63
57
  return findUser;
64
58
  }
65
59
  }
@@ -1,14 +1,14 @@
1
1
  import config from 'config';
2
- import fs from 'fs';
3
- import path from 'path';
2
+ import { existsSync, mkdirSync } from 'fs';
3
+ import { join } from 'path';
4
4
  import winston from 'winston';
5
5
  import winstonDaily from 'winston-daily-rotate-file';
6
6
 
7
7
  // logs dir
8
- const logDir: string = path.join(__dirname, config.get('log.dir'));
8
+ const logDir: string = join(__dirname, config.get('log.dir'));
9
9
 
10
- if (!fs.existsSync(logDir)) {
11
- fs.mkdirSync(logDir);
10
+ if (!existsSync(logDir)) {
11
+ mkdirSync(logDir);
12
12
  }
13
13
 
14
14
  // Define log format
@@ -9,7 +9,7 @@ export const isEmpty = (value: string | number | object): boolean => {
9
9
  return true;
10
10
  } else if (typeof value !== 'number' && value === '') {
11
11
  return true;
12
- } else if (value === 'undefined' || value === undefined) {
12
+ } else if (typeof value === 'undefined' || value === undefined) {
13
13
  return true;
14
14
  } else if (value !== null && typeof value === 'object' && !Object.keys(value).length) {
15
15
  return true;
@@ -13,7 +13,7 @@
13
13
  "pretty": true,
14
14
  "sourceMap": true,
15
15
  "declaration": true,
16
- "outDir": "./dist",
16
+ "outDir": "dist",
17
17
  "allowJs": true,
18
18
  "noEmit": false,
19
19
  "esModuleInterop": true,
@@ -25,7 +25,7 @@
25
25
  "@controllers/*": ["controllers/*"],
26
26
  "@databases": ["databases"],
27
27
  "@dtos/*": ["dtos/*"],
28
- "@entity/*": ["entity/*"],
28
+ "@entities/*": ["entities/*"],
29
29
  "@exceptions/*": ["exceptions/*"],
30
30
  "@interfaces/*": ["interfaces/*"],
31
31
  "@middlewares/*": ["middlewares/*"],
@@ -35,5 +35,5 @@
35
35
  }
36
36
  },
37
37
  "include": ["src/**/*.ts", "src/**/*.json", ".env"],
38
- "exclude": ["node_modules"]
38
+ "exclude": ["node_modules", "src/http", "src/logs", "src/tests"]
39
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-express-starter",
3
- "version": "6.0.0",
3
+ "version": "6.3.0",
4
4
  "description": "Quick and Easy TypeScript Express Starter",
5
5
  "author": "AGUMON <ljlm0402@gmail.com>",
6
6
  "license": "MIT",
@@ -8,12 +8,12 @@
8
8
  "typescript",
9
9
  "express",
10
10
  "routing-controllers",
11
+ "routing-controllers-openapi",
11
12
  "sequelize",
12
13
  "mongoose",
13
14
  "typeorm",
14
15
  "knex",
15
16
  "prisma",
16
- "querybuilder",
17
17
  "jest",
18
18
  "nodemon",
19
19
  "jsonwebtoken",
@@ -31,7 +31,8 @@
31
31
  "mysql",
32
32
  "mariadb",
33
33
  "mongodb",
34
- "postgresql"
34
+ "postgresql",
35
+ "swc"
35
36
  ],
36
37
  "main": "bin/cli.js",
37
38
  "bin": {
@@ -49,6 +50,13 @@
49
50
  "ora": "^4.0.3"
50
51
  },
51
52
  "devDependencies": {},
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "engines": {
57
+ "node": ">= 10.13.0",
58
+ "npm": ">= 6.11.0"
59
+ },
52
60
  "repository": {
53
61
  "type": "git",
54
62
  "url": "git+https://github.com/ljlm0402/typescript-express-starter.git"
@@ -57,4 +65,4 @@
57
65
  "url": "https://github.com/ljlm0402/typescript-express-starter/issues"
58
66
  },
59
67
  "homepage": "https://github.com/ljlm0402/typescript-express-starter#readme"
60
- }
68
+ }