(input: {
props?: Array<ServerConnection.Any>
stored: StoredServer[]
})
| 112 | } |
| 113 | |
| 114 | export function resolveServerList(input: { |
| 115 | props?: Array<ServerConnection.Any> |
| 116 | stored: StoredServer[] |
| 117 | }): Array<ServerConnection.Any> { |
| 118 | const deduped = new Map<ServerConnection.Key, ServerConnection.Any>( |
| 119 | input.props?.map((v) => [ServerConnection.key(v), v]) ?? [], |
| 120 | ) |
| 121 | |
| 122 | for (const value of input.stored) { |
| 123 | const conn: ServerConnection.Http = |
| 124 | typeof value === "string" |
| 125 | ? { |
| 126 | type: "http" as const, |
| 127 | http: { url: value }, |
| 128 | } |
| 129 | : "http" in value |
| 130 | ? value |
| 131 | : { type: "http", http: value } |
| 132 | const key = ServerConnection.key(conn) |
| 133 | |
| 134 | const existing = deduped.get(key) |
| 135 | if (existing) |
| 136 | deduped.set(key, { |
| 137 | ...existing, |
| 138 | ...conn, |
| 139 | http: { ...existing.http, ...conn.http }, |
| 140 | }) |
| 141 | else deduped.set(key, conn) |
| 142 | } |
| 143 | |
| 144 | return [...deduped.values()] |
| 145 | } |
| 146 | |
| 147 | export namespace ServerConnection { |
| 148 | type Base = { displayName?: string; label?: string } |
no test coverage detected