export type ChannelEntryMatch = { entry?: T; key?: string; wildcardEntry?: T; wildcardKey?: string; }; export function buildChannelKeyCandidates( ...keys: Array ): string[] { const seen = new Set(); const candidates: string[] = []; for (const key of keys) { if (typeof key !== "string") continue; const trimmed = key.trim(); if (!trimmed || seen.has(trimmed)) continue; seen.add(trimmed); candidates.push(trimmed); } return candidates; } export function resolveChannelEntryMatch(params: { entries?: Record; keys: string[]; wildcardKey?: string; }): ChannelEntryMatch { const entries = params.entries ?? {}; const match: ChannelEntryMatch = {}; for (const key of params.keys) { if (!Object.prototype.hasOwnProperty.call(entries, key)) continue; match.entry = entries[key]; match.key = key; break; } if (params.wildcardKey && Object.prototype.hasOwnProperty.call(entries, params.wildcardKey)) { match.wildcardEntry = entries[params.wildcardKey]; match.wildcardKey = params.wildcardKey; } return match; }