| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 1 | import { z } from "zod"; |
| 2 | import { Node } from "@xyflow/react"; |
| 3 | import { Domain, ServiceType, VolumeType } from "./types.js"; |
| 4 | |
| 5 | export const serviceAnalyzisSchema = z.object({ |
| 6 | name: z.string(), |
| 7 | location: z.string(), |
| 8 | configVars: z.array( |
| 9 | z.object({ |
| 10 | name: z.string(), |
| 11 | category: z.enum(["CommandLineFlag", "EnvironmentVariable"]), |
| 12 | type: z.optional(z.enum(["String", "Number", "Boolean"])), |
| 13 | semanticType: z.optional( |
| 14 | z.enum([ |
| 15 | "EXPANDED_ENV_VAR", |
| 16 | "PORT", |
| 17 | "FILESYSTEM_PATH", |
| 18 | "DATABASE_URL", |
| 19 | "SQLITE_PATH", |
| 20 | "POSTGRES_URL", |
| 21 | "POSTGRES_PASSWORD", |
| 22 | "POSTGRES_USER", |
| 23 | "POSTGRES_DB", |
| 24 | "POSTGRES_PORT", |
| 25 | "POSTGRES_HOST", |
| 26 | "POSTGRES_SSL", |
| 27 | "MONGO_URL", |
| 28 | "MONGO_PASSWORD", |
| 29 | "MONGO_USER", |
| 30 | "MONGO_DB", |
| 31 | "MONGO_PORT", |
| 32 | "MONGO_HOST", |
| 33 | "MONGO_SSL", |
| 34 | ]), |
| 35 | ), |
| 36 | }), |
| 37 | ), |
| 38 | }); |
| 39 | |
| 40 | export type BoundEnvVar = |
| 41 | | { |
| 42 | id: string; |
| 43 | source: string | null; |
| 44 | } |
| 45 | | { |
| 46 | id: string; |
| 47 | source: string | null; |
| 48 | name: string; |
| 49 | isEditting: boolean; |
| 50 | } |
| 51 | | { |
| 52 | id: string; |
| 53 | source: string | null; |
| 54 | name: string; |
| 55 | alias: string; |
| 56 | isEditting: boolean; |
| 57 | } |
| 58 | | { |
| 59 | id: string; |
| 60 | source: string | null; |
| 61 | portId: string; |
| 62 | name: string; |
| 63 | alias: string; |
| 64 | isEditting: boolean; |
| gio | 1dacf1c | 2025-07-03 16:39:04 +0000 | [diff] [blame] | 65 | } |
| 66 | | { |
| 67 | id: string; |
| 68 | source: null; |
| 69 | name: string; |
| 70 | value: string; |
| 71 | isEditting?: boolean; |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | export type EnvVar = { |
| 75 | name: string; |
| 76 | value: string; |
| 77 | }; |
| 78 | |
| 79 | export type InitData = { |
| 80 | label: string; |
| 81 | envVars: BoundEnvVar[]; |
| 82 | ports: Port[]; |
| 83 | }; |
| 84 | |
| 85 | export type NodeData = InitData & { |
| 86 | activeField?: string | undefined; |
| 87 | state?: string | null; |
| 88 | }; |
| 89 | |
| 90 | export type PortConnectedTo = { |
| 91 | serviceId: string; |
| 92 | portId: string; |
| 93 | }; |
| 94 | |
| 95 | export type NetworkData = NodeData & { |
| 96 | domain: string; |
| 97 | }; |
| 98 | |
| 99 | export type NetworkNode = Node<NetworkData> & { |
| 100 | type: "network"; |
| 101 | }; |
| 102 | |
| 103 | export type GatewayHttpsData = NodeData & { |
| 104 | readonly?: boolean; |
| 105 | network?: string; |
| 106 | subdomain?: string; |
| 107 | https?: PortConnectedTo; |
| 108 | auth?: { |
| 109 | enabled: boolean; |
| 110 | groups: string[]; |
| 111 | noAuthPathPatterns: string[]; |
| 112 | }; |
| 113 | }; |
| 114 | |
| 115 | export type GatewayHttpsNode = Node<GatewayHttpsData> & { |
| 116 | type: "gateway-https"; |
| 117 | }; |
| 118 | |
| 119 | export type GatewayTCPData = NodeData & { |
| 120 | readonly?: boolean; |
| 121 | network?: string; |
| 122 | subdomain?: string; |
| 123 | exposed: PortConnectedTo[]; |
| 124 | selected?: { |
| 125 | serviceId?: string; |
| 126 | portId?: string; |
| 127 | }; |
| 128 | }; |
| 129 | |
| 130 | export type GatewayTCPNode = Node<GatewayTCPData> & { |
| 131 | type: "gateway-tcp"; |
| 132 | }; |
| 133 | |
| 134 | export type Port = { |
| 135 | id: string; |
| 136 | name: string; |
| 137 | value: number; |
| 138 | }; |
| 139 | |
| 140 | export type ServiceData = NodeData & { |
| 141 | type: ServiceType; |
| 142 | repository?: |
| 143 | | { |
| 144 | id: number; |
| 145 | repoNodeId: string; |
| 146 | } |
| 147 | | { |
| 148 | id: number; |
| 149 | repoNodeId: string; |
| 150 | branch: string; |
| 151 | } |
| 152 | | { |
| 153 | id: number; |
| 154 | repoNodeId: string; |
| 155 | branch: string; |
| 156 | rootDir: string; |
| 157 | }; |
| 158 | env: string[]; |
| 159 | volume: string[]; |
| 160 | preBuildCommands: string; |
| 161 | isChoosingPortToConnect: boolean; |
| 162 | dev?: |
| 163 | | { |
| 164 | enabled: false; |
| 165 | expose?: Domain; |
| 166 | } |
| 167 | | { |
| 168 | enabled: true; |
| 169 | expose?: Domain; |
| 170 | codeServerNodeId: string; |
| 171 | sshNodeId: string; |
| 172 | }; |
| gio | 69ff759 | 2025-07-03 06:27:21 +0000 | [diff] [blame] | 173 | model?: { |
| 174 | name: "gemini" | "claude"; |
| 175 | apiKey?: string; |
| gio | 6914832 | 2025-06-19 23:16:12 +0400 | [diff] [blame] | 176 | }; |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 177 | info?: z.infer<typeof serviceAnalyzisSchema>; |
| 178 | }; |
| 179 | |
| 180 | export type ServiceNode = Node<ServiceData> & { |
| 181 | type: "app"; |
| 182 | }; |
| 183 | |
| 184 | export type VolumeData = NodeData & { |
| 185 | type: VolumeType; |
| 186 | size: string; |
| 187 | attachedTo: string[]; |
| 188 | }; |
| 189 | |
| 190 | export type VolumeNode = Node<VolumeData> & { |
| 191 | type: "volume"; |
| 192 | }; |
| 193 | |
| 194 | export type PostgreSQLData = NodeData & { |
| 195 | volumeId: string; |
| 196 | }; |
| 197 | |
| 198 | export type PostgreSQLNode = Node<PostgreSQLData> & { |
| 199 | type: "postgresql"; |
| 200 | }; |
| 201 | |
| 202 | export type MongoDBData = NodeData & { |
| 203 | volumeId: string; |
| 204 | }; |
| 205 | |
| 206 | export type MongoDBNode = Node<MongoDBData> & { |
| 207 | type: "mongodb"; |
| 208 | }; |
| 209 | |
| 210 | export type GithubData = NodeData & { |
| 211 | repository?: { |
| 212 | id: number; |
| 213 | sshURL: string; |
| 214 | fullName: string; |
| 215 | }; |
| 216 | }; |
| 217 | |
| 218 | export type GithubNode = Node<GithubData> & { |
| 219 | type: "github"; |
| 220 | }; |
| 221 | |
| 222 | export type NANode = Node<NodeData> & { |
| 223 | type: undefined; |
| 224 | }; |
| 225 | |
| 226 | export type AppNode = |
| 227 | | NetworkNode |
| 228 | | GatewayHttpsNode |
| 229 | | GatewayTCPNode |
| 230 | | ServiceNode |
| 231 | | VolumeNode |
| 232 | | PostgreSQLNode |
| 233 | | MongoDBNode |
| 234 | | GithubNode |
| 235 | | NANode; |
| 236 | |
| 237 | export type NodeType = Exclude<Pick<AppNode, "type">["type"], undefined>; |
| 238 | |
| 239 | export const networkSchema = z.object({ |
| 240 | name: z.string().min(1), |
| 241 | domain: z.string().min(1), |
| 242 | hasAuth: z.boolean(), |
| 243 | }); |
| 244 | |
| 245 | export type Network = z.infer<typeof networkSchema>; |
| 246 | |
| 247 | export const accessSchema = z.discriminatedUnion("type", [ |
| 248 | z.object({ |
| 249 | type: z.literal("https"), |
| 250 | name: z.string(), |
| 251 | address: z.string(), |
| gio | cc5ce58 | 2025-06-25 07:45:21 +0400 | [diff] [blame] | 252 | agentName: z.string().optional(), |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 253 | }), |
| 254 | z.object({ |
| 255 | type: z.literal("ssh"), |
| 256 | name: z.string(), |
| 257 | host: z.string(), |
| 258 | port: z.number(), |
| 259 | }), |
| 260 | z.object({ |
| 261 | type: z.literal("tcp"), |
| 262 | name: z.string(), |
| 263 | host: z.string(), |
| 264 | port: z.number(), |
| 265 | }), |
| 266 | z.object({ |
| 267 | type: z.literal("udp"), |
| 268 | name: z.string(), |
| 269 | host: z.string(), |
| 270 | port: z.number(), |
| 271 | }), |
| 272 | z.object({ |
| 273 | type: z.literal("postgresql"), |
| 274 | name: z.string(), |
| 275 | host: z.string(), |
| 276 | port: z.number(), |
| 277 | database: z.string(), |
| 278 | username: z.string(), |
| 279 | password: z.string(), |
| 280 | }), |
| 281 | z.object({ |
| 282 | type: z.literal("mongodb"), |
| 283 | name: z.string(), |
| 284 | host: z.string(), |
| 285 | port: z.number(), |
| 286 | database: z.string(), |
| 287 | username: z.string(), |
| 288 | password: z.string(), |
| 289 | }), |
| 290 | ]); |
| 291 | |
| 292 | export const serviceInfoSchema = z.object({ |
| 293 | name: z.string(), |
| 294 | workers: z.array( |
| 295 | z.object({ |
| 296 | id: z.string(), |
| gio | a70535a | 2025-07-02 15:50:25 +0000 | [diff] [blame] | 297 | commit: z |
| 298 | .object({ |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 299 | hash: z.string(), |
| 300 | message: z.string(), |
| gio | a70535a | 2025-07-02 15:50:25 +0000 | [diff] [blame] | 301 | }) |
| 302 | .nullable() |
| 303 | .optional(), |
| 304 | commands: z |
| 305 | .array( |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 306 | z.object({ |
| 307 | command: z.string(), |
| 308 | state: z.string(), |
| 309 | }), |
| gio | a70535a | 2025-07-02 15:50:25 +0000 | [diff] [blame] | 310 | ) |
| 311 | .optional(), |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 312 | }), |
| 313 | ), |
| 314 | }); |
| 315 | |
| 316 | export const envSchema = z.object({ |
| gio | 69ff759 | 2025-07-03 06:27:21 +0000 | [diff] [blame] | 317 | deployKeyPublic: z.string().optional(), |
| 318 | instanceId: z.string().optional(), |
| 319 | networks: z.array( |
| 320 | z.object({ |
| 321 | name: z.string(), |
| 322 | domain: z.string(), |
| 323 | hasAuth: z.boolean(), |
| 324 | }), |
| 325 | ), |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 326 | integrations: z.object({ |
| 327 | github: z.boolean(), |
| gio | 6914832 | 2025-06-19 23:16:12 +0400 | [diff] [blame] | 328 | gemini: z.boolean(), |
| gio | 69ff759 | 2025-07-03 06:27:21 +0000 | [diff] [blame] | 329 | anthropic: z.boolean(), |
| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 330 | }), |
| 331 | services: z.array(serviceInfoSchema), |
| 332 | user: z.object({ |
| 333 | id: z.string(), |
| 334 | username: z.string(), |
| 335 | }), |
| 336 | access: z.array(accessSchema), |
| 337 | }); |
| 338 | |
| 339 | export type ServiceInfo = z.infer<typeof serviceInfoSchema>; |
| 340 | export type Env = z.infer<typeof envSchema>; |
| gio | cc5ce58 | 2025-06-25 07:45:21 +0400 | [diff] [blame] | 341 | export type Access = z.infer<typeof accessSchema>; |