SuiteCoffee/packages/devices/i60/namesProxy.mjs
2025-10-16 19:49:50 +00:00

19 lines
621 B
JavaScript

// Proxy de servicio de nombres (caché + normalización)
export class NamesServiceProxy {
constructor(fetchNamesForDocs){
this._fetch = typeof fetchNamesForDocs === 'function' ? fetchNamesForDocs : async () => ({});
this._cache = new Map();
}
async get(docs){
const ask = [];
for (const d of docs) if (!this._cache.has(d)) ask.push(d);
if (ask.length){
const map = await this._fetch(ask);
for (const [k,v] of Object.entries(map || {})) this._cache.set(String(k), v || {});
}
const out = {};
for (const d of docs) out[d] = this._cache.get(d) || {};
return out;
}
}