import type { Channel, ChannelListingEntry, ChannelMap, StoredChannel, StoredChannelMap } from "../types/index.js"; /** * User-defined channel with all channel properties. */ export type UserChannel = Channel; /** * Map of channel keys to stored channel data (full definitions or deltas). This is the raw file format for channels.json. */ export type UserChannelMap = StoredChannelMap; /** * Result of loading user channels from the file. */ export interface UserChannelsLoadResult { channels: StoredChannelMap; parseError: boolean; parseErrorMessage?: string; providerSelections: Record; } /** * Returns the path to the user channels file. * @returns The absolute path to channels.json inside the data directory. */ export declare function getUserChannelsFilePath(): string; /** * Returns whether the user channels file had a parse error. * @returns True if the channels file exists but contains invalid JSON. */ export declare function hasChannelsParseError(): boolean; /** * Returns the parse error message if the channels file had a parse error. * @returns The error message or undefined. */ export declare function getChannelsParseErrorMessage(): string | undefined; /** * Loads user channels from the channels file. Returns an empty map if the file doesn't exist, and sets parseError if the file exists but contains invalid JSON. * The file can contain a special `providerSelections` key with user's provider preferences, which is extracted separately from channels. * @returns The loaded channels with parse status and provider selections. */ export declare function loadUserChannels(): Promise; /** * Saves user channels to the channels file and updates the in-memory cache. Changes take effect immediately for new stream requests without requiring a server * restart. Creates the data directory if it doesn't exist. Provider selections are also saved if any exist. Empty deltas (no overridden fields) for predefined * channel keys are stripped before saving to avoid storing no-op entries. * @param channels - The channels to save (full definitions or delta overrides). * @throws If the file cannot be written. */ export declare function saveUserChannels(channels: StoredChannelMap): Promise; /** * Deletes a user channel by key. * @param key - The channel key to delete. * @throws If the file cannot be read or written. */ export declare function deleteUserChannel(key: string): Promise; /** * Resets all user channels by deleting the channels file. * @throws If the file exists but cannot be deleted. */ export declare function resetUserChannels(): Promise; /** * Initializes user channels by loading them from the file. This should be called once at server startup. Also builds provider groups and loads provider selections. */ export declare function initializeUserChannels(): Promise; /** * Resolves a stored channel entry (full definition or delta) into a fully resolved Channel. For user-defined channels with no predefined equivalent, the stored * entry is returned as-is (it must be a full Channel). For overrides of predefined channels, the predefined definition is used as a base and only allowlisted * delta fields are overlaid. Fields set to null in the delta are removed from the result. Fields not in the allowlist are silently ignored. * @param key - The channel key. * @param stored - The stored channel data (full definition or delta). * @returns A fully resolved Channel with all fields populated. */ export declare function resolveStoredChannel(key: string, stored: StoredChannel): Channel; /** * Returns the full channel listing with source classification and enabled status. This is the authoritative merge point for predefined and user channels — all * code that needs a merged view of channels should use this function (or getAllChannels() which delegates to it). * * For each channel key, the source is classified as: * - "predefined": exists only in predefined channels * - "user": exists only in user channels * - "override": exists in both (user channel data takes precedence) * * The enabled field reflects whether the channel is available for streaming. Predefined-only channels can be disabled via configuration; user and override * channels are always enabled. * * Provider variants (non-canonical keys in provider groups) are filtered out from this listing — they are accessed via the provider selection mechanism instead. * * Override entries produce a new resolved Channel object (via resolveStoredChannel()), which is a different reference from PREDEFINED_CHANNELS[key]. The provider * system (providers.ts) relies on this reference difference to detect user overrides via isUserOverride(). Predefined-only entries preserve the original reference. * @returns Sorted array of channel listing entries. */ export declare function getChannelListing(): ChannelListingEntry[]; /** * Returns all available channels (predefined + user), with user channels taking precedence on key conflicts. Disabled predefined channels are excluded unless they * have a user override. Built on top of getChannelListing() to ensure a single merging code path. * @returns The merged channel map with disabled predefined channels filtered out. */ export declare function getAllChannels(): ChannelMap; /** * Returns the raw stored channel data (without predefined channels). Entries may be full Channel definitions or ChannelDelta overrides. * @returns The stored channel map. */ export declare function getUserChannels(): StoredChannelMap; /** * Returns the predefined channel definition for a key. * @param key - The channel key to look up. * @returns The predefined channel, or undefined if the key is not predefined. */ export declare function getPredefinedChannel(key: string): Channel | undefined; /** * Checks if a channel key exists in the predefined channels. * @param key - The channel key to check. * @returns True if the channel is predefined. */ export declare function isPredefinedChannel(key: string): boolean; /** * Checks if a channel key exists in the user channels. * @param key - The channel key to check. * @returns True if the channel is user-defined. */ export declare function isUserChannel(key: string): boolean; /** * Checks if a predefined channel is disabled. * @param key - The channel key to check. * @returns True if the channel is predefined and disabled. */ export declare function isPredefinedChannelDisabled(key: string): boolean; /** * Returns the list of disabled predefined channel keys. * @returns Array of disabled channel keys. */ export declare function getDisabledPredefinedChannels(): string[]; /** * Returns all predefined channels regardless of disabled state, excluding provider variants. Used by the UI to show all predefined channels including disabled ones. * Provider variants are internal implementation details of channel delivery and are not channels themselves. * @returns The predefined channel map with canonical entries only. */ export declare function getPredefinedChannels(): ChannelMap; /** * Returns the keys of all predefined channels that are Pacific entries (canonical keys only). A key is Pacific if it ends in "p" and the East counterpart * (key minus trailing "p") exists in PREDEFINED_CHANNELS. * @returns Sorted array of canonical Pacific predefined channel keys. */ export declare function getPacificPredefinedKeys(): string[]; /** * Returns the keys of all predefined East channels that have Pacific counterparts (canonical keys only). A key qualifies if it does NOT end in "p" and * the Pacific counterpart (key plus "p") exists in PREDEFINED_CHANNELS. * @returns Sorted array of canonical East predefined channel keys that have Pacific counterparts. */ export declare function getEastWithPacificPredefinedKeys(): string[]; /** * Computes enabled/total counts for all three predefined channel scopes (all, east, pacific) against the current disabled set. Both the enabled count and * the total are filtered by provider availability so that the displayed counts match the visible channel table. When no provider filter is active, * all channels pass and the counts are unaffected. Used by the server-side HTML renderer and both toggle endpoints to provide consistent counts to the client. * @returns An object with `all`, `east`, and `pacific` keys, each containing `{ enabled, total }`. */ export declare function getPredefinedScopeCounts(): { all: { enabled: number; total: number; }; east: { enabled: number; total: number; }; pacific: { enabled: number; total: number; }; }; /** * Checks if a channel is available for streaming. A channel is available if it exists in the merged channel map returned by getAllChannels(), which already * excludes disabled predefined channels (unless overridden by a user channel). * @param key - The channel key to check. * @returns True if the channel can be streamed. */ export declare function isChannelAvailable(key: string): boolean; /** * Validates a channel key for format and uniqueness. * @param key - The channel key to validate. * @param isNew - True if this is a new channel (checks for duplicates among user channels). * @returns Error message if invalid, undefined if valid. */ export declare function validateChannelKey(key: string, isNew: boolean): string | undefined; /** * Validates a channel URL. * @param url - The URL to validate. * @returns Error message if invalid, undefined if valid. */ export declare function validateChannelUrl(url: string): string | undefined; /** * Validates a channel name. * @param name - The name to validate. * @returns Error message if invalid, undefined if valid. */ export declare function validateChannelName(name: string): string | undefined; /** * Validates a profile name. * @param profile - The profile name to validate (can be empty for autodetect). * @param validProfiles - Array of valid profile names. * @returns Error message if invalid, undefined if valid. */ export declare function validateChannelProfile(profile: string | undefined, validProfiles: string[]): string | undefined; /** * Result of validating imported channels. */ export interface ChannelsValidationResult { channels: ChannelMap; errors: string[]; valid: boolean; } /** * Validates an imported channels object for structure and content. * @param data - The raw imported data to validate. * @param validProfiles - Array of valid profile names. * @returns Validation result with errors if invalid. */ export declare function validateImportedChannels(data: unknown, validProfiles: string[]): ChannelsValidationResult; /** * Saves the current provider selections to the channels file. This triggers a full file save including all user channels. * @throws If the file cannot be written. */ export declare function saveProviderSelections(): Promise;