From a02b531e47d3fdc5597106c94b8aba26bb8b07b4 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 18 Mar 2024 12:37:50 -0600 Subject: [PATCH] update sdk --- core/startos/bindings/ExposeUiParams.ts | 19 +++++- .../src/service/service_effect_handler.rs | 14 ++++- sdk/lib/StartSdk.ts | 11 +++- sdk/lib/backup/Backups.ts | 2 +- sdk/lib/backup/setupBackups.ts | 2 +- sdk/lib/index.ts | 1 + sdk/lib/inits/setupExports.ts | 4 +- sdk/lib/inits/setupInit.ts | 34 +++++++--- sdk/lib/interfaces/Host.ts | 12 ++-- sdk/lib/test/host.test.ts | 3 - sdk/lib/types.ts | 63 +++++++++++-------- sdk/lib/util/utils.ts | 19 ------ 12 files changed, 113 insertions(+), 71 deletions(-) diff --git a/core/startos/bindings/ExposeUiParams.ts b/core/startos/bindings/ExposeUiParams.ts index dcf649285..124fac851 100644 --- a/core/startos/bindings/ExposeUiParams.ts +++ b/core/startos/bindings/ExposeUiParams.ts @@ -1,4 +1,21 @@ // 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 +export type ExposeUiParams = + | { + type: "object"; + value: { [k: string]: ExposeUiParams }; + } + | { + type: "string"; + /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ + path: string; + /** A human readable description or explanation of the value */ + description: string | null; + /** (string/number only) Whether or not to mask the value, for example, when displaying a password */ + masked: boolean; + /** (string/number only) Whether or not to include a button for copying the value to clipboard */ + copyable: boolean | null; + /** (string/number only) Whether or not to include a button for displaying the value as a QR code */ + qr: boolean | null; + }; diff --git a/core/startos/src/service/service_effect_handler.rs b/core/startos/src/service/service_effect_handler.rs index 6e9610c8a..ebcbcaf08 100644 --- a/core/startos/src/service/service_effect_handler.rs +++ b/core/startos/src/service/service_effect_handler.rs @@ -691,9 +691,19 @@ async fn expose_for_dependents( } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[serde(rename_all = "camelCase")] +#[serde(tag = "type")] #[ts(export)] -struct ExposeUiParams { - paths: Vec, +enum ExposeUiParams { + Object { + value: Record, + }, + r#String { + path: String, + description: Option, + masked: bool, + copyable: Option, + qr: Option, + }, } async fn expose_ui( diff --git a/sdk/lib/StartSdk.ts b/sdk/lib/StartSdk.ts index 85f157aa9..764f419a6 100644 --- a/sdk/lib/StartSdk.ts +++ b/sdk/lib/StartSdk.ts @@ -54,6 +54,7 @@ import { } from "./interfaces/setupInterfaces" import { successFailure } from "./trigger/successFailure" import { SetupExports } from "./inits/setupExports" +import { HealthReceipt } from "./health/HealthReceipt" // prettier-ignore type AnyNeverCond = @@ -234,7 +235,15 @@ export class StartSdk { spec: Spec, ) => Config.of(spec), }, - Daemons: { of: Daemons.of }, + Daemons: { + of(config: { + effects: Effects + started: (onTerm: () => PromiseLike) => PromiseLike + healthReceipts: HealthReceipt[] + }) { + return Daemons.of(config) + }, + }, DependencyConfig: { of< LocalConfig extends Record, diff --git a/sdk/lib/backup/Backups.ts b/sdk/lib/backup/Backups.ts index 659da0ec7..20099c86d 100644 --- a/sdk/lib/backup/Backups.ts +++ b/sdk/lib/backup/Backups.ts @@ -42,7 +42,7 @@ export class Backups { private constructor( private options = DEFAULT_OPTIONS, - private backupSet = [] as BackupSet[], + private backupSet = [] as BackupSet[], ) {} static volumes( ...volumeNames: Array diff --git a/sdk/lib/backup/setupBackups.ts b/sdk/lib/backup/setupBackups.ts index d171a4aa7..af2d08410 100644 --- a/sdk/lib/backup/setupBackups.ts +++ b/sdk/lib/backup/setupBackups.ts @@ -4,7 +4,7 @@ import { ExpectedExports } from "../types" import { _ } from "../util" export type SetupBackupsParams = Array< - M["volumes"][0] | Backups + M["volumes"][number] | Backups > export function setupBackups( diff --git a/sdk/lib/index.ts b/sdk/lib/index.ts index aff2ef7ed..49d385207 100644 --- a/sdk/lib/index.ts +++ b/sdk/lib/index.ts @@ -4,6 +4,7 @@ export { Overlay } from "./util/Overlay" export { Utils } from "./util/utils" export { StartSdk } from "./StartSdk" export { setupManifest } from "./manifest/setupManifest" +export { FileHelper } from "./util/fileHelper" export * as actions from "./actions" export * as backup from "./backup" export * as config from "./config" diff --git a/sdk/lib/inits/setupExports.ts b/sdk/lib/inits/setupExports.ts index bad6dd9ad..ec5e5eb1f 100644 --- a/sdk/lib/inits/setupExports.ts +++ b/sdk/lib/inits/setupExports.ts @@ -6,11 +6,11 @@ export type SetupExports = (opts: { utils: Utils }) => | { - ui: ExposeUiPaths + ui: { [k: string]: ExposeUiPaths } services: ExposeServicePaths } | Promise<{ - ui: ExposeUiPaths + ui: { [k: string]: ExposeUiPaths } services: ExposeServicePaths }> diff --git a/sdk/lib/inits/setupInit.ts b/sdk/lib/inits/setupInit.ts index 4c52ddad2..f5581fb8d 100644 --- a/sdk/lib/inits/setupInit.ts +++ b/sdk/lib/inits/setupInit.ts @@ -1,6 +1,6 @@ import { SetInterfaces } from "../interfaces/setupInterfaces" import { SDKManifest } from "../manifest/ManifestTypes" -import { ExpectedExports } from "../types" +import { ExpectedExports, ExposeUiPaths, ExposeUiPathsAll } from "../types" import { createUtils } from "../util" import { Migrations } from "./migrations/setupMigrations" import { SetupExports } from "./setupExports" @@ -32,14 +32,12 @@ export function setupInit( utils, }) await opts.effects.exposeForDependents(services) - await opts.effects.exposeUi({ - paths: ui.map((x) => ({ - description: null, - copyable: null, - qr: null, - ...x, - })), - }) + await opts.effects.exposeUi( + forExpose({ + type: "object", + value: ui, + }), + ) }, uninit: async (opts) => { await migrations.uninit(opts) @@ -47,3 +45,21 @@ export function setupInit( }, } } + +function forExpose(ui: ExposeUiPaths): ExposeUiPathsAll { + if (ui.type === ("object" as const)) { + return { + type: "object" as const, + value: Object.fromEntries( + Object.entries(ui.value).map(([key, value]) => [key, forExpose(value)]), + ), + } + } + return { + description: null, + + copyable: null, + qr: null, + ...ui, + } +} diff --git a/sdk/lib/interfaces/Host.ts b/sdk/lib/interfaces/Host.ts index cb6fa9f9a..250f42075 100644 --- a/sdk/lib/interfaces/Host.ts +++ b/sdk/lib/interfaces/Host.ts @@ -82,15 +82,15 @@ type NotProtocolsWithSslVariants = Exclude< type BindOptionsByKnownProtocol = | { protocol: ProtocolsWithSslVariants - preferredExternalPort: number | null - scheme: Scheme | null - addSsl: Partial | null + preferredExternalPort?: number + scheme?: Scheme + addSsl?: Partial } | { protocol: NotProtocolsWithSslVariants - preferredExternalPort: number | null - scheme: Scheme | null - addSsl: AddSslOptions | null + preferredExternalPort?: number + scheme?: Scheme + addSsl?: AddSslOptions } type BindOptionsByProtocol = BindOptionsByKnownProtocol | BindOptions diff --git a/sdk/lib/test/host.test.ts b/sdk/lib/test/host.test.ts index 461d4a82a..eec63bb8a 100644 --- a/sdk/lib/test/host.test.ts +++ b/sdk/lib/test/host.test.ts @@ -9,9 +9,6 @@ describe("host", () => { const foo = utils.host.multi("foo") const fooOrigin = await foo.bindPort(80, { protocol: "http" as const, - scheme: null, - addSsl: null, - preferredExternalPort: null, }) const fooInterface = new ServiceInterfaceBuilder({ effects, diff --git a/sdk/lib/types.ts b/sdk/lib/types.ts index a578e711a..e3b9045e6 100644 --- a/sdk/lib/types.ts +++ b/sdk/lib/types.ts @@ -261,22 +261,42 @@ export type ExposeServicePaths = { paths: Store extends never ? string[] : ExposeAllServicePaths[] } -export type ExposeUiPaths = Array<{ - /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ - path: ExposeAllUiPaths - /** A human readable title for the value */ - title: string - /** A human readable description or explanation of the value */ - description?: string - /** (string/number only) Whether or not to mask the value, for example, when displaying a password */ - masked: boolean - /** (string/number only) Whether or not to include a button for copying the value to clipboard */ - copyable?: boolean - /** (string/number only) Whether or not to include a button for displaying the value as a QR code */ - qr?: boolean -}> - -type tset = keyof Effects +export type ExposeUiPaths = + | { + type: "object" + value: { [k: string]: ExposeUiPaths } + } + | { + type: "string" + /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ + path: ExposeAllUiPaths + /** A human readable description or explanation of the value */ + description?: string + /** (string/number only) Whether or not to mask the value, for example, when displaying a password */ + masked: boolean + /** (string/number only) Whether or not to include a button for copying the value to clipboard */ + copyable?: boolean + /** (string/number only) Whether or not to include a button for displaying the value as a QR code */ + qr?: boolean + } +export type ExposeUiPathsAll = + | { + type: "object" + value: { [k: string]: ExposeUiPathsAll } + } + | { + type: "string" + /** The path to the value in the Store. [JsonPath](https://jsonpath.com/) */ + path: string + /** A human readable description or explanation of the value */ + description: string | null + /** (string/number only) Whether or not to mask the value, for example, when displaying a password */ + masked: boolean + /** (string/number only) Whether or not to include a button for copying the value to clipboard */ + copyable: boolean | null + /** (string/number only) Whether or not to include a button for displaying the value as a QR code */ + qr: boolean | null + } /** Used to reach out from the pure js runtime */ export type Effects = { @@ -375,16 +395,7 @@ export type Effects = { exposeForDependents(options: { paths: string[] }): Promise - exposeUi(options: { - paths: { - path: string - title: string | null - description: string | null - masked: boolean | null - copyable: boolean | null - qr: boolean | null - }[] - }): Promise + exposeUi(options: ExposeUiPathsAll): Promise /** * There are times that we want to see the addresses that where exported * @param options.addressId If we want to filter the address id diff --git a/sdk/lib/util/utils.ts b/sdk/lib/util/utils.ts index cc18c7714..9d424888e 100644 --- a/sdk/lib/util/utils.ts +++ b/sdk/lib/util/utils.ts @@ -56,23 +56,6 @@ export type Utils< Store, WrapperOverWrite = { const: never }, > = { - checkPortListening( - port: number, - options: { - errorMessage: string - successMessage: string - timeoutMessage?: string - timeout?: number - }, - ): Promise - checkWebUrl( - url: string, - options?: { - timeout?: number - successMessage?: string - errorMessage?: string - }, - ): Promise childProcess: typeof childProcess createInterface: (options: { name: string @@ -304,8 +287,6 @@ export const createUtils = < }, } }, - checkPortListening: checkPortListening.bind(null, effects), - checkWebUrl: checkWebUrl.bind(null, effects), mountDependencies: < In extends