UNPKG

apitally

Version:

Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, and Koa.

57 lines (56 loc) 1.87 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/common/validationErrorCounter.ts import { createHash } from "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 createHash("md5").update(hashInput).digest("hex"); } }; __name(_ValidationErrorCounter, "ValidationErrorCounter"); var ValidationErrorCounter = _ValidationErrorCounter; export { ValidationErrorCounter as default }; //# sourceMappingURL=validationErrorCounter.js.map