apitally 0.25.5 → 0.25.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.
@@ -2,14 +2,20 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  const regExpToParseExpressPathRegExp = /^\/\^\\?\/?(?:(:?[\w\\.-]*(?:\\\/:?[\w\\.-]*)*)|(\(\?:\\?\/?\([^)]+\)\)))\\\/.*/;
4
4
  const regExpToReplaceExpressPathRegExpParams = /\(\?:\\?\/?\([^)]+\)\)/;
5
- const regexpExpressParamRegexp = /\(\?:\\?\\?\/?\([^)]+\)\)/g;
6
- const regexpExpressPathParamRegexp = /(:[^)]+)\([^)]+\)/g;
7
- const EXPRESS_ROOT_PATH_REGEXP_VALUE = "/^\\/?(?=\\/|$)/i";
8
- const STACK_ITEM_VALID_NAMES = [
5
+ const regExpExpressParamRegExp = /\(\?:\\?\\?\/?\([^)]+\)\)/g;
6
+ const regExpExpressPathParamRegExp = /(:[^)]+)\([^)]+\)/g;
7
+ const rootPathRegExpValue = "/^\\/?(?=\\/|$)/i";
8
+ const stackItemValidNames = [
9
9
  "router",
10
10
  "bound dispatch",
11
11
  "mounted_app"
12
12
  ];
