Skip to content

Commit f5fc86b

Browse files
authored
Resolved implementation (#103)
## Description This PR includes internal changes to improve the process of resolving properties in the `Internal.Session` and `Internal.Request` components. The updates aim to enhance the overall functionality and efficiency of the codebase. Previously, the result of the property resolution process in `Internal.Session` and `Internal.Request` was returned directly. However, in this PR, we have made internal modifications so that the `Resolve` method now returns a `Resolved` object. This `Resolved` object contains all the necessary information required to execute the request effectively. By introducing the `Resolved` object, we centralize and encapsulate the relevant data, ensuring a more structured and comprehensive approach to property resolution. This change simplifies the code logic and improves code readability by providing a single object that holds all the pertinent information. These modifications have been implemented to enhance the overall efficiency, maintainability, and extensibility of the codebase. They provide a clear and concise way to access and utilize the resolved properties, streamlining the execution of requests within the `Internal.Session` and `Internal.Request` components. Please note that these changes do not impact the external behavior or functionality of the code. They solely focus on improving the internal process of resolving properties, resulting in a more robust and streamlined codebase. Fixes **None** ## Type of change - [x] New feature (non-breaking change which adds functionality) ## Checklist - [x] My code follows the code style of this project. - [x] All new and existing tests passed.
1 parent c60033b commit f5fc86b

46 files changed

Lines changed: 652 additions & 512 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
See LICENSE for this package's licensing information.
3+
*/
4+
5+
import Foundation
6+
7+
@RequestActor
8+
struct Resolved {
9+
10+
let session: Internals.Session
11+
let request: Internals.Request
12+
}

Sources/RequestDL/Properties/Sources/Graph/Resolve/Resolve.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Resolve<Root: Property> {
2828
)
2929
}
3030

