Skip to content

Commit

Permalink
chore: generated code for commit 9451edcd. [skip ci]
Browse files Browse the repository at this point in the history
algolia/api-clients-automation@9451edc

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Thomas Raffray <[email protected]>
  • Loading branch information
algolia-bot and Fluf22 committed Jul 9, 2024
1 parent 40da14b commit ffe1c1e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Sources/Core/Networking/Transporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ open class Transporter {
self.retryStrategy.notify(host: host, error: error)

guard self.retryStrategy.canRetry(inCaseOf: error) else {
throw AlgoliaError.requestError(error)
throw error
}

intermediateErrors.append(error)
Expand Down
68 changes: 38 additions & 30 deletions Sources/Search/Extra/SearchClientExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public extension SearchClient {
/// - returns: GetTaskResponse
@discardableResult
func waitForTask(
with taskID: Int64,
in indexName: String,
indexName: String,
taskID: Int64,
maxRetries: Int = 50,
timeout: (Int) -> TimeInterval = { count in
min(TimeInterval(count) * 0.2, 5)
Expand Down Expand Up @@ -62,7 +62,7 @@ public extension SearchClient {
/// - returns: GetTaskResponse
@discardableResult
func waitForAppTask(
with taskID: Int64,
taskID: Int64,
maxRetries: Int = 50,
timeout: (Int) -> TimeInterval = { count in
min(TimeInterval(count) * 0.2, 5)
Expand Down Expand Up @@ -105,7 +105,7 @@ public extension SearchClient {
/// - returns: GetApiKeyResponse?
@discardableResult
func waitForApiKey(
with key: String,
key: String,
operation: ApiKeyOperation,
apiKey: ApiKey? = nil,
maxRetries: Int = 50,
Expand All @@ -126,23 +126,24 @@ public extension SearchClient {
try await self.getApiKey(key: key, requestOptions: requestOptions)
},
validate: { response in
if apiKey.description != response.description {
if apiKey.description != nil, apiKey.description != response.description {
return false
}

if apiKey.queryParameters != response.queryParameters {
if apiKey.queryParameters != nil, apiKey.queryParameters != response.queryParameters {
return false
}

if apiKey.maxHitsPerQuery != response.maxHitsPerQuery {
if apiKey.maxHitsPerQuery != nil, apiKey.maxHitsPerQuery != response.maxHitsPerQuery {
return false
}

if apiKey.maxQueriesPerIPPerHour != response.maxQueriesPerIPPerHour {
if apiKey.maxQueriesPerIPPerHour != nil,
apiKey.maxQueriesPerIPPerHour != response.maxQueriesPerIPPerHour {
return false
}

if apiKey.validity != response.validity {
if apiKey.validity != nil, apiKey.validity != response.validity {
return false
}

Expand All @@ -152,16 +153,20 @@ public extension SearchClient {
return false
}

let expectedIndexes = apiKey.indexes?.sorted { $0 > $1 }
let responseIndexes = response.indexes?.sorted { $0 > $1 }
if expectedIndexes != responseIndexes {
return false
if let apiKeyIndexes = apiKey.indexes {
let expectedIndexes = apiKeyIndexes.sorted { $0 > $1 }
let responseIndexes = response.indexes?.sorted { $0 > $1 }
if expectedIndexes != responseIndexes {
return false
}
}

let expectedReferers = apiKey.referers?.sorted { $0 > $1 }
let responseReferers = response.referers?.sorted { $0 > $1 }
if expectedReferers != responseReferers {
return false
if let apiKeyReferers = apiKey.referers {
let expectedReferers = apiKeyReferers.sorted { $0 > $1 }
let responseReferers = response.referers?.sorted { $0 > $1 }
if expectedReferers != responseReferers {
return false
}
}

return true
Expand All @@ -185,12 +190,15 @@ public extension SearchClient {

return try await createIterable(
execute: { _ in
let response = try await self.getApiKeyWithHTTPInfo(key: key, requestOptions: requestOptions)
if response.statusCode == 404 {
return nil
}
do {
return try await self.getApiKey(key: key, requestOptions: requestOptions)
} catch let AlgoliaError.httpError(error) {
if error.statusCode == 404 {
return nil
}

return response.body
throw error
}
},
validate: { response in
switch operation {
Expand Down Expand Up @@ -232,7 +240,7 @@ public extension SearchClient {
/// - returns: BrowseResponse
@discardableResult
func browseObjects<T: Codable>(
in indexName: String,
indexName: String,
browseParams: BrowseParamsObject,
validate: (BrowseResponse<T>) -> Bool = { response in
response.cursor == nil
Expand Down Expand Up @@ -267,7 +275,7 @@ public extension SearchClient {
/// - returns: SearchRulesResponse
@discardableResult
func browseRules(
in indexName: String,
indexName: String,
searchRulesParams: SearchRulesParams,
validate: ((SearchRulesResponse) -> Bool)? = nil,
aggregator: @escaping (SearchRulesResponse) -> Void,
Expand Down Expand Up @@ -310,7 +318,7 @@ public extension SearchClient {
/// - returns: SearchSynonymsResponse
@discardableResult
func browseSynonyms(
in indexName: String,
indexName: String,
searchSynonymsParams: SearchSynonymsParams,
validate: ((SearchSynonymsResponse) -> Bool)? = nil,
aggregator: @escaping (SearchSynonymsResponse) -> Void,
Expand Down Expand Up @@ -449,7 +457,7 @@ public extension SearchClient {

if waitForTasks {
for batchResponse in responses {
try await self.waitForTask(with: batchResponse.taskID, in: indexName)
try await self.waitForTask(indexName: indexName, taskID: batchResponse.taskID)
}
}

Expand Down Expand Up @@ -557,7 +565,7 @@ public extension SearchClient {
batchSize: batchSize,
requestOptions: requestOptions
)
try await self.waitForTask(with: copyOperationResponse.taskID, in: tmpIndexName)
try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID)

copyOperationResponse = try await operationIndex(
indexName: indexName,
Expand All @@ -568,7 +576,7 @@ public extension SearchClient {
),
requestOptions: requestOptions
)
try await self.waitForTask(with: copyOperationResponse.taskID, in: tmpIndexName)
try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID)

let moveOperationResponse = try await self.operationIndex(
indexName: tmpIndexName,
Expand All @@ -578,7 +586,7 @@ public extension SearchClient {
),
requestOptions: requestOptions
)
try await self.waitForTask(with: moveOperationResponse.taskID, in: tmpIndexName)
try await self.waitForTask(indexName: tmpIndexName, taskID: moveOperationResponse.taskID)

return ReplaceAllObjectsResponse(
copyOperationResponse: copyOperationResponse,
Expand All @@ -603,7 +611,7 @@ public extension SearchClient {
/// Get the remaining validity of a secured API key
/// - parameter securedApiKey: The secured API key
/// - returns: TimeInterval?
func getSecuredApiKeyRemainingValidity(for securedApiKey: String) -> TimeInterval? {
func getSecuredApiKeyRemainingValidity(securedApiKey: String) -> TimeInterval? {
guard let rawDecodedAPIKey = String(data: Data(base64Encoded: securedApiKey) ?? Data(), encoding: .utf8),
!rawDecodedAPIKey.isEmpty else {
return nil
Expand Down

0 comments on commit ffe1c1e

Please sign in to comment.