refactor(v2): make the proxy group's exhaustiveness real

MetadataProviderKeyIn claimed a consumer would get a compile error when
a group grew a member, but the hash-matcher code branched on the key:
setHashMatcher treated every non-Hasheous key as Playmatch, so a third
proxy would silently share Playmatch's stored flag and be missing from
the switch list.

Both now hang off a Record keyed by HashMatcherKey, so adding a proxy to
the map fails to compile until it declares its own stored flag and its
name/logo/gate. providerKeysInGroup returns the narrowed union to make
that possible, and the catalog filter asks the taxonomy for the group
instead of matching against the proxy key list.

Payload wiring stays hand-written: which slot a matcher fills is set by
its backend gate, not by the taxonomy.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Sam Dornan
2026-08-21 18:44:57 -05:00
parent 54f63e0544
commit f81d5115a0
2 changed files with 26 additions and 30 deletions

View File

@@ -32,10 +32,11 @@ const LOCAL_STORAGE_LAUNCHBOX_REMOTE_ENABLED_KEY =
const LOCAL_STORAGE_HASHEOUS_ENABLED_KEY = "scan.hasheousEnabled";
const LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY = "scan.playmatchEnabled";
const HASH_MATCHER_KEYS: readonly string[] = providerKeysInGroup("proxy");
export type HashMatcherKey = MetadataProviderKeyIn<"proxy">;
// Render order for the hash-matcher switches.
const HASH_MATCHER_KEYS = providerKeysInGroup("proxy");
export interface HashMatcher {
value: HashMatcherKey;
name: string;
@@ -84,7 +85,7 @@ export function useScanProviders(): UseScanProviders {
const metadataOptions = computed(() =>
heartbeat
.getMetadataOptionsByPriority()
.filter((option) => !HASH_MATCHER_KEYS.includes(option.value))
.filter((option) => metadataProviderGroup(option.value) !== "proxy")
.map((option) => {
const requiresHashes = option.value === "ra";
let disabled = option.disabled;
@@ -120,14 +121,10 @@ export function useScanProviders(): UseScanProviders {
LOCAL_STORAGE_LAUNCHBOX_REMOTE_ENABLED_KEY,
true,
);
const hasheousEnabled = useLocalStorage(
LOCAL_STORAGE_HASHEOUS_ENABLED_KEY,
true,
);
const playmatchEnabled = useLocalStorage(
LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY,
true,
);
const hashMatcherEnabled: Record<HashMatcherKey, RemovableRef<boolean>> = {
hasheous: useLocalStorage(LOCAL_STORAGE_HASHEOUS_ENABLED_KEY, true),
playmatch: useLocalStorage(LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY, true),
};
// A group with no pick stays empty, which the selects read as All.
const metadataSources = ref<MetadataOption[]>([]);
@@ -201,9 +198,8 @@ export function useScanProviders(): UseScanProviders {
const hasheousAdmin = Boolean(sources?.HASHEOUS_API_ENABLED);
const playmatchAdmin = Boolean(sources?.PLAYMATCH_API_ENABLED);
return [
{
value: "hasheous",
const matchers: Record<HashMatcherKey, Omit<HashMatcher, "value">> = {
hasheous: {
name: "Hasheous",
logo: "/assets/scrappers/hasheous.png",
blockedReason: !hasheousAdmin
@@ -213,8 +209,7 @@ export function useScanProviders(): UseScanProviders {
: null,
switchEnabled: hasheousAdmin && !noHashes,
},
{
value: "playmatch",
playmatch: {
name: "Playmatch",
logo: "/assets/scrappers/playmatch.png",
blockedReason: !playmatchAdmin
@@ -226,19 +221,17 @@ export function useScanProviders(): UseScanProviders {
: null,
switchEnabled: playmatchAdmin && !noHashes && igdbSelected,
},
];
};
return HASH_MATCHER_KEYS.map((value) => ({ value, ...matchers[value] }));
});
function setHashMatcher(value: HashMatcherKey, next: boolean) {
if (value === "hasheous") hasheousEnabled.value = next;
else playmatchEnabled.value = next;
hashMatcherEnabled[value].value = next;
}
function isHashMatcherOn(matcher: HashMatcher): boolean {
if (!matcher.switchEnabled) return false;
return matcher.value === "hasheous"
? hasheousEnabled.value
: playmatchEnabled.value;
return matcher.switchEnabled && hashMatcherEnabled[matcher.value].value;
}
function isOn(value: HashMatcherKey): boolean {

View File

@@ -24,9 +24,9 @@ export const METADATA_PROVIDER_GROUPS = {
export type MetadataProviderKey = keyof typeof METADATA_PROVIDER_GROUPS;
/** The provider keys of one group, as a union. Lets a consumer that
* branches per provider (the hash-matcher switches) get a compile error
* when the group grows a member. */
/** The provider keys of one group, as a union. A consumer that holds
* per-provider state or config in a `Record` keyed by this gets a
* compile error when the group grows a member. */
export type MetadataProviderKeyIn<G extends MetadataProviderGroup> = {
[K in MetadataProviderKey]: (typeof METADATA_PROVIDER_GROUPS)[K] extends G
? K
@@ -40,12 +40,15 @@ export const METADATA_PROVIDER_GROUP_ORDER = [
"proxy",
] as const satisfies readonly MetadataProviderGroup[];
export function providerKeysInGroup(
group: MetadataProviderGroup,
): MetadataProviderKey[] {
export function providerKeysInGroup<G extends MetadataProviderGroup>(
group: G,
): MetadataProviderKeyIn<G>[] {
return (
Object.keys(METADATA_PROVIDER_GROUPS) as MetadataProviderKey[]
).filter((key) => METADATA_PROVIDER_GROUPS[key] === group);
).filter(
(key): key is MetadataProviderKeyIn<G> =>
METADATA_PROVIDER_GROUPS[key] === group,
);
}
/** Group of an unvalidated key (a heartbeat option value), or undefined