在这段生成的授权事件索引处理生产日志前,对它进行审查。
构建以稳定用户 ID 为键的 Map。为每个用户保留唯一的公开角色名,只统计 allowed 严格等于 false 的记录,并且不保留完整事件或访问令牌。
JavaScript
function indexAccess(events) {
const byUser = new Map();
for (const event of events) {
const userKey = { id: event.userId };
const summary = byUser.get(userKey) ?? {
roles: [],
denied: 0,
events: [],
};
if (!event.allowed) summary.denied += 1;
summary.roles.push(event.role);
summary.events.push(event);
byUser.set(userKey, summary);
}
return byUser;
}
生成代码仅作示例,不代表任何特定模型