express-generator-typescript 2.7.14 → 2.7.16

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.
@@ -7,7 +7,7 @@ import server from './server';
7
7
  Constants
8
8
  ******************************************************************************/
9
9
 
10
- const SERVER_START_MSG =
10
+ const SERVER_START_MESSAGE =
11
11
  'Express server started on port: ' + EnvVars.Port.toString();
12
12
 
13
13
  /******************************************************************************
@@ -19,6 +19,6 @@ server.listen(EnvVars.Port, (err) => {
19
19
  if (!!err) {
20
20
  logger.err(err.message);
21
21
  } else {
22
- logger.info(SERVER_START_MSG);
22
+ logger.info(SERVER_START_MESSAGE);
23
23
  }
24
24
  });
@@ -3,7 +3,7 @@ import { parseObject, Schema, testObject } from 'jet-validators/utils';
3
3
 
4
4
  import { transformIsDate } from '@src/common/utils/validators';
5
5
 
6
- import { IModel } from './common/IModel';
6
+ import { Entity } from './common/types';
7
7
 
8
8
  /******************************************************************************
9
9
  Constants
@@ -30,21 +30,20 @@ const schema: Schema<IUser> = {
30
30
  /**
31
31
  * @entity users
32
32
  */
33
- export interface IUser extends IModel {
33
+ export interface IUser extends Entity {
34
34
  name: string;
35
35
  email: string;
36
- }
36
+ };
37
37
 
38
38
  /******************************************************************************
39
39
  Setup
40
40
  ******************************************************************************/
41
41
 
42
-
43
42
  // Set the "parseUser" function
44
43
  const parseUser = parseObject<IUser>(schema);
45
44
 
46
45
  // For the APIs make sure the right fields are complete