31-
func build() async throws -> (Internals.Session, Internals.Request) {
31+
func build() async throws -> Resolved {
3232
let output = try await outputs()
3333

3434
var make = Make(
@@ -43,7 +43,10 @@ struct Resolve<Root: Property> {
4343
configuration: make.configuration
4444
)
4545

46-
return (session, make.request)
46+
return Resolved(
47+
session: session,
48+
request: make.request
49+
)
4750
}
4851
}
4952

Sources/RequestDL/Tasks/Sources/Raw Task/RawTask.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ struct RawTask<Content: Property>: Task {
1212
extension RawTask {
1313

1414
func result() async throws -> AsyncResponse {
15-
let (session, request) = try await Resolve(content).build()
16-
return try await .init(session.request(request).response)
15+
let resolved = try await Resolve(content).build()
16+
17+
return try await .init(resolved.session.request(
18+
resolved.request
19+
).response)
1720
}
1821
}

Tests/RequestDLTests/Properties/Sources/Extra Properties/Any/AnyPropertyTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class AnyPropertyTests: XCTestCase {
1313
let property = Query(123, forKey: "number")
1414

1515
// When
16-
let (_, request) = try await resolve(TestProperty {
16+
let resolved = try await resolve(TestProperty {
1717
BaseURL("127.0.0.1")
1818
AnyProperty(property)
1919
})
2020

2121
// Then
22-
XCTAssertEqual(request.url, "https://127.0.0.1?number=123")
22+
XCTAssertEqual(resolved.request.url, "https://127.0.0.1?number=123")
2323
}
2424

2525
func testAnyProperty_whenCertificate() async throws {
@@ -28,15 +28,15 @@ class AnyPropertyTests: XCTestCase {
2828
let path = certificate.certificateURL.absolutePath(percentEncoded: false)
2929

3030
// When
31-
let (session, _) = try await resolve(TestProperty {
31+
let resolved = try await resolve(TestProperty {
3232
SecureConnection {
3333
AdditionalTrusts {
3434
AnyProperty(Certificate(path))
3535
}
3636
}
3737
})
3838

39-
let sut = session.configuration.secureConnection
39+
let sut = resolved.session.configuration.secureConnection
4040

4141
// Then
4242
XCTAssertEqual(sut?.additionalTrustRoots, [

Tests/RequestDLTests/Properties/Sources/Extra Properties/Async/AsyncPropertyTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AsyncPropertyTests: XCTestCase {
1717
}
1818

1919
// When
20-
let (_, request) = try await resolve(TestProperty {
20+
let resolved = try await resolve(TestProperty {
2121
AsyncProperty {
2222
if let apiKey = await apiKey {
2323
Authorization(.bearer, token: apiKey)
@@ -26,7 +26,10 @@ class AsyncPropertyTests: XCTestCase {
2626
})
2727

2828
// Then
29-
XCTAssertEqual(request.headers.getValue(forKey: "Authorization"), "Bearer 123ddf4")
29+
XCTAssertEqual(
30+
resolved.request.headers.getValue(forKey: "Authorization"),
31+
"Bearer 123ddf4"
32+
)
3033
}
3134

3235
func testNeverBody() async throws {

Tests/RequestDLTests/Properties/Sources/Extra Properties/ForEach/ForEachTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ForEachTests: XCTestCase {
1919
}
2020

2121
// When
22-
let (_, request) = try await resolve(TestProperty {
22+
let resolved = try await resolve(TestProperty {
2323
BaseURL("127.0.0.1")
2424
ForEach(paths) { path in
2525
Path(path.id)
@@ -28,7 +28,7 @@ class ForEachTests: XCTestCase {
2828

2929
// Then
3030
XCTAssertEqual(
31-
request.url,
31+
resolved.request.url,
3232
"https://127.0.0.1/api/v1/users"
3333
)
3434
}
@@ -38,7 +38,7 @@ class ForEachTests: XCTestCase {
3838
let paths = ["api", "v1", "users"]
3939

4040
// When
41-
let (_, request) = try await resolve(TestProperty {
41+
let resolved = try await resolve(TestProperty {
4242
BaseURL("127.0.0.1")
4343
ForEach(paths, id: \.self) { path in
4444
Path(path)
@@ -47,7 +47,7 @@ class ForEachTests: XCTestCase {
4747

4848
// Then
4949
XCTAssertEqual(
50-
request.url,
50+
resolved.request.url,
5151
"https://127.0.0.1/api/v1/users"
5252
)
5353
}
@@ -57,7 +57,7 @@ class ForEachTests: XCTestCase {
5757
let range = 0 ..< 3
5858

5959
// When
60-
let (_, request) = try await resolve(TestProperty {
60+
let resolved = try await resolve(TestProperty {
6161
BaseURL("127.0.0.1")
6262
ForEach(range) { index in
6363
Path("\(index)")
@@ -66,7 +66,7 @@ class ForEachTests: XCTestCase {
6666

6767
// Then
6868
XCTAssertEqual(
69-
request.url,
69+
resolved.request.url,
7070
"https://127.0.0.1/\(range.map { "\($0)" }.joined(separator: "/"))"
7171
)
7272
}
@@ -76,7 +76,7 @@ class ForEachTests: XCTestCase {
7676
let range = 0 ... 3
7777

7878
// When
79-
let (_, request) = try await resolve(TestProperty {
79+
let resolved = try await resolve(TestProperty {
8080
BaseURL("127.0.0.1")
8181
ForEach(range) { index in
8282
Path("\(index)")
@@ -85,7 +85,7 @@ class ForEachTests: XCTestCase {
8585

8686
// Then
8787
XCTAssertEqual(
88-
request.url,
88+
resolved.request.url,
8989
"https://127.0.0.1/\(range.map { "\($0)" }.joined(separator: "/"))"
9090
)
9191
}

Tests/RequestDLTests/Properties/Sources/Extra Properties/Group/GroupTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class GroupTests: XCTestCase {
1515
}
1616

1717
// When
18-
let (_, request) = try await resolve(TestProperty(property))
18+
let resolved = try await resolve(TestProperty(property))
1919

2020
// Then
21-
XCTAssertEqual(request.url, "https://google.com")
21+
XCTAssertEqual(resolved.request.url, "https://google.com")
2222
}
2323

2424
func testMultipleGroup() async throws {
@@ -30,11 +30,11 @@ class GroupTests: XCTestCase {
3030
}
3131

3232
// When
33-
let (_, request) = try await resolve(TestProperty(property))
33+
let resolved = try await resolve(TestProperty(property))
3434

3535
// Then
3636
XCTAssertEqual(
37-
request.url,
37+
resolved.request.url,
3838
"https://google.com/api/v1?available_methods=all"
3939
)
4040
}

Tests/RequestDLTests/Properties/Sources/Extra Properties/Modifier/PropertyModifierTests.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,33 @@ class PropertyModifierTests: XCTestCase {
3333
let modifier = CustomModifier(includesContent: true)
3434

3535
// When
36-
let (_, request) = try await resolve(TestProperty {
36+
let resolved = try await resolve(TestProperty {
3737
BaseURL("apple.com")
3838
.modifier(modifier)
3939
})
4040

4141
// Then
42-
XCTAssertEqual(request.url, "https://apple.com/api/v2?id=123")
42+
XCTAssertEqual(
43+
resolved.request.url,
44+
"https://apple.com/api/v2?id=123"
45+
)
4346
}
4447

4548
func testModifier_whenNotIncludesContent() async throws {
4649
// Given
4750
let modifier = CustomModifier(includesContent: false)
4851

4952
// When
50-
let (_, request) = try await resolve(TestProperty {
53+
let resolved = try await resolve(TestProperty {
5154
BaseURL("apple.com")
5255
.modifier(modifier)
5356
})
5457

5558
// Then
56-
XCTAssertEqual(request.url, "https://google.com/api/v2?id=123")
59+
XCTAssertEqual(
60+
resolved.request.url,
61+
"https://google.com/api/v2?id=123"
62+
)
5763
}
5864
}
5965

@@ -73,14 +79,14 @@ extension PropertyModifierTests {
7379
let certificatePath = resource.certificateURL.absolutePath(percentEncoded: false)
7480

7581
// When
76-
let (session, _) = try await resolve(TestProperty {
82+
let resolved = try await resolve(TestProperty {
7783
SecureConnection {
7884
Certificate(certificatePath)
7985
.modifier(AdditionalTrustsFaker())
8086
}
8187
})
8288

83-
let sut = session.configuration.secureConnection
89+
let sut = resolved.session.configuration.secureConnection
8490

8591
// Then
8692
XCTAssertEqual(sut?.additionalTrustRoots, [
@@ -114,28 +120,34 @@ extension PropertyModifierTests {
114120
let modifier = PathModifier()
115121

116122
// When
117-
let (_, request) = try await resolve(TestProperty {
123+
let resolved = try await resolve(TestProperty {
118124
BaseURL("www.google.com")
119125
.modifier(modifier)
120126
.environment(\.path, additionalPath)
121127
})
122128

123129
// Then
124-
XCTAssertEqual(request.url, "https://www.google.com/\(additionalPath)")
130+
XCTAssertEqual(
131+
resolved.request.url,
132+
"https://www.google.com/\(additionalPath)"
133+
)
125134
}
126135

127136
func testModifier_whenPathEnvironmentIsNotSet() async throws {
128137
// Given
129138
let modifier = PathModifier()
130139

131140
// When
132-
let (_, request) = try await resolve(TestProperty {
141+
let resolved = try await resolve(TestProperty {
133142
BaseURL("www.google.com")
134143
.modifier(modifier)
135144
})
136145

137146
// Then
138-
XCTAssertEqual(request.url, "https://www.google.com")
147+
XCTAssertEqual(
148+
resolved.request.url,
149+
"https://www.google.com"
150+
)
139151
}
140152
}
141153

Tests/RequestDLTests/Properties/Sources/Extra Properties/Namespace/NamespaceTests.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension NamespaceTests {
6666
var namespaceID: Namespace.ID?
6767

6868
// When
69-
let (_, request) = try await resolve(TestProperty {
69+
let resolved = try await resolve(TestProperty {
7070
SingleNamespace {
7171
NamespaceSpy {
7272
namespaceID = $0
@@ -75,7 +75,7 @@ extension NamespaceTests {
7575
})
7676

7777
// Then
78-
XCTAssertEqual(request.url, "https://www.apple.com/v1")
78+
XCTAssertEqual(resolved.request.url, "https://www.apple.com/v1")
7979
XCTAssertEqual(namespaceID, Namespace.ID(
8080
base: SingleNamespace<NamespaceSpy>.self,
8181
namespace: "_v1"
@@ -107,7 +107,7 @@ extension NamespaceTests {
107107
var namespaceID: Namespace.ID?
108108

109109
// When
110-
let (_, request) = try await resolve(TestProperty {
110+
let resolved = try await resolve(TestProperty {
111111
MultipleNamespace {
112112
NamespaceSpy {
113113
namespaceID = $0
@@ -116,7 +116,11 @@ extension NamespaceTests {
116116
})
117117

118118
// Then
119-
XCTAssertEqual(request.url, "https://www.apple.com/multiple/namespace")
119+
XCTAssertEqual(
120+
resolved.request.url,
121+
"https://www.apple.com/multiple/namespace"
122+
)
123+
120124
XCTAssertEqual(namespaceID, Namespace.ID(
121125
base: MultipleNamespace<NamespaceSpy>.self,
122126
namespace: "_multiple._namespace"
@@ -144,15 +148,19 @@ extension NamespaceTests {
144148
var namespaceID: Namespace.ID?
145149

146150
// When
147-
let (_, request) = try await resolve(TestProperty {
151+
let resolved = try await resolve(TestProperty {
148152
Path("v1")
149153
.modifier(NamespaceModifier {
150154
namespaceID = $0
151155
})
152156
})
153157

154158
// Then
155-
XCTAssertEqual(request.url, "https://www.apple.com/v1/namespace")
159+
XCTAssertEqual(
160+
resolved.request.url,
161+
"https://www.apple.com/v1/namespace"
162+
)
163+
156164
XCTAssertEqual(namespaceID, Namespace.ID(
157165
base: NamespaceModifier.self,
158166
namespace: "_namespace"

0 commit comments

Comments
 (0)