@@ -87,13 +87,7 @@ export class Pica {
8787 . then ( ( ) => {
8888 let filteredConnections = this . connections . filter ( ( conn : any ) => conn . active ) ;
8989
90- if ( options ?. connectors ?. length ) {
91- if ( ! options . connectors . includes ( "*" ) ) {
92- filteredConnections = filteredConnections . filter ( conn =>
93- options . connectors ! . includes ( conn . key )
94- ) ;
95- }
96- } else {
90+ if ( ! options ?. connectors ?. length ) {
9791 filteredConnections = [ ] ;
9892 }
9993
@@ -147,7 +141,7 @@ ${this.system.trim()}
147141
148142 private async initialize ( ) {
149143 await Promise . all ( [
150- this . initializeConnections ( ) ,
144+ this . initializeConnections ( undefined , this . options ?. connectors ) ,
151145 this . initializeConnectionDefinitions ( ) ,
152146 ] ) ;
153147 }
@@ -157,8 +151,13 @@ ${this.system.trim()}
157151 return this . system ;
158152 }
159153
160- private async initializeConnections ( platform ?: string ) {
154+ private async initializeConnections ( platform ?: string , connectionKeys ?: string [ ] ) {
161155 try {
156+ if ( ! connectionKeys || connectionKeys . length === 0 ) {
157+ this . connections = [ ] ;
158+ return ;
159+ }
160+
162161 const headers = this . generateHeaders ( ) ;
163162
164163 let baseUrl = this . getConnectionUrl ;
@@ -169,6 +168,11 @@ ${this.system.trim()}
169168 hasQueryParam = true ;
170169 }
171170
171+ if ( ! connectionKeys . includes ( "*" ) ) {
172+ baseUrl += hasQueryParam ? `&key=${ connectionKeys . join ( ',' ) } ` : `?key=${ connectionKeys . join ( ',' ) } ` ;
173+ hasQueryParam = true ;
174+ }
175+
172176 if ( this . identity ) {
173177 baseUrl += hasQueryParam ? `&identity=${ encodeURIComponent ( this . identity ) } ` : `?identity=${ encodeURIComponent ( this . identity ) } ` ;
174178 hasQueryParam = true ;
@@ -301,7 +305,7 @@ ${this.system.trim()}
301305 }
302306
303307 public async getAvailableConnectors ( platform ?: string ) {
304- await this . initializeConnections ( platform ) ;
308+ await this . initializeConnections ( platform , this . options ?. connectors ) ;
305309 return this . connections ;
306310 }
307311
0 commit comments