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