From 0e8530172c46919749113cf40742234ef5b748fa Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 6 Aug 2024 13:59:14 -0600 Subject: [PATCH] fix config set dry --- core/startos/src/config/mod.rs | 70 +++++++++++++++++-- .../ui/src/app/modals/config.component.ts | 6 +- .../ui/src/app/services/api/api.types.ts | 2 +- .../services/api/embassy-mock-api.service.ts | 2 +- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/core/startos/src/config/mod.rs b/core/startos/src/config/mod.rs index 01309a16f..22edd98f7 100644 --- a/core/startos/src/config/mod.rs +++ b/core/startos/src/config/mod.rs @@ -1,3 +1,4 @@ +use std::collections::BTreeSet; use std::sync::Arc; use std::time::Duration; @@ -178,13 +179,68 @@ pub struct SetParams { // )] #[instrument(skip_all)] pub fn set() -> ParentHandler { - ParentHandler::new().root_handler( - from_fn_async(set_impl) - .with_metadata("sync_db", Value::Bool(true)) - .with_inherited(|set_params, id| (id, set_params)) - .no_display() - .with_call_remote::(), - ) + ParentHandler::new() + .root_handler( + from_fn_async(set_impl) + .with_metadata("sync_db", Value::Bool(true)) + .with_inherited(|set_params, id| (id, set_params)) + .no_display() + .with_call_remote::(), + ) + .subcommand( + "dry", + from_fn_async(set_dry) + .with_inherited(|set_params, id| (id, set_params)) + .no_display() + .with_call_remote::(), + ) +} + +pub async fn set_dry( + ctx: RpcContext, + _: Empty, + ( + id, + SetParams { + timeout, + config: StdinDeserializable(config), + }, + ): (PackageId, SetParams), +) -> Result, Error> { + let mut breakages = BTreeSet::new(); + + let procedure_id = Guid::new(); + + let db = ctx.db.peek().await; + for dep in db + .as_public() + .as_package_data() + .as_entries()? + .into_iter() + .filter_map( + |(k, v)| match v.as_current_dependencies().contains_key(&id) { + Ok(true) => Some(Ok(k)), + Ok(false) => None, + Err(e) => Some(Err(e)), + }, + ) + { + let dep_id = dep?; + + let Some(dependent) = &*ctx.services.get(&dep_id).await else { + continue; + }; + + if dependent + .dependency_config(procedure_id.clone(), id.clone(), config.clone()) + .await? + .is_some() + { + breakages.insert(dep_id); + } + } + + Ok(breakages) } #[derive(Default)] diff --git a/web/projects/ui/src/app/modals/config.component.ts b/web/projects/ui/src/app/modals/config.component.ts index 60cef3141..d0e8afa4d 100644 --- a/web/projects/ui/src/app/modals/config.component.ts +++ b/web/projects/ui/src/app/modals/config.component.ts @@ -6,7 +6,7 @@ import { isEmptyObject, LoadingService, } from '@start9labs/shared' -import { CT } from '@start9labs/start-sdk' +import { CT, T } from '@start9labs/start-sdk' import { TuiButtonModule } from '@taiga-ui/experimental' import { TuiDialogContext, @@ -245,11 +245,11 @@ export class ConfigModal { this.context.$implicit.complete() } - private async approveBreakages(breakages: Breakages): Promise { + private async approveBreakages(breakages: T.PackageId[]): Promise { const packages = await getAllPackages(this.patchDb) const message = 'As a result of this change, the following services will no longer work properly and may crash:
    ' - const content = `${message}${Object.keys(breakages).map( + const content = `${message}${breakages.map( id => `
  • ${getManifest(packages[id]).title}
  • `, )}
` const data: TuiPromptData = { content, yes: 'Continue', no: 'Cancel' } diff --git a/web/projects/ui/src/app/services/api/api.types.ts b/web/projects/ui/src/app/services/api/api.types.ts index faa4a072e..5742ba67f 100644 --- a/web/projects/ui/src/app/services/api/api.types.ts +++ b/web/projects/ui/src/app/services/api/api.types.ts @@ -230,7 +230,7 @@ export module RR { export type GetPackageConfigRes = { spec: CT.InputSpec; config: object } export type DrySetPackageConfigReq = { id: string; config: object } // package.config.set.dry - export type DrySetPackageConfigRes = Breakages + export type DrySetPackageConfigRes = T.PackageId[] export type SetPackageConfigReq = DrySetPackageConfigReq // package.config.set export type SetPackageConfigRes = null diff --git a/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts b/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts index f716a1863..d44ef809a 100644 --- a/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts @@ -790,7 +790,7 @@ export class MockApiService extends ApiService { params: RR.DrySetPackageConfigReq, ): Promise { await pauseFor(2000) - return {} + return [] } async setPackageConfig(