speedly 2.1.2 → 2.1.3

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.
@@ -37,7 +37,6 @@ function speedly(config = {}) {
37
37
  }
38
38
  }
39
39
  }
40
- console.log("init", 48, fs_1.default.existsSync(path_1.default.join(process.cwd(), "src/module")));
41
40
  if (finalConfig.documentation &&
42
41
  fs_1.default.existsSync(path_1.default.join(process.cwd(), "src/module")))
43
42
  (0, document_1.default)(app, path_1.default.join(process.cwd(), "src/module"), finalConfig.documentation === true
@@ -31,6 +31,14 @@ export interface DefaultConfig {
31
31
  translate: {
32
32
  one_api_token: string;
33
33
  };
34
+ document: {
35
+ editEntities?: {
36
+ [key: string]: {
37
+ rename?: string;
38
+ basePath?: string;
39
+ };
40
+ };
41
+ };
34
42
  }
35
43
  declare const defaultConfigs: DefaultConfig;
36
44
  export default defaultConfigs;
@@ -27,6 +27,7 @@ const defaultConfigs = {
27
27
  return true;
28
28
  },
29
29
  },
30
- translate: { one_api_token: "" }
30
+ translate: { one_api_token: "" },
31
+ document: {}
31
32
  };
32
33
  exports.default = defaultConfigs;
@@ -9,6 +9,8 @@ const path_1 = __importDefault(require("path"));
9
9
  const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
10
10
  const swagger_themes_1 = require("swagger-themes");
11
11
  const parser_1 = require("./parser");
12
+ const getConfig_1 = __importDefault(require("../util/getConfig"));
13
+ const config = (0, getConfig_1.default)('document');
12
14
  const METHODS_WITH_BODY = ["post", "put", "patch"];
13
15
  /* ===================== HELPERS ======================= */
