import {REGISTRY_URL, Registry} from '../const.js' import {safeFetch} from './safeFetcher.js' export async function getRegistry( branch?: string, ): Promise<{message: string; ok: false} | {ok: true; registry: Registry}> { const registryResponse = await safeFetch(REGISTRY_URL(branch ?? 'main')) if (registryResponse.ok) { const registryJson = (await registryResponse.response.json()) as Registry registryJson.base = registryJson.base.replace('{branch}', branch ?? 'main') return { ok: true, registry: registryJson, } } return registryResponse } export async function getAvailableComponentNames(registry: Registry): Promise { return Object.keys(registry.components) } export async function getComponentURL( registry: Registry, componentName: string, dirComponentFile?: string, ): Promise { let base = registry.base + registry.paths.components.replace('{componentName}', registry.components[componentName].name) if (dirComponentFile) { base += '/' + dirComponentFile } return base } export async function getComponentRealname( registry: Registry, componentName: keyof Registry['components'], ): Promise { return registry.components[componentName].name }