express-generator-typescript 2.7.11 → 2.7.14

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 (50) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/lib/cli.js +0 -0
  4. package/lib/express-generator-typescript.js +44 -11
  5. package/lib/project-files/.prettierignore +12 -0
  6. package/lib/project-files/.prettierrc.json +15 -0
  7. package/lib/project-files/README.md +54 -65
  8. package/lib/project-files/config/.env.development +0 -0
  9. package/lib/project-files/config/.env.production +0 -0
  10. package/lib/project-files/config/.env.test +0 -0
  11. package/lib/project-files/eslint.config.ts +46 -100
  12. package/lib/project-files/gitignore +0 -2
  13. package/lib/project-files/package.json +62 -56
  14. package/lib/project-files/src/common/constants/HttpStatusCodes.ts +393 -394
  15. package/lib/project-files/src/common/constants/Paths.ts +15 -15
  16. package/lib/project-files/src/common/constants/{EnvVars.ts → env.ts} +28 -19
  17. package/lib/project-files/src/common/utils/{misc.ts → number-utils.ts} +10 -11
  18. package/lib/project-files/src/common/utils/route-errors.ts +35 -36
  19. package/lib/project-files/src/common/utils/validators.ts +14 -14
  20. package/lib/project-files/src/{index.ts → main.ts} +24 -27
  21. package/lib/project-files/src/models/User.ts +73 -72
  22. package/lib/project-files/src/models/common/IModel.ts +4 -0
  23. package/lib/project-files/src/public/stylesheets/users.css +50 -48
  24. package/lib/project-files/src/repos/MockOrm.ts +57 -63
  25. package/lib/project-files/src/repos/UserRepo.ts +131 -133
  26. package/lib/project-files/src/repos/{database.json → common/database.json} +0 -0
  27. package/lib/project-files/src/repos/common/database.test.json +1 -0
  28. package/lib/project-files/src/routes/UserRoutes.ts +77 -69
  29. package/lib/project-files/src/routes/{index.ts → apiRouter.ts} +28 -28
  30. package/lib/project-files/src/routes/common/{types.ts → express-types.ts} +9 -10
  31. package/lib/project-files/src/routes/common/{utils.ts → parseReq.ts} +19 -16
  32. package/lib/project-files/src/server.ts +79 -84
  33. package/lib/project-files/src/services/{UserService/index.ts → UserService.ts} +64 -58
  34. package/lib/project-files/src/views/users.html +118 -132
  35. package/lib/project-files/tests/common/{utils.ts → comparators.ts} +38 -55
  36. package/lib/project-files/tests/common/error-utils.ts +25 -0
  37. package/lib/project-files/tests/common/{types.ts → supertest-types.ts} +15 -16
  38. package/lib/project-files/tests/{aux/setup.ts → support/agent.ts} +23 -26
  39. package/lib/project-files/tests/users.test.ts +131 -123
  40. package/lib/project-files/tsconfig.json +29 -35
  41. package/lib/project-files/tsconfig.prod.json +27 -30
  42. package/lib/project-files/vitest.config.mts +21 -18
  43. package/package.json +1 -1
  44. package/lib/project-files/config.ts +0 -22
  45. package/lib/project-files/scripts/build.ts +0 -28
  46. package/lib/project-files/scripts/common/utils.ts +0 -93
  47. package/lib/project-files/src/common/constants/index.ts +0 -11
  48. package/lib/project-files/src/models/common/types.ts +0 -5
  49. package/lib/project-files/src/repos/database.test.json +0 -1
  50. package/lib/project-files/src/services/UserService/constants.ts +0 -5
@@ -1,15 +1,15 @@
1
- import jetPaths from 'jet-paths';
2
-
3
- const Paths = {
4
- _: '/api',
5
- Users: {
6
- _: '/users',
7
- Get: '/all',
8
- Add: '/add',
9
- Update: '/update',
10
- Delete: '/delete/:id',
11
- },
12
- } as const;
13
-
14
- export const JetPaths = jetPaths(Paths);
15
- export default Paths;
1
+ import jetPaths from 'jet-paths';
2
+
3
+ const Paths = {
4
+ _: '/api',
5
+ Users: {
6
+ _: '/users',
7
+ Get: '/all',
8
+ Add: '/add',
9
+ Update: '/update',
10
+ Delete: '/delete/:id',
11
+ },
12
+ } as const;
13
+
14
+ export const JetPaths = jetPaths(Paths);
15
+ export default Paths;
@@ -1,19 +1,28 @@
1
- import jetEnv, { num } from 'jet-env';
2
- import { isValueOf } from 'jet-validators';
3
-
4
- import { NodeEnvs } from '.';
5
-
6
- /******************************************************************************
7
- Setup
8
- ******************************************************************************/
9
-
10
- const EnvVars = jetEnv({
11
- NodeEnv: isValueOf(NodeEnvs),
12
- Port: num,
13
- });
14
-
15
- /******************************************************************************
16
- Export default
17
- ******************************************************************************/
18
-
19
- export default EnvVars;
1
+ import jetEnv, { num } from 'jet-env';
2
+ import { isValueOf } from 'jet-validators';
3
+
4
+ /******************************************************************************
5
+ Constants
6
+ ******************************************************************************/
7
+
8
+ // NOTE: These need to match the names of your ".env" files
9
+ export const NodeEnvs = {
10
+ DEV: 'development',
11
+ TEST: 'test',
12
+ PRODUCTION: 'production',
13
+ } as const;
14
+
15
+ /******************************************************************************
16
+ Setup
17
+ ******************************************************************************/
18
+
19
+ const EnvVars = jetEnv({
20
+ NodeEnv: isValueOf(NodeEnvs),
21
+ Port: num,
22
+ });
23
+
24
+ /******************************************************************************
25
+ Export default
26
+ ******************************************************************************/
27
+
28
+ export default EnvVars;
@@ -1,11 +1,10 @@
1
-
2
- /******************************************************************************
3
- Functions
4
- ******************************************************************************/
5
-
6
- /**
7
- * Get a random number between 1 and 1,000,000,000,000
8
- */
9
- export function getRandomInt(): number {
10
- return Math.floor(Math.random() * 1_000_000_000_000);
11
- }
1
+ /******************************************************************************
2
+ Functions
3
+ ******************************************************************************/
4
+
5
+ /**
6
+ * Get a random number between 1 and 1,000,000,000,000
7
+ */
8
+ export function getRandomInt(): number {
9
+ return Math.floor(Math.random() * 1_000_000_000_000);
10
+ }
@@ -1,36 +1,35 @@
1
- import { ParseError } from 'jet-validators/utils';
2
-
3
- import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
4
-
5
- /******************************************************************************
6
- Classes
7
- ******************************************************************************/
8
-
9
- /**
10
- * Error with status code and message.
11
- */
12
- export class RouteError extends Error {
13
- public status: HttpStatusCodes;
14
-
15
- public constructor(status: HttpStatusCodes, message: string) {
16
- super(message);
17
- this.status = status;
18
- }
19
- }
20
-
21
- /**
22
- * Handle "parseObj" errors.
23
- */
24
- export class ValidationError extends RouteError {
25
-
26
- public static MESSAGE = 'The parseObj() function discovered one or ' +
27
- 'more errors.';
28
-
29
- public constructor(errors: ParseError[]) {
30
- const msg = JSON.stringify({
31
- message: ValidationError.MESSAGE,
32
- errors,
33
- });
34
- super(HttpStatusCodes.BAD_REQUEST, msg);
35
- }
36
- }
1
+ import { ParseError } from 'jet-validators/utils';
2
+
3
+ import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
4
+
5
+ /******************************************************************************
6
+ Classes
7
+ ******************************************************************************/
8
+
9
+ /**
10
+ * Error with status code and message.
11
+ */
12
+ export class RouteError extends Error {
13
+ public status: HttpStatusCodes;
14
+
15
+ public constructor(status: HttpStatusCodes, message: string) {
16
+ super(message);
17
+ this.status = status;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Handle "parseObj" errors.
23
+ */
24
+ export class ValidationError extends RouteError {
25
+ public static MESSAGE =
26
+ 'The parseObj() function discovered one or ' + 'more errors.';
27
+
28
+ public constructor(errors: ParseError[]) {
29
+ const msg = JSON.stringify({
30
+ message: ValidationError.MESSAGE,
31
+ errors,
32
+ });
33
+ super(HttpStatusCodes.BAD_REQUEST, msg);
34
+ }
35
+ }
@@ -1,14 +1,14 @@
1
- import { isDate } from 'jet-validators';
2
- import { transform } from 'jet-validators/utils';
3
-
4
- /******************************************************************************
5
- Functions
6
- ******************************************************************************/
7
-
8
- /**
9
- * Convert to date object then check is a validate date.
10
- */
11
- export const transformIsDate = transform(
12
- arg => new Date(arg as string),
13
- arg => isDate(arg),
14
- );
1
+ import { isDate } from 'jet-validators';
2
+ import { transform } from 'jet-validators/utils';
3
+
4
+ /******************************************************************************
5
+ Functions
6
+ ******************************************************************************/
7
+
8
+ /**
9
+ * Convert to date object then check is a validate date.
10
+ */
11
+ export const transformIsDate = transform(
12
+ (arg) => new Date(arg as string),
13
+ (arg) => isDate(arg),
14
+ );
@@ -1,27 +1,24 @@
1
- import logger from 'jet-logger';
2
-
3
- import EnvVars from '@src/common/constants/EnvVars';
4
- import server from './server';
5
-
6
-
7
- /******************************************************************************
8
- Constants
9
- ******************************************************************************/
10
-
11
- const SERVER_START_MSG = (
12
- 'Express server started on port: ' + EnvVars.Port.toString()
13
- );
14
-
15
-
16
- /******************************************************************************
17
- Run
18
- ******************************************************************************/
19
-
20
- // Start the server
21
- server.listen(EnvVars.Port, err => {
22
- if (!!err) {
23
- logger.err(err.message);
24
- } else {
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,72 +1,73 @@
1
- import { isNonEmptyString, isString, isUnsignedInteger } from 'jet-validators';
2
- import {
3
- parseObject,
4
- Schema,
5
- testObject,
6
- } from 'jet-validators/utils';
7
-
8
- import { transformIsDate } from '@src/common/utils/validators';
9
- import { IModel } from './common/types';
10
-
11
- /******************************************************************************
12
- Constants
13
- ******************************************************************************/
14
-
15
- const GetDefaults = (): IUser => ({
16
- id: 0,
17
- name: '',
18
- email: '',
19
- created: new Date(),
20
- });
21
-
22
- /******************************************************************************
23
- Types
24
- ******************************************************************************/
25
-
26
- export interface IUser extends IModel {
27
- name: string;
28
- email: string;
29
- }
30
-
31
- /******************************************************************************
32
- Setup
33
- ******************************************************************************/
34
-
35
- const schema: Schema<IUser> = {
36
- id: isUnsignedInteger,
37
- name: isString,
38
- email: isString,
39
- created: transformIsDate,
40
- };
41
-
42
- // Set the "parseUser" function
43
- const parseUser = parseObject<IUser>(schema);
44
-
45
- // For the APIs make sure the right fields are complete
46
- const testIsCompleteUser = testObject<IUser>({
47
- ...schema,
48
- name: isNonEmptyString,
49
- email: isNonEmptyString,
50
- });
51
-
52
- /******************************************************************************
53
- Functions
54
- ******************************************************************************/
55
-
56
- /**
57
- * New user object.
58
- */
59
- function __new__(user?: Partial<IUser>): IUser {
60
- return parseUser({ ...GetDefaults(), ...user }, errors => {
61
- throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
62
- });
63
- }
64
-
65
- /******************************************************************************
66
- Export default
67
- ******************************************************************************/
68
-
69
- export default {
70
- new: __new__,
71
- isComplete: testIsCompleteUser,
72
- } 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
+ const schema: Schema<IUser> = {
20
+ id: isUnsignedInteger,
21
+ name: isString,
22
+ email: isString,
23
+ created: transformIsDate,
24
+ };
25
+
26
+ /******************************************************************************
27
+ Types
28
+ ******************************************************************************/
29
+
30
+ /**
31
+ * @entity users
32
+ */
33
+ export interface IUser extends IModel {
34
+ name: string;
35
+ email: string;
36
+ }
37
+
38
+ /******************************************************************************
39
+ Setup
40
+ ******************************************************************************/
41
+
42
+
43
+ // Set the "parseUser" function
44
+ const parseUser = parseObject<IUser>(schema);
45
+
46
+ // For the APIs make sure the right fields are complete
47
+ const testIsCompleteUser = testObject<IUser>({
48
+ ...schema,
49
+ name: isNonEmptyString,
50
+ email: isNonEmptyString,
51
+ });
52
+
53
+ /******************************************************************************
54
+ Functions
55
+ ******************************************************************************/
56
+
57
+ /**
58
+ * New user object.
59
+ */
60
+ function __new__(user?: Partial<IUser>): IUser {
61
+ return parseUser({ ...GetDefaults(), ...user }, (errors) => {
62
+ throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
63
+ });
64
+ }
65
+
66
+ /******************************************************************************
67
+ Export default
68
+ ******************************************************************************/
69
+
70
+ export default {
71
+ new: __new__,
72
+ isComplete: testIsCompleteUser,
73
+ } as const;
@@ -0,0 +1,4 @@
1
+ export interface IModel {
2
+ id: number; // @PK
3
+ created: Date | string; // @audit
4
+ }
@@ -1,48 +1,50 @@
1
- body {
2
- padding: 100px;
3
- font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4
- }
5
-
6
- body .users-column {
7
- display: inline-block;
8
- margin-right: 2em;
9
- vertical-align: top;
10
- }
11
-
12
- body .users-column .column-header {
13
- padding-bottom: 5px;
14
- font-weight: 700;
15
- font-size: 1.2em;
16
- }
17
-
18
-
19
- /** Add User Column **/
20
-
21
- body .add-user-col input {
22
- margin-bottom: 10px;
23
- }
24
-
25
- body .add-user-col #add-user-btn {
26
- margin-top: 2px;
27
- margin-bottom: 10px;
28
- }
29
-
30
-
31
- /** Users Display Column **/
32
-
33
- .email-edit {
34
- padding-bottom: 8px;
35
- }
36
-
37
- body .users-column .user-display-ele {
38
- padding-bottom: 10px;
39
- }
40
-
41
- body .users-column .user-display-ele button {
42
- margin-top: 2px;
43
- margin-bottom: 10px;
44
- }
45
-
46
- body .users-column .user-display-ele .edit-view {
47
- display: none;
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 EnvVars from '@src/common/constants/EnvVars';
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
- EnvVars.NodeEnv === NodeEnvs.TEST
14
- ? 'database.test.json'
15
- : 'database.json'
16
- );
17
-
18
-
19
- /******************************************************************************
20
- Types
21
- ******************************************************************************/
22
-
23
- interface IDatabase {
24
- users: IUser[];
25
- }
26
-
27
-
28
- /******************************************************************************
29
- Functions
30
- ******************************************************************************/
31
-
32
- /**
33
- * Fetch the json from the file.
34
- */
35
- function openDb(): Promise<IDatabase> {
36
- return jsonfile.readFile(__dirname + '/' + DB_FILE_NAME) as
37
- Promise<IDatabase>;
38
- }
39
-
40
- /**
41
- * Update the file.
42
- */
43
- function saveDb(db: IDatabase): Promise<void> {
44
- return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), db);
45
- }
46
-
47
- /**
48
- * Empty the database
49
- */
50
- function cleanDb(): Promise<void> {
51
- return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), {});
52
- }
53
-
54
-
55
- /******************************************************************************
56
- Export default
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;