import { readAppYaml } from './AppContext'; import { getEnv } from './Config'; import { Rivendell } from './Rivendell'; export async function applicableShards(availability = '', fromManifest?: any): Promise { if (getEnv() === 'staging') { return ['us']; } if (availability) { return [availability]; } const manifest = fromManifest || readAppYaml(); return resolveShards(manifest); } export async function shardsFromManifest(fromManifest: any): Promise { return resolveShards(fromManifest); } export async function targetShards(): Promise { return await resolveShards(readAppYaml()); } async function resolveShards(manifest: any) { let shards = manifest.meta.availability || ['us']; if (shards.includes('all')) { shards = (await Rivendell.shards()).map((s) => s.id); } return shards.sort((a: string, b: string) => { if (a === 'us') { return -1; } if (b === 'us') { return 1; } return a.localeCompare(b); }); }