express-generator-typescript 2.7.2 → 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.
Files changed (33) hide show
  1. package/LICENSE +21 -21
  2. package/README-npm +20 -0
  3. package/README.md +85 -20
  4. package/lib/project-files/README.md +65 -65
  5. package/lib/project-files/config.ts +22 -22
  6. package/lib/project-files/eslint.config.ts +95 -95
  7. package/lib/project-files/package.json +58 -58
  8. package/lib/project-files/src/common/constants/ENV.ts +21 -21
  9. package/lib/project-files/src/common/constants/HttpStatusCodes.ts +391 -391
  10. package/lib/project-files/src/common/constants/Paths.ts +11 -11
  11. package/lib/project-files/src/common/constants/index.ts +11 -11
  12. package/lib/project-files/src/common/util/route-errors.ts +37 -37
  13. package/lib/project-files/src/common/util/validators.ts +22 -22
  14. package/lib/project-files/src/models/common/types/index.ts +5 -5
  15. package/lib/project-files/src/public/scripts/http.js +26 -26
  16. package/lib/project-files/src/public/scripts/users.js +141 -141
  17. package/lib/project-files/src/public/stylesheets/users.css +48 -48
  18. package/lib/project-files/src/repos/MockOrm.ts +62 -62
  19. package/lib/project-files/src/repos/database.json +1 -1
  20. package/lib/project-files/src/repos/database.test.json +1 -1
  21. package/lib/project-files/src/routes/common/types/index.ts +11 -11
  22. package/lib/project-files/src/routes/common/util/index.ts +18 -18
  23. package/lib/project-files/src/routes/index.ts +33 -33
  24. package/lib/project-files/src/services/UserService.ts +73 -73
  25. package/lib/project-files/src/views/users.html +132 -132
  26. package/lib/project-files/tests/common/Paths.ts +5 -5
  27. package/lib/project-files/tests/common/types/index.ts +16 -16
  28. package/lib/project-files/tests/common/util/index.ts +38 -38
  29. package/lib/project-files/tests/support/setup.ts +26 -26
  30. package/lib/project-files/tsconfig.prod.json +30 -30
  31. package/lib/project-files/vitest.config.mts +18 -18
  32. package/package.json +1 -1
  33. package/README-git +0 -95
