feat: Move from properties to vault

This commit is contained in:
BluJ
2023-05-04 15:13:16 -06:00
parent e68b4b7652
commit 50bcad0300
7 changed files with 18 additions and 138 deletions

View File

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

View File

@@ -11,7 +11,6 @@ import "@iarna/toml"
import "./types"
import "./util"
import "yaml"
import "./properties"
import "./autoconfig"
import "./actions"
import "./manifest"

View File

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

View File

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

View File

@@ -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<PackagePropertyString, "type">) {
return new PropertyString({
...value,
type: "string",
})
}
}

View File

@@ -1,35 +0,0 @@
import { ExpectedExports, Properties } from "../types"
import { PropertyGroup } from "./PropertyGroup"
import { PropertyString } from "./PropertyString"
import "./PropertyGroup"
import "./PropertyString"
export type UnionToIntersection<T> = ((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<WrapperData>(
fn: (args: {
wrapperData: WrapperData
}) => void | Promise<void> | Promise<PropertyGroup[]>,
): 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
}

View File

@@ -24,10 +24,6 @@ export namespace ExpectedExports {
export type restoreBackup = (options: {
effects: Effects
}) => Promise<unknown>
/** Properties are used to get values from the docker, like a username + password, what ports we are hosting from */
export type properties = <WrapperData>(options: {
wrapperData: WrapperData
}) => Promise<Properties | null | undefined | void>
// /** 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<void>
stopped(packageId?: string): Promise<boolean>
vaultList(): Promise<string[]>
vaultSet(opt: { key: string; value: string }): Promise<void>
vaultMove(opt: { fromKey: string; toKey: string }): Promise<void>
vaultDelete(opt: { key: string }): Promise<void>
}
// 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