Review this AI-generated request index against its stated task.
Index up to 100,000 public request payloads by case-insensitive tenant and arbitrary external ID, preserve stored null, bound each key field to 128 characters, and keep lookup work independent of payload size.
JavaScript
function createRequestIndex(maxEntries = 100_000) {
const entries = new Map();
function key(tenant, externalId) {
return `${tenant.toLowerCase()}:${externalId}`;
}
return {
set(tenant, externalId, payload) {
const compound = key(tenant, externalId);
if (!entries.has(compound) && entries.size >= maxEntries) {
throw new RangeError("index is full");
}
entries.set(compound, payload);
},
get(tenant, externalId) {
const compound = `${tenant.trim().toLowerCase()}:${externalId}`;
return structuredClone(entries.get(compound) ?? null);
},
has(tenant, externalId) {
return entries.has(key(tenant, externalId));
},
};
}
generated code is illustrative, not from any one model