apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, and Koa.
76 lines (75 loc) • 2.81 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/common/validationErrorCounter.ts
var validationErrorCounter_exports = {};
__export(validationErrorCounter_exports, {
default: () => ValidationErrorCounter
});
module.exports = __toCommonJS(validationErrorCounter_exports);
var import_node_crypto = require("crypto");
var _ValidationErrorCounter = class _ValidationErrorCounter {
errorCounts;
errorDetails;
constructor() {
this.errorCounts = /* @__PURE__ */ new Map();
this.errorDetails = /* @__PURE__ */ new Map();
}
addValidationError(validationError) {
const key = this.getKey(validationError);
if (!this.errorDetails.has(key)) {
this.errorDetails.set(key, validationError);
}
this.errorCounts.set(key, (this.errorCounts.get(key) || 0) + 1);
}
getAndResetValidationErrors() {
const data = [];
this.errorCounts.forEach((count, key) => {
const validationError = this.errorDetails.get(key);
if (validationError) {
data.push({
consumer: validationError.consumer || null,
method: validationError.method,
path: validationError.path,
loc: validationError.loc.split(".").filter(Boolean),
msg: validationError.msg,
type: validationError.type,
error_count: count
});
}
});
this.errorCounts.clear();
this.errorDetails.clear();
return data;
}
getKey(validationError) {
const hashInput = [
validationError.consumer || "",
validationError.method.toUpperCase(),
validationError.path,
validationError.loc.split(".").filter(Boolean),
validationError.msg.trim(),
validationError.type
].join("|");
return (0, import_node_crypto.createHash)("md5").update(hashInput).digest("hex");
}
};
__name(_ValidationErrorCounter, "ValidationErrorCounter");
var ValidationErrorCounter = _ValidationErrorCounter;
//# sourceMappingURL=validationErrorCounter.cjs.map