13
+ const stripExpressPathParamRegex = /* @__PURE__ */ __name(function(path) {
14
+ return path.replace(regExpExpressPathParamRegExp, "$1");
15
+ }, "stripExpressPathParamRegex");
16
+ const formatRegExpRoutePath = /* @__PURE__ */ __name(function(re) {
17
+ return `RegExp(${re})`;
18
+ }, "formatRegExpRoutePath");
13
19
  const getRouterInfo = /* @__PURE__ */ __name(function(app) {
14
20
  var _a, _b;
15
21
  if (app.stack) {
@@ -45,23 +51,29 @@ const getRouteMiddlewares = /* @__PURE__ */ __name(function(route) {
45
51
  });
46
52
  }, "getRouteMiddlewares");
47
53
  const hasParams = /* @__PURE__ */ __name(function(expressPathRegExp) {
48
- return regexpExpressParamRegexp.test(expressPathRegExp);
54
+ return regExpExpressParamRegExp.test(expressPathRegExp);
49
55
  }, "hasParams");
50
56
  const parseExpressRoute = /* @__PURE__ */ __name(function(route, basePath) {
51
- const paths = [];
52
- if (Array.isArray(route.path)) {
53
- paths.push(...route.path);
54
- } else {
55
- paths.push(route.path);
56
- }
57
- const endpoints = paths.map((path) => {
58
- const completePath = basePath && path === "/" ? basePath : `${basePath}${path}`;
59
- const endpoint = {
60
- path: completePath.replace(regexpExpressPathParamRegexp, "$1"),
61
- methods: getRouteMethods(route),
62
- middlewares: getRouteMiddlewares(route)
63
- };
64
- return endpoint;
57
+ const paths = Array.isArray(route.path) ? route.path : [
58
+ route.path
59
+ ];
60
+ const endpoints = paths.flatMap((path) => {
61
+ let pathStr;
62
+ if (typeof path === "string") {
63
+ pathStr = stripExpressPathParamRegex(path);
64
+ } else if (path instanceof RegExp) {
65
+ pathStr = formatRegExpRoutePath(path);
66
+ } else {
67
+ return [];
68
+ }
69
+ const completePath = basePath && pathStr === "/" ? basePath : `${basePath}${pathStr}`;
70
+ return [
71
+ {
72
+ path: completePath,
73
+ methods: getRouteMethods(route),
74
+ middlewares: getRouteMiddlewares(route)
75
+ }
76
+ ];
65
77
  });
66
78
  return endpoints;
67
79
  }, "parseExpressRoute");
@@ -130,16 +142,15 @@ const parseStack = /* @__PURE__ */ __name(function(stack, basePath, endpoints, v
130
142
  if (stackItem.route) {
131
143
  const newEndpoints = parseExpressRoute(stackItem.route, basePath);
132
144
  endpoints = addEndpoints(endpoints, newEndpoints);
133
- } else if (STACK_ITEM_VALID_NAMES.includes(stackItem.name)) {
145
+ } else if (stackItemValidNames.includes(stackItem.name)) {
134
146
  let newBasePath = basePath;
135
147
  if (version === "v4") {
136
148
  const isExpressPathRegExp = regExpToParseExpressPathRegExp.test(stackItem.regexp);
137
149
  if (isExpressPathRegExp) {
138
150
  const parsedPath = parseExpressPathRegExp(stackItem.regexp, stackItem.keys);
139
151
  newBasePath += `/${parsedPath}`;
140
- } else if (!stackItem.path && stackItem.regexp && stackItem.regexp.toString() !== EXPRESS_ROOT_PATH_REGEXP_VALUE) {
141
- const regExpPath = `RegExp(${stackItem.regexp})`;
142
- newBasePath += `/${regExpPath}`;
152
+ } else if (!stackItem.path && stackItem.regexp && stackItem.regexp.toString() !== rootPathRegExpValue) {
153
+ newBasePath += `/${formatRegExpRoutePath(stackItem.regexp)}`;
143
154
  }
144
155
  } else if (version === "v5") {
145
156
  if (!stackItem.path) {
@@ -168,9 +179,11 @@ const getEndpoints = /* @__PURE__ */ __name(function(app, basePath) {
168
179
  })));
169
180
  }, "getEndpoints");
170
181
  export {
182
+ formatRegExpRoutePath,
171
183
  getEndpoints,
172
184
  getRouterInfo,
173
185
  parseExpressPath,
174
- parseExpressPathRegExp
186
+ parseExpressPathRegExp,
187
+ stripExpressPathParamRegex
175
188
  };
176
189
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/express/utils.js"],"sourcesContent":["// Adapted from https://github.com/AlbertoFdzM/express-list-endpoints/blob/305535d43008b46f34e18b01947762e039af6d2d/src/index.js\n// and also incorporated https://github.com/AlbertoFdzM/express-list-endpoints/pull/96\n// and https://github.com/labithiotis/express-list-routes/blob/5432c83a67c2788c56a1cdfc067ec809961c0c05/index.js\n\n/**\n * @typedef {Object} Route\n * @property {Object} methods\n * @property {string | string[]} path\n * @property {any[]} stack\n *\n * @typedef {Object} Endpoint\n * @property {string} path Path name\n * @property {string[]} methods Methods handled\n * @property {string[]} middlewares Mounted middlewares\n */\n\nconst regExpToParseExpressPathRegExp =\n /^\\/\\^\\\\?\\/?(?:(:?[\\w\\\\.-]*(?:\\\\\\/:?[\\w\\\\.-]*)*)|(\\(\\?:\\\\?\\/?\\([^)]+\\)\\)))\\\\\\/.*/;\nconst regExpToReplaceExpressPathRegExpParams = /\\(\\?:\\\\?\\/?\\([^)]+\\)\\)/;\nconst regexpExpressParamRegexp = /\\(\\?:\\\\?\\\\?\\/?\\([^)]+\\)\\)/g;\nconst regexpExpressPathParamRegexp = /(:[^)]+)\\([^)]+\\)/g;\n\nconst EXPRESS_ROOT_PATH_REGEXP_VALUE = \"/^\\\\/?(?=\\\\/|$)/i\";\nconst STACK_ITEM_VALID_NAMES = [\"router\", \"bound dispatch\", \"mounted_app\"];\n\n/**\n * Detects Express version and returns router information\n * @param {import('express').Express | import('express').Router | any} app\n * @returns {{stack: any[] | null, version: 'v4' | 'v5'}}\n */\nexport const getRouterInfo = function (app) {\n if (app.stack) {\n // Express 4 router\n return { stack: app.stack, version: \"v4\" };\n } else if (app._router?.stack) {\n // Express 4\n return { stack: app._router.stack, version: \"v4\" };\n } else if (app.router?.stack) {\n // Express 5\n return { stack: app.router.stack, version: \"v5\" };\n }\n return { stack: null, version: \"v4\" };\n};\n\n/**\n * Returns all the verbs detected for the passed route\n * @param {Route} route\n */\nconst getRouteMethods = function (route) {\n let methods = Object.keys(route.methods);\n\n methods = methods.filter((method) => method !== \"_all\");\n methods = methods.map((method) => method.toUpperCase());\n\n return methods;\n};\n\n/**\n * Returns the names (or anonymous) of all the middlewares attached to the\n * passed route\n * @param {Route} route\n * @returns {string[]}\n */\nconst getRouteMiddlewares = function (route) {\n return route.stack.map((item) => {\n return item.handle.name || \"anonymous\";\n });\n};\n\n/**\n * Returns true if found regexp related with express params\n * @param {string} expressPathRegExp\n * @returns {boolean}\n */\nconst hasParams = function (expressPathRegExp) {\n return regexpExpressParamRegexp.test(expressPathRegExp);\n};\n\n/**\n * @param {Route} route Express route object to be parsed\n * @param {string} basePath The basePath the route is on\n * @return {Endpoint[]} Endpoints info\n */\nconst parseExpressRoute = function (route, basePath) {\n const paths = [];\n\n if (Array.isArray(route.path)) {\n paths.push(...route.path);\n } else {\n paths.push(route.path);\n }\n\n /** @type {Endpoint[]} */\n const endpoints = paths.map((path) => {\n const completePath =\n basePath && path === \"/\" ? basePath : `${basePath}${path}`;\n\n /** @type {Endpoint} */\n const endpoint = {\n path: completePath.replace(regexpExpressPathParamRegexp, \"$1\"),\n methods: getRouteMethods(route),\n middlewares: getRouteMiddlewares(route),\n };\n\n return endpoint;\n });\n\n return endpoints;\n};\n\n/**\n * @param {RegExp} expressPathRegExp\n * @param {any[]} keys\n * @returns {string}\n */\nexport const parseExpressPathRegExp = function (expressPathRegExp, keys) {\n let parsedRegExp = expressPathRegExp.toString();\n let expressPathRegExpExec = regExpToParseExpressPathRegExp.exec(parsedRegExp);\n let paramIndex = 0;\n\n while (hasParams(parsedRegExp)) {\n const paramName = keys[paramIndex].name;\n const paramId = `:${paramName}`;\n\n parsedRegExp = parsedRegExp.replace(\n regExpToReplaceExpressPathRegExpParams,\n (str) => {\n // Express >= 4.20.0 uses a different RegExp for parameters: it\n // captures the slash as part of the parameter. We need to check\n // for this case and add the slash to the value that will replace\n // the parameter in the path.\n if (str.startsWith(\"(?:\\\\/\")) {\n return `\\\\/${paramId}`;\n }\n\n return paramId;\n },\n );\n\n paramIndex++;\n }\n\n if (parsedRegExp !== expressPathRegExp.toString()) {\n expressPathRegExpExec = regExpToParseExpressPathRegExp.exec(parsedRegExp);\n }\n\n return expressPathRegExpExec[1].replace(/\\\\\\//g, \"/\");\n};\n\n/**\n * @param {string} expressPath\n * @param {Object.<string, string>} params\n * @returns {string}\n */\nexport const parseExpressPath = function (expressPath, params) {\n let result = expressPath;\n for (const [paramName, paramValue] of Object.entries(params)) {\n result = result.replace(paramValue, `:${paramName}`);\n }\n return result;\n};\n\n/**\n * @param {import('express').Express | import('express').Router | any} app\n * @param {string} [basePath]\n * @param {Endpoint[]} [endpoints]\n * @returns {Endpoint[]}\n */\nconst parseEndpoints = function (app, basePath, endpoints) {\n const routerInfo = getRouterInfo(app);\n const stack = routerInfo.stack;\n const version = routerInfo.version;\n\n endpoints = endpoints || [];\n basePath = basePath || \"\";\n\n if (!stack) {\n if (endpoints.length) {\n endpoints = addEndpoints(endpoints, [\n {\n path: basePath,\n methods: [],\n middlewares: [],\n },\n ]);\n }\n } else {\n endpoints = parseStack(stack, basePath, endpoints, version);\n }\n\n return endpoints;\n};\n\n/**\n * Ensures the path of the new endpoints isn't yet in the array.\n * If the path is already in the array merges the endpoints with the existing\n * one, if not, it adds them to the array.\n *\n * @param {Endpoint[]} currentEndpoints Array of current endpoints\n * @param {Endpoint[]} endpointsToAdd New endpoints to be added to the array\n * @returns {Endpoint[]} Updated endpoints array\n */\nconst addEndpoints = function (currentEndpoints, endpointsToAdd) {\n endpointsToAdd.forEach((newEndpoint) => {\n const existingEndpoint = currentEndpoints.find(\n (endpoint) => endpoint.path === newEndpoint.path,\n );\n\n if (existingEndpoint !== undefined) {\n const newMethods = newEndpoint.methods.filter(\n (method) => !existingEndpoint.methods.includes(method),\n );\n\n existingEndpoint.methods = existingEndpoint.methods.concat(newMethods);\n } else {\n currentEndpoints.push(newEndpoint);\n }\n });\n\n return currentEndpoints;\n};\n\n/**\n * @param {any[]} stack\n * @param {string} basePath\n * @param {Endpoint[]} endpoints\n * @param {'v4' | 'v5'} [version]\n * @returns {Endpoint[]}\n */\nconst parseStack = function (stack, basePath, endpoints, version) {\n stack.forEach((stackItem) => {\n if (stackItem.route) {\n const newEndpoints = parseExpressRoute(stackItem.route, basePath);\n\n endpoints = addEndpoints(endpoints, newEndpoints);\n } else if (STACK_ITEM_VALID_NAMES.includes(stackItem.name)) {\n let newBasePath = basePath;\n\n if (version === \"v4\") {\n const isExpressPathRegExp = regExpToParseExpressPathRegExp.test(\n stackItem.regexp,\n );\n if (isExpressPathRegExp) {\n const parsedPath = parseExpressPathRegExp(\n stackItem.regexp,\n stackItem.keys,\n );\n newBasePath += `/${parsedPath}`;\n } else if (\n !stackItem.path &&\n stackItem.regexp &&\n stackItem.regexp.toString() !== EXPRESS_ROOT_PATH_REGEXP_VALUE\n ) {\n const regExpPath = `RegExp(${stackItem.regexp})`;\n newBasePath += `/${regExpPath}`;\n }\n } else if (version === \"v5\") {\n if (!stackItem.path) {\n return;\n } else if (stackItem.path !== \"/\") {\n newBasePath += stackItem.path.startsWith(\"/\")\n ? stackItem.path\n : `/${stackItem.path}`;\n }\n }\n\n endpoints = parseEndpoints(stackItem.handle, newBasePath, endpoints);\n }\n });\n\n return endpoints;\n};\n\nexport const getEndpoints = function (app, basePath) {\n const endpoints = parseEndpoints(app);\n const standardHttpMethods = [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\"];\n return endpoints.flatMap((route) =>\n route.methods\n .filter((method) => standardHttpMethods.includes(method.toUpperCase()))\n .map((method) => ({\n method,\n path: (basePath + route.path).replace(/\\/\\//g, \"/\"),\n })),\n );\n};\n"],"mappings":";;AAgBA,MAAMA,iCACJ;AACF,MAAMC,yCAAyC;AAC/C,MAAMC,2BAA2B;AACjC,MAAMC,+BAA+B;AAErC,MAAMC,iCAAiC;AACvC,MAAMC,yBAAyB;EAAC;EAAU;EAAkB;;AAOrD,MAAMC,gBAAgB,gCAAUC,KAAG;AA9B1C;AA+BE,MAAIA,IAAIC,OAAO;AAEb,WAAO;MAAEA,OAAOD,IAAIC;MAAOC,SAAS;IAAK;EAC3C,YAAWF,SAAIG,YAAJH,mBAAaC,OAAO;AAE7B,WAAO;MAAEA,OAAOD,IAAIG,QAAQF;MAAOC,SAAS;IAAK;EACnD,YAAWF,SAAII,WAAJJ,mBAAYC,OAAO;AAE5B,WAAO;MAAEA,OAAOD,IAAII,OAAOH;MAAOC,SAAS;IAAK;EAClD;AACA,SAAO;IAAED,OAAO;IAAMC,SAAS;EAAK;AACtC,GAZ6B;AAkB7B,MAAMG,kBAAkB,gCAAUC,OAAK;AACrC,MAAIC,UAAUC,OAAOC,KAAKH,MAAMC,OAAO;AAEvCA,YAAUA,QAAQG,OAAO,CAACC,WAAWA,WAAW,MAAA;AAChDJ,YAAUA,QAAQK,IAAI,CAACD,WAAWA,OAAOE,YAAW,CAAA;AAEpD,SAAON;AACT,GAPwB;AAexB,MAAMO,sBAAsB,gCAAUR,OAAK;AACzC,SAAOA,MAAML,MAAMW,IAAI,CAACG,SAAAA;AACtB,WAAOA,KAAKC,OAAOC,QAAQ;EAC7B,C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A,CAAA;AAEN,GAX4B;","names":["regExpToParseExpressPathRegExp","regExpToReplaceExpressPathRegExpParams","regexpExpressParamRegexp","regexpExpressPathParamRegexp","EXPRESS_ROOT_PATH_REGEXP_VALUE","STACK_ITEM_VALID_NAMES","getRouterInfo","app","stack","version","_router","router","getRouteMethods","route","methods","Object","keys","filter","method","map","toUpperCase","getRouteMiddlewares","item","handle","name","hasParams","expressPathRegExp","test","parseExpressRoute","basePath","paths","Array","isArray","path","push","endpoints","completePath","endpoint","replace","middlewares","parseExpressPathRegExp","parsedRegExp","toString","expressPathRegExpExec","exec","paramIndex","paramName","paramId","str","startsWith","parseExpressPath","expressPath","params","result","paramValue","entries","parseEndpoints","routerInfo","length","addEndpoints","parseStack","currentEndpoints","endpointsToAdd","forEach","newEndpoint","existingEndpoint","find","undefined","newMethods","includes","concat","stackItem","newEndpoints","newBasePath","isExpressPathRegExp","regexp","parsedPath","regExpPath","getEndpoints","standardHttpMethods","flatMap"]}
1
+ {"version":3,"sources":["../../src/express/utils.js"],"sourcesContent":["// Adapted from https://github.com/AlbertoFdzM/express-list-endpoints/blob/305535d43008b46f34e18b01947762e039af6d2d/src/index.js\n// and also incorporated https://github.com/AlbertoFdzM/express-list-endpoints/pull/96\n// and https://github.com/labithiotis/express-list-routes/blob/5432c83a67c2788c56a1cdfc067ec809961c0c05/index.js\n\n/**\n * @typedef {Object} Route\n * @property {Object} methods\n * @property {string | string[]} path\n * @property {any[]} stack\n *\n * @typedef {Object} Endpoint\n * @property {string} path Path name\n * @property {string[]} methods Methods handled\n * @property {string[]} middlewares Mounted middlewares\n */\n\nconst regExpToParseExpressPathRegExp =\n /^\\/\\^\\\\?\\/?(?:(:?[\\w\\\\.-]*(?:\\\\\\/:?[\\w\\\\.-]*)*)|(\\(\\?:\\\\?\\/?\\([^)]+\\)\\)))\\\\\\/.*/;\nconst regExpToReplaceExpressPathRegExpParams = /\\(\\?:\\\\?\\/?\\([^)]+\\)\\)/;\nconst regExpExpressParamRegExp = /\\(\\?:\\\\?\\\\?\\/?\\([^)]+\\)\\)/g;\nconst regExpExpressPathParamRegExp = /(:[^)]+)\\([^)]+\\)/g;\nconst rootPathRegExpValue = \"/^\\\\/?(?=\\\\/|$)/i\";\nconst stackItemValidNames = [\"router\", \"bound dispatch\", \"mounted_app\"];\n\n/**\n * Strips inline RegExp validators from Express path params, e.g.\n * \"/users/:id(\\\\d+)\" → \"/users/:id\".\n * @param {string} path\n * @returns {string}\n */\nexport const stripExpressPathParamRegex = function (path) {\n return path.replace(regExpExpressPathParamRegExp, \"$1\");\n};\n\n/**\n * Formats a RegExp route as a stable string identifier, e.g.\n * /^\\/foo$/ → \"RegExp(/^\\\\/foo$/)\".\n * @param {RegExp} re\n * @returns {string}\n */\nexport const formatRegExpRoutePath = function (re) {\n return `RegExp(${re})`;\n};\n\n/**\n * Detects Express version and returns router information\n * @param {import('express').Express | import('express').Router | any} app\n * @returns {{stack: any[] | null, version: 'v4' | 'v5'}}\n */\nexport const getRouterInfo = function (app) {\n if (app.stack) {\n // Express 4 router\n return { stack: app.stack, version: \"v4\" };\n } else if (app._router?.stack) {\n // Express 4\n return { stack: app._router.stack, version: \"v4\" };\n } else if (app.router?.stack) {\n // Express 5\n return { stack: app.router.stack, version: \"v5\" };\n }\n return { stack: null, version: \"v4\" };\n};\n\n/**\n * Returns all the verbs detected for the passed route\n * @param {Route} route\n */\nconst getRouteMethods = function (route) {\n let methods = Object.keys(route.methods);\n\n methods = methods.filter((method) => method !== \"_all\");\n methods = methods.map((method) => method.toUpperCase());\n\n return methods;\n};\n\n/**\n * Returns the names (or anonymous) of all the middlewares attached to the\n * passed route\n * @param {Route} route\n * @returns {string[]}\n */\nconst getRouteMiddlewares = function (route) {\n return route.stack.map((item) => {\n return item.handle.name || \"anonymous\";\n });\n};\n\n/**\n * Returns true if found regexp related with express params\n * @param {string} expressPathRegExp\n * @returns {boolean}\n */\nconst hasParams = function (expressPathRegExp) {\n return regExpExpressParamRegExp.test(expressPathRegExp);\n};\n\n/**\n * @param {Route} route Express route object to be parsed\n * @param {string} basePath The basePath the route is on\n * @return {Endpoint[]} Endpoints info\n */\nconst parseExpressRoute = function (route, basePath) {\n // route.path can be a string, a RegExp, or an array of either\n const paths = Array.isArray(route.path) ? route.path : [route.path];\n\n /** @type {Endpoint[]} */\n const endpoints = paths.flatMap((path) => {\n let pathStr;\n if (typeof path === \"string\") {\n pathStr = stripExpressPathParamRegex(path);\n } else if (path instanceof RegExp) {\n pathStr = formatRegExpRoutePath(path);\n } else {\n return [];\n }\n const completePath =\n basePath && pathStr === \"/\" ? basePath : `${basePath}${pathStr}`;\n return [\n {\n path: completePath,\n methods: getRouteMethods(route),\n middlewares: getRouteMiddlewares(route),\n },\n ];\n });\n\n return endpoints;\n};\n\n/**\n * @param {RegExp} expressPathRegExp\n * @param {any[]} keys\n * @returns {string}\n */\nexport const parseExpressPathRegExp = function (expressPathRegExp, keys) {\n let parsedRegExp = expressPathRegExp.toString();\n let expressPathRegExpExec = regExpToParseExpressPathRegExp.exec(parsedRegExp);\n let paramIndex = 0;\n\n while (hasParams(parsedRegExp)) {\n const paramName = keys[paramIndex].name;\n const paramId = `:${paramName}`;\n\n parsedRegExp = parsedRegExp.replace(\n regExpToReplaceExpressPathRegExpParams,\n (str) => {\n // Express >= 4.20.0 uses a different RegExp for parameters: it\n // captures the slash as part of the parameter. We need to check\n // for this case and add the slash to the value that will replace\n // the parameter in the path.\n if (str.startsWith(\"(?:\\\\/\")) {\n return `\\\\/${paramId}`;\n }\n\n return paramId;\n },\n );\n\n paramIndex++;\n }\n\n if (parsedRegExp !== expressPathRegExp.toString()) {\n expressPathRegExpExec = regExpToParseExpressPathRegExp.exec(parsedRegExp);\n }\n\n return expressPathRegExpExec[1].replace(/\\\\\\//g, \"/\");\n};\n\n/**\n * @param {string} expressPath\n * @param {Object.<string, string>} params\n * @returns {string}\n */\nexport const parseExpressPath = function (expressPath, params) {\n let result = expressPath;\n for (const [paramName, paramValue] of Object.entries(params)) {\n result = result.replace(paramValue, `:${paramName}`);\n }\n return result;\n};\n\n/**\n * @param {import('express').Express | import('express').Router | any} app\n * @param {string} [basePath]\n * @param {Endpoint[]} [endpoints]\n * @returns {Endpoint[]}\n */\nconst parseEndpoints = function (app, basePath, endpoints) {\n const routerInfo = getRouterInfo(app);\n const stack = routerInfo.stack;\n const version = routerInfo.version;\n\n endpoints = endpoints || [];\n basePath = basePath || \"\";\n\n if (!stack) {\n if (endpoints.length) {\n endpoints = addEndpoints(endpoints, [\n {\n path: basePath,\n methods: [],\n middlewares: [],\n },\n ]);\n }\n } else {\n endpoints = parseStack(stack, basePath, endpoints, version);\n }\n\n return endpoints;\n};\n\n/**\n * Ensures the path of the new endpoints isn't yet in the array.\n * If the path is already in the array merges the endpoints with the existing\n * one, if not, it adds them to the array.\n *\n * @param {Endpoint[]} currentEndpoints Array of current endpoints\n * @param {Endpoint[]} endpointsToAdd New endpoints to be added to the array\n * @returns {Endpoint[]} Updated endpoints array\n */\nconst addEndpoints = function (currentEndpoints, endpointsToAdd) {\n endpointsToAdd.forEach((newEndpoint) => {\n const existingEndpoint = currentEndpoints.find(\n (endpoint) => endpoint.path === newEndpoint.path,\n );\n\n if (existingEndpoint !== undefined) {\n const newMethods = newEndpoint.methods.filter(\n (method) => !existingEndpoint.methods.includes(method),\n );\n\n existingEndpoint.methods = existingEndpoint.methods.concat(newMethods);\n } else {\n currentEndpoints.push(newEndpoint);\n }\n });\n\n return currentEndpoints;\n};\n\n/**\n * @param {any[]} stack\n * @param {string} basePath\n * @param {Endpoint[]} endpoints\n * @param {'v4' | 'v5'} [version]\n * @returns {Endpoint[]}\n */\nconst parseStack = function (stack, basePath, endpoints, version) {\n stack.forEach((stackItem) => {\n if (stackItem.route) {\n const newEndpoints = parseExpressRoute(stackItem.route, basePath);\n\n endpoints = addEndpoints(endpoints, newEndpoints);\n } else if (stackItemValidNames.includes(stackItem.name)) {\n let newBasePath = basePath;\n\n if (version === \"v4\") {\n const isExpressPathRegExp = regExpToParseExpressPathRegExp.test(\n stackItem.regexp,\n );\n if (isExpressPathRegExp) {\n const parsedPath = parseExpressPathRegExp(\n stackItem.regexp,\n stackItem.keys,\n );\n newBasePath += `/${parsedPath}`;\n } else if (\n !stackItem.path &&\n stackItem.regexp &&\n stackItem.regexp.toString() !== rootPathRegExpValue\n ) {\n newBasePath += `/${formatRegExpRoutePath(stackItem.regexp)}`;\n }\n } else if (version === \"v5\") {\n if (!stackItem.path) {\n return;\n } else if (stackItem.path !== \"/\") {\n newBasePath += stackItem.path.startsWith(\"/\")\n ? stackItem.path\n : `/${stackItem.path}`;\n }\n }\n\n endpoints = parseEndpoints(stackItem.handle, newBasePath, endpoints);\n }\n });\n\n return endpoints;\n};\n\nexport const getEndpoints = function (app, basePath) {\n const endpoints = parseEndpoints(app);\n const standardHttpMethods = [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\"];\n return endpoints.flatMap((route) =>\n route.methods\n .filter((method) => standardHttpMethods.includes(method.toUpperCase()))\n .map((method) => ({\n method,\n path: (basePath + route.path).replace(/\\/\\//g, \"/\"),\n })),\n );\n};\n"],"mappings":";;AAgBA,MAAMA,iCACJ;AACF,MAAMC,yCAAyC;AAC/C,MAAMC,2BAA2B;AACjC,MAAMC,+BAA+B;AACrC,MAAMC,sBAAsB;AAC5B,MAAMC,sBAAsB;EAAC;EAAU;EAAkB;;AAQlD,MAAMC,6BAA6B,gCAAUC,MAAI;AACtD,SAAOA,KAAKC,QAAQL,8BAA8B,IAAA;AACpD,GAF0C;AAUnC,MAAMM,wBAAwB,gCAAUC,IAAE;AAC/C,SAAO,UAAUA,EAAAA;AACnB,GAFqC;AAS9B,MAAMC,gBAAgB,gCAAUC,KAAG;AAjD1C;AAkDE,MAAIA,IAAIC,OAAO;AAEb,WAAO;MAAEA,OAAOD,IAAIC;MAAOC,SAAS;IAAK;EAC3C,YAAWF,SAAIG,YAAJH,mBAAaC,OAAO;AAE7B,WAAO;MAAEA,OAAOD,IAAIG,QAAQF;MAAOC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jCwE,yBAAeF,UAAUtE,KAAK8C,WAAW,GAAA,IACrCwB,UAAUtE,OACV,IAAIsE,UAAUtE,IAAI;QACxB;MACF;AAEA+B,kBAAYsB,eAAeiB,UAAUjD,QAAQmD,aAAazC,SAAAA;IAC5D;EACF,CAAA;AAEA,SAAOA;AACT,GAzCmB;AA2CZ,MAAM6C,eAAe,gCAAUvE,KAAKsB,UAAQ;AACjD,QAAMI,YAAYsB,eAAehD,GAAAA;AACjC,QAAMwE,sBAAsB;IAAC;IAAO;IAAQ;IAAO;IAAU;;AAC7D,SAAO9C,UAAUC,QAAQ,CAACrB,UACxBA,MAAMC,QACHG,OAAO,CAACC,WAAW6D,oBAAoBV,SAASnD,OAAOE,YAAW,CAAA,CAAA,EAClED,IAAI,CAACD,YAAY;IAChBA;IACAhB,OAAO2B,WAAWhB,MAAMX,MAAMC,QAAQ,SAAS,GAAA;EACjD,EAAA,CAAA;AAEN,GAX4B;","names":["regExpToParseExpressPathRegExp","regExpToReplaceExpressPathRegExpParams","regExpExpressParamRegExp","regExpExpressPathParamRegExp","rootPathRegExpValue","stackItemValidNames","stripExpressPathParamRegex","path","replace","formatRegExpRoutePath","re","getRouterInfo","app","stack","version","_router","router","getRouteMethods","route","methods","Object","keys","filter","method","map","toUpperCase","getRouteMiddlewares","item","handle","name","hasParams","expressPathRegExp","test","parseExpressRoute","basePath","paths","Array","isArray","endpoints","flatMap","pathStr","RegExp","completePath","middlewares","parseExpressPathRegExp","parsedRegExp","toString","expressPathRegExpExec","exec","paramIndex","paramName","paramId","str","startsWith","parseExpressPath","expressPath","params","result","paramValue","entries","parseEndpoints","routerInfo","length","addEndpoints","parseStack","currentEndpoints","endpointsToAdd","forEach","newEndpoint","existingEndpoint","find","endpoint","undefined","newMethods","includes","concat","push","stackItem","newEndpoints","newBasePath","isExpressPathRegExp","regexp","parsedPath","getEndpoints","standardHttpMethods"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apitally",
3
- "version": "0.25.5",
3
+ "version": "0.25.7",
4
4
  "description": "Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.",
5
5
  "author": "Apitally <hello@apitally.io>",
6
6
  "license": "MIT",
@@ -287,11 +287,17 @@
287
287
  "optional": true
288
288
  }
289
289
  },
290
+ "overrides": {
291
+ "@arethetypeswrong/cli": {
292
+ "fflate": "0.8.2"
293
+ }
294
+ },
290
295
  "devDependencies": {
291
296
  "@adonisjs/core": "^7.0.0",
297
+ "@arethetypeswrong/cli": "^0.18.2",
292
298
  "@eslint/js": "^9.29.0",
293
299
  "@hapi/hapi": "^21.4.3",
294
- "@hono/zod-validator": "^0.7.0",
300
+ "@hono/zod-validator": "^0.8.0",
295
301
  "@koa/router": "^13.1.0",
296
302
  "@nestjs/common": "^11.0.0",
297
303
  "@nestjs/core": "^11.0.0",
@@ -323,7 +329,7 @@
323
329
  "fastify": "^5.0.0",
324
330
  "fastify-plugin": "^5.0.1",
325
331
  "globals": "^17.0.0",
326
- "h3": "2.0.1-rc.20",
332
+ "h3": "2.0.1-rc.22",
327
333
  "hono": "^4.6.5",
328
334
  "koa": "^3.0.0",
329
335
  "koa-bodyparser": "^4.4.1",