express-generator-typescript 2.9.1 → 3.0.2
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/README.md +46 -40
- package/lib/template/README.md +33 -15
- package/lib/template/package.json +11 -21
- package/lib/template/src/common/{utils → classes}/route-errors.ts +1 -1
- package/lib/template/src/common/constants/HttpStatusCodes.ts +1 -1
- package/lib/template/src/common/constants/env-inv.ts +2 -1
- package/lib/template/src/common/utils/dev-only.ts +25 -0
- package/lib/template/src/entities/User/_internal/validators.ts +47 -0
- package/lib/template/src/entities/User/index.ts +2 -0
- package/lib/template/src/entities/User/module.ts +63 -0
- package/lib/template/src/entities/User/types.ts +18 -0
- package/lib/template/src/{models → entities}/common/types.ts +1 -1
- package/lib/template/src/public/scripts/HttpClient.js +59 -0
- package/lib/template/src/public/scripts/renderUsers.js +43 -5
- package/lib/template/src/public/scripts/users.js +75 -14
- package/lib/template/src/repos/MockOrm.ts +3 -3
- package/lib/template/src/repos/UserRepo.ts +6 -6
- package/lib/template/src/repos/common/database.json +2 -2
- package/lib/template/src/routes/UserRoutes.ts +2 -2
- package/lib/template/src/routes/common/express-types.ts +1 -1
- package/lib/template/src/routes/common/parseReq.ts +2 -2
- package/lib/template/src/server.ts +16 -4
- package/lib/template/src/services/UserService.ts +6 -6
- package/lib/template/src/views/users.html +1 -1
- package/lib/template/tests/common/comparators.ts +3 -3
- package/lib/template/tests/common/supertest-types.ts +2 -2
- package/lib/template/tests/frontend.test.ts +1 -1
- package/lib/template/tests/support/agent.ts +2 -2
- package/lib/template/tests/users.test.ts +11 -11
- package/lib/template/tsconfig.json +9 -10
- package/lib/template/tsconfig.prod.json +13 -4
- package/lib/template/{vitest.config.mts → vitest.config.ts} +6 -4
- package/package.json +1 -1
- package/lib/template/bs-config.js +0 -8
- package/lib/template/src/models/User.model.ts +0 -95
- package/lib/template/src/public/scripts/http.js +0 -25
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import jetid from 'jet-id';
|
|
2
|
-
import { isNonEmptyString, isString } from 'jet-validators';
|
|
3
|
-
import { parseObject, Schema, testObject } from 'jet-validators/utils';
|
|
4
|
-
|
|
5
|
-
import { getISOString, isISOString } from '@src/common/utils/date-utils';
|
|
6
|
-
|
|
7
|
-
import { Entity } from './common/types';
|
|
8
|
-
|
|
9
|
-
// ========================================================================= //
|
|
10
|
-
// CONSTANTS //
|
|
11
|
-
// ========================================================================= //
|
|
12
|
-
|
|
13
|
-
const GetDefaults = (): IUser => ({
|
|
14
|
-
id: jetid(),
|
|
15
|
-
name: '',
|
|
16
|
-
email: '',
|
|
17
|
-
created: getISOString(),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const schema: Schema<IUser> = {
|
|
21
|
-
id: isUserId,
|
|
22
|
-
name: isString,
|
|
23
|
-
email: isString,
|
|
24
|
-
created: isISOString,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// ========================================================================= //
|
|
28
|
-
// TYPES //
|
|
29
|
-
// ========================================================================= //
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @entity users
|
|
33
|
-
*/
|
|
34
|
-
export interface IUser extends Entity {
|
|
35
|
-
name: string;
|
|
36
|
-
email: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Fields a client supplies when creating a user; the server sets the rest.
|
|
41
|
-
*/
|
|
42
|
-
export type IUserInput = Pick<IUser, 'name' | 'email'>;
|
|
43
|
-
|
|
44
|
-
// ========================================================================= //
|
|
45
|
-
// FUNCTIONS //
|
|
46
|
-
// ========================================================================= //
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Validate the `User` schema.
|
|
50
|
-
*/
|
|
51
|
-
const parseUser = parseObject<IUser>(schema);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* For the APIs make sure the right fields are complete
|
|
55
|
-
*/
|
|
56
|
-
const isCompleteUser = testObject<IUser>({
|
|
57
|
-
...schema,
|
|
58
|
-
name: isNonEmptyString,
|
|
59
|
-
email: isNonEmptyString,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Validate the fields a client sends to create a user.
|
|
64
|
-
*/
|
|
65
|
-
const isUserInput = testObject<IUserInput>({
|
|
66
|
-
name: isNonEmptyString,
|
|
67
|
-
email: isNonEmptyString,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Test if an id is a valid user id.
|
|
72
|
-
*/
|
|
73
|
-
function isUserId(val: unknown): val is string {
|
|
74
|
-
return jetid.test(val);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* New user object.
|
|
79
|
-
*/
|
|
80
|
-
function new_(user?: Partial<IUser>): IUser {
|
|
81
|
-
return parseUser({ ...GetDefaults(), ...user }, (errors) => {
|
|
82
|
-
throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ========================================================================= //
|
|
87
|
-
// EXPORT //
|
|
88
|
-
// ========================================================================= //
|
|
89
|
-
|
|
90
|
-
export default {
|
|
91
|
-
new: new_,
|
|
92
|
-
isId: isUserId,
|
|
93
|
-
isComplete: isCompleteUser,
|
|
94
|
-
isInput: isUserInput,
|
|
95
|
-
} as const;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var Http = (() => {
|
|
2
|
-
// Setup request for json
|
|
3
|
-
var getOptions = (verb, data) => {
|
|
4
|
-
var options = {
|
|
5
|
-
dataType: 'json',
|
|
6
|
-
method: verb,
|
|
7
|
-
headers: {
|
|
8
|
-
Accept: 'application/json',
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
if (!!data) {
|
|
13
|
-
options.body = JSON.stringify(data);
|
|
14
|
-
}
|
|
15
|
-
return options;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// Set Http methods
|
|
19
|
-
return {
|
|
20
|
-
get: (path) => fetch(path, getOptions('GET')),
|
|
21
|
-
post: (path, data) => fetch(path, getOptions('POST', data)),
|
|
22
|
-
put: (path, data) => fetch(path, getOptions('PUT', data)),
|
|
23
|
-
delete: (path) => fetch(path, getOptions('DELETE')),
|
|
24
|
-
};
|
|
25
|
-
})();
|