chore: Delete sled-state-inspector

The sled store is on its way out and nobody is using this.
pull/1553/head
Jonas Platte 2023-02-22 12:32:54 +01:00 committed by Jonas Platte
parent b1062a67e0
commit 95f1867816
7 changed files with 3 additions and 592 deletions

View File

@ -101,8 +101,8 @@ section aims at listing all the scopes used inside this project:
</tr>
<tr>
<td>Labs</td>
<td><code>sled-state-inspector</code></td>
<td>About the <code>sled-state-inspector</code> project.</td>
<td><code>jack-in</code></td>
<td>About the <code>jack-in</code> project.</td>
</tr>
<tr>
<td>Continuous Integration</td>

201
Cargo.lock generated
View File

@ -426,21 +426,6 @@ dependencies = [
"serde",
]
[[package]]
name = "bit-set"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitflags"
version = "1.3.2"
@ -772,17 +757,6 @@ dependencies = [
"os_str_bytes",
]
[[package]]
name = "clipboard-win"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362"
dependencies = [
"error-code",
"str-buf",
"winapi",
]
[[package]]
name = "cmake"
version = "0.1.49"
@ -1262,16 +1236,6 @@ dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
@ -1283,17 +1247,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "discard"
version = "1.0.4"
@ -1357,12 +1310,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "endian-type"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
[[package]]
name = "errno"
version = "0.2.8"
@ -1384,16 +1331,6 @@ dependencies = [
"libc",
]
[[package]]
name = "error-code"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21"
dependencies = [
"libc",
"str-buf",
]
[[package]]
name = "event-listener"
version = "2.5.3"
@ -1572,16 +1509,6 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "fancy-regex"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d6b8560a05112eb52f04b00e5d3790c0dd75d9d980eb8a122fb23b92a623ccf"
dependencies = [
"bit-set",
"regex",
]
[[package]]
name = "fastrand"
version = "1.9.0"
@ -1591,17 +1518,6 @@ dependencies = [
"instant",
]
[[package]]
name = "fd-lock"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ef1a30ae415c3a691a4f41afddc2dbcd6d70baf338368d85ebc1e8ed92cedb9"
dependencies = [
"cfg-if",
"rustix",
"windows-sys 0.45.0",
]
[[package]]
name = "findshlibs"
version = "0.10.2"
@ -3228,15 +3144,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"
[[package]]
name = "nibble_vec"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43"
dependencies = [
"smallvec",
]
[[package]]
name = "nix"
version = "0.24.3"
@ -3248,18 +3155,6 @@ dependencies = [
"libc",
]
[[package]]
name = "nix"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
dependencies = [
"autocfg",
"bitflags",
"cfg-if",
"libc",
]
[[package]]
name = "nom"
version = "7.1.3"
@ -3793,7 +3688,7 @@ dependencies = [
"inferno",
"libc",
"log",
"nix 0.24.3",
"nix",
"once_cell",
"parking_lot 0.12.1",
"smallvec",
@ -3979,16 +3874,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "radix_trie"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd"
dependencies = [
"endian-type",
"nibble_vec",
]
[[package]]
name = "rand"
version = "0.7.3"
@ -4428,40 +4313,6 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
[[package]]
name = "rustyline"
version = "10.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1e83c32c3f3c33b08496e0d1df9ea8c64d39adb8eb36a1ebb1440c690697aef"
dependencies = [
"bitflags",
"cfg-if",
"clipboard-win",
"dirs-next",
"fd-lock",
"libc",
"log",
"memchr",
"nix 0.25.1",
"radix_trie",
"scopeguard",
"unicode-segmentation",
"unicode-width",
"utf8parse",
"winapi",
]
[[package]]
name = "rustyline-derive"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "107c3d5d7f370ac09efa62a78375f94d94b8a33c61d8c278b96683fb4dbf2d8d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "ryu"
version = "1.0.12"
@ -4804,23 +4655,6 @@ dependencies = [
"parking_lot 0.11.2",
]
[[package]]
name = "sled-state-inspector"
version = "0.1.0"
dependencies = [
"atty",
"clap 3.2.23",
"futures",
"matrix-sdk-base",
"matrix-sdk-sled",
"ruma",
"rustyline",
"rustyline-derive",
"serde",
"serde_json",
"syntect",
]
[[package]]
name = "sliding-sync-integration-test"
version = "0.1.0"
@ -4890,12 +4724,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "str-buf"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0"
[[package]]
name = "str_stack"
version = "0.1.0"
@ -4966,27 +4794,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "syntect"
version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6c454c27d9d7d9a84c7803aaa3c50cd088d2906fe3c6e42da3209aa623576a8"
dependencies = [
"bincode",
"bitflags",
"fancy-regex",
"flate2",
"fnv",
"lazy_static",
"once_cell",
"regex-syntax",
"serde",
"serde_derive",
"serde_json",
"thiserror",
"walkdir",
]
[[package]]
name = "tempfile"
version = "3.3.0"
@ -5819,12 +5626,6 @@ dependencies = [
"serde",
]
[[package]]
name = "utf8parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
name = "uuid"
version = "1.3.0"

View File

@ -1,22 +0,0 @@
[package]
name = "sled-state-inspector"
version = "0.1.0"
edition = "2021"
publish = false
[[bin]]
name = "sled-state-inspector"
test = false
[dependencies]
atty = "0.2.14"
clap = "3.2.4"
futures = { version = "0.3.21", default-features = false, features = ["executor"] }
matrix-sdk-base = { path = "../../crates/matrix-sdk-base", version = "0.6.0"}
matrix-sdk-sled = { path = "../../crates/matrix-sdk-sled", version = "0.2.0"}
ruma = { workspace = true }
rustyline = "10.0.0"
rustyline-derive = "0.7.0"
serde = { workspace = true }
serde_json = { workspace = true }
syntect = { version = "5.0.0", default-features = false, features = ["dump-load", "parsing", "regex-fancy"] }

View File

@ -1,367 +0,0 @@
use std::{fmt::Debug, sync::Arc};
use atty::Stream;
use clap::{Arg, ArgMatches, Command as Argparse};
use futures::executor::block_on;
use matrix_sdk_base::{RoomInfo, StateStore};
use matrix_sdk_sled::SledStateStore;
use ruma::{events::StateEventType, OwnedRoomId, OwnedUserId, RoomId};
use rustyline::{
completion::{Completer, Pair},
error::ReadlineError,
highlight::{Highlighter, MatchingBracketHighlighter},
hint::{Hinter, HistoryHinter},
validate::{MatchingBracketValidator, Validator},
CompletionType, Config, Context, EditMode, Editor,
};
use rustyline_derive::Helper;
use serde::Serialize;
use syntect::{
dumps::from_binary,
easy::HighlightLines,
highlighting::{Style, ThemeSet},
parsing::SyntaxSet,
util::{as_24_bit_terminal_escaped, LinesWithEndings},
};
#[derive(Clone)]
struct Inspector {
store: Arc<SledStateStore>,
printer: Printer,
}
#[derive(Helper)]
struct InspectorHelper {
store: Arc<SledStateStore>,
_highlighter: MatchingBracketHighlighter,
_validator: MatchingBracketValidator,
_hinter: HistoryHinter,
}
impl InspectorHelper {
const EVENT_TYPES: &'static [&'static str] = &[
"m.room.aliases",
"m.room.avatar",
"m.room.canonical_alias",
"m.room.create",
"m.room.encryption",
"m.room.guest_access",
"m.room.history_visibility",
"m.room.join_rules",
"m.room.name",
"m.room.power_levels",
"m.room.tombstone",
"m.room.topic",
];
fn new(store: Arc<SledStateStore>) -> Self {
Self {
store,
_highlighter: MatchingBracketHighlighter::new(),
_validator: MatchingBracketValidator::new(),
_hinter: HistoryHinter {},
}
}
fn complete_event_types(&self, arg: Option<&&str>) -> Vec<Pair> {
Self::EVENT_TYPES
.iter()
.map(|&t| Pair { display: t.to_owned(), replacement: format!("{t} ") })
.filter(|r| if let Some(arg) = arg { r.replacement.starts_with(arg) } else { true })
.collect()
}
fn complete_rooms(&self, arg: Option<&&str>) -> Vec<Pair> {
let rooms: Vec<RoomInfo> =
block_on(async { StateStore::get_room_infos(&*self.store).await.unwrap() });
rooms
.into_iter()
.map(|r| Pair {
display: r.room_id().to_string(),
replacement: format!("{} ", r.room_id()),
})
.filter(|r| if let Some(arg) = arg { r.replacement.starts_with(arg) } else { true })
.collect()
}
}
impl Completer for InspectorHelper {
type Candidate = Pair;
fn complete(
&self,
line: &str,
pos: usize,
_: &Context<'_>,
) -> Result<(usize, Vec<Pair>), ReadlineError> {
let args: Vec<&str> = line.split_ascii_whitespace().collect();
let commands = vec![
("get-state", "get a state event in the given room"),
("get-profiles", "get all the stored profiles in the given room"),
("list-rooms", "list all rooms"),
("get-members", "get all the membership events in the given room"),
]
.iter()
.map(|(r, d)| Pair { display: format!("{r} ({d})"), replacement: format!("{r} ") })
.collect();
if args.is_empty() {
Ok((pos, commands))
} else if args.len() == 1 {
if (args[0] == "get-state" || args[0] == "get-members" || args[0] == "get-profiles")
&& line.ends_with(' ')
{
Ok((args[0].len() + 1, self.complete_rooms(args.get(1))))
} else {
Ok((
0,
commands.into_iter().filter(|c| c.replacement.starts_with(args[0])).collect(),
))
}
} else if args.len() == 2 {
if args[0] == "get-state" {
if line.ends_with(' ') {
Ok((args[0].len() + args[1].len() + 2, self.complete_event_types(args.get(2))))
} else {
Ok((args[0].len() + 1, self.complete_rooms(args.get(1))))
}
} else if args[0] == "get-members" || args[0] == "get-profiles" {
Ok((args[0].len() + 1, self.complete_rooms(args.get(1))))
} else {
Ok((pos, vec![]))
}
} else if args.len() == 3 {
if args[0] == "get-state" {
Ok((args[0].len() + args[1].len() + 2, self.complete_event_types(args.get(2))))
} else {
Ok((pos, vec![]))
}
} else {
Ok((pos, vec![]))
}
}
}
impl Hinter for InspectorHelper {
type Hint = String;
}
impl Highlighter for InspectorHelper {}
impl Validator for InspectorHelper {}
#[derive(Clone, Debug)]
struct Printer {
ps: Arc<SyntaxSet>,
ts: Arc<ThemeSet>,
json: bool,
color: bool,
}
impl Printer {
fn new(json: bool, color: bool) -> Self {
let syntax_set: SyntaxSet = from_binary(include_bytes!("../syntaxes.bin"));
let themes: ThemeSet = from_binary(include_bytes!("../themes.bin"));
Self { ps: syntax_set.into(), ts: themes.into(), json, color }
}
fn pretty_print_struct<T: Debug + Serialize>(&self, data: &T) {
let data = if self.json {
serde_json::to_string_pretty(data).expect("Can't serialize struct")
} else {
format!("{data:#?}")
};
let syntax = if self.json {
self.ps.find_syntax_by_extension("rs").expect("Can't find rust syntax extension")
} else {
self.ps.find_syntax_by_extension("json").expect("Can't find json syntax extension")
};
if self.color {
let mut h = HighlightLines::new(syntax, &self.ts.themes["Forest Night"]);
for line in LinesWithEndings::from(&data) {
let ranges: Vec<(Style, &str)> =
h.highlight_line(line, &self.ps).expect("Failed to highlight line");
let escaped = as_24_bit_terminal_escaped(&ranges[..], false);
print!("{escaped}");
}
// Clear the formatting
println!("\x1b[0m");
} else {
println!("{data}");
}
}
}
impl Inspector {
fn new(database_path: &str, json: bool, color: bool) -> Self {
let printer = Printer::new(json, color);
let store = Arc::new(
SledStateStore::builder()
.path(database_path.into())
.build()
.expect("Can't open sled database"),
);
Self { store, printer }
}
async fn run(&self, matches: ArgMatches) {
match matches.subcommand() {
Some(("get-profiles", args)) => {
let room_id = RoomId::parse(args.value_of("room-id").unwrap()).unwrap();
self.get_profiles(room_id).await;
}
Some(("get-members", args)) => {
let room_id = RoomId::parse(args.value_of("room-id").unwrap()).unwrap();
self.get_members(room_id).await;
}
Some(("list-rooms", _)) => self.list_rooms().await,
Some(("get-display-names", args)) => {
let room_id = RoomId::parse(args.value_of("room-id").unwrap()).unwrap();
let display_name = args.value_of("display-name").unwrap().to_owned();
self.get_display_name_owners(room_id, display_name).await;
}
Some(("get-state", args)) => {
let room_id = RoomId::parse(args.value_of("room-id").unwrap()).unwrap();
let event_type =
StateEventType::try_from(args.value_of("event-type").unwrap()).unwrap();
self.get_state(room_id, event_type).await;
}
_ => unreachable!(),
}
}
async fn list_rooms(&self) {
let rooms: Vec<RoomInfo> = StateStore::get_room_infos(&*self.store).await.unwrap();
self.printer.pretty_print_struct(&rooms);
}
async fn get_display_name_owners(&self, room_id: OwnedRoomId, display_name: String) {
let users = self.store.get_users_with_display_name(&room_id, &display_name).await.unwrap();
self.printer.pretty_print_struct(&users);
}
async fn get_profiles(&self, room_id: OwnedRoomId) {
let joined: Vec<OwnedUserId> =
StateStore::get_joined_user_ids(&*self.store, &room_id).await.unwrap();
for member in joined {
let event = self.store.get_profile(&room_id, &member).await.unwrap();
self.printer.pretty_print_struct(&event);
}
}
async fn get_members(&self, room_id: OwnedRoomId) {
let joined: Vec<OwnedUserId> =
StateStore::get_joined_user_ids(&*self.store, &room_id).await.unwrap();
for member in joined {
let event = self.store.get_member_event(&room_id, &member).await.unwrap();
self.printer.pretty_print_struct(&event);
}
}
async fn get_state(&self, room_id: OwnedRoomId, event_type: StateEventType) {
self.printer.pretty_print_struct(
&self.store.get_state_event(&room_id, event_type, "").await.unwrap(),
);
}
fn subcommands() -> Vec<Argparse<'static>> {
vec![
Argparse::new("list-rooms"),
Argparse::new("get-members").arg(Arg::new("room-id").required(true).validator(|r| {
RoomId::parse(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
})),
Argparse::new("get-profiles").arg(Arg::new("room-id").required(true).validator(|r| {
RoomId::parse(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
})),
Argparse::new("get-display-names")
.arg(Arg::new("room-id").required(true).validator(|r| {
RoomId::parse(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
}))
.arg(Arg::new("display-name").required(true)),
Argparse::new("get-state")
.arg(Arg::new("room-id").required(true).validator(|r| {
RoomId::parse(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
}))
.arg(Arg::new("event-type").required(true).validator(|e| {
StateEventType::try_from(e)
.map(|_| ())
.map_err(|_| "Invalid event type".to_owned())
})),
]
}
async fn parse_and_run(&self, input: &str) {
let argparse = Argparse::new("state-inspector")
.disable_version_flag(true)
.disable_help_flag(true)
.no_binary_name(true)
.subcommand_required(true)
.arg_required_else_help(true)
.subcommands(Inspector::subcommands());
match argparse.try_get_matches_from(input.split_ascii_whitespace()) {
Ok(m) => {
self.run(m).await;
}
Err(e) => {
println!("{e}");
}
}
}
}
fn main() {
let argparse = Argparse::new("state-inspector")
.disable_version_flag(true)
.arg(Arg::new("database").required(true))
.arg(
Arg::new("json")
.long("json")
.help("set the output to raw json instead of Rust structs")
.global(true)
.takes_value(false),
)
.subcommands(Inspector::subcommands());
let matches = argparse.get_matches();
let database_path = matches.value_of("database").expect("No database path");
let json = matches.is_present("json");
let color = atty::is(Stream::Stdout);
let inspector = Inspector::new(database_path, json, color);
if matches.subcommand().is_none() {
let config = Config::builder()
.history_ignore_space(true)
.completion_type(CompletionType::List)
.edit_mode(EditMode::Emacs)
.build();
let helper = InspectorHelper::new(inspector.store.clone());
let mut rl =
Editor::<InspectorHelper>::with_config(config).expect("Failed to create Editor");
rl.set_helper(Some(helper));
while let Ok(input) = rl.readline(">> ") {
rl.add_history_entry(input.as_str());
block_on(inspector.parse_and_run(input.as_str()));
}
} else {
block_on(inspector.run(matches));
}
}

Binary file not shown.

View File

@ -23,7 +23,6 @@ exclude = [
"matrix-sdk-test-macros",
# labs
"jack-in",
"sled-state-inspector",
# repo automation (ci, codegen)
"uniffi-bindgen",
"xtask",