From b4d8145f2adb981b462a4581bdf3bf96bc32e3d9 Mon Sep 17 00:00:00 2001 From: cashmere Date: Mon, 27 Jul 2026 00:26:31 +0200 Subject: fix: restore missing keybinding validation guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit persistence.ts imported isActionWithOptionalArgs and isShortcutKey, neither of which existed at runtime — loading persisted custom keybindings would crash. Adds actions/guards.ts (excluding required-args actions per TActionArgsMap) and isShortcutKey in keybinding.ts; the nine previously dead persistence tests now pass. --- apps/web/src/actions/guards.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 apps/web/src/actions/guards.ts (limited to 'apps/web/src/actions/guards.ts') diff --git a/apps/web/src/actions/guards.ts b/apps/web/src/actions/guards.ts new file mode 100644 index 00000000..c4fbe8a7 --- /dev/null +++ b/apps/web/src/actions/guards.ts @@ -0,0 +1,29 @@ +import { ACTIONS } from "./definitions"; +import type { TActionArgsMap, TActionWithOptionalArgs } from "./types"; + +type TActionWithRequiredArgs = { + [K in keyof TActionArgsMap]: undefined extends TActionArgsMap[K] + ? never + : K; +}[keyof TActionArgsMap]; + +/** + * Actions that require arguments cannot be bound to a shortcut key — a key + * press has no way to supply them. Keep in sync with the required (non- + * optional) members of `TActionArgsMap`; the type annotation rejects keys + * that are not actually required-args actions. + */ +const ACTIONS_WITH_REQUIRED_ARGS: readonly TActionWithRequiredArgs[] = [ + "remove-media-asset", + "remove-media-assets", +]; + +export function isActionWithOptionalArgs( + action: unknown, +): action is TActionWithOptionalArgs { + return ( + typeof action === "string" && + action in ACTIONS && + !(ACTIONS_WITH_REQUIRED_ARGS as readonly string[]).includes(action) + ); +} -- cgit v1.3.1