47
- const testIsCompleteUser = testObject<IUser>({
46
+ const isCompleteUser = testObject<IUser>({
48
47
  ...schema,
49
48
  name: isNonEmptyString,
50
49
  email: isNonEmptyString,
@@ -57,7 +56,7 @@ const testIsCompleteUser = testObject<IUser>({
57
56
  /**
58
57
  * New user object.
59
58
  */
60
- function __new__(user?: Partial<IUser>): IUser {
59
+ function new_(user?: Partial<IUser>): IUser {
61
60
  return parseUser({ ...GetDefaults(), ...user }, (errors) => {
62
61
  throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
63
62
  });
@@ -68,6 +67,6 @@ function __new__(user?: Partial<IUser>): IUser {
68
67
  ******************************************************************************/
69
68
 
70
69
  export default {
71
- new: __new__,
72
- isComplete: testIsCompleteUser,
70
+ new: new_,
71
+ isComplete: isCompleteUser,
73
72
  } as const;
@@ -1,4 +1,4 @@
1
- export interface IModel {
1
+ export interface Entity {
2
2
  id: number; // @PK
3
3
  created: Date | string; // @audit
4
4
  }
@@ -1,25 +1,26 @@
1
1
  import jsonfile from 'jsonfile';
2
2
 
3
3
  import EnvVars, { NodeEnvs } from '@src/common/constants/env';
4
- import { IUser } from '@src/models/User';
4
+ import { IUser } from '@src/models/User.model';
5
5
 
6
6
  /******************************************************************************
7
7
  Constants
8
8
  ******************************************************************************/
9
9
 
10
- const DATABASE_FILE_PATH = __dirname + '/common' + (
11
- EnvVars.NodeEnv === NodeEnvs.TEST
12
- ? '/database.test.json'
13
- : '/database.json'
14
- );
10
+ const DATABASE_FILE_PATH =
11
+ __dirname +
12
+ '/common' +
13
+ (EnvVars.NodeEnv === NodeEnvs.TEST
14
+ ? '/database.test.json'
15
+ : '/database.json');
15
16
 
16
17
  /******************************************************************************
17
18
  Types
18
19
  ******************************************************************************/
19
20
 
20
- interface IDatabase {
21
+ type Database = {
21
22
  users: IUser[];
22
- }
23
+ };
23
24
 
24
25
  /******************************************************************************
25
26
  Functions
@@ -28,14 +29,14 @@ interface IDatabase {
28
29
  /**
29
30
  * Fetch the json from the file.
30
31
  */
31
- function openDb(): Promise<IDatabase> {
32
- return jsonfile.readFile(DATABASE_FILE_PATH) as Promise<IDatabase>;
32
+ function openDb(): Promise<Database> {
33
+ return jsonfile.readFile(DATABASE_FILE_PATH) as Promise<Database>;
33
34
  }
34
35
 
35
36
  /**
36
37
  * Update the file.
37
38
  */
38
- function saveDb(db: IDatabase): Promise<void> {
39
+ function saveDb(db: Database): Promise<void> {
39
40
  return jsonfile.writeFile(DATABASE_FILE_PATH, db);
40
41
  }
41
42
 
@@ -43,7 +44,7 @@ function saveDb(db: IDatabase): Promise<void> {
43
44
  * Empty the database
44
45
  */
45
46
  function cleanDb(): Promise<void> {
46
- return jsonfile.writeFile( DATABASE_FILE_PATH, {});
47
+ return jsonfile.writeFile(DATABASE_FILE_PATH, {});
47
48
  }
48
49
 
49
50
  /******************************************************************************
@@ -1,5 +1,5 @@
1
1
  import { getRandomInt } from '@src/common/utils/number-utils';
2
- import { IUser } from '@src/models/User';
2
+ import { IUser } from '@src/models/User.model';
3
3
 
4
4
  import orm from './MockOrm';
5
5
 
@@ -72,7 +72,7 @@ async function update(user: IUser): Promise<void> {
72
72
  /**
73
73
  * Delete one user.
74
74
  */
75
- async function __delete__(id: number): Promise<void> {
75
+ async function delete_(id: number): Promise<void> {
76
76
  const db = await orm.openDb();
77
77
  for (let i = 0; i < db.users.length; i++) {
78
78
  if (db.users[i].id === id) {
@@ -86,7 +86,7 @@ async function __delete__(id: number): Promise<void> {
86
86
 
87
87
  /**
88
88
  * @testOnly
89
- *
89
+ *
90
90
  * Delete every user record.
91
91
  */
92
92
  async function deleteAllUsers(): Promise<void> {
@@ -97,7 +97,7 @@ async function deleteAllUsers(): Promise<void> {
97
97
 
98
98
  /**
99
99
  * @testOnly
100
- *
100
+ *
101
101
  * Insert multiple users. Can't do multiple at once cause using a plain file
102
102
  * for now.
103
103
  */
@@ -125,7 +125,7 @@ export default {
125
125
  getAll,
126
126
  add,
127
127
  update,
128
- delete: __delete__,
128
+ delete: delete_,
129
129
  deleteAllUsers,
130
130
  insertMultiple,
131
131
  } as const;
@@ -1 +1,22 @@
1
- {"users":[{"id":366115170645,"name":"Sean Maxwell","email":"smaxwell@example.com","created":"2024-03-22T05:14:36.252Z"},{"id":310946254456,"name":"John Smith","email":"john.smith@example.com","created":"2024-03-22T05:20:55.079Z"},{"id":143027113460,"name":"Gordan Freeman","email":"nova@prospect.com","created":"2024-03-22T05:42:18.895Z"}]}
1
+ {
2
+ "users": [
3
+ {
4
+ "id": 366115170645,
5
+ "name": "Sean Maxwell",
6
+ "email": "smaxwell@example.com",
7
+ "created": "2024-03-22T05:14:36.252Z"
8
+ },
9
+ {
10
+ "id": 310946254456,
11
+ "name": "John Smith",
12
+ "email": "john.smith@example.com",
13
+ "created": "2024-03-22T05:20:55.079Z"
14
+ },
15
+ {
16
+ "id": 143027113460,
17
+ "name": "Gordan Freeman",
18
+ "email": "nova@prospect.com",
19
+ "created": "2024-03-22T05:42:18.895Z"
20
+ }
21
+ ]
22
+ }
@@ -1 +1 @@
1
- {"users":[{"id":743599328040,"name":"Bill","email":"sean.maxwell@gmail.com","created":"2026-01-22T02:53:04.104Z"},{"id":366376663219,"name":"John Smith","email":"john.smith@gmail.com","created":"2026-01-22T02:53:04.104Z"},{"id":223776680823,"name":"Gordan Freeman","email":"gordan.freeman@gmail.com","created":"2026-01-22T02:53:04.104Z"}]}
1
+ {"users":[{"id":279249255772,"name":"Bill","email":"sean.maxwell@gmail.com","created":"2026-01-28T05:15:24.564Z"},{"id":374980001180,"name":"John Smith","email":"john.smith@gmail.com","created":"2026-01-28T05:15:24.564Z"},{"id":551114509623,"name":"Gordan Freeman","email":"gordan.freeman@gmail.com","created":"2026-01-28T05:15:24.564Z"}]}
@@ -2,7 +2,7 @@ import { isNumber } from 'jet-validators';
2
2
  import { transform } from 'jet-validators/utils';
3
3
 
4
4
  import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
5
- import User from '@src/models/User';
5
+ import User from '@src/models/User.model';
6
6
  import UserService from '@src/services/UserService';
7
7
 
8
8
  import { IReq, IRes } from './common/express-types';
@@ -12,7 +12,7 @@ import parseReq from './common/parseReq';
12
12
  Constants
13
13
  ******************************************************************************/
14
14
 
15
- const Validators = {
15
+ const reqValidators = {
16
16
  add: parseReq({ user: User.isComplete }),
17
17
  update: parseReq({ user: User.isComplete }),
18
18
  delete: parseReq({ id: transform(Number, isNumber) }),
@@ -38,7 +38,7 @@ async function getAll(_: IReq, res: IRes) {
38
38
  * @route POST /api/users/add
39
39
  */
40
40
  async function add(req: IReq, res: IRes) {
41
- const { user } = Validators.add(req.body);
41
+ const { user } = reqValidators.add(req.body);
42
42
  await UserService.addOne(user);
43
43
  res.status(HttpStatusCodes.CREATED).end();
44
44
  }
@@ -49,7 +49,7 @@ async function add(req: IReq, res: IRes) {
49
49
  * @route PUT /api/users/update
50
50
  */
51
51
  async function update(req: IReq, res: IRes) {
52
- const { user } = Validators.update(req.body);
52
+ const { user } = reqValidators.update(req.body);
53
53
  await UserService.updateOne(user);
54
54
  res.status(HttpStatusCodes.OK).end();
55
55
  }
@@ -59,8 +59,8 @@ async function update(req: IReq, res: IRes) {
59
59
  *
60
60
  * @route DELETE /api/users/delete/:id
61
61
  */
62
- async function __delete__(req: IReq, res: IRes) {
63
- const { id } = Validators.delete(req.params);
62
+ async function delete_(req: IReq, res: IRes) {
63
+ const { id } = reqValidators.delete(req.params);
64
64
  await UserService.delete(id);
65
65
  res.status(HttpStatusCodes.OK).end();
66
66
  }
@@ -73,5 +73,5 @@ export default {
73
73
  getAll,
74
74
  add,
75
75
  update,
76
- delete: __delete__,
76
+ delete: delete_,
77
77
  } as const;
@@ -10,7 +10,7 @@ import UserRoutes from './UserRoutes';
10
10
 
11
11
  const apiRouter = Router();
12
12
 
13
- // ----------------------- Add UserRouter ---------------------------------- //
13
+ // ----------------------- Add UserRouter --------------------------------- //
14
14
 
15
15
  const userRouter = Router();
16
16
 
@@ -22,7 +22,7 @@ userRouter.delete(Paths.Users.Delete, UserRoutes.delete);
22
22
  apiRouter.use(Paths.Users._, userRouter);
23
23
 
24
24
  /******************************************************************************
25
- Export default
25
+ Export
26
26
  ******************************************************************************/
27
27
 
28
28
  export default apiRouter;
@@ -1,6 +1,6 @@
1
1
  import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
2
2
  import { RouteError } from '@src/common/utils/route-errors';
3
- import { IUser } from '@src/models/User';
3
+ import { IUser } from '@src/models/User.model';
4
4
  import UserRepo from '@src/repos/UserRepo';
5
5
 
6
6
  /******************************************************************************
@@ -43,7 +43,7 @@ async function updateOne(user: IUser): Promise<void> {
43
43
  /**
44
44
  * Delete a user by their id.
45
45
  */
46
- async function __delete__(id: number): Promise<void> {
46
+ async function deleteOne(id: number): Promise<void> {
47
47
  const persists = await UserRepo.persists(id);
48
48
  if (!persists) {
49
49
  throw new RouteError(HttpStatusCodes.NOT_FOUND, Errors.USER_NOT_FOUND);
@@ -60,5 +60,5 @@ export default {
60
60
  getAll,
61
61
  addOne,
62
62
  updateOne,
63
- delete: __delete__,
63
+ delete: deleteOne,
64
64
  } as const;
@@ -1,4 +1,4 @@
1
- import { IUser } from '@src/models/User';
1
+ import { IUser } from '@src/models/User.model';
2
2
 
3
3
  /******************************************************************************
4
4
  Types
@@ -5,7 +5,7 @@ import { ParseError, parseJson } from 'jet-validators/utils';
5
5
  Types
6
6
  ******************************************************************************/
7
7
 
8
- interface IValidationError {
8
+ type ValidationError = {
9
9
  message: string;
10
10
  errors: ParseError[];
11
11
  }
@@ -17,9 +17,9 @@ interface IValidationError {
17
17
  /**
18
18
  * JSON parse a validation error.
19
19
  */
20
- export function parseValidationError(arg: unknown): IValidationError {
20
+ export function parseValidationError(arg: unknown): ValidationError {
21
21
  if (!isString(arg)) {
22
22
  throw new Error('Not a string');
23
23
  }
24
- return parseJson<IValidationError>(arg);
24
+ return parseJson<ValidationError>(arg);
25
25
  }
@@ -6,10 +6,10 @@ import { Response } from 'supertest';
6
6
 
7
7
  // Use generics to add properties to 'body'
8
8
  export interface IRes<T = object> extends Omit<Response, 'body'> {
9
- body: T & { error?: string | IErrorObject };
9
+ body: T & { error?: string | ErrorObject };
10
10
  }
11
11
 
12
- interface IErrorObject {
12
+ interface ErrorObject {
13
13
  message: string;
14
14
  [key: string]: unknown;
15
15
  }
@@ -1,7 +1,7 @@
1
1
  import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
2
2
  import { JetPaths as Paths } from '@src/common/constants/Paths';
3
3
  import { ValidationError } from '@src/common/utils/route-errors';
4
- import User, { IUser } from '@src/models/User';
4
+ import User, { IUser } from '@src/models/User.model';
5
5
  import UserRepo from '@src/repos/UserRepo';
6
6
 
7
7
  import { agent } from './support/agent';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.7.14",
3
+ "version": "2.7.16",
4
4
  "description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
5
5
  "scripts": {
6
6
  "express-generator-typescript": "node bin/cli.js",