very-express 0.4.5 → 0.4.7
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 +1 -1
- package/dist/generators/controller/controller.template.d.ts +1 -1
- package/dist/generators/routes/routes.generator.d.ts +1 -1
- package/dist/generators/routes/routes.template.d.ts +1 -1
- package/dist/index.js +451 -500
- package/dist/templates/jsonSchema/User.json +0 -2
- package/dist/types/openapi.d.ts +1 -1
- package/dist/types/types.d.ts +0 -1
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/configChecker.d.ts +4 -0
- package/dist/utils/index.d.ts +30 -5
- package/docs/{defineJsonSchema.md → vexJsonSchema.md} +5 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/******/ (() => { // webpackBootstrap
|
|
1
|
+
#!/usr/bin/env node
|
|
3
2
|
/******/ var __webpack_modules__ = ({
|
|
4
3
|
|
|
5
4
|
/***/ 7721:
|
|
@@ -79618,14 +79617,14 @@ const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
|
79618
79617
|
const child_process_1 = __importDefault(__nccwpck_require__(2081));
|
|
79619
79618
|
const minimist_1 = __importDefault(__nccwpck_require__(5871));
|
|
79620
79619
|
const index_1 = __nccwpck_require__(6144);
|
|
79620
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
79621
79621
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
79622
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
79623
79622
|
function main() {
|
|
79624
79623
|
var _a;
|
|
79625
79624
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79626
79625
|
console.log("\x1b[35m%s\x1b[0m", "\n========== veryExpress CLI (vex) Start ==========\n");
|
|
79627
79626
|
const args = (0, minimist_1.default)(process.argv.slice(2));
|
|
79628
|
-
let config = utils_1.defaultCompilerOptions;
|
|
79627
|
+
let config = utils_1.default.generator.defaultCompilerOptions;
|
|
79629
79628
|
if (fs_1.default.existsSync("vex.config.json")) {
|
|
79630
79629
|
try {
|
|
79631
79630
|
config = JSON.parse(fs_1.default.readFileSync("vex.config.json", "utf8"));
|
|
@@ -79659,16 +79658,16 @@ function main() {
|
|
|
79659
79658
|
logger_1.default.warn("Not recommended to use \"useObjectID\" with \"allowApiCreateUpdate_id\",\nthis may cause some logic issues");
|
|
79660
79659
|
}
|
|
79661
79660
|
logger_1.default.process("validate vex.config.json");
|
|
79662
|
-
|
|
79661
|
+
utils_1.default.common.writeFile("vex.config", "vex.config.json", JSON.stringify(config, null, 4));
|
|
79663
79662
|
if (String(args._[0]).toLowerCase() === "h" || args["h"]) {
|
|
79664
|
-
logger_1.default.info(`Very Express CLI Usage :
|
|
79665
|
-
vex [flag]
|
|
79666
|
-
-h : Help
|
|
79667
|
-
-i : Create generator config etc.
|
|
79668
|
-
to generate app :
|
|
79669
|
-
vex [jsonSchemaDir] [rootDir]
|
|
79670
|
-
-j : jsonSchemaDir (configured: ${config.jsonSchemaDir})
|
|
79671
|
-
-o : rootDir (configured: ${config.rootDir})
|
|
79663
|
+
logger_1.default.info(`Very Express CLI Usage :
|
|
79664
|
+
vex [flag]
|
|
79665
|
+
-h : Help
|
|
79666
|
+
-i : Create generator config etc.
|
|
79667
|
+
to generate app :
|
|
79668
|
+
vex [jsonSchemaDir] [rootDir]
|
|
79669
|
+
-j : jsonSchemaDir (configured: ${config.jsonSchemaDir})
|
|
79670
|
+
-o : rootDir (configured: ${config.rootDir})
|
|
79672
79671
|
`);
|
|
79673
79672
|
process.exit(0);
|
|
79674
79673
|
}
|
|
@@ -79691,10 +79690,10 @@ function main() {
|
|
|
79691
79690
|
}
|
|
79692
79691
|
logger_1.default.process("generate with config", config);
|
|
79693
79692
|
yield (0, index_1.generate)(config);
|
|
79694
|
-
console.log(`next step:
|
|
79695
|
-
cd ${config.rootDir}
|
|
79696
|
-
npm install
|
|
79697
|
-
npm run dev
|
|
79693
|
+
console.log(`next step:
|
|
79694
|
+
cd ${config.rootDir}
|
|
79695
|
+
npm install
|
|
79696
|
+
npm run dev
|
|
79698
79697
|
`);
|
|
79699
79698
|
processEnd();
|
|
79700
79699
|
}
|
|
@@ -79734,9 +79733,8 @@ exports.compile = void 0;
|
|
|
79734
79733
|
const json_schema_to_openapi_schema_1 = __importDefault(__nccwpck_require__(2679));
|
|
79735
79734
|
const js_yaml_1 = __importDefault(__nccwpck_require__(1917));
|
|
79736
79735
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
79737
|
-
const
|
|
79736
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
79738
79737
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
79739
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
79740
79738
|
function compile(openapiOutFileName, compilerOptions) {
|
|
79741
79739
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79742
79740
|
let openapiJson = {
|
|
@@ -79765,7 +79763,7 @@ function compile(openapiOutFileName, compilerOptions) {
|
|
|
79765
79763
|
const validOpenApi = (0, json_schema_to_openapi_schema_1.default)(openapiJson, { version: 3.0 });
|
|
79766
79764
|
const openapiYaml = js_yaml_1.default.dump(validOpenApi);
|
|
79767
79765
|
const openapiOutFile = compilerOptions.openapiDir + openapiOutFileName;
|
|
79768
|
-
|
|
79766
|
+
utils_1.default.common.writeFile("OpenApi", openapiOutFile, openapiYaml);
|
|
79769
79767
|
return;
|
|
79770
79768
|
});
|
|
79771
79769
|
}
|
|
@@ -79773,30 +79771,30 @@ exports.compile = compile;
|
|
|
79773
79771
|
function jsonToOpenapiPath(openapiJson, jsonSchema, additionalinfo) {
|
|
79774
79772
|
const documentConfig = jsonSchema["x-documentConfig"];
|
|
79775
79773
|
const lowerDocName = documentConfig.documentName.toLowerCase();
|
|
79776
|
-
const
|
|
79774
|
+
const documentName = documentConfig.documentName;
|
|
79777
79775
|
const properties = jsonSchema.properties;
|
|
79778
79776
|
const routes = {
|
|
79779
79777
|
["/" + lowerDocName]: {
|
|
79780
79778
|
"x-collection": documentConfig.documentName,
|
|
79781
|
-
"x-
|
|
79779
|
+
"x-documentName": documentName,
|
|
79782
79780
|
},
|
|
79783
79781
|
["/" + lowerDocName + "/{id}"]: {
|
|
79784
79782
|
"x-collection": documentConfig.documentName,
|
|
79785
|
-
"x-
|
|
79783
|
+
"x-documentName": documentName,
|
|
79786
79784
|
},
|
|
79787
79785
|
};
|
|
79788
79786
|
documentConfig.methods.forEach((jsonSchemaMethod) => {
|
|
79789
79787
|
const routeWithId = ["get", "put", "patch", "delete"].includes(jsonSchemaMethod);
|
|
79790
79788
|
const useBody = ["post", "put", "patch"].includes(jsonSchemaMethod);
|
|
79791
79789
|
const route = "/" + lowerDocName + (routeWithId ? "/{id}" : "");
|
|
79792
|
-
const httpMethod =
|
|
79790
|
+
const httpMethod = utils_1.default.jsonSchema.httpMethod(jsonSchemaMethod, additionalinfo.jsonSchemaFilePath);
|
|
79793
79791
|
const parameters = [];
|
|
79794
79792
|
let requestBody = undefined;
|
|
79795
79793
|
const successResponse = {
|
|
79796
79794
|
200: {
|
|
79797
79795
|
description: "OK",
|
|
79798
79796
|
content: {
|
|
79799
|
-
"application/json": { schema: { $ref: `#/components/schemas/${httpMethod}${
|
|
79797
|
+
"application/json": { schema: { $ref: `#/components/schemas/${httpMethod}${documentName}Response` } },
|
|
79800
79798
|
},
|
|
79801
79799
|
},
|
|
79802
79800
|
};
|
|
@@ -79826,12 +79824,12 @@ function jsonToOpenapiPath(openapiJson, jsonSchema, additionalinfo) {
|
|
|
79826
79824
|
description: `${httpMethod} ${documentConfig.documentName}`,
|
|
79827
79825
|
required: false,
|
|
79828
79826
|
content: {
|
|
79829
|
-
"application/json": { schema: { $ref: `#/components/schemas/${httpMethod}${
|
|
79827
|
+
"application/json": { schema: { $ref: `#/components/schemas/${httpMethod}${documentName}Body` } },
|
|
79830
79828
|
},
|
|
79831
79829
|
};
|
|
79832
79830
|
}
|
|
79833
79831
|
routes[route][httpMethod] = {
|
|
79834
|
-
operationId: jsonSchemaMethod +
|
|
79832
|
+
operationId: jsonSchemaMethod + documentName,
|
|
79835
79833
|
tags: [lowerDocName],
|
|
79836
79834
|
parameters: parameters,
|
|
79837
79835
|
requestBody: requestBody,
|
|
@@ -79856,32 +79854,32 @@ function jsonToOpenapiComponentSchema(openapiJson, jsonSchema, additionalinfo, c
|
|
|
79856
79854
|
const componentSchemaPath = {};
|
|
79857
79855
|
const documentConfig = jsonSchema["x-documentConfig"];
|
|
79858
79856
|
const lowerDocName = documentConfig.documentName.toLowerCase();
|
|
79859
|
-
const
|
|
79857
|
+
const documentName = documentConfig.documentName;
|
|
79860
79858
|
const componentSchemaResponse = {
|
|
79861
79859
|
type: "object",
|
|
79862
|
-
properties: (0, json_schema_to_openapi_schema_1.default)(
|
|
79860
|
+
properties: (0, json_schema_to_openapi_schema_1.default)(utils_1.default.jsonSchema.cleanXcustomValue(jsonSchema.properties, ["index", "unique", "required"]), { version: 3.0 }),
|
|
79863
79861
|
};
|
|
79864
79862
|
const componentSchemaBodyRequired = {
|
|
79865
79863
|
type: "object",
|
|
79866
|
-
properties: (0, json_schema_to_openapi_schema_1.default)(
|
|
79864
|
+
properties: (0, json_schema_to_openapi_schema_1.default)(utils_1.default.jsonSchema.cleanXcustomValue(jsonSchema.properties, { index: "boolean", unique: "boolean", required: "boolean" }), { version: 3.0 }),
|
|
79867
79865
|
required: jsonSchema.required,
|
|
79868
79866
|
};
|
|
79869
79867
|
const componentSchemaBodyRequiredWithoutId = {
|
|
79870
79868
|
type: "object",
|
|
79871
|
-
properties: (0, json_schema_to_openapi_schema_1.default)(
|
|
79869
|
+
properties: (0, json_schema_to_openapi_schema_1.default)(utils_1.default.jsonSchema.cleanXcustomValue(componentSchemaBodyRequired.properties, { _id: "object" }), { version: 3.0 }),
|
|
79872
79870
|
required: jsonSchema.required,
|
|
79873
79871
|
};
|
|
79874
79872
|
const componentSchemaBody = {
|
|
79875
79873
|
type: "object",
|
|
79876
|
-
properties: (0, json_schema_to_openapi_schema_1.default)(
|
|
79874
|
+
properties: (0, json_schema_to_openapi_schema_1.default)(utils_1.default.jsonSchema.cleanXcustomValue(componentSchemaBodyRequiredWithoutId.properties, ["required"]), { version: 3.0 }),
|
|
79877
79875
|
};
|
|
79878
79876
|
documentConfig.methods.forEach((jsonSchemaMethod) => {
|
|
79879
|
-
const httpMethod =
|
|
79877
|
+
const httpMethod = utils_1.default.jsonSchema.httpMethod(jsonSchemaMethod, additionalinfo.jsonSchemaFilePath);
|
|
79880
79878
|
switch (jsonSchemaMethod) {
|
|
79881
79879
|
case "delete":
|
|
79882
79880
|
break;
|
|
79883
79881
|
case "get":
|
|
79884
|
-
componentSchemaPath[httpMethod +
|
|
79882
|
+
componentSchemaPath[httpMethod + documentName + "Response"] = componentSchemaResponse;
|
|
79885
79883
|
break;
|
|
79886
79884
|
case "getList": {
|
|
79887
79885
|
const parameters = [];
|
|
@@ -79928,24 +79926,24 @@ function jsonToOpenapiComponentSchema(openapiJson, jsonSchema, additionalinfo, c
|
|
|
79928
79926
|
}
|
|
79929
79927
|
});
|
|
79930
79928
|
openapiJson.paths["/" + lowerDocName][httpMethod].parameters = parameters;
|
|
79931
|
-
componentSchemaPath[httpMethod +
|
|
79932
|
-
componentSchemaPath[httpMethod +
|
|
79929
|
+
componentSchemaPath[httpMethod + documentName + "Response"] = componentSchemaResponse;
|
|
79930
|
+
componentSchemaPath[httpMethod + documentName + "ResponseList"] = {
|
|
79933
79931
|
type: "array",
|
|
79934
79932
|
items: componentSchemaResponse,
|
|
79935
79933
|
};
|
|
79936
79934
|
break;
|
|
79937
79935
|
}
|
|
79938
79936
|
case "patch":
|
|
79939
|
-
componentSchemaPath[httpMethod +
|
|
79940
|
-
componentSchemaPath[httpMethod +
|
|
79937
|
+
componentSchemaPath[httpMethod + documentName + "Body"] = componentSchemaBody;
|
|
79938
|
+
componentSchemaPath[httpMethod + documentName + "Response"] = componentSchemaResponse;
|
|
79941
79939
|
break;
|
|
79942
79940
|
case "post":
|
|
79943
|
-
componentSchemaPath[httpMethod +
|
|
79944
|
-
componentSchemaPath[httpMethod +
|
|
79941
|
+
componentSchemaPath[httpMethod + documentName + "Body"] = compilerOptions.app.allowApiCreateUpdate_id ? componentSchemaBodyRequired : componentSchemaBodyRequiredWithoutId;
|
|
79942
|
+
componentSchemaPath[httpMethod + documentName + "Response"] = componentSchemaResponse;
|
|
79945
79943
|
break;
|
|
79946
79944
|
case "put":
|
|
79947
|
-
componentSchemaPath[httpMethod +
|
|
79948
|
-
componentSchemaPath[httpMethod +
|
|
79945
|
+
componentSchemaPath[httpMethod + documentName + "Body"] = componentSchemaBodyRequired;
|
|
79946
|
+
componentSchemaPath[httpMethod + documentName + "Response"] = componentSchemaResponse;
|
|
79949
79947
|
break;
|
|
79950
79948
|
default:
|
|
79951
79949
|
break;
|
|
@@ -79981,23 +79979,23 @@ exports.compile = void 0;
|
|
|
79981
79979
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
79982
79980
|
const server_template_1 = __importDefault(__nccwpck_require__(1162));
|
|
79983
79981
|
const packageJson_generator_1 = __importDefault(__nccwpck_require__(3479));
|
|
79982
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
79984
79983
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
79985
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
79986
79984
|
function compile(compilerOptions) {
|
|
79987
79985
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79988
79986
|
const serverOutPath = compilerOptions.srcDir + "/server.ts";
|
|
79989
79987
|
const packageOutPath = compilerOptions.rootDir + "/package.json";
|
|
79990
79988
|
const envOutPath = compilerOptions.rootDir + "/.env";
|
|
79991
79989
|
const tsconfigOutPath = compilerOptions.rootDir + "/tsconfig.json";
|
|
79992
|
-
|
|
79990
|
+
utils_1.default.common.writeFile("Server", serverOutPath, (0, server_template_1.default)({
|
|
79993
79991
|
compilerOptions: compilerOptions,
|
|
79994
79992
|
}));
|
|
79995
79993
|
if (!fs_1.default.existsSync(envOutPath)) {
|
|
79996
|
-
logger_1.default.writing(`
|
|
79994
|
+
logger_1.default.writing(`Root : ${envOutPath}`);
|
|
79997
79995
|
fs_1.default.copyFileSync(__dirname + "/templates/root/.env", envOutPath);
|
|
79998
79996
|
}
|
|
79999
79997
|
if (!fs_1.default.existsSync(tsconfigOutPath)) {
|
|
80000
|
-
logger_1.default.writing(`
|
|
79998
|
+
logger_1.default.writing(`Root : ${tsconfigOutPath}`);
|
|
80001
79999
|
fs_1.default.copyFileSync(__dirname + "/templates/root/tsconfig.json", tsconfigOutPath);
|
|
80002
80000
|
}
|
|
80003
80001
|
packageJson_generator_1.default.compile(packageOutPath, compilerOptions);
|
|
@@ -80014,135 +80012,115 @@ exports.compile = compile;
|
|
|
80014
80012
|
|
|
80015
80013
|
"use strict";
|
|
80016
80014
|
|
|
80017
|
-
var
|
|
80018
|
-
|
|
80019
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
80020
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
80021
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
80022
|
-
}
|
|
80023
|
-
Object.defineProperty(o, k2, desc);
|
|
80024
|
-
}) : (function(o, m, k, k2) {
|
|
80025
|
-
if (k2 === undefined) k2 = k;
|
|
80026
|
-
o[k2] = m[k];
|
|
80027
|
-
}));
|
|
80028
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
80029
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
80030
|
-
}) : function(o, v) {
|
|
80031
|
-
o["default"] = v;
|
|
80032
|
-
});
|
|
80033
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
80034
|
-
if (mod && mod.__esModule) return mod;
|
|
80035
|
-
var result = {};
|
|
80036
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
80037
|
-
__setModuleDefault(result, mod);
|
|
80038
|
-
return result;
|
|
80015
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
80016
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80039
80017
|
};
|
|
80040
80018
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80041
|
-
const
|
|
80019
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
80042
80020
|
const importExpressSession = "import session from 'express-session';";
|
|
80043
80021
|
const importOAuthVerifyPlugin = "import oauthVerify from './system/_plugins/oauthVerify.gen';";
|
|
80044
80022
|
const importPassportGoogle = "import PassportGoogle from './system/_plugins/PassportGoogle.gen'";
|
|
80045
80023
|
const importSwaggerRouter = "import SwaggerRouter from './system/_routes/SwaggerRouter.gen';";
|
|
80046
80024
|
const importOAuthRouter = "import OAuthRouter from './system/_routes/OAuthRouter.gen';";
|
|
80047
|
-
const ConfigExpressSession = `
|
|
80048
|
-
const expressSessionConfig = {
|
|
80049
|
-
secret: 'your session secret',
|
|
80050
|
-
resave: false,
|
|
80051
|
-
saveUninitialized: false
|
|
80025
|
+
const ConfigExpressSession = `
|
|
80026
|
+
const expressSessionConfig = {
|
|
80027
|
+
secret: 'your session secret',
|
|
80028
|
+
resave: false,
|
|
80029
|
+
saveUninitialized: false
|
|
80052
80030
|
}`;
|
|
80053
80031
|
const ConfigSwaggerRouter = "const SwaggerRoute = new SwaggerRouter(); SwaggerRoute.initRoutes();";
|
|
80054
80032
|
const ConfigOAuthRouter = "const OAuthRoute = new OAuthRouter(); OAuthRoute.initRoutes();";
|
|
80055
|
-
const ConfigPassportGoogle = `
|
|
80056
|
-
const OAuthGoogle = new PassportGoogle({
|
|
80057
|
-
strategyConfig: {
|
|
80058
|
-
verify: oauthVerify
|
|
80059
|
-
}
|
|
80033
|
+
const ConfigPassportGoogle = `
|
|
80034
|
+
const OAuthGoogle = new PassportGoogle({
|
|
80035
|
+
strategyConfig: {
|
|
80036
|
+
verify: oauthVerify
|
|
80037
|
+
}
|
|
80060
80038
|
});`;
|
|
80061
80039
|
const UseSession = "app.use(session(expressSessionConfig));";
|
|
80062
|
-
const UsePassportGoogle = `
|
|
80063
|
-
await OAuthGoogle.passportSerializeUser();
|
|
80064
|
-
await OAuthGoogle.passportDeserializeUser();
|
|
80065
|
-
app.use(OAuthGoogle.passport.initialize());
|
|
80040
|
+
const UsePassportGoogle = `
|
|
80041
|
+
await OAuthGoogle.passportSerializeUser();
|
|
80042
|
+
await OAuthGoogle.passportDeserializeUser();
|
|
80043
|
+
app.use(OAuthGoogle.passport.initialize());
|
|
80066
80044
|
app.use(OAuthGoogle.passport.session());`;
|
|
80067
80045
|
const UseOAuthRouter = "app.use(OAuthRoute.router);";
|
|
80068
80046
|
const UseSwaggerRouter = "app.use(SwaggerRoute.router);";
|
|
80069
80047
|
const UseOAuthGoogleRouter = "app.use(OAuthGoogle.router);";
|
|
80070
80048
|
function serverTemplate(options) {
|
|
80071
|
-
let template = options.template || `${options.compilerOptions.headerComment || "// generated files by very-express"}
|
|
80072
|
-
|
|
80073
|
-
import express from 'express';
|
|
80074
|
-
import dotenv from 'dotenv';
|
|
80075
|
-
import helmet from 'helmet';
|
|
80076
|
-
import log from './system/_utils/logger.gen';
|
|
80077
|
-
import VexDbConnector from './system/_services/VexDbConnector.gen';
|
|
80078
|
-
|
|
80079
|
-
import ApiRouter from './system/_routes/ApiRouter.gen';
|
|
80080
|
-
{{Import}}
|
|
80081
|
-
|
|
80082
|
-
|
|
80083
|
-
/**
|
|
80084
|
-
* Configure
|
|
80085
|
-
*/
|
|
80086
|
-
dotenv.config();
|
|
80087
|
-
|
|
80088
|
-
const helmetConfig = {
|
|
80089
|
-
xPoweredBy: false,
|
|
80090
|
-
xDnsPrefetchControl: { allow: false },
|
|
80091
|
-
};
|
|
80092
|
-
|
|
80093
|
-
const vexDB = new VexDbConnector({
|
|
80094
|
-
mongoUrl: process.env.MONGODB_URI,
|
|
80095
|
-
});
|
|
80096
|
-
|
|
80097
|
-
|
|
80098
|
-
const ApiRoute = new ApiRouter(); ApiRoute.initRoutes();
|
|
80099
|
-
{{Config}}
|
|
80100
|
-
|
|
80101
|
-
|
|
80102
|
-
/**
|
|
80103
|
-
* App
|
|
80104
|
-
*/
|
|
80105
|
-
async function main(): Promise<void> {
|
|
80106
|
-
|
|
80107
|
-
const app = express();
|
|
80108
|
-
app.disable("x-powered-by");
|
|
80109
|
-
|
|
80110
|
-
// UseMiddleware
|
|
80111
|
-
app.use(express.json());
|
|
80112
|
-
app.use(helmet(helmetConfig));
|
|
80113
|
-
|
|
80114
|
-
// UsePlugins
|
|
80115
|
-
{{AppUse}}
|
|
80116
|
-
|
|
80117
|
-
// Routes
|
|
80118
|
-
{{AppRouter}}
|
|
80119
|
-
|
|
80120
|
-
app.use(ApiRoute.router);
|
|
80121
|
-
app.get('/', (req, res) => {
|
|
80122
|
-
res.send(\`
|
|
80123
|
-
<div>
|
|
80124
|
-
<h1>Hello World</h1>
|
|
80125
|
-
<ul>
|
|
80126
|
-
<li><a href="/login">login</a></li>
|
|
80127
|
-
<li><a href="/profile">profile</a></li>
|
|
80128
|
-
<li><a href="/logout">logout</a></li>
|
|
80129
|
-
<li><a href="/api">api</a></li>
|
|
80130
|
-
</ul>
|
|
80131
|
-
</div>
|
|
80132
|
-
\`);
|
|
80133
|
-
});
|
|
80134
|
-
|
|
80135
|
-
app.listen(3000, () => {
|
|
80136
|
-
if(!process.env.MONGODB_URI) throw new Error('MONGODB_URI is not defined');
|
|
80137
|
-
vexDB.connectMongo();
|
|
80138
|
-
log.ok(\`Server is running on : \${process.env.APP_HOST}\`);
|
|
80139
|
-
});
|
|
80140
|
-
|
|
80141
|
-
}
|
|
80142
|
-
|
|
80143
|
-
main();
|
|
80049
|
+
let template = options.template || `${options.compilerOptions.headerComment || "// generated files by very-express"}
|
|
80050
|
+
|
|
80051
|
+
import express from 'express';
|
|
80052
|
+
import dotenv from 'dotenv';
|
|
80053
|
+
import helmet from 'helmet';
|
|
80054
|
+
import log from './system/_utils/logger.gen';
|
|
80055
|
+
import VexDbConnector from './system/_services/VexDbConnector.gen';
|
|
80056
|
+
|
|
80057
|
+
import ApiRouter from './system/_routes/ApiRouter.gen';
|
|
80058
|
+
{{Import}}
|
|
80059
|
+
|
|
80060
|
+
|
|
80061
|
+
/**
|
|
80062
|
+
* Configure
|
|
80063
|
+
*/
|
|
80064
|
+
dotenv.config();
|
|
80065
|
+
|
|
80066
|
+
const helmetConfig = {
|
|
80067
|
+
xPoweredBy: false,
|
|
80068
|
+
xDnsPrefetchControl: { allow: false },
|
|
80069
|
+
};
|
|
80070
|
+
|
|
80071
|
+
const vexDB = new VexDbConnector({
|
|
80072
|
+
mongoUrl: process.env.MONGODB_URI,
|
|
80073
|
+
});
|
|
80074
|
+
|
|
80075
|
+
|
|
80076
|
+
const ApiRoute = new ApiRouter(); ApiRoute.initRoutes();
|
|
80077
|
+
{{Config}}
|
|
80078
|
+
|
|
80079
|
+
|
|
80080
|
+
/**
|
|
80081
|
+
* App
|
|
80082
|
+
*/
|
|
80083
|
+
async function main(): Promise<void> {
|
|
80084
|
+
|
|
80085
|
+
const app = express();
|
|
80086
|
+
app.disable("x-powered-by");
|
|
80087
|
+
|
|
80088
|
+
// UseMiddleware
|
|
80089
|
+
app.use(express.json());
|
|
80090
|
+
app.use(helmet(helmetConfig));
|
|
80091
|
+
|
|
80092
|
+
// UsePlugins
|
|
80093
|
+
{{AppUse}}
|
|
80094
|
+
|
|
80095
|
+
// Routes
|
|
80096
|
+
{{AppRouter}}
|
|
80097
|
+
|
|
80098
|
+
app.use(ApiRoute.router);
|
|
80099
|
+
app.get('/', (req, res) => {
|
|
80100
|
+
res.send(\`
|
|
80101
|
+
<div>
|
|
80102
|
+
<h1>Hello World</h1>
|
|
80103
|
+
<ul>
|
|
80104
|
+
<li><a href="/login">login</a></li>
|
|
80105
|
+
<li><a href="/profile">profile</a></li>
|
|
80106
|
+
<li><a href="/logout">logout</a></li>
|
|
80107
|
+
<li><a href="/api">api</a></li>
|
|
80108
|
+
</ul>
|
|
80109
|
+
</div>
|
|
80110
|
+
\`);
|
|
80111
|
+
});
|
|
80112
|
+
|
|
80113
|
+
app.listen(3000, () => {
|
|
80114
|
+
if(!process.env.MONGODB_URI) throw new Error('MONGODB_URI is not defined');
|
|
80115
|
+
vexDB.connectMongo();
|
|
80116
|
+
log.ok(\`Server is running on : \${process.env.APP_HOST}\`);
|
|
80117
|
+
});
|
|
80118
|
+
|
|
80119
|
+
}
|
|
80120
|
+
|
|
80121
|
+
main();
|
|
80144
80122
|
`;
|
|
80145
|
-
const usedProvider =
|
|
80123
|
+
const usedProvider = utils_1.default.generator.isUseOAuth(options.compilerOptions);
|
|
80146
80124
|
const Import = [];
|
|
80147
80125
|
const Config = [];
|
|
80148
80126
|
const AppUse = [];
|
|
@@ -80190,204 +80168,204 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
80190
80168
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80191
80169
|
const util_1 = __importDefault(__nccwpck_require__(3837));
|
|
80192
80170
|
function controllerTemplate(templateOptions) {
|
|
80193
|
-
let template = templateOptions.template || `{{headerComment}}
|
|
80194
|
-
import { Router, Request, Response } from 'express';
|
|
80195
|
-
|
|
80196
|
-
import { checkSchema, validationResult } from 'express-validator';
|
|
80197
|
-
import vex from "./../../system/_utils/index.gen";
|
|
80198
|
-
import MongoQS from 'mongo-ts-querystring';
|
|
80199
|
-
|
|
80200
|
-
import { {{
|
|
80201
|
-
|
|
80202
|
-
class {{
|
|
80203
|
-
public router: Router;
|
|
80204
|
-
|
|
80205
|
-
constructor() {
|
|
80206
|
-
this.router = Router();
|
|
80207
|
-
this.routes();
|
|
80208
|
-
}
|
|
80209
|
-
|
|
80210
|
-
public routes() {
|
|
80211
|
-
|
|
80212
|
-
{{getListRoute}}
|
|
80213
|
-
|
|
80214
|
-
{{getRoute}}
|
|
80215
|
-
|
|
80216
|
-
{{postRoute}}
|
|
80217
|
-
|
|
80218
|
-
{{putRoute}}
|
|
80219
|
-
|
|
80220
|
-
{{patchRoute}}
|
|
80221
|
-
|
|
80222
|
-
{{deleteRoute}}
|
|
80223
|
-
|
|
80224
|
-
};
|
|
80225
|
-
|
|
80226
|
-
public async get{{
|
|
80227
|
-
try {
|
|
80228
|
-
const validationError = validationResult(req);
|
|
80229
|
-
if ( ! validationError.isEmpty() ) {
|
|
80230
|
-
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80231
|
-
};
|
|
80232
|
-
|
|
80233
|
-
const result = await {{
|
|
80234
|
-
if (!result) {
|
|
80235
|
-
return vex.response.send(res, 404, vex.responseMsg.notFound);
|
|
80236
|
-
}
|
|
80237
|
-
else {
|
|
80238
|
-
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80239
|
-
};
|
|
80240
|
-
} catch (err:any) {
|
|
80241
|
-
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80242
|
-
}
|
|
80243
|
-
}
|
|
80244
|
-
|
|
80245
|
-
public async getList{{
|
|
80246
|
-
try {
|
|
80247
|
-
const validationError = validationResult(req);
|
|
80248
|
-
if ( ! validationError.isEmpty() ) {
|
|
80249
|
-
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80250
|
-
};
|
|
80251
|
-
|
|
80252
|
-
const searchFilter = new MongoQS().parse(req.query);
|
|
80253
|
-
let selectedFields : {[key: string]: number} | undefined = undefined;
|
|
80254
|
-
|
|
80255
|
-
try {
|
|
80256
|
-
selectedFields = vex.common.parseFieldsSelect(req.query.select || '');
|
|
80257
|
-
}
|
|
80258
|
-
catch (err:any) {
|
|
80259
|
-
return vex.response.send(res, 400, vex.responseMsg.queryError, { error: err.message });
|
|
80260
|
-
};
|
|
80261
|
-
|
|
80262
|
-
const result = await {{
|
|
80263
|
-
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80264
|
-
} catch (err:any) {
|
|
80265
|
-
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80266
|
-
}
|
|
80267
|
-
}
|
|
80268
|
-
|
|
80269
|
-
public async create{{
|
|
80270
|
-
try {
|
|
80271
|
-
const validationError = validationResult(req);
|
|
80272
|
-
if ( ! validationError.isEmpty() ) {
|
|
80273
|
-
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80274
|
-
};{{check_id}}
|
|
80275
|
-
|
|
80276
|
-
const result = await {{
|
|
80277
|
-
if (!result) {
|
|
80278
|
-
return vex.response.send(res, 400, vex.responseMsg.createFail);
|
|
80279
|
-
}
|
|
80280
|
-
else {
|
|
80281
|
-
return vex.response.send(res, 201, vex.responseMsg.ok, result);
|
|
80282
|
-
};
|
|
80283
|
-
} catch (err:any) {
|
|
80284
|
-
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80285
|
-
};
|
|
80286
|
-
};
|
|
80287
|
-
|
|
80288
|
-
public async update{{
|
|
80289
|
-
try {
|
|
80290
|
-
const validationError = validationResult(req);
|
|
80291
|
-
if ( ! validationError.isEmpty() ) {
|
|
80292
|
-
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80293
|
-
};{{check_id}}
|
|
80294
|
-
|
|
80295
|
-
const result = await {{
|
|
80296
|
-
if (!result) {
|
|
80297
|
-
return vex.response.send(res, 404, vex.responseMsg.updateFail);
|
|
80298
|
-
}
|
|
80299
|
-
else {
|
|
80300
|
-
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80301
|
-
};
|
|
80302
|
-
} catch (err:any) {
|
|
80303
|
-
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80304
|
-
}
|
|
80305
|
-
}
|
|
80306
|
-
|
|
80307
|
-
public async replace{{
|
|
80308
|
-
try {
|
|
80309
|
-
const validationError = validationResult(req);
|
|
80310
|
-
if ( ! validationError.isEmpty() ) {
|
|
80311
|
-
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80312
|
-
};{{check_id}}
|
|
80313
|
-
|
|
80314
|
-
const result = await {{
|
|
80315
|
-
if (!result) {
|
|
80316
|
-
return vex.response.send(res, 404, vex.responseMsg.updateFail);
|
|
80317
|
-
}
|
|
80318
|
-
else {
|
|
80319
|
-
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80320
|
-
};
|
|
80321
|
-
} catch (err:any) {
|
|
80322
|
-
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80323
|
-
}
|
|
80324
|
-
}
|
|
80325
|
-
|
|
80326
|
-
public async delete{{
|
|
80327
|
-
try {
|
|
80328
|
-
const validationError = validationResult(req);
|
|
80329
|
-
if ( ! validationError.isEmpty() ) {
|
|
80330
|
-
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80331
|
-
};
|
|
80332
|
-
|
|
80333
|
-
const result = await {{
|
|
80334
|
-
if (!result) {
|
|
80335
|
-
return vex.response.send(res, 404, vex.responseMsg.deleteFail);
|
|
80336
|
-
}
|
|
80337
|
-
else {
|
|
80338
|
-
return vex.response.send(res, 204, vex.responseMsg.ok, result);
|
|
80339
|
-
};
|
|
80340
|
-
} catch (err:any) {
|
|
80341
|
-
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80342
|
-
}
|
|
80343
|
-
}
|
|
80344
|
-
}
|
|
80345
|
-
|
|
80346
|
-
export default new {{
|
|
80171
|
+
let template = templateOptions.template || `{{headerComment}}
|
|
80172
|
+
import { Router, Request, Response } from 'express';
|
|
80173
|
+
|
|
80174
|
+
import { checkSchema, validationResult } from 'express-validator';
|
|
80175
|
+
import vex from "./../../system/_utils/index.gen";
|
|
80176
|
+
import MongoQS from 'mongo-ts-querystring';
|
|
80177
|
+
|
|
80178
|
+
import { {{documentName}}Model } from '{{modelPath}}';
|
|
80179
|
+
|
|
80180
|
+
class {{documentName}}Controller {
|
|
80181
|
+
public router: Router;
|
|
80182
|
+
|
|
80183
|
+
constructor() {
|
|
80184
|
+
this.router = Router();
|
|
80185
|
+
this.routes();
|
|
80186
|
+
}
|
|
80187
|
+
|
|
80188
|
+
public routes() {
|
|
80189
|
+
|
|
80190
|
+
{{getListRoute}}
|
|
80191
|
+
|
|
80192
|
+
{{getRoute}}
|
|
80193
|
+
|
|
80194
|
+
{{postRoute}}
|
|
80195
|
+
|
|
80196
|
+
{{putRoute}}
|
|
80197
|
+
|
|
80198
|
+
{{patchRoute}}
|
|
80199
|
+
|
|
80200
|
+
{{deleteRoute}}
|
|
80201
|
+
|
|
80202
|
+
};
|
|
80203
|
+
|
|
80204
|
+
public async get{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
80205
|
+
try {
|
|
80206
|
+
const validationError = validationResult(req);
|
|
80207
|
+
if ( ! validationError.isEmpty() ) {
|
|
80208
|
+
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80209
|
+
};
|
|
80210
|
+
|
|
80211
|
+
const result = await {{documentName}}Model.findById(req.params.id);
|
|
80212
|
+
if (!result) {
|
|
80213
|
+
return vex.response.send(res, 404, vex.responseMsg.notFound);
|
|
80214
|
+
}
|
|
80215
|
+
else {
|
|
80216
|
+
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80217
|
+
};
|
|
80218
|
+
} catch (err:any) {
|
|
80219
|
+
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80220
|
+
}
|
|
80221
|
+
}
|
|
80222
|
+
|
|
80223
|
+
public async getList{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
80224
|
+
try {
|
|
80225
|
+
const validationError = validationResult(req);
|
|
80226
|
+
if ( ! validationError.isEmpty() ) {
|
|
80227
|
+
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80228
|
+
};
|
|
80229
|
+
|
|
80230
|
+
const searchFilter = new MongoQS().parse(req.query);
|
|
80231
|
+
let selectedFields : {[key: string]: number} | undefined = undefined;
|
|
80232
|
+
|
|
80233
|
+
try {
|
|
80234
|
+
selectedFields = vex.common.parseFieldsSelect(req.query.select || '');
|
|
80235
|
+
}
|
|
80236
|
+
catch (err:any) {
|
|
80237
|
+
return vex.response.send(res, 400, vex.responseMsg.queryError, { error: err.message });
|
|
80238
|
+
};
|
|
80239
|
+
|
|
80240
|
+
const result = await {{documentName}}Model.find(searchFilter, selectedFields);
|
|
80241
|
+
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80242
|
+
} catch (err:any) {
|
|
80243
|
+
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80244
|
+
}
|
|
80245
|
+
}
|
|
80246
|
+
|
|
80247
|
+
public async create{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
80248
|
+
try {
|
|
80249
|
+
const validationError = validationResult(req);
|
|
80250
|
+
if ( ! validationError.isEmpty() ) {
|
|
80251
|
+
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80252
|
+
};{{check_id}}
|
|
80253
|
+
|
|
80254
|
+
const result = await {{documentName}}Model.create(req.body);
|
|
80255
|
+
if (!result) {
|
|
80256
|
+
return vex.response.send(res, 400, vex.responseMsg.createFail);
|
|
80257
|
+
}
|
|
80258
|
+
else {
|
|
80259
|
+
return vex.response.send(res, 201, vex.responseMsg.ok, result);
|
|
80260
|
+
};
|
|
80261
|
+
} catch (err:any) {
|
|
80262
|
+
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80263
|
+
};
|
|
80264
|
+
};
|
|
80265
|
+
|
|
80266
|
+
public async update{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
80267
|
+
try {
|
|
80268
|
+
const validationError = validationResult(req);
|
|
80269
|
+
if ( ! validationError.isEmpty() ) {
|
|
80270
|
+
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80271
|
+
};{{check_id}}
|
|
80272
|
+
|
|
80273
|
+
const result = await {{documentName}}Model.findByIdAndUpdate(req.params.id, req.body, { new: true });
|
|
80274
|
+
if (!result) {
|
|
80275
|
+
return vex.response.send(res, 404, vex.responseMsg.updateFail);
|
|
80276
|
+
}
|
|
80277
|
+
else {
|
|
80278
|
+
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80279
|
+
};
|
|
80280
|
+
} catch (err:any) {
|
|
80281
|
+
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80282
|
+
}
|
|
80283
|
+
}
|
|
80284
|
+
|
|
80285
|
+
public async replace{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
80286
|
+
try {
|
|
80287
|
+
const validationError = validationResult(req);
|
|
80288
|
+
if ( ! validationError.isEmpty() ) {
|
|
80289
|
+
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80290
|
+
};{{check_id}}
|
|
80291
|
+
|
|
80292
|
+
const result = await {{documentName}}Model.replaceOne({_id: req.params.id}, req.body);
|
|
80293
|
+
if (!result) {
|
|
80294
|
+
return vex.response.send(res, 404, vex.responseMsg.updateFail);
|
|
80295
|
+
}
|
|
80296
|
+
else {
|
|
80297
|
+
return vex.response.send(res, 200, vex.responseMsg.ok, result);
|
|
80298
|
+
};
|
|
80299
|
+
} catch (err:any) {
|
|
80300
|
+
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80301
|
+
}
|
|
80302
|
+
}
|
|
80303
|
+
|
|
80304
|
+
public async delete{{documentName}}(req: Request, res: Response): Promise<Response> {
|
|
80305
|
+
try {
|
|
80306
|
+
const validationError = validationResult(req);
|
|
80307
|
+
if ( ! validationError.isEmpty() ) {
|
|
80308
|
+
return vex.response.send(res, 400, vex.responseMsg.validateError, validationError.array());
|
|
80309
|
+
};
|
|
80310
|
+
|
|
80311
|
+
const result = await {{documentName}}Model.findByIdAndDelete(req.params.id);
|
|
80312
|
+
if (!result) {
|
|
80313
|
+
return vex.response.send(res, 404, vex.responseMsg.deleteFail);
|
|
80314
|
+
}
|
|
80315
|
+
else {
|
|
80316
|
+
return vex.response.send(res, 204, vex.responseMsg.ok, result);
|
|
80317
|
+
};
|
|
80318
|
+
} catch (err:any) {
|
|
80319
|
+
return vex.response.send(res, 500, vex.responseMsg.unexpectedError, { error: err.message });
|
|
80320
|
+
}
|
|
80321
|
+
}
|
|
80322
|
+
}
|
|
80323
|
+
|
|
80324
|
+
export default new {{documentName}}Controller().router;
|
|
80347
80325
|
`;
|
|
80348
80326
|
const indent3 = " ";
|
|
80349
80327
|
template = template.replace(/{{headerComment}}/g, templateOptions.compilerOptions.headerComment || "// generated files by very-express");
|
|
80350
|
-
template = template.replace(/{{
|
|
80328
|
+
template = template.replace(/{{documentName}}/g, templateOptions.documentName);
|
|
80351
80329
|
template = template.replace(/{{modelPath}}/g, templateOptions.modelPath);
|
|
80352
|
-
template = template.replace(/{{getListRoute}}/g, !templateOptions.validators[templateOptions.endpoint].get ? `
|
|
80353
|
-
// getListRoute disabled` : `
|
|
80354
|
-
this.router.get('/',
|
|
80355
|
-
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint].get, { depth: null }).replace(/^/gm, indent3)}),
|
|
80356
|
-
this.getList${templateOptions.
|
|
80330
|
+
template = template.replace(/{{getListRoute}}/g, !templateOptions.validators[templateOptions.endpoint].get ? `
|
|
80331
|
+
// getListRoute disabled` : `
|
|
80332
|
+
this.router.get('/',
|
|
80333
|
+
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint].get, { depth: null }).replace(/^/gm, indent3)}),
|
|
80334
|
+
this.getList${templateOptions.documentName}.bind(this)
|
|
80357
80335
|
);`);
|
|
80358
|
-
template = template.replace(/{{getRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].get ? `
|
|
80359
|
-
// getRoute disabled` : `
|
|
80360
|
-
this.router.get('/:id',
|
|
80361
|
-
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].get, { depth: null }).replace(/^/gm, indent3)}),
|
|
80362
|
-
this.get${templateOptions.
|
|
80336
|
+
template = template.replace(/{{getRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].get ? `
|
|
80337
|
+
// getRoute disabled` : `
|
|
80338
|
+
this.router.get('/:id',
|
|
80339
|
+
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].get, { depth: null }).replace(/^/gm, indent3)}),
|
|
80340
|
+
this.get${templateOptions.documentName}.bind(this)
|
|
80363
80341
|
);`);
|
|
80364
|
-
template = template.replace(/{{postRoute}}/g, !templateOptions.validators[templateOptions.endpoint].post ? `
|
|
80365
|
-
// postRoute disabled` : `
|
|
80366
|
-
this.router.post('/',
|
|
80367
|
-
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint].post, { depth: null }).replace(/^/gm, indent3)}),
|
|
80368
|
-
this.create${templateOptions.
|
|
80342
|
+
template = template.replace(/{{postRoute}}/g, !templateOptions.validators[templateOptions.endpoint].post ? `
|
|
80343
|
+
// postRoute disabled` : `
|
|
80344
|
+
this.router.post('/',
|
|
80345
|
+
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint].post, { depth: null }).replace(/^/gm, indent3)}),
|
|
80346
|
+
this.create${templateOptions.documentName}.bind(this)
|
|
80369
80347
|
);`);
|
|
80370
|
-
template = template.replace(/{{putRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].put ? `
|
|
80371
|
-
// putRoute disabled` : `
|
|
80372
|
-
this.router.put('/:id',
|
|
80373
|
-
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].put, { depth: null }).replace(/^/gm, indent3)}),
|
|
80374
|
-
this.replace${templateOptions.
|
|
80348
|
+
template = template.replace(/{{putRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].put ? `
|
|
80349
|
+
// putRoute disabled` : `
|
|
80350
|
+
this.router.put('/:id',
|
|
80351
|
+
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].put, { depth: null }).replace(/^/gm, indent3)}),
|
|
80352
|
+
this.replace${templateOptions.documentName}.bind(this)
|
|
80375
80353
|
);`);
|
|
80376
|
-
template = template.replace(/{{patchRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].patch ? `
|
|
80377
|
-
// patchRoute disabled` : `
|
|
80378
|
-
this.router.patch('/:id',
|
|
80379
|
-
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].patch, { depth: null }).replace(/^/gm, indent3)}),
|
|
80380
|
-
this.update${templateOptions.
|
|
80354
|
+
template = template.replace(/{{patchRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].patch ? `
|
|
80355
|
+
// patchRoute disabled` : `
|
|
80356
|
+
this.router.patch('/:id',
|
|
80357
|
+
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].patch, { depth: null }).replace(/^/gm, indent3)}),
|
|
80358
|
+
this.update${templateOptions.documentName}.bind(this)
|
|
80381
80359
|
);`);
|
|
80382
|
-
template = template.replace(/{{deleteRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].delete ? `
|
|
80383
|
-
// deleteRoute disabled` : `
|
|
80384
|
-
this.router.delete('/:id',
|
|
80385
|
-
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].delete, { depth: null }).replace(/^/gm, indent3)}),
|
|
80386
|
-
this.delete${templateOptions.
|
|
80360
|
+
template = template.replace(/{{deleteRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].delete ? `
|
|
80361
|
+
// deleteRoute disabled` : `
|
|
80362
|
+
this.router.delete('/:id',
|
|
80363
|
+
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].delete, { depth: null }).replace(/^/gm, indent3)}),
|
|
80364
|
+
this.delete${templateOptions.documentName}.bind(this)
|
|
80387
80365
|
);`);
|
|
80388
|
-
template = template.replace(/{{check_id}}/g, templateOptions.compilerOptions.app.allowApiCreateUpdate_id ? "" : `
|
|
80389
|
-
if (req.body._id) {
|
|
80390
|
-
delete req.body._id;
|
|
80366
|
+
template = template.replace(/{{check_id}}/g, templateOptions.compilerOptions.app.allowApiCreateUpdate_id ? "" : `
|
|
80367
|
+
if (req.body._id) {
|
|
80368
|
+
delete req.body._id;
|
|
80391
80369
|
};`);
|
|
80392
80370
|
return template;
|
|
80393
80371
|
}
|
|
@@ -80441,13 +80419,13 @@ exports.compile = void 0;
|
|
|
80441
80419
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
80442
80420
|
const js_yaml_1 = __importDefault(__nccwpck_require__(1917));
|
|
80443
80421
|
const controller_template_1 = __importDefault(__nccwpck_require__(9737));
|
|
80422
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
80444
80423
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
80445
|
-
const common_1 = __nccwpck_require__(3851);
|
|
80446
80424
|
const types = __importStar(__nccwpck_require__(1456));
|
|
80447
80425
|
function compile(options) {
|
|
80448
80426
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80449
80427
|
const file = fs_1.default.readFileSync(options.compilerOptions.openapiDir + "/" + options.openapiFile, "utf8");
|
|
80450
|
-
const controllerToModelBasePath =
|
|
80428
|
+
const controllerToModelBasePath = utils_1.default.common.relativePath(options.compilerOptions.sysDir, options.modelDir);
|
|
80451
80429
|
const openApi = js_yaml_1.default.load(file);
|
|
80452
80430
|
const endpointsValidator = {};
|
|
80453
80431
|
const writtedEndpoint = [];
|
|
@@ -80464,26 +80442,21 @@ function compile(options) {
|
|
|
80464
80442
|
});
|
|
80465
80443
|
Object.keys(openApi.paths).forEach((endpoint) => {
|
|
80466
80444
|
const documentName = openApi.paths[endpoint]["x-collection"];
|
|
80467
|
-
const interfaceName = openApi.paths[endpoint]["x-interface"];
|
|
80468
80445
|
const endpointFormatted = endpoint.replace("/{id}", "").toLowerCase();
|
|
80469
80446
|
if (documentName === undefined) {
|
|
80470
80447
|
logger_1.default.error(`"x-collection" not found in openapi spec's path "${endpoint}"\n - opanapi source: ${options.compilerOptions.openapiDir}`);
|
|
80471
80448
|
return;
|
|
80472
80449
|
}
|
|
80473
|
-
else if (interfaceName === undefined) {
|
|
80474
|
-
logger_1.default.error(`"x-interface" not found in openapi spec's path "${endpoint}"\n - opanapi source: ${options.compilerOptions.openapiDir}`);
|
|
80475
|
-
return;
|
|
80476
|
-
}
|
|
80477
80450
|
else if (writtedEndpoint.includes(endpointFormatted)) {
|
|
80478
80451
|
return;
|
|
80479
80452
|
}
|
|
80480
80453
|
else {
|
|
80481
|
-
const outPath = `${options.controllerOutDir}/${
|
|
80482
|
-
const controllerToModelPath = `../${controllerToModelBasePath}/${
|
|
80483
|
-
|
|
80454
|
+
const outPath = `${options.controllerOutDir}/${documentName}Controller.gen.ts`;
|
|
80455
|
+
const controllerToModelPath = `../${controllerToModelBasePath}/${documentName}Model.gen`;
|
|
80456
|
+
utils_1.default.common.writeFile("Controller", outPath, (0, controller_template_1.default)({
|
|
80484
80457
|
endpoint: endpoint,
|
|
80485
80458
|
modelPath: controllerToModelPath,
|
|
80486
|
-
|
|
80459
|
+
documentName: documentName,
|
|
80487
80460
|
validators: endpointsValidator,
|
|
80488
80461
|
compilerOptions: options.compilerOptions,
|
|
80489
80462
|
}));
|
|
@@ -80610,8 +80583,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
80610
80583
|
exports.compile = void 0;
|
|
80611
80584
|
const RBACmiddlewares_template_1 = __importDefault(__nccwpck_require__(7573));
|
|
80612
80585
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
80586
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
80613
80587
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
80614
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
80615
80588
|
function compile(options) {
|
|
80616
80589
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80617
80590
|
logger_1.default.process("RBAC Middleware");
|
|
@@ -80619,7 +80592,7 @@ function compile(options) {
|
|
|
80619
80592
|
fs_1.default.mkdirSync(options.middlewareDir);
|
|
80620
80593
|
}
|
|
80621
80594
|
const middlewareFilePath = `${options.middlewareDir}/RoleBaseAccessControl.gen.ts`;
|
|
80622
|
-
|
|
80595
|
+
utils_1.default.common.writeFile("RBAC Middleware", middlewareFilePath, (0, RBACmiddlewares_template_1.default)({
|
|
80623
80596
|
roleTypes: options.roleTypes,
|
|
80624
80597
|
compilerOptions: options.compilerOptions,
|
|
80625
80598
|
}));
|
|
@@ -80686,12 +80659,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
80686
80659
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80687
80660
|
exports.compile = void 0;
|
|
80688
80661
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
80689
|
-
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
80690
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
80691
80662
|
const package_json_1 = __importDefault(__nccwpck_require__(1360));
|
|
80663
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
80664
|
+
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
80692
80665
|
function compile(packageOutPath, compilerOptions) {
|
|
80693
80666
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80694
|
-
logger_1.default.process(`
|
|
80667
|
+
logger_1.default.process(`Root : ${packageOutPath}`);
|
|
80695
80668
|
let packjson = "";
|
|
80696
80669
|
if (!fs_1.default.existsSync(packageOutPath)) {
|
|
80697
80670
|
packjson = JSON.stringify(package_json_1.default);
|
|
@@ -80712,7 +80685,7 @@ function compile(packageOutPath, compilerOptions) {
|
|
|
80712
80685
|
logger_1.default.process(`package.json : Update script : start > ${packageJson.scripts.start}`);
|
|
80713
80686
|
packageJson.scripts.start = "node ./dist/server.js";
|
|
80714
80687
|
}
|
|
80715
|
-
|
|
80688
|
+
utils_1.default.common.writeFile(`ROOT : ${packageOutPath}`, packageOutPath, JSON.stringify(packageJson, null, 4));
|
|
80716
80689
|
return;
|
|
80717
80690
|
});
|
|
80718
80691
|
}
|
|
@@ -80743,8 +80716,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
80743
80716
|
};
|
|
80744
80717
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80745
80718
|
exports.compile = void 0;
|
|
80719
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
80746
80720
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
80747
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
80748
80721
|
function compile(options) {
|
|
80749
80722
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80750
80723
|
if (!options.compilerOptions.app.useUserSchema) {
|
|
@@ -80752,8 +80725,8 @@ function compile(options) {
|
|
|
80752
80725
|
}
|
|
80753
80726
|
logger_1.default.process("UserSchmea");
|
|
80754
80727
|
const schemaOutPath = `${options.compilerOptions.jsonSchemaDir}/User.json`;
|
|
80755
|
-
const templateSchema =
|
|
80756
|
-
const userSchema =
|
|
80728
|
+
const templateSchema = utils_1.default.common.loadJson(__dirname + "/templates/jsonSchema/User.json");
|
|
80729
|
+
const userSchema = utils_1.default.common.loadJson(schemaOutPath, () => {
|
|
80757
80730
|
return templateSchema;
|
|
80758
80731
|
});
|
|
80759
80732
|
Object.keys(templateSchema.properties).forEach((key) => {
|
|
@@ -80765,7 +80738,7 @@ function compile(options) {
|
|
|
80765
80738
|
}
|
|
80766
80739
|
}
|
|
80767
80740
|
});
|
|
80768
|
-
|
|
80741
|
+
utils_1.default.common.writeFile("UserSchmea", schemaOutPath, JSON.stringify(userSchema, null, 4));
|
|
80769
80742
|
return;
|
|
80770
80743
|
});
|
|
80771
80744
|
}
|
|
@@ -80818,8 +80791,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
80818
80791
|
exports.compile = void 0;
|
|
80819
80792
|
const role_template_1 = __importDefault(__nccwpck_require__(224));
|
|
80820
80793
|
const roleBase = __importStar(__nccwpck_require__(735));
|
|
80794
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
80821
80795
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
80822
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
80823
80796
|
const roleSetupFile_1 = __nccwpck_require__(6669);
|
|
80824
80797
|
const RBACmiddlewareGen = __importStar(__nccwpck_require__(5782));
|
|
80825
80798
|
function compile(options) {
|
|
@@ -80839,7 +80812,7 @@ function compile(options) {
|
|
|
80839
80812
|
const RoleAccessAction = [];
|
|
80840
80813
|
const roleSrcFile = `${options.compilerOptions.srcDir}/roles/${role}.json`;
|
|
80841
80814
|
const roleOutFile = `${options.roleOutDir}/${role}.gen.ts`;
|
|
80842
|
-
const roleContent =
|
|
80815
|
+
const roleContent = utils_1.default.common.loadJson(roleSrcFile);
|
|
80843
80816
|
Object.values(roleContent).forEach((resourceContent) => {
|
|
80844
80817
|
if (Array.isArray(resourceContent)) {
|
|
80845
80818
|
resourceContent.forEach((action) => {
|
|
@@ -80851,7 +80824,7 @@ function compile(options) {
|
|
|
80851
80824
|
});
|
|
80852
80825
|
const RoleAccessActionString = Object.keys(RoleAccessAction).map((key) => `"${key}"`);
|
|
80853
80826
|
RoleAccessActionString.push("roleFactory.accessAction");
|
|
80854
|
-
|
|
80827
|
+
utils_1.default.common.writeFile("RBAC Role", roleOutFile, (0, role_template_1.default)({
|
|
80855
80828
|
role: role,
|
|
80856
80829
|
roleContent: roleContent,
|
|
80857
80830
|
RoleAccessActionString: RoleAccessActionString,
|
|
@@ -80864,7 +80837,7 @@ function compile(options) {
|
|
|
80864
80837
|
});
|
|
80865
80838
|
const indexFilePath = `${options.roleOutDir}/index.ts`;
|
|
80866
80839
|
const indexFileContent = indexFileData.map((data) => `export { default as ${data.name} } from "./${data.name}.gen";`).join("\n");
|
|
80867
|
-
|
|
80840
|
+
utils_1.default.common.writeFile("RBAC Index", indexFilePath, `${options.compilerOptions.headerComment}\n${indexFileContent}`);
|
|
80868
80841
|
const roleTypesString = indexFileData.map((data) => `Role${data.name}`).join(" | ");
|
|
80869
80842
|
RBACmiddlewareGen.compile({
|
|
80870
80843
|
middlewareDir: options.middlewareDir,
|
|
@@ -81043,22 +81016,21 @@ exports.compile = void 0;
|
|
|
81043
81016
|
const routes_template_1 = __importDefault(__nccwpck_require__(8264));
|
|
81044
81017
|
const routesOAuthGen = __importStar(__nccwpck_require__(2061));
|
|
81045
81018
|
const routesSwaggerGen = __importStar(__nccwpck_require__(8241));
|
|
81046
|
-
const
|
|
81019
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
81047
81020
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
81048
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
81049
81021
|
function compile(options) {
|
|
81050
81022
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81051
81023
|
logger_1.default.process("Route");
|
|
81052
81024
|
const routesApiOutPath = `${options.routesDir}/ApiRouter.gen.ts`;
|
|
81053
81025
|
const routesOAuthOutPath = `${options.routesDir}/OAuthRouter.gen.ts`;
|
|
81054
81026
|
const routesSwaggerOutPath = `${options.routesDir}/SwaggerRouter.gen.ts`;
|
|
81055
|
-
if (
|
|
81056
|
-
|
|
81027
|
+
if (utils_1.default.generator.isUseOAuth(options.compilerOptions).length > 0) {
|
|
81028
|
+
utils_1.default.common.writeFile("Route OAuth", routesOAuthOutPath, routesOAuthGen.compile(options.compilerOptions));
|
|
81057
81029
|
}
|
|
81058
81030
|
if (options.compilerOptions.app.enableSwagger) {
|
|
81059
|
-
|
|
81031
|
+
utils_1.default.common.writeFile("Route Swagger", routesSwaggerOutPath, routesSwaggerGen.compile(options.compilerOptions));
|
|
81060
81032
|
}
|
|
81061
|
-
|
|
81033
|
+
utils_1.default.common.writeFile("Route API", routesApiOutPath, (0, routes_template_1.default)({
|
|
81062
81034
|
routes: options.routesArr,
|
|
81063
81035
|
openapiFile: options.openapiFile,
|
|
81064
81036
|
compilerOptions: options.compilerOptions,
|
|
@@ -81078,28 +81050,28 @@ exports.compile = compile;
|
|
|
81078
81050
|
|
|
81079
81051
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
81080
81052
|
function routesTemplate(options) {
|
|
81081
|
-
let template = options.template || `{{headerComment}}
|
|
81082
|
-
import { Router } from 'express';
|
|
81083
|
-
|
|
81084
|
-
{{importRoutes}}
|
|
81085
|
-
|
|
81086
|
-
export default class ApiRouter{
|
|
81087
|
-
|
|
81088
|
-
public router: Router = Router();
|
|
81089
|
-
|
|
81090
|
-
constructor() {}
|
|
81091
|
-
|
|
81092
|
-
public initRoutes() {
|
|
81093
|
-
|
|
81094
|
-
{{useRoutes}}
|
|
81095
|
-
}
|
|
81096
|
-
|
|
81053
|
+
let template = options.template || `{{headerComment}}
|
|
81054
|
+
import { Router } from 'express';
|
|
81055
|
+
|
|
81056
|
+
{{importRoutes}}
|
|
81057
|
+
|
|
81058
|
+
export default class ApiRouter{
|
|
81059
|
+
|
|
81060
|
+
public router: Router = Router();
|
|
81061
|
+
|
|
81062
|
+
constructor() {}
|
|
81063
|
+
|
|
81064
|
+
public initRoutes() {
|
|
81065
|
+
|
|
81066
|
+
{{useRoutes}}
|
|
81067
|
+
}
|
|
81068
|
+
|
|
81097
81069
|
}`;
|
|
81098
81070
|
let importRoutes = "";
|
|
81099
81071
|
let useRoutes = "";
|
|
81100
81072
|
options.routes.forEach((obj) => {
|
|
81101
|
-
importRoutes += `import ${obj.
|
|
81102
|
-
useRoutes += ` this.router.use('${obj.route}', ${obj.
|
|
81073
|
+
importRoutes += `import ${obj.documentName}Controller from '${obj.controllerPath}';\n`;
|
|
81074
|
+
useRoutes += ` this.router.use('${obj.route}', ${obj.documentName}Controller);\n`;
|
|
81103
81075
|
});
|
|
81104
81076
|
template = template.replace(/{{headerComment}}/g, options.compilerOptions.headerComment || "// generated files by very-express");
|
|
81105
81077
|
template = template.replace(/{{importRoutes}}/g, importRoutes);
|
|
@@ -81116,48 +81088,28 @@ exports["default"] = routesTemplate;
|
|
|
81116
81088
|
|
|
81117
81089
|
"use strict";
|
|
81118
81090
|
|
|
81119
|
-
var
|
|
81120
|
-
|
|
81121
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
81122
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
81123
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
81124
|
-
}
|
|
81125
|
-
Object.defineProperty(o, k2, desc);
|
|
81126
|
-
}) : (function(o, m, k, k2) {
|
|
81127
|
-
if (k2 === undefined) k2 = k;
|
|
81128
|
-
o[k2] = m[k];
|
|
81129
|
-
}));
|
|
81130
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
81131
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
81132
|
-
}) : function(o, v) {
|
|
81133
|
-
o["default"] = v;
|
|
81134
|
-
});
|
|
81135
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
81136
|
-
if (mod && mod.__esModule) return mod;
|
|
81137
|
-
var result = {};
|
|
81138
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
81139
|
-
__setModuleDefault(result, mod);
|
|
81140
|
-
return result;
|
|
81091
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
81092
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
81141
81093
|
};
|
|
81142
81094
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
81143
81095
|
exports.compile = void 0;
|
|
81144
|
-
const
|
|
81096
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
81145
81097
|
function compile(compilerOptions) {
|
|
81146
|
-
const yamlPath =
|
|
81147
|
-
return `${compilerOptions.headerComment}
|
|
81148
|
-
import { Router } from "express";
|
|
81149
|
-
import swaggerUi, { JsonObject } from "swagger-ui-express";
|
|
81150
|
-
import { loadYaml } from "./../_utils/common.gen";
|
|
81151
|
-
|
|
81152
|
-
export default class SwaggerRouter{
|
|
81153
|
-
|
|
81154
|
-
public router: Router = Router();
|
|
81155
|
-
|
|
81156
|
-
constructor() {}
|
|
81157
|
-
|
|
81158
|
-
public initRoutes() {
|
|
81159
|
-
this.router.use("/api", swaggerUi.serve, swaggerUi.setup(loadYaml(__dirname+"/${yamlPath}") as JsonObject));
|
|
81160
|
-
}
|
|
81098
|
+
const yamlPath = utils_1.default.common.relativePath(compilerOptions.sysDir + "/routes", compilerOptions.openapiDir + "/openapi.gen.yaml");
|
|
81099
|
+
return `${compilerOptions.headerComment}
|
|
81100
|
+
import { Router } from "express";
|
|
81101
|
+
import swaggerUi, { JsonObject } from "swagger-ui-express";
|
|
81102
|
+
import { loadYaml } from "./../_utils/common.gen";
|
|
81103
|
+
|
|
81104
|
+
export default class SwaggerRouter{
|
|
81105
|
+
|
|
81106
|
+
public router: Router = Router();
|
|
81107
|
+
|
|
81108
|
+
constructor() {}
|
|
81109
|
+
|
|
81110
|
+
public initRoutes() {
|
|
81111
|
+
this.router.use("/api", swaggerUi.serve, swaggerUi.setup(loadYaml(__dirname+"/${yamlPath}") as JsonObject));
|
|
81112
|
+
}
|
|
81161
81113
|
}`;
|
|
81162
81114
|
}
|
|
81163
81115
|
exports.compile = compile;
|
|
@@ -81210,19 +81162,18 @@ exports.generate = void 0;
|
|
|
81210
81162
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
81211
81163
|
const json2mongoose_1 = __importDefault(__nccwpck_require__(526));
|
|
81212
81164
|
const openapiGen = __importStar(__nccwpck_require__(8566));
|
|
81165
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
81213
81166
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
81214
|
-
const
|
|
81167
|
+
const jsonschemaFormat_1 = __nccwpck_require__(37);
|
|
81168
|
+
const roleSetupFile_1 = __nccwpck_require__(6669);
|
|
81215
81169
|
const userSchemaGen = __importStar(__nccwpck_require__(5651));
|
|
81216
81170
|
const roleGen = __importStar(__nccwpck_require__(3009));
|
|
81217
81171
|
const controllerGen = __importStar(__nccwpck_require__(6727));
|
|
81218
81172
|
const routeGen = __importStar(__nccwpck_require__(2964));
|
|
81219
81173
|
const serverGen = __importStar(__nccwpck_require__(2418));
|
|
81220
|
-
const configChecker_1 = __nccwpck_require__(7377);
|
|
81221
|
-
const jsonschemaFormat_1 = __nccwpck_require__(37);
|
|
81222
|
-
const roleSetupFile_1 = __nccwpck_require__(6669);
|
|
81223
81174
|
function generate(options) {
|
|
81224
81175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81225
|
-
|
|
81176
|
+
utils_1.default.configChecker.checkConfigValid(options);
|
|
81226
81177
|
const openapiFile = "/openapi.gen.yaml";
|
|
81227
81178
|
const documents = [];
|
|
81228
81179
|
const dir = {
|
|
@@ -81239,7 +81190,7 @@ function generate(options) {
|
|
|
81239
81190
|
};
|
|
81240
81191
|
const routeData = [];
|
|
81241
81192
|
if (!options.headerComment) {
|
|
81242
|
-
options.headerComment =
|
|
81193
|
+
options.headerComment = utils_1.default.generator.getGenaratorHeaderComment();
|
|
81243
81194
|
}
|
|
81244
81195
|
if (!fs_1.default.existsSync(options.rootDir)) {
|
|
81245
81196
|
fs_1.default.mkdirSync(options.rootDir);
|
|
@@ -81261,13 +81212,13 @@ function generate(options) {
|
|
|
81261
81212
|
fs_1.default.mkdirSync(path);
|
|
81262
81213
|
}
|
|
81263
81214
|
});
|
|
81264
|
-
|
|
81265
|
-
|
|
81266
|
-
|
|
81267
|
-
|
|
81268
|
-
|
|
81269
|
-
yield userSchemaGen.compile({ compilerOptions: options ||
|
|
81270
|
-
(0, roleSetupFile_1.roleSchemaFormat)({ compilerOptions: options ||
|
|
81215
|
+
utils_1.default.common.copyDir(__nccwpck_require__.ab + "_plugins", dir.pluginDir, options, true);
|
|
81216
|
+
utils_1.default.common.copyDir(__nccwpck_require__.ab + "_roles", dir.roleDir, options, true);
|
|
81217
|
+
utils_1.default.common.copyDir(__nccwpck_require__.ab + "_services", dir.serviceDir, options, true);
|
|
81218
|
+
utils_1.default.common.copyDir(__nccwpck_require__.ab + "_types", dir.typeDir, options, true);
|
|
81219
|
+
utils_1.default.common.copyDir(__nccwpck_require__.ab + "_utils", dir.utilsDir, options, true);
|
|
81220
|
+
yield userSchemaGen.compile({ compilerOptions: options || utils_1.default.generator.defaultCompilerOptions });
|
|
81221
|
+
(0, roleSetupFile_1.roleSchemaFormat)({ compilerOptions: options || utils_1.default.generator.defaultCompilerOptions });
|
|
81271
81222
|
const files = fs_1.default.readdirSync(options.jsonSchemaDir);
|
|
81272
81223
|
files.forEach((schemaFileName) => {
|
|
81273
81224
|
const schemaPath = `${options.jsonSchemaDir}/${schemaFileName}`;
|
|
@@ -81292,18 +81243,18 @@ function generate(options) {
|
|
|
81292
81243
|
roleSourceDir: dir.roleSrcDir,
|
|
81293
81244
|
roleOutDir: dir.roleDir,
|
|
81294
81245
|
middlewareDir: dir.middlewareDir,
|
|
81295
|
-
compilerOptions: options ||
|
|
81246
|
+
compilerOptions: options || utils_1.default.generator.defaultCompilerOptions
|
|
81296
81247
|
});
|
|
81297
81248
|
}
|
|
81298
|
-
yield openapiGen.compile(openapiFile, options ||
|
|
81299
|
-
|
|
81249
|
+
yield openapiGen.compile(openapiFile, options || utils_1.default.generator.defaultCompilerOptions);
|
|
81250
|
+
utils_1.default.common.copyDir(`${options.openapiDir}`, options.srcDir + "/openapi", options, true);
|
|
81300
81251
|
yield Promise.all(documents.map((doc) => __awaiter(this, void 0, void 0, function* () {
|
|
81301
|
-
json2mongoose_1.default.modelsGen.compileFromFile(`${doc.path}`, `${
|
|
81302
|
-
yield json2mongoose_1.default.typesGen.compileFromFile(`${doc.path}`, `${dir.typeDir}/${doc.config.
|
|
81252
|
+
json2mongoose_1.default.modelsGen.compileFromFile(`${doc.path}`, `${utils_1.default.common.relativePath(dir.modelDir, dir.typeDir)}/${doc.config.documentName}.gen`, `${dir.modelDir}/${doc.config.documentName}Model.gen.ts`, options || utils_1.default.generator.defaultCompilerOptions);
|
|
81253
|
+
yield json2mongoose_1.default.typesGen.compileFromFile(`${doc.path}`, `${dir.typeDir}/${doc.config.documentName}.gen.ts`, options || utils_1.default.generator.defaultCompilerOptions);
|
|
81303
81254
|
routeData.push({
|
|
81304
81255
|
route: `/${doc.config.documentName}`,
|
|
81305
|
-
|
|
81306
|
-
controllerPath:
|
|
81256
|
+
documentName: doc.config.documentName,
|
|
81257
|
+
controllerPath: utils_1.default.common.relativePath(dir.routeDir, dir.controllerDir) + "/" + doc.config.documentName + "Controller.gen",
|
|
81307
81258
|
});
|
|
81308
81259
|
return;
|
|
81309
81260
|
})));
|
|
@@ -81311,13 +81262,13 @@ function generate(options) {
|
|
|
81311
81262
|
openapiFile: openapiFile,
|
|
81312
81263
|
controllerOutDir: dir.controllerDir,
|
|
81313
81264
|
modelDir: dir.modelDir,
|
|
81314
|
-
compilerOptions: options ||
|
|
81265
|
+
compilerOptions: options || utils_1.default.generator.defaultCompilerOptions
|
|
81315
81266
|
});
|
|
81316
81267
|
yield routeGen.compile({
|
|
81317
81268
|
routesArr: routeData,
|
|
81318
81269
|
openapiFile: openapiFile,
|
|
81319
81270
|
routesDir: dir.routeDir,
|
|
81320
|
-
compilerOptions: options ||
|
|
81271
|
+
compilerOptions: options || utils_1.default.generator.defaultCompilerOptions
|
|
81321
81272
|
});
|
|
81322
81273
|
yield serverGen.compile(options);
|
|
81323
81274
|
return;
|
|
@@ -81362,24 +81313,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
81362
81313
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
81363
81314
|
exports.formatJsonSchema = void 0;
|
|
81364
81315
|
const types = __importStar(__nccwpck_require__(1456));
|
|
81365
|
-
const
|
|
81316
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
81366
81317
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
81367
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
81368
81318
|
function formatJsonSchema(jsonSchemaPath, compilerOptions) {
|
|
81369
|
-
|
|
81319
|
+
var _a;
|
|
81320
|
+
const fileName = ((_a = jsonSchemaPath.split("/").pop()) === null || _a === void 0 ? void 0 : _a.split(".")[0]) || "Unknown_File_Name";
|
|
81321
|
+
const jsonSchema = utils_1.default.jsonSchema.loadJsonSchema(jsonSchemaPath);
|
|
81370
81322
|
if (!jsonSchema["x-documentConfig"]) {
|
|
81371
|
-
logger_1.default.error(`
|
|
81323
|
+
logger_1.default.error(`Json Schema Formatting: "${jsonSchemaPath}" x-documentConfig not found.`);
|
|
81372
81324
|
}
|
|
81373
81325
|
else if (!jsonSchema["x-documentConfig"].documentName) {
|
|
81374
|
-
logger_1.default.
|
|
81375
|
-
|
|
81376
|
-
else if (!jsonSchema["x-documentConfig"].interfaceName) {
|
|
81377
|
-
logger_1.default.error(`formatJsonSchema : x-documentConfig.interfaceName not found in ${jsonSchemaPath}`);
|
|
81326
|
+
logger_1.default.warn(`Json Schema Formatting: "${jsonSchemaPath}" x-documentConfig.documentName added.`);
|
|
81327
|
+
jsonSchema["x-documentConfig"].documentName = fileName;
|
|
81378
81328
|
}
|
|
81379
81329
|
else if (!jsonSchema["x-documentConfig"].methods) {
|
|
81380
|
-
logger_1.default.warn(`
|
|
81330
|
+
logger_1.default.warn(`Json Schema Formatting: "${jsonSchemaPath}" x-documentConfig.methods not found, supported methods added.`);
|
|
81381
81331
|
jsonSchema["x-documentConfig"].methods = Object.assign([], types.schemaMethodArr);
|
|
81382
81332
|
}
|
|
81333
|
+
else if (jsonSchema["x-documentConfig"].documentName != fileName) {
|
|
81334
|
+
logger_1.default.error(`Json Schema Formatting: "${jsonSchemaPath}" x-documentConfig.documentName is not consistant with file name.`);
|
|
81335
|
+
}
|
|
81383
81336
|
if (typeof jsonSchema.properties !== "object") {
|
|
81384
81337
|
logger_1.default.error(`properties is invalid in ${jsonSchemaPath}`);
|
|
81385
81338
|
}
|
|
@@ -81387,7 +81340,7 @@ function formatJsonSchema(jsonSchemaPath, compilerOptions) {
|
|
|
81387
81340
|
checkField_id(jsonSchema, jsonSchemaPath);
|
|
81388
81341
|
}
|
|
81389
81342
|
jsonSchema.required = getRequiredArrStr(jsonSchema, jsonSchemaPath);
|
|
81390
|
-
|
|
81343
|
+
utils_1.default.common.writeFile("Json Schema Formatting", jsonSchemaPath, JSON.stringify(jsonSchema, null, 4));
|
|
81391
81344
|
return jsonSchema;
|
|
81392
81345
|
}
|
|
81393
81346
|
exports.formatJsonSchema = formatJsonSchema;
|
|
@@ -81454,7 +81407,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
81454
81407
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
81455
81408
|
exports.roleSchemaFormat = exports.roleSetupFile = void 0;
|
|
81456
81409
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
|
81457
|
-
const utils_1 = __nccwpck_require__(6252);
|
|
81410
|
+
const utils_1 = __importDefault(__nccwpck_require__(6252));
|
|
81458
81411
|
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
81459
81412
|
function roleSetupFile(options) {
|
|
81460
81413
|
var _a;
|
|
@@ -81467,14 +81420,14 @@ function roleSetupFile(options) {
|
|
|
81467
81420
|
const roleFilePath = `${options.roleSetupDir}/${role}.json`;
|
|
81468
81421
|
const content = {};
|
|
81469
81422
|
if (fs_1.default.existsSync(roleFilePath)) {
|
|
81470
|
-
Object.assign(content,
|
|
81423
|
+
Object.assign(content, utils_1.default.common.loadJson(roleFilePath));
|
|
81471
81424
|
}
|
|
81472
81425
|
options.collectionList.forEach(collectionName => {
|
|
81473
81426
|
if (!content[collectionName]) {
|
|
81474
81427
|
content[collectionName] = actionArray;
|
|
81475
81428
|
}
|
|
81476
81429
|
});
|
|
81477
|
-
|
|
81430
|
+
utils_1.default.common.writeFile(`Role Setting File : ${roleFilePath}`, roleFilePath, JSON.stringify(content, null, 4));
|
|
81478
81431
|
});
|
|
81479
81432
|
}
|
|
81480
81433
|
exports.roleSetupFile = roleSetupFile;
|
|
@@ -81485,9 +81438,9 @@ function roleSchemaFormat(options) {
|
|
|
81485
81438
|
}
|
|
81486
81439
|
(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.schemaIncluded.forEach((file) => {
|
|
81487
81440
|
var _a, _b;
|
|
81488
|
-
logger_1.default.process(`Schema Role
|
|
81441
|
+
logger_1.default.process(`Schema Role Formatting : ${file}.json`);
|
|
81489
81442
|
const roleSchemaPath = `${options.compilerOptions.jsonSchemaDir}/${file}.json`;
|
|
81490
|
-
const schema =
|
|
81443
|
+
const schema = utils_1.default.common.loadJson(roleSchemaPath);
|
|
81491
81444
|
for (const key in schema.properties) {
|
|
81492
81445
|
const prop = schema.properties[key];
|
|
81493
81446
|
if (prop["x-vexData"] === "role") {
|
|
@@ -81503,7 +81456,7 @@ function roleSchemaFormat(options) {
|
|
|
81503
81456
|
break;
|
|
81504
81457
|
}
|
|
81505
81458
|
}
|
|
81506
|
-
|
|
81459
|
+
utils_1.default.common.writeFile("Schema Role Formatting", roleSchemaPath, JSON.stringify(schema, null, 4));
|
|
81507
81460
|
});
|
|
81508
81461
|
}
|
|
81509
81462
|
exports.roleSchemaFormat = roleSchemaFormat;
|
|
@@ -81589,7 +81542,6 @@ exports.loadJson = loadJson;
|
|
|
81589
81542
|
function writeFile(title, destination, newContent) {
|
|
81590
81543
|
const oldContent = fs_1.default.existsSync(destination) ? fs_1.default.readFileSync(destination, "utf8") : "";
|
|
81591
81544
|
if (oldContent === newContent) {
|
|
81592
|
-
logger_1.default.info(`${title} : "${destination}" No changes`);
|
|
81593
81545
|
return false;
|
|
81594
81546
|
}
|
|
81595
81547
|
else {
|
|
@@ -81605,20 +81557,18 @@ function copyDir(source, destination, compilerOptions, overwrite) {
|
|
|
81605
81557
|
}
|
|
81606
81558
|
const files = fs_1.default.readdirSync(source);
|
|
81607
81559
|
for (let i = 0; i < files.length; i++) {
|
|
81608
|
-
const
|
|
81609
|
-
|
|
81610
|
-
|
|
81560
|
+
const sourcePath = path_1.default.join(source, files[i]);
|
|
81561
|
+
const destinationPath = path_1.default.join(destination, files[i].replace(".ts", ".gen.ts"));
|
|
81562
|
+
if (fs_1.default.lstatSync(sourcePath).isDirectory()) {
|
|
81563
|
+
copyDir(sourcePath, destinationPath, compilerOptions, overwrite);
|
|
81611
81564
|
}
|
|
81612
|
-
else if (!overwrite && fs_1.default.existsSync(
|
|
81613
|
-
logger_1.default.info(`FILE :
|
|
81565
|
+
else if (!overwrite && fs_1.default.existsSync(destinationPath)) {
|
|
81566
|
+
logger_1.default.info(`FILE : AVOID OVERWRITE, skip "${destinationPath}"`);
|
|
81614
81567
|
}
|
|
81615
81568
|
else {
|
|
81616
|
-
|
|
81617
|
-
|
|
81618
|
-
|
|
81619
|
-
let content = fs_1.default.readFileSync(source + "/" + files[i], "utf8");
|
|
81620
|
-
content = content.replace(/\/\/ {{headerComment}}/g, compilerOptions.headerComment);
|
|
81621
|
-
fs_1.default.writeFileSync(outPath, content);
|
|
81569
|
+
let newContent = fs_1.default.readFileSync(sourcePath, "utf8");
|
|
81570
|
+
newContent = newContent.replace(/\/\/ {{headerComment}}/g, compilerOptions.headerComment);
|
|
81571
|
+
writeFile(`FILE : ${destinationPath}`, destinationPath, newContent);
|
|
81622
81572
|
}
|
|
81623
81573
|
}
|
|
81624
81574
|
}
|
|
@@ -81626,6 +81576,8 @@ exports.copyDir = copyDir;
|
|
|
81626
81576
|
exports["default"] = {
|
|
81627
81577
|
relativePath: exports.relativePath,
|
|
81628
81578
|
copyDir,
|
|
81579
|
+
loadJson,
|
|
81580
|
+
writeFile,
|
|
81629
81581
|
};
|
|
81630
81582
|
|
|
81631
81583
|
|
|
@@ -81656,6 +81608,9 @@ function checkConfigValid(options) {
|
|
|
81656
81608
|
}
|
|
81657
81609
|
}
|
|
81658
81610
|
exports.checkConfigValid = checkConfigValid;
|
|
81611
|
+
exports["default"] = {
|
|
81612
|
+
checkConfigValid
|
|
81613
|
+
};
|
|
81659
81614
|
|
|
81660
81615
|
|
|
81661
81616
|
/***/ }),
|
|
@@ -81748,26 +81703,22 @@ exports["default"] = {
|
|
|
81748
81703
|
|
|
81749
81704
|
"use strict";
|
|
81750
81705
|
|
|
81751
|
-
var
|
|
81752
|
-
|
|
81753
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
81754
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
81755
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
81756
|
-
}
|
|
81757
|
-
Object.defineProperty(o, k2, desc);
|
|
81758
|
-
}) : (function(o, m, k, k2) {
|
|
81759
|
-
if (k2 === undefined) k2 = k;
|
|
81760
|
-
o[k2] = m[k];
|
|
81761
|
-
}));
|
|
81762
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
81763
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
81706
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
81707
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
81764
81708
|
};
|
|
81765
81709
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
81766
|
-
|
|
81767
|
-
|
|
81768
|
-
|
|
81769
|
-
|
|
81770
|
-
|
|
81710
|
+
const common_1 = __importDefault(__nccwpck_require__(3851));
|
|
81711
|
+
const generator_1 = __importDefault(__nccwpck_require__(4907));
|
|
81712
|
+
const jsonSchema_1 = __importDefault(__nccwpck_require__(3661));
|
|
81713
|
+
const logger_1 = __importDefault(__nccwpck_require__(8836));
|
|
81714
|
+
const configChecker_1 = __importDefault(__nccwpck_require__(7377));
|
|
81715
|
+
exports["default"] = {
|
|
81716
|
+
common: common_1.default,
|
|
81717
|
+
generator: generator_1.default,
|
|
81718
|
+
jsonSchema: jsonSchema_1.default,
|
|
81719
|
+
logger: logger_1.default,
|
|
81720
|
+
configChecker: configChecker_1.default
|
|
81721
|
+
};
|
|
81771
81722
|
|
|
81772
81723
|
|
|
81773
81724
|
/***/ }),
|