| 1 | import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts"; |
| 2 | |
| 3 | export interface KnownEnvironmentConnectionTarget { |
| 4 | readonly httpBaseUrl: string; |
| 5 | readonly wsBaseUrl: string; |
| 6 | } |
| 7 | |
| 8 | export type KnownEnvironmentSource = "configured" | "desktop-managed" | "manual" | "window-origin"; |
| 9 | |
| 10 | export interface KnownEnvironment { |
| 11 | readonly id: string; |
| 12 | readonly label: string; |
| 13 | readonly source: KnownEnvironmentSource; |
| 14 | readonly environmentId?: EnvironmentId; |
| 15 | readonly target: KnownEnvironmentConnectionTarget; |
| 16 | } |
| 17 | |
| 18 | export function createKnownEnvironment(input: { |
| 19 | readonly id?: string; |
| 20 | readonly label: string; |
| 21 | readonly source?: KnownEnvironmentSource; |
| 22 | readonly target: KnownEnvironmentConnectionTarget; |
| 23 | }): KnownEnvironment { |
| 24 | return { |
| 25 | id: input.id ?? `ws:${input.label}`, |
| 26 | label: input.label, |
| 27 | source: input.source ?? "manual", |
| 28 | target: input.target, |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | export function attachEnvironmentDescriptor( |
| 33 | environment: KnownEnvironment, |
| 34 | descriptor: ExecutionEnvironmentDescriptor, |
| 35 | ): KnownEnvironment { |
| 36 | return { |
| 37 | ...environment, |
| 38 | environmentId: descriptor.environmentId, |
| 39 | label: descriptor.label, |
| 40 | }; |
| 41 | } |