apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, Hono, H3, Koa, and NestJS.
107 lines (105 loc) • 2.79 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/common/packageVersions.ts
import { createRequire } from "module";
function getPackageVersion(name) {
const packageJsonPath = `${name}/package.json`;
try {
return __require(packageJsonPath).version || null;
} catch (error) {
try {
const _require = createRequire(import.meta.url);
return _require(packageJsonPath).version || null;
} catch (error2) {
return null;
}
}
}
__name(getPackageVersion, "getPackageVersion");
// src/h3/utils.ts
function getAppInfo(h3, appVersion) {
const routes = h3._routes ? listAllRoutes(h3._routes.root) : [];
const versions = [];
if (process.versions.node) {
versions.push([
"nodejs",
process.versions.node
]);
}
if (process.versions.bun) {
versions.push([
"bun",
process.versions.bun
]);
}
const h3Version = getPackageVersion("h3");
const apitallyVersion = getPackageVersion("../..");
if (h3Version) {
versions.push([
"h3",
h3Version
]);
}
if (apitallyVersion) {
versions.push([
"apitally",
apitallyVersion
]);
}
if (appVersion) {
versions.push([
"app",
appVersion
]);
}
return {
paths: routes.map((route) => ({
method: route.method || "",
path: route.route || ""
})).filter((route) => route.method && route.path),
versions: Object.fromEntries(versions),
client: "js:h3"
};
}
__name(getAppInfo, "getAppInfo");
function listAllRoutes(node) {
const routes = [];
_collectAllRoutes(node, routes);
return routes;
}
__name(listAllRoutes, "listAllRoutes");
function _collectAllRoutes(node, routes = []) {
if (node.methods) {
for (const methodData of Object.values(node.methods)) {
if (Array.isArray(methodData)) {
for (const item of methodData) {
if (item.data) {
routes.push(item.data);
}
}
}
}
}
if (node.static) {
for (const staticChild of Object.values(node.static)) {
_collectAllRoutes(staticChild, routes);
}
}
if (node.param) {
_collectAllRoutes(node.param, routes);
}
if (node.wildcard) {
_collectAllRoutes(node.wildcard, routes);
}
}
__name(_collectAllRoutes, "_collectAllRoutes");
export {
getAppInfo
};
//# sourceMappingURL=utils.js.map