╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1000 const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; 1001 const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); 1002 1003 // get the map of repos 1004 const event_id_to_repo_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->repo")) orelse return error.NotFound; 1005 const event_id_to_repo = try Repo.DB.HashMap(.read_only).init(event_id_to_repo_cursor); 1006 1007 try std.testing.expect(null == try event_id_to_repo.getCursor(hash.hashInt(repo_opts.hash, &repo_event_id))); 1008 1009 // get the repos created by the user 1010 const user_id_to_repos_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "user-id->repos")) orelse return error.NotFound; 1011 const user_id_to_repos = try Repo.DB.HashMap(.read_only).init(user_id_to_repos_cursor); 1012 1013 const user_repos_cursor = try user_id_to_repos.getCursor(hash.hashInt(repo_opts.hash, &user_event_id)) orelse return error.NotFound; 1014 const user_repos = try Repo.DB.CountedHashSet(.read_only).init(user_repos_cursor); 1015 1016 try std.testing.expectEqual(0, try user_repos.count()); 1017 try std.testing.expect(null == try user_repos.getCursor(hash.hashInt(repo_opts.hash, &repo_event_id))); 1018 } 1019 1020 // 1021 // remove the user 1022 // 1023 1024 const events_to_consume3 = [_]evt.EventWithId{ 1025 .{ 1026 .id = std.fmt.bytesToHex(user_event_id, .lower), 1027 .event = .{ .user = null }, 1028 }, 1029 }; 1030 1031 { 1032 var json: std.Io.Writer.Allocating = .init(allocator); 1033 defer json.deinit(); 1034 1035 for (events_to_consume3) |event| { 1036 json.clearRetainingCapacity(); 1037 1038 try std.json.Stringify.value(event, .{}, &json.writer); 1039 1040 // commit the event into a special branch 1041 _ = try repo.commitAtRef(io, allocator, .{ .message = json.written() }, null, .{ .kind = .head, .name = "haxy/meta" }); 1042 } 1043 } 1044 1045 // 1046 // consume the user removal into the database 1047 // 1048 1049 { 1050 try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); 1051 1052 const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); 1053 1054 // read the moment we just created 1055 const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; 1056 const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); 1057 1058 // get the last object id 1059 const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound; 1060 var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; 1061 _ = try last_object_id_cursor.readBytes(&last_object_id); 1062 1063 const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; 1064 const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); 1065 1066 try std.testing.expectEqual(3, try haxy.count()); 1067 1068 const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; 1069 const haxy_moments = try Repo.DB.HashMap(.read_only).init(haxy_moments_cursor); 1070 1071 const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; 1072 const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); 1073 1074 // get the map of users 1075 const event_id_to_user_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->user")) orelse return error.NotFound; 1076 const event_id_to_user = try Repo.DB.HashMap(.read_only).init(event_id_to_user_cursor); 1077 1078 try std.testing.expect(null == try event_id_to_user.getCursor(hash.hashInt(repo_opts.hash, &user_event_id))); 1079 } 1080 } 1081