43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import "server-only";
|
|
|
|
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();
|
|
|
|
registerHousekeepingCommands(currentHousekeepingCommands);
|
|
sealHousekeepingCommandRegistry();
|
|
|
|
export const housekeepingCommandRegistryReady = true;
|