very-express 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,7 +34,9 @@ const utils_1 = require("../utils");
34
34
  const roleSetupFile_1 = require("../preprocess/roleSetupFile");
35
35
  function compile(options) {
36
36
  var _a;
37
- (0, roleSetupFile_1.roleSchemaFormat)({ compilerOptions: options.compilerOptions });
37
+ if (!options.compilerOptions.useRBAC) {
38
+ return;
39
+ }
38
40
  (0, roleSetupFile_1.roleSetupFile)({
39
41
  collectionList: options.collectionList,
40
42
  roleSetupDir: options.roleSourceDir,
@@ -57,15 +59,15 @@ function compile(options) {
57
59
  }
58
60
  });
59
61
  const RoleAccessActionString = Object.keys(RoleAccessAction).map((key) => `"${key}"`);
60
- RoleAccessActionString.push("roleFt.accessAction");
62
+ RoleAccessActionString.push("roleFactory.accessAction");
61
63
  const content = `${options.compilerOptions.headerComment}
62
- import * as role from "./_RoleFactory.gen";
64
+ import * as roleFactory from "./_RoleFactory.gen";
63
65
 
64
66
  export type accessAction${role} = ${RoleAccessActionString.join(" | ")};
65
67
 
66
- const ${role}AccessControl: roleFt.accessControl<accessAction${role}> = ${JSON.stringify(roleContent, null, 4)};
68
+ const ${role}AccessControl: roleFactory.accessControl<accessAction${role}> = ${JSON.stringify(roleContent, null, 4)};
67
69
 
68
- export default class Role${role} extends roleFt._RoleFactory<accessAction${role}> {
70
+ export default class Role${role} extends roleFactory._RoleFactory<accessAction${role}> {
69
71
  constructor() {
70
72
  super(${role}AccessControl);
71
73
  }
@@ -77,14 +79,14 @@ export default class Role${role} extends roleFt._RoleFactory<accessAction${role}
77
79
  from: roleOutFile,
78
80
  });
79
81
  });
80
- const indexFile = `${options.roleOutDir}/index.gen.ts`;
81
- const indexFileContent = indexFileData.map((data) => `export { default as ${data.name} } from "./${data.from.replace(".ts", "")}";`).join("\n");
82
+ const indexFile = `${options.roleOutDir}/index.ts`;
83
+ const indexFileContent = indexFileData.map((data) => `export { default as ${data.name} } from "./${data.name}.gen";`).join("\n");
82
84
  (0, utils_1.writeFile)("RBAC Index", indexFile, `${options.compilerOptions.headerComment}\n${indexFileContent}`);
83
- if (!fs_1.default.existsSync(`${options.compilerOptions.srcDir}/middleware`)) {
84
- fs_1.default.mkdirSync(`${options.compilerOptions.srcDir}/middleware`);
85
+ if (!fs_1.default.existsSync(`${options.compilerOptions.srcDir}/middlewares`)) {
86
+ fs_1.default.mkdirSync(`${options.compilerOptions.srcDir}/middlewares`);
85
87
  }
86
- const middlewareFile = `${options.compilerOptions.srcDir}/middleware/RoleBaseAccessControl.gen.ts`;
87
- const roleTypes = indexFileData.map((data) => `typeof ${data.name}`).join(" | ");
88
+ const middlewareFile = `${options.compilerOptions.srcDir}/middlewares/RoleBaseAccessControl.gen.ts`;
89
+ const roleTypes = indexFileData.map((data) => `typeof roles.${data.name}`).join(" | ");
88
90
  const middlewareContent = `${options.compilerOptions.headerComment}
89
91
  import { Request, Response, NextFunction } from "express";
90
92
  import * as roles from "../roles";
@@ -7,6 +7,9 @@ exports.compile = void 0;
7
7
  const logger_1 = __importDefault(require("../utils/logger"));
8
8
  const utils_1 = require("../utils");
9
9
  function compile(options) {
10
+ if (!options.compilerOptions.app.useUserSchema) {
11
+ return;
12
+ }
10
13
  logger_1.default.process("UserSchmea");
11
14
  const schemaOutPath = `${options.compilerOptions.jsonSchemaDir}/User.json`;
12
15
  const templateSchema = (0, utils_1.loadJson)(`${__dirname}/../templates/jsonSchema/User.json`);
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ const controllerGen = __importStar(require("./generators/controllers.generator")
38
38
  const routeGen = __importStar(require("./generators/routes/routes.generator"));
39
39
  const serverGen = __importStar(require("./generators/server.generator"));
40
40
  const jsonschemaFormat_1 = require("./preprocess/jsonschemaFormat");
41
+ const roleSetupFile_1 = require("./preprocess/roleSetupFile");
41
42
  function generate(options) {
42
43
  const openapiFile = "/openapi.gen.yaml";
43
44
  const roleSourceDir = `${options.rootDir}/roles`;
@@ -78,11 +79,8 @@ function generate(options) {
78
79
  utils.copyDir(`${__dirname}/templates/services`, dir.serviceDir, options, true);
79
80
  utils.copyDir(`${__dirname}/templates/plugins`, dir.pluginDir, options, true);
80
81
  utils.copyDir(`${__dirname}/templates/roles`, dir.roleDir, options, true);
81
- if (options.app.useUserSchema) {
82
- userSchemaGen.compile({
83
- compilerOptions: options || utils.defaultCompilerOptions,
84
- });
85
- }
82
+ userSchemaGen.compile({ compilerOptions: options || utils.defaultCompilerOptions });
83
+ (0, roleSetupFile_1.roleSchemaFormat)({ compilerOptions: options || utils.defaultCompilerOptions });
86
84
  const files = fs_1.default.readdirSync(options.jsonSchemaDir);
87
85
  files.forEach((schemaFileName) => {
88
86
  const schemaPath = `${options.jsonSchemaDir}/${schemaFileName}`;
@@ -9,6 +9,9 @@ const utils_1 = require("../utils");
9
9
  const logger_1 = __importDefault(require("../utils/logger"));
10
10
  function roleSetupFile(options) {
11
11
  var _a;
12
+ if (!options.compilerOptions.useRBAC) {
13
+ return;
14
+ }
12
15
  const actionArray = ["create", "search", "read", "update", "delete"];
13
16
  (_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.roles.forEach((role) => {
14
17
  logger_1.default.process(`Role Setting File : ${role}`);
@@ -28,6 +31,9 @@ function roleSetupFile(options) {
28
31
  exports.roleSetupFile = roleSetupFile;
29
32
  function roleSchemaFormat(options) {
30
33
  var _a;
34
+ if (!options.compilerOptions.useRBAC) {
35
+ return;
36
+ }
31
37
  (_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.schemaIncluded.forEach((file) => {
32
38
  var _a, _b;
33
39
  logger_1.default.process(`Schema Role Format : ${file}.json`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "justin26l",
6
6
  "license": "MIT",