InstanceConfiguration.constants.ts 4.2 KB

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