diff --git a/clients/algoliasearch-client-swift/.swiftformat b/clients/algoliasearch-client-swift/.swiftformat index 394a6ba965..4a5dede1bb 100644 --- a/clients/algoliasearch-client-swift/.swiftformat +++ b/clients/algoliasearch-client-swift/.swiftformat @@ -83,12 +83,10 @@ --enable leadingDelimiters --enable linebreakAtEndOfFile --enable linebreaks ---enable markTypes --enable modifierOrder --enable noExplicitOwnership --enable numberFormatting --enable opaqueGenericParameters ---enable organizeDeclarations --enable preferKeyPath --enable redundantClosure --enable redundantExtensionACL @@ -144,6 +142,8 @@ --disable applicationMain --disable blankLinesBetweenImports --disable fileHeader +--disable markTypes +--disable organizeDeclarations --disable preferForLoop --disable redundantBackticks --disable redundantBreak diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/CallType.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/CallType.swift index 90274a479a..ec82248076 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/CallType.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/CallType.swift @@ -7,8 +7,6 @@ import Foundation -// MARK: - CallType - /// Indicate whether the HTTP call performed is of type [read] (GET) or [write] (POST, PUT ..). /// Used to determine which timeout duration to use. public enum CallType { @@ -16,8 +14,6 @@ public enum CallType { case write } -// MARK: CustomStringConvertible - extension CallType: CustomStringConvertible { public var description: String { switch self { diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/DecodingErrorPrettyPrinter.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/DecodingErrorPrettyPrinter.swift index 1216b96fb0..e9e4aade10 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/DecodingErrorPrettyPrinter.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/DecodingErrorPrettyPrinter.swift @@ -7,17 +7,11 @@ import Foundation -// MARK: - DecodingErrorPrettyPrinter - struct DecodingErrorPrettyPrinter: CustomStringConvertible, CustomDebugStringConvertible { - // MARK: Lifecycle - init(decodingError: DecodingError) { self.decodingError = decodingError } - // MARK: Internal - let decodingError: DecodingError var description: String { @@ -28,8 +22,6 @@ struct DecodingErrorPrettyPrinter: CustomStringConvertible, CustomDebugStringCon self.description } - // MARK: Private - private let prefix = "Decoding error" private func codingKeyDescription(_ key: CodingKey) -> String { diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/ErrorMessage.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/ErrorMessage.swift index 0c7b87ea26..c2bfb1998b 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/ErrorMessage.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/ErrorMessage.swift @@ -7,29 +7,17 @@ import Foundation -// MARK: - GenericError - public struct GenericError: Error, CustomStringConvertible { - // MARK: Lifecycle - public init(description: String) { self.description = description } - // MARK: Public - public var description: String } -// MARK: - ErrorMessage - public struct ErrorMessage: Codable, CustomStringConvertible { - // MARK: Public - public let description: String - // MARK: Internal - enum CodingKeys: String, CodingKey { case description = "message" } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/Logging.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/Logging.swift index a9757be2a9..fef3a4718e 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/Logging.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/Logging.swift @@ -10,15 +10,9 @@ import Logging typealias SwiftLog = Logging.Logger -// MARK: - Logger - public struct Logger { - // MARK: Lifecycle - private init() {} - // MARK: Public - public static var loggingService: Loggable = { var swiftLog = SwiftLog(label: "com.algolia.searchClientSwift") print( @@ -38,8 +32,6 @@ public struct Logger { } } - // MARK: Internal - static func trace(_ message: String) { self.loggingService.log(level: .trace, message: message) } @@ -69,8 +61,6 @@ public struct Logger { } } -// MARK: - LogLevel - public enum LogLevel { case trace case debug @@ -119,16 +109,12 @@ extension LogLevel { } } -// MARK: - Loggable - public protocol Loggable { var minSeverityLevel: LogLevel { get set } func log(level: LogLevel, message: String) } -// MARK: - SwiftLog + Loggable - extension SwiftLog: Loggable { public var minSeverityLevel: LogLevel { get { diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/Region.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/Region.swift index 4778b17f86..9c2a2e20f1 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/Region.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/Region.swift @@ -8,14 +8,10 @@ import Foundation public struct Region: StringOption, ProvidingCustomOption { - // MARK: Lifecycle - public init(rawValue: String) { self.rawValue = rawValue } - // MARK: Public - public static var us: Self { .init(rawValue: #function) } /// European (Germany) region for Insights and Analytics APIs diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/RequestOptions.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/RequestOptions.swift index a9d17c4692..5c399c880f 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/RequestOptions.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/RequestOptions.swift @@ -8,8 +8,6 @@ import Foundation public class RequestOptions { - // MARK: Lifecycle - public init( headers: [String: String]? = nil, queryParameters: [String: Any?]? = nil, @@ -24,8 +22,6 @@ public class RequestOptions { self.body = body } - // MARK: Public - public static func +(lhs: RequestOptions, rhs: RequestOptions?) -> RequestOptions { guard let rhs else { return lhs @@ -86,8 +82,6 @@ public class RequestOptions { return self } - // MARK: Internal - private(set) var headers: [String: String]? private(set) var queryParameters: [String: Any?]? private(set) var readTimeout: TimeInterval? diff --git a/clients/algoliasearch-client-swift/Sources/Core/Common/StringOption.swift b/clients/algoliasearch-client-swift/Sources/Core/Common/StringOption.swift index 46dfeabae5..e5369b31a7 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Common/StringOption.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Common/StringOption.swift @@ -7,8 +7,6 @@ import Foundation -// MARK: - StringOption - public protocol StringOption: Codable, Equatable, RawRepresentable where RawValue == String {} public extension StringOption { @@ -17,8 +15,6 @@ public extension StringOption { } } -// MARK: - ProvidingCustomOption - public protocol ProvidingCustomOption { static func custom(_ value: String) -> Self } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/CodableHelper.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/CodableHelper.swift index 8d46d3900e..4b30f2cbce 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/CodableHelper.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/CodableHelper.swift @@ -7,8 +7,6 @@ import Foundation open class CodableHelper { - // MARK: Open - open class func decode(_ type: T.Type, from data: Data) -> Swift.Result where T: Decodable { Swift.Result { try self.jsonDecoder.decode(type, from: data) } @@ -18,8 +16,6 @@ open class CodableHelper { Swift.Result { try self.jsonEncoder.encode(value) } } - // MARK: Public - public static var dateFormatter: DateFormatter { get { customDateFormatter ?? defaultDateFormatter } set { customDateFormatter = newValue } @@ -35,8 +31,6 @@ open class CodableHelper { set { customJSONEncoder = newValue } } - // MARK: Private - private static var customDateFormatter: DateFormatter? private static var defaultDateFormatter: DateFormatter = OpenISO8601DateFormatter() diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Extensions.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Extensions.swift index f524f04739..69e38591dc 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Extensions.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Extensions.swift @@ -12,62 +12,42 @@ import Foundation import AnyCodable #endif -// MARK: - Bool + JSONEncodable - extension Bool: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - Float + JSONEncodable - extension Float: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - Int + JSONEncodable - extension Int: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - Int32 + JSONEncodable - extension Int32: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - Int64 + JSONEncodable - extension Int64: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - Double + JSONEncodable - extension Double: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - Decimal + JSONEncodable - extension Decimal: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - String + JSONEncodable - extension String: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - URL + JSONEncodable - extension URL: JSONEncodable { public func encodeToJSON() -> Any { self } } -// MARK: - UUID + JSONEncodable - extension UUID: JSONEncodable { public func encodeToJSON() -> Any { self } } @@ -84,24 +64,18 @@ private func encodeIfPossible(_ object: some Any) -> Any { } } -// MARK: - Array + JSONEncodable - extension Array: JSONEncodable { public func encodeToJSON() -> Any { map(encodeIfPossible) } } -// MARK: - Set + JSONEncodable - extension Set: JSONEncodable { public func encodeToJSON() -> Any { Array(self).encodeToJSON() } } -// MARK: - Dictionary + JSONEncodable - extension Dictionary: JSONEncodable where Key == String { public func encodeToJSON() -> Any { var dictionary = [String: Any]() @@ -112,8 +86,6 @@ extension Dictionary: JSONEncodable where Key == String { } } -// MARK: - Data + JSONEncodable - extension Data: JSONEncodable { public func encodeToJSON() -> Any { guard let selfString = String(data: self, encoding: .utf8) else { @@ -130,8 +102,6 @@ extension Data: JSONEncodable { } } -// MARK: - Date + JSONEncodable - extension Date: JSONEncodable { public func encodeToJSON() -> Any { CodableHelper.dateFormatter.string(from: self) @@ -153,8 +123,6 @@ public extension JSONEncodable where Self: Encodable { } } -// MARK: - String + CodingKey - extension String: CodingKey { public var stringValue: String { self @@ -284,8 +252,6 @@ extension HTTPURLResponse { } } -// MARK: - URLRequest.FormatError - public extension URLRequest { enum FormatError: LocalizedError { case missingURL @@ -294,8 +260,6 @@ public extension URLRequest { case invalidPath(String) case invalidQueryItems - // MARK: Public - public var errorDescription: String? { let contactUs = "Please contact support@algolia.com if this problem occurs." switch self { diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Models.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Models.swift index be1e7ca16f..602acaab4f 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Models.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Models.swift @@ -9,14 +9,10 @@ import Foundation import FoundationNetworking #endif -// MARK: - JSONEncodable - public protocol JSONEncodable { func encodeToJSON() -> Any } -// MARK: - CaseIterableDefaultsLast - /// An enum where the last case value can be used as a default catch-all. protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable where RawValue: Decodable, AllCases: BidirectionalCollection {} @@ -39,8 +35,6 @@ extension CaseIterableDefaultsLast { } } -// MARK: - NullEncodable - /// A flexible type that can be encoded (`.encodeNull` or `.encodeValue`) /// or not encoded (`.encodeNothing`). Intended for request payloads. public enum NullEncodable: Hashable { @@ -49,8 +43,6 @@ public enum NullEncodable: Hashable { case encodeValue(Wrapped) } -// MARK: Codable - extension NullEncodable: Codable where Wrapped: Codable { public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() @@ -73,14 +65,10 @@ extension NullEncodable: Codable where Wrapped: Codable { } } -// MARK: - ErrorResponse - public enum ErrorResponse: Error { case error(Int, Data?, URLResponse?, Error) } -// MARK: - DownloadException - public enum DownloadException: Error { case responseDataMissing case responseFailed @@ -89,8 +77,6 @@ public enum DownloadException: Error { case requestMissingURL } -// MARK: - DecodableRequestBuilderError - public enum DecodableRequestBuilderError: Error { case emptyDataResponse case nilHTTPResponse @@ -99,11 +85,7 @@ public enum DecodableRequestBuilderError: Error { case generalError(Error) } -// MARK: - Response - open class Response { - // MARK: Lifecycle - public init(response: HTTPURLResponse, body: T?, bodyData: Data?) { let rawHeader = response.allHeaderFields var responseHeaders = [String: String]() @@ -120,8 +102,6 @@ open class Response { self.httpResponse = response } - // MARK: Public - public let statusCode: Int public let headers: [String: String] public let body: T? @@ -129,8 +109,6 @@ open class Response { public let httpResponse: HTTPURLResponse } -// MARK: - AbstractEncodable - public protocol AbstractEncodable: JSONEncodable { func GetActualInstance() -> Encodable } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/OpenISO8601DateFormatter.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/OpenISO8601DateFormatter.swift index 8da3cace6c..36a77fc5d1 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/OpenISO8601DateFormatter.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/OpenISO8601DateFormatter.swift @@ -8,8 +8,6 @@ import Foundation /// https://stackoverflow.com/a/50281094/976628 public class OpenISO8601DateFormatter: DateFormatter { - // MARK: Lifecycle - override init() { super.init() self.setup() @@ -20,8 +18,6 @@ public class OpenISO8601DateFormatter: DateFormatter { self.setup() } - // MARK: Public - override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result @@ -32,8 +28,6 @@ public class OpenISO8601DateFormatter: DateFormatter { return OpenISO8601DateFormatter.withoutTime.date(from: string) } - // MARK: Internal - static let withoutSeconds: DateFormatter = { let formatter = DateFormatter() formatter.calendar = Calendar(identifier: .iso8601) @@ -52,8 +46,6 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() - // MARK: Private - private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/SynchronizedDictionary.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/SynchronizedDictionary.swift index da4200ed98..f32a892001 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/SynchronizedDictionary.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/SynchronizedDictionary.swift @@ -6,8 +6,6 @@ import Foundation struct SynchronizedDictionary { - // MARK: Internal - subscript(key: K) -> V? { get { var value: V? @@ -25,8 +23,6 @@ struct SynchronizedDictionary { } } - // MARK: Private - private var dictionary = [K: V]() private let queue = DispatchQueue( label: "SynchronizedDictionary", diff --git a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Validation.swift b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Validation.swift index 015e45299e..d2c96d41e7 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Helpers/Validation.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Helpers/Validation.swift @@ -5,29 +5,19 @@ import Foundation -// MARK: - StringRule - public struct StringRule { - // MARK: Lifecycle - public init(minLength: Int? = nil, maxLength: Int? = nil, pattern: String? = nil) { self.minLength = minLength self.maxLength = maxLength self.pattern = pattern } - // MARK: Public - public var minLength: Int? public var maxLength: Int? public var pattern: String? } -// MARK: - NumericRule - public struct NumericRule { - // MARK: Lifecycle - public init( minimum: T? = nil, exclusiveMinimum: Bool = false, maximum: T? = nil, exclusiveMaximum: Bool = false, multipleOf: T? = nil @@ -39,8 +29,6 @@ public struct NumericRule { self.multipleOf = multipleOf } - // MARK: Public - public var minimum: T? public var exclusiveMinimum = false public var maximum: T? @@ -48,30 +36,22 @@ public struct NumericRule { public var multipleOf: T? } -// MARK: - StringValidationErrorKind - public enum StringValidationErrorKind: Error { case minLength case maxLength case pattern } -// MARK: - NumericValidationErrorKind - public enum NumericValidationErrorKind: Error { case minimum case maximum case multipleOf } -// MARK: - ValidationError - public struct ValidationError: Error { public fileprivate(set) var kinds: Set } -// MARK: - Validator - public enum Validator { /// Validate a string against a rule. /// - Parameter string: The String you wish to validate. diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift index 5e11e2b432..dce1569b83 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/AlgoliaError.swift @@ -17,8 +17,6 @@ public enum AlgoliaError: Error, LocalizedError { case invalidCredentials(String) case invalidArgument(String, String) - // MARK: Public - public var errorDescription: String? { switch self { case let .requestError(error): diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPError.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPError.swift index e303e123ae..d7643c2889 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPError.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPError.swift @@ -14,7 +14,12 @@ import Foundation // MARK: - HTTPError public struct HTTPError: Error, CustomStringConvertible { - // MARK: Lifecycle + public let statusCode: HTTPStatusСode + public let message: ErrorMessage? + + public var description: String { + "Status code: \(self.statusCode) Message: \(self.message?.description ?? "No message")" + } public init?(response: HTTPURLResponse?, data: Data?) { guard let response, !response.statusCode.belongs(to: .success) else { @@ -29,13 +34,4 @@ public struct HTTPError: Error, CustomStringConvertible { self.statusCode = statusCode self.message = message } - - // MARK: Public - - public let statusCode: HTTPStatusСode - public let message: ErrorMessage? - - public var description: String { - "Status code: \(self.statusCode) Message: \(self.message?.description ?? "No message")" - } } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPStatusCode.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPStatusCode.swift index 90b621b5f0..643bd64364 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPStatusCode.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/HTTP/HTTPStatusCode.swift @@ -33,8 +33,6 @@ enum HTTPStatusCategory { case clientError case serverError - // MARK: Internal - var range: Range { switch self { case .informational: diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/EchoRequestBuilder.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/EchoRequestBuilder.swift index ccd5151402..f918e5a727 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/EchoRequestBuilder.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/EchoRequestBuilder.swift @@ -29,7 +29,7 @@ public struct EchoResponse: Codable { // MARK: - EchoRequestBuilder final class EchoRequestBuilder: RequestBuilder { - // MARK: Lifecycle + let statusCode: HTTPStatusСode public init() { self.statusCode = 200 @@ -39,10 +39,6 @@ final class EchoRequestBuilder: RequestBuilder { self.statusCode = statusCode } - // MARK: Internal - - let statusCode: HTTPStatusСode - final func execute(urlRequest: URLRequest, timeout: TimeInterval) async throws -> Response { let headers = urlRequest.allHTTPHeaderFields ?? [:] @@ -92,8 +88,6 @@ final class EchoRequestBuilder: RequestBuilder { return Response(response: mockHTTPURLResponse, body: nil, bodyData: interceptedBody) } - // MARK: Fileprivate - fileprivate func processQueryItems(from queryItems: [URLQueryItem]?) -> [String: String?]? { guard let queryItems else { diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/URLSessionRequestBuilder.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/URLSessionRequestBuilder.swift index 031acb727b..bbd455e557 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/URLSessionRequestBuilder.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/URLSessionRequestBuilder.swift @@ -14,7 +14,7 @@ import Foundation // MARK: - URLSessionRequestBuilder open class URLSessionRequestBuilder: RequestBuilder { - // MARK: Lifecycle + private(set) var sessionManager: URLSession public required init() { let sessionConfiguration: URLSessionConfiguration = .default @@ -28,8 +28,6 @@ open class URLSessionRequestBuilder: RequestBuilder { self.sessionManager = URLSession(configuration: sessionConfiguration) } - // MARK: Open - @discardableResult open func execute(urlRequest: URLRequest, timeout: TimeInterval) async throws -> Response { @@ -51,12 +49,6 @@ open class URLSessionRequestBuilder: RequestBuilder { ) } - // MARK: Internal - - private(set) var sessionManager: URLSession - - // MARK: Fileprivate - fileprivate func processRequestResponse( urlRequest _: URLRequest, data: Data?, response: URLResponse? ) async throws -> Response { diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/AlgoliaRetryStrategy.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/AlgoliaRetryStrategy.swift index be5227cce7..a016f3d049 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/AlgoliaRetryStrategy.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/AlgoliaRetryStrategy.swift @@ -16,7 +16,11 @@ import Foundation // Algolia's retry strategy in case of server error, timeouts... class AlgoliaRetryStrategy: RetryStrategy { - // MARK: Lifecycle + private var hosts: [RetryableHost] + /// Concurrent synchronization queue + private let queue = DispatchQueue(label: "AlgoliaRetryStrategySync.queue") + + let hostsExpirationDelay: TimeInterval init(hosts: [RetryableHost], hostsExpirationDelay: TimeInterval = .minutes(5)) { self.hosts = hosts @@ -27,10 +31,6 @@ class AlgoliaRetryStrategy: RetryStrategy { self.init(hosts: configuration.hosts) } - // MARK: Internal - - let hostsExpirationDelay: TimeInterval - func retryableHosts(for callType: CallType) -> HostIterator { self.queue.sync { // Reset expired hosts @@ -109,12 +109,6 @@ class AlgoliaRetryStrategy: RetryStrategy { func canRetry(inCaseOf error: some Error) -> Bool { self.isTimeout(error) || self.isRetryable(error) } - - // MARK: Private - - private var hosts: [RetryableHost] - /// Concurrent synchronization queue - private let queue = DispatchQueue(label: "AlgoliaRetryStrategySync.queue") } // MARK: CustomDebugStringConvertible diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/HostIterator.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/HostIterator.swift index 69e92436be..36e4ab5eac 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/HostIterator.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/HostIterator.swift @@ -8,19 +8,13 @@ import Foundation open class HostIterator: IteratorProtocol { - // MARK: Lifecycle + var getHost: () -> RetryableHost? init(getHost: @escaping () -> RetryableHost?) { self.getHost = getHost } - // MARK: Public - public func next() -> RetryableHost? { self.getHost() } - - // MARK: Internal - - var getHost: () -> RetryableHost? } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/RetryableHost.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/RetryableHost.swift index f16ada73b0..58f9d3146f 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/RetryableHost.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/RetryStrategy/RetryableHost.swift @@ -10,7 +10,13 @@ import Foundation // MARK: - RetryableHost public struct RetryableHost { - // MARK: Lifecycle + /// The url to target. + public let url: URL + + let supportedCallTypes: CallTypeSupport + var isUp: Bool + var lastUpdated: Date + var retryCount: Int public init(url: URL) { self.init(url: url, callType: .universal) @@ -24,11 +30,6 @@ public struct RetryableHost { self.retryCount = 0 } - // MARK: Public - - /// The url to target. - public let url: URL - public func supports(_ callType: CallType) -> Bool { switch callType { case .read: @@ -38,13 +39,6 @@ public struct RetryableHost { } } - // MARK: Internal - - let supportedCallTypes: CallTypeSupport - var isUp: Bool - var lastUpdated: Date - var retryCount: Int - mutating func reset() { self.lastUpdated = .init() self.isUp = true @@ -67,19 +61,15 @@ public struct RetryableHost { public extension RetryableHost { struct CallTypeSupport: OptionSet { - // MARK: Lifecycle - - public init(rawValue: Int) { - self.rawValue = rawValue - } - - // MARK: Public - public static let read = CallTypeSupport(rawValue: 1 << 0) public static let write = CallTypeSupport(rawValue: 1 << 1) public static let universal: CallTypeSupport = [.read, .write] public let rawValue: Int + + public init(rawValue: Int) { + self.rawValue = rawValue + } } } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift index 6fff369971..67803fe616 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/Transporter.swift @@ -12,7 +12,9 @@ import Foundation // MARK: - Transporter open class Transporter { - // MARK: Lifecycle + let configuration: Configuration + let retryStrategy: RetryStrategy + let requestBuilder: RequestBuilder public init( configuration: Configuration, @@ -38,8 +40,6 @@ open class Transporter { self.requestBuilder = requestBuilder } - // MARK: Public - public func send( method: String, path: String, data: Codable?, requestOptions: RequestOptions? = nil, useReadTransporter: Bool = false @@ -132,10 +132,4 @@ open class Transporter { throw AlgoliaError.noReachableHosts(intermediateErrors: intermediateErrors) } - - // MARK: Internal - - let configuration: Configuration - let retryStrategy: RetryStrategy - let requestBuilder: RequestBuilder } diff --git a/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgent.swift b/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgent.swift index 0da985c8d8..ad057f3700 100644 --- a/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgent.swift +++ b/clients/algoliasearch-client-swift/Sources/Core/Networking/UserAgent/UserAgent.swift @@ -10,17 +10,13 @@ import Foundation // MARK: - UserAgent public struct UserAgent: Hashable { - // MARK: Lifecycle + public let title: String + public let version: String public init(title: String, version: String) { self.title = title self.version = version } - - // MARK: Public - - public let title: String - public let version: String } // MARK: CustomStringConvertible diff --git a/snippets/swift/.swiftformat b/snippets/swift/.swiftformat index 394a6ba965..4a5dede1bb 100644 --- a/snippets/swift/.swiftformat +++ b/snippets/swift/.swiftformat @@ -83,12 +83,10 @@ --enable leadingDelimiters --enable linebreakAtEndOfFile --enable linebreaks ---enable markTypes --enable modifierOrder --enable noExplicitOwnership --enable numberFormatting --enable opaqueGenericParameters ---enable organizeDeclarations --enable preferKeyPath --enable redundantClosure --enable redundantExtensionACL @@ -144,6 +142,8 @@ --disable applicationMain --disable blankLinesBetweenImports --disable fileHeader +--disable markTypes +--disable organizeDeclarations --disable preferForLoop --disable redundantBackticks --disable redundantBreak diff --git a/tests/output/swift/.swiftformat b/tests/output/swift/.swiftformat index 394a6ba965..4a5dede1bb 100644 --- a/tests/output/swift/.swiftformat +++ b/tests/output/swift/.swiftformat @@ -83,12 +83,10 @@ --enable leadingDelimiters --enable linebreakAtEndOfFile --enable linebreaks ---enable markTypes --enable modifierOrder --enable noExplicitOwnership --enable numberFormatting --enable opaqueGenericParameters ---enable organizeDeclarations --enable preferKeyPath --enable redundantClosure --enable redundantExtensionACL @@ -144,6 +142,8 @@ --disable applicationMain --disable blankLinesBetweenImports --disable fileHeader +--disable markTypes +--disable organizeDeclarations --disable preferForLoop --disable redundantBackticks --disable redundantBreak