14
16
  function extractPath(layer) {
@@ -100,14 +102,15 @@ function scanRouter(router, base = "") {
100
102
  }
101
103
  /* ================== MAIN ANALYZER ===================== */
102
104
  function routeAnalyzer(route, routerName) {
105
+ const realName = config.editEntities?.[routerName]?.rename || routerName;
103
106
  const routerDetails = {};
104
107
  const scanned = scanRouter(route);
105
108
  scanned.forEach((route) => {
106
- const fullPath = `/${routerName}${(0, parser_1.expressToSwagger)(route.path)}`;
109
+ const fullPath = `/${config.editEntities?.[routerName]?.basePath || routerName}${(0, parser_1.expressToSwagger)(route.path)}`;
107
110
  routerDetails[fullPath] = {};
108
111
  Object.entries(route.methods).forEach(([method, detail]) => {
109
112
  const doc = {
110
- tags: [routerName.replace("_", " ")],
113
+ tags: [realName || routerName.replace('_', ' ')],
111
114
  description: "Public route",
112
115
  };
113
116
  const validation = detail.middlewares.find((mw) => mw.handle?.__validationSchema)?.handle.__validationSchema;
@@ -235,9 +238,10 @@ function RouterFetcher(baseDir, servers) {
235
238
  try {
236
239
  const router = require(routerPath);
237
240
  paths = { ...paths, ...routeAnalyzer(router, mf) };
241
+ const realName = config.editEntities?.[mf]?.rename || mf;
238
242
  tags.push({
239
- name: mf.replace("_", " "),
240
- description: `${mf} operations`,
243
+ name: realName || mf.replace("_", " "),
244
+ description: `${realName || mf} operations`,
241
245
  });
242
246
  }
243
247
  catch (err) {
@@ -265,6 +269,6 @@ function swaggerLoader(app, baseDir = path_1.default.join(process.cwd(), "src/mo
265
269
  const doc = RouterFetcher(baseDir, servers);
266
270
  const theme = new swagger_themes_1.SwaggerTheme();
267
271
  app.use("/docs", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(doc, {
268
- customCss: theme.getBuffer(swagger_themes_1.SwaggerThemeNameEnum.DARK),
272
+ customCss: theme.getBuffer(swagger_themes_1.SwaggerThemeNameEnum.CLASSIC),
269
273
  }));
270
274
  }
@@ -9,6 +9,7 @@ const strToObj_1 = __importDefault(require("../../util/strToObj"));
9
9
  const getConfig_1 = __importDefault(require("../../util/getConfig"));
10
10
  const translator_1 = __importDefault(require("../../util/translator"));
11
11
  const utils_1 = require("./utils");
12
+ const importFromPwd_1 = __importDefault(require("../../util/importFromPwd"));
12
13
  let configs = (0, getConfig_1.default)("db");
13
14
  const usingMongoDb = (collectionName, config = { type: "external" }) => {
14
15
  let model;
@@ -18,9 +19,12 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
18
19
  };
19
20
  if (config?.path)
20
21
  __path = config.path;
21
- model = require(path_1.default.join(...(config.type == "external"
22
- ? [require.main?.filename || "./", __path]
23
- : ["../../model"]), collectionName));
22
+ if (config.type == 'external') {
23
+ model = (0, importFromPwd_1.default)(__path, collectionName);
24
+ }
25
+ else {
26
+ model = require(path_1.default.join("../../model", collectionName));
27
+ }
24
28
  if (model.default)
25
29
  model = model.default;
26
30
  const actionHandler = {
@@ -428,6 +432,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
428
432
  });
429
433
  // if(req.query.select) data = data.select(req.query.select)
430
434
  data = await data;
435
+ req.document = data;
431
436
  if (queryState.events.after) {
432
437
  await queryState.events.after(req, data);
433
438
  }
@@ -1 +1 @@
1
- export default function importFromPwd(path: string): any;
1
+ export default function importFromPwd(...paths: string[]): any;
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = importFromPwd;
7
7
  const path_1 = __importDefault(require("path"));
8
- function importFromPwd(path) {
8
+ function importFromPwd(...paths) {
9
9
  if (!require?.main?.filename)
10
10
  return null;
11
11
  const mainDir = path_1.default.dirname(require.main.filename);
12
- const fullPath = path_1.default.join(mainDir, path);
12
+ const fullPath = path_1.default.join(mainDir, ...paths);
13
13
  try {
14
14
  return require(fullPath);
15
15
  }
@@ -37,7 +37,6 @@ function speedly(config = {}) {
37
37
  }
38
38
  }
39
39
  }
40
- console.log("init", 48, fs_1.default.existsSync(path_1.default.join(process.cwd(), "src/module")));
41
40
  if (finalConfig.documentation &&
42
41
  fs_1.default.existsSync(path_1.default.join(process.cwd(), "src/module")))
43
42
  (0, document_1.default)(app, path_1.default.join(process.cwd(), "src/module"), finalConfig.documentation === true
@@ -31,6 +31,14 @@ export interface DefaultConfig {
31
31
  translate: {
32
32
  one_api_token: string;
33
33
  };
34
+ document: {
35
+ editEntities?: {
36
+ [key: string]: {
37
+ rename?: string;
38
+ basePath?: string;
39
+ };
40
+ };
41
+ };
34
42
  }
35
43
  declare const defaultConfigs: DefaultConfig;
36
44
  export default defaultConfigs;
@@ -27,6 +27,7 @@ const defaultConfigs = {
27
27
  return true;
28
28
  },
29
29
  },
30
- translate: { one_api_token: "" }
30
+ translate: { one_api_token: "" },
31
+ document: {}
31
32
  };
32
33
  exports.default = defaultConfigs;
@@ -9,6 +9,8 @@ const path_1 = __importDefault(require("path"));
9
9
  const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
10
10
  const swagger_themes_1 = require("swagger-themes");
11
11
  const parser_1 = require("./parser");
12
+ const getConfig_1 = __importDefault(require("../util/getConfig"));
13
+ const config = (0, getConfig_1.default)('document');
12
14
  const METHODS_WITH_BODY = ["post", "put", "patch"];
13
15
  /* ===================== HELPERS ======================= */
14
16
  function extractPath(layer) {
@@ -100,14 +102,15 @@ function scanRouter(router, base = "") {
100
102
  }
101
103
  /* ================== MAIN ANALYZER ===================== */
102
104
  function routeAnalyzer(route, routerName) {
105
+ const realName = config.editEntities?.[routerName]?.rename || routerName;
103
106
  const routerDetails = {};
104
107
  const scanned = scanRouter(route);
105
108
  scanned.forEach((route) => {
106
- const fullPath = `/${routerName}${(0, parser_1.expressToSwagger)(route.path)}`;
109
+ const fullPath = `/${config.editEntities?.[routerName]?.basePath || routerName}${(0, parser_1.expressToSwagger)(route.path)}`;
107
110
  routerDetails[fullPath] = {};
108
111
  Object.entries(route.methods).forEach(([method, detail]) => {
109
112
  const doc = {
110
- tags: [routerName.replace("_", " ")],
113
+ tags: [realName || routerName.replace('_', ' ')],
111
114
  description: "Public route",
112
115
  };
113
116
  const validation = detail.middlewares.find((mw) => mw.handle?.__validationSchema)?.handle.__validationSchema;
@@ -235,9 +238,10 @@ function RouterFetcher(baseDir, servers) {
235
238
  try {
236
239
  const router = require(routerPath);
237
240
  paths = { ...paths, ...routeAnalyzer(router, mf) };
241
+ const realName = config.editEntities?.[mf]?.rename || mf;
238
242
  tags.push({
239
- name: mf.replace("_", " "),
240
- description: `${mf} operations`,
243
+ name: realName || mf.replace("_", " "),
244
+ description: `${realName || mf} operations`,
241
245
  });
242
246
  }
243
247
  catch (err) {
@@ -265,6 +269,6 @@ function swaggerLoader(app, baseDir = path_1.default.join(process.cwd(), "src/mo
265
269
  const doc = RouterFetcher(baseDir, servers);
266
270
  const theme = new swagger_themes_1.SwaggerTheme();
267
271
  app.use("/docs", swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(doc, {
268
- customCss: theme.getBuffer(swagger_themes_1.SwaggerThemeNameEnum.DARK),
272
+ customCss: theme.getBuffer(swagger_themes_1.SwaggerThemeNameEnum.CLASSIC),
269
273
  }));
270
274
  }
@@ -9,6 +9,7 @@ const strToObj_1 = __importDefault(require("../../util/strToObj"));
9
9
  const getConfig_1 = __importDefault(require("../../util/getConfig"));
10
10
  const translator_1 = __importDefault(require("../../util/translator"));
11
11
  const utils_1 = require("./utils");
12
+ const importFromPwd_1 = __importDefault(require("../../util/importFromPwd"));
12
13
  let configs = (0, getConfig_1.default)("db");
13
14
  const usingMongoDb = (collectionName, config = { type: "external" }) => {
14
15
  let model;
@@ -18,9 +19,12 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
18
19
  };
19
20
  if (config?.path)
20
21
  __path = config.path;
21
- model = require(path_1.default.join(...(config.type == "external"
22
- ? [require.main?.filename || "./", __path]
23
- : ["../../model"]), collectionName));
22
+ if (config.type == 'external') {
23
+ model = (0, importFromPwd_1.default)(__path, collectionName);
24
+ }
25
+ else {
26
+ model = require(path_1.default.join("../../model", collectionName));
27
+ }
24
28
  if (model.default)
25
29
  model = model.default;
26
30
  const actionHandler = {
@@ -428,6 +432,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
428
432
  });
429
433
  // if(req.query.select) data = data.select(req.query.select)
430
434
  data = await data;
435
+ req.document = data;
431
436
  if (queryState.events.after) {
432
437
  await queryState.events.after(req, data);
433
438
  }
@@ -1 +1 @@
1
- export default function importFromPwd(path: string): any;
1
+ export default function importFromPwd(...paths: string[]): any;
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = importFromPwd;
7
7
  const path_1 = __importDefault(require("path"));
8
- function importFromPwd(path) {
8
+ function importFromPwd(...paths) {
9
9
  if (!require?.main?.filename)
10
10
  return null;
11
11
  const mainDir = path_1.default.dirname(require.main.filename);
12
- const fullPath = path_1.default.join(mainDir, path);
12
+ const fullPath = path_1.default.join(mainDir, ...paths);
13
13
  try {
14
14
  return require(fullPath);
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "Schema-driven backend framework for rapid API and admin panel development",
5
5
  "author": "MAHSERIN",
6
6
  "license": "MIT",
@@ -82,6 +82,7 @@
82
82
  "@types/multer": "^2.0.0",
83
83
  "@types/node": "^24.5.2",
84
84
  "@types/swagger-ui-express": "^4.1.8",
85
+ "cookie-parser": "^1.4.7",
85
86
  "ts-node": "^10.9.2",
86
87
  "typescript": "^5.9.2"
87
88
  },