UNPKG

apitally

Version:

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

86 lines (85 loc) 3.11 kB
"use strict"; 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/consumerRegistry.ts var consumerRegistry_exports = {}; __export(consumerRegistry_exports, { consumerFromStringOrObject: () => consumerFromStringOrObject, default: () => ConsumerRegistry }); module.exports = __toCommonJS(consumerRegistry_exports); var consumerFromStringOrObject = /* @__PURE__ */ __name((consumer) => { var _a, _b; if (typeof consumer === "string") { consumer = String(consumer).trim().substring(0, 128); return consumer ? { identifier: consumer } : null; } else { consumer.identifier = String(consumer.identifier).trim().substring(0, 128); consumer.name = (_a = consumer.name) == null ? void 0 : _a.trim().substring(0, 64); consumer.group = (_b = consumer.group) == null ? void 0 : _b.trim().substring(0, 64); return consumer.identifier ? consumer : null; } }, "consumerFromStringOrObject"); var _ConsumerRegistry = class _ConsumerRegistry { consumers; updated; constructor() { this.consumers = /* @__PURE__ */ new Map(); this.updated = /* @__PURE__ */ new Set(); } addOrUpdateConsumer(consumer) { if (!consumer || !consumer.name && !consumer.group) { return; } const existing = this.consumers.get(consumer.identifier); if (!existing) { this.consumers.set(consumer.identifier, consumer); this.updated.add(consumer.identifier); } else { if (consumer.name && consumer.name !== existing.name) { existing.name = consumer.name; this.updated.add(consumer.identifier); } if (consumer.group && consumer.group !== existing.group) { existing.group = consumer.group; this.updated.add(consumer.identifier); } } } getAndResetUpdatedConsumers() { const data = []; this.updated.forEach((identifier) => { const consumer = this.consumers.get(identifier); if (consumer) { data.push(consumer); } }); this.updated.clear(); return data; } }; __name(_ConsumerRegistry, "ConsumerRegistry"); var ConsumerRegistry = _ConsumerRegistry; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { consumerFromStringOrObject }); //# sourceMappingURL=consumerRegistry.cjs.map