mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
Update some of the types
This commit is contained in:
@@ -1,14 +1,11 @@
|
|||||||
import { types as T, util, EmVer } from "@start9labs/start-sdk"
|
import { types as T, util, EmVer, Utils } from "@start9labs/start-sdk"
|
||||||
import * as fs from "fs/promises"
|
import * as fs from "fs/promises"
|
||||||
|
|
||||||
import { PolyfillEffects } from "./polyfillEffects"
|
import { PolyfillEffects } from "./polyfillEffects"
|
||||||
import { Duration, duration } from "../../../Models/Duration"
|
import { Duration, duration } from "../../../Models/Duration"
|
||||||
import { ExecuteResult, System } from "../../../Interfaces/System"
|
import { System } from "../../../Interfaces/System"
|
||||||
import { matchManifest, Manifest, Procedure } from "./matchManifest"
|
import { matchManifest, Manifest, Procedure } from "./matchManifest"
|
||||||
import { create } from "domain"
|
|
||||||
import * as childProcess from "node:child_process"
|
import * as childProcess from "node:child_process"
|
||||||
import { Volume } from "../../../Models/Volume"
|
|
||||||
import { DockerProcedure } from "../../../Models/DockerProcedure"
|
|
||||||
import { DockerProcedureContainer } from "./DockerProcedureContainer"
|
import { DockerProcedureContainer } from "./DockerProcedureContainer"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import * as U from "./oldEmbassyTypes"
|
import * as U from "./oldEmbassyTypes"
|
||||||
@@ -28,9 +25,7 @@ import {
|
|||||||
} from "ts-matches"
|
} from "ts-matches"
|
||||||
import { HostSystemStartOs } from "../../HostSystemStartOs"
|
import { HostSystemStartOs } from "../../HostSystemStartOs"
|
||||||
import { JsonPath, unNestPath } from "../../../Models/JsonPath"
|
import { JsonPath, unNestPath } from "../../../Models/JsonPath"
|
||||||
import { HostSystem } from "../../../Interfaces/HostSystem"
|
|
||||||
import { RpcResult, matchRpcResult } from "../../RpcListener"
|
import { RpcResult, matchRpcResult } from "../../RpcListener"
|
||||||
import { ServiceInterface } from "../../../../../sdk/dist/cjs/lib/types"
|
|
||||||
|
|
||||||
type Optional<A> = A | undefined | null
|
type Optional<A> = A | undefined | null
|
||||||
function todo(): never {
|
function todo(): never {
|
||||||
@@ -42,6 +37,60 @@ const MANIFEST_LOCATION = "/usr/lib/startos/package/embassyManifest.json"
|
|||||||
const EMBASSY_JS_LOCATION = "/usr/lib/startos/package/embassy.js"
|
const EMBASSY_JS_LOCATION = "/usr/lib/startos/package/embassy.js"
|
||||||
const EMBASSY_POINTER_PATH_PREFIX = "/embassyConfig"
|
const EMBASSY_POINTER_PATH_PREFIX = "/embassyConfig"
|
||||||
|
|
||||||
|
const matchPackagePropertyObject = object({
|
||||||
|
value: any,
|
||||||
|
type: literal("object"),
|
||||||
|
description: string,
|
||||||
|
})
|
||||||
|
|
||||||
|
const matchPackagePropertyString = object(
|
||||||
|
{
|
||||||
|
type: literal("string"),
|
||||||
|
description: string,
|
||||||
|
value: string,
|
||||||
|
copyable: boolean,
|
||||||
|
qr: boolean,
|
||||||
|
masked: boolean,
|
||||||
|
},
|
||||||
|
["copyable", "description", "qr", "masked"],
|
||||||
|
)
|
||||||
|
|
||||||
|
const matchProperties = object({
|
||||||
|
version: literal(2),
|
||||||
|
data: any,
|
||||||
|
})
|
||||||
|
|
||||||
|
type ExportUi = {
|
||||||
|
value: string
|
||||||
|
title: string
|
||||||
|
description?: string | undefined
|
||||||
|
masked?: boolean | undefined
|
||||||
|
copyable?: boolean | undefined
|
||||||
|
qr?: boolean | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function propertiesToExportUi(properties: unknown): ExportUi[] {
|
||||||
|
if (!object.test(properties)) return []
|
||||||
|
const paths: ExportUi[] = []
|
||||||
|
for (const key in properties) {
|
||||||
|
const value: unknown = (properties as any)[key]
|
||||||
|
if (matchPackagePropertyObject.test(value)) {
|
||||||
|
paths.push(...propertiesToExportUi(value))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!matchPackagePropertyString.test(value)) continue
|
||||||
|
paths.push({
|
||||||
|
value: value.value,
|
||||||
|
title: key,
|
||||||
|
description: value.description,
|
||||||
|
masked: value.masked,
|
||||||
|
copyable: value.copyable,
|
||||||
|
qr: value.qr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
export class SystemForEmbassy implements System {
|
export class SystemForEmbassy implements System {
|
||||||
currentRunning: MainLoop | undefined
|
currentRunning: MainLoop | undefined
|
||||||
static async of(manifestLocation: string = MANIFEST_LOCATION) {
|
static async of(manifestLocation: string = MANIFEST_LOCATION) {
|
||||||
@@ -399,7 +448,7 @@ export class SystemForEmbassy implements System {
|
|||||||
setConfigValue,
|
setConfigValue,
|
||||||
this.manifest.volumes,
|
this.manifest.volumes,
|
||||||
)
|
)
|
||||||
return JSON.parse(
|
const properties = JSON.parse(
|
||||||
(
|
(
|
||||||
await container.exec([
|
await container.exec([
|
||||||
setConfigValue.entrypoint,
|
setConfigValue.entrypoint,
|
||||||
@@ -407,6 +456,14 @@ export class SystemForEmbassy implements System {
|
|||||||
])
|
])
|
||||||
).stdout.toString(),
|
).stdout.toString(),
|
||||||
)
|
)
|
||||||
|
const exposeUis = propertiesToExportUi(properties)
|
||||||
|
await effects.store.set<any, any>({
|
||||||
|
path: "/properties",
|
||||||
|
value: exposeUis.map((x) => x.value),
|
||||||
|
})
|
||||||
|
await effects.exposeUi(
|
||||||
|
exposeUis.map((x, i) => ({ ...x, path: `/properties/${i}` }) as any),
|
||||||
|
)
|
||||||
} else if (setConfigValue.type === "script") {
|
} else if (setConfigValue.type === "script") {
|
||||||
const moduleCode = this.moduleCode
|
const moduleCode = this.moduleCode
|
||||||
const method = moduleCode.properties
|
const method = moduleCode.properties
|
||||||
|
|||||||
@@ -530,12 +530,12 @@ pub struct ExposedDependent {
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
|
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
|
||||||
#[model = "Model<Self>"]
|
#[model = "Model<Self>"]
|
||||||
pub struct ExposedUI {
|
pub struct ExposedUI {
|
||||||
path: Vec<JsonPointer>,
|
pub path: JsonPointer,
|
||||||
title: String,
|
pub title: String,
|
||||||
description: Option<String>,
|
pub description: Option<String>,
|
||||||
masked: Option<bool>,
|
pub masked: Option<bool>,
|
||||||
copyable: Option<bool>,
|
pub copyable: Option<bool>,
|
||||||
qr: Option<bool>,
|
pub qr: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||||
|
|||||||
@@ -1,16 +1,41 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use imbl_value::{json, Value};
|
||||||
use models::PackageId;
|
use models::PackageId;
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
use crate::context::RpcContext;
|
use crate::prelude::*;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
use crate::{context::RpcContext, db::model::ExposedUI};
|
||||||
|
|
||||||
pub fn display_properties(response: Value) {
|
pub fn display_properties(response: Value) {
|
||||||
println!("{}", response);
|
println!("{}", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait IntoProperties {
|
||||||
|
fn into_properties(self, store: &Value) -> Value;
|
||||||
|
}
|
||||||
|
impl IntoProperties for Vec<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!({
|
||||||
|
"type": "string",
|
||||||
|
"description": ui.description,
|
||||||
|
"value": value.map(|x| x.to_string()).unwrap_or_default(),
|
||||||
|
"copyable": ui.copyable,
|
||||||
|
"qr": ui.qr,
|
||||||
|
"masked": ui.masked,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
json!({
|
||||||
|
"version": 2,
|
||||||
|
"data": data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Parser)]
|
#[derive(Deserialize, Serialize, Parser)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
#[command(rename_all = "kebab-case")]
|
#[command(rename_all = "kebab-case")]
|
||||||
@@ -22,5 +47,24 @@ pub async fn properties(
|
|||||||
ctx: RpcContext,
|
ctx: RpcContext,
|
||||||
PropertiesParam { id }: PropertiesParam,
|
PropertiesParam { id }: PropertiesParam,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
Ok(todo!())
|
let peeked = ctx.db.peek().await;
|
||||||
|
let data = peeked
|
||||||
|
.as_public()
|
||||||
|
.as_package_data()
|
||||||
|
.as_idx(&id)
|
||||||
|
.or_not_found(&id)?
|
||||||
|
.as_installed()
|
||||||
|
.or_not_found(&id)?
|
||||||
|
.as_store()
|
||||||
|
.de()?;
|
||||||
|
Ok(peeked
|
||||||
|
.as_public()
|
||||||
|
.as_package_data()
|
||||||
|
.as_idx(&id)
|
||||||
|
.or_not_found(&id)?
|
||||||
|
.as_installed()
|
||||||
|
.or_not_found(&id)?
|
||||||
|
.as_store_exposed_ui()
|
||||||
|
.de()?
|
||||||
|
.into_properties(&data))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import { DataModel } from 'src/app/services/patch-db/data-model'
|
|||||||
import { PatchDB } from 'patch-db-client'
|
import { PatchDB } from 'patch-db-client'
|
||||||
import { QRComponent } from 'src/app/components/qr/qr.component'
|
import { QRComponent } from 'src/app/components/qr/qr.component'
|
||||||
import { map } from 'rxjs'
|
import { map } from 'rxjs'
|
||||||
import {
|
import { types as T } from '@start9labs/start-sdk'
|
||||||
ServiceInterface,
|
|
||||||
ServiceInterfaceWithHostInfo,
|
type ServiceInterface = T.ServiceInterface
|
||||||
} from '@start9labs/start-sdk/mjs/lib/types'
|
type ServiceInterfaceWithHostInfo = T.ServiceInterfaceWithHostInfo
|
||||||
|
|
||||||
type MappedInterface = ServiceInterface & {
|
type MappedInterface = ServiceInterface & {
|
||||||
addresses: MappedAddress[]
|
addresses: MappedAddress[]
|
||||||
|
|||||||
Reference in New Issue
Block a user