Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

knownEnvironment.ts

53 lines1.5 KB

1import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
2​
3export interface KnownEnvironmentConnectionTarget {
4 readonly httpBaseUrl: string;
5 readonly wsBaseUrl: string;
6}
7​
8export type KnownEnvironmentSource = "configured" | "desktop-managed" | "manual" | "window-origin";
9​
10export interface KnownEnvironment {
11 readonly id: string;
12 readonly label: string;
13 readonly source: KnownEnvironmentSource;
14 readonly environmentId?: EnvironmentId;
15 readonly target: KnownEnvironmentConnectionTarget;
17​
18export 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 };
31​
32export function getKnownEnvironmentWsBaseUrl(
33 environment: KnownEnvironment | null | undefined,
34): string | null {
35 return environment?.target.wsBaseUrl ?? null;
37​
38export function getKnownEnvironmentHttpBaseUrl(
39 environment: KnownEnvironment | null | undefined,
40): string | null {
41 return environment?.target.httpBaseUrl ?? null;
43​
44export function attachEnvironmentDescriptor(
45 environment: KnownEnvironment,
46 descriptor: ExecutionEnvironmentDescriptor,
47): KnownEnvironment {
48 return {
49 ...environment,
50 environmentId: descriptor.environmentId,
51 label: descriptor.label,
52 };