mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
wip: Adding in properties and nested path
This commit is contained in:
@@ -21,9 +21,6 @@ import {
|
||||
MaybePromise,
|
||||
ServiceInterfaceId,
|
||||
PackageId,
|
||||
EnsureStorePath,
|
||||
ExtractStore,
|
||||
DaemonReturned,
|
||||
ValidIfNoStupidEscape,
|
||||
} from "./types"
|
||||
import * as patterns from "./util/patterns"
|
||||
@@ -61,7 +58,6 @@ import {
|
||||
setupInterfaces,
|
||||
} from "./interfaces/setupInterfaces"
|
||||
import { successFailure } from "./trigger/successFailure"
|
||||
import { SetupExports } from "./inits/setupExports"
|
||||
import { HealthReceipt } from "./health/HealthReceipt"
|
||||
import { MultiHost, Scheme, SingleHost, StaticHost } from "./interfaces/Host"
|
||||
import { ServiceInterfaceBuilder } from "./interfaces/ServiceInterfaceBuilder"
|
||||
@@ -79,6 +75,8 @@ import { Mounts } from "./mainFn/Mounts"
|
||||
import { Dependency } from "./Dependency"
|
||||
import * as T from "./types"
|
||||
import { Checker, EmVer } from "./emverLite/mod"
|
||||
import { ExposedStorePaths } from "./store/setupExposeStore"
|
||||
import { PathBuilder, extractJsonPath, pathBuilder } from "./store/PathBuilder"
|
||||
|
||||
// prettier-ignore
|
||||
type AnyNeverCond<T extends any[], Then, Else> =
|
||||
@@ -151,25 +149,29 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
},
|
||||
|
||||
store: {
|
||||
get: <E extends Effects, Path extends string = never>(
|
||||
get: <E extends Effects, StoreValue = unknown>(
|
||||
effects: E,
|
||||
packageId: string,
|
||||
path: EnsureStorePath<Store, Path>,
|
||||
path: PathBuilder<Store, StoreValue>,
|
||||
) =>
|
||||
removeConstType<E>()(
|
||||
getStore<Store, Path>(effects, path as any, {
|
||||
getStore<Store, StoreValue>(effects, path, {
|
||||
packageId,
|
||||
}),
|
||||
),
|
||||
getOwn: <E extends Effects, Path extends string>(
|
||||
getOwn: <E extends Effects, StoreValue = unknown>(
|
||||
effects: E,
|
||||
path: EnsureStorePath<Store, Path>,
|
||||
) => removeConstType<E>()(getStore<Store, Path>(effects, path as any)),
|
||||
setOwn: <E extends Effects, Path extends string | never>(
|
||||
path: PathBuilder<Store, StoreValue>,
|
||||
) => removeConstType<E>()(getStore<Store, StoreValue>(effects, path)),
|
||||
setOwn: <E extends Effects, Path extends PathBuilder<Store, unknown>>(
|
||||
effects: E,
|
||||
path: EnsureStorePath<Store, Path>,
|
||||
value: ExtractStore<Store, Path>,
|
||||
) => effects.store.set<Store, Path>({ value, path: path as any }),
|
||||
path: Path,
|
||||
value: Path extends PathBuilder<Store, infer Value> ? Value : never,
|
||||
) =>
|
||||
effects.store.set<Store>({
|
||||
value,
|
||||
path: extractJsonPath(path),
|
||||
}),
|
||||
},
|
||||
|
||||
host: {
|
||||
@@ -180,24 +182,17 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
multi: (effects: Effects, id: string) => new MultiHost({ id, effects }),
|
||||
},
|
||||
nullIfEmpty,
|
||||
|
||||
configConstants: { smtpConfig },
|
||||
createInterface: (
|
||||
runCommand: async <A extends string>(
|
||||
effects: Effects,
|
||||
options: {
|
||||
name: string
|
||||
id: string
|
||||
description: string
|
||||
hasPrimary: boolean
|
||||
disabled: boolean
|
||||
type: ServiceInterfaceType
|
||||
username: null | string
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
schemeOverride: { ssl: Scheme; noSsl: Scheme } | null
|
||||
masked: boolean
|
||||
imageId: Manifest["images"][number],
|
||||
command: ValidIfNoStupidEscape<A> | [string, ...string[]],
|
||||
options: CommandOptions & {
|
||||
mounts?: { path: string; options: MountOptions }[]
|
||||
},
|
||||
) => new ServiceInterfaceBuilder({ ...options, effects }),
|
||||
): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> => {
|
||||
return runCommand<Manifest>(effects, imageId, command, options)
|
||||
},
|
||||
|
||||
createAction: <
|
||||
ConfigType extends
|
||||
| Record<string, any>
|
||||
@@ -216,18 +211,25 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
const { input, ...rest } = metaData
|
||||
return createAction<Manifest, Store, ConfigType, Type>(rest, fn, input)
|
||||
},
|
||||
configConstants: { smtpConfig },
|
||||
createInterface: (
|
||||
effects: Effects,
|
||||
options: {
|
||||
name: string
|
||||
id: string
|
||||
description: string
|
||||
hasPrimary: boolean
|
||||
disabled: boolean
|
||||
type: ServiceInterfaceType
|
||||
username: null | string
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
schemeOverride: { ssl: Scheme; noSsl: Scheme } | null
|
||||
masked: boolean
|
||||
},
|
||||
) => new ServiceInterfaceBuilder({ ...options, effects }),
|
||||
getSystemSmtp: <E extends Effects>(effects: E) =>
|
||||
removeConstType<E>()(new GetSystemSmtp(effects)),
|
||||
runCommand: async <A extends string>(
|
||||
effects: Effects,
|
||||
imageId: Manifest["images"][number],
|
||||
command: ValidIfNoStupidEscape<A> | [string, ...string[]],
|
||||
options: CommandOptions & {
|
||||
mounts?: { path: string; options: MountOptions }[]
|
||||
},
|
||||
): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> => {
|
||||
return runCommand<Manifest>(effects, imageId, command, options)
|
||||
},
|
||||
|
||||
createDynamicAction: <
|
||||
ConfigType extends
|
||||
@@ -336,7 +338,6 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
})
|
||||
}
|
||||
},
|
||||
setupExports: (fn: SetupExports<Store>) => fn,
|
||||
setupInit: (
|
||||
migrations: Migrations<Manifest, Store>,
|
||||
install: Install<Manifest, Store>,
|
||||
@@ -346,15 +347,15 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
effects: Effects
|
||||
input: any
|
||||
}) => Promise<DependenciesReceipt>,
|
||||
setupExports: SetupExports<Store>,
|
||||
exposedStore: ExposedStorePaths,
|
||||
) =>
|
||||
setupInit<Manifest, Store>(
|
||||
migrations,
|
||||
install,
|
||||
uninstall,
|
||||
setInterfaces,
|
||||
setupExports,
|
||||
setDependencies,
|
||||
exposedStore,
|
||||
),
|
||||
setupInstall: (fn: InstallFn<Manifest, Store>) => Install.of(fn),
|
||||
setupInterfaces: <
|
||||
@@ -379,6 +380,12 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
this.manifest,
|
||||
...migrations,
|
||||
),
|
||||
setupProperties:
|
||||
(
|
||||
fn: (options: { effects: Effects }) => Promise<T.SdkPropertiesReturn>,
|
||||
): T.ExpectedExports.Properties =>
|
||||
(options) =>
|
||||
fn(options).then(nullifyProperties),
|
||||
setupUninstall: (fn: UninstallFn<Manifest, Store>) =>
|
||||
setupUninstall<Manifest, Store>(fn),
|
||||
trigger: {
|
||||
@@ -531,6 +538,7 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
|
||||
down: (opts: { effects: Effects }) => Promise<void>
|
||||
}) => Migration.of<Manifest, Store, Version>(options),
|
||||
},
|
||||
StorePath: pathBuilder<Store>(),
|
||||
Value: {
|
||||
toggle: Value.toggle,
|
||||
text: Value.text,
|
||||
@@ -739,3 +747,20 @@ export async function runCommand<Manifest extends SDKManifest>(
|
||||
await overlay.destroy()
|
||||
}
|
||||
}
|
||||
function nullifyProperties(value: T.SdkPropertiesReturn): T.PropertiesReturn {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).map(([k, v]) => [k, nullifyProperties_(v)]),
|
||||
)
|
||||
}
|
||||
function nullifyProperties_(value: T.SdkPropertiesValue): T.PropertiesValue {
|
||||
if (value.type === "string") {
|
||||
return { description: null, copyable: null, qr: null, ...value }
|
||||
}
|
||||
return {
|
||||
description: null,
|
||||
...value,
|
||||
value: Object.fromEntries(
|
||||
Object.entries(value.value).map(([k, v]) => [k, nullifyProperties_(v)]),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user