express-generator-typescript 2.9.0 → 3.0.1
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 +196 -17
- package/lib/template/README.md +33 -15
- package/lib/template/package.json +13 -24
- package/lib/template/src/common/{utils → classes}/route-errors.ts +1 -1
- package/lib/template/src/common/constants/HttpStatusCodes.ts +7 -2
- package/lib/template/src/common/constants/{env.ts → env-inv.ts} +13 -9
- 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/main.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 +4 -4
- 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 +17 -5
- 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 -5
- 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,27 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
5
|
-
"
|
|
6
|
-
"strict": true,
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
7
6
|
"esModuleInterop": true,
|
|
7
|
+
"lib": ["ES2022"],
|
|
8
|
+
"strict": true,
|
|
8
9
|
"skipLibCheck": true,
|
|
9
10
|
"forceConsistentCasingInFileNames": true,
|
|
10
11
|
"paths": {
|
|
11
12
|
"@src/*": ["./src/*"]
|
|
12
13
|
},
|
|
14
|
+
// tsx transpiles one file at a time, so type-only imports must say so
|
|
15
|
+
"verbatimModuleSyntax": true,
|
|
13
16
|
"useUnknownInCatchVariables": false,
|
|
14
|
-
"types": ["vitest/globals"]
|
|
15
|
-
},
|
|
16
|
-
"ts-node": {
|
|
17
|
-
"swc": true,
|
|
18
|
-
"require": ["tsconfig-paths/register", "dotenv/config"],
|
|
17
|
+
"types": ["node", "vitest/globals"]
|
|
19
18
|
},
|
|
20
19
|
"include": [
|
|
21
20
|
"src/**/*.ts",
|
|
22
21
|
"tests/**/*.ts",
|
|
23
22
|
"eslint.config.ts",
|
|
24
|
-
"vitest.config.
|
|
23
|
+
"vitest.config.ts"
|
|
25
24
|
],
|
|
26
25
|
"exclude": ["src/public/*"]
|
|
27
26
|
}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
5
|
-
"
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"lib": ["ES2022"],
|
|
6
8
|
"strict": true,
|
|
7
9
|
"rootDir": "./src",
|
|
8
10
|
"outDir": "dist",
|
|
9
|
-
"esModuleInterop": true,
|
|
10
11
|
"skipLibCheck": true,
|
|
11
12
|
"forceConsistentCasingInFileNames": true,
|
|
12
13
|
"paths": {
|
|
13
14
|
"@src/*": ["./src/*"]
|
|
14
15
|
},
|
|
16
|
+
"verbatimModuleSyntax": true,
|
|
15
17
|
"useUnknownInCatchVariables": false,
|
|
18
|
+
"types": ["node"],
|
|
16
19
|
"sourceMap": false,
|
|
17
20
|
"removeComments": true
|
|
18
21
|
},
|
|
22
|
+
// After tsc, tsc-alias rewrites "@src/..." imports in dist/ to relative
|
|
23
|
+
// paths and adds the ".js" extensions Node's ESM loader requires (source
|
|
24
|
+
// imports are written without extensions)
|
|
25
|
+
"tsc-alias": {
|
|
26
|
+
"resolveFullPaths": true
|
|
27
|
+
},
|
|
19
28
|
"include": ["src/**/*.ts"],
|
|
20
29
|
"exclude": ["src/public/"]
|
|
21
30
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { defineConfig } from 'vitest/config';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// ========================================================================= //
|
|
5
|
+
// EXPORT //
|
|
6
|
+
// ========================================================================= //
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
5
9
|
test: {
|
|
6
10
|
globals: true,
|
|
7
11
|
environment: 'node',
|
|
@@ -15,9 +19,7 @@ const config = defineConfig({
|
|
|
15
19
|
},
|
|
16
20
|
resolve: {
|
|
17
21
|
alias: {
|
|
18
|
-
'@src': path.resolve(
|
|
22
|
+
'@src': path.resolve(import.meta.dirname, './src'),
|
|
19
23
|
},
|
|
20
24
|
},
|
|
21
25
|
});
|
|
22
|
-
|
|
23
|
-
export default config;
|
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"commit": "git add -A && git commit -m \"dev commit\"",
|
|
7
7
|
"commit:push": "npm run commit && git push",
|
|
8
8
|
"install:clean": "rm -rf node_modules && rm -rf package-lock.json && npm i",
|
|
9
|
-
"prepack": "npm run readme:swap",
|
|
10
|
-
"postpack": "npm run readme:restore",
|
|
11
|
-
"readme:swap": "node scripts/readme.js swap",
|
|
12
|
-
"readme:restore": "node scripts/readme.js restore",
|
|
13
9
|
"test": "node --test \"tests/**/*.test.js\"",
|
|
14
10
|
"test:e2e": "node scripts/e2e.js"
|
|
15
11
|
},
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
proxy: "http://localhost:3000/", // The address where your Express app runs
|
|
3
|
-
open: true, // Avoid reopening the browser on every nodemon restart
|
|
4
|
-
port: 3001, // The port BrowserSync will run on
|
|
5
|
-
files: ["src/**/*.*"], // Files to watch
|
|
6
|
-
ignore: ['**/node_modules/**', '**/repos/**/*.json'],
|
|
7
|
-
reloadDelay: 500, // Wait for nodemon to restart
|
|
8
|
-
};
|
|
@@ -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
|
-
})();
|