@@ -20,8 +20,8 @@ public extension SearchClient {
2020 /// - returns: GetTaskResponse
2121 @discardableResult
2222 func waitForTask(
23- with taskID : Int64 ,
24- in indexName : String ,
23+ indexName : String ,
24+ taskID : Int64 ,
2525 maxRetries: Int = 50 ,
2626 timeout: ( Int ) -> TimeInterval = { count in
2727 min ( TimeInterval ( count) * 0.2 , 5 )
@@ -62,7 +62,7 @@ public extension SearchClient {
6262 /// - returns: GetTaskResponse
6363 @discardableResult
6464 func waitForAppTask(
65- with taskID: Int64 ,
65+ taskID: Int64 ,
6666 maxRetries: Int = 50 ,
6767 timeout: ( Int ) -> TimeInterval = { count in
6868 min ( TimeInterval ( count) * 0.2 , 5 )
@@ -105,7 +105,7 @@ public extension SearchClient {
105105 /// - returns: GetApiKeyResponse?
106106 @discardableResult
107107 func waitForApiKey(
108- with key: String ,
108+ key: String ,
109109 operation: ApiKeyOperation ,
110110 apiKey: ApiKey ? = nil ,
111111 maxRetries: Int = 50 ,
@@ -126,23 +126,24 @@ public extension SearchClient {
126126 try await self . getApiKey ( key: key, requestOptions: requestOptions)
127127 } ,
128128 validate: { response in
129- if apiKey. description != response. description {
129+ if apiKey. description != nil , apiKey . description != response. description {
130130 return false
131131 }
132132
133- if apiKey. queryParameters != response. queryParameters {
133+ if apiKey. queryParameters != nil , apiKey . queryParameters != response. queryParameters {
134134 return false
135135 }
136136
137- if apiKey. maxHitsPerQuery != response. maxHitsPerQuery {
137+ if apiKey. maxHitsPerQuery != nil , apiKey . maxHitsPerQuery != response. maxHitsPerQuery {
138138 return false
139139 }
140140
141- if apiKey. maxQueriesPerIPPerHour != response. maxQueriesPerIPPerHour {
141+ if apiKey. maxQueriesPerIPPerHour != nil ,
142+ apiKey. maxQueriesPerIPPerHour != response. maxQueriesPerIPPerHour {
142143 return false
143144 }
144145
145- if apiKey. validity != response. validity {
146+ if apiKey. validity != nil , apiKey . validity != response. validity {
146147 return false
147148 }
148149
@@ -152,16 +153,20 @@ public extension SearchClient {
152153 return false
153154 }
154155
155- let expectedIndexes = apiKey. indexes? . sorted { $0 > $1 }
156- let responseIndexes = response. indexes? . sorted { $0 > $1 }
157- if expectedIndexes != responseIndexes {
158- return false
156+ if let apiKeyIndexes = apiKey. indexes {
157+ let expectedIndexes = apiKeyIndexes. sorted { $0 > $1 }
158+ let responseIndexes = response. indexes? . sorted { $0 > $1 }
159+ if expectedIndexes != responseIndexes {
160+ return false
161+ }
159162 }
160163
161- let expectedReferers = apiKey. referers? . sorted { $0 > $1 }
162- let responseReferers = response. referers? . sorted { $0 > $1 }
163- if expectedReferers != responseReferers {
164- return false
164+ if let apiKeyReferers = apiKey. referers {
165+ let expectedReferers = apiKeyReferers. sorted { $0 > $1 }
166+ let responseReferers = response. referers? . sorted { $0 > $1 }
167+ if expectedReferers != responseReferers {
168+ return false
169+ }
165170 }
166171
167172 return true
@@ -185,12 +190,15 @@ public extension SearchClient {
185190
186191 return try await createIterable (
187192 execute: { _ in
188- let response = try await self . getApiKeyWithHTTPInfo ( key: key, requestOptions: requestOptions)
189- if response. statusCode == 404 {
190- return nil
191- }
193+ do {
194+ return try await self . getApiKey ( key: key, requestOptions: requestOptions)
195+ } catch let AlgoliaError . httpError( error) {
196+ if error. statusCode == 404 {
197+ return nil
198+ }
192199
193- return response. body
200+ throw error
201+ }
194202 } ,
195203 validate: { response in
196204 switch operation {
@@ -232,7 +240,7 @@ public extension SearchClient {
232240 /// - returns: BrowseResponse
233241 @discardableResult
234242 func browseObjects< T: Codable > (
235- in indexName: String ,
243+ indexName: String ,
236244 browseParams: BrowseParamsObject ,
237245 validate: ( BrowseResponse < T > ) -> Bool = { response in
238246 response. cursor == nil
@@ -267,7 +275,7 @@ public extension SearchClient {
267275 /// - returns: SearchRulesResponse
268276 @discardableResult
269277 func browseRules(
270- in indexName: String ,
278+ indexName: String ,
271279 searchRulesParams: SearchRulesParams ,
272280 validate: ( ( SearchRulesResponse ) -> Bool ) ? = nil ,
273281 aggregator: @escaping ( SearchRulesResponse ) -> Void ,
@@ -310,7 +318,7 @@ public extension SearchClient {
310318 /// - returns: SearchSynonymsResponse
311319 @discardableResult
312320 func browseSynonyms(
313- in indexName: String ,
321+ indexName: String ,
314322 searchSynonymsParams: SearchSynonymsParams ,
315323 validate: ( ( SearchSynonymsResponse ) -> Bool ) ? = nil ,
316324 aggregator: @escaping ( SearchSynonymsResponse ) -> Void ,
@@ -449,7 +457,7 @@ public extension SearchClient {
449457
450458 if waitForTasks {
451459 for batchResponse in responses {
452- try await self . waitForTask ( with : batchResponse . taskID , in : indexName )
460+ try await self . waitForTask ( indexName : indexName , taskID : batchResponse . taskID )
453461 }
454462 }
455463
@@ -557,7 +565,7 @@ public extension SearchClient {
557565 batchSize: batchSize,
558566 requestOptions: requestOptions
559567 )
560- try await self . waitForTask ( with : copyOperationResponse . taskID , in : tmpIndexName )
568+ try await self . waitForTask ( indexName : tmpIndexName , taskID : copyOperationResponse . taskID )
561569
562570 copyOperationResponse = try await operationIndex (
563571 indexName: indexName,
@@ -568,7 +576,7 @@ public extension SearchClient {
568576 ) ,
569577 requestOptions: requestOptions
570578 )
571- try await self . waitForTask ( with : copyOperationResponse . taskID , in : tmpIndexName )
579+ try await self . waitForTask ( indexName : tmpIndexName , taskID : copyOperationResponse . taskID )
572580
573581 let moveOperationResponse = try await self . operationIndex (
574582 indexName: tmpIndexName,
@@ -578,7 +586,7 @@ public extension SearchClient {
578586 ) ,
579587 requestOptions: requestOptions
580588 )
581- try await self . waitForTask ( with : moveOperationResponse . taskID , in : tmpIndexName )
589+ try await self . waitForTask ( indexName : tmpIndexName , taskID : moveOperationResponse . taskID )
582590
583591 return ReplaceAllObjectsResponse (
584592 copyOperationResponse: copyOperationResponse,
@@ -603,7 +611,7 @@ public extension SearchClient {
603611 /// Get the remaining validity of a secured API key
604612 /// - parameter securedApiKey: The secured API key
605613 /// - returns: TimeInterval?
606- func getSecuredApiKeyRemainingValidity( for securedApiKey: String ) -> TimeInterval ? {
614+ func getSecuredApiKeyRemainingValidity( securedApiKey: String ) -> TimeInterval ? {
607615 guard let rawDecodedAPIKey = String ( data: Data ( base64Encoded: securedApiKey) ?? Data ( ) , encoding: . utf8) ,
608616 !rawDecodedAPIKey. isEmpty else {
609617 return nil
0 commit comments