very-express 0.4.10 → 0.4.12

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 (68) hide show
  1. package/.eslintrc.json +37 -37
  2. package/.gitattributes +2 -2
  3. package/.github/workflows/npm-publish.yml +38 -0
  4. package/LICENSE +21 -21
  5. package/README.md +61 -52
  6. package/docs/developmentNote.md +23 -16
  7. package/docs/roadMap/RoadMap.md +30 -30
  8. package/docs/roadMap/v0-5-0.md +19 -19
  9. package/docs/roadMap/v0-6-0.md +6 -6
  10. package/docs/roadMap/v0-7-0.md +3 -3
  11. package/docs/vexJsonSchema.md +54 -40
  12. package/package.json +59 -65
  13. package/scripts/build.js +14 -0
  14. package/scripts/copyTsTemplates.js +24 -0
  15. package/tsconfig.json +121 -121
  16. package/vex.config.json +1 -1
  17. package/dist/_plugins/PassportGoogle.ts +0 -87
  18. package/dist/_plugins/oauthVerify.ts +0 -39
  19. package/dist/_roles/_RoleFactory.ts +0 -22
  20. package/dist/_services/VexDbConnector.ts +0 -70
  21. package/dist/_types/responseMsg.ts +0 -20
  22. package/dist/_utils/common.ts +0 -53
  23. package/dist/_utils/index.ts +0 -11
  24. package/dist/_utils/logger.ts +0 -50
  25. package/dist/_utils/response.ts +0 -27
  26. package/dist/cli.d.ts +0 -1
  27. package/dist/generators/app/openapi.generator.d.ts +0 -3
  28. package/dist/generators/app/server.generator.d.ts +0 -2
  29. package/dist/generators/app/server.template.d.ts +0 -5
  30. package/dist/generators/controller/controller.template.d.ts +0 -14
  31. package/dist/generators/controller/controllers.generator.d.ts +0 -7
  32. package/dist/generators/index.d.ts +0 -9
  33. package/dist/generators/middlewares/RBACmiddleware.generator.d.ts +0 -6
  34. package/dist/generators/middlewares/RBACmiddlewares.template.d.ts +0 -6
  35. package/dist/generators/project/packageJson.generator.d.ts +0 -6
  36. package/dist/generators/project/userSchema.generator.d.ts +0 -4
  37. package/dist/generators/role/role.generator.d.ts +0 -8
  38. package/dist/generators/role/role.template.d.ts +0 -8
  39. package/dist/generators/routes/oauth.generator.d.ts +0 -2
  40. package/dist/generators/routes/routes.generator.d.ts +0 -11
  41. package/dist/generators/routes/routes.template.d.ts +0 -11
  42. package/dist/generators/routes/swagger.generator.d.ts +0 -2
  43. package/dist/index.d.ts +0 -2
  44. package/dist/index.js +0 -1031
  45. package/dist/preprocess/jsonschemaFormat.d.ts +0 -2
  46. package/dist/preprocess/roleSetupFile.d.ts +0 -9
  47. package/dist/templates/_plugins/PassportGoogle.ts +0 -87
  48. package/dist/templates/_plugins/oauthVerify.ts +0 -39
  49. package/dist/templates/_roles/_RoleFactory.d.ts +0 -10
  50. package/dist/templates/_roles/_RoleFactory.ts +0 -22
  51. package/dist/templates/_services/VexDbConnector.ts +0 -70
  52. package/dist/templates/_types/responseMsg.ts +0 -20
  53. package/dist/templates/_utils/common.ts +0 -53
  54. package/dist/templates/_utils/index.ts +0 -11
  55. package/dist/templates/_utils/logger.ts +0 -50
  56. package/dist/templates/_utils/response.ts +0 -27
  57. package/dist/templates/jsonSchema/User.json +0 -56
  58. package/dist/templates/root/.env +0 -5
  59. package/dist/templates/root/package.json +0 -40
  60. package/dist/templates/root/tsconfig.json +0 -22
  61. package/dist/types/openapi.d.ts +0 -108
  62. package/dist/types/types.d.ts +0 -75
  63. package/dist/utils/common.d.ts +0 -13
  64. package/dist/utils/configChecker.d.ts +0 -6
  65. package/dist/utils/generator.d.ts +0 -12
  66. package/dist/utils/index.d.ts +0 -30
  67. package/dist/utils/jsonSchema.d.ts +0 -14
  68. package/dist/utils/logger.d.ts +0 -13
