InstanceConfiguration.constants.ts126 lines · main
| 1 | import { ReadReplicaSetupError, ReadReplicaSetupProgress } from '@supabase/shared-types/out/events' |
| 2 | import type { AWS_REGIONS_KEYS } from 'shared-data' |
| 3 | import { AWS_REGIONS } from 'shared-data' |
| 4 | |
| 5 | import { components } from '@/data/api' |
| 6 | import { PROJECT_STATUS } from '@/lib/constants' |
| 7 | |
| 8 | export interface Region { |
| 9 | key: AWS_REGIONS_KEYS |
| 10 | name: string |
| 11 | region: string |
| 12 | coordinates: [number, number] |
| 13 | } |
| 14 | |
| 15 | export type NodeData = { |
| 16 | id: string |
| 17 | provider: string |
| 18 | region: Region |
| 19 | computeSize?: string |
| 20 | status: string |
| 21 | inserted_at: string |
| 22 | } |
| 23 | |
| 24 | export type PrimaryNodeData = NodeData & { |
| 25 | numReplicas: number |
| 26 | numRegions: number |
| 27 | hasLoadBalancer: boolean |
| 28 | } |
| 29 | |
| 30 | export type LoadBalancerData = NodeData & { |
| 31 | numDatabases: number |
| 32 | } |
| 33 | |
| 34 | export type ReplicaNodeData = NodeData & { |
| 35 | onSelectRestartReplica: () => void |
| 36 | onSelectResizeReplica: () => void |
| 37 | onSelectDropReplica: () => void |
| 38 | } |
| 39 | |
| 40 | export type EdgeData = { |
| 41 | status: string |
| 42 | identifier: string |
| 43 | connectionString: string | null | undefined |
| 44 | } |
| 45 | |
| 46 | // ReactFlow is scaling everything by the factor of 2 |
| 47 | export const NODE_WIDTH = 660 |
| 48 | export const NODE_SEP = 20 |
| 49 | |
| 50 | // The region wrapper is a static, non-measured sibling node with a fixed size. |
| 51 | export const REGION_NODE_HEIGHT = 162 |
| 52 | |
| 53 | // First-paint fallback heights for the dagre layout, only used before React |
| 54 | // Flow has measured the real nodes. Subsequent layouts use node.measured.height. |
| 55 | export const NODE_HEIGHT_FALLBACKS: Record<string, number> = { |
| 56 | LOAD_BALANCER: 64, |
| 57 | PRIMARY: 140, |
| 58 | READ_REPLICA: 140, |
| 59 | REGION: REGION_NODE_HEIGHT, |
| 60 | } |
| 61 | |
| 62 | export const REPLICA_STATUS: { |
| 63 | [key: string]: components['schemas']['DatabaseStatusResponse']['status'] |
| 64 | } = { |
| 65 | ...PROJECT_STATUS, |
| 66 | INIT_READ_REPLICA: 'INIT_READ_REPLICA', |
| 67 | INIT_READ_REPLICA_FAILED: 'INIT_READ_REPLICA_FAILED', |
| 68 | } |
| 69 | |
| 70 | // [Joshen] Coordinates from https://github.com/tobilg/aws-edge-locations/blob/main/data/aws-edge-locations.json |
| 71 | // In the format of [lon, lat] |
| 72 | export const AWS_REGIONS_COORDINATES: { [key: string]: [number, number] } = { |
| 73 | SOUTHEAST_ASIA: [103.8, 1.37], |
| 74 | NORTHEAST_ASIA: [139.42, 35.41], |
| 75 | NORTHEAST_ASIA_2: [126.98, 37.56], |
| 76 | CENTRAL_CANADA: [-73.6, 45.5], |
| 77 | WEST_US: [-121.96, 37.35], |
| 78 | WEST_US_2: [-122.67, 45.51], |
| 79 | EAST_US: [-78.45, 38.13], |
| 80 | WEST_EU: [-8, 53], |
| 81 | WEST_EU_2: [-0.1, 51], |
| 82 | CENTRAL_EU: [8, 50], |
| 83 | SOUTH_ASIA: [72.88, 19.08], |
| 84 | OCEANIA: [151.2, -33.86], |
| 85 | SOUTH_AMERICA: [-46.38, -23.34], |
| 86 | CENTRAL_EU_2: [8.54, 47.45], |
| 87 | EAST_US_2: [-83, 39.96], |
| 88 | NORTH_EU: [17.91, 59.65], |
| 89 | WEST_EU_3: [2.35, 48.86], |
| 90 | } |
| 91 | |
| 92 | export const FLY_REGIONS_COORDINATES: { [key: string]: [number, number] } = { |
| 93 | SOUTHEAST_ASIA: [103.8, 1.37], |
| 94 | } |
| 95 | |
| 96 | // [Joshen] Just to make sure that we just depend on AWS_REGIONS to determine available |
| 97 | // regions for replicas. Just FYI - might need to update this if we support Fly in future |
| 98 | export const AVAILABLE_REPLICA_REGIONS: Region[] = Object.keys(AWS_REGIONS) |
| 99 | .map((key) => { |
| 100 | return { |
| 101 | key: key as AWS_REGIONS_KEYS, |
| 102 | name: AWS_REGIONS?.[key as AWS_REGIONS_KEYS].displayName, |
| 103 | region: AWS_REGIONS?.[key as AWS_REGIONS_KEYS].code, |
| 104 | coordinates: AWS_REGIONS_COORDINATES[key], |
| 105 | } |
| 106 | }) |
| 107 | .filter((x) => x.coordinates !== undefined) |
| 108 | |
| 109 | // [Joshen] Just a more user friendly language, so that all the verbs are progressive |
| 110 | export const INIT_PROGRESS = { |
| 111 | [ReadReplicaSetupProgress.Requested]: 'Requesting replica instance', |
| 112 | [ReadReplicaSetupProgress.Started]: 'Launching replica instance', |
| 113 | [ReadReplicaSetupProgress.LaunchedReadReplicaInstance]: 'Initiating replica setup', |
| 114 | [ReadReplicaSetupProgress.InitiatedReadReplicaSetup]: 'Downloading base backup', |
| 115 | [ReadReplicaSetupProgress.DownloadedBaseBackup]: 'Replaying WAL archives', |
| 116 | [ReadReplicaSetupProgress.ReplayedWalArchives]: 'Completing set up', |
| 117 | [ReadReplicaSetupProgress.CompletedReadReplicaSetup]: 'Completed', |
| 118 | } |
| 119 | |
| 120 | export const ERROR_STATES = { |
| 121 | [ReadReplicaSetupError.ReadReplicaInstanceLaunchFailed]: 'Failed to launch replica', |
| 122 | [ReadReplicaSetupError.InitiateReadReplicaSetupFailed]: 'Failed to initiate replica', |
| 123 | [ReadReplicaSetupError.DownloadBaseBackupFailed]: 'Failed to download backup', |
| 124 | [ReadReplicaSetupError.ReplayWalArchivesFailed]: 'Failed to replay WAL archives', |
| 125 | [ReadReplicaSetupError.CompleteReadReplicaSetupFailed]: 'Failed to set up replica', |
| 126 | } |