fix(housekeeping): isolate executable command schemas
This commit is contained in:
1 parent
00618fb2a3
commit
7895188b56
5 files changed
+431
-67
No files matched your search
@@ -6,12 +6,37 @@ import {
|
||||
sealHousekeepingCommandRegistry,
|
||||
} from "./registry";
|
||||
|
||||
const currentHousekeepingCommands =
|
||||
[] as const satisfies readonly HousekeepingCommand<unknown, unknown>[];
|
||||
type PreserveHousekeepingCommand<Definition> =
|
||||
Definition extends HousekeepingCommand<infer _Input, infer _Output>
|
||||
? Definition
|
||||
: never;
|
||||
|
||||
for (const command of currentHousekeepingCommands) {
|
||||
registerHousekeepingCommand(command);
|
||||
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;
|
||||
Reference in new issue
Block a user