@@ -1,70 +0,0 @@
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,20 +0,0 @@
1
- export enum responseMsg {
2
- permissionDeny = "Permission Denied",
3
- ok = "OK",
4
- notFound = "Not Found",
5
- queryError = "Query Error",
6
- validateError = "Validation Error",
7
- unexpectedError = "Unexpected Error",
8
- createFail = "Create Fail",
9
- updateFail = "Update Fail",
10
- deleteFail = "Delete Fail",
11
- }
12
-
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;
@@ -1,53 +0,0 @@
1
- // {{headerComment}}
2
-
3
- import jsYaml from "js-yaml";
4
- import fs from "fs";
5
-
6
- export function loadYaml(yamlFilePath: string) {
7
- try {
8
- return jsYaml.load(fs.readFileSync(yamlFilePath, "utf8"));
9
- } catch (e: any) {
10
- console.log("\x1b[41m%s\x1b[0m", "[ERROR]", "Error Load OpenApi File :\n", e);
11
- process.exit(0);
12
- }
13
- }
14
-
15
- /**
16
- * build mongoose select object
17
- * @param fieldsString json stringified array of string
18
- * @error may throw an error if the fieldsString is not a valid JSON
19
- */
20
- export function parseFieldsSelect(selectString: any) : { [key: string]: number } | undefined {
21
- const ErrorArrStrMsg = "Invalid select string, only array of string accepted";
22
-
23
- if (typeof selectString === "undefined" || selectString === "") {
24
- return undefined;
25
- }
26
- else if (typeof selectString !== "string") {
27
- throw new Error(ErrorArrStrMsg);
28
- }
29
-
30
- const fieldArr: string[] = JSON.parse(selectString);
31
-
32
- if (!Array.isArray(fieldArr)) {
33
- throw new Error(ErrorArrStrMsg);
34
- }
35
-
36
- for (let i = 0; i < fieldArr.length; i++) {
37
- if (typeof fieldArr[i] !== "string") {
38
- throw new Error(ErrorArrStrMsg);
39
- }
40
- }
41
- // Convert the fieldArr to an object that can be used in the select method
42
- const selectFields = fieldArr.reduce((obj: any, field: string) => {
43
- obj[field] = 1;
44
- return obj;
45
- }, {} as Record<string, number>);
46
-
47
- return selectFields;
48
- }
49
-
50
- export default {
51
- loadYaml,
52
- parseFieldsSelect
53
- };
@@ -1,11 +0,0 @@
1
- import logger from "./logger.gen";
2
- import response from "./response.gen";
3
- import { responseMsg } from "./../_types/responseMsg.gen";
4
- import common from "./common.gen";
5
-
6
- export default {
7
- log : logger,
8
- response,
9
- responseMsg : responseMsg ,
10
- common
11
- };
@@ -1,50 +0,0 @@
1
- export function processing(msg: any, ...optionalParams: any[]): void {
2
- console.log("\x1b[34m%s\x1b[0m", "[PROCESSING]", msg, optionalParams.length > 0 ? optionalParams : "");
3
- }
4
-
5
- export function ok(msg: any, ...optionalParams: any[]): void {
6
- console.log("\x1b[32m%s\x1b[0m", "[OK]", msg, optionalParams.length > 0 ? optionalParams : "");
7
- }
8
-
9
- export function info(msg: any, ...optionalParams: any[]): void {
10
- console.log("\x1b[36m%s\x1b[0m", "[INFO]", msg, optionalParams.length > 0 ? optionalParams : "");
11
- }
12
-
13
- export function warn(msg: any, ...optionalParams: any[]): void {
14
- console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
15
- }
16
-
17
- export function error(msg: any, ...optionalParams: any[]): never {
18
- console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
19
- process.exit(1);
20
- }
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
-
39
- export default {
40
- process : processing,
41
- ok,
42
- info,
43
- warn,
44
- error,
45
-
46
- infoMongo,
47
- errorMongo,
48
- infoSql,
49
- errorSql,
50
- };
@@ -1,27 +0,0 @@
1
- import { Response } from "express";
2
- // import { responseObject } from "./../_types/responseMsg.gen";
3
-
4
- /**
5
- * @param res express response object
6
- * @param code http status
7
- * @param message response data message
8
- * @param result response data result
9
- * @returns express response object
10
- */
11
- export function send<T = undefined>(
12
- res: Response,
13
- code: number = 200,
14
- message: string = "OK",
15
- result?: T,
16
- ): Response<any, Record<string, any>> {
17
- return res.status(code).json({
18
- ret_code: code,
19
- ret_msg: message,
20
- ret_time: new Date().getTime(),
21
- result: result,
22
- });
23
- }
24
-
25
- export default {
26
- send
27
- };
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import * as types from "./../../types/types";
2
- export declare function compile(openapiOutFileName: string, compilerOptions: types.compilerOptions): Promise<void>;
3
- export default compile;
@@ -1,2 +0,0 @@
1
- import * as types from "../../types/types";
2
- export declare function compile(compilerOptions: types.compilerOptions): Promise<void>;
@@ -1,5 +0,0 @@
1
- import * as types from "../../types/types";
2
- export default function serverTemplate(options: {
3
- compilerOptions: types.compilerOptions;
4
- template?: string;
5
- }): string;
@@ -1,14 +0,0 @@
1
- import * as types from "../../types/types";
2
- import { Schema } from "express-validator";
3
- export default function controllerTemplate(templateOptions: {
4
- template?: string;
5
- endpoint: string;
6
- modelPath: string;
7
- documentName: string;
8
- validators: {
9
- [key: string]: {
10
- [key: string]: Schema;
11
- };
12
- };
13
- compilerOptions: types.compilerOptions;
14
- }): string;
@@ -1,7 +0,0 @@
1
- import * as types from "./../../types/types";
2
- export declare function compile(options: {
3
- openapiFile: string;
4
- controllerOutDir: string;
5
- modelDir: string;
6
- compilerOptions: types.compilerOptions;
7
- }): Promise<void>;
@@ -1,9 +0,0 @@
1
- import controllerTemplate from "./controller/controller.template";
2
- import routesTemplate from "./routes/routes.template";
3
- import serverTemplate from "./app/server.template";
4
- declare const _default: {
5
- controllerTemplate: typeof controllerTemplate;
6
- routesTemplate: typeof routesTemplate;
7
- serverTemplate: typeof serverTemplate;
8
- };
9
- export default _default;
@@ -1,6 +0,0 @@
1
- import * as types from "../../types/types";
2
- export declare function compile(options: {
3
- middlewareDir: string;
4
- roleTypes: string;
5
- compilerOptions: types.compilerOptions;
6
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- import * as types from "../../types/types";
2
- export default function RBACmiddlewareTemplate(options: {
3
- template?: string;
4
- roleTypes: string;
5
- compilerOptions: types.compilerOptions;
6
- }): string;
@@ -1,6 +0,0 @@
1
- import * as types from "./../../types/types";
2
- export declare function compile(packageOutPath: string, compilerOptions: types.compilerOptions): Promise<void>;
3
- declare const _default: {
4
- compile: typeof compile;
5
- };
6
- export default _default;
@@ -1,4 +0,0 @@
1
- import * as types from "./../../types/types";
2
- export declare function compile(options: {
3
- compilerOptions: types.compilerOptions;
4
- }): Promise<void>;
@@ -1,8 +0,0 @@
1
- import * as types from "../../types/types";
2
- export declare function compile(options: {
3
- collectionList: string[];
4
- roleSourceDir: string;
5
- roleOutDir: string;
6
- middlewareDir: string;
7
- compilerOptions: types.compilerOptions;
8
- }): Promise<void>;
@@ -1,8 +0,0 @@
1
- import * as types from "../../types/types";
2
- export default function RBACmiddlewareTemplate(options: {
3
- template?: string;
4
- role: string;
5
- roleContent: any;
6
- RoleAccessActionString: string[];
7
- compilerOptions: types.compilerOptions;
8
- }): string;
@@ -1,2 +0,0 @@
1
- import * as types from "../../types/types";
2
- export declare function compile(compilerOptions: types.compilerOptions): string;
@@ -1,11 +0,0 @@
1
- import * as types from "./../../types/types";
2
- export declare function compile(options: {
3
- routesArr: {
4
- route: string;
5
- documentName: string;
6
- controllerPath: string;
7
- }[];
8
- routesDir: string;
9
- openapiFile: string;
10
- compilerOptions: types.compilerOptions;
11
- }): Promise<void>;
@@ -1,11 +0,0 @@
1
- import * as types from "../../types/types";
2
- export default function routesTemplate(options: {
3
- template?: string;
4
- openapiFile?: string;
5
- routes: {
6
- route: string;
7
- documentName: string;
8
- controllerPath: string;
9
- }[];
10
- compilerOptions: types.compilerOptions;
11
- }): string;
@@ -1,2 +0,0 @@
1
- import * as types from "../../types/types";
2
- export declare function compile(compilerOptions: types.compilerOptions): string;
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import * as types from "./types/types";
2
- export declare function generate(options: types.compilerOptions): Promise<void>;