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