1/**
2 * A Fly.io region code. The literal codes are the regions Fly listed in
3 * September 2026 and give editor completion; any other string is accepted
4 * so new regions work without an Alchemy release. `bom` is deprecated by
5 * Fly. See [Regions](/fly/compute/regions).
6 */
7export type Region =
8 | "ams"
9 | "arn"
10 | "bom"
11 | "cdg"
12 | "dfw"
13 | "ewr"
14 | "fra"
15 | "gru"
16 | "iad"
17 | "jnb"
18 | "lax"
19 | "lhr"
20 | "nrt"
21 | "ord"
22 | "sin"
23 | "sjc"
24 | "syd"
25 | "yyz"
26 | (string & {});
27
28/** Normalize a `Region | Region[]` prop into a de-duplicated list. */
29export const regionList = (
30 region: Region | readonly Region[] | undefined,
31 fallback: string,
32): string[] => {
33 const list = region === undefined ? [fallback] : [region].flat();
34 const unique = [...new Set(list)];
35 return unique.length === 0 ? [fallback] : unique;
36};
37
38/**
39 * Region of replica `index` when `count` replicas run in each of
40 * `regions`. Replicas are spread round-robin, so growing `count` keeps
41 * every existing replica in its region.
42 */
43export const regionOfReplica = (regions: readonly string[], index: number) =>
44 regions[index % regions.length]!;