From 02fd7604e384ac955cfb167b78332e608e70c3aa Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 14 Jan 2025 09:55:32 -0700 Subject: [PATCH 1/3] rename some things in the sdk --- .../SystemForEmbassy/DockerProcedureContainer.ts | 2 +- .../Systems/SystemForEmbassy/polyfillEffects.ts | 6 +++--- sdk/package/lib/StartSdk.ts | 14 +++++--------- sdk/package/lib/mainFn/CommandController.ts | 2 +- sdk/package/lib/mainFn/Daemon.ts | 2 +- sdk/package/lib/mainFn/Daemons.ts | 2 +- sdk/package/lib/test/host.test.ts | 2 +- sdk/package/lib/util/SubContainer.ts | 10 +++++----- sdk/package/package-lock.json | 4 ++-- sdk/package/package.json | 2 +- 10 files changed, 21 insertions(+), 25 deletions(-) diff --git a/container-runtime/src/Adapters/Systems/SystemForEmbassy/DockerProcedureContainer.ts b/container-runtime/src/Adapters/Systems/SystemForEmbassy/DockerProcedureContainer.ts index 26e4dd8bf..806216786 100644 --- a/container-runtime/src/Adapters/Systems/SystemForEmbassy/DockerProcedureContainer.ts +++ b/container-runtime/src/Adapters/Systems/SystemForEmbassy/DockerProcedureContainer.ts @@ -43,7 +43,7 @@ export class DockerProcedureContainer { ) { const subcontainer = await SubContainer.of( effects, - { id: data.image }, + { imageId: data.image }, name, ) diff --git a/container-runtime/src/Adapters/Systems/SystemForEmbassy/polyfillEffects.ts b/container-runtime/src/Adapters/Systems/SystemForEmbassy/polyfillEffects.ts index 7438070ea..5cbec945a 100644 --- a/container-runtime/src/Adapters/Systems/SystemForEmbassy/polyfillEffects.ts +++ b/container-runtime/src/Adapters/Systems/SystemForEmbassy/polyfillEffects.ts @@ -109,7 +109,7 @@ export const polyfillEffects = ( return startSdk .runCommand( effects, - { id: manifest.main.image }, + { imageId: manifest.main.image }, commands, {}, commands.join(" "), @@ -165,7 +165,7 @@ export const polyfillEffects = ( await startSdk .runCommand( effects, - { id: manifest.main.image }, + { imageId: manifest.main.image }, commands, { mounts: [ @@ -207,7 +207,7 @@ export const polyfillEffects = ( await startSdk .runCommand( effects, - { id: manifest.main.image }, + { imageId: manifest.main.image }, commands, { mounts: [ diff --git a/sdk/package/lib/StartSdk.ts b/sdk/package/lib/StartSdk.ts index 65ef23883..2514ba552 100644 --- a/sdk/package/lib/StartSdk.ts +++ b/sdk/package/lib/StartSdk.ts @@ -215,18 +215,14 @@ export class StartSdk { }), }, - host: { - // static: (effects: Effects, id: string) => - // new StaticHost({ id, effects }), - // single: (effects: Effects, id: string) => - // new SingleHost({ id, effects }), - multi: (effects: Effects, id: string) => new MultiHost({ id, effects }), + MultiHost: { + of: (effects: Effects, id: string) => new MultiHost({ id, effects }), }, nullIfEmpty, runCommand: async ( effects: Effects, image: { - id: keyof Manifest["images"] & T.ImageId + imageId: keyof Manifest["images"] & T.ImageId sharedRun?: boolean }, command: T.CommandType, @@ -685,7 +681,7 @@ export class StartSdk { of( effects: Effects, image: { - id: T.ImageId & keyof Manifest["images"] + imageId: T.ImageId & keyof Manifest["images"] sharedRun?: boolean }, name: string, @@ -1414,7 +1410,7 @@ export class StartSdk { export async function runCommand( effects: Effects, - image: { id: keyof Manifest["images"] & T.ImageId; sharedRun?: boolean }, + image: { imageId: keyof Manifest["images"] & T.ImageId; sharedRun?: boolean }, command: string | [string, ...string[]], options: CommandOptions & { mounts?: { path: string; options: MountOptions }[] diff --git a/sdk/package/lib/mainFn/CommandController.ts b/sdk/package/lib/mainFn/CommandController.ts index 498de2843..a7375b369 100644 --- a/sdk/package/lib/mainFn/CommandController.ts +++ b/sdk/package/lib/mainFn/CommandController.ts @@ -23,7 +23,7 @@ export class CommandController { effects: T.Effects, subcontainer: | { - id: keyof Manifest["images"] & T.ImageId + imageId: keyof Manifest["images"] & T.ImageId sharedRun?: boolean } | SubContainer, diff --git a/sdk/package/lib/mainFn/Daemon.ts b/sdk/package/lib/mainFn/Daemon.ts index 0cbc9cd94..864ae4122 100644 --- a/sdk/package/lib/mainFn/Daemon.ts +++ b/sdk/package/lib/mainFn/Daemon.ts @@ -22,7 +22,7 @@ export class Daemon { effects: T.Effects, subcontainer: | { - id: keyof Manifest["images"] & T.ImageId + imageId: keyof Manifest["images"] & T.ImageId sharedRun?: boolean } | SubContainer, diff --git a/sdk/package/lib/mainFn/Daemons.ts b/sdk/package/lib/mainFn/Daemons.ts index e18fa2314..8d0e6297a 100644 --- a/sdk/package/lib/mainFn/Daemons.ts +++ b/sdk/package/lib/mainFn/Daemons.ts @@ -53,7 +53,7 @@ type DaemonsParams< subcontainer: | { /** The ID of the image. Must be one of the image IDs declared in the manifest */ - id: keyof Manifest["images"] & T.ImageId + imageId: keyof Manifest["images"] & T.ImageId /** * Whether or not to share the `/run` directory with the parent container. * This is useful if you are trying to connect to a service that exposes a unix domain socket or auth cookie via the `/run` directory diff --git a/sdk/package/lib/test/host.test.ts b/sdk/package/lib/test/host.test.ts index 4492804ec..88ca7c4b6 100644 --- a/sdk/package/lib/test/host.test.ts +++ b/sdk/package/lib/test/host.test.ts @@ -5,7 +5,7 @@ import { sdk } from "../test/output.sdk" describe("host", () => { test("Testing that the types work", () => { async function test(effects: Effects) { - const foo = sdk.host.multi(effects, "foo") + const foo = sdk.MultiHost.of(effects, "foo") const fooOrigin = await foo.bindPort(80, { protocol: "http" as const, preferredExternalPort: 80, diff --git a/sdk/package/lib/util/SubContainer.ts b/sdk/package/lib/util/SubContainer.ts index f9b5a1084..77b31fec8 100644 --- a/sdk/package/lib/util/SubContainer.ts +++ b/sdk/package/lib/util/SubContainer.ts @@ -86,12 +86,12 @@ export class SubContainer implements ExecSpawnable { } static async of( effects: T.Effects, - image: { id: T.ImageId; sharedRun?: boolean }, + image: { imageId: T.ImageId; sharedRun?: boolean }, name: string, ) { - const { id, sharedRun } = image + const { imageId, sharedRun } = image const [rootfs, guid] = await effects.subcontainer.createFs({ - imageId: id as string, + imageId, name, }) @@ -111,12 +111,12 @@ export class SubContainer implements ExecSpawnable { await execFile("mount", ["--rbind", from, to]) } - return new SubContainer(effects, id, rootfs, guid) + return new SubContainer(effects, imageId, rootfs, guid) } static async with( effects: T.Effects, - image: { id: T.ImageId; sharedRun?: boolean }, + image: { imageId: T.ImageId; sharedRun?: boolean }, mounts: { options: MountOptions; path: string }[], name: string, fn: (subContainer: SubContainer) => Promise, diff --git a/sdk/package/package-lock.json b/sdk/package/package-lock.json index 58a37e357..6f2cf74d8 100644 --- a/sdk/package/package-lock.json +++ b/sdk/package/package-lock.json @@ -1,12 +1,12 @@ { "name": "@start9labs/start-sdk", - "version": "0.3.6-beta.3", + "version": "0.3.6-beta.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@start9labs/start-sdk", - "version": "0.3.6-beta.3", + "version": "0.3.6-beta.4", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/sdk/package/package.json b/sdk/package/package.json index 1a68b9d1b..5e80f5a94 100644 --- a/sdk/package/package.json +++ b/sdk/package/package.json @@ -1,6 +1,6 @@ { "name": "@start9labs/start-sdk", - "version": "0.3.6-beta.3", + "version": "0.3.6-beta.4", "description": "Software development kit to facilitate packaging services for StartOS", "main": "./package/lib/index.js", "types": "./package/lib/index.d.ts", From 07b2756cf7f06e1f2f883a15b59fec246ae27b4a Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 14 Jan 2025 10:00:15 -0700 Subject: [PATCH 2/3] fix docs --- sdk/package/lib/StartSdk.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/package/lib/StartSdk.ts b/sdk/package/lib/StartSdk.ts index 2514ba552..667e4297b 100644 --- a/sdk/package/lib/StartSdk.ts +++ b/sdk/package/lib/StartSdk.ts @@ -544,7 +544,7 @@ export class StartSdk { inputSpecSpec, async ({ effects, input }) => { // ** UI multi-host ** - const uiMulti = sdk.host.multi(effects, 'ui-multi') + const uiMulti = sdk.MultiHost.of(effects, 'ui-multi') const uiMultiOrigin = await uiMulti.bindPort(80, { protocol: 'http', }) @@ -576,7 +576,7 @@ export class StartSdk { const uiReceipt = await uiMultiOrigin.export([primaryUi, adminUi]) // ** API multi-host ** - const apiMulti = sdk.host.multi(effects, 'api-multi') + const apiMulti = sdk.MultiHost.of(effects, 'api-multi') const apiMultiOrigin = await apiMulti.bindPort(5959, { protocol: 'http', }) From 3dab2527373e92dbc693c3a23d75533ce6d5bb97 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 14 Jan 2025 11:20:25 -0700 Subject: [PATCH 3/3] rename some types exported from rust --- core/startos/src/net/host/address.rs | 8 +++++++- core/startos/src/net/host/binding.rs | 9 +++++---- core/startos/src/net/network_interface.rs | 4 ++-- .../{SetPublicParams.ts => BindingSetPublicParams.ts} | 5 ++++- sdk/base/lib/osBindings/HostAddress.ts | 11 +++++++++++ .../lib/osBindings/NetworkInterfaceSetPublicParams.ts | 6 ++++++ sdk/base/lib/osBindings/index.ts | 4 +++- 7 files changed, 38 insertions(+), 9 deletions(-) rename sdk/base/lib/osBindings/{SetPublicParams.ts => BindingSetPublicParams.ts} (55%) create mode 100644 sdk/base/lib/osBindings/HostAddress.ts create mode 100644 sdk/base/lib/osBindings/NetworkInterfaceSetPublicParams.ts diff --git a/core/startos/src/net/host/address.rs b/core/startos/src/net/host/address.rs index 3d639b31e..fa41824a5 100644 --- a/core/startos/src/net/host/address.rs +++ b/core/startos/src/net/host/address.rs @@ -11,12 +11,18 @@ use crate::net::acme::AcmeProvider; use crate::prelude::*; use crate::util::serde::{display_serializable, HandlerExtSerde}; -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize, TS)] +#[serde(rename_all = "kebab-case")] +#[serde(rename_all_fields = "camelCase")] +#[serde(tag = "kind")] +#[ts(export)] pub enum HostAddress { Onion { + #[ts(type = "string")] address: OnionAddressV3, }, Domain { + #[ts(type = "string")] address: InternedString, public: bool, acme: Option, diff --git a/core/startos/src/net/host/binding.rs b/core/startos/src/net/host/binding.rs index d56f607a9..08f9f68c4 100644 --- a/core/startos/src/net/host/binding.rs +++ b/core/startos/src/net/host/binding.rs @@ -221,9 +221,10 @@ pub async fn list_bindings( .de() } -#[derive(Deserialize, Serialize, Parser)] +#[derive(Deserialize, Serialize, Parser, TS)] #[serde(rename_all = "camelCase")] -pub struct SetPublicParams { +#[ts(export)] +pub struct BindingSetPublicParams { internal_port: u16, #[arg(long)] public: Option, @@ -231,10 +232,10 @@ pub struct SetPublicParams { pub async fn set_public( ctx: RpcContext, - SetPublicParams { + BindingSetPublicParams { internal_port, public, - }: SetPublicParams, + }: BindingSetPublicParams, (package, host): (PackageId, HostId), ) -> Result<(), Error> { ctx.db diff --git a/core/startos/src/net/network_interface.rs b/core/startos/src/net/network_interface.rs index 4f7696c97..920bdd4e4 100644 --- a/core/startos/src/net/network_interface.rs +++ b/core/startos/src/net/network_interface.rs @@ -114,7 +114,7 @@ async fn list_interfaces( #[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)] #[ts(export)] -struct SetPublicParams { +struct NetworkInterfaceSetPublicParams { #[ts(type = "string")] interface: InternedString, public: Option, @@ -122,7 +122,7 @@ struct SetPublicParams { async fn set_public( ctx: RpcContext, - SetPublicParams { interface, public }: SetPublicParams, + NetworkInterfaceSetPublicParams { interface, public }: NetworkInterfaceSetPublicParams, ) -> Result<(), Error> { ctx.net_controller .net_iface diff --git a/sdk/base/lib/osBindings/SetPublicParams.ts b/sdk/base/lib/osBindings/BindingSetPublicParams.ts similarity index 55% rename from sdk/base/lib/osBindings/SetPublicParams.ts rename to sdk/base/lib/osBindings/BindingSetPublicParams.ts index 03bc3082b..077cf8510 100644 --- a/sdk/base/lib/osBindings/SetPublicParams.ts +++ b/sdk/base/lib/osBindings/BindingSetPublicParams.ts @@ -1,3 +1,6 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type SetPublicParams = { interface: string; public: boolean | null } +export type BindingSetPublicParams = { + internalPort: number + public: boolean | null +} diff --git a/sdk/base/lib/osBindings/HostAddress.ts b/sdk/base/lib/osBindings/HostAddress.ts new file mode 100644 index 000000000..fe16c89d7 --- /dev/null +++ b/sdk/base/lib/osBindings/HostAddress.ts @@ -0,0 +1,11 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AcmeProvider } from "./AcmeProvider" + +export type HostAddress = + | { kind: "onion"; address: string } + | { + kind: "domain" + address: string + public: boolean + acme: AcmeProvider | null + } diff --git a/sdk/base/lib/osBindings/NetworkInterfaceSetPublicParams.ts b/sdk/base/lib/osBindings/NetworkInterfaceSetPublicParams.ts new file mode 100644 index 000000000..516bfc817 --- /dev/null +++ b/sdk/base/lib/osBindings/NetworkInterfaceSetPublicParams.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type NetworkInterfaceSetPublicParams = { + interface: string + public: boolean | null +} diff --git a/sdk/base/lib/osBindings/index.ts b/sdk/base/lib/osBindings/index.ts index 6eff86872..f500cacc3 100644 --- a/sdk/base/lib/osBindings/index.ts +++ b/sdk/base/lib/osBindings/index.ts @@ -38,6 +38,7 @@ export { BackupTargetFS } from "./BackupTargetFS" export { Base64 } from "./Base64" export { BindId } from "./BindId" export { BindInfo } from "./BindInfo" +export { BindingSetPublicParams } from "./BindingSetPublicParams" export { BindOptions } from "./BindOptions" export { BindParams } from "./BindParams" export { Blake3Commitment } from "./Blake3Commitment" @@ -97,6 +98,7 @@ export { Governor } from "./Governor" export { Guid } from "./Guid" export { HardwareRequirements } from "./HardwareRequirements" export { HealthCheckId } from "./HealthCheckId" +export { HostAddress } from "./HostAddress" export { HostId } from "./HostId" export { HostKind } from "./HostKind" export { HostnameInfo } from "./HostnameInfo" @@ -131,6 +133,7 @@ export { NamedHealthCheckResult } from "./NamedHealthCheckResult" export { NamedProgress } from "./NamedProgress" export { NetInfo } from "./NetInfo" export { NetworkInterfaceInfo } from "./NetworkInterfaceInfo" +export { NetworkInterfaceSetPublicParams } from "./NetworkInterfaceSetPublicParams" export { NetworkInterfaceType } from "./NetworkInterfaceType" export { OnionHostname } from "./OnionHostname" export { OsIndex } from "./OsIndex" @@ -176,7 +179,6 @@ export { SetIconParams } from "./SetIconParams" export { SetMainStatusStatus } from "./SetMainStatusStatus" export { SetMainStatus } from "./SetMainStatus" export { SetNameParams } from "./SetNameParams" -export { SetPublicParams } from "./SetPublicParams" export { SetStoreParams } from "./SetStoreParams" export { SetupExecuteParams } from "./SetupExecuteParams" export { SetupProgress } from "./SetupProgress"