fix the types

This commit is contained in:
J H
2024-01-30 16:28:40 -07:00
parent cbded5f4e9
commit 01ad2421b4
8 changed files with 24 additions and 50 deletions

View File

@@ -42,12 +42,12 @@ export class Backups<M extends SDKManifest> {
private constructor(
private options = DEFAULT_OPTIONS,
private backupSet = [] as BackupSet<keyof M["volumes"] & string>[],
private backupSet = [] as BackupSet<M["volumes"][0]>[],
) {}
static volumes<M extends SDKManifest = never>(
...volumeNames: Array<keyof M["volumes"] & string>
) {
return new Backups().addSets(
...volumeNames: Array<M["volumes"][0]>
): Backups<M> {
return new Backups<M>().addSets(
...volumeNames.map((srcVolume) => ({
srcVolume,
srcPath: "./",
@@ -57,7 +57,7 @@ export class Backups<M extends SDKManifest> {
)
}
static addSets<M extends SDKManifest = never>(
...options: BackupSet<keyof M["volumes"] & string>[]
...options: BackupSet<M["volumes"][0]>[]
) {
return new Backups().addSets(...options)
}
@@ -75,7 +75,7 @@ export class Backups<M extends SDKManifest> {
}
return this
}
volumes(...volumeNames: Array<keyof M["volumes"] & string>) {
volumes(...volumeNames: Array<M["volumes"][0]>) {
return this.addSets(
...volumeNames.map((srcVolume) => ({
srcVolume,
@@ -85,7 +85,7 @@ export class Backups<M extends SDKManifest> {
})),
)
}
addSets(...options: BackupSet<keyof M["volumes"] & string>[]) {
addSets(...options: BackupSet<M["volumes"][0]>[]) {
options.forEach((x) =>
this.backupSet.push({ ...x, options: { ...this.options, ...x.options } }),
)

View File

@@ -4,14 +4,14 @@ import { ExpectedExports } from "../types"
import { _ } from "../util"
export type SetupBackupsParams<M extends SDKManifest> = Array<
(keyof M["volumes"] & string) | Backups<M>
M["volumes"][0] | Backups<M>
>
export function setupBackups<M extends SDKManifest>(
...args: _<SetupBackupsParams<M>>
) {
const backups = Array<Backups<M>>()
const volumes = new Set<keyof M["volumes"] & string>()
const volumes = new Set<M["volumes"][0]>()
for (const arg of args) {
if (arg instanceof Backups) {
backups.push(arg)

View File

@@ -35,7 +35,7 @@ class SetupDependencyMounts<Building> {
addPath<
Name extends string,
Volume extends keyof M["volumes"] & string,
Volume extends M["volumes"][0] & string,
Path extends string,
ManifestId extends M["id"],
M extends SDKManifest,

View File

@@ -5,6 +5,7 @@ import { TriggerInput } from "../trigger/TriggerInput"
import { defaultTrigger } from "../trigger/defaultTrigger"
import { DaemonReturned, Effects, ValidIfNoStupidEscape } from "../types"
import { createUtils } from "../util"
import { Signals } from "../util/utils"
type Daemon<Ids extends string, Command extends string, Id extends string> = {
id: "" extends Id ? never : Id
command: ValidIfNoStupidEscape<Command> | [string, ...string[]]
@@ -128,7 +129,7 @@ export class Daemons<Ids extends string> {
})
}
return {
async term(options?: { signal?: string; timeout?: number }) {
async term(options?: { signal?: Signals; timeout?: number }) {
await Promise.all(
Object.values<Promise<DaemonReturned>>(daemonsStarted).map((x) =>
x.then((x) => x.term(options)),

View File

@@ -4,12 +4,16 @@ export function setupManifest<
Id extends string,
Version extends ManifestVersion,
Dependencies extends Record<string, unknown>,
Volumes extends string[],
VolumesTypes extends string,
AssetTypes extends string,
ImagesTypes extends string,
Manifest extends SDKManifest & {
dependencies: Dependencies
id: Id
version: Version
volumes: Volumes
assets: AssetTypes[]
images: ImagesTypes[]
volumes: VolumesTypes[]
},
>(manifest: Manifest): Manifest {
return manifest

View File

@@ -35,6 +35,7 @@ describe("mountDependencies", () => {
},
dependencies: {},
})
const clnManifestVolumes = clnManifest.volumes
const lndManifest = setupManifest({
id: "lnd",
title: "",

View File

@@ -3,7 +3,7 @@ import { InputSpec } from "./config/configTypes"
import { DependenciesReceipt } from "./config/setupConfig"
import { PortOptions } from "./interfaces/Host"
import { UrlString } from "./util/getNetworkInterface"
import { NetworkInterfaceType } from "./util/utils"
import { NetworkInterfaceType, Signals } from "./util/utils"
export type ExportedAction = (options: {
effects: Effects
@@ -148,7 +148,7 @@ export type CommandType<A extends string> =
export type DaemonReturned = {
wait(): Promise<string>
term(): Promise<void>
term(options?: { signal?: Signals; timeout?: number }): Promise<void>
}
export type ActionMetadata = {
@@ -495,40 +495,7 @@ export type ActionResult = {
}
export type SetResult = {
/** These are the unix process signals */
signal:
| "SIGTERM"
| "SIGHUP"
| "SIGINT"
| "SIGQUIT"
| "SIGILL"
| "SIGTRAP"
| "SIGABRT"
| "SIGBUS"
| "SIGFPE"
| "SIGKILL"
| "SIGUSR1"
| "SIGSEGV"
| "SIGUSR2"
| "SIGPIPE"
| "SIGALRM"
| "SIGSTKFLT"
| "SIGCHLD"
| "SIGCONT"
| "SIGSTOP"
| "SIGTSTP"
| "SIGTTIN"
| "SIGTTOU"
| "SIGURG"
| "SIGXCPU"
| "SIGXFSZ"
| "SIGVTALRM"
| "SIGPROF"
| "SIGWINCH"
| "SIGIO"
| "SIGPWR"
| "SIGSYS"
| "SIGEMT"
| "SIGINFO"
signal: Signals
"depends-on": DependsOn
}

View File

@@ -37,7 +37,8 @@ import {
import * as CP from "node:child_process"
import { promisify } from "node:util"
import { splitCommand } from "./splitCommand"
export type Signals = "SIGTERM" | "SIGKILL"
export type Signals = NodeJS.Signals
export const SIGTERM: Signals = "SIGTERM"
export const SIGKILL: Signals = "SIGTERM"
export const NO_TIMEOUT = -1