mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
chore: Update the types
This commit is contained in:
@@ -303,7 +303,7 @@ pub struct PackageDataEntry {
|
||||
pub current_dependencies: CurrentDependencies,
|
||||
pub interface_addresses: InterfaceAddressMap,
|
||||
pub hosts: HostInfo,
|
||||
pub store_exposed_ui: Vec<ExposedUI>,
|
||||
pub store_exposed_ui: StoreExposedUI,
|
||||
pub store_exposed_dependents: Vec<JsonPointer>,
|
||||
}
|
||||
impl AsRef<PackageDataEntry> for PackageDataEntry {
|
||||
@@ -322,17 +322,39 @@ pub struct ExposedDependent {
|
||||
copyable: Option<bool>,
|
||||
qr: Option<bool>,
|
||||
}
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, HasModel, TS)]
|
||||
#[model = "Model<Self>"]
|
||||
#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StoreExposedUI(pub BTreeMap<InternedString, ExposedUI>);
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(tag = "type")]
|
||||
#[ts(export)]
|
||||
pub struct ExposedUI {
|
||||
#[ts(type = "string")]
|
||||
pub path: JsonPointer,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub masked: Option<bool>,
|
||||
pub copyable: Option<bool>,
|
||||
pub qr: Option<bool>,
|
||||
pub enum ExposedUI {
|
||||
Object {
|
||||
#[ts(type = "{[key: string]: ExposedUI}")]
|
||||
value: BTreeMap<String, ExposedUI>,
|
||||
#[serde(default)]
|
||||
#[ts(type = "string | null")]
|
||||
description: String,
|
||||
},
|
||||
String {
|
||||
#[ts(type = "string")]
|
||||
path: JsonPointer,
|
||||
description: Option<String>,
|
||||
masked: bool,
|
||||
copyable: Option<bool>,
|
||||
qr: Option<bool>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Default for ExposedUI {
|
||||
fn default() -> Self {
|
||||
ExposedUI::Object {
|
||||
value: BTreeMap::new(),
|
||||
description: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use clap::Parser;
|
||||
use imbl_value::{json, Value};
|
||||
use imbl_value::{json, InOMap, InternedString, Value};
|
||||
use models::PackageId;
|
||||
use rpc_toolkit::command;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::context::RpcContext;
|
||||
use crate::db::model::package::ExposedUI;
|
||||
use crate::prelude::*;
|
||||
use crate::Error;
|
||||
use crate::{context::RpcContext, db::model::package::StoreExposedUI};
|
||||
|
||||
pub fn display_properties(response: Value) {
|
||||
println!("{}", response);
|
||||
@@ -16,24 +18,42 @@ pub fn display_properties(response: Value) {
|
||||
trait IntoProperties {
|
||||
fn into_properties(self, store: &Value) -> Value;
|
||||
}
|
||||
impl IntoProperties for Vec<ExposedUI> {
|
||||
impl IntoProperties for ExposedUI {
|
||||
fn into_properties(self, store: &Value) -> Value {
|
||||
let mut data = json!({});
|
||||
for ui in self {
|
||||
let value = ui.path.get(store);
|
||||
data[ui.title] = json!({
|
||||
match self {
|
||||
ExposedUI::Object { value, description } => {
|
||||
json!({
|
||||
"type": "object",
|
||||
"description": description,
|
||||
"value": value.into_iter().map(|(k, v)| (k, v.into_properties(store))).collect::<BTreeMap<String,_>>()
|
||||
})
|
||||
}
|
||||
ExposedUI::String {
|
||||
path,
|
||||
description,
|
||||
masked,
|
||||
copyable,
|
||||
qr,
|
||||
} => json!({
|
||||
"type": "string",
|
||||
"description": ui.description,
|
||||
"value": value.map(|x| x.to_string()).unwrap_or_default(),
|
||||
"copyable": ui.copyable,
|
||||
"qr": ui.qr,
|
||||
"masked": ui.masked,
|
||||
});
|
||||
"description": description,
|
||||
"value": path.get(store).cloned().unwrap_or_default(),
|
||||
"copyable": copyable,
|
||||
"qr": qr,
|
||||
"masked": masked
|
||||
}),
|
||||
}
|
||||
json!({
|
||||
"version": 2,
|
||||
"data": data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoProperties for StoreExposedUI {
|
||||
fn into_properties(self, store: &Value) -> Value {
|
||||
Value::Object(
|
||||
self.0
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into_properties(store)))
|
||||
.collect::<InOMap<InternedString, Value>>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ use serde::{Deserialize, Serialize};
|
||||
use tokio::process::Command;
|
||||
use ts_rs::TS;
|
||||
|
||||
use crate::db::model::package::{CurrentDependencies, CurrentDependencyInfo, ExposedUI};
|
||||
use crate::db::model::package::{
|
||||
CurrentDependencies, CurrentDependencyInfo, ExposedUI, StoreExposedUI,
|
||||
};
|
||||
use crate::disk::mount::filesystem::idmapped::IdMapped;
|
||||
use crate::disk::mount::filesystem::loop_dev::LoopDev;
|
||||
use crate::disk::mount::filesystem::overlayfs::OverlayGuard;
|
||||
@@ -674,6 +676,10 @@ async fn expose_for_dependents(
|
||||
context: EffectContext,
|
||||
ExposeForDependentsParams { paths }: ExposeForDependentsParams,
|
||||
) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn expose_ui(context: EffectContext, params: StoreExposedUI) -> Result<(), Error> {
|
||||
let context = context.deref()?;
|
||||
let package_id = context.id.clone();
|
||||
context
|
||||
@@ -684,48 +690,12 @@ async fn expose_for_dependents(
|
||||
.as_package_data_mut()
|
||||
.as_idx_mut(&package_id)
|
||||
.or_not_found(&package_id)?
|
||||
.as_store_exposed_dependents_mut()
|
||||
.ser(&paths)
|
||||
.as_store_exposed_ui_mut()
|
||||
.ser(¶ms)
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(tag = "type")]
|
||||
#[ts(export)]
|
||||
enum ExposeUiParams {
|
||||
Object {
|
||||
#[ts(type = "{[key: string]: ExposeUiParams}")]
|
||||
value: OrdMap<String, ExposeUiParams>,
|
||||
},
|
||||
String {
|
||||
path: String,
|
||||
description: Option<String>,
|
||||
masked: bool,
|
||||
copyable: Option<bool>,
|
||||
qr: Option<bool>,
|
||||
},
|
||||
}
|
||||
|
||||
async fn expose_ui(context: EffectContext, params: ExposeUiParams) -> Result<(), Error> {
|
||||
todo!()
|
||||
// let context = context.deref()?;
|
||||
// let package_id = context.id.clone();
|
||||
// context
|
||||
// .ctx
|
||||
// .db
|
||||
// .mutate(|db| {
|
||||
// db.as_public_mut()
|
||||
// .as_package_data_mut()
|
||||
// .as_idx_mut(&package_id)
|
||||
// .or_not_found(&package_id)?
|
||||
// .as_store_exposed_ui_mut()
|
||||
// .ser(&paths)
|
||||
// })
|
||||
// .await?;
|
||||
// Ok(())
|
||||
}
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
Reference in New Issue
Block a user