express-generator-typescript 2.7.15 → 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.
@@ -9,14 +9,14 @@ import { Entity } from './common/types';
9
9
  Constants
10
10
  ******************************************************************************/
11
11
 
12
- const GetDefaults = (): User => ({
12
+ const GetDefaults = (): IUser => ({
13
13
  id: 0,
14
14
  name: '',
15
15
  email: '',
16
16
  created: new Date(),
17
17
  });
18
18
 
19
- const schema: Schema<User> = {
19
+ const schema: Schema<IUser> = {
20
20
  id: isUnsignedInteger,
21
21
  name: isString,
22
22
  email: isString,
@@ -30,7 +30,7 @@ const schema: Schema<User> = {
30
30
  /**
31
31
  * @entity users
32
32
  */
33
- export type User = Entity & {
33
+ export interface IUser extends Entity {
34
34
  name: string;
35
35
  email: string;
36
36
  };
@@ -40,10 +40,10 @@ export type User = Entity & {
40
40
  ******************************************************************************/
41
41
 
42
42
  // Set the "parseUser" function
43
- const parseUser = parseObject<User>(schema);
43
+ const parseUser = parseObject<IUser>(schema);
44
44
 
45
45
  // For the APIs make sure the right fields are complete
46
- const isCompleteUser = testObject<User>({
46
+ const isCompleteUser = testObject<IUser>({
47
47
  ...schema,
48
48
  name: isNonEmptyString,
49
49
  email: isNonEmptyString,
@@ -56,7 +56,7 @@ const isCompleteUser = testObject<User>({
56
56
  /**
57
57
  * New user object.
58
58
  */
59
- function newUser(user?: Partial<User>): User {
59
+ function new_(user?: Partial<IUser>): IUser {
60
60
  return parseUser({ ...GetDefaults(), ...user }, (errors) => {
61
61
  throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
62
62
  });
@@ -67,6 +67,6 @@ function newUser(user?: Partial<User>): User {
67
67
  ******************************************************************************/
68
68
 
69
69
  export default {
70
- new: newUser,
70
+ new: new_,
71
71
  isComplete: isCompleteUser,
72
72
  } as const;
@@ -1,4 +1,4 @@
1
- export type Entity = {
1
+ export interface Entity {
2
2
  id: number; // @PK
3
3
  created: Date | string; // @audit
4
- };
4
+ }
@@ -1,7 +1,7 @@
1
1
  import jsonfile from 'jsonfile';
2
2
 
3
3
  import EnvVars, { NodeEnvs } from '@src/common/constants/env';
4
- import { User } from '@src/models/UserModel';
4
+ import { IUser } from '@src/models/User.model';
5
5
 
6
6
  /******************************************************************************
7
7
  Constants
@@ -19,7 +19,7 @@ const DATABASE_FILE_PATH =
19
19
  ******************************************************************************/
20
20
 
21
21
  type Database = {
22
- users: User[];
22
+ users: IUser[];
23
23
  };
24
24
 
25
25
  /******************************************************************************
@@ -1,5 +1,5 @@
1
1
  import { getRandomInt } from '@src/common/utils/number-utils';
2
- import { User } from '@src/models/UserModel';
2
+ import { IUser } from '@src/models/User.model';
3
3
 
4
4
  import orm from './MockOrm';
5
5
 
@@ -10,7 +10,7 @@ import orm from './MockOrm';
10
10
  /**
11
11
  * Get one user.
12
12
  */
13
- async function getOne(email: string): Promise<User | null> {
13
+ async function getOne(email: string): Promise<IUser | null> {
14
14
  const db = await orm.openDb();
15
15
  for (const user of db.users) {
16
16
  if (user.email === email) {
@@ -36,7 +36,7 @@ async function persists(id: number): Promise<boolean> {
36
36
  /**
37
37
  * Get all users.
38
38
  */
39
- async function getAll(): Promise<User[]> {
39
+ async function getAll(): Promise<IUser[]> {
40
40
  const db = await orm.openDb();
41
41
  return db.users;
42
42
  }
@@ -44,7 +44,7 @@ async function getAll(): Promise<User[]> {
44
44
  /**
45
45
  * Add one user.
46
46
  */
47
- async function add(user: User): Promise<void> {
47
+ async function add(user: IUser): Promise<void> {
48
48
  const db = await orm.openDb();
49
49
  user.id = getRandomInt();
50
50
  db.users.push(user);
@@ -54,7 +54,7 @@ async function add(user: User): Promise<void> {
54
54
  /**
55
55
  * Update a user.
56
56
  */
57
- async function update(user: User): Promise<void> {
57
+ async function update(user: IUser): Promise<void> {
58
58
  const db = await orm.openDb();
59
59
  for (let i = 0; i < db.users.length; i++) {
60
60
  if (db.users[i].id === user.id) {
@@ -72,7 +72,7 @@ async function update(user: User): 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) {
@@ -102,8 +102,8 @@ async function deleteAllUsers(): Promise<void> {
102
102
  * for now.
103
103
  */
104
104
  async function insertMultiple(
105
- users: User[] | readonly User[],
106
- ): Promise<User[]> {
105
+ users: IUser[] | readonly IUser[],
106
+ ): Promise<IUser[]> {
107
107
  const db = await orm.openDb(),
108
108
  usersF = [...users];
109
109
  for (const user of usersF) {
@@ -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 @@
1
- {"users":[{"id":146631637670,"name":"Bill","email":"sean.maxwell@gmail.com","created":"2026-01-26T00:52:08.804Z"},{"id":498481378998,"name":"John Smith","email":"john.smith@gmail.com","created":"2026-01-26T00:52:08.804Z"},{"id":878476468362,"name":"Gordan Freeman","email":"gordan.freeman@gmail.com","created":"2026-01-26T00:52:08.804Z"}]}
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 UserModel from '@src/models/UserModel';
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';
@@ -13,8 +13,8 @@ import parseReq from './common/parseReq';
13
13
  ******************************************************************************/
14
14
 
15
15
  const reqValidators = {
16
- add: parseReq({ user: UserModel.isComplete }),
17
- update: parseReq({ user: UserModel.isComplete }),
16
+ add: parseReq({ user: User.isComplete }),
17
+ update: parseReq({ user: User.isComplete }),
18
18
  delete: parseReq({ id: transform(Number, isNumber) }),
19
19
  } as const;
20
20
 
@@ -59,7 +59,7 @@ 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) {
62
+ async function delete_(req: IReq, res: IRes) {
63
63
  const { id } = reqValidators.delete(req.params);
64
64
  await UserService.delete(id);
65
65
  res.status(HttpStatusCodes.OK).end();
@@ -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;
@@ -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 { User } from '@src/models/UserModel';
3
+ import { IUser } from '@src/models/User.model';
4
4
  import UserRepo from '@src/repos/UserRepo';
5
5
 
6
6
  /******************************************************************************
@@ -18,21 +18,21 @@ const Errors = {
18
18
  /**
19
19
  * Get all users.
20
20
  */
21
- function getAll(): Promise<User[]> {
21
+ function getAll(): Promise<IUser[]> {
22
22
  return UserRepo.getAll();
23
23
  }
24
24
 
25
25
  /**
26
26
  * Add one user.
27
27
  */
28
- function addOne(user: User): Promise<void> {
28
+ function addOne(user: IUser): Promise<void> {
29
29
  return UserRepo.add(user);
30
30
  }
31
31
 
32
32
  /**
33
33
  * Update one user.
34
34
  */
35
- async function updateOne(user: User): Promise<void> {
35
+ async function updateOne(user: IUser): Promise<void> {
36
36
  const persists = await UserRepo.persists(user.id);
37
37
  if (!persists) {
38
38
  throw new RouteError(HttpStatusCodes.NOT_FOUND, Errors.USER_NOT_FOUND);
@@ -1,10 +1,10 @@
1
- import { User } from '@src/models/UserModel';
1
+ import { IUser } from '@src/models/User.model';
2
2
 
3
3
  /******************************************************************************
4
4
  Types
5
5
  ******************************************************************************/
6
6
 
7
- type UserArray = User[] | readonly User[];
7
+ type UserArray = IUser[] | readonly IUser[];
8
8
 
9
9
  /******************************************************************************
10
10
  Functions
@@ -31,7 +31,7 @@ export function compareUserArrays(a: UserArray, b: UserArray): boolean {
31
31
  /**
32
32
  * Sort user array by email.
33
33
  */
34
- function sortByEmail(arr: UserArray): User[] {
34
+ function sortByEmail(arr: UserArray): IUser[] {
35
35
  return [...arr].sort((x, y) => {
36
36
  return x.email.localeCompare(y.email);
37
37
  });
@@ -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 UserModel, { User } from '@src/models/UserModel';
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';
@@ -15,9 +15,9 @@ import { compareUserArrays } from './common/comparators';
15
15
  ******************************************************************************/
16
16
 
17
17
  const DUMMY_USERS = [
18
- UserModel.new({ name: 'Sean Maxwell', email: 'sean.maxwell@gmail.com' }),
19
- UserModel.new({ name: 'John Smith', email: 'john.smith@gmail.com' }),
20
- UserModel.new({ name: 'Gordan Freeman', email: 'gordan.freeman@gmail.com' }),
18
+ User.new({ name: 'Sean Maxwell', email: 'sean.maxwell@gmail.com' }),
19
+ User.new({ name: 'John Smith', email: 'john.smith@gmail.com' }),
20
+ User.new({ name: 'Gordan Freeman', email: 'gordan.freeman@gmail.com' }),
21
21
  ] as const;
22
22
 
23
23
  const { BAD_REQUEST, CREATED, OK, NOT_FOUND } = HttpStatusCodes;
@@ -30,7 +30,7 @@ const { BAD_REQUEST, CREATED, OK, NOT_FOUND } = HttpStatusCodes;
30
30
  ******************************************************************************/
31
31
 
32
32
  describe('UserRouter', () => {
33
- let dbUsers: User[] = [];
33
+ let dbUsers: IUser[] = [];
34
34
 
35
35
  beforeEach(async () => {
36
36
  await UserRepo.deleteAllUsers();
@@ -42,7 +42,7 @@ describe('UserRouter', () => {
42
42
  'should return a JSON object with all the users and a status code of ' +
43
43
  `"${OK}" if the request was successful.`,
44
44
  async () => {
45
- const res: IRes<{ users: User[] }> = await agent.get(Paths.Users.Get);
45
+ const res: IRes<{ users: IUser[] }> = await agent.get(Paths.Users.Get);
46
46
  expect(res.status).toBe(OK);
47
47
  expect(compareUserArrays(res.body.users, DUMMY_USERS)).toBeTruthy();
48
48
  },
@@ -54,7 +54,7 @@ describe('UserRouter', () => {
54
54
  `should return a status code of "${CREATED}" if the request was ` +
55
55
  'successful.',
56
56
  async () => {
57
- const user = UserModel.new({ name: 'a', email: 'a@a.com' }),
57
+ const user = User.new({ name: 'a', email: 'a@a.com' }),
58
58
  res = await agent.post(Paths.Users.Add).send({ user });
59
59
  expect(res.status).toBe(CREATED);
60
60
  },
@@ -87,7 +87,7 @@ describe('UserRouter', () => {
87
87
  'should return a JSON object with an error message and a status code ' +
88
88
  `of "${BAD_REQUEST}" if id is the wrong data type`,
89
89
  async () => {
90
- const user = UserModel.new();
90
+ const user = User.new();
91
91
  user.id = '5' as unknown as number;
92
92
  const res: IRes = await agent.put(Paths.Users.Update).send({ user });
93
93
  expect(res.status).toBe(BAD_REQUEST);
@@ -102,7 +102,7 @@ describe('UserRouter', () => {
102
102
  `"${UserService.Errors.USER_NOT_FOUND}" and a status code of ` +
103
103
  `"${NOT_FOUND}" if the id was not found.`,
104
104
  async () => {
105
- const user = UserModel.new({ id: 4, name: 'a', email: 'a@a.com' }),
105
+ const user = User.new({ id: 4, name: 'a', email: 'a@a.com' }),
106
106
  res: IRes = await agent.put(Paths.Users.Update).send({ user });
107
107
  expect(res.status).toBe(NOT_FOUND);
108
108
  expect(res.body.error).toBe(UserService.Errors.USER_NOT_FOUND);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.7.15",
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",