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