very-express 0.4.14 → 0.5.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/dist/index.js +702 -524
- package/dist/templates/_middlewares/Authentication.ts +45 -0
- package/dist/templates/_plugins/auth/JWTKeyStore.ts +71 -0
- package/dist/templates/_plugins/auth/jwt.ts +57 -0
- package/dist/templates/_plugins/auth/oauthVerify.ts +83 -0
- package/dist/templates/_plugins/auth/profileMapping.ts +69 -0
- package/dist/templates/_plugins/auth/token.ts +25 -0
- package/dist/templates/_roles/_RoleFactory.ts +2 -2
- package/dist/templates/_routes/oauth/OAuthRouteFactory.ts +88 -0
- package/dist/templates/_services/VexDbConnector.ts +20 -3
- package/dist/templates/_types/response/index.ts +10 -0
- package/dist/templates/_types/response/responseCode.ts +13 -0
- package/dist/templates/_types/response/responseMsg.ts +23 -0
- package/dist/templates/_types/response/responseStatusToCode.ts +70 -0
- package/dist/templates/_utils/common.ts +39 -3
- package/dist/templates/_utils/index.ts +6 -2
- package/dist/templates/_utils/logger.ts +5 -5
- package/dist/templates/_utils/processTimer.ts +6 -0
- package/dist/templates/_utils/response.ts +25 -11
- package/dist/templates/jsonSchema/User.json +41 -14
- package/dist/templates/root/.env +10 -1
- package/dist/templates/root/Dockerfile +20 -0
- package/dist/templates/root/README.md +5 -0
- package/dist/templates/root/package.json +13 -4
- package/dist/templates/root/scripts/build.js +39 -0
- package/docs/ForeignKey.md +40 -0
- package/docs/releaseNote/v0-5-0.md +18 -0
- package/docs/roadMap/v0-6-0.md +9 -1
- package/docs/roadMap/v0-7-0.md +3 -2
- package/docs/vexJsonSchema.md +5 -4
- package/package.json +4 -14
- package/scripts/copyTsTemplates.js +6 -0
- package/vex.config.json +4 -6
- package/dist/templates/_plugins/PassportGoogle.ts +0 -84
- package/dist/templates/_plugins/oauthVerify.ts +0 -39
- package/dist/templates/_types/responseMsg.ts +0 -20
- package/docs/roadMap/v0-5-0.md +0 -20
- /package/.github/workflows/{npm-publish.yml → npm-start.yml} +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import jsYaml from "js-yaml";
|
|
4
4
|
import fs from "fs";
|
|
5
|
+
import { Request } from "express";
|
|
5
6
|
|
|
6
7
|
export function loadYaml(yamlFilePath: string) {
|
|
7
8
|
try {
|
|
@@ -17,8 +18,10 @@ export function loadYaml(yamlFilePath: string) {
|
|
|
17
18
|
* @param fieldsString json stringified array of string
|
|
18
19
|
* @error may throw an error if the fieldsString is not a valid JSON
|
|
19
20
|
*/
|
|
20
|
-
export function parseFieldsSelect(
|
|
21
|
-
|
|
21
|
+
export function parseFieldsSelect(req: Request) : { [key: string]: number } | undefined {
|
|
22
|
+
|
|
23
|
+
const selectString = req.query._select;
|
|
24
|
+
const ErrorArrStrMsg = "Invalid \"_select\" string, only json array accepted";
|
|
22
25
|
|
|
23
26
|
if (typeof selectString === "undefined" || selectString === "") {
|
|
24
27
|
return undefined;
|
|
@@ -47,7 +50,40 @@ export function parseFieldsSelect(selectString: any) : { [key: string]: number }
|
|
|
47
50
|
return selectFields;
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
export function parseCollectionJoin(req: Request, availablePopulateOptions:{[key:string]: string}) : { [key: string]: string } | undefined {
|
|
54
|
+
|
|
55
|
+
const joinString = req.query._join;
|
|
56
|
+
const ErrorArrStrMsg = "Invalid \"_select\" string, only json array accepted";
|
|
57
|
+
const populateOptions: any = [];
|
|
58
|
+
|
|
59
|
+
if (typeof joinString === "undefined" || joinString === "") {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
else if (typeof joinString !== "string") {
|
|
63
|
+
throw new Error(ErrorArrStrMsg);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const joinArr: string[] = JSON.parse(joinString);
|
|
67
|
+
|
|
68
|
+
// switch joinArr's item to populate options
|
|
69
|
+
if(joinArr.length > 0) {
|
|
70
|
+
joinArr.forEach((refKey: any) => {
|
|
71
|
+
|
|
72
|
+
if(availablePopulateOptions[refKey]) {
|
|
73
|
+
populateOptions.push({
|
|
74
|
+
path: refKey,
|
|
75
|
+
select: availablePopulateOptions[refKey],
|
|
76
|
+
options: { lean: true }
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return populateOptions;
|
|
83
|
+
}
|
|
84
|
+
|
|
50
85
|
export default {
|
|
51
86
|
loadYaml,
|
|
52
|
-
parseFieldsSelect
|
|
87
|
+
parseFieldsSelect,
|
|
88
|
+
parseCollectionJoin
|
|
53
89
|
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
import logger from "./logger.gen";
|
|
2
4
|
import response from "./response.gen";
|
|
3
5
|
import validator from "./validator.gen";
|
|
4
|
-
import { responseMsg } from "./../_types/
|
|
6
|
+
import { responseMsg, responseCode, responseStatusToCode } from "./../_types/response/index.gen";
|
|
5
7
|
import common from "./common.gen";
|
|
6
8
|
|
|
7
9
|
export default {
|
|
8
10
|
log : logger,
|
|
9
11
|
response,
|
|
10
12
|
validator,
|
|
11
|
-
responseMsg
|
|
13
|
+
responseMsg,
|
|
14
|
+
responseCode,
|
|
15
|
+
responseStatusToCode,
|
|
12
16
|
common
|
|
13
17
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export function processing(msg: any, ...optionalParams: any[]): void {
|
|
2
|
-
console.log("\x1b[34m%s\x1b[0m", "[PROCESSING]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
2
|
+
console.log("\x1b[34m%s\x1b[0m", "[PROCESSING]" , new Date().toLocaleString() +" -", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function ok(msg: any, ...optionalParams: any[]): void {
|
|
6
|
-
console.log("\x1b[32m%s\x1b[0m", "[OK]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
6
|
+
console.log("\x1b[32m%s\x1b[0m", "[OK]" , new Date().toLocaleString() +" -", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function info(msg: any, ...optionalParams: any[]): void {
|
|
10
|
-
console.log("\x1b[36m%s\x1b[0m", "[INFO]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
10
|
+
console.log("\x1b[36m%s\x1b[0m", "[INFO]" , new Date().toLocaleString() +" -", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function warn(msg: any, ...optionalParams: any[]): void {
|
|
14
|
-
console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
14
|
+
console.log("\x1b[33m%s\x1b[0m", "[WARN]" , new Date().toLocaleString() +" -", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function error(msg: any, ...optionalParams: any[]): never {
|
|
@@ -20,7 +20,7 @@ export function error(msg: any, ...optionalParams: any[]): never {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function errorNoExit(msg: any, ...optionalParams: any[]): void {
|
|
23
|
-
console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
23
|
+
console.log("\x1b[41m%s\x1b[0m", "[ERROR]" , new Date().toLocaleString() +" -", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// wrapper
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import { Response } from "express";
|
|
2
|
-
|
|
2
|
+
import { responseStatusToCode, responseMsg, ResponseCode } from "./../_types/response/index.gen";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param res express response object
|
|
6
|
-
* @param
|
|
6
|
+
* @param status http response code
|
|
7
|
+
* @param code custom response/error code
|
|
7
8
|
* @param message response data message
|
|
8
9
|
* @param result response data result
|
|
9
10
|
* @returns express response object
|
|
10
11
|
*/
|
|
11
12
|
export function send<T = undefined>(
|
|
12
13
|
res: Response,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
status: number = 200,
|
|
15
|
+
body?:{
|
|
16
|
+
code?: ResponseCode,
|
|
17
|
+
message?: string|null,
|
|
18
|
+
result?: T,
|
|
19
|
+
}
|
|
16
20
|
): Response<any, Record<string, any>> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const code :ResponseCode | undefined = body?.code || responseStatusToCode.get(status) as ResponseCode | undefined;
|
|
22
|
+
const msg :string | undefined = body?.message || (code ? responseMsg[code] : undefined);
|
|
23
|
+
const noBody = !code && !msg && !body?.result;
|
|
24
|
+
|
|
25
|
+
if(noBody){
|
|
26
|
+
return res.status(status).send();
|
|
27
|
+
}
|
|
28
|
+
else{
|
|
29
|
+
return res.status(status)
|
|
30
|
+
.json({
|
|
31
|
+
ret_code: code,
|
|
32
|
+
ret_msg: msg,
|
|
33
|
+
elapse: Date.now() - res.locals?.startAt || 0,
|
|
34
|
+
result: body?.result,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
export default {
|
|
@@ -6,25 +6,39 @@
|
|
|
6
6
|
"getList",
|
|
7
7
|
"post",
|
|
8
8
|
"patch"
|
|
9
|
-
]
|
|
9
|
+
],
|
|
10
|
+
"documentName": "User"
|
|
10
11
|
},
|
|
11
12
|
"properties": {
|
|
12
13
|
"_id": {
|
|
13
14
|
"type": "string",
|
|
15
|
+
"x-format": "ObjectId",
|
|
14
16
|
"index": true
|
|
15
17
|
},
|
|
16
|
-
"
|
|
17
|
-
"type": "
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
"authProfiles": {
|
|
19
|
+
"type": "array",
|
|
20
|
+
"items": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"provider": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"index": true
|
|
26
|
+
},
|
|
27
|
+
"authId": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"index": true
|
|
30
|
+
},
|
|
31
|
+
"username": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"required": []
|
|
36
|
+
}
|
|
22
37
|
},
|
|
23
38
|
"email": {
|
|
24
39
|
"type": "string",
|
|
25
40
|
"format": "email",
|
|
26
|
-
"index": true
|
|
27
|
-
"required": true
|
|
41
|
+
"index": true
|
|
28
42
|
},
|
|
29
43
|
"name": {
|
|
30
44
|
"type": "string",
|
|
@@ -40,17 +54,30 @@
|
|
|
40
54
|
"type": "string",
|
|
41
55
|
"maxLength": 8
|
|
42
56
|
},
|
|
43
|
-
"roles":{
|
|
57
|
+
"roles": {
|
|
44
58
|
"type": "array",
|
|
45
59
|
"x-vexData": "role",
|
|
46
60
|
"items": {
|
|
47
61
|
"type": "string",
|
|
48
|
-
"default": "user",
|
|
49
|
-
"required": true,
|
|
50
62
|
"enum": [
|
|
51
|
-
"
|
|
63
|
+
"visitor",
|
|
64
|
+
"member",
|
|
65
|
+
"admin"
|
|
52
66
|
]
|
|
67
|
+
},
|
|
68
|
+
"default": [
|
|
69
|
+
"visitor"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"profileErrors": {
|
|
73
|
+
"type": "array",
|
|
74
|
+
"items": {
|
|
75
|
+
"type": "string"
|
|
53
76
|
}
|
|
54
77
|
}
|
|
55
|
-
}
|
|
78
|
+
},
|
|
79
|
+
"required": [
|
|
80
|
+
"name",
|
|
81
|
+
"active"
|
|
82
|
+
]
|
|
56
83
|
}
|
package/dist/templates/root/.env
CHANGED
|
@@ -2,4 +2,13 @@ APP_HOST=http://localhost:3000
|
|
|
2
2
|
MONGODB_URI=mongodb://localhost:27017/veryExpressDB
|
|
3
3
|
|
|
4
4
|
OAUTH_GOOGLE_CLIENTID=
|
|
5
|
-
OAUTH_GOOGLE_CLIENTSECRET=
|
|
5
|
+
OAUTH_GOOGLE_CLIENTSECRET=
|
|
6
|
+
|
|
7
|
+
OAUTH_GITHUB_CLIENTID=
|
|
8
|
+
OAUTH_GITHUB_CLIENTSECRET=
|
|
9
|
+
|
|
10
|
+
# OAUTH_APPLE_CLIENTID=
|
|
11
|
+
# OAUTH_APPLE_CLIENTSECRET=
|
|
12
|
+
|
|
13
|
+
JWT_EXPIRE_TIME=1m
|
|
14
|
+
JWT_KEY0='my-secret-key0'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Use the official Node.js image as the base image
|
|
2
|
+
FROM node:14
|
|
3
|
+
|
|
4
|
+
# Set the working directory inside the container
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
# Copy package.json and package-lock.json to the working directory
|
|
8
|
+
COPY package*.json ./
|
|
9
|
+
|
|
10
|
+
# Install dependencies
|
|
11
|
+
RUN npm install
|
|
12
|
+
|
|
13
|
+
# Copy only the /dist directory to the working directory
|
|
14
|
+
COPY dist ./dist
|
|
15
|
+
|
|
16
|
+
# Expose the port the app runs on
|
|
17
|
+
EXPOSE 3000
|
|
18
|
+
|
|
19
|
+
# Define the command to run the application
|
|
20
|
+
CMD ["npm", "start"]
|
|
@@ -1,39 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"main": "index.js",
|
|
3
3
|
"scripts": {
|
|
4
|
-
"build": "tsc -p .",
|
|
4
|
+
"build": "tsc -p . && node scripts/build.js",
|
|
5
5
|
"start": "node dist/server.js",
|
|
6
|
-
"dev": "nodemon --watch src --exec ts-node src/server.ts"
|
|
6
|
+
"dev": "nodemon --watch src --exec ts-node src/server.ts",
|
|
7
|
+
"docker-build": "docker build -t very-express .",
|
|
8
|
+
"docker-start": "docker run -p 3000:3000 very-express"
|
|
7
9
|
},
|
|
8
10
|
"dependencies": {
|
|
11
|
+
"cookie": "^0.6.0",
|
|
12
|
+
"cookie-parser": "^1.4.6",
|
|
9
13
|
"dotenv": "^16.4.4",
|
|
10
14
|
"express": "^4.18.2",
|
|
11
|
-
"express-session": "^1.18.0",
|
|
12
15
|
"express-validator": "^7.0.1",
|
|
13
16
|
"helmet": "^7.1.0",
|
|
14
17
|
"js-yaml": "^4.1.0",
|
|
18
|
+
"jsonwebtoken": "^9.0.2",
|
|
15
19
|
"mongo-ts-querystring": "^1.0.4",
|
|
16
20
|
"mongodb": "^5.6.0",
|
|
17
21
|
"mongoose": "^7.4.0",
|
|
18
22
|
"passport": "^0.7.0",
|
|
19
23
|
"passport-google-oauth20": "^2.0.0",
|
|
24
|
+
"passport-github": "^1.1.0",
|
|
25
|
+
"passport-jwt": "^4.0.1",
|
|
20
26
|
"swagger-ui-express": "^5.0.0"
|
|
21
27
|
},
|
|
22
28
|
"devDependencies": {
|
|
29
|
+
"@types/cookie-parser": "^1.4.7",
|
|
30
|
+
"@types/jsonwebtoken": "^9.0.7",
|
|
23
31
|
"@types/crypto-js": "^4.1.2",
|
|
24
32
|
"@types/dotenv": "^8.2.0",
|
|
25
33
|
"@types/express": "^4.17.17",
|
|
26
|
-
"@types/express-session": "^1.17.10",
|
|
27
34
|
"@types/express-validator": "^3.0.0",
|
|
28
35
|
"@types/js-yaml": "^4.0.9",
|
|
29
36
|
"@types/mongodb": "^4.0.7",
|
|
30
37
|
"@types/node": "^20.4.2",
|
|
31
38
|
"@types/passport": "^1.0.16",
|
|
32
39
|
"@types/passport-google-oauth20": "^2.0.14",
|
|
40
|
+
"@types/passport-github": "^1.1.12",
|
|
33
41
|
"@types/sequelize": "^4.28.15",
|
|
34
42
|
"@types/swagger-ui-express": "^4.1.6",
|
|
35
43
|
"@types/ws": "^8.5.5",
|
|
36
44
|
"nodemon": "^2.0.22",
|
|
45
|
+
"strip-json-comments": "^5.0.1",
|
|
37
46
|
"ts-node": "^10.9.1",
|
|
38
47
|
"typescript": "^5.1.6"
|
|
39
48
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// copy openapiDir to tsconfig's outDir
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
async function loadStripJsonComments() {
|
|
7
|
+
const { default: stripJsonComments } = await import('strip-json-comments');
|
|
8
|
+
return stripJsonComments;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
// Load strip-json-comments dynamically
|
|
13
|
+
const stripJsonComments = await loadStripJsonComments();
|
|
14
|
+
|
|
15
|
+
const openapiDir = "{{openapiDir}}";
|
|
16
|
+
const tsconfigPath = "tsconfig.json"
|
|
17
|
+
|
|
18
|
+
// 1. read tsconfig.json to get outDir
|
|
19
|
+
const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
20
|
+
const tsconfig = JSON.parse(stripJsonComments(tsconfigContent));
|
|
21
|
+
const outDir = tsconfig.compilerOptions.outDir;
|
|
22
|
+
|
|
23
|
+
// 2. copy ./openapi to outDir
|
|
24
|
+
const outDirOpenapi = path.resolve(outDir, 'openapi');
|
|
25
|
+
if (!fs.existsSync(outDirOpenapi)) {
|
|
26
|
+
fs.mkdirSync(outDirOpenapi, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
fs.readdirSync(openapiDir).forEach((file) => {
|
|
29
|
+
fs.copyFileSync(path.resolve(openapiDir, file), path.resolve(outDirOpenapi, file));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// Execute the main function
|
|
35
|
+
main()
|
|
36
|
+
.catch(err => {
|
|
37
|
+
console.error(err);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# v0.5.0 - Foreign-key & REST API
|
|
2
|
+
|
|
3
|
+
### Define Foreign-key
|
|
4
|
+
add attribute at JsonSchmea's field props, `x-foreignKey: "targetCollectionName"`
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
- **User Collection's** field "contactId" as foreign-key of **Contact Collection**
|
|
8
|
+
```JSON
|
|
9
|
+
{
|
|
10
|
+
"username": {
|
|
11
|
+
"type" : "string",
|
|
12
|
+
...
|
|
13
|
+
},
|
|
14
|
+
"contactId": {
|
|
15
|
+
"type" : "string",
|
|
16
|
+
"x-foreignKey" : "contact"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
### REST API Foreign-key supports
|
|
21
|
+
|
|
22
|
+
| Methods | Param | Type | Mandatory | Description |
|
|
23
|
+
| ------- | ----- | ---- | --------- | ----------- |
|
|
24
|
+
| GET | _join | QueryString `array<String>` | false | join collection using **Current Resource's Field Name**. target joined collection decleare by `x-forignKey` |
|
|
25
|
+
| GET | _select | QueryString `array<String>` | false | work with `_join`, select fields to join for target collection. empty = select all. |
|
|
26
|
+
|
|
27
|
+
**Example :**
|
|
28
|
+
`/user?_join=["contact"]&_select=["contactName","contactNumber"]`
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
**Output:**
|
|
32
|
+
```JSON
|
|
33
|
+
{
|
|
34
|
+
"username": "justin",
|
|
35
|
+
"contactId": {
|
|
36
|
+
"contactName": "justin's mobile",
|
|
37
|
+
"contactNumber": 1122333445566
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# v0.5.0 Plan
|
|
2
|
+
|
|
3
|
+
### foreign-key
|
|
4
|
+
- [x] define FK, add props at field, `x-foreignKey: "targetCollectionName"`
|
|
5
|
+
```JSON
|
|
6
|
+
{
|
|
7
|
+
"username": {
|
|
8
|
+
"type" : "string",
|
|
9
|
+
},
|
|
10
|
+
"contactId": {
|
|
11
|
+
"type" : "string",
|
|
12
|
+
"x-foreignKey" : "contact" // target collection's name
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
- [x] REST API, to request data with foreign-key collection:
|
|
17
|
+
add field name as array into querystring "_join"
|
|
18
|
+
example `/user?_join=["contact"]_select=["contactNo"]&`
|
package/docs/roadMap/v0-6-0.md
CHANGED
|
@@ -3,5 +3,13 @@
|
|
|
3
3
|
### dockernize
|
|
4
4
|
- [ ] dockernize
|
|
5
5
|
### oauth2 support
|
|
6
|
+
- [x] google
|
|
7
|
+
- [ ] apple
|
|
6
8
|
- [ ] microsoft
|
|
7
|
-
- [
|
|
9
|
+
- [-] github
|
|
10
|
+
- [ ] meta/facebook
|
|
11
|
+
### session storage
|
|
12
|
+
- [x] jwt
|
|
13
|
+
- [-] stateless design
|
|
14
|
+
- [ ] redis cache
|
|
15
|
+
- [-] rolling session secret
|
package/docs/roadMap/v0-7-0.md
CHANGED
package/docs/vexJsonSchema.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
| Fields | Data Type | Options | Description |
|
|
6
6
|
| - | - | - | - |
|
|
7
|
-
| documentName | `string` | - | auto generated using file name. used to name **Collection**, **TS Interface**, **ODM Model** etc. |
|
|
7
|
+
| documentName | `string` | - | auto generated using file name. this value should be same as the collection name, it will used to name **Collection**, **TS Interface**, **ODM Model** etc. |
|
|
8
8
|
| methods | `array<string>` | `get`, `post`, `put`, `patch`, `delete` | array of **REST API Method** to be enable. |
|
|
9
9
|
|
|
10
10
|
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
| type | `string` | true | - | [JsonSchema's type field](https://json-schema.org/understanding-json-schema/reference/type) |
|
|
16
16
|
| required | `boolean` | false | - | rest api's validator will check value cannot be falsy / undefined. |
|
|
17
17
|
| x-vexData | `string` | false | `primaryKey`, `role` | determine veryExpress generation process. |
|
|
18
|
-
| x-foreignKey |
|
|
18
|
+
| x-foreignKey | `string` | false | - | `documentName` from other JsonSchema, auto indexed, use to join collection |
|
|
19
|
+
| x-foreignValue | `array<String>` | false | - | default selected fields for target collection |
|
|
19
20
|
<!-- | format | `string` | false | - | veryExpress did not handle this field | -->
|
|
20
21
|
|
|
21
22
|
### System Fields
|
|
22
|
-
|
|
23
|
-
- `_id` : if defined in schema, will auto set as `"index": true`, `"x-vexData": "ObjectId"`.
|
|
23
|
+
System Fields is the properties to let generator run as expected,it should not be changed.
|
|
24
|
+
- `_id` : if defined in schema, it will auto being set as `"index": true`, `"x-vexData": "ObjectId"`.
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
#### Example :
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "very-express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
|
|
5
5
|
"author": "Justin26l",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,31 +28,21 @@
|
|
|
28
28
|
"url": "git+https://github.com/Justin26l/VeryExpress.git"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/express": "^4.17.21",
|
|
32
|
-
"@types/express-session": "^1.17.10",
|
|
33
31
|
"@types/js-yaml": "^4.0.9",
|
|
34
32
|
"@types/minimist": "^1.2.5",
|
|
35
33
|
"@types/node": "^20.10.5",
|
|
36
34
|
"@types/passport": "^1.0.16",
|
|
37
|
-
"@types/passport-google-oauth20": "^2.0.14",
|
|
38
|
-
"@types/swagger-ui-express": "^4.1.6",
|
|
39
35
|
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
40
36
|
"@typescript-eslint/parser": "^6.18.1",
|
|
41
37
|
"dotenv": "^16.3.1",
|
|
42
38
|
"esbuild": "0.23.0",
|
|
43
|
-
"eslint": "^8.
|
|
44
|
-
"express": "^4.18.2",
|
|
45
|
-
"express-session": "^1.17.3",
|
|
46
|
-
"express-validator": "^7.0.1",
|
|
47
|
-
"helmet": "^7.1.0",
|
|
39
|
+
"eslint": "^8.57.1",
|
|
48
40
|
"js-yaml": "^4.1.0",
|
|
49
41
|
"json-schema-to-openapi-schema": "^0.4.0",
|
|
50
42
|
"json-schema-to-typescript": "^13.1.1",
|
|
51
|
-
"json2mongoose": "^0.
|
|
43
|
+
"json2mongoose": "^0.4.4",
|
|
52
44
|
"minimist": "^1.2.8",
|
|
53
|
-
"
|
|
54
|
-
"passport-google-oauth20": "^2.0.0",
|
|
55
|
-
"swagger-ui-express": "^5.0.0",
|
|
45
|
+
"mongoose": "^8.7.1",
|
|
56
46
|
"ts-node": "^10.9.2",
|
|
57
47
|
"typescript": "^5.3.3"
|
|
58
48
|
}
|
|
@@ -6,9 +6,15 @@ const path = require('path');
|
|
|
6
6
|
* to copy template files into tsc output dir (dist)
|
|
7
7
|
*/
|
|
8
8
|
function copyDir (src, destination) {
|
|
9
|
+
|
|
9
10
|
if (!fs.existsSync(destination)) {
|
|
10
11
|
fs.mkdirSync(destination);
|
|
11
12
|
}
|
|
13
|
+
else {
|
|
14
|
+
fs.rmdirSync(destination, { recursive: true });
|
|
15
|
+
fs.mkdirSync(destination);
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
fs.readdirSync(src).forEach((file) => {
|
|
13
19
|
const srcPath = path.join(src, file);
|
|
14
20
|
const destPath = path.join(destination, file);
|
package/vex.config.json
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
"enableSwagger": true,
|
|
9
9
|
"useUserSchema": true,
|
|
10
10
|
"useObjectID": true,
|
|
11
|
-
"allowApiCreateUpdate_id": false
|
|
11
|
+
"allowApiCreateUpdate_id": false,
|
|
12
|
+
"useStatefulRedisAuth": true
|
|
12
13
|
},
|
|
13
14
|
"useOauth": {
|
|
14
15
|
"google": true,
|
|
15
|
-
"
|
|
16
|
-
"apple": false,
|
|
17
|
-
"github": false,
|
|
18
|
-
"facebook": false
|
|
16
|
+
"github": true
|
|
19
17
|
},
|
|
20
18
|
"useRBAC": {
|
|
21
19
|
"roles": [
|
|
@@ -28,5 +26,5 @@
|
|
|
28
26
|
"User"
|
|
29
27
|
]
|
|
30
28
|
},
|
|
31
|
-
"sysDir": "
|
|
29
|
+
"sysDir": "output/src/system"
|
|
32
30
|
}
|