Skip to content

Commit ff1430d

Browse files
committed
refactoring of plugins execution order
1 parent c40dff6 commit ff1430d

36 files changed

+283
-289
lines changed

Source/Address/Address.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import Foundation
22

33
/// The struct Address is designed to encapsulate URL-related information and
44
/// provide flexibility in constructing URLs based on different sources and configurations.
5-
public struct Address: Hashable {
6-
public enum Source: Hashable {
5+
public struct Address: Hashable, SmartSendable {
6+
public enum Source: Hashable, SmartSendable {
77
case string(String)
88
case url(URL)
99
case components(URLComponents)
@@ -163,8 +163,3 @@ extension Address.Source: CustomStringConvertible {
163163
}
164164
}
165165
}
166-
167-
#if swift(>=6.0)
168-
extension Address: Sendable {}
169-
extension Address.Source: Sendable {}
170-
#endif

Source/Address/AddressDetails.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
/// The ``AddressDetails`` struct in Swift represents a ``URL`` and contains specific components to define the address details.
44
/// This struct is intended to encapsulate detailed information about a ``URL``, such as scheme, host, port,
55
/// path components, query items, and fragment for constructing and processing ``URL``s effectively within the system.
6-
public struct AddressDetails: Hashable {
6+
public struct AddressDetails: Hashable, SmartSendable {
77
public let scheme: Scheme?
88
public let host: String
99
public let port: Int?
@@ -104,7 +104,3 @@ private extension String? {
104104
}
105105
}
106106
}
107-
108-
#if swift(>=6.0)
109-
extension AddressDetails: Sendable {}
110-
#endif

Source/CURLConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
public protocol CURLConvertible {
3+
public protocol CURLConvertible: SmartSendable {
44
/// cURL representation of the instance.
55
///
66
/// - Returns: The cURL equivalent of the instance.

Source/Content/DecodableKeyPath.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ extension DecodableKeyPath: ExpressibleByStringLiteral {
7878
self.init(path: value)
7979
}
8080
}
81+
82+
#if swift(>=6.0)
83+
extension DecodableKeyPath: Sendable where T: Sendable {}
84+
extension DecodableKeyPath.Fallback: Sendable where T: Sendable {}
85+
#endif

Source/Error/StatusCode.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
/// The StatusCode struct is designed to represent different status codes and their corresponding kinds,
44
/// providing flexibility in error handling and status code representations within the system.
5-
public struct StatusCode: Error, Hashable, ExpressibleByIntegerLiteral {
5+
public struct StatusCode: Error, Hashable, ExpressibleByIntegerLiteral, SmartSendable {
66
public let code: Int
77
public let kind: Kind?
88

@@ -44,7 +44,7 @@ extension StatusCode: RequestErrorDescription {
4444
public extension StatusCode {
4545
/// This enum is designed to categorize status codes into different kinds,
4646
/// facilitating error handling and status code interpretation within the system.
47-
enum Kind: Int, Hashable, CaseIterable {
47+
enum Kind: Int, Hashable, CaseIterable, SmartSendable {
4848
// MARK: - Successful responses
4949

5050
case created = 201
@@ -116,8 +116,3 @@ public extension StatusCode.Kind {
116116
return name.unsafelyUnwrapped
117117
}
118118
}
119-
120-
#if swift(>=6.0)
121-
extension StatusCode: Sendable {}
122-
extension StatusCode.Kind: Sendable {}
123-
#endif

Source/Managers/RequestManager.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import Foundation
22
import Threading
33

4-
#if swift(>=6.0)
5-
public protocol RequestManager: Sendable {
6-
/// A closure that is called when a response is received.
4+
/// The ``RequestManager`` protocol defines mechanisms for sending requests
5+
/// and includes functions that handle the transmission of requests to specified addresses
6+
/// with specified parameters and with support for custom completion handling in specified queues.
7+
public protocol RequestManager: SmartSendable {
8+
/// A closure that gets called upon receiving a response.
79
typealias ResponseClosure = (_ result: SmartResponse) -> Void
810

9-
/// Sends a request to the specified address with the given parameters.
10-
func request(address: Address, parameters: Parameters, userInfo: UserInfo) async -> SmartResponse
11-
12-
/// Sends a request to the specified address with the given parameters.
13-
func request(address: Address, parameters: Parameters, userInfo: UserInfo, completionQueue: DelayedQueue, completion: @escaping ResponseClosure) -> SmartTasking
14-
}
15-
#else
16-
public protocol RequestManager {
17-
/// A closure that is called when a response is received.
18-
typealias ResponseClosure = (_ result: SmartResponse) -> Void
19-
20-
/// Sends a request to the specified address with the given parameters.
11+
/// Sends a request asynchronously to the specified address with the given parameters.
12+
///
13+
/// - Parameter address: An ``Address`` object specifying the target address.
14+
/// - Parameter parameters: A ``Parameters`` object containing the request parameters.
15+
/// - Parameter userInfo: A ``UserInfo`` object with additional user information.
2116
func request(address: Address, parameters: Parameters, userInfo: UserInfo) async -> SmartResponse
2217

2318
/// Sends a request to the specified address with the given parameters.
19+
///
20+
/// - Parameter address: An ``Address`` object specifying the target address.
21+
/// - Parameter parameters: A ``Parameters`` object containing the request parameters.
22+
/// - Parameter userInfo: A ``UserInfo`` object with additional user information.
23+
/// - Parameter completionQueue: A ``DelayedQueue`` where the completion handler will be executed.
24+
/// - Parameter completion: A ``ResponseClosure`` that is executed when a response is received.
2425
func request(address: Address, parameters: Parameters, userInfo: UserInfo, completionQueue: DelayedQueue, completion: @escaping ResponseClosure) -> SmartTasking
2526
}
26-
#endif
2727

2828
public extension RequestManager {
2929
/// Sends a request to the specified address with the given parameters.

Source/Managers/SmartRequestManager.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ private extension SmartRequestManager {
182182
func prepare(_ parameters: Parameters) -> Parameters {
183183
var parameters = parameters
184184

185-
let newPlugins = (parameters.plugins + plugins)
186-
.unified()
187-
.sorted { a, b in
188-
return a.priority > b.priority
189-
}
185+
let newPlugins = (parameters.plugins + plugins).prepareForExecution()
190186
parameters.plugins = newPlugins
191187
return parameters
192188
}
@@ -270,10 +266,6 @@ private extension SmartRequestManager {
270266
}
271267
}
272268

273-
#if swift(>=6.0)
274-
extension SmartRequestManager: @unchecked Sendable {}
275-
#endif
276-
277269
private extension SmartTask {
278270
func fillUserInfo(with address: Address) -> Self {
279271
userInfo.smartRequestAddress = address
@@ -286,3 +278,7 @@ private extension SmartResponse {
286278
self.init(request: nil, body: nil, response: nil, error: error, session: session)
287279
}
288280
}
281+
282+
#if swift(>=6.0)
283+
extension SmartRequestManager: @unchecked Sendable {}
284+
#endif

Source/Parameters/Body.MultipartForm.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private extension Body.MultipartForm {
268268
}
269269
}
270270

271-
struct Header: Equatable, Hashable, Sendable {
271+
struct Header: Equatable, Hashable {
272272
let name: String
273273
let value: String
274274
}
@@ -293,6 +293,7 @@ private extension Body.MultipartForm {
293293
#if swift(>=6.0)
294294
extension Body.MultipartForm: @unchecked Sendable {}
295295
extension Body.MultipartForm.Name: Sendable {}
296+
extension Body.MultipartForm.Header: Sendable {}
296297
extension Body.MultipartForm.MimeType: Sendable {}
297298
extension Body.MultipartForm.Boundary: Sendable {}
298299
extension Body.MultipartForm.DataContent: Sendable {}
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import Foundation
22
import Threading
33

4-
#if swift(>=6.0)
54
/// A protocol that represents a ``RequestCache`` interface which can be used to mock requests in unit tests.
6-
public protocol RequestCache: AnyObject, Sendable {
5+
public protocol RequestCache: AnyObject, SmartSendable {
76
func cachedResponse(for request: URLRequest) -> CachedURLResponse?
87
func storeCachedResponse(_ cachedResponse: CachedURLResponse, for request: URLRequest)
98
func removeCachedResponse(for request: URLRequest)
109
}
11-
#else
12-
/// A protocol that represents a ``RequestCache`` interface which can be used to mock requests in unit tests.
13-
public protocol RequestCache: AnyObject {
14-
func cachedResponse(for request: URLRequest) -> CachedURLResponse?
15-
func storeCachedResponse(_ cachedResponse: CachedURLResponse, for request: URLRequest)
16-
func removeCachedResponse(for request: URLRequest)
17-
}
18-
#endif
1910

2011
extension URLCache: RequestCache {}
2112

2213
/// A struct that manages cache settings.
23-
public struct CacheSettings {
14+
public struct CacheSettings: SmartSendable {
2415
public let cache: RequestCache
2516
public let storagePolicy: URLCache.StoragePolicy
2617

@@ -30,7 +21,3 @@ public struct CacheSettings {
3021
self.storagePolicy = storagePolicy
3122
}
3223
}
33-
34-
#if swift(>=6.0)
35-
extension CacheSettings: Sendable {}
36-
#endif

Source/Parameters/HTTPMethod.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
/// HTTP method types. It is used in `Parameters` to specify the HTTP method.
4-
public enum HTTPMethod: Hashable {
4+
public enum HTTPMethod: Hashable, SmartSendable {
55
case get
66
case head
77
case post
@@ -48,7 +48,3 @@ internal extension HTTPMethod {
4848
}
4949
}
5050
}
51-
52-
#if swift(>=6.0)
53-
extension HTTPMethod: Sendable {}
54-
#endif

0 commit comments

Comments
 (0)