express-generator-typescript 2.7.1 → 2.7.3
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.
- package/LICENSE +21 -21
- package/README-npm +20 -0
- package/README.md +85 -20
- package/lib/project-files/README.md +65 -65
- package/lib/project-files/config.ts +22 -22
- package/lib/project-files/eslint.config.ts +95 -95
- package/lib/project-files/package.json +58 -58
- package/lib/project-files/src/common/constants/ENV.ts +21 -21
- package/lib/project-files/src/common/constants/HttpStatusCodes.ts +391 -391
- package/lib/project-files/src/common/constants/Paths.ts +11 -11
- package/lib/project-files/src/common/constants/index.ts +11 -11
- package/lib/project-files/src/common/util/route-errors.ts +37 -37
- package/lib/project-files/src/common/util/validators.ts +22 -22
- package/lib/project-files/src/index.ts +17 -4
- package/lib/project-files/src/models/User.ts +4 -4
- package/lib/project-files/src/models/common/types/index.ts +5 -5
- package/lib/project-files/src/public/scripts/http.js +26 -26
- package/lib/project-files/src/public/scripts/users.js +141 -141
- package/lib/project-files/src/public/stylesheets/users.css +48 -48
- package/lib/project-files/src/repos/MockOrm.ts +62 -62
- package/lib/project-files/src/repos/database.json +1 -1
- package/lib/project-files/src/repos/database.test.json +1 -22
- package/lib/project-files/src/routes/common/types/index.ts +11 -11
- package/lib/project-files/src/routes/common/util/index.ts +18 -18
- package/lib/project-files/src/routes/index.ts +33 -33
- package/lib/project-files/src/services/UserService.ts +73 -73
- package/lib/project-files/src/views/users.html +132 -132
- package/lib/project-files/tests/common/Paths.ts +5 -5
- package/lib/project-files/tests/common/types/index.ts +16 -16
- package/lib/project-files/tests/common/util/index.ts +38 -38
- package/lib/project-files/tests/support/setup.ts +26 -26
- package/lib/project-files/tsconfig.json +1 -1
- package/lib/project-files/tsconfig.prod.json +30 -30
- package/lib/project-files/{vitest.config.ts → vitest.config.mts} +18 -18
- package/package.json +1 -1
- package/README-git +0 -95
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import jsonfile from 'jsonfile';
|
|
2
|
-
|
|
3
|
-
import ENV from '@src/common/constants/ENV';
|
|
4
|
-
import { NodeEnvs } from '@src/common/constants';
|
|
5
|
-
import { IUser } from '@src/models/User';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/******************************************************************************
|
|
9
|
-
Constants
|
|
10
|
-
******************************************************************************/
|
|
11
|
-
|
|
12
|
-
const DB_FILE_NAME = (
|
|
13
|
-
ENV.NodeEnv === NodeEnvs.Test
|
|
14
|
-
? 'database.test.json'
|
|
15
|
-
: 'database.json'
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/******************************************************************************
|
|
20
|
-
Types
|
|
21
|
-
******************************************************************************/
|
|
22
|
-
|
|
23
|
-
interface IDb {
|
|
24
|
-
users: IUser[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/******************************************************************************
|
|
29
|
-
Functions
|
|
30
|
-
******************************************************************************/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Fetch the json from the file.
|
|
34
|
-
*/
|
|
35
|
-
function openDb(): Promise<IDb> {
|
|
36
|
-
return jsonfile.readFile(__dirname + '/' + DB_FILE_NAME) as Promise<IDb>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Update the file.
|
|
41
|
-
*/
|
|
42
|
-
function saveDb(db: IDb): Promise<void> {
|
|
43
|
-
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), db);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Empty the database
|
|
48
|
-
*/
|
|
49
|
-
function cleanDb(): Promise<void> {
|
|
50
|
-
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), {});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/******************************************************************************
|
|
55
|
-
Export default
|
|
56
|
-
******************************************************************************/
|
|
57
|
-
|
|
58
|
-
export default {
|
|
59
|
-
openDb,
|
|
60
|
-
saveDb,
|
|
61
|
-
cleanDb,
|
|
62
|
-
} as const;
|
|
1
|
+
import jsonfile from 'jsonfile';
|
|
2
|
+
|
|
3
|
+
import ENV from '@src/common/constants/ENV';
|
|
4
|
+
import { NodeEnvs } from '@src/common/constants';
|
|
5
|
+
import { IUser } from '@src/models/User';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
Constants
|
|
10
|
+
******************************************************************************/
|
|
11
|
+
|
|
12
|
+
const DB_FILE_NAME = (
|
|
13
|
+
ENV.NodeEnv === NodeEnvs.Test
|
|
14
|
+
? 'database.test.json'
|
|
15
|
+
: 'database.json'
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/******************************************************************************
|
|
20
|
+
Types
|
|
21
|
+
******************************************************************************/
|
|
22
|
+
|
|
23
|
+
interface IDb {
|
|
24
|
+
users: IUser[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/******************************************************************************
|
|
29
|
+
Functions
|
|
30
|
+
******************************************************************************/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Fetch the json from the file.
|
|
34
|
+
*/
|
|
35
|
+
function openDb(): Promise<IDb> {
|
|
36
|
+
return jsonfile.readFile(__dirname + '/' + DB_FILE_NAME) as Promise<IDb>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Update the file.
|
|
41
|
+
*/
|
|
42
|
+
function saveDb(db: IDb): Promise<void> {
|
|
43
|
+
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), db);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Empty the database
|
|
48
|
+
*/
|
|
49
|
+
function cleanDb(): Promise<void> {
|
|
50
|
+
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), {});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/******************************************************************************
|
|
55
|
+
Export default
|
|
56
|
+
******************************************************************************/
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
openDb,
|
|
60
|
+
saveDb,
|
|
61
|
+
cleanDb,
|
|
62
|
+
} as const;
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"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,22 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"users": [
|
|
3
|
-
{
|
|
4
|
-
"id": 752712205078,
|
|
5
|
-
"name": "Bill",
|
|
6
|
-
"created": "2025-04-30T18:42:44.406Z",
|
|
7
|
-
"email": "sean.maxwell@gmail.com"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"id": 874707860804,
|
|
11
|
-
"name": "John Smith",
|
|
12
|
-
"created": "2025-04-30T18:42:44.406Z",
|
|
13
|
-
"email": "john.smith@gmail.com"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"id": 299903074095,
|
|
17
|
-
"name": "Gordan Freeman",
|
|
18
|
-
"created": "2025-04-30T18:42:44.406Z",
|
|
19
|
-
"email": "gordan.freeman@gmail.com"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
|
1
|
+
{"users":[{"id":497419234357,"name":"Bill","created":"2025-06-09T14:39:52.401Z","email":"sean.maxwell@gmail.com"},{"id":194170887976,"name":"John Smith","created":"2025-06-09T14:39:52.401Z","email":"john.smith@gmail.com"},{"id":893739541148,"name":"Gordan Freeman","created":"2025-06-09T14:39:52.401Z","email":"gordan.freeman@gmail.com"}]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Response, Request } from 'express';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/******************************************************************************
|
|
5
|
-
Types
|
|
6
|
-
******************************************************************************/
|
|
7
|
-
|
|
8
|
-
type TRecord = Record<string, unknown>;
|
|
9
|
-
export type IReq = Request<TRecord, void, TRecord, TRecord>;
|
|
10
|
-
export type IRes = Response<unknown, TRecord>;
|
|
11
|
-
|
|
1
|
+
import { Response, Request } from 'express';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/******************************************************************************
|
|
5
|
+
Types
|
|
6
|
+
******************************************************************************/
|
|
7
|
+
|
|
8
|
+
type TRecord = Record<string, unknown>;
|
|
9
|
+
export type IReq = Request<TRecord, void, TRecord, TRecord>;
|
|
10
|
+
export type IRes = Response<unknown, TRecord>;
|
|
11
|
+
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { parseObject, TSchema } from 'jet-validators/utils';
|
|
2
|
-
|
|
3
|
-
import { ValidationError } from '@src/common/util/route-errors';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/******************************************************************************
|
|
7
|
-
Functions
|
|
8
|
-
******************************************************************************/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Throw a "ParseObjError" when "parseObject" fails. Also extract a nested
|
|
12
|
-
* "ParseObjError" and add it to the nestedErrors array.
|
|
13
|
-
*/
|
|
14
|
-
export function parseReq<U extends TSchema>(schema: U) {
|
|
15
|
-
return parseObject(schema, errors => {
|
|
16
|
-
throw new ValidationError(errors);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
import { parseObject, TSchema } from 'jet-validators/utils';
|
|
2
|
+
|
|
3
|
+
import { ValidationError } from '@src/common/util/route-errors';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Functions
|
|
8
|
+
******************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Throw a "ParseObjError" when "parseObject" fails. Also extract a nested
|
|
12
|
+
* "ParseObjError" and add it to the nestedErrors array.
|
|
13
|
+
*/
|
|
14
|
+
export function parseReq<U extends TSchema>(schema: U) {
|
|
15
|
+
return parseObject(schema, errors => {
|
|
16
|
+
throw new ValidationError(errors);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
|
|
3
|
-
import Paths from '@src/common/constants/Paths';
|
|
4
|
-
import UserRoutes from './UserRoutes';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Setup
|
|
9
|
-
******************************************************************************/
|
|
10
|
-
|
|
11
|
-
const apiRouter = Router();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// ** Add UserRouter ** //
|
|
15
|
-
|
|
16
|
-
// Init router
|
|
17
|
-
const userRouter = Router();
|
|
18
|
-
|
|
19
|
-
// Get all users
|
|
20
|
-
userRouter.get(Paths.Users.Get, UserRoutes.getAll);
|
|
21
|
-
userRouter.post(Paths.Users.Add, UserRoutes.add);
|
|
22
|
-
userRouter.put(Paths.Users.Update, UserRoutes.update);
|
|
23
|
-
userRouter.delete(Paths.Users.Delete, UserRoutes.delete);
|
|
24
|
-
|
|
25
|
-
// Add UserRouter
|
|
26
|
-
apiRouter.use(Paths.Users.Base, userRouter);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/******************************************************************************
|
|
30
|
-
Export default
|
|
31
|
-
******************************************************************************/
|
|
32
|
-
|
|
33
|
-
export default apiRouter;
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
|
|
3
|
+
import Paths from '@src/common/constants/Paths';
|
|
4
|
+
import UserRoutes from './UserRoutes';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Setup
|
|
9
|
+
******************************************************************************/
|
|
10
|
+
|
|
11
|
+
const apiRouter = Router();
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// ** Add UserRouter ** //
|
|
15
|
+
|
|
16
|
+
// Init router
|
|
17
|
+
const userRouter = Router();
|
|
18
|
+
|
|
19
|
+
// Get all users
|
|
20
|
+
userRouter.get(Paths.Users.Get, UserRoutes.getAll);
|
|
21
|
+
userRouter.post(Paths.Users.Add, UserRoutes.add);
|
|
22
|
+
userRouter.put(Paths.Users.Update, UserRoutes.update);
|
|
23
|
+
userRouter.delete(Paths.Users.Delete, UserRoutes.delete);
|
|
24
|
+
|
|
25
|
+
// Add UserRouter
|
|
26
|
+
apiRouter.use(Paths.Users.Base, userRouter);
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/******************************************************************************
|
|
30
|
+
Export default
|
|
31
|
+
******************************************************************************/
|
|
32
|
+
|
|
33
|
+
export default apiRouter;
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { RouteError } from '@src/common/util/route-errors';
|
|
2
|
-
import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
|
|
3
|
-
|
|
4
|
-
import UserRepo from '@src/repos/UserRepo';
|
|
5
|
-
import { IUser } from '@src/models/User';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/******************************************************************************
|
|
9
|
-
Constants
|
|
10
|
-
******************************************************************************/
|
|
11
|
-
|
|
12
|
-
export const USER_NOT_FOUND_ERR = 'User not found';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/******************************************************************************
|
|
16
|
-
Functions
|
|
17
|
-
******************************************************************************/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get all users.
|
|
21
|
-
*/
|
|
22
|
-
function getAll(): Promise<IUser[]> {
|
|
23
|
-
return UserRepo.getAll();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Add one user.
|
|
28
|
-
*/
|
|
29
|
-
function addOne(user: IUser): Promise<void> {
|
|
30
|
-
return UserRepo.add(user);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Update one user.
|
|
35
|
-
*/
|
|
36
|
-
async function updateOne(user: IUser): Promise<void> {
|
|
37
|
-
const persists = await UserRepo.persists(user.id);
|
|
38
|
-
if (!persists) {
|
|
39
|
-
throw new RouteError(
|
|
40
|
-
HttpStatusCodes.NOT_FOUND,
|
|
41
|
-
USER_NOT_FOUND_ERR,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
// Return user
|
|
45
|
-
return UserRepo.update(user);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Delete a user by their id.
|
|
50
|
-
*/
|
|
51
|
-
async function _delete(id: number): Promise<void> {
|
|
52
|
-
const persists = await UserRepo.persists(id);
|
|
53
|
-
if (!persists) {
|
|
54
|
-
throw new RouteError(
|
|
55
|
-
HttpStatusCodes.NOT_FOUND,
|
|
56
|
-
USER_NOT_FOUND_ERR,
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
// Delete user
|
|
60
|
-
return UserRepo.delete(id);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/******************************************************************************
|
|
65
|
-
Export default
|
|
66
|
-
******************************************************************************/
|
|
67
|
-
|
|
68
|
-
export default {
|
|
69
|
-
getAll,
|
|
70
|
-
addOne,
|
|
71
|
-
updateOne,
|
|
72
|
-
delete: _delete,
|
|
73
|
-
} as const;
|
|
1
|
+
import { RouteError } from '@src/common/util/route-errors';
|
|
2
|
+
import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
|
|
3
|
+
|
|
4
|
+
import UserRepo from '@src/repos/UserRepo';
|
|
5
|
+
import { IUser } from '@src/models/User';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
Constants
|
|
10
|
+
******************************************************************************/
|
|
11
|
+
|
|
12
|
+
export const USER_NOT_FOUND_ERR = 'User not found';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/******************************************************************************
|
|
16
|
+
Functions
|
|
17
|
+
******************************************************************************/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get all users.
|
|
21
|
+
*/
|
|
22
|
+
function getAll(): Promise<IUser[]> {
|
|
23
|
+
return UserRepo.getAll();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Add one user.
|
|
28
|
+
*/
|
|
29
|
+
function addOne(user: IUser): Promise<void> {
|
|
30
|
+
return UserRepo.add(user);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Update one user.
|
|
35
|
+
*/
|
|
36
|
+
async function updateOne(user: IUser): Promise<void> {
|
|
37
|
+
const persists = await UserRepo.persists(user.id);
|
|
38
|
+
if (!persists) {
|
|
39
|
+
throw new RouteError(
|
|
40
|
+
HttpStatusCodes.NOT_FOUND,
|
|
41
|
+
USER_NOT_FOUND_ERR,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
// Return user
|
|
45
|
+
return UserRepo.update(user);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Delete a user by their id.
|
|
50
|
+
*/
|
|
51
|
+
async function _delete(id: number): Promise<void> {
|
|
52
|
+
const persists = await UserRepo.persists(id);
|
|
53
|
+
if (!persists) {
|
|
54
|
+
throw new RouteError(
|
|
55
|
+
HttpStatusCodes.NOT_FOUND,
|
|
56
|
+
USER_NOT_FOUND_ERR,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
// Delete user
|
|
60
|
+
return UserRepo.delete(id);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
/******************************************************************************
|
|
65
|
+
Export default
|
|
66
|
+
******************************************************************************/
|
|
67
|
+
|
|
68
|
+
export default {
|
|
69
|
+
getAll,
|
|
70
|
+
addOne,
|
|
71
|
+
updateOne,
|
|
72
|
+
delete: _delete,
|
|
73
|
+
} as const;
|