rename some things in the sdk (#2809)

* rename some things in the sdk

* fix docs

* rename some types exported from rust
This commit is contained in:
Aiden McClelland
2025-01-15 16:58:50 +00:00
committed by GitHub
parent e012a29b5e
commit 5e103770fd
17 changed files with 61 additions and 36 deletions

View File

@@ -43,7 +43,7 @@ export class DockerProcedureContainer {
) {
const subcontainer = await SubContainer.of(
effects,
{ id: data.image },
{ imageId: data.image },
name,
)

View File

@@ -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: [

View File

@@ -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<AcmeProvider>,

View File

@@ -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<bool>,
@@ -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

View File

@@ -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<bool>,
@@ -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

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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"

View File

@@ -215,18 +215,14 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
}),
},
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 <A extends string>(
effects: Effects,
image: {
id: keyof Manifest["images"] & T.ImageId
imageId: keyof Manifest["images"] & T.ImageId
sharedRun?: boolean
},
command: T.CommandType,
@@ -548,7 +544,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
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',
})
@@ -580,7 +576,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
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',
})
@@ -685,7 +681,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
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<Manifest extends T.SDKManifest, Store> {
export async function runCommand<Manifest extends T.SDKManifest>(
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 }[]

View File

@@ -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,

View File

@@ -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,

View File

@@ -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

View File

@@ -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,

View File

@@ -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<T>(
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<T>,

View File

@@ -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",

View File

@@ -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",