feat: Move the store to private.

This commit is contained in:
J H
2024-03-12 11:58:13 -06:00
parent 1f47abf195
commit ba325b1581
5 changed files with 31 additions and 31 deletions

View File

@@ -186,18 +186,30 @@ pub enum RevisionsRes {
#[serde(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
pub struct CliDumpParams {
#[arg(long = "include-private", short = 'p')]
#[serde(default)]
include_private: bool,
path: Option<PathBuf>,
}
#[instrument(skip_all)]
async fn cli_dump(
ctx: CliContext,
CliDumpParams { path }: CliDumpParams,
CliDumpParams {
path,
include_private,
}: CliDumpParams,
) -> Result<Dump, RpcError> {
let dump = if let Some(path) = path {
PatchDb::open(path).await?.dump(&ROOT).await
} else {
from_value::<Dump>(ctx.call_remote("db.dump", imbl_value::json!({})).await?)?
from_value::<Dump>(
ctx.call_remote(
"db.dump",
imbl_value::json!({ "include-private":include_private }),
)
.await?,
)?
};
Ok(dump)
@@ -216,14 +228,11 @@ pub async fn dump(
ctx: RpcContext,
DumpParams { include_private }: DumpParams,
) -> Result<Dump, Error> {
Ok(ctx
.db
.dump(&if include_private {
ROOT
} else {
PUBLIC.borrowed()
})
.await)
Ok(if include_private {
ctx.db.dump(&ROOT).await
} else {
ctx.db.dump(&PUBLIC).await
})
}
#[instrument(skip_all)]

View File

@@ -120,6 +120,7 @@ impl Database {
sessions: Sessions::new(),
notifications: Notifications::new(),
cifs: CifsTargets::new(),
package_stores: BTreeMap::new(),
}, // TODO
})
}
@@ -149,6 +150,8 @@ pub struct Private {
pub sessions: Sessions,
pub notifications: Notifications,
pub cifs: CifsTargets,
#[serde(default)]
pub package_stores: BTreeMap<PackageId, Value>,
}
#[derive(Debug, Deserialize, Serialize, HasModel)]
@@ -513,7 +516,6 @@ pub struct InstalledPackageInfo {
pub current_dependencies: CurrentDependencies,
pub interface_addresses: InterfaceAddressMap,
pub hosts: HostInfo,
pub store: Value,
pub store_exposed_ui: Vec<ExposedUI>,
pub store_exposed_dependents: Vec<JsonPointer>,
}

View File

@@ -49,14 +49,11 @@ pub async fn properties(
) -> Result<Value, Error> {
let peeked = ctx.db.peek().await;
let data = peeked
.as_public()
.as_package_data()
.as_private()
.as_package_stores()
.as_idx(&id)
.or_not_found(&id)?
.as_installed()
.or_not_found(&id)?
.as_store()
.de()?;
.map(|x| x.de())
.unwrap_or_else(|| Ok(json!({})))?;
Ok(peeked
.as_public()
.as_package_data()

View File

@@ -290,7 +290,6 @@ impl Service {
manifest: manifest.clone(),
last_backup: None, // TODO
hosts: Default::default(), // TODO
store: Value::Null, // TODO
store_exposed_dependents: Default::default(), // TODO
store_exposed_ui: Default::default(), // TODO
},

View File

@@ -300,13 +300,10 @@ async fn get_store(
let peeked = context.ctx.db.peek().await;
let package_id = package_id.unwrap_or(context.id.clone());
let value = peeked
.as_public()
.as_package_data()
.as_private()
.as_package_stores()
.as_idx(&package_id)
.or_not_found(&package_id)?
.as_installed()
.or_not_found(&package_id)?
.as_store()
.de()?;
Ok(path
@@ -332,13 +329,9 @@ async fn set_store(
.db
.mutate(|db| {
let model = db
.as_public_mut()
.as_package_data_mut()
.as_idx_mut(&package_id)
.or_not_found(&package_id)?
.as_installed_mut()
.or_not_found(&package_id)?
.as_store_mut();
.as_private_mut()
.as_package_stores_mut()
.upsert(&package_id, || Box::new(json!({})))?;
let mut model_value = model.de()?;
if model_value.is_null() {
model_value = json!({});