diff --git a/lib/health/HealthCheck.ts b/lib/health/HealthCheck.ts index 46c9573..7e2b54b 100644 --- a/lib/health/HealthCheck.ts +++ b/lib/health/HealthCheck.ts @@ -44,10 +44,22 @@ export function healthCheck(o: { await triggerFirstSuccess().catch((err) => { console.error(err) }) - } catch (_) { + } catch (e) { + await o.effects.setHealth({ + name: o.name, + status: "failing", + message: asMessage(e), + }) currentValue.lastResult = "failing" } } }) return {} as HealthReceipt } +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 + return value +} diff --git a/lib/index.ts b/lib/index.ts index 2e5823c..85c32e1 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -11,7 +11,6 @@ import "@iarna/toml" import "./types" import "./util" import "yaml" -import "./properties" import "./autoconfig" import "./actions" import "./manifest" diff --git a/lib/properties/PropertyGroup.ts b/lib/properties/PropertyGroup.ts deleted file mode 100644 index 65bf1b7..0000000 --- a/lib/properties/PropertyGroup.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { PackagePropertyGroup } from "../types" -import { PropertyPage } from "./PropertyPage" -import { PropertyString } from "./PropertyString" - -/** - * A Property Group is a list of values, separated from other property groups by a whitespace divider with an optional header - */ -export class PropertyGroup { - private constructor(readonly data: PackagePropertyGroup) {} - /** - * Returns a new Property Group with the provided options - * @param options - * @returns - */ - static of(options: { - header: string | null - values: (PropertyPage | PropertyString)[] - }) { - return new PropertyGroup({ - header: options.header, - value: options.values.map((x) => x.data), - }) - } -} diff --git a/lib/properties/PropertyPage.ts b/lib/properties/PropertyPage.ts deleted file mode 100644 index ef28a53..0000000 --- a/lib/properties/PropertyPage.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { PackagePropertyPage } from "../types" -import { PropertyGroup } from "./PropertyGroup" - -/** - * A Property Page will display to the user as a button with a name a description. - * Clicking the button will take the user to a nested page displaying the provided - * list of Property Groups - */ -export class PropertyPage { - private constructor(readonly data: PackagePropertyPage) {} - /** - * Returns a new Property Page with the provided options - * @param options - * @returns - */ - static of(options: { - name: string - description: string | null - groups: PropertyGroup[] - }) { - return new PropertyPage({ - type: "page", - name: options.name, - description: options.description, - value: options.groups.map((x) => x.data), - }) - } -} diff --git a/lib/properties/PropertyString.ts b/lib/properties/PropertyString.ts deleted file mode 100644 index e250e83..0000000 --- a/lib/properties/PropertyString.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { PackagePropertyString } from "../types" - -/** - * A Property String is an arbitrary string value to display to the user - */ -export class PropertyString { - private constructor(readonly data: PackagePropertyString) {} - /** - * Returns a new Property String with the provided options - * @param value - * @returns - */ - static of(value: Omit) { - return new PropertyString({ - ...value, - type: "string", - }) - } -} diff --git a/lib/properties/index.ts b/lib/properties/index.ts deleted file mode 100644 index 1c7c057..0000000 --- a/lib/properties/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { ExpectedExports, Properties } from "../types" - -import { PropertyGroup } from "./PropertyGroup" -import { PropertyString } from "./PropertyString" -import "./PropertyGroup" -import "./PropertyString" - -export type UnionToIntersection = ((x: T) => any) extends (x: infer R) => any - ? R - : never - -/** - * This is used during creating the type of properties fn in the service package. - * This fn makes sure that the return type is correct and everything is infered to - * reduce the types that the user has to make. - * @param fn - * @returns - */ -export function setupProperties( - fn: (args: { - wrapperData: WrapperData - }) => void | Promise | Promise, -): ExpectedExports.properties { - return (async (options) => { - const result = await fn( - options as { - wrapperData: WrapperData & typeof options.wrapperData - }, - ) - if (result) { - const answer: Properties = result.map((x) => x.data) - return answer - } - }) as ExpectedExports.properties -} diff --git a/lib/types.ts b/lib/types.ts index 82ee5cb..2b7373d 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -24,10 +24,6 @@ export namespace ExpectedExports { export type restoreBackup = (options: { effects: Effects }) => Promise - /** Properties are used to get values from the docker, like a username + password, what ports we are hosting from */ - export type properties = (options: { - wrapperData: WrapperData - }) => Promise // /** Health checks are used to determine if the service is working properly after starting // * A good use case is if we are using a web server, seeing if we can get to the web server. @@ -393,6 +389,11 @@ export type Effects = { }): Promise stopped(packageId?: string): Promise + + vaultList(): Promise + vaultSet(opt: { key: string; value: string }): Promise + vaultMove(opt: { fromKey: string; toKey: string }): Promise + vaultDelete(opt: { key: string }): Promise } // prettier-ignore @@ -502,32 +503,6 @@ export type KnownError = "error-code": [number, string] | readonly [number, string] } -export type PackagePropertyGroup = { - header: string | null - value: PackageProperties[] -} -export type PackageProperties = PackagePropertyPage | PackagePropertyString -export type PackagePropertyPage = { - type: "page" - name: string - description: string | null - value: Properties -} -export type PackagePropertyString = { - type: "string" - name: string - description: string | null - value: string - /** Let's the ui make this copyable button */ - copyable: boolean - /** Let the ui create a qr for this field */ - qr: boolean - /** Hiding the value unless toggled off for field */ - masked: boolean -} - -export type Properties = PackagePropertyGroup[] - export type Dependency = { id: PackageId kind: DependencyKind