speedly 2.0.31 → 2.0.33

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.
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
8
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
+ const parser_1 = require("./parser");
11
12
  const METHODS_WITH_BODY = ["post", "put", "patch"];
12
13
  /* ===================== HELPERS ======================= */
13
14
  function extractPath(layer) {
@@ -103,9 +104,7 @@ function routeAnalyzer(route, routerName) {
103
104
  const scanned = scanRouter(route);
104
105
  const paramsRegex = /:[^/]+/g;
105
106
  scanned.forEach((route) => {
106
- const fullPath = `/${routerName}${route.path
107
- .replace(/^\/$/, "")
108
- .replaceAll(paramsRegex, (r) => `{${r.slice(1)}}`)}`;
107
+ const fullPath = `/${routerName}${(0, parser_1.expressToSwagger)(route.path)}`;
109
108
  routerDetails[fullPath] = {};
110
109
  Object.entries(route.methods).forEach(([method, detail]) => {
111
110
  const doc = {
@@ -0,0 +1 @@
1
+ export declare function expressToSwagger(path: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expressToSwagger = expressToSwagger;
4
+ function expressToSwagger(path) {
5
+ // مرحله 1: optional group ها رو unwrap کن
6
+ // {/:newName} -> /:newName
7
+ let normalized = path.replace(/\{([^}]+)\}/g, "$1");
8
+ // مرحله 2: :param رو تبدیل کن به {param}
9
+ normalized = normalized.replace(/:([A-Za-z0-9_]+)/g, "{$1}");
10
+ return normalized;
11
+ }
@@ -51,9 +51,9 @@ exports.default = (destination = "/image", filename, config = configs) => {
51
51
  }
52
52
  const originalName = Buffer.from(file.originalname, "latin1").toString("utf8");
53
53
  const fileName = (configs.prefix ? configs.prefix + "-" : "") +
54
- (typeof filename === "function"
54
+ ((typeof filename === "function"
55
55
  ? filename(req, file)
56
- : filename || originalName.replace(/\.\w+$/, "")) +
56
+ : filename) || originalName.replace(/\.\w+$/, "")) +
57
57
  ext;
58
58
  const filePath = path_1.default.join(configs.path, dest, fileName);
59
59
  try {
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
8
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
+ const parser_1 = require("./parser");
11
12
  const METHODS_WITH_BODY = ["post", "put", "patch"];
12
13
  /* ===================== HELPERS ======================= */
13
14
  function extractPath(layer) {
@@ -103,9 +104,7 @@ function routeAnalyzer(route, routerName) {
103
104
  const scanned = scanRouter(route);
104
105
  const paramsRegex = /:[^/]+/g;
105
106
  scanned.forEach((route) => {
106
- const fullPath = `/${routerName}${route.path
107
- .replace(/^\/$/, "")
108
- .replaceAll(paramsRegex, (r) => `{${r.slice(1)}}`)}`;
107
+ const fullPath = `/${routerName}${(0, parser_1.expressToSwagger)(route.path)}`;
109
108
  routerDetails[fullPath] = {};
110
109
  Object.entries(route.methods).forEach(([method, detail]) => {
111
110
  const doc = {
@@ -0,0 +1 @@
1
+ export declare function expressToSwagger(path: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expressToSwagger = expressToSwagger;
4
+ function expressToSwagger(path) {
5
+ // مرحله 1: optional group ها رو unwrap کن
6
+ // {/:newName} -> /:newName
7
+ let normalized = path.replace(/\{([^}]+)\}/g, "$1");
8
+ // مرحله 2: :param رو تبدیل کن به {param}
9
+ normalized = normalized.replace(/:([A-Za-z0-9_]+)/g, "{$1}");
10
+ return normalized;
11
+ }
@@ -51,9 +51,9 @@ exports.default = (destination = "/image", filename, config = configs) => {
51
51
  }
52
52
  const originalName = Buffer.from(file.originalname, "latin1").toString("utf8");
53
53
  const fileName = (configs.prefix ? configs.prefix + "-" : "") +
54
- (typeof filename === "function"
54
+ ((typeof filename === "function"
55
55
  ? filename(req, file)
56
- : filename || originalName.replace(/\.\w+$/, "")) +
56
+ : filename) || originalName.replace(/\.\w+$/, "")) +
57
57
  ext;
58
58
  const filePath = path_1.default.join(configs.path, dest, fileName);
59
59
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "2.0.31",
3
+ "version": "2.0.33",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",