╭ changed ─────────╮ │src/event/User.zig│ ╰──────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │143 const user_cursor = try event_id_to_user.getCursor(hash.hashInt(hash_kind, user_id)) orelse return null; │ │144 const user_map = try DB.HashMap(.read_only).init(user_cursor); │ │145 return try evt.read(@This(), DB, hash_kind, arena, user_map); │ │146 +} │ │147 + │ │148 +// read a user by name from the admin event store, or null if the admin repo or │ │149 +// the user doesn't exist. field byte slices are allocated in `arena`. │ │150 +pub fn readByName( │ │151 + io: std.Io, │ │152 + allocator: std.mem.Allocator, │ │153 + admin_repo_path: []const u8, │ │154 + arena: *std.heap.ArenaAllocator, │ │155 + name: []const u8, │ │156 +) !?Self { │ │157 + var repo = rp.Repo(.xit, evt.admin_repo_opts).open(io, allocator, .{ .path = admin_repo_path }) catch |err| switch (err) { │ │158 + error.RepoNotFound => return null, │ │159 + else => |e| return e, │ │160 + }; │ │161 + defer repo.deinit(io, allocator); │ │162 + │ │163 + const moment = try evt.currentMoment(evt.admin_repo_opts, &repo); │ │164 + │ │165 + const name_to_user_id_cursor = try moment.getCursor(hash.hashInt(evt.admin_repo_opts.hash, "name->user-id")) orelse return null;│ │166 + const name_to_user_id = try evt.AdminDB.HashMap(.read_only).init(name_to_user_id_cursor); │ │167 + const user_id_cursor = try name_to_user_id.getCursor(hash.hashInt(evt.admin_repo_opts.hash, name)) orelse return null; │ │168 + var user_id: [evt.event_id_size]u8 = undefined; │ │169 + _ = try user_id_cursor.readBytes(&user_id); │ │170 + │ │171 + return try readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, &user_id); │ │172 } │ │173 │ │174 // flip a user's ANSI-art preference by re-emitting their User event with │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