From b6fe0be1b24bfc01008fa32ae1656533dbfccace Mon Sep 17 00:00:00 2001 From: J H Date: Wed, 13 Mar 2024 16:23:24 -0600 Subject: [PATCH] chore: Add in some more files for the testing of the sdk and the rust interface --- Makefile | 6 +- core/Cargo.lock | 31 +++ core/models/Cargo.toml | 1 + core/models/src/id/action.rs | 2 +- core/models/src/id/health_check.rs | 2 +- core/models/src/id/image.rs | 2 +- core/models/src/id/mod.rs | 14 +- core/models/src/id/package.rs | 5 +- core/startos/Cargo.toml | 1 + core/startos/Effects.ts | 3 + core/startos/bindings/AddSslOptions.ts | 3 + core/startos/bindings/Algorithm.ts | 3 + core/startos/bindings/BindKind.ts | 3 + core/startos/bindings/BindParams.ts | 5 + core/startos/bindings/Callback.ts | 3 + core/startos/bindings/ChrootParams.ts | 3 + .../bindings/CreateOverlayedImageParams.ts | 4 + .../bindings/DestroyOverlayedImageParams.ts | 4 + core/startos/bindings/ExecuteAction.ts | 5 + .../bindings/ExposeForDependentsParams.ts | 3 + core/startos/bindings/ExposeUiParams.ts | 4 + core/startos/bindings/GetHostInfoParams.ts | 5 + .../startos/bindings/GetHostInfoParamsKind.ts | 3 + .../bindings/GetServiceInterfaceParams.ts | 5 + .../bindings/GetSslCertificateParams.ts | 4 + core/startos/bindings/GetSslKeyParams.ts | 4 + core/startos/bindings/GetStoreParams.ts | 4 + core/startos/bindings/ParamsMaybePackageId.ts | 4 + core/startos/bindings/ParamsPackageId.ts | 4 + core/startos/bindings/SetConfigured.ts | 3 + core/startos/bindings/SetHealth.ts | 5 + core/startos/bindings/SetMainStatus.ts | 4 + core/startos/bindings/SetStoreParams.ts | 3 + core/startos/bindings/Status.ts | 3 + core/startos/src/db/model.rs | 3 +- .../src/service/service_effect_handler.rs | 192 ++++++++++++++---- core/startos/src/status/health_check.rs | 2 +- sdk/lib/health/HealthCheck.ts | 2 +- sdk/lib/health/checkFns/CheckResult.ts | 2 +- sdk/lib/interfaces/Host.ts | 9 +- sdk/lib/test/host.test.ts | 5 +- sdk/lib/test/startosTypeValidation.test.ts | 75 +++++++ sdk/lib/types.ts | 93 +++++---- sdk/lib/util/getServiceInterface.ts | 7 +- sdk/lib/util/getServiceInterfaces.ts | 8 +- sdk/lib/util/utils.ts | 11 +- 46 files changed, 451 insertions(+), 116 deletions(-) create mode 100644 core/startos/Effects.ts create mode 100644 core/startos/bindings/AddSslOptions.ts create mode 100644 core/startos/bindings/Algorithm.ts create mode 100644 core/startos/bindings/BindKind.ts create mode 100644 core/startos/bindings/BindParams.ts create mode 100644 core/startos/bindings/Callback.ts create mode 100644 core/startos/bindings/ChrootParams.ts create mode 100644 core/startos/bindings/CreateOverlayedImageParams.ts create mode 100644 core/startos/bindings/DestroyOverlayedImageParams.ts create mode 100644 core/startos/bindings/ExecuteAction.ts create mode 100644 core/startos/bindings/ExposeForDependentsParams.ts create mode 100644 core/startos/bindings/ExposeUiParams.ts create mode 100644 core/startos/bindings/GetHostInfoParams.ts create mode 100644 core/startos/bindings/GetHostInfoParamsKind.ts create mode 100644 core/startos/bindings/GetServiceInterfaceParams.ts create mode 100644 core/startos/bindings/GetSslCertificateParams.ts create mode 100644 core/startos/bindings/GetSslKeyParams.ts create mode 100644 core/startos/bindings/GetStoreParams.ts create mode 100644 core/startos/bindings/ParamsMaybePackageId.ts create mode 100644 core/startos/bindings/ParamsPackageId.ts create mode 100644 core/startos/bindings/SetConfigured.ts create mode 100644 core/startos/bindings/SetHealth.ts create mode 100644 core/startos/bindings/SetMainStatus.ts create mode 100644 core/startos/bindings/SetStoreParams.ts create mode 100644 core/startos/bindings/Status.ts create mode 100644 sdk/lib/test/startosTypeValidation.test.ts diff --git a/Makefile b/Makefile index bc1edc6fe..286f79da5 100644 --- a/Makefile +++ b/Makefile @@ -173,7 +173,11 @@ container-runtime/node_modules: container-runtime/package.json container-runtime npm --prefix container-runtime ci touch container-runtime/node_modules -sdk/dist: $(shell git ls-files sdk) +core/startos/bindings: $(CORE_SRC) $(ENVIRONMENT_FILE) $(PLATFORM_FILE) + (cd core/ && cargo test) + touch core/startos/bindings + +sdk/dist: $(shell git ls-files sdk) core/startos/bindings (cd sdk && make bundle) container-runtime/dist: container-runtime/node_modules $(shell git ls-files container-runtime/src) container-runtime/package.json container-runtime/tsconfig.json diff --git a/core/Cargo.lock b/core/Cargo.lock index aec941882..2d800eda1 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "addr2line" version = "0.21.0" @@ -2679,6 +2685,7 @@ dependencies = [ "tokio", "torut", "tracing", + "ts-rs", "yasi", ] @@ -4723,6 +4730,7 @@ dependencies = [ "tracing-journald", "tracing-subscriber", "trust-dns-server", + "ts-rs", "typed-builder", "url", "urlencoding", @@ -5426,6 +5434,29 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ts-rs" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2cae1fc5d05d47aa24b64f9a4f7cba24cdc9187a2084dd97ac57bef5eccae6" +dependencies = [ + "thiserror", + "ts-rs-macros", +] + +[[package]] +name = "ts-rs-macros" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f7f9b821696963053a89a7bd8b292dc34420aea8294d7b225274d488f3ec92" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn 2.0.52", + "termcolor", +] + [[package]] name = "tungstenite" version = "0.21.0" diff --git a/core/models/Cargo.toml b/core/models/Cargo.toml index 250ba22a7..9f6a53443 100644 --- a/core/models/Cargo.toml +++ b/core/models/Cargo.toml @@ -32,6 +32,7 @@ sqlx = { version = "0.7.2", features = [ "postgres", ] } ssh-key = "0.6.2" +ts-rs = "7" thiserror = "1.0" tokio = { version = "1", features = ["full"] } torut = { git = "https://github.com/Start9Labs/torut.git", branch = "update/dependencies" } diff --git a/core/models/src/id/action.rs b/core/models/src/id/action.rs index 9b814a98a..992c995f7 100644 --- a/core/models/src/id/action.rs +++ b/core/models/src/id/action.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{Id, InvalidId}; -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, ts_rs::TS)] pub struct ActionId(Id); impl FromStr for ActionId { type Err = InvalidId; diff --git a/core/models/src/id/health_check.rs b/core/models/src/id/health_check.rs index dc643c912..72c2947e7 100644 --- a/core/models/src/id/health_check.rs +++ b/core/models/src/id/health_check.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Deserializer, Serialize}; use crate::Id; -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, ts_rs::TS)] pub struct HealthCheckId(Id); impl std::fmt::Display for HealthCheckId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/core/models/src/id/image.rs b/core/models/src/id/image.rs index 8a4f87175..5fd91a5a1 100644 --- a/core/models/src/id/image.rs +++ b/core/models/src/id/image.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize}; use crate::{Id, InvalidId, PackageId, Version}; -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, ts_rs::TS)] pub struct ImageId(Id); impl AsRef for ImageId { fn as_ref(&self) -> &Path { diff --git a/core/models/src/id/mod.rs b/core/models/src/id/mod.rs index efbe1f818..ef38ece9d 100644 --- a/core/models/src/id/mod.rs +++ b/core/models/src/id/mod.rs @@ -27,12 +27,12 @@ lazy_static::lazy_static! { pub static ref SYSTEM_ID: Id = Id(InternedString::intern("x_system")); } -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -pub struct Id(InternedString); +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, ts_rs::TS)] +pub struct Id(#[ts(type = "string")] InternedString); impl TryFrom for Id { type Error = InvalidId; fn try_from(value: InternedString) -> Result { - if ID_REGEX.is_match(&*value) { + if ID_REGEX.is_match(&value) { Ok(Id(value)) } else { Err(InvalidId) @@ -52,7 +52,7 @@ impl TryFrom for Id { impl TryFrom<&str> for Id { type Error = InvalidId; fn try_from(value: &str) -> Result { - if ID_REGEX.is_match(&value) { + if ID_REGEX.is_match(value) { Ok(Id(InternedString::intern(value))) } else { Err(InvalidId) @@ -67,7 +67,7 @@ impl From for InternedString { impl std::ops::Deref for Id { type Target = str; fn deref(&self) -> &Self::Target { - &*self.0 + &self.0 } } impl std::fmt::Display for Id { @@ -77,7 +77,7 @@ impl std::fmt::Display for Id { } impl AsRef for Id { fn as_ref(&self) -> &str { - &*self.0 + &self.0 } } impl Borrow for Id { @@ -99,7 +99,7 @@ impl Serialize for Id { where Ser: Serializer, { - serializer.serialize_str(&*self) + serializer.serialize_str(self) } } impl<'q> sqlx::Encode<'q, sqlx::Postgres> for Id { diff --git a/core/models/src/id/package.rs b/core/models/src/id/package.rs index 060f541c3..8f71285c6 100644 --- a/core/models/src/id/package.rs +++ b/core/models/src/id/package.rs @@ -3,6 +3,7 @@ use std::path::Path; use std::str::FromStr; use serde::{Deserialize, Serialize, Serializer}; +use ts_rs::TS; use yasi::InternedString; use crate::{Id, InvalidId, SYSTEM_ID}; @@ -10,7 +11,7 @@ use crate::{Id, InvalidId, SYSTEM_ID}; lazy_static::lazy_static! { pub static ref SYSTEM_PACKAGE_ID: PackageId = PackageId(SYSTEM_ID.clone()); } -#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, TS)] pub struct PackageId(Id); impl FromStr for PackageId { type Err = InvalidId; @@ -36,7 +37,7 @@ impl From for InternedString { impl std::ops::Deref for PackageId { type Target = str; fn deref(&self) -> &Self::Target { - &*self.0 + &self.0 } } impl AsRef for PackageId { diff --git a/core/startos/Cargo.toml b/core/startos/Cargo.toml index fd36c3de6..5d48179f9 100644 --- a/core/startos/Cargo.toml +++ b/core/startos/Cargo.toml @@ -174,6 +174,7 @@ tracing-futures = "0.2.5" tracing-journald = "0.3.0" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } trust-dns-server = "0.23.1" +ts-rs = "7.1.1" typed-builder = "0.18.0" url = { version = "2.4.1", features = ["serde"] } urlencoding = "2.1.3" diff --git a/core/startos/Effects.ts b/core/startos/Effects.ts new file mode 100644 index 000000000..9be56724e --- /dev/null +++ b/core/startos/Effects.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface SetStoreParams { value: any, path: string, } \ No newline at end of file diff --git a/core/startos/bindings/AddSslOptions.ts b/core/startos/bindings/AddSslOptions.ts new file mode 100644 index 000000000..304bcb515 --- /dev/null +++ b/core/startos/bindings/AddSslOptions.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface AddSslOptions { scheme: string | null, preferredExternalPort: number, addXForwardedHeaders: boolean | null, } \ No newline at end of file diff --git a/core/startos/bindings/Algorithm.ts b/core/startos/bindings/Algorithm.ts new file mode 100644 index 000000000..d12447f04 --- /dev/null +++ b/core/startos/bindings/Algorithm.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type Algorithm = "ecdsa" | "ed25519"; \ No newline at end of file diff --git a/core/startos/bindings/BindKind.ts b/core/startos/bindings/BindKind.ts new file mode 100644 index 000000000..e026fb081 --- /dev/null +++ b/core/startos/bindings/BindKind.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type BindKind = "static" | "single" | "multi"; \ No newline at end of file diff --git a/core/startos/bindings/BindParams.ts b/core/startos/bindings/BindParams.ts new file mode 100644 index 000000000..8d8eef6b4 --- /dev/null +++ b/core/startos/bindings/BindParams.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AddSslOptions } from "./AddSslOptions"; +import type { BindKind } from "./BindKind"; + +export interface BindParams { kind: BindKind, id: string, internalPort: number, scheme: string, preferredExternalPort: number, addSsl: AddSslOptions | null, secure: boolean, ssl: boolean, } \ No newline at end of file diff --git a/core/startos/bindings/Callback.ts b/core/startos/bindings/Callback.ts new file mode 100644 index 000000000..9c4cacab0 --- /dev/null +++ b/core/startos/bindings/Callback.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type Callback = () => void; \ No newline at end of file diff --git a/core/startos/bindings/ChrootParams.ts b/core/startos/bindings/ChrootParams.ts new file mode 100644 index 000000000..afbfb83b8 --- /dev/null +++ b/core/startos/bindings/ChrootParams.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ChrootParams { env: string | null, workdir: string | null, user: string | null, path: string, command: string, args: string[], } \ No newline at end of file diff --git a/core/startos/bindings/CreateOverlayedImageParams.ts b/core/startos/bindings/CreateOverlayedImageParams.ts new file mode 100644 index 000000000..98a72b497 --- /dev/null +++ b/core/startos/bindings/CreateOverlayedImageParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ImageId } from "./ImageId"; + +export interface CreateOverlayedImageParams { imageId: ImageId, } \ No newline at end of file diff --git a/core/startos/bindings/DestroyOverlayedImageParams.ts b/core/startos/bindings/DestroyOverlayedImageParams.ts new file mode 100644 index 000000000..aef910544 --- /dev/null +++ b/core/startos/bindings/DestroyOverlayedImageParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ImageId } from "./ImageId"; + +export interface DestroyOverlayedImageParams { imageId: ImageId, guid: string, } \ No newline at end of file diff --git a/core/startos/bindings/ExecuteAction.ts b/core/startos/bindings/ExecuteAction.ts new file mode 100644 index 000000000..a92852147 --- /dev/null +++ b/core/startos/bindings/ExecuteAction.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ActionId } from "./ActionId"; +import type { PackageId } from "./PackageId"; + +export interface ExecuteAction { serviceId: PackageId | null, actionId: ActionId, input: any, } \ No newline at end of file diff --git a/core/startos/bindings/ExposeForDependentsParams.ts b/core/startos/bindings/ExposeForDependentsParams.ts new file mode 100644 index 000000000..4a1d627b6 --- /dev/null +++ b/core/startos/bindings/ExposeForDependentsParams.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ExposeForDependentsParams { paths: string[], } \ No newline at end of file diff --git a/core/startos/bindings/ExposeUiParams.ts b/core/startos/bindings/ExposeUiParams.ts new file mode 100644 index 000000000..dcf649285 --- /dev/null +++ b/core/startos/bindings/ExposeUiParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ExposedUI } from "./ExposedUI"; + +export interface ExposeUiParams { paths: Array, } \ No newline at end of file diff --git a/core/startos/bindings/GetHostInfoParams.ts b/core/startos/bindings/GetHostInfoParams.ts new file mode 100644 index 000000000..4041bff45 --- /dev/null +++ b/core/startos/bindings/GetHostInfoParams.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Callback } from "./Callback"; +import type { GetHostInfoParamsKind } from "./GetHostInfoParamsKind"; + +export interface GetHostInfoParams { kind: GetHostInfoParamsKind | null, serviceInterfaceId: string, packageId: string | null, callback: Callback, } \ No newline at end of file diff --git a/core/startos/bindings/GetHostInfoParamsKind.ts b/core/startos/bindings/GetHostInfoParamsKind.ts new file mode 100644 index 000000000..6d401f685 --- /dev/null +++ b/core/startos/bindings/GetHostInfoParamsKind.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type GetHostInfoParamsKind = "multi"; \ No newline at end of file diff --git a/core/startos/bindings/GetServiceInterfaceParams.ts b/core/startos/bindings/GetServiceInterfaceParams.ts new file mode 100644 index 000000000..e0e4d2477 --- /dev/null +++ b/core/startos/bindings/GetServiceInterfaceParams.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Callback } from "./Callback"; +import type { PackageId } from "./PackageId"; + +export interface GetServiceInterfaceParams { packageId: PackageId | null, serviceInterfaceId: string, callback: Callback, } \ No newline at end of file diff --git a/core/startos/bindings/GetSslCertificateParams.ts b/core/startos/bindings/GetSslCertificateParams.ts new file mode 100644 index 000000000..5be8333a5 --- /dev/null +++ b/core/startos/bindings/GetSslCertificateParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Algorithm } from "./Algorithm"; + +export interface GetSslCertificateParams { packageId: string | null, hostId: string, algorithm: Algorithm | null, } \ No newline at end of file diff --git a/core/startos/bindings/GetSslKeyParams.ts b/core/startos/bindings/GetSslKeyParams.ts new file mode 100644 index 000000000..ca7e0e404 --- /dev/null +++ b/core/startos/bindings/GetSslKeyParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Algorithm } from "./Algorithm"; + +export interface GetSslKeyParams { packageId: string | null, hostId: string, algorithm: Algorithm | null, } \ No newline at end of file diff --git a/core/startos/bindings/GetStoreParams.ts b/core/startos/bindings/GetStoreParams.ts new file mode 100644 index 000000000..f2087832a --- /dev/null +++ b/core/startos/bindings/GetStoreParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { PackageId } from "./PackageId"; + +export interface GetStoreParams { packageId: PackageId | null, path: string, } \ No newline at end of file diff --git a/core/startos/bindings/ParamsMaybePackageId.ts b/core/startos/bindings/ParamsMaybePackageId.ts new file mode 100644 index 000000000..9a2e46c0b --- /dev/null +++ b/core/startos/bindings/ParamsMaybePackageId.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { PackageId } from "./PackageId"; + +export interface ParamsMaybePackageId { packageId: PackageId | null, } \ No newline at end of file diff --git a/core/startos/bindings/ParamsPackageId.ts b/core/startos/bindings/ParamsPackageId.ts new file mode 100644 index 000000000..784f268f5 --- /dev/null +++ b/core/startos/bindings/ParamsPackageId.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { PackageId } from "./PackageId"; + +export interface ParamsPackageId { packageId: PackageId, } \ No newline at end of file diff --git a/core/startos/bindings/SetConfigured.ts b/core/startos/bindings/SetConfigured.ts new file mode 100644 index 000000000..05e1c7f83 --- /dev/null +++ b/core/startos/bindings/SetConfigured.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface SetConfigured { configured: boolean, } \ No newline at end of file diff --git a/core/startos/bindings/SetHealth.ts b/core/startos/bindings/SetHealth.ts new file mode 100644 index 000000000..d4c202067 --- /dev/null +++ b/core/startos/bindings/SetHealth.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { HealthCheckId } from "./HealthCheckId"; +import type { HealthCheckString } from "./HealthCheckString"; + +export interface SetHealth { name: HealthCheckId, status: HealthCheckString, message: string | null, } \ No newline at end of file diff --git a/core/startos/bindings/SetMainStatus.ts b/core/startos/bindings/SetMainStatus.ts new file mode 100644 index 000000000..86e7d9b2f --- /dev/null +++ b/core/startos/bindings/SetMainStatus.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Status } from "./Status"; + +export interface SetMainStatus { status: Status, } \ No newline at end of file diff --git a/core/startos/bindings/SetStoreParams.ts b/core/startos/bindings/SetStoreParams.ts new file mode 100644 index 000000000..9be56724e --- /dev/null +++ b/core/startos/bindings/SetStoreParams.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface SetStoreParams { value: any, path: string, } \ No newline at end of file diff --git a/core/startos/bindings/Status.ts b/core/startos/bindings/Status.ts new file mode 100644 index 000000000..fdfaea244 --- /dev/null +++ b/core/startos/bindings/Status.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type Status = "running" | "stopped"; \ No newline at end of file diff --git a/core/startos/src/db/model.rs b/core/startos/src/db/model.rs index f166ed3e0..d3dd9db74 100644 --- a/core/startos/src/db/model.rs +++ b/core/startos/src/db/model.rs @@ -529,9 +529,10 @@ pub struct ExposedDependent { copyable: Option, qr: Option, } -#[derive(Clone, Debug, Deserialize, Serialize, HasModel)] +#[derive(Clone, Debug, Deserialize, Serialize, HasModel, ts_rs::TS)] #[model = "Model"] pub struct ExposedUI { + #[ts(type = "string")] pub path: JsonPointer, pub title: String, pub description: Option, diff --git a/core/startos/src/service/service_effect_handler.rs b/core/startos/src/service/service_effect_handler.rs index 08de40b8f..4524eb0ee 100644 --- a/core/startos/src/service/service_effect_handler.rs +++ b/core/startos/src/service/service_effect_handler.rs @@ -11,6 +11,7 @@ use models::{ActionId, HealthCheckId, ImageId, PackageId}; use patch_db::json_ptr::JsonPointer; use rpc_toolkit::{from_fn, from_fn_async, AnyContext, Context, Empty, HandlerExt, ParentHandler}; use tokio::process::Command; +use ts_rs::TS; use crate::db::model::ExposedUI; use crate::disk::mount::filesystem::idmapped::IdMapped; @@ -127,36 +128,103 @@ pub fn service_effect_handler() -> ParentHandler { "getServiceInterface", from_fn_async(get_service_interface).no_cli(), ) + .subcommand("clearBindings", from_fn_async(clear_bindings).no_cli()) + .subcommand("bind", from_fn_async(bind).no_cli()) + .subcommand("getHostInfo", from_fn_async(get_host_info).no_cli()) // TODO @DrBonez when we get the new api for 4.0 - // .subcommand("setDependencies",from_fn(set_dependencies)) - // .subcommand("embassyGetInterface",from_fn(embassy_get_interface)) - // .subcommand("mount",from_fn(mount)) - // .subcommand("removeAction",from_fn(remove_action)) - // .subcommand("removeAddress",from_fn(remove_address)) - // .subcommand("exportAction",from_fn(export_action)) - // .subcommand("bind",from_fn(bind)) - // .subcommand("clearServiceInterfaces",from_fn(clear_network_interfaces)) - // .subcommand("exportServiceInterface",from_fn(export_network_interface)) - // .subcommand("clearBindings",from_fn(clear_bindings)) - // .subcommand("getHostnames",from_fn(get_hostnames)) - // .subcommand("getInterface",from_fn(get_interface)) - // .subcommand("listInterface",from_fn(list_interface)) - // .subcommand("getIPHostname",from_fn(get_ip_hostname)) - // .subcommand("getContainerIp",from_fn(get_container_ip)) - // .subcommand("getLocalHostname",from_fn(get_local_hostname)) - // .subcommand("getPrimaryUrl",from_fn(get_primary_url)) - // .subcommand("getServicePortForward",from_fn(get_service_port_forward)) - // .subcommand("getServiceTorHostname",from_fn(get_service_tor_hostname)) - // .subcommand("getSystemSmtp",from_fn(get_system_smtp)) - // .subcommand("reverseProxy",from_fn(reverse_pro)xy) + // .subcommand("setDependencies",from_fn_async(set_dependencies).no_cli()) + // .subcommand("embassyGetInterface",from_fn_async(embassy_get_interface).no_cli()) + // .subcommand("mount",from_fn_async(mount).no_cli()) + // .subcommand("removeAction",from_fn_async(remove_action).no_cli()) + // .subcommand("removeAddress",from_fn_async(remove_address).no_cli()) + // .subcommand("exportAction",from_fn_async(export_action).no_cli()) + // .subcommand("clearServiceInterfaces",from_fn_async(clear_network_interfaces).no_cli()) + // .subcommand("exportServiceInterface",from_fn_async(export_network_interface).no_cli()) + // .subcommand("getHostnames",from_fn_async(get_hostnames).no_cli()) + // .subcommand("getInterface",from_fn_async(get_interface).no_cli()) + // .subcommand("listInterface",from_fn_async(list_interface).no_cli()) + // .subcommand("getIPHostname",from_fn_async(get_ip_hostname).no_cli()) + // .subcommand("getContainerIp",from_fn_async(get_container_ip).no_cli()) + // .subcommand("getLocalHostname",from_fn_async(get_local_hostname).no_cli()) + // .subcommand("getPrimaryUrl",from_fn_async(get_primary_url).no_cli()) + // .subcommand("getServicePortForward",from_fn_async(get_service_port_forward).no_cli()) + // .subcommand("getServiceTorHostname",from_fn_async(get_service_tor_hostname).no_cli()) + // .subcommand("getSystemSmtp",from_fn_async(get_system_smtp).no_cli()) + // .subcommand("reverseProxy",from_fn_async(reverse_proxy).no_cli()) // TODO Callbacks } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser)] + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[ts(export)] +struct Callback(#[ts(type = "() => void")] i64); + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] +enum GetHostInfoParamsKind { + Multi, +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export)] +struct GetHostInfoParams { + kind: Option, + service_interface_id: String, + package_id: Option, + callback: Callback, +} +async fn get_host_info( + _: AnyContext, + GetHostInfoParams { .. }: GetHostInfoParams, +) -> Result { + todo!() +} + +async fn clear_bindings(context: EffectContext, _: Empty) -> Result { + todo!() +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export)] + +enum BindKind { + Static, + Single, + Multi, +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export)] + +struct AddSslOptions { + scheme: Option, + preferred_external_port: u32, + add_x_forwarded_headers: Option, +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export)] +struct BindParams { + kind: BindKind, + id: String, + internal_port: u32, + scheme: String, + preferred_external_port: u32, + add_ssl: Option, + secure: bool, + ssl: bool, +} +async fn bind(_: AnyContext, BindParams { .. }: BindParams) -> Result { + todo!() +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export)] struct GetServiceInterfaceParams { package_id: Option, service_interface_id: String, - callback: String, + callback: Callback, } async fn get_service_interface( _: AnyContext, @@ -190,8 +258,9 @@ async fn get_service_interface( })) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct ChrootParams { #[arg(short = 'e', long = "env")] env: Option, @@ -200,7 +269,9 @@ struct ChrootParams { #[arg(short = 'u', long = "user")] user: Option, path: PathBuf, + #[ts(type = "string")] command: OsString, + #[ts(type = "string[]")] args: Vec, } fn chroot( @@ -250,11 +321,22 @@ fn chroot( cmd.args(args); Err(cmd.exec().into()) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] +enum Algorithm { + Ecdsa, + Ed25519, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export)] struct GetSslCertificateParams { package_id: Option, - algorithm: Option, //"ecdsa" | "ed25519" + host_id: String, + algorithm: Option, //"ecdsa" | "ed25519" } async fn get_ssl_certificate( @@ -262,33 +344,39 @@ async fn get_ssl_certificate( GetSslCertificateParams { package_id, algorithm, + host_id, }: GetSslCertificateParams, ) -> Result { let fake = include_str!("./fake.cert.pem"); Ok(json!([fake, fake, fake])) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct GetSslKeyParams { package_id: Option, - algorithm: Option, //"ecdsa" | "ed25519" + host_id: String, + algorithm: Option, } async fn get_ssl_key( context: EffectContext, GetSslKeyParams { package_id, + host_id, algorithm, }: GetSslKeyParams, ) -> Result { let fake = include_str!("./fake.cert.key"); Ok(json!(fake)) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct GetStoreParams { package_id: Option, + #[ts(type = "string")] path: JsonPointer, } @@ -311,10 +399,13 @@ async fn get_store( .ok_or_else(|| Error::new(eyre!("Did not find value at path"), ErrorKind::NotFound))? .clone()) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct SetStoreParams { + #[ts(type = "any")] value: Value, + #[ts(type = "string")] path: JsonPointer, } @@ -344,9 +435,11 @@ async fn set_store( Ok(()) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct ExposeForDependentsParams { + #[ts(type = "string[]")] paths: Vec, } @@ -372,8 +465,9 @@ async fn expose_for_dependents( .await?; Ok(()) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct ExposeUiParams { paths: Vec, } @@ -400,13 +494,16 @@ async fn expose_ui( .await?; Ok(()) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[ts(export)] +#[serde(rename_all = "camelCase")] struct ParamsPackageId { - package: PackageId, + package_id: PackageId, } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)] #[serde(rename_all = "camelCase")] #[command(rename_all = "camelCase")] +#[ts(export)] struct ParamsMaybePackageId { package_id: Option, } @@ -417,16 +514,18 @@ async fn exists(context: EffectContext, params: ParamsPackageId) -> Result, action_id: ActionId, + #[ts(type = "any")] input: Value, } async fn execute_action( @@ -529,9 +628,10 @@ async fn shutdown(context: EffectContext, _: Empty) -> Result { Ok(json!(())) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)] #[serde(rename_all = "camelCase")] #[command(rename_all = "camelCase")] +#[ts(export)] struct SetConfigured { configured: bool, } @@ -556,8 +656,9 @@ async fn set_configured(context: EffectContext, params: SetConfigured) -> Result Ok(json!(())) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] enum Status { Running, Stopped, @@ -579,9 +680,10 @@ impl ValueParserFactory for Status { } } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Parser, TS)] #[serde(rename_all = "camelCase")] #[command(rename_all = "camelCase")] +#[ts(export)] struct SetMainStatus { status: Status, } @@ -595,8 +697,9 @@ async fn set_main_status(context: EffectContext, params: SetMainStatus) -> Resul Ok(Value::Null) } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[ts(export)] struct SetHealth { name: HealthCheckId, status: HealthCheckString, @@ -663,11 +766,13 @@ async fn set_health( .await?; Ok(json!(())) } -#[derive(serde::Deserialize, serde::Serialize, Parser)] +#[derive(serde::Deserialize, serde::Serialize, Parser, TS)] #[serde(rename_all = "camelCase")] #[command(rename_all = "camelCase")] +#[ts(export)] pub struct DestroyOverlayedImageParams { image_id: ImageId, + #[ts(type = "string")] guid: InternedString, } @@ -689,9 +794,10 @@ pub async fn destroy_overlayed_image( } Ok(()) } -#[derive(serde::Deserialize, serde::Serialize, Parser)] +#[derive(serde::Deserialize, serde::Serialize, Parser, TS)] #[serde(rename_all = "camelCase")] #[command(rename_all = "camelCase")] +#[ts(export)] pub struct CreateOverlayedImageParams { image_id: ImageId, } diff --git a/core/startos/src/status/health_check.rs b/core/startos/src/status/health_check.rs index fef879e33..fd3a89683 100644 --- a/core/startos/src/status/health_check.rs +++ b/core/startos/src/status/health_check.rs @@ -23,7 +23,7 @@ impl std::fmt::Display for HealthCheckResult { } } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, ts_rs::TS)] #[serde(rename_all = "camelCase")] pub enum HealthCheckString { Passing, diff --git a/sdk/lib/health/HealthCheck.ts b/sdk/lib/health/HealthCheck.ts index 1cbc5ebf2..652aed94e 100644 --- a/sdk/lib/health/HealthCheck.ts +++ b/sdk/lib/health/HealthCheck.ts @@ -60,6 +60,6 @@ function asMessage(e: unknown) { if (typeof e === "object" && e != null && "message" in e) return String(e.message) const value = String(e) - if (value.length == null) return undefined + if (value.length == null) return null return value } diff --git a/sdk/lib/health/checkFns/CheckResult.ts b/sdk/lib/health/checkFns/CheckResult.ts index 1b2f54f39..8b46ee5c4 100644 --- a/sdk/lib/health/checkFns/CheckResult.ts +++ b/sdk/lib/health/checkFns/CheckResult.ts @@ -2,5 +2,5 @@ import { HealthStatus } from "../../types" export type CheckResult = { status: HealthStatus - message?: string + message: string | null } diff --git a/sdk/lib/interfaces/Host.ts b/sdk/lib/interfaces/Host.ts index 80368fe51..4c3f43634 100644 --- a/sdk/lib/interfaces/Host.ts +++ b/sdk/lib/interfaces/Host.ts @@ -57,7 +57,7 @@ export type Scheme = string | null type AddSslOptions = { scheme: Scheme preferredExternalPort: number - addXForwardedHeaders?: boolean /** default: false */ + addXForwardedHeaders: boolean | null /** default: false */ } type Security = { secure: false; ssl: false } | { secure: true; ssl: boolean } export type BindOptions = { @@ -82,13 +82,13 @@ type BindOptionsByKnownProtocol = | ({ protocol: ProtocolsWithSslVariants preferredExternalPort?: number - scheme?: Scheme + scheme: Scheme | null } & ({ noAddSsl: true } | { addSsl?: Partial })) | { protocol: NotProtocolsWithSslVariants preferredExternalPort?: number - scheme?: Scheme - addSsl?: AddSslOptions | null + scheme: Scheme | null + addSsl: AddSslOptions | null } type BindOptionsByProtocol = BindOptionsByKnownProtocol | BindOptions @@ -185,6 +185,7 @@ export class Host { if ("noAddSsl" in options && options.noAddSsl) return null if ("withSsl" in protoInfo && protoInfo.withSsl) return { + addXForwardedHeaders: null, preferredExternalPort: knownProtocols[protoInfo.withSsl].defaultPort, scheme: protoInfo.withSsl, ...("addSsl" in options ? options.addSsl : null), diff --git a/sdk/lib/test/host.test.ts b/sdk/lib/test/host.test.ts index d891bd52c..89776cf66 100644 --- a/sdk/lib/test/host.test.ts +++ b/sdk/lib/test/host.test.ts @@ -7,7 +7,10 @@ describe("host", () => { async function test(effects: Effects) { const utils = createUtils(effects) const foo = utils.host.multi("foo") - const fooOrigin = await foo.bindPort(80, { protocol: "http" as const }) + const fooOrigin = await foo.bindPort(80, { + protocol: "http" as const, + scheme: null, + }) const fooInterface = new ServiceInterfaceBuilder({ effects, name: "Foo", diff --git a/sdk/lib/test/startosTypeValidation.test.ts b/sdk/lib/test/startosTypeValidation.test.ts new file mode 100644 index 000000000..b07d6dd0c --- /dev/null +++ b/sdk/lib/test/startosTypeValidation.test.ts @@ -0,0 +1,75 @@ +import { Effects } from "../types" +import { ExecuteAction } from "../../../core/startos/bindings/ExecuteAction" +import { CreateOverlayedImageParams } from "../../../core/startos/bindings/CreateOverlayedImageParams" +import { DestroyOverlayedImageParams } from "../../../core/startos/bindings/DestroyOverlayedImageParams" +import { BindParams } from "../../../core/startos/bindings/BindParams" +import { GetHostInfoParams } from "../../../core/startos/bindings/GetHostInfoParams" +import { ParamsPackageId } from "../../../core/startos/bindings/ParamsPackageId" +import { ParamsMaybePackageId } from "../../../core/startos/bindings/ParamsMaybePackageId" +import { SetConfigured } from "../../../core/startos/bindings/SetConfigured" +import { SetHealth } from "../../../core/startos/bindings/SetHealth" +import { ExposeForDependentsParams } from "../../../core/startos/bindings/ExposeForDependentsParams" +import { ExposeUiParams } from "../../../core/startos/bindings/ExposeUiParams" +import { GetSslCertificateParams } from "../../../core/startos/bindings/GetSslCertificateParams" +import { GetSslKeyParams } from "../../../core/startos/bindings/GetSslKeyParams" +import { GetServiceInterfaceParams } from "../../../core/startos/bindings/GetServiceInterfaceParams" + +function typeEquality(_a: ExpectedType) {} +describe("startosTypeValidation ", () => { + test(`checking the params match`, () => { + const testInput: any = {} + typeEquality<{ + [K in keyof Effects & + ( + | "gitInfo" + | "echo" + | "chroot" + | "exists" + | "executeAction" + | "getConfigured" + | "stopped" + | "running" + | "restart" + | "shutdown" + | "setConfigured" + | "setMainStatus" + | "setHealth" + | "getStore" + | "setStore" + | "exposeForDependents" + | "exposeUi" + | "createOverlayedImage" + | "destroyOverlayedImage" + | "getSslCertificate" + | "getSslKey" + | "getServiceInterface" + | "clearBindings" + | "bind" + | "getHostInfo" + )]: Effects[K] extends Function ? Parameters[0] : never + }>({ + executeAction: {} as ExecuteAction, + createOverlayedImage: {} as CreateOverlayedImageParams, + destroyOverlayedImage: {} as DestroyOverlayedImageParams, + clearBindings: undefined, + bind: {} as BindParams, + getHostInfo: {} as GetHostInfoParams, + exists: {} as ParamsPackageId, + getConfigured: undefined, + stopped: {} as ParamsMaybePackageId, + running: {} as ParamsMaybePackageId, + restart: undefined, + shutdown: undefined, + setConfigured: {} as SetConfigured, + setHealth: {} as SetHealth, + exposeForDependents: {} as ExposeForDependentsParams, + exposeUi: {} as ExposeUiParams, + getSslCertificate: {} as GetSslCertificateParams, + getSslKey: {} as GetSslKeyParams, + getServiceInterface: {} as GetServiceInterfaceParams, + }) + typeEquality[0]>( + testInput as ExecuteAction, + ) + }) +}) diff --git a/sdk/lib/types.ts b/sdk/lib/types.ts index 335372d6c..d863fe3d1 100644 --- a/sdk/lib/types.ts +++ b/sdk/lib/types.ts @@ -1,7 +1,8 @@ export * as configTypes from "./config/configTypes" +import { AddSslOptions } from "../../core/startos/bindings/AddSslOptions" import { InputSpec } from "./config/configTypes" import { DependenciesReceipt } from "./config/setupConfig" -import { BindOptions } from "./interfaces/Host" +import { BindOptions, Scheme } from "./interfaces/Host" import { Daemons } from "./mainFn/Daemons" import { UrlString } from "./util/getServiceInterface" import { ServiceInterfaceType, Signals } from "./util/utils" @@ -247,6 +248,7 @@ export type ServiceInterfaceWithHostInfo = ServiceInterface & { // prettier-ignore export type ExposeAllServicePaths = + Store extends never ? string : Store extends Record ? {[K in keyof Store & string]: ExposeAllServicePaths}[keyof Store & string] : PreviousPath // prettier-ignore @@ -254,10 +256,10 @@ export type ExposeAllUiPaths = Store extends Record ? {[K in keyof Store & string]: ExposeAllUiPaths}[keyof Store & string] : Store extends string ? PreviousPath : never -export type ExposeServicePaths = Array<{ +export type ExposeServicePaths = { /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ - path: ExposeAllServicePaths -}> + paths: Store extends never ? string[] : ExposeAllServicePaths[] +} export type ExposeUiPaths = Array<{ /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ @@ -292,24 +294,28 @@ export type Effects = { /** Removes all network bindings */ clearBindings(): Promise /** Creates a host connected to the specified port with the provided options */ - bind( - options: { - kind: "static" | "single" | "multi" - id: string - internalPort: number - } & BindOptions, - ): Promise + bind(options: { + kind: "static" | "single" | "multi" + id: string + internalPort: number + + scheme: Scheme + preferredExternalPort: number + addSsl: AddSslOptions | null + secure: boolean + ssl: boolean + }): Promise /** Retrieves the current hostname(s) associated with a host id */ + // getHostInfo(options: { + // kind: "static" | "single" + // serviceInterfaceId: string + // packageId: string | null + // callback: () => void + // }): Promise getHostInfo(options: { - kind: "static" | "single" + kind: "multi" | null serviceInterfaceId: string - packageId?: string - callback: () => void - }): Promise - getHostInfo(options: { - kind?: "multi" - serviceInterfaceId: string - packageId?: string + packageId: string | null callback: () => void }): Promise @@ -368,12 +374,17 @@ export type Effects = { */ exportServiceInterface(options: ServiceInterface): Promise - exposeForDependents( - options: ExposeServicePaths, - ): Promise + exposeForDependents(options: { paths: string[] }): Promise exposeUi(options: { - paths: ExposeUiPaths + paths: { + path: string + title: string + description?: string | undefined + masked?: boolean | undefined + copyable?: boolean | undefined + qr?: boolean | undefined + }[] }): Promise /** * There are times that we want to see the addresses that where exported @@ -382,7 +393,7 @@ export type Effects = { * Note: any auth should be filtered out already */ getServiceInterface(options: { - packageId?: PackageId + packageId: PackageId | null serviceInterfaceId: ServiceInterfaceId callback: () => void }): Promise @@ -392,7 +403,7 @@ export type Effects = { * @param options */ getPrimaryUrl(options: { - packageId?: PackageId + packageId: PackageId | null serviceInterfaceId: ServiceInterfaceId callback: () => void }): Promise @@ -404,7 +415,7 @@ export type Effects = { * Note: any auth should be filtered out already */ listServiceInterfaces(options: { - packageId?: PackageId + packageId: PackageId | null callback: () => void }): Promise @@ -429,38 +440,38 @@ export type Effects = { * This called after a valid set config as well as during init. * @param configured */ - setConfigured(configured: boolean): Promise + setConfigured(options: { configured: boolean }): Promise /** * * @returns PEM encoded fullchain (ecdsa) */ - getSslCertificate: ( - packageId: string | null, - hostId: string, - algorithm?: "ecdsa" | "ed25519", - ) => Promise<[string, string, string]> + getSslCertificate: (options: { + packageId: string | null + hostId: string + algorithm: "ecdsa" | "ed25519" | null + }) => Promise<[string, string, string]> /** * @returns PEM encoded ssl key (ecdsa) */ - getSslKey: ( - packageId: string | null, - hostId: string, - algorithm?: "ecdsa" | "ed25519", - ) => Promise + getSslKey: (options: { + packageId: string | null + hostId: string + algorithm: "ecdsa" | "ed25519" | null + }) => Promise setHealth(o: { name: string status: HealthStatus - message?: string + message: string | null }): Promise /** Set the dependencies of what the service needs, usually ran during the set config as a best practice */ setDependencies(dependencies: Dependencies): Promise /** Exists could be useful during the runtime to know if some service exists, option dep */ - exists(packageId: PackageId): Promise + exists(options: { packageId: PackageId }): Promise /** Exists could be useful during the runtime to know if some service is running, option dep */ - running(packageId: PackageId): Promise + running(options: { packageId: PackageId }): Promise /** Instead of creating proxies with nginx, we have a utility to create and maintain a proxy in the lifetime of this running. */ reverseProxy(options: { @@ -494,7 +505,7 @@ export type Effects = { } }): Promise - stopped(packageId?: string): Promise + stopped(options: { packageId: string | null }): Promise } // prettier-ignore diff --git a/sdk/lib/util/getServiceInterface.ts b/sdk/lib/util/getServiceInterface.ts index dd2712849..d5ad048e3 100644 --- a/sdk/lib/util/getServiceInterface.ts +++ b/sdk/lib/util/getServiceInterface.ts @@ -185,7 +185,7 @@ const makeInterfaceFilled = async ({ }: { effects: Effects id: string - packageId: string | undefined + packageId: string | null callback: () => void }) => { const serviceInterfaceValue = await effects.getServiceInterface({ @@ -195,6 +195,7 @@ const makeInterfaceFilled = async ({ }) const hostInfo = await effects.getHostInfo({ packageId, + kind: null, serviceInterfaceId: serviceInterfaceValue.id, callback, }) @@ -220,7 +221,7 @@ const makeInterfaceFilled = async ({ export class GetServiceInterface { constructor( readonly effects: Effects, - readonly opts: { id: string; packageId?: string }, + readonly opts: { id: string; packageId: string | null }, ) {} /** @@ -276,7 +277,7 @@ export class GetServiceInterface { } export function getServiceInterface( effects: Effects, - opts: { id: string; packageId?: string }, + opts: { id: string; packageId: string | null }, ) { return new GetServiceInterface(effects, opts) } diff --git a/sdk/lib/util/getServiceInterfaces.ts b/sdk/lib/util/getServiceInterfaces.ts index 176918bb3..a7106568b 100644 --- a/sdk/lib/util/getServiceInterfaces.ts +++ b/sdk/lib/util/getServiceInterfaces.ts @@ -11,7 +11,7 @@ const makeManyInterfaceFilled = async ({ callback, }: { effects: Effects - packageId: string | undefined + packageId: string | null callback: () => void }) => { const serviceInterfaceValues = await effects.listServiceInterfaces({ @@ -25,6 +25,7 @@ const makeManyInterfaceFilled = async ({ [ id, await effects.getHostInfo({ + kind: null, packageId, serviceInterfaceId: id, callback, @@ -37,6 +38,7 @@ const makeManyInterfaceFilled = async ({ const serviceInterfacesFilled: ServiceInterfaceFilled[] = await Promise.all( serviceInterfaceValues.map(async (serviceInterfaceValue) => { const hostInfo = await effects.getHostInfo({ + kind: null, packageId, serviceInterfaceId: serviceInterfaceValue.id, callback, @@ -64,7 +66,7 @@ const makeManyInterfaceFilled = async ({ export class GetServiceInterfaces { constructor( readonly effects: Effects, - readonly opts: { packageId?: string }, + readonly opts: { packageId: string | null }, ) {} /** @@ -119,7 +121,7 @@ export class GetServiceInterfaces { } export function getServiceInterfaces( effects: Effects, - opts: { packageId?: string }, + opts: { packageId: string | null }, ) { return new GetServiceInterfaces(effects, opts) } diff --git a/sdk/lib/util/utils.ts b/sdk/lib/util/utils.ts index f0592385e..cc18c7714 100644 --- a/sdk/lib/util/utils.ts +++ b/sdk/lib/util/utils.ts @@ -177,14 +177,17 @@ export const createUtils = < serviceInterface: { getOwn: (id: ServiceInterfaceId) => - getServiceInterface(effects, { id }) as GetServiceInterface & - WrapperOverWrite, + getServiceInterface(effects, { + id, + packageId: null, + }) as GetServiceInterface & WrapperOverWrite, get: (opts: { id: ServiceInterfaceId; packageId: PackageId }) => getServiceInterface(effects, opts) as GetServiceInterface & WrapperOverWrite, getAllOwn: () => - getServiceInterfaces(effects, {}) as GetServiceInterfaces & - WrapperOverWrite, + getServiceInterfaces(effects, { + packageId: null, + }) as GetServiceInterfaces & WrapperOverWrite, getAll: (opts: { packageId: PackageId }) => getServiceInterfaces(effects, opts) as GetServiceInterfaces & WrapperOverWrite,