Skip to content

Commit

Permalink
[bfops/remove-expand]: do thing
Browse files Browse the repository at this point in the history
  • Loading branch information
bfops committed Sep 27, 2024
1 parent 5375842 commit b399a95
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
11 changes: 1 addition & 10 deletions crates/cli/src/subcommands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub fn cli() -> clap::Command {
.requires("entity_type")
.help("The name of the entity to describe"),
)
.arg(Arg::new("brief").long("brief").short('b').action(SetTrue)
.help("If this flag is present, a brief description shall be returned"))
.arg(
common_args::identity()
.conflicts_with("anon_identity")
Expand All @@ -46,7 +44,6 @@ pub fn cli() -> clap::Command {

pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
let database = args.get_one::<String>("database").unwrap();
let expand = !args.get_flag("brief");
let entity_name = args.get_one::<String>("entity_name");
let entity_type = args.get_one::<String>("entity_type");
let server = args.get_one::<String>("server").map(|s| s.as_ref());
Expand All @@ -69,13 +66,7 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
let auth_header = get_auth_header_only(&mut config, anon_identity, identity, server).await?;
let builder = add_auth_header_opt(builder, &auth_header);

let descr = builder
.query(&[("expand", expand)])
.send()
.await?
.error_for_status()?
.text()
.await?;
let descr = builder.send().await?.error_for_status()?.text().await?;
println!("{}", descr);

Ok(())
Expand Down
47 changes: 20 additions & 27 deletions crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl<'a> EntityDef<'a> {
}
}

fn entity_description_json(description: WithTypespace<EntityDef>, expand: bool) -> Option<Value> {
fn entity_description_json(description: WithTypespace<EntityDef>) -> Option<Value> {
let typ = description.ty().described_entity_ty().as_str();
let len = match description.ty() {
EntityDef::Table(t) => description
Expand All @@ -233,32 +233,25 @@ fn entity_description_json(description: WithTypespace<EntityDef>, expand: bool)
.len(),
EntityDef::Reducer(r) => r.params.elements.len(),
};
if expand {
// TODO(noa): make this less hacky; needs coordination w/ spacetime-web
let schema = match description.ty() {
EntityDef::Table(table) => {
json!(description
.with(&table.product_type_ref)
.resolve_refs()
.ok()?
.as_product()?)
}
EntityDef::Reducer(r) => json!({
"name": &r.name[..],
"elements": r.params.elements,
}),
};
Some(json!({
"type": typ,
"arity": len,
"schema": schema
}))
} else {
Some(json!({
"type": typ,
"arity": len,
}))
}
// TODO(noa): make this less hacky; needs coordination w/ spacetime-web
let schema = match description.ty() {
EntityDef::Table(table) => {
json!(description
.with(&table.product_type_ref)
.resolve_refs()
.ok()?
.as_product()?)
}
EntityDef::Reducer(r) => json!({
"name": &r.name[..],
"elements": r.params.elements,
}),
};
Some(json!({
"type": typ,
"arity": len,
"schema": schema
}))
}

#[derive(Deserialize)]
Expand Down

0 comments on commit b399a95

Please sign in to comment.