mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
sdk tweaks (#2760)
* sdk tweaks * update action result types * accommodate new action response types * fix: show action value labels * Feature/get status effect (#2765) * wip: get status * feat: Add the get_status for effects * feat: Do a callback --------- Co-authored-by: J H <dragondef@gmail.com> --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> Co-authored-by: waterplea <alexander@inkin.ru> Co-authored-by: J H <dragondef@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
ServiceInterface,
|
||||
ActionRequest,
|
||||
RequestActionParams,
|
||||
MainStatus,
|
||||
} from "./osBindings"
|
||||
import { StorePath } from "./util/PathBuilder"
|
||||
import {
|
||||
@@ -61,6 +62,11 @@ export type Effects = {
|
||||
restart(): Promise<null>
|
||||
/** stop this service's main function */
|
||||
shutdown(): Promise<null>
|
||||
/** ask the host os what the service's current status is */
|
||||
getStatus(options: {
|
||||
packageId?: PackageId
|
||||
callback?: () => void
|
||||
}): Promise<MainStatus>
|
||||
/** indicate to the host os what runstate the service is in */
|
||||
setMainStatus(options: SetMainStatus): Promise<null>
|
||||
|
||||
|
||||
15
sdk/base/lib/osBindings/ActionResultMember.ts
Normal file
15
sdk/base/lib/osBindings/ActionResultMember.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ActionResultMember = {
|
||||
name: string
|
||||
description: string | null
|
||||
} & (
|
||||
| {
|
||||
type: "single"
|
||||
value: string
|
||||
copyable: boolean
|
||||
qr: boolean
|
||||
masked: boolean
|
||||
}
|
||||
| { type: "group"; value: Array<ActionResultMember> }
|
||||
)
|
||||
@@ -1,18 +1,8 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionResultValue } from "./ActionResultValue"
|
||||
|
||||
export type ActionResultV1 =
|
||||
| {
|
||||
type: "string"
|
||||
name: string
|
||||
value: string
|
||||
description: string | null
|
||||
copyable: boolean
|
||||
qr: boolean
|
||||
masked: boolean
|
||||
}
|
||||
| {
|
||||
type: "object"
|
||||
name: string
|
||||
value: Array<ActionResultV1>
|
||||
description?: string
|
||||
}
|
||||
export type ActionResultV1 = {
|
||||
title: string
|
||||
message: string | null
|
||||
result: ActionResultValue | null
|
||||
}
|
||||
|
||||
12
sdk/base/lib/osBindings/ActionResultValue.ts
Normal file
12
sdk/base/lib/osBindings/ActionResultValue.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ActionResultMember } from "./ActionResultMember"
|
||||
|
||||
export type ActionResultValue =
|
||||
| {
|
||||
type: "single"
|
||||
value: string
|
||||
copyable: boolean
|
||||
qr: boolean
|
||||
masked: boolean
|
||||
}
|
||||
| { type: "group"; value: Array<ActionResultMember> }
|
||||
5
sdk/base/lib/osBindings/GetStatusParams.ts
Normal file
5
sdk/base/lib/osBindings/GetStatusParams.ts
Normal file
@@ -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 { CallbackId } from "./CallbackId"
|
||||
import type { PackageId } from "./PackageId"
|
||||
|
||||
export type GetStatusParams = { packageId?: PackageId; callback?: CallbackId }
|
||||
@@ -7,9 +7,11 @@ export { ActionRequestEntry } from "./ActionRequestEntry"
|
||||
export { ActionRequestInput } from "./ActionRequestInput"
|
||||
export { ActionRequestTrigger } from "./ActionRequestTrigger"
|
||||
export { ActionRequest } from "./ActionRequest"
|
||||
export { ActionResultMember } from "./ActionResultMember"
|
||||
export { ActionResult } from "./ActionResult"
|
||||
export { ActionResultV0 } from "./ActionResultV0"
|
||||
export { ActionResultV1 } from "./ActionResultV1"
|
||||
export { ActionResultValue } from "./ActionResultValue"
|
||||
export { ActionSeverity } from "./ActionSeverity"
|
||||
export { ActionVisibility } from "./ActionVisibility"
|
||||
export { AddAdminParams } from "./AddAdminParams"
|
||||
@@ -79,6 +81,7 @@ export { GetServiceInterfaceParams } from "./GetServiceInterfaceParams"
|
||||
export { GetServicePortForwardParams } from "./GetServicePortForwardParams"
|
||||
export { GetSslCertificateParams } from "./GetSslCertificateParams"
|
||||
export { GetSslKeyParams } from "./GetSslKeyParams"
|
||||
export { GetStatusParams } from "./GetStatusParams"
|
||||
export { GetStoreParams } from "./GetStoreParams"
|
||||
export { GetSystemSmtpParams } from "./GetSystemSmtpParams"
|
||||
export { Governor } from "./Governor"
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
ClearCallbacksParams,
|
||||
ClearServiceInterfacesParams,
|
||||
GetActionInputParams,
|
||||
GetStatusParams,
|
||||
GetStoreParams,
|
||||
RequestActionParams,
|
||||
RunActionParams,
|
||||
@@ -89,6 +90,7 @@ describe("startosTypeValidation ", () => {
|
||||
mount: {} as MountParams,
|
||||
checkDependencies: {} as CheckDependenciesParam,
|
||||
getDependencies: undefined,
|
||||
getStatus: {} as WithCallback<GetStatusParams>,
|
||||
setMainStatus: {} as SetMainStatus,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -134,6 +134,7 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
|
||||
getDataVersion: (effects, ...args) => effects.getDataVersion(...args),
|
||||
shutdown: (effects, ...args) => effects.shutdown(...args),
|
||||
getDependencies: (effects, ...args) => effects.getDependencies(...args),
|
||||
getStatus: (effects, ...args) => effects.getStatus(...args),
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -387,8 +388,8 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
|
||||
algorithm?: T.Algorithm,
|
||||
) => new GetSslCertificate(effects, hostnames, algorithm),
|
||||
HealthCheck: {
|
||||
of(o: HealthCheckParams) {
|
||||
return healthCheck(o)
|
||||
of(effects: T.Effects, o: Omit<HealthCheckParams, "effects">) {
|
||||
return healthCheck({ effects, ...o })
|
||||
},
|
||||
},
|
||||
healthCheck: {
|
||||
@@ -636,12 +637,12 @@ export class StartSdk<Manifest extends T.SDKManifest, Store> {
|
||||
) => InputSpec.of<Spec, Store>(spec),
|
||||
},
|
||||
Daemons: {
|
||||
of(options: {
|
||||
effects: Effects
|
||||
started: (onTerm: () => PromiseLike<void>) => PromiseLike<null>
|
||||
healthReceipts: HealthReceipt[]
|
||||
}) {
|
||||
return Daemons.of<Manifest>(options)
|
||||
of(
|
||||
effects: Effects,
|
||||
started: (onTerm: () => PromiseLike<void>) => PromiseLike<null>,
|
||||
healthReceipts: HealthReceipt[],
|
||||
) {
|
||||
return Daemons.of<Manifest>({ effects, started, healthReceipts })
|
||||
},
|
||||
},
|
||||
List: {
|
||||
|
||||
@@ -15,18 +15,14 @@ import { VersionGraph } from "../version/VersionGraph"
|
||||
*/
|
||||
export function setupManifest<
|
||||
Id extends string,
|
||||
Dependencies extends Record<string, unknown>,
|
||||
VolumesTypes extends VolumeId,
|
||||
AssetTypes extends VolumeId,
|
||||
ImagesTypes extends ImageId,
|
||||
Manifest extends {
|
||||
dependencies: Dependencies
|
||||
id: Id
|
||||
assets: AssetTypes[]
|
||||
images: Record<ImagesTypes, SDKImageInputSpec>
|
||||
volumes: VolumesTypes[]
|
||||
},
|
||||
>(manifest: SDKManifest & Manifest): SDKManifest & Manifest {
|
||||
} & SDKManifest,
|
||||
>(manifest: Manifest): Manifest {
|
||||
return manifest
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ export class FileHelper<A> {
|
||||
/**
|
||||
* Accepts structured data and overwrites the existing file on disk.
|
||||
*/
|
||||
async write(data: A): Promise<null> {
|
||||
private async writeFile(data: A): Promise<null> {
|
||||
const parent = previousPath.exec(this.path)
|
||||
if (parent) {
|
||||
await fs.mkdir(parent[1], { recursive: true })
|
||||
@@ -153,13 +153,27 @@ export class FileHelper<A> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts structured data and performs a merge with the existing file on disk.
|
||||
* Accepts full structured data and performs a merge with the existing file on disk if it exists.
|
||||
*/
|
||||
async merge(data: A) {
|
||||
const fileData = (await this.readOnce().catch(() => ({}))) || {}
|
||||
async write(data: A) {
|
||||
const fileData = (await this.readOnce()) || {}
|
||||
const mergeData = merge({}, fileData, data)
|
||||
return await this.write(mergeData)
|
||||
return await this.writeFile(mergeData)
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts partial structured data and performs a merge with the existing file on disk.
|
||||
*/
|
||||
async merge(data: Partial<A>) {
|
||||
const fileData =
|
||||
(await this.readOnce()) ||
|
||||
(() => {
|
||||
throw new Error(`${this.path}: does not exist`)
|
||||
})()
|
||||
const mergeData = merge({}, fileData, data)
|
||||
return await this.writeFile(mergeData)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a File Helper for an arbitrary file type.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user