@@ -1,11 +1,11 @@
1
-
2
- export default {
3
- Base: '/api',
4
- Users: {
5
- Base: '/users',
6
- Get: '/all',
7
- Add: '/add',
8
- Update: '/update',
9
- Delete: '/delete/:id',
10
- },
11
- } as const;
1
+
2
+ export default {
3
+ Base: '/api',
4
+ Users: {
5
+ Base: '/users',
6
+ Get: '/all',
7
+ Add: '/add',
8
+ Update: '/update',
9
+ Delete: '/delete/:id',
10
+ },
11
+ } as const;
@@ -1,11 +1,11 @@
1
-
2
- /******************************************************************************
3
- Enums
4
- ******************************************************************************/
5
-
6
- // NOTE: These need to match the names of your ".env" files
7
- export enum NodeEnvs {
8
- Dev = 'development',
9
- Test = 'test',
10
- Production = 'production'
11
- }
1
+
2
+ /******************************************************************************
3
+ Enums
4
+ ******************************************************************************/
5
+
6
+ // NOTE: These need to match the names of your ".env" files
7
+ export enum NodeEnvs {
8
+ Dev = 'development',
9
+ Test = 'test',
10
+ Production = 'production'
11
+ }
@@ -1,37 +1,37 @@
1
- import { IParseObjectError } from 'jet-validators/utils';
2
-
3
- import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
4
-
5
-
6
- /******************************************************************************
7
- Classes
8
- ******************************************************************************/
9
-
10
- /**
11
- * Error with status code and message.
12
- */
13
- export class RouteError extends Error {
14
- public status: HttpStatusCodes;
15
-
16
- public constructor(status: HttpStatusCodes, message: string) {
17
- super(message);
18
- this.status = status;
19
- }
20
- }
21
-
22
- /**
23
- * Handle "parseObj" errors.
24
- */
25
- export class ValidationError extends RouteError {
26
-
27
- public static MESSAGE = 'The parseObj() function discovered one or ' +
28
- 'more errors.';
29
-
30
- public constructor(errors: IParseObjectError[]) {
31
- const msg = JSON.stringify({
32
- message: ValidationError.MESSAGE,
33
- errors,
34
- });
35
- super(HttpStatusCodes.BAD_REQUEST, msg);
36
- }
37
- }
1
+ import { IParseObjectError } from 'jet-validators/utils';
2
+
3
+ import HttpStatusCodes from '@src/common/constants/HttpStatusCodes';
4
+
5
+
6
+ /******************************************************************************
7
+ Classes
8
+ ******************************************************************************/
9
+
10
+ /**
11
+ * Error with status code and message.
12
+ */
13
+ export class RouteError extends Error {
14
+ public status: HttpStatusCodes;
15
+
16
+ public constructor(status: HttpStatusCodes, message: string) {
17
+ super(message);
18
+ this.status = status;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Handle "parseObj" errors.
24
+ */
25
+ export class ValidationError extends RouteError {
26
+
27
+ public static MESSAGE = 'The parseObj() function discovered one or ' +
28
+ 'more errors.';
29
+
30
+ public constructor(errors: IParseObjectError[]) {
31
+ const msg = JSON.stringify({
32
+ message: ValidationError.MESSAGE,
33
+ errors,
34
+ });
35
+ super(HttpStatusCodes.BAD_REQUEST, msg);
36
+ }
37
+ }
@@ -1,22 +1,22 @@
1
- import { isNumber, isDate } from 'jet-validators';
2
- import { transform } from 'jet-validators/utils';
3
-
4
-
5
- /******************************************************************************
6
- Functions
7
- ******************************************************************************/
8
-
9
- /**
10
- * Database relational key.
11
- */
12
- export function isRelationalKey(arg: unknown): arg is number {
13
- return isNumber(arg) && arg >= -1;
14
- }
15
-
16
- /**
17
- * Convert to date object then check is a validate date.
18
- */
19
- export const transIsDate = transform(
20
- arg => new Date(arg as string),
21
- arg => isDate(arg),
22
- );
1
+ import { isNumber, isDate } from 'jet-validators';
2
+ import { transform } from 'jet-validators/utils';
3
+
4
+
5
+ /******************************************************************************
6
+ Functions
7
+ ******************************************************************************/
8
+
9
+ /**
10
+ * Database relational key.
11
+ */
12
+ export function isRelationalKey(arg: unknown): arg is number {
13
+ return isNumber(arg) && arg >= -1;
14
+ }
15
+
16
+ /**
17
+ * Convert to date object then check is a validate date.
18
+ */
19
+ export const transIsDate = transform(
20
+ arg => new Date(arg as string),
21
+ arg => isDate(arg),
22
+ );
@@ -1,5 +1,5 @@
1
-
2
- export interface IModel {
3
- id: number;
4
- created: Date;
5
- }
1
+
2
+ export interface IModel {
3
+ id: number;
4
+ created: Date;
5
+ }
@@ -1,26 +1,26 @@
1
- var Http = (() => {
2
-
3
- // Setup request for json
4
- var getOptions = (verb, data) => {
5
- var options = {
6
- dataType: 'json',
7
- method: verb,
8
- headers: {
9
- 'Accept': 'application/json',
10
- 'Content-Type': 'application/json',
11
- },
12
- };
13
- if (!!data) {
14
- options.body = JSON.stringify(data);
15
- }
16
- return options;
17
- };
18
-
19
- // Set Http methods
20
- return {
21
- get: (path) => fetch(path, getOptions('GET')),
22
- post: (path, data) => fetch(path, getOptions('POST', data)),
23
- put: (path, data) => fetch(path, getOptions('PUT', data)),
24
- delete: (path) => fetch(path, getOptions('DELETE')),
25
- };
26
- })();
1
+ var Http = (() => {
2
+
3
+ // Setup request for json
4
+ var getOptions = (verb, data) => {
5
+ var options = {
6
+ dataType: 'json',
7
+ method: verb,
8
+ headers: {
9
+ 'Accept': 'application/json',
10
+ 'Content-Type': 'application/json',
11
+ },
12
+ };
13
+ if (!!data) {
14
+ options.body = JSON.stringify(data);
15
+ }
16
+ return options;
17
+ };
18
+
19
+ // Set Http methods
20
+ return {
21
+ get: (path) => fetch(path, getOptions('GET')),
22
+ post: (path, data) => fetch(path, getOptions('POST', data)),
23
+ put: (path, data) => fetch(path, getOptions('PUT', data)),
24
+ delete: (path) => fetch(path, getOptions('DELETE')),
25
+ };
26
+ })();
@@ -1,141 +1,141 @@
1
- // @ts-nocheck
2
-
3
- /******************************************************************************
4
- Constants
5
- ******************************************************************************/
6
-
7
- const DateFormatter = new Intl.DateTimeFormat('en-US', {
8
- year: 'numeric',
9
- month: '2-digit',
10
- day: '2-digit',
11
- });
12
-
13
- const formatDate = (date) => DateFormatter.format(new Date(date));
14
-
15
-
16
- /******************************************************************************
17
- Run
18
- ******************************************************************************/
19
-
20
- // Start
21
- displayUsers();
22
-
23
-
24
- /******************************************************************************
25
- Functions
26
- ******************************************************************************/
27
-
28
- /**
29
- * Call api
30
- */
31
- function displayUsers() {
32
- Http
33
- .get('/api/users/all')
34
- .then(resp => resp.json())
35
- .then(resp => {
36
- var allUsersTemplate = document.getElementById('all-users-template'),
37
- allUsersTemplateHtml = allUsersTemplate.innerHTML,
38
- template = Handlebars.compile(allUsersTemplateHtml);
39
- var allUsersAnchor = document.getElementById('all-users-anchor');
40
- allUsersAnchor.innerHTML = template({
41
- users: resp.users.map(user => ({
42
- ...user,
43
- createdFormatted: formatDate(user.created),
44
- })),
45
- });
46
- });
47
- }
48
-
49
- // Setup event listener for button click
50
- document.addEventListener('click', event => {
51
- event.preventDefault();
52
- var ele = event.target;
53
- if (ele.matches('#add-user-btn')) {
54
- addUser();
55
- } else if (ele.matches('.edit-user-btn')) {
56
- showEditView(ele.parentNode.parentNode);
57
- } else if (ele.matches('.cancel-edit-btn')) {
58
- cancelEdit(ele.parentNode.parentNode);
59
- } else if (ele.matches('.submit-edit-btn')) {
60
- submitEdit(ele);
61
- } else if (ele.matches('.delete-user-btn')) {
62
- deleteUser(ele);
63
- }
64
- }, false);
65
-
66
- /**
67
- * Add a new user.
68
- */
69
- function addUser() {
70
- var nameInput = document.getElementById('name-input');
71
- var emailInput = document.getElementById('email-input');
72
- var data = {
73
- user: {
74
- id: -1,
75
- name: nameInput.value,
76
- email: emailInput.value,
77
- created: new Date(),
78
- },
79
- };
80
- // Call api
81
- Http
82
- .post('/api/users/add', data)
83
- .then(() => {
84
- nameInput.value = '';
85
- emailInput.value = '';
86
- displayUsers();
87
- });
88
- }
89
-
90
- /**
91
- * Show edit view.
92
- */
93
- function showEditView(userEle) {
94
- var normalView = userEle.getElementsByClassName('normal-view')[0];
95
- var editView = userEle.getElementsByClassName('edit-view')[0];
96
- normalView.style.display = 'none';
97
- editView.style.display = 'block';
98
- }
99
-
100
- /**
101
- * Cancel edit.
102
- */
103
- function cancelEdit(userEle) {
104
- var normalView = userEle.getElementsByClassName('normal-view')[0];
105
- var editView = userEle.getElementsByClassName('edit-view')[0];
106
- normalView.style.display = 'block';
107
- editView.style.display = 'none';
108
- }
109
-
110
- /**
111
- * Submit edit.
112
- */
113
- function submitEdit(ele) {
114
- var userEle = ele.parentNode.parentNode;
115
- var nameInput = userEle.getElementsByClassName('name-edit-input')[0];
116
- var emailInput = userEle.getElementsByClassName('email-edit-input')[0];
117
- var id = ele.getAttribute('data-user-id');
118
- var created = ele.getAttribute('data-user-created');
119
- console.log(ele, created)
120
- var data = {
121
- user: {
122
- id: Number(id),
123
- name: nameInput.value,
124
- email: emailInput.value,
125
- created: new Date(created),
126
- },
127
- };
128
- Http
129
- .put('/api/users/update', data)
130
- .then(() => displayUsers());
131
- }
132
-
133
- /**
134
- * Delete a user
135
- */
136
- function deleteUser(ele) {
137
- var id = ele.getAttribute('data-user-id');
138
- Http
139
- .delete('/api/users/delete/' + id)
140
- .then(() => displayUsers());
141
- }
1
+ // @ts-nocheck
2
+
3
+ /******************************************************************************
4
+ Constants
5
+ ******************************************************************************/
6
+
7
+ const DateFormatter = new Intl.DateTimeFormat('en-US', {
8
+ year: 'numeric',
9
+ month: '2-digit',
10
+ day: '2-digit',
11
+ });
12
+
13
+ const formatDate = (date) => DateFormatter.format(new Date(date));
14
+
15
+
16
+ /******************************************************************************
17
+ Run
18
+ ******************************************************************************/
19
+
20
+ // Start
21
+ displayUsers();
22
+
23
+
24
+ /******************************************************************************
25
+ Functions
26
+ ******************************************************************************/
27
+
28
+ /**
29
+ * Call api
30
+ */
31
+ function displayUsers() {
32
+ Http
33
+ .get('/api/users/all')
34
+ .then(resp => resp.json())
35
+ .then(resp => {
36
+ var allUsersTemplate = document.getElementById('all-users-template'),
37
+ allUsersTemplateHtml = allUsersTemplate.innerHTML,
38
+ template = Handlebars.compile(allUsersTemplateHtml);
39
+ var allUsersAnchor = document.getElementById('all-users-anchor');
40
+ allUsersAnchor.innerHTML = template({
41
+ users: resp.users.map(user => ({
42
+ ...user,
43
+ createdFormatted: formatDate(user.created),
44
+ })),
45
+ });
46
+ });
47
+ }
48
+
49
+ // Setup event listener for button click
50
+ document.addEventListener('click', event => {
51
+ event.preventDefault();
52
+ var ele = event.target;
53
+ if (ele.matches('#add-user-btn')) {
54
+ addUser();
55
+ } else if (ele.matches('.edit-user-btn')) {
56
+ showEditView(ele.parentNode.parentNode);
57
+ } else if (ele.matches('.cancel-edit-btn')) {
58
+ cancelEdit(ele.parentNode.parentNode);
59
+ } else if (ele.matches('.submit-edit-btn')) {
60
+ submitEdit(ele);
61
+ } else if (ele.matches('.delete-user-btn')) {
62
+ deleteUser(ele);
63
+ }
64
+ }, false);
65
+
66
+ /**
67
+ * Add a new user.
68
+ */
69
+ function addUser() {
70
+ var nameInput = document.getElementById('name-input');
71
+ var emailInput = document.getElementById('email-input');
72
+ var data = {
73
+ user: {
74
+ id: -1,
75
+ name: nameInput.value,
76
+ email: emailInput.value,
77
+ created: new Date(),
78
+ },
79
+ };
80
+ // Call api
81
+ Http
82
+ .post('/api/users/add', data)
83
+ .then(() => {
84
+ nameInput.value = '';
85
+ emailInput.value = '';
86
+ displayUsers();
87
+ });
88
+ }
89
+
90
+ /**
91
+ * Show edit view.
92
+ */
93
+ function showEditView(userEle) {
94
+ var normalView = userEle.getElementsByClassName('normal-view')[0];
95
+ var editView = userEle.getElementsByClassName('edit-view')[0];
96
+ normalView.style.display = 'none';
97
+ editView.style.display = 'block';
98
+ }
99
+
100
+ /**
101
+ * Cancel edit.
102
+ */
103
+ function cancelEdit(userEle) {
104
+ var normalView = userEle.getElementsByClassName('normal-view')[0];
105
+ var editView = userEle.getElementsByClassName('edit-view')[0];
106
+ normalView.style.display = 'block';
107
+ editView.style.display = 'none';
108
+ }
109
+
110
+ /**
111
+ * Submit edit.
112
+ */
113
+ function submitEdit(ele) {
114
+ var userEle = ele.parentNode.parentNode;
115
+ var nameInput = userEle.getElementsByClassName('name-edit-input')[0];
116
+ var emailInput = userEle.getElementsByClassName('email-edit-input')[0];
117
+ var id = ele.getAttribute('data-user-id');
118
+ var created = ele.getAttribute('data-user-created');
119
+ console.log(ele, created)
120
+ var data = {
121
+ user: {
122
+ id: Number(id),
123
+ name: nameInput.value,
124
+ email: emailInput.value,
125
+ created: new Date(created),
126
+ },
127
+ };
128
+ Http
129
+ .put('/api/users/update', data)
130
+ .then(() => displayUsers());
131
+ }
132
+
133
+ /**
134
+ * Delete a user
135
+ */
136
+ function deleteUser(ele) {
137
+ var id = ele.getAttribute('data-user-id');
138
+ Http
139
+ .delete('/api/users/delete/' + id)
140
+ .then(() => displayUsers());
141
+ }
@@ -1,48 +1,48 @@
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: 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
+ }