express-generator-typescript 2.7.10 → 2.7.12
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/lib/express-generator-typescript.js +44 -11
- package/lib/project-files/.prettierignore +12 -0
- package/lib/project-files/.prettierrc.json +15 -0
- package/lib/project-files/README.md +58 -65
- package/lib/project-files/config/.env.development +3 -3
- package/lib/project-files/config/.env.production +3 -3
- package/lib/project-files/config/.env.test +3 -3
- package/lib/project-files/config.ts +20 -22
- package/lib/project-files/eslint.config.ts +46 -100
- package/lib/project-files/package.json +59 -56
- package/lib/project-files/scripts/build.ts +23 -28
- package/lib/project-files/scripts/common/utils.ts +11 -11
- package/lib/project-files/src/common/constants/HttpStatusCodes.ts +393 -0
- package/lib/project-files/src/common/constants/{PATHS.ts → Paths.ts} +15 -15
- package/lib/project-files/src/common/constants/{ENV.ts → env.ts} +28 -19
- package/lib/project-files/src/common/{util/misc.ts → utils/number-utils.ts} +10 -11
- package/lib/project-files/src/common/{util → utils}/route-errors.ts +35 -38
- package/lib/project-files/src/common/{util → utils}/validators.ts +14 -14
- package/lib/project-files/src/{index.ts → main.ts} +24 -27
- package/lib/project-files/src/models/User.ts +69 -70
- package/lib/project-files/src/models/common/{types.ts → IModel.ts} +4 -5
- package/lib/project-files/src/public/stylesheets/users.css +50 -48
- package/lib/project-files/src/repos/MockOrm.ts +57 -63
- package/lib/project-files/src/repos/UserRepo.ts +133 -133
- package/lib/project-files/src/repos/common/database.test.json +22 -0
- package/lib/project-files/src/routes/UserRoutes.ts +77 -69
- package/lib/project-files/src/routes/{index.ts → apiRouter.ts} +28 -31
- package/lib/project-files/src/routes/common/express-types.ts +9 -0
- package/lib/project-files/src/routes/common/{util/index.ts → parseReq.ts} +19 -16
- package/lib/project-files/src/server.ts +79 -86
- package/lib/project-files/src/services/UserService.ts +64 -70
- package/lib/project-files/src/views/users.html +118 -132
- package/lib/project-files/tests/common/{utils.ts → comparators.ts} +38 -55
- package/lib/project-files/tests/common/error-utils.ts +25 -0
- package/lib/project-files/tests/common/{types.ts → supertest-types.ts} +15 -16
- package/lib/project-files/tests/{aux/setup.ts → support/agent.ts} +23 -26
- package/lib/project-files/tests/users.test.ts +131 -123
- package/lib/project-files/tsconfig.json +30 -35
- package/lib/project-files/tsconfig.prod.json +27 -30
- package/lib/project-files/vitest.config.mts +18 -18
- package/package.json +1 -1
- package/lib/project-files/src/common/constants/HTTP_STATUS_CODES.ts +0 -81
- package/lib/project-files/src/common/constants/index.ts +0 -11
- package/lib/project-files/src/repos/database.test.json +0 -1
- package/lib/project-files/src/routes/common/types/index.ts +0 -10
- /package/lib/project-files/src/repos/{database.json → common/database.json} +0 -0
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import logger from 'jet-logger';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import server from './server';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
logger.info(SERVER_START_MSG);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
1
|
+
import logger from 'jet-logger';
|
|
2
|
+
|
|
3
|
+
import EnvVars from './common/constants/env';
|
|
4
|
+
import server from './server';
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Constants
|
|
8
|
+
******************************************************************************/
|
|
9
|
+
|
|
10
|
+
const SERVER_START_MSG =
|
|
11
|
+
'Express server started on port: ' + EnvVars.Port.toString();
|
|
12
|
+
|
|
13
|
+
/******************************************************************************
|
|
14
|
+
Run
|
|
15
|
+
******************************************************************************/
|
|
16
|
+
|
|
17
|
+
// Start the server
|
|
18
|
+
server.listen(EnvVars.Port, (err) => {
|
|
19
|
+
if (!!err) {
|
|
20
|
+
logger.err(err.message);
|
|
21
|
+
} else {
|
|
22
|
+
logger.info(SERVER_START_MSG);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
import { isString, isUnsignedInteger } from 'jet-validators';
|
|
2
|
-
import { parseObject,
|
|
3
|
-
|
|
4
|
-
import { transformIsDate } from '@src/common/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
email: '',
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
id: isUnsignedInteger,
|
|
34
|
-
name: isString,
|
|
35
|
-
email: isString,
|
|
36
|
-
created: transformIsDate,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
} as const;
|
|
1
|
+
import { isNonEmptyString, isString, isUnsignedInteger } from 'jet-validators';
|
|
2
|
+
import { parseObject, Schema, testObject } from 'jet-validators/utils';
|
|
3
|
+
|
|
4
|
+
import { transformIsDate } from '@src/common/utils/validators';
|
|
5
|
+
|
|
6
|
+
import { IModel } from './common/IModel';
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
Constants
|
|
10
|
+
******************************************************************************/
|
|
11
|
+
|
|
12
|
+
const GetDefaults = (): IUser => ({
|
|
13
|
+
id: 0,
|
|
14
|
+
name: '',
|
|
15
|
+
email: '',
|
|
16
|
+
created: new Date(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/******************************************************************************
|
|
20
|
+
Types
|
|
21
|
+
******************************************************************************/
|
|
22
|
+
|
|
23
|
+
export interface IUser extends IModel {
|
|
24
|
+
name: string;
|
|
25
|
+
email: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/******************************************************************************
|
|
29
|
+
Setup
|
|
30
|
+
******************************************************************************/
|
|
31
|
+
|
|
32
|
+
const schema: Schema<IUser> = {
|
|
33
|
+
id: isUnsignedInteger,
|
|
34
|
+
name: isString,
|
|
35
|
+
email: isString,
|
|
36
|
+
created: transformIsDate,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Set the "parseUser" function
|
|
40
|
+
const parseUser = parseObject<IUser>(schema);
|
|
41
|
+
|
|
42
|
+
// For the APIs make sure the right fields are complete
|
|
43
|
+
const testIsCompleteUser = testObject<IUser>({
|
|
44
|
+
...schema,
|
|
45
|
+
name: isNonEmptyString,
|
|
46
|
+
email: isNonEmptyString,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/******************************************************************************
|
|
50
|
+
Functions
|
|
51
|
+
******************************************************************************/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* New user object.
|
|
55
|
+
*/
|
|
56
|
+
function __new__(user?: Partial<IUser>): IUser {
|
|
57
|
+
return parseUser({ ...GetDefaults(), ...user }, (errors) => {
|
|
58
|
+
throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/******************************************************************************
|
|
63
|
+
Export default
|
|
64
|
+
******************************************************************************/
|
|
65
|
+
|
|
66
|
+
export default {
|
|
67
|
+
new: __new__,
|
|
68
|
+
isComplete: testIsCompleteUser,
|
|
69
|
+
} as const;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
export interface IModel {
|
|
2
|
+
id: number;
|
|
3
|
+
created: Date;
|
|
4
|
+
}
|
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
body {
|
|
2
|
-
padding: 100px;
|
|
3
|
-
font:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
body {
|
|
2
|
+
padding: 100px;
|
|
3
|
+
font:
|
|
4
|
+
14px 'Lucida Grande',
|
|
5
|
+
Helvetica,
|
|
6
|
+
Arial,
|
|
7
|
+
sans-serif;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
body .users-column {
|
|
11
|
+
display: inline-block;
|
|
12
|
+
margin-right: 2em;
|
|
13
|
+
vertical-align: top;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
body .users-column .column-header {
|
|
17
|
+
padding-bottom: 5px;
|
|
18
|
+
font-weight: 700;
|
|
19
|
+
font-size: 1.2em;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Add User Column **/
|
|
23
|
+
|
|
24
|
+
body .add-user-col input {
|
|
25
|
+
margin-bottom: 10px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
body .add-user-col #add-user-btn {
|
|
29
|
+
margin-top: 2px;
|
|
30
|
+
margin-bottom: 10px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Users Display Column **/
|
|
34
|
+
|
|
35
|
+
.email-edit {
|
|
36
|
+
padding-bottom: 8px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
body .users-column .user-display-ele {
|
|
40
|
+
padding-bottom: 10px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
body .users-column .user-display-ele button {
|
|
44
|
+
margin-top: 2px;
|
|
45
|
+
margin-bottom: 10px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
body .users-column .user-display-ele .edit-view {
|
|
49
|
+
display: none;
|
|
50
|
+
}
|
|
@@ -1,63 +1,57 @@
|
|
|
1
|
-
import jsonfile from 'jsonfile';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export default {
|
|
60
|
-
openDb,
|
|
61
|
-
saveDb,
|
|
62
|
-
cleanDb,
|
|
63
|
-
} as const;
|
|
1
|
+
import jsonfile from 'jsonfile';
|
|
2
|
+
|
|
3
|
+
import EnvVars, { NodeEnvs } from '@src/common/constants/env';
|
|
4
|
+
import { IUser } from '@src/models/User';
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Constants
|
|
8
|
+
******************************************************************************/
|
|
9
|
+
|
|
10
|
+
const DATABASE_FILE_PATH = __dirname + '/common' + (
|
|
11
|
+
EnvVars.NodeEnv === NodeEnvs.TEST
|
|
12
|
+
? '/database.test.json'
|
|
13
|
+
: '/database.json'
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
/******************************************************************************
|
|
17
|
+
Types
|
|
18
|
+
******************************************************************************/
|
|
19
|
+
|
|
20
|
+
interface IDatabase {
|
|
21
|
+
users: IUser[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/******************************************************************************
|
|
25
|
+
Functions
|
|
26
|
+
******************************************************************************/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Fetch the json from the file.
|
|
30
|
+
*/
|
|
31
|
+
function openDb(): Promise<IDatabase> {
|
|
32
|
+
return jsonfile.readFile(DATABASE_FILE_PATH) as Promise<IDatabase>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Update the file.
|
|
37
|
+
*/
|
|
38
|
+
function saveDb(db: IDatabase): Promise<void> {
|
|
39
|
+
return jsonfile.writeFile(DATABASE_FILE_PATH, db);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Empty the database
|
|
44
|
+
*/
|
|
45
|
+
function cleanDb(): Promise<void> {
|
|
46
|
+
return jsonfile.writeFile( DATABASE_FILE_PATH, {});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/******************************************************************************
|
|
50
|
+
Export default
|
|
51
|
+
******************************************************************************/
|
|
52
|
+
|
|
53
|
+
export default {
|
|
54
|
+
openDb,
|
|
55
|
+
saveDb,
|
|
56
|
+
cleanDb,
|
|
57
|
+
} as const;
|