╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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