mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
fix: Daemons should exclude previous, and not have nothing
This commit is contained in:
@@ -4,12 +4,8 @@ import { Trigger } from "../health/trigger"
|
|||||||
import { defaultTrigger } from "../health/trigger/defaultTrigger"
|
import { defaultTrigger } from "../health/trigger/defaultTrigger"
|
||||||
import { DaemonReturned, Effects, ValidIfNoStupidEscape } from "../types"
|
import { DaemonReturned, Effects, ValidIfNoStupidEscape } from "../types"
|
||||||
import { InterfaceReceipt } from "./interfaceReceipt"
|
import { InterfaceReceipt } from "./interfaceReceipt"
|
||||||
type Daemon<
|
type Daemon<Ids extends string, Command extends string, Id extends string> = {
|
||||||
Ids extends string | never,
|
id: "" extends Id ? never : Id
|
||||||
Command extends string,
|
|
||||||
Id extends string,
|
|
||||||
> = {
|
|
||||||
id: Id
|
|
||||||
command: ValidIfNoStupidEscape<Command> | [string, ...string[]]
|
command: ValidIfNoStupidEscape<Command> | [string, ...string[]]
|
||||||
|
|
||||||
ready: {
|
ready: {
|
||||||
@@ -18,7 +14,6 @@ type Daemon<
|
|||||||
trigger?: Trigger
|
trigger?: Trigger
|
||||||
}
|
}
|
||||||
requires?: Exclude<Ids, Id>[]
|
requires?: Exclude<Ids, Id>[]
|
||||||
intervalTime?: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +40,7 @@ Daemons.with({
|
|||||||
.build()
|
.build()
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
export class Daemons<Ids extends string | never> {
|
export class Daemons<Ids extends string> {
|
||||||
private constructor(
|
private constructor(
|
||||||
readonly effects: Effects,
|
readonly effects: Effects,
|
||||||
readonly started: (onTerm: () => void) => null,
|
readonly started: (onTerm: () => void) => null,
|
||||||
@@ -61,9 +56,13 @@ export class Daemons<Ids extends string | never> {
|
|||||||
return new Daemons<never>(config.effects, config.started)
|
return new Daemons<never>(config.effects, config.started)
|
||||||
}
|
}
|
||||||
addDaemon<Id extends string, Command extends string>(
|
addDaemon<Id extends string, Command extends string>(
|
||||||
newDaemon: Daemon<Ids, Command, Id>,
|
id: "" extends Id ? never : Id extends Ids ? never : Id,
|
||||||
|
newDaemon: Omit<Daemon<Ids, Command, Id>, "id">,
|
||||||
) {
|
) {
|
||||||
const daemons = ((this?.daemons ?? []) as any[]).concat(newDaemon)
|
const daemons = ((this?.daemons ?? []) as any[]).concat({
|
||||||
|
...newDaemon,
|
||||||
|
id,
|
||||||
|
})
|
||||||
return new Daemons<Ids | Id>(this.effects, this.started, daemons)
|
return new Daemons<Ids | Id>(this.effects, this.started, daemons)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user