@@ -20,8 +20,8 @@ public extension SearchClient {
20
20
/// - returns: GetTaskResponse
21
21
@discardableResult
22
22
func waitForTask(
23
- with taskID : Int64 ,
24
- in indexName : String ,
23
+ indexName : String ,
24
+ taskID : Int64 ,
25
25
maxRetries: Int = 50 ,
26
26
timeout: ( Int ) -> TimeInterval = { count in
27
27
min ( TimeInterval ( count) * 0.2 , 5 )
@@ -62,7 +62,7 @@ public extension SearchClient {
62
62
/// - returns: GetTaskResponse
63
63
@discardableResult
64
64
func waitForAppTask(
65
- with taskID: Int64 ,
65
+ taskID: Int64 ,
66
66
maxRetries: Int = 50 ,
67
67
timeout: ( Int ) -> TimeInterval = { count in
68
68
min ( TimeInterval ( count) * 0.2 , 5 )
@@ -105,7 +105,7 @@ public extension SearchClient {
105
105
/// - returns: GetApiKeyResponse?
106
106
@discardableResult
107
107
func waitForApiKey(
108
- with key: String ,
108
+ key: String ,
109
109
operation: ApiKeyOperation ,
110
110
apiKey: ApiKey ? = nil ,
111
111
maxRetries: Int = 50 ,
@@ -126,23 +126,23 @@ public extension SearchClient {
126
126
try await self . getApiKey ( key: key, requestOptions: requestOptions)
127
127
} ,
128
128
validate: { response in
129
- if apiKey. description != response. description {
129
+ if apiKey. description != nil && apiKey . description != response. description {
130
130
return false
131
131
}
132
132
133
- if apiKey. queryParameters != response. queryParameters {
133
+ if apiKey. queryParameters != nil && apiKey . queryParameters != response. queryParameters {
134
134
return false
135
135
}
136
136
137
- if apiKey. maxHitsPerQuery != response. maxHitsPerQuery {
137
+ if apiKey. maxHitsPerQuery != nil && apiKey . maxHitsPerQuery != response. maxHitsPerQuery {
138
138
return false
139
139
}
140
140
141
- if apiKey. maxQueriesPerIPPerHour != response. maxQueriesPerIPPerHour {
141
+ if apiKey. maxQueriesPerIPPerHour != nil && apiKey . maxQueriesPerIPPerHour != response. maxQueriesPerIPPerHour {
142
142
return false
143
143
}
144
144
145
- if apiKey. validity != response. validity {
145
+ if apiKey. validity != nil && apiKey . validity != response. validity {
146
146
return false
147
147
}
148
148
@@ -152,16 +152,20 @@ public extension SearchClient {
152
152
return false
153
153
}
154
154
155
- let expectedIndexes = apiKey. indexes? . sorted { $0 > $1 }
156
- let responseIndexes = response. indexes? . sorted { $0 > $1 }
157
- if expectedIndexes != responseIndexes {
158
- return false
155
+ if let apiKeyIndexes = apiKey. indexes {
156
+ let expectedIndexes = apiKeyIndexes. sorted { $0 > $1 }
157
+ let responseIndexes = response. indexes? . sorted { $0 > $1 }
158
+ if expectedIndexes != responseIndexes {
159
+ return false
160
+ }
159
161
}
160
162
161
- let expectedReferers = apiKey. referers? . sorted { $0 > $1 }
162
- let responseReferers = response. referers? . sorted { $0 > $1 }
163
- if expectedReferers != responseReferers {
164
- return false
163
+ if let apiKeyReferers = apiKey. referers {
164
+ let expectedReferers = apiKeyReferers. sorted { $0 > $1 }
165
+ let responseReferers = response. referers? . sorted { $0 > $1 }
166
+ if expectedReferers != responseReferers {
167
+ return false
168
+ }
165
169
}
166
170
167
171
return true
@@ -185,12 +189,15 @@ public extension SearchClient {
185
189
186
190
return try await createIterable (
187
191
execute: { _ in
188
- let response = try await self . getApiKeyWithHTTPInfo ( key: key, requestOptions: requestOptions)
189
- if response. statusCode == 404 {
190
- return nil
192
+ do {
193
+ return try await self . getApiKey ( key: key, requestOptions: requestOptions)
194
+ } catch AlgoliaError . httpError( let error) {
195
+ if error. statusCode == 404 {
196
+ return nil
197
+ }
198
+
199
+ throw error
191
200
}
192
-
193
- return response. body
194
201
} ,
195
202
validate: { response in
196
203
switch operation {
@@ -232,7 +239,7 @@ public extension SearchClient {
232
239
/// - returns: BrowseResponse
233
240
@discardableResult
234
241
func browseObjects< T: Codable > (
235
- in indexName: String ,
242
+ indexName: String ,
236
243
browseParams: BrowseParamsObject ,
237
244
validate: ( BrowseResponse < T > ) -> Bool = { response in
238
245
response. cursor == nil
@@ -267,7 +274,7 @@ public extension SearchClient {
267
274
/// - returns: SearchRulesResponse
268
275
@discardableResult
269
276
func browseRules(
270
- in indexName: String ,
277
+ indexName: String ,
271
278
searchRulesParams: SearchRulesParams ,
272
279
validate: ( ( SearchRulesResponse ) -> Bool ) ? = nil ,
273
280
aggregator: @escaping ( SearchRulesResponse ) -> Void ,
@@ -310,7 +317,7 @@ public extension SearchClient {
310
317
/// - returns: SearchSynonymsResponse
311
318
@discardableResult
312
319
func browseSynonyms(
313
- in indexName: String ,
320
+ indexName: String ,
314
321
searchSynonymsParams: SearchSynonymsParams ,
315
322
validate: ( ( SearchSynonymsResponse ) -> Bool ) ? = nil ,
316
323
aggregator: @escaping ( SearchSynonymsResponse ) -> Void ,
@@ -449,7 +456,7 @@ public extension SearchClient {
449
456
450
457
if waitForTasks {
451
458
for batchResponse in responses {
452
- try await self . waitForTask ( with : batchResponse . taskID , in : indexName )
459
+ try await self . waitForTask ( indexName : indexName , taskID : batchResponse . taskID )
453
460
}
454
461
}
455
462
@@ -557,7 +564,7 @@ public extension SearchClient {
557
564
batchSize: batchSize,
558
565
requestOptions: requestOptions
559
566
)
560
- try await self . waitForTask ( with : copyOperationResponse . taskID , in : tmpIndexName )
567
+ try await self . waitForTask ( indexName : tmpIndexName , taskID : copyOperationResponse . taskID )
561
568
562
569
copyOperationResponse = try await operationIndex (
563
570
indexName: indexName,
@@ -568,7 +575,7 @@ public extension SearchClient {
568
575
) ,
569
576
requestOptions: requestOptions
570
577
)
571
- try await self . waitForTask ( with : copyOperationResponse . taskID , in : tmpIndexName )
578
+ try await self . waitForTask ( indexName : tmpIndexName , taskID : copyOperationResponse . taskID )
572
579
573
580
let moveOperationResponse = try await self . operationIndex (
574
581
indexName: tmpIndexName,
@@ -578,7 +585,7 @@ public extension SearchClient {
578
585
) ,
579
586
requestOptions: requestOptions
580
587
)
581
- try await self . waitForTask ( with : moveOperationResponse . taskID , in : tmpIndexName )
588
+ try await self . waitForTask ( indexName : tmpIndexName , taskID : moveOperationResponse . taskID )
582
589
583
590
return ReplaceAllObjectsResponse (
584
591
copyOperationResponse: copyOperationResponse,
@@ -603,7 +610,7 @@ public extension SearchClient {
603
610
/// Get the remaining validity of a secured API key
604
611
/// - parameter securedApiKey: The secured API key
605
612
/// - returns: TimeInterval?
606
- func getSecuredApiKeyRemainingValidity( for securedApiKey: String ) -> TimeInterval ? {
613
+ func getSecuredApiKeyRemainingValidity( securedApiKey: String ) -> TimeInterval ? {
607
614
guard let rawDecodedAPIKey = String ( data: Data ( base64Encoded: securedApiKey) ?? Data ( ) , encoding: . utf8) ,
608
615
!rawDecodedAPIKey. isEmpty else {
609
616
return nil
0 commit comments