Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez committed Sep 10, 2024
1 parent bf1e215 commit 8996fd3
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 36 deletions.
25 changes: 20 additions & 5 deletions core/startos/src/db/model/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::net::service_interface::ServiceInterface;
use crate::prelude::*;
use crate::progress::FullProgress;
use crate::s9pk::manifest::Manifest;
use crate::status::Status;
use crate::status::MainStatus;
use crate::util::serde::Pem;

#[derive(Debug, Default, Deserialize, Serialize, TS)]
Expand Down Expand Up @@ -310,9 +310,9 @@ pub struct InstallingInfo {
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
#[ts(export)]
#[serde(rename_all = "camelCase")]
#[serde(rename_all = "kebab-case")]
pub enum AllowedStatuses {
OnlyRunning, // onlyRunning
OnlyRunning,
OnlyStopped,
Any,
}
Expand All @@ -324,19 +324,34 @@ pub struct ActionMetadata {
pub name: String,
pub description: String,
pub warning: Option<String>,
pub disabled: Option<String>,
#[serde(default)]
pub visibility: ActionVisibility,
pub allowed_statuses: AllowedStatuses,
pub group: Option<String>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
#[ts(export)]
#[serde(rename_all = "kebab-case")]
pub enum ActionVisibility {
Hidden,
Disabled { reason: String },
Enabled,
}
impl Default for ActionVisibility {
fn default() -> Self {
Self::Enabled
}
}

#[derive(Debug, Deserialize, Serialize, HasModel, TS)]
#[serde(rename_all = "camelCase")]
#[model = "Model<Self>"]
#[ts(export)]
pub struct PackageDataEntry {
pub state_info: PackageState,
pub data_version: Option<VersionString>,
pub status: Status,
pub status: MainStatus,
#[ts(type = "string | null")]
pub registry: Option<Url>,
#[ts(type = "string")]
Expand Down
2 changes: 1 addition & 1 deletion core/startos/src/service/effects/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ pub async fn check_dependencies(
let satisfies = manifest.as_satisfies().de()?;
let installed_version = Some(installed_version.clone());
let is_installed = true;
let status = package.as_status().as_main().de()?;
let status = package.as_status().de()?;
let is_running = if is_installed {
status.running()
} else {
Expand Down
1 change: 0 additions & 1 deletion core/startos/src/service/effects/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub async fn set_health(
.as_idx_mut(package_id)
.or_not_found(package_id)?
.as_status_mut()
.as_main_mut()
.mutate(|main| {
match main {
MainStatus::Running { ref mut health, .. }
Expand Down
2 changes: 1 addition & 1 deletion core/startos/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Service {
tokio::fs::create_dir_all(&path).await?;
}
}
let start_stop = if i.as_status().as_main().de()?.running() {
let start_stop = if i.as_status().de()?.running() {
StartStop::Start
} else {
StartStop::Stop
Expand Down
4 changes: 2 additions & 2 deletions core/startos/src/service/service_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn service_actor_loop(
.db
.mutate(|d| {
if let Some(i) = d.as_public_mut().as_package_data_mut().as_idx_mut(&id) {
let previous = i.as_status().as_main().de()?;
let previous = i.as_status().de()?;
let main_status = match &kinds {
ServiceStateKinds {
transition_state: Some(TransitionKind::Restarting),
Expand Down Expand Up @@ -89,7 +89,7 @@ async fn service_actor_loop(
..
} => MainStatus::Stopped,
};
i.as_status_mut().as_main_mut().ser(&main_status)?;
i.as_status_mut().ser(&main_status)?;
}
Ok(())
})
Expand Down
6 changes: 2 additions & 4 deletions core/startos/src/service/service_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::s9pk::manifest::PackageId;
use crate::s9pk::merkle_archive::source::FileSource;
use crate::s9pk::S9pk;
use crate::service::{LoadDisposition, Service, ServiceRef};
use crate::status::{MainStatus, Status};
use crate::status::MainStatus;
use crate::util::serde::Pem;

pub type DownloadInstallFuture = BoxFuture<'static, Result<InstallFuture, Error>>;
Expand Down Expand Up @@ -174,9 +174,7 @@ impl ServiceMap {
PackageState::Installing(installing)
},
data_version: None,
status: Status {
main: MainStatus::Stopped,
},
status: MainStatus::Stopped,
registry: None,
developer_key: Pem::new(developer_key),
icon,
Expand Down
9 changes: 1 addition & 8 deletions core/startos/src/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ use crate::service::start_stop::StartStop;
use crate::status::health_check::NamedHealthCheckResult;

pub mod health_check;
#[derive(Clone, Debug, Deserialize, Serialize, HasModel, TS)]
#[serde(rename_all = "camelCase")]
#[model = "Model<Self>"]
#[ts(export)]
pub struct Status {
pub main: MainStatus,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, TS)]
#[serde(tag = "status")]
#[serde(tag = "main")]
#[serde(rename_all = "camelCase")]
#[serde(rename_all_fields = "camelCase")]
pub enum MainStatus {
Expand Down
3 changes: 2 additions & 1 deletion sdk/lib/osBindings/ActionMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ActionVisibility } from "./ActionVisibility"
import type { AllowedStatuses } from "./AllowedStatuses"

export type ActionMetadata = {
name: string
description: string
warning: string | null
disabled: string | null
visibility: ActionVisibility
allowedStatuses: AllowedStatuses
group: string | null
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { MainStatus } from "./MainStatus"

export type Status = { main: MainStatus }
export type ActionVisibility =
| "hidden"
| { disabled: { reason: string } }
| "enabled"
2 changes: 1 addition & 1 deletion sdk/lib/osBindings/AllowedStatuses.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type AllowedStatuses = "onlyRunning" | "onlyStopped" | "any"
export type AllowedStatuses = "only-running" | "only-stopped" | "any"
14 changes: 7 additions & 7 deletions sdk/lib/osBindings/MainStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import type { NamedHealthCheckResult } from "./NamedHealthCheckResult"
import type { StartStop } from "./StartStop"

export type MainStatus =
| { status: "stopped" }
| { status: "restarting" }
| { status: "restoring" }
| { status: "stopping" }
| { main: "stopped" }
| { main: "restarting" }
| { main: "restoring" }
| { main: "stopping" }
| {
status: "starting"
main: "starting"
health: { [key: HealthCheckId]: NamedHealthCheckResult }
}
| {
status: "running"
main: "running"
started: string
health: { [key: HealthCheckId]: NamedHealthCheckResult }
}
| { status: "backingUp"; onComplete: StartStop }
| { main: "backingUp"; onComplete: StartStop }
4 changes: 2 additions & 2 deletions sdk/lib/osBindings/PackageDataEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import type { ActionRequest } from "./ActionRequest"
import type { CurrentDependencies } from "./CurrentDependencies"
import type { DataUrl } from "./DataUrl"
import type { Hosts } from "./Hosts"
import type { MainStatus } from "./MainStatus"
import type { PackageState } from "./PackageState"
import type { ServiceInterface } from "./ServiceInterface"
import type { ServiceInterfaceId } from "./ServiceInterfaceId"
import type { Status } from "./Status"
import type { Version } from "./Version"

export type PackageDataEntry = {
stateInfo: PackageState
dataVersion: Version | null
status: Status
status: MainStatus
registry: string | null
developerKey: string
icon: DataUrl
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/osBindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { ActionMetadata } from "./ActionMetadata"
export { ActionRequestCondition } from "./ActionRequestCondition"
export { ActionRequestInput } from "./ActionRequestInput"
export { ActionRequest } from "./ActionRequest"
export { ActionVisibility } from "./ActionVisibility"
export { AddAdminParams } from "./AddAdminParams"
export { AddAssetParams } from "./AddAssetParams"
export { AddPackageParams } from "./AddPackageParams"
Expand Down Expand Up @@ -152,7 +153,6 @@ export { SignAssetParams } from "./SignAssetParams"
export { SignerInfo } from "./SignerInfo"
export { SmtpValue } from "./SmtpValue"
export { StartStop } from "./StartStop"
export { Status } from "./Status"
export { UpdatingState } from "./UpdatingState"
export { VerifyCifsParams } from "./VerifyCifsParams"
export { VersionSignerParams } from "./VersionSignerParams"
Expand Down

0 comments on commit 8996fd3

Please sign in to comment.