@@ -33,6 +33,33 @@ function isLocalHost(url: string) {
3333 if ( host === "localhost" || host === "127.0.0.1" ) return "local"
3434}
3535
36+ export function resolveServerList ( input : {
37+ props ?: Array < ServerConnection . Any >
38+ stored : StoredServer [ ]
39+ } ) : Array < ServerConnection . Any > {
40+ const servers = [
41+ ...input . stored . map ( ( value ) =>
42+ typeof value === "string"
43+ ? {
44+ type : "http" as const ,
45+ http : { url : value } ,
46+ }
47+ : value ,
48+ ) ,
49+ ...( input . props ?? [ ] ) ,
50+ ]
51+
52+ const deduped = new Map < ServerConnection . Key , ServerConnection . Any > ( )
53+ for ( const value of servers ) {
54+ const conn : ServerConnection . Any = "type" in value ? value : { type : "http" , http : value }
55+ const key = ServerConnection . key ( conn )
56+ if ( deduped . has ( key ) && conn . type === "http" && ! conn . authToken ) continue
57+ deduped . set ( key , conn )
58+ }
59+
60+ return [ ...deduped . values ( ) ]
61+ }
62+
3663export namespace ServerConnection {
3764 type Base = { displayName ?: string }
3865
@@ -46,6 +73,7 @@ export namespace ServerConnection {
4673 export type Http = {
4774 type : "http"
4875 http : HttpBase
76+ authToken ?: boolean
4977 } & Base
5078
5179 export type Sidecar = {
@@ -113,26 +141,7 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
113141 const url = ( x : StoredServer ) => ( typeof x === "string" ? x : "type" in x ? x . http . url : x . url )
114142
115143 const allServers = createMemo ( ( ) : Array < ServerConnection . Any > => {
116- const servers = [
117- ...( props . servers ?? [ ] ) ,
118- ...store . list . map ( ( value ) =>
119- typeof value === "string"
120- ? {
121- type : "http" as const ,
122- http : { url : value } ,
123- }
124- : value ,
125- ) ,
126- ]
127-
128- const deduped = new Map (
129- servers . map ( ( value ) => {
130- const conn : ServerConnection . Any = "type" in value ? value : { type : "http" , http : value }
131- return [ ServerConnection . key ( conn ) , conn ]
132- } ) ,
133- )
134-
135- return [ ...deduped . values ( ) ]
144+ return resolveServerList ( { stored : store . list , props : props . servers } )
136145 } )
137146
138147 const [ state , setState ] = createStore ( {
@@ -174,7 +183,7 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
174183 function add ( input : ServerConnection . Http ) {
175184 const url_ = normalizeServerUrl ( input . http . url )
176185 if ( ! url_ ) return
177- const conn = { ...input , http : { ...input . http , url : url_ } }
186+ const conn : ServerConnection . Http = { ...input , authToken : undefined , http : { ...input . http , url : url_ } }
178187 return batch ( ( ) => {
179188 const existing = store . list . findIndex ( ( x ) => url ( x ) === url_ )
180189 if ( existing !== - 1 ) {
0 commit comments