chore: Update the types and get the container-runtime working

This commit is contained in:
J H
2024-03-20 10:48:03 -06:00
parent 8d83f64aba
commit 53d82618d9
10 changed files with 139 additions and 88 deletions

View File

@@ -205,16 +205,7 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
mounts?: { path: string; options: MountOptions }[]
},
): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> => {
const commands = splitCommand(command)
const overlay = await Overlay.of(effects, imageId)
try {
for (let mount of options.mounts || []) {
await overlay.mount(mount.options, mount.path)
}
return await overlay.exec(commands)
} finally {
await overlay.destroy()
}
return runCommand<Manifest>(effects, imageId, command, options)
},
createDynamicAction: <
@@ -654,3 +645,23 @@ export class StartSdk<Manifest extends SDKManifest, Store> {
}
}
}
export async function runCommand<Manifest extends SDKManifest>(
effects: Effects,
imageId: Manifest["images"][number],
command: string | [string, ...string[]],
options: CommandOptions & {
mounts?: { path: string; options: MountOptions }[]
},
): Promise<{ stdout: string | Buffer; stderr: string | Buffer }> {
const commands = splitCommand(command)
const overlay = await Overlay.of(effects, imageId)
try {
for (let mount of options.mounts || []) {
await overlay.mount(mount.options, mount.path)
}
return await overlay.exec(commands)
} finally {
await overlay.destroy()
}
}

View File

@@ -10,6 +10,7 @@ export * as config from "./config"
export * as configBuilder from "./config/builder"
export * as configTypes from "./config/configTypes"
export * as dependencyConfig from "./dependencyConfig"
export * as daemons from "./mainFn/Daemons"
export * as health from "./health"
export * as healthFns from "./health/checkFns"
export * as inits from "./inits"
@@ -17,8 +18,10 @@ export * as mainFn from "./mainFn"
export * as manifest from "./manifest"
export * as toml from "@iarna/toml"
export * as types from "./types"
export * as T from "./types"
export * as util from "./util"
export * as yaml from "yaml"
export * as startSdk from "./StartSdk"
export * as matches from "ts-matches"
export * as YAML from "yaml"

View File

@@ -43,7 +43,7 @@ type Daemon<
type ErrorDuplicateId<Id extends string> = `The id '${Id}' is already used`
const runDaemon =
export const runDaemon =
<Manifest extends SDKManifest>() =>
async <A extends string>(
effects: Effects,

View File

@@ -7,6 +7,8 @@ import { BindOptions, Scheme } from "./interfaces/Host"
import { Daemons } from "./mainFn/Daemons"
import { UrlString } from "./util/getServiceInterface"
export { SDKManifest } from "./manifest/ManifestTypes"
export type ExportedAction = (options: {
effects: Effects
input?: Record<string, unknown>

View File

@@ -9,6 +9,8 @@ import "./Overlay"
import "./once"
import { SDKManifest } from "../manifest/ManifestTypes"
export { GetServiceInterface, getServiceInterface } from "./getServiceInterface"
export { getServiceInterfaces } from "./getServiceInterfaces"
// prettier-ignore
export type FlattenIntersection<T> =
T extends ArrayLike<any> ? T :

View File

@@ -1,8 +1,8 @@
import { arrayOf, string } from "ts-matches"
import { ValidIfNoStupidEscape } from "../types"
export const splitCommand = <A>(
command: ValidIfNoStupidEscape<A> | [string, ...string[]],
export const splitCommand = (
command: string | [string, ...string[]],
): string[] => {
if (arrayOf(string).test(command)) return command
return String(command)