46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import "server-only";
|
|
|
|
import { SYSTEM_COMMANDS } from "../../domains/system/commands/system-commands";
|
|
import type { HousekeepingCommand } from "./registry";
|
|
import {
|
|
registerHousekeepingCommand,
|
|
sealHousekeepingCommandRegistry,
|
|
} from "./registry";
|
|
|
|
type PreserveHousekeepingCommand<Definition> =
|
|
Definition extends HousekeepingCommand<infer _Input, infer _Output>
|
|
? Definition
|
|
: never;
|
|
|
|
type HousekeepingCommandTuple<Commands extends readonly unknown[]> =
|
|
Commands & {
|
|
readonly [Index in keyof Commands]: PreserveHousekeepingCommand<
|
|
Commands[Index]
|
|
>;
|
|
};
|
|
|
|
export function defineHousekeepingCommands<
|
|
const Commands extends readonly unknown[],
|
|
>(...commands: HousekeepingCommandTuple<Commands>): Commands {
|
|
return commands;
|
|
}
|
|
|
|
export function registerHousekeepingCommands<
|
|
const Commands extends readonly unknown[],
|
|
>(commands: HousekeepingCommandTuple<Commands>): void {
|
|
for (const command of commands) {
|
|
registerHousekeepingCommand(
|
|
command as unknown as HousekeepingCommand<unknown, unknown>,
|
|
);
|
|
}
|
|
}
|
|
|
|
const currentHousekeepingCommands = defineHousekeepingCommands(
|
|
...SYSTEM_COMMANDS,
|
|
);
|
|
|
|
registerHousekeepingCommands(currentHousekeepingCommands);
|
|
sealHousekeepingCommandRegistry();
|
|
|
|
export const housekeepingCommandRegistryReady = true;
|