very-express 0.4.2 → 0.4.5
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 +50 -74
- package/dist/_plugins/PassportGoogle.ts +1 -1
- package/dist/_services/VexDbConnector.ts +70 -0
- package/dist/_types/responseMsg.ts +9 -2
- package/dist/_utils/index.ts +2 -2
- package/dist/_utils/logger.ts +22 -0
- package/dist/_utils/response.ts +2 -7
- package/dist/index.js +86602 -922
- package/dist/templates/_plugins/PassportGoogle.ts +1 -1
- package/dist/templates/_services/VexDbConnector.ts +70 -0
- package/dist/templates/_types/responseMsg.ts +9 -2
- package/dist/templates/_utils/index.ts +2 -2
- package/dist/templates/_utils/logger.ts +22 -0
- package/dist/templates/_utils/response.ts +2 -7
- package/dist/templates/root/.env +1 -2
- package/dist/templates/root/package.json +0 -2
- package/docs/defineJsonSchema.md +42 -0
- package/docs/developmentNote.md +16 -0
- package/docs/roadMap/RoadMap.md +30 -0
- package/docs/roadMap/v0-5-0.md +20 -0
- package/docs/roadMap/v0-6-0.md +7 -0
- package/docs/roadMap/v0-7-0.md +4 -0
- package/package.json +3 -4
- package/dist/_services/mongoConn.ts +0 -38
- package/dist/generators/app/role.generator.d.ts +0 -7
- package/dist/templates/_services/mongoConn.ts +0 -38
package/README.md
CHANGED
|
@@ -1,76 +1,52 @@
|
|
|
1
1
|
# VeryExpress
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
all you need is define the
|
|
9
|
-
|
|
2
|
+
this is a generator to make [Express](https://github.com/expressjs/express) REST API app based on [Json Schema](https://github.com/json-schema-org) and [Open Api](https://github.com/OAI)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Why?
|
|
6
|
+
bored on writing CRUD API time after time ?
|
|
7
|
+
then this tool might save your time,
|
|
8
|
+
all you need is define the **Json Schema** files.
|
|
9
|
+
|
|
10
|
+
|
|
10
11
|
# Quick Start
|
|
11
|
-
1.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
3.
|
|
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
|
-
## Road Map
|
|
56
|
-
- [ ] dockernize
|
|
57
|
-
- [x] generate express app
|
|
58
|
-
- [x] gen. openapi based on json schema
|
|
59
|
-
- [x] gen. controllers based on openapi
|
|
60
|
-
- [x] CRUD + Search api
|
|
61
|
-
- [ ] database
|
|
62
|
-
- [x] mongodb
|
|
63
|
-
- [ ] sql
|
|
64
|
-
- [ ] db encrtption [PDPA](https://en.wikipedia.org/wiki/Personal_Data_Protection_Act_2012)
|
|
65
|
-
- [ ] oauth2
|
|
66
|
-
- [ ] google
|
|
67
|
-
- [ ] microsoft
|
|
68
|
-
- [ ] github
|
|
69
|
-
- [ ] Role Base Access Control
|
|
70
|
-
|
|
71
|
-
## Enhancement To Do
|
|
72
|
-
|
|
73
|
-
- Implement data encryption & hash (PDPA)
|
|
74
|
-
- at JsonSchmea fields, add attribute
|
|
75
|
-
`x-dataSecure: "method"` while accessing data, perform encryption based on method selected.
|
|
76
|
-
|
|
12
|
+
1. install package globally.
|
|
13
|
+
```npm i -g very-express```
|
|
14
|
+
|
|
15
|
+
3. use cli to initialize configuration file **vex.config.json** under your project root directory.
|
|
16
|
+
`vex -init`
|
|
17
|
+
|
|
18
|
+
2. create a empty directory name it as value of vex.config's "jsonSchemaDir", default **jsonSchema**.
|
|
19
|
+
`mkdir jsonSchema`.
|
|
20
|
+
|
|
21
|
+
4. generate the app with vex.config param.
|
|
22
|
+
`vex`
|
|
23
|
+
|
|
24
|
+
5. you should saw a express typescript app being generated (with src, package.json etc) .
|
|
25
|
+
```
|
|
26
|
+
├── jsonSchema/
|
|
27
|
+
│ └── ...
|
|
28
|
+
├── src/
|
|
29
|
+
│ └── ...
|
|
30
|
+
├── package.json
|
|
31
|
+
├── tsconfig.json
|
|
32
|
+
├── vex.config.json
|
|
33
|
+
└── .env
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
6. you could create your db collection/table now in directory **jsonSchema/** just created,
|
|
37
|
+
refer to [Define Json Schmea](./docs/defineJsonSchema.md).
|
|
38
|
+
|
|
39
|
+
7. start the generated express app.
|
|
40
|
+
```
|
|
41
|
+
npm i
|
|
42
|
+
npm build
|
|
43
|
+
npm run start
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Resource
|
|
48
|
+
- [Documents](./docs/)
|
|
49
|
+
- [Road Map](./docs/roadMap/)
|
|
50
|
+
- [ReleaseNote](./docs/releaseNote)
|
|
51
|
+
|
|
52
|
+
- [Discord](https://discord.gg/PZGMzDp7)
|
|
@@ -31,7 +31,7 @@ export default class PassportGoogle {
|
|
|
31
31
|
this.config.strategyConfig.options || {
|
|
32
32
|
clientID: process.env.OAUTH_GOOGLE_CLIENTID || "",
|
|
33
33
|
clientSecret: process.env.OAUTH_GOOGLE_CLIENTSECRET || "",
|
|
34
|
-
callbackURL: `${process.env.APP_HOST}
|
|
34
|
+
callbackURL: `${process.env.APP_HOST}/auth/google/callback`,
|
|
35
35
|
},
|
|
36
36
|
this.config.strategyConfig.verify
|
|
37
37
|
));
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// {{headerComment}}
|
|
2
|
+
|
|
3
|
+
import mongoose from "mongoose";
|
|
4
|
+
import { Request, Response, NextFunction } from "express";
|
|
5
|
+
import vex from "./../_utils/index.gen";
|
|
6
|
+
|
|
7
|
+
export default class VexDbConnector {
|
|
8
|
+
private mongoUrl: string;
|
|
9
|
+
private sqlUrl: string;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
constructor(options:{
|
|
13
|
+
mongoUrl?: string;
|
|
14
|
+
sqlUrl?: string;
|
|
15
|
+
}){
|
|
16
|
+
this.mongoUrl = options.mongoUrl || "";
|
|
17
|
+
this.sqlUrl = options.sqlUrl || "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
connectMongo() : mongoose.Connection | void {
|
|
21
|
+
if ( !this.mongoUrl ){
|
|
22
|
+
vex.log.error(`VexDbConnector : MongoUrl is not invalid "${this.mongoUrl}"`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @param retryTime time in second
|
|
27
|
+
*/
|
|
28
|
+
const connectWithRetry = (retryTime: number = 10) : Promise<void | typeof mongoose> => {
|
|
29
|
+
// vex.log.infoMongo("Connection with retry");
|
|
30
|
+
return mongoose.connect(this.mongoUrl, {
|
|
31
|
+
autoCreate: true,
|
|
32
|
+
connectTimeoutMS: 5000,
|
|
33
|
+
})
|
|
34
|
+
.catch((err) => {
|
|
35
|
+
vex.log.errorMongo(`Failed to Connect DB, Retrying in ${retryTime} seconds.`, err);
|
|
36
|
+
setTimeout(connectWithRetry, retryTime*1000);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
connectWithRetry(10);
|
|
40
|
+
|
|
41
|
+
mongoose.connection.on("open", () => {
|
|
42
|
+
vex.log.infoMongo("MongoDB Connection open : " + this.mongoUrl);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
mongoose.connection.on("error", (err: any) => {
|
|
46
|
+
vex.log.errorMongo("MongoDB Connection error:", err.message, err);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return mongoose.connection;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
middleware(req: Request, res: Response, next: NextFunction) {
|
|
53
|
+
if (mongoose.connection.readyState !== 1) {
|
|
54
|
+
vex.response.send(res, 503, "Database Connection Down");
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
mongoose.connection.collection("accessLogs").insertOne({
|
|
58
|
+
timestamp: new Date().getTime(),
|
|
59
|
+
ipa: req.socket.remoteAddress || req.headers["x-forwarded-for"],
|
|
60
|
+
method: req.method,
|
|
61
|
+
url: req.url.split("?")[0],
|
|
62
|
+
headers: req.headers,
|
|
63
|
+
// body: req.body,
|
|
64
|
+
query: req.query,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
next();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
enum
|
|
1
|
+
export enum responseMsg {
|
|
2
2
|
permissionDeny = "Permission Denied",
|
|
3
3
|
ok = "OK",
|
|
4
4
|
notFound = "Not Found",
|
|
@@ -10,4 +10,11 @@ enum responseMessage {
|
|
|
10
10
|
deleteFail = "Delete Fail",
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface responseObject<T>{
|
|
14
|
+
ret_code : number,
|
|
15
|
+
ret_msg : string,
|
|
16
|
+
ret_time?: number,
|
|
17
|
+
result: T,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default responseMsg;
|
package/dist/_utils/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import logger from "./logger.gen";
|
|
2
2
|
import response from "./response.gen";
|
|
3
|
-
import
|
|
3
|
+
import { responseMsg } from "./../_types/responseMsg.gen";
|
|
4
4
|
import common from "./common.gen";
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
log : logger,
|
|
8
8
|
response,
|
|
9
|
-
responseMsg :
|
|
9
|
+
responseMsg : responseMsg ,
|
|
10
10
|
common
|
|
11
11
|
};
|
package/dist/_utils/logger.ts
CHANGED
|
@@ -19,10 +19,32 @@ export function error(msg: any, ...optionalParams: any[]): never {
|
|
|
19
19
|
process.exit(1);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// wrapper
|
|
23
|
+
export function infoMongo(msg: any, ...optionalParams: any[]): void {
|
|
24
|
+
info("[MONGO]", msg, optionalParams);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function errorMongo(msg: any, ...optionalParams: any[]): never {
|
|
28
|
+
error("[MONGO]", msg, optionalParams);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function infoSql(msg: any, ...optionalParams: any[]): void {
|
|
32
|
+
info("[SQL]", msg, optionalParams);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function errorSql(msg: any, ...optionalParams: any[]): never {
|
|
36
|
+
error("[SQL]", msg, optionalParams);
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
export default {
|
|
23
40
|
process : processing,
|
|
24
41
|
ok,
|
|
25
42
|
info,
|
|
26
43
|
warn,
|
|
27
44
|
error,
|
|
45
|
+
|
|
46
|
+
infoMongo,
|
|
47
|
+
errorMongo,
|
|
48
|
+
infoSql,
|
|
49
|
+
errorSql,
|
|
28
50
|
};
|
package/dist/_utils/response.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Response } from "express";
|
|
2
|
-
|
|
3
|
-
export interface responseObject<T>{
|
|
4
|
-
ret_code : number,
|
|
5
|
-
ret_msg : string,
|
|
6
|
-
ret_time?: number,
|
|
7
|
-
result: T,
|
|
8
|
-
}
|
|
2
|
+
// import { responseObject } from "./../_types/responseMsg.gen";
|
|
9
3
|
|
|
10
4
|
/**
|
|
11
5
|
* @param res express response object
|
|
12
6
|
* @param code http status
|
|
13
7
|
* @param message response data message
|
|
14
8
|
* @param result response data result
|
|
9
|
+
* @returns express response object
|
|
15
10
|
*/
|
|
16
11
|
export function send<T = undefined>(
|
|
17
12
|
res: Response,
|