fix: Optional input

This commit is contained in:
J H
2024-07-25 13:25:18 -06:00
parent 099b77cf9b
commit 1a0536d212
6 changed files with 35 additions and 9 deletions

View File

@@ -64,7 +64,7 @@ const runType = object({
input: any, input: any,
timeout: number, timeout: number,
}, },
["timeout"], ["timeout", "input"],
), ),
}) })
const sandboxRunType = object({ const sandboxRunType = object({
@@ -77,7 +77,7 @@ const sandboxRunType = object({
input: any, input: any,
timeout: number, timeout: number,
}, },
["timeout"], ["timeout", "input"],
), ),
}) })
const callbackType = object({ const callbackType = object({

View File

@@ -232,7 +232,7 @@ export class SystemForEmbassy implements System {
effects: Effects, effects: Effects,
options: { options: {
procedure: JsonPath procedure: JsonPath
input: unknown input?: unknown
timeout?: number | undefined timeout?: number | undefined
}, },
): Promise<RpcResult> { ): Promise<RpcResult> {
@@ -294,7 +294,7 @@ export class SystemForEmbassy implements System {
effects: Effects, effects: Effects,
options: { options: {
procedure: JsonPath procedure: JsonPath
input: unknown input?: unknown
timeout?: number | undefined timeout?: number | undefined
}, },
): Promise<unknown> { ): Promise<unknown> {

View File

@@ -75,7 +75,7 @@ export class SystemForStartOs implements System {
effects: Effects, effects: Effects,
options: { options: {
procedure: Procedure procedure: Procedure
input: unknown input?: unknown
timeout?: number | undefined timeout?: number | undefined
}, },
): Promise<RpcResult> { ): Promise<RpcResult> {
@@ -137,7 +137,7 @@ export class SystemForStartOs implements System {
effects: Effects | MainEffects, effects: Effects | MainEffects,
options: { options: {
procedure: Procedure procedure: Procedure
input: unknown input?: unknown
timeout?: number | undefined timeout?: number | undefined
}, },
): Promise<unknown> { ): Promise<unknown> {
@@ -219,7 +219,7 @@ export class SystemForStartOs implements System {
async sandbox( async sandbox(
effects: Effects, effects: Effects,
options: { procedure: Procedure; input: unknown; timeout?: number }, options: { procedure: Procedure; input?: unknown; timeout?: number },
): Promise<RpcResult> { ): Promise<RpcResult> {
return this.execute(effects, options) return this.execute(effects, options)
} }

View File

@@ -58,6 +58,7 @@ pub struct ActionParams {
pub action_id: ActionId, pub action_id: ActionId,
#[command(flatten)] #[command(flatten)]
#[ts(type = "{ [key: string]: any } | null")] #[ts(type = "{ [key: string]: any } | null")]
#[serde(default)]
pub input: StdinDeserializable<Option<Config>>, pub input: StdinDeserializable<Option<Config>>,
} }
// impl C // impl C

View File

@@ -568,6 +568,14 @@ where
#[derive(Deserialize, Serialize, TS)] #[derive(Deserialize, Serialize, TS)]
pub struct StdinDeserializable<T>(pub T); pub struct StdinDeserializable<T>(pub T);
impl<T> Default for StdinDeserializable<T>
where
T: Default,
{
fn default() -> Self {
Self(T::default())
}
}
impl<T> FromArgMatches for StdinDeserializable<T> impl<T> FromArgMatches for StdinDeserializable<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

View File

@@ -20,6 +20,20 @@ import {
import { getAllPackages, getManifest } from 'src/app/util/get-package-data' import { getAllPackages, getManifest } from 'src/app/util/get-package-data'
import { hasCurrentDeps } from 'src/app/util/has-deps' import { hasCurrentDeps } from 'src/app/util/has-deps'
const allowedStatuses = {
onlyRunning: new Set(['running']),
onlyStopped: new Set(['stopped']),
any: new Set([
'running',
'stopped',
'restarting',
'restoring',
'stopping',
'starting',
'backingUp',
]),
}
@Component({ @Component({
selector: 'app-actions', selector: 'app-actions',
templateUrl: './app-actions.page.html', templateUrl: './app-actions.page.html',
@@ -46,7 +60,10 @@ export class AppActionsPage {
status: T.Status, status: T.Status,
action: { key: string; value: T.ActionMetadata }, action: { key: string; value: T.ActionMetadata },
) { ) {
if (status && action.value.allowedStatuses.includes(status.main.status)) { if (
status &&
allowedStatuses[action.value.allowedStatuses].has(status.main.status)
) {
if (!isEmptyObject(action.value.input || {})) { if (!isEmptyObject(action.value.input || {})) {
this.formDialog.open(FormComponent, { this.formDialog.open(FormComponent, {
label: action.value.name, label: action.value.name,
@@ -84,7 +101,7 @@ export class AppActionsPage {
await alert.present() await alert.present()
} }
} else { } else {
const statuses = [...action.value.allowedStatuses] const statuses = [...allowedStatuses[action.value.allowedStatuses]]
const last = statuses.pop() const last = statuses.pop()
let statusesStr = statuses.join(', ') let statusesStr = statuses.join(', ')
let error = '' let